]> git.proxmox.com Git - mirror_frr.git/blob - bgpd/bgp_vty.c
Merge pull request #5163 from ton31337/fix/do_not_reconnect_if_prefix_overflow_7.1
[mirror_frr.git] / bgpd / bgp_vty.c
1 /* BGP VTY interface.
2 * Copyright (C) 1996, 97, 98, 99, 2000 Kunihiro Ishiguro
3 *
4 * This file is part of GNU Zebra.
5 *
6 * GNU Zebra is free software; you can redistribute it and/or modify it
7 * under the terms of the GNU General Public License as published by the
8 * Free Software Foundation; either version 2, or (at your option) any
9 * later version.
10 *
11 * GNU Zebra is distributed in the hope that it will be useful, but
12 * WITHOUT ANY WARRANTY; without even the implied warranty of
13 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
14 * General Public License for more details.
15 *
16 * You should have received a copy of the GNU General Public License along
17 * with this program; see the file COPYING; if not, write to the Free Software
18 * Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA
19 */
20
21 #include <zebra.h>
22
23 #include "command.h"
24 #include "lib/json.h"
25 #include "lib/zclient.h"
26 #include "prefix.h"
27 #include "plist.h"
28 #include "buffer.h"
29 #include "linklist.h"
30 #include "stream.h"
31 #include "thread.h"
32 #include "log.h"
33 #include "memory.h"
34 #include "memory_vty.h"
35 #include "hash.h"
36 #include "queue.h"
37 #include "filter.h"
38 #include "frrstr.h"
39
40 #include "bgpd/bgpd.h"
41 #include "bgpd/bgp_attr_evpn.h"
42 #include "bgpd/bgp_advertise.h"
43 #include "bgpd/bgp_attr.h"
44 #include "bgpd/bgp_aspath.h"
45 #include "bgpd/bgp_community.h"
46 #include "bgpd/bgp_ecommunity.h"
47 #include "bgpd/bgp_lcommunity.h"
48 #include "bgpd/bgp_damp.h"
49 #include "bgpd/bgp_debug.h"
50 #include "bgpd/bgp_errors.h"
51 #include "bgpd/bgp_fsm.h"
52 #include "bgpd/bgp_nexthop.h"
53 #include "bgpd/bgp_open.h"
54 #include "bgpd/bgp_regex.h"
55 #include "bgpd/bgp_route.h"
56 #include "bgpd/bgp_mplsvpn.h"
57 #include "bgpd/bgp_zebra.h"
58 #include "bgpd/bgp_table.h"
59 #include "bgpd/bgp_vty.h"
60 #include "bgpd/bgp_mpath.h"
61 #include "bgpd/bgp_packet.h"
62 #include "bgpd/bgp_updgrp.h"
63 #include "bgpd/bgp_bfd.h"
64 #include "bgpd/bgp_io.h"
65 #include "bgpd/bgp_evpn.h"
66 #include "bgpd/bgp_addpath.h"
67 #include "bgpd/bgp_mac.h"
68
69 static struct peer_group *listen_range_exists(struct bgp *bgp,
70 struct prefix *range, int exact);
71
72 static enum node_type bgp_node_type(afi_t afi, safi_t safi)
73 {
74 switch (afi) {
75 case AFI_IP:
76 switch (safi) {
77 case SAFI_UNICAST:
78 return BGP_IPV4_NODE;
79 break;
80 case SAFI_MULTICAST:
81 return BGP_IPV4M_NODE;
82 break;
83 case SAFI_LABELED_UNICAST:
84 return BGP_IPV4L_NODE;
85 break;
86 case SAFI_MPLS_VPN:
87 return BGP_VPNV4_NODE;
88 break;
89 case SAFI_FLOWSPEC:
90 return BGP_FLOWSPECV4_NODE;
91 default:
92 /* not expected */
93 return BGP_IPV4_NODE;
94 break;
95 }
96 break;
97 case AFI_IP6:
98 switch (safi) {
99 case SAFI_UNICAST:
100 return BGP_IPV6_NODE;
101 break;
102 case SAFI_MULTICAST:
103 return BGP_IPV6M_NODE;
104 break;
105 case SAFI_LABELED_UNICAST:
106 return BGP_IPV6L_NODE;
107 break;
108 case SAFI_MPLS_VPN:
109 return BGP_VPNV6_NODE;
110 break;
111 case SAFI_FLOWSPEC:
112 return BGP_FLOWSPECV6_NODE;
113 default:
114 /* not expected */
115 return BGP_IPV4_NODE;
116 break;
117 }
118 break;
119 case AFI_L2VPN:
120 return BGP_EVPN_NODE;
121 break;
122 case AFI_MAX:
123 // We should never be here but to clarify the switch statement..
124 return BGP_IPV4_NODE;
125 break;
126 }
127
128 // Impossible to happen
129 return BGP_IPV4_NODE;
130 }
131
132 /* Utility function to get address family from current node. */
133 afi_t bgp_node_afi(struct vty *vty)
134 {
135 afi_t afi;
136 switch (vty->node) {
137 case BGP_IPV6_NODE:
138 case BGP_IPV6M_NODE:
139 case BGP_IPV6L_NODE:
140 case BGP_VPNV6_NODE:
141 case BGP_FLOWSPECV6_NODE:
142 afi = AFI_IP6;
143 break;
144 case BGP_EVPN_NODE:
145 afi = AFI_L2VPN;
146 break;
147 default:
148 afi = AFI_IP;
149 break;
150 }
151 return afi;
152 }
153
154 /* Utility function to get subsequent address family from current
155 node. */
156 safi_t bgp_node_safi(struct vty *vty)
157 {
158 safi_t safi;
159 switch (vty->node) {
160 case BGP_VPNV4_NODE:
161 case BGP_VPNV6_NODE:
162 safi = SAFI_MPLS_VPN;
163 break;
164 case BGP_IPV4M_NODE:
165 case BGP_IPV6M_NODE:
166 safi = SAFI_MULTICAST;
167 break;
168 case BGP_EVPN_NODE:
169 safi = SAFI_EVPN;
170 break;
171 case BGP_IPV4L_NODE:
172 case BGP_IPV6L_NODE:
173 safi = SAFI_LABELED_UNICAST;
174 break;
175 case BGP_FLOWSPECV4_NODE:
176 case BGP_FLOWSPECV6_NODE:
177 safi = SAFI_FLOWSPEC;
178 break;
179 default:
180 safi = SAFI_UNICAST;
181 break;
182 }
183 return safi;
184 }
185
186 /**
187 * Converts an AFI in string form to afi_t
188 *
189 * @param afi string, one of
190 * - "ipv4"
191 * - "ipv6"
192 * - "l2vpn"
193 * @return the corresponding afi_t
194 */
195 afi_t bgp_vty_afi_from_str(const char *afi_str)
196 {
197 afi_t afi = AFI_MAX; /* unknown */
198 if (strmatch(afi_str, "ipv4"))
199 afi = AFI_IP;
200 else if (strmatch(afi_str, "ipv6"))
201 afi = AFI_IP6;
202 else if (strmatch(afi_str, "l2vpn"))
203 afi = AFI_L2VPN;
204 return afi;
205 }
206
207 int argv_find_and_parse_afi(struct cmd_token **argv, int argc, int *index,
208 afi_t *afi)
209 {
210 int ret = 0;
211 if (argv_find(argv, argc, "ipv4", index)) {
212 ret = 1;
213 if (afi)
214 *afi = AFI_IP;
215 } else if (argv_find(argv, argc, "ipv6", index)) {
216 ret = 1;
217 if (afi)
218 *afi = AFI_IP6;
219 }
220 return ret;
221 }
222
223 /* supports <unicast|multicast|vpn|labeled-unicast> */
224 safi_t bgp_vty_safi_from_str(const char *safi_str)
225 {
226 safi_t safi = SAFI_MAX; /* unknown */
227 if (strmatch(safi_str, "multicast"))
228 safi = SAFI_MULTICAST;
229 else if (strmatch(safi_str, "unicast"))
230 safi = SAFI_UNICAST;
231 else if (strmatch(safi_str, "vpn"))
232 safi = SAFI_MPLS_VPN;
233 else if (strmatch(safi_str, "evpn"))
234 safi = SAFI_EVPN;
235 else if (strmatch(safi_str, "labeled-unicast"))
236 safi = SAFI_LABELED_UNICAST;
237 else if (strmatch(safi_str, "flowspec"))
238 safi = SAFI_FLOWSPEC;
239 return safi;
240 }
241
242 int argv_find_and_parse_safi(struct cmd_token **argv, int argc, int *index,
243 safi_t *safi)
244 {
245 int ret = 0;
246 if (argv_find(argv, argc, "unicast", index)) {
247 ret = 1;
248 if (safi)
249 *safi = SAFI_UNICAST;
250 } else if (argv_find(argv, argc, "multicast", index)) {
251 ret = 1;
252 if (safi)
253 *safi = SAFI_MULTICAST;
254 } else if (argv_find(argv, argc, "labeled-unicast", index)) {
255 ret = 1;
256 if (safi)
257 *safi = SAFI_LABELED_UNICAST;
258 } else if (argv_find(argv, argc, "vpn", index)) {
259 ret = 1;
260 if (safi)
261 *safi = SAFI_MPLS_VPN;
262 } else if (argv_find(argv, argc, "flowspec", index)) {
263 ret = 1;
264 if (safi)
265 *safi = SAFI_FLOWSPEC;
266 }
267 return ret;
268 }
269
270 /*
271 * bgp_vty_find_and_parse_afi_safi_bgp
272 *
273 * For a given 'show ...' command, correctly parse the afi/safi/bgp out from it
274 * This function *assumes* that the calling function pre-sets the afi/safi/bgp
275 * to appropriate values for the calling function. This is to allow the
276 * calling function to make decisions appropriate for the show command
277 * that is being parsed.
278 *
279 * The show commands are generally of the form:
280 * "show [ip] bgp [<view|vrf> VIEWVRFNAME] [<ipv4|ipv6>
281 * [<unicast|multicast|vpn|labeled-unicast>]] ..."
282 *
283 * Since we use argv_find if the show command in particular doesn't have:
284 * [ip]
285 * [<view|vrf> VIEWVRFNAME]
286 * [<ipv4|ipv6> [<unicast|multicast|vpn|labeled-unicast>]]
287 * The command parsing should still be ok.
288 *
289 * vty -> The vty for the command so we can output some useful data in
290 * the event of a parse error in the vrf.
291 * argv -> The command tokens
292 * argc -> How many command tokens we have
293 * idx -> The current place in the command, generally should be 0 for this
294 * function
295 * afi -> The parsed afi if it was included in the show command, returned here
296 * safi -> The parsed safi if it was included in the show command, returned here
297 * bgp -> Pointer to the bgp data structure we need to fill in.
298 * use_json -> json is configured or not
299 *
300 * The function returns the correct location in the parse tree for the
301 * last token found.
302 *
303 * Returns 0 for failure to parse correctly, else the idx position of where
304 * it found the last token.
305 */
306 int bgp_vty_find_and_parse_afi_safi_bgp(struct vty *vty,
307 struct cmd_token **argv, int argc,
308 int *idx, afi_t *afi, safi_t *safi,
309 struct bgp **bgp, bool use_json)
310 {
311 char *vrf_name = NULL;
312
313 assert(afi);
314 assert(safi);
315 assert(bgp);
316
317 if (argv_find(argv, argc, "ip", idx))
318 *afi = AFI_IP;
319
320 if (argv_find(argv, argc, "view", idx))
321 vrf_name = argv[*idx + 1]->arg;
322 else if (argv_find(argv, argc, "vrf", idx)) {
323 vrf_name = argv[*idx + 1]->arg;
324 if (strmatch(vrf_name, VRF_DEFAULT_NAME))
325 vrf_name = NULL;
326 }
327 if (vrf_name) {
328 if (strmatch(vrf_name, "all"))
329 *bgp = NULL;
330 else {
331 *bgp = bgp_lookup_by_name(vrf_name);
332 if (!*bgp) {
333 if (use_json) {
334 json_object *json = NULL;
335 json = json_object_new_object();
336 json_object_string_add(
337 json, "warning",
338 "View/Vrf is unknown");
339 vty_out(vty, "%s\n",
340 json_object_to_json_string_ext(json,
341 JSON_C_TO_STRING_PRETTY));
342 json_object_free(json);
343 }
344 else
345 vty_out(vty, "View/Vrf %s is unknown\n",
346 vrf_name);
347 *idx = 0;
348 return 0;
349 }
350 }
351 } else {
352 *bgp = bgp_get_default();
353 if (!*bgp) {
354 if (use_json) {
355 json_object *json = NULL;
356 json = json_object_new_object();
357 json_object_string_add(
358 json, "warning",
359 "Default BGP instance not found");
360 vty_out(vty, "%s\n",
361 json_object_to_json_string_ext(json,
362 JSON_C_TO_STRING_PRETTY));
363 json_object_free(json);
364 }
365 else
366 vty_out(vty,
367 "Default BGP instance not found\n");
368 *idx = 0;
369 return 0;
370 }
371 }
372
373 if (argv_find_and_parse_afi(argv, argc, idx, afi))
374 argv_find_and_parse_safi(argv, argc, idx, safi);
375
376 *idx += 1;
377 return *idx;
378 }
379
380 static int peer_address_self_check(struct bgp *bgp, union sockunion *su)
381 {
382 struct interface *ifp = NULL;
383
384 if (su->sa.sa_family == AF_INET)
385 ifp = if_lookup_by_ipv4_exact(&su->sin.sin_addr, bgp->vrf_id);
386 else if (su->sa.sa_family == AF_INET6)
387 ifp = if_lookup_by_ipv6_exact(&su->sin6.sin6_addr,
388 su->sin6.sin6_scope_id,
389 bgp->vrf_id);
390
391 if (ifp)
392 return 1;
393
394 return 0;
395 }
396
397 /* Utility function for looking up peer from VTY. */
398 /* This is used only for configuration, so disallow if attempted on
399 * a dynamic neighbor.
400 */
401 static struct peer *peer_lookup_vty(struct vty *vty, const char *ip_str)
402 {
403 struct bgp *bgp = VTY_GET_CONTEXT(bgp);
404 int ret;
405 union sockunion su;
406 struct peer *peer;
407
408 if (!bgp) {
409 return NULL;
410 }
411
412 ret = str2sockunion(ip_str, &su);
413 if (ret < 0) {
414 peer = peer_lookup_by_conf_if(bgp, ip_str);
415 if (!peer) {
416 if ((peer = peer_lookup_by_hostname(bgp, ip_str))
417 == NULL) {
418 vty_out(vty,
419 "%% Malformed address or name: %s\n",
420 ip_str);
421 return NULL;
422 }
423 }
424 } else {
425 peer = peer_lookup(bgp, &su);
426 if (!peer) {
427 vty_out(vty,
428 "%% Specify remote-as or peer-group commands first\n");
429 return NULL;
430 }
431 if (peer_dynamic_neighbor(peer)) {
432 vty_out(vty,
433 "%% Operation not allowed on a dynamic neighbor\n");
434 return NULL;
435 }
436 }
437 return peer;
438 }
439
440 /* Utility function for looking up peer or peer group. */
441 /* This is used only for configuration, so disallow if attempted on
442 * a dynamic neighbor.
443 */
444 struct peer *peer_and_group_lookup_vty(struct vty *vty, const char *peer_str)
445 {
446 struct bgp *bgp = VTY_GET_CONTEXT(bgp);
447 int ret;
448 union sockunion su;
449 struct peer *peer = NULL;
450 struct peer_group *group = NULL;
451
452 if (!bgp) {
453 return NULL;
454 }
455
456 ret = str2sockunion(peer_str, &su);
457 if (ret == 0) {
458 /* IP address, locate peer. */
459 peer = peer_lookup(bgp, &su);
460 } else {
461 /* Not IP, could match either peer configured on interface or a
462 * group. */
463 peer = peer_lookup_by_conf_if(bgp, peer_str);
464 if (!peer)
465 group = peer_group_lookup(bgp, peer_str);
466 }
467
468 if (peer) {
469 if (peer_dynamic_neighbor(peer)) {
470 vty_out(vty,
471 "%% Operation not allowed on a dynamic neighbor\n");
472 return NULL;
473 }
474
475 return peer;
476 }
477
478 if (group)
479 return group->conf;
480
481 vty_out(vty, "%% Specify remote-as or peer-group commands first\n");
482
483 return NULL;
484 }
485
486 int bgp_vty_return(struct vty *vty, int ret)
487 {
488 const char *str = NULL;
489
490 switch (ret) {
491 case BGP_ERR_INVALID_VALUE:
492 str = "Invalid value";
493 break;
494 case BGP_ERR_INVALID_FLAG:
495 str = "Invalid flag";
496 break;
497 case BGP_ERR_PEER_GROUP_SHUTDOWN:
498 str = "Peer-group has been shutdown. Activate the peer-group first";
499 break;
500 case BGP_ERR_PEER_FLAG_CONFLICT:
501 str = "Can't set override-capability and strict-capability-match at the same time";
502 break;
503 case BGP_ERR_PEER_GROUP_NO_REMOTE_AS:
504 str = "Specify remote-as or peer-group remote AS first";
505 break;
506 case BGP_ERR_PEER_GROUP_CANT_CHANGE:
507 str = "Cannot change the peer-group. Deconfigure first";
508 break;
509 case BGP_ERR_PEER_GROUP_MISMATCH:
510 str = "Peer is not a member of this peer-group";
511 break;
512 case BGP_ERR_PEER_FILTER_CONFLICT:
513 str = "Prefix/distribute list can not co-exist";
514 break;
515 case BGP_ERR_NOT_INTERNAL_PEER:
516 str = "Invalid command. Not an internal neighbor";
517 break;
518 case BGP_ERR_REMOVE_PRIVATE_AS:
519 str = "remove-private-AS cannot be configured for IBGP peers";
520 break;
521 case BGP_ERR_LOCAL_AS_ALLOWED_ONLY_FOR_EBGP:
522 str = "Local-AS allowed only for EBGP peers";
523 break;
524 case BGP_ERR_CANNOT_HAVE_LOCAL_AS_SAME_AS:
525 str = "Cannot have local-as same as BGP AS number";
526 break;
527 case BGP_ERR_TCPSIG_FAILED:
528 str = "Error while applying TCP-Sig to session(s)";
529 break;
530 case BGP_ERR_NO_EBGP_MULTIHOP_WITH_TTLHACK:
531 str = "ebgp-multihop and ttl-security cannot be configured together";
532 break;
533 case BGP_ERR_NO_IBGP_WITH_TTLHACK:
534 str = "ttl-security only allowed for EBGP peers";
535 break;
536 case BGP_ERR_AS_OVERRIDE:
537 str = "as-override cannot be configured for IBGP peers";
538 break;
539 case BGP_ERR_INVALID_DYNAMIC_NEIGHBORS_LIMIT:
540 str = "Invalid limit for number of dynamic neighbors";
541 break;
542 case BGP_ERR_DYNAMIC_NEIGHBORS_RANGE_EXISTS:
543 str = "Dynamic neighbor listen range already exists";
544 break;
545 case BGP_ERR_INVALID_FOR_DYNAMIC_PEER:
546 str = "Operation not allowed on a dynamic neighbor";
547 break;
548 case BGP_ERR_INVALID_FOR_DIRECT_PEER:
549 str = "Operation not allowed on a directly connected neighbor";
550 break;
551 case BGP_ERR_PEER_SAFI_CONFLICT:
552 str = "Cannot activate peer for both 'ipv4 unicast' and 'ipv4 labeled-unicast'";
553 break;
554 }
555 if (str) {
556 vty_out(vty, "%% %s\n", str);
557 return CMD_WARNING_CONFIG_FAILED;
558 }
559 return CMD_SUCCESS;
560 }
561
562 /* BGP clear sort. */
563 enum clear_sort {
564 clear_all,
565 clear_peer,
566 clear_group,
567 clear_external,
568 clear_as
569 };
570
571 static void bgp_clear_vty_error(struct vty *vty, struct peer *peer, afi_t afi,
572 safi_t safi, int error)
573 {
574 switch (error) {
575 case BGP_ERR_AF_UNCONFIGURED:
576 vty_out(vty,
577 "%%BGP: Enable %s address family for the neighbor %s\n",
578 afi_safi_print(afi, safi), peer->host);
579 break;
580 case BGP_ERR_SOFT_RECONFIG_UNCONFIGURED:
581 vty_out(vty,
582 "%%BGP: Inbound soft reconfig for %s not possible as it\n has neither refresh capability, nor inbound soft reconfig\n",
583 peer->host);
584 break;
585 default:
586 break;
587 }
588 }
589
590 /* `clear ip bgp' functions. */
591 static int bgp_clear(struct vty *vty, struct bgp *bgp, afi_t afi, safi_t safi,
592 enum clear_sort sort, enum bgp_clear_type stype,
593 const char *arg)
594 {
595 int ret;
596 bool found = false;
597 struct peer *peer;
598 struct listnode *node, *nnode;
599
600 /* Clear all neighbors. */
601 /*
602 * Pass along pointer to next node to peer_clear() when walking all
603 * nodes on the BGP instance as that may get freed if it is a
604 * doppelganger
605 */
606 if (sort == clear_all) {
607 for (ALL_LIST_ELEMENTS(bgp->peer, node, nnode, peer)) {
608 if (!peer->afc[afi][safi])
609 continue;
610
611 if (stype == BGP_CLEAR_SOFT_NONE)
612 ret = peer_clear(peer, &nnode);
613 else
614 ret = peer_clear_soft(peer, afi, safi, stype);
615
616 if (ret < 0)
617 bgp_clear_vty_error(vty, peer, afi, safi, ret);
618 else
619 found = true;
620 }
621
622 /* This is to apply read-only mode on this clear. */
623 if (stype == BGP_CLEAR_SOFT_NONE)
624 bgp->update_delay_over = 0;
625
626 if (!found)
627 vty_out(vty, "%%BGP: No %s peer configured\n",
628 afi_safi_print(afi, safi));
629
630 return CMD_SUCCESS;
631 }
632
633 /* Clear specified neighbor. */
634 if (sort == clear_peer) {
635 union sockunion su;
636
637 /* Make sockunion for lookup. */
638 ret = str2sockunion(arg, &su);
639 if (ret < 0) {
640 peer = peer_lookup_by_conf_if(bgp, arg);
641 if (!peer) {
642 peer = peer_lookup_by_hostname(bgp, arg);
643 if (!peer) {
644 vty_out(vty,
645 "Malformed address or name: %s\n",
646 arg);
647 return CMD_WARNING;
648 }
649 }
650 } else {
651 peer = peer_lookup(bgp, &su);
652 if (!peer) {
653 vty_out(vty,
654 "%%BGP: Unknown neighbor - \"%s\"\n",
655 arg);
656 return CMD_WARNING;
657 }
658 }
659
660 if (!peer->afc[afi][safi])
661 ret = BGP_ERR_AF_UNCONFIGURED;
662 else if (stype == BGP_CLEAR_SOFT_NONE)
663 ret = peer_clear(peer, NULL);
664 else
665 ret = peer_clear_soft(peer, afi, safi, stype);
666
667 if (ret < 0)
668 bgp_clear_vty_error(vty, peer, afi, safi, ret);
669
670 return CMD_SUCCESS;
671 }
672
673 /* Clear all neighbors belonging to a specific peer-group. */
674 if (sort == clear_group) {
675 struct peer_group *group;
676
677 group = peer_group_lookup(bgp, arg);
678 if (!group) {
679 vty_out(vty, "%%BGP: No such peer-group %s\n", arg);
680 return CMD_WARNING;
681 }
682
683 for (ALL_LIST_ELEMENTS(group->peer, node, nnode, peer)) {
684 if (!peer->afc[afi][safi])
685 continue;
686
687 if (stype == BGP_CLEAR_SOFT_NONE)
688 ret = peer_clear(peer, NULL);
689 else
690 ret = peer_clear_soft(peer, afi, safi, stype);
691
692 if (ret < 0)
693 bgp_clear_vty_error(vty, peer, afi, safi, ret);
694 else
695 found = true;
696 }
697
698 if (!found)
699 vty_out(vty,
700 "%%BGP: No %s peer belonging to peer-group %s is configured\n",
701 afi_safi_print(afi, safi), arg);
702
703 return CMD_SUCCESS;
704 }
705
706 /* Clear all external (eBGP) neighbors. */
707 if (sort == clear_external) {
708 for (ALL_LIST_ELEMENTS(bgp->peer, node, nnode, peer)) {
709 if (peer->sort == BGP_PEER_IBGP)
710 continue;
711
712 if (!peer->afc[afi][safi])
713 continue;
714
715 if (stype == BGP_CLEAR_SOFT_NONE)
716 ret = peer_clear(peer, &nnode);
717 else
718 ret = peer_clear_soft(peer, afi, safi, stype);
719
720 if (ret < 0)
721 bgp_clear_vty_error(vty, peer, afi, safi, ret);
722 else
723 found = true;
724 }
725
726 if (!found)
727 vty_out(vty,
728 "%%BGP: No external %s peer is configured\n",
729 afi_safi_print(afi, safi));
730
731 return CMD_SUCCESS;
732 }
733
734 /* Clear all neighbors belonging to a specific AS. */
735 if (sort == clear_as) {
736 as_t as = strtoul(arg, NULL, 10);
737
738 for (ALL_LIST_ELEMENTS(bgp->peer, node, nnode, peer)) {
739 if (peer->as != as)
740 continue;
741
742 if (!peer->afc[afi][safi])
743 ret = BGP_ERR_AF_UNCONFIGURED;
744 else if (stype == BGP_CLEAR_SOFT_NONE)
745 ret = peer_clear(peer, &nnode);
746 else
747 ret = peer_clear_soft(peer, afi, safi, stype);
748
749 if (ret < 0)
750 bgp_clear_vty_error(vty, peer, afi, safi, ret);
751 else
752 found = true;
753 }
754
755 if (!found)
756 vty_out(vty,
757 "%%BGP: No %s peer is configured with AS %s\n",
758 afi_safi_print(afi, safi), arg);
759
760 return CMD_SUCCESS;
761 }
762
763 return CMD_SUCCESS;
764 }
765
766 static int bgp_clear_vty(struct vty *vty, const char *name, afi_t afi,
767 safi_t safi, enum clear_sort sort,
768 enum bgp_clear_type stype, const char *arg)
769 {
770 struct bgp *bgp;
771
772 /* BGP structure lookup. */
773 if (name) {
774 bgp = bgp_lookup_by_name(name);
775 if (bgp == NULL) {
776 vty_out(vty, "Can't find BGP instance %s\n", name);
777 return CMD_WARNING;
778 }
779 } else {
780 bgp = bgp_get_default();
781 if (bgp == NULL) {
782 vty_out(vty, "No BGP process is configured\n");
783 return CMD_WARNING;
784 }
785 }
786
787 return bgp_clear(vty, bgp, afi, safi, sort, stype, arg);
788 }
789
790 /* clear soft inbound */
791 static void bgp_clear_star_soft_in(struct vty *vty, const char *name)
792 {
793 afi_t afi;
794 safi_t safi;
795
796 FOREACH_AFI_SAFI (afi, safi)
797 bgp_clear_vty(vty, name, afi, safi, clear_all,
798 BGP_CLEAR_SOFT_IN, NULL);
799 }
800
801 /* clear soft outbound */
802 static void bgp_clear_star_soft_out(struct vty *vty, const char *name)
803 {
804 afi_t afi;
805 safi_t safi;
806
807 FOREACH_AFI_SAFI (afi, safi)
808 bgp_clear_vty(vty, name, afi, safi, clear_all,
809 BGP_CLEAR_SOFT_OUT, NULL);
810 }
811
812
813 #ifndef VTYSH_EXTRACT_PL
814 #include "bgpd/bgp_vty_clippy.c"
815 #endif
816
817 /* BGP global configuration. */
818 #if (CONFDATE > 20190601)
819 CPP_NOTICE("bgpd: time to remove deprecated bgp multiple-instance")
820 CPP_NOTICE("This includes BGP_OPT_MULTIPLE_INSTANCE")
821 #endif
822 DEFUN_HIDDEN (bgp_multiple_instance_func,
823 bgp_multiple_instance_cmd,
824 "bgp multiple-instance",
825 BGP_STR
826 "Enable bgp multiple instance\n")
827 {
828 bgp_option_set(BGP_OPT_MULTIPLE_INSTANCE);
829 return CMD_SUCCESS;
830 }
831
832 DEFUN_HIDDEN (no_bgp_multiple_instance,
833 no_bgp_multiple_instance_cmd,
834 "no bgp multiple-instance",
835 NO_STR
836 BGP_STR
837 "BGP multiple instance\n")
838 {
839 int ret;
840
841 vty_out(vty, "This config option is deprecated, and is scheduled for removal.\n");
842 vty_out(vty, "if you are using this please let the developers know\n");
843 zlog_info("Deprecated option: `bgp multiple-instance` being used");
844 ret = bgp_option_unset(BGP_OPT_MULTIPLE_INSTANCE);
845 if (ret < 0) {
846 vty_out(vty, "%% There are more than two BGP instances\n");
847 return CMD_WARNING_CONFIG_FAILED;
848 }
849 return CMD_SUCCESS;
850 }
851
852 DEFUN_HIDDEN (bgp_local_mac,
853 bgp_local_mac_cmd,
854 "bgp local-mac vni " CMD_VNI_RANGE " mac WORD seq (0-4294967295)",
855 BGP_STR
856 "Local MAC config\n"
857 "VxLAN Network Identifier\n"
858 "VNI number\n"
859 "local mac\n"
860 "mac address\n"
861 "mac-mobility sequence\n"
862 "seq number\n")
863 {
864 int rv;
865 vni_t vni;
866 struct ethaddr mac;
867 struct ipaddr ip;
868 uint32_t seq;
869 struct bgp *bgp;
870
871 vni = strtoul(argv[3]->arg, NULL, 10);
872 if (!prefix_str2mac(argv[5]->arg, &mac)) {
873 vty_out(vty, "%% Malformed MAC address\n");
874 return CMD_WARNING;
875 }
876 memset(&ip, 0, sizeof(ip));
877 seq = strtoul(argv[7]->arg, NULL, 10);
878
879 bgp = bgp_get_default();
880 if (!bgp) {
881 vty_out(vty, "Default BGP instance is not there\n");
882 return CMD_WARNING;
883 }
884
885 rv = bgp_evpn_local_macip_add(bgp, vni, &mac, &ip, 0 /* flags */, seq);
886 if (rv < 0) {
887 vty_out(vty, "Internal error\n");
888 return CMD_WARNING;
889 }
890
891 return CMD_SUCCESS;
892 }
893
894 DEFUN_HIDDEN (no_bgp_local_mac,
895 no_bgp_local_mac_cmd,
896 "no bgp local-mac vni " CMD_VNI_RANGE " mac WORD",
897 NO_STR
898 BGP_STR
899 "Local MAC config\n"
900 "VxLAN Network Identifier\n"
901 "VNI number\n"
902 "local mac\n"
903 "mac address\n")
904 {
905 int rv;
906 vni_t vni;
907 struct ethaddr mac;
908 struct ipaddr ip;
909 struct bgp *bgp;
910
911 vni = strtoul(argv[4]->arg, NULL, 10);
912 if (!prefix_str2mac(argv[6]->arg, &mac)) {
913 vty_out(vty, "%% Malformed MAC address\n");
914 return CMD_WARNING;
915 }
916 memset(&ip, 0, sizeof(ip));
917
918 bgp = bgp_get_default();
919 if (!bgp) {
920 vty_out(vty, "Default BGP instance is not there\n");
921 return CMD_WARNING;
922 }
923
924 rv = bgp_evpn_local_macip_del(bgp, vni, &mac, &ip, ZEBRA_NEIGH_ACTIVE);
925 if (rv < 0) {
926 vty_out(vty, "Internal error\n");
927 return CMD_WARNING;
928 }
929
930 return CMD_SUCCESS;
931 }
932
933 #if (CONFDATE > 20190601)
934 CPP_NOTICE("bgpd: time to remove deprecated cli bgp config-type cisco")
935 CPP_NOTICE("This includes BGP_OPT_CISCO_CONFIG")
936 #endif
937 DEFUN_HIDDEN (bgp_config_type,
938 bgp_config_type_cmd,
939 "bgp config-type <cisco|zebra>",
940 BGP_STR
941 "Configuration type\n"
942 "cisco\n"
943 "zebra\n")
944 {
945 int idx = 0;
946 if (argv_find(argv, argc, "cisco", &idx)) {
947 vty_out(vty, "This config option is deprecated, and is scheduled for removal.\n");
948 vty_out(vty, "if you are using this please let the developers know!\n");
949 zlog_info("Deprecated option: `bgp config-type cisco` being used");
950 bgp_option_set(BGP_OPT_CONFIG_CISCO);
951 } else
952 bgp_option_unset(BGP_OPT_CONFIG_CISCO);
953
954 return CMD_SUCCESS;
955 }
956
957 DEFUN_HIDDEN (no_bgp_config_type,
958 no_bgp_config_type_cmd,
959 "no bgp config-type [<cisco|zebra>]",
960 NO_STR
961 BGP_STR
962 "Display configuration type\n"
963 "cisco\n"
964 "zebra\n")
965 {
966 bgp_option_unset(BGP_OPT_CONFIG_CISCO);
967 return CMD_SUCCESS;
968 }
969
970
971 DEFUN (no_synchronization,
972 no_synchronization_cmd,
973 "no synchronization",
974 NO_STR
975 "Perform IGP synchronization\n")
976 {
977 return CMD_SUCCESS;
978 }
979
980 DEFUN (no_auto_summary,
981 no_auto_summary_cmd,
982 "no auto-summary",
983 NO_STR
984 "Enable automatic network number summarization\n")
985 {
986 return CMD_SUCCESS;
987 }
988
989 /* "router bgp" commands. */
990 DEFUN_NOSH (router_bgp,
991 router_bgp_cmd,
992 "router bgp [(1-4294967295) [<view|vrf> VIEWVRFNAME]]",
993 ROUTER_STR
994 BGP_STR
995 AS_STR
996 BGP_INSTANCE_HELP_STR)
997 {
998 int idx_asn = 2;
999 int idx_view_vrf = 3;
1000 int idx_vrf = 4;
1001 int is_new_bgp = 0;
1002 int ret;
1003 as_t as;
1004 struct bgp *bgp;
1005 const char *name = NULL;
1006 enum bgp_instance_type inst_type;
1007
1008 // "router bgp" without an ASN
1009 if (argc == 2) {
1010 // Pending: Make VRF option available for ASN less config
1011 bgp = bgp_get_default();
1012
1013 if (bgp == NULL) {
1014 vty_out(vty, "%% No BGP process is configured\n");
1015 return CMD_WARNING_CONFIG_FAILED;
1016 }
1017
1018 if (listcount(bm->bgp) > 1) {
1019 vty_out(vty, "%% Please specify ASN and VRF\n");
1020 return CMD_WARNING_CONFIG_FAILED;
1021 }
1022 }
1023
1024 // "router bgp X"
1025 else {
1026 as = strtoul(argv[idx_asn]->arg, NULL, 10);
1027
1028 inst_type = BGP_INSTANCE_TYPE_DEFAULT;
1029 if (argc > 3) {
1030 name = argv[idx_vrf]->arg;
1031
1032 if (!strcmp(argv[idx_view_vrf]->text, "vrf")) {
1033 if (strmatch(name, VRF_DEFAULT_NAME))
1034 name = NULL;
1035 else
1036 inst_type = BGP_INSTANCE_TYPE_VRF;
1037 } else if (!strcmp(argv[idx_view_vrf]->text, "view"))
1038 inst_type = BGP_INSTANCE_TYPE_VIEW;
1039 }
1040
1041 if (inst_type == BGP_INSTANCE_TYPE_DEFAULT)
1042 is_new_bgp = (bgp_lookup(as, name) == NULL);
1043
1044 ret = bgp_get(&bgp, &as, name, inst_type);
1045 switch (ret) {
1046 case BGP_ERR_MULTIPLE_INSTANCE_NOT_SET:
1047 vty_out(vty,
1048 "Please specify 'bgp multiple-instance' first\n");
1049 return CMD_WARNING_CONFIG_FAILED;
1050 case BGP_ERR_AS_MISMATCH:
1051 vty_out(vty, "BGP is already running; AS is %u\n", as);
1052 return CMD_WARNING_CONFIG_FAILED;
1053 case BGP_ERR_INSTANCE_MISMATCH:
1054 vty_out(vty,
1055 "BGP instance name and AS number mismatch\n");
1056 vty_out(vty,
1057 "BGP instance is already running; AS is %u\n",
1058 as);
1059 return CMD_WARNING_CONFIG_FAILED;
1060 }
1061
1062 /*
1063 * If we just instantiated the default instance, complete
1064 * any pending VRF-VPN leaking that was configured via
1065 * earlier "router bgp X vrf FOO" blocks.
1066 */
1067 if (is_new_bgp && inst_type == BGP_INSTANCE_TYPE_DEFAULT)
1068 vpn_leak_postchange_all();
1069
1070 /* Pending: handle when user tries to change a view to vrf n vv.
1071 */
1072 }
1073
1074 /* unset the auto created flag as the user config is now present */
1075 UNSET_FLAG(bgp->vrf_flags, BGP_VRF_AUTO);
1076 VTY_PUSH_CONTEXT(BGP_NODE, bgp);
1077
1078 return CMD_SUCCESS;
1079 }
1080
1081 /* "no router bgp" commands. */
1082 DEFUN (no_router_bgp,
1083 no_router_bgp_cmd,
1084 "no router bgp [(1-4294967295) [<view|vrf> VIEWVRFNAME]]",
1085 NO_STR
1086 ROUTER_STR
1087 BGP_STR
1088 AS_STR
1089 BGP_INSTANCE_HELP_STR)
1090 {
1091 int idx_asn = 3;
1092 int idx_vrf = 5;
1093 as_t as;
1094 struct bgp *bgp;
1095 const char *name = NULL;
1096
1097 // "no router bgp" without an ASN
1098 if (argc == 3) {
1099 // Pending: Make VRF option available for ASN less config
1100 bgp = bgp_get_default();
1101
1102 if (bgp == NULL) {
1103 vty_out(vty, "%% No BGP process is configured\n");
1104 return CMD_WARNING_CONFIG_FAILED;
1105 }
1106
1107 if (listcount(bm->bgp) > 1) {
1108 vty_out(vty, "%% Please specify ASN and VRF\n");
1109 return CMD_WARNING_CONFIG_FAILED;
1110 }
1111
1112 if (bgp->l3vni) {
1113 vty_out(vty, "%% Please unconfigure l3vni %u",
1114 bgp->l3vni);
1115 return CMD_WARNING_CONFIG_FAILED;
1116 }
1117 } else {
1118 as = strtoul(argv[idx_asn]->arg, NULL, 10);
1119
1120 if (argc > 4)
1121 name = argv[idx_vrf]->arg;
1122
1123 /* Lookup bgp structure. */
1124 bgp = bgp_lookup(as, name);
1125 if (!bgp) {
1126 vty_out(vty, "%% Can't find BGP instance\n");
1127 return CMD_WARNING_CONFIG_FAILED;
1128 }
1129
1130 if (bgp->l3vni) {
1131 vty_out(vty, "%% Please unconfigure l3vni %u",
1132 bgp->l3vni);
1133 return CMD_WARNING_CONFIG_FAILED;
1134 }
1135 }
1136
1137 bgp_delete(bgp);
1138
1139 return CMD_SUCCESS;
1140 }
1141
1142
1143 /* BGP router-id. */
1144
1145 DEFPY (bgp_router_id,
1146 bgp_router_id_cmd,
1147 "bgp router-id A.B.C.D",
1148 BGP_STR
1149 "Override configured router identifier\n"
1150 "Manually configured router identifier\n")
1151 {
1152 VTY_DECLVAR_CONTEXT(bgp, bgp);
1153 bgp_router_id_static_set(bgp, router_id);
1154 return CMD_SUCCESS;
1155 }
1156
1157 DEFPY (no_bgp_router_id,
1158 no_bgp_router_id_cmd,
1159 "no bgp router-id [A.B.C.D]",
1160 NO_STR
1161 BGP_STR
1162 "Override configured router identifier\n"
1163 "Manually configured router identifier\n")
1164 {
1165 VTY_DECLVAR_CONTEXT(bgp, bgp);
1166
1167 if (router_id_str) {
1168 if (!IPV4_ADDR_SAME(&bgp->router_id_static, &router_id)) {
1169 vty_out(vty, "%% BGP router-id doesn't match\n");
1170 return CMD_WARNING_CONFIG_FAILED;
1171 }
1172 }
1173
1174 router_id.s_addr = 0;
1175 bgp_router_id_static_set(bgp, router_id);
1176
1177 return CMD_SUCCESS;
1178 }
1179
1180
1181 /* BGP Cluster ID. */
1182 DEFUN (bgp_cluster_id,
1183 bgp_cluster_id_cmd,
1184 "bgp cluster-id <A.B.C.D|(1-4294967295)>",
1185 BGP_STR
1186 "Configure Route-Reflector Cluster-id\n"
1187 "Route-Reflector Cluster-id in IP address format\n"
1188 "Route-Reflector Cluster-id as 32 bit quantity\n")
1189 {
1190 VTY_DECLVAR_CONTEXT(bgp, bgp);
1191 int idx_ipv4 = 2;
1192 int ret;
1193 struct in_addr cluster;
1194
1195 ret = inet_aton(argv[idx_ipv4]->arg, &cluster);
1196 if (!ret) {
1197 vty_out(vty, "%% Malformed bgp cluster identifier\n");
1198 return CMD_WARNING_CONFIG_FAILED;
1199 }
1200
1201 bgp_cluster_id_set(bgp, &cluster);
1202 bgp_clear_star_soft_out(vty, bgp->name);
1203
1204 return CMD_SUCCESS;
1205 }
1206
1207 DEFUN (no_bgp_cluster_id,
1208 no_bgp_cluster_id_cmd,
1209 "no bgp cluster-id [<A.B.C.D|(1-4294967295)>]",
1210 NO_STR
1211 BGP_STR
1212 "Configure Route-Reflector Cluster-id\n"
1213 "Route-Reflector Cluster-id in IP address format\n"
1214 "Route-Reflector Cluster-id as 32 bit quantity\n")
1215 {
1216 VTY_DECLVAR_CONTEXT(bgp, bgp);
1217 bgp_cluster_id_unset(bgp);
1218 bgp_clear_star_soft_out(vty, bgp->name);
1219
1220 return CMD_SUCCESS;
1221 }
1222
1223 DEFUN (bgp_confederation_identifier,
1224 bgp_confederation_identifier_cmd,
1225 "bgp confederation identifier (1-4294967295)",
1226 "BGP specific commands\n"
1227 "AS confederation parameters\n"
1228 "AS number\n"
1229 "Set routing domain confederation AS\n")
1230 {
1231 VTY_DECLVAR_CONTEXT(bgp, bgp);
1232 int idx_number = 3;
1233 as_t as;
1234
1235 as = strtoul(argv[idx_number]->arg, NULL, 10);
1236
1237 bgp_confederation_id_set(bgp, as);
1238
1239 return CMD_SUCCESS;
1240 }
1241
1242 DEFUN (no_bgp_confederation_identifier,
1243 no_bgp_confederation_identifier_cmd,
1244 "no bgp confederation identifier [(1-4294967295)]",
1245 NO_STR
1246 "BGP specific commands\n"
1247 "AS confederation parameters\n"
1248 "AS number\n"
1249 "Set routing domain confederation AS\n")
1250 {
1251 VTY_DECLVAR_CONTEXT(bgp, bgp);
1252 bgp_confederation_id_unset(bgp);
1253
1254 return CMD_SUCCESS;
1255 }
1256
1257 DEFUN (bgp_confederation_peers,
1258 bgp_confederation_peers_cmd,
1259 "bgp confederation peers (1-4294967295)...",
1260 "BGP specific commands\n"
1261 "AS confederation parameters\n"
1262 "Peer ASs in BGP confederation\n"
1263 AS_STR)
1264 {
1265 VTY_DECLVAR_CONTEXT(bgp, bgp);
1266 int idx_asn = 3;
1267 as_t as;
1268 int i;
1269
1270 for (i = idx_asn; i < argc; i++) {
1271 as = strtoul(argv[i]->arg, NULL, 10);
1272
1273 if (bgp->as == as) {
1274 vty_out(vty,
1275 "%% Local member-AS not allowed in confed peer list\n");
1276 continue;
1277 }
1278
1279 bgp_confederation_peers_add(bgp, as);
1280 }
1281 return CMD_SUCCESS;
1282 }
1283
1284 DEFUN (no_bgp_confederation_peers,
1285 no_bgp_confederation_peers_cmd,
1286 "no bgp confederation peers (1-4294967295)...",
1287 NO_STR
1288 "BGP specific commands\n"
1289 "AS confederation parameters\n"
1290 "Peer ASs in BGP confederation\n"
1291 AS_STR)
1292 {
1293 VTY_DECLVAR_CONTEXT(bgp, bgp);
1294 int idx_asn = 4;
1295 as_t as;
1296 int i;
1297
1298 for (i = idx_asn; i < argc; i++) {
1299 as = strtoul(argv[i]->arg, NULL, 10);
1300
1301 bgp_confederation_peers_remove(bgp, as);
1302 }
1303 return CMD_SUCCESS;
1304 }
1305
1306 /**
1307 * Central routine for maximum-paths configuration.
1308 * @peer_type: BGP_PEER_EBGP or BGP_PEER_IBGP
1309 * @set: 1 for setting values, 0 for removing the max-paths config.
1310 */
1311 static int bgp_maxpaths_config_vty(struct vty *vty, int peer_type,
1312 const char *mpaths, uint16_t options,
1313 int set)
1314 {
1315 VTY_DECLVAR_CONTEXT(bgp, bgp);
1316 uint16_t maxpaths = 0;
1317 int ret;
1318 afi_t afi;
1319 safi_t safi;
1320
1321 afi = bgp_node_afi(vty);
1322 safi = bgp_node_safi(vty);
1323
1324 if (set) {
1325 maxpaths = strtol(mpaths, NULL, 10);
1326 if (maxpaths > multipath_num) {
1327 vty_out(vty,
1328 "%% Maxpaths Specified: %d is > than multipath num specified on bgp command line %d",
1329 maxpaths, multipath_num);
1330 return CMD_WARNING_CONFIG_FAILED;
1331 }
1332 ret = bgp_maximum_paths_set(bgp, afi, safi, peer_type, maxpaths,
1333 options);
1334 } else
1335 ret = bgp_maximum_paths_unset(bgp, afi, safi, peer_type);
1336
1337 if (ret < 0) {
1338 vty_out(vty,
1339 "%% Failed to %sset maximum-paths %s %u for afi %u, safi %u\n",
1340 (set == 1) ? "" : "un",
1341 (peer_type == BGP_PEER_EBGP) ? "ebgp" : "ibgp",
1342 maxpaths, afi, safi);
1343 return CMD_WARNING_CONFIG_FAILED;
1344 }
1345
1346 bgp_recalculate_all_bestpaths(bgp);
1347
1348 return CMD_SUCCESS;
1349 }
1350
1351 DEFUN (bgp_maxmed_admin,
1352 bgp_maxmed_admin_cmd,
1353 "bgp max-med administrative ",
1354 BGP_STR
1355 "Advertise routes with max-med\n"
1356 "Administratively applied, for an indefinite period\n")
1357 {
1358 VTY_DECLVAR_CONTEXT(bgp, bgp);
1359
1360 bgp->v_maxmed_admin = 1;
1361 bgp->maxmed_admin_value = BGP_MAXMED_VALUE_DEFAULT;
1362
1363 bgp_maxmed_update(bgp);
1364
1365 return CMD_SUCCESS;
1366 }
1367
1368 DEFUN (bgp_maxmed_admin_medv,
1369 bgp_maxmed_admin_medv_cmd,
1370 "bgp max-med administrative (0-4294967295)",
1371 BGP_STR
1372 "Advertise routes with max-med\n"
1373 "Administratively applied, for an indefinite period\n"
1374 "Max MED value to be used\n")
1375 {
1376 VTY_DECLVAR_CONTEXT(bgp, bgp);
1377 int idx_number = 3;
1378
1379 bgp->v_maxmed_admin = 1;
1380 bgp->maxmed_admin_value = strtoul(argv[idx_number]->arg, NULL, 10);
1381
1382 bgp_maxmed_update(bgp);
1383
1384 return CMD_SUCCESS;
1385 }
1386
1387 DEFUN (no_bgp_maxmed_admin,
1388 no_bgp_maxmed_admin_cmd,
1389 "no bgp max-med administrative [(0-4294967295)]",
1390 NO_STR
1391 BGP_STR
1392 "Advertise routes with max-med\n"
1393 "Administratively applied, for an indefinite period\n"
1394 "Max MED value to be used\n")
1395 {
1396 VTY_DECLVAR_CONTEXT(bgp, bgp);
1397 bgp->v_maxmed_admin = BGP_MAXMED_ADMIN_UNCONFIGURED;
1398 bgp->maxmed_admin_value = BGP_MAXMED_VALUE_DEFAULT;
1399 bgp_maxmed_update(bgp);
1400
1401 return CMD_SUCCESS;
1402 }
1403
1404 DEFUN (bgp_maxmed_onstartup,
1405 bgp_maxmed_onstartup_cmd,
1406 "bgp max-med on-startup (5-86400) [(0-4294967295)]",
1407 BGP_STR
1408 "Advertise routes with max-med\n"
1409 "Effective on a startup\n"
1410 "Time (seconds) period for max-med\n"
1411 "Max MED value to be used\n")
1412 {
1413 VTY_DECLVAR_CONTEXT(bgp, bgp);
1414 int idx = 0;
1415
1416 argv_find(argv, argc, "(5-86400)", &idx);
1417 bgp->v_maxmed_onstartup = strtoul(argv[idx]->arg, NULL, 10);
1418 if (argv_find(argv, argc, "(0-4294967295)", &idx))
1419 bgp->maxmed_onstartup_value = strtoul(argv[idx]->arg, NULL, 10);
1420 else
1421 bgp->maxmed_onstartup_value = BGP_MAXMED_VALUE_DEFAULT;
1422
1423 bgp_maxmed_update(bgp);
1424
1425 return CMD_SUCCESS;
1426 }
1427
1428 DEFUN (no_bgp_maxmed_onstartup,
1429 no_bgp_maxmed_onstartup_cmd,
1430 "no bgp max-med on-startup [(5-86400) [(0-4294967295)]]",
1431 NO_STR
1432 BGP_STR
1433 "Advertise routes with max-med\n"
1434 "Effective on a startup\n"
1435 "Time (seconds) period for max-med\n"
1436 "Max MED value to be used\n")
1437 {
1438 VTY_DECLVAR_CONTEXT(bgp, bgp);
1439
1440 /* Cancel max-med onstartup if its on */
1441 if (bgp->t_maxmed_onstartup) {
1442 THREAD_TIMER_OFF(bgp->t_maxmed_onstartup);
1443 bgp->maxmed_onstartup_over = 1;
1444 }
1445
1446 bgp->v_maxmed_onstartup = BGP_MAXMED_ONSTARTUP_UNCONFIGURED;
1447 bgp->maxmed_onstartup_value = BGP_MAXMED_VALUE_DEFAULT;
1448
1449 bgp_maxmed_update(bgp);
1450
1451 return CMD_SUCCESS;
1452 }
1453
1454 static int bgp_update_delay_config_vty(struct vty *vty, const char *delay,
1455 const char *wait)
1456 {
1457 VTY_DECLVAR_CONTEXT(bgp, bgp);
1458 uint16_t update_delay;
1459 uint16_t establish_wait;
1460
1461 update_delay = strtoul(delay, NULL, 10);
1462
1463 if (!wait) /* update-delay <delay> */
1464 {
1465 bgp->v_update_delay = update_delay;
1466 bgp->v_establish_wait = bgp->v_update_delay;
1467 return CMD_SUCCESS;
1468 }
1469
1470 /* update-delay <delay> <establish-wait> */
1471 establish_wait = atoi(wait);
1472 if (update_delay < establish_wait) {
1473 vty_out(vty,
1474 "%%Failed: update-delay less than the establish-wait!\n");
1475 return CMD_WARNING_CONFIG_FAILED;
1476 }
1477
1478 bgp->v_update_delay = update_delay;
1479 bgp->v_establish_wait = establish_wait;
1480
1481 return CMD_SUCCESS;
1482 }
1483
1484 static int bgp_update_delay_deconfig_vty(struct vty *vty)
1485 {
1486 VTY_DECLVAR_CONTEXT(bgp, bgp);
1487
1488 bgp->v_update_delay = BGP_UPDATE_DELAY_DEF;
1489 bgp->v_establish_wait = bgp->v_update_delay;
1490
1491 return CMD_SUCCESS;
1492 }
1493
1494 void bgp_config_write_update_delay(struct vty *vty, struct bgp *bgp)
1495 {
1496 if (bgp->v_update_delay != BGP_UPDATE_DELAY_DEF) {
1497 vty_out(vty, " update-delay %d", bgp->v_update_delay);
1498 if (bgp->v_update_delay != bgp->v_establish_wait)
1499 vty_out(vty, " %d", bgp->v_establish_wait);
1500 vty_out(vty, "\n");
1501 }
1502 }
1503
1504
1505 /* Update-delay configuration */
1506 DEFUN (bgp_update_delay,
1507 bgp_update_delay_cmd,
1508 "update-delay (0-3600)",
1509 "Force initial delay for best-path and updates\n"
1510 "Seconds\n")
1511 {
1512 int idx_number = 1;
1513 return bgp_update_delay_config_vty(vty, argv[idx_number]->arg, NULL);
1514 }
1515
1516 DEFUN (bgp_update_delay_establish_wait,
1517 bgp_update_delay_establish_wait_cmd,
1518 "update-delay (0-3600) (1-3600)",
1519 "Force initial delay for best-path and updates\n"
1520 "Seconds\n"
1521 "Seconds\n")
1522 {
1523 int idx_number = 1;
1524 int idx_number_2 = 2;
1525 return bgp_update_delay_config_vty(vty, argv[idx_number]->arg,
1526 argv[idx_number_2]->arg);
1527 }
1528
1529 /* Update-delay deconfiguration */
1530 DEFUN (no_bgp_update_delay,
1531 no_bgp_update_delay_cmd,
1532 "no update-delay [(0-3600) [(1-3600)]]",
1533 NO_STR
1534 "Force initial delay for best-path and updates\n"
1535 "Seconds\n"
1536 "Seconds\n")
1537 {
1538 return bgp_update_delay_deconfig_vty(vty);
1539 }
1540
1541
1542 static int bgp_wpkt_quanta_config_vty(struct vty *vty, const char *num,
1543 char set)
1544 {
1545 VTY_DECLVAR_CONTEXT(bgp, bgp);
1546
1547 if (set) {
1548 uint32_t quanta = strtoul(num, NULL, 10);
1549 atomic_store_explicit(&bgp->wpkt_quanta, quanta,
1550 memory_order_relaxed);
1551 } else {
1552 atomic_store_explicit(&bgp->wpkt_quanta, BGP_WRITE_PACKET_MAX,
1553 memory_order_relaxed);
1554 }
1555
1556 return CMD_SUCCESS;
1557 }
1558
1559 static int bgp_rpkt_quanta_config_vty(struct vty *vty, const char *num,
1560 char set)
1561 {
1562 VTY_DECLVAR_CONTEXT(bgp, bgp);
1563
1564 if (set) {
1565 uint32_t quanta = strtoul(num, NULL, 10);
1566 atomic_store_explicit(&bgp->rpkt_quanta, quanta,
1567 memory_order_relaxed);
1568 } else {
1569 atomic_store_explicit(&bgp->rpkt_quanta, BGP_READ_PACKET_MAX,
1570 memory_order_relaxed);
1571 }
1572
1573 return CMD_SUCCESS;
1574 }
1575
1576 void bgp_config_write_wpkt_quanta(struct vty *vty, struct bgp *bgp)
1577 {
1578 uint32_t quanta =
1579 atomic_load_explicit(&bgp->wpkt_quanta, memory_order_relaxed);
1580 if (quanta != BGP_WRITE_PACKET_MAX)
1581 vty_out(vty, " write-quanta %d\n", quanta);
1582 }
1583
1584 void bgp_config_write_rpkt_quanta(struct vty *vty, struct bgp *bgp)
1585 {
1586 uint32_t quanta =
1587 atomic_load_explicit(&bgp->rpkt_quanta, memory_order_relaxed);
1588 if (quanta != BGP_READ_PACKET_MAX)
1589 vty_out(vty, " read-quanta %d\n", quanta);
1590 }
1591
1592 /* Packet quanta configuration */
1593 DEFUN (bgp_wpkt_quanta,
1594 bgp_wpkt_quanta_cmd,
1595 "write-quanta (1-10)",
1596 "How many packets to write to peer socket per run\n"
1597 "Number of packets\n")
1598 {
1599 int idx_number = 1;
1600 return bgp_wpkt_quanta_config_vty(vty, argv[idx_number]->arg, 1);
1601 }
1602
1603 DEFUN (no_bgp_wpkt_quanta,
1604 no_bgp_wpkt_quanta_cmd,
1605 "no write-quanta (1-10)",
1606 NO_STR
1607 "How many packets to write to peer socket per I/O cycle\n"
1608 "Number of packets\n")
1609 {
1610 int idx_number = 2;
1611 return bgp_wpkt_quanta_config_vty(vty, argv[idx_number]->arg, 0);
1612 }
1613
1614 DEFUN (bgp_rpkt_quanta,
1615 bgp_rpkt_quanta_cmd,
1616 "read-quanta (1-10)",
1617 "How many packets to read from peer socket per I/O cycle\n"
1618 "Number of packets\n")
1619 {
1620 int idx_number = 1;
1621 return bgp_rpkt_quanta_config_vty(vty, argv[idx_number]->arg, 1);
1622 }
1623
1624 DEFUN (no_bgp_rpkt_quanta,
1625 no_bgp_rpkt_quanta_cmd,
1626 "no read-quanta (1-10)",
1627 NO_STR
1628 "How many packets to read from peer socket per I/O cycle\n"
1629 "Number of packets\n")
1630 {
1631 int idx_number = 2;
1632 return bgp_rpkt_quanta_config_vty(vty, argv[idx_number]->arg, 0);
1633 }
1634
1635 void bgp_config_write_coalesce_time(struct vty *vty, struct bgp *bgp)
1636 {
1637 if (!bgp->heuristic_coalesce)
1638 vty_out(vty, " coalesce-time %u\n", bgp->coalesce_time);
1639 }
1640
1641
1642 DEFUN (bgp_coalesce_time,
1643 bgp_coalesce_time_cmd,
1644 "coalesce-time (0-4294967295)",
1645 "Subgroup coalesce timer\n"
1646 "Subgroup coalesce timer value (in ms)\n")
1647 {
1648 VTY_DECLVAR_CONTEXT(bgp, bgp);
1649
1650 int idx = 0;
1651 argv_find(argv, argc, "(0-4294967295)", &idx);
1652 bgp->heuristic_coalesce = false;
1653 bgp->coalesce_time = strtoul(argv[idx]->arg, NULL, 10);
1654 return CMD_SUCCESS;
1655 }
1656
1657 DEFUN (no_bgp_coalesce_time,
1658 no_bgp_coalesce_time_cmd,
1659 "no coalesce-time (0-4294967295)",
1660 NO_STR
1661 "Subgroup coalesce timer\n"
1662 "Subgroup coalesce timer value (in ms)\n")
1663 {
1664 VTY_DECLVAR_CONTEXT(bgp, bgp);
1665
1666 bgp->heuristic_coalesce = true;
1667 bgp->coalesce_time = BGP_DEFAULT_SUBGROUP_COALESCE_TIME;
1668 return CMD_SUCCESS;
1669 }
1670
1671 /* Maximum-paths configuration */
1672 DEFUN (bgp_maxpaths,
1673 bgp_maxpaths_cmd,
1674 "maximum-paths " CMD_RANGE_STR(1, MULTIPATH_NUM),
1675 "Forward packets over multiple paths\n"
1676 "Number of paths\n")
1677 {
1678 int idx_number = 1;
1679 return bgp_maxpaths_config_vty(vty, BGP_PEER_EBGP,
1680 argv[idx_number]->arg, 0, 1);
1681 }
1682
1683 ALIAS_HIDDEN(bgp_maxpaths, bgp_maxpaths_hidden_cmd,
1684 "maximum-paths " CMD_RANGE_STR(1, MULTIPATH_NUM),
1685 "Forward packets over multiple paths\n"
1686 "Number of paths\n")
1687
1688 DEFUN (bgp_maxpaths_ibgp,
1689 bgp_maxpaths_ibgp_cmd,
1690 "maximum-paths ibgp " CMD_RANGE_STR(1, MULTIPATH_NUM),
1691 "Forward packets over multiple paths\n"
1692 "iBGP-multipath\n"
1693 "Number of paths\n")
1694 {
1695 int idx_number = 2;
1696 return bgp_maxpaths_config_vty(vty, BGP_PEER_IBGP,
1697 argv[idx_number]->arg, 0, 1);
1698 }
1699
1700 ALIAS_HIDDEN(bgp_maxpaths_ibgp, bgp_maxpaths_ibgp_hidden_cmd,
1701 "maximum-paths ibgp " CMD_RANGE_STR(1, MULTIPATH_NUM),
1702 "Forward packets over multiple paths\n"
1703 "iBGP-multipath\n"
1704 "Number of paths\n")
1705
1706 DEFUN (bgp_maxpaths_ibgp_cluster,
1707 bgp_maxpaths_ibgp_cluster_cmd,
1708 "maximum-paths ibgp " CMD_RANGE_STR(1, MULTIPATH_NUM) " equal-cluster-length",
1709 "Forward packets over multiple paths\n"
1710 "iBGP-multipath\n"
1711 "Number of paths\n"
1712 "Match the cluster length\n")
1713 {
1714 int idx_number = 2;
1715 return bgp_maxpaths_config_vty(
1716 vty, BGP_PEER_IBGP, argv[idx_number]->arg,
1717 BGP_FLAG_IBGP_MULTIPATH_SAME_CLUSTERLEN, 1);
1718 }
1719
1720 ALIAS_HIDDEN(bgp_maxpaths_ibgp_cluster, bgp_maxpaths_ibgp_cluster_hidden_cmd,
1721 "maximum-paths ibgp " CMD_RANGE_STR(
1722 1, MULTIPATH_NUM) " equal-cluster-length",
1723 "Forward packets over multiple paths\n"
1724 "iBGP-multipath\n"
1725 "Number of paths\n"
1726 "Match the cluster length\n")
1727
1728 DEFUN (no_bgp_maxpaths,
1729 no_bgp_maxpaths_cmd,
1730 "no maximum-paths [" CMD_RANGE_STR(1, MULTIPATH_NUM) "]",
1731 NO_STR
1732 "Forward packets over multiple paths\n"
1733 "Number of paths\n")
1734 {
1735 return bgp_maxpaths_config_vty(vty, BGP_PEER_EBGP, NULL, 0, 0);
1736 }
1737
1738 ALIAS_HIDDEN(no_bgp_maxpaths, no_bgp_maxpaths_hidden_cmd,
1739 "no maximum-paths [" CMD_RANGE_STR(1, MULTIPATH_NUM) "]", NO_STR
1740 "Forward packets over multiple paths\n"
1741 "Number of paths\n")
1742
1743 DEFUN (no_bgp_maxpaths_ibgp,
1744 no_bgp_maxpaths_ibgp_cmd,
1745 "no maximum-paths ibgp [" CMD_RANGE_STR(1, MULTIPATH_NUM) " [equal-cluster-length]]",
1746 NO_STR
1747 "Forward packets over multiple paths\n"
1748 "iBGP-multipath\n"
1749 "Number of paths\n"
1750 "Match the cluster length\n")
1751 {
1752 return bgp_maxpaths_config_vty(vty, BGP_PEER_IBGP, NULL, 0, 0);
1753 }
1754
1755 ALIAS_HIDDEN(no_bgp_maxpaths_ibgp, no_bgp_maxpaths_ibgp_hidden_cmd,
1756 "no maximum-paths ibgp [" CMD_RANGE_STR(
1757 1, MULTIPATH_NUM) " [equal-cluster-length]]",
1758 NO_STR
1759 "Forward packets over multiple paths\n"
1760 "iBGP-multipath\n"
1761 "Number of paths\n"
1762 "Match the cluster length\n")
1763
1764 void bgp_config_write_maxpaths(struct vty *vty, struct bgp *bgp, afi_t afi,
1765 safi_t safi)
1766 {
1767 if (bgp->maxpaths[afi][safi].maxpaths_ebgp != MULTIPATH_NUM) {
1768 vty_out(vty, " maximum-paths %d\n",
1769 bgp->maxpaths[afi][safi].maxpaths_ebgp);
1770 }
1771
1772 if (bgp->maxpaths[afi][safi].maxpaths_ibgp != MULTIPATH_NUM) {
1773 vty_out(vty, " maximum-paths ibgp %d",
1774 bgp->maxpaths[afi][safi].maxpaths_ibgp);
1775 if (CHECK_FLAG(bgp->maxpaths[afi][safi].ibgp_flags,
1776 BGP_FLAG_IBGP_MULTIPATH_SAME_CLUSTERLEN))
1777 vty_out(vty, " equal-cluster-length");
1778 vty_out(vty, "\n");
1779 }
1780 }
1781
1782 /* BGP timers. */
1783
1784 DEFUN (bgp_timers,
1785 bgp_timers_cmd,
1786 "timers bgp (0-65535) (0-65535)",
1787 "Adjust routing timers\n"
1788 "BGP timers\n"
1789 "Keepalive interval\n"
1790 "Holdtime\n")
1791 {
1792 VTY_DECLVAR_CONTEXT(bgp, bgp);
1793 int idx_number = 2;
1794 int idx_number_2 = 3;
1795 unsigned long keepalive = 0;
1796 unsigned long holdtime = 0;
1797
1798 keepalive = strtoul(argv[idx_number]->arg, NULL, 10);
1799 holdtime = strtoul(argv[idx_number_2]->arg, NULL, 10);
1800
1801 /* Holdtime value check. */
1802 if (holdtime < 3 && holdtime != 0) {
1803 vty_out(vty,
1804 "%% hold time value must be either 0 or greater than 3\n");
1805 return CMD_WARNING_CONFIG_FAILED;
1806 }
1807
1808 bgp_timers_set(bgp, keepalive, holdtime);
1809
1810 return CMD_SUCCESS;
1811 }
1812
1813 DEFUN (no_bgp_timers,
1814 no_bgp_timers_cmd,
1815 "no timers bgp [(0-65535) (0-65535)]",
1816 NO_STR
1817 "Adjust routing timers\n"
1818 "BGP timers\n"
1819 "Keepalive interval\n"
1820 "Holdtime\n")
1821 {
1822 VTY_DECLVAR_CONTEXT(bgp, bgp);
1823 bgp_timers_unset(bgp);
1824
1825 return CMD_SUCCESS;
1826 }
1827
1828
1829 DEFUN (bgp_client_to_client_reflection,
1830 bgp_client_to_client_reflection_cmd,
1831 "bgp client-to-client reflection",
1832 "BGP specific commands\n"
1833 "Configure client to client route reflection\n"
1834 "reflection of routes allowed\n")
1835 {
1836 VTY_DECLVAR_CONTEXT(bgp, bgp);
1837 bgp_flag_unset(bgp, BGP_FLAG_NO_CLIENT_TO_CLIENT);
1838 bgp_clear_star_soft_out(vty, bgp->name);
1839
1840 return CMD_SUCCESS;
1841 }
1842
1843 DEFUN (no_bgp_client_to_client_reflection,
1844 no_bgp_client_to_client_reflection_cmd,
1845 "no bgp client-to-client reflection",
1846 NO_STR
1847 "BGP specific commands\n"
1848 "Configure client to client route reflection\n"
1849 "reflection of routes allowed\n")
1850 {
1851 VTY_DECLVAR_CONTEXT(bgp, bgp);
1852 bgp_flag_set(bgp, BGP_FLAG_NO_CLIENT_TO_CLIENT);
1853 bgp_clear_star_soft_out(vty, bgp->name);
1854
1855 return CMD_SUCCESS;
1856 }
1857
1858 /* "bgp always-compare-med" configuration. */
1859 DEFUN (bgp_always_compare_med,
1860 bgp_always_compare_med_cmd,
1861 "bgp always-compare-med",
1862 "BGP specific commands\n"
1863 "Allow comparing MED from different neighbors\n")
1864 {
1865 VTY_DECLVAR_CONTEXT(bgp, bgp);
1866 bgp_flag_set(bgp, BGP_FLAG_ALWAYS_COMPARE_MED);
1867 bgp_recalculate_all_bestpaths(bgp);
1868
1869 return CMD_SUCCESS;
1870 }
1871
1872 DEFUN (no_bgp_always_compare_med,
1873 no_bgp_always_compare_med_cmd,
1874 "no bgp always-compare-med",
1875 NO_STR
1876 "BGP specific commands\n"
1877 "Allow comparing MED from different neighbors\n")
1878 {
1879 VTY_DECLVAR_CONTEXT(bgp, bgp);
1880 bgp_flag_unset(bgp, BGP_FLAG_ALWAYS_COMPARE_MED);
1881 bgp_recalculate_all_bestpaths(bgp);
1882
1883 return CMD_SUCCESS;
1884 }
1885
1886
1887 DEFUN(bgp_ebgp_requires_policy, bgp_ebgp_requires_policy_cmd,
1888 "bgp ebgp-requires-policy",
1889 "BGP specific commands\n"
1890 "Require in and out policy for eBGP peers (RFC8212)\n")
1891 {
1892 VTY_DECLVAR_CONTEXT(bgp, bgp);
1893 bgp->ebgp_requires_policy = DEFAULT_EBGP_POLICY_ENABLED;
1894 return CMD_SUCCESS;
1895 }
1896
1897 DEFUN(no_bgp_ebgp_requires_policy, no_bgp_ebgp_requires_policy_cmd,
1898 "no bgp ebgp-requires-policy",
1899 NO_STR
1900 "BGP specific commands\n"
1901 "Require in and out policy for eBGP peers (RFC8212)\n")
1902 {
1903 VTY_DECLVAR_CONTEXT(bgp, bgp);
1904 bgp->ebgp_requires_policy = DEFAULT_EBGP_POLICY_DISABLED;
1905 return CMD_SUCCESS;
1906 }
1907
1908
1909 /* "bgp deterministic-med" configuration. */
1910 DEFUN (bgp_deterministic_med,
1911 bgp_deterministic_med_cmd,
1912 "bgp deterministic-med",
1913 "BGP specific commands\n"
1914 "Pick the best-MED path among paths advertised from the neighboring AS\n")
1915 {
1916 VTY_DECLVAR_CONTEXT(bgp, bgp);
1917
1918 if (!bgp_flag_check(bgp, BGP_FLAG_DETERMINISTIC_MED)) {
1919 bgp_flag_set(bgp, BGP_FLAG_DETERMINISTIC_MED);
1920 bgp_recalculate_all_bestpaths(bgp);
1921 }
1922
1923 return CMD_SUCCESS;
1924 }
1925
1926 DEFUN (no_bgp_deterministic_med,
1927 no_bgp_deterministic_med_cmd,
1928 "no bgp deterministic-med",
1929 NO_STR
1930 "BGP specific commands\n"
1931 "Pick the best-MED path among paths advertised from the neighboring AS\n")
1932 {
1933 VTY_DECLVAR_CONTEXT(bgp, bgp);
1934 int bestpath_per_as_used;
1935 afi_t afi;
1936 safi_t safi;
1937 struct peer *peer;
1938 struct listnode *node, *nnode;
1939
1940 if (bgp_flag_check(bgp, BGP_FLAG_DETERMINISTIC_MED)) {
1941 bestpath_per_as_used = 0;
1942
1943 for (ALL_LIST_ELEMENTS(bgp->peer, node, nnode, peer)) {
1944 FOREACH_AFI_SAFI (afi, safi)
1945 if (bgp_addpath_dmed_required(
1946 peer->addpath_type[afi][safi])) {
1947 bestpath_per_as_used = 1;
1948 break;
1949 }
1950
1951 if (bestpath_per_as_used)
1952 break;
1953 }
1954
1955 if (bestpath_per_as_used) {
1956 vty_out(vty,
1957 "bgp deterministic-med cannot be disabled while addpath-tx-bestpath-per-AS is in use\n");
1958 return CMD_WARNING_CONFIG_FAILED;
1959 } else {
1960 bgp_flag_unset(bgp, BGP_FLAG_DETERMINISTIC_MED);
1961 bgp_recalculate_all_bestpaths(bgp);
1962 }
1963 }
1964
1965 return CMD_SUCCESS;
1966 }
1967
1968 /* "bgp graceful-restart" configuration. */
1969 DEFUN (bgp_graceful_restart,
1970 bgp_graceful_restart_cmd,
1971 "bgp graceful-restart",
1972 "BGP specific commands\n"
1973 "Graceful restart capability parameters\n")
1974 {
1975 VTY_DECLVAR_CONTEXT(bgp, bgp);
1976 bgp_flag_set(bgp, BGP_FLAG_GRACEFUL_RESTART);
1977 return CMD_SUCCESS;
1978 }
1979
1980 DEFUN (no_bgp_graceful_restart,
1981 no_bgp_graceful_restart_cmd,
1982 "no bgp graceful-restart",
1983 NO_STR
1984 "BGP specific commands\n"
1985 "Graceful restart capability parameters\n")
1986 {
1987 VTY_DECLVAR_CONTEXT(bgp, bgp);
1988 bgp_flag_unset(bgp, BGP_FLAG_GRACEFUL_RESTART);
1989 return CMD_SUCCESS;
1990 }
1991
1992 DEFUN (bgp_graceful_restart_stalepath_time,
1993 bgp_graceful_restart_stalepath_time_cmd,
1994 "bgp graceful-restart stalepath-time (1-4095)",
1995 "BGP specific commands\n"
1996 "Graceful restart capability parameters\n"
1997 "Set the max time to hold onto restarting peer's stale paths\n"
1998 "Delay value (seconds)\n")
1999 {
2000 VTY_DECLVAR_CONTEXT(bgp, bgp);
2001 int idx_number = 3;
2002 uint32_t stalepath;
2003
2004 stalepath = strtoul(argv[idx_number]->arg, NULL, 10);
2005 bgp->stalepath_time = stalepath;
2006 return CMD_SUCCESS;
2007 }
2008
2009 DEFUN (bgp_graceful_restart_restart_time,
2010 bgp_graceful_restart_restart_time_cmd,
2011 "bgp graceful-restart restart-time (1-4095)",
2012 "BGP specific commands\n"
2013 "Graceful restart capability parameters\n"
2014 "Set the time to wait to delete stale routes before a BGP open message is received\n"
2015 "Delay value (seconds)\n")
2016 {
2017 VTY_DECLVAR_CONTEXT(bgp, bgp);
2018 int idx_number = 3;
2019 uint32_t restart;
2020
2021 restart = strtoul(argv[idx_number]->arg, NULL, 10);
2022 bgp->restart_time = restart;
2023 return CMD_SUCCESS;
2024 }
2025
2026 DEFUN (no_bgp_graceful_restart_stalepath_time,
2027 no_bgp_graceful_restart_stalepath_time_cmd,
2028 "no bgp graceful-restart stalepath-time [(1-4095)]",
2029 NO_STR
2030 "BGP specific commands\n"
2031 "Graceful restart capability parameters\n"
2032 "Set the max time to hold onto restarting peer's stale paths\n"
2033 "Delay value (seconds)\n")
2034 {
2035 VTY_DECLVAR_CONTEXT(bgp, bgp);
2036
2037 bgp->stalepath_time = BGP_DEFAULT_STALEPATH_TIME;
2038 return CMD_SUCCESS;
2039 }
2040
2041 DEFUN (no_bgp_graceful_restart_restart_time,
2042 no_bgp_graceful_restart_restart_time_cmd,
2043 "no bgp graceful-restart restart-time [(1-4095)]",
2044 NO_STR
2045 "BGP specific commands\n"
2046 "Graceful restart capability parameters\n"
2047 "Set the time to wait to delete stale routes before a BGP open message is received\n"
2048 "Delay value (seconds)\n")
2049 {
2050 VTY_DECLVAR_CONTEXT(bgp, bgp);
2051
2052 bgp->restart_time = BGP_DEFAULT_RESTART_TIME;
2053 return CMD_SUCCESS;
2054 }
2055
2056 DEFUN (bgp_graceful_restart_preserve_fw,
2057 bgp_graceful_restart_preserve_fw_cmd,
2058 "bgp graceful-restart preserve-fw-state",
2059 "BGP specific commands\n"
2060 "Graceful restart capability parameters\n"
2061 "Sets F-bit indication that fib is preserved while doing Graceful Restart\n")
2062 {
2063 VTY_DECLVAR_CONTEXT(bgp, bgp);
2064 bgp_flag_set(bgp, BGP_FLAG_GR_PRESERVE_FWD);
2065 return CMD_SUCCESS;
2066 }
2067
2068 DEFUN (no_bgp_graceful_restart_preserve_fw,
2069 no_bgp_graceful_restart_preserve_fw_cmd,
2070 "no bgp graceful-restart preserve-fw-state",
2071 NO_STR
2072 "BGP specific commands\n"
2073 "Graceful restart capability parameters\n"
2074 "Unsets F-bit indication that fib is preserved while doing Graceful Restart\n")
2075 {
2076 VTY_DECLVAR_CONTEXT(bgp, bgp);
2077 bgp_flag_unset(bgp, BGP_FLAG_GR_PRESERVE_FWD);
2078 return CMD_SUCCESS;
2079 }
2080
2081 /* "bgp graceful-shutdown" configuration */
2082 DEFUN (bgp_graceful_shutdown,
2083 bgp_graceful_shutdown_cmd,
2084 "bgp graceful-shutdown",
2085 BGP_STR
2086 "Graceful shutdown parameters\n")
2087 {
2088 VTY_DECLVAR_CONTEXT(bgp, bgp);
2089
2090 if (!bgp_flag_check(bgp, BGP_FLAG_GRACEFUL_SHUTDOWN)) {
2091 bgp_flag_set(bgp, BGP_FLAG_GRACEFUL_SHUTDOWN);
2092 bgp_static_redo_import_check(bgp);
2093 bgp_redistribute_redo(bgp);
2094 bgp_clear_star_soft_out(vty, bgp->name);
2095 bgp_clear_star_soft_in(vty, bgp->name);
2096 }
2097
2098 return CMD_SUCCESS;
2099 }
2100
2101 DEFUN (no_bgp_graceful_shutdown,
2102 no_bgp_graceful_shutdown_cmd,
2103 "no bgp graceful-shutdown",
2104 NO_STR
2105 BGP_STR
2106 "Graceful shutdown parameters\n")
2107 {
2108 VTY_DECLVAR_CONTEXT(bgp, bgp);
2109
2110 if (bgp_flag_check(bgp, BGP_FLAG_GRACEFUL_SHUTDOWN)) {
2111 bgp_flag_unset(bgp, BGP_FLAG_GRACEFUL_SHUTDOWN);
2112 bgp_static_redo_import_check(bgp);
2113 bgp_redistribute_redo(bgp);
2114 bgp_clear_star_soft_out(vty, bgp->name);
2115 bgp_clear_star_soft_in(vty, bgp->name);
2116 }
2117
2118 return CMD_SUCCESS;
2119 }
2120
2121 /* "bgp fast-external-failover" configuration. */
2122 DEFUN (bgp_fast_external_failover,
2123 bgp_fast_external_failover_cmd,
2124 "bgp fast-external-failover",
2125 BGP_STR
2126 "Immediately reset session if a link to a directly connected external peer goes down\n")
2127 {
2128 VTY_DECLVAR_CONTEXT(bgp, bgp);
2129 bgp_flag_unset(bgp, BGP_FLAG_NO_FAST_EXT_FAILOVER);
2130 return CMD_SUCCESS;
2131 }
2132
2133 DEFUN (no_bgp_fast_external_failover,
2134 no_bgp_fast_external_failover_cmd,
2135 "no bgp fast-external-failover",
2136 NO_STR
2137 BGP_STR
2138 "Immediately reset session if a link to a directly connected external peer goes down\n")
2139 {
2140 VTY_DECLVAR_CONTEXT(bgp, bgp);
2141 bgp_flag_set(bgp, BGP_FLAG_NO_FAST_EXT_FAILOVER);
2142 return CMD_SUCCESS;
2143 }
2144
2145 /* "bgp enforce-first-as" configuration. */
2146 #if CONFDATE > 20190517
2147 CPP_NOTICE("bgpd: remove deprecated '[no] bgp enforce-first-as' commands")
2148 #endif
2149
2150 DEFUN_HIDDEN (bgp_enforce_first_as,
2151 bgp_enforce_first_as_cmd,
2152 "[no] bgp enforce-first-as",
2153 NO_STR
2154 BGP_STR
2155 "Enforce the first AS for EBGP routes\n")
2156 {
2157 VTY_DECLVAR_CONTEXT(bgp, bgp);
2158
2159 if (strmatch(argv[0]->text, "no"))
2160 bgp_flag_unset(bgp, BGP_FLAG_ENFORCE_FIRST_AS);
2161 else
2162 bgp_flag_set(bgp, BGP_FLAG_ENFORCE_FIRST_AS);
2163
2164 return CMD_SUCCESS;
2165 }
2166
2167 /* "bgp bestpath compare-routerid" configuration. */
2168 DEFUN (bgp_bestpath_compare_router_id,
2169 bgp_bestpath_compare_router_id_cmd,
2170 "bgp bestpath compare-routerid",
2171 "BGP specific commands\n"
2172 "Change the default bestpath selection\n"
2173 "Compare router-id for identical EBGP paths\n")
2174 {
2175 VTY_DECLVAR_CONTEXT(bgp, bgp);
2176 bgp_flag_set(bgp, BGP_FLAG_COMPARE_ROUTER_ID);
2177 bgp_recalculate_all_bestpaths(bgp);
2178
2179 return CMD_SUCCESS;
2180 }
2181
2182 DEFUN (no_bgp_bestpath_compare_router_id,
2183 no_bgp_bestpath_compare_router_id_cmd,
2184 "no bgp bestpath compare-routerid",
2185 NO_STR
2186 "BGP specific commands\n"
2187 "Change the default bestpath selection\n"
2188 "Compare router-id for identical EBGP paths\n")
2189 {
2190 VTY_DECLVAR_CONTEXT(bgp, bgp);
2191 bgp_flag_unset(bgp, BGP_FLAG_COMPARE_ROUTER_ID);
2192 bgp_recalculate_all_bestpaths(bgp);
2193
2194 return CMD_SUCCESS;
2195 }
2196
2197 /* "bgp bestpath as-path ignore" configuration. */
2198 DEFUN (bgp_bestpath_aspath_ignore,
2199 bgp_bestpath_aspath_ignore_cmd,
2200 "bgp bestpath as-path ignore",
2201 "BGP specific commands\n"
2202 "Change the default bestpath selection\n"
2203 "AS-path attribute\n"
2204 "Ignore as-path length in selecting a route\n")
2205 {
2206 VTY_DECLVAR_CONTEXT(bgp, bgp);
2207 bgp_flag_set(bgp, BGP_FLAG_ASPATH_IGNORE);
2208 bgp_recalculate_all_bestpaths(bgp);
2209
2210 return CMD_SUCCESS;
2211 }
2212
2213 DEFUN (no_bgp_bestpath_aspath_ignore,
2214 no_bgp_bestpath_aspath_ignore_cmd,
2215 "no bgp bestpath as-path ignore",
2216 NO_STR
2217 "BGP specific commands\n"
2218 "Change the default bestpath selection\n"
2219 "AS-path attribute\n"
2220 "Ignore as-path length in selecting a route\n")
2221 {
2222 VTY_DECLVAR_CONTEXT(bgp, bgp);
2223 bgp_flag_unset(bgp, BGP_FLAG_ASPATH_IGNORE);
2224 bgp_recalculate_all_bestpaths(bgp);
2225
2226 return CMD_SUCCESS;
2227 }
2228
2229 /* "bgp bestpath as-path confed" configuration. */
2230 DEFUN (bgp_bestpath_aspath_confed,
2231 bgp_bestpath_aspath_confed_cmd,
2232 "bgp bestpath as-path confed",
2233 "BGP specific commands\n"
2234 "Change the default bestpath selection\n"
2235 "AS-path attribute\n"
2236 "Compare path lengths including confederation sets & sequences in selecting a route\n")
2237 {
2238 VTY_DECLVAR_CONTEXT(bgp, bgp);
2239 bgp_flag_set(bgp, BGP_FLAG_ASPATH_CONFED);
2240 bgp_recalculate_all_bestpaths(bgp);
2241
2242 return CMD_SUCCESS;
2243 }
2244
2245 DEFUN (no_bgp_bestpath_aspath_confed,
2246 no_bgp_bestpath_aspath_confed_cmd,
2247 "no bgp bestpath as-path confed",
2248 NO_STR
2249 "BGP specific commands\n"
2250 "Change the default bestpath selection\n"
2251 "AS-path attribute\n"
2252 "Compare path lengths including confederation sets & sequences in selecting a route\n")
2253 {
2254 VTY_DECLVAR_CONTEXT(bgp, bgp);
2255 bgp_flag_unset(bgp, BGP_FLAG_ASPATH_CONFED);
2256 bgp_recalculate_all_bestpaths(bgp);
2257
2258 return CMD_SUCCESS;
2259 }
2260
2261 /* "bgp bestpath as-path multipath-relax" configuration. */
2262 DEFUN (bgp_bestpath_aspath_multipath_relax,
2263 bgp_bestpath_aspath_multipath_relax_cmd,
2264 "bgp bestpath as-path multipath-relax [<as-set|no-as-set>]",
2265 "BGP specific commands\n"
2266 "Change the default bestpath selection\n"
2267 "AS-path attribute\n"
2268 "Allow load sharing across routes that have different AS paths (but same length)\n"
2269 "Generate an AS_SET\n"
2270 "Do not generate an AS_SET\n")
2271 {
2272 VTY_DECLVAR_CONTEXT(bgp, bgp);
2273 int idx = 0;
2274 bgp_flag_set(bgp, BGP_FLAG_ASPATH_MULTIPATH_RELAX);
2275
2276 /* no-as-set is now the default behavior so we can silently
2277 * ignore it */
2278 if (argv_find(argv, argc, "as-set", &idx))
2279 bgp_flag_set(bgp, BGP_FLAG_MULTIPATH_RELAX_AS_SET);
2280 else
2281 bgp_flag_unset(bgp, BGP_FLAG_MULTIPATH_RELAX_AS_SET);
2282
2283 bgp_recalculate_all_bestpaths(bgp);
2284
2285 return CMD_SUCCESS;
2286 }
2287
2288 DEFUN (no_bgp_bestpath_aspath_multipath_relax,
2289 no_bgp_bestpath_aspath_multipath_relax_cmd,
2290 "no bgp bestpath as-path multipath-relax [<as-set|no-as-set>]",
2291 NO_STR
2292 "BGP specific commands\n"
2293 "Change the default bestpath selection\n"
2294 "AS-path attribute\n"
2295 "Allow load sharing across routes that have different AS paths (but same length)\n"
2296 "Generate an AS_SET\n"
2297 "Do not generate an AS_SET\n")
2298 {
2299 VTY_DECLVAR_CONTEXT(bgp, bgp);
2300 bgp_flag_unset(bgp, BGP_FLAG_ASPATH_MULTIPATH_RELAX);
2301 bgp_flag_unset(bgp, BGP_FLAG_MULTIPATH_RELAX_AS_SET);
2302 bgp_recalculate_all_bestpaths(bgp);
2303
2304 return CMD_SUCCESS;
2305 }
2306
2307 /* "bgp log-neighbor-changes" configuration. */
2308 DEFUN (bgp_log_neighbor_changes,
2309 bgp_log_neighbor_changes_cmd,
2310 "bgp log-neighbor-changes",
2311 "BGP specific commands\n"
2312 "Log neighbor up/down and reset reason\n")
2313 {
2314 VTY_DECLVAR_CONTEXT(bgp, bgp);
2315 bgp_flag_set(bgp, BGP_FLAG_LOG_NEIGHBOR_CHANGES);
2316 return CMD_SUCCESS;
2317 }
2318
2319 DEFUN (no_bgp_log_neighbor_changes,
2320 no_bgp_log_neighbor_changes_cmd,
2321 "no bgp log-neighbor-changes",
2322 NO_STR
2323 "BGP specific commands\n"
2324 "Log neighbor up/down and reset reason\n")
2325 {
2326 VTY_DECLVAR_CONTEXT(bgp, bgp);
2327 bgp_flag_unset(bgp, BGP_FLAG_LOG_NEIGHBOR_CHANGES);
2328 return CMD_SUCCESS;
2329 }
2330
2331 /* "bgp bestpath med" configuration. */
2332 DEFUN (bgp_bestpath_med,
2333 bgp_bestpath_med_cmd,
2334 "bgp bestpath med <confed [missing-as-worst]|missing-as-worst [confed]>",
2335 "BGP specific commands\n"
2336 "Change the default bestpath selection\n"
2337 "MED attribute\n"
2338 "Compare MED among confederation paths\n"
2339 "Treat missing MED as the least preferred one\n"
2340 "Treat missing MED as the least preferred one\n"
2341 "Compare MED among confederation paths\n")
2342 {
2343 VTY_DECLVAR_CONTEXT(bgp, bgp);
2344
2345 int idx = 0;
2346 if (argv_find(argv, argc, "confed", &idx))
2347 bgp_flag_set(bgp, BGP_FLAG_MED_CONFED);
2348 idx = 0;
2349 if (argv_find(argv, argc, "missing-as-worst", &idx))
2350 bgp_flag_set(bgp, BGP_FLAG_MED_MISSING_AS_WORST);
2351
2352 bgp_recalculate_all_bestpaths(bgp);
2353
2354 return CMD_SUCCESS;
2355 }
2356
2357 DEFUN (no_bgp_bestpath_med,
2358 no_bgp_bestpath_med_cmd,
2359 "no bgp bestpath med <confed [missing-as-worst]|missing-as-worst [confed]>",
2360 NO_STR
2361 "BGP specific commands\n"
2362 "Change the default bestpath selection\n"
2363 "MED attribute\n"
2364 "Compare MED among confederation paths\n"
2365 "Treat missing MED as the least preferred one\n"
2366 "Treat missing MED as the least preferred one\n"
2367 "Compare MED among confederation paths\n")
2368 {
2369 VTY_DECLVAR_CONTEXT(bgp, bgp);
2370
2371 int idx = 0;
2372 if (argv_find(argv, argc, "confed", &idx))
2373 bgp_flag_unset(bgp, BGP_FLAG_MED_CONFED);
2374 idx = 0;
2375 if (argv_find(argv, argc, "missing-as-worst", &idx))
2376 bgp_flag_unset(bgp, BGP_FLAG_MED_MISSING_AS_WORST);
2377
2378 bgp_recalculate_all_bestpaths(bgp);
2379
2380 return CMD_SUCCESS;
2381 }
2382
2383 /* "no bgp default ipv4-unicast". */
2384 DEFUN (no_bgp_default_ipv4_unicast,
2385 no_bgp_default_ipv4_unicast_cmd,
2386 "no bgp default ipv4-unicast",
2387 NO_STR
2388 "BGP specific commands\n"
2389 "Configure BGP defaults\n"
2390 "Activate ipv4-unicast for a peer by default\n")
2391 {
2392 VTY_DECLVAR_CONTEXT(bgp, bgp);
2393 bgp_flag_set(bgp, BGP_FLAG_NO_DEFAULT_IPV4);
2394 return CMD_SUCCESS;
2395 }
2396
2397 DEFUN (bgp_default_ipv4_unicast,
2398 bgp_default_ipv4_unicast_cmd,
2399 "bgp default ipv4-unicast",
2400 "BGP specific commands\n"
2401 "Configure BGP defaults\n"
2402 "Activate ipv4-unicast for a peer by default\n")
2403 {
2404 VTY_DECLVAR_CONTEXT(bgp, bgp);
2405 bgp_flag_unset(bgp, BGP_FLAG_NO_DEFAULT_IPV4);
2406 return CMD_SUCCESS;
2407 }
2408
2409 /* Display hostname in certain command outputs */
2410 DEFUN (bgp_default_show_hostname,
2411 bgp_default_show_hostname_cmd,
2412 "bgp default show-hostname",
2413 "BGP specific commands\n"
2414 "Configure BGP defaults\n"
2415 "Show hostname in certain command outputs\n")
2416 {
2417 VTY_DECLVAR_CONTEXT(bgp, bgp);
2418 bgp_flag_set(bgp, BGP_FLAG_SHOW_HOSTNAME);
2419 return CMD_SUCCESS;
2420 }
2421
2422 DEFUN (no_bgp_default_show_hostname,
2423 no_bgp_default_show_hostname_cmd,
2424 "no bgp default show-hostname",
2425 NO_STR
2426 "BGP specific commands\n"
2427 "Configure BGP defaults\n"
2428 "Show hostname in certain command outputs\n")
2429 {
2430 VTY_DECLVAR_CONTEXT(bgp, bgp);
2431 bgp_flag_unset(bgp, BGP_FLAG_SHOW_HOSTNAME);
2432 return CMD_SUCCESS;
2433 }
2434
2435 /* "bgp network import-check" configuration. */
2436 DEFUN (bgp_network_import_check,
2437 bgp_network_import_check_cmd,
2438 "bgp network import-check",
2439 "BGP specific commands\n"
2440 "BGP network command\n"
2441 "Check BGP network route exists in IGP\n")
2442 {
2443 VTY_DECLVAR_CONTEXT(bgp, bgp);
2444 if (!bgp_flag_check(bgp, BGP_FLAG_IMPORT_CHECK)) {
2445 bgp_flag_set(bgp, BGP_FLAG_IMPORT_CHECK);
2446 bgp_static_redo_import_check(bgp);
2447 }
2448
2449 return CMD_SUCCESS;
2450 }
2451
2452 ALIAS_HIDDEN(bgp_network_import_check, bgp_network_import_check_exact_cmd,
2453 "bgp network import-check exact",
2454 "BGP specific commands\n"
2455 "BGP network command\n"
2456 "Check BGP network route exists in IGP\n"
2457 "Match route precisely\n")
2458
2459 DEFUN (no_bgp_network_import_check,
2460 no_bgp_network_import_check_cmd,
2461 "no bgp network import-check",
2462 NO_STR
2463 "BGP specific commands\n"
2464 "BGP network command\n"
2465 "Check BGP network route exists in IGP\n")
2466 {
2467 VTY_DECLVAR_CONTEXT(bgp, bgp);
2468 if (bgp_flag_check(bgp, BGP_FLAG_IMPORT_CHECK)) {
2469 bgp_flag_unset(bgp, BGP_FLAG_IMPORT_CHECK);
2470 bgp_static_redo_import_check(bgp);
2471 }
2472
2473 return CMD_SUCCESS;
2474 }
2475
2476 DEFUN (bgp_default_local_preference,
2477 bgp_default_local_preference_cmd,
2478 "bgp default local-preference (0-4294967295)",
2479 "BGP specific commands\n"
2480 "Configure BGP defaults\n"
2481 "local preference (higher=more preferred)\n"
2482 "Configure default local preference value\n")
2483 {
2484 VTY_DECLVAR_CONTEXT(bgp, bgp);
2485 int idx_number = 3;
2486 uint32_t local_pref;
2487
2488 local_pref = strtoul(argv[idx_number]->arg, NULL, 10);
2489
2490 bgp_default_local_preference_set(bgp, local_pref);
2491 bgp_clear_star_soft_in(vty, bgp->name);
2492
2493 return CMD_SUCCESS;
2494 }
2495
2496 DEFUN (no_bgp_default_local_preference,
2497 no_bgp_default_local_preference_cmd,
2498 "no bgp default local-preference [(0-4294967295)]",
2499 NO_STR
2500 "BGP specific commands\n"
2501 "Configure BGP defaults\n"
2502 "local preference (higher=more preferred)\n"
2503 "Configure default local preference value\n")
2504 {
2505 VTY_DECLVAR_CONTEXT(bgp, bgp);
2506 bgp_default_local_preference_unset(bgp);
2507 bgp_clear_star_soft_in(vty, bgp->name);
2508
2509 return CMD_SUCCESS;
2510 }
2511
2512
2513 DEFUN (bgp_default_subgroup_pkt_queue_max,
2514 bgp_default_subgroup_pkt_queue_max_cmd,
2515 "bgp default subgroup-pkt-queue-max (20-100)",
2516 "BGP specific commands\n"
2517 "Configure BGP defaults\n"
2518 "subgroup-pkt-queue-max\n"
2519 "Configure subgroup packet queue max\n")
2520 {
2521 VTY_DECLVAR_CONTEXT(bgp, bgp);
2522 int idx_number = 3;
2523 uint32_t max_size;
2524
2525 max_size = strtoul(argv[idx_number]->arg, NULL, 10);
2526
2527 bgp_default_subgroup_pkt_queue_max_set(bgp, max_size);
2528
2529 return CMD_SUCCESS;
2530 }
2531
2532 DEFUN (no_bgp_default_subgroup_pkt_queue_max,
2533 no_bgp_default_subgroup_pkt_queue_max_cmd,
2534 "no bgp default subgroup-pkt-queue-max [(20-100)]",
2535 NO_STR
2536 "BGP specific commands\n"
2537 "Configure BGP defaults\n"
2538 "subgroup-pkt-queue-max\n"
2539 "Configure subgroup packet queue max\n")
2540 {
2541 VTY_DECLVAR_CONTEXT(bgp, bgp);
2542 bgp_default_subgroup_pkt_queue_max_unset(bgp);
2543 return CMD_SUCCESS;
2544 }
2545
2546
2547 DEFUN (bgp_rr_allow_outbound_policy,
2548 bgp_rr_allow_outbound_policy_cmd,
2549 "bgp route-reflector allow-outbound-policy",
2550 "BGP specific commands\n"
2551 "Allow modifications made by out route-map\n"
2552 "on ibgp neighbors\n")
2553 {
2554 VTY_DECLVAR_CONTEXT(bgp, bgp);
2555
2556 if (!bgp_flag_check(bgp, BGP_FLAG_RR_ALLOW_OUTBOUND_POLICY)) {
2557 bgp_flag_set(bgp, BGP_FLAG_RR_ALLOW_OUTBOUND_POLICY);
2558 update_group_announce_rrclients(bgp);
2559 bgp_clear_star_soft_out(vty, bgp->name);
2560 }
2561
2562 return CMD_SUCCESS;
2563 }
2564
2565 DEFUN (no_bgp_rr_allow_outbound_policy,
2566 no_bgp_rr_allow_outbound_policy_cmd,
2567 "no bgp route-reflector allow-outbound-policy",
2568 NO_STR
2569 "BGP specific commands\n"
2570 "Allow modifications made by out route-map\n"
2571 "on ibgp neighbors\n")
2572 {
2573 VTY_DECLVAR_CONTEXT(bgp, bgp);
2574
2575 if (bgp_flag_check(bgp, BGP_FLAG_RR_ALLOW_OUTBOUND_POLICY)) {
2576 bgp_flag_unset(bgp, BGP_FLAG_RR_ALLOW_OUTBOUND_POLICY);
2577 update_group_announce_rrclients(bgp);
2578 bgp_clear_star_soft_out(vty, bgp->name);
2579 }
2580
2581 return CMD_SUCCESS;
2582 }
2583
2584 DEFUN (bgp_listen_limit,
2585 bgp_listen_limit_cmd,
2586 "bgp listen limit (1-5000)",
2587 "BGP specific commands\n"
2588 "Configure BGP defaults\n"
2589 "maximum number of BGP Dynamic Neighbors that can be created\n"
2590 "Configure Dynamic Neighbors listen limit value\n")
2591 {
2592 VTY_DECLVAR_CONTEXT(bgp, bgp);
2593 int idx_number = 3;
2594 int listen_limit;
2595
2596 listen_limit = strtoul(argv[idx_number]->arg, NULL, 10);
2597
2598 bgp_listen_limit_set(bgp, listen_limit);
2599
2600 return CMD_SUCCESS;
2601 }
2602
2603 DEFUN (no_bgp_listen_limit,
2604 no_bgp_listen_limit_cmd,
2605 "no bgp listen limit [(1-5000)]",
2606 "BGP specific commands\n"
2607 "Configure BGP defaults\n"
2608 "unset maximum number of BGP Dynamic Neighbors that can be created\n"
2609 "Configure Dynamic Neighbors listen limit value to default\n"
2610 "Configure Dynamic Neighbors listen limit value\n")
2611 {
2612 VTY_DECLVAR_CONTEXT(bgp, bgp);
2613 bgp_listen_limit_unset(bgp);
2614 return CMD_SUCCESS;
2615 }
2616
2617
2618 /*
2619 * Check if this listen range is already configured. Check for exact
2620 * match or overlap based on input.
2621 */
2622 static struct peer_group *listen_range_exists(struct bgp *bgp,
2623 struct prefix *range, int exact)
2624 {
2625 struct listnode *node, *nnode;
2626 struct listnode *node1, *nnode1;
2627 struct peer_group *group;
2628 struct prefix *lr;
2629 afi_t afi;
2630 int match;
2631
2632 afi = family2afi(range->family);
2633 for (ALL_LIST_ELEMENTS(bgp->group, node, nnode, group)) {
2634 for (ALL_LIST_ELEMENTS(group->listen_range[afi], node1, nnode1,
2635 lr)) {
2636 if (exact)
2637 match = prefix_same(range, lr);
2638 else
2639 match = (prefix_match(range, lr)
2640 || prefix_match(lr, range));
2641 if (match)
2642 return group;
2643 }
2644 }
2645
2646 return NULL;
2647 }
2648
2649 DEFUN (bgp_listen_range,
2650 bgp_listen_range_cmd,
2651 "bgp listen range <A.B.C.D/M|X:X::X:X/M> peer-group PGNAME",
2652 "BGP specific commands\n"
2653 "Configure BGP dynamic neighbors listen range\n"
2654 "Configure BGP dynamic neighbors listen range\n"
2655 NEIGHBOR_ADDR_STR
2656 "Member of the peer-group\n"
2657 "Peer-group name\n")
2658 {
2659 VTY_DECLVAR_CONTEXT(bgp, bgp);
2660 struct prefix range;
2661 struct peer_group *group, *existing_group;
2662 afi_t afi;
2663 int ret;
2664 int idx = 0;
2665
2666 argv_find(argv, argc, "A.B.C.D/M", &idx);
2667 argv_find(argv, argc, "X:X::X:X/M", &idx);
2668 char *prefix = argv[idx]->arg;
2669 argv_find(argv, argc, "PGNAME", &idx);
2670 char *peergroup = argv[idx]->arg;
2671
2672 /* Convert IP prefix string to struct prefix. */
2673 ret = str2prefix(prefix, &range);
2674 if (!ret) {
2675 vty_out(vty, "%% Malformed listen range\n");
2676 return CMD_WARNING_CONFIG_FAILED;
2677 }
2678
2679 afi = family2afi(range.family);
2680
2681 if (afi == AFI_IP6 && IN6_IS_ADDR_LINKLOCAL(&range.u.prefix6)) {
2682 vty_out(vty,
2683 "%% Malformed listen range (link-local address)\n");
2684 return CMD_WARNING_CONFIG_FAILED;
2685 }
2686
2687 apply_mask(&range);
2688
2689 /* Check if same listen range is already configured. */
2690 existing_group = listen_range_exists(bgp, &range, 1);
2691 if (existing_group) {
2692 if (strcmp(existing_group->name, peergroup) == 0)
2693 return CMD_SUCCESS;
2694 else {
2695 vty_out(vty,
2696 "%% Same listen range is attached to peer-group %s\n",
2697 existing_group->name);
2698 return CMD_WARNING_CONFIG_FAILED;
2699 }
2700 }
2701
2702 /* Check if an overlapping listen range exists. */
2703 if (listen_range_exists(bgp, &range, 0)) {
2704 vty_out(vty,
2705 "%% Listen range overlaps with existing listen range\n");
2706 return CMD_WARNING_CONFIG_FAILED;
2707 }
2708
2709 group = peer_group_lookup(bgp, peergroup);
2710 if (!group) {
2711 vty_out(vty, "%% Configure the peer-group first\n");
2712 return CMD_WARNING_CONFIG_FAILED;
2713 }
2714
2715 ret = peer_group_listen_range_add(group, &range);
2716 return bgp_vty_return(vty, ret);
2717 }
2718
2719 DEFUN (no_bgp_listen_range,
2720 no_bgp_listen_range_cmd,
2721 "no bgp listen range <A.B.C.D/M|X:X::X:X/M> peer-group PGNAME",
2722 NO_STR
2723 "BGP specific commands\n"
2724 "Unconfigure BGP dynamic neighbors listen range\n"
2725 "Unconfigure BGP dynamic neighbors listen range\n"
2726 NEIGHBOR_ADDR_STR
2727 "Member of the peer-group\n"
2728 "Peer-group name\n")
2729 {
2730 VTY_DECLVAR_CONTEXT(bgp, bgp);
2731 struct prefix range;
2732 struct peer_group *group;
2733 afi_t afi;
2734 int ret;
2735 int idx = 0;
2736
2737 argv_find(argv, argc, "A.B.C.D/M", &idx);
2738 argv_find(argv, argc, "X:X::X:X/M", &idx);
2739 char *prefix = argv[idx]->arg;
2740 argv_find(argv, argc, "WORD", &idx);
2741 char *peergroup = argv[idx]->arg;
2742
2743 /* Convert IP prefix string to struct prefix. */
2744 ret = str2prefix(prefix, &range);
2745 if (!ret) {
2746 vty_out(vty, "%% Malformed listen range\n");
2747 return CMD_WARNING_CONFIG_FAILED;
2748 }
2749
2750 afi = family2afi(range.family);
2751
2752 if (afi == AFI_IP6 && IN6_IS_ADDR_LINKLOCAL(&range.u.prefix6)) {
2753 vty_out(vty,
2754 "%% Malformed listen range (link-local address)\n");
2755 return CMD_WARNING_CONFIG_FAILED;
2756 }
2757
2758 apply_mask(&range);
2759
2760 group = peer_group_lookup(bgp, peergroup);
2761 if (!group) {
2762 vty_out(vty, "%% Peer-group does not exist\n");
2763 return CMD_WARNING_CONFIG_FAILED;
2764 }
2765
2766 ret = peer_group_listen_range_del(group, &range);
2767 return bgp_vty_return(vty, ret);
2768 }
2769
2770 void bgp_config_write_listen(struct vty *vty, struct bgp *bgp)
2771 {
2772 struct peer_group *group;
2773 struct listnode *node, *nnode, *rnode, *nrnode;
2774 struct prefix *range;
2775 afi_t afi;
2776 char buf[PREFIX2STR_BUFFER];
2777
2778 if (bgp->dynamic_neighbors_limit != BGP_DYNAMIC_NEIGHBORS_LIMIT_DEFAULT)
2779 vty_out(vty, " bgp listen limit %d\n",
2780 bgp->dynamic_neighbors_limit);
2781
2782 for (ALL_LIST_ELEMENTS(bgp->group, node, nnode, group)) {
2783 for (afi = AFI_IP; afi < AFI_MAX; afi++) {
2784 for (ALL_LIST_ELEMENTS(group->listen_range[afi], rnode,
2785 nrnode, range)) {
2786 prefix2str(range, buf, sizeof(buf));
2787 vty_out(vty,
2788 " bgp listen range %s peer-group %s\n",
2789 buf, group->name);
2790 }
2791 }
2792 }
2793 }
2794
2795
2796 DEFUN (bgp_disable_connected_route_check,
2797 bgp_disable_connected_route_check_cmd,
2798 "bgp disable-ebgp-connected-route-check",
2799 "BGP specific commands\n"
2800 "Disable checking if nexthop is connected on ebgp sessions\n")
2801 {
2802 VTY_DECLVAR_CONTEXT(bgp, bgp);
2803 bgp_flag_set(bgp, BGP_FLAG_DISABLE_NH_CONNECTED_CHK);
2804 bgp_clear_star_soft_in(vty, bgp->name);
2805
2806 return CMD_SUCCESS;
2807 }
2808
2809 DEFUN (no_bgp_disable_connected_route_check,
2810 no_bgp_disable_connected_route_check_cmd,
2811 "no bgp disable-ebgp-connected-route-check",
2812 NO_STR
2813 "BGP specific commands\n"
2814 "Disable checking if nexthop is connected on ebgp sessions\n")
2815 {
2816 VTY_DECLVAR_CONTEXT(bgp, bgp);
2817 bgp_flag_unset(bgp, BGP_FLAG_DISABLE_NH_CONNECTED_CHK);
2818 bgp_clear_star_soft_in(vty, bgp->name);
2819
2820 return CMD_SUCCESS;
2821 }
2822
2823
2824 static int peer_remote_as_vty(struct vty *vty, const char *peer_str,
2825 const char *as_str, afi_t afi, safi_t safi)
2826 {
2827 VTY_DECLVAR_CONTEXT(bgp, bgp);
2828 int ret;
2829 as_t as;
2830 int as_type = AS_SPECIFIED;
2831 union sockunion su;
2832
2833 if (as_str[0] == 'i') {
2834 as = 0;
2835 as_type = AS_INTERNAL;
2836 } else if (as_str[0] == 'e') {
2837 as = 0;
2838 as_type = AS_EXTERNAL;
2839 } else {
2840 /* Get AS number. */
2841 as = strtoul(as_str, NULL, 10);
2842 }
2843
2844 /* If peer is peer group or interface peer, call proper function. */
2845 ret = str2sockunion(peer_str, &su);
2846 if (ret < 0) {
2847 struct peer *peer;
2848
2849 /* Check if existing interface peer */
2850 peer = peer_lookup_by_conf_if(bgp, peer_str);
2851
2852 ret = peer_remote_as(bgp, NULL, peer_str, &as, as_type, afi,
2853 safi);
2854
2855 /* if not interface peer, check peer-group settings */
2856 if (ret < 0 && !peer) {
2857 ret = peer_group_remote_as(bgp, peer_str, &as, as_type);
2858 if (ret < 0) {
2859 vty_out(vty,
2860 "%% Create the peer-group or interface first\n");
2861 return CMD_WARNING_CONFIG_FAILED;
2862 }
2863 return CMD_SUCCESS;
2864 }
2865 } else {
2866 if (peer_address_self_check(bgp, &su)) {
2867 vty_out(vty,
2868 "%% Can not configure the local system as neighbor\n");
2869 return CMD_WARNING_CONFIG_FAILED;
2870 }
2871 ret = peer_remote_as(bgp, &su, NULL, &as, as_type, afi, safi);
2872 }
2873
2874 /* This peer belongs to peer group. */
2875 switch (ret) {
2876 case BGP_ERR_PEER_GROUP_MEMBER:
2877 vty_out(vty,
2878 "%% Peer-group member cannot override remote-as of peer-group\n");
2879 return CMD_WARNING_CONFIG_FAILED;
2880 case BGP_ERR_PEER_GROUP_PEER_TYPE_DIFFERENT:
2881 vty_out(vty,
2882 "%% Peer-group members must be all internal or all external\n");
2883 return CMD_WARNING_CONFIG_FAILED;
2884 }
2885 return bgp_vty_return(vty, ret);
2886 }
2887
2888 DEFUN (bgp_default_shutdown,
2889 bgp_default_shutdown_cmd,
2890 "[no] bgp default shutdown",
2891 NO_STR
2892 BGP_STR
2893 "Configure BGP defaults\n"
2894 "Apply administrative shutdown to newly configured peers\n")
2895 {
2896 VTY_DECLVAR_CONTEXT(bgp, bgp);
2897 bgp->autoshutdown = !strmatch(argv[0]->text, "no");
2898 return CMD_SUCCESS;
2899 }
2900
2901 DEFUN (neighbor_remote_as,
2902 neighbor_remote_as_cmd,
2903 "neighbor <A.B.C.D|X:X::X:X|WORD> remote-as <(1-4294967295)|internal|external>",
2904 NEIGHBOR_STR
2905 NEIGHBOR_ADDR_STR2
2906 "Specify a BGP neighbor\n"
2907 AS_STR
2908 "Internal BGP peer\n"
2909 "External BGP peer\n")
2910 {
2911 int idx_peer = 1;
2912 int idx_remote_as = 3;
2913 return peer_remote_as_vty(vty, argv[idx_peer]->arg,
2914 argv[idx_remote_as]->arg, AFI_IP,
2915 SAFI_UNICAST);
2916 }
2917
2918 static int peer_conf_interface_get(struct vty *vty, const char *conf_if,
2919 afi_t afi, safi_t safi, int v6only,
2920 const char *peer_group_name,
2921 const char *as_str)
2922 {
2923 VTY_DECLVAR_CONTEXT(bgp, bgp);
2924 as_t as = 0;
2925 int as_type = AS_UNSPECIFIED;
2926 struct peer *peer;
2927 struct peer_group *group;
2928 int ret = 0;
2929 union sockunion su;
2930
2931 group = peer_group_lookup(bgp, conf_if);
2932
2933 if (group) {
2934 vty_out(vty, "%% Name conflict with peer-group \n");
2935 return CMD_WARNING_CONFIG_FAILED;
2936 }
2937
2938 if (as_str) {
2939 if (as_str[0] == 'i') {
2940 as_type = AS_INTERNAL;
2941 } else if (as_str[0] == 'e') {
2942 as_type = AS_EXTERNAL;
2943 } else {
2944 /* Get AS number. */
2945 as = strtoul(as_str, NULL, 10);
2946 as_type = AS_SPECIFIED;
2947 }
2948 }
2949
2950 peer = peer_lookup_by_conf_if(bgp, conf_if);
2951 if (peer) {
2952 if (as_str)
2953 ret = peer_remote_as(bgp, NULL, conf_if, &as, as_type,
2954 afi, safi);
2955 } else {
2956 if (bgp_flag_check(bgp, BGP_FLAG_NO_DEFAULT_IPV4)
2957 && afi == AFI_IP && safi == SAFI_UNICAST)
2958 peer = peer_create(NULL, conf_if, bgp, bgp->as, as,
2959 as_type, 0, 0, NULL);
2960 else
2961 peer = peer_create(NULL, conf_if, bgp, bgp->as, as,
2962 as_type, afi, safi, NULL);
2963
2964 if (!peer) {
2965 vty_out(vty, "%% BGP failed to create peer\n");
2966 return CMD_WARNING_CONFIG_FAILED;
2967 }
2968
2969 if (v6only)
2970 peer_flag_set(peer, PEER_FLAG_IFPEER_V6ONLY);
2971
2972 /* Request zebra to initiate IPv6 RAs on this interface. We do
2973 * this
2974 * any unnumbered peer in order to not worry about run-time
2975 * transitions
2976 * (e.g., peering is initially IPv4, but the IPv4 /30 or /31
2977 * address
2978 * gets deleted later etc.)
2979 */
2980 if (peer->ifp)
2981 bgp_zebra_initiate_radv(bgp, peer);
2982 }
2983
2984 if ((v6only && !CHECK_FLAG(peer->flags, PEER_FLAG_IFPEER_V6ONLY))
2985 || (!v6only && CHECK_FLAG(peer->flags, PEER_FLAG_IFPEER_V6ONLY))) {
2986 if (v6only)
2987 peer_flag_set(peer, PEER_FLAG_IFPEER_V6ONLY);
2988 else
2989 peer_flag_unset(peer, PEER_FLAG_IFPEER_V6ONLY);
2990
2991 /* v6only flag changed. Reset bgp seesion */
2992 if (BGP_IS_VALID_STATE_FOR_NOTIF(peer->status)) {
2993 peer->last_reset = PEER_DOWN_V6ONLY_CHANGE;
2994 bgp_notify_send(peer, BGP_NOTIFY_CEASE,
2995 BGP_NOTIFY_CEASE_CONFIG_CHANGE);
2996 } else
2997 bgp_session_reset(peer);
2998 }
2999
3000 if (!CHECK_FLAG(peer->flags_invert, PEER_FLAG_CAPABILITY_ENHE)) {
3001 SET_FLAG(peer->flags, PEER_FLAG_CAPABILITY_ENHE);
3002 SET_FLAG(peer->flags_invert, PEER_FLAG_CAPABILITY_ENHE);
3003 SET_FLAG(peer->flags_override, PEER_FLAG_CAPABILITY_ENHE);
3004 }
3005
3006 if (peer_group_name) {
3007 group = peer_group_lookup(bgp, peer_group_name);
3008 if (!group) {
3009 vty_out(vty, "%% Configure the peer-group first\n");
3010 return CMD_WARNING_CONFIG_FAILED;
3011 }
3012
3013 ret = peer_group_bind(bgp, &su, peer, group, &as);
3014 }
3015
3016 return bgp_vty_return(vty, ret);
3017 }
3018
3019 DEFUN (neighbor_interface_config,
3020 neighbor_interface_config_cmd,
3021 "neighbor WORD interface [peer-group PGNAME]",
3022 NEIGHBOR_STR
3023 "Interface name or neighbor tag\n"
3024 "Enable BGP on interface\n"
3025 "Member of the peer-group\n"
3026 "Peer-group name\n")
3027 {
3028 int idx_word = 1;
3029 int idx_peer_group_word = 4;
3030
3031 if (argc > idx_peer_group_word)
3032 return peer_conf_interface_get(
3033 vty, argv[idx_word]->arg, AFI_IP, SAFI_UNICAST, 0,
3034 argv[idx_peer_group_word]->arg, NULL);
3035 else
3036 return peer_conf_interface_get(vty, argv[idx_word]->arg, AFI_IP,
3037 SAFI_UNICAST, 0, NULL, NULL);
3038 }
3039
3040 DEFUN (neighbor_interface_config_v6only,
3041 neighbor_interface_config_v6only_cmd,
3042 "neighbor WORD interface v6only [peer-group PGNAME]",
3043 NEIGHBOR_STR
3044 "Interface name or neighbor tag\n"
3045 "Enable BGP on interface\n"
3046 "Enable BGP with v6 link-local only\n"
3047 "Member of the peer-group\n"
3048 "Peer-group name\n")
3049 {
3050 int idx_word = 1;
3051 int idx_peer_group_word = 5;
3052
3053 if (argc > idx_peer_group_word)
3054 return peer_conf_interface_get(
3055 vty, argv[idx_word]->arg, AFI_IP, SAFI_UNICAST, 1,
3056 argv[idx_peer_group_word]->arg, NULL);
3057
3058 return peer_conf_interface_get(vty, argv[idx_word]->arg, AFI_IP,
3059 SAFI_UNICAST, 1, NULL, NULL);
3060 }
3061
3062
3063 DEFUN (neighbor_interface_config_remote_as,
3064 neighbor_interface_config_remote_as_cmd,
3065 "neighbor WORD interface remote-as <(1-4294967295)|internal|external>",
3066 NEIGHBOR_STR
3067 "Interface name or neighbor tag\n"
3068 "Enable BGP on interface\n"
3069 "Specify a BGP neighbor\n"
3070 AS_STR
3071 "Internal BGP peer\n"
3072 "External BGP peer\n")
3073 {
3074 int idx_word = 1;
3075 int idx_remote_as = 4;
3076 return peer_conf_interface_get(vty, argv[idx_word]->arg, AFI_IP,
3077 SAFI_UNICAST, 0, NULL,
3078 argv[idx_remote_as]->arg);
3079 }
3080
3081 DEFUN (neighbor_interface_v6only_config_remote_as,
3082 neighbor_interface_v6only_config_remote_as_cmd,
3083 "neighbor WORD interface v6only remote-as <(1-4294967295)|internal|external>",
3084 NEIGHBOR_STR
3085 "Interface name or neighbor tag\n"
3086 "Enable BGP with v6 link-local only\n"
3087 "Enable BGP on interface\n"
3088 "Specify a BGP neighbor\n"
3089 AS_STR
3090 "Internal BGP peer\n"
3091 "External BGP peer\n")
3092 {
3093 int idx_word = 1;
3094 int idx_remote_as = 5;
3095 return peer_conf_interface_get(vty, argv[idx_word]->arg, AFI_IP,
3096 SAFI_UNICAST, 1, NULL,
3097 argv[idx_remote_as]->arg);
3098 }
3099
3100 DEFUN (neighbor_peer_group,
3101 neighbor_peer_group_cmd,
3102 "neighbor WORD peer-group",
3103 NEIGHBOR_STR
3104 "Interface name or neighbor tag\n"
3105 "Configure peer-group\n")
3106 {
3107 VTY_DECLVAR_CONTEXT(bgp, bgp);
3108 int idx_word = 1;
3109 struct peer *peer;
3110 struct peer_group *group;
3111
3112 peer = peer_lookup_by_conf_if(bgp, argv[idx_word]->arg);
3113 if (peer) {
3114 vty_out(vty, "%% Name conflict with interface: \n");
3115 return CMD_WARNING_CONFIG_FAILED;
3116 }
3117
3118 group = peer_group_get(bgp, argv[idx_word]->arg);
3119 if (!group) {
3120 vty_out(vty, "%% BGP failed to find or create peer-group\n");
3121 return CMD_WARNING_CONFIG_FAILED;
3122 }
3123
3124 return CMD_SUCCESS;
3125 }
3126
3127 DEFUN (no_neighbor,
3128 no_neighbor_cmd,
3129 "no neighbor <WORD|<A.B.C.D|X:X::X:X> [remote-as <(1-4294967295)|internal|external>]>",
3130 NO_STR
3131 NEIGHBOR_STR
3132 NEIGHBOR_ADDR_STR2
3133 "Specify a BGP neighbor\n"
3134 AS_STR
3135 "Internal BGP peer\n"
3136 "External BGP peer\n")
3137 {
3138 VTY_DECLVAR_CONTEXT(bgp, bgp);
3139 int idx_peer = 2;
3140 int ret;
3141 union sockunion su;
3142 struct peer_group *group;
3143 struct peer *peer;
3144 struct peer *other;
3145
3146 ret = str2sockunion(argv[idx_peer]->arg, &su);
3147 if (ret < 0) {
3148 /* look up for neighbor by interface name config. */
3149 peer = peer_lookup_by_conf_if(bgp, argv[idx_peer]->arg);
3150 if (peer) {
3151 /* Request zebra to terminate IPv6 RAs on this
3152 * interface. */
3153 if (peer->ifp)
3154 bgp_zebra_terminate_radv(peer->bgp, peer);
3155 peer_delete(peer);
3156 return CMD_SUCCESS;
3157 }
3158
3159 group = peer_group_lookup(bgp, argv[idx_peer]->arg);
3160 if (group)
3161 peer_group_delete(group);
3162 else {
3163 vty_out(vty, "%% Create the peer-group first\n");
3164 return CMD_WARNING_CONFIG_FAILED;
3165 }
3166 } else {
3167 peer = peer_lookup(bgp, &su);
3168 if (peer) {
3169 if (peer_dynamic_neighbor(peer)) {
3170 vty_out(vty,
3171 "%% Operation not allowed on a dynamic neighbor\n");
3172 return CMD_WARNING_CONFIG_FAILED;
3173 }
3174
3175 other = peer->doppelganger;
3176 peer_delete(peer);
3177 if (other && other->status != Deleted)
3178 peer_delete(other);
3179 }
3180 }
3181
3182 return CMD_SUCCESS;
3183 }
3184
3185 DEFUN (no_neighbor_interface_config,
3186 no_neighbor_interface_config_cmd,
3187 "no neighbor WORD interface [v6only] [peer-group PGNAME] [remote-as <(1-4294967295)|internal|external>]",
3188 NO_STR
3189 NEIGHBOR_STR
3190 "Interface name\n"
3191 "Configure BGP on interface\n"
3192 "Enable BGP with v6 link-local only\n"
3193 "Member of the peer-group\n"
3194 "Peer-group name\n"
3195 "Specify a BGP neighbor\n"
3196 AS_STR
3197 "Internal BGP peer\n"
3198 "External BGP peer\n")
3199 {
3200 VTY_DECLVAR_CONTEXT(bgp, bgp);
3201 int idx_word = 2;
3202 struct peer *peer;
3203
3204 /* look up for neighbor by interface name config. */
3205 peer = peer_lookup_by_conf_if(bgp, argv[idx_word]->arg);
3206 if (peer) {
3207 /* Request zebra to terminate IPv6 RAs on this interface. */
3208 if (peer->ifp)
3209 bgp_zebra_terminate_radv(peer->bgp, peer);
3210 peer_delete(peer);
3211 } else {
3212 vty_out(vty, "%% Create the bgp interface first\n");
3213 return CMD_WARNING_CONFIG_FAILED;
3214 }
3215 return CMD_SUCCESS;
3216 }
3217
3218 DEFUN (no_neighbor_peer_group,
3219 no_neighbor_peer_group_cmd,
3220 "no neighbor WORD peer-group",
3221 NO_STR
3222 NEIGHBOR_STR
3223 "Neighbor tag\n"
3224 "Configure peer-group\n")
3225 {
3226 VTY_DECLVAR_CONTEXT(bgp, bgp);
3227 int idx_word = 2;
3228 struct peer_group *group;
3229
3230 group = peer_group_lookup(bgp, argv[idx_word]->arg);
3231 if (group)
3232 peer_group_delete(group);
3233 else {
3234 vty_out(vty, "%% Create the peer-group first\n");
3235 return CMD_WARNING_CONFIG_FAILED;
3236 }
3237 return CMD_SUCCESS;
3238 }
3239
3240 DEFUN (no_neighbor_interface_peer_group_remote_as,
3241 no_neighbor_interface_peer_group_remote_as_cmd,
3242 "no neighbor WORD remote-as <(1-4294967295)|internal|external>",
3243 NO_STR
3244 NEIGHBOR_STR
3245 "Interface name or neighbor tag\n"
3246 "Specify a BGP neighbor\n"
3247 AS_STR
3248 "Internal BGP peer\n"
3249 "External BGP peer\n")
3250 {
3251 VTY_DECLVAR_CONTEXT(bgp, bgp);
3252 int idx_word = 2;
3253 struct peer_group *group;
3254 struct peer *peer;
3255
3256 /* look up for neighbor by interface name config. */
3257 peer = peer_lookup_by_conf_if(bgp, argv[idx_word]->arg);
3258 if (peer) {
3259 peer_as_change(peer, 0, AS_UNSPECIFIED);
3260 return CMD_SUCCESS;
3261 }
3262
3263 group = peer_group_lookup(bgp, argv[idx_word]->arg);
3264 if (group)
3265 peer_group_remote_as_delete(group);
3266 else {
3267 vty_out(vty, "%% Create the peer-group or interface first\n");
3268 return CMD_WARNING_CONFIG_FAILED;
3269 }
3270 return CMD_SUCCESS;
3271 }
3272
3273 DEFUN (neighbor_local_as,
3274 neighbor_local_as_cmd,
3275 "neighbor <A.B.C.D|X:X::X:X|WORD> local-as (1-4294967295)",
3276 NEIGHBOR_STR
3277 NEIGHBOR_ADDR_STR2
3278 "Specify a local-as number\n"
3279 "AS number used as local AS\n")
3280 {
3281 int idx_peer = 1;
3282 int idx_number = 3;
3283 struct peer *peer;
3284 int ret;
3285 as_t as;
3286
3287 peer = peer_and_group_lookup_vty(vty, argv[idx_peer]->arg);
3288 if (!peer)
3289 return CMD_WARNING_CONFIG_FAILED;
3290
3291 as = strtoul(argv[idx_number]->arg, NULL, 10);
3292 ret = peer_local_as_set(peer, as, 0, 0);
3293 return bgp_vty_return(vty, ret);
3294 }
3295
3296 DEFUN (neighbor_local_as_no_prepend,
3297 neighbor_local_as_no_prepend_cmd,
3298 "neighbor <A.B.C.D|X:X::X:X|WORD> local-as (1-4294967295) no-prepend",
3299 NEIGHBOR_STR
3300 NEIGHBOR_ADDR_STR2
3301 "Specify a local-as number\n"
3302 "AS number used as local AS\n"
3303 "Do not prepend local-as to updates from ebgp peers\n")
3304 {
3305 int idx_peer = 1;
3306 int idx_number = 3;
3307 struct peer *peer;
3308 int ret;
3309 as_t as;
3310
3311 peer = peer_and_group_lookup_vty(vty, argv[idx_peer]->arg);
3312 if (!peer)
3313 return CMD_WARNING_CONFIG_FAILED;
3314
3315 as = strtoul(argv[idx_number]->arg, NULL, 10);
3316 ret = peer_local_as_set(peer, as, 1, 0);
3317 return bgp_vty_return(vty, ret);
3318 }
3319
3320 DEFUN (neighbor_local_as_no_prepend_replace_as,
3321 neighbor_local_as_no_prepend_replace_as_cmd,
3322 "neighbor <A.B.C.D|X:X::X:X|WORD> local-as (1-4294967295) no-prepend replace-as",
3323 NEIGHBOR_STR
3324 NEIGHBOR_ADDR_STR2
3325 "Specify a local-as number\n"
3326 "AS number used as local AS\n"
3327 "Do not prepend local-as to updates from ebgp peers\n"
3328 "Do not prepend local-as to updates from ibgp peers\n")
3329 {
3330 int idx_peer = 1;
3331 int idx_number = 3;
3332 struct peer *peer;
3333 int ret;
3334 as_t as;
3335
3336 peer = peer_and_group_lookup_vty(vty, argv[idx_peer]->arg);
3337 if (!peer)
3338 return CMD_WARNING_CONFIG_FAILED;
3339
3340 as = strtoul(argv[idx_number]->arg, NULL, 10);
3341 ret = peer_local_as_set(peer, as, 1, 1);
3342 return bgp_vty_return(vty, ret);
3343 }
3344
3345 DEFUN (no_neighbor_local_as,
3346 no_neighbor_local_as_cmd,
3347 "no neighbor <A.B.C.D|X:X::X:X|WORD> local-as [(1-4294967295) [no-prepend [replace-as]]]",
3348 NO_STR
3349 NEIGHBOR_STR
3350 NEIGHBOR_ADDR_STR2
3351 "Specify a local-as number\n"
3352 "AS number used as local AS\n"
3353 "Do not prepend local-as to updates from ebgp peers\n"
3354 "Do not prepend local-as to updates from ibgp peers\n")
3355 {
3356 int idx_peer = 2;
3357 struct peer *peer;
3358 int ret;
3359
3360 peer = peer_and_group_lookup_vty(vty, argv[idx_peer]->arg);
3361 if (!peer)
3362 return CMD_WARNING_CONFIG_FAILED;
3363
3364 ret = peer_local_as_unset(peer);
3365 return bgp_vty_return(vty, ret);
3366 }
3367
3368
3369 DEFUN (neighbor_solo,
3370 neighbor_solo_cmd,
3371 "neighbor <A.B.C.D|X:X::X:X|WORD> solo",
3372 NEIGHBOR_STR
3373 NEIGHBOR_ADDR_STR2
3374 "Solo peer - part of its own update group\n")
3375 {
3376 int idx_peer = 1;
3377 struct peer *peer;
3378 int ret;
3379
3380 peer = peer_and_group_lookup_vty(vty, argv[idx_peer]->arg);
3381 if (!peer)
3382 return CMD_WARNING_CONFIG_FAILED;
3383
3384 ret = update_group_adjust_soloness(peer, 1);
3385 return bgp_vty_return(vty, ret);
3386 }
3387
3388 DEFUN (no_neighbor_solo,
3389 no_neighbor_solo_cmd,
3390 "no neighbor <A.B.C.D|X:X::X:X|WORD> solo",
3391 NO_STR
3392 NEIGHBOR_STR
3393 NEIGHBOR_ADDR_STR2
3394 "Solo peer - part of its own update group\n")
3395 {
3396 int idx_peer = 2;
3397 struct peer *peer;
3398 int ret;
3399
3400 peer = peer_and_group_lookup_vty(vty, argv[idx_peer]->arg);
3401 if (!peer)
3402 return CMD_WARNING_CONFIG_FAILED;
3403
3404 ret = update_group_adjust_soloness(peer, 0);
3405 return bgp_vty_return(vty, ret);
3406 }
3407
3408 DEFUN (neighbor_password,
3409 neighbor_password_cmd,
3410 "neighbor <A.B.C.D|X:X::X:X|WORD> password LINE",
3411 NEIGHBOR_STR
3412 NEIGHBOR_ADDR_STR2
3413 "Set a password\n"
3414 "The password\n")
3415 {
3416 int idx_peer = 1;
3417 int idx_line = 3;
3418 struct peer *peer;
3419 int ret;
3420
3421 peer = peer_and_group_lookup_vty(vty, argv[idx_peer]->arg);
3422 if (!peer)
3423 return CMD_WARNING_CONFIG_FAILED;
3424
3425 ret = peer_password_set(peer, argv[idx_line]->arg);
3426 return bgp_vty_return(vty, ret);
3427 }
3428
3429 DEFUN (no_neighbor_password,
3430 no_neighbor_password_cmd,
3431 "no neighbor <A.B.C.D|X:X::X:X|WORD> password [LINE]",
3432 NO_STR
3433 NEIGHBOR_STR
3434 NEIGHBOR_ADDR_STR2
3435 "Set a password\n"
3436 "The password\n")
3437 {
3438 int idx_peer = 2;
3439 struct peer *peer;
3440 int ret;
3441
3442 peer = peer_and_group_lookup_vty(vty, argv[idx_peer]->arg);
3443 if (!peer)
3444 return CMD_WARNING_CONFIG_FAILED;
3445
3446 ret = peer_password_unset(peer);
3447 return bgp_vty_return(vty, ret);
3448 }
3449
3450 DEFUN (neighbor_activate,
3451 neighbor_activate_cmd,
3452 "neighbor <A.B.C.D|X:X::X:X|WORD> activate",
3453 NEIGHBOR_STR
3454 NEIGHBOR_ADDR_STR2
3455 "Enable the Address Family for this Neighbor\n")
3456 {
3457 int idx_peer = 1;
3458 int ret;
3459 struct peer *peer;
3460
3461 peer = peer_and_group_lookup_vty(vty, argv[idx_peer]->arg);
3462 if (!peer)
3463 return CMD_WARNING_CONFIG_FAILED;
3464
3465 ret = peer_activate(peer, bgp_node_afi(vty), bgp_node_safi(vty));
3466 return bgp_vty_return(vty, ret);
3467 }
3468
3469 ALIAS_HIDDEN(neighbor_activate, neighbor_activate_hidden_cmd,
3470 "neighbor <A.B.C.D|X:X::X:X|WORD> activate",
3471 NEIGHBOR_STR NEIGHBOR_ADDR_STR2
3472 "Enable the Address Family for this Neighbor\n")
3473
3474 DEFUN (no_neighbor_activate,
3475 no_neighbor_activate_cmd,
3476 "no neighbor <A.B.C.D|X:X::X:X|WORD> activate",
3477 NO_STR
3478 NEIGHBOR_STR
3479 NEIGHBOR_ADDR_STR2
3480 "Enable the Address Family for this Neighbor\n")
3481 {
3482 int idx_peer = 2;
3483 int ret;
3484 struct peer *peer;
3485
3486 /* Lookup peer. */
3487 peer = peer_and_group_lookup_vty(vty, argv[idx_peer]->arg);
3488 if (!peer)
3489 return CMD_WARNING_CONFIG_FAILED;
3490
3491 ret = peer_deactivate(peer, bgp_node_afi(vty), bgp_node_safi(vty));
3492 return bgp_vty_return(vty, ret);
3493 }
3494
3495 ALIAS_HIDDEN(no_neighbor_activate, no_neighbor_activate_hidden_cmd,
3496 "no neighbor <A.B.C.D|X:X::X:X|WORD> activate",
3497 NO_STR NEIGHBOR_STR NEIGHBOR_ADDR_STR2
3498 "Enable the Address Family for this Neighbor\n")
3499
3500 DEFUN (neighbor_set_peer_group,
3501 neighbor_set_peer_group_cmd,
3502 "neighbor <A.B.C.D|X:X::X:X|WORD> peer-group PGNAME",
3503 NEIGHBOR_STR
3504 NEIGHBOR_ADDR_STR2
3505 "Member of the peer-group\n"
3506 "Peer-group name\n")
3507 {
3508 VTY_DECLVAR_CONTEXT(bgp, bgp);
3509 int idx_peer = 1;
3510 int idx_word = 3;
3511 int ret;
3512 as_t as;
3513 union sockunion su;
3514 struct peer *peer;
3515 struct peer_group *group;
3516
3517 ret = str2sockunion(argv[idx_peer]->arg, &su);
3518 if (ret < 0) {
3519 peer = peer_lookup_by_conf_if(bgp, argv[idx_peer]->arg);
3520 if (!peer) {
3521 vty_out(vty, "%% Malformed address or name: %s\n",
3522 argv[idx_peer]->arg);
3523 return CMD_WARNING_CONFIG_FAILED;
3524 }
3525 } else {
3526 if (peer_address_self_check(bgp, &su)) {
3527 vty_out(vty,
3528 "%% Can not configure the local system as neighbor\n");
3529 return CMD_WARNING_CONFIG_FAILED;
3530 }
3531
3532 /* Disallow for dynamic neighbor. */
3533 peer = peer_lookup(bgp, &su);
3534 if (peer && peer_dynamic_neighbor(peer)) {
3535 vty_out(vty,
3536 "%% Operation not allowed on a dynamic neighbor\n");
3537 return CMD_WARNING_CONFIG_FAILED;
3538 }
3539 }
3540
3541 group = peer_group_lookup(bgp, argv[idx_word]->arg);
3542 if (!group) {
3543 vty_out(vty, "%% Configure the peer-group first\n");
3544 return CMD_WARNING_CONFIG_FAILED;
3545 }
3546
3547 ret = peer_group_bind(bgp, &su, peer, group, &as);
3548
3549 if (ret == BGP_ERR_PEER_GROUP_PEER_TYPE_DIFFERENT) {
3550 vty_out(vty,
3551 "%% Peer with AS %u cannot be in this peer-group, members must be all internal or all external\n",
3552 as);
3553 return CMD_WARNING_CONFIG_FAILED;
3554 }
3555
3556 return bgp_vty_return(vty, ret);
3557 }
3558
3559 ALIAS_HIDDEN(neighbor_set_peer_group, neighbor_set_peer_group_hidden_cmd,
3560 "neighbor <A.B.C.D|X:X::X:X|WORD> peer-group PGNAME",
3561 NEIGHBOR_STR NEIGHBOR_ADDR_STR2
3562 "Member of the peer-group\n"
3563 "Peer-group name\n")
3564
3565 DEFUN (no_neighbor_set_peer_group,
3566 no_neighbor_set_peer_group_cmd,
3567 "no neighbor <A.B.C.D|X:X::X:X|WORD> peer-group PGNAME",
3568 NO_STR
3569 NEIGHBOR_STR
3570 NEIGHBOR_ADDR_STR2
3571 "Member of the peer-group\n"
3572 "Peer-group name\n")
3573 {
3574 VTY_DECLVAR_CONTEXT(bgp, bgp);
3575 int idx_peer = 2;
3576 int idx_word = 4;
3577 int ret;
3578 struct peer *peer;
3579 struct peer_group *group;
3580
3581 peer = peer_lookup_vty(vty, argv[idx_peer]->arg);
3582 if (!peer)
3583 return CMD_WARNING_CONFIG_FAILED;
3584
3585 group = peer_group_lookup(bgp, argv[idx_word]->arg);
3586 if (!group) {
3587 vty_out(vty, "%% Configure the peer-group first\n");
3588 return CMD_WARNING_CONFIG_FAILED;
3589 }
3590
3591 ret = peer_delete(peer);
3592
3593 return bgp_vty_return(vty, ret);
3594 }
3595
3596 ALIAS_HIDDEN(no_neighbor_set_peer_group, no_neighbor_set_peer_group_hidden_cmd,
3597 "no neighbor <A.B.C.D|X:X::X:X|WORD> peer-group PGNAME",
3598 NO_STR NEIGHBOR_STR NEIGHBOR_ADDR_STR2
3599 "Member of the peer-group\n"
3600 "Peer-group name\n")
3601
3602 static int peer_flag_modify_vty(struct vty *vty, const char *ip_str,
3603 uint32_t flag, int set)
3604 {
3605 int ret;
3606 struct peer *peer;
3607
3608 peer = peer_and_group_lookup_vty(vty, ip_str);
3609 if (!peer)
3610 return CMD_WARNING_CONFIG_FAILED;
3611
3612 /*
3613 * If 'neighbor <interface>', then this is for directly connected peers,
3614 * we should not accept disable-connected-check.
3615 */
3616 if (peer->conf_if && (flag == PEER_FLAG_DISABLE_CONNECTED_CHECK)) {
3617 vty_out(vty,
3618 "%s is directly connected peer, cannot accept disable-"
3619 "connected-check\n",
3620 ip_str);
3621 return CMD_WARNING_CONFIG_FAILED;
3622 }
3623
3624 if (!set && flag == PEER_FLAG_SHUTDOWN)
3625 peer_tx_shutdown_message_unset(peer);
3626
3627 if (set)
3628 ret = peer_flag_set(peer, flag);
3629 else
3630 ret = peer_flag_unset(peer, flag);
3631
3632 return bgp_vty_return(vty, ret);
3633 }
3634
3635 static int peer_flag_set_vty(struct vty *vty, const char *ip_str, uint32_t flag)
3636 {
3637 return peer_flag_modify_vty(vty, ip_str, flag, 1);
3638 }
3639
3640 static int peer_flag_unset_vty(struct vty *vty, const char *ip_str,
3641 uint32_t flag)
3642 {
3643 return peer_flag_modify_vty(vty, ip_str, flag, 0);
3644 }
3645
3646 /* neighbor passive. */
3647 DEFUN (neighbor_passive,
3648 neighbor_passive_cmd,
3649 "neighbor <A.B.C.D|X:X::X:X|WORD> passive",
3650 NEIGHBOR_STR
3651 NEIGHBOR_ADDR_STR2
3652 "Don't send open messages to this neighbor\n")
3653 {
3654 int idx_peer = 1;
3655 return peer_flag_set_vty(vty, argv[idx_peer]->arg, PEER_FLAG_PASSIVE);
3656 }
3657
3658 DEFUN (no_neighbor_passive,
3659 no_neighbor_passive_cmd,
3660 "no neighbor <A.B.C.D|X:X::X:X|WORD> passive",
3661 NO_STR
3662 NEIGHBOR_STR
3663 NEIGHBOR_ADDR_STR2
3664 "Don't send open messages to this neighbor\n")
3665 {
3666 int idx_peer = 2;
3667 return peer_flag_unset_vty(vty, argv[idx_peer]->arg, PEER_FLAG_PASSIVE);
3668 }
3669
3670 /* neighbor shutdown. */
3671 DEFUN (neighbor_shutdown_msg,
3672 neighbor_shutdown_msg_cmd,
3673 "neighbor <A.B.C.D|X:X::X:X|WORD> shutdown message MSG...",
3674 NEIGHBOR_STR
3675 NEIGHBOR_ADDR_STR2
3676 "Administratively shut down this neighbor\n"
3677 "Add a shutdown message (draft-ietf-idr-shutdown-06)\n"
3678 "Shutdown message\n")
3679 {
3680 int idx_peer = 1;
3681
3682 if (argc >= 5) {
3683 struct peer *peer =
3684 peer_and_group_lookup_vty(vty, argv[idx_peer]->arg);
3685 char *message;
3686
3687 if (!peer)
3688 return CMD_WARNING_CONFIG_FAILED;
3689 message = argv_concat(argv, argc, 4);
3690 peer_tx_shutdown_message_set(peer, message);
3691 XFREE(MTYPE_TMP, message);
3692 }
3693
3694 return peer_flag_set_vty(vty, argv[idx_peer]->arg, PEER_FLAG_SHUTDOWN);
3695 }
3696
3697 ALIAS(neighbor_shutdown_msg, neighbor_shutdown_cmd,
3698 "neighbor <A.B.C.D|X:X::X:X|WORD> shutdown",
3699 NEIGHBOR_STR NEIGHBOR_ADDR_STR2
3700 "Administratively shut down this neighbor\n")
3701
3702 DEFUN (no_neighbor_shutdown_msg,
3703 no_neighbor_shutdown_msg_cmd,
3704 "no neighbor <A.B.C.D|X:X::X:X|WORD> shutdown message MSG...",
3705 NO_STR
3706 NEIGHBOR_STR
3707 NEIGHBOR_ADDR_STR2
3708 "Administratively shut down this neighbor\n"
3709 "Remove a shutdown message (draft-ietf-idr-shutdown-06)\n"
3710 "Shutdown message\n")
3711 {
3712 int idx_peer = 2;
3713
3714 return peer_flag_unset_vty(vty, argv[idx_peer]->arg,
3715 PEER_FLAG_SHUTDOWN);
3716 }
3717
3718 ALIAS(no_neighbor_shutdown_msg, no_neighbor_shutdown_cmd,
3719 "no neighbor <A.B.C.D|X:X::X:X|WORD> shutdown",
3720 NO_STR NEIGHBOR_STR NEIGHBOR_ADDR_STR2
3721 "Administratively shut down this neighbor\n")
3722
3723 /* neighbor capability dynamic. */
3724 DEFUN (neighbor_capability_dynamic,
3725 neighbor_capability_dynamic_cmd,
3726 "neighbor <A.B.C.D|X:X::X:X|WORD> capability dynamic",
3727 NEIGHBOR_STR
3728 NEIGHBOR_ADDR_STR2
3729 "Advertise capability to the peer\n"
3730 "Advertise dynamic capability to this neighbor\n")
3731 {
3732 int idx_peer = 1;
3733 return peer_flag_set_vty(vty, argv[idx_peer]->arg,
3734 PEER_FLAG_DYNAMIC_CAPABILITY);
3735 }
3736
3737 DEFUN (no_neighbor_capability_dynamic,
3738 no_neighbor_capability_dynamic_cmd,
3739 "no neighbor <A.B.C.D|X:X::X:X|WORD> capability dynamic",
3740 NO_STR
3741 NEIGHBOR_STR
3742 NEIGHBOR_ADDR_STR2
3743 "Advertise capability to the peer\n"
3744 "Advertise dynamic capability to this neighbor\n")
3745 {
3746 int idx_peer = 2;
3747 return peer_flag_unset_vty(vty, argv[idx_peer]->arg,
3748 PEER_FLAG_DYNAMIC_CAPABILITY);
3749 }
3750
3751 /* neighbor dont-capability-negotiate */
3752 DEFUN (neighbor_dont_capability_negotiate,
3753 neighbor_dont_capability_negotiate_cmd,
3754 "neighbor <A.B.C.D|X:X::X:X|WORD> dont-capability-negotiate",
3755 NEIGHBOR_STR
3756 NEIGHBOR_ADDR_STR2
3757 "Do not perform capability negotiation\n")
3758 {
3759 int idx_peer = 1;
3760 return peer_flag_set_vty(vty, argv[idx_peer]->arg,
3761 PEER_FLAG_DONT_CAPABILITY);
3762 }
3763
3764 DEFUN (no_neighbor_dont_capability_negotiate,
3765 no_neighbor_dont_capability_negotiate_cmd,
3766 "no neighbor <A.B.C.D|X:X::X:X|WORD> dont-capability-negotiate",
3767 NO_STR
3768 NEIGHBOR_STR
3769 NEIGHBOR_ADDR_STR2
3770 "Do not perform capability negotiation\n")
3771 {
3772 int idx_peer = 2;
3773 return peer_flag_unset_vty(vty, argv[idx_peer]->arg,
3774 PEER_FLAG_DONT_CAPABILITY);
3775 }
3776
3777 /* neighbor capability extended next hop encoding */
3778 DEFUN (neighbor_capability_enhe,
3779 neighbor_capability_enhe_cmd,
3780 "neighbor <A.B.C.D|X:X::X:X|WORD> capability extended-nexthop",
3781 NEIGHBOR_STR
3782 NEIGHBOR_ADDR_STR2
3783 "Advertise capability to the peer\n"
3784 "Advertise extended next-hop capability to the peer\n")
3785 {
3786 int idx_peer = 1;
3787 return peer_flag_set_vty(vty, argv[idx_peer]->arg,
3788 PEER_FLAG_CAPABILITY_ENHE);
3789 }
3790
3791 DEFUN (no_neighbor_capability_enhe,
3792 no_neighbor_capability_enhe_cmd,
3793 "no neighbor <A.B.C.D|X:X::X:X|WORD> capability extended-nexthop",
3794 NO_STR
3795 NEIGHBOR_STR
3796 NEIGHBOR_ADDR_STR2
3797 "Advertise capability to the peer\n"
3798 "Advertise extended next-hop capability to the peer\n")
3799 {
3800 int idx_peer = 2;
3801 return peer_flag_unset_vty(vty, argv[idx_peer]->arg,
3802 PEER_FLAG_CAPABILITY_ENHE);
3803 }
3804
3805 static int peer_af_flag_modify_vty(struct vty *vty, const char *peer_str,
3806 afi_t afi, safi_t safi, uint32_t flag,
3807 int set)
3808 {
3809 int ret;
3810 struct peer *peer;
3811
3812 peer = peer_and_group_lookup_vty(vty, peer_str);
3813 if (!peer)
3814 return CMD_WARNING_CONFIG_FAILED;
3815
3816 if (set)
3817 ret = peer_af_flag_set(peer, afi, safi, flag);
3818 else
3819 ret = peer_af_flag_unset(peer, afi, safi, flag);
3820
3821 return bgp_vty_return(vty, ret);
3822 }
3823
3824 static int peer_af_flag_set_vty(struct vty *vty, const char *peer_str,
3825 afi_t afi, safi_t safi, uint32_t flag)
3826 {
3827 return peer_af_flag_modify_vty(vty, peer_str, afi, safi, flag, 1);
3828 }
3829
3830 static int peer_af_flag_unset_vty(struct vty *vty, const char *peer_str,
3831 afi_t afi, safi_t safi, uint32_t flag)
3832 {
3833 return peer_af_flag_modify_vty(vty, peer_str, afi, safi, flag, 0);
3834 }
3835
3836 /* neighbor capability orf prefix-list. */
3837 DEFUN (neighbor_capability_orf_prefix,
3838 neighbor_capability_orf_prefix_cmd,
3839 "neighbor <A.B.C.D|X:X::X:X|WORD> capability orf prefix-list <both|send|receive>",
3840 NEIGHBOR_STR
3841 NEIGHBOR_ADDR_STR2
3842 "Advertise capability to the peer\n"
3843 "Advertise ORF capability to the peer\n"
3844 "Advertise prefixlist ORF capability to this neighbor\n"
3845 "Capability to SEND and RECEIVE the ORF to/from this neighbor\n"
3846 "Capability to RECEIVE the ORF from this neighbor\n"
3847 "Capability to SEND the ORF to this neighbor\n")
3848 {
3849 int idx_peer = 1;
3850 int idx_send_recv = 5;
3851 uint16_t flag = 0;
3852
3853 if (strmatch(argv[idx_send_recv]->text, "send"))
3854 flag = PEER_FLAG_ORF_PREFIX_SM;
3855 else if (strmatch(argv[idx_send_recv]->text, "receive"))
3856 flag = PEER_FLAG_ORF_PREFIX_RM;
3857 else if (strmatch(argv[idx_send_recv]->text, "both"))
3858 flag = PEER_FLAG_ORF_PREFIX_SM | PEER_FLAG_ORF_PREFIX_RM;
3859 else {
3860 vty_out(vty, "%% BGP invalid orf prefix-list option\n");
3861 return CMD_WARNING_CONFIG_FAILED;
3862 }
3863
3864 return peer_af_flag_set_vty(vty, argv[idx_peer]->arg, bgp_node_afi(vty),
3865 bgp_node_safi(vty), flag);
3866 }
3867
3868 ALIAS_HIDDEN(
3869 neighbor_capability_orf_prefix,
3870 neighbor_capability_orf_prefix_hidden_cmd,
3871 "neighbor <A.B.C.D|X:X::X:X|WORD> capability orf prefix-list <both|send|receive>",
3872 NEIGHBOR_STR NEIGHBOR_ADDR_STR2
3873 "Advertise capability to the peer\n"
3874 "Advertise ORF capability to the peer\n"
3875 "Advertise prefixlist ORF capability to this neighbor\n"
3876 "Capability to SEND and RECEIVE the ORF to/from this neighbor\n"
3877 "Capability to RECEIVE the ORF from this neighbor\n"
3878 "Capability to SEND the ORF to this neighbor\n")
3879
3880 DEFUN (no_neighbor_capability_orf_prefix,
3881 no_neighbor_capability_orf_prefix_cmd,
3882 "no neighbor <A.B.C.D|X:X::X:X|WORD> capability orf prefix-list <both|send|receive>",
3883 NO_STR
3884 NEIGHBOR_STR
3885 NEIGHBOR_ADDR_STR2
3886 "Advertise capability to the peer\n"
3887 "Advertise ORF capability to the peer\n"
3888 "Advertise prefixlist ORF capability to this neighbor\n"
3889 "Capability to SEND and RECEIVE the ORF to/from this neighbor\n"
3890 "Capability to RECEIVE the ORF from this neighbor\n"
3891 "Capability to SEND the ORF to this neighbor\n")
3892 {
3893 int idx_peer = 2;
3894 int idx_send_recv = 6;
3895 uint16_t flag = 0;
3896
3897 if (strmatch(argv[idx_send_recv]->text, "send"))
3898 flag = PEER_FLAG_ORF_PREFIX_SM;
3899 else if (strmatch(argv[idx_send_recv]->text, "receive"))
3900 flag = PEER_FLAG_ORF_PREFIX_RM;
3901 else if (strmatch(argv[idx_send_recv]->text, "both"))
3902 flag = PEER_FLAG_ORF_PREFIX_SM | PEER_FLAG_ORF_PREFIX_RM;
3903 else {
3904 vty_out(vty, "%% BGP invalid orf prefix-list option\n");
3905 return CMD_WARNING_CONFIG_FAILED;
3906 }
3907
3908 return peer_af_flag_unset_vty(vty, argv[idx_peer]->arg,
3909 bgp_node_afi(vty), bgp_node_safi(vty),
3910 flag);
3911 }
3912
3913 ALIAS_HIDDEN(
3914 no_neighbor_capability_orf_prefix,
3915 no_neighbor_capability_orf_prefix_hidden_cmd,
3916 "no neighbor <A.B.C.D|X:X::X:X|WORD> capability orf prefix-list <both|send|receive>",
3917 NO_STR NEIGHBOR_STR NEIGHBOR_ADDR_STR2
3918 "Advertise capability to the peer\n"
3919 "Advertise ORF capability to the peer\n"
3920 "Advertise prefixlist ORF capability to this neighbor\n"
3921 "Capability to SEND and RECEIVE the ORF to/from this neighbor\n"
3922 "Capability to RECEIVE the ORF from this neighbor\n"
3923 "Capability to SEND the ORF to this neighbor\n")
3924
3925 /* neighbor next-hop-self. */
3926 DEFUN (neighbor_nexthop_self,
3927 neighbor_nexthop_self_cmd,
3928 "neighbor <A.B.C.D|X:X::X:X|WORD> next-hop-self",
3929 NEIGHBOR_STR
3930 NEIGHBOR_ADDR_STR2
3931 "Disable the next hop calculation for this neighbor\n")
3932 {
3933 int idx_peer = 1;
3934 return peer_af_flag_set_vty(vty, argv[idx_peer]->arg, bgp_node_afi(vty),
3935 bgp_node_safi(vty), PEER_FLAG_NEXTHOP_SELF);
3936 }
3937
3938 ALIAS_HIDDEN(neighbor_nexthop_self, neighbor_nexthop_self_hidden_cmd,
3939 "neighbor <A.B.C.D|X:X::X:X|WORD> next-hop-self",
3940 NEIGHBOR_STR NEIGHBOR_ADDR_STR2
3941 "Disable the next hop calculation for this neighbor\n")
3942
3943 /* neighbor next-hop-self. */
3944 DEFUN (neighbor_nexthop_self_force,
3945 neighbor_nexthop_self_force_cmd,
3946 "neighbor <A.B.C.D|X:X::X:X|WORD> next-hop-self force",
3947 NEIGHBOR_STR
3948 NEIGHBOR_ADDR_STR2
3949 "Disable the next hop calculation for this neighbor\n"
3950 "Set the next hop to self for reflected routes\n")
3951 {
3952 int idx_peer = 1;
3953 return peer_af_flag_set_vty(vty, argv[idx_peer]->arg, bgp_node_afi(vty),
3954 bgp_node_safi(vty),
3955 PEER_FLAG_FORCE_NEXTHOP_SELF);
3956 }
3957
3958 ALIAS_HIDDEN(neighbor_nexthop_self_force,
3959 neighbor_nexthop_self_force_hidden_cmd,
3960 "neighbor <A.B.C.D|X:X::X:X|WORD> next-hop-self force",
3961 NEIGHBOR_STR NEIGHBOR_ADDR_STR2
3962 "Disable the next hop calculation for this neighbor\n"
3963 "Set the next hop to self for reflected routes\n")
3964
3965 ALIAS_HIDDEN(neighbor_nexthop_self_force,
3966 neighbor_nexthop_self_all_hidden_cmd,
3967 "neighbor <A.B.C.D|X:X::X:X|WORD> next-hop-self all",
3968 NEIGHBOR_STR NEIGHBOR_ADDR_STR2
3969 "Disable the next hop calculation for this neighbor\n"
3970 "Set the next hop to self for reflected routes\n")
3971
3972 DEFUN (no_neighbor_nexthop_self,
3973 no_neighbor_nexthop_self_cmd,
3974 "no neighbor <A.B.C.D|X:X::X:X|WORD> next-hop-self",
3975 NO_STR
3976 NEIGHBOR_STR
3977 NEIGHBOR_ADDR_STR2
3978 "Disable the next hop calculation for this neighbor\n")
3979 {
3980 int idx_peer = 2;
3981 return peer_af_flag_unset_vty(vty, argv[idx_peer]->arg,
3982 bgp_node_afi(vty), bgp_node_safi(vty),
3983 PEER_FLAG_NEXTHOP_SELF);
3984 }
3985
3986 ALIAS_HIDDEN(no_neighbor_nexthop_self, no_neighbor_nexthop_self_hidden_cmd,
3987 "no neighbor <A.B.C.D|X:X::X:X|WORD> next-hop-self",
3988 NO_STR NEIGHBOR_STR NEIGHBOR_ADDR_STR2
3989 "Disable the next hop calculation for this neighbor\n")
3990
3991 DEFUN (no_neighbor_nexthop_self_force,
3992 no_neighbor_nexthop_self_force_cmd,
3993 "no neighbor <A.B.C.D|X:X::X:X|WORD> next-hop-self force",
3994 NO_STR
3995 NEIGHBOR_STR
3996 NEIGHBOR_ADDR_STR2
3997 "Disable the next hop calculation for this neighbor\n"
3998 "Set the next hop to self for reflected routes\n")
3999 {
4000 int idx_peer = 2;
4001 return peer_af_flag_unset_vty(vty, argv[idx_peer]->arg,
4002 bgp_node_afi(vty), bgp_node_safi(vty),
4003 PEER_FLAG_FORCE_NEXTHOP_SELF);
4004 }
4005
4006 ALIAS_HIDDEN(no_neighbor_nexthop_self_force,
4007 no_neighbor_nexthop_self_force_hidden_cmd,
4008 "no neighbor <A.B.C.D|X:X::X:X|WORD> next-hop-self force",
4009 NO_STR NEIGHBOR_STR NEIGHBOR_ADDR_STR2
4010 "Disable the next hop calculation for this neighbor\n"
4011 "Set the next hop to self for reflected routes\n")
4012
4013 ALIAS_HIDDEN(no_neighbor_nexthop_self_force,
4014 no_neighbor_nexthop_self_all_hidden_cmd,
4015 "no neighbor <A.B.C.D|X:X::X:X|WORD> next-hop-self all",
4016 NO_STR NEIGHBOR_STR NEIGHBOR_ADDR_STR2
4017 "Disable the next hop calculation for this neighbor\n"
4018 "Set the next hop to self for reflected routes\n")
4019
4020 /* neighbor as-override */
4021 DEFUN (neighbor_as_override,
4022 neighbor_as_override_cmd,
4023 "neighbor <A.B.C.D|X:X::X:X|WORD> as-override",
4024 NEIGHBOR_STR
4025 NEIGHBOR_ADDR_STR2
4026 "Override ASNs in outbound updates if aspath equals remote-as\n")
4027 {
4028 int idx_peer = 1;
4029 return peer_af_flag_set_vty(vty, argv[idx_peer]->arg, bgp_node_afi(vty),
4030 bgp_node_safi(vty), PEER_FLAG_AS_OVERRIDE);
4031 }
4032
4033 ALIAS_HIDDEN(neighbor_as_override, neighbor_as_override_hidden_cmd,
4034 "neighbor <A.B.C.D|X:X::X:X|WORD> as-override",
4035 NEIGHBOR_STR NEIGHBOR_ADDR_STR2
4036 "Override ASNs in outbound updates if aspath equals remote-as\n")
4037
4038 DEFUN (no_neighbor_as_override,
4039 no_neighbor_as_override_cmd,
4040 "no neighbor <A.B.C.D|X:X::X:X|WORD> as-override",
4041 NO_STR
4042 NEIGHBOR_STR
4043 NEIGHBOR_ADDR_STR2
4044 "Override ASNs in outbound updates if aspath equals remote-as\n")
4045 {
4046 int idx_peer = 2;
4047 return peer_af_flag_unset_vty(vty, argv[idx_peer]->arg,
4048 bgp_node_afi(vty), bgp_node_safi(vty),
4049 PEER_FLAG_AS_OVERRIDE);
4050 }
4051
4052 ALIAS_HIDDEN(no_neighbor_as_override, no_neighbor_as_override_hidden_cmd,
4053 "no neighbor <A.B.C.D|X:X::X:X|WORD> as-override",
4054 NO_STR NEIGHBOR_STR NEIGHBOR_ADDR_STR2
4055 "Override ASNs in outbound updates if aspath equals remote-as\n")
4056
4057 /* neighbor remove-private-AS. */
4058 DEFUN (neighbor_remove_private_as,
4059 neighbor_remove_private_as_cmd,
4060 "neighbor <A.B.C.D|X:X::X:X|WORD> remove-private-AS",
4061 NEIGHBOR_STR
4062 NEIGHBOR_ADDR_STR2
4063 "Remove private ASNs in outbound updates\n")
4064 {
4065 int idx_peer = 1;
4066 return peer_af_flag_set_vty(vty, argv[idx_peer]->arg, bgp_node_afi(vty),
4067 bgp_node_safi(vty),
4068 PEER_FLAG_REMOVE_PRIVATE_AS);
4069 }
4070
4071 ALIAS_HIDDEN(neighbor_remove_private_as, neighbor_remove_private_as_hidden_cmd,
4072 "neighbor <A.B.C.D|X:X::X:X|WORD> remove-private-AS",
4073 NEIGHBOR_STR NEIGHBOR_ADDR_STR2
4074 "Remove private ASNs in outbound updates\n")
4075
4076 DEFUN (neighbor_remove_private_as_all,
4077 neighbor_remove_private_as_all_cmd,
4078 "neighbor <A.B.C.D|X:X::X:X|WORD> remove-private-AS all",
4079 NEIGHBOR_STR
4080 NEIGHBOR_ADDR_STR2
4081 "Remove private ASNs in outbound updates\n"
4082 "Apply to all AS numbers\n")
4083 {
4084 int idx_peer = 1;
4085 return peer_af_flag_set_vty(vty, argv[idx_peer]->arg, bgp_node_afi(vty),
4086 bgp_node_safi(vty),
4087 PEER_FLAG_REMOVE_PRIVATE_AS_ALL);
4088 }
4089
4090 ALIAS_HIDDEN(neighbor_remove_private_as_all,
4091 neighbor_remove_private_as_all_hidden_cmd,
4092 "neighbor <A.B.C.D|X:X::X:X|WORD> remove-private-AS all",
4093 NEIGHBOR_STR NEIGHBOR_ADDR_STR2
4094 "Remove private ASNs in outbound updates\n"
4095 "Apply to all AS numbers")
4096
4097 DEFUN (neighbor_remove_private_as_replace_as,
4098 neighbor_remove_private_as_replace_as_cmd,
4099 "neighbor <A.B.C.D|X:X::X:X|WORD> remove-private-AS replace-AS",
4100 NEIGHBOR_STR
4101 NEIGHBOR_ADDR_STR2
4102 "Remove private ASNs in outbound updates\n"
4103 "Replace private ASNs with our ASN in outbound updates\n")
4104 {
4105 int idx_peer = 1;
4106 return peer_af_flag_set_vty(vty, argv[idx_peer]->arg, bgp_node_afi(vty),
4107 bgp_node_safi(vty),
4108 PEER_FLAG_REMOVE_PRIVATE_AS_REPLACE);
4109 }
4110
4111 ALIAS_HIDDEN(neighbor_remove_private_as_replace_as,
4112 neighbor_remove_private_as_replace_as_hidden_cmd,
4113 "neighbor <A.B.C.D|X:X::X:X|WORD> remove-private-AS replace-AS",
4114 NEIGHBOR_STR NEIGHBOR_ADDR_STR2
4115 "Remove private ASNs in outbound updates\n"
4116 "Replace private ASNs with our ASN in outbound updates\n")
4117
4118 DEFUN (neighbor_remove_private_as_all_replace_as,
4119 neighbor_remove_private_as_all_replace_as_cmd,
4120 "neighbor <A.B.C.D|X:X::X:X|WORD> remove-private-AS all replace-AS",
4121 NEIGHBOR_STR
4122 NEIGHBOR_ADDR_STR2
4123 "Remove private ASNs in outbound updates\n"
4124 "Apply to all AS numbers\n"
4125 "Replace private ASNs with our ASN in outbound updates\n")
4126 {
4127 int idx_peer = 1;
4128 return peer_af_flag_set_vty(vty, argv[idx_peer]->arg, bgp_node_afi(vty),
4129 bgp_node_safi(vty),
4130 PEER_FLAG_REMOVE_PRIVATE_AS_ALL_REPLACE);
4131 }
4132
4133 ALIAS_HIDDEN(
4134 neighbor_remove_private_as_all_replace_as,
4135 neighbor_remove_private_as_all_replace_as_hidden_cmd,
4136 "neighbor <A.B.C.D|X:X::X:X|WORD> remove-private-AS all replace-AS",
4137 NEIGHBOR_STR NEIGHBOR_ADDR_STR2
4138 "Remove private ASNs in outbound updates\n"
4139 "Apply to all AS numbers\n"
4140 "Replace private ASNs with our ASN in outbound updates\n")
4141
4142 DEFUN (no_neighbor_remove_private_as,
4143 no_neighbor_remove_private_as_cmd,
4144 "no neighbor <A.B.C.D|X:X::X:X|WORD> remove-private-AS",
4145 NO_STR
4146 NEIGHBOR_STR
4147 NEIGHBOR_ADDR_STR2
4148 "Remove private ASNs in outbound updates\n")
4149 {
4150 int idx_peer = 2;
4151 return peer_af_flag_unset_vty(vty, argv[idx_peer]->arg,
4152 bgp_node_afi(vty), bgp_node_safi(vty),
4153 PEER_FLAG_REMOVE_PRIVATE_AS);
4154 }
4155
4156 ALIAS_HIDDEN(no_neighbor_remove_private_as,
4157 no_neighbor_remove_private_as_hidden_cmd,
4158 "no neighbor <A.B.C.D|X:X::X:X|WORD> remove-private-AS",
4159 NO_STR NEIGHBOR_STR NEIGHBOR_ADDR_STR2
4160 "Remove private ASNs in outbound updates\n")
4161
4162 DEFUN (no_neighbor_remove_private_as_all,
4163 no_neighbor_remove_private_as_all_cmd,
4164 "no neighbor <A.B.C.D|X:X::X:X|WORD> remove-private-AS all",
4165 NO_STR
4166 NEIGHBOR_STR
4167 NEIGHBOR_ADDR_STR2
4168 "Remove private ASNs in outbound updates\n"
4169 "Apply to all AS numbers\n")
4170 {
4171 int idx_peer = 2;
4172 return peer_af_flag_unset_vty(vty, argv[idx_peer]->arg,
4173 bgp_node_afi(vty), bgp_node_safi(vty),
4174 PEER_FLAG_REMOVE_PRIVATE_AS_ALL);
4175 }
4176
4177 ALIAS_HIDDEN(no_neighbor_remove_private_as_all,
4178 no_neighbor_remove_private_as_all_hidden_cmd,
4179 "no neighbor <A.B.C.D|X:X::X:X|WORD> remove-private-AS all",
4180 NO_STR NEIGHBOR_STR NEIGHBOR_ADDR_STR2
4181 "Remove private ASNs in outbound updates\n"
4182 "Apply to all AS numbers\n")
4183
4184 DEFUN (no_neighbor_remove_private_as_replace_as,
4185 no_neighbor_remove_private_as_replace_as_cmd,
4186 "no neighbor <A.B.C.D|X:X::X:X|WORD> remove-private-AS replace-AS",
4187 NO_STR
4188 NEIGHBOR_STR
4189 NEIGHBOR_ADDR_STR2
4190 "Remove private ASNs in outbound updates\n"
4191 "Replace private ASNs with our ASN in outbound updates\n")
4192 {
4193 int idx_peer = 2;
4194 return peer_af_flag_unset_vty(vty, argv[idx_peer]->arg,
4195 bgp_node_afi(vty), bgp_node_safi(vty),
4196 PEER_FLAG_REMOVE_PRIVATE_AS_REPLACE);
4197 }
4198
4199 ALIAS_HIDDEN(no_neighbor_remove_private_as_replace_as,
4200 no_neighbor_remove_private_as_replace_as_hidden_cmd,
4201 "no neighbor <A.B.C.D|X:X::X:X|WORD> remove-private-AS replace-AS",
4202 NO_STR NEIGHBOR_STR NEIGHBOR_ADDR_STR2
4203 "Remove private ASNs in outbound updates\n"
4204 "Replace private ASNs with our ASN in outbound updates\n")
4205
4206 DEFUN (no_neighbor_remove_private_as_all_replace_as,
4207 no_neighbor_remove_private_as_all_replace_as_cmd,
4208 "no neighbor <A.B.C.D|X:X::X:X|WORD> remove-private-AS all replace-AS",
4209 NO_STR
4210 NEIGHBOR_STR
4211 NEIGHBOR_ADDR_STR2
4212 "Remove private ASNs in outbound updates\n"
4213 "Apply to all AS numbers\n"
4214 "Replace private ASNs with our ASN in outbound updates\n")
4215 {
4216 int idx_peer = 2;
4217 return peer_af_flag_unset_vty(vty, argv[idx_peer]->arg,
4218 bgp_node_afi(vty), bgp_node_safi(vty),
4219 PEER_FLAG_REMOVE_PRIVATE_AS_ALL_REPLACE);
4220 }
4221
4222 ALIAS_HIDDEN(
4223 no_neighbor_remove_private_as_all_replace_as,
4224 no_neighbor_remove_private_as_all_replace_as_hidden_cmd,
4225 "no neighbor <A.B.C.D|X:X::X:X|WORD> remove-private-AS all replace-AS",
4226 NO_STR NEIGHBOR_STR NEIGHBOR_ADDR_STR2
4227 "Remove private ASNs in outbound updates\n"
4228 "Apply to all AS numbers\n"
4229 "Replace private ASNs with our ASN in outbound updates\n")
4230
4231
4232 /* neighbor send-community. */
4233 DEFUN (neighbor_send_community,
4234 neighbor_send_community_cmd,
4235 "neighbor <A.B.C.D|X:X::X:X|WORD> send-community",
4236 NEIGHBOR_STR
4237 NEIGHBOR_ADDR_STR2
4238 "Send Community attribute to this neighbor\n")
4239 {
4240 int idx_peer = 1;
4241
4242 return peer_af_flag_set_vty(vty, argv[idx_peer]->arg, bgp_node_afi(vty),
4243 bgp_node_safi(vty),
4244 PEER_FLAG_SEND_COMMUNITY);
4245 }
4246
4247 ALIAS_HIDDEN(neighbor_send_community, neighbor_send_community_hidden_cmd,
4248 "neighbor <A.B.C.D|X:X::X:X|WORD> send-community",
4249 NEIGHBOR_STR NEIGHBOR_ADDR_STR2
4250 "Send Community attribute to this neighbor\n")
4251
4252 DEFUN (no_neighbor_send_community,
4253 no_neighbor_send_community_cmd,
4254 "no neighbor <A.B.C.D|X:X::X:X|WORD> send-community",
4255 NO_STR
4256 NEIGHBOR_STR
4257 NEIGHBOR_ADDR_STR2
4258 "Send Community attribute to this neighbor\n")
4259 {
4260 int idx_peer = 2;
4261
4262 return peer_af_flag_unset_vty(vty, argv[idx_peer]->arg,
4263 bgp_node_afi(vty), bgp_node_safi(vty),
4264 PEER_FLAG_SEND_COMMUNITY);
4265 }
4266
4267 ALIAS_HIDDEN(no_neighbor_send_community, no_neighbor_send_community_hidden_cmd,
4268 "no neighbor <A.B.C.D|X:X::X:X|WORD> send-community",
4269 NO_STR NEIGHBOR_STR NEIGHBOR_ADDR_STR2
4270 "Send Community attribute to this neighbor\n")
4271
4272 /* neighbor send-community extended. */
4273 DEFUN (neighbor_send_community_type,
4274 neighbor_send_community_type_cmd,
4275 "neighbor <A.B.C.D|X:X::X:X|WORD> send-community <both|all|extended|standard|large>",
4276 NEIGHBOR_STR
4277 NEIGHBOR_ADDR_STR2
4278 "Send Community attribute to this neighbor\n"
4279 "Send Standard and Extended Community attributes\n"
4280 "Send Standard, Large and Extended Community attributes\n"
4281 "Send Extended Community attributes\n"
4282 "Send Standard Community attributes\n"
4283 "Send Large Community attributes\n")
4284 {
4285 int idx_peer = 1;
4286 uint32_t flag = 0;
4287 const char *type = argv[argc - 1]->text;
4288
4289 if (strmatch(type, "standard")) {
4290 SET_FLAG(flag, PEER_FLAG_SEND_COMMUNITY);
4291 } else if (strmatch(type, "extended")) {
4292 SET_FLAG(flag, PEER_FLAG_SEND_EXT_COMMUNITY);
4293 } else if (strmatch(type, "large")) {
4294 SET_FLAG(flag, PEER_FLAG_SEND_LARGE_COMMUNITY);
4295 } else if (strmatch(type, "both")) {
4296 SET_FLAG(flag, PEER_FLAG_SEND_COMMUNITY);
4297 SET_FLAG(flag, PEER_FLAG_SEND_EXT_COMMUNITY);
4298 } else { /* if (strmatch(type, "all")) */
4299 SET_FLAG(flag, PEER_FLAG_SEND_COMMUNITY);
4300 SET_FLAG(flag, PEER_FLAG_SEND_EXT_COMMUNITY);
4301 SET_FLAG(flag, PEER_FLAG_SEND_LARGE_COMMUNITY);
4302 }
4303
4304 return peer_af_flag_set_vty(vty, argv[idx_peer]->arg, bgp_node_afi(vty),
4305 bgp_node_safi(vty), flag);
4306 }
4307
4308 ALIAS_HIDDEN(
4309 neighbor_send_community_type, neighbor_send_community_type_hidden_cmd,
4310 "neighbor <A.B.C.D|X:X::X:X|WORD> send-community <both|all|extended|standard|large>",
4311 NEIGHBOR_STR NEIGHBOR_ADDR_STR2
4312 "Send Community attribute to this neighbor\n"
4313 "Send Standard and Extended Community attributes\n"
4314 "Send Standard, Large and Extended Community attributes\n"
4315 "Send Extended Community attributes\n"
4316 "Send Standard Community attributes\n"
4317 "Send Large Community attributes\n")
4318
4319 DEFUN (no_neighbor_send_community_type,
4320 no_neighbor_send_community_type_cmd,
4321 "no neighbor <A.B.C.D|X:X::X:X|WORD> send-community <both|all|extended|standard|large>",
4322 NO_STR
4323 NEIGHBOR_STR
4324 NEIGHBOR_ADDR_STR2
4325 "Send Community attribute to this neighbor\n"
4326 "Send Standard and Extended Community attributes\n"
4327 "Send Standard, Large and Extended Community attributes\n"
4328 "Send Extended Community attributes\n"
4329 "Send Standard Community attributes\n"
4330 "Send Large Community attributes\n")
4331 {
4332 int idx_peer = 2;
4333 uint32_t flag = 0;
4334 const char *type = argv[argc - 1]->text;
4335
4336 if (strmatch(type, "standard")) {
4337 SET_FLAG(flag, PEER_FLAG_SEND_COMMUNITY);
4338 } else if (strmatch(type, "extended")) {
4339 SET_FLAG(flag, PEER_FLAG_SEND_EXT_COMMUNITY);
4340 } else if (strmatch(type, "large")) {
4341 SET_FLAG(flag, PEER_FLAG_SEND_LARGE_COMMUNITY);
4342 } else if (strmatch(type, "both")) {
4343 SET_FLAG(flag, PEER_FLAG_SEND_COMMUNITY);
4344 SET_FLAG(flag, PEER_FLAG_SEND_EXT_COMMUNITY);
4345 } else { /* if (strmatch(type, "all")) */
4346 SET_FLAG(flag, PEER_FLAG_SEND_COMMUNITY);
4347 SET_FLAG(flag, PEER_FLAG_SEND_EXT_COMMUNITY);
4348 SET_FLAG(flag, PEER_FLAG_SEND_LARGE_COMMUNITY);
4349 }
4350
4351 return peer_af_flag_unset_vty(vty, argv[idx_peer]->arg,
4352 bgp_node_afi(vty), bgp_node_safi(vty),
4353 flag);
4354 }
4355
4356 ALIAS_HIDDEN(
4357 no_neighbor_send_community_type,
4358 no_neighbor_send_community_type_hidden_cmd,
4359 "no neighbor <A.B.C.D|X:X::X:X|WORD> send-community <both|all|extended|standard|large>",
4360 NO_STR NEIGHBOR_STR NEIGHBOR_ADDR_STR2
4361 "Send Community attribute to this neighbor\n"
4362 "Send Standard and Extended Community attributes\n"
4363 "Send Standard, Large and Extended Community attributes\n"
4364 "Send Extended Community attributes\n"
4365 "Send Standard Community attributes\n"
4366 "Send Large Community attributes\n")
4367
4368 /* neighbor soft-reconfig. */
4369 DEFUN (neighbor_soft_reconfiguration,
4370 neighbor_soft_reconfiguration_cmd,
4371 "neighbor <A.B.C.D|X:X::X:X|WORD> soft-reconfiguration inbound",
4372 NEIGHBOR_STR
4373 NEIGHBOR_ADDR_STR2
4374 "Per neighbor soft reconfiguration\n"
4375 "Allow inbound soft reconfiguration for this neighbor\n")
4376 {
4377 int idx_peer = 1;
4378 return peer_af_flag_set_vty(vty, argv[idx_peer]->arg, bgp_node_afi(vty),
4379 bgp_node_safi(vty),
4380 PEER_FLAG_SOFT_RECONFIG);
4381 }
4382
4383 ALIAS_HIDDEN(neighbor_soft_reconfiguration,
4384 neighbor_soft_reconfiguration_hidden_cmd,
4385 "neighbor <A.B.C.D|X:X::X:X|WORD> soft-reconfiguration inbound",
4386 NEIGHBOR_STR NEIGHBOR_ADDR_STR2
4387 "Per neighbor soft reconfiguration\n"
4388 "Allow inbound soft reconfiguration for this neighbor\n")
4389
4390 DEFUN (no_neighbor_soft_reconfiguration,
4391 no_neighbor_soft_reconfiguration_cmd,
4392 "no neighbor <A.B.C.D|X:X::X:X|WORD> soft-reconfiguration inbound",
4393 NO_STR
4394 NEIGHBOR_STR
4395 NEIGHBOR_ADDR_STR2
4396 "Per neighbor soft reconfiguration\n"
4397 "Allow inbound soft reconfiguration for this neighbor\n")
4398 {
4399 int idx_peer = 2;
4400 return peer_af_flag_unset_vty(vty, argv[idx_peer]->arg,
4401 bgp_node_afi(vty), bgp_node_safi(vty),
4402 PEER_FLAG_SOFT_RECONFIG);
4403 }
4404
4405 ALIAS_HIDDEN(no_neighbor_soft_reconfiguration,
4406 no_neighbor_soft_reconfiguration_hidden_cmd,
4407 "no neighbor <A.B.C.D|X:X::X:X|WORD> soft-reconfiguration inbound",
4408 NO_STR NEIGHBOR_STR NEIGHBOR_ADDR_STR2
4409 "Per neighbor soft reconfiguration\n"
4410 "Allow inbound soft reconfiguration for this neighbor\n")
4411
4412 DEFUN (neighbor_route_reflector_client,
4413 neighbor_route_reflector_client_cmd,
4414 "neighbor <A.B.C.D|X:X::X:X|WORD> route-reflector-client",
4415 NEIGHBOR_STR
4416 NEIGHBOR_ADDR_STR2
4417 "Configure a neighbor as Route Reflector client\n")
4418 {
4419 int idx_peer = 1;
4420 struct peer *peer;
4421
4422
4423 peer = peer_and_group_lookup_vty(vty, argv[idx_peer]->arg);
4424 if (!peer)
4425 return CMD_WARNING_CONFIG_FAILED;
4426
4427 return peer_af_flag_set_vty(vty, argv[idx_peer]->arg, bgp_node_afi(vty),
4428 bgp_node_safi(vty),
4429 PEER_FLAG_REFLECTOR_CLIENT);
4430 }
4431
4432 ALIAS_HIDDEN(neighbor_route_reflector_client,
4433 neighbor_route_reflector_client_hidden_cmd,
4434 "neighbor <A.B.C.D|X:X::X:X|WORD> route-reflector-client",
4435 NEIGHBOR_STR NEIGHBOR_ADDR_STR2
4436 "Configure a neighbor as Route Reflector client\n")
4437
4438 DEFUN (no_neighbor_route_reflector_client,
4439 no_neighbor_route_reflector_client_cmd,
4440 "no neighbor <A.B.C.D|X:X::X:X|WORD> route-reflector-client",
4441 NO_STR
4442 NEIGHBOR_STR
4443 NEIGHBOR_ADDR_STR2
4444 "Configure a neighbor as Route Reflector client\n")
4445 {
4446 int idx_peer = 2;
4447 return peer_af_flag_unset_vty(vty, argv[idx_peer]->arg,
4448 bgp_node_afi(vty), bgp_node_safi(vty),
4449 PEER_FLAG_REFLECTOR_CLIENT);
4450 }
4451
4452 ALIAS_HIDDEN(no_neighbor_route_reflector_client,
4453 no_neighbor_route_reflector_client_hidden_cmd,
4454 "no neighbor <A.B.C.D|X:X::X:X|WORD> route-reflector-client",
4455 NO_STR NEIGHBOR_STR NEIGHBOR_ADDR_STR2
4456 "Configure a neighbor as Route Reflector client\n")
4457
4458 /* neighbor route-server-client. */
4459 DEFUN (neighbor_route_server_client,
4460 neighbor_route_server_client_cmd,
4461 "neighbor <A.B.C.D|X:X::X:X|WORD> route-server-client",
4462 NEIGHBOR_STR
4463 NEIGHBOR_ADDR_STR2
4464 "Configure a neighbor as Route Server client\n")
4465 {
4466 int idx_peer = 1;
4467 struct peer *peer;
4468
4469 peer = peer_and_group_lookup_vty(vty, argv[idx_peer]->arg);
4470 if (!peer)
4471 return CMD_WARNING_CONFIG_FAILED;
4472 return peer_af_flag_set_vty(vty, argv[idx_peer]->arg, bgp_node_afi(vty),
4473 bgp_node_safi(vty),
4474 PEER_FLAG_RSERVER_CLIENT);
4475 }
4476
4477 ALIAS_HIDDEN(neighbor_route_server_client,
4478 neighbor_route_server_client_hidden_cmd,
4479 "neighbor <A.B.C.D|X:X::X:X|WORD> route-server-client",
4480 NEIGHBOR_STR NEIGHBOR_ADDR_STR2
4481 "Configure a neighbor as Route Server client\n")
4482
4483 DEFUN (no_neighbor_route_server_client,
4484 no_neighbor_route_server_client_cmd,
4485 "no neighbor <A.B.C.D|X:X::X:X|WORD> route-server-client",
4486 NO_STR
4487 NEIGHBOR_STR
4488 NEIGHBOR_ADDR_STR2
4489 "Configure a neighbor as Route Server client\n")
4490 {
4491 int idx_peer = 2;
4492 return peer_af_flag_unset_vty(vty, argv[idx_peer]->arg,
4493 bgp_node_afi(vty), bgp_node_safi(vty),
4494 PEER_FLAG_RSERVER_CLIENT);
4495 }
4496
4497 ALIAS_HIDDEN(no_neighbor_route_server_client,
4498 no_neighbor_route_server_client_hidden_cmd,
4499 "no neighbor <A.B.C.D|X:X::X:X|WORD> route-server-client",
4500 NO_STR NEIGHBOR_STR NEIGHBOR_ADDR_STR2
4501 "Configure a neighbor as Route Server client\n")
4502
4503 DEFUN (neighbor_nexthop_local_unchanged,
4504 neighbor_nexthop_local_unchanged_cmd,
4505 "neighbor <A.B.C.D|X:X::X:X|WORD> nexthop-local unchanged",
4506 NEIGHBOR_STR
4507 NEIGHBOR_ADDR_STR2
4508 "Configure treatment of outgoing link-local nexthop attribute\n"
4509 "Leave link-local nexthop unchanged for this peer\n")
4510 {
4511 int idx_peer = 1;
4512 return peer_af_flag_set_vty(vty, argv[idx_peer]->arg, bgp_node_afi(vty),
4513 bgp_node_safi(vty),
4514 PEER_FLAG_NEXTHOP_LOCAL_UNCHANGED);
4515 }
4516
4517 DEFUN (no_neighbor_nexthop_local_unchanged,
4518 no_neighbor_nexthop_local_unchanged_cmd,
4519 "no neighbor <A.B.C.D|X:X::X:X|WORD> nexthop-local unchanged",
4520 NO_STR
4521 NEIGHBOR_STR
4522 NEIGHBOR_ADDR_STR2
4523 "Configure treatment of outgoing link-local-nexthop attribute\n"
4524 "Leave link-local nexthop unchanged for this peer\n")
4525 {
4526 int idx_peer = 2;
4527 return peer_af_flag_unset_vty(vty, argv[idx_peer]->arg,
4528 bgp_node_afi(vty), bgp_node_safi(vty),
4529 PEER_FLAG_NEXTHOP_LOCAL_UNCHANGED);
4530 }
4531
4532 DEFUN (neighbor_attr_unchanged,
4533 neighbor_attr_unchanged_cmd,
4534 "neighbor <A.B.C.D|X:X::X:X|WORD> attribute-unchanged [{as-path|next-hop|med}]",
4535 NEIGHBOR_STR
4536 NEIGHBOR_ADDR_STR2
4537 "BGP attribute is propagated unchanged to this neighbor\n"
4538 "As-path attribute\n"
4539 "Nexthop attribute\n"
4540 "Med attribute\n")
4541 {
4542 int idx = 0;
4543 char *peer_str = argv[1]->arg;
4544 struct peer *peer;
4545 uint16_t flags = 0;
4546 afi_t afi = bgp_node_afi(vty);
4547 safi_t safi = bgp_node_safi(vty);
4548
4549 peer = peer_and_group_lookup_vty(vty, peer_str);
4550 if (!peer)
4551 return CMD_WARNING_CONFIG_FAILED;
4552
4553 if (argv_find(argv, argc, "as-path", &idx))
4554 SET_FLAG(flags, PEER_FLAG_AS_PATH_UNCHANGED);
4555 idx = 0;
4556 if (argv_find(argv, argc, "next-hop", &idx))
4557 SET_FLAG(flags, PEER_FLAG_NEXTHOP_UNCHANGED);
4558 idx = 0;
4559 if (argv_find(argv, argc, "med", &idx))
4560 SET_FLAG(flags, PEER_FLAG_MED_UNCHANGED);
4561
4562 /* no flags means all of them! */
4563 if (!flags) {
4564 SET_FLAG(flags, PEER_FLAG_AS_PATH_UNCHANGED);
4565 SET_FLAG(flags, PEER_FLAG_NEXTHOP_UNCHANGED);
4566 SET_FLAG(flags, PEER_FLAG_MED_UNCHANGED);
4567 } else {
4568 if (!CHECK_FLAG(flags, PEER_FLAG_AS_PATH_UNCHANGED)
4569 && peer_af_flag_check(peer, afi, safi,
4570 PEER_FLAG_AS_PATH_UNCHANGED)) {
4571 peer_af_flag_unset_vty(vty, peer_str, afi, safi,
4572 PEER_FLAG_AS_PATH_UNCHANGED);
4573 }
4574
4575 if (!CHECK_FLAG(flags, PEER_FLAG_NEXTHOP_UNCHANGED)
4576 && peer_af_flag_check(peer, afi, safi,
4577 PEER_FLAG_NEXTHOP_UNCHANGED)) {
4578 peer_af_flag_unset_vty(vty, peer_str, afi, safi,
4579 PEER_FLAG_NEXTHOP_UNCHANGED);
4580 }
4581
4582 if (!CHECK_FLAG(flags, PEER_FLAG_MED_UNCHANGED)
4583 && peer_af_flag_check(peer, afi, safi,
4584 PEER_FLAG_MED_UNCHANGED)) {
4585 peer_af_flag_unset_vty(vty, peer_str, afi, safi,
4586 PEER_FLAG_MED_UNCHANGED);
4587 }
4588 }
4589
4590 return peer_af_flag_set_vty(vty, peer_str, afi, safi, flags);
4591 }
4592
4593 ALIAS_HIDDEN(
4594 neighbor_attr_unchanged, neighbor_attr_unchanged_hidden_cmd,
4595 "neighbor <A.B.C.D|X:X::X:X|WORD> attribute-unchanged [{as-path|next-hop|med}]",
4596 NEIGHBOR_STR NEIGHBOR_ADDR_STR2
4597 "BGP attribute is propagated unchanged to this neighbor\n"
4598 "As-path attribute\n"
4599 "Nexthop attribute\n"
4600 "Med attribute\n")
4601
4602 DEFUN (no_neighbor_attr_unchanged,
4603 no_neighbor_attr_unchanged_cmd,
4604 "no neighbor <A.B.C.D|X:X::X:X|WORD> attribute-unchanged [{as-path|next-hop|med}]",
4605 NO_STR
4606 NEIGHBOR_STR
4607 NEIGHBOR_ADDR_STR2
4608 "BGP attribute is propagated unchanged to this neighbor\n"
4609 "As-path attribute\n"
4610 "Nexthop attribute\n"
4611 "Med attribute\n")
4612 {
4613 int idx = 0;
4614 char *peer = argv[2]->arg;
4615 uint16_t flags = 0;
4616
4617 if (argv_find(argv, argc, "as-path", &idx))
4618 SET_FLAG(flags, PEER_FLAG_AS_PATH_UNCHANGED);
4619 idx = 0;
4620 if (argv_find(argv, argc, "next-hop", &idx))
4621 SET_FLAG(flags, PEER_FLAG_NEXTHOP_UNCHANGED);
4622 idx = 0;
4623 if (argv_find(argv, argc, "med", &idx))
4624 SET_FLAG(flags, PEER_FLAG_MED_UNCHANGED);
4625
4626 if (!flags) // no flags means all of them!
4627 {
4628 SET_FLAG(flags, PEER_FLAG_AS_PATH_UNCHANGED);
4629 SET_FLAG(flags, PEER_FLAG_NEXTHOP_UNCHANGED);
4630 SET_FLAG(flags, PEER_FLAG_MED_UNCHANGED);
4631 }
4632
4633 return peer_af_flag_unset_vty(vty, peer, bgp_node_afi(vty),
4634 bgp_node_safi(vty), flags);
4635 }
4636
4637 ALIAS_HIDDEN(
4638 no_neighbor_attr_unchanged, no_neighbor_attr_unchanged_hidden_cmd,
4639 "no neighbor <A.B.C.D|X:X::X:X|WORD> attribute-unchanged [{as-path|next-hop|med}]",
4640 NO_STR NEIGHBOR_STR NEIGHBOR_ADDR_STR2
4641 "BGP attribute is propagated unchanged to this neighbor\n"
4642 "As-path attribute\n"
4643 "Nexthop attribute\n"
4644 "Med attribute\n")
4645
4646 /* EBGP multihop configuration. */
4647 static int peer_ebgp_multihop_set_vty(struct vty *vty, const char *ip_str,
4648 const char *ttl_str)
4649 {
4650 struct peer *peer;
4651 unsigned int ttl;
4652
4653 peer = peer_and_group_lookup_vty(vty, ip_str);
4654 if (!peer)
4655 return CMD_WARNING_CONFIG_FAILED;
4656
4657 if (peer->conf_if)
4658 return bgp_vty_return(vty, BGP_ERR_INVALID_FOR_DIRECT_PEER);
4659
4660 if (!ttl_str)
4661 ttl = MAXTTL;
4662 else
4663 ttl = strtoul(ttl_str, NULL, 10);
4664
4665 return bgp_vty_return(vty, peer_ebgp_multihop_set(peer, ttl));
4666 }
4667
4668 static int peer_ebgp_multihop_unset_vty(struct vty *vty, const char *ip_str)
4669 {
4670 struct peer *peer;
4671
4672 peer = peer_and_group_lookup_vty(vty, ip_str);
4673 if (!peer)
4674 return CMD_WARNING_CONFIG_FAILED;
4675
4676 return bgp_vty_return(vty, peer_ebgp_multihop_unset(peer));
4677 }
4678
4679 /* neighbor ebgp-multihop. */
4680 DEFUN (neighbor_ebgp_multihop,
4681 neighbor_ebgp_multihop_cmd,
4682 "neighbor <A.B.C.D|X:X::X:X|WORD> ebgp-multihop",
4683 NEIGHBOR_STR
4684 NEIGHBOR_ADDR_STR2
4685 "Allow EBGP neighbors not on directly connected networks\n")
4686 {
4687 int idx_peer = 1;
4688 return peer_ebgp_multihop_set_vty(vty, argv[idx_peer]->arg, NULL);
4689 }
4690
4691 DEFUN (neighbor_ebgp_multihop_ttl,
4692 neighbor_ebgp_multihop_ttl_cmd,
4693 "neighbor <A.B.C.D|X:X::X:X|WORD> ebgp-multihop (1-255)",
4694 NEIGHBOR_STR
4695 NEIGHBOR_ADDR_STR2
4696 "Allow EBGP neighbors not on directly connected networks\n"
4697 "maximum hop count\n")
4698 {
4699 int idx_peer = 1;
4700 int idx_number = 3;
4701 return peer_ebgp_multihop_set_vty(vty, argv[idx_peer]->arg,
4702 argv[idx_number]->arg);
4703 }
4704
4705 DEFUN (no_neighbor_ebgp_multihop,
4706 no_neighbor_ebgp_multihop_cmd,
4707 "no neighbor <A.B.C.D|X:X::X:X|WORD> ebgp-multihop [(1-255)]",
4708 NO_STR
4709 NEIGHBOR_STR
4710 NEIGHBOR_ADDR_STR2
4711 "Allow EBGP neighbors not on directly connected networks\n"
4712 "maximum hop count\n")
4713 {
4714 int idx_peer = 2;
4715 return peer_ebgp_multihop_unset_vty(vty, argv[idx_peer]->arg);
4716 }
4717
4718
4719 /* disable-connected-check */
4720 DEFUN (neighbor_disable_connected_check,
4721 neighbor_disable_connected_check_cmd,
4722 "neighbor <A.B.C.D|X:X::X:X|WORD> <disable-connected-check|enforce-multihop>",
4723 NEIGHBOR_STR
4724 NEIGHBOR_ADDR_STR2
4725 "one-hop away EBGP peer using loopback address\n"
4726 "Enforce EBGP neighbors perform multihop\n")
4727 {
4728 int idx_peer = 1;
4729 return peer_flag_set_vty(vty, argv[idx_peer]->arg,
4730 PEER_FLAG_DISABLE_CONNECTED_CHECK);
4731 }
4732
4733 DEFUN (no_neighbor_disable_connected_check,
4734 no_neighbor_disable_connected_check_cmd,
4735 "no neighbor <A.B.C.D|X:X::X:X|WORD> <disable-connected-check|enforce-multihop>",
4736 NO_STR
4737 NEIGHBOR_STR
4738 NEIGHBOR_ADDR_STR2
4739 "one-hop away EBGP peer using loopback address\n"
4740 "Enforce EBGP neighbors perform multihop\n")
4741 {
4742 int idx_peer = 2;
4743 return peer_flag_unset_vty(vty, argv[idx_peer]->arg,
4744 PEER_FLAG_DISABLE_CONNECTED_CHECK);
4745 }
4746
4747
4748 /* enforce-first-as */
4749 DEFUN (neighbor_enforce_first_as,
4750 neighbor_enforce_first_as_cmd,
4751 "neighbor <A.B.C.D|X:X::X:X|WORD> enforce-first-as",
4752 NEIGHBOR_STR
4753 NEIGHBOR_ADDR_STR2
4754 "Enforce the first AS for EBGP routes\n")
4755 {
4756 int idx_peer = 1;
4757
4758 return peer_flag_set_vty(vty, argv[idx_peer]->arg,
4759 PEER_FLAG_ENFORCE_FIRST_AS);
4760 }
4761
4762 DEFUN (no_neighbor_enforce_first_as,
4763 no_neighbor_enforce_first_as_cmd,
4764 "no neighbor <A.B.C.D|X:X::X:X|WORD> enforce-first-as",
4765 NO_STR
4766 NEIGHBOR_STR
4767 NEIGHBOR_ADDR_STR2
4768 "Enforce the first AS for EBGP routes\n")
4769 {
4770 int idx_peer = 2;
4771
4772 return peer_flag_unset_vty(vty, argv[idx_peer]->arg,
4773 PEER_FLAG_ENFORCE_FIRST_AS);
4774 }
4775
4776
4777 DEFUN (neighbor_description,
4778 neighbor_description_cmd,
4779 "neighbor <A.B.C.D|X:X::X:X|WORD> description LINE...",
4780 NEIGHBOR_STR
4781 NEIGHBOR_ADDR_STR2
4782 "Neighbor specific description\n"
4783 "Up to 80 characters describing this neighbor\n")
4784 {
4785 int idx_peer = 1;
4786 int idx_line = 3;
4787 struct peer *peer;
4788 char *str;
4789
4790 peer = peer_and_group_lookup_vty(vty, argv[idx_peer]->arg);
4791 if (!peer)
4792 return CMD_WARNING_CONFIG_FAILED;
4793
4794 str = argv_concat(argv, argc, idx_line);
4795
4796 peer_description_set(peer, str);
4797
4798 XFREE(MTYPE_TMP, str);
4799
4800 return CMD_SUCCESS;
4801 }
4802
4803 DEFUN (no_neighbor_description,
4804 no_neighbor_description_cmd,
4805 "no neighbor <A.B.C.D|X:X::X:X|WORD> description",
4806 NO_STR
4807 NEIGHBOR_STR
4808 NEIGHBOR_ADDR_STR2
4809 "Neighbor specific description\n")
4810 {
4811 int idx_peer = 2;
4812 struct peer *peer;
4813
4814 peer = peer_and_group_lookup_vty(vty, argv[idx_peer]->arg);
4815 if (!peer)
4816 return CMD_WARNING_CONFIG_FAILED;
4817
4818 peer_description_unset(peer);
4819
4820 return CMD_SUCCESS;
4821 }
4822
4823 ALIAS(no_neighbor_description, no_neighbor_description_comment_cmd,
4824 "no neighbor <A.B.C.D|X:X::X:X|WORD> description LINE...",
4825 NO_STR NEIGHBOR_STR NEIGHBOR_ADDR_STR2
4826 "Neighbor specific description\n"
4827 "Up to 80 characters describing this neighbor\n")
4828
4829 /* Neighbor update-source. */
4830 static int peer_update_source_vty(struct vty *vty, const char *peer_str,
4831 const char *source_str)
4832 {
4833 struct peer *peer;
4834 struct prefix p;
4835 union sockunion su;
4836
4837 peer = peer_and_group_lookup_vty(vty, peer_str);
4838 if (!peer)
4839 return CMD_WARNING_CONFIG_FAILED;
4840
4841 if (peer->conf_if)
4842 return CMD_WARNING;
4843
4844 if (source_str) {
4845 if (str2sockunion(source_str, &su) == 0)
4846 peer_update_source_addr_set(peer, &su);
4847 else {
4848 if (str2prefix(source_str, &p)) {
4849 vty_out(vty,
4850 "%% Invalid update-source, remove prefix length \n");
4851 return CMD_WARNING_CONFIG_FAILED;
4852 } else
4853 peer_update_source_if_set(peer, source_str);
4854 }
4855 } else
4856 peer_update_source_unset(peer);
4857
4858 return CMD_SUCCESS;
4859 }
4860
4861 #define BGP_UPDATE_SOURCE_HELP_STR \
4862 "IPv4 address\n" \
4863 "IPv6 address\n" \
4864 "Interface name (requires zebra to be running)\n"
4865
4866 DEFUN (neighbor_update_source,
4867 neighbor_update_source_cmd,
4868 "neighbor <A.B.C.D|X:X::X:X|WORD> update-source <A.B.C.D|X:X::X:X|WORD>",
4869 NEIGHBOR_STR
4870 NEIGHBOR_ADDR_STR2
4871 "Source of routing updates\n"
4872 BGP_UPDATE_SOURCE_HELP_STR)
4873 {
4874 int idx_peer = 1;
4875 int idx_peer_2 = 3;
4876 return peer_update_source_vty(vty, argv[idx_peer]->arg,
4877 argv[idx_peer_2]->arg);
4878 }
4879
4880 DEFUN (no_neighbor_update_source,
4881 no_neighbor_update_source_cmd,
4882 "no neighbor <A.B.C.D|X:X::X:X|WORD> update-source [<A.B.C.D|X:X::X:X|WORD>]",
4883 NO_STR
4884 NEIGHBOR_STR
4885 NEIGHBOR_ADDR_STR2
4886 "Source of routing updates\n"
4887 BGP_UPDATE_SOURCE_HELP_STR)
4888 {
4889 int idx_peer = 2;
4890 return peer_update_source_vty(vty, argv[idx_peer]->arg, NULL);
4891 }
4892
4893 static int peer_default_originate_set_vty(struct vty *vty, const char *peer_str,
4894 afi_t afi, safi_t safi,
4895 const char *rmap, int set)
4896 {
4897 int ret;
4898 struct peer *peer;
4899 struct route_map *route_map = NULL;
4900
4901 peer = peer_and_group_lookup_vty(vty, peer_str);
4902 if (!peer)
4903 return CMD_WARNING_CONFIG_FAILED;
4904
4905 if (set) {
4906 if (rmap)
4907 route_map = route_map_lookup_warn_noexist(vty, rmap);
4908 ret = peer_default_originate_set(peer, afi, safi,
4909 rmap, route_map);
4910 } else
4911 ret = peer_default_originate_unset(peer, afi, safi);
4912
4913 return bgp_vty_return(vty, ret);
4914 }
4915
4916 /* neighbor default-originate. */
4917 DEFUN (neighbor_default_originate,
4918 neighbor_default_originate_cmd,
4919 "neighbor <A.B.C.D|X:X::X:X|WORD> default-originate",
4920 NEIGHBOR_STR
4921 NEIGHBOR_ADDR_STR2
4922 "Originate default route to this neighbor\n")
4923 {
4924 int idx_peer = 1;
4925 return peer_default_originate_set_vty(vty, argv[idx_peer]->arg,
4926 bgp_node_afi(vty),
4927 bgp_node_safi(vty), NULL, 1);
4928 }
4929
4930 ALIAS_HIDDEN(neighbor_default_originate, neighbor_default_originate_hidden_cmd,
4931 "neighbor <A.B.C.D|X:X::X:X|WORD> default-originate",
4932 NEIGHBOR_STR NEIGHBOR_ADDR_STR2
4933 "Originate default route to this neighbor\n")
4934
4935 DEFUN (neighbor_default_originate_rmap,
4936 neighbor_default_originate_rmap_cmd,
4937 "neighbor <A.B.C.D|X:X::X:X|WORD> default-originate route-map WORD",
4938 NEIGHBOR_STR
4939 NEIGHBOR_ADDR_STR2
4940 "Originate default route to this neighbor\n"
4941 "Route-map to specify criteria to originate default\n"
4942 "route-map name\n")
4943 {
4944 int idx_peer = 1;
4945 int idx_word = 4;
4946 return peer_default_originate_set_vty(
4947 vty, argv[idx_peer]->arg, bgp_node_afi(vty), bgp_node_safi(vty),
4948 argv[idx_word]->arg, 1);
4949 }
4950
4951 ALIAS_HIDDEN(
4952 neighbor_default_originate_rmap,
4953 neighbor_default_originate_rmap_hidden_cmd,
4954 "neighbor <A.B.C.D|X:X::X:X|WORD> default-originate route-map WORD",
4955 NEIGHBOR_STR NEIGHBOR_ADDR_STR2
4956 "Originate default route to this neighbor\n"
4957 "Route-map to specify criteria to originate default\n"
4958 "route-map name\n")
4959
4960 DEFUN (no_neighbor_default_originate,
4961 no_neighbor_default_originate_cmd,
4962 "no neighbor <A.B.C.D|X:X::X:X|WORD> default-originate [route-map WORD]",
4963 NO_STR
4964 NEIGHBOR_STR
4965 NEIGHBOR_ADDR_STR2
4966 "Originate default route to this neighbor\n"
4967 "Route-map to specify criteria to originate default\n"
4968 "route-map name\n")
4969 {
4970 int idx_peer = 2;
4971 return peer_default_originate_set_vty(vty, argv[idx_peer]->arg,
4972 bgp_node_afi(vty),
4973 bgp_node_safi(vty), NULL, 0);
4974 }
4975
4976 ALIAS_HIDDEN(
4977 no_neighbor_default_originate, no_neighbor_default_originate_hidden_cmd,
4978 "no neighbor <A.B.C.D|X:X::X:X|WORD> default-originate [route-map WORD]",
4979 NO_STR NEIGHBOR_STR NEIGHBOR_ADDR_STR2
4980 "Originate default route to this neighbor\n"
4981 "Route-map to specify criteria to originate default\n"
4982 "route-map name\n")
4983
4984
4985 /* Set neighbor's BGP port. */
4986 static int peer_port_vty(struct vty *vty, const char *ip_str, int afi,
4987 const char *port_str)
4988 {
4989 struct peer *peer;
4990 uint16_t port;
4991 struct servent *sp;
4992
4993 peer = peer_lookup_vty(vty, ip_str);
4994 if (!peer)
4995 return CMD_WARNING_CONFIG_FAILED;
4996
4997 if (!port_str) {
4998 sp = getservbyname("bgp", "tcp");
4999 port = (sp == NULL) ? BGP_PORT_DEFAULT : ntohs(sp->s_port);
5000 } else {
5001 port = strtoul(port_str, NULL, 10);
5002 }
5003
5004 peer_port_set(peer, port);
5005
5006 return CMD_SUCCESS;
5007 }
5008
5009 /* Set specified peer's BGP port. */
5010 DEFUN (neighbor_port,
5011 neighbor_port_cmd,
5012 "neighbor <A.B.C.D|X:X::X:X> port (0-65535)",
5013 NEIGHBOR_STR
5014 NEIGHBOR_ADDR_STR
5015 "Neighbor's BGP port\n"
5016 "TCP port number\n")
5017 {
5018 int idx_ip = 1;
5019 int idx_number = 3;
5020 return peer_port_vty(vty, argv[idx_ip]->arg, AFI_IP,
5021 argv[idx_number]->arg);
5022 }
5023
5024 DEFUN (no_neighbor_port,
5025 no_neighbor_port_cmd,
5026 "no neighbor <A.B.C.D|X:X::X:X> port [(0-65535)]",
5027 NO_STR
5028 NEIGHBOR_STR
5029 NEIGHBOR_ADDR_STR
5030 "Neighbor's BGP port\n"
5031 "TCP port number\n")
5032 {
5033 int idx_ip = 2;
5034 return peer_port_vty(vty, argv[idx_ip]->arg, AFI_IP, NULL);
5035 }
5036
5037
5038 /* neighbor weight. */
5039 static int peer_weight_set_vty(struct vty *vty, const char *ip_str, afi_t afi,
5040 safi_t safi, const char *weight_str)
5041 {
5042 int ret;
5043 struct peer *peer;
5044 unsigned long weight;
5045
5046 peer = peer_and_group_lookup_vty(vty, ip_str);
5047 if (!peer)
5048 return CMD_WARNING_CONFIG_FAILED;
5049
5050 weight = strtoul(weight_str, NULL, 10);
5051
5052 ret = peer_weight_set(peer, afi, safi, weight);
5053 return bgp_vty_return(vty, ret);
5054 }
5055
5056 static int peer_weight_unset_vty(struct vty *vty, const char *ip_str, afi_t afi,
5057 safi_t safi)
5058 {
5059 int ret;
5060 struct peer *peer;
5061
5062 peer = peer_and_group_lookup_vty(vty, ip_str);
5063 if (!peer)
5064 return CMD_WARNING_CONFIG_FAILED;
5065
5066 ret = peer_weight_unset(peer, afi, safi);
5067 return bgp_vty_return(vty, ret);
5068 }
5069
5070 DEFUN (neighbor_weight,
5071 neighbor_weight_cmd,
5072 "neighbor <A.B.C.D|X:X::X:X|WORD> weight (0-65535)",
5073 NEIGHBOR_STR
5074 NEIGHBOR_ADDR_STR2
5075 "Set default weight for routes from this neighbor\n"
5076 "default weight\n")
5077 {
5078 int idx_peer = 1;
5079 int idx_number = 3;
5080 return peer_weight_set_vty(vty, argv[idx_peer]->arg, bgp_node_afi(vty),
5081 bgp_node_safi(vty), argv[idx_number]->arg);
5082 }
5083
5084 ALIAS_HIDDEN(neighbor_weight, neighbor_weight_hidden_cmd,
5085 "neighbor <A.B.C.D|X:X::X:X|WORD> weight (0-65535)",
5086 NEIGHBOR_STR NEIGHBOR_ADDR_STR2
5087 "Set default weight for routes from this neighbor\n"
5088 "default weight\n")
5089
5090 DEFUN (no_neighbor_weight,
5091 no_neighbor_weight_cmd,
5092 "no neighbor <A.B.C.D|X:X::X:X|WORD> weight [(0-65535)]",
5093 NO_STR
5094 NEIGHBOR_STR
5095 NEIGHBOR_ADDR_STR2
5096 "Set default weight for routes from this neighbor\n"
5097 "default weight\n")
5098 {
5099 int idx_peer = 2;
5100 return peer_weight_unset_vty(vty, argv[idx_peer]->arg,
5101 bgp_node_afi(vty), bgp_node_safi(vty));
5102 }
5103
5104 ALIAS_HIDDEN(no_neighbor_weight, no_neighbor_weight_hidden_cmd,
5105 "no neighbor <A.B.C.D|X:X::X:X|WORD> weight [(0-65535)]",
5106 NO_STR NEIGHBOR_STR NEIGHBOR_ADDR_STR2
5107 "Set default weight for routes from this neighbor\n"
5108 "default weight\n")
5109
5110
5111 /* Override capability negotiation. */
5112 DEFUN (neighbor_override_capability,
5113 neighbor_override_capability_cmd,
5114 "neighbor <A.B.C.D|X:X::X:X|WORD> override-capability",
5115 NEIGHBOR_STR
5116 NEIGHBOR_ADDR_STR2
5117 "Override capability negotiation result\n")
5118 {
5119 int idx_peer = 1;
5120 return peer_flag_set_vty(vty, argv[idx_peer]->arg,
5121 PEER_FLAG_OVERRIDE_CAPABILITY);
5122 }
5123
5124 DEFUN (no_neighbor_override_capability,
5125 no_neighbor_override_capability_cmd,
5126 "no neighbor <A.B.C.D|X:X::X:X|WORD> override-capability",
5127 NO_STR
5128 NEIGHBOR_STR
5129 NEIGHBOR_ADDR_STR2
5130 "Override capability negotiation result\n")
5131 {
5132 int idx_peer = 2;
5133 return peer_flag_unset_vty(vty, argv[idx_peer]->arg,
5134 PEER_FLAG_OVERRIDE_CAPABILITY);
5135 }
5136
5137 DEFUN (neighbor_strict_capability,
5138 neighbor_strict_capability_cmd,
5139 "neighbor <A.B.C.D|X:X::X:X|WORD> strict-capability-match",
5140 NEIGHBOR_STR
5141 NEIGHBOR_ADDR_STR2
5142 "Strict capability negotiation match\n")
5143 {
5144 int idx_peer = 1;
5145
5146 return peer_flag_set_vty(vty, argv[idx_peer]->arg,
5147 PEER_FLAG_STRICT_CAP_MATCH);
5148 }
5149
5150 DEFUN (no_neighbor_strict_capability,
5151 no_neighbor_strict_capability_cmd,
5152 "no neighbor <A.B.C.D|X:X::X:X|WORD> strict-capability-match",
5153 NO_STR
5154 NEIGHBOR_STR
5155 NEIGHBOR_ADDR_STR2
5156 "Strict capability negotiation match\n")
5157 {
5158 int idx_peer = 2;
5159
5160 return peer_flag_unset_vty(vty, argv[idx_peer]->arg,
5161 PEER_FLAG_STRICT_CAP_MATCH);
5162 }
5163
5164 static int peer_timers_set_vty(struct vty *vty, const char *ip_str,
5165 const char *keep_str, const char *hold_str)
5166 {
5167 int ret;
5168 struct peer *peer;
5169 uint32_t keepalive;
5170 uint32_t holdtime;
5171
5172 peer = peer_and_group_lookup_vty(vty, ip_str);
5173 if (!peer)
5174 return CMD_WARNING_CONFIG_FAILED;
5175
5176 keepalive = strtoul(keep_str, NULL, 10);
5177 holdtime = strtoul(hold_str, NULL, 10);
5178
5179 ret = peer_timers_set(peer, keepalive, holdtime);
5180
5181 return bgp_vty_return(vty, ret);
5182 }
5183
5184 static int peer_timers_unset_vty(struct vty *vty, const char *ip_str)
5185 {
5186 int ret;
5187 struct peer *peer;
5188
5189 peer = peer_and_group_lookup_vty(vty, ip_str);
5190 if (!peer)
5191 return CMD_WARNING_CONFIG_FAILED;
5192
5193 ret = peer_timers_unset(peer);
5194
5195 return bgp_vty_return(vty, ret);
5196 }
5197
5198 DEFUN (neighbor_timers,
5199 neighbor_timers_cmd,
5200 "neighbor <A.B.C.D|X:X::X:X|WORD> timers (0-65535) (0-65535)",
5201 NEIGHBOR_STR
5202 NEIGHBOR_ADDR_STR2
5203 "BGP per neighbor timers\n"
5204 "Keepalive interval\n"
5205 "Holdtime\n")
5206 {
5207 int idx_peer = 1;
5208 int idx_number = 3;
5209 int idx_number_2 = 4;
5210 return peer_timers_set_vty(vty, argv[idx_peer]->arg,
5211 argv[idx_number]->arg,
5212 argv[idx_number_2]->arg);
5213 }
5214
5215 DEFUN (no_neighbor_timers,
5216 no_neighbor_timers_cmd,
5217 "no neighbor <A.B.C.D|X:X::X:X|WORD> timers [(0-65535) (0-65535)]",
5218 NO_STR
5219 NEIGHBOR_STR
5220 NEIGHBOR_ADDR_STR2
5221 "BGP per neighbor timers\n"
5222 "Keepalive interval\n"
5223 "Holdtime\n")
5224 {
5225 int idx_peer = 2;
5226 return peer_timers_unset_vty(vty, argv[idx_peer]->arg);
5227 }
5228
5229
5230 static int peer_timers_connect_set_vty(struct vty *vty, const char *ip_str,
5231 const char *time_str)
5232 {
5233 int ret;
5234 struct peer *peer;
5235 uint32_t connect;
5236
5237 peer = peer_and_group_lookup_vty(vty, ip_str);
5238 if (!peer)
5239 return CMD_WARNING_CONFIG_FAILED;
5240
5241 connect = strtoul(time_str, NULL, 10);
5242
5243 ret = peer_timers_connect_set(peer, connect);
5244
5245 return bgp_vty_return(vty, ret);
5246 }
5247
5248 static int peer_timers_connect_unset_vty(struct vty *vty, const char *ip_str)
5249 {
5250 int ret;
5251 struct peer *peer;
5252
5253 peer = peer_and_group_lookup_vty(vty, ip_str);
5254 if (!peer)
5255 return CMD_WARNING_CONFIG_FAILED;
5256
5257 ret = peer_timers_connect_unset(peer);
5258
5259 return bgp_vty_return(vty, ret);
5260 }
5261
5262 DEFUN (neighbor_timers_connect,
5263 neighbor_timers_connect_cmd,
5264 "neighbor <A.B.C.D|X:X::X:X|WORD> timers connect (1-65535)",
5265 NEIGHBOR_STR
5266 NEIGHBOR_ADDR_STR2
5267 "BGP per neighbor timers\n"
5268 "BGP connect timer\n"
5269 "Connect timer\n")
5270 {
5271 int idx_peer = 1;
5272 int idx_number = 4;
5273 return peer_timers_connect_set_vty(vty, argv[idx_peer]->arg,
5274 argv[idx_number]->arg);
5275 }
5276
5277 DEFUN (no_neighbor_timers_connect,
5278 no_neighbor_timers_connect_cmd,
5279 "no neighbor <A.B.C.D|X:X::X:X|WORD> timers connect [(1-65535)]",
5280 NO_STR
5281 NEIGHBOR_STR
5282 NEIGHBOR_ADDR_STR2
5283 "BGP per neighbor timers\n"
5284 "BGP connect timer\n"
5285 "Connect timer\n")
5286 {
5287 int idx_peer = 2;
5288 return peer_timers_connect_unset_vty(vty, argv[idx_peer]->arg);
5289 }
5290
5291
5292 static int peer_advertise_interval_vty(struct vty *vty, const char *ip_str,
5293 const char *time_str, int set)
5294 {
5295 int ret;
5296 struct peer *peer;
5297 uint32_t routeadv = 0;
5298
5299 peer = peer_and_group_lookup_vty(vty, ip_str);
5300 if (!peer)
5301 return CMD_WARNING_CONFIG_FAILED;
5302
5303 if (time_str)
5304 routeadv = strtoul(time_str, NULL, 10);
5305
5306 if (set)
5307 ret = peer_advertise_interval_set(peer, routeadv);
5308 else
5309 ret = peer_advertise_interval_unset(peer);
5310
5311 return bgp_vty_return(vty, ret);
5312 }
5313
5314 DEFUN (neighbor_advertise_interval,
5315 neighbor_advertise_interval_cmd,
5316 "neighbor <A.B.C.D|X:X::X:X|WORD> advertisement-interval (0-600)",
5317 NEIGHBOR_STR
5318 NEIGHBOR_ADDR_STR2
5319 "Minimum interval between sending BGP routing updates\n"
5320 "time in seconds\n")
5321 {
5322 int idx_peer = 1;
5323 int idx_number = 3;
5324 return peer_advertise_interval_vty(vty, argv[idx_peer]->arg,
5325 argv[idx_number]->arg, 1);
5326 }
5327
5328 DEFUN (no_neighbor_advertise_interval,
5329 no_neighbor_advertise_interval_cmd,
5330 "no neighbor <A.B.C.D|X:X::X:X|WORD> advertisement-interval [(0-600)]",
5331 NO_STR
5332 NEIGHBOR_STR
5333 NEIGHBOR_ADDR_STR2
5334 "Minimum interval between sending BGP routing updates\n"
5335 "time in seconds\n")
5336 {
5337 int idx_peer = 2;
5338 return peer_advertise_interval_vty(vty, argv[idx_peer]->arg, NULL, 0);
5339 }
5340
5341
5342 /* Time to wait before processing route-map updates */
5343 DEFUN (bgp_set_route_map_delay_timer,
5344 bgp_set_route_map_delay_timer_cmd,
5345 "bgp route-map delay-timer (0-600)",
5346 SET_STR
5347 "BGP route-map delay timer\n"
5348 "Time in secs to wait before processing route-map changes\n"
5349 "0 disables the timer, no route updates happen when route-maps change\n")
5350 {
5351 int idx_number = 3;
5352 uint32_t rmap_delay_timer;
5353
5354 if (argv[idx_number]->arg) {
5355 rmap_delay_timer = strtoul(argv[idx_number]->arg, NULL, 10);
5356 bm->rmap_update_timer = rmap_delay_timer;
5357
5358 /* if the dynamic update handling is being disabled, and a timer
5359 * is
5360 * running, stop the timer and act as if the timer has already
5361 * fired.
5362 */
5363 if (!rmap_delay_timer && bm->t_rmap_update) {
5364 BGP_TIMER_OFF(bm->t_rmap_update);
5365 thread_execute(bm->master, bgp_route_map_update_timer,
5366 NULL, 0);
5367 }
5368 return CMD_SUCCESS;
5369 } else {
5370 vty_out(vty, "%% BGP invalid route-map delay-timer\n");
5371 return CMD_WARNING_CONFIG_FAILED;
5372 }
5373 }
5374
5375 DEFUN (no_bgp_set_route_map_delay_timer,
5376 no_bgp_set_route_map_delay_timer_cmd,
5377 "no bgp route-map delay-timer [(0-600)]",
5378 NO_STR
5379 BGP_STR
5380 "Default BGP route-map delay timer\n"
5381 "Reset to default time to wait for processing route-map changes\n"
5382 "0 disables the timer, no route updates happen when route-maps change\n")
5383 {
5384
5385 bm->rmap_update_timer = RMAP_DEFAULT_UPDATE_TIMER;
5386
5387 return CMD_SUCCESS;
5388 }
5389
5390
5391 /* neighbor interface */
5392 static int peer_interface_vty(struct vty *vty, const char *ip_str,
5393 const char *str)
5394 {
5395 struct peer *peer;
5396
5397 peer = peer_lookup_vty(vty, ip_str);
5398 if (!peer || peer->conf_if) {
5399 vty_out(vty, "%% BGP invalid peer %s\n", ip_str);
5400 return CMD_WARNING_CONFIG_FAILED;
5401 }
5402
5403 if (str)
5404 peer_interface_set(peer, str);
5405 else
5406 peer_interface_unset(peer);
5407
5408 return CMD_SUCCESS;
5409 }
5410
5411 DEFUN (neighbor_interface,
5412 neighbor_interface_cmd,
5413 "neighbor <A.B.C.D|X:X::X:X> interface WORD",
5414 NEIGHBOR_STR
5415 NEIGHBOR_ADDR_STR
5416 "Interface\n"
5417 "Interface name\n")
5418 {
5419 int idx_ip = 1;
5420 int idx_word = 3;
5421 return peer_interface_vty(vty, argv[idx_ip]->arg, argv[idx_word]->arg);
5422 }
5423
5424 DEFUN (no_neighbor_interface,
5425 no_neighbor_interface_cmd,
5426 "no neighbor <A.B.C.D|X:X::X:X|WORD> interface WORD",
5427 NO_STR
5428 NEIGHBOR_STR
5429 NEIGHBOR_ADDR_STR2
5430 "Interface\n"
5431 "Interface name\n")
5432 {
5433 int idx_peer = 2;
5434 return peer_interface_vty(vty, argv[idx_peer]->arg, NULL);
5435 }
5436
5437 DEFUN (neighbor_distribute_list,
5438 neighbor_distribute_list_cmd,
5439 "neighbor <A.B.C.D|X:X::X:X|WORD> distribute-list <(1-199)|(1300-2699)|WORD> <in|out>",
5440 NEIGHBOR_STR
5441 NEIGHBOR_ADDR_STR2
5442 "Filter updates to/from this neighbor\n"
5443 "IP access-list number\n"
5444 "IP access-list number (expanded range)\n"
5445 "IP Access-list name\n"
5446 "Filter incoming updates\n"
5447 "Filter outgoing updates\n")
5448 {
5449 int idx_peer = 1;
5450 int idx_acl = 3;
5451 int direct, ret;
5452 struct peer *peer;
5453
5454 const char *pstr = argv[idx_peer]->arg;
5455 const char *acl = argv[idx_acl]->arg;
5456 const char *inout = argv[argc - 1]->text;
5457
5458 peer = peer_and_group_lookup_vty(vty, pstr);
5459 if (!peer)
5460 return CMD_WARNING_CONFIG_FAILED;
5461
5462 /* Check filter direction. */
5463 direct = strmatch(inout, "in") ? FILTER_IN : FILTER_OUT;
5464 ret = peer_distribute_set(peer, bgp_node_afi(vty), bgp_node_safi(vty),
5465 direct, acl);
5466
5467 return bgp_vty_return(vty, ret);
5468 }
5469
5470 ALIAS_HIDDEN(
5471 neighbor_distribute_list, neighbor_distribute_list_hidden_cmd,
5472 "neighbor <A.B.C.D|X:X::X:X|WORD> distribute-list <(1-199)|(1300-2699)|WORD> <in|out>",
5473 NEIGHBOR_STR NEIGHBOR_ADDR_STR2
5474 "Filter updates to/from this neighbor\n"
5475 "IP access-list number\n"
5476 "IP access-list number (expanded range)\n"
5477 "IP Access-list name\n"
5478 "Filter incoming updates\n"
5479 "Filter outgoing updates\n")
5480
5481 DEFUN (no_neighbor_distribute_list,
5482 no_neighbor_distribute_list_cmd,
5483 "no neighbor <A.B.C.D|X:X::X:X|WORD> distribute-list <(1-199)|(1300-2699)|WORD> <in|out>",
5484 NO_STR
5485 NEIGHBOR_STR
5486 NEIGHBOR_ADDR_STR2
5487 "Filter updates to/from this neighbor\n"
5488 "IP access-list number\n"
5489 "IP access-list number (expanded range)\n"
5490 "IP Access-list name\n"
5491 "Filter incoming updates\n"
5492 "Filter outgoing updates\n")
5493 {
5494 int idx_peer = 2;
5495 int direct, ret;
5496 struct peer *peer;
5497
5498 const char *pstr = argv[idx_peer]->arg;
5499 const char *inout = argv[argc - 1]->text;
5500
5501 peer = peer_and_group_lookup_vty(vty, pstr);
5502 if (!peer)
5503 return CMD_WARNING_CONFIG_FAILED;
5504
5505 /* Check filter direction. */
5506 direct = strmatch(inout, "in") ? FILTER_IN : FILTER_OUT;
5507 ret = peer_distribute_unset(peer, bgp_node_afi(vty), bgp_node_safi(vty),
5508 direct);
5509
5510 return bgp_vty_return(vty, ret);
5511 }
5512
5513 ALIAS_HIDDEN(
5514 no_neighbor_distribute_list, no_neighbor_distribute_list_hidden_cmd,
5515 "no neighbor <A.B.C.D|X:X::X:X|WORD> distribute-list <(1-199)|(1300-2699)|WORD> <in|out>",
5516 NO_STR NEIGHBOR_STR NEIGHBOR_ADDR_STR2
5517 "Filter updates to/from this neighbor\n"
5518 "IP access-list number\n"
5519 "IP access-list number (expanded range)\n"
5520 "IP Access-list name\n"
5521 "Filter incoming updates\n"
5522 "Filter outgoing updates\n")
5523
5524 /* Set prefix list to the peer. */
5525 static int peer_prefix_list_set_vty(struct vty *vty, const char *ip_str,
5526 afi_t afi, safi_t safi,
5527 const char *name_str,
5528 const char *direct_str)
5529 {
5530 int ret;
5531 int direct = FILTER_IN;
5532 struct peer *peer;
5533
5534 peer = peer_and_group_lookup_vty(vty, ip_str);
5535 if (!peer)
5536 return CMD_WARNING_CONFIG_FAILED;
5537
5538 /* Check filter direction. */
5539 if (strncmp(direct_str, "i", 1) == 0)
5540 direct = FILTER_IN;
5541 else if (strncmp(direct_str, "o", 1) == 0)
5542 direct = FILTER_OUT;
5543
5544 ret = peer_prefix_list_set(peer, afi, safi, direct, name_str);
5545
5546 return bgp_vty_return(vty, ret);
5547 }
5548
5549 static int peer_prefix_list_unset_vty(struct vty *vty, const char *ip_str,
5550 afi_t afi, safi_t safi,
5551 const char *direct_str)
5552 {
5553 int ret;
5554 struct peer *peer;
5555 int direct = FILTER_IN;
5556
5557 peer = peer_and_group_lookup_vty(vty, ip_str);
5558 if (!peer)
5559 return CMD_WARNING_CONFIG_FAILED;
5560
5561 /* Check filter direction. */
5562 if (strncmp(direct_str, "i", 1) == 0)
5563 direct = FILTER_IN;
5564 else if (strncmp(direct_str, "o", 1) == 0)
5565 direct = FILTER_OUT;
5566
5567 ret = peer_prefix_list_unset(peer, afi, safi, direct);
5568
5569 return bgp_vty_return(vty, ret);
5570 }
5571
5572 DEFUN (neighbor_prefix_list,
5573 neighbor_prefix_list_cmd,
5574 "neighbor <A.B.C.D|X:X::X:X|WORD> prefix-list WORD <in|out>",
5575 NEIGHBOR_STR
5576 NEIGHBOR_ADDR_STR2
5577 "Filter updates to/from this neighbor\n"
5578 "Name of a prefix list\n"
5579 "Filter incoming updates\n"
5580 "Filter outgoing updates\n")
5581 {
5582 int idx_peer = 1;
5583 int idx_word = 3;
5584 int idx_in_out = 4;
5585 return peer_prefix_list_set_vty(
5586 vty, argv[idx_peer]->arg, bgp_node_afi(vty), bgp_node_safi(vty),
5587 argv[idx_word]->arg, argv[idx_in_out]->arg);
5588 }
5589
5590 ALIAS_HIDDEN(neighbor_prefix_list, neighbor_prefix_list_hidden_cmd,
5591 "neighbor <A.B.C.D|X:X::X:X|WORD> prefix-list WORD <in|out>",
5592 NEIGHBOR_STR NEIGHBOR_ADDR_STR2
5593 "Filter updates to/from this neighbor\n"
5594 "Name of a prefix list\n"
5595 "Filter incoming updates\n"
5596 "Filter outgoing updates\n")
5597
5598 DEFUN (no_neighbor_prefix_list,
5599 no_neighbor_prefix_list_cmd,
5600 "no neighbor <A.B.C.D|X:X::X:X|WORD> prefix-list WORD <in|out>",
5601 NO_STR
5602 NEIGHBOR_STR
5603 NEIGHBOR_ADDR_STR2
5604 "Filter updates to/from this neighbor\n"
5605 "Name of a prefix list\n"
5606 "Filter incoming updates\n"
5607 "Filter outgoing updates\n")
5608 {
5609 int idx_peer = 2;
5610 int idx_in_out = 5;
5611 return peer_prefix_list_unset_vty(vty, argv[idx_peer]->arg,
5612 bgp_node_afi(vty), bgp_node_safi(vty),
5613 argv[idx_in_out]->arg);
5614 }
5615
5616 ALIAS_HIDDEN(no_neighbor_prefix_list, no_neighbor_prefix_list_hidden_cmd,
5617 "no neighbor <A.B.C.D|X:X::X:X|WORD> prefix-list WORD <in|out>",
5618 NO_STR NEIGHBOR_STR NEIGHBOR_ADDR_STR2
5619 "Filter updates to/from this neighbor\n"
5620 "Name of a prefix list\n"
5621 "Filter incoming updates\n"
5622 "Filter outgoing updates\n")
5623
5624 static int peer_aslist_set_vty(struct vty *vty, const char *ip_str, afi_t afi,
5625 safi_t safi, const char *name_str,
5626 const char *direct_str)
5627 {
5628 int ret;
5629 struct peer *peer;
5630 int direct = FILTER_IN;
5631
5632 peer = peer_and_group_lookup_vty(vty, ip_str);
5633 if (!peer)
5634 return CMD_WARNING_CONFIG_FAILED;
5635
5636 /* Check filter direction. */
5637 if (strncmp(direct_str, "i", 1) == 0)
5638 direct = FILTER_IN;
5639 else if (strncmp(direct_str, "o", 1) == 0)
5640 direct = FILTER_OUT;
5641
5642 ret = peer_aslist_set(peer, afi, safi, direct, name_str);
5643
5644 return bgp_vty_return(vty, ret);
5645 }
5646
5647 static int peer_aslist_unset_vty(struct vty *vty, const char *ip_str, afi_t afi,
5648 safi_t safi, const char *direct_str)
5649 {
5650 int ret;
5651 struct peer *peer;
5652 int direct = FILTER_IN;
5653
5654 peer = peer_and_group_lookup_vty(vty, ip_str);
5655 if (!peer)
5656 return CMD_WARNING_CONFIG_FAILED;
5657
5658 /* Check filter direction. */
5659 if (strncmp(direct_str, "i", 1) == 0)
5660 direct = FILTER_IN;
5661 else if (strncmp(direct_str, "o", 1) == 0)
5662 direct = FILTER_OUT;
5663
5664 ret = peer_aslist_unset(peer, afi, safi, direct);
5665
5666 return bgp_vty_return(vty, ret);
5667 }
5668
5669 DEFUN (neighbor_filter_list,
5670 neighbor_filter_list_cmd,
5671 "neighbor <A.B.C.D|X:X::X:X|WORD> filter-list WORD <in|out>",
5672 NEIGHBOR_STR
5673 NEIGHBOR_ADDR_STR2
5674 "Establish BGP filters\n"
5675 "AS path access-list name\n"
5676 "Filter incoming routes\n"
5677 "Filter outgoing routes\n")
5678 {
5679 int idx_peer = 1;
5680 int idx_word = 3;
5681 int idx_in_out = 4;
5682 return peer_aslist_set_vty(vty, argv[idx_peer]->arg, bgp_node_afi(vty),
5683 bgp_node_safi(vty), argv[idx_word]->arg,
5684 argv[idx_in_out]->arg);
5685 }
5686
5687 ALIAS_HIDDEN(neighbor_filter_list, neighbor_filter_list_hidden_cmd,
5688 "neighbor <A.B.C.D|X:X::X:X|WORD> filter-list WORD <in|out>",
5689 NEIGHBOR_STR NEIGHBOR_ADDR_STR2
5690 "Establish BGP filters\n"
5691 "AS path access-list name\n"
5692 "Filter incoming routes\n"
5693 "Filter outgoing routes\n")
5694
5695 DEFUN (no_neighbor_filter_list,
5696 no_neighbor_filter_list_cmd,
5697 "no neighbor <A.B.C.D|X:X::X:X|WORD> filter-list WORD <in|out>",
5698 NO_STR
5699 NEIGHBOR_STR
5700 NEIGHBOR_ADDR_STR2
5701 "Establish BGP filters\n"
5702 "AS path access-list name\n"
5703 "Filter incoming routes\n"
5704 "Filter outgoing routes\n")
5705 {
5706 int idx_peer = 2;
5707 int idx_in_out = 5;
5708 return peer_aslist_unset_vty(vty, argv[idx_peer]->arg,
5709 bgp_node_afi(vty), bgp_node_safi(vty),
5710 argv[idx_in_out]->arg);
5711 }
5712
5713 ALIAS_HIDDEN(no_neighbor_filter_list, no_neighbor_filter_list_hidden_cmd,
5714 "no neighbor <A.B.C.D|X:X::X:X|WORD> filter-list WORD <in|out>",
5715 NO_STR NEIGHBOR_STR NEIGHBOR_ADDR_STR2
5716 "Establish BGP filters\n"
5717 "AS path access-list name\n"
5718 "Filter incoming routes\n"
5719 "Filter outgoing routes\n")
5720
5721 /* Set route-map to the peer. */
5722 static int peer_route_map_set_vty(struct vty *vty, const char *ip_str,
5723 afi_t afi, safi_t safi, const char *name_str,
5724 const char *direct_str)
5725 {
5726 int ret;
5727 struct peer *peer;
5728 int direct = RMAP_IN;
5729 struct route_map *route_map;
5730
5731 peer = peer_and_group_lookup_vty(vty, ip_str);
5732 if (!peer)
5733 return CMD_WARNING_CONFIG_FAILED;
5734
5735 /* Check filter direction. */
5736 if (strncmp(direct_str, "in", 2) == 0)
5737 direct = RMAP_IN;
5738 else if (strncmp(direct_str, "o", 1) == 0)
5739 direct = RMAP_OUT;
5740
5741 route_map = route_map_lookup_warn_noexist(vty, name_str);
5742 ret = peer_route_map_set(peer, afi, safi, direct, name_str, route_map);
5743
5744 return bgp_vty_return(vty, ret);
5745 }
5746
5747 static int peer_route_map_unset_vty(struct vty *vty, const char *ip_str,
5748 afi_t afi, safi_t safi,
5749 const char *direct_str)
5750 {
5751 int ret;
5752 struct peer *peer;
5753 int direct = RMAP_IN;
5754
5755 peer = peer_and_group_lookup_vty(vty, ip_str);
5756 if (!peer)
5757 return CMD_WARNING_CONFIG_FAILED;
5758
5759 /* Check filter direction. */
5760 if (strncmp(direct_str, "in", 2) == 0)
5761 direct = RMAP_IN;
5762 else if (strncmp(direct_str, "o", 1) == 0)
5763 direct = RMAP_OUT;
5764
5765 ret = peer_route_map_unset(peer, afi, safi, direct);
5766
5767 return bgp_vty_return(vty, ret);
5768 }
5769
5770 DEFUN (neighbor_route_map,
5771 neighbor_route_map_cmd,
5772 "neighbor <A.B.C.D|X:X::X:X|WORD> route-map WORD <in|out>",
5773 NEIGHBOR_STR
5774 NEIGHBOR_ADDR_STR2
5775 "Apply route map to neighbor\n"
5776 "Name of route map\n"
5777 "Apply map to incoming routes\n"
5778 "Apply map to outbound routes\n")
5779 {
5780 int idx_peer = 1;
5781 int idx_word = 3;
5782 int idx_in_out = 4;
5783 return peer_route_map_set_vty(
5784 vty, argv[idx_peer]->arg, bgp_node_afi(vty), bgp_node_safi(vty),
5785 argv[idx_word]->arg, argv[idx_in_out]->arg);
5786 }
5787
5788 ALIAS_HIDDEN(neighbor_route_map, neighbor_route_map_hidden_cmd,
5789 "neighbor <A.B.C.D|X:X::X:X|WORD> route-map WORD <in|out>",
5790 NEIGHBOR_STR NEIGHBOR_ADDR_STR2
5791 "Apply route map to neighbor\n"
5792 "Name of route map\n"
5793 "Apply map to incoming routes\n"
5794 "Apply map to outbound routes\n")
5795
5796 DEFUN (no_neighbor_route_map,
5797 no_neighbor_route_map_cmd,
5798 "no neighbor <A.B.C.D|X:X::X:X|WORD> route-map WORD <in|out>",
5799 NO_STR
5800 NEIGHBOR_STR
5801 NEIGHBOR_ADDR_STR2
5802 "Apply route map to neighbor\n"
5803 "Name of route map\n"
5804 "Apply map to incoming routes\n"
5805 "Apply map to outbound routes\n")
5806 {
5807 int idx_peer = 2;
5808 int idx_in_out = 5;
5809 return peer_route_map_unset_vty(vty, argv[idx_peer]->arg,
5810 bgp_node_afi(vty), bgp_node_safi(vty),
5811 argv[idx_in_out]->arg);
5812 }
5813
5814 ALIAS_HIDDEN(no_neighbor_route_map, no_neighbor_route_map_hidden_cmd,
5815 "no neighbor <A.B.C.D|X:X::X:X|WORD> route-map WORD <in|out>",
5816 NO_STR NEIGHBOR_STR NEIGHBOR_ADDR_STR2
5817 "Apply route map to neighbor\n"
5818 "Name of route map\n"
5819 "Apply map to incoming routes\n"
5820 "Apply map to outbound routes\n")
5821
5822 /* Set unsuppress-map to the peer. */
5823 static int peer_unsuppress_map_set_vty(struct vty *vty, const char *ip_str,
5824 afi_t afi, safi_t safi,
5825 const char *name_str)
5826 {
5827 int ret;
5828 struct peer *peer;
5829 struct route_map *route_map;
5830
5831 peer = peer_and_group_lookup_vty(vty, ip_str);
5832 if (!peer)
5833 return CMD_WARNING_CONFIG_FAILED;
5834
5835 route_map = route_map_lookup_warn_noexist(vty, name_str);
5836 ret = peer_unsuppress_map_set(peer, afi, safi, name_str, route_map);
5837
5838 return bgp_vty_return(vty, ret);
5839 }
5840
5841 /* Unset route-map from the peer. */
5842 static int peer_unsuppress_map_unset_vty(struct vty *vty, const char *ip_str,
5843 afi_t afi, safi_t safi)
5844 {
5845 int ret;
5846 struct peer *peer;
5847
5848 peer = peer_and_group_lookup_vty(vty, ip_str);
5849 if (!peer)
5850 return CMD_WARNING_CONFIG_FAILED;
5851
5852 ret = peer_unsuppress_map_unset(peer, afi, safi);
5853
5854 return bgp_vty_return(vty, ret);
5855 }
5856
5857 DEFUN (neighbor_unsuppress_map,
5858 neighbor_unsuppress_map_cmd,
5859 "neighbor <A.B.C.D|X:X::X:X|WORD> unsuppress-map WORD",
5860 NEIGHBOR_STR
5861 NEIGHBOR_ADDR_STR2
5862 "Route-map to selectively unsuppress suppressed routes\n"
5863 "Name of route map\n")
5864 {
5865 int idx_peer = 1;
5866 int idx_word = 3;
5867 return peer_unsuppress_map_set_vty(
5868 vty, argv[idx_peer]->arg, bgp_node_afi(vty), bgp_node_safi(vty),
5869 argv[idx_word]->arg);
5870 }
5871
5872 ALIAS_HIDDEN(neighbor_unsuppress_map, neighbor_unsuppress_map_hidden_cmd,
5873 "neighbor <A.B.C.D|X:X::X:X|WORD> unsuppress-map WORD",
5874 NEIGHBOR_STR NEIGHBOR_ADDR_STR2
5875 "Route-map to selectively unsuppress suppressed routes\n"
5876 "Name of route map\n")
5877
5878 DEFUN (no_neighbor_unsuppress_map,
5879 no_neighbor_unsuppress_map_cmd,
5880 "no neighbor <A.B.C.D|X:X::X:X|WORD> unsuppress-map WORD",
5881 NO_STR
5882 NEIGHBOR_STR
5883 NEIGHBOR_ADDR_STR2
5884 "Route-map to selectively unsuppress suppressed routes\n"
5885 "Name of route map\n")
5886 {
5887 int idx_peer = 2;
5888 return peer_unsuppress_map_unset_vty(vty, argv[idx_peer]->arg,
5889 bgp_node_afi(vty),
5890 bgp_node_safi(vty));
5891 }
5892
5893 ALIAS_HIDDEN(no_neighbor_unsuppress_map, no_neighbor_unsuppress_map_hidden_cmd,
5894 "no neighbor <A.B.C.D|X:X::X:X|WORD> unsuppress-map WORD",
5895 NO_STR NEIGHBOR_STR NEIGHBOR_ADDR_STR2
5896 "Route-map to selectively unsuppress suppressed routes\n"
5897 "Name of route map\n")
5898
5899 static int peer_maximum_prefix_set_vty(struct vty *vty, const char *ip_str,
5900 afi_t afi, safi_t safi,
5901 const char *num_str,
5902 const char *threshold_str, int warning,
5903 const char *restart_str)
5904 {
5905 int ret;
5906 struct peer *peer;
5907 uint32_t max;
5908 uint8_t threshold;
5909 uint16_t restart;
5910
5911 peer = peer_and_group_lookup_vty(vty, ip_str);
5912 if (!peer)
5913 return CMD_WARNING_CONFIG_FAILED;
5914
5915 max = strtoul(num_str, NULL, 10);
5916 if (threshold_str)
5917 threshold = atoi(threshold_str);
5918 else
5919 threshold = MAXIMUM_PREFIX_THRESHOLD_DEFAULT;
5920
5921 if (restart_str)
5922 restart = atoi(restart_str);
5923 else
5924 restart = 0;
5925
5926 ret = peer_maximum_prefix_set(peer, afi, safi, max, threshold, warning,
5927 restart);
5928
5929 return bgp_vty_return(vty, ret);
5930 }
5931
5932 static int peer_maximum_prefix_unset_vty(struct vty *vty, const char *ip_str,
5933 afi_t afi, safi_t safi)
5934 {
5935 int ret;
5936 struct peer *peer;
5937
5938 peer = peer_and_group_lookup_vty(vty, ip_str);
5939 if (!peer)
5940 return CMD_WARNING_CONFIG_FAILED;
5941
5942 ret = peer_maximum_prefix_unset(peer, afi, safi);
5943
5944 return bgp_vty_return(vty, ret);
5945 }
5946
5947 /* Maximum number of prefix configuration. prefix count is different
5948 for each peer configuration. So this configuration can be set for
5949 each peer configuration. */
5950 DEFUN (neighbor_maximum_prefix,
5951 neighbor_maximum_prefix_cmd,
5952 "neighbor <A.B.C.D|X:X::X:X|WORD> maximum-prefix (1-4294967295)",
5953 NEIGHBOR_STR
5954 NEIGHBOR_ADDR_STR2
5955 "Maximum number of prefix accept from this peer\n"
5956 "maximum no. of prefix limit\n")
5957 {
5958 int idx_peer = 1;
5959 int idx_number = 3;
5960 return peer_maximum_prefix_set_vty(
5961 vty, argv[idx_peer]->arg, bgp_node_afi(vty), bgp_node_safi(vty),
5962 argv[idx_number]->arg, NULL, 0, NULL);
5963 }
5964
5965 ALIAS_HIDDEN(neighbor_maximum_prefix, neighbor_maximum_prefix_hidden_cmd,
5966 "neighbor <A.B.C.D|X:X::X:X|WORD> maximum-prefix (1-4294967295)",
5967 NEIGHBOR_STR NEIGHBOR_ADDR_STR2
5968 "Maximum number of prefix accept from this peer\n"
5969 "maximum no. of prefix limit\n")
5970
5971 DEFUN (neighbor_maximum_prefix_threshold,
5972 neighbor_maximum_prefix_threshold_cmd,
5973 "neighbor <A.B.C.D|X:X::X:X|WORD> maximum-prefix (1-4294967295) (1-100)",
5974 NEIGHBOR_STR
5975 NEIGHBOR_ADDR_STR2
5976 "Maximum number of prefix accept from this peer\n"
5977 "maximum no. of prefix limit\n"
5978 "Threshold value (%) at which to generate a warning msg\n")
5979 {
5980 int idx_peer = 1;
5981 int idx_number = 3;
5982 int idx_number_2 = 4;
5983 return peer_maximum_prefix_set_vty(
5984 vty, argv[idx_peer]->arg, bgp_node_afi(vty), bgp_node_safi(vty),
5985 argv[idx_number]->arg, argv[idx_number_2]->arg, 0, NULL);
5986 }
5987
5988 ALIAS_HIDDEN(
5989 neighbor_maximum_prefix_threshold,
5990 neighbor_maximum_prefix_threshold_hidden_cmd,
5991 "neighbor <A.B.C.D|X:X::X:X|WORD> maximum-prefix (1-4294967295) (1-100)",
5992 NEIGHBOR_STR NEIGHBOR_ADDR_STR2
5993 "Maximum number of prefix accept from this peer\n"
5994 "maximum no. of prefix limit\n"
5995 "Threshold value (%) at which to generate a warning msg\n")
5996
5997 DEFUN (neighbor_maximum_prefix_warning,
5998 neighbor_maximum_prefix_warning_cmd,
5999 "neighbor <A.B.C.D|X:X::X:X|WORD> maximum-prefix (1-4294967295) warning-only",
6000 NEIGHBOR_STR
6001 NEIGHBOR_ADDR_STR2
6002 "Maximum number of prefix accept from this peer\n"
6003 "maximum no. of prefix limit\n"
6004 "Only give warning message when limit is exceeded\n")
6005 {
6006 int idx_peer = 1;
6007 int idx_number = 3;
6008 return peer_maximum_prefix_set_vty(
6009 vty, argv[idx_peer]->arg, bgp_node_afi(vty), bgp_node_safi(vty),
6010 argv[idx_number]->arg, NULL, 1, NULL);
6011 }
6012
6013 ALIAS_HIDDEN(
6014 neighbor_maximum_prefix_warning,
6015 neighbor_maximum_prefix_warning_hidden_cmd,
6016 "neighbor <A.B.C.D|X:X::X:X|WORD> maximum-prefix (1-4294967295) warning-only",
6017 NEIGHBOR_STR NEIGHBOR_ADDR_STR2
6018 "Maximum number of prefix accept from this peer\n"
6019 "maximum no. of prefix limit\n"
6020 "Only give warning message when limit is exceeded\n")
6021
6022 DEFUN (neighbor_maximum_prefix_threshold_warning,
6023 neighbor_maximum_prefix_threshold_warning_cmd,
6024 "neighbor <A.B.C.D|X:X::X:X|WORD> maximum-prefix (1-4294967295) (1-100) warning-only",
6025 NEIGHBOR_STR
6026 NEIGHBOR_ADDR_STR2
6027 "Maximum number of prefix accept from this peer\n"
6028 "maximum no. of prefix limit\n"
6029 "Threshold value (%) at which to generate a warning msg\n"
6030 "Only give warning message when limit is exceeded\n")
6031 {
6032 int idx_peer = 1;
6033 int idx_number = 3;
6034 int idx_number_2 = 4;
6035 return peer_maximum_prefix_set_vty(
6036 vty, argv[idx_peer]->arg, bgp_node_afi(vty), bgp_node_safi(vty),
6037 argv[idx_number]->arg, argv[idx_number_2]->arg, 1, NULL);
6038 }
6039
6040 ALIAS_HIDDEN(
6041 neighbor_maximum_prefix_threshold_warning,
6042 neighbor_maximum_prefix_threshold_warning_hidden_cmd,
6043 "neighbor <A.B.C.D|X:X::X:X|WORD> maximum-prefix (1-4294967295) (1-100) warning-only",
6044 NEIGHBOR_STR NEIGHBOR_ADDR_STR2
6045 "Maximum number of prefix accept from this peer\n"
6046 "maximum no. of prefix limit\n"
6047 "Threshold value (%) at which to generate a warning msg\n"
6048 "Only give warning message when limit is exceeded\n")
6049
6050 DEFUN (neighbor_maximum_prefix_restart,
6051 neighbor_maximum_prefix_restart_cmd,
6052 "neighbor <A.B.C.D|X:X::X:X|WORD> maximum-prefix (1-4294967295) restart (1-65535)",
6053 NEIGHBOR_STR
6054 NEIGHBOR_ADDR_STR2
6055 "Maximum number of prefix accept from this peer\n"
6056 "maximum no. of prefix limit\n"
6057 "Restart bgp connection after limit is exceeded\n"
6058 "Restart interval in minutes\n")
6059 {
6060 int idx_peer = 1;
6061 int idx_number = 3;
6062 int idx_number_2 = 5;
6063 return peer_maximum_prefix_set_vty(
6064 vty, argv[idx_peer]->arg, bgp_node_afi(vty), bgp_node_safi(vty),
6065 argv[idx_number]->arg, NULL, 0, argv[idx_number_2]->arg);
6066 }
6067
6068 ALIAS_HIDDEN(
6069 neighbor_maximum_prefix_restart,
6070 neighbor_maximum_prefix_restart_hidden_cmd,
6071 "neighbor <A.B.C.D|X:X::X:X|WORD> maximum-prefix (1-4294967295) restart (1-65535)",
6072 NEIGHBOR_STR NEIGHBOR_ADDR_STR2
6073 "Maximum number of prefix accept from this peer\n"
6074 "maximum no. of prefix limit\n"
6075 "Restart bgp connection after limit is exceeded\n"
6076 "Restart interval in minutes\n")
6077
6078 DEFUN (neighbor_maximum_prefix_threshold_restart,
6079 neighbor_maximum_prefix_threshold_restart_cmd,
6080 "neighbor <A.B.C.D|X:X::X:X|WORD> maximum-prefix (1-4294967295) (1-100) restart (1-65535)",
6081 NEIGHBOR_STR
6082 NEIGHBOR_ADDR_STR2
6083 "Maximum number of prefixes to accept from this peer\n"
6084 "maximum no. of prefix limit\n"
6085 "Threshold value (%) at which to generate a warning msg\n"
6086 "Restart bgp connection after limit is exceeded\n"
6087 "Restart interval in minutes\n")
6088 {
6089 int idx_peer = 1;
6090 int idx_number = 3;
6091 int idx_number_2 = 4;
6092 int idx_number_3 = 6;
6093 return peer_maximum_prefix_set_vty(
6094 vty, argv[idx_peer]->arg, bgp_node_afi(vty), bgp_node_safi(vty),
6095 argv[idx_number]->arg, argv[idx_number_2]->arg, 0,
6096 argv[idx_number_3]->arg);
6097 }
6098
6099 ALIAS_HIDDEN(
6100 neighbor_maximum_prefix_threshold_restart,
6101 neighbor_maximum_prefix_threshold_restart_hidden_cmd,
6102 "neighbor <A.B.C.D|X:X::X:X|WORD> maximum-prefix (1-4294967295) (1-100) restart (1-65535)",
6103 NEIGHBOR_STR NEIGHBOR_ADDR_STR2
6104 "Maximum number of prefixes to accept from this peer\n"
6105 "maximum no. of prefix limit\n"
6106 "Threshold value (%) at which to generate a warning msg\n"
6107 "Restart bgp connection after limit is exceeded\n"
6108 "Restart interval in minutes\n")
6109
6110 DEFUN (no_neighbor_maximum_prefix,
6111 no_neighbor_maximum_prefix_cmd,
6112 "no neighbor <A.B.C.D|X:X::X:X|WORD> maximum-prefix [(1-4294967295) [(1-100)] [restart (1-65535)] [warning-only]]",
6113 NO_STR
6114 NEIGHBOR_STR
6115 NEIGHBOR_ADDR_STR2
6116 "Maximum number of prefixes to accept from this peer\n"
6117 "maximum no. of prefix limit\n"
6118 "Threshold value (%) at which to generate a warning msg\n"
6119 "Restart bgp connection after limit is exceeded\n"
6120 "Restart interval in minutes\n"
6121 "Only give warning message when limit is exceeded\n")
6122 {
6123 int idx_peer = 2;
6124 return peer_maximum_prefix_unset_vty(vty, argv[idx_peer]->arg,
6125 bgp_node_afi(vty),
6126 bgp_node_safi(vty));
6127 }
6128
6129 ALIAS_HIDDEN(
6130 no_neighbor_maximum_prefix, no_neighbor_maximum_prefix_hidden_cmd,
6131 "no neighbor <A.B.C.D|X:X::X:X|WORD> maximum-prefix [(1-4294967295) [(1-100)] [restart (1-65535)] [warning-only]]",
6132 NO_STR NEIGHBOR_STR NEIGHBOR_ADDR_STR2
6133 "Maximum number of prefixes to accept from this peer\n"
6134 "maximum no. of prefix limit\n"
6135 "Threshold value (%) at which to generate a warning msg\n"
6136 "Restart bgp connection after limit is exceeded\n"
6137 "Restart interval in minutes\n"
6138 "Only give warning message when limit is exceeded\n")
6139
6140
6141 /* "neighbor allowas-in" */
6142 DEFUN (neighbor_allowas_in,
6143 neighbor_allowas_in_cmd,
6144 "neighbor <A.B.C.D|X:X::X:X|WORD> allowas-in [<(1-10)|origin>]",
6145 NEIGHBOR_STR
6146 NEIGHBOR_ADDR_STR2
6147 "Accept as-path with my AS present in it\n"
6148 "Number of occurences of AS number\n"
6149 "Only accept my AS in the as-path if the route was originated in my AS\n")
6150 {
6151 int idx_peer = 1;
6152 int idx_number_origin = 3;
6153 int ret;
6154 int origin = 0;
6155 struct peer *peer;
6156 int allow_num = 0;
6157
6158 peer = peer_and_group_lookup_vty(vty, argv[idx_peer]->arg);
6159 if (!peer)
6160 return CMD_WARNING_CONFIG_FAILED;
6161
6162 if (argc <= idx_number_origin)
6163 allow_num = 3;
6164 else {
6165 if (argv[idx_number_origin]->type == WORD_TKN)
6166 origin = 1;
6167 else
6168 allow_num = atoi(argv[idx_number_origin]->arg);
6169 }
6170
6171 ret = peer_allowas_in_set(peer, bgp_node_afi(vty), bgp_node_safi(vty),
6172 allow_num, origin);
6173
6174 return bgp_vty_return(vty, ret);
6175 }
6176
6177 ALIAS_HIDDEN(
6178 neighbor_allowas_in, neighbor_allowas_in_hidden_cmd,
6179 "neighbor <A.B.C.D|X:X::X:X|WORD> allowas-in [<(1-10)|origin>]",
6180 NEIGHBOR_STR NEIGHBOR_ADDR_STR2
6181 "Accept as-path with my AS present in it\n"
6182 "Number of occurences of AS number\n"
6183 "Only accept my AS in the as-path if the route was originated in my AS\n")
6184
6185 DEFUN (no_neighbor_allowas_in,
6186 no_neighbor_allowas_in_cmd,
6187 "no neighbor <A.B.C.D|X:X::X:X|WORD> allowas-in [<(1-10)|origin>]",
6188 NO_STR
6189 NEIGHBOR_STR
6190 NEIGHBOR_ADDR_STR2
6191 "allow local ASN appears in aspath attribute\n"
6192 "Number of occurences of AS number\n"
6193 "Only accept my AS in the as-path if the route was originated in my AS\n")
6194 {
6195 int idx_peer = 2;
6196 int ret;
6197 struct peer *peer;
6198
6199 peer = peer_and_group_lookup_vty(vty, argv[idx_peer]->arg);
6200 if (!peer)
6201 return CMD_WARNING_CONFIG_FAILED;
6202
6203 ret = peer_allowas_in_unset(peer, bgp_node_afi(vty),
6204 bgp_node_safi(vty));
6205
6206 return bgp_vty_return(vty, ret);
6207 }
6208
6209 ALIAS_HIDDEN(
6210 no_neighbor_allowas_in, no_neighbor_allowas_in_hidden_cmd,
6211 "no neighbor <A.B.C.D|X:X::X:X|WORD> allowas-in [<(1-10)|origin>]",
6212 NO_STR NEIGHBOR_STR NEIGHBOR_ADDR_STR2
6213 "allow local ASN appears in aspath attribute\n"
6214 "Number of occurences of AS number\n"
6215 "Only accept my AS in the as-path if the route was originated in my AS\n")
6216
6217 DEFUN (neighbor_ttl_security,
6218 neighbor_ttl_security_cmd,
6219 "neighbor <A.B.C.D|X:X::X:X|WORD> ttl-security hops (1-254)",
6220 NEIGHBOR_STR
6221 NEIGHBOR_ADDR_STR2
6222 "BGP ttl-security parameters\n"
6223 "Specify the maximum number of hops to the BGP peer\n"
6224 "Number of hops to BGP peer\n")
6225 {
6226 int idx_peer = 1;
6227 int idx_number = 4;
6228 struct peer *peer;
6229 int gtsm_hops;
6230
6231 peer = peer_and_group_lookup_vty(vty, argv[idx_peer]->arg);
6232 if (!peer)
6233 return CMD_WARNING_CONFIG_FAILED;
6234
6235 gtsm_hops = strtoul(argv[idx_number]->arg, NULL, 10);
6236
6237 /*
6238 * If 'neighbor swpX', then this is for directly connected peers,
6239 * we should not accept a ttl-security hops value greater than 1.
6240 */
6241 if (peer->conf_if && (gtsm_hops > 1)) {
6242 vty_out(vty,
6243 "%s is directly connected peer, hops cannot exceed 1\n",
6244 argv[idx_peer]->arg);
6245 return CMD_WARNING_CONFIG_FAILED;
6246 }
6247
6248 return bgp_vty_return(vty, peer_ttl_security_hops_set(peer, gtsm_hops));
6249 }
6250
6251 DEFUN (no_neighbor_ttl_security,
6252 no_neighbor_ttl_security_cmd,
6253 "no neighbor <A.B.C.D|X:X::X:X|WORD> ttl-security hops (1-254)",
6254 NO_STR
6255 NEIGHBOR_STR
6256 NEIGHBOR_ADDR_STR2
6257 "BGP ttl-security parameters\n"
6258 "Specify the maximum number of hops to the BGP peer\n"
6259 "Number of hops to BGP peer\n")
6260 {
6261 int idx_peer = 2;
6262 struct peer *peer;
6263
6264 peer = peer_and_group_lookup_vty(vty, argv[idx_peer]->arg);
6265 if (!peer)
6266 return CMD_WARNING_CONFIG_FAILED;
6267
6268 return bgp_vty_return(vty, peer_ttl_security_hops_unset(peer));
6269 }
6270
6271 DEFUN (neighbor_addpath_tx_all_paths,
6272 neighbor_addpath_tx_all_paths_cmd,
6273 "neighbor <A.B.C.D|X:X::X:X|WORD> addpath-tx-all-paths",
6274 NEIGHBOR_STR
6275 NEIGHBOR_ADDR_STR2
6276 "Use addpath to advertise all paths to a neighbor\n")
6277 {
6278 int idx_peer = 1;
6279 struct peer *peer;
6280
6281 peer = peer_and_group_lookup_vty(vty, argv[idx_peer]->arg);
6282 if (!peer)
6283 return CMD_WARNING_CONFIG_FAILED;
6284
6285 bgp_addpath_set_peer_type(peer, bgp_node_afi(vty), bgp_node_safi(vty),
6286 BGP_ADDPATH_ALL);
6287 return CMD_SUCCESS;
6288 }
6289
6290 ALIAS_HIDDEN(neighbor_addpath_tx_all_paths,
6291 neighbor_addpath_tx_all_paths_hidden_cmd,
6292 "neighbor <A.B.C.D|X:X::X:X|WORD> addpath-tx-all-paths",
6293 NEIGHBOR_STR NEIGHBOR_ADDR_STR2
6294 "Use addpath to advertise all paths to a neighbor\n")
6295
6296 DEFUN (no_neighbor_addpath_tx_all_paths,
6297 no_neighbor_addpath_tx_all_paths_cmd,
6298 "no neighbor <A.B.C.D|X:X::X:X|WORD> addpath-tx-all-paths",
6299 NO_STR
6300 NEIGHBOR_STR
6301 NEIGHBOR_ADDR_STR2
6302 "Use addpath to advertise all paths to a neighbor\n")
6303 {
6304 int idx_peer = 2;
6305 struct peer *peer;
6306
6307 peer = peer_and_group_lookup_vty(vty, argv[idx_peer]->arg);
6308 if (!peer)
6309 return CMD_WARNING_CONFIG_FAILED;
6310
6311 if (peer->addpath_type[bgp_node_afi(vty)][bgp_node_safi(vty)]
6312 != BGP_ADDPATH_ALL) {
6313 vty_out(vty,
6314 "%% Peer not currently configured to transmit all paths.");
6315 return CMD_WARNING_CONFIG_FAILED;
6316 }
6317
6318 bgp_addpath_set_peer_type(peer, bgp_node_afi(vty), bgp_node_safi(vty),
6319 BGP_ADDPATH_NONE);
6320
6321 return CMD_SUCCESS;
6322 }
6323
6324 ALIAS_HIDDEN(no_neighbor_addpath_tx_all_paths,
6325 no_neighbor_addpath_tx_all_paths_hidden_cmd,
6326 "no neighbor <A.B.C.D|X:X::X:X|WORD> addpath-tx-all-paths",
6327 NO_STR NEIGHBOR_STR NEIGHBOR_ADDR_STR2
6328 "Use addpath to advertise all paths to a neighbor\n")
6329
6330 DEFUN (neighbor_addpath_tx_bestpath_per_as,
6331 neighbor_addpath_tx_bestpath_per_as_cmd,
6332 "neighbor <A.B.C.D|X:X::X:X|WORD> addpath-tx-bestpath-per-AS",
6333 NEIGHBOR_STR
6334 NEIGHBOR_ADDR_STR2
6335 "Use addpath to advertise the bestpath per each neighboring AS\n")
6336 {
6337 int idx_peer = 1;
6338 struct peer *peer;
6339
6340 peer = peer_and_group_lookup_vty(vty, argv[idx_peer]->arg);
6341 if (!peer)
6342 return CMD_WARNING_CONFIG_FAILED;
6343
6344 bgp_addpath_set_peer_type(peer, bgp_node_afi(vty), bgp_node_safi(vty),
6345 BGP_ADDPATH_BEST_PER_AS);
6346
6347 return CMD_SUCCESS;
6348 }
6349
6350 ALIAS_HIDDEN(neighbor_addpath_tx_bestpath_per_as,
6351 neighbor_addpath_tx_bestpath_per_as_hidden_cmd,
6352 "neighbor <A.B.C.D|X:X::X:X|WORD> addpath-tx-bestpath-per-AS",
6353 NEIGHBOR_STR NEIGHBOR_ADDR_STR2
6354 "Use addpath to advertise the bestpath per each neighboring AS\n")
6355
6356 DEFUN (no_neighbor_addpath_tx_bestpath_per_as,
6357 no_neighbor_addpath_tx_bestpath_per_as_cmd,
6358 "no neighbor <A.B.C.D|X:X::X:X|WORD> addpath-tx-bestpath-per-AS",
6359 NO_STR
6360 NEIGHBOR_STR
6361 NEIGHBOR_ADDR_STR2
6362 "Use addpath to advertise the bestpath per each neighboring AS\n")
6363 {
6364 int idx_peer = 2;
6365 struct peer *peer;
6366
6367 peer = peer_and_group_lookup_vty(vty, argv[idx_peer]->arg);
6368 if (!peer)
6369 return CMD_WARNING_CONFIG_FAILED;
6370
6371 if (peer->addpath_type[bgp_node_afi(vty)][bgp_node_safi(vty)]
6372 != BGP_ADDPATH_BEST_PER_AS) {
6373 vty_out(vty,
6374 "%% Peer not currently configured to transmit all best path per as.");
6375 return CMD_WARNING_CONFIG_FAILED;
6376 }
6377
6378 bgp_addpath_set_peer_type(peer, bgp_node_afi(vty), bgp_node_safi(vty),
6379 BGP_ADDPATH_NONE);
6380
6381 return CMD_SUCCESS;
6382 }
6383
6384 ALIAS_HIDDEN(no_neighbor_addpath_tx_bestpath_per_as,
6385 no_neighbor_addpath_tx_bestpath_per_as_hidden_cmd,
6386 "no neighbor <A.B.C.D|X:X::X:X|WORD> addpath-tx-bestpath-per-AS",
6387 NO_STR NEIGHBOR_STR NEIGHBOR_ADDR_STR2
6388 "Use addpath to advertise the bestpath per each neighboring AS\n")
6389
6390 static int set_ecom_list(struct vty *vty, int argc, struct cmd_token **argv,
6391 struct ecommunity **list)
6392 {
6393 struct ecommunity *ecom = NULL;
6394 struct ecommunity *ecomadd;
6395
6396 for (; argc; --argc, ++argv) {
6397
6398 ecomadd = ecommunity_str2com(argv[0]->arg,
6399 ECOMMUNITY_ROUTE_TARGET, 0);
6400 if (!ecomadd) {
6401 vty_out(vty, "Malformed community-list value\n");
6402 if (ecom)
6403 ecommunity_free(&ecom);
6404 return CMD_WARNING_CONFIG_FAILED;
6405 }
6406
6407 if (ecom) {
6408 ecommunity_merge(ecom, ecomadd);
6409 ecommunity_free(&ecomadd);
6410 } else {
6411 ecom = ecomadd;
6412 }
6413 }
6414
6415 if (*list) {
6416 ecommunity_free(&*list);
6417 }
6418 *list = ecom;
6419
6420 return CMD_SUCCESS;
6421 }
6422
6423 /*
6424 * v2vimport is true if we are handling a `import vrf ...` command
6425 */
6426 static afi_t vpn_policy_getafi(struct vty *vty, struct bgp *bgp, bool v2vimport)
6427 {
6428 afi_t afi;
6429
6430 switch (vty->node) {
6431 case BGP_IPV4_NODE:
6432 afi = AFI_IP;
6433 break;
6434 case BGP_IPV6_NODE:
6435 afi = AFI_IP6;
6436 break;
6437 default:
6438 vty_out(vty,
6439 "%% context error: valid only in address-family <ipv4|ipv6> unicast block\n");
6440 return AFI_MAX;
6441 }
6442
6443 if (!v2vimport) {
6444 if (CHECK_FLAG(bgp->af_flags[afi][SAFI_UNICAST],
6445 BGP_CONFIG_VRF_TO_VRF_IMPORT)
6446 || CHECK_FLAG(bgp->af_flags[afi][SAFI_UNICAST],
6447 BGP_CONFIG_VRF_TO_VRF_EXPORT)) {
6448 vty_out(vty,
6449 "%% error: Please unconfigure import vrf commands before using vpn commands\n");
6450 return AFI_MAX;
6451 }
6452 } else {
6453 if (CHECK_FLAG(bgp->af_flags[afi][SAFI_UNICAST],
6454 BGP_CONFIG_VRF_TO_MPLSVPN_EXPORT)
6455 || CHECK_FLAG(bgp->af_flags[afi][SAFI_UNICAST],
6456 BGP_CONFIG_MPLSVPN_TO_VRF_IMPORT)) {
6457 vty_out(vty,
6458 "%% error: Please unconfigure vpn to vrf commands before using import vrf commands\n");
6459 return AFI_MAX;
6460 }
6461 }
6462 return afi;
6463 }
6464
6465 DEFPY (af_rd_vpn_export,
6466 af_rd_vpn_export_cmd,
6467 "[no] rd vpn export ASN:NN_OR_IP-ADDRESS:NN$rd_str",
6468 NO_STR
6469 "Specify route distinguisher\n"
6470 "Between current address-family and vpn\n"
6471 "For routes leaked from current address-family to vpn\n"
6472 "Route Distinguisher (<as-number>:<number> | <ip-address>:<number>)\n")
6473 {
6474 VTY_DECLVAR_CONTEXT(bgp, bgp);
6475 struct prefix_rd prd;
6476 int ret;
6477 afi_t afi;
6478 int idx = 0;
6479 int yes = 1;
6480
6481 if (argv_find(argv, argc, "no", &idx))
6482 yes = 0;
6483
6484 if (yes) {
6485 ret = str2prefix_rd(rd_str, &prd);
6486 if (!ret) {
6487 vty_out(vty, "%% Malformed rd\n");
6488 return CMD_WARNING_CONFIG_FAILED;
6489 }
6490 }
6491
6492 afi = vpn_policy_getafi(vty, bgp, false);
6493 if (afi == AFI_MAX)
6494 return CMD_WARNING_CONFIG_FAILED;
6495
6496 /*
6497 * pre-change: un-export vpn routes (vpn->vrf routes unaffected)
6498 */
6499 vpn_leak_prechange(BGP_VPN_POLICY_DIR_TOVPN, afi,
6500 bgp_get_default(), bgp);
6501
6502 if (yes) {
6503 bgp->vpn_policy[afi].tovpn_rd = prd;
6504 SET_FLAG(bgp->vpn_policy[afi].flags,
6505 BGP_VPN_POLICY_TOVPN_RD_SET);
6506 } else {
6507 UNSET_FLAG(bgp->vpn_policy[afi].flags,
6508 BGP_VPN_POLICY_TOVPN_RD_SET);
6509 }
6510
6511 /* post-change: re-export vpn routes */
6512 vpn_leak_postchange(BGP_VPN_POLICY_DIR_TOVPN, afi,
6513 bgp_get_default(), bgp);
6514
6515 return CMD_SUCCESS;
6516 }
6517
6518 ALIAS (af_rd_vpn_export,
6519 af_no_rd_vpn_export_cmd,
6520 "no rd vpn export",
6521 NO_STR
6522 "Specify route distinguisher\n"
6523 "Between current address-family and vpn\n"
6524 "For routes leaked from current address-family to vpn\n")
6525
6526 DEFPY (af_label_vpn_export,
6527 af_label_vpn_export_cmd,
6528 "[no] label vpn export <(0-1048575)$label_val|auto$label_auto>",
6529 NO_STR
6530 "label value for VRF\n"
6531 "Between current address-family and vpn\n"
6532 "For routes leaked from current address-family to vpn\n"
6533 "Label Value <0-1048575>\n"
6534 "Automatically assign a label\n")
6535 {
6536 VTY_DECLVAR_CONTEXT(bgp, bgp);
6537 mpls_label_t label = MPLS_LABEL_NONE;
6538 afi_t afi;
6539 int idx = 0;
6540 int yes = 1;
6541
6542 if (argv_find(argv, argc, "no", &idx))
6543 yes = 0;
6544
6545 /* If "no ...", squash trailing parameter */
6546 if (!yes)
6547 label_auto = NULL;
6548
6549 if (yes) {
6550 if (!label_auto)
6551 label = label_val; /* parser should force unsigned */
6552 }
6553
6554 afi = vpn_policy_getafi(vty, bgp, false);
6555 if (afi == AFI_MAX)
6556 return CMD_WARNING_CONFIG_FAILED;
6557
6558
6559 if (label_auto && CHECK_FLAG(bgp->vpn_policy[afi].flags,
6560 BGP_VPN_POLICY_TOVPN_LABEL_AUTO))
6561 /* no change */
6562 return CMD_SUCCESS;
6563
6564 /*
6565 * pre-change: un-export vpn routes (vpn->vrf routes unaffected)
6566 */
6567 vpn_leak_prechange(BGP_VPN_POLICY_DIR_TOVPN, afi,
6568 bgp_get_default(), bgp);
6569
6570 if (!label_auto && CHECK_FLAG(bgp->vpn_policy[afi].flags,
6571 BGP_VPN_POLICY_TOVPN_LABEL_AUTO)) {
6572
6573 if (bgp->vpn_policy[afi].tovpn_label != MPLS_LABEL_NONE) {
6574
6575 /*
6576 * label has previously been automatically
6577 * assigned by labelpool: release it
6578 *
6579 * NB if tovpn_label == MPLS_LABEL_NONE it
6580 * means the automatic assignment is in flight
6581 * and therefore the labelpool callback must
6582 * detect that the auto label is not needed.
6583 */
6584
6585 bgp_lp_release(LP_TYPE_VRF,
6586 &bgp->vpn_policy[afi],
6587 bgp->vpn_policy[afi].tovpn_label);
6588 }
6589 UNSET_FLAG(bgp->vpn_policy[afi].flags,
6590 BGP_VPN_POLICY_TOVPN_LABEL_AUTO);
6591 }
6592
6593 bgp->vpn_policy[afi].tovpn_label = label;
6594 if (label_auto) {
6595 SET_FLAG(bgp->vpn_policy[afi].flags,
6596 BGP_VPN_POLICY_TOVPN_LABEL_AUTO);
6597 bgp_lp_get(LP_TYPE_VRF, &bgp->vpn_policy[afi],
6598 vpn_leak_label_callback);
6599 }
6600
6601 /* post-change: re-export vpn routes */
6602 vpn_leak_postchange(BGP_VPN_POLICY_DIR_TOVPN, afi,
6603 bgp_get_default(), bgp);
6604
6605 return CMD_SUCCESS;
6606 }
6607
6608 ALIAS (af_label_vpn_export,
6609 af_no_label_vpn_export_cmd,
6610 "no label vpn export",
6611 NO_STR
6612 "label value for VRF\n"
6613 "Between current address-family and vpn\n"
6614 "For routes leaked from current address-family to vpn\n")
6615
6616 DEFPY (af_nexthop_vpn_export,
6617 af_nexthop_vpn_export_cmd,
6618 "[no] nexthop vpn export <A.B.C.D|X:X::X:X>$nexthop_str",
6619 NO_STR
6620 "Specify next hop to use for VRF advertised prefixes\n"
6621 "Between current address-family and vpn\n"
6622 "For routes leaked from current address-family to vpn\n"
6623 "IPv4 prefix\n"
6624 "IPv6 prefix\n")
6625 {
6626 VTY_DECLVAR_CONTEXT(bgp, bgp);
6627 afi_t afi;
6628 struct prefix p;
6629 int idx = 0;
6630 int yes = 1;
6631
6632 if (argv_find(argv, argc, "no", &idx))
6633 yes = 0;
6634
6635 if (yes) {
6636 if (!sockunion2hostprefix(nexthop_str, &p))
6637 return CMD_WARNING_CONFIG_FAILED;
6638 }
6639
6640 afi = vpn_policy_getafi(vty, bgp, false);
6641 if (afi == AFI_MAX)
6642 return CMD_WARNING_CONFIG_FAILED;
6643
6644 /*
6645 * pre-change: un-export vpn routes (vpn->vrf routes unaffected)
6646 */
6647 vpn_leak_prechange(BGP_VPN_POLICY_DIR_TOVPN, afi,
6648 bgp_get_default(), bgp);
6649
6650 if (yes) {
6651 bgp->vpn_policy[afi].tovpn_nexthop = p;
6652 SET_FLAG(bgp->vpn_policy[afi].flags,
6653 BGP_VPN_POLICY_TOVPN_NEXTHOP_SET);
6654 } else {
6655 UNSET_FLAG(bgp->vpn_policy[afi].flags,
6656 BGP_VPN_POLICY_TOVPN_NEXTHOP_SET);
6657 }
6658
6659 /* post-change: re-export vpn routes */
6660 vpn_leak_postchange(BGP_VPN_POLICY_DIR_TOVPN, afi,
6661 bgp_get_default(), bgp);
6662
6663 return CMD_SUCCESS;
6664 }
6665
6666 ALIAS (af_nexthop_vpn_export,
6667 af_no_nexthop_vpn_export_cmd,
6668 "no nexthop vpn export",
6669 NO_STR
6670 "Specify next hop to use for VRF advertised prefixes\n"
6671 "Between current address-family and vpn\n"
6672 "For routes leaked from current address-family to vpn\n")
6673
6674 static int vpn_policy_getdirs(struct vty *vty, const char *dstr, int *dodir)
6675 {
6676 if (!strcmp(dstr, "import")) {
6677 dodir[BGP_VPN_POLICY_DIR_FROMVPN] = 1;
6678 } else if (!strcmp(dstr, "export")) {
6679 dodir[BGP_VPN_POLICY_DIR_TOVPN] = 1;
6680 } else if (!strcmp(dstr, "both")) {
6681 dodir[BGP_VPN_POLICY_DIR_FROMVPN] = 1;
6682 dodir[BGP_VPN_POLICY_DIR_TOVPN] = 1;
6683 } else {
6684 vty_out(vty, "%% direction parse error\n");
6685 return CMD_WARNING_CONFIG_FAILED;
6686 }
6687 return CMD_SUCCESS;
6688 }
6689
6690 DEFPY (af_rt_vpn_imexport,
6691 af_rt_vpn_imexport_cmd,
6692 "[no] <rt|route-target> vpn <import|export|both>$direction_str RTLIST...",
6693 NO_STR
6694 "Specify route target list\n"
6695 "Specify route target list\n"
6696 "Between current address-family and vpn\n"
6697 "For routes leaked from vpn to current address-family: match any\n"
6698 "For routes leaked from current address-family to vpn: set\n"
6699 "both import: match any and export: set\n"
6700 "Space separated route target list (A.B.C.D:MN|EF:OPQR|GHJK:MN)\n")
6701 {
6702 VTY_DECLVAR_CONTEXT(bgp, bgp);
6703 int ret;
6704 struct ecommunity *ecom = NULL;
6705 int dodir[BGP_VPN_POLICY_DIR_MAX] = {0};
6706 vpn_policy_direction_t dir;
6707 afi_t afi;
6708 int idx = 0;
6709 int yes = 1;
6710
6711 if (argv_find(argv, argc, "no", &idx))
6712 yes = 0;
6713
6714 afi = vpn_policy_getafi(vty, bgp, false);
6715 if (afi == AFI_MAX)
6716 return CMD_WARNING_CONFIG_FAILED;
6717
6718 ret = vpn_policy_getdirs(vty, direction_str, dodir);
6719 if (ret != CMD_SUCCESS)
6720 return ret;
6721
6722 if (yes) {
6723 if (!argv_find(argv, argc, "RTLIST", &idx)) {
6724 vty_out(vty, "%% Missing RTLIST\n");
6725 return CMD_WARNING_CONFIG_FAILED;
6726 }
6727 ret = set_ecom_list(vty, argc - idx, argv + idx, &ecom);
6728 if (ret != CMD_SUCCESS) {
6729 return ret;
6730 }
6731 }
6732
6733 for (dir = 0; dir < BGP_VPN_POLICY_DIR_MAX; ++dir) {
6734 if (!dodir[dir])
6735 continue;
6736
6737 vpn_leak_prechange(dir, afi, bgp_get_default(), bgp);
6738
6739 if (yes) {
6740 if (bgp->vpn_policy[afi].rtlist[dir])
6741 ecommunity_free(
6742 &bgp->vpn_policy[afi].rtlist[dir]);
6743 bgp->vpn_policy[afi].rtlist[dir] =
6744 ecommunity_dup(ecom);
6745 } else {
6746 if (bgp->vpn_policy[afi].rtlist[dir])
6747 ecommunity_free(
6748 &bgp->vpn_policy[afi].rtlist[dir]);
6749 bgp->vpn_policy[afi].rtlist[dir] = NULL;
6750 }
6751
6752 vpn_leak_postchange(dir, afi, bgp_get_default(), bgp);
6753 }
6754
6755 if (ecom)
6756 ecommunity_free(&ecom);
6757
6758 return CMD_SUCCESS;
6759 }
6760
6761 ALIAS (af_rt_vpn_imexport,
6762 af_no_rt_vpn_imexport_cmd,
6763 "no <rt|route-target> vpn <import|export|both>$direction_str",
6764 NO_STR
6765 "Specify route target list\n"
6766 "Specify route target list\n"
6767 "Between current address-family and vpn\n"
6768 "For routes leaked from vpn to current address-family\n"
6769 "For routes leaked from current address-family to vpn\n"
6770 "both import and export\n")
6771
6772 DEFPY (af_route_map_vpn_imexport,
6773 af_route_map_vpn_imexport_cmd,
6774 /* future: "route-map <vpn|evpn|vrf NAME> <import|export> RMAP" */
6775 "[no] route-map vpn <import|export>$direction_str RMAP$rmap_str",
6776 NO_STR
6777 "Specify route map\n"
6778 "Between current address-family and vpn\n"
6779 "For routes leaked from vpn to current address-family\n"
6780 "For routes leaked from current address-family to vpn\n"
6781 "name of route-map\n")
6782 {
6783 VTY_DECLVAR_CONTEXT(bgp, bgp);
6784 int ret;
6785 int dodir[BGP_VPN_POLICY_DIR_MAX] = {0};
6786 vpn_policy_direction_t dir;
6787 afi_t afi;
6788 int idx = 0;
6789 int yes = 1;
6790
6791 if (argv_find(argv, argc, "no", &idx))
6792 yes = 0;
6793
6794 afi = vpn_policy_getafi(vty, bgp, false);
6795 if (afi == AFI_MAX)
6796 return CMD_WARNING_CONFIG_FAILED;
6797
6798 ret = vpn_policy_getdirs(vty, direction_str, dodir);
6799 if (ret != CMD_SUCCESS)
6800 return ret;
6801
6802 for (dir = 0; dir < BGP_VPN_POLICY_DIR_MAX; ++dir) {
6803 if (!dodir[dir])
6804 continue;
6805
6806 vpn_leak_prechange(dir, afi, bgp_get_default(), bgp);
6807
6808 if (yes) {
6809 if (bgp->vpn_policy[afi].rmap_name[dir])
6810 XFREE(MTYPE_ROUTE_MAP_NAME,
6811 bgp->vpn_policy[afi].rmap_name[dir]);
6812 bgp->vpn_policy[afi].rmap_name[dir] = XSTRDUP(
6813 MTYPE_ROUTE_MAP_NAME, rmap_str);
6814 bgp->vpn_policy[afi].rmap[dir] =
6815 route_map_lookup_warn_noexist(vty, rmap_str);
6816 if (!bgp->vpn_policy[afi].rmap[dir])
6817 return CMD_SUCCESS;
6818 } else {
6819 if (bgp->vpn_policy[afi].rmap_name[dir])
6820 XFREE(MTYPE_ROUTE_MAP_NAME,
6821 bgp->vpn_policy[afi].rmap_name[dir]);
6822 bgp->vpn_policy[afi].rmap_name[dir] = NULL;
6823 bgp->vpn_policy[afi].rmap[dir] = NULL;
6824 }
6825
6826 vpn_leak_postchange(dir, afi, bgp_get_default(), bgp);
6827 }
6828
6829 return CMD_SUCCESS;
6830 }
6831
6832 ALIAS (af_route_map_vpn_imexport,
6833 af_no_route_map_vpn_imexport_cmd,
6834 "no route-map vpn <import|export>$direction_str",
6835 NO_STR
6836 "Specify route map\n"
6837 "Between current address-family and vpn\n"
6838 "For routes leaked from vpn to current address-family\n"
6839 "For routes leaked from current address-family to vpn\n")
6840
6841 DEFPY(af_import_vrf_route_map, af_import_vrf_route_map_cmd,
6842 "[no] import vrf route-map RMAP$rmap_str",
6843 NO_STR
6844 "Import routes from another VRF\n"
6845 "Vrf routes being filtered\n"
6846 "Specify route map\n"
6847 "name of route-map\n")
6848 {
6849 VTY_DECLVAR_CONTEXT(bgp, bgp);
6850 vpn_policy_direction_t dir = BGP_VPN_POLICY_DIR_FROMVPN;
6851 afi_t afi;
6852 int idx = 0;
6853 int yes = 1;
6854 struct bgp *bgp_default;
6855
6856 if (argv_find(argv, argc, "no", &idx))
6857 yes = 0;
6858
6859 afi = vpn_policy_getafi(vty, bgp, true);
6860 if (afi == AFI_MAX)
6861 return CMD_WARNING_CONFIG_FAILED;
6862
6863 bgp_default = bgp_get_default();
6864 if (!bgp_default) {
6865 int32_t ret;
6866 as_t as = bgp->as;
6867
6868 /* Auto-create assuming the same AS */
6869 ret = bgp_get(&bgp_default, &as, NULL,
6870 BGP_INSTANCE_TYPE_DEFAULT);
6871
6872 if (ret) {
6873 vty_out(vty,
6874 "VRF default is not configured as a bgp instance\n");
6875 return CMD_WARNING;
6876 }
6877 }
6878
6879 vpn_leak_prechange(dir, afi, bgp_get_default(), bgp);
6880
6881 if (yes) {
6882 if (bgp->vpn_policy[afi].rmap_name[dir])
6883 XFREE(MTYPE_ROUTE_MAP_NAME,
6884 bgp->vpn_policy[afi].rmap_name[dir]);
6885 bgp->vpn_policy[afi].rmap_name[dir] =
6886 XSTRDUP(MTYPE_ROUTE_MAP_NAME, rmap_str);
6887 bgp->vpn_policy[afi].rmap[dir] =
6888 route_map_lookup_warn_noexist(vty, rmap_str);
6889 if (!bgp->vpn_policy[afi].rmap[dir])
6890 return CMD_SUCCESS;
6891 } else {
6892 if (bgp->vpn_policy[afi].rmap_name[dir])
6893 XFREE(MTYPE_ROUTE_MAP_NAME,
6894 bgp->vpn_policy[afi].rmap_name[dir]);
6895 bgp->vpn_policy[afi].rmap_name[dir] = NULL;
6896 bgp->vpn_policy[afi].rmap[dir] = NULL;
6897 }
6898
6899 vpn_leak_postchange(dir, afi, bgp_get_default(), bgp);
6900
6901 return CMD_SUCCESS;
6902 }
6903
6904 ALIAS(af_import_vrf_route_map, af_no_import_vrf_route_map_cmd,
6905 "no import vrf route-map",
6906 NO_STR
6907 "Import routes from another VRF\n"
6908 "Vrf routes being filtered\n"
6909 "Specify route map\n")
6910
6911 DEFPY(bgp_imexport_vrf, bgp_imexport_vrf_cmd,
6912 "[no] import vrf VIEWVRFNAME$import_name",
6913 NO_STR
6914 "Import routes from another VRF\n"
6915 "VRF to import from\n"
6916 "The name of the VRF\n")
6917 {
6918 VTY_DECLVAR_CONTEXT(bgp, bgp);
6919 struct listnode *node;
6920 struct bgp *vrf_bgp, *bgp_default;
6921 int32_t ret = 0;
6922 as_t as = bgp->as;
6923 bool remove = false;
6924 int32_t idx = 0;
6925 char *vname;
6926 enum bgp_instance_type bgp_type = BGP_INSTANCE_TYPE_VRF;
6927 safi_t safi;
6928 afi_t afi;
6929
6930 if (import_name == NULL) {
6931 vty_out(vty, "%% Missing import name\n");
6932 return CMD_WARNING;
6933 }
6934
6935 if (argv_find(argv, argc, "no", &idx))
6936 remove = true;
6937
6938 afi = vpn_policy_getafi(vty, bgp, true);
6939 if (afi == AFI_MAX)
6940 return CMD_WARNING_CONFIG_FAILED;
6941
6942 safi = bgp_node_safi(vty);
6943
6944 if (((BGP_INSTANCE_TYPE_DEFAULT == bgp->inst_type)
6945 && (strcmp(import_name, VRF_DEFAULT_NAME) == 0))
6946 || (bgp->name && (strcmp(import_name, bgp->name) == 0))) {
6947 vty_out(vty, "%% Cannot %s vrf %s into itself\n",
6948 remove ? "unimport" : "import", import_name);
6949 return CMD_WARNING;
6950 }
6951
6952 bgp_default = bgp_get_default();
6953 if (!bgp_default) {
6954 /* Auto-create assuming the same AS */
6955 ret = bgp_get(&bgp_default, &as, NULL,
6956 BGP_INSTANCE_TYPE_DEFAULT);
6957
6958 if (ret) {
6959 vty_out(vty,
6960 "VRF default is not configured as a bgp instance\n");
6961 return CMD_WARNING;
6962 }
6963 }
6964
6965 vrf_bgp = bgp_lookup_by_name(import_name);
6966 if (!vrf_bgp) {
6967 if (strcmp(import_name, VRF_DEFAULT_NAME) == 0)
6968 vrf_bgp = bgp_default;
6969 else
6970 /* Auto-create assuming the same AS */
6971 ret = bgp_get(&vrf_bgp, &as, import_name, bgp_type);
6972
6973 if (ret) {
6974 vty_out(vty,
6975 "VRF %s is not configured as a bgp instance\n",
6976 import_name);
6977 return CMD_WARNING;
6978 }
6979 }
6980
6981 if (remove) {
6982 vrf_unimport_from_vrf(bgp, vrf_bgp, afi, safi);
6983 } else {
6984 /* Already importing from "import_vrf"? */
6985 for (ALL_LIST_ELEMENTS_RO(bgp->vpn_policy[afi].import_vrf, node,
6986 vname)) {
6987 if (strcmp(vname, import_name) == 0)
6988 return CMD_WARNING;
6989 }
6990
6991 vrf_import_from_vrf(bgp, vrf_bgp, afi, safi);
6992 }
6993
6994 return CMD_SUCCESS;
6995 }
6996
6997 /* This command is valid only in a bgp vrf instance or the default instance */
6998 DEFPY (bgp_imexport_vpn,
6999 bgp_imexport_vpn_cmd,
7000 "[no] <import|export>$direction_str vpn",
7001 NO_STR
7002 "Import routes to this address-family\n"
7003 "Export routes from this address-family\n"
7004 "to/from default instance VPN RIB\n")
7005 {
7006 VTY_DECLVAR_CONTEXT(bgp, bgp);
7007 int previous_state;
7008 afi_t afi;
7009 safi_t safi;
7010 int idx = 0;
7011 int yes = 1;
7012 int flag;
7013 vpn_policy_direction_t dir;
7014
7015 if (argv_find(argv, argc, "no", &idx))
7016 yes = 0;
7017
7018 if (BGP_INSTANCE_TYPE_VRF != bgp->inst_type &&
7019 BGP_INSTANCE_TYPE_DEFAULT != bgp->inst_type) {
7020
7021 vty_out(vty, "%% import|export vpn valid only for bgp vrf or default instance\n");
7022 return CMD_WARNING_CONFIG_FAILED;
7023 }
7024
7025 afi = bgp_node_afi(vty);
7026 safi = bgp_node_safi(vty);
7027 if ((SAFI_UNICAST != safi) || ((AFI_IP != afi) && (AFI_IP6 != afi))) {
7028 vty_out(vty, "%% import|export vpn valid only for unicast ipv4|ipv6\n");
7029 return CMD_WARNING_CONFIG_FAILED;
7030 }
7031
7032 if (!strcmp(direction_str, "import")) {
7033 flag = BGP_CONFIG_MPLSVPN_TO_VRF_IMPORT;
7034 dir = BGP_VPN_POLICY_DIR_FROMVPN;
7035 } else if (!strcmp(direction_str, "export")) {
7036 flag = BGP_CONFIG_VRF_TO_MPLSVPN_EXPORT;
7037 dir = BGP_VPN_POLICY_DIR_TOVPN;
7038 } else {
7039 vty_out(vty, "%% unknown direction %s\n", direction_str);
7040 return CMD_WARNING_CONFIG_FAILED;
7041 }
7042
7043 previous_state = CHECK_FLAG(bgp->af_flags[afi][safi], flag);
7044
7045 if (yes) {
7046 SET_FLAG(bgp->af_flags[afi][safi], flag);
7047 if (!previous_state) {
7048 /* trigger export current vrf */
7049 vpn_leak_postchange(dir, afi, bgp_get_default(), bgp);
7050 }
7051 } else {
7052 if (previous_state) {
7053 /* trigger un-export current vrf */
7054 vpn_leak_prechange(dir, afi, bgp_get_default(), bgp);
7055 }
7056 UNSET_FLAG(bgp->af_flags[afi][safi], flag);
7057 }
7058
7059 return CMD_SUCCESS;
7060 }
7061
7062 DEFPY (af_routetarget_import,
7063 af_routetarget_import_cmd,
7064 "[no] <rt|route-target> redirect import RTLIST...",
7065 NO_STR
7066 "Specify route target list\n"
7067 "Specify route target list\n"
7068 "Flow-spec redirect type route target\n"
7069 "Import routes to this address-family\n"
7070 "Space separated route target list (A.B.C.D:MN|EF:OPQR|GHJK:MN)\n")
7071 {
7072 VTY_DECLVAR_CONTEXT(bgp, bgp);
7073 int ret;
7074 struct ecommunity *ecom = NULL;
7075 afi_t afi;
7076 int idx = 0;
7077 int yes = 1;
7078
7079 if (argv_find(argv, argc, "no", &idx))
7080 yes = 0;
7081
7082 afi = vpn_policy_getafi(vty, bgp, false);
7083 if (afi == AFI_MAX)
7084 return CMD_WARNING_CONFIG_FAILED;
7085
7086 if (yes) {
7087 if (!argv_find(argv, argc, "RTLIST", &idx)) {
7088 vty_out(vty, "%% Missing RTLIST\n");
7089 return CMD_WARNING_CONFIG_FAILED;
7090 }
7091 ret = set_ecom_list(vty, argc - idx, argv + idx, &ecom);
7092 if (ret != CMD_SUCCESS)
7093 return ret;
7094 }
7095
7096 if (yes) {
7097 if (bgp->vpn_policy[afi].import_redirect_rtlist)
7098 ecommunity_free(&bgp->vpn_policy[afi]
7099 .import_redirect_rtlist);
7100 bgp->vpn_policy[afi].import_redirect_rtlist =
7101 ecommunity_dup(ecom);
7102 } else {
7103 if (bgp->vpn_policy[afi].import_redirect_rtlist)
7104 ecommunity_free(&bgp->vpn_policy[afi]
7105 .import_redirect_rtlist);
7106 bgp->vpn_policy[afi].import_redirect_rtlist = NULL;
7107 }
7108
7109 if (ecom)
7110 ecommunity_free(&ecom);
7111
7112 return CMD_SUCCESS;
7113 }
7114
7115 DEFUN_NOSH (address_family_ipv4_safi,
7116 address_family_ipv4_safi_cmd,
7117 "address-family ipv4 [<unicast|multicast|vpn|labeled-unicast|flowspec>]",
7118 "Enter Address Family command mode\n"
7119 "Address Family\n"
7120 BGP_SAFI_WITH_LABEL_HELP_STR)
7121 {
7122
7123 if (argc == 3) {
7124 VTY_DECLVAR_CONTEXT(bgp, bgp);
7125 safi_t safi = bgp_vty_safi_from_str(argv[2]->text);
7126 if (bgp->inst_type != BGP_INSTANCE_TYPE_DEFAULT
7127 && safi != SAFI_UNICAST && safi != SAFI_MULTICAST
7128 && safi != SAFI_EVPN) {
7129 vty_out(vty,
7130 "Only Unicast/Multicast/EVPN SAFIs supported in non-core instances.\n");
7131 return CMD_WARNING_CONFIG_FAILED;
7132 }
7133 vty->node = bgp_node_type(AFI_IP, safi);
7134 } else
7135 vty->node = BGP_IPV4_NODE;
7136
7137 return CMD_SUCCESS;
7138 }
7139
7140 DEFUN_NOSH (address_family_ipv6_safi,
7141 address_family_ipv6_safi_cmd,
7142 "address-family ipv6 [<unicast|multicast|vpn|labeled-unicast|flowspec>]",
7143 "Enter Address Family command mode\n"
7144 "Address Family\n"
7145 BGP_SAFI_WITH_LABEL_HELP_STR)
7146 {
7147 if (argc == 3) {
7148 VTY_DECLVAR_CONTEXT(bgp, bgp);
7149 safi_t safi = bgp_vty_safi_from_str(argv[2]->text);
7150 if (bgp->inst_type != BGP_INSTANCE_TYPE_DEFAULT
7151 && safi != SAFI_UNICAST && safi != SAFI_MULTICAST
7152 && safi != SAFI_EVPN) {
7153 vty_out(vty,
7154 "Only Unicast/Multicast/EVPN SAFIs supported in non-core instances.\n");
7155 return CMD_WARNING_CONFIG_FAILED;
7156 }
7157 vty->node = bgp_node_type(AFI_IP6, safi);
7158 } else
7159 vty->node = BGP_IPV6_NODE;
7160
7161 return CMD_SUCCESS;
7162 }
7163
7164 #ifdef KEEP_OLD_VPN_COMMANDS
7165 DEFUN_NOSH (address_family_vpnv4,
7166 address_family_vpnv4_cmd,
7167 "address-family vpnv4 [unicast]",
7168 "Enter Address Family command mode\n"
7169 "Address Family\n"
7170 "Address Family modifier\n")
7171 {
7172 vty->node = BGP_VPNV4_NODE;
7173 return CMD_SUCCESS;
7174 }
7175
7176 DEFUN_NOSH (address_family_vpnv6,
7177 address_family_vpnv6_cmd,
7178 "address-family vpnv6 [unicast]",
7179 "Enter Address Family command mode\n"
7180 "Address Family\n"
7181 "Address Family modifier\n")
7182 {
7183 vty->node = BGP_VPNV6_NODE;
7184 return CMD_SUCCESS;
7185 }
7186 #endif /* KEEP_OLD_VPN_COMMANDS */
7187
7188 DEFUN_NOSH (address_family_evpn,
7189 address_family_evpn_cmd,
7190 "address-family l2vpn evpn",
7191 "Enter Address Family command mode\n"
7192 "Address Family\n"
7193 "Address Family modifier\n")
7194 {
7195 VTY_DECLVAR_CONTEXT(bgp, bgp);
7196 vty->node = BGP_EVPN_NODE;
7197 return CMD_SUCCESS;
7198 }
7199
7200 DEFUN_NOSH (exit_address_family,
7201 exit_address_family_cmd,
7202 "exit-address-family",
7203 "Exit from Address Family configuration mode\n")
7204 {
7205 if (vty->node == BGP_IPV4_NODE || vty->node == BGP_IPV4M_NODE
7206 || vty->node == BGP_IPV4L_NODE || vty->node == BGP_VPNV4_NODE
7207 || vty->node == BGP_IPV6_NODE || vty->node == BGP_IPV6M_NODE
7208 || vty->node == BGP_IPV6L_NODE || vty->node == BGP_VPNV6_NODE
7209 || vty->node == BGP_EVPN_NODE
7210 || vty->node == BGP_FLOWSPECV4_NODE
7211 || vty->node == BGP_FLOWSPECV6_NODE)
7212 vty->node = BGP_NODE;
7213 return CMD_SUCCESS;
7214 }
7215
7216 /* Recalculate bestpath and re-advertise a prefix */
7217 static int bgp_clear_prefix(struct vty *vty, const char *view_name,
7218 const char *ip_str, afi_t afi, safi_t safi,
7219 struct prefix_rd *prd)
7220 {
7221 int ret;
7222 struct prefix match;
7223 struct bgp_node *rn;
7224 struct bgp_node *rm;
7225 struct bgp *bgp;
7226 struct bgp_table *table;
7227 struct bgp_table *rib;
7228
7229 /* BGP structure lookup. */
7230 if (view_name) {
7231 bgp = bgp_lookup_by_name(view_name);
7232 if (bgp == NULL) {
7233 vty_out(vty, "%% Can't find BGP instance %s\n",
7234 view_name);
7235 return CMD_WARNING;
7236 }
7237 } else {
7238 bgp = bgp_get_default();
7239 if (bgp == NULL) {
7240 vty_out(vty, "%% No BGP process is configured\n");
7241 return CMD_WARNING;
7242 }
7243 }
7244
7245 /* Check IP address argument. */
7246 ret = str2prefix(ip_str, &match);
7247 if (!ret) {
7248 vty_out(vty, "%% address is malformed\n");
7249 return CMD_WARNING;
7250 }
7251
7252 match.family = afi2family(afi);
7253 rib = bgp->rib[afi][safi];
7254
7255 if (safi == SAFI_MPLS_VPN) {
7256 for (rn = bgp_table_top(rib); rn; rn = bgp_route_next(rn)) {
7257 if (prd && memcmp(rn->p.u.val, prd->val, 8) != 0)
7258 continue;
7259
7260 table = bgp_node_get_bgp_table_info(rn);
7261 if (table != NULL) {
7262
7263 if ((rm = bgp_node_match(table, &match))
7264 != NULL) {
7265 if (rm->p.prefixlen
7266 == match.prefixlen) {
7267 SET_FLAG(rm->flags,
7268 BGP_NODE_USER_CLEAR);
7269 bgp_process(bgp, rm, afi, safi);
7270 }
7271 bgp_unlock_node(rm);
7272 }
7273 }
7274 }
7275 } else {
7276 if ((rn = bgp_node_match(rib, &match)) != NULL) {
7277 if (rn->p.prefixlen == match.prefixlen) {
7278 SET_FLAG(rn->flags, BGP_NODE_USER_CLEAR);
7279 bgp_process(bgp, rn, afi, safi);
7280 }
7281 bgp_unlock_node(rn);
7282 }
7283 }
7284
7285 return CMD_SUCCESS;
7286 }
7287
7288 /* one clear bgp command to rule them all */
7289 DEFUN (clear_ip_bgp_all,
7290 clear_ip_bgp_all_cmd,
7291 "clear [ip] bgp [<view|vrf> VIEWVRFNAME] [<ipv4|ipv6|l2vpn> [<unicast|multicast|vpn|labeled-unicast|flowspec|evpn>]] <*|A.B.C.D|X:X::X:X|WORD|(1-4294967295)|external|peer-group PGNAME> [<soft [<in|out>]|in [prefix-filter]|out>]",
7292 CLEAR_STR
7293 IP_STR
7294 BGP_STR
7295 BGP_INSTANCE_HELP_STR
7296 BGP_AFI_HELP_STR
7297 "Address Family\n"
7298 BGP_SAFI_WITH_LABEL_HELP_STR
7299 "Address Family modifier\n"
7300 "Clear all peers\n"
7301 "BGP neighbor address to clear\n"
7302 "BGP IPv6 neighbor to clear\n"
7303 "BGP neighbor on interface to clear\n"
7304 "Clear peers with the AS number\n"
7305 "Clear all external peers\n"
7306 "Clear all members of peer-group\n"
7307 "BGP peer-group name\n"
7308 BGP_SOFT_STR
7309 BGP_SOFT_IN_STR
7310 BGP_SOFT_OUT_STR
7311 BGP_SOFT_IN_STR
7312 "Push out prefix-list ORF and do inbound soft reconfig\n"
7313 BGP_SOFT_OUT_STR)
7314 {
7315 char *vrf = NULL;
7316
7317 afi_t afi = AFI_IP6;
7318 safi_t safi = SAFI_UNICAST;
7319 enum clear_sort clr_sort = clear_peer;
7320 enum bgp_clear_type clr_type;
7321 char *clr_arg = NULL;
7322
7323 int idx = 0;
7324
7325 /* clear [ip] bgp */
7326 if (argv_find(argv, argc, "ip", &idx))
7327 afi = AFI_IP;
7328
7329 /* [<vrf> VIEWVRFNAME] */
7330 if (argv_find(argv, argc, "vrf", &idx)) {
7331 vrf = argv[idx + 1]->arg;
7332 idx += 2;
7333 if (vrf && strmatch(vrf, VRF_DEFAULT_NAME))
7334 vrf = NULL;
7335 } else if (argv_find(argv, argc, "view", &idx)) {
7336 /* [<view> VIEWVRFNAME] */
7337 vrf = argv[idx + 1]->arg;
7338 idx += 2;
7339 }
7340 /* ["BGP_AFI_CMD_STR" ["BGP_SAFI_CMD_STR"]] */
7341 if (argv_find_and_parse_afi(argv, argc, &idx, &afi))
7342 argv_find_and_parse_safi(argv, argc, &idx, &safi);
7343
7344 /* <*|A.B.C.D|X:X::X:X|WORD|(1-4294967295)|external|peer-group PGNAME> */
7345 if (argv_find(argv, argc, "*", &idx)) {
7346 clr_sort = clear_all;
7347 } else if (argv_find(argv, argc, "A.B.C.D", &idx)) {
7348 clr_sort = clear_peer;
7349 clr_arg = argv[idx]->arg;
7350 } else if (argv_find(argv, argc, "X:X::X:X", &idx)) {
7351 clr_sort = clear_peer;
7352 clr_arg = argv[idx]->arg;
7353 } else if (argv_find(argv, argc, "peer-group", &idx)) {
7354 clr_sort = clear_group;
7355 idx++;
7356 clr_arg = argv[idx]->arg;
7357 } else if (argv_find(argv, argc, "PGNAME", &idx)) {
7358 clr_sort = clear_peer;
7359 clr_arg = argv[idx]->arg;
7360 } else if (argv_find(argv, argc, "(1-4294967295)", &idx)) {
7361 clr_sort = clear_as;
7362 clr_arg = argv[idx]->arg;
7363 } else if (argv_find(argv, argc, "external", &idx)) {
7364 clr_sort = clear_external;
7365 }
7366
7367 /* [<soft [<in|out>]|in [prefix-filter]|out>] */
7368 if (argv_find(argv, argc, "soft", &idx)) {
7369 if (argv_find(argv, argc, "in", &idx)
7370 || argv_find(argv, argc, "out", &idx))
7371 clr_type = strmatch(argv[idx]->text, "in")
7372 ? BGP_CLEAR_SOFT_IN
7373 : BGP_CLEAR_SOFT_OUT;
7374 else
7375 clr_type = BGP_CLEAR_SOFT_BOTH;
7376 } else if (argv_find(argv, argc, "in", &idx)) {
7377 clr_type = argv_find(argv, argc, "prefix-filter", &idx)
7378 ? BGP_CLEAR_SOFT_IN_ORF_PREFIX
7379 : BGP_CLEAR_SOFT_IN;
7380 } else if (argv_find(argv, argc, "out", &idx)) {
7381 clr_type = BGP_CLEAR_SOFT_OUT;
7382 } else
7383 clr_type = BGP_CLEAR_SOFT_NONE;
7384
7385 return bgp_clear_vty(vty, vrf, afi, safi, clr_sort, clr_type, clr_arg);
7386 }
7387
7388 DEFUN (clear_ip_bgp_prefix,
7389 clear_ip_bgp_prefix_cmd,
7390 "clear [ip] bgp [<view|vrf> VIEWVRFNAME] prefix A.B.C.D/M",
7391 CLEAR_STR
7392 IP_STR
7393 BGP_STR
7394 BGP_INSTANCE_HELP_STR
7395 "Clear bestpath and re-advertise\n"
7396 "IPv4 prefix\n")
7397 {
7398 char *vrf = NULL;
7399 char *prefix = NULL;
7400
7401 int idx = 0;
7402
7403 /* [<view|vrf> VIEWVRFNAME] */
7404 if (argv_find(argv, argc, "vrf", &idx)) {
7405 vrf = argv[idx + 1]->arg;
7406 idx += 2;
7407 if (vrf && strmatch(vrf, VRF_DEFAULT_NAME))
7408 vrf = NULL;
7409 } else if (argv_find(argv, argc, "view", &idx)) {
7410 /* [<view> VIEWVRFNAME] */
7411 vrf = argv[idx + 1]->arg;
7412 idx += 2;
7413 }
7414
7415 prefix = argv[argc - 1]->arg;
7416
7417 return bgp_clear_prefix(vty, vrf, prefix, AFI_IP, SAFI_UNICAST, NULL);
7418 }
7419
7420 DEFUN (clear_bgp_ipv6_safi_prefix,
7421 clear_bgp_ipv6_safi_prefix_cmd,
7422 "clear [ip] bgp ipv6 "BGP_SAFI_CMD_STR" prefix X:X::X:X/M",
7423 CLEAR_STR
7424 IP_STR
7425 BGP_STR
7426 "Address Family\n"
7427 BGP_SAFI_HELP_STR
7428 "Clear bestpath and re-advertise\n"
7429 "IPv6 prefix\n")
7430 {
7431 int idx_safi = 0;
7432 int idx_ipv6_prefix = 0;
7433 safi_t safi = SAFI_UNICAST;
7434 char *prefix = argv_find(argv, argc, "X:X::X:X/M", &idx_ipv6_prefix) ?
7435 argv[idx_ipv6_prefix]->arg : NULL;
7436
7437 argv_find_and_parse_safi(argv, argc, &idx_safi, &safi);
7438 return bgp_clear_prefix(
7439 vty, NULL, prefix, AFI_IP6,
7440 safi, NULL);
7441 }
7442
7443 DEFUN (clear_bgp_instance_ipv6_safi_prefix,
7444 clear_bgp_instance_ipv6_safi_prefix_cmd,
7445 "clear [ip] bgp <view|vrf> VIEWVRFNAME ipv6 "BGP_SAFI_CMD_STR" prefix X:X::X:X/M",
7446 CLEAR_STR
7447 IP_STR
7448 BGP_STR
7449 BGP_INSTANCE_HELP_STR
7450 "Address Family\n"
7451 BGP_SAFI_HELP_STR
7452 "Clear bestpath and re-advertise\n"
7453 "IPv6 prefix\n")
7454 {
7455 int idx_safi = 0;
7456 int idx_vrfview = 0;
7457 int idx_ipv6_prefix = 0;
7458 safi_t safi = SAFI_UNICAST;
7459 char *prefix = argv_find(argv, argc, "X:X::X:X/M", &idx_ipv6_prefix) ?
7460 argv[idx_ipv6_prefix]->arg : NULL;
7461 char *vrfview = NULL;
7462
7463 /* [<view|vrf> VIEWVRFNAME] */
7464 if (argv_find(argv, argc, "vrf", &idx_vrfview)) {
7465 vrfview = argv[idx_vrfview + 1]->arg;
7466 if (vrfview && strmatch(vrfview, VRF_DEFAULT_NAME))
7467 vrfview = NULL;
7468 } else if (argv_find(argv, argc, "view", &idx_vrfview)) {
7469 /* [<view> VIEWVRFNAME] */
7470 vrfview = argv[idx_vrfview + 1]->arg;
7471 }
7472 argv_find_and_parse_safi(argv, argc, &idx_safi, &safi);
7473
7474 return bgp_clear_prefix(
7475 vty, vrfview, prefix,
7476 AFI_IP6, safi, NULL);
7477 }
7478
7479 DEFUN (show_bgp_views,
7480 show_bgp_views_cmd,
7481 "show [ip] bgp views",
7482 SHOW_STR
7483 IP_STR
7484 BGP_STR
7485 "Show the defined BGP views\n")
7486 {
7487 struct list *inst = bm->bgp;
7488 struct listnode *node;
7489 struct bgp *bgp;
7490
7491 if (!bgp_option_check(BGP_OPT_MULTIPLE_INSTANCE)) {
7492 vty_out(vty, "BGP Multiple Instance is not enabled\n");
7493 return CMD_WARNING;
7494 }
7495
7496 vty_out(vty, "Defined BGP views:\n");
7497 for (ALL_LIST_ELEMENTS_RO(inst, node, bgp)) {
7498 /* Skip VRFs. */
7499 if (bgp->inst_type == BGP_INSTANCE_TYPE_VRF)
7500 continue;
7501 vty_out(vty, "\t%s (AS%u)\n", bgp->name ? bgp->name : "(null)",
7502 bgp->as);
7503 }
7504
7505 return CMD_SUCCESS;
7506 }
7507
7508 DEFUN (show_bgp_vrfs,
7509 show_bgp_vrfs_cmd,
7510 "show [ip] bgp vrfs [json]",
7511 SHOW_STR
7512 IP_STR
7513 BGP_STR
7514 "Show BGP VRFs\n"
7515 JSON_STR)
7516 {
7517 char buf[ETHER_ADDR_STRLEN];
7518 struct list *inst = bm->bgp;
7519 struct listnode *node;
7520 struct bgp *bgp;
7521 bool uj = use_json(argc, argv);
7522 json_object *json = NULL;
7523 json_object *json_vrfs = NULL;
7524 int count = 0;
7525
7526 if (!bgp_option_check(BGP_OPT_MULTIPLE_INSTANCE)) {
7527 vty_out(vty, "BGP Multiple Instance is not enabled\n");
7528 return CMD_WARNING;
7529 }
7530
7531 if (uj) {
7532 json = json_object_new_object();
7533 json_vrfs = json_object_new_object();
7534 }
7535
7536 for (ALL_LIST_ELEMENTS_RO(inst, node, bgp)) {
7537 const char *name, *type;
7538 struct peer *peer;
7539 struct listnode *node2, *nnode2;
7540 int peers_cfg, peers_estb;
7541 json_object *json_vrf = NULL;
7542
7543 /* Skip Views. */
7544 if (bgp->inst_type == BGP_INSTANCE_TYPE_VIEW)
7545 continue;
7546
7547 count++;
7548 if (!uj && count == 1)
7549 vty_out(vty,
7550 "%4s %-5s %-16s %9s %10s %-37s %-10s %-15s\n",
7551 "Type", "Id", "routerId", "#PeersVfg",
7552 "#PeersEstb", "Name", "L3-VNI", "Rmac");
7553
7554 peers_cfg = peers_estb = 0;
7555 if (uj)
7556 json_vrf = json_object_new_object();
7557
7558
7559 for (ALL_LIST_ELEMENTS(bgp->peer, node2, nnode2, peer)) {
7560 if (!CHECK_FLAG(peer->flags, PEER_FLAG_CONFIG_NODE))
7561 continue;
7562 peers_cfg++;
7563 if (peer->status == Established)
7564 peers_estb++;
7565 }
7566
7567 if (bgp->inst_type == BGP_INSTANCE_TYPE_DEFAULT) {
7568 name = VRF_DEFAULT_NAME;
7569 type = "DFLT";
7570 } else {
7571 name = bgp->name;
7572 type = "VRF";
7573 }
7574
7575
7576 if (uj) {
7577 int64_t vrf_id_ui = (bgp->vrf_id == VRF_UNKNOWN)
7578 ? -1
7579 : (int64_t)bgp->vrf_id;
7580 json_object_string_add(json_vrf, "type", type);
7581 json_object_int_add(json_vrf, "vrfId", vrf_id_ui);
7582 json_object_string_add(json_vrf, "routerId",
7583 inet_ntoa(bgp->router_id));
7584 json_object_int_add(json_vrf, "numConfiguredPeers",
7585 peers_cfg);
7586 json_object_int_add(json_vrf, "numEstablishedPeers",
7587 peers_estb);
7588
7589 json_object_int_add(json_vrf, "l3vni", bgp->l3vni);
7590 json_object_string_add(
7591 json_vrf, "rmac",
7592 prefix_mac2str(&bgp->rmac, buf, sizeof(buf)));
7593 json_object_object_add(json_vrfs, name, json_vrf);
7594 } else
7595 vty_out(vty,
7596 "%4s %-5d %-16s %9u %10u %-37s %-10u %-15s\n",
7597 type,
7598 bgp->vrf_id == VRF_UNKNOWN ? -1
7599 : (int)bgp->vrf_id,
7600 inet_ntoa(bgp->router_id), peers_cfg,
7601 peers_estb, name, bgp->l3vni,
7602 prefix_mac2str(&bgp->rmac, buf, sizeof(buf)));
7603 }
7604
7605 if (uj) {
7606 json_object_object_add(json, "vrfs", json_vrfs);
7607
7608 json_object_int_add(json, "totalVrfs", count);
7609
7610 vty_out(vty, "%s\n", json_object_to_json_string_ext(
7611 json, JSON_C_TO_STRING_PRETTY));
7612 json_object_free(json);
7613 } else {
7614 if (count)
7615 vty_out(vty,
7616 "\nTotal number of VRFs (including default): %d\n",
7617 count);
7618 }
7619
7620 return CMD_SUCCESS;
7621 }
7622
7623 DEFUN (show_bgp_mac_hash,
7624 show_bgp_mac_hash_cmd,
7625 "show bgp mac hash",
7626 SHOW_STR
7627 BGP_STR
7628 "Mac Address\n"
7629 "Mac Address database\n")
7630 {
7631 bgp_mac_dump_table(vty);
7632
7633 return CMD_SUCCESS;
7634 }
7635
7636 static void show_tip_entry(struct hash_bucket *bucket, void *args)
7637 {
7638 struct vty *vty = (struct vty *)args;
7639 struct tip_addr *tip = (struct tip_addr *)bucket->data;
7640
7641 vty_out(vty, "addr: %s, count: %d\n", inet_ntoa(tip->addr),
7642 tip->refcnt);
7643 }
7644
7645 static void bgp_show_martian_nexthops(struct vty *vty, struct bgp *bgp)
7646 {
7647 vty_out(vty, "self nexthop database:\n");
7648 bgp_nexthop_show_address_hash(vty, bgp);
7649
7650 vty_out(vty, "Tunnel-ip database:\n");
7651 hash_iterate(bgp->tip_hash,
7652 (void (*)(struct hash_bucket *, void *))show_tip_entry,
7653 vty);
7654 }
7655
7656 DEFUN(show_bgp_martian_nexthop_db, show_bgp_martian_nexthop_db_cmd,
7657 "show bgp [<view|vrf> VIEWVRFNAME] martian next-hop",
7658 SHOW_STR BGP_STR BGP_INSTANCE_HELP_STR
7659 "martian next-hops\n"
7660 "martian next-hop database\n")
7661 {
7662 struct bgp *bgp = NULL;
7663 int idx = 0;
7664 char *name = NULL;
7665
7666 /* [<vrf> VIEWVRFNAME] */
7667 if (argv_find(argv, argc, "vrf", &idx)) {
7668 name = argv[idx + 1]->arg;
7669 if (name && strmatch(name, VRF_DEFAULT_NAME))
7670 name = NULL;
7671 } else if (argv_find(argv, argc, "view", &idx))
7672 /* [<view> VIEWVRFNAME] */
7673 name = argv[idx + 1]->arg;
7674 if (name)
7675 bgp = bgp_lookup_by_name(name);
7676 else
7677 bgp = bgp_get_default();
7678
7679 if (!bgp) {
7680 vty_out(vty, "%% No BGP process is configured\n");
7681 return CMD_WARNING;
7682 }
7683 bgp_show_martian_nexthops(vty, bgp);
7684
7685 return CMD_SUCCESS;
7686 }
7687
7688 DEFUN (show_bgp_memory,
7689 show_bgp_memory_cmd,
7690 "show [ip] bgp memory",
7691 SHOW_STR
7692 IP_STR
7693 BGP_STR
7694 "Global BGP memory statistics\n")
7695 {
7696 char memstrbuf[MTYPE_MEMSTR_LEN];
7697 unsigned long count;
7698
7699 /* RIB related usage stats */
7700 count = mtype_stats_alloc(MTYPE_BGP_NODE);
7701 vty_out(vty, "%ld RIB nodes, using %s of memory\n", count,
7702 mtype_memstr(memstrbuf, sizeof(memstrbuf),
7703 count * sizeof(struct bgp_node)));
7704
7705 count = mtype_stats_alloc(MTYPE_BGP_ROUTE);
7706 vty_out(vty, "%ld BGP routes, using %s of memory\n", count,
7707 mtype_memstr(memstrbuf, sizeof(memstrbuf),
7708 count * sizeof(struct bgp_path_info)));
7709 if ((count = mtype_stats_alloc(MTYPE_BGP_ROUTE_EXTRA)))
7710 vty_out(vty, "%ld BGP route ancillaries, using %s of memory\n",
7711 count,
7712 mtype_memstr(
7713 memstrbuf, sizeof(memstrbuf),
7714 count * sizeof(struct bgp_path_info_extra)));
7715
7716 if ((count = mtype_stats_alloc(MTYPE_BGP_STATIC)))
7717 vty_out(vty, "%ld Static routes, using %s of memory\n", count,
7718 mtype_memstr(memstrbuf, sizeof(memstrbuf),
7719 count * sizeof(struct bgp_static)));
7720
7721 if ((count = mtype_stats_alloc(MTYPE_BGP_PACKET)))
7722 vty_out(vty, "%ld Packets, using %s of memory\n", count,
7723 mtype_memstr(memstrbuf, sizeof(memstrbuf),
7724 count * sizeof(struct bpacket)));
7725
7726 /* Adj-In/Out */
7727 if ((count = mtype_stats_alloc(MTYPE_BGP_ADJ_IN)))
7728 vty_out(vty, "%ld Adj-In entries, using %s of memory\n", count,
7729 mtype_memstr(memstrbuf, sizeof(memstrbuf),
7730 count * sizeof(struct bgp_adj_in)));
7731 if ((count = mtype_stats_alloc(MTYPE_BGP_ADJ_OUT)))
7732 vty_out(vty, "%ld Adj-Out entries, using %s of memory\n", count,
7733 mtype_memstr(memstrbuf, sizeof(memstrbuf),
7734 count * sizeof(struct bgp_adj_out)));
7735
7736 if ((count = mtype_stats_alloc(MTYPE_BGP_NEXTHOP_CACHE)))
7737 vty_out(vty, "%ld Nexthop cache entries, using %s of memory\n",
7738 count,
7739 mtype_memstr(memstrbuf, sizeof(memstrbuf),
7740 count * sizeof(struct bgp_nexthop_cache)));
7741
7742 if ((count = mtype_stats_alloc(MTYPE_BGP_DAMP_INFO)))
7743 vty_out(vty, "%ld Dampening entries, using %s of memory\n",
7744 count,
7745 mtype_memstr(memstrbuf, sizeof(memstrbuf),
7746 count * sizeof(struct bgp_damp_info)));
7747
7748 /* Attributes */
7749 count = attr_count();
7750 vty_out(vty, "%ld BGP attributes, using %s of memory\n", count,
7751 mtype_memstr(memstrbuf, sizeof(memstrbuf),
7752 count * sizeof(struct attr)));
7753
7754 if ((count = attr_unknown_count()))
7755 vty_out(vty, "%ld unknown attributes\n", count);
7756
7757 /* AS_PATH attributes */
7758 count = aspath_count();
7759 vty_out(vty, "%ld BGP AS-PATH entries, using %s of memory\n", count,
7760 mtype_memstr(memstrbuf, sizeof(memstrbuf),
7761 count * sizeof(struct aspath)));
7762
7763 count = mtype_stats_alloc(MTYPE_AS_SEG);
7764 vty_out(vty, "%ld BGP AS-PATH segments, using %s of memory\n", count,
7765 mtype_memstr(memstrbuf, sizeof(memstrbuf),
7766 count * sizeof(struct assegment)));
7767
7768 /* Other attributes */
7769 if ((count = community_count()))
7770 vty_out(vty, "%ld BGP community entries, using %s of memory\n",
7771 count, mtype_memstr(memstrbuf, sizeof(memstrbuf),
7772 count * sizeof(struct community)));
7773 if ((count = mtype_stats_alloc(MTYPE_ECOMMUNITY)))
7774 vty_out(vty, "%ld BGP community entries, using %s of memory\n",
7775 count, mtype_memstr(memstrbuf, sizeof(memstrbuf),
7776 count * sizeof(struct ecommunity)));
7777 if ((count = mtype_stats_alloc(MTYPE_LCOMMUNITY)))
7778 vty_out(vty,
7779 "%ld BGP large-community entries, using %s of memory\n",
7780 count, mtype_memstr(memstrbuf, sizeof(memstrbuf),
7781 count * sizeof(struct lcommunity)));
7782
7783 if ((count = mtype_stats_alloc(MTYPE_CLUSTER)))
7784 vty_out(vty, "%ld Cluster lists, using %s of memory\n", count,
7785 mtype_memstr(memstrbuf, sizeof(memstrbuf),
7786 count * sizeof(struct cluster_list)));
7787
7788 /* Peer related usage */
7789 count = mtype_stats_alloc(MTYPE_BGP_PEER);
7790 vty_out(vty, "%ld peers, using %s of memory\n", count,
7791 mtype_memstr(memstrbuf, sizeof(memstrbuf),
7792 count * sizeof(struct peer)));
7793
7794 if ((count = mtype_stats_alloc(MTYPE_PEER_GROUP)))
7795 vty_out(vty, "%ld peer groups, using %s of memory\n", count,
7796 mtype_memstr(memstrbuf, sizeof(memstrbuf),
7797 count * sizeof(struct peer_group)));
7798
7799 /* Other */
7800 if ((count = mtype_stats_alloc(MTYPE_HASH)))
7801 vty_out(vty, "%ld hash tables, using %s of memory\n", count,
7802 mtype_memstr(memstrbuf, sizeof(memstrbuf),
7803 count * sizeof(struct hash)));
7804 if ((count = mtype_stats_alloc(MTYPE_HASH_BACKET)))
7805 vty_out(vty, "%ld hash buckets, using %s of memory\n", count,
7806 mtype_memstr(memstrbuf, sizeof(memstrbuf),
7807 count * sizeof(struct hash_bucket)));
7808 if ((count = mtype_stats_alloc(MTYPE_BGP_REGEXP)))
7809 vty_out(vty, "%ld compiled regexes, using %s of memory\n",
7810 count, mtype_memstr(memstrbuf, sizeof(memstrbuf),
7811 count * sizeof(regex_t)));
7812 return CMD_SUCCESS;
7813 }
7814
7815 static void bgp_show_bestpath_json(struct bgp *bgp, json_object *json)
7816 {
7817 json_object *bestpath = json_object_new_object();
7818
7819 if (bgp_flag_check(bgp, BGP_FLAG_ASPATH_IGNORE))
7820 json_object_string_add(bestpath, "asPath", "ignore");
7821
7822 if (bgp_flag_check(bgp, BGP_FLAG_ASPATH_CONFED))
7823 json_object_string_add(bestpath, "asPath", "confed");
7824
7825 if (bgp_flag_check(bgp, BGP_FLAG_ASPATH_MULTIPATH_RELAX)) {
7826 if (bgp_flag_check(bgp, BGP_FLAG_MULTIPATH_RELAX_AS_SET))
7827 json_object_string_add(bestpath, "multiPathRelax",
7828 "as-set");
7829 else
7830 json_object_string_add(bestpath, "multiPathRelax",
7831 "true");
7832 } else
7833 json_object_string_add(bestpath, "multiPathRelax", "false");
7834
7835 if (bgp_flag_check(bgp, BGP_FLAG_COMPARE_ROUTER_ID))
7836 json_object_string_add(bestpath, "compareRouterId", "true");
7837 if (bgp_flag_check(bgp, BGP_FLAG_MED_CONFED)
7838 || bgp_flag_check(bgp, BGP_FLAG_MED_MISSING_AS_WORST)) {
7839 if (bgp_flag_check(bgp, BGP_FLAG_MED_CONFED))
7840 json_object_string_add(bestpath, "med", "confed");
7841 if (bgp_flag_check(bgp, BGP_FLAG_MED_MISSING_AS_WORST))
7842 json_object_string_add(bestpath, "med",
7843 "missing-as-worst");
7844 else
7845 json_object_string_add(bestpath, "med", "true");
7846 }
7847
7848 json_object_object_add(json, "bestPath", bestpath);
7849 }
7850
7851 /* Show BGP peer's summary information. */
7852 static int bgp_show_summary(struct vty *vty, struct bgp *bgp, int afi, int safi,
7853 bool use_json, json_object *json)
7854 {
7855 struct peer *peer;
7856 struct listnode *node, *nnode;
7857 unsigned int count = 0, dn_count = 0;
7858 char timebuf[BGP_UPTIME_LEN], dn_flag[2];
7859 char neighbor_buf[VTY_BUFSIZ];
7860 int neighbor_col_default_width = 16;
7861 int len;
7862 int max_neighbor_width = 0;
7863 int pfx_rcd_safi;
7864 json_object *json_peer = NULL;
7865 json_object *json_peers = NULL;
7866 struct peer_af *paf;
7867
7868 /* labeled-unicast routes are installed in the unicast table so in order
7869 * to
7870 * display the correct PfxRcd value we must look at SAFI_UNICAST
7871 */
7872 if (safi == SAFI_LABELED_UNICAST)
7873 pfx_rcd_safi = SAFI_UNICAST;
7874 else
7875 pfx_rcd_safi = safi;
7876
7877 if (use_json) {
7878 if (json == NULL)
7879 json = json_object_new_object();
7880
7881 json_peers = json_object_new_object();
7882 } else {
7883 /* Loop over all neighbors that will be displayed to determine
7884 * how many
7885 * characters are needed for the Neighbor column
7886 */
7887 for (ALL_LIST_ELEMENTS(bgp->peer, node, nnode, peer)) {
7888 if (!CHECK_FLAG(peer->flags, PEER_FLAG_CONFIG_NODE))
7889 continue;
7890
7891 if (peer->afc[afi][safi]) {
7892 memset(dn_flag, '\0', sizeof(dn_flag));
7893 if (peer_dynamic_neighbor(peer))
7894 dn_flag[0] = '*';
7895
7896 if (peer->hostname
7897 && bgp_flag_check(bgp,
7898 BGP_FLAG_SHOW_HOSTNAME))
7899 sprintf(neighbor_buf, "%s%s(%s) ",
7900 dn_flag, peer->hostname,
7901 peer->host);
7902 else
7903 sprintf(neighbor_buf, "%s%s ", dn_flag,
7904 peer->host);
7905
7906 len = strlen(neighbor_buf);
7907
7908 if (len > max_neighbor_width)
7909 max_neighbor_width = len;
7910 }
7911 }
7912
7913 /* Originally we displayed the Neighbor column as 16
7914 * characters wide so make that the default
7915 */
7916 if (max_neighbor_width < neighbor_col_default_width)
7917 max_neighbor_width = neighbor_col_default_width;
7918 }
7919
7920 for (ALL_LIST_ELEMENTS(bgp->peer, node, nnode, peer)) {
7921 if (!CHECK_FLAG(peer->flags, PEER_FLAG_CONFIG_NODE))
7922 continue;
7923
7924 if (!peer->afc[afi][safi])
7925 continue;
7926
7927 if (!count) {
7928 unsigned long ents;
7929 char memstrbuf[MTYPE_MEMSTR_LEN];
7930 int64_t vrf_id_ui;
7931
7932 vrf_id_ui = (bgp->vrf_id == VRF_UNKNOWN)
7933 ? -1
7934 : (int64_t)bgp->vrf_id;
7935
7936 /* Usage summary and header */
7937 if (use_json) {
7938 json_object_string_add(
7939 json, "routerId",
7940 inet_ntoa(bgp->router_id));
7941 json_object_int_add(json, "as", bgp->as);
7942 json_object_int_add(json, "vrfId", vrf_id_ui);
7943 json_object_string_add(
7944 json, "vrfName",
7945 (bgp->inst_type
7946 == BGP_INSTANCE_TYPE_DEFAULT)
7947 ? VRF_DEFAULT_NAME
7948 : bgp->name);
7949 } else {
7950 vty_out(vty,
7951 "BGP router identifier %s, local AS number %u vrf-id %d",
7952 inet_ntoa(bgp->router_id), bgp->as,
7953 bgp->vrf_id == VRF_UNKNOWN
7954 ? -1
7955 : (int)bgp->vrf_id);
7956 vty_out(vty, "\n");
7957 }
7958
7959 if (bgp_update_delay_configured(bgp)) {
7960 if (use_json) {
7961 json_object_int_add(
7962 json, "updateDelayLimit",
7963 bgp->v_update_delay);
7964
7965 if (bgp->v_update_delay
7966 != bgp->v_establish_wait)
7967 json_object_int_add(
7968 json,
7969 "updateDelayEstablishWait",
7970 bgp->v_establish_wait);
7971
7972 if (bgp_update_delay_active(bgp)) {
7973 json_object_string_add(
7974 json,
7975 "updateDelayFirstNeighbor",
7976 bgp->update_delay_begin_time);
7977 json_object_boolean_true_add(
7978 json,
7979 "updateDelayInProgress");
7980 } else {
7981 if (bgp->update_delay_over) {
7982 json_object_string_add(
7983 json,
7984 "updateDelayFirstNeighbor",
7985 bgp->update_delay_begin_time);
7986 json_object_string_add(
7987 json,
7988 "updateDelayBestpathResumed",
7989 bgp->update_delay_end_time);
7990 json_object_string_add(
7991 json,
7992 "updateDelayZebraUpdateResume",
7993 bgp->update_delay_zebra_resume_time);
7994 json_object_string_add(
7995 json,
7996 "updateDelayPeerUpdateResume",
7997 bgp->update_delay_peers_resume_time);
7998 }
7999 }
8000 } else {
8001 vty_out(vty,
8002 "Read-only mode update-delay limit: %d seconds\n",
8003 bgp->v_update_delay);
8004 if (bgp->v_update_delay
8005 != bgp->v_establish_wait)
8006 vty_out(vty,
8007 " Establish wait: %d seconds\n",
8008 bgp->v_establish_wait);
8009
8010 if (bgp_update_delay_active(bgp)) {
8011 vty_out(vty,
8012 " First neighbor established: %s\n",
8013 bgp->update_delay_begin_time);
8014 vty_out(vty,
8015 " Delay in progress\n");
8016 } else {
8017 if (bgp->update_delay_over) {
8018 vty_out(vty,
8019 " First neighbor established: %s\n",
8020 bgp->update_delay_begin_time);
8021 vty_out(vty,
8022 " Best-paths resumed: %s\n",
8023 bgp->update_delay_end_time);
8024 vty_out(vty,
8025 " zebra update resumed: %s\n",
8026 bgp->update_delay_zebra_resume_time);
8027 vty_out(vty,
8028 " peers update resumed: %s\n",
8029 bgp->update_delay_peers_resume_time);
8030 }
8031 }
8032 }
8033 }
8034
8035 if (use_json) {
8036 if (bgp_maxmed_onstartup_configured(bgp)
8037 && bgp->maxmed_active)
8038 json_object_boolean_true_add(
8039 json, "maxMedOnStartup");
8040 if (bgp->v_maxmed_admin)
8041 json_object_boolean_true_add(
8042 json, "maxMedAdministrative");
8043
8044 json_object_int_add(
8045 json, "tableVersion",
8046 bgp_table_version(bgp->rib[afi][safi]));
8047
8048 ents = bgp_table_count(bgp->rib[afi][safi]);
8049 json_object_int_add(json, "ribCount", ents);
8050 json_object_int_add(
8051 json, "ribMemory",
8052 ents * sizeof(struct bgp_node));
8053
8054 ents = bgp->af_peer_count[afi][safi];
8055 json_object_int_add(json, "peerCount", ents);
8056 json_object_int_add(json, "peerMemory",
8057 ents * sizeof(struct peer));
8058
8059 if ((ents = listcount(bgp->group))) {
8060 json_object_int_add(
8061 json, "peerGroupCount", ents);
8062 json_object_int_add(
8063 json, "peerGroupMemory",
8064 ents * sizeof(struct
8065 peer_group));
8066 }
8067
8068 if (CHECK_FLAG(bgp->af_flags[afi][safi],
8069 BGP_CONFIG_DAMPENING))
8070 json_object_boolean_true_add(
8071 json, "dampeningEnabled");
8072 } else {
8073 if (bgp_maxmed_onstartup_configured(bgp)
8074 && bgp->maxmed_active)
8075 vty_out(vty,
8076 "Max-med on-startup active\n");
8077 if (bgp->v_maxmed_admin)
8078 vty_out(vty,
8079 "Max-med administrative active\n");
8080
8081 vty_out(vty, "BGP table version %" PRIu64 "\n",
8082 bgp_table_version(bgp->rib[afi][safi]));
8083
8084 ents = bgp_table_count(bgp->rib[afi][safi]);
8085 vty_out(vty,
8086 "RIB entries %ld, using %s of memory\n",
8087 ents,
8088 mtype_memstr(memstrbuf,
8089 sizeof(memstrbuf),
8090 ents * sizeof(struct
8091 bgp_node)));
8092
8093 /* Peer related usage */
8094 ents = bgp->af_peer_count[afi][safi];
8095 vty_out(vty, "Peers %ld, using %s of memory\n",
8096 ents,
8097 mtype_memstr(
8098 memstrbuf, sizeof(memstrbuf),
8099 ents * sizeof(struct peer)));
8100
8101 if ((ents = listcount(bgp->group)))
8102 vty_out(vty,
8103 "Peer groups %ld, using %s of memory\n",
8104 ents,
8105 mtype_memstr(
8106 memstrbuf,
8107 sizeof(memstrbuf),
8108 ents * sizeof(struct
8109 peer_group)));
8110
8111 if (CHECK_FLAG(bgp->af_flags[afi][safi],
8112 BGP_CONFIG_DAMPENING))
8113 vty_out(vty, "Dampening enabled.\n");
8114 vty_out(vty, "\n");
8115
8116 /* Subtract 8 here because 'Neighbor' is
8117 * 8 characters */
8118 vty_out(vty, "Neighbor");
8119 vty_out(vty, "%*s", max_neighbor_width - 8,
8120 " ");
8121 vty_out(vty,
8122 "V AS MsgRcvd MsgSent TblVer InQ OutQ Up/Down State/PfxRcd\n");
8123 }
8124 }
8125
8126 count++;
8127
8128 if (use_json) {
8129 json_peer = json_object_new_object();
8130
8131 if (peer_dynamic_neighbor(peer)) {
8132 dn_count++;
8133 json_object_boolean_true_add(json_peer,
8134 "dynamicPeer");
8135 }
8136
8137 if (peer->hostname)
8138 json_object_string_add(json_peer, "hostname",
8139 peer->hostname);
8140
8141 if (peer->domainname)
8142 json_object_string_add(json_peer, "domainname",
8143 peer->domainname);
8144
8145 json_object_int_add(json_peer, "remoteAs", peer->as);
8146 json_object_int_add(json_peer, "version", 4);
8147 json_object_int_add(json_peer, "msgRcvd",
8148 PEER_TOTAL_RX(peer));
8149 json_object_int_add(json_peer, "msgSent",
8150 PEER_TOTAL_TX(peer));
8151
8152 json_object_int_add(json_peer, "tableVersion",
8153 peer->version[afi][safi]);
8154 json_object_int_add(json_peer, "outq",
8155 peer->obuf->count);
8156 json_object_int_add(json_peer, "inq", 0);
8157 peer_uptime(peer->uptime, timebuf, BGP_UPTIME_LEN,
8158 use_json, json_peer);
8159
8160 /*
8161 * Adding "pfxRcd" field to match with the corresponding
8162 * CLI. "prefixReceivedCount" will be deprecated in
8163 * future.
8164 */
8165 json_object_int_add(json_peer, "prefixReceivedCount",
8166 peer->pcount[afi][pfx_rcd_safi]);
8167 json_object_int_add(json_peer, "pfxRcd",
8168 peer->pcount[afi][pfx_rcd_safi]);
8169
8170 paf = peer_af_find(peer, afi, pfx_rcd_safi);
8171 if (paf && PAF_SUBGRP(paf))
8172 json_object_int_add(json_peer,
8173 "pfxSnt",
8174 (PAF_SUBGRP(paf))->scount);
8175
8176 if (CHECK_FLAG(peer->flags, PEER_FLAG_SHUTDOWN))
8177 json_object_string_add(json_peer, "state",
8178 "Idle (Admin)");
8179 else if (peer->afc_recv[afi][safi])
8180 json_object_string_add(
8181 json_peer, "state",
8182 lookup_msg(bgp_status_msg, peer->status,
8183 NULL));
8184 else if (CHECK_FLAG(peer->sflags,
8185 PEER_STATUS_PREFIX_OVERFLOW))
8186 json_object_string_add(json_peer, "state",
8187 "Idle (PfxCt)");
8188 else
8189 json_object_string_add(
8190 json_peer, "state",
8191 lookup_msg(bgp_status_msg, peer->status,
8192 NULL));
8193
8194 if (peer->conf_if)
8195 json_object_string_add(json_peer, "idType",
8196 "interface");
8197 else if (peer->su.sa.sa_family == AF_INET)
8198 json_object_string_add(json_peer, "idType",
8199 "ipv4");
8200 else if (peer->su.sa.sa_family == AF_INET6)
8201 json_object_string_add(json_peer, "idType",
8202 "ipv6");
8203
8204 json_object_object_add(json_peers, peer->host,
8205 json_peer);
8206 } else {
8207 memset(dn_flag, '\0', sizeof(dn_flag));
8208 if (peer_dynamic_neighbor(peer)) {
8209 dn_count++;
8210 dn_flag[0] = '*';
8211 }
8212
8213 if (peer->hostname
8214 && bgp_flag_check(bgp, BGP_FLAG_SHOW_HOSTNAME))
8215 len = vty_out(vty, "%s%s(%s)", dn_flag,
8216 peer->hostname, peer->host);
8217 else
8218 len = vty_out(vty, "%s%s", dn_flag, peer->host);
8219
8220 /* pad the neighbor column with spaces */
8221 if (len < max_neighbor_width)
8222 vty_out(vty, "%*s", max_neighbor_width - len,
8223 " ");
8224
8225 vty_out(vty, "4 %10u %7u %7u %8" PRIu64 " %4d %4zd %8s",
8226 peer->as, PEER_TOTAL_RX(peer),
8227 PEER_TOTAL_TX(peer), peer->version[afi][safi],
8228 0, peer->obuf->count,
8229 peer_uptime(peer->uptime, timebuf,
8230 BGP_UPTIME_LEN, 0, NULL));
8231
8232 if (peer->status == Established)
8233 if (peer->afc_recv[afi][safi])
8234 vty_out(vty, " %12" PRIu32,
8235 peer->pcount[afi]
8236 [pfx_rcd_safi]);
8237 else
8238 vty_out(vty, " NoNeg");
8239 else {
8240 if (CHECK_FLAG(peer->flags, PEER_FLAG_SHUTDOWN))
8241 vty_out(vty, " Idle (Admin)");
8242 else if (CHECK_FLAG(
8243 peer->sflags,
8244 PEER_STATUS_PREFIX_OVERFLOW))
8245 vty_out(vty, " Idle (PfxCt)");
8246 else
8247 vty_out(vty, " %12s",
8248 lookup_msg(bgp_status_msg,
8249 peer->status, NULL));
8250 }
8251 vty_out(vty, "\n");
8252 }
8253 }
8254
8255 if (use_json) {
8256 json_object_object_add(json, "peers", json_peers);
8257
8258 json_object_int_add(json, "totalPeers", count);
8259 json_object_int_add(json, "dynamicPeers", dn_count);
8260
8261 bgp_show_bestpath_json(bgp, json);
8262
8263 vty_out(vty, "%s\n", json_object_to_json_string_ext(
8264 json, JSON_C_TO_STRING_PRETTY));
8265 json_object_free(json);
8266 } else {
8267 if (count)
8268 vty_out(vty, "\nTotal number of neighbors %d\n", count);
8269 else {
8270 vty_out(vty, "No %s neighbor is configured\n",
8271 afi_safi_print(afi, safi));
8272 }
8273
8274 if (dn_count) {
8275 vty_out(vty, "* - dynamic neighbor\n");
8276 vty_out(vty, "%d dynamic neighbor(s), limit %d\n",
8277 dn_count, bgp->dynamic_neighbors_limit);
8278 }
8279 }
8280
8281 return CMD_SUCCESS;
8282 }
8283
8284 static void bgp_show_summary_afi_safi(struct vty *vty, struct bgp *bgp, int afi,
8285 int safi, bool use_json,
8286 json_object *json)
8287 {
8288 int is_first = 1;
8289 int afi_wildcard = (afi == AFI_MAX);
8290 int safi_wildcard = (safi == SAFI_MAX);
8291 int is_wildcard = (afi_wildcard || safi_wildcard);
8292 bool nbr_output = false;
8293
8294 if (use_json && is_wildcard)
8295 vty_out(vty, "{\n");
8296 if (afi_wildcard)
8297 afi = 1; /* AFI_IP */
8298 while (afi < AFI_MAX) {
8299 if (safi_wildcard)
8300 safi = 1; /* SAFI_UNICAST */
8301 while (safi < SAFI_MAX) {
8302 if (bgp_afi_safi_peer_exists(bgp, afi, safi)) {
8303 nbr_output = true;
8304 if (is_wildcard) {
8305 /*
8306 * So limit output to those afi/safi
8307 * pairs that
8308 * actualy have something interesting in
8309 * them
8310 */
8311 if (use_json) {
8312 json = json_object_new_object();
8313
8314 if (!is_first)
8315 vty_out(vty, ",\n");
8316 else
8317 is_first = 0;
8318
8319 vty_out(vty, "\"%s\":",
8320 afi_safi_json(afi,
8321 safi));
8322 } else {
8323 vty_out(vty, "\n%s Summary:\n",
8324 afi_safi_print(afi,
8325 safi));
8326 }
8327 }
8328 bgp_show_summary(vty, bgp, afi, safi, use_json,
8329 json);
8330 }
8331 safi++;
8332 if (!safi_wildcard)
8333 safi = SAFI_MAX;
8334 }
8335 afi++;
8336 if (!afi_wildcard)
8337 afi = AFI_MAX;
8338 }
8339
8340 if (use_json && is_wildcard)
8341 vty_out(vty, "}\n");
8342 else if (!nbr_output) {
8343 if (use_json)
8344 vty_out(vty, "{}\n");
8345 else
8346 vty_out(vty, "%% No BGP neighbors found\n");
8347 }
8348 }
8349
8350 static void bgp_show_all_instances_summary_vty(struct vty *vty, afi_t afi,
8351 safi_t safi, bool use_json)
8352 {
8353 struct listnode *node, *nnode;
8354 struct bgp *bgp;
8355 json_object *json = NULL;
8356 int is_first = 1;
8357 bool nbr_output = false;
8358
8359 if (use_json)
8360 vty_out(vty, "{\n");
8361
8362 for (ALL_LIST_ELEMENTS(bm->bgp, node, nnode, bgp)) {
8363 nbr_output = true;
8364 if (use_json) {
8365 json = json_object_new_object();
8366
8367 if (!is_first)
8368 vty_out(vty, ",\n");
8369 else
8370 is_first = 0;
8371
8372 vty_out(vty, "\"%s\":",
8373 (bgp->inst_type == BGP_INSTANCE_TYPE_DEFAULT)
8374 ? VRF_DEFAULT_NAME
8375 : bgp->name);
8376 } else {
8377 vty_out(vty, "\nInstance %s:\n",
8378 (bgp->inst_type == BGP_INSTANCE_TYPE_DEFAULT)
8379 ? VRF_DEFAULT_NAME
8380 : bgp->name);
8381 }
8382 bgp_show_summary_afi_safi(vty, bgp, afi, safi, use_json, json);
8383 }
8384
8385 if (use_json)
8386 vty_out(vty, "}\n");
8387 else if (!nbr_output)
8388 vty_out(vty, "%% BGP instance not found\n");
8389 }
8390
8391 int bgp_show_summary_vty(struct vty *vty, const char *name, afi_t afi,
8392 safi_t safi, bool use_json)
8393 {
8394 struct bgp *bgp;
8395
8396 if (name) {
8397 if (strmatch(name, "all")) {
8398 bgp_show_all_instances_summary_vty(vty, afi, safi,
8399 use_json);
8400 return CMD_SUCCESS;
8401 } else {
8402 bgp = bgp_lookup_by_name(name);
8403
8404 if (!bgp) {
8405 if (use_json)
8406 vty_out(vty, "{}\n");
8407 else
8408 vty_out(vty,
8409 "%% BGP instance not found\n");
8410 return CMD_WARNING;
8411 }
8412
8413 bgp_show_summary_afi_safi(vty, bgp, afi, safi, use_json,
8414 NULL);
8415 return CMD_SUCCESS;
8416 }
8417 }
8418
8419 bgp = bgp_get_default();
8420
8421 if (bgp)
8422 bgp_show_summary_afi_safi(vty, bgp, afi, safi, use_json, NULL);
8423 else {
8424 if (use_json)
8425 vty_out(vty, "{}\n");
8426 else
8427 vty_out(vty, "%% BGP instance not found\n");
8428 return CMD_WARNING;
8429 }
8430
8431 return CMD_SUCCESS;
8432 }
8433
8434 /* `show [ip] bgp summary' commands. */
8435 DEFUN (show_ip_bgp_summary,
8436 show_ip_bgp_summary_cmd,
8437 "show [ip] bgp [<view|vrf> VIEWVRFNAME] ["BGP_AFI_CMD_STR" ["BGP_SAFI_WITH_LABEL_CMD_STR"]] summary [json]",
8438 SHOW_STR
8439 IP_STR
8440 BGP_STR
8441 BGP_INSTANCE_HELP_STR
8442 BGP_AFI_HELP_STR
8443 BGP_SAFI_WITH_LABEL_HELP_STR
8444 "Summary of BGP neighbor status\n"
8445 JSON_STR)
8446 {
8447 char *vrf = NULL;
8448 afi_t afi = AFI_MAX;
8449 safi_t safi = SAFI_MAX;
8450
8451 int idx = 0;
8452
8453 /* show [ip] bgp */
8454 if (argv_find(argv, argc, "ip", &idx))
8455 afi = AFI_IP;
8456 /* [<vrf> VIEWVRFNAME] */
8457 if (argv_find(argv, argc, "vrf", &idx)) {
8458 vrf = argv[idx + 1]->arg;
8459 if (vrf && strmatch(vrf, VRF_DEFAULT_NAME))
8460 vrf = NULL;
8461 } else if (argv_find(argv, argc, "view", &idx))
8462 /* [<view> VIEWVRFNAME] */
8463 vrf = argv[idx + 1]->arg;
8464 /* ["BGP_AFI_CMD_STR" ["BGP_SAFI_CMD_STR"]] */
8465 if (argv_find_and_parse_afi(argv, argc, &idx, &afi)) {
8466 argv_find_and_parse_safi(argv, argc, &idx, &safi);
8467 }
8468
8469 bool uj = use_json(argc, argv);
8470
8471 return bgp_show_summary_vty(vty, vrf, afi, safi, uj);
8472 }
8473
8474 const char *afi_safi_print(afi_t afi, safi_t safi)
8475 {
8476 if (afi == AFI_IP && safi == SAFI_UNICAST)
8477 return "IPv4 Unicast";
8478 else if (afi == AFI_IP && safi == SAFI_MULTICAST)
8479 return "IPv4 Multicast";
8480 else if (afi == AFI_IP && safi == SAFI_LABELED_UNICAST)
8481 return "IPv4 Labeled Unicast";
8482 else if (afi == AFI_IP && safi == SAFI_MPLS_VPN)
8483 return "IPv4 VPN";
8484 else if (afi == AFI_IP && safi == SAFI_ENCAP)
8485 return "IPv4 Encap";
8486 else if (afi == AFI_IP && safi == SAFI_FLOWSPEC)
8487 return "IPv4 Flowspec";
8488 else if (afi == AFI_IP6 && safi == SAFI_UNICAST)
8489 return "IPv6 Unicast";
8490 else if (afi == AFI_IP6 && safi == SAFI_MULTICAST)
8491 return "IPv6 Multicast";
8492 else if (afi == AFI_IP6 && safi == SAFI_LABELED_UNICAST)
8493 return "IPv6 Labeled Unicast";
8494 else if (afi == AFI_IP6 && safi == SAFI_MPLS_VPN)
8495 return "IPv6 VPN";
8496 else if (afi == AFI_IP6 && safi == SAFI_ENCAP)
8497 return "IPv6 Encap";
8498 else if (afi == AFI_IP6 && safi == SAFI_FLOWSPEC)
8499 return "IPv6 Flowspec";
8500 else if (afi == AFI_L2VPN && safi == SAFI_EVPN)
8501 return "L2VPN EVPN";
8502 else
8503 return "Unknown";
8504 }
8505
8506 /*
8507 * Please note that we have intentionally camelCased
8508 * the return strings here. So if you want
8509 * to use this function, please ensure you
8510 * are doing this within json output
8511 */
8512 const char *afi_safi_json(afi_t afi, safi_t safi)
8513 {
8514 if (afi == AFI_IP && safi == SAFI_UNICAST)
8515 return "ipv4Unicast";
8516 else if (afi == AFI_IP && safi == SAFI_MULTICAST)
8517 return "ipv4Multicast";
8518 else if (afi == AFI_IP && safi == SAFI_LABELED_UNICAST)
8519 return "ipv4LabeledUnicast";
8520 else if (afi == AFI_IP && safi == SAFI_MPLS_VPN)
8521 return "ipv4Vpn";
8522 else if (afi == AFI_IP && safi == SAFI_ENCAP)
8523 return "ipv4Encap";
8524 else if (afi == AFI_IP && safi == SAFI_FLOWSPEC)
8525 return "ipv4Flowspec";
8526 else if (afi == AFI_IP6 && safi == SAFI_UNICAST)
8527 return "ipv6Unicast";
8528 else if (afi == AFI_IP6 && safi == SAFI_MULTICAST)
8529 return "ipv6Multicast";
8530 else if (afi == AFI_IP6 && safi == SAFI_LABELED_UNICAST)
8531 return "ipv6LabeledUnicast";
8532 else if (afi == AFI_IP6 && safi == SAFI_MPLS_VPN)
8533 return "ipv6Vpn";
8534 else if (afi == AFI_IP6 && safi == SAFI_ENCAP)
8535 return "ipv6Encap";
8536 else if (afi == AFI_IP6 && safi == SAFI_FLOWSPEC)
8537 return "ipv6Flowspec";
8538 else if (afi == AFI_L2VPN && safi == SAFI_EVPN)
8539 return "l2VpnEvpn";
8540 else
8541 return "Unknown";
8542 }
8543
8544 /* Show BGP peer's information. */
8545 enum show_type { show_all, show_peer, show_ipv4_all, show_ipv6_all, show_ipv4_peer, show_ipv6_peer };
8546
8547 static void bgp_show_peer_afi_orf_cap(struct vty *vty, struct peer *p,
8548 afi_t afi, safi_t safi,
8549 uint16_t adv_smcap, uint16_t adv_rmcap,
8550 uint16_t rcv_smcap, uint16_t rcv_rmcap,
8551 bool use_json, json_object *json_pref)
8552 {
8553 /* Send-Mode */
8554 if (CHECK_FLAG(p->af_cap[afi][safi], adv_smcap)
8555 || CHECK_FLAG(p->af_cap[afi][safi], rcv_smcap)) {
8556 if (use_json) {
8557 if (CHECK_FLAG(p->af_cap[afi][safi], adv_smcap)
8558 && CHECK_FLAG(p->af_cap[afi][safi], rcv_smcap))
8559 json_object_string_add(json_pref, "sendMode",
8560 "advertisedAndReceived");
8561 else if (CHECK_FLAG(p->af_cap[afi][safi], adv_smcap))
8562 json_object_string_add(json_pref, "sendMode",
8563 "advertised");
8564 else if (CHECK_FLAG(p->af_cap[afi][safi], rcv_smcap))
8565 json_object_string_add(json_pref, "sendMode",
8566 "received");
8567 } else {
8568 vty_out(vty, " Send-mode: ");
8569 if (CHECK_FLAG(p->af_cap[afi][safi], adv_smcap))
8570 vty_out(vty, "advertised");
8571 if (CHECK_FLAG(p->af_cap[afi][safi], rcv_smcap))
8572 vty_out(vty, "%sreceived",
8573 CHECK_FLAG(p->af_cap[afi][safi],
8574 adv_smcap)
8575 ? ", "
8576 : "");
8577 vty_out(vty, "\n");
8578 }
8579 }
8580
8581 /* Receive-Mode */
8582 if (CHECK_FLAG(p->af_cap[afi][safi], adv_rmcap)
8583 || CHECK_FLAG(p->af_cap[afi][safi], rcv_rmcap)) {
8584 if (use_json) {
8585 if (CHECK_FLAG(p->af_cap[afi][safi], adv_rmcap)
8586 && CHECK_FLAG(p->af_cap[afi][safi], rcv_rmcap))
8587 json_object_string_add(json_pref, "recvMode",
8588 "advertisedAndReceived");
8589 else if (CHECK_FLAG(p->af_cap[afi][safi], adv_rmcap))
8590 json_object_string_add(json_pref, "recvMode",
8591 "advertised");
8592 else if (CHECK_FLAG(p->af_cap[afi][safi], rcv_rmcap))
8593 json_object_string_add(json_pref, "recvMode",
8594 "received");
8595 } else {
8596 vty_out(vty, " Receive-mode: ");
8597 if (CHECK_FLAG(p->af_cap[afi][safi], adv_rmcap))
8598 vty_out(vty, "advertised");
8599 if (CHECK_FLAG(p->af_cap[afi][safi], rcv_rmcap))
8600 vty_out(vty, "%sreceived",
8601 CHECK_FLAG(p->af_cap[afi][safi],
8602 adv_rmcap)
8603 ? ", "
8604 : "");
8605 vty_out(vty, "\n");
8606 }
8607 }
8608 }
8609
8610 static void bgp_show_peer_afi(struct vty *vty, struct peer *p, afi_t afi,
8611 safi_t safi, bool use_json,
8612 json_object *json_neigh)
8613 {
8614 struct bgp_filter *filter;
8615 struct peer_af *paf;
8616 char orf_pfx_name[BUFSIZ];
8617 int orf_pfx_count;
8618 json_object *json_af = NULL;
8619 json_object *json_prefA = NULL;
8620 json_object *json_prefB = NULL;
8621 json_object *json_addr = NULL;
8622
8623 if (use_json) {
8624 json_addr = json_object_new_object();
8625 json_af = json_object_new_object();
8626 filter = &p->filter[afi][safi];
8627
8628 if (peer_group_active(p))
8629 json_object_string_add(json_addr, "peerGroupMember",
8630 p->group->name);
8631
8632 paf = peer_af_find(p, afi, safi);
8633 if (paf && PAF_SUBGRP(paf)) {
8634 json_object_int_add(json_addr, "updateGroupId",
8635 PAF_UPDGRP(paf)->id);
8636 json_object_int_add(json_addr, "subGroupId",
8637 PAF_SUBGRP(paf)->id);
8638 json_object_int_add(json_addr, "packetQueueLength",
8639 bpacket_queue_virtual_length(paf));
8640 }
8641
8642 if (CHECK_FLAG(p->af_cap[afi][safi], PEER_CAP_ORF_PREFIX_SM_ADV)
8643 || CHECK_FLAG(p->af_cap[afi][safi],
8644 PEER_CAP_ORF_PREFIX_SM_RCV)
8645 || CHECK_FLAG(p->af_cap[afi][safi],
8646 PEER_CAP_ORF_PREFIX_RM_ADV)
8647 || CHECK_FLAG(p->af_cap[afi][safi],
8648 PEER_CAP_ORF_PREFIX_RM_RCV)) {
8649 json_object_int_add(json_af, "orfType",
8650 ORF_TYPE_PREFIX);
8651 json_prefA = json_object_new_object();
8652 bgp_show_peer_afi_orf_cap(vty, p, afi, safi,
8653 PEER_CAP_ORF_PREFIX_SM_ADV,
8654 PEER_CAP_ORF_PREFIX_RM_ADV,
8655 PEER_CAP_ORF_PREFIX_SM_RCV,
8656 PEER_CAP_ORF_PREFIX_RM_RCV,
8657 use_json, json_prefA);
8658 json_object_object_add(json_af, "orfPrefixList",
8659 json_prefA);
8660 }
8661
8662 if (CHECK_FLAG(p->af_cap[afi][safi], PEER_CAP_ORF_PREFIX_SM_ADV)
8663 || CHECK_FLAG(p->af_cap[afi][safi],
8664 PEER_CAP_ORF_PREFIX_SM_OLD_RCV)
8665 || CHECK_FLAG(p->af_cap[afi][safi],
8666 PEER_CAP_ORF_PREFIX_RM_ADV)
8667 || CHECK_FLAG(p->af_cap[afi][safi],
8668 PEER_CAP_ORF_PREFIX_RM_OLD_RCV)) {
8669 json_object_int_add(json_af, "orfOldType",
8670 ORF_TYPE_PREFIX_OLD);
8671 json_prefB = json_object_new_object();
8672 bgp_show_peer_afi_orf_cap(
8673 vty, p, afi, safi, PEER_CAP_ORF_PREFIX_SM_ADV,
8674 PEER_CAP_ORF_PREFIX_RM_ADV,
8675 PEER_CAP_ORF_PREFIX_SM_OLD_RCV,
8676 PEER_CAP_ORF_PREFIX_RM_OLD_RCV, use_json,
8677 json_prefB);
8678 json_object_object_add(json_af, "orfOldPrefixList",
8679 json_prefB);
8680 }
8681
8682 if (CHECK_FLAG(p->af_cap[afi][safi], PEER_CAP_ORF_PREFIX_SM_ADV)
8683 || CHECK_FLAG(p->af_cap[afi][safi],
8684 PEER_CAP_ORF_PREFIX_SM_RCV)
8685 || CHECK_FLAG(p->af_cap[afi][safi],
8686 PEER_CAP_ORF_PREFIX_SM_OLD_RCV)
8687 || CHECK_FLAG(p->af_cap[afi][safi],
8688 PEER_CAP_ORF_PREFIX_RM_ADV)
8689 || CHECK_FLAG(p->af_cap[afi][safi],
8690 PEER_CAP_ORF_PREFIX_RM_RCV)
8691 || CHECK_FLAG(p->af_cap[afi][safi],
8692 PEER_CAP_ORF_PREFIX_RM_OLD_RCV))
8693 json_object_object_add(json_addr, "afDependentCap",
8694 json_af);
8695 else
8696 json_object_free(json_af);
8697
8698 sprintf(orf_pfx_name, "%s.%d.%d", p->host, afi, safi);
8699 orf_pfx_count = prefix_bgp_show_prefix_list(
8700 NULL, afi, orf_pfx_name, use_json);
8701
8702 if (CHECK_FLAG(p->af_sflags[afi][safi],
8703 PEER_STATUS_ORF_PREFIX_SEND)
8704 || orf_pfx_count) {
8705 if (CHECK_FLAG(p->af_sflags[afi][safi],
8706 PEER_STATUS_ORF_PREFIX_SEND))
8707 json_object_boolean_true_add(json_neigh,
8708 "orfSent");
8709 if (orf_pfx_count)
8710 json_object_int_add(json_addr, "orfRecvCounter",
8711 orf_pfx_count);
8712 }
8713 if (CHECK_FLAG(p->af_sflags[afi][safi],
8714 PEER_STATUS_ORF_WAIT_REFRESH))
8715 json_object_string_add(
8716 json_addr, "orfFirstUpdate",
8717 "deferredUntilORFOrRouteRefreshRecvd");
8718
8719 if (CHECK_FLAG(p->af_flags[afi][safi],
8720 PEER_FLAG_REFLECTOR_CLIENT))
8721 json_object_boolean_true_add(json_addr,
8722 "routeReflectorClient");
8723 if (CHECK_FLAG(p->af_flags[afi][safi],
8724 PEER_FLAG_RSERVER_CLIENT))
8725 json_object_boolean_true_add(json_addr,
8726 "routeServerClient");
8727 if (CHECK_FLAG(p->af_flags[afi][safi], PEER_FLAG_SOFT_RECONFIG))
8728 json_object_boolean_true_add(json_addr,
8729 "inboundSoftConfigPermit");
8730
8731 if (CHECK_FLAG(p->af_flags[afi][safi],
8732 PEER_FLAG_REMOVE_PRIVATE_AS_ALL_REPLACE))
8733 json_object_boolean_true_add(
8734 json_addr,
8735 "privateAsNumsAllReplacedInUpdatesToNbr");
8736 else if (CHECK_FLAG(p->af_flags[afi][safi],
8737 PEER_FLAG_REMOVE_PRIVATE_AS_REPLACE))
8738 json_object_boolean_true_add(
8739 json_addr,
8740 "privateAsNumsReplacedInUpdatesToNbr");
8741 else if (CHECK_FLAG(p->af_flags[afi][safi],
8742 PEER_FLAG_REMOVE_PRIVATE_AS_ALL))
8743 json_object_boolean_true_add(
8744 json_addr,
8745 "privateAsNumsAllRemovedInUpdatesToNbr");
8746 else if (CHECK_FLAG(p->af_flags[afi][safi],
8747 PEER_FLAG_REMOVE_PRIVATE_AS))
8748 json_object_boolean_true_add(
8749 json_addr,
8750 "privateAsNumsRemovedInUpdatesToNbr");
8751
8752 if (p->addpath_type[afi][safi] != BGP_ADDPATH_NONE)
8753 json_object_boolean_true_add(
8754 json_addr,
8755 bgp_addpath_names(p->addpath_type[afi][safi])
8756 ->type_json_name);
8757
8758 if (CHECK_FLAG(p->af_flags[afi][safi], PEER_FLAG_AS_OVERRIDE))
8759 json_object_string_add(json_addr,
8760 "overrideASNsInOutboundUpdates",
8761 "ifAspathEqualRemoteAs");
8762
8763 if (CHECK_FLAG(p->af_flags[afi][safi], PEER_FLAG_NEXTHOP_SELF)
8764 || CHECK_FLAG(p->af_flags[afi][safi],
8765 PEER_FLAG_FORCE_NEXTHOP_SELF))
8766 json_object_boolean_true_add(json_addr,
8767 "routerAlwaysNextHop");
8768 if (CHECK_FLAG(p->af_flags[afi][safi],
8769 PEER_FLAG_AS_PATH_UNCHANGED))
8770 json_object_boolean_true_add(
8771 json_addr, "unchangedAsPathPropogatedToNbr");
8772 if (CHECK_FLAG(p->af_flags[afi][safi],
8773 PEER_FLAG_NEXTHOP_UNCHANGED))
8774 json_object_boolean_true_add(
8775 json_addr, "unchangedNextHopPropogatedToNbr");
8776 if (CHECK_FLAG(p->af_flags[afi][safi], PEER_FLAG_MED_UNCHANGED))
8777 json_object_boolean_true_add(
8778 json_addr, "unchangedMedPropogatedToNbr");
8779 if (CHECK_FLAG(p->af_flags[afi][safi], PEER_FLAG_SEND_COMMUNITY)
8780 || CHECK_FLAG(p->af_flags[afi][safi],
8781 PEER_FLAG_SEND_EXT_COMMUNITY)) {
8782 if (CHECK_FLAG(p->af_flags[afi][safi],
8783 PEER_FLAG_SEND_COMMUNITY)
8784 && CHECK_FLAG(p->af_flags[afi][safi],
8785 PEER_FLAG_SEND_EXT_COMMUNITY))
8786 json_object_string_add(json_addr,
8787 "commAttriSentToNbr",
8788 "extendedAndStandard");
8789 else if (CHECK_FLAG(p->af_flags[afi][safi],
8790 PEER_FLAG_SEND_EXT_COMMUNITY))
8791 json_object_string_add(json_addr,
8792 "commAttriSentToNbr",
8793 "extended");
8794 else
8795 json_object_string_add(json_addr,
8796 "commAttriSentToNbr",
8797 "standard");
8798 }
8799 if (CHECK_FLAG(p->af_flags[afi][safi],
8800 PEER_FLAG_DEFAULT_ORIGINATE)) {
8801 if (p->default_rmap[afi][safi].name)
8802 json_object_string_add(
8803 json_addr, "defaultRouteMap",
8804 p->default_rmap[afi][safi].name);
8805
8806 if (paf && PAF_SUBGRP(paf)
8807 && CHECK_FLAG(PAF_SUBGRP(paf)->sflags,
8808 SUBGRP_STATUS_DEFAULT_ORIGINATE))
8809 json_object_boolean_true_add(json_addr,
8810 "defaultSent");
8811 else
8812 json_object_boolean_true_add(json_addr,
8813 "defaultNotSent");
8814 }
8815
8816 if (afi == AFI_L2VPN && safi == SAFI_EVPN) {
8817 if (is_evpn_enabled())
8818 json_object_boolean_true_add(
8819 json_addr, "advertiseAllVnis");
8820 }
8821
8822 if (filter->plist[FILTER_IN].name
8823 || filter->dlist[FILTER_IN].name
8824 || filter->aslist[FILTER_IN].name
8825 || filter->map[RMAP_IN].name)
8826 json_object_boolean_true_add(json_addr,
8827 "inboundPathPolicyConfig");
8828 if (filter->plist[FILTER_OUT].name
8829 || filter->dlist[FILTER_OUT].name
8830 || filter->aslist[FILTER_OUT].name
8831 || filter->map[RMAP_OUT].name || filter->usmap.name)
8832 json_object_boolean_true_add(
8833 json_addr, "outboundPathPolicyConfig");
8834
8835 /* prefix-list */
8836 if (filter->plist[FILTER_IN].name)
8837 json_object_string_add(json_addr,
8838 "incomingUpdatePrefixFilterList",
8839 filter->plist[FILTER_IN].name);
8840 if (filter->plist[FILTER_OUT].name)
8841 json_object_string_add(json_addr,
8842 "outgoingUpdatePrefixFilterList",
8843 filter->plist[FILTER_OUT].name);
8844
8845 /* distribute-list */
8846 if (filter->dlist[FILTER_IN].name)
8847 json_object_string_add(
8848 json_addr, "incomingUpdateNetworkFilterList",
8849 filter->dlist[FILTER_IN].name);
8850 if (filter->dlist[FILTER_OUT].name)
8851 json_object_string_add(
8852 json_addr, "outgoingUpdateNetworkFilterList",
8853 filter->dlist[FILTER_OUT].name);
8854
8855 /* filter-list. */
8856 if (filter->aslist[FILTER_IN].name)
8857 json_object_string_add(json_addr,
8858 "incomingUpdateAsPathFilterList",
8859 filter->aslist[FILTER_IN].name);
8860 if (filter->aslist[FILTER_OUT].name)
8861 json_object_string_add(json_addr,
8862 "outgoingUpdateAsPathFilterList",
8863 filter->aslist[FILTER_OUT].name);
8864
8865 /* route-map. */
8866 if (filter->map[RMAP_IN].name)
8867 json_object_string_add(
8868 json_addr, "routeMapForIncomingAdvertisements",
8869 filter->map[RMAP_IN].name);
8870 if (filter->map[RMAP_OUT].name)
8871 json_object_string_add(
8872 json_addr, "routeMapForOutgoingAdvertisements",
8873 filter->map[RMAP_OUT].name);
8874
8875 /* ebgp-requires-policy (inbound) */
8876 if (p->bgp->ebgp_requires_policy == DEFAULT_EBGP_POLICY_ENABLED
8877 && !bgp_inbound_policy_exists(p, filter))
8878 json_object_string_add(
8879 json_addr, "inboundEbgpRequiresPolicy",
8880 "Inbound updates discarded due to missing policy");
8881
8882 /* ebgp-requires-policy (outbound) */
8883 if (p->bgp->ebgp_requires_policy == DEFAULT_EBGP_POLICY_ENABLED
8884 && (!bgp_outbound_policy_exists(p, filter)))
8885 json_object_string_add(
8886 json_addr, "outboundEbgpRequiresPolicy",
8887 "Outbound updates discarded due to missing policy");
8888
8889 /* unsuppress-map */
8890 if (filter->usmap.name)
8891 json_object_string_add(json_addr,
8892 "selectiveUnsuppressRouteMap",
8893 filter->usmap.name);
8894
8895 /* Receive prefix count */
8896 json_object_int_add(json_addr, "acceptedPrefixCounter",
8897 p->pcount[afi][safi]);
8898 if (paf && PAF_SUBGRP(paf))
8899 json_object_int_add(json_addr, "sentPrefixCounter",
8900 (PAF_SUBGRP(paf))->scount);
8901
8902 /* Maximum prefix */
8903 if (CHECK_FLAG(p->af_flags[afi][safi], PEER_FLAG_MAX_PREFIX)) {
8904 json_object_int_add(json_addr, "prefixAllowedMax",
8905 p->pmax[afi][safi]);
8906 if (CHECK_FLAG(p->af_flags[afi][safi],
8907 PEER_FLAG_MAX_PREFIX_WARNING))
8908 json_object_boolean_true_add(
8909 json_addr, "prefixAllowedMaxWarning");
8910 json_object_int_add(json_addr,
8911 "prefixAllowedWarningThresh",
8912 p->pmax_threshold[afi][safi]);
8913 if (p->pmax_restart[afi][safi])
8914 json_object_int_add(
8915 json_addr,
8916 "prefixAllowedRestartIntervalMsecs",
8917 p->pmax_restart[afi][safi] * 60000);
8918 }
8919 json_object_object_add(json_neigh, afi_safi_print(afi, safi),
8920 json_addr);
8921
8922 } else {
8923 filter = &p->filter[afi][safi];
8924
8925 vty_out(vty, " For address family: %s\n",
8926 afi_safi_print(afi, safi));
8927
8928 if (peer_group_active(p))
8929 vty_out(vty, " %s peer-group member\n",
8930 p->group->name);
8931
8932 paf = peer_af_find(p, afi, safi);
8933 if (paf && PAF_SUBGRP(paf)) {
8934 vty_out(vty, " Update group %" PRIu64
8935 ", subgroup %" PRIu64 "\n",
8936 PAF_UPDGRP(paf)->id, PAF_SUBGRP(paf)->id);
8937 vty_out(vty, " Packet Queue length %d\n",
8938 bpacket_queue_virtual_length(paf));
8939 } else {
8940 vty_out(vty, " Not part of any update group\n");
8941 }
8942 if (CHECK_FLAG(p->af_cap[afi][safi], PEER_CAP_ORF_PREFIX_SM_ADV)
8943 || CHECK_FLAG(p->af_cap[afi][safi],
8944 PEER_CAP_ORF_PREFIX_SM_RCV)
8945 || CHECK_FLAG(p->af_cap[afi][safi],
8946 PEER_CAP_ORF_PREFIX_SM_OLD_RCV)
8947 || CHECK_FLAG(p->af_cap[afi][safi],
8948 PEER_CAP_ORF_PREFIX_RM_ADV)
8949 || CHECK_FLAG(p->af_cap[afi][safi],
8950 PEER_CAP_ORF_PREFIX_RM_RCV)
8951 || CHECK_FLAG(p->af_cap[afi][safi],
8952 PEER_CAP_ORF_PREFIX_RM_OLD_RCV))
8953 vty_out(vty, " AF-dependant capabilities:\n");
8954
8955 if (CHECK_FLAG(p->af_cap[afi][safi], PEER_CAP_ORF_PREFIX_SM_ADV)
8956 || CHECK_FLAG(p->af_cap[afi][safi],
8957 PEER_CAP_ORF_PREFIX_SM_RCV)
8958 || CHECK_FLAG(p->af_cap[afi][safi],
8959 PEER_CAP_ORF_PREFIX_RM_ADV)
8960 || CHECK_FLAG(p->af_cap[afi][safi],
8961 PEER_CAP_ORF_PREFIX_RM_RCV)) {
8962 vty_out(vty,
8963 " Outbound Route Filter (ORF) type (%d) Prefix-list:\n",
8964 ORF_TYPE_PREFIX);
8965 bgp_show_peer_afi_orf_cap(
8966 vty, p, afi, safi, PEER_CAP_ORF_PREFIX_SM_ADV,
8967 PEER_CAP_ORF_PREFIX_RM_ADV,
8968 PEER_CAP_ORF_PREFIX_SM_RCV,
8969 PEER_CAP_ORF_PREFIX_RM_RCV, use_json, NULL);
8970 }
8971 if (CHECK_FLAG(p->af_cap[afi][safi], PEER_CAP_ORF_PREFIX_SM_ADV)
8972 || CHECK_FLAG(p->af_cap[afi][safi],
8973 PEER_CAP_ORF_PREFIX_SM_OLD_RCV)
8974 || CHECK_FLAG(p->af_cap[afi][safi],
8975 PEER_CAP_ORF_PREFIX_RM_ADV)
8976 || CHECK_FLAG(p->af_cap[afi][safi],
8977 PEER_CAP_ORF_PREFIX_RM_OLD_RCV)) {
8978 vty_out(vty,
8979 " Outbound Route Filter (ORF) type (%d) Prefix-list:\n",
8980 ORF_TYPE_PREFIX_OLD);
8981 bgp_show_peer_afi_orf_cap(
8982 vty, p, afi, safi, PEER_CAP_ORF_PREFIX_SM_ADV,
8983 PEER_CAP_ORF_PREFIX_RM_ADV,
8984 PEER_CAP_ORF_PREFIX_SM_OLD_RCV,
8985 PEER_CAP_ORF_PREFIX_RM_OLD_RCV, use_json, NULL);
8986 }
8987
8988 sprintf(orf_pfx_name, "%s.%d.%d", p->host, afi, safi);
8989 orf_pfx_count = prefix_bgp_show_prefix_list(
8990 NULL, afi, orf_pfx_name, use_json);
8991
8992 if (CHECK_FLAG(p->af_sflags[afi][safi],
8993 PEER_STATUS_ORF_PREFIX_SEND)
8994 || orf_pfx_count) {
8995 vty_out(vty, " Outbound Route Filter (ORF):");
8996 if (CHECK_FLAG(p->af_sflags[afi][safi],
8997 PEER_STATUS_ORF_PREFIX_SEND))
8998 vty_out(vty, " sent;");
8999 if (orf_pfx_count)
9000 vty_out(vty, " received (%d entries)",
9001 orf_pfx_count);
9002 vty_out(vty, "\n");
9003 }
9004 if (CHECK_FLAG(p->af_sflags[afi][safi],
9005 PEER_STATUS_ORF_WAIT_REFRESH))
9006 vty_out(vty,
9007 " First update is deferred until ORF or ROUTE-REFRESH is received\n");
9008
9009 if (CHECK_FLAG(p->af_flags[afi][safi],
9010 PEER_FLAG_REFLECTOR_CLIENT))
9011 vty_out(vty, " Route-Reflector Client\n");
9012 if (CHECK_FLAG(p->af_flags[afi][safi],
9013 PEER_FLAG_RSERVER_CLIENT))
9014 vty_out(vty, " Route-Server Client\n");
9015 if (CHECK_FLAG(p->af_flags[afi][safi], PEER_FLAG_SOFT_RECONFIG))
9016 vty_out(vty,
9017 " Inbound soft reconfiguration allowed\n");
9018
9019 if (CHECK_FLAG(p->af_flags[afi][safi],
9020 PEER_FLAG_REMOVE_PRIVATE_AS_ALL_REPLACE))
9021 vty_out(vty,
9022 " Private AS numbers (all) replaced in updates to this neighbor\n");
9023 else if (CHECK_FLAG(p->af_flags[afi][safi],
9024 PEER_FLAG_REMOVE_PRIVATE_AS_REPLACE))
9025 vty_out(vty,
9026 " Private AS numbers replaced in updates to this neighbor\n");
9027 else if (CHECK_FLAG(p->af_flags[afi][safi],
9028 PEER_FLAG_REMOVE_PRIVATE_AS_ALL))
9029 vty_out(vty,
9030 " Private AS numbers (all) removed in updates to this neighbor\n");
9031 else if (CHECK_FLAG(p->af_flags[afi][safi],
9032 PEER_FLAG_REMOVE_PRIVATE_AS))
9033 vty_out(vty,
9034 " Private AS numbers removed in updates to this neighbor\n");
9035
9036 if (p->addpath_type[afi][safi] != BGP_ADDPATH_NONE)
9037 vty_out(vty, " %s\n",
9038 bgp_addpath_names(p->addpath_type[afi][safi])
9039 ->human_description);
9040
9041 if (CHECK_FLAG(p->af_flags[afi][safi], PEER_FLAG_AS_OVERRIDE))
9042 vty_out(vty,
9043 " Override ASNs in outbound updates if aspath equals remote-as\n");
9044
9045 if (CHECK_FLAG(p->af_flags[afi][safi], PEER_FLAG_NEXTHOP_SELF)
9046 || CHECK_FLAG(p->af_flags[afi][safi],
9047 PEER_FLAG_FORCE_NEXTHOP_SELF))
9048 vty_out(vty, " NEXT_HOP is always this router\n");
9049 if (CHECK_FLAG(p->af_flags[afi][safi],
9050 PEER_FLAG_AS_PATH_UNCHANGED))
9051 vty_out(vty,
9052 " AS_PATH is propagated unchanged to this neighbor\n");
9053 if (CHECK_FLAG(p->af_flags[afi][safi],
9054 PEER_FLAG_NEXTHOP_UNCHANGED))
9055 vty_out(vty,
9056 " NEXT_HOP is propagated unchanged to this neighbor\n");
9057 if (CHECK_FLAG(p->af_flags[afi][safi], PEER_FLAG_MED_UNCHANGED))
9058 vty_out(vty,
9059 " MED is propagated unchanged to this neighbor\n");
9060 if (CHECK_FLAG(p->af_flags[afi][safi], PEER_FLAG_SEND_COMMUNITY)
9061 || CHECK_FLAG(p->af_flags[afi][safi],
9062 PEER_FLAG_SEND_EXT_COMMUNITY)
9063 || CHECK_FLAG(p->af_flags[afi][safi],
9064 PEER_FLAG_SEND_LARGE_COMMUNITY)) {
9065 vty_out(vty,
9066 " Community attribute sent to this neighbor");
9067 if (CHECK_FLAG(p->af_flags[afi][safi],
9068 PEER_FLAG_SEND_COMMUNITY)
9069 && CHECK_FLAG(p->af_flags[afi][safi],
9070 PEER_FLAG_SEND_EXT_COMMUNITY)
9071 && CHECK_FLAG(p->af_flags[afi][safi],
9072 PEER_FLAG_SEND_LARGE_COMMUNITY))
9073 vty_out(vty, "(all)\n");
9074 else if (CHECK_FLAG(p->af_flags[afi][safi],
9075 PEER_FLAG_SEND_LARGE_COMMUNITY))
9076 vty_out(vty, "(large)\n");
9077 else if (CHECK_FLAG(p->af_flags[afi][safi],
9078 PEER_FLAG_SEND_EXT_COMMUNITY))
9079 vty_out(vty, "(extended)\n");
9080 else
9081 vty_out(vty, "(standard)\n");
9082 }
9083 if (CHECK_FLAG(p->af_flags[afi][safi],
9084 PEER_FLAG_DEFAULT_ORIGINATE)) {
9085 vty_out(vty, " Default information originate,");
9086
9087 if (p->default_rmap[afi][safi].name)
9088 vty_out(vty, " default route-map %s%s,",
9089 p->default_rmap[afi][safi].map ? "*"
9090 : "",
9091 p->default_rmap[afi][safi].name);
9092 if (paf && PAF_SUBGRP(paf)
9093 && CHECK_FLAG(PAF_SUBGRP(paf)->sflags,
9094 SUBGRP_STATUS_DEFAULT_ORIGINATE))
9095 vty_out(vty, " default sent\n");
9096 else
9097 vty_out(vty, " default not sent\n");
9098 }
9099
9100 /* advertise-vni-all */
9101 if (afi == AFI_L2VPN && safi == SAFI_EVPN) {
9102 if (is_evpn_enabled())
9103 vty_out(vty, " advertise-all-vni\n");
9104 }
9105
9106 if (filter->plist[FILTER_IN].name
9107 || filter->dlist[FILTER_IN].name
9108 || filter->aslist[FILTER_IN].name
9109 || filter->map[RMAP_IN].name)
9110 vty_out(vty, " Inbound path policy configured\n");
9111 if (filter->plist[FILTER_OUT].name
9112 || filter->dlist[FILTER_OUT].name
9113 || filter->aslist[FILTER_OUT].name
9114 || filter->map[RMAP_OUT].name || filter->usmap.name)
9115 vty_out(vty, " Outbound path policy configured\n");
9116
9117 /* prefix-list */
9118 if (filter->plist[FILTER_IN].name)
9119 vty_out(vty,
9120 " Incoming update prefix filter list is %s%s\n",
9121 filter->plist[FILTER_IN].plist ? "*" : "",
9122 filter->plist[FILTER_IN].name);
9123 if (filter->plist[FILTER_OUT].name)
9124 vty_out(vty,
9125 " Outgoing update prefix filter list is %s%s\n",
9126 filter->plist[FILTER_OUT].plist ? "*" : "",
9127 filter->plist[FILTER_OUT].name);
9128
9129 /* distribute-list */
9130 if (filter->dlist[FILTER_IN].name)
9131 vty_out(vty,
9132 " Incoming update network filter list is %s%s\n",
9133 filter->dlist[FILTER_IN].alist ? "*" : "",
9134 filter->dlist[FILTER_IN].name);
9135 if (filter->dlist[FILTER_OUT].name)
9136 vty_out(vty,
9137 " Outgoing update network filter list is %s%s\n",
9138 filter->dlist[FILTER_OUT].alist ? "*" : "",
9139 filter->dlist[FILTER_OUT].name);
9140
9141 /* filter-list. */
9142 if (filter->aslist[FILTER_IN].name)
9143 vty_out(vty,
9144 " Incoming update AS path filter list is %s%s\n",
9145 filter->aslist[FILTER_IN].aslist ? "*" : "",
9146 filter->aslist[FILTER_IN].name);
9147 if (filter->aslist[FILTER_OUT].name)
9148 vty_out(vty,
9149 " Outgoing update AS path filter list is %s%s\n",
9150 filter->aslist[FILTER_OUT].aslist ? "*" : "",
9151 filter->aslist[FILTER_OUT].name);
9152
9153 /* route-map. */
9154 if (filter->map[RMAP_IN].name)
9155 vty_out(vty,
9156 " Route map for incoming advertisements is %s%s\n",
9157 filter->map[RMAP_IN].map ? "*" : "",
9158 filter->map[RMAP_IN].name);
9159 if (filter->map[RMAP_OUT].name)
9160 vty_out(vty,
9161 " Route map for outgoing advertisements is %s%s\n",
9162 filter->map[RMAP_OUT].map ? "*" : "",
9163 filter->map[RMAP_OUT].name);
9164
9165 /* ebgp-requires-policy (inbound) */
9166 if (p->bgp->ebgp_requires_policy == DEFAULT_EBGP_POLICY_ENABLED
9167 && !bgp_inbound_policy_exists(p, filter))
9168 vty_out(vty,
9169 " Inbound updates discarded due to missing policy\n");
9170
9171 /* ebgp-requires-policy (outbound) */
9172 if (p->bgp->ebgp_requires_policy == DEFAULT_EBGP_POLICY_ENABLED
9173 && !bgp_outbound_policy_exists(p, filter))
9174 vty_out(vty,
9175 " Outbound updates discarded due to missing policy\n");
9176
9177 /* unsuppress-map */
9178 if (filter->usmap.name)
9179 vty_out(vty,
9180 " Route map for selective unsuppress is %s%s\n",
9181 filter->usmap.map ? "*" : "",
9182 filter->usmap.name);
9183
9184 /* Receive prefix count */
9185 vty_out(vty, " %" PRIu32 " accepted prefixes\n",
9186 p->pcount[afi][safi]);
9187
9188 /* Maximum prefix */
9189 if (CHECK_FLAG(p->af_flags[afi][safi], PEER_FLAG_MAX_PREFIX)) {
9190 vty_out(vty,
9191 " Maximum prefixes allowed %" PRIu32 "%s\n",
9192 p->pmax[afi][safi],
9193 CHECK_FLAG(p->af_flags[afi][safi],
9194 PEER_FLAG_MAX_PREFIX_WARNING)
9195 ? " (warning-only)"
9196 : "");
9197 vty_out(vty, " Threshold for warning message %d%%",
9198 p->pmax_threshold[afi][safi]);
9199 if (p->pmax_restart[afi][safi])
9200 vty_out(vty, ", restart interval %d min",
9201 p->pmax_restart[afi][safi]);
9202 vty_out(vty, "\n");
9203 }
9204
9205 vty_out(vty, "\n");
9206 }
9207 }
9208
9209 static void bgp_show_peer(struct vty *vty, struct peer *p, bool use_json,
9210 json_object *json)
9211 {
9212 struct bgp *bgp;
9213 char buf1[PREFIX2STR_BUFFER], buf[SU_ADDRSTRLEN];
9214 char timebuf[BGP_UPTIME_LEN];
9215 char dn_flag[2];
9216 const char *subcode_str;
9217 const char *code_str;
9218 afi_t afi;
9219 safi_t safi;
9220 uint16_t i;
9221 uint8_t *msg;
9222 json_object *json_neigh = NULL;
9223 time_t epoch_tbuf;
9224
9225 bgp = p->bgp;
9226
9227 if (use_json)
9228 json_neigh = json_object_new_object();
9229
9230 memset(dn_flag, '\0', sizeof(dn_flag));
9231 if (!p->conf_if && peer_dynamic_neighbor(p))
9232 dn_flag[0] = '*';
9233
9234 if (!use_json) {
9235 if (p->conf_if) /* Configured interface name. */
9236 vty_out(vty, "BGP neighbor on %s: %s, ", p->conf_if,
9237 BGP_PEER_SU_UNSPEC(p)
9238 ? "None"
9239 : sockunion2str(&p->su, buf,
9240 SU_ADDRSTRLEN));
9241 else /* Configured IP address. */
9242 vty_out(vty, "BGP neighbor is %s%s, ", dn_flag,
9243 p->host);
9244 }
9245
9246 if (use_json) {
9247 if (p->conf_if && BGP_PEER_SU_UNSPEC(p))
9248 json_object_string_add(json_neigh, "bgpNeighborAddr",
9249 "none");
9250 else if (p->conf_if && !BGP_PEER_SU_UNSPEC(p))
9251 json_object_string_add(
9252 json_neigh, "bgpNeighborAddr",
9253 sockunion2str(&p->su, buf, SU_ADDRSTRLEN));
9254
9255 json_object_int_add(json_neigh, "remoteAs", p->as);
9256
9257 if (p->change_local_as)
9258 json_object_int_add(json_neigh, "localAs",
9259 p->change_local_as);
9260 else
9261 json_object_int_add(json_neigh, "localAs", p->local_as);
9262
9263 if (CHECK_FLAG(p->flags, PEER_FLAG_LOCAL_AS_NO_PREPEND))
9264 json_object_boolean_true_add(json_neigh,
9265 "localAsNoPrepend");
9266
9267 if (CHECK_FLAG(p->flags, PEER_FLAG_LOCAL_AS_REPLACE_AS))
9268 json_object_boolean_true_add(json_neigh,
9269 "localAsReplaceAs");
9270 } else {
9271 if ((p->as_type == AS_SPECIFIED) || (p->as_type == AS_EXTERNAL)
9272 || (p->as_type == AS_INTERNAL))
9273 vty_out(vty, "remote AS %u, ", p->as);
9274 else
9275 vty_out(vty, "remote AS Unspecified, ");
9276 vty_out(vty, "local AS %u%s%s, ",
9277 p->change_local_as ? p->change_local_as : p->local_as,
9278 CHECK_FLAG(p->flags, PEER_FLAG_LOCAL_AS_NO_PREPEND)
9279 ? " no-prepend"
9280 : "",
9281 CHECK_FLAG(p->flags, PEER_FLAG_LOCAL_AS_REPLACE_AS)
9282 ? " replace-as"
9283 : "");
9284 }
9285 /* peer type internal or confed-internal */
9286 if ((p->as == p->local_as) || (p->as_type == AS_INTERNAL)) {
9287 if (use_json) {
9288 if (CHECK_FLAG(bgp->config, BGP_CONFIG_CONFEDERATION))
9289 json_object_boolean_true_add(
9290 json_neigh, "nbrConfedInternalLink");
9291 else
9292 json_object_boolean_true_add(json_neigh,
9293 "nbrInternalLink");
9294 } else {
9295 if (CHECK_FLAG(bgp->config, BGP_CONFIG_CONFEDERATION))
9296 vty_out(vty, "confed-internal link\n");
9297 else
9298 vty_out(vty, "internal link\n");
9299 }
9300 /* peer type external or confed-external */
9301 } else if (p->as || (p->as_type == AS_EXTERNAL)) {
9302 if (use_json) {
9303 if (CHECK_FLAG(bgp->config, BGP_CONFIG_CONFEDERATION))
9304 json_object_boolean_true_add(
9305 json_neigh, "nbrConfedExternalLink");
9306 else
9307 json_object_boolean_true_add(json_neigh,
9308 "nbrExternalLink");
9309 } else {
9310 if (bgp_confederation_peers_check(bgp, p->as))
9311 vty_out(vty, "confed-external link\n");
9312 else
9313 vty_out(vty, "external link\n");
9314 }
9315 } else {
9316 if (use_json)
9317 json_object_boolean_true_add(json_neigh,
9318 "nbrUnspecifiedLink");
9319 else
9320 vty_out(vty, "unspecified link\n");
9321 }
9322
9323 /* Description. */
9324 if (p->desc) {
9325 if (use_json)
9326 json_object_string_add(json_neigh, "nbrDesc", p->desc);
9327 else
9328 vty_out(vty, " Description: %s\n", p->desc);
9329 }
9330
9331 if (p->hostname) {
9332 if (use_json) {
9333 if (p->hostname)
9334 json_object_string_add(json_neigh, "hostname",
9335 p->hostname);
9336
9337 if (p->domainname)
9338 json_object_string_add(json_neigh, "domainname",
9339 p->domainname);
9340 } else {
9341 if (p->domainname && (p->domainname[0] != '\0'))
9342 vty_out(vty, "Hostname: %s.%s\n", p->hostname,
9343 p->domainname);
9344 else
9345 vty_out(vty, "Hostname: %s\n", p->hostname);
9346 }
9347 }
9348
9349 /* Peer-group */
9350 if (p->group) {
9351 if (use_json) {
9352 json_object_string_add(json_neigh, "peerGroup",
9353 p->group->name);
9354
9355 if (dn_flag[0]) {
9356 struct prefix prefix, *range = NULL;
9357
9358 sockunion2hostprefix(&(p->su), &prefix);
9359 range = peer_group_lookup_dynamic_neighbor_range(
9360 p->group, &prefix);
9361
9362 if (range) {
9363 prefix2str(range, buf1, sizeof(buf1));
9364 json_object_string_add(
9365 json_neigh,
9366 "peerSubnetRangeGroup", buf1);
9367 }
9368 }
9369 } else {
9370 vty_out(vty,
9371 " Member of peer-group %s for session parameters\n",
9372 p->group->name);
9373
9374 if (dn_flag[0]) {
9375 struct prefix prefix, *range = NULL;
9376
9377 sockunion2hostprefix(&(p->su), &prefix);
9378 range = peer_group_lookup_dynamic_neighbor_range(
9379 p->group, &prefix);
9380
9381 if (range) {
9382 prefix2str(range, buf1, sizeof(buf1));
9383 vty_out(vty,
9384 " Belongs to the subnet range group: %s\n",
9385 buf1);
9386 }
9387 }
9388 }
9389 }
9390
9391 if (use_json) {
9392 /* Administrative shutdown. */
9393 if (CHECK_FLAG(p->flags, PEER_FLAG_SHUTDOWN))
9394 json_object_boolean_true_add(json_neigh,
9395 "adminShutDown");
9396
9397 /* BGP Version. */
9398 json_object_int_add(json_neigh, "bgpVersion", 4);
9399 json_object_string_add(
9400 json_neigh, "remoteRouterId",
9401 inet_ntop(AF_INET, &p->remote_id, buf1, sizeof(buf1)));
9402 json_object_string_add(
9403 json_neigh, "localRouterId",
9404 inet_ntop(AF_INET, &bgp->router_id, buf1,
9405 sizeof(buf1)));
9406
9407 /* Confederation */
9408 if (CHECK_FLAG(bgp->config, BGP_CONFIG_CONFEDERATION)
9409 && bgp_confederation_peers_check(bgp, p->as))
9410 json_object_boolean_true_add(json_neigh,
9411 "nbrCommonAdmin");
9412
9413 /* Status. */
9414 json_object_string_add(
9415 json_neigh, "bgpState",
9416 lookup_msg(bgp_status_msg, p->status, NULL));
9417
9418 if (p->status == Established) {
9419 time_t uptime;
9420
9421 uptime = bgp_clock();
9422 uptime -= p->uptime;
9423 epoch_tbuf = time(NULL) - uptime;
9424
9425 #if CONFDATE > 20200101
9426 CPP_NOTICE(
9427 "bgpTimerUp should be deprecated and can be removed now");
9428 #endif
9429 /*
9430 * bgpTimerUp was miliseconds that was accurate
9431 * up to 1 day, then the value returned
9432 * became garbage. So in order to provide
9433 * some level of backwards compatability,
9434 * we still provde the data, but now
9435 * we are returning the correct value
9436 * and also adding a new bgpTimerUpMsec
9437 * which will allow us to deprecate
9438 * this eventually
9439 */
9440 json_object_int_add(json_neigh, "bgpTimerUp",
9441 uptime * 1000);
9442 json_object_int_add(json_neigh, "bgpTimerUpMsec",
9443 uptime * 1000);
9444 json_object_string_add(json_neigh, "bgpTimerUpString",
9445 peer_uptime(p->uptime, timebuf,
9446 BGP_UPTIME_LEN, 0,
9447 NULL));
9448 json_object_int_add(json_neigh,
9449 "bgpTimerUpEstablishedEpoch",
9450 epoch_tbuf);
9451 }
9452
9453 else if (p->status == Active) {
9454 if (CHECK_FLAG(p->flags, PEER_FLAG_PASSIVE))
9455 json_object_string_add(json_neigh, "bgpStateIs",
9456 "passive");
9457 else if (CHECK_FLAG(p->sflags, PEER_STATUS_NSF_WAIT))
9458 json_object_string_add(json_neigh, "bgpStateIs",
9459 "passiveNSF");
9460 }
9461
9462 /* read timer */
9463 time_t uptime;
9464 struct tm *tm;
9465
9466 uptime = bgp_clock();
9467 uptime -= p->readtime;
9468 tm = gmtime(&uptime);
9469 json_object_int_add(json_neigh, "bgpTimerLastRead",
9470 (tm->tm_sec * 1000) + (tm->tm_min * 60000)
9471 + (tm->tm_hour * 3600000));
9472
9473 uptime = bgp_clock();
9474 uptime -= p->last_write;
9475 tm = gmtime(&uptime);
9476 json_object_int_add(json_neigh, "bgpTimerLastWrite",
9477 (tm->tm_sec * 1000) + (tm->tm_min * 60000)
9478 + (tm->tm_hour * 3600000));
9479
9480 uptime = bgp_clock();
9481 uptime -= p->update_time;
9482 tm = gmtime(&uptime);
9483 json_object_int_add(json_neigh, "bgpInUpdateElapsedTimeMsecs",
9484 (tm->tm_sec * 1000) + (tm->tm_min * 60000)
9485 + (tm->tm_hour * 3600000));
9486
9487 /* Configured timer values. */
9488 json_object_int_add(json_neigh, "bgpTimerHoldTimeMsecs",
9489 p->v_holdtime * 1000);
9490 json_object_int_add(json_neigh,
9491 "bgpTimerKeepAliveIntervalMsecs",
9492 p->v_keepalive * 1000);
9493 if (CHECK_FLAG(p->flags, PEER_FLAG_TIMER)) {
9494 json_object_int_add(json_neigh,
9495 "bgpTimerConfiguredHoldTimeMsecs",
9496 p->holdtime * 1000);
9497 json_object_int_add(
9498 json_neigh,
9499 "bgpTimerConfiguredKeepAliveIntervalMsecs",
9500 p->keepalive * 1000);
9501 } else if ((bgp->default_holdtime != BGP_DEFAULT_HOLDTIME)
9502 || (bgp->default_keepalive
9503 != BGP_DEFAULT_KEEPALIVE)) {
9504 json_object_int_add(json_neigh,
9505 "bgpTimerConfiguredHoldTimeMsecs",
9506 bgp->default_holdtime);
9507 json_object_int_add(
9508 json_neigh,
9509 "bgpTimerConfiguredKeepAliveIntervalMsecs",
9510 bgp->default_keepalive);
9511 }
9512 } else {
9513 /* Administrative shutdown. */
9514 if (CHECK_FLAG(p->flags, PEER_FLAG_SHUTDOWN))
9515 vty_out(vty, " Administratively shut down\n");
9516
9517 /* BGP Version. */
9518 vty_out(vty, " BGP version 4");
9519 vty_out(vty, ", remote router ID %s",
9520 inet_ntop(AF_INET, &p->remote_id, buf1, sizeof(buf1)));
9521 vty_out(vty, ", local router ID %s\n",
9522 inet_ntop(AF_INET, &bgp->router_id, buf1,
9523 sizeof(buf1)));
9524
9525 /* Confederation */
9526 if (CHECK_FLAG(bgp->config, BGP_CONFIG_CONFEDERATION)
9527 && bgp_confederation_peers_check(bgp, p->as))
9528 vty_out(vty,
9529 " Neighbor under common administration\n");
9530
9531 /* Status. */
9532 vty_out(vty, " BGP state = %s",
9533 lookup_msg(bgp_status_msg, p->status, NULL));
9534
9535 if (p->status == Established)
9536 vty_out(vty, ", up for %8s",
9537 peer_uptime(p->uptime, timebuf, BGP_UPTIME_LEN,
9538 0, NULL));
9539
9540 else if (p->status == Active) {
9541 if (CHECK_FLAG(p->flags, PEER_FLAG_PASSIVE))
9542 vty_out(vty, " (passive)");
9543 else if (CHECK_FLAG(p->sflags, PEER_STATUS_NSF_WAIT))
9544 vty_out(vty, " (NSF passive)");
9545 }
9546 vty_out(vty, "\n");
9547
9548 /* read timer */
9549 vty_out(vty, " Last read %s",
9550 peer_uptime(p->readtime, timebuf, BGP_UPTIME_LEN, 0,
9551 NULL));
9552 vty_out(vty, ", Last write %s\n",
9553 peer_uptime(p->last_write, timebuf, BGP_UPTIME_LEN, 0,
9554 NULL));
9555
9556 /* Configured timer values. */
9557 vty_out(vty,
9558 " Hold time is %d, keepalive interval is %d seconds\n",
9559 p->v_holdtime, p->v_keepalive);
9560 if (CHECK_FLAG(p->flags, PEER_FLAG_TIMER)) {
9561 vty_out(vty, " Configured hold time is %d",
9562 p->holdtime);
9563 vty_out(vty, ", keepalive interval is %d seconds\n",
9564 p->keepalive);
9565 } else if ((bgp->default_holdtime != BGP_DEFAULT_HOLDTIME)
9566 || (bgp->default_keepalive
9567 != BGP_DEFAULT_KEEPALIVE)) {
9568 vty_out(vty, " Configured hold time is %d",
9569 bgp->default_holdtime);
9570 vty_out(vty, ", keepalive interval is %d seconds\n",
9571 bgp->default_keepalive);
9572 }
9573 }
9574 /* Capability. */
9575 if (p->status == Established) {
9576 if (p->cap || p->afc_adv[AFI_IP][SAFI_UNICAST]
9577 || p->afc_recv[AFI_IP][SAFI_UNICAST]
9578 || p->afc_adv[AFI_IP][SAFI_MULTICAST]
9579 || p->afc_recv[AFI_IP][SAFI_MULTICAST]
9580 || p->afc_adv[AFI_IP6][SAFI_UNICAST]
9581 || p->afc_recv[AFI_IP6][SAFI_UNICAST]
9582 || p->afc_adv[AFI_IP6][SAFI_MULTICAST]
9583 || p->afc_recv[AFI_IP6][SAFI_MULTICAST]
9584 || p->afc_adv[AFI_IP6][SAFI_MPLS_VPN]
9585 || p->afc_recv[AFI_IP6][SAFI_MPLS_VPN]
9586 || p->afc_adv[AFI_IP6][SAFI_ENCAP]
9587 || p->afc_recv[AFI_IP6][SAFI_ENCAP]
9588 || p->afc_adv[AFI_IP6][SAFI_FLOWSPEC]
9589 || p->afc_recv[AFI_IP6][SAFI_FLOWSPEC]
9590 || p->afc_adv[AFI_IP][SAFI_ENCAP]
9591 || p->afc_recv[AFI_IP][SAFI_ENCAP]
9592 || p->afc_adv[AFI_IP][SAFI_FLOWSPEC]
9593 || p->afc_recv[AFI_IP][SAFI_FLOWSPEC]
9594 || p->afc_adv[AFI_IP][SAFI_MPLS_VPN]
9595 || p->afc_recv[AFI_IP][SAFI_MPLS_VPN]) {
9596 if (use_json) {
9597 json_object *json_cap = NULL;
9598
9599 json_cap = json_object_new_object();
9600
9601 /* AS4 */
9602 if (CHECK_FLAG(p->cap, PEER_CAP_AS4_RCV)
9603 || CHECK_FLAG(p->cap, PEER_CAP_AS4_ADV)) {
9604 if (CHECK_FLAG(p->cap, PEER_CAP_AS4_ADV)
9605 && CHECK_FLAG(p->cap,
9606 PEER_CAP_AS4_RCV))
9607 json_object_string_add(
9608 json_cap, "4byteAs",
9609 "advertisedAndReceived");
9610 else if (CHECK_FLAG(p->cap,
9611 PEER_CAP_AS4_ADV))
9612 json_object_string_add(
9613 json_cap, "4byteAs",
9614 "advertised");
9615 else if (CHECK_FLAG(p->cap,
9616 PEER_CAP_AS4_RCV))
9617 json_object_string_add(
9618 json_cap, "4byteAs",
9619 "received");
9620 }
9621
9622 /* AddPath */
9623 if (CHECK_FLAG(p->cap, PEER_CAP_ADDPATH_RCV)
9624 || CHECK_FLAG(p->cap,
9625 PEER_CAP_ADDPATH_ADV)) {
9626 json_object *json_add = NULL;
9627 const char *print_store;
9628
9629 json_add = json_object_new_object();
9630
9631 FOREACH_AFI_SAFI (afi, safi) {
9632 json_object *json_sub = NULL;
9633 json_sub =
9634 json_object_new_object();
9635 print_store = afi_safi_print(
9636 afi, safi);
9637
9638 if (CHECK_FLAG(
9639 p->af_cap[afi]
9640 [safi],
9641 PEER_CAP_ADDPATH_AF_TX_ADV)
9642 || CHECK_FLAG(
9643 p->af_cap[afi]
9644 [safi],
9645 PEER_CAP_ADDPATH_AF_TX_RCV)) {
9646 if (CHECK_FLAG(
9647 p->af_cap
9648 [afi]
9649 [safi],
9650 PEER_CAP_ADDPATH_AF_TX_ADV)
9651 && CHECK_FLAG(
9652 p->af_cap
9653 [afi]
9654 [safi],
9655 PEER_CAP_ADDPATH_AF_TX_RCV))
9656 json_object_boolean_true_add(
9657 json_sub,
9658 "txAdvertisedAndReceived");
9659 else if (
9660 CHECK_FLAG(
9661 p->af_cap
9662 [afi]
9663 [safi],
9664 PEER_CAP_ADDPATH_AF_TX_ADV))
9665 json_object_boolean_true_add(
9666 json_sub,
9667 "txAdvertised");
9668 else if (
9669 CHECK_FLAG(
9670 p->af_cap
9671 [afi]
9672 [safi],
9673 PEER_CAP_ADDPATH_AF_TX_RCV))
9674 json_object_boolean_true_add(
9675 json_sub,
9676 "txReceived");
9677 }
9678
9679 if (CHECK_FLAG(
9680 p->af_cap[afi]
9681 [safi],
9682 PEER_CAP_ADDPATH_AF_RX_ADV)
9683 || CHECK_FLAG(
9684 p->af_cap[afi]
9685 [safi],
9686 PEER_CAP_ADDPATH_AF_RX_RCV)) {
9687 if (CHECK_FLAG(
9688 p->af_cap
9689 [afi]
9690 [safi],
9691 PEER_CAP_ADDPATH_AF_RX_ADV)
9692 && CHECK_FLAG(
9693 p->af_cap
9694 [afi]
9695 [safi],
9696 PEER_CAP_ADDPATH_AF_RX_RCV))
9697 json_object_boolean_true_add(
9698 json_sub,
9699 "rxAdvertisedAndReceived");
9700 else if (
9701 CHECK_FLAG(
9702 p->af_cap
9703 [afi]
9704 [safi],
9705 PEER_CAP_ADDPATH_AF_RX_ADV))
9706 json_object_boolean_true_add(
9707 json_sub,
9708 "rxAdvertised");
9709 else if (
9710 CHECK_FLAG(
9711 p->af_cap
9712 [afi]
9713 [safi],
9714 PEER_CAP_ADDPATH_AF_RX_RCV))
9715 json_object_boolean_true_add(
9716 json_sub,
9717 "rxReceived");
9718 }
9719
9720 if (CHECK_FLAG(
9721 p->af_cap[afi]
9722 [safi],
9723 PEER_CAP_ADDPATH_AF_TX_ADV)
9724 || CHECK_FLAG(
9725 p->af_cap[afi]
9726 [safi],
9727 PEER_CAP_ADDPATH_AF_TX_RCV)
9728 || CHECK_FLAG(
9729 p->af_cap[afi]
9730 [safi],
9731 PEER_CAP_ADDPATH_AF_RX_ADV)
9732 || CHECK_FLAG(
9733 p->af_cap[afi]
9734 [safi],
9735 PEER_CAP_ADDPATH_AF_RX_RCV))
9736 json_object_object_add(
9737 json_add,
9738 print_store,
9739 json_sub);
9740 else
9741 json_object_free(
9742 json_sub);
9743 }
9744
9745 json_object_object_add(
9746 json_cap, "addPath", json_add);
9747 }
9748
9749 /* Dynamic */
9750 if (CHECK_FLAG(p->cap, PEER_CAP_DYNAMIC_RCV)
9751 || CHECK_FLAG(p->cap,
9752 PEER_CAP_DYNAMIC_ADV)) {
9753 if (CHECK_FLAG(p->cap,
9754 PEER_CAP_DYNAMIC_ADV)
9755 && CHECK_FLAG(p->cap,
9756 PEER_CAP_DYNAMIC_RCV))
9757 json_object_string_add(
9758 json_cap, "dynamic",
9759 "advertisedAndReceived");
9760 else if (CHECK_FLAG(
9761 p->cap,
9762 PEER_CAP_DYNAMIC_ADV))
9763 json_object_string_add(
9764 json_cap, "dynamic",
9765 "advertised");
9766 else if (CHECK_FLAG(
9767 p->cap,
9768 PEER_CAP_DYNAMIC_RCV))
9769 json_object_string_add(
9770 json_cap, "dynamic",
9771 "received");
9772 }
9773
9774 /* Extended nexthop */
9775 if (CHECK_FLAG(p->cap, PEER_CAP_ENHE_RCV)
9776 || CHECK_FLAG(p->cap, PEER_CAP_ENHE_ADV)) {
9777 json_object *json_nxt = NULL;
9778 const char *print_store;
9779
9780
9781 if (CHECK_FLAG(p->cap,
9782 PEER_CAP_ENHE_ADV)
9783 && CHECK_FLAG(p->cap,
9784 PEER_CAP_ENHE_RCV))
9785 json_object_string_add(
9786 json_cap,
9787 "extendedNexthop",
9788 "advertisedAndReceived");
9789 else if (CHECK_FLAG(p->cap,
9790 PEER_CAP_ENHE_ADV))
9791 json_object_string_add(
9792 json_cap,
9793 "extendedNexthop",
9794 "advertised");
9795 else if (CHECK_FLAG(p->cap,
9796 PEER_CAP_ENHE_RCV))
9797 json_object_string_add(
9798 json_cap,
9799 "extendedNexthop",
9800 "received");
9801
9802 if (CHECK_FLAG(p->cap,
9803 PEER_CAP_ENHE_RCV)) {
9804 json_nxt =
9805 json_object_new_object();
9806
9807 for (safi = SAFI_UNICAST;
9808 safi < SAFI_MAX; safi++) {
9809 if (CHECK_FLAG(
9810 p->af_cap
9811 [AFI_IP]
9812 [safi],
9813 PEER_CAP_ENHE_AF_RCV)) {
9814 print_store = afi_safi_print(
9815 AFI_IP,
9816 safi);
9817 json_object_string_add(
9818 json_nxt,
9819 print_store,
9820 "recieved"); /* misspelled for compatibility */
9821 }
9822 }
9823 json_object_object_add(
9824 json_cap,
9825 "extendedNexthopFamililesByPeer",
9826 json_nxt);
9827 }
9828 }
9829
9830 /* Route Refresh */
9831 if (CHECK_FLAG(p->cap, PEER_CAP_REFRESH_ADV)
9832 || CHECK_FLAG(p->cap,
9833 PEER_CAP_REFRESH_NEW_RCV)
9834 || CHECK_FLAG(p->cap,
9835 PEER_CAP_REFRESH_OLD_RCV)) {
9836 if (CHECK_FLAG(p->cap,
9837 PEER_CAP_REFRESH_ADV)
9838 && (CHECK_FLAG(
9839 p->cap,
9840 PEER_CAP_REFRESH_NEW_RCV)
9841 || CHECK_FLAG(
9842 p->cap,
9843 PEER_CAP_REFRESH_OLD_RCV))) {
9844 if (CHECK_FLAG(
9845 p->cap,
9846 PEER_CAP_REFRESH_OLD_RCV)
9847 && CHECK_FLAG(
9848 p->cap,
9849 PEER_CAP_REFRESH_NEW_RCV))
9850 json_object_string_add(
9851 json_cap,
9852 "routeRefresh",
9853 "advertisedAndReceivedOldNew");
9854 else {
9855 if (CHECK_FLAG(
9856 p->cap,
9857 PEER_CAP_REFRESH_OLD_RCV))
9858 json_object_string_add(
9859 json_cap,
9860 "routeRefresh",
9861 "advertisedAndReceivedOld");
9862 else
9863 json_object_string_add(
9864 json_cap,
9865 "routeRefresh",
9866 "advertisedAndReceivedNew");
9867 }
9868 } else if (
9869 CHECK_FLAG(
9870 p->cap,
9871 PEER_CAP_REFRESH_ADV))
9872 json_object_string_add(
9873 json_cap,
9874 "routeRefresh",
9875 "advertised");
9876 else if (
9877 CHECK_FLAG(
9878 p->cap,
9879 PEER_CAP_REFRESH_NEW_RCV)
9880 || CHECK_FLAG(
9881 p->cap,
9882 PEER_CAP_REFRESH_OLD_RCV))
9883 json_object_string_add(
9884 json_cap,
9885 "routeRefresh",
9886 "received");
9887 }
9888
9889 /* Multiprotocol Extensions */
9890 json_object *json_multi = NULL;
9891 json_multi = json_object_new_object();
9892
9893 FOREACH_AFI_SAFI (afi, safi) {
9894 if (p->afc_adv[afi][safi]
9895 || p->afc_recv[afi][safi]) {
9896 json_object *json_exten = NULL;
9897 json_exten =
9898 json_object_new_object();
9899
9900 if (p->afc_adv[afi][safi]
9901 && p->afc_recv[afi][safi])
9902 json_object_boolean_true_add(
9903 json_exten,
9904 "advertisedAndReceived");
9905 else if (p->afc_adv[afi][safi])
9906 json_object_boolean_true_add(
9907 json_exten,
9908 "advertised");
9909 else if (p->afc_recv[afi][safi])
9910 json_object_boolean_true_add(
9911 json_exten,
9912 "received");
9913
9914 json_object_object_add(
9915 json_multi,
9916 afi_safi_print(afi,
9917 safi),
9918 json_exten);
9919 }
9920 }
9921 json_object_object_add(
9922 json_cap, "multiprotocolExtensions",
9923 json_multi);
9924
9925 /* Hostname capabilities */
9926 json_object *json_hname = NULL;
9927
9928 json_hname = json_object_new_object();
9929
9930 if (CHECK_FLAG(p->cap, PEER_CAP_HOSTNAME_ADV)) {
9931 json_object_string_add(
9932 json_hname, "advHostName",
9933 bgp->peer_self->hostname
9934 ? bgp->peer_self
9935 ->hostname
9936 : "n/a");
9937 json_object_string_add(
9938 json_hname, "advDomainName",
9939 bgp->peer_self->domainname
9940 ? bgp->peer_self
9941 ->domainname
9942 : "n/a");
9943 }
9944
9945
9946 if (CHECK_FLAG(p->cap, PEER_CAP_HOSTNAME_RCV)) {
9947 json_object_string_add(
9948 json_hname, "rcvHostName",
9949 p->hostname ? p->hostname
9950 : "n/a");
9951 json_object_string_add(
9952 json_hname, "rcvDomainName",
9953 p->domainname ? p->domainname
9954 : "n/a");
9955 }
9956
9957 json_object_object_add(json_cap, "hostName",
9958 json_hname);
9959
9960 /* Gracefull Restart */
9961 if (CHECK_FLAG(p->cap, PEER_CAP_RESTART_RCV)
9962 || CHECK_FLAG(p->cap,
9963 PEER_CAP_RESTART_ADV)) {
9964 if (CHECK_FLAG(p->cap,
9965 PEER_CAP_RESTART_ADV)
9966 && CHECK_FLAG(p->cap,
9967 PEER_CAP_RESTART_RCV))
9968 json_object_string_add(
9969 json_cap,
9970 "gracefulRestart",
9971 "advertisedAndReceived");
9972 else if (CHECK_FLAG(
9973 p->cap,
9974 PEER_CAP_RESTART_ADV))
9975 json_object_string_add(
9976 json_cap,
9977 "gracefulRestartCapability",
9978 "advertised");
9979 else if (CHECK_FLAG(
9980 p->cap,
9981 PEER_CAP_RESTART_RCV))
9982 json_object_string_add(
9983 json_cap,
9984 "gracefulRestartCapability",
9985 "received");
9986
9987 if (CHECK_FLAG(p->cap,
9988 PEER_CAP_RESTART_RCV)) {
9989 int restart_af_count = 0;
9990 json_object *json_restart =
9991 NULL;
9992 json_restart =
9993 json_object_new_object();
9994
9995 json_object_int_add(
9996 json_cap,
9997 "gracefulRestartRemoteTimerMsecs",
9998 p->v_gr_restart * 1000);
9999
10000 FOREACH_AFI_SAFI (afi, safi) {
10001 if (CHECK_FLAG(
10002 p->af_cap
10003 [afi]
10004 [safi],
10005 PEER_CAP_RESTART_AF_RCV)) {
10006 json_object *
10007 json_sub =
10008 NULL;
10009 json_sub =
10010 json_object_new_object();
10011
10012 if (CHECK_FLAG(
10013 p->af_cap
10014 [afi]
10015 [safi],
10016 PEER_CAP_RESTART_AF_PRESERVE_RCV))
10017 json_object_boolean_true_add(
10018 json_sub,
10019 "preserved");
10020 restart_af_count++;
10021 json_object_object_add(
10022 json_restart,
10023 afi_safi_print(
10024 afi,
10025 safi),
10026 json_sub);
10027 }
10028 }
10029 if (!restart_af_count) {
10030 json_object_string_add(
10031 json_cap,
10032 "addressFamiliesByPeer",
10033 "none");
10034 json_object_free(
10035 json_restart);
10036 } else
10037 json_object_object_add(
10038 json_cap,
10039 "addressFamiliesByPeer",
10040 json_restart);
10041 }
10042 }
10043 json_object_object_add(json_neigh,
10044 "neighborCapabilities",
10045 json_cap);
10046 } else {
10047 vty_out(vty, " Neighbor capabilities:\n");
10048
10049 /* AS4 */
10050 if (CHECK_FLAG(p->cap, PEER_CAP_AS4_RCV)
10051 || CHECK_FLAG(p->cap, PEER_CAP_AS4_ADV)) {
10052 vty_out(vty, " 4 Byte AS:");
10053 if (CHECK_FLAG(p->cap,
10054 PEER_CAP_AS4_ADV))
10055 vty_out(vty, " advertised");
10056 if (CHECK_FLAG(p->cap,
10057 PEER_CAP_AS4_RCV))
10058 vty_out(vty, " %sreceived",
10059 CHECK_FLAG(
10060 p->cap,
10061 PEER_CAP_AS4_ADV)
10062 ? "and "
10063 : "");
10064 vty_out(vty, "\n");
10065 }
10066
10067 /* AddPath */
10068 if (CHECK_FLAG(p->cap, PEER_CAP_ADDPATH_RCV)
10069 || CHECK_FLAG(p->cap,
10070 PEER_CAP_ADDPATH_ADV)) {
10071 vty_out(vty, " AddPath:\n");
10072
10073 FOREACH_AFI_SAFI (afi, safi) {
10074 if (CHECK_FLAG(
10075 p->af_cap[afi]
10076 [safi],
10077 PEER_CAP_ADDPATH_AF_TX_ADV)
10078 || CHECK_FLAG(
10079 p->af_cap[afi]
10080 [safi],
10081 PEER_CAP_ADDPATH_AF_TX_RCV)) {
10082 vty_out(vty,
10083 " %s: TX ",
10084 afi_safi_print(
10085 afi,
10086 safi));
10087
10088 if (CHECK_FLAG(
10089 p->af_cap
10090 [afi]
10091 [safi],
10092 PEER_CAP_ADDPATH_AF_TX_ADV))
10093 vty_out(vty,
10094 "advertised %s",
10095 afi_safi_print(
10096 afi,
10097 safi));
10098
10099 if (CHECK_FLAG(
10100 p->af_cap
10101 [afi]
10102 [safi],
10103 PEER_CAP_ADDPATH_AF_TX_RCV))
10104 vty_out(vty,
10105 "%sreceived",
10106 CHECK_FLAG(
10107 p->af_cap
10108 [afi]
10109 [safi],
10110 PEER_CAP_ADDPATH_AF_TX_ADV)
10111 ? " and "
10112 : "");
10113
10114 vty_out(vty, "\n");
10115 }
10116
10117 if (CHECK_FLAG(
10118 p->af_cap[afi]
10119 [safi],
10120 PEER_CAP_ADDPATH_AF_RX_ADV)
10121 || CHECK_FLAG(
10122 p->af_cap[afi]
10123 [safi],
10124 PEER_CAP_ADDPATH_AF_RX_RCV)) {
10125 vty_out(vty,
10126 " %s: RX ",
10127 afi_safi_print(
10128 afi,
10129 safi));
10130
10131 if (CHECK_FLAG(
10132 p->af_cap
10133 [afi]
10134 [safi],
10135 PEER_CAP_ADDPATH_AF_RX_ADV))
10136 vty_out(vty,
10137 "advertised %s",
10138 afi_safi_print(
10139 afi,
10140 safi));
10141
10142 if (CHECK_FLAG(
10143 p->af_cap
10144 [afi]
10145 [safi],
10146 PEER_CAP_ADDPATH_AF_RX_RCV))
10147 vty_out(vty,
10148 "%sreceived",
10149 CHECK_FLAG(
10150 p->af_cap
10151 [afi]
10152 [safi],
10153 PEER_CAP_ADDPATH_AF_RX_ADV)
10154 ? " and "
10155 : "");
10156
10157 vty_out(vty, "\n");
10158 }
10159 }
10160 }
10161
10162 /* Dynamic */
10163 if (CHECK_FLAG(p->cap, PEER_CAP_DYNAMIC_RCV)
10164 || CHECK_FLAG(p->cap,
10165 PEER_CAP_DYNAMIC_ADV)) {
10166 vty_out(vty, " Dynamic:");
10167 if (CHECK_FLAG(p->cap,
10168 PEER_CAP_DYNAMIC_ADV))
10169 vty_out(vty, " advertised");
10170 if (CHECK_FLAG(p->cap,
10171 PEER_CAP_DYNAMIC_RCV))
10172 vty_out(vty, " %sreceived",
10173 CHECK_FLAG(
10174 p->cap,
10175 PEER_CAP_DYNAMIC_ADV)
10176 ? "and "
10177 : "");
10178 vty_out(vty, "\n");
10179 }
10180
10181 /* Extended nexthop */
10182 if (CHECK_FLAG(p->cap, PEER_CAP_ENHE_RCV)
10183 || CHECK_FLAG(p->cap, PEER_CAP_ENHE_ADV)) {
10184 vty_out(vty, " Extended nexthop:");
10185 if (CHECK_FLAG(p->cap,
10186 PEER_CAP_ENHE_ADV))
10187 vty_out(vty, " advertised");
10188 if (CHECK_FLAG(p->cap,
10189 PEER_CAP_ENHE_RCV))
10190 vty_out(vty, " %sreceived",
10191 CHECK_FLAG(
10192 p->cap,
10193 PEER_CAP_ENHE_ADV)
10194 ? "and "
10195 : "");
10196 vty_out(vty, "\n");
10197
10198 if (CHECK_FLAG(p->cap,
10199 PEER_CAP_ENHE_RCV)) {
10200 vty_out(vty,
10201 " Address families by peer:\n ");
10202 for (safi = SAFI_UNICAST;
10203 safi < SAFI_MAX; safi++)
10204 if (CHECK_FLAG(
10205 p->af_cap
10206 [AFI_IP]
10207 [safi],
10208 PEER_CAP_ENHE_AF_RCV))
10209 vty_out(vty,
10210 " %s\n",
10211 afi_safi_print(
10212 AFI_IP,
10213 safi));
10214 }
10215 }
10216
10217 /* Route Refresh */
10218 if (CHECK_FLAG(p->cap, PEER_CAP_REFRESH_ADV)
10219 || CHECK_FLAG(p->cap,
10220 PEER_CAP_REFRESH_NEW_RCV)
10221 || CHECK_FLAG(p->cap,
10222 PEER_CAP_REFRESH_OLD_RCV)) {
10223 vty_out(vty, " Route refresh:");
10224 if (CHECK_FLAG(p->cap,
10225 PEER_CAP_REFRESH_ADV))
10226 vty_out(vty, " advertised");
10227 if (CHECK_FLAG(p->cap,
10228 PEER_CAP_REFRESH_NEW_RCV)
10229 || CHECK_FLAG(
10230 p->cap,
10231 PEER_CAP_REFRESH_OLD_RCV))
10232 vty_out(vty, " %sreceived(%s)",
10233 CHECK_FLAG(
10234 p->cap,
10235 PEER_CAP_REFRESH_ADV)
10236 ? "and "
10237 : "",
10238 (CHECK_FLAG(
10239 p->cap,
10240 PEER_CAP_REFRESH_OLD_RCV)
10241 && CHECK_FLAG(
10242 p->cap,
10243 PEER_CAP_REFRESH_NEW_RCV))
10244 ? "old & new"
10245 : CHECK_FLAG(
10246 p->cap,
10247 PEER_CAP_REFRESH_OLD_RCV)
10248 ? "old"
10249 : "new");
10250
10251 vty_out(vty, "\n");
10252 }
10253
10254 /* Multiprotocol Extensions */
10255 FOREACH_AFI_SAFI (afi, safi)
10256 if (p->afc_adv[afi][safi]
10257 || p->afc_recv[afi][safi]) {
10258 vty_out(vty,
10259 " Address Family %s:",
10260 afi_safi_print(afi,
10261 safi));
10262 if (p->afc_adv[afi][safi])
10263 vty_out(vty,
10264 " advertised");
10265 if (p->afc_recv[afi][safi])
10266 vty_out(vty,
10267 " %sreceived",
10268 p->afc_adv[afi]
10269 [safi]
10270 ? "and "
10271 : "");
10272 vty_out(vty, "\n");
10273 }
10274
10275 /* Hostname capability */
10276 vty_out(vty, " Hostname Capability:");
10277
10278 if (CHECK_FLAG(p->cap, PEER_CAP_HOSTNAME_ADV)) {
10279 vty_out(vty,
10280 " advertised (name: %s,domain name: %s)",
10281 bgp->peer_self->hostname
10282 ? bgp->peer_self
10283 ->hostname
10284 : "n/a",
10285 bgp->peer_self->domainname
10286 ? bgp->peer_self
10287 ->domainname
10288 : "n/a");
10289 } else {
10290 vty_out(vty, " not advertised");
10291 }
10292
10293 if (CHECK_FLAG(p->cap, PEER_CAP_HOSTNAME_RCV)) {
10294 vty_out(vty,
10295 " received (name: %s,domain name: %s)",
10296 p->hostname ? p->hostname
10297 : "n/a",
10298 p->domainname ? p->domainname
10299 : "n/a");
10300 } else {
10301 vty_out(vty, " not received");
10302 }
10303
10304 vty_out(vty, "\n");
10305
10306 /* Gracefull Restart */
10307 if (CHECK_FLAG(p->cap, PEER_CAP_RESTART_RCV)
10308 || CHECK_FLAG(p->cap,
10309 PEER_CAP_RESTART_ADV)) {
10310 vty_out(vty,
10311 " Graceful Restart Capabilty:");
10312 if (CHECK_FLAG(p->cap,
10313 PEER_CAP_RESTART_ADV))
10314 vty_out(vty, " advertised");
10315 if (CHECK_FLAG(p->cap,
10316 PEER_CAP_RESTART_RCV))
10317 vty_out(vty, " %sreceived",
10318 CHECK_FLAG(
10319 p->cap,
10320 PEER_CAP_RESTART_ADV)
10321 ? "and "
10322 : "");
10323 vty_out(vty, "\n");
10324
10325 if (CHECK_FLAG(p->cap,
10326 PEER_CAP_RESTART_RCV)) {
10327 int restart_af_count = 0;
10328
10329 vty_out(vty,
10330 " Remote Restart timer is %d seconds\n",
10331 p->v_gr_restart);
10332 vty_out(vty,
10333 " Address families by peer:\n ");
10334
10335 FOREACH_AFI_SAFI (afi, safi)
10336 if (CHECK_FLAG(
10337 p->af_cap
10338 [afi]
10339 [safi],
10340 PEER_CAP_RESTART_AF_RCV)) {
10341 vty_out(vty,
10342 "%s%s(%s)",
10343 restart_af_count
10344 ? ", "
10345 : "",
10346 afi_safi_print(
10347 afi,
10348 safi),
10349 CHECK_FLAG(
10350 p->af_cap
10351 [afi]
10352 [safi],
10353 PEER_CAP_RESTART_AF_PRESERVE_RCV)
10354 ? "preserved"
10355 : "not preserved");
10356 restart_af_count++;
10357 }
10358 if (!restart_af_count)
10359 vty_out(vty, "none");
10360 vty_out(vty, "\n");
10361 }
10362 }
10363 }
10364 }
10365 }
10366
10367 /* graceful restart information */
10368 if (CHECK_FLAG(p->cap, PEER_CAP_RESTART_RCV) || p->t_gr_restart
10369 || p->t_gr_stale) {
10370 json_object *json_grace = NULL;
10371 json_object *json_grace_send = NULL;
10372 json_object *json_grace_recv = NULL;
10373 int eor_send_af_count = 0;
10374 int eor_receive_af_count = 0;
10375
10376 if (use_json) {
10377 json_grace = json_object_new_object();
10378 json_grace_send = json_object_new_object();
10379 json_grace_recv = json_object_new_object();
10380
10381 if (p->status == Established) {
10382 FOREACH_AFI_SAFI (afi, safi) {
10383 if (CHECK_FLAG(p->af_sflags[afi][safi],
10384 PEER_STATUS_EOR_SEND)) {
10385 json_object_boolean_true_add(
10386 json_grace_send,
10387 afi_safi_print(afi,
10388 safi));
10389 eor_send_af_count++;
10390 }
10391 }
10392 FOREACH_AFI_SAFI (afi, safi) {
10393 if (CHECK_FLAG(
10394 p->af_sflags[afi][safi],
10395 PEER_STATUS_EOR_RECEIVED)) {
10396 json_object_boolean_true_add(
10397 json_grace_recv,
10398 afi_safi_print(afi,
10399 safi));
10400 eor_receive_af_count++;
10401 }
10402 }
10403 }
10404
10405 json_object_object_add(json_grace, "endOfRibSend",
10406 json_grace_send);
10407 json_object_object_add(json_grace, "endOfRibRecv",
10408 json_grace_recv);
10409
10410 if (p->t_gr_restart)
10411 json_object_int_add(json_grace,
10412 "gracefulRestartTimerMsecs",
10413 thread_timer_remain_second(
10414 p->t_gr_restart)
10415 * 1000);
10416
10417 if (p->t_gr_stale)
10418 json_object_int_add(
10419 json_grace,
10420 "gracefulStalepathTimerMsecs",
10421 thread_timer_remain_second(
10422 p->t_gr_stale)
10423 * 1000);
10424
10425 json_object_object_add(
10426 json_neigh, "gracefulRestartInfo", json_grace);
10427 } else {
10428 vty_out(vty, " Graceful restart information:\n");
10429 if (p->status == Established) {
10430 vty_out(vty, " End-of-RIB send: ");
10431 FOREACH_AFI_SAFI (afi, safi) {
10432 if (CHECK_FLAG(p->af_sflags[afi][safi],
10433 PEER_STATUS_EOR_SEND)) {
10434 vty_out(vty, "%s%s",
10435 eor_send_af_count ? ", "
10436 : "",
10437 afi_safi_print(afi,
10438 safi));
10439 eor_send_af_count++;
10440 }
10441 }
10442 vty_out(vty, "\n");
10443 vty_out(vty, " End-of-RIB received: ");
10444 FOREACH_AFI_SAFI (afi, safi) {
10445 if (CHECK_FLAG(
10446 p->af_sflags[afi][safi],
10447 PEER_STATUS_EOR_RECEIVED)) {
10448 vty_out(vty, "%s%s",
10449 eor_receive_af_count
10450 ? ", "
10451 : "",
10452 afi_safi_print(afi,
10453 safi));
10454 eor_receive_af_count++;
10455 }
10456 }
10457 vty_out(vty, "\n");
10458 }
10459
10460 if (p->t_gr_restart)
10461 vty_out(vty,
10462 " The remaining time of restart timer is %ld\n",
10463 thread_timer_remain_second(
10464 p->t_gr_restart));
10465
10466 if (p->t_gr_stale)
10467 vty_out(vty,
10468 " The remaining time of stalepath timer is %ld\n",
10469 thread_timer_remain_second(
10470 p->t_gr_stale));
10471 }
10472 }
10473 if (use_json) {
10474 json_object *json_stat = NULL;
10475 json_stat = json_object_new_object();
10476 /* Packet counts. */
10477 json_object_int_add(json_stat, "depthInq", 0);
10478 json_object_int_add(json_stat, "depthOutq",
10479 (unsigned long)p->obuf->count);
10480 json_object_int_add(json_stat, "opensSent",
10481 atomic_load_explicit(&p->open_out,
10482 memory_order_relaxed));
10483 json_object_int_add(json_stat, "opensRecv",
10484 atomic_load_explicit(&p->open_in,
10485 memory_order_relaxed));
10486 json_object_int_add(json_stat, "notificationsSent",
10487 atomic_load_explicit(&p->notify_out,
10488 memory_order_relaxed));
10489 json_object_int_add(json_stat, "notificationsRecv",
10490 atomic_load_explicit(&p->notify_in,
10491 memory_order_relaxed));
10492 json_object_int_add(json_stat, "updatesSent",
10493 atomic_load_explicit(&p->update_out,
10494 memory_order_relaxed));
10495 json_object_int_add(json_stat, "updatesRecv",
10496 atomic_load_explicit(&p->update_in,
10497 memory_order_relaxed));
10498 json_object_int_add(json_stat, "keepalivesSent",
10499 atomic_load_explicit(&p->keepalive_out,
10500 memory_order_relaxed));
10501 json_object_int_add(json_stat, "keepalivesRecv",
10502 atomic_load_explicit(&p->keepalive_in,
10503 memory_order_relaxed));
10504 json_object_int_add(json_stat, "routeRefreshSent",
10505 atomic_load_explicit(&p->refresh_out,
10506 memory_order_relaxed));
10507 json_object_int_add(json_stat, "routeRefreshRecv",
10508 atomic_load_explicit(&p->refresh_in,
10509 memory_order_relaxed));
10510 json_object_int_add(json_stat, "capabilitySent",
10511 atomic_load_explicit(&p->dynamic_cap_out,
10512 memory_order_relaxed));
10513 json_object_int_add(json_stat, "capabilityRecv",
10514 atomic_load_explicit(&p->dynamic_cap_in,
10515 memory_order_relaxed));
10516 json_object_int_add(json_stat, "totalSent", PEER_TOTAL_TX(p));
10517 json_object_int_add(json_stat, "totalRecv", PEER_TOTAL_RX(p));
10518 json_object_object_add(json_neigh, "messageStats", json_stat);
10519 } else {
10520 /* Packet counts. */
10521 vty_out(vty, " Message statistics:\n");
10522 vty_out(vty, " Inq depth is 0\n");
10523 vty_out(vty, " Outq depth is %lu\n",
10524 (unsigned long)p->obuf->count);
10525 vty_out(vty, " Sent Rcvd\n");
10526 vty_out(vty, " Opens: %10d %10d\n",
10527 atomic_load_explicit(&p->open_out,
10528 memory_order_relaxed),
10529 atomic_load_explicit(&p->open_in,
10530 memory_order_relaxed));
10531 vty_out(vty, " Notifications: %10d %10d\n",
10532 atomic_load_explicit(&p->notify_out,
10533 memory_order_relaxed),
10534 atomic_load_explicit(&p->notify_in,
10535 memory_order_relaxed));
10536 vty_out(vty, " Updates: %10d %10d\n",
10537 atomic_load_explicit(&p->update_out,
10538 memory_order_relaxed),
10539 atomic_load_explicit(&p->update_in,
10540 memory_order_relaxed));
10541 vty_out(vty, " Keepalives: %10d %10d\n",
10542 atomic_load_explicit(&p->keepalive_out,
10543 memory_order_relaxed),
10544 atomic_load_explicit(&p->keepalive_in,
10545 memory_order_relaxed));
10546 vty_out(vty, " Route Refresh: %10d %10d\n",
10547 atomic_load_explicit(&p->refresh_out,
10548 memory_order_relaxed),
10549 atomic_load_explicit(&p->refresh_in,
10550 memory_order_relaxed));
10551 vty_out(vty, " Capability: %10d %10d\n",
10552 atomic_load_explicit(&p->dynamic_cap_out,
10553 memory_order_relaxed),
10554 atomic_load_explicit(&p->dynamic_cap_in,
10555 memory_order_relaxed));
10556 vty_out(vty, " Total: %10d %10d\n", PEER_TOTAL_TX(p),
10557 PEER_TOTAL_RX(p));
10558 }
10559
10560 if (use_json) {
10561 /* advertisement-interval */
10562 json_object_int_add(json_neigh,
10563 "minBtwnAdvertisementRunsTimerMsecs",
10564 p->v_routeadv * 1000);
10565
10566 /* Update-source. */
10567 if (p->update_if || p->update_source) {
10568 if (p->update_if)
10569 json_object_string_add(json_neigh,
10570 "updateSource",
10571 p->update_if);
10572 else if (p->update_source)
10573 json_object_string_add(
10574 json_neigh, "updateSource",
10575 sockunion2str(p->update_source, buf1,
10576 SU_ADDRSTRLEN));
10577 }
10578 } else {
10579 /* advertisement-interval */
10580 vty_out(vty,
10581 " Minimum time between advertisement runs is %d seconds\n",
10582 p->v_routeadv);
10583
10584 /* Update-source. */
10585 if (p->update_if || p->update_source) {
10586 vty_out(vty, " Update source is ");
10587 if (p->update_if)
10588 vty_out(vty, "%s", p->update_if);
10589 else if (p->update_source)
10590 vty_out(vty, "%s",
10591 sockunion2str(p->update_source, buf1,
10592 SU_ADDRSTRLEN));
10593 vty_out(vty, "\n");
10594 }
10595
10596 vty_out(vty, "\n");
10597 }
10598
10599 /* Address Family Information */
10600 json_object *json_hold = NULL;
10601
10602 if (use_json)
10603 json_hold = json_object_new_object();
10604
10605 FOREACH_AFI_SAFI (afi, safi)
10606 if (p->afc[afi][safi])
10607 bgp_show_peer_afi(vty, p, afi, safi, use_json,
10608 json_hold);
10609
10610 if (use_json) {
10611 json_object_object_add(json_neigh, "addressFamilyInfo",
10612 json_hold);
10613 json_object_int_add(json_neigh, "connectionsEstablished",
10614 p->established);
10615 json_object_int_add(json_neigh, "connectionsDropped",
10616 p->dropped);
10617 } else
10618 vty_out(vty, " Connections established %d; dropped %d\n",
10619 p->established, p->dropped);
10620
10621 if (!p->last_reset) {
10622 if (use_json)
10623 json_object_string_add(json_neigh, "lastReset",
10624 "never");
10625 else
10626 vty_out(vty, " Last reset never\n");
10627 } else {
10628 if (use_json) {
10629 time_t uptime;
10630 struct tm *tm;
10631
10632 uptime = bgp_clock();
10633 uptime -= p->resettime;
10634 tm = gmtime(&uptime);
10635 json_object_int_add(json_neigh, "lastResetTimerMsecs",
10636 (tm->tm_sec * 1000)
10637 + (tm->tm_min * 60000)
10638 + (tm->tm_hour * 3600000));
10639 json_object_string_add(
10640 json_neigh, "lastResetDueTo",
10641 peer_down_str[(int)p->last_reset]);
10642 if (p->last_reset == PEER_DOWN_NOTIFY_SEND
10643 || p->last_reset == PEER_DOWN_NOTIFY_RECEIVED) {
10644 char errorcodesubcode_hexstr[5];
10645 char errorcodesubcode_str[256];
10646
10647 code_str = bgp_notify_code_str(p->notify.code);
10648 subcode_str = bgp_notify_subcode_str(
10649 p->notify.code, p->notify.subcode);
10650
10651 sprintf(errorcodesubcode_hexstr, "%02X%02X",
10652 p->notify.code, p->notify.subcode);
10653 json_object_string_add(json_neigh,
10654 "lastErrorCodeSubcode",
10655 errorcodesubcode_hexstr);
10656 snprintf(errorcodesubcode_str, 255, "%s%s",
10657 code_str, subcode_str);
10658 json_object_string_add(json_neigh,
10659 "lastNotificationReason",
10660 errorcodesubcode_str);
10661 if (p->last_reset == PEER_DOWN_NOTIFY_RECEIVED
10662 && p->notify.code == BGP_NOTIFY_CEASE
10663 && (p->notify.subcode
10664 == BGP_NOTIFY_CEASE_ADMIN_SHUTDOWN
10665 || p->notify.subcode
10666 == BGP_NOTIFY_CEASE_ADMIN_RESET)
10667 && p->notify.length) {
10668 char msgbuf[1024];
10669 const char *msg_str;
10670
10671 msg_str = bgp_notify_admin_message(
10672 msgbuf, sizeof(msgbuf),
10673 (uint8_t *)p->notify.data,
10674 p->notify.length);
10675 if (msg_str)
10676 json_object_string_add(
10677 json_neigh,
10678 "lastShutdownDescription",
10679 msg_str);
10680 }
10681 }
10682 } else {
10683 vty_out(vty, " Last reset %s, ",
10684 peer_uptime(p->resettime, timebuf,
10685 BGP_UPTIME_LEN, 0, NULL));
10686
10687 if (p->last_reset == PEER_DOWN_NOTIFY_SEND
10688 || p->last_reset == PEER_DOWN_NOTIFY_RECEIVED) {
10689 code_str = bgp_notify_code_str(p->notify.code);
10690 subcode_str = bgp_notify_subcode_str(
10691 p->notify.code, p->notify.subcode);
10692 vty_out(vty, "due to NOTIFICATION %s (%s%s)\n",
10693 p->last_reset == PEER_DOWN_NOTIFY_SEND
10694 ? "sent"
10695 : "received",
10696 code_str, subcode_str);
10697 if (p->last_reset == PEER_DOWN_NOTIFY_RECEIVED
10698 && p->notify.code == BGP_NOTIFY_CEASE
10699 && (p->notify.subcode
10700 == BGP_NOTIFY_CEASE_ADMIN_SHUTDOWN
10701 || p->notify.subcode
10702 == BGP_NOTIFY_CEASE_ADMIN_RESET)
10703 && p->notify.length) {
10704 char msgbuf[1024];
10705 const char *msg_str;
10706
10707 msg_str = bgp_notify_admin_message(
10708 msgbuf, sizeof(msgbuf),
10709 (uint8_t *)p->notify.data,
10710 p->notify.length);
10711 if (msg_str)
10712 vty_out(vty,
10713 " Message: \"%s\"\n",
10714 msg_str);
10715 }
10716 } else {
10717 vty_out(vty, "due to %s\n",
10718 peer_down_str[(int)p->last_reset]);
10719 }
10720
10721 if (p->last_reset_cause_size) {
10722 msg = p->last_reset_cause;
10723 vty_out(vty,
10724 " Message received that caused BGP to send a NOTIFICATION:\n ");
10725 for (i = 1; i <= p->last_reset_cause_size;
10726 i++) {
10727 vty_out(vty, "%02X", *msg++);
10728
10729 if (i != p->last_reset_cause_size) {
10730 if (i % 16 == 0) {
10731 vty_out(vty, "\n ");
10732 } else if (i % 4 == 0) {
10733 vty_out(vty, " ");
10734 }
10735 }
10736 }
10737 vty_out(vty, "\n");
10738 }
10739 }
10740 }
10741
10742 if (CHECK_FLAG(p->sflags, PEER_STATUS_PREFIX_OVERFLOW)) {
10743 if (use_json)
10744 json_object_boolean_true_add(json_neigh,
10745 "prefixesConfigExceedMax");
10746 else
10747 vty_out(vty,
10748 " Peer had exceeded the max. no. of prefixes configured.\n");
10749
10750 if (p->t_pmax_restart) {
10751 if (use_json) {
10752 json_object_boolean_true_add(
10753 json_neigh, "reducePrefixNumFrom");
10754 json_object_int_add(json_neigh,
10755 "restartInTimerMsec",
10756 thread_timer_remain_second(
10757 p->t_pmax_restart)
10758 * 1000);
10759 } else
10760 vty_out(vty,
10761 " Reduce the no. of prefix from %s, will restart in %ld seconds\n",
10762 p->host, thread_timer_remain_second(
10763 p->t_pmax_restart));
10764 } else {
10765 if (use_json)
10766 json_object_boolean_true_add(
10767 json_neigh,
10768 "reducePrefixNumAndClearIpBgp");
10769 else
10770 vty_out(vty,
10771 " Reduce the no. of prefix and clear ip bgp %s to restore peering\n",
10772 p->host);
10773 }
10774 }
10775
10776 /* EBGP Multihop and GTSM */
10777 if (p->sort != BGP_PEER_IBGP) {
10778 if (use_json) {
10779 if (p->gtsm_hops > 0)
10780 json_object_int_add(json_neigh,
10781 "externalBgpNbrMaxHopsAway",
10782 p->gtsm_hops);
10783 else if (p->ttl > 1)
10784 json_object_int_add(json_neigh,
10785 "externalBgpNbrMaxHopsAway",
10786 p->ttl);
10787 } else {
10788 if (p->gtsm_hops > 0)
10789 vty_out(vty,
10790 " External BGP neighbor may be up to %d hops away.\n",
10791 p->gtsm_hops);
10792 else if (p->ttl > 1)
10793 vty_out(vty,
10794 " External BGP neighbor may be up to %d hops away.\n",
10795 p->ttl);
10796 }
10797 } else {
10798 if (p->gtsm_hops > 0) {
10799 if (use_json)
10800 json_object_int_add(json_neigh,
10801 "internalBgpNbrMaxHopsAway",
10802 p->gtsm_hops);
10803 else
10804 vty_out(vty,
10805 " Internal BGP neighbor may be up to %d hops away.\n",
10806 p->gtsm_hops);
10807 }
10808 }
10809
10810 /* Local address. */
10811 if (p->su_local) {
10812 if (use_json) {
10813 json_object_string_add(json_neigh, "hostLocal",
10814 sockunion2str(p->su_local, buf1,
10815 SU_ADDRSTRLEN));
10816 json_object_int_add(json_neigh, "portLocal",
10817 ntohs(p->su_local->sin.sin_port));
10818 } else
10819 vty_out(vty, "Local host: %s, Local port: %d\n",
10820 sockunion2str(p->su_local, buf1, SU_ADDRSTRLEN),
10821 ntohs(p->su_local->sin.sin_port));
10822 }
10823
10824 /* Remote address. */
10825 if (p->su_remote) {
10826 if (use_json) {
10827 json_object_string_add(json_neigh, "hostForeign",
10828 sockunion2str(p->su_remote, buf1,
10829 SU_ADDRSTRLEN));
10830 json_object_int_add(json_neigh, "portForeign",
10831 ntohs(p->su_remote->sin.sin_port));
10832 } else
10833 vty_out(vty, "Foreign host: %s, Foreign port: %d\n",
10834 sockunion2str(p->su_remote, buf1,
10835 SU_ADDRSTRLEN),
10836 ntohs(p->su_remote->sin.sin_port));
10837 }
10838
10839 /* Nexthop display. */
10840 if (p->su_local) {
10841 if (use_json) {
10842 json_object_string_add(json_neigh, "nexthop",
10843 inet_ntop(AF_INET,
10844 &p->nexthop.v4, buf1,
10845 sizeof(buf1)));
10846 json_object_string_add(json_neigh, "nexthopGlobal",
10847 inet_ntop(AF_INET6,
10848 &p->nexthop.v6_global,
10849 buf1, sizeof(buf1)));
10850 json_object_string_add(json_neigh, "nexthopLocal",
10851 inet_ntop(AF_INET6,
10852 &p->nexthop.v6_local,
10853 buf1, sizeof(buf1)));
10854 if (p->shared_network)
10855 json_object_string_add(json_neigh,
10856 "bgpConnection",
10857 "sharedNetwork");
10858 else
10859 json_object_string_add(json_neigh,
10860 "bgpConnection",
10861 "nonSharedNetwork");
10862 } else {
10863 vty_out(vty, "Nexthop: %s\n",
10864 inet_ntop(AF_INET, &p->nexthop.v4, buf1,
10865 sizeof(buf1)));
10866 vty_out(vty, "Nexthop global: %s\n",
10867 inet_ntop(AF_INET6, &p->nexthop.v6_global, buf1,
10868 sizeof(buf1)));
10869 vty_out(vty, "Nexthop local: %s\n",
10870 inet_ntop(AF_INET6, &p->nexthop.v6_local, buf1,
10871 sizeof(buf1)));
10872 vty_out(vty, "BGP connection: %s\n",
10873 p->shared_network ? "shared network"
10874 : "non shared network");
10875 }
10876 }
10877
10878 /* Timer information. */
10879 if (use_json) {
10880 json_object_int_add(json_neigh, "connectRetryTimer",
10881 p->v_connect);
10882 if (p->status == Established && p->rtt)
10883 json_object_int_add(json_neigh, "estimatedRttInMsecs",
10884 p->rtt);
10885 if (p->t_start)
10886 json_object_int_add(
10887 json_neigh, "nextStartTimerDueInMsecs",
10888 thread_timer_remain_second(p->t_start) * 1000);
10889 if (p->t_connect)
10890 json_object_int_add(
10891 json_neigh, "nextConnectTimerDueInMsecs",
10892 thread_timer_remain_second(p->t_connect)
10893 * 1000);
10894 if (p->t_routeadv) {
10895 json_object_int_add(json_neigh, "mraiInterval",
10896 p->v_routeadv);
10897 json_object_int_add(
10898 json_neigh, "mraiTimerExpireInMsecs",
10899 thread_timer_remain_second(p->t_routeadv)
10900 * 1000);
10901 }
10902 if (p->password)
10903 json_object_int_add(json_neigh, "authenticationEnabled",
10904 1);
10905
10906 if (p->t_read)
10907 json_object_string_add(json_neigh, "readThread", "on");
10908 else
10909 json_object_string_add(json_neigh, "readThread", "off");
10910
10911 if (CHECK_FLAG(p->thread_flags, PEER_THREAD_WRITES_ON))
10912 json_object_string_add(json_neigh, "writeThread", "on");
10913 else
10914 json_object_string_add(json_neigh, "writeThread",
10915 "off");
10916 } else {
10917 vty_out(vty, "BGP Connect Retry Timer in Seconds: %d\n",
10918 p->v_connect);
10919 if (p->status == Established && p->rtt)
10920 vty_out(vty, "Estimated round trip time: %d ms\n",
10921 p->rtt);
10922 if (p->t_start)
10923 vty_out(vty, "Next start timer due in %ld seconds\n",
10924 thread_timer_remain_second(p->t_start));
10925 if (p->t_connect)
10926 vty_out(vty, "Next connect timer due in %ld seconds\n",
10927 thread_timer_remain_second(p->t_connect));
10928 if (p->t_routeadv)
10929 vty_out(vty,
10930 "MRAI (interval %u) timer expires in %ld seconds\n",
10931 p->v_routeadv,
10932 thread_timer_remain_second(p->t_routeadv));
10933 if (p->password)
10934 vty_out(vty, "Peer Authentication Enabled\n");
10935
10936 vty_out(vty, "Read thread: %s Write thread: %s\n",
10937 p->t_read ? "on" : "off",
10938 CHECK_FLAG(p->thread_flags, PEER_THREAD_WRITES_ON)
10939 ? "on"
10940 : "off");
10941 }
10942
10943 if (p->notify.code == BGP_NOTIFY_OPEN_ERR
10944 && p->notify.subcode == BGP_NOTIFY_OPEN_UNSUP_CAPBL)
10945 bgp_capability_vty_out(vty, p, use_json, json_neigh);
10946
10947 if (!use_json)
10948 vty_out(vty, "\n");
10949
10950 /* BFD information. */
10951 bgp_bfd_show_info(vty, p, use_json, json_neigh);
10952
10953 if (use_json) {
10954 if (p->conf_if) /* Configured interface name. */
10955 json_object_object_add(json, p->conf_if, json_neigh);
10956 else /* Configured IP address. */
10957 json_object_object_add(json, p->host, json_neigh);
10958 }
10959 }
10960
10961 static int bgp_show_neighbor(struct vty *vty, struct bgp *bgp,
10962 enum show_type type, union sockunion *su,
10963 const char *conf_if, bool use_json,
10964 json_object *json)
10965 {
10966 struct listnode *node, *nnode;
10967 struct peer *peer;
10968 int find = 0;
10969 bool nbr_output = false;
10970 afi_t afi = AFI_MAX;
10971 safi_t safi = SAFI_MAX;
10972
10973 if (type == show_ipv4_peer || type == show_ipv4_all) {
10974 afi = AFI_IP;
10975 } else if (type == show_ipv6_peer || type == show_ipv6_all) {
10976 afi = AFI_IP6;
10977 }
10978
10979 for (ALL_LIST_ELEMENTS(bgp->peer, node, nnode, peer)) {
10980 if (!CHECK_FLAG(peer->flags, PEER_FLAG_CONFIG_NODE))
10981 continue;
10982
10983 switch (type) {
10984 case show_all:
10985 bgp_show_peer(vty, peer, use_json, json);
10986 nbr_output = true;
10987 break;
10988 case show_peer:
10989 if (conf_if) {
10990 if ((peer->conf_if
10991 && !strcmp(peer->conf_if, conf_if))
10992 || (peer->hostname
10993 && !strcmp(peer->hostname, conf_if))) {
10994 find = 1;
10995 bgp_show_peer(vty, peer, use_json,
10996 json);
10997 }
10998 } else {
10999 if (sockunion_same(&peer->su, su)) {
11000 find = 1;
11001 bgp_show_peer(vty, peer, use_json,
11002 json);
11003 }
11004 }
11005 break;
11006 case show_ipv4_peer:
11007 case show_ipv6_peer:
11008 FOREACH_SAFI (safi) {
11009 if (peer->afc[afi][safi]) {
11010 if (conf_if) {
11011 if ((peer->conf_if
11012 && !strcmp(peer->conf_if, conf_if))
11013 || (peer->hostname
11014 && !strcmp(peer->hostname, conf_if))) {
11015 find = 1;
11016 bgp_show_peer(vty, peer, use_json,
11017 json);
11018 break;
11019 }
11020 } else {
11021 if (sockunion_same(&peer->su, su)) {
11022 find = 1;
11023 bgp_show_peer(vty, peer, use_json,
11024 json);
11025 break;
11026 }
11027 }
11028 }
11029 }
11030 break;
11031 case show_ipv4_all:
11032 case show_ipv6_all:
11033 FOREACH_SAFI (safi) {
11034 if (peer->afc[afi][safi]) {
11035 bgp_show_peer(vty, peer, use_json, json);
11036 nbr_output = true;
11037 break;
11038 }
11039 }
11040 break;
11041 }
11042 }
11043
11044 if ((type == show_peer || type == show_ipv4_peer ||
11045 type == show_ipv6_peer) && !find) {
11046 if (use_json)
11047 json_object_boolean_true_add(json, "bgpNoSuchNeighbor");
11048 else
11049 vty_out(vty, "%% No such neighbor in this view/vrf\n");
11050 }
11051
11052 if (type != show_peer && type != show_ipv4_peer &&
11053 type != show_ipv6_peer && !nbr_output && !use_json)
11054 vty_out(vty, "%% No BGP neighbors found\n");
11055
11056 if (use_json) {
11057 vty_out(vty, "%s\n", json_object_to_json_string_ext(
11058 json, JSON_C_TO_STRING_PRETTY));
11059 } else {
11060 vty_out(vty, "\n");
11061 }
11062
11063 return CMD_SUCCESS;
11064 }
11065
11066 static void bgp_show_all_instances_neighbors_vty(struct vty *vty,
11067 enum show_type type,
11068 const char *ip_str,
11069 bool use_json)
11070 {
11071 struct listnode *node, *nnode;
11072 struct bgp *bgp;
11073 union sockunion su;
11074 json_object *json = NULL;
11075 int ret, is_first = 1;
11076 bool nbr_output = false;
11077
11078 if (use_json)
11079 vty_out(vty, "{\n");
11080
11081 for (ALL_LIST_ELEMENTS(bm->bgp, node, nnode, bgp)) {
11082 nbr_output = true;
11083 if (use_json) {
11084 if (!(json = json_object_new_object())) {
11085 flog_err(
11086 EC_BGP_JSON_MEM_ERROR,
11087 "Unable to allocate memory for JSON object");
11088 vty_out(vty,
11089 "{\"error\": {\"message:\": \"Unable to allocate memory for JSON object\"}}}\n");
11090 return;
11091 }
11092
11093 json_object_int_add(json, "vrfId",
11094 (bgp->vrf_id == VRF_UNKNOWN)
11095 ? -1
11096 : (int64_t)bgp->vrf_id);
11097 json_object_string_add(
11098 json, "vrfName",
11099 (bgp->inst_type == BGP_INSTANCE_TYPE_DEFAULT)
11100 ? VRF_DEFAULT_NAME
11101 : bgp->name);
11102
11103 if (!is_first)
11104 vty_out(vty, ",\n");
11105 else
11106 is_first = 0;
11107
11108 vty_out(vty, "\"%s\":",
11109 (bgp->inst_type == BGP_INSTANCE_TYPE_DEFAULT)
11110 ? VRF_DEFAULT_NAME
11111 : bgp->name);
11112 } else {
11113 vty_out(vty, "\nInstance %s:\n",
11114 (bgp->inst_type == BGP_INSTANCE_TYPE_DEFAULT)
11115 ? VRF_DEFAULT_NAME
11116 : bgp->name);
11117 }
11118
11119 if (type == show_peer || type == show_ipv4_peer ||
11120 type == show_ipv6_peer) {
11121 ret = str2sockunion(ip_str, &su);
11122 if (ret < 0)
11123 bgp_show_neighbor(vty, bgp, type, NULL, ip_str,
11124 use_json, json);
11125 else
11126 bgp_show_neighbor(vty, bgp, type, &su, NULL,
11127 use_json, json);
11128 } else {
11129 bgp_show_neighbor(vty, bgp, type, NULL, NULL,
11130 use_json, json);
11131 }
11132 json_object_free(json);
11133 }
11134
11135 if (use_json) {
11136 vty_out(vty, "}\n");
11137 json_object_free(json);
11138 }
11139 else if (!nbr_output)
11140 vty_out(vty, "%% BGP instance not found\n");
11141 }
11142
11143 static int bgp_show_neighbor_vty(struct vty *vty, const char *name,
11144 enum show_type type, const char *ip_str,
11145 bool use_json)
11146 {
11147 int ret;
11148 struct bgp *bgp;
11149 union sockunion su;
11150 json_object *json = NULL;
11151
11152 if (name) {
11153 if (strmatch(name, "all")) {
11154 bgp_show_all_instances_neighbors_vty(vty, type, ip_str,
11155 use_json);
11156 return CMD_SUCCESS;
11157 } else {
11158 bgp = bgp_lookup_by_name(name);
11159 if (!bgp) {
11160 if (use_json) {
11161 json = json_object_new_object();
11162 vty_out(vty, "%s\n",
11163 json_object_to_json_string_ext(
11164 json,
11165 JSON_C_TO_STRING_PRETTY));
11166 json_object_free(json);
11167 } else
11168 vty_out(vty,
11169 "%% BGP instance not found\n");
11170
11171 return CMD_WARNING;
11172 }
11173 }
11174 } else {
11175 bgp = bgp_get_default();
11176 }
11177
11178 if (bgp) {
11179 json = json_object_new_object();
11180 if (ip_str) {
11181 ret = str2sockunion(ip_str, &su);
11182 if (ret < 0)
11183 bgp_show_neighbor(vty, bgp, type, NULL, ip_str,
11184 use_json, json);
11185 else
11186 bgp_show_neighbor(vty, bgp, type, &su, NULL,
11187 use_json, json);
11188 } else {
11189 bgp_show_neighbor(vty, bgp, type, NULL, NULL, use_json,
11190 json);
11191 }
11192 json_object_free(json);
11193 } else {
11194 if (use_json)
11195 vty_out(vty, "{}\n");
11196 else
11197 vty_out(vty, "%% BGP instance not found\n");
11198 }
11199
11200 return CMD_SUCCESS;
11201 }
11202
11203 /* "show [ip] bgp neighbors" commands. */
11204 DEFUN (show_ip_bgp_neighbors,
11205 show_ip_bgp_neighbors_cmd,
11206 "show [ip] bgp [<view|vrf> VIEWVRFNAME] [<ipv4|ipv6>] neighbors [<A.B.C.D|X:X::X:X|WORD>] [json]",
11207 SHOW_STR
11208 IP_STR
11209 BGP_STR
11210 BGP_INSTANCE_HELP_STR
11211 "Address Family\n"
11212 "Address Family\n"
11213 "Detailed information on TCP and BGP neighbor connections\n"
11214 "Neighbor to display information about\n"
11215 "Neighbor to display information about\n"
11216 "Neighbor on BGP configured interface\n"
11217 JSON_STR)
11218 {
11219 char *vrf = NULL;
11220 char *sh_arg = NULL;
11221 enum show_type sh_type;
11222 afi_t afi = AFI_MAX;
11223
11224 bool uj = use_json(argc, argv);
11225
11226 int idx = 0;
11227
11228 /* [<vrf> VIEWVRFNAME] */
11229 if (argv_find(argv, argc, "vrf", &idx)) {
11230 vrf = argv[idx + 1]->arg;
11231 if (vrf && strmatch(vrf, VRF_DEFAULT_NAME))
11232 vrf = NULL;
11233 } else if (argv_find(argv, argc, "view", &idx))
11234 /* [<view> VIEWVRFNAME] */
11235 vrf = argv[idx + 1]->arg;
11236
11237 idx++;
11238
11239 if (argv_find(argv, argc, "ipv4", &idx)) {
11240 sh_type = show_ipv4_all;
11241 afi = AFI_IP;
11242 } else if (argv_find(argv, argc, "ipv6", &idx)) {
11243 sh_type = show_ipv6_all;
11244 afi = AFI_IP6;
11245 } else {
11246 sh_type = show_all;
11247 }
11248
11249 if (argv_find(argv, argc, "A.B.C.D", &idx)
11250 || argv_find(argv, argc, "X:X::X:X", &idx)
11251 || argv_find(argv, argc, "WORD", &idx)) {
11252 sh_type = show_peer;
11253 sh_arg = argv[idx]->arg;
11254 }
11255
11256 if (sh_type == show_peer && afi == AFI_IP) {
11257 sh_type = show_ipv4_peer;
11258 } else if (sh_type == show_peer && afi == AFI_IP6) {
11259 sh_type = show_ipv6_peer;
11260 }
11261
11262 return bgp_show_neighbor_vty(vty, vrf, sh_type, sh_arg, uj);
11263 }
11264
11265 /* Show BGP's AS paths internal data. There are both `show [ip] bgp
11266 paths' and `show ip mbgp paths'. Those functions results are the
11267 same.*/
11268 DEFUN (show_ip_bgp_paths,
11269 show_ip_bgp_paths_cmd,
11270 "show [ip] bgp ["BGP_SAFI_CMD_STR"] paths",
11271 SHOW_STR
11272 IP_STR
11273 BGP_STR
11274 BGP_SAFI_HELP_STR
11275 "Path information\n")
11276 {
11277 vty_out(vty, "Address Refcnt Path\n");
11278 aspath_print_all_vty(vty);
11279 return CMD_SUCCESS;
11280 }
11281
11282 #include "hash.h"
11283
11284 static void community_show_all_iterator(struct hash_bucket *bucket,
11285 struct vty *vty)
11286 {
11287 struct community *com;
11288
11289 com = (struct community *)bucket->data;
11290 vty_out(vty, "[%p] (%ld) %s\n", (void *)com, com->refcnt,
11291 community_str(com, false));
11292 }
11293
11294 /* Show BGP's community internal data. */
11295 DEFUN (show_ip_bgp_community_info,
11296 show_ip_bgp_community_info_cmd,
11297 "show [ip] bgp community-info",
11298 SHOW_STR
11299 IP_STR
11300 BGP_STR
11301 "List all bgp community information\n")
11302 {
11303 vty_out(vty, "Address Refcnt Community\n");
11304
11305 hash_iterate(community_hash(),
11306 (void (*)(struct hash_bucket *,
11307 void *))community_show_all_iterator,
11308 vty);
11309
11310 return CMD_SUCCESS;
11311 }
11312
11313 static void lcommunity_show_all_iterator(struct hash_bucket *bucket,
11314 struct vty *vty)
11315 {
11316 struct lcommunity *lcom;
11317
11318 lcom = (struct lcommunity *)bucket->data;
11319 vty_out(vty, "[%p] (%ld) %s\n", (void *)lcom, lcom->refcnt,
11320 lcommunity_str(lcom, false));
11321 }
11322
11323 /* Show BGP's community internal data. */
11324 DEFUN (show_ip_bgp_lcommunity_info,
11325 show_ip_bgp_lcommunity_info_cmd,
11326 "show ip bgp large-community-info",
11327 SHOW_STR
11328 IP_STR
11329 BGP_STR
11330 "List all bgp large-community information\n")
11331 {
11332 vty_out(vty, "Address Refcnt Large-community\n");
11333
11334 hash_iterate(lcommunity_hash(),
11335 (void (*)(struct hash_bucket *,
11336 void *))lcommunity_show_all_iterator,
11337 vty);
11338
11339 return CMD_SUCCESS;
11340 }
11341
11342
11343 DEFUN (show_ip_bgp_attr_info,
11344 show_ip_bgp_attr_info_cmd,
11345 "show [ip] bgp attribute-info",
11346 SHOW_STR
11347 IP_STR
11348 BGP_STR
11349 "List all bgp attribute information\n")
11350 {
11351 attr_show_all(vty);
11352 return CMD_SUCCESS;
11353 }
11354
11355 static int bgp_show_route_leak_vty(struct vty *vty, const char *name,
11356 afi_t afi, safi_t safi,
11357 bool use_json, json_object *json)
11358 {
11359 struct bgp *bgp;
11360 struct listnode *node;
11361 char *vname;
11362 char buf1[INET6_ADDRSTRLEN];
11363 char *ecom_str;
11364 vpn_policy_direction_t dir;
11365
11366 if (json) {
11367 json_object *json_import_vrfs = NULL;
11368 json_object *json_export_vrfs = NULL;
11369
11370 bgp = name ? bgp_lookup_by_name(name) : bgp_get_default();
11371
11372 if (!bgp) {
11373 vty_out(vty, "%s\n",
11374 json_object_to_json_string_ext(
11375 json,
11376 JSON_C_TO_STRING_PRETTY));
11377 json_object_free(json);
11378
11379 return CMD_WARNING;
11380 }
11381
11382 /* Provide context for the block */
11383 json_object_string_add(json, "vrf", name ? name : "default");
11384 json_object_string_add(json, "afiSafi",
11385 afi_safi_print(afi, safi));
11386
11387 if (!CHECK_FLAG(bgp->af_flags[afi][safi],
11388 BGP_CONFIG_VRF_TO_VRF_IMPORT)) {
11389 json_object_string_add(json, "importFromVrfs", "none");
11390 json_object_string_add(json, "importRts", "none");
11391 } else {
11392 json_import_vrfs = json_object_new_array();
11393
11394 for (ALL_LIST_ELEMENTS_RO(
11395 bgp->vpn_policy[afi].import_vrf,
11396 node, vname))
11397 json_object_array_add(json_import_vrfs,
11398 json_object_new_string(vname));
11399
11400 dir = BGP_VPN_POLICY_DIR_FROMVPN;
11401 ecom_str = ecommunity_ecom2str(
11402 bgp->vpn_policy[afi].rtlist[dir],
11403 ECOMMUNITY_FORMAT_ROUTE_MAP, 0);
11404 json_object_object_add(json, "importFromVrfs",
11405 json_import_vrfs);
11406 json_object_string_add(json, "importRts", ecom_str);
11407
11408 XFREE(MTYPE_ECOMMUNITY_STR, ecom_str);
11409 }
11410
11411 if (!CHECK_FLAG(bgp->af_flags[afi][safi],
11412 BGP_CONFIG_VRF_TO_VRF_EXPORT)) {
11413 json_object_string_add(json, "exportToVrfs", "none");
11414 json_object_string_add(json, "routeDistinguisher",
11415 "none");
11416 json_object_string_add(json, "exportRts", "none");
11417 } else {
11418 json_export_vrfs = json_object_new_array();
11419
11420 for (ALL_LIST_ELEMENTS_RO(
11421 bgp->vpn_policy[afi].export_vrf,
11422 node, vname))
11423 json_object_array_add(json_export_vrfs,
11424 json_object_new_string(vname));
11425 json_object_object_add(json, "exportToVrfs",
11426 json_export_vrfs);
11427 json_object_string_add(json, "routeDistinguisher",
11428 prefix_rd2str(&bgp->vpn_policy[afi].tovpn_rd,
11429 buf1, RD_ADDRSTRLEN));
11430
11431 dir = BGP_VPN_POLICY_DIR_TOVPN;
11432 ecom_str = ecommunity_ecom2str(
11433 bgp->vpn_policy[afi].rtlist[dir],
11434 ECOMMUNITY_FORMAT_ROUTE_MAP, 0);
11435 json_object_string_add(json, "exportRts", ecom_str);
11436
11437 XFREE(MTYPE_ECOMMUNITY_STR, ecom_str);
11438 }
11439
11440 if (use_json) {
11441 vty_out(vty, "%s\n",
11442 json_object_to_json_string_ext(json,
11443 JSON_C_TO_STRING_PRETTY));
11444 json_object_free(json);
11445 }
11446 } else {
11447 bgp = name ? bgp_lookup_by_name(name) : bgp_get_default();
11448
11449 if (!bgp) {
11450 vty_out(vty, "%% No such BGP instance exist\n");
11451 return CMD_WARNING;
11452 }
11453
11454 if (!CHECK_FLAG(bgp->af_flags[afi][safi],
11455 BGP_CONFIG_VRF_TO_VRF_IMPORT))
11456 vty_out(vty,
11457 "This VRF is not importing %s routes from any other VRF\n",
11458 afi_safi_print(afi, safi));
11459 else {
11460 vty_out(vty,
11461 "This VRF is importing %s routes from the following VRFs:\n",
11462 afi_safi_print(afi, safi));
11463
11464 for (ALL_LIST_ELEMENTS_RO(
11465 bgp->vpn_policy[afi].import_vrf,
11466 node, vname))
11467 vty_out(vty, " %s\n", vname);
11468
11469 dir = BGP_VPN_POLICY_DIR_FROMVPN;
11470 ecom_str = ecommunity_ecom2str(
11471 bgp->vpn_policy[afi].rtlist[dir],
11472 ECOMMUNITY_FORMAT_ROUTE_MAP, 0);
11473 vty_out(vty, "Import RT(s): %s\n", ecom_str);
11474
11475 XFREE(MTYPE_ECOMMUNITY_STR, ecom_str);
11476 }
11477
11478 if (!CHECK_FLAG(bgp->af_flags[afi][safi],
11479 BGP_CONFIG_VRF_TO_VRF_EXPORT))
11480 vty_out(vty,
11481 "This VRF is not exporting %s routes to any other VRF\n",
11482 afi_safi_print(afi, safi));
11483 else {
11484 vty_out(vty,
11485 "This VRF is exporting %s routes to the following VRFs:\n",
11486 afi_safi_print(afi, safi));
11487
11488 for (ALL_LIST_ELEMENTS_RO(
11489 bgp->vpn_policy[afi].export_vrf,
11490 node, vname))
11491 vty_out(vty, " %s\n", vname);
11492
11493 vty_out(vty, "RD: %s\n",
11494 prefix_rd2str(&bgp->vpn_policy[afi].tovpn_rd,
11495 buf1, RD_ADDRSTRLEN));
11496
11497 dir = BGP_VPN_POLICY_DIR_TOVPN;
11498 ecom_str = ecommunity_ecom2str(
11499 bgp->vpn_policy[afi].rtlist[dir],
11500 ECOMMUNITY_FORMAT_ROUTE_MAP, 0);
11501 vty_out(vty, "Export RT: %s\n", ecom_str);
11502 XFREE(MTYPE_ECOMMUNITY_STR, ecom_str);
11503 }
11504 }
11505
11506 return CMD_SUCCESS;
11507 }
11508
11509 static int bgp_show_all_instance_route_leak_vty(struct vty *vty, afi_t afi,
11510 safi_t safi, bool use_json)
11511 {
11512 struct listnode *node, *nnode;
11513 struct bgp *bgp;
11514 char *vrf_name = NULL;
11515 json_object *json = NULL;
11516 json_object *json_vrf = NULL;
11517 json_object *json_vrfs = NULL;
11518
11519 if (use_json) {
11520 json = json_object_new_object();
11521 json_vrfs = json_object_new_object();
11522 }
11523
11524 for (ALL_LIST_ELEMENTS(bm->bgp, node, nnode, bgp)) {
11525
11526 if (bgp->inst_type != BGP_INSTANCE_TYPE_DEFAULT)
11527 vrf_name = bgp->name;
11528
11529 if (use_json) {
11530 json_vrf = json_object_new_object();
11531 } else {
11532 vty_out(vty, "\nInstance %s:\n",
11533 (bgp->inst_type == BGP_INSTANCE_TYPE_DEFAULT)
11534 ? VRF_DEFAULT_NAME : bgp->name);
11535 }
11536 bgp_show_route_leak_vty(vty, vrf_name, afi, safi, 0, json_vrf);
11537 if (use_json) {
11538 if (bgp->inst_type == BGP_INSTANCE_TYPE_DEFAULT)
11539 json_object_object_add(json_vrfs,
11540 VRF_DEFAULT_NAME, json_vrf);
11541 else
11542 json_object_object_add(json_vrfs, vrf_name,
11543 json_vrf);
11544 }
11545 }
11546
11547 if (use_json) {
11548 json_object_object_add(json, "vrfs", json_vrfs);
11549 vty_out(vty, "%s\n", json_object_to_json_string_ext(json,
11550 JSON_C_TO_STRING_PRETTY));
11551 json_object_free(json);
11552 }
11553
11554 return CMD_SUCCESS;
11555 }
11556
11557 /* "show [ip] bgp route-leak" command. */
11558 DEFUN (show_ip_bgp_route_leak,
11559 show_ip_bgp_route_leak_cmd,
11560 "show [ip] bgp [<view|vrf> VIEWVRFNAME] ["BGP_AFI_CMD_STR" ["BGP_SAFI_CMD_STR"]] route-leak [json]",
11561 SHOW_STR
11562 IP_STR
11563 BGP_STR
11564 BGP_INSTANCE_HELP_STR
11565 BGP_AFI_HELP_STR
11566 BGP_SAFI_HELP_STR
11567 "Route leaking information\n"
11568 JSON_STR)
11569 {
11570 char *vrf = NULL;
11571 afi_t afi = AFI_MAX;
11572 safi_t safi = SAFI_MAX;
11573
11574 bool uj = use_json(argc, argv);
11575 int idx = 0;
11576 json_object *json = NULL;
11577
11578 /* show [ip] bgp */
11579 if (argv_find(argv, argc, "ip", &idx)) {
11580 afi = AFI_IP;
11581 safi = SAFI_UNICAST;
11582 }
11583 /* [vrf VIEWVRFNAME] */
11584 if (argv_find(argv, argc, "view", &idx)) {
11585 vty_out(vty,
11586 "%% This command is not applicable to BGP views\n");
11587 return CMD_WARNING;
11588 }
11589
11590 if (argv_find(argv, argc, "vrf", &idx)) {
11591 vrf = argv[idx + 1]->arg;
11592 if (vrf && strmatch(vrf, VRF_DEFAULT_NAME))
11593 vrf = NULL;
11594 }
11595 /* ["BGP_AFI_CMD_STR" ["BGP_SAFI_CMD_STR"]] */
11596 if (argv_find_and_parse_afi(argv, argc, &idx, &afi)) {
11597 argv_find_and_parse_safi(argv, argc, &idx, &safi);
11598 }
11599
11600 if (!((afi == AFI_IP || afi == AFI_IP6) && safi == SAFI_UNICAST)) {
11601 vty_out(vty,
11602 "%% This command is applicable only for unicast ipv4|ipv6\n");
11603 return CMD_WARNING;
11604 }
11605
11606 if (vrf && strmatch(vrf, "all"))
11607 return bgp_show_all_instance_route_leak_vty(vty, afi, safi, uj);
11608
11609 if (uj)
11610 json = json_object_new_object();
11611
11612 return bgp_show_route_leak_vty(vty, vrf, afi, safi, uj, json);
11613 }
11614
11615 static void bgp_show_all_instances_updgrps_vty(struct vty *vty, afi_t afi,
11616 safi_t safi)
11617 {
11618 struct listnode *node, *nnode;
11619 struct bgp *bgp;
11620
11621 for (ALL_LIST_ELEMENTS(bm->bgp, node, nnode, bgp)) {
11622 vty_out(vty, "\nInstance %s:\n",
11623 (bgp->inst_type == BGP_INSTANCE_TYPE_DEFAULT)
11624 ? VRF_DEFAULT_NAME
11625 : bgp->name);
11626 update_group_show(bgp, afi, safi, vty, 0);
11627 }
11628 }
11629
11630 static int bgp_show_update_groups(struct vty *vty, const char *name, int afi,
11631 int safi, uint64_t subgrp_id)
11632 {
11633 struct bgp *bgp;
11634
11635 if (name) {
11636 if (strmatch(name, "all")) {
11637 bgp_show_all_instances_updgrps_vty(vty, afi, safi);
11638 return CMD_SUCCESS;
11639 } else {
11640 bgp = bgp_lookup_by_name(name);
11641 }
11642 } else {
11643 bgp = bgp_get_default();
11644 }
11645
11646 if (bgp)
11647 update_group_show(bgp, afi, safi, vty, subgrp_id);
11648 return CMD_SUCCESS;
11649 }
11650
11651 DEFUN (show_ip_bgp_updgrps,
11652 show_ip_bgp_updgrps_cmd,
11653 "show [ip] bgp [<view|vrf> VIEWVRFNAME] ["BGP_AFI_CMD_STR" ["BGP_SAFI_WITH_LABEL_CMD_STR"]] update-groups [SUBGROUP-ID]",
11654 SHOW_STR
11655 IP_STR
11656 BGP_STR
11657 BGP_INSTANCE_HELP_STR
11658 BGP_AFI_HELP_STR
11659 BGP_SAFI_WITH_LABEL_HELP_STR
11660 "Detailed info about dynamic update groups\n"
11661 "Specific subgroup to display detailed info for\n")
11662 {
11663 char *vrf = NULL;
11664 afi_t afi = AFI_IP6;
11665 safi_t safi = SAFI_UNICAST;
11666 uint64_t subgrp_id = 0;
11667
11668 int idx = 0;
11669
11670 /* show [ip] bgp */
11671 if (argv_find(argv, argc, "ip", &idx))
11672 afi = AFI_IP;
11673 /* [<vrf> VIEWVRFNAME] */
11674 if (argv_find(argv, argc, "vrf", &idx)) {
11675 vrf = argv[idx + 1]->arg;
11676 if (vrf && strmatch(vrf, VRF_DEFAULT_NAME))
11677 vrf = NULL;
11678 } else if (argv_find(argv, argc, "view", &idx))
11679 /* [<view> VIEWVRFNAME] */
11680 vrf = argv[idx + 1]->arg;
11681 /* ["BGP_AFI_CMD_STR" ["BGP_SAFI_CMD_STR"]] */
11682 if (argv_find_and_parse_afi(argv, argc, &idx, &afi)) {
11683 argv_find_and_parse_safi(argv, argc, &idx, &safi);
11684 }
11685
11686 /* get subgroup id, if provided */
11687 idx = argc - 1;
11688 if (argv[idx]->type == VARIABLE_TKN)
11689 subgrp_id = strtoull(argv[idx]->arg, NULL, 10);
11690
11691 return (bgp_show_update_groups(vty, vrf, afi, safi, subgrp_id));
11692 }
11693
11694 DEFUN (show_bgp_instance_all_ipv6_updgrps,
11695 show_bgp_instance_all_ipv6_updgrps_cmd,
11696 "show [ip] bgp <view|vrf> all update-groups",
11697 SHOW_STR
11698 IP_STR
11699 BGP_STR
11700 BGP_INSTANCE_ALL_HELP_STR
11701 "Detailed info about dynamic update groups\n")
11702 {
11703 bgp_show_all_instances_updgrps_vty(vty, AFI_IP6, SAFI_UNICAST);
11704 return CMD_SUCCESS;
11705 }
11706
11707 DEFUN (show_bgp_l2vpn_evpn_updgrps,
11708 show_bgp_l2vpn_evpn_updgrps_cmd,
11709 "show [ip] bgp l2vpn evpn update-groups",
11710 SHOW_STR
11711 IP_STR
11712 BGP_STR
11713 "l2vpn address family\n"
11714 "evpn sub-address family\n"
11715 "Detailed info about dynamic update groups\n")
11716 {
11717 char *vrf = NULL;
11718 uint64_t subgrp_id = 0;
11719
11720 bgp_show_update_groups(vty, vrf, AFI_L2VPN, SAFI_EVPN, subgrp_id);
11721 return CMD_SUCCESS;
11722 }
11723
11724 DEFUN (show_bgp_updgrps_stats,
11725 show_bgp_updgrps_stats_cmd,
11726 "show [ip] bgp update-groups statistics",
11727 SHOW_STR
11728 IP_STR
11729 BGP_STR
11730 "Detailed info about dynamic update groups\n"
11731 "Statistics\n")
11732 {
11733 struct bgp *bgp;
11734
11735 bgp = bgp_get_default();
11736 if (bgp)
11737 update_group_show_stats(bgp, vty);
11738
11739 return CMD_SUCCESS;
11740 }
11741
11742 DEFUN (show_bgp_instance_updgrps_stats,
11743 show_bgp_instance_updgrps_stats_cmd,
11744 "show [ip] bgp <view|vrf> VIEWVRFNAME update-groups statistics",
11745 SHOW_STR
11746 IP_STR
11747 BGP_STR
11748 BGP_INSTANCE_HELP_STR
11749 "Detailed info about dynamic update groups\n"
11750 "Statistics\n")
11751 {
11752 int idx_word = 3;
11753 struct bgp *bgp;
11754
11755 bgp = bgp_lookup_by_name(argv[idx_word]->arg);
11756 if (bgp)
11757 update_group_show_stats(bgp, vty);
11758
11759 return CMD_SUCCESS;
11760 }
11761
11762 static void show_bgp_updgrps_adj_info_aux(struct vty *vty, const char *name,
11763 afi_t afi, safi_t safi,
11764 const char *what, uint64_t subgrp_id)
11765 {
11766 struct bgp *bgp;
11767
11768 if (name)
11769 bgp = bgp_lookup_by_name(name);
11770 else
11771 bgp = bgp_get_default();
11772
11773 if (bgp) {
11774 if (!strcmp(what, "advertise-queue"))
11775 update_group_show_adj_queue(bgp, afi, safi, vty,
11776 subgrp_id);
11777 else if (!strcmp(what, "advertised-routes"))
11778 update_group_show_advertised(bgp, afi, safi, vty,
11779 subgrp_id);
11780 else if (!strcmp(what, "packet-queue"))
11781 update_group_show_packet_queue(bgp, afi, safi, vty,
11782 subgrp_id);
11783 }
11784 }
11785
11786 DEFPY(show_ip_bgp_instance_updgrps_adj_s,
11787 show_ip_bgp_instance_updgrps_adj_s_cmd,
11788 "show [ip]$ip bgp [<view|vrf> VIEWVRFNAME$vrf] [<ipv4|ipv6>$afi <unicast|multicast|vpn>$safi] update-groups [SUBGROUP-ID]$sgid <advertise-queue|advertised-routes|packet-queue>$rtq",
11789 SHOW_STR IP_STR BGP_STR BGP_INSTANCE_HELP_STR BGP_AFI_HELP_STR
11790 BGP_SAFI_HELP_STR
11791 "Detailed info about dynamic update groups\n"
11792 "Specific subgroup to display info for\n"
11793 "Advertisement queue\n"
11794 "Announced routes\n"
11795 "Packet queue\n")
11796 {
11797 uint64_t subgrp_id = 0;
11798 afi_t afiz;
11799 safi_t safiz;
11800 if (sgid)
11801 subgrp_id = strtoull(sgid, NULL, 10);
11802
11803 if (!ip && !afi)
11804 afiz = AFI_IP6;
11805 if (!ip && afi)
11806 afiz = bgp_vty_afi_from_str(afi);
11807 if (ip && !afi)
11808 afiz = AFI_IP;
11809 if (ip && afi) {
11810 afiz = bgp_vty_afi_from_str(afi);
11811 if (afiz != AFI_IP)
11812 vty_out(vty,
11813 "%% Cannot specify both 'ip' and 'ipv6'\n");
11814 return CMD_WARNING;
11815 }
11816
11817 safiz = safi ? bgp_vty_safi_from_str(safi) : SAFI_UNICAST;
11818
11819 show_bgp_updgrps_adj_info_aux(vty, vrf, afiz, safiz, rtq, subgrp_id);
11820 return CMD_SUCCESS;
11821 }
11822
11823 static int bgp_show_one_peer_group(struct vty *vty, struct peer_group *group)
11824 {
11825 struct listnode *node, *nnode;
11826 struct prefix *range;
11827 struct peer *conf;
11828 struct peer *peer;
11829 char buf[PREFIX2STR_BUFFER];
11830 afi_t afi;
11831 safi_t safi;
11832 const char *peer_status;
11833 const char *af_str;
11834 int lr_count;
11835 int dynamic;
11836 int af_cfgd;
11837
11838 conf = group->conf;
11839
11840 if (conf->as_type == AS_SPECIFIED || conf->as_type == AS_EXTERNAL) {
11841 vty_out(vty, "\nBGP peer-group %s, remote AS %" PRIu32 "\n",
11842 group->name, conf->as);
11843 } else if (conf->as_type == AS_INTERNAL) {
11844 vty_out(vty, "\nBGP peer-group %s, remote AS %" PRIu32 "\n",
11845 group->name, group->bgp->as);
11846 } else {
11847 vty_out(vty, "\nBGP peer-group %s\n", group->name);
11848 }
11849
11850 if ((group->bgp->as == conf->as) || (conf->as_type == AS_INTERNAL))
11851 vty_out(vty, " Peer-group type is internal\n");
11852 else
11853 vty_out(vty, " Peer-group type is external\n");
11854
11855 /* Display AFs configured. */
11856 vty_out(vty, " Configured address-families:");
11857 FOREACH_AFI_SAFI (afi, safi) {
11858 if (conf->afc[afi][safi]) {
11859 af_cfgd = 1;
11860 vty_out(vty, " %s;", afi_safi_print(afi, safi));
11861 }
11862 }
11863 if (!af_cfgd)
11864 vty_out(vty, " none\n");
11865 else
11866 vty_out(vty, "\n");
11867
11868 /* Display listen ranges (for dynamic neighbors), if any */
11869 for (afi = AFI_IP; afi < AFI_MAX; afi++) {
11870 if (afi == AFI_IP)
11871 af_str = "IPv4";
11872 else if (afi == AFI_IP6)
11873 af_str = "IPv6";
11874 else
11875 af_str = "???";
11876 lr_count = listcount(group->listen_range[afi]);
11877 if (lr_count) {
11878 vty_out(vty, " %d %s listen range(s)\n", lr_count,
11879 af_str);
11880
11881
11882 for (ALL_LIST_ELEMENTS(group->listen_range[afi], node,
11883 nnode, range)) {
11884 prefix2str(range, buf, sizeof(buf));
11885 vty_out(vty, " %s\n", buf);
11886 }
11887 }
11888 }
11889
11890 /* Display group members and their status */
11891 if (listcount(group->peer)) {
11892 vty_out(vty, " Peer-group members:\n");
11893 for (ALL_LIST_ELEMENTS(group->peer, node, nnode, peer)) {
11894 if (CHECK_FLAG(peer->flags, PEER_FLAG_SHUTDOWN))
11895 peer_status = "Idle (Admin)";
11896 else if (CHECK_FLAG(peer->sflags,
11897 PEER_STATUS_PREFIX_OVERFLOW))
11898 peer_status = "Idle (PfxCt)";
11899 else
11900 peer_status = lookup_msg(bgp_status_msg,
11901 peer->status, NULL);
11902
11903 dynamic = peer_dynamic_neighbor(peer);
11904 vty_out(vty, " %s %s %s \n", peer->host,
11905 dynamic ? "(dynamic)" : "", peer_status);
11906 }
11907 }
11908
11909 return CMD_SUCCESS;
11910 }
11911
11912 static int bgp_show_peer_group_vty(struct vty *vty, const char *name,
11913 const char *group_name)
11914 {
11915 struct bgp *bgp;
11916 struct listnode *node, *nnode;
11917 struct peer_group *group;
11918 bool found = false;
11919
11920 bgp = name ? bgp_lookup_by_name(name) : bgp_get_default();
11921
11922 if (!bgp) {
11923 vty_out(vty, "%% BGP instance not found\n");
11924 return CMD_WARNING;
11925 }
11926
11927 for (ALL_LIST_ELEMENTS(bgp->group, node, nnode, group)) {
11928 if (group_name) {
11929 if (strmatch(group->name, group_name)) {
11930 bgp_show_one_peer_group(vty, group);
11931 found = true;
11932 break;
11933 }
11934 } else {
11935 bgp_show_one_peer_group(vty, group);
11936 }
11937 }
11938
11939 if (group_name && !found)
11940 vty_out(vty, "%% No such peer-group\n");
11941
11942 return CMD_SUCCESS;
11943 }
11944
11945 DEFUN (show_ip_bgp_peer_groups,
11946 show_ip_bgp_peer_groups_cmd,
11947 "show [ip] bgp [<view|vrf> VIEWVRFNAME] peer-group [PGNAME]",
11948 SHOW_STR
11949 IP_STR
11950 BGP_STR
11951 BGP_INSTANCE_HELP_STR
11952 "Detailed information on BGP peer groups\n"
11953 "Peer group name\n")
11954 {
11955 char *vrf, *pg;
11956 int idx = 0;
11957
11958 vrf = argv_find(argv, argc, "VIEWVRFNAME", &idx) ? argv[idx]->arg
11959 : NULL;
11960 pg = argv_find(argv, argc, "PGNAME", &idx) ? argv[idx]->arg : NULL;
11961
11962 return bgp_show_peer_group_vty(vty, vrf, pg);
11963 }
11964
11965
11966 /* Redistribute VTY commands. */
11967
11968 DEFUN (bgp_redistribute_ipv4,
11969 bgp_redistribute_ipv4_cmd,
11970 "redistribute " FRR_IP_REDIST_STR_BGPD,
11971 "Redistribute information from another routing protocol\n"
11972 FRR_IP_REDIST_HELP_STR_BGPD)
11973 {
11974 VTY_DECLVAR_CONTEXT(bgp, bgp);
11975 int idx_protocol = 1;
11976 int type;
11977
11978 type = proto_redistnum(AFI_IP, argv[idx_protocol]->text);
11979 if (type < 0) {
11980 vty_out(vty, "%% Invalid route type\n");
11981 return CMD_WARNING_CONFIG_FAILED;
11982 }
11983
11984 bgp_redist_add(bgp, AFI_IP, type, 0);
11985 return bgp_redistribute_set(bgp, AFI_IP, type, 0, false);
11986 }
11987
11988 ALIAS_HIDDEN(
11989 bgp_redistribute_ipv4, bgp_redistribute_ipv4_hidden_cmd,
11990 "redistribute " FRR_IP_REDIST_STR_BGPD,
11991 "Redistribute information from another routing protocol\n" FRR_IP_REDIST_HELP_STR_BGPD)
11992
11993 DEFUN (bgp_redistribute_ipv4_rmap,
11994 bgp_redistribute_ipv4_rmap_cmd,
11995 "redistribute " FRR_IP_REDIST_STR_BGPD " route-map WORD",
11996 "Redistribute information from another routing protocol\n"
11997 FRR_IP_REDIST_HELP_STR_BGPD
11998 "Route map reference\n"
11999 "Pointer to route-map entries\n")
12000 {
12001 VTY_DECLVAR_CONTEXT(bgp, bgp);
12002 int idx_protocol = 1;
12003 int idx_word = 3;
12004 int type;
12005 struct bgp_redist *red;
12006 bool changed;
12007 struct route_map *route_map = route_map_lookup_warn_noexist(
12008 vty, argv[idx_word]->arg);
12009
12010 type = proto_redistnum(AFI_IP, argv[idx_protocol]->text);
12011 if (type < 0) {
12012 vty_out(vty, "%% Invalid route type\n");
12013 return CMD_WARNING_CONFIG_FAILED;
12014 }
12015
12016 red = bgp_redist_add(bgp, AFI_IP, type, 0);
12017 changed =
12018 bgp_redistribute_rmap_set(red, argv[idx_word]->arg, route_map);
12019 return bgp_redistribute_set(bgp, AFI_IP, type, 0, changed);
12020 }
12021
12022 ALIAS_HIDDEN(
12023 bgp_redistribute_ipv4_rmap, bgp_redistribute_ipv4_rmap_hidden_cmd,
12024 "redistribute " FRR_IP_REDIST_STR_BGPD " route-map WORD",
12025 "Redistribute information from another routing protocol\n" FRR_IP_REDIST_HELP_STR_BGPD
12026 "Route map reference\n"
12027 "Pointer to route-map entries\n")
12028
12029 DEFUN (bgp_redistribute_ipv4_metric,
12030 bgp_redistribute_ipv4_metric_cmd,
12031 "redistribute " FRR_IP_REDIST_STR_BGPD " metric (0-4294967295)",
12032 "Redistribute information from another routing protocol\n"
12033 FRR_IP_REDIST_HELP_STR_BGPD
12034 "Metric for redistributed routes\n"
12035 "Default metric\n")
12036 {
12037 VTY_DECLVAR_CONTEXT(bgp, bgp);
12038 int idx_protocol = 1;
12039 int idx_number = 3;
12040 int type;
12041 uint32_t metric;
12042 struct bgp_redist *red;
12043 bool changed;
12044
12045 type = proto_redistnum(AFI_IP, argv[idx_protocol]->text);
12046 if (type < 0) {
12047 vty_out(vty, "%% Invalid route type\n");
12048 return CMD_WARNING_CONFIG_FAILED;
12049 }
12050 metric = strtoul(argv[idx_number]->arg, NULL, 10);
12051
12052 red = bgp_redist_add(bgp, AFI_IP, type, 0);
12053 changed = bgp_redistribute_metric_set(bgp, red, AFI_IP, type, metric);
12054 return bgp_redistribute_set(bgp, AFI_IP, type, 0, changed);
12055 }
12056
12057 ALIAS_HIDDEN(
12058 bgp_redistribute_ipv4_metric, bgp_redistribute_ipv4_metric_hidden_cmd,
12059 "redistribute " FRR_IP_REDIST_STR_BGPD " metric (0-4294967295)",
12060 "Redistribute information from another routing protocol\n" FRR_IP_REDIST_HELP_STR_BGPD
12061 "Metric for redistributed routes\n"
12062 "Default metric\n")
12063
12064 DEFUN (bgp_redistribute_ipv4_rmap_metric,
12065 bgp_redistribute_ipv4_rmap_metric_cmd,
12066 "redistribute " FRR_IP_REDIST_STR_BGPD " route-map WORD metric (0-4294967295)",
12067 "Redistribute information from another routing protocol\n"
12068 FRR_IP_REDIST_HELP_STR_BGPD
12069 "Route map reference\n"
12070 "Pointer to route-map entries\n"
12071 "Metric for redistributed routes\n"
12072 "Default metric\n")
12073 {
12074 VTY_DECLVAR_CONTEXT(bgp, bgp);
12075 int idx_protocol = 1;
12076 int idx_word = 3;
12077 int idx_number = 5;
12078 int type;
12079 uint32_t metric;
12080 struct bgp_redist *red;
12081 bool changed;
12082 struct route_map *route_map =
12083 route_map_lookup_warn_noexist(vty, argv[idx_word]->arg);
12084
12085 type = proto_redistnum(AFI_IP, argv[idx_protocol]->text);
12086 if (type < 0) {
12087 vty_out(vty, "%% Invalid route type\n");
12088 return CMD_WARNING_CONFIG_FAILED;
12089 }
12090 metric = strtoul(argv[idx_number]->arg, NULL, 10);
12091
12092 red = bgp_redist_add(bgp, AFI_IP, type, 0);
12093 changed =
12094 bgp_redistribute_rmap_set(red, argv[idx_word]->arg, route_map);
12095 changed |= bgp_redistribute_metric_set(bgp, red, AFI_IP, type, metric);
12096 return bgp_redistribute_set(bgp, AFI_IP, type, 0, changed);
12097 }
12098
12099 ALIAS_HIDDEN(
12100 bgp_redistribute_ipv4_rmap_metric,
12101 bgp_redistribute_ipv4_rmap_metric_hidden_cmd,
12102 "redistribute " FRR_IP_REDIST_STR_BGPD
12103 " route-map WORD metric (0-4294967295)",
12104 "Redistribute information from another routing protocol\n" FRR_IP_REDIST_HELP_STR_BGPD
12105 "Route map reference\n"
12106 "Pointer to route-map entries\n"
12107 "Metric for redistributed routes\n"
12108 "Default metric\n")
12109
12110 DEFUN (bgp_redistribute_ipv4_metric_rmap,
12111 bgp_redistribute_ipv4_metric_rmap_cmd,
12112 "redistribute " FRR_IP_REDIST_STR_BGPD " metric (0-4294967295) route-map WORD",
12113 "Redistribute information from another routing protocol\n"
12114 FRR_IP_REDIST_HELP_STR_BGPD
12115 "Metric for redistributed routes\n"
12116 "Default metric\n"
12117 "Route map reference\n"
12118 "Pointer to route-map entries\n")
12119 {
12120 VTY_DECLVAR_CONTEXT(bgp, bgp);
12121 int idx_protocol = 1;
12122 int idx_number = 3;
12123 int idx_word = 5;
12124 int type;
12125 uint32_t metric;
12126 struct bgp_redist *red;
12127 bool changed;
12128 struct route_map *route_map =
12129 route_map_lookup_warn_noexist(vty, argv[idx_word]->arg);
12130
12131 type = proto_redistnum(AFI_IP, argv[idx_protocol]->text);
12132 if (type < 0) {
12133 vty_out(vty, "%% Invalid route type\n");
12134 return CMD_WARNING_CONFIG_FAILED;
12135 }
12136 metric = strtoul(argv[idx_number]->arg, NULL, 10);
12137
12138 red = bgp_redist_add(bgp, AFI_IP, type, 0);
12139 changed = bgp_redistribute_metric_set(bgp, red, AFI_IP, type, metric);
12140 changed |=
12141 bgp_redistribute_rmap_set(red, argv[idx_word]->arg, route_map);
12142 return bgp_redistribute_set(bgp, AFI_IP, type, 0, changed);
12143 }
12144
12145 ALIAS_HIDDEN(
12146 bgp_redistribute_ipv4_metric_rmap,
12147 bgp_redistribute_ipv4_metric_rmap_hidden_cmd,
12148 "redistribute " FRR_IP_REDIST_STR_BGPD
12149 " metric (0-4294967295) route-map WORD",
12150 "Redistribute information from another routing protocol\n" FRR_IP_REDIST_HELP_STR_BGPD
12151 "Metric for redistributed routes\n"
12152 "Default metric\n"
12153 "Route map reference\n"
12154 "Pointer to route-map entries\n")
12155
12156 DEFUN (bgp_redistribute_ipv4_ospf,
12157 bgp_redistribute_ipv4_ospf_cmd,
12158 "redistribute <ospf|table> (1-65535)",
12159 "Redistribute information from another routing protocol\n"
12160 "Open Shortest Path First (OSPFv2)\n"
12161 "Non-main Kernel Routing Table\n"
12162 "Instance ID/Table ID\n")
12163 {
12164 VTY_DECLVAR_CONTEXT(bgp, bgp);
12165 int idx_ospf_table = 1;
12166 int idx_number = 2;
12167 unsigned short instance;
12168 unsigned short protocol;
12169
12170 instance = strtoul(argv[idx_number]->arg, NULL, 10);
12171
12172 if (strncmp(argv[idx_ospf_table]->arg, "o", 1) == 0)
12173 protocol = ZEBRA_ROUTE_OSPF;
12174 else
12175 protocol = ZEBRA_ROUTE_TABLE;
12176
12177 bgp_redist_add(bgp, AFI_IP, protocol, instance);
12178 return bgp_redistribute_set(bgp, AFI_IP, protocol, instance, false);
12179 }
12180
12181 ALIAS_HIDDEN(bgp_redistribute_ipv4_ospf, bgp_redistribute_ipv4_ospf_hidden_cmd,
12182 "redistribute <ospf|table> (1-65535)",
12183 "Redistribute information from another routing protocol\n"
12184 "Open Shortest Path First (OSPFv2)\n"
12185 "Non-main Kernel Routing Table\n"
12186 "Instance ID/Table ID\n")
12187
12188 DEFUN (bgp_redistribute_ipv4_ospf_rmap,
12189 bgp_redistribute_ipv4_ospf_rmap_cmd,
12190 "redistribute <ospf|table> (1-65535) route-map WORD",
12191 "Redistribute information from another routing protocol\n"
12192 "Open Shortest Path First (OSPFv2)\n"
12193 "Non-main Kernel Routing Table\n"
12194 "Instance ID/Table ID\n"
12195 "Route map reference\n"
12196 "Pointer to route-map entries\n")
12197 {
12198 VTY_DECLVAR_CONTEXT(bgp, bgp);
12199 int idx_ospf_table = 1;
12200 int idx_number = 2;
12201 int idx_word = 4;
12202 struct bgp_redist *red;
12203 unsigned short instance;
12204 int protocol;
12205 bool changed;
12206 struct route_map *route_map =
12207 route_map_lookup_warn_noexist(vty, argv[idx_word]->arg);
12208
12209 if (strncmp(argv[idx_ospf_table]->arg, "o", 1) == 0)
12210 protocol = ZEBRA_ROUTE_OSPF;
12211 else
12212 protocol = ZEBRA_ROUTE_TABLE;
12213
12214 instance = strtoul(argv[idx_number]->arg, NULL, 10);
12215 red = bgp_redist_add(bgp, AFI_IP, protocol, instance);
12216 changed =
12217 bgp_redistribute_rmap_set(red, argv[idx_word]->arg, route_map);
12218 return bgp_redistribute_set(bgp, AFI_IP, protocol, instance, changed);
12219 }
12220
12221 ALIAS_HIDDEN(bgp_redistribute_ipv4_ospf_rmap,
12222 bgp_redistribute_ipv4_ospf_rmap_hidden_cmd,
12223 "redistribute <ospf|table> (1-65535) route-map WORD",
12224 "Redistribute information from another routing protocol\n"
12225 "Open Shortest Path First (OSPFv2)\n"
12226 "Non-main Kernel Routing Table\n"
12227 "Instance ID/Table ID\n"
12228 "Route map reference\n"
12229 "Pointer to route-map entries\n")
12230
12231 DEFUN (bgp_redistribute_ipv4_ospf_metric,
12232 bgp_redistribute_ipv4_ospf_metric_cmd,
12233 "redistribute <ospf|table> (1-65535) metric (0-4294967295)",
12234 "Redistribute information from another routing protocol\n"
12235 "Open Shortest Path First (OSPFv2)\n"
12236 "Non-main Kernel Routing Table\n"
12237 "Instance ID/Table ID\n"
12238 "Metric for redistributed routes\n"
12239 "Default metric\n")
12240 {
12241 VTY_DECLVAR_CONTEXT(bgp, bgp);
12242 int idx_ospf_table = 1;
12243 int idx_number = 2;
12244 int idx_number_2 = 4;
12245 uint32_t metric;
12246 struct bgp_redist *red;
12247 unsigned short instance;
12248 int protocol;
12249 bool changed;
12250
12251 if (strncmp(argv[idx_ospf_table]->arg, "o", 1) == 0)
12252 protocol = ZEBRA_ROUTE_OSPF;
12253 else
12254 protocol = ZEBRA_ROUTE_TABLE;
12255
12256 instance = strtoul(argv[idx_number]->arg, NULL, 10);
12257 metric = strtoul(argv[idx_number_2]->arg, NULL, 10);
12258
12259 red = bgp_redist_add(bgp, AFI_IP, protocol, instance);
12260 changed = bgp_redistribute_metric_set(bgp, red, AFI_IP, protocol,
12261 metric);
12262 return bgp_redistribute_set(bgp, AFI_IP, protocol, instance, changed);
12263 }
12264
12265 ALIAS_HIDDEN(bgp_redistribute_ipv4_ospf_metric,
12266 bgp_redistribute_ipv4_ospf_metric_hidden_cmd,
12267 "redistribute <ospf|table> (1-65535) metric (0-4294967295)",
12268 "Redistribute information from another routing protocol\n"
12269 "Open Shortest Path First (OSPFv2)\n"
12270 "Non-main Kernel Routing Table\n"
12271 "Instance ID/Table ID\n"
12272 "Metric for redistributed routes\n"
12273 "Default metric\n")
12274
12275 DEFUN (bgp_redistribute_ipv4_ospf_rmap_metric,
12276 bgp_redistribute_ipv4_ospf_rmap_metric_cmd,
12277 "redistribute <ospf|table> (1-65535) route-map WORD metric (0-4294967295)",
12278 "Redistribute information from another routing protocol\n"
12279 "Open Shortest Path First (OSPFv2)\n"
12280 "Non-main Kernel Routing Table\n"
12281 "Instance ID/Table ID\n"
12282 "Route map reference\n"
12283 "Pointer to route-map entries\n"
12284 "Metric for redistributed routes\n"
12285 "Default metric\n")
12286 {
12287 VTY_DECLVAR_CONTEXT(bgp, bgp);
12288 int idx_ospf_table = 1;
12289 int idx_number = 2;
12290 int idx_word = 4;
12291 int idx_number_2 = 6;
12292 uint32_t metric;
12293 struct bgp_redist *red;
12294 unsigned short instance;
12295 int protocol;
12296 bool changed;
12297 struct route_map *route_map =
12298 route_map_lookup_warn_noexist(vty, argv[idx_word]->arg);
12299
12300 if (strncmp(argv[idx_ospf_table]->arg, "o", 1) == 0)
12301 protocol = ZEBRA_ROUTE_OSPF;
12302 else
12303 protocol = ZEBRA_ROUTE_TABLE;
12304
12305 instance = strtoul(argv[idx_number]->arg, NULL, 10);
12306 metric = strtoul(argv[idx_number_2]->arg, NULL, 10);
12307
12308 red = bgp_redist_add(bgp, AFI_IP, protocol, instance);
12309 changed =
12310 bgp_redistribute_rmap_set(red, argv[idx_word]->arg, route_map);
12311 changed |= bgp_redistribute_metric_set(bgp, red, AFI_IP, protocol,
12312 metric);
12313 return bgp_redistribute_set(bgp, AFI_IP, protocol, instance, changed);
12314 }
12315
12316 ALIAS_HIDDEN(
12317 bgp_redistribute_ipv4_ospf_rmap_metric,
12318 bgp_redistribute_ipv4_ospf_rmap_metric_hidden_cmd,
12319 "redistribute <ospf|table> (1-65535) route-map WORD metric (0-4294967295)",
12320 "Redistribute information from another routing protocol\n"
12321 "Open Shortest Path First (OSPFv2)\n"
12322 "Non-main Kernel Routing Table\n"
12323 "Instance ID/Table ID\n"
12324 "Route map reference\n"
12325 "Pointer to route-map entries\n"
12326 "Metric for redistributed routes\n"
12327 "Default metric\n")
12328
12329 DEFUN (bgp_redistribute_ipv4_ospf_metric_rmap,
12330 bgp_redistribute_ipv4_ospf_metric_rmap_cmd,
12331 "redistribute <ospf|table> (1-65535) metric (0-4294967295) route-map WORD",
12332 "Redistribute information from another routing protocol\n"
12333 "Open Shortest Path First (OSPFv2)\n"
12334 "Non-main Kernel Routing Table\n"
12335 "Instance ID/Table ID\n"
12336 "Metric for redistributed routes\n"
12337 "Default metric\n"
12338 "Route map reference\n"
12339 "Pointer to route-map entries\n")
12340 {
12341 VTY_DECLVAR_CONTEXT(bgp, bgp);
12342 int idx_ospf_table = 1;
12343 int idx_number = 2;
12344 int idx_number_2 = 4;
12345 int idx_word = 6;
12346 uint32_t metric;
12347 struct bgp_redist *red;
12348 unsigned short instance;
12349 int protocol;
12350 bool changed;
12351 struct route_map *route_map =
12352 route_map_lookup_warn_noexist(vty, argv[idx_word]->arg);
12353
12354 if (strncmp(argv[idx_ospf_table]->arg, "o", 1) == 0)
12355 protocol = ZEBRA_ROUTE_OSPF;
12356 else
12357 protocol = ZEBRA_ROUTE_TABLE;
12358
12359 instance = strtoul(argv[idx_number]->arg, NULL, 10);
12360 metric = strtoul(argv[idx_number_2]->arg, NULL, 10);
12361
12362 red = bgp_redist_add(bgp, AFI_IP, protocol, instance);
12363 changed = bgp_redistribute_metric_set(bgp, red, AFI_IP, protocol,
12364 metric);
12365 changed |=
12366 bgp_redistribute_rmap_set(red, argv[idx_word]->arg, route_map);
12367 return bgp_redistribute_set(bgp, AFI_IP, protocol, instance, changed);
12368 }
12369
12370 ALIAS_HIDDEN(
12371 bgp_redistribute_ipv4_ospf_metric_rmap,
12372 bgp_redistribute_ipv4_ospf_metric_rmap_hidden_cmd,
12373 "redistribute <ospf|table> (1-65535) metric (0-4294967295) route-map WORD",
12374 "Redistribute information from another routing protocol\n"
12375 "Open Shortest Path First (OSPFv2)\n"
12376 "Non-main Kernel Routing Table\n"
12377 "Instance ID/Table ID\n"
12378 "Metric for redistributed routes\n"
12379 "Default metric\n"
12380 "Route map reference\n"
12381 "Pointer to route-map entries\n")
12382
12383 DEFUN (no_bgp_redistribute_ipv4_ospf,
12384 no_bgp_redistribute_ipv4_ospf_cmd,
12385 "no redistribute <ospf|table> (1-65535) [metric (0-4294967295)] [route-map WORD]",
12386 NO_STR
12387 "Redistribute information from another routing protocol\n"
12388 "Open Shortest Path First (OSPFv2)\n"
12389 "Non-main Kernel Routing Table\n"
12390 "Instance ID/Table ID\n"
12391 "Metric for redistributed routes\n"
12392 "Default metric\n"
12393 "Route map reference\n"
12394 "Pointer to route-map entries\n")
12395 {
12396 VTY_DECLVAR_CONTEXT(bgp, bgp);
12397 int idx_ospf_table = 2;
12398 int idx_number = 3;
12399 unsigned short instance;
12400 int protocol;
12401
12402 if (strncmp(argv[idx_ospf_table]->arg, "o", 1) == 0)
12403 protocol = ZEBRA_ROUTE_OSPF;
12404 else
12405 protocol = ZEBRA_ROUTE_TABLE;
12406
12407 instance = strtoul(argv[idx_number]->arg, NULL, 10);
12408 return bgp_redistribute_unset(bgp, AFI_IP, protocol, instance);
12409 }
12410
12411 ALIAS_HIDDEN(
12412 no_bgp_redistribute_ipv4_ospf, no_bgp_redistribute_ipv4_ospf_hidden_cmd,
12413 "no redistribute <ospf|table> (1-65535) [metric (0-4294967295)] [route-map WORD]",
12414 NO_STR
12415 "Redistribute information from another routing protocol\n"
12416 "Open Shortest Path First (OSPFv2)\n"
12417 "Non-main Kernel Routing Table\n"
12418 "Instance ID/Table ID\n"
12419 "Metric for redistributed routes\n"
12420 "Default metric\n"
12421 "Route map reference\n"
12422 "Pointer to route-map entries\n")
12423
12424 DEFUN (no_bgp_redistribute_ipv4,
12425 no_bgp_redistribute_ipv4_cmd,
12426 "no redistribute " FRR_IP_REDIST_STR_BGPD " [metric (0-4294967295)] [route-map WORD]",
12427 NO_STR
12428 "Redistribute information from another routing protocol\n"
12429 FRR_IP_REDIST_HELP_STR_BGPD
12430 "Metric for redistributed routes\n"
12431 "Default metric\n"
12432 "Route map reference\n"
12433 "Pointer to route-map entries\n")
12434 {
12435 VTY_DECLVAR_CONTEXT(bgp, bgp);
12436 int idx_protocol = 2;
12437 int type;
12438
12439 type = proto_redistnum(AFI_IP, argv[idx_protocol]->text);
12440 if (type < 0) {
12441 vty_out(vty, "%% Invalid route type\n");
12442 return CMD_WARNING_CONFIG_FAILED;
12443 }
12444 return bgp_redistribute_unset(bgp, AFI_IP, type, 0);
12445 }
12446
12447 ALIAS_HIDDEN(
12448 no_bgp_redistribute_ipv4, no_bgp_redistribute_ipv4_hidden_cmd,
12449 "no redistribute " FRR_IP_REDIST_STR_BGPD
12450 " [metric (0-4294967295)] [route-map WORD]",
12451 NO_STR
12452 "Redistribute information from another routing protocol\n" FRR_IP_REDIST_HELP_STR_BGPD
12453 "Metric for redistributed routes\n"
12454 "Default metric\n"
12455 "Route map reference\n"
12456 "Pointer to route-map entries\n")
12457
12458 DEFUN (bgp_redistribute_ipv6,
12459 bgp_redistribute_ipv6_cmd,
12460 "redistribute " FRR_IP6_REDIST_STR_BGPD,
12461 "Redistribute information from another routing protocol\n"
12462 FRR_IP6_REDIST_HELP_STR_BGPD)
12463 {
12464 VTY_DECLVAR_CONTEXT(bgp, bgp);
12465 int idx_protocol = 1;
12466 int type;
12467
12468 type = proto_redistnum(AFI_IP6, argv[idx_protocol]->text);
12469 if (type < 0) {
12470 vty_out(vty, "%% Invalid route type\n");
12471 return CMD_WARNING_CONFIG_FAILED;
12472 }
12473
12474 bgp_redist_add(bgp, AFI_IP6, type, 0);
12475 return bgp_redistribute_set(bgp, AFI_IP6, type, 0, false);
12476 }
12477
12478 DEFUN (bgp_redistribute_ipv6_rmap,
12479 bgp_redistribute_ipv6_rmap_cmd,
12480 "redistribute " FRR_IP6_REDIST_STR_BGPD " route-map WORD",
12481 "Redistribute information from another routing protocol\n"
12482 FRR_IP6_REDIST_HELP_STR_BGPD
12483 "Route map reference\n"
12484 "Pointer to route-map entries\n")
12485 {
12486 VTY_DECLVAR_CONTEXT(bgp, bgp);
12487 int idx_protocol = 1;
12488 int idx_word = 3;
12489 int type;
12490 struct bgp_redist *red;
12491 bool changed;
12492 struct route_map *route_map =
12493 route_map_lookup_warn_noexist(vty, argv[idx_word]->arg);
12494
12495 type = proto_redistnum(AFI_IP6, argv[idx_protocol]->text);
12496 if (type < 0) {
12497 vty_out(vty, "%% Invalid route type\n");
12498 return CMD_WARNING_CONFIG_FAILED;
12499 }
12500
12501 red = bgp_redist_add(bgp, AFI_IP6, type, 0);
12502 changed =
12503 bgp_redistribute_rmap_set(red, argv[idx_word]->arg, route_map);
12504 return bgp_redistribute_set(bgp, AFI_IP6, type, 0, changed);
12505 }
12506
12507 DEFUN (bgp_redistribute_ipv6_metric,
12508 bgp_redistribute_ipv6_metric_cmd,
12509 "redistribute " FRR_IP6_REDIST_STR_BGPD " metric (0-4294967295)",
12510 "Redistribute information from another routing protocol\n"
12511 FRR_IP6_REDIST_HELP_STR_BGPD
12512 "Metric for redistributed routes\n"
12513 "Default metric\n")
12514 {
12515 VTY_DECLVAR_CONTEXT(bgp, bgp);
12516 int idx_protocol = 1;
12517 int idx_number = 3;
12518 int type;
12519 uint32_t metric;
12520 struct bgp_redist *red;
12521 bool changed;
12522
12523 type = proto_redistnum(AFI_IP6, argv[idx_protocol]->text);
12524 if (type < 0) {
12525 vty_out(vty, "%% Invalid route type\n");
12526 return CMD_WARNING_CONFIG_FAILED;
12527 }
12528 metric = strtoul(argv[idx_number]->arg, NULL, 10);
12529
12530 red = bgp_redist_add(bgp, AFI_IP6, type, 0);
12531 changed = bgp_redistribute_metric_set(bgp, red, AFI_IP6, type, metric);
12532 return bgp_redistribute_set(bgp, AFI_IP6, type, 0, changed);
12533 }
12534
12535 DEFUN (bgp_redistribute_ipv6_rmap_metric,
12536 bgp_redistribute_ipv6_rmap_metric_cmd,
12537 "redistribute " FRR_IP6_REDIST_STR_BGPD " route-map WORD metric (0-4294967295)",
12538 "Redistribute information from another routing protocol\n"
12539 FRR_IP6_REDIST_HELP_STR_BGPD
12540 "Route map reference\n"
12541 "Pointer to route-map entries\n"
12542 "Metric for redistributed routes\n"
12543 "Default metric\n")
12544 {
12545 VTY_DECLVAR_CONTEXT(bgp, bgp);
12546 int idx_protocol = 1;
12547 int idx_word = 3;
12548 int idx_number = 5;
12549 int type;
12550 uint32_t metric;
12551 struct bgp_redist *red;
12552 bool changed;
12553 struct route_map *route_map =
12554 route_map_lookup_warn_noexist(vty, argv[idx_word]->arg);
12555
12556 type = proto_redistnum(AFI_IP6, argv[idx_protocol]->text);
12557 if (type < 0) {
12558 vty_out(vty, "%% Invalid route type\n");
12559 return CMD_WARNING_CONFIG_FAILED;
12560 }
12561 metric = strtoul(argv[idx_number]->arg, NULL, 10);
12562
12563 red = bgp_redist_add(bgp, AFI_IP6, type, 0);
12564 changed =
12565 bgp_redistribute_rmap_set(red, argv[idx_word]->arg, route_map);
12566 changed |= bgp_redistribute_metric_set(bgp, red, AFI_IP6, type,
12567 metric);
12568 return bgp_redistribute_set(bgp, AFI_IP6, type, 0, changed);
12569 }
12570
12571 DEFUN (bgp_redistribute_ipv6_metric_rmap,
12572 bgp_redistribute_ipv6_metric_rmap_cmd,
12573 "redistribute " FRR_IP6_REDIST_STR_BGPD " metric (0-4294967295) route-map WORD",
12574 "Redistribute information from another routing protocol\n"
12575 FRR_IP6_REDIST_HELP_STR_BGPD
12576 "Metric for redistributed routes\n"
12577 "Default metric\n"
12578 "Route map reference\n"
12579 "Pointer to route-map entries\n")
12580 {
12581 VTY_DECLVAR_CONTEXT(bgp, bgp);
12582 int idx_protocol = 1;
12583 int idx_number = 3;
12584 int idx_word = 5;
12585 int type;
12586 uint32_t metric;
12587 struct bgp_redist *red;
12588 bool changed;
12589 struct route_map *route_map =
12590 route_map_lookup_warn_noexist(vty, argv[idx_word]->arg);
12591
12592 type = proto_redistnum(AFI_IP6, argv[idx_protocol]->text);
12593 if (type < 0) {
12594 vty_out(vty, "%% Invalid route type\n");
12595 return CMD_WARNING_CONFIG_FAILED;
12596 }
12597 metric = strtoul(argv[idx_number]->arg, NULL, 10);
12598
12599 red = bgp_redist_add(bgp, AFI_IP6, type, 0);
12600 changed = bgp_redistribute_metric_set(bgp, red, AFI_IP6, SAFI_UNICAST,
12601 metric);
12602 changed |=
12603 bgp_redistribute_rmap_set(red, argv[idx_word]->arg, route_map);
12604 return bgp_redistribute_set(bgp, AFI_IP6, type, 0, changed);
12605 }
12606
12607 DEFUN (no_bgp_redistribute_ipv6,
12608 no_bgp_redistribute_ipv6_cmd,
12609 "no redistribute " FRR_IP6_REDIST_STR_BGPD " [metric (0-4294967295)] [route-map WORD]",
12610 NO_STR
12611 "Redistribute information from another routing protocol\n"
12612 FRR_IP6_REDIST_HELP_STR_BGPD
12613 "Metric for redistributed routes\n"
12614 "Default metric\n"
12615 "Route map reference\n"
12616 "Pointer to route-map entries\n")
12617 {
12618 VTY_DECLVAR_CONTEXT(bgp, bgp);
12619 int idx_protocol = 2;
12620 int type;
12621
12622 type = proto_redistnum(AFI_IP6, argv[idx_protocol]->text);
12623 if (type < 0) {
12624 vty_out(vty, "%% Invalid route type\n");
12625 return CMD_WARNING_CONFIG_FAILED;
12626 }
12627
12628 return bgp_redistribute_unset(bgp, AFI_IP6, type, 0);
12629 }
12630
12631 void bgp_config_write_redistribute(struct vty *vty, struct bgp *bgp, afi_t afi,
12632 safi_t safi)
12633 {
12634 int i;
12635
12636 /* Unicast redistribution only. */
12637 if (safi != SAFI_UNICAST)
12638 return;
12639
12640 for (i = 0; i < ZEBRA_ROUTE_MAX; i++) {
12641 /* Redistribute BGP does not make sense. */
12642 if (i != ZEBRA_ROUTE_BGP) {
12643 struct list *red_list;
12644 struct listnode *node;
12645 struct bgp_redist *red;
12646
12647 red_list = bgp->redist[afi][i];
12648 if (!red_list)
12649 continue;
12650
12651 for (ALL_LIST_ELEMENTS_RO(red_list, node, red)) {
12652 /* "redistribute" configuration. */
12653 vty_out(vty, " redistribute %s",
12654 zebra_route_string(i));
12655 if (red->instance)
12656 vty_out(vty, " %d", red->instance);
12657 if (red->redist_metric_flag)
12658 vty_out(vty, " metric %u",
12659 red->redist_metric);
12660 if (red->rmap.name)
12661 vty_out(vty, " route-map %s",
12662 red->rmap.name);
12663 vty_out(vty, "\n");
12664 }
12665 }
12666 }
12667 }
12668
12669 /* This is part of the address-family block (unicast only) */
12670 void bgp_vpn_policy_config_write_afi(struct vty *vty, struct bgp *bgp,
12671 afi_t afi)
12672 {
12673 int indent = 2;
12674
12675 if (bgp->vpn_policy[afi].rmap_name[BGP_VPN_POLICY_DIR_FROMVPN]) {
12676 if (listcount(bgp->vpn_policy[afi].import_vrf))
12677 vty_out(vty, "%*simport vrf route-map %s\n", indent, "",
12678 bgp->vpn_policy[afi]
12679 .rmap_name[BGP_VPN_POLICY_DIR_FROMVPN]);
12680 else
12681 vty_out(vty, "%*sroute-map vpn import %s\n", indent, "",
12682 bgp->vpn_policy[afi]
12683 .rmap_name[BGP_VPN_POLICY_DIR_FROMVPN]);
12684 }
12685 if (CHECK_FLAG(bgp->af_flags[afi][SAFI_UNICAST],
12686 BGP_CONFIG_VRF_TO_VRF_IMPORT)
12687 || CHECK_FLAG(bgp->af_flags[afi][SAFI_UNICAST],
12688 BGP_CONFIG_VRF_TO_VRF_EXPORT))
12689 return;
12690
12691 if (CHECK_FLAG(bgp->vpn_policy[afi].flags,
12692 BGP_VPN_POLICY_TOVPN_LABEL_AUTO)) {
12693
12694 vty_out(vty, "%*slabel vpn export %s\n", indent, "", "auto");
12695
12696 } else {
12697 if (bgp->vpn_policy[afi].tovpn_label != MPLS_LABEL_NONE) {
12698 vty_out(vty, "%*slabel vpn export %u\n", indent, "",
12699 bgp->vpn_policy[afi].tovpn_label);
12700 }
12701 }
12702 if (CHECK_FLAG(bgp->vpn_policy[afi].flags,
12703 BGP_VPN_POLICY_TOVPN_RD_SET)) {
12704 char buf[RD_ADDRSTRLEN];
12705 vty_out(vty, "%*srd vpn export %s\n", indent, "",
12706 prefix_rd2str(&bgp->vpn_policy[afi].tovpn_rd, buf,
12707 sizeof(buf)));
12708 }
12709 if (CHECK_FLAG(bgp->vpn_policy[afi].flags,
12710 BGP_VPN_POLICY_TOVPN_NEXTHOP_SET)) {
12711
12712 char buf[PREFIX_STRLEN];
12713 if (inet_ntop(bgp->vpn_policy[afi].tovpn_nexthop.family,
12714 &bgp->vpn_policy[afi].tovpn_nexthop.u.prefix, buf,
12715 sizeof(buf))) {
12716
12717 vty_out(vty, "%*snexthop vpn export %s\n",
12718 indent, "", buf);
12719 }
12720 }
12721 if (bgp->vpn_policy[afi].rtlist[BGP_VPN_POLICY_DIR_FROMVPN]
12722 && bgp->vpn_policy[afi].rtlist[BGP_VPN_POLICY_DIR_TOVPN]
12723 && ecommunity_cmp(
12724 bgp->vpn_policy[afi].rtlist[BGP_VPN_POLICY_DIR_FROMVPN],
12725 bgp->vpn_policy[afi].rtlist[BGP_VPN_POLICY_DIR_TOVPN])) {
12726
12727 char *b = ecommunity_ecom2str(
12728 bgp->vpn_policy[afi].rtlist[BGP_VPN_POLICY_DIR_TOVPN],
12729 ECOMMUNITY_FORMAT_ROUTE_MAP, ECOMMUNITY_ROUTE_TARGET);
12730 vty_out(vty, "%*srt vpn both %s\n", indent, "", b);
12731 XFREE(MTYPE_ECOMMUNITY_STR, b);
12732 } else {
12733 if (bgp->vpn_policy[afi].rtlist[BGP_VPN_POLICY_DIR_FROMVPN]) {
12734 char *b = ecommunity_ecom2str(
12735 bgp->vpn_policy[afi]
12736 .rtlist[BGP_VPN_POLICY_DIR_FROMVPN],
12737 ECOMMUNITY_FORMAT_ROUTE_MAP,
12738 ECOMMUNITY_ROUTE_TARGET);
12739 vty_out(vty, "%*srt vpn import %s\n", indent, "", b);
12740 XFREE(MTYPE_ECOMMUNITY_STR, b);
12741 }
12742 if (bgp->vpn_policy[afi].rtlist[BGP_VPN_POLICY_DIR_TOVPN]) {
12743 char *b = ecommunity_ecom2str(
12744 bgp->vpn_policy[afi]
12745 .rtlist[BGP_VPN_POLICY_DIR_TOVPN],
12746 ECOMMUNITY_FORMAT_ROUTE_MAP,
12747 ECOMMUNITY_ROUTE_TARGET);
12748 vty_out(vty, "%*srt vpn export %s\n", indent, "", b);
12749 XFREE(MTYPE_ECOMMUNITY_STR, b);
12750 }
12751 }
12752
12753 if (bgp->vpn_policy[afi].rmap_name[BGP_VPN_POLICY_DIR_TOVPN])
12754 vty_out(vty, "%*sroute-map vpn export %s\n", indent, "",
12755 bgp->vpn_policy[afi]
12756 .rmap_name[BGP_VPN_POLICY_DIR_TOVPN]);
12757
12758 if (bgp->vpn_policy[afi].import_redirect_rtlist) {
12759 char *b = ecommunity_ecom2str(
12760 bgp->vpn_policy[afi]
12761 .import_redirect_rtlist,
12762 ECOMMUNITY_FORMAT_ROUTE_MAP,
12763 ECOMMUNITY_ROUTE_TARGET);
12764
12765 vty_out(vty, "%*srt redirect import %s\n", indent, "", b);
12766 XFREE(MTYPE_ECOMMUNITY_STR, b);
12767 }
12768 }
12769
12770
12771 /* BGP node structure. */
12772 static struct cmd_node bgp_node = {
12773 BGP_NODE, "%s(config-router)# ", 1,
12774 };
12775
12776 static struct cmd_node bgp_ipv4_unicast_node = {
12777 BGP_IPV4_NODE, "%s(config-router-af)# ", 1,
12778 };
12779
12780 static struct cmd_node bgp_ipv4_multicast_node = {
12781 BGP_IPV4M_NODE, "%s(config-router-af)# ", 1,
12782 };
12783
12784 static struct cmd_node bgp_ipv4_labeled_unicast_node = {
12785 BGP_IPV4L_NODE, "%s(config-router-af)# ", 1,
12786 };
12787
12788 static struct cmd_node bgp_ipv6_unicast_node = {
12789 BGP_IPV6_NODE, "%s(config-router-af)# ", 1,
12790 };
12791
12792 static struct cmd_node bgp_ipv6_multicast_node = {
12793 BGP_IPV6M_NODE, "%s(config-router-af)# ", 1,
12794 };
12795
12796 static struct cmd_node bgp_ipv6_labeled_unicast_node = {
12797 BGP_IPV6L_NODE, "%s(config-router-af)# ", 1,
12798 };
12799
12800 static struct cmd_node bgp_vpnv4_node = {BGP_VPNV4_NODE,
12801 "%s(config-router-af)# ", 1};
12802
12803 static struct cmd_node bgp_vpnv6_node = {BGP_VPNV6_NODE,
12804 "%s(config-router-af-vpnv6)# ", 1};
12805
12806 static struct cmd_node bgp_evpn_node = {BGP_EVPN_NODE,
12807 "%s(config-router-evpn)# ", 1};
12808
12809 static struct cmd_node bgp_evpn_vni_node = {BGP_EVPN_VNI_NODE,
12810 "%s(config-router-af-vni)# ", 1};
12811
12812 static struct cmd_node bgp_flowspecv4_node = {BGP_FLOWSPECV4_NODE,
12813 "%s(config-router-af)# ", 1};
12814
12815 static struct cmd_node bgp_flowspecv6_node = {BGP_FLOWSPECV6_NODE,
12816 "%s(config-router-af-vpnv6)# ", 1};
12817
12818 static void community_list_vty(void);
12819
12820 static void bgp_ac_neighbor(vector comps, struct cmd_token *token)
12821 {
12822 struct bgp *bgp;
12823 struct peer *peer;
12824 struct listnode *lnbgp, *lnpeer;
12825
12826 for (ALL_LIST_ELEMENTS_RO(bm->bgp, lnbgp, bgp)) {
12827 for (ALL_LIST_ELEMENTS_RO(bgp->peer, lnpeer, peer)) {
12828 /* only provide suggestions on the appropriate input
12829 * token type,
12830 * they'll otherwise show up multiple times */
12831 enum cmd_token_type match_type;
12832 char *name = peer->host;
12833
12834 if (peer->conf_if) {
12835 match_type = VARIABLE_TKN;
12836 name = peer->conf_if;
12837 } else if (strchr(peer->host, ':'))
12838 match_type = IPV6_TKN;
12839 else
12840 match_type = IPV4_TKN;
12841
12842 if (token->type != match_type)
12843 continue;
12844
12845 vector_set(comps, XSTRDUP(MTYPE_COMPLETION, name));
12846 }
12847 }
12848 }
12849
12850 static const struct cmd_variable_handler bgp_var_neighbor[] = {
12851 {.varname = "neighbor", .completions = bgp_ac_neighbor},
12852 {.varname = "neighbors", .completions = bgp_ac_neighbor},
12853 {.varname = "peer", .completions = bgp_ac_neighbor},
12854 {.completions = NULL}};
12855
12856 static void bgp_ac_peergroup(vector comps, struct cmd_token *token)
12857 {
12858 struct bgp *bgp;
12859 struct peer_group *group;
12860 struct listnode *lnbgp, *lnpeer;
12861
12862 for (ALL_LIST_ELEMENTS_RO(bm->bgp, lnbgp, bgp)) {
12863 for (ALL_LIST_ELEMENTS_RO(bgp->group, lnpeer, group))
12864 vector_set(comps, XSTRDUP(MTYPE_COMPLETION,
12865 group->name));
12866 }
12867 }
12868
12869 static const struct cmd_variable_handler bgp_var_peergroup[] = {
12870 {.tokenname = "PGNAME", .completions = bgp_ac_peergroup},
12871 {.completions = NULL} };
12872
12873 void bgp_vty_init(void)
12874 {
12875 cmd_variable_handler_register(bgp_var_neighbor);
12876 cmd_variable_handler_register(bgp_var_peergroup);
12877
12878 /* Install bgp top node. */
12879 install_node(&bgp_node, bgp_config_write);
12880 install_node(&bgp_ipv4_unicast_node, NULL);
12881 install_node(&bgp_ipv4_multicast_node, NULL);
12882 install_node(&bgp_ipv4_labeled_unicast_node, NULL);
12883 install_node(&bgp_ipv6_unicast_node, NULL);
12884 install_node(&bgp_ipv6_multicast_node, NULL);
12885 install_node(&bgp_ipv6_labeled_unicast_node, NULL);
12886 install_node(&bgp_vpnv4_node, NULL);
12887 install_node(&bgp_vpnv6_node, NULL);
12888 install_node(&bgp_evpn_node, NULL);
12889 install_node(&bgp_evpn_vni_node, NULL);
12890 install_node(&bgp_flowspecv4_node, NULL);
12891 install_node(&bgp_flowspecv6_node, NULL);
12892
12893 /* Install default VTY commands to new nodes. */
12894 install_default(BGP_NODE);
12895 install_default(BGP_IPV4_NODE);
12896 install_default(BGP_IPV4M_NODE);
12897 install_default(BGP_IPV4L_NODE);
12898 install_default(BGP_IPV6_NODE);
12899 install_default(BGP_IPV6M_NODE);
12900 install_default(BGP_IPV6L_NODE);
12901 install_default(BGP_VPNV4_NODE);
12902 install_default(BGP_VPNV6_NODE);
12903 install_default(BGP_FLOWSPECV4_NODE);
12904 install_default(BGP_FLOWSPECV6_NODE);
12905 install_default(BGP_EVPN_NODE);
12906 install_default(BGP_EVPN_VNI_NODE);
12907
12908 /* "bgp multiple-instance" commands. */
12909 install_element(CONFIG_NODE, &bgp_multiple_instance_cmd);
12910 install_element(CONFIG_NODE, &no_bgp_multiple_instance_cmd);
12911
12912 /* "bgp config-type" commands. */
12913 install_element(CONFIG_NODE, &bgp_config_type_cmd);
12914 install_element(CONFIG_NODE, &no_bgp_config_type_cmd);
12915
12916 /* "bgp local-mac" hidden commands. */
12917 install_element(CONFIG_NODE, &bgp_local_mac_cmd);
12918 install_element(CONFIG_NODE, &no_bgp_local_mac_cmd);
12919
12920 /* bgp route-map delay-timer commands. */
12921 install_element(CONFIG_NODE, &bgp_set_route_map_delay_timer_cmd);
12922 install_element(CONFIG_NODE, &no_bgp_set_route_map_delay_timer_cmd);
12923
12924 /* Dummy commands (Currently not supported) */
12925 install_element(BGP_NODE, &no_synchronization_cmd);
12926 install_element(BGP_NODE, &no_auto_summary_cmd);
12927
12928 /* "router bgp" commands. */
12929 install_element(CONFIG_NODE, &router_bgp_cmd);
12930
12931 /* "no router bgp" commands. */
12932 install_element(CONFIG_NODE, &no_router_bgp_cmd);
12933
12934 /* "bgp router-id" commands. */
12935 install_element(BGP_NODE, &bgp_router_id_cmd);
12936 install_element(BGP_NODE, &no_bgp_router_id_cmd);
12937
12938 /* "bgp cluster-id" commands. */
12939 install_element(BGP_NODE, &bgp_cluster_id_cmd);
12940 install_element(BGP_NODE, &no_bgp_cluster_id_cmd);
12941
12942 /* "bgp confederation" commands. */
12943 install_element(BGP_NODE, &bgp_confederation_identifier_cmd);
12944 install_element(BGP_NODE, &no_bgp_confederation_identifier_cmd);
12945
12946 /* "bgp confederation peers" commands. */
12947 install_element(BGP_NODE, &bgp_confederation_peers_cmd);
12948 install_element(BGP_NODE, &no_bgp_confederation_peers_cmd);
12949
12950 /* bgp max-med command */
12951 install_element(BGP_NODE, &bgp_maxmed_admin_cmd);
12952 install_element(BGP_NODE, &no_bgp_maxmed_admin_cmd);
12953 install_element(BGP_NODE, &bgp_maxmed_admin_medv_cmd);
12954 install_element(BGP_NODE, &bgp_maxmed_onstartup_cmd);
12955 install_element(BGP_NODE, &no_bgp_maxmed_onstartup_cmd);
12956
12957 /* bgp disable-ebgp-connected-nh-check */
12958 install_element(BGP_NODE, &bgp_disable_connected_route_check_cmd);
12959 install_element(BGP_NODE, &no_bgp_disable_connected_route_check_cmd);
12960
12961 /* bgp update-delay command */
12962 install_element(BGP_NODE, &bgp_update_delay_cmd);
12963 install_element(BGP_NODE, &no_bgp_update_delay_cmd);
12964 install_element(BGP_NODE, &bgp_update_delay_establish_wait_cmd);
12965
12966 install_element(BGP_NODE, &bgp_wpkt_quanta_cmd);
12967 install_element(BGP_NODE, &no_bgp_wpkt_quanta_cmd);
12968 install_element(BGP_NODE, &bgp_rpkt_quanta_cmd);
12969 install_element(BGP_NODE, &no_bgp_rpkt_quanta_cmd);
12970
12971 install_element(BGP_NODE, &bgp_coalesce_time_cmd);
12972 install_element(BGP_NODE, &no_bgp_coalesce_time_cmd);
12973
12974 /* "maximum-paths" commands. */
12975 install_element(BGP_NODE, &bgp_maxpaths_hidden_cmd);
12976 install_element(BGP_NODE, &no_bgp_maxpaths_hidden_cmd);
12977 install_element(BGP_IPV4_NODE, &bgp_maxpaths_cmd);
12978 install_element(BGP_IPV4_NODE, &no_bgp_maxpaths_cmd);
12979 install_element(BGP_IPV6_NODE, &bgp_maxpaths_cmd);
12980 install_element(BGP_IPV6_NODE, &no_bgp_maxpaths_cmd);
12981 install_element(BGP_NODE, &bgp_maxpaths_ibgp_hidden_cmd);
12982 install_element(BGP_NODE, &bgp_maxpaths_ibgp_cluster_hidden_cmd);
12983 install_element(BGP_NODE, &no_bgp_maxpaths_ibgp_hidden_cmd);
12984 install_element(BGP_IPV4_NODE, &bgp_maxpaths_ibgp_cmd);
12985 install_element(BGP_IPV4_NODE, &bgp_maxpaths_ibgp_cluster_cmd);
12986 install_element(BGP_IPV4_NODE, &no_bgp_maxpaths_ibgp_cmd);
12987 install_element(BGP_IPV6_NODE, &bgp_maxpaths_ibgp_cmd);
12988 install_element(BGP_IPV6_NODE, &bgp_maxpaths_ibgp_cluster_cmd);
12989 install_element(BGP_IPV6_NODE, &no_bgp_maxpaths_ibgp_cmd);
12990
12991 install_element(BGP_IPV6L_NODE, &bgp_maxpaths_cmd);
12992 install_element(BGP_IPV6L_NODE, &no_bgp_maxpaths_cmd);
12993 install_element(BGP_IPV6L_NODE, &bgp_maxpaths_ibgp_cmd);
12994 install_element(BGP_IPV6L_NODE, &bgp_maxpaths_ibgp_cluster_cmd);
12995 install_element(BGP_IPV6L_NODE, &no_bgp_maxpaths_ibgp_cmd);
12996
12997 /* "timers bgp" commands. */
12998 install_element(BGP_NODE, &bgp_timers_cmd);
12999 install_element(BGP_NODE, &no_bgp_timers_cmd);
13000
13001 /* route-map delay-timer commands - per instance for backwards compat.
13002 */
13003 install_element(BGP_NODE, &bgp_set_route_map_delay_timer_cmd);
13004 install_element(BGP_NODE, &no_bgp_set_route_map_delay_timer_cmd);
13005
13006 /* "bgp client-to-client reflection" commands */
13007 install_element(BGP_NODE, &no_bgp_client_to_client_reflection_cmd);
13008 install_element(BGP_NODE, &bgp_client_to_client_reflection_cmd);
13009
13010 /* "bgp always-compare-med" commands */
13011 install_element(BGP_NODE, &bgp_always_compare_med_cmd);
13012 install_element(BGP_NODE, &no_bgp_always_compare_med_cmd);
13013
13014 /* bgp ebgp-requires-policy */
13015 install_element(BGP_NODE, &bgp_ebgp_requires_policy_cmd);
13016 install_element(BGP_NODE, &no_bgp_ebgp_requires_policy_cmd);
13017
13018 /* "bgp deterministic-med" commands */
13019 install_element(BGP_NODE, &bgp_deterministic_med_cmd);
13020 install_element(BGP_NODE, &no_bgp_deterministic_med_cmd);
13021
13022 /* "bgp graceful-restart" commands */
13023 install_element(BGP_NODE, &bgp_graceful_restart_cmd);
13024 install_element(BGP_NODE, &no_bgp_graceful_restart_cmd);
13025 install_element(BGP_NODE, &bgp_graceful_restart_stalepath_time_cmd);
13026 install_element(BGP_NODE, &no_bgp_graceful_restart_stalepath_time_cmd);
13027 install_element(BGP_NODE, &bgp_graceful_restart_restart_time_cmd);
13028 install_element(BGP_NODE, &no_bgp_graceful_restart_restart_time_cmd);
13029
13030 install_element(BGP_NODE, &bgp_graceful_restart_preserve_fw_cmd);
13031 install_element(BGP_NODE, &no_bgp_graceful_restart_preserve_fw_cmd);
13032
13033 /* "bgp graceful-shutdown" commands */
13034 install_element(BGP_NODE, &bgp_graceful_shutdown_cmd);
13035 install_element(BGP_NODE, &no_bgp_graceful_shutdown_cmd);
13036
13037 /* "bgp fast-external-failover" commands */
13038 install_element(BGP_NODE, &bgp_fast_external_failover_cmd);
13039 install_element(BGP_NODE, &no_bgp_fast_external_failover_cmd);
13040
13041 /* "bgp enforce-first-as" commands */
13042 install_element(BGP_NODE, &bgp_enforce_first_as_cmd);
13043
13044 /* "bgp bestpath compare-routerid" commands */
13045 install_element(BGP_NODE, &bgp_bestpath_compare_router_id_cmd);
13046 install_element(BGP_NODE, &no_bgp_bestpath_compare_router_id_cmd);
13047
13048 /* "bgp bestpath as-path ignore" commands */
13049 install_element(BGP_NODE, &bgp_bestpath_aspath_ignore_cmd);
13050 install_element(BGP_NODE, &no_bgp_bestpath_aspath_ignore_cmd);
13051
13052 /* "bgp bestpath as-path confed" commands */
13053 install_element(BGP_NODE, &bgp_bestpath_aspath_confed_cmd);
13054 install_element(BGP_NODE, &no_bgp_bestpath_aspath_confed_cmd);
13055
13056 /* "bgp bestpath as-path multipath-relax" commands */
13057 install_element(BGP_NODE, &bgp_bestpath_aspath_multipath_relax_cmd);
13058 install_element(BGP_NODE, &no_bgp_bestpath_aspath_multipath_relax_cmd);
13059
13060 /* "bgp log-neighbor-changes" commands */
13061 install_element(BGP_NODE, &bgp_log_neighbor_changes_cmd);
13062 install_element(BGP_NODE, &no_bgp_log_neighbor_changes_cmd);
13063
13064 /* "bgp bestpath med" commands */
13065 install_element(BGP_NODE, &bgp_bestpath_med_cmd);
13066 install_element(BGP_NODE, &no_bgp_bestpath_med_cmd);
13067
13068 /* "no bgp default ipv4-unicast" commands. */
13069 install_element(BGP_NODE, &no_bgp_default_ipv4_unicast_cmd);
13070 install_element(BGP_NODE, &bgp_default_ipv4_unicast_cmd);
13071
13072 /* "bgp network import-check" commands. */
13073 install_element(BGP_NODE, &bgp_network_import_check_cmd);
13074 install_element(BGP_NODE, &bgp_network_import_check_exact_cmd);
13075 install_element(BGP_NODE, &no_bgp_network_import_check_cmd);
13076
13077 /* "bgp default local-preference" commands. */
13078 install_element(BGP_NODE, &bgp_default_local_preference_cmd);
13079 install_element(BGP_NODE, &no_bgp_default_local_preference_cmd);
13080
13081 /* bgp default show-hostname */
13082 install_element(BGP_NODE, &bgp_default_show_hostname_cmd);
13083 install_element(BGP_NODE, &no_bgp_default_show_hostname_cmd);
13084
13085 /* "bgp default subgroup-pkt-queue-max" commands. */
13086 install_element(BGP_NODE, &bgp_default_subgroup_pkt_queue_max_cmd);
13087 install_element(BGP_NODE, &no_bgp_default_subgroup_pkt_queue_max_cmd);
13088
13089 /* bgp ibgp-allow-policy-mods command */
13090 install_element(BGP_NODE, &bgp_rr_allow_outbound_policy_cmd);
13091 install_element(BGP_NODE, &no_bgp_rr_allow_outbound_policy_cmd);
13092
13093 /* "bgp listen limit" commands. */
13094 install_element(BGP_NODE, &bgp_listen_limit_cmd);
13095 install_element(BGP_NODE, &no_bgp_listen_limit_cmd);
13096
13097 /* "bgp listen range" commands. */
13098 install_element(BGP_NODE, &bgp_listen_range_cmd);
13099 install_element(BGP_NODE, &no_bgp_listen_range_cmd);
13100
13101 /* "bgp default shutdown" command */
13102 install_element(BGP_NODE, &bgp_default_shutdown_cmd);
13103
13104 /* "neighbor remote-as" commands. */
13105 install_element(BGP_NODE, &neighbor_remote_as_cmd);
13106 install_element(BGP_NODE, &neighbor_interface_config_cmd);
13107 install_element(BGP_NODE, &neighbor_interface_config_v6only_cmd);
13108 install_element(BGP_NODE, &neighbor_interface_config_remote_as_cmd);
13109 install_element(BGP_NODE,
13110 &neighbor_interface_v6only_config_remote_as_cmd);
13111 install_element(BGP_NODE, &no_neighbor_cmd);
13112 install_element(BGP_NODE, &no_neighbor_interface_config_cmd);
13113
13114 /* "neighbor peer-group" commands. */
13115 install_element(BGP_NODE, &neighbor_peer_group_cmd);
13116 install_element(BGP_NODE, &no_neighbor_peer_group_cmd);
13117 install_element(BGP_NODE,
13118 &no_neighbor_interface_peer_group_remote_as_cmd);
13119
13120 /* "neighbor local-as" commands. */
13121 install_element(BGP_NODE, &neighbor_local_as_cmd);
13122 install_element(BGP_NODE, &neighbor_local_as_no_prepend_cmd);
13123 install_element(BGP_NODE, &neighbor_local_as_no_prepend_replace_as_cmd);
13124 install_element(BGP_NODE, &no_neighbor_local_as_cmd);
13125
13126 /* "neighbor solo" commands. */
13127 install_element(BGP_NODE, &neighbor_solo_cmd);
13128 install_element(BGP_NODE, &no_neighbor_solo_cmd);
13129
13130 /* "neighbor password" commands. */
13131 install_element(BGP_NODE, &neighbor_password_cmd);
13132 install_element(BGP_NODE, &no_neighbor_password_cmd);
13133
13134 /* "neighbor activate" commands. */
13135 install_element(BGP_NODE, &neighbor_activate_hidden_cmd);
13136 install_element(BGP_IPV4_NODE, &neighbor_activate_cmd);
13137 install_element(BGP_IPV4M_NODE, &neighbor_activate_cmd);
13138 install_element(BGP_IPV4L_NODE, &neighbor_activate_cmd);
13139 install_element(BGP_IPV6_NODE, &neighbor_activate_cmd);
13140 install_element(BGP_IPV6M_NODE, &neighbor_activate_cmd);
13141 install_element(BGP_IPV6L_NODE, &neighbor_activate_cmd);
13142 install_element(BGP_VPNV4_NODE, &neighbor_activate_cmd);
13143 install_element(BGP_VPNV6_NODE, &neighbor_activate_cmd);
13144 install_element(BGP_FLOWSPECV4_NODE, &neighbor_activate_cmd);
13145 install_element(BGP_FLOWSPECV6_NODE, &neighbor_activate_cmd);
13146 install_element(BGP_EVPN_NODE, &neighbor_activate_cmd);
13147
13148 /* "no neighbor activate" commands. */
13149 install_element(BGP_NODE, &no_neighbor_activate_hidden_cmd);
13150 install_element(BGP_IPV4_NODE, &no_neighbor_activate_cmd);
13151 install_element(BGP_IPV4M_NODE, &no_neighbor_activate_cmd);
13152 install_element(BGP_IPV4L_NODE, &no_neighbor_activate_cmd);
13153 install_element(BGP_IPV6_NODE, &no_neighbor_activate_cmd);
13154 install_element(BGP_IPV6M_NODE, &no_neighbor_activate_cmd);
13155 install_element(BGP_IPV6L_NODE, &no_neighbor_activate_cmd);
13156 install_element(BGP_VPNV4_NODE, &no_neighbor_activate_cmd);
13157 install_element(BGP_VPNV6_NODE, &no_neighbor_activate_cmd);
13158 install_element(BGP_FLOWSPECV4_NODE, &no_neighbor_activate_cmd);
13159 install_element(BGP_FLOWSPECV6_NODE, &no_neighbor_activate_cmd);
13160 install_element(BGP_EVPN_NODE, &no_neighbor_activate_cmd);
13161
13162 /* "neighbor peer-group" set commands. */
13163 install_element(BGP_NODE, &neighbor_set_peer_group_cmd);
13164 install_element(BGP_IPV4_NODE, &neighbor_set_peer_group_hidden_cmd);
13165 install_element(BGP_IPV4M_NODE, &neighbor_set_peer_group_hidden_cmd);
13166 install_element(BGP_IPV6_NODE, &neighbor_set_peer_group_hidden_cmd);
13167 install_element(BGP_IPV6M_NODE, &neighbor_set_peer_group_hidden_cmd);
13168 install_element(BGP_IPV6L_NODE, &neighbor_set_peer_group_hidden_cmd);
13169 install_element(BGP_VPNV4_NODE, &neighbor_set_peer_group_hidden_cmd);
13170 install_element(BGP_VPNV6_NODE, &neighbor_set_peer_group_hidden_cmd);
13171 install_element(BGP_FLOWSPECV4_NODE,
13172 &neighbor_set_peer_group_hidden_cmd);
13173 install_element(BGP_FLOWSPECV6_NODE,
13174 &neighbor_set_peer_group_hidden_cmd);
13175
13176 /* "no neighbor peer-group unset" commands. */
13177 install_element(BGP_NODE, &no_neighbor_set_peer_group_cmd);
13178 install_element(BGP_IPV4_NODE, &no_neighbor_set_peer_group_hidden_cmd);
13179 install_element(BGP_IPV4M_NODE, &no_neighbor_set_peer_group_hidden_cmd);
13180 install_element(BGP_IPV6_NODE, &no_neighbor_set_peer_group_hidden_cmd);
13181 install_element(BGP_IPV6M_NODE, &no_neighbor_set_peer_group_hidden_cmd);
13182 install_element(BGP_IPV6L_NODE, &no_neighbor_set_peer_group_hidden_cmd);
13183 install_element(BGP_VPNV4_NODE, &no_neighbor_set_peer_group_hidden_cmd);
13184 install_element(BGP_VPNV6_NODE, &no_neighbor_set_peer_group_hidden_cmd);
13185 install_element(BGP_FLOWSPECV4_NODE,
13186 &no_neighbor_set_peer_group_hidden_cmd);
13187 install_element(BGP_FLOWSPECV6_NODE,
13188 &no_neighbor_set_peer_group_hidden_cmd);
13189
13190 /* "neighbor softreconfiguration inbound" commands.*/
13191 install_element(BGP_NODE, &neighbor_soft_reconfiguration_hidden_cmd);
13192 install_element(BGP_NODE, &no_neighbor_soft_reconfiguration_hidden_cmd);
13193 install_element(BGP_IPV4_NODE, &neighbor_soft_reconfiguration_cmd);
13194 install_element(BGP_IPV4_NODE, &no_neighbor_soft_reconfiguration_cmd);
13195 install_element(BGP_IPV4L_NODE, &neighbor_soft_reconfiguration_cmd);
13196 install_element(BGP_IPV4L_NODE, &no_neighbor_soft_reconfiguration_cmd);
13197 install_element(BGP_IPV4M_NODE, &neighbor_soft_reconfiguration_cmd);
13198 install_element(BGP_IPV4M_NODE, &no_neighbor_soft_reconfiguration_cmd);
13199 install_element(BGP_IPV6_NODE, &neighbor_soft_reconfiguration_cmd);
13200 install_element(BGP_IPV6_NODE, &no_neighbor_soft_reconfiguration_cmd);
13201 install_element(BGP_IPV6M_NODE, &neighbor_soft_reconfiguration_cmd);
13202 install_element(BGP_IPV6M_NODE, &no_neighbor_soft_reconfiguration_cmd);
13203 install_element(BGP_IPV6L_NODE, &neighbor_soft_reconfiguration_cmd);
13204 install_element(BGP_IPV6L_NODE, &no_neighbor_soft_reconfiguration_cmd);
13205 install_element(BGP_VPNV4_NODE, &neighbor_soft_reconfiguration_cmd);
13206 install_element(BGP_VPNV4_NODE, &no_neighbor_soft_reconfiguration_cmd);
13207 install_element(BGP_VPNV6_NODE, &neighbor_soft_reconfiguration_cmd);
13208 install_element(BGP_VPNV6_NODE, &no_neighbor_soft_reconfiguration_cmd);
13209 install_element(BGP_FLOWSPECV4_NODE,
13210 &neighbor_soft_reconfiguration_cmd);
13211 install_element(BGP_FLOWSPECV4_NODE,
13212 &no_neighbor_soft_reconfiguration_cmd);
13213 install_element(BGP_FLOWSPECV6_NODE,
13214 &neighbor_soft_reconfiguration_cmd);
13215 install_element(BGP_FLOWSPECV6_NODE,
13216 &no_neighbor_soft_reconfiguration_cmd);
13217 install_element(BGP_EVPN_NODE, &neighbor_soft_reconfiguration_cmd);
13218 install_element(BGP_EVPN_NODE, &no_neighbor_soft_reconfiguration_cmd);
13219
13220 /* "neighbor attribute-unchanged" commands. */
13221 install_element(BGP_NODE, &neighbor_attr_unchanged_hidden_cmd);
13222 install_element(BGP_NODE, &no_neighbor_attr_unchanged_hidden_cmd);
13223 install_element(BGP_IPV4_NODE, &neighbor_attr_unchanged_cmd);
13224 install_element(BGP_IPV4_NODE, &no_neighbor_attr_unchanged_cmd);
13225 install_element(BGP_IPV4M_NODE, &neighbor_attr_unchanged_cmd);
13226 install_element(BGP_IPV4M_NODE, &no_neighbor_attr_unchanged_cmd);
13227 install_element(BGP_IPV4L_NODE, &neighbor_attr_unchanged_cmd);
13228 install_element(BGP_IPV4L_NODE, &no_neighbor_attr_unchanged_cmd);
13229 install_element(BGP_IPV6_NODE, &neighbor_attr_unchanged_cmd);
13230 install_element(BGP_IPV6_NODE, &no_neighbor_attr_unchanged_cmd);
13231 install_element(BGP_IPV6M_NODE, &neighbor_attr_unchanged_cmd);
13232 install_element(BGP_IPV6M_NODE, &no_neighbor_attr_unchanged_cmd);
13233 install_element(BGP_IPV6L_NODE, &neighbor_attr_unchanged_cmd);
13234 install_element(BGP_IPV6L_NODE, &no_neighbor_attr_unchanged_cmd);
13235 install_element(BGP_VPNV4_NODE, &neighbor_attr_unchanged_cmd);
13236 install_element(BGP_VPNV4_NODE, &no_neighbor_attr_unchanged_cmd);
13237 install_element(BGP_VPNV6_NODE, &neighbor_attr_unchanged_cmd);
13238 install_element(BGP_VPNV6_NODE, &no_neighbor_attr_unchanged_cmd);
13239
13240 install_element(BGP_EVPN_NODE, &neighbor_attr_unchanged_cmd);
13241 install_element(BGP_EVPN_NODE, &no_neighbor_attr_unchanged_cmd);
13242
13243 /* "nexthop-local unchanged" commands */
13244 install_element(BGP_IPV6_NODE, &neighbor_nexthop_local_unchanged_cmd);
13245 install_element(BGP_IPV6_NODE,
13246 &no_neighbor_nexthop_local_unchanged_cmd);
13247
13248 /* "neighbor next-hop-self" commands. */
13249 install_element(BGP_NODE, &neighbor_nexthop_self_hidden_cmd);
13250 install_element(BGP_NODE, &no_neighbor_nexthop_self_hidden_cmd);
13251 install_element(BGP_IPV4_NODE, &neighbor_nexthop_self_cmd);
13252 install_element(BGP_IPV4_NODE, &no_neighbor_nexthop_self_cmd);
13253 install_element(BGP_IPV4M_NODE, &neighbor_nexthop_self_cmd);
13254 install_element(BGP_IPV4M_NODE, &no_neighbor_nexthop_self_cmd);
13255 install_element(BGP_IPV4L_NODE, &neighbor_nexthop_self_cmd);
13256 install_element(BGP_IPV4L_NODE, &no_neighbor_nexthop_self_cmd);
13257 install_element(BGP_IPV6_NODE, &neighbor_nexthop_self_cmd);
13258 install_element(BGP_IPV6_NODE, &no_neighbor_nexthop_self_cmd);
13259 install_element(BGP_IPV6M_NODE, &neighbor_nexthop_self_cmd);
13260 install_element(BGP_IPV6M_NODE, &no_neighbor_nexthop_self_cmd);
13261 install_element(BGP_IPV6L_NODE, &neighbor_nexthop_self_cmd);
13262 install_element(BGP_IPV6L_NODE, &no_neighbor_nexthop_self_cmd);
13263 install_element(BGP_VPNV4_NODE, &neighbor_nexthop_self_cmd);
13264 install_element(BGP_VPNV4_NODE, &no_neighbor_nexthop_self_cmd);
13265 install_element(BGP_VPNV6_NODE, &neighbor_nexthop_self_cmd);
13266 install_element(BGP_VPNV6_NODE, &no_neighbor_nexthop_self_cmd);
13267 install_element(BGP_EVPN_NODE, &neighbor_nexthop_self_cmd);
13268 install_element(BGP_EVPN_NODE, &no_neighbor_nexthop_self_cmd);
13269
13270 /* "neighbor next-hop-self force" commands. */
13271 install_element(BGP_NODE, &neighbor_nexthop_self_force_hidden_cmd);
13272 install_element(BGP_NODE, &no_neighbor_nexthop_self_force_hidden_cmd);
13273 install_element(BGP_NODE, &neighbor_nexthop_self_all_hidden_cmd);
13274 install_element(BGP_NODE, &no_neighbor_nexthop_self_all_hidden_cmd);
13275 install_element(BGP_IPV4_NODE, &neighbor_nexthop_self_force_cmd);
13276 install_element(BGP_IPV4_NODE, &no_neighbor_nexthop_self_force_cmd);
13277 install_element(BGP_IPV4_NODE, &neighbor_nexthop_self_all_hidden_cmd);
13278 install_element(BGP_IPV4_NODE,
13279 &no_neighbor_nexthop_self_all_hidden_cmd);
13280 install_element(BGP_IPV4M_NODE, &neighbor_nexthop_self_force_cmd);
13281 install_element(BGP_IPV4M_NODE, &no_neighbor_nexthop_self_force_cmd);
13282 install_element(BGP_IPV4M_NODE, &neighbor_nexthop_self_all_hidden_cmd);
13283 install_element(BGP_IPV4M_NODE,
13284 &no_neighbor_nexthop_self_all_hidden_cmd);
13285 install_element(BGP_IPV4L_NODE, &neighbor_nexthop_self_force_cmd);
13286 install_element(BGP_IPV4L_NODE, &no_neighbor_nexthop_self_force_cmd);
13287 install_element(BGP_IPV4L_NODE, &neighbor_nexthop_self_all_hidden_cmd);
13288 install_element(BGP_IPV4L_NODE,
13289 &no_neighbor_nexthop_self_all_hidden_cmd);
13290 install_element(BGP_IPV6_NODE, &neighbor_nexthop_self_force_cmd);
13291 install_element(BGP_IPV6_NODE, &no_neighbor_nexthop_self_force_cmd);
13292 install_element(BGP_IPV6_NODE, &neighbor_nexthop_self_all_hidden_cmd);
13293 install_element(BGP_IPV6_NODE,
13294 &no_neighbor_nexthop_self_all_hidden_cmd);
13295 install_element(BGP_IPV6M_NODE, &neighbor_nexthop_self_force_cmd);
13296 install_element(BGP_IPV6M_NODE, &no_neighbor_nexthop_self_force_cmd);
13297 install_element(BGP_IPV6M_NODE, &neighbor_nexthop_self_all_hidden_cmd);
13298 install_element(BGP_IPV6M_NODE,
13299 &no_neighbor_nexthop_self_all_hidden_cmd);
13300 install_element(BGP_IPV6L_NODE, &neighbor_nexthop_self_force_cmd);
13301 install_element(BGP_IPV6L_NODE, &no_neighbor_nexthop_self_force_cmd);
13302 install_element(BGP_IPV6L_NODE, &neighbor_nexthop_self_all_hidden_cmd);
13303 install_element(BGP_IPV6L_NODE,
13304 &no_neighbor_nexthop_self_all_hidden_cmd);
13305 install_element(BGP_VPNV4_NODE, &neighbor_nexthop_self_force_cmd);
13306 install_element(BGP_VPNV4_NODE, &no_neighbor_nexthop_self_force_cmd);
13307 install_element(BGP_VPNV4_NODE, &neighbor_nexthop_self_all_hidden_cmd);
13308 install_element(BGP_VPNV4_NODE,
13309 &no_neighbor_nexthop_self_all_hidden_cmd);
13310 install_element(BGP_VPNV6_NODE, &neighbor_nexthop_self_force_cmd);
13311 install_element(BGP_VPNV6_NODE, &no_neighbor_nexthop_self_force_cmd);
13312 install_element(BGP_VPNV6_NODE, &neighbor_nexthop_self_all_hidden_cmd);
13313 install_element(BGP_VPNV6_NODE,
13314 &no_neighbor_nexthop_self_all_hidden_cmd);
13315
13316 /* "neighbor as-override" commands. */
13317 install_element(BGP_NODE, &neighbor_as_override_hidden_cmd);
13318 install_element(BGP_NODE, &no_neighbor_as_override_hidden_cmd);
13319 install_element(BGP_IPV4_NODE, &neighbor_as_override_cmd);
13320 install_element(BGP_IPV4_NODE, &no_neighbor_as_override_cmd);
13321 install_element(BGP_IPV4M_NODE, &neighbor_as_override_cmd);
13322 install_element(BGP_IPV4M_NODE, &no_neighbor_as_override_cmd);
13323 install_element(BGP_IPV4L_NODE, &neighbor_as_override_cmd);
13324 install_element(BGP_IPV4L_NODE, &no_neighbor_as_override_cmd);
13325 install_element(BGP_IPV6_NODE, &neighbor_as_override_cmd);
13326 install_element(BGP_IPV6_NODE, &no_neighbor_as_override_cmd);
13327 install_element(BGP_IPV6M_NODE, &neighbor_as_override_cmd);
13328 install_element(BGP_IPV6M_NODE, &no_neighbor_as_override_cmd);
13329 install_element(BGP_IPV6L_NODE, &neighbor_as_override_cmd);
13330 install_element(BGP_IPV6L_NODE, &no_neighbor_as_override_cmd);
13331 install_element(BGP_VPNV4_NODE, &neighbor_as_override_cmd);
13332 install_element(BGP_VPNV4_NODE, &no_neighbor_as_override_cmd);
13333 install_element(BGP_VPNV6_NODE, &neighbor_as_override_cmd);
13334 install_element(BGP_VPNV6_NODE, &no_neighbor_as_override_cmd);
13335
13336 /* "neighbor remove-private-AS" commands. */
13337 install_element(BGP_NODE, &neighbor_remove_private_as_hidden_cmd);
13338 install_element(BGP_NODE, &no_neighbor_remove_private_as_hidden_cmd);
13339 install_element(BGP_NODE, &neighbor_remove_private_as_all_hidden_cmd);
13340 install_element(BGP_NODE,
13341 &no_neighbor_remove_private_as_all_hidden_cmd);
13342 install_element(BGP_NODE,
13343 &neighbor_remove_private_as_replace_as_hidden_cmd);
13344 install_element(BGP_NODE,
13345 &no_neighbor_remove_private_as_replace_as_hidden_cmd);
13346 install_element(BGP_NODE,
13347 &neighbor_remove_private_as_all_replace_as_hidden_cmd);
13348 install_element(
13349 BGP_NODE,
13350 &no_neighbor_remove_private_as_all_replace_as_hidden_cmd);
13351 install_element(BGP_IPV4_NODE, &neighbor_remove_private_as_cmd);
13352 install_element(BGP_IPV4_NODE, &no_neighbor_remove_private_as_cmd);
13353 install_element(BGP_IPV4_NODE, &neighbor_remove_private_as_all_cmd);
13354 install_element(BGP_IPV4_NODE, &no_neighbor_remove_private_as_all_cmd);
13355 install_element(BGP_IPV4_NODE,
13356 &neighbor_remove_private_as_replace_as_cmd);
13357 install_element(BGP_IPV4_NODE,
13358 &no_neighbor_remove_private_as_replace_as_cmd);
13359 install_element(BGP_IPV4_NODE,
13360 &neighbor_remove_private_as_all_replace_as_cmd);
13361 install_element(BGP_IPV4_NODE,
13362 &no_neighbor_remove_private_as_all_replace_as_cmd);
13363 install_element(BGP_IPV4M_NODE, &neighbor_remove_private_as_cmd);
13364 install_element(BGP_IPV4M_NODE, &no_neighbor_remove_private_as_cmd);
13365 install_element(BGP_IPV4M_NODE, &neighbor_remove_private_as_all_cmd);
13366 install_element(BGP_IPV4M_NODE, &no_neighbor_remove_private_as_all_cmd);
13367 install_element(BGP_IPV4M_NODE,
13368 &neighbor_remove_private_as_replace_as_cmd);
13369 install_element(BGP_IPV4M_NODE,
13370 &no_neighbor_remove_private_as_replace_as_cmd);
13371 install_element(BGP_IPV4M_NODE,
13372 &neighbor_remove_private_as_all_replace_as_cmd);
13373 install_element(BGP_IPV4M_NODE,
13374 &no_neighbor_remove_private_as_all_replace_as_cmd);
13375 install_element(BGP_IPV4L_NODE, &neighbor_remove_private_as_cmd);
13376 install_element(BGP_IPV4L_NODE, &no_neighbor_remove_private_as_cmd);
13377 install_element(BGP_IPV4L_NODE, &neighbor_remove_private_as_all_cmd);
13378 install_element(BGP_IPV4L_NODE, &no_neighbor_remove_private_as_all_cmd);
13379 install_element(BGP_IPV4L_NODE,
13380 &neighbor_remove_private_as_replace_as_cmd);
13381 install_element(BGP_IPV4L_NODE,
13382 &no_neighbor_remove_private_as_replace_as_cmd);
13383 install_element(BGP_IPV4L_NODE,
13384 &neighbor_remove_private_as_all_replace_as_cmd);
13385 install_element(BGP_IPV4L_NODE,
13386 &no_neighbor_remove_private_as_all_replace_as_cmd);
13387 install_element(BGP_IPV6_NODE, &neighbor_remove_private_as_cmd);
13388 install_element(BGP_IPV6_NODE, &no_neighbor_remove_private_as_cmd);
13389 install_element(BGP_IPV6_NODE, &neighbor_remove_private_as_all_cmd);
13390 install_element(BGP_IPV6_NODE, &no_neighbor_remove_private_as_all_cmd);
13391 install_element(BGP_IPV6_NODE,
13392 &neighbor_remove_private_as_replace_as_cmd);
13393 install_element(BGP_IPV6_NODE,
13394 &no_neighbor_remove_private_as_replace_as_cmd);
13395 install_element(BGP_IPV6_NODE,
13396 &neighbor_remove_private_as_all_replace_as_cmd);
13397 install_element(BGP_IPV6_NODE,
13398 &no_neighbor_remove_private_as_all_replace_as_cmd);
13399 install_element(BGP_IPV6M_NODE, &neighbor_remove_private_as_cmd);
13400 install_element(BGP_IPV6M_NODE, &no_neighbor_remove_private_as_cmd);
13401 install_element(BGP_IPV6M_NODE, &neighbor_remove_private_as_all_cmd);
13402 install_element(BGP_IPV6M_NODE, &no_neighbor_remove_private_as_all_cmd);
13403 install_element(BGP_IPV6M_NODE,
13404 &neighbor_remove_private_as_replace_as_cmd);
13405 install_element(BGP_IPV6M_NODE,
13406 &no_neighbor_remove_private_as_replace_as_cmd);
13407 install_element(BGP_IPV6M_NODE,
13408 &neighbor_remove_private_as_all_replace_as_cmd);
13409 install_element(BGP_IPV6M_NODE,
13410 &no_neighbor_remove_private_as_all_replace_as_cmd);
13411 install_element(BGP_IPV6L_NODE, &neighbor_remove_private_as_cmd);
13412 install_element(BGP_IPV6L_NODE, &no_neighbor_remove_private_as_cmd);
13413 install_element(BGP_IPV6L_NODE, &neighbor_remove_private_as_all_cmd);
13414 install_element(BGP_IPV6L_NODE, &no_neighbor_remove_private_as_all_cmd);
13415 install_element(BGP_IPV6L_NODE,
13416 &neighbor_remove_private_as_replace_as_cmd);
13417 install_element(BGP_IPV6L_NODE,
13418 &no_neighbor_remove_private_as_replace_as_cmd);
13419 install_element(BGP_IPV6L_NODE,
13420 &neighbor_remove_private_as_all_replace_as_cmd);
13421 install_element(BGP_IPV6L_NODE,
13422 &no_neighbor_remove_private_as_all_replace_as_cmd);
13423 install_element(BGP_VPNV4_NODE, &neighbor_remove_private_as_cmd);
13424 install_element(BGP_VPNV4_NODE, &no_neighbor_remove_private_as_cmd);
13425 install_element(BGP_VPNV4_NODE, &neighbor_remove_private_as_all_cmd);
13426 install_element(BGP_VPNV4_NODE, &no_neighbor_remove_private_as_all_cmd);
13427 install_element(BGP_VPNV4_NODE,
13428 &neighbor_remove_private_as_replace_as_cmd);
13429 install_element(BGP_VPNV4_NODE,
13430 &no_neighbor_remove_private_as_replace_as_cmd);
13431 install_element(BGP_VPNV4_NODE,
13432 &neighbor_remove_private_as_all_replace_as_cmd);
13433 install_element(BGP_VPNV4_NODE,
13434 &no_neighbor_remove_private_as_all_replace_as_cmd);
13435 install_element(BGP_VPNV6_NODE, &neighbor_remove_private_as_cmd);
13436 install_element(BGP_VPNV6_NODE, &no_neighbor_remove_private_as_cmd);
13437 install_element(BGP_VPNV6_NODE, &neighbor_remove_private_as_all_cmd);
13438 install_element(BGP_VPNV6_NODE, &no_neighbor_remove_private_as_all_cmd);
13439 install_element(BGP_VPNV6_NODE,
13440 &neighbor_remove_private_as_replace_as_cmd);
13441 install_element(BGP_VPNV6_NODE,
13442 &no_neighbor_remove_private_as_replace_as_cmd);
13443 install_element(BGP_VPNV6_NODE,
13444 &neighbor_remove_private_as_all_replace_as_cmd);
13445 install_element(BGP_VPNV6_NODE,
13446 &no_neighbor_remove_private_as_all_replace_as_cmd);
13447
13448 /* "neighbor send-community" commands.*/
13449 install_element(BGP_NODE, &neighbor_send_community_hidden_cmd);
13450 install_element(BGP_NODE, &neighbor_send_community_type_hidden_cmd);
13451 install_element(BGP_NODE, &no_neighbor_send_community_hidden_cmd);
13452 install_element(BGP_NODE, &no_neighbor_send_community_type_hidden_cmd);
13453 install_element(BGP_IPV4_NODE, &neighbor_send_community_cmd);
13454 install_element(BGP_IPV4_NODE, &neighbor_send_community_type_cmd);
13455 install_element(BGP_IPV4_NODE, &no_neighbor_send_community_cmd);
13456 install_element(BGP_IPV4_NODE, &no_neighbor_send_community_type_cmd);
13457 install_element(BGP_IPV4M_NODE, &neighbor_send_community_cmd);
13458 install_element(BGP_IPV4M_NODE, &neighbor_send_community_type_cmd);
13459 install_element(BGP_IPV4M_NODE, &no_neighbor_send_community_cmd);
13460 install_element(BGP_IPV4M_NODE, &no_neighbor_send_community_type_cmd);
13461 install_element(BGP_IPV4L_NODE, &neighbor_send_community_cmd);
13462 install_element(BGP_IPV4L_NODE, &neighbor_send_community_type_cmd);
13463 install_element(BGP_IPV4L_NODE, &no_neighbor_send_community_cmd);
13464 install_element(BGP_IPV4L_NODE, &no_neighbor_send_community_type_cmd);
13465 install_element(BGP_IPV6_NODE, &neighbor_send_community_cmd);
13466 install_element(BGP_IPV6_NODE, &neighbor_send_community_type_cmd);
13467 install_element(BGP_IPV6_NODE, &no_neighbor_send_community_cmd);
13468 install_element(BGP_IPV6_NODE, &no_neighbor_send_community_type_cmd);
13469 install_element(BGP_IPV6M_NODE, &neighbor_send_community_cmd);
13470 install_element(BGP_IPV6M_NODE, &neighbor_send_community_type_cmd);
13471 install_element(BGP_IPV6M_NODE, &no_neighbor_send_community_cmd);
13472 install_element(BGP_IPV6M_NODE, &no_neighbor_send_community_type_cmd);
13473 install_element(BGP_IPV6L_NODE, &neighbor_send_community_cmd);
13474 install_element(BGP_IPV6L_NODE, &neighbor_send_community_type_cmd);
13475 install_element(BGP_IPV6L_NODE, &no_neighbor_send_community_cmd);
13476 install_element(BGP_IPV6L_NODE, &no_neighbor_send_community_type_cmd);
13477 install_element(BGP_VPNV4_NODE, &neighbor_send_community_cmd);
13478 install_element(BGP_VPNV4_NODE, &neighbor_send_community_type_cmd);
13479 install_element(BGP_VPNV4_NODE, &no_neighbor_send_community_cmd);
13480 install_element(BGP_VPNV4_NODE, &no_neighbor_send_community_type_cmd);
13481 install_element(BGP_VPNV6_NODE, &neighbor_send_community_cmd);
13482 install_element(BGP_VPNV6_NODE, &neighbor_send_community_type_cmd);
13483 install_element(BGP_VPNV6_NODE, &no_neighbor_send_community_cmd);
13484 install_element(BGP_VPNV6_NODE, &no_neighbor_send_community_type_cmd);
13485
13486 /* "neighbor route-reflector" commands.*/
13487 install_element(BGP_NODE, &neighbor_route_reflector_client_hidden_cmd);
13488 install_element(BGP_NODE,
13489 &no_neighbor_route_reflector_client_hidden_cmd);
13490 install_element(BGP_IPV4_NODE, &neighbor_route_reflector_client_cmd);
13491 install_element(BGP_IPV4_NODE, &no_neighbor_route_reflector_client_cmd);
13492 install_element(BGP_IPV4M_NODE, &neighbor_route_reflector_client_cmd);
13493 install_element(BGP_IPV4M_NODE,
13494 &no_neighbor_route_reflector_client_cmd);
13495 install_element(BGP_IPV4L_NODE, &neighbor_route_reflector_client_cmd);
13496 install_element(BGP_IPV4L_NODE,
13497 &no_neighbor_route_reflector_client_cmd);
13498 install_element(BGP_IPV6_NODE, &neighbor_route_reflector_client_cmd);
13499 install_element(BGP_IPV6_NODE, &no_neighbor_route_reflector_client_cmd);
13500 install_element(BGP_IPV6M_NODE, &neighbor_route_reflector_client_cmd);
13501 install_element(BGP_IPV6M_NODE,
13502 &no_neighbor_route_reflector_client_cmd);
13503 install_element(BGP_IPV6L_NODE, &neighbor_route_reflector_client_cmd);
13504 install_element(BGP_IPV6L_NODE,
13505 &no_neighbor_route_reflector_client_cmd);
13506 install_element(BGP_VPNV4_NODE, &neighbor_route_reflector_client_cmd);
13507 install_element(BGP_VPNV4_NODE,
13508 &no_neighbor_route_reflector_client_cmd);
13509 install_element(BGP_VPNV6_NODE, &neighbor_route_reflector_client_cmd);
13510 install_element(BGP_VPNV6_NODE,
13511 &no_neighbor_route_reflector_client_cmd);
13512 install_element(BGP_FLOWSPECV4_NODE,
13513 &neighbor_route_reflector_client_cmd);
13514 install_element(BGP_FLOWSPECV4_NODE,
13515 &no_neighbor_route_reflector_client_cmd);
13516 install_element(BGP_FLOWSPECV6_NODE,
13517 &neighbor_route_reflector_client_cmd);
13518 install_element(BGP_FLOWSPECV6_NODE,
13519 &no_neighbor_route_reflector_client_cmd);
13520 install_element(BGP_EVPN_NODE, &neighbor_route_reflector_client_cmd);
13521 install_element(BGP_EVPN_NODE, &no_neighbor_route_reflector_client_cmd);
13522
13523 /* "neighbor route-server" commands.*/
13524 install_element(BGP_NODE, &neighbor_route_server_client_hidden_cmd);
13525 install_element(BGP_NODE, &no_neighbor_route_server_client_hidden_cmd);
13526 install_element(BGP_IPV4_NODE, &neighbor_route_server_client_cmd);
13527 install_element(BGP_IPV4_NODE, &no_neighbor_route_server_client_cmd);
13528 install_element(BGP_IPV4M_NODE, &neighbor_route_server_client_cmd);
13529 install_element(BGP_IPV4M_NODE, &no_neighbor_route_server_client_cmd);
13530 install_element(BGP_IPV4L_NODE, &neighbor_route_server_client_cmd);
13531 install_element(BGP_IPV4L_NODE, &no_neighbor_route_server_client_cmd);
13532 install_element(BGP_IPV6_NODE, &neighbor_route_server_client_cmd);
13533 install_element(BGP_IPV6_NODE, &no_neighbor_route_server_client_cmd);
13534 install_element(BGP_IPV6M_NODE, &neighbor_route_server_client_cmd);
13535 install_element(BGP_IPV6M_NODE, &no_neighbor_route_server_client_cmd);
13536 install_element(BGP_IPV6L_NODE, &neighbor_route_server_client_cmd);
13537 install_element(BGP_IPV6L_NODE, &no_neighbor_route_server_client_cmd);
13538 install_element(BGP_VPNV4_NODE, &neighbor_route_server_client_cmd);
13539 install_element(BGP_VPNV4_NODE, &no_neighbor_route_server_client_cmd);
13540 install_element(BGP_VPNV6_NODE, &neighbor_route_server_client_cmd);
13541 install_element(BGP_VPNV6_NODE, &no_neighbor_route_server_client_cmd);
13542 install_element(BGP_EVPN_NODE, &neighbor_route_server_client_cmd);
13543 install_element(BGP_EVPN_NODE, &no_neighbor_route_server_client_cmd);
13544 install_element(BGP_FLOWSPECV4_NODE, &neighbor_route_server_client_cmd);
13545 install_element(BGP_FLOWSPECV4_NODE,
13546 &no_neighbor_route_server_client_cmd);
13547 install_element(BGP_FLOWSPECV6_NODE, &neighbor_route_server_client_cmd);
13548 install_element(BGP_FLOWSPECV6_NODE,
13549 &no_neighbor_route_server_client_cmd);
13550
13551 /* "neighbor addpath-tx-all-paths" commands.*/
13552 install_element(BGP_NODE, &neighbor_addpath_tx_all_paths_hidden_cmd);
13553 install_element(BGP_NODE, &no_neighbor_addpath_tx_all_paths_hidden_cmd);
13554 install_element(BGP_IPV4_NODE, &neighbor_addpath_tx_all_paths_cmd);
13555 install_element(BGP_IPV4_NODE, &no_neighbor_addpath_tx_all_paths_cmd);
13556 install_element(BGP_IPV4M_NODE, &neighbor_addpath_tx_all_paths_cmd);
13557 install_element(BGP_IPV4M_NODE, &no_neighbor_addpath_tx_all_paths_cmd);
13558 install_element(BGP_IPV4L_NODE, &neighbor_addpath_tx_all_paths_cmd);
13559 install_element(BGP_IPV4L_NODE, &no_neighbor_addpath_tx_all_paths_cmd);
13560 install_element(BGP_IPV6_NODE, &neighbor_addpath_tx_all_paths_cmd);
13561 install_element(BGP_IPV6_NODE, &no_neighbor_addpath_tx_all_paths_cmd);
13562 install_element(BGP_IPV6M_NODE, &neighbor_addpath_tx_all_paths_cmd);
13563 install_element(BGP_IPV6M_NODE, &no_neighbor_addpath_tx_all_paths_cmd);
13564 install_element(BGP_IPV6L_NODE, &neighbor_addpath_tx_all_paths_cmd);
13565 install_element(BGP_IPV6L_NODE, &no_neighbor_addpath_tx_all_paths_cmd);
13566 install_element(BGP_VPNV4_NODE, &neighbor_addpath_tx_all_paths_cmd);
13567 install_element(BGP_VPNV4_NODE, &no_neighbor_addpath_tx_all_paths_cmd);
13568 install_element(BGP_VPNV6_NODE, &neighbor_addpath_tx_all_paths_cmd);
13569 install_element(BGP_VPNV6_NODE, &no_neighbor_addpath_tx_all_paths_cmd);
13570
13571 /* "neighbor addpath-tx-bestpath-per-AS" commands.*/
13572 install_element(BGP_NODE,
13573 &neighbor_addpath_tx_bestpath_per_as_hidden_cmd);
13574 install_element(BGP_NODE,
13575 &no_neighbor_addpath_tx_bestpath_per_as_hidden_cmd);
13576 install_element(BGP_IPV4_NODE,
13577 &neighbor_addpath_tx_bestpath_per_as_cmd);
13578 install_element(BGP_IPV4_NODE,
13579 &no_neighbor_addpath_tx_bestpath_per_as_cmd);
13580 install_element(BGP_IPV4M_NODE,
13581 &neighbor_addpath_tx_bestpath_per_as_cmd);
13582 install_element(BGP_IPV4M_NODE,
13583 &no_neighbor_addpath_tx_bestpath_per_as_cmd);
13584 install_element(BGP_IPV4L_NODE,
13585 &neighbor_addpath_tx_bestpath_per_as_cmd);
13586 install_element(BGP_IPV4L_NODE,
13587 &no_neighbor_addpath_tx_bestpath_per_as_cmd);
13588 install_element(BGP_IPV6_NODE,
13589 &neighbor_addpath_tx_bestpath_per_as_cmd);
13590 install_element(BGP_IPV6_NODE,
13591 &no_neighbor_addpath_tx_bestpath_per_as_cmd);
13592 install_element(BGP_IPV6M_NODE,
13593 &neighbor_addpath_tx_bestpath_per_as_cmd);
13594 install_element(BGP_IPV6M_NODE,
13595 &no_neighbor_addpath_tx_bestpath_per_as_cmd);
13596 install_element(BGP_IPV6L_NODE,
13597 &neighbor_addpath_tx_bestpath_per_as_cmd);
13598 install_element(BGP_IPV6L_NODE,
13599 &no_neighbor_addpath_tx_bestpath_per_as_cmd);
13600 install_element(BGP_VPNV4_NODE,
13601 &neighbor_addpath_tx_bestpath_per_as_cmd);
13602 install_element(BGP_VPNV4_NODE,
13603 &no_neighbor_addpath_tx_bestpath_per_as_cmd);
13604 install_element(BGP_VPNV6_NODE,
13605 &neighbor_addpath_tx_bestpath_per_as_cmd);
13606 install_element(BGP_VPNV6_NODE,
13607 &no_neighbor_addpath_tx_bestpath_per_as_cmd);
13608
13609 /* "neighbor passive" commands. */
13610 install_element(BGP_NODE, &neighbor_passive_cmd);
13611 install_element(BGP_NODE, &no_neighbor_passive_cmd);
13612
13613
13614 /* "neighbor shutdown" commands. */
13615 install_element(BGP_NODE, &neighbor_shutdown_cmd);
13616 install_element(BGP_NODE, &no_neighbor_shutdown_cmd);
13617 install_element(BGP_NODE, &neighbor_shutdown_msg_cmd);
13618 install_element(BGP_NODE, &no_neighbor_shutdown_msg_cmd);
13619
13620 /* "neighbor capability extended-nexthop" commands.*/
13621 install_element(BGP_NODE, &neighbor_capability_enhe_cmd);
13622 install_element(BGP_NODE, &no_neighbor_capability_enhe_cmd);
13623
13624 /* "neighbor capability orf prefix-list" commands.*/
13625 install_element(BGP_NODE, &neighbor_capability_orf_prefix_hidden_cmd);
13626 install_element(BGP_NODE,
13627 &no_neighbor_capability_orf_prefix_hidden_cmd);
13628 install_element(BGP_IPV4_NODE, &neighbor_capability_orf_prefix_cmd);
13629 install_element(BGP_IPV4_NODE, &no_neighbor_capability_orf_prefix_cmd);
13630 install_element(BGP_IPV4M_NODE, &neighbor_capability_orf_prefix_cmd);
13631 install_element(BGP_IPV4M_NODE, &no_neighbor_capability_orf_prefix_cmd);
13632 install_element(BGP_IPV4L_NODE, &neighbor_capability_orf_prefix_cmd);
13633 install_element(BGP_IPV4L_NODE, &no_neighbor_capability_orf_prefix_cmd);
13634 install_element(BGP_IPV6_NODE, &neighbor_capability_orf_prefix_cmd);
13635 install_element(BGP_IPV6_NODE, &no_neighbor_capability_orf_prefix_cmd);
13636 install_element(BGP_IPV6M_NODE, &neighbor_capability_orf_prefix_cmd);
13637 install_element(BGP_IPV6M_NODE, &no_neighbor_capability_orf_prefix_cmd);
13638 install_element(BGP_IPV6L_NODE, &neighbor_capability_orf_prefix_cmd);
13639 install_element(BGP_IPV6L_NODE, &no_neighbor_capability_orf_prefix_cmd);
13640
13641 /* "neighbor capability dynamic" commands.*/
13642 install_element(BGP_NODE, &neighbor_capability_dynamic_cmd);
13643 install_element(BGP_NODE, &no_neighbor_capability_dynamic_cmd);
13644
13645 /* "neighbor dont-capability-negotiate" commands. */
13646 install_element(BGP_NODE, &neighbor_dont_capability_negotiate_cmd);
13647 install_element(BGP_NODE, &no_neighbor_dont_capability_negotiate_cmd);
13648
13649 /* "neighbor ebgp-multihop" commands. */
13650 install_element(BGP_NODE, &neighbor_ebgp_multihop_cmd);
13651 install_element(BGP_NODE, &neighbor_ebgp_multihop_ttl_cmd);
13652 install_element(BGP_NODE, &no_neighbor_ebgp_multihop_cmd);
13653
13654 /* "neighbor disable-connected-check" commands. */
13655 install_element(BGP_NODE, &neighbor_disable_connected_check_cmd);
13656 install_element(BGP_NODE, &no_neighbor_disable_connected_check_cmd);
13657
13658 /* "neighbor enforce-first-as" commands. */
13659 install_element(BGP_NODE, &neighbor_enforce_first_as_cmd);
13660 install_element(BGP_NODE, &no_neighbor_enforce_first_as_cmd);
13661
13662 /* "neighbor description" commands. */
13663 install_element(BGP_NODE, &neighbor_description_cmd);
13664 install_element(BGP_NODE, &no_neighbor_description_cmd);
13665 install_element(BGP_NODE, &no_neighbor_description_comment_cmd);
13666
13667 /* "neighbor update-source" commands. "*/
13668 install_element(BGP_NODE, &neighbor_update_source_cmd);
13669 install_element(BGP_NODE, &no_neighbor_update_source_cmd);
13670
13671 /* "neighbor default-originate" commands. */
13672 install_element(BGP_NODE, &neighbor_default_originate_hidden_cmd);
13673 install_element(BGP_NODE, &neighbor_default_originate_rmap_hidden_cmd);
13674 install_element(BGP_NODE, &no_neighbor_default_originate_hidden_cmd);
13675 install_element(BGP_IPV4_NODE, &neighbor_default_originate_cmd);
13676 install_element(BGP_IPV4_NODE, &neighbor_default_originate_rmap_cmd);
13677 install_element(BGP_IPV4_NODE, &no_neighbor_default_originate_cmd);
13678 install_element(BGP_IPV4M_NODE, &neighbor_default_originate_cmd);
13679 install_element(BGP_IPV4M_NODE, &neighbor_default_originate_rmap_cmd);
13680 install_element(BGP_IPV4M_NODE, &no_neighbor_default_originate_cmd);
13681 install_element(BGP_IPV4L_NODE, &neighbor_default_originate_cmd);
13682 install_element(BGP_IPV4L_NODE, &neighbor_default_originate_rmap_cmd);
13683 install_element(BGP_IPV4L_NODE, &no_neighbor_default_originate_cmd);
13684 install_element(BGP_IPV6_NODE, &neighbor_default_originate_cmd);
13685 install_element(BGP_IPV6_NODE, &neighbor_default_originate_rmap_cmd);
13686 install_element(BGP_IPV6_NODE, &no_neighbor_default_originate_cmd);
13687 install_element(BGP_IPV6M_NODE, &neighbor_default_originate_cmd);
13688 install_element(BGP_IPV6M_NODE, &neighbor_default_originate_rmap_cmd);
13689 install_element(BGP_IPV6M_NODE, &no_neighbor_default_originate_cmd);
13690 install_element(BGP_IPV6L_NODE, &neighbor_default_originate_cmd);
13691 install_element(BGP_IPV6L_NODE, &neighbor_default_originate_rmap_cmd);
13692 install_element(BGP_IPV6L_NODE, &no_neighbor_default_originate_cmd);
13693
13694 /* "neighbor port" commands. */
13695 install_element(BGP_NODE, &neighbor_port_cmd);
13696 install_element(BGP_NODE, &no_neighbor_port_cmd);
13697
13698 /* "neighbor weight" commands. */
13699 install_element(BGP_NODE, &neighbor_weight_hidden_cmd);
13700 install_element(BGP_NODE, &no_neighbor_weight_hidden_cmd);
13701
13702 install_element(BGP_IPV4_NODE, &neighbor_weight_cmd);
13703 install_element(BGP_IPV4_NODE, &no_neighbor_weight_cmd);
13704 install_element(BGP_IPV4M_NODE, &neighbor_weight_cmd);
13705 install_element(BGP_IPV4M_NODE, &no_neighbor_weight_cmd);
13706 install_element(BGP_IPV4L_NODE, &neighbor_weight_cmd);
13707 install_element(BGP_IPV4L_NODE, &no_neighbor_weight_cmd);
13708 install_element(BGP_IPV6_NODE, &neighbor_weight_cmd);
13709 install_element(BGP_IPV6_NODE, &no_neighbor_weight_cmd);
13710 install_element(BGP_IPV6M_NODE, &neighbor_weight_cmd);
13711 install_element(BGP_IPV6M_NODE, &no_neighbor_weight_cmd);
13712 install_element(BGP_IPV6L_NODE, &neighbor_weight_cmd);
13713 install_element(BGP_IPV6L_NODE, &no_neighbor_weight_cmd);
13714 install_element(BGP_VPNV4_NODE, &neighbor_weight_cmd);
13715 install_element(BGP_VPNV4_NODE, &no_neighbor_weight_cmd);
13716 install_element(BGP_VPNV6_NODE, &neighbor_weight_cmd);
13717 install_element(BGP_VPNV6_NODE, &no_neighbor_weight_cmd);
13718
13719 /* "neighbor override-capability" commands. */
13720 install_element(BGP_NODE, &neighbor_override_capability_cmd);
13721 install_element(BGP_NODE, &no_neighbor_override_capability_cmd);
13722
13723 /* "neighbor strict-capability-match" commands. */
13724 install_element(BGP_NODE, &neighbor_strict_capability_cmd);
13725 install_element(BGP_NODE, &no_neighbor_strict_capability_cmd);
13726
13727 /* "neighbor timers" commands. */
13728 install_element(BGP_NODE, &neighbor_timers_cmd);
13729 install_element(BGP_NODE, &no_neighbor_timers_cmd);
13730
13731 /* "neighbor timers connect" commands. */
13732 install_element(BGP_NODE, &neighbor_timers_connect_cmd);
13733 install_element(BGP_NODE, &no_neighbor_timers_connect_cmd);
13734
13735 /* "neighbor advertisement-interval" commands. */
13736 install_element(BGP_NODE, &neighbor_advertise_interval_cmd);
13737 install_element(BGP_NODE, &no_neighbor_advertise_interval_cmd);
13738
13739 /* "neighbor interface" commands. */
13740 install_element(BGP_NODE, &neighbor_interface_cmd);
13741 install_element(BGP_NODE, &no_neighbor_interface_cmd);
13742
13743 /* "neighbor distribute" commands. */
13744 install_element(BGP_NODE, &neighbor_distribute_list_hidden_cmd);
13745 install_element(BGP_NODE, &no_neighbor_distribute_list_hidden_cmd);
13746 install_element(BGP_IPV4_NODE, &neighbor_distribute_list_cmd);
13747 install_element(BGP_IPV4_NODE, &no_neighbor_distribute_list_cmd);
13748 install_element(BGP_IPV4M_NODE, &neighbor_distribute_list_cmd);
13749 install_element(BGP_IPV4M_NODE, &no_neighbor_distribute_list_cmd);
13750 install_element(BGP_IPV4L_NODE, &neighbor_distribute_list_cmd);
13751 install_element(BGP_IPV4L_NODE, &no_neighbor_distribute_list_cmd);
13752 install_element(BGP_IPV6_NODE, &neighbor_distribute_list_cmd);
13753 install_element(BGP_IPV6_NODE, &no_neighbor_distribute_list_cmd);
13754 install_element(BGP_IPV6M_NODE, &neighbor_distribute_list_cmd);
13755 install_element(BGP_IPV6M_NODE, &no_neighbor_distribute_list_cmd);
13756 install_element(BGP_IPV6L_NODE, &neighbor_distribute_list_cmd);
13757 install_element(BGP_IPV6L_NODE, &no_neighbor_distribute_list_cmd);
13758 install_element(BGP_VPNV4_NODE, &neighbor_distribute_list_cmd);
13759 install_element(BGP_VPNV4_NODE, &no_neighbor_distribute_list_cmd);
13760 install_element(BGP_VPNV6_NODE, &neighbor_distribute_list_cmd);
13761 install_element(BGP_VPNV6_NODE, &no_neighbor_distribute_list_cmd);
13762
13763 /* "neighbor prefix-list" commands. */
13764 install_element(BGP_NODE, &neighbor_prefix_list_hidden_cmd);
13765 install_element(BGP_NODE, &no_neighbor_prefix_list_hidden_cmd);
13766 install_element(BGP_IPV4_NODE, &neighbor_prefix_list_cmd);
13767 install_element(BGP_IPV4_NODE, &no_neighbor_prefix_list_cmd);
13768 install_element(BGP_IPV4M_NODE, &neighbor_prefix_list_cmd);
13769 install_element(BGP_IPV4M_NODE, &no_neighbor_prefix_list_cmd);
13770 install_element(BGP_IPV4L_NODE, &neighbor_prefix_list_cmd);
13771 install_element(BGP_IPV4L_NODE, &no_neighbor_prefix_list_cmd);
13772 install_element(BGP_IPV6_NODE, &neighbor_prefix_list_cmd);
13773 install_element(BGP_IPV6_NODE, &no_neighbor_prefix_list_cmd);
13774 install_element(BGP_IPV6M_NODE, &neighbor_prefix_list_cmd);
13775 install_element(BGP_IPV6M_NODE, &no_neighbor_prefix_list_cmd);
13776 install_element(BGP_IPV6L_NODE, &neighbor_prefix_list_cmd);
13777 install_element(BGP_IPV6L_NODE, &no_neighbor_prefix_list_cmd);
13778 install_element(BGP_VPNV4_NODE, &neighbor_prefix_list_cmd);
13779 install_element(BGP_VPNV4_NODE, &no_neighbor_prefix_list_cmd);
13780 install_element(BGP_VPNV6_NODE, &neighbor_prefix_list_cmd);
13781 install_element(BGP_VPNV6_NODE, &no_neighbor_prefix_list_cmd);
13782 install_element(BGP_FLOWSPECV4_NODE, &neighbor_prefix_list_cmd);
13783 install_element(BGP_FLOWSPECV4_NODE, &no_neighbor_prefix_list_cmd);
13784 install_element(BGP_FLOWSPECV6_NODE, &neighbor_prefix_list_cmd);
13785 install_element(BGP_FLOWSPECV6_NODE, &no_neighbor_prefix_list_cmd);
13786
13787 /* "neighbor filter-list" commands. */
13788 install_element(BGP_NODE, &neighbor_filter_list_hidden_cmd);
13789 install_element(BGP_NODE, &no_neighbor_filter_list_hidden_cmd);
13790 install_element(BGP_IPV4_NODE, &neighbor_filter_list_cmd);
13791 install_element(BGP_IPV4_NODE, &no_neighbor_filter_list_cmd);
13792 install_element(BGP_IPV4M_NODE, &neighbor_filter_list_cmd);
13793 install_element(BGP_IPV4M_NODE, &no_neighbor_filter_list_cmd);
13794 install_element(BGP_IPV4L_NODE, &neighbor_filter_list_cmd);
13795 install_element(BGP_IPV4L_NODE, &no_neighbor_filter_list_cmd);
13796 install_element(BGP_IPV6_NODE, &neighbor_filter_list_cmd);
13797 install_element(BGP_IPV6_NODE, &no_neighbor_filter_list_cmd);
13798 install_element(BGP_IPV6M_NODE, &neighbor_filter_list_cmd);
13799 install_element(BGP_IPV6M_NODE, &no_neighbor_filter_list_cmd);
13800 install_element(BGP_IPV6L_NODE, &neighbor_filter_list_cmd);
13801 install_element(BGP_IPV6L_NODE, &no_neighbor_filter_list_cmd);
13802 install_element(BGP_VPNV4_NODE, &neighbor_filter_list_cmd);
13803 install_element(BGP_VPNV4_NODE, &no_neighbor_filter_list_cmd);
13804 install_element(BGP_VPNV6_NODE, &neighbor_filter_list_cmd);
13805 install_element(BGP_VPNV6_NODE, &no_neighbor_filter_list_cmd);
13806 install_element(BGP_FLOWSPECV4_NODE, &neighbor_filter_list_cmd);
13807 install_element(BGP_FLOWSPECV4_NODE, &no_neighbor_filter_list_cmd);
13808 install_element(BGP_FLOWSPECV6_NODE, &neighbor_filter_list_cmd);
13809 install_element(BGP_FLOWSPECV6_NODE, &no_neighbor_filter_list_cmd);
13810
13811 /* "neighbor route-map" commands. */
13812 install_element(BGP_NODE, &neighbor_route_map_hidden_cmd);
13813 install_element(BGP_NODE, &no_neighbor_route_map_hidden_cmd);
13814 install_element(BGP_IPV4_NODE, &neighbor_route_map_cmd);
13815 install_element(BGP_IPV4_NODE, &no_neighbor_route_map_cmd);
13816 install_element(BGP_IPV4M_NODE, &neighbor_route_map_cmd);
13817 install_element(BGP_IPV4M_NODE, &no_neighbor_route_map_cmd);
13818 install_element(BGP_IPV4L_NODE, &neighbor_route_map_cmd);
13819 install_element(BGP_IPV4L_NODE, &no_neighbor_route_map_cmd);
13820 install_element(BGP_IPV6_NODE, &neighbor_route_map_cmd);
13821 install_element(BGP_IPV6_NODE, &no_neighbor_route_map_cmd);
13822 install_element(BGP_IPV6M_NODE, &neighbor_route_map_cmd);
13823 install_element(BGP_IPV6M_NODE, &no_neighbor_route_map_cmd);
13824 install_element(BGP_IPV6L_NODE, &neighbor_route_map_cmd);
13825 install_element(BGP_IPV6L_NODE, &no_neighbor_route_map_cmd);
13826 install_element(BGP_VPNV4_NODE, &neighbor_route_map_cmd);
13827 install_element(BGP_VPNV4_NODE, &no_neighbor_route_map_cmd);
13828 install_element(BGP_VPNV6_NODE, &neighbor_route_map_cmd);
13829 install_element(BGP_VPNV6_NODE, &no_neighbor_route_map_cmd);
13830 install_element(BGP_FLOWSPECV4_NODE, &neighbor_route_map_cmd);
13831 install_element(BGP_FLOWSPECV4_NODE, &no_neighbor_route_map_cmd);
13832 install_element(BGP_FLOWSPECV6_NODE, &neighbor_route_map_cmd);
13833 install_element(BGP_FLOWSPECV6_NODE, &no_neighbor_route_map_cmd);
13834 install_element(BGP_EVPN_NODE, &neighbor_route_map_cmd);
13835 install_element(BGP_EVPN_NODE, &no_neighbor_route_map_cmd);
13836
13837 /* "neighbor unsuppress-map" commands. */
13838 install_element(BGP_NODE, &neighbor_unsuppress_map_hidden_cmd);
13839 install_element(BGP_NODE, &no_neighbor_unsuppress_map_hidden_cmd);
13840 install_element(BGP_IPV4_NODE, &neighbor_unsuppress_map_cmd);
13841 install_element(BGP_IPV4_NODE, &no_neighbor_unsuppress_map_cmd);
13842 install_element(BGP_IPV4M_NODE, &neighbor_unsuppress_map_cmd);
13843 install_element(BGP_IPV4M_NODE, &no_neighbor_unsuppress_map_cmd);
13844 install_element(BGP_IPV4L_NODE, &neighbor_unsuppress_map_cmd);
13845 install_element(BGP_IPV4L_NODE, &no_neighbor_unsuppress_map_cmd);
13846 install_element(BGP_IPV6_NODE, &neighbor_unsuppress_map_cmd);
13847 install_element(BGP_IPV6_NODE, &no_neighbor_unsuppress_map_cmd);
13848 install_element(BGP_IPV6M_NODE, &neighbor_unsuppress_map_cmd);
13849 install_element(BGP_IPV6M_NODE, &no_neighbor_unsuppress_map_cmd);
13850 install_element(BGP_IPV6L_NODE, &neighbor_unsuppress_map_cmd);
13851 install_element(BGP_IPV6L_NODE, &no_neighbor_unsuppress_map_cmd);
13852 install_element(BGP_VPNV4_NODE, &neighbor_unsuppress_map_cmd);
13853 install_element(BGP_VPNV4_NODE, &no_neighbor_unsuppress_map_cmd);
13854 install_element(BGP_VPNV6_NODE, &neighbor_unsuppress_map_cmd);
13855 install_element(BGP_VPNV6_NODE, &no_neighbor_unsuppress_map_cmd);
13856
13857 /* "neighbor maximum-prefix" commands. */
13858 install_element(BGP_NODE, &neighbor_maximum_prefix_hidden_cmd);
13859 install_element(BGP_NODE,
13860 &neighbor_maximum_prefix_threshold_hidden_cmd);
13861 install_element(BGP_NODE, &neighbor_maximum_prefix_warning_hidden_cmd);
13862 install_element(BGP_NODE,
13863 &neighbor_maximum_prefix_threshold_warning_hidden_cmd);
13864 install_element(BGP_NODE, &neighbor_maximum_prefix_restart_hidden_cmd);
13865 install_element(BGP_NODE,
13866 &neighbor_maximum_prefix_threshold_restart_hidden_cmd);
13867 install_element(BGP_NODE, &no_neighbor_maximum_prefix_hidden_cmd);
13868 install_element(BGP_IPV4_NODE, &neighbor_maximum_prefix_cmd);
13869 install_element(BGP_IPV4_NODE, &neighbor_maximum_prefix_threshold_cmd);
13870 install_element(BGP_IPV4_NODE, &neighbor_maximum_prefix_warning_cmd);
13871 install_element(BGP_IPV4_NODE,
13872 &neighbor_maximum_prefix_threshold_warning_cmd);
13873 install_element(BGP_IPV4_NODE, &neighbor_maximum_prefix_restart_cmd);
13874 install_element(BGP_IPV4_NODE,
13875 &neighbor_maximum_prefix_threshold_restart_cmd);
13876 install_element(BGP_IPV4_NODE, &no_neighbor_maximum_prefix_cmd);
13877 install_element(BGP_IPV4M_NODE, &neighbor_maximum_prefix_cmd);
13878 install_element(BGP_IPV4M_NODE, &neighbor_maximum_prefix_threshold_cmd);
13879 install_element(BGP_IPV4M_NODE, &neighbor_maximum_prefix_warning_cmd);
13880 install_element(BGP_IPV4M_NODE,
13881 &neighbor_maximum_prefix_threshold_warning_cmd);
13882 install_element(BGP_IPV4M_NODE, &neighbor_maximum_prefix_restart_cmd);
13883 install_element(BGP_IPV4M_NODE,
13884 &neighbor_maximum_prefix_threshold_restart_cmd);
13885 install_element(BGP_IPV4M_NODE, &no_neighbor_maximum_prefix_cmd);
13886 install_element(BGP_IPV4L_NODE, &neighbor_maximum_prefix_cmd);
13887 install_element(BGP_IPV4L_NODE, &neighbor_maximum_prefix_threshold_cmd);
13888 install_element(BGP_IPV4L_NODE, &neighbor_maximum_prefix_warning_cmd);
13889 install_element(BGP_IPV4L_NODE,
13890 &neighbor_maximum_prefix_threshold_warning_cmd);
13891 install_element(BGP_IPV4L_NODE, &neighbor_maximum_prefix_restart_cmd);
13892 install_element(BGP_IPV4L_NODE,
13893 &neighbor_maximum_prefix_threshold_restart_cmd);
13894 install_element(BGP_IPV4L_NODE, &no_neighbor_maximum_prefix_cmd);
13895 install_element(BGP_IPV6_NODE, &neighbor_maximum_prefix_cmd);
13896 install_element(BGP_IPV6_NODE, &neighbor_maximum_prefix_threshold_cmd);
13897 install_element(BGP_IPV6_NODE, &neighbor_maximum_prefix_warning_cmd);
13898 install_element(BGP_IPV6_NODE,
13899 &neighbor_maximum_prefix_threshold_warning_cmd);
13900 install_element(BGP_IPV6_NODE, &neighbor_maximum_prefix_restart_cmd);
13901 install_element(BGP_IPV6_NODE,
13902 &neighbor_maximum_prefix_threshold_restart_cmd);
13903 install_element(BGP_IPV6_NODE, &no_neighbor_maximum_prefix_cmd);
13904 install_element(BGP_IPV6M_NODE, &neighbor_maximum_prefix_cmd);
13905 install_element(BGP_IPV6M_NODE, &neighbor_maximum_prefix_threshold_cmd);
13906 install_element(BGP_IPV6M_NODE, &neighbor_maximum_prefix_warning_cmd);
13907 install_element(BGP_IPV6M_NODE,
13908 &neighbor_maximum_prefix_threshold_warning_cmd);
13909 install_element(BGP_IPV6M_NODE, &neighbor_maximum_prefix_restart_cmd);
13910 install_element(BGP_IPV6M_NODE,
13911 &neighbor_maximum_prefix_threshold_restart_cmd);
13912 install_element(BGP_IPV6M_NODE, &no_neighbor_maximum_prefix_cmd);
13913 install_element(BGP_IPV6L_NODE, &neighbor_maximum_prefix_cmd);
13914 install_element(BGP_IPV6L_NODE, &neighbor_maximum_prefix_threshold_cmd);
13915 install_element(BGP_IPV6L_NODE, &neighbor_maximum_prefix_warning_cmd);
13916 install_element(BGP_IPV6L_NODE,
13917 &neighbor_maximum_prefix_threshold_warning_cmd);
13918 install_element(BGP_IPV6L_NODE, &neighbor_maximum_prefix_restart_cmd);
13919 install_element(BGP_IPV6L_NODE,
13920 &neighbor_maximum_prefix_threshold_restart_cmd);
13921 install_element(BGP_IPV6L_NODE, &no_neighbor_maximum_prefix_cmd);
13922 install_element(BGP_VPNV4_NODE, &neighbor_maximum_prefix_cmd);
13923 install_element(BGP_VPNV4_NODE, &neighbor_maximum_prefix_threshold_cmd);
13924 install_element(BGP_VPNV4_NODE, &neighbor_maximum_prefix_warning_cmd);
13925 install_element(BGP_VPNV4_NODE,
13926 &neighbor_maximum_prefix_threshold_warning_cmd);
13927 install_element(BGP_VPNV4_NODE, &neighbor_maximum_prefix_restart_cmd);
13928 install_element(BGP_VPNV4_NODE,
13929 &neighbor_maximum_prefix_threshold_restart_cmd);
13930 install_element(BGP_VPNV4_NODE, &no_neighbor_maximum_prefix_cmd);
13931 install_element(BGP_VPNV6_NODE, &neighbor_maximum_prefix_cmd);
13932 install_element(BGP_VPNV6_NODE, &neighbor_maximum_prefix_threshold_cmd);
13933 install_element(BGP_VPNV6_NODE, &neighbor_maximum_prefix_warning_cmd);
13934 install_element(BGP_VPNV6_NODE,
13935 &neighbor_maximum_prefix_threshold_warning_cmd);
13936 install_element(BGP_VPNV6_NODE, &neighbor_maximum_prefix_restart_cmd);
13937 install_element(BGP_VPNV6_NODE,
13938 &neighbor_maximum_prefix_threshold_restart_cmd);
13939 install_element(BGP_VPNV6_NODE, &no_neighbor_maximum_prefix_cmd);
13940
13941 /* "neighbor allowas-in" */
13942 install_element(BGP_NODE, &neighbor_allowas_in_hidden_cmd);
13943 install_element(BGP_NODE, &no_neighbor_allowas_in_hidden_cmd);
13944 install_element(BGP_IPV4_NODE, &neighbor_allowas_in_cmd);
13945 install_element(BGP_IPV4_NODE, &no_neighbor_allowas_in_cmd);
13946 install_element(BGP_IPV4M_NODE, &neighbor_allowas_in_cmd);
13947 install_element(BGP_IPV4M_NODE, &no_neighbor_allowas_in_cmd);
13948 install_element(BGP_IPV4L_NODE, &neighbor_allowas_in_cmd);
13949 install_element(BGP_IPV4L_NODE, &no_neighbor_allowas_in_cmd);
13950 install_element(BGP_IPV6_NODE, &neighbor_allowas_in_cmd);
13951 install_element(BGP_IPV6_NODE, &no_neighbor_allowas_in_cmd);
13952 install_element(BGP_IPV6M_NODE, &neighbor_allowas_in_cmd);
13953 install_element(BGP_IPV6M_NODE, &no_neighbor_allowas_in_cmd);
13954 install_element(BGP_IPV6L_NODE, &neighbor_allowas_in_cmd);
13955 install_element(BGP_IPV6L_NODE, &no_neighbor_allowas_in_cmd);
13956 install_element(BGP_VPNV4_NODE, &neighbor_allowas_in_cmd);
13957 install_element(BGP_VPNV4_NODE, &no_neighbor_allowas_in_cmd);
13958 install_element(BGP_VPNV6_NODE, &neighbor_allowas_in_cmd);
13959 install_element(BGP_VPNV6_NODE, &no_neighbor_allowas_in_cmd);
13960 install_element(BGP_EVPN_NODE, &neighbor_allowas_in_cmd);
13961 install_element(BGP_EVPN_NODE, &no_neighbor_allowas_in_cmd);
13962
13963 /* address-family commands. */
13964 install_element(BGP_NODE, &address_family_ipv4_safi_cmd);
13965 install_element(BGP_NODE, &address_family_ipv6_safi_cmd);
13966 #ifdef KEEP_OLD_VPN_COMMANDS
13967 install_element(BGP_NODE, &address_family_vpnv4_cmd);
13968 install_element(BGP_NODE, &address_family_vpnv6_cmd);
13969 #endif /* KEEP_OLD_VPN_COMMANDS */
13970
13971 install_element(BGP_NODE, &address_family_evpn_cmd);
13972
13973 /* "exit-address-family" command. */
13974 install_element(BGP_IPV4_NODE, &exit_address_family_cmd);
13975 install_element(BGP_IPV4M_NODE, &exit_address_family_cmd);
13976 install_element(BGP_IPV4L_NODE, &exit_address_family_cmd);
13977 install_element(BGP_IPV6_NODE, &exit_address_family_cmd);
13978 install_element(BGP_IPV6M_NODE, &exit_address_family_cmd);
13979 install_element(BGP_IPV6L_NODE, &exit_address_family_cmd);
13980 install_element(BGP_VPNV4_NODE, &exit_address_family_cmd);
13981 install_element(BGP_VPNV6_NODE, &exit_address_family_cmd);
13982 install_element(BGP_FLOWSPECV4_NODE, &exit_address_family_cmd);
13983 install_element(BGP_FLOWSPECV6_NODE, &exit_address_family_cmd);
13984 install_element(BGP_EVPN_NODE, &exit_address_family_cmd);
13985
13986 /* "clear ip bgp commands" */
13987 install_element(ENABLE_NODE, &clear_ip_bgp_all_cmd);
13988
13989 /* clear ip bgp prefix */
13990 install_element(ENABLE_NODE, &clear_ip_bgp_prefix_cmd);
13991 install_element(ENABLE_NODE, &clear_bgp_ipv6_safi_prefix_cmd);
13992 install_element(ENABLE_NODE, &clear_bgp_instance_ipv6_safi_prefix_cmd);
13993
13994 /* "show [ip] bgp summary" commands. */
13995 install_element(VIEW_NODE, &show_bgp_instance_all_ipv6_updgrps_cmd);
13996 install_element(VIEW_NODE, &show_bgp_l2vpn_evpn_updgrps_cmd);
13997 install_element(VIEW_NODE, &show_bgp_instance_updgrps_stats_cmd);
13998 install_element(VIEW_NODE, &show_bgp_updgrps_stats_cmd);
13999 install_element(VIEW_NODE, &show_ip_bgp_instance_updgrps_adj_s_cmd);
14000 install_element(VIEW_NODE, &show_ip_bgp_summary_cmd);
14001 install_element(VIEW_NODE, &show_ip_bgp_updgrps_cmd);
14002
14003 /* "show [ip] bgp neighbors" commands. */
14004 install_element(VIEW_NODE, &show_ip_bgp_neighbors_cmd);
14005
14006 /* "show [ip] bgp peer-group" commands. */
14007 install_element(VIEW_NODE, &show_ip_bgp_peer_groups_cmd);
14008
14009 /* "show [ip] bgp paths" commands. */
14010 install_element(VIEW_NODE, &show_ip_bgp_paths_cmd);
14011
14012 /* "show [ip] bgp community" commands. */
14013 install_element(VIEW_NODE, &show_ip_bgp_community_info_cmd);
14014
14015 /* "show ip bgp large-community" commands. */
14016 install_element(VIEW_NODE, &show_ip_bgp_lcommunity_info_cmd);
14017 /* "show [ip] bgp attribute-info" commands. */
14018 install_element(VIEW_NODE, &show_ip_bgp_attr_info_cmd);
14019 /* "show [ip] bgp route-leak" command */
14020 install_element(VIEW_NODE, &show_ip_bgp_route_leak_cmd);
14021
14022 /* "redistribute" commands. */
14023 install_element(BGP_NODE, &bgp_redistribute_ipv4_hidden_cmd);
14024 install_element(BGP_NODE, &no_bgp_redistribute_ipv4_hidden_cmd);
14025 install_element(BGP_NODE, &bgp_redistribute_ipv4_rmap_hidden_cmd);
14026 install_element(BGP_NODE, &bgp_redistribute_ipv4_metric_hidden_cmd);
14027 install_element(BGP_NODE,
14028 &bgp_redistribute_ipv4_rmap_metric_hidden_cmd);
14029 install_element(BGP_NODE,
14030 &bgp_redistribute_ipv4_metric_rmap_hidden_cmd);
14031 install_element(BGP_NODE, &bgp_redistribute_ipv4_ospf_hidden_cmd);
14032 install_element(BGP_NODE, &no_bgp_redistribute_ipv4_ospf_hidden_cmd);
14033 install_element(BGP_NODE, &bgp_redistribute_ipv4_ospf_rmap_hidden_cmd);
14034 install_element(BGP_NODE,
14035 &bgp_redistribute_ipv4_ospf_metric_hidden_cmd);
14036 install_element(BGP_NODE,
14037 &bgp_redistribute_ipv4_ospf_rmap_metric_hidden_cmd);
14038 install_element(BGP_NODE,
14039 &bgp_redistribute_ipv4_ospf_metric_rmap_hidden_cmd);
14040 install_element(BGP_IPV4_NODE, &bgp_redistribute_ipv4_cmd);
14041 install_element(BGP_IPV4_NODE, &no_bgp_redistribute_ipv4_cmd);
14042 install_element(BGP_IPV4_NODE, &bgp_redistribute_ipv4_rmap_cmd);
14043 install_element(BGP_IPV4_NODE, &bgp_redistribute_ipv4_metric_cmd);
14044 install_element(BGP_IPV4_NODE, &bgp_redistribute_ipv4_rmap_metric_cmd);
14045 install_element(BGP_IPV4_NODE, &bgp_redistribute_ipv4_metric_rmap_cmd);
14046 install_element(BGP_IPV4_NODE, &bgp_redistribute_ipv4_ospf_cmd);
14047 install_element(BGP_IPV4_NODE, &no_bgp_redistribute_ipv4_ospf_cmd);
14048 install_element(BGP_IPV4_NODE, &bgp_redistribute_ipv4_ospf_rmap_cmd);
14049 install_element(BGP_IPV4_NODE, &bgp_redistribute_ipv4_ospf_metric_cmd);
14050 install_element(BGP_IPV4_NODE,
14051 &bgp_redistribute_ipv4_ospf_rmap_metric_cmd);
14052 install_element(BGP_IPV4_NODE,
14053 &bgp_redistribute_ipv4_ospf_metric_rmap_cmd);
14054 install_element(BGP_IPV6_NODE, &bgp_redistribute_ipv6_cmd);
14055 install_element(BGP_IPV6_NODE, &no_bgp_redistribute_ipv6_cmd);
14056 install_element(BGP_IPV6_NODE, &bgp_redistribute_ipv6_rmap_cmd);
14057 install_element(BGP_IPV6_NODE, &bgp_redistribute_ipv6_metric_cmd);
14058 install_element(BGP_IPV6_NODE, &bgp_redistribute_ipv6_rmap_metric_cmd);
14059 install_element(BGP_IPV6_NODE, &bgp_redistribute_ipv6_metric_rmap_cmd);
14060
14061 /* import|export vpn [route-map WORD] */
14062 install_element(BGP_IPV4_NODE, &bgp_imexport_vpn_cmd);
14063 install_element(BGP_IPV6_NODE, &bgp_imexport_vpn_cmd);
14064
14065 install_element(BGP_IPV4_NODE, &bgp_imexport_vrf_cmd);
14066 install_element(BGP_IPV6_NODE, &bgp_imexport_vrf_cmd);
14067
14068 /* ttl_security commands */
14069 install_element(BGP_NODE, &neighbor_ttl_security_cmd);
14070 install_element(BGP_NODE, &no_neighbor_ttl_security_cmd);
14071
14072 /* "show [ip] bgp memory" commands. */
14073 install_element(VIEW_NODE, &show_bgp_memory_cmd);
14074
14075 /* "show bgp martian next-hop" */
14076 install_element(VIEW_NODE, &show_bgp_martian_nexthop_db_cmd);
14077
14078 install_element(VIEW_NODE, &show_bgp_mac_hash_cmd);
14079
14080 /* "show [ip] bgp views" commands. */
14081 install_element(VIEW_NODE, &show_bgp_views_cmd);
14082
14083 /* "show [ip] bgp vrfs" commands. */
14084 install_element(VIEW_NODE, &show_bgp_vrfs_cmd);
14085
14086 /* Community-list. */
14087 community_list_vty();
14088
14089 /* vpn-policy commands */
14090 install_element(BGP_IPV4_NODE, &af_rd_vpn_export_cmd);
14091 install_element(BGP_IPV6_NODE, &af_rd_vpn_export_cmd);
14092 install_element(BGP_IPV4_NODE, &af_label_vpn_export_cmd);
14093 install_element(BGP_IPV6_NODE, &af_label_vpn_export_cmd);
14094 install_element(BGP_IPV4_NODE, &af_nexthop_vpn_export_cmd);
14095 install_element(BGP_IPV6_NODE, &af_nexthop_vpn_export_cmd);
14096 install_element(BGP_IPV4_NODE, &af_rt_vpn_imexport_cmd);
14097 install_element(BGP_IPV6_NODE, &af_rt_vpn_imexport_cmd);
14098 install_element(BGP_IPV4_NODE, &af_route_map_vpn_imexport_cmd);
14099 install_element(BGP_IPV6_NODE, &af_route_map_vpn_imexport_cmd);
14100 install_element(BGP_IPV4_NODE, &af_import_vrf_route_map_cmd);
14101 install_element(BGP_IPV6_NODE, &af_import_vrf_route_map_cmd);
14102
14103 install_element(BGP_IPV4_NODE, &af_routetarget_import_cmd);
14104 install_element(BGP_IPV6_NODE, &af_routetarget_import_cmd);
14105
14106 install_element(BGP_IPV4_NODE, &af_no_rd_vpn_export_cmd);
14107 install_element(BGP_IPV6_NODE, &af_no_rd_vpn_export_cmd);
14108 install_element(BGP_IPV4_NODE, &af_no_label_vpn_export_cmd);
14109 install_element(BGP_IPV6_NODE, &af_no_label_vpn_export_cmd);
14110 install_element(BGP_IPV4_NODE, &af_no_nexthop_vpn_export_cmd);
14111 install_element(BGP_IPV6_NODE, &af_no_nexthop_vpn_export_cmd);
14112 install_element(BGP_IPV4_NODE, &af_no_rt_vpn_imexport_cmd);
14113 install_element(BGP_IPV6_NODE, &af_no_rt_vpn_imexport_cmd);
14114 install_element(BGP_IPV4_NODE, &af_no_route_map_vpn_imexport_cmd);
14115 install_element(BGP_IPV6_NODE, &af_no_route_map_vpn_imexport_cmd);
14116 install_element(BGP_IPV4_NODE, &af_no_import_vrf_route_map_cmd);
14117 install_element(BGP_IPV6_NODE, &af_no_import_vrf_route_map_cmd);
14118 }
14119
14120 #include "memory.h"
14121 #include "bgp_regex.h"
14122 #include "bgp_clist.h"
14123 #include "bgp_ecommunity.h"
14124
14125 /* VTY functions. */
14126
14127 /* Direction value to string conversion. */
14128 static const char *community_direct_str(int direct)
14129 {
14130 switch (direct) {
14131 case COMMUNITY_DENY:
14132 return "deny";
14133 case COMMUNITY_PERMIT:
14134 return "permit";
14135 default:
14136 return "unknown";
14137 }
14138 }
14139
14140 /* Display error string. */
14141 static void community_list_perror(struct vty *vty, int ret)
14142 {
14143 switch (ret) {
14144 case COMMUNITY_LIST_ERR_CANT_FIND_LIST:
14145 vty_out(vty, "%% Can't find community-list\n");
14146 break;
14147 case COMMUNITY_LIST_ERR_MALFORMED_VAL:
14148 vty_out(vty, "%% Malformed community-list value\n");
14149 break;
14150 case COMMUNITY_LIST_ERR_STANDARD_CONFLICT:
14151 vty_out(vty,
14152 "%% Community name conflict, previously defined as standard community\n");
14153 break;
14154 case COMMUNITY_LIST_ERR_EXPANDED_CONFLICT:
14155 vty_out(vty,
14156 "%% Community name conflict, previously defined as expanded community\n");
14157 break;
14158 }
14159 }
14160
14161 /* "community-list" keyword help string. */
14162 #define COMMUNITY_LIST_STR "Add a community list entry\n"
14163
14164 /*community-list standard */
14165 DEFUN (community_list_standard,
14166 bgp_community_list_standard_cmd,
14167 "bgp community-list <(1-99)|standard WORD> <deny|permit> AA:NN...",
14168 BGP_STR
14169 COMMUNITY_LIST_STR
14170 "Community list number (standard)\n"
14171 "Add an standard community-list entry\n"
14172 "Community list name\n"
14173 "Specify community to reject\n"
14174 "Specify community to accept\n"
14175 COMMUNITY_VAL_STR)
14176 {
14177 char *cl_name_or_number = NULL;
14178 int direct = 0;
14179 int style = COMMUNITY_LIST_STANDARD;
14180
14181 int idx = 0;
14182
14183 if (argv_find(argv, argc, "ip", &idx)) {
14184 vty_out(vty, "This config option is deprecated, and is scheduled for removal.\n");
14185 vty_out(vty, "if you are using this please migrate to the below command.\n");
14186 vty_out(vty, "'bgp community-list <(1-99)|(100-500)|standard|expanded> <deny|permit> AA:NN'\n");
14187 zlog_warn("Deprecated option: 'ip community-list <(1-99)|(100-500)|standard|expanded> <deny|permit> AA:NN' being used");
14188 }
14189
14190 argv_find(argv, argc, "(1-99)", &idx);
14191 argv_find(argv, argc, "WORD", &idx);
14192 cl_name_or_number = argv[idx]->arg;
14193 direct = argv_find(argv, argc, "permit", &idx) ? COMMUNITY_PERMIT
14194 : COMMUNITY_DENY;
14195 argv_find(argv, argc, "AA:NN", &idx);
14196 char *str = argv_concat(argv, argc, idx);
14197
14198 int ret = community_list_set(bgp_clist, cl_name_or_number, str, direct,
14199 style);
14200
14201 XFREE(MTYPE_TMP, str);
14202
14203 if (ret < 0) {
14204 /* Display error string. */
14205 community_list_perror(vty, ret);
14206 return CMD_WARNING_CONFIG_FAILED;
14207 }
14208
14209 return CMD_SUCCESS;
14210 }
14211
14212 #if CONFDATE > 20191005
14213 CPP_NOTICE("bgpd: remove deprecated 'ip community-list <(1-99)|(100-500)|standard|expanded> <deny|permit> AA:NN' command")
14214 #endif
14215 ALIAS (community_list_standard,
14216 ip_community_list_standard_cmd,
14217 "ip community-list <(1-99)|standard WORD> <deny|permit> AA:NN...",
14218 IP_STR
14219 COMMUNITY_LIST_STR
14220 "Community list number (standard)\n"
14221 "Add an standard community-list entry\n"
14222 "Community list name\n"
14223 "Specify community to reject\n"
14224 "Specify community to accept\n"
14225 COMMUNITY_VAL_STR)
14226
14227 DEFUN (no_community_list_standard_all,
14228 no_bgp_community_list_standard_all_cmd,
14229 "no bgp community-list <(1-99)|standard WORD> <deny|permit> AA:NN...",
14230 NO_STR
14231 BGP_STR
14232 COMMUNITY_LIST_STR
14233 "Community list number (standard)\n"
14234 "Add an standard community-list entry\n"
14235 "Community list name\n"
14236 "Specify community to reject\n"
14237 "Specify community to accept\n"
14238 COMMUNITY_VAL_STR)
14239 {
14240 char *cl_name_or_number = NULL;
14241 char *str = NULL;
14242 int direct = 0;
14243 int style = COMMUNITY_LIST_STANDARD;
14244
14245 int idx = 0;
14246
14247 if (argv_find(argv, argc, "ip", &idx)) {
14248 vty_out(vty, "This config option is deprecated, and is scheduled for removal\n");
14249 vty_out(vty, "if you are using this please migrate to the below command.\n");
14250 vty_out(vty, "'no bgp community-list <(1-99)|(100-500)|standard|expanded> <deny|permit> AA:NN'\n");
14251 zlog_warn("Deprecated option: 'no ip community-list <(1-99)|(100-500)|standard|expanded> <deny|permit> |AA:NN' being used");
14252 }
14253
14254 argv_find(argv, argc, "permit", &idx);
14255 argv_find(argv, argc, "deny", &idx);
14256
14257 if (idx) {
14258 direct = argv_find(argv, argc, "permit", &idx)
14259 ? COMMUNITY_PERMIT
14260 : COMMUNITY_DENY;
14261
14262 idx = 0;
14263 argv_find(argv, argc, "AA:NN", &idx);
14264 str = argv_concat(argv, argc, idx);
14265 }
14266
14267 idx = 0;
14268 argv_find(argv, argc, "(1-99)", &idx);
14269 argv_find(argv, argc, "WORD", &idx);
14270 cl_name_or_number = argv[idx]->arg;
14271
14272 int ret = community_list_unset(bgp_clist, cl_name_or_number, str,
14273 direct, style);
14274
14275 XFREE(MTYPE_TMP, str);
14276
14277 if (ret < 0) {
14278 community_list_perror(vty, ret);
14279 return CMD_WARNING_CONFIG_FAILED;
14280 }
14281
14282 return CMD_SUCCESS;
14283 }
14284 ALIAS (no_community_list_standard_all,
14285 no_ip_community_list_standard_all_cmd,
14286 "no ip community-list <(1-99)|standard WORD> <deny|permit> AA:NN...",
14287 NO_STR
14288 IP_STR
14289 COMMUNITY_LIST_STR
14290 "Community list number (standard)\n"
14291 "Add an standard community-list entry\n"
14292 "Community list name\n"
14293 "Specify community to reject\n"
14294 "Specify community to accept\n"
14295 COMMUNITY_VAL_STR)
14296
14297 ALIAS(no_community_list_standard_all, no_bgp_community_list_standard_all_list_cmd,
14298 "no bgp community-list <(1-99)|standard WORD>",
14299 NO_STR BGP_STR COMMUNITY_LIST_STR
14300 "Community list number (standard)\n"
14301 "Add an standard community-list entry\n"
14302 "Community list name\n")
14303
14304 ALIAS(no_community_list_standard_all, no_ip_community_list_standard_all_list_cmd,
14305 "no ip community-list <(1-99)|standard WORD>",
14306 NO_STR BGP_STR COMMUNITY_LIST_STR
14307 "Community list number (standard)\n"
14308 "Add an standard community-list entry\n"
14309 "Community list name\n")
14310
14311 /*community-list expanded */
14312 DEFUN (community_list_expanded_all,
14313 bgp_community_list_expanded_all_cmd,
14314 "bgp community-list <(100-500)|expanded WORD> <deny|permit> AA:NN...",
14315 BGP_STR
14316 COMMUNITY_LIST_STR
14317 "Community list number (expanded)\n"
14318 "Add an expanded community-list entry\n"
14319 "Community list name\n"
14320 "Specify community to reject\n"
14321 "Specify community to accept\n"
14322 COMMUNITY_VAL_STR)
14323 {
14324 char *cl_name_or_number = NULL;
14325 int direct = 0;
14326 int style = COMMUNITY_LIST_EXPANDED;
14327
14328 int idx = 0;
14329 if (argv_find(argv, argc, "ip", &idx)) {
14330 vty_out(vty, "This config option is deprecated, and is scheduled for removal.\n");
14331 vty_out(vty, "if you are using this please migrate to the below command.\n");
14332 vty_out(vty, "'bgp community-list <(1-99)|(100-500)|standard|expanded> <deny|permit> AA:NN'\n");
14333 zlog_warn("Deprecated option: 'ip community-list <(1-99)|(100-500)|standard|expanded> <deny|permit> AA:NN' being used");
14334 }
14335 argv_find(argv, argc, "(100-500)", &idx);
14336 argv_find(argv, argc, "WORD", &idx);
14337 cl_name_or_number = argv[idx]->arg;
14338 direct = argv_find(argv, argc, "permit", &idx) ? COMMUNITY_PERMIT
14339 : COMMUNITY_DENY;
14340 argv_find(argv, argc, "AA:NN", &idx);
14341 char *str = argv_concat(argv, argc, idx);
14342
14343 int ret = community_list_set(bgp_clist, cl_name_or_number, str, direct,
14344 style);
14345
14346 XFREE(MTYPE_TMP, str);
14347
14348 if (ret < 0) {
14349 /* Display error string. */
14350 community_list_perror(vty, ret);
14351 return CMD_WARNING_CONFIG_FAILED;
14352 }
14353
14354 return CMD_SUCCESS;
14355 }
14356
14357 ALIAS (community_list_expanded_all,
14358 ip_community_list_expanded_all_cmd,
14359 "ip community-list <(100-500)|expanded WORD> <deny|permit> AA:NN...",
14360 IP_STR
14361 COMMUNITY_LIST_STR
14362 "Community list number (expanded)\n"
14363 "Add an expanded community-list entry\n"
14364 "Community list name\n"
14365 "Specify community to reject\n"
14366 "Specify community to accept\n"
14367 COMMUNITY_VAL_STR)
14368
14369 DEFUN (no_community_list_expanded_all,
14370 no_bgp_community_list_expanded_all_cmd,
14371 "no bgp community-list <(100-500)|expanded WORD> <deny|permit> AA:NN...",
14372 NO_STR
14373 BGP_STR
14374 COMMUNITY_LIST_STR
14375 "Community list number (expanded)\n"
14376 "Add an expanded community-list entry\n"
14377 "Community list name\n"
14378 "Specify community to reject\n"
14379 "Specify community to accept\n"
14380 COMMUNITY_VAL_STR)
14381 {
14382 char *cl_name_or_number = NULL;
14383 char *str = NULL;
14384 int direct = 0;
14385 int style = COMMUNITY_LIST_EXPANDED;
14386
14387 int idx = 0;
14388 if (argv_find(argv, argc, "ip", &idx)) {
14389 vty_out(vty, "This config option is deprecated, and is scheduled for removal.\n");
14390 vty_out(vty, "if you are using this please migrate to the below command.\n");
14391 vty_out(vty, "'no bgp community-list <(1-99)|(100-500)|standard|expanded> <deny|permit> AA:NN'\n");
14392 zlog_warn("Deprecated option: 'no ip community-list <(1-99)|(100-500)|standard|expanded> <deny|permit> AA:NN' being used");
14393 }
14394
14395 idx = 0;
14396 argv_find(argv, argc, "permit", &idx);
14397 argv_find(argv, argc, "deny", &idx);
14398
14399 if (idx) {
14400 direct = argv_find(argv, argc, "permit", &idx)
14401 ? COMMUNITY_PERMIT
14402 : COMMUNITY_DENY;
14403
14404 idx = 0;
14405 argv_find(argv, argc, "AA:NN", &idx);
14406 str = argv_concat(argv, argc, idx);
14407 }
14408
14409 idx = 0;
14410 argv_find(argv, argc, "(100-500)", &idx);
14411 argv_find(argv, argc, "WORD", &idx);
14412 cl_name_or_number = argv[idx]->arg;
14413
14414 int ret = community_list_unset(bgp_clist, cl_name_or_number, str,
14415 direct, style);
14416
14417 XFREE(MTYPE_TMP, str);
14418
14419 if (ret < 0) {
14420 community_list_perror(vty, ret);
14421 return CMD_WARNING_CONFIG_FAILED;
14422 }
14423
14424 return CMD_SUCCESS;
14425 }
14426
14427 ALIAS (no_community_list_expanded_all,
14428 no_ip_community_list_expanded_all_cmd,
14429 "no ip community-list <(100-500)|expanded WORD> <deny|permit> AA:NN...",
14430 NO_STR
14431 IP_STR
14432 COMMUNITY_LIST_STR
14433 "Community list number (expanded)\n"
14434 "Add an expanded community-list entry\n"
14435 "Community list name\n"
14436 "Specify community to reject\n"
14437 "Specify community to accept\n"
14438 COMMUNITY_VAL_STR)
14439
14440 ALIAS(no_community_list_expanded_all, no_bgp_community_list_expanded_all_list_cmd,
14441 "no bgp community-list <(100-500)|expanded WORD>",
14442 NO_STR IP_STR COMMUNITY_LIST_STR
14443 "Community list number (expanded)\n"
14444 "Add an expanded community-list entry\n"
14445 "Community list name\n")
14446
14447 ALIAS(no_community_list_expanded_all, no_ip_community_list_expanded_all_list_cmd,
14448 "no ip community-list <(100-500)|expanded WORD>",
14449 NO_STR IP_STR COMMUNITY_LIST_STR
14450 "Community list number (expanded)\n"
14451 "Add an expanded community-list entry\n"
14452 "Community list name\n")
14453
14454 /* Return configuration string of community-list entry. */
14455 static const char *community_list_config_str(struct community_entry *entry)
14456 {
14457 const char *str;
14458
14459 if (entry->any)
14460 str = "";
14461 else {
14462 if (entry->style == COMMUNITY_LIST_STANDARD)
14463 str = community_str(entry->u.com, false);
14464 else if (entry->style == LARGE_COMMUNITY_LIST_STANDARD)
14465 str = lcommunity_str(entry->u.lcom, false);
14466 else
14467 str = entry->config;
14468 }
14469 return str;
14470 }
14471
14472 static void community_list_show(struct vty *vty, struct community_list *list)
14473 {
14474 struct community_entry *entry;
14475
14476 for (entry = list->head; entry; entry = entry->next) {
14477 if (entry == list->head) {
14478 if (all_digit(list->name))
14479 vty_out(vty, "Community %s list %s\n",
14480 entry->style == COMMUNITY_LIST_STANDARD
14481 ? "standard"
14482 : "(expanded) access",
14483 list->name);
14484 else
14485 vty_out(vty, "Named Community %s list %s\n",
14486 entry->style == COMMUNITY_LIST_STANDARD
14487 ? "standard"
14488 : "expanded",
14489 list->name);
14490 }
14491 if (entry->any)
14492 vty_out(vty, " %s\n",
14493 community_direct_str(entry->direct));
14494 else
14495 vty_out(vty, " %s %s\n",
14496 community_direct_str(entry->direct),
14497 community_list_config_str(entry));
14498 }
14499 }
14500
14501 DEFUN (show_community_list,
14502 show_bgp_community_list_cmd,
14503 "show bgp community-list",
14504 SHOW_STR
14505 BGP_STR
14506 "List community-list\n")
14507 {
14508 struct community_list *list;
14509 struct community_list_master *cm;
14510
14511 int idx = 0;
14512 if (argv_find(argv, argc, "ip", &idx)) {
14513 vty_out(vty, "This config option is deprecated, and is scheduled for removal.\n");
14514 vty_out(vty, "if you are using this please migrate to the below command.\n");
14515 vty_out(vty, "'show bgp community-list <(1-500)|WORD>'\n");
14516 zlog_warn("Deprecated option: 'ip show community-list <(1-500)|WORD>' being used");
14517 }
14518 cm = community_list_master_lookup(bgp_clist, COMMUNITY_LIST_MASTER);
14519 if (!cm)
14520 return CMD_SUCCESS;
14521
14522 for (list = cm->num.head; list; list = list->next)
14523 community_list_show(vty, list);
14524
14525 for (list = cm->str.head; list; list = list->next)
14526 community_list_show(vty, list);
14527
14528 return CMD_SUCCESS;
14529 }
14530
14531 ALIAS (show_community_list,
14532 show_ip_community_list_cmd,
14533 "show ip community-list",
14534 SHOW_STR
14535 IP_STR
14536 "List community-list\n")
14537
14538 DEFUN (show_community_list_arg,
14539 show_bgp_community_list_arg_cmd,
14540 "show bgp community-list <(1-500)|WORD>",
14541 SHOW_STR
14542 BGP_STR
14543 "List community-list\n"
14544 "Community-list number\n"
14545 "Community-list name\n")
14546 {
14547 int idx_comm_list = 3;
14548 struct community_list *list;
14549
14550 int idx = 0;
14551 if (argv_find(argv, argc, "ip", &idx)) {
14552 vty_out(vty, "This config option is deprecated, and is scheduled for removal.\n");
14553 vty_out(vty, "if you are using this please migrate to the below command.\n");
14554 vty_out(vty, "'show bgp community-list <(1-500)|WORD>'\n");
14555 zlog_warn("Deprecated option: 'ip show community-list <(1-500)|WORD>' being used");
14556 }
14557 list = community_list_lookup(bgp_clist, argv[idx_comm_list]->arg, 0,
14558 COMMUNITY_LIST_MASTER);
14559 if (!list) {
14560 vty_out(vty, "%% Can't find community-list\n");
14561 return CMD_WARNING;
14562 }
14563
14564 community_list_show(vty, list);
14565
14566 return CMD_SUCCESS;
14567 }
14568
14569 ALIAS (show_community_list_arg,
14570 show_ip_community_list_arg_cmd,
14571 "show ip community-list <(1-500)|WORD>",
14572 SHOW_STR
14573 IP_STR
14574 "List community-list\n"
14575 "Community-list number\n"
14576 "Community-list name\n")
14577
14578 /*
14579 * Large Community code.
14580 */
14581 static int lcommunity_list_set_vty(struct vty *vty, int argc,
14582 struct cmd_token **argv, int style,
14583 int reject_all_digit_name)
14584 {
14585 int ret;
14586 int direct;
14587 char *str;
14588 int idx = 0;
14589 char *cl_name;
14590
14591 if (argv_find(argv, argc, "ip", &idx)) {
14592 vty_out(vty, "This config option is deprecated, and is scheduled for removal.\n");
14593 vty_out(vty, "if you are using this please migrate to the below command.\n");
14594 vty_out(vty, "'bgp large-community-list <(1-99)|(100-500)|standard|expanded> <deny|permit> <LINE|AA:BB:CC>'\n");
14595 zlog_warn("Deprecated option: 'large-community-list <(1-99)|(100-500)|standard|expanded> <deny|permit> <LINE|AA:BB:CC>' being used");
14596 }
14597 direct = argv_find(argv, argc, "permit", &idx) ? COMMUNITY_PERMIT
14598 : COMMUNITY_DENY;
14599
14600 /* All digit name check. */
14601 idx = 0;
14602 argv_find(argv, argc, "WORD", &idx);
14603 argv_find(argv, argc, "(1-99)", &idx);
14604 argv_find(argv, argc, "(100-500)", &idx);
14605 cl_name = argv[idx]->arg;
14606 if (reject_all_digit_name && all_digit(cl_name)) {
14607 vty_out(vty, "%% Community name cannot have all digits\n");
14608 return CMD_WARNING_CONFIG_FAILED;
14609 }
14610
14611 idx = 0;
14612 argv_find(argv, argc, "AA:BB:CC", &idx);
14613 argv_find(argv, argc, "LINE", &idx);
14614 /* Concat community string argument. */
14615 if (idx)
14616 str = argv_concat(argv, argc, idx);
14617 else
14618 str = NULL;
14619
14620 ret = lcommunity_list_set(bgp_clist, cl_name, str, direct, style);
14621
14622 /* Free temporary community list string allocated by
14623 argv_concat(). */
14624 XFREE(MTYPE_TMP, str);
14625
14626 if (ret < 0) {
14627 community_list_perror(vty, ret);
14628 return CMD_WARNING_CONFIG_FAILED;
14629 }
14630 return CMD_SUCCESS;
14631 }
14632
14633 static int lcommunity_list_unset_vty(struct vty *vty, int argc,
14634 struct cmd_token **argv, int style)
14635 {
14636 int ret;
14637 int direct = 0;
14638 char *str = NULL;
14639 int idx = 0;
14640
14641 if (argv_find(argv, argc, "ip", &idx)) {
14642 vty_out(vty, "This config option is deprecated, and is scheduled for removal.\n");
14643 vty_out(vty, "if you are using this please migrate to the below command.\n");
14644 vty_out(vty, "'no bgp large-community-list <(1-99)|(100-500)|standard|expanded> <deny|permit> <LINE|AA:BB:CC>'\n");
14645 zlog_warn("Deprecated option: 'no ip large-community-list <(1-99)|(100-500)|standard|expanded> <deny|permit> <LINE|AA:BB:CC>' being used");
14646 }
14647 argv_find(argv, argc, "permit", &idx);
14648 argv_find(argv, argc, "deny", &idx);
14649
14650 if (idx) {
14651 /* Check the list direct. */
14652 if (strncmp(argv[idx]->arg, "p", 1) == 0)
14653 direct = COMMUNITY_PERMIT;
14654 else
14655 direct = COMMUNITY_DENY;
14656
14657 idx = 0;
14658 argv_find(argv, argc, "LINE", &idx);
14659 argv_find(argv, argc, "AA:AA:NN", &idx);
14660 /* Concat community string argument. */
14661 str = argv_concat(argv, argc, idx);
14662 }
14663
14664 idx = 0;
14665 argv_find(argv, argc, "(1-99)", &idx);
14666 argv_find(argv, argc, "(100-500)", &idx);
14667 argv_find(argv, argc, "WORD", &idx);
14668
14669 /* Unset community list. */
14670 ret = lcommunity_list_unset(bgp_clist, argv[idx]->arg, str, direct,
14671 style);
14672
14673 /* Free temporary community list string allocated by
14674 argv_concat(). */
14675 XFREE(MTYPE_TMP, str);
14676
14677 if (ret < 0) {
14678 community_list_perror(vty, ret);
14679 return CMD_WARNING_CONFIG_FAILED;
14680 }
14681
14682 return CMD_SUCCESS;
14683 }
14684
14685 /* "large-community-list" keyword help string. */
14686 #define LCOMMUNITY_LIST_STR "Add a large community list entry\n"
14687 #define LCOMMUNITY_VAL_STR "large community in 'aa:bb:cc' format\n"
14688
14689 #if CONFDATE > 20191005
14690 CPP_NOTICE("bgpd: remove deprecated 'ip large-community-list <(1-99)|(100-500)|standard|expanded> <deny|permit> <LINE|AA:BB:CC>' command")
14691 #endif
14692 DEFUN (lcommunity_list_standard,
14693 bgp_lcommunity_list_standard_cmd,
14694 "bgp large-community-list (1-99) <deny|permit>",
14695 BGP_STR
14696 LCOMMUNITY_LIST_STR
14697 "Large Community list number (standard)\n"
14698 "Specify large community to reject\n"
14699 "Specify large community to accept\n")
14700 {
14701 return lcommunity_list_set_vty(vty, argc, argv,
14702 LARGE_COMMUNITY_LIST_STANDARD, 0);
14703 }
14704
14705 ALIAS (lcommunity_list_standard,
14706 ip_lcommunity_list_standard_cmd,
14707 "ip large-community-list (1-99) <deny|permit>",
14708 IP_STR
14709 LCOMMUNITY_LIST_STR
14710 "Large Community list number (standard)\n"
14711 "Specify large community to reject\n"
14712 "Specify large community to accept\n")
14713
14714 DEFUN (lcommunity_list_standard1,
14715 bgp_lcommunity_list_standard1_cmd,
14716 "bgp large-community-list (1-99) <deny|permit> AA:BB:CC...",
14717 BGP_STR
14718 LCOMMUNITY_LIST_STR
14719 "Large Community list number (standard)\n"
14720 "Specify large community to reject\n"
14721 "Specify large community to accept\n"
14722 LCOMMUNITY_VAL_STR)
14723 {
14724 return lcommunity_list_set_vty(vty, argc, argv,
14725 LARGE_COMMUNITY_LIST_STANDARD, 0);
14726 }
14727
14728 ALIAS (lcommunity_list_standard1,
14729 ip_lcommunity_list_standard1_cmd,
14730 "ip large-community-list (1-99) <deny|permit> AA:BB:CC...",
14731 IP_STR
14732 LCOMMUNITY_LIST_STR
14733 "Large Community list number (standard)\n"
14734 "Specify large community to reject\n"
14735 "Specify large community to accept\n"
14736 LCOMMUNITY_VAL_STR)
14737
14738 DEFUN (lcommunity_list_expanded,
14739 bgp_lcommunity_list_expanded_cmd,
14740 "bgp large-community-list (100-500) <deny|permit> LINE...",
14741 BGP_STR
14742 LCOMMUNITY_LIST_STR
14743 "Large Community list number (expanded)\n"
14744 "Specify large community to reject\n"
14745 "Specify large community to accept\n"
14746 "An ordered list as a regular-expression\n")
14747 {
14748 return lcommunity_list_set_vty(vty, argc, argv,
14749 LARGE_COMMUNITY_LIST_EXPANDED, 0);
14750 }
14751
14752 ALIAS (lcommunity_list_expanded,
14753 ip_lcommunity_list_expanded_cmd,
14754 "ip large-community-list (100-500) <deny|permit> LINE...",
14755 IP_STR
14756 LCOMMUNITY_LIST_STR
14757 "Large Community list number (expanded)\n"
14758 "Specify large community to reject\n"
14759 "Specify large community to accept\n"
14760 "An ordered list as a regular-expression\n")
14761
14762 DEFUN (lcommunity_list_name_standard,
14763 bgp_lcommunity_list_name_standard_cmd,
14764 "bgp large-community-list standard WORD <deny|permit>",
14765 BGP_STR
14766 LCOMMUNITY_LIST_STR
14767 "Specify standard large-community-list\n"
14768 "Large Community list name\n"
14769 "Specify large community to reject\n"
14770 "Specify large community to accept\n")
14771 {
14772 return lcommunity_list_set_vty(vty, argc, argv,
14773 LARGE_COMMUNITY_LIST_STANDARD, 1);
14774 }
14775
14776 ALIAS (lcommunity_list_name_standard,
14777 ip_lcommunity_list_name_standard_cmd,
14778 "ip large-community-list standard WORD <deny|permit>",
14779 IP_STR
14780 LCOMMUNITY_LIST_STR
14781 "Specify standard large-community-list\n"
14782 "Large Community list name\n"
14783 "Specify large community to reject\n"
14784 "Specify large community to accept\n")
14785
14786 DEFUN (lcommunity_list_name_standard1,
14787 bgp_lcommunity_list_name_standard1_cmd,
14788 "bgp large-community-list standard WORD <deny|permit> AA:BB:CC...",
14789 BGP_STR
14790 LCOMMUNITY_LIST_STR
14791 "Specify standard large-community-list\n"
14792 "Large Community list name\n"
14793 "Specify large community to reject\n"
14794 "Specify large community to accept\n"
14795 LCOMMUNITY_VAL_STR)
14796 {
14797 return lcommunity_list_set_vty(vty, argc, argv,
14798 LARGE_COMMUNITY_LIST_STANDARD, 1);
14799 }
14800
14801 ALIAS (lcommunity_list_name_standard1,
14802 ip_lcommunity_list_name_standard1_cmd,
14803 "ip large-community-list standard WORD <deny|permit> AA:BB:CC...",
14804 IP_STR
14805 LCOMMUNITY_LIST_STR
14806 "Specify standard large-community-list\n"
14807 "Large Community list name\n"
14808 "Specify large community to reject\n"
14809 "Specify large community to accept\n"
14810 LCOMMUNITY_VAL_STR)
14811
14812 DEFUN (lcommunity_list_name_expanded,
14813 bgp_lcommunity_list_name_expanded_cmd,
14814 "bgp large-community-list expanded WORD <deny|permit> LINE...",
14815 BGP_STR
14816 LCOMMUNITY_LIST_STR
14817 "Specify expanded large-community-list\n"
14818 "Large Community list name\n"
14819 "Specify large community to reject\n"
14820 "Specify large community to accept\n"
14821 "An ordered list as a regular-expression\n")
14822 {
14823 return lcommunity_list_set_vty(vty, argc, argv,
14824 LARGE_COMMUNITY_LIST_EXPANDED, 1);
14825 }
14826
14827 ALIAS (lcommunity_list_name_expanded,
14828 ip_lcommunity_list_name_expanded_cmd,
14829 "ip large-community-list expanded WORD <deny|permit> LINE...",
14830 IP_STR
14831 LCOMMUNITY_LIST_STR
14832 "Specify expanded large-community-list\n"
14833 "Large Community list name\n"
14834 "Specify large community to reject\n"
14835 "Specify large community to accept\n"
14836 "An ordered list as a regular-expression\n")
14837
14838 DEFUN (no_lcommunity_list_standard_all,
14839 no_bgp_lcommunity_list_standard_all_cmd,
14840 "no bgp large-community-list <(1-99)|(100-500)|WORD>",
14841 NO_STR
14842 BGP_STR
14843 LCOMMUNITY_LIST_STR
14844 "Large Community list number (standard)\n"
14845 "Large Community list number (expanded)\n"
14846 "Large Community list name\n")
14847 {
14848 return lcommunity_list_unset_vty(vty, argc, argv,
14849 LARGE_COMMUNITY_LIST_STANDARD);
14850 }
14851
14852 ALIAS (no_lcommunity_list_standard_all,
14853 no_ip_lcommunity_list_standard_all_cmd,
14854 "no ip large-community-list <(1-99)|(100-500)|WORD>",
14855 NO_STR
14856 IP_STR
14857 LCOMMUNITY_LIST_STR
14858 "Large Community list number (standard)\n"
14859 "Large Community list number (expanded)\n"
14860 "Large Community list name\n")
14861
14862 DEFUN (no_lcommunity_list_name_expanded_all,
14863 no_bgp_lcommunity_list_name_expanded_all_cmd,
14864 "no bgp large-community-list expanded WORD",
14865 NO_STR
14866 BGP_STR
14867 LCOMMUNITY_LIST_STR
14868 "Specify expanded large-community-list\n"
14869 "Large Community list name\n")
14870 {
14871 return lcommunity_list_unset_vty(vty, argc, argv,
14872 LARGE_COMMUNITY_LIST_EXPANDED);
14873 }
14874
14875 ALIAS (no_lcommunity_list_name_expanded_all,
14876 no_ip_lcommunity_list_name_expanded_all_cmd,
14877 "no ip large-community-list expanded WORD",
14878 NO_STR
14879 IP_STR
14880 LCOMMUNITY_LIST_STR
14881 "Specify expanded large-community-list\n"
14882 "Large Community list name\n")
14883
14884 DEFUN (no_lcommunity_list_standard,
14885 no_bgp_lcommunity_list_standard_cmd,
14886 "no bgp large-community-list (1-99) <deny|permit> AA:AA:NN...",
14887 NO_STR
14888 BGP_STR
14889 LCOMMUNITY_LIST_STR
14890 "Large Community list number (standard)\n"
14891 "Specify large community to reject\n"
14892 "Specify large community to accept\n"
14893 LCOMMUNITY_VAL_STR)
14894 {
14895 return lcommunity_list_unset_vty(vty, argc, argv,
14896 LARGE_COMMUNITY_LIST_STANDARD);
14897 }
14898
14899 ALIAS (no_lcommunity_list_standard,
14900 no_ip_lcommunity_list_standard_cmd,
14901 "no ip large-community-list (1-99) <deny|permit> AA:AA:NN...",
14902 NO_STR
14903 IP_STR
14904 LCOMMUNITY_LIST_STR
14905 "Large Community list number (standard)\n"
14906 "Specify large community to reject\n"
14907 "Specify large community to accept\n"
14908 LCOMMUNITY_VAL_STR)
14909
14910 DEFUN (no_lcommunity_list_expanded,
14911 no_bgp_lcommunity_list_expanded_cmd,
14912 "no bgp large-community-list (100-500) <deny|permit> LINE...",
14913 NO_STR
14914 BGP_STR
14915 LCOMMUNITY_LIST_STR
14916 "Large Community list number (expanded)\n"
14917 "Specify large community to reject\n"
14918 "Specify large community to accept\n"
14919 "An ordered list as a regular-expression\n")
14920 {
14921 return lcommunity_list_unset_vty(vty, argc, argv,
14922 LARGE_COMMUNITY_LIST_EXPANDED);
14923 }
14924
14925 ALIAS (no_lcommunity_list_expanded,
14926 no_ip_lcommunity_list_expanded_cmd,
14927 "no ip large-community-list (100-500) <deny|permit> LINE...",
14928 NO_STR
14929 IP_STR
14930 LCOMMUNITY_LIST_STR
14931 "Large Community list number (expanded)\n"
14932 "Specify large community to reject\n"
14933 "Specify large community to accept\n"
14934 "An ordered list as a regular-expression\n")
14935
14936 DEFUN (no_lcommunity_list_name_standard,
14937 no_bgp_lcommunity_list_name_standard_cmd,
14938 "no bgp large-community-list standard WORD <deny|permit> AA:AA:NN...",
14939 NO_STR
14940 BGP_STR
14941 LCOMMUNITY_LIST_STR
14942 "Specify standard large-community-list\n"
14943 "Large Community list name\n"
14944 "Specify large community to reject\n"
14945 "Specify large community to accept\n"
14946 LCOMMUNITY_VAL_STR)
14947 {
14948 return lcommunity_list_unset_vty(vty, argc, argv,
14949 LARGE_COMMUNITY_LIST_STANDARD);
14950 }
14951
14952 ALIAS (no_lcommunity_list_name_standard,
14953 no_ip_lcommunity_list_name_standard_cmd,
14954 "no ip large-community-list standard WORD <deny|permit> AA:AA:NN...",
14955 NO_STR
14956 IP_STR
14957 LCOMMUNITY_LIST_STR
14958 "Specify standard large-community-list\n"
14959 "Large Community list name\n"
14960 "Specify large community to reject\n"
14961 "Specify large community to accept\n"
14962 LCOMMUNITY_VAL_STR)
14963
14964 DEFUN (no_lcommunity_list_name_expanded,
14965 no_bgp_lcommunity_list_name_expanded_cmd,
14966 "no bgp large-community-list expanded WORD <deny|permit> LINE...",
14967 NO_STR
14968 BGP_STR
14969 LCOMMUNITY_LIST_STR
14970 "Specify expanded large-community-list\n"
14971 "Large community list name\n"
14972 "Specify large community to reject\n"
14973 "Specify large community to accept\n"
14974 "An ordered list as a regular-expression\n")
14975 {
14976 return lcommunity_list_unset_vty(vty, argc, argv,
14977 LARGE_COMMUNITY_LIST_EXPANDED);
14978 }
14979
14980 ALIAS (no_lcommunity_list_name_expanded,
14981 no_ip_lcommunity_list_name_expanded_cmd,
14982 "no ip large-community-list expanded WORD <deny|permit> LINE...",
14983 NO_STR
14984 IP_STR
14985 LCOMMUNITY_LIST_STR
14986 "Specify expanded large-community-list\n"
14987 "Large community list name\n"
14988 "Specify large community to reject\n"
14989 "Specify large community to accept\n"
14990 "An ordered list as a regular-expression\n")
14991
14992 static void lcommunity_list_show(struct vty *vty, struct community_list *list)
14993 {
14994 struct community_entry *entry;
14995
14996 for (entry = list->head; entry; entry = entry->next) {
14997 if (entry == list->head) {
14998 if (all_digit(list->name))
14999 vty_out(vty, "Large community %s list %s\n",
15000 entry->style ==
15001 LARGE_COMMUNITY_LIST_STANDARD
15002 ? "standard"
15003 : "(expanded) access",
15004 list->name);
15005 else
15006 vty_out(vty,
15007 "Named large community %s list %s\n",
15008 entry->style ==
15009 LARGE_COMMUNITY_LIST_STANDARD
15010 ? "standard"
15011 : "expanded",
15012 list->name);
15013 }
15014 if (entry->any)
15015 vty_out(vty, " %s\n",
15016 community_direct_str(entry->direct));
15017 else
15018 vty_out(vty, " %s %s\n",
15019 community_direct_str(entry->direct),
15020 community_list_config_str(entry));
15021 }
15022 }
15023
15024 DEFUN (show_lcommunity_list,
15025 show_bgp_lcommunity_list_cmd,
15026 "show bgp large-community-list",
15027 SHOW_STR
15028 BGP_STR
15029 "List large-community list\n")
15030 {
15031 struct community_list *list;
15032 struct community_list_master *cm;
15033 int idx = 0;
15034
15035 if (argv_find(argv, argc, "ip", &idx)) {
15036 vty_out(vty, "This config option is deprecated, and is scheduled for removal.\n");
15037 vty_out(vty, "if you are using this please migrate to the below command.\n");
15038 vty_out(vty, "'show bgp large-community-list <(1-500)|WORD>'\n");
15039 zlog_warn("Deprecated option: 'ip show large-community-list <(1-500)|WORD>' being used");
15040 }
15041
15042 cm = community_list_master_lookup(bgp_clist,
15043 LARGE_COMMUNITY_LIST_MASTER);
15044 if (!cm)
15045 return CMD_SUCCESS;
15046
15047 for (list = cm->num.head; list; list = list->next)
15048 lcommunity_list_show(vty, list);
15049
15050 for (list = cm->str.head; list; list = list->next)
15051 lcommunity_list_show(vty, list);
15052
15053 return CMD_SUCCESS;
15054 }
15055
15056 ALIAS (show_lcommunity_list,
15057 show_ip_lcommunity_list_cmd,
15058 "show ip large-community-list",
15059 SHOW_STR
15060 IP_STR
15061 "List large-community list\n")
15062
15063 DEFUN (show_lcommunity_list_arg,
15064 show_bgp_lcommunity_list_arg_cmd,
15065 "show bgp large-community-list <(1-500)|WORD>",
15066 SHOW_STR
15067 BGP_STR
15068 "List large-community list\n"
15069 "large-community-list number\n"
15070 "large-community-list name\n")
15071 {
15072 struct community_list *list;
15073 int idx = 0;
15074
15075 if (argv_find(argv, argc, "ip", &idx)) {
15076 vty_out(vty, "This config option is deprecated, and is scheduled for removal.\n");
15077 vty_out(vty, "if you are using this please migrate to the below command.\n");
15078 vty_out(vty, "'show bgp large-community-list <(1-500)|WORD>'\n");
15079 zlog_warn("Deprecated option: 'ip show large-community-list <(1-500)|WORD>' being used");
15080 }
15081
15082 list = community_list_lookup(bgp_clist, argv[3]->arg, 0,
15083 LARGE_COMMUNITY_LIST_MASTER);
15084 if (!list) {
15085 vty_out(vty, "%% Can't find extcommunity-list\n");
15086 return CMD_WARNING;
15087 }
15088
15089 lcommunity_list_show(vty, list);
15090
15091 return CMD_SUCCESS;
15092 }
15093
15094 ALIAS (show_lcommunity_list_arg,
15095 show_ip_lcommunity_list_arg_cmd,
15096 "show ip large-community-list <(1-500)|WORD>",
15097 SHOW_STR
15098 IP_STR
15099 "List large-community list\n"
15100 "large-community-list number\n"
15101 "large-community-list name\n")
15102
15103 /* "extcommunity-list" keyword help string. */
15104 #define EXTCOMMUNITY_LIST_STR "Add a extended community list entry\n"
15105 #define EXTCOMMUNITY_VAL_STR "Extended community attribute in 'rt aa:nn_or_IPaddr:nn' OR 'soo aa:nn_or_IPaddr:nn' format\n"
15106
15107 DEFUN (extcommunity_list_standard,
15108 bgp_extcommunity_list_standard_cmd,
15109 "bgp extcommunity-list <(1-99)|standard WORD> <deny|permit> AA:NN...",
15110 BGP_STR
15111 EXTCOMMUNITY_LIST_STR
15112 "Extended Community list number (standard)\n"
15113 "Specify standard extcommunity-list\n"
15114 "Community list name\n"
15115 "Specify community to reject\n"
15116 "Specify community to accept\n"
15117 EXTCOMMUNITY_VAL_STR)
15118 {
15119 int style = EXTCOMMUNITY_LIST_STANDARD;
15120 int direct = 0;
15121 char *cl_number_or_name = NULL;
15122
15123 int idx = 0;
15124 if (argv_find(argv, argc, "ip", &idx)) {
15125 vty_out(vty, "This config option is deprecated, and is scheduled for removal.\n");
15126 vty_out(vty, "if you are using this please migrate to the below command.\n");
15127 vty_out(vty, "'bgp extcommunity-list <(1-99)|(100-500)|standard|expanded> <deny|permit> <LINE|AA:NN>'\n");
15128 zlog_warn("Deprecated option: 'ip extcommunity-list <(1-99)|(100-500)|standard|expanded> <deny|permit> <LINE|AA:NN>' being used");
15129 }
15130 argv_find(argv, argc, "(1-99)", &idx);
15131 argv_find(argv, argc, "WORD", &idx);
15132 cl_number_or_name = argv[idx]->arg;
15133 direct = argv_find(argv, argc, "permit", &idx) ? COMMUNITY_PERMIT
15134 : COMMUNITY_DENY;
15135 argv_find(argv, argc, "AA:NN", &idx);
15136 char *str = argv_concat(argv, argc, idx);
15137
15138 int ret = extcommunity_list_set(bgp_clist, cl_number_or_name, str,
15139 direct, style);
15140
15141 XFREE(MTYPE_TMP, str);
15142
15143 if (ret < 0) {
15144 community_list_perror(vty, ret);
15145 return CMD_WARNING_CONFIG_FAILED;
15146 }
15147
15148 return CMD_SUCCESS;
15149 }
15150
15151 #if CONFDATE > 20191005
15152 CPP_NOTICE("bgpd: remove deprecated 'ip extcommunity-list <(1-99)|(100-500)|standard|expanded> <deny|permit> <LINE|AA:NN>' command")
15153 #endif
15154 ALIAS (extcommunity_list_standard,
15155 ip_extcommunity_list_standard_cmd,
15156 "ip extcommunity-list <(1-99)|standard WORD> <deny|permit> AA:NN...",
15157 IP_STR
15158 EXTCOMMUNITY_LIST_STR
15159 "Extended Community list number (standard)\n"
15160 "Specify standard extcommunity-list\n"
15161 "Community list name\n"
15162 "Specify community to reject\n"
15163 "Specify community to accept\n"
15164 EXTCOMMUNITY_VAL_STR)
15165
15166 DEFUN (extcommunity_list_name_expanded,
15167 bgp_extcommunity_list_name_expanded_cmd,
15168 "bgp extcommunity-list <(100-500)|expanded WORD> <deny|permit> LINE...",
15169 BGP_STR
15170 EXTCOMMUNITY_LIST_STR
15171 "Extended Community list number (expanded)\n"
15172 "Specify expanded extcommunity-list\n"
15173 "Extended Community list name\n"
15174 "Specify community to reject\n"
15175 "Specify community to accept\n"
15176 "An ordered list as a regular-expression\n")
15177 {
15178 int style = EXTCOMMUNITY_LIST_EXPANDED;
15179 int direct = 0;
15180 char *cl_number_or_name = NULL;
15181
15182 int idx = 0;
15183 if (argv_find(argv, argc, "ip", &idx)) {
15184 vty_out(vty, "This config option is deprecated, and is scheduled for removal.\n");
15185 vty_out(vty, "if you are using this please migrate to the below command.\n");
15186 vty_out(vty, "'extcommunity-list <(1-99)|(100-500)|standard|expanded> <deny|permit> <LINE|AA:NN>'\n");
15187 zlog_warn("Deprecated option: ‘ip extcommunity-list <(1-99)|(100-500)|standard|expanded> <deny|permit> <LINE|AA:NN>' being used");
15188 }
15189
15190 argv_find(argv, argc, "(100-500)", &idx);
15191 argv_find(argv, argc, "WORD", &idx);
15192 cl_number_or_name = argv[idx]->arg;
15193 direct = argv_find(argv, argc, "permit", &idx) ? COMMUNITY_PERMIT
15194 : COMMUNITY_DENY;
15195 argv_find(argv, argc, "LINE", &idx);
15196 char *str = argv_concat(argv, argc, idx);
15197
15198 int ret = extcommunity_list_set(bgp_clist, cl_number_or_name, str,
15199 direct, style);
15200
15201 XFREE(MTYPE_TMP, str);
15202
15203 if (ret < 0) {
15204 community_list_perror(vty, ret);
15205 return CMD_WARNING_CONFIG_FAILED;
15206 }
15207
15208 return CMD_SUCCESS;
15209 }
15210
15211 ALIAS (extcommunity_list_name_expanded,
15212 ip_extcommunity_list_name_expanded_cmd,
15213 "ip extcommunity-list <(100-500)|expanded WORD> <deny|permit> LINE...",
15214 IP_STR
15215 EXTCOMMUNITY_LIST_STR
15216 "Extended Community list number (expanded)\n"
15217 "Specify expanded extcommunity-list\n"
15218 "Extended Community list name\n"
15219 "Specify community to reject\n"
15220 "Specify community to accept\n"
15221 "An ordered list as a regular-expression\n")
15222
15223 DEFUN (no_extcommunity_list_standard_all,
15224 no_bgp_extcommunity_list_standard_all_cmd,
15225 "no bgp extcommunity-list <(1-99)|standard WORD> <deny|permit> AA:NN...",
15226 NO_STR
15227 BGP_STR
15228 EXTCOMMUNITY_LIST_STR
15229 "Extended Community list number (standard)\n"
15230 "Specify standard extcommunity-list\n"
15231 "Community list name\n"
15232 "Specify community to reject\n"
15233 "Specify community to accept\n"
15234 EXTCOMMUNITY_VAL_STR)
15235 {
15236 int style = EXTCOMMUNITY_LIST_STANDARD;
15237 int direct = 0;
15238 char *cl_number_or_name = NULL;
15239 char *str = NULL;
15240
15241 int idx = 0;
15242 if (argv_find(argv, argc, "ip", &idx)) {
15243 vty_out(vty, "This config option is deprecated, and is scheduled for removal\n");
15244 vty_out(vty, "if you are using this please migrate to the below command.\n");
15245 vty_out(vty, "'no bgp extcommunity-list <(1-99)|(100-500)|standard|expanded> <deny|permit> <LINE|AA:NN>'\n");
15246 zlog_warn("Deprecated option: ‘no ip extcommunity-list <(1-99)|(100-500)|standard|expanded> <deny|permit> <LINE|AA:NN>' being used");
15247 }
15248
15249 idx = 0;
15250 argv_find(argv, argc, "permit", &idx);
15251 argv_find(argv, argc, "deny", &idx);
15252
15253 if (idx) {
15254 direct = argv_find(argv, argc, "permit", &idx)
15255 ? COMMUNITY_PERMIT
15256 : COMMUNITY_DENY;
15257
15258 idx = 0;
15259 argv_find(argv, argc, "AA:NN", &idx);
15260 str = argv_concat(argv, argc, idx);
15261 }
15262
15263 idx = 0;
15264 argv_find(argv, argc, "(1-99)", &idx);
15265 argv_find(argv, argc, "WORD", &idx);
15266 cl_number_or_name = argv[idx]->arg;
15267
15268 int ret = extcommunity_list_unset(bgp_clist, cl_number_or_name, str,
15269 direct, style);
15270
15271 XFREE(MTYPE_TMP, str);
15272
15273 if (ret < 0) {
15274 community_list_perror(vty, ret);
15275 return CMD_WARNING_CONFIG_FAILED;
15276 }
15277
15278 return CMD_SUCCESS;
15279 }
15280
15281 ALIAS (no_extcommunity_list_standard_all,
15282 no_ip_extcommunity_list_standard_all_cmd,
15283 "no ip extcommunity-list <(1-99)|standard WORD> <deny|permit> AA:NN...",
15284 NO_STR
15285 IP_STR
15286 EXTCOMMUNITY_LIST_STR
15287 "Extended Community list number (standard)\n"
15288 "Specify standard extcommunity-list\n"
15289 "Community list name\n"
15290 "Specify community to reject\n"
15291 "Specify community to accept\n"
15292 EXTCOMMUNITY_VAL_STR)
15293
15294 ALIAS(no_extcommunity_list_standard_all,
15295 no_bgp_extcommunity_list_standard_all_list_cmd,
15296 "no bgp extcommunity-list <(1-99)|standard WORD>",
15297 NO_STR IP_STR EXTCOMMUNITY_LIST_STR
15298 "Extended Community list number (standard)\n"
15299 "Specify standard extcommunity-list\n"
15300 "Community list name\n")
15301
15302 ALIAS(no_extcommunity_list_standard_all,
15303 no_ip_extcommunity_list_standard_all_list_cmd,
15304 "no ip extcommunity-list <(1-99)|standard WORD>",
15305 NO_STR IP_STR EXTCOMMUNITY_LIST_STR
15306 "Extended Community list number (standard)\n"
15307 "Specify standard extcommunity-list\n"
15308 "Community list name\n")
15309
15310 DEFUN (no_extcommunity_list_expanded_all,
15311 no_bgp_extcommunity_list_expanded_all_cmd,
15312 "no bgp extcommunity-list <(100-500)|expanded WORD> <deny|permit> LINE...",
15313 NO_STR
15314 BGP_STR
15315 EXTCOMMUNITY_LIST_STR
15316 "Extended Community list number (expanded)\n"
15317 "Specify expanded extcommunity-list\n"
15318 "Extended Community list name\n"
15319 "Specify community to reject\n"
15320 "Specify community to accept\n"
15321 "An ordered list as a regular-expression\n")
15322 {
15323 int style = EXTCOMMUNITY_LIST_EXPANDED;
15324 int direct = 0;
15325 char *cl_number_or_name = NULL;
15326 char *str = NULL;
15327
15328 int idx = 0;
15329 if (argv_find(argv, argc, "ip", &idx)) {
15330 vty_out(vty, "This config option is deprecated, and is scheduled for removal.\n");
15331 vty_out(vty, "if you are using this please migrate to the below command.\n");
15332 vty_out(vty, "'no bgp extcommunity-list <(1-99)|(100-500)|standard|expanded> <deny|permit> <LINE|AA:NN>'\n");
15333 zlog_warn("Deprecated option: ‘no ip extcommunity-list <(1-99)|(100-500)|standard|expanded> <deny|permit> <LINE|AA:NN>' being used");
15334 }
15335
15336 idx = 0;
15337 argv_find(argv, argc, "permit", &idx);
15338 argv_find(argv, argc, "deny", &idx);
15339
15340 if (idx) {
15341 direct = argv_find(argv, argc, "permit", &idx)
15342 ? COMMUNITY_PERMIT
15343 : COMMUNITY_DENY;
15344
15345 idx = 0;
15346 argv_find(argv, argc, "LINE", &idx);
15347 str = argv_concat(argv, argc, idx);
15348 }
15349
15350 idx = 0;
15351 argv_find(argv, argc, "(100-500)", &idx);
15352 argv_find(argv, argc, "WORD", &idx);
15353 cl_number_or_name = argv[idx]->arg;
15354
15355 int ret = extcommunity_list_unset(bgp_clist, cl_number_or_name, str,
15356 direct, style);
15357
15358 XFREE(MTYPE_TMP, str);
15359
15360 if (ret < 0) {
15361 community_list_perror(vty, ret);
15362 return CMD_WARNING_CONFIG_FAILED;
15363 }
15364
15365 return CMD_SUCCESS;
15366 }
15367
15368 ALIAS (no_extcommunity_list_expanded_all,
15369 no_ip_extcommunity_list_expanded_all_cmd,
15370 "no ip extcommunity-list <(100-500)|expanded WORD> <deny|permit> LINE...",
15371 NO_STR
15372 IP_STR
15373 EXTCOMMUNITY_LIST_STR
15374 "Extended Community list number (expanded)\n"
15375 "Specify expanded extcommunity-list\n"
15376 "Extended Community list name\n"
15377 "Specify community to reject\n"
15378 "Specify community to accept\n"
15379 "An ordered list as a regular-expression\n")
15380
15381 ALIAS(no_extcommunity_list_expanded_all,
15382 no_ip_extcommunity_list_expanded_all_list_cmd,
15383 "no ip extcommunity-list <(100-500)|expanded WORD>",
15384 NO_STR IP_STR EXTCOMMUNITY_LIST_STR
15385 "Extended Community list number (expanded)\n"
15386 "Specify expanded extcommunity-list\n"
15387 "Extended Community list name\n")
15388
15389 ALIAS(no_extcommunity_list_expanded_all,
15390 no_bgp_extcommunity_list_expanded_all_list_cmd,
15391 "no bgp extcommunity-list <(100-500)|expanded WORD>",
15392 NO_STR IP_STR EXTCOMMUNITY_LIST_STR
15393 "Extended Community list number (expanded)\n"
15394 "Specify expanded extcommunity-list\n"
15395 "Extended Community list name\n")
15396
15397 static void extcommunity_list_show(struct vty *vty, struct community_list *list)
15398 {
15399 struct community_entry *entry;
15400
15401 for (entry = list->head; entry; entry = entry->next) {
15402 if (entry == list->head) {
15403 if (all_digit(list->name))
15404 vty_out(vty, "Extended community %s list %s\n",
15405 entry->style == EXTCOMMUNITY_LIST_STANDARD
15406 ? "standard"
15407 : "(expanded) access",
15408 list->name);
15409 else
15410 vty_out(vty,
15411 "Named extended community %s list %s\n",
15412 entry->style == EXTCOMMUNITY_LIST_STANDARD
15413 ? "standard"
15414 : "expanded",
15415 list->name);
15416 }
15417 if (entry->any)
15418 vty_out(vty, " %s\n",
15419 community_direct_str(entry->direct));
15420 else
15421 vty_out(vty, " %s %s\n",
15422 community_direct_str(entry->direct),
15423 community_list_config_str(entry));
15424 }
15425 }
15426
15427 DEFUN (show_extcommunity_list,
15428 show_bgp_extcommunity_list_cmd,
15429 "show bgp extcommunity-list",
15430 SHOW_STR
15431 BGP_STR
15432 "List extended-community list\n")
15433 {
15434 struct community_list *list;
15435 struct community_list_master *cm;
15436 int idx = 0;
15437
15438 if (argv_find(argv, argc, "ip", &idx)) {
15439 vty_out(vty, "This config option is deprecated, and is scheduled for removal\n");
15440 vty_out(vty, "if you are using this please migrate to the below command.\n");
15441 vty_out(vty, "'show bgp extcommunity-list <(1-500)|WORD>'\n");
15442 zlog_warn("Deprecated option: 'ip show extcommunity-list <(1-500)|WORD>' being used");
15443 }
15444 cm = community_list_master_lookup(bgp_clist, EXTCOMMUNITY_LIST_MASTER);
15445 if (!cm)
15446 return CMD_SUCCESS;
15447
15448 for (list = cm->num.head; list; list = list->next)
15449 extcommunity_list_show(vty, list);
15450
15451 for (list = cm->str.head; list; list = list->next)
15452 extcommunity_list_show(vty, list);
15453
15454 return CMD_SUCCESS;
15455 }
15456
15457 ALIAS (show_extcommunity_list,
15458 show_ip_extcommunity_list_cmd,
15459 "show ip extcommunity-list",
15460 SHOW_STR
15461 IP_STR
15462 "List extended-community list\n")
15463
15464 DEFUN (show_extcommunity_list_arg,
15465 show_bgp_extcommunity_list_arg_cmd,
15466 "show bgp extcommunity-list <(1-500)|WORD>",
15467 SHOW_STR
15468 BGP_STR
15469 "List extended-community list\n"
15470 "Extcommunity-list number\n"
15471 "Extcommunity-list name\n")
15472 {
15473 int idx_comm_list = 3;
15474 struct community_list *list;
15475 int idx = 0;
15476
15477 if (argv_find(argv, argc, "ip", &idx)) {
15478 vty_out(vty, "This config option is deprecated, and is scheduled for removal.\n");
15479 vty_out(vty, "if you are using this please migrate to the below command.\n");
15480 vty_out(vty, "'show bgp extcommunity-list <(1-500)|WORD>'\n");
15481 zlog_warn("Deprecated option: 'ip show extcommunity-list <(1-500)|WORD>' being used");
15482 }
15483 list = community_list_lookup(bgp_clist, argv[idx_comm_list]->arg, 0,
15484 EXTCOMMUNITY_LIST_MASTER);
15485 if (!list) {
15486 vty_out(vty, "%% Can't find extcommunity-list\n");
15487 return CMD_WARNING;
15488 }
15489
15490 extcommunity_list_show(vty, list);
15491
15492 return CMD_SUCCESS;
15493 }
15494
15495 ALIAS (show_extcommunity_list_arg,
15496 show_ip_extcommunity_list_arg_cmd,
15497 "show ip extcommunity-list <(1-500)|WORD>",
15498 SHOW_STR
15499 IP_STR
15500 "List extended-community list\n"
15501 "Extcommunity-list number\n"
15502 "Extcommunity-list name\n")
15503
15504 /* Display community-list and extcommunity-list configuration. */
15505 static int community_list_config_write(struct vty *vty)
15506 {
15507 struct community_list *list;
15508 struct community_entry *entry;
15509 struct community_list_master *cm;
15510 int write = 0;
15511
15512 /* Community-list. */
15513 cm = community_list_master_lookup(bgp_clist, COMMUNITY_LIST_MASTER);
15514
15515 for (list = cm->num.head; list; list = list->next)
15516 for (entry = list->head; entry; entry = entry->next) {
15517 vty_out(vty, "bgp community-list %s %s %s\n", list->name,
15518 community_direct_str(entry->direct),
15519 community_list_config_str(entry));
15520 write++;
15521 }
15522 for (list = cm->str.head; list; list = list->next)
15523 for (entry = list->head; entry; entry = entry->next) {
15524 vty_out(vty, "bgp community-list %s %s %s %s\n",
15525 entry->style == COMMUNITY_LIST_STANDARD
15526 ? "standard"
15527 : "expanded",
15528 list->name, community_direct_str(entry->direct),
15529 community_list_config_str(entry));
15530 write++;
15531 }
15532
15533 /* Extcommunity-list. */
15534 cm = community_list_master_lookup(bgp_clist, EXTCOMMUNITY_LIST_MASTER);
15535
15536 for (list = cm->num.head; list; list = list->next)
15537 for (entry = list->head; entry; entry = entry->next) {
15538 vty_out(vty, "bgp extcommunity-list %s %s %s\n",
15539 list->name, community_direct_str(entry->direct),
15540 community_list_config_str(entry));
15541 write++;
15542 }
15543 for (list = cm->str.head; list; list = list->next)
15544 for (entry = list->head; entry; entry = entry->next) {
15545 vty_out(vty, "bgp extcommunity-list %s %s %s %s\n",
15546 entry->style == EXTCOMMUNITY_LIST_STANDARD
15547 ? "standard"
15548 : "expanded",
15549 list->name, community_direct_str(entry->direct),
15550 community_list_config_str(entry));
15551 write++;
15552 }
15553
15554
15555 /* lcommunity-list. */
15556 cm = community_list_master_lookup(bgp_clist,
15557 LARGE_COMMUNITY_LIST_MASTER);
15558
15559 for (list = cm->num.head; list; list = list->next)
15560 for (entry = list->head; entry; entry = entry->next) {
15561 vty_out(vty, "bgp large-community-list %s %s %s\n",
15562 list->name, community_direct_str(entry->direct),
15563 community_list_config_str(entry));
15564 write++;
15565 }
15566 for (list = cm->str.head; list; list = list->next)
15567 for (entry = list->head; entry; entry = entry->next) {
15568 vty_out(vty, "bgp large-community-list %s %s %s %s\n",
15569 entry->style == LARGE_COMMUNITY_LIST_STANDARD
15570 ? "standard"
15571 : "expanded",
15572 list->name, community_direct_str(entry->direct),
15573 community_list_config_str(entry));
15574 write++;
15575 }
15576
15577 return write;
15578 }
15579
15580 static struct cmd_node community_list_node = {
15581 COMMUNITY_LIST_NODE, "", 1 /* Export to vtysh. */
15582 };
15583
15584 static void community_list_vty(void)
15585 {
15586 install_node(&community_list_node, community_list_config_write);
15587
15588 /* Community-list. */
15589 install_element(CONFIG_NODE, &bgp_community_list_standard_cmd);
15590 install_element(CONFIG_NODE, &bgp_community_list_expanded_all_cmd);
15591 install_element(CONFIG_NODE, &no_bgp_community_list_standard_all_cmd);
15592 install_element(CONFIG_NODE, &no_bgp_community_list_standard_all_list_cmd);
15593 install_element(CONFIG_NODE, &no_bgp_community_list_expanded_all_cmd);
15594 install_element(CONFIG_NODE, &no_bgp_community_list_expanded_all_list_cmd);
15595 install_element(VIEW_NODE, &show_bgp_community_list_cmd);
15596 install_element(VIEW_NODE, &show_bgp_community_list_arg_cmd);
15597 install_element(CONFIG_NODE, &ip_community_list_standard_cmd);
15598 install_element(CONFIG_NODE, &ip_community_list_expanded_all_cmd);
15599 install_element(CONFIG_NODE, &no_ip_community_list_standard_all_cmd);
15600 install_element(CONFIG_NODE, &no_ip_community_list_standard_all_list_cmd);
15601 install_element(CONFIG_NODE, &no_ip_community_list_expanded_all_cmd);
15602 install_element(CONFIG_NODE, &no_ip_community_list_expanded_all_list_cmd);
15603 install_element(VIEW_NODE, &show_ip_community_list_cmd);
15604 install_element(VIEW_NODE, &show_ip_community_list_arg_cmd);
15605
15606 /* Extcommunity-list. */
15607 install_element(CONFIG_NODE, &bgp_extcommunity_list_standard_cmd);
15608 install_element(CONFIG_NODE, &bgp_extcommunity_list_name_expanded_cmd);
15609 install_element(CONFIG_NODE, &no_bgp_extcommunity_list_standard_all_cmd);
15610 install_element(CONFIG_NODE,
15611 &no_bgp_extcommunity_list_standard_all_list_cmd);
15612 install_element(CONFIG_NODE, &no_bgp_extcommunity_list_expanded_all_cmd);
15613 install_element(CONFIG_NODE,
15614 &no_bgp_extcommunity_list_expanded_all_list_cmd);
15615 install_element(VIEW_NODE, &show_bgp_extcommunity_list_cmd);
15616 install_element(VIEW_NODE, &show_bgp_extcommunity_list_arg_cmd);
15617 install_element(CONFIG_NODE, &ip_extcommunity_list_standard_cmd);
15618 install_element(CONFIG_NODE, &ip_extcommunity_list_name_expanded_cmd);
15619 install_element(CONFIG_NODE, &no_ip_extcommunity_list_standard_all_cmd);
15620 install_element(CONFIG_NODE, &no_ip_extcommunity_list_standard_all_list_cmd);
15621 install_element(CONFIG_NODE, &no_ip_extcommunity_list_expanded_all_cmd);
15622 install_element(CONFIG_NODE, &no_ip_extcommunity_list_expanded_all_list_cmd);
15623 install_element(VIEW_NODE, &show_ip_extcommunity_list_cmd);
15624 install_element(VIEW_NODE, &show_ip_extcommunity_list_arg_cmd);
15625
15626 /* Large Community List */
15627 install_element(CONFIG_NODE, &bgp_lcommunity_list_standard_cmd);
15628 install_element(CONFIG_NODE, &bgp_lcommunity_list_standard1_cmd);
15629 install_element(CONFIG_NODE, &bgp_lcommunity_list_expanded_cmd);
15630 install_element(CONFIG_NODE, &bgp_lcommunity_list_name_standard_cmd);
15631 install_element(CONFIG_NODE, &bgp_lcommunity_list_name_standard1_cmd);
15632 install_element(CONFIG_NODE, &bgp_lcommunity_list_name_expanded_cmd);
15633 install_element(CONFIG_NODE, &no_bgp_lcommunity_list_standard_all_cmd);
15634 install_element(CONFIG_NODE,
15635 &no_bgp_lcommunity_list_name_expanded_all_cmd);
15636 install_element(CONFIG_NODE, &no_bgp_lcommunity_list_standard_cmd);
15637 install_element(CONFIG_NODE, &no_bgp_lcommunity_list_expanded_cmd);
15638 install_element(CONFIG_NODE, &no_bgp_lcommunity_list_name_standard_cmd);
15639 install_element(CONFIG_NODE, &no_bgp_lcommunity_list_name_expanded_cmd);
15640 install_element(VIEW_NODE, &show_bgp_lcommunity_list_cmd);
15641 install_element(VIEW_NODE, &show_bgp_lcommunity_list_arg_cmd);
15642 install_element(CONFIG_NODE, &ip_lcommunity_list_standard_cmd);
15643 install_element(CONFIG_NODE, &ip_lcommunity_list_standard1_cmd);
15644 install_element(CONFIG_NODE, &ip_lcommunity_list_expanded_cmd);
15645 install_element(CONFIG_NODE, &ip_lcommunity_list_name_standard_cmd);
15646 install_element(CONFIG_NODE, &ip_lcommunity_list_name_standard1_cmd);
15647 install_element(CONFIG_NODE, &ip_lcommunity_list_name_expanded_cmd);
15648 install_element(CONFIG_NODE, &no_ip_lcommunity_list_standard_all_cmd);
15649 install_element(CONFIG_NODE,
15650 &no_ip_lcommunity_list_name_expanded_all_cmd);
15651 install_element(CONFIG_NODE, &no_ip_lcommunity_list_standard_cmd);
15652 install_element(CONFIG_NODE, &no_ip_lcommunity_list_expanded_cmd);
15653 install_element(CONFIG_NODE, &no_ip_lcommunity_list_name_standard_cmd);
15654 install_element(CONFIG_NODE, &no_ip_lcommunity_list_name_expanded_cmd);
15655 install_element(VIEW_NODE, &show_ip_lcommunity_list_cmd);
15656 install_element(VIEW_NODE, &show_ip_lcommunity_list_arg_cmd);
15657 }