]> git.proxmox.com Git - mirror_frr.git/blob - bgpd/bgp_vty.c
bgpd: Add evpn prefix to debug bgp updates prefix
[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 "prefix.h"
26 #include "plist.h"
27 #include "buffer.h"
28 #include "linklist.h"
29 #include "stream.h"
30 #include "thread.h"
31 #include "log.h"
32 #include "memory.h"
33 #include "memory_vty.h"
34 #include "hash.h"
35 #include "queue.h"
36 #include "filter.h"
37 #include "frrstr.h"
38
39 #include "bgpd/bgpd.h"
40 #include "bgpd/bgp_advertise.h"
41 #include "bgpd/bgp_attr.h"
42 #include "bgpd/bgp_aspath.h"
43 #include "bgpd/bgp_community.h"
44 #include "bgpd/bgp_ecommunity.h"
45 #include "bgpd/bgp_lcommunity.h"
46 #include "bgpd/bgp_damp.h"
47 #include "bgpd/bgp_debug.h"
48 #include "bgpd/bgp_fsm.h"
49 #include "bgpd/bgp_nexthop.h"
50 #include "bgpd/bgp_open.h"
51 #include "bgpd/bgp_regex.h"
52 #include "bgpd/bgp_route.h"
53 #include "bgpd/bgp_mplsvpn.h"
54 #include "bgpd/bgp_zebra.h"
55 #include "bgpd/bgp_table.h"
56 #include "bgpd/bgp_vty.h"
57 #include "bgpd/bgp_mpath.h"
58 #include "bgpd/bgp_packet.h"
59 #include "bgpd/bgp_updgrp.h"
60 #include "bgpd/bgp_bfd.h"
61 #include "bgpd/bgp_io.h"
62 #include "bgpd/bgp_evpn.h"
63
64 static struct peer_group *listen_range_exists(struct bgp *bgp,
65 struct prefix *range, int exact);
66
67 static enum node_type bgp_node_type(afi_t afi, safi_t safi)
68 {
69 switch (afi) {
70 case AFI_IP:
71 switch (safi) {
72 case SAFI_UNICAST:
73 return BGP_IPV4_NODE;
74 break;
75 case SAFI_MULTICAST:
76 return BGP_IPV4M_NODE;
77 break;
78 case SAFI_LABELED_UNICAST:
79 return BGP_IPV4L_NODE;
80 break;
81 case SAFI_MPLS_VPN:
82 return BGP_VPNV4_NODE;
83 break;
84 case SAFI_FLOWSPEC:
85 return BGP_FLOWSPECV4_NODE;
86 default:
87 /* not expected */
88 return BGP_IPV4_NODE;
89 break;
90 }
91 break;
92 case AFI_IP6:
93 switch (safi) {
94 case SAFI_UNICAST:
95 return BGP_IPV6_NODE;
96 break;
97 case SAFI_MULTICAST:
98 return BGP_IPV6M_NODE;
99 break;
100 case SAFI_LABELED_UNICAST:
101 return BGP_IPV6L_NODE;
102 break;
103 case SAFI_MPLS_VPN:
104 return BGP_VPNV6_NODE;
105 break;
106 case SAFI_FLOWSPEC:
107 return BGP_FLOWSPECV6_NODE;
108 default:
109 /* not expected */
110 return BGP_IPV4_NODE;
111 break;
112 }
113 break;
114 case AFI_L2VPN:
115 return BGP_EVPN_NODE;
116 break;
117 case AFI_MAX:
118 // We should never be here but to clarify the switch statement..
119 return BGP_IPV4_NODE;
120 break;
121 }
122
123 // Impossible to happen
124 return BGP_IPV4_NODE;
125 }
126
127 /* Utility function to get address family from current node. */
128 afi_t bgp_node_afi(struct vty *vty)
129 {
130 afi_t afi;
131 switch (vty->node) {
132 case BGP_IPV6_NODE:
133 case BGP_IPV6M_NODE:
134 case BGP_IPV6L_NODE:
135 case BGP_VPNV6_NODE:
136 case BGP_FLOWSPECV6_NODE:
137 afi = AFI_IP6;
138 break;
139 case BGP_EVPN_NODE:
140 afi = AFI_L2VPN;
141 break;
142 default:
143 afi = AFI_IP;
144 break;
145 }
146 return afi;
147 }
148
149 /* Utility function to get subsequent address family from current
150 node. */
151 safi_t bgp_node_safi(struct vty *vty)
152 {
153 safi_t safi;
154 switch (vty->node) {
155 case BGP_VPNV4_NODE:
156 case BGP_VPNV6_NODE:
157 safi = SAFI_MPLS_VPN;
158 break;
159 case BGP_IPV4M_NODE:
160 case BGP_IPV6M_NODE:
161 safi = SAFI_MULTICAST;
162 break;
163 case BGP_EVPN_NODE:
164 safi = SAFI_EVPN;
165 break;
166 case BGP_IPV4L_NODE:
167 case BGP_IPV6L_NODE:
168 safi = SAFI_LABELED_UNICAST;
169 break;
170 case BGP_FLOWSPECV4_NODE:
171 case BGP_FLOWSPECV6_NODE:
172 safi = SAFI_FLOWSPEC;
173 break;
174 default:
175 safi = SAFI_UNICAST;
176 break;
177 }
178 return safi;
179 }
180
181 /**
182 * Converts an AFI in string form to afi_t
183 *
184 * @param afi string, one of
185 * - "ipv4"
186 * - "ipv6"
187 * - "l2vpn"
188 * @return the corresponding afi_t
189 */
190 afi_t bgp_vty_afi_from_str(const char *afi_str)
191 {
192 afi_t afi = AFI_MAX; /* unknown */
193 if (strmatch(afi_str, "ipv4"))
194 afi = AFI_IP;
195 else if (strmatch(afi_str, "ipv6"))
196 afi = AFI_IP6;
197 else if (strmatch(afi_str, "l2vpn"))
198 afi = AFI_L2VPN;
199 return afi;
200 }
201
202 int argv_find_and_parse_afi(struct cmd_token **argv, int argc, int *index,
203 afi_t *afi)
204 {
205 int ret = 0;
206 if (argv_find(argv, argc, "ipv4", index)) {
207 ret = 1;
208 if (afi)
209 *afi = AFI_IP;
210 } else if (argv_find(argv, argc, "ipv6", index)) {
211 ret = 1;
212 if (afi)
213 *afi = AFI_IP6;
214 }
215 return ret;
216 }
217
218 /* supports <unicast|multicast|vpn|labeled-unicast> */
219 safi_t bgp_vty_safi_from_str(const char *safi_str)
220 {
221 safi_t safi = SAFI_MAX; /* unknown */
222 if (strmatch(safi_str, "multicast"))
223 safi = SAFI_MULTICAST;
224 else if (strmatch(safi_str, "unicast"))
225 safi = SAFI_UNICAST;
226 else if (strmatch(safi_str, "vpn"))
227 safi = SAFI_MPLS_VPN;
228 else if (strmatch(safi_str, "evpn"))
229 safi = SAFI_EVPN;
230 else if (strmatch(safi_str, "labeled-unicast"))
231 safi = SAFI_LABELED_UNICAST;
232 else if (strmatch(safi_str, "flowspec"))
233 safi = SAFI_FLOWSPEC;
234 return safi;
235 }
236
237 int argv_find_and_parse_safi(struct cmd_token **argv, int argc, int *index,
238 safi_t *safi)
239 {
240 int ret = 0;
241 if (argv_find(argv, argc, "unicast", index)) {
242 ret = 1;
243 if (safi)
244 *safi = SAFI_UNICAST;
245 } else if (argv_find(argv, argc, "multicast", index)) {
246 ret = 1;
247 if (safi)
248 *safi = SAFI_MULTICAST;
249 } else if (argv_find(argv, argc, "labeled-unicast", index)) {
250 ret = 1;
251 if (safi)
252 *safi = SAFI_LABELED_UNICAST;
253 } else if (argv_find(argv, argc, "vpn", index)) {
254 ret = 1;
255 if (safi)
256 *safi = SAFI_MPLS_VPN;
257 } else if (argv_find(argv, argc, "flowspec", index)) {
258 ret = 1;
259 if (safi)
260 *safi = SAFI_FLOWSPEC;
261 }
262 return ret;
263 }
264
265 /*
266 * bgp_vty_find_and_parse_afi_safi_bgp
267 *
268 * For a given 'show ...' command, correctly parse the afi/safi/bgp out from it
269 * This function *assumes* that the calling function pre-sets the afi/safi/bgp
270 * to appropriate values for the calling function. This is to allow the
271 * calling function to make decisions appropriate for the show command
272 * that is being parsed.
273 *
274 * The show commands are generally of the form:
275 * "show [ip] bgp [<view|vrf> VIEWVRFNAME] [<ipv4|ipv6>
276 * [<unicast|multicast|vpn|labeled-unicast>]] ..."
277 *
278 * Since we use argv_find if the show command in particular doesn't have:
279 * [ip]
280 * [<view|vrf> VIEWVRFNAME]
281 * [<ipv4|ipv6> [<unicast|multicast|vpn|labeled-unicast>]]
282 * The command parsing should still be ok.
283 *
284 * vty -> The vty for the command so we can output some useful data in
285 * the event of a parse error in the vrf.
286 * argv -> The command tokens
287 * argc -> How many command tokens we have
288 * idx -> The current place in the command, generally should be 0 for this
289 * function
290 * afi -> The parsed afi if it was included in the show command, returned here
291 * safi -> The parsed safi if it was included in the show command, returned here
292 * bgp -> Pointer to the bgp data structure we need to fill in.
293 *
294 * The function returns the correct location in the parse tree for the
295 * last token found.
296 *
297 * Returns 0 for failure to parse correctly, else the idx position of where
298 * it found the last token.
299 */
300 int bgp_vty_find_and_parse_afi_safi_bgp(struct vty *vty,
301 struct cmd_token **argv, int argc,
302 int *idx, afi_t *afi, safi_t *safi,
303 struct bgp **bgp)
304 {
305 char *vrf_name = NULL;
306
307 assert(afi);
308 assert(safi);
309 assert(bgp);
310
311 if (argv_find(argv, argc, "ip", idx))
312 *afi = AFI_IP;
313
314 if (argv_find(argv, argc, "view", idx)
315 || argv_find(argv, argc, "vrf", idx)) {
316 vrf_name = argv[*idx + 1]->arg;
317
318 if (strmatch(vrf_name, "all"))
319 *bgp = NULL;
320 else {
321 *bgp = bgp_lookup_by_name(vrf_name);
322 if (!*bgp) {
323 vty_out(vty,
324 "View/Vrf specified is unknown: %s\n",
325 vrf_name);
326 *idx = 0;
327 return 0;
328 }
329 }
330 } else {
331 *bgp = bgp_get_default();
332 if (!*bgp) {
333 vty_out(vty, "Unable to find default BGP instance\n");
334 *idx = 0;
335 return 0;
336 }
337 }
338
339 if (argv_find_and_parse_afi(argv, argc, idx, afi))
340 argv_find_and_parse_safi(argv, argc, idx, safi);
341
342 *idx += 1;
343 return *idx;
344 }
345
346 static int peer_address_self_check(struct bgp *bgp, union sockunion *su)
347 {
348 struct interface *ifp = NULL;
349
350 if (su->sa.sa_family == AF_INET)
351 ifp = if_lookup_by_ipv4_exact(&su->sin.sin_addr, bgp->vrf_id);
352 else if (su->sa.sa_family == AF_INET6)
353 ifp = if_lookup_by_ipv6_exact(&su->sin6.sin6_addr,
354 su->sin6.sin6_scope_id,
355 bgp->vrf_id);
356
357 if (ifp)
358 return 1;
359
360 return 0;
361 }
362
363 /* Utility function for looking up peer from VTY. */
364 /* This is used only for configuration, so disallow if attempted on
365 * a dynamic neighbor.
366 */
367 static struct peer *peer_lookup_vty(struct vty *vty, const char *ip_str)
368 {
369 struct bgp *bgp = VTY_GET_CONTEXT(bgp);
370 int ret;
371 union sockunion su;
372 struct peer *peer;
373
374 if (!bgp) {
375 return NULL;
376 }
377
378 ret = str2sockunion(ip_str, &su);
379 if (ret < 0) {
380 peer = peer_lookup_by_conf_if(bgp, ip_str);
381 if (!peer) {
382 if ((peer = peer_lookup_by_hostname(bgp, ip_str))
383 == NULL) {
384 vty_out(vty,
385 "%% Malformed address or name: %s\n",
386 ip_str);
387 return NULL;
388 }
389 }
390 } else {
391 peer = peer_lookup(bgp, &su);
392 if (!peer) {
393 vty_out(vty,
394 "%% Specify remote-as or peer-group commands first\n");
395 return NULL;
396 }
397 if (peer_dynamic_neighbor(peer)) {
398 vty_out(vty,
399 "%% Operation not allowed on a dynamic neighbor\n");
400 return NULL;
401 }
402 }
403 return peer;
404 }
405
406 /* Utility function for looking up peer or peer group. */
407 /* This is used only for configuration, so disallow if attempted on
408 * a dynamic neighbor.
409 */
410 struct peer *peer_and_group_lookup_vty(struct vty *vty, const char *peer_str)
411 {
412 struct bgp *bgp = VTY_GET_CONTEXT(bgp);
413 int ret;
414 union sockunion su;
415 struct peer *peer = NULL;
416 struct peer_group *group = NULL;
417
418 if (!bgp) {
419 return NULL;
420 }
421
422 ret = str2sockunion(peer_str, &su);
423 if (ret == 0) {
424 /* IP address, locate peer. */
425 peer = peer_lookup(bgp, &su);
426 } else {
427 /* Not IP, could match either peer configured on interface or a
428 * group. */
429 peer = peer_lookup_by_conf_if(bgp, peer_str);
430 if (!peer)
431 group = peer_group_lookup(bgp, peer_str);
432 }
433
434 if (peer) {
435 if (peer_dynamic_neighbor(peer)) {
436 vty_out(vty,
437 "%% Operation not allowed on a dynamic neighbor\n");
438 return NULL;
439 }
440
441 return peer;
442 }
443
444 if (group)
445 return group->conf;
446
447 vty_out(vty, "%% Specify remote-as or peer-group commands first\n");
448
449 return NULL;
450 }
451
452 int bgp_vty_return(struct vty *vty, int ret)
453 {
454 const char *str = NULL;
455
456 switch (ret) {
457 case BGP_ERR_INVALID_VALUE:
458 str = "Invalid value";
459 break;
460 case BGP_ERR_INVALID_FLAG:
461 str = "Invalid flag";
462 break;
463 case BGP_ERR_PEER_GROUP_SHUTDOWN:
464 str = "Peer-group has been shutdown. Activate the peer-group first";
465 break;
466 case BGP_ERR_PEER_FLAG_CONFLICT:
467 str = "Can't set override-capability and strict-capability-match at the same time";
468 break;
469 case BGP_ERR_PEER_GROUP_NO_REMOTE_AS:
470 str = "Specify remote-as or peer-group remote AS first";
471 break;
472 case BGP_ERR_PEER_GROUP_CANT_CHANGE:
473 str = "Cannot change the peer-group. Deconfigure first";
474 break;
475 case BGP_ERR_PEER_GROUP_MISMATCH:
476 str = "Peer is not a member of this peer-group";
477 break;
478 case BGP_ERR_PEER_FILTER_CONFLICT:
479 str = "Prefix/distribute list can not co-exist";
480 break;
481 case BGP_ERR_NOT_INTERNAL_PEER:
482 str = "Invalid command. Not an internal neighbor";
483 break;
484 case BGP_ERR_REMOVE_PRIVATE_AS:
485 str = "remove-private-AS cannot be configured for IBGP peers";
486 break;
487 case BGP_ERR_LOCAL_AS_ALLOWED_ONLY_FOR_EBGP:
488 str = "Local-AS allowed only for EBGP peers";
489 break;
490 case BGP_ERR_CANNOT_HAVE_LOCAL_AS_SAME_AS:
491 str = "Cannot have local-as same as BGP AS number";
492 break;
493 case BGP_ERR_TCPSIG_FAILED:
494 str = "Error while applying TCP-Sig to session(s)";
495 break;
496 case BGP_ERR_NO_EBGP_MULTIHOP_WITH_TTLHACK:
497 str = "ebgp-multihop and ttl-security cannot be configured together";
498 break;
499 case BGP_ERR_NO_IBGP_WITH_TTLHACK:
500 str = "ttl-security only allowed for EBGP peers";
501 break;
502 case BGP_ERR_AS_OVERRIDE:
503 str = "as-override cannot be configured for IBGP peers";
504 break;
505 case BGP_ERR_INVALID_DYNAMIC_NEIGHBORS_LIMIT:
506 str = "Invalid limit for number of dynamic neighbors";
507 break;
508 case BGP_ERR_DYNAMIC_NEIGHBORS_RANGE_EXISTS:
509 str = "Dynamic neighbor listen range already exists";
510 break;
511 case BGP_ERR_INVALID_FOR_DYNAMIC_PEER:
512 str = "Operation not allowed on a dynamic neighbor";
513 break;
514 case BGP_ERR_INVALID_FOR_DIRECT_PEER:
515 str = "Operation not allowed on a directly connected neighbor";
516 break;
517 case BGP_ERR_PEER_SAFI_CONFLICT:
518 str = "Cannot activate peer for both 'ipv4 unicast' and 'ipv4 labeled-unicast'";
519 break;
520 }
521 if (str) {
522 vty_out(vty, "%% %s\n", str);
523 return CMD_WARNING_CONFIG_FAILED;
524 }
525 return CMD_SUCCESS;
526 }
527
528 /* BGP clear sort. */
529 enum clear_sort {
530 clear_all,
531 clear_peer,
532 clear_group,
533 clear_external,
534 clear_as
535 };
536
537 static void bgp_clear_vty_error(struct vty *vty, struct peer *peer, afi_t afi,
538 safi_t safi, int error)
539 {
540 switch (error) {
541 case BGP_ERR_AF_UNCONFIGURED:
542 vty_out(vty,
543 "%%BGP: Enable %s address family for the neighbor %s\n",
544 afi_safi_print(afi, safi), peer->host);
545 break;
546 case BGP_ERR_SOFT_RECONFIG_UNCONFIGURED:
547 vty_out(vty,
548 "%%BGP: Inbound soft reconfig for %s not possible as it\n has neither refresh capability, nor inbound soft reconfig\n",
549 peer->host);
550 break;
551 default:
552 break;
553 }
554 }
555
556 /* `clear ip bgp' functions. */
557 static int bgp_clear(struct vty *vty, struct bgp *bgp, afi_t afi, safi_t safi,
558 enum clear_sort sort, enum bgp_clear_type stype,
559 const char *arg)
560 {
561 int ret;
562 bool found = false;
563 struct peer *peer;
564 struct listnode *node, *nnode;
565
566 /* Clear all neighbors. */
567 /*
568 * Pass along pointer to next node to peer_clear() when walking all
569 * nodes on the BGP instance as that may get freed if it is a
570 * doppelganger
571 */
572 if (sort == clear_all) {
573 for (ALL_LIST_ELEMENTS(bgp->peer, node, nnode, peer)) {
574 if (!peer->afc[afi][safi])
575 continue;
576
577 if (stype == BGP_CLEAR_SOFT_NONE)
578 ret = peer_clear(peer, &nnode);
579 else
580 ret = peer_clear_soft(peer, afi, safi, stype);
581
582 if (ret < 0)
583 bgp_clear_vty_error(vty, peer, afi, safi, ret);
584 else
585 found = true;
586 }
587
588 /* This is to apply read-only mode on this clear. */
589 if (stype == BGP_CLEAR_SOFT_NONE)
590 bgp->update_delay_over = 0;
591
592 if (!found)
593 vty_out(vty, "%%BGP: No %s peer configured",
594 afi_safi_print(afi, safi));
595
596 return CMD_SUCCESS;
597 }
598
599 /* Clear specified neighbor. */
600 if (sort == clear_peer) {
601 union sockunion su;
602
603 /* Make sockunion for lookup. */
604 ret = str2sockunion(arg, &su);
605 if (ret < 0) {
606 peer = peer_lookup_by_conf_if(bgp, arg);
607 if (!peer) {
608 peer = peer_lookup_by_hostname(bgp, arg);
609 if (!peer) {
610 vty_out(vty,
611 "Malformed address or name: %s\n",
612 arg);
613 return CMD_WARNING;
614 }
615 }
616 } else {
617 peer = peer_lookup(bgp, &su);
618 if (!peer) {
619 vty_out(vty,
620 "%%BGP: Unknown neighbor - \"%s\"\n",
621 arg);
622 return CMD_WARNING;
623 }
624 }
625
626 if (!peer->afc[afi][safi])
627 ret = BGP_ERR_AF_UNCONFIGURED;
628 else if (stype == BGP_CLEAR_SOFT_NONE)
629 ret = peer_clear(peer, NULL);
630 else
631 ret = peer_clear_soft(peer, afi, safi, stype);
632
633 if (ret < 0)
634 bgp_clear_vty_error(vty, peer, afi, safi, ret);
635
636 return CMD_SUCCESS;
637 }
638
639 /* Clear all neighbors belonging to a specific peer-group. */
640 if (sort == clear_group) {
641 struct peer_group *group;
642
643 group = peer_group_lookup(bgp, arg);
644 if (!group) {
645 vty_out(vty, "%%BGP: No such peer-group %s\n", arg);
646 return CMD_WARNING;
647 }
648
649 for (ALL_LIST_ELEMENTS(group->peer, node, nnode, peer)) {
650 if (!peer->afc[afi][safi])
651 continue;
652
653 if (stype == BGP_CLEAR_SOFT_NONE)
654 ret = peer_clear(peer, NULL);
655 else
656 ret = peer_clear_soft(peer, afi, safi, stype);
657
658 if (ret < 0)
659 bgp_clear_vty_error(vty, peer, afi, safi, ret);
660 else
661 found = true;
662 }
663
664 if (!found)
665 vty_out(vty,
666 "%%BGP: No %s peer belonging to peer-group %s is configured\n",
667 afi_safi_print(afi, safi), arg);
668
669 return CMD_SUCCESS;
670 }
671
672 /* Clear all external (eBGP) neighbors. */
673 if (sort == clear_external) {
674 for (ALL_LIST_ELEMENTS(bgp->peer, node, nnode, peer)) {
675 if (peer->sort == BGP_PEER_IBGP)
676 continue;
677
678 if (!peer->afc[afi][safi])
679 continue;
680
681 if (stype == BGP_CLEAR_SOFT_NONE)
682 ret = peer_clear(peer, &nnode);
683 else
684 ret = peer_clear_soft(peer, afi, safi, stype);
685
686 if (ret < 0)
687 bgp_clear_vty_error(vty, peer, afi, safi, ret);
688 else
689 found = true;
690 }
691
692 if (!found)
693 vty_out(vty,
694 "%%BGP: No external %s peer is configured\n",
695 afi_safi_print(afi, safi));
696
697 return CMD_SUCCESS;
698 }
699
700 /* Clear all neighbors belonging to a specific AS. */
701 if (sort == clear_as) {
702 as_t as = strtoul(arg, NULL, 10);
703
704 for (ALL_LIST_ELEMENTS(bgp->peer, node, nnode, peer)) {
705 if (peer->as != as)
706 continue;
707
708 if (!peer->afc[afi][safi])
709 ret = BGP_ERR_AF_UNCONFIGURED;
710 else if (stype == BGP_CLEAR_SOFT_NONE)
711 ret = peer_clear(peer, &nnode);
712 else
713 ret = peer_clear_soft(peer, afi, safi, stype);
714
715 if (ret < 0)
716 bgp_clear_vty_error(vty, peer, afi, safi, ret);
717 else
718 found = true;
719 }
720
721 if (!found)
722 vty_out(vty,
723 "%%BGP: No %s peer is configured with AS %s\n",
724 afi_safi_print(afi, safi), arg);
725
726 return CMD_SUCCESS;
727 }
728
729 return CMD_SUCCESS;
730 }
731
732 static int bgp_clear_vty(struct vty *vty, const char *name, afi_t afi,
733 safi_t safi, enum clear_sort sort,
734 enum bgp_clear_type stype, const char *arg)
735 {
736 struct bgp *bgp;
737
738 /* BGP structure lookup. */
739 if (name) {
740 bgp = bgp_lookup_by_name(name);
741 if (bgp == NULL) {
742 vty_out(vty, "Can't find BGP instance %s\n", name);
743 return CMD_WARNING;
744 }
745 } else {
746 bgp = bgp_get_default();
747 if (bgp == NULL) {
748 vty_out(vty, "No BGP process is configured\n");
749 return CMD_WARNING;
750 }
751 }
752
753 return bgp_clear(vty, bgp, afi, safi, sort, stype, arg);
754 }
755
756 /* clear soft inbound */
757 static void bgp_clear_star_soft_in(struct vty *vty, const char *name)
758 {
759 bgp_clear_vty(vty, name, AFI_IP, SAFI_UNICAST, clear_all,
760 BGP_CLEAR_SOFT_IN, NULL);
761 bgp_clear_vty(vty, name, AFI_IP6, SAFI_UNICAST, clear_all,
762 BGP_CLEAR_SOFT_IN, NULL);
763 }
764
765 /* clear soft outbound */
766 static void bgp_clear_star_soft_out(struct vty *vty, const char *name)
767 {
768 bgp_clear_vty(vty, name, AFI_IP, SAFI_UNICAST, clear_all,
769 BGP_CLEAR_SOFT_OUT, NULL);
770 bgp_clear_vty(vty, name, AFI_IP6, SAFI_UNICAST, clear_all,
771 BGP_CLEAR_SOFT_OUT, NULL);
772 }
773
774
775 #ifndef VTYSH_EXTRACT_PL
776 #include "bgpd/bgp_vty_clippy.c"
777 #endif
778
779 /* BGP global configuration. */
780 #if (CONFDATE > 20190601)
781 CPP_NOTICE("bgpd: time to remove deprecated bgp multiple-instance")
782 CPP_NOTICE("This includes BGP_OPT_MULTIPLE_INSTANCE")
783 #endif
784 DEFUN_HIDDEN (bgp_multiple_instance_func,
785 bgp_multiple_instance_cmd,
786 "bgp multiple-instance",
787 BGP_STR
788 "Enable bgp multiple instance\n")
789 {
790 bgp_option_set(BGP_OPT_MULTIPLE_INSTANCE);
791 return CMD_SUCCESS;
792 }
793
794 DEFUN_HIDDEN (no_bgp_multiple_instance,
795 no_bgp_multiple_instance_cmd,
796 "no bgp multiple-instance",
797 NO_STR
798 BGP_STR
799 "BGP multiple instance\n")
800 {
801 int ret;
802
803 vty_out(vty, "This config option is deprecated, and is scheduled for removal.\n");
804 vty_out(vty, "if you are using this please let the developers know\n");
805 zlog_warn("Deprecated option: `bgp multiple-instance` being used");
806 ret = bgp_option_unset(BGP_OPT_MULTIPLE_INSTANCE);
807 if (ret < 0) {
808 vty_out(vty, "%% There are more than two BGP instances\n");
809 return CMD_WARNING_CONFIG_FAILED;
810 }
811 return CMD_SUCCESS;
812 }
813
814 #if (CONFDATE > 20190601)
815 CPP_NOTICE("bgpd: time to remove deprecated cli bgp config-type cisco")
816 CPP_NOTICE("This includes BGP_OPT_CISCO_CONFIG")
817 #endif
818 DEFUN_HIDDEN (bgp_config_type,
819 bgp_config_type_cmd,
820 "bgp config-type <cisco|zebra>",
821 BGP_STR
822 "Configuration type\n"
823 "cisco\n"
824 "zebra\n")
825 {
826 int idx = 0;
827 if (argv_find(argv, argc, "cisco", &idx)) {
828 vty_out(vty, "This config option is deprecated, and is scheduled for removal.\n");
829 vty_out(vty, "if you are using this please let the developers know!\n");
830 zlog_warn("Deprecated option: `bgp config-type cisco` being used");
831 bgp_option_set(BGP_OPT_CONFIG_CISCO);
832 } else
833 bgp_option_unset(BGP_OPT_CONFIG_CISCO);
834
835 return CMD_SUCCESS;
836 }
837
838 DEFUN_HIDDEN (no_bgp_config_type,
839 no_bgp_config_type_cmd,
840 "no bgp config-type [<cisco|zebra>]",
841 NO_STR
842 BGP_STR
843 "Display configuration type\n"
844 "cisco\n"
845 "zebra\n")
846 {
847 bgp_option_unset(BGP_OPT_CONFIG_CISCO);
848 return CMD_SUCCESS;
849 }
850
851
852 DEFUN (no_synchronization,
853 no_synchronization_cmd,
854 "no synchronization",
855 NO_STR
856 "Perform IGP synchronization\n")
857 {
858 return CMD_SUCCESS;
859 }
860
861 DEFUN (no_auto_summary,
862 no_auto_summary_cmd,
863 "no auto-summary",
864 NO_STR
865 "Enable automatic network number summarization\n")
866 {
867 return CMD_SUCCESS;
868 }
869
870 /* "router bgp" commands. */
871 DEFUN_NOSH (router_bgp,
872 router_bgp_cmd,
873 "router bgp [(1-4294967295) [<view|vrf> VIEWVRFNAME]]",
874 ROUTER_STR
875 BGP_STR
876 AS_STR
877 BGP_INSTANCE_HELP_STR)
878 {
879 int idx_asn = 2;
880 int idx_view_vrf = 3;
881 int idx_vrf = 4;
882 int ret;
883 as_t as;
884 struct bgp *bgp;
885 const char *name = NULL;
886 enum bgp_instance_type inst_type;
887
888 // "router bgp" without an ASN
889 if (argc == 2) {
890 // Pending: Make VRF option available for ASN less config
891 bgp = bgp_get_default();
892
893 if (bgp == NULL) {
894 vty_out(vty, "%% No BGP process is configured\n");
895 return CMD_WARNING_CONFIG_FAILED;
896 }
897
898 if (listcount(bm->bgp) > 1) {
899 vty_out(vty, "%% Please specify ASN and VRF\n");
900 return CMD_WARNING_CONFIG_FAILED;
901 }
902 }
903
904 // "router bgp X"
905 else {
906 as = strtoul(argv[idx_asn]->arg, NULL, 10);
907
908 inst_type = BGP_INSTANCE_TYPE_DEFAULT;
909 if (argc > 3) {
910 name = argv[idx_vrf]->arg;
911
912 if (!strcmp(argv[idx_view_vrf]->text, "vrf"))
913 inst_type = BGP_INSTANCE_TYPE_VRF;
914 else if (!strcmp(argv[idx_view_vrf]->text, "view"))
915 inst_type = BGP_INSTANCE_TYPE_VIEW;
916 }
917
918 ret = bgp_get(&bgp, &as, name, inst_type);
919 switch (ret) {
920 case BGP_ERR_MULTIPLE_INSTANCE_NOT_SET:
921 vty_out(vty,
922 "Please specify 'bgp multiple-instance' first\n");
923 return CMD_WARNING_CONFIG_FAILED;
924 case BGP_ERR_AS_MISMATCH:
925 vty_out(vty, "BGP is already running; AS is %u\n", as);
926 return CMD_WARNING_CONFIG_FAILED;
927 case BGP_ERR_INSTANCE_MISMATCH:
928 vty_out(vty,
929 "BGP instance name and AS number mismatch\n");
930 vty_out(vty,
931 "BGP instance is already running; AS is %u\n",
932 as);
933 return CMD_WARNING_CONFIG_FAILED;
934 }
935
936 /*
937 * If we just instantiated the default instance, complete
938 * any pending VRF-VPN leaking that was configured via
939 * earlier "router bgp X vrf FOO" blocks.
940 */
941 if (inst_type == BGP_INSTANCE_TYPE_DEFAULT)
942 vpn_leak_postchange_all();
943
944 /* Pending: handle when user tries to change a view to vrf n vv.
945 */
946 }
947
948 /* unset the auto created flag as the user config is now present */
949 UNSET_FLAG(bgp->vrf_flags, BGP_VRF_AUTO);
950 VTY_PUSH_CONTEXT(BGP_NODE, bgp);
951
952 return CMD_SUCCESS;
953 }
954
955 /* "no router bgp" commands. */
956 DEFUN (no_router_bgp,
957 no_router_bgp_cmd,
958 "no router bgp [(1-4294967295) [<view|vrf> VIEWVRFNAME]]",
959 NO_STR
960 ROUTER_STR
961 BGP_STR
962 AS_STR
963 BGP_INSTANCE_HELP_STR)
964 {
965 int idx_asn = 3;
966 int idx_vrf = 5;
967 as_t as;
968 struct bgp *bgp;
969 const char *name = NULL;
970
971 // "no router bgp" without an ASN
972 if (argc == 3) {
973 // Pending: Make VRF option available for ASN less config
974 bgp = bgp_get_default();
975
976 if (bgp == NULL) {
977 vty_out(vty, "%% No BGP process is configured\n");
978 return CMD_WARNING_CONFIG_FAILED;
979 }
980
981 if (listcount(bm->bgp) > 1) {
982 vty_out(vty, "%% Please specify ASN and VRF\n");
983 return CMD_WARNING_CONFIG_FAILED;
984 }
985
986 if (bgp->l3vni) {
987 vty_out(vty, "%% Please unconfigure l3vni %u",
988 bgp->l3vni);
989 return CMD_WARNING_CONFIG_FAILED;
990 }
991 } else {
992 as = strtoul(argv[idx_asn]->arg, NULL, 10);
993
994 if (argc > 4)
995 name = argv[idx_vrf]->arg;
996
997 /* Lookup bgp structure. */
998 bgp = bgp_lookup(as, name);
999 if (!bgp) {
1000 vty_out(vty, "%% Can't find BGP instance\n");
1001 return CMD_WARNING_CONFIG_FAILED;
1002 }
1003
1004 if (bgp->l3vni) {
1005 vty_out(vty, "%% Please unconfigure l3vni %u",
1006 bgp->l3vni);
1007 return CMD_WARNING_CONFIG_FAILED;
1008 }
1009 }
1010
1011 bgp_delete(bgp);
1012
1013 return CMD_SUCCESS;
1014 }
1015
1016
1017 /* BGP router-id. */
1018
1019 DEFPY (bgp_router_id,
1020 bgp_router_id_cmd,
1021 "bgp router-id A.B.C.D",
1022 BGP_STR
1023 "Override configured router identifier\n"
1024 "Manually configured router identifier\n")
1025 {
1026 VTY_DECLVAR_CONTEXT(bgp, bgp);
1027 bgp_router_id_static_set(bgp, router_id);
1028 return CMD_SUCCESS;
1029 }
1030
1031 DEFPY (no_bgp_router_id,
1032 no_bgp_router_id_cmd,
1033 "no bgp router-id [A.B.C.D]",
1034 NO_STR
1035 BGP_STR
1036 "Override configured router identifier\n"
1037 "Manually configured router identifier\n")
1038 {
1039 VTY_DECLVAR_CONTEXT(bgp, bgp);
1040
1041 if (router_id_str) {
1042 if (!IPV4_ADDR_SAME(&bgp->router_id_static, &router_id)) {
1043 vty_out(vty, "%% BGP router-id doesn't match\n");
1044 return CMD_WARNING_CONFIG_FAILED;
1045 }
1046 }
1047
1048 router_id.s_addr = 0;
1049 bgp_router_id_static_set(bgp, router_id);
1050
1051 return CMD_SUCCESS;
1052 }
1053
1054
1055 /* BGP Cluster ID. */
1056 DEFUN (bgp_cluster_id,
1057 bgp_cluster_id_cmd,
1058 "bgp cluster-id <A.B.C.D|(1-4294967295)>",
1059 BGP_STR
1060 "Configure Route-Reflector Cluster-id\n"
1061 "Route-Reflector Cluster-id in IP address format\n"
1062 "Route-Reflector Cluster-id as 32 bit quantity\n")
1063 {
1064 VTY_DECLVAR_CONTEXT(bgp, bgp);
1065 int idx_ipv4 = 2;
1066 int ret;
1067 struct in_addr cluster;
1068
1069 ret = inet_aton(argv[idx_ipv4]->arg, &cluster);
1070 if (!ret) {
1071 vty_out(vty, "%% Malformed bgp cluster identifier\n");
1072 return CMD_WARNING_CONFIG_FAILED;
1073 }
1074
1075 bgp_cluster_id_set(bgp, &cluster);
1076 bgp_clear_star_soft_out(vty, bgp->name);
1077
1078 return CMD_SUCCESS;
1079 }
1080
1081 DEFUN (no_bgp_cluster_id,
1082 no_bgp_cluster_id_cmd,
1083 "no bgp cluster-id [<A.B.C.D|(1-4294967295)>]",
1084 NO_STR
1085 BGP_STR
1086 "Configure Route-Reflector Cluster-id\n"
1087 "Route-Reflector Cluster-id in IP address format\n"
1088 "Route-Reflector Cluster-id as 32 bit quantity\n")
1089 {
1090 VTY_DECLVAR_CONTEXT(bgp, bgp);
1091 bgp_cluster_id_unset(bgp);
1092 bgp_clear_star_soft_out(vty, bgp->name);
1093
1094 return CMD_SUCCESS;
1095 }
1096
1097 DEFUN (bgp_confederation_identifier,
1098 bgp_confederation_identifier_cmd,
1099 "bgp confederation identifier (1-4294967295)",
1100 "BGP specific commands\n"
1101 "AS confederation parameters\n"
1102 "AS number\n"
1103 "Set routing domain confederation AS\n")
1104 {
1105 VTY_DECLVAR_CONTEXT(bgp, bgp);
1106 int idx_number = 3;
1107 as_t as;
1108
1109 as = strtoul(argv[idx_number]->arg, NULL, 10);
1110
1111 bgp_confederation_id_set(bgp, as);
1112
1113 return CMD_SUCCESS;
1114 }
1115
1116 DEFUN (no_bgp_confederation_identifier,
1117 no_bgp_confederation_identifier_cmd,
1118 "no bgp confederation identifier [(1-4294967295)]",
1119 NO_STR
1120 "BGP specific commands\n"
1121 "AS confederation parameters\n"
1122 "AS number\n"
1123 "Set routing domain confederation AS\n")
1124 {
1125 VTY_DECLVAR_CONTEXT(bgp, bgp);
1126 bgp_confederation_id_unset(bgp);
1127
1128 return CMD_SUCCESS;
1129 }
1130
1131 DEFUN (bgp_confederation_peers,
1132 bgp_confederation_peers_cmd,
1133 "bgp confederation peers (1-4294967295)...",
1134 "BGP specific commands\n"
1135 "AS confederation parameters\n"
1136 "Peer ASs in BGP confederation\n"
1137 AS_STR)
1138 {
1139 VTY_DECLVAR_CONTEXT(bgp, bgp);
1140 int idx_asn = 3;
1141 as_t as;
1142 int i;
1143
1144 for (i = idx_asn; i < argc; i++) {
1145 as = strtoul(argv[i]->arg, NULL, 10);
1146
1147 if (bgp->as == as) {
1148 vty_out(vty,
1149 "%% Local member-AS not allowed in confed peer list\n");
1150 continue;
1151 }
1152
1153 bgp_confederation_peers_add(bgp, as);
1154 }
1155 return CMD_SUCCESS;
1156 }
1157
1158 DEFUN (no_bgp_confederation_peers,
1159 no_bgp_confederation_peers_cmd,
1160 "no bgp confederation peers (1-4294967295)...",
1161 NO_STR
1162 "BGP specific commands\n"
1163 "AS confederation parameters\n"
1164 "Peer ASs in BGP confederation\n"
1165 AS_STR)
1166 {
1167 VTY_DECLVAR_CONTEXT(bgp, bgp);
1168 int idx_asn = 4;
1169 as_t as;
1170 int i;
1171
1172 for (i = idx_asn; i < argc; i++) {
1173 as = strtoul(argv[i]->arg, NULL, 10);
1174
1175 bgp_confederation_peers_remove(bgp, as);
1176 }
1177 return CMD_SUCCESS;
1178 }
1179
1180 /**
1181 * Central routine for maximum-paths configuration.
1182 * @peer_type: BGP_PEER_EBGP or BGP_PEER_IBGP
1183 * @set: 1 for setting values, 0 for removing the max-paths config.
1184 */
1185 static int bgp_maxpaths_config_vty(struct vty *vty, int peer_type,
1186 const char *mpaths, uint16_t options,
1187 int set)
1188 {
1189 VTY_DECLVAR_CONTEXT(bgp, bgp);
1190 uint16_t maxpaths = 0;
1191 int ret;
1192 afi_t afi;
1193 safi_t safi;
1194
1195 afi = bgp_node_afi(vty);
1196 safi = bgp_node_safi(vty);
1197
1198 if (set) {
1199 maxpaths = strtol(mpaths, NULL, 10);
1200 if (maxpaths > multipath_num) {
1201 vty_out(vty,
1202 "%% Maxpaths Specified: %d is > than multipath num specified on bgp command line %d",
1203 maxpaths, multipath_num);
1204 return CMD_WARNING_CONFIG_FAILED;
1205 }
1206 ret = bgp_maximum_paths_set(bgp, afi, safi, peer_type, maxpaths,
1207 options);
1208 } else
1209 ret = bgp_maximum_paths_unset(bgp, afi, safi, peer_type);
1210
1211 if (ret < 0) {
1212 vty_out(vty,
1213 "%% Failed to %sset maximum-paths %s %u for afi %u, safi %u\n",
1214 (set == 1) ? "" : "un",
1215 (peer_type == BGP_PEER_EBGP) ? "ebgp" : "ibgp",
1216 maxpaths, afi, safi);
1217 return CMD_WARNING_CONFIG_FAILED;
1218 }
1219
1220 bgp_recalculate_all_bestpaths(bgp);
1221
1222 return CMD_SUCCESS;
1223 }
1224
1225 DEFUN (bgp_maxmed_admin,
1226 bgp_maxmed_admin_cmd,
1227 "bgp max-med administrative ",
1228 BGP_STR
1229 "Advertise routes with max-med\n"
1230 "Administratively applied, for an indefinite period\n")
1231 {
1232 VTY_DECLVAR_CONTEXT(bgp, bgp);
1233
1234 bgp->v_maxmed_admin = 1;
1235 bgp->maxmed_admin_value = BGP_MAXMED_VALUE_DEFAULT;
1236
1237 bgp_maxmed_update(bgp);
1238
1239 return CMD_SUCCESS;
1240 }
1241
1242 DEFUN (bgp_maxmed_admin_medv,
1243 bgp_maxmed_admin_medv_cmd,
1244 "bgp max-med administrative (0-4294967295)",
1245 BGP_STR
1246 "Advertise routes with max-med\n"
1247 "Administratively applied, for an indefinite period\n"
1248 "Max MED value to be used\n")
1249 {
1250 VTY_DECLVAR_CONTEXT(bgp, bgp);
1251 int idx_number = 3;
1252
1253 bgp->v_maxmed_admin = 1;
1254 bgp->maxmed_admin_value = strtoul(argv[idx_number]->arg, NULL, 10);
1255
1256 bgp_maxmed_update(bgp);
1257
1258 return CMD_SUCCESS;
1259 }
1260
1261 DEFUN (no_bgp_maxmed_admin,
1262 no_bgp_maxmed_admin_cmd,
1263 "no bgp max-med administrative [(0-4294967295)]",
1264 NO_STR
1265 BGP_STR
1266 "Advertise routes with max-med\n"
1267 "Administratively applied, for an indefinite period\n"
1268 "Max MED value to be used\n")
1269 {
1270 VTY_DECLVAR_CONTEXT(bgp, bgp);
1271 bgp->v_maxmed_admin = BGP_MAXMED_ADMIN_UNCONFIGURED;
1272 bgp->maxmed_admin_value = BGP_MAXMED_VALUE_DEFAULT;
1273 bgp_maxmed_update(bgp);
1274
1275 return CMD_SUCCESS;
1276 }
1277
1278 DEFUN (bgp_maxmed_onstartup,
1279 bgp_maxmed_onstartup_cmd,
1280 "bgp max-med on-startup (5-86400) [(0-4294967295)]",
1281 BGP_STR
1282 "Advertise routes with max-med\n"
1283 "Effective on a startup\n"
1284 "Time (seconds) period for max-med\n"
1285 "Max MED value to be used\n")
1286 {
1287 VTY_DECLVAR_CONTEXT(bgp, bgp);
1288 int idx = 0;
1289
1290 argv_find(argv, argc, "(5-86400)", &idx);
1291 bgp->v_maxmed_onstartup = strtoul(argv[idx]->arg, NULL, 10);
1292 if (argv_find(argv, argc, "(0-4294967295)", &idx))
1293 bgp->maxmed_onstartup_value = strtoul(argv[idx]->arg, NULL, 10);
1294 else
1295 bgp->maxmed_onstartup_value = BGP_MAXMED_VALUE_DEFAULT;
1296
1297 bgp_maxmed_update(bgp);
1298
1299 return CMD_SUCCESS;
1300 }
1301
1302 DEFUN (no_bgp_maxmed_onstartup,
1303 no_bgp_maxmed_onstartup_cmd,
1304 "no bgp max-med on-startup [(5-86400) [(0-4294967295)]]",
1305 NO_STR
1306 BGP_STR
1307 "Advertise routes with max-med\n"
1308 "Effective on a startup\n"
1309 "Time (seconds) period for max-med\n"
1310 "Max MED value to be used\n")
1311 {
1312 VTY_DECLVAR_CONTEXT(bgp, bgp);
1313
1314 /* Cancel max-med onstartup if its on */
1315 if (bgp->t_maxmed_onstartup) {
1316 THREAD_TIMER_OFF(bgp->t_maxmed_onstartup);
1317 bgp->maxmed_onstartup_over = 1;
1318 }
1319
1320 bgp->v_maxmed_onstartup = BGP_MAXMED_ONSTARTUP_UNCONFIGURED;
1321 bgp->maxmed_onstartup_value = BGP_MAXMED_VALUE_DEFAULT;
1322
1323 bgp_maxmed_update(bgp);
1324
1325 return CMD_SUCCESS;
1326 }
1327
1328 static int bgp_update_delay_config_vty(struct vty *vty, const char *delay,
1329 const char *wait)
1330 {
1331 VTY_DECLVAR_CONTEXT(bgp, bgp);
1332 uint16_t update_delay;
1333 uint16_t establish_wait;
1334
1335 update_delay = strtoul(delay, NULL, 10);
1336
1337 if (!wait) /* update-delay <delay> */
1338 {
1339 bgp->v_update_delay = update_delay;
1340 bgp->v_establish_wait = bgp->v_update_delay;
1341 return CMD_SUCCESS;
1342 }
1343
1344 /* update-delay <delay> <establish-wait> */
1345 establish_wait = atoi(wait);
1346 if (update_delay < establish_wait) {
1347 vty_out(vty,
1348 "%%Failed: update-delay less than the establish-wait!\n");
1349 return CMD_WARNING_CONFIG_FAILED;
1350 }
1351
1352 bgp->v_update_delay = update_delay;
1353 bgp->v_establish_wait = establish_wait;
1354
1355 return CMD_SUCCESS;
1356 }
1357
1358 static int bgp_update_delay_deconfig_vty(struct vty *vty)
1359 {
1360 VTY_DECLVAR_CONTEXT(bgp, bgp);
1361
1362 bgp->v_update_delay = BGP_UPDATE_DELAY_DEF;
1363 bgp->v_establish_wait = bgp->v_update_delay;
1364
1365 return CMD_SUCCESS;
1366 }
1367
1368 void bgp_config_write_update_delay(struct vty *vty, struct bgp *bgp)
1369 {
1370 if (bgp->v_update_delay != BGP_UPDATE_DELAY_DEF) {
1371 vty_out(vty, " update-delay %d", bgp->v_update_delay);
1372 if (bgp->v_update_delay != bgp->v_establish_wait)
1373 vty_out(vty, " %d", bgp->v_establish_wait);
1374 vty_out(vty, "\n");
1375 }
1376 }
1377
1378
1379 /* Update-delay configuration */
1380 DEFUN (bgp_update_delay,
1381 bgp_update_delay_cmd,
1382 "update-delay (0-3600)",
1383 "Force initial delay for best-path and updates\n"
1384 "Seconds\n")
1385 {
1386 int idx_number = 1;
1387 return bgp_update_delay_config_vty(vty, argv[idx_number]->arg, NULL);
1388 }
1389
1390 DEFUN (bgp_update_delay_establish_wait,
1391 bgp_update_delay_establish_wait_cmd,
1392 "update-delay (0-3600) (1-3600)",
1393 "Force initial delay for best-path and updates\n"
1394 "Seconds\n"
1395 "Seconds\n")
1396 {
1397 int idx_number = 1;
1398 int idx_number_2 = 2;
1399 return bgp_update_delay_config_vty(vty, argv[idx_number]->arg,
1400 argv[idx_number_2]->arg);
1401 }
1402
1403 /* Update-delay deconfiguration */
1404 DEFUN (no_bgp_update_delay,
1405 no_bgp_update_delay_cmd,
1406 "no update-delay [(0-3600) [(1-3600)]]",
1407 NO_STR
1408 "Force initial delay for best-path and updates\n"
1409 "Seconds\n"
1410 "Seconds\n")
1411 {
1412 return bgp_update_delay_deconfig_vty(vty);
1413 }
1414
1415
1416 static int bgp_wpkt_quanta_config_vty(struct vty *vty, const char *num,
1417 char set)
1418 {
1419 VTY_DECLVAR_CONTEXT(bgp, bgp);
1420
1421 if (set) {
1422 uint32_t quanta = strtoul(num, NULL, 10);
1423 atomic_store_explicit(&bgp->wpkt_quanta, quanta,
1424 memory_order_relaxed);
1425 } else {
1426 atomic_store_explicit(&bgp->wpkt_quanta, BGP_WRITE_PACKET_MAX,
1427 memory_order_relaxed);
1428 }
1429
1430 return CMD_SUCCESS;
1431 }
1432
1433 static int bgp_rpkt_quanta_config_vty(struct vty *vty, const char *num,
1434 char set)
1435 {
1436 VTY_DECLVAR_CONTEXT(bgp, bgp);
1437
1438 if (set) {
1439 uint32_t quanta = strtoul(num, NULL, 10);
1440 atomic_store_explicit(&bgp->rpkt_quanta, quanta,
1441 memory_order_relaxed);
1442 } else {
1443 atomic_store_explicit(&bgp->rpkt_quanta, BGP_READ_PACKET_MAX,
1444 memory_order_relaxed);
1445 }
1446
1447 return CMD_SUCCESS;
1448 }
1449
1450 void bgp_config_write_wpkt_quanta(struct vty *vty, struct bgp *bgp)
1451 {
1452 uint32_t quanta =
1453 atomic_load_explicit(&bgp->wpkt_quanta, memory_order_relaxed);
1454 if (quanta != BGP_WRITE_PACKET_MAX)
1455 vty_out(vty, " write-quanta %d\n", quanta);
1456 }
1457
1458 void bgp_config_write_rpkt_quanta(struct vty *vty, struct bgp *bgp)
1459 {
1460 uint32_t quanta =
1461 atomic_load_explicit(&bgp->rpkt_quanta, memory_order_relaxed);
1462 if (quanta != BGP_READ_PACKET_MAX)
1463 vty_out(vty, " read-quanta %d\n", quanta);
1464 }
1465
1466 /* Packet quanta configuration */
1467 DEFUN (bgp_wpkt_quanta,
1468 bgp_wpkt_quanta_cmd,
1469 "write-quanta (1-10)",
1470 "How many packets to write to peer socket per run\n"
1471 "Number of packets\n")
1472 {
1473 int idx_number = 1;
1474 return bgp_wpkt_quanta_config_vty(vty, argv[idx_number]->arg, 1);
1475 }
1476
1477 DEFUN (no_bgp_wpkt_quanta,
1478 no_bgp_wpkt_quanta_cmd,
1479 "no write-quanta (1-10)",
1480 NO_STR
1481 "How many packets to write to peer socket per I/O cycle\n"
1482 "Number of packets\n")
1483 {
1484 int idx_number = 2;
1485 return bgp_wpkt_quanta_config_vty(vty, argv[idx_number]->arg, 0);
1486 }
1487
1488 DEFUN (bgp_rpkt_quanta,
1489 bgp_rpkt_quanta_cmd,
1490 "read-quanta (1-10)",
1491 "How many packets to read from peer socket per I/O cycle\n"
1492 "Number of packets\n")
1493 {
1494 int idx_number = 1;
1495 return bgp_rpkt_quanta_config_vty(vty, argv[idx_number]->arg, 1);
1496 }
1497
1498 DEFUN (no_bgp_rpkt_quanta,
1499 no_bgp_rpkt_quanta_cmd,
1500 "no read-quanta (1-10)",
1501 NO_STR
1502 "How many packets to read from peer socket per I/O cycle\n"
1503 "Number of packets\n")
1504 {
1505 int idx_number = 2;
1506 return bgp_rpkt_quanta_config_vty(vty, argv[idx_number]->arg, 0);
1507 }
1508
1509 void bgp_config_write_coalesce_time(struct vty *vty, struct bgp *bgp)
1510 {
1511 if (!bgp->heuristic_coalesce)
1512 vty_out(vty, " coalesce-time %u\n", bgp->coalesce_time);
1513 }
1514
1515
1516 DEFUN (bgp_coalesce_time,
1517 bgp_coalesce_time_cmd,
1518 "coalesce-time (0-4294967295)",
1519 "Subgroup coalesce timer\n"
1520 "Subgroup coalesce timer value (in ms)\n")
1521 {
1522 VTY_DECLVAR_CONTEXT(bgp, bgp);
1523
1524 int idx = 0;
1525 argv_find(argv, argc, "(0-4294967295)", &idx);
1526 bgp->heuristic_coalesce = false;
1527 bgp->coalesce_time = strtoul(argv[idx]->arg, NULL, 10);
1528 return CMD_SUCCESS;
1529 }
1530
1531 DEFUN (no_bgp_coalesce_time,
1532 no_bgp_coalesce_time_cmd,
1533 "no coalesce-time (0-4294967295)",
1534 NO_STR
1535 "Subgroup coalesce timer\n"
1536 "Subgroup coalesce timer value (in ms)\n")
1537 {
1538 VTY_DECLVAR_CONTEXT(bgp, bgp);
1539
1540 bgp->heuristic_coalesce = true;
1541 bgp->coalesce_time = BGP_DEFAULT_SUBGROUP_COALESCE_TIME;
1542 return CMD_SUCCESS;
1543 }
1544
1545 /* Maximum-paths configuration */
1546 DEFUN (bgp_maxpaths,
1547 bgp_maxpaths_cmd,
1548 "maximum-paths " CMD_RANGE_STR(1, MULTIPATH_NUM),
1549 "Forward packets over multiple paths\n"
1550 "Number of paths\n")
1551 {
1552 int idx_number = 1;
1553 return bgp_maxpaths_config_vty(vty, BGP_PEER_EBGP,
1554 argv[idx_number]->arg, 0, 1);
1555 }
1556
1557 ALIAS_HIDDEN(bgp_maxpaths, bgp_maxpaths_hidden_cmd,
1558 "maximum-paths " CMD_RANGE_STR(1, MULTIPATH_NUM),
1559 "Forward packets over multiple paths\n"
1560 "Number of paths\n")
1561
1562 DEFUN (bgp_maxpaths_ibgp,
1563 bgp_maxpaths_ibgp_cmd,
1564 "maximum-paths ibgp " CMD_RANGE_STR(1, MULTIPATH_NUM),
1565 "Forward packets over multiple paths\n"
1566 "iBGP-multipath\n"
1567 "Number of paths\n")
1568 {
1569 int idx_number = 2;
1570 return bgp_maxpaths_config_vty(vty, BGP_PEER_IBGP,
1571 argv[idx_number]->arg, 0, 1);
1572 }
1573
1574 ALIAS_HIDDEN(bgp_maxpaths_ibgp, bgp_maxpaths_ibgp_hidden_cmd,
1575 "maximum-paths ibgp " CMD_RANGE_STR(1, MULTIPATH_NUM),
1576 "Forward packets over multiple paths\n"
1577 "iBGP-multipath\n"
1578 "Number of paths\n")
1579
1580 DEFUN (bgp_maxpaths_ibgp_cluster,
1581 bgp_maxpaths_ibgp_cluster_cmd,
1582 "maximum-paths ibgp " CMD_RANGE_STR(1, MULTIPATH_NUM) " equal-cluster-length",
1583 "Forward packets over multiple paths\n"
1584 "iBGP-multipath\n"
1585 "Number of paths\n"
1586 "Match the cluster length\n")
1587 {
1588 int idx_number = 2;
1589 return bgp_maxpaths_config_vty(
1590 vty, BGP_PEER_IBGP, argv[idx_number]->arg,
1591 BGP_FLAG_IBGP_MULTIPATH_SAME_CLUSTERLEN, 1);
1592 }
1593
1594 ALIAS_HIDDEN(bgp_maxpaths_ibgp_cluster, bgp_maxpaths_ibgp_cluster_hidden_cmd,
1595 "maximum-paths ibgp " CMD_RANGE_STR(
1596 1, MULTIPATH_NUM) " equal-cluster-length",
1597 "Forward packets over multiple paths\n"
1598 "iBGP-multipath\n"
1599 "Number of paths\n"
1600 "Match the cluster length\n")
1601
1602 DEFUN (no_bgp_maxpaths,
1603 no_bgp_maxpaths_cmd,
1604 "no maximum-paths [" CMD_RANGE_STR(1, MULTIPATH_NUM) "]",
1605 NO_STR
1606 "Forward packets over multiple paths\n"
1607 "Number of paths\n")
1608 {
1609 return bgp_maxpaths_config_vty(vty, BGP_PEER_EBGP, NULL, 0, 0);
1610 }
1611
1612 ALIAS_HIDDEN(no_bgp_maxpaths, no_bgp_maxpaths_hidden_cmd,
1613 "no maximum-paths [" CMD_RANGE_STR(1, MULTIPATH_NUM) "]", NO_STR
1614 "Forward packets over multiple paths\n"
1615 "Number of paths\n")
1616
1617 DEFUN (no_bgp_maxpaths_ibgp,
1618 no_bgp_maxpaths_ibgp_cmd,
1619 "no maximum-paths ibgp [" CMD_RANGE_STR(1, MULTIPATH_NUM) " [equal-cluster-length]]",
1620 NO_STR
1621 "Forward packets over multiple paths\n"
1622 "iBGP-multipath\n"
1623 "Number of paths\n"
1624 "Match the cluster length\n")
1625 {
1626 return bgp_maxpaths_config_vty(vty, BGP_PEER_IBGP, NULL, 0, 0);
1627 }
1628
1629 ALIAS_HIDDEN(no_bgp_maxpaths_ibgp, no_bgp_maxpaths_ibgp_hidden_cmd,
1630 "no maximum-paths ibgp [" CMD_RANGE_STR(
1631 1, MULTIPATH_NUM) " [equal-cluster-length]]",
1632 NO_STR
1633 "Forward packets over multiple paths\n"
1634 "iBGP-multipath\n"
1635 "Number of paths\n"
1636 "Match the cluster length\n")
1637
1638 void bgp_config_write_maxpaths(struct vty *vty, struct bgp *bgp, afi_t afi,
1639 safi_t safi)
1640 {
1641 if (bgp->maxpaths[afi][safi].maxpaths_ebgp != MULTIPATH_NUM) {
1642 vty_out(vty, " maximum-paths %d\n",
1643 bgp->maxpaths[afi][safi].maxpaths_ebgp);
1644 }
1645
1646 if (bgp->maxpaths[afi][safi].maxpaths_ibgp != MULTIPATH_NUM) {
1647 vty_out(vty, " maximum-paths ibgp %d",
1648 bgp->maxpaths[afi][safi].maxpaths_ibgp);
1649 if (CHECK_FLAG(bgp->maxpaths[afi][safi].ibgp_flags,
1650 BGP_FLAG_IBGP_MULTIPATH_SAME_CLUSTERLEN))
1651 vty_out(vty, " equal-cluster-length");
1652 vty_out(vty, "\n");
1653 }
1654 }
1655
1656 /* BGP timers. */
1657
1658 DEFUN (bgp_timers,
1659 bgp_timers_cmd,
1660 "timers bgp (0-65535) (0-65535)",
1661 "Adjust routing timers\n"
1662 "BGP timers\n"
1663 "Keepalive interval\n"
1664 "Holdtime\n")
1665 {
1666 VTY_DECLVAR_CONTEXT(bgp, bgp);
1667 int idx_number = 2;
1668 int idx_number_2 = 3;
1669 unsigned long keepalive = 0;
1670 unsigned long holdtime = 0;
1671
1672 keepalive = strtoul(argv[idx_number]->arg, NULL, 10);
1673 holdtime = strtoul(argv[idx_number_2]->arg, NULL, 10);
1674
1675 /* Holdtime value check. */
1676 if (holdtime < 3 && holdtime != 0) {
1677 vty_out(vty,
1678 "%% hold time value must be either 0 or greater than 3\n");
1679 return CMD_WARNING_CONFIG_FAILED;
1680 }
1681
1682 bgp_timers_set(bgp, keepalive, holdtime);
1683
1684 return CMD_SUCCESS;
1685 }
1686
1687 DEFUN (no_bgp_timers,
1688 no_bgp_timers_cmd,
1689 "no timers bgp [(0-65535) (0-65535)]",
1690 NO_STR
1691 "Adjust routing timers\n"
1692 "BGP timers\n"
1693 "Keepalive interval\n"
1694 "Holdtime\n")
1695 {
1696 VTY_DECLVAR_CONTEXT(bgp, bgp);
1697 bgp_timers_unset(bgp);
1698
1699 return CMD_SUCCESS;
1700 }
1701
1702
1703 DEFUN (bgp_client_to_client_reflection,
1704 bgp_client_to_client_reflection_cmd,
1705 "bgp client-to-client reflection",
1706 "BGP specific commands\n"
1707 "Configure client to client route reflection\n"
1708 "reflection of routes allowed\n")
1709 {
1710 VTY_DECLVAR_CONTEXT(bgp, bgp);
1711 bgp_flag_unset(bgp, BGP_FLAG_NO_CLIENT_TO_CLIENT);
1712 bgp_clear_star_soft_out(vty, bgp->name);
1713
1714 return CMD_SUCCESS;
1715 }
1716
1717 DEFUN (no_bgp_client_to_client_reflection,
1718 no_bgp_client_to_client_reflection_cmd,
1719 "no bgp client-to-client reflection",
1720 NO_STR
1721 "BGP specific commands\n"
1722 "Configure client to client route reflection\n"
1723 "reflection of routes allowed\n")
1724 {
1725 VTY_DECLVAR_CONTEXT(bgp, bgp);
1726 bgp_flag_set(bgp, BGP_FLAG_NO_CLIENT_TO_CLIENT);
1727 bgp_clear_star_soft_out(vty, bgp->name);
1728
1729 return CMD_SUCCESS;
1730 }
1731
1732 /* "bgp always-compare-med" configuration. */
1733 DEFUN (bgp_always_compare_med,
1734 bgp_always_compare_med_cmd,
1735 "bgp always-compare-med",
1736 "BGP specific commands\n"
1737 "Allow comparing MED from different neighbors\n")
1738 {
1739 VTY_DECLVAR_CONTEXT(bgp, bgp);
1740 bgp_flag_set(bgp, BGP_FLAG_ALWAYS_COMPARE_MED);
1741 bgp_recalculate_all_bestpaths(bgp);
1742
1743 return CMD_SUCCESS;
1744 }
1745
1746 DEFUN (no_bgp_always_compare_med,
1747 no_bgp_always_compare_med_cmd,
1748 "no bgp always-compare-med",
1749 NO_STR
1750 "BGP specific commands\n"
1751 "Allow comparing MED from different neighbors\n")
1752 {
1753 VTY_DECLVAR_CONTEXT(bgp, bgp);
1754 bgp_flag_unset(bgp, BGP_FLAG_ALWAYS_COMPARE_MED);
1755 bgp_recalculate_all_bestpaths(bgp);
1756
1757 return CMD_SUCCESS;
1758 }
1759
1760 /* "bgp deterministic-med" configuration. */
1761 DEFUN (bgp_deterministic_med,
1762 bgp_deterministic_med_cmd,
1763 "bgp deterministic-med",
1764 "BGP specific commands\n"
1765 "Pick the best-MED path among paths advertised from the neighboring AS\n")
1766 {
1767 VTY_DECLVAR_CONTEXT(bgp, bgp);
1768
1769 if (!bgp_flag_check(bgp, BGP_FLAG_DETERMINISTIC_MED)) {
1770 bgp_flag_set(bgp, BGP_FLAG_DETERMINISTIC_MED);
1771 bgp_recalculate_all_bestpaths(bgp);
1772 }
1773
1774 return CMD_SUCCESS;
1775 }
1776
1777 DEFUN (no_bgp_deterministic_med,
1778 no_bgp_deterministic_med_cmd,
1779 "no bgp deterministic-med",
1780 NO_STR
1781 "BGP specific commands\n"
1782 "Pick the best-MED path among paths advertised from the neighboring AS\n")
1783 {
1784 VTY_DECLVAR_CONTEXT(bgp, bgp);
1785 int bestpath_per_as_used;
1786 afi_t afi;
1787 safi_t safi;
1788 struct peer *peer;
1789 struct listnode *node, *nnode;
1790
1791 if (bgp_flag_check(bgp, BGP_FLAG_DETERMINISTIC_MED)) {
1792 bestpath_per_as_used = 0;
1793
1794 for (ALL_LIST_ELEMENTS(bgp->peer, node, nnode, peer)) {
1795 FOREACH_AFI_SAFI (afi, safi)
1796 if (CHECK_FLAG(
1797 peer->af_flags[afi][safi],
1798 PEER_FLAG_ADDPATH_TX_BESTPATH_PER_AS)) {
1799 bestpath_per_as_used = 1;
1800 break;
1801 }
1802
1803 if (bestpath_per_as_used)
1804 break;
1805 }
1806
1807 if (bestpath_per_as_used) {
1808 vty_out(vty,
1809 "bgp deterministic-med cannot be disabled while addpath-tx-bestpath-per-AS is in use\n");
1810 return CMD_WARNING_CONFIG_FAILED;
1811 } else {
1812 bgp_flag_unset(bgp, BGP_FLAG_DETERMINISTIC_MED);
1813 bgp_recalculate_all_bestpaths(bgp);
1814 }
1815 }
1816
1817 return CMD_SUCCESS;
1818 }
1819
1820 /* "bgp graceful-restart" configuration. */
1821 DEFUN (bgp_graceful_restart,
1822 bgp_graceful_restart_cmd,
1823 "bgp graceful-restart",
1824 "BGP specific commands\n"
1825 "Graceful restart capability parameters\n")
1826 {
1827 VTY_DECLVAR_CONTEXT(bgp, bgp);
1828 bgp_flag_set(bgp, BGP_FLAG_GRACEFUL_RESTART);
1829 return CMD_SUCCESS;
1830 }
1831
1832 DEFUN (no_bgp_graceful_restart,
1833 no_bgp_graceful_restart_cmd,
1834 "no bgp graceful-restart",
1835 NO_STR
1836 "BGP specific commands\n"
1837 "Graceful restart capability parameters\n")
1838 {
1839 VTY_DECLVAR_CONTEXT(bgp, bgp);
1840 bgp_flag_unset(bgp, BGP_FLAG_GRACEFUL_RESTART);
1841 return CMD_SUCCESS;
1842 }
1843
1844 DEFUN (bgp_graceful_restart_stalepath_time,
1845 bgp_graceful_restart_stalepath_time_cmd,
1846 "bgp graceful-restart stalepath-time (1-3600)",
1847 "BGP specific commands\n"
1848 "Graceful restart capability parameters\n"
1849 "Set the max time to hold onto restarting peer's stale paths\n"
1850 "Delay value (seconds)\n")
1851 {
1852 VTY_DECLVAR_CONTEXT(bgp, bgp);
1853 int idx_number = 3;
1854 uint32_t stalepath;
1855
1856 stalepath = strtoul(argv[idx_number]->arg, NULL, 10);
1857 bgp->stalepath_time = stalepath;
1858 return CMD_SUCCESS;
1859 }
1860
1861 DEFUN (bgp_graceful_restart_restart_time,
1862 bgp_graceful_restart_restart_time_cmd,
1863 "bgp graceful-restart restart-time (1-3600)",
1864 "BGP specific commands\n"
1865 "Graceful restart capability parameters\n"
1866 "Set the time to wait to delete stale routes before a BGP open message is received\n"
1867 "Delay value (seconds)\n")
1868 {
1869 VTY_DECLVAR_CONTEXT(bgp, bgp);
1870 int idx_number = 3;
1871 uint32_t restart;
1872
1873 restart = strtoul(argv[idx_number]->arg, NULL, 10);
1874 bgp->restart_time = restart;
1875 return CMD_SUCCESS;
1876 }
1877
1878 DEFUN (no_bgp_graceful_restart_stalepath_time,
1879 no_bgp_graceful_restart_stalepath_time_cmd,
1880 "no bgp graceful-restart stalepath-time [(1-3600)]",
1881 NO_STR
1882 "BGP specific commands\n"
1883 "Graceful restart capability parameters\n"
1884 "Set the max time to hold onto restarting peer's stale paths\n"
1885 "Delay value (seconds)\n")
1886 {
1887 VTY_DECLVAR_CONTEXT(bgp, bgp);
1888
1889 bgp->stalepath_time = BGP_DEFAULT_STALEPATH_TIME;
1890 return CMD_SUCCESS;
1891 }
1892
1893 DEFUN (no_bgp_graceful_restart_restart_time,
1894 no_bgp_graceful_restart_restart_time_cmd,
1895 "no bgp graceful-restart restart-time [(1-3600)]",
1896 NO_STR
1897 "BGP specific commands\n"
1898 "Graceful restart capability parameters\n"
1899 "Set the time to wait to delete stale routes before a BGP open message is received\n"
1900 "Delay value (seconds)\n")
1901 {
1902 VTY_DECLVAR_CONTEXT(bgp, bgp);
1903
1904 bgp->restart_time = BGP_DEFAULT_RESTART_TIME;
1905 return CMD_SUCCESS;
1906 }
1907
1908 DEFUN (bgp_graceful_restart_preserve_fw,
1909 bgp_graceful_restart_preserve_fw_cmd,
1910 "bgp graceful-restart preserve-fw-state",
1911 "BGP specific commands\n"
1912 "Graceful restart capability parameters\n"
1913 "Sets F-bit indication that fib is preserved while doing Graceful Restart\n")
1914 {
1915 VTY_DECLVAR_CONTEXT(bgp, bgp);
1916 bgp_flag_set(bgp, BGP_FLAG_GR_PRESERVE_FWD);
1917 return CMD_SUCCESS;
1918 }
1919
1920 DEFUN (no_bgp_graceful_restart_preserve_fw,
1921 no_bgp_graceful_restart_preserve_fw_cmd,
1922 "no bgp graceful-restart preserve-fw-state",
1923 NO_STR
1924 "BGP specific commands\n"
1925 "Graceful restart capability parameters\n"
1926 "Unsets F-bit indication that fib is preserved while doing Graceful Restart\n")
1927 {
1928 VTY_DECLVAR_CONTEXT(bgp, bgp);
1929 bgp_flag_unset(bgp, BGP_FLAG_GR_PRESERVE_FWD);
1930 return CMD_SUCCESS;
1931 }
1932
1933 static void bgp_redistribute_redo(struct bgp *bgp)
1934 {
1935 afi_t afi;
1936 int i;
1937 struct list *red_list;
1938 struct listnode *node;
1939 struct bgp_redist *red;
1940
1941 for (afi = AFI_IP; afi < AFI_MAX; afi++) {
1942 for (i = 0; i < ZEBRA_ROUTE_MAX; i++) {
1943
1944 red_list = bgp->redist[afi][i];
1945 if (!red_list)
1946 continue;
1947
1948 for (ALL_LIST_ELEMENTS_RO(red_list, node, red)) {
1949 bgp_redistribute_resend(bgp, afi, i,
1950 red->instance);
1951 }
1952 }
1953 }
1954 }
1955
1956 /* "bgp graceful-shutdown" configuration */
1957 DEFUN (bgp_graceful_shutdown,
1958 bgp_graceful_shutdown_cmd,
1959 "bgp graceful-shutdown",
1960 BGP_STR
1961 "Graceful shutdown parameters\n")
1962 {
1963 VTY_DECLVAR_CONTEXT(bgp, bgp);
1964
1965 if (!bgp_flag_check(bgp, BGP_FLAG_GRACEFUL_SHUTDOWN)) {
1966 bgp_flag_set(bgp, BGP_FLAG_GRACEFUL_SHUTDOWN);
1967 bgp_static_redo_import_check(bgp);
1968 bgp_redistribute_redo(bgp);
1969 bgp_clear_star_soft_out(vty, bgp->name);
1970 bgp_clear_star_soft_in(vty, bgp->name);
1971 }
1972
1973 return CMD_SUCCESS;
1974 }
1975
1976 DEFUN (no_bgp_graceful_shutdown,
1977 no_bgp_graceful_shutdown_cmd,
1978 "no bgp graceful-shutdown",
1979 NO_STR
1980 BGP_STR
1981 "Graceful shutdown parameters\n")
1982 {
1983 VTY_DECLVAR_CONTEXT(bgp, bgp);
1984
1985 if (bgp_flag_check(bgp, BGP_FLAG_GRACEFUL_SHUTDOWN)) {
1986 bgp_flag_unset(bgp, BGP_FLAG_GRACEFUL_SHUTDOWN);
1987 bgp_static_redo_import_check(bgp);
1988 bgp_redistribute_redo(bgp);
1989 bgp_clear_star_soft_out(vty, bgp->name);
1990 bgp_clear_star_soft_in(vty, bgp->name);
1991 }
1992
1993 return CMD_SUCCESS;
1994 }
1995
1996 /* "bgp fast-external-failover" configuration. */
1997 DEFUN (bgp_fast_external_failover,
1998 bgp_fast_external_failover_cmd,
1999 "bgp fast-external-failover",
2000 BGP_STR
2001 "Immediately reset session if a link to a directly connected external peer goes down\n")
2002 {
2003 VTY_DECLVAR_CONTEXT(bgp, bgp);
2004 bgp_flag_unset(bgp, BGP_FLAG_NO_FAST_EXT_FAILOVER);
2005 return CMD_SUCCESS;
2006 }
2007
2008 DEFUN (no_bgp_fast_external_failover,
2009 no_bgp_fast_external_failover_cmd,
2010 "no bgp fast-external-failover",
2011 NO_STR
2012 BGP_STR
2013 "Immediately reset session if a link to a directly connected external peer goes down\n")
2014 {
2015 VTY_DECLVAR_CONTEXT(bgp, bgp);
2016 bgp_flag_set(bgp, BGP_FLAG_NO_FAST_EXT_FAILOVER);
2017 return CMD_SUCCESS;
2018 }
2019
2020 /* "bgp enforce-first-as" configuration. */
2021 #if CONFDATE > 20180517
2022 CPP_NOTICE("bgpd: remove deprecated '[no] bgp enforce-first-as' commands")
2023 #endif
2024
2025 DEFUN_HIDDEN (bgp_enforce_first_as,
2026 bgp_enforce_first_as_cmd,
2027 "[no] bgp enforce-first-as",
2028 NO_STR
2029 BGP_STR
2030 "Enforce the first AS for EBGP routes\n")
2031 {
2032 VTY_DECLVAR_CONTEXT(bgp, bgp);
2033
2034 if (strmatch(argv[0]->text, "no"))
2035 bgp_flag_unset(bgp, BGP_FLAG_ENFORCE_FIRST_AS);
2036 else
2037 bgp_flag_set(bgp, BGP_FLAG_ENFORCE_FIRST_AS);
2038
2039 return CMD_SUCCESS;
2040 }
2041
2042 /* "bgp bestpath compare-routerid" configuration. */
2043 DEFUN (bgp_bestpath_compare_router_id,
2044 bgp_bestpath_compare_router_id_cmd,
2045 "bgp bestpath compare-routerid",
2046 "BGP specific commands\n"
2047 "Change the default bestpath selection\n"
2048 "Compare router-id for identical EBGP paths\n")
2049 {
2050 VTY_DECLVAR_CONTEXT(bgp, bgp);
2051 bgp_flag_set(bgp, BGP_FLAG_COMPARE_ROUTER_ID);
2052 bgp_recalculate_all_bestpaths(bgp);
2053
2054 return CMD_SUCCESS;
2055 }
2056
2057 DEFUN (no_bgp_bestpath_compare_router_id,
2058 no_bgp_bestpath_compare_router_id_cmd,
2059 "no bgp bestpath compare-routerid",
2060 NO_STR
2061 "BGP specific commands\n"
2062 "Change the default bestpath selection\n"
2063 "Compare router-id for identical EBGP paths\n")
2064 {
2065 VTY_DECLVAR_CONTEXT(bgp, bgp);
2066 bgp_flag_unset(bgp, BGP_FLAG_COMPARE_ROUTER_ID);
2067 bgp_recalculate_all_bestpaths(bgp);
2068
2069 return CMD_SUCCESS;
2070 }
2071
2072 /* "bgp bestpath as-path ignore" configuration. */
2073 DEFUN (bgp_bestpath_aspath_ignore,
2074 bgp_bestpath_aspath_ignore_cmd,
2075 "bgp bestpath as-path ignore",
2076 "BGP specific commands\n"
2077 "Change the default bestpath selection\n"
2078 "AS-path attribute\n"
2079 "Ignore as-path length in selecting a route\n")
2080 {
2081 VTY_DECLVAR_CONTEXT(bgp, bgp);
2082 bgp_flag_set(bgp, BGP_FLAG_ASPATH_IGNORE);
2083 bgp_recalculate_all_bestpaths(bgp);
2084
2085 return CMD_SUCCESS;
2086 }
2087
2088 DEFUN (no_bgp_bestpath_aspath_ignore,
2089 no_bgp_bestpath_aspath_ignore_cmd,
2090 "no bgp bestpath as-path ignore",
2091 NO_STR
2092 "BGP specific commands\n"
2093 "Change the default bestpath selection\n"
2094 "AS-path attribute\n"
2095 "Ignore as-path length in selecting a route\n")
2096 {
2097 VTY_DECLVAR_CONTEXT(bgp, bgp);
2098 bgp_flag_unset(bgp, BGP_FLAG_ASPATH_IGNORE);
2099 bgp_recalculate_all_bestpaths(bgp);
2100
2101 return CMD_SUCCESS;
2102 }
2103
2104 /* "bgp bestpath as-path confed" configuration. */
2105 DEFUN (bgp_bestpath_aspath_confed,
2106 bgp_bestpath_aspath_confed_cmd,
2107 "bgp bestpath as-path confed",
2108 "BGP specific commands\n"
2109 "Change the default bestpath selection\n"
2110 "AS-path attribute\n"
2111 "Compare path lengths including confederation sets & sequences in selecting a route\n")
2112 {
2113 VTY_DECLVAR_CONTEXT(bgp, bgp);
2114 bgp_flag_set(bgp, BGP_FLAG_ASPATH_CONFED);
2115 bgp_recalculate_all_bestpaths(bgp);
2116
2117 return CMD_SUCCESS;
2118 }
2119
2120 DEFUN (no_bgp_bestpath_aspath_confed,
2121 no_bgp_bestpath_aspath_confed_cmd,
2122 "no bgp bestpath as-path confed",
2123 NO_STR
2124 "BGP specific commands\n"
2125 "Change the default bestpath selection\n"
2126 "AS-path attribute\n"
2127 "Compare path lengths including confederation sets & sequences in selecting a route\n")
2128 {
2129 VTY_DECLVAR_CONTEXT(bgp, bgp);
2130 bgp_flag_unset(bgp, BGP_FLAG_ASPATH_CONFED);
2131 bgp_recalculate_all_bestpaths(bgp);
2132
2133 return CMD_SUCCESS;
2134 }
2135
2136 /* "bgp bestpath as-path multipath-relax" configuration. */
2137 DEFUN (bgp_bestpath_aspath_multipath_relax,
2138 bgp_bestpath_aspath_multipath_relax_cmd,
2139 "bgp bestpath as-path multipath-relax [<as-set|no-as-set>]",
2140 "BGP specific commands\n"
2141 "Change the default bestpath selection\n"
2142 "AS-path attribute\n"
2143 "Allow load sharing across routes that have different AS paths (but same length)\n"
2144 "Generate an AS_SET\n"
2145 "Do not generate an AS_SET\n")
2146 {
2147 VTY_DECLVAR_CONTEXT(bgp, bgp);
2148 int idx = 0;
2149 bgp_flag_set(bgp, BGP_FLAG_ASPATH_MULTIPATH_RELAX);
2150
2151 /* no-as-set is now the default behavior so we can silently
2152 * ignore it */
2153 if (argv_find(argv, argc, "as-set", &idx))
2154 bgp_flag_set(bgp, BGP_FLAG_MULTIPATH_RELAX_AS_SET);
2155 else
2156 bgp_flag_unset(bgp, BGP_FLAG_MULTIPATH_RELAX_AS_SET);
2157
2158 bgp_recalculate_all_bestpaths(bgp);
2159
2160 return CMD_SUCCESS;
2161 }
2162
2163 DEFUN (no_bgp_bestpath_aspath_multipath_relax,
2164 no_bgp_bestpath_aspath_multipath_relax_cmd,
2165 "no bgp bestpath as-path multipath-relax [<as-set|no-as-set>]",
2166 NO_STR
2167 "BGP specific commands\n"
2168 "Change the default bestpath selection\n"
2169 "AS-path attribute\n"
2170 "Allow load sharing across routes that have different AS paths (but same length)\n"
2171 "Generate an AS_SET\n"
2172 "Do not generate an AS_SET\n")
2173 {
2174 VTY_DECLVAR_CONTEXT(bgp, bgp);
2175 bgp_flag_unset(bgp, BGP_FLAG_ASPATH_MULTIPATH_RELAX);
2176 bgp_flag_unset(bgp, BGP_FLAG_MULTIPATH_RELAX_AS_SET);
2177 bgp_recalculate_all_bestpaths(bgp);
2178
2179 return CMD_SUCCESS;
2180 }
2181
2182 /* "bgp log-neighbor-changes" configuration. */
2183 DEFUN (bgp_log_neighbor_changes,
2184 bgp_log_neighbor_changes_cmd,
2185 "bgp log-neighbor-changes",
2186 "BGP specific commands\n"
2187 "Log neighbor up/down and reset reason\n")
2188 {
2189 VTY_DECLVAR_CONTEXT(bgp, bgp);
2190 bgp_flag_set(bgp, BGP_FLAG_LOG_NEIGHBOR_CHANGES);
2191 return CMD_SUCCESS;
2192 }
2193
2194 DEFUN (no_bgp_log_neighbor_changes,
2195 no_bgp_log_neighbor_changes_cmd,
2196 "no bgp log-neighbor-changes",
2197 NO_STR
2198 "BGP specific commands\n"
2199 "Log neighbor up/down and reset reason\n")
2200 {
2201 VTY_DECLVAR_CONTEXT(bgp, bgp);
2202 bgp_flag_unset(bgp, BGP_FLAG_LOG_NEIGHBOR_CHANGES);
2203 return CMD_SUCCESS;
2204 }
2205
2206 /* "bgp bestpath med" configuration. */
2207 DEFUN (bgp_bestpath_med,
2208 bgp_bestpath_med_cmd,
2209 "bgp bestpath med <confed [missing-as-worst]|missing-as-worst [confed]>",
2210 "BGP specific commands\n"
2211 "Change the default bestpath selection\n"
2212 "MED attribute\n"
2213 "Compare MED among confederation paths\n"
2214 "Treat missing MED as the least preferred one\n"
2215 "Treat missing MED as the least preferred one\n"
2216 "Compare MED among confederation paths\n")
2217 {
2218 VTY_DECLVAR_CONTEXT(bgp, bgp);
2219
2220 int idx = 0;
2221 if (argv_find(argv, argc, "confed", &idx))
2222 bgp_flag_set(bgp, BGP_FLAG_MED_CONFED);
2223 idx = 0;
2224 if (argv_find(argv, argc, "missing-as-worst", &idx))
2225 bgp_flag_set(bgp, BGP_FLAG_MED_MISSING_AS_WORST);
2226
2227 bgp_recalculate_all_bestpaths(bgp);
2228
2229 return CMD_SUCCESS;
2230 }
2231
2232 DEFUN (no_bgp_bestpath_med,
2233 no_bgp_bestpath_med_cmd,
2234 "no bgp bestpath med <confed [missing-as-worst]|missing-as-worst [confed]>",
2235 NO_STR
2236 "BGP specific commands\n"
2237 "Change the default bestpath selection\n"
2238 "MED attribute\n"
2239 "Compare MED among confederation paths\n"
2240 "Treat missing MED as the least preferred one\n"
2241 "Treat missing MED as the least preferred one\n"
2242 "Compare MED among confederation paths\n")
2243 {
2244 VTY_DECLVAR_CONTEXT(bgp, bgp);
2245
2246 int idx = 0;
2247 if (argv_find(argv, argc, "confed", &idx))
2248 bgp_flag_unset(bgp, BGP_FLAG_MED_CONFED);
2249 idx = 0;
2250 if (argv_find(argv, argc, "missing-as-worst", &idx))
2251 bgp_flag_unset(bgp, BGP_FLAG_MED_MISSING_AS_WORST);
2252
2253 bgp_recalculate_all_bestpaths(bgp);
2254
2255 return CMD_SUCCESS;
2256 }
2257
2258 /* "no bgp default ipv4-unicast". */
2259 DEFUN (no_bgp_default_ipv4_unicast,
2260 no_bgp_default_ipv4_unicast_cmd,
2261 "no bgp default ipv4-unicast",
2262 NO_STR
2263 "BGP specific commands\n"
2264 "Configure BGP defaults\n"
2265 "Activate ipv4-unicast for a peer by default\n")
2266 {
2267 VTY_DECLVAR_CONTEXT(bgp, bgp);
2268 bgp_flag_set(bgp, BGP_FLAG_NO_DEFAULT_IPV4);
2269 return CMD_SUCCESS;
2270 }
2271
2272 DEFUN (bgp_default_ipv4_unicast,
2273 bgp_default_ipv4_unicast_cmd,
2274 "bgp default ipv4-unicast",
2275 "BGP specific commands\n"
2276 "Configure BGP defaults\n"
2277 "Activate ipv4-unicast for a peer by default\n")
2278 {
2279 VTY_DECLVAR_CONTEXT(bgp, bgp);
2280 bgp_flag_unset(bgp, BGP_FLAG_NO_DEFAULT_IPV4);
2281 return CMD_SUCCESS;
2282 }
2283
2284 /* Display hostname in certain command outputs */
2285 DEFUN (bgp_default_show_hostname,
2286 bgp_default_show_hostname_cmd,
2287 "bgp default show-hostname",
2288 "BGP specific commands\n"
2289 "Configure BGP defaults\n"
2290 "Show hostname in certain command ouputs\n")
2291 {
2292 VTY_DECLVAR_CONTEXT(bgp, bgp);
2293 bgp_flag_set(bgp, BGP_FLAG_SHOW_HOSTNAME);
2294 return CMD_SUCCESS;
2295 }
2296
2297 DEFUN (no_bgp_default_show_hostname,
2298 no_bgp_default_show_hostname_cmd,
2299 "no bgp default show-hostname",
2300 NO_STR
2301 "BGP specific commands\n"
2302 "Configure BGP defaults\n"
2303 "Show hostname in certain command ouputs\n")
2304 {
2305 VTY_DECLVAR_CONTEXT(bgp, bgp);
2306 bgp_flag_unset(bgp, BGP_FLAG_SHOW_HOSTNAME);
2307 return CMD_SUCCESS;
2308 }
2309
2310 /* "bgp network import-check" configuration. */
2311 DEFUN (bgp_network_import_check,
2312 bgp_network_import_check_cmd,
2313 "bgp network import-check",
2314 "BGP specific commands\n"
2315 "BGP network command\n"
2316 "Check BGP network route exists in IGP\n")
2317 {
2318 VTY_DECLVAR_CONTEXT(bgp, bgp);
2319 if (!bgp_flag_check(bgp, BGP_FLAG_IMPORT_CHECK)) {
2320 bgp_flag_set(bgp, BGP_FLAG_IMPORT_CHECK);
2321 bgp_static_redo_import_check(bgp);
2322 }
2323
2324 return CMD_SUCCESS;
2325 }
2326
2327 ALIAS_HIDDEN(bgp_network_import_check, bgp_network_import_check_exact_cmd,
2328 "bgp network import-check exact",
2329 "BGP specific commands\n"
2330 "BGP network command\n"
2331 "Check BGP network route exists in IGP\n"
2332 "Match route precisely\n")
2333
2334 DEFUN (no_bgp_network_import_check,
2335 no_bgp_network_import_check_cmd,
2336 "no bgp network import-check",
2337 NO_STR
2338 "BGP specific commands\n"
2339 "BGP network command\n"
2340 "Check BGP network route exists in IGP\n")
2341 {
2342 VTY_DECLVAR_CONTEXT(bgp, bgp);
2343 if (bgp_flag_check(bgp, BGP_FLAG_IMPORT_CHECK)) {
2344 bgp_flag_unset(bgp, BGP_FLAG_IMPORT_CHECK);
2345 bgp_static_redo_import_check(bgp);
2346 }
2347
2348 return CMD_SUCCESS;
2349 }
2350
2351 DEFUN (bgp_default_local_preference,
2352 bgp_default_local_preference_cmd,
2353 "bgp default local-preference (0-4294967295)",
2354 "BGP specific commands\n"
2355 "Configure BGP defaults\n"
2356 "local preference (higher=more preferred)\n"
2357 "Configure default local preference value\n")
2358 {
2359 VTY_DECLVAR_CONTEXT(bgp, bgp);
2360 int idx_number = 3;
2361 uint32_t local_pref;
2362
2363 local_pref = strtoul(argv[idx_number]->arg, NULL, 10);
2364
2365 bgp_default_local_preference_set(bgp, local_pref);
2366 bgp_clear_star_soft_in(vty, bgp->name);
2367
2368 return CMD_SUCCESS;
2369 }
2370
2371 DEFUN (no_bgp_default_local_preference,
2372 no_bgp_default_local_preference_cmd,
2373 "no bgp default local-preference [(0-4294967295)]",
2374 NO_STR
2375 "BGP specific commands\n"
2376 "Configure BGP defaults\n"
2377 "local preference (higher=more preferred)\n"
2378 "Configure default local preference value\n")
2379 {
2380 VTY_DECLVAR_CONTEXT(bgp, bgp);
2381 bgp_default_local_preference_unset(bgp);
2382 bgp_clear_star_soft_in(vty, bgp->name);
2383
2384 return CMD_SUCCESS;
2385 }
2386
2387
2388 DEFUN (bgp_default_subgroup_pkt_queue_max,
2389 bgp_default_subgroup_pkt_queue_max_cmd,
2390 "bgp default subgroup-pkt-queue-max (20-100)",
2391 "BGP specific commands\n"
2392 "Configure BGP defaults\n"
2393 "subgroup-pkt-queue-max\n"
2394 "Configure subgroup packet queue max\n")
2395 {
2396 VTY_DECLVAR_CONTEXT(bgp, bgp);
2397 int idx_number = 3;
2398 uint32_t max_size;
2399
2400 max_size = strtoul(argv[idx_number]->arg, NULL, 10);
2401
2402 bgp_default_subgroup_pkt_queue_max_set(bgp, max_size);
2403
2404 return CMD_SUCCESS;
2405 }
2406
2407 DEFUN (no_bgp_default_subgroup_pkt_queue_max,
2408 no_bgp_default_subgroup_pkt_queue_max_cmd,
2409 "no bgp default subgroup-pkt-queue-max [(20-100)]",
2410 NO_STR
2411 "BGP specific commands\n"
2412 "Configure BGP defaults\n"
2413 "subgroup-pkt-queue-max\n"
2414 "Configure subgroup packet queue max\n")
2415 {
2416 VTY_DECLVAR_CONTEXT(bgp, bgp);
2417 bgp_default_subgroup_pkt_queue_max_unset(bgp);
2418 return CMD_SUCCESS;
2419 }
2420
2421
2422 DEFUN (bgp_rr_allow_outbound_policy,
2423 bgp_rr_allow_outbound_policy_cmd,
2424 "bgp route-reflector allow-outbound-policy",
2425 "BGP specific commands\n"
2426 "Allow modifications made by out route-map\n"
2427 "on ibgp neighbors\n")
2428 {
2429 VTY_DECLVAR_CONTEXT(bgp, bgp);
2430
2431 if (!bgp_flag_check(bgp, BGP_FLAG_RR_ALLOW_OUTBOUND_POLICY)) {
2432 bgp_flag_set(bgp, BGP_FLAG_RR_ALLOW_OUTBOUND_POLICY);
2433 update_group_announce_rrclients(bgp);
2434 bgp_clear_star_soft_out(vty, bgp->name);
2435 }
2436
2437 return CMD_SUCCESS;
2438 }
2439
2440 DEFUN (no_bgp_rr_allow_outbound_policy,
2441 no_bgp_rr_allow_outbound_policy_cmd,
2442 "no bgp route-reflector allow-outbound-policy",
2443 NO_STR
2444 "BGP specific commands\n"
2445 "Allow modifications made by out route-map\n"
2446 "on ibgp neighbors\n")
2447 {
2448 VTY_DECLVAR_CONTEXT(bgp, bgp);
2449
2450 if (bgp_flag_check(bgp, BGP_FLAG_RR_ALLOW_OUTBOUND_POLICY)) {
2451 bgp_flag_unset(bgp, BGP_FLAG_RR_ALLOW_OUTBOUND_POLICY);
2452 update_group_announce_rrclients(bgp);
2453 bgp_clear_star_soft_out(vty, bgp->name);
2454 }
2455
2456 return CMD_SUCCESS;
2457 }
2458
2459 DEFUN (bgp_listen_limit,
2460 bgp_listen_limit_cmd,
2461 "bgp listen limit (1-5000)",
2462 "BGP specific commands\n"
2463 "Configure BGP defaults\n"
2464 "maximum number of BGP Dynamic Neighbors that can be created\n"
2465 "Configure Dynamic Neighbors listen limit value\n")
2466 {
2467 VTY_DECLVAR_CONTEXT(bgp, bgp);
2468 int idx_number = 3;
2469 int listen_limit;
2470
2471 listen_limit = strtoul(argv[idx_number]->arg, NULL, 10);
2472
2473 bgp_listen_limit_set(bgp, listen_limit);
2474
2475 return CMD_SUCCESS;
2476 }
2477
2478 DEFUN (no_bgp_listen_limit,
2479 no_bgp_listen_limit_cmd,
2480 "no bgp listen limit [(1-5000)]",
2481 "BGP specific commands\n"
2482 "Configure BGP defaults\n"
2483 "unset maximum number of BGP Dynamic Neighbors that can be created\n"
2484 "Configure Dynamic Neighbors listen limit value to default\n"
2485 "Configure Dynamic Neighbors listen limit value\n")
2486 {
2487 VTY_DECLVAR_CONTEXT(bgp, bgp);
2488 bgp_listen_limit_unset(bgp);
2489 return CMD_SUCCESS;
2490 }
2491
2492
2493 /*
2494 * Check if this listen range is already configured. Check for exact
2495 * match or overlap based on input.
2496 */
2497 static struct peer_group *listen_range_exists(struct bgp *bgp,
2498 struct prefix *range, int exact)
2499 {
2500 struct listnode *node, *nnode;
2501 struct listnode *node1, *nnode1;
2502 struct peer_group *group;
2503 struct prefix *lr;
2504 afi_t afi;
2505 int match;
2506
2507 afi = family2afi(range->family);
2508 for (ALL_LIST_ELEMENTS(bgp->group, node, nnode, group)) {
2509 for (ALL_LIST_ELEMENTS(group->listen_range[afi], node1, nnode1,
2510 lr)) {
2511 if (exact)
2512 match = prefix_same(range, lr);
2513 else
2514 match = (prefix_match(range, lr)
2515 || prefix_match(lr, range));
2516 if (match)
2517 return group;
2518 }
2519 }
2520
2521 return NULL;
2522 }
2523
2524 DEFUN (bgp_listen_range,
2525 bgp_listen_range_cmd,
2526 "bgp listen range <A.B.C.D/M|X:X::X:X/M> peer-group WORD",
2527 "BGP specific commands\n"
2528 "Configure BGP dynamic neighbors listen range\n"
2529 "Configure BGP dynamic neighbors listen range\n"
2530 NEIGHBOR_ADDR_STR
2531 "Member of the peer-group\n"
2532 "Peer-group name\n")
2533 {
2534 VTY_DECLVAR_CONTEXT(bgp, bgp);
2535 struct prefix range;
2536 struct peer_group *group, *existing_group;
2537 afi_t afi;
2538 int ret;
2539 int idx = 0;
2540
2541 argv_find(argv, argc, "A.B.C.D/M", &idx);
2542 argv_find(argv, argc, "X:X::X:X/M", &idx);
2543 char *prefix = argv[idx]->arg;
2544 argv_find(argv, argc, "WORD", &idx);
2545 char *peergroup = argv[idx]->arg;
2546
2547 /* Convert IP prefix string to struct prefix. */
2548 ret = str2prefix(prefix, &range);
2549 if (!ret) {
2550 vty_out(vty, "%% Malformed listen range\n");
2551 return CMD_WARNING_CONFIG_FAILED;
2552 }
2553
2554 afi = family2afi(range.family);
2555
2556 if (afi == AFI_IP6 && IN6_IS_ADDR_LINKLOCAL(&range.u.prefix6)) {
2557 vty_out(vty,
2558 "%% Malformed listen range (link-local address)\n");
2559 return CMD_WARNING_CONFIG_FAILED;
2560 }
2561
2562 apply_mask(&range);
2563
2564 /* Check if same listen range is already configured. */
2565 existing_group = listen_range_exists(bgp, &range, 1);
2566 if (existing_group) {
2567 if (strcmp(existing_group->name, peergroup) == 0)
2568 return CMD_SUCCESS;
2569 else {
2570 vty_out(vty,
2571 "%% Same listen range is attached to peer-group %s\n",
2572 existing_group->name);
2573 return CMD_WARNING_CONFIG_FAILED;
2574 }
2575 }
2576
2577 /* Check if an overlapping listen range exists. */
2578 if (listen_range_exists(bgp, &range, 0)) {
2579 vty_out(vty,
2580 "%% Listen range overlaps with existing listen range\n");
2581 return CMD_WARNING_CONFIG_FAILED;
2582 }
2583
2584 group = peer_group_lookup(bgp, peergroup);
2585 if (!group) {
2586 vty_out(vty, "%% Configure the peer-group first\n");
2587 return CMD_WARNING_CONFIG_FAILED;
2588 }
2589
2590 ret = peer_group_listen_range_add(group, &range);
2591 return bgp_vty_return(vty, ret);
2592 }
2593
2594 DEFUN (no_bgp_listen_range,
2595 no_bgp_listen_range_cmd,
2596 "no bgp listen range <A.B.C.D/M|X:X::X:X/M> peer-group WORD",
2597 NO_STR
2598 "BGP specific commands\n"
2599 "Unconfigure BGP dynamic neighbors listen range\n"
2600 "Unconfigure BGP dynamic neighbors listen range\n"
2601 NEIGHBOR_ADDR_STR
2602 "Member of the peer-group\n"
2603 "Peer-group name\n")
2604 {
2605 VTY_DECLVAR_CONTEXT(bgp, bgp);
2606 struct prefix range;
2607 struct peer_group *group;
2608 afi_t afi;
2609 int ret;
2610 int idx = 0;
2611
2612 argv_find(argv, argc, "A.B.C.D/M", &idx);
2613 argv_find(argv, argc, "X:X::X:X/M", &idx);
2614 char *prefix = argv[idx]->arg;
2615 argv_find(argv, argc, "WORD", &idx);
2616 char *peergroup = argv[idx]->arg;
2617
2618 /* Convert IP prefix string to struct prefix. */
2619 ret = str2prefix(prefix, &range);
2620 if (!ret) {
2621 vty_out(vty, "%% Malformed listen range\n");
2622 return CMD_WARNING_CONFIG_FAILED;
2623 }
2624
2625 afi = family2afi(range.family);
2626
2627 if (afi == AFI_IP6 && IN6_IS_ADDR_LINKLOCAL(&range.u.prefix6)) {
2628 vty_out(vty,
2629 "%% Malformed listen range (link-local address)\n");
2630 return CMD_WARNING_CONFIG_FAILED;
2631 }
2632
2633 apply_mask(&range);
2634
2635 group = peer_group_lookup(bgp, peergroup);
2636 if (!group) {
2637 vty_out(vty, "%% Peer-group does not exist\n");
2638 return CMD_WARNING_CONFIG_FAILED;
2639 }
2640
2641 ret = peer_group_listen_range_del(group, &range);
2642 return bgp_vty_return(vty, ret);
2643 }
2644
2645 void bgp_config_write_listen(struct vty *vty, struct bgp *bgp)
2646 {
2647 struct peer_group *group;
2648 struct listnode *node, *nnode, *rnode, *nrnode;
2649 struct prefix *range;
2650 afi_t afi;
2651 char buf[PREFIX2STR_BUFFER];
2652
2653 if (bgp->dynamic_neighbors_limit != BGP_DYNAMIC_NEIGHBORS_LIMIT_DEFAULT)
2654 vty_out(vty, " bgp listen limit %d\n",
2655 bgp->dynamic_neighbors_limit);
2656
2657 for (ALL_LIST_ELEMENTS(bgp->group, node, nnode, group)) {
2658 for (afi = AFI_IP; afi < AFI_MAX; afi++) {
2659 for (ALL_LIST_ELEMENTS(group->listen_range[afi], rnode,
2660 nrnode, range)) {
2661 prefix2str(range, buf, sizeof(buf));
2662 vty_out(vty,
2663 " bgp listen range %s peer-group %s\n",
2664 buf, group->name);
2665 }
2666 }
2667 }
2668 }
2669
2670
2671 DEFUN (bgp_disable_connected_route_check,
2672 bgp_disable_connected_route_check_cmd,
2673 "bgp disable-ebgp-connected-route-check",
2674 "BGP specific commands\n"
2675 "Disable checking if nexthop is connected on ebgp sessions\n")
2676 {
2677 VTY_DECLVAR_CONTEXT(bgp, bgp);
2678 bgp_flag_set(bgp, BGP_FLAG_DISABLE_NH_CONNECTED_CHK);
2679 bgp_clear_star_soft_in(vty, bgp->name);
2680
2681 return CMD_SUCCESS;
2682 }
2683
2684 DEFUN (no_bgp_disable_connected_route_check,
2685 no_bgp_disable_connected_route_check_cmd,
2686 "no bgp disable-ebgp-connected-route-check",
2687 NO_STR
2688 "BGP specific commands\n"
2689 "Disable checking if nexthop is connected on ebgp sessions\n")
2690 {
2691 VTY_DECLVAR_CONTEXT(bgp, bgp);
2692 bgp_flag_unset(bgp, BGP_FLAG_DISABLE_NH_CONNECTED_CHK);
2693 bgp_clear_star_soft_in(vty, bgp->name);
2694
2695 return CMD_SUCCESS;
2696 }
2697
2698
2699 static int peer_remote_as_vty(struct vty *vty, const char *peer_str,
2700 const char *as_str, afi_t afi, safi_t safi)
2701 {
2702 VTY_DECLVAR_CONTEXT(bgp, bgp);
2703 int ret;
2704 as_t as;
2705 int as_type = AS_SPECIFIED;
2706 union sockunion su;
2707
2708 if (as_str[0] == 'i') {
2709 as = 0;
2710 as_type = AS_INTERNAL;
2711 } else if (as_str[0] == 'e') {
2712 as = 0;
2713 as_type = AS_EXTERNAL;
2714 } else {
2715 /* Get AS number. */
2716 as = strtoul(as_str, NULL, 10);
2717 }
2718
2719 /* If peer is peer group, call proper function. */
2720 ret = str2sockunion(peer_str, &su);
2721 if (ret < 0) {
2722 /* Check for peer by interface */
2723 ret = peer_remote_as(bgp, NULL, peer_str, &as, as_type, afi,
2724 safi);
2725 if (ret < 0) {
2726 ret = peer_group_remote_as(bgp, peer_str, &as, as_type);
2727 if (ret < 0) {
2728 vty_out(vty,
2729 "%% Create the peer-group or interface first\n");
2730 return CMD_WARNING_CONFIG_FAILED;
2731 }
2732 return CMD_SUCCESS;
2733 }
2734 } else {
2735 if (peer_address_self_check(bgp, &su)) {
2736 vty_out(vty,
2737 "%% Can not configure the local system as neighbor\n");
2738 return CMD_WARNING_CONFIG_FAILED;
2739 }
2740 ret = peer_remote_as(bgp, &su, NULL, &as, as_type, afi, safi);
2741 }
2742
2743 /* This peer belongs to peer group. */
2744 switch (ret) {
2745 case BGP_ERR_PEER_GROUP_MEMBER:
2746 vty_out(vty,
2747 "%% Peer-group AS %u. Cannot configure remote-as for member\n",
2748 as);
2749 return CMD_WARNING_CONFIG_FAILED;
2750 case BGP_ERR_PEER_GROUP_PEER_TYPE_DIFFERENT:
2751 vty_out(vty,
2752 "%% The AS# can not be changed from %u to %s, peer-group members must be all internal or all external\n",
2753 as, as_str);
2754 return CMD_WARNING_CONFIG_FAILED;
2755 }
2756 return bgp_vty_return(vty, ret);
2757 }
2758
2759 DEFUN (bgp_default_shutdown,
2760 bgp_default_shutdown_cmd,
2761 "[no] bgp default shutdown",
2762 NO_STR
2763 BGP_STR
2764 "Configure BGP defaults\n"
2765 "Apply administrative shutdown to newly configured peers\n")
2766 {
2767 VTY_DECLVAR_CONTEXT(bgp, bgp);
2768 bgp->autoshutdown = !strmatch(argv[0]->text, "no");
2769 return CMD_SUCCESS;
2770 }
2771
2772 DEFUN (neighbor_remote_as,
2773 neighbor_remote_as_cmd,
2774 "neighbor <A.B.C.D|X:X::X:X|WORD> remote-as <(1-4294967295)|internal|external>",
2775 NEIGHBOR_STR
2776 NEIGHBOR_ADDR_STR2
2777 "Specify a BGP neighbor\n"
2778 AS_STR
2779 "Internal BGP peer\n"
2780 "External BGP peer\n")
2781 {
2782 int idx_peer = 1;
2783 int idx_remote_as = 3;
2784 return peer_remote_as_vty(vty, argv[idx_peer]->arg,
2785 argv[idx_remote_as]->arg, AFI_IP,
2786 SAFI_UNICAST);
2787 }
2788
2789 static int peer_conf_interface_get(struct vty *vty, const char *conf_if,
2790 afi_t afi, safi_t safi, int v6only,
2791 const char *peer_group_name,
2792 const char *as_str)
2793 {
2794 VTY_DECLVAR_CONTEXT(bgp, bgp);
2795 as_t as = 0;
2796 int as_type = AS_UNSPECIFIED;
2797 struct peer *peer;
2798 struct peer_group *group;
2799 int ret = 0;
2800 union sockunion su;
2801
2802 group = peer_group_lookup(bgp, conf_if);
2803
2804 if (group) {
2805 vty_out(vty, "%% Name conflict with peer-group \n");
2806 return CMD_WARNING_CONFIG_FAILED;
2807 }
2808
2809 if (as_str) {
2810 if (as_str[0] == 'i') {
2811 as_type = AS_INTERNAL;
2812 } else if (as_str[0] == 'e') {
2813 as_type = AS_EXTERNAL;
2814 } else {
2815 /* Get AS number. */
2816 as = strtoul(as_str, NULL, 10);
2817 as_type = AS_SPECIFIED;
2818 }
2819 }
2820
2821 peer = peer_lookup_by_conf_if(bgp, conf_if);
2822 if (peer) {
2823 if (as_str)
2824 ret = peer_remote_as(bgp, &su, conf_if, &as, as_type,
2825 afi, safi);
2826 } else {
2827 if (bgp_flag_check(bgp, BGP_FLAG_NO_DEFAULT_IPV4)
2828 && afi == AFI_IP && safi == SAFI_UNICAST)
2829 peer = peer_create(NULL, conf_if, bgp, bgp->as, as,
2830 as_type, 0, 0, NULL);
2831 else
2832 peer = peer_create(NULL, conf_if, bgp, bgp->as, as,
2833 as_type, afi, safi, NULL);
2834
2835 if (!peer) {
2836 vty_out(vty, "%% BGP failed to create peer\n");
2837 return CMD_WARNING_CONFIG_FAILED;
2838 }
2839
2840 if (v6only)
2841 peer_flag_set(peer, PEER_FLAG_IFPEER_V6ONLY);
2842
2843 /* Request zebra to initiate IPv6 RAs on this interface. We do
2844 * this
2845 * any unnumbered peer in order to not worry about run-time
2846 * transitions
2847 * (e.g., peering is initially IPv4, but the IPv4 /30 or /31
2848 * address
2849 * gets deleted later etc.)
2850 */
2851 if (peer->ifp)
2852 bgp_zebra_initiate_radv(bgp, peer);
2853 }
2854
2855 if ((v6only && !CHECK_FLAG(peer->flags, PEER_FLAG_IFPEER_V6ONLY))
2856 || (!v6only && CHECK_FLAG(peer->flags, PEER_FLAG_IFPEER_V6ONLY))) {
2857 if (v6only)
2858 peer_flag_set(peer, PEER_FLAG_IFPEER_V6ONLY);
2859 else
2860 peer_flag_unset(peer, PEER_FLAG_IFPEER_V6ONLY);
2861
2862 /* v6only flag changed. Reset bgp seesion */
2863 if (BGP_IS_VALID_STATE_FOR_NOTIF(peer->status)) {
2864 peer->last_reset = PEER_DOWN_V6ONLY_CHANGE;
2865 bgp_notify_send(peer, BGP_NOTIFY_CEASE,
2866 BGP_NOTIFY_CEASE_CONFIG_CHANGE);
2867 } else
2868 bgp_session_reset(peer);
2869 }
2870
2871 if (!CHECK_FLAG(peer->flags_invert, PEER_FLAG_CAPABILITY_ENHE)) {
2872 SET_FLAG(peer->flags, PEER_FLAG_CAPABILITY_ENHE);
2873 SET_FLAG(peer->flags_invert, PEER_FLAG_CAPABILITY_ENHE);
2874 UNSET_FLAG(peer->flags_override, PEER_FLAG_CAPABILITY_ENHE);
2875 }
2876
2877 if (peer_group_name) {
2878 group = peer_group_lookup(bgp, peer_group_name);
2879 if (!group) {
2880 vty_out(vty, "%% Configure the peer-group first\n");
2881 return CMD_WARNING_CONFIG_FAILED;
2882 }
2883
2884 ret = peer_group_bind(bgp, &su, peer, group, &as);
2885 }
2886
2887 return bgp_vty_return(vty, ret);
2888 }
2889
2890 DEFUN (neighbor_interface_config,
2891 neighbor_interface_config_cmd,
2892 "neighbor WORD interface [peer-group WORD]",
2893 NEIGHBOR_STR
2894 "Interface name or neighbor tag\n"
2895 "Enable BGP on interface\n"
2896 "Member of the peer-group\n"
2897 "Peer-group name\n")
2898 {
2899 int idx_word = 1;
2900 int idx_peer_group_word = 4;
2901
2902 if (argc > idx_peer_group_word)
2903 return peer_conf_interface_get(
2904 vty, argv[idx_word]->arg, AFI_IP, SAFI_UNICAST, 0,
2905 argv[idx_peer_group_word]->arg, NULL);
2906 else
2907 return peer_conf_interface_get(vty, argv[idx_word]->arg, AFI_IP,
2908 SAFI_UNICAST, 0, NULL, NULL);
2909 }
2910
2911 DEFUN (neighbor_interface_config_v6only,
2912 neighbor_interface_config_v6only_cmd,
2913 "neighbor WORD interface v6only [peer-group WORD]",
2914 NEIGHBOR_STR
2915 "Interface name or neighbor tag\n"
2916 "Enable BGP on interface\n"
2917 "Enable BGP with v6 link-local only\n"
2918 "Member of the peer-group\n"
2919 "Peer-group name\n")
2920 {
2921 int idx_word = 1;
2922 int idx_peer_group_word = 5;
2923
2924 if (argc > idx_peer_group_word)
2925 return peer_conf_interface_get(
2926 vty, argv[idx_word]->arg, AFI_IP, SAFI_UNICAST, 1,
2927 argv[idx_peer_group_word]->arg, NULL);
2928
2929 return peer_conf_interface_get(vty, argv[idx_word]->arg, AFI_IP,
2930 SAFI_UNICAST, 1, NULL, NULL);
2931 }
2932
2933
2934 DEFUN (neighbor_interface_config_remote_as,
2935 neighbor_interface_config_remote_as_cmd,
2936 "neighbor WORD interface remote-as <(1-4294967295)|internal|external>",
2937 NEIGHBOR_STR
2938 "Interface name or neighbor tag\n"
2939 "Enable BGP on interface\n"
2940 "Specify a BGP neighbor\n"
2941 AS_STR
2942 "Internal BGP peer\n"
2943 "External BGP peer\n")
2944 {
2945 int idx_word = 1;
2946 int idx_remote_as = 4;
2947 return peer_conf_interface_get(vty, argv[idx_word]->arg, AFI_IP,
2948 SAFI_UNICAST, 0, NULL,
2949 argv[idx_remote_as]->arg);
2950 }
2951
2952 DEFUN (neighbor_interface_v6only_config_remote_as,
2953 neighbor_interface_v6only_config_remote_as_cmd,
2954 "neighbor WORD interface v6only remote-as <(1-4294967295)|internal|external>",
2955 NEIGHBOR_STR
2956 "Interface name or neighbor tag\n"
2957 "Enable BGP with v6 link-local only\n"
2958 "Enable BGP on interface\n"
2959 "Specify a BGP neighbor\n"
2960 AS_STR
2961 "Internal BGP peer\n"
2962 "External BGP peer\n")
2963 {
2964 int idx_word = 1;
2965 int idx_remote_as = 5;
2966 return peer_conf_interface_get(vty, argv[idx_word]->arg, AFI_IP,
2967 SAFI_UNICAST, 1, NULL,
2968 argv[idx_remote_as]->arg);
2969 }
2970
2971 DEFUN (neighbor_peer_group,
2972 neighbor_peer_group_cmd,
2973 "neighbor WORD peer-group",
2974 NEIGHBOR_STR
2975 "Interface name or neighbor tag\n"
2976 "Configure peer-group\n")
2977 {
2978 VTY_DECLVAR_CONTEXT(bgp, bgp);
2979 int idx_word = 1;
2980 struct peer *peer;
2981 struct peer_group *group;
2982
2983 peer = peer_lookup_by_conf_if(bgp, argv[idx_word]->arg);
2984 if (peer) {
2985 vty_out(vty, "%% Name conflict with interface: \n");
2986 return CMD_WARNING_CONFIG_FAILED;
2987 }
2988
2989 group = peer_group_get(bgp, argv[idx_word]->arg);
2990 if (!group) {
2991 vty_out(vty, "%% BGP failed to find or create peer-group\n");
2992 return CMD_WARNING_CONFIG_FAILED;
2993 }
2994
2995 return CMD_SUCCESS;
2996 }
2997
2998 DEFUN (no_neighbor,
2999 no_neighbor_cmd,
3000 "no neighbor <WORD|<A.B.C.D|X:X::X:X> [remote-as <(1-4294967295)|internal|external>]>",
3001 NO_STR
3002 NEIGHBOR_STR
3003 NEIGHBOR_ADDR_STR2
3004 "Specify a BGP neighbor\n"
3005 AS_STR
3006 "Internal BGP peer\n"
3007 "External BGP peer\n")
3008 {
3009 VTY_DECLVAR_CONTEXT(bgp, bgp);
3010 int idx_peer = 2;
3011 int ret;
3012 union sockunion su;
3013 struct peer_group *group;
3014 struct peer *peer;
3015 struct peer *other;
3016
3017 ret = str2sockunion(argv[idx_peer]->arg, &su);
3018 if (ret < 0) {
3019 /* look up for neighbor by interface name config. */
3020 peer = peer_lookup_by_conf_if(bgp, argv[idx_peer]->arg);
3021 if (peer) {
3022 /* Request zebra to terminate IPv6 RAs on this
3023 * interface. */
3024 if (peer->ifp)
3025 bgp_zebra_terminate_radv(peer->bgp, peer);
3026 peer_delete(peer);
3027 return CMD_SUCCESS;
3028 }
3029
3030 group = peer_group_lookup(bgp, argv[idx_peer]->arg);
3031 if (group)
3032 peer_group_delete(group);
3033 else {
3034 vty_out(vty, "%% Create the peer-group first\n");
3035 return CMD_WARNING_CONFIG_FAILED;
3036 }
3037 } else {
3038 peer = peer_lookup(bgp, &su);
3039 if (peer) {
3040 if (peer_dynamic_neighbor(peer)) {
3041 vty_out(vty,
3042 "%% Operation not allowed on a dynamic neighbor\n");
3043 return CMD_WARNING_CONFIG_FAILED;
3044 }
3045
3046 other = peer->doppelganger;
3047 peer_delete(peer);
3048 if (other && other->status != Deleted)
3049 peer_delete(other);
3050 }
3051 }
3052
3053 return CMD_SUCCESS;
3054 }
3055
3056 DEFUN (no_neighbor_interface_config,
3057 no_neighbor_interface_config_cmd,
3058 "no neighbor WORD interface [v6only] [peer-group WORD] [remote-as <(1-4294967295)|internal|external>]",
3059 NO_STR
3060 NEIGHBOR_STR
3061 "Interface name\n"
3062 "Configure BGP on interface\n"
3063 "Enable BGP with v6 link-local only\n"
3064 "Member of the peer-group\n"
3065 "Peer-group name\n"
3066 "Specify a BGP neighbor\n"
3067 AS_STR
3068 "Internal BGP peer\n"
3069 "External BGP peer\n")
3070 {
3071 VTY_DECLVAR_CONTEXT(bgp, bgp);
3072 int idx_word = 2;
3073 struct peer *peer;
3074
3075 /* look up for neighbor by interface name config. */
3076 peer = peer_lookup_by_conf_if(bgp, argv[idx_word]->arg);
3077 if (peer) {
3078 /* Request zebra to terminate IPv6 RAs on this interface. */
3079 if (peer->ifp)
3080 bgp_zebra_terminate_radv(peer->bgp, peer);
3081 peer_delete(peer);
3082 } else {
3083 vty_out(vty, "%% Create the bgp interface first\n");
3084 return CMD_WARNING_CONFIG_FAILED;
3085 }
3086 return CMD_SUCCESS;
3087 }
3088
3089 DEFUN (no_neighbor_peer_group,
3090 no_neighbor_peer_group_cmd,
3091 "no neighbor WORD peer-group",
3092 NO_STR
3093 NEIGHBOR_STR
3094 "Neighbor tag\n"
3095 "Configure peer-group\n")
3096 {
3097 VTY_DECLVAR_CONTEXT(bgp, bgp);
3098 int idx_word = 2;
3099 struct peer_group *group;
3100
3101 group = peer_group_lookup(bgp, argv[idx_word]->arg);
3102 if (group)
3103 peer_group_delete(group);
3104 else {
3105 vty_out(vty, "%% Create the peer-group first\n");
3106 return CMD_WARNING_CONFIG_FAILED;
3107 }
3108 return CMD_SUCCESS;
3109 }
3110
3111 DEFUN (no_neighbor_interface_peer_group_remote_as,
3112 no_neighbor_interface_peer_group_remote_as_cmd,
3113 "no neighbor WORD remote-as <(1-4294967295)|internal|external>",
3114 NO_STR
3115 NEIGHBOR_STR
3116 "Interface name or neighbor tag\n"
3117 "Specify a BGP neighbor\n"
3118 AS_STR
3119 "Internal BGP peer\n"
3120 "External BGP peer\n")
3121 {
3122 VTY_DECLVAR_CONTEXT(bgp, bgp);
3123 int idx_word = 2;
3124 struct peer_group *group;
3125 struct peer *peer;
3126
3127 /* look up for neighbor by interface name config. */
3128 peer = peer_lookup_by_conf_if(bgp, argv[idx_word]->arg);
3129 if (peer) {
3130 peer_as_change(peer, 0, AS_SPECIFIED);
3131 return CMD_SUCCESS;
3132 }
3133
3134 group = peer_group_lookup(bgp, argv[idx_word]->arg);
3135 if (group)
3136 peer_group_remote_as_delete(group);
3137 else {
3138 vty_out(vty, "%% Create the peer-group or interface first\n");
3139 return CMD_WARNING_CONFIG_FAILED;
3140 }
3141 return CMD_SUCCESS;
3142 }
3143
3144 DEFUN (neighbor_local_as,
3145 neighbor_local_as_cmd,
3146 "neighbor <A.B.C.D|X:X::X:X|WORD> local-as (1-4294967295)",
3147 NEIGHBOR_STR
3148 NEIGHBOR_ADDR_STR2
3149 "Specify a local-as number\n"
3150 "AS number used as local AS\n")
3151 {
3152 int idx_peer = 1;
3153 int idx_number = 3;
3154 struct peer *peer;
3155 int ret;
3156 as_t as;
3157
3158 peer = peer_and_group_lookup_vty(vty, argv[idx_peer]->arg);
3159 if (!peer)
3160 return CMD_WARNING_CONFIG_FAILED;
3161
3162 as = strtoul(argv[idx_number]->arg, NULL, 10);
3163 ret = peer_local_as_set(peer, as, 0, 0);
3164 return bgp_vty_return(vty, ret);
3165 }
3166
3167 DEFUN (neighbor_local_as_no_prepend,
3168 neighbor_local_as_no_prepend_cmd,
3169 "neighbor <A.B.C.D|X:X::X:X|WORD> local-as (1-4294967295) no-prepend",
3170 NEIGHBOR_STR
3171 NEIGHBOR_ADDR_STR2
3172 "Specify a local-as number\n"
3173 "AS number used as local AS\n"
3174 "Do not prepend local-as to updates from ebgp peers\n")
3175 {
3176 int idx_peer = 1;
3177 int idx_number = 3;
3178 struct peer *peer;
3179 int ret;
3180 as_t as;
3181
3182 peer = peer_and_group_lookup_vty(vty, argv[idx_peer]->arg);
3183 if (!peer)
3184 return CMD_WARNING_CONFIG_FAILED;
3185
3186 as = strtoul(argv[idx_number]->arg, NULL, 10);
3187 ret = peer_local_as_set(peer, as, 1, 0);
3188 return bgp_vty_return(vty, ret);
3189 }
3190
3191 DEFUN (neighbor_local_as_no_prepend_replace_as,
3192 neighbor_local_as_no_prepend_replace_as_cmd,
3193 "neighbor <A.B.C.D|X:X::X:X|WORD> local-as (1-4294967295) no-prepend replace-as",
3194 NEIGHBOR_STR
3195 NEIGHBOR_ADDR_STR2
3196 "Specify a local-as number\n"
3197 "AS number used as local AS\n"
3198 "Do not prepend local-as to updates from ebgp peers\n"
3199 "Do not prepend local-as to updates from ibgp peers\n")
3200 {
3201 int idx_peer = 1;
3202 int idx_number = 3;
3203 struct peer *peer;
3204 int ret;
3205 as_t as;
3206
3207 peer = peer_and_group_lookup_vty(vty, argv[idx_peer]->arg);
3208 if (!peer)
3209 return CMD_WARNING_CONFIG_FAILED;
3210
3211 as = strtoul(argv[idx_number]->arg, NULL, 10);
3212 ret = peer_local_as_set(peer, as, 1, 1);
3213 return bgp_vty_return(vty, ret);
3214 }
3215
3216 DEFUN (no_neighbor_local_as,
3217 no_neighbor_local_as_cmd,
3218 "no neighbor <A.B.C.D|X:X::X:X|WORD> local-as [(1-4294967295) [no-prepend [replace-as]]]",
3219 NO_STR
3220 NEIGHBOR_STR
3221 NEIGHBOR_ADDR_STR2
3222 "Specify a local-as number\n"
3223 "AS number used as local AS\n"
3224 "Do not prepend local-as to updates from ebgp peers\n"
3225 "Do not prepend local-as to updates from ibgp peers\n")
3226 {
3227 int idx_peer = 2;
3228 struct peer *peer;
3229 int ret;
3230
3231 peer = peer_and_group_lookup_vty(vty, argv[idx_peer]->arg);
3232 if (!peer)
3233 return CMD_WARNING_CONFIG_FAILED;
3234
3235 ret = peer_local_as_unset(peer);
3236 return bgp_vty_return(vty, ret);
3237 }
3238
3239
3240 DEFUN (neighbor_solo,
3241 neighbor_solo_cmd,
3242 "neighbor <A.B.C.D|X:X::X:X|WORD> solo",
3243 NEIGHBOR_STR
3244 NEIGHBOR_ADDR_STR2
3245 "Solo peer - part of its own update group\n")
3246 {
3247 int idx_peer = 1;
3248 struct peer *peer;
3249 int ret;
3250
3251 peer = peer_and_group_lookup_vty(vty, argv[idx_peer]->arg);
3252 if (!peer)
3253 return CMD_WARNING_CONFIG_FAILED;
3254
3255 ret = update_group_adjust_soloness(peer, 1);
3256 return bgp_vty_return(vty, ret);
3257 }
3258
3259 DEFUN (no_neighbor_solo,
3260 no_neighbor_solo_cmd,
3261 "no neighbor <A.B.C.D|X:X::X:X|WORD> solo",
3262 NO_STR
3263 NEIGHBOR_STR
3264 NEIGHBOR_ADDR_STR2
3265 "Solo peer - part of its own update group\n")
3266 {
3267 int idx_peer = 2;
3268 struct peer *peer;
3269 int ret;
3270
3271 peer = peer_and_group_lookup_vty(vty, argv[idx_peer]->arg);
3272 if (!peer)
3273 return CMD_WARNING_CONFIG_FAILED;
3274
3275 ret = update_group_adjust_soloness(peer, 0);
3276 return bgp_vty_return(vty, ret);
3277 }
3278
3279 DEFUN (neighbor_password,
3280 neighbor_password_cmd,
3281 "neighbor <A.B.C.D|X:X::X:X|WORD> password LINE",
3282 NEIGHBOR_STR
3283 NEIGHBOR_ADDR_STR2
3284 "Set a password\n"
3285 "The password\n")
3286 {
3287 int idx_peer = 1;
3288 int idx_line = 3;
3289 struct peer *peer;
3290 int ret;
3291
3292 peer = peer_and_group_lookup_vty(vty, argv[idx_peer]->arg);
3293 if (!peer)
3294 return CMD_WARNING_CONFIG_FAILED;
3295
3296 ret = peer_password_set(peer, argv[idx_line]->arg);
3297 return bgp_vty_return(vty, ret);
3298 }
3299
3300 DEFUN (no_neighbor_password,
3301 no_neighbor_password_cmd,
3302 "no neighbor <A.B.C.D|X:X::X:X|WORD> password [LINE]",
3303 NO_STR
3304 NEIGHBOR_STR
3305 NEIGHBOR_ADDR_STR2
3306 "Set a password\n"
3307 "The password\n")
3308 {
3309 int idx_peer = 2;
3310 struct peer *peer;
3311 int ret;
3312
3313 peer = peer_and_group_lookup_vty(vty, argv[idx_peer]->arg);
3314 if (!peer)
3315 return CMD_WARNING_CONFIG_FAILED;
3316
3317 ret = peer_password_unset(peer);
3318 return bgp_vty_return(vty, ret);
3319 }
3320
3321 DEFUN (neighbor_activate,
3322 neighbor_activate_cmd,
3323 "neighbor <A.B.C.D|X:X::X:X|WORD> activate",
3324 NEIGHBOR_STR
3325 NEIGHBOR_ADDR_STR2
3326 "Enable the Address Family for this Neighbor\n")
3327 {
3328 int idx_peer = 1;
3329 int ret;
3330 struct peer *peer;
3331
3332 peer = peer_and_group_lookup_vty(vty, argv[idx_peer]->arg);
3333 if (!peer)
3334 return CMD_WARNING_CONFIG_FAILED;
3335
3336 ret = peer_activate(peer, bgp_node_afi(vty), bgp_node_safi(vty));
3337 return bgp_vty_return(vty, ret);
3338 }
3339
3340 ALIAS_HIDDEN(neighbor_activate, neighbor_activate_hidden_cmd,
3341 "neighbor <A.B.C.D|X:X::X:X|WORD> activate",
3342 NEIGHBOR_STR NEIGHBOR_ADDR_STR2
3343 "Enable the Address Family for this Neighbor\n")
3344
3345 DEFUN (no_neighbor_activate,
3346 no_neighbor_activate_cmd,
3347 "no neighbor <A.B.C.D|X:X::X:X|WORD> activate",
3348 NO_STR
3349 NEIGHBOR_STR
3350 NEIGHBOR_ADDR_STR2
3351 "Enable the Address Family for this Neighbor\n")
3352 {
3353 int idx_peer = 2;
3354 int ret;
3355 struct peer *peer;
3356
3357 /* Lookup peer. */
3358 peer = peer_and_group_lookup_vty(vty, argv[idx_peer]->arg);
3359 if (!peer)
3360 return CMD_WARNING_CONFIG_FAILED;
3361
3362 ret = peer_deactivate(peer, bgp_node_afi(vty), bgp_node_safi(vty));
3363 return bgp_vty_return(vty, ret);
3364 }
3365
3366 ALIAS_HIDDEN(no_neighbor_activate, no_neighbor_activate_hidden_cmd,
3367 "no neighbor <A.B.C.D|X:X::X:X|WORD> activate",
3368 NO_STR NEIGHBOR_STR NEIGHBOR_ADDR_STR2
3369 "Enable the Address Family for this Neighbor\n")
3370
3371 DEFUN (neighbor_set_peer_group,
3372 neighbor_set_peer_group_cmd,
3373 "neighbor <A.B.C.D|X:X::X:X|WORD> peer-group WORD",
3374 NEIGHBOR_STR
3375 NEIGHBOR_ADDR_STR2
3376 "Member of the peer-group\n"
3377 "Peer-group name\n")
3378 {
3379 VTY_DECLVAR_CONTEXT(bgp, bgp);
3380 int idx_peer = 1;
3381 int idx_word = 3;
3382 int ret;
3383 as_t as;
3384 union sockunion su;
3385 struct peer *peer;
3386 struct peer_group *group;
3387
3388 ret = str2sockunion(argv[idx_peer]->arg, &su);
3389 if (ret < 0) {
3390 peer = peer_lookup_by_conf_if(bgp, argv[idx_peer]->arg);
3391 if (!peer) {
3392 vty_out(vty, "%% Malformed address or name: %s\n",
3393 argv[idx_peer]->arg);
3394 return CMD_WARNING_CONFIG_FAILED;
3395 }
3396 } else {
3397 if (peer_address_self_check(bgp, &su)) {
3398 vty_out(vty,
3399 "%% Can not configure the local system as neighbor\n");
3400 return CMD_WARNING_CONFIG_FAILED;
3401 }
3402
3403 /* Disallow for dynamic neighbor. */
3404 peer = peer_lookup(bgp, &su);
3405 if (peer && peer_dynamic_neighbor(peer)) {
3406 vty_out(vty,
3407 "%% Operation not allowed on a dynamic neighbor\n");
3408 return CMD_WARNING_CONFIG_FAILED;
3409 }
3410 }
3411
3412 group = peer_group_lookup(bgp, argv[idx_word]->arg);
3413 if (!group) {
3414 vty_out(vty, "%% Configure the peer-group first\n");
3415 return CMD_WARNING_CONFIG_FAILED;
3416 }
3417
3418 ret = peer_group_bind(bgp, &su, peer, group, &as);
3419
3420 if (ret == BGP_ERR_PEER_GROUP_PEER_TYPE_DIFFERENT) {
3421 vty_out(vty,
3422 "%% Peer with AS %u cannot be in this peer-group, members must be all internal or all external\n",
3423 as);
3424 return CMD_WARNING_CONFIG_FAILED;
3425 }
3426
3427 return bgp_vty_return(vty, ret);
3428 }
3429
3430 ALIAS_HIDDEN(neighbor_set_peer_group, neighbor_set_peer_group_hidden_cmd,
3431 "neighbor <A.B.C.D|X:X::X:X|WORD> peer-group WORD",
3432 NEIGHBOR_STR NEIGHBOR_ADDR_STR2
3433 "Member of the peer-group\n"
3434 "Peer-group name\n")
3435
3436 DEFUN (no_neighbor_set_peer_group,
3437 no_neighbor_set_peer_group_cmd,
3438 "no neighbor <A.B.C.D|X:X::X:X|WORD> peer-group WORD",
3439 NO_STR
3440 NEIGHBOR_STR
3441 NEIGHBOR_ADDR_STR2
3442 "Member of the peer-group\n"
3443 "Peer-group name\n")
3444 {
3445 VTY_DECLVAR_CONTEXT(bgp, bgp);
3446 int idx_peer = 2;
3447 int idx_word = 4;
3448 int ret;
3449 struct peer *peer;
3450 struct peer_group *group;
3451
3452 peer = peer_lookup_vty(vty, argv[idx_peer]->arg);
3453 if (!peer)
3454 return CMD_WARNING_CONFIG_FAILED;
3455
3456 group = peer_group_lookup(bgp, argv[idx_word]->arg);
3457 if (!group) {
3458 vty_out(vty, "%% Configure the peer-group first\n");
3459 return CMD_WARNING_CONFIG_FAILED;
3460 }
3461
3462 ret = peer_delete(peer);
3463
3464 return bgp_vty_return(vty, ret);
3465 }
3466
3467 ALIAS_HIDDEN(no_neighbor_set_peer_group, no_neighbor_set_peer_group_hidden_cmd,
3468 "no neighbor <A.B.C.D|X:X::X:X|WORD> peer-group WORD",
3469 NO_STR NEIGHBOR_STR NEIGHBOR_ADDR_STR2
3470 "Member of the peer-group\n"
3471 "Peer-group name\n")
3472
3473 static int peer_flag_modify_vty(struct vty *vty, const char *ip_str,
3474 uint32_t flag, int set)
3475 {
3476 int ret;
3477 struct peer *peer;
3478
3479 peer = peer_and_group_lookup_vty(vty, ip_str);
3480 if (!peer)
3481 return CMD_WARNING_CONFIG_FAILED;
3482
3483 /*
3484 * If 'neighbor <interface>', then this is for directly connected peers,
3485 * we should not accept disable-connected-check.
3486 */
3487 if (peer->conf_if && (flag == PEER_FLAG_DISABLE_CONNECTED_CHECK)) {
3488 vty_out(vty,
3489 "%s is directly connected peer, cannot accept disable-"
3490 "connected-check\n",
3491 ip_str);
3492 return CMD_WARNING_CONFIG_FAILED;
3493 }
3494
3495 if (!set && flag == PEER_FLAG_SHUTDOWN)
3496 peer_tx_shutdown_message_unset(peer);
3497
3498 if (set)
3499 ret = peer_flag_set(peer, flag);
3500 else
3501 ret = peer_flag_unset(peer, flag);
3502
3503 return bgp_vty_return(vty, ret);
3504 }
3505
3506 static int peer_flag_set_vty(struct vty *vty, const char *ip_str, uint32_t flag)
3507 {
3508 return peer_flag_modify_vty(vty, ip_str, flag, 1);
3509 }
3510
3511 static int peer_flag_unset_vty(struct vty *vty, const char *ip_str,
3512 uint32_t flag)
3513 {
3514 return peer_flag_modify_vty(vty, ip_str, flag, 0);
3515 }
3516
3517 /* neighbor passive. */
3518 DEFUN (neighbor_passive,
3519 neighbor_passive_cmd,
3520 "neighbor <A.B.C.D|X:X::X:X|WORD> passive",
3521 NEIGHBOR_STR
3522 NEIGHBOR_ADDR_STR2
3523 "Don't send open messages to this neighbor\n")
3524 {
3525 int idx_peer = 1;
3526 return peer_flag_set_vty(vty, argv[idx_peer]->arg, PEER_FLAG_PASSIVE);
3527 }
3528
3529 DEFUN (no_neighbor_passive,
3530 no_neighbor_passive_cmd,
3531 "no neighbor <A.B.C.D|X:X::X:X|WORD> passive",
3532 NO_STR
3533 NEIGHBOR_STR
3534 NEIGHBOR_ADDR_STR2
3535 "Don't send open messages to this neighbor\n")
3536 {
3537 int idx_peer = 2;
3538 return peer_flag_unset_vty(vty, argv[idx_peer]->arg, PEER_FLAG_PASSIVE);
3539 }
3540
3541 /* neighbor shutdown. */
3542 DEFUN (neighbor_shutdown_msg,
3543 neighbor_shutdown_msg_cmd,
3544 "neighbor <A.B.C.D|X:X::X:X|WORD> shutdown message MSG...",
3545 NEIGHBOR_STR
3546 NEIGHBOR_ADDR_STR2
3547 "Administratively shut down this neighbor\n"
3548 "Add a shutdown message (draft-ietf-idr-shutdown-06)\n"
3549 "Shutdown message\n")
3550 {
3551 int idx_peer = 1;
3552
3553 if (argc >= 5) {
3554 struct peer *peer =
3555 peer_and_group_lookup_vty(vty, argv[idx_peer]->arg);
3556 char *message;
3557
3558 if (!peer)
3559 return CMD_WARNING_CONFIG_FAILED;
3560 message = argv_concat(argv, argc, 4);
3561 peer_tx_shutdown_message_set(peer, message);
3562 XFREE(MTYPE_TMP, message);
3563 }
3564
3565 return peer_flag_set_vty(vty, argv[idx_peer]->arg, PEER_FLAG_SHUTDOWN);
3566 }
3567
3568 ALIAS(neighbor_shutdown_msg, neighbor_shutdown_cmd,
3569 "neighbor <A.B.C.D|X:X::X:X|WORD> shutdown",
3570 NEIGHBOR_STR NEIGHBOR_ADDR_STR2
3571 "Administratively shut down this neighbor\n")
3572
3573 DEFUN (no_neighbor_shutdown_msg,
3574 no_neighbor_shutdown_msg_cmd,
3575 "no neighbor <A.B.C.D|X:X::X:X|WORD> shutdown message MSG...",
3576 NO_STR
3577 NEIGHBOR_STR
3578 NEIGHBOR_ADDR_STR2
3579 "Administratively shut down this neighbor\n"
3580 "Remove a shutdown message (draft-ietf-idr-shutdown-06)\n"
3581 "Shutdown message\n")
3582 {
3583 int idx_peer = 2;
3584
3585 return peer_flag_unset_vty(vty, argv[idx_peer]->arg,
3586 PEER_FLAG_SHUTDOWN);
3587 }
3588
3589 ALIAS(no_neighbor_shutdown_msg, no_neighbor_shutdown_cmd,
3590 "no neighbor <A.B.C.D|X:X::X:X|WORD> shutdown",
3591 NO_STR NEIGHBOR_STR NEIGHBOR_ADDR_STR2
3592 "Administratively shut down this neighbor\n")
3593
3594 /* neighbor capability dynamic. */
3595 DEFUN (neighbor_capability_dynamic,
3596 neighbor_capability_dynamic_cmd,
3597 "neighbor <A.B.C.D|X:X::X:X|WORD> capability dynamic",
3598 NEIGHBOR_STR
3599 NEIGHBOR_ADDR_STR2
3600 "Advertise capability to the peer\n"
3601 "Advertise dynamic capability to this neighbor\n")
3602 {
3603 int idx_peer = 1;
3604 return peer_flag_set_vty(vty, argv[idx_peer]->arg,
3605 PEER_FLAG_DYNAMIC_CAPABILITY);
3606 }
3607
3608 DEFUN (no_neighbor_capability_dynamic,
3609 no_neighbor_capability_dynamic_cmd,
3610 "no neighbor <A.B.C.D|X:X::X:X|WORD> capability dynamic",
3611 NO_STR
3612 NEIGHBOR_STR
3613 NEIGHBOR_ADDR_STR2
3614 "Advertise capability to the peer\n"
3615 "Advertise dynamic capability to this neighbor\n")
3616 {
3617 int idx_peer = 2;
3618 return peer_flag_unset_vty(vty, argv[idx_peer]->arg,
3619 PEER_FLAG_DYNAMIC_CAPABILITY);
3620 }
3621
3622 /* neighbor dont-capability-negotiate */
3623 DEFUN (neighbor_dont_capability_negotiate,
3624 neighbor_dont_capability_negotiate_cmd,
3625 "neighbor <A.B.C.D|X:X::X:X|WORD> dont-capability-negotiate",
3626 NEIGHBOR_STR
3627 NEIGHBOR_ADDR_STR2
3628 "Do not perform capability negotiation\n")
3629 {
3630 int idx_peer = 1;
3631 return peer_flag_set_vty(vty, argv[idx_peer]->arg,
3632 PEER_FLAG_DONT_CAPABILITY);
3633 }
3634
3635 DEFUN (no_neighbor_dont_capability_negotiate,
3636 no_neighbor_dont_capability_negotiate_cmd,
3637 "no neighbor <A.B.C.D|X:X::X:X|WORD> dont-capability-negotiate",
3638 NO_STR
3639 NEIGHBOR_STR
3640 NEIGHBOR_ADDR_STR2
3641 "Do not perform capability negotiation\n")
3642 {
3643 int idx_peer = 2;
3644 return peer_flag_unset_vty(vty, argv[idx_peer]->arg,
3645 PEER_FLAG_DONT_CAPABILITY);
3646 }
3647
3648 /* neighbor capability extended next hop encoding */
3649 DEFUN (neighbor_capability_enhe,
3650 neighbor_capability_enhe_cmd,
3651 "neighbor <A.B.C.D|X:X::X:X|WORD> capability extended-nexthop",
3652 NEIGHBOR_STR
3653 NEIGHBOR_ADDR_STR2
3654 "Advertise capability to the peer\n"
3655 "Advertise extended next-hop capability to the peer\n")
3656 {
3657 int idx_peer = 1;
3658 return peer_flag_set_vty(vty, argv[idx_peer]->arg,
3659 PEER_FLAG_CAPABILITY_ENHE);
3660 }
3661
3662 DEFUN (no_neighbor_capability_enhe,
3663 no_neighbor_capability_enhe_cmd,
3664 "no neighbor <A.B.C.D|X:X::X:X|WORD> capability extended-nexthop",
3665 NO_STR
3666 NEIGHBOR_STR
3667 NEIGHBOR_ADDR_STR2
3668 "Advertise capability to the peer\n"
3669 "Advertise extended next-hop capability to the peer\n")
3670 {
3671 int idx_peer = 2;
3672 return peer_flag_unset_vty(vty, argv[idx_peer]->arg,
3673 PEER_FLAG_CAPABILITY_ENHE);
3674 }
3675
3676 static int peer_af_flag_modify_vty(struct vty *vty, const char *peer_str,
3677 afi_t afi, safi_t safi, uint32_t flag,
3678 int set)
3679 {
3680 int ret;
3681 struct peer *peer;
3682
3683 peer = peer_and_group_lookup_vty(vty, peer_str);
3684 if (!peer)
3685 return CMD_WARNING_CONFIG_FAILED;
3686
3687 if (set)
3688 ret = peer_af_flag_set(peer, afi, safi, flag);
3689 else
3690 ret = peer_af_flag_unset(peer, afi, safi, flag);
3691
3692 return bgp_vty_return(vty, ret);
3693 }
3694
3695 static int peer_af_flag_set_vty(struct vty *vty, const char *peer_str,
3696 afi_t afi, safi_t safi, uint32_t flag)
3697 {
3698 return peer_af_flag_modify_vty(vty, peer_str, afi, safi, flag, 1);
3699 }
3700
3701 static int peer_af_flag_unset_vty(struct vty *vty, const char *peer_str,
3702 afi_t afi, safi_t safi, uint32_t flag)
3703 {
3704 return peer_af_flag_modify_vty(vty, peer_str, afi, safi, flag, 0);
3705 }
3706
3707 /* neighbor capability orf prefix-list. */
3708 DEFUN (neighbor_capability_orf_prefix,
3709 neighbor_capability_orf_prefix_cmd,
3710 "neighbor <A.B.C.D|X:X::X:X|WORD> capability orf prefix-list <both|send|receive>",
3711 NEIGHBOR_STR
3712 NEIGHBOR_ADDR_STR2
3713 "Advertise capability to the peer\n"
3714 "Advertise ORF capability to the peer\n"
3715 "Advertise prefixlist ORF capability to this neighbor\n"
3716 "Capability to SEND and RECEIVE the ORF to/from this neighbor\n"
3717 "Capability to RECEIVE the ORF from this neighbor\n"
3718 "Capability to SEND the ORF to this neighbor\n")
3719 {
3720 int idx_peer = 1;
3721 int idx_send_recv = 5;
3722 uint16_t flag = 0;
3723
3724 if (strmatch(argv[idx_send_recv]->text, "send"))
3725 flag = PEER_FLAG_ORF_PREFIX_SM;
3726 else if (strmatch(argv[idx_send_recv]->text, "receive"))
3727 flag = PEER_FLAG_ORF_PREFIX_RM;
3728 else if (strmatch(argv[idx_send_recv]->text, "both"))
3729 flag = PEER_FLAG_ORF_PREFIX_SM | PEER_FLAG_ORF_PREFIX_RM;
3730 else {
3731 vty_out(vty, "%% BGP invalid orf prefix-list option\n");
3732 return CMD_WARNING_CONFIG_FAILED;
3733 }
3734
3735 return peer_af_flag_set_vty(vty, argv[idx_peer]->arg, bgp_node_afi(vty),
3736 bgp_node_safi(vty), flag);
3737 }
3738
3739 ALIAS_HIDDEN(
3740 neighbor_capability_orf_prefix,
3741 neighbor_capability_orf_prefix_hidden_cmd,
3742 "neighbor <A.B.C.D|X:X::X:X|WORD> capability orf prefix-list <both|send|receive>",
3743 NEIGHBOR_STR NEIGHBOR_ADDR_STR2
3744 "Advertise capability to the peer\n"
3745 "Advertise ORF capability to the peer\n"
3746 "Advertise prefixlist ORF capability to this neighbor\n"
3747 "Capability to SEND and RECEIVE the ORF to/from this neighbor\n"
3748 "Capability to RECEIVE the ORF from this neighbor\n"
3749 "Capability to SEND the ORF to this neighbor\n")
3750
3751 DEFUN (no_neighbor_capability_orf_prefix,
3752 no_neighbor_capability_orf_prefix_cmd,
3753 "no neighbor <A.B.C.D|X:X::X:X|WORD> capability orf prefix-list <both|send|receive>",
3754 NO_STR
3755 NEIGHBOR_STR
3756 NEIGHBOR_ADDR_STR2
3757 "Advertise capability to the peer\n"
3758 "Advertise ORF capability to the peer\n"
3759 "Advertise prefixlist ORF capability to this neighbor\n"
3760 "Capability to SEND and RECEIVE the ORF to/from this neighbor\n"
3761 "Capability to RECEIVE the ORF from this neighbor\n"
3762 "Capability to SEND the ORF to this neighbor\n")
3763 {
3764 int idx_peer = 2;
3765 int idx_send_recv = 6;
3766 uint16_t flag = 0;
3767
3768 if (strmatch(argv[idx_send_recv]->text, "send"))
3769 flag = PEER_FLAG_ORF_PREFIX_SM;
3770 else if (strmatch(argv[idx_send_recv]->text, "receive"))
3771 flag = PEER_FLAG_ORF_PREFIX_RM;
3772 else if (strmatch(argv[idx_send_recv]->text, "both"))
3773 flag = PEER_FLAG_ORF_PREFIX_SM | PEER_FLAG_ORF_PREFIX_RM;
3774 else {
3775 vty_out(vty, "%% BGP invalid orf prefix-list option\n");
3776 return CMD_WARNING_CONFIG_FAILED;
3777 }
3778
3779 return peer_af_flag_unset_vty(vty, argv[idx_peer]->arg,
3780 bgp_node_afi(vty), bgp_node_safi(vty),
3781 flag);
3782 }
3783
3784 ALIAS_HIDDEN(
3785 no_neighbor_capability_orf_prefix,
3786 no_neighbor_capability_orf_prefix_hidden_cmd,
3787 "no neighbor <A.B.C.D|X:X::X:X|WORD> capability orf prefix-list <both|send|receive>",
3788 NO_STR NEIGHBOR_STR NEIGHBOR_ADDR_STR2
3789 "Advertise capability to the peer\n"
3790 "Advertise ORF capability to the peer\n"
3791 "Advertise prefixlist ORF capability to this neighbor\n"
3792 "Capability to SEND and RECEIVE the ORF to/from this neighbor\n"
3793 "Capability to RECEIVE the ORF from this neighbor\n"
3794 "Capability to SEND the ORF to this neighbor\n")
3795
3796 /* neighbor next-hop-self. */
3797 DEFUN (neighbor_nexthop_self,
3798 neighbor_nexthop_self_cmd,
3799 "neighbor <A.B.C.D|X:X::X:X|WORD> next-hop-self",
3800 NEIGHBOR_STR
3801 NEIGHBOR_ADDR_STR2
3802 "Disable the next hop calculation for this neighbor\n")
3803 {
3804 int idx_peer = 1;
3805 return peer_af_flag_set_vty(vty, argv[idx_peer]->arg, bgp_node_afi(vty),
3806 bgp_node_safi(vty), PEER_FLAG_NEXTHOP_SELF);
3807 }
3808
3809 ALIAS_HIDDEN(neighbor_nexthop_self, neighbor_nexthop_self_hidden_cmd,
3810 "neighbor <A.B.C.D|X:X::X:X|WORD> next-hop-self",
3811 NEIGHBOR_STR NEIGHBOR_ADDR_STR2
3812 "Disable the next hop calculation for this neighbor\n")
3813
3814 /* neighbor next-hop-self. */
3815 DEFUN (neighbor_nexthop_self_force,
3816 neighbor_nexthop_self_force_cmd,
3817 "neighbor <A.B.C.D|X:X::X:X|WORD> next-hop-self force",
3818 NEIGHBOR_STR
3819 NEIGHBOR_ADDR_STR2
3820 "Disable the next hop calculation for this neighbor\n"
3821 "Set the next hop to self for reflected routes\n")
3822 {
3823 int idx_peer = 1;
3824 return peer_af_flag_set_vty(vty, argv[idx_peer]->arg, bgp_node_afi(vty),
3825 bgp_node_safi(vty),
3826 PEER_FLAG_FORCE_NEXTHOP_SELF);
3827 }
3828
3829 ALIAS_HIDDEN(neighbor_nexthop_self_force,
3830 neighbor_nexthop_self_force_hidden_cmd,
3831 "neighbor <A.B.C.D|X:X::X:X|WORD> next-hop-self force",
3832 NEIGHBOR_STR NEIGHBOR_ADDR_STR2
3833 "Disable the next hop calculation for this neighbor\n"
3834 "Set the next hop to self for reflected routes\n")
3835
3836 DEFUN (no_neighbor_nexthop_self,
3837 no_neighbor_nexthop_self_cmd,
3838 "no neighbor <A.B.C.D|X:X::X:X|WORD> next-hop-self",
3839 NO_STR
3840 NEIGHBOR_STR
3841 NEIGHBOR_ADDR_STR2
3842 "Disable the next hop calculation for this neighbor\n")
3843 {
3844 int idx_peer = 2;
3845 return peer_af_flag_unset_vty(vty, argv[idx_peer]->arg,
3846 bgp_node_afi(vty), bgp_node_safi(vty),
3847 PEER_FLAG_NEXTHOP_SELF);
3848 }
3849
3850 ALIAS_HIDDEN(no_neighbor_nexthop_self, no_neighbor_nexthop_self_hidden_cmd,
3851 "no neighbor <A.B.C.D|X:X::X:X|WORD> next-hop-self",
3852 NO_STR NEIGHBOR_STR NEIGHBOR_ADDR_STR2
3853 "Disable the next hop calculation for this neighbor\n")
3854
3855 DEFUN (no_neighbor_nexthop_self_force,
3856 no_neighbor_nexthop_self_force_cmd,
3857 "no neighbor <A.B.C.D|X:X::X:X|WORD> next-hop-self force",
3858 NO_STR
3859 NEIGHBOR_STR
3860 NEIGHBOR_ADDR_STR2
3861 "Disable the next hop calculation for this neighbor\n"
3862 "Set the next hop to self for reflected routes\n")
3863 {
3864 int idx_peer = 2;
3865 return peer_af_flag_unset_vty(vty, argv[idx_peer]->arg,
3866 bgp_node_afi(vty), bgp_node_safi(vty),
3867 PEER_FLAG_FORCE_NEXTHOP_SELF);
3868 }
3869
3870 ALIAS_HIDDEN(no_neighbor_nexthop_self_force,
3871 no_neighbor_nexthop_self_force_hidden_cmd,
3872 "no neighbor <A.B.C.D|X:X::X:X|WORD> next-hop-self force",
3873 NO_STR NEIGHBOR_STR NEIGHBOR_ADDR_STR2
3874 "Disable the next hop calculation for this neighbor\n"
3875 "Set the next hop to self for reflected routes\n")
3876
3877 /* neighbor as-override */
3878 DEFUN (neighbor_as_override,
3879 neighbor_as_override_cmd,
3880 "neighbor <A.B.C.D|X:X::X:X|WORD> as-override",
3881 NEIGHBOR_STR
3882 NEIGHBOR_ADDR_STR2
3883 "Override ASNs in outbound updates if aspath equals remote-as\n")
3884 {
3885 int idx_peer = 1;
3886 return peer_af_flag_set_vty(vty, argv[idx_peer]->arg, bgp_node_afi(vty),
3887 bgp_node_safi(vty), PEER_FLAG_AS_OVERRIDE);
3888 }
3889
3890 ALIAS_HIDDEN(neighbor_as_override, neighbor_as_override_hidden_cmd,
3891 "neighbor <A.B.C.D|X:X::X:X|WORD> as-override",
3892 NEIGHBOR_STR NEIGHBOR_ADDR_STR2
3893 "Override ASNs in outbound updates if aspath equals remote-as\n")
3894
3895 DEFUN (no_neighbor_as_override,
3896 no_neighbor_as_override_cmd,
3897 "no neighbor <A.B.C.D|X:X::X:X|WORD> as-override",
3898 NO_STR
3899 NEIGHBOR_STR
3900 NEIGHBOR_ADDR_STR2
3901 "Override ASNs in outbound updates if aspath equals remote-as\n")
3902 {
3903 int idx_peer = 2;
3904 return peer_af_flag_unset_vty(vty, argv[idx_peer]->arg,
3905 bgp_node_afi(vty), bgp_node_safi(vty),
3906 PEER_FLAG_AS_OVERRIDE);
3907 }
3908
3909 ALIAS_HIDDEN(no_neighbor_as_override, no_neighbor_as_override_hidden_cmd,
3910 "no neighbor <A.B.C.D|X:X::X:X|WORD> as-override",
3911 NO_STR NEIGHBOR_STR NEIGHBOR_ADDR_STR2
3912 "Override ASNs in outbound updates if aspath equals remote-as\n")
3913
3914 /* neighbor remove-private-AS. */
3915 DEFUN (neighbor_remove_private_as,
3916 neighbor_remove_private_as_cmd,
3917 "neighbor <A.B.C.D|X:X::X:X|WORD> remove-private-AS",
3918 NEIGHBOR_STR
3919 NEIGHBOR_ADDR_STR2
3920 "Remove private ASNs in outbound updates\n")
3921 {
3922 int idx_peer = 1;
3923 return peer_af_flag_set_vty(vty, argv[idx_peer]->arg, bgp_node_afi(vty),
3924 bgp_node_safi(vty),
3925 PEER_FLAG_REMOVE_PRIVATE_AS);
3926 }
3927
3928 ALIAS_HIDDEN(neighbor_remove_private_as, neighbor_remove_private_as_hidden_cmd,
3929 "neighbor <A.B.C.D|X:X::X:X|WORD> remove-private-AS",
3930 NEIGHBOR_STR NEIGHBOR_ADDR_STR2
3931 "Remove private ASNs in outbound updates\n")
3932
3933 DEFUN (neighbor_remove_private_as_all,
3934 neighbor_remove_private_as_all_cmd,
3935 "neighbor <A.B.C.D|X:X::X:X|WORD> remove-private-AS all",
3936 NEIGHBOR_STR
3937 NEIGHBOR_ADDR_STR2
3938 "Remove private ASNs in outbound updates\n"
3939 "Apply to all AS numbers\n")
3940 {
3941 int idx_peer = 1;
3942 return peer_af_flag_set_vty(vty, argv[idx_peer]->arg, bgp_node_afi(vty),
3943 bgp_node_safi(vty),
3944 PEER_FLAG_REMOVE_PRIVATE_AS_ALL);
3945 }
3946
3947 ALIAS_HIDDEN(neighbor_remove_private_as_all,
3948 neighbor_remove_private_as_all_hidden_cmd,
3949 "neighbor <A.B.C.D|X:X::X:X|WORD> remove-private-AS all",
3950 NEIGHBOR_STR NEIGHBOR_ADDR_STR2
3951 "Remove private ASNs in outbound updates\n"
3952 "Apply to all AS numbers")
3953
3954 DEFUN (neighbor_remove_private_as_replace_as,
3955 neighbor_remove_private_as_replace_as_cmd,
3956 "neighbor <A.B.C.D|X:X::X:X|WORD> remove-private-AS replace-AS",
3957 NEIGHBOR_STR
3958 NEIGHBOR_ADDR_STR2
3959 "Remove private ASNs in outbound updates\n"
3960 "Replace private ASNs with our ASN in outbound updates\n")
3961 {
3962 int idx_peer = 1;
3963 return peer_af_flag_set_vty(vty, argv[idx_peer]->arg, bgp_node_afi(vty),
3964 bgp_node_safi(vty),
3965 PEER_FLAG_REMOVE_PRIVATE_AS_REPLACE);
3966 }
3967
3968 ALIAS_HIDDEN(neighbor_remove_private_as_replace_as,
3969 neighbor_remove_private_as_replace_as_hidden_cmd,
3970 "neighbor <A.B.C.D|X:X::X:X|WORD> remove-private-AS replace-AS",
3971 NEIGHBOR_STR NEIGHBOR_ADDR_STR2
3972 "Remove private ASNs in outbound updates\n"
3973 "Replace private ASNs with our ASN in outbound updates\n")
3974
3975 DEFUN (neighbor_remove_private_as_all_replace_as,
3976 neighbor_remove_private_as_all_replace_as_cmd,
3977 "neighbor <A.B.C.D|X:X::X:X|WORD> remove-private-AS all replace-AS",
3978 NEIGHBOR_STR
3979 NEIGHBOR_ADDR_STR2
3980 "Remove private ASNs in outbound updates\n"
3981 "Apply to all AS numbers\n"
3982 "Replace private ASNs with our ASN in outbound updates\n")
3983 {
3984 int idx_peer = 1;
3985 return peer_af_flag_set_vty(vty, argv[idx_peer]->arg, bgp_node_afi(vty),
3986 bgp_node_safi(vty),
3987 PEER_FLAG_REMOVE_PRIVATE_AS_ALL_REPLACE);
3988 }
3989
3990 ALIAS_HIDDEN(
3991 neighbor_remove_private_as_all_replace_as,
3992 neighbor_remove_private_as_all_replace_as_hidden_cmd,
3993 "neighbor <A.B.C.D|X:X::X:X|WORD> remove-private-AS all replace-AS",
3994 NEIGHBOR_STR NEIGHBOR_ADDR_STR2
3995 "Remove private ASNs in outbound updates\n"
3996 "Apply to all AS numbers\n"
3997 "Replace private ASNs with our ASN in outbound updates\n")
3998
3999 DEFUN (no_neighbor_remove_private_as,
4000 no_neighbor_remove_private_as_cmd,
4001 "no neighbor <A.B.C.D|X:X::X:X|WORD> remove-private-AS",
4002 NO_STR
4003 NEIGHBOR_STR
4004 NEIGHBOR_ADDR_STR2
4005 "Remove private ASNs in outbound updates\n")
4006 {
4007 int idx_peer = 2;
4008 return peer_af_flag_unset_vty(vty, argv[idx_peer]->arg,
4009 bgp_node_afi(vty), bgp_node_safi(vty),
4010 PEER_FLAG_REMOVE_PRIVATE_AS);
4011 }
4012
4013 ALIAS_HIDDEN(no_neighbor_remove_private_as,
4014 no_neighbor_remove_private_as_hidden_cmd,
4015 "no neighbor <A.B.C.D|X:X::X:X|WORD> remove-private-AS",
4016 NO_STR NEIGHBOR_STR NEIGHBOR_ADDR_STR2
4017 "Remove private ASNs in outbound updates\n")
4018
4019 DEFUN (no_neighbor_remove_private_as_all,
4020 no_neighbor_remove_private_as_all_cmd,
4021 "no neighbor <A.B.C.D|X:X::X:X|WORD> remove-private-AS all",
4022 NO_STR
4023 NEIGHBOR_STR
4024 NEIGHBOR_ADDR_STR2
4025 "Remove private ASNs in outbound updates\n"
4026 "Apply to all AS numbers\n")
4027 {
4028 int idx_peer = 2;
4029 return peer_af_flag_unset_vty(vty, argv[idx_peer]->arg,
4030 bgp_node_afi(vty), bgp_node_safi(vty),
4031 PEER_FLAG_REMOVE_PRIVATE_AS_ALL);
4032 }
4033
4034 ALIAS_HIDDEN(no_neighbor_remove_private_as_all,
4035 no_neighbor_remove_private_as_all_hidden_cmd,
4036 "no neighbor <A.B.C.D|X:X::X:X|WORD> remove-private-AS all",
4037 NO_STR NEIGHBOR_STR NEIGHBOR_ADDR_STR2
4038 "Remove private ASNs in outbound updates\n"
4039 "Apply to all AS numbers\n")
4040
4041 DEFUN (no_neighbor_remove_private_as_replace_as,
4042 no_neighbor_remove_private_as_replace_as_cmd,
4043 "no neighbor <A.B.C.D|X:X::X:X|WORD> remove-private-AS replace-AS",
4044 NO_STR
4045 NEIGHBOR_STR
4046 NEIGHBOR_ADDR_STR2
4047 "Remove private ASNs in outbound updates\n"
4048 "Replace private ASNs with our ASN in outbound updates\n")
4049 {
4050 int idx_peer = 2;
4051 return peer_af_flag_unset_vty(vty, argv[idx_peer]->arg,
4052 bgp_node_afi(vty), bgp_node_safi(vty),
4053 PEER_FLAG_REMOVE_PRIVATE_AS_REPLACE);
4054 }
4055
4056 ALIAS_HIDDEN(no_neighbor_remove_private_as_replace_as,
4057 no_neighbor_remove_private_as_replace_as_hidden_cmd,
4058 "no neighbor <A.B.C.D|X:X::X:X|WORD> remove-private-AS replace-AS",
4059 NO_STR NEIGHBOR_STR NEIGHBOR_ADDR_STR2
4060 "Remove private ASNs in outbound updates\n"
4061 "Replace private ASNs with our ASN in outbound updates\n")
4062
4063 DEFUN (no_neighbor_remove_private_as_all_replace_as,
4064 no_neighbor_remove_private_as_all_replace_as_cmd,
4065 "no neighbor <A.B.C.D|X:X::X:X|WORD> remove-private-AS all replace-AS",
4066 NO_STR
4067 NEIGHBOR_STR
4068 NEIGHBOR_ADDR_STR2
4069 "Remove private ASNs in outbound updates\n"
4070 "Apply to all AS numbers\n"
4071 "Replace private ASNs with our ASN in outbound updates\n")
4072 {
4073 int idx_peer = 2;
4074 return peer_af_flag_unset_vty(vty, argv[idx_peer]->arg,
4075 bgp_node_afi(vty), bgp_node_safi(vty),
4076 PEER_FLAG_REMOVE_PRIVATE_AS_ALL_REPLACE);
4077 }
4078
4079 ALIAS_HIDDEN(
4080 no_neighbor_remove_private_as_all_replace_as,
4081 no_neighbor_remove_private_as_all_replace_as_hidden_cmd,
4082 "no neighbor <A.B.C.D|X:X::X:X|WORD> remove-private-AS all replace-AS",
4083 NO_STR NEIGHBOR_STR NEIGHBOR_ADDR_STR2
4084 "Remove private ASNs in outbound updates\n"
4085 "Apply to all AS numbers\n"
4086 "Replace private ASNs with our ASN in outbound updates\n")
4087
4088
4089 /* neighbor send-community. */
4090 DEFUN (neighbor_send_community,
4091 neighbor_send_community_cmd,
4092 "neighbor <A.B.C.D|X:X::X:X|WORD> send-community",
4093 NEIGHBOR_STR
4094 NEIGHBOR_ADDR_STR2
4095 "Send Community attribute to this neighbor\n")
4096 {
4097 int idx_peer = 1;
4098
4099 return peer_af_flag_set_vty(vty, argv[idx_peer]->arg, bgp_node_afi(vty),
4100 bgp_node_safi(vty),
4101 PEER_FLAG_SEND_COMMUNITY);
4102 }
4103
4104 ALIAS_HIDDEN(neighbor_send_community, neighbor_send_community_hidden_cmd,
4105 "neighbor <A.B.C.D|X:X::X:X|WORD> send-community",
4106 NEIGHBOR_STR NEIGHBOR_ADDR_STR2
4107 "Send Community attribute to this neighbor\n")
4108
4109 DEFUN (no_neighbor_send_community,
4110 no_neighbor_send_community_cmd,
4111 "no neighbor <A.B.C.D|X:X::X:X|WORD> send-community",
4112 NO_STR
4113 NEIGHBOR_STR
4114 NEIGHBOR_ADDR_STR2
4115 "Send Community attribute to this neighbor\n")
4116 {
4117 int idx_peer = 2;
4118
4119 return peer_af_flag_unset_vty(vty, argv[idx_peer]->arg,
4120 bgp_node_afi(vty), bgp_node_safi(vty),
4121 PEER_FLAG_SEND_COMMUNITY);
4122 }
4123
4124 ALIAS_HIDDEN(no_neighbor_send_community, no_neighbor_send_community_hidden_cmd,
4125 "no neighbor <A.B.C.D|X:X::X:X|WORD> send-community",
4126 NO_STR NEIGHBOR_STR NEIGHBOR_ADDR_STR2
4127 "Send Community attribute to this neighbor\n")
4128
4129 /* neighbor send-community extended. */
4130 DEFUN (neighbor_send_community_type,
4131 neighbor_send_community_type_cmd,
4132 "neighbor <A.B.C.D|X:X::X:X|WORD> send-community <both|all|extended|standard|large>",
4133 NEIGHBOR_STR
4134 NEIGHBOR_ADDR_STR2
4135 "Send Community attribute to this neighbor\n"
4136 "Send Standard and Extended Community attributes\n"
4137 "Send Standard, Large and Extended Community attributes\n"
4138 "Send Extended Community attributes\n"
4139 "Send Standard Community attributes\n"
4140 "Send Large Community attributes\n")
4141 {
4142 int idx_peer = 1;
4143 uint32_t flag = 0;
4144 const char *type = argv[argc - 1]->text;
4145
4146 if (strmatch(type, "standard")) {
4147 SET_FLAG(flag, PEER_FLAG_SEND_COMMUNITY);
4148 } else if (strmatch(type, "extended")) {
4149 SET_FLAG(flag, PEER_FLAG_SEND_EXT_COMMUNITY);
4150 } else if (strmatch(type, "large")) {
4151 SET_FLAG(flag, PEER_FLAG_SEND_LARGE_COMMUNITY);
4152 } else if (strmatch(type, "both")) {
4153 SET_FLAG(flag, PEER_FLAG_SEND_COMMUNITY);
4154 SET_FLAG(flag, PEER_FLAG_SEND_EXT_COMMUNITY);
4155 } else { /* if (strmatch(type, "all")) */
4156 SET_FLAG(flag, PEER_FLAG_SEND_COMMUNITY);
4157 SET_FLAG(flag, PEER_FLAG_SEND_EXT_COMMUNITY);
4158 SET_FLAG(flag, PEER_FLAG_SEND_LARGE_COMMUNITY);
4159 }
4160
4161 return peer_af_flag_set_vty(vty, argv[idx_peer]->arg, bgp_node_afi(vty),
4162 bgp_node_safi(vty), flag);
4163 }
4164
4165 ALIAS_HIDDEN(
4166 neighbor_send_community_type, neighbor_send_community_type_hidden_cmd,
4167 "neighbor <A.B.C.D|X:X::X:X|WORD> send-community <both|all|extended|standard|large>",
4168 NEIGHBOR_STR NEIGHBOR_ADDR_STR2
4169 "Send Community attribute to this neighbor\n"
4170 "Send Standard and Extended Community attributes\n"
4171 "Send Standard, Large and Extended Community attributes\n"
4172 "Send Extended Community attributes\n"
4173 "Send Standard Community attributes\n"
4174 "Send Large Community attributes\n")
4175
4176 DEFUN (no_neighbor_send_community_type,
4177 no_neighbor_send_community_type_cmd,
4178 "no neighbor <A.B.C.D|X:X::X:X|WORD> send-community <both|all|extended|standard|large>",
4179 NO_STR
4180 NEIGHBOR_STR
4181 NEIGHBOR_ADDR_STR2
4182 "Send Community attribute to this neighbor\n"
4183 "Send Standard and Extended Community attributes\n"
4184 "Send Standard, Large and Extended Community attributes\n"
4185 "Send Extended Community attributes\n"
4186 "Send Standard Community attributes\n"
4187 "Send Large Community attributes\n")
4188 {
4189 int idx_peer = 2;
4190 uint32_t flag = 0;
4191 const char *type = argv[argc - 1]->text;
4192
4193 if (strmatch(type, "standard")) {
4194 SET_FLAG(flag, PEER_FLAG_SEND_COMMUNITY);
4195 } else if (strmatch(type, "extended")) {
4196 SET_FLAG(flag, PEER_FLAG_SEND_EXT_COMMUNITY);
4197 } else if (strmatch(type, "large")) {
4198 SET_FLAG(flag, PEER_FLAG_SEND_LARGE_COMMUNITY);
4199 } else if (strmatch(type, "both")) {
4200 SET_FLAG(flag, PEER_FLAG_SEND_COMMUNITY);
4201 SET_FLAG(flag, PEER_FLAG_SEND_EXT_COMMUNITY);
4202 } else { /* if (strmatch(type, "all")) */
4203 SET_FLAG(flag, PEER_FLAG_SEND_COMMUNITY);
4204 SET_FLAG(flag, PEER_FLAG_SEND_EXT_COMMUNITY);
4205 SET_FLAG(flag, PEER_FLAG_SEND_LARGE_COMMUNITY);
4206 }
4207
4208 return peer_af_flag_unset_vty(vty, argv[idx_peer]->arg,
4209 bgp_node_afi(vty), bgp_node_safi(vty),
4210 flag);
4211 }
4212
4213 ALIAS_HIDDEN(
4214 no_neighbor_send_community_type,
4215 no_neighbor_send_community_type_hidden_cmd,
4216 "no neighbor <A.B.C.D|X:X::X:X|WORD> send-community <both|all|extended|standard|large>",
4217 NO_STR NEIGHBOR_STR NEIGHBOR_ADDR_STR2
4218 "Send Community attribute to this neighbor\n"
4219 "Send Standard and Extended Community attributes\n"
4220 "Send Standard, Large and Extended Community attributes\n"
4221 "Send Extended Community attributes\n"
4222 "Send Standard Community attributes\n"
4223 "Send Large Community attributes\n")
4224
4225 /* neighbor soft-reconfig. */
4226 DEFUN (neighbor_soft_reconfiguration,
4227 neighbor_soft_reconfiguration_cmd,
4228 "neighbor <A.B.C.D|X:X::X:X|WORD> soft-reconfiguration inbound",
4229 NEIGHBOR_STR
4230 NEIGHBOR_ADDR_STR2
4231 "Per neighbor soft reconfiguration\n"
4232 "Allow inbound soft reconfiguration for this neighbor\n")
4233 {
4234 int idx_peer = 1;
4235 return peer_af_flag_set_vty(vty, argv[idx_peer]->arg, bgp_node_afi(vty),
4236 bgp_node_safi(vty),
4237 PEER_FLAG_SOFT_RECONFIG);
4238 }
4239
4240 ALIAS_HIDDEN(neighbor_soft_reconfiguration,
4241 neighbor_soft_reconfiguration_hidden_cmd,
4242 "neighbor <A.B.C.D|X:X::X:X|WORD> soft-reconfiguration inbound",
4243 NEIGHBOR_STR NEIGHBOR_ADDR_STR2
4244 "Per neighbor soft reconfiguration\n"
4245 "Allow inbound soft reconfiguration for this neighbor\n")
4246
4247 DEFUN (no_neighbor_soft_reconfiguration,
4248 no_neighbor_soft_reconfiguration_cmd,
4249 "no neighbor <A.B.C.D|X:X::X:X|WORD> soft-reconfiguration inbound",
4250 NO_STR
4251 NEIGHBOR_STR
4252 NEIGHBOR_ADDR_STR2
4253 "Per neighbor soft reconfiguration\n"
4254 "Allow inbound soft reconfiguration for this neighbor\n")
4255 {
4256 int idx_peer = 2;
4257 return peer_af_flag_unset_vty(vty, argv[idx_peer]->arg,
4258 bgp_node_afi(vty), bgp_node_safi(vty),
4259 PEER_FLAG_SOFT_RECONFIG);
4260 }
4261
4262 ALIAS_HIDDEN(no_neighbor_soft_reconfiguration,
4263 no_neighbor_soft_reconfiguration_hidden_cmd,
4264 "no neighbor <A.B.C.D|X:X::X:X|WORD> soft-reconfiguration inbound",
4265 NO_STR NEIGHBOR_STR NEIGHBOR_ADDR_STR2
4266 "Per neighbor soft reconfiguration\n"
4267 "Allow inbound soft reconfiguration for this neighbor\n")
4268
4269 DEFUN (neighbor_route_reflector_client,
4270 neighbor_route_reflector_client_cmd,
4271 "neighbor <A.B.C.D|X:X::X:X|WORD> route-reflector-client",
4272 NEIGHBOR_STR
4273 NEIGHBOR_ADDR_STR2
4274 "Configure a neighbor as Route Reflector client\n")
4275 {
4276 int idx_peer = 1;
4277 struct peer *peer;
4278
4279
4280 peer = peer_and_group_lookup_vty(vty, argv[idx_peer]->arg);
4281 if (!peer)
4282 return CMD_WARNING_CONFIG_FAILED;
4283
4284 return peer_af_flag_set_vty(vty, argv[idx_peer]->arg, bgp_node_afi(vty),
4285 bgp_node_safi(vty),
4286 PEER_FLAG_REFLECTOR_CLIENT);
4287 }
4288
4289 ALIAS_HIDDEN(neighbor_route_reflector_client,
4290 neighbor_route_reflector_client_hidden_cmd,
4291 "neighbor <A.B.C.D|X:X::X:X|WORD> route-reflector-client",
4292 NEIGHBOR_STR NEIGHBOR_ADDR_STR2
4293 "Configure a neighbor as Route Reflector client\n")
4294
4295 DEFUN (no_neighbor_route_reflector_client,
4296 no_neighbor_route_reflector_client_cmd,
4297 "no neighbor <A.B.C.D|X:X::X:X|WORD> route-reflector-client",
4298 NO_STR
4299 NEIGHBOR_STR
4300 NEIGHBOR_ADDR_STR2
4301 "Configure a neighbor as Route Reflector client\n")
4302 {
4303 int idx_peer = 2;
4304 return peer_af_flag_unset_vty(vty, argv[idx_peer]->arg,
4305 bgp_node_afi(vty), bgp_node_safi(vty),
4306 PEER_FLAG_REFLECTOR_CLIENT);
4307 }
4308
4309 ALIAS_HIDDEN(no_neighbor_route_reflector_client,
4310 no_neighbor_route_reflector_client_hidden_cmd,
4311 "no neighbor <A.B.C.D|X:X::X:X|WORD> route-reflector-client",
4312 NO_STR NEIGHBOR_STR NEIGHBOR_ADDR_STR2
4313 "Configure a neighbor as Route Reflector client\n")
4314
4315 /* neighbor route-server-client. */
4316 DEFUN (neighbor_route_server_client,
4317 neighbor_route_server_client_cmd,
4318 "neighbor <A.B.C.D|X:X::X:X|WORD> route-server-client",
4319 NEIGHBOR_STR
4320 NEIGHBOR_ADDR_STR2
4321 "Configure a neighbor as Route Server client\n")
4322 {
4323 int idx_peer = 1;
4324 struct peer *peer;
4325
4326 peer = peer_and_group_lookup_vty(vty, argv[idx_peer]->arg);
4327 if (!peer)
4328 return CMD_WARNING_CONFIG_FAILED;
4329 return peer_af_flag_set_vty(vty, argv[idx_peer]->arg, bgp_node_afi(vty),
4330 bgp_node_safi(vty),
4331 PEER_FLAG_RSERVER_CLIENT);
4332 }
4333
4334 ALIAS_HIDDEN(neighbor_route_server_client,
4335 neighbor_route_server_client_hidden_cmd,
4336 "neighbor <A.B.C.D|X:X::X:X|WORD> route-server-client",
4337 NEIGHBOR_STR NEIGHBOR_ADDR_STR2
4338 "Configure a neighbor as Route Server client\n")
4339
4340 DEFUN (no_neighbor_route_server_client,
4341 no_neighbor_route_server_client_cmd,
4342 "no neighbor <A.B.C.D|X:X::X:X|WORD> route-server-client",
4343 NO_STR
4344 NEIGHBOR_STR
4345 NEIGHBOR_ADDR_STR2
4346 "Configure a neighbor as Route Server client\n")
4347 {
4348 int idx_peer = 2;
4349 return peer_af_flag_unset_vty(vty, argv[idx_peer]->arg,
4350 bgp_node_afi(vty), bgp_node_safi(vty),
4351 PEER_FLAG_RSERVER_CLIENT);
4352 }
4353
4354 ALIAS_HIDDEN(no_neighbor_route_server_client,
4355 no_neighbor_route_server_client_hidden_cmd,
4356 "no neighbor <A.B.C.D|X:X::X:X|WORD> route-server-client",
4357 NO_STR NEIGHBOR_STR NEIGHBOR_ADDR_STR2
4358 "Configure a neighbor as Route Server client\n")
4359
4360 DEFUN (neighbor_nexthop_local_unchanged,
4361 neighbor_nexthop_local_unchanged_cmd,
4362 "neighbor <A.B.C.D|X:X::X:X|WORD> nexthop-local unchanged",
4363 NEIGHBOR_STR
4364 NEIGHBOR_ADDR_STR2
4365 "Configure treatment of outgoing link-local nexthop attribute\n"
4366 "Leave link-local nexthop unchanged for this peer\n")
4367 {
4368 int idx_peer = 1;
4369 return peer_af_flag_set_vty(vty, argv[idx_peer]->arg, bgp_node_afi(vty),
4370 bgp_node_safi(vty),
4371 PEER_FLAG_NEXTHOP_LOCAL_UNCHANGED);
4372 }
4373
4374 DEFUN (no_neighbor_nexthop_local_unchanged,
4375 no_neighbor_nexthop_local_unchanged_cmd,
4376 "no neighbor <A.B.C.D|X:X::X:X|WORD> nexthop-local unchanged",
4377 NO_STR
4378 NEIGHBOR_STR
4379 NEIGHBOR_ADDR_STR2
4380 "Configure treatment of outgoing link-local-nexthop attribute\n"
4381 "Leave link-local nexthop unchanged for this peer\n")
4382 {
4383 int idx_peer = 2;
4384 return peer_af_flag_unset_vty(vty, argv[idx_peer]->arg,
4385 bgp_node_afi(vty), bgp_node_safi(vty),
4386 PEER_FLAG_NEXTHOP_LOCAL_UNCHANGED);
4387 }
4388
4389 DEFUN (neighbor_attr_unchanged,
4390 neighbor_attr_unchanged_cmd,
4391 "neighbor <A.B.C.D|X:X::X:X|WORD> attribute-unchanged [{as-path|next-hop|med}]",
4392 NEIGHBOR_STR
4393 NEIGHBOR_ADDR_STR2
4394 "BGP attribute is propagated unchanged to this neighbor\n"
4395 "As-path attribute\n"
4396 "Nexthop attribute\n"
4397 "Med attribute\n")
4398 {
4399 int idx = 0;
4400 char *peer_str = argv[1]->arg;
4401 struct peer *peer;
4402 uint16_t flags = 0;
4403 afi_t afi = bgp_node_afi(vty);
4404 safi_t safi = bgp_node_safi(vty);
4405
4406 peer = peer_and_group_lookup_vty(vty, peer_str);
4407 if (!peer)
4408 return CMD_WARNING_CONFIG_FAILED;
4409
4410 if (argv_find(argv, argc, "as-path", &idx))
4411 SET_FLAG(flags, PEER_FLAG_AS_PATH_UNCHANGED);
4412 idx = 0;
4413 if (argv_find(argv, argc, "next-hop", &idx))
4414 SET_FLAG(flags, PEER_FLAG_NEXTHOP_UNCHANGED);
4415 idx = 0;
4416 if (argv_find(argv, argc, "med", &idx))
4417 SET_FLAG(flags, PEER_FLAG_MED_UNCHANGED);
4418
4419 /* no flags means all of them! */
4420 if (!flags) {
4421 SET_FLAG(flags, PEER_FLAG_AS_PATH_UNCHANGED);
4422 SET_FLAG(flags, PEER_FLAG_NEXTHOP_UNCHANGED);
4423 SET_FLAG(flags, PEER_FLAG_MED_UNCHANGED);
4424 } else {
4425 if (!CHECK_FLAG(flags, PEER_FLAG_AS_PATH_UNCHANGED)
4426 && peer_af_flag_check(peer, afi, safi,
4427 PEER_FLAG_AS_PATH_UNCHANGED)) {
4428 peer_af_flag_unset_vty(vty, peer_str, afi, safi,
4429 PEER_FLAG_AS_PATH_UNCHANGED);
4430 }
4431
4432 if (!CHECK_FLAG(flags, PEER_FLAG_NEXTHOP_UNCHANGED)
4433 && peer_af_flag_check(peer, afi, safi,
4434 PEER_FLAG_NEXTHOP_UNCHANGED)) {
4435 peer_af_flag_unset_vty(vty, peer_str, afi, safi,
4436 PEER_FLAG_NEXTHOP_UNCHANGED);
4437 }
4438
4439 if (!CHECK_FLAG(flags, PEER_FLAG_MED_UNCHANGED)
4440 && peer_af_flag_check(peer, afi, safi,
4441 PEER_FLAG_MED_UNCHANGED)) {
4442 peer_af_flag_unset_vty(vty, peer_str, afi, safi,
4443 PEER_FLAG_MED_UNCHANGED);
4444 }
4445 }
4446
4447 return peer_af_flag_set_vty(vty, peer_str, afi, safi, flags);
4448 }
4449
4450 ALIAS_HIDDEN(
4451 neighbor_attr_unchanged, neighbor_attr_unchanged_hidden_cmd,
4452 "neighbor <A.B.C.D|X:X::X:X|WORD> attribute-unchanged [{as-path|next-hop|med}]",
4453 NEIGHBOR_STR NEIGHBOR_ADDR_STR2
4454 "BGP attribute is propagated unchanged to this neighbor\n"
4455 "As-path attribute\n"
4456 "Nexthop attribute\n"
4457 "Med attribute\n")
4458
4459 DEFUN (no_neighbor_attr_unchanged,
4460 no_neighbor_attr_unchanged_cmd,
4461 "no neighbor <A.B.C.D|X:X::X:X|WORD> attribute-unchanged [{as-path|next-hop|med}]",
4462 NO_STR
4463 NEIGHBOR_STR
4464 NEIGHBOR_ADDR_STR2
4465 "BGP attribute is propagated unchanged to this neighbor\n"
4466 "As-path attribute\n"
4467 "Nexthop attribute\n"
4468 "Med attribute\n")
4469 {
4470 int idx = 0;
4471 char *peer = argv[2]->arg;
4472 uint16_t flags = 0;
4473
4474 if (argv_find(argv, argc, "as-path", &idx))
4475 SET_FLAG(flags, PEER_FLAG_AS_PATH_UNCHANGED);
4476 idx = 0;
4477 if (argv_find(argv, argc, "next-hop", &idx))
4478 SET_FLAG(flags, PEER_FLAG_NEXTHOP_UNCHANGED);
4479 idx = 0;
4480 if (argv_find(argv, argc, "med", &idx))
4481 SET_FLAG(flags, PEER_FLAG_MED_UNCHANGED);
4482
4483 if (!flags) // no flags means all of them!
4484 {
4485 SET_FLAG(flags, PEER_FLAG_AS_PATH_UNCHANGED);
4486 SET_FLAG(flags, PEER_FLAG_NEXTHOP_UNCHANGED);
4487 SET_FLAG(flags, PEER_FLAG_MED_UNCHANGED);
4488 }
4489
4490 return peer_af_flag_unset_vty(vty, peer, bgp_node_afi(vty),
4491 bgp_node_safi(vty), flags);
4492 }
4493
4494 ALIAS_HIDDEN(
4495 no_neighbor_attr_unchanged, no_neighbor_attr_unchanged_hidden_cmd,
4496 "no neighbor <A.B.C.D|X:X::X:X|WORD> attribute-unchanged [{as-path|next-hop|med}]",
4497 NO_STR NEIGHBOR_STR NEIGHBOR_ADDR_STR2
4498 "BGP attribute is propagated unchanged to this neighbor\n"
4499 "As-path attribute\n"
4500 "Nexthop attribute\n"
4501 "Med attribute\n")
4502
4503 /* EBGP multihop configuration. */
4504 static int peer_ebgp_multihop_set_vty(struct vty *vty, const char *ip_str,
4505 const char *ttl_str)
4506 {
4507 struct peer *peer;
4508 unsigned int ttl;
4509
4510 peer = peer_and_group_lookup_vty(vty, ip_str);
4511 if (!peer)
4512 return CMD_WARNING_CONFIG_FAILED;
4513
4514 if (peer->conf_if)
4515 return bgp_vty_return(vty, BGP_ERR_INVALID_FOR_DIRECT_PEER);
4516
4517 if (!ttl_str)
4518 ttl = MAXTTL;
4519 else
4520 ttl = strtoul(ttl_str, NULL, 10);
4521
4522 return bgp_vty_return(vty, peer_ebgp_multihop_set(peer, ttl));
4523 }
4524
4525 static int peer_ebgp_multihop_unset_vty(struct vty *vty, const char *ip_str)
4526 {
4527 struct peer *peer;
4528
4529 peer = peer_and_group_lookup_vty(vty, ip_str);
4530 if (!peer)
4531 return CMD_WARNING_CONFIG_FAILED;
4532
4533 return bgp_vty_return(vty, peer_ebgp_multihop_unset(peer));
4534 }
4535
4536 /* neighbor ebgp-multihop. */
4537 DEFUN (neighbor_ebgp_multihop,
4538 neighbor_ebgp_multihop_cmd,
4539 "neighbor <A.B.C.D|X:X::X:X|WORD> ebgp-multihop",
4540 NEIGHBOR_STR
4541 NEIGHBOR_ADDR_STR2
4542 "Allow EBGP neighbors not on directly connected networks\n")
4543 {
4544 int idx_peer = 1;
4545 return peer_ebgp_multihop_set_vty(vty, argv[idx_peer]->arg, NULL);
4546 }
4547
4548 DEFUN (neighbor_ebgp_multihop_ttl,
4549 neighbor_ebgp_multihop_ttl_cmd,
4550 "neighbor <A.B.C.D|X:X::X:X|WORD> ebgp-multihop (1-255)",
4551 NEIGHBOR_STR
4552 NEIGHBOR_ADDR_STR2
4553 "Allow EBGP neighbors not on directly connected networks\n"
4554 "maximum hop count\n")
4555 {
4556 int idx_peer = 1;
4557 int idx_number = 3;
4558 return peer_ebgp_multihop_set_vty(vty, argv[idx_peer]->arg,
4559 argv[idx_number]->arg);
4560 }
4561
4562 DEFUN (no_neighbor_ebgp_multihop,
4563 no_neighbor_ebgp_multihop_cmd,
4564 "no neighbor <A.B.C.D|X:X::X:X|WORD> ebgp-multihop [(1-255)]",
4565 NO_STR
4566 NEIGHBOR_STR
4567 NEIGHBOR_ADDR_STR2
4568 "Allow EBGP neighbors not on directly connected networks\n"
4569 "maximum hop count\n")
4570 {
4571 int idx_peer = 2;
4572 return peer_ebgp_multihop_unset_vty(vty, argv[idx_peer]->arg);
4573 }
4574
4575
4576 /* disable-connected-check */
4577 DEFUN (neighbor_disable_connected_check,
4578 neighbor_disable_connected_check_cmd,
4579 "neighbor <A.B.C.D|X:X::X:X|WORD> <disable-connected-check|enforce-multihop>",
4580 NEIGHBOR_STR
4581 NEIGHBOR_ADDR_STR2
4582 "one-hop away EBGP peer using loopback address\n"
4583 "Enforce EBGP neighbors perform multihop\n")
4584 {
4585 int idx_peer = 1;
4586 return peer_flag_set_vty(vty, argv[idx_peer]->arg,
4587 PEER_FLAG_DISABLE_CONNECTED_CHECK);
4588 }
4589
4590 DEFUN (no_neighbor_disable_connected_check,
4591 no_neighbor_disable_connected_check_cmd,
4592 "no neighbor <A.B.C.D|X:X::X:X|WORD> <disable-connected-check|enforce-multihop>",
4593 NO_STR
4594 NEIGHBOR_STR
4595 NEIGHBOR_ADDR_STR2
4596 "one-hop away EBGP peer using loopback address\n"
4597 "Enforce EBGP neighbors perform multihop\n")
4598 {
4599 int idx_peer = 2;
4600 return peer_flag_unset_vty(vty, argv[idx_peer]->arg,
4601 PEER_FLAG_DISABLE_CONNECTED_CHECK);
4602 }
4603
4604
4605 /* enforce-first-as */
4606 DEFUN (neighbor_enforce_first_as,
4607 neighbor_enforce_first_as_cmd,
4608 "neighbor <A.B.C.D|X:X::X:X|WORD> enforce-first-as",
4609 NEIGHBOR_STR
4610 NEIGHBOR_ADDR_STR2
4611 "Enforce the first AS for EBGP routes\n")
4612 {
4613 int idx_peer = 1;
4614
4615 return peer_flag_set_vty(vty, argv[idx_peer]->arg,
4616 PEER_FLAG_ENFORCE_FIRST_AS);
4617 }
4618
4619 DEFUN (no_neighbor_enforce_first_as,
4620 no_neighbor_enforce_first_as_cmd,
4621 "no neighbor <A.B.C.D|X:X::X:X|WORD> enforce-first-as",
4622 NO_STR
4623 NEIGHBOR_STR
4624 NEIGHBOR_ADDR_STR2
4625 "Enforce the first AS for EBGP routes\n")
4626 {
4627 int idx_peer = 2;
4628
4629 return peer_flag_unset_vty(vty, argv[idx_peer]->arg,
4630 PEER_FLAG_ENFORCE_FIRST_AS);
4631 }
4632
4633
4634 DEFUN (neighbor_description,
4635 neighbor_description_cmd,
4636 "neighbor <A.B.C.D|X:X::X:X|WORD> description LINE...",
4637 NEIGHBOR_STR
4638 NEIGHBOR_ADDR_STR2
4639 "Neighbor specific description\n"
4640 "Up to 80 characters describing this neighbor\n")
4641 {
4642 int idx_peer = 1;
4643 int idx_line = 3;
4644 struct peer *peer;
4645 char *str;
4646
4647 peer = peer_and_group_lookup_vty(vty, argv[idx_peer]->arg);
4648 if (!peer)
4649 return CMD_WARNING_CONFIG_FAILED;
4650
4651 str = argv_concat(argv, argc, idx_line);
4652
4653 peer_description_set(peer, str);
4654
4655 XFREE(MTYPE_TMP, str);
4656
4657 return CMD_SUCCESS;
4658 }
4659
4660 DEFUN (no_neighbor_description,
4661 no_neighbor_description_cmd,
4662 "no neighbor <A.B.C.D|X:X::X:X|WORD> description",
4663 NO_STR
4664 NEIGHBOR_STR
4665 NEIGHBOR_ADDR_STR2
4666 "Neighbor specific description\n")
4667 {
4668 int idx_peer = 2;
4669 struct peer *peer;
4670
4671 peer = peer_and_group_lookup_vty(vty, argv[idx_peer]->arg);
4672 if (!peer)
4673 return CMD_WARNING_CONFIG_FAILED;
4674
4675 peer_description_unset(peer);
4676
4677 return CMD_SUCCESS;
4678 }
4679
4680 ALIAS(no_neighbor_description, no_neighbor_description_comment_cmd,
4681 "no neighbor <A.B.C.D|X:X::X:X|WORD> description LINE...",
4682 NO_STR NEIGHBOR_STR NEIGHBOR_ADDR_STR2
4683 "Neighbor specific description\n"
4684 "Up to 80 characters describing this neighbor\n")
4685
4686 /* Neighbor update-source. */
4687 static int peer_update_source_vty(struct vty *vty, const char *peer_str,
4688 const char *source_str)
4689 {
4690 struct peer *peer;
4691 struct prefix p;
4692 union sockunion su;
4693
4694 peer = peer_and_group_lookup_vty(vty, peer_str);
4695 if (!peer)
4696 return CMD_WARNING_CONFIG_FAILED;
4697
4698 if (peer->conf_if)
4699 return CMD_WARNING;
4700
4701 if (source_str) {
4702 if (str2sockunion(source_str, &su) == 0)
4703 peer_update_source_addr_set(peer, &su);
4704 else {
4705 if (str2prefix(source_str, &p)) {
4706 vty_out(vty,
4707 "%% Invalid update-source, remove prefix length \n");
4708 return CMD_WARNING_CONFIG_FAILED;
4709 } else
4710 peer_update_source_if_set(peer, source_str);
4711 }
4712 } else
4713 peer_update_source_unset(peer);
4714
4715 return CMD_SUCCESS;
4716 }
4717
4718 #define BGP_UPDATE_SOURCE_HELP_STR \
4719 "IPv4 address\n" \
4720 "IPv6 address\n" \
4721 "Interface name (requires zebra to be running)\n"
4722
4723 DEFUN (neighbor_update_source,
4724 neighbor_update_source_cmd,
4725 "neighbor <A.B.C.D|X:X::X:X|WORD> update-source <A.B.C.D|X:X::X:X|WORD>",
4726 NEIGHBOR_STR
4727 NEIGHBOR_ADDR_STR2
4728 "Source of routing updates\n"
4729 BGP_UPDATE_SOURCE_HELP_STR)
4730 {
4731 int idx_peer = 1;
4732 int idx_peer_2 = 3;
4733 return peer_update_source_vty(vty, argv[idx_peer]->arg,
4734 argv[idx_peer_2]->arg);
4735 }
4736
4737 DEFUN (no_neighbor_update_source,
4738 no_neighbor_update_source_cmd,
4739 "no neighbor <A.B.C.D|X:X::X:X|WORD> update-source [<A.B.C.D|X:X::X:X|WORD>]",
4740 NO_STR
4741 NEIGHBOR_STR
4742 NEIGHBOR_ADDR_STR2
4743 "Source of routing updates\n"
4744 BGP_UPDATE_SOURCE_HELP_STR)
4745 {
4746 int idx_peer = 2;
4747 return peer_update_source_vty(vty, argv[idx_peer]->arg, NULL);
4748 }
4749
4750 static int peer_default_originate_set_vty(struct vty *vty, const char *peer_str,
4751 afi_t afi, safi_t safi,
4752 const char *rmap, int set)
4753 {
4754 int ret;
4755 struct peer *peer;
4756
4757 peer = peer_and_group_lookup_vty(vty, peer_str);
4758 if (!peer)
4759 return CMD_WARNING_CONFIG_FAILED;
4760
4761 if (set)
4762 ret = peer_default_originate_set(peer, afi, safi, rmap);
4763 else
4764 ret = peer_default_originate_unset(peer, afi, safi);
4765
4766 return bgp_vty_return(vty, ret);
4767 }
4768
4769 /* neighbor default-originate. */
4770 DEFUN (neighbor_default_originate,
4771 neighbor_default_originate_cmd,
4772 "neighbor <A.B.C.D|X:X::X:X|WORD> default-originate",
4773 NEIGHBOR_STR
4774 NEIGHBOR_ADDR_STR2
4775 "Originate default route to this neighbor\n")
4776 {
4777 int idx_peer = 1;
4778 return peer_default_originate_set_vty(vty, argv[idx_peer]->arg,
4779 bgp_node_afi(vty),
4780 bgp_node_safi(vty), NULL, 1);
4781 }
4782
4783 ALIAS_HIDDEN(neighbor_default_originate, neighbor_default_originate_hidden_cmd,
4784 "neighbor <A.B.C.D|X:X::X:X|WORD> default-originate",
4785 NEIGHBOR_STR NEIGHBOR_ADDR_STR2
4786 "Originate default route to this neighbor\n")
4787
4788 DEFUN (neighbor_default_originate_rmap,
4789 neighbor_default_originate_rmap_cmd,
4790 "neighbor <A.B.C.D|X:X::X:X|WORD> default-originate route-map WORD",
4791 NEIGHBOR_STR
4792 NEIGHBOR_ADDR_STR2
4793 "Originate default route to this neighbor\n"
4794 "Route-map to specify criteria to originate default\n"
4795 "route-map name\n")
4796 {
4797 int idx_peer = 1;
4798 int idx_word = 4;
4799 return peer_default_originate_set_vty(
4800 vty, argv[idx_peer]->arg, bgp_node_afi(vty), bgp_node_safi(vty),
4801 argv[idx_word]->arg, 1);
4802 }
4803
4804 ALIAS_HIDDEN(
4805 neighbor_default_originate_rmap,
4806 neighbor_default_originate_rmap_hidden_cmd,
4807 "neighbor <A.B.C.D|X:X::X:X|WORD> default-originate route-map WORD",
4808 NEIGHBOR_STR NEIGHBOR_ADDR_STR2
4809 "Originate default route to this neighbor\n"
4810 "Route-map to specify criteria to originate default\n"
4811 "route-map name\n")
4812
4813 DEFUN (no_neighbor_default_originate,
4814 no_neighbor_default_originate_cmd,
4815 "no neighbor <A.B.C.D|X:X::X:X|WORD> default-originate [route-map WORD]",
4816 NO_STR
4817 NEIGHBOR_STR
4818 NEIGHBOR_ADDR_STR2
4819 "Originate default route to this neighbor\n"
4820 "Route-map to specify criteria to originate default\n"
4821 "route-map name\n")
4822 {
4823 int idx_peer = 2;
4824 return peer_default_originate_set_vty(vty, argv[idx_peer]->arg,
4825 bgp_node_afi(vty),
4826 bgp_node_safi(vty), NULL, 0);
4827 }
4828
4829 ALIAS_HIDDEN(
4830 no_neighbor_default_originate, no_neighbor_default_originate_hidden_cmd,
4831 "no neighbor <A.B.C.D|X:X::X:X|WORD> default-originate [route-map WORD]",
4832 NO_STR NEIGHBOR_STR NEIGHBOR_ADDR_STR2
4833 "Originate default route to this neighbor\n"
4834 "Route-map to specify criteria to originate default\n"
4835 "route-map name\n")
4836
4837
4838 /* Set neighbor's BGP port. */
4839 static int peer_port_vty(struct vty *vty, const char *ip_str, int afi,
4840 const char *port_str)
4841 {
4842 struct peer *peer;
4843 uint16_t port;
4844 struct servent *sp;
4845
4846 peer = peer_lookup_vty(vty, ip_str);
4847 if (!peer)
4848 return CMD_WARNING_CONFIG_FAILED;
4849
4850 if (!port_str) {
4851 sp = getservbyname("bgp", "tcp");
4852 port = (sp == NULL) ? BGP_PORT_DEFAULT : ntohs(sp->s_port);
4853 } else {
4854 port = strtoul(port_str, NULL, 10);
4855 }
4856
4857 peer_port_set(peer, port);
4858
4859 return CMD_SUCCESS;
4860 }
4861
4862 /* Set specified peer's BGP port. */
4863 DEFUN (neighbor_port,
4864 neighbor_port_cmd,
4865 "neighbor <A.B.C.D|X:X::X:X> port (0-65535)",
4866 NEIGHBOR_STR
4867 NEIGHBOR_ADDR_STR
4868 "Neighbor's BGP port\n"
4869 "TCP port number\n")
4870 {
4871 int idx_ip = 1;
4872 int idx_number = 3;
4873 return peer_port_vty(vty, argv[idx_ip]->arg, AFI_IP,
4874 argv[idx_number]->arg);
4875 }
4876
4877 DEFUN (no_neighbor_port,
4878 no_neighbor_port_cmd,
4879 "no neighbor <A.B.C.D|X:X::X:X> port [(0-65535)]",
4880 NO_STR
4881 NEIGHBOR_STR
4882 NEIGHBOR_ADDR_STR
4883 "Neighbor's BGP port\n"
4884 "TCP port number\n")
4885 {
4886 int idx_ip = 2;
4887 return peer_port_vty(vty, argv[idx_ip]->arg, AFI_IP, NULL);
4888 }
4889
4890
4891 /* neighbor weight. */
4892 static int peer_weight_set_vty(struct vty *vty, const char *ip_str, afi_t afi,
4893 safi_t safi, const char *weight_str)
4894 {
4895 int ret;
4896 struct peer *peer;
4897 unsigned long weight;
4898
4899 peer = peer_and_group_lookup_vty(vty, ip_str);
4900 if (!peer)
4901 return CMD_WARNING_CONFIG_FAILED;
4902
4903 weight = strtoul(weight_str, NULL, 10);
4904
4905 ret = peer_weight_set(peer, afi, safi, weight);
4906 return bgp_vty_return(vty, ret);
4907 }
4908
4909 static int peer_weight_unset_vty(struct vty *vty, const char *ip_str, afi_t afi,
4910 safi_t safi)
4911 {
4912 int ret;
4913 struct peer *peer;
4914
4915 peer = peer_and_group_lookup_vty(vty, ip_str);
4916 if (!peer)
4917 return CMD_WARNING_CONFIG_FAILED;
4918
4919 ret = peer_weight_unset(peer, afi, safi);
4920 return bgp_vty_return(vty, ret);
4921 }
4922
4923 DEFUN (neighbor_weight,
4924 neighbor_weight_cmd,
4925 "neighbor <A.B.C.D|X:X::X:X|WORD> weight (0-65535)",
4926 NEIGHBOR_STR
4927 NEIGHBOR_ADDR_STR2
4928 "Set default weight for routes from this neighbor\n"
4929 "default weight\n")
4930 {
4931 int idx_peer = 1;
4932 int idx_number = 3;
4933 return peer_weight_set_vty(vty, argv[idx_peer]->arg, bgp_node_afi(vty),
4934 bgp_node_safi(vty), argv[idx_number]->arg);
4935 }
4936
4937 ALIAS_HIDDEN(neighbor_weight, neighbor_weight_hidden_cmd,
4938 "neighbor <A.B.C.D|X:X::X:X|WORD> weight (0-65535)",
4939 NEIGHBOR_STR NEIGHBOR_ADDR_STR2
4940 "Set default weight for routes from this neighbor\n"
4941 "default weight\n")
4942
4943 DEFUN (no_neighbor_weight,
4944 no_neighbor_weight_cmd,
4945 "no neighbor <A.B.C.D|X:X::X:X|WORD> weight [(0-65535)]",
4946 NO_STR
4947 NEIGHBOR_STR
4948 NEIGHBOR_ADDR_STR2
4949 "Set default weight for routes from this neighbor\n"
4950 "default weight\n")
4951 {
4952 int idx_peer = 2;
4953 return peer_weight_unset_vty(vty, argv[idx_peer]->arg,
4954 bgp_node_afi(vty), bgp_node_safi(vty));
4955 }
4956
4957 ALIAS_HIDDEN(no_neighbor_weight, no_neighbor_weight_hidden_cmd,
4958 "no neighbor <A.B.C.D|X:X::X:X|WORD> weight [(0-65535)]",
4959 NO_STR NEIGHBOR_STR NEIGHBOR_ADDR_STR2
4960 "Set default weight for routes from this neighbor\n"
4961 "default weight\n")
4962
4963
4964 /* Override capability negotiation. */
4965 DEFUN (neighbor_override_capability,
4966 neighbor_override_capability_cmd,
4967 "neighbor <A.B.C.D|X:X::X:X|WORD> override-capability",
4968 NEIGHBOR_STR
4969 NEIGHBOR_ADDR_STR2
4970 "Override capability negotiation result\n")
4971 {
4972 int idx_peer = 1;
4973 return peer_flag_set_vty(vty, argv[idx_peer]->arg,
4974 PEER_FLAG_OVERRIDE_CAPABILITY);
4975 }
4976
4977 DEFUN (no_neighbor_override_capability,
4978 no_neighbor_override_capability_cmd,
4979 "no neighbor <A.B.C.D|X:X::X:X|WORD> override-capability",
4980 NO_STR
4981 NEIGHBOR_STR
4982 NEIGHBOR_ADDR_STR2
4983 "Override capability negotiation result\n")
4984 {
4985 int idx_peer = 2;
4986 return peer_flag_unset_vty(vty, argv[idx_peer]->arg,
4987 PEER_FLAG_OVERRIDE_CAPABILITY);
4988 }
4989
4990 DEFUN (neighbor_strict_capability,
4991 neighbor_strict_capability_cmd,
4992 "neighbor <A.B.C.D|X:X::X:X|WORD> strict-capability-match",
4993 NEIGHBOR_STR
4994 NEIGHBOR_ADDR_STR2
4995 "Strict capability negotiation match\n")
4996 {
4997 int idx_peer = 1;
4998
4999 return peer_flag_set_vty(vty, argv[idx_peer]->arg,
5000 PEER_FLAG_STRICT_CAP_MATCH);
5001 }
5002
5003 DEFUN (no_neighbor_strict_capability,
5004 no_neighbor_strict_capability_cmd,
5005 "no neighbor <A.B.C.D|X:X::X:X|WORD> strict-capability-match",
5006 NO_STR
5007 NEIGHBOR_STR
5008 NEIGHBOR_ADDR_STR2
5009 "Strict capability negotiation match\n")
5010 {
5011 int idx_peer = 2;
5012
5013 return peer_flag_unset_vty(vty, argv[idx_peer]->arg,
5014 PEER_FLAG_STRICT_CAP_MATCH);
5015 }
5016
5017 static int peer_timers_set_vty(struct vty *vty, const char *ip_str,
5018 const char *keep_str, const char *hold_str)
5019 {
5020 int ret;
5021 struct peer *peer;
5022 uint32_t keepalive;
5023 uint32_t holdtime;
5024
5025 peer = peer_and_group_lookup_vty(vty, ip_str);
5026 if (!peer)
5027 return CMD_WARNING_CONFIG_FAILED;
5028
5029 keepalive = strtoul(keep_str, NULL, 10);
5030 holdtime = strtoul(hold_str, NULL, 10);
5031
5032 ret = peer_timers_set(peer, keepalive, holdtime);
5033
5034 return bgp_vty_return(vty, ret);
5035 }
5036
5037 static int peer_timers_unset_vty(struct vty *vty, const char *ip_str)
5038 {
5039 int ret;
5040 struct peer *peer;
5041
5042 peer = peer_and_group_lookup_vty(vty, ip_str);
5043 if (!peer)
5044 return CMD_WARNING_CONFIG_FAILED;
5045
5046 ret = peer_timers_unset(peer);
5047
5048 return bgp_vty_return(vty, ret);
5049 }
5050
5051 DEFUN (neighbor_timers,
5052 neighbor_timers_cmd,
5053 "neighbor <A.B.C.D|X:X::X:X|WORD> timers (0-65535) (0-65535)",
5054 NEIGHBOR_STR
5055 NEIGHBOR_ADDR_STR2
5056 "BGP per neighbor timers\n"
5057 "Keepalive interval\n"
5058 "Holdtime\n")
5059 {
5060 int idx_peer = 1;
5061 int idx_number = 3;
5062 int idx_number_2 = 4;
5063 return peer_timers_set_vty(vty, argv[idx_peer]->arg,
5064 argv[idx_number]->arg,
5065 argv[idx_number_2]->arg);
5066 }
5067
5068 DEFUN (no_neighbor_timers,
5069 no_neighbor_timers_cmd,
5070 "no neighbor <A.B.C.D|X:X::X:X|WORD> timers [(0-65535) (0-65535)]",
5071 NO_STR
5072 NEIGHBOR_STR
5073 NEIGHBOR_ADDR_STR2
5074 "BGP per neighbor timers\n"
5075 "Keepalive interval\n"
5076 "Holdtime\n")
5077 {
5078 int idx_peer = 2;
5079 return peer_timers_unset_vty(vty, argv[idx_peer]->arg);
5080 }
5081
5082
5083 static int peer_timers_connect_set_vty(struct vty *vty, const char *ip_str,
5084 const char *time_str)
5085 {
5086 int ret;
5087 struct peer *peer;
5088 uint32_t connect;
5089
5090 peer = peer_and_group_lookup_vty(vty, ip_str);
5091 if (!peer)
5092 return CMD_WARNING_CONFIG_FAILED;
5093
5094 connect = strtoul(time_str, NULL, 10);
5095
5096 ret = peer_timers_connect_set(peer, connect);
5097
5098 return bgp_vty_return(vty, ret);
5099 }
5100
5101 static int peer_timers_connect_unset_vty(struct vty *vty, const char *ip_str)
5102 {
5103 int ret;
5104 struct peer *peer;
5105
5106 peer = peer_and_group_lookup_vty(vty, ip_str);
5107 if (!peer)
5108 return CMD_WARNING_CONFIG_FAILED;
5109
5110 ret = peer_timers_connect_unset(peer);
5111
5112 return bgp_vty_return(vty, ret);
5113 }
5114
5115 DEFUN (neighbor_timers_connect,
5116 neighbor_timers_connect_cmd,
5117 "neighbor <A.B.C.D|X:X::X:X|WORD> timers connect (1-65535)",
5118 NEIGHBOR_STR
5119 NEIGHBOR_ADDR_STR2
5120 "BGP per neighbor timers\n"
5121 "BGP connect timer\n"
5122 "Connect timer\n")
5123 {
5124 int idx_peer = 1;
5125 int idx_number = 4;
5126 return peer_timers_connect_set_vty(vty, argv[idx_peer]->arg,
5127 argv[idx_number]->arg);
5128 }
5129
5130 DEFUN (no_neighbor_timers_connect,
5131 no_neighbor_timers_connect_cmd,
5132 "no neighbor <A.B.C.D|X:X::X:X|WORD> timers connect [(1-65535)]",
5133 NO_STR
5134 NEIGHBOR_STR
5135 NEIGHBOR_ADDR_STR2
5136 "BGP per neighbor timers\n"
5137 "BGP connect timer\n"
5138 "Connect timer\n")
5139 {
5140 int idx_peer = 2;
5141 return peer_timers_connect_unset_vty(vty, argv[idx_peer]->arg);
5142 }
5143
5144
5145 static int peer_advertise_interval_vty(struct vty *vty, const char *ip_str,
5146 const char *time_str, int set)
5147 {
5148 int ret;
5149 struct peer *peer;
5150 uint32_t routeadv = 0;
5151
5152 peer = peer_and_group_lookup_vty(vty, ip_str);
5153 if (!peer)
5154 return CMD_WARNING_CONFIG_FAILED;
5155
5156 if (time_str)
5157 routeadv = strtoul(time_str, NULL, 10);
5158
5159 if (set)
5160 ret = peer_advertise_interval_set(peer, routeadv);
5161 else
5162 ret = peer_advertise_interval_unset(peer);
5163
5164 return bgp_vty_return(vty, ret);
5165 }
5166
5167 DEFUN (neighbor_advertise_interval,
5168 neighbor_advertise_interval_cmd,
5169 "neighbor <A.B.C.D|X:X::X:X|WORD> advertisement-interval (0-600)",
5170 NEIGHBOR_STR
5171 NEIGHBOR_ADDR_STR2
5172 "Minimum interval between sending BGP routing updates\n"
5173 "time in seconds\n")
5174 {
5175 int idx_peer = 1;
5176 int idx_number = 3;
5177 return peer_advertise_interval_vty(vty, argv[idx_peer]->arg,
5178 argv[idx_number]->arg, 1);
5179 }
5180
5181 DEFUN (no_neighbor_advertise_interval,
5182 no_neighbor_advertise_interval_cmd,
5183 "no neighbor <A.B.C.D|X:X::X:X|WORD> advertisement-interval [(0-600)]",
5184 NO_STR
5185 NEIGHBOR_STR
5186 NEIGHBOR_ADDR_STR2
5187 "Minimum interval between sending BGP routing updates\n"
5188 "time in seconds\n")
5189 {
5190 int idx_peer = 2;
5191 return peer_advertise_interval_vty(vty, argv[idx_peer]->arg, NULL, 0);
5192 }
5193
5194
5195 /* Time to wait before processing route-map updates */
5196 DEFUN (bgp_set_route_map_delay_timer,
5197 bgp_set_route_map_delay_timer_cmd,
5198 "bgp route-map delay-timer (0-600)",
5199 SET_STR
5200 "BGP route-map delay timer\n"
5201 "Time in secs to wait before processing route-map changes\n"
5202 "0 disables the timer, no route updates happen when route-maps change\n")
5203 {
5204 int idx_number = 3;
5205 uint32_t rmap_delay_timer;
5206
5207 if (argv[idx_number]->arg) {
5208 rmap_delay_timer = strtoul(argv[idx_number]->arg, NULL, 10);
5209 bm->rmap_update_timer = rmap_delay_timer;
5210
5211 /* if the dynamic update handling is being disabled, and a timer
5212 * is
5213 * running, stop the timer and act as if the timer has already
5214 * fired.
5215 */
5216 if (!rmap_delay_timer && bm->t_rmap_update) {
5217 BGP_TIMER_OFF(bm->t_rmap_update);
5218 thread_execute(bm->master, bgp_route_map_update_timer,
5219 NULL, 0);
5220 }
5221 return CMD_SUCCESS;
5222 } else {
5223 vty_out(vty, "%% BGP invalid route-map delay-timer\n");
5224 return CMD_WARNING_CONFIG_FAILED;
5225 }
5226 }
5227
5228 DEFUN (no_bgp_set_route_map_delay_timer,
5229 no_bgp_set_route_map_delay_timer_cmd,
5230 "no bgp route-map delay-timer [(0-600)]",
5231 NO_STR
5232 BGP_STR
5233 "Default BGP route-map delay timer\n"
5234 "Reset to default time to wait for processing route-map changes\n"
5235 "0 disables the timer, no route updates happen when route-maps change\n")
5236 {
5237
5238 bm->rmap_update_timer = RMAP_DEFAULT_UPDATE_TIMER;
5239
5240 return CMD_SUCCESS;
5241 }
5242
5243
5244 /* neighbor interface */
5245 static int peer_interface_vty(struct vty *vty, const char *ip_str,
5246 const char *str)
5247 {
5248 struct peer *peer;
5249
5250 peer = peer_lookup_vty(vty, ip_str);
5251 if (!peer || peer->conf_if) {
5252 vty_out(vty, "%% BGP invalid peer %s\n", ip_str);
5253 return CMD_WARNING_CONFIG_FAILED;
5254 }
5255
5256 if (str)
5257 peer_interface_set(peer, str);
5258 else
5259 peer_interface_unset(peer);
5260
5261 return CMD_SUCCESS;
5262 }
5263
5264 DEFUN (neighbor_interface,
5265 neighbor_interface_cmd,
5266 "neighbor <A.B.C.D|X:X::X:X> interface WORD",
5267 NEIGHBOR_STR
5268 NEIGHBOR_ADDR_STR
5269 "Interface\n"
5270 "Interface name\n")
5271 {
5272 int idx_ip = 1;
5273 int idx_word = 3;
5274 return peer_interface_vty(vty, argv[idx_ip]->arg, argv[idx_word]->arg);
5275 }
5276
5277 DEFUN (no_neighbor_interface,
5278 no_neighbor_interface_cmd,
5279 "no neighbor <A.B.C.D|X:X::X:X|WORD> interface WORD",
5280 NO_STR
5281 NEIGHBOR_STR
5282 NEIGHBOR_ADDR_STR2
5283 "Interface\n"
5284 "Interface name\n")
5285 {
5286 int idx_peer = 2;
5287 return peer_interface_vty(vty, argv[idx_peer]->arg, NULL);
5288 }
5289
5290 DEFUN (neighbor_distribute_list,
5291 neighbor_distribute_list_cmd,
5292 "neighbor <A.B.C.D|X:X::X:X|WORD> distribute-list <(1-199)|(1300-2699)|WORD> <in|out>",
5293 NEIGHBOR_STR
5294 NEIGHBOR_ADDR_STR2
5295 "Filter updates to/from this neighbor\n"
5296 "IP access-list number\n"
5297 "IP access-list number (expanded range)\n"
5298 "IP Access-list name\n"
5299 "Filter incoming updates\n"
5300 "Filter outgoing updates\n")
5301 {
5302 int idx_peer = 1;
5303 int idx_acl = 3;
5304 int direct, ret;
5305 struct peer *peer;
5306
5307 const char *pstr = argv[idx_peer]->arg;
5308 const char *acl = argv[idx_acl]->arg;
5309 const char *inout = argv[argc - 1]->text;
5310
5311 peer = peer_and_group_lookup_vty(vty, pstr);
5312 if (!peer)
5313 return CMD_WARNING_CONFIG_FAILED;
5314
5315 /* Check filter direction. */
5316 direct = strmatch(inout, "in") ? FILTER_IN : FILTER_OUT;
5317 ret = peer_distribute_set(peer, bgp_node_afi(vty), bgp_node_safi(vty),
5318 direct, acl);
5319
5320 return bgp_vty_return(vty, ret);
5321 }
5322
5323 ALIAS_HIDDEN(
5324 neighbor_distribute_list, neighbor_distribute_list_hidden_cmd,
5325 "neighbor <A.B.C.D|X:X::X:X|WORD> distribute-list <(1-199)|(1300-2699)|WORD> <in|out>",
5326 NEIGHBOR_STR NEIGHBOR_ADDR_STR2
5327 "Filter updates to/from this neighbor\n"
5328 "IP access-list number\n"
5329 "IP access-list number (expanded range)\n"
5330 "IP Access-list name\n"
5331 "Filter incoming updates\n"
5332 "Filter outgoing updates\n")
5333
5334 DEFUN (no_neighbor_distribute_list,
5335 no_neighbor_distribute_list_cmd,
5336 "no neighbor <A.B.C.D|X:X::X:X|WORD> distribute-list <(1-199)|(1300-2699)|WORD> <in|out>",
5337 NO_STR
5338 NEIGHBOR_STR
5339 NEIGHBOR_ADDR_STR2
5340 "Filter updates to/from this neighbor\n"
5341 "IP access-list number\n"
5342 "IP access-list number (expanded range)\n"
5343 "IP Access-list name\n"
5344 "Filter incoming updates\n"
5345 "Filter outgoing updates\n")
5346 {
5347 int idx_peer = 2;
5348 int direct, ret;
5349 struct peer *peer;
5350
5351 const char *pstr = argv[idx_peer]->arg;
5352 const char *inout = argv[argc - 1]->text;
5353
5354 peer = peer_and_group_lookup_vty(vty, pstr);
5355 if (!peer)
5356 return CMD_WARNING_CONFIG_FAILED;
5357
5358 /* Check filter direction. */
5359 direct = strmatch(inout, "in") ? FILTER_IN : FILTER_OUT;
5360 ret = peer_distribute_unset(peer, bgp_node_afi(vty), bgp_node_safi(vty),
5361 direct);
5362
5363 return bgp_vty_return(vty, ret);
5364 }
5365
5366 ALIAS_HIDDEN(
5367 no_neighbor_distribute_list, no_neighbor_distribute_list_hidden_cmd,
5368 "no neighbor <A.B.C.D|X:X::X:X|WORD> distribute-list <(1-199)|(1300-2699)|WORD> <in|out>",
5369 NO_STR NEIGHBOR_STR NEIGHBOR_ADDR_STR2
5370 "Filter updates to/from this neighbor\n"
5371 "IP access-list number\n"
5372 "IP access-list number (expanded range)\n"
5373 "IP Access-list name\n"
5374 "Filter incoming updates\n"
5375 "Filter outgoing updates\n")
5376
5377 /* Set prefix list to the peer. */
5378 static int peer_prefix_list_set_vty(struct vty *vty, const char *ip_str,
5379 afi_t afi, safi_t safi,
5380 const char *name_str,
5381 const char *direct_str)
5382 {
5383 int ret;
5384 int direct = FILTER_IN;
5385 struct peer *peer;
5386
5387 peer = peer_and_group_lookup_vty(vty, ip_str);
5388 if (!peer)
5389 return CMD_WARNING_CONFIG_FAILED;
5390
5391 /* Check filter direction. */
5392 if (strncmp(direct_str, "i", 1) == 0)
5393 direct = FILTER_IN;
5394 else if (strncmp(direct_str, "o", 1) == 0)
5395 direct = FILTER_OUT;
5396
5397 ret = peer_prefix_list_set(peer, afi, safi, direct, name_str);
5398
5399 return bgp_vty_return(vty, ret);
5400 }
5401
5402 static int peer_prefix_list_unset_vty(struct vty *vty, const char *ip_str,
5403 afi_t afi, safi_t safi,
5404 const char *direct_str)
5405 {
5406 int ret;
5407 struct peer *peer;
5408 int direct = FILTER_IN;
5409
5410 peer = peer_and_group_lookup_vty(vty, ip_str);
5411 if (!peer)
5412 return CMD_WARNING_CONFIG_FAILED;
5413
5414 /* Check filter direction. */
5415 if (strncmp(direct_str, "i", 1) == 0)
5416 direct = FILTER_IN;
5417 else if (strncmp(direct_str, "o", 1) == 0)
5418 direct = FILTER_OUT;
5419
5420 ret = peer_prefix_list_unset(peer, afi, safi, direct);
5421
5422 return bgp_vty_return(vty, ret);
5423 }
5424
5425 DEFUN (neighbor_prefix_list,
5426 neighbor_prefix_list_cmd,
5427 "neighbor <A.B.C.D|X:X::X:X|WORD> prefix-list WORD <in|out>",
5428 NEIGHBOR_STR
5429 NEIGHBOR_ADDR_STR2
5430 "Filter updates to/from this neighbor\n"
5431 "Name of a prefix list\n"
5432 "Filter incoming updates\n"
5433 "Filter outgoing updates\n")
5434 {
5435 int idx_peer = 1;
5436 int idx_word = 3;
5437 int idx_in_out = 4;
5438 return peer_prefix_list_set_vty(
5439 vty, argv[idx_peer]->arg, bgp_node_afi(vty), bgp_node_safi(vty),
5440 argv[idx_word]->arg, argv[idx_in_out]->arg);
5441 }
5442
5443 ALIAS_HIDDEN(neighbor_prefix_list, neighbor_prefix_list_hidden_cmd,
5444 "neighbor <A.B.C.D|X:X::X:X|WORD> prefix-list WORD <in|out>",
5445 NEIGHBOR_STR NEIGHBOR_ADDR_STR2
5446 "Filter updates to/from this neighbor\n"
5447 "Name of a prefix list\n"
5448 "Filter incoming updates\n"
5449 "Filter outgoing updates\n")
5450
5451 DEFUN (no_neighbor_prefix_list,
5452 no_neighbor_prefix_list_cmd,
5453 "no neighbor <A.B.C.D|X:X::X:X|WORD> prefix-list WORD <in|out>",
5454 NO_STR
5455 NEIGHBOR_STR
5456 NEIGHBOR_ADDR_STR2
5457 "Filter updates to/from this neighbor\n"
5458 "Name of a prefix list\n"
5459 "Filter incoming updates\n"
5460 "Filter outgoing updates\n")
5461 {
5462 int idx_peer = 2;
5463 int idx_in_out = 5;
5464 return peer_prefix_list_unset_vty(vty, argv[idx_peer]->arg,
5465 bgp_node_afi(vty), bgp_node_safi(vty),
5466 argv[idx_in_out]->arg);
5467 }
5468
5469 ALIAS_HIDDEN(no_neighbor_prefix_list, no_neighbor_prefix_list_hidden_cmd,
5470 "no neighbor <A.B.C.D|X:X::X:X|WORD> prefix-list WORD <in|out>",
5471 NO_STR NEIGHBOR_STR NEIGHBOR_ADDR_STR2
5472 "Filter updates to/from this neighbor\n"
5473 "Name of a prefix list\n"
5474 "Filter incoming updates\n"
5475 "Filter outgoing updates\n")
5476
5477 static int peer_aslist_set_vty(struct vty *vty, const char *ip_str, afi_t afi,
5478 safi_t safi, const char *name_str,
5479 const char *direct_str)
5480 {
5481 int ret;
5482 struct peer *peer;
5483 int direct = FILTER_IN;
5484
5485 peer = peer_and_group_lookup_vty(vty, ip_str);
5486 if (!peer)
5487 return CMD_WARNING_CONFIG_FAILED;
5488
5489 /* Check filter direction. */
5490 if (strncmp(direct_str, "i", 1) == 0)
5491 direct = FILTER_IN;
5492 else if (strncmp(direct_str, "o", 1) == 0)
5493 direct = FILTER_OUT;
5494
5495 ret = peer_aslist_set(peer, afi, safi, direct, name_str);
5496
5497 return bgp_vty_return(vty, ret);
5498 }
5499
5500 static int peer_aslist_unset_vty(struct vty *vty, const char *ip_str, afi_t afi,
5501 safi_t safi, const char *direct_str)
5502 {
5503 int ret;
5504 struct peer *peer;
5505 int direct = FILTER_IN;
5506
5507 peer = peer_and_group_lookup_vty(vty, ip_str);
5508 if (!peer)
5509 return CMD_WARNING_CONFIG_FAILED;
5510
5511 /* Check filter direction. */
5512 if (strncmp(direct_str, "i", 1) == 0)
5513 direct = FILTER_IN;
5514 else if (strncmp(direct_str, "o", 1) == 0)
5515 direct = FILTER_OUT;
5516
5517 ret = peer_aslist_unset(peer, afi, safi, direct);
5518
5519 return bgp_vty_return(vty, ret);
5520 }
5521
5522 DEFUN (neighbor_filter_list,
5523 neighbor_filter_list_cmd,
5524 "neighbor <A.B.C.D|X:X::X:X|WORD> filter-list WORD <in|out>",
5525 NEIGHBOR_STR
5526 NEIGHBOR_ADDR_STR2
5527 "Establish BGP filters\n"
5528 "AS path access-list name\n"
5529 "Filter incoming routes\n"
5530 "Filter outgoing routes\n")
5531 {
5532 int idx_peer = 1;
5533 int idx_word = 3;
5534 int idx_in_out = 4;
5535 return peer_aslist_set_vty(vty, argv[idx_peer]->arg, bgp_node_afi(vty),
5536 bgp_node_safi(vty), argv[idx_word]->arg,
5537 argv[idx_in_out]->arg);
5538 }
5539
5540 ALIAS_HIDDEN(neighbor_filter_list, neighbor_filter_list_hidden_cmd,
5541 "neighbor <A.B.C.D|X:X::X:X|WORD> filter-list WORD <in|out>",
5542 NEIGHBOR_STR NEIGHBOR_ADDR_STR2
5543 "Establish BGP filters\n"
5544 "AS path access-list name\n"
5545 "Filter incoming routes\n"
5546 "Filter outgoing routes\n")
5547
5548 DEFUN (no_neighbor_filter_list,
5549 no_neighbor_filter_list_cmd,
5550 "no neighbor <A.B.C.D|X:X::X:X|WORD> filter-list WORD <in|out>",
5551 NO_STR
5552 NEIGHBOR_STR
5553 NEIGHBOR_ADDR_STR2
5554 "Establish BGP filters\n"
5555 "AS path access-list name\n"
5556 "Filter incoming routes\n"
5557 "Filter outgoing routes\n")
5558 {
5559 int idx_peer = 2;
5560 int idx_in_out = 5;
5561 return peer_aslist_unset_vty(vty, argv[idx_peer]->arg,
5562 bgp_node_afi(vty), bgp_node_safi(vty),
5563 argv[idx_in_out]->arg);
5564 }
5565
5566 ALIAS_HIDDEN(no_neighbor_filter_list, no_neighbor_filter_list_hidden_cmd,
5567 "no neighbor <A.B.C.D|X:X::X:X|WORD> filter-list WORD <in|out>",
5568 NO_STR NEIGHBOR_STR NEIGHBOR_ADDR_STR2
5569 "Establish BGP filters\n"
5570 "AS path access-list name\n"
5571 "Filter incoming routes\n"
5572 "Filter outgoing routes\n")
5573
5574 /* Set route-map to the peer. */
5575 static int peer_route_map_set_vty(struct vty *vty, const char *ip_str,
5576 afi_t afi, safi_t safi, const char *name_str,
5577 const char *direct_str)
5578 {
5579 int ret;
5580 struct peer *peer;
5581 int direct = RMAP_IN;
5582
5583 peer = peer_and_group_lookup_vty(vty, ip_str);
5584 if (!peer)
5585 return CMD_WARNING_CONFIG_FAILED;
5586
5587 /* Check filter direction. */
5588 if (strncmp(direct_str, "in", 2) == 0)
5589 direct = RMAP_IN;
5590 else if (strncmp(direct_str, "o", 1) == 0)
5591 direct = RMAP_OUT;
5592
5593 ret = peer_route_map_set(peer, afi, safi, direct, name_str);
5594
5595 return bgp_vty_return(vty, ret);
5596 }
5597
5598 static int peer_route_map_unset_vty(struct vty *vty, const char *ip_str,
5599 afi_t afi, safi_t safi,
5600 const char *direct_str)
5601 {
5602 int ret;
5603 struct peer *peer;
5604 int direct = RMAP_IN;
5605
5606 peer = peer_and_group_lookup_vty(vty, ip_str);
5607 if (!peer)
5608 return CMD_WARNING_CONFIG_FAILED;
5609
5610 /* Check filter direction. */
5611 if (strncmp(direct_str, "in", 2) == 0)
5612 direct = RMAP_IN;
5613 else if (strncmp(direct_str, "o", 1) == 0)
5614 direct = RMAP_OUT;
5615
5616 ret = peer_route_map_unset(peer, afi, safi, direct);
5617
5618 return bgp_vty_return(vty, ret);
5619 }
5620
5621 DEFUN (neighbor_route_map,
5622 neighbor_route_map_cmd,
5623 "neighbor <A.B.C.D|X:X::X:X|WORD> route-map WORD <in|out>",
5624 NEIGHBOR_STR
5625 NEIGHBOR_ADDR_STR2
5626 "Apply route map to neighbor\n"
5627 "Name of route map\n"
5628 "Apply map to incoming routes\n"
5629 "Apply map to outbound routes\n")
5630 {
5631 int idx_peer = 1;
5632 int idx_word = 3;
5633 int idx_in_out = 4;
5634 return peer_route_map_set_vty(
5635 vty, argv[idx_peer]->arg, bgp_node_afi(vty), bgp_node_safi(vty),
5636 argv[idx_word]->arg, argv[idx_in_out]->arg);
5637 }
5638
5639 ALIAS_HIDDEN(neighbor_route_map, neighbor_route_map_hidden_cmd,
5640 "neighbor <A.B.C.D|X:X::X:X|WORD> route-map WORD <in|out>",
5641 NEIGHBOR_STR NEIGHBOR_ADDR_STR2
5642 "Apply route map to neighbor\n"
5643 "Name of route map\n"
5644 "Apply map to incoming routes\n"
5645 "Apply map to outbound routes\n")
5646
5647 DEFUN (no_neighbor_route_map,
5648 no_neighbor_route_map_cmd,
5649 "no neighbor <A.B.C.D|X:X::X:X|WORD> route-map WORD <in|out>",
5650 NO_STR
5651 NEIGHBOR_STR
5652 NEIGHBOR_ADDR_STR2
5653 "Apply route map to neighbor\n"
5654 "Name of route map\n"
5655 "Apply map to incoming routes\n"
5656 "Apply map to outbound routes\n")
5657 {
5658 int idx_peer = 2;
5659 int idx_in_out = 5;
5660 return peer_route_map_unset_vty(vty, argv[idx_peer]->arg,
5661 bgp_node_afi(vty), bgp_node_safi(vty),
5662 argv[idx_in_out]->arg);
5663 }
5664
5665 ALIAS_HIDDEN(no_neighbor_route_map, no_neighbor_route_map_hidden_cmd,
5666 "no neighbor <A.B.C.D|X:X::X:X|WORD> route-map WORD <in|out>",
5667 NO_STR NEIGHBOR_STR NEIGHBOR_ADDR_STR2
5668 "Apply route map to neighbor\n"
5669 "Name of route map\n"
5670 "Apply map to incoming routes\n"
5671 "Apply map to outbound routes\n")
5672
5673 /* Set unsuppress-map to the peer. */
5674 static int peer_unsuppress_map_set_vty(struct vty *vty, const char *ip_str,
5675 afi_t afi, safi_t safi,
5676 const char *name_str)
5677 {
5678 int ret;
5679 struct peer *peer;
5680
5681 peer = peer_and_group_lookup_vty(vty, ip_str);
5682 if (!peer)
5683 return CMD_WARNING_CONFIG_FAILED;
5684
5685 ret = peer_unsuppress_map_set(peer, afi, safi, name_str);
5686
5687 return bgp_vty_return(vty, ret);
5688 }
5689
5690 /* Unset route-map from the peer. */
5691 static int peer_unsuppress_map_unset_vty(struct vty *vty, const char *ip_str,
5692 afi_t afi, safi_t safi)
5693 {
5694 int ret;
5695 struct peer *peer;
5696
5697 peer = peer_and_group_lookup_vty(vty, ip_str);
5698 if (!peer)
5699 return CMD_WARNING_CONFIG_FAILED;
5700
5701 ret = peer_unsuppress_map_unset(peer, afi, safi);
5702
5703 return bgp_vty_return(vty, ret);
5704 }
5705
5706 DEFUN (neighbor_unsuppress_map,
5707 neighbor_unsuppress_map_cmd,
5708 "neighbor <A.B.C.D|X:X::X:X|WORD> unsuppress-map WORD",
5709 NEIGHBOR_STR
5710 NEIGHBOR_ADDR_STR2
5711 "Route-map to selectively unsuppress suppressed routes\n"
5712 "Name of route map\n")
5713 {
5714 int idx_peer = 1;
5715 int idx_word = 3;
5716 return peer_unsuppress_map_set_vty(
5717 vty, argv[idx_peer]->arg, bgp_node_afi(vty), bgp_node_safi(vty),
5718 argv[idx_word]->arg);
5719 }
5720
5721 ALIAS_HIDDEN(neighbor_unsuppress_map, neighbor_unsuppress_map_hidden_cmd,
5722 "neighbor <A.B.C.D|X:X::X:X|WORD> unsuppress-map WORD",
5723 NEIGHBOR_STR NEIGHBOR_ADDR_STR2
5724 "Route-map to selectively unsuppress suppressed routes\n"
5725 "Name of route map\n")
5726
5727 DEFUN (no_neighbor_unsuppress_map,
5728 no_neighbor_unsuppress_map_cmd,
5729 "no neighbor <A.B.C.D|X:X::X:X|WORD> unsuppress-map WORD",
5730 NO_STR
5731 NEIGHBOR_STR
5732 NEIGHBOR_ADDR_STR2
5733 "Route-map to selectively unsuppress suppressed routes\n"
5734 "Name of route map\n")
5735 {
5736 int idx_peer = 2;
5737 return peer_unsuppress_map_unset_vty(vty, argv[idx_peer]->arg,
5738 bgp_node_afi(vty),
5739 bgp_node_safi(vty));
5740 }
5741
5742 ALIAS_HIDDEN(no_neighbor_unsuppress_map, no_neighbor_unsuppress_map_hidden_cmd,
5743 "no neighbor <A.B.C.D|X:X::X:X|WORD> unsuppress-map WORD",
5744 NO_STR NEIGHBOR_STR NEIGHBOR_ADDR_STR2
5745 "Route-map to selectively unsuppress suppressed routes\n"
5746 "Name of route map\n")
5747
5748 static int peer_maximum_prefix_set_vty(struct vty *vty, const char *ip_str,
5749 afi_t afi, safi_t safi,
5750 const char *num_str,
5751 const char *threshold_str, int warning,
5752 const char *restart_str)
5753 {
5754 int ret;
5755 struct peer *peer;
5756 uint32_t max;
5757 uint8_t threshold;
5758 uint16_t restart;
5759
5760 peer = peer_and_group_lookup_vty(vty, ip_str);
5761 if (!peer)
5762 return CMD_WARNING_CONFIG_FAILED;
5763
5764 max = strtoul(num_str, NULL, 10);
5765 if (threshold_str)
5766 threshold = atoi(threshold_str);
5767 else
5768 threshold = MAXIMUM_PREFIX_THRESHOLD_DEFAULT;
5769
5770 if (restart_str)
5771 restart = atoi(restart_str);
5772 else
5773 restart = 0;
5774
5775 ret = peer_maximum_prefix_set(peer, afi, safi, max, threshold, warning,
5776 restart);
5777
5778 return bgp_vty_return(vty, ret);
5779 }
5780
5781 static int peer_maximum_prefix_unset_vty(struct vty *vty, const char *ip_str,
5782 afi_t afi, safi_t safi)
5783 {
5784 int ret;
5785 struct peer *peer;
5786
5787 peer = peer_and_group_lookup_vty(vty, ip_str);
5788 if (!peer)
5789 return CMD_WARNING_CONFIG_FAILED;
5790
5791 ret = peer_maximum_prefix_unset(peer, afi, safi);
5792
5793 return bgp_vty_return(vty, ret);
5794 }
5795
5796 /* Maximum number of prefix configuration. prefix count is different
5797 for each peer configuration. So this configuration can be set for
5798 each peer configuration. */
5799 DEFUN (neighbor_maximum_prefix,
5800 neighbor_maximum_prefix_cmd,
5801 "neighbor <A.B.C.D|X:X::X:X|WORD> maximum-prefix (1-4294967295)",
5802 NEIGHBOR_STR
5803 NEIGHBOR_ADDR_STR2
5804 "Maximum number of prefix accept from this peer\n"
5805 "maximum no. of prefix limit\n")
5806 {
5807 int idx_peer = 1;
5808 int idx_number = 3;
5809 return peer_maximum_prefix_set_vty(
5810 vty, argv[idx_peer]->arg, bgp_node_afi(vty), bgp_node_safi(vty),
5811 argv[idx_number]->arg, NULL, 0, NULL);
5812 }
5813
5814 ALIAS_HIDDEN(neighbor_maximum_prefix, neighbor_maximum_prefix_hidden_cmd,
5815 "neighbor <A.B.C.D|X:X::X:X|WORD> maximum-prefix (1-4294967295)",
5816 NEIGHBOR_STR NEIGHBOR_ADDR_STR2
5817 "Maximum number of prefix accept from this peer\n"
5818 "maximum no. of prefix limit\n")
5819
5820 DEFUN (neighbor_maximum_prefix_threshold,
5821 neighbor_maximum_prefix_threshold_cmd,
5822 "neighbor <A.B.C.D|X:X::X:X|WORD> maximum-prefix (1-4294967295) (1-100)",
5823 NEIGHBOR_STR
5824 NEIGHBOR_ADDR_STR2
5825 "Maximum number of prefix accept from this peer\n"
5826 "maximum no. of prefix limit\n"
5827 "Threshold value (%) at which to generate a warning msg\n")
5828 {
5829 int idx_peer = 1;
5830 int idx_number = 3;
5831 int idx_number_2 = 4;
5832 return peer_maximum_prefix_set_vty(
5833 vty, argv[idx_peer]->arg, bgp_node_afi(vty), bgp_node_safi(vty),
5834 argv[idx_number]->arg, argv[idx_number_2]->arg, 0, NULL);
5835 }
5836
5837 ALIAS_HIDDEN(
5838 neighbor_maximum_prefix_threshold,
5839 neighbor_maximum_prefix_threshold_hidden_cmd,
5840 "neighbor <A.B.C.D|X:X::X:X|WORD> maximum-prefix (1-4294967295) (1-100)",
5841 NEIGHBOR_STR NEIGHBOR_ADDR_STR2
5842 "Maximum number of prefix accept from this peer\n"
5843 "maximum no. of prefix limit\n"
5844 "Threshold value (%) at which to generate a warning msg\n")
5845
5846 DEFUN (neighbor_maximum_prefix_warning,
5847 neighbor_maximum_prefix_warning_cmd,
5848 "neighbor <A.B.C.D|X:X::X:X|WORD> maximum-prefix (1-4294967295) warning-only",
5849 NEIGHBOR_STR
5850 NEIGHBOR_ADDR_STR2
5851 "Maximum number of prefix accept from this peer\n"
5852 "maximum no. of prefix limit\n"
5853 "Only give warning message when limit is exceeded\n")
5854 {
5855 int idx_peer = 1;
5856 int idx_number = 3;
5857 return peer_maximum_prefix_set_vty(
5858 vty, argv[idx_peer]->arg, bgp_node_afi(vty), bgp_node_safi(vty),
5859 argv[idx_number]->arg, NULL, 1, NULL);
5860 }
5861
5862 ALIAS_HIDDEN(
5863 neighbor_maximum_prefix_warning,
5864 neighbor_maximum_prefix_warning_hidden_cmd,
5865 "neighbor <A.B.C.D|X:X::X:X|WORD> maximum-prefix (1-4294967295) warning-only",
5866 NEIGHBOR_STR NEIGHBOR_ADDR_STR2
5867 "Maximum number of prefix accept from this peer\n"
5868 "maximum no. of prefix limit\n"
5869 "Only give warning message when limit is exceeded\n")
5870
5871 DEFUN (neighbor_maximum_prefix_threshold_warning,
5872 neighbor_maximum_prefix_threshold_warning_cmd,
5873 "neighbor <A.B.C.D|X:X::X:X|WORD> maximum-prefix (1-4294967295) (1-100) warning-only",
5874 NEIGHBOR_STR
5875 NEIGHBOR_ADDR_STR2
5876 "Maximum number of prefix accept from this peer\n"
5877 "maximum no. of prefix limit\n"
5878 "Threshold value (%) at which to generate a warning msg\n"
5879 "Only give warning message when limit is exceeded\n")
5880 {
5881 int idx_peer = 1;
5882 int idx_number = 3;
5883 int idx_number_2 = 4;
5884 return peer_maximum_prefix_set_vty(
5885 vty, argv[idx_peer]->arg, bgp_node_afi(vty), bgp_node_safi(vty),
5886 argv[idx_number]->arg, argv[idx_number_2]->arg, 1, NULL);
5887 }
5888
5889 ALIAS_HIDDEN(
5890 neighbor_maximum_prefix_threshold_warning,
5891 neighbor_maximum_prefix_threshold_warning_hidden_cmd,
5892 "neighbor <A.B.C.D|X:X::X:X|WORD> maximum-prefix (1-4294967295) (1-100) warning-only",
5893 NEIGHBOR_STR NEIGHBOR_ADDR_STR2
5894 "Maximum number of prefix accept from this peer\n"
5895 "maximum no. of prefix limit\n"
5896 "Threshold value (%) at which to generate a warning msg\n"
5897 "Only give warning message when limit is exceeded\n")
5898
5899 DEFUN (neighbor_maximum_prefix_restart,
5900 neighbor_maximum_prefix_restart_cmd,
5901 "neighbor <A.B.C.D|X:X::X:X|WORD> maximum-prefix (1-4294967295) restart (1-65535)",
5902 NEIGHBOR_STR
5903 NEIGHBOR_ADDR_STR2
5904 "Maximum number of prefix accept from this peer\n"
5905 "maximum no. of prefix limit\n"
5906 "Restart bgp connection after limit is exceeded\n"
5907 "Restart interval in minutes\n")
5908 {
5909 int idx_peer = 1;
5910 int idx_number = 3;
5911 int idx_number_2 = 5;
5912 return peer_maximum_prefix_set_vty(
5913 vty, argv[idx_peer]->arg, bgp_node_afi(vty), bgp_node_safi(vty),
5914 argv[idx_number]->arg, NULL, 0, argv[idx_number_2]->arg);
5915 }
5916
5917 ALIAS_HIDDEN(
5918 neighbor_maximum_prefix_restart,
5919 neighbor_maximum_prefix_restart_hidden_cmd,
5920 "neighbor <A.B.C.D|X:X::X:X|WORD> maximum-prefix (1-4294967295) restart (1-65535)",
5921 NEIGHBOR_STR NEIGHBOR_ADDR_STR2
5922 "Maximum number of prefix accept from this peer\n"
5923 "maximum no. of prefix limit\n"
5924 "Restart bgp connection after limit is exceeded\n"
5925 "Restart interval in minutes\n")
5926
5927 DEFUN (neighbor_maximum_prefix_threshold_restart,
5928 neighbor_maximum_prefix_threshold_restart_cmd,
5929 "neighbor <A.B.C.D|X:X::X:X|WORD> maximum-prefix (1-4294967295) (1-100) restart (1-65535)",
5930 NEIGHBOR_STR
5931 NEIGHBOR_ADDR_STR2
5932 "Maximum number of prefixes to accept from this peer\n"
5933 "maximum no. of prefix limit\n"
5934 "Threshold value (%) at which to generate a warning msg\n"
5935 "Restart bgp connection after limit is exceeded\n"
5936 "Restart interval in minutes\n")
5937 {
5938 int idx_peer = 1;
5939 int idx_number = 3;
5940 int idx_number_2 = 4;
5941 int idx_number_3 = 6;
5942 return peer_maximum_prefix_set_vty(
5943 vty, argv[idx_peer]->arg, bgp_node_afi(vty), bgp_node_safi(vty),
5944 argv[idx_number]->arg, argv[idx_number_2]->arg, 0,
5945 argv[idx_number_3]->arg);
5946 }
5947
5948 ALIAS_HIDDEN(
5949 neighbor_maximum_prefix_threshold_restart,
5950 neighbor_maximum_prefix_threshold_restart_hidden_cmd,
5951 "neighbor <A.B.C.D|X:X::X:X|WORD> maximum-prefix (1-4294967295) (1-100) restart (1-65535)",
5952 NEIGHBOR_STR NEIGHBOR_ADDR_STR2
5953 "Maximum number of prefixes to accept from this peer\n"
5954 "maximum no. of prefix limit\n"
5955 "Threshold value (%) at which to generate a warning msg\n"
5956 "Restart bgp connection after limit is exceeded\n"
5957 "Restart interval in minutes\n")
5958
5959 DEFUN (no_neighbor_maximum_prefix,
5960 no_neighbor_maximum_prefix_cmd,
5961 "no neighbor <A.B.C.D|X:X::X:X|WORD> maximum-prefix [(1-4294967295) [(1-100)] [restart (1-65535)] [warning-only]]",
5962 NO_STR
5963 NEIGHBOR_STR
5964 NEIGHBOR_ADDR_STR2
5965 "Maximum number of prefixes to accept from this peer\n"
5966 "maximum no. of prefix limit\n"
5967 "Threshold value (%) at which to generate a warning msg\n"
5968 "Restart bgp connection after limit is exceeded\n"
5969 "Restart interval in minutes\n"
5970 "Only give warning message when limit is exceeded\n")
5971 {
5972 int idx_peer = 2;
5973 return peer_maximum_prefix_unset_vty(vty, argv[idx_peer]->arg,
5974 bgp_node_afi(vty),
5975 bgp_node_safi(vty));
5976 }
5977
5978 ALIAS_HIDDEN(
5979 no_neighbor_maximum_prefix, no_neighbor_maximum_prefix_hidden_cmd,
5980 "no neighbor <A.B.C.D|X:X::X:X|WORD> maximum-prefix [(1-4294967295) [(1-100)] [restart (1-65535)] [warning-only]]",
5981 NO_STR NEIGHBOR_STR NEIGHBOR_ADDR_STR2
5982 "Maximum number of prefixes to accept from this peer\n"
5983 "maximum no. of prefix limit\n"
5984 "Threshold value (%) at which to generate a warning msg\n"
5985 "Restart bgp connection after limit is exceeded\n"
5986 "Restart interval in minutes\n"
5987 "Only give warning message when limit is exceeded\n")
5988
5989
5990 /* "neighbor allowas-in" */
5991 DEFUN (neighbor_allowas_in,
5992 neighbor_allowas_in_cmd,
5993 "neighbor <A.B.C.D|X:X::X:X|WORD> allowas-in [<(1-10)|origin>]",
5994 NEIGHBOR_STR
5995 NEIGHBOR_ADDR_STR2
5996 "Accept as-path with my AS present in it\n"
5997 "Number of occurances of AS number\n"
5998 "Only accept my AS in the as-path if the route was originated in my AS\n")
5999 {
6000 int idx_peer = 1;
6001 int idx_number_origin = 3;
6002 int ret;
6003 int origin = 0;
6004 struct peer *peer;
6005 int allow_num = 0;
6006
6007 peer = peer_and_group_lookup_vty(vty, argv[idx_peer]->arg);
6008 if (!peer)
6009 return CMD_WARNING_CONFIG_FAILED;
6010
6011 if (argc <= idx_number_origin)
6012 allow_num = 3;
6013 else {
6014 if (argv[idx_number_origin]->type == WORD_TKN)
6015 origin = 1;
6016 else
6017 allow_num = atoi(argv[idx_number_origin]->arg);
6018 }
6019
6020 ret = peer_allowas_in_set(peer, bgp_node_afi(vty), bgp_node_safi(vty),
6021 allow_num, origin);
6022
6023 return bgp_vty_return(vty, ret);
6024 }
6025
6026 ALIAS_HIDDEN(
6027 neighbor_allowas_in, neighbor_allowas_in_hidden_cmd,
6028 "neighbor <A.B.C.D|X:X::X:X|WORD> allowas-in [<(1-10)|origin>]",
6029 NEIGHBOR_STR NEIGHBOR_ADDR_STR2
6030 "Accept as-path with my AS present in it\n"
6031 "Number of occurances of AS number\n"
6032 "Only accept my AS in the as-path if the route was originated in my AS\n")
6033
6034 DEFUN (no_neighbor_allowas_in,
6035 no_neighbor_allowas_in_cmd,
6036 "no neighbor <A.B.C.D|X:X::X:X|WORD> allowas-in [<(1-10)|origin>]",
6037 NO_STR
6038 NEIGHBOR_STR
6039 NEIGHBOR_ADDR_STR2
6040 "allow local ASN appears in aspath attribute\n"
6041 "Number of occurances of AS number\n"
6042 "Only accept my AS in the as-path if the route was originated in my AS\n")
6043 {
6044 int idx_peer = 2;
6045 int ret;
6046 struct peer *peer;
6047
6048 peer = peer_and_group_lookup_vty(vty, argv[idx_peer]->arg);
6049 if (!peer)
6050 return CMD_WARNING_CONFIG_FAILED;
6051
6052 ret = peer_allowas_in_unset(peer, bgp_node_afi(vty),
6053 bgp_node_safi(vty));
6054
6055 return bgp_vty_return(vty, ret);
6056 }
6057
6058 ALIAS_HIDDEN(
6059 no_neighbor_allowas_in, no_neighbor_allowas_in_hidden_cmd,
6060 "no neighbor <A.B.C.D|X:X::X:X|WORD> allowas-in [<(1-10)|origin>]",
6061 NO_STR NEIGHBOR_STR NEIGHBOR_ADDR_STR2
6062 "allow local ASN appears in aspath attribute\n"
6063 "Number of occurances of AS number\n"
6064 "Only accept my AS in the as-path if the route was originated in my AS\n")
6065
6066 DEFUN (neighbor_ttl_security,
6067 neighbor_ttl_security_cmd,
6068 "neighbor <A.B.C.D|X:X::X:X|WORD> ttl-security hops (1-254)",
6069 NEIGHBOR_STR
6070 NEIGHBOR_ADDR_STR2
6071 "BGP ttl-security parameters\n"
6072 "Specify the maximum number of hops to the BGP peer\n"
6073 "Number of hops to BGP peer\n")
6074 {
6075 int idx_peer = 1;
6076 int idx_number = 4;
6077 struct peer *peer;
6078 int gtsm_hops;
6079
6080 peer = peer_and_group_lookup_vty(vty, argv[idx_peer]->arg);
6081 if (!peer)
6082 return CMD_WARNING_CONFIG_FAILED;
6083
6084 gtsm_hops = strtoul(argv[idx_number]->arg, NULL, 10);
6085
6086 /*
6087 * If 'neighbor swpX', then this is for directly connected peers,
6088 * we should not accept a ttl-security hops value greater than 1.
6089 */
6090 if (peer->conf_if && (gtsm_hops > 1)) {
6091 vty_out(vty,
6092 "%s is directly connected peer, hops cannot exceed 1\n",
6093 argv[idx_peer]->arg);
6094 return CMD_WARNING_CONFIG_FAILED;
6095 }
6096
6097 return bgp_vty_return(vty, peer_ttl_security_hops_set(peer, gtsm_hops));
6098 }
6099
6100 DEFUN (no_neighbor_ttl_security,
6101 no_neighbor_ttl_security_cmd,
6102 "no neighbor <A.B.C.D|X:X::X:X|WORD> ttl-security hops (1-254)",
6103 NO_STR
6104 NEIGHBOR_STR
6105 NEIGHBOR_ADDR_STR2
6106 "BGP ttl-security parameters\n"
6107 "Specify the maximum number of hops to the BGP peer\n"
6108 "Number of hops to BGP peer\n")
6109 {
6110 int idx_peer = 2;
6111 struct peer *peer;
6112
6113 peer = peer_and_group_lookup_vty(vty, argv[idx_peer]->arg);
6114 if (!peer)
6115 return CMD_WARNING_CONFIG_FAILED;
6116
6117 return bgp_vty_return(vty, peer_ttl_security_hops_unset(peer));
6118 }
6119
6120 DEFUN (neighbor_addpath_tx_all_paths,
6121 neighbor_addpath_tx_all_paths_cmd,
6122 "neighbor <A.B.C.D|X:X::X:X|WORD> addpath-tx-all-paths",
6123 NEIGHBOR_STR
6124 NEIGHBOR_ADDR_STR2
6125 "Use addpath to advertise all paths to a neighbor\n")
6126 {
6127 int idx_peer = 1;
6128 struct peer *peer;
6129
6130 peer = peer_and_group_lookup_vty(vty, argv[idx_peer]->arg);
6131 if (!peer)
6132 return CMD_WARNING_CONFIG_FAILED;
6133
6134 return peer_af_flag_set_vty(vty, argv[idx_peer]->arg, bgp_node_afi(vty),
6135 bgp_node_safi(vty),
6136 PEER_FLAG_ADDPATH_TX_ALL_PATHS);
6137 }
6138
6139 ALIAS_HIDDEN(neighbor_addpath_tx_all_paths,
6140 neighbor_addpath_tx_all_paths_hidden_cmd,
6141 "neighbor <A.B.C.D|X:X::X:X|WORD> addpath-tx-all-paths",
6142 NEIGHBOR_STR NEIGHBOR_ADDR_STR2
6143 "Use addpath to advertise all paths to a neighbor\n")
6144
6145 DEFUN (no_neighbor_addpath_tx_all_paths,
6146 no_neighbor_addpath_tx_all_paths_cmd,
6147 "no neighbor <A.B.C.D|X:X::X:X|WORD> addpath-tx-all-paths",
6148 NO_STR
6149 NEIGHBOR_STR
6150 NEIGHBOR_ADDR_STR2
6151 "Use addpath to advertise all paths to a neighbor\n")
6152 {
6153 int idx_peer = 2;
6154 return peer_af_flag_unset_vty(vty, argv[idx_peer]->arg,
6155 bgp_node_afi(vty), bgp_node_safi(vty),
6156 PEER_FLAG_ADDPATH_TX_ALL_PATHS);
6157 }
6158
6159 ALIAS_HIDDEN(no_neighbor_addpath_tx_all_paths,
6160 no_neighbor_addpath_tx_all_paths_hidden_cmd,
6161 "no neighbor <A.B.C.D|X:X::X:X|WORD> addpath-tx-all-paths",
6162 NO_STR NEIGHBOR_STR NEIGHBOR_ADDR_STR2
6163 "Use addpath to advertise all paths to a neighbor\n")
6164
6165 DEFUN (neighbor_addpath_tx_bestpath_per_as,
6166 neighbor_addpath_tx_bestpath_per_as_cmd,
6167 "neighbor <A.B.C.D|X:X::X:X|WORD> addpath-tx-bestpath-per-AS",
6168 NEIGHBOR_STR
6169 NEIGHBOR_ADDR_STR2
6170 "Use addpath to advertise the bestpath per each neighboring AS\n")
6171 {
6172 int idx_peer = 1;
6173 struct peer *peer;
6174
6175 peer = peer_and_group_lookup_vty(vty, argv[idx_peer]->arg);
6176 if (!peer)
6177 return CMD_WARNING_CONFIG_FAILED;
6178
6179 return peer_af_flag_set_vty(vty, argv[idx_peer]->arg, bgp_node_afi(vty),
6180 bgp_node_safi(vty),
6181 PEER_FLAG_ADDPATH_TX_BESTPATH_PER_AS);
6182 }
6183
6184 ALIAS_HIDDEN(neighbor_addpath_tx_bestpath_per_as,
6185 neighbor_addpath_tx_bestpath_per_as_hidden_cmd,
6186 "neighbor <A.B.C.D|X:X::X:X|WORD> addpath-tx-bestpath-per-AS",
6187 NEIGHBOR_STR NEIGHBOR_ADDR_STR2
6188 "Use addpath to advertise the bestpath per each neighboring AS\n")
6189
6190 DEFUN (no_neighbor_addpath_tx_bestpath_per_as,
6191 no_neighbor_addpath_tx_bestpath_per_as_cmd,
6192 "no neighbor <A.B.C.D|X:X::X:X|WORD> addpath-tx-bestpath-per-AS",
6193 NO_STR
6194 NEIGHBOR_STR
6195 NEIGHBOR_ADDR_STR2
6196 "Use addpath to advertise the bestpath per each neighboring AS\n")
6197 {
6198 int idx_peer = 2;
6199 return peer_af_flag_unset_vty(vty, argv[idx_peer]->arg,
6200 bgp_node_afi(vty), bgp_node_safi(vty),
6201 PEER_FLAG_ADDPATH_TX_BESTPATH_PER_AS);
6202 }
6203
6204 ALIAS_HIDDEN(no_neighbor_addpath_tx_bestpath_per_as,
6205 no_neighbor_addpath_tx_bestpath_per_as_hidden_cmd,
6206 "no neighbor <A.B.C.D|X:X::X:X|WORD> addpath-tx-bestpath-per-AS",
6207 NO_STR NEIGHBOR_STR NEIGHBOR_ADDR_STR2
6208 "Use addpath to advertise the bestpath per each neighboring AS\n")
6209
6210 static int set_ecom_list(struct vty *vty, int argc, struct cmd_token **argv,
6211 struct ecommunity **list)
6212 {
6213 struct ecommunity *ecom = NULL;
6214 struct ecommunity *ecomadd;
6215
6216 for (; argc; --argc, ++argv) {
6217
6218 ecomadd = ecommunity_str2com(argv[0]->arg,
6219 ECOMMUNITY_ROUTE_TARGET, 0);
6220 if (!ecomadd) {
6221 vty_out(vty, "Malformed community-list value\n");
6222 if (ecom)
6223 ecommunity_free(&ecom);
6224 return CMD_WARNING_CONFIG_FAILED;
6225 }
6226
6227 if (ecom) {
6228 ecommunity_merge(ecom, ecomadd);
6229 ecommunity_free(&ecomadd);
6230 } else {
6231 ecom = ecomadd;
6232 }
6233 }
6234
6235 if (*list) {
6236 ecommunity_free(&*list);
6237 }
6238 *list = ecom;
6239
6240 return CMD_SUCCESS;
6241 }
6242
6243 /*
6244 * v2vimport is true if we are handling a `import vrf ...` command
6245 */
6246 static afi_t vpn_policy_getafi(struct vty *vty, struct bgp *bgp, bool v2vimport)
6247 {
6248 afi_t afi;
6249
6250 switch (vty->node) {
6251 case BGP_IPV4_NODE:
6252 afi = AFI_IP;
6253 break;
6254 case BGP_IPV6_NODE:
6255 afi = AFI_IP6;
6256 break;
6257 default:
6258 vty_out(vty,
6259 "%% context error: valid only in address-family <ipv4|ipv6> unicast block\n");
6260 return AFI_MAX;
6261 }
6262
6263 if (!v2vimport) {
6264 if (CHECK_FLAG(bgp->af_flags[afi][SAFI_UNICAST],
6265 BGP_CONFIG_VRF_TO_VRF_IMPORT)
6266 || CHECK_FLAG(bgp->af_flags[afi][SAFI_UNICAST],
6267 BGP_CONFIG_VRF_TO_VRF_EXPORT)) {
6268 vty_out(vty,
6269 "%% error: Please unconfigure import vrf commands before using vpn commands\n");
6270 return AFI_MAX;
6271 }
6272 } else {
6273 if (CHECK_FLAG(bgp->af_flags[afi][SAFI_UNICAST],
6274 BGP_CONFIG_VRF_TO_MPLSVPN_EXPORT)
6275 || CHECK_FLAG(bgp->af_flags[afi][SAFI_UNICAST],
6276 BGP_CONFIG_MPLSVPN_TO_VRF_IMPORT)) {
6277 vty_out(vty,
6278 "%% error: Please unconfigure vpn to vrf commands before using import vrf commands\n");
6279 return AFI_MAX;
6280 }
6281 }
6282 return afi;
6283 }
6284
6285 DEFPY (af_rd_vpn_export,
6286 af_rd_vpn_export_cmd,
6287 "[no] rd vpn export ASN:NN_OR_IP-ADDRESS:NN$rd_str",
6288 NO_STR
6289 "Specify route distinguisher\n"
6290 "Between current address-family and vpn\n"
6291 "For routes leaked from current address-family to vpn\n"
6292 "Route Distinguisher (<as-number>:<number> | <ip-address>:<number>)\n")
6293 {
6294 VTY_DECLVAR_CONTEXT(bgp, bgp);
6295 struct prefix_rd prd;
6296 int ret;
6297 afi_t afi;
6298 int idx = 0;
6299 int yes = 1;
6300
6301 if (argv_find(argv, argc, "no", &idx))
6302 yes = 0;
6303
6304 if (yes) {
6305 ret = str2prefix_rd(rd_str, &prd);
6306 if (!ret) {
6307 vty_out(vty, "%% Malformed rd\n");
6308 return CMD_WARNING_CONFIG_FAILED;
6309 }
6310 }
6311
6312 afi = vpn_policy_getafi(vty, bgp, false);
6313 if (afi == AFI_MAX)
6314 return CMD_WARNING_CONFIG_FAILED;
6315
6316 /*
6317 * pre-change: un-export vpn routes (vpn->vrf routes unaffected)
6318 */
6319 vpn_leak_prechange(BGP_VPN_POLICY_DIR_TOVPN, afi,
6320 bgp_get_default(), bgp);
6321
6322 if (yes) {
6323 bgp->vpn_policy[afi].tovpn_rd = prd;
6324 SET_FLAG(bgp->vpn_policy[afi].flags,
6325 BGP_VPN_POLICY_TOVPN_RD_SET);
6326 } else {
6327 UNSET_FLAG(bgp->vpn_policy[afi].flags,
6328 BGP_VPN_POLICY_TOVPN_RD_SET);
6329 }
6330
6331 /* post-change: re-export vpn routes */
6332 vpn_leak_postchange(BGP_VPN_POLICY_DIR_TOVPN, afi,
6333 bgp_get_default(), bgp);
6334
6335 return CMD_SUCCESS;
6336 }
6337
6338 ALIAS (af_rd_vpn_export,
6339 af_no_rd_vpn_export_cmd,
6340 "no rd vpn export",
6341 NO_STR
6342 "Specify route distinguisher\n"
6343 "Between current address-family and vpn\n"
6344 "For routes leaked from current address-family to vpn\n")
6345
6346 DEFPY (af_label_vpn_export,
6347 af_label_vpn_export_cmd,
6348 "[no] label vpn export <(0-1048575)$label_val|auto$label_auto>",
6349 NO_STR
6350 "label value for VRF\n"
6351 "Between current address-family and vpn\n"
6352 "For routes leaked from current address-family to vpn\n"
6353 "Label Value <0-1048575>\n"
6354 "Automatically assign a label\n")
6355 {
6356 VTY_DECLVAR_CONTEXT(bgp, bgp);
6357 mpls_label_t label = MPLS_LABEL_NONE;
6358 afi_t afi;
6359 int idx = 0;
6360 int yes = 1;
6361
6362 if (argv_find(argv, argc, "no", &idx))
6363 yes = 0;
6364
6365 /* If "no ...", squash trailing parameter */
6366 if (!yes)
6367 label_auto = NULL;
6368
6369 if (yes) {
6370 if (!label_auto)
6371 label = label_val; /* parser should force unsigned */
6372 }
6373
6374 afi = vpn_policy_getafi(vty, bgp, false);
6375 if (afi == AFI_MAX)
6376 return CMD_WARNING_CONFIG_FAILED;
6377
6378
6379 if (label_auto && CHECK_FLAG(bgp->vpn_policy[afi].flags,
6380 BGP_VPN_POLICY_TOVPN_LABEL_AUTO))
6381 /* no change */
6382 return CMD_SUCCESS;
6383
6384 /*
6385 * pre-change: un-export vpn routes (vpn->vrf routes unaffected)
6386 */
6387 vpn_leak_prechange(BGP_VPN_POLICY_DIR_TOVPN, afi,
6388 bgp_get_default(), bgp);
6389
6390 if (!label_auto && CHECK_FLAG(bgp->vpn_policy[afi].flags,
6391 BGP_VPN_POLICY_TOVPN_LABEL_AUTO)) {
6392
6393 if (bgp->vpn_policy[afi].tovpn_label != MPLS_LABEL_NONE) {
6394
6395 /*
6396 * label has previously been automatically
6397 * assigned by labelpool: release it
6398 *
6399 * NB if tovpn_label == MPLS_LABEL_NONE it
6400 * means the automatic assignment is in flight
6401 * and therefore the labelpool callback must
6402 * detect that the auto label is not needed.
6403 */
6404
6405 bgp_lp_release(LP_TYPE_VRF,
6406 &bgp->vpn_policy[afi],
6407 bgp->vpn_policy[afi].tovpn_label);
6408 }
6409 UNSET_FLAG(bgp->vpn_policy[afi].flags,
6410 BGP_VPN_POLICY_TOVPN_LABEL_AUTO);
6411 }
6412
6413 bgp->vpn_policy[afi].tovpn_label = label;
6414 if (label_auto) {
6415 SET_FLAG(bgp->vpn_policy[afi].flags,
6416 BGP_VPN_POLICY_TOVPN_LABEL_AUTO);
6417 bgp_lp_get(LP_TYPE_VRF, &bgp->vpn_policy[afi],
6418 vpn_leak_label_callback);
6419 }
6420
6421 /* post-change: re-export vpn routes */
6422 vpn_leak_postchange(BGP_VPN_POLICY_DIR_TOVPN, afi,
6423 bgp_get_default(), bgp);
6424
6425 return CMD_SUCCESS;
6426 }
6427
6428 ALIAS (af_label_vpn_export,
6429 af_no_label_vpn_export_cmd,
6430 "no label vpn export",
6431 NO_STR
6432 "label value for VRF\n"
6433 "Between current address-family and vpn\n"
6434 "For routes leaked from current address-family to vpn\n")
6435
6436 DEFPY (af_nexthop_vpn_export,
6437 af_nexthop_vpn_export_cmd,
6438 "[no] nexthop vpn export <A.B.C.D|X:X::X:X>$nexthop_str",
6439 NO_STR
6440 "Specify next hop to use for VRF advertised prefixes\n"
6441 "Between current address-family and vpn\n"
6442 "For routes leaked from current address-family to vpn\n"
6443 "IPv4 prefix\n"
6444 "IPv6 prefix\n")
6445 {
6446 VTY_DECLVAR_CONTEXT(bgp, bgp);
6447 afi_t afi;
6448 struct prefix p;
6449 int idx = 0;
6450 int yes = 1;
6451
6452 if (argv_find(argv, argc, "no", &idx))
6453 yes = 0;
6454
6455 if (yes) {
6456 if (!sockunion2hostprefix(nexthop_str, &p))
6457 return CMD_WARNING_CONFIG_FAILED;
6458 }
6459
6460 afi = vpn_policy_getafi(vty, bgp, false);
6461 if (afi == AFI_MAX)
6462 return CMD_WARNING_CONFIG_FAILED;
6463
6464 /*
6465 * pre-change: un-export vpn routes (vpn->vrf routes unaffected)
6466 */
6467 vpn_leak_prechange(BGP_VPN_POLICY_DIR_TOVPN, afi,
6468 bgp_get_default(), bgp);
6469
6470 if (yes) {
6471 bgp->vpn_policy[afi].tovpn_nexthop = p;
6472 SET_FLAG(bgp->vpn_policy[afi].flags,
6473 BGP_VPN_POLICY_TOVPN_NEXTHOP_SET);
6474 } else {
6475 UNSET_FLAG(bgp->vpn_policy[afi].flags,
6476 BGP_VPN_POLICY_TOVPN_NEXTHOP_SET);
6477 }
6478
6479 /* post-change: re-export vpn routes */
6480 vpn_leak_postchange(BGP_VPN_POLICY_DIR_TOVPN, afi,
6481 bgp_get_default(), bgp);
6482
6483 return CMD_SUCCESS;
6484 }
6485
6486 ALIAS (af_nexthop_vpn_export,
6487 af_no_nexthop_vpn_export_cmd,
6488 "no nexthop vpn export",
6489 NO_STR
6490 "Specify next hop to use for VRF advertised prefixes\n"
6491 "Between current address-family and vpn\n"
6492 "For routes leaked from current address-family to vpn\n")
6493
6494 static int vpn_policy_getdirs(struct vty *vty, const char *dstr, int *dodir)
6495 {
6496 if (!strcmp(dstr, "import")) {
6497 dodir[BGP_VPN_POLICY_DIR_FROMVPN] = 1;
6498 } else if (!strcmp(dstr, "export")) {
6499 dodir[BGP_VPN_POLICY_DIR_TOVPN] = 1;
6500 } else if (!strcmp(dstr, "both")) {
6501 dodir[BGP_VPN_POLICY_DIR_FROMVPN] = 1;
6502 dodir[BGP_VPN_POLICY_DIR_TOVPN] = 1;
6503 } else {
6504 vty_out(vty, "%% direction parse error\n");
6505 return CMD_WARNING_CONFIG_FAILED;
6506 }
6507 return CMD_SUCCESS;
6508 }
6509
6510 DEFPY (af_rt_vpn_imexport,
6511 af_rt_vpn_imexport_cmd,
6512 "[no] <rt|route-target> vpn <import|export|both>$direction_str RTLIST...",
6513 NO_STR
6514 "Specify route target list\n"
6515 "Specify route target list\n"
6516 "Between current address-family and vpn\n"
6517 "For routes leaked from vpn to current address-family: match any\n"
6518 "For routes leaked from current address-family to vpn: set\n"
6519 "both import: match any and export: set\n"
6520 "Space separated route target list (A.B.C.D:MN|EF:OPQR|GHJK:MN)\n")
6521 {
6522 VTY_DECLVAR_CONTEXT(bgp, bgp);
6523 int ret;
6524 struct ecommunity *ecom = NULL;
6525 int dodir[BGP_VPN_POLICY_DIR_MAX] = {0};
6526 vpn_policy_direction_t dir;
6527 afi_t afi;
6528 int idx = 0;
6529 int yes = 1;
6530
6531 if (argv_find(argv, argc, "no", &idx))
6532 yes = 0;
6533
6534 afi = vpn_policy_getafi(vty, bgp, false);
6535 if (afi == AFI_MAX)
6536 return CMD_WARNING_CONFIG_FAILED;
6537
6538 ret = vpn_policy_getdirs(vty, direction_str, dodir);
6539 if (ret != CMD_SUCCESS)
6540 return ret;
6541
6542 if (yes) {
6543 if (!argv_find(argv, argc, "RTLIST", &idx)) {
6544 vty_out(vty, "%% Missing RTLIST\n");
6545 return CMD_WARNING_CONFIG_FAILED;
6546 }
6547 ret = set_ecom_list(vty, argc - idx, argv + idx, &ecom);
6548 if (ret != CMD_SUCCESS) {
6549 return ret;
6550 }
6551 }
6552
6553 for (dir = 0; dir < BGP_VPN_POLICY_DIR_MAX; ++dir) {
6554 if (!dodir[dir])
6555 continue;
6556
6557 vpn_leak_prechange(dir, afi, bgp_get_default(), bgp);
6558
6559 if (yes) {
6560 if (bgp->vpn_policy[afi].rtlist[dir])
6561 ecommunity_free(
6562 &bgp->vpn_policy[afi].rtlist[dir]);
6563 bgp->vpn_policy[afi].rtlist[dir] =
6564 ecommunity_dup(ecom);
6565 } else {
6566 if (bgp->vpn_policy[afi].rtlist[dir])
6567 ecommunity_free(
6568 &bgp->vpn_policy[afi].rtlist[dir]);
6569 bgp->vpn_policy[afi].rtlist[dir] = NULL;
6570 }
6571
6572 vpn_leak_postchange(dir, afi, bgp_get_default(), bgp);
6573 }
6574
6575 if (ecom)
6576 ecommunity_free(&ecom);
6577
6578 return CMD_SUCCESS;
6579 }
6580
6581 ALIAS (af_rt_vpn_imexport,
6582 af_no_rt_vpn_imexport_cmd,
6583 "no <rt|route-target> vpn <import|export|both>$direction_str",
6584 NO_STR
6585 "Specify route target list\n"
6586 "Specify route target list\n"
6587 "Between current address-family and vpn\n"
6588 "For routes leaked from vpn to current address-family\n"
6589 "For routes leaked from current address-family to vpn\n"
6590 "both import and export\n")
6591
6592 DEFPY (af_route_map_vpn_imexport,
6593 af_route_map_vpn_imexport_cmd,
6594 /* future: "route-map <vpn|evpn|vrf NAME> <import|export> RMAP" */
6595 "[no] route-map vpn <import|export>$direction_str RMAP$rmap_str",
6596 NO_STR
6597 "Specify route map\n"
6598 "Between current address-family and vpn\n"
6599 "For routes leaked from vpn to current address-family\n"
6600 "For routes leaked from current address-family to vpn\n"
6601 "name of route-map\n")
6602 {
6603 VTY_DECLVAR_CONTEXT(bgp, bgp);
6604 int ret;
6605 int dodir[BGP_VPN_POLICY_DIR_MAX] = {0};
6606 vpn_policy_direction_t dir;
6607 afi_t afi;
6608 int idx = 0;
6609 int yes = 1;
6610
6611 if (argv_find(argv, argc, "no", &idx))
6612 yes = 0;
6613
6614 afi = vpn_policy_getafi(vty, bgp, false);
6615 if (afi == AFI_MAX)
6616 return CMD_WARNING_CONFIG_FAILED;
6617
6618 ret = vpn_policy_getdirs(vty, direction_str, dodir);
6619 if (ret != CMD_SUCCESS)
6620 return ret;
6621
6622 for (dir = 0; dir < BGP_VPN_POLICY_DIR_MAX; ++dir) {
6623 if (!dodir[dir])
6624 continue;
6625
6626 vpn_leak_prechange(dir, afi, bgp_get_default(), bgp);
6627
6628 if (yes) {
6629 if (bgp->vpn_policy[afi].rmap_name[dir])
6630 XFREE(MTYPE_ROUTE_MAP_NAME,
6631 bgp->vpn_policy[afi].rmap_name[dir]);
6632 bgp->vpn_policy[afi].rmap_name[dir] = XSTRDUP(
6633 MTYPE_ROUTE_MAP_NAME, rmap_str);
6634 bgp->vpn_policy[afi].rmap[dir] =
6635 route_map_lookup_by_name(rmap_str);
6636 if (!bgp->vpn_policy[afi].rmap[dir])
6637 return CMD_SUCCESS;
6638 } else {
6639 if (bgp->vpn_policy[afi].rmap_name[dir])
6640 XFREE(MTYPE_ROUTE_MAP_NAME,
6641 bgp->vpn_policy[afi].rmap_name[dir]);
6642 bgp->vpn_policy[afi].rmap_name[dir] = NULL;
6643 bgp->vpn_policy[afi].rmap[dir] = NULL;
6644 }
6645
6646 vpn_leak_postchange(dir, afi, bgp_get_default(), bgp);
6647 }
6648
6649 return CMD_SUCCESS;
6650 }
6651
6652 ALIAS (af_route_map_vpn_imexport,
6653 af_no_route_map_vpn_imexport_cmd,
6654 "no route-map vpn <import|export>$direction_str",
6655 NO_STR
6656 "Specify route map\n"
6657 "Between current address-family and vpn\n"
6658 "For routes leaked from vpn to current address-family\n"
6659 "For routes leaked from current address-family to vpn\n")
6660
6661 DEFPY(af_import_vrf_route_map, af_import_vrf_route_map_cmd,
6662 "[no] import vrf route-map RMAP$rmap_str",
6663 NO_STR
6664 "Import routes from another VRF\n"
6665 "Vrf routes being filtered\n"
6666 "Specify route map\n"
6667 "name of route-map\n")
6668 {
6669 VTY_DECLVAR_CONTEXT(bgp, bgp);
6670 vpn_policy_direction_t dir = BGP_VPN_POLICY_DIR_FROMVPN;
6671 afi_t afi;
6672 int idx = 0;
6673 int yes = 1;
6674 struct bgp *bgp_default;
6675
6676 if (argv_find(argv, argc, "no", &idx))
6677 yes = 0;
6678
6679 afi = vpn_policy_getafi(vty, bgp, true);
6680 if (afi == AFI_MAX)
6681 return CMD_WARNING_CONFIG_FAILED;
6682
6683 bgp_default = bgp_get_default();
6684 if (!bgp_default) {
6685 int32_t ret;
6686 as_t as = bgp->as;
6687
6688 /* Auto-create assuming the same AS */
6689 ret = bgp_get(&bgp_default, &as, NULL,
6690 BGP_INSTANCE_TYPE_DEFAULT);
6691
6692 if (ret) {
6693 vty_out(vty,
6694 "VRF default is not configured as a bgp instance\n");
6695 return CMD_WARNING;
6696 }
6697 }
6698
6699 vpn_leak_prechange(dir, afi, bgp_get_default(), bgp);
6700
6701 if (yes) {
6702 if (bgp->vpn_policy[afi].rmap_name[dir])
6703 XFREE(MTYPE_ROUTE_MAP_NAME,
6704 bgp->vpn_policy[afi].rmap_name[dir]);
6705 bgp->vpn_policy[afi].rmap_name[dir] =
6706 XSTRDUP(MTYPE_ROUTE_MAP_NAME, rmap_str);
6707 bgp->vpn_policy[afi].rmap[dir] =
6708 route_map_lookup_by_name(rmap_str);
6709 if (!bgp->vpn_policy[afi].rmap[dir])
6710 return CMD_SUCCESS;
6711 } else {
6712 if (bgp->vpn_policy[afi].rmap_name[dir])
6713 XFREE(MTYPE_ROUTE_MAP_NAME,
6714 bgp->vpn_policy[afi].rmap_name[dir]);
6715 bgp->vpn_policy[afi].rmap_name[dir] = NULL;
6716 bgp->vpn_policy[afi].rmap[dir] = NULL;
6717 }
6718
6719 vpn_leak_postchange(dir, afi, bgp_get_default(), bgp);
6720
6721 return CMD_SUCCESS;
6722 }
6723
6724 ALIAS(af_import_vrf_route_map, af_no_import_vrf_route_map_cmd,
6725 "no import vrf route-map",
6726 NO_STR
6727 "Import routes from another VRF\n"
6728 "Vrf routes being filtered\n"
6729 "Specify route map\n")
6730
6731 DEFPY (bgp_imexport_vrf,
6732 bgp_imexport_vrf_cmd,
6733 "[no] import vrf NAME$import_name",
6734 NO_STR
6735 "Import routes from another VRF\n"
6736 "VRF to import from\n"
6737 "The name of the VRF\n")
6738 {
6739 VTY_DECLVAR_CONTEXT(bgp, bgp);
6740 struct listnode *node;
6741 struct bgp *vrf_bgp, *bgp_default;
6742 int32_t ret = 0;
6743 as_t as = bgp->as;
6744 bool remove = false;
6745 int32_t idx = 0;
6746 char *vname;
6747 enum bgp_instance_type bgp_type = BGP_INSTANCE_TYPE_VRF;
6748 safi_t safi;
6749 afi_t afi;
6750
6751 if (import_name == NULL) {
6752 vty_out(vty, "%% Missing import name\n");
6753 return CMD_WARNING;
6754 }
6755
6756 if (argv_find(argv, argc, "no", &idx))
6757 remove = true;
6758
6759 afi = vpn_policy_getafi(vty, bgp, true);
6760 if (afi == AFI_MAX)
6761 return CMD_WARNING_CONFIG_FAILED;
6762
6763 safi = bgp_node_safi(vty);
6764
6765 if (((BGP_INSTANCE_TYPE_DEFAULT == bgp->inst_type)
6766 && (strcmp(import_name, BGP_DEFAULT_NAME) == 0))
6767 || (bgp->name && (strcmp(import_name, bgp->name) == 0))) {
6768 vty_out(vty, "%% Cannot %s vrf %s into itself\n",
6769 remove ? "unimport" : "import", import_name);
6770 return CMD_WARNING;
6771 }
6772
6773 bgp_default = bgp_get_default();
6774 if (!bgp_default) {
6775 /* Auto-create assuming the same AS */
6776 ret = bgp_get(&bgp_default, &as, NULL,
6777 BGP_INSTANCE_TYPE_DEFAULT);
6778
6779 if (ret) {
6780 vty_out(vty,
6781 "VRF default is not configured as a bgp instance\n");
6782 return CMD_WARNING;
6783 }
6784 }
6785
6786 vrf_bgp = bgp_lookup_by_name(import_name);
6787 if (!vrf_bgp) {
6788 if (strcmp(import_name, BGP_DEFAULT_NAME) == 0)
6789 vrf_bgp = bgp_default;
6790 else
6791 /* Auto-create assuming the same AS */
6792 ret = bgp_get(&vrf_bgp, &as, import_name, bgp_type);
6793
6794 if (ret) {
6795 vty_out(vty,
6796 "VRF %s is not configured as a bgp instance\n",
6797 import_name);
6798 return CMD_WARNING;
6799 }
6800 }
6801
6802 if (remove) {
6803 vrf_unimport_from_vrf(bgp, vrf_bgp, afi, safi);
6804 } else {
6805 /* Already importing from "import_vrf"? */
6806 for (ALL_LIST_ELEMENTS_RO(bgp->vpn_policy[afi].import_vrf, node,
6807 vname)) {
6808 if (strcmp(vname, import_name) == 0)
6809 return CMD_WARNING;
6810 }
6811
6812 vrf_import_from_vrf(bgp, vrf_bgp, afi, safi);
6813 }
6814
6815 return CMD_SUCCESS;
6816 }
6817
6818 /* This command is valid only in a bgp vrf instance or the default instance */
6819 DEFPY (bgp_imexport_vpn,
6820 bgp_imexport_vpn_cmd,
6821 "[no] <import|export>$direction_str vpn",
6822 NO_STR
6823 "Import routes to this address-family\n"
6824 "Export routes from this address-family\n"
6825 "to/from default instance VPN RIB\n")
6826 {
6827 VTY_DECLVAR_CONTEXT(bgp, bgp);
6828 int previous_state;
6829 afi_t afi;
6830 safi_t safi;
6831 int idx = 0;
6832 int yes = 1;
6833 int flag;
6834 vpn_policy_direction_t dir;
6835
6836 if (argv_find(argv, argc, "no", &idx))
6837 yes = 0;
6838
6839 if (BGP_INSTANCE_TYPE_VRF != bgp->inst_type &&
6840 BGP_INSTANCE_TYPE_DEFAULT != bgp->inst_type) {
6841
6842 vty_out(vty, "%% import|export vpn valid only for bgp vrf or default instance\n");
6843 return CMD_WARNING_CONFIG_FAILED;
6844 }
6845
6846 afi = bgp_node_afi(vty);
6847 safi = bgp_node_safi(vty);
6848 if ((SAFI_UNICAST != safi) || ((AFI_IP != afi) && (AFI_IP6 != afi))) {
6849 vty_out(vty, "%% import|export vpn valid only for unicast ipv4|ipv6\n");
6850 return CMD_WARNING_CONFIG_FAILED;
6851 }
6852
6853 if (!strcmp(direction_str, "import")) {
6854 flag = BGP_CONFIG_MPLSVPN_TO_VRF_IMPORT;
6855 dir = BGP_VPN_POLICY_DIR_FROMVPN;
6856 } else if (!strcmp(direction_str, "export")) {
6857 flag = BGP_CONFIG_VRF_TO_MPLSVPN_EXPORT;
6858 dir = BGP_VPN_POLICY_DIR_TOVPN;
6859 } else {
6860 vty_out(vty, "%% unknown direction %s\n", direction_str);
6861 return CMD_WARNING_CONFIG_FAILED;
6862 }
6863
6864 previous_state = CHECK_FLAG(bgp->af_flags[afi][safi], flag);
6865
6866 if (yes) {
6867 SET_FLAG(bgp->af_flags[afi][safi], flag);
6868 if (!previous_state) {
6869 /* trigger export current vrf */
6870 vpn_leak_postchange(dir, afi, bgp_get_default(), bgp);
6871 }
6872 } else {
6873 if (previous_state) {
6874 /* trigger un-export current vrf */
6875 vpn_leak_prechange(dir, afi, bgp_get_default(), bgp);
6876 }
6877 UNSET_FLAG(bgp->af_flags[afi][safi], flag);
6878 }
6879
6880 return CMD_SUCCESS;
6881 }
6882
6883 DEFPY (af_routetarget_import,
6884 af_routetarget_import_cmd,
6885 "[no] <rt|route-target> redirect import RTLIST...",
6886 NO_STR
6887 "Specify route target list\n"
6888 "Specify route target list\n"
6889 "Flow-spec redirect type route target\n"
6890 "Import routes to this address-family\n"
6891 "Space separated route target list (A.B.C.D:MN|EF:OPQR|GHJK:MN)\n")
6892 {
6893 VTY_DECLVAR_CONTEXT(bgp, bgp);
6894 int ret;
6895 struct ecommunity *ecom = NULL;
6896 afi_t afi;
6897 int idx = 0;
6898 int yes = 1;
6899
6900 if (argv_find(argv, argc, "no", &idx))
6901 yes = 0;
6902
6903 afi = vpn_policy_getafi(vty, bgp, false);
6904 if (afi == AFI_MAX)
6905 return CMD_WARNING_CONFIG_FAILED;
6906
6907 if (yes) {
6908 if (!argv_find(argv, argc, "RTLIST", &idx)) {
6909 vty_out(vty, "%% Missing RTLIST\n");
6910 return CMD_WARNING_CONFIG_FAILED;
6911 }
6912 ret = set_ecom_list(vty, argc - idx, argv + idx, &ecom);
6913 if (ret != CMD_SUCCESS)
6914 return ret;
6915 }
6916
6917 if (yes) {
6918 if (bgp->vpn_policy[afi].import_redirect_rtlist)
6919 ecommunity_free(&bgp->vpn_policy[afi]
6920 .import_redirect_rtlist);
6921 bgp->vpn_policy[afi].import_redirect_rtlist =
6922 ecommunity_dup(ecom);
6923 } else {
6924 if (bgp->vpn_policy[afi].import_redirect_rtlist)
6925 ecommunity_free(&bgp->vpn_policy[afi]
6926 .import_redirect_rtlist);
6927 bgp->vpn_policy[afi].import_redirect_rtlist = NULL;
6928 }
6929
6930 if (ecom)
6931 ecommunity_free(&ecom);
6932
6933 return CMD_SUCCESS;
6934 }
6935
6936 DEFUN_NOSH (address_family_ipv4_safi,
6937 address_family_ipv4_safi_cmd,
6938 "address-family ipv4 [<unicast|multicast|vpn|labeled-unicast|flowspec>]",
6939 "Enter Address Family command mode\n"
6940 "Address Family\n"
6941 BGP_SAFI_WITH_LABEL_HELP_STR)
6942 {
6943
6944 if (argc == 3) {
6945 VTY_DECLVAR_CONTEXT(bgp, bgp);
6946 safi_t safi = bgp_vty_safi_from_str(argv[2]->text);
6947 if (bgp->inst_type != BGP_INSTANCE_TYPE_DEFAULT
6948 && safi != SAFI_UNICAST && safi != SAFI_MULTICAST
6949 && safi != SAFI_EVPN) {
6950 vty_out(vty,
6951 "Only Unicast/Multicast/EVPN SAFIs supported in non-core instances.\n");
6952 return CMD_WARNING_CONFIG_FAILED;
6953 }
6954 vty->node = bgp_node_type(AFI_IP, safi);
6955 } else
6956 vty->node = BGP_IPV4_NODE;
6957
6958 return CMD_SUCCESS;
6959 }
6960
6961 DEFUN_NOSH (address_family_ipv6_safi,
6962 address_family_ipv6_safi_cmd,
6963 "address-family ipv6 [<unicast|multicast|vpn|labeled-unicast|flowspec>]",
6964 "Enter Address Family command mode\n"
6965 "Address Family\n"
6966 BGP_SAFI_WITH_LABEL_HELP_STR)
6967 {
6968 if (argc == 3) {
6969 VTY_DECLVAR_CONTEXT(bgp, bgp);
6970 safi_t safi = bgp_vty_safi_from_str(argv[2]->text);
6971 if (bgp->inst_type != BGP_INSTANCE_TYPE_DEFAULT
6972 && safi != SAFI_UNICAST && safi != SAFI_MULTICAST
6973 && safi != SAFI_EVPN) {
6974 vty_out(vty,
6975 "Only Unicast/Multicast/EVPN SAFIs supported in non-core instances.\n");
6976 return CMD_WARNING_CONFIG_FAILED;
6977 }
6978 vty->node = bgp_node_type(AFI_IP6, safi);
6979 } else
6980 vty->node = BGP_IPV6_NODE;
6981
6982 return CMD_SUCCESS;
6983 }
6984
6985 #ifdef KEEP_OLD_VPN_COMMANDS
6986 DEFUN_NOSH (address_family_vpnv4,
6987 address_family_vpnv4_cmd,
6988 "address-family vpnv4 [unicast]",
6989 "Enter Address Family command mode\n"
6990 "Address Family\n"
6991 "Address Family modifier\n")
6992 {
6993 vty->node = BGP_VPNV4_NODE;
6994 return CMD_SUCCESS;
6995 }
6996
6997 DEFUN_NOSH (address_family_vpnv6,
6998 address_family_vpnv6_cmd,
6999 "address-family vpnv6 [unicast]",
7000 "Enter Address Family command mode\n"
7001 "Address Family\n"
7002 "Address Family modifier\n")
7003 {
7004 vty->node = BGP_VPNV6_NODE;
7005 return CMD_SUCCESS;
7006 }
7007 #endif
7008
7009 DEFUN_NOSH (address_family_evpn,
7010 address_family_evpn_cmd,
7011 "address-family l2vpn evpn",
7012 "Enter Address Family command mode\n"
7013 "Address Family\n"
7014 "Address Family modifier\n")
7015 {
7016 VTY_DECLVAR_CONTEXT(bgp, bgp);
7017 vty->node = BGP_EVPN_NODE;
7018 return CMD_SUCCESS;
7019 }
7020
7021 DEFUN_NOSH (exit_address_family,
7022 exit_address_family_cmd,
7023 "exit-address-family",
7024 "Exit from Address Family configuration mode\n")
7025 {
7026 if (vty->node == BGP_IPV4_NODE || vty->node == BGP_IPV4M_NODE
7027 || vty->node == BGP_IPV4L_NODE || vty->node == BGP_VPNV4_NODE
7028 || vty->node == BGP_IPV6_NODE || vty->node == BGP_IPV6M_NODE
7029 || vty->node == BGP_IPV6L_NODE || vty->node == BGP_VPNV6_NODE
7030 || vty->node == BGP_EVPN_NODE
7031 || vty->node == BGP_FLOWSPECV4_NODE
7032 || vty->node == BGP_FLOWSPECV6_NODE)
7033 vty->node = BGP_NODE;
7034 return CMD_SUCCESS;
7035 }
7036
7037 /* Recalculate bestpath and re-advertise a prefix */
7038 static int bgp_clear_prefix(struct vty *vty, const char *view_name,
7039 const char *ip_str, afi_t afi, safi_t safi,
7040 struct prefix_rd *prd)
7041 {
7042 int ret;
7043 struct prefix match;
7044 struct bgp_node *rn;
7045 struct bgp_node *rm;
7046 struct bgp *bgp;
7047 struct bgp_table *table;
7048 struct bgp_table *rib;
7049
7050 /* BGP structure lookup. */
7051 if (view_name) {
7052 bgp = bgp_lookup_by_name(view_name);
7053 if (bgp == NULL) {
7054 vty_out(vty, "%% Can't find BGP instance %s\n",
7055 view_name);
7056 return CMD_WARNING;
7057 }
7058 } else {
7059 bgp = bgp_get_default();
7060 if (bgp == NULL) {
7061 vty_out(vty, "%% No BGP process is configured\n");
7062 return CMD_WARNING;
7063 }
7064 }
7065
7066 /* Check IP address argument. */
7067 ret = str2prefix(ip_str, &match);
7068 if (!ret) {
7069 vty_out(vty, "%% address is malformed\n");
7070 return CMD_WARNING;
7071 }
7072
7073 match.family = afi2family(afi);
7074 rib = bgp->rib[afi][safi];
7075
7076 if (safi == SAFI_MPLS_VPN) {
7077 for (rn = bgp_table_top(rib); rn; rn = bgp_route_next(rn)) {
7078 if (prd && memcmp(rn->p.u.val, prd->val, 8) != 0)
7079 continue;
7080
7081 if ((table = rn->info) != NULL) {
7082 if ((rm = bgp_node_match(table, &match))
7083 != NULL) {
7084 if (rm->p.prefixlen
7085 == match.prefixlen) {
7086 SET_FLAG(rm->flags,
7087 BGP_NODE_USER_CLEAR);
7088 bgp_process(bgp, rm, afi, safi);
7089 }
7090 bgp_unlock_node(rm);
7091 }
7092 }
7093 }
7094 } else {
7095 if ((rn = bgp_node_match(rib, &match)) != NULL) {
7096 if (rn->p.prefixlen == match.prefixlen) {
7097 SET_FLAG(rn->flags, BGP_NODE_USER_CLEAR);
7098 bgp_process(bgp, rn, afi, safi);
7099 }
7100 bgp_unlock_node(rn);
7101 }
7102 }
7103
7104 return CMD_SUCCESS;
7105 }
7106
7107 /* one clear bgp command to rule them all */
7108 DEFUN (clear_ip_bgp_all,
7109 clear_ip_bgp_all_cmd,
7110 "clear [ip] bgp [<view|vrf> VIEWVRFNAME] ["BGP_AFI_CMD_STR" ["BGP_SAFI_WITH_LABEL_CMD_STR"]] <*|A.B.C.D|X:X::X:X|WORD|(1-4294967295)|external|peer-group WORD> [<soft [<in|out>]|in [prefix-filter]|out>]",
7111 CLEAR_STR
7112 IP_STR
7113 BGP_STR
7114 BGP_INSTANCE_HELP_STR
7115 BGP_AFI_HELP_STR
7116 BGP_SAFI_WITH_LABEL_HELP_STR
7117 "Clear all peers\n"
7118 "BGP neighbor address to clear\n"
7119 "BGP IPv6 neighbor to clear\n"
7120 "BGP neighbor on interface to clear\n"
7121 "Clear peers with the AS number\n"
7122 "Clear all external peers\n"
7123 "Clear all members of peer-group\n"
7124 "BGP peer-group name\n"
7125 BGP_SOFT_STR
7126 BGP_SOFT_IN_STR
7127 BGP_SOFT_OUT_STR
7128 BGP_SOFT_IN_STR
7129 "Push out prefix-list ORF and do inbound soft reconfig\n"
7130 BGP_SOFT_OUT_STR)
7131 {
7132 char *vrf = NULL;
7133
7134 afi_t afi = AFI_IP6;
7135 safi_t safi = SAFI_UNICAST;
7136 enum clear_sort clr_sort = clear_peer;
7137 enum bgp_clear_type clr_type;
7138 char *clr_arg = NULL;
7139
7140 int idx = 0;
7141
7142 /* clear [ip] bgp */
7143 if (argv_find(argv, argc, "ip", &idx))
7144 afi = AFI_IP;
7145
7146 /* [<view|vrf> VIEWVRFNAME] */
7147 if (argv_find(argv, argc, "view", &idx)
7148 || argv_find(argv, argc, "vrf", &idx)) {
7149 vrf = argv[idx + 1]->arg;
7150 idx += 2;
7151 }
7152
7153 /* ["BGP_AFI_CMD_STR" ["BGP_SAFI_CMD_STR"]] */
7154 if (argv_find_and_parse_afi(argv, argc, &idx, &afi))
7155 argv_find_and_parse_safi(argv, argc, &idx, &safi);
7156
7157 /* <*|A.B.C.D|X:X::X:X|WORD|(1-4294967295)|external|peer-group WORD> */
7158 if (argv_find(argv, argc, "*", &idx)) {
7159 clr_sort = clear_all;
7160 } else if (argv_find(argv, argc, "A.B.C.D", &idx)) {
7161 clr_sort = clear_peer;
7162 clr_arg = argv[idx]->arg;
7163 } else if (argv_find(argv, argc, "X:X::X:X", &idx)) {
7164 clr_sort = clear_peer;
7165 clr_arg = argv[idx]->arg;
7166 } else if (argv_find(argv, argc, "peer-group", &idx)) {
7167 clr_sort = clear_group;
7168 idx++;
7169 clr_arg = argv[idx]->arg;
7170 } else if (argv_find(argv, argc, "WORD", &idx)) {
7171 clr_sort = clear_peer;
7172 clr_arg = argv[idx]->arg;
7173 } else if (argv_find(argv, argc, "(1-4294967295)", &idx)) {
7174 clr_sort = clear_as;
7175 clr_arg = argv[idx]->arg;
7176 } else if (argv_find(argv, argc, "external", &idx)) {
7177 clr_sort = clear_external;
7178 }
7179
7180 /* [<soft [<in|out>]|in [prefix-filter]|out>] */
7181 if (argv_find(argv, argc, "soft", &idx)) {
7182 if (argv_find(argv, argc, "in", &idx)
7183 || argv_find(argv, argc, "out", &idx))
7184 clr_type = strmatch(argv[idx]->text, "in")
7185 ? BGP_CLEAR_SOFT_IN
7186 : BGP_CLEAR_SOFT_OUT;
7187 else
7188 clr_type = BGP_CLEAR_SOFT_BOTH;
7189 } else if (argv_find(argv, argc, "in", &idx)) {
7190 clr_type = argv_find(argv, argc, "prefix-filter", &idx)
7191 ? BGP_CLEAR_SOFT_IN_ORF_PREFIX
7192 : BGP_CLEAR_SOFT_IN;
7193 } else if (argv_find(argv, argc, "out", &idx)) {
7194 clr_type = BGP_CLEAR_SOFT_OUT;
7195 } else
7196 clr_type = BGP_CLEAR_SOFT_NONE;
7197
7198 return bgp_clear_vty(vty, vrf, afi, safi, clr_sort, clr_type, clr_arg);
7199 }
7200
7201 DEFUN (clear_ip_bgp_prefix,
7202 clear_ip_bgp_prefix_cmd,
7203 "clear [ip] bgp [<view|vrf> VIEWVRFNAME] prefix A.B.C.D/M",
7204 CLEAR_STR
7205 IP_STR
7206 BGP_STR
7207 BGP_INSTANCE_HELP_STR
7208 "Clear bestpath and re-advertise\n"
7209 "IPv4 prefix\n")
7210 {
7211 char *vrf = NULL;
7212 char *prefix = NULL;
7213
7214 int idx = 0;
7215
7216 /* [<view|vrf> VIEWVRFNAME] */
7217 if (argv_find(argv, argc, "VIEWVRFNAME", &idx))
7218 vrf = argv[idx]->arg;
7219
7220 prefix = argv[argc - 1]->arg;
7221
7222 return bgp_clear_prefix(vty, vrf, prefix, AFI_IP, SAFI_UNICAST, NULL);
7223 }
7224
7225 DEFUN (clear_bgp_ipv6_safi_prefix,
7226 clear_bgp_ipv6_safi_prefix_cmd,
7227 "clear [ip] bgp ipv6 "BGP_SAFI_CMD_STR" prefix X:X::X:X/M",
7228 CLEAR_STR
7229 IP_STR
7230 BGP_STR
7231 "Address Family\n"
7232 BGP_SAFI_HELP_STR
7233 "Clear bestpath and re-advertise\n"
7234 "IPv6 prefix\n")
7235 {
7236 int idx_safi = 0;
7237 int idx_ipv6_prefix = 0;
7238 safi_t safi = SAFI_UNICAST;
7239 char *prefix = argv_find(argv, argc, "X:X::X:X/M", &idx_ipv6_prefix) ?
7240 argv[idx_ipv6_prefix]->arg : NULL;
7241
7242 argv_find_and_parse_safi(argv, argc, &idx_safi, &safi);
7243 return bgp_clear_prefix(
7244 vty, NULL, prefix, AFI_IP6,
7245 safi, NULL);
7246 }
7247
7248 DEFUN (clear_bgp_instance_ipv6_safi_prefix,
7249 clear_bgp_instance_ipv6_safi_prefix_cmd,
7250 "clear [ip] bgp <view|vrf> VIEWVRFNAME ipv6 "BGP_SAFI_CMD_STR" prefix X:X::X:X/M",
7251 CLEAR_STR
7252 IP_STR
7253 BGP_STR
7254 BGP_INSTANCE_HELP_STR
7255 "Address Family\n"
7256 BGP_SAFI_HELP_STR
7257 "Clear bestpath and re-advertise\n"
7258 "IPv6 prefix\n")
7259 {
7260 int idx_word = 3;
7261 int idx_safi = 0;
7262 int idx_ipv6_prefix = 0;
7263 safi_t safi = SAFI_UNICAST;
7264 char *prefix = argv_find(argv, argc, "X:X::X:X/M", &idx_ipv6_prefix) ?
7265 argv[idx_ipv6_prefix]->arg : NULL;
7266 /* [<view|vrf> VIEWVRFNAME] */
7267 char *vrfview = argv_find(argv, argc, "VIEWVRFNAME", &idx_word) ?
7268 argv[idx_word]->arg : NULL;
7269
7270 argv_find_and_parse_safi(argv, argc, &idx_safi, &safi);
7271
7272 return bgp_clear_prefix(
7273 vty, vrfview, prefix,
7274 AFI_IP6, safi, NULL);
7275 }
7276
7277 DEFUN (show_bgp_views,
7278 show_bgp_views_cmd,
7279 "show [ip] bgp views",
7280 SHOW_STR
7281 IP_STR
7282 BGP_STR
7283 "Show the defined BGP views\n")
7284 {
7285 struct list *inst = bm->bgp;
7286 struct listnode *node;
7287 struct bgp *bgp;
7288
7289 if (!bgp_option_check(BGP_OPT_MULTIPLE_INSTANCE)) {
7290 vty_out(vty, "BGP Multiple Instance is not enabled\n");
7291 return CMD_WARNING;
7292 }
7293
7294 vty_out(vty, "Defined BGP views:\n");
7295 for (ALL_LIST_ELEMENTS_RO(inst, node, bgp)) {
7296 /* Skip VRFs. */
7297 if (bgp->inst_type == BGP_INSTANCE_TYPE_VRF)
7298 continue;
7299 vty_out(vty, "\t%s (AS%u)\n", bgp->name ? bgp->name : "(null)",
7300 bgp->as);
7301 }
7302
7303 return CMD_SUCCESS;
7304 }
7305
7306 DEFUN (show_bgp_vrfs,
7307 show_bgp_vrfs_cmd,
7308 "show [ip] bgp vrfs [json]",
7309 SHOW_STR
7310 IP_STR
7311 BGP_STR
7312 "Show BGP VRFs\n"
7313 JSON_STR)
7314 {
7315 char buf[ETHER_ADDR_STRLEN];
7316 struct list *inst = bm->bgp;
7317 struct listnode *node;
7318 struct bgp *bgp;
7319 uint8_t uj = use_json(argc, argv);
7320 json_object *json = NULL;
7321 json_object *json_vrfs = NULL;
7322 int count = 0;
7323
7324 if (!bgp_option_check(BGP_OPT_MULTIPLE_INSTANCE)) {
7325 vty_out(vty, "BGP Multiple Instance is not enabled\n");
7326 return CMD_WARNING;
7327 }
7328
7329 if (uj) {
7330 json = json_object_new_object();
7331 json_vrfs = json_object_new_object();
7332 }
7333
7334 for (ALL_LIST_ELEMENTS_RO(inst, node, bgp)) {
7335 const char *name, *type;
7336 struct peer *peer;
7337 struct listnode *node, *nnode;
7338 int peers_cfg, peers_estb;
7339 json_object *json_vrf = NULL;
7340
7341 /* Skip Views. */
7342 if (bgp->inst_type == BGP_INSTANCE_TYPE_VIEW)
7343 continue;
7344
7345 count++;
7346 if (!uj && count == 1)
7347 vty_out(vty,
7348 "%4s %-5s %-16s %9s %10s %-37s %-10s %-15s\n",
7349 "Type", "Id", "routerId", "#PeersVfg",
7350 "#PeersEstb", "Name", "L3-VNI", "Rmac");
7351
7352 peers_cfg = peers_estb = 0;
7353 if (uj)
7354 json_vrf = json_object_new_object();
7355
7356
7357 for (ALL_LIST_ELEMENTS(bgp->peer, node, nnode, peer)) {
7358 if (!CHECK_FLAG(peer->flags, PEER_FLAG_CONFIG_NODE))
7359 continue;
7360 peers_cfg++;
7361 if (peer->status == Established)
7362 peers_estb++;
7363 }
7364
7365 if (bgp->inst_type == BGP_INSTANCE_TYPE_DEFAULT) {
7366 name = "Default";
7367 type = "DFLT";
7368 } else {
7369 name = bgp->name;
7370 type = "VRF";
7371 }
7372
7373
7374 if (uj) {
7375 int64_t vrf_id_ui = (bgp->vrf_id == VRF_UNKNOWN)
7376 ? -1
7377 : (int64_t)bgp->vrf_id;
7378 json_object_string_add(json_vrf, "type", type);
7379 json_object_int_add(json_vrf, "vrfId", vrf_id_ui);
7380 json_object_string_add(json_vrf, "routerId",
7381 inet_ntoa(bgp->router_id));
7382 json_object_int_add(json_vrf, "numConfiguredPeers",
7383 peers_cfg);
7384 json_object_int_add(json_vrf, "numEstablishedPeers",
7385 peers_estb);
7386
7387 json_object_int_add(json_vrf, "l3vni", bgp->l3vni);
7388 json_object_string_add(
7389 json_vrf, "rmac",
7390 prefix_mac2str(&bgp->rmac, buf, sizeof(buf)));
7391 json_object_object_add(json_vrfs, name, json_vrf);
7392 } else
7393 vty_out(vty,
7394 "%4s %-5d %-16s %9u %10u %-37s %-10u %-15s\n",
7395 type,
7396 bgp->vrf_id == VRF_UNKNOWN ? -1
7397 : (int)bgp->vrf_id,
7398 inet_ntoa(bgp->router_id), peers_cfg,
7399 peers_estb, name, bgp->l3vni,
7400 prefix_mac2str(&bgp->rmac, buf, sizeof(buf)));
7401 }
7402
7403 if (uj) {
7404 json_object_object_add(json, "vrfs", json_vrfs);
7405
7406 json_object_int_add(json, "totalVrfs", count);
7407
7408 vty_out(vty, "%s\n", json_object_to_json_string_ext(
7409 json, JSON_C_TO_STRING_PRETTY));
7410 json_object_free(json);
7411 } else {
7412 if (count)
7413 vty_out(vty,
7414 "\nTotal number of VRFs (including default): %d\n",
7415 count);
7416 }
7417
7418 return CMD_SUCCESS;
7419 }
7420
7421 static void show_address_entry(struct hash_backet *backet, void *args)
7422 {
7423 struct vty *vty = (struct vty *)args;
7424 struct bgp_addr *addr = (struct bgp_addr *)backet->data;
7425
7426 vty_out(vty, "addr: %s, count: %d\n", inet_ntoa(addr->addr),
7427 addr->refcnt);
7428 }
7429
7430 static void show_tip_entry(struct hash_backet *backet, void *args)
7431 {
7432 struct vty *vty = (struct vty *)args;
7433 struct tip_addr *tip = (struct tip_addr *)backet->data;
7434
7435 vty_out(vty, "addr: %s, count: %d\n", inet_ntoa(tip->addr),
7436 tip->refcnt);
7437 }
7438
7439 static void bgp_show_martian_nexthops(struct vty *vty, struct bgp *bgp)
7440 {
7441 vty_out(vty, "self nexthop database:\n");
7442 hash_iterate(bgp->address_hash,
7443 (void (*)(struct hash_backet *, void *))show_address_entry,
7444 vty);
7445
7446 vty_out(vty, "Tunnel-ip database:\n");
7447 hash_iterate(bgp->tip_hash,
7448 (void (*)(struct hash_backet *, void *))show_tip_entry,
7449 vty);
7450 }
7451
7452 DEFUN(show_bgp_martian_nexthop_db, show_bgp_martian_nexthop_db_cmd,
7453 "show bgp [<view|vrf> VIEWVRFNAME] martian next-hop",
7454 SHOW_STR BGP_STR BGP_INSTANCE_HELP_STR
7455 "martian next-hops\n"
7456 "martian next-hop database\n")
7457 {
7458 struct bgp *bgp = NULL;
7459 int idx = 0;
7460
7461 if (argv_find(argv, argc, "view", &idx)
7462 || argv_find(argv, argc, "vrf", &idx))
7463 bgp = bgp_lookup_by_name(argv[idx + 1]->arg);
7464 else
7465 bgp = bgp_get_default();
7466
7467 if (!bgp) {
7468 vty_out(vty, "%% No BGP process is configured\n");
7469 return CMD_WARNING;
7470 }
7471 bgp_show_martian_nexthops(vty, bgp);
7472
7473 return CMD_SUCCESS;
7474 }
7475
7476 DEFUN (show_bgp_memory,
7477 show_bgp_memory_cmd,
7478 "show [ip] bgp memory",
7479 SHOW_STR
7480 IP_STR
7481 BGP_STR
7482 "Global BGP memory statistics\n")
7483 {
7484 char memstrbuf[MTYPE_MEMSTR_LEN];
7485 unsigned long count;
7486
7487 /* RIB related usage stats */
7488 count = mtype_stats_alloc(MTYPE_BGP_NODE);
7489 vty_out(vty, "%ld RIB nodes, using %s of memory\n", count,
7490 mtype_memstr(memstrbuf, sizeof(memstrbuf),
7491 count * sizeof(struct bgp_node)));
7492
7493 count = mtype_stats_alloc(MTYPE_BGP_ROUTE);
7494 vty_out(vty, "%ld BGP routes, using %s of memory\n", count,
7495 mtype_memstr(memstrbuf, sizeof(memstrbuf),
7496 count * sizeof(struct bgp_info)));
7497 if ((count = mtype_stats_alloc(MTYPE_BGP_ROUTE_EXTRA)))
7498 vty_out(vty, "%ld BGP route ancillaries, using %s of memory\n",
7499 count,
7500 mtype_memstr(memstrbuf, sizeof(memstrbuf),
7501 count * sizeof(struct bgp_info_extra)));
7502
7503 if ((count = mtype_stats_alloc(MTYPE_BGP_STATIC)))
7504 vty_out(vty, "%ld Static routes, using %s of memory\n", count,
7505 mtype_memstr(memstrbuf, sizeof(memstrbuf),
7506 count * sizeof(struct bgp_static)));
7507
7508 if ((count = mtype_stats_alloc(MTYPE_BGP_PACKET)))
7509 vty_out(vty, "%ld Packets, using %s of memory\n", count,
7510 mtype_memstr(memstrbuf, sizeof(memstrbuf),
7511 count * sizeof(struct bpacket)));
7512
7513 /* Adj-In/Out */
7514 if ((count = mtype_stats_alloc(MTYPE_BGP_ADJ_IN)))
7515 vty_out(vty, "%ld Adj-In entries, using %s of memory\n", count,
7516 mtype_memstr(memstrbuf, sizeof(memstrbuf),
7517 count * sizeof(struct bgp_adj_in)));
7518 if ((count = mtype_stats_alloc(MTYPE_BGP_ADJ_OUT)))
7519 vty_out(vty, "%ld Adj-Out entries, using %s of memory\n", count,
7520 mtype_memstr(memstrbuf, sizeof(memstrbuf),
7521 count * sizeof(struct bgp_adj_out)));
7522
7523 if ((count = mtype_stats_alloc(MTYPE_BGP_NEXTHOP_CACHE)))
7524 vty_out(vty, "%ld Nexthop cache entries, using %s of memory\n",
7525 count,
7526 mtype_memstr(memstrbuf, sizeof(memstrbuf),
7527 count * sizeof(struct bgp_nexthop_cache)));
7528
7529 if ((count = mtype_stats_alloc(MTYPE_BGP_DAMP_INFO)))
7530 vty_out(vty, "%ld Dampening entries, using %s of memory\n",
7531 count,
7532 mtype_memstr(memstrbuf, sizeof(memstrbuf),
7533 count * sizeof(struct bgp_damp_info)));
7534
7535 /* Attributes */
7536 count = attr_count();
7537 vty_out(vty, "%ld BGP attributes, using %s of memory\n", count,
7538 mtype_memstr(memstrbuf, sizeof(memstrbuf),
7539 count * sizeof(struct attr)));
7540
7541 if ((count = attr_unknown_count()))
7542 vty_out(vty, "%ld unknown attributes\n", count);
7543
7544 /* AS_PATH attributes */
7545 count = aspath_count();
7546 vty_out(vty, "%ld BGP AS-PATH entries, using %s of memory\n", count,
7547 mtype_memstr(memstrbuf, sizeof(memstrbuf),
7548 count * sizeof(struct aspath)));
7549
7550 count = mtype_stats_alloc(MTYPE_AS_SEG);
7551 vty_out(vty, "%ld BGP AS-PATH segments, using %s of memory\n", count,
7552 mtype_memstr(memstrbuf, sizeof(memstrbuf),
7553 count * sizeof(struct assegment)));
7554
7555 /* Other attributes */
7556 if ((count = community_count()))
7557 vty_out(vty, "%ld BGP community entries, using %s of memory\n",
7558 count, mtype_memstr(memstrbuf, sizeof(memstrbuf),
7559 count * sizeof(struct community)));
7560 if ((count = mtype_stats_alloc(MTYPE_ECOMMUNITY)))
7561 vty_out(vty, "%ld BGP community entries, using %s of memory\n",
7562 count, mtype_memstr(memstrbuf, sizeof(memstrbuf),
7563 count * sizeof(struct ecommunity)));
7564 if ((count = mtype_stats_alloc(MTYPE_LCOMMUNITY)))
7565 vty_out(vty,
7566 "%ld BGP large-community entries, using %s of memory\n",
7567 count, mtype_memstr(memstrbuf, sizeof(memstrbuf),
7568 count * sizeof(struct lcommunity)));
7569
7570 if ((count = mtype_stats_alloc(MTYPE_CLUSTER)))
7571 vty_out(vty, "%ld Cluster lists, using %s of memory\n", count,
7572 mtype_memstr(memstrbuf, sizeof(memstrbuf),
7573 count * sizeof(struct cluster_list)));
7574
7575 /* Peer related usage */
7576 count = mtype_stats_alloc(MTYPE_BGP_PEER);
7577 vty_out(vty, "%ld peers, using %s of memory\n", count,
7578 mtype_memstr(memstrbuf, sizeof(memstrbuf),
7579 count * sizeof(struct peer)));
7580
7581 if ((count = mtype_stats_alloc(MTYPE_PEER_GROUP)))
7582 vty_out(vty, "%ld peer groups, using %s of memory\n", count,
7583 mtype_memstr(memstrbuf, sizeof(memstrbuf),
7584 count * sizeof(struct peer_group)));
7585
7586 /* Other */
7587 if ((count = mtype_stats_alloc(MTYPE_HASH)))
7588 vty_out(vty, "%ld hash tables, using %s of memory\n", count,
7589 mtype_memstr(memstrbuf, sizeof(memstrbuf),
7590 count * sizeof(struct hash)));
7591 if ((count = mtype_stats_alloc(MTYPE_HASH_BACKET)))
7592 vty_out(vty, "%ld hash buckets, using %s of memory\n", count,
7593 mtype_memstr(memstrbuf, sizeof(memstrbuf),
7594 count * sizeof(struct hash_backet)));
7595 if ((count = mtype_stats_alloc(MTYPE_BGP_REGEXP)))
7596 vty_out(vty, "%ld compiled regexes, using %s of memory\n",
7597 count, mtype_memstr(memstrbuf, sizeof(memstrbuf),
7598 count * sizeof(regex_t)));
7599 return CMD_SUCCESS;
7600 }
7601
7602 static void bgp_show_bestpath_json(struct bgp *bgp, json_object *json)
7603 {
7604 json_object *bestpath = json_object_new_object();
7605
7606 if (bgp_flag_check(bgp, BGP_FLAG_ASPATH_IGNORE))
7607 json_object_string_add(bestpath, "asPath", "ignore");
7608
7609 if (bgp_flag_check(bgp, BGP_FLAG_ASPATH_CONFED))
7610 json_object_string_add(bestpath, "asPath", "confed");
7611
7612 if (bgp_flag_check(bgp, BGP_FLAG_ASPATH_MULTIPATH_RELAX)) {
7613 if (bgp_flag_check(bgp, BGP_FLAG_MULTIPATH_RELAX_AS_SET))
7614 json_object_string_add(bestpath, "multiPathRelax",
7615 "as-set");
7616 else
7617 json_object_string_add(bestpath, "multiPathRelax",
7618 "true");
7619 } else
7620 json_object_string_add(bestpath, "multiPathRelax", "false");
7621
7622 if (bgp_flag_check(bgp, BGP_FLAG_COMPARE_ROUTER_ID))
7623 json_object_string_add(bestpath, "compareRouterId", "true");
7624 if (bgp_flag_check(bgp, BGP_FLAG_MED_CONFED)
7625 || bgp_flag_check(bgp, BGP_FLAG_MED_MISSING_AS_WORST)) {
7626 if (bgp_flag_check(bgp, BGP_FLAG_MED_CONFED))
7627 json_object_string_add(bestpath, "med", "confed");
7628 if (bgp_flag_check(bgp, BGP_FLAG_MED_MISSING_AS_WORST))
7629 json_object_string_add(bestpath, "med",
7630 "missing-as-worst");
7631 else
7632 json_object_string_add(bestpath, "med", "true");
7633 }
7634
7635 json_object_object_add(json, "bestPath", bestpath);
7636 }
7637
7638 /* Show BGP peer's summary information. */
7639 static int bgp_show_summary(struct vty *vty, struct bgp *bgp, int afi, int safi,
7640 uint8_t use_json, json_object *json)
7641 {
7642 struct peer *peer;
7643 struct listnode *node, *nnode;
7644 unsigned int count = 0, dn_count = 0;
7645 char timebuf[BGP_UPTIME_LEN], dn_flag[2];
7646 char neighbor_buf[VTY_BUFSIZ];
7647 int neighbor_col_default_width = 16;
7648 int len;
7649 int max_neighbor_width = 0;
7650 int pfx_rcd_safi;
7651 json_object *json_peer = NULL;
7652 json_object *json_peers = NULL;
7653
7654 /* labeled-unicast routes are installed in the unicast table so in order
7655 * to
7656 * display the correct PfxRcd value we must look at SAFI_UNICAST
7657 */
7658 if (safi == SAFI_LABELED_UNICAST)
7659 pfx_rcd_safi = SAFI_UNICAST;
7660 else
7661 pfx_rcd_safi = safi;
7662
7663 if (use_json) {
7664 if (json == NULL)
7665 json = json_object_new_object();
7666
7667 json_peers = json_object_new_object();
7668 } else {
7669 /* Loop over all neighbors that will be displayed to determine
7670 * how many
7671 * characters are needed for the Neighbor column
7672 */
7673 for (ALL_LIST_ELEMENTS(bgp->peer, node, nnode, peer)) {
7674 if (!CHECK_FLAG(peer->flags, PEER_FLAG_CONFIG_NODE))
7675 continue;
7676
7677 if (peer->afc[afi][safi]) {
7678 memset(dn_flag, '\0', sizeof(dn_flag));
7679 if (peer_dynamic_neighbor(peer))
7680 dn_flag[0] = '*';
7681
7682 if (peer->hostname
7683 && bgp_flag_check(bgp,
7684 BGP_FLAG_SHOW_HOSTNAME))
7685 sprintf(neighbor_buf, "%s%s(%s) ",
7686 dn_flag, peer->hostname,
7687 peer->host);
7688 else
7689 sprintf(neighbor_buf, "%s%s ", dn_flag,
7690 peer->host);
7691
7692 len = strlen(neighbor_buf);
7693
7694 if (len > max_neighbor_width)
7695 max_neighbor_width = len;
7696 }
7697 }
7698
7699 /* Originally we displayed the Neighbor column as 16
7700 * characters wide so make that the default
7701 */
7702 if (max_neighbor_width < neighbor_col_default_width)
7703 max_neighbor_width = neighbor_col_default_width;
7704 }
7705
7706 for (ALL_LIST_ELEMENTS(bgp->peer, node, nnode, peer)) {
7707 if (!CHECK_FLAG(peer->flags, PEER_FLAG_CONFIG_NODE))
7708 continue;
7709
7710 if (!peer->afc[afi][safi])
7711 continue;
7712
7713 if (!count) {
7714 unsigned long ents;
7715 char memstrbuf[MTYPE_MEMSTR_LEN];
7716 int64_t vrf_id_ui;
7717
7718 vrf_id_ui = (bgp->vrf_id == VRF_UNKNOWN)
7719 ? -1
7720 : (int64_t)bgp->vrf_id;
7721
7722 /* Usage summary and header */
7723 if (use_json) {
7724 json_object_string_add(
7725 json, "routerId",
7726 inet_ntoa(bgp->router_id));
7727 json_object_int_add(json, "as", bgp->as);
7728 json_object_int_add(json, "vrfId", vrf_id_ui);
7729 json_object_string_add(
7730 json, "vrfName",
7731 (bgp->inst_type
7732 == BGP_INSTANCE_TYPE_DEFAULT)
7733 ? "Default"
7734 : bgp->name);
7735 } else {
7736 vty_out(vty,
7737 "BGP router identifier %s, local AS number %u vrf-id %d",
7738 inet_ntoa(bgp->router_id), bgp->as,
7739 bgp->vrf_id == VRF_UNKNOWN
7740 ? -1
7741 : (int)bgp->vrf_id);
7742 vty_out(vty, "\n");
7743 }
7744
7745 if (bgp_update_delay_configured(bgp)) {
7746 if (use_json) {
7747 json_object_int_add(
7748 json, "updateDelayLimit",
7749 bgp->v_update_delay);
7750
7751 if (bgp->v_update_delay
7752 != bgp->v_establish_wait)
7753 json_object_int_add(
7754 json,
7755 "updateDelayEstablishWait",
7756 bgp->v_establish_wait);
7757
7758 if (bgp_update_delay_active(bgp)) {
7759 json_object_string_add(
7760 json,
7761 "updateDelayFirstNeighbor",
7762 bgp->update_delay_begin_time);
7763 json_object_boolean_true_add(
7764 json,
7765 "updateDelayInProgress");
7766 } else {
7767 if (bgp->update_delay_over) {
7768 json_object_string_add(
7769 json,
7770 "updateDelayFirstNeighbor",
7771 bgp->update_delay_begin_time);
7772 json_object_string_add(
7773 json,
7774 "updateDelayBestpathResumed",
7775 bgp->update_delay_end_time);
7776 json_object_string_add(
7777 json,
7778 "updateDelayZebraUpdateResume",
7779 bgp->update_delay_zebra_resume_time);
7780 json_object_string_add(
7781 json,
7782 "updateDelayPeerUpdateResume",
7783 bgp->update_delay_peers_resume_time);
7784 }
7785 }
7786 } else {
7787 vty_out(vty,
7788 "Read-only mode update-delay limit: %d seconds\n",
7789 bgp->v_update_delay);
7790 if (bgp->v_update_delay
7791 != bgp->v_establish_wait)
7792 vty_out(vty,
7793 " Establish wait: %d seconds\n",
7794 bgp->v_establish_wait);
7795
7796 if (bgp_update_delay_active(bgp)) {
7797 vty_out(vty,
7798 " First neighbor established: %s\n",
7799 bgp->update_delay_begin_time);
7800 vty_out(vty,
7801 " Delay in progress\n");
7802 } else {
7803 if (bgp->update_delay_over) {
7804 vty_out(vty,
7805 " First neighbor established: %s\n",
7806 bgp->update_delay_begin_time);
7807 vty_out(vty,
7808 " Best-paths resumed: %s\n",
7809 bgp->update_delay_end_time);
7810 vty_out(vty,
7811 " zebra update resumed: %s\n",
7812 bgp->update_delay_zebra_resume_time);
7813 vty_out(vty,
7814 " peers update resumed: %s\n",
7815 bgp->update_delay_peers_resume_time);
7816 }
7817 }
7818 }
7819 }
7820
7821 if (use_json) {
7822 if (bgp_maxmed_onstartup_configured(bgp)
7823 && bgp->maxmed_active)
7824 json_object_boolean_true_add(
7825 json, "maxMedOnStartup");
7826 if (bgp->v_maxmed_admin)
7827 json_object_boolean_true_add(
7828 json, "maxMedAdministrative");
7829
7830 json_object_int_add(
7831 json, "tableVersion",
7832 bgp_table_version(bgp->rib[afi][safi]));
7833
7834 ents = bgp_table_count(bgp->rib[afi][safi]);
7835 json_object_int_add(json, "ribCount", ents);
7836 json_object_int_add(
7837 json, "ribMemory",
7838 ents * sizeof(struct bgp_node));
7839
7840 ents = listcount(bgp->peer);
7841 json_object_int_add(json, "peerCount", ents);
7842 json_object_int_add(json, "peerMemory",
7843 ents * sizeof(struct peer));
7844
7845 if ((ents = listcount(bgp->group))) {
7846 json_object_int_add(
7847 json, "peerGroupCount", ents);
7848 json_object_int_add(
7849 json, "peerGroupMemory",
7850 ents * sizeof(struct
7851 peer_group));
7852 }
7853
7854 if (CHECK_FLAG(bgp->af_flags[afi][safi],
7855 BGP_CONFIG_DAMPENING))
7856 json_object_boolean_true_add(
7857 json, "dampeningEnabled");
7858 } else {
7859 if (bgp_maxmed_onstartup_configured(bgp)
7860 && bgp->maxmed_active)
7861 vty_out(vty,
7862 "Max-med on-startup active\n");
7863 if (bgp->v_maxmed_admin)
7864 vty_out(vty,
7865 "Max-med administrative active\n");
7866
7867 vty_out(vty, "BGP table version %" PRIu64 "\n",
7868 bgp_table_version(bgp->rib[afi][safi]));
7869
7870 ents = bgp_table_count(bgp->rib[afi][safi]);
7871 vty_out(vty,
7872 "RIB entries %ld, using %s of memory\n",
7873 ents,
7874 mtype_memstr(memstrbuf,
7875 sizeof(memstrbuf),
7876 ents * sizeof(struct
7877 bgp_node)));
7878
7879 /* Peer related usage */
7880 ents = listcount(bgp->peer);
7881 vty_out(vty, "Peers %ld, using %s of memory\n",
7882 ents,
7883 mtype_memstr(
7884 memstrbuf, sizeof(memstrbuf),
7885 ents * sizeof(struct peer)));
7886
7887 if ((ents = listcount(bgp->group)))
7888 vty_out(vty,
7889 "Peer groups %ld, using %s of memory\n",
7890 ents,
7891 mtype_memstr(
7892 memstrbuf,
7893 sizeof(memstrbuf),
7894 ents * sizeof(struct
7895 peer_group)));
7896
7897 if (CHECK_FLAG(bgp->af_flags[afi][safi],
7898 BGP_CONFIG_DAMPENING))
7899 vty_out(vty, "Dampening enabled.\n");
7900 vty_out(vty, "\n");
7901
7902 /* Subtract 8 here because 'Neighbor' is
7903 * 8 characters */
7904 vty_out(vty, "Neighbor");
7905 vty_out(vty, "%*s", max_neighbor_width - 8,
7906 " ");
7907 vty_out(vty,
7908 "V AS MsgRcvd MsgSent TblVer InQ OutQ Up/Down State/PfxRcd\n");
7909 }
7910 }
7911
7912 count++;
7913
7914 if (use_json) {
7915 json_peer = json_object_new_object();
7916
7917 if (peer_dynamic_neighbor(peer))
7918 json_object_boolean_true_add(json_peer,
7919 "dynamicPeer");
7920
7921 if (peer->hostname)
7922 json_object_string_add(json_peer, "hostname",
7923 peer->hostname);
7924
7925 if (peer->domainname)
7926 json_object_string_add(json_peer, "domainname",
7927 peer->domainname);
7928
7929 json_object_int_add(json_peer, "remoteAs", peer->as);
7930 json_object_int_add(json_peer, "version", 4);
7931 json_object_int_add(json_peer, "msgRcvd",
7932 PEER_TOTAL_RX(peer));
7933 json_object_int_add(json_peer, "msgSent",
7934 PEER_TOTAL_TX(peer));
7935
7936 json_object_int_add(json_peer, "tableVersion",
7937 peer->version[afi][safi]);
7938 json_object_int_add(json_peer, "outq",
7939 peer->obuf->count);
7940 json_object_int_add(json_peer, "inq", 0);
7941 peer_uptime(peer->uptime, timebuf, BGP_UPTIME_LEN,
7942 use_json, json_peer);
7943 json_object_int_add(json_peer, "prefixReceivedCount",
7944 peer->pcount[afi][pfx_rcd_safi]);
7945
7946 if (CHECK_FLAG(peer->flags, PEER_FLAG_SHUTDOWN))
7947 json_object_string_add(json_peer, "state",
7948 "Idle (Admin)");
7949 else if (peer->afc_recv[afi][safi])
7950 json_object_string_add(
7951 json_peer, "state",
7952 lookup_msg(bgp_status_msg, peer->status,
7953 NULL));
7954 else if (CHECK_FLAG(peer->sflags,
7955 PEER_STATUS_PREFIX_OVERFLOW))
7956 json_object_string_add(json_peer, "state",
7957 "Idle (PfxCt)");
7958 else
7959 json_object_string_add(
7960 json_peer, "state",
7961 lookup_msg(bgp_status_msg, peer->status,
7962 NULL));
7963
7964 if (peer->conf_if)
7965 json_object_string_add(json_peer, "idType",
7966 "interface");
7967 else if (peer->su.sa.sa_family == AF_INET)
7968 json_object_string_add(json_peer, "idType",
7969 "ipv4");
7970 else if (peer->su.sa.sa_family == AF_INET6)
7971 json_object_string_add(json_peer, "idType",
7972 "ipv6");
7973
7974 json_object_object_add(json_peers, peer->host,
7975 json_peer);
7976 } else {
7977 memset(dn_flag, '\0', sizeof(dn_flag));
7978 if (peer_dynamic_neighbor(peer)) {
7979 dn_count++;
7980 dn_flag[0] = '*';
7981 }
7982
7983 if (peer->hostname
7984 && bgp_flag_check(bgp, BGP_FLAG_SHOW_HOSTNAME))
7985 len = vty_out(vty, "%s%s(%s)", dn_flag,
7986 peer->hostname, peer->host);
7987 else
7988 len = vty_out(vty, "%s%s", dn_flag, peer->host);
7989
7990 /* pad the neighbor column with spaces */
7991 if (len < max_neighbor_width)
7992 vty_out(vty, "%*s", max_neighbor_width - len,
7993 " ");
7994
7995 vty_out(vty, "4 %10u %7u %7u %8" PRIu64 " %4d %4zd %8s",
7996 peer->as, PEER_TOTAL_RX(peer),
7997 PEER_TOTAL_TX(peer), peer->version[afi][safi],
7998 0, peer->obuf->count,
7999 peer_uptime(peer->uptime, timebuf,
8000 BGP_UPTIME_LEN, 0, NULL));
8001
8002 if (peer->status == Established)
8003 if (peer->afc_recv[afi][safi])
8004 vty_out(vty, " %12ld",
8005 peer->pcount[afi]
8006 [pfx_rcd_safi]);
8007 else
8008 vty_out(vty, " NoNeg");
8009 else {
8010 if (CHECK_FLAG(peer->flags, PEER_FLAG_SHUTDOWN))
8011 vty_out(vty, " Idle (Admin)");
8012 else if (CHECK_FLAG(
8013 peer->sflags,
8014 PEER_STATUS_PREFIX_OVERFLOW))
8015 vty_out(vty, " Idle (PfxCt)");
8016 else
8017 vty_out(vty, " %12s",
8018 lookup_msg(bgp_status_msg,
8019 peer->status, NULL));
8020 }
8021 vty_out(vty, "\n");
8022 }
8023 }
8024
8025 if (use_json) {
8026 json_object_object_add(json, "peers", json_peers);
8027
8028 json_object_int_add(json, "totalPeers", count);
8029 json_object_int_add(json, "dynamicPeers", dn_count);
8030
8031 bgp_show_bestpath_json(bgp, json);
8032
8033 vty_out(vty, "%s\n", json_object_to_json_string_ext(
8034 json, JSON_C_TO_STRING_PRETTY));
8035 json_object_free(json);
8036 } else {
8037 if (count)
8038 vty_out(vty, "\nTotal number of neighbors %d\n", count);
8039 else {
8040 vty_out(vty, "No %s neighbor is configured\n",
8041 afi_safi_print(afi, safi));
8042 }
8043
8044 if (dn_count) {
8045 vty_out(vty, "* - dynamic neighbor\n");
8046 vty_out(vty, "%d dynamic neighbor(s), limit %d\n",
8047 dn_count, bgp->dynamic_neighbors_limit);
8048 }
8049 }
8050
8051 return CMD_SUCCESS;
8052 }
8053
8054 static void bgp_show_summary_afi_safi(struct vty *vty, struct bgp *bgp, int afi,
8055 int safi, uint8_t use_json,
8056 json_object *json)
8057 {
8058 int is_first = 1;
8059 int afi_wildcard = (afi == AFI_MAX);
8060 int safi_wildcard = (safi == SAFI_MAX);
8061 int is_wildcard = (afi_wildcard || safi_wildcard);
8062 bool json_output = false;
8063
8064 if (use_json && is_wildcard)
8065 vty_out(vty, "{\n");
8066 if (afi_wildcard)
8067 afi = 1; /* AFI_IP */
8068 while (afi < AFI_MAX) {
8069 if (safi_wildcard)
8070 safi = 1; /* SAFI_UNICAST */
8071 while (safi < SAFI_MAX) {
8072 if (bgp_afi_safi_peer_exists(bgp, afi, safi)) {
8073 json_output = true;
8074 if (is_wildcard) {
8075 /*
8076 * So limit output to those afi/safi
8077 * pairs that
8078 * actualy have something interesting in
8079 * them
8080 */
8081 if (use_json) {
8082 json = json_object_new_object();
8083
8084 if (!is_first)
8085 vty_out(vty, ",\n");
8086 else
8087 is_first = 0;
8088
8089 vty_out(vty, "\"%s\":",
8090 afi_safi_json(afi,
8091 safi));
8092 } else {
8093 vty_out(vty, "\n%s Summary:\n",
8094 afi_safi_print(afi,
8095 safi));
8096 }
8097 }
8098 bgp_show_summary(vty, bgp, afi, safi, use_json,
8099 json);
8100 }
8101 safi++;
8102 if (!safi_wildcard)
8103 safi = SAFI_MAX;
8104 }
8105 afi++;
8106 if (!afi_wildcard)
8107 afi = AFI_MAX;
8108 }
8109
8110 if (use_json && is_wildcard)
8111 vty_out(vty, "}\n");
8112 else if (use_json && !json_output)
8113 vty_out(vty, "{}\n");
8114 }
8115
8116 static void bgp_show_all_instances_summary_vty(struct vty *vty, afi_t afi,
8117 safi_t safi, uint8_t use_json)
8118 {
8119 struct listnode *node, *nnode;
8120 struct bgp *bgp;
8121 json_object *json = NULL;
8122 int is_first = 1;
8123
8124 if (use_json)
8125 vty_out(vty, "{\n");
8126
8127 for (ALL_LIST_ELEMENTS(bm->bgp, node, nnode, bgp)) {
8128 if (use_json) {
8129 json = json_object_new_object();
8130
8131 if (!is_first)
8132 vty_out(vty, ",\n");
8133 else
8134 is_first = 0;
8135
8136 vty_out(vty, "\"%s\":",
8137 (bgp->inst_type == BGP_INSTANCE_TYPE_DEFAULT)
8138 ? "Default"
8139 : bgp->name);
8140 } else {
8141 vty_out(vty, "\nInstance %s:\n",
8142 (bgp->inst_type == BGP_INSTANCE_TYPE_DEFAULT)
8143 ? "Default"
8144 : bgp->name);
8145 }
8146 bgp_show_summary_afi_safi(vty, bgp, afi, safi, use_json, json);
8147 }
8148
8149 if (use_json)
8150 vty_out(vty, "}\n");
8151 }
8152
8153 int bgp_show_summary_vty(struct vty *vty, const char *name, afi_t afi,
8154 safi_t safi, uint8_t use_json)
8155 {
8156 struct bgp *bgp;
8157
8158 if (name) {
8159 if (strmatch(name, "all")) {
8160 bgp_show_all_instances_summary_vty(vty, afi, safi,
8161 use_json);
8162 return CMD_SUCCESS;
8163 } else {
8164 bgp = bgp_lookup_by_name(name);
8165
8166 if (!bgp) {
8167 if (use_json)
8168 vty_out(vty, "{}\n");
8169 else
8170 vty_out(vty,
8171 "%% No such BGP instance exist\n");
8172 return CMD_WARNING;
8173 }
8174
8175 bgp_show_summary_afi_safi(vty, bgp, afi, safi, use_json,
8176 NULL);
8177 return CMD_SUCCESS;
8178 }
8179 }
8180
8181 bgp = bgp_get_default();
8182
8183 if (bgp)
8184 bgp_show_summary_afi_safi(vty, bgp, afi, safi, use_json, NULL);
8185
8186 return CMD_SUCCESS;
8187 }
8188
8189 /* `show [ip] bgp summary' commands. */
8190 DEFUN (show_ip_bgp_summary,
8191 show_ip_bgp_summary_cmd,
8192 "show [ip] bgp [<view|vrf> VIEWVRFNAME] ["BGP_AFI_CMD_STR" ["BGP_SAFI_WITH_LABEL_CMD_STR"]] summary [json]",
8193 SHOW_STR
8194 IP_STR
8195 BGP_STR
8196 BGP_INSTANCE_HELP_STR
8197 BGP_AFI_HELP_STR
8198 BGP_SAFI_WITH_LABEL_HELP_STR
8199 "Summary of BGP neighbor status\n"
8200 JSON_STR)
8201 {
8202 char *vrf = NULL;
8203 afi_t afi = AFI_MAX;
8204 safi_t safi = SAFI_MAX;
8205
8206 int idx = 0;
8207
8208 /* show [ip] bgp */
8209 if (argv_find(argv, argc, "ip", &idx))
8210 afi = AFI_IP;
8211 /* [<view|vrf> VIEWVRFNAME] */
8212 if (argv_find(argv, argc, "view", &idx)
8213 || argv_find(argv, argc, "vrf", &idx))
8214 vrf = argv[++idx]->arg;
8215 /* ["BGP_AFI_CMD_STR" ["BGP_SAFI_CMD_STR"]] */
8216 if (argv_find_and_parse_afi(argv, argc, &idx, &afi)) {
8217 argv_find_and_parse_safi(argv, argc, &idx, &safi);
8218 }
8219
8220 int uj = use_json(argc, argv);
8221
8222 return bgp_show_summary_vty(vty, vrf, afi, safi, uj);
8223 }
8224
8225 const char *afi_safi_print(afi_t afi, safi_t safi)
8226 {
8227 if (afi == AFI_IP && safi == SAFI_UNICAST)
8228 return "IPv4 Unicast";
8229 else if (afi == AFI_IP && safi == SAFI_MULTICAST)
8230 return "IPv4 Multicast";
8231 else if (afi == AFI_IP && safi == SAFI_LABELED_UNICAST)
8232 return "IPv4 Labeled Unicast";
8233 else if (afi == AFI_IP && safi == SAFI_MPLS_VPN)
8234 return "IPv4 VPN";
8235 else if (afi == AFI_IP && safi == SAFI_ENCAP)
8236 return "IPv4 Encap";
8237 else if (afi == AFI_IP && safi == SAFI_FLOWSPEC)
8238 return "IPv4 Flowspec";
8239 else if (afi == AFI_IP6 && safi == SAFI_UNICAST)
8240 return "IPv6 Unicast";
8241 else if (afi == AFI_IP6 && safi == SAFI_MULTICAST)
8242 return "IPv6 Multicast";
8243 else if (afi == AFI_IP6 && safi == SAFI_LABELED_UNICAST)
8244 return "IPv6 Labeled Unicast";
8245 else if (afi == AFI_IP6 && safi == SAFI_MPLS_VPN)
8246 return "IPv6 VPN";
8247 else if (afi == AFI_IP6 && safi == SAFI_ENCAP)
8248 return "IPv6 Encap";
8249 else if (afi == AFI_IP6 && safi == SAFI_FLOWSPEC)
8250 return "IPv6 Flowspec";
8251 else if (afi == AFI_L2VPN && safi == SAFI_EVPN)
8252 return "L2VPN EVPN";
8253 else
8254 return "Unknown";
8255 }
8256
8257 /*
8258 * Please note that we have intentionally camelCased
8259 * the return strings here. So if you want
8260 * to use this function, please ensure you
8261 * are doing this within json output
8262 */
8263 const char *afi_safi_json(afi_t afi, safi_t safi)
8264 {
8265 if (afi == AFI_IP && safi == SAFI_UNICAST)
8266 return "ipv4Unicast";
8267 else if (afi == AFI_IP && safi == SAFI_MULTICAST)
8268 return "ipv4Multicast";
8269 else if (afi == AFI_IP && safi == SAFI_LABELED_UNICAST)
8270 return "ipv4LabeledUnicast";
8271 else if (afi == AFI_IP && safi == SAFI_MPLS_VPN)
8272 return "ipv4Vpn";
8273 else if (afi == AFI_IP && safi == SAFI_ENCAP)
8274 return "ipv4Encap";
8275 else if (afi == AFI_IP && safi == SAFI_FLOWSPEC)
8276 return "ipv4Flowspec";
8277 else if (afi == AFI_IP6 && safi == SAFI_UNICAST)
8278 return "ipv6Unicast";
8279 else if (afi == AFI_IP6 && safi == SAFI_MULTICAST)
8280 return "ipv6Multicast";
8281 else if (afi == AFI_IP6 && safi == SAFI_LABELED_UNICAST)
8282 return "ipv6LabeledUnicast";
8283 else if (afi == AFI_IP6 && safi == SAFI_MPLS_VPN)
8284 return "ipv6Vpn";
8285 else if (afi == AFI_IP6 && safi == SAFI_ENCAP)
8286 return "ipv6Encap";
8287 else if (afi == AFI_IP6 && safi == SAFI_FLOWSPEC)
8288 return "ipv6Flowspec";
8289 else if (afi == AFI_L2VPN && safi == SAFI_EVPN)
8290 return "l2VpnEvpn";
8291 else
8292 return "Unknown";
8293 }
8294
8295 /* Show BGP peer's information. */
8296 enum show_type { show_all, show_peer };
8297
8298 static void bgp_show_peer_afi_orf_cap(struct vty *vty, struct peer *p,
8299 afi_t afi, safi_t safi,
8300 uint16_t adv_smcap, uint16_t adv_rmcap,
8301 uint16_t rcv_smcap, uint16_t rcv_rmcap,
8302 uint8_t use_json, json_object *json_pref)
8303 {
8304 /* Send-Mode */
8305 if (CHECK_FLAG(p->af_cap[afi][safi], adv_smcap)
8306 || CHECK_FLAG(p->af_cap[afi][safi], rcv_smcap)) {
8307 if (use_json) {
8308 if (CHECK_FLAG(p->af_cap[afi][safi], adv_smcap)
8309 && CHECK_FLAG(p->af_cap[afi][safi], rcv_smcap))
8310 json_object_string_add(json_pref, "sendMode",
8311 "advertisedAndReceived");
8312 else if (CHECK_FLAG(p->af_cap[afi][safi], adv_smcap))
8313 json_object_string_add(json_pref, "sendMode",
8314 "advertised");
8315 else if (CHECK_FLAG(p->af_cap[afi][safi], rcv_smcap))
8316 json_object_string_add(json_pref, "sendMode",
8317 "received");
8318 } else {
8319 vty_out(vty, " Send-mode: ");
8320 if (CHECK_FLAG(p->af_cap[afi][safi], adv_smcap))
8321 vty_out(vty, "advertised");
8322 if (CHECK_FLAG(p->af_cap[afi][safi], rcv_smcap))
8323 vty_out(vty, "%sreceived",
8324 CHECK_FLAG(p->af_cap[afi][safi],
8325 adv_smcap)
8326 ? ", "
8327 : "");
8328 vty_out(vty, "\n");
8329 }
8330 }
8331
8332 /* Receive-Mode */
8333 if (CHECK_FLAG(p->af_cap[afi][safi], adv_rmcap)
8334 || CHECK_FLAG(p->af_cap[afi][safi], rcv_rmcap)) {
8335 if (use_json) {
8336 if (CHECK_FLAG(p->af_cap[afi][safi], adv_rmcap)
8337 && CHECK_FLAG(p->af_cap[afi][safi], rcv_rmcap))
8338 json_object_string_add(json_pref, "recvMode",
8339 "advertisedAndReceived");
8340 else if (CHECK_FLAG(p->af_cap[afi][safi], adv_rmcap))
8341 json_object_string_add(json_pref, "recvMode",
8342 "advertised");
8343 else if (CHECK_FLAG(p->af_cap[afi][safi], rcv_rmcap))
8344 json_object_string_add(json_pref, "recvMode",
8345 "received");
8346 } else {
8347 vty_out(vty, " Receive-mode: ");
8348 if (CHECK_FLAG(p->af_cap[afi][safi], adv_rmcap))
8349 vty_out(vty, "advertised");
8350 if (CHECK_FLAG(p->af_cap[afi][safi], rcv_rmcap))
8351 vty_out(vty, "%sreceived",
8352 CHECK_FLAG(p->af_cap[afi][safi],
8353 adv_rmcap)
8354 ? ", "
8355 : "");
8356 vty_out(vty, "\n");
8357 }
8358 }
8359 }
8360
8361 static void bgp_show_peer_afi(struct vty *vty, struct peer *p, afi_t afi,
8362 safi_t safi, uint8_t use_json,
8363 json_object *json_neigh)
8364 {
8365 struct bgp_filter *filter;
8366 struct peer_af *paf;
8367 char orf_pfx_name[BUFSIZ];
8368 int orf_pfx_count;
8369 json_object *json_af = NULL;
8370 json_object *json_prefA = NULL;
8371 json_object *json_prefB = NULL;
8372 json_object *json_addr = NULL;
8373
8374 if (use_json) {
8375 json_addr = json_object_new_object();
8376 json_af = json_object_new_object();
8377 filter = &p->filter[afi][safi];
8378
8379 if (peer_group_active(p))
8380 json_object_string_add(json_addr, "peerGroupMember",
8381 p->group->name);
8382
8383 paf = peer_af_find(p, afi, safi);
8384 if (paf && PAF_SUBGRP(paf)) {
8385 json_object_int_add(json_addr, "updateGroupId",
8386 PAF_UPDGRP(paf)->id);
8387 json_object_int_add(json_addr, "subGroupId",
8388 PAF_SUBGRP(paf)->id);
8389 json_object_int_add(json_addr, "packetQueueLength",
8390 bpacket_queue_virtual_length(paf));
8391 }
8392
8393 if (CHECK_FLAG(p->af_cap[afi][safi], PEER_CAP_ORF_PREFIX_SM_ADV)
8394 || CHECK_FLAG(p->af_cap[afi][safi],
8395 PEER_CAP_ORF_PREFIX_SM_RCV)
8396 || CHECK_FLAG(p->af_cap[afi][safi],
8397 PEER_CAP_ORF_PREFIX_RM_ADV)
8398 || CHECK_FLAG(p->af_cap[afi][safi],
8399 PEER_CAP_ORF_PREFIX_RM_RCV)) {
8400 json_object_int_add(json_af, "orfType",
8401 ORF_TYPE_PREFIX);
8402 json_prefA = json_object_new_object();
8403 bgp_show_peer_afi_orf_cap(vty, p, afi, safi,
8404 PEER_CAP_ORF_PREFIX_SM_ADV,
8405 PEER_CAP_ORF_PREFIX_RM_ADV,
8406 PEER_CAP_ORF_PREFIX_SM_RCV,
8407 PEER_CAP_ORF_PREFIX_RM_RCV,
8408 use_json, json_prefA);
8409 json_object_object_add(json_af, "orfPrefixList",
8410 json_prefA);
8411 }
8412
8413 if (CHECK_FLAG(p->af_cap[afi][safi], PEER_CAP_ORF_PREFIX_SM_ADV)
8414 || CHECK_FLAG(p->af_cap[afi][safi],
8415 PEER_CAP_ORF_PREFIX_SM_OLD_RCV)
8416 || CHECK_FLAG(p->af_cap[afi][safi],
8417 PEER_CAP_ORF_PREFIX_RM_ADV)
8418 || CHECK_FLAG(p->af_cap[afi][safi],
8419 PEER_CAP_ORF_PREFIX_RM_OLD_RCV)) {
8420 json_object_int_add(json_af, "orfOldType",
8421 ORF_TYPE_PREFIX_OLD);
8422 json_prefB = json_object_new_object();
8423 bgp_show_peer_afi_orf_cap(
8424 vty, p, afi, safi, PEER_CAP_ORF_PREFIX_SM_ADV,
8425 PEER_CAP_ORF_PREFIX_RM_ADV,
8426 PEER_CAP_ORF_PREFIX_SM_OLD_RCV,
8427 PEER_CAP_ORF_PREFIX_RM_OLD_RCV, use_json,
8428 json_prefB);
8429 json_object_object_add(json_af, "orfOldPrefixList",
8430 json_prefB);
8431 }
8432
8433 if (CHECK_FLAG(p->af_cap[afi][safi], PEER_CAP_ORF_PREFIX_SM_ADV)
8434 || CHECK_FLAG(p->af_cap[afi][safi],
8435 PEER_CAP_ORF_PREFIX_SM_RCV)
8436 || CHECK_FLAG(p->af_cap[afi][safi],
8437 PEER_CAP_ORF_PREFIX_SM_OLD_RCV)
8438 || CHECK_FLAG(p->af_cap[afi][safi],
8439 PEER_CAP_ORF_PREFIX_RM_ADV)
8440 || CHECK_FLAG(p->af_cap[afi][safi],
8441 PEER_CAP_ORF_PREFIX_RM_RCV)
8442 || CHECK_FLAG(p->af_cap[afi][safi],
8443 PEER_CAP_ORF_PREFIX_RM_OLD_RCV))
8444 json_object_object_add(json_addr, "afDependentCap",
8445 json_af);
8446 else
8447 json_object_free(json_af);
8448
8449 sprintf(orf_pfx_name, "%s.%d.%d", p->host, afi, safi);
8450 orf_pfx_count = prefix_bgp_show_prefix_list(
8451 NULL, afi, orf_pfx_name, use_json);
8452
8453 if (CHECK_FLAG(p->af_sflags[afi][safi],
8454 PEER_STATUS_ORF_PREFIX_SEND)
8455 || orf_pfx_count) {
8456 if (CHECK_FLAG(p->af_sflags[afi][safi],
8457 PEER_STATUS_ORF_PREFIX_SEND))
8458 json_object_boolean_true_add(json_neigh,
8459 "orfSent");
8460 if (orf_pfx_count)
8461 json_object_int_add(json_addr, "orfRecvCounter",
8462 orf_pfx_count);
8463 }
8464 if (CHECK_FLAG(p->af_sflags[afi][safi],
8465 PEER_STATUS_ORF_WAIT_REFRESH))
8466 json_object_string_add(
8467 json_addr, "orfFirstUpdate",
8468 "deferredUntilORFOrRouteRefreshRecvd");
8469
8470 if (CHECK_FLAG(p->af_flags[afi][safi],
8471 PEER_FLAG_REFLECTOR_CLIENT))
8472 json_object_boolean_true_add(json_addr,
8473 "routeReflectorClient");
8474 if (CHECK_FLAG(p->af_flags[afi][safi],
8475 PEER_FLAG_RSERVER_CLIENT))
8476 json_object_boolean_true_add(json_addr,
8477 "routeServerClient");
8478 if (CHECK_FLAG(p->af_flags[afi][safi], PEER_FLAG_SOFT_RECONFIG))
8479 json_object_boolean_true_add(json_addr,
8480 "inboundSoftConfigPermit");
8481
8482 if (CHECK_FLAG(p->af_flags[afi][safi],
8483 PEER_FLAG_REMOVE_PRIVATE_AS_ALL_REPLACE))
8484 json_object_boolean_true_add(
8485 json_addr,
8486 "privateAsNumsAllReplacedInUpdatesToNbr");
8487 else if (CHECK_FLAG(p->af_flags[afi][safi],
8488 PEER_FLAG_REMOVE_PRIVATE_AS_REPLACE))
8489 json_object_boolean_true_add(
8490 json_addr,
8491 "privateAsNumsReplacedInUpdatesToNbr");
8492 else if (CHECK_FLAG(p->af_flags[afi][safi],
8493 PEER_FLAG_REMOVE_PRIVATE_AS_ALL))
8494 json_object_boolean_true_add(
8495 json_addr,
8496 "privateAsNumsAllRemovedInUpdatesToNbr");
8497 else if (CHECK_FLAG(p->af_flags[afi][safi],
8498 PEER_FLAG_REMOVE_PRIVATE_AS))
8499 json_object_boolean_true_add(
8500 json_addr,
8501 "privateAsNumsRemovedInUpdatesToNbr");
8502
8503 if (CHECK_FLAG(p->af_flags[afi][safi],
8504 PEER_FLAG_ADDPATH_TX_ALL_PATHS))
8505 json_object_boolean_true_add(json_addr,
8506 "addpathTxAllPaths");
8507
8508 if (CHECK_FLAG(p->af_flags[afi][safi],
8509 PEER_FLAG_ADDPATH_TX_BESTPATH_PER_AS))
8510 json_object_boolean_true_add(json_addr,
8511 "addpathTxBestpathPerAS");
8512
8513 if (CHECK_FLAG(p->af_flags[afi][safi], PEER_FLAG_AS_OVERRIDE))
8514 json_object_string_add(json_addr,
8515 "overrideASNsInOutboundUpdates",
8516 "ifAspathEqualRemoteAs");
8517
8518 if (CHECK_FLAG(p->af_flags[afi][safi], PEER_FLAG_NEXTHOP_SELF)
8519 || CHECK_FLAG(p->af_flags[afi][safi],
8520 PEER_FLAG_FORCE_NEXTHOP_SELF))
8521 json_object_boolean_true_add(json_addr,
8522 "routerAlwaysNextHop");
8523 if (CHECK_FLAG(p->af_flags[afi][safi],
8524 PEER_FLAG_AS_PATH_UNCHANGED))
8525 json_object_boolean_true_add(
8526 json_addr, "unchangedAsPathPropogatedToNbr");
8527 if (CHECK_FLAG(p->af_flags[afi][safi],
8528 PEER_FLAG_NEXTHOP_UNCHANGED))
8529 json_object_boolean_true_add(
8530 json_addr, "unchangedNextHopPropogatedToNbr");
8531 if (CHECK_FLAG(p->af_flags[afi][safi], PEER_FLAG_MED_UNCHANGED))
8532 json_object_boolean_true_add(
8533 json_addr, "unchangedMedPropogatedToNbr");
8534 if (CHECK_FLAG(p->af_flags[afi][safi], PEER_FLAG_SEND_COMMUNITY)
8535 || CHECK_FLAG(p->af_flags[afi][safi],
8536 PEER_FLAG_SEND_EXT_COMMUNITY)) {
8537 if (CHECK_FLAG(p->af_flags[afi][safi],
8538 PEER_FLAG_SEND_COMMUNITY)
8539 && CHECK_FLAG(p->af_flags[afi][safi],
8540 PEER_FLAG_SEND_EXT_COMMUNITY))
8541 json_object_string_add(json_addr,
8542 "commAttriSentToNbr",
8543 "extendedAndStandard");
8544 else if (CHECK_FLAG(p->af_flags[afi][safi],
8545 PEER_FLAG_SEND_EXT_COMMUNITY))
8546 json_object_string_add(json_addr,
8547 "commAttriSentToNbr",
8548 "extended");
8549 else
8550 json_object_string_add(json_addr,
8551 "commAttriSentToNbr",
8552 "standard");
8553 }
8554 if (CHECK_FLAG(p->af_flags[afi][safi],
8555 PEER_FLAG_DEFAULT_ORIGINATE)) {
8556 if (p->default_rmap[afi][safi].name)
8557 json_object_string_add(
8558 json_addr, "defaultRouteMap",
8559 p->default_rmap[afi][safi].name);
8560
8561 if (paf && PAF_SUBGRP(paf)
8562 && CHECK_FLAG(PAF_SUBGRP(paf)->sflags,
8563 SUBGRP_STATUS_DEFAULT_ORIGINATE))
8564 json_object_boolean_true_add(json_addr,
8565 "defaultSent");
8566 else
8567 json_object_boolean_true_add(json_addr,
8568 "defaultNotSent");
8569 }
8570
8571 if (afi == AFI_L2VPN && safi == SAFI_EVPN) {
8572 if (is_evpn_enabled())
8573 json_object_boolean_true_add(
8574 json_addr, "advertiseAllVnis");
8575 }
8576
8577 if (filter->plist[FILTER_IN].name
8578 || filter->dlist[FILTER_IN].name
8579 || filter->aslist[FILTER_IN].name
8580 || filter->map[RMAP_IN].name)
8581 json_object_boolean_true_add(json_addr,
8582 "inboundPathPolicyConfig");
8583 if (filter->plist[FILTER_OUT].name
8584 || filter->dlist[FILTER_OUT].name
8585 || filter->aslist[FILTER_OUT].name
8586 || filter->map[RMAP_OUT].name || filter->usmap.name)
8587 json_object_boolean_true_add(
8588 json_addr, "outboundPathPolicyConfig");
8589
8590 /* prefix-list */
8591 if (filter->plist[FILTER_IN].name)
8592 json_object_string_add(json_addr,
8593 "incomingUpdatePrefixFilterList",
8594 filter->plist[FILTER_IN].name);
8595 if (filter->plist[FILTER_OUT].name)
8596 json_object_string_add(json_addr,
8597 "outgoingUpdatePrefixFilterList",
8598 filter->plist[FILTER_OUT].name);
8599
8600 /* distribute-list */
8601 if (filter->dlist[FILTER_IN].name)
8602 json_object_string_add(
8603 json_addr, "incomingUpdateNetworkFilterList",
8604 filter->dlist[FILTER_IN].name);
8605 if (filter->dlist[FILTER_OUT].name)
8606 json_object_string_add(
8607 json_addr, "outgoingUpdateNetworkFilterList",
8608 filter->dlist[FILTER_OUT].name);
8609
8610 /* filter-list. */
8611 if (filter->aslist[FILTER_IN].name)
8612 json_object_string_add(json_addr,
8613 "incomingUpdateAsPathFilterList",
8614 filter->aslist[FILTER_IN].name);
8615 if (filter->aslist[FILTER_OUT].name)
8616 json_object_string_add(json_addr,
8617 "outgoingUpdateAsPathFilterList",
8618 filter->aslist[FILTER_OUT].name);
8619
8620 /* route-map. */
8621 if (filter->map[RMAP_IN].name)
8622 json_object_string_add(
8623 json_addr, "routeMapForIncomingAdvertisements",
8624 filter->map[RMAP_IN].name);
8625 if (filter->map[RMAP_OUT].name)
8626 json_object_string_add(
8627 json_addr, "routeMapForOutgoingAdvertisements",
8628 filter->map[RMAP_OUT].name);
8629
8630 /* unsuppress-map */
8631 if (filter->usmap.name)
8632 json_object_string_add(json_addr,
8633 "selectiveUnsuppressRouteMap",
8634 filter->usmap.name);
8635
8636 /* Receive prefix count */
8637 json_object_int_add(json_addr, "acceptedPrefixCounter",
8638 p->pcount[afi][safi]);
8639
8640 /* Maximum prefix */
8641 if (CHECK_FLAG(p->af_flags[afi][safi], PEER_FLAG_MAX_PREFIX)) {
8642 json_object_int_add(json_addr, "prefixAllowedMax",
8643 p->pmax[afi][safi]);
8644 if (CHECK_FLAG(p->af_flags[afi][safi],
8645 PEER_FLAG_MAX_PREFIX_WARNING))
8646 json_object_boolean_true_add(
8647 json_addr, "prefixAllowedMaxWarning");
8648 json_object_int_add(json_addr,
8649 "prefixAllowedWarningThresh",
8650 p->pmax_threshold[afi][safi]);
8651 if (p->pmax_restart[afi][safi])
8652 json_object_int_add(
8653 json_addr,
8654 "prefixAllowedRestartIntervalMsecs",
8655 p->pmax_restart[afi][safi] * 60000);
8656 }
8657 json_object_object_add(json_neigh, afi_safi_print(afi, safi),
8658 json_addr);
8659
8660 } else {
8661 filter = &p->filter[afi][safi];
8662
8663 vty_out(vty, " For address family: %s\n",
8664 afi_safi_print(afi, safi));
8665
8666 if (peer_group_active(p))
8667 vty_out(vty, " %s peer-group member\n",
8668 p->group->name);
8669
8670 paf = peer_af_find(p, afi, safi);
8671 if (paf && PAF_SUBGRP(paf)) {
8672 vty_out(vty, " Update group %" PRIu64
8673 ", subgroup %" PRIu64 "\n",
8674 PAF_UPDGRP(paf)->id, PAF_SUBGRP(paf)->id);
8675 vty_out(vty, " Packet Queue length %d\n",
8676 bpacket_queue_virtual_length(paf));
8677 } else {
8678 vty_out(vty, " Not part of any update group\n");
8679 }
8680 if (CHECK_FLAG(p->af_cap[afi][safi], PEER_CAP_ORF_PREFIX_SM_ADV)
8681 || CHECK_FLAG(p->af_cap[afi][safi],
8682 PEER_CAP_ORF_PREFIX_SM_RCV)
8683 || CHECK_FLAG(p->af_cap[afi][safi],
8684 PEER_CAP_ORF_PREFIX_SM_OLD_RCV)
8685 || CHECK_FLAG(p->af_cap[afi][safi],
8686 PEER_CAP_ORF_PREFIX_RM_ADV)
8687 || CHECK_FLAG(p->af_cap[afi][safi],
8688 PEER_CAP_ORF_PREFIX_RM_RCV)
8689 || CHECK_FLAG(p->af_cap[afi][safi],
8690 PEER_CAP_ORF_PREFIX_RM_OLD_RCV))
8691 vty_out(vty, " AF-dependant capabilities:\n");
8692
8693 if (CHECK_FLAG(p->af_cap[afi][safi], PEER_CAP_ORF_PREFIX_SM_ADV)
8694 || CHECK_FLAG(p->af_cap[afi][safi],
8695 PEER_CAP_ORF_PREFIX_SM_RCV)
8696 || CHECK_FLAG(p->af_cap[afi][safi],
8697 PEER_CAP_ORF_PREFIX_RM_ADV)
8698 || CHECK_FLAG(p->af_cap[afi][safi],
8699 PEER_CAP_ORF_PREFIX_RM_RCV)) {
8700 vty_out(vty,
8701 " Outbound Route Filter (ORF) type (%d) Prefix-list:\n",
8702 ORF_TYPE_PREFIX);
8703 bgp_show_peer_afi_orf_cap(
8704 vty, p, afi, safi, PEER_CAP_ORF_PREFIX_SM_ADV,
8705 PEER_CAP_ORF_PREFIX_RM_ADV,
8706 PEER_CAP_ORF_PREFIX_SM_RCV,
8707 PEER_CAP_ORF_PREFIX_RM_RCV, use_json, NULL);
8708 }
8709 if (CHECK_FLAG(p->af_cap[afi][safi], PEER_CAP_ORF_PREFIX_SM_ADV)
8710 || CHECK_FLAG(p->af_cap[afi][safi],
8711 PEER_CAP_ORF_PREFIX_SM_OLD_RCV)
8712 || CHECK_FLAG(p->af_cap[afi][safi],
8713 PEER_CAP_ORF_PREFIX_RM_ADV)
8714 || CHECK_FLAG(p->af_cap[afi][safi],
8715 PEER_CAP_ORF_PREFIX_RM_OLD_RCV)) {
8716 vty_out(vty,
8717 " Outbound Route Filter (ORF) type (%d) Prefix-list:\n",
8718 ORF_TYPE_PREFIX_OLD);
8719 bgp_show_peer_afi_orf_cap(
8720 vty, p, afi, safi, PEER_CAP_ORF_PREFIX_SM_ADV,
8721 PEER_CAP_ORF_PREFIX_RM_ADV,
8722 PEER_CAP_ORF_PREFIX_SM_OLD_RCV,
8723 PEER_CAP_ORF_PREFIX_RM_OLD_RCV, use_json, NULL);
8724 }
8725
8726 sprintf(orf_pfx_name, "%s.%d.%d", p->host, afi, safi);
8727 orf_pfx_count = prefix_bgp_show_prefix_list(
8728 NULL, afi, orf_pfx_name, use_json);
8729
8730 if (CHECK_FLAG(p->af_sflags[afi][safi],
8731 PEER_STATUS_ORF_PREFIX_SEND)
8732 || orf_pfx_count) {
8733 vty_out(vty, " Outbound Route Filter (ORF):");
8734 if (CHECK_FLAG(p->af_sflags[afi][safi],
8735 PEER_STATUS_ORF_PREFIX_SEND))
8736 vty_out(vty, " sent;");
8737 if (orf_pfx_count)
8738 vty_out(vty, " received (%d entries)",
8739 orf_pfx_count);
8740 vty_out(vty, "\n");
8741 }
8742 if (CHECK_FLAG(p->af_sflags[afi][safi],
8743 PEER_STATUS_ORF_WAIT_REFRESH))
8744 vty_out(vty,
8745 " First update is deferred until ORF or ROUTE-REFRESH is received\n");
8746
8747 if (CHECK_FLAG(p->af_flags[afi][safi],
8748 PEER_FLAG_REFLECTOR_CLIENT))
8749 vty_out(vty, " Route-Reflector Client\n");
8750 if (CHECK_FLAG(p->af_flags[afi][safi],
8751 PEER_FLAG_RSERVER_CLIENT))
8752 vty_out(vty, " Route-Server Client\n");
8753 if (CHECK_FLAG(p->af_flags[afi][safi], PEER_FLAG_SOFT_RECONFIG))
8754 vty_out(vty,
8755 " Inbound soft reconfiguration allowed\n");
8756
8757 if (CHECK_FLAG(p->af_flags[afi][safi],
8758 PEER_FLAG_REMOVE_PRIVATE_AS_ALL_REPLACE))
8759 vty_out(vty,
8760 " Private AS numbers (all) replaced in updates to this neighbor\n");
8761 else if (CHECK_FLAG(p->af_flags[afi][safi],
8762 PEER_FLAG_REMOVE_PRIVATE_AS_REPLACE))
8763 vty_out(vty,
8764 " Private AS numbers replaced in updates to this neighbor\n");
8765 else if (CHECK_FLAG(p->af_flags[afi][safi],
8766 PEER_FLAG_REMOVE_PRIVATE_AS_ALL))
8767 vty_out(vty,
8768 " Private AS numbers (all) removed in updates to this neighbor\n");
8769 else if (CHECK_FLAG(p->af_flags[afi][safi],
8770 PEER_FLAG_REMOVE_PRIVATE_AS))
8771 vty_out(vty,
8772 " Private AS numbers removed in updates to this neighbor\n");
8773
8774 if (CHECK_FLAG(p->af_flags[afi][safi],
8775 PEER_FLAG_ADDPATH_TX_ALL_PATHS))
8776 vty_out(vty, " Advertise all paths via addpath\n");
8777
8778 if (CHECK_FLAG(p->af_flags[afi][safi],
8779 PEER_FLAG_ADDPATH_TX_BESTPATH_PER_AS))
8780 vty_out(vty,
8781 " Advertise bestpath per AS via addpath\n");
8782
8783 if (CHECK_FLAG(p->af_flags[afi][safi], PEER_FLAG_AS_OVERRIDE))
8784 vty_out(vty,
8785 " Override ASNs in outbound updates if aspath equals remote-as\n");
8786
8787 if (CHECK_FLAG(p->af_flags[afi][safi], PEER_FLAG_NEXTHOP_SELF)
8788 || CHECK_FLAG(p->af_flags[afi][safi],
8789 PEER_FLAG_FORCE_NEXTHOP_SELF))
8790 vty_out(vty, " NEXT_HOP is always this router\n");
8791 if (CHECK_FLAG(p->af_flags[afi][safi],
8792 PEER_FLAG_AS_PATH_UNCHANGED))
8793 vty_out(vty,
8794 " AS_PATH is propagated unchanged to this neighbor\n");
8795 if (CHECK_FLAG(p->af_flags[afi][safi],
8796 PEER_FLAG_NEXTHOP_UNCHANGED))
8797 vty_out(vty,
8798 " NEXT_HOP is propagated unchanged to this neighbor\n");
8799 if (CHECK_FLAG(p->af_flags[afi][safi], PEER_FLAG_MED_UNCHANGED))
8800 vty_out(vty,
8801 " MED is propagated unchanged to this neighbor\n");
8802 if (CHECK_FLAG(p->af_flags[afi][safi], PEER_FLAG_SEND_COMMUNITY)
8803 || CHECK_FLAG(p->af_flags[afi][safi],
8804 PEER_FLAG_SEND_EXT_COMMUNITY)
8805 || CHECK_FLAG(p->af_flags[afi][safi],
8806 PEER_FLAG_SEND_LARGE_COMMUNITY)) {
8807 vty_out(vty,
8808 " Community attribute sent to this neighbor");
8809 if (CHECK_FLAG(p->af_flags[afi][safi],
8810 PEER_FLAG_SEND_COMMUNITY)
8811 && CHECK_FLAG(p->af_flags[afi][safi],
8812 PEER_FLAG_SEND_EXT_COMMUNITY)
8813 && CHECK_FLAG(p->af_flags[afi][safi],
8814 PEER_FLAG_SEND_LARGE_COMMUNITY))
8815 vty_out(vty, "(all)\n");
8816 else if (CHECK_FLAG(p->af_flags[afi][safi],
8817 PEER_FLAG_SEND_LARGE_COMMUNITY))
8818 vty_out(vty, "(large)\n");
8819 else if (CHECK_FLAG(p->af_flags[afi][safi],
8820 PEER_FLAG_SEND_EXT_COMMUNITY))
8821 vty_out(vty, "(extended)\n");
8822 else
8823 vty_out(vty, "(standard)\n");
8824 }
8825 if (CHECK_FLAG(p->af_flags[afi][safi],
8826 PEER_FLAG_DEFAULT_ORIGINATE)) {
8827 vty_out(vty, " Default information originate,");
8828
8829 if (p->default_rmap[afi][safi].name)
8830 vty_out(vty, " default route-map %s%s,",
8831 p->default_rmap[afi][safi].map ? "*"
8832 : "",
8833 p->default_rmap[afi][safi].name);
8834 if (paf && PAF_SUBGRP(paf)
8835 && CHECK_FLAG(PAF_SUBGRP(paf)->sflags,
8836 SUBGRP_STATUS_DEFAULT_ORIGINATE))
8837 vty_out(vty, " default sent\n");
8838 else
8839 vty_out(vty, " default not sent\n");
8840 }
8841
8842 /* advertise-vni-all */
8843 if (afi == AFI_L2VPN && safi == SAFI_EVPN) {
8844 if (is_evpn_enabled())
8845 vty_out(vty, " advertise-all-vni\n");
8846 }
8847
8848 if (filter->plist[FILTER_IN].name
8849 || filter->dlist[FILTER_IN].name
8850 || filter->aslist[FILTER_IN].name
8851 || filter->map[RMAP_IN].name)
8852 vty_out(vty, " Inbound path policy configured\n");
8853 if (filter->plist[FILTER_OUT].name
8854 || filter->dlist[FILTER_OUT].name
8855 || filter->aslist[FILTER_OUT].name
8856 || filter->map[RMAP_OUT].name || filter->usmap.name)
8857 vty_out(vty, " Outbound path policy configured\n");
8858
8859 /* prefix-list */
8860 if (filter->plist[FILTER_IN].name)
8861 vty_out(vty,
8862 " Incoming update prefix filter list is %s%s\n",
8863 filter->plist[FILTER_IN].plist ? "*" : "",
8864 filter->plist[FILTER_IN].name);
8865 if (filter->plist[FILTER_OUT].name)
8866 vty_out(vty,
8867 " Outgoing update prefix filter list is %s%s\n",
8868 filter->plist[FILTER_OUT].plist ? "*" : "",
8869 filter->plist[FILTER_OUT].name);
8870
8871 /* distribute-list */
8872 if (filter->dlist[FILTER_IN].name)
8873 vty_out(vty,
8874 " Incoming update network filter list is %s%s\n",
8875 filter->dlist[FILTER_IN].alist ? "*" : "",
8876 filter->dlist[FILTER_IN].name);
8877 if (filter->dlist[FILTER_OUT].name)
8878 vty_out(vty,
8879 " Outgoing update network filter list is %s%s\n",
8880 filter->dlist[FILTER_OUT].alist ? "*" : "",
8881 filter->dlist[FILTER_OUT].name);
8882
8883 /* filter-list. */
8884 if (filter->aslist[FILTER_IN].name)
8885 vty_out(vty,
8886 " Incoming update AS path filter list is %s%s\n",
8887 filter->aslist[FILTER_IN].aslist ? "*" : "",
8888 filter->aslist[FILTER_IN].name);
8889 if (filter->aslist[FILTER_OUT].name)
8890 vty_out(vty,
8891 " Outgoing update AS path filter list is %s%s\n",
8892 filter->aslist[FILTER_OUT].aslist ? "*" : "",
8893 filter->aslist[FILTER_OUT].name);
8894
8895 /* route-map. */
8896 if (filter->map[RMAP_IN].name)
8897 vty_out(vty,
8898 " Route map for incoming advertisements is %s%s\n",
8899 filter->map[RMAP_IN].map ? "*" : "",
8900 filter->map[RMAP_IN].name);
8901 if (filter->map[RMAP_OUT].name)
8902 vty_out(vty,
8903 " Route map for outgoing advertisements is %s%s\n",
8904 filter->map[RMAP_OUT].map ? "*" : "",
8905 filter->map[RMAP_OUT].name);
8906
8907 /* unsuppress-map */
8908 if (filter->usmap.name)
8909 vty_out(vty,
8910 " Route map for selective unsuppress is %s%s\n",
8911 filter->usmap.map ? "*" : "",
8912 filter->usmap.name);
8913
8914 /* Receive prefix count */
8915 vty_out(vty, " %ld accepted prefixes\n", p->pcount[afi][safi]);
8916
8917 /* Maximum prefix */
8918 if (CHECK_FLAG(p->af_flags[afi][safi], PEER_FLAG_MAX_PREFIX)) {
8919 vty_out(vty, " Maximum prefixes allowed %ld%s\n",
8920 p->pmax[afi][safi],
8921 CHECK_FLAG(p->af_flags[afi][safi],
8922 PEER_FLAG_MAX_PREFIX_WARNING)
8923 ? " (warning-only)"
8924 : "");
8925 vty_out(vty, " Threshold for warning message %d%%",
8926 p->pmax_threshold[afi][safi]);
8927 if (p->pmax_restart[afi][safi])
8928 vty_out(vty, ", restart interval %d min",
8929 p->pmax_restart[afi][safi]);
8930 vty_out(vty, "\n");
8931 }
8932
8933 vty_out(vty, "\n");
8934 }
8935 }
8936
8937 static void bgp_show_peer(struct vty *vty, struct peer *p, uint8_t use_json,
8938 json_object *json)
8939 {
8940 struct bgp *bgp;
8941 char buf1[PREFIX2STR_BUFFER], buf[SU_ADDRSTRLEN];
8942 char timebuf[BGP_UPTIME_LEN];
8943 char dn_flag[2];
8944 const char *subcode_str;
8945 const char *code_str;
8946 afi_t afi;
8947 safi_t safi;
8948 uint16_t i;
8949 uint8_t *msg;
8950 json_object *json_neigh = NULL;
8951 time_t epoch_tbuf;
8952
8953 bgp = p->bgp;
8954
8955 if (use_json)
8956 json_neigh = json_object_new_object();
8957
8958 memset(dn_flag, '\0', sizeof(dn_flag));
8959 if (!p->conf_if && peer_dynamic_neighbor(p))
8960 dn_flag[0] = '*';
8961
8962 if (!use_json) {
8963 if (p->conf_if) /* Configured interface name. */
8964 vty_out(vty, "BGP neighbor on %s: %s, ", p->conf_if,
8965 BGP_PEER_SU_UNSPEC(p)
8966 ? "None"
8967 : sockunion2str(&p->su, buf,
8968 SU_ADDRSTRLEN));
8969 else /* Configured IP address. */
8970 vty_out(vty, "BGP neighbor is %s%s, ", dn_flag,
8971 p->host);
8972 }
8973
8974 if (use_json) {
8975 if (p->conf_if && BGP_PEER_SU_UNSPEC(p))
8976 json_object_string_add(json_neigh, "bgpNeighborAddr",
8977 "none");
8978 else if (p->conf_if && !BGP_PEER_SU_UNSPEC(p))
8979 json_object_string_add(
8980 json_neigh, "bgpNeighborAddr",
8981 sockunion2str(&p->su, buf, SU_ADDRSTRLEN));
8982
8983 json_object_int_add(json_neigh, "remoteAs", p->as);
8984
8985 if (p->change_local_as)
8986 json_object_int_add(json_neigh, "localAs",
8987 p->change_local_as);
8988 else
8989 json_object_int_add(json_neigh, "localAs", p->local_as);
8990
8991 if (CHECK_FLAG(p->flags, PEER_FLAG_LOCAL_AS_NO_PREPEND))
8992 json_object_boolean_true_add(json_neigh,
8993 "localAsNoPrepend");
8994
8995 if (CHECK_FLAG(p->flags, PEER_FLAG_LOCAL_AS_REPLACE_AS))
8996 json_object_boolean_true_add(json_neigh,
8997 "localAsReplaceAs");
8998 } else {
8999 if ((p->as_type == AS_SPECIFIED) || (p->as_type == AS_EXTERNAL)
9000 || (p->as_type == AS_INTERNAL))
9001 vty_out(vty, "remote AS %u, ", p->as);
9002 else
9003 vty_out(vty, "remote AS Unspecified, ");
9004 vty_out(vty, "local AS %u%s%s, ",
9005 p->change_local_as ? p->change_local_as : p->local_as,
9006 CHECK_FLAG(p->flags, PEER_FLAG_LOCAL_AS_NO_PREPEND)
9007 ? " no-prepend"
9008 : "",
9009 CHECK_FLAG(p->flags, PEER_FLAG_LOCAL_AS_REPLACE_AS)
9010 ? " replace-as"
9011 : "");
9012 }
9013 /* peer type internal, external, confed-internal or confed-external */
9014 if (p->as == p->local_as) {
9015 if (use_json) {
9016 if (CHECK_FLAG(bgp->config, BGP_CONFIG_CONFEDERATION))
9017 json_object_boolean_true_add(
9018 json_neigh, "nbrConfedInternalLink");
9019 else
9020 json_object_boolean_true_add(json_neigh,
9021 "nbrInternalLink");
9022 } else {
9023 if (CHECK_FLAG(bgp->config, BGP_CONFIG_CONFEDERATION))
9024 vty_out(vty, "confed-internal link\n");
9025 else
9026 vty_out(vty, "internal link\n");
9027 }
9028 } else {
9029 if (use_json) {
9030 if (CHECK_FLAG(bgp->config, BGP_CONFIG_CONFEDERATION))
9031 json_object_boolean_true_add(
9032 json_neigh, "nbrConfedExternalLink");
9033 else
9034 json_object_boolean_true_add(json_neigh,
9035 "nbrExternalLink");
9036 } else {
9037 if (bgp_confederation_peers_check(bgp, p->as))
9038 vty_out(vty, "confed-external link\n");
9039 else
9040 vty_out(vty, "external link\n");
9041 }
9042 }
9043
9044 /* Description. */
9045 if (p->desc) {
9046 if (use_json)
9047 json_object_string_add(json_neigh, "nbrDesc", p->desc);
9048 else
9049 vty_out(vty, " Description: %s\n", p->desc);
9050 }
9051
9052 if (p->hostname) {
9053 if (use_json) {
9054 if (p->hostname)
9055 json_object_string_add(json_neigh, "hostname",
9056 p->hostname);
9057
9058 if (p->domainname)
9059 json_object_string_add(json_neigh, "domainname",
9060 p->domainname);
9061 } else {
9062 if (p->domainname && (p->domainname[0] != '\0'))
9063 vty_out(vty, "Hostname: %s.%s\n", p->hostname,
9064 p->domainname);
9065 else
9066 vty_out(vty, "Hostname: %s\n", p->hostname);
9067 }
9068 }
9069
9070 /* Peer-group */
9071 if (p->group) {
9072 if (use_json) {
9073 json_object_string_add(json_neigh, "peerGroup",
9074 p->group->name);
9075
9076 if (dn_flag[0]) {
9077 struct prefix prefix, *range = NULL;
9078
9079 sockunion2hostprefix(&(p->su), &prefix);
9080 range = peer_group_lookup_dynamic_neighbor_range(
9081 p->group, &prefix);
9082
9083 if (range) {
9084 prefix2str(range, buf1, sizeof(buf1));
9085 json_object_string_add(
9086 json_neigh,
9087 "peerSubnetRangeGroup", buf1);
9088 }
9089 }
9090 } else {
9091 vty_out(vty,
9092 " Member of peer-group %s for session parameters\n",
9093 p->group->name);
9094
9095 if (dn_flag[0]) {
9096 struct prefix prefix, *range = NULL;
9097
9098 sockunion2hostprefix(&(p->su), &prefix);
9099 range = peer_group_lookup_dynamic_neighbor_range(
9100 p->group, &prefix);
9101
9102 if (range) {
9103 prefix2str(range, buf1, sizeof(buf1));
9104 vty_out(vty,
9105 " Belongs to the subnet range group: %s\n",
9106 buf1);
9107 }
9108 }
9109 }
9110 }
9111
9112 if (use_json) {
9113 /* Administrative shutdown. */
9114 if (CHECK_FLAG(p->flags, PEER_FLAG_SHUTDOWN))
9115 json_object_boolean_true_add(json_neigh,
9116 "adminShutDown");
9117
9118 /* BGP Version. */
9119 json_object_int_add(json_neigh, "bgpVersion", 4);
9120 json_object_string_add(
9121 json_neigh, "remoteRouterId",
9122 inet_ntop(AF_INET, &p->remote_id, buf1, sizeof(buf1)));
9123 json_object_string_add(
9124 json_neigh, "localRouterId",
9125 inet_ntop(AF_INET, &bgp->router_id, buf1,
9126 sizeof(buf1)));
9127
9128 /* Confederation */
9129 if (CHECK_FLAG(bgp->config, BGP_CONFIG_CONFEDERATION)
9130 && bgp_confederation_peers_check(bgp, p->as))
9131 json_object_boolean_true_add(json_neigh,
9132 "nbrCommonAdmin");
9133
9134 /* Status. */
9135 json_object_string_add(
9136 json_neigh, "bgpState",
9137 lookup_msg(bgp_status_msg, p->status, NULL));
9138
9139 if (p->status == Established) {
9140 time_t uptime;
9141
9142 uptime = bgp_clock();
9143 uptime -= p->uptime;
9144 epoch_tbuf = time(NULL) - uptime;
9145
9146 #if CONFDATE > 20200101
9147 CPP_NOTICE(
9148 "bgpTimerUp should be deprecated and can be removed now");
9149 #endif
9150 /*
9151 * bgpTimerUp was miliseconds that was accurate
9152 * up to 1 day, then the value returned
9153 * became garbage. So in order to provide
9154 * some level of backwards compatability,
9155 * we still provde the data, but now
9156 * we are returning the correct value
9157 * and also adding a new bgpTimerUpMsec
9158 * which will allow us to deprecate
9159 * this eventually
9160 */
9161 json_object_int_add(json_neigh, "bgpTimerUp",
9162 uptime * 1000);
9163 json_object_int_add(json_neigh, "bgpTimerUpMsec",
9164 uptime * 1000);
9165 json_object_string_add(json_neigh, "bgpTimerUpString",
9166 peer_uptime(p->uptime, timebuf,
9167 BGP_UPTIME_LEN, 0,
9168 NULL));
9169 json_object_int_add(json_neigh,
9170 "bgpTimerUpEstablishedEpoch",
9171 epoch_tbuf);
9172 }
9173
9174 else if (p->status == Active) {
9175 if (CHECK_FLAG(p->flags, PEER_FLAG_PASSIVE))
9176 json_object_string_add(json_neigh, "bgpStateIs",
9177 "passive");
9178 else if (CHECK_FLAG(p->sflags, PEER_STATUS_NSF_WAIT))
9179 json_object_string_add(json_neigh, "bgpStateIs",
9180 "passiveNSF");
9181 }
9182
9183 /* read timer */
9184 time_t uptime;
9185 struct tm *tm;
9186
9187 uptime = bgp_clock();
9188 uptime -= p->readtime;
9189 tm = gmtime(&uptime);
9190 json_object_int_add(json_neigh, "bgpTimerLastRead",
9191 (tm->tm_sec * 1000) + (tm->tm_min * 60000)
9192 + (tm->tm_hour * 3600000));
9193
9194 uptime = bgp_clock();
9195 uptime -= p->last_write;
9196 tm = gmtime(&uptime);
9197 json_object_int_add(json_neigh, "bgpTimerLastWrite",
9198 (tm->tm_sec * 1000) + (tm->tm_min * 60000)
9199 + (tm->tm_hour * 3600000));
9200
9201 uptime = bgp_clock();
9202 uptime -= p->update_time;
9203 tm = gmtime(&uptime);
9204 json_object_int_add(json_neigh, "bgpInUpdateElapsedTimeMsecs",
9205 (tm->tm_sec * 1000) + (tm->tm_min * 60000)
9206 + (tm->tm_hour * 3600000));
9207
9208 /* Configured timer values. */
9209 json_object_int_add(json_neigh, "bgpTimerHoldTimeMsecs",
9210 p->v_holdtime * 1000);
9211 json_object_int_add(json_neigh,
9212 "bgpTimerKeepAliveIntervalMsecs",
9213 p->v_keepalive * 1000);
9214 if (CHECK_FLAG(p->flags, PEER_FLAG_TIMER)) {
9215 json_object_int_add(json_neigh,
9216 "bgpTimerConfiguredHoldTimeMsecs",
9217 p->holdtime * 1000);
9218 json_object_int_add(
9219 json_neigh,
9220 "bgpTimerConfiguredKeepAliveIntervalMsecs",
9221 p->keepalive * 1000);
9222 } else if ((bgp->default_holdtime != BGP_DEFAULT_HOLDTIME)
9223 || (bgp->default_keepalive
9224 != BGP_DEFAULT_KEEPALIVE)) {
9225 json_object_int_add(json_neigh,
9226 "bgpTimerConfiguredHoldTimeMsecs",
9227 bgp->default_holdtime);
9228 json_object_int_add(
9229 json_neigh,
9230 "bgpTimerConfiguredKeepAliveIntervalMsecs",
9231 bgp->default_keepalive);
9232 }
9233 } else {
9234 /* Administrative shutdown. */
9235 if (CHECK_FLAG(p->flags, PEER_FLAG_SHUTDOWN))
9236 vty_out(vty, " Administratively shut down\n");
9237
9238 /* BGP Version. */
9239 vty_out(vty, " BGP version 4");
9240 vty_out(vty, ", remote router ID %s\n",
9241 inet_ntop(AF_INET, &p->remote_id, buf1, sizeof(buf1)));
9242
9243 /* Confederation */
9244 if (CHECK_FLAG(bgp->config, BGP_CONFIG_CONFEDERATION)
9245 && bgp_confederation_peers_check(bgp, p->as))
9246 vty_out(vty,
9247 " Neighbor under common administration\n");
9248
9249 /* Status. */
9250 vty_out(vty, " BGP state = %s",
9251 lookup_msg(bgp_status_msg, p->status, NULL));
9252
9253 if (p->status == Established)
9254 vty_out(vty, ", up for %8s",
9255 peer_uptime(p->uptime, timebuf, BGP_UPTIME_LEN,
9256 0, NULL));
9257
9258 else if (p->status == Active) {
9259 if (CHECK_FLAG(p->flags, PEER_FLAG_PASSIVE))
9260 vty_out(vty, " (passive)");
9261 else if (CHECK_FLAG(p->sflags, PEER_STATUS_NSF_WAIT))
9262 vty_out(vty, " (NSF passive)");
9263 }
9264 vty_out(vty, "\n");
9265
9266 /* read timer */
9267 vty_out(vty, " Last read %s",
9268 peer_uptime(p->readtime, timebuf, BGP_UPTIME_LEN, 0,
9269 NULL));
9270 vty_out(vty, ", Last write %s\n",
9271 peer_uptime(p->last_write, timebuf, BGP_UPTIME_LEN, 0,
9272 NULL));
9273
9274 /* Configured timer values. */
9275 vty_out(vty,
9276 " Hold time is %d, keepalive interval is %d seconds\n",
9277 p->v_holdtime, p->v_keepalive);
9278 if (CHECK_FLAG(p->flags, PEER_FLAG_TIMER)) {
9279 vty_out(vty, " Configured hold time is %d",
9280 p->holdtime);
9281 vty_out(vty, ", keepalive interval is %d seconds\n",
9282 p->keepalive);
9283 } else if ((bgp->default_holdtime != BGP_DEFAULT_HOLDTIME)
9284 || (bgp->default_keepalive
9285 != BGP_DEFAULT_KEEPALIVE)) {
9286 vty_out(vty, " Configured hold time is %d",
9287 bgp->default_holdtime);
9288 vty_out(vty, ", keepalive interval is %d seconds\n",
9289 bgp->default_keepalive);
9290 }
9291 }
9292 /* Capability. */
9293 if (p->status == Established) {
9294 if (p->cap || p->afc_adv[AFI_IP][SAFI_UNICAST]
9295 || p->afc_recv[AFI_IP][SAFI_UNICAST]
9296 || p->afc_adv[AFI_IP][SAFI_MULTICAST]
9297 || p->afc_recv[AFI_IP][SAFI_MULTICAST]
9298 || p->afc_adv[AFI_IP6][SAFI_UNICAST]
9299 || p->afc_recv[AFI_IP6][SAFI_UNICAST]
9300 || p->afc_adv[AFI_IP6][SAFI_MULTICAST]
9301 || p->afc_recv[AFI_IP6][SAFI_MULTICAST]
9302 || p->afc_adv[AFI_IP6][SAFI_MPLS_VPN]
9303 || p->afc_recv[AFI_IP6][SAFI_MPLS_VPN]
9304 || p->afc_adv[AFI_IP6][SAFI_ENCAP]
9305 || p->afc_recv[AFI_IP6][SAFI_ENCAP]
9306 || p->afc_adv[AFI_IP6][SAFI_FLOWSPEC]
9307 || p->afc_recv[AFI_IP6][SAFI_FLOWSPEC]
9308 || p->afc_adv[AFI_IP][SAFI_ENCAP]
9309 || p->afc_recv[AFI_IP][SAFI_ENCAP]
9310 || p->afc_adv[AFI_IP][SAFI_FLOWSPEC]
9311 || p->afc_recv[AFI_IP][SAFI_FLOWSPEC]
9312 || p->afc_adv[AFI_IP][SAFI_MPLS_VPN]
9313 || p->afc_recv[AFI_IP][SAFI_MPLS_VPN]) {
9314 if (use_json) {
9315 json_object *json_cap = NULL;
9316
9317 json_cap = json_object_new_object();
9318
9319 /* AS4 */
9320 if (CHECK_FLAG(p->cap, PEER_CAP_AS4_RCV)
9321 || CHECK_FLAG(p->cap, PEER_CAP_AS4_ADV)) {
9322 if (CHECK_FLAG(p->cap, PEER_CAP_AS4_ADV)
9323 && CHECK_FLAG(p->cap,
9324 PEER_CAP_AS4_RCV))
9325 json_object_string_add(
9326 json_cap, "4byteAs",
9327 "advertisedAndReceived");
9328 else if (CHECK_FLAG(p->cap,
9329 PEER_CAP_AS4_ADV))
9330 json_object_string_add(
9331 json_cap, "4byteAs",
9332 "advertised");
9333 else if (CHECK_FLAG(p->cap,
9334 PEER_CAP_AS4_RCV))
9335 json_object_string_add(
9336 json_cap, "4byteAs",
9337 "received");
9338 }
9339
9340 /* AddPath */
9341 if (CHECK_FLAG(p->cap, PEER_CAP_ADDPATH_RCV)
9342 || CHECK_FLAG(p->cap,
9343 PEER_CAP_ADDPATH_ADV)) {
9344 json_object *json_add = NULL;
9345 const char *print_store;
9346
9347 json_add = json_object_new_object();
9348
9349 FOREACH_AFI_SAFI (afi, safi) {
9350 json_object *json_sub = NULL;
9351 json_sub =
9352 json_object_new_object();
9353 print_store = afi_safi_print(
9354 afi, safi);
9355
9356 if (CHECK_FLAG(
9357 p->af_cap[afi]
9358 [safi],
9359 PEER_CAP_ADDPATH_AF_TX_ADV)
9360 || CHECK_FLAG(
9361 p->af_cap[afi]
9362 [safi],
9363 PEER_CAP_ADDPATH_AF_TX_RCV)) {
9364 if (CHECK_FLAG(
9365 p->af_cap
9366 [afi]
9367 [safi],
9368 PEER_CAP_ADDPATH_AF_TX_ADV)
9369 && CHECK_FLAG(
9370 p->af_cap
9371 [afi]
9372 [safi],
9373 PEER_CAP_ADDPATH_AF_TX_RCV))
9374 json_object_boolean_true_add(
9375 json_sub,
9376 "txAdvertisedAndReceived");
9377 else if (
9378 CHECK_FLAG(
9379 p->af_cap
9380 [afi]
9381 [safi],
9382 PEER_CAP_ADDPATH_AF_TX_ADV))
9383 json_object_boolean_true_add(
9384 json_sub,
9385 "txAdvertised");
9386 else if (
9387 CHECK_FLAG(
9388 p->af_cap
9389 [afi]
9390 [safi],
9391 PEER_CAP_ADDPATH_AF_TX_RCV))
9392 json_object_boolean_true_add(
9393 json_sub,
9394 "txReceived");
9395 }
9396
9397 if (CHECK_FLAG(
9398 p->af_cap[afi]
9399 [safi],
9400 PEER_CAP_ADDPATH_AF_RX_ADV)
9401 || CHECK_FLAG(
9402 p->af_cap[afi]
9403 [safi],
9404 PEER_CAP_ADDPATH_AF_RX_RCV)) {
9405 if (CHECK_FLAG(
9406 p->af_cap
9407 [afi]
9408 [safi],
9409 PEER_CAP_ADDPATH_AF_RX_ADV)
9410 && CHECK_FLAG(
9411 p->af_cap
9412 [afi]
9413 [safi],
9414 PEER_CAP_ADDPATH_AF_RX_RCV))
9415 json_object_boolean_true_add(
9416 json_sub,
9417 "rxAdvertisedAndReceived");
9418 else if (
9419 CHECK_FLAG(
9420 p->af_cap
9421 [afi]
9422 [safi],
9423 PEER_CAP_ADDPATH_AF_RX_ADV))
9424 json_object_boolean_true_add(
9425 json_sub,
9426 "rxAdvertised");
9427 else if (
9428 CHECK_FLAG(
9429 p->af_cap
9430 [afi]
9431 [safi],
9432 PEER_CAP_ADDPATH_AF_RX_RCV))
9433 json_object_boolean_true_add(
9434 json_sub,
9435 "rxReceived");
9436 }
9437
9438 if (CHECK_FLAG(
9439 p->af_cap[afi]
9440 [safi],
9441 PEER_CAP_ADDPATH_AF_TX_ADV)
9442 || CHECK_FLAG(
9443 p->af_cap[afi]
9444 [safi],
9445 PEER_CAP_ADDPATH_AF_TX_RCV)
9446 || CHECK_FLAG(
9447 p->af_cap[afi]
9448 [safi],
9449 PEER_CAP_ADDPATH_AF_RX_ADV)
9450 || CHECK_FLAG(
9451 p->af_cap[afi]
9452 [safi],
9453 PEER_CAP_ADDPATH_AF_RX_RCV))
9454 json_object_object_add(
9455 json_add,
9456 print_store,
9457 json_sub);
9458 else
9459 json_object_free(
9460 json_sub);
9461 }
9462
9463 json_object_object_add(
9464 json_cap, "addPath", json_add);
9465 }
9466
9467 /* Dynamic */
9468 if (CHECK_FLAG(p->cap, PEER_CAP_DYNAMIC_RCV)
9469 || CHECK_FLAG(p->cap,
9470 PEER_CAP_DYNAMIC_ADV)) {
9471 if (CHECK_FLAG(p->cap,
9472 PEER_CAP_DYNAMIC_ADV)
9473 && CHECK_FLAG(p->cap,
9474 PEER_CAP_DYNAMIC_RCV))
9475 json_object_string_add(
9476 json_cap, "dynamic",
9477 "advertisedAndReceived");
9478 else if (CHECK_FLAG(
9479 p->cap,
9480 PEER_CAP_DYNAMIC_ADV))
9481 json_object_string_add(
9482 json_cap, "dynamic",
9483 "advertised");
9484 else if (CHECK_FLAG(
9485 p->cap,
9486 PEER_CAP_DYNAMIC_RCV))
9487 json_object_string_add(
9488 json_cap, "dynamic",
9489 "received");
9490 }
9491
9492 /* Extended nexthop */
9493 if (CHECK_FLAG(p->cap, PEER_CAP_ENHE_RCV)
9494 || CHECK_FLAG(p->cap, PEER_CAP_ENHE_ADV)) {
9495 json_object *json_nxt = NULL;
9496 const char *print_store;
9497
9498
9499 if (CHECK_FLAG(p->cap,
9500 PEER_CAP_ENHE_ADV)
9501 && CHECK_FLAG(p->cap,
9502 PEER_CAP_ENHE_RCV))
9503 json_object_string_add(
9504 json_cap,
9505 "extendedNexthop",
9506 "advertisedAndReceived");
9507 else if (CHECK_FLAG(p->cap,
9508 PEER_CAP_ENHE_ADV))
9509 json_object_string_add(
9510 json_cap,
9511 "extendedNexthop",
9512 "advertised");
9513 else if (CHECK_FLAG(p->cap,
9514 PEER_CAP_ENHE_RCV))
9515 json_object_string_add(
9516 json_cap,
9517 "extendedNexthop",
9518 "received");
9519
9520 if (CHECK_FLAG(p->cap,
9521 PEER_CAP_ENHE_RCV)) {
9522 json_nxt =
9523 json_object_new_object();
9524
9525 for (safi = SAFI_UNICAST;
9526 safi < SAFI_MAX; safi++) {
9527 if (CHECK_FLAG(
9528 p->af_cap
9529 [AFI_IP]
9530 [safi],
9531 PEER_CAP_ENHE_AF_RCV)) {
9532 print_store = afi_safi_print(
9533 AFI_IP,
9534 safi);
9535 json_object_string_add(
9536 json_nxt,
9537 print_store,
9538 "recieved");
9539 }
9540 }
9541 json_object_object_add(
9542 json_cap,
9543 "extendedNexthopFamililesByPeer",
9544 json_nxt);
9545 }
9546 }
9547
9548 /* Route Refresh */
9549 if (CHECK_FLAG(p->cap, PEER_CAP_REFRESH_ADV)
9550 || CHECK_FLAG(p->cap,
9551 PEER_CAP_REFRESH_NEW_RCV)
9552 || CHECK_FLAG(p->cap,
9553 PEER_CAP_REFRESH_OLD_RCV)) {
9554 if (CHECK_FLAG(p->cap,
9555 PEER_CAP_REFRESH_ADV)
9556 && (CHECK_FLAG(
9557 p->cap,
9558 PEER_CAP_REFRESH_NEW_RCV)
9559 || CHECK_FLAG(
9560 p->cap,
9561 PEER_CAP_REFRESH_OLD_RCV))) {
9562 if (CHECK_FLAG(
9563 p->cap,
9564 PEER_CAP_REFRESH_OLD_RCV)
9565 && CHECK_FLAG(
9566 p->cap,
9567 PEER_CAP_REFRESH_NEW_RCV))
9568 json_object_string_add(
9569 json_cap,
9570 "routeRefresh",
9571 "advertisedAndReceivedOldNew");
9572 else {
9573 if (CHECK_FLAG(
9574 p->cap,
9575 PEER_CAP_REFRESH_OLD_RCV))
9576 json_object_string_add(
9577 json_cap,
9578 "routeRefresh",
9579 "advertisedAndReceivedOld");
9580 else
9581 json_object_string_add(
9582 json_cap,
9583 "routeRefresh",
9584 "advertisedAndReceivedNew");
9585 }
9586 } else if (
9587 CHECK_FLAG(
9588 p->cap,
9589 PEER_CAP_REFRESH_ADV))
9590 json_object_string_add(
9591 json_cap,
9592 "routeRefresh",
9593 "advertised");
9594 else if (
9595 CHECK_FLAG(
9596 p->cap,
9597 PEER_CAP_REFRESH_NEW_RCV)
9598 || CHECK_FLAG(
9599 p->cap,
9600 PEER_CAP_REFRESH_OLD_RCV))
9601 json_object_string_add(
9602 json_cap,
9603 "routeRefresh",
9604 "received");
9605 }
9606
9607 /* Multiprotocol Extensions */
9608 json_object *json_multi = NULL;
9609 json_multi = json_object_new_object();
9610
9611 FOREACH_AFI_SAFI (afi, safi) {
9612 if (p->afc_adv[afi][safi]
9613 || p->afc_recv[afi][safi]) {
9614 json_object *json_exten = NULL;
9615 json_exten =
9616 json_object_new_object();
9617
9618 if (p->afc_adv[afi][safi]
9619 && p->afc_recv[afi][safi])
9620 json_object_boolean_true_add(
9621 json_exten,
9622 "advertisedAndReceived");
9623 else if (p->afc_adv[afi][safi])
9624 json_object_boolean_true_add(
9625 json_exten,
9626 "advertised");
9627 else if (p->afc_recv[afi][safi])
9628 json_object_boolean_true_add(
9629 json_exten,
9630 "received");
9631
9632 json_object_object_add(
9633 json_multi,
9634 afi_safi_print(afi,
9635 safi),
9636 json_exten);
9637 }
9638 }
9639 json_object_object_add(
9640 json_cap, "multiprotocolExtensions",
9641 json_multi);
9642
9643 /* Hostname capabilities */
9644 json_object *json_hname = NULL;
9645
9646 json_hname = json_object_new_object();
9647
9648 if (CHECK_FLAG(p->cap, PEER_CAP_HOSTNAME_ADV)) {
9649 json_object_string_add(
9650 json_hname, "advHostName",
9651 bgp->peer_self->hostname
9652 ? bgp->peer_self
9653 ->hostname
9654 : "n/a");
9655 json_object_string_add(
9656 json_hname, "advDomainName",
9657 bgp->peer_self->domainname
9658 ? bgp->peer_self
9659 ->domainname
9660 : "n/a");
9661 }
9662
9663
9664 if (CHECK_FLAG(p->cap, PEER_CAP_HOSTNAME_RCV)) {
9665 json_object_string_add(
9666 json_hname, "rcvHostName",
9667 p->hostname ? p->hostname
9668 : "n/a");
9669 json_object_string_add(
9670 json_hname, "rcvDomainName",
9671 p->domainname ? p->domainname
9672 : "n/a");
9673 }
9674
9675 json_object_object_add(json_cap, "hostName",
9676 json_hname);
9677
9678 /* Gracefull Restart */
9679 if (CHECK_FLAG(p->cap, PEER_CAP_RESTART_RCV)
9680 || CHECK_FLAG(p->cap,
9681 PEER_CAP_RESTART_ADV)) {
9682 if (CHECK_FLAG(p->cap,
9683 PEER_CAP_RESTART_ADV)
9684 && CHECK_FLAG(p->cap,
9685 PEER_CAP_RESTART_RCV))
9686 json_object_string_add(
9687 json_cap,
9688 "gracefulRestart",
9689 "advertisedAndReceived");
9690 else if (CHECK_FLAG(
9691 p->cap,
9692 PEER_CAP_RESTART_ADV))
9693 json_object_string_add(
9694 json_cap,
9695 "gracefulRestartCapability",
9696 "advertised");
9697 else if (CHECK_FLAG(
9698 p->cap,
9699 PEER_CAP_RESTART_RCV))
9700 json_object_string_add(
9701 json_cap,
9702 "gracefulRestartCapability",
9703 "received");
9704
9705 if (CHECK_FLAG(p->cap,
9706 PEER_CAP_RESTART_RCV)) {
9707 int restart_af_count = 0;
9708 json_object *json_restart =
9709 NULL;
9710 json_restart =
9711 json_object_new_object();
9712
9713 json_object_int_add(
9714 json_cap,
9715 "gracefulRestartRemoteTimerMsecs",
9716 p->v_gr_restart * 1000);
9717
9718 FOREACH_AFI_SAFI (afi, safi) {
9719 if (CHECK_FLAG(
9720 p->af_cap
9721 [afi]
9722 [safi],
9723 PEER_CAP_RESTART_AF_RCV)) {
9724 json_object *
9725 json_sub =
9726 NULL;
9727 json_sub =
9728 json_object_new_object();
9729
9730 if (CHECK_FLAG(
9731 p->af_cap
9732 [afi]
9733 [safi],
9734 PEER_CAP_RESTART_AF_PRESERVE_RCV))
9735 json_object_boolean_true_add(
9736 json_sub,
9737 "preserved");
9738 restart_af_count++;
9739 json_object_object_add(
9740 json_restart,
9741 afi_safi_print(
9742 afi,
9743 safi),
9744 json_sub);
9745 }
9746 }
9747 if (!restart_af_count) {
9748 json_object_string_add(
9749 json_cap,
9750 "addressFamiliesByPeer",
9751 "none");
9752 json_object_free(
9753 json_restart);
9754 } else
9755 json_object_object_add(
9756 json_cap,
9757 "addressFamiliesByPeer",
9758 json_restart);
9759 }
9760 }
9761 json_object_object_add(json_neigh,
9762 "neighborCapabilities",
9763 json_cap);
9764 } else {
9765 vty_out(vty, " Neighbor capabilities:\n");
9766
9767 /* AS4 */
9768 if (CHECK_FLAG(p->cap, PEER_CAP_AS4_RCV)
9769 || CHECK_FLAG(p->cap, PEER_CAP_AS4_ADV)) {
9770 vty_out(vty, " 4 Byte AS:");
9771 if (CHECK_FLAG(p->cap,
9772 PEER_CAP_AS4_ADV))
9773 vty_out(vty, " advertised");
9774 if (CHECK_FLAG(p->cap,
9775 PEER_CAP_AS4_RCV))
9776 vty_out(vty, " %sreceived",
9777 CHECK_FLAG(
9778 p->cap,
9779 PEER_CAP_AS4_ADV)
9780 ? "and "
9781 : "");
9782 vty_out(vty, "\n");
9783 }
9784
9785 /* AddPath */
9786 if (CHECK_FLAG(p->cap, PEER_CAP_ADDPATH_RCV)
9787 || CHECK_FLAG(p->cap,
9788 PEER_CAP_ADDPATH_ADV)) {
9789 vty_out(vty, " AddPath:\n");
9790
9791 FOREACH_AFI_SAFI (afi, safi) {
9792 if (CHECK_FLAG(
9793 p->af_cap[afi]
9794 [safi],
9795 PEER_CAP_ADDPATH_AF_TX_ADV)
9796 || CHECK_FLAG(
9797 p->af_cap[afi]
9798 [safi],
9799 PEER_CAP_ADDPATH_AF_TX_RCV)) {
9800 vty_out(vty,
9801 " %s: TX ",
9802 afi_safi_print(
9803 afi,
9804 safi));
9805
9806 if (CHECK_FLAG(
9807 p->af_cap
9808 [afi]
9809 [safi],
9810 PEER_CAP_ADDPATH_AF_TX_ADV))
9811 vty_out(vty,
9812 "advertised %s",
9813 afi_safi_print(
9814 afi,
9815 safi));
9816
9817 if (CHECK_FLAG(
9818 p->af_cap
9819 [afi]
9820 [safi],
9821 PEER_CAP_ADDPATH_AF_TX_RCV))
9822 vty_out(vty,
9823 "%sreceived",
9824 CHECK_FLAG(
9825 p->af_cap
9826 [afi]
9827 [safi],
9828 PEER_CAP_ADDPATH_AF_TX_ADV)
9829 ? " and "
9830 : "");
9831
9832 vty_out(vty, "\n");
9833 }
9834
9835 if (CHECK_FLAG(
9836 p->af_cap[afi]
9837 [safi],
9838 PEER_CAP_ADDPATH_AF_RX_ADV)
9839 || CHECK_FLAG(
9840 p->af_cap[afi]
9841 [safi],
9842 PEER_CAP_ADDPATH_AF_RX_RCV)) {
9843 vty_out(vty,
9844 " %s: RX ",
9845 afi_safi_print(
9846 afi,
9847 safi));
9848
9849 if (CHECK_FLAG(
9850 p->af_cap
9851 [afi]
9852 [safi],
9853 PEER_CAP_ADDPATH_AF_RX_ADV))
9854 vty_out(vty,
9855 "advertised %s",
9856 afi_safi_print(
9857 afi,
9858 safi));
9859
9860 if (CHECK_FLAG(
9861 p->af_cap
9862 [afi]
9863 [safi],
9864 PEER_CAP_ADDPATH_AF_RX_RCV))
9865 vty_out(vty,
9866 "%sreceived",
9867 CHECK_FLAG(
9868 p->af_cap
9869 [afi]
9870 [safi],
9871 PEER_CAP_ADDPATH_AF_RX_ADV)
9872 ? " and "
9873 : "");
9874
9875 vty_out(vty, "\n");
9876 }
9877 }
9878 }
9879
9880 /* Dynamic */
9881 if (CHECK_FLAG(p->cap, PEER_CAP_DYNAMIC_RCV)
9882 || CHECK_FLAG(p->cap,
9883 PEER_CAP_DYNAMIC_ADV)) {
9884 vty_out(vty, " Dynamic:");
9885 if (CHECK_FLAG(p->cap,
9886 PEER_CAP_DYNAMIC_ADV))
9887 vty_out(vty, " advertised");
9888 if (CHECK_FLAG(p->cap,
9889 PEER_CAP_DYNAMIC_RCV))
9890 vty_out(vty, " %sreceived",
9891 CHECK_FLAG(
9892 p->cap,
9893 PEER_CAP_DYNAMIC_ADV)
9894 ? "and "
9895 : "");
9896 vty_out(vty, "\n");
9897 }
9898
9899 /* Extended nexthop */
9900 if (CHECK_FLAG(p->cap, PEER_CAP_ENHE_RCV)
9901 || CHECK_FLAG(p->cap, PEER_CAP_ENHE_ADV)) {
9902 vty_out(vty, " Extended nexthop:");
9903 if (CHECK_FLAG(p->cap,
9904 PEER_CAP_ENHE_ADV))
9905 vty_out(vty, " advertised");
9906 if (CHECK_FLAG(p->cap,
9907 PEER_CAP_ENHE_RCV))
9908 vty_out(vty, " %sreceived",
9909 CHECK_FLAG(
9910 p->cap,
9911 PEER_CAP_ENHE_ADV)
9912 ? "and "
9913 : "");
9914 vty_out(vty, "\n");
9915
9916 if (CHECK_FLAG(p->cap,
9917 PEER_CAP_ENHE_RCV)) {
9918 vty_out(vty,
9919 " Address families by peer:\n ");
9920 for (safi = SAFI_UNICAST;
9921 safi < SAFI_MAX; safi++)
9922 if (CHECK_FLAG(
9923 p->af_cap
9924 [AFI_IP]
9925 [safi],
9926 PEER_CAP_ENHE_AF_RCV))
9927 vty_out(vty,
9928 " %s\n",
9929 afi_safi_print(
9930 AFI_IP,
9931 safi));
9932 }
9933 }
9934
9935 /* Route Refresh */
9936 if (CHECK_FLAG(p->cap, PEER_CAP_REFRESH_ADV)
9937 || CHECK_FLAG(p->cap,
9938 PEER_CAP_REFRESH_NEW_RCV)
9939 || CHECK_FLAG(p->cap,
9940 PEER_CAP_REFRESH_OLD_RCV)) {
9941 vty_out(vty, " Route refresh:");
9942 if (CHECK_FLAG(p->cap,
9943 PEER_CAP_REFRESH_ADV))
9944 vty_out(vty, " advertised");
9945 if (CHECK_FLAG(p->cap,
9946 PEER_CAP_REFRESH_NEW_RCV)
9947 || CHECK_FLAG(
9948 p->cap,
9949 PEER_CAP_REFRESH_OLD_RCV))
9950 vty_out(vty, " %sreceived(%s)",
9951 CHECK_FLAG(
9952 p->cap,
9953 PEER_CAP_REFRESH_ADV)
9954 ? "and "
9955 : "",
9956 (CHECK_FLAG(
9957 p->cap,
9958 PEER_CAP_REFRESH_OLD_RCV)
9959 && CHECK_FLAG(
9960 p->cap,
9961 PEER_CAP_REFRESH_NEW_RCV))
9962 ? "old & new"
9963 : CHECK_FLAG(
9964 p->cap,
9965 PEER_CAP_REFRESH_OLD_RCV)
9966 ? "old"
9967 : "new");
9968
9969 vty_out(vty, "\n");
9970 }
9971
9972 /* Multiprotocol Extensions */
9973 FOREACH_AFI_SAFI (afi, safi)
9974 if (p->afc_adv[afi][safi]
9975 || p->afc_recv[afi][safi]) {
9976 vty_out(vty,
9977 " Address Family %s:",
9978 afi_safi_print(afi,
9979 safi));
9980 if (p->afc_adv[afi][safi])
9981 vty_out(vty,
9982 " advertised");
9983 if (p->afc_recv[afi][safi])
9984 vty_out(vty,
9985 " %sreceived",
9986 p->afc_adv[afi]
9987 [safi]
9988 ? "and "
9989 : "");
9990 vty_out(vty, "\n");
9991 }
9992
9993 /* Hostname capability */
9994 vty_out(vty, " Hostname Capability:");
9995
9996 if (CHECK_FLAG(p->cap, PEER_CAP_HOSTNAME_ADV)) {
9997 vty_out(vty,
9998 " advertised (name: %s,domain name: %s)",
9999 bgp->peer_self->hostname
10000 ? bgp->peer_self
10001 ->hostname
10002 : "n/a",
10003 bgp->peer_self->domainname
10004 ? bgp->peer_self
10005 ->domainname
10006 : "n/a");
10007 } else {
10008 vty_out(vty, " not advertised");
10009 }
10010
10011 if (CHECK_FLAG(p->cap, PEER_CAP_HOSTNAME_RCV)) {
10012 vty_out(vty,
10013 " received (name: %s,domain name: %s)",
10014 p->hostname ? p->hostname
10015 : "n/a",
10016 p->domainname ? p->domainname
10017 : "n/a");
10018 } else {
10019 vty_out(vty, " not received");
10020 }
10021
10022 vty_out(vty, "\n");
10023
10024 /* Gracefull Restart */
10025 if (CHECK_FLAG(p->cap, PEER_CAP_RESTART_RCV)
10026 || CHECK_FLAG(p->cap,
10027 PEER_CAP_RESTART_ADV)) {
10028 vty_out(vty,
10029 " Graceful Restart Capabilty:");
10030 if (CHECK_FLAG(p->cap,
10031 PEER_CAP_RESTART_ADV))
10032 vty_out(vty, " advertised");
10033 if (CHECK_FLAG(p->cap,
10034 PEER_CAP_RESTART_RCV))
10035 vty_out(vty, " %sreceived",
10036 CHECK_FLAG(
10037 p->cap,
10038 PEER_CAP_RESTART_ADV)
10039 ? "and "
10040 : "");
10041 vty_out(vty, "\n");
10042
10043 if (CHECK_FLAG(p->cap,
10044 PEER_CAP_RESTART_RCV)) {
10045 int restart_af_count = 0;
10046
10047 vty_out(vty,
10048 " Remote Restart timer is %d seconds\n",
10049 p->v_gr_restart);
10050 vty_out(vty,
10051 " Address families by peer:\n ");
10052
10053 FOREACH_AFI_SAFI (afi, safi)
10054 if (CHECK_FLAG(
10055 p->af_cap
10056 [afi]
10057 [safi],
10058 PEER_CAP_RESTART_AF_RCV)) {
10059 vty_out(vty,
10060 "%s%s(%s)",
10061 restart_af_count
10062 ? ", "
10063 : "",
10064 afi_safi_print(
10065 afi,
10066 safi),
10067 CHECK_FLAG(
10068 p->af_cap
10069 [afi]
10070 [safi],
10071 PEER_CAP_RESTART_AF_PRESERVE_RCV)
10072 ? "preserved"
10073 : "not preserved");
10074 restart_af_count++;
10075 }
10076 if (!restart_af_count)
10077 vty_out(vty, "none");
10078 vty_out(vty, "\n");
10079 }
10080 }
10081 }
10082 }
10083 }
10084
10085 /* graceful restart information */
10086 if (CHECK_FLAG(p->cap, PEER_CAP_RESTART_RCV) || p->t_gr_restart
10087 || p->t_gr_stale) {
10088 json_object *json_grace = NULL;
10089 json_object *json_grace_send = NULL;
10090 json_object *json_grace_recv = NULL;
10091 int eor_send_af_count = 0;
10092 int eor_receive_af_count = 0;
10093
10094 if (use_json) {
10095 json_grace = json_object_new_object();
10096 json_grace_send = json_object_new_object();
10097 json_grace_recv = json_object_new_object();
10098
10099 if (p->status == Established) {
10100 FOREACH_AFI_SAFI (afi, safi) {
10101 if (CHECK_FLAG(p->af_sflags[afi][safi],
10102 PEER_STATUS_EOR_SEND)) {
10103 json_object_boolean_true_add(
10104 json_grace_send,
10105 afi_safi_print(afi,
10106 safi));
10107 eor_send_af_count++;
10108 }
10109 }
10110 FOREACH_AFI_SAFI (afi, safi) {
10111 if (CHECK_FLAG(
10112 p->af_sflags[afi][safi],
10113 PEER_STATUS_EOR_RECEIVED)) {
10114 json_object_boolean_true_add(
10115 json_grace_recv,
10116 afi_safi_print(afi,
10117 safi));
10118 eor_receive_af_count++;
10119 }
10120 }
10121 }
10122
10123 json_object_object_add(json_grace, "endOfRibSend",
10124 json_grace_send);
10125 json_object_object_add(json_grace, "endOfRibRecv",
10126 json_grace_recv);
10127
10128 if (p->t_gr_restart)
10129 json_object_int_add(json_grace,
10130 "gracefulRestartTimerMsecs",
10131 thread_timer_remain_second(
10132 p->t_gr_restart)
10133 * 1000);
10134
10135 if (p->t_gr_stale)
10136 json_object_int_add(
10137 json_grace,
10138 "gracefulStalepathTimerMsecs",
10139 thread_timer_remain_second(
10140 p->t_gr_stale)
10141 * 1000);
10142
10143 json_object_object_add(
10144 json_neigh, "gracefulRestartInfo", json_grace);
10145 } else {
10146 vty_out(vty, " Graceful restart informations:\n");
10147 if (p->status == Established) {
10148 vty_out(vty, " End-of-RIB send: ");
10149 FOREACH_AFI_SAFI (afi, safi) {
10150 if (CHECK_FLAG(p->af_sflags[afi][safi],
10151 PEER_STATUS_EOR_SEND)) {
10152 vty_out(vty, "%s%s",
10153 eor_send_af_count ? ", "
10154 : "",
10155 afi_safi_print(afi,
10156 safi));
10157 eor_send_af_count++;
10158 }
10159 }
10160 vty_out(vty, "\n");
10161 vty_out(vty, " End-of-RIB received: ");
10162 FOREACH_AFI_SAFI (afi, safi) {
10163 if (CHECK_FLAG(
10164 p->af_sflags[afi][safi],
10165 PEER_STATUS_EOR_RECEIVED)) {
10166 vty_out(vty, "%s%s",
10167 eor_receive_af_count
10168 ? ", "
10169 : "",
10170 afi_safi_print(afi,
10171 safi));
10172 eor_receive_af_count++;
10173 }
10174 }
10175 vty_out(vty, "\n");
10176 }
10177
10178 if (p->t_gr_restart)
10179 vty_out(vty,
10180 " The remaining time of restart timer is %ld\n",
10181 thread_timer_remain_second(
10182 p->t_gr_restart));
10183
10184 if (p->t_gr_stale)
10185 vty_out(vty,
10186 " The remaining time of stalepath timer is %ld\n",
10187 thread_timer_remain_second(
10188 p->t_gr_stale));
10189 }
10190 }
10191 if (use_json) {
10192 json_object *json_stat = NULL;
10193 json_stat = json_object_new_object();
10194 /* Packet counts. */
10195 json_object_int_add(json_stat, "depthInq", 0);
10196 json_object_int_add(json_stat, "depthOutq",
10197 (unsigned long)p->obuf->count);
10198 json_object_int_add(json_stat, "opensSent",
10199 atomic_load_explicit(&p->open_out,
10200 memory_order_relaxed));
10201 json_object_int_add(json_stat, "opensRecv",
10202 atomic_load_explicit(&p->open_in,
10203 memory_order_relaxed));
10204 json_object_int_add(json_stat, "notificationsSent",
10205 atomic_load_explicit(&p->notify_out,
10206 memory_order_relaxed));
10207 json_object_int_add(json_stat, "notificationsRecv",
10208 atomic_load_explicit(&p->notify_in,
10209 memory_order_relaxed));
10210 json_object_int_add(json_stat, "updatesSent",
10211 atomic_load_explicit(&p->update_out,
10212 memory_order_relaxed));
10213 json_object_int_add(json_stat, "updatesRecv",
10214 atomic_load_explicit(&p->update_in,
10215 memory_order_relaxed));
10216 json_object_int_add(json_stat, "keepalivesSent",
10217 atomic_load_explicit(&p->keepalive_out,
10218 memory_order_relaxed));
10219 json_object_int_add(json_stat, "keepalivesRecv",
10220 atomic_load_explicit(&p->keepalive_in,
10221 memory_order_relaxed));
10222 json_object_int_add(json_stat, "routeRefreshSent",
10223 atomic_load_explicit(&p->refresh_out,
10224 memory_order_relaxed));
10225 json_object_int_add(json_stat, "routeRefreshRecv",
10226 atomic_load_explicit(&p->refresh_in,
10227 memory_order_relaxed));
10228 json_object_int_add(json_stat, "capabilitySent",
10229 atomic_load_explicit(&p->dynamic_cap_out,
10230 memory_order_relaxed));
10231 json_object_int_add(json_stat, "capabilityRecv",
10232 atomic_load_explicit(&p->dynamic_cap_in,
10233 memory_order_relaxed));
10234 json_object_int_add(json_stat, "totalSent", PEER_TOTAL_TX(p));
10235 json_object_int_add(json_stat, "totalRecv", PEER_TOTAL_RX(p));
10236 json_object_object_add(json_neigh, "messageStats", json_stat);
10237 } else {
10238 /* Packet counts. */
10239 vty_out(vty, " Message statistics:\n");
10240 vty_out(vty, " Inq depth is 0\n");
10241 vty_out(vty, " Outq depth is %lu\n",
10242 (unsigned long)p->obuf->count);
10243 vty_out(vty, " Sent Rcvd\n");
10244 vty_out(vty, " Opens: %10d %10d\n",
10245 atomic_load_explicit(&p->open_out,
10246 memory_order_relaxed),
10247 atomic_load_explicit(&p->open_in,
10248 memory_order_relaxed));
10249 vty_out(vty, " Notifications: %10d %10d\n",
10250 atomic_load_explicit(&p->notify_out,
10251 memory_order_relaxed),
10252 atomic_load_explicit(&p->notify_in,
10253 memory_order_relaxed));
10254 vty_out(vty, " Updates: %10d %10d\n",
10255 atomic_load_explicit(&p->update_out,
10256 memory_order_relaxed),
10257 atomic_load_explicit(&p->update_in,
10258 memory_order_relaxed));
10259 vty_out(vty, " Keepalives: %10d %10d\n",
10260 atomic_load_explicit(&p->keepalive_out,
10261 memory_order_relaxed),
10262 atomic_load_explicit(&p->keepalive_in,
10263 memory_order_relaxed));
10264 vty_out(vty, " Route Refresh: %10d %10d\n",
10265 atomic_load_explicit(&p->refresh_out,
10266 memory_order_relaxed),
10267 atomic_load_explicit(&p->refresh_in,
10268 memory_order_relaxed));
10269 vty_out(vty, " Capability: %10d %10d\n",
10270 atomic_load_explicit(&p->dynamic_cap_out,
10271 memory_order_relaxed),
10272 atomic_load_explicit(&p->dynamic_cap_in,
10273 memory_order_relaxed));
10274 vty_out(vty, " Total: %10d %10d\n", PEER_TOTAL_TX(p),
10275 PEER_TOTAL_RX(p));
10276 }
10277
10278 if (use_json) {
10279 /* advertisement-interval */
10280 json_object_int_add(json_neigh,
10281 "minBtwnAdvertisementRunsTimerMsecs",
10282 p->v_routeadv * 1000);
10283
10284 /* Update-source. */
10285 if (p->update_if || p->update_source) {
10286 if (p->update_if)
10287 json_object_string_add(json_neigh,
10288 "updateSource",
10289 p->update_if);
10290 else if (p->update_source)
10291 json_object_string_add(
10292 json_neigh, "updateSource",
10293 sockunion2str(p->update_source, buf1,
10294 SU_ADDRSTRLEN));
10295 }
10296 } else {
10297 /* advertisement-interval */
10298 vty_out(vty,
10299 " Minimum time between advertisement runs is %d seconds\n",
10300 p->v_routeadv);
10301
10302 /* Update-source. */
10303 if (p->update_if || p->update_source) {
10304 vty_out(vty, " Update source is ");
10305 if (p->update_if)
10306 vty_out(vty, "%s", p->update_if);
10307 else if (p->update_source)
10308 vty_out(vty, "%s",
10309 sockunion2str(p->update_source, buf1,
10310 SU_ADDRSTRLEN));
10311 vty_out(vty, "\n");
10312 }
10313
10314 vty_out(vty, "\n");
10315 }
10316
10317 /* Address Family Information */
10318 json_object *json_hold = NULL;
10319
10320 if (use_json)
10321 json_hold = json_object_new_object();
10322
10323 FOREACH_AFI_SAFI (afi, safi)
10324 if (p->afc[afi][safi])
10325 bgp_show_peer_afi(vty, p, afi, safi, use_json,
10326 json_hold);
10327
10328 if (use_json) {
10329 json_object_object_add(json_neigh, "addressFamilyInfo",
10330 json_hold);
10331 json_object_int_add(json_neigh, "connectionsEstablished",
10332 p->established);
10333 json_object_int_add(json_neigh, "connectionsDropped",
10334 p->dropped);
10335 } else
10336 vty_out(vty, " Connections established %d; dropped %d\n",
10337 p->established, p->dropped);
10338
10339 if (!p->last_reset) {
10340 if (use_json)
10341 json_object_string_add(json_neigh, "lastReset",
10342 "never");
10343 else
10344 vty_out(vty, " Last reset never\n");
10345 } else {
10346 if (use_json) {
10347 time_t uptime;
10348 struct tm *tm;
10349
10350 uptime = bgp_clock();
10351 uptime -= p->resettime;
10352 tm = gmtime(&uptime);
10353 json_object_int_add(json_neigh, "lastResetTimerMsecs",
10354 (tm->tm_sec * 1000)
10355 + (tm->tm_min * 60000)
10356 + (tm->tm_hour * 3600000));
10357 json_object_string_add(
10358 json_neigh, "lastResetDueTo",
10359 peer_down_str[(int)p->last_reset]);
10360 if (p->last_reset == PEER_DOWN_NOTIFY_SEND
10361 || p->last_reset == PEER_DOWN_NOTIFY_RECEIVED) {
10362 char errorcodesubcode_hexstr[5];
10363 char errorcodesubcode_str[256];
10364
10365 code_str = bgp_notify_code_str(p->notify.code);
10366 subcode_str = bgp_notify_subcode_str(
10367 p->notify.code, p->notify.subcode);
10368
10369 sprintf(errorcodesubcode_hexstr, "%02X%02X",
10370 p->notify.code, p->notify.subcode);
10371 json_object_string_add(json_neigh,
10372 "lastErrorCodeSubcode",
10373 errorcodesubcode_hexstr);
10374 snprintf(errorcodesubcode_str, 255, "%s%s",
10375 code_str, subcode_str);
10376 json_object_string_add(json_neigh,
10377 "lastNotificationReason",
10378 errorcodesubcode_str);
10379 if (p->last_reset == PEER_DOWN_NOTIFY_RECEIVED
10380 && p->notify.code == BGP_NOTIFY_CEASE
10381 && (p->notify.subcode
10382 == BGP_NOTIFY_CEASE_ADMIN_SHUTDOWN
10383 || p->notify.subcode
10384 == BGP_NOTIFY_CEASE_ADMIN_RESET)
10385 && p->notify.length) {
10386 char msgbuf[1024];
10387 const char *msg_str;
10388
10389 msg_str = bgp_notify_admin_message(
10390 msgbuf, sizeof(msgbuf),
10391 (uint8_t *)p->notify.data,
10392 p->notify.length);
10393 if (msg_str)
10394 json_object_string_add(
10395 json_neigh,
10396 "lastShutdownDescription",
10397 msg_str);
10398 }
10399 }
10400 } else {
10401 vty_out(vty, " Last reset %s, ",
10402 peer_uptime(p->resettime, timebuf,
10403 BGP_UPTIME_LEN, 0, NULL));
10404
10405 if (p->last_reset == PEER_DOWN_NOTIFY_SEND
10406 || p->last_reset == PEER_DOWN_NOTIFY_RECEIVED) {
10407 code_str = bgp_notify_code_str(p->notify.code);
10408 subcode_str = bgp_notify_subcode_str(
10409 p->notify.code, p->notify.subcode);
10410 vty_out(vty, "due to NOTIFICATION %s (%s%s)\n",
10411 p->last_reset == PEER_DOWN_NOTIFY_SEND
10412 ? "sent"
10413 : "received",
10414 code_str, subcode_str);
10415 if (p->last_reset == PEER_DOWN_NOTIFY_RECEIVED
10416 && p->notify.code == BGP_NOTIFY_CEASE
10417 && (p->notify.subcode
10418 == BGP_NOTIFY_CEASE_ADMIN_SHUTDOWN
10419 || p->notify.subcode
10420 == BGP_NOTIFY_CEASE_ADMIN_RESET)
10421 && p->notify.length) {
10422 char msgbuf[1024];
10423 const char *msg_str;
10424
10425 msg_str = bgp_notify_admin_message(
10426 msgbuf, sizeof(msgbuf),
10427 (uint8_t *)p->notify.data,
10428 p->notify.length);
10429 if (msg_str)
10430 vty_out(vty,
10431 " Message: \"%s\"\n",
10432 msg_str);
10433 }
10434 } else {
10435 vty_out(vty, "due to %s\n",
10436 peer_down_str[(int)p->last_reset]);
10437 }
10438
10439 if (p->last_reset_cause_size) {
10440 msg = p->last_reset_cause;
10441 vty_out(vty,
10442 " Message received that caused BGP to send a NOTIFICATION:\n ");
10443 for (i = 1; i <= p->last_reset_cause_size;
10444 i++) {
10445 vty_out(vty, "%02X", *msg++);
10446
10447 if (i != p->last_reset_cause_size) {
10448 if (i % 16 == 0) {
10449 vty_out(vty, "\n ");
10450 } else if (i % 4 == 0) {
10451 vty_out(vty, " ");
10452 }
10453 }
10454 }
10455 vty_out(vty, "\n");
10456 }
10457 }
10458 }
10459
10460 if (CHECK_FLAG(p->sflags, PEER_STATUS_PREFIX_OVERFLOW)) {
10461 if (use_json)
10462 json_object_boolean_true_add(json_neigh,
10463 "prefixesConfigExceedMax");
10464 else
10465 vty_out(vty,
10466 " Peer had exceeded the max. no. of prefixes configured.\n");
10467
10468 if (p->t_pmax_restart) {
10469 if (use_json) {
10470 json_object_boolean_true_add(
10471 json_neigh, "reducePrefixNumFrom");
10472 json_object_int_add(json_neigh,
10473 "restartInTimerMsec",
10474 thread_timer_remain_second(
10475 p->t_pmax_restart)
10476 * 1000);
10477 } else
10478 vty_out(vty,
10479 " Reduce the no. of prefix from %s, will restart in %ld seconds\n",
10480 p->host, thread_timer_remain_second(
10481 p->t_pmax_restart));
10482 } else {
10483 if (use_json)
10484 json_object_boolean_true_add(
10485 json_neigh,
10486 "reducePrefixNumAndClearIpBgp");
10487 else
10488 vty_out(vty,
10489 " Reduce the no. of prefix and clear ip bgp %s to restore peering\n",
10490 p->host);
10491 }
10492 }
10493
10494 /* EBGP Multihop and GTSM */
10495 if (p->sort != BGP_PEER_IBGP) {
10496 if (use_json) {
10497 if (p->gtsm_hops > 0)
10498 json_object_int_add(json_neigh,
10499 "externalBgpNbrMaxHopsAway",
10500 p->gtsm_hops);
10501 else if (p->ttl > 1)
10502 json_object_int_add(json_neigh,
10503 "externalBgpNbrMaxHopsAway",
10504 p->ttl);
10505 } else {
10506 if (p->gtsm_hops > 0)
10507 vty_out(vty,
10508 " External BGP neighbor may be up to %d hops away.\n",
10509 p->gtsm_hops);
10510 else if (p->ttl > 1)
10511 vty_out(vty,
10512 " External BGP neighbor may be up to %d hops away.\n",
10513 p->ttl);
10514 }
10515 } else {
10516 if (p->gtsm_hops > 0) {
10517 if (use_json)
10518 json_object_int_add(json_neigh,
10519 "internalBgpNbrMaxHopsAway",
10520 p->gtsm_hops);
10521 else
10522 vty_out(vty,
10523 " Internal BGP neighbor may be up to %d hops away.\n",
10524 p->gtsm_hops);
10525 }
10526 }
10527
10528 /* Local address. */
10529 if (p->su_local) {
10530 if (use_json) {
10531 json_object_string_add(json_neigh, "hostLocal",
10532 sockunion2str(p->su_local, buf1,
10533 SU_ADDRSTRLEN));
10534 json_object_int_add(json_neigh, "portLocal",
10535 ntohs(p->su_local->sin.sin_port));
10536 } else
10537 vty_out(vty, "Local host: %s, Local port: %d\n",
10538 sockunion2str(p->su_local, buf1, SU_ADDRSTRLEN),
10539 ntohs(p->su_local->sin.sin_port));
10540 }
10541
10542 /* Remote address. */
10543 if (p->su_remote) {
10544 if (use_json) {
10545 json_object_string_add(json_neigh, "hostForeign",
10546 sockunion2str(p->su_remote, buf1,
10547 SU_ADDRSTRLEN));
10548 json_object_int_add(json_neigh, "portForeign",
10549 ntohs(p->su_remote->sin.sin_port));
10550 } else
10551 vty_out(vty, "Foreign host: %s, Foreign port: %d\n",
10552 sockunion2str(p->su_remote, buf1,
10553 SU_ADDRSTRLEN),
10554 ntohs(p->su_remote->sin.sin_port));
10555 }
10556
10557 /* Nexthop display. */
10558 if (p->su_local) {
10559 if (use_json) {
10560 json_object_string_add(json_neigh, "nexthop",
10561 inet_ntop(AF_INET,
10562 &p->nexthop.v4, buf1,
10563 sizeof(buf1)));
10564 json_object_string_add(json_neigh, "nexthopGlobal",
10565 inet_ntop(AF_INET6,
10566 &p->nexthop.v6_global,
10567 buf1, sizeof(buf1)));
10568 json_object_string_add(json_neigh, "nexthopLocal",
10569 inet_ntop(AF_INET6,
10570 &p->nexthop.v6_local,
10571 buf1, sizeof(buf1)));
10572 if (p->shared_network)
10573 json_object_string_add(json_neigh,
10574 "bgpConnection",
10575 "sharedNetwork");
10576 else
10577 json_object_string_add(json_neigh,
10578 "bgpConnection",
10579 "nonSharedNetwork");
10580 } else {
10581 vty_out(vty, "Nexthop: %s\n",
10582 inet_ntop(AF_INET, &p->nexthop.v4, buf1,
10583 sizeof(buf1)));
10584 vty_out(vty, "Nexthop global: %s\n",
10585 inet_ntop(AF_INET6, &p->nexthop.v6_global, buf1,
10586 sizeof(buf1)));
10587 vty_out(vty, "Nexthop local: %s\n",
10588 inet_ntop(AF_INET6, &p->nexthop.v6_local, buf1,
10589 sizeof(buf1)));
10590 vty_out(vty, "BGP connection: %s\n",
10591 p->shared_network ? "shared network"
10592 : "non shared network");
10593 }
10594 }
10595
10596 /* Timer information. */
10597 if (use_json) {
10598 json_object_int_add(json_neigh, "connectRetryTimer",
10599 p->v_connect);
10600 if (p->status == Established && p->rtt)
10601 json_object_int_add(json_neigh, "estimatedRttInMsecs",
10602 p->rtt);
10603 if (p->t_start)
10604 json_object_int_add(
10605 json_neigh, "nextStartTimerDueInMsecs",
10606 thread_timer_remain_second(p->t_start) * 1000);
10607 if (p->t_connect)
10608 json_object_int_add(
10609 json_neigh, "nextConnectTimerDueInMsecs",
10610 thread_timer_remain_second(p->t_connect)
10611 * 1000);
10612 if (p->t_routeadv) {
10613 json_object_int_add(json_neigh, "mraiInterval",
10614 p->v_routeadv);
10615 json_object_int_add(
10616 json_neigh, "mraiTimerExpireInMsecs",
10617 thread_timer_remain_second(p->t_routeadv)
10618 * 1000);
10619 }
10620 if (p->password)
10621 json_object_int_add(json_neigh, "authenticationEnabled",
10622 1);
10623
10624 if (p->t_read)
10625 json_object_string_add(json_neigh, "readThread", "on");
10626 else
10627 json_object_string_add(json_neigh, "readThread", "off");
10628
10629 if (CHECK_FLAG(p->thread_flags, PEER_THREAD_WRITES_ON))
10630 json_object_string_add(json_neigh, "writeThread", "on");
10631 else
10632 json_object_string_add(json_neigh, "writeThread",
10633 "off");
10634 } else {
10635 vty_out(vty, "BGP Connect Retry Timer in Seconds: %d\n",
10636 p->v_connect);
10637 if (p->status == Established && p->rtt)
10638 vty_out(vty, "Estimated round trip time: %d ms\n",
10639 p->rtt);
10640 if (p->t_start)
10641 vty_out(vty, "Next start timer due in %ld seconds\n",
10642 thread_timer_remain_second(p->t_start));
10643 if (p->t_connect)
10644 vty_out(vty, "Next connect timer due in %ld seconds\n",
10645 thread_timer_remain_second(p->t_connect));
10646 if (p->t_routeadv)
10647 vty_out(vty,
10648 "MRAI (interval %u) timer expires in %ld seconds\n",
10649 p->v_routeadv,
10650 thread_timer_remain_second(p->t_routeadv));
10651 if (p->password)
10652 vty_out(vty, "Peer Authentication Enabled\n");
10653
10654 vty_out(vty, "Read thread: %s Write thread: %s\n",
10655 p->t_read ? "on" : "off",
10656 CHECK_FLAG(p->thread_flags, PEER_THREAD_WRITES_ON)
10657 ? "on"
10658 : "off");
10659 }
10660
10661 if (p->notify.code == BGP_NOTIFY_OPEN_ERR
10662 && p->notify.subcode == BGP_NOTIFY_OPEN_UNSUP_CAPBL)
10663 bgp_capability_vty_out(vty, p, use_json, json_neigh);
10664
10665 if (!use_json)
10666 vty_out(vty, "\n");
10667
10668 /* BFD information. */
10669 bgp_bfd_show_info(vty, p, use_json, json_neigh);
10670
10671 if (use_json) {
10672 if (p->conf_if) /* Configured interface name. */
10673 json_object_object_add(json, p->conf_if, json_neigh);
10674 else /* Configured IP address. */
10675 json_object_object_add(json, p->host, json_neigh);
10676 }
10677 }
10678
10679 static int bgp_show_neighbor(struct vty *vty, struct bgp *bgp,
10680 enum show_type type, union sockunion *su,
10681 const char *conf_if, uint8_t use_json,
10682 json_object *json)
10683 {
10684 struct listnode *node, *nnode;
10685 struct peer *peer;
10686 int find = 0;
10687
10688 for (ALL_LIST_ELEMENTS(bgp->peer, node, nnode, peer)) {
10689 if (!CHECK_FLAG(peer->flags, PEER_FLAG_CONFIG_NODE))
10690 continue;
10691
10692 switch (type) {
10693 case show_all:
10694 bgp_show_peer(vty, peer, use_json, json);
10695 break;
10696 case show_peer:
10697 if (conf_if) {
10698 if ((peer->conf_if
10699 && !strcmp(peer->conf_if, conf_if))
10700 || (peer->hostname
10701 && !strcmp(peer->hostname, conf_if))) {
10702 find = 1;
10703 bgp_show_peer(vty, peer, use_json,
10704 json);
10705 }
10706 } else {
10707 if (sockunion_same(&peer->su, su)) {
10708 find = 1;
10709 bgp_show_peer(vty, peer, use_json,
10710 json);
10711 }
10712 }
10713 break;
10714 }
10715 }
10716
10717 if (type == show_peer && !find) {
10718 if (use_json)
10719 json_object_boolean_true_add(json, "bgpNoSuchNeighbor");
10720 else
10721 vty_out(vty, "%% No such neighbor in this view/vrf\n");
10722 }
10723
10724 if (use_json) {
10725 vty_out(vty, "%s\n", json_object_to_json_string_ext(
10726 json, JSON_C_TO_STRING_PRETTY));
10727 json_object_free(json);
10728 } else {
10729 vty_out(vty, "\n");
10730 }
10731
10732 return CMD_SUCCESS;
10733 }
10734
10735 static void bgp_show_all_instances_neighbors_vty(struct vty *vty,
10736 enum show_type type,
10737 const char *ip_str,
10738 uint8_t use_json)
10739 {
10740 struct listnode *node, *nnode;
10741 struct bgp *bgp;
10742 union sockunion su;
10743 json_object *json = NULL;
10744 int ret, is_first = 1;
10745
10746 if (use_json)
10747 vty_out(vty, "{\n");
10748
10749 for (ALL_LIST_ELEMENTS(bm->bgp, node, nnode, bgp)) {
10750 if (use_json) {
10751 if (!(json = json_object_new_object())) {
10752 zlog_err(
10753 "Unable to allocate memory for JSON object");
10754 vty_out(vty,
10755 "{\"error\": {\"message:\": \"Unable to allocate memory for JSON object\"}}}\n");
10756 return;
10757 }
10758
10759 json_object_int_add(json, "vrfId",
10760 (bgp->vrf_id == VRF_UNKNOWN)
10761 ? -1
10762 : (int64_t)bgp->vrf_id);
10763 json_object_string_add(
10764 json, "vrfName",
10765 (bgp->inst_type == BGP_INSTANCE_TYPE_DEFAULT)
10766 ? "Default"
10767 : bgp->name);
10768
10769 if (!is_first)
10770 vty_out(vty, ",\n");
10771 else
10772 is_first = 0;
10773
10774 vty_out(vty, "\"%s\":",
10775 (bgp->inst_type == BGP_INSTANCE_TYPE_DEFAULT)
10776 ? "Default"
10777 : bgp->name);
10778 } else {
10779 vty_out(vty, "\nInstance %s:\n",
10780 (bgp->inst_type == BGP_INSTANCE_TYPE_DEFAULT)
10781 ? "Default"
10782 : bgp->name);
10783 }
10784
10785 if (type == show_peer) {
10786 ret = str2sockunion(ip_str, &su);
10787 if (ret < 0)
10788 bgp_show_neighbor(vty, bgp, type, NULL, ip_str,
10789 use_json, json);
10790 else
10791 bgp_show_neighbor(vty, bgp, type, &su, NULL,
10792 use_json, json);
10793 } else {
10794 bgp_show_neighbor(vty, bgp, show_all, NULL, NULL,
10795 use_json, json);
10796 }
10797 }
10798
10799 if (use_json)
10800 vty_out(vty, "}\n");
10801 }
10802
10803 static int bgp_show_neighbor_vty(struct vty *vty, const char *name,
10804 enum show_type type, const char *ip_str,
10805 uint8_t use_json)
10806 {
10807 int ret;
10808 struct bgp *bgp;
10809 union sockunion su;
10810 json_object *json = NULL;
10811
10812 if (name) {
10813 if (strmatch(name, "all")) {
10814 bgp_show_all_instances_neighbors_vty(vty, type, ip_str,
10815 use_json);
10816 return CMD_SUCCESS;
10817 } else {
10818 bgp = bgp_lookup_by_name(name);
10819 if (!bgp) {
10820 if (use_json) {
10821 json = json_object_new_object();
10822 json_object_boolean_true_add(
10823 json, "bgpNoSuchInstance");
10824 vty_out(vty, "%s\n",
10825 json_object_to_json_string_ext(
10826 json,
10827 JSON_C_TO_STRING_PRETTY));
10828 json_object_free(json);
10829 } else
10830 vty_out(vty,
10831 "%% No such BGP instance exist\n");
10832
10833 return CMD_WARNING;
10834 }
10835 }
10836 } else {
10837 bgp = bgp_get_default();
10838 }
10839
10840 if (bgp) {
10841 json = json_object_new_object();
10842 if (ip_str) {
10843 ret = str2sockunion(ip_str, &su);
10844 if (ret < 0)
10845 bgp_show_neighbor(vty, bgp, type, NULL, ip_str,
10846 use_json, json);
10847 else
10848 bgp_show_neighbor(vty, bgp, type, &su, NULL,
10849 use_json, json);
10850 } else {
10851 bgp_show_neighbor(vty, bgp, type, NULL, NULL, use_json,
10852 json);
10853 }
10854 json_object_free(json);
10855 }
10856
10857 return CMD_SUCCESS;
10858 }
10859
10860 /* "show [ip] bgp neighbors" commands. */
10861 DEFUN (show_ip_bgp_neighbors,
10862 show_ip_bgp_neighbors_cmd,
10863 "show [ip] bgp [<view|vrf> VIEWVRFNAME] [<ipv4|ipv6>] neighbors [<A.B.C.D|X:X::X:X|WORD>] [json]",
10864 SHOW_STR
10865 IP_STR
10866 BGP_STR
10867 BGP_INSTANCE_HELP_STR
10868 "Address Family\n"
10869 "Address Family\n"
10870 "Detailed information on TCP and BGP neighbor connections\n"
10871 "Neighbor to display information about\n"
10872 "Neighbor to display information about\n"
10873 "Neighbor on BGP configured interface\n"
10874 JSON_STR)
10875 {
10876 char *vrf = NULL;
10877 char *sh_arg = NULL;
10878 enum show_type sh_type;
10879
10880 uint8_t uj = use_json(argc, argv);
10881
10882 int idx = 0;
10883
10884 if (argv_find(argv, argc, "view", &idx)
10885 || argv_find(argv, argc, "vrf", &idx))
10886 vrf = argv[idx + 1]->arg;
10887
10888 idx++;
10889 if (argv_find(argv, argc, "A.B.C.D", &idx)
10890 || argv_find(argv, argc, "X:X::X:X", &idx)
10891 || argv_find(argv, argc, "WORD", &idx)) {
10892 sh_type = show_peer;
10893 sh_arg = argv[idx]->arg;
10894 } else
10895 sh_type = show_all;
10896
10897 return bgp_show_neighbor_vty(vty, vrf, sh_type, sh_arg, uj);
10898 }
10899
10900 /* Show BGP's AS paths internal data. There are both `show [ip] bgp
10901 paths' and `show ip mbgp paths'. Those functions results are the
10902 same.*/
10903 DEFUN (show_ip_bgp_paths,
10904 show_ip_bgp_paths_cmd,
10905 "show [ip] bgp ["BGP_SAFI_CMD_STR"] paths",
10906 SHOW_STR
10907 IP_STR
10908 BGP_STR
10909 BGP_SAFI_HELP_STR
10910 "Path information\n")
10911 {
10912 vty_out(vty, "Address Refcnt Path\n");
10913 aspath_print_all_vty(vty);
10914 return CMD_SUCCESS;
10915 }
10916
10917 #include "hash.h"
10918
10919 static void community_show_all_iterator(struct hash_backet *backet,
10920 struct vty *vty)
10921 {
10922 struct community *com;
10923
10924 com = (struct community *)backet->data;
10925 vty_out(vty, "[%p] (%ld) %s\n", (void *)com, com->refcnt,
10926 community_str(com, false));
10927 }
10928
10929 /* Show BGP's community internal data. */
10930 DEFUN (show_ip_bgp_community_info,
10931 show_ip_bgp_community_info_cmd,
10932 "show [ip] bgp community-info",
10933 SHOW_STR
10934 IP_STR
10935 BGP_STR
10936 "List all bgp community information\n")
10937 {
10938 vty_out(vty, "Address Refcnt Community\n");
10939
10940 hash_iterate(community_hash(),
10941 (void (*)(struct hash_backet *,
10942 void *))community_show_all_iterator,
10943 vty);
10944
10945 return CMD_SUCCESS;
10946 }
10947
10948 static void lcommunity_show_all_iterator(struct hash_backet *backet,
10949 struct vty *vty)
10950 {
10951 struct lcommunity *lcom;
10952
10953 lcom = (struct lcommunity *)backet->data;
10954 vty_out(vty, "[%p] (%ld) %s\n", (void *)lcom, lcom->refcnt,
10955 lcommunity_str(lcom, false));
10956 }
10957
10958 /* Show BGP's community internal data. */
10959 DEFUN (show_ip_bgp_lcommunity_info,
10960 show_ip_bgp_lcommunity_info_cmd,
10961 "show ip bgp large-community-info",
10962 SHOW_STR
10963 IP_STR
10964 BGP_STR
10965 "List all bgp large-community information\n")
10966 {
10967 vty_out(vty, "Address Refcnt Large-community\n");
10968
10969 hash_iterate(lcommunity_hash(),
10970 (void (*)(struct hash_backet *,
10971 void *))lcommunity_show_all_iterator,
10972 vty);
10973
10974 return CMD_SUCCESS;
10975 }
10976
10977
10978 DEFUN (show_ip_bgp_attr_info,
10979 show_ip_bgp_attr_info_cmd,
10980 "show [ip] bgp attribute-info",
10981 SHOW_STR
10982 IP_STR
10983 BGP_STR
10984 "List all bgp attribute information\n")
10985 {
10986 attr_show_all(vty);
10987 return CMD_SUCCESS;
10988 }
10989
10990 static int bgp_show_route_leak_vty(struct vty *vty, const char *name,
10991 afi_t afi, safi_t safi)
10992 {
10993 struct bgp *bgp;
10994 struct listnode *node;
10995 char *vname;
10996 char buf1[INET6_ADDRSTRLEN];
10997 char *ecom_str;
10998 vpn_policy_direction_t dir;
10999
11000 if (name) {
11001 bgp = bgp_lookup_by_name(name);
11002 if (!bgp) {
11003 vty_out(vty, "%% No such BGP instance exist\n");
11004 return CMD_WARNING;
11005 }
11006 } else {
11007 bgp = bgp_get_default();
11008 if (!bgp) {
11009 vty_out(vty,
11010 "%% Default BGP instance does not exist\n");
11011 return CMD_WARNING;
11012 }
11013 }
11014
11015 if (!CHECK_FLAG(bgp->af_flags[afi][safi],
11016 BGP_CONFIG_VRF_TO_VRF_IMPORT)) {
11017 vty_out(vty,
11018 "This VRF is not importing %s routes from any other VRF\n",
11019 afi_safi_print(afi, safi));
11020 } else {
11021 vty_out(vty,
11022 "This VRF is importing %s routes from the following VRFs:\n",
11023 afi_safi_print(afi, safi));
11024 for (ALL_LIST_ELEMENTS_RO(bgp->vpn_policy[afi].import_vrf, node,
11025 vname)) {
11026 vty_out(vty, " %s\n", vname);
11027 }
11028 dir = BGP_VPN_POLICY_DIR_FROMVPN;
11029 ecom_str = ecommunity_ecom2str(
11030 bgp->vpn_policy[afi].rtlist[dir],
11031 ECOMMUNITY_FORMAT_ROUTE_MAP, 0);
11032 vty_out(vty, "Import RT(s): %s\n", ecom_str);
11033 XFREE(MTYPE_ECOMMUNITY_STR, ecom_str);
11034 }
11035
11036 if (!CHECK_FLAG(bgp->af_flags[afi][safi],
11037 BGP_CONFIG_VRF_TO_VRF_EXPORT)) {
11038 vty_out(vty,
11039 "This VRF is not exporting %s routes to any other VRF\n",
11040 afi_safi_print(afi, safi));
11041 } else {
11042 vty_out(vty,
11043 "This VRF is exporting %s routes to the following VRFs:\n",
11044 afi_safi_print(afi, safi));
11045 for (ALL_LIST_ELEMENTS_RO(bgp->vpn_policy[afi].export_vrf, node,
11046 vname)) {
11047 vty_out(vty, " %s\n", vname);
11048 }
11049 vty_out(vty, "RD: %s\n",
11050 prefix_rd2str(&bgp->vpn_policy[afi].tovpn_rd,
11051 buf1, RD_ADDRSTRLEN));
11052 dir = BGP_VPN_POLICY_DIR_TOVPN;
11053 ecom_str = ecommunity_ecom2str(
11054 bgp->vpn_policy[afi].rtlist[dir],
11055 ECOMMUNITY_FORMAT_ROUTE_MAP, 0);
11056 vty_out(vty, "Emport RT: %s\n", ecom_str);
11057 XFREE(MTYPE_ECOMMUNITY_STR, ecom_str);
11058 }
11059
11060 return CMD_SUCCESS;
11061 }
11062
11063 /* "show [ip] bgp route-leak" command. */
11064 DEFUN (show_ip_bgp_route_leak,
11065 show_ip_bgp_route_leak_cmd,
11066 "show [ip] bgp [<view|vrf> VIEWVRFNAME] ["BGP_AFI_CMD_STR" ["BGP_SAFI_CMD_STR"]] route-leak",
11067 SHOW_STR
11068 IP_STR
11069 BGP_STR
11070 BGP_INSTANCE_HELP_STR
11071 BGP_AFI_HELP_STR
11072 BGP_SAFI_HELP_STR
11073 "Route leaking information\n")
11074 {
11075 char *vrf = NULL;
11076 afi_t afi = AFI_MAX;
11077 safi_t safi = SAFI_MAX;
11078
11079 int idx = 0;
11080
11081 /* show [ip] bgp */
11082 if (argv_find(argv, argc, "ip", &idx)) {
11083 afi = AFI_IP;
11084 safi = SAFI_UNICAST;
11085 }
11086 /* [vrf VIEWVRFNAME] */
11087 if (argv_find(argv, argc, "view", &idx)) {
11088 vty_out(vty,
11089 "%% This command is not applicable to BGP views\n");
11090 return CMD_WARNING;
11091 }
11092
11093 if (argv_find(argv, argc, "vrf", &idx))
11094 vrf = argv[++idx]->arg;
11095 /* ["BGP_AFI_CMD_STR" ["BGP_SAFI_CMD_STR"]] */
11096 if (argv_find_and_parse_afi(argv, argc, &idx, &afi)) {
11097 argv_find_and_parse_safi(argv, argc, &idx, &safi);
11098 }
11099
11100 if (!((afi == AFI_IP || afi == AFI_IP6) && safi == SAFI_UNICAST)) {
11101 vty_out(vty,
11102 "%% This command is applicable only for unicast ipv4|ipv6\n");
11103 return CMD_WARNING;
11104 }
11105
11106 return bgp_show_route_leak_vty(vty, vrf, afi, safi);
11107 }
11108
11109 static void bgp_show_all_instances_updgrps_vty(struct vty *vty, afi_t afi,
11110 safi_t safi)
11111 {
11112 struct listnode *node, *nnode;
11113 struct bgp *bgp;
11114
11115 for (ALL_LIST_ELEMENTS(bm->bgp, node, nnode, bgp)) {
11116 vty_out(vty, "\nInstance %s:\n",
11117 (bgp->inst_type == BGP_INSTANCE_TYPE_DEFAULT)
11118 ? "Default"
11119 : bgp->name);
11120 update_group_show(bgp, afi, safi, vty, 0);
11121 }
11122 }
11123
11124 static int bgp_show_update_groups(struct vty *vty, const char *name, int afi,
11125 int safi, uint64_t subgrp_id)
11126 {
11127 struct bgp *bgp;
11128
11129 if (name) {
11130 if (strmatch(name, "all")) {
11131 bgp_show_all_instances_updgrps_vty(vty, afi, safi);
11132 return CMD_SUCCESS;
11133 } else {
11134 bgp = bgp_lookup_by_name(name);
11135 }
11136 } else {
11137 bgp = bgp_get_default();
11138 }
11139
11140 if (bgp)
11141 update_group_show(bgp, afi, safi, vty, subgrp_id);
11142 return CMD_SUCCESS;
11143 }
11144
11145 DEFUN (show_ip_bgp_updgrps,
11146 show_ip_bgp_updgrps_cmd,
11147 "show [ip] bgp [<view|vrf> VIEWVRFNAME] ["BGP_AFI_CMD_STR" ["BGP_SAFI_WITH_LABEL_CMD_STR"]] update-groups [SUBGROUP-ID]",
11148 SHOW_STR
11149 IP_STR
11150 BGP_STR
11151 BGP_INSTANCE_HELP_STR
11152 BGP_AFI_HELP_STR
11153 BGP_SAFI_WITH_LABEL_HELP_STR
11154 "Detailed info about dynamic update groups\n"
11155 "Specific subgroup to display detailed info for\n")
11156 {
11157 char *vrf = NULL;
11158 afi_t afi = AFI_IP6;
11159 safi_t safi = SAFI_UNICAST;
11160 uint64_t subgrp_id = 0;
11161
11162 int idx = 0;
11163
11164 /* show [ip] bgp */
11165 if (argv_find(argv, argc, "ip", &idx))
11166 afi = AFI_IP;
11167 /* [<view|vrf> VIEWVRFNAME] */
11168 if (argv_find(argv, argc, "view", &idx)
11169 || argv_find(argv, argc, "vrf", &idx))
11170 vrf = argv[++idx]->arg;
11171 /* ["BGP_AFI_CMD_STR" ["BGP_SAFI_CMD_STR"]] */
11172 if (argv_find_and_parse_afi(argv, argc, &idx, &afi)) {
11173 argv_find_and_parse_safi(argv, argc, &idx, &safi);
11174 }
11175
11176 /* get subgroup id, if provided */
11177 idx = argc - 1;
11178 if (argv[idx]->type == VARIABLE_TKN)
11179 subgrp_id = strtoull(argv[idx]->arg, NULL, 10);
11180
11181 return (bgp_show_update_groups(vty, vrf, afi, safi, subgrp_id));
11182 }
11183
11184 DEFUN (show_bgp_instance_all_ipv6_updgrps,
11185 show_bgp_instance_all_ipv6_updgrps_cmd,
11186 "show [ip] bgp <view|vrf> all update-groups",
11187 SHOW_STR
11188 IP_STR
11189 BGP_STR
11190 BGP_INSTANCE_ALL_HELP_STR
11191 "Detailed info about dynamic update groups\n")
11192 {
11193 bgp_show_all_instances_updgrps_vty(vty, AFI_IP6, SAFI_UNICAST);
11194 return CMD_SUCCESS;
11195 }
11196
11197 DEFUN (show_bgp_updgrps_stats,
11198 show_bgp_updgrps_stats_cmd,
11199 "show [ip] bgp update-groups statistics",
11200 SHOW_STR
11201 IP_STR
11202 BGP_STR
11203 "Detailed info about dynamic update groups\n"
11204 "Statistics\n")
11205 {
11206 struct bgp *bgp;
11207
11208 bgp = bgp_get_default();
11209 if (bgp)
11210 update_group_show_stats(bgp, vty);
11211
11212 return CMD_SUCCESS;
11213 }
11214
11215 DEFUN (show_bgp_instance_updgrps_stats,
11216 show_bgp_instance_updgrps_stats_cmd,
11217 "show [ip] bgp <view|vrf> VIEWVRFNAME update-groups statistics",
11218 SHOW_STR
11219 IP_STR
11220 BGP_STR
11221 BGP_INSTANCE_HELP_STR
11222 "Detailed info about dynamic update groups\n"
11223 "Statistics\n")
11224 {
11225 int idx_word = 3;
11226 struct bgp *bgp;
11227
11228 bgp = bgp_lookup_by_name(argv[idx_word]->arg);
11229 if (bgp)
11230 update_group_show_stats(bgp, vty);
11231
11232 return CMD_SUCCESS;
11233 }
11234
11235 static void show_bgp_updgrps_adj_info_aux(struct vty *vty, const char *name,
11236 afi_t afi, safi_t safi,
11237 const char *what, uint64_t subgrp_id)
11238 {
11239 struct bgp *bgp;
11240
11241 if (name)
11242 bgp = bgp_lookup_by_name(name);
11243 else
11244 bgp = bgp_get_default();
11245
11246 if (bgp) {
11247 if (!strcmp(what, "advertise-queue"))
11248 update_group_show_adj_queue(bgp, afi, safi, vty,
11249 subgrp_id);
11250 else if (!strcmp(what, "advertised-routes"))
11251 update_group_show_advertised(bgp, afi, safi, vty,
11252 subgrp_id);
11253 else if (!strcmp(what, "packet-queue"))
11254 update_group_show_packet_queue(bgp, afi, safi, vty,
11255 subgrp_id);
11256 }
11257 }
11258
11259 DEFPY(show_ip_bgp_instance_updgrps_adj_s,
11260 show_ip_bgp_instance_updgrps_adj_s_cmd,
11261 "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",
11262 SHOW_STR IP_STR BGP_STR BGP_INSTANCE_HELP_STR BGP_AFI_HELP_STR
11263 BGP_SAFI_HELP_STR
11264 "Detailed info about dynamic update groups\n"
11265 "Specific subgroup to display info for\n"
11266 "Advertisement queue\n"
11267 "Announced routes\n"
11268 "Packet queue\n")
11269 {
11270 uint64_t subgrp_id = 0;
11271 afi_t afiz;
11272 safi_t safiz;
11273 if (sgid)
11274 subgrp_id = strtoull(sgid, NULL, 10);
11275
11276 if (!ip && !afi)
11277 afiz = AFI_IP6;
11278 if (!ip && afi)
11279 afiz = bgp_vty_afi_from_str(afi);
11280 if (ip && !afi)
11281 afiz = AFI_IP;
11282 if (ip && afi) {
11283 afiz = bgp_vty_afi_from_str(afi);
11284 if (afiz != AFI_IP)
11285 vty_out(vty,
11286 "%% Cannot specify both 'ip' and 'ipv6'\n");
11287 return CMD_WARNING;
11288 }
11289
11290 safiz = safi ? bgp_vty_safi_from_str(safi) : SAFI_UNICAST;
11291
11292 show_bgp_updgrps_adj_info_aux(vty, vrf, afiz, safiz, rtq, subgrp_id);
11293 return CMD_SUCCESS;
11294 }
11295
11296 static int bgp_show_one_peer_group(struct vty *vty, struct peer_group *group)
11297 {
11298 struct listnode *node, *nnode;
11299 struct prefix *range;
11300 struct peer *conf;
11301 struct peer *peer;
11302 char buf[PREFIX2STR_BUFFER];
11303 afi_t afi;
11304 safi_t safi;
11305 const char *peer_status;
11306 const char *af_str;
11307 int lr_count;
11308 int dynamic;
11309 int af_cfgd;
11310
11311 conf = group->conf;
11312
11313 if (conf->as_type == AS_SPECIFIED || conf->as_type == AS_EXTERNAL) {
11314 vty_out(vty, "\nBGP peer-group %s, remote AS %d\n", group->name,
11315 conf->as);
11316 } else if (conf->as_type == AS_INTERNAL) {
11317 vty_out(vty, "\nBGP peer-group %s, remote AS %d\n", group->name,
11318 group->bgp->as);
11319 } else {
11320 vty_out(vty, "\nBGP peer-group %s\n", group->name);
11321 }
11322
11323 if ((group->bgp->as == conf->as) || (conf->as_type == AS_INTERNAL))
11324 vty_out(vty, " Peer-group type is internal\n");
11325 else
11326 vty_out(vty, " Peer-group type is external\n");
11327
11328 /* Display AFs configured. */
11329 vty_out(vty, " Configured address-families:");
11330 FOREACH_AFI_SAFI (afi, safi) {
11331 if (conf->afc[afi][safi]) {
11332 af_cfgd = 1;
11333 vty_out(vty, " %s;", afi_safi_print(afi, safi));
11334 }
11335 }
11336 if (!af_cfgd)
11337 vty_out(vty, " none\n");
11338 else
11339 vty_out(vty, "\n");
11340
11341 /* Display listen ranges (for dynamic neighbors), if any */
11342 for (afi = AFI_IP; afi < AFI_MAX; afi++) {
11343 if (afi == AFI_IP)
11344 af_str = "IPv4";
11345 else if (afi == AFI_IP6)
11346 af_str = "IPv6";
11347 else
11348 af_str = "???";
11349 lr_count = listcount(group->listen_range[afi]);
11350 if (lr_count) {
11351 vty_out(vty, " %d %s listen range(s)\n", lr_count,
11352 af_str);
11353
11354
11355 for (ALL_LIST_ELEMENTS(group->listen_range[afi], node,
11356 nnode, range)) {
11357 prefix2str(range, buf, sizeof(buf));
11358 vty_out(vty, " %s\n", buf);
11359 }
11360 }
11361 }
11362
11363 /* Display group members and their status */
11364 if (listcount(group->peer)) {
11365 vty_out(vty, " Peer-group members:\n");
11366 for (ALL_LIST_ELEMENTS(group->peer, node, nnode, peer)) {
11367 if (CHECK_FLAG(peer->flags, PEER_FLAG_SHUTDOWN))
11368 peer_status = "Idle (Admin)";
11369 else if (CHECK_FLAG(peer->sflags,
11370 PEER_STATUS_PREFIX_OVERFLOW))
11371 peer_status = "Idle (PfxCt)";
11372 else
11373 peer_status = lookup_msg(bgp_status_msg,
11374 peer->status, NULL);
11375
11376 dynamic = peer_dynamic_neighbor(peer);
11377 vty_out(vty, " %s %s %s \n", peer->host,
11378 dynamic ? "(dynamic)" : "", peer_status);
11379 }
11380 }
11381
11382 return CMD_SUCCESS;
11383 }
11384
11385 static int bgp_show_peer_group_vty(struct vty *vty, const char *name,
11386 const char *group_name)
11387 {
11388 struct bgp *bgp;
11389 struct listnode *node, *nnode;
11390 struct peer_group *group;
11391 bool found = false;
11392
11393 bgp = name ? bgp_lookup_by_name(name) : bgp_get_default();
11394
11395 if (!bgp) {
11396 vty_out(vty, "%% No such BGP instance exists\n");
11397 return CMD_WARNING;
11398 }
11399
11400 for (ALL_LIST_ELEMENTS(bgp->group, node, nnode, group)) {
11401 if (group_name) {
11402 if (strmatch(group->name, group_name)) {
11403 bgp_show_one_peer_group(vty, group);
11404 found = true;
11405 break;
11406 }
11407 } else {
11408 bgp_show_one_peer_group(vty, group);
11409 }
11410 }
11411
11412 if (group_name && !found)
11413 vty_out(vty, "%% No such peer-group\n");
11414
11415 return CMD_SUCCESS;
11416 }
11417
11418 DEFUN (show_ip_bgp_peer_groups,
11419 show_ip_bgp_peer_groups_cmd,
11420 "show [ip] bgp [<view|vrf> VIEWVRFNAME] peer-group [PGNAME]",
11421 SHOW_STR
11422 IP_STR
11423 BGP_STR
11424 BGP_INSTANCE_HELP_STR
11425 "Detailed information on BGP peer groups\n"
11426 "Peer group name\n")
11427 {
11428 char *vrf, *pg;
11429 int idx = 0;
11430
11431 vrf = argv_find(argv, argc, "VIEWVRFNAME", &idx) ? argv[idx]->arg
11432 : NULL;
11433 pg = argv_find(argv, argc, "PGNAME", &idx) ? argv[idx]->arg : NULL;
11434
11435 return bgp_show_peer_group_vty(vty, vrf, pg);
11436 }
11437
11438
11439 /* Redistribute VTY commands. */
11440
11441 DEFUN (bgp_redistribute_ipv4,
11442 bgp_redistribute_ipv4_cmd,
11443 "redistribute " FRR_IP_REDIST_STR_BGPD,
11444 "Redistribute information from another routing protocol\n"
11445 FRR_IP_REDIST_HELP_STR_BGPD)
11446 {
11447 VTY_DECLVAR_CONTEXT(bgp, bgp);
11448 int idx_protocol = 1;
11449 int type;
11450
11451 type = proto_redistnum(AFI_IP, argv[idx_protocol]->text);
11452 if (type < 0) {
11453 vty_out(vty, "%% Invalid route type\n");
11454 return CMD_WARNING_CONFIG_FAILED;
11455 }
11456
11457 bgp_redist_add(bgp, AFI_IP, type, 0);
11458 return bgp_redistribute_set(bgp, AFI_IP, type, 0);
11459 }
11460
11461 ALIAS_HIDDEN(
11462 bgp_redistribute_ipv4, bgp_redistribute_ipv4_hidden_cmd,
11463 "redistribute " FRR_IP_REDIST_STR_BGPD,
11464 "Redistribute information from another routing protocol\n" FRR_IP_REDIST_HELP_STR_BGPD)
11465
11466 DEFUN (bgp_redistribute_ipv4_rmap,
11467 bgp_redistribute_ipv4_rmap_cmd,
11468 "redistribute " FRR_IP_REDIST_STR_BGPD " route-map WORD",
11469 "Redistribute information from another routing protocol\n"
11470 FRR_IP_REDIST_HELP_STR_BGPD
11471 "Route map reference\n"
11472 "Pointer to route-map entries\n")
11473 {
11474 VTY_DECLVAR_CONTEXT(bgp, bgp);
11475 int idx_protocol = 1;
11476 int idx_word = 3;
11477 int type;
11478 struct bgp_redist *red;
11479
11480 type = proto_redistnum(AFI_IP, argv[idx_protocol]->text);
11481 if (type < 0) {
11482 vty_out(vty, "%% Invalid route type\n");
11483 return CMD_WARNING_CONFIG_FAILED;
11484 }
11485
11486 red = bgp_redist_add(bgp, AFI_IP, type, 0);
11487 bgp_redistribute_rmap_set(red, argv[idx_word]->arg);
11488 return bgp_redistribute_set(bgp, AFI_IP, type, 0);
11489 }
11490
11491 ALIAS_HIDDEN(
11492 bgp_redistribute_ipv4_rmap, bgp_redistribute_ipv4_rmap_hidden_cmd,
11493 "redistribute " FRR_IP_REDIST_STR_BGPD " route-map WORD",
11494 "Redistribute information from another routing protocol\n" FRR_IP_REDIST_HELP_STR_BGPD
11495 "Route map reference\n"
11496 "Pointer to route-map entries\n")
11497
11498 DEFUN (bgp_redistribute_ipv4_metric,
11499 bgp_redistribute_ipv4_metric_cmd,
11500 "redistribute " FRR_IP_REDIST_STR_BGPD " metric (0-4294967295)",
11501 "Redistribute information from another routing protocol\n"
11502 FRR_IP_REDIST_HELP_STR_BGPD
11503 "Metric for redistributed routes\n"
11504 "Default metric\n")
11505 {
11506 VTY_DECLVAR_CONTEXT(bgp, bgp);
11507 int idx_protocol = 1;
11508 int idx_number = 3;
11509 int type;
11510 uint32_t metric;
11511 struct bgp_redist *red;
11512
11513 type = proto_redistnum(AFI_IP, argv[idx_protocol]->text);
11514 if (type < 0) {
11515 vty_out(vty, "%% Invalid route type\n");
11516 return CMD_WARNING_CONFIG_FAILED;
11517 }
11518 metric = strtoul(argv[idx_number]->arg, NULL, 10);
11519
11520 red = bgp_redist_add(bgp, AFI_IP, type, 0);
11521 bgp_redistribute_metric_set(bgp, red, AFI_IP, type, metric);
11522 return bgp_redistribute_set(bgp, AFI_IP, type, 0);
11523 }
11524
11525 ALIAS_HIDDEN(
11526 bgp_redistribute_ipv4_metric, bgp_redistribute_ipv4_metric_hidden_cmd,
11527 "redistribute " FRR_IP_REDIST_STR_BGPD " metric (0-4294967295)",
11528 "Redistribute information from another routing protocol\n" FRR_IP_REDIST_HELP_STR_BGPD
11529 "Metric for redistributed routes\n"
11530 "Default metric\n")
11531
11532 DEFUN (bgp_redistribute_ipv4_rmap_metric,
11533 bgp_redistribute_ipv4_rmap_metric_cmd,
11534 "redistribute " FRR_IP_REDIST_STR_BGPD " route-map WORD metric (0-4294967295)",
11535 "Redistribute information from another routing protocol\n"
11536 FRR_IP_REDIST_HELP_STR_BGPD
11537 "Route map reference\n"
11538 "Pointer to route-map entries\n"
11539 "Metric for redistributed routes\n"
11540 "Default metric\n")
11541 {
11542 VTY_DECLVAR_CONTEXT(bgp, bgp);
11543 int idx_protocol = 1;
11544 int idx_word = 3;
11545 int idx_number = 5;
11546 int type;
11547 uint32_t metric;
11548 struct bgp_redist *red;
11549
11550 type = proto_redistnum(AFI_IP, argv[idx_protocol]->text);
11551 if (type < 0) {
11552 vty_out(vty, "%% Invalid route type\n");
11553 return CMD_WARNING_CONFIG_FAILED;
11554 }
11555 metric = strtoul(argv[idx_number]->arg, NULL, 10);
11556
11557 red = bgp_redist_add(bgp, AFI_IP, type, 0);
11558 bgp_redistribute_rmap_set(red, argv[idx_word]->arg);
11559 bgp_redistribute_metric_set(bgp, red, AFI_IP, type, metric);
11560 return bgp_redistribute_set(bgp, AFI_IP, type, 0);
11561 }
11562
11563 ALIAS_HIDDEN(
11564 bgp_redistribute_ipv4_rmap_metric,
11565 bgp_redistribute_ipv4_rmap_metric_hidden_cmd,
11566 "redistribute " FRR_IP_REDIST_STR_BGPD
11567 " route-map WORD metric (0-4294967295)",
11568 "Redistribute information from another routing protocol\n" FRR_IP_REDIST_HELP_STR_BGPD
11569 "Route map reference\n"
11570 "Pointer to route-map entries\n"
11571 "Metric for redistributed routes\n"
11572 "Default metric\n")
11573
11574 DEFUN (bgp_redistribute_ipv4_metric_rmap,
11575 bgp_redistribute_ipv4_metric_rmap_cmd,
11576 "redistribute " FRR_IP_REDIST_STR_BGPD " metric (0-4294967295) route-map WORD",
11577 "Redistribute information from another routing protocol\n"
11578 FRR_IP_REDIST_HELP_STR_BGPD
11579 "Metric for redistributed routes\n"
11580 "Default metric\n"
11581 "Route map reference\n"
11582 "Pointer to route-map entries\n")
11583 {
11584 VTY_DECLVAR_CONTEXT(bgp, bgp);
11585 int idx_protocol = 1;
11586 int idx_number = 3;
11587 int idx_word = 5;
11588 int type;
11589 uint32_t metric;
11590 struct bgp_redist *red;
11591
11592 type = proto_redistnum(AFI_IP, argv[idx_protocol]->text);
11593 if (type < 0) {
11594 vty_out(vty, "%% Invalid route type\n");
11595 return CMD_WARNING_CONFIG_FAILED;
11596 }
11597 metric = strtoul(argv[idx_number]->arg, NULL, 10);
11598
11599 red = bgp_redist_add(bgp, AFI_IP, type, 0);
11600 bgp_redistribute_metric_set(bgp, red, AFI_IP, type, metric);
11601 bgp_redistribute_rmap_set(red, argv[idx_word]->arg);
11602 return bgp_redistribute_set(bgp, AFI_IP, type, 0);
11603 }
11604
11605 ALIAS_HIDDEN(
11606 bgp_redistribute_ipv4_metric_rmap,
11607 bgp_redistribute_ipv4_metric_rmap_hidden_cmd,
11608 "redistribute " FRR_IP_REDIST_STR_BGPD
11609 " metric (0-4294967295) route-map WORD",
11610 "Redistribute information from another routing protocol\n" FRR_IP_REDIST_HELP_STR_BGPD
11611 "Metric for redistributed routes\n"
11612 "Default metric\n"
11613 "Route map reference\n"
11614 "Pointer to route-map entries\n")
11615
11616 DEFUN (bgp_redistribute_ipv4_ospf,
11617 bgp_redistribute_ipv4_ospf_cmd,
11618 "redistribute <ospf|table> (1-65535)",
11619 "Redistribute information from another routing protocol\n"
11620 "Open Shortest Path First (OSPFv2)\n"
11621 "Non-main Kernel Routing Table\n"
11622 "Instance ID/Table ID\n")
11623 {
11624 VTY_DECLVAR_CONTEXT(bgp, bgp);
11625 int idx_ospf_table = 1;
11626 int idx_number = 2;
11627 unsigned short instance;
11628 unsigned short protocol;
11629
11630 instance = strtoul(argv[idx_number]->arg, NULL, 10);
11631
11632 if (strncmp(argv[idx_ospf_table]->arg, "o", 1) == 0)
11633 protocol = ZEBRA_ROUTE_OSPF;
11634 else
11635 protocol = ZEBRA_ROUTE_TABLE;
11636
11637 bgp_redist_add(bgp, AFI_IP, protocol, instance);
11638 return bgp_redistribute_set(bgp, AFI_IP, protocol, instance);
11639 }
11640
11641 ALIAS_HIDDEN(bgp_redistribute_ipv4_ospf, bgp_redistribute_ipv4_ospf_hidden_cmd,
11642 "redistribute <ospf|table> (1-65535)",
11643 "Redistribute information from another routing protocol\n"
11644 "Open Shortest Path First (OSPFv2)\n"
11645 "Non-main Kernel Routing Table\n"
11646 "Instance ID/Table ID\n")
11647
11648 DEFUN (bgp_redistribute_ipv4_ospf_rmap,
11649 bgp_redistribute_ipv4_ospf_rmap_cmd,
11650 "redistribute <ospf|table> (1-65535) route-map WORD",
11651 "Redistribute information from another routing protocol\n"
11652 "Open Shortest Path First (OSPFv2)\n"
11653 "Non-main Kernel Routing Table\n"
11654 "Instance ID/Table ID\n"
11655 "Route map reference\n"
11656 "Pointer to route-map entries\n")
11657 {
11658 VTY_DECLVAR_CONTEXT(bgp, bgp);
11659 int idx_ospf_table = 1;
11660 int idx_number = 2;
11661 int idx_word = 4;
11662 struct bgp_redist *red;
11663 unsigned short instance;
11664 int protocol;
11665
11666 if (strncmp(argv[idx_ospf_table]->arg, "o", 1) == 0)
11667 protocol = ZEBRA_ROUTE_OSPF;
11668 else
11669 protocol = ZEBRA_ROUTE_TABLE;
11670
11671 instance = strtoul(argv[idx_number]->arg, NULL, 10);
11672 red = bgp_redist_add(bgp, AFI_IP, protocol, instance);
11673 bgp_redistribute_rmap_set(red, argv[idx_word]->arg);
11674 return bgp_redistribute_set(bgp, AFI_IP, protocol, instance);
11675 }
11676
11677 ALIAS_HIDDEN(bgp_redistribute_ipv4_ospf_rmap,
11678 bgp_redistribute_ipv4_ospf_rmap_hidden_cmd,
11679 "redistribute <ospf|table> (1-65535) route-map WORD",
11680 "Redistribute information from another routing protocol\n"
11681 "Open Shortest Path First (OSPFv2)\n"
11682 "Non-main Kernel Routing Table\n"
11683 "Instance ID/Table ID\n"
11684 "Route map reference\n"
11685 "Pointer to route-map entries\n")
11686
11687 DEFUN (bgp_redistribute_ipv4_ospf_metric,
11688 bgp_redistribute_ipv4_ospf_metric_cmd,
11689 "redistribute <ospf|table> (1-65535) metric (0-4294967295)",
11690 "Redistribute information from another routing protocol\n"
11691 "Open Shortest Path First (OSPFv2)\n"
11692 "Non-main Kernel Routing Table\n"
11693 "Instance ID/Table ID\n"
11694 "Metric for redistributed routes\n"
11695 "Default metric\n")
11696 {
11697 VTY_DECLVAR_CONTEXT(bgp, bgp);
11698 int idx_ospf_table = 1;
11699 int idx_number = 2;
11700 int idx_number_2 = 4;
11701 uint32_t metric;
11702 struct bgp_redist *red;
11703 unsigned short instance;
11704 int protocol;
11705
11706 if (strncmp(argv[idx_ospf_table]->arg, "o", 1) == 0)
11707 protocol = ZEBRA_ROUTE_OSPF;
11708 else
11709 protocol = ZEBRA_ROUTE_TABLE;
11710
11711 instance = strtoul(argv[idx_number]->arg, NULL, 10);
11712 metric = strtoul(argv[idx_number_2]->arg, NULL, 10);
11713
11714 red = bgp_redist_add(bgp, AFI_IP, protocol, instance);
11715 bgp_redistribute_metric_set(bgp, red, AFI_IP, protocol, metric);
11716 return bgp_redistribute_set(bgp, AFI_IP, protocol, instance);
11717 }
11718
11719 ALIAS_HIDDEN(bgp_redistribute_ipv4_ospf_metric,
11720 bgp_redistribute_ipv4_ospf_metric_hidden_cmd,
11721 "redistribute <ospf|table> (1-65535) metric (0-4294967295)",
11722 "Redistribute information from another routing protocol\n"
11723 "Open Shortest Path First (OSPFv2)\n"
11724 "Non-main Kernel Routing Table\n"
11725 "Instance ID/Table ID\n"
11726 "Metric for redistributed routes\n"
11727 "Default metric\n")
11728
11729 DEFUN (bgp_redistribute_ipv4_ospf_rmap_metric,
11730 bgp_redistribute_ipv4_ospf_rmap_metric_cmd,
11731 "redistribute <ospf|table> (1-65535) route-map WORD metric (0-4294967295)",
11732 "Redistribute information from another routing protocol\n"
11733 "Open Shortest Path First (OSPFv2)\n"
11734 "Non-main Kernel Routing Table\n"
11735 "Instance ID/Table ID\n"
11736 "Route map reference\n"
11737 "Pointer to route-map entries\n"
11738 "Metric for redistributed routes\n"
11739 "Default metric\n")
11740 {
11741 VTY_DECLVAR_CONTEXT(bgp, bgp);
11742 int idx_ospf_table = 1;
11743 int idx_number = 2;
11744 int idx_word = 4;
11745 int idx_number_2 = 6;
11746 uint32_t metric;
11747 struct bgp_redist *red;
11748 unsigned short instance;
11749 int protocol;
11750
11751 if (strncmp(argv[idx_ospf_table]->arg, "o", 1) == 0)
11752 protocol = ZEBRA_ROUTE_OSPF;
11753 else
11754 protocol = ZEBRA_ROUTE_TABLE;
11755
11756 instance = strtoul(argv[idx_number]->arg, NULL, 10);
11757 metric = strtoul(argv[idx_number_2]->arg, NULL, 10);
11758
11759 red = bgp_redist_add(bgp, AFI_IP, protocol, instance);
11760 bgp_redistribute_rmap_set(red, argv[idx_word]->arg);
11761 bgp_redistribute_metric_set(bgp, red, AFI_IP, protocol, metric);
11762 return bgp_redistribute_set(bgp, AFI_IP, protocol, instance);
11763 }
11764
11765 ALIAS_HIDDEN(
11766 bgp_redistribute_ipv4_ospf_rmap_metric,
11767 bgp_redistribute_ipv4_ospf_rmap_metric_hidden_cmd,
11768 "redistribute <ospf|table> (1-65535) route-map WORD metric (0-4294967295)",
11769 "Redistribute information from another routing protocol\n"
11770 "Open Shortest Path First (OSPFv2)\n"
11771 "Non-main Kernel Routing Table\n"
11772 "Instance ID/Table ID\n"
11773 "Route map reference\n"
11774 "Pointer to route-map entries\n"
11775 "Metric for redistributed routes\n"
11776 "Default metric\n")
11777
11778 DEFUN (bgp_redistribute_ipv4_ospf_metric_rmap,
11779 bgp_redistribute_ipv4_ospf_metric_rmap_cmd,
11780 "redistribute <ospf|table> (1-65535) metric (0-4294967295) route-map WORD",
11781 "Redistribute information from another routing protocol\n"
11782 "Open Shortest Path First (OSPFv2)\n"
11783 "Non-main Kernel Routing Table\n"
11784 "Instance ID/Table ID\n"
11785 "Metric for redistributed routes\n"
11786 "Default metric\n"
11787 "Route map reference\n"
11788 "Pointer to route-map entries\n")
11789 {
11790 VTY_DECLVAR_CONTEXT(bgp, bgp);
11791 int idx_ospf_table = 1;
11792 int idx_number = 2;
11793 int idx_number_2 = 4;
11794 int idx_word = 6;
11795 uint32_t metric;
11796 struct bgp_redist *red;
11797 unsigned short instance;
11798 int protocol;
11799
11800 if (strncmp(argv[idx_ospf_table]->arg, "o", 1) == 0)
11801 protocol = ZEBRA_ROUTE_OSPF;
11802 else
11803 protocol = ZEBRA_ROUTE_TABLE;
11804
11805 instance = strtoul(argv[idx_number]->arg, NULL, 10);
11806 metric = strtoul(argv[idx_number_2]->arg, NULL, 10);
11807
11808 red = bgp_redist_add(bgp, AFI_IP, protocol, instance);
11809 bgp_redistribute_metric_set(bgp, red, AFI_IP, protocol, metric);
11810 bgp_redistribute_rmap_set(red, argv[idx_word]->arg);
11811 return bgp_redistribute_set(bgp, AFI_IP, protocol, instance);
11812 }
11813
11814 ALIAS_HIDDEN(
11815 bgp_redistribute_ipv4_ospf_metric_rmap,
11816 bgp_redistribute_ipv4_ospf_metric_rmap_hidden_cmd,
11817 "redistribute <ospf|table> (1-65535) metric (0-4294967295) route-map WORD",
11818 "Redistribute information from another routing protocol\n"
11819 "Open Shortest Path First (OSPFv2)\n"
11820 "Non-main Kernel Routing Table\n"
11821 "Instance ID/Table ID\n"
11822 "Metric for redistributed routes\n"
11823 "Default metric\n"
11824 "Route map reference\n"
11825 "Pointer to route-map entries\n")
11826
11827 DEFUN (no_bgp_redistribute_ipv4_ospf,
11828 no_bgp_redistribute_ipv4_ospf_cmd,
11829 "no redistribute <ospf|table> (1-65535) [metric (0-4294967295)] [route-map WORD]",
11830 NO_STR
11831 "Redistribute information from another routing protocol\n"
11832 "Open Shortest Path First (OSPFv2)\n"
11833 "Non-main Kernel Routing Table\n"
11834 "Instance ID/Table ID\n"
11835 "Metric for redistributed routes\n"
11836 "Default metric\n"
11837 "Route map reference\n"
11838 "Pointer to route-map entries\n")
11839 {
11840 VTY_DECLVAR_CONTEXT(bgp, bgp);
11841 int idx_ospf_table = 2;
11842 int idx_number = 3;
11843 unsigned short instance;
11844 int protocol;
11845
11846 if (strncmp(argv[idx_ospf_table]->arg, "o", 1) == 0)
11847 protocol = ZEBRA_ROUTE_OSPF;
11848 else
11849 protocol = ZEBRA_ROUTE_TABLE;
11850
11851 instance = strtoul(argv[idx_number]->arg, NULL, 10);
11852 return bgp_redistribute_unset(bgp, AFI_IP, protocol, instance);
11853 }
11854
11855 ALIAS_HIDDEN(
11856 no_bgp_redistribute_ipv4_ospf, no_bgp_redistribute_ipv4_ospf_hidden_cmd,
11857 "no redistribute <ospf|table> (1-65535) [metric (0-4294967295)] [route-map WORD]",
11858 NO_STR
11859 "Redistribute information from another routing protocol\n"
11860 "Open Shortest Path First (OSPFv2)\n"
11861 "Non-main Kernel Routing Table\n"
11862 "Instance ID/Table ID\n"
11863 "Metric for redistributed routes\n"
11864 "Default metric\n"
11865 "Route map reference\n"
11866 "Pointer to route-map entries\n")
11867
11868 DEFUN (no_bgp_redistribute_ipv4,
11869 no_bgp_redistribute_ipv4_cmd,
11870 "no redistribute " FRR_IP_REDIST_STR_BGPD " [metric (0-4294967295)] [route-map WORD]",
11871 NO_STR
11872 "Redistribute information from another routing protocol\n"
11873 FRR_IP_REDIST_HELP_STR_BGPD
11874 "Metric for redistributed routes\n"
11875 "Default metric\n"
11876 "Route map reference\n"
11877 "Pointer to route-map entries\n")
11878 {
11879 VTY_DECLVAR_CONTEXT(bgp, bgp);
11880 int idx_protocol = 2;
11881 int type;
11882
11883 type = proto_redistnum(AFI_IP, argv[idx_protocol]->text);
11884 if (type < 0) {
11885 vty_out(vty, "%% Invalid route type\n");
11886 return CMD_WARNING_CONFIG_FAILED;
11887 }
11888 return bgp_redistribute_unset(bgp, AFI_IP, type, 0);
11889 }
11890
11891 ALIAS_HIDDEN(
11892 no_bgp_redistribute_ipv4, no_bgp_redistribute_ipv4_hidden_cmd,
11893 "no redistribute " FRR_IP_REDIST_STR_BGPD
11894 " [metric (0-4294967295)] [route-map WORD]",
11895 NO_STR
11896 "Redistribute information from another routing protocol\n" FRR_IP_REDIST_HELP_STR_BGPD
11897 "Metric for redistributed routes\n"
11898 "Default metric\n"
11899 "Route map reference\n"
11900 "Pointer to route-map entries\n")
11901
11902 DEFUN (bgp_redistribute_ipv6,
11903 bgp_redistribute_ipv6_cmd,
11904 "redistribute " FRR_IP6_REDIST_STR_BGPD,
11905 "Redistribute information from another routing protocol\n"
11906 FRR_IP6_REDIST_HELP_STR_BGPD)
11907 {
11908 VTY_DECLVAR_CONTEXT(bgp, bgp);
11909 int idx_protocol = 1;
11910 int type;
11911
11912 type = proto_redistnum(AFI_IP6, argv[idx_protocol]->text);
11913 if (type < 0) {
11914 vty_out(vty, "%% Invalid route type\n");
11915 return CMD_WARNING_CONFIG_FAILED;
11916 }
11917
11918 bgp_redist_add(bgp, AFI_IP6, type, 0);
11919 return bgp_redistribute_set(bgp, AFI_IP6, type, 0);
11920 }
11921
11922 DEFUN (bgp_redistribute_ipv6_rmap,
11923 bgp_redistribute_ipv6_rmap_cmd,
11924 "redistribute " FRR_IP6_REDIST_STR_BGPD " route-map WORD",
11925 "Redistribute information from another routing protocol\n"
11926 FRR_IP6_REDIST_HELP_STR_BGPD
11927 "Route map reference\n"
11928 "Pointer to route-map entries\n")
11929 {
11930 VTY_DECLVAR_CONTEXT(bgp, bgp);
11931 int idx_protocol = 1;
11932 int idx_word = 3;
11933 int type;
11934 struct bgp_redist *red;
11935
11936 type = proto_redistnum(AFI_IP6, argv[idx_protocol]->text);
11937 if (type < 0) {
11938 vty_out(vty, "%% Invalid route type\n");
11939 return CMD_WARNING_CONFIG_FAILED;
11940 }
11941
11942 red = bgp_redist_add(bgp, AFI_IP6, type, 0);
11943 bgp_redistribute_rmap_set(red, argv[idx_word]->arg);
11944 return bgp_redistribute_set(bgp, AFI_IP6, type, 0);
11945 }
11946
11947 DEFUN (bgp_redistribute_ipv6_metric,
11948 bgp_redistribute_ipv6_metric_cmd,
11949 "redistribute " FRR_IP6_REDIST_STR_BGPD " metric (0-4294967295)",
11950 "Redistribute information from another routing protocol\n"
11951 FRR_IP6_REDIST_HELP_STR_BGPD
11952 "Metric for redistributed routes\n"
11953 "Default metric\n")
11954 {
11955 VTY_DECLVAR_CONTEXT(bgp, bgp);
11956 int idx_protocol = 1;
11957 int idx_number = 3;
11958 int type;
11959 uint32_t metric;
11960 struct bgp_redist *red;
11961
11962 type = proto_redistnum(AFI_IP6, argv[idx_protocol]->text);
11963 if (type < 0) {
11964 vty_out(vty, "%% Invalid route type\n");
11965 return CMD_WARNING_CONFIG_FAILED;
11966 }
11967 metric = strtoul(argv[idx_number]->arg, NULL, 10);
11968
11969 red = bgp_redist_add(bgp, AFI_IP6, type, 0);
11970 bgp_redistribute_metric_set(bgp, red, AFI_IP6, type, metric);
11971 return bgp_redistribute_set(bgp, AFI_IP6, type, 0);
11972 }
11973
11974 DEFUN (bgp_redistribute_ipv6_rmap_metric,
11975 bgp_redistribute_ipv6_rmap_metric_cmd,
11976 "redistribute " FRR_IP6_REDIST_STR_BGPD " route-map WORD metric (0-4294967295)",
11977 "Redistribute information from another routing protocol\n"
11978 FRR_IP6_REDIST_HELP_STR_BGPD
11979 "Route map reference\n"
11980 "Pointer to route-map entries\n"
11981 "Metric for redistributed routes\n"
11982 "Default metric\n")
11983 {
11984 VTY_DECLVAR_CONTEXT(bgp, bgp);
11985 int idx_protocol = 1;
11986 int idx_word = 3;
11987 int idx_number = 5;
11988 int type;
11989 uint32_t metric;
11990 struct bgp_redist *red;
11991
11992 type = proto_redistnum(AFI_IP6, argv[idx_protocol]->text);
11993 if (type < 0) {
11994 vty_out(vty, "%% Invalid route type\n");
11995 return CMD_WARNING_CONFIG_FAILED;
11996 }
11997 metric = strtoul(argv[idx_number]->arg, NULL, 10);
11998
11999 red = bgp_redist_add(bgp, AFI_IP6, type, 0);
12000 bgp_redistribute_rmap_set(red, argv[idx_word]->arg);
12001 bgp_redistribute_metric_set(bgp, red, AFI_IP6, type, metric);
12002 return bgp_redistribute_set(bgp, AFI_IP6, type, 0);
12003 }
12004
12005 DEFUN (bgp_redistribute_ipv6_metric_rmap,
12006 bgp_redistribute_ipv6_metric_rmap_cmd,
12007 "redistribute " FRR_IP6_REDIST_STR_BGPD " metric (0-4294967295) route-map WORD",
12008 "Redistribute information from another routing protocol\n"
12009 FRR_IP6_REDIST_HELP_STR_BGPD
12010 "Metric for redistributed routes\n"
12011 "Default metric\n"
12012 "Route map reference\n"
12013 "Pointer to route-map entries\n")
12014 {
12015 VTY_DECLVAR_CONTEXT(bgp, bgp);
12016 int idx_protocol = 1;
12017 int idx_number = 3;
12018 int idx_word = 5;
12019 int type;
12020 uint32_t metric;
12021 struct bgp_redist *red;
12022
12023 type = proto_redistnum(AFI_IP6, argv[idx_protocol]->text);
12024 if (type < 0) {
12025 vty_out(vty, "%% Invalid route type\n");
12026 return CMD_WARNING_CONFIG_FAILED;
12027 }
12028 metric = strtoul(argv[idx_number]->arg, NULL, 10);
12029
12030 red = bgp_redist_add(bgp, AFI_IP6, type, 0);
12031 bgp_redistribute_metric_set(bgp, red, AFI_IP6, SAFI_UNICAST, metric);
12032 bgp_redistribute_rmap_set(red, argv[idx_word]->arg);
12033 return bgp_redistribute_set(bgp, AFI_IP6, type, 0);
12034 }
12035
12036 DEFUN (no_bgp_redistribute_ipv6,
12037 no_bgp_redistribute_ipv6_cmd,
12038 "no redistribute " FRR_IP6_REDIST_STR_BGPD " [metric (0-4294967295)] [route-map WORD]",
12039 NO_STR
12040 "Redistribute information from another routing protocol\n"
12041 FRR_IP6_REDIST_HELP_STR_BGPD
12042 "Metric for redistributed routes\n"
12043 "Default metric\n"
12044 "Route map reference\n"
12045 "Pointer to route-map entries\n")
12046 {
12047 VTY_DECLVAR_CONTEXT(bgp, bgp);
12048 int idx_protocol = 2;
12049 int type;
12050
12051 type = proto_redistnum(AFI_IP6, argv[idx_protocol]->text);
12052 if (type < 0) {
12053 vty_out(vty, "%% Invalid route type\n");
12054 return CMD_WARNING_CONFIG_FAILED;
12055 }
12056
12057 return bgp_redistribute_unset(bgp, AFI_IP6, type, 0);
12058 }
12059
12060 void bgp_config_write_redistribute(struct vty *vty, struct bgp *bgp, afi_t afi,
12061 safi_t safi)
12062 {
12063 int i;
12064
12065 /* Unicast redistribution only. */
12066 if (safi != SAFI_UNICAST)
12067 return;
12068
12069 for (i = 0; i < ZEBRA_ROUTE_MAX; i++) {
12070 /* Redistribute BGP does not make sense. */
12071 if (i != ZEBRA_ROUTE_BGP) {
12072 struct list *red_list;
12073 struct listnode *node;
12074 struct bgp_redist *red;
12075
12076 red_list = bgp->redist[afi][i];
12077 if (!red_list)
12078 continue;
12079
12080 for (ALL_LIST_ELEMENTS_RO(red_list, node, red)) {
12081 /* "redistribute" configuration. */
12082 vty_out(vty, " redistribute %s",
12083 zebra_route_string(i));
12084 if (red->instance)
12085 vty_out(vty, " %d", red->instance);
12086 if (red->redist_metric_flag)
12087 vty_out(vty, " metric %u",
12088 red->redist_metric);
12089 if (red->rmap.name)
12090 vty_out(vty, " route-map %s",
12091 red->rmap.name);
12092 vty_out(vty, "\n");
12093 }
12094 }
12095 }
12096 }
12097
12098 /* This is part of the address-family block (unicast only) */
12099 void bgp_vpn_policy_config_write_afi(struct vty *vty, struct bgp *bgp,
12100 afi_t afi)
12101 {
12102 int indent = 2;
12103
12104 if (bgp->vpn_policy[afi].rmap_name[BGP_VPN_POLICY_DIR_FROMVPN])
12105 vty_out(vty, "%*simport vrf route-map %s\n", indent, "",
12106 bgp->vpn_policy[afi]
12107 .rmap_name[BGP_VPN_POLICY_DIR_FROMVPN]);
12108
12109 if (CHECK_FLAG(bgp->af_flags[afi][SAFI_UNICAST],
12110 BGP_CONFIG_VRF_TO_VRF_IMPORT)
12111 || CHECK_FLAG(bgp->af_flags[afi][SAFI_UNICAST],
12112 BGP_CONFIG_VRF_TO_VRF_EXPORT))
12113 return;
12114
12115 if (CHECK_FLAG(bgp->vpn_policy[afi].flags,
12116 BGP_VPN_POLICY_TOVPN_LABEL_AUTO)) {
12117
12118 vty_out(vty, "%*slabel vpn export %s\n", indent, "", "auto");
12119
12120 } else {
12121 if (bgp->vpn_policy[afi].tovpn_label != MPLS_LABEL_NONE) {
12122 vty_out(vty, "%*slabel vpn export %u\n", indent, "",
12123 bgp->vpn_policy[afi].tovpn_label);
12124 }
12125 }
12126 if (CHECK_FLAG(bgp->vpn_policy[afi].flags,
12127 BGP_VPN_POLICY_TOVPN_RD_SET)) {
12128 char buf[RD_ADDRSTRLEN];
12129 vty_out(vty, "%*srd vpn export %s\n", indent, "",
12130 prefix_rd2str(&bgp->vpn_policy[afi].tovpn_rd, buf,
12131 sizeof(buf)));
12132 }
12133 if (CHECK_FLAG(bgp->vpn_policy[afi].flags,
12134 BGP_VPN_POLICY_TOVPN_NEXTHOP_SET)) {
12135
12136 char buf[PREFIX_STRLEN];
12137 if (inet_ntop(bgp->vpn_policy[afi].tovpn_nexthop.family,
12138 &bgp->vpn_policy[afi].tovpn_nexthop.u.prefix, buf,
12139 sizeof(buf))) {
12140
12141 vty_out(vty, "%*snexthop vpn export %s\n",
12142 indent, "", buf);
12143 }
12144 }
12145 if (bgp->vpn_policy[afi].rtlist[BGP_VPN_POLICY_DIR_FROMVPN]
12146 && bgp->vpn_policy[afi].rtlist[BGP_VPN_POLICY_DIR_TOVPN]
12147 && ecommunity_cmp(
12148 bgp->vpn_policy[afi].rtlist[BGP_VPN_POLICY_DIR_FROMVPN],
12149 bgp->vpn_policy[afi].rtlist[BGP_VPN_POLICY_DIR_TOVPN])) {
12150
12151 char *b = ecommunity_ecom2str(
12152 bgp->vpn_policy[afi].rtlist[BGP_VPN_POLICY_DIR_TOVPN],
12153 ECOMMUNITY_FORMAT_ROUTE_MAP, ECOMMUNITY_ROUTE_TARGET);
12154 vty_out(vty, "%*srt vpn both %s\n", indent, "", b);
12155 XFREE(MTYPE_ECOMMUNITY_STR, b);
12156 } else {
12157 if (bgp->vpn_policy[afi].rtlist[BGP_VPN_POLICY_DIR_FROMVPN]) {
12158 char *b = ecommunity_ecom2str(
12159 bgp->vpn_policy[afi]
12160 .rtlist[BGP_VPN_POLICY_DIR_FROMVPN],
12161 ECOMMUNITY_FORMAT_ROUTE_MAP,
12162 ECOMMUNITY_ROUTE_TARGET);
12163 vty_out(vty, "%*srt vpn import %s\n", indent, "", b);
12164 XFREE(MTYPE_ECOMMUNITY_STR, b);
12165 }
12166 if (bgp->vpn_policy[afi].rtlist[BGP_VPN_POLICY_DIR_TOVPN]) {
12167 char *b = ecommunity_ecom2str(
12168 bgp->vpn_policy[afi]
12169 .rtlist[BGP_VPN_POLICY_DIR_TOVPN],
12170 ECOMMUNITY_FORMAT_ROUTE_MAP,
12171 ECOMMUNITY_ROUTE_TARGET);
12172 vty_out(vty, "%*srt vpn export %s\n", indent, "", b);
12173 XFREE(MTYPE_ECOMMUNITY_STR, b);
12174 }
12175 }
12176
12177 if (bgp->vpn_policy[afi].rmap_name[BGP_VPN_POLICY_DIR_TOVPN])
12178 vty_out(vty, "%*sroute-map vpn export %s\n", indent, "",
12179 bgp->vpn_policy[afi]
12180 .rmap_name[BGP_VPN_POLICY_DIR_TOVPN]);
12181
12182 if (bgp->vpn_policy[afi].import_redirect_rtlist) {
12183 char *b = ecommunity_ecom2str(
12184 bgp->vpn_policy[afi]
12185 .import_redirect_rtlist,
12186 ECOMMUNITY_FORMAT_ROUTE_MAP,
12187 ECOMMUNITY_ROUTE_TARGET);
12188
12189 vty_out(vty, "%*srt redirect import %s\n", indent, "", b);
12190 XFREE(MTYPE_ECOMMUNITY_STR, b);
12191 }
12192 }
12193
12194
12195 /* BGP node structure. */
12196 static struct cmd_node bgp_node = {
12197 BGP_NODE, "%s(config-router)# ", 1,
12198 };
12199
12200 static struct cmd_node bgp_ipv4_unicast_node = {
12201 BGP_IPV4_NODE, "%s(config-router-af)# ", 1,
12202 };
12203
12204 static struct cmd_node bgp_ipv4_multicast_node = {
12205 BGP_IPV4M_NODE, "%s(config-router-af)# ", 1,
12206 };
12207
12208 static struct cmd_node bgp_ipv4_labeled_unicast_node = {
12209 BGP_IPV4L_NODE, "%s(config-router-af)# ", 1,
12210 };
12211
12212 static struct cmd_node bgp_ipv6_unicast_node = {
12213 BGP_IPV6_NODE, "%s(config-router-af)# ", 1,
12214 };
12215
12216 static struct cmd_node bgp_ipv6_multicast_node = {
12217 BGP_IPV6M_NODE, "%s(config-router-af)# ", 1,
12218 };
12219
12220 static struct cmd_node bgp_ipv6_labeled_unicast_node = {
12221 BGP_IPV6L_NODE, "%s(config-router-af)# ", 1,
12222 };
12223
12224 static struct cmd_node bgp_vpnv4_node = {BGP_VPNV4_NODE,
12225 "%s(config-router-af)# ", 1};
12226
12227 static struct cmd_node bgp_vpnv6_node = {BGP_VPNV6_NODE,
12228 "%s(config-router-af-vpnv6)# ", 1};
12229
12230 static struct cmd_node bgp_evpn_node = {BGP_EVPN_NODE,
12231 "%s(config-router-evpn)# ", 1};
12232
12233 static struct cmd_node bgp_evpn_vni_node = {BGP_EVPN_VNI_NODE,
12234 "%s(config-router-af-vni)# ", 1};
12235
12236 static struct cmd_node bgp_flowspecv4_node = {BGP_FLOWSPECV4_NODE,
12237 "%s(config-router-af)# ", 1};
12238
12239 static struct cmd_node bgp_flowspecv6_node = {BGP_FLOWSPECV6_NODE,
12240 "%s(config-router-af-vpnv6)# ", 1};
12241
12242 static void community_list_vty(void);
12243
12244 static void bgp_ac_neighbor(vector comps, struct cmd_token *token)
12245 {
12246 struct bgp *bgp;
12247 struct peer *peer;
12248 struct listnode *lnbgp, *lnpeer;
12249
12250 for (ALL_LIST_ELEMENTS_RO(bm->bgp, lnbgp, bgp)) {
12251 for (ALL_LIST_ELEMENTS_RO(bgp->peer, lnpeer, peer)) {
12252 /* only provide suggestions on the appropriate input
12253 * token type,
12254 * they'll otherwise show up multiple times */
12255 enum cmd_token_type match_type;
12256 char *name = peer->host;
12257
12258 if (peer->conf_if) {
12259 match_type = VARIABLE_TKN;
12260 name = peer->conf_if;
12261 } else if (strchr(peer->host, ':'))
12262 match_type = IPV6_TKN;
12263 else
12264 match_type = IPV4_TKN;
12265
12266 if (token->type != match_type)
12267 continue;
12268
12269 vector_set(comps, XSTRDUP(MTYPE_COMPLETION, name));
12270 }
12271 }
12272 }
12273
12274 static const struct cmd_variable_handler bgp_var_neighbor[] = {
12275 {.varname = "neighbor", .completions = bgp_ac_neighbor},
12276 {.varname = "neighbors", .completions = bgp_ac_neighbor},
12277 {.varname = "peer", .completions = bgp_ac_neighbor},
12278 {.completions = NULL}};
12279
12280 static void bgp_ac_peergroup(vector comps, struct cmd_token *token)
12281 {
12282 struct bgp *bgp;
12283 struct peer_group *group;
12284 struct listnode *lnbgp, *lnpeer;
12285
12286 for (ALL_LIST_ELEMENTS_RO(bm->bgp, lnbgp, bgp)) {
12287 for (ALL_LIST_ELEMENTS_RO(bgp->group, lnpeer, group))
12288 vector_set(comps, XSTRDUP(MTYPE_COMPLETION,
12289 group->name));
12290 }
12291 }
12292
12293 static const struct cmd_variable_handler bgp_var_peergroup[] = {
12294 {.tokenname = "PGNAME", .completions = bgp_ac_peergroup},
12295 {.completions = NULL} };
12296
12297 void bgp_vty_init(void)
12298 {
12299 cmd_variable_handler_register(bgp_var_neighbor);
12300 cmd_variable_handler_register(bgp_var_peergroup);
12301
12302 /* Install bgp top node. */
12303 install_node(&bgp_node, bgp_config_write);
12304 install_node(&bgp_ipv4_unicast_node, NULL);
12305 install_node(&bgp_ipv4_multicast_node, NULL);
12306 install_node(&bgp_ipv4_labeled_unicast_node, NULL);
12307 install_node(&bgp_ipv6_unicast_node, NULL);
12308 install_node(&bgp_ipv6_multicast_node, NULL);
12309 install_node(&bgp_ipv6_labeled_unicast_node, NULL);
12310 install_node(&bgp_vpnv4_node, NULL);
12311 install_node(&bgp_vpnv6_node, NULL);
12312 install_node(&bgp_evpn_node, NULL);
12313 install_node(&bgp_evpn_vni_node, NULL);
12314 install_node(&bgp_flowspecv4_node, NULL);
12315 install_node(&bgp_flowspecv6_node, NULL);
12316
12317 /* Install default VTY commands to new nodes. */
12318 install_default(BGP_NODE);
12319 install_default(BGP_IPV4_NODE);
12320 install_default(BGP_IPV4M_NODE);
12321 install_default(BGP_IPV4L_NODE);
12322 install_default(BGP_IPV6_NODE);
12323 install_default(BGP_IPV6M_NODE);
12324 install_default(BGP_IPV6L_NODE);
12325 install_default(BGP_VPNV4_NODE);
12326 install_default(BGP_VPNV6_NODE);
12327 install_default(BGP_FLOWSPECV4_NODE);
12328 install_default(BGP_FLOWSPECV6_NODE);
12329 install_default(BGP_EVPN_NODE);
12330 install_default(BGP_EVPN_VNI_NODE);
12331
12332 /* "bgp multiple-instance" commands. */
12333 install_element(CONFIG_NODE, &bgp_multiple_instance_cmd);
12334 install_element(CONFIG_NODE, &no_bgp_multiple_instance_cmd);
12335
12336 /* "bgp config-type" commands. */
12337 install_element(CONFIG_NODE, &bgp_config_type_cmd);
12338 install_element(CONFIG_NODE, &no_bgp_config_type_cmd);
12339
12340 /* bgp route-map delay-timer commands. */
12341 install_element(CONFIG_NODE, &bgp_set_route_map_delay_timer_cmd);
12342 install_element(CONFIG_NODE, &no_bgp_set_route_map_delay_timer_cmd);
12343
12344 /* Dummy commands (Currently not supported) */
12345 install_element(BGP_NODE, &no_synchronization_cmd);
12346 install_element(BGP_NODE, &no_auto_summary_cmd);
12347
12348 /* "router bgp" commands. */
12349 install_element(CONFIG_NODE, &router_bgp_cmd);
12350
12351 /* "no router bgp" commands. */
12352 install_element(CONFIG_NODE, &no_router_bgp_cmd);
12353
12354 /* "bgp router-id" commands. */
12355 install_element(BGP_NODE, &bgp_router_id_cmd);
12356 install_element(BGP_NODE, &no_bgp_router_id_cmd);
12357
12358 /* "bgp cluster-id" commands. */
12359 install_element(BGP_NODE, &bgp_cluster_id_cmd);
12360 install_element(BGP_NODE, &no_bgp_cluster_id_cmd);
12361
12362 /* "bgp confederation" commands. */
12363 install_element(BGP_NODE, &bgp_confederation_identifier_cmd);
12364 install_element(BGP_NODE, &no_bgp_confederation_identifier_cmd);
12365
12366 /* "bgp confederation peers" commands. */
12367 install_element(BGP_NODE, &bgp_confederation_peers_cmd);
12368 install_element(BGP_NODE, &no_bgp_confederation_peers_cmd);
12369
12370 /* bgp max-med command */
12371 install_element(BGP_NODE, &bgp_maxmed_admin_cmd);
12372 install_element(BGP_NODE, &no_bgp_maxmed_admin_cmd);
12373 install_element(BGP_NODE, &bgp_maxmed_admin_medv_cmd);
12374 install_element(BGP_NODE, &bgp_maxmed_onstartup_cmd);
12375 install_element(BGP_NODE, &no_bgp_maxmed_onstartup_cmd);
12376
12377 /* bgp disable-ebgp-connected-nh-check */
12378 install_element(BGP_NODE, &bgp_disable_connected_route_check_cmd);
12379 install_element(BGP_NODE, &no_bgp_disable_connected_route_check_cmd);
12380
12381 /* bgp update-delay command */
12382 install_element(BGP_NODE, &bgp_update_delay_cmd);
12383 install_element(BGP_NODE, &no_bgp_update_delay_cmd);
12384 install_element(BGP_NODE, &bgp_update_delay_establish_wait_cmd);
12385
12386 install_element(BGP_NODE, &bgp_wpkt_quanta_cmd);
12387 install_element(BGP_NODE, &no_bgp_wpkt_quanta_cmd);
12388 install_element(BGP_NODE, &bgp_rpkt_quanta_cmd);
12389 install_element(BGP_NODE, &no_bgp_rpkt_quanta_cmd);
12390
12391 install_element(BGP_NODE, &bgp_coalesce_time_cmd);
12392 install_element(BGP_NODE, &no_bgp_coalesce_time_cmd);
12393
12394 /* "maximum-paths" commands. */
12395 install_element(BGP_NODE, &bgp_maxpaths_hidden_cmd);
12396 install_element(BGP_NODE, &no_bgp_maxpaths_hidden_cmd);
12397 install_element(BGP_IPV4_NODE, &bgp_maxpaths_cmd);
12398 install_element(BGP_IPV4_NODE, &no_bgp_maxpaths_cmd);
12399 install_element(BGP_IPV6_NODE, &bgp_maxpaths_cmd);
12400 install_element(BGP_IPV6_NODE, &no_bgp_maxpaths_cmd);
12401 install_element(BGP_NODE, &bgp_maxpaths_ibgp_hidden_cmd);
12402 install_element(BGP_NODE, &bgp_maxpaths_ibgp_cluster_hidden_cmd);
12403 install_element(BGP_NODE, &no_bgp_maxpaths_ibgp_hidden_cmd);
12404 install_element(BGP_IPV4_NODE, &bgp_maxpaths_ibgp_cmd);
12405 install_element(BGP_IPV4_NODE, &bgp_maxpaths_ibgp_cluster_cmd);
12406 install_element(BGP_IPV4_NODE, &no_bgp_maxpaths_ibgp_cmd);
12407 install_element(BGP_IPV6_NODE, &bgp_maxpaths_ibgp_cmd);
12408 install_element(BGP_IPV6_NODE, &bgp_maxpaths_ibgp_cluster_cmd);
12409 install_element(BGP_IPV6_NODE, &no_bgp_maxpaths_ibgp_cmd);
12410
12411 install_element(BGP_IPV6L_NODE, &bgp_maxpaths_cmd);
12412 install_element(BGP_IPV6L_NODE, &no_bgp_maxpaths_cmd);
12413 install_element(BGP_IPV6L_NODE, &bgp_maxpaths_ibgp_cmd);
12414 install_element(BGP_IPV6L_NODE, &bgp_maxpaths_ibgp_cluster_cmd);
12415 install_element(BGP_IPV6L_NODE, &no_bgp_maxpaths_ibgp_cmd);
12416
12417 /* "timers bgp" commands. */
12418 install_element(BGP_NODE, &bgp_timers_cmd);
12419 install_element(BGP_NODE, &no_bgp_timers_cmd);
12420
12421 /* route-map delay-timer commands - per instance for backwards compat.
12422 */
12423 install_element(BGP_NODE, &bgp_set_route_map_delay_timer_cmd);
12424 install_element(BGP_NODE, &no_bgp_set_route_map_delay_timer_cmd);
12425
12426 /* "bgp client-to-client reflection" commands */
12427 install_element(BGP_NODE, &no_bgp_client_to_client_reflection_cmd);
12428 install_element(BGP_NODE, &bgp_client_to_client_reflection_cmd);
12429
12430 /* "bgp always-compare-med" commands */
12431 install_element(BGP_NODE, &bgp_always_compare_med_cmd);
12432 install_element(BGP_NODE, &no_bgp_always_compare_med_cmd);
12433
12434 /* "bgp deterministic-med" commands */
12435 install_element(BGP_NODE, &bgp_deterministic_med_cmd);
12436 install_element(BGP_NODE, &no_bgp_deterministic_med_cmd);
12437
12438 /* "bgp graceful-restart" commands */
12439 install_element(BGP_NODE, &bgp_graceful_restart_cmd);
12440 install_element(BGP_NODE, &no_bgp_graceful_restart_cmd);
12441 install_element(BGP_NODE, &bgp_graceful_restart_stalepath_time_cmd);
12442 install_element(BGP_NODE, &no_bgp_graceful_restart_stalepath_time_cmd);
12443 install_element(BGP_NODE, &bgp_graceful_restart_restart_time_cmd);
12444 install_element(BGP_NODE, &no_bgp_graceful_restart_restart_time_cmd);
12445
12446 install_element(BGP_NODE, &bgp_graceful_restart_preserve_fw_cmd);
12447 install_element(BGP_NODE, &no_bgp_graceful_restart_preserve_fw_cmd);
12448
12449 /* "bgp graceful-shutdown" commands */
12450 install_element(BGP_NODE, &bgp_graceful_shutdown_cmd);
12451 install_element(BGP_NODE, &no_bgp_graceful_shutdown_cmd);
12452
12453 /* "bgp fast-external-failover" commands */
12454 install_element(BGP_NODE, &bgp_fast_external_failover_cmd);
12455 install_element(BGP_NODE, &no_bgp_fast_external_failover_cmd);
12456
12457 /* "bgp enforce-first-as" commands */
12458 install_element(BGP_NODE, &bgp_enforce_first_as_cmd);
12459
12460 /* "bgp bestpath compare-routerid" commands */
12461 install_element(BGP_NODE, &bgp_bestpath_compare_router_id_cmd);
12462 install_element(BGP_NODE, &no_bgp_bestpath_compare_router_id_cmd);
12463
12464 /* "bgp bestpath as-path ignore" commands */
12465 install_element(BGP_NODE, &bgp_bestpath_aspath_ignore_cmd);
12466 install_element(BGP_NODE, &no_bgp_bestpath_aspath_ignore_cmd);
12467
12468 /* "bgp bestpath as-path confed" commands */
12469 install_element(BGP_NODE, &bgp_bestpath_aspath_confed_cmd);
12470 install_element(BGP_NODE, &no_bgp_bestpath_aspath_confed_cmd);
12471
12472 /* "bgp bestpath as-path multipath-relax" commands */
12473 install_element(BGP_NODE, &bgp_bestpath_aspath_multipath_relax_cmd);
12474 install_element(BGP_NODE, &no_bgp_bestpath_aspath_multipath_relax_cmd);
12475
12476 /* "bgp log-neighbor-changes" commands */
12477 install_element(BGP_NODE, &bgp_log_neighbor_changes_cmd);
12478 install_element(BGP_NODE, &no_bgp_log_neighbor_changes_cmd);
12479
12480 /* "bgp bestpath med" commands */
12481 install_element(BGP_NODE, &bgp_bestpath_med_cmd);
12482 install_element(BGP_NODE, &no_bgp_bestpath_med_cmd);
12483
12484 /* "no bgp default ipv4-unicast" commands. */
12485 install_element(BGP_NODE, &no_bgp_default_ipv4_unicast_cmd);
12486 install_element(BGP_NODE, &bgp_default_ipv4_unicast_cmd);
12487
12488 /* "bgp network import-check" commands. */
12489 install_element(BGP_NODE, &bgp_network_import_check_cmd);
12490 install_element(BGP_NODE, &bgp_network_import_check_exact_cmd);
12491 install_element(BGP_NODE, &no_bgp_network_import_check_cmd);
12492
12493 /* "bgp default local-preference" commands. */
12494 install_element(BGP_NODE, &bgp_default_local_preference_cmd);
12495 install_element(BGP_NODE, &no_bgp_default_local_preference_cmd);
12496
12497 /* bgp default show-hostname */
12498 install_element(BGP_NODE, &bgp_default_show_hostname_cmd);
12499 install_element(BGP_NODE, &no_bgp_default_show_hostname_cmd);
12500
12501 /* "bgp default subgroup-pkt-queue-max" commands. */
12502 install_element(BGP_NODE, &bgp_default_subgroup_pkt_queue_max_cmd);
12503 install_element(BGP_NODE, &no_bgp_default_subgroup_pkt_queue_max_cmd);
12504
12505 /* bgp ibgp-allow-policy-mods command */
12506 install_element(BGP_NODE, &bgp_rr_allow_outbound_policy_cmd);
12507 install_element(BGP_NODE, &no_bgp_rr_allow_outbound_policy_cmd);
12508
12509 /* "bgp listen limit" commands. */
12510 install_element(BGP_NODE, &bgp_listen_limit_cmd);
12511 install_element(BGP_NODE, &no_bgp_listen_limit_cmd);
12512
12513 /* "bgp listen range" commands. */
12514 install_element(BGP_NODE, &bgp_listen_range_cmd);
12515 install_element(BGP_NODE, &no_bgp_listen_range_cmd);
12516
12517 /* "bgp default shutdown" command */
12518 install_element(BGP_NODE, &bgp_default_shutdown_cmd);
12519
12520 /* "neighbor remote-as" commands. */
12521 install_element(BGP_NODE, &neighbor_remote_as_cmd);
12522 install_element(BGP_NODE, &neighbor_interface_config_cmd);
12523 install_element(BGP_NODE, &neighbor_interface_config_v6only_cmd);
12524 install_element(BGP_NODE, &neighbor_interface_config_remote_as_cmd);
12525 install_element(BGP_NODE,
12526 &neighbor_interface_v6only_config_remote_as_cmd);
12527 install_element(BGP_NODE, &no_neighbor_cmd);
12528 install_element(BGP_NODE, &no_neighbor_interface_config_cmd);
12529
12530 /* "neighbor peer-group" commands. */
12531 install_element(BGP_NODE, &neighbor_peer_group_cmd);
12532 install_element(BGP_NODE, &no_neighbor_peer_group_cmd);
12533 install_element(BGP_NODE,
12534 &no_neighbor_interface_peer_group_remote_as_cmd);
12535
12536 /* "neighbor local-as" commands. */
12537 install_element(BGP_NODE, &neighbor_local_as_cmd);
12538 install_element(BGP_NODE, &neighbor_local_as_no_prepend_cmd);
12539 install_element(BGP_NODE, &neighbor_local_as_no_prepend_replace_as_cmd);
12540 install_element(BGP_NODE, &no_neighbor_local_as_cmd);
12541
12542 /* "neighbor solo" commands. */
12543 install_element(BGP_NODE, &neighbor_solo_cmd);
12544 install_element(BGP_NODE, &no_neighbor_solo_cmd);
12545
12546 /* "neighbor password" commands. */
12547 install_element(BGP_NODE, &neighbor_password_cmd);
12548 install_element(BGP_NODE, &no_neighbor_password_cmd);
12549
12550 /* "neighbor activate" commands. */
12551 install_element(BGP_NODE, &neighbor_activate_hidden_cmd);
12552 install_element(BGP_IPV4_NODE, &neighbor_activate_cmd);
12553 install_element(BGP_IPV4M_NODE, &neighbor_activate_cmd);
12554 install_element(BGP_IPV4L_NODE, &neighbor_activate_cmd);
12555 install_element(BGP_IPV6_NODE, &neighbor_activate_cmd);
12556 install_element(BGP_IPV6M_NODE, &neighbor_activate_cmd);
12557 install_element(BGP_IPV6L_NODE, &neighbor_activate_cmd);
12558 install_element(BGP_VPNV4_NODE, &neighbor_activate_cmd);
12559 install_element(BGP_VPNV6_NODE, &neighbor_activate_cmd);
12560 install_element(BGP_FLOWSPECV4_NODE, &neighbor_activate_cmd);
12561 install_element(BGP_FLOWSPECV6_NODE, &neighbor_activate_cmd);
12562 install_element(BGP_EVPN_NODE, &neighbor_activate_cmd);
12563
12564 /* "no neighbor activate" commands. */
12565 install_element(BGP_NODE, &no_neighbor_activate_hidden_cmd);
12566 install_element(BGP_IPV4_NODE, &no_neighbor_activate_cmd);
12567 install_element(BGP_IPV4M_NODE, &no_neighbor_activate_cmd);
12568 install_element(BGP_IPV4L_NODE, &no_neighbor_activate_cmd);
12569 install_element(BGP_IPV6_NODE, &no_neighbor_activate_cmd);
12570 install_element(BGP_IPV6M_NODE, &no_neighbor_activate_cmd);
12571 install_element(BGP_IPV6L_NODE, &no_neighbor_activate_cmd);
12572 install_element(BGP_VPNV4_NODE, &no_neighbor_activate_cmd);
12573 install_element(BGP_VPNV6_NODE, &no_neighbor_activate_cmd);
12574 install_element(BGP_FLOWSPECV4_NODE, &no_neighbor_activate_cmd);
12575 install_element(BGP_FLOWSPECV6_NODE, &no_neighbor_activate_cmd);
12576 install_element(BGP_EVPN_NODE, &no_neighbor_activate_cmd);
12577
12578 /* "neighbor peer-group" set commands. */
12579 install_element(BGP_NODE, &neighbor_set_peer_group_cmd);
12580 install_element(BGP_IPV4_NODE, &neighbor_set_peer_group_hidden_cmd);
12581 install_element(BGP_IPV4M_NODE, &neighbor_set_peer_group_hidden_cmd);
12582 install_element(BGP_IPV6_NODE, &neighbor_set_peer_group_hidden_cmd);
12583 install_element(BGP_IPV6M_NODE, &neighbor_set_peer_group_hidden_cmd);
12584 install_element(BGP_IPV6L_NODE, &neighbor_set_peer_group_hidden_cmd);
12585 install_element(BGP_VPNV4_NODE, &neighbor_set_peer_group_hidden_cmd);
12586 install_element(BGP_VPNV6_NODE, &neighbor_set_peer_group_hidden_cmd);
12587 install_element(BGP_FLOWSPECV4_NODE,
12588 &neighbor_set_peer_group_hidden_cmd);
12589 install_element(BGP_FLOWSPECV6_NODE,
12590 &neighbor_set_peer_group_hidden_cmd);
12591
12592 /* "no neighbor peer-group unset" commands. */
12593 install_element(BGP_NODE, &no_neighbor_set_peer_group_cmd);
12594 install_element(BGP_IPV4_NODE, &no_neighbor_set_peer_group_hidden_cmd);
12595 install_element(BGP_IPV4M_NODE, &no_neighbor_set_peer_group_hidden_cmd);
12596 install_element(BGP_IPV6_NODE, &no_neighbor_set_peer_group_hidden_cmd);
12597 install_element(BGP_IPV6M_NODE, &no_neighbor_set_peer_group_hidden_cmd);
12598 install_element(BGP_IPV6L_NODE, &no_neighbor_set_peer_group_hidden_cmd);
12599 install_element(BGP_VPNV4_NODE, &no_neighbor_set_peer_group_hidden_cmd);
12600 install_element(BGP_VPNV6_NODE, &no_neighbor_set_peer_group_hidden_cmd);
12601 install_element(BGP_FLOWSPECV4_NODE,
12602 &no_neighbor_set_peer_group_hidden_cmd);
12603 install_element(BGP_FLOWSPECV6_NODE,
12604 &no_neighbor_set_peer_group_hidden_cmd);
12605
12606 /* "neighbor softreconfiguration inbound" commands.*/
12607 install_element(BGP_NODE, &neighbor_soft_reconfiguration_hidden_cmd);
12608 install_element(BGP_NODE, &no_neighbor_soft_reconfiguration_hidden_cmd);
12609 install_element(BGP_IPV4_NODE, &neighbor_soft_reconfiguration_cmd);
12610 install_element(BGP_IPV4_NODE, &no_neighbor_soft_reconfiguration_cmd);
12611 install_element(BGP_IPV4L_NODE, &neighbor_soft_reconfiguration_cmd);
12612 install_element(BGP_IPV4L_NODE, &no_neighbor_soft_reconfiguration_cmd);
12613 install_element(BGP_IPV4M_NODE, &neighbor_soft_reconfiguration_cmd);
12614 install_element(BGP_IPV4M_NODE, &no_neighbor_soft_reconfiguration_cmd);
12615 install_element(BGP_IPV6_NODE, &neighbor_soft_reconfiguration_cmd);
12616 install_element(BGP_IPV6_NODE, &no_neighbor_soft_reconfiguration_cmd);
12617 install_element(BGP_IPV6M_NODE, &neighbor_soft_reconfiguration_cmd);
12618 install_element(BGP_IPV6M_NODE, &no_neighbor_soft_reconfiguration_cmd);
12619 install_element(BGP_IPV6L_NODE, &neighbor_soft_reconfiguration_cmd);
12620 install_element(BGP_IPV6L_NODE, &no_neighbor_soft_reconfiguration_cmd);
12621 install_element(BGP_VPNV4_NODE, &neighbor_soft_reconfiguration_cmd);
12622 install_element(BGP_VPNV4_NODE, &no_neighbor_soft_reconfiguration_cmd);
12623 install_element(BGP_VPNV6_NODE, &neighbor_soft_reconfiguration_cmd);
12624 install_element(BGP_VPNV6_NODE, &no_neighbor_soft_reconfiguration_cmd);
12625 install_element(BGP_FLOWSPECV4_NODE,
12626 &neighbor_soft_reconfiguration_cmd);
12627 install_element(BGP_FLOWSPECV4_NODE,
12628 &no_neighbor_soft_reconfiguration_cmd);
12629 install_element(BGP_FLOWSPECV6_NODE,
12630 &neighbor_soft_reconfiguration_cmd);
12631 install_element(BGP_FLOWSPECV6_NODE,
12632 &no_neighbor_soft_reconfiguration_cmd);
12633
12634 /* "neighbor attribute-unchanged" commands. */
12635 install_element(BGP_NODE, &neighbor_attr_unchanged_hidden_cmd);
12636 install_element(BGP_NODE, &no_neighbor_attr_unchanged_hidden_cmd);
12637 install_element(BGP_IPV4_NODE, &neighbor_attr_unchanged_cmd);
12638 install_element(BGP_IPV4_NODE, &no_neighbor_attr_unchanged_cmd);
12639 install_element(BGP_IPV4M_NODE, &neighbor_attr_unchanged_cmd);
12640 install_element(BGP_IPV4M_NODE, &no_neighbor_attr_unchanged_cmd);
12641 install_element(BGP_IPV4L_NODE, &neighbor_attr_unchanged_cmd);
12642 install_element(BGP_IPV4L_NODE, &no_neighbor_attr_unchanged_cmd);
12643 install_element(BGP_IPV6_NODE, &neighbor_attr_unchanged_cmd);
12644 install_element(BGP_IPV6_NODE, &no_neighbor_attr_unchanged_cmd);
12645 install_element(BGP_IPV6M_NODE, &neighbor_attr_unchanged_cmd);
12646 install_element(BGP_IPV6M_NODE, &no_neighbor_attr_unchanged_cmd);
12647 install_element(BGP_IPV6L_NODE, &neighbor_attr_unchanged_cmd);
12648 install_element(BGP_IPV6L_NODE, &no_neighbor_attr_unchanged_cmd);
12649 install_element(BGP_VPNV4_NODE, &neighbor_attr_unchanged_cmd);
12650 install_element(BGP_VPNV4_NODE, &no_neighbor_attr_unchanged_cmd);
12651 install_element(BGP_VPNV6_NODE, &neighbor_attr_unchanged_cmd);
12652 install_element(BGP_VPNV6_NODE, &no_neighbor_attr_unchanged_cmd);
12653
12654 install_element(BGP_EVPN_NODE, &neighbor_attr_unchanged_cmd);
12655 install_element(BGP_EVPN_NODE, &no_neighbor_attr_unchanged_cmd);
12656
12657 /* "nexthop-local unchanged" commands */
12658 install_element(BGP_IPV6_NODE, &neighbor_nexthop_local_unchanged_cmd);
12659 install_element(BGP_IPV6_NODE,
12660 &no_neighbor_nexthop_local_unchanged_cmd);
12661
12662 /* "neighbor next-hop-self" commands. */
12663 install_element(BGP_NODE, &neighbor_nexthop_self_hidden_cmd);
12664 install_element(BGP_NODE, &no_neighbor_nexthop_self_hidden_cmd);
12665 install_element(BGP_IPV4_NODE, &neighbor_nexthop_self_cmd);
12666 install_element(BGP_IPV4_NODE, &no_neighbor_nexthop_self_cmd);
12667 install_element(BGP_IPV4M_NODE, &neighbor_nexthop_self_cmd);
12668 install_element(BGP_IPV4M_NODE, &no_neighbor_nexthop_self_cmd);
12669 install_element(BGP_IPV4L_NODE, &neighbor_nexthop_self_cmd);
12670 install_element(BGP_IPV4L_NODE, &no_neighbor_nexthop_self_cmd);
12671 install_element(BGP_IPV6_NODE, &neighbor_nexthop_self_cmd);
12672 install_element(BGP_IPV6_NODE, &no_neighbor_nexthop_self_cmd);
12673 install_element(BGP_IPV6M_NODE, &neighbor_nexthop_self_cmd);
12674 install_element(BGP_IPV6M_NODE, &no_neighbor_nexthop_self_cmd);
12675 install_element(BGP_IPV6L_NODE, &neighbor_nexthop_self_cmd);
12676 install_element(BGP_IPV6L_NODE, &no_neighbor_nexthop_self_cmd);
12677 install_element(BGP_VPNV4_NODE, &neighbor_nexthop_self_cmd);
12678 install_element(BGP_VPNV4_NODE, &no_neighbor_nexthop_self_cmd);
12679 install_element(BGP_VPNV6_NODE, &neighbor_nexthop_self_cmd);
12680 install_element(BGP_VPNV6_NODE, &no_neighbor_nexthop_self_cmd);
12681 install_element(BGP_EVPN_NODE, &neighbor_nexthop_self_cmd);
12682 install_element(BGP_EVPN_NODE, &no_neighbor_nexthop_self_cmd);
12683
12684 /* "neighbor next-hop-self force" commands. */
12685 install_element(BGP_NODE, &neighbor_nexthop_self_force_hidden_cmd);
12686 install_element(BGP_NODE, &no_neighbor_nexthop_self_force_hidden_cmd);
12687 install_element(BGP_IPV4_NODE, &neighbor_nexthop_self_force_cmd);
12688 install_element(BGP_IPV4_NODE, &no_neighbor_nexthop_self_force_cmd);
12689 install_element(BGP_IPV4M_NODE, &neighbor_nexthop_self_force_cmd);
12690 install_element(BGP_IPV4M_NODE, &no_neighbor_nexthop_self_force_cmd);
12691 install_element(BGP_IPV4L_NODE, &neighbor_nexthop_self_force_cmd);
12692 install_element(BGP_IPV4L_NODE, &no_neighbor_nexthop_self_force_cmd);
12693 install_element(BGP_IPV6_NODE, &neighbor_nexthop_self_force_cmd);
12694 install_element(BGP_IPV6_NODE, &no_neighbor_nexthop_self_force_cmd);
12695 install_element(BGP_IPV6M_NODE, &neighbor_nexthop_self_force_cmd);
12696 install_element(BGP_IPV6M_NODE, &no_neighbor_nexthop_self_force_cmd);
12697 install_element(BGP_IPV6L_NODE, &neighbor_nexthop_self_force_cmd);
12698 install_element(BGP_IPV6L_NODE, &no_neighbor_nexthop_self_force_cmd);
12699 install_element(BGP_VPNV4_NODE, &neighbor_nexthop_self_force_cmd);
12700 install_element(BGP_VPNV4_NODE, &no_neighbor_nexthop_self_force_cmd);
12701 install_element(BGP_VPNV6_NODE, &neighbor_nexthop_self_force_cmd);
12702 install_element(BGP_VPNV6_NODE, &no_neighbor_nexthop_self_force_cmd);
12703
12704 /* "neighbor as-override" commands. */
12705 install_element(BGP_NODE, &neighbor_as_override_hidden_cmd);
12706 install_element(BGP_NODE, &no_neighbor_as_override_hidden_cmd);
12707 install_element(BGP_IPV4_NODE, &neighbor_as_override_cmd);
12708 install_element(BGP_IPV4_NODE, &no_neighbor_as_override_cmd);
12709 install_element(BGP_IPV4M_NODE, &neighbor_as_override_cmd);
12710 install_element(BGP_IPV4M_NODE, &no_neighbor_as_override_cmd);
12711 install_element(BGP_IPV4L_NODE, &neighbor_as_override_cmd);
12712 install_element(BGP_IPV4L_NODE, &no_neighbor_as_override_cmd);
12713 install_element(BGP_IPV6_NODE, &neighbor_as_override_cmd);
12714 install_element(BGP_IPV6_NODE, &no_neighbor_as_override_cmd);
12715 install_element(BGP_IPV6M_NODE, &neighbor_as_override_cmd);
12716 install_element(BGP_IPV6M_NODE, &no_neighbor_as_override_cmd);
12717 install_element(BGP_IPV6L_NODE, &neighbor_as_override_cmd);
12718 install_element(BGP_IPV6L_NODE, &no_neighbor_as_override_cmd);
12719 install_element(BGP_VPNV4_NODE, &neighbor_as_override_cmd);
12720 install_element(BGP_VPNV4_NODE, &no_neighbor_as_override_cmd);
12721 install_element(BGP_VPNV6_NODE, &neighbor_as_override_cmd);
12722 install_element(BGP_VPNV6_NODE, &no_neighbor_as_override_cmd);
12723
12724 /* "neighbor remove-private-AS" commands. */
12725 install_element(BGP_NODE, &neighbor_remove_private_as_hidden_cmd);
12726 install_element(BGP_NODE, &no_neighbor_remove_private_as_hidden_cmd);
12727 install_element(BGP_NODE, &neighbor_remove_private_as_all_hidden_cmd);
12728 install_element(BGP_NODE,
12729 &no_neighbor_remove_private_as_all_hidden_cmd);
12730 install_element(BGP_NODE,
12731 &neighbor_remove_private_as_replace_as_hidden_cmd);
12732 install_element(BGP_NODE,
12733 &no_neighbor_remove_private_as_replace_as_hidden_cmd);
12734 install_element(BGP_NODE,
12735 &neighbor_remove_private_as_all_replace_as_hidden_cmd);
12736 install_element(
12737 BGP_NODE,
12738 &no_neighbor_remove_private_as_all_replace_as_hidden_cmd);
12739 install_element(BGP_IPV4_NODE, &neighbor_remove_private_as_cmd);
12740 install_element(BGP_IPV4_NODE, &no_neighbor_remove_private_as_cmd);
12741 install_element(BGP_IPV4_NODE, &neighbor_remove_private_as_all_cmd);
12742 install_element(BGP_IPV4_NODE, &no_neighbor_remove_private_as_all_cmd);
12743 install_element(BGP_IPV4_NODE,
12744 &neighbor_remove_private_as_replace_as_cmd);
12745 install_element(BGP_IPV4_NODE,
12746 &no_neighbor_remove_private_as_replace_as_cmd);
12747 install_element(BGP_IPV4_NODE,
12748 &neighbor_remove_private_as_all_replace_as_cmd);
12749 install_element(BGP_IPV4_NODE,
12750 &no_neighbor_remove_private_as_all_replace_as_cmd);
12751 install_element(BGP_IPV4M_NODE, &neighbor_remove_private_as_cmd);
12752 install_element(BGP_IPV4M_NODE, &no_neighbor_remove_private_as_cmd);
12753 install_element(BGP_IPV4M_NODE, &neighbor_remove_private_as_all_cmd);
12754 install_element(BGP_IPV4M_NODE, &no_neighbor_remove_private_as_all_cmd);
12755 install_element(BGP_IPV4M_NODE,
12756 &neighbor_remove_private_as_replace_as_cmd);
12757 install_element(BGP_IPV4M_NODE,
12758 &no_neighbor_remove_private_as_replace_as_cmd);
12759 install_element(BGP_IPV4M_NODE,
12760 &neighbor_remove_private_as_all_replace_as_cmd);
12761 install_element(BGP_IPV4M_NODE,
12762 &no_neighbor_remove_private_as_all_replace_as_cmd);
12763 install_element(BGP_IPV4L_NODE, &neighbor_remove_private_as_cmd);
12764 install_element(BGP_IPV4L_NODE, &no_neighbor_remove_private_as_cmd);
12765 install_element(BGP_IPV4L_NODE, &neighbor_remove_private_as_all_cmd);
12766 install_element(BGP_IPV4L_NODE, &no_neighbor_remove_private_as_all_cmd);
12767 install_element(BGP_IPV4L_NODE,
12768 &neighbor_remove_private_as_replace_as_cmd);
12769 install_element(BGP_IPV4L_NODE,
12770 &no_neighbor_remove_private_as_replace_as_cmd);
12771 install_element(BGP_IPV4L_NODE,
12772 &neighbor_remove_private_as_all_replace_as_cmd);
12773 install_element(BGP_IPV4L_NODE,
12774 &no_neighbor_remove_private_as_all_replace_as_cmd);
12775 install_element(BGP_IPV6_NODE, &neighbor_remove_private_as_cmd);
12776 install_element(BGP_IPV6_NODE, &no_neighbor_remove_private_as_cmd);
12777 install_element(BGP_IPV6_NODE, &neighbor_remove_private_as_all_cmd);
12778 install_element(BGP_IPV6_NODE, &no_neighbor_remove_private_as_all_cmd);
12779 install_element(BGP_IPV6_NODE,
12780 &neighbor_remove_private_as_replace_as_cmd);
12781 install_element(BGP_IPV6_NODE,
12782 &no_neighbor_remove_private_as_replace_as_cmd);
12783 install_element(BGP_IPV6_NODE,
12784 &neighbor_remove_private_as_all_replace_as_cmd);
12785 install_element(BGP_IPV6_NODE,
12786 &no_neighbor_remove_private_as_all_replace_as_cmd);
12787 install_element(BGP_IPV6M_NODE, &neighbor_remove_private_as_cmd);
12788 install_element(BGP_IPV6M_NODE, &no_neighbor_remove_private_as_cmd);
12789 install_element(BGP_IPV6M_NODE, &neighbor_remove_private_as_all_cmd);
12790 install_element(BGP_IPV6M_NODE, &no_neighbor_remove_private_as_all_cmd);
12791 install_element(BGP_IPV6M_NODE,
12792 &neighbor_remove_private_as_replace_as_cmd);
12793 install_element(BGP_IPV6M_NODE,
12794 &no_neighbor_remove_private_as_replace_as_cmd);
12795 install_element(BGP_IPV6M_NODE,
12796 &neighbor_remove_private_as_all_replace_as_cmd);
12797 install_element(BGP_IPV6M_NODE,
12798 &no_neighbor_remove_private_as_all_replace_as_cmd);
12799 install_element(BGP_IPV6L_NODE, &neighbor_remove_private_as_cmd);
12800 install_element(BGP_IPV6L_NODE, &no_neighbor_remove_private_as_cmd);
12801 install_element(BGP_IPV6L_NODE, &neighbor_remove_private_as_all_cmd);
12802 install_element(BGP_IPV6L_NODE, &no_neighbor_remove_private_as_all_cmd);
12803 install_element(BGP_IPV6L_NODE,
12804 &neighbor_remove_private_as_replace_as_cmd);
12805 install_element(BGP_IPV6L_NODE,
12806 &no_neighbor_remove_private_as_replace_as_cmd);
12807 install_element(BGP_IPV6L_NODE,
12808 &neighbor_remove_private_as_all_replace_as_cmd);
12809 install_element(BGP_IPV6L_NODE,
12810 &no_neighbor_remove_private_as_all_replace_as_cmd);
12811 install_element(BGP_VPNV4_NODE, &neighbor_remove_private_as_cmd);
12812 install_element(BGP_VPNV4_NODE, &no_neighbor_remove_private_as_cmd);
12813 install_element(BGP_VPNV4_NODE, &neighbor_remove_private_as_all_cmd);
12814 install_element(BGP_VPNV4_NODE, &no_neighbor_remove_private_as_all_cmd);
12815 install_element(BGP_VPNV4_NODE,
12816 &neighbor_remove_private_as_replace_as_cmd);
12817 install_element(BGP_VPNV4_NODE,
12818 &no_neighbor_remove_private_as_replace_as_cmd);
12819 install_element(BGP_VPNV4_NODE,
12820 &neighbor_remove_private_as_all_replace_as_cmd);
12821 install_element(BGP_VPNV4_NODE,
12822 &no_neighbor_remove_private_as_all_replace_as_cmd);
12823 install_element(BGP_VPNV6_NODE, &neighbor_remove_private_as_cmd);
12824 install_element(BGP_VPNV6_NODE, &no_neighbor_remove_private_as_cmd);
12825 install_element(BGP_VPNV6_NODE, &neighbor_remove_private_as_all_cmd);
12826 install_element(BGP_VPNV6_NODE, &no_neighbor_remove_private_as_all_cmd);
12827 install_element(BGP_VPNV6_NODE,
12828 &neighbor_remove_private_as_replace_as_cmd);
12829 install_element(BGP_VPNV6_NODE,
12830 &no_neighbor_remove_private_as_replace_as_cmd);
12831 install_element(BGP_VPNV6_NODE,
12832 &neighbor_remove_private_as_all_replace_as_cmd);
12833 install_element(BGP_VPNV6_NODE,
12834 &no_neighbor_remove_private_as_all_replace_as_cmd);
12835
12836 /* "neighbor send-community" commands.*/
12837 install_element(BGP_NODE, &neighbor_send_community_hidden_cmd);
12838 install_element(BGP_NODE, &neighbor_send_community_type_hidden_cmd);
12839 install_element(BGP_NODE, &no_neighbor_send_community_hidden_cmd);
12840 install_element(BGP_NODE, &no_neighbor_send_community_type_hidden_cmd);
12841 install_element(BGP_IPV4_NODE, &neighbor_send_community_cmd);
12842 install_element(BGP_IPV4_NODE, &neighbor_send_community_type_cmd);
12843 install_element(BGP_IPV4_NODE, &no_neighbor_send_community_cmd);
12844 install_element(BGP_IPV4_NODE, &no_neighbor_send_community_type_cmd);
12845 install_element(BGP_IPV4M_NODE, &neighbor_send_community_cmd);
12846 install_element(BGP_IPV4M_NODE, &neighbor_send_community_type_cmd);
12847 install_element(BGP_IPV4M_NODE, &no_neighbor_send_community_cmd);
12848 install_element(BGP_IPV4M_NODE, &no_neighbor_send_community_type_cmd);
12849 install_element(BGP_IPV4L_NODE, &neighbor_send_community_cmd);
12850 install_element(BGP_IPV4L_NODE, &neighbor_send_community_type_cmd);
12851 install_element(BGP_IPV4L_NODE, &no_neighbor_send_community_cmd);
12852 install_element(BGP_IPV4L_NODE, &no_neighbor_send_community_type_cmd);
12853 install_element(BGP_IPV6_NODE, &neighbor_send_community_cmd);
12854 install_element(BGP_IPV6_NODE, &neighbor_send_community_type_cmd);
12855 install_element(BGP_IPV6_NODE, &no_neighbor_send_community_cmd);
12856 install_element(BGP_IPV6_NODE, &no_neighbor_send_community_type_cmd);
12857 install_element(BGP_IPV6M_NODE, &neighbor_send_community_cmd);
12858 install_element(BGP_IPV6M_NODE, &neighbor_send_community_type_cmd);
12859 install_element(BGP_IPV6M_NODE, &no_neighbor_send_community_cmd);
12860 install_element(BGP_IPV6M_NODE, &no_neighbor_send_community_type_cmd);
12861 install_element(BGP_IPV6L_NODE, &neighbor_send_community_cmd);
12862 install_element(BGP_IPV6L_NODE, &neighbor_send_community_type_cmd);
12863 install_element(BGP_IPV6L_NODE, &no_neighbor_send_community_cmd);
12864 install_element(BGP_IPV6L_NODE, &no_neighbor_send_community_type_cmd);
12865 install_element(BGP_VPNV4_NODE, &neighbor_send_community_cmd);
12866 install_element(BGP_VPNV4_NODE, &neighbor_send_community_type_cmd);
12867 install_element(BGP_VPNV4_NODE, &no_neighbor_send_community_cmd);
12868 install_element(BGP_VPNV4_NODE, &no_neighbor_send_community_type_cmd);
12869 install_element(BGP_VPNV6_NODE, &neighbor_send_community_cmd);
12870 install_element(BGP_VPNV6_NODE, &neighbor_send_community_type_cmd);
12871 install_element(BGP_VPNV6_NODE, &no_neighbor_send_community_cmd);
12872 install_element(BGP_VPNV6_NODE, &no_neighbor_send_community_type_cmd);
12873
12874 /* "neighbor route-reflector" commands.*/
12875 install_element(BGP_NODE, &neighbor_route_reflector_client_hidden_cmd);
12876 install_element(BGP_NODE,
12877 &no_neighbor_route_reflector_client_hidden_cmd);
12878 install_element(BGP_IPV4_NODE, &neighbor_route_reflector_client_cmd);
12879 install_element(BGP_IPV4_NODE, &no_neighbor_route_reflector_client_cmd);
12880 install_element(BGP_IPV4M_NODE, &neighbor_route_reflector_client_cmd);
12881 install_element(BGP_IPV4M_NODE,
12882 &no_neighbor_route_reflector_client_cmd);
12883 install_element(BGP_IPV4L_NODE, &neighbor_route_reflector_client_cmd);
12884 install_element(BGP_IPV4L_NODE,
12885 &no_neighbor_route_reflector_client_cmd);
12886 install_element(BGP_IPV6_NODE, &neighbor_route_reflector_client_cmd);
12887 install_element(BGP_IPV6_NODE, &no_neighbor_route_reflector_client_cmd);
12888 install_element(BGP_IPV6M_NODE, &neighbor_route_reflector_client_cmd);
12889 install_element(BGP_IPV6M_NODE,
12890 &no_neighbor_route_reflector_client_cmd);
12891 install_element(BGP_IPV6L_NODE, &neighbor_route_reflector_client_cmd);
12892 install_element(BGP_IPV6L_NODE,
12893 &no_neighbor_route_reflector_client_cmd);
12894 install_element(BGP_VPNV4_NODE, &neighbor_route_reflector_client_cmd);
12895 install_element(BGP_VPNV4_NODE,
12896 &no_neighbor_route_reflector_client_cmd);
12897 install_element(BGP_VPNV6_NODE, &neighbor_route_reflector_client_cmd);
12898 install_element(BGP_VPNV6_NODE,
12899 &no_neighbor_route_reflector_client_cmd);
12900 install_element(BGP_FLOWSPECV4_NODE,
12901 &neighbor_route_reflector_client_cmd);
12902 install_element(BGP_FLOWSPECV4_NODE,
12903 &no_neighbor_route_reflector_client_cmd);
12904 install_element(BGP_FLOWSPECV6_NODE,
12905 &neighbor_route_reflector_client_cmd);
12906 install_element(BGP_FLOWSPECV6_NODE,
12907 &no_neighbor_route_reflector_client_cmd);
12908 install_element(BGP_EVPN_NODE, &neighbor_route_reflector_client_cmd);
12909 install_element(BGP_EVPN_NODE, &no_neighbor_route_reflector_client_cmd);
12910
12911 /* "neighbor route-server" commands.*/
12912 install_element(BGP_NODE, &neighbor_route_server_client_hidden_cmd);
12913 install_element(BGP_NODE, &no_neighbor_route_server_client_hidden_cmd);
12914 install_element(BGP_IPV4_NODE, &neighbor_route_server_client_cmd);
12915 install_element(BGP_IPV4_NODE, &no_neighbor_route_server_client_cmd);
12916 install_element(BGP_IPV4M_NODE, &neighbor_route_server_client_cmd);
12917 install_element(BGP_IPV4M_NODE, &no_neighbor_route_server_client_cmd);
12918 install_element(BGP_IPV4L_NODE, &neighbor_route_server_client_cmd);
12919 install_element(BGP_IPV4L_NODE, &no_neighbor_route_server_client_cmd);
12920 install_element(BGP_IPV6_NODE, &neighbor_route_server_client_cmd);
12921 install_element(BGP_IPV6_NODE, &no_neighbor_route_server_client_cmd);
12922 install_element(BGP_IPV6M_NODE, &neighbor_route_server_client_cmd);
12923 install_element(BGP_IPV6M_NODE, &no_neighbor_route_server_client_cmd);
12924 install_element(BGP_IPV6L_NODE, &neighbor_route_server_client_cmd);
12925 install_element(BGP_IPV6L_NODE, &no_neighbor_route_server_client_cmd);
12926 install_element(BGP_VPNV4_NODE, &neighbor_route_server_client_cmd);
12927 install_element(BGP_VPNV4_NODE, &no_neighbor_route_server_client_cmd);
12928 install_element(BGP_VPNV6_NODE, &neighbor_route_server_client_cmd);
12929 install_element(BGP_VPNV6_NODE, &no_neighbor_route_server_client_cmd);
12930 install_element(BGP_FLOWSPECV4_NODE, &neighbor_route_server_client_cmd);
12931 install_element(BGP_FLOWSPECV4_NODE,
12932 &no_neighbor_route_server_client_cmd);
12933 install_element(BGP_FLOWSPECV6_NODE, &neighbor_route_server_client_cmd);
12934 install_element(BGP_FLOWSPECV6_NODE,
12935 &no_neighbor_route_server_client_cmd);
12936
12937 /* "neighbor addpath-tx-all-paths" commands.*/
12938 install_element(BGP_NODE, &neighbor_addpath_tx_all_paths_hidden_cmd);
12939 install_element(BGP_NODE, &no_neighbor_addpath_tx_all_paths_hidden_cmd);
12940 install_element(BGP_IPV4_NODE, &neighbor_addpath_tx_all_paths_cmd);
12941 install_element(BGP_IPV4_NODE, &no_neighbor_addpath_tx_all_paths_cmd);
12942 install_element(BGP_IPV4M_NODE, &neighbor_addpath_tx_all_paths_cmd);
12943 install_element(BGP_IPV4M_NODE, &no_neighbor_addpath_tx_all_paths_cmd);
12944 install_element(BGP_IPV4L_NODE, &neighbor_addpath_tx_all_paths_cmd);
12945 install_element(BGP_IPV4L_NODE, &no_neighbor_addpath_tx_all_paths_cmd);
12946 install_element(BGP_IPV6_NODE, &neighbor_addpath_tx_all_paths_cmd);
12947 install_element(BGP_IPV6_NODE, &no_neighbor_addpath_tx_all_paths_cmd);
12948 install_element(BGP_IPV6M_NODE, &neighbor_addpath_tx_all_paths_cmd);
12949 install_element(BGP_IPV6M_NODE, &no_neighbor_addpath_tx_all_paths_cmd);
12950 install_element(BGP_IPV6L_NODE, &neighbor_addpath_tx_all_paths_cmd);
12951 install_element(BGP_IPV6L_NODE, &no_neighbor_addpath_tx_all_paths_cmd);
12952 install_element(BGP_VPNV4_NODE, &neighbor_addpath_tx_all_paths_cmd);
12953 install_element(BGP_VPNV4_NODE, &no_neighbor_addpath_tx_all_paths_cmd);
12954 install_element(BGP_VPNV6_NODE, &neighbor_addpath_tx_all_paths_cmd);
12955 install_element(BGP_VPNV6_NODE, &no_neighbor_addpath_tx_all_paths_cmd);
12956
12957 /* "neighbor addpath-tx-bestpath-per-AS" commands.*/
12958 install_element(BGP_NODE,
12959 &neighbor_addpath_tx_bestpath_per_as_hidden_cmd);
12960 install_element(BGP_NODE,
12961 &no_neighbor_addpath_tx_bestpath_per_as_hidden_cmd);
12962 install_element(BGP_IPV4_NODE,
12963 &neighbor_addpath_tx_bestpath_per_as_cmd);
12964 install_element(BGP_IPV4_NODE,
12965 &no_neighbor_addpath_tx_bestpath_per_as_cmd);
12966 install_element(BGP_IPV4M_NODE,
12967 &neighbor_addpath_tx_bestpath_per_as_cmd);
12968 install_element(BGP_IPV4M_NODE,
12969 &no_neighbor_addpath_tx_bestpath_per_as_cmd);
12970 install_element(BGP_IPV4L_NODE,
12971 &neighbor_addpath_tx_bestpath_per_as_cmd);
12972 install_element(BGP_IPV4L_NODE,
12973 &no_neighbor_addpath_tx_bestpath_per_as_cmd);
12974 install_element(BGP_IPV6_NODE,
12975 &neighbor_addpath_tx_bestpath_per_as_cmd);
12976 install_element(BGP_IPV6_NODE,
12977 &no_neighbor_addpath_tx_bestpath_per_as_cmd);
12978 install_element(BGP_IPV6M_NODE,
12979 &neighbor_addpath_tx_bestpath_per_as_cmd);
12980 install_element(BGP_IPV6M_NODE,
12981 &no_neighbor_addpath_tx_bestpath_per_as_cmd);
12982 install_element(BGP_IPV6L_NODE,
12983 &neighbor_addpath_tx_bestpath_per_as_cmd);
12984 install_element(BGP_IPV6L_NODE,
12985 &no_neighbor_addpath_tx_bestpath_per_as_cmd);
12986 install_element(BGP_VPNV4_NODE,
12987 &neighbor_addpath_tx_bestpath_per_as_cmd);
12988 install_element(BGP_VPNV4_NODE,
12989 &no_neighbor_addpath_tx_bestpath_per_as_cmd);
12990 install_element(BGP_VPNV6_NODE,
12991 &neighbor_addpath_tx_bestpath_per_as_cmd);
12992 install_element(BGP_VPNV6_NODE,
12993 &no_neighbor_addpath_tx_bestpath_per_as_cmd);
12994
12995 /* "neighbor passive" commands. */
12996 install_element(BGP_NODE, &neighbor_passive_cmd);
12997 install_element(BGP_NODE, &no_neighbor_passive_cmd);
12998
12999
13000 /* "neighbor shutdown" commands. */
13001 install_element(BGP_NODE, &neighbor_shutdown_cmd);
13002 install_element(BGP_NODE, &no_neighbor_shutdown_cmd);
13003 install_element(BGP_NODE, &neighbor_shutdown_msg_cmd);
13004 install_element(BGP_NODE, &no_neighbor_shutdown_msg_cmd);
13005
13006 /* "neighbor capability extended-nexthop" commands.*/
13007 install_element(BGP_NODE, &neighbor_capability_enhe_cmd);
13008 install_element(BGP_NODE, &no_neighbor_capability_enhe_cmd);
13009
13010 /* "neighbor capability orf prefix-list" commands.*/
13011 install_element(BGP_NODE, &neighbor_capability_orf_prefix_hidden_cmd);
13012 install_element(BGP_NODE,
13013 &no_neighbor_capability_orf_prefix_hidden_cmd);
13014 install_element(BGP_IPV4_NODE, &neighbor_capability_orf_prefix_cmd);
13015 install_element(BGP_IPV4_NODE, &no_neighbor_capability_orf_prefix_cmd);
13016 install_element(BGP_IPV4M_NODE, &neighbor_capability_orf_prefix_cmd);
13017 install_element(BGP_IPV4M_NODE, &no_neighbor_capability_orf_prefix_cmd);
13018 install_element(BGP_IPV4L_NODE, &neighbor_capability_orf_prefix_cmd);
13019 install_element(BGP_IPV4L_NODE, &no_neighbor_capability_orf_prefix_cmd);
13020 install_element(BGP_IPV6_NODE, &neighbor_capability_orf_prefix_cmd);
13021 install_element(BGP_IPV6_NODE, &no_neighbor_capability_orf_prefix_cmd);
13022 install_element(BGP_IPV6M_NODE, &neighbor_capability_orf_prefix_cmd);
13023 install_element(BGP_IPV6M_NODE, &no_neighbor_capability_orf_prefix_cmd);
13024 install_element(BGP_IPV6L_NODE, &neighbor_capability_orf_prefix_cmd);
13025 install_element(BGP_IPV6L_NODE, &no_neighbor_capability_orf_prefix_cmd);
13026
13027 /* "neighbor capability dynamic" commands.*/
13028 install_element(BGP_NODE, &neighbor_capability_dynamic_cmd);
13029 install_element(BGP_NODE, &no_neighbor_capability_dynamic_cmd);
13030
13031 /* "neighbor dont-capability-negotiate" commands. */
13032 install_element(BGP_NODE, &neighbor_dont_capability_negotiate_cmd);
13033 install_element(BGP_NODE, &no_neighbor_dont_capability_negotiate_cmd);
13034
13035 /* "neighbor ebgp-multihop" commands. */
13036 install_element(BGP_NODE, &neighbor_ebgp_multihop_cmd);
13037 install_element(BGP_NODE, &neighbor_ebgp_multihop_ttl_cmd);
13038 install_element(BGP_NODE, &no_neighbor_ebgp_multihop_cmd);
13039
13040 /* "neighbor disable-connected-check" commands. */
13041 install_element(BGP_NODE, &neighbor_disable_connected_check_cmd);
13042 install_element(BGP_NODE, &no_neighbor_disable_connected_check_cmd);
13043
13044 /* "neighbor enforce-first-as" commands. */
13045 install_element(BGP_NODE, &neighbor_enforce_first_as_cmd);
13046 install_element(BGP_NODE, &no_neighbor_enforce_first_as_cmd);
13047
13048 /* "neighbor description" commands. */
13049 install_element(BGP_NODE, &neighbor_description_cmd);
13050 install_element(BGP_NODE, &no_neighbor_description_cmd);
13051 install_element(BGP_NODE, &no_neighbor_description_comment_cmd);
13052
13053 /* "neighbor update-source" commands. "*/
13054 install_element(BGP_NODE, &neighbor_update_source_cmd);
13055 install_element(BGP_NODE, &no_neighbor_update_source_cmd);
13056
13057 /* "neighbor default-originate" commands. */
13058 install_element(BGP_NODE, &neighbor_default_originate_hidden_cmd);
13059 install_element(BGP_NODE, &neighbor_default_originate_rmap_hidden_cmd);
13060 install_element(BGP_NODE, &no_neighbor_default_originate_hidden_cmd);
13061 install_element(BGP_IPV4_NODE, &neighbor_default_originate_cmd);
13062 install_element(BGP_IPV4_NODE, &neighbor_default_originate_rmap_cmd);
13063 install_element(BGP_IPV4_NODE, &no_neighbor_default_originate_cmd);
13064 install_element(BGP_IPV4M_NODE, &neighbor_default_originate_cmd);
13065 install_element(BGP_IPV4M_NODE, &neighbor_default_originate_rmap_cmd);
13066 install_element(BGP_IPV4M_NODE, &no_neighbor_default_originate_cmd);
13067 install_element(BGP_IPV4L_NODE, &neighbor_default_originate_cmd);
13068 install_element(BGP_IPV4L_NODE, &neighbor_default_originate_rmap_cmd);
13069 install_element(BGP_IPV4L_NODE, &no_neighbor_default_originate_cmd);
13070 install_element(BGP_IPV6_NODE, &neighbor_default_originate_cmd);
13071 install_element(BGP_IPV6_NODE, &neighbor_default_originate_rmap_cmd);
13072 install_element(BGP_IPV6_NODE, &no_neighbor_default_originate_cmd);
13073 install_element(BGP_IPV6M_NODE, &neighbor_default_originate_cmd);
13074 install_element(BGP_IPV6M_NODE, &neighbor_default_originate_rmap_cmd);
13075 install_element(BGP_IPV6M_NODE, &no_neighbor_default_originate_cmd);
13076 install_element(BGP_IPV6L_NODE, &neighbor_default_originate_cmd);
13077 install_element(BGP_IPV6L_NODE, &neighbor_default_originate_rmap_cmd);
13078 install_element(BGP_IPV6L_NODE, &no_neighbor_default_originate_cmd);
13079
13080 /* "neighbor port" commands. */
13081 install_element(BGP_NODE, &neighbor_port_cmd);
13082 install_element(BGP_NODE, &no_neighbor_port_cmd);
13083
13084 /* "neighbor weight" commands. */
13085 install_element(BGP_NODE, &neighbor_weight_hidden_cmd);
13086 install_element(BGP_NODE, &no_neighbor_weight_hidden_cmd);
13087
13088 install_element(BGP_IPV4_NODE, &neighbor_weight_cmd);
13089 install_element(BGP_IPV4_NODE, &no_neighbor_weight_cmd);
13090 install_element(BGP_IPV4M_NODE, &neighbor_weight_cmd);
13091 install_element(BGP_IPV4M_NODE, &no_neighbor_weight_cmd);
13092 install_element(BGP_IPV4L_NODE, &neighbor_weight_cmd);
13093 install_element(BGP_IPV4L_NODE, &no_neighbor_weight_cmd);
13094 install_element(BGP_IPV6_NODE, &neighbor_weight_cmd);
13095 install_element(BGP_IPV6_NODE, &no_neighbor_weight_cmd);
13096 install_element(BGP_IPV6M_NODE, &neighbor_weight_cmd);
13097 install_element(BGP_IPV6M_NODE, &no_neighbor_weight_cmd);
13098 install_element(BGP_IPV6L_NODE, &neighbor_weight_cmd);
13099 install_element(BGP_IPV6L_NODE, &no_neighbor_weight_cmd);
13100 install_element(BGP_VPNV4_NODE, &neighbor_weight_cmd);
13101 install_element(BGP_VPNV4_NODE, &no_neighbor_weight_cmd);
13102 install_element(BGP_VPNV6_NODE, &neighbor_weight_cmd);
13103 install_element(BGP_VPNV6_NODE, &no_neighbor_weight_cmd);
13104
13105 /* "neighbor override-capability" commands. */
13106 install_element(BGP_NODE, &neighbor_override_capability_cmd);
13107 install_element(BGP_NODE, &no_neighbor_override_capability_cmd);
13108
13109 /* "neighbor strict-capability-match" commands. */
13110 install_element(BGP_NODE, &neighbor_strict_capability_cmd);
13111 install_element(BGP_NODE, &no_neighbor_strict_capability_cmd);
13112
13113 /* "neighbor timers" commands. */
13114 install_element(BGP_NODE, &neighbor_timers_cmd);
13115 install_element(BGP_NODE, &no_neighbor_timers_cmd);
13116
13117 /* "neighbor timers connect" commands. */
13118 install_element(BGP_NODE, &neighbor_timers_connect_cmd);
13119 install_element(BGP_NODE, &no_neighbor_timers_connect_cmd);
13120
13121 /* "neighbor advertisement-interval" commands. */
13122 install_element(BGP_NODE, &neighbor_advertise_interval_cmd);
13123 install_element(BGP_NODE, &no_neighbor_advertise_interval_cmd);
13124
13125 /* "neighbor interface" commands. */
13126 install_element(BGP_NODE, &neighbor_interface_cmd);
13127 install_element(BGP_NODE, &no_neighbor_interface_cmd);
13128
13129 /* "neighbor distribute" commands. */
13130 install_element(BGP_NODE, &neighbor_distribute_list_hidden_cmd);
13131 install_element(BGP_NODE, &no_neighbor_distribute_list_hidden_cmd);
13132 install_element(BGP_IPV4_NODE, &neighbor_distribute_list_cmd);
13133 install_element(BGP_IPV4_NODE, &no_neighbor_distribute_list_cmd);
13134 install_element(BGP_IPV4M_NODE, &neighbor_distribute_list_cmd);
13135 install_element(BGP_IPV4M_NODE, &no_neighbor_distribute_list_cmd);
13136 install_element(BGP_IPV4L_NODE, &neighbor_distribute_list_cmd);
13137 install_element(BGP_IPV4L_NODE, &no_neighbor_distribute_list_cmd);
13138 install_element(BGP_IPV6_NODE, &neighbor_distribute_list_cmd);
13139 install_element(BGP_IPV6_NODE, &no_neighbor_distribute_list_cmd);
13140 install_element(BGP_IPV6M_NODE, &neighbor_distribute_list_cmd);
13141 install_element(BGP_IPV6M_NODE, &no_neighbor_distribute_list_cmd);
13142 install_element(BGP_IPV6L_NODE, &neighbor_distribute_list_cmd);
13143 install_element(BGP_IPV6L_NODE, &no_neighbor_distribute_list_cmd);
13144 install_element(BGP_VPNV4_NODE, &neighbor_distribute_list_cmd);
13145 install_element(BGP_VPNV4_NODE, &no_neighbor_distribute_list_cmd);
13146 install_element(BGP_VPNV6_NODE, &neighbor_distribute_list_cmd);
13147 install_element(BGP_VPNV6_NODE, &no_neighbor_distribute_list_cmd);
13148
13149 /* "neighbor prefix-list" commands. */
13150 install_element(BGP_NODE, &neighbor_prefix_list_hidden_cmd);
13151 install_element(BGP_NODE, &no_neighbor_prefix_list_hidden_cmd);
13152 install_element(BGP_IPV4_NODE, &neighbor_prefix_list_cmd);
13153 install_element(BGP_IPV4_NODE, &no_neighbor_prefix_list_cmd);
13154 install_element(BGP_IPV4M_NODE, &neighbor_prefix_list_cmd);
13155 install_element(BGP_IPV4M_NODE, &no_neighbor_prefix_list_cmd);
13156 install_element(BGP_IPV4L_NODE, &neighbor_prefix_list_cmd);
13157 install_element(BGP_IPV4L_NODE, &no_neighbor_prefix_list_cmd);
13158 install_element(BGP_IPV6_NODE, &neighbor_prefix_list_cmd);
13159 install_element(BGP_IPV6_NODE, &no_neighbor_prefix_list_cmd);
13160 install_element(BGP_IPV6M_NODE, &neighbor_prefix_list_cmd);
13161 install_element(BGP_IPV6M_NODE, &no_neighbor_prefix_list_cmd);
13162 install_element(BGP_IPV6L_NODE, &neighbor_prefix_list_cmd);
13163 install_element(BGP_IPV6L_NODE, &no_neighbor_prefix_list_cmd);
13164 install_element(BGP_VPNV4_NODE, &neighbor_prefix_list_cmd);
13165 install_element(BGP_VPNV4_NODE, &no_neighbor_prefix_list_cmd);
13166 install_element(BGP_VPNV6_NODE, &neighbor_prefix_list_cmd);
13167 install_element(BGP_VPNV6_NODE, &no_neighbor_prefix_list_cmd);
13168 install_element(BGP_FLOWSPECV4_NODE, &neighbor_prefix_list_cmd);
13169 install_element(BGP_FLOWSPECV4_NODE, &no_neighbor_prefix_list_cmd);
13170 install_element(BGP_FLOWSPECV6_NODE, &neighbor_prefix_list_cmd);
13171 install_element(BGP_FLOWSPECV6_NODE, &no_neighbor_prefix_list_cmd);
13172
13173 /* "neighbor filter-list" commands. */
13174 install_element(BGP_NODE, &neighbor_filter_list_hidden_cmd);
13175 install_element(BGP_NODE, &no_neighbor_filter_list_hidden_cmd);
13176 install_element(BGP_IPV4_NODE, &neighbor_filter_list_cmd);
13177 install_element(BGP_IPV4_NODE, &no_neighbor_filter_list_cmd);
13178 install_element(BGP_IPV4M_NODE, &neighbor_filter_list_cmd);
13179 install_element(BGP_IPV4M_NODE, &no_neighbor_filter_list_cmd);
13180 install_element(BGP_IPV4L_NODE, &neighbor_filter_list_cmd);
13181 install_element(BGP_IPV4L_NODE, &no_neighbor_filter_list_cmd);
13182 install_element(BGP_IPV6_NODE, &neighbor_filter_list_cmd);
13183 install_element(BGP_IPV6_NODE, &no_neighbor_filter_list_cmd);
13184 install_element(BGP_IPV6M_NODE, &neighbor_filter_list_cmd);
13185 install_element(BGP_IPV6M_NODE, &no_neighbor_filter_list_cmd);
13186 install_element(BGP_IPV6L_NODE, &neighbor_filter_list_cmd);
13187 install_element(BGP_IPV6L_NODE, &no_neighbor_filter_list_cmd);
13188 install_element(BGP_VPNV4_NODE, &neighbor_filter_list_cmd);
13189 install_element(BGP_VPNV4_NODE, &no_neighbor_filter_list_cmd);
13190 install_element(BGP_VPNV6_NODE, &neighbor_filter_list_cmd);
13191 install_element(BGP_VPNV6_NODE, &no_neighbor_filter_list_cmd);
13192 install_element(BGP_FLOWSPECV4_NODE, &neighbor_filter_list_cmd);
13193 install_element(BGP_FLOWSPECV4_NODE, &no_neighbor_filter_list_cmd);
13194 install_element(BGP_FLOWSPECV6_NODE, &neighbor_filter_list_cmd);
13195 install_element(BGP_FLOWSPECV6_NODE, &no_neighbor_filter_list_cmd);
13196
13197 /* "neighbor route-map" commands. */
13198 install_element(BGP_NODE, &neighbor_route_map_hidden_cmd);
13199 install_element(BGP_NODE, &no_neighbor_route_map_hidden_cmd);
13200 install_element(BGP_IPV4_NODE, &neighbor_route_map_cmd);
13201 install_element(BGP_IPV4_NODE, &no_neighbor_route_map_cmd);
13202 install_element(BGP_IPV4M_NODE, &neighbor_route_map_cmd);
13203 install_element(BGP_IPV4M_NODE, &no_neighbor_route_map_cmd);
13204 install_element(BGP_IPV4L_NODE, &neighbor_route_map_cmd);
13205 install_element(BGP_IPV4L_NODE, &no_neighbor_route_map_cmd);
13206 install_element(BGP_IPV6_NODE, &neighbor_route_map_cmd);
13207 install_element(BGP_IPV6_NODE, &no_neighbor_route_map_cmd);
13208 install_element(BGP_IPV6M_NODE, &neighbor_route_map_cmd);
13209 install_element(BGP_IPV6M_NODE, &no_neighbor_route_map_cmd);
13210 install_element(BGP_IPV6L_NODE, &neighbor_route_map_cmd);
13211 install_element(BGP_IPV6L_NODE, &no_neighbor_route_map_cmd);
13212 install_element(BGP_VPNV4_NODE, &neighbor_route_map_cmd);
13213 install_element(BGP_VPNV4_NODE, &no_neighbor_route_map_cmd);
13214 install_element(BGP_VPNV6_NODE, &neighbor_route_map_cmd);
13215 install_element(BGP_VPNV6_NODE, &no_neighbor_route_map_cmd);
13216 install_element(BGP_FLOWSPECV4_NODE, &neighbor_route_map_cmd);
13217 install_element(BGP_FLOWSPECV4_NODE, &no_neighbor_route_map_cmd);
13218 install_element(BGP_FLOWSPECV6_NODE, &neighbor_route_map_cmd);
13219 install_element(BGP_FLOWSPECV6_NODE, &no_neighbor_route_map_cmd);
13220 install_element(BGP_EVPN_NODE, &neighbor_route_map_cmd);
13221 install_element(BGP_EVPN_NODE, &no_neighbor_route_map_cmd);
13222
13223 /* "neighbor unsuppress-map" commands. */
13224 install_element(BGP_NODE, &neighbor_unsuppress_map_hidden_cmd);
13225 install_element(BGP_NODE, &no_neighbor_unsuppress_map_hidden_cmd);
13226 install_element(BGP_IPV4_NODE, &neighbor_unsuppress_map_cmd);
13227 install_element(BGP_IPV4_NODE, &no_neighbor_unsuppress_map_cmd);
13228 install_element(BGP_IPV4M_NODE, &neighbor_unsuppress_map_cmd);
13229 install_element(BGP_IPV4M_NODE, &no_neighbor_unsuppress_map_cmd);
13230 install_element(BGP_IPV4L_NODE, &neighbor_unsuppress_map_cmd);
13231 install_element(BGP_IPV4L_NODE, &no_neighbor_unsuppress_map_cmd);
13232 install_element(BGP_IPV6_NODE, &neighbor_unsuppress_map_cmd);
13233 install_element(BGP_IPV6_NODE, &no_neighbor_unsuppress_map_cmd);
13234 install_element(BGP_IPV6M_NODE, &neighbor_unsuppress_map_cmd);
13235 install_element(BGP_IPV6M_NODE, &no_neighbor_unsuppress_map_cmd);
13236 install_element(BGP_IPV6L_NODE, &neighbor_unsuppress_map_cmd);
13237 install_element(BGP_IPV6L_NODE, &no_neighbor_unsuppress_map_cmd);
13238 install_element(BGP_VPNV4_NODE, &neighbor_unsuppress_map_cmd);
13239 install_element(BGP_VPNV4_NODE, &no_neighbor_unsuppress_map_cmd);
13240 install_element(BGP_VPNV6_NODE, &neighbor_unsuppress_map_cmd);
13241 install_element(BGP_VPNV6_NODE, &no_neighbor_unsuppress_map_cmd);
13242
13243 /* "neighbor maximum-prefix" commands. */
13244 install_element(BGP_NODE, &neighbor_maximum_prefix_hidden_cmd);
13245 install_element(BGP_NODE,
13246 &neighbor_maximum_prefix_threshold_hidden_cmd);
13247 install_element(BGP_NODE, &neighbor_maximum_prefix_warning_hidden_cmd);
13248 install_element(BGP_NODE,
13249 &neighbor_maximum_prefix_threshold_warning_hidden_cmd);
13250 install_element(BGP_NODE, &neighbor_maximum_prefix_restart_hidden_cmd);
13251 install_element(BGP_NODE,
13252 &neighbor_maximum_prefix_threshold_restart_hidden_cmd);
13253 install_element(BGP_NODE, &no_neighbor_maximum_prefix_hidden_cmd);
13254 install_element(BGP_IPV4_NODE, &neighbor_maximum_prefix_cmd);
13255 install_element(BGP_IPV4_NODE, &neighbor_maximum_prefix_threshold_cmd);
13256 install_element(BGP_IPV4_NODE, &neighbor_maximum_prefix_warning_cmd);
13257 install_element(BGP_IPV4_NODE,
13258 &neighbor_maximum_prefix_threshold_warning_cmd);
13259 install_element(BGP_IPV4_NODE, &neighbor_maximum_prefix_restart_cmd);
13260 install_element(BGP_IPV4_NODE,
13261 &neighbor_maximum_prefix_threshold_restart_cmd);
13262 install_element(BGP_IPV4_NODE, &no_neighbor_maximum_prefix_cmd);
13263 install_element(BGP_IPV4M_NODE, &neighbor_maximum_prefix_cmd);
13264 install_element(BGP_IPV4M_NODE, &neighbor_maximum_prefix_threshold_cmd);
13265 install_element(BGP_IPV4M_NODE, &neighbor_maximum_prefix_warning_cmd);
13266 install_element(BGP_IPV4M_NODE,
13267 &neighbor_maximum_prefix_threshold_warning_cmd);
13268 install_element(BGP_IPV4M_NODE, &neighbor_maximum_prefix_restart_cmd);
13269 install_element(BGP_IPV4M_NODE,
13270 &neighbor_maximum_prefix_threshold_restart_cmd);
13271 install_element(BGP_IPV4M_NODE, &no_neighbor_maximum_prefix_cmd);
13272 install_element(BGP_IPV4L_NODE, &neighbor_maximum_prefix_cmd);
13273 install_element(BGP_IPV4L_NODE, &neighbor_maximum_prefix_threshold_cmd);
13274 install_element(BGP_IPV4L_NODE, &neighbor_maximum_prefix_warning_cmd);
13275 install_element(BGP_IPV4L_NODE,
13276 &neighbor_maximum_prefix_threshold_warning_cmd);
13277 install_element(BGP_IPV4L_NODE, &neighbor_maximum_prefix_restart_cmd);
13278 install_element(BGP_IPV4L_NODE,
13279 &neighbor_maximum_prefix_threshold_restart_cmd);
13280 install_element(BGP_IPV4L_NODE, &no_neighbor_maximum_prefix_cmd);
13281 install_element(BGP_IPV6_NODE, &neighbor_maximum_prefix_cmd);
13282 install_element(BGP_IPV6_NODE, &neighbor_maximum_prefix_threshold_cmd);
13283 install_element(BGP_IPV6_NODE, &neighbor_maximum_prefix_warning_cmd);
13284 install_element(BGP_IPV6_NODE,
13285 &neighbor_maximum_prefix_threshold_warning_cmd);
13286 install_element(BGP_IPV6_NODE, &neighbor_maximum_prefix_restart_cmd);
13287 install_element(BGP_IPV6_NODE,
13288 &neighbor_maximum_prefix_threshold_restart_cmd);
13289 install_element(BGP_IPV6_NODE, &no_neighbor_maximum_prefix_cmd);
13290 install_element(BGP_IPV6M_NODE, &neighbor_maximum_prefix_cmd);
13291 install_element(BGP_IPV6M_NODE, &neighbor_maximum_prefix_threshold_cmd);
13292 install_element(BGP_IPV6M_NODE, &neighbor_maximum_prefix_warning_cmd);
13293 install_element(BGP_IPV6M_NODE,
13294 &neighbor_maximum_prefix_threshold_warning_cmd);
13295 install_element(BGP_IPV6M_NODE, &neighbor_maximum_prefix_restart_cmd);
13296 install_element(BGP_IPV6M_NODE,
13297 &neighbor_maximum_prefix_threshold_restart_cmd);
13298 install_element(BGP_IPV6M_NODE, &no_neighbor_maximum_prefix_cmd);
13299 install_element(BGP_IPV6L_NODE, &neighbor_maximum_prefix_cmd);
13300 install_element(BGP_IPV6L_NODE, &neighbor_maximum_prefix_threshold_cmd);
13301 install_element(BGP_IPV6L_NODE, &neighbor_maximum_prefix_warning_cmd);
13302 install_element(BGP_IPV6L_NODE,
13303 &neighbor_maximum_prefix_threshold_warning_cmd);
13304 install_element(BGP_IPV6L_NODE, &neighbor_maximum_prefix_restart_cmd);
13305 install_element(BGP_IPV6L_NODE,
13306 &neighbor_maximum_prefix_threshold_restart_cmd);
13307 install_element(BGP_IPV6L_NODE, &no_neighbor_maximum_prefix_cmd);
13308 install_element(BGP_VPNV4_NODE, &neighbor_maximum_prefix_cmd);
13309 install_element(BGP_VPNV4_NODE, &neighbor_maximum_prefix_threshold_cmd);
13310 install_element(BGP_VPNV4_NODE, &neighbor_maximum_prefix_warning_cmd);
13311 install_element(BGP_VPNV4_NODE,
13312 &neighbor_maximum_prefix_threshold_warning_cmd);
13313 install_element(BGP_VPNV4_NODE, &neighbor_maximum_prefix_restart_cmd);
13314 install_element(BGP_VPNV4_NODE,
13315 &neighbor_maximum_prefix_threshold_restart_cmd);
13316 install_element(BGP_VPNV4_NODE, &no_neighbor_maximum_prefix_cmd);
13317 install_element(BGP_VPNV6_NODE, &neighbor_maximum_prefix_cmd);
13318 install_element(BGP_VPNV6_NODE, &neighbor_maximum_prefix_threshold_cmd);
13319 install_element(BGP_VPNV6_NODE, &neighbor_maximum_prefix_warning_cmd);
13320 install_element(BGP_VPNV6_NODE,
13321 &neighbor_maximum_prefix_threshold_warning_cmd);
13322 install_element(BGP_VPNV6_NODE, &neighbor_maximum_prefix_restart_cmd);
13323 install_element(BGP_VPNV6_NODE,
13324 &neighbor_maximum_prefix_threshold_restart_cmd);
13325 install_element(BGP_VPNV6_NODE, &no_neighbor_maximum_prefix_cmd);
13326
13327 /* "neighbor allowas-in" */
13328 install_element(BGP_NODE, &neighbor_allowas_in_hidden_cmd);
13329 install_element(BGP_NODE, &no_neighbor_allowas_in_hidden_cmd);
13330 install_element(BGP_IPV4_NODE, &neighbor_allowas_in_cmd);
13331 install_element(BGP_IPV4_NODE, &no_neighbor_allowas_in_cmd);
13332 install_element(BGP_IPV4M_NODE, &neighbor_allowas_in_cmd);
13333 install_element(BGP_IPV4M_NODE, &no_neighbor_allowas_in_cmd);
13334 install_element(BGP_IPV4L_NODE, &neighbor_allowas_in_cmd);
13335 install_element(BGP_IPV4L_NODE, &no_neighbor_allowas_in_cmd);
13336 install_element(BGP_IPV6_NODE, &neighbor_allowas_in_cmd);
13337 install_element(BGP_IPV6_NODE, &no_neighbor_allowas_in_cmd);
13338 install_element(BGP_IPV6M_NODE, &neighbor_allowas_in_cmd);
13339 install_element(BGP_IPV6M_NODE, &no_neighbor_allowas_in_cmd);
13340 install_element(BGP_IPV6L_NODE, &neighbor_allowas_in_cmd);
13341 install_element(BGP_IPV6L_NODE, &no_neighbor_allowas_in_cmd);
13342 install_element(BGP_VPNV4_NODE, &neighbor_allowas_in_cmd);
13343 install_element(BGP_VPNV4_NODE, &no_neighbor_allowas_in_cmd);
13344 install_element(BGP_VPNV6_NODE, &neighbor_allowas_in_cmd);
13345 install_element(BGP_VPNV6_NODE, &no_neighbor_allowas_in_cmd);
13346 install_element(BGP_EVPN_NODE, &neighbor_allowas_in_cmd);
13347 install_element(BGP_EVPN_NODE, &no_neighbor_allowas_in_cmd);
13348
13349 /* address-family commands. */
13350 install_element(BGP_NODE, &address_family_ipv4_safi_cmd);
13351 install_element(BGP_NODE, &address_family_ipv6_safi_cmd);
13352 #ifdef KEEP_OLD_VPN_COMMANDS
13353 install_element(BGP_NODE, &address_family_vpnv4_cmd);
13354 install_element(BGP_NODE, &address_family_vpnv6_cmd);
13355 #endif /* KEEP_OLD_VPN_COMMANDS */
13356
13357 install_element(BGP_NODE, &address_family_evpn_cmd);
13358
13359 /* "exit-address-family" command. */
13360 install_element(BGP_IPV4_NODE, &exit_address_family_cmd);
13361 install_element(BGP_IPV4M_NODE, &exit_address_family_cmd);
13362 install_element(BGP_IPV4L_NODE, &exit_address_family_cmd);
13363 install_element(BGP_IPV6_NODE, &exit_address_family_cmd);
13364 install_element(BGP_IPV6M_NODE, &exit_address_family_cmd);
13365 install_element(BGP_IPV6L_NODE, &exit_address_family_cmd);
13366 install_element(BGP_VPNV4_NODE, &exit_address_family_cmd);
13367 install_element(BGP_VPNV6_NODE, &exit_address_family_cmd);
13368 install_element(BGP_FLOWSPECV4_NODE, &exit_address_family_cmd);
13369 install_element(BGP_FLOWSPECV6_NODE, &exit_address_family_cmd);
13370 install_element(BGP_EVPN_NODE, &exit_address_family_cmd);
13371
13372 /* "clear ip bgp commands" */
13373 install_element(ENABLE_NODE, &clear_ip_bgp_all_cmd);
13374
13375 /* clear ip bgp prefix */
13376 install_element(ENABLE_NODE, &clear_ip_bgp_prefix_cmd);
13377 install_element(ENABLE_NODE, &clear_bgp_ipv6_safi_prefix_cmd);
13378 install_element(ENABLE_NODE, &clear_bgp_instance_ipv6_safi_prefix_cmd);
13379
13380 /* "show [ip] bgp summary" commands. */
13381 install_element(VIEW_NODE, &show_bgp_instance_all_ipv6_updgrps_cmd);
13382 install_element(VIEW_NODE, &show_bgp_instance_updgrps_stats_cmd);
13383 install_element(VIEW_NODE, &show_bgp_updgrps_stats_cmd);
13384 install_element(VIEW_NODE, &show_ip_bgp_instance_updgrps_adj_s_cmd);
13385 install_element(VIEW_NODE, &show_ip_bgp_summary_cmd);
13386 install_element(VIEW_NODE, &show_ip_bgp_updgrps_cmd);
13387
13388 /* "show [ip] bgp neighbors" commands. */
13389 install_element(VIEW_NODE, &show_ip_bgp_neighbors_cmd);
13390
13391 /* "show [ip] bgp peer-group" commands. */
13392 install_element(VIEW_NODE, &show_ip_bgp_peer_groups_cmd);
13393
13394 /* "show [ip] bgp paths" commands. */
13395 install_element(VIEW_NODE, &show_ip_bgp_paths_cmd);
13396
13397 /* "show [ip] bgp community" commands. */
13398 install_element(VIEW_NODE, &show_ip_bgp_community_info_cmd);
13399
13400 /* "show ip bgp large-community" commands. */
13401 install_element(VIEW_NODE, &show_ip_bgp_lcommunity_info_cmd);
13402 /* "show [ip] bgp attribute-info" commands. */
13403 install_element(VIEW_NODE, &show_ip_bgp_attr_info_cmd);
13404 /* "show [ip] bgp route-leak" command */
13405 install_element(VIEW_NODE, &show_ip_bgp_route_leak_cmd);
13406
13407 /* "redistribute" commands. */
13408 install_element(BGP_NODE, &bgp_redistribute_ipv4_hidden_cmd);
13409 install_element(BGP_NODE, &no_bgp_redistribute_ipv4_hidden_cmd);
13410 install_element(BGP_NODE, &bgp_redistribute_ipv4_rmap_hidden_cmd);
13411 install_element(BGP_NODE, &bgp_redistribute_ipv4_metric_hidden_cmd);
13412 install_element(BGP_NODE,
13413 &bgp_redistribute_ipv4_rmap_metric_hidden_cmd);
13414 install_element(BGP_NODE,
13415 &bgp_redistribute_ipv4_metric_rmap_hidden_cmd);
13416 install_element(BGP_NODE, &bgp_redistribute_ipv4_ospf_hidden_cmd);
13417 install_element(BGP_NODE, &no_bgp_redistribute_ipv4_ospf_hidden_cmd);
13418 install_element(BGP_NODE, &bgp_redistribute_ipv4_ospf_rmap_hidden_cmd);
13419 install_element(BGP_NODE,
13420 &bgp_redistribute_ipv4_ospf_metric_hidden_cmd);
13421 install_element(BGP_NODE,
13422 &bgp_redistribute_ipv4_ospf_rmap_metric_hidden_cmd);
13423 install_element(BGP_NODE,
13424 &bgp_redistribute_ipv4_ospf_metric_rmap_hidden_cmd);
13425 install_element(BGP_IPV4_NODE, &bgp_redistribute_ipv4_cmd);
13426 install_element(BGP_IPV4_NODE, &no_bgp_redistribute_ipv4_cmd);
13427 install_element(BGP_IPV4_NODE, &bgp_redistribute_ipv4_rmap_cmd);
13428 install_element(BGP_IPV4_NODE, &bgp_redistribute_ipv4_metric_cmd);
13429 install_element(BGP_IPV4_NODE, &bgp_redistribute_ipv4_rmap_metric_cmd);
13430 install_element(BGP_IPV4_NODE, &bgp_redistribute_ipv4_metric_rmap_cmd);
13431 install_element(BGP_IPV4_NODE, &bgp_redistribute_ipv4_ospf_cmd);
13432 install_element(BGP_IPV4_NODE, &no_bgp_redistribute_ipv4_ospf_cmd);
13433 install_element(BGP_IPV4_NODE, &bgp_redistribute_ipv4_ospf_rmap_cmd);
13434 install_element(BGP_IPV4_NODE, &bgp_redistribute_ipv4_ospf_metric_cmd);
13435 install_element(BGP_IPV4_NODE,
13436 &bgp_redistribute_ipv4_ospf_rmap_metric_cmd);
13437 install_element(BGP_IPV4_NODE,
13438 &bgp_redistribute_ipv4_ospf_metric_rmap_cmd);
13439 install_element(BGP_IPV6_NODE, &bgp_redistribute_ipv6_cmd);
13440 install_element(BGP_IPV6_NODE, &no_bgp_redistribute_ipv6_cmd);
13441 install_element(BGP_IPV6_NODE, &bgp_redistribute_ipv6_rmap_cmd);
13442 install_element(BGP_IPV6_NODE, &bgp_redistribute_ipv6_metric_cmd);
13443 install_element(BGP_IPV6_NODE, &bgp_redistribute_ipv6_rmap_metric_cmd);
13444 install_element(BGP_IPV6_NODE, &bgp_redistribute_ipv6_metric_rmap_cmd);
13445
13446 /* import|export vpn [route-map WORD] */
13447 install_element(BGP_IPV4_NODE, &bgp_imexport_vpn_cmd);
13448 install_element(BGP_IPV6_NODE, &bgp_imexport_vpn_cmd);
13449
13450 install_element(BGP_IPV4_NODE, &bgp_imexport_vrf_cmd);
13451 install_element(BGP_IPV6_NODE, &bgp_imexport_vrf_cmd);
13452
13453 /* ttl_security commands */
13454 install_element(BGP_NODE, &neighbor_ttl_security_cmd);
13455 install_element(BGP_NODE, &no_neighbor_ttl_security_cmd);
13456
13457 /* "show [ip] bgp memory" commands. */
13458 install_element(VIEW_NODE, &show_bgp_memory_cmd);
13459
13460 /* "show bgp martian next-hop" */
13461 install_element(VIEW_NODE, &show_bgp_martian_nexthop_db_cmd);
13462
13463 /* "show [ip] bgp views" commands. */
13464 install_element(VIEW_NODE, &show_bgp_views_cmd);
13465
13466 /* "show [ip] bgp vrfs" commands. */
13467 install_element(VIEW_NODE, &show_bgp_vrfs_cmd);
13468
13469 /* Community-list. */
13470 community_list_vty();
13471
13472 /* vpn-policy commands */
13473 install_element(BGP_IPV4_NODE, &af_rd_vpn_export_cmd);
13474 install_element(BGP_IPV6_NODE, &af_rd_vpn_export_cmd);
13475 install_element(BGP_IPV4_NODE, &af_label_vpn_export_cmd);
13476 install_element(BGP_IPV6_NODE, &af_label_vpn_export_cmd);
13477 install_element(BGP_IPV4_NODE, &af_nexthop_vpn_export_cmd);
13478 install_element(BGP_IPV6_NODE, &af_nexthop_vpn_export_cmd);
13479 install_element(BGP_IPV4_NODE, &af_rt_vpn_imexport_cmd);
13480 install_element(BGP_IPV6_NODE, &af_rt_vpn_imexport_cmd);
13481 install_element(BGP_IPV4_NODE, &af_route_map_vpn_imexport_cmd);
13482 install_element(BGP_IPV6_NODE, &af_route_map_vpn_imexport_cmd);
13483 install_element(BGP_IPV4_NODE, &af_import_vrf_route_map_cmd);
13484 install_element(BGP_IPV6_NODE, &af_import_vrf_route_map_cmd);
13485
13486 install_element(BGP_IPV4_NODE, &af_routetarget_import_cmd);
13487 install_element(BGP_IPV6_NODE, &af_routetarget_import_cmd);
13488
13489 install_element(BGP_IPV4_NODE, &af_no_rd_vpn_export_cmd);
13490 install_element(BGP_IPV6_NODE, &af_no_rd_vpn_export_cmd);
13491 install_element(BGP_IPV4_NODE, &af_no_label_vpn_export_cmd);
13492 install_element(BGP_IPV6_NODE, &af_no_label_vpn_export_cmd);
13493 install_element(BGP_IPV4_NODE, &af_no_nexthop_vpn_export_cmd);
13494 install_element(BGP_IPV6_NODE, &af_no_nexthop_vpn_export_cmd);
13495 install_element(BGP_IPV4_NODE, &af_no_rt_vpn_imexport_cmd);
13496 install_element(BGP_IPV6_NODE, &af_no_rt_vpn_imexport_cmd);
13497 install_element(BGP_IPV4_NODE, &af_no_route_map_vpn_imexport_cmd);
13498 install_element(BGP_IPV6_NODE, &af_no_route_map_vpn_imexport_cmd);
13499 install_element(BGP_IPV4_NODE, &af_no_import_vrf_route_map_cmd);
13500 install_element(BGP_IPV6_NODE, &af_no_import_vrf_route_map_cmd);
13501 }
13502
13503 #include "memory.h"
13504 #include "bgp_regex.h"
13505 #include "bgp_clist.h"
13506 #include "bgp_ecommunity.h"
13507
13508 /* VTY functions. */
13509
13510 /* Direction value to string conversion. */
13511 static const char *community_direct_str(int direct)
13512 {
13513 switch (direct) {
13514 case COMMUNITY_DENY:
13515 return "deny";
13516 case COMMUNITY_PERMIT:
13517 return "permit";
13518 default:
13519 return "unknown";
13520 }
13521 }
13522
13523 /* Display error string. */
13524 static void community_list_perror(struct vty *vty, int ret)
13525 {
13526 switch (ret) {
13527 case COMMUNITY_LIST_ERR_CANT_FIND_LIST:
13528 vty_out(vty, "%% Can't find community-list\n");
13529 break;
13530 case COMMUNITY_LIST_ERR_MALFORMED_VAL:
13531 vty_out(vty, "%% Malformed community-list value\n");
13532 break;
13533 case COMMUNITY_LIST_ERR_STANDARD_CONFLICT:
13534 vty_out(vty,
13535 "%% Community name conflict, previously defined as standard community\n");
13536 break;
13537 case COMMUNITY_LIST_ERR_EXPANDED_CONFLICT:
13538 vty_out(vty,
13539 "%% Community name conflict, previously defined as expanded community\n");
13540 break;
13541 }
13542 }
13543
13544 /* "community-list" keyword help string. */
13545 #define COMMUNITY_LIST_STR "Add a community list entry\n"
13546
13547 /* ip community-list standard */
13548 DEFUN (ip_community_list_standard,
13549 ip_community_list_standard_cmd,
13550 "ip community-list <(1-99)|standard WORD> <deny|permit> AA:NN...",
13551 IP_STR
13552 COMMUNITY_LIST_STR
13553 "Community list number (standard)\n"
13554 "Add an standard community-list entry\n"
13555 "Community list name\n"
13556 "Specify community to reject\n"
13557 "Specify community to accept\n"
13558 COMMUNITY_VAL_STR)
13559 {
13560 char *cl_name_or_number = NULL;
13561 int direct = 0;
13562 int style = COMMUNITY_LIST_STANDARD;
13563
13564 int idx = 0;
13565 argv_find(argv, argc, "(1-99)", &idx);
13566 argv_find(argv, argc, "WORD", &idx);
13567 cl_name_or_number = argv[idx]->arg;
13568 direct = argv_find(argv, argc, "permit", &idx) ? COMMUNITY_PERMIT
13569 : COMMUNITY_DENY;
13570 argv_find(argv, argc, "AA:NN", &idx);
13571 char *str = argv_concat(argv, argc, idx);
13572
13573 int ret = community_list_set(bgp_clist, cl_name_or_number, str, direct,
13574 style);
13575
13576 XFREE(MTYPE_TMP, str);
13577
13578 if (ret < 0) {
13579 /* Display error string. */
13580 community_list_perror(vty, ret);
13581 return CMD_WARNING_CONFIG_FAILED;
13582 }
13583
13584 return CMD_SUCCESS;
13585 }
13586
13587 DEFUN (no_ip_community_list_standard_all,
13588 no_ip_community_list_standard_all_cmd,
13589 "no ip community-list <(1-99)|standard WORD> <deny|permit> AA:NN...",
13590 NO_STR
13591 IP_STR
13592 COMMUNITY_LIST_STR
13593 "Community list number (standard)\n"
13594 "Add an standard community-list entry\n"
13595 "Community list name\n"
13596 "Specify community to reject\n"
13597 "Specify community to accept\n"
13598 COMMUNITY_VAL_STR)
13599 {
13600 char *cl_name_or_number = NULL;
13601 int direct = 0;
13602 int style = COMMUNITY_LIST_STANDARD;
13603
13604 int idx = 0;
13605 argv_find(argv, argc, "(1-99)", &idx);
13606 argv_find(argv, argc, "WORD", &idx);
13607 cl_name_or_number = argv[idx]->arg;
13608 direct = argv_find(argv, argc, "permit", &idx) ? COMMUNITY_PERMIT
13609 : COMMUNITY_DENY;
13610 argv_find(argv, argc, "AA:NN", &idx);
13611 char *str = argv_concat(argv, argc, idx);
13612
13613 int ret = community_list_unset(bgp_clist, cl_name_or_number, str,
13614 direct, style);
13615
13616 XFREE(MTYPE_TMP, str);
13617
13618 if (ret < 0) {
13619 community_list_perror(vty, ret);
13620 return CMD_WARNING_CONFIG_FAILED;
13621 }
13622
13623 return CMD_SUCCESS;
13624 }
13625
13626 /* ip community-list expanded */
13627 DEFUN (ip_community_list_expanded_all,
13628 ip_community_list_expanded_all_cmd,
13629 "ip community-list <(100-500)|expanded WORD> <deny|permit> AA:NN...",
13630 IP_STR
13631 COMMUNITY_LIST_STR
13632 "Community list number (expanded)\n"
13633 "Add an expanded community-list entry\n"
13634 "Community list name\n"
13635 "Specify community to reject\n"
13636 "Specify community to accept\n"
13637 COMMUNITY_VAL_STR)
13638 {
13639 char *cl_name_or_number = NULL;
13640 int direct = 0;
13641 int style = COMMUNITY_LIST_EXPANDED;
13642
13643 int idx = 0;
13644 argv_find(argv, argc, "(100-500)", &idx);
13645 argv_find(argv, argc, "WORD", &idx);
13646 cl_name_or_number = argv[idx]->arg;
13647 direct = argv_find(argv, argc, "permit", &idx) ? COMMUNITY_PERMIT
13648 : COMMUNITY_DENY;
13649 argv_find(argv, argc, "AA:NN", &idx);
13650 char *str = argv_concat(argv, argc, idx);
13651
13652 int ret = community_list_set(bgp_clist, cl_name_or_number, str, direct,
13653 style);
13654
13655 XFREE(MTYPE_TMP, str);
13656
13657 if (ret < 0) {
13658 /* Display error string. */
13659 community_list_perror(vty, ret);
13660 return CMD_WARNING_CONFIG_FAILED;
13661 }
13662
13663 return CMD_SUCCESS;
13664 }
13665
13666 DEFUN (no_ip_community_list_expanded_all,
13667 no_ip_community_list_expanded_all_cmd,
13668 "no ip community-list <(100-500)|expanded WORD> <deny|permit> AA:NN...",
13669 NO_STR
13670 IP_STR
13671 COMMUNITY_LIST_STR
13672 "Community list number (expanded)\n"
13673 "Add an expanded community-list entry\n"
13674 "Community list name\n"
13675 "Specify community to reject\n"
13676 "Specify community to accept\n"
13677 COMMUNITY_VAL_STR)
13678 {
13679 char *cl_name_or_number = NULL;
13680 int direct = 0;
13681 int style = COMMUNITY_LIST_EXPANDED;
13682
13683 int idx = 0;
13684 argv_find(argv, argc, "(100-500)", &idx);
13685 argv_find(argv, argc, "WORD", &idx);
13686 cl_name_or_number = argv[idx]->arg;
13687 direct = argv_find(argv, argc, "permit", &idx) ? COMMUNITY_PERMIT
13688 : COMMUNITY_DENY;
13689 argv_find(argv, argc, "AA:NN", &idx);
13690 char *str = argv_concat(argv, argc, idx);
13691
13692 int ret = community_list_unset(bgp_clist, cl_name_or_number, str,
13693 direct, style);
13694
13695 XFREE(MTYPE_TMP, str);
13696
13697 if (ret < 0) {
13698 community_list_perror(vty, ret);
13699 return CMD_WARNING_CONFIG_FAILED;
13700 }
13701
13702 return CMD_SUCCESS;
13703 }
13704
13705 /* Return configuration string of community-list entry. */
13706 static const char *community_list_config_str(struct community_entry *entry)
13707 {
13708 const char *str;
13709
13710 if (entry->any)
13711 str = "";
13712 else {
13713 if (entry->style == COMMUNITY_LIST_STANDARD)
13714 str = community_str(entry->u.com, false);
13715 else if (entry->style == LARGE_COMMUNITY_LIST_STANDARD)
13716 str = lcommunity_str(entry->u.lcom, false);
13717 else
13718 str = entry->config;
13719 }
13720 return str;
13721 }
13722
13723 static void community_list_show(struct vty *vty, struct community_list *list)
13724 {
13725 struct community_entry *entry;
13726
13727 for (entry = list->head; entry; entry = entry->next) {
13728 if (entry == list->head) {
13729 if (all_digit(list->name))
13730 vty_out(vty, "Community %s list %s\n",
13731 entry->style == COMMUNITY_LIST_STANDARD
13732 ? "standard"
13733 : "(expanded) access",
13734 list->name);
13735 else
13736 vty_out(vty, "Named Community %s list %s\n",
13737 entry->style == COMMUNITY_LIST_STANDARD
13738 ? "standard"
13739 : "expanded",
13740 list->name);
13741 }
13742 if (entry->any)
13743 vty_out(vty, " %s\n",
13744 community_direct_str(entry->direct));
13745 else
13746 vty_out(vty, " %s %s\n",
13747 community_direct_str(entry->direct),
13748 community_list_config_str(entry));
13749 }
13750 }
13751
13752 DEFUN (show_ip_community_list,
13753 show_ip_community_list_cmd,
13754 "show ip community-list",
13755 SHOW_STR
13756 IP_STR
13757 "List community-list\n")
13758 {
13759 struct community_list *list;
13760 struct community_list_master *cm;
13761
13762 cm = community_list_master_lookup(bgp_clist, COMMUNITY_LIST_MASTER);
13763 if (!cm)
13764 return CMD_SUCCESS;
13765
13766 for (list = cm->num.head; list; list = list->next)
13767 community_list_show(vty, list);
13768
13769 for (list = cm->str.head; list; list = list->next)
13770 community_list_show(vty, list);
13771
13772 return CMD_SUCCESS;
13773 }
13774
13775 DEFUN (show_ip_community_list_arg,
13776 show_ip_community_list_arg_cmd,
13777 "show ip community-list <(1-500)|WORD>",
13778 SHOW_STR
13779 IP_STR
13780 "List community-list\n"
13781 "Community-list number\n"
13782 "Community-list name\n")
13783 {
13784 int idx_comm_list = 3;
13785 struct community_list *list;
13786
13787 list = community_list_lookup(bgp_clist, argv[idx_comm_list]->arg,
13788 COMMUNITY_LIST_MASTER);
13789 if (!list) {
13790 vty_out(vty, "%% Can't find community-list\n");
13791 return CMD_WARNING;
13792 }
13793
13794 community_list_show(vty, list);
13795
13796 return CMD_SUCCESS;
13797 }
13798
13799 /*
13800 * Large Community code.
13801 */
13802 static int lcommunity_list_set_vty(struct vty *vty, int argc,
13803 struct cmd_token **argv, int style,
13804 int reject_all_digit_name)
13805 {
13806 int ret;
13807 int direct;
13808 char *str;
13809 int idx = 0;
13810 char *cl_name;
13811
13812 direct = argv_find(argv, argc, "permit", &idx) ? COMMUNITY_PERMIT
13813 : COMMUNITY_DENY;
13814
13815 /* All digit name check. */
13816 idx = 0;
13817 argv_find(argv, argc, "WORD", &idx);
13818 argv_find(argv, argc, "(1-99)", &idx);
13819 argv_find(argv, argc, "(100-500)", &idx);
13820 cl_name = argv[idx]->arg;
13821 if (reject_all_digit_name && all_digit(cl_name)) {
13822 vty_out(vty, "%% Community name cannot have all digits\n");
13823 return CMD_WARNING_CONFIG_FAILED;
13824 }
13825
13826 idx = 0;
13827 argv_find(argv, argc, "AA:BB:CC", &idx);
13828 argv_find(argv, argc, "LINE", &idx);
13829 /* Concat community string argument. */
13830 if (idx)
13831 str = argv_concat(argv, argc, idx);
13832 else
13833 str = NULL;
13834
13835 ret = lcommunity_list_set(bgp_clist, cl_name, str, direct, style);
13836
13837 /* Free temporary community list string allocated by
13838 argv_concat(). */
13839 if (str)
13840 XFREE(MTYPE_TMP, str);
13841
13842 if (ret < 0) {
13843 community_list_perror(vty, ret);
13844 return CMD_WARNING_CONFIG_FAILED;
13845 }
13846 return CMD_SUCCESS;
13847 }
13848
13849 static int lcommunity_list_unset_vty(struct vty *vty, int argc,
13850 struct cmd_token **argv, int style)
13851 {
13852 int ret;
13853 int direct = 0;
13854 char *str = NULL;
13855 int idx = 0;
13856
13857 argv_find(argv, argc, "permit", &idx);
13858 argv_find(argv, argc, "deny", &idx);
13859
13860 if (idx) {
13861 /* Check the list direct. */
13862 if (strncmp(argv[idx]->arg, "p", 1) == 0)
13863 direct = COMMUNITY_PERMIT;
13864 else
13865 direct = COMMUNITY_DENY;
13866
13867 idx = 0;
13868 argv_find(argv, argc, "LINE", &idx);
13869 argv_find(argv, argc, "AA:AA:NN", &idx);
13870 /* Concat community string argument. */
13871 str = argv_concat(argv, argc, idx);
13872 }
13873
13874 idx = 0;
13875 argv_find(argv, argc, "(1-99)", &idx);
13876 argv_find(argv, argc, "(100-500)", &idx);
13877 argv_find(argv, argc, "WORD", &idx);
13878
13879 /* Unset community list. */
13880 ret = lcommunity_list_unset(bgp_clist, argv[idx]->arg, str, direct,
13881 style);
13882
13883 /* Free temporary community list string allocated by
13884 argv_concat(). */
13885 if (str)
13886 XFREE(MTYPE_TMP, str);
13887
13888 if (ret < 0) {
13889 community_list_perror(vty, ret);
13890 return CMD_WARNING_CONFIG_FAILED;
13891 }
13892
13893 return CMD_SUCCESS;
13894 }
13895
13896 /* "large-community-list" keyword help string. */
13897 #define LCOMMUNITY_LIST_STR "Add a large community list entry\n"
13898 #define LCOMMUNITY_VAL_STR "large community in 'aa:bb:cc' format\n"
13899
13900 DEFUN (ip_lcommunity_list_standard,
13901 ip_lcommunity_list_standard_cmd,
13902 "ip large-community-list (1-99) <deny|permit>",
13903 IP_STR
13904 LCOMMUNITY_LIST_STR
13905 "Large Community list number (standard)\n"
13906 "Specify large community to reject\n"
13907 "Specify large community to accept\n")
13908 {
13909 return lcommunity_list_set_vty(vty, argc, argv,
13910 LARGE_COMMUNITY_LIST_STANDARD, 0);
13911 }
13912
13913 DEFUN (ip_lcommunity_list_standard1,
13914 ip_lcommunity_list_standard1_cmd,
13915 "ip large-community-list (1-99) <deny|permit> AA:BB:CC...",
13916 IP_STR
13917 LCOMMUNITY_LIST_STR
13918 "Large Community list number (standard)\n"
13919 "Specify large community to reject\n"
13920 "Specify large community to accept\n"
13921 LCOMMUNITY_VAL_STR)
13922 {
13923 return lcommunity_list_set_vty(vty, argc, argv,
13924 LARGE_COMMUNITY_LIST_STANDARD, 0);
13925 }
13926
13927 DEFUN (ip_lcommunity_list_expanded,
13928 ip_lcommunity_list_expanded_cmd,
13929 "ip large-community-list (100-500) <deny|permit> LINE...",
13930 IP_STR
13931 LCOMMUNITY_LIST_STR
13932 "Large Community list number (expanded)\n"
13933 "Specify large community to reject\n"
13934 "Specify large community to accept\n"
13935 "An ordered list as a regular-expression\n")
13936 {
13937 return lcommunity_list_set_vty(vty, argc, argv,
13938 LARGE_COMMUNITY_LIST_EXPANDED, 0);
13939 }
13940
13941 DEFUN (ip_lcommunity_list_name_standard,
13942 ip_lcommunity_list_name_standard_cmd,
13943 "ip large-community-list standard WORD <deny|permit>",
13944 IP_STR
13945 LCOMMUNITY_LIST_STR
13946 "Specify standard large-community-list\n"
13947 "Large Community list name\n"
13948 "Specify large community to reject\n"
13949 "Specify large community to accept\n")
13950 {
13951 return lcommunity_list_set_vty(vty, argc, argv,
13952 LARGE_COMMUNITY_LIST_STANDARD, 1);
13953 }
13954
13955 DEFUN (ip_lcommunity_list_name_standard1,
13956 ip_lcommunity_list_name_standard1_cmd,
13957 "ip large-community-list standard WORD <deny|permit> AA:BB:CC...",
13958 IP_STR
13959 LCOMMUNITY_LIST_STR
13960 "Specify standard large-community-list\n"
13961 "Large Community list name\n"
13962 "Specify large community to reject\n"
13963 "Specify large community to accept\n"
13964 LCOMMUNITY_VAL_STR)
13965 {
13966 return lcommunity_list_set_vty(vty, argc, argv,
13967 LARGE_COMMUNITY_LIST_STANDARD, 1);
13968 }
13969
13970 DEFUN (ip_lcommunity_list_name_expanded,
13971 ip_lcommunity_list_name_expanded_cmd,
13972 "ip large-community-list expanded WORD <deny|permit> LINE...",
13973 IP_STR
13974 LCOMMUNITY_LIST_STR
13975 "Specify expanded large-community-list\n"
13976 "Large Community list name\n"
13977 "Specify large community to reject\n"
13978 "Specify large community to accept\n"
13979 "An ordered list as a regular-expression\n")
13980 {
13981 return lcommunity_list_set_vty(vty, argc, argv,
13982 LARGE_COMMUNITY_LIST_EXPANDED, 1);
13983 }
13984
13985 DEFUN (no_ip_lcommunity_list_standard_all,
13986 no_ip_lcommunity_list_standard_all_cmd,
13987 "no ip large-community-list <(1-99)|(100-500)|WORD>",
13988 NO_STR
13989 IP_STR
13990 LCOMMUNITY_LIST_STR
13991 "Large Community list number (standard)\n"
13992 "Large Community list number (expanded)\n"
13993 "Large Community list name\n")
13994 {
13995 return lcommunity_list_unset_vty(vty, argc, argv,
13996 LARGE_COMMUNITY_LIST_STANDARD);
13997 }
13998
13999 DEFUN (no_ip_lcommunity_list_name_expanded_all,
14000 no_ip_lcommunity_list_name_expanded_all_cmd,
14001 "no ip large-community-list expanded WORD",
14002 NO_STR
14003 IP_STR
14004 LCOMMUNITY_LIST_STR
14005 "Specify expanded large-community-list\n"
14006 "Large Community list name\n")
14007 {
14008 return lcommunity_list_unset_vty(vty, argc, argv,
14009 LARGE_COMMUNITY_LIST_EXPANDED);
14010 }
14011
14012 DEFUN (no_ip_lcommunity_list_standard,
14013 no_ip_lcommunity_list_standard_cmd,
14014 "no ip large-community-list (1-99) <deny|permit> AA:AA:NN...",
14015 NO_STR
14016 IP_STR
14017 LCOMMUNITY_LIST_STR
14018 "Large Community list number (standard)\n"
14019 "Specify large community to reject\n"
14020 "Specify large community to accept\n"
14021 LCOMMUNITY_VAL_STR)
14022 {
14023 return lcommunity_list_unset_vty(vty, argc, argv,
14024 LARGE_COMMUNITY_LIST_STANDARD);
14025 }
14026
14027 DEFUN (no_ip_lcommunity_list_expanded,
14028 no_ip_lcommunity_list_expanded_cmd,
14029 "no ip large-community-list (100-500) <deny|permit> LINE...",
14030 NO_STR
14031 IP_STR
14032 LCOMMUNITY_LIST_STR
14033 "Large Community list number (expanded)\n"
14034 "Specify large community to reject\n"
14035 "Specify large community to accept\n"
14036 "An ordered list as a regular-expression\n")
14037 {
14038 return lcommunity_list_unset_vty(vty, argc, argv,
14039 LARGE_COMMUNITY_LIST_EXPANDED);
14040 }
14041
14042 DEFUN (no_ip_lcommunity_list_name_standard,
14043 no_ip_lcommunity_list_name_standard_cmd,
14044 "no ip large-community-list standard WORD <deny|permit> AA:AA:NN...",
14045 NO_STR
14046 IP_STR
14047 LCOMMUNITY_LIST_STR
14048 "Specify standard large-community-list\n"
14049 "Large Community list name\n"
14050 "Specify large community to reject\n"
14051 "Specify large community to accept\n"
14052 LCOMMUNITY_VAL_STR)
14053 {
14054 return lcommunity_list_unset_vty(vty, argc, argv,
14055 LARGE_COMMUNITY_LIST_STANDARD);
14056 }
14057
14058 DEFUN (no_ip_lcommunity_list_name_expanded,
14059 no_ip_lcommunity_list_name_expanded_cmd,
14060 "no ip large-community-list expanded WORD <deny|permit> LINE...",
14061 NO_STR
14062 IP_STR
14063 LCOMMUNITY_LIST_STR
14064 "Specify expanded large-community-list\n"
14065 "Large community list name\n"
14066 "Specify large community to reject\n"
14067 "Specify large community to accept\n"
14068 "An ordered list as a regular-expression\n")
14069 {
14070 return lcommunity_list_unset_vty(vty, argc, argv,
14071 LARGE_COMMUNITY_LIST_EXPANDED);
14072 }
14073
14074 static void lcommunity_list_show(struct vty *vty, struct community_list *list)
14075 {
14076 struct community_entry *entry;
14077
14078 for (entry = list->head; entry; entry = entry->next) {
14079 if (entry == list->head) {
14080 if (all_digit(list->name))
14081 vty_out(vty, "Large community %s list %s\n",
14082 entry->style == EXTCOMMUNITY_LIST_STANDARD
14083 ? "standard"
14084 : "(expanded) access",
14085 list->name);
14086 else
14087 vty_out(vty,
14088 "Named large community %s list %s\n",
14089 entry->style == EXTCOMMUNITY_LIST_STANDARD
14090 ? "standard"
14091 : "expanded",
14092 list->name);
14093 }
14094 if (entry->any)
14095 vty_out(vty, " %s\n",
14096 community_direct_str(entry->direct));
14097 else
14098 vty_out(vty, " %s %s\n",
14099 community_direct_str(entry->direct),
14100 community_list_config_str(entry));
14101 }
14102 }
14103
14104 DEFUN (show_ip_lcommunity_list,
14105 show_ip_lcommunity_list_cmd,
14106 "show ip large-community-list",
14107 SHOW_STR
14108 IP_STR
14109 "List large-community list\n")
14110 {
14111 struct community_list *list;
14112 struct community_list_master *cm;
14113
14114 cm = community_list_master_lookup(bgp_clist,
14115 LARGE_COMMUNITY_LIST_MASTER);
14116 if (!cm)
14117 return CMD_SUCCESS;
14118
14119 for (list = cm->num.head; list; list = list->next)
14120 lcommunity_list_show(vty, list);
14121
14122 for (list = cm->str.head; list; list = list->next)
14123 lcommunity_list_show(vty, list);
14124
14125 return CMD_SUCCESS;
14126 }
14127
14128 DEFUN (show_ip_lcommunity_list_arg,
14129 show_ip_lcommunity_list_arg_cmd,
14130 "show ip large-community-list <(1-500)|WORD>",
14131 SHOW_STR
14132 IP_STR
14133 "List large-community list\n"
14134 "large-community-list number\n"
14135 "large-community-list name\n")
14136 {
14137 struct community_list *list;
14138
14139 list = community_list_lookup(bgp_clist, argv[3]->arg,
14140 LARGE_COMMUNITY_LIST_MASTER);
14141 if (!list) {
14142 vty_out(vty, "%% Can't find extcommunity-list\n");
14143 return CMD_WARNING;
14144 }
14145
14146 lcommunity_list_show(vty, list);
14147
14148 return CMD_SUCCESS;
14149 }
14150
14151 /* "extcommunity-list" keyword help string. */
14152 #define EXTCOMMUNITY_LIST_STR "Add a extended community list entry\n"
14153 #define EXTCOMMUNITY_VAL_STR "Extended community attribute in 'rt aa:nn_or_IPaddr:nn' OR 'soo aa:nn_or_IPaddr:nn' format\n"
14154
14155 DEFUN (ip_extcommunity_list_standard,
14156 ip_extcommunity_list_standard_cmd,
14157 "ip extcommunity-list <(1-99)|standard WORD> <deny|permit> AA:NN...",
14158 IP_STR
14159 EXTCOMMUNITY_LIST_STR
14160 "Extended Community list number (standard)\n"
14161 "Specify standard extcommunity-list\n"
14162 "Community list name\n"
14163 "Specify community to reject\n"
14164 "Specify community to accept\n"
14165 EXTCOMMUNITY_VAL_STR)
14166 {
14167 int style = EXTCOMMUNITY_LIST_STANDARD;
14168 int direct = 0;
14169 char *cl_number_or_name = NULL;
14170
14171 int idx = 0;
14172 argv_find(argv, argc, "(1-99)", &idx);
14173 argv_find(argv, argc, "WORD", &idx);
14174 cl_number_or_name = argv[idx]->arg;
14175 direct = argv_find(argv, argc, "permit", &idx) ? COMMUNITY_PERMIT
14176 : COMMUNITY_DENY;
14177 argv_find(argv, argc, "AA:NN", &idx);
14178 char *str = argv_concat(argv, argc, idx);
14179
14180 int ret = extcommunity_list_set(bgp_clist, cl_number_or_name, str,
14181 direct, style);
14182
14183 XFREE(MTYPE_TMP, str);
14184
14185 if (ret < 0) {
14186 community_list_perror(vty, ret);
14187 return CMD_WARNING_CONFIG_FAILED;
14188 }
14189
14190 return CMD_SUCCESS;
14191 }
14192
14193 DEFUN (ip_extcommunity_list_name_expanded,
14194 ip_extcommunity_list_name_expanded_cmd,
14195 "ip extcommunity-list <(100-500)|expanded WORD> <deny|permit> LINE...",
14196 IP_STR
14197 EXTCOMMUNITY_LIST_STR
14198 "Extended Community list number (expanded)\n"
14199 "Specify expanded extcommunity-list\n"
14200 "Extended Community list name\n"
14201 "Specify community to reject\n"
14202 "Specify community to accept\n"
14203 "An ordered list as a regular-expression\n")
14204 {
14205 int style = EXTCOMMUNITY_LIST_EXPANDED;
14206 int direct = 0;
14207 char *cl_number_or_name = NULL;
14208
14209 int idx = 0;
14210 argv_find(argv, argc, "(100-500)", &idx);
14211 argv_find(argv, argc, "WORD", &idx);
14212 cl_number_or_name = argv[idx]->arg;
14213 direct = argv_find(argv, argc, "permit", &idx) ? COMMUNITY_PERMIT
14214 : COMMUNITY_DENY;
14215 argv_find(argv, argc, "LINE", &idx);
14216 char *str = argv_concat(argv, argc, idx);
14217
14218 int ret = extcommunity_list_set(bgp_clist, cl_number_or_name, str,
14219 direct, style);
14220
14221 XFREE(MTYPE_TMP, str);
14222
14223 if (ret < 0) {
14224 community_list_perror(vty, ret);
14225 return CMD_WARNING_CONFIG_FAILED;
14226 }
14227
14228 return CMD_SUCCESS;
14229 }
14230
14231 DEFUN (no_ip_extcommunity_list_standard_all,
14232 no_ip_extcommunity_list_standard_all_cmd,
14233 "no ip extcommunity-list <(1-99)|standard WORD> <deny|permit> AA:NN...",
14234 NO_STR
14235 IP_STR
14236 EXTCOMMUNITY_LIST_STR
14237 "Extended Community list number (standard)\n"
14238 "Specify standard extcommunity-list\n"
14239 "Community list name\n"
14240 "Specify community to reject\n"
14241 "Specify community to accept\n"
14242 EXTCOMMUNITY_VAL_STR)
14243 {
14244 int style = EXTCOMMUNITY_LIST_STANDARD;
14245 int direct = 0;
14246 char *cl_number_or_name = NULL;
14247
14248 int idx = 0;
14249 argv_find(argv, argc, "(1-99)", &idx);
14250 argv_find(argv, argc, "WORD", &idx);
14251 cl_number_or_name = argv[idx]->arg;
14252 direct = argv_find(argv, argc, "permit", &idx) ? COMMUNITY_PERMIT
14253 : COMMUNITY_DENY;
14254 argv_find(argv, argc, "AA:NN", &idx);
14255 char *str = argv_concat(argv, argc, idx);
14256
14257 int ret = extcommunity_list_unset(bgp_clist, cl_number_or_name, str,
14258 direct, style);
14259
14260 XFREE(MTYPE_TMP, str);
14261
14262 if (ret < 0) {
14263 community_list_perror(vty, ret);
14264 return CMD_WARNING_CONFIG_FAILED;
14265 }
14266
14267 return CMD_SUCCESS;
14268 }
14269
14270 DEFUN (no_ip_extcommunity_list_expanded_all,
14271 no_ip_extcommunity_list_expanded_all_cmd,
14272 "no ip extcommunity-list <(100-500)|expanded WORD> <deny|permit> LINE...",
14273 NO_STR
14274 IP_STR
14275 EXTCOMMUNITY_LIST_STR
14276 "Extended Community list number (expanded)\n"
14277 "Specify expanded extcommunity-list\n"
14278 "Extended Community list name\n"
14279 "Specify community to reject\n"
14280 "Specify community to accept\n"
14281 "An ordered list as a regular-expression\n")
14282 {
14283 int style = EXTCOMMUNITY_LIST_EXPANDED;
14284 int direct = 0;
14285 char *cl_number_or_name = NULL;
14286
14287 int idx = 0;
14288 argv_find(argv, argc, "(100-500)", &idx);
14289 argv_find(argv, argc, "WORD", &idx);
14290 cl_number_or_name = argv[idx]->arg;
14291 direct = argv_find(argv, argc, "permit", &idx) ? COMMUNITY_PERMIT
14292 : COMMUNITY_DENY;
14293 argv_find(argv, argc, "LINE", &idx);
14294 char *str = argv_concat(argv, argc, idx);
14295
14296 int ret = extcommunity_list_unset(bgp_clist, cl_number_or_name, str,
14297 direct, style);
14298
14299 XFREE(MTYPE_TMP, str);
14300
14301 if (ret < 0) {
14302 community_list_perror(vty, ret);
14303 return CMD_WARNING_CONFIG_FAILED;
14304 }
14305
14306 return CMD_SUCCESS;
14307 }
14308
14309 static void extcommunity_list_show(struct vty *vty, struct community_list *list)
14310 {
14311 struct community_entry *entry;
14312
14313 for (entry = list->head; entry; entry = entry->next) {
14314 if (entry == list->head) {
14315 if (all_digit(list->name))
14316 vty_out(vty, "Extended community %s list %s\n",
14317 entry->style == EXTCOMMUNITY_LIST_STANDARD
14318 ? "standard"
14319 : "(expanded) access",
14320 list->name);
14321 else
14322 vty_out(vty,
14323 "Named extended community %s list %s\n",
14324 entry->style == EXTCOMMUNITY_LIST_STANDARD
14325 ? "standard"
14326 : "expanded",
14327 list->name);
14328 }
14329 if (entry->any)
14330 vty_out(vty, " %s\n",
14331 community_direct_str(entry->direct));
14332 else
14333 vty_out(vty, " %s %s\n",
14334 community_direct_str(entry->direct),
14335 community_list_config_str(entry));
14336 }
14337 }
14338
14339 DEFUN (show_ip_extcommunity_list,
14340 show_ip_extcommunity_list_cmd,
14341 "show ip extcommunity-list",
14342 SHOW_STR
14343 IP_STR
14344 "List extended-community list\n")
14345 {
14346 struct community_list *list;
14347 struct community_list_master *cm;
14348
14349 cm = community_list_master_lookup(bgp_clist, EXTCOMMUNITY_LIST_MASTER);
14350 if (!cm)
14351 return CMD_SUCCESS;
14352
14353 for (list = cm->num.head; list; list = list->next)
14354 extcommunity_list_show(vty, list);
14355
14356 for (list = cm->str.head; list; list = list->next)
14357 extcommunity_list_show(vty, list);
14358
14359 return CMD_SUCCESS;
14360 }
14361
14362 DEFUN (show_ip_extcommunity_list_arg,
14363 show_ip_extcommunity_list_arg_cmd,
14364 "show ip extcommunity-list <(1-500)|WORD>",
14365 SHOW_STR
14366 IP_STR
14367 "List extended-community list\n"
14368 "Extcommunity-list number\n"
14369 "Extcommunity-list name\n")
14370 {
14371 int idx_comm_list = 3;
14372 struct community_list *list;
14373
14374 list = community_list_lookup(bgp_clist, argv[idx_comm_list]->arg,
14375 EXTCOMMUNITY_LIST_MASTER);
14376 if (!list) {
14377 vty_out(vty, "%% Can't find extcommunity-list\n");
14378 return CMD_WARNING;
14379 }
14380
14381 extcommunity_list_show(vty, list);
14382
14383 return CMD_SUCCESS;
14384 }
14385
14386 /* Display community-list and extcommunity-list configuration. */
14387 static int community_list_config_write(struct vty *vty)
14388 {
14389 struct community_list *list;
14390 struct community_entry *entry;
14391 struct community_list_master *cm;
14392 int write = 0;
14393
14394 /* Community-list. */
14395 cm = community_list_master_lookup(bgp_clist, COMMUNITY_LIST_MASTER);
14396
14397 for (list = cm->num.head; list; list = list->next)
14398 for (entry = list->head; entry; entry = entry->next) {
14399 vty_out(vty, "ip community-list %s %s %s\n", list->name,
14400 community_direct_str(entry->direct),
14401 community_list_config_str(entry));
14402 write++;
14403 }
14404 for (list = cm->str.head; list; list = list->next)
14405 for (entry = list->head; entry; entry = entry->next) {
14406 vty_out(vty, "ip community-list %s %s %s %s\n",
14407 entry->style == COMMUNITY_LIST_STANDARD
14408 ? "standard"
14409 : "expanded",
14410 list->name, community_direct_str(entry->direct),
14411 community_list_config_str(entry));
14412 write++;
14413 }
14414
14415 /* Extcommunity-list. */
14416 cm = community_list_master_lookup(bgp_clist, EXTCOMMUNITY_LIST_MASTER);
14417
14418 for (list = cm->num.head; list; list = list->next)
14419 for (entry = list->head; entry; entry = entry->next) {
14420 vty_out(vty, "ip extcommunity-list %s %s %s\n",
14421 list->name, community_direct_str(entry->direct),
14422 community_list_config_str(entry));
14423 write++;
14424 }
14425 for (list = cm->str.head; list; list = list->next)
14426 for (entry = list->head; entry; entry = entry->next) {
14427 vty_out(vty, "ip extcommunity-list %s %s %s %s\n",
14428 entry->style == EXTCOMMUNITY_LIST_STANDARD
14429 ? "standard"
14430 : "expanded",
14431 list->name, community_direct_str(entry->direct),
14432 community_list_config_str(entry));
14433 write++;
14434 }
14435
14436
14437 /* lcommunity-list. */
14438 cm = community_list_master_lookup(bgp_clist,
14439 LARGE_COMMUNITY_LIST_MASTER);
14440
14441 for (list = cm->num.head; list; list = list->next)
14442 for (entry = list->head; entry; entry = entry->next) {
14443 vty_out(vty, "ip large-community-list %s %s %s\n",
14444 list->name, community_direct_str(entry->direct),
14445 community_list_config_str(entry));
14446 write++;
14447 }
14448 for (list = cm->str.head; list; list = list->next)
14449 for (entry = list->head; entry; entry = entry->next) {
14450 vty_out(vty, "ip large-community-list %s %s %s %s\n",
14451 entry->style == LARGE_COMMUNITY_LIST_STANDARD
14452 ? "standard"
14453 : "expanded",
14454 list->name, community_direct_str(entry->direct),
14455 community_list_config_str(entry));
14456 write++;
14457 }
14458
14459 return write;
14460 }
14461
14462 static struct cmd_node community_list_node = {
14463 COMMUNITY_LIST_NODE, "", 1 /* Export to vtysh. */
14464 };
14465
14466 static void community_list_vty(void)
14467 {
14468 install_node(&community_list_node, community_list_config_write);
14469
14470 /* Community-list. */
14471 install_element(CONFIG_NODE, &ip_community_list_standard_cmd);
14472 install_element(CONFIG_NODE, &ip_community_list_expanded_all_cmd);
14473 install_element(CONFIG_NODE, &no_ip_community_list_standard_all_cmd);
14474 install_element(CONFIG_NODE, &no_ip_community_list_expanded_all_cmd);
14475 install_element(VIEW_NODE, &show_ip_community_list_cmd);
14476 install_element(VIEW_NODE, &show_ip_community_list_arg_cmd);
14477
14478 /* Extcommunity-list. */
14479 install_element(CONFIG_NODE, &ip_extcommunity_list_standard_cmd);
14480 install_element(CONFIG_NODE, &ip_extcommunity_list_name_expanded_cmd);
14481 install_element(CONFIG_NODE, &no_ip_extcommunity_list_standard_all_cmd);
14482 install_element(CONFIG_NODE, &no_ip_extcommunity_list_expanded_all_cmd);
14483 install_element(VIEW_NODE, &show_ip_extcommunity_list_cmd);
14484 install_element(VIEW_NODE, &show_ip_extcommunity_list_arg_cmd);
14485
14486 /* Large Community List */
14487 install_element(CONFIG_NODE, &ip_lcommunity_list_standard_cmd);
14488 install_element(CONFIG_NODE, &ip_lcommunity_list_standard1_cmd);
14489 install_element(CONFIG_NODE, &ip_lcommunity_list_expanded_cmd);
14490 install_element(CONFIG_NODE, &ip_lcommunity_list_name_standard_cmd);
14491 install_element(CONFIG_NODE, &ip_lcommunity_list_name_standard1_cmd);
14492 install_element(CONFIG_NODE, &ip_lcommunity_list_name_expanded_cmd);
14493 install_element(CONFIG_NODE, &no_ip_lcommunity_list_standard_all_cmd);
14494 install_element(CONFIG_NODE,
14495 &no_ip_lcommunity_list_name_expanded_all_cmd);
14496 install_element(CONFIG_NODE, &no_ip_lcommunity_list_standard_cmd);
14497 install_element(CONFIG_NODE, &no_ip_lcommunity_list_expanded_cmd);
14498 install_element(CONFIG_NODE, &no_ip_lcommunity_list_name_standard_cmd);
14499 install_element(CONFIG_NODE, &no_ip_lcommunity_list_name_expanded_cmd);
14500 install_element(VIEW_NODE, &show_ip_lcommunity_list_cmd);
14501 install_element(VIEW_NODE, &show_ip_lcommunity_list_arg_cmd);
14502 }