]> git.proxmox.com Git - mirror_frr.git/blob - bgpd/bgp_vty.c
Merge pull request #2731 from chiragshah6/mdev
[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 dn_count++;
7919 json_object_boolean_true_add(json_peer,
7920 "dynamicPeer");
7921 }
7922
7923 if (peer->hostname)
7924 json_object_string_add(json_peer, "hostname",
7925 peer->hostname);
7926
7927 if (peer->domainname)
7928 json_object_string_add(json_peer, "domainname",
7929 peer->domainname);
7930
7931 json_object_int_add(json_peer, "remoteAs", peer->as);
7932 json_object_int_add(json_peer, "version", 4);
7933 json_object_int_add(json_peer, "msgRcvd",
7934 PEER_TOTAL_RX(peer));
7935 json_object_int_add(json_peer, "msgSent",
7936 PEER_TOTAL_TX(peer));
7937
7938 json_object_int_add(json_peer, "tableVersion",
7939 peer->version[afi][safi]);
7940 json_object_int_add(json_peer, "outq",
7941 peer->obuf->count);
7942 json_object_int_add(json_peer, "inq", 0);
7943 peer_uptime(peer->uptime, timebuf, BGP_UPTIME_LEN,
7944 use_json, json_peer);
7945 json_object_int_add(json_peer, "prefixReceivedCount",
7946 peer->pcount[afi][pfx_rcd_safi]);
7947
7948 if (CHECK_FLAG(peer->flags, PEER_FLAG_SHUTDOWN))
7949 json_object_string_add(json_peer, "state",
7950 "Idle (Admin)");
7951 else if (peer->afc_recv[afi][safi])
7952 json_object_string_add(
7953 json_peer, "state",
7954 lookup_msg(bgp_status_msg, peer->status,
7955 NULL));
7956 else if (CHECK_FLAG(peer->sflags,
7957 PEER_STATUS_PREFIX_OVERFLOW))
7958 json_object_string_add(json_peer, "state",
7959 "Idle (PfxCt)");
7960 else
7961 json_object_string_add(
7962 json_peer, "state",
7963 lookup_msg(bgp_status_msg, peer->status,
7964 NULL));
7965
7966 if (peer->conf_if)
7967 json_object_string_add(json_peer, "idType",
7968 "interface");
7969 else if (peer->su.sa.sa_family == AF_INET)
7970 json_object_string_add(json_peer, "idType",
7971 "ipv4");
7972 else if (peer->su.sa.sa_family == AF_INET6)
7973 json_object_string_add(json_peer, "idType",
7974 "ipv6");
7975
7976 json_object_object_add(json_peers, peer->host,
7977 json_peer);
7978 } else {
7979 memset(dn_flag, '\0', sizeof(dn_flag));
7980 if (peer_dynamic_neighbor(peer)) {
7981 dn_count++;
7982 dn_flag[0] = '*';
7983 }
7984
7985 if (peer->hostname
7986 && bgp_flag_check(bgp, BGP_FLAG_SHOW_HOSTNAME))
7987 len = vty_out(vty, "%s%s(%s)", dn_flag,
7988 peer->hostname, peer->host);
7989 else
7990 len = vty_out(vty, "%s%s", dn_flag, peer->host);
7991
7992 /* pad the neighbor column with spaces */
7993 if (len < max_neighbor_width)
7994 vty_out(vty, "%*s", max_neighbor_width - len,
7995 " ");
7996
7997 vty_out(vty, "4 %10u %7u %7u %8" PRIu64 " %4d %4zd %8s",
7998 peer->as, PEER_TOTAL_RX(peer),
7999 PEER_TOTAL_TX(peer), peer->version[afi][safi],
8000 0, peer->obuf->count,
8001 peer_uptime(peer->uptime, timebuf,
8002 BGP_UPTIME_LEN, 0, NULL));
8003
8004 if (peer->status == Established)
8005 if (peer->afc_recv[afi][safi])
8006 vty_out(vty, " %12ld",
8007 peer->pcount[afi]
8008 [pfx_rcd_safi]);
8009 else
8010 vty_out(vty, " NoNeg");
8011 else {
8012 if (CHECK_FLAG(peer->flags, PEER_FLAG_SHUTDOWN))
8013 vty_out(vty, " Idle (Admin)");
8014 else if (CHECK_FLAG(
8015 peer->sflags,
8016 PEER_STATUS_PREFIX_OVERFLOW))
8017 vty_out(vty, " Idle (PfxCt)");
8018 else
8019 vty_out(vty, " %12s",
8020 lookup_msg(bgp_status_msg,
8021 peer->status, NULL));
8022 }
8023 vty_out(vty, "\n");
8024 }
8025 }
8026
8027 if (use_json) {
8028 json_object_object_add(json, "peers", json_peers);
8029
8030 json_object_int_add(json, "totalPeers", count);
8031 json_object_int_add(json, "dynamicPeers", dn_count);
8032
8033 bgp_show_bestpath_json(bgp, json);
8034
8035 vty_out(vty, "%s\n", json_object_to_json_string_ext(
8036 json, JSON_C_TO_STRING_PRETTY));
8037 json_object_free(json);
8038 } else {
8039 if (count)
8040 vty_out(vty, "\nTotal number of neighbors %d\n", count);
8041 else {
8042 vty_out(vty, "No %s neighbor is configured\n",
8043 afi_safi_print(afi, safi));
8044 }
8045
8046 if (dn_count) {
8047 vty_out(vty, "* - dynamic neighbor\n");
8048 vty_out(vty, "%d dynamic neighbor(s), limit %d\n",
8049 dn_count, bgp->dynamic_neighbors_limit);
8050 }
8051 }
8052
8053 return CMD_SUCCESS;
8054 }
8055
8056 static void bgp_show_summary_afi_safi(struct vty *vty, struct bgp *bgp, int afi,
8057 int safi, uint8_t use_json,
8058 json_object *json)
8059 {
8060 int is_first = 1;
8061 int afi_wildcard = (afi == AFI_MAX);
8062 int safi_wildcard = (safi == SAFI_MAX);
8063 int is_wildcard = (afi_wildcard || safi_wildcard);
8064 bool json_output = false;
8065
8066 if (use_json && is_wildcard)
8067 vty_out(vty, "{\n");
8068 if (afi_wildcard)
8069 afi = 1; /* AFI_IP */
8070 while (afi < AFI_MAX) {
8071 if (safi_wildcard)
8072 safi = 1; /* SAFI_UNICAST */
8073 while (safi < SAFI_MAX) {
8074 if (bgp_afi_safi_peer_exists(bgp, afi, safi)) {
8075 json_output = true;
8076 if (is_wildcard) {
8077 /*
8078 * So limit output to those afi/safi
8079 * pairs that
8080 * actualy have something interesting in
8081 * them
8082 */
8083 if (use_json) {
8084 json = json_object_new_object();
8085
8086 if (!is_first)
8087 vty_out(vty, ",\n");
8088 else
8089 is_first = 0;
8090
8091 vty_out(vty, "\"%s\":",
8092 afi_safi_json(afi,
8093 safi));
8094 } else {
8095 vty_out(vty, "\n%s Summary:\n",
8096 afi_safi_print(afi,
8097 safi));
8098 }
8099 }
8100 bgp_show_summary(vty, bgp, afi, safi, use_json,
8101 json);
8102 }
8103 safi++;
8104 if (!safi_wildcard)
8105 safi = SAFI_MAX;
8106 }
8107 afi++;
8108 if (!afi_wildcard)
8109 afi = AFI_MAX;
8110 }
8111
8112 if (use_json && is_wildcard)
8113 vty_out(vty, "}\n");
8114 else if (use_json && !json_output)
8115 vty_out(vty, "{}\n");
8116 }
8117
8118 static void bgp_show_all_instances_summary_vty(struct vty *vty, afi_t afi,
8119 safi_t safi, uint8_t use_json)
8120 {
8121 struct listnode *node, *nnode;
8122 struct bgp *bgp;
8123 json_object *json = NULL;
8124 int is_first = 1;
8125
8126 if (use_json)
8127 vty_out(vty, "{\n");
8128
8129 for (ALL_LIST_ELEMENTS(bm->bgp, node, nnode, bgp)) {
8130 if (use_json) {
8131 json = json_object_new_object();
8132
8133 if (!is_first)
8134 vty_out(vty, ",\n");
8135 else
8136 is_first = 0;
8137
8138 vty_out(vty, "\"%s\":",
8139 (bgp->inst_type == BGP_INSTANCE_TYPE_DEFAULT)
8140 ? "Default"
8141 : bgp->name);
8142 } else {
8143 vty_out(vty, "\nInstance %s:\n",
8144 (bgp->inst_type == BGP_INSTANCE_TYPE_DEFAULT)
8145 ? "Default"
8146 : bgp->name);
8147 }
8148 bgp_show_summary_afi_safi(vty, bgp, afi, safi, use_json, json);
8149 }
8150
8151 if (use_json)
8152 vty_out(vty, "}\n");
8153 }
8154
8155 int bgp_show_summary_vty(struct vty *vty, const char *name, afi_t afi,
8156 safi_t safi, uint8_t use_json)
8157 {
8158 struct bgp *bgp;
8159
8160 if (name) {
8161 if (strmatch(name, "all")) {
8162 bgp_show_all_instances_summary_vty(vty, afi, safi,
8163 use_json);
8164 return CMD_SUCCESS;
8165 } else {
8166 bgp = bgp_lookup_by_name(name);
8167
8168 if (!bgp) {
8169 if (use_json)
8170 vty_out(vty, "{}\n");
8171 else
8172 vty_out(vty,
8173 "%% No such BGP instance exist\n");
8174 return CMD_WARNING;
8175 }
8176
8177 bgp_show_summary_afi_safi(vty, bgp, afi, safi, use_json,
8178 NULL);
8179 return CMD_SUCCESS;
8180 }
8181 }
8182
8183 bgp = bgp_get_default();
8184
8185 if (bgp)
8186 bgp_show_summary_afi_safi(vty, bgp, afi, safi, use_json, NULL);
8187
8188 return CMD_SUCCESS;
8189 }
8190
8191 /* `show [ip] bgp summary' commands. */
8192 DEFUN (show_ip_bgp_summary,
8193 show_ip_bgp_summary_cmd,
8194 "show [ip] bgp [<view|vrf> VIEWVRFNAME] ["BGP_AFI_CMD_STR" ["BGP_SAFI_WITH_LABEL_CMD_STR"]] summary [json]",
8195 SHOW_STR
8196 IP_STR
8197 BGP_STR
8198 BGP_INSTANCE_HELP_STR
8199 BGP_AFI_HELP_STR
8200 BGP_SAFI_WITH_LABEL_HELP_STR
8201 "Summary of BGP neighbor status\n"
8202 JSON_STR)
8203 {
8204 char *vrf = NULL;
8205 afi_t afi = AFI_MAX;
8206 safi_t safi = SAFI_MAX;
8207
8208 int idx = 0;
8209
8210 /* show [ip] bgp */
8211 if (argv_find(argv, argc, "ip", &idx))
8212 afi = AFI_IP;
8213 /* [<view|vrf> VIEWVRFNAME] */
8214 if (argv_find(argv, argc, "view", &idx)
8215 || argv_find(argv, argc, "vrf", &idx))
8216 vrf = argv[++idx]->arg;
8217 /* ["BGP_AFI_CMD_STR" ["BGP_SAFI_CMD_STR"]] */
8218 if (argv_find_and_parse_afi(argv, argc, &idx, &afi)) {
8219 argv_find_and_parse_safi(argv, argc, &idx, &safi);
8220 }
8221
8222 int uj = use_json(argc, argv);
8223
8224 return bgp_show_summary_vty(vty, vrf, afi, safi, uj);
8225 }
8226
8227 const char *afi_safi_print(afi_t afi, safi_t safi)
8228 {
8229 if (afi == AFI_IP && safi == SAFI_UNICAST)
8230 return "IPv4 Unicast";
8231 else if (afi == AFI_IP && safi == SAFI_MULTICAST)
8232 return "IPv4 Multicast";
8233 else if (afi == AFI_IP && safi == SAFI_LABELED_UNICAST)
8234 return "IPv4 Labeled Unicast";
8235 else if (afi == AFI_IP && safi == SAFI_MPLS_VPN)
8236 return "IPv4 VPN";
8237 else if (afi == AFI_IP && safi == SAFI_ENCAP)
8238 return "IPv4 Encap";
8239 else if (afi == AFI_IP && safi == SAFI_FLOWSPEC)
8240 return "IPv4 Flowspec";
8241 else if (afi == AFI_IP6 && safi == SAFI_UNICAST)
8242 return "IPv6 Unicast";
8243 else if (afi == AFI_IP6 && safi == SAFI_MULTICAST)
8244 return "IPv6 Multicast";
8245 else if (afi == AFI_IP6 && safi == SAFI_LABELED_UNICAST)
8246 return "IPv6 Labeled Unicast";
8247 else if (afi == AFI_IP6 && safi == SAFI_MPLS_VPN)
8248 return "IPv6 VPN";
8249 else if (afi == AFI_IP6 && safi == SAFI_ENCAP)
8250 return "IPv6 Encap";
8251 else if (afi == AFI_IP6 && safi == SAFI_FLOWSPEC)
8252 return "IPv6 Flowspec";
8253 else if (afi == AFI_L2VPN && safi == SAFI_EVPN)
8254 return "L2VPN EVPN";
8255 else
8256 return "Unknown";
8257 }
8258
8259 /*
8260 * Please note that we have intentionally camelCased
8261 * the return strings here. So if you want
8262 * to use this function, please ensure you
8263 * are doing this within json output
8264 */
8265 const char *afi_safi_json(afi_t afi, safi_t safi)
8266 {
8267 if (afi == AFI_IP && safi == SAFI_UNICAST)
8268 return "ipv4Unicast";
8269 else if (afi == AFI_IP && safi == SAFI_MULTICAST)
8270 return "ipv4Multicast";
8271 else if (afi == AFI_IP && safi == SAFI_LABELED_UNICAST)
8272 return "ipv4LabeledUnicast";
8273 else if (afi == AFI_IP && safi == SAFI_MPLS_VPN)
8274 return "ipv4Vpn";
8275 else if (afi == AFI_IP && safi == SAFI_ENCAP)
8276 return "ipv4Encap";
8277 else if (afi == AFI_IP && safi == SAFI_FLOWSPEC)
8278 return "ipv4Flowspec";
8279 else if (afi == AFI_IP6 && safi == SAFI_UNICAST)
8280 return "ipv6Unicast";
8281 else if (afi == AFI_IP6 && safi == SAFI_MULTICAST)
8282 return "ipv6Multicast";
8283 else if (afi == AFI_IP6 && safi == SAFI_LABELED_UNICAST)
8284 return "ipv6LabeledUnicast";
8285 else if (afi == AFI_IP6 && safi == SAFI_MPLS_VPN)
8286 return "ipv6Vpn";
8287 else if (afi == AFI_IP6 && safi == SAFI_ENCAP)
8288 return "ipv6Encap";
8289 else if (afi == AFI_IP6 && safi == SAFI_FLOWSPEC)
8290 return "ipv6Flowspec";
8291 else if (afi == AFI_L2VPN && safi == SAFI_EVPN)
8292 return "l2VpnEvpn";
8293 else
8294 return "Unknown";
8295 }
8296
8297 /* Show BGP peer's information. */
8298 enum show_type { show_all, show_peer };
8299
8300 static void bgp_show_peer_afi_orf_cap(struct vty *vty, struct peer *p,
8301 afi_t afi, safi_t safi,
8302 uint16_t adv_smcap, uint16_t adv_rmcap,
8303 uint16_t rcv_smcap, uint16_t rcv_rmcap,
8304 uint8_t use_json, json_object *json_pref)
8305 {
8306 /* Send-Mode */
8307 if (CHECK_FLAG(p->af_cap[afi][safi], adv_smcap)
8308 || CHECK_FLAG(p->af_cap[afi][safi], rcv_smcap)) {
8309 if (use_json) {
8310 if (CHECK_FLAG(p->af_cap[afi][safi], adv_smcap)
8311 && CHECK_FLAG(p->af_cap[afi][safi], rcv_smcap))
8312 json_object_string_add(json_pref, "sendMode",
8313 "advertisedAndReceived");
8314 else if (CHECK_FLAG(p->af_cap[afi][safi], adv_smcap))
8315 json_object_string_add(json_pref, "sendMode",
8316 "advertised");
8317 else if (CHECK_FLAG(p->af_cap[afi][safi], rcv_smcap))
8318 json_object_string_add(json_pref, "sendMode",
8319 "received");
8320 } else {
8321 vty_out(vty, " Send-mode: ");
8322 if (CHECK_FLAG(p->af_cap[afi][safi], adv_smcap))
8323 vty_out(vty, "advertised");
8324 if (CHECK_FLAG(p->af_cap[afi][safi], rcv_smcap))
8325 vty_out(vty, "%sreceived",
8326 CHECK_FLAG(p->af_cap[afi][safi],
8327 adv_smcap)
8328 ? ", "
8329 : "");
8330 vty_out(vty, "\n");
8331 }
8332 }
8333
8334 /* Receive-Mode */
8335 if (CHECK_FLAG(p->af_cap[afi][safi], adv_rmcap)
8336 || CHECK_FLAG(p->af_cap[afi][safi], rcv_rmcap)) {
8337 if (use_json) {
8338 if (CHECK_FLAG(p->af_cap[afi][safi], adv_rmcap)
8339 && CHECK_FLAG(p->af_cap[afi][safi], rcv_rmcap))
8340 json_object_string_add(json_pref, "recvMode",
8341 "advertisedAndReceived");
8342 else if (CHECK_FLAG(p->af_cap[afi][safi], adv_rmcap))
8343 json_object_string_add(json_pref, "recvMode",
8344 "advertised");
8345 else if (CHECK_FLAG(p->af_cap[afi][safi], rcv_rmcap))
8346 json_object_string_add(json_pref, "recvMode",
8347 "received");
8348 } else {
8349 vty_out(vty, " Receive-mode: ");
8350 if (CHECK_FLAG(p->af_cap[afi][safi], adv_rmcap))
8351 vty_out(vty, "advertised");
8352 if (CHECK_FLAG(p->af_cap[afi][safi], rcv_rmcap))
8353 vty_out(vty, "%sreceived",
8354 CHECK_FLAG(p->af_cap[afi][safi],
8355 adv_rmcap)
8356 ? ", "
8357 : "");
8358 vty_out(vty, "\n");
8359 }
8360 }
8361 }
8362
8363 static void bgp_show_peer_afi(struct vty *vty, struct peer *p, afi_t afi,
8364 safi_t safi, uint8_t use_json,
8365 json_object *json_neigh)
8366 {
8367 struct bgp_filter *filter;
8368 struct peer_af *paf;
8369 char orf_pfx_name[BUFSIZ];
8370 int orf_pfx_count;
8371 json_object *json_af = NULL;
8372 json_object *json_prefA = NULL;
8373 json_object *json_prefB = NULL;
8374 json_object *json_addr = NULL;
8375
8376 if (use_json) {
8377 json_addr = json_object_new_object();
8378 json_af = json_object_new_object();
8379 filter = &p->filter[afi][safi];
8380
8381 if (peer_group_active(p))
8382 json_object_string_add(json_addr, "peerGroupMember",
8383 p->group->name);
8384
8385 paf = peer_af_find(p, afi, safi);
8386 if (paf && PAF_SUBGRP(paf)) {
8387 json_object_int_add(json_addr, "updateGroupId",
8388 PAF_UPDGRP(paf)->id);
8389 json_object_int_add(json_addr, "subGroupId",
8390 PAF_SUBGRP(paf)->id);
8391 json_object_int_add(json_addr, "packetQueueLength",
8392 bpacket_queue_virtual_length(paf));
8393 }
8394
8395 if (CHECK_FLAG(p->af_cap[afi][safi], PEER_CAP_ORF_PREFIX_SM_ADV)
8396 || CHECK_FLAG(p->af_cap[afi][safi],
8397 PEER_CAP_ORF_PREFIX_SM_RCV)
8398 || CHECK_FLAG(p->af_cap[afi][safi],
8399 PEER_CAP_ORF_PREFIX_RM_ADV)
8400 || CHECK_FLAG(p->af_cap[afi][safi],
8401 PEER_CAP_ORF_PREFIX_RM_RCV)) {
8402 json_object_int_add(json_af, "orfType",
8403 ORF_TYPE_PREFIX);
8404 json_prefA = json_object_new_object();
8405 bgp_show_peer_afi_orf_cap(vty, p, afi, safi,
8406 PEER_CAP_ORF_PREFIX_SM_ADV,
8407 PEER_CAP_ORF_PREFIX_RM_ADV,
8408 PEER_CAP_ORF_PREFIX_SM_RCV,
8409 PEER_CAP_ORF_PREFIX_RM_RCV,
8410 use_json, json_prefA);
8411 json_object_object_add(json_af, "orfPrefixList",
8412 json_prefA);
8413 }
8414
8415 if (CHECK_FLAG(p->af_cap[afi][safi], PEER_CAP_ORF_PREFIX_SM_ADV)
8416 || CHECK_FLAG(p->af_cap[afi][safi],
8417 PEER_CAP_ORF_PREFIX_SM_OLD_RCV)
8418 || CHECK_FLAG(p->af_cap[afi][safi],
8419 PEER_CAP_ORF_PREFIX_RM_ADV)
8420 || CHECK_FLAG(p->af_cap[afi][safi],
8421 PEER_CAP_ORF_PREFIX_RM_OLD_RCV)) {
8422 json_object_int_add(json_af, "orfOldType",
8423 ORF_TYPE_PREFIX_OLD);
8424 json_prefB = json_object_new_object();
8425 bgp_show_peer_afi_orf_cap(
8426 vty, p, afi, safi, PEER_CAP_ORF_PREFIX_SM_ADV,
8427 PEER_CAP_ORF_PREFIX_RM_ADV,
8428 PEER_CAP_ORF_PREFIX_SM_OLD_RCV,
8429 PEER_CAP_ORF_PREFIX_RM_OLD_RCV, use_json,
8430 json_prefB);
8431 json_object_object_add(json_af, "orfOldPrefixList",
8432 json_prefB);
8433 }
8434
8435 if (CHECK_FLAG(p->af_cap[afi][safi], PEER_CAP_ORF_PREFIX_SM_ADV)
8436 || CHECK_FLAG(p->af_cap[afi][safi],
8437 PEER_CAP_ORF_PREFIX_SM_RCV)
8438 || CHECK_FLAG(p->af_cap[afi][safi],
8439 PEER_CAP_ORF_PREFIX_SM_OLD_RCV)
8440 || CHECK_FLAG(p->af_cap[afi][safi],
8441 PEER_CAP_ORF_PREFIX_RM_ADV)
8442 || CHECK_FLAG(p->af_cap[afi][safi],
8443 PEER_CAP_ORF_PREFIX_RM_RCV)
8444 || CHECK_FLAG(p->af_cap[afi][safi],
8445 PEER_CAP_ORF_PREFIX_RM_OLD_RCV))
8446 json_object_object_add(json_addr, "afDependentCap",
8447 json_af);
8448 else
8449 json_object_free(json_af);
8450
8451 sprintf(orf_pfx_name, "%s.%d.%d", p->host, afi, safi);
8452 orf_pfx_count = prefix_bgp_show_prefix_list(
8453 NULL, afi, orf_pfx_name, use_json);
8454
8455 if (CHECK_FLAG(p->af_sflags[afi][safi],
8456 PEER_STATUS_ORF_PREFIX_SEND)
8457 || orf_pfx_count) {
8458 if (CHECK_FLAG(p->af_sflags[afi][safi],
8459 PEER_STATUS_ORF_PREFIX_SEND))
8460 json_object_boolean_true_add(json_neigh,
8461 "orfSent");
8462 if (orf_pfx_count)
8463 json_object_int_add(json_addr, "orfRecvCounter",
8464 orf_pfx_count);
8465 }
8466 if (CHECK_FLAG(p->af_sflags[afi][safi],
8467 PEER_STATUS_ORF_WAIT_REFRESH))
8468 json_object_string_add(
8469 json_addr, "orfFirstUpdate",
8470 "deferredUntilORFOrRouteRefreshRecvd");
8471
8472 if (CHECK_FLAG(p->af_flags[afi][safi],
8473 PEER_FLAG_REFLECTOR_CLIENT))
8474 json_object_boolean_true_add(json_addr,
8475 "routeReflectorClient");
8476 if (CHECK_FLAG(p->af_flags[afi][safi],
8477 PEER_FLAG_RSERVER_CLIENT))
8478 json_object_boolean_true_add(json_addr,
8479 "routeServerClient");
8480 if (CHECK_FLAG(p->af_flags[afi][safi], PEER_FLAG_SOFT_RECONFIG))
8481 json_object_boolean_true_add(json_addr,
8482 "inboundSoftConfigPermit");
8483
8484 if (CHECK_FLAG(p->af_flags[afi][safi],
8485 PEER_FLAG_REMOVE_PRIVATE_AS_ALL_REPLACE))
8486 json_object_boolean_true_add(
8487 json_addr,
8488 "privateAsNumsAllReplacedInUpdatesToNbr");
8489 else if (CHECK_FLAG(p->af_flags[afi][safi],
8490 PEER_FLAG_REMOVE_PRIVATE_AS_REPLACE))
8491 json_object_boolean_true_add(
8492 json_addr,
8493 "privateAsNumsReplacedInUpdatesToNbr");
8494 else if (CHECK_FLAG(p->af_flags[afi][safi],
8495 PEER_FLAG_REMOVE_PRIVATE_AS_ALL))
8496 json_object_boolean_true_add(
8497 json_addr,
8498 "privateAsNumsAllRemovedInUpdatesToNbr");
8499 else if (CHECK_FLAG(p->af_flags[afi][safi],
8500 PEER_FLAG_REMOVE_PRIVATE_AS))
8501 json_object_boolean_true_add(
8502 json_addr,
8503 "privateAsNumsRemovedInUpdatesToNbr");
8504
8505 if (CHECK_FLAG(p->af_flags[afi][safi],
8506 PEER_FLAG_ADDPATH_TX_ALL_PATHS))
8507 json_object_boolean_true_add(json_addr,
8508 "addpathTxAllPaths");
8509
8510 if (CHECK_FLAG(p->af_flags[afi][safi],
8511 PEER_FLAG_ADDPATH_TX_BESTPATH_PER_AS))
8512 json_object_boolean_true_add(json_addr,
8513 "addpathTxBestpathPerAS");
8514
8515 if (CHECK_FLAG(p->af_flags[afi][safi], PEER_FLAG_AS_OVERRIDE))
8516 json_object_string_add(json_addr,
8517 "overrideASNsInOutboundUpdates",
8518 "ifAspathEqualRemoteAs");
8519
8520 if (CHECK_FLAG(p->af_flags[afi][safi], PEER_FLAG_NEXTHOP_SELF)
8521 || CHECK_FLAG(p->af_flags[afi][safi],
8522 PEER_FLAG_FORCE_NEXTHOP_SELF))
8523 json_object_boolean_true_add(json_addr,
8524 "routerAlwaysNextHop");
8525 if (CHECK_FLAG(p->af_flags[afi][safi],
8526 PEER_FLAG_AS_PATH_UNCHANGED))
8527 json_object_boolean_true_add(
8528 json_addr, "unchangedAsPathPropogatedToNbr");
8529 if (CHECK_FLAG(p->af_flags[afi][safi],
8530 PEER_FLAG_NEXTHOP_UNCHANGED))
8531 json_object_boolean_true_add(
8532 json_addr, "unchangedNextHopPropogatedToNbr");
8533 if (CHECK_FLAG(p->af_flags[afi][safi], PEER_FLAG_MED_UNCHANGED))
8534 json_object_boolean_true_add(
8535 json_addr, "unchangedMedPropogatedToNbr");
8536 if (CHECK_FLAG(p->af_flags[afi][safi], PEER_FLAG_SEND_COMMUNITY)
8537 || CHECK_FLAG(p->af_flags[afi][safi],
8538 PEER_FLAG_SEND_EXT_COMMUNITY)) {
8539 if (CHECK_FLAG(p->af_flags[afi][safi],
8540 PEER_FLAG_SEND_COMMUNITY)
8541 && CHECK_FLAG(p->af_flags[afi][safi],
8542 PEER_FLAG_SEND_EXT_COMMUNITY))
8543 json_object_string_add(json_addr,
8544 "commAttriSentToNbr",
8545 "extendedAndStandard");
8546 else if (CHECK_FLAG(p->af_flags[afi][safi],
8547 PEER_FLAG_SEND_EXT_COMMUNITY))
8548 json_object_string_add(json_addr,
8549 "commAttriSentToNbr",
8550 "extended");
8551 else
8552 json_object_string_add(json_addr,
8553 "commAttriSentToNbr",
8554 "standard");
8555 }
8556 if (CHECK_FLAG(p->af_flags[afi][safi],
8557 PEER_FLAG_DEFAULT_ORIGINATE)) {
8558 if (p->default_rmap[afi][safi].name)
8559 json_object_string_add(
8560 json_addr, "defaultRouteMap",
8561 p->default_rmap[afi][safi].name);
8562
8563 if (paf && PAF_SUBGRP(paf)
8564 && CHECK_FLAG(PAF_SUBGRP(paf)->sflags,
8565 SUBGRP_STATUS_DEFAULT_ORIGINATE))
8566 json_object_boolean_true_add(json_addr,
8567 "defaultSent");
8568 else
8569 json_object_boolean_true_add(json_addr,
8570 "defaultNotSent");
8571 }
8572
8573 if (afi == AFI_L2VPN && safi == SAFI_EVPN) {
8574 if (is_evpn_enabled())
8575 json_object_boolean_true_add(
8576 json_addr, "advertiseAllVnis");
8577 }
8578
8579 if (filter->plist[FILTER_IN].name
8580 || filter->dlist[FILTER_IN].name
8581 || filter->aslist[FILTER_IN].name
8582 || filter->map[RMAP_IN].name)
8583 json_object_boolean_true_add(json_addr,
8584 "inboundPathPolicyConfig");
8585 if (filter->plist[FILTER_OUT].name
8586 || filter->dlist[FILTER_OUT].name
8587 || filter->aslist[FILTER_OUT].name
8588 || filter->map[RMAP_OUT].name || filter->usmap.name)
8589 json_object_boolean_true_add(
8590 json_addr, "outboundPathPolicyConfig");
8591
8592 /* prefix-list */
8593 if (filter->plist[FILTER_IN].name)
8594 json_object_string_add(json_addr,
8595 "incomingUpdatePrefixFilterList",
8596 filter->plist[FILTER_IN].name);
8597 if (filter->plist[FILTER_OUT].name)
8598 json_object_string_add(json_addr,
8599 "outgoingUpdatePrefixFilterList",
8600 filter->plist[FILTER_OUT].name);
8601
8602 /* distribute-list */
8603 if (filter->dlist[FILTER_IN].name)
8604 json_object_string_add(
8605 json_addr, "incomingUpdateNetworkFilterList",
8606 filter->dlist[FILTER_IN].name);
8607 if (filter->dlist[FILTER_OUT].name)
8608 json_object_string_add(
8609 json_addr, "outgoingUpdateNetworkFilterList",
8610 filter->dlist[FILTER_OUT].name);
8611
8612 /* filter-list. */
8613 if (filter->aslist[FILTER_IN].name)
8614 json_object_string_add(json_addr,
8615 "incomingUpdateAsPathFilterList",
8616 filter->aslist[FILTER_IN].name);
8617 if (filter->aslist[FILTER_OUT].name)
8618 json_object_string_add(json_addr,
8619 "outgoingUpdateAsPathFilterList",
8620 filter->aslist[FILTER_OUT].name);
8621
8622 /* route-map. */
8623 if (filter->map[RMAP_IN].name)
8624 json_object_string_add(
8625 json_addr, "routeMapForIncomingAdvertisements",
8626 filter->map[RMAP_IN].name);
8627 if (filter->map[RMAP_OUT].name)
8628 json_object_string_add(
8629 json_addr, "routeMapForOutgoingAdvertisements",
8630 filter->map[RMAP_OUT].name);
8631
8632 /* unsuppress-map */
8633 if (filter->usmap.name)
8634 json_object_string_add(json_addr,
8635 "selectiveUnsuppressRouteMap",
8636 filter->usmap.name);
8637
8638 /* Receive prefix count */
8639 json_object_int_add(json_addr, "acceptedPrefixCounter",
8640 p->pcount[afi][safi]);
8641
8642 /* Maximum prefix */
8643 if (CHECK_FLAG(p->af_flags[afi][safi], PEER_FLAG_MAX_PREFIX)) {
8644 json_object_int_add(json_addr, "prefixAllowedMax",
8645 p->pmax[afi][safi]);
8646 if (CHECK_FLAG(p->af_flags[afi][safi],
8647 PEER_FLAG_MAX_PREFIX_WARNING))
8648 json_object_boolean_true_add(
8649 json_addr, "prefixAllowedMaxWarning");
8650 json_object_int_add(json_addr,
8651 "prefixAllowedWarningThresh",
8652 p->pmax_threshold[afi][safi]);
8653 if (p->pmax_restart[afi][safi])
8654 json_object_int_add(
8655 json_addr,
8656 "prefixAllowedRestartIntervalMsecs",
8657 p->pmax_restart[afi][safi] * 60000);
8658 }
8659 json_object_object_add(json_neigh, afi_safi_print(afi, safi),
8660 json_addr);
8661
8662 } else {
8663 filter = &p->filter[afi][safi];
8664
8665 vty_out(vty, " For address family: %s\n",
8666 afi_safi_print(afi, safi));
8667
8668 if (peer_group_active(p))
8669 vty_out(vty, " %s peer-group member\n",
8670 p->group->name);
8671
8672 paf = peer_af_find(p, afi, safi);
8673 if (paf && PAF_SUBGRP(paf)) {
8674 vty_out(vty, " Update group %" PRIu64
8675 ", subgroup %" PRIu64 "\n",
8676 PAF_UPDGRP(paf)->id, PAF_SUBGRP(paf)->id);
8677 vty_out(vty, " Packet Queue length %d\n",
8678 bpacket_queue_virtual_length(paf));
8679 } else {
8680 vty_out(vty, " Not part of any update group\n");
8681 }
8682 if (CHECK_FLAG(p->af_cap[afi][safi], PEER_CAP_ORF_PREFIX_SM_ADV)
8683 || CHECK_FLAG(p->af_cap[afi][safi],
8684 PEER_CAP_ORF_PREFIX_SM_RCV)
8685 || CHECK_FLAG(p->af_cap[afi][safi],
8686 PEER_CAP_ORF_PREFIX_SM_OLD_RCV)
8687 || CHECK_FLAG(p->af_cap[afi][safi],
8688 PEER_CAP_ORF_PREFIX_RM_ADV)
8689 || CHECK_FLAG(p->af_cap[afi][safi],
8690 PEER_CAP_ORF_PREFIX_RM_RCV)
8691 || CHECK_FLAG(p->af_cap[afi][safi],
8692 PEER_CAP_ORF_PREFIX_RM_OLD_RCV))
8693 vty_out(vty, " AF-dependant capabilities:\n");
8694
8695 if (CHECK_FLAG(p->af_cap[afi][safi], PEER_CAP_ORF_PREFIX_SM_ADV)
8696 || CHECK_FLAG(p->af_cap[afi][safi],
8697 PEER_CAP_ORF_PREFIX_SM_RCV)
8698 || CHECK_FLAG(p->af_cap[afi][safi],
8699 PEER_CAP_ORF_PREFIX_RM_ADV)
8700 || CHECK_FLAG(p->af_cap[afi][safi],
8701 PEER_CAP_ORF_PREFIX_RM_RCV)) {
8702 vty_out(vty,
8703 " Outbound Route Filter (ORF) type (%d) Prefix-list:\n",
8704 ORF_TYPE_PREFIX);
8705 bgp_show_peer_afi_orf_cap(
8706 vty, p, afi, safi, PEER_CAP_ORF_PREFIX_SM_ADV,
8707 PEER_CAP_ORF_PREFIX_RM_ADV,
8708 PEER_CAP_ORF_PREFIX_SM_RCV,
8709 PEER_CAP_ORF_PREFIX_RM_RCV, use_json, NULL);
8710 }
8711 if (CHECK_FLAG(p->af_cap[afi][safi], PEER_CAP_ORF_PREFIX_SM_ADV)
8712 || CHECK_FLAG(p->af_cap[afi][safi],
8713 PEER_CAP_ORF_PREFIX_SM_OLD_RCV)
8714 || CHECK_FLAG(p->af_cap[afi][safi],
8715 PEER_CAP_ORF_PREFIX_RM_ADV)
8716 || CHECK_FLAG(p->af_cap[afi][safi],
8717 PEER_CAP_ORF_PREFIX_RM_OLD_RCV)) {
8718 vty_out(vty,
8719 " Outbound Route Filter (ORF) type (%d) Prefix-list:\n",
8720 ORF_TYPE_PREFIX_OLD);
8721 bgp_show_peer_afi_orf_cap(
8722 vty, p, afi, safi, PEER_CAP_ORF_PREFIX_SM_ADV,
8723 PEER_CAP_ORF_PREFIX_RM_ADV,
8724 PEER_CAP_ORF_PREFIX_SM_OLD_RCV,
8725 PEER_CAP_ORF_PREFIX_RM_OLD_RCV, use_json, NULL);
8726 }
8727
8728 sprintf(orf_pfx_name, "%s.%d.%d", p->host, afi, safi);
8729 orf_pfx_count = prefix_bgp_show_prefix_list(
8730 NULL, afi, orf_pfx_name, use_json);
8731
8732 if (CHECK_FLAG(p->af_sflags[afi][safi],
8733 PEER_STATUS_ORF_PREFIX_SEND)
8734 || orf_pfx_count) {
8735 vty_out(vty, " Outbound Route Filter (ORF):");
8736 if (CHECK_FLAG(p->af_sflags[afi][safi],
8737 PEER_STATUS_ORF_PREFIX_SEND))
8738 vty_out(vty, " sent;");
8739 if (orf_pfx_count)
8740 vty_out(vty, " received (%d entries)",
8741 orf_pfx_count);
8742 vty_out(vty, "\n");
8743 }
8744 if (CHECK_FLAG(p->af_sflags[afi][safi],
8745 PEER_STATUS_ORF_WAIT_REFRESH))
8746 vty_out(vty,
8747 " First update is deferred until ORF or ROUTE-REFRESH is received\n");
8748
8749 if (CHECK_FLAG(p->af_flags[afi][safi],
8750 PEER_FLAG_REFLECTOR_CLIENT))
8751 vty_out(vty, " Route-Reflector Client\n");
8752 if (CHECK_FLAG(p->af_flags[afi][safi],
8753 PEER_FLAG_RSERVER_CLIENT))
8754 vty_out(vty, " Route-Server Client\n");
8755 if (CHECK_FLAG(p->af_flags[afi][safi], PEER_FLAG_SOFT_RECONFIG))
8756 vty_out(vty,
8757 " Inbound soft reconfiguration allowed\n");
8758
8759 if (CHECK_FLAG(p->af_flags[afi][safi],
8760 PEER_FLAG_REMOVE_PRIVATE_AS_ALL_REPLACE))
8761 vty_out(vty,
8762 " Private AS numbers (all) replaced in updates to this neighbor\n");
8763 else if (CHECK_FLAG(p->af_flags[afi][safi],
8764 PEER_FLAG_REMOVE_PRIVATE_AS_REPLACE))
8765 vty_out(vty,
8766 " Private AS numbers replaced in updates to this neighbor\n");
8767 else if (CHECK_FLAG(p->af_flags[afi][safi],
8768 PEER_FLAG_REMOVE_PRIVATE_AS_ALL))
8769 vty_out(vty,
8770 " Private AS numbers (all) removed in updates to this neighbor\n");
8771 else if (CHECK_FLAG(p->af_flags[afi][safi],
8772 PEER_FLAG_REMOVE_PRIVATE_AS))
8773 vty_out(vty,
8774 " Private AS numbers removed in updates to this neighbor\n");
8775
8776 if (CHECK_FLAG(p->af_flags[afi][safi],
8777 PEER_FLAG_ADDPATH_TX_ALL_PATHS))
8778 vty_out(vty, " Advertise all paths via addpath\n");
8779
8780 if (CHECK_FLAG(p->af_flags[afi][safi],
8781 PEER_FLAG_ADDPATH_TX_BESTPATH_PER_AS))
8782 vty_out(vty,
8783 " Advertise bestpath per AS via addpath\n");
8784
8785 if (CHECK_FLAG(p->af_flags[afi][safi], PEER_FLAG_AS_OVERRIDE))
8786 vty_out(vty,
8787 " Override ASNs in outbound updates if aspath equals remote-as\n");
8788
8789 if (CHECK_FLAG(p->af_flags[afi][safi], PEER_FLAG_NEXTHOP_SELF)
8790 || CHECK_FLAG(p->af_flags[afi][safi],
8791 PEER_FLAG_FORCE_NEXTHOP_SELF))
8792 vty_out(vty, " NEXT_HOP is always this router\n");
8793 if (CHECK_FLAG(p->af_flags[afi][safi],
8794 PEER_FLAG_AS_PATH_UNCHANGED))
8795 vty_out(vty,
8796 " AS_PATH is propagated unchanged to this neighbor\n");
8797 if (CHECK_FLAG(p->af_flags[afi][safi],
8798 PEER_FLAG_NEXTHOP_UNCHANGED))
8799 vty_out(vty,
8800 " NEXT_HOP is propagated unchanged to this neighbor\n");
8801 if (CHECK_FLAG(p->af_flags[afi][safi], PEER_FLAG_MED_UNCHANGED))
8802 vty_out(vty,
8803 " MED is propagated unchanged to this neighbor\n");
8804 if (CHECK_FLAG(p->af_flags[afi][safi], PEER_FLAG_SEND_COMMUNITY)
8805 || CHECK_FLAG(p->af_flags[afi][safi],
8806 PEER_FLAG_SEND_EXT_COMMUNITY)
8807 || CHECK_FLAG(p->af_flags[afi][safi],
8808 PEER_FLAG_SEND_LARGE_COMMUNITY)) {
8809 vty_out(vty,
8810 " Community attribute sent to this neighbor");
8811 if (CHECK_FLAG(p->af_flags[afi][safi],
8812 PEER_FLAG_SEND_COMMUNITY)
8813 && CHECK_FLAG(p->af_flags[afi][safi],
8814 PEER_FLAG_SEND_EXT_COMMUNITY)
8815 && CHECK_FLAG(p->af_flags[afi][safi],
8816 PEER_FLAG_SEND_LARGE_COMMUNITY))
8817 vty_out(vty, "(all)\n");
8818 else if (CHECK_FLAG(p->af_flags[afi][safi],
8819 PEER_FLAG_SEND_LARGE_COMMUNITY))
8820 vty_out(vty, "(large)\n");
8821 else if (CHECK_FLAG(p->af_flags[afi][safi],
8822 PEER_FLAG_SEND_EXT_COMMUNITY))
8823 vty_out(vty, "(extended)\n");
8824 else
8825 vty_out(vty, "(standard)\n");
8826 }
8827 if (CHECK_FLAG(p->af_flags[afi][safi],
8828 PEER_FLAG_DEFAULT_ORIGINATE)) {
8829 vty_out(vty, " Default information originate,");
8830
8831 if (p->default_rmap[afi][safi].name)
8832 vty_out(vty, " default route-map %s%s,",
8833 p->default_rmap[afi][safi].map ? "*"
8834 : "",
8835 p->default_rmap[afi][safi].name);
8836 if (paf && PAF_SUBGRP(paf)
8837 && CHECK_FLAG(PAF_SUBGRP(paf)->sflags,
8838 SUBGRP_STATUS_DEFAULT_ORIGINATE))
8839 vty_out(vty, " default sent\n");
8840 else
8841 vty_out(vty, " default not sent\n");
8842 }
8843
8844 /* advertise-vni-all */
8845 if (afi == AFI_L2VPN && safi == SAFI_EVPN) {
8846 if (is_evpn_enabled())
8847 vty_out(vty, " advertise-all-vni\n");
8848 }
8849
8850 if (filter->plist[FILTER_IN].name
8851 || filter->dlist[FILTER_IN].name
8852 || filter->aslist[FILTER_IN].name
8853 || filter->map[RMAP_IN].name)
8854 vty_out(vty, " Inbound path policy configured\n");
8855 if (filter->plist[FILTER_OUT].name
8856 || filter->dlist[FILTER_OUT].name
8857 || filter->aslist[FILTER_OUT].name
8858 || filter->map[RMAP_OUT].name || filter->usmap.name)
8859 vty_out(vty, " Outbound path policy configured\n");
8860
8861 /* prefix-list */
8862 if (filter->plist[FILTER_IN].name)
8863 vty_out(vty,
8864 " Incoming update prefix filter list is %s%s\n",
8865 filter->plist[FILTER_IN].plist ? "*" : "",
8866 filter->plist[FILTER_IN].name);
8867 if (filter->plist[FILTER_OUT].name)
8868 vty_out(vty,
8869 " Outgoing update prefix filter list is %s%s\n",
8870 filter->plist[FILTER_OUT].plist ? "*" : "",
8871 filter->plist[FILTER_OUT].name);
8872
8873 /* distribute-list */
8874 if (filter->dlist[FILTER_IN].name)
8875 vty_out(vty,
8876 " Incoming update network filter list is %s%s\n",
8877 filter->dlist[FILTER_IN].alist ? "*" : "",
8878 filter->dlist[FILTER_IN].name);
8879 if (filter->dlist[FILTER_OUT].name)
8880 vty_out(vty,
8881 " Outgoing update network filter list is %s%s\n",
8882 filter->dlist[FILTER_OUT].alist ? "*" : "",
8883 filter->dlist[FILTER_OUT].name);
8884
8885 /* filter-list. */
8886 if (filter->aslist[FILTER_IN].name)
8887 vty_out(vty,
8888 " Incoming update AS path filter list is %s%s\n",
8889 filter->aslist[FILTER_IN].aslist ? "*" : "",
8890 filter->aslist[FILTER_IN].name);
8891 if (filter->aslist[FILTER_OUT].name)
8892 vty_out(vty,
8893 " Outgoing update AS path filter list is %s%s\n",
8894 filter->aslist[FILTER_OUT].aslist ? "*" : "",
8895 filter->aslist[FILTER_OUT].name);
8896
8897 /* route-map. */
8898 if (filter->map[RMAP_IN].name)
8899 vty_out(vty,
8900 " Route map for incoming advertisements is %s%s\n",
8901 filter->map[RMAP_IN].map ? "*" : "",
8902 filter->map[RMAP_IN].name);
8903 if (filter->map[RMAP_OUT].name)
8904 vty_out(vty,
8905 " Route map for outgoing advertisements is %s%s\n",
8906 filter->map[RMAP_OUT].map ? "*" : "",
8907 filter->map[RMAP_OUT].name);
8908
8909 /* unsuppress-map */
8910 if (filter->usmap.name)
8911 vty_out(vty,
8912 " Route map for selective unsuppress is %s%s\n",
8913 filter->usmap.map ? "*" : "",
8914 filter->usmap.name);
8915
8916 /* Receive prefix count */
8917 vty_out(vty, " %ld accepted prefixes\n", p->pcount[afi][safi]);
8918
8919 /* Maximum prefix */
8920 if (CHECK_FLAG(p->af_flags[afi][safi], PEER_FLAG_MAX_PREFIX)) {
8921 vty_out(vty, " Maximum prefixes allowed %ld%s\n",
8922 p->pmax[afi][safi],
8923 CHECK_FLAG(p->af_flags[afi][safi],
8924 PEER_FLAG_MAX_PREFIX_WARNING)
8925 ? " (warning-only)"
8926 : "");
8927 vty_out(vty, " Threshold for warning message %d%%",
8928 p->pmax_threshold[afi][safi]);
8929 if (p->pmax_restart[afi][safi])
8930 vty_out(vty, ", restart interval %d min",
8931 p->pmax_restart[afi][safi]);
8932 vty_out(vty, "\n");
8933 }
8934
8935 vty_out(vty, "\n");
8936 }
8937 }
8938
8939 static void bgp_show_peer(struct vty *vty, struct peer *p, uint8_t use_json,
8940 json_object *json)
8941 {
8942 struct bgp *bgp;
8943 char buf1[PREFIX2STR_BUFFER], buf[SU_ADDRSTRLEN];
8944 char timebuf[BGP_UPTIME_LEN];
8945 char dn_flag[2];
8946 const char *subcode_str;
8947 const char *code_str;
8948 afi_t afi;
8949 safi_t safi;
8950 uint16_t i;
8951 uint8_t *msg;
8952 json_object *json_neigh = NULL;
8953 time_t epoch_tbuf;
8954
8955 bgp = p->bgp;
8956
8957 if (use_json)
8958 json_neigh = json_object_new_object();
8959
8960 memset(dn_flag, '\0', sizeof(dn_flag));
8961 if (!p->conf_if && peer_dynamic_neighbor(p))
8962 dn_flag[0] = '*';
8963
8964 if (!use_json) {
8965 if (p->conf_if) /* Configured interface name. */
8966 vty_out(vty, "BGP neighbor on %s: %s, ", p->conf_if,
8967 BGP_PEER_SU_UNSPEC(p)
8968 ? "None"
8969 : sockunion2str(&p->su, buf,
8970 SU_ADDRSTRLEN));
8971 else /* Configured IP address. */
8972 vty_out(vty, "BGP neighbor is %s%s, ", dn_flag,
8973 p->host);
8974 }
8975
8976 if (use_json) {
8977 if (p->conf_if && BGP_PEER_SU_UNSPEC(p))
8978 json_object_string_add(json_neigh, "bgpNeighborAddr",
8979 "none");
8980 else if (p->conf_if && !BGP_PEER_SU_UNSPEC(p))
8981 json_object_string_add(
8982 json_neigh, "bgpNeighborAddr",
8983 sockunion2str(&p->su, buf, SU_ADDRSTRLEN));
8984
8985 json_object_int_add(json_neigh, "remoteAs", p->as);
8986
8987 if (p->change_local_as)
8988 json_object_int_add(json_neigh, "localAs",
8989 p->change_local_as);
8990 else
8991 json_object_int_add(json_neigh, "localAs", p->local_as);
8992
8993 if (CHECK_FLAG(p->flags, PEER_FLAG_LOCAL_AS_NO_PREPEND))
8994 json_object_boolean_true_add(json_neigh,
8995 "localAsNoPrepend");
8996
8997 if (CHECK_FLAG(p->flags, PEER_FLAG_LOCAL_AS_REPLACE_AS))
8998 json_object_boolean_true_add(json_neigh,
8999 "localAsReplaceAs");
9000 } else {
9001 if ((p->as_type == AS_SPECIFIED) || (p->as_type == AS_EXTERNAL)
9002 || (p->as_type == AS_INTERNAL))
9003 vty_out(vty, "remote AS %u, ", p->as);
9004 else
9005 vty_out(vty, "remote AS Unspecified, ");
9006 vty_out(vty, "local AS %u%s%s, ",
9007 p->change_local_as ? p->change_local_as : p->local_as,
9008 CHECK_FLAG(p->flags, PEER_FLAG_LOCAL_AS_NO_PREPEND)
9009 ? " no-prepend"
9010 : "",
9011 CHECK_FLAG(p->flags, PEER_FLAG_LOCAL_AS_REPLACE_AS)
9012 ? " replace-as"
9013 : "");
9014 }
9015 /* peer type internal, external, confed-internal or confed-external */
9016 if (p->as == p->local_as) {
9017 if (use_json) {
9018 if (CHECK_FLAG(bgp->config, BGP_CONFIG_CONFEDERATION))
9019 json_object_boolean_true_add(
9020 json_neigh, "nbrConfedInternalLink");
9021 else
9022 json_object_boolean_true_add(json_neigh,
9023 "nbrInternalLink");
9024 } else {
9025 if (CHECK_FLAG(bgp->config, BGP_CONFIG_CONFEDERATION))
9026 vty_out(vty, "confed-internal link\n");
9027 else
9028 vty_out(vty, "internal link\n");
9029 }
9030 } else {
9031 if (use_json) {
9032 if (CHECK_FLAG(bgp->config, BGP_CONFIG_CONFEDERATION))
9033 json_object_boolean_true_add(
9034 json_neigh, "nbrConfedExternalLink");
9035 else
9036 json_object_boolean_true_add(json_neigh,
9037 "nbrExternalLink");
9038 } else {
9039 if (bgp_confederation_peers_check(bgp, p->as))
9040 vty_out(vty, "confed-external link\n");
9041 else
9042 vty_out(vty, "external link\n");
9043 }
9044 }
9045
9046 /* Description. */
9047 if (p->desc) {
9048 if (use_json)
9049 json_object_string_add(json_neigh, "nbrDesc", p->desc);
9050 else
9051 vty_out(vty, " Description: %s\n", p->desc);
9052 }
9053
9054 if (p->hostname) {
9055 if (use_json) {
9056 if (p->hostname)
9057 json_object_string_add(json_neigh, "hostname",
9058 p->hostname);
9059
9060 if (p->domainname)
9061 json_object_string_add(json_neigh, "domainname",
9062 p->domainname);
9063 } else {
9064 if (p->domainname && (p->domainname[0] != '\0'))
9065 vty_out(vty, "Hostname: %s.%s\n", p->hostname,
9066 p->domainname);
9067 else
9068 vty_out(vty, "Hostname: %s\n", p->hostname);
9069 }
9070 }
9071
9072 /* Peer-group */
9073 if (p->group) {
9074 if (use_json) {
9075 json_object_string_add(json_neigh, "peerGroup",
9076 p->group->name);
9077
9078 if (dn_flag[0]) {
9079 struct prefix prefix, *range = NULL;
9080
9081 sockunion2hostprefix(&(p->su), &prefix);
9082 range = peer_group_lookup_dynamic_neighbor_range(
9083 p->group, &prefix);
9084
9085 if (range) {
9086 prefix2str(range, buf1, sizeof(buf1));
9087 json_object_string_add(
9088 json_neigh,
9089 "peerSubnetRangeGroup", buf1);
9090 }
9091 }
9092 } else {
9093 vty_out(vty,
9094 " Member of peer-group %s for session parameters\n",
9095 p->group->name);
9096
9097 if (dn_flag[0]) {
9098 struct prefix prefix, *range = NULL;
9099
9100 sockunion2hostprefix(&(p->su), &prefix);
9101 range = peer_group_lookup_dynamic_neighbor_range(
9102 p->group, &prefix);
9103
9104 if (range) {
9105 prefix2str(range, buf1, sizeof(buf1));
9106 vty_out(vty,
9107 " Belongs to the subnet range group: %s\n",
9108 buf1);
9109 }
9110 }
9111 }
9112 }
9113
9114 if (use_json) {
9115 /* Administrative shutdown. */
9116 if (CHECK_FLAG(p->flags, PEER_FLAG_SHUTDOWN))
9117 json_object_boolean_true_add(json_neigh,
9118 "adminShutDown");
9119
9120 /* BGP Version. */
9121 json_object_int_add(json_neigh, "bgpVersion", 4);
9122 json_object_string_add(
9123 json_neigh, "remoteRouterId",
9124 inet_ntop(AF_INET, &p->remote_id, buf1, sizeof(buf1)));
9125 json_object_string_add(
9126 json_neigh, "localRouterId",
9127 inet_ntop(AF_INET, &bgp->router_id, buf1,
9128 sizeof(buf1)));
9129
9130 /* Confederation */
9131 if (CHECK_FLAG(bgp->config, BGP_CONFIG_CONFEDERATION)
9132 && bgp_confederation_peers_check(bgp, p->as))
9133 json_object_boolean_true_add(json_neigh,
9134 "nbrCommonAdmin");
9135
9136 /* Status. */
9137 json_object_string_add(
9138 json_neigh, "bgpState",
9139 lookup_msg(bgp_status_msg, p->status, NULL));
9140
9141 if (p->status == Established) {
9142 time_t uptime;
9143
9144 uptime = bgp_clock();
9145 uptime -= p->uptime;
9146 epoch_tbuf = time(NULL) - uptime;
9147
9148 #if CONFDATE > 20200101
9149 CPP_NOTICE(
9150 "bgpTimerUp should be deprecated and can be removed now");
9151 #endif
9152 /*
9153 * bgpTimerUp was miliseconds that was accurate
9154 * up to 1 day, then the value returned
9155 * became garbage. So in order to provide
9156 * some level of backwards compatability,
9157 * we still provde the data, but now
9158 * we are returning the correct value
9159 * and also adding a new bgpTimerUpMsec
9160 * which will allow us to deprecate
9161 * this eventually
9162 */
9163 json_object_int_add(json_neigh, "bgpTimerUp",
9164 uptime * 1000);
9165 json_object_int_add(json_neigh, "bgpTimerUpMsec",
9166 uptime * 1000);
9167 json_object_string_add(json_neigh, "bgpTimerUpString",
9168 peer_uptime(p->uptime, timebuf,
9169 BGP_UPTIME_LEN, 0,
9170 NULL));
9171 json_object_int_add(json_neigh,
9172 "bgpTimerUpEstablishedEpoch",
9173 epoch_tbuf);
9174 }
9175
9176 else if (p->status == Active) {
9177 if (CHECK_FLAG(p->flags, PEER_FLAG_PASSIVE))
9178 json_object_string_add(json_neigh, "bgpStateIs",
9179 "passive");
9180 else if (CHECK_FLAG(p->sflags, PEER_STATUS_NSF_WAIT))
9181 json_object_string_add(json_neigh, "bgpStateIs",
9182 "passiveNSF");
9183 }
9184
9185 /* read timer */
9186 time_t uptime;
9187 struct tm *tm;
9188
9189 uptime = bgp_clock();
9190 uptime -= p->readtime;
9191 tm = gmtime(&uptime);
9192 json_object_int_add(json_neigh, "bgpTimerLastRead",
9193 (tm->tm_sec * 1000) + (tm->tm_min * 60000)
9194 + (tm->tm_hour * 3600000));
9195
9196 uptime = bgp_clock();
9197 uptime -= p->last_write;
9198 tm = gmtime(&uptime);
9199 json_object_int_add(json_neigh, "bgpTimerLastWrite",
9200 (tm->tm_sec * 1000) + (tm->tm_min * 60000)
9201 + (tm->tm_hour * 3600000));
9202
9203 uptime = bgp_clock();
9204 uptime -= p->update_time;
9205 tm = gmtime(&uptime);
9206 json_object_int_add(json_neigh, "bgpInUpdateElapsedTimeMsecs",
9207 (tm->tm_sec * 1000) + (tm->tm_min * 60000)
9208 + (tm->tm_hour * 3600000));
9209
9210 /* Configured timer values. */
9211 json_object_int_add(json_neigh, "bgpTimerHoldTimeMsecs",
9212 p->v_holdtime * 1000);
9213 json_object_int_add(json_neigh,
9214 "bgpTimerKeepAliveIntervalMsecs",
9215 p->v_keepalive * 1000);
9216 if (CHECK_FLAG(p->flags, PEER_FLAG_TIMER)) {
9217 json_object_int_add(json_neigh,
9218 "bgpTimerConfiguredHoldTimeMsecs",
9219 p->holdtime * 1000);
9220 json_object_int_add(
9221 json_neigh,
9222 "bgpTimerConfiguredKeepAliveIntervalMsecs",
9223 p->keepalive * 1000);
9224 } else if ((bgp->default_holdtime != BGP_DEFAULT_HOLDTIME)
9225 || (bgp->default_keepalive
9226 != BGP_DEFAULT_KEEPALIVE)) {
9227 json_object_int_add(json_neigh,
9228 "bgpTimerConfiguredHoldTimeMsecs",
9229 bgp->default_holdtime);
9230 json_object_int_add(
9231 json_neigh,
9232 "bgpTimerConfiguredKeepAliveIntervalMsecs",
9233 bgp->default_keepalive);
9234 }
9235 } else {
9236 /* Administrative shutdown. */
9237 if (CHECK_FLAG(p->flags, PEER_FLAG_SHUTDOWN))
9238 vty_out(vty, " Administratively shut down\n");
9239
9240 /* BGP Version. */
9241 vty_out(vty, " BGP version 4");
9242 vty_out(vty, ", remote router ID %s\n",
9243 inet_ntop(AF_INET, &p->remote_id, buf1, sizeof(buf1)));
9244
9245 /* Confederation */
9246 if (CHECK_FLAG(bgp->config, BGP_CONFIG_CONFEDERATION)
9247 && bgp_confederation_peers_check(bgp, p->as))
9248 vty_out(vty,
9249 " Neighbor under common administration\n");
9250
9251 /* Status. */
9252 vty_out(vty, " BGP state = %s",
9253 lookup_msg(bgp_status_msg, p->status, NULL));
9254
9255 if (p->status == Established)
9256 vty_out(vty, ", up for %8s",
9257 peer_uptime(p->uptime, timebuf, BGP_UPTIME_LEN,
9258 0, NULL));
9259
9260 else if (p->status == Active) {
9261 if (CHECK_FLAG(p->flags, PEER_FLAG_PASSIVE))
9262 vty_out(vty, " (passive)");
9263 else if (CHECK_FLAG(p->sflags, PEER_STATUS_NSF_WAIT))
9264 vty_out(vty, " (NSF passive)");
9265 }
9266 vty_out(vty, "\n");
9267
9268 /* read timer */
9269 vty_out(vty, " Last read %s",
9270 peer_uptime(p->readtime, timebuf, BGP_UPTIME_LEN, 0,
9271 NULL));
9272 vty_out(vty, ", Last write %s\n",
9273 peer_uptime(p->last_write, timebuf, BGP_UPTIME_LEN, 0,
9274 NULL));
9275
9276 /* Configured timer values. */
9277 vty_out(vty,
9278 " Hold time is %d, keepalive interval is %d seconds\n",
9279 p->v_holdtime, p->v_keepalive);
9280 if (CHECK_FLAG(p->flags, PEER_FLAG_TIMER)) {
9281 vty_out(vty, " Configured hold time is %d",
9282 p->holdtime);
9283 vty_out(vty, ", keepalive interval is %d seconds\n",
9284 p->keepalive);
9285 } else if ((bgp->default_holdtime != BGP_DEFAULT_HOLDTIME)
9286 || (bgp->default_keepalive
9287 != BGP_DEFAULT_KEEPALIVE)) {
9288 vty_out(vty, " Configured hold time is %d",
9289 bgp->default_holdtime);
9290 vty_out(vty, ", keepalive interval is %d seconds\n",
9291 bgp->default_keepalive);
9292 }
9293 }
9294 /* Capability. */
9295 if (p->status == Established) {
9296 if (p->cap || p->afc_adv[AFI_IP][SAFI_UNICAST]
9297 || p->afc_recv[AFI_IP][SAFI_UNICAST]
9298 || p->afc_adv[AFI_IP][SAFI_MULTICAST]
9299 || p->afc_recv[AFI_IP][SAFI_MULTICAST]
9300 || p->afc_adv[AFI_IP6][SAFI_UNICAST]
9301 || p->afc_recv[AFI_IP6][SAFI_UNICAST]
9302 || p->afc_adv[AFI_IP6][SAFI_MULTICAST]
9303 || p->afc_recv[AFI_IP6][SAFI_MULTICAST]
9304 || p->afc_adv[AFI_IP6][SAFI_MPLS_VPN]
9305 || p->afc_recv[AFI_IP6][SAFI_MPLS_VPN]
9306 || p->afc_adv[AFI_IP6][SAFI_ENCAP]
9307 || p->afc_recv[AFI_IP6][SAFI_ENCAP]
9308 || p->afc_adv[AFI_IP6][SAFI_FLOWSPEC]
9309 || p->afc_recv[AFI_IP6][SAFI_FLOWSPEC]
9310 || p->afc_adv[AFI_IP][SAFI_ENCAP]
9311 || p->afc_recv[AFI_IP][SAFI_ENCAP]
9312 || p->afc_adv[AFI_IP][SAFI_FLOWSPEC]
9313 || p->afc_recv[AFI_IP][SAFI_FLOWSPEC]
9314 || p->afc_adv[AFI_IP][SAFI_MPLS_VPN]
9315 || p->afc_recv[AFI_IP][SAFI_MPLS_VPN]) {
9316 if (use_json) {
9317 json_object *json_cap = NULL;
9318
9319 json_cap = json_object_new_object();
9320
9321 /* AS4 */
9322 if (CHECK_FLAG(p->cap, PEER_CAP_AS4_RCV)
9323 || CHECK_FLAG(p->cap, PEER_CAP_AS4_ADV)) {
9324 if (CHECK_FLAG(p->cap, PEER_CAP_AS4_ADV)
9325 && CHECK_FLAG(p->cap,
9326 PEER_CAP_AS4_RCV))
9327 json_object_string_add(
9328 json_cap, "4byteAs",
9329 "advertisedAndReceived");
9330 else if (CHECK_FLAG(p->cap,
9331 PEER_CAP_AS4_ADV))
9332 json_object_string_add(
9333 json_cap, "4byteAs",
9334 "advertised");
9335 else if (CHECK_FLAG(p->cap,
9336 PEER_CAP_AS4_RCV))
9337 json_object_string_add(
9338 json_cap, "4byteAs",
9339 "received");
9340 }
9341
9342 /* AddPath */
9343 if (CHECK_FLAG(p->cap, PEER_CAP_ADDPATH_RCV)
9344 || CHECK_FLAG(p->cap,
9345 PEER_CAP_ADDPATH_ADV)) {
9346 json_object *json_add = NULL;
9347 const char *print_store;
9348
9349 json_add = json_object_new_object();
9350
9351 FOREACH_AFI_SAFI (afi, safi) {
9352 json_object *json_sub = NULL;
9353 json_sub =
9354 json_object_new_object();
9355 print_store = afi_safi_print(
9356 afi, safi);
9357
9358 if (CHECK_FLAG(
9359 p->af_cap[afi]
9360 [safi],
9361 PEER_CAP_ADDPATH_AF_TX_ADV)
9362 || CHECK_FLAG(
9363 p->af_cap[afi]
9364 [safi],
9365 PEER_CAP_ADDPATH_AF_TX_RCV)) {
9366 if (CHECK_FLAG(
9367 p->af_cap
9368 [afi]
9369 [safi],
9370 PEER_CAP_ADDPATH_AF_TX_ADV)
9371 && CHECK_FLAG(
9372 p->af_cap
9373 [afi]
9374 [safi],
9375 PEER_CAP_ADDPATH_AF_TX_RCV))
9376 json_object_boolean_true_add(
9377 json_sub,
9378 "txAdvertisedAndReceived");
9379 else if (
9380 CHECK_FLAG(
9381 p->af_cap
9382 [afi]
9383 [safi],
9384 PEER_CAP_ADDPATH_AF_TX_ADV))
9385 json_object_boolean_true_add(
9386 json_sub,
9387 "txAdvertised");
9388 else if (
9389 CHECK_FLAG(
9390 p->af_cap
9391 [afi]
9392 [safi],
9393 PEER_CAP_ADDPATH_AF_TX_RCV))
9394 json_object_boolean_true_add(
9395 json_sub,
9396 "txReceived");
9397 }
9398
9399 if (CHECK_FLAG(
9400 p->af_cap[afi]
9401 [safi],
9402 PEER_CAP_ADDPATH_AF_RX_ADV)
9403 || CHECK_FLAG(
9404 p->af_cap[afi]
9405 [safi],
9406 PEER_CAP_ADDPATH_AF_RX_RCV)) {
9407 if (CHECK_FLAG(
9408 p->af_cap
9409 [afi]
9410 [safi],
9411 PEER_CAP_ADDPATH_AF_RX_ADV)
9412 && CHECK_FLAG(
9413 p->af_cap
9414 [afi]
9415 [safi],
9416 PEER_CAP_ADDPATH_AF_RX_RCV))
9417 json_object_boolean_true_add(
9418 json_sub,
9419 "rxAdvertisedAndReceived");
9420 else if (
9421 CHECK_FLAG(
9422 p->af_cap
9423 [afi]
9424 [safi],
9425 PEER_CAP_ADDPATH_AF_RX_ADV))
9426 json_object_boolean_true_add(
9427 json_sub,
9428 "rxAdvertised");
9429 else if (
9430 CHECK_FLAG(
9431 p->af_cap
9432 [afi]
9433 [safi],
9434 PEER_CAP_ADDPATH_AF_RX_RCV))
9435 json_object_boolean_true_add(
9436 json_sub,
9437 "rxReceived");
9438 }
9439
9440 if (CHECK_FLAG(
9441 p->af_cap[afi]
9442 [safi],
9443 PEER_CAP_ADDPATH_AF_TX_ADV)
9444 || CHECK_FLAG(
9445 p->af_cap[afi]
9446 [safi],
9447 PEER_CAP_ADDPATH_AF_TX_RCV)
9448 || CHECK_FLAG(
9449 p->af_cap[afi]
9450 [safi],
9451 PEER_CAP_ADDPATH_AF_RX_ADV)
9452 || CHECK_FLAG(
9453 p->af_cap[afi]
9454 [safi],
9455 PEER_CAP_ADDPATH_AF_RX_RCV))
9456 json_object_object_add(
9457 json_add,
9458 print_store,
9459 json_sub);
9460 else
9461 json_object_free(
9462 json_sub);
9463 }
9464
9465 json_object_object_add(
9466 json_cap, "addPath", json_add);
9467 }
9468
9469 /* Dynamic */
9470 if (CHECK_FLAG(p->cap, PEER_CAP_DYNAMIC_RCV)
9471 || CHECK_FLAG(p->cap,
9472 PEER_CAP_DYNAMIC_ADV)) {
9473 if (CHECK_FLAG(p->cap,
9474 PEER_CAP_DYNAMIC_ADV)
9475 && CHECK_FLAG(p->cap,
9476 PEER_CAP_DYNAMIC_RCV))
9477 json_object_string_add(
9478 json_cap, "dynamic",
9479 "advertisedAndReceived");
9480 else if (CHECK_FLAG(
9481 p->cap,
9482 PEER_CAP_DYNAMIC_ADV))
9483 json_object_string_add(
9484 json_cap, "dynamic",
9485 "advertised");
9486 else if (CHECK_FLAG(
9487 p->cap,
9488 PEER_CAP_DYNAMIC_RCV))
9489 json_object_string_add(
9490 json_cap, "dynamic",
9491 "received");
9492 }
9493
9494 /* Extended nexthop */
9495 if (CHECK_FLAG(p->cap, PEER_CAP_ENHE_RCV)
9496 || CHECK_FLAG(p->cap, PEER_CAP_ENHE_ADV)) {
9497 json_object *json_nxt = NULL;
9498 const char *print_store;
9499
9500
9501 if (CHECK_FLAG(p->cap,
9502 PEER_CAP_ENHE_ADV)
9503 && CHECK_FLAG(p->cap,
9504 PEER_CAP_ENHE_RCV))
9505 json_object_string_add(
9506 json_cap,
9507 "extendedNexthop",
9508 "advertisedAndReceived");
9509 else if (CHECK_FLAG(p->cap,
9510 PEER_CAP_ENHE_ADV))
9511 json_object_string_add(
9512 json_cap,
9513 "extendedNexthop",
9514 "advertised");
9515 else if (CHECK_FLAG(p->cap,
9516 PEER_CAP_ENHE_RCV))
9517 json_object_string_add(
9518 json_cap,
9519 "extendedNexthop",
9520 "received");
9521
9522 if (CHECK_FLAG(p->cap,
9523 PEER_CAP_ENHE_RCV)) {
9524 json_nxt =
9525 json_object_new_object();
9526
9527 for (safi = SAFI_UNICAST;
9528 safi < SAFI_MAX; safi++) {
9529 if (CHECK_FLAG(
9530 p->af_cap
9531 [AFI_IP]
9532 [safi],
9533 PEER_CAP_ENHE_AF_RCV)) {
9534 print_store = afi_safi_print(
9535 AFI_IP,
9536 safi);
9537 json_object_string_add(
9538 json_nxt,
9539 print_store,
9540 "recieved");
9541 }
9542 }
9543 json_object_object_add(
9544 json_cap,
9545 "extendedNexthopFamililesByPeer",
9546 json_nxt);
9547 }
9548 }
9549
9550 /* Route Refresh */
9551 if (CHECK_FLAG(p->cap, PEER_CAP_REFRESH_ADV)
9552 || CHECK_FLAG(p->cap,
9553 PEER_CAP_REFRESH_NEW_RCV)
9554 || CHECK_FLAG(p->cap,
9555 PEER_CAP_REFRESH_OLD_RCV)) {
9556 if (CHECK_FLAG(p->cap,
9557 PEER_CAP_REFRESH_ADV)
9558 && (CHECK_FLAG(
9559 p->cap,
9560 PEER_CAP_REFRESH_NEW_RCV)
9561 || CHECK_FLAG(
9562 p->cap,
9563 PEER_CAP_REFRESH_OLD_RCV))) {
9564 if (CHECK_FLAG(
9565 p->cap,
9566 PEER_CAP_REFRESH_OLD_RCV)
9567 && CHECK_FLAG(
9568 p->cap,
9569 PEER_CAP_REFRESH_NEW_RCV))
9570 json_object_string_add(
9571 json_cap,
9572 "routeRefresh",
9573 "advertisedAndReceivedOldNew");
9574 else {
9575 if (CHECK_FLAG(
9576 p->cap,
9577 PEER_CAP_REFRESH_OLD_RCV))
9578 json_object_string_add(
9579 json_cap,
9580 "routeRefresh",
9581 "advertisedAndReceivedOld");
9582 else
9583 json_object_string_add(
9584 json_cap,
9585 "routeRefresh",
9586 "advertisedAndReceivedNew");
9587 }
9588 } else if (
9589 CHECK_FLAG(
9590 p->cap,
9591 PEER_CAP_REFRESH_ADV))
9592 json_object_string_add(
9593 json_cap,
9594 "routeRefresh",
9595 "advertised");
9596 else if (
9597 CHECK_FLAG(
9598 p->cap,
9599 PEER_CAP_REFRESH_NEW_RCV)
9600 || CHECK_FLAG(
9601 p->cap,
9602 PEER_CAP_REFRESH_OLD_RCV))
9603 json_object_string_add(
9604 json_cap,
9605 "routeRefresh",
9606 "received");
9607 }
9608
9609 /* Multiprotocol Extensions */
9610 json_object *json_multi = NULL;
9611 json_multi = json_object_new_object();
9612
9613 FOREACH_AFI_SAFI (afi, safi) {
9614 if (p->afc_adv[afi][safi]
9615 || p->afc_recv[afi][safi]) {
9616 json_object *json_exten = NULL;
9617 json_exten =
9618 json_object_new_object();
9619
9620 if (p->afc_adv[afi][safi]
9621 && p->afc_recv[afi][safi])
9622 json_object_boolean_true_add(
9623 json_exten,
9624 "advertisedAndReceived");
9625 else if (p->afc_adv[afi][safi])
9626 json_object_boolean_true_add(
9627 json_exten,
9628 "advertised");
9629 else if (p->afc_recv[afi][safi])
9630 json_object_boolean_true_add(
9631 json_exten,
9632 "received");
9633
9634 json_object_object_add(
9635 json_multi,
9636 afi_safi_print(afi,
9637 safi),
9638 json_exten);
9639 }
9640 }
9641 json_object_object_add(
9642 json_cap, "multiprotocolExtensions",
9643 json_multi);
9644
9645 /* Hostname capabilities */
9646 json_object *json_hname = NULL;
9647
9648 json_hname = json_object_new_object();
9649
9650 if (CHECK_FLAG(p->cap, PEER_CAP_HOSTNAME_ADV)) {
9651 json_object_string_add(
9652 json_hname, "advHostName",
9653 bgp->peer_self->hostname
9654 ? bgp->peer_self
9655 ->hostname
9656 : "n/a");
9657 json_object_string_add(
9658 json_hname, "advDomainName",
9659 bgp->peer_self->domainname
9660 ? bgp->peer_self
9661 ->domainname
9662 : "n/a");
9663 }
9664
9665
9666 if (CHECK_FLAG(p->cap, PEER_CAP_HOSTNAME_RCV)) {
9667 json_object_string_add(
9668 json_hname, "rcvHostName",
9669 p->hostname ? p->hostname
9670 : "n/a");
9671 json_object_string_add(
9672 json_hname, "rcvDomainName",
9673 p->domainname ? p->domainname
9674 : "n/a");
9675 }
9676
9677 json_object_object_add(json_cap, "hostName",
9678 json_hname);
9679
9680 /* Gracefull Restart */
9681 if (CHECK_FLAG(p->cap, PEER_CAP_RESTART_RCV)
9682 || CHECK_FLAG(p->cap,
9683 PEER_CAP_RESTART_ADV)) {
9684 if (CHECK_FLAG(p->cap,
9685 PEER_CAP_RESTART_ADV)
9686 && CHECK_FLAG(p->cap,
9687 PEER_CAP_RESTART_RCV))
9688 json_object_string_add(
9689 json_cap,
9690 "gracefulRestart",
9691 "advertisedAndReceived");
9692 else if (CHECK_FLAG(
9693 p->cap,
9694 PEER_CAP_RESTART_ADV))
9695 json_object_string_add(
9696 json_cap,
9697 "gracefulRestartCapability",
9698 "advertised");
9699 else if (CHECK_FLAG(
9700 p->cap,
9701 PEER_CAP_RESTART_RCV))
9702 json_object_string_add(
9703 json_cap,
9704 "gracefulRestartCapability",
9705 "received");
9706
9707 if (CHECK_FLAG(p->cap,
9708 PEER_CAP_RESTART_RCV)) {
9709 int restart_af_count = 0;
9710 json_object *json_restart =
9711 NULL;
9712 json_restart =
9713 json_object_new_object();
9714
9715 json_object_int_add(
9716 json_cap,
9717 "gracefulRestartRemoteTimerMsecs",
9718 p->v_gr_restart * 1000);
9719
9720 FOREACH_AFI_SAFI (afi, safi) {
9721 if (CHECK_FLAG(
9722 p->af_cap
9723 [afi]
9724 [safi],
9725 PEER_CAP_RESTART_AF_RCV)) {
9726 json_object *
9727 json_sub =
9728 NULL;
9729 json_sub =
9730 json_object_new_object();
9731
9732 if (CHECK_FLAG(
9733 p->af_cap
9734 [afi]
9735 [safi],
9736 PEER_CAP_RESTART_AF_PRESERVE_RCV))
9737 json_object_boolean_true_add(
9738 json_sub,
9739 "preserved");
9740 restart_af_count++;
9741 json_object_object_add(
9742 json_restart,
9743 afi_safi_print(
9744 afi,
9745 safi),
9746 json_sub);
9747 }
9748 }
9749 if (!restart_af_count) {
9750 json_object_string_add(
9751 json_cap,
9752 "addressFamiliesByPeer",
9753 "none");
9754 json_object_free(
9755 json_restart);
9756 } else
9757 json_object_object_add(
9758 json_cap,
9759 "addressFamiliesByPeer",
9760 json_restart);
9761 }
9762 }
9763 json_object_object_add(json_neigh,
9764 "neighborCapabilities",
9765 json_cap);
9766 } else {
9767 vty_out(vty, " Neighbor capabilities:\n");
9768
9769 /* AS4 */
9770 if (CHECK_FLAG(p->cap, PEER_CAP_AS4_RCV)
9771 || CHECK_FLAG(p->cap, PEER_CAP_AS4_ADV)) {
9772 vty_out(vty, " 4 Byte AS:");
9773 if (CHECK_FLAG(p->cap,
9774 PEER_CAP_AS4_ADV))
9775 vty_out(vty, " advertised");
9776 if (CHECK_FLAG(p->cap,
9777 PEER_CAP_AS4_RCV))
9778 vty_out(vty, " %sreceived",
9779 CHECK_FLAG(
9780 p->cap,
9781 PEER_CAP_AS4_ADV)
9782 ? "and "
9783 : "");
9784 vty_out(vty, "\n");
9785 }
9786
9787 /* AddPath */
9788 if (CHECK_FLAG(p->cap, PEER_CAP_ADDPATH_RCV)
9789 || CHECK_FLAG(p->cap,
9790 PEER_CAP_ADDPATH_ADV)) {
9791 vty_out(vty, " AddPath:\n");
9792
9793 FOREACH_AFI_SAFI (afi, safi) {
9794 if (CHECK_FLAG(
9795 p->af_cap[afi]
9796 [safi],
9797 PEER_CAP_ADDPATH_AF_TX_ADV)
9798 || CHECK_FLAG(
9799 p->af_cap[afi]
9800 [safi],
9801 PEER_CAP_ADDPATH_AF_TX_RCV)) {
9802 vty_out(vty,
9803 " %s: TX ",
9804 afi_safi_print(
9805 afi,
9806 safi));
9807
9808 if (CHECK_FLAG(
9809 p->af_cap
9810 [afi]
9811 [safi],
9812 PEER_CAP_ADDPATH_AF_TX_ADV))
9813 vty_out(vty,
9814 "advertised %s",
9815 afi_safi_print(
9816 afi,
9817 safi));
9818
9819 if (CHECK_FLAG(
9820 p->af_cap
9821 [afi]
9822 [safi],
9823 PEER_CAP_ADDPATH_AF_TX_RCV))
9824 vty_out(vty,
9825 "%sreceived",
9826 CHECK_FLAG(
9827 p->af_cap
9828 [afi]
9829 [safi],
9830 PEER_CAP_ADDPATH_AF_TX_ADV)
9831 ? " and "
9832 : "");
9833
9834 vty_out(vty, "\n");
9835 }
9836
9837 if (CHECK_FLAG(
9838 p->af_cap[afi]
9839 [safi],
9840 PEER_CAP_ADDPATH_AF_RX_ADV)
9841 || CHECK_FLAG(
9842 p->af_cap[afi]
9843 [safi],
9844 PEER_CAP_ADDPATH_AF_RX_RCV)) {
9845 vty_out(vty,
9846 " %s: RX ",
9847 afi_safi_print(
9848 afi,
9849 safi));
9850
9851 if (CHECK_FLAG(
9852 p->af_cap
9853 [afi]
9854 [safi],
9855 PEER_CAP_ADDPATH_AF_RX_ADV))
9856 vty_out(vty,
9857 "advertised %s",
9858 afi_safi_print(
9859 afi,
9860 safi));
9861
9862 if (CHECK_FLAG(
9863 p->af_cap
9864 [afi]
9865 [safi],
9866 PEER_CAP_ADDPATH_AF_RX_RCV))
9867 vty_out(vty,
9868 "%sreceived",
9869 CHECK_FLAG(
9870 p->af_cap
9871 [afi]
9872 [safi],
9873 PEER_CAP_ADDPATH_AF_RX_ADV)
9874 ? " and "
9875 : "");
9876
9877 vty_out(vty, "\n");
9878 }
9879 }
9880 }
9881
9882 /* Dynamic */
9883 if (CHECK_FLAG(p->cap, PEER_CAP_DYNAMIC_RCV)
9884 || CHECK_FLAG(p->cap,
9885 PEER_CAP_DYNAMIC_ADV)) {
9886 vty_out(vty, " Dynamic:");
9887 if (CHECK_FLAG(p->cap,
9888 PEER_CAP_DYNAMIC_ADV))
9889 vty_out(vty, " advertised");
9890 if (CHECK_FLAG(p->cap,
9891 PEER_CAP_DYNAMIC_RCV))
9892 vty_out(vty, " %sreceived",
9893 CHECK_FLAG(
9894 p->cap,
9895 PEER_CAP_DYNAMIC_ADV)
9896 ? "and "
9897 : "");
9898 vty_out(vty, "\n");
9899 }
9900
9901 /* Extended nexthop */
9902 if (CHECK_FLAG(p->cap, PEER_CAP_ENHE_RCV)
9903 || CHECK_FLAG(p->cap, PEER_CAP_ENHE_ADV)) {
9904 vty_out(vty, " Extended nexthop:");
9905 if (CHECK_FLAG(p->cap,
9906 PEER_CAP_ENHE_ADV))
9907 vty_out(vty, " advertised");
9908 if (CHECK_FLAG(p->cap,
9909 PEER_CAP_ENHE_RCV))
9910 vty_out(vty, " %sreceived",
9911 CHECK_FLAG(
9912 p->cap,
9913 PEER_CAP_ENHE_ADV)
9914 ? "and "
9915 : "");
9916 vty_out(vty, "\n");
9917
9918 if (CHECK_FLAG(p->cap,
9919 PEER_CAP_ENHE_RCV)) {
9920 vty_out(vty,
9921 " Address families by peer:\n ");
9922 for (safi = SAFI_UNICAST;
9923 safi < SAFI_MAX; safi++)
9924 if (CHECK_FLAG(
9925 p->af_cap
9926 [AFI_IP]
9927 [safi],
9928 PEER_CAP_ENHE_AF_RCV))
9929 vty_out(vty,
9930 " %s\n",
9931 afi_safi_print(
9932 AFI_IP,
9933 safi));
9934 }
9935 }
9936
9937 /* Route Refresh */
9938 if (CHECK_FLAG(p->cap, PEER_CAP_REFRESH_ADV)
9939 || CHECK_FLAG(p->cap,
9940 PEER_CAP_REFRESH_NEW_RCV)
9941 || CHECK_FLAG(p->cap,
9942 PEER_CAP_REFRESH_OLD_RCV)) {
9943 vty_out(vty, " Route refresh:");
9944 if (CHECK_FLAG(p->cap,
9945 PEER_CAP_REFRESH_ADV))
9946 vty_out(vty, " advertised");
9947 if (CHECK_FLAG(p->cap,
9948 PEER_CAP_REFRESH_NEW_RCV)
9949 || CHECK_FLAG(
9950 p->cap,
9951 PEER_CAP_REFRESH_OLD_RCV))
9952 vty_out(vty, " %sreceived(%s)",
9953 CHECK_FLAG(
9954 p->cap,
9955 PEER_CAP_REFRESH_ADV)
9956 ? "and "
9957 : "",
9958 (CHECK_FLAG(
9959 p->cap,
9960 PEER_CAP_REFRESH_OLD_RCV)
9961 && CHECK_FLAG(
9962 p->cap,
9963 PEER_CAP_REFRESH_NEW_RCV))
9964 ? "old & new"
9965 : CHECK_FLAG(
9966 p->cap,
9967 PEER_CAP_REFRESH_OLD_RCV)
9968 ? "old"
9969 : "new");
9970
9971 vty_out(vty, "\n");
9972 }
9973
9974 /* Multiprotocol Extensions */
9975 FOREACH_AFI_SAFI (afi, safi)
9976 if (p->afc_adv[afi][safi]
9977 || p->afc_recv[afi][safi]) {
9978 vty_out(vty,
9979 " Address Family %s:",
9980 afi_safi_print(afi,
9981 safi));
9982 if (p->afc_adv[afi][safi])
9983 vty_out(vty,
9984 " advertised");
9985 if (p->afc_recv[afi][safi])
9986 vty_out(vty,
9987 " %sreceived",
9988 p->afc_adv[afi]
9989 [safi]
9990 ? "and "
9991 : "");
9992 vty_out(vty, "\n");
9993 }
9994
9995 /* Hostname capability */
9996 vty_out(vty, " Hostname Capability:");
9997
9998 if (CHECK_FLAG(p->cap, PEER_CAP_HOSTNAME_ADV)) {
9999 vty_out(vty,
10000 " advertised (name: %s,domain name: %s)",
10001 bgp->peer_self->hostname
10002 ? bgp->peer_self
10003 ->hostname
10004 : "n/a",
10005 bgp->peer_self->domainname
10006 ? bgp->peer_self
10007 ->domainname
10008 : "n/a");
10009 } else {
10010 vty_out(vty, " not advertised");
10011 }
10012
10013 if (CHECK_FLAG(p->cap, PEER_CAP_HOSTNAME_RCV)) {
10014 vty_out(vty,
10015 " received (name: %s,domain name: %s)",
10016 p->hostname ? p->hostname
10017 : "n/a",
10018 p->domainname ? p->domainname
10019 : "n/a");
10020 } else {
10021 vty_out(vty, " not received");
10022 }
10023
10024 vty_out(vty, "\n");
10025
10026 /* Gracefull Restart */
10027 if (CHECK_FLAG(p->cap, PEER_CAP_RESTART_RCV)
10028 || CHECK_FLAG(p->cap,
10029 PEER_CAP_RESTART_ADV)) {
10030 vty_out(vty,
10031 " Graceful Restart Capabilty:");
10032 if (CHECK_FLAG(p->cap,
10033 PEER_CAP_RESTART_ADV))
10034 vty_out(vty, " advertised");
10035 if (CHECK_FLAG(p->cap,
10036 PEER_CAP_RESTART_RCV))
10037 vty_out(vty, " %sreceived",
10038 CHECK_FLAG(
10039 p->cap,
10040 PEER_CAP_RESTART_ADV)
10041 ? "and "
10042 : "");
10043 vty_out(vty, "\n");
10044
10045 if (CHECK_FLAG(p->cap,
10046 PEER_CAP_RESTART_RCV)) {
10047 int restart_af_count = 0;
10048
10049 vty_out(vty,
10050 " Remote Restart timer is %d seconds\n",
10051 p->v_gr_restart);
10052 vty_out(vty,
10053 " Address families by peer:\n ");
10054
10055 FOREACH_AFI_SAFI (afi, safi)
10056 if (CHECK_FLAG(
10057 p->af_cap
10058 [afi]
10059 [safi],
10060 PEER_CAP_RESTART_AF_RCV)) {
10061 vty_out(vty,
10062 "%s%s(%s)",
10063 restart_af_count
10064 ? ", "
10065 : "",
10066 afi_safi_print(
10067 afi,
10068 safi),
10069 CHECK_FLAG(
10070 p->af_cap
10071 [afi]
10072 [safi],
10073 PEER_CAP_RESTART_AF_PRESERVE_RCV)
10074 ? "preserved"
10075 : "not preserved");
10076 restart_af_count++;
10077 }
10078 if (!restart_af_count)
10079 vty_out(vty, "none");
10080 vty_out(vty, "\n");
10081 }
10082 }
10083 }
10084 }
10085 }
10086
10087 /* graceful restart information */
10088 if (CHECK_FLAG(p->cap, PEER_CAP_RESTART_RCV) || p->t_gr_restart
10089 || p->t_gr_stale) {
10090 json_object *json_grace = NULL;
10091 json_object *json_grace_send = NULL;
10092 json_object *json_grace_recv = NULL;
10093 int eor_send_af_count = 0;
10094 int eor_receive_af_count = 0;
10095
10096 if (use_json) {
10097 json_grace = json_object_new_object();
10098 json_grace_send = json_object_new_object();
10099 json_grace_recv = json_object_new_object();
10100
10101 if (p->status == Established) {
10102 FOREACH_AFI_SAFI (afi, safi) {
10103 if (CHECK_FLAG(p->af_sflags[afi][safi],
10104 PEER_STATUS_EOR_SEND)) {
10105 json_object_boolean_true_add(
10106 json_grace_send,
10107 afi_safi_print(afi,
10108 safi));
10109 eor_send_af_count++;
10110 }
10111 }
10112 FOREACH_AFI_SAFI (afi, safi) {
10113 if (CHECK_FLAG(
10114 p->af_sflags[afi][safi],
10115 PEER_STATUS_EOR_RECEIVED)) {
10116 json_object_boolean_true_add(
10117 json_grace_recv,
10118 afi_safi_print(afi,
10119 safi));
10120 eor_receive_af_count++;
10121 }
10122 }
10123 }
10124
10125 json_object_object_add(json_grace, "endOfRibSend",
10126 json_grace_send);
10127 json_object_object_add(json_grace, "endOfRibRecv",
10128 json_grace_recv);
10129
10130 if (p->t_gr_restart)
10131 json_object_int_add(json_grace,
10132 "gracefulRestartTimerMsecs",
10133 thread_timer_remain_second(
10134 p->t_gr_restart)
10135 * 1000);
10136
10137 if (p->t_gr_stale)
10138 json_object_int_add(
10139 json_grace,
10140 "gracefulStalepathTimerMsecs",
10141 thread_timer_remain_second(
10142 p->t_gr_stale)
10143 * 1000);
10144
10145 json_object_object_add(
10146 json_neigh, "gracefulRestartInfo", json_grace);
10147 } else {
10148 vty_out(vty, " Graceful restart informations:\n");
10149 if (p->status == Established) {
10150 vty_out(vty, " End-of-RIB send: ");
10151 FOREACH_AFI_SAFI (afi, safi) {
10152 if (CHECK_FLAG(p->af_sflags[afi][safi],
10153 PEER_STATUS_EOR_SEND)) {
10154 vty_out(vty, "%s%s",
10155 eor_send_af_count ? ", "
10156 : "",
10157 afi_safi_print(afi,
10158 safi));
10159 eor_send_af_count++;
10160 }
10161 }
10162 vty_out(vty, "\n");
10163 vty_out(vty, " End-of-RIB received: ");
10164 FOREACH_AFI_SAFI (afi, safi) {
10165 if (CHECK_FLAG(
10166 p->af_sflags[afi][safi],
10167 PEER_STATUS_EOR_RECEIVED)) {
10168 vty_out(vty, "%s%s",
10169 eor_receive_af_count
10170 ? ", "
10171 : "",
10172 afi_safi_print(afi,
10173 safi));
10174 eor_receive_af_count++;
10175 }
10176 }
10177 vty_out(vty, "\n");
10178 }
10179
10180 if (p->t_gr_restart)
10181 vty_out(vty,
10182 " The remaining time of restart timer is %ld\n",
10183 thread_timer_remain_second(
10184 p->t_gr_restart));
10185
10186 if (p->t_gr_stale)
10187 vty_out(vty,
10188 " The remaining time of stalepath timer is %ld\n",
10189 thread_timer_remain_second(
10190 p->t_gr_stale));
10191 }
10192 }
10193 if (use_json) {
10194 json_object *json_stat = NULL;
10195 json_stat = json_object_new_object();
10196 /* Packet counts. */
10197 json_object_int_add(json_stat, "depthInq", 0);
10198 json_object_int_add(json_stat, "depthOutq",
10199 (unsigned long)p->obuf->count);
10200 json_object_int_add(json_stat, "opensSent",
10201 atomic_load_explicit(&p->open_out,
10202 memory_order_relaxed));
10203 json_object_int_add(json_stat, "opensRecv",
10204 atomic_load_explicit(&p->open_in,
10205 memory_order_relaxed));
10206 json_object_int_add(json_stat, "notificationsSent",
10207 atomic_load_explicit(&p->notify_out,
10208 memory_order_relaxed));
10209 json_object_int_add(json_stat, "notificationsRecv",
10210 atomic_load_explicit(&p->notify_in,
10211 memory_order_relaxed));
10212 json_object_int_add(json_stat, "updatesSent",
10213 atomic_load_explicit(&p->update_out,
10214 memory_order_relaxed));
10215 json_object_int_add(json_stat, "updatesRecv",
10216 atomic_load_explicit(&p->update_in,
10217 memory_order_relaxed));
10218 json_object_int_add(json_stat, "keepalivesSent",
10219 atomic_load_explicit(&p->keepalive_out,
10220 memory_order_relaxed));
10221 json_object_int_add(json_stat, "keepalivesRecv",
10222 atomic_load_explicit(&p->keepalive_in,
10223 memory_order_relaxed));
10224 json_object_int_add(json_stat, "routeRefreshSent",
10225 atomic_load_explicit(&p->refresh_out,
10226 memory_order_relaxed));
10227 json_object_int_add(json_stat, "routeRefreshRecv",
10228 atomic_load_explicit(&p->refresh_in,
10229 memory_order_relaxed));
10230 json_object_int_add(json_stat, "capabilitySent",
10231 atomic_load_explicit(&p->dynamic_cap_out,
10232 memory_order_relaxed));
10233 json_object_int_add(json_stat, "capabilityRecv",
10234 atomic_load_explicit(&p->dynamic_cap_in,
10235 memory_order_relaxed));
10236 json_object_int_add(json_stat, "totalSent", PEER_TOTAL_TX(p));
10237 json_object_int_add(json_stat, "totalRecv", PEER_TOTAL_RX(p));
10238 json_object_object_add(json_neigh, "messageStats", json_stat);
10239 } else {
10240 /* Packet counts. */
10241 vty_out(vty, " Message statistics:\n");
10242 vty_out(vty, " Inq depth is 0\n");
10243 vty_out(vty, " Outq depth is %lu\n",
10244 (unsigned long)p->obuf->count);
10245 vty_out(vty, " Sent Rcvd\n");
10246 vty_out(vty, " Opens: %10d %10d\n",
10247 atomic_load_explicit(&p->open_out,
10248 memory_order_relaxed),
10249 atomic_load_explicit(&p->open_in,
10250 memory_order_relaxed));
10251 vty_out(vty, " Notifications: %10d %10d\n",
10252 atomic_load_explicit(&p->notify_out,
10253 memory_order_relaxed),
10254 atomic_load_explicit(&p->notify_in,
10255 memory_order_relaxed));
10256 vty_out(vty, " Updates: %10d %10d\n",
10257 atomic_load_explicit(&p->update_out,
10258 memory_order_relaxed),
10259 atomic_load_explicit(&p->update_in,
10260 memory_order_relaxed));
10261 vty_out(vty, " Keepalives: %10d %10d\n",
10262 atomic_load_explicit(&p->keepalive_out,
10263 memory_order_relaxed),
10264 atomic_load_explicit(&p->keepalive_in,
10265 memory_order_relaxed));
10266 vty_out(vty, " Route Refresh: %10d %10d\n",
10267 atomic_load_explicit(&p->refresh_out,
10268 memory_order_relaxed),
10269 atomic_load_explicit(&p->refresh_in,
10270 memory_order_relaxed));
10271 vty_out(vty, " Capability: %10d %10d\n",
10272 atomic_load_explicit(&p->dynamic_cap_out,
10273 memory_order_relaxed),
10274 atomic_load_explicit(&p->dynamic_cap_in,
10275 memory_order_relaxed));
10276 vty_out(vty, " Total: %10d %10d\n", PEER_TOTAL_TX(p),
10277 PEER_TOTAL_RX(p));
10278 }
10279
10280 if (use_json) {
10281 /* advertisement-interval */
10282 json_object_int_add(json_neigh,
10283 "minBtwnAdvertisementRunsTimerMsecs",
10284 p->v_routeadv * 1000);
10285
10286 /* Update-source. */
10287 if (p->update_if || p->update_source) {
10288 if (p->update_if)
10289 json_object_string_add(json_neigh,
10290 "updateSource",
10291 p->update_if);
10292 else if (p->update_source)
10293 json_object_string_add(
10294 json_neigh, "updateSource",
10295 sockunion2str(p->update_source, buf1,
10296 SU_ADDRSTRLEN));
10297 }
10298 } else {
10299 /* advertisement-interval */
10300 vty_out(vty,
10301 " Minimum time between advertisement runs is %d seconds\n",
10302 p->v_routeadv);
10303
10304 /* Update-source. */
10305 if (p->update_if || p->update_source) {
10306 vty_out(vty, " Update source is ");
10307 if (p->update_if)
10308 vty_out(vty, "%s", p->update_if);
10309 else if (p->update_source)
10310 vty_out(vty, "%s",
10311 sockunion2str(p->update_source, buf1,
10312 SU_ADDRSTRLEN));
10313 vty_out(vty, "\n");
10314 }
10315
10316 vty_out(vty, "\n");
10317 }
10318
10319 /* Address Family Information */
10320 json_object *json_hold = NULL;
10321
10322 if (use_json)
10323 json_hold = json_object_new_object();
10324
10325 FOREACH_AFI_SAFI (afi, safi)
10326 if (p->afc[afi][safi])
10327 bgp_show_peer_afi(vty, p, afi, safi, use_json,
10328 json_hold);
10329
10330 if (use_json) {
10331 json_object_object_add(json_neigh, "addressFamilyInfo",
10332 json_hold);
10333 json_object_int_add(json_neigh, "connectionsEstablished",
10334 p->established);
10335 json_object_int_add(json_neigh, "connectionsDropped",
10336 p->dropped);
10337 } else
10338 vty_out(vty, " Connections established %d; dropped %d\n",
10339 p->established, p->dropped);
10340
10341 if (!p->last_reset) {
10342 if (use_json)
10343 json_object_string_add(json_neigh, "lastReset",
10344 "never");
10345 else
10346 vty_out(vty, " Last reset never\n");
10347 } else {
10348 if (use_json) {
10349 time_t uptime;
10350 struct tm *tm;
10351
10352 uptime = bgp_clock();
10353 uptime -= p->resettime;
10354 tm = gmtime(&uptime);
10355 json_object_int_add(json_neigh, "lastResetTimerMsecs",
10356 (tm->tm_sec * 1000)
10357 + (tm->tm_min * 60000)
10358 + (tm->tm_hour * 3600000));
10359 json_object_string_add(
10360 json_neigh, "lastResetDueTo",
10361 peer_down_str[(int)p->last_reset]);
10362 if (p->last_reset == PEER_DOWN_NOTIFY_SEND
10363 || p->last_reset == PEER_DOWN_NOTIFY_RECEIVED) {
10364 char errorcodesubcode_hexstr[5];
10365 char errorcodesubcode_str[256];
10366
10367 code_str = bgp_notify_code_str(p->notify.code);
10368 subcode_str = bgp_notify_subcode_str(
10369 p->notify.code, p->notify.subcode);
10370
10371 sprintf(errorcodesubcode_hexstr, "%02X%02X",
10372 p->notify.code, p->notify.subcode);
10373 json_object_string_add(json_neigh,
10374 "lastErrorCodeSubcode",
10375 errorcodesubcode_hexstr);
10376 snprintf(errorcodesubcode_str, 255, "%s%s",
10377 code_str, subcode_str);
10378 json_object_string_add(json_neigh,
10379 "lastNotificationReason",
10380 errorcodesubcode_str);
10381 if (p->last_reset == PEER_DOWN_NOTIFY_RECEIVED
10382 && p->notify.code == BGP_NOTIFY_CEASE
10383 && (p->notify.subcode
10384 == BGP_NOTIFY_CEASE_ADMIN_SHUTDOWN
10385 || p->notify.subcode
10386 == BGP_NOTIFY_CEASE_ADMIN_RESET)
10387 && p->notify.length) {
10388 char msgbuf[1024];
10389 const char *msg_str;
10390
10391 msg_str = bgp_notify_admin_message(
10392 msgbuf, sizeof(msgbuf),
10393 (uint8_t *)p->notify.data,
10394 p->notify.length);
10395 if (msg_str)
10396 json_object_string_add(
10397 json_neigh,
10398 "lastShutdownDescription",
10399 msg_str);
10400 }
10401 }
10402 } else {
10403 vty_out(vty, " Last reset %s, ",
10404 peer_uptime(p->resettime, timebuf,
10405 BGP_UPTIME_LEN, 0, NULL));
10406
10407 if (p->last_reset == PEER_DOWN_NOTIFY_SEND
10408 || p->last_reset == PEER_DOWN_NOTIFY_RECEIVED) {
10409 code_str = bgp_notify_code_str(p->notify.code);
10410 subcode_str = bgp_notify_subcode_str(
10411 p->notify.code, p->notify.subcode);
10412 vty_out(vty, "due to NOTIFICATION %s (%s%s)\n",
10413 p->last_reset == PEER_DOWN_NOTIFY_SEND
10414 ? "sent"
10415 : "received",
10416 code_str, subcode_str);
10417 if (p->last_reset == PEER_DOWN_NOTIFY_RECEIVED
10418 && p->notify.code == BGP_NOTIFY_CEASE
10419 && (p->notify.subcode
10420 == BGP_NOTIFY_CEASE_ADMIN_SHUTDOWN
10421 || p->notify.subcode
10422 == BGP_NOTIFY_CEASE_ADMIN_RESET)
10423 && p->notify.length) {
10424 char msgbuf[1024];
10425 const char *msg_str;
10426
10427 msg_str = bgp_notify_admin_message(
10428 msgbuf, sizeof(msgbuf),
10429 (uint8_t *)p->notify.data,
10430 p->notify.length);
10431 if (msg_str)
10432 vty_out(vty,
10433 " Message: \"%s\"\n",
10434 msg_str);
10435 }
10436 } else {
10437 vty_out(vty, "due to %s\n",
10438 peer_down_str[(int)p->last_reset]);
10439 }
10440
10441 if (p->last_reset_cause_size) {
10442 msg = p->last_reset_cause;
10443 vty_out(vty,
10444 " Message received that caused BGP to send a NOTIFICATION:\n ");
10445 for (i = 1; i <= p->last_reset_cause_size;
10446 i++) {
10447 vty_out(vty, "%02X", *msg++);
10448
10449 if (i != p->last_reset_cause_size) {
10450 if (i % 16 == 0) {
10451 vty_out(vty, "\n ");
10452 } else if (i % 4 == 0) {
10453 vty_out(vty, " ");
10454 }
10455 }
10456 }
10457 vty_out(vty, "\n");
10458 }
10459 }
10460 }
10461
10462 if (CHECK_FLAG(p->sflags, PEER_STATUS_PREFIX_OVERFLOW)) {
10463 if (use_json)
10464 json_object_boolean_true_add(json_neigh,
10465 "prefixesConfigExceedMax");
10466 else
10467 vty_out(vty,
10468 " Peer had exceeded the max. no. of prefixes configured.\n");
10469
10470 if (p->t_pmax_restart) {
10471 if (use_json) {
10472 json_object_boolean_true_add(
10473 json_neigh, "reducePrefixNumFrom");
10474 json_object_int_add(json_neigh,
10475 "restartInTimerMsec",
10476 thread_timer_remain_second(
10477 p->t_pmax_restart)
10478 * 1000);
10479 } else
10480 vty_out(vty,
10481 " Reduce the no. of prefix from %s, will restart in %ld seconds\n",
10482 p->host, thread_timer_remain_second(
10483 p->t_pmax_restart));
10484 } else {
10485 if (use_json)
10486 json_object_boolean_true_add(
10487 json_neigh,
10488 "reducePrefixNumAndClearIpBgp");
10489 else
10490 vty_out(vty,
10491 " Reduce the no. of prefix and clear ip bgp %s to restore peering\n",
10492 p->host);
10493 }
10494 }
10495
10496 /* EBGP Multihop and GTSM */
10497 if (p->sort != BGP_PEER_IBGP) {
10498 if (use_json) {
10499 if (p->gtsm_hops > 0)
10500 json_object_int_add(json_neigh,
10501 "externalBgpNbrMaxHopsAway",
10502 p->gtsm_hops);
10503 else if (p->ttl > 1)
10504 json_object_int_add(json_neigh,
10505 "externalBgpNbrMaxHopsAway",
10506 p->ttl);
10507 } else {
10508 if (p->gtsm_hops > 0)
10509 vty_out(vty,
10510 " External BGP neighbor may be up to %d hops away.\n",
10511 p->gtsm_hops);
10512 else if (p->ttl > 1)
10513 vty_out(vty,
10514 " External BGP neighbor may be up to %d hops away.\n",
10515 p->ttl);
10516 }
10517 } else {
10518 if (p->gtsm_hops > 0) {
10519 if (use_json)
10520 json_object_int_add(json_neigh,
10521 "internalBgpNbrMaxHopsAway",
10522 p->gtsm_hops);
10523 else
10524 vty_out(vty,
10525 " Internal BGP neighbor may be up to %d hops away.\n",
10526 p->gtsm_hops);
10527 }
10528 }
10529
10530 /* Local address. */
10531 if (p->su_local) {
10532 if (use_json) {
10533 json_object_string_add(json_neigh, "hostLocal",
10534 sockunion2str(p->su_local, buf1,
10535 SU_ADDRSTRLEN));
10536 json_object_int_add(json_neigh, "portLocal",
10537 ntohs(p->su_local->sin.sin_port));
10538 } else
10539 vty_out(vty, "Local host: %s, Local port: %d\n",
10540 sockunion2str(p->su_local, buf1, SU_ADDRSTRLEN),
10541 ntohs(p->su_local->sin.sin_port));
10542 }
10543
10544 /* Remote address. */
10545 if (p->su_remote) {
10546 if (use_json) {
10547 json_object_string_add(json_neigh, "hostForeign",
10548 sockunion2str(p->su_remote, buf1,
10549 SU_ADDRSTRLEN));
10550 json_object_int_add(json_neigh, "portForeign",
10551 ntohs(p->su_remote->sin.sin_port));
10552 } else
10553 vty_out(vty, "Foreign host: %s, Foreign port: %d\n",
10554 sockunion2str(p->su_remote, buf1,
10555 SU_ADDRSTRLEN),
10556 ntohs(p->su_remote->sin.sin_port));
10557 }
10558
10559 /* Nexthop display. */
10560 if (p->su_local) {
10561 if (use_json) {
10562 json_object_string_add(json_neigh, "nexthop",
10563 inet_ntop(AF_INET,
10564 &p->nexthop.v4, buf1,
10565 sizeof(buf1)));
10566 json_object_string_add(json_neigh, "nexthopGlobal",
10567 inet_ntop(AF_INET6,
10568 &p->nexthop.v6_global,
10569 buf1, sizeof(buf1)));
10570 json_object_string_add(json_neigh, "nexthopLocal",
10571 inet_ntop(AF_INET6,
10572 &p->nexthop.v6_local,
10573 buf1, sizeof(buf1)));
10574 if (p->shared_network)
10575 json_object_string_add(json_neigh,
10576 "bgpConnection",
10577 "sharedNetwork");
10578 else
10579 json_object_string_add(json_neigh,
10580 "bgpConnection",
10581 "nonSharedNetwork");
10582 } else {
10583 vty_out(vty, "Nexthop: %s\n",
10584 inet_ntop(AF_INET, &p->nexthop.v4, buf1,
10585 sizeof(buf1)));
10586 vty_out(vty, "Nexthop global: %s\n",
10587 inet_ntop(AF_INET6, &p->nexthop.v6_global, buf1,
10588 sizeof(buf1)));
10589 vty_out(vty, "Nexthop local: %s\n",
10590 inet_ntop(AF_INET6, &p->nexthop.v6_local, buf1,
10591 sizeof(buf1)));
10592 vty_out(vty, "BGP connection: %s\n",
10593 p->shared_network ? "shared network"
10594 : "non shared network");
10595 }
10596 }
10597
10598 /* Timer information. */
10599 if (use_json) {
10600 json_object_int_add(json_neigh, "connectRetryTimer",
10601 p->v_connect);
10602 if (p->status == Established && p->rtt)
10603 json_object_int_add(json_neigh, "estimatedRttInMsecs",
10604 p->rtt);
10605 if (p->t_start)
10606 json_object_int_add(
10607 json_neigh, "nextStartTimerDueInMsecs",
10608 thread_timer_remain_second(p->t_start) * 1000);
10609 if (p->t_connect)
10610 json_object_int_add(
10611 json_neigh, "nextConnectTimerDueInMsecs",
10612 thread_timer_remain_second(p->t_connect)
10613 * 1000);
10614 if (p->t_routeadv) {
10615 json_object_int_add(json_neigh, "mraiInterval",
10616 p->v_routeadv);
10617 json_object_int_add(
10618 json_neigh, "mraiTimerExpireInMsecs",
10619 thread_timer_remain_second(p->t_routeadv)
10620 * 1000);
10621 }
10622 if (p->password)
10623 json_object_int_add(json_neigh, "authenticationEnabled",
10624 1);
10625
10626 if (p->t_read)
10627 json_object_string_add(json_neigh, "readThread", "on");
10628 else
10629 json_object_string_add(json_neigh, "readThread", "off");
10630
10631 if (CHECK_FLAG(p->thread_flags, PEER_THREAD_WRITES_ON))
10632 json_object_string_add(json_neigh, "writeThread", "on");
10633 else
10634 json_object_string_add(json_neigh, "writeThread",
10635 "off");
10636 } else {
10637 vty_out(vty, "BGP Connect Retry Timer in Seconds: %d\n",
10638 p->v_connect);
10639 if (p->status == Established && p->rtt)
10640 vty_out(vty, "Estimated round trip time: %d ms\n",
10641 p->rtt);
10642 if (p->t_start)
10643 vty_out(vty, "Next start timer due in %ld seconds\n",
10644 thread_timer_remain_second(p->t_start));
10645 if (p->t_connect)
10646 vty_out(vty, "Next connect timer due in %ld seconds\n",
10647 thread_timer_remain_second(p->t_connect));
10648 if (p->t_routeadv)
10649 vty_out(vty,
10650 "MRAI (interval %u) timer expires in %ld seconds\n",
10651 p->v_routeadv,
10652 thread_timer_remain_second(p->t_routeadv));
10653 if (p->password)
10654 vty_out(vty, "Peer Authentication Enabled\n");
10655
10656 vty_out(vty, "Read thread: %s Write thread: %s\n",
10657 p->t_read ? "on" : "off",
10658 CHECK_FLAG(p->thread_flags, PEER_THREAD_WRITES_ON)
10659 ? "on"
10660 : "off");
10661 }
10662
10663 if (p->notify.code == BGP_NOTIFY_OPEN_ERR
10664 && p->notify.subcode == BGP_NOTIFY_OPEN_UNSUP_CAPBL)
10665 bgp_capability_vty_out(vty, p, use_json, json_neigh);
10666
10667 if (!use_json)
10668 vty_out(vty, "\n");
10669
10670 /* BFD information. */
10671 bgp_bfd_show_info(vty, p, use_json, json_neigh);
10672
10673 if (use_json) {
10674 if (p->conf_if) /* Configured interface name. */
10675 json_object_object_add(json, p->conf_if, json_neigh);
10676 else /* Configured IP address. */
10677 json_object_object_add(json, p->host, json_neigh);
10678 }
10679 }
10680
10681 static int bgp_show_neighbor(struct vty *vty, struct bgp *bgp,
10682 enum show_type type, union sockunion *su,
10683 const char *conf_if, uint8_t use_json,
10684 json_object *json)
10685 {
10686 struct listnode *node, *nnode;
10687 struct peer *peer;
10688 int find = 0;
10689
10690 for (ALL_LIST_ELEMENTS(bgp->peer, node, nnode, peer)) {
10691 if (!CHECK_FLAG(peer->flags, PEER_FLAG_CONFIG_NODE))
10692 continue;
10693
10694 switch (type) {
10695 case show_all:
10696 bgp_show_peer(vty, peer, use_json, json);
10697 break;
10698 case show_peer:
10699 if (conf_if) {
10700 if ((peer->conf_if
10701 && !strcmp(peer->conf_if, conf_if))
10702 || (peer->hostname
10703 && !strcmp(peer->hostname, conf_if))) {
10704 find = 1;
10705 bgp_show_peer(vty, peer, use_json,
10706 json);
10707 }
10708 } else {
10709 if (sockunion_same(&peer->su, su)) {
10710 find = 1;
10711 bgp_show_peer(vty, peer, use_json,
10712 json);
10713 }
10714 }
10715 break;
10716 }
10717 }
10718
10719 if (type == show_peer && !find) {
10720 if (use_json)
10721 json_object_boolean_true_add(json, "bgpNoSuchNeighbor");
10722 else
10723 vty_out(vty, "%% No such neighbor in this view/vrf\n");
10724 }
10725
10726 if (use_json) {
10727 vty_out(vty, "%s\n", json_object_to_json_string_ext(
10728 json, JSON_C_TO_STRING_PRETTY));
10729 json_object_free(json);
10730 } else {
10731 vty_out(vty, "\n");
10732 }
10733
10734 return CMD_SUCCESS;
10735 }
10736
10737 static void bgp_show_all_instances_neighbors_vty(struct vty *vty,
10738 enum show_type type,
10739 const char *ip_str,
10740 uint8_t use_json)
10741 {
10742 struct listnode *node, *nnode;
10743 struct bgp *bgp;
10744 union sockunion su;
10745 json_object *json = NULL;
10746 int ret, is_first = 1;
10747
10748 if (use_json)
10749 vty_out(vty, "{\n");
10750
10751 for (ALL_LIST_ELEMENTS(bm->bgp, node, nnode, bgp)) {
10752 if (use_json) {
10753 if (!(json = json_object_new_object())) {
10754 zlog_err(
10755 "Unable to allocate memory for JSON object");
10756 vty_out(vty,
10757 "{\"error\": {\"message:\": \"Unable to allocate memory for JSON object\"}}}\n");
10758 return;
10759 }
10760
10761 json_object_int_add(json, "vrfId",
10762 (bgp->vrf_id == VRF_UNKNOWN)
10763 ? -1
10764 : (int64_t)bgp->vrf_id);
10765 json_object_string_add(
10766 json, "vrfName",
10767 (bgp->inst_type == BGP_INSTANCE_TYPE_DEFAULT)
10768 ? "Default"
10769 : bgp->name);
10770
10771 if (!is_first)
10772 vty_out(vty, ",\n");
10773 else
10774 is_first = 0;
10775
10776 vty_out(vty, "\"%s\":",
10777 (bgp->inst_type == BGP_INSTANCE_TYPE_DEFAULT)
10778 ? "Default"
10779 : bgp->name);
10780 } else {
10781 vty_out(vty, "\nInstance %s:\n",
10782 (bgp->inst_type == BGP_INSTANCE_TYPE_DEFAULT)
10783 ? "Default"
10784 : bgp->name);
10785 }
10786
10787 if (type == show_peer) {
10788 ret = str2sockunion(ip_str, &su);
10789 if (ret < 0)
10790 bgp_show_neighbor(vty, bgp, type, NULL, ip_str,
10791 use_json, json);
10792 else
10793 bgp_show_neighbor(vty, bgp, type, &su, NULL,
10794 use_json, json);
10795 } else {
10796 bgp_show_neighbor(vty, bgp, show_all, NULL, NULL,
10797 use_json, json);
10798 }
10799 }
10800
10801 if (use_json)
10802 vty_out(vty, "}\n");
10803 }
10804
10805 static int bgp_show_neighbor_vty(struct vty *vty, const char *name,
10806 enum show_type type, const char *ip_str,
10807 uint8_t use_json)
10808 {
10809 int ret;
10810 struct bgp *bgp;
10811 union sockunion su;
10812 json_object *json = NULL;
10813
10814 if (name) {
10815 if (strmatch(name, "all")) {
10816 bgp_show_all_instances_neighbors_vty(vty, type, ip_str,
10817 use_json);
10818 return CMD_SUCCESS;
10819 } else {
10820 bgp = bgp_lookup_by_name(name);
10821 if (!bgp) {
10822 if (use_json) {
10823 json = json_object_new_object();
10824 json_object_boolean_true_add(
10825 json, "bgpNoSuchInstance");
10826 vty_out(vty, "%s\n",
10827 json_object_to_json_string_ext(
10828 json,
10829 JSON_C_TO_STRING_PRETTY));
10830 json_object_free(json);
10831 } else
10832 vty_out(vty,
10833 "%% No such BGP instance exist\n");
10834
10835 return CMD_WARNING;
10836 }
10837 }
10838 } else {
10839 bgp = bgp_get_default();
10840 }
10841
10842 if (bgp) {
10843 json = json_object_new_object();
10844 if (ip_str) {
10845 ret = str2sockunion(ip_str, &su);
10846 if (ret < 0)
10847 bgp_show_neighbor(vty, bgp, type, NULL, ip_str,
10848 use_json, json);
10849 else
10850 bgp_show_neighbor(vty, bgp, type, &su, NULL,
10851 use_json, json);
10852 } else {
10853 bgp_show_neighbor(vty, bgp, type, NULL, NULL, use_json,
10854 json);
10855 }
10856 json_object_free(json);
10857 }
10858
10859 return CMD_SUCCESS;
10860 }
10861
10862 /* "show [ip] bgp neighbors" commands. */
10863 DEFUN (show_ip_bgp_neighbors,
10864 show_ip_bgp_neighbors_cmd,
10865 "show [ip] bgp [<view|vrf> VIEWVRFNAME] [<ipv4|ipv6>] neighbors [<A.B.C.D|X:X::X:X|WORD>] [json]",
10866 SHOW_STR
10867 IP_STR
10868 BGP_STR
10869 BGP_INSTANCE_HELP_STR
10870 "Address Family\n"
10871 "Address Family\n"
10872 "Detailed information on TCP and BGP neighbor connections\n"
10873 "Neighbor to display information about\n"
10874 "Neighbor to display information about\n"
10875 "Neighbor on BGP configured interface\n"
10876 JSON_STR)
10877 {
10878 char *vrf = NULL;
10879 char *sh_arg = NULL;
10880 enum show_type sh_type;
10881
10882 uint8_t uj = use_json(argc, argv);
10883
10884 int idx = 0;
10885
10886 if (argv_find(argv, argc, "view", &idx)
10887 || argv_find(argv, argc, "vrf", &idx))
10888 vrf = argv[idx + 1]->arg;
10889
10890 idx++;
10891 if (argv_find(argv, argc, "A.B.C.D", &idx)
10892 || argv_find(argv, argc, "X:X::X:X", &idx)
10893 || argv_find(argv, argc, "WORD", &idx)) {
10894 sh_type = show_peer;
10895 sh_arg = argv[idx]->arg;
10896 } else
10897 sh_type = show_all;
10898
10899 return bgp_show_neighbor_vty(vty, vrf, sh_type, sh_arg, uj);
10900 }
10901
10902 /* Show BGP's AS paths internal data. There are both `show [ip] bgp
10903 paths' and `show ip mbgp paths'. Those functions results are the
10904 same.*/
10905 DEFUN (show_ip_bgp_paths,
10906 show_ip_bgp_paths_cmd,
10907 "show [ip] bgp ["BGP_SAFI_CMD_STR"] paths",
10908 SHOW_STR
10909 IP_STR
10910 BGP_STR
10911 BGP_SAFI_HELP_STR
10912 "Path information\n")
10913 {
10914 vty_out(vty, "Address Refcnt Path\n");
10915 aspath_print_all_vty(vty);
10916 return CMD_SUCCESS;
10917 }
10918
10919 #include "hash.h"
10920
10921 static void community_show_all_iterator(struct hash_backet *backet,
10922 struct vty *vty)
10923 {
10924 struct community *com;
10925
10926 com = (struct community *)backet->data;
10927 vty_out(vty, "[%p] (%ld) %s\n", (void *)com, com->refcnt,
10928 community_str(com, false));
10929 }
10930
10931 /* Show BGP's community internal data. */
10932 DEFUN (show_ip_bgp_community_info,
10933 show_ip_bgp_community_info_cmd,
10934 "show [ip] bgp community-info",
10935 SHOW_STR
10936 IP_STR
10937 BGP_STR
10938 "List all bgp community information\n")
10939 {
10940 vty_out(vty, "Address Refcnt Community\n");
10941
10942 hash_iterate(community_hash(),
10943 (void (*)(struct hash_backet *,
10944 void *))community_show_all_iterator,
10945 vty);
10946
10947 return CMD_SUCCESS;
10948 }
10949
10950 static void lcommunity_show_all_iterator(struct hash_backet *backet,
10951 struct vty *vty)
10952 {
10953 struct lcommunity *lcom;
10954
10955 lcom = (struct lcommunity *)backet->data;
10956 vty_out(vty, "[%p] (%ld) %s\n", (void *)lcom, lcom->refcnt,
10957 lcommunity_str(lcom, false));
10958 }
10959
10960 /* Show BGP's community internal data. */
10961 DEFUN (show_ip_bgp_lcommunity_info,
10962 show_ip_bgp_lcommunity_info_cmd,
10963 "show ip bgp large-community-info",
10964 SHOW_STR
10965 IP_STR
10966 BGP_STR
10967 "List all bgp large-community information\n")
10968 {
10969 vty_out(vty, "Address Refcnt Large-community\n");
10970
10971 hash_iterate(lcommunity_hash(),
10972 (void (*)(struct hash_backet *,
10973 void *))lcommunity_show_all_iterator,
10974 vty);
10975
10976 return CMD_SUCCESS;
10977 }
10978
10979
10980 DEFUN (show_ip_bgp_attr_info,
10981 show_ip_bgp_attr_info_cmd,
10982 "show [ip] bgp attribute-info",
10983 SHOW_STR
10984 IP_STR
10985 BGP_STR
10986 "List all bgp attribute information\n")
10987 {
10988 attr_show_all(vty);
10989 return CMD_SUCCESS;
10990 }
10991
10992 static int bgp_show_route_leak_vty(struct vty *vty, const char *name,
10993 afi_t afi, safi_t safi)
10994 {
10995 struct bgp *bgp;
10996 struct listnode *node;
10997 char *vname;
10998 char buf1[INET6_ADDRSTRLEN];
10999 char *ecom_str;
11000 vpn_policy_direction_t dir;
11001
11002 if (name) {
11003 bgp = bgp_lookup_by_name(name);
11004 if (!bgp) {
11005 vty_out(vty, "%% No such BGP instance exist\n");
11006 return CMD_WARNING;
11007 }
11008 } else {
11009 bgp = bgp_get_default();
11010 if (!bgp) {
11011 vty_out(vty,
11012 "%% Default BGP instance does not exist\n");
11013 return CMD_WARNING;
11014 }
11015 }
11016
11017 if (!CHECK_FLAG(bgp->af_flags[afi][safi],
11018 BGP_CONFIG_VRF_TO_VRF_IMPORT)) {
11019 vty_out(vty,
11020 "This VRF is not importing %s routes from any other VRF\n",
11021 afi_safi_print(afi, safi));
11022 } else {
11023 vty_out(vty,
11024 "This VRF is importing %s routes from the following VRFs:\n",
11025 afi_safi_print(afi, safi));
11026 for (ALL_LIST_ELEMENTS_RO(bgp->vpn_policy[afi].import_vrf, node,
11027 vname)) {
11028 vty_out(vty, " %s\n", vname);
11029 }
11030 dir = BGP_VPN_POLICY_DIR_FROMVPN;
11031 ecom_str = ecommunity_ecom2str(
11032 bgp->vpn_policy[afi].rtlist[dir],
11033 ECOMMUNITY_FORMAT_ROUTE_MAP, 0);
11034 vty_out(vty, "Import RT(s): %s\n", ecom_str);
11035 XFREE(MTYPE_ECOMMUNITY_STR, ecom_str);
11036 }
11037
11038 if (!CHECK_FLAG(bgp->af_flags[afi][safi],
11039 BGP_CONFIG_VRF_TO_VRF_EXPORT)) {
11040 vty_out(vty,
11041 "This VRF is not exporting %s routes to any other VRF\n",
11042 afi_safi_print(afi, safi));
11043 } else {
11044 vty_out(vty,
11045 "This VRF is exporting %s routes to the following VRFs:\n",
11046 afi_safi_print(afi, safi));
11047 for (ALL_LIST_ELEMENTS_RO(bgp->vpn_policy[afi].export_vrf, node,
11048 vname)) {
11049 vty_out(vty, " %s\n", vname);
11050 }
11051 vty_out(vty, "RD: %s\n",
11052 prefix_rd2str(&bgp->vpn_policy[afi].tovpn_rd,
11053 buf1, RD_ADDRSTRLEN));
11054 dir = BGP_VPN_POLICY_DIR_TOVPN;
11055 ecom_str = ecommunity_ecom2str(
11056 bgp->vpn_policy[afi].rtlist[dir],
11057 ECOMMUNITY_FORMAT_ROUTE_MAP, 0);
11058 vty_out(vty, "Emport RT: %s\n", ecom_str);
11059 XFREE(MTYPE_ECOMMUNITY_STR, ecom_str);
11060 }
11061
11062 return CMD_SUCCESS;
11063 }
11064
11065 /* "show [ip] bgp route-leak" command. */
11066 DEFUN (show_ip_bgp_route_leak,
11067 show_ip_bgp_route_leak_cmd,
11068 "show [ip] bgp [<view|vrf> VIEWVRFNAME] ["BGP_AFI_CMD_STR" ["BGP_SAFI_CMD_STR"]] route-leak",
11069 SHOW_STR
11070 IP_STR
11071 BGP_STR
11072 BGP_INSTANCE_HELP_STR
11073 BGP_AFI_HELP_STR
11074 BGP_SAFI_HELP_STR
11075 "Route leaking information\n")
11076 {
11077 char *vrf = NULL;
11078 afi_t afi = AFI_MAX;
11079 safi_t safi = SAFI_MAX;
11080
11081 int idx = 0;
11082
11083 /* show [ip] bgp */
11084 if (argv_find(argv, argc, "ip", &idx)) {
11085 afi = AFI_IP;
11086 safi = SAFI_UNICAST;
11087 }
11088 /* [vrf VIEWVRFNAME] */
11089 if (argv_find(argv, argc, "view", &idx)) {
11090 vty_out(vty,
11091 "%% This command is not applicable to BGP views\n");
11092 return CMD_WARNING;
11093 }
11094
11095 if (argv_find(argv, argc, "vrf", &idx))
11096 vrf = argv[++idx]->arg;
11097 /* ["BGP_AFI_CMD_STR" ["BGP_SAFI_CMD_STR"]] */
11098 if (argv_find_and_parse_afi(argv, argc, &idx, &afi)) {
11099 argv_find_and_parse_safi(argv, argc, &idx, &safi);
11100 }
11101
11102 if (!((afi == AFI_IP || afi == AFI_IP6) && safi == SAFI_UNICAST)) {
11103 vty_out(vty,
11104 "%% This command is applicable only for unicast ipv4|ipv6\n");
11105 return CMD_WARNING;
11106 }
11107
11108 return bgp_show_route_leak_vty(vty, vrf, afi, safi);
11109 }
11110
11111 static void bgp_show_all_instances_updgrps_vty(struct vty *vty, afi_t afi,
11112 safi_t safi)
11113 {
11114 struct listnode *node, *nnode;
11115 struct bgp *bgp;
11116
11117 for (ALL_LIST_ELEMENTS(bm->bgp, node, nnode, bgp)) {
11118 vty_out(vty, "\nInstance %s:\n",
11119 (bgp->inst_type == BGP_INSTANCE_TYPE_DEFAULT)
11120 ? "Default"
11121 : bgp->name);
11122 update_group_show(bgp, afi, safi, vty, 0);
11123 }
11124 }
11125
11126 static int bgp_show_update_groups(struct vty *vty, const char *name, int afi,
11127 int safi, uint64_t subgrp_id)
11128 {
11129 struct bgp *bgp;
11130
11131 if (name) {
11132 if (strmatch(name, "all")) {
11133 bgp_show_all_instances_updgrps_vty(vty, afi, safi);
11134 return CMD_SUCCESS;
11135 } else {
11136 bgp = bgp_lookup_by_name(name);
11137 }
11138 } else {
11139 bgp = bgp_get_default();
11140 }
11141
11142 if (bgp)
11143 update_group_show(bgp, afi, safi, vty, subgrp_id);
11144 return CMD_SUCCESS;
11145 }
11146
11147 DEFUN (show_ip_bgp_updgrps,
11148 show_ip_bgp_updgrps_cmd,
11149 "show [ip] bgp [<view|vrf> VIEWVRFNAME] ["BGP_AFI_CMD_STR" ["BGP_SAFI_WITH_LABEL_CMD_STR"]] update-groups [SUBGROUP-ID]",
11150 SHOW_STR
11151 IP_STR
11152 BGP_STR
11153 BGP_INSTANCE_HELP_STR
11154 BGP_AFI_HELP_STR
11155 BGP_SAFI_WITH_LABEL_HELP_STR
11156 "Detailed info about dynamic update groups\n"
11157 "Specific subgroup to display detailed info for\n")
11158 {
11159 char *vrf = NULL;
11160 afi_t afi = AFI_IP6;
11161 safi_t safi = SAFI_UNICAST;
11162 uint64_t subgrp_id = 0;
11163
11164 int idx = 0;
11165
11166 /* show [ip] bgp */
11167 if (argv_find(argv, argc, "ip", &idx))
11168 afi = AFI_IP;
11169 /* [<view|vrf> VIEWVRFNAME] */
11170 if (argv_find(argv, argc, "view", &idx)
11171 || argv_find(argv, argc, "vrf", &idx))
11172 vrf = argv[++idx]->arg;
11173 /* ["BGP_AFI_CMD_STR" ["BGP_SAFI_CMD_STR"]] */
11174 if (argv_find_and_parse_afi(argv, argc, &idx, &afi)) {
11175 argv_find_and_parse_safi(argv, argc, &idx, &safi);
11176 }
11177
11178 /* get subgroup id, if provided */
11179 idx = argc - 1;
11180 if (argv[idx]->type == VARIABLE_TKN)
11181 subgrp_id = strtoull(argv[idx]->arg, NULL, 10);
11182
11183 return (bgp_show_update_groups(vty, vrf, afi, safi, subgrp_id));
11184 }
11185
11186 DEFUN (show_bgp_instance_all_ipv6_updgrps,
11187 show_bgp_instance_all_ipv6_updgrps_cmd,
11188 "show [ip] bgp <view|vrf> all update-groups",
11189 SHOW_STR
11190 IP_STR
11191 BGP_STR
11192 BGP_INSTANCE_ALL_HELP_STR
11193 "Detailed info about dynamic update groups\n")
11194 {
11195 bgp_show_all_instances_updgrps_vty(vty, AFI_IP6, SAFI_UNICAST);
11196 return CMD_SUCCESS;
11197 }
11198
11199 DEFUN (show_bgp_updgrps_stats,
11200 show_bgp_updgrps_stats_cmd,
11201 "show [ip] bgp update-groups statistics",
11202 SHOW_STR
11203 IP_STR
11204 BGP_STR
11205 "Detailed info about dynamic update groups\n"
11206 "Statistics\n")
11207 {
11208 struct bgp *bgp;
11209
11210 bgp = bgp_get_default();
11211 if (bgp)
11212 update_group_show_stats(bgp, vty);
11213
11214 return CMD_SUCCESS;
11215 }
11216
11217 DEFUN (show_bgp_instance_updgrps_stats,
11218 show_bgp_instance_updgrps_stats_cmd,
11219 "show [ip] bgp <view|vrf> VIEWVRFNAME update-groups statistics",
11220 SHOW_STR
11221 IP_STR
11222 BGP_STR
11223 BGP_INSTANCE_HELP_STR
11224 "Detailed info about dynamic update groups\n"
11225 "Statistics\n")
11226 {
11227 int idx_word = 3;
11228 struct bgp *bgp;
11229
11230 bgp = bgp_lookup_by_name(argv[idx_word]->arg);
11231 if (bgp)
11232 update_group_show_stats(bgp, vty);
11233
11234 return CMD_SUCCESS;
11235 }
11236
11237 static void show_bgp_updgrps_adj_info_aux(struct vty *vty, const char *name,
11238 afi_t afi, safi_t safi,
11239 const char *what, uint64_t subgrp_id)
11240 {
11241 struct bgp *bgp;
11242
11243 if (name)
11244 bgp = bgp_lookup_by_name(name);
11245 else
11246 bgp = bgp_get_default();
11247
11248 if (bgp) {
11249 if (!strcmp(what, "advertise-queue"))
11250 update_group_show_adj_queue(bgp, afi, safi, vty,
11251 subgrp_id);
11252 else if (!strcmp(what, "advertised-routes"))
11253 update_group_show_advertised(bgp, afi, safi, vty,
11254 subgrp_id);
11255 else if (!strcmp(what, "packet-queue"))
11256 update_group_show_packet_queue(bgp, afi, safi, vty,
11257 subgrp_id);
11258 }
11259 }
11260
11261 DEFPY(show_ip_bgp_instance_updgrps_adj_s,
11262 show_ip_bgp_instance_updgrps_adj_s_cmd,
11263 "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",
11264 SHOW_STR IP_STR BGP_STR BGP_INSTANCE_HELP_STR BGP_AFI_HELP_STR
11265 BGP_SAFI_HELP_STR
11266 "Detailed info about dynamic update groups\n"
11267 "Specific subgroup to display info for\n"
11268 "Advertisement queue\n"
11269 "Announced routes\n"
11270 "Packet queue\n")
11271 {
11272 uint64_t subgrp_id = 0;
11273 afi_t afiz;
11274 safi_t safiz;
11275 if (sgid)
11276 subgrp_id = strtoull(sgid, NULL, 10);
11277
11278 if (!ip && !afi)
11279 afiz = AFI_IP6;
11280 if (!ip && afi)
11281 afiz = bgp_vty_afi_from_str(afi);
11282 if (ip && !afi)
11283 afiz = AFI_IP;
11284 if (ip && afi) {
11285 afiz = bgp_vty_afi_from_str(afi);
11286 if (afiz != AFI_IP)
11287 vty_out(vty,
11288 "%% Cannot specify both 'ip' and 'ipv6'\n");
11289 return CMD_WARNING;
11290 }
11291
11292 safiz = safi ? bgp_vty_safi_from_str(safi) : SAFI_UNICAST;
11293
11294 show_bgp_updgrps_adj_info_aux(vty, vrf, afiz, safiz, rtq, subgrp_id);
11295 return CMD_SUCCESS;
11296 }
11297
11298 static int bgp_show_one_peer_group(struct vty *vty, struct peer_group *group)
11299 {
11300 struct listnode *node, *nnode;
11301 struct prefix *range;
11302 struct peer *conf;
11303 struct peer *peer;
11304 char buf[PREFIX2STR_BUFFER];
11305 afi_t afi;
11306 safi_t safi;
11307 const char *peer_status;
11308 const char *af_str;
11309 int lr_count;
11310 int dynamic;
11311 int af_cfgd;
11312
11313 conf = group->conf;
11314
11315 if (conf->as_type == AS_SPECIFIED || conf->as_type == AS_EXTERNAL) {
11316 vty_out(vty, "\nBGP peer-group %s, remote AS %d\n", group->name,
11317 conf->as);
11318 } else if (conf->as_type == AS_INTERNAL) {
11319 vty_out(vty, "\nBGP peer-group %s, remote AS %d\n", group->name,
11320 group->bgp->as);
11321 } else {
11322 vty_out(vty, "\nBGP peer-group %s\n", group->name);
11323 }
11324
11325 if ((group->bgp->as == conf->as) || (conf->as_type == AS_INTERNAL))
11326 vty_out(vty, " Peer-group type is internal\n");
11327 else
11328 vty_out(vty, " Peer-group type is external\n");
11329
11330 /* Display AFs configured. */
11331 vty_out(vty, " Configured address-families:");
11332 FOREACH_AFI_SAFI (afi, safi) {
11333 if (conf->afc[afi][safi]) {
11334 af_cfgd = 1;
11335 vty_out(vty, " %s;", afi_safi_print(afi, safi));
11336 }
11337 }
11338 if (!af_cfgd)
11339 vty_out(vty, " none\n");
11340 else
11341 vty_out(vty, "\n");
11342
11343 /* Display listen ranges (for dynamic neighbors), if any */
11344 for (afi = AFI_IP; afi < AFI_MAX; afi++) {
11345 if (afi == AFI_IP)
11346 af_str = "IPv4";
11347 else if (afi == AFI_IP6)
11348 af_str = "IPv6";
11349 else
11350 af_str = "???";
11351 lr_count = listcount(group->listen_range[afi]);
11352 if (lr_count) {
11353 vty_out(vty, " %d %s listen range(s)\n", lr_count,
11354 af_str);
11355
11356
11357 for (ALL_LIST_ELEMENTS(group->listen_range[afi], node,
11358 nnode, range)) {
11359 prefix2str(range, buf, sizeof(buf));
11360 vty_out(vty, " %s\n", buf);
11361 }
11362 }
11363 }
11364
11365 /* Display group members and their status */
11366 if (listcount(group->peer)) {
11367 vty_out(vty, " Peer-group members:\n");
11368 for (ALL_LIST_ELEMENTS(group->peer, node, nnode, peer)) {
11369 if (CHECK_FLAG(peer->flags, PEER_FLAG_SHUTDOWN))
11370 peer_status = "Idle (Admin)";
11371 else if (CHECK_FLAG(peer->sflags,
11372 PEER_STATUS_PREFIX_OVERFLOW))
11373 peer_status = "Idle (PfxCt)";
11374 else
11375 peer_status = lookup_msg(bgp_status_msg,
11376 peer->status, NULL);
11377
11378 dynamic = peer_dynamic_neighbor(peer);
11379 vty_out(vty, " %s %s %s \n", peer->host,
11380 dynamic ? "(dynamic)" : "", peer_status);
11381 }
11382 }
11383
11384 return CMD_SUCCESS;
11385 }
11386
11387 static int bgp_show_peer_group_vty(struct vty *vty, const char *name,
11388 const char *group_name)
11389 {
11390 struct bgp *bgp;
11391 struct listnode *node, *nnode;
11392 struct peer_group *group;
11393 bool found = false;
11394
11395 bgp = name ? bgp_lookup_by_name(name) : bgp_get_default();
11396
11397 if (!bgp) {
11398 vty_out(vty, "%% No such BGP instance exists\n");
11399 return CMD_WARNING;
11400 }
11401
11402 for (ALL_LIST_ELEMENTS(bgp->group, node, nnode, group)) {
11403 if (group_name) {
11404 if (strmatch(group->name, group_name)) {
11405 bgp_show_one_peer_group(vty, group);
11406 found = true;
11407 break;
11408 }
11409 } else {
11410 bgp_show_one_peer_group(vty, group);
11411 }
11412 }
11413
11414 if (group_name && !found)
11415 vty_out(vty, "%% No such peer-group\n");
11416
11417 return CMD_SUCCESS;
11418 }
11419
11420 DEFUN (show_ip_bgp_peer_groups,
11421 show_ip_bgp_peer_groups_cmd,
11422 "show [ip] bgp [<view|vrf> VIEWVRFNAME] peer-group [PGNAME]",
11423 SHOW_STR
11424 IP_STR
11425 BGP_STR
11426 BGP_INSTANCE_HELP_STR
11427 "Detailed information on BGP peer groups\n"
11428 "Peer group name\n")
11429 {
11430 char *vrf, *pg;
11431 int idx = 0;
11432
11433 vrf = argv_find(argv, argc, "VIEWVRFNAME", &idx) ? argv[idx]->arg
11434 : NULL;
11435 pg = argv_find(argv, argc, "PGNAME", &idx) ? argv[idx]->arg : NULL;
11436
11437 return bgp_show_peer_group_vty(vty, vrf, pg);
11438 }
11439
11440
11441 /* Redistribute VTY commands. */
11442
11443 DEFUN (bgp_redistribute_ipv4,
11444 bgp_redistribute_ipv4_cmd,
11445 "redistribute " FRR_IP_REDIST_STR_BGPD,
11446 "Redistribute information from another routing protocol\n"
11447 FRR_IP_REDIST_HELP_STR_BGPD)
11448 {
11449 VTY_DECLVAR_CONTEXT(bgp, bgp);
11450 int idx_protocol = 1;
11451 int type;
11452
11453 type = proto_redistnum(AFI_IP, argv[idx_protocol]->text);
11454 if (type < 0) {
11455 vty_out(vty, "%% Invalid route type\n");
11456 return CMD_WARNING_CONFIG_FAILED;
11457 }
11458
11459 bgp_redist_add(bgp, AFI_IP, type, 0);
11460 return bgp_redistribute_set(bgp, AFI_IP, type, 0);
11461 }
11462
11463 ALIAS_HIDDEN(
11464 bgp_redistribute_ipv4, bgp_redistribute_ipv4_hidden_cmd,
11465 "redistribute " FRR_IP_REDIST_STR_BGPD,
11466 "Redistribute information from another routing protocol\n" FRR_IP_REDIST_HELP_STR_BGPD)
11467
11468 DEFUN (bgp_redistribute_ipv4_rmap,
11469 bgp_redistribute_ipv4_rmap_cmd,
11470 "redistribute " FRR_IP_REDIST_STR_BGPD " route-map WORD",
11471 "Redistribute information from another routing protocol\n"
11472 FRR_IP_REDIST_HELP_STR_BGPD
11473 "Route map reference\n"
11474 "Pointer to route-map entries\n")
11475 {
11476 VTY_DECLVAR_CONTEXT(bgp, bgp);
11477 int idx_protocol = 1;
11478 int idx_word = 3;
11479 int type;
11480 struct bgp_redist *red;
11481
11482 type = proto_redistnum(AFI_IP, argv[idx_protocol]->text);
11483 if (type < 0) {
11484 vty_out(vty, "%% Invalid route type\n");
11485 return CMD_WARNING_CONFIG_FAILED;
11486 }
11487
11488 red = bgp_redist_add(bgp, AFI_IP, type, 0);
11489 bgp_redistribute_rmap_set(red, argv[idx_word]->arg);
11490 return bgp_redistribute_set(bgp, AFI_IP, type, 0);
11491 }
11492
11493 ALIAS_HIDDEN(
11494 bgp_redistribute_ipv4_rmap, bgp_redistribute_ipv4_rmap_hidden_cmd,
11495 "redistribute " FRR_IP_REDIST_STR_BGPD " route-map WORD",
11496 "Redistribute information from another routing protocol\n" FRR_IP_REDIST_HELP_STR_BGPD
11497 "Route map reference\n"
11498 "Pointer to route-map entries\n")
11499
11500 DEFUN (bgp_redistribute_ipv4_metric,
11501 bgp_redistribute_ipv4_metric_cmd,
11502 "redistribute " FRR_IP_REDIST_STR_BGPD " metric (0-4294967295)",
11503 "Redistribute information from another routing protocol\n"
11504 FRR_IP_REDIST_HELP_STR_BGPD
11505 "Metric for redistributed routes\n"
11506 "Default metric\n")
11507 {
11508 VTY_DECLVAR_CONTEXT(bgp, bgp);
11509 int idx_protocol = 1;
11510 int idx_number = 3;
11511 int type;
11512 uint32_t metric;
11513 struct bgp_redist *red;
11514
11515 type = proto_redistnum(AFI_IP, argv[idx_protocol]->text);
11516 if (type < 0) {
11517 vty_out(vty, "%% Invalid route type\n");
11518 return CMD_WARNING_CONFIG_FAILED;
11519 }
11520 metric = strtoul(argv[idx_number]->arg, NULL, 10);
11521
11522 red = bgp_redist_add(bgp, AFI_IP, type, 0);
11523 bgp_redistribute_metric_set(bgp, red, AFI_IP, type, metric);
11524 return bgp_redistribute_set(bgp, AFI_IP, type, 0);
11525 }
11526
11527 ALIAS_HIDDEN(
11528 bgp_redistribute_ipv4_metric, bgp_redistribute_ipv4_metric_hidden_cmd,
11529 "redistribute " FRR_IP_REDIST_STR_BGPD " metric (0-4294967295)",
11530 "Redistribute information from another routing protocol\n" FRR_IP_REDIST_HELP_STR_BGPD
11531 "Metric for redistributed routes\n"
11532 "Default metric\n")
11533
11534 DEFUN (bgp_redistribute_ipv4_rmap_metric,
11535 bgp_redistribute_ipv4_rmap_metric_cmd,
11536 "redistribute " FRR_IP_REDIST_STR_BGPD " route-map WORD metric (0-4294967295)",
11537 "Redistribute information from another routing protocol\n"
11538 FRR_IP_REDIST_HELP_STR_BGPD
11539 "Route map reference\n"
11540 "Pointer to route-map entries\n"
11541 "Metric for redistributed routes\n"
11542 "Default metric\n")
11543 {
11544 VTY_DECLVAR_CONTEXT(bgp, bgp);
11545 int idx_protocol = 1;
11546 int idx_word = 3;
11547 int idx_number = 5;
11548 int type;
11549 uint32_t metric;
11550 struct bgp_redist *red;
11551
11552 type = proto_redistnum(AFI_IP, argv[idx_protocol]->text);
11553 if (type < 0) {
11554 vty_out(vty, "%% Invalid route type\n");
11555 return CMD_WARNING_CONFIG_FAILED;
11556 }
11557 metric = strtoul(argv[idx_number]->arg, NULL, 10);
11558
11559 red = bgp_redist_add(bgp, AFI_IP, type, 0);
11560 bgp_redistribute_rmap_set(red, argv[idx_word]->arg);
11561 bgp_redistribute_metric_set(bgp, red, AFI_IP, type, metric);
11562 return bgp_redistribute_set(bgp, AFI_IP, type, 0);
11563 }
11564
11565 ALIAS_HIDDEN(
11566 bgp_redistribute_ipv4_rmap_metric,
11567 bgp_redistribute_ipv4_rmap_metric_hidden_cmd,
11568 "redistribute " FRR_IP_REDIST_STR_BGPD
11569 " route-map WORD metric (0-4294967295)",
11570 "Redistribute information from another routing protocol\n" FRR_IP_REDIST_HELP_STR_BGPD
11571 "Route map reference\n"
11572 "Pointer to route-map entries\n"
11573 "Metric for redistributed routes\n"
11574 "Default metric\n")
11575
11576 DEFUN (bgp_redistribute_ipv4_metric_rmap,
11577 bgp_redistribute_ipv4_metric_rmap_cmd,
11578 "redistribute " FRR_IP_REDIST_STR_BGPD " metric (0-4294967295) route-map WORD",
11579 "Redistribute information from another routing protocol\n"
11580 FRR_IP_REDIST_HELP_STR_BGPD
11581 "Metric for redistributed routes\n"
11582 "Default metric\n"
11583 "Route map reference\n"
11584 "Pointer to route-map entries\n")
11585 {
11586 VTY_DECLVAR_CONTEXT(bgp, bgp);
11587 int idx_protocol = 1;
11588 int idx_number = 3;
11589 int idx_word = 5;
11590 int type;
11591 uint32_t metric;
11592 struct bgp_redist *red;
11593
11594 type = proto_redistnum(AFI_IP, argv[idx_protocol]->text);
11595 if (type < 0) {
11596 vty_out(vty, "%% Invalid route type\n");
11597 return CMD_WARNING_CONFIG_FAILED;
11598 }
11599 metric = strtoul(argv[idx_number]->arg, NULL, 10);
11600
11601 red = bgp_redist_add(bgp, AFI_IP, type, 0);
11602 bgp_redistribute_metric_set(bgp, red, AFI_IP, type, metric);
11603 bgp_redistribute_rmap_set(red, argv[idx_word]->arg);
11604 return bgp_redistribute_set(bgp, AFI_IP, type, 0);
11605 }
11606
11607 ALIAS_HIDDEN(
11608 bgp_redistribute_ipv4_metric_rmap,
11609 bgp_redistribute_ipv4_metric_rmap_hidden_cmd,
11610 "redistribute " FRR_IP_REDIST_STR_BGPD
11611 " metric (0-4294967295) route-map WORD",
11612 "Redistribute information from another routing protocol\n" FRR_IP_REDIST_HELP_STR_BGPD
11613 "Metric for redistributed routes\n"
11614 "Default metric\n"
11615 "Route map reference\n"
11616 "Pointer to route-map entries\n")
11617
11618 DEFUN (bgp_redistribute_ipv4_ospf,
11619 bgp_redistribute_ipv4_ospf_cmd,
11620 "redistribute <ospf|table> (1-65535)",
11621 "Redistribute information from another routing protocol\n"
11622 "Open Shortest Path First (OSPFv2)\n"
11623 "Non-main Kernel Routing Table\n"
11624 "Instance ID/Table ID\n")
11625 {
11626 VTY_DECLVAR_CONTEXT(bgp, bgp);
11627 int idx_ospf_table = 1;
11628 int idx_number = 2;
11629 unsigned short instance;
11630 unsigned short protocol;
11631
11632 instance = strtoul(argv[idx_number]->arg, NULL, 10);
11633
11634 if (strncmp(argv[idx_ospf_table]->arg, "o", 1) == 0)
11635 protocol = ZEBRA_ROUTE_OSPF;
11636 else
11637 protocol = ZEBRA_ROUTE_TABLE;
11638
11639 bgp_redist_add(bgp, AFI_IP, protocol, instance);
11640 return bgp_redistribute_set(bgp, AFI_IP, protocol, instance);
11641 }
11642
11643 ALIAS_HIDDEN(bgp_redistribute_ipv4_ospf, bgp_redistribute_ipv4_ospf_hidden_cmd,
11644 "redistribute <ospf|table> (1-65535)",
11645 "Redistribute information from another routing protocol\n"
11646 "Open Shortest Path First (OSPFv2)\n"
11647 "Non-main Kernel Routing Table\n"
11648 "Instance ID/Table ID\n")
11649
11650 DEFUN (bgp_redistribute_ipv4_ospf_rmap,
11651 bgp_redistribute_ipv4_ospf_rmap_cmd,
11652 "redistribute <ospf|table> (1-65535) route-map WORD",
11653 "Redistribute information from another routing protocol\n"
11654 "Open Shortest Path First (OSPFv2)\n"
11655 "Non-main Kernel Routing Table\n"
11656 "Instance ID/Table ID\n"
11657 "Route map reference\n"
11658 "Pointer to route-map entries\n")
11659 {
11660 VTY_DECLVAR_CONTEXT(bgp, bgp);
11661 int idx_ospf_table = 1;
11662 int idx_number = 2;
11663 int idx_word = 4;
11664 struct bgp_redist *red;
11665 unsigned short instance;
11666 int protocol;
11667
11668 if (strncmp(argv[idx_ospf_table]->arg, "o", 1) == 0)
11669 protocol = ZEBRA_ROUTE_OSPF;
11670 else
11671 protocol = ZEBRA_ROUTE_TABLE;
11672
11673 instance = strtoul(argv[idx_number]->arg, NULL, 10);
11674 red = bgp_redist_add(bgp, AFI_IP, protocol, instance);
11675 bgp_redistribute_rmap_set(red, argv[idx_word]->arg);
11676 return bgp_redistribute_set(bgp, AFI_IP, protocol, instance);
11677 }
11678
11679 ALIAS_HIDDEN(bgp_redistribute_ipv4_ospf_rmap,
11680 bgp_redistribute_ipv4_ospf_rmap_hidden_cmd,
11681 "redistribute <ospf|table> (1-65535) route-map WORD",
11682 "Redistribute information from another routing protocol\n"
11683 "Open Shortest Path First (OSPFv2)\n"
11684 "Non-main Kernel Routing Table\n"
11685 "Instance ID/Table ID\n"
11686 "Route map reference\n"
11687 "Pointer to route-map entries\n")
11688
11689 DEFUN (bgp_redistribute_ipv4_ospf_metric,
11690 bgp_redistribute_ipv4_ospf_metric_cmd,
11691 "redistribute <ospf|table> (1-65535) metric (0-4294967295)",
11692 "Redistribute information from another routing protocol\n"
11693 "Open Shortest Path First (OSPFv2)\n"
11694 "Non-main Kernel Routing Table\n"
11695 "Instance ID/Table ID\n"
11696 "Metric for redistributed routes\n"
11697 "Default metric\n")
11698 {
11699 VTY_DECLVAR_CONTEXT(bgp, bgp);
11700 int idx_ospf_table = 1;
11701 int idx_number = 2;
11702 int idx_number_2 = 4;
11703 uint32_t metric;
11704 struct bgp_redist *red;
11705 unsigned short instance;
11706 int protocol;
11707
11708 if (strncmp(argv[idx_ospf_table]->arg, "o", 1) == 0)
11709 protocol = ZEBRA_ROUTE_OSPF;
11710 else
11711 protocol = ZEBRA_ROUTE_TABLE;
11712
11713 instance = strtoul(argv[idx_number]->arg, NULL, 10);
11714 metric = strtoul(argv[idx_number_2]->arg, NULL, 10);
11715
11716 red = bgp_redist_add(bgp, AFI_IP, protocol, instance);
11717 bgp_redistribute_metric_set(bgp, red, AFI_IP, protocol, metric);
11718 return bgp_redistribute_set(bgp, AFI_IP, protocol, instance);
11719 }
11720
11721 ALIAS_HIDDEN(bgp_redistribute_ipv4_ospf_metric,
11722 bgp_redistribute_ipv4_ospf_metric_hidden_cmd,
11723 "redistribute <ospf|table> (1-65535) metric (0-4294967295)",
11724 "Redistribute information from another routing protocol\n"
11725 "Open Shortest Path First (OSPFv2)\n"
11726 "Non-main Kernel Routing Table\n"
11727 "Instance ID/Table ID\n"
11728 "Metric for redistributed routes\n"
11729 "Default metric\n")
11730
11731 DEFUN (bgp_redistribute_ipv4_ospf_rmap_metric,
11732 bgp_redistribute_ipv4_ospf_rmap_metric_cmd,
11733 "redistribute <ospf|table> (1-65535) route-map WORD metric (0-4294967295)",
11734 "Redistribute information from another routing protocol\n"
11735 "Open Shortest Path First (OSPFv2)\n"
11736 "Non-main Kernel Routing Table\n"
11737 "Instance ID/Table ID\n"
11738 "Route map reference\n"
11739 "Pointer to route-map entries\n"
11740 "Metric for redistributed routes\n"
11741 "Default metric\n")
11742 {
11743 VTY_DECLVAR_CONTEXT(bgp, bgp);
11744 int idx_ospf_table = 1;
11745 int idx_number = 2;
11746 int idx_word = 4;
11747 int idx_number_2 = 6;
11748 uint32_t metric;
11749 struct bgp_redist *red;
11750 unsigned short instance;
11751 int protocol;
11752
11753 if (strncmp(argv[idx_ospf_table]->arg, "o", 1) == 0)
11754 protocol = ZEBRA_ROUTE_OSPF;
11755 else
11756 protocol = ZEBRA_ROUTE_TABLE;
11757
11758 instance = strtoul(argv[idx_number]->arg, NULL, 10);
11759 metric = strtoul(argv[idx_number_2]->arg, NULL, 10);
11760
11761 red = bgp_redist_add(bgp, AFI_IP, protocol, instance);
11762 bgp_redistribute_rmap_set(red, argv[idx_word]->arg);
11763 bgp_redistribute_metric_set(bgp, red, AFI_IP, protocol, metric);
11764 return bgp_redistribute_set(bgp, AFI_IP, protocol, instance);
11765 }
11766
11767 ALIAS_HIDDEN(
11768 bgp_redistribute_ipv4_ospf_rmap_metric,
11769 bgp_redistribute_ipv4_ospf_rmap_metric_hidden_cmd,
11770 "redistribute <ospf|table> (1-65535) route-map WORD metric (0-4294967295)",
11771 "Redistribute information from another routing protocol\n"
11772 "Open Shortest Path First (OSPFv2)\n"
11773 "Non-main Kernel Routing Table\n"
11774 "Instance ID/Table ID\n"
11775 "Route map reference\n"
11776 "Pointer to route-map entries\n"
11777 "Metric for redistributed routes\n"
11778 "Default metric\n")
11779
11780 DEFUN (bgp_redistribute_ipv4_ospf_metric_rmap,
11781 bgp_redistribute_ipv4_ospf_metric_rmap_cmd,
11782 "redistribute <ospf|table> (1-65535) metric (0-4294967295) route-map WORD",
11783 "Redistribute information from another routing protocol\n"
11784 "Open Shortest Path First (OSPFv2)\n"
11785 "Non-main Kernel Routing Table\n"
11786 "Instance ID/Table ID\n"
11787 "Metric for redistributed routes\n"
11788 "Default metric\n"
11789 "Route map reference\n"
11790 "Pointer to route-map entries\n")
11791 {
11792 VTY_DECLVAR_CONTEXT(bgp, bgp);
11793 int idx_ospf_table = 1;
11794 int idx_number = 2;
11795 int idx_number_2 = 4;
11796 int idx_word = 6;
11797 uint32_t metric;
11798 struct bgp_redist *red;
11799 unsigned short instance;
11800 int protocol;
11801
11802 if (strncmp(argv[idx_ospf_table]->arg, "o", 1) == 0)
11803 protocol = ZEBRA_ROUTE_OSPF;
11804 else
11805 protocol = ZEBRA_ROUTE_TABLE;
11806
11807 instance = strtoul(argv[idx_number]->arg, NULL, 10);
11808 metric = strtoul(argv[idx_number_2]->arg, NULL, 10);
11809
11810 red = bgp_redist_add(bgp, AFI_IP, protocol, instance);
11811 bgp_redistribute_metric_set(bgp, red, AFI_IP, protocol, metric);
11812 bgp_redistribute_rmap_set(red, argv[idx_word]->arg);
11813 return bgp_redistribute_set(bgp, AFI_IP, protocol, instance);
11814 }
11815
11816 ALIAS_HIDDEN(
11817 bgp_redistribute_ipv4_ospf_metric_rmap,
11818 bgp_redistribute_ipv4_ospf_metric_rmap_hidden_cmd,
11819 "redistribute <ospf|table> (1-65535) metric (0-4294967295) route-map WORD",
11820 "Redistribute information from another routing protocol\n"
11821 "Open Shortest Path First (OSPFv2)\n"
11822 "Non-main Kernel Routing Table\n"
11823 "Instance ID/Table ID\n"
11824 "Metric for redistributed routes\n"
11825 "Default metric\n"
11826 "Route map reference\n"
11827 "Pointer to route-map entries\n")
11828
11829 DEFUN (no_bgp_redistribute_ipv4_ospf,
11830 no_bgp_redistribute_ipv4_ospf_cmd,
11831 "no redistribute <ospf|table> (1-65535) [metric (0-4294967295)] [route-map WORD]",
11832 NO_STR
11833 "Redistribute information from another routing protocol\n"
11834 "Open Shortest Path First (OSPFv2)\n"
11835 "Non-main Kernel Routing Table\n"
11836 "Instance ID/Table ID\n"
11837 "Metric for redistributed routes\n"
11838 "Default metric\n"
11839 "Route map reference\n"
11840 "Pointer to route-map entries\n")
11841 {
11842 VTY_DECLVAR_CONTEXT(bgp, bgp);
11843 int idx_ospf_table = 2;
11844 int idx_number = 3;
11845 unsigned short instance;
11846 int protocol;
11847
11848 if (strncmp(argv[idx_ospf_table]->arg, "o", 1) == 0)
11849 protocol = ZEBRA_ROUTE_OSPF;
11850 else
11851 protocol = ZEBRA_ROUTE_TABLE;
11852
11853 instance = strtoul(argv[idx_number]->arg, NULL, 10);
11854 return bgp_redistribute_unset(bgp, AFI_IP, protocol, instance);
11855 }
11856
11857 ALIAS_HIDDEN(
11858 no_bgp_redistribute_ipv4_ospf, no_bgp_redistribute_ipv4_ospf_hidden_cmd,
11859 "no redistribute <ospf|table> (1-65535) [metric (0-4294967295)] [route-map WORD]",
11860 NO_STR
11861 "Redistribute information from another routing protocol\n"
11862 "Open Shortest Path First (OSPFv2)\n"
11863 "Non-main Kernel Routing Table\n"
11864 "Instance ID/Table ID\n"
11865 "Metric for redistributed routes\n"
11866 "Default metric\n"
11867 "Route map reference\n"
11868 "Pointer to route-map entries\n")
11869
11870 DEFUN (no_bgp_redistribute_ipv4,
11871 no_bgp_redistribute_ipv4_cmd,
11872 "no redistribute " FRR_IP_REDIST_STR_BGPD " [metric (0-4294967295)] [route-map WORD]",
11873 NO_STR
11874 "Redistribute information from another routing protocol\n"
11875 FRR_IP_REDIST_HELP_STR_BGPD
11876 "Metric for redistributed routes\n"
11877 "Default metric\n"
11878 "Route map reference\n"
11879 "Pointer to route-map entries\n")
11880 {
11881 VTY_DECLVAR_CONTEXT(bgp, bgp);
11882 int idx_protocol = 2;
11883 int type;
11884
11885 type = proto_redistnum(AFI_IP, argv[idx_protocol]->text);
11886 if (type < 0) {
11887 vty_out(vty, "%% Invalid route type\n");
11888 return CMD_WARNING_CONFIG_FAILED;
11889 }
11890 return bgp_redistribute_unset(bgp, AFI_IP, type, 0);
11891 }
11892
11893 ALIAS_HIDDEN(
11894 no_bgp_redistribute_ipv4, no_bgp_redistribute_ipv4_hidden_cmd,
11895 "no redistribute " FRR_IP_REDIST_STR_BGPD
11896 " [metric (0-4294967295)] [route-map WORD]",
11897 NO_STR
11898 "Redistribute information from another routing protocol\n" FRR_IP_REDIST_HELP_STR_BGPD
11899 "Metric for redistributed routes\n"
11900 "Default metric\n"
11901 "Route map reference\n"
11902 "Pointer to route-map entries\n")
11903
11904 DEFUN (bgp_redistribute_ipv6,
11905 bgp_redistribute_ipv6_cmd,
11906 "redistribute " FRR_IP6_REDIST_STR_BGPD,
11907 "Redistribute information from another routing protocol\n"
11908 FRR_IP6_REDIST_HELP_STR_BGPD)
11909 {
11910 VTY_DECLVAR_CONTEXT(bgp, bgp);
11911 int idx_protocol = 1;
11912 int type;
11913
11914 type = proto_redistnum(AFI_IP6, argv[idx_protocol]->text);
11915 if (type < 0) {
11916 vty_out(vty, "%% Invalid route type\n");
11917 return CMD_WARNING_CONFIG_FAILED;
11918 }
11919
11920 bgp_redist_add(bgp, AFI_IP6, type, 0);
11921 return bgp_redistribute_set(bgp, AFI_IP6, type, 0);
11922 }
11923
11924 DEFUN (bgp_redistribute_ipv6_rmap,
11925 bgp_redistribute_ipv6_rmap_cmd,
11926 "redistribute " FRR_IP6_REDIST_STR_BGPD " route-map WORD",
11927 "Redistribute information from another routing protocol\n"
11928 FRR_IP6_REDIST_HELP_STR_BGPD
11929 "Route map reference\n"
11930 "Pointer to route-map entries\n")
11931 {
11932 VTY_DECLVAR_CONTEXT(bgp, bgp);
11933 int idx_protocol = 1;
11934 int idx_word = 3;
11935 int type;
11936 struct bgp_redist *red;
11937
11938 type = proto_redistnum(AFI_IP6, argv[idx_protocol]->text);
11939 if (type < 0) {
11940 vty_out(vty, "%% Invalid route type\n");
11941 return CMD_WARNING_CONFIG_FAILED;
11942 }
11943
11944 red = bgp_redist_add(bgp, AFI_IP6, type, 0);
11945 bgp_redistribute_rmap_set(red, argv[idx_word]->arg);
11946 return bgp_redistribute_set(bgp, AFI_IP6, type, 0);
11947 }
11948
11949 DEFUN (bgp_redistribute_ipv6_metric,
11950 bgp_redistribute_ipv6_metric_cmd,
11951 "redistribute " FRR_IP6_REDIST_STR_BGPD " metric (0-4294967295)",
11952 "Redistribute information from another routing protocol\n"
11953 FRR_IP6_REDIST_HELP_STR_BGPD
11954 "Metric for redistributed routes\n"
11955 "Default metric\n")
11956 {
11957 VTY_DECLVAR_CONTEXT(bgp, bgp);
11958 int idx_protocol = 1;
11959 int idx_number = 3;
11960 int type;
11961 uint32_t metric;
11962 struct bgp_redist *red;
11963
11964 type = proto_redistnum(AFI_IP6, argv[idx_protocol]->text);
11965 if (type < 0) {
11966 vty_out(vty, "%% Invalid route type\n");
11967 return CMD_WARNING_CONFIG_FAILED;
11968 }
11969 metric = strtoul(argv[idx_number]->arg, NULL, 10);
11970
11971 red = bgp_redist_add(bgp, AFI_IP6, type, 0);
11972 bgp_redistribute_metric_set(bgp, red, AFI_IP6, type, metric);
11973 return bgp_redistribute_set(bgp, AFI_IP6, type, 0);
11974 }
11975
11976 DEFUN (bgp_redistribute_ipv6_rmap_metric,
11977 bgp_redistribute_ipv6_rmap_metric_cmd,
11978 "redistribute " FRR_IP6_REDIST_STR_BGPD " route-map WORD metric (0-4294967295)",
11979 "Redistribute information from another routing protocol\n"
11980 FRR_IP6_REDIST_HELP_STR_BGPD
11981 "Route map reference\n"
11982 "Pointer to route-map entries\n"
11983 "Metric for redistributed routes\n"
11984 "Default metric\n")
11985 {
11986 VTY_DECLVAR_CONTEXT(bgp, bgp);
11987 int idx_protocol = 1;
11988 int idx_word = 3;
11989 int idx_number = 5;
11990 int type;
11991 uint32_t metric;
11992 struct bgp_redist *red;
11993
11994 type = proto_redistnum(AFI_IP6, argv[idx_protocol]->text);
11995 if (type < 0) {
11996 vty_out(vty, "%% Invalid route type\n");
11997 return CMD_WARNING_CONFIG_FAILED;
11998 }
11999 metric = strtoul(argv[idx_number]->arg, NULL, 10);
12000
12001 red = bgp_redist_add(bgp, AFI_IP6, type, 0);
12002 bgp_redistribute_rmap_set(red, argv[idx_word]->arg);
12003 bgp_redistribute_metric_set(bgp, red, AFI_IP6, type, metric);
12004 return bgp_redistribute_set(bgp, AFI_IP6, type, 0);
12005 }
12006
12007 DEFUN (bgp_redistribute_ipv6_metric_rmap,
12008 bgp_redistribute_ipv6_metric_rmap_cmd,
12009 "redistribute " FRR_IP6_REDIST_STR_BGPD " metric (0-4294967295) route-map WORD",
12010 "Redistribute information from another routing protocol\n"
12011 FRR_IP6_REDIST_HELP_STR_BGPD
12012 "Metric for redistributed routes\n"
12013 "Default metric\n"
12014 "Route map reference\n"
12015 "Pointer to route-map entries\n")
12016 {
12017 VTY_DECLVAR_CONTEXT(bgp, bgp);
12018 int idx_protocol = 1;
12019 int idx_number = 3;
12020 int idx_word = 5;
12021 int type;
12022 uint32_t metric;
12023 struct bgp_redist *red;
12024
12025 type = proto_redistnum(AFI_IP6, argv[idx_protocol]->text);
12026 if (type < 0) {
12027 vty_out(vty, "%% Invalid route type\n");
12028 return CMD_WARNING_CONFIG_FAILED;
12029 }
12030 metric = strtoul(argv[idx_number]->arg, NULL, 10);
12031
12032 red = bgp_redist_add(bgp, AFI_IP6, type, 0);
12033 bgp_redistribute_metric_set(bgp, red, AFI_IP6, SAFI_UNICAST, metric);
12034 bgp_redistribute_rmap_set(red, argv[idx_word]->arg);
12035 return bgp_redistribute_set(bgp, AFI_IP6, type, 0);
12036 }
12037
12038 DEFUN (no_bgp_redistribute_ipv6,
12039 no_bgp_redistribute_ipv6_cmd,
12040 "no redistribute " FRR_IP6_REDIST_STR_BGPD " [metric (0-4294967295)] [route-map WORD]",
12041 NO_STR
12042 "Redistribute information from another routing protocol\n"
12043 FRR_IP6_REDIST_HELP_STR_BGPD
12044 "Metric for redistributed routes\n"
12045 "Default metric\n"
12046 "Route map reference\n"
12047 "Pointer to route-map entries\n")
12048 {
12049 VTY_DECLVAR_CONTEXT(bgp, bgp);
12050 int idx_protocol = 2;
12051 int type;
12052
12053 type = proto_redistnum(AFI_IP6, argv[idx_protocol]->text);
12054 if (type < 0) {
12055 vty_out(vty, "%% Invalid route type\n");
12056 return CMD_WARNING_CONFIG_FAILED;
12057 }
12058
12059 return bgp_redistribute_unset(bgp, AFI_IP6, type, 0);
12060 }
12061
12062 void bgp_config_write_redistribute(struct vty *vty, struct bgp *bgp, afi_t afi,
12063 safi_t safi)
12064 {
12065 int i;
12066
12067 /* Unicast redistribution only. */
12068 if (safi != SAFI_UNICAST)
12069 return;
12070
12071 for (i = 0; i < ZEBRA_ROUTE_MAX; i++) {
12072 /* Redistribute BGP does not make sense. */
12073 if (i != ZEBRA_ROUTE_BGP) {
12074 struct list *red_list;
12075 struct listnode *node;
12076 struct bgp_redist *red;
12077
12078 red_list = bgp->redist[afi][i];
12079 if (!red_list)
12080 continue;
12081
12082 for (ALL_LIST_ELEMENTS_RO(red_list, node, red)) {
12083 /* "redistribute" configuration. */
12084 vty_out(vty, " redistribute %s",
12085 zebra_route_string(i));
12086 if (red->instance)
12087 vty_out(vty, " %d", red->instance);
12088 if (red->redist_metric_flag)
12089 vty_out(vty, " metric %u",
12090 red->redist_metric);
12091 if (red->rmap.name)
12092 vty_out(vty, " route-map %s",
12093 red->rmap.name);
12094 vty_out(vty, "\n");
12095 }
12096 }
12097 }
12098 }
12099
12100 /* This is part of the address-family block (unicast only) */
12101 void bgp_vpn_policy_config_write_afi(struct vty *vty, struct bgp *bgp,
12102 afi_t afi)
12103 {
12104 int indent = 2;
12105
12106 if (bgp->vpn_policy[afi].rmap_name[BGP_VPN_POLICY_DIR_FROMVPN])
12107 vty_out(vty, "%*simport vrf route-map %s\n", indent, "",
12108 bgp->vpn_policy[afi]
12109 .rmap_name[BGP_VPN_POLICY_DIR_FROMVPN]);
12110
12111 if (CHECK_FLAG(bgp->af_flags[afi][SAFI_UNICAST],
12112 BGP_CONFIG_VRF_TO_VRF_IMPORT)
12113 || CHECK_FLAG(bgp->af_flags[afi][SAFI_UNICAST],
12114 BGP_CONFIG_VRF_TO_VRF_EXPORT))
12115 return;
12116
12117 if (CHECK_FLAG(bgp->vpn_policy[afi].flags,
12118 BGP_VPN_POLICY_TOVPN_LABEL_AUTO)) {
12119
12120 vty_out(vty, "%*slabel vpn export %s\n", indent, "", "auto");
12121
12122 } else {
12123 if (bgp->vpn_policy[afi].tovpn_label != MPLS_LABEL_NONE) {
12124 vty_out(vty, "%*slabel vpn export %u\n", indent, "",
12125 bgp->vpn_policy[afi].tovpn_label);
12126 }
12127 }
12128 if (CHECK_FLAG(bgp->vpn_policy[afi].flags,
12129 BGP_VPN_POLICY_TOVPN_RD_SET)) {
12130 char buf[RD_ADDRSTRLEN];
12131 vty_out(vty, "%*srd vpn export %s\n", indent, "",
12132 prefix_rd2str(&bgp->vpn_policy[afi].tovpn_rd, buf,
12133 sizeof(buf)));
12134 }
12135 if (CHECK_FLAG(bgp->vpn_policy[afi].flags,
12136 BGP_VPN_POLICY_TOVPN_NEXTHOP_SET)) {
12137
12138 char buf[PREFIX_STRLEN];
12139 if (inet_ntop(bgp->vpn_policy[afi].tovpn_nexthop.family,
12140 &bgp->vpn_policy[afi].tovpn_nexthop.u.prefix, buf,
12141 sizeof(buf))) {
12142
12143 vty_out(vty, "%*snexthop vpn export %s\n",
12144 indent, "", buf);
12145 }
12146 }
12147 if (bgp->vpn_policy[afi].rtlist[BGP_VPN_POLICY_DIR_FROMVPN]
12148 && bgp->vpn_policy[afi].rtlist[BGP_VPN_POLICY_DIR_TOVPN]
12149 && ecommunity_cmp(
12150 bgp->vpn_policy[afi].rtlist[BGP_VPN_POLICY_DIR_FROMVPN],
12151 bgp->vpn_policy[afi].rtlist[BGP_VPN_POLICY_DIR_TOVPN])) {
12152
12153 char *b = ecommunity_ecom2str(
12154 bgp->vpn_policy[afi].rtlist[BGP_VPN_POLICY_DIR_TOVPN],
12155 ECOMMUNITY_FORMAT_ROUTE_MAP, ECOMMUNITY_ROUTE_TARGET);
12156 vty_out(vty, "%*srt vpn both %s\n", indent, "", b);
12157 XFREE(MTYPE_ECOMMUNITY_STR, b);
12158 } else {
12159 if (bgp->vpn_policy[afi].rtlist[BGP_VPN_POLICY_DIR_FROMVPN]) {
12160 char *b = ecommunity_ecom2str(
12161 bgp->vpn_policy[afi]
12162 .rtlist[BGP_VPN_POLICY_DIR_FROMVPN],
12163 ECOMMUNITY_FORMAT_ROUTE_MAP,
12164 ECOMMUNITY_ROUTE_TARGET);
12165 vty_out(vty, "%*srt vpn import %s\n", indent, "", b);
12166 XFREE(MTYPE_ECOMMUNITY_STR, b);
12167 }
12168 if (bgp->vpn_policy[afi].rtlist[BGP_VPN_POLICY_DIR_TOVPN]) {
12169 char *b = ecommunity_ecom2str(
12170 bgp->vpn_policy[afi]
12171 .rtlist[BGP_VPN_POLICY_DIR_TOVPN],
12172 ECOMMUNITY_FORMAT_ROUTE_MAP,
12173 ECOMMUNITY_ROUTE_TARGET);
12174 vty_out(vty, "%*srt vpn export %s\n", indent, "", b);
12175 XFREE(MTYPE_ECOMMUNITY_STR, b);
12176 }
12177 }
12178
12179 if (bgp->vpn_policy[afi].rmap_name[BGP_VPN_POLICY_DIR_TOVPN])
12180 vty_out(vty, "%*sroute-map vpn export %s\n", indent, "",
12181 bgp->vpn_policy[afi]
12182 .rmap_name[BGP_VPN_POLICY_DIR_TOVPN]);
12183
12184 if (bgp->vpn_policy[afi].import_redirect_rtlist) {
12185 char *b = ecommunity_ecom2str(
12186 bgp->vpn_policy[afi]
12187 .import_redirect_rtlist,
12188 ECOMMUNITY_FORMAT_ROUTE_MAP,
12189 ECOMMUNITY_ROUTE_TARGET);
12190
12191 vty_out(vty, "%*srt redirect import %s\n", indent, "", b);
12192 XFREE(MTYPE_ECOMMUNITY_STR, b);
12193 }
12194 }
12195
12196
12197 /* BGP node structure. */
12198 static struct cmd_node bgp_node = {
12199 BGP_NODE, "%s(config-router)# ", 1,
12200 };
12201
12202 static struct cmd_node bgp_ipv4_unicast_node = {
12203 BGP_IPV4_NODE, "%s(config-router-af)# ", 1,
12204 };
12205
12206 static struct cmd_node bgp_ipv4_multicast_node = {
12207 BGP_IPV4M_NODE, "%s(config-router-af)# ", 1,
12208 };
12209
12210 static struct cmd_node bgp_ipv4_labeled_unicast_node = {
12211 BGP_IPV4L_NODE, "%s(config-router-af)# ", 1,
12212 };
12213
12214 static struct cmd_node bgp_ipv6_unicast_node = {
12215 BGP_IPV6_NODE, "%s(config-router-af)# ", 1,
12216 };
12217
12218 static struct cmd_node bgp_ipv6_multicast_node = {
12219 BGP_IPV6M_NODE, "%s(config-router-af)# ", 1,
12220 };
12221
12222 static struct cmd_node bgp_ipv6_labeled_unicast_node = {
12223 BGP_IPV6L_NODE, "%s(config-router-af)# ", 1,
12224 };
12225
12226 static struct cmd_node bgp_vpnv4_node = {BGP_VPNV4_NODE,
12227 "%s(config-router-af)# ", 1};
12228
12229 static struct cmd_node bgp_vpnv6_node = {BGP_VPNV6_NODE,
12230 "%s(config-router-af-vpnv6)# ", 1};
12231
12232 static struct cmd_node bgp_evpn_node = {BGP_EVPN_NODE,
12233 "%s(config-router-evpn)# ", 1};
12234
12235 static struct cmd_node bgp_evpn_vni_node = {BGP_EVPN_VNI_NODE,
12236 "%s(config-router-af-vni)# ", 1};
12237
12238 static struct cmd_node bgp_flowspecv4_node = {BGP_FLOWSPECV4_NODE,
12239 "%s(config-router-af)# ", 1};
12240
12241 static struct cmd_node bgp_flowspecv6_node = {BGP_FLOWSPECV6_NODE,
12242 "%s(config-router-af-vpnv6)# ", 1};
12243
12244 static void community_list_vty(void);
12245
12246 static void bgp_ac_neighbor(vector comps, struct cmd_token *token)
12247 {
12248 struct bgp *bgp;
12249 struct peer *peer;
12250 struct listnode *lnbgp, *lnpeer;
12251
12252 for (ALL_LIST_ELEMENTS_RO(bm->bgp, lnbgp, bgp)) {
12253 for (ALL_LIST_ELEMENTS_RO(bgp->peer, lnpeer, peer)) {
12254 /* only provide suggestions on the appropriate input
12255 * token type,
12256 * they'll otherwise show up multiple times */
12257 enum cmd_token_type match_type;
12258 char *name = peer->host;
12259
12260 if (peer->conf_if) {
12261 match_type = VARIABLE_TKN;
12262 name = peer->conf_if;
12263 } else if (strchr(peer->host, ':'))
12264 match_type = IPV6_TKN;
12265 else
12266 match_type = IPV4_TKN;
12267
12268 if (token->type != match_type)
12269 continue;
12270
12271 vector_set(comps, XSTRDUP(MTYPE_COMPLETION, name));
12272 }
12273 }
12274 }
12275
12276 static const struct cmd_variable_handler bgp_var_neighbor[] = {
12277 {.varname = "neighbor", .completions = bgp_ac_neighbor},
12278 {.varname = "neighbors", .completions = bgp_ac_neighbor},
12279 {.varname = "peer", .completions = bgp_ac_neighbor},
12280 {.completions = NULL}};
12281
12282 static void bgp_ac_peergroup(vector comps, struct cmd_token *token)
12283 {
12284 struct bgp *bgp;
12285 struct peer_group *group;
12286 struct listnode *lnbgp, *lnpeer;
12287
12288 for (ALL_LIST_ELEMENTS_RO(bm->bgp, lnbgp, bgp)) {
12289 for (ALL_LIST_ELEMENTS_RO(bgp->group, lnpeer, group))
12290 vector_set(comps, XSTRDUP(MTYPE_COMPLETION,
12291 group->name));
12292 }
12293 }
12294
12295 static const struct cmd_variable_handler bgp_var_peergroup[] = {
12296 {.tokenname = "PGNAME", .completions = bgp_ac_peergroup},
12297 {.completions = NULL} };
12298
12299 void bgp_vty_init(void)
12300 {
12301 cmd_variable_handler_register(bgp_var_neighbor);
12302 cmd_variable_handler_register(bgp_var_peergroup);
12303
12304 /* Install bgp top node. */
12305 install_node(&bgp_node, bgp_config_write);
12306 install_node(&bgp_ipv4_unicast_node, NULL);
12307 install_node(&bgp_ipv4_multicast_node, NULL);
12308 install_node(&bgp_ipv4_labeled_unicast_node, NULL);
12309 install_node(&bgp_ipv6_unicast_node, NULL);
12310 install_node(&bgp_ipv6_multicast_node, NULL);
12311 install_node(&bgp_ipv6_labeled_unicast_node, NULL);
12312 install_node(&bgp_vpnv4_node, NULL);
12313 install_node(&bgp_vpnv6_node, NULL);
12314 install_node(&bgp_evpn_node, NULL);
12315 install_node(&bgp_evpn_vni_node, NULL);
12316 install_node(&bgp_flowspecv4_node, NULL);
12317 install_node(&bgp_flowspecv6_node, NULL);
12318
12319 /* Install default VTY commands to new nodes. */
12320 install_default(BGP_NODE);
12321 install_default(BGP_IPV4_NODE);
12322 install_default(BGP_IPV4M_NODE);
12323 install_default(BGP_IPV4L_NODE);
12324 install_default(BGP_IPV6_NODE);
12325 install_default(BGP_IPV6M_NODE);
12326 install_default(BGP_IPV6L_NODE);
12327 install_default(BGP_VPNV4_NODE);
12328 install_default(BGP_VPNV6_NODE);
12329 install_default(BGP_FLOWSPECV4_NODE);
12330 install_default(BGP_FLOWSPECV6_NODE);
12331 install_default(BGP_EVPN_NODE);
12332 install_default(BGP_EVPN_VNI_NODE);
12333
12334 /* "bgp multiple-instance" commands. */
12335 install_element(CONFIG_NODE, &bgp_multiple_instance_cmd);
12336 install_element(CONFIG_NODE, &no_bgp_multiple_instance_cmd);
12337
12338 /* "bgp config-type" commands. */
12339 install_element(CONFIG_NODE, &bgp_config_type_cmd);
12340 install_element(CONFIG_NODE, &no_bgp_config_type_cmd);
12341
12342 /* bgp route-map delay-timer commands. */
12343 install_element(CONFIG_NODE, &bgp_set_route_map_delay_timer_cmd);
12344 install_element(CONFIG_NODE, &no_bgp_set_route_map_delay_timer_cmd);
12345
12346 /* Dummy commands (Currently not supported) */
12347 install_element(BGP_NODE, &no_synchronization_cmd);
12348 install_element(BGP_NODE, &no_auto_summary_cmd);
12349
12350 /* "router bgp" commands. */
12351 install_element(CONFIG_NODE, &router_bgp_cmd);
12352
12353 /* "no router bgp" commands. */
12354 install_element(CONFIG_NODE, &no_router_bgp_cmd);
12355
12356 /* "bgp router-id" commands. */
12357 install_element(BGP_NODE, &bgp_router_id_cmd);
12358 install_element(BGP_NODE, &no_bgp_router_id_cmd);
12359
12360 /* "bgp cluster-id" commands. */
12361 install_element(BGP_NODE, &bgp_cluster_id_cmd);
12362 install_element(BGP_NODE, &no_bgp_cluster_id_cmd);
12363
12364 /* "bgp confederation" commands. */
12365 install_element(BGP_NODE, &bgp_confederation_identifier_cmd);
12366 install_element(BGP_NODE, &no_bgp_confederation_identifier_cmd);
12367
12368 /* "bgp confederation peers" commands. */
12369 install_element(BGP_NODE, &bgp_confederation_peers_cmd);
12370 install_element(BGP_NODE, &no_bgp_confederation_peers_cmd);
12371
12372 /* bgp max-med command */
12373 install_element(BGP_NODE, &bgp_maxmed_admin_cmd);
12374 install_element(BGP_NODE, &no_bgp_maxmed_admin_cmd);
12375 install_element(BGP_NODE, &bgp_maxmed_admin_medv_cmd);
12376 install_element(BGP_NODE, &bgp_maxmed_onstartup_cmd);
12377 install_element(BGP_NODE, &no_bgp_maxmed_onstartup_cmd);
12378
12379 /* bgp disable-ebgp-connected-nh-check */
12380 install_element(BGP_NODE, &bgp_disable_connected_route_check_cmd);
12381 install_element(BGP_NODE, &no_bgp_disable_connected_route_check_cmd);
12382
12383 /* bgp update-delay command */
12384 install_element(BGP_NODE, &bgp_update_delay_cmd);
12385 install_element(BGP_NODE, &no_bgp_update_delay_cmd);
12386 install_element(BGP_NODE, &bgp_update_delay_establish_wait_cmd);
12387
12388 install_element(BGP_NODE, &bgp_wpkt_quanta_cmd);
12389 install_element(BGP_NODE, &no_bgp_wpkt_quanta_cmd);
12390 install_element(BGP_NODE, &bgp_rpkt_quanta_cmd);
12391 install_element(BGP_NODE, &no_bgp_rpkt_quanta_cmd);
12392
12393 install_element(BGP_NODE, &bgp_coalesce_time_cmd);
12394 install_element(BGP_NODE, &no_bgp_coalesce_time_cmd);
12395
12396 /* "maximum-paths" commands. */
12397 install_element(BGP_NODE, &bgp_maxpaths_hidden_cmd);
12398 install_element(BGP_NODE, &no_bgp_maxpaths_hidden_cmd);
12399 install_element(BGP_IPV4_NODE, &bgp_maxpaths_cmd);
12400 install_element(BGP_IPV4_NODE, &no_bgp_maxpaths_cmd);
12401 install_element(BGP_IPV6_NODE, &bgp_maxpaths_cmd);
12402 install_element(BGP_IPV6_NODE, &no_bgp_maxpaths_cmd);
12403 install_element(BGP_NODE, &bgp_maxpaths_ibgp_hidden_cmd);
12404 install_element(BGP_NODE, &bgp_maxpaths_ibgp_cluster_hidden_cmd);
12405 install_element(BGP_NODE, &no_bgp_maxpaths_ibgp_hidden_cmd);
12406 install_element(BGP_IPV4_NODE, &bgp_maxpaths_ibgp_cmd);
12407 install_element(BGP_IPV4_NODE, &bgp_maxpaths_ibgp_cluster_cmd);
12408 install_element(BGP_IPV4_NODE, &no_bgp_maxpaths_ibgp_cmd);
12409 install_element(BGP_IPV6_NODE, &bgp_maxpaths_ibgp_cmd);
12410 install_element(BGP_IPV6_NODE, &bgp_maxpaths_ibgp_cluster_cmd);
12411 install_element(BGP_IPV6_NODE, &no_bgp_maxpaths_ibgp_cmd);
12412
12413 install_element(BGP_IPV6L_NODE, &bgp_maxpaths_cmd);
12414 install_element(BGP_IPV6L_NODE, &no_bgp_maxpaths_cmd);
12415 install_element(BGP_IPV6L_NODE, &bgp_maxpaths_ibgp_cmd);
12416 install_element(BGP_IPV6L_NODE, &bgp_maxpaths_ibgp_cluster_cmd);
12417 install_element(BGP_IPV6L_NODE, &no_bgp_maxpaths_ibgp_cmd);
12418
12419 /* "timers bgp" commands. */
12420 install_element(BGP_NODE, &bgp_timers_cmd);
12421 install_element(BGP_NODE, &no_bgp_timers_cmd);
12422
12423 /* route-map delay-timer commands - per instance for backwards compat.
12424 */
12425 install_element(BGP_NODE, &bgp_set_route_map_delay_timer_cmd);
12426 install_element(BGP_NODE, &no_bgp_set_route_map_delay_timer_cmd);
12427
12428 /* "bgp client-to-client reflection" commands */
12429 install_element(BGP_NODE, &no_bgp_client_to_client_reflection_cmd);
12430 install_element(BGP_NODE, &bgp_client_to_client_reflection_cmd);
12431
12432 /* "bgp always-compare-med" commands */
12433 install_element(BGP_NODE, &bgp_always_compare_med_cmd);
12434 install_element(BGP_NODE, &no_bgp_always_compare_med_cmd);
12435
12436 /* "bgp deterministic-med" commands */
12437 install_element(BGP_NODE, &bgp_deterministic_med_cmd);
12438 install_element(BGP_NODE, &no_bgp_deterministic_med_cmd);
12439
12440 /* "bgp graceful-restart" commands */
12441 install_element(BGP_NODE, &bgp_graceful_restart_cmd);
12442 install_element(BGP_NODE, &no_bgp_graceful_restart_cmd);
12443 install_element(BGP_NODE, &bgp_graceful_restart_stalepath_time_cmd);
12444 install_element(BGP_NODE, &no_bgp_graceful_restart_stalepath_time_cmd);
12445 install_element(BGP_NODE, &bgp_graceful_restart_restart_time_cmd);
12446 install_element(BGP_NODE, &no_bgp_graceful_restart_restart_time_cmd);
12447
12448 install_element(BGP_NODE, &bgp_graceful_restart_preserve_fw_cmd);
12449 install_element(BGP_NODE, &no_bgp_graceful_restart_preserve_fw_cmd);
12450
12451 /* "bgp graceful-shutdown" commands */
12452 install_element(BGP_NODE, &bgp_graceful_shutdown_cmd);
12453 install_element(BGP_NODE, &no_bgp_graceful_shutdown_cmd);
12454
12455 /* "bgp fast-external-failover" commands */
12456 install_element(BGP_NODE, &bgp_fast_external_failover_cmd);
12457 install_element(BGP_NODE, &no_bgp_fast_external_failover_cmd);
12458
12459 /* "bgp enforce-first-as" commands */
12460 install_element(BGP_NODE, &bgp_enforce_first_as_cmd);
12461
12462 /* "bgp bestpath compare-routerid" commands */
12463 install_element(BGP_NODE, &bgp_bestpath_compare_router_id_cmd);
12464 install_element(BGP_NODE, &no_bgp_bestpath_compare_router_id_cmd);
12465
12466 /* "bgp bestpath as-path ignore" commands */
12467 install_element(BGP_NODE, &bgp_bestpath_aspath_ignore_cmd);
12468 install_element(BGP_NODE, &no_bgp_bestpath_aspath_ignore_cmd);
12469
12470 /* "bgp bestpath as-path confed" commands */
12471 install_element(BGP_NODE, &bgp_bestpath_aspath_confed_cmd);
12472 install_element(BGP_NODE, &no_bgp_bestpath_aspath_confed_cmd);
12473
12474 /* "bgp bestpath as-path multipath-relax" commands */
12475 install_element(BGP_NODE, &bgp_bestpath_aspath_multipath_relax_cmd);
12476 install_element(BGP_NODE, &no_bgp_bestpath_aspath_multipath_relax_cmd);
12477
12478 /* "bgp log-neighbor-changes" commands */
12479 install_element(BGP_NODE, &bgp_log_neighbor_changes_cmd);
12480 install_element(BGP_NODE, &no_bgp_log_neighbor_changes_cmd);
12481
12482 /* "bgp bestpath med" commands */
12483 install_element(BGP_NODE, &bgp_bestpath_med_cmd);
12484 install_element(BGP_NODE, &no_bgp_bestpath_med_cmd);
12485
12486 /* "no bgp default ipv4-unicast" commands. */
12487 install_element(BGP_NODE, &no_bgp_default_ipv4_unicast_cmd);
12488 install_element(BGP_NODE, &bgp_default_ipv4_unicast_cmd);
12489
12490 /* "bgp network import-check" commands. */
12491 install_element(BGP_NODE, &bgp_network_import_check_cmd);
12492 install_element(BGP_NODE, &bgp_network_import_check_exact_cmd);
12493 install_element(BGP_NODE, &no_bgp_network_import_check_cmd);
12494
12495 /* "bgp default local-preference" commands. */
12496 install_element(BGP_NODE, &bgp_default_local_preference_cmd);
12497 install_element(BGP_NODE, &no_bgp_default_local_preference_cmd);
12498
12499 /* bgp default show-hostname */
12500 install_element(BGP_NODE, &bgp_default_show_hostname_cmd);
12501 install_element(BGP_NODE, &no_bgp_default_show_hostname_cmd);
12502
12503 /* "bgp default subgroup-pkt-queue-max" commands. */
12504 install_element(BGP_NODE, &bgp_default_subgroup_pkt_queue_max_cmd);
12505 install_element(BGP_NODE, &no_bgp_default_subgroup_pkt_queue_max_cmd);
12506
12507 /* bgp ibgp-allow-policy-mods command */
12508 install_element(BGP_NODE, &bgp_rr_allow_outbound_policy_cmd);
12509 install_element(BGP_NODE, &no_bgp_rr_allow_outbound_policy_cmd);
12510
12511 /* "bgp listen limit" commands. */
12512 install_element(BGP_NODE, &bgp_listen_limit_cmd);
12513 install_element(BGP_NODE, &no_bgp_listen_limit_cmd);
12514
12515 /* "bgp listen range" commands. */
12516 install_element(BGP_NODE, &bgp_listen_range_cmd);
12517 install_element(BGP_NODE, &no_bgp_listen_range_cmd);
12518
12519 /* "bgp default shutdown" command */
12520 install_element(BGP_NODE, &bgp_default_shutdown_cmd);
12521
12522 /* "neighbor remote-as" commands. */
12523 install_element(BGP_NODE, &neighbor_remote_as_cmd);
12524 install_element(BGP_NODE, &neighbor_interface_config_cmd);
12525 install_element(BGP_NODE, &neighbor_interface_config_v6only_cmd);
12526 install_element(BGP_NODE, &neighbor_interface_config_remote_as_cmd);
12527 install_element(BGP_NODE,
12528 &neighbor_interface_v6only_config_remote_as_cmd);
12529 install_element(BGP_NODE, &no_neighbor_cmd);
12530 install_element(BGP_NODE, &no_neighbor_interface_config_cmd);
12531
12532 /* "neighbor peer-group" commands. */
12533 install_element(BGP_NODE, &neighbor_peer_group_cmd);
12534 install_element(BGP_NODE, &no_neighbor_peer_group_cmd);
12535 install_element(BGP_NODE,
12536 &no_neighbor_interface_peer_group_remote_as_cmd);
12537
12538 /* "neighbor local-as" commands. */
12539 install_element(BGP_NODE, &neighbor_local_as_cmd);
12540 install_element(BGP_NODE, &neighbor_local_as_no_prepend_cmd);
12541 install_element(BGP_NODE, &neighbor_local_as_no_prepend_replace_as_cmd);
12542 install_element(BGP_NODE, &no_neighbor_local_as_cmd);
12543
12544 /* "neighbor solo" commands. */
12545 install_element(BGP_NODE, &neighbor_solo_cmd);
12546 install_element(BGP_NODE, &no_neighbor_solo_cmd);
12547
12548 /* "neighbor password" commands. */
12549 install_element(BGP_NODE, &neighbor_password_cmd);
12550 install_element(BGP_NODE, &no_neighbor_password_cmd);
12551
12552 /* "neighbor activate" commands. */
12553 install_element(BGP_NODE, &neighbor_activate_hidden_cmd);
12554 install_element(BGP_IPV4_NODE, &neighbor_activate_cmd);
12555 install_element(BGP_IPV4M_NODE, &neighbor_activate_cmd);
12556 install_element(BGP_IPV4L_NODE, &neighbor_activate_cmd);
12557 install_element(BGP_IPV6_NODE, &neighbor_activate_cmd);
12558 install_element(BGP_IPV6M_NODE, &neighbor_activate_cmd);
12559 install_element(BGP_IPV6L_NODE, &neighbor_activate_cmd);
12560 install_element(BGP_VPNV4_NODE, &neighbor_activate_cmd);
12561 install_element(BGP_VPNV6_NODE, &neighbor_activate_cmd);
12562 install_element(BGP_FLOWSPECV4_NODE, &neighbor_activate_cmd);
12563 install_element(BGP_FLOWSPECV6_NODE, &neighbor_activate_cmd);
12564 install_element(BGP_EVPN_NODE, &neighbor_activate_cmd);
12565
12566 /* "no neighbor activate" commands. */
12567 install_element(BGP_NODE, &no_neighbor_activate_hidden_cmd);
12568 install_element(BGP_IPV4_NODE, &no_neighbor_activate_cmd);
12569 install_element(BGP_IPV4M_NODE, &no_neighbor_activate_cmd);
12570 install_element(BGP_IPV4L_NODE, &no_neighbor_activate_cmd);
12571 install_element(BGP_IPV6_NODE, &no_neighbor_activate_cmd);
12572 install_element(BGP_IPV6M_NODE, &no_neighbor_activate_cmd);
12573 install_element(BGP_IPV6L_NODE, &no_neighbor_activate_cmd);
12574 install_element(BGP_VPNV4_NODE, &no_neighbor_activate_cmd);
12575 install_element(BGP_VPNV6_NODE, &no_neighbor_activate_cmd);
12576 install_element(BGP_FLOWSPECV4_NODE, &no_neighbor_activate_cmd);
12577 install_element(BGP_FLOWSPECV6_NODE, &no_neighbor_activate_cmd);
12578 install_element(BGP_EVPN_NODE, &no_neighbor_activate_cmd);
12579
12580 /* "neighbor peer-group" set commands. */
12581 install_element(BGP_NODE, &neighbor_set_peer_group_cmd);
12582 install_element(BGP_IPV4_NODE, &neighbor_set_peer_group_hidden_cmd);
12583 install_element(BGP_IPV4M_NODE, &neighbor_set_peer_group_hidden_cmd);
12584 install_element(BGP_IPV6_NODE, &neighbor_set_peer_group_hidden_cmd);
12585 install_element(BGP_IPV6M_NODE, &neighbor_set_peer_group_hidden_cmd);
12586 install_element(BGP_IPV6L_NODE, &neighbor_set_peer_group_hidden_cmd);
12587 install_element(BGP_VPNV4_NODE, &neighbor_set_peer_group_hidden_cmd);
12588 install_element(BGP_VPNV6_NODE, &neighbor_set_peer_group_hidden_cmd);
12589 install_element(BGP_FLOWSPECV4_NODE,
12590 &neighbor_set_peer_group_hidden_cmd);
12591 install_element(BGP_FLOWSPECV6_NODE,
12592 &neighbor_set_peer_group_hidden_cmd);
12593
12594 /* "no neighbor peer-group unset" commands. */
12595 install_element(BGP_NODE, &no_neighbor_set_peer_group_cmd);
12596 install_element(BGP_IPV4_NODE, &no_neighbor_set_peer_group_hidden_cmd);
12597 install_element(BGP_IPV4M_NODE, &no_neighbor_set_peer_group_hidden_cmd);
12598 install_element(BGP_IPV6_NODE, &no_neighbor_set_peer_group_hidden_cmd);
12599 install_element(BGP_IPV6M_NODE, &no_neighbor_set_peer_group_hidden_cmd);
12600 install_element(BGP_IPV6L_NODE, &no_neighbor_set_peer_group_hidden_cmd);
12601 install_element(BGP_VPNV4_NODE, &no_neighbor_set_peer_group_hidden_cmd);
12602 install_element(BGP_VPNV6_NODE, &no_neighbor_set_peer_group_hidden_cmd);
12603 install_element(BGP_FLOWSPECV4_NODE,
12604 &no_neighbor_set_peer_group_hidden_cmd);
12605 install_element(BGP_FLOWSPECV6_NODE,
12606 &no_neighbor_set_peer_group_hidden_cmd);
12607
12608 /* "neighbor softreconfiguration inbound" commands.*/
12609 install_element(BGP_NODE, &neighbor_soft_reconfiguration_hidden_cmd);
12610 install_element(BGP_NODE, &no_neighbor_soft_reconfiguration_hidden_cmd);
12611 install_element(BGP_IPV4_NODE, &neighbor_soft_reconfiguration_cmd);
12612 install_element(BGP_IPV4_NODE, &no_neighbor_soft_reconfiguration_cmd);
12613 install_element(BGP_IPV4L_NODE, &neighbor_soft_reconfiguration_cmd);
12614 install_element(BGP_IPV4L_NODE, &no_neighbor_soft_reconfiguration_cmd);
12615 install_element(BGP_IPV4M_NODE, &neighbor_soft_reconfiguration_cmd);
12616 install_element(BGP_IPV4M_NODE, &no_neighbor_soft_reconfiguration_cmd);
12617 install_element(BGP_IPV6_NODE, &neighbor_soft_reconfiguration_cmd);
12618 install_element(BGP_IPV6_NODE, &no_neighbor_soft_reconfiguration_cmd);
12619 install_element(BGP_IPV6M_NODE, &neighbor_soft_reconfiguration_cmd);
12620 install_element(BGP_IPV6M_NODE, &no_neighbor_soft_reconfiguration_cmd);
12621 install_element(BGP_IPV6L_NODE, &neighbor_soft_reconfiguration_cmd);
12622 install_element(BGP_IPV6L_NODE, &no_neighbor_soft_reconfiguration_cmd);
12623 install_element(BGP_VPNV4_NODE, &neighbor_soft_reconfiguration_cmd);
12624 install_element(BGP_VPNV4_NODE, &no_neighbor_soft_reconfiguration_cmd);
12625 install_element(BGP_VPNV6_NODE, &neighbor_soft_reconfiguration_cmd);
12626 install_element(BGP_VPNV6_NODE, &no_neighbor_soft_reconfiguration_cmd);
12627 install_element(BGP_FLOWSPECV4_NODE,
12628 &neighbor_soft_reconfiguration_cmd);
12629 install_element(BGP_FLOWSPECV4_NODE,
12630 &no_neighbor_soft_reconfiguration_cmd);
12631 install_element(BGP_FLOWSPECV6_NODE,
12632 &neighbor_soft_reconfiguration_cmd);
12633 install_element(BGP_FLOWSPECV6_NODE,
12634 &no_neighbor_soft_reconfiguration_cmd);
12635
12636 /* "neighbor attribute-unchanged" commands. */
12637 install_element(BGP_NODE, &neighbor_attr_unchanged_hidden_cmd);
12638 install_element(BGP_NODE, &no_neighbor_attr_unchanged_hidden_cmd);
12639 install_element(BGP_IPV4_NODE, &neighbor_attr_unchanged_cmd);
12640 install_element(BGP_IPV4_NODE, &no_neighbor_attr_unchanged_cmd);
12641 install_element(BGP_IPV4M_NODE, &neighbor_attr_unchanged_cmd);
12642 install_element(BGP_IPV4M_NODE, &no_neighbor_attr_unchanged_cmd);
12643 install_element(BGP_IPV4L_NODE, &neighbor_attr_unchanged_cmd);
12644 install_element(BGP_IPV4L_NODE, &no_neighbor_attr_unchanged_cmd);
12645 install_element(BGP_IPV6_NODE, &neighbor_attr_unchanged_cmd);
12646 install_element(BGP_IPV6_NODE, &no_neighbor_attr_unchanged_cmd);
12647 install_element(BGP_IPV6M_NODE, &neighbor_attr_unchanged_cmd);
12648 install_element(BGP_IPV6M_NODE, &no_neighbor_attr_unchanged_cmd);
12649 install_element(BGP_IPV6L_NODE, &neighbor_attr_unchanged_cmd);
12650 install_element(BGP_IPV6L_NODE, &no_neighbor_attr_unchanged_cmd);
12651 install_element(BGP_VPNV4_NODE, &neighbor_attr_unchanged_cmd);
12652 install_element(BGP_VPNV4_NODE, &no_neighbor_attr_unchanged_cmd);
12653 install_element(BGP_VPNV6_NODE, &neighbor_attr_unchanged_cmd);
12654 install_element(BGP_VPNV6_NODE, &no_neighbor_attr_unchanged_cmd);
12655
12656 install_element(BGP_EVPN_NODE, &neighbor_attr_unchanged_cmd);
12657 install_element(BGP_EVPN_NODE, &no_neighbor_attr_unchanged_cmd);
12658
12659 /* "nexthop-local unchanged" commands */
12660 install_element(BGP_IPV6_NODE, &neighbor_nexthop_local_unchanged_cmd);
12661 install_element(BGP_IPV6_NODE,
12662 &no_neighbor_nexthop_local_unchanged_cmd);
12663
12664 /* "neighbor next-hop-self" commands. */
12665 install_element(BGP_NODE, &neighbor_nexthop_self_hidden_cmd);
12666 install_element(BGP_NODE, &no_neighbor_nexthop_self_hidden_cmd);
12667 install_element(BGP_IPV4_NODE, &neighbor_nexthop_self_cmd);
12668 install_element(BGP_IPV4_NODE, &no_neighbor_nexthop_self_cmd);
12669 install_element(BGP_IPV4M_NODE, &neighbor_nexthop_self_cmd);
12670 install_element(BGP_IPV4M_NODE, &no_neighbor_nexthop_self_cmd);
12671 install_element(BGP_IPV4L_NODE, &neighbor_nexthop_self_cmd);
12672 install_element(BGP_IPV4L_NODE, &no_neighbor_nexthop_self_cmd);
12673 install_element(BGP_IPV6_NODE, &neighbor_nexthop_self_cmd);
12674 install_element(BGP_IPV6_NODE, &no_neighbor_nexthop_self_cmd);
12675 install_element(BGP_IPV6M_NODE, &neighbor_nexthop_self_cmd);
12676 install_element(BGP_IPV6M_NODE, &no_neighbor_nexthop_self_cmd);
12677 install_element(BGP_IPV6L_NODE, &neighbor_nexthop_self_cmd);
12678 install_element(BGP_IPV6L_NODE, &no_neighbor_nexthop_self_cmd);
12679 install_element(BGP_VPNV4_NODE, &neighbor_nexthop_self_cmd);
12680 install_element(BGP_VPNV4_NODE, &no_neighbor_nexthop_self_cmd);
12681 install_element(BGP_VPNV6_NODE, &neighbor_nexthop_self_cmd);
12682 install_element(BGP_VPNV6_NODE, &no_neighbor_nexthop_self_cmd);
12683 install_element(BGP_EVPN_NODE, &neighbor_nexthop_self_cmd);
12684 install_element(BGP_EVPN_NODE, &no_neighbor_nexthop_self_cmd);
12685
12686 /* "neighbor next-hop-self force" commands. */
12687 install_element(BGP_NODE, &neighbor_nexthop_self_force_hidden_cmd);
12688 install_element(BGP_NODE, &no_neighbor_nexthop_self_force_hidden_cmd);
12689 install_element(BGP_IPV4_NODE, &neighbor_nexthop_self_force_cmd);
12690 install_element(BGP_IPV4_NODE, &no_neighbor_nexthop_self_force_cmd);
12691 install_element(BGP_IPV4M_NODE, &neighbor_nexthop_self_force_cmd);
12692 install_element(BGP_IPV4M_NODE, &no_neighbor_nexthop_self_force_cmd);
12693 install_element(BGP_IPV4L_NODE, &neighbor_nexthop_self_force_cmd);
12694 install_element(BGP_IPV4L_NODE, &no_neighbor_nexthop_self_force_cmd);
12695 install_element(BGP_IPV6_NODE, &neighbor_nexthop_self_force_cmd);
12696 install_element(BGP_IPV6_NODE, &no_neighbor_nexthop_self_force_cmd);
12697 install_element(BGP_IPV6M_NODE, &neighbor_nexthop_self_force_cmd);
12698 install_element(BGP_IPV6M_NODE, &no_neighbor_nexthop_self_force_cmd);
12699 install_element(BGP_IPV6L_NODE, &neighbor_nexthop_self_force_cmd);
12700 install_element(BGP_IPV6L_NODE, &no_neighbor_nexthop_self_force_cmd);
12701 install_element(BGP_VPNV4_NODE, &neighbor_nexthop_self_force_cmd);
12702 install_element(BGP_VPNV4_NODE, &no_neighbor_nexthop_self_force_cmd);
12703 install_element(BGP_VPNV6_NODE, &neighbor_nexthop_self_force_cmd);
12704 install_element(BGP_VPNV6_NODE, &no_neighbor_nexthop_self_force_cmd);
12705
12706 /* "neighbor as-override" commands. */
12707 install_element(BGP_NODE, &neighbor_as_override_hidden_cmd);
12708 install_element(BGP_NODE, &no_neighbor_as_override_hidden_cmd);
12709 install_element(BGP_IPV4_NODE, &neighbor_as_override_cmd);
12710 install_element(BGP_IPV4_NODE, &no_neighbor_as_override_cmd);
12711 install_element(BGP_IPV4M_NODE, &neighbor_as_override_cmd);
12712 install_element(BGP_IPV4M_NODE, &no_neighbor_as_override_cmd);
12713 install_element(BGP_IPV4L_NODE, &neighbor_as_override_cmd);
12714 install_element(BGP_IPV4L_NODE, &no_neighbor_as_override_cmd);
12715 install_element(BGP_IPV6_NODE, &neighbor_as_override_cmd);
12716 install_element(BGP_IPV6_NODE, &no_neighbor_as_override_cmd);
12717 install_element(BGP_IPV6M_NODE, &neighbor_as_override_cmd);
12718 install_element(BGP_IPV6M_NODE, &no_neighbor_as_override_cmd);
12719 install_element(BGP_IPV6L_NODE, &neighbor_as_override_cmd);
12720 install_element(BGP_IPV6L_NODE, &no_neighbor_as_override_cmd);
12721 install_element(BGP_VPNV4_NODE, &neighbor_as_override_cmd);
12722 install_element(BGP_VPNV4_NODE, &no_neighbor_as_override_cmd);
12723 install_element(BGP_VPNV6_NODE, &neighbor_as_override_cmd);
12724 install_element(BGP_VPNV6_NODE, &no_neighbor_as_override_cmd);
12725
12726 /* "neighbor remove-private-AS" commands. */
12727 install_element(BGP_NODE, &neighbor_remove_private_as_hidden_cmd);
12728 install_element(BGP_NODE, &no_neighbor_remove_private_as_hidden_cmd);
12729 install_element(BGP_NODE, &neighbor_remove_private_as_all_hidden_cmd);
12730 install_element(BGP_NODE,
12731 &no_neighbor_remove_private_as_all_hidden_cmd);
12732 install_element(BGP_NODE,
12733 &neighbor_remove_private_as_replace_as_hidden_cmd);
12734 install_element(BGP_NODE,
12735 &no_neighbor_remove_private_as_replace_as_hidden_cmd);
12736 install_element(BGP_NODE,
12737 &neighbor_remove_private_as_all_replace_as_hidden_cmd);
12738 install_element(
12739 BGP_NODE,
12740 &no_neighbor_remove_private_as_all_replace_as_hidden_cmd);
12741 install_element(BGP_IPV4_NODE, &neighbor_remove_private_as_cmd);
12742 install_element(BGP_IPV4_NODE, &no_neighbor_remove_private_as_cmd);
12743 install_element(BGP_IPV4_NODE, &neighbor_remove_private_as_all_cmd);
12744 install_element(BGP_IPV4_NODE, &no_neighbor_remove_private_as_all_cmd);
12745 install_element(BGP_IPV4_NODE,
12746 &neighbor_remove_private_as_replace_as_cmd);
12747 install_element(BGP_IPV4_NODE,
12748 &no_neighbor_remove_private_as_replace_as_cmd);
12749 install_element(BGP_IPV4_NODE,
12750 &neighbor_remove_private_as_all_replace_as_cmd);
12751 install_element(BGP_IPV4_NODE,
12752 &no_neighbor_remove_private_as_all_replace_as_cmd);
12753 install_element(BGP_IPV4M_NODE, &neighbor_remove_private_as_cmd);
12754 install_element(BGP_IPV4M_NODE, &no_neighbor_remove_private_as_cmd);
12755 install_element(BGP_IPV4M_NODE, &neighbor_remove_private_as_all_cmd);
12756 install_element(BGP_IPV4M_NODE, &no_neighbor_remove_private_as_all_cmd);
12757 install_element(BGP_IPV4M_NODE,
12758 &neighbor_remove_private_as_replace_as_cmd);
12759 install_element(BGP_IPV4M_NODE,
12760 &no_neighbor_remove_private_as_replace_as_cmd);
12761 install_element(BGP_IPV4M_NODE,
12762 &neighbor_remove_private_as_all_replace_as_cmd);
12763 install_element(BGP_IPV4M_NODE,
12764 &no_neighbor_remove_private_as_all_replace_as_cmd);
12765 install_element(BGP_IPV4L_NODE, &neighbor_remove_private_as_cmd);
12766 install_element(BGP_IPV4L_NODE, &no_neighbor_remove_private_as_cmd);
12767 install_element(BGP_IPV4L_NODE, &neighbor_remove_private_as_all_cmd);
12768 install_element(BGP_IPV4L_NODE, &no_neighbor_remove_private_as_all_cmd);
12769 install_element(BGP_IPV4L_NODE,
12770 &neighbor_remove_private_as_replace_as_cmd);
12771 install_element(BGP_IPV4L_NODE,
12772 &no_neighbor_remove_private_as_replace_as_cmd);
12773 install_element(BGP_IPV4L_NODE,
12774 &neighbor_remove_private_as_all_replace_as_cmd);
12775 install_element(BGP_IPV4L_NODE,
12776 &no_neighbor_remove_private_as_all_replace_as_cmd);
12777 install_element(BGP_IPV6_NODE, &neighbor_remove_private_as_cmd);
12778 install_element(BGP_IPV6_NODE, &no_neighbor_remove_private_as_cmd);
12779 install_element(BGP_IPV6_NODE, &neighbor_remove_private_as_all_cmd);
12780 install_element(BGP_IPV6_NODE, &no_neighbor_remove_private_as_all_cmd);
12781 install_element(BGP_IPV6_NODE,
12782 &neighbor_remove_private_as_replace_as_cmd);
12783 install_element(BGP_IPV6_NODE,
12784 &no_neighbor_remove_private_as_replace_as_cmd);
12785 install_element(BGP_IPV6_NODE,
12786 &neighbor_remove_private_as_all_replace_as_cmd);
12787 install_element(BGP_IPV6_NODE,
12788 &no_neighbor_remove_private_as_all_replace_as_cmd);
12789 install_element(BGP_IPV6M_NODE, &neighbor_remove_private_as_cmd);
12790 install_element(BGP_IPV6M_NODE, &no_neighbor_remove_private_as_cmd);
12791 install_element(BGP_IPV6M_NODE, &neighbor_remove_private_as_all_cmd);
12792 install_element(BGP_IPV6M_NODE, &no_neighbor_remove_private_as_all_cmd);
12793 install_element(BGP_IPV6M_NODE,
12794 &neighbor_remove_private_as_replace_as_cmd);
12795 install_element(BGP_IPV6M_NODE,
12796 &no_neighbor_remove_private_as_replace_as_cmd);
12797 install_element(BGP_IPV6M_NODE,
12798 &neighbor_remove_private_as_all_replace_as_cmd);
12799 install_element(BGP_IPV6M_NODE,
12800 &no_neighbor_remove_private_as_all_replace_as_cmd);
12801 install_element(BGP_IPV6L_NODE, &neighbor_remove_private_as_cmd);
12802 install_element(BGP_IPV6L_NODE, &no_neighbor_remove_private_as_cmd);
12803 install_element(BGP_IPV6L_NODE, &neighbor_remove_private_as_all_cmd);
12804 install_element(BGP_IPV6L_NODE, &no_neighbor_remove_private_as_all_cmd);
12805 install_element(BGP_IPV6L_NODE,
12806 &neighbor_remove_private_as_replace_as_cmd);
12807 install_element(BGP_IPV6L_NODE,
12808 &no_neighbor_remove_private_as_replace_as_cmd);
12809 install_element(BGP_IPV6L_NODE,
12810 &neighbor_remove_private_as_all_replace_as_cmd);
12811 install_element(BGP_IPV6L_NODE,
12812 &no_neighbor_remove_private_as_all_replace_as_cmd);
12813 install_element(BGP_VPNV4_NODE, &neighbor_remove_private_as_cmd);
12814 install_element(BGP_VPNV4_NODE, &no_neighbor_remove_private_as_cmd);
12815 install_element(BGP_VPNV4_NODE, &neighbor_remove_private_as_all_cmd);
12816 install_element(BGP_VPNV4_NODE, &no_neighbor_remove_private_as_all_cmd);
12817 install_element(BGP_VPNV4_NODE,
12818 &neighbor_remove_private_as_replace_as_cmd);
12819 install_element(BGP_VPNV4_NODE,
12820 &no_neighbor_remove_private_as_replace_as_cmd);
12821 install_element(BGP_VPNV4_NODE,
12822 &neighbor_remove_private_as_all_replace_as_cmd);
12823 install_element(BGP_VPNV4_NODE,
12824 &no_neighbor_remove_private_as_all_replace_as_cmd);
12825 install_element(BGP_VPNV6_NODE, &neighbor_remove_private_as_cmd);
12826 install_element(BGP_VPNV6_NODE, &no_neighbor_remove_private_as_cmd);
12827 install_element(BGP_VPNV6_NODE, &neighbor_remove_private_as_all_cmd);
12828 install_element(BGP_VPNV6_NODE, &no_neighbor_remove_private_as_all_cmd);
12829 install_element(BGP_VPNV6_NODE,
12830 &neighbor_remove_private_as_replace_as_cmd);
12831 install_element(BGP_VPNV6_NODE,
12832 &no_neighbor_remove_private_as_replace_as_cmd);
12833 install_element(BGP_VPNV6_NODE,
12834 &neighbor_remove_private_as_all_replace_as_cmd);
12835 install_element(BGP_VPNV6_NODE,
12836 &no_neighbor_remove_private_as_all_replace_as_cmd);
12837
12838 /* "neighbor send-community" commands.*/
12839 install_element(BGP_NODE, &neighbor_send_community_hidden_cmd);
12840 install_element(BGP_NODE, &neighbor_send_community_type_hidden_cmd);
12841 install_element(BGP_NODE, &no_neighbor_send_community_hidden_cmd);
12842 install_element(BGP_NODE, &no_neighbor_send_community_type_hidden_cmd);
12843 install_element(BGP_IPV4_NODE, &neighbor_send_community_cmd);
12844 install_element(BGP_IPV4_NODE, &neighbor_send_community_type_cmd);
12845 install_element(BGP_IPV4_NODE, &no_neighbor_send_community_cmd);
12846 install_element(BGP_IPV4_NODE, &no_neighbor_send_community_type_cmd);
12847 install_element(BGP_IPV4M_NODE, &neighbor_send_community_cmd);
12848 install_element(BGP_IPV4M_NODE, &neighbor_send_community_type_cmd);
12849 install_element(BGP_IPV4M_NODE, &no_neighbor_send_community_cmd);
12850 install_element(BGP_IPV4M_NODE, &no_neighbor_send_community_type_cmd);
12851 install_element(BGP_IPV4L_NODE, &neighbor_send_community_cmd);
12852 install_element(BGP_IPV4L_NODE, &neighbor_send_community_type_cmd);
12853 install_element(BGP_IPV4L_NODE, &no_neighbor_send_community_cmd);
12854 install_element(BGP_IPV4L_NODE, &no_neighbor_send_community_type_cmd);
12855 install_element(BGP_IPV6_NODE, &neighbor_send_community_cmd);
12856 install_element(BGP_IPV6_NODE, &neighbor_send_community_type_cmd);
12857 install_element(BGP_IPV6_NODE, &no_neighbor_send_community_cmd);
12858 install_element(BGP_IPV6_NODE, &no_neighbor_send_community_type_cmd);
12859 install_element(BGP_IPV6M_NODE, &neighbor_send_community_cmd);
12860 install_element(BGP_IPV6M_NODE, &neighbor_send_community_type_cmd);
12861 install_element(BGP_IPV6M_NODE, &no_neighbor_send_community_cmd);
12862 install_element(BGP_IPV6M_NODE, &no_neighbor_send_community_type_cmd);
12863 install_element(BGP_IPV6L_NODE, &neighbor_send_community_cmd);
12864 install_element(BGP_IPV6L_NODE, &neighbor_send_community_type_cmd);
12865 install_element(BGP_IPV6L_NODE, &no_neighbor_send_community_cmd);
12866 install_element(BGP_IPV6L_NODE, &no_neighbor_send_community_type_cmd);
12867 install_element(BGP_VPNV4_NODE, &neighbor_send_community_cmd);
12868 install_element(BGP_VPNV4_NODE, &neighbor_send_community_type_cmd);
12869 install_element(BGP_VPNV4_NODE, &no_neighbor_send_community_cmd);
12870 install_element(BGP_VPNV4_NODE, &no_neighbor_send_community_type_cmd);
12871 install_element(BGP_VPNV6_NODE, &neighbor_send_community_cmd);
12872 install_element(BGP_VPNV6_NODE, &neighbor_send_community_type_cmd);
12873 install_element(BGP_VPNV6_NODE, &no_neighbor_send_community_cmd);
12874 install_element(BGP_VPNV6_NODE, &no_neighbor_send_community_type_cmd);
12875
12876 /* "neighbor route-reflector" commands.*/
12877 install_element(BGP_NODE, &neighbor_route_reflector_client_hidden_cmd);
12878 install_element(BGP_NODE,
12879 &no_neighbor_route_reflector_client_hidden_cmd);
12880 install_element(BGP_IPV4_NODE, &neighbor_route_reflector_client_cmd);
12881 install_element(BGP_IPV4_NODE, &no_neighbor_route_reflector_client_cmd);
12882 install_element(BGP_IPV4M_NODE, &neighbor_route_reflector_client_cmd);
12883 install_element(BGP_IPV4M_NODE,
12884 &no_neighbor_route_reflector_client_cmd);
12885 install_element(BGP_IPV4L_NODE, &neighbor_route_reflector_client_cmd);
12886 install_element(BGP_IPV4L_NODE,
12887 &no_neighbor_route_reflector_client_cmd);
12888 install_element(BGP_IPV6_NODE, &neighbor_route_reflector_client_cmd);
12889 install_element(BGP_IPV6_NODE, &no_neighbor_route_reflector_client_cmd);
12890 install_element(BGP_IPV6M_NODE, &neighbor_route_reflector_client_cmd);
12891 install_element(BGP_IPV6M_NODE,
12892 &no_neighbor_route_reflector_client_cmd);
12893 install_element(BGP_IPV6L_NODE, &neighbor_route_reflector_client_cmd);
12894 install_element(BGP_IPV6L_NODE,
12895 &no_neighbor_route_reflector_client_cmd);
12896 install_element(BGP_VPNV4_NODE, &neighbor_route_reflector_client_cmd);
12897 install_element(BGP_VPNV4_NODE,
12898 &no_neighbor_route_reflector_client_cmd);
12899 install_element(BGP_VPNV6_NODE, &neighbor_route_reflector_client_cmd);
12900 install_element(BGP_VPNV6_NODE,
12901 &no_neighbor_route_reflector_client_cmd);
12902 install_element(BGP_FLOWSPECV4_NODE,
12903 &neighbor_route_reflector_client_cmd);
12904 install_element(BGP_FLOWSPECV4_NODE,
12905 &no_neighbor_route_reflector_client_cmd);
12906 install_element(BGP_FLOWSPECV6_NODE,
12907 &neighbor_route_reflector_client_cmd);
12908 install_element(BGP_FLOWSPECV6_NODE,
12909 &no_neighbor_route_reflector_client_cmd);
12910 install_element(BGP_EVPN_NODE, &neighbor_route_reflector_client_cmd);
12911 install_element(BGP_EVPN_NODE, &no_neighbor_route_reflector_client_cmd);
12912
12913 /* "neighbor route-server" commands.*/
12914 install_element(BGP_NODE, &neighbor_route_server_client_hidden_cmd);
12915 install_element(BGP_NODE, &no_neighbor_route_server_client_hidden_cmd);
12916 install_element(BGP_IPV4_NODE, &neighbor_route_server_client_cmd);
12917 install_element(BGP_IPV4_NODE, &no_neighbor_route_server_client_cmd);
12918 install_element(BGP_IPV4M_NODE, &neighbor_route_server_client_cmd);
12919 install_element(BGP_IPV4M_NODE, &no_neighbor_route_server_client_cmd);
12920 install_element(BGP_IPV4L_NODE, &neighbor_route_server_client_cmd);
12921 install_element(BGP_IPV4L_NODE, &no_neighbor_route_server_client_cmd);
12922 install_element(BGP_IPV6_NODE, &neighbor_route_server_client_cmd);
12923 install_element(BGP_IPV6_NODE, &no_neighbor_route_server_client_cmd);
12924 install_element(BGP_IPV6M_NODE, &neighbor_route_server_client_cmd);
12925 install_element(BGP_IPV6M_NODE, &no_neighbor_route_server_client_cmd);
12926 install_element(BGP_IPV6L_NODE, &neighbor_route_server_client_cmd);
12927 install_element(BGP_IPV6L_NODE, &no_neighbor_route_server_client_cmd);
12928 install_element(BGP_VPNV4_NODE, &neighbor_route_server_client_cmd);
12929 install_element(BGP_VPNV4_NODE, &no_neighbor_route_server_client_cmd);
12930 install_element(BGP_VPNV6_NODE, &neighbor_route_server_client_cmd);
12931 install_element(BGP_VPNV6_NODE, &no_neighbor_route_server_client_cmd);
12932 install_element(BGP_FLOWSPECV4_NODE, &neighbor_route_server_client_cmd);
12933 install_element(BGP_FLOWSPECV4_NODE,
12934 &no_neighbor_route_server_client_cmd);
12935 install_element(BGP_FLOWSPECV6_NODE, &neighbor_route_server_client_cmd);
12936 install_element(BGP_FLOWSPECV6_NODE,
12937 &no_neighbor_route_server_client_cmd);
12938
12939 /* "neighbor addpath-tx-all-paths" commands.*/
12940 install_element(BGP_NODE, &neighbor_addpath_tx_all_paths_hidden_cmd);
12941 install_element(BGP_NODE, &no_neighbor_addpath_tx_all_paths_hidden_cmd);
12942 install_element(BGP_IPV4_NODE, &neighbor_addpath_tx_all_paths_cmd);
12943 install_element(BGP_IPV4_NODE, &no_neighbor_addpath_tx_all_paths_cmd);
12944 install_element(BGP_IPV4M_NODE, &neighbor_addpath_tx_all_paths_cmd);
12945 install_element(BGP_IPV4M_NODE, &no_neighbor_addpath_tx_all_paths_cmd);
12946 install_element(BGP_IPV4L_NODE, &neighbor_addpath_tx_all_paths_cmd);
12947 install_element(BGP_IPV4L_NODE, &no_neighbor_addpath_tx_all_paths_cmd);
12948 install_element(BGP_IPV6_NODE, &neighbor_addpath_tx_all_paths_cmd);
12949 install_element(BGP_IPV6_NODE, &no_neighbor_addpath_tx_all_paths_cmd);
12950 install_element(BGP_IPV6M_NODE, &neighbor_addpath_tx_all_paths_cmd);
12951 install_element(BGP_IPV6M_NODE, &no_neighbor_addpath_tx_all_paths_cmd);
12952 install_element(BGP_IPV6L_NODE, &neighbor_addpath_tx_all_paths_cmd);
12953 install_element(BGP_IPV6L_NODE, &no_neighbor_addpath_tx_all_paths_cmd);
12954 install_element(BGP_VPNV4_NODE, &neighbor_addpath_tx_all_paths_cmd);
12955 install_element(BGP_VPNV4_NODE, &no_neighbor_addpath_tx_all_paths_cmd);
12956 install_element(BGP_VPNV6_NODE, &neighbor_addpath_tx_all_paths_cmd);
12957 install_element(BGP_VPNV6_NODE, &no_neighbor_addpath_tx_all_paths_cmd);
12958
12959 /* "neighbor addpath-tx-bestpath-per-AS" commands.*/
12960 install_element(BGP_NODE,
12961 &neighbor_addpath_tx_bestpath_per_as_hidden_cmd);
12962 install_element(BGP_NODE,
12963 &no_neighbor_addpath_tx_bestpath_per_as_hidden_cmd);
12964 install_element(BGP_IPV4_NODE,
12965 &neighbor_addpath_tx_bestpath_per_as_cmd);
12966 install_element(BGP_IPV4_NODE,
12967 &no_neighbor_addpath_tx_bestpath_per_as_cmd);
12968 install_element(BGP_IPV4M_NODE,
12969 &neighbor_addpath_tx_bestpath_per_as_cmd);
12970 install_element(BGP_IPV4M_NODE,
12971 &no_neighbor_addpath_tx_bestpath_per_as_cmd);
12972 install_element(BGP_IPV4L_NODE,
12973 &neighbor_addpath_tx_bestpath_per_as_cmd);
12974 install_element(BGP_IPV4L_NODE,
12975 &no_neighbor_addpath_tx_bestpath_per_as_cmd);
12976 install_element(BGP_IPV6_NODE,
12977 &neighbor_addpath_tx_bestpath_per_as_cmd);
12978 install_element(BGP_IPV6_NODE,
12979 &no_neighbor_addpath_tx_bestpath_per_as_cmd);
12980 install_element(BGP_IPV6M_NODE,
12981 &neighbor_addpath_tx_bestpath_per_as_cmd);
12982 install_element(BGP_IPV6M_NODE,
12983 &no_neighbor_addpath_tx_bestpath_per_as_cmd);
12984 install_element(BGP_IPV6L_NODE,
12985 &neighbor_addpath_tx_bestpath_per_as_cmd);
12986 install_element(BGP_IPV6L_NODE,
12987 &no_neighbor_addpath_tx_bestpath_per_as_cmd);
12988 install_element(BGP_VPNV4_NODE,
12989 &neighbor_addpath_tx_bestpath_per_as_cmd);
12990 install_element(BGP_VPNV4_NODE,
12991 &no_neighbor_addpath_tx_bestpath_per_as_cmd);
12992 install_element(BGP_VPNV6_NODE,
12993 &neighbor_addpath_tx_bestpath_per_as_cmd);
12994 install_element(BGP_VPNV6_NODE,
12995 &no_neighbor_addpath_tx_bestpath_per_as_cmd);
12996
12997 /* "neighbor passive" commands. */
12998 install_element(BGP_NODE, &neighbor_passive_cmd);
12999 install_element(BGP_NODE, &no_neighbor_passive_cmd);
13000
13001
13002 /* "neighbor shutdown" commands. */
13003 install_element(BGP_NODE, &neighbor_shutdown_cmd);
13004 install_element(BGP_NODE, &no_neighbor_shutdown_cmd);
13005 install_element(BGP_NODE, &neighbor_shutdown_msg_cmd);
13006 install_element(BGP_NODE, &no_neighbor_shutdown_msg_cmd);
13007
13008 /* "neighbor capability extended-nexthop" commands.*/
13009 install_element(BGP_NODE, &neighbor_capability_enhe_cmd);
13010 install_element(BGP_NODE, &no_neighbor_capability_enhe_cmd);
13011
13012 /* "neighbor capability orf prefix-list" commands.*/
13013 install_element(BGP_NODE, &neighbor_capability_orf_prefix_hidden_cmd);
13014 install_element(BGP_NODE,
13015 &no_neighbor_capability_orf_prefix_hidden_cmd);
13016 install_element(BGP_IPV4_NODE, &neighbor_capability_orf_prefix_cmd);
13017 install_element(BGP_IPV4_NODE, &no_neighbor_capability_orf_prefix_cmd);
13018 install_element(BGP_IPV4M_NODE, &neighbor_capability_orf_prefix_cmd);
13019 install_element(BGP_IPV4M_NODE, &no_neighbor_capability_orf_prefix_cmd);
13020 install_element(BGP_IPV4L_NODE, &neighbor_capability_orf_prefix_cmd);
13021 install_element(BGP_IPV4L_NODE, &no_neighbor_capability_orf_prefix_cmd);
13022 install_element(BGP_IPV6_NODE, &neighbor_capability_orf_prefix_cmd);
13023 install_element(BGP_IPV6_NODE, &no_neighbor_capability_orf_prefix_cmd);
13024 install_element(BGP_IPV6M_NODE, &neighbor_capability_orf_prefix_cmd);
13025 install_element(BGP_IPV6M_NODE, &no_neighbor_capability_orf_prefix_cmd);
13026 install_element(BGP_IPV6L_NODE, &neighbor_capability_orf_prefix_cmd);
13027 install_element(BGP_IPV6L_NODE, &no_neighbor_capability_orf_prefix_cmd);
13028
13029 /* "neighbor capability dynamic" commands.*/
13030 install_element(BGP_NODE, &neighbor_capability_dynamic_cmd);
13031 install_element(BGP_NODE, &no_neighbor_capability_dynamic_cmd);
13032
13033 /* "neighbor dont-capability-negotiate" commands. */
13034 install_element(BGP_NODE, &neighbor_dont_capability_negotiate_cmd);
13035 install_element(BGP_NODE, &no_neighbor_dont_capability_negotiate_cmd);
13036
13037 /* "neighbor ebgp-multihop" commands. */
13038 install_element(BGP_NODE, &neighbor_ebgp_multihop_cmd);
13039 install_element(BGP_NODE, &neighbor_ebgp_multihop_ttl_cmd);
13040 install_element(BGP_NODE, &no_neighbor_ebgp_multihop_cmd);
13041
13042 /* "neighbor disable-connected-check" commands. */
13043 install_element(BGP_NODE, &neighbor_disable_connected_check_cmd);
13044 install_element(BGP_NODE, &no_neighbor_disable_connected_check_cmd);
13045
13046 /* "neighbor enforce-first-as" commands. */
13047 install_element(BGP_NODE, &neighbor_enforce_first_as_cmd);
13048 install_element(BGP_NODE, &no_neighbor_enforce_first_as_cmd);
13049
13050 /* "neighbor description" commands. */
13051 install_element(BGP_NODE, &neighbor_description_cmd);
13052 install_element(BGP_NODE, &no_neighbor_description_cmd);
13053 install_element(BGP_NODE, &no_neighbor_description_comment_cmd);
13054
13055 /* "neighbor update-source" commands. "*/
13056 install_element(BGP_NODE, &neighbor_update_source_cmd);
13057 install_element(BGP_NODE, &no_neighbor_update_source_cmd);
13058
13059 /* "neighbor default-originate" commands. */
13060 install_element(BGP_NODE, &neighbor_default_originate_hidden_cmd);
13061 install_element(BGP_NODE, &neighbor_default_originate_rmap_hidden_cmd);
13062 install_element(BGP_NODE, &no_neighbor_default_originate_hidden_cmd);
13063 install_element(BGP_IPV4_NODE, &neighbor_default_originate_cmd);
13064 install_element(BGP_IPV4_NODE, &neighbor_default_originate_rmap_cmd);
13065 install_element(BGP_IPV4_NODE, &no_neighbor_default_originate_cmd);
13066 install_element(BGP_IPV4M_NODE, &neighbor_default_originate_cmd);
13067 install_element(BGP_IPV4M_NODE, &neighbor_default_originate_rmap_cmd);
13068 install_element(BGP_IPV4M_NODE, &no_neighbor_default_originate_cmd);
13069 install_element(BGP_IPV4L_NODE, &neighbor_default_originate_cmd);
13070 install_element(BGP_IPV4L_NODE, &neighbor_default_originate_rmap_cmd);
13071 install_element(BGP_IPV4L_NODE, &no_neighbor_default_originate_cmd);
13072 install_element(BGP_IPV6_NODE, &neighbor_default_originate_cmd);
13073 install_element(BGP_IPV6_NODE, &neighbor_default_originate_rmap_cmd);
13074 install_element(BGP_IPV6_NODE, &no_neighbor_default_originate_cmd);
13075 install_element(BGP_IPV6M_NODE, &neighbor_default_originate_cmd);
13076 install_element(BGP_IPV6M_NODE, &neighbor_default_originate_rmap_cmd);
13077 install_element(BGP_IPV6M_NODE, &no_neighbor_default_originate_cmd);
13078 install_element(BGP_IPV6L_NODE, &neighbor_default_originate_cmd);
13079 install_element(BGP_IPV6L_NODE, &neighbor_default_originate_rmap_cmd);
13080 install_element(BGP_IPV6L_NODE, &no_neighbor_default_originate_cmd);
13081
13082 /* "neighbor port" commands. */
13083 install_element(BGP_NODE, &neighbor_port_cmd);
13084 install_element(BGP_NODE, &no_neighbor_port_cmd);
13085
13086 /* "neighbor weight" commands. */
13087 install_element(BGP_NODE, &neighbor_weight_hidden_cmd);
13088 install_element(BGP_NODE, &no_neighbor_weight_hidden_cmd);
13089
13090 install_element(BGP_IPV4_NODE, &neighbor_weight_cmd);
13091 install_element(BGP_IPV4_NODE, &no_neighbor_weight_cmd);
13092 install_element(BGP_IPV4M_NODE, &neighbor_weight_cmd);
13093 install_element(BGP_IPV4M_NODE, &no_neighbor_weight_cmd);
13094 install_element(BGP_IPV4L_NODE, &neighbor_weight_cmd);
13095 install_element(BGP_IPV4L_NODE, &no_neighbor_weight_cmd);
13096 install_element(BGP_IPV6_NODE, &neighbor_weight_cmd);
13097 install_element(BGP_IPV6_NODE, &no_neighbor_weight_cmd);
13098 install_element(BGP_IPV6M_NODE, &neighbor_weight_cmd);
13099 install_element(BGP_IPV6M_NODE, &no_neighbor_weight_cmd);
13100 install_element(BGP_IPV6L_NODE, &neighbor_weight_cmd);
13101 install_element(BGP_IPV6L_NODE, &no_neighbor_weight_cmd);
13102 install_element(BGP_VPNV4_NODE, &neighbor_weight_cmd);
13103 install_element(BGP_VPNV4_NODE, &no_neighbor_weight_cmd);
13104 install_element(BGP_VPNV6_NODE, &neighbor_weight_cmd);
13105 install_element(BGP_VPNV6_NODE, &no_neighbor_weight_cmd);
13106
13107 /* "neighbor override-capability" commands. */
13108 install_element(BGP_NODE, &neighbor_override_capability_cmd);
13109 install_element(BGP_NODE, &no_neighbor_override_capability_cmd);
13110
13111 /* "neighbor strict-capability-match" commands. */
13112 install_element(BGP_NODE, &neighbor_strict_capability_cmd);
13113 install_element(BGP_NODE, &no_neighbor_strict_capability_cmd);
13114
13115 /* "neighbor timers" commands. */
13116 install_element(BGP_NODE, &neighbor_timers_cmd);
13117 install_element(BGP_NODE, &no_neighbor_timers_cmd);
13118
13119 /* "neighbor timers connect" commands. */
13120 install_element(BGP_NODE, &neighbor_timers_connect_cmd);
13121 install_element(BGP_NODE, &no_neighbor_timers_connect_cmd);
13122
13123 /* "neighbor advertisement-interval" commands. */
13124 install_element(BGP_NODE, &neighbor_advertise_interval_cmd);
13125 install_element(BGP_NODE, &no_neighbor_advertise_interval_cmd);
13126
13127 /* "neighbor interface" commands. */
13128 install_element(BGP_NODE, &neighbor_interface_cmd);
13129 install_element(BGP_NODE, &no_neighbor_interface_cmd);
13130
13131 /* "neighbor distribute" commands. */
13132 install_element(BGP_NODE, &neighbor_distribute_list_hidden_cmd);
13133 install_element(BGP_NODE, &no_neighbor_distribute_list_hidden_cmd);
13134 install_element(BGP_IPV4_NODE, &neighbor_distribute_list_cmd);
13135 install_element(BGP_IPV4_NODE, &no_neighbor_distribute_list_cmd);
13136 install_element(BGP_IPV4M_NODE, &neighbor_distribute_list_cmd);
13137 install_element(BGP_IPV4M_NODE, &no_neighbor_distribute_list_cmd);
13138 install_element(BGP_IPV4L_NODE, &neighbor_distribute_list_cmd);
13139 install_element(BGP_IPV4L_NODE, &no_neighbor_distribute_list_cmd);
13140 install_element(BGP_IPV6_NODE, &neighbor_distribute_list_cmd);
13141 install_element(BGP_IPV6_NODE, &no_neighbor_distribute_list_cmd);
13142 install_element(BGP_IPV6M_NODE, &neighbor_distribute_list_cmd);
13143 install_element(BGP_IPV6M_NODE, &no_neighbor_distribute_list_cmd);
13144 install_element(BGP_IPV6L_NODE, &neighbor_distribute_list_cmd);
13145 install_element(BGP_IPV6L_NODE, &no_neighbor_distribute_list_cmd);
13146 install_element(BGP_VPNV4_NODE, &neighbor_distribute_list_cmd);
13147 install_element(BGP_VPNV4_NODE, &no_neighbor_distribute_list_cmd);
13148 install_element(BGP_VPNV6_NODE, &neighbor_distribute_list_cmd);
13149 install_element(BGP_VPNV6_NODE, &no_neighbor_distribute_list_cmd);
13150
13151 /* "neighbor prefix-list" commands. */
13152 install_element(BGP_NODE, &neighbor_prefix_list_hidden_cmd);
13153 install_element(BGP_NODE, &no_neighbor_prefix_list_hidden_cmd);
13154 install_element(BGP_IPV4_NODE, &neighbor_prefix_list_cmd);
13155 install_element(BGP_IPV4_NODE, &no_neighbor_prefix_list_cmd);
13156 install_element(BGP_IPV4M_NODE, &neighbor_prefix_list_cmd);
13157 install_element(BGP_IPV4M_NODE, &no_neighbor_prefix_list_cmd);
13158 install_element(BGP_IPV4L_NODE, &neighbor_prefix_list_cmd);
13159 install_element(BGP_IPV4L_NODE, &no_neighbor_prefix_list_cmd);
13160 install_element(BGP_IPV6_NODE, &neighbor_prefix_list_cmd);
13161 install_element(BGP_IPV6_NODE, &no_neighbor_prefix_list_cmd);
13162 install_element(BGP_IPV6M_NODE, &neighbor_prefix_list_cmd);
13163 install_element(BGP_IPV6M_NODE, &no_neighbor_prefix_list_cmd);
13164 install_element(BGP_IPV6L_NODE, &neighbor_prefix_list_cmd);
13165 install_element(BGP_IPV6L_NODE, &no_neighbor_prefix_list_cmd);
13166 install_element(BGP_VPNV4_NODE, &neighbor_prefix_list_cmd);
13167 install_element(BGP_VPNV4_NODE, &no_neighbor_prefix_list_cmd);
13168 install_element(BGP_VPNV6_NODE, &neighbor_prefix_list_cmd);
13169 install_element(BGP_VPNV6_NODE, &no_neighbor_prefix_list_cmd);
13170 install_element(BGP_FLOWSPECV4_NODE, &neighbor_prefix_list_cmd);
13171 install_element(BGP_FLOWSPECV4_NODE, &no_neighbor_prefix_list_cmd);
13172 install_element(BGP_FLOWSPECV6_NODE, &neighbor_prefix_list_cmd);
13173 install_element(BGP_FLOWSPECV6_NODE, &no_neighbor_prefix_list_cmd);
13174
13175 /* "neighbor filter-list" commands. */
13176 install_element(BGP_NODE, &neighbor_filter_list_hidden_cmd);
13177 install_element(BGP_NODE, &no_neighbor_filter_list_hidden_cmd);
13178 install_element(BGP_IPV4_NODE, &neighbor_filter_list_cmd);
13179 install_element(BGP_IPV4_NODE, &no_neighbor_filter_list_cmd);
13180 install_element(BGP_IPV4M_NODE, &neighbor_filter_list_cmd);
13181 install_element(BGP_IPV4M_NODE, &no_neighbor_filter_list_cmd);
13182 install_element(BGP_IPV4L_NODE, &neighbor_filter_list_cmd);
13183 install_element(BGP_IPV4L_NODE, &no_neighbor_filter_list_cmd);
13184 install_element(BGP_IPV6_NODE, &neighbor_filter_list_cmd);
13185 install_element(BGP_IPV6_NODE, &no_neighbor_filter_list_cmd);
13186 install_element(BGP_IPV6M_NODE, &neighbor_filter_list_cmd);
13187 install_element(BGP_IPV6M_NODE, &no_neighbor_filter_list_cmd);
13188 install_element(BGP_IPV6L_NODE, &neighbor_filter_list_cmd);
13189 install_element(BGP_IPV6L_NODE, &no_neighbor_filter_list_cmd);
13190 install_element(BGP_VPNV4_NODE, &neighbor_filter_list_cmd);
13191 install_element(BGP_VPNV4_NODE, &no_neighbor_filter_list_cmd);
13192 install_element(BGP_VPNV6_NODE, &neighbor_filter_list_cmd);
13193 install_element(BGP_VPNV6_NODE, &no_neighbor_filter_list_cmd);
13194 install_element(BGP_FLOWSPECV4_NODE, &neighbor_filter_list_cmd);
13195 install_element(BGP_FLOWSPECV4_NODE, &no_neighbor_filter_list_cmd);
13196 install_element(BGP_FLOWSPECV6_NODE, &neighbor_filter_list_cmd);
13197 install_element(BGP_FLOWSPECV6_NODE, &no_neighbor_filter_list_cmd);
13198
13199 /* "neighbor route-map" commands. */
13200 install_element(BGP_NODE, &neighbor_route_map_hidden_cmd);
13201 install_element(BGP_NODE, &no_neighbor_route_map_hidden_cmd);
13202 install_element(BGP_IPV4_NODE, &neighbor_route_map_cmd);
13203 install_element(BGP_IPV4_NODE, &no_neighbor_route_map_cmd);
13204 install_element(BGP_IPV4M_NODE, &neighbor_route_map_cmd);
13205 install_element(BGP_IPV4M_NODE, &no_neighbor_route_map_cmd);
13206 install_element(BGP_IPV4L_NODE, &neighbor_route_map_cmd);
13207 install_element(BGP_IPV4L_NODE, &no_neighbor_route_map_cmd);
13208 install_element(BGP_IPV6_NODE, &neighbor_route_map_cmd);
13209 install_element(BGP_IPV6_NODE, &no_neighbor_route_map_cmd);
13210 install_element(BGP_IPV6M_NODE, &neighbor_route_map_cmd);
13211 install_element(BGP_IPV6M_NODE, &no_neighbor_route_map_cmd);
13212 install_element(BGP_IPV6L_NODE, &neighbor_route_map_cmd);
13213 install_element(BGP_IPV6L_NODE, &no_neighbor_route_map_cmd);
13214 install_element(BGP_VPNV4_NODE, &neighbor_route_map_cmd);
13215 install_element(BGP_VPNV4_NODE, &no_neighbor_route_map_cmd);
13216 install_element(BGP_VPNV6_NODE, &neighbor_route_map_cmd);
13217 install_element(BGP_VPNV6_NODE, &no_neighbor_route_map_cmd);
13218 install_element(BGP_FLOWSPECV4_NODE, &neighbor_route_map_cmd);
13219 install_element(BGP_FLOWSPECV4_NODE, &no_neighbor_route_map_cmd);
13220 install_element(BGP_FLOWSPECV6_NODE, &neighbor_route_map_cmd);
13221 install_element(BGP_FLOWSPECV6_NODE, &no_neighbor_route_map_cmd);
13222 install_element(BGP_EVPN_NODE, &neighbor_route_map_cmd);
13223 install_element(BGP_EVPN_NODE, &no_neighbor_route_map_cmd);
13224
13225 /* "neighbor unsuppress-map" commands. */
13226 install_element(BGP_NODE, &neighbor_unsuppress_map_hidden_cmd);
13227 install_element(BGP_NODE, &no_neighbor_unsuppress_map_hidden_cmd);
13228 install_element(BGP_IPV4_NODE, &neighbor_unsuppress_map_cmd);
13229 install_element(BGP_IPV4_NODE, &no_neighbor_unsuppress_map_cmd);
13230 install_element(BGP_IPV4M_NODE, &neighbor_unsuppress_map_cmd);
13231 install_element(BGP_IPV4M_NODE, &no_neighbor_unsuppress_map_cmd);
13232 install_element(BGP_IPV4L_NODE, &neighbor_unsuppress_map_cmd);
13233 install_element(BGP_IPV4L_NODE, &no_neighbor_unsuppress_map_cmd);
13234 install_element(BGP_IPV6_NODE, &neighbor_unsuppress_map_cmd);
13235 install_element(BGP_IPV6_NODE, &no_neighbor_unsuppress_map_cmd);
13236 install_element(BGP_IPV6M_NODE, &neighbor_unsuppress_map_cmd);
13237 install_element(BGP_IPV6M_NODE, &no_neighbor_unsuppress_map_cmd);
13238 install_element(BGP_IPV6L_NODE, &neighbor_unsuppress_map_cmd);
13239 install_element(BGP_IPV6L_NODE, &no_neighbor_unsuppress_map_cmd);
13240 install_element(BGP_VPNV4_NODE, &neighbor_unsuppress_map_cmd);
13241 install_element(BGP_VPNV4_NODE, &no_neighbor_unsuppress_map_cmd);
13242 install_element(BGP_VPNV6_NODE, &neighbor_unsuppress_map_cmd);
13243 install_element(BGP_VPNV6_NODE, &no_neighbor_unsuppress_map_cmd);
13244
13245 /* "neighbor maximum-prefix" commands. */
13246 install_element(BGP_NODE, &neighbor_maximum_prefix_hidden_cmd);
13247 install_element(BGP_NODE,
13248 &neighbor_maximum_prefix_threshold_hidden_cmd);
13249 install_element(BGP_NODE, &neighbor_maximum_prefix_warning_hidden_cmd);
13250 install_element(BGP_NODE,
13251 &neighbor_maximum_prefix_threshold_warning_hidden_cmd);
13252 install_element(BGP_NODE, &neighbor_maximum_prefix_restart_hidden_cmd);
13253 install_element(BGP_NODE,
13254 &neighbor_maximum_prefix_threshold_restart_hidden_cmd);
13255 install_element(BGP_NODE, &no_neighbor_maximum_prefix_hidden_cmd);
13256 install_element(BGP_IPV4_NODE, &neighbor_maximum_prefix_cmd);
13257 install_element(BGP_IPV4_NODE, &neighbor_maximum_prefix_threshold_cmd);
13258 install_element(BGP_IPV4_NODE, &neighbor_maximum_prefix_warning_cmd);
13259 install_element(BGP_IPV4_NODE,
13260 &neighbor_maximum_prefix_threshold_warning_cmd);
13261 install_element(BGP_IPV4_NODE, &neighbor_maximum_prefix_restart_cmd);
13262 install_element(BGP_IPV4_NODE,
13263 &neighbor_maximum_prefix_threshold_restart_cmd);
13264 install_element(BGP_IPV4_NODE, &no_neighbor_maximum_prefix_cmd);
13265 install_element(BGP_IPV4M_NODE, &neighbor_maximum_prefix_cmd);
13266 install_element(BGP_IPV4M_NODE, &neighbor_maximum_prefix_threshold_cmd);
13267 install_element(BGP_IPV4M_NODE, &neighbor_maximum_prefix_warning_cmd);
13268 install_element(BGP_IPV4M_NODE,
13269 &neighbor_maximum_prefix_threshold_warning_cmd);
13270 install_element(BGP_IPV4M_NODE, &neighbor_maximum_prefix_restart_cmd);
13271 install_element(BGP_IPV4M_NODE,
13272 &neighbor_maximum_prefix_threshold_restart_cmd);
13273 install_element(BGP_IPV4M_NODE, &no_neighbor_maximum_prefix_cmd);
13274 install_element(BGP_IPV4L_NODE, &neighbor_maximum_prefix_cmd);
13275 install_element(BGP_IPV4L_NODE, &neighbor_maximum_prefix_threshold_cmd);
13276 install_element(BGP_IPV4L_NODE, &neighbor_maximum_prefix_warning_cmd);
13277 install_element(BGP_IPV4L_NODE,
13278 &neighbor_maximum_prefix_threshold_warning_cmd);
13279 install_element(BGP_IPV4L_NODE, &neighbor_maximum_prefix_restart_cmd);
13280 install_element(BGP_IPV4L_NODE,
13281 &neighbor_maximum_prefix_threshold_restart_cmd);
13282 install_element(BGP_IPV4L_NODE, &no_neighbor_maximum_prefix_cmd);
13283 install_element(BGP_IPV6_NODE, &neighbor_maximum_prefix_cmd);
13284 install_element(BGP_IPV6_NODE, &neighbor_maximum_prefix_threshold_cmd);
13285 install_element(BGP_IPV6_NODE, &neighbor_maximum_prefix_warning_cmd);
13286 install_element(BGP_IPV6_NODE,
13287 &neighbor_maximum_prefix_threshold_warning_cmd);
13288 install_element(BGP_IPV6_NODE, &neighbor_maximum_prefix_restart_cmd);
13289 install_element(BGP_IPV6_NODE,
13290 &neighbor_maximum_prefix_threshold_restart_cmd);
13291 install_element(BGP_IPV6_NODE, &no_neighbor_maximum_prefix_cmd);
13292 install_element(BGP_IPV6M_NODE, &neighbor_maximum_prefix_cmd);
13293 install_element(BGP_IPV6M_NODE, &neighbor_maximum_prefix_threshold_cmd);
13294 install_element(BGP_IPV6M_NODE, &neighbor_maximum_prefix_warning_cmd);
13295 install_element(BGP_IPV6M_NODE,
13296 &neighbor_maximum_prefix_threshold_warning_cmd);
13297 install_element(BGP_IPV6M_NODE, &neighbor_maximum_prefix_restart_cmd);
13298 install_element(BGP_IPV6M_NODE,
13299 &neighbor_maximum_prefix_threshold_restart_cmd);
13300 install_element(BGP_IPV6M_NODE, &no_neighbor_maximum_prefix_cmd);
13301 install_element(BGP_IPV6L_NODE, &neighbor_maximum_prefix_cmd);
13302 install_element(BGP_IPV6L_NODE, &neighbor_maximum_prefix_threshold_cmd);
13303 install_element(BGP_IPV6L_NODE, &neighbor_maximum_prefix_warning_cmd);
13304 install_element(BGP_IPV6L_NODE,
13305 &neighbor_maximum_prefix_threshold_warning_cmd);
13306 install_element(BGP_IPV6L_NODE, &neighbor_maximum_prefix_restart_cmd);
13307 install_element(BGP_IPV6L_NODE,
13308 &neighbor_maximum_prefix_threshold_restart_cmd);
13309 install_element(BGP_IPV6L_NODE, &no_neighbor_maximum_prefix_cmd);
13310 install_element(BGP_VPNV4_NODE, &neighbor_maximum_prefix_cmd);
13311 install_element(BGP_VPNV4_NODE, &neighbor_maximum_prefix_threshold_cmd);
13312 install_element(BGP_VPNV4_NODE, &neighbor_maximum_prefix_warning_cmd);
13313 install_element(BGP_VPNV4_NODE,
13314 &neighbor_maximum_prefix_threshold_warning_cmd);
13315 install_element(BGP_VPNV4_NODE, &neighbor_maximum_prefix_restart_cmd);
13316 install_element(BGP_VPNV4_NODE,
13317 &neighbor_maximum_prefix_threshold_restart_cmd);
13318 install_element(BGP_VPNV4_NODE, &no_neighbor_maximum_prefix_cmd);
13319 install_element(BGP_VPNV6_NODE, &neighbor_maximum_prefix_cmd);
13320 install_element(BGP_VPNV6_NODE, &neighbor_maximum_prefix_threshold_cmd);
13321 install_element(BGP_VPNV6_NODE, &neighbor_maximum_prefix_warning_cmd);
13322 install_element(BGP_VPNV6_NODE,
13323 &neighbor_maximum_prefix_threshold_warning_cmd);
13324 install_element(BGP_VPNV6_NODE, &neighbor_maximum_prefix_restart_cmd);
13325 install_element(BGP_VPNV6_NODE,
13326 &neighbor_maximum_prefix_threshold_restart_cmd);
13327 install_element(BGP_VPNV6_NODE, &no_neighbor_maximum_prefix_cmd);
13328
13329 /* "neighbor allowas-in" */
13330 install_element(BGP_NODE, &neighbor_allowas_in_hidden_cmd);
13331 install_element(BGP_NODE, &no_neighbor_allowas_in_hidden_cmd);
13332 install_element(BGP_IPV4_NODE, &neighbor_allowas_in_cmd);
13333 install_element(BGP_IPV4_NODE, &no_neighbor_allowas_in_cmd);
13334 install_element(BGP_IPV4M_NODE, &neighbor_allowas_in_cmd);
13335 install_element(BGP_IPV4M_NODE, &no_neighbor_allowas_in_cmd);
13336 install_element(BGP_IPV4L_NODE, &neighbor_allowas_in_cmd);
13337 install_element(BGP_IPV4L_NODE, &no_neighbor_allowas_in_cmd);
13338 install_element(BGP_IPV6_NODE, &neighbor_allowas_in_cmd);
13339 install_element(BGP_IPV6_NODE, &no_neighbor_allowas_in_cmd);
13340 install_element(BGP_IPV6M_NODE, &neighbor_allowas_in_cmd);
13341 install_element(BGP_IPV6M_NODE, &no_neighbor_allowas_in_cmd);
13342 install_element(BGP_IPV6L_NODE, &neighbor_allowas_in_cmd);
13343 install_element(BGP_IPV6L_NODE, &no_neighbor_allowas_in_cmd);
13344 install_element(BGP_VPNV4_NODE, &neighbor_allowas_in_cmd);
13345 install_element(BGP_VPNV4_NODE, &no_neighbor_allowas_in_cmd);
13346 install_element(BGP_VPNV6_NODE, &neighbor_allowas_in_cmd);
13347 install_element(BGP_VPNV6_NODE, &no_neighbor_allowas_in_cmd);
13348 install_element(BGP_EVPN_NODE, &neighbor_allowas_in_cmd);
13349 install_element(BGP_EVPN_NODE, &no_neighbor_allowas_in_cmd);
13350
13351 /* address-family commands. */
13352 install_element(BGP_NODE, &address_family_ipv4_safi_cmd);
13353 install_element(BGP_NODE, &address_family_ipv6_safi_cmd);
13354 #ifdef KEEP_OLD_VPN_COMMANDS
13355 install_element(BGP_NODE, &address_family_vpnv4_cmd);
13356 install_element(BGP_NODE, &address_family_vpnv6_cmd);
13357 #endif /* KEEP_OLD_VPN_COMMANDS */
13358
13359 install_element(BGP_NODE, &address_family_evpn_cmd);
13360
13361 /* "exit-address-family" command. */
13362 install_element(BGP_IPV4_NODE, &exit_address_family_cmd);
13363 install_element(BGP_IPV4M_NODE, &exit_address_family_cmd);
13364 install_element(BGP_IPV4L_NODE, &exit_address_family_cmd);
13365 install_element(BGP_IPV6_NODE, &exit_address_family_cmd);
13366 install_element(BGP_IPV6M_NODE, &exit_address_family_cmd);
13367 install_element(BGP_IPV6L_NODE, &exit_address_family_cmd);
13368 install_element(BGP_VPNV4_NODE, &exit_address_family_cmd);
13369 install_element(BGP_VPNV6_NODE, &exit_address_family_cmd);
13370 install_element(BGP_FLOWSPECV4_NODE, &exit_address_family_cmd);
13371 install_element(BGP_FLOWSPECV6_NODE, &exit_address_family_cmd);
13372 install_element(BGP_EVPN_NODE, &exit_address_family_cmd);
13373
13374 /* "clear ip bgp commands" */
13375 install_element(ENABLE_NODE, &clear_ip_bgp_all_cmd);
13376
13377 /* clear ip bgp prefix */
13378 install_element(ENABLE_NODE, &clear_ip_bgp_prefix_cmd);
13379 install_element(ENABLE_NODE, &clear_bgp_ipv6_safi_prefix_cmd);
13380 install_element(ENABLE_NODE, &clear_bgp_instance_ipv6_safi_prefix_cmd);
13381
13382 /* "show [ip] bgp summary" commands. */
13383 install_element(VIEW_NODE, &show_bgp_instance_all_ipv6_updgrps_cmd);
13384 install_element(VIEW_NODE, &show_bgp_instance_updgrps_stats_cmd);
13385 install_element(VIEW_NODE, &show_bgp_updgrps_stats_cmd);
13386 install_element(VIEW_NODE, &show_ip_bgp_instance_updgrps_adj_s_cmd);
13387 install_element(VIEW_NODE, &show_ip_bgp_summary_cmd);
13388 install_element(VIEW_NODE, &show_ip_bgp_updgrps_cmd);
13389
13390 /* "show [ip] bgp neighbors" commands. */
13391 install_element(VIEW_NODE, &show_ip_bgp_neighbors_cmd);
13392
13393 /* "show [ip] bgp peer-group" commands. */
13394 install_element(VIEW_NODE, &show_ip_bgp_peer_groups_cmd);
13395
13396 /* "show [ip] bgp paths" commands. */
13397 install_element(VIEW_NODE, &show_ip_bgp_paths_cmd);
13398
13399 /* "show [ip] bgp community" commands. */
13400 install_element(VIEW_NODE, &show_ip_bgp_community_info_cmd);
13401
13402 /* "show ip bgp large-community" commands. */
13403 install_element(VIEW_NODE, &show_ip_bgp_lcommunity_info_cmd);
13404 /* "show [ip] bgp attribute-info" commands. */
13405 install_element(VIEW_NODE, &show_ip_bgp_attr_info_cmd);
13406 /* "show [ip] bgp route-leak" command */
13407 install_element(VIEW_NODE, &show_ip_bgp_route_leak_cmd);
13408
13409 /* "redistribute" commands. */
13410 install_element(BGP_NODE, &bgp_redistribute_ipv4_hidden_cmd);
13411 install_element(BGP_NODE, &no_bgp_redistribute_ipv4_hidden_cmd);
13412 install_element(BGP_NODE, &bgp_redistribute_ipv4_rmap_hidden_cmd);
13413 install_element(BGP_NODE, &bgp_redistribute_ipv4_metric_hidden_cmd);
13414 install_element(BGP_NODE,
13415 &bgp_redistribute_ipv4_rmap_metric_hidden_cmd);
13416 install_element(BGP_NODE,
13417 &bgp_redistribute_ipv4_metric_rmap_hidden_cmd);
13418 install_element(BGP_NODE, &bgp_redistribute_ipv4_ospf_hidden_cmd);
13419 install_element(BGP_NODE, &no_bgp_redistribute_ipv4_ospf_hidden_cmd);
13420 install_element(BGP_NODE, &bgp_redistribute_ipv4_ospf_rmap_hidden_cmd);
13421 install_element(BGP_NODE,
13422 &bgp_redistribute_ipv4_ospf_metric_hidden_cmd);
13423 install_element(BGP_NODE,
13424 &bgp_redistribute_ipv4_ospf_rmap_metric_hidden_cmd);
13425 install_element(BGP_NODE,
13426 &bgp_redistribute_ipv4_ospf_metric_rmap_hidden_cmd);
13427 install_element(BGP_IPV4_NODE, &bgp_redistribute_ipv4_cmd);
13428 install_element(BGP_IPV4_NODE, &no_bgp_redistribute_ipv4_cmd);
13429 install_element(BGP_IPV4_NODE, &bgp_redistribute_ipv4_rmap_cmd);
13430 install_element(BGP_IPV4_NODE, &bgp_redistribute_ipv4_metric_cmd);
13431 install_element(BGP_IPV4_NODE, &bgp_redistribute_ipv4_rmap_metric_cmd);
13432 install_element(BGP_IPV4_NODE, &bgp_redistribute_ipv4_metric_rmap_cmd);
13433 install_element(BGP_IPV4_NODE, &bgp_redistribute_ipv4_ospf_cmd);
13434 install_element(BGP_IPV4_NODE, &no_bgp_redistribute_ipv4_ospf_cmd);
13435 install_element(BGP_IPV4_NODE, &bgp_redistribute_ipv4_ospf_rmap_cmd);
13436 install_element(BGP_IPV4_NODE, &bgp_redistribute_ipv4_ospf_metric_cmd);
13437 install_element(BGP_IPV4_NODE,
13438 &bgp_redistribute_ipv4_ospf_rmap_metric_cmd);
13439 install_element(BGP_IPV4_NODE,
13440 &bgp_redistribute_ipv4_ospf_metric_rmap_cmd);
13441 install_element(BGP_IPV6_NODE, &bgp_redistribute_ipv6_cmd);
13442 install_element(BGP_IPV6_NODE, &no_bgp_redistribute_ipv6_cmd);
13443 install_element(BGP_IPV6_NODE, &bgp_redistribute_ipv6_rmap_cmd);
13444 install_element(BGP_IPV6_NODE, &bgp_redistribute_ipv6_metric_cmd);
13445 install_element(BGP_IPV6_NODE, &bgp_redistribute_ipv6_rmap_metric_cmd);
13446 install_element(BGP_IPV6_NODE, &bgp_redistribute_ipv6_metric_rmap_cmd);
13447
13448 /* import|export vpn [route-map WORD] */
13449 install_element(BGP_IPV4_NODE, &bgp_imexport_vpn_cmd);
13450 install_element(BGP_IPV6_NODE, &bgp_imexport_vpn_cmd);
13451
13452 install_element(BGP_IPV4_NODE, &bgp_imexport_vrf_cmd);
13453 install_element(BGP_IPV6_NODE, &bgp_imexport_vrf_cmd);
13454
13455 /* ttl_security commands */
13456 install_element(BGP_NODE, &neighbor_ttl_security_cmd);
13457 install_element(BGP_NODE, &no_neighbor_ttl_security_cmd);
13458
13459 /* "show [ip] bgp memory" commands. */
13460 install_element(VIEW_NODE, &show_bgp_memory_cmd);
13461
13462 /* "show bgp martian next-hop" */
13463 install_element(VIEW_NODE, &show_bgp_martian_nexthop_db_cmd);
13464
13465 /* "show [ip] bgp views" commands. */
13466 install_element(VIEW_NODE, &show_bgp_views_cmd);
13467
13468 /* "show [ip] bgp vrfs" commands. */
13469 install_element(VIEW_NODE, &show_bgp_vrfs_cmd);
13470
13471 /* Community-list. */
13472 community_list_vty();
13473
13474 /* vpn-policy commands */
13475 install_element(BGP_IPV4_NODE, &af_rd_vpn_export_cmd);
13476 install_element(BGP_IPV6_NODE, &af_rd_vpn_export_cmd);
13477 install_element(BGP_IPV4_NODE, &af_label_vpn_export_cmd);
13478 install_element(BGP_IPV6_NODE, &af_label_vpn_export_cmd);
13479 install_element(BGP_IPV4_NODE, &af_nexthop_vpn_export_cmd);
13480 install_element(BGP_IPV6_NODE, &af_nexthop_vpn_export_cmd);
13481 install_element(BGP_IPV4_NODE, &af_rt_vpn_imexport_cmd);
13482 install_element(BGP_IPV6_NODE, &af_rt_vpn_imexport_cmd);
13483 install_element(BGP_IPV4_NODE, &af_route_map_vpn_imexport_cmd);
13484 install_element(BGP_IPV6_NODE, &af_route_map_vpn_imexport_cmd);
13485 install_element(BGP_IPV4_NODE, &af_import_vrf_route_map_cmd);
13486 install_element(BGP_IPV6_NODE, &af_import_vrf_route_map_cmd);
13487
13488 install_element(BGP_IPV4_NODE, &af_routetarget_import_cmd);
13489 install_element(BGP_IPV6_NODE, &af_routetarget_import_cmd);
13490
13491 install_element(BGP_IPV4_NODE, &af_no_rd_vpn_export_cmd);
13492 install_element(BGP_IPV6_NODE, &af_no_rd_vpn_export_cmd);
13493 install_element(BGP_IPV4_NODE, &af_no_label_vpn_export_cmd);
13494 install_element(BGP_IPV6_NODE, &af_no_label_vpn_export_cmd);
13495 install_element(BGP_IPV4_NODE, &af_no_nexthop_vpn_export_cmd);
13496 install_element(BGP_IPV6_NODE, &af_no_nexthop_vpn_export_cmd);
13497 install_element(BGP_IPV4_NODE, &af_no_rt_vpn_imexport_cmd);
13498 install_element(BGP_IPV6_NODE, &af_no_rt_vpn_imexport_cmd);
13499 install_element(BGP_IPV4_NODE, &af_no_route_map_vpn_imexport_cmd);
13500 install_element(BGP_IPV6_NODE, &af_no_route_map_vpn_imexport_cmd);
13501 install_element(BGP_IPV4_NODE, &af_no_import_vrf_route_map_cmd);
13502 install_element(BGP_IPV6_NODE, &af_no_import_vrf_route_map_cmd);
13503 }
13504
13505 #include "memory.h"
13506 #include "bgp_regex.h"
13507 #include "bgp_clist.h"
13508 #include "bgp_ecommunity.h"
13509
13510 /* VTY functions. */
13511
13512 /* Direction value to string conversion. */
13513 static const char *community_direct_str(int direct)
13514 {
13515 switch (direct) {
13516 case COMMUNITY_DENY:
13517 return "deny";
13518 case COMMUNITY_PERMIT:
13519 return "permit";
13520 default:
13521 return "unknown";
13522 }
13523 }
13524
13525 /* Display error string. */
13526 static void community_list_perror(struct vty *vty, int ret)
13527 {
13528 switch (ret) {
13529 case COMMUNITY_LIST_ERR_CANT_FIND_LIST:
13530 vty_out(vty, "%% Can't find community-list\n");
13531 break;
13532 case COMMUNITY_LIST_ERR_MALFORMED_VAL:
13533 vty_out(vty, "%% Malformed community-list value\n");
13534 break;
13535 case COMMUNITY_LIST_ERR_STANDARD_CONFLICT:
13536 vty_out(vty,
13537 "%% Community name conflict, previously defined as standard community\n");
13538 break;
13539 case COMMUNITY_LIST_ERR_EXPANDED_CONFLICT:
13540 vty_out(vty,
13541 "%% Community name conflict, previously defined as expanded community\n");
13542 break;
13543 }
13544 }
13545
13546 /* "community-list" keyword help string. */
13547 #define COMMUNITY_LIST_STR "Add a community list entry\n"
13548
13549 /* ip community-list standard */
13550 DEFUN (ip_community_list_standard,
13551 ip_community_list_standard_cmd,
13552 "ip community-list <(1-99)|standard WORD> <deny|permit> AA:NN...",
13553 IP_STR
13554 COMMUNITY_LIST_STR
13555 "Community list number (standard)\n"
13556 "Add an standard community-list entry\n"
13557 "Community list name\n"
13558 "Specify community to reject\n"
13559 "Specify community to accept\n"
13560 COMMUNITY_VAL_STR)
13561 {
13562 char *cl_name_or_number = NULL;
13563 int direct = 0;
13564 int style = COMMUNITY_LIST_STANDARD;
13565
13566 int idx = 0;
13567 argv_find(argv, argc, "(1-99)", &idx);
13568 argv_find(argv, argc, "WORD", &idx);
13569 cl_name_or_number = argv[idx]->arg;
13570 direct = argv_find(argv, argc, "permit", &idx) ? COMMUNITY_PERMIT
13571 : COMMUNITY_DENY;
13572 argv_find(argv, argc, "AA:NN", &idx);
13573 char *str = argv_concat(argv, argc, idx);
13574
13575 int ret = community_list_set(bgp_clist, cl_name_or_number, str, direct,
13576 style);
13577
13578 XFREE(MTYPE_TMP, str);
13579
13580 if (ret < 0) {
13581 /* Display error string. */
13582 community_list_perror(vty, ret);
13583 return CMD_WARNING_CONFIG_FAILED;
13584 }
13585
13586 return CMD_SUCCESS;
13587 }
13588
13589 DEFUN (no_ip_community_list_standard_all,
13590 no_ip_community_list_standard_all_cmd,
13591 "no ip community-list <(1-99)|standard WORD> <deny|permit> AA:NN...",
13592 NO_STR
13593 IP_STR
13594 COMMUNITY_LIST_STR
13595 "Community list number (standard)\n"
13596 "Add an standard community-list entry\n"
13597 "Community list name\n"
13598 "Specify community to reject\n"
13599 "Specify community to accept\n"
13600 COMMUNITY_VAL_STR)
13601 {
13602 char *cl_name_or_number = NULL;
13603 int direct = 0;
13604 int style = COMMUNITY_LIST_STANDARD;
13605
13606 int idx = 0;
13607 argv_find(argv, argc, "(1-99)", &idx);
13608 argv_find(argv, argc, "WORD", &idx);
13609 cl_name_or_number = argv[idx]->arg;
13610 direct = argv_find(argv, argc, "permit", &idx) ? COMMUNITY_PERMIT
13611 : COMMUNITY_DENY;
13612 argv_find(argv, argc, "AA:NN", &idx);
13613 char *str = argv_concat(argv, argc, idx);
13614
13615 int ret = community_list_unset(bgp_clist, cl_name_or_number, str,
13616 direct, style);
13617
13618 XFREE(MTYPE_TMP, str);
13619
13620 if (ret < 0) {
13621 community_list_perror(vty, ret);
13622 return CMD_WARNING_CONFIG_FAILED;
13623 }
13624
13625 return CMD_SUCCESS;
13626 }
13627
13628 /* ip community-list expanded */
13629 DEFUN (ip_community_list_expanded_all,
13630 ip_community_list_expanded_all_cmd,
13631 "ip community-list <(100-500)|expanded WORD> <deny|permit> AA:NN...",
13632 IP_STR
13633 COMMUNITY_LIST_STR
13634 "Community list number (expanded)\n"
13635 "Add an expanded community-list entry\n"
13636 "Community list name\n"
13637 "Specify community to reject\n"
13638 "Specify community to accept\n"
13639 COMMUNITY_VAL_STR)
13640 {
13641 char *cl_name_or_number = NULL;
13642 int direct = 0;
13643 int style = COMMUNITY_LIST_EXPANDED;
13644
13645 int idx = 0;
13646 argv_find(argv, argc, "(100-500)", &idx);
13647 argv_find(argv, argc, "WORD", &idx);
13648 cl_name_or_number = argv[idx]->arg;
13649 direct = argv_find(argv, argc, "permit", &idx) ? COMMUNITY_PERMIT
13650 : COMMUNITY_DENY;
13651 argv_find(argv, argc, "AA:NN", &idx);
13652 char *str = argv_concat(argv, argc, idx);
13653
13654 int ret = community_list_set(bgp_clist, cl_name_or_number, str, direct,
13655 style);
13656
13657 XFREE(MTYPE_TMP, str);
13658
13659 if (ret < 0) {
13660 /* Display error string. */
13661 community_list_perror(vty, ret);
13662 return CMD_WARNING_CONFIG_FAILED;
13663 }
13664
13665 return CMD_SUCCESS;
13666 }
13667
13668 DEFUN (no_ip_community_list_expanded_all,
13669 no_ip_community_list_expanded_all_cmd,
13670 "no ip community-list <(100-500)|expanded WORD> <deny|permit> AA:NN...",
13671 NO_STR
13672 IP_STR
13673 COMMUNITY_LIST_STR
13674 "Community list number (expanded)\n"
13675 "Add an expanded community-list entry\n"
13676 "Community list name\n"
13677 "Specify community to reject\n"
13678 "Specify community to accept\n"
13679 COMMUNITY_VAL_STR)
13680 {
13681 char *cl_name_or_number = NULL;
13682 int direct = 0;
13683 int style = COMMUNITY_LIST_EXPANDED;
13684
13685 int idx = 0;
13686 argv_find(argv, argc, "(100-500)", &idx);
13687 argv_find(argv, argc, "WORD", &idx);
13688 cl_name_or_number = argv[idx]->arg;
13689 direct = argv_find(argv, argc, "permit", &idx) ? COMMUNITY_PERMIT
13690 : COMMUNITY_DENY;
13691 argv_find(argv, argc, "AA:NN", &idx);
13692 char *str = argv_concat(argv, argc, idx);
13693
13694 int ret = community_list_unset(bgp_clist, cl_name_or_number, str,
13695 direct, style);
13696
13697 XFREE(MTYPE_TMP, str);
13698
13699 if (ret < 0) {
13700 community_list_perror(vty, ret);
13701 return CMD_WARNING_CONFIG_FAILED;
13702 }
13703
13704 return CMD_SUCCESS;
13705 }
13706
13707 /* Return configuration string of community-list entry. */
13708 static const char *community_list_config_str(struct community_entry *entry)
13709 {
13710 const char *str;
13711
13712 if (entry->any)
13713 str = "";
13714 else {
13715 if (entry->style == COMMUNITY_LIST_STANDARD)
13716 str = community_str(entry->u.com, false);
13717 else if (entry->style == LARGE_COMMUNITY_LIST_STANDARD)
13718 str = lcommunity_str(entry->u.lcom, false);
13719 else
13720 str = entry->config;
13721 }
13722 return str;
13723 }
13724
13725 static void community_list_show(struct vty *vty, struct community_list *list)
13726 {
13727 struct community_entry *entry;
13728
13729 for (entry = list->head; entry; entry = entry->next) {
13730 if (entry == list->head) {
13731 if (all_digit(list->name))
13732 vty_out(vty, "Community %s list %s\n",
13733 entry->style == COMMUNITY_LIST_STANDARD
13734 ? "standard"
13735 : "(expanded) access",
13736 list->name);
13737 else
13738 vty_out(vty, "Named Community %s list %s\n",
13739 entry->style == COMMUNITY_LIST_STANDARD
13740 ? "standard"
13741 : "expanded",
13742 list->name);
13743 }
13744 if (entry->any)
13745 vty_out(vty, " %s\n",
13746 community_direct_str(entry->direct));
13747 else
13748 vty_out(vty, " %s %s\n",
13749 community_direct_str(entry->direct),
13750 community_list_config_str(entry));
13751 }
13752 }
13753
13754 DEFUN (show_ip_community_list,
13755 show_ip_community_list_cmd,
13756 "show ip community-list",
13757 SHOW_STR
13758 IP_STR
13759 "List community-list\n")
13760 {
13761 struct community_list *list;
13762 struct community_list_master *cm;
13763
13764 cm = community_list_master_lookup(bgp_clist, COMMUNITY_LIST_MASTER);
13765 if (!cm)
13766 return CMD_SUCCESS;
13767
13768 for (list = cm->num.head; list; list = list->next)
13769 community_list_show(vty, list);
13770
13771 for (list = cm->str.head; list; list = list->next)
13772 community_list_show(vty, list);
13773
13774 return CMD_SUCCESS;
13775 }
13776
13777 DEFUN (show_ip_community_list_arg,
13778 show_ip_community_list_arg_cmd,
13779 "show ip community-list <(1-500)|WORD>",
13780 SHOW_STR
13781 IP_STR
13782 "List community-list\n"
13783 "Community-list number\n"
13784 "Community-list name\n")
13785 {
13786 int idx_comm_list = 3;
13787 struct community_list *list;
13788
13789 list = community_list_lookup(bgp_clist, argv[idx_comm_list]->arg,
13790 COMMUNITY_LIST_MASTER);
13791 if (!list) {
13792 vty_out(vty, "%% Can't find community-list\n");
13793 return CMD_WARNING;
13794 }
13795
13796 community_list_show(vty, list);
13797
13798 return CMD_SUCCESS;
13799 }
13800
13801 /*
13802 * Large Community code.
13803 */
13804 static int lcommunity_list_set_vty(struct vty *vty, int argc,
13805 struct cmd_token **argv, int style,
13806 int reject_all_digit_name)
13807 {
13808 int ret;
13809 int direct;
13810 char *str;
13811 int idx = 0;
13812 char *cl_name;
13813
13814 direct = argv_find(argv, argc, "permit", &idx) ? COMMUNITY_PERMIT
13815 : COMMUNITY_DENY;
13816
13817 /* All digit name check. */
13818 idx = 0;
13819 argv_find(argv, argc, "WORD", &idx);
13820 argv_find(argv, argc, "(1-99)", &idx);
13821 argv_find(argv, argc, "(100-500)", &idx);
13822 cl_name = argv[idx]->arg;
13823 if (reject_all_digit_name && all_digit(cl_name)) {
13824 vty_out(vty, "%% Community name cannot have all digits\n");
13825 return CMD_WARNING_CONFIG_FAILED;
13826 }
13827
13828 idx = 0;
13829 argv_find(argv, argc, "AA:BB:CC", &idx);
13830 argv_find(argv, argc, "LINE", &idx);
13831 /* Concat community string argument. */
13832 if (idx)
13833 str = argv_concat(argv, argc, idx);
13834 else
13835 str = NULL;
13836
13837 ret = lcommunity_list_set(bgp_clist, cl_name, str, direct, style);
13838
13839 /* Free temporary community list string allocated by
13840 argv_concat(). */
13841 if (str)
13842 XFREE(MTYPE_TMP, str);
13843
13844 if (ret < 0) {
13845 community_list_perror(vty, ret);
13846 return CMD_WARNING_CONFIG_FAILED;
13847 }
13848 return CMD_SUCCESS;
13849 }
13850
13851 static int lcommunity_list_unset_vty(struct vty *vty, int argc,
13852 struct cmd_token **argv, int style)
13853 {
13854 int ret;
13855 int direct = 0;
13856 char *str = NULL;
13857 int idx = 0;
13858
13859 argv_find(argv, argc, "permit", &idx);
13860 argv_find(argv, argc, "deny", &idx);
13861
13862 if (idx) {
13863 /* Check the list direct. */
13864 if (strncmp(argv[idx]->arg, "p", 1) == 0)
13865 direct = COMMUNITY_PERMIT;
13866 else
13867 direct = COMMUNITY_DENY;
13868
13869 idx = 0;
13870 argv_find(argv, argc, "LINE", &idx);
13871 argv_find(argv, argc, "AA:AA:NN", &idx);
13872 /* Concat community string argument. */
13873 str = argv_concat(argv, argc, idx);
13874 }
13875
13876 idx = 0;
13877 argv_find(argv, argc, "(1-99)", &idx);
13878 argv_find(argv, argc, "(100-500)", &idx);
13879 argv_find(argv, argc, "WORD", &idx);
13880
13881 /* Unset community list. */
13882 ret = lcommunity_list_unset(bgp_clist, argv[idx]->arg, str, direct,
13883 style);
13884
13885 /* Free temporary community list string allocated by
13886 argv_concat(). */
13887 if (str)
13888 XFREE(MTYPE_TMP, str);
13889
13890 if (ret < 0) {
13891 community_list_perror(vty, ret);
13892 return CMD_WARNING_CONFIG_FAILED;
13893 }
13894
13895 return CMD_SUCCESS;
13896 }
13897
13898 /* "large-community-list" keyword help string. */
13899 #define LCOMMUNITY_LIST_STR "Add a large community list entry\n"
13900 #define LCOMMUNITY_VAL_STR "large community in 'aa:bb:cc' format\n"
13901
13902 DEFUN (ip_lcommunity_list_standard,
13903 ip_lcommunity_list_standard_cmd,
13904 "ip large-community-list (1-99) <deny|permit>",
13905 IP_STR
13906 LCOMMUNITY_LIST_STR
13907 "Large Community list number (standard)\n"
13908 "Specify large community to reject\n"
13909 "Specify large community to accept\n")
13910 {
13911 return lcommunity_list_set_vty(vty, argc, argv,
13912 LARGE_COMMUNITY_LIST_STANDARD, 0);
13913 }
13914
13915 DEFUN (ip_lcommunity_list_standard1,
13916 ip_lcommunity_list_standard1_cmd,
13917 "ip large-community-list (1-99) <deny|permit> AA:BB:CC...",
13918 IP_STR
13919 LCOMMUNITY_LIST_STR
13920 "Large Community list number (standard)\n"
13921 "Specify large community to reject\n"
13922 "Specify large community to accept\n"
13923 LCOMMUNITY_VAL_STR)
13924 {
13925 return lcommunity_list_set_vty(vty, argc, argv,
13926 LARGE_COMMUNITY_LIST_STANDARD, 0);
13927 }
13928
13929 DEFUN (ip_lcommunity_list_expanded,
13930 ip_lcommunity_list_expanded_cmd,
13931 "ip large-community-list (100-500) <deny|permit> LINE...",
13932 IP_STR
13933 LCOMMUNITY_LIST_STR
13934 "Large Community list number (expanded)\n"
13935 "Specify large community to reject\n"
13936 "Specify large community to accept\n"
13937 "An ordered list as a regular-expression\n")
13938 {
13939 return lcommunity_list_set_vty(vty, argc, argv,
13940 LARGE_COMMUNITY_LIST_EXPANDED, 0);
13941 }
13942
13943 DEFUN (ip_lcommunity_list_name_standard,
13944 ip_lcommunity_list_name_standard_cmd,
13945 "ip large-community-list standard WORD <deny|permit>",
13946 IP_STR
13947 LCOMMUNITY_LIST_STR
13948 "Specify standard large-community-list\n"
13949 "Large Community list name\n"
13950 "Specify large community to reject\n"
13951 "Specify large community to accept\n")
13952 {
13953 return lcommunity_list_set_vty(vty, argc, argv,
13954 LARGE_COMMUNITY_LIST_STANDARD, 1);
13955 }
13956
13957 DEFUN (ip_lcommunity_list_name_standard1,
13958 ip_lcommunity_list_name_standard1_cmd,
13959 "ip large-community-list standard WORD <deny|permit> AA:BB:CC...",
13960 IP_STR
13961 LCOMMUNITY_LIST_STR
13962 "Specify standard large-community-list\n"
13963 "Large Community list name\n"
13964 "Specify large community to reject\n"
13965 "Specify large community to accept\n"
13966 LCOMMUNITY_VAL_STR)
13967 {
13968 return lcommunity_list_set_vty(vty, argc, argv,
13969 LARGE_COMMUNITY_LIST_STANDARD, 1);
13970 }
13971
13972 DEFUN (ip_lcommunity_list_name_expanded,
13973 ip_lcommunity_list_name_expanded_cmd,
13974 "ip large-community-list expanded WORD <deny|permit> LINE...",
13975 IP_STR
13976 LCOMMUNITY_LIST_STR
13977 "Specify expanded large-community-list\n"
13978 "Large Community list name\n"
13979 "Specify large community to reject\n"
13980 "Specify large community to accept\n"
13981 "An ordered list as a regular-expression\n")
13982 {
13983 return lcommunity_list_set_vty(vty, argc, argv,
13984 LARGE_COMMUNITY_LIST_EXPANDED, 1);
13985 }
13986
13987 DEFUN (no_ip_lcommunity_list_standard_all,
13988 no_ip_lcommunity_list_standard_all_cmd,
13989 "no ip large-community-list <(1-99)|(100-500)|WORD>",
13990 NO_STR
13991 IP_STR
13992 LCOMMUNITY_LIST_STR
13993 "Large Community list number (standard)\n"
13994 "Large Community list number (expanded)\n"
13995 "Large Community list name\n")
13996 {
13997 return lcommunity_list_unset_vty(vty, argc, argv,
13998 LARGE_COMMUNITY_LIST_STANDARD);
13999 }
14000
14001 DEFUN (no_ip_lcommunity_list_name_expanded_all,
14002 no_ip_lcommunity_list_name_expanded_all_cmd,
14003 "no ip large-community-list expanded WORD",
14004 NO_STR
14005 IP_STR
14006 LCOMMUNITY_LIST_STR
14007 "Specify expanded large-community-list\n"
14008 "Large Community list name\n")
14009 {
14010 return lcommunity_list_unset_vty(vty, argc, argv,
14011 LARGE_COMMUNITY_LIST_EXPANDED);
14012 }
14013
14014 DEFUN (no_ip_lcommunity_list_standard,
14015 no_ip_lcommunity_list_standard_cmd,
14016 "no ip large-community-list (1-99) <deny|permit> AA:AA:NN...",
14017 NO_STR
14018 IP_STR
14019 LCOMMUNITY_LIST_STR
14020 "Large Community list number (standard)\n"
14021 "Specify large community to reject\n"
14022 "Specify large community to accept\n"
14023 LCOMMUNITY_VAL_STR)
14024 {
14025 return lcommunity_list_unset_vty(vty, argc, argv,
14026 LARGE_COMMUNITY_LIST_STANDARD);
14027 }
14028
14029 DEFUN (no_ip_lcommunity_list_expanded,
14030 no_ip_lcommunity_list_expanded_cmd,
14031 "no ip large-community-list (100-500) <deny|permit> LINE...",
14032 NO_STR
14033 IP_STR
14034 LCOMMUNITY_LIST_STR
14035 "Large Community list number (expanded)\n"
14036 "Specify large community to reject\n"
14037 "Specify large community to accept\n"
14038 "An ordered list as a regular-expression\n")
14039 {
14040 return lcommunity_list_unset_vty(vty, argc, argv,
14041 LARGE_COMMUNITY_LIST_EXPANDED);
14042 }
14043
14044 DEFUN (no_ip_lcommunity_list_name_standard,
14045 no_ip_lcommunity_list_name_standard_cmd,
14046 "no ip large-community-list standard WORD <deny|permit> AA:AA:NN...",
14047 NO_STR
14048 IP_STR
14049 LCOMMUNITY_LIST_STR
14050 "Specify standard large-community-list\n"
14051 "Large Community list name\n"
14052 "Specify large community to reject\n"
14053 "Specify large community to accept\n"
14054 LCOMMUNITY_VAL_STR)
14055 {
14056 return lcommunity_list_unset_vty(vty, argc, argv,
14057 LARGE_COMMUNITY_LIST_STANDARD);
14058 }
14059
14060 DEFUN (no_ip_lcommunity_list_name_expanded,
14061 no_ip_lcommunity_list_name_expanded_cmd,
14062 "no ip large-community-list expanded WORD <deny|permit> LINE...",
14063 NO_STR
14064 IP_STR
14065 LCOMMUNITY_LIST_STR
14066 "Specify expanded large-community-list\n"
14067 "Large community list name\n"
14068 "Specify large community to reject\n"
14069 "Specify large community to accept\n"
14070 "An ordered list as a regular-expression\n")
14071 {
14072 return lcommunity_list_unset_vty(vty, argc, argv,
14073 LARGE_COMMUNITY_LIST_EXPANDED);
14074 }
14075
14076 static void lcommunity_list_show(struct vty *vty, struct community_list *list)
14077 {
14078 struct community_entry *entry;
14079
14080 for (entry = list->head; entry; entry = entry->next) {
14081 if (entry == list->head) {
14082 if (all_digit(list->name))
14083 vty_out(vty, "Large community %s list %s\n",
14084 entry->style == EXTCOMMUNITY_LIST_STANDARD
14085 ? "standard"
14086 : "(expanded) access",
14087 list->name);
14088 else
14089 vty_out(vty,
14090 "Named large community %s list %s\n",
14091 entry->style == EXTCOMMUNITY_LIST_STANDARD
14092 ? "standard"
14093 : "expanded",
14094 list->name);
14095 }
14096 if (entry->any)
14097 vty_out(vty, " %s\n",
14098 community_direct_str(entry->direct));
14099 else
14100 vty_out(vty, " %s %s\n",
14101 community_direct_str(entry->direct),
14102 community_list_config_str(entry));
14103 }
14104 }
14105
14106 DEFUN (show_ip_lcommunity_list,
14107 show_ip_lcommunity_list_cmd,
14108 "show ip large-community-list",
14109 SHOW_STR
14110 IP_STR
14111 "List large-community list\n")
14112 {
14113 struct community_list *list;
14114 struct community_list_master *cm;
14115
14116 cm = community_list_master_lookup(bgp_clist,
14117 LARGE_COMMUNITY_LIST_MASTER);
14118 if (!cm)
14119 return CMD_SUCCESS;
14120
14121 for (list = cm->num.head; list; list = list->next)
14122 lcommunity_list_show(vty, list);
14123
14124 for (list = cm->str.head; list; list = list->next)
14125 lcommunity_list_show(vty, list);
14126
14127 return CMD_SUCCESS;
14128 }
14129
14130 DEFUN (show_ip_lcommunity_list_arg,
14131 show_ip_lcommunity_list_arg_cmd,
14132 "show ip large-community-list <(1-500)|WORD>",
14133 SHOW_STR
14134 IP_STR
14135 "List large-community list\n"
14136 "large-community-list number\n"
14137 "large-community-list name\n")
14138 {
14139 struct community_list *list;
14140
14141 list = community_list_lookup(bgp_clist, argv[3]->arg,
14142 LARGE_COMMUNITY_LIST_MASTER);
14143 if (!list) {
14144 vty_out(vty, "%% Can't find extcommunity-list\n");
14145 return CMD_WARNING;
14146 }
14147
14148 lcommunity_list_show(vty, list);
14149
14150 return CMD_SUCCESS;
14151 }
14152
14153 /* "extcommunity-list" keyword help string. */
14154 #define EXTCOMMUNITY_LIST_STR "Add a extended community list entry\n"
14155 #define EXTCOMMUNITY_VAL_STR "Extended community attribute in 'rt aa:nn_or_IPaddr:nn' OR 'soo aa:nn_or_IPaddr:nn' format\n"
14156
14157 DEFUN (ip_extcommunity_list_standard,
14158 ip_extcommunity_list_standard_cmd,
14159 "ip extcommunity-list <(1-99)|standard WORD> <deny|permit> AA:NN...",
14160 IP_STR
14161 EXTCOMMUNITY_LIST_STR
14162 "Extended Community list number (standard)\n"
14163 "Specify standard extcommunity-list\n"
14164 "Community list name\n"
14165 "Specify community to reject\n"
14166 "Specify community to accept\n"
14167 EXTCOMMUNITY_VAL_STR)
14168 {
14169 int style = EXTCOMMUNITY_LIST_STANDARD;
14170 int direct = 0;
14171 char *cl_number_or_name = NULL;
14172
14173 int idx = 0;
14174 argv_find(argv, argc, "(1-99)", &idx);
14175 argv_find(argv, argc, "WORD", &idx);
14176 cl_number_or_name = argv[idx]->arg;
14177 direct = argv_find(argv, argc, "permit", &idx) ? COMMUNITY_PERMIT
14178 : COMMUNITY_DENY;
14179 argv_find(argv, argc, "AA:NN", &idx);
14180 char *str = argv_concat(argv, argc, idx);
14181
14182 int ret = extcommunity_list_set(bgp_clist, cl_number_or_name, str,
14183 direct, style);
14184
14185 XFREE(MTYPE_TMP, str);
14186
14187 if (ret < 0) {
14188 community_list_perror(vty, ret);
14189 return CMD_WARNING_CONFIG_FAILED;
14190 }
14191
14192 return CMD_SUCCESS;
14193 }
14194
14195 DEFUN (ip_extcommunity_list_name_expanded,
14196 ip_extcommunity_list_name_expanded_cmd,
14197 "ip extcommunity-list <(100-500)|expanded WORD> <deny|permit> LINE...",
14198 IP_STR
14199 EXTCOMMUNITY_LIST_STR
14200 "Extended Community list number (expanded)\n"
14201 "Specify expanded extcommunity-list\n"
14202 "Extended Community list name\n"
14203 "Specify community to reject\n"
14204 "Specify community to accept\n"
14205 "An ordered list as a regular-expression\n")
14206 {
14207 int style = EXTCOMMUNITY_LIST_EXPANDED;
14208 int direct = 0;
14209 char *cl_number_or_name = NULL;
14210
14211 int idx = 0;
14212 argv_find(argv, argc, "(100-500)", &idx);
14213 argv_find(argv, argc, "WORD", &idx);
14214 cl_number_or_name = argv[idx]->arg;
14215 direct = argv_find(argv, argc, "permit", &idx) ? COMMUNITY_PERMIT
14216 : COMMUNITY_DENY;
14217 argv_find(argv, argc, "LINE", &idx);
14218 char *str = argv_concat(argv, argc, idx);
14219
14220 int ret = extcommunity_list_set(bgp_clist, cl_number_or_name, str,
14221 direct, style);
14222
14223 XFREE(MTYPE_TMP, str);
14224
14225 if (ret < 0) {
14226 community_list_perror(vty, ret);
14227 return CMD_WARNING_CONFIG_FAILED;
14228 }
14229
14230 return CMD_SUCCESS;
14231 }
14232
14233 DEFUN (no_ip_extcommunity_list_standard_all,
14234 no_ip_extcommunity_list_standard_all_cmd,
14235 "no ip extcommunity-list <(1-99)|standard WORD> <deny|permit> AA:NN...",
14236 NO_STR
14237 IP_STR
14238 EXTCOMMUNITY_LIST_STR
14239 "Extended Community list number (standard)\n"
14240 "Specify standard extcommunity-list\n"
14241 "Community list name\n"
14242 "Specify community to reject\n"
14243 "Specify community to accept\n"
14244 EXTCOMMUNITY_VAL_STR)
14245 {
14246 int style = EXTCOMMUNITY_LIST_STANDARD;
14247 int direct = 0;
14248 char *cl_number_or_name = NULL;
14249
14250 int idx = 0;
14251 argv_find(argv, argc, "(1-99)", &idx);
14252 argv_find(argv, argc, "WORD", &idx);
14253 cl_number_or_name = argv[idx]->arg;
14254 direct = argv_find(argv, argc, "permit", &idx) ? COMMUNITY_PERMIT
14255 : COMMUNITY_DENY;
14256 argv_find(argv, argc, "AA:NN", &idx);
14257 char *str = argv_concat(argv, argc, idx);
14258
14259 int ret = extcommunity_list_unset(bgp_clist, cl_number_or_name, str,
14260 direct, style);
14261
14262 XFREE(MTYPE_TMP, str);
14263
14264 if (ret < 0) {
14265 community_list_perror(vty, ret);
14266 return CMD_WARNING_CONFIG_FAILED;
14267 }
14268
14269 return CMD_SUCCESS;
14270 }
14271
14272 DEFUN (no_ip_extcommunity_list_expanded_all,
14273 no_ip_extcommunity_list_expanded_all_cmd,
14274 "no ip extcommunity-list <(100-500)|expanded WORD> <deny|permit> LINE...",
14275 NO_STR
14276 IP_STR
14277 EXTCOMMUNITY_LIST_STR
14278 "Extended Community list number (expanded)\n"
14279 "Specify expanded extcommunity-list\n"
14280 "Extended Community list name\n"
14281 "Specify community to reject\n"
14282 "Specify community to accept\n"
14283 "An ordered list as a regular-expression\n")
14284 {
14285 int style = EXTCOMMUNITY_LIST_EXPANDED;
14286 int direct = 0;
14287 char *cl_number_or_name = NULL;
14288
14289 int idx = 0;
14290 argv_find(argv, argc, "(100-500)", &idx);
14291 argv_find(argv, argc, "WORD", &idx);
14292 cl_number_or_name = argv[idx]->arg;
14293 direct = argv_find(argv, argc, "permit", &idx) ? COMMUNITY_PERMIT
14294 : COMMUNITY_DENY;
14295 argv_find(argv, argc, "LINE", &idx);
14296 char *str = argv_concat(argv, argc, idx);
14297
14298 int ret = extcommunity_list_unset(bgp_clist, cl_number_or_name, str,
14299 direct, style);
14300
14301 XFREE(MTYPE_TMP, str);
14302
14303 if (ret < 0) {
14304 community_list_perror(vty, ret);
14305 return CMD_WARNING_CONFIG_FAILED;
14306 }
14307
14308 return CMD_SUCCESS;
14309 }
14310
14311 static void extcommunity_list_show(struct vty *vty, struct community_list *list)
14312 {
14313 struct community_entry *entry;
14314
14315 for (entry = list->head; entry; entry = entry->next) {
14316 if (entry == list->head) {
14317 if (all_digit(list->name))
14318 vty_out(vty, "Extended community %s list %s\n",
14319 entry->style == EXTCOMMUNITY_LIST_STANDARD
14320 ? "standard"
14321 : "(expanded) access",
14322 list->name);
14323 else
14324 vty_out(vty,
14325 "Named extended community %s list %s\n",
14326 entry->style == EXTCOMMUNITY_LIST_STANDARD
14327 ? "standard"
14328 : "expanded",
14329 list->name);
14330 }
14331 if (entry->any)
14332 vty_out(vty, " %s\n",
14333 community_direct_str(entry->direct));
14334 else
14335 vty_out(vty, " %s %s\n",
14336 community_direct_str(entry->direct),
14337 community_list_config_str(entry));
14338 }
14339 }
14340
14341 DEFUN (show_ip_extcommunity_list,
14342 show_ip_extcommunity_list_cmd,
14343 "show ip extcommunity-list",
14344 SHOW_STR
14345 IP_STR
14346 "List extended-community list\n")
14347 {
14348 struct community_list *list;
14349 struct community_list_master *cm;
14350
14351 cm = community_list_master_lookup(bgp_clist, EXTCOMMUNITY_LIST_MASTER);
14352 if (!cm)
14353 return CMD_SUCCESS;
14354
14355 for (list = cm->num.head; list; list = list->next)
14356 extcommunity_list_show(vty, list);
14357
14358 for (list = cm->str.head; list; list = list->next)
14359 extcommunity_list_show(vty, list);
14360
14361 return CMD_SUCCESS;
14362 }
14363
14364 DEFUN (show_ip_extcommunity_list_arg,
14365 show_ip_extcommunity_list_arg_cmd,
14366 "show ip extcommunity-list <(1-500)|WORD>",
14367 SHOW_STR
14368 IP_STR
14369 "List extended-community list\n"
14370 "Extcommunity-list number\n"
14371 "Extcommunity-list name\n")
14372 {
14373 int idx_comm_list = 3;
14374 struct community_list *list;
14375
14376 list = community_list_lookup(bgp_clist, argv[idx_comm_list]->arg,
14377 EXTCOMMUNITY_LIST_MASTER);
14378 if (!list) {
14379 vty_out(vty, "%% Can't find extcommunity-list\n");
14380 return CMD_WARNING;
14381 }
14382
14383 extcommunity_list_show(vty, list);
14384
14385 return CMD_SUCCESS;
14386 }
14387
14388 /* Display community-list and extcommunity-list configuration. */
14389 static int community_list_config_write(struct vty *vty)
14390 {
14391 struct community_list *list;
14392 struct community_entry *entry;
14393 struct community_list_master *cm;
14394 int write = 0;
14395
14396 /* Community-list. */
14397 cm = community_list_master_lookup(bgp_clist, COMMUNITY_LIST_MASTER);
14398
14399 for (list = cm->num.head; list; list = list->next)
14400 for (entry = list->head; entry; entry = entry->next) {
14401 vty_out(vty, "ip community-list %s %s %s\n", list->name,
14402 community_direct_str(entry->direct),
14403 community_list_config_str(entry));
14404 write++;
14405 }
14406 for (list = cm->str.head; list; list = list->next)
14407 for (entry = list->head; entry; entry = entry->next) {
14408 vty_out(vty, "ip community-list %s %s %s %s\n",
14409 entry->style == COMMUNITY_LIST_STANDARD
14410 ? "standard"
14411 : "expanded",
14412 list->name, community_direct_str(entry->direct),
14413 community_list_config_str(entry));
14414 write++;
14415 }
14416
14417 /* Extcommunity-list. */
14418 cm = community_list_master_lookup(bgp_clist, EXTCOMMUNITY_LIST_MASTER);
14419
14420 for (list = cm->num.head; list; list = list->next)
14421 for (entry = list->head; entry; entry = entry->next) {
14422 vty_out(vty, "ip extcommunity-list %s %s %s\n",
14423 list->name, community_direct_str(entry->direct),
14424 community_list_config_str(entry));
14425 write++;
14426 }
14427 for (list = cm->str.head; list; list = list->next)
14428 for (entry = list->head; entry; entry = entry->next) {
14429 vty_out(vty, "ip extcommunity-list %s %s %s %s\n",
14430 entry->style == EXTCOMMUNITY_LIST_STANDARD
14431 ? "standard"
14432 : "expanded",
14433 list->name, community_direct_str(entry->direct),
14434 community_list_config_str(entry));
14435 write++;
14436 }
14437
14438
14439 /* lcommunity-list. */
14440 cm = community_list_master_lookup(bgp_clist,
14441 LARGE_COMMUNITY_LIST_MASTER);
14442
14443 for (list = cm->num.head; list; list = list->next)
14444 for (entry = list->head; entry; entry = entry->next) {
14445 vty_out(vty, "ip large-community-list %s %s %s\n",
14446 list->name, community_direct_str(entry->direct),
14447 community_list_config_str(entry));
14448 write++;
14449 }
14450 for (list = cm->str.head; list; list = list->next)
14451 for (entry = list->head; entry; entry = entry->next) {
14452 vty_out(vty, "ip large-community-list %s %s %s %s\n",
14453 entry->style == LARGE_COMMUNITY_LIST_STANDARD
14454 ? "standard"
14455 : "expanded",
14456 list->name, community_direct_str(entry->direct),
14457 community_list_config_str(entry));
14458 write++;
14459 }
14460
14461 return write;
14462 }
14463
14464 static struct cmd_node community_list_node = {
14465 COMMUNITY_LIST_NODE, "", 1 /* Export to vtysh. */
14466 };
14467
14468 static void community_list_vty(void)
14469 {
14470 install_node(&community_list_node, community_list_config_write);
14471
14472 /* Community-list. */
14473 install_element(CONFIG_NODE, &ip_community_list_standard_cmd);
14474 install_element(CONFIG_NODE, &ip_community_list_expanded_all_cmd);
14475 install_element(CONFIG_NODE, &no_ip_community_list_standard_all_cmd);
14476 install_element(CONFIG_NODE, &no_ip_community_list_expanded_all_cmd);
14477 install_element(VIEW_NODE, &show_ip_community_list_cmd);
14478 install_element(VIEW_NODE, &show_ip_community_list_arg_cmd);
14479
14480 /* Extcommunity-list. */
14481 install_element(CONFIG_NODE, &ip_extcommunity_list_standard_cmd);
14482 install_element(CONFIG_NODE, &ip_extcommunity_list_name_expanded_cmd);
14483 install_element(CONFIG_NODE, &no_ip_extcommunity_list_standard_all_cmd);
14484 install_element(CONFIG_NODE, &no_ip_extcommunity_list_expanded_all_cmd);
14485 install_element(VIEW_NODE, &show_ip_extcommunity_list_cmd);
14486 install_element(VIEW_NODE, &show_ip_extcommunity_list_arg_cmd);
14487
14488 /* Large Community List */
14489 install_element(CONFIG_NODE, &ip_lcommunity_list_standard_cmd);
14490 install_element(CONFIG_NODE, &ip_lcommunity_list_standard1_cmd);
14491 install_element(CONFIG_NODE, &ip_lcommunity_list_expanded_cmd);
14492 install_element(CONFIG_NODE, &ip_lcommunity_list_name_standard_cmd);
14493 install_element(CONFIG_NODE, &ip_lcommunity_list_name_standard1_cmd);
14494 install_element(CONFIG_NODE, &ip_lcommunity_list_name_expanded_cmd);
14495 install_element(CONFIG_NODE, &no_ip_lcommunity_list_standard_all_cmd);
14496 install_element(CONFIG_NODE,
14497 &no_ip_lcommunity_list_name_expanded_all_cmd);
14498 install_element(CONFIG_NODE, &no_ip_lcommunity_list_standard_cmd);
14499 install_element(CONFIG_NODE, &no_ip_lcommunity_list_expanded_cmd);
14500 install_element(CONFIG_NODE, &no_ip_lcommunity_list_name_standard_cmd);
14501 install_element(CONFIG_NODE, &no_ip_lcommunity_list_name_expanded_cmd);
14502 install_element(VIEW_NODE, &show_ip_lcommunity_list_cmd);
14503 install_element(VIEW_NODE, &show_ip_lcommunity_list_arg_cmd);
14504 }