]> git.proxmox.com Git - mirror_frr.git/blob - bgpd/bgp_vty.c
bgpd: Added local router-id to "show bgp neighbor"
[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 * @return the corresponding afi_t
188 */
189 afi_t bgp_vty_afi_from_str(const char *afi_str)
190 {
191 afi_t afi = AFI_MAX; /* unknown */
192 if (strmatch(afi_str, "ipv4"))
193 afi = AFI_IP;
194 else if (strmatch(afi_str, "ipv6"))
195 afi = AFI_IP6;
196 return afi;
197 }
198
199 int argv_find_and_parse_afi(struct cmd_token **argv, int argc, int *index,
200 afi_t *afi)
201 {
202 int ret = 0;
203 if (argv_find(argv, argc, "ipv4", index)) {
204 ret = 1;
205 if (afi)
206 *afi = AFI_IP;
207 } else if (argv_find(argv, argc, "ipv6", index)) {
208 ret = 1;
209 if (afi)
210 *afi = AFI_IP6;
211 }
212 return ret;
213 }
214
215 /* supports <unicast|multicast|vpn|labeled-unicast> */
216 safi_t bgp_vty_safi_from_str(const char *safi_str)
217 {
218 safi_t safi = SAFI_MAX; /* unknown */
219 if (strmatch(safi_str, "multicast"))
220 safi = SAFI_MULTICAST;
221 else if (strmatch(safi_str, "unicast"))
222 safi = SAFI_UNICAST;
223 else if (strmatch(safi_str, "vpn"))
224 safi = SAFI_MPLS_VPN;
225 else if (strmatch(safi_str, "labeled-unicast"))
226 safi = SAFI_LABELED_UNICAST;
227 else if (strmatch(safi_str, "flowspec"))
228 safi = SAFI_FLOWSPEC;
229 return safi;
230 }
231
232 int argv_find_and_parse_safi(struct cmd_token **argv, int argc, int *index,
233 safi_t *safi)
234 {
235 int ret = 0;
236 if (argv_find(argv, argc, "unicast", index)) {
237 ret = 1;
238 if (safi)
239 *safi = SAFI_UNICAST;
240 } else if (argv_find(argv, argc, "multicast", index)) {
241 ret = 1;
242 if (safi)
243 *safi = SAFI_MULTICAST;
244 } else if (argv_find(argv, argc, "labeled-unicast", index)) {
245 ret = 1;
246 if (safi)
247 *safi = SAFI_LABELED_UNICAST;
248 } else if (argv_find(argv, argc, "vpn", index)) {
249 ret = 1;
250 if (safi)
251 *safi = SAFI_MPLS_VPN;
252 } else if (argv_find(argv, argc, "flowspec", index)) {
253 ret = 1;
254 if (safi)
255 *safi = SAFI_FLOWSPEC;
256 }
257 return ret;
258 }
259
260 /*
261 * bgp_vty_find_and_parse_afi_safi_bgp
262 *
263 * For a given 'show ...' command, correctly parse the afi/safi/bgp out from it
264 * This function *assumes* that the calling function pre-sets the afi/safi/bgp
265 * to appropriate values for the calling function. This is to allow the
266 * calling function to make decisions appropriate for the show command
267 * that is being parsed.
268 *
269 * The show commands are generally of the form:
270 * "show [ip] bgp [<view|vrf> VIEWVRFNAME] [<ipv4|ipv6>
271 * [<unicast|multicast|vpn|labeled-unicast>]] ..."
272 *
273 * Since we use argv_find if the show command in particular doesn't have:
274 * [ip]
275 * [<view|vrf> VIEWVRFNAME]
276 * [<ipv4|ipv6> [<unicast|multicast|vpn|labeled-unicast>]]
277 * The command parsing should still be ok.
278 *
279 * vty -> The vty for the command so we can output some useful data in
280 * the event of a parse error in the vrf.
281 * argv -> The command tokens
282 * argc -> How many command tokens we have
283 * idx -> The current place in the command, generally should be 0 for this
284 * function
285 * afi -> The parsed afi if it was included in the show command, returned here
286 * safi -> The parsed safi if it was included in the show command, returned here
287 * bgp -> Pointer to the bgp data structure we need to fill in.
288 *
289 * The function returns the correct location in the parse tree for the
290 * last token found.
291 *
292 * Returns 0 for failure to parse correctly, else the idx position of where
293 * it found the last token.
294 */
295 int bgp_vty_find_and_parse_afi_safi_bgp(struct vty *vty,
296 struct cmd_token **argv, int argc,
297 int *idx, afi_t *afi, safi_t *safi,
298 struct bgp **bgp)
299 {
300 char *vrf_name = NULL;
301
302 assert(afi);
303 assert(safi);
304 assert(bgp);
305
306 if (argv_find(argv, argc, "ip", idx))
307 *afi = AFI_IP;
308
309 if (argv_find(argv, argc, "view", idx)
310 || argv_find(argv, argc, "vrf", idx)) {
311 vrf_name = argv[*idx + 1]->arg;
312
313 if (strmatch(vrf_name, "all"))
314 *bgp = NULL;
315 else {
316 *bgp = bgp_lookup_by_name(vrf_name);
317 if (!*bgp) {
318 vty_out(vty,
319 "View/Vrf specified is unknown: %s\n",
320 vrf_name);
321 *idx = 0;
322 return 0;
323 }
324 }
325 } else {
326 *bgp = bgp_get_default();
327 if (!*bgp) {
328 vty_out(vty, "Unable to find default BGP instance\n");
329 *idx = 0;
330 return 0;
331 }
332 }
333
334 if (argv_find_and_parse_afi(argv, argc, idx, afi))
335 argv_find_and_parse_safi(argv, argc, idx, safi);
336
337 *idx += 1;
338 return *idx;
339 }
340
341 static int peer_address_self_check(struct bgp *bgp, union sockunion *su)
342 {
343 struct interface *ifp = NULL;
344
345 if (su->sa.sa_family == AF_INET)
346 ifp = if_lookup_by_ipv4_exact(&su->sin.sin_addr, bgp->vrf_id);
347 else if (su->sa.sa_family == AF_INET6)
348 ifp = if_lookup_by_ipv6_exact(&su->sin6.sin6_addr,
349 su->sin6.sin6_scope_id,
350 bgp->vrf_id);
351
352 if (ifp)
353 return 1;
354
355 return 0;
356 }
357
358 /* Utility function for looking up peer from VTY. */
359 /* This is used only for configuration, so disallow if attempted on
360 * a dynamic neighbor.
361 */
362 static struct peer *peer_lookup_vty(struct vty *vty, const char *ip_str)
363 {
364 struct bgp *bgp = VTY_GET_CONTEXT(bgp);
365 int ret;
366 union sockunion su;
367 struct peer *peer;
368
369 if (!bgp) {
370 return NULL;
371 }
372
373 ret = str2sockunion(ip_str, &su);
374 if (ret < 0) {
375 peer = peer_lookup_by_conf_if(bgp, ip_str);
376 if (!peer) {
377 if ((peer = peer_lookup_by_hostname(bgp, ip_str))
378 == NULL) {
379 vty_out(vty,
380 "%% Malformed address or name: %s\n",
381 ip_str);
382 return NULL;
383 }
384 }
385 } else {
386 peer = peer_lookup(bgp, &su);
387 if (!peer) {
388 vty_out(vty,
389 "%% Specify remote-as or peer-group commands first\n");
390 return NULL;
391 }
392 if (peer_dynamic_neighbor(peer)) {
393 vty_out(vty,
394 "%% Operation not allowed on a dynamic neighbor\n");
395 return NULL;
396 }
397 }
398 return peer;
399 }
400
401 /* Utility function for looking up peer or peer group. */
402 /* This is used only for configuration, so disallow if attempted on
403 * a dynamic neighbor.
404 */
405 struct peer *peer_and_group_lookup_vty(struct vty *vty, const char *peer_str)
406 {
407 struct bgp *bgp = VTY_GET_CONTEXT(bgp);
408 int ret;
409 union sockunion su;
410 struct peer *peer = NULL;
411 struct peer_group *group = NULL;
412
413 if (!bgp) {
414 return NULL;
415 }
416
417 ret = str2sockunion(peer_str, &su);
418 if (ret == 0) {
419 /* IP address, locate peer. */
420 peer = peer_lookup(bgp, &su);
421 } else {
422 /* Not IP, could match either peer configured on interface or a
423 * group. */
424 peer = peer_lookup_by_conf_if(bgp, peer_str);
425 if (!peer)
426 group = peer_group_lookup(bgp, peer_str);
427 }
428
429 if (peer) {
430 if (peer_dynamic_neighbor(peer)) {
431 vty_out(vty,
432 "%% Operation not allowed on a dynamic neighbor\n");
433 return NULL;
434 }
435
436 return peer;
437 }
438
439 if (group)
440 return group->conf;
441
442 vty_out(vty, "%% Specify remote-as or peer-group commands first\n");
443
444 return NULL;
445 }
446
447 int bgp_vty_return(struct vty *vty, int ret)
448 {
449 const char *str = NULL;
450
451 switch (ret) {
452 case BGP_ERR_INVALID_VALUE:
453 str = "Invalid value";
454 break;
455 case BGP_ERR_INVALID_FLAG:
456 str = "Invalid flag";
457 break;
458 case BGP_ERR_PEER_GROUP_SHUTDOWN:
459 str = "Peer-group has been shutdown. Activate the peer-group first";
460 break;
461 case BGP_ERR_PEER_FLAG_CONFLICT:
462 str = "Can't set override-capability and strict-capability-match at the same time";
463 break;
464 case BGP_ERR_PEER_GROUP_NO_REMOTE_AS:
465 str = "Specify remote-as or peer-group remote AS first";
466 break;
467 case BGP_ERR_PEER_GROUP_CANT_CHANGE:
468 str = "Cannot change the peer-group. Deconfigure first";
469 break;
470 case BGP_ERR_PEER_GROUP_MISMATCH:
471 str = "Peer is not a member of this peer-group";
472 break;
473 case BGP_ERR_PEER_FILTER_CONFLICT:
474 str = "Prefix/distribute list can not co-exist";
475 break;
476 case BGP_ERR_NOT_INTERNAL_PEER:
477 str = "Invalid command. Not an internal neighbor";
478 break;
479 case BGP_ERR_REMOVE_PRIVATE_AS:
480 str = "remove-private-AS cannot be configured for IBGP peers";
481 break;
482 case BGP_ERR_LOCAL_AS_ALLOWED_ONLY_FOR_EBGP:
483 str = "Local-AS allowed only for EBGP peers";
484 break;
485 case BGP_ERR_CANNOT_HAVE_LOCAL_AS_SAME_AS:
486 str = "Cannot have local-as same as BGP AS number";
487 break;
488 case BGP_ERR_TCPSIG_FAILED:
489 str = "Error while applying TCP-Sig to session(s)";
490 break;
491 case BGP_ERR_NO_EBGP_MULTIHOP_WITH_TTLHACK:
492 str = "ebgp-multihop and ttl-security cannot be configured together";
493 break;
494 case BGP_ERR_NO_IBGP_WITH_TTLHACK:
495 str = "ttl-security only allowed for EBGP peers";
496 break;
497 case BGP_ERR_AS_OVERRIDE:
498 str = "as-override cannot be configured for IBGP peers";
499 break;
500 case BGP_ERR_INVALID_DYNAMIC_NEIGHBORS_LIMIT:
501 str = "Invalid limit for number of dynamic neighbors";
502 break;
503 case BGP_ERR_DYNAMIC_NEIGHBORS_RANGE_EXISTS:
504 str = "Dynamic neighbor listen range already exists";
505 break;
506 case BGP_ERR_INVALID_FOR_DYNAMIC_PEER:
507 str = "Operation not allowed on a dynamic neighbor";
508 break;
509 case BGP_ERR_INVALID_FOR_DIRECT_PEER:
510 str = "Operation not allowed on a directly connected neighbor";
511 break;
512 case BGP_ERR_PEER_SAFI_CONFLICT:
513 str = "Cannot activate peer for both 'ipv4 unicast' and 'ipv4 labeled-unicast'";
514 break;
515 }
516 if (str) {
517 vty_out(vty, "%% %s\n", str);
518 return CMD_WARNING_CONFIG_FAILED;
519 }
520 return CMD_SUCCESS;
521 }
522
523 /* BGP clear sort. */
524 enum clear_sort {
525 clear_all,
526 clear_peer,
527 clear_group,
528 clear_external,
529 clear_as
530 };
531
532 static void bgp_clear_vty_error(struct vty *vty, struct peer *peer, afi_t afi,
533 safi_t safi, int error)
534 {
535 switch (error) {
536 case BGP_ERR_AF_UNCONFIGURED:
537 vty_out(vty,
538 "%%BGP: Enable %s address family for the neighbor %s\n",
539 afi_safi_print(afi, safi), peer->host);
540 break;
541 case BGP_ERR_SOFT_RECONFIG_UNCONFIGURED:
542 vty_out(vty,
543 "%%BGP: Inbound soft reconfig for %s not possible as it\n has neither refresh capability, nor inbound soft reconfig\n",
544 peer->host);
545 break;
546 default:
547 break;
548 }
549 }
550
551 /* `clear ip bgp' functions. */
552 static int bgp_clear(struct vty *vty, struct bgp *bgp, afi_t afi, safi_t safi,
553 enum clear_sort sort, enum bgp_clear_type stype,
554 const char *arg)
555 {
556 int ret;
557 bool found = false;
558 struct peer *peer;
559 struct listnode *node, *nnode;
560
561 /* Clear all neighbors. */
562 /*
563 * Pass along pointer to next node to peer_clear() when walking all
564 * nodes on the BGP instance as that may get freed if it is a
565 * doppelganger
566 */
567 if (sort == clear_all) {
568 for (ALL_LIST_ELEMENTS(bgp->peer, node, nnode, peer)) {
569 if (!peer->afc[afi][safi])
570 continue;
571
572 if (stype == BGP_CLEAR_SOFT_NONE)
573 ret = peer_clear(peer, &nnode);
574 else
575 ret = peer_clear_soft(peer, afi, safi, stype);
576
577 if (ret < 0)
578 bgp_clear_vty_error(vty, peer, afi, safi, ret);
579 else
580 found = true;
581 }
582
583 /* This is to apply read-only mode on this clear. */
584 if (stype == BGP_CLEAR_SOFT_NONE)
585 bgp->update_delay_over = 0;
586
587 if (!found)
588 vty_out(vty, "%%BGP: No %s peer configured",
589 afi_safi_print(afi, safi));
590
591 return CMD_SUCCESS;
592 }
593
594 /* Clear specified neighbor. */
595 if (sort == clear_peer) {
596 union sockunion su;
597
598 /* Make sockunion for lookup. */
599 ret = str2sockunion(arg, &su);
600 if (ret < 0) {
601 peer = peer_lookup_by_conf_if(bgp, arg);
602 if (!peer) {
603 peer = peer_lookup_by_hostname(bgp, arg);
604 if (!peer) {
605 vty_out(vty,
606 "Malformed address or name: %s\n",
607 arg);
608 return CMD_WARNING;
609 }
610 }
611 } else {
612 peer = peer_lookup(bgp, &su);
613 if (!peer) {
614 vty_out(vty,
615 "%%BGP: Unknown neighbor - \"%s\"\n",
616 arg);
617 return CMD_WARNING;
618 }
619 }
620
621 if (!peer->afc[afi][safi])
622 ret = BGP_ERR_AF_UNCONFIGURED;
623 else if (stype == BGP_CLEAR_SOFT_NONE)
624 ret = peer_clear(peer, NULL);
625 else
626 ret = peer_clear_soft(peer, afi, safi, stype);
627
628 if (ret < 0)
629 bgp_clear_vty_error(vty, peer, afi, safi, ret);
630
631 return CMD_SUCCESS;
632 }
633
634 /* Clear all neighbors belonging to a specific peer-group. */
635 if (sort == clear_group) {
636 struct peer_group *group;
637
638 group = peer_group_lookup(bgp, arg);
639 if (!group) {
640 vty_out(vty, "%%BGP: No such peer-group %s\n", arg);
641 return CMD_WARNING;
642 }
643
644 for (ALL_LIST_ELEMENTS(group->peer, node, nnode, peer)) {
645 if (!peer->afc[afi][safi])
646 continue;
647
648 if (stype == BGP_CLEAR_SOFT_NONE)
649 ret = peer_clear(peer, NULL);
650 else
651 ret = peer_clear_soft(peer, afi, safi, stype);
652
653 if (ret < 0)
654 bgp_clear_vty_error(vty, peer, afi, safi, ret);
655 else
656 found = true;
657 }
658
659 if (!found)
660 vty_out(vty,
661 "%%BGP: No %s peer belonging to peer-group %s is configured\n",
662 afi_safi_print(afi, safi), arg);
663
664 return CMD_SUCCESS;
665 }
666
667 /* Clear all external (eBGP) neighbors. */
668 if (sort == clear_external) {
669 for (ALL_LIST_ELEMENTS(bgp->peer, node, nnode, peer)) {
670 if (peer->sort == BGP_PEER_IBGP)
671 continue;
672
673 if (!peer->afc[afi][safi])
674 continue;
675
676 if (stype == BGP_CLEAR_SOFT_NONE)
677 ret = peer_clear(peer, &nnode);
678 else
679 ret = peer_clear_soft(peer, afi, safi, stype);
680
681 if (ret < 0)
682 bgp_clear_vty_error(vty, peer, afi, safi, ret);
683 else
684 found = true;
685 }
686
687 if (!found)
688 vty_out(vty,
689 "%%BGP: No external %s peer is configured\n",
690 afi_safi_print(afi, safi));
691
692 return CMD_SUCCESS;
693 }
694
695 /* Clear all neighbors belonging to a specific AS. */
696 if (sort == clear_as) {
697 as_t as = strtoul(arg, NULL, 10);
698
699 for (ALL_LIST_ELEMENTS(bgp->peer, node, nnode, peer)) {
700 if (peer->as != as)
701 continue;
702
703 if (!peer->afc[afi][safi])
704 ret = BGP_ERR_AF_UNCONFIGURED;
705 else if (stype == BGP_CLEAR_SOFT_NONE)
706 ret = peer_clear(peer, &nnode);
707 else
708 ret = peer_clear_soft(peer, afi, safi, stype);
709
710 if (ret < 0)
711 bgp_clear_vty_error(vty, peer, afi, safi, ret);
712 else
713 found = true;
714 }
715
716 if (!found)
717 vty_out(vty,
718 "%%BGP: No %s peer is configured with AS %s\n",
719 afi_safi_print(afi, safi), arg);
720
721 return CMD_SUCCESS;
722 }
723
724 return CMD_SUCCESS;
725 }
726
727 static int bgp_clear_vty(struct vty *vty, const char *name, afi_t afi,
728 safi_t safi, enum clear_sort sort,
729 enum bgp_clear_type stype, const char *arg)
730 {
731 struct bgp *bgp;
732
733 /* BGP structure lookup. */
734 if (name) {
735 bgp = bgp_lookup_by_name(name);
736 if (bgp == NULL) {
737 vty_out(vty, "Can't find BGP instance %s\n", name);
738 return CMD_WARNING;
739 }
740 } else {
741 bgp = bgp_get_default();
742 if (bgp == NULL) {
743 vty_out(vty, "No BGP process is configured\n");
744 return CMD_WARNING;
745 }
746 }
747
748 return bgp_clear(vty, bgp, afi, safi, sort, stype, arg);
749 }
750
751 /* clear soft inbound */
752 static void bgp_clear_star_soft_in(struct vty *vty, const char *name)
753 {
754 bgp_clear_vty(vty, name, AFI_IP, SAFI_UNICAST, clear_all,
755 BGP_CLEAR_SOFT_IN, NULL);
756 bgp_clear_vty(vty, name, AFI_IP6, SAFI_UNICAST, clear_all,
757 BGP_CLEAR_SOFT_IN, NULL);
758 }
759
760 /* clear soft outbound */
761 static void bgp_clear_star_soft_out(struct vty *vty, const char *name)
762 {
763 bgp_clear_vty(vty, name, AFI_IP, SAFI_UNICAST, clear_all,
764 BGP_CLEAR_SOFT_OUT, NULL);
765 bgp_clear_vty(vty, name, AFI_IP6, SAFI_UNICAST, clear_all,
766 BGP_CLEAR_SOFT_OUT, NULL);
767 }
768
769
770 #ifndef VTYSH_EXTRACT_PL
771 #include "bgpd/bgp_vty_clippy.c"
772 #endif
773
774 /* BGP global configuration. */
775 #if defined(VERSION_TYPE_DEV) && (CONFDATE > 20190601)
776 CPP_NOTICE("bgpd: time to remove deprecated bgp multiple-instance")
777 CPP_NOTICE("This includes BGP_OPT_MULTIPLE_INSTANCE")
778 #endif
779 DEFUN_HIDDEN (bgp_multiple_instance_func,
780 bgp_multiple_instance_cmd,
781 "bgp multiple-instance",
782 BGP_STR
783 "Enable bgp multiple instance\n")
784 {
785 bgp_option_set(BGP_OPT_MULTIPLE_INSTANCE);
786 return CMD_SUCCESS;
787 }
788
789 DEFUN_HIDDEN (no_bgp_multiple_instance,
790 no_bgp_multiple_instance_cmd,
791 "no bgp multiple-instance",
792 NO_STR
793 BGP_STR
794 "BGP multiple instance\n")
795 {
796 int ret;
797
798 vty_out(vty, "This config option is deprecated, and is scheduled for removal.\n");
799 vty_out(vty, "if you are using this please let the developers know\n");
800 zlog_warn("Deprecated option: `bgp multiple-instance` being used");
801 ret = bgp_option_unset(BGP_OPT_MULTIPLE_INSTANCE);
802 if (ret < 0) {
803 vty_out(vty, "%% There are more than two BGP instances\n");
804 return CMD_WARNING_CONFIG_FAILED;
805 }
806 return CMD_SUCCESS;
807 }
808
809 #if defined(VERSION_TYPE_DEV) && (CONFDATE > 20190601)
810 CPP_NOTICE("bgpd: time to remove deprecated cli bgp config-type cisco")
811 CPP_NOTICE("This includes BGP_OPT_CISCO_CONFIG")
812 #endif
813 DEFUN_HIDDEN (bgp_config_type,
814 bgp_config_type_cmd,
815 "bgp config-type <cisco|zebra>",
816 BGP_STR
817 "Configuration type\n"
818 "cisco\n"
819 "zebra\n")
820 {
821 int idx = 0;
822 if (argv_find(argv, argc, "cisco", &idx)) {
823 vty_out(vty, "This config option is deprecated, and is scheduled for removal.\n");
824 vty_out(vty, "if you are using this please let the developers know!\n");
825 zlog_warn("Deprecated option: `bgp config-type cisco` being used");
826 bgp_option_set(BGP_OPT_CONFIG_CISCO);
827 } else
828 bgp_option_unset(BGP_OPT_CONFIG_CISCO);
829
830 return CMD_SUCCESS;
831 }
832
833 DEFUN_HIDDEN (no_bgp_config_type,
834 no_bgp_config_type_cmd,
835 "no bgp config-type [<cisco|zebra>]",
836 NO_STR
837 BGP_STR
838 "Display configuration type\n"
839 "cisco\n"
840 "zebra\n")
841 {
842 bgp_option_unset(BGP_OPT_CONFIG_CISCO);
843 return CMD_SUCCESS;
844 }
845
846
847 DEFUN (no_synchronization,
848 no_synchronization_cmd,
849 "no synchronization",
850 NO_STR
851 "Perform IGP synchronization\n")
852 {
853 return CMD_SUCCESS;
854 }
855
856 DEFUN (no_auto_summary,
857 no_auto_summary_cmd,
858 "no auto-summary",
859 NO_STR
860 "Enable automatic network number summarization\n")
861 {
862 return CMD_SUCCESS;
863 }
864
865 /* "router bgp" commands. */
866 DEFUN_NOSH (router_bgp,
867 router_bgp_cmd,
868 "router bgp [(1-4294967295) [<view|vrf> VIEWVRFNAME]]",
869 ROUTER_STR
870 BGP_STR
871 AS_STR
872 BGP_INSTANCE_HELP_STR)
873 {
874 int idx_asn = 2;
875 int idx_view_vrf = 3;
876 int idx_vrf = 4;
877 int ret;
878 as_t as;
879 struct bgp *bgp;
880 const char *name = NULL;
881 enum bgp_instance_type inst_type;
882
883 // "router bgp" without an ASN
884 if (argc == 2) {
885 // Pending: Make VRF option available for ASN less config
886 bgp = bgp_get_default();
887
888 if (bgp == NULL) {
889 vty_out(vty, "%% No BGP process is configured\n");
890 return CMD_WARNING_CONFIG_FAILED;
891 }
892
893 if (listcount(bm->bgp) > 1) {
894 vty_out(vty, "%% Please specify ASN and VRF\n");
895 return CMD_WARNING_CONFIG_FAILED;
896 }
897 }
898
899 // "router bgp X"
900 else {
901 as = strtoul(argv[idx_asn]->arg, NULL, 10);
902
903 inst_type = BGP_INSTANCE_TYPE_DEFAULT;
904 if (argc > 3) {
905 name = argv[idx_vrf]->arg;
906
907 if (!strcmp(argv[idx_view_vrf]->text, "vrf"))
908 inst_type = BGP_INSTANCE_TYPE_VRF;
909 else if (!strcmp(argv[idx_view_vrf]->text, "view"))
910 inst_type = BGP_INSTANCE_TYPE_VIEW;
911 }
912
913 ret = bgp_get(&bgp, &as, name, inst_type);
914 switch (ret) {
915 case BGP_ERR_MULTIPLE_INSTANCE_NOT_SET:
916 vty_out(vty,
917 "Please specify 'bgp multiple-instance' first\n");
918 return CMD_WARNING_CONFIG_FAILED;
919 case BGP_ERR_AS_MISMATCH:
920 vty_out(vty, "BGP is already running; AS is %u\n", as);
921 return CMD_WARNING_CONFIG_FAILED;
922 case BGP_ERR_INSTANCE_MISMATCH:
923 vty_out(vty,
924 "BGP instance name and AS number mismatch\n");
925 vty_out(vty,
926 "BGP instance is already running; AS is %u\n",
927 as);
928 return CMD_WARNING_CONFIG_FAILED;
929 }
930
931 /*
932 * If we just instantiated the default instance, complete
933 * any pending VRF-VPN leaking that was configured via
934 * earlier "router bgp X vrf FOO" blocks.
935 */
936 if (inst_type == BGP_INSTANCE_TYPE_DEFAULT)
937 vpn_leak_postchange_all();
938
939 /* Pending: handle when user tries to change a view to vrf n vv.
940 */
941 }
942
943 /* unset the auto created flag as the user config is now present */
944 UNSET_FLAG(bgp->vrf_flags, BGP_VRF_AUTO);
945 VTY_PUSH_CONTEXT(BGP_NODE, bgp);
946
947 return CMD_SUCCESS;
948 }
949
950 /* "no router bgp" commands. */
951 DEFUN (no_router_bgp,
952 no_router_bgp_cmd,
953 "no router bgp [(1-4294967295) [<view|vrf> VIEWVRFNAME]]",
954 NO_STR
955 ROUTER_STR
956 BGP_STR
957 AS_STR
958 BGP_INSTANCE_HELP_STR)
959 {
960 int idx_asn = 3;
961 int idx_vrf = 5;
962 as_t as;
963 struct bgp *bgp;
964 const char *name = NULL;
965
966 // "no router bgp" without an ASN
967 if (argc == 3) {
968 // Pending: Make VRF option available for ASN less config
969 bgp = bgp_get_default();
970
971 if (bgp == NULL) {
972 vty_out(vty, "%% No BGP process is configured\n");
973 return CMD_WARNING_CONFIG_FAILED;
974 }
975
976 if (listcount(bm->bgp) > 1) {
977 vty_out(vty, "%% Please specify ASN and VRF\n");
978 return CMD_WARNING_CONFIG_FAILED;
979 }
980
981 if (bgp->l3vni) {
982 vty_out(vty, "%% Please unconfigure l3vni %u",
983 bgp->l3vni);
984 return CMD_WARNING_CONFIG_FAILED;
985 }
986 } else {
987 as = strtoul(argv[idx_asn]->arg, NULL, 10);
988
989 if (argc > 4)
990 name = argv[idx_vrf]->arg;
991
992 /* Lookup bgp structure. */
993 bgp = bgp_lookup(as, name);
994 if (!bgp) {
995 vty_out(vty, "%% Can't find BGP instance\n");
996 return CMD_WARNING_CONFIG_FAILED;
997 }
998
999 if (bgp->l3vni) {
1000 vty_out(vty, "%% Please unconfigure l3vni %u",
1001 bgp->l3vni);
1002 return CMD_WARNING_CONFIG_FAILED;
1003 }
1004 }
1005
1006 bgp_delete(bgp);
1007
1008 return CMD_SUCCESS;
1009 }
1010
1011
1012 /* BGP router-id. */
1013
1014 DEFPY (bgp_router_id,
1015 bgp_router_id_cmd,
1016 "bgp router-id A.B.C.D",
1017 BGP_STR
1018 "Override configured router identifier\n"
1019 "Manually configured router identifier\n")
1020 {
1021 VTY_DECLVAR_CONTEXT(bgp, bgp);
1022 bgp_router_id_static_set(bgp, router_id);
1023 return CMD_SUCCESS;
1024 }
1025
1026 DEFPY (no_bgp_router_id,
1027 no_bgp_router_id_cmd,
1028 "no bgp router-id [A.B.C.D]",
1029 NO_STR
1030 BGP_STR
1031 "Override configured router identifier\n"
1032 "Manually configured router identifier\n")
1033 {
1034 VTY_DECLVAR_CONTEXT(bgp, bgp);
1035
1036 if (router_id_str) {
1037 if (!IPV4_ADDR_SAME(&bgp->router_id_static, &router_id)) {
1038 vty_out(vty, "%% BGP router-id doesn't match\n");
1039 return CMD_WARNING_CONFIG_FAILED;
1040 }
1041 }
1042
1043 router_id.s_addr = 0;
1044 bgp_router_id_static_set(bgp, router_id);
1045
1046 return CMD_SUCCESS;
1047 }
1048
1049
1050 /* BGP Cluster ID. */
1051 DEFUN (bgp_cluster_id,
1052 bgp_cluster_id_cmd,
1053 "bgp cluster-id <A.B.C.D|(1-4294967295)>",
1054 BGP_STR
1055 "Configure Route-Reflector Cluster-id\n"
1056 "Route-Reflector Cluster-id in IP address format\n"
1057 "Route-Reflector Cluster-id as 32 bit quantity\n")
1058 {
1059 VTY_DECLVAR_CONTEXT(bgp, bgp);
1060 int idx_ipv4 = 2;
1061 int ret;
1062 struct in_addr cluster;
1063
1064 ret = inet_aton(argv[idx_ipv4]->arg, &cluster);
1065 if (!ret) {
1066 vty_out(vty, "%% Malformed bgp cluster identifier\n");
1067 return CMD_WARNING_CONFIG_FAILED;
1068 }
1069
1070 bgp_cluster_id_set(bgp, &cluster);
1071 bgp_clear_star_soft_out(vty, bgp->name);
1072
1073 return CMD_SUCCESS;
1074 }
1075
1076 DEFUN (no_bgp_cluster_id,
1077 no_bgp_cluster_id_cmd,
1078 "no bgp cluster-id [<A.B.C.D|(1-4294967295)>]",
1079 NO_STR
1080 BGP_STR
1081 "Configure Route-Reflector Cluster-id\n"
1082 "Route-Reflector Cluster-id in IP address format\n"
1083 "Route-Reflector Cluster-id as 32 bit quantity\n")
1084 {
1085 VTY_DECLVAR_CONTEXT(bgp, bgp);
1086 bgp_cluster_id_unset(bgp);
1087 bgp_clear_star_soft_out(vty, bgp->name);
1088
1089 return CMD_SUCCESS;
1090 }
1091
1092 DEFUN (bgp_confederation_identifier,
1093 bgp_confederation_identifier_cmd,
1094 "bgp confederation identifier (1-4294967295)",
1095 "BGP specific commands\n"
1096 "AS confederation parameters\n"
1097 "AS number\n"
1098 "Set routing domain confederation AS\n")
1099 {
1100 VTY_DECLVAR_CONTEXT(bgp, bgp);
1101 int idx_number = 3;
1102 as_t as;
1103
1104 as = strtoul(argv[idx_number]->arg, NULL, 10);
1105
1106 bgp_confederation_id_set(bgp, as);
1107
1108 return CMD_SUCCESS;
1109 }
1110
1111 DEFUN (no_bgp_confederation_identifier,
1112 no_bgp_confederation_identifier_cmd,
1113 "no bgp confederation identifier [(1-4294967295)]",
1114 NO_STR
1115 "BGP specific commands\n"
1116 "AS confederation parameters\n"
1117 "AS number\n"
1118 "Set routing domain confederation AS\n")
1119 {
1120 VTY_DECLVAR_CONTEXT(bgp, bgp);
1121 bgp_confederation_id_unset(bgp);
1122
1123 return CMD_SUCCESS;
1124 }
1125
1126 DEFUN (bgp_confederation_peers,
1127 bgp_confederation_peers_cmd,
1128 "bgp confederation peers (1-4294967295)...",
1129 "BGP specific commands\n"
1130 "AS confederation parameters\n"
1131 "Peer ASs in BGP confederation\n"
1132 AS_STR)
1133 {
1134 VTY_DECLVAR_CONTEXT(bgp, bgp);
1135 int idx_asn = 3;
1136 as_t as;
1137 int i;
1138
1139 for (i = idx_asn; i < argc; i++) {
1140 as = strtoul(argv[i]->arg, NULL, 10);
1141
1142 if (bgp->as == as) {
1143 vty_out(vty,
1144 "%% Local member-AS not allowed in confed peer list\n");
1145 continue;
1146 }
1147
1148 bgp_confederation_peers_add(bgp, as);
1149 }
1150 return CMD_SUCCESS;
1151 }
1152
1153 DEFUN (no_bgp_confederation_peers,
1154 no_bgp_confederation_peers_cmd,
1155 "no bgp confederation peers (1-4294967295)...",
1156 NO_STR
1157 "BGP specific commands\n"
1158 "AS confederation parameters\n"
1159 "Peer ASs in BGP confederation\n"
1160 AS_STR)
1161 {
1162 VTY_DECLVAR_CONTEXT(bgp, bgp);
1163 int idx_asn = 4;
1164 as_t as;
1165 int i;
1166
1167 for (i = idx_asn; i < argc; i++) {
1168 as = strtoul(argv[i]->arg, NULL, 10);
1169
1170 bgp_confederation_peers_remove(bgp, as);
1171 }
1172 return CMD_SUCCESS;
1173 }
1174
1175 /**
1176 * Central routine for maximum-paths configuration.
1177 * @peer_type: BGP_PEER_EBGP or BGP_PEER_IBGP
1178 * @set: 1 for setting values, 0 for removing the max-paths config.
1179 */
1180 static int bgp_maxpaths_config_vty(struct vty *vty, int peer_type,
1181 const char *mpaths, uint16_t options,
1182 int set)
1183 {
1184 VTY_DECLVAR_CONTEXT(bgp, bgp);
1185 uint16_t maxpaths = 0;
1186 int ret;
1187 afi_t afi;
1188 safi_t safi;
1189
1190 afi = bgp_node_afi(vty);
1191 safi = bgp_node_safi(vty);
1192
1193 if (set) {
1194 maxpaths = strtol(mpaths, NULL, 10);
1195 if (maxpaths > multipath_num) {
1196 vty_out(vty,
1197 "%% Maxpaths Specified: %d is > than multipath num specified on bgp command line %d",
1198 maxpaths, multipath_num);
1199 return CMD_WARNING_CONFIG_FAILED;
1200 }
1201 ret = bgp_maximum_paths_set(bgp, afi, safi, peer_type, maxpaths,
1202 options);
1203 } else
1204 ret = bgp_maximum_paths_unset(bgp, afi, safi, peer_type);
1205
1206 if (ret < 0) {
1207 vty_out(vty,
1208 "%% Failed to %sset maximum-paths %s %u for afi %u, safi %u\n",
1209 (set == 1) ? "" : "un",
1210 (peer_type == BGP_PEER_EBGP) ? "ebgp" : "ibgp",
1211 maxpaths, afi, safi);
1212 return CMD_WARNING_CONFIG_FAILED;
1213 }
1214
1215 bgp_recalculate_all_bestpaths(bgp);
1216
1217 return CMD_SUCCESS;
1218 }
1219
1220 DEFUN (bgp_maxmed_admin,
1221 bgp_maxmed_admin_cmd,
1222 "bgp max-med administrative ",
1223 BGP_STR
1224 "Advertise routes with max-med\n"
1225 "Administratively applied, for an indefinite period\n")
1226 {
1227 VTY_DECLVAR_CONTEXT(bgp, bgp);
1228
1229 bgp->v_maxmed_admin = 1;
1230 bgp->maxmed_admin_value = BGP_MAXMED_VALUE_DEFAULT;
1231
1232 bgp_maxmed_update(bgp);
1233
1234 return CMD_SUCCESS;
1235 }
1236
1237 DEFUN (bgp_maxmed_admin_medv,
1238 bgp_maxmed_admin_medv_cmd,
1239 "bgp max-med administrative (0-4294967295)",
1240 BGP_STR
1241 "Advertise routes with max-med\n"
1242 "Administratively applied, for an indefinite period\n"
1243 "Max MED value to be used\n")
1244 {
1245 VTY_DECLVAR_CONTEXT(bgp, bgp);
1246 int idx_number = 3;
1247
1248 bgp->v_maxmed_admin = 1;
1249 bgp->maxmed_admin_value = strtoul(argv[idx_number]->arg, NULL, 10);
1250
1251 bgp_maxmed_update(bgp);
1252
1253 return CMD_SUCCESS;
1254 }
1255
1256 DEFUN (no_bgp_maxmed_admin,
1257 no_bgp_maxmed_admin_cmd,
1258 "no bgp max-med administrative [(0-4294967295)]",
1259 NO_STR
1260 BGP_STR
1261 "Advertise routes with max-med\n"
1262 "Administratively applied, for an indefinite period\n"
1263 "Max MED value to be used\n")
1264 {
1265 VTY_DECLVAR_CONTEXT(bgp, bgp);
1266 bgp->v_maxmed_admin = BGP_MAXMED_ADMIN_UNCONFIGURED;
1267 bgp->maxmed_admin_value = BGP_MAXMED_VALUE_DEFAULT;
1268 bgp_maxmed_update(bgp);
1269
1270 return CMD_SUCCESS;
1271 }
1272
1273 DEFUN (bgp_maxmed_onstartup,
1274 bgp_maxmed_onstartup_cmd,
1275 "bgp max-med on-startup (5-86400) [(0-4294967295)]",
1276 BGP_STR
1277 "Advertise routes with max-med\n"
1278 "Effective on a startup\n"
1279 "Time (seconds) period for max-med\n"
1280 "Max MED value to be used\n")
1281 {
1282 VTY_DECLVAR_CONTEXT(bgp, bgp);
1283 int idx = 0;
1284
1285 argv_find(argv, argc, "(5-86400)", &idx);
1286 bgp->v_maxmed_onstartup = strtoul(argv[idx]->arg, NULL, 10);
1287 if (argv_find(argv, argc, "(0-4294967295)", &idx))
1288 bgp->maxmed_onstartup_value = strtoul(argv[idx]->arg, NULL, 10);
1289 else
1290 bgp->maxmed_onstartup_value = BGP_MAXMED_VALUE_DEFAULT;
1291
1292 bgp_maxmed_update(bgp);
1293
1294 return CMD_SUCCESS;
1295 }
1296
1297 DEFUN (no_bgp_maxmed_onstartup,
1298 no_bgp_maxmed_onstartup_cmd,
1299 "no bgp max-med on-startup [(5-86400) [(0-4294967295)]]",
1300 NO_STR
1301 BGP_STR
1302 "Advertise routes with max-med\n"
1303 "Effective on a startup\n"
1304 "Time (seconds) period for max-med\n"
1305 "Max MED value to be used\n")
1306 {
1307 VTY_DECLVAR_CONTEXT(bgp, bgp);
1308
1309 /* Cancel max-med onstartup if its on */
1310 if (bgp->t_maxmed_onstartup) {
1311 THREAD_TIMER_OFF(bgp->t_maxmed_onstartup);
1312 bgp->maxmed_onstartup_over = 1;
1313 }
1314
1315 bgp->v_maxmed_onstartup = BGP_MAXMED_ONSTARTUP_UNCONFIGURED;
1316 bgp->maxmed_onstartup_value = BGP_MAXMED_VALUE_DEFAULT;
1317
1318 bgp_maxmed_update(bgp);
1319
1320 return CMD_SUCCESS;
1321 }
1322
1323 static int bgp_update_delay_config_vty(struct vty *vty, const char *delay,
1324 const char *wait)
1325 {
1326 VTY_DECLVAR_CONTEXT(bgp, bgp);
1327 uint16_t update_delay;
1328 uint16_t establish_wait;
1329
1330 update_delay = strtoul(delay, NULL, 10);
1331
1332 if (!wait) /* update-delay <delay> */
1333 {
1334 bgp->v_update_delay = update_delay;
1335 bgp->v_establish_wait = bgp->v_update_delay;
1336 return CMD_SUCCESS;
1337 }
1338
1339 /* update-delay <delay> <establish-wait> */
1340 establish_wait = atoi(wait);
1341 if (update_delay < establish_wait) {
1342 vty_out(vty,
1343 "%%Failed: update-delay less than the establish-wait!\n");
1344 return CMD_WARNING_CONFIG_FAILED;
1345 }
1346
1347 bgp->v_update_delay = update_delay;
1348 bgp->v_establish_wait = establish_wait;
1349
1350 return CMD_SUCCESS;
1351 }
1352
1353 static int bgp_update_delay_deconfig_vty(struct vty *vty)
1354 {
1355 VTY_DECLVAR_CONTEXT(bgp, bgp);
1356
1357 bgp->v_update_delay = BGP_UPDATE_DELAY_DEF;
1358 bgp->v_establish_wait = bgp->v_update_delay;
1359
1360 return CMD_SUCCESS;
1361 }
1362
1363 void bgp_config_write_update_delay(struct vty *vty, struct bgp *bgp)
1364 {
1365 if (bgp->v_update_delay != BGP_UPDATE_DELAY_DEF) {
1366 vty_out(vty, " update-delay %d", bgp->v_update_delay);
1367 if (bgp->v_update_delay != bgp->v_establish_wait)
1368 vty_out(vty, " %d", bgp->v_establish_wait);
1369 vty_out(vty, "\n");
1370 }
1371 }
1372
1373
1374 /* Update-delay configuration */
1375 DEFUN (bgp_update_delay,
1376 bgp_update_delay_cmd,
1377 "update-delay (0-3600)",
1378 "Force initial delay for best-path and updates\n"
1379 "Seconds\n")
1380 {
1381 int idx_number = 1;
1382 return bgp_update_delay_config_vty(vty, argv[idx_number]->arg, NULL);
1383 }
1384
1385 DEFUN (bgp_update_delay_establish_wait,
1386 bgp_update_delay_establish_wait_cmd,
1387 "update-delay (0-3600) (1-3600)",
1388 "Force initial delay for best-path and updates\n"
1389 "Seconds\n"
1390 "Seconds\n")
1391 {
1392 int idx_number = 1;
1393 int idx_number_2 = 2;
1394 return bgp_update_delay_config_vty(vty, argv[idx_number]->arg,
1395 argv[idx_number_2]->arg);
1396 }
1397
1398 /* Update-delay deconfiguration */
1399 DEFUN (no_bgp_update_delay,
1400 no_bgp_update_delay_cmd,
1401 "no update-delay [(0-3600) [(1-3600)]]",
1402 NO_STR
1403 "Force initial delay for best-path and updates\n"
1404 "Seconds\n"
1405 "Seconds\n")
1406 {
1407 return bgp_update_delay_deconfig_vty(vty);
1408 }
1409
1410
1411 static int bgp_wpkt_quanta_config_vty(struct vty *vty, const char *num,
1412 char set)
1413 {
1414 VTY_DECLVAR_CONTEXT(bgp, bgp);
1415
1416 if (set) {
1417 uint32_t quanta = strtoul(num, NULL, 10);
1418 atomic_store_explicit(&bgp->wpkt_quanta, quanta,
1419 memory_order_relaxed);
1420 } else {
1421 atomic_store_explicit(&bgp->wpkt_quanta, BGP_WRITE_PACKET_MAX,
1422 memory_order_relaxed);
1423 }
1424
1425 return CMD_SUCCESS;
1426 }
1427
1428 static int bgp_rpkt_quanta_config_vty(struct vty *vty, const char *num,
1429 char set)
1430 {
1431 VTY_DECLVAR_CONTEXT(bgp, bgp);
1432
1433 if (set) {
1434 uint32_t quanta = strtoul(num, NULL, 10);
1435 atomic_store_explicit(&bgp->rpkt_quanta, quanta,
1436 memory_order_relaxed);
1437 } else {
1438 atomic_store_explicit(&bgp->rpkt_quanta, BGP_READ_PACKET_MAX,
1439 memory_order_relaxed);
1440 }
1441
1442 return CMD_SUCCESS;
1443 }
1444
1445 void bgp_config_write_wpkt_quanta(struct vty *vty, struct bgp *bgp)
1446 {
1447 uint32_t quanta =
1448 atomic_load_explicit(&bgp->wpkt_quanta, memory_order_relaxed);
1449 if (quanta != BGP_WRITE_PACKET_MAX)
1450 vty_out(vty, " write-quanta %d\n", quanta);
1451 }
1452
1453 void bgp_config_write_rpkt_quanta(struct vty *vty, struct bgp *bgp)
1454 {
1455 uint32_t quanta =
1456 atomic_load_explicit(&bgp->rpkt_quanta, memory_order_relaxed);
1457 if (quanta != BGP_READ_PACKET_MAX)
1458 vty_out(vty, " read-quanta %d\n", quanta);
1459 }
1460
1461 /* Packet quanta configuration */
1462 DEFUN (bgp_wpkt_quanta,
1463 bgp_wpkt_quanta_cmd,
1464 "write-quanta (1-10)",
1465 "How many packets to write to peer socket per run\n"
1466 "Number of packets\n")
1467 {
1468 int idx_number = 1;
1469 return bgp_wpkt_quanta_config_vty(vty, argv[idx_number]->arg, 1);
1470 }
1471
1472 DEFUN (no_bgp_wpkt_quanta,
1473 no_bgp_wpkt_quanta_cmd,
1474 "no write-quanta (1-10)",
1475 NO_STR
1476 "How many packets to write to peer socket per I/O cycle\n"
1477 "Number of packets\n")
1478 {
1479 int idx_number = 2;
1480 return bgp_wpkt_quanta_config_vty(vty, argv[idx_number]->arg, 0);
1481 }
1482
1483 DEFUN (bgp_rpkt_quanta,
1484 bgp_rpkt_quanta_cmd,
1485 "read-quanta (1-10)",
1486 "How many packets to read from peer socket per I/O cycle\n"
1487 "Number of packets\n")
1488 {
1489 int idx_number = 1;
1490 return bgp_rpkt_quanta_config_vty(vty, argv[idx_number]->arg, 1);
1491 }
1492
1493 DEFUN (no_bgp_rpkt_quanta,
1494 no_bgp_rpkt_quanta_cmd,
1495 "no read-quanta (1-10)",
1496 NO_STR
1497 "How many packets to read from peer socket per I/O cycle\n"
1498 "Number of packets\n")
1499 {
1500 int idx_number = 2;
1501 return bgp_rpkt_quanta_config_vty(vty, argv[idx_number]->arg, 0);
1502 }
1503
1504 void bgp_config_write_coalesce_time(struct vty *vty, struct bgp *bgp)
1505 {
1506 if (!bgp->heuristic_coalesce)
1507 vty_out(vty, " coalesce-time %u\n", bgp->coalesce_time);
1508 }
1509
1510
1511 DEFUN (bgp_coalesce_time,
1512 bgp_coalesce_time_cmd,
1513 "coalesce-time (0-4294967295)",
1514 "Subgroup coalesce timer\n"
1515 "Subgroup coalesce timer value (in ms)\n")
1516 {
1517 VTY_DECLVAR_CONTEXT(bgp, bgp);
1518
1519 int idx = 0;
1520 argv_find(argv, argc, "(0-4294967295)", &idx);
1521 bgp->heuristic_coalesce = false;
1522 bgp->coalesce_time = strtoul(argv[idx]->arg, NULL, 10);
1523 return CMD_SUCCESS;
1524 }
1525
1526 DEFUN (no_bgp_coalesce_time,
1527 no_bgp_coalesce_time_cmd,
1528 "no coalesce-time (0-4294967295)",
1529 NO_STR
1530 "Subgroup coalesce timer\n"
1531 "Subgroup coalesce timer value (in ms)\n")
1532 {
1533 VTY_DECLVAR_CONTEXT(bgp, bgp);
1534
1535 bgp->heuristic_coalesce = true;
1536 bgp->coalesce_time = BGP_DEFAULT_SUBGROUP_COALESCE_TIME;
1537 return CMD_SUCCESS;
1538 }
1539
1540 /* Maximum-paths configuration */
1541 DEFUN (bgp_maxpaths,
1542 bgp_maxpaths_cmd,
1543 "maximum-paths " CMD_RANGE_STR(1, MULTIPATH_NUM),
1544 "Forward packets over multiple paths\n"
1545 "Number of paths\n")
1546 {
1547 int idx_number = 1;
1548 return bgp_maxpaths_config_vty(vty, BGP_PEER_EBGP,
1549 argv[idx_number]->arg, 0, 1);
1550 }
1551
1552 ALIAS_HIDDEN(bgp_maxpaths, bgp_maxpaths_hidden_cmd,
1553 "maximum-paths " CMD_RANGE_STR(1, MULTIPATH_NUM),
1554 "Forward packets over multiple paths\n"
1555 "Number of paths\n")
1556
1557 DEFUN (bgp_maxpaths_ibgp,
1558 bgp_maxpaths_ibgp_cmd,
1559 "maximum-paths ibgp " CMD_RANGE_STR(1, MULTIPATH_NUM),
1560 "Forward packets over multiple paths\n"
1561 "iBGP-multipath\n"
1562 "Number of paths\n")
1563 {
1564 int idx_number = 2;
1565 return bgp_maxpaths_config_vty(vty, BGP_PEER_IBGP,
1566 argv[idx_number]->arg, 0, 1);
1567 }
1568
1569 ALIAS_HIDDEN(bgp_maxpaths_ibgp, bgp_maxpaths_ibgp_hidden_cmd,
1570 "maximum-paths ibgp " CMD_RANGE_STR(1, MULTIPATH_NUM),
1571 "Forward packets over multiple paths\n"
1572 "iBGP-multipath\n"
1573 "Number of paths\n")
1574
1575 DEFUN (bgp_maxpaths_ibgp_cluster,
1576 bgp_maxpaths_ibgp_cluster_cmd,
1577 "maximum-paths ibgp " CMD_RANGE_STR(1, MULTIPATH_NUM) " equal-cluster-length",
1578 "Forward packets over multiple paths\n"
1579 "iBGP-multipath\n"
1580 "Number of paths\n"
1581 "Match the cluster length\n")
1582 {
1583 int idx_number = 2;
1584 return bgp_maxpaths_config_vty(
1585 vty, BGP_PEER_IBGP, argv[idx_number]->arg,
1586 BGP_FLAG_IBGP_MULTIPATH_SAME_CLUSTERLEN, 1);
1587 }
1588
1589 ALIAS_HIDDEN(bgp_maxpaths_ibgp_cluster, bgp_maxpaths_ibgp_cluster_hidden_cmd,
1590 "maximum-paths ibgp " CMD_RANGE_STR(
1591 1, MULTIPATH_NUM) " equal-cluster-length",
1592 "Forward packets over multiple paths\n"
1593 "iBGP-multipath\n"
1594 "Number of paths\n"
1595 "Match the cluster length\n")
1596
1597 DEFUN (no_bgp_maxpaths,
1598 no_bgp_maxpaths_cmd,
1599 "no maximum-paths [" CMD_RANGE_STR(1, MULTIPATH_NUM) "]",
1600 NO_STR
1601 "Forward packets over multiple paths\n"
1602 "Number of paths\n")
1603 {
1604 return bgp_maxpaths_config_vty(vty, BGP_PEER_EBGP, NULL, 0, 0);
1605 }
1606
1607 ALIAS_HIDDEN(no_bgp_maxpaths, no_bgp_maxpaths_hidden_cmd,
1608 "no maximum-paths [" CMD_RANGE_STR(1, MULTIPATH_NUM) "]", NO_STR
1609 "Forward packets over multiple paths\n"
1610 "Number of paths\n")
1611
1612 DEFUN (no_bgp_maxpaths_ibgp,
1613 no_bgp_maxpaths_ibgp_cmd,
1614 "no maximum-paths ibgp [" CMD_RANGE_STR(1, MULTIPATH_NUM) " [equal-cluster-length]]",
1615 NO_STR
1616 "Forward packets over multiple paths\n"
1617 "iBGP-multipath\n"
1618 "Number of paths\n"
1619 "Match the cluster length\n")
1620 {
1621 return bgp_maxpaths_config_vty(vty, BGP_PEER_IBGP, NULL, 0, 0);
1622 }
1623
1624 ALIAS_HIDDEN(no_bgp_maxpaths_ibgp, no_bgp_maxpaths_ibgp_hidden_cmd,
1625 "no maximum-paths ibgp [" CMD_RANGE_STR(
1626 1, MULTIPATH_NUM) " [equal-cluster-length]]",
1627 NO_STR
1628 "Forward packets over multiple paths\n"
1629 "iBGP-multipath\n"
1630 "Number of paths\n"
1631 "Match the cluster length\n")
1632
1633 void bgp_config_write_maxpaths(struct vty *vty, struct bgp *bgp, afi_t afi,
1634 safi_t safi)
1635 {
1636 if (bgp->maxpaths[afi][safi].maxpaths_ebgp != MULTIPATH_NUM) {
1637 vty_out(vty, " maximum-paths %d\n",
1638 bgp->maxpaths[afi][safi].maxpaths_ebgp);
1639 }
1640
1641 if (bgp->maxpaths[afi][safi].maxpaths_ibgp != MULTIPATH_NUM) {
1642 vty_out(vty, " maximum-paths ibgp %d",
1643 bgp->maxpaths[afi][safi].maxpaths_ibgp);
1644 if (CHECK_FLAG(bgp->maxpaths[afi][safi].ibgp_flags,
1645 BGP_FLAG_IBGP_MULTIPATH_SAME_CLUSTERLEN))
1646 vty_out(vty, " equal-cluster-length");
1647 vty_out(vty, "\n");
1648 }
1649 }
1650
1651 /* BGP timers. */
1652
1653 DEFUN (bgp_timers,
1654 bgp_timers_cmd,
1655 "timers bgp (0-65535) (0-65535)",
1656 "Adjust routing timers\n"
1657 "BGP timers\n"
1658 "Keepalive interval\n"
1659 "Holdtime\n")
1660 {
1661 VTY_DECLVAR_CONTEXT(bgp, bgp);
1662 int idx_number = 2;
1663 int idx_number_2 = 3;
1664 unsigned long keepalive = 0;
1665 unsigned long holdtime = 0;
1666
1667 keepalive = strtoul(argv[idx_number]->arg, NULL, 10);
1668 holdtime = strtoul(argv[idx_number_2]->arg, NULL, 10);
1669
1670 /* Holdtime value check. */
1671 if (holdtime < 3 && holdtime != 0) {
1672 vty_out(vty,
1673 "%% hold time value must be either 0 or greater than 3\n");
1674 return CMD_WARNING_CONFIG_FAILED;
1675 }
1676
1677 bgp_timers_set(bgp, keepalive, holdtime);
1678
1679 return CMD_SUCCESS;
1680 }
1681
1682 DEFUN (no_bgp_timers,
1683 no_bgp_timers_cmd,
1684 "no timers bgp [(0-65535) (0-65535)]",
1685 NO_STR
1686 "Adjust routing timers\n"
1687 "BGP timers\n"
1688 "Keepalive interval\n"
1689 "Holdtime\n")
1690 {
1691 VTY_DECLVAR_CONTEXT(bgp, bgp);
1692 bgp_timers_unset(bgp);
1693
1694 return CMD_SUCCESS;
1695 }
1696
1697
1698 DEFUN (bgp_client_to_client_reflection,
1699 bgp_client_to_client_reflection_cmd,
1700 "bgp client-to-client reflection",
1701 "BGP specific commands\n"
1702 "Configure client to client route reflection\n"
1703 "reflection of routes allowed\n")
1704 {
1705 VTY_DECLVAR_CONTEXT(bgp, bgp);
1706 bgp_flag_unset(bgp, BGP_FLAG_NO_CLIENT_TO_CLIENT);
1707 bgp_clear_star_soft_out(vty, bgp->name);
1708
1709 return CMD_SUCCESS;
1710 }
1711
1712 DEFUN (no_bgp_client_to_client_reflection,
1713 no_bgp_client_to_client_reflection_cmd,
1714 "no bgp client-to-client reflection",
1715 NO_STR
1716 "BGP specific commands\n"
1717 "Configure client to client route reflection\n"
1718 "reflection of routes allowed\n")
1719 {
1720 VTY_DECLVAR_CONTEXT(bgp, bgp);
1721 bgp_flag_set(bgp, BGP_FLAG_NO_CLIENT_TO_CLIENT);
1722 bgp_clear_star_soft_out(vty, bgp->name);
1723
1724 return CMD_SUCCESS;
1725 }
1726
1727 /* "bgp always-compare-med" configuration. */
1728 DEFUN (bgp_always_compare_med,
1729 bgp_always_compare_med_cmd,
1730 "bgp always-compare-med",
1731 "BGP specific commands\n"
1732 "Allow comparing MED from different neighbors\n")
1733 {
1734 VTY_DECLVAR_CONTEXT(bgp, bgp);
1735 bgp_flag_set(bgp, BGP_FLAG_ALWAYS_COMPARE_MED);
1736 bgp_recalculate_all_bestpaths(bgp);
1737
1738 return CMD_SUCCESS;
1739 }
1740
1741 DEFUN (no_bgp_always_compare_med,
1742 no_bgp_always_compare_med_cmd,
1743 "no bgp always-compare-med",
1744 NO_STR
1745 "BGP specific commands\n"
1746 "Allow comparing MED from different neighbors\n")
1747 {
1748 VTY_DECLVAR_CONTEXT(bgp, bgp);
1749 bgp_flag_unset(bgp, BGP_FLAG_ALWAYS_COMPARE_MED);
1750 bgp_recalculate_all_bestpaths(bgp);
1751
1752 return CMD_SUCCESS;
1753 }
1754
1755 /* "bgp deterministic-med" configuration. */
1756 DEFUN (bgp_deterministic_med,
1757 bgp_deterministic_med_cmd,
1758 "bgp deterministic-med",
1759 "BGP specific commands\n"
1760 "Pick the best-MED path among paths advertised from the neighboring AS\n")
1761 {
1762 VTY_DECLVAR_CONTEXT(bgp, bgp);
1763
1764 if (!bgp_flag_check(bgp, BGP_FLAG_DETERMINISTIC_MED)) {
1765 bgp_flag_set(bgp, BGP_FLAG_DETERMINISTIC_MED);
1766 bgp_recalculate_all_bestpaths(bgp);
1767 }
1768
1769 return CMD_SUCCESS;
1770 }
1771
1772 DEFUN (no_bgp_deterministic_med,
1773 no_bgp_deterministic_med_cmd,
1774 "no bgp deterministic-med",
1775 NO_STR
1776 "BGP specific commands\n"
1777 "Pick the best-MED path among paths advertised from the neighboring AS\n")
1778 {
1779 VTY_DECLVAR_CONTEXT(bgp, bgp);
1780 int bestpath_per_as_used;
1781 afi_t afi;
1782 safi_t safi;
1783 struct peer *peer;
1784 struct listnode *node, *nnode;
1785
1786 if (bgp_flag_check(bgp, BGP_FLAG_DETERMINISTIC_MED)) {
1787 bestpath_per_as_used = 0;
1788
1789 for (ALL_LIST_ELEMENTS(bgp->peer, node, nnode, peer)) {
1790 FOREACH_AFI_SAFI (afi, safi)
1791 if (CHECK_FLAG(
1792 peer->af_flags[afi][safi],
1793 PEER_FLAG_ADDPATH_TX_BESTPATH_PER_AS)) {
1794 bestpath_per_as_used = 1;
1795 break;
1796 }
1797
1798 if (bestpath_per_as_used)
1799 break;
1800 }
1801
1802 if (bestpath_per_as_used) {
1803 vty_out(vty,
1804 "bgp deterministic-med cannot be disabled while addpath-tx-bestpath-per-AS is in use\n");
1805 return CMD_WARNING_CONFIG_FAILED;
1806 } else {
1807 bgp_flag_unset(bgp, BGP_FLAG_DETERMINISTIC_MED);
1808 bgp_recalculate_all_bestpaths(bgp);
1809 }
1810 }
1811
1812 return CMD_SUCCESS;
1813 }
1814
1815 /* "bgp graceful-restart" configuration. */
1816 DEFUN (bgp_graceful_restart,
1817 bgp_graceful_restart_cmd,
1818 "bgp graceful-restart",
1819 "BGP specific commands\n"
1820 "Graceful restart capability parameters\n")
1821 {
1822 VTY_DECLVAR_CONTEXT(bgp, bgp);
1823 bgp_flag_set(bgp, BGP_FLAG_GRACEFUL_RESTART);
1824 return CMD_SUCCESS;
1825 }
1826
1827 DEFUN (no_bgp_graceful_restart,
1828 no_bgp_graceful_restart_cmd,
1829 "no bgp graceful-restart",
1830 NO_STR
1831 "BGP specific commands\n"
1832 "Graceful restart capability parameters\n")
1833 {
1834 VTY_DECLVAR_CONTEXT(bgp, bgp);
1835 bgp_flag_unset(bgp, BGP_FLAG_GRACEFUL_RESTART);
1836 return CMD_SUCCESS;
1837 }
1838
1839 DEFUN (bgp_graceful_restart_stalepath_time,
1840 bgp_graceful_restart_stalepath_time_cmd,
1841 "bgp graceful-restart stalepath-time (1-3600)",
1842 "BGP specific commands\n"
1843 "Graceful restart capability parameters\n"
1844 "Set the max time to hold onto restarting peer's stale paths\n"
1845 "Delay value (seconds)\n")
1846 {
1847 VTY_DECLVAR_CONTEXT(bgp, bgp);
1848 int idx_number = 3;
1849 uint32_t stalepath;
1850
1851 stalepath = strtoul(argv[idx_number]->arg, NULL, 10);
1852 bgp->stalepath_time = stalepath;
1853 return CMD_SUCCESS;
1854 }
1855
1856 DEFUN (bgp_graceful_restart_restart_time,
1857 bgp_graceful_restart_restart_time_cmd,
1858 "bgp graceful-restart restart-time (1-3600)",
1859 "BGP specific commands\n"
1860 "Graceful restart capability parameters\n"
1861 "Set the time to wait to delete stale routes before a BGP open message is received\n"
1862 "Delay value (seconds)\n")
1863 {
1864 VTY_DECLVAR_CONTEXT(bgp, bgp);
1865 int idx_number = 3;
1866 uint32_t restart;
1867
1868 restart = strtoul(argv[idx_number]->arg, NULL, 10);
1869 bgp->restart_time = restart;
1870 return CMD_SUCCESS;
1871 }
1872
1873 DEFUN (no_bgp_graceful_restart_stalepath_time,
1874 no_bgp_graceful_restart_stalepath_time_cmd,
1875 "no bgp graceful-restart stalepath-time [(1-3600)]",
1876 NO_STR
1877 "BGP specific commands\n"
1878 "Graceful restart capability parameters\n"
1879 "Set the max time to hold onto restarting peer's stale paths\n"
1880 "Delay value (seconds)\n")
1881 {
1882 VTY_DECLVAR_CONTEXT(bgp, bgp);
1883
1884 bgp->stalepath_time = BGP_DEFAULT_STALEPATH_TIME;
1885 return CMD_SUCCESS;
1886 }
1887
1888 DEFUN (no_bgp_graceful_restart_restart_time,
1889 no_bgp_graceful_restart_restart_time_cmd,
1890 "no bgp graceful-restart restart-time [(1-3600)]",
1891 NO_STR
1892 "BGP specific commands\n"
1893 "Graceful restart capability parameters\n"
1894 "Set the time to wait to delete stale routes before a BGP open message is received\n"
1895 "Delay value (seconds)\n")
1896 {
1897 VTY_DECLVAR_CONTEXT(bgp, bgp);
1898
1899 bgp->restart_time = BGP_DEFAULT_RESTART_TIME;
1900 return CMD_SUCCESS;
1901 }
1902
1903 DEFUN (bgp_graceful_restart_preserve_fw,
1904 bgp_graceful_restart_preserve_fw_cmd,
1905 "bgp graceful-restart preserve-fw-state",
1906 "BGP specific commands\n"
1907 "Graceful restart capability parameters\n"
1908 "Sets F-bit indication that fib is preserved while doing Graceful Restart\n")
1909 {
1910 VTY_DECLVAR_CONTEXT(bgp, bgp);
1911 bgp_flag_set(bgp, BGP_FLAG_GR_PRESERVE_FWD);
1912 return CMD_SUCCESS;
1913 }
1914
1915 DEFUN (no_bgp_graceful_restart_preserve_fw,
1916 no_bgp_graceful_restart_preserve_fw_cmd,
1917 "no bgp graceful-restart preserve-fw-state",
1918 NO_STR
1919 "BGP specific commands\n"
1920 "Graceful restart capability parameters\n"
1921 "Unsets F-bit indication that fib is preserved while doing Graceful Restart\n")
1922 {
1923 VTY_DECLVAR_CONTEXT(bgp, bgp);
1924 bgp_flag_unset(bgp, BGP_FLAG_GR_PRESERVE_FWD);
1925 return CMD_SUCCESS;
1926 }
1927
1928 static void bgp_redistribute_redo(struct bgp *bgp)
1929 {
1930 afi_t afi;
1931 int i;
1932 struct list *red_list;
1933 struct listnode *node;
1934 struct bgp_redist *red;
1935
1936 for (afi = AFI_IP; afi < AFI_MAX; afi++) {
1937 for (i = 0; i < ZEBRA_ROUTE_MAX; i++) {
1938
1939 red_list = bgp->redist[afi][i];
1940 if (!red_list)
1941 continue;
1942
1943 for (ALL_LIST_ELEMENTS_RO(red_list, node, red)) {
1944 bgp_redistribute_resend(bgp, afi, i,
1945 red->instance);
1946 }
1947 }
1948 }
1949 }
1950
1951 /* "bgp graceful-shutdown" configuration */
1952 DEFUN (bgp_graceful_shutdown,
1953 bgp_graceful_shutdown_cmd,
1954 "bgp graceful-shutdown",
1955 BGP_STR
1956 "Graceful shutdown parameters\n")
1957 {
1958 VTY_DECLVAR_CONTEXT(bgp, bgp);
1959
1960 if (!bgp_flag_check(bgp, BGP_FLAG_GRACEFUL_SHUTDOWN)) {
1961 bgp_flag_set(bgp, BGP_FLAG_GRACEFUL_SHUTDOWN);
1962 bgp_static_redo_import_check(bgp);
1963 bgp_redistribute_redo(bgp);
1964 bgp_clear_star_soft_out(vty, bgp->name);
1965 bgp_clear_star_soft_in(vty, bgp->name);
1966 }
1967
1968 return CMD_SUCCESS;
1969 }
1970
1971 DEFUN (no_bgp_graceful_shutdown,
1972 no_bgp_graceful_shutdown_cmd,
1973 "no bgp graceful-shutdown",
1974 NO_STR
1975 BGP_STR
1976 "Graceful shutdown parameters\n")
1977 {
1978 VTY_DECLVAR_CONTEXT(bgp, bgp);
1979
1980 if (bgp_flag_check(bgp, BGP_FLAG_GRACEFUL_SHUTDOWN)) {
1981 bgp_flag_unset(bgp, BGP_FLAG_GRACEFUL_SHUTDOWN);
1982 bgp_static_redo_import_check(bgp);
1983 bgp_redistribute_redo(bgp);
1984 bgp_clear_star_soft_out(vty, bgp->name);
1985 bgp_clear_star_soft_in(vty, bgp->name);
1986 }
1987
1988 return CMD_SUCCESS;
1989 }
1990
1991 /* "bgp fast-external-failover" configuration. */
1992 DEFUN (bgp_fast_external_failover,
1993 bgp_fast_external_failover_cmd,
1994 "bgp fast-external-failover",
1995 BGP_STR
1996 "Immediately reset session if a link to a directly connected external peer goes down\n")
1997 {
1998 VTY_DECLVAR_CONTEXT(bgp, bgp);
1999 bgp_flag_unset(bgp, BGP_FLAG_NO_FAST_EXT_FAILOVER);
2000 return CMD_SUCCESS;
2001 }
2002
2003 DEFUN (no_bgp_fast_external_failover,
2004 no_bgp_fast_external_failover_cmd,
2005 "no bgp fast-external-failover",
2006 NO_STR
2007 BGP_STR
2008 "Immediately reset session if a link to a directly connected external peer goes down\n")
2009 {
2010 VTY_DECLVAR_CONTEXT(bgp, bgp);
2011 bgp_flag_set(bgp, BGP_FLAG_NO_FAST_EXT_FAILOVER);
2012 return CMD_SUCCESS;
2013 }
2014
2015 /* "bgp enforce-first-as" configuration. */
2016 #if defined(VERSION_TYPE_DEV) && CONFDATE > 20180517
2017 CPP_NOTICE("bgpd: remove deprecated '[no] bgp enforce-first-as' commands")
2018 #endif
2019
2020 DEFUN_HIDDEN (bgp_enforce_first_as,
2021 bgp_enforce_first_as_cmd,
2022 "[no] bgp enforce-first-as",
2023 NO_STR
2024 BGP_STR
2025 "Enforce the first AS for EBGP routes\n")
2026 {
2027 VTY_DECLVAR_CONTEXT(bgp, bgp);
2028
2029 if (strmatch(argv[0]->text, "no"))
2030 bgp_flag_unset(bgp, BGP_FLAG_ENFORCE_FIRST_AS);
2031 else
2032 bgp_flag_set(bgp, BGP_FLAG_ENFORCE_FIRST_AS);
2033
2034 return CMD_SUCCESS;
2035 }
2036
2037 /* "bgp bestpath compare-routerid" configuration. */
2038 DEFUN (bgp_bestpath_compare_router_id,
2039 bgp_bestpath_compare_router_id_cmd,
2040 "bgp bestpath compare-routerid",
2041 "BGP specific commands\n"
2042 "Change the default bestpath selection\n"
2043 "Compare router-id for identical EBGP paths\n")
2044 {
2045 VTY_DECLVAR_CONTEXT(bgp, bgp);
2046 bgp_flag_set(bgp, BGP_FLAG_COMPARE_ROUTER_ID);
2047 bgp_recalculate_all_bestpaths(bgp);
2048
2049 return CMD_SUCCESS;
2050 }
2051
2052 DEFUN (no_bgp_bestpath_compare_router_id,
2053 no_bgp_bestpath_compare_router_id_cmd,
2054 "no bgp bestpath compare-routerid",
2055 NO_STR
2056 "BGP specific commands\n"
2057 "Change the default bestpath selection\n"
2058 "Compare router-id for identical EBGP paths\n")
2059 {
2060 VTY_DECLVAR_CONTEXT(bgp, bgp);
2061 bgp_flag_unset(bgp, BGP_FLAG_COMPARE_ROUTER_ID);
2062 bgp_recalculate_all_bestpaths(bgp);
2063
2064 return CMD_SUCCESS;
2065 }
2066
2067 /* "bgp bestpath as-path ignore" configuration. */
2068 DEFUN (bgp_bestpath_aspath_ignore,
2069 bgp_bestpath_aspath_ignore_cmd,
2070 "bgp bestpath as-path ignore",
2071 "BGP specific commands\n"
2072 "Change the default bestpath selection\n"
2073 "AS-path attribute\n"
2074 "Ignore as-path length in selecting a route\n")
2075 {
2076 VTY_DECLVAR_CONTEXT(bgp, bgp);
2077 bgp_flag_set(bgp, BGP_FLAG_ASPATH_IGNORE);
2078 bgp_recalculate_all_bestpaths(bgp);
2079
2080 return CMD_SUCCESS;
2081 }
2082
2083 DEFUN (no_bgp_bestpath_aspath_ignore,
2084 no_bgp_bestpath_aspath_ignore_cmd,
2085 "no bgp bestpath as-path ignore",
2086 NO_STR
2087 "BGP specific commands\n"
2088 "Change the default bestpath selection\n"
2089 "AS-path attribute\n"
2090 "Ignore as-path length in selecting a route\n")
2091 {
2092 VTY_DECLVAR_CONTEXT(bgp, bgp);
2093 bgp_flag_unset(bgp, BGP_FLAG_ASPATH_IGNORE);
2094 bgp_recalculate_all_bestpaths(bgp);
2095
2096 return CMD_SUCCESS;
2097 }
2098
2099 /* "bgp bestpath as-path confed" configuration. */
2100 DEFUN (bgp_bestpath_aspath_confed,
2101 bgp_bestpath_aspath_confed_cmd,
2102 "bgp bestpath as-path confed",
2103 "BGP specific commands\n"
2104 "Change the default bestpath selection\n"
2105 "AS-path attribute\n"
2106 "Compare path lengths including confederation sets & sequences in selecting a route\n")
2107 {
2108 VTY_DECLVAR_CONTEXT(bgp, bgp);
2109 bgp_flag_set(bgp, BGP_FLAG_ASPATH_CONFED);
2110 bgp_recalculate_all_bestpaths(bgp);
2111
2112 return CMD_SUCCESS;
2113 }
2114
2115 DEFUN (no_bgp_bestpath_aspath_confed,
2116 no_bgp_bestpath_aspath_confed_cmd,
2117 "no bgp bestpath as-path confed",
2118 NO_STR
2119 "BGP specific commands\n"
2120 "Change the default bestpath selection\n"
2121 "AS-path attribute\n"
2122 "Compare path lengths including confederation sets & sequences in selecting a route\n")
2123 {
2124 VTY_DECLVAR_CONTEXT(bgp, bgp);
2125 bgp_flag_unset(bgp, BGP_FLAG_ASPATH_CONFED);
2126 bgp_recalculate_all_bestpaths(bgp);
2127
2128 return CMD_SUCCESS;
2129 }
2130
2131 /* "bgp bestpath as-path multipath-relax" configuration. */
2132 DEFUN (bgp_bestpath_aspath_multipath_relax,
2133 bgp_bestpath_aspath_multipath_relax_cmd,
2134 "bgp bestpath as-path multipath-relax [<as-set|no-as-set>]",
2135 "BGP specific commands\n"
2136 "Change the default bestpath selection\n"
2137 "AS-path attribute\n"
2138 "Allow load sharing across routes that have different AS paths (but same length)\n"
2139 "Generate an AS_SET\n"
2140 "Do not generate an AS_SET\n")
2141 {
2142 VTY_DECLVAR_CONTEXT(bgp, bgp);
2143 int idx = 0;
2144 bgp_flag_set(bgp, BGP_FLAG_ASPATH_MULTIPATH_RELAX);
2145
2146 /* no-as-set is now the default behavior so we can silently
2147 * ignore it */
2148 if (argv_find(argv, argc, "as-set", &idx))
2149 bgp_flag_set(bgp, BGP_FLAG_MULTIPATH_RELAX_AS_SET);
2150 else
2151 bgp_flag_unset(bgp, BGP_FLAG_MULTIPATH_RELAX_AS_SET);
2152
2153 bgp_recalculate_all_bestpaths(bgp);
2154
2155 return CMD_SUCCESS;
2156 }
2157
2158 DEFUN (no_bgp_bestpath_aspath_multipath_relax,
2159 no_bgp_bestpath_aspath_multipath_relax_cmd,
2160 "no bgp bestpath as-path multipath-relax [<as-set|no-as-set>]",
2161 NO_STR
2162 "BGP specific commands\n"
2163 "Change the default bestpath selection\n"
2164 "AS-path attribute\n"
2165 "Allow load sharing across routes that have different AS paths (but same length)\n"
2166 "Generate an AS_SET\n"
2167 "Do not generate an AS_SET\n")
2168 {
2169 VTY_DECLVAR_CONTEXT(bgp, bgp);
2170 bgp_flag_unset(bgp, BGP_FLAG_ASPATH_MULTIPATH_RELAX);
2171 bgp_flag_unset(bgp, BGP_FLAG_MULTIPATH_RELAX_AS_SET);
2172 bgp_recalculate_all_bestpaths(bgp);
2173
2174 return CMD_SUCCESS;
2175 }
2176
2177 /* "bgp log-neighbor-changes" configuration. */
2178 DEFUN (bgp_log_neighbor_changes,
2179 bgp_log_neighbor_changes_cmd,
2180 "bgp log-neighbor-changes",
2181 "BGP specific commands\n"
2182 "Log neighbor up/down and reset reason\n")
2183 {
2184 VTY_DECLVAR_CONTEXT(bgp, bgp);
2185 bgp_flag_set(bgp, BGP_FLAG_LOG_NEIGHBOR_CHANGES);
2186 return CMD_SUCCESS;
2187 }
2188
2189 DEFUN (no_bgp_log_neighbor_changes,
2190 no_bgp_log_neighbor_changes_cmd,
2191 "no bgp log-neighbor-changes",
2192 NO_STR
2193 "BGP specific commands\n"
2194 "Log neighbor up/down and reset reason\n")
2195 {
2196 VTY_DECLVAR_CONTEXT(bgp, bgp);
2197 bgp_flag_unset(bgp, BGP_FLAG_LOG_NEIGHBOR_CHANGES);
2198 return CMD_SUCCESS;
2199 }
2200
2201 /* "bgp bestpath med" configuration. */
2202 DEFUN (bgp_bestpath_med,
2203 bgp_bestpath_med_cmd,
2204 "bgp bestpath med <confed [missing-as-worst]|missing-as-worst [confed]>",
2205 "BGP specific commands\n"
2206 "Change the default bestpath selection\n"
2207 "MED attribute\n"
2208 "Compare MED among confederation paths\n"
2209 "Treat missing MED as the least preferred one\n"
2210 "Treat missing MED as the least preferred one\n"
2211 "Compare MED among confederation paths\n")
2212 {
2213 VTY_DECLVAR_CONTEXT(bgp, bgp);
2214
2215 int idx = 0;
2216 if (argv_find(argv, argc, "confed", &idx))
2217 bgp_flag_set(bgp, BGP_FLAG_MED_CONFED);
2218 idx = 0;
2219 if (argv_find(argv, argc, "missing-as-worst", &idx))
2220 bgp_flag_set(bgp, BGP_FLAG_MED_MISSING_AS_WORST);
2221
2222 bgp_recalculate_all_bestpaths(bgp);
2223
2224 return CMD_SUCCESS;
2225 }
2226
2227 DEFUN (no_bgp_bestpath_med,
2228 no_bgp_bestpath_med_cmd,
2229 "no bgp bestpath med <confed [missing-as-worst]|missing-as-worst [confed]>",
2230 NO_STR
2231 "BGP specific commands\n"
2232 "Change the default bestpath selection\n"
2233 "MED attribute\n"
2234 "Compare MED among confederation paths\n"
2235 "Treat missing MED as the least preferred one\n"
2236 "Treat missing MED as the least preferred one\n"
2237 "Compare MED among confederation paths\n")
2238 {
2239 VTY_DECLVAR_CONTEXT(bgp, bgp);
2240
2241 int idx = 0;
2242 if (argv_find(argv, argc, "confed", &idx))
2243 bgp_flag_unset(bgp, BGP_FLAG_MED_CONFED);
2244 idx = 0;
2245 if (argv_find(argv, argc, "missing-as-worst", &idx))
2246 bgp_flag_unset(bgp, BGP_FLAG_MED_MISSING_AS_WORST);
2247
2248 bgp_recalculate_all_bestpaths(bgp);
2249
2250 return CMD_SUCCESS;
2251 }
2252
2253 /* "no bgp default ipv4-unicast". */
2254 DEFUN (no_bgp_default_ipv4_unicast,
2255 no_bgp_default_ipv4_unicast_cmd,
2256 "no bgp default ipv4-unicast",
2257 NO_STR
2258 "BGP specific commands\n"
2259 "Configure BGP defaults\n"
2260 "Activate ipv4-unicast for a peer by default\n")
2261 {
2262 VTY_DECLVAR_CONTEXT(bgp, bgp);
2263 bgp_flag_set(bgp, BGP_FLAG_NO_DEFAULT_IPV4);
2264 return CMD_SUCCESS;
2265 }
2266
2267 DEFUN (bgp_default_ipv4_unicast,
2268 bgp_default_ipv4_unicast_cmd,
2269 "bgp default ipv4-unicast",
2270 "BGP specific commands\n"
2271 "Configure BGP defaults\n"
2272 "Activate ipv4-unicast for a peer by default\n")
2273 {
2274 VTY_DECLVAR_CONTEXT(bgp, bgp);
2275 bgp_flag_unset(bgp, BGP_FLAG_NO_DEFAULT_IPV4);
2276 return CMD_SUCCESS;
2277 }
2278
2279 /* Display hostname in certain command outputs */
2280 DEFUN (bgp_default_show_hostname,
2281 bgp_default_show_hostname_cmd,
2282 "bgp default show-hostname",
2283 "BGP specific commands\n"
2284 "Configure BGP defaults\n"
2285 "Show hostname in certain command ouputs\n")
2286 {
2287 VTY_DECLVAR_CONTEXT(bgp, bgp);
2288 bgp_flag_set(bgp, BGP_FLAG_SHOW_HOSTNAME);
2289 return CMD_SUCCESS;
2290 }
2291
2292 DEFUN (no_bgp_default_show_hostname,
2293 no_bgp_default_show_hostname_cmd,
2294 "no bgp default show-hostname",
2295 NO_STR
2296 "BGP specific commands\n"
2297 "Configure BGP defaults\n"
2298 "Show hostname in certain command ouputs\n")
2299 {
2300 VTY_DECLVAR_CONTEXT(bgp, bgp);
2301 bgp_flag_unset(bgp, BGP_FLAG_SHOW_HOSTNAME);
2302 return CMD_SUCCESS;
2303 }
2304
2305 /* "bgp network import-check" configuration. */
2306 DEFUN (bgp_network_import_check,
2307 bgp_network_import_check_cmd,
2308 "bgp network import-check",
2309 "BGP specific commands\n"
2310 "BGP network command\n"
2311 "Check BGP network route exists in IGP\n")
2312 {
2313 VTY_DECLVAR_CONTEXT(bgp, bgp);
2314 if (!bgp_flag_check(bgp, BGP_FLAG_IMPORT_CHECK)) {
2315 bgp_flag_set(bgp, BGP_FLAG_IMPORT_CHECK);
2316 bgp_static_redo_import_check(bgp);
2317 }
2318
2319 return CMD_SUCCESS;
2320 }
2321
2322 ALIAS_HIDDEN(bgp_network_import_check, bgp_network_import_check_exact_cmd,
2323 "bgp network import-check exact",
2324 "BGP specific commands\n"
2325 "BGP network command\n"
2326 "Check BGP network route exists in IGP\n"
2327 "Match route precisely\n")
2328
2329 DEFUN (no_bgp_network_import_check,
2330 no_bgp_network_import_check_cmd,
2331 "no bgp network import-check",
2332 NO_STR
2333 "BGP specific commands\n"
2334 "BGP network command\n"
2335 "Check BGP network route exists in IGP\n")
2336 {
2337 VTY_DECLVAR_CONTEXT(bgp, bgp);
2338 if (bgp_flag_check(bgp, BGP_FLAG_IMPORT_CHECK)) {
2339 bgp_flag_unset(bgp, BGP_FLAG_IMPORT_CHECK);
2340 bgp_static_redo_import_check(bgp);
2341 }
2342
2343 return CMD_SUCCESS;
2344 }
2345
2346 DEFUN (bgp_default_local_preference,
2347 bgp_default_local_preference_cmd,
2348 "bgp default local-preference (0-4294967295)",
2349 "BGP specific commands\n"
2350 "Configure BGP defaults\n"
2351 "local preference (higher=more preferred)\n"
2352 "Configure default local preference value\n")
2353 {
2354 VTY_DECLVAR_CONTEXT(bgp, bgp);
2355 int idx_number = 3;
2356 uint32_t local_pref;
2357
2358 local_pref = strtoul(argv[idx_number]->arg, NULL, 10);
2359
2360 bgp_default_local_preference_set(bgp, local_pref);
2361 bgp_clear_star_soft_in(vty, bgp->name);
2362
2363 return CMD_SUCCESS;
2364 }
2365
2366 DEFUN (no_bgp_default_local_preference,
2367 no_bgp_default_local_preference_cmd,
2368 "no bgp default local-preference [(0-4294967295)]",
2369 NO_STR
2370 "BGP specific commands\n"
2371 "Configure BGP defaults\n"
2372 "local preference (higher=more preferred)\n"
2373 "Configure default local preference value\n")
2374 {
2375 VTY_DECLVAR_CONTEXT(bgp, bgp);
2376 bgp_default_local_preference_unset(bgp);
2377 bgp_clear_star_soft_in(vty, bgp->name);
2378
2379 return CMD_SUCCESS;
2380 }
2381
2382
2383 DEFUN (bgp_default_subgroup_pkt_queue_max,
2384 bgp_default_subgroup_pkt_queue_max_cmd,
2385 "bgp default subgroup-pkt-queue-max (20-100)",
2386 "BGP specific commands\n"
2387 "Configure BGP defaults\n"
2388 "subgroup-pkt-queue-max\n"
2389 "Configure subgroup packet queue max\n")
2390 {
2391 VTY_DECLVAR_CONTEXT(bgp, bgp);
2392 int idx_number = 3;
2393 uint32_t max_size;
2394
2395 max_size = strtoul(argv[idx_number]->arg, NULL, 10);
2396
2397 bgp_default_subgroup_pkt_queue_max_set(bgp, max_size);
2398
2399 return CMD_SUCCESS;
2400 }
2401
2402 DEFUN (no_bgp_default_subgroup_pkt_queue_max,
2403 no_bgp_default_subgroup_pkt_queue_max_cmd,
2404 "no bgp default subgroup-pkt-queue-max [(20-100)]",
2405 NO_STR
2406 "BGP specific commands\n"
2407 "Configure BGP defaults\n"
2408 "subgroup-pkt-queue-max\n"
2409 "Configure subgroup packet queue max\n")
2410 {
2411 VTY_DECLVAR_CONTEXT(bgp, bgp);
2412 bgp_default_subgroup_pkt_queue_max_unset(bgp);
2413 return CMD_SUCCESS;
2414 }
2415
2416
2417 DEFUN (bgp_rr_allow_outbound_policy,
2418 bgp_rr_allow_outbound_policy_cmd,
2419 "bgp route-reflector allow-outbound-policy",
2420 "BGP specific commands\n"
2421 "Allow modifications made by out route-map\n"
2422 "on ibgp neighbors\n")
2423 {
2424 VTY_DECLVAR_CONTEXT(bgp, bgp);
2425
2426 if (!bgp_flag_check(bgp, BGP_FLAG_RR_ALLOW_OUTBOUND_POLICY)) {
2427 bgp_flag_set(bgp, BGP_FLAG_RR_ALLOW_OUTBOUND_POLICY);
2428 update_group_announce_rrclients(bgp);
2429 bgp_clear_star_soft_out(vty, bgp->name);
2430 }
2431
2432 return CMD_SUCCESS;
2433 }
2434
2435 DEFUN (no_bgp_rr_allow_outbound_policy,
2436 no_bgp_rr_allow_outbound_policy_cmd,
2437 "no bgp route-reflector allow-outbound-policy",
2438 NO_STR
2439 "BGP specific commands\n"
2440 "Allow modifications made by out route-map\n"
2441 "on ibgp neighbors\n")
2442 {
2443 VTY_DECLVAR_CONTEXT(bgp, bgp);
2444
2445 if (bgp_flag_check(bgp, BGP_FLAG_RR_ALLOW_OUTBOUND_POLICY)) {
2446 bgp_flag_unset(bgp, BGP_FLAG_RR_ALLOW_OUTBOUND_POLICY);
2447 update_group_announce_rrclients(bgp);
2448 bgp_clear_star_soft_out(vty, bgp->name);
2449 }
2450
2451 return CMD_SUCCESS;
2452 }
2453
2454 DEFUN (bgp_listen_limit,
2455 bgp_listen_limit_cmd,
2456 "bgp listen limit (1-5000)",
2457 "BGP specific commands\n"
2458 "Configure BGP defaults\n"
2459 "maximum number of BGP Dynamic Neighbors that can be created\n"
2460 "Configure Dynamic Neighbors listen limit value\n")
2461 {
2462 VTY_DECLVAR_CONTEXT(bgp, bgp);
2463 int idx_number = 3;
2464 int listen_limit;
2465
2466 listen_limit = strtoul(argv[idx_number]->arg, NULL, 10);
2467
2468 bgp_listen_limit_set(bgp, listen_limit);
2469
2470 return CMD_SUCCESS;
2471 }
2472
2473 DEFUN (no_bgp_listen_limit,
2474 no_bgp_listen_limit_cmd,
2475 "no bgp listen limit [(1-5000)]",
2476 "BGP specific commands\n"
2477 "Configure BGP defaults\n"
2478 "unset maximum number of BGP Dynamic Neighbors that can be created\n"
2479 "Configure Dynamic Neighbors listen limit value to default\n"
2480 "Configure Dynamic Neighbors listen limit value\n")
2481 {
2482 VTY_DECLVAR_CONTEXT(bgp, bgp);
2483 bgp_listen_limit_unset(bgp);
2484 return CMD_SUCCESS;
2485 }
2486
2487
2488 /*
2489 * Check if this listen range is already configured. Check for exact
2490 * match or overlap based on input.
2491 */
2492 static struct peer_group *listen_range_exists(struct bgp *bgp,
2493 struct prefix *range, int exact)
2494 {
2495 struct listnode *node, *nnode;
2496 struct listnode *node1, *nnode1;
2497 struct peer_group *group;
2498 struct prefix *lr;
2499 afi_t afi;
2500 int match;
2501
2502 afi = family2afi(range->family);
2503 for (ALL_LIST_ELEMENTS(bgp->group, node, nnode, group)) {
2504 for (ALL_LIST_ELEMENTS(group->listen_range[afi], node1, nnode1,
2505 lr)) {
2506 if (exact)
2507 match = prefix_same(range, lr);
2508 else
2509 match = (prefix_match(range, lr)
2510 || prefix_match(lr, range));
2511 if (match)
2512 return group;
2513 }
2514 }
2515
2516 return NULL;
2517 }
2518
2519 DEFUN (bgp_listen_range,
2520 bgp_listen_range_cmd,
2521 "bgp listen range <A.B.C.D/M|X:X::X:X/M> peer-group WORD",
2522 "BGP specific commands\n"
2523 "Configure BGP dynamic neighbors listen range\n"
2524 "Configure BGP dynamic neighbors listen range\n"
2525 NEIGHBOR_ADDR_STR
2526 "Member of the peer-group\n"
2527 "Peer-group name\n")
2528 {
2529 VTY_DECLVAR_CONTEXT(bgp, bgp);
2530 struct prefix range;
2531 struct peer_group *group, *existing_group;
2532 afi_t afi;
2533 int ret;
2534 int idx = 0;
2535
2536 argv_find(argv, argc, "A.B.C.D/M", &idx);
2537 argv_find(argv, argc, "X:X::X:X/M", &idx);
2538 char *prefix = argv[idx]->arg;
2539 argv_find(argv, argc, "WORD", &idx);
2540 char *peergroup = argv[idx]->arg;
2541
2542 /* Convert IP prefix string to struct prefix. */
2543 ret = str2prefix(prefix, &range);
2544 if (!ret) {
2545 vty_out(vty, "%% Malformed listen range\n");
2546 return CMD_WARNING_CONFIG_FAILED;
2547 }
2548
2549 afi = family2afi(range.family);
2550
2551 if (afi == AFI_IP6 && IN6_IS_ADDR_LINKLOCAL(&range.u.prefix6)) {
2552 vty_out(vty,
2553 "%% Malformed listen range (link-local address)\n");
2554 return CMD_WARNING_CONFIG_FAILED;
2555 }
2556
2557 apply_mask(&range);
2558
2559 /* Check if same listen range is already configured. */
2560 existing_group = listen_range_exists(bgp, &range, 1);
2561 if (existing_group) {
2562 if (strcmp(existing_group->name, peergroup) == 0)
2563 return CMD_SUCCESS;
2564 else {
2565 vty_out(vty,
2566 "%% Same listen range is attached to peer-group %s\n",
2567 existing_group->name);
2568 return CMD_WARNING_CONFIG_FAILED;
2569 }
2570 }
2571
2572 /* Check if an overlapping listen range exists. */
2573 if (listen_range_exists(bgp, &range, 0)) {
2574 vty_out(vty,
2575 "%% Listen range overlaps with existing listen range\n");
2576 return CMD_WARNING_CONFIG_FAILED;
2577 }
2578
2579 group = peer_group_lookup(bgp, peergroup);
2580 if (!group) {
2581 vty_out(vty, "%% Configure the peer-group first\n");
2582 return CMD_WARNING_CONFIG_FAILED;
2583 }
2584
2585 ret = peer_group_listen_range_add(group, &range);
2586 return bgp_vty_return(vty, ret);
2587 }
2588
2589 DEFUN (no_bgp_listen_range,
2590 no_bgp_listen_range_cmd,
2591 "no bgp listen range <A.B.C.D/M|X:X::X:X/M> peer-group WORD",
2592 NO_STR
2593 "BGP specific commands\n"
2594 "Unconfigure BGP dynamic neighbors listen range\n"
2595 "Unconfigure BGP dynamic neighbors listen range\n"
2596 NEIGHBOR_ADDR_STR
2597 "Member of the peer-group\n"
2598 "Peer-group name\n")
2599 {
2600 VTY_DECLVAR_CONTEXT(bgp, bgp);
2601 struct prefix range;
2602 struct peer_group *group;
2603 afi_t afi;
2604 int ret;
2605 int idx = 0;
2606
2607 argv_find(argv, argc, "A.B.C.D/M", &idx);
2608 argv_find(argv, argc, "X:X::X:X/M", &idx);
2609 char *prefix = argv[idx]->arg;
2610 argv_find(argv, argc, "WORD", &idx);
2611 char *peergroup = argv[idx]->arg;
2612
2613 /* Convert IP prefix string to struct prefix. */
2614 ret = str2prefix(prefix, &range);
2615 if (!ret) {
2616 vty_out(vty, "%% Malformed listen range\n");
2617 return CMD_WARNING_CONFIG_FAILED;
2618 }
2619
2620 afi = family2afi(range.family);
2621
2622 if (afi == AFI_IP6 && IN6_IS_ADDR_LINKLOCAL(&range.u.prefix6)) {
2623 vty_out(vty,
2624 "%% Malformed listen range (link-local address)\n");
2625 return CMD_WARNING_CONFIG_FAILED;
2626 }
2627
2628 apply_mask(&range);
2629
2630 group = peer_group_lookup(bgp, peergroup);
2631 if (!group) {
2632 vty_out(vty, "%% Peer-group does not exist\n");
2633 return CMD_WARNING_CONFIG_FAILED;
2634 }
2635
2636 ret = peer_group_listen_range_del(group, &range);
2637 return bgp_vty_return(vty, ret);
2638 }
2639
2640 void bgp_config_write_listen(struct vty *vty, struct bgp *bgp)
2641 {
2642 struct peer_group *group;
2643 struct listnode *node, *nnode, *rnode, *nrnode;
2644 struct prefix *range;
2645 afi_t afi;
2646 char buf[PREFIX2STR_BUFFER];
2647
2648 if (bgp->dynamic_neighbors_limit != BGP_DYNAMIC_NEIGHBORS_LIMIT_DEFAULT)
2649 vty_out(vty, " bgp listen limit %d\n",
2650 bgp->dynamic_neighbors_limit);
2651
2652 for (ALL_LIST_ELEMENTS(bgp->group, node, nnode, group)) {
2653 for (afi = AFI_IP; afi < AFI_MAX; afi++) {
2654 for (ALL_LIST_ELEMENTS(group->listen_range[afi], rnode,
2655 nrnode, range)) {
2656 prefix2str(range, buf, sizeof(buf));
2657 vty_out(vty,
2658 " bgp listen range %s peer-group %s\n",
2659 buf, group->name);
2660 }
2661 }
2662 }
2663 }
2664
2665
2666 DEFUN (bgp_disable_connected_route_check,
2667 bgp_disable_connected_route_check_cmd,
2668 "bgp disable-ebgp-connected-route-check",
2669 "BGP specific commands\n"
2670 "Disable checking if nexthop is connected on ebgp sessions\n")
2671 {
2672 VTY_DECLVAR_CONTEXT(bgp, bgp);
2673 bgp_flag_set(bgp, BGP_FLAG_DISABLE_NH_CONNECTED_CHK);
2674 bgp_clear_star_soft_in(vty, bgp->name);
2675
2676 return CMD_SUCCESS;
2677 }
2678
2679 DEFUN (no_bgp_disable_connected_route_check,
2680 no_bgp_disable_connected_route_check_cmd,
2681 "no bgp disable-ebgp-connected-route-check",
2682 NO_STR
2683 "BGP specific commands\n"
2684 "Disable checking if nexthop is connected on ebgp sessions\n")
2685 {
2686 VTY_DECLVAR_CONTEXT(bgp, bgp);
2687 bgp_flag_unset(bgp, BGP_FLAG_DISABLE_NH_CONNECTED_CHK);
2688 bgp_clear_star_soft_in(vty, bgp->name);
2689
2690 return CMD_SUCCESS;
2691 }
2692
2693
2694 static int peer_remote_as_vty(struct vty *vty, const char *peer_str,
2695 const char *as_str, afi_t afi, safi_t safi)
2696 {
2697 VTY_DECLVAR_CONTEXT(bgp, bgp);
2698 int ret;
2699 as_t as;
2700 int as_type = AS_SPECIFIED;
2701 union sockunion su;
2702
2703 if (as_str[0] == 'i') {
2704 as = 0;
2705 as_type = AS_INTERNAL;
2706 } else if (as_str[0] == 'e') {
2707 as = 0;
2708 as_type = AS_EXTERNAL;
2709 } else {
2710 /* Get AS number. */
2711 as = strtoul(as_str, NULL, 10);
2712 }
2713
2714 /* If peer is peer group, call proper function. */
2715 ret = str2sockunion(peer_str, &su);
2716 if (ret < 0) {
2717 /* Check for peer by interface */
2718 ret = peer_remote_as(bgp, NULL, peer_str, &as, as_type, afi,
2719 safi);
2720 if (ret < 0) {
2721 ret = peer_group_remote_as(bgp, peer_str, &as, as_type);
2722 if (ret < 0) {
2723 vty_out(vty,
2724 "%% Create the peer-group or interface first\n");
2725 return CMD_WARNING_CONFIG_FAILED;
2726 }
2727 return CMD_SUCCESS;
2728 }
2729 } else {
2730 if (peer_address_self_check(bgp, &su)) {
2731 vty_out(vty,
2732 "%% Can not configure the local system as neighbor\n");
2733 return CMD_WARNING_CONFIG_FAILED;
2734 }
2735 ret = peer_remote_as(bgp, &su, NULL, &as, as_type, afi, safi);
2736 }
2737
2738 /* This peer belongs to peer group. */
2739 switch (ret) {
2740 case BGP_ERR_PEER_GROUP_MEMBER:
2741 vty_out(vty,
2742 "%% Peer-group AS %u. Cannot configure remote-as for member\n",
2743 as);
2744 return CMD_WARNING_CONFIG_FAILED;
2745 case BGP_ERR_PEER_GROUP_PEER_TYPE_DIFFERENT:
2746 vty_out(vty,
2747 "%% The AS# can not be changed from %u to %s, peer-group members must be all internal or all external\n",
2748 as, as_str);
2749 return CMD_WARNING_CONFIG_FAILED;
2750 }
2751 return bgp_vty_return(vty, ret);
2752 }
2753
2754 DEFUN (bgp_default_shutdown,
2755 bgp_default_shutdown_cmd,
2756 "[no] bgp default shutdown",
2757 NO_STR
2758 BGP_STR
2759 "Configure BGP defaults\n"
2760 "Apply administrative shutdown to newly configured peers\n")
2761 {
2762 VTY_DECLVAR_CONTEXT(bgp, bgp);
2763 bgp->autoshutdown = !strmatch(argv[0]->text, "no");
2764 return CMD_SUCCESS;
2765 }
2766
2767 DEFUN (neighbor_remote_as,
2768 neighbor_remote_as_cmd,
2769 "neighbor <A.B.C.D|X:X::X:X|WORD> remote-as <(1-4294967295)|internal|external>",
2770 NEIGHBOR_STR
2771 NEIGHBOR_ADDR_STR2
2772 "Specify a BGP neighbor\n"
2773 AS_STR
2774 "Internal BGP peer\n"
2775 "External BGP peer\n")
2776 {
2777 int idx_peer = 1;
2778 int idx_remote_as = 3;
2779 return peer_remote_as_vty(vty, argv[idx_peer]->arg,
2780 argv[idx_remote_as]->arg, AFI_IP,
2781 SAFI_UNICAST);
2782 }
2783
2784 static int peer_conf_interface_get(struct vty *vty, const char *conf_if,
2785 afi_t afi, safi_t safi, int v6only,
2786 const char *peer_group_name,
2787 const char *as_str)
2788 {
2789 VTY_DECLVAR_CONTEXT(bgp, bgp);
2790 as_t as = 0;
2791 int as_type = AS_UNSPECIFIED;
2792 struct peer *peer;
2793 struct peer_group *group;
2794 int ret = 0;
2795 union sockunion su;
2796
2797 group = peer_group_lookup(bgp, conf_if);
2798
2799 if (group) {
2800 vty_out(vty, "%% Name conflict with peer-group \n");
2801 return CMD_WARNING_CONFIG_FAILED;
2802 }
2803
2804 if (as_str) {
2805 if (as_str[0] == 'i') {
2806 as_type = AS_INTERNAL;
2807 } else if (as_str[0] == 'e') {
2808 as_type = AS_EXTERNAL;
2809 } else {
2810 /* Get AS number. */
2811 as = strtoul(as_str, NULL, 10);
2812 as_type = AS_SPECIFIED;
2813 }
2814 }
2815
2816 peer = peer_lookup_by_conf_if(bgp, conf_if);
2817 if (peer) {
2818 if (as_str)
2819 ret = peer_remote_as(bgp, &su, conf_if, &as, as_type,
2820 afi, safi);
2821 } else {
2822 if (bgp_flag_check(bgp, BGP_FLAG_NO_DEFAULT_IPV4)
2823 && afi == AFI_IP && safi == SAFI_UNICAST)
2824 peer = peer_create(NULL, conf_if, bgp, bgp->as, as,
2825 as_type, 0, 0, NULL);
2826 else
2827 peer = peer_create(NULL, conf_if, bgp, bgp->as, as,
2828 as_type, afi, safi, NULL);
2829
2830 if (!peer) {
2831 vty_out(vty, "%% BGP failed to create peer\n");
2832 return CMD_WARNING_CONFIG_FAILED;
2833 }
2834
2835 if (v6only)
2836 peer_flag_set(peer, PEER_FLAG_IFPEER_V6ONLY);
2837
2838 /* Request zebra to initiate IPv6 RAs on this interface. We do
2839 * this
2840 * any unnumbered peer in order to not worry about run-time
2841 * transitions
2842 * (e.g., peering is initially IPv4, but the IPv4 /30 or /31
2843 * address
2844 * gets deleted later etc.)
2845 */
2846 if (peer->ifp)
2847 bgp_zebra_initiate_radv(bgp, peer);
2848 }
2849
2850 if ((v6only && !CHECK_FLAG(peer->flags, PEER_FLAG_IFPEER_V6ONLY))
2851 || (!v6only && CHECK_FLAG(peer->flags, PEER_FLAG_IFPEER_V6ONLY))) {
2852 if (v6only)
2853 peer_flag_set(peer, PEER_FLAG_IFPEER_V6ONLY);
2854 else
2855 peer_flag_unset(peer, PEER_FLAG_IFPEER_V6ONLY);
2856
2857 /* v6only flag changed. Reset bgp seesion */
2858 if (BGP_IS_VALID_STATE_FOR_NOTIF(peer->status)) {
2859 peer->last_reset = PEER_DOWN_V6ONLY_CHANGE;
2860 bgp_notify_send(peer, BGP_NOTIFY_CEASE,
2861 BGP_NOTIFY_CEASE_CONFIG_CHANGE);
2862 } else
2863 bgp_session_reset(peer);
2864 }
2865
2866 if (!CHECK_FLAG(peer->flags_invert, PEER_FLAG_CAPABILITY_ENHE)) {
2867 SET_FLAG(peer->flags, PEER_FLAG_CAPABILITY_ENHE);
2868 SET_FLAG(peer->flags_invert, PEER_FLAG_CAPABILITY_ENHE);
2869 UNSET_FLAG(peer->flags_override, PEER_FLAG_CAPABILITY_ENHE);
2870 }
2871
2872 if (peer_group_name) {
2873 group = peer_group_lookup(bgp, peer_group_name);
2874 if (!group) {
2875 vty_out(vty, "%% Configure the peer-group first\n");
2876 return CMD_WARNING_CONFIG_FAILED;
2877 }
2878
2879 ret = peer_group_bind(bgp, &su, peer, group, &as);
2880 }
2881
2882 return bgp_vty_return(vty, ret);
2883 }
2884
2885 DEFUN (neighbor_interface_config,
2886 neighbor_interface_config_cmd,
2887 "neighbor WORD interface [peer-group WORD]",
2888 NEIGHBOR_STR
2889 "Interface name or neighbor tag\n"
2890 "Enable BGP on interface\n"
2891 "Member of the peer-group\n"
2892 "Peer-group name\n")
2893 {
2894 int idx_word = 1;
2895 int idx_peer_group_word = 4;
2896
2897 if (argc > idx_peer_group_word)
2898 return peer_conf_interface_get(
2899 vty, argv[idx_word]->arg, AFI_IP, SAFI_UNICAST, 0,
2900 argv[idx_peer_group_word]->arg, NULL);
2901 else
2902 return peer_conf_interface_get(vty, argv[idx_word]->arg, AFI_IP,
2903 SAFI_UNICAST, 0, NULL, NULL);
2904 }
2905
2906 DEFUN (neighbor_interface_config_v6only,
2907 neighbor_interface_config_v6only_cmd,
2908 "neighbor WORD interface v6only [peer-group WORD]",
2909 NEIGHBOR_STR
2910 "Interface name or neighbor tag\n"
2911 "Enable BGP on interface\n"
2912 "Enable BGP with v6 link-local only\n"
2913 "Member of the peer-group\n"
2914 "Peer-group name\n")
2915 {
2916 int idx_word = 1;
2917 int idx_peer_group_word = 5;
2918
2919 if (argc > idx_peer_group_word)
2920 return peer_conf_interface_get(
2921 vty, argv[idx_word]->arg, AFI_IP, SAFI_UNICAST, 1,
2922 argv[idx_peer_group_word]->arg, NULL);
2923
2924 return peer_conf_interface_get(vty, argv[idx_word]->arg, AFI_IP,
2925 SAFI_UNICAST, 1, NULL, NULL);
2926 }
2927
2928
2929 DEFUN (neighbor_interface_config_remote_as,
2930 neighbor_interface_config_remote_as_cmd,
2931 "neighbor WORD interface remote-as <(1-4294967295)|internal|external>",
2932 NEIGHBOR_STR
2933 "Interface name or neighbor tag\n"
2934 "Enable BGP on interface\n"
2935 "Specify a BGP neighbor\n"
2936 AS_STR
2937 "Internal BGP peer\n"
2938 "External BGP peer\n")
2939 {
2940 int idx_word = 1;
2941 int idx_remote_as = 4;
2942 return peer_conf_interface_get(vty, argv[idx_word]->arg, AFI_IP,
2943 SAFI_UNICAST, 0, NULL,
2944 argv[idx_remote_as]->arg);
2945 }
2946
2947 DEFUN (neighbor_interface_v6only_config_remote_as,
2948 neighbor_interface_v6only_config_remote_as_cmd,
2949 "neighbor WORD interface v6only remote-as <(1-4294967295)|internal|external>",
2950 NEIGHBOR_STR
2951 "Interface name or neighbor tag\n"
2952 "Enable BGP with v6 link-local only\n"
2953 "Enable BGP on interface\n"
2954 "Specify a BGP neighbor\n"
2955 AS_STR
2956 "Internal BGP peer\n"
2957 "External BGP peer\n")
2958 {
2959 int idx_word = 1;
2960 int idx_remote_as = 5;
2961 return peer_conf_interface_get(vty, argv[idx_word]->arg, AFI_IP,
2962 SAFI_UNICAST, 1, NULL,
2963 argv[idx_remote_as]->arg);
2964 }
2965
2966 DEFUN (neighbor_peer_group,
2967 neighbor_peer_group_cmd,
2968 "neighbor WORD peer-group",
2969 NEIGHBOR_STR
2970 "Interface name or neighbor tag\n"
2971 "Configure peer-group\n")
2972 {
2973 VTY_DECLVAR_CONTEXT(bgp, bgp);
2974 int idx_word = 1;
2975 struct peer *peer;
2976 struct peer_group *group;
2977
2978 peer = peer_lookup_by_conf_if(bgp, argv[idx_word]->arg);
2979 if (peer) {
2980 vty_out(vty, "%% Name conflict with interface: \n");
2981 return CMD_WARNING_CONFIG_FAILED;
2982 }
2983
2984 group = peer_group_get(bgp, argv[idx_word]->arg);
2985 if (!group) {
2986 vty_out(vty, "%% BGP failed to find or create peer-group\n");
2987 return CMD_WARNING_CONFIG_FAILED;
2988 }
2989
2990 return CMD_SUCCESS;
2991 }
2992
2993 DEFUN (no_neighbor,
2994 no_neighbor_cmd,
2995 "no neighbor <WORD|<A.B.C.D|X:X::X:X> [remote-as <(1-4294967295)|internal|external>]>",
2996 NO_STR
2997 NEIGHBOR_STR
2998 NEIGHBOR_ADDR_STR2
2999 "Specify a BGP neighbor\n"
3000 AS_STR
3001 "Internal BGP peer\n"
3002 "External BGP peer\n")
3003 {
3004 VTY_DECLVAR_CONTEXT(bgp, bgp);
3005 int idx_peer = 2;
3006 int ret;
3007 union sockunion su;
3008 struct peer_group *group;
3009 struct peer *peer;
3010 struct peer *other;
3011
3012 ret = str2sockunion(argv[idx_peer]->arg, &su);
3013 if (ret < 0) {
3014 /* look up for neighbor by interface name config. */
3015 peer = peer_lookup_by_conf_if(bgp, argv[idx_peer]->arg);
3016 if (peer) {
3017 /* Request zebra to terminate IPv6 RAs on this
3018 * interface. */
3019 if (peer->ifp)
3020 bgp_zebra_terminate_radv(peer->bgp, peer);
3021 peer_delete(peer);
3022 return CMD_SUCCESS;
3023 }
3024
3025 group = peer_group_lookup(bgp, argv[idx_peer]->arg);
3026 if (group)
3027 peer_group_delete(group);
3028 else {
3029 vty_out(vty, "%% Create the peer-group first\n");
3030 return CMD_WARNING_CONFIG_FAILED;
3031 }
3032 } else {
3033 peer = peer_lookup(bgp, &su);
3034 if (peer) {
3035 if (peer_dynamic_neighbor(peer)) {
3036 vty_out(vty,
3037 "%% Operation not allowed on a dynamic neighbor\n");
3038 return CMD_WARNING_CONFIG_FAILED;
3039 }
3040
3041 other = peer->doppelganger;
3042 peer_delete(peer);
3043 if (other && other->status != Deleted)
3044 peer_delete(other);
3045 }
3046 }
3047
3048 return CMD_SUCCESS;
3049 }
3050
3051 DEFUN (no_neighbor_interface_config,
3052 no_neighbor_interface_config_cmd,
3053 "no neighbor WORD interface [v6only] [peer-group WORD] [remote-as <(1-4294967295)|internal|external>]",
3054 NO_STR
3055 NEIGHBOR_STR
3056 "Interface name\n"
3057 "Configure BGP on interface\n"
3058 "Enable BGP with v6 link-local only\n"
3059 "Member of the peer-group\n"
3060 "Peer-group name\n"
3061 "Specify a BGP neighbor\n"
3062 AS_STR
3063 "Internal BGP peer\n"
3064 "External BGP peer\n")
3065 {
3066 VTY_DECLVAR_CONTEXT(bgp, bgp);
3067 int idx_word = 2;
3068 struct peer *peer;
3069
3070 /* look up for neighbor by interface name config. */
3071 peer = peer_lookup_by_conf_if(bgp, argv[idx_word]->arg);
3072 if (peer) {
3073 /* Request zebra to terminate IPv6 RAs on this interface. */
3074 if (peer->ifp)
3075 bgp_zebra_terminate_radv(peer->bgp, peer);
3076 peer_delete(peer);
3077 } else {
3078 vty_out(vty, "%% Create the bgp interface first\n");
3079 return CMD_WARNING_CONFIG_FAILED;
3080 }
3081 return CMD_SUCCESS;
3082 }
3083
3084 DEFUN (no_neighbor_peer_group,
3085 no_neighbor_peer_group_cmd,
3086 "no neighbor WORD peer-group",
3087 NO_STR
3088 NEIGHBOR_STR
3089 "Neighbor tag\n"
3090 "Configure peer-group\n")
3091 {
3092 VTY_DECLVAR_CONTEXT(bgp, bgp);
3093 int idx_word = 2;
3094 struct peer_group *group;
3095
3096 group = peer_group_lookup(bgp, argv[idx_word]->arg);
3097 if (group)
3098 peer_group_delete(group);
3099 else {
3100 vty_out(vty, "%% Create the peer-group first\n");
3101 return CMD_WARNING_CONFIG_FAILED;
3102 }
3103 return CMD_SUCCESS;
3104 }
3105
3106 DEFUN (no_neighbor_interface_peer_group_remote_as,
3107 no_neighbor_interface_peer_group_remote_as_cmd,
3108 "no neighbor WORD remote-as <(1-4294967295)|internal|external>",
3109 NO_STR
3110 NEIGHBOR_STR
3111 "Interface name or neighbor tag\n"
3112 "Specify a BGP neighbor\n"
3113 AS_STR
3114 "Internal BGP peer\n"
3115 "External BGP peer\n")
3116 {
3117 VTY_DECLVAR_CONTEXT(bgp, bgp);
3118 int idx_word = 2;
3119 struct peer_group *group;
3120 struct peer *peer;
3121
3122 /* look up for neighbor by interface name config. */
3123 peer = peer_lookup_by_conf_if(bgp, argv[idx_word]->arg);
3124 if (peer) {
3125 peer_as_change(peer, 0, AS_SPECIFIED);
3126 return CMD_SUCCESS;
3127 }
3128
3129 group = peer_group_lookup(bgp, argv[idx_word]->arg);
3130 if (group)
3131 peer_group_remote_as_delete(group);
3132 else {
3133 vty_out(vty, "%% Create the peer-group or interface first\n");
3134 return CMD_WARNING_CONFIG_FAILED;
3135 }
3136 return CMD_SUCCESS;
3137 }
3138
3139 DEFUN (neighbor_local_as,
3140 neighbor_local_as_cmd,
3141 "neighbor <A.B.C.D|X:X::X:X|WORD> local-as (1-4294967295)",
3142 NEIGHBOR_STR
3143 NEIGHBOR_ADDR_STR2
3144 "Specify a local-as number\n"
3145 "AS number used as local AS\n")
3146 {
3147 int idx_peer = 1;
3148 int idx_number = 3;
3149 struct peer *peer;
3150 int ret;
3151 as_t as;
3152
3153 peer = peer_and_group_lookup_vty(vty, argv[idx_peer]->arg);
3154 if (!peer)
3155 return CMD_WARNING_CONFIG_FAILED;
3156
3157 as = strtoul(argv[idx_number]->arg, NULL, 10);
3158 ret = peer_local_as_set(peer, as, 0, 0);
3159 return bgp_vty_return(vty, ret);
3160 }
3161
3162 DEFUN (neighbor_local_as_no_prepend,
3163 neighbor_local_as_no_prepend_cmd,
3164 "neighbor <A.B.C.D|X:X::X:X|WORD> local-as (1-4294967295) no-prepend",
3165 NEIGHBOR_STR
3166 NEIGHBOR_ADDR_STR2
3167 "Specify a local-as number\n"
3168 "AS number used as local AS\n"
3169 "Do not prepend local-as to updates from ebgp peers\n")
3170 {
3171 int idx_peer = 1;
3172 int idx_number = 3;
3173 struct peer *peer;
3174 int ret;
3175 as_t as;
3176
3177 peer = peer_and_group_lookup_vty(vty, argv[idx_peer]->arg);
3178 if (!peer)
3179 return CMD_WARNING_CONFIG_FAILED;
3180
3181 as = strtoul(argv[idx_number]->arg, NULL, 10);
3182 ret = peer_local_as_set(peer, as, 1, 0);
3183 return bgp_vty_return(vty, ret);
3184 }
3185
3186 DEFUN (neighbor_local_as_no_prepend_replace_as,
3187 neighbor_local_as_no_prepend_replace_as_cmd,
3188 "neighbor <A.B.C.D|X:X::X:X|WORD> local-as (1-4294967295) no-prepend replace-as",
3189 NEIGHBOR_STR
3190 NEIGHBOR_ADDR_STR2
3191 "Specify a local-as number\n"
3192 "AS number used as local AS\n"
3193 "Do not prepend local-as to updates from ebgp peers\n"
3194 "Do not prepend local-as to updates from ibgp peers\n")
3195 {
3196 int idx_peer = 1;
3197 int idx_number = 3;
3198 struct peer *peer;
3199 int ret;
3200 as_t as;
3201
3202 peer = peer_and_group_lookup_vty(vty, argv[idx_peer]->arg);
3203 if (!peer)
3204 return CMD_WARNING_CONFIG_FAILED;
3205
3206 as = strtoul(argv[idx_number]->arg, NULL, 10);
3207 ret = peer_local_as_set(peer, as, 1, 1);
3208 return bgp_vty_return(vty, ret);
3209 }
3210
3211 DEFUN (no_neighbor_local_as,
3212 no_neighbor_local_as_cmd,
3213 "no neighbor <A.B.C.D|X:X::X:X|WORD> local-as [(1-4294967295) [no-prepend [replace-as]]]",
3214 NO_STR
3215 NEIGHBOR_STR
3216 NEIGHBOR_ADDR_STR2
3217 "Specify a local-as number\n"
3218 "AS number used as local AS\n"
3219 "Do not prepend local-as to updates from ebgp peers\n"
3220 "Do not prepend local-as to updates from ibgp peers\n")
3221 {
3222 int idx_peer = 2;
3223 struct peer *peer;
3224 int ret;
3225
3226 peer = peer_and_group_lookup_vty(vty, argv[idx_peer]->arg);
3227 if (!peer)
3228 return CMD_WARNING_CONFIG_FAILED;
3229
3230 ret = peer_local_as_unset(peer);
3231 return bgp_vty_return(vty, ret);
3232 }
3233
3234
3235 DEFUN (neighbor_solo,
3236 neighbor_solo_cmd,
3237 "neighbor <A.B.C.D|X:X::X:X|WORD> solo",
3238 NEIGHBOR_STR
3239 NEIGHBOR_ADDR_STR2
3240 "Solo peer - part of its own update group\n")
3241 {
3242 int idx_peer = 1;
3243 struct peer *peer;
3244 int ret;
3245
3246 peer = peer_and_group_lookup_vty(vty, argv[idx_peer]->arg);
3247 if (!peer)
3248 return CMD_WARNING_CONFIG_FAILED;
3249
3250 ret = update_group_adjust_soloness(peer, 1);
3251 return bgp_vty_return(vty, ret);
3252 }
3253
3254 DEFUN (no_neighbor_solo,
3255 no_neighbor_solo_cmd,
3256 "no neighbor <A.B.C.D|X:X::X:X|WORD> solo",
3257 NO_STR
3258 NEIGHBOR_STR
3259 NEIGHBOR_ADDR_STR2
3260 "Solo peer - part of its own update group\n")
3261 {
3262 int idx_peer = 2;
3263 struct peer *peer;
3264 int ret;
3265
3266 peer = peer_and_group_lookup_vty(vty, argv[idx_peer]->arg);
3267 if (!peer)
3268 return CMD_WARNING_CONFIG_FAILED;
3269
3270 ret = update_group_adjust_soloness(peer, 0);
3271 return bgp_vty_return(vty, ret);
3272 }
3273
3274 DEFUN (neighbor_password,
3275 neighbor_password_cmd,
3276 "neighbor <A.B.C.D|X:X::X:X|WORD> password LINE",
3277 NEIGHBOR_STR
3278 NEIGHBOR_ADDR_STR2
3279 "Set a password\n"
3280 "The password\n")
3281 {
3282 int idx_peer = 1;
3283 int idx_line = 3;
3284 struct peer *peer;
3285 int ret;
3286
3287 peer = peer_and_group_lookup_vty(vty, argv[idx_peer]->arg);
3288 if (!peer)
3289 return CMD_WARNING_CONFIG_FAILED;
3290
3291 ret = peer_password_set(peer, argv[idx_line]->arg);
3292 return bgp_vty_return(vty, ret);
3293 }
3294
3295 DEFUN (no_neighbor_password,
3296 no_neighbor_password_cmd,
3297 "no neighbor <A.B.C.D|X:X::X:X|WORD> password [LINE]",
3298 NO_STR
3299 NEIGHBOR_STR
3300 NEIGHBOR_ADDR_STR2
3301 "Set a password\n"
3302 "The password\n")
3303 {
3304 int idx_peer = 2;
3305 struct peer *peer;
3306 int ret;
3307
3308 peer = peer_and_group_lookup_vty(vty, argv[idx_peer]->arg);
3309 if (!peer)
3310 return CMD_WARNING_CONFIG_FAILED;
3311
3312 ret = peer_password_unset(peer);
3313 return bgp_vty_return(vty, ret);
3314 }
3315
3316 DEFUN (neighbor_activate,
3317 neighbor_activate_cmd,
3318 "neighbor <A.B.C.D|X:X::X:X|WORD> activate",
3319 NEIGHBOR_STR
3320 NEIGHBOR_ADDR_STR2
3321 "Enable the Address Family for this Neighbor\n")
3322 {
3323 int idx_peer = 1;
3324 int ret;
3325 struct peer *peer;
3326
3327 peer = peer_and_group_lookup_vty(vty, argv[idx_peer]->arg);
3328 if (!peer)
3329 return CMD_WARNING_CONFIG_FAILED;
3330
3331 ret = peer_activate(peer, bgp_node_afi(vty), bgp_node_safi(vty));
3332 return bgp_vty_return(vty, ret);
3333 }
3334
3335 ALIAS_HIDDEN(neighbor_activate, neighbor_activate_hidden_cmd,
3336 "neighbor <A.B.C.D|X:X::X:X|WORD> activate",
3337 NEIGHBOR_STR NEIGHBOR_ADDR_STR2
3338 "Enable the Address Family for this Neighbor\n")
3339
3340 DEFUN (no_neighbor_activate,
3341 no_neighbor_activate_cmd,
3342 "no neighbor <A.B.C.D|X:X::X:X|WORD> activate",
3343 NO_STR
3344 NEIGHBOR_STR
3345 NEIGHBOR_ADDR_STR2
3346 "Enable the Address Family for this Neighbor\n")
3347 {
3348 int idx_peer = 2;
3349 int ret;
3350 struct peer *peer;
3351
3352 /* Lookup peer. */
3353 peer = peer_and_group_lookup_vty(vty, argv[idx_peer]->arg);
3354 if (!peer)
3355 return CMD_WARNING_CONFIG_FAILED;
3356
3357 ret = peer_deactivate(peer, bgp_node_afi(vty), bgp_node_safi(vty));
3358 return bgp_vty_return(vty, ret);
3359 }
3360
3361 ALIAS_HIDDEN(no_neighbor_activate, no_neighbor_activate_hidden_cmd,
3362 "no neighbor <A.B.C.D|X:X::X:X|WORD> activate",
3363 NO_STR NEIGHBOR_STR NEIGHBOR_ADDR_STR2
3364 "Enable the Address Family for this Neighbor\n")
3365
3366 DEFUN (neighbor_set_peer_group,
3367 neighbor_set_peer_group_cmd,
3368 "neighbor <A.B.C.D|X:X::X:X|WORD> peer-group WORD",
3369 NEIGHBOR_STR
3370 NEIGHBOR_ADDR_STR2
3371 "Member of the peer-group\n"
3372 "Peer-group name\n")
3373 {
3374 VTY_DECLVAR_CONTEXT(bgp, bgp);
3375 int idx_peer = 1;
3376 int idx_word = 3;
3377 int ret;
3378 as_t as;
3379 union sockunion su;
3380 struct peer *peer;
3381 struct peer_group *group;
3382
3383 ret = str2sockunion(argv[idx_peer]->arg, &su);
3384 if (ret < 0) {
3385 peer = peer_lookup_by_conf_if(bgp, argv[idx_peer]->arg);
3386 if (!peer) {
3387 vty_out(vty, "%% Malformed address or name: %s\n",
3388 argv[idx_peer]->arg);
3389 return CMD_WARNING_CONFIG_FAILED;
3390 }
3391 } else {
3392 if (peer_address_self_check(bgp, &su)) {
3393 vty_out(vty,
3394 "%% Can not configure the local system as neighbor\n");
3395 return CMD_WARNING_CONFIG_FAILED;
3396 }
3397
3398 /* Disallow for dynamic neighbor. */
3399 peer = peer_lookup(bgp, &su);
3400 if (peer && peer_dynamic_neighbor(peer)) {
3401 vty_out(vty,
3402 "%% Operation not allowed on a dynamic neighbor\n");
3403 return CMD_WARNING_CONFIG_FAILED;
3404 }
3405 }
3406
3407 group = peer_group_lookup(bgp, argv[idx_word]->arg);
3408 if (!group) {
3409 vty_out(vty, "%% Configure the peer-group first\n");
3410 return CMD_WARNING_CONFIG_FAILED;
3411 }
3412
3413 ret = peer_group_bind(bgp, &su, peer, group, &as);
3414
3415 if (ret == BGP_ERR_PEER_GROUP_PEER_TYPE_DIFFERENT) {
3416 vty_out(vty,
3417 "%% Peer with AS %u cannot be in this peer-group, members must be all internal or all external\n",
3418 as);
3419 return CMD_WARNING_CONFIG_FAILED;
3420 }
3421
3422 return bgp_vty_return(vty, ret);
3423 }
3424
3425 ALIAS_HIDDEN(neighbor_set_peer_group, neighbor_set_peer_group_hidden_cmd,
3426 "neighbor <A.B.C.D|X:X::X:X|WORD> peer-group WORD",
3427 NEIGHBOR_STR NEIGHBOR_ADDR_STR2
3428 "Member of the peer-group\n"
3429 "Peer-group name\n")
3430
3431 DEFUN (no_neighbor_set_peer_group,
3432 no_neighbor_set_peer_group_cmd,
3433 "no neighbor <A.B.C.D|X:X::X:X|WORD> peer-group WORD",
3434 NO_STR
3435 NEIGHBOR_STR
3436 NEIGHBOR_ADDR_STR2
3437 "Member of the peer-group\n"
3438 "Peer-group name\n")
3439 {
3440 VTY_DECLVAR_CONTEXT(bgp, bgp);
3441 int idx_peer = 2;
3442 int idx_word = 4;
3443 int ret;
3444 struct peer *peer;
3445 struct peer_group *group;
3446
3447 peer = peer_lookup_vty(vty, argv[idx_peer]->arg);
3448 if (!peer)
3449 return CMD_WARNING_CONFIG_FAILED;
3450
3451 group = peer_group_lookup(bgp, argv[idx_word]->arg);
3452 if (!group) {
3453 vty_out(vty, "%% Configure the peer-group first\n");
3454 return CMD_WARNING_CONFIG_FAILED;
3455 }
3456
3457 ret = peer_delete(peer);
3458
3459 return bgp_vty_return(vty, ret);
3460 }
3461
3462 ALIAS_HIDDEN(no_neighbor_set_peer_group, no_neighbor_set_peer_group_hidden_cmd,
3463 "no neighbor <A.B.C.D|X:X::X:X|WORD> peer-group WORD",
3464 NO_STR NEIGHBOR_STR NEIGHBOR_ADDR_STR2
3465 "Member of the peer-group\n"
3466 "Peer-group name\n")
3467
3468 static int peer_flag_modify_vty(struct vty *vty, const char *ip_str,
3469 uint32_t flag, int set)
3470 {
3471 int ret;
3472 struct peer *peer;
3473
3474 peer = peer_and_group_lookup_vty(vty, ip_str);
3475 if (!peer)
3476 return CMD_WARNING_CONFIG_FAILED;
3477
3478 /*
3479 * If 'neighbor <interface>', then this is for directly connected peers,
3480 * we should not accept disable-connected-check.
3481 */
3482 if (peer->conf_if && (flag == PEER_FLAG_DISABLE_CONNECTED_CHECK)) {
3483 vty_out(vty,
3484 "%s is directly connected peer, cannot accept disable-"
3485 "connected-check\n",
3486 ip_str);
3487 return CMD_WARNING_CONFIG_FAILED;
3488 }
3489
3490 if (!set && flag == PEER_FLAG_SHUTDOWN)
3491 peer_tx_shutdown_message_unset(peer);
3492
3493 if (set)
3494 ret = peer_flag_set(peer, flag);
3495 else
3496 ret = peer_flag_unset(peer, flag);
3497
3498 return bgp_vty_return(vty, ret);
3499 }
3500
3501 static int peer_flag_set_vty(struct vty *vty, const char *ip_str, uint32_t flag)
3502 {
3503 return peer_flag_modify_vty(vty, ip_str, flag, 1);
3504 }
3505
3506 static int peer_flag_unset_vty(struct vty *vty, const char *ip_str,
3507 uint32_t flag)
3508 {
3509 return peer_flag_modify_vty(vty, ip_str, flag, 0);
3510 }
3511
3512 /* neighbor passive. */
3513 DEFUN (neighbor_passive,
3514 neighbor_passive_cmd,
3515 "neighbor <A.B.C.D|X:X::X:X|WORD> passive",
3516 NEIGHBOR_STR
3517 NEIGHBOR_ADDR_STR2
3518 "Don't send open messages to this neighbor\n")
3519 {
3520 int idx_peer = 1;
3521 return peer_flag_set_vty(vty, argv[idx_peer]->arg, PEER_FLAG_PASSIVE);
3522 }
3523
3524 DEFUN (no_neighbor_passive,
3525 no_neighbor_passive_cmd,
3526 "no neighbor <A.B.C.D|X:X::X:X|WORD> passive",
3527 NO_STR
3528 NEIGHBOR_STR
3529 NEIGHBOR_ADDR_STR2
3530 "Don't send open messages to this neighbor\n")
3531 {
3532 int idx_peer = 2;
3533 return peer_flag_unset_vty(vty, argv[idx_peer]->arg, PEER_FLAG_PASSIVE);
3534 }
3535
3536 /* neighbor shutdown. */
3537 DEFUN (neighbor_shutdown_msg,
3538 neighbor_shutdown_msg_cmd,
3539 "neighbor <A.B.C.D|X:X::X:X|WORD> shutdown message MSG...",
3540 NEIGHBOR_STR
3541 NEIGHBOR_ADDR_STR2
3542 "Administratively shut down this neighbor\n"
3543 "Add a shutdown message (draft-ietf-idr-shutdown-06)\n"
3544 "Shutdown message\n")
3545 {
3546 int idx_peer = 1;
3547
3548 if (argc >= 5) {
3549 struct peer *peer =
3550 peer_and_group_lookup_vty(vty, argv[idx_peer]->arg);
3551 char *message;
3552
3553 if (!peer)
3554 return CMD_WARNING_CONFIG_FAILED;
3555 message = argv_concat(argv, argc, 4);
3556 peer_tx_shutdown_message_set(peer, message);
3557 XFREE(MTYPE_TMP, message);
3558 }
3559
3560 return peer_flag_set_vty(vty, argv[idx_peer]->arg, PEER_FLAG_SHUTDOWN);
3561 }
3562
3563 ALIAS(neighbor_shutdown_msg, neighbor_shutdown_cmd,
3564 "neighbor <A.B.C.D|X:X::X:X|WORD> shutdown",
3565 NEIGHBOR_STR NEIGHBOR_ADDR_STR2
3566 "Administratively shut down this neighbor\n")
3567
3568 DEFUN (no_neighbor_shutdown_msg,
3569 no_neighbor_shutdown_msg_cmd,
3570 "no neighbor <A.B.C.D|X:X::X:X|WORD> shutdown message MSG...",
3571 NO_STR
3572 NEIGHBOR_STR
3573 NEIGHBOR_ADDR_STR2
3574 "Administratively shut down this neighbor\n"
3575 "Remove a shutdown message (draft-ietf-idr-shutdown-06)\n"
3576 "Shutdown message\n")
3577 {
3578 int idx_peer = 2;
3579
3580 return peer_flag_unset_vty(vty, argv[idx_peer]->arg,
3581 PEER_FLAG_SHUTDOWN);
3582 }
3583
3584 ALIAS(no_neighbor_shutdown_msg, no_neighbor_shutdown_cmd,
3585 "no neighbor <A.B.C.D|X:X::X:X|WORD> shutdown",
3586 NO_STR NEIGHBOR_STR NEIGHBOR_ADDR_STR2
3587 "Administratively shut down this neighbor\n")
3588
3589 /* neighbor capability dynamic. */
3590 DEFUN (neighbor_capability_dynamic,
3591 neighbor_capability_dynamic_cmd,
3592 "neighbor <A.B.C.D|X:X::X:X|WORD> capability dynamic",
3593 NEIGHBOR_STR
3594 NEIGHBOR_ADDR_STR2
3595 "Advertise capability to the peer\n"
3596 "Advertise dynamic capability to this neighbor\n")
3597 {
3598 int idx_peer = 1;
3599 return peer_flag_set_vty(vty, argv[idx_peer]->arg,
3600 PEER_FLAG_DYNAMIC_CAPABILITY);
3601 }
3602
3603 DEFUN (no_neighbor_capability_dynamic,
3604 no_neighbor_capability_dynamic_cmd,
3605 "no neighbor <A.B.C.D|X:X::X:X|WORD> capability dynamic",
3606 NO_STR
3607 NEIGHBOR_STR
3608 NEIGHBOR_ADDR_STR2
3609 "Advertise capability to the peer\n"
3610 "Advertise dynamic capability to this neighbor\n")
3611 {
3612 int idx_peer = 2;
3613 return peer_flag_unset_vty(vty, argv[idx_peer]->arg,
3614 PEER_FLAG_DYNAMIC_CAPABILITY);
3615 }
3616
3617 /* neighbor dont-capability-negotiate */
3618 DEFUN (neighbor_dont_capability_negotiate,
3619 neighbor_dont_capability_negotiate_cmd,
3620 "neighbor <A.B.C.D|X:X::X:X|WORD> dont-capability-negotiate",
3621 NEIGHBOR_STR
3622 NEIGHBOR_ADDR_STR2
3623 "Do not perform capability negotiation\n")
3624 {
3625 int idx_peer = 1;
3626 return peer_flag_set_vty(vty, argv[idx_peer]->arg,
3627 PEER_FLAG_DONT_CAPABILITY);
3628 }
3629
3630 DEFUN (no_neighbor_dont_capability_negotiate,
3631 no_neighbor_dont_capability_negotiate_cmd,
3632 "no neighbor <A.B.C.D|X:X::X:X|WORD> dont-capability-negotiate",
3633 NO_STR
3634 NEIGHBOR_STR
3635 NEIGHBOR_ADDR_STR2
3636 "Do not perform capability negotiation\n")
3637 {
3638 int idx_peer = 2;
3639 return peer_flag_unset_vty(vty, argv[idx_peer]->arg,
3640 PEER_FLAG_DONT_CAPABILITY);
3641 }
3642
3643 /* neighbor capability extended next hop encoding */
3644 DEFUN (neighbor_capability_enhe,
3645 neighbor_capability_enhe_cmd,
3646 "neighbor <A.B.C.D|X:X::X:X|WORD> capability extended-nexthop",
3647 NEIGHBOR_STR
3648 NEIGHBOR_ADDR_STR2
3649 "Advertise capability to the peer\n"
3650 "Advertise extended next-hop capability to the peer\n")
3651 {
3652 int idx_peer = 1;
3653 return peer_flag_set_vty(vty, argv[idx_peer]->arg,
3654 PEER_FLAG_CAPABILITY_ENHE);
3655 }
3656
3657 DEFUN (no_neighbor_capability_enhe,
3658 no_neighbor_capability_enhe_cmd,
3659 "no neighbor <A.B.C.D|X:X::X:X|WORD> capability extended-nexthop",
3660 NO_STR
3661 NEIGHBOR_STR
3662 NEIGHBOR_ADDR_STR2
3663 "Advertise capability to the peer\n"
3664 "Advertise extended next-hop capability to the peer\n")
3665 {
3666 int idx_peer = 2;
3667 return peer_flag_unset_vty(vty, argv[idx_peer]->arg,
3668 PEER_FLAG_CAPABILITY_ENHE);
3669 }
3670
3671 static int peer_af_flag_modify_vty(struct vty *vty, const char *peer_str,
3672 afi_t afi, safi_t safi, uint32_t flag,
3673 int set)
3674 {
3675 int ret;
3676 struct peer *peer;
3677
3678 peer = peer_and_group_lookup_vty(vty, peer_str);
3679 if (!peer)
3680 return CMD_WARNING_CONFIG_FAILED;
3681
3682 if (set)
3683 ret = peer_af_flag_set(peer, afi, safi, flag);
3684 else
3685 ret = peer_af_flag_unset(peer, afi, safi, flag);
3686
3687 return bgp_vty_return(vty, ret);
3688 }
3689
3690 static int peer_af_flag_set_vty(struct vty *vty, const char *peer_str,
3691 afi_t afi, safi_t safi, uint32_t flag)
3692 {
3693 return peer_af_flag_modify_vty(vty, peer_str, afi, safi, flag, 1);
3694 }
3695
3696 static int peer_af_flag_unset_vty(struct vty *vty, const char *peer_str,
3697 afi_t afi, safi_t safi, uint32_t flag)
3698 {
3699 return peer_af_flag_modify_vty(vty, peer_str, afi, safi, flag, 0);
3700 }
3701
3702 /* neighbor capability orf prefix-list. */
3703 DEFUN (neighbor_capability_orf_prefix,
3704 neighbor_capability_orf_prefix_cmd,
3705 "neighbor <A.B.C.D|X:X::X:X|WORD> capability orf prefix-list <both|send|receive>",
3706 NEIGHBOR_STR
3707 NEIGHBOR_ADDR_STR2
3708 "Advertise capability to the peer\n"
3709 "Advertise ORF capability to the peer\n"
3710 "Advertise prefixlist ORF capability to this neighbor\n"
3711 "Capability to SEND and RECEIVE the ORF to/from this neighbor\n"
3712 "Capability to RECEIVE the ORF from this neighbor\n"
3713 "Capability to SEND the ORF to this neighbor\n")
3714 {
3715 int idx_peer = 1;
3716 int idx_send_recv = 5;
3717 uint16_t flag = 0;
3718
3719 if (strmatch(argv[idx_send_recv]->text, "send"))
3720 flag = PEER_FLAG_ORF_PREFIX_SM;
3721 else if (strmatch(argv[idx_send_recv]->text, "receive"))
3722 flag = PEER_FLAG_ORF_PREFIX_RM;
3723 else if (strmatch(argv[idx_send_recv]->text, "both"))
3724 flag = PEER_FLAG_ORF_PREFIX_SM | PEER_FLAG_ORF_PREFIX_RM;
3725 else {
3726 vty_out(vty, "%% BGP invalid orf prefix-list option\n");
3727 return CMD_WARNING_CONFIG_FAILED;
3728 }
3729
3730 return peer_af_flag_set_vty(vty, argv[idx_peer]->arg, bgp_node_afi(vty),
3731 bgp_node_safi(vty), flag);
3732 }
3733
3734 ALIAS_HIDDEN(
3735 neighbor_capability_orf_prefix,
3736 neighbor_capability_orf_prefix_hidden_cmd,
3737 "neighbor <A.B.C.D|X:X::X:X|WORD> capability orf prefix-list <both|send|receive>",
3738 NEIGHBOR_STR NEIGHBOR_ADDR_STR2
3739 "Advertise capability to the peer\n"
3740 "Advertise ORF capability to the peer\n"
3741 "Advertise prefixlist ORF capability to this neighbor\n"
3742 "Capability to SEND and RECEIVE the ORF to/from this neighbor\n"
3743 "Capability to RECEIVE the ORF from this neighbor\n"
3744 "Capability to SEND the ORF to this neighbor\n")
3745
3746 DEFUN (no_neighbor_capability_orf_prefix,
3747 no_neighbor_capability_orf_prefix_cmd,
3748 "no neighbor <A.B.C.D|X:X::X:X|WORD> capability orf prefix-list <both|send|receive>",
3749 NO_STR
3750 NEIGHBOR_STR
3751 NEIGHBOR_ADDR_STR2
3752 "Advertise capability to the peer\n"
3753 "Advertise ORF capability to the peer\n"
3754 "Advertise prefixlist ORF capability to this neighbor\n"
3755 "Capability to SEND and RECEIVE the ORF to/from this neighbor\n"
3756 "Capability to RECEIVE the ORF from this neighbor\n"
3757 "Capability to SEND the ORF to this neighbor\n")
3758 {
3759 int idx_peer = 2;
3760 int idx_send_recv = 6;
3761 uint16_t flag = 0;
3762
3763 if (strmatch(argv[idx_send_recv]->text, "send"))
3764 flag = PEER_FLAG_ORF_PREFIX_SM;
3765 else if (strmatch(argv[idx_send_recv]->text, "receive"))
3766 flag = PEER_FLAG_ORF_PREFIX_RM;
3767 else if (strmatch(argv[idx_send_recv]->text, "both"))
3768 flag = PEER_FLAG_ORF_PREFIX_SM | PEER_FLAG_ORF_PREFIX_RM;
3769 else {
3770 vty_out(vty, "%% BGP invalid orf prefix-list option\n");
3771 return CMD_WARNING_CONFIG_FAILED;
3772 }
3773
3774 return peer_af_flag_unset_vty(vty, argv[idx_peer]->arg,
3775 bgp_node_afi(vty), bgp_node_safi(vty),
3776 flag);
3777 }
3778
3779 ALIAS_HIDDEN(
3780 no_neighbor_capability_orf_prefix,
3781 no_neighbor_capability_orf_prefix_hidden_cmd,
3782 "no neighbor <A.B.C.D|X:X::X:X|WORD> capability orf prefix-list <both|send|receive>",
3783 NO_STR NEIGHBOR_STR NEIGHBOR_ADDR_STR2
3784 "Advertise capability to the peer\n"
3785 "Advertise ORF capability to the peer\n"
3786 "Advertise prefixlist ORF capability to this neighbor\n"
3787 "Capability to SEND and RECEIVE the ORF to/from this neighbor\n"
3788 "Capability to RECEIVE the ORF from this neighbor\n"
3789 "Capability to SEND the ORF to this neighbor\n")
3790
3791 /* neighbor next-hop-self. */
3792 DEFUN (neighbor_nexthop_self,
3793 neighbor_nexthop_self_cmd,
3794 "neighbor <A.B.C.D|X:X::X:X|WORD> next-hop-self",
3795 NEIGHBOR_STR
3796 NEIGHBOR_ADDR_STR2
3797 "Disable the next hop calculation for this neighbor\n")
3798 {
3799 int idx_peer = 1;
3800 return peer_af_flag_set_vty(vty, argv[idx_peer]->arg, bgp_node_afi(vty),
3801 bgp_node_safi(vty), PEER_FLAG_NEXTHOP_SELF);
3802 }
3803
3804 ALIAS_HIDDEN(neighbor_nexthop_self, neighbor_nexthop_self_hidden_cmd,
3805 "neighbor <A.B.C.D|X:X::X:X|WORD> next-hop-self",
3806 NEIGHBOR_STR NEIGHBOR_ADDR_STR2
3807 "Disable the next hop calculation for this neighbor\n")
3808
3809 /* neighbor next-hop-self. */
3810 DEFUN (neighbor_nexthop_self_force,
3811 neighbor_nexthop_self_force_cmd,
3812 "neighbor <A.B.C.D|X:X::X:X|WORD> next-hop-self force",
3813 NEIGHBOR_STR
3814 NEIGHBOR_ADDR_STR2
3815 "Disable the next hop calculation for this neighbor\n"
3816 "Set the next hop to self for reflected routes\n")
3817 {
3818 int idx_peer = 1;
3819 return peer_af_flag_set_vty(vty, argv[idx_peer]->arg, bgp_node_afi(vty),
3820 bgp_node_safi(vty),
3821 PEER_FLAG_FORCE_NEXTHOP_SELF);
3822 }
3823
3824 ALIAS_HIDDEN(neighbor_nexthop_self_force,
3825 neighbor_nexthop_self_force_hidden_cmd,
3826 "neighbor <A.B.C.D|X:X::X:X|WORD> next-hop-self force",
3827 NEIGHBOR_STR NEIGHBOR_ADDR_STR2
3828 "Disable the next hop calculation for this neighbor\n"
3829 "Set the next hop to self for reflected routes\n")
3830
3831 DEFUN (no_neighbor_nexthop_self,
3832 no_neighbor_nexthop_self_cmd,
3833 "no neighbor <A.B.C.D|X:X::X:X|WORD> next-hop-self",
3834 NO_STR
3835 NEIGHBOR_STR
3836 NEIGHBOR_ADDR_STR2
3837 "Disable the next hop calculation for this neighbor\n")
3838 {
3839 int idx_peer = 2;
3840 return peer_af_flag_unset_vty(vty, argv[idx_peer]->arg,
3841 bgp_node_afi(vty), bgp_node_safi(vty),
3842 PEER_FLAG_NEXTHOP_SELF);
3843 }
3844
3845 ALIAS_HIDDEN(no_neighbor_nexthop_self, no_neighbor_nexthop_self_hidden_cmd,
3846 "no neighbor <A.B.C.D|X:X::X:X|WORD> next-hop-self",
3847 NO_STR NEIGHBOR_STR NEIGHBOR_ADDR_STR2
3848 "Disable the next hop calculation for this neighbor\n")
3849
3850 DEFUN (no_neighbor_nexthop_self_force,
3851 no_neighbor_nexthop_self_force_cmd,
3852 "no neighbor <A.B.C.D|X:X::X:X|WORD> next-hop-self force",
3853 NO_STR
3854 NEIGHBOR_STR
3855 NEIGHBOR_ADDR_STR2
3856 "Disable the next hop calculation for this neighbor\n"
3857 "Set the next hop to self for reflected routes\n")
3858 {
3859 int idx_peer = 2;
3860 return peer_af_flag_unset_vty(vty, argv[idx_peer]->arg,
3861 bgp_node_afi(vty), bgp_node_safi(vty),
3862 PEER_FLAG_FORCE_NEXTHOP_SELF);
3863 }
3864
3865 ALIAS_HIDDEN(no_neighbor_nexthop_self_force,
3866 no_neighbor_nexthop_self_force_hidden_cmd,
3867 "no neighbor <A.B.C.D|X:X::X:X|WORD> next-hop-self force",
3868 NO_STR NEIGHBOR_STR NEIGHBOR_ADDR_STR2
3869 "Disable the next hop calculation for this neighbor\n"
3870 "Set the next hop to self for reflected routes\n")
3871
3872 /* neighbor as-override */
3873 DEFUN (neighbor_as_override,
3874 neighbor_as_override_cmd,
3875 "neighbor <A.B.C.D|X:X::X:X|WORD> as-override",
3876 NEIGHBOR_STR
3877 NEIGHBOR_ADDR_STR2
3878 "Override ASNs in outbound updates if aspath equals remote-as\n")
3879 {
3880 int idx_peer = 1;
3881 return peer_af_flag_set_vty(vty, argv[idx_peer]->arg, bgp_node_afi(vty),
3882 bgp_node_safi(vty), PEER_FLAG_AS_OVERRIDE);
3883 }
3884
3885 ALIAS_HIDDEN(neighbor_as_override, neighbor_as_override_hidden_cmd,
3886 "neighbor <A.B.C.D|X:X::X:X|WORD> as-override",
3887 NEIGHBOR_STR NEIGHBOR_ADDR_STR2
3888 "Override ASNs in outbound updates if aspath equals remote-as\n")
3889
3890 DEFUN (no_neighbor_as_override,
3891 no_neighbor_as_override_cmd,
3892 "no neighbor <A.B.C.D|X:X::X:X|WORD> as-override",
3893 NO_STR
3894 NEIGHBOR_STR
3895 NEIGHBOR_ADDR_STR2
3896 "Override ASNs in outbound updates if aspath equals remote-as\n")
3897 {
3898 int idx_peer = 2;
3899 return peer_af_flag_unset_vty(vty, argv[idx_peer]->arg,
3900 bgp_node_afi(vty), bgp_node_safi(vty),
3901 PEER_FLAG_AS_OVERRIDE);
3902 }
3903
3904 ALIAS_HIDDEN(no_neighbor_as_override, no_neighbor_as_override_hidden_cmd,
3905 "no neighbor <A.B.C.D|X:X::X:X|WORD> as-override",
3906 NO_STR NEIGHBOR_STR NEIGHBOR_ADDR_STR2
3907 "Override ASNs in outbound updates if aspath equals remote-as\n")
3908
3909 /* neighbor remove-private-AS. */
3910 DEFUN (neighbor_remove_private_as,
3911 neighbor_remove_private_as_cmd,
3912 "neighbor <A.B.C.D|X:X::X:X|WORD> remove-private-AS",
3913 NEIGHBOR_STR
3914 NEIGHBOR_ADDR_STR2
3915 "Remove private ASNs in outbound updates\n")
3916 {
3917 int idx_peer = 1;
3918 return peer_af_flag_set_vty(vty, argv[idx_peer]->arg, bgp_node_afi(vty),
3919 bgp_node_safi(vty),
3920 PEER_FLAG_REMOVE_PRIVATE_AS);
3921 }
3922
3923 ALIAS_HIDDEN(neighbor_remove_private_as, neighbor_remove_private_as_hidden_cmd,
3924 "neighbor <A.B.C.D|X:X::X:X|WORD> remove-private-AS",
3925 NEIGHBOR_STR NEIGHBOR_ADDR_STR2
3926 "Remove private ASNs in outbound updates\n")
3927
3928 DEFUN (neighbor_remove_private_as_all,
3929 neighbor_remove_private_as_all_cmd,
3930 "neighbor <A.B.C.D|X:X::X:X|WORD> remove-private-AS all",
3931 NEIGHBOR_STR
3932 NEIGHBOR_ADDR_STR2
3933 "Remove private ASNs in outbound updates\n"
3934 "Apply to all AS numbers\n")
3935 {
3936 int idx_peer = 1;
3937 return peer_af_flag_set_vty(vty, argv[idx_peer]->arg, bgp_node_afi(vty),
3938 bgp_node_safi(vty),
3939 PEER_FLAG_REMOVE_PRIVATE_AS_ALL);
3940 }
3941
3942 ALIAS_HIDDEN(neighbor_remove_private_as_all,
3943 neighbor_remove_private_as_all_hidden_cmd,
3944 "neighbor <A.B.C.D|X:X::X:X|WORD> remove-private-AS all",
3945 NEIGHBOR_STR NEIGHBOR_ADDR_STR2
3946 "Remove private ASNs in outbound updates\n"
3947 "Apply to all AS numbers")
3948
3949 DEFUN (neighbor_remove_private_as_replace_as,
3950 neighbor_remove_private_as_replace_as_cmd,
3951 "neighbor <A.B.C.D|X:X::X:X|WORD> remove-private-AS replace-AS",
3952 NEIGHBOR_STR
3953 NEIGHBOR_ADDR_STR2
3954 "Remove private ASNs in outbound updates\n"
3955 "Replace private ASNs with our ASN in outbound updates\n")
3956 {
3957 int idx_peer = 1;
3958 return peer_af_flag_set_vty(vty, argv[idx_peer]->arg, bgp_node_afi(vty),
3959 bgp_node_safi(vty),
3960 PEER_FLAG_REMOVE_PRIVATE_AS_REPLACE);
3961 }
3962
3963 ALIAS_HIDDEN(neighbor_remove_private_as_replace_as,
3964 neighbor_remove_private_as_replace_as_hidden_cmd,
3965 "neighbor <A.B.C.D|X:X::X:X|WORD> remove-private-AS replace-AS",
3966 NEIGHBOR_STR NEIGHBOR_ADDR_STR2
3967 "Remove private ASNs in outbound updates\n"
3968 "Replace private ASNs with our ASN in outbound updates\n")
3969
3970 DEFUN (neighbor_remove_private_as_all_replace_as,
3971 neighbor_remove_private_as_all_replace_as_cmd,
3972 "neighbor <A.B.C.D|X:X::X:X|WORD> remove-private-AS all replace-AS",
3973 NEIGHBOR_STR
3974 NEIGHBOR_ADDR_STR2
3975 "Remove private ASNs in outbound updates\n"
3976 "Apply to all AS numbers\n"
3977 "Replace private ASNs with our ASN in outbound updates\n")
3978 {
3979 int idx_peer = 1;
3980 return peer_af_flag_set_vty(vty, argv[idx_peer]->arg, bgp_node_afi(vty),
3981 bgp_node_safi(vty),
3982 PEER_FLAG_REMOVE_PRIVATE_AS_ALL_REPLACE);
3983 }
3984
3985 ALIAS_HIDDEN(
3986 neighbor_remove_private_as_all_replace_as,
3987 neighbor_remove_private_as_all_replace_as_hidden_cmd,
3988 "neighbor <A.B.C.D|X:X::X:X|WORD> remove-private-AS all replace-AS",
3989 NEIGHBOR_STR NEIGHBOR_ADDR_STR2
3990 "Remove private ASNs in outbound updates\n"
3991 "Apply to all AS numbers\n"
3992 "Replace private ASNs with our ASN in outbound updates\n")
3993
3994 DEFUN (no_neighbor_remove_private_as,
3995 no_neighbor_remove_private_as_cmd,
3996 "no neighbor <A.B.C.D|X:X::X:X|WORD> remove-private-AS",
3997 NO_STR
3998 NEIGHBOR_STR
3999 NEIGHBOR_ADDR_STR2
4000 "Remove private ASNs in outbound updates\n")
4001 {
4002 int idx_peer = 2;
4003 return peer_af_flag_unset_vty(vty, argv[idx_peer]->arg,
4004 bgp_node_afi(vty), bgp_node_safi(vty),
4005 PEER_FLAG_REMOVE_PRIVATE_AS);
4006 }
4007
4008 ALIAS_HIDDEN(no_neighbor_remove_private_as,
4009 no_neighbor_remove_private_as_hidden_cmd,
4010 "no neighbor <A.B.C.D|X:X::X:X|WORD> remove-private-AS",
4011 NO_STR NEIGHBOR_STR NEIGHBOR_ADDR_STR2
4012 "Remove private ASNs in outbound updates\n")
4013
4014 DEFUN (no_neighbor_remove_private_as_all,
4015 no_neighbor_remove_private_as_all_cmd,
4016 "no neighbor <A.B.C.D|X:X::X:X|WORD> remove-private-AS all",
4017 NO_STR
4018 NEIGHBOR_STR
4019 NEIGHBOR_ADDR_STR2
4020 "Remove private ASNs in outbound updates\n"
4021 "Apply to all AS numbers\n")
4022 {
4023 int idx_peer = 2;
4024 return peer_af_flag_unset_vty(vty, argv[idx_peer]->arg,
4025 bgp_node_afi(vty), bgp_node_safi(vty),
4026 PEER_FLAG_REMOVE_PRIVATE_AS_ALL);
4027 }
4028
4029 ALIAS_HIDDEN(no_neighbor_remove_private_as_all,
4030 no_neighbor_remove_private_as_all_hidden_cmd,
4031 "no neighbor <A.B.C.D|X:X::X:X|WORD> remove-private-AS all",
4032 NO_STR NEIGHBOR_STR NEIGHBOR_ADDR_STR2
4033 "Remove private ASNs in outbound updates\n"
4034 "Apply to all AS numbers\n")
4035
4036 DEFUN (no_neighbor_remove_private_as_replace_as,
4037 no_neighbor_remove_private_as_replace_as_cmd,
4038 "no neighbor <A.B.C.D|X:X::X:X|WORD> remove-private-AS replace-AS",
4039 NO_STR
4040 NEIGHBOR_STR
4041 NEIGHBOR_ADDR_STR2
4042 "Remove private ASNs in outbound updates\n"
4043 "Replace private ASNs with our ASN in outbound updates\n")
4044 {
4045 int idx_peer = 2;
4046 return peer_af_flag_unset_vty(vty, argv[idx_peer]->arg,
4047 bgp_node_afi(vty), bgp_node_safi(vty),
4048 PEER_FLAG_REMOVE_PRIVATE_AS_REPLACE);
4049 }
4050
4051 ALIAS_HIDDEN(no_neighbor_remove_private_as_replace_as,
4052 no_neighbor_remove_private_as_replace_as_hidden_cmd,
4053 "no neighbor <A.B.C.D|X:X::X:X|WORD> remove-private-AS replace-AS",
4054 NO_STR NEIGHBOR_STR NEIGHBOR_ADDR_STR2
4055 "Remove private ASNs in outbound updates\n"
4056 "Replace private ASNs with our ASN in outbound updates\n")
4057
4058 DEFUN (no_neighbor_remove_private_as_all_replace_as,
4059 no_neighbor_remove_private_as_all_replace_as_cmd,
4060 "no neighbor <A.B.C.D|X:X::X:X|WORD> remove-private-AS all replace-AS",
4061 NO_STR
4062 NEIGHBOR_STR
4063 NEIGHBOR_ADDR_STR2
4064 "Remove private ASNs in outbound updates\n"
4065 "Apply to all AS numbers\n"
4066 "Replace private ASNs with our ASN in outbound updates\n")
4067 {
4068 int idx_peer = 2;
4069 return peer_af_flag_unset_vty(vty, argv[idx_peer]->arg,
4070 bgp_node_afi(vty), bgp_node_safi(vty),
4071 PEER_FLAG_REMOVE_PRIVATE_AS_ALL_REPLACE);
4072 }
4073
4074 ALIAS_HIDDEN(
4075 no_neighbor_remove_private_as_all_replace_as,
4076 no_neighbor_remove_private_as_all_replace_as_hidden_cmd,
4077 "no neighbor <A.B.C.D|X:X::X:X|WORD> remove-private-AS all replace-AS",
4078 NO_STR NEIGHBOR_STR NEIGHBOR_ADDR_STR2
4079 "Remove private ASNs in outbound updates\n"
4080 "Apply to all AS numbers\n"
4081 "Replace private ASNs with our ASN in outbound updates\n")
4082
4083
4084 /* neighbor send-community. */
4085 DEFUN (neighbor_send_community,
4086 neighbor_send_community_cmd,
4087 "neighbor <A.B.C.D|X:X::X:X|WORD> send-community",
4088 NEIGHBOR_STR
4089 NEIGHBOR_ADDR_STR2
4090 "Send Community attribute to this neighbor\n")
4091 {
4092 int idx_peer = 1;
4093
4094 return peer_af_flag_set_vty(vty, argv[idx_peer]->arg, bgp_node_afi(vty),
4095 bgp_node_safi(vty),
4096 PEER_FLAG_SEND_COMMUNITY);
4097 }
4098
4099 ALIAS_HIDDEN(neighbor_send_community, neighbor_send_community_hidden_cmd,
4100 "neighbor <A.B.C.D|X:X::X:X|WORD> send-community",
4101 NEIGHBOR_STR NEIGHBOR_ADDR_STR2
4102 "Send Community attribute to this neighbor\n")
4103
4104 DEFUN (no_neighbor_send_community,
4105 no_neighbor_send_community_cmd,
4106 "no neighbor <A.B.C.D|X:X::X:X|WORD> send-community",
4107 NO_STR
4108 NEIGHBOR_STR
4109 NEIGHBOR_ADDR_STR2
4110 "Send Community attribute to this neighbor\n")
4111 {
4112 int idx_peer = 2;
4113
4114 return peer_af_flag_unset_vty(vty, argv[idx_peer]->arg,
4115 bgp_node_afi(vty), bgp_node_safi(vty),
4116 PEER_FLAG_SEND_COMMUNITY);
4117 }
4118
4119 ALIAS_HIDDEN(no_neighbor_send_community, no_neighbor_send_community_hidden_cmd,
4120 "no neighbor <A.B.C.D|X:X::X:X|WORD> send-community",
4121 NO_STR NEIGHBOR_STR NEIGHBOR_ADDR_STR2
4122 "Send Community attribute to this neighbor\n")
4123
4124 /* neighbor send-community extended. */
4125 DEFUN (neighbor_send_community_type,
4126 neighbor_send_community_type_cmd,
4127 "neighbor <A.B.C.D|X:X::X:X|WORD> send-community <both|all|extended|standard|large>",
4128 NEIGHBOR_STR
4129 NEIGHBOR_ADDR_STR2
4130 "Send Community attribute to this neighbor\n"
4131 "Send Standard and Extended Community attributes\n"
4132 "Send Standard, Large and Extended Community attributes\n"
4133 "Send Extended Community attributes\n"
4134 "Send Standard Community attributes\n"
4135 "Send Large Community attributes\n")
4136 {
4137 int idx_peer = 1;
4138 uint32_t flag = 0;
4139 const char *type = argv[argc - 1]->text;
4140
4141 if (strmatch(type, "standard")) {
4142 SET_FLAG(flag, PEER_FLAG_SEND_COMMUNITY);
4143 } else if (strmatch(type, "extended")) {
4144 SET_FLAG(flag, PEER_FLAG_SEND_EXT_COMMUNITY);
4145 } else if (strmatch(type, "large")) {
4146 SET_FLAG(flag, PEER_FLAG_SEND_LARGE_COMMUNITY);
4147 } else if (strmatch(type, "both")) {
4148 SET_FLAG(flag, PEER_FLAG_SEND_COMMUNITY);
4149 SET_FLAG(flag, PEER_FLAG_SEND_EXT_COMMUNITY);
4150 } else { /* if (strmatch(type, "all")) */
4151 SET_FLAG(flag, PEER_FLAG_SEND_COMMUNITY);
4152 SET_FLAG(flag, PEER_FLAG_SEND_EXT_COMMUNITY);
4153 SET_FLAG(flag, PEER_FLAG_SEND_LARGE_COMMUNITY);
4154 }
4155
4156 return peer_af_flag_set_vty(vty, argv[idx_peer]->arg, bgp_node_afi(vty),
4157 bgp_node_safi(vty), flag);
4158 }
4159
4160 ALIAS_HIDDEN(
4161 neighbor_send_community_type, neighbor_send_community_type_hidden_cmd,
4162 "neighbor <A.B.C.D|X:X::X:X|WORD> send-community <both|all|extended|standard|large>",
4163 NEIGHBOR_STR NEIGHBOR_ADDR_STR2
4164 "Send Community attribute to this neighbor\n"
4165 "Send Standard and Extended Community attributes\n"
4166 "Send Standard, Large and Extended Community attributes\n"
4167 "Send Extended Community attributes\n"
4168 "Send Standard Community attributes\n"
4169 "Send Large Community attributes\n")
4170
4171 DEFUN (no_neighbor_send_community_type,
4172 no_neighbor_send_community_type_cmd,
4173 "no neighbor <A.B.C.D|X:X::X:X|WORD> send-community <both|all|extended|standard|large>",
4174 NO_STR
4175 NEIGHBOR_STR
4176 NEIGHBOR_ADDR_STR2
4177 "Send Community attribute to this neighbor\n"
4178 "Send Standard and Extended Community attributes\n"
4179 "Send Standard, Large and Extended Community attributes\n"
4180 "Send Extended Community attributes\n"
4181 "Send Standard Community attributes\n"
4182 "Send Large Community attributes\n")
4183 {
4184 int idx_peer = 2;
4185 uint32_t flag = 0;
4186 const char *type = argv[argc - 1]->text;
4187
4188 if (strmatch(type, "standard")) {
4189 SET_FLAG(flag, PEER_FLAG_SEND_COMMUNITY);
4190 } else if (strmatch(type, "extended")) {
4191 SET_FLAG(flag, PEER_FLAG_SEND_EXT_COMMUNITY);
4192 } else if (strmatch(type, "large")) {
4193 SET_FLAG(flag, PEER_FLAG_SEND_LARGE_COMMUNITY);
4194 } else if (strmatch(type, "both")) {
4195 SET_FLAG(flag, PEER_FLAG_SEND_COMMUNITY);
4196 SET_FLAG(flag, PEER_FLAG_SEND_EXT_COMMUNITY);
4197 } else { /* if (strmatch(type, "all")) */
4198 SET_FLAG(flag, PEER_FLAG_SEND_COMMUNITY);
4199 SET_FLAG(flag, PEER_FLAG_SEND_EXT_COMMUNITY);
4200 SET_FLAG(flag, PEER_FLAG_SEND_LARGE_COMMUNITY);
4201 }
4202
4203 return peer_af_flag_unset_vty(vty, argv[idx_peer]->arg,
4204 bgp_node_afi(vty), bgp_node_safi(vty),
4205 flag);
4206 }
4207
4208 ALIAS_HIDDEN(
4209 no_neighbor_send_community_type,
4210 no_neighbor_send_community_type_hidden_cmd,
4211 "no neighbor <A.B.C.D|X:X::X:X|WORD> send-community <both|all|extended|standard|large>",
4212 NO_STR NEIGHBOR_STR NEIGHBOR_ADDR_STR2
4213 "Send Community attribute to this neighbor\n"
4214 "Send Standard and Extended Community attributes\n"
4215 "Send Standard, Large and Extended Community attributes\n"
4216 "Send Extended Community attributes\n"
4217 "Send Standard Community attributes\n"
4218 "Send Large Community attributes\n")
4219
4220 /* neighbor soft-reconfig. */
4221 DEFUN (neighbor_soft_reconfiguration,
4222 neighbor_soft_reconfiguration_cmd,
4223 "neighbor <A.B.C.D|X:X::X:X|WORD> soft-reconfiguration inbound",
4224 NEIGHBOR_STR
4225 NEIGHBOR_ADDR_STR2
4226 "Per neighbor soft reconfiguration\n"
4227 "Allow inbound soft reconfiguration for this neighbor\n")
4228 {
4229 int idx_peer = 1;
4230 return peer_af_flag_set_vty(vty, argv[idx_peer]->arg, bgp_node_afi(vty),
4231 bgp_node_safi(vty),
4232 PEER_FLAG_SOFT_RECONFIG);
4233 }
4234
4235 ALIAS_HIDDEN(neighbor_soft_reconfiguration,
4236 neighbor_soft_reconfiguration_hidden_cmd,
4237 "neighbor <A.B.C.D|X:X::X:X|WORD> soft-reconfiguration inbound",
4238 NEIGHBOR_STR NEIGHBOR_ADDR_STR2
4239 "Per neighbor soft reconfiguration\n"
4240 "Allow inbound soft reconfiguration for this neighbor\n")
4241
4242 DEFUN (no_neighbor_soft_reconfiguration,
4243 no_neighbor_soft_reconfiguration_cmd,
4244 "no neighbor <A.B.C.D|X:X::X:X|WORD> soft-reconfiguration inbound",
4245 NO_STR
4246 NEIGHBOR_STR
4247 NEIGHBOR_ADDR_STR2
4248 "Per neighbor soft reconfiguration\n"
4249 "Allow inbound soft reconfiguration for this neighbor\n")
4250 {
4251 int idx_peer = 2;
4252 return peer_af_flag_unset_vty(vty, argv[idx_peer]->arg,
4253 bgp_node_afi(vty), bgp_node_safi(vty),
4254 PEER_FLAG_SOFT_RECONFIG);
4255 }
4256
4257 ALIAS_HIDDEN(no_neighbor_soft_reconfiguration,
4258 no_neighbor_soft_reconfiguration_hidden_cmd,
4259 "no neighbor <A.B.C.D|X:X::X:X|WORD> soft-reconfiguration inbound",
4260 NO_STR NEIGHBOR_STR NEIGHBOR_ADDR_STR2
4261 "Per neighbor soft reconfiguration\n"
4262 "Allow inbound soft reconfiguration for this neighbor\n")
4263
4264 DEFUN (neighbor_route_reflector_client,
4265 neighbor_route_reflector_client_cmd,
4266 "neighbor <A.B.C.D|X:X::X:X|WORD> route-reflector-client",
4267 NEIGHBOR_STR
4268 NEIGHBOR_ADDR_STR2
4269 "Configure a neighbor as Route Reflector client\n")
4270 {
4271 int idx_peer = 1;
4272 struct peer *peer;
4273
4274
4275 peer = peer_and_group_lookup_vty(vty, argv[idx_peer]->arg);
4276 if (!peer)
4277 return CMD_WARNING_CONFIG_FAILED;
4278
4279 return peer_af_flag_set_vty(vty, argv[idx_peer]->arg, bgp_node_afi(vty),
4280 bgp_node_safi(vty),
4281 PEER_FLAG_REFLECTOR_CLIENT);
4282 }
4283
4284 ALIAS_HIDDEN(neighbor_route_reflector_client,
4285 neighbor_route_reflector_client_hidden_cmd,
4286 "neighbor <A.B.C.D|X:X::X:X|WORD> route-reflector-client",
4287 NEIGHBOR_STR NEIGHBOR_ADDR_STR2
4288 "Configure a neighbor as Route Reflector client\n")
4289
4290 DEFUN (no_neighbor_route_reflector_client,
4291 no_neighbor_route_reflector_client_cmd,
4292 "no neighbor <A.B.C.D|X:X::X:X|WORD> route-reflector-client",
4293 NO_STR
4294 NEIGHBOR_STR
4295 NEIGHBOR_ADDR_STR2
4296 "Configure a neighbor as Route Reflector client\n")
4297 {
4298 int idx_peer = 2;
4299 return peer_af_flag_unset_vty(vty, argv[idx_peer]->arg,
4300 bgp_node_afi(vty), bgp_node_safi(vty),
4301 PEER_FLAG_REFLECTOR_CLIENT);
4302 }
4303
4304 ALIAS_HIDDEN(no_neighbor_route_reflector_client,
4305 no_neighbor_route_reflector_client_hidden_cmd,
4306 "no neighbor <A.B.C.D|X:X::X:X|WORD> route-reflector-client",
4307 NO_STR NEIGHBOR_STR NEIGHBOR_ADDR_STR2
4308 "Configure a neighbor as Route Reflector client\n")
4309
4310 /* neighbor route-server-client. */
4311 DEFUN (neighbor_route_server_client,
4312 neighbor_route_server_client_cmd,
4313 "neighbor <A.B.C.D|X:X::X:X|WORD> route-server-client",
4314 NEIGHBOR_STR
4315 NEIGHBOR_ADDR_STR2
4316 "Configure a neighbor as Route Server client\n")
4317 {
4318 int idx_peer = 1;
4319 struct peer *peer;
4320
4321 peer = peer_and_group_lookup_vty(vty, argv[idx_peer]->arg);
4322 if (!peer)
4323 return CMD_WARNING_CONFIG_FAILED;
4324 return peer_af_flag_set_vty(vty, argv[idx_peer]->arg, bgp_node_afi(vty),
4325 bgp_node_safi(vty),
4326 PEER_FLAG_RSERVER_CLIENT);
4327 }
4328
4329 ALIAS_HIDDEN(neighbor_route_server_client,
4330 neighbor_route_server_client_hidden_cmd,
4331 "neighbor <A.B.C.D|X:X::X:X|WORD> route-server-client",
4332 NEIGHBOR_STR NEIGHBOR_ADDR_STR2
4333 "Configure a neighbor as Route Server client\n")
4334
4335 DEFUN (no_neighbor_route_server_client,
4336 no_neighbor_route_server_client_cmd,
4337 "no neighbor <A.B.C.D|X:X::X:X|WORD> route-server-client",
4338 NO_STR
4339 NEIGHBOR_STR
4340 NEIGHBOR_ADDR_STR2
4341 "Configure a neighbor as Route Server client\n")
4342 {
4343 int idx_peer = 2;
4344 return peer_af_flag_unset_vty(vty, argv[idx_peer]->arg,
4345 bgp_node_afi(vty), bgp_node_safi(vty),
4346 PEER_FLAG_RSERVER_CLIENT);
4347 }
4348
4349 ALIAS_HIDDEN(no_neighbor_route_server_client,
4350 no_neighbor_route_server_client_hidden_cmd,
4351 "no neighbor <A.B.C.D|X:X::X:X|WORD> route-server-client",
4352 NO_STR NEIGHBOR_STR NEIGHBOR_ADDR_STR2
4353 "Configure a neighbor as Route Server client\n")
4354
4355 DEFUN (neighbor_nexthop_local_unchanged,
4356 neighbor_nexthop_local_unchanged_cmd,
4357 "neighbor <A.B.C.D|X:X::X:X|WORD> nexthop-local unchanged",
4358 NEIGHBOR_STR
4359 NEIGHBOR_ADDR_STR2
4360 "Configure treatment of outgoing link-local nexthop attribute\n"
4361 "Leave link-local nexthop unchanged for this peer\n")
4362 {
4363 int idx_peer = 1;
4364 return peer_af_flag_set_vty(vty, argv[idx_peer]->arg, bgp_node_afi(vty),
4365 bgp_node_safi(vty),
4366 PEER_FLAG_NEXTHOP_LOCAL_UNCHANGED);
4367 }
4368
4369 DEFUN (no_neighbor_nexthop_local_unchanged,
4370 no_neighbor_nexthop_local_unchanged_cmd,
4371 "no neighbor <A.B.C.D|X:X::X:X|WORD> nexthop-local unchanged",
4372 NO_STR
4373 NEIGHBOR_STR
4374 NEIGHBOR_ADDR_STR2
4375 "Configure treatment of outgoing link-local-nexthop attribute\n"
4376 "Leave link-local nexthop unchanged for this peer\n")
4377 {
4378 int idx_peer = 2;
4379 return peer_af_flag_unset_vty(vty, argv[idx_peer]->arg,
4380 bgp_node_afi(vty), bgp_node_safi(vty),
4381 PEER_FLAG_NEXTHOP_LOCAL_UNCHANGED);
4382 }
4383
4384 DEFUN (neighbor_attr_unchanged,
4385 neighbor_attr_unchanged_cmd,
4386 "neighbor <A.B.C.D|X:X::X:X|WORD> attribute-unchanged [{as-path|next-hop|med}]",
4387 NEIGHBOR_STR
4388 NEIGHBOR_ADDR_STR2
4389 "BGP attribute is propagated unchanged to this neighbor\n"
4390 "As-path attribute\n"
4391 "Nexthop attribute\n"
4392 "Med attribute\n")
4393 {
4394 int idx = 0;
4395 char *peer_str = argv[1]->arg;
4396 struct peer *peer;
4397 uint16_t flags = 0;
4398 afi_t afi = bgp_node_afi(vty);
4399 safi_t safi = bgp_node_safi(vty);
4400
4401 peer = peer_and_group_lookup_vty(vty, peer_str);
4402 if (!peer)
4403 return CMD_WARNING_CONFIG_FAILED;
4404
4405 if (argv_find(argv, argc, "as-path", &idx))
4406 SET_FLAG(flags, PEER_FLAG_AS_PATH_UNCHANGED);
4407 idx = 0;
4408 if (argv_find(argv, argc, "next-hop", &idx))
4409 SET_FLAG(flags, PEER_FLAG_NEXTHOP_UNCHANGED);
4410 idx = 0;
4411 if (argv_find(argv, argc, "med", &idx))
4412 SET_FLAG(flags, PEER_FLAG_MED_UNCHANGED);
4413
4414 /* no flags means all of them! */
4415 if (!flags) {
4416 SET_FLAG(flags, PEER_FLAG_AS_PATH_UNCHANGED);
4417 SET_FLAG(flags, PEER_FLAG_NEXTHOP_UNCHANGED);
4418 SET_FLAG(flags, PEER_FLAG_MED_UNCHANGED);
4419 } else {
4420 if (!CHECK_FLAG(flags, PEER_FLAG_AS_PATH_UNCHANGED)
4421 && peer_af_flag_check(peer, afi, safi,
4422 PEER_FLAG_AS_PATH_UNCHANGED)) {
4423 peer_af_flag_unset_vty(vty, peer_str, afi, safi,
4424 PEER_FLAG_AS_PATH_UNCHANGED);
4425 }
4426
4427 if (!CHECK_FLAG(flags, PEER_FLAG_NEXTHOP_UNCHANGED)
4428 && peer_af_flag_check(peer, afi, safi,
4429 PEER_FLAG_NEXTHOP_UNCHANGED)) {
4430 peer_af_flag_unset_vty(vty, peer_str, afi, safi,
4431 PEER_FLAG_NEXTHOP_UNCHANGED);
4432 }
4433
4434 if (!CHECK_FLAG(flags, PEER_FLAG_MED_UNCHANGED)
4435 && peer_af_flag_check(peer, afi, safi,
4436 PEER_FLAG_MED_UNCHANGED)) {
4437 peer_af_flag_unset_vty(vty, peer_str, afi, safi,
4438 PEER_FLAG_MED_UNCHANGED);
4439 }
4440 }
4441
4442 return peer_af_flag_set_vty(vty, peer_str, afi, safi, flags);
4443 }
4444
4445 ALIAS_HIDDEN(
4446 neighbor_attr_unchanged, neighbor_attr_unchanged_hidden_cmd,
4447 "neighbor <A.B.C.D|X:X::X:X|WORD> attribute-unchanged [{as-path|next-hop|med}]",
4448 NEIGHBOR_STR NEIGHBOR_ADDR_STR2
4449 "BGP attribute is propagated unchanged to this neighbor\n"
4450 "As-path attribute\n"
4451 "Nexthop attribute\n"
4452 "Med attribute\n")
4453
4454 DEFUN (no_neighbor_attr_unchanged,
4455 no_neighbor_attr_unchanged_cmd,
4456 "no neighbor <A.B.C.D|X:X::X:X|WORD> attribute-unchanged [{as-path|next-hop|med}]",
4457 NO_STR
4458 NEIGHBOR_STR
4459 NEIGHBOR_ADDR_STR2
4460 "BGP attribute is propagated unchanged to this neighbor\n"
4461 "As-path attribute\n"
4462 "Nexthop attribute\n"
4463 "Med attribute\n")
4464 {
4465 int idx = 0;
4466 char *peer = argv[2]->arg;
4467 uint16_t flags = 0;
4468
4469 if (argv_find(argv, argc, "as-path", &idx))
4470 SET_FLAG(flags, PEER_FLAG_AS_PATH_UNCHANGED);
4471 idx = 0;
4472 if (argv_find(argv, argc, "next-hop", &idx))
4473 SET_FLAG(flags, PEER_FLAG_NEXTHOP_UNCHANGED);
4474 idx = 0;
4475 if (argv_find(argv, argc, "med", &idx))
4476 SET_FLAG(flags, PEER_FLAG_MED_UNCHANGED);
4477
4478 if (!flags) // no flags means all of them!
4479 {
4480 SET_FLAG(flags, PEER_FLAG_AS_PATH_UNCHANGED);
4481 SET_FLAG(flags, PEER_FLAG_NEXTHOP_UNCHANGED);
4482 SET_FLAG(flags, PEER_FLAG_MED_UNCHANGED);
4483 }
4484
4485 return peer_af_flag_unset_vty(vty, peer, bgp_node_afi(vty),
4486 bgp_node_safi(vty), flags);
4487 }
4488
4489 ALIAS_HIDDEN(
4490 no_neighbor_attr_unchanged, no_neighbor_attr_unchanged_hidden_cmd,
4491 "no neighbor <A.B.C.D|X:X::X:X|WORD> attribute-unchanged [{as-path|next-hop|med}]",
4492 NO_STR NEIGHBOR_STR NEIGHBOR_ADDR_STR2
4493 "BGP attribute is propagated unchanged to this neighbor\n"
4494 "As-path attribute\n"
4495 "Nexthop attribute\n"
4496 "Med attribute\n")
4497
4498 /* EBGP multihop configuration. */
4499 static int peer_ebgp_multihop_set_vty(struct vty *vty, const char *ip_str,
4500 const char *ttl_str)
4501 {
4502 struct peer *peer;
4503 unsigned int ttl;
4504
4505 peer = peer_and_group_lookup_vty(vty, ip_str);
4506 if (!peer)
4507 return CMD_WARNING_CONFIG_FAILED;
4508
4509 if (peer->conf_if)
4510 return bgp_vty_return(vty, BGP_ERR_INVALID_FOR_DIRECT_PEER);
4511
4512 if (!ttl_str)
4513 ttl = MAXTTL;
4514 else
4515 ttl = strtoul(ttl_str, NULL, 10);
4516
4517 return bgp_vty_return(vty, peer_ebgp_multihop_set(peer, ttl));
4518 }
4519
4520 static int peer_ebgp_multihop_unset_vty(struct vty *vty, const char *ip_str)
4521 {
4522 struct peer *peer;
4523
4524 peer = peer_and_group_lookup_vty(vty, ip_str);
4525 if (!peer)
4526 return CMD_WARNING_CONFIG_FAILED;
4527
4528 return bgp_vty_return(vty, peer_ebgp_multihop_unset(peer));
4529 }
4530
4531 /* neighbor ebgp-multihop. */
4532 DEFUN (neighbor_ebgp_multihop,
4533 neighbor_ebgp_multihop_cmd,
4534 "neighbor <A.B.C.D|X:X::X:X|WORD> ebgp-multihop",
4535 NEIGHBOR_STR
4536 NEIGHBOR_ADDR_STR2
4537 "Allow EBGP neighbors not on directly connected networks\n")
4538 {
4539 int idx_peer = 1;
4540 return peer_ebgp_multihop_set_vty(vty, argv[idx_peer]->arg, NULL);
4541 }
4542
4543 DEFUN (neighbor_ebgp_multihop_ttl,
4544 neighbor_ebgp_multihop_ttl_cmd,
4545 "neighbor <A.B.C.D|X:X::X:X|WORD> ebgp-multihop (1-255)",
4546 NEIGHBOR_STR
4547 NEIGHBOR_ADDR_STR2
4548 "Allow EBGP neighbors not on directly connected networks\n"
4549 "maximum hop count\n")
4550 {
4551 int idx_peer = 1;
4552 int idx_number = 3;
4553 return peer_ebgp_multihop_set_vty(vty, argv[idx_peer]->arg,
4554 argv[idx_number]->arg);
4555 }
4556
4557 DEFUN (no_neighbor_ebgp_multihop,
4558 no_neighbor_ebgp_multihop_cmd,
4559 "no neighbor <A.B.C.D|X:X::X:X|WORD> ebgp-multihop [(1-255)]",
4560 NO_STR
4561 NEIGHBOR_STR
4562 NEIGHBOR_ADDR_STR2
4563 "Allow EBGP neighbors not on directly connected networks\n"
4564 "maximum hop count\n")
4565 {
4566 int idx_peer = 2;
4567 return peer_ebgp_multihop_unset_vty(vty, argv[idx_peer]->arg);
4568 }
4569
4570
4571 /* disable-connected-check */
4572 DEFUN (neighbor_disable_connected_check,
4573 neighbor_disable_connected_check_cmd,
4574 "neighbor <A.B.C.D|X:X::X:X|WORD> <disable-connected-check|enforce-multihop>",
4575 NEIGHBOR_STR
4576 NEIGHBOR_ADDR_STR2
4577 "one-hop away EBGP peer using loopback address\n"
4578 "Enforce EBGP neighbors perform multihop\n")
4579 {
4580 int idx_peer = 1;
4581 return peer_flag_set_vty(vty, argv[idx_peer]->arg,
4582 PEER_FLAG_DISABLE_CONNECTED_CHECK);
4583 }
4584
4585 DEFUN (no_neighbor_disable_connected_check,
4586 no_neighbor_disable_connected_check_cmd,
4587 "no neighbor <A.B.C.D|X:X::X:X|WORD> <disable-connected-check|enforce-multihop>",
4588 NO_STR
4589 NEIGHBOR_STR
4590 NEIGHBOR_ADDR_STR2
4591 "one-hop away EBGP peer using loopback address\n"
4592 "Enforce EBGP neighbors perform multihop\n")
4593 {
4594 int idx_peer = 2;
4595 return peer_flag_unset_vty(vty, argv[idx_peer]->arg,
4596 PEER_FLAG_DISABLE_CONNECTED_CHECK);
4597 }
4598
4599
4600 /* enforce-first-as */
4601 DEFUN (neighbor_enforce_first_as,
4602 neighbor_enforce_first_as_cmd,
4603 "neighbor <A.B.C.D|X:X::X:X|WORD> enforce-first-as",
4604 NEIGHBOR_STR
4605 NEIGHBOR_ADDR_STR2
4606 "Enforce the first AS for EBGP routes\n")
4607 {
4608 int idx_peer = 1;
4609
4610 return peer_flag_set_vty(vty, argv[idx_peer]->arg,
4611 PEER_FLAG_ENFORCE_FIRST_AS);
4612 }
4613
4614 DEFUN (no_neighbor_enforce_first_as,
4615 no_neighbor_enforce_first_as_cmd,
4616 "no neighbor <A.B.C.D|X:X::X:X|WORD> enforce-first-as",
4617 NO_STR
4618 NEIGHBOR_STR
4619 NEIGHBOR_ADDR_STR2
4620 "Enforce the first AS for EBGP routes\n")
4621 {
4622 int idx_peer = 2;
4623
4624 return peer_flag_unset_vty(vty, argv[idx_peer]->arg,
4625 PEER_FLAG_ENFORCE_FIRST_AS);
4626 }
4627
4628
4629 DEFUN (neighbor_description,
4630 neighbor_description_cmd,
4631 "neighbor <A.B.C.D|X:X::X:X|WORD> description LINE...",
4632 NEIGHBOR_STR
4633 NEIGHBOR_ADDR_STR2
4634 "Neighbor specific description\n"
4635 "Up to 80 characters describing this neighbor\n")
4636 {
4637 int idx_peer = 1;
4638 int idx_line = 3;
4639 struct peer *peer;
4640 char *str;
4641
4642 peer = peer_and_group_lookup_vty(vty, argv[idx_peer]->arg);
4643 if (!peer)
4644 return CMD_WARNING_CONFIG_FAILED;
4645
4646 str = argv_concat(argv, argc, idx_line);
4647
4648 peer_description_set(peer, str);
4649
4650 XFREE(MTYPE_TMP, str);
4651
4652 return CMD_SUCCESS;
4653 }
4654
4655 DEFUN (no_neighbor_description,
4656 no_neighbor_description_cmd,
4657 "no neighbor <A.B.C.D|X:X::X:X|WORD> description",
4658 NO_STR
4659 NEIGHBOR_STR
4660 NEIGHBOR_ADDR_STR2
4661 "Neighbor specific description\n")
4662 {
4663 int idx_peer = 2;
4664 struct peer *peer;
4665
4666 peer = peer_and_group_lookup_vty(vty, argv[idx_peer]->arg);
4667 if (!peer)
4668 return CMD_WARNING_CONFIG_FAILED;
4669
4670 peer_description_unset(peer);
4671
4672 return CMD_SUCCESS;
4673 }
4674
4675 ALIAS(no_neighbor_description, no_neighbor_description_comment_cmd,
4676 "no neighbor <A.B.C.D|X:X::X:X|WORD> description LINE...",
4677 NO_STR NEIGHBOR_STR NEIGHBOR_ADDR_STR2
4678 "Neighbor specific description\n"
4679 "Up to 80 characters describing this neighbor\n")
4680
4681 /* Neighbor update-source. */
4682 static int peer_update_source_vty(struct vty *vty, const char *peer_str,
4683 const char *source_str)
4684 {
4685 struct peer *peer;
4686 struct prefix p;
4687 union sockunion su;
4688
4689 peer = peer_and_group_lookup_vty(vty, peer_str);
4690 if (!peer)
4691 return CMD_WARNING_CONFIG_FAILED;
4692
4693 if (peer->conf_if)
4694 return CMD_WARNING;
4695
4696 if (source_str) {
4697 if (str2sockunion(source_str, &su) == 0)
4698 peer_update_source_addr_set(peer, &su);
4699 else {
4700 if (str2prefix(source_str, &p)) {
4701 vty_out(vty,
4702 "%% Invalid update-source, remove prefix length \n");
4703 return CMD_WARNING_CONFIG_FAILED;
4704 } else
4705 peer_update_source_if_set(peer, source_str);
4706 }
4707 } else
4708 peer_update_source_unset(peer);
4709
4710 return CMD_SUCCESS;
4711 }
4712
4713 #define BGP_UPDATE_SOURCE_HELP_STR \
4714 "IPv4 address\n" \
4715 "IPv6 address\n" \
4716 "Interface name (requires zebra to be running)\n"
4717
4718 DEFUN (neighbor_update_source,
4719 neighbor_update_source_cmd,
4720 "neighbor <A.B.C.D|X:X::X:X|WORD> update-source <A.B.C.D|X:X::X:X|WORD>",
4721 NEIGHBOR_STR
4722 NEIGHBOR_ADDR_STR2
4723 "Source of routing updates\n"
4724 BGP_UPDATE_SOURCE_HELP_STR)
4725 {
4726 int idx_peer = 1;
4727 int idx_peer_2 = 3;
4728 return peer_update_source_vty(vty, argv[idx_peer]->arg,
4729 argv[idx_peer_2]->arg);
4730 }
4731
4732 DEFUN (no_neighbor_update_source,
4733 no_neighbor_update_source_cmd,
4734 "no neighbor <A.B.C.D|X:X::X:X|WORD> update-source [<A.B.C.D|X:X::X:X|WORD>]",
4735 NO_STR
4736 NEIGHBOR_STR
4737 NEIGHBOR_ADDR_STR2
4738 "Source of routing updates\n"
4739 BGP_UPDATE_SOURCE_HELP_STR)
4740 {
4741 int idx_peer = 2;
4742 return peer_update_source_vty(vty, argv[idx_peer]->arg, NULL);
4743 }
4744
4745 static int peer_default_originate_set_vty(struct vty *vty, const char *peer_str,
4746 afi_t afi, safi_t safi,
4747 const char *rmap, int set)
4748 {
4749 int ret;
4750 struct peer *peer;
4751
4752 peer = peer_and_group_lookup_vty(vty, peer_str);
4753 if (!peer)
4754 return CMD_WARNING_CONFIG_FAILED;
4755
4756 if (set)
4757 ret = peer_default_originate_set(peer, afi, safi, rmap);
4758 else
4759 ret = peer_default_originate_unset(peer, afi, safi);
4760
4761 return bgp_vty_return(vty, ret);
4762 }
4763
4764 /* neighbor default-originate. */
4765 DEFUN (neighbor_default_originate,
4766 neighbor_default_originate_cmd,
4767 "neighbor <A.B.C.D|X:X::X:X|WORD> default-originate",
4768 NEIGHBOR_STR
4769 NEIGHBOR_ADDR_STR2
4770 "Originate default route to this neighbor\n")
4771 {
4772 int idx_peer = 1;
4773 return peer_default_originate_set_vty(vty, argv[idx_peer]->arg,
4774 bgp_node_afi(vty),
4775 bgp_node_safi(vty), NULL, 1);
4776 }
4777
4778 ALIAS_HIDDEN(neighbor_default_originate, neighbor_default_originate_hidden_cmd,
4779 "neighbor <A.B.C.D|X:X::X:X|WORD> default-originate",
4780 NEIGHBOR_STR NEIGHBOR_ADDR_STR2
4781 "Originate default route to this neighbor\n")
4782
4783 DEFUN (neighbor_default_originate_rmap,
4784 neighbor_default_originate_rmap_cmd,
4785 "neighbor <A.B.C.D|X:X::X:X|WORD> default-originate route-map WORD",
4786 NEIGHBOR_STR
4787 NEIGHBOR_ADDR_STR2
4788 "Originate default route to this neighbor\n"
4789 "Route-map to specify criteria to originate default\n"
4790 "route-map name\n")
4791 {
4792 int idx_peer = 1;
4793 int idx_word = 4;
4794 return peer_default_originate_set_vty(
4795 vty, argv[idx_peer]->arg, bgp_node_afi(vty), bgp_node_safi(vty),
4796 argv[idx_word]->arg, 1);
4797 }
4798
4799 ALIAS_HIDDEN(
4800 neighbor_default_originate_rmap,
4801 neighbor_default_originate_rmap_hidden_cmd,
4802 "neighbor <A.B.C.D|X:X::X:X|WORD> default-originate route-map WORD",
4803 NEIGHBOR_STR NEIGHBOR_ADDR_STR2
4804 "Originate default route to this neighbor\n"
4805 "Route-map to specify criteria to originate default\n"
4806 "route-map name\n")
4807
4808 DEFUN (no_neighbor_default_originate,
4809 no_neighbor_default_originate_cmd,
4810 "no neighbor <A.B.C.D|X:X::X:X|WORD> default-originate [route-map WORD]",
4811 NO_STR
4812 NEIGHBOR_STR
4813 NEIGHBOR_ADDR_STR2
4814 "Originate default route to this neighbor\n"
4815 "Route-map to specify criteria to originate default\n"
4816 "route-map name\n")
4817 {
4818 int idx_peer = 2;
4819 return peer_default_originate_set_vty(vty, argv[idx_peer]->arg,
4820 bgp_node_afi(vty),
4821 bgp_node_safi(vty), NULL, 0);
4822 }
4823
4824 ALIAS_HIDDEN(
4825 no_neighbor_default_originate, no_neighbor_default_originate_hidden_cmd,
4826 "no neighbor <A.B.C.D|X:X::X:X|WORD> default-originate [route-map WORD]",
4827 NO_STR NEIGHBOR_STR NEIGHBOR_ADDR_STR2
4828 "Originate default route to this neighbor\n"
4829 "Route-map to specify criteria to originate default\n"
4830 "route-map name\n")
4831
4832
4833 /* Set neighbor's BGP port. */
4834 static int peer_port_vty(struct vty *vty, const char *ip_str, int afi,
4835 const char *port_str)
4836 {
4837 struct peer *peer;
4838 uint16_t port;
4839 struct servent *sp;
4840
4841 peer = peer_lookup_vty(vty, ip_str);
4842 if (!peer)
4843 return CMD_WARNING_CONFIG_FAILED;
4844
4845 if (!port_str) {
4846 sp = getservbyname("bgp", "tcp");
4847 port = (sp == NULL) ? BGP_PORT_DEFAULT : ntohs(sp->s_port);
4848 } else {
4849 port = strtoul(port_str, NULL, 10);
4850 }
4851
4852 peer_port_set(peer, port);
4853
4854 return CMD_SUCCESS;
4855 }
4856
4857 /* Set specified peer's BGP port. */
4858 DEFUN (neighbor_port,
4859 neighbor_port_cmd,
4860 "neighbor <A.B.C.D|X:X::X:X> port (0-65535)",
4861 NEIGHBOR_STR
4862 NEIGHBOR_ADDR_STR
4863 "Neighbor's BGP port\n"
4864 "TCP port number\n")
4865 {
4866 int idx_ip = 1;
4867 int idx_number = 3;
4868 return peer_port_vty(vty, argv[idx_ip]->arg, AFI_IP,
4869 argv[idx_number]->arg);
4870 }
4871
4872 DEFUN (no_neighbor_port,
4873 no_neighbor_port_cmd,
4874 "no neighbor <A.B.C.D|X:X::X:X> port [(0-65535)]",
4875 NO_STR
4876 NEIGHBOR_STR
4877 NEIGHBOR_ADDR_STR
4878 "Neighbor's BGP port\n"
4879 "TCP port number\n")
4880 {
4881 int idx_ip = 2;
4882 return peer_port_vty(vty, argv[idx_ip]->arg, AFI_IP, NULL);
4883 }
4884
4885
4886 /* neighbor weight. */
4887 static int peer_weight_set_vty(struct vty *vty, const char *ip_str, afi_t afi,
4888 safi_t safi, const char *weight_str)
4889 {
4890 int ret;
4891 struct peer *peer;
4892 unsigned long weight;
4893
4894 peer = peer_and_group_lookup_vty(vty, ip_str);
4895 if (!peer)
4896 return CMD_WARNING_CONFIG_FAILED;
4897
4898 weight = strtoul(weight_str, NULL, 10);
4899
4900 ret = peer_weight_set(peer, afi, safi, weight);
4901 return bgp_vty_return(vty, ret);
4902 }
4903
4904 static int peer_weight_unset_vty(struct vty *vty, const char *ip_str, afi_t afi,
4905 safi_t safi)
4906 {
4907 int ret;
4908 struct peer *peer;
4909
4910 peer = peer_and_group_lookup_vty(vty, ip_str);
4911 if (!peer)
4912 return CMD_WARNING_CONFIG_FAILED;
4913
4914 ret = peer_weight_unset(peer, afi, safi);
4915 return bgp_vty_return(vty, ret);
4916 }
4917
4918 DEFUN (neighbor_weight,
4919 neighbor_weight_cmd,
4920 "neighbor <A.B.C.D|X:X::X:X|WORD> weight (0-65535)",
4921 NEIGHBOR_STR
4922 NEIGHBOR_ADDR_STR2
4923 "Set default weight for routes from this neighbor\n"
4924 "default weight\n")
4925 {
4926 int idx_peer = 1;
4927 int idx_number = 3;
4928 return peer_weight_set_vty(vty, argv[idx_peer]->arg, bgp_node_afi(vty),
4929 bgp_node_safi(vty), argv[idx_number]->arg);
4930 }
4931
4932 ALIAS_HIDDEN(neighbor_weight, neighbor_weight_hidden_cmd,
4933 "neighbor <A.B.C.D|X:X::X:X|WORD> weight (0-65535)",
4934 NEIGHBOR_STR NEIGHBOR_ADDR_STR2
4935 "Set default weight for routes from this neighbor\n"
4936 "default weight\n")
4937
4938 DEFUN (no_neighbor_weight,
4939 no_neighbor_weight_cmd,
4940 "no neighbor <A.B.C.D|X:X::X:X|WORD> weight [(0-65535)]",
4941 NO_STR
4942 NEIGHBOR_STR
4943 NEIGHBOR_ADDR_STR2
4944 "Set default weight for routes from this neighbor\n"
4945 "default weight\n")
4946 {
4947 int idx_peer = 2;
4948 return peer_weight_unset_vty(vty, argv[idx_peer]->arg,
4949 bgp_node_afi(vty), bgp_node_safi(vty));
4950 }
4951
4952 ALIAS_HIDDEN(no_neighbor_weight, no_neighbor_weight_hidden_cmd,
4953 "no neighbor <A.B.C.D|X:X::X:X|WORD> weight [(0-65535)]",
4954 NO_STR NEIGHBOR_STR NEIGHBOR_ADDR_STR2
4955 "Set default weight for routes from this neighbor\n"
4956 "default weight\n")
4957
4958
4959 /* Override capability negotiation. */
4960 DEFUN (neighbor_override_capability,
4961 neighbor_override_capability_cmd,
4962 "neighbor <A.B.C.D|X:X::X:X|WORD> override-capability",
4963 NEIGHBOR_STR
4964 NEIGHBOR_ADDR_STR2
4965 "Override capability negotiation result\n")
4966 {
4967 int idx_peer = 1;
4968 return peer_flag_set_vty(vty, argv[idx_peer]->arg,
4969 PEER_FLAG_OVERRIDE_CAPABILITY);
4970 }
4971
4972 DEFUN (no_neighbor_override_capability,
4973 no_neighbor_override_capability_cmd,
4974 "no neighbor <A.B.C.D|X:X::X:X|WORD> override-capability",
4975 NO_STR
4976 NEIGHBOR_STR
4977 NEIGHBOR_ADDR_STR2
4978 "Override capability negotiation result\n")
4979 {
4980 int idx_peer = 2;
4981 return peer_flag_unset_vty(vty, argv[idx_peer]->arg,
4982 PEER_FLAG_OVERRIDE_CAPABILITY);
4983 }
4984
4985 DEFUN (neighbor_strict_capability,
4986 neighbor_strict_capability_cmd,
4987 "neighbor <A.B.C.D|X:X::X:X|WORD> strict-capability-match",
4988 NEIGHBOR_STR
4989 NEIGHBOR_ADDR_STR2
4990 "Strict capability negotiation match\n")
4991 {
4992 int idx_peer = 1;
4993
4994 return peer_flag_set_vty(vty, argv[idx_peer]->arg,
4995 PEER_FLAG_STRICT_CAP_MATCH);
4996 }
4997
4998 DEFUN (no_neighbor_strict_capability,
4999 no_neighbor_strict_capability_cmd,
5000 "no neighbor <A.B.C.D|X:X::X:X|WORD> strict-capability-match",
5001 NO_STR
5002 NEIGHBOR_STR
5003 NEIGHBOR_ADDR_STR2
5004 "Strict capability negotiation match\n")
5005 {
5006 int idx_peer = 2;
5007
5008 return peer_flag_unset_vty(vty, argv[idx_peer]->arg,
5009 PEER_FLAG_STRICT_CAP_MATCH);
5010 }
5011
5012 static int peer_timers_set_vty(struct vty *vty, const char *ip_str,
5013 const char *keep_str, const char *hold_str)
5014 {
5015 int ret;
5016 struct peer *peer;
5017 uint32_t keepalive;
5018 uint32_t holdtime;
5019
5020 peer = peer_and_group_lookup_vty(vty, ip_str);
5021 if (!peer)
5022 return CMD_WARNING_CONFIG_FAILED;
5023
5024 keepalive = strtoul(keep_str, NULL, 10);
5025 holdtime = strtoul(hold_str, NULL, 10);
5026
5027 ret = peer_timers_set(peer, keepalive, holdtime);
5028
5029 return bgp_vty_return(vty, ret);
5030 }
5031
5032 static int peer_timers_unset_vty(struct vty *vty, const char *ip_str)
5033 {
5034 int ret;
5035 struct peer *peer;
5036
5037 peer = peer_and_group_lookup_vty(vty, ip_str);
5038 if (!peer)
5039 return CMD_WARNING_CONFIG_FAILED;
5040
5041 ret = peer_timers_unset(peer);
5042
5043 return bgp_vty_return(vty, ret);
5044 }
5045
5046 DEFUN (neighbor_timers,
5047 neighbor_timers_cmd,
5048 "neighbor <A.B.C.D|X:X::X:X|WORD> timers (0-65535) (0-65535)",
5049 NEIGHBOR_STR
5050 NEIGHBOR_ADDR_STR2
5051 "BGP per neighbor timers\n"
5052 "Keepalive interval\n"
5053 "Holdtime\n")
5054 {
5055 int idx_peer = 1;
5056 int idx_number = 3;
5057 int idx_number_2 = 4;
5058 return peer_timers_set_vty(vty, argv[idx_peer]->arg,
5059 argv[idx_number]->arg,
5060 argv[idx_number_2]->arg);
5061 }
5062
5063 DEFUN (no_neighbor_timers,
5064 no_neighbor_timers_cmd,
5065 "no neighbor <A.B.C.D|X:X::X:X|WORD> timers [(0-65535) (0-65535)]",
5066 NO_STR
5067 NEIGHBOR_STR
5068 NEIGHBOR_ADDR_STR2
5069 "BGP per neighbor timers\n"
5070 "Keepalive interval\n"
5071 "Holdtime\n")
5072 {
5073 int idx_peer = 2;
5074 return peer_timers_unset_vty(vty, argv[idx_peer]->arg);
5075 }
5076
5077
5078 static int peer_timers_connect_set_vty(struct vty *vty, const char *ip_str,
5079 const char *time_str)
5080 {
5081 int ret;
5082 struct peer *peer;
5083 uint32_t connect;
5084
5085 peer = peer_and_group_lookup_vty(vty, ip_str);
5086 if (!peer)
5087 return CMD_WARNING_CONFIG_FAILED;
5088
5089 connect = strtoul(time_str, NULL, 10);
5090
5091 ret = peer_timers_connect_set(peer, connect);
5092
5093 return bgp_vty_return(vty, ret);
5094 }
5095
5096 static int peer_timers_connect_unset_vty(struct vty *vty, const char *ip_str)
5097 {
5098 int ret;
5099 struct peer *peer;
5100
5101 peer = peer_and_group_lookup_vty(vty, ip_str);
5102 if (!peer)
5103 return CMD_WARNING_CONFIG_FAILED;
5104
5105 ret = peer_timers_connect_unset(peer);
5106
5107 return bgp_vty_return(vty, ret);
5108 }
5109
5110 DEFUN (neighbor_timers_connect,
5111 neighbor_timers_connect_cmd,
5112 "neighbor <A.B.C.D|X:X::X:X|WORD> timers connect (1-65535)",
5113 NEIGHBOR_STR
5114 NEIGHBOR_ADDR_STR2
5115 "BGP per neighbor timers\n"
5116 "BGP connect timer\n"
5117 "Connect timer\n")
5118 {
5119 int idx_peer = 1;
5120 int idx_number = 4;
5121 return peer_timers_connect_set_vty(vty, argv[idx_peer]->arg,
5122 argv[idx_number]->arg);
5123 }
5124
5125 DEFUN (no_neighbor_timers_connect,
5126 no_neighbor_timers_connect_cmd,
5127 "no neighbor <A.B.C.D|X:X::X:X|WORD> timers connect [(1-65535)]",
5128 NO_STR
5129 NEIGHBOR_STR
5130 NEIGHBOR_ADDR_STR2
5131 "BGP per neighbor timers\n"
5132 "BGP connect timer\n"
5133 "Connect timer\n")
5134 {
5135 int idx_peer = 2;
5136 return peer_timers_connect_unset_vty(vty, argv[idx_peer]->arg);
5137 }
5138
5139
5140 static int peer_advertise_interval_vty(struct vty *vty, const char *ip_str,
5141 const char *time_str, int set)
5142 {
5143 int ret;
5144 struct peer *peer;
5145 uint32_t routeadv = 0;
5146
5147 peer = peer_and_group_lookup_vty(vty, ip_str);
5148 if (!peer)
5149 return CMD_WARNING_CONFIG_FAILED;
5150
5151 if (time_str)
5152 routeadv = strtoul(time_str, NULL, 10);
5153
5154 if (set)
5155 ret = peer_advertise_interval_set(peer, routeadv);
5156 else
5157 ret = peer_advertise_interval_unset(peer);
5158
5159 return bgp_vty_return(vty, ret);
5160 }
5161
5162 DEFUN (neighbor_advertise_interval,
5163 neighbor_advertise_interval_cmd,
5164 "neighbor <A.B.C.D|X:X::X:X|WORD> advertisement-interval (0-600)",
5165 NEIGHBOR_STR
5166 NEIGHBOR_ADDR_STR2
5167 "Minimum interval between sending BGP routing updates\n"
5168 "time in seconds\n")
5169 {
5170 int idx_peer = 1;
5171 int idx_number = 3;
5172 return peer_advertise_interval_vty(vty, argv[idx_peer]->arg,
5173 argv[idx_number]->arg, 1);
5174 }
5175
5176 DEFUN (no_neighbor_advertise_interval,
5177 no_neighbor_advertise_interval_cmd,
5178 "no neighbor <A.B.C.D|X:X::X:X|WORD> advertisement-interval [(0-600)]",
5179 NO_STR
5180 NEIGHBOR_STR
5181 NEIGHBOR_ADDR_STR2
5182 "Minimum interval between sending BGP routing updates\n"
5183 "time in seconds\n")
5184 {
5185 int idx_peer = 2;
5186 return peer_advertise_interval_vty(vty, argv[idx_peer]->arg, NULL, 0);
5187 }
5188
5189
5190 /* Time to wait before processing route-map updates */
5191 DEFUN (bgp_set_route_map_delay_timer,
5192 bgp_set_route_map_delay_timer_cmd,
5193 "bgp route-map delay-timer (0-600)",
5194 SET_STR
5195 "BGP route-map delay timer\n"
5196 "Time in secs to wait before processing route-map changes\n"
5197 "0 disables the timer, no route updates happen when route-maps change\n")
5198 {
5199 int idx_number = 3;
5200 uint32_t rmap_delay_timer;
5201
5202 if (argv[idx_number]->arg) {
5203 rmap_delay_timer = strtoul(argv[idx_number]->arg, NULL, 10);
5204 bm->rmap_update_timer = rmap_delay_timer;
5205
5206 /* if the dynamic update handling is being disabled, and a timer
5207 * is
5208 * running, stop the timer and act as if the timer has already
5209 * fired.
5210 */
5211 if (!rmap_delay_timer && bm->t_rmap_update) {
5212 BGP_TIMER_OFF(bm->t_rmap_update);
5213 thread_execute(bm->master, bgp_route_map_update_timer,
5214 NULL, 0);
5215 }
5216 return CMD_SUCCESS;
5217 } else {
5218 vty_out(vty, "%% BGP invalid route-map delay-timer\n");
5219 return CMD_WARNING_CONFIG_FAILED;
5220 }
5221 }
5222
5223 DEFUN (no_bgp_set_route_map_delay_timer,
5224 no_bgp_set_route_map_delay_timer_cmd,
5225 "no bgp route-map delay-timer [(0-600)]",
5226 NO_STR
5227 BGP_STR
5228 "Default BGP route-map delay timer\n"
5229 "Reset to default time to wait for processing route-map changes\n"
5230 "0 disables the timer, no route updates happen when route-maps change\n")
5231 {
5232
5233 bm->rmap_update_timer = RMAP_DEFAULT_UPDATE_TIMER;
5234
5235 return CMD_SUCCESS;
5236 }
5237
5238
5239 /* neighbor interface */
5240 static int peer_interface_vty(struct vty *vty, const char *ip_str,
5241 const char *str)
5242 {
5243 struct peer *peer;
5244
5245 peer = peer_lookup_vty(vty, ip_str);
5246 if (!peer || peer->conf_if) {
5247 vty_out(vty, "%% BGP invalid peer %s\n", ip_str);
5248 return CMD_WARNING_CONFIG_FAILED;
5249 }
5250
5251 if (str)
5252 peer_interface_set(peer, str);
5253 else
5254 peer_interface_unset(peer);
5255
5256 return CMD_SUCCESS;
5257 }
5258
5259 DEFUN (neighbor_interface,
5260 neighbor_interface_cmd,
5261 "neighbor <A.B.C.D|X:X::X:X> interface WORD",
5262 NEIGHBOR_STR
5263 NEIGHBOR_ADDR_STR
5264 "Interface\n"
5265 "Interface name\n")
5266 {
5267 int idx_ip = 1;
5268 int idx_word = 3;
5269 return peer_interface_vty(vty, argv[idx_ip]->arg, argv[idx_word]->arg);
5270 }
5271
5272 DEFUN (no_neighbor_interface,
5273 no_neighbor_interface_cmd,
5274 "no neighbor <A.B.C.D|X:X::X:X|WORD> interface WORD",
5275 NO_STR
5276 NEIGHBOR_STR
5277 NEIGHBOR_ADDR_STR2
5278 "Interface\n"
5279 "Interface name\n")
5280 {
5281 int idx_peer = 2;
5282 return peer_interface_vty(vty, argv[idx_peer]->arg, NULL);
5283 }
5284
5285 DEFUN (neighbor_distribute_list,
5286 neighbor_distribute_list_cmd,
5287 "neighbor <A.B.C.D|X:X::X:X|WORD> distribute-list <(1-199)|(1300-2699)|WORD> <in|out>",
5288 NEIGHBOR_STR
5289 NEIGHBOR_ADDR_STR2
5290 "Filter updates to/from this neighbor\n"
5291 "IP access-list number\n"
5292 "IP access-list number (expanded range)\n"
5293 "IP Access-list name\n"
5294 "Filter incoming updates\n"
5295 "Filter outgoing updates\n")
5296 {
5297 int idx_peer = 1;
5298 int idx_acl = 3;
5299 int direct, ret;
5300 struct peer *peer;
5301
5302 const char *pstr = argv[idx_peer]->arg;
5303 const char *acl = argv[idx_acl]->arg;
5304 const char *inout = argv[argc - 1]->text;
5305
5306 peer = peer_and_group_lookup_vty(vty, pstr);
5307 if (!peer)
5308 return CMD_WARNING_CONFIG_FAILED;
5309
5310 /* Check filter direction. */
5311 direct = strmatch(inout, "in") ? FILTER_IN : FILTER_OUT;
5312 ret = peer_distribute_set(peer, bgp_node_afi(vty), bgp_node_safi(vty),
5313 direct, acl);
5314
5315 return bgp_vty_return(vty, ret);
5316 }
5317
5318 ALIAS_HIDDEN(
5319 neighbor_distribute_list, neighbor_distribute_list_hidden_cmd,
5320 "neighbor <A.B.C.D|X:X::X:X|WORD> distribute-list <(1-199)|(1300-2699)|WORD> <in|out>",
5321 NEIGHBOR_STR NEIGHBOR_ADDR_STR2
5322 "Filter updates to/from this neighbor\n"
5323 "IP access-list number\n"
5324 "IP access-list number (expanded range)\n"
5325 "IP Access-list name\n"
5326 "Filter incoming updates\n"
5327 "Filter outgoing updates\n")
5328
5329 DEFUN (no_neighbor_distribute_list,
5330 no_neighbor_distribute_list_cmd,
5331 "no neighbor <A.B.C.D|X:X::X:X|WORD> distribute-list <(1-199)|(1300-2699)|WORD> <in|out>",
5332 NO_STR
5333 NEIGHBOR_STR
5334 NEIGHBOR_ADDR_STR2
5335 "Filter updates to/from this neighbor\n"
5336 "IP access-list number\n"
5337 "IP access-list number (expanded range)\n"
5338 "IP Access-list name\n"
5339 "Filter incoming updates\n"
5340 "Filter outgoing updates\n")
5341 {
5342 int idx_peer = 2;
5343 int direct, ret;
5344 struct peer *peer;
5345
5346 const char *pstr = argv[idx_peer]->arg;
5347 const char *inout = argv[argc - 1]->text;
5348
5349 peer = peer_and_group_lookup_vty(vty, pstr);
5350 if (!peer)
5351 return CMD_WARNING_CONFIG_FAILED;
5352
5353 /* Check filter direction. */
5354 direct = strmatch(inout, "in") ? FILTER_IN : FILTER_OUT;
5355 ret = peer_distribute_unset(peer, bgp_node_afi(vty), bgp_node_safi(vty),
5356 direct);
5357
5358 return bgp_vty_return(vty, ret);
5359 }
5360
5361 ALIAS_HIDDEN(
5362 no_neighbor_distribute_list, no_neighbor_distribute_list_hidden_cmd,
5363 "no neighbor <A.B.C.D|X:X::X:X|WORD> distribute-list <(1-199)|(1300-2699)|WORD> <in|out>",
5364 NO_STR NEIGHBOR_STR NEIGHBOR_ADDR_STR2
5365 "Filter updates to/from this neighbor\n"
5366 "IP access-list number\n"
5367 "IP access-list number (expanded range)\n"
5368 "IP Access-list name\n"
5369 "Filter incoming updates\n"
5370 "Filter outgoing updates\n")
5371
5372 /* Set prefix list to the peer. */
5373 static int peer_prefix_list_set_vty(struct vty *vty, const char *ip_str,
5374 afi_t afi, safi_t safi,
5375 const char *name_str,
5376 const char *direct_str)
5377 {
5378 int ret;
5379 int direct = FILTER_IN;
5380 struct peer *peer;
5381
5382 peer = peer_and_group_lookup_vty(vty, ip_str);
5383 if (!peer)
5384 return CMD_WARNING_CONFIG_FAILED;
5385
5386 /* Check filter direction. */
5387 if (strncmp(direct_str, "i", 1) == 0)
5388 direct = FILTER_IN;
5389 else if (strncmp(direct_str, "o", 1) == 0)
5390 direct = FILTER_OUT;
5391
5392 ret = peer_prefix_list_set(peer, afi, safi, direct, name_str);
5393
5394 return bgp_vty_return(vty, ret);
5395 }
5396
5397 static int peer_prefix_list_unset_vty(struct vty *vty, const char *ip_str,
5398 afi_t afi, safi_t safi,
5399 const char *direct_str)
5400 {
5401 int ret;
5402 struct peer *peer;
5403 int direct = FILTER_IN;
5404
5405 peer = peer_and_group_lookup_vty(vty, ip_str);
5406 if (!peer)
5407 return CMD_WARNING_CONFIG_FAILED;
5408
5409 /* Check filter direction. */
5410 if (strncmp(direct_str, "i", 1) == 0)
5411 direct = FILTER_IN;
5412 else if (strncmp(direct_str, "o", 1) == 0)
5413 direct = FILTER_OUT;
5414
5415 ret = peer_prefix_list_unset(peer, afi, safi, direct);
5416
5417 return bgp_vty_return(vty, ret);
5418 }
5419
5420 DEFUN (neighbor_prefix_list,
5421 neighbor_prefix_list_cmd,
5422 "neighbor <A.B.C.D|X:X::X:X|WORD> prefix-list WORD <in|out>",
5423 NEIGHBOR_STR
5424 NEIGHBOR_ADDR_STR2
5425 "Filter updates to/from this neighbor\n"
5426 "Name of a prefix list\n"
5427 "Filter incoming updates\n"
5428 "Filter outgoing updates\n")
5429 {
5430 int idx_peer = 1;
5431 int idx_word = 3;
5432 int idx_in_out = 4;
5433 return peer_prefix_list_set_vty(
5434 vty, argv[idx_peer]->arg, bgp_node_afi(vty), bgp_node_safi(vty),
5435 argv[idx_word]->arg, argv[idx_in_out]->arg);
5436 }
5437
5438 ALIAS_HIDDEN(neighbor_prefix_list, neighbor_prefix_list_hidden_cmd,
5439 "neighbor <A.B.C.D|X:X::X:X|WORD> prefix-list WORD <in|out>",
5440 NEIGHBOR_STR NEIGHBOR_ADDR_STR2
5441 "Filter updates to/from this neighbor\n"
5442 "Name of a prefix list\n"
5443 "Filter incoming updates\n"
5444 "Filter outgoing updates\n")
5445
5446 DEFUN (no_neighbor_prefix_list,
5447 no_neighbor_prefix_list_cmd,
5448 "no neighbor <A.B.C.D|X:X::X:X|WORD> prefix-list WORD <in|out>",
5449 NO_STR
5450 NEIGHBOR_STR
5451 NEIGHBOR_ADDR_STR2
5452 "Filter updates to/from this neighbor\n"
5453 "Name of a prefix list\n"
5454 "Filter incoming updates\n"
5455 "Filter outgoing updates\n")
5456 {
5457 int idx_peer = 2;
5458 int idx_in_out = 5;
5459 return peer_prefix_list_unset_vty(vty, argv[idx_peer]->arg,
5460 bgp_node_afi(vty), bgp_node_safi(vty),
5461 argv[idx_in_out]->arg);
5462 }
5463
5464 ALIAS_HIDDEN(no_neighbor_prefix_list, no_neighbor_prefix_list_hidden_cmd,
5465 "no neighbor <A.B.C.D|X:X::X:X|WORD> prefix-list WORD <in|out>",
5466 NO_STR NEIGHBOR_STR NEIGHBOR_ADDR_STR2
5467 "Filter updates to/from this neighbor\n"
5468 "Name of a prefix list\n"
5469 "Filter incoming updates\n"
5470 "Filter outgoing updates\n")
5471
5472 static int peer_aslist_set_vty(struct vty *vty, const char *ip_str, afi_t afi,
5473 safi_t safi, const char *name_str,
5474 const char *direct_str)
5475 {
5476 int ret;
5477 struct peer *peer;
5478 int direct = FILTER_IN;
5479
5480 peer = peer_and_group_lookup_vty(vty, ip_str);
5481 if (!peer)
5482 return CMD_WARNING_CONFIG_FAILED;
5483
5484 /* Check filter direction. */
5485 if (strncmp(direct_str, "i", 1) == 0)
5486 direct = FILTER_IN;
5487 else if (strncmp(direct_str, "o", 1) == 0)
5488 direct = FILTER_OUT;
5489
5490 ret = peer_aslist_set(peer, afi, safi, direct, name_str);
5491
5492 return bgp_vty_return(vty, ret);
5493 }
5494
5495 static int peer_aslist_unset_vty(struct vty *vty, const char *ip_str, afi_t afi,
5496 safi_t safi, const char *direct_str)
5497 {
5498 int ret;
5499 struct peer *peer;
5500 int direct = FILTER_IN;
5501
5502 peer = peer_and_group_lookup_vty(vty, ip_str);
5503 if (!peer)
5504 return CMD_WARNING_CONFIG_FAILED;
5505
5506 /* Check filter direction. */
5507 if (strncmp(direct_str, "i", 1) == 0)
5508 direct = FILTER_IN;
5509 else if (strncmp(direct_str, "o", 1) == 0)
5510 direct = FILTER_OUT;
5511
5512 ret = peer_aslist_unset(peer, afi, safi, direct);
5513
5514 return bgp_vty_return(vty, ret);
5515 }
5516
5517 DEFUN (neighbor_filter_list,
5518 neighbor_filter_list_cmd,
5519 "neighbor <A.B.C.D|X:X::X:X|WORD> filter-list WORD <in|out>",
5520 NEIGHBOR_STR
5521 NEIGHBOR_ADDR_STR2
5522 "Establish BGP filters\n"
5523 "AS path access-list name\n"
5524 "Filter incoming routes\n"
5525 "Filter outgoing routes\n")
5526 {
5527 int idx_peer = 1;
5528 int idx_word = 3;
5529 int idx_in_out = 4;
5530 return peer_aslist_set_vty(vty, argv[idx_peer]->arg, bgp_node_afi(vty),
5531 bgp_node_safi(vty), argv[idx_word]->arg,
5532 argv[idx_in_out]->arg);
5533 }
5534
5535 ALIAS_HIDDEN(neighbor_filter_list, neighbor_filter_list_hidden_cmd,
5536 "neighbor <A.B.C.D|X:X::X:X|WORD> filter-list WORD <in|out>",
5537 NEIGHBOR_STR NEIGHBOR_ADDR_STR2
5538 "Establish BGP filters\n"
5539 "AS path access-list name\n"
5540 "Filter incoming routes\n"
5541 "Filter outgoing routes\n")
5542
5543 DEFUN (no_neighbor_filter_list,
5544 no_neighbor_filter_list_cmd,
5545 "no neighbor <A.B.C.D|X:X::X:X|WORD> filter-list WORD <in|out>",
5546 NO_STR
5547 NEIGHBOR_STR
5548 NEIGHBOR_ADDR_STR2
5549 "Establish BGP filters\n"
5550 "AS path access-list name\n"
5551 "Filter incoming routes\n"
5552 "Filter outgoing routes\n")
5553 {
5554 int idx_peer = 2;
5555 int idx_in_out = 5;
5556 return peer_aslist_unset_vty(vty, argv[idx_peer]->arg,
5557 bgp_node_afi(vty), bgp_node_safi(vty),
5558 argv[idx_in_out]->arg);
5559 }
5560
5561 ALIAS_HIDDEN(no_neighbor_filter_list, no_neighbor_filter_list_hidden_cmd,
5562 "no neighbor <A.B.C.D|X:X::X:X|WORD> filter-list WORD <in|out>",
5563 NO_STR NEIGHBOR_STR NEIGHBOR_ADDR_STR2
5564 "Establish BGP filters\n"
5565 "AS path access-list name\n"
5566 "Filter incoming routes\n"
5567 "Filter outgoing routes\n")
5568
5569 /* Set route-map to the peer. */
5570 static int peer_route_map_set_vty(struct vty *vty, const char *ip_str,
5571 afi_t afi, safi_t safi, const char *name_str,
5572 const char *direct_str)
5573 {
5574 int ret;
5575 struct peer *peer;
5576 int direct = RMAP_IN;
5577
5578 peer = peer_and_group_lookup_vty(vty, ip_str);
5579 if (!peer)
5580 return CMD_WARNING_CONFIG_FAILED;
5581
5582 /* Check filter direction. */
5583 if (strncmp(direct_str, "in", 2) == 0)
5584 direct = RMAP_IN;
5585 else if (strncmp(direct_str, "o", 1) == 0)
5586 direct = RMAP_OUT;
5587
5588 ret = peer_route_map_set(peer, afi, safi, direct, name_str);
5589
5590 return bgp_vty_return(vty, ret);
5591 }
5592
5593 static int peer_route_map_unset_vty(struct vty *vty, const char *ip_str,
5594 afi_t afi, safi_t safi,
5595 const char *direct_str)
5596 {
5597 int ret;
5598 struct peer *peer;
5599 int direct = RMAP_IN;
5600
5601 peer = peer_and_group_lookup_vty(vty, ip_str);
5602 if (!peer)
5603 return CMD_WARNING_CONFIG_FAILED;
5604
5605 /* Check filter direction. */
5606 if (strncmp(direct_str, "in", 2) == 0)
5607 direct = RMAP_IN;
5608 else if (strncmp(direct_str, "o", 1) == 0)
5609 direct = RMAP_OUT;
5610
5611 ret = peer_route_map_unset(peer, afi, safi, direct);
5612
5613 return bgp_vty_return(vty, ret);
5614 }
5615
5616 DEFUN (neighbor_route_map,
5617 neighbor_route_map_cmd,
5618 "neighbor <A.B.C.D|X:X::X:X|WORD> route-map WORD <in|out>",
5619 NEIGHBOR_STR
5620 NEIGHBOR_ADDR_STR2
5621 "Apply route map to neighbor\n"
5622 "Name of route map\n"
5623 "Apply map to incoming routes\n"
5624 "Apply map to outbound routes\n")
5625 {
5626 int idx_peer = 1;
5627 int idx_word = 3;
5628 int idx_in_out = 4;
5629 return peer_route_map_set_vty(
5630 vty, argv[idx_peer]->arg, bgp_node_afi(vty), bgp_node_safi(vty),
5631 argv[idx_word]->arg, argv[idx_in_out]->arg);
5632 }
5633
5634 ALIAS_HIDDEN(neighbor_route_map, neighbor_route_map_hidden_cmd,
5635 "neighbor <A.B.C.D|X:X::X:X|WORD> route-map WORD <in|out>",
5636 NEIGHBOR_STR NEIGHBOR_ADDR_STR2
5637 "Apply route map to neighbor\n"
5638 "Name of route map\n"
5639 "Apply map to incoming routes\n"
5640 "Apply map to outbound routes\n")
5641
5642 DEFUN (no_neighbor_route_map,
5643 no_neighbor_route_map_cmd,
5644 "no neighbor <A.B.C.D|X:X::X:X|WORD> route-map WORD <in|out>",
5645 NO_STR
5646 NEIGHBOR_STR
5647 NEIGHBOR_ADDR_STR2
5648 "Apply route map to neighbor\n"
5649 "Name of route map\n"
5650 "Apply map to incoming routes\n"
5651 "Apply map to outbound routes\n")
5652 {
5653 int idx_peer = 2;
5654 int idx_in_out = 5;
5655 return peer_route_map_unset_vty(vty, argv[idx_peer]->arg,
5656 bgp_node_afi(vty), bgp_node_safi(vty),
5657 argv[idx_in_out]->arg);
5658 }
5659
5660 ALIAS_HIDDEN(no_neighbor_route_map, no_neighbor_route_map_hidden_cmd,
5661 "no neighbor <A.B.C.D|X:X::X:X|WORD> route-map WORD <in|out>",
5662 NO_STR NEIGHBOR_STR NEIGHBOR_ADDR_STR2
5663 "Apply route map to neighbor\n"
5664 "Name of route map\n"
5665 "Apply map to incoming routes\n"
5666 "Apply map to outbound routes\n")
5667
5668 /* Set unsuppress-map to the peer. */
5669 static int peer_unsuppress_map_set_vty(struct vty *vty, const char *ip_str,
5670 afi_t afi, safi_t safi,
5671 const char *name_str)
5672 {
5673 int ret;
5674 struct peer *peer;
5675
5676 peer = peer_and_group_lookup_vty(vty, ip_str);
5677 if (!peer)
5678 return CMD_WARNING_CONFIG_FAILED;
5679
5680 ret = peer_unsuppress_map_set(peer, afi, safi, name_str);
5681
5682 return bgp_vty_return(vty, ret);
5683 }
5684
5685 /* Unset route-map from the peer. */
5686 static int peer_unsuppress_map_unset_vty(struct vty *vty, const char *ip_str,
5687 afi_t afi, safi_t safi)
5688 {
5689 int ret;
5690 struct peer *peer;
5691
5692 peer = peer_and_group_lookup_vty(vty, ip_str);
5693 if (!peer)
5694 return CMD_WARNING_CONFIG_FAILED;
5695
5696 ret = peer_unsuppress_map_unset(peer, afi, safi);
5697
5698 return bgp_vty_return(vty, ret);
5699 }
5700
5701 DEFUN (neighbor_unsuppress_map,
5702 neighbor_unsuppress_map_cmd,
5703 "neighbor <A.B.C.D|X:X::X:X|WORD> unsuppress-map WORD",
5704 NEIGHBOR_STR
5705 NEIGHBOR_ADDR_STR2
5706 "Route-map to selectively unsuppress suppressed routes\n"
5707 "Name of route map\n")
5708 {
5709 int idx_peer = 1;
5710 int idx_word = 3;
5711 return peer_unsuppress_map_set_vty(
5712 vty, argv[idx_peer]->arg, bgp_node_afi(vty), bgp_node_safi(vty),
5713 argv[idx_word]->arg);
5714 }
5715
5716 ALIAS_HIDDEN(neighbor_unsuppress_map, neighbor_unsuppress_map_hidden_cmd,
5717 "neighbor <A.B.C.D|X:X::X:X|WORD> unsuppress-map WORD",
5718 NEIGHBOR_STR NEIGHBOR_ADDR_STR2
5719 "Route-map to selectively unsuppress suppressed routes\n"
5720 "Name of route map\n")
5721
5722 DEFUN (no_neighbor_unsuppress_map,
5723 no_neighbor_unsuppress_map_cmd,
5724 "no neighbor <A.B.C.D|X:X::X:X|WORD> unsuppress-map WORD",
5725 NO_STR
5726 NEIGHBOR_STR
5727 NEIGHBOR_ADDR_STR2
5728 "Route-map to selectively unsuppress suppressed routes\n"
5729 "Name of route map\n")
5730 {
5731 int idx_peer = 2;
5732 return peer_unsuppress_map_unset_vty(vty, argv[idx_peer]->arg,
5733 bgp_node_afi(vty),
5734 bgp_node_safi(vty));
5735 }
5736
5737 ALIAS_HIDDEN(no_neighbor_unsuppress_map, no_neighbor_unsuppress_map_hidden_cmd,
5738 "no neighbor <A.B.C.D|X:X::X:X|WORD> unsuppress-map WORD",
5739 NO_STR NEIGHBOR_STR NEIGHBOR_ADDR_STR2
5740 "Route-map to selectively unsuppress suppressed routes\n"
5741 "Name of route map\n")
5742
5743 static int peer_maximum_prefix_set_vty(struct vty *vty, const char *ip_str,
5744 afi_t afi, safi_t safi,
5745 const char *num_str,
5746 const char *threshold_str, int warning,
5747 const char *restart_str)
5748 {
5749 int ret;
5750 struct peer *peer;
5751 uint32_t max;
5752 uint8_t threshold;
5753 uint16_t restart;
5754
5755 peer = peer_and_group_lookup_vty(vty, ip_str);
5756 if (!peer)
5757 return CMD_WARNING_CONFIG_FAILED;
5758
5759 max = strtoul(num_str, NULL, 10);
5760 if (threshold_str)
5761 threshold = atoi(threshold_str);
5762 else
5763 threshold = MAXIMUM_PREFIX_THRESHOLD_DEFAULT;
5764
5765 if (restart_str)
5766 restart = atoi(restart_str);
5767 else
5768 restart = 0;
5769
5770 ret = peer_maximum_prefix_set(peer, afi, safi, max, threshold, warning,
5771 restart);
5772
5773 return bgp_vty_return(vty, ret);
5774 }
5775
5776 static int peer_maximum_prefix_unset_vty(struct vty *vty, const char *ip_str,
5777 afi_t afi, safi_t safi)
5778 {
5779 int ret;
5780 struct peer *peer;
5781
5782 peer = peer_and_group_lookup_vty(vty, ip_str);
5783 if (!peer)
5784 return CMD_WARNING_CONFIG_FAILED;
5785
5786 ret = peer_maximum_prefix_unset(peer, afi, safi);
5787
5788 return bgp_vty_return(vty, ret);
5789 }
5790
5791 /* Maximum number of prefix configuration. prefix count is different
5792 for each peer configuration. So this configuration can be set for
5793 each peer configuration. */
5794 DEFUN (neighbor_maximum_prefix,
5795 neighbor_maximum_prefix_cmd,
5796 "neighbor <A.B.C.D|X:X::X:X|WORD> maximum-prefix (1-4294967295)",
5797 NEIGHBOR_STR
5798 NEIGHBOR_ADDR_STR2
5799 "Maximum number of prefix accept from this peer\n"
5800 "maximum no. of prefix limit\n")
5801 {
5802 int idx_peer = 1;
5803 int idx_number = 3;
5804 return peer_maximum_prefix_set_vty(
5805 vty, argv[idx_peer]->arg, bgp_node_afi(vty), bgp_node_safi(vty),
5806 argv[idx_number]->arg, NULL, 0, NULL);
5807 }
5808
5809 ALIAS_HIDDEN(neighbor_maximum_prefix, neighbor_maximum_prefix_hidden_cmd,
5810 "neighbor <A.B.C.D|X:X::X:X|WORD> maximum-prefix (1-4294967295)",
5811 NEIGHBOR_STR NEIGHBOR_ADDR_STR2
5812 "Maximum number of prefix accept from this peer\n"
5813 "maximum no. of prefix limit\n")
5814
5815 DEFUN (neighbor_maximum_prefix_threshold,
5816 neighbor_maximum_prefix_threshold_cmd,
5817 "neighbor <A.B.C.D|X:X::X:X|WORD> maximum-prefix (1-4294967295) (1-100)",
5818 NEIGHBOR_STR
5819 NEIGHBOR_ADDR_STR2
5820 "Maximum number of prefix accept from this peer\n"
5821 "maximum no. of prefix limit\n"
5822 "Threshold value (%) at which to generate a warning msg\n")
5823 {
5824 int idx_peer = 1;
5825 int idx_number = 3;
5826 int idx_number_2 = 4;
5827 return peer_maximum_prefix_set_vty(
5828 vty, argv[idx_peer]->arg, bgp_node_afi(vty), bgp_node_safi(vty),
5829 argv[idx_number]->arg, argv[idx_number_2]->arg, 0, NULL);
5830 }
5831
5832 ALIAS_HIDDEN(
5833 neighbor_maximum_prefix_threshold,
5834 neighbor_maximum_prefix_threshold_hidden_cmd,
5835 "neighbor <A.B.C.D|X:X::X:X|WORD> maximum-prefix (1-4294967295) (1-100)",
5836 NEIGHBOR_STR NEIGHBOR_ADDR_STR2
5837 "Maximum number of prefix accept from this peer\n"
5838 "maximum no. of prefix limit\n"
5839 "Threshold value (%) at which to generate a warning msg\n")
5840
5841 DEFUN (neighbor_maximum_prefix_warning,
5842 neighbor_maximum_prefix_warning_cmd,
5843 "neighbor <A.B.C.D|X:X::X:X|WORD> maximum-prefix (1-4294967295) warning-only",
5844 NEIGHBOR_STR
5845 NEIGHBOR_ADDR_STR2
5846 "Maximum number of prefix accept from this peer\n"
5847 "maximum no. of prefix limit\n"
5848 "Only give warning message when limit is exceeded\n")
5849 {
5850 int idx_peer = 1;
5851 int idx_number = 3;
5852 return peer_maximum_prefix_set_vty(
5853 vty, argv[idx_peer]->arg, bgp_node_afi(vty), bgp_node_safi(vty),
5854 argv[idx_number]->arg, NULL, 1, NULL);
5855 }
5856
5857 ALIAS_HIDDEN(
5858 neighbor_maximum_prefix_warning,
5859 neighbor_maximum_prefix_warning_hidden_cmd,
5860 "neighbor <A.B.C.D|X:X::X:X|WORD> maximum-prefix (1-4294967295) warning-only",
5861 NEIGHBOR_STR NEIGHBOR_ADDR_STR2
5862 "Maximum number of prefix accept from this peer\n"
5863 "maximum no. of prefix limit\n"
5864 "Only give warning message when limit is exceeded\n")
5865
5866 DEFUN (neighbor_maximum_prefix_threshold_warning,
5867 neighbor_maximum_prefix_threshold_warning_cmd,
5868 "neighbor <A.B.C.D|X:X::X:X|WORD> maximum-prefix (1-4294967295) (1-100) warning-only",
5869 NEIGHBOR_STR
5870 NEIGHBOR_ADDR_STR2
5871 "Maximum number of prefix accept from this peer\n"
5872 "maximum no. of prefix limit\n"
5873 "Threshold value (%) at which to generate a warning msg\n"
5874 "Only give warning message when limit is exceeded\n")
5875 {
5876 int idx_peer = 1;
5877 int idx_number = 3;
5878 int idx_number_2 = 4;
5879 return peer_maximum_prefix_set_vty(
5880 vty, argv[idx_peer]->arg, bgp_node_afi(vty), bgp_node_safi(vty),
5881 argv[idx_number]->arg, argv[idx_number_2]->arg, 1, NULL);
5882 }
5883
5884 ALIAS_HIDDEN(
5885 neighbor_maximum_prefix_threshold_warning,
5886 neighbor_maximum_prefix_threshold_warning_hidden_cmd,
5887 "neighbor <A.B.C.D|X:X::X:X|WORD> maximum-prefix (1-4294967295) (1-100) warning-only",
5888 NEIGHBOR_STR NEIGHBOR_ADDR_STR2
5889 "Maximum number of prefix accept from this peer\n"
5890 "maximum no. of prefix limit\n"
5891 "Threshold value (%) at which to generate a warning msg\n"
5892 "Only give warning message when limit is exceeded\n")
5893
5894 DEFUN (neighbor_maximum_prefix_restart,
5895 neighbor_maximum_prefix_restart_cmd,
5896 "neighbor <A.B.C.D|X:X::X:X|WORD> maximum-prefix (1-4294967295) restart (1-65535)",
5897 NEIGHBOR_STR
5898 NEIGHBOR_ADDR_STR2
5899 "Maximum number of prefix accept from this peer\n"
5900 "maximum no. of prefix limit\n"
5901 "Restart bgp connection after limit is exceeded\n"
5902 "Restart interval in minutes\n")
5903 {
5904 int idx_peer = 1;
5905 int idx_number = 3;
5906 int idx_number_2 = 5;
5907 return peer_maximum_prefix_set_vty(
5908 vty, argv[idx_peer]->arg, bgp_node_afi(vty), bgp_node_safi(vty),
5909 argv[idx_number]->arg, NULL, 0, argv[idx_number_2]->arg);
5910 }
5911
5912 ALIAS_HIDDEN(
5913 neighbor_maximum_prefix_restart,
5914 neighbor_maximum_prefix_restart_hidden_cmd,
5915 "neighbor <A.B.C.D|X:X::X:X|WORD> maximum-prefix (1-4294967295) restart (1-65535)",
5916 NEIGHBOR_STR NEIGHBOR_ADDR_STR2
5917 "Maximum number of prefix accept from this peer\n"
5918 "maximum no. of prefix limit\n"
5919 "Restart bgp connection after limit is exceeded\n"
5920 "Restart interval in minutes\n")
5921
5922 DEFUN (neighbor_maximum_prefix_threshold_restart,
5923 neighbor_maximum_prefix_threshold_restart_cmd,
5924 "neighbor <A.B.C.D|X:X::X:X|WORD> maximum-prefix (1-4294967295) (1-100) restart (1-65535)",
5925 NEIGHBOR_STR
5926 NEIGHBOR_ADDR_STR2
5927 "Maximum number of prefixes to accept from this peer\n"
5928 "maximum no. of prefix limit\n"
5929 "Threshold value (%) at which to generate a warning msg\n"
5930 "Restart bgp connection after limit is exceeded\n"
5931 "Restart interval in minutes\n")
5932 {
5933 int idx_peer = 1;
5934 int idx_number = 3;
5935 int idx_number_2 = 4;
5936 int idx_number_3 = 6;
5937 return peer_maximum_prefix_set_vty(
5938 vty, argv[idx_peer]->arg, bgp_node_afi(vty), bgp_node_safi(vty),
5939 argv[idx_number]->arg, argv[idx_number_2]->arg, 0,
5940 argv[idx_number_3]->arg);
5941 }
5942
5943 ALIAS_HIDDEN(
5944 neighbor_maximum_prefix_threshold_restart,
5945 neighbor_maximum_prefix_threshold_restart_hidden_cmd,
5946 "neighbor <A.B.C.D|X:X::X:X|WORD> maximum-prefix (1-4294967295) (1-100) restart (1-65535)",
5947 NEIGHBOR_STR NEIGHBOR_ADDR_STR2
5948 "Maximum number of prefixes to accept from this peer\n"
5949 "maximum no. of prefix limit\n"
5950 "Threshold value (%) at which to generate a warning msg\n"
5951 "Restart bgp connection after limit is exceeded\n"
5952 "Restart interval in minutes\n")
5953
5954 DEFUN (no_neighbor_maximum_prefix,
5955 no_neighbor_maximum_prefix_cmd,
5956 "no neighbor <A.B.C.D|X:X::X:X|WORD> maximum-prefix [(1-4294967295) [(1-100)] [restart (1-65535)] [warning-only]]",
5957 NO_STR
5958 NEIGHBOR_STR
5959 NEIGHBOR_ADDR_STR2
5960 "Maximum number of prefixes to accept from this peer\n"
5961 "maximum no. of prefix limit\n"
5962 "Threshold value (%) at which to generate a warning msg\n"
5963 "Restart bgp connection after limit is exceeded\n"
5964 "Restart interval in minutes\n"
5965 "Only give warning message when limit is exceeded\n")
5966 {
5967 int idx_peer = 2;
5968 return peer_maximum_prefix_unset_vty(vty, argv[idx_peer]->arg,
5969 bgp_node_afi(vty),
5970 bgp_node_safi(vty));
5971 }
5972
5973 ALIAS_HIDDEN(
5974 no_neighbor_maximum_prefix, no_neighbor_maximum_prefix_hidden_cmd,
5975 "no neighbor <A.B.C.D|X:X::X:X|WORD> maximum-prefix [(1-4294967295) [(1-100)] [restart (1-65535)] [warning-only]]",
5976 NO_STR NEIGHBOR_STR NEIGHBOR_ADDR_STR2
5977 "Maximum number of prefixes to accept from this peer\n"
5978 "maximum no. of prefix limit\n"
5979 "Threshold value (%) at which to generate a warning msg\n"
5980 "Restart bgp connection after limit is exceeded\n"
5981 "Restart interval in minutes\n"
5982 "Only give warning message when limit is exceeded\n")
5983
5984
5985 /* "neighbor allowas-in" */
5986 DEFUN (neighbor_allowas_in,
5987 neighbor_allowas_in_cmd,
5988 "neighbor <A.B.C.D|X:X::X:X|WORD> allowas-in [<(1-10)|origin>]",
5989 NEIGHBOR_STR
5990 NEIGHBOR_ADDR_STR2
5991 "Accept as-path with my AS present in it\n"
5992 "Number of occurances of AS number\n"
5993 "Only accept my AS in the as-path if the route was originated in my AS\n")
5994 {
5995 int idx_peer = 1;
5996 int idx_number_origin = 3;
5997 int ret;
5998 int origin = 0;
5999 struct peer *peer;
6000 int allow_num = 0;
6001
6002 peer = peer_and_group_lookup_vty(vty, argv[idx_peer]->arg);
6003 if (!peer)
6004 return CMD_WARNING_CONFIG_FAILED;
6005
6006 if (argc <= idx_number_origin)
6007 allow_num = 3;
6008 else {
6009 if (argv[idx_number_origin]->type == WORD_TKN)
6010 origin = 1;
6011 else
6012 allow_num = atoi(argv[idx_number_origin]->arg);
6013 }
6014
6015 ret = peer_allowas_in_set(peer, bgp_node_afi(vty), bgp_node_safi(vty),
6016 allow_num, origin);
6017
6018 return bgp_vty_return(vty, ret);
6019 }
6020
6021 ALIAS_HIDDEN(
6022 neighbor_allowas_in, neighbor_allowas_in_hidden_cmd,
6023 "neighbor <A.B.C.D|X:X::X:X|WORD> allowas-in [<(1-10)|origin>]",
6024 NEIGHBOR_STR NEIGHBOR_ADDR_STR2
6025 "Accept as-path with my AS present in it\n"
6026 "Number of occurances of AS number\n"
6027 "Only accept my AS in the as-path if the route was originated in my AS\n")
6028
6029 DEFUN (no_neighbor_allowas_in,
6030 no_neighbor_allowas_in_cmd,
6031 "no neighbor <A.B.C.D|X:X::X:X|WORD> allowas-in [<(1-10)|origin>]",
6032 NO_STR
6033 NEIGHBOR_STR
6034 NEIGHBOR_ADDR_STR2
6035 "allow local ASN appears in aspath attribute\n"
6036 "Number of occurances of AS number\n"
6037 "Only accept my AS in the as-path if the route was originated in my AS\n")
6038 {
6039 int idx_peer = 2;
6040 int ret;
6041 struct peer *peer;
6042
6043 peer = peer_and_group_lookup_vty(vty, argv[idx_peer]->arg);
6044 if (!peer)
6045 return CMD_WARNING_CONFIG_FAILED;
6046
6047 ret = peer_allowas_in_unset(peer, bgp_node_afi(vty),
6048 bgp_node_safi(vty));
6049
6050 return bgp_vty_return(vty, ret);
6051 }
6052
6053 ALIAS_HIDDEN(
6054 no_neighbor_allowas_in, no_neighbor_allowas_in_hidden_cmd,
6055 "no neighbor <A.B.C.D|X:X::X:X|WORD> allowas-in [<(1-10)|origin>]",
6056 NO_STR NEIGHBOR_STR NEIGHBOR_ADDR_STR2
6057 "allow local ASN appears in aspath attribute\n"
6058 "Number of occurances of AS number\n"
6059 "Only accept my AS in the as-path if the route was originated in my AS\n")
6060
6061 DEFUN (neighbor_ttl_security,
6062 neighbor_ttl_security_cmd,
6063 "neighbor <A.B.C.D|X:X::X:X|WORD> ttl-security hops (1-254)",
6064 NEIGHBOR_STR
6065 NEIGHBOR_ADDR_STR2
6066 "BGP ttl-security parameters\n"
6067 "Specify the maximum number of hops to the BGP peer\n"
6068 "Number of hops to BGP peer\n")
6069 {
6070 int idx_peer = 1;
6071 int idx_number = 4;
6072 struct peer *peer;
6073 int gtsm_hops;
6074
6075 peer = peer_and_group_lookup_vty(vty, argv[idx_peer]->arg);
6076 if (!peer)
6077 return CMD_WARNING_CONFIG_FAILED;
6078
6079 gtsm_hops = strtoul(argv[idx_number]->arg, NULL, 10);
6080
6081 /*
6082 * If 'neighbor swpX', then this is for directly connected peers,
6083 * we should not accept a ttl-security hops value greater than 1.
6084 */
6085 if (peer->conf_if && (gtsm_hops > 1)) {
6086 vty_out(vty,
6087 "%s is directly connected peer, hops cannot exceed 1\n",
6088 argv[idx_peer]->arg);
6089 return CMD_WARNING_CONFIG_FAILED;
6090 }
6091
6092 return bgp_vty_return(vty, peer_ttl_security_hops_set(peer, gtsm_hops));
6093 }
6094
6095 DEFUN (no_neighbor_ttl_security,
6096 no_neighbor_ttl_security_cmd,
6097 "no neighbor <A.B.C.D|X:X::X:X|WORD> ttl-security hops (1-254)",
6098 NO_STR
6099 NEIGHBOR_STR
6100 NEIGHBOR_ADDR_STR2
6101 "BGP ttl-security parameters\n"
6102 "Specify the maximum number of hops to the BGP peer\n"
6103 "Number of hops to BGP peer\n")
6104 {
6105 int idx_peer = 2;
6106 struct peer *peer;
6107
6108 peer = peer_and_group_lookup_vty(vty, argv[idx_peer]->arg);
6109 if (!peer)
6110 return CMD_WARNING_CONFIG_FAILED;
6111
6112 return bgp_vty_return(vty, peer_ttl_security_hops_unset(peer));
6113 }
6114
6115 DEFUN (neighbor_addpath_tx_all_paths,
6116 neighbor_addpath_tx_all_paths_cmd,
6117 "neighbor <A.B.C.D|X:X::X:X|WORD> addpath-tx-all-paths",
6118 NEIGHBOR_STR
6119 NEIGHBOR_ADDR_STR2
6120 "Use addpath to advertise all paths to a neighbor\n")
6121 {
6122 int idx_peer = 1;
6123 struct peer *peer;
6124
6125 peer = peer_and_group_lookup_vty(vty, argv[idx_peer]->arg);
6126 if (!peer)
6127 return CMD_WARNING_CONFIG_FAILED;
6128
6129 return peer_af_flag_set_vty(vty, argv[idx_peer]->arg, bgp_node_afi(vty),
6130 bgp_node_safi(vty),
6131 PEER_FLAG_ADDPATH_TX_ALL_PATHS);
6132 }
6133
6134 ALIAS_HIDDEN(neighbor_addpath_tx_all_paths,
6135 neighbor_addpath_tx_all_paths_hidden_cmd,
6136 "neighbor <A.B.C.D|X:X::X:X|WORD> addpath-tx-all-paths",
6137 NEIGHBOR_STR NEIGHBOR_ADDR_STR2
6138 "Use addpath to advertise all paths to a neighbor\n")
6139
6140 DEFUN (no_neighbor_addpath_tx_all_paths,
6141 no_neighbor_addpath_tx_all_paths_cmd,
6142 "no neighbor <A.B.C.D|X:X::X:X|WORD> addpath-tx-all-paths",
6143 NO_STR
6144 NEIGHBOR_STR
6145 NEIGHBOR_ADDR_STR2
6146 "Use addpath to advertise all paths to a neighbor\n")
6147 {
6148 int idx_peer = 2;
6149 return peer_af_flag_unset_vty(vty, argv[idx_peer]->arg,
6150 bgp_node_afi(vty), bgp_node_safi(vty),
6151 PEER_FLAG_ADDPATH_TX_ALL_PATHS);
6152 }
6153
6154 ALIAS_HIDDEN(no_neighbor_addpath_tx_all_paths,
6155 no_neighbor_addpath_tx_all_paths_hidden_cmd,
6156 "no neighbor <A.B.C.D|X:X::X:X|WORD> addpath-tx-all-paths",
6157 NO_STR NEIGHBOR_STR NEIGHBOR_ADDR_STR2
6158 "Use addpath to advertise all paths to a neighbor\n")
6159
6160 DEFUN (neighbor_addpath_tx_bestpath_per_as,
6161 neighbor_addpath_tx_bestpath_per_as_cmd,
6162 "neighbor <A.B.C.D|X:X::X:X|WORD> addpath-tx-bestpath-per-AS",
6163 NEIGHBOR_STR
6164 NEIGHBOR_ADDR_STR2
6165 "Use addpath to advertise the bestpath per each neighboring AS\n")
6166 {
6167 int idx_peer = 1;
6168 struct peer *peer;
6169
6170 peer = peer_and_group_lookup_vty(vty, argv[idx_peer]->arg);
6171 if (!peer)
6172 return CMD_WARNING_CONFIG_FAILED;
6173
6174 return peer_af_flag_set_vty(vty, argv[idx_peer]->arg, bgp_node_afi(vty),
6175 bgp_node_safi(vty),
6176 PEER_FLAG_ADDPATH_TX_BESTPATH_PER_AS);
6177 }
6178
6179 ALIAS_HIDDEN(neighbor_addpath_tx_bestpath_per_as,
6180 neighbor_addpath_tx_bestpath_per_as_hidden_cmd,
6181 "neighbor <A.B.C.D|X:X::X:X|WORD> addpath-tx-bestpath-per-AS",
6182 NEIGHBOR_STR NEIGHBOR_ADDR_STR2
6183 "Use addpath to advertise the bestpath per each neighboring AS\n")
6184
6185 DEFUN (no_neighbor_addpath_tx_bestpath_per_as,
6186 no_neighbor_addpath_tx_bestpath_per_as_cmd,
6187 "no neighbor <A.B.C.D|X:X::X:X|WORD> addpath-tx-bestpath-per-AS",
6188 NO_STR
6189 NEIGHBOR_STR
6190 NEIGHBOR_ADDR_STR2
6191 "Use addpath to advertise the bestpath per each neighboring AS\n")
6192 {
6193 int idx_peer = 2;
6194 return peer_af_flag_unset_vty(vty, argv[idx_peer]->arg,
6195 bgp_node_afi(vty), bgp_node_safi(vty),
6196 PEER_FLAG_ADDPATH_TX_BESTPATH_PER_AS);
6197 }
6198
6199 ALIAS_HIDDEN(no_neighbor_addpath_tx_bestpath_per_as,
6200 no_neighbor_addpath_tx_bestpath_per_as_hidden_cmd,
6201 "no neighbor <A.B.C.D|X:X::X:X|WORD> addpath-tx-bestpath-per-AS",
6202 NO_STR NEIGHBOR_STR NEIGHBOR_ADDR_STR2
6203 "Use addpath to advertise the bestpath per each neighboring AS\n")
6204
6205 static int set_ecom_list(struct vty *vty, int argc, struct cmd_token **argv,
6206 struct ecommunity **list)
6207 {
6208 struct ecommunity *ecom = NULL;
6209 struct ecommunity *ecomadd;
6210
6211 for (; argc; --argc, ++argv) {
6212
6213 ecomadd = ecommunity_str2com(argv[0]->arg,
6214 ECOMMUNITY_ROUTE_TARGET, 0);
6215 if (!ecomadd) {
6216 vty_out(vty, "Malformed community-list value\n");
6217 if (ecom)
6218 ecommunity_free(&ecom);
6219 return CMD_WARNING_CONFIG_FAILED;
6220 }
6221
6222 if (ecom) {
6223 ecommunity_merge(ecom, ecomadd);
6224 ecommunity_free(&ecomadd);
6225 } else {
6226 ecom = ecomadd;
6227 }
6228 }
6229
6230 if (*list) {
6231 ecommunity_free(&*list);
6232 }
6233 *list = ecom;
6234
6235 return CMD_SUCCESS;
6236 }
6237
6238 /*
6239 * v2vimport is true if we are handling a `import vrf ...` command
6240 */
6241 static afi_t vpn_policy_getafi(struct vty *vty, struct bgp *bgp, bool v2vimport)
6242 {
6243 afi_t afi;
6244
6245 switch (vty->node) {
6246 case BGP_IPV4_NODE:
6247 afi = AFI_IP;
6248 break;
6249 case BGP_IPV6_NODE:
6250 afi = AFI_IP6;
6251 break;
6252 default:
6253 vty_out(vty,
6254 "%% context error: valid only in address-family <ipv4|ipv6> unicast block\n");
6255 return AFI_MAX;
6256 }
6257
6258 if (!v2vimport) {
6259 if (CHECK_FLAG(bgp->af_flags[afi][SAFI_UNICAST],
6260 BGP_CONFIG_VRF_TO_VRF_IMPORT)
6261 || CHECK_FLAG(bgp->af_flags[afi][SAFI_UNICAST],
6262 BGP_CONFIG_VRF_TO_VRF_EXPORT)) {
6263 vty_out(vty,
6264 "%% error: Please unconfigure import vrf commands before using vpn commands\n");
6265 return AFI_MAX;
6266 }
6267 } else {
6268 if (CHECK_FLAG(bgp->af_flags[afi][SAFI_UNICAST],
6269 BGP_CONFIG_VRF_TO_MPLSVPN_EXPORT)
6270 || CHECK_FLAG(bgp->af_flags[afi][SAFI_UNICAST],
6271 BGP_CONFIG_MPLSVPN_TO_VRF_IMPORT)) {
6272 vty_out(vty,
6273 "%% error: Please unconfigure vpn to vrf commands before using import vrf commands\n");
6274 return AFI_MAX;
6275 }
6276 }
6277 return afi;
6278 }
6279
6280 DEFPY (af_rd_vpn_export,
6281 af_rd_vpn_export_cmd,
6282 "[no] rd vpn export ASN:NN_OR_IP-ADDRESS:NN$rd_str",
6283 NO_STR
6284 "Specify route distinguisher\n"
6285 "Between current address-family and vpn\n"
6286 "For routes leaked from current address-family to vpn\n"
6287 "Route Distinguisher (<as-number>:<number> | <ip-address>:<number>)\n")
6288 {
6289 VTY_DECLVAR_CONTEXT(bgp, bgp);
6290 struct prefix_rd prd;
6291 int ret;
6292 afi_t afi;
6293 int idx = 0;
6294 int yes = 1;
6295
6296 if (argv_find(argv, argc, "no", &idx))
6297 yes = 0;
6298
6299 if (yes) {
6300 ret = str2prefix_rd(rd_str, &prd);
6301 if (!ret) {
6302 vty_out(vty, "%% Malformed rd\n");
6303 return CMD_WARNING_CONFIG_FAILED;
6304 }
6305 }
6306
6307 afi = vpn_policy_getafi(vty, bgp, false);
6308 if (afi == AFI_MAX)
6309 return CMD_WARNING_CONFIG_FAILED;
6310
6311 /*
6312 * pre-change: un-export vpn routes (vpn->vrf routes unaffected)
6313 */
6314 vpn_leak_prechange(BGP_VPN_POLICY_DIR_TOVPN, afi,
6315 bgp_get_default(), bgp);
6316
6317 if (yes) {
6318 bgp->vpn_policy[afi].tovpn_rd = prd;
6319 SET_FLAG(bgp->vpn_policy[afi].flags,
6320 BGP_VPN_POLICY_TOVPN_RD_SET);
6321 } else {
6322 UNSET_FLAG(bgp->vpn_policy[afi].flags,
6323 BGP_VPN_POLICY_TOVPN_RD_SET);
6324 }
6325
6326 /* post-change: re-export vpn routes */
6327 vpn_leak_postchange(BGP_VPN_POLICY_DIR_TOVPN, afi,
6328 bgp_get_default(), bgp);
6329
6330 return CMD_SUCCESS;
6331 }
6332
6333 ALIAS (af_rd_vpn_export,
6334 af_no_rd_vpn_export_cmd,
6335 "no rd vpn export",
6336 NO_STR
6337 "Specify route distinguisher\n"
6338 "Between current address-family and vpn\n"
6339 "For routes leaked from current address-family to vpn\n")
6340
6341 DEFPY (af_label_vpn_export,
6342 af_label_vpn_export_cmd,
6343 "[no] label vpn export <(0-1048575)$label_val|auto$label_auto>",
6344 NO_STR
6345 "label value for VRF\n"
6346 "Between current address-family and vpn\n"
6347 "For routes leaked from current address-family to vpn\n"
6348 "Label Value <0-1048575>\n"
6349 "Automatically assign a label\n")
6350 {
6351 VTY_DECLVAR_CONTEXT(bgp, bgp);
6352 mpls_label_t label = MPLS_LABEL_NONE;
6353 afi_t afi;
6354 int idx = 0;
6355 int yes = 1;
6356
6357 if (argv_find(argv, argc, "no", &idx))
6358 yes = 0;
6359
6360 /* If "no ...", squash trailing parameter */
6361 if (!yes)
6362 label_auto = NULL;
6363
6364 if (yes) {
6365 if (!label_auto)
6366 label = label_val; /* parser should force unsigned */
6367 }
6368
6369 afi = vpn_policy_getafi(vty, bgp, false);
6370 if (afi == AFI_MAX)
6371 return CMD_WARNING_CONFIG_FAILED;
6372
6373
6374 if (label_auto && CHECK_FLAG(bgp->vpn_policy[afi].flags,
6375 BGP_VPN_POLICY_TOVPN_LABEL_AUTO))
6376 /* no change */
6377 return CMD_SUCCESS;
6378
6379 /*
6380 * pre-change: un-export vpn routes (vpn->vrf routes unaffected)
6381 */
6382 vpn_leak_prechange(BGP_VPN_POLICY_DIR_TOVPN, afi,
6383 bgp_get_default(), bgp);
6384
6385 if (!label_auto && CHECK_FLAG(bgp->vpn_policy[afi].flags,
6386 BGP_VPN_POLICY_TOVPN_LABEL_AUTO)) {
6387
6388 if (bgp->vpn_policy[afi].tovpn_label != MPLS_LABEL_NONE) {
6389
6390 /*
6391 * label has previously been automatically
6392 * assigned by labelpool: release it
6393 *
6394 * NB if tovpn_label == MPLS_LABEL_NONE it
6395 * means the automatic assignment is in flight
6396 * and therefore the labelpool callback must
6397 * detect that the auto label is not needed.
6398 */
6399
6400 bgp_lp_release(LP_TYPE_VRF,
6401 &bgp->vpn_policy[afi],
6402 bgp->vpn_policy[afi].tovpn_label);
6403 }
6404 UNSET_FLAG(bgp->vpn_policy[afi].flags,
6405 BGP_VPN_POLICY_TOVPN_LABEL_AUTO);
6406 }
6407
6408 bgp->vpn_policy[afi].tovpn_label = label;
6409 if (label_auto) {
6410 SET_FLAG(bgp->vpn_policy[afi].flags,
6411 BGP_VPN_POLICY_TOVPN_LABEL_AUTO);
6412 bgp_lp_get(LP_TYPE_VRF, &bgp->vpn_policy[afi],
6413 vpn_leak_label_callback);
6414 }
6415
6416 /* post-change: re-export vpn routes */
6417 vpn_leak_postchange(BGP_VPN_POLICY_DIR_TOVPN, afi,
6418 bgp_get_default(), bgp);
6419
6420 return CMD_SUCCESS;
6421 }
6422
6423 ALIAS (af_label_vpn_export,
6424 af_no_label_vpn_export_cmd,
6425 "no label vpn export",
6426 NO_STR
6427 "label value for VRF\n"
6428 "Between current address-family and vpn\n"
6429 "For routes leaked from current address-family to vpn\n")
6430
6431 DEFPY (af_nexthop_vpn_export,
6432 af_nexthop_vpn_export_cmd,
6433 "[no] nexthop vpn export <A.B.C.D|X:X::X:X>$nexthop_str",
6434 NO_STR
6435 "Specify next hop to use for VRF advertised prefixes\n"
6436 "Between current address-family and vpn\n"
6437 "For routes leaked from current address-family to vpn\n"
6438 "IPv4 prefix\n"
6439 "IPv6 prefix\n")
6440 {
6441 VTY_DECLVAR_CONTEXT(bgp, bgp);
6442 afi_t afi;
6443 struct prefix p;
6444 int idx = 0;
6445 int yes = 1;
6446
6447 if (argv_find(argv, argc, "no", &idx))
6448 yes = 0;
6449
6450 if (yes) {
6451 if (!sockunion2hostprefix(nexthop_str, &p))
6452 return CMD_WARNING_CONFIG_FAILED;
6453 }
6454
6455 afi = vpn_policy_getafi(vty, bgp, false);
6456 if (afi == AFI_MAX)
6457 return CMD_WARNING_CONFIG_FAILED;
6458
6459 /*
6460 * pre-change: un-export vpn routes (vpn->vrf routes unaffected)
6461 */
6462 vpn_leak_prechange(BGP_VPN_POLICY_DIR_TOVPN, afi,
6463 bgp_get_default(), bgp);
6464
6465 if (yes) {
6466 bgp->vpn_policy[afi].tovpn_nexthop = p;
6467 SET_FLAG(bgp->vpn_policy[afi].flags,
6468 BGP_VPN_POLICY_TOVPN_NEXTHOP_SET);
6469 } else {
6470 UNSET_FLAG(bgp->vpn_policy[afi].flags,
6471 BGP_VPN_POLICY_TOVPN_NEXTHOP_SET);
6472 }
6473
6474 /* post-change: re-export vpn routes */
6475 vpn_leak_postchange(BGP_VPN_POLICY_DIR_TOVPN, afi,
6476 bgp_get_default(), bgp);
6477
6478 return CMD_SUCCESS;
6479 }
6480
6481 ALIAS (af_nexthop_vpn_export,
6482 af_no_nexthop_vpn_export_cmd,
6483 "no nexthop vpn export",
6484 NO_STR
6485 "Specify next hop to use for VRF advertised prefixes\n"
6486 "Between current address-family and vpn\n"
6487 "For routes leaked from current address-family to vpn\n")
6488
6489 static int vpn_policy_getdirs(struct vty *vty, const char *dstr, int *dodir)
6490 {
6491 if (!strcmp(dstr, "import")) {
6492 dodir[BGP_VPN_POLICY_DIR_FROMVPN] = 1;
6493 } else if (!strcmp(dstr, "export")) {
6494 dodir[BGP_VPN_POLICY_DIR_TOVPN] = 1;
6495 } else if (!strcmp(dstr, "both")) {
6496 dodir[BGP_VPN_POLICY_DIR_FROMVPN] = 1;
6497 dodir[BGP_VPN_POLICY_DIR_TOVPN] = 1;
6498 } else {
6499 vty_out(vty, "%% direction parse error\n");
6500 return CMD_WARNING_CONFIG_FAILED;
6501 }
6502 return CMD_SUCCESS;
6503 }
6504
6505 DEFPY (af_rt_vpn_imexport,
6506 af_rt_vpn_imexport_cmd,
6507 "[no] <rt|route-target> vpn <import|export|both>$direction_str RTLIST...",
6508 NO_STR
6509 "Specify route target list\n"
6510 "Specify route target list\n"
6511 "Between current address-family and vpn\n"
6512 "For routes leaked from vpn to current address-family: match any\n"
6513 "For routes leaked from current address-family to vpn: set\n"
6514 "both import: match any and export: set\n"
6515 "Space separated route target list (A.B.C.D:MN|EF:OPQR|GHJK:MN)\n")
6516 {
6517 VTY_DECLVAR_CONTEXT(bgp, bgp);
6518 int ret;
6519 struct ecommunity *ecom = NULL;
6520 int dodir[BGP_VPN_POLICY_DIR_MAX] = {0};
6521 vpn_policy_direction_t dir;
6522 afi_t afi;
6523 int idx = 0;
6524 int yes = 1;
6525
6526 if (argv_find(argv, argc, "no", &idx))
6527 yes = 0;
6528
6529 afi = vpn_policy_getafi(vty, bgp, false);
6530 if (afi == AFI_MAX)
6531 return CMD_WARNING_CONFIG_FAILED;
6532
6533 ret = vpn_policy_getdirs(vty, direction_str, dodir);
6534 if (ret != CMD_SUCCESS)
6535 return ret;
6536
6537 if (yes) {
6538 if (!argv_find(argv, argc, "RTLIST", &idx)) {
6539 vty_out(vty, "%% Missing RTLIST\n");
6540 return CMD_WARNING_CONFIG_FAILED;
6541 }
6542 ret = set_ecom_list(vty, argc - idx, argv + idx, &ecom);
6543 if (ret != CMD_SUCCESS) {
6544 return ret;
6545 }
6546 }
6547
6548 for (dir = 0; dir < BGP_VPN_POLICY_DIR_MAX; ++dir) {
6549 if (!dodir[dir])
6550 continue;
6551
6552 vpn_leak_prechange(dir, afi, bgp_get_default(), bgp);
6553
6554 if (yes) {
6555 if (bgp->vpn_policy[afi].rtlist[dir])
6556 ecommunity_free(
6557 &bgp->vpn_policy[afi].rtlist[dir]);
6558 bgp->vpn_policy[afi].rtlist[dir] =
6559 ecommunity_dup(ecom);
6560 } else {
6561 if (bgp->vpn_policy[afi].rtlist[dir])
6562 ecommunity_free(
6563 &bgp->vpn_policy[afi].rtlist[dir]);
6564 bgp->vpn_policy[afi].rtlist[dir] = NULL;
6565 }
6566
6567 vpn_leak_postchange(dir, afi, bgp_get_default(), bgp);
6568 }
6569
6570 if (ecom)
6571 ecommunity_free(&ecom);
6572
6573 return CMD_SUCCESS;
6574 }
6575
6576 ALIAS (af_rt_vpn_imexport,
6577 af_no_rt_vpn_imexport_cmd,
6578 "no <rt|route-target> vpn <import|export|both>$direction_str",
6579 NO_STR
6580 "Specify route target list\n"
6581 "Specify route target list\n"
6582 "Between current address-family and vpn\n"
6583 "For routes leaked from vpn to current address-family\n"
6584 "For routes leaked from current address-family to vpn\n"
6585 "both import and export\n")
6586
6587 DEFPY (af_route_map_vpn_imexport,
6588 af_route_map_vpn_imexport_cmd,
6589 /* future: "route-map <vpn|evpn|vrf NAME> <import|export> RMAP" */
6590 "[no] route-map vpn <import|export>$direction_str RMAP$rmap_str",
6591 NO_STR
6592 "Specify route map\n"
6593 "Between current address-family and vpn\n"
6594 "For routes leaked from vpn to current address-family\n"
6595 "For routes leaked from current address-family to vpn\n"
6596 "name of route-map\n")
6597 {
6598 VTY_DECLVAR_CONTEXT(bgp, bgp);
6599 int ret;
6600 int dodir[BGP_VPN_POLICY_DIR_MAX] = {0};
6601 vpn_policy_direction_t dir;
6602 afi_t afi;
6603 int idx = 0;
6604 int yes = 1;
6605
6606 if (argv_find(argv, argc, "no", &idx))
6607 yes = 0;
6608
6609 afi = vpn_policy_getafi(vty, bgp, false);
6610 if (afi == AFI_MAX)
6611 return CMD_WARNING_CONFIG_FAILED;
6612
6613 ret = vpn_policy_getdirs(vty, direction_str, dodir);
6614 if (ret != CMD_SUCCESS)
6615 return ret;
6616
6617 for (dir = 0; dir < BGP_VPN_POLICY_DIR_MAX; ++dir) {
6618 if (!dodir[dir])
6619 continue;
6620
6621 vpn_leak_prechange(dir, afi, bgp_get_default(), bgp);
6622
6623 if (yes) {
6624 if (bgp->vpn_policy[afi].rmap_name[dir])
6625 XFREE(MTYPE_ROUTE_MAP_NAME,
6626 bgp->vpn_policy[afi].rmap_name[dir]);
6627 bgp->vpn_policy[afi].rmap_name[dir] = XSTRDUP(
6628 MTYPE_ROUTE_MAP_NAME, rmap_str);
6629 bgp->vpn_policy[afi].rmap[dir] =
6630 route_map_lookup_by_name(rmap_str);
6631 if (!bgp->vpn_policy[afi].rmap[dir])
6632 return CMD_SUCCESS;
6633 } else {
6634 if (bgp->vpn_policy[afi].rmap_name[dir])
6635 XFREE(MTYPE_ROUTE_MAP_NAME,
6636 bgp->vpn_policy[afi].rmap_name[dir]);
6637 bgp->vpn_policy[afi].rmap_name[dir] = NULL;
6638 bgp->vpn_policy[afi].rmap[dir] = NULL;
6639 }
6640
6641 vpn_leak_postchange(dir, afi, bgp_get_default(), bgp);
6642 }
6643
6644 return CMD_SUCCESS;
6645 }
6646
6647 ALIAS (af_route_map_vpn_imexport,
6648 af_no_route_map_vpn_imexport_cmd,
6649 "no route-map vpn <import|export>$direction_str",
6650 NO_STR
6651 "Specify route map\n"
6652 "Between current address-family and vpn\n"
6653 "For routes leaked from vpn to current address-family\n"
6654 "For routes leaked from current address-family to vpn\n")
6655
6656 DEFPY(af_import_vrf_route_map, af_import_vrf_route_map_cmd,
6657 "[no] import vrf route-map RMAP$rmap_str",
6658 NO_STR
6659 "Import routes from another VRF\n"
6660 "Vrf routes being filtered\n"
6661 "Specify route map\n"
6662 "name of route-map\n")
6663 {
6664 VTY_DECLVAR_CONTEXT(bgp, bgp);
6665 vpn_policy_direction_t dir = BGP_VPN_POLICY_DIR_FROMVPN;
6666 afi_t afi;
6667 int idx = 0;
6668 int yes = 1;
6669 struct bgp *bgp_default;
6670
6671 if (argv_find(argv, argc, "no", &idx))
6672 yes = 0;
6673
6674 afi = vpn_policy_getafi(vty, bgp, true);
6675 if (afi == AFI_MAX)
6676 return CMD_WARNING_CONFIG_FAILED;
6677
6678 bgp_default = bgp_get_default();
6679 if (!bgp_default) {
6680 int32_t ret;
6681 as_t as = bgp->as;
6682
6683 /* Auto-create assuming the same AS */
6684 ret = bgp_get(&bgp_default, &as, NULL,
6685 BGP_INSTANCE_TYPE_DEFAULT);
6686
6687 if (ret) {
6688 vty_out(vty,
6689 "VRF default is not configured as a bgp instance\n");
6690 return CMD_WARNING;
6691 }
6692 }
6693
6694 vpn_leak_prechange(dir, afi, bgp_get_default(), bgp);
6695
6696 if (yes) {
6697 if (bgp->vpn_policy[afi].rmap_name[dir])
6698 XFREE(MTYPE_ROUTE_MAP_NAME,
6699 bgp->vpn_policy[afi].rmap_name[dir]);
6700 bgp->vpn_policy[afi].rmap_name[dir] =
6701 XSTRDUP(MTYPE_ROUTE_MAP_NAME, rmap_str);
6702 bgp->vpn_policy[afi].rmap[dir] =
6703 route_map_lookup_by_name(rmap_str);
6704 if (!bgp->vpn_policy[afi].rmap[dir])
6705 return CMD_SUCCESS;
6706 } else {
6707 if (bgp->vpn_policy[afi].rmap_name[dir])
6708 XFREE(MTYPE_ROUTE_MAP_NAME,
6709 bgp->vpn_policy[afi].rmap_name[dir]);
6710 bgp->vpn_policy[afi].rmap_name[dir] = NULL;
6711 bgp->vpn_policy[afi].rmap[dir] = NULL;
6712 }
6713
6714 vpn_leak_postchange(dir, afi, bgp_get_default(), bgp);
6715
6716 return CMD_SUCCESS;
6717 }
6718
6719 ALIAS(af_import_vrf_route_map, af_no_import_vrf_route_map_cmd,
6720 "no import vrf route-map",
6721 NO_STR
6722 "Import routes from another VRF\n"
6723 "Vrf routes being filtered\n"
6724 "Specify route map\n")
6725
6726 DEFPY (bgp_imexport_vrf,
6727 bgp_imexport_vrf_cmd,
6728 "[no] import vrf NAME$import_name",
6729 NO_STR
6730 "Import routes from another VRF\n"
6731 "VRF to import from\n"
6732 "The name of the VRF\n")
6733 {
6734 VTY_DECLVAR_CONTEXT(bgp, bgp);
6735 struct listnode *node;
6736 struct bgp *vrf_bgp, *bgp_default;
6737 int32_t ret = 0;
6738 as_t as = bgp->as;
6739 bool remove = false;
6740 int32_t idx = 0;
6741 char *vname;
6742 enum bgp_instance_type bgp_type = BGP_INSTANCE_TYPE_VRF;
6743 safi_t safi;
6744 afi_t afi;
6745
6746 if (import_name == NULL) {
6747 vty_out(vty, "%% Missing import name\n");
6748 return CMD_WARNING;
6749 }
6750
6751 if (argv_find(argv, argc, "no", &idx))
6752 remove = true;
6753
6754 afi = vpn_policy_getafi(vty, bgp, true);
6755 if (afi == AFI_MAX)
6756 return CMD_WARNING_CONFIG_FAILED;
6757
6758 safi = bgp_node_safi(vty);
6759
6760 if (((BGP_INSTANCE_TYPE_DEFAULT == bgp->inst_type)
6761 && (strcmp(import_name, BGP_DEFAULT_NAME) == 0))
6762 || (bgp->name && (strcmp(import_name, bgp->name) == 0))) {
6763 vty_out(vty, "%% Cannot %s vrf %s into itself\n",
6764 remove ? "unimport" : "import", import_name);
6765 return CMD_WARNING;
6766 }
6767
6768 bgp_default = bgp_get_default();
6769 if (!bgp_default) {
6770 /* Auto-create assuming the same AS */
6771 ret = bgp_get(&bgp_default, &as, NULL,
6772 BGP_INSTANCE_TYPE_DEFAULT);
6773
6774 if (ret) {
6775 vty_out(vty,
6776 "VRF default is not configured as a bgp instance\n");
6777 return CMD_WARNING;
6778 }
6779 }
6780
6781 vrf_bgp = bgp_lookup_by_name(import_name);
6782 if (!vrf_bgp) {
6783 if (strcmp(import_name, BGP_DEFAULT_NAME) == 0)
6784 vrf_bgp = bgp_default;
6785 else
6786 /* Auto-create assuming the same AS */
6787 ret = bgp_get(&vrf_bgp, &as, import_name, bgp_type);
6788
6789 if (ret) {
6790 vty_out(vty,
6791 "VRF %s is not configured as a bgp instance\n",
6792 import_name);
6793 return CMD_WARNING;
6794 }
6795 }
6796
6797 if (remove) {
6798 vrf_unimport_from_vrf(bgp, vrf_bgp, afi, safi);
6799 } else {
6800 /* Already importing from "import_vrf"? */
6801 for (ALL_LIST_ELEMENTS_RO(bgp->vpn_policy[afi].import_vrf, node,
6802 vname)) {
6803 if (strcmp(vname, import_name) == 0)
6804 return CMD_WARNING;
6805 }
6806
6807 vrf_import_from_vrf(bgp, vrf_bgp, afi, safi);
6808 }
6809
6810 return CMD_SUCCESS;
6811 }
6812
6813 /* This command is valid only in a bgp vrf instance or the default instance */
6814 DEFPY (bgp_imexport_vpn,
6815 bgp_imexport_vpn_cmd,
6816 "[no] <import|export>$direction_str vpn",
6817 NO_STR
6818 "Import routes to this address-family\n"
6819 "Export routes from this address-family\n"
6820 "to/from default instance VPN RIB\n")
6821 {
6822 VTY_DECLVAR_CONTEXT(bgp, bgp);
6823 int previous_state;
6824 afi_t afi;
6825 safi_t safi;
6826 int idx = 0;
6827 int yes = 1;
6828 int flag;
6829 vpn_policy_direction_t dir;
6830
6831 if (argv_find(argv, argc, "no", &idx))
6832 yes = 0;
6833
6834 if (BGP_INSTANCE_TYPE_VRF != bgp->inst_type &&
6835 BGP_INSTANCE_TYPE_DEFAULT != bgp->inst_type) {
6836
6837 vty_out(vty, "%% import|export vpn valid only for bgp vrf or default instance\n");
6838 return CMD_WARNING_CONFIG_FAILED;
6839 }
6840
6841 afi = bgp_node_afi(vty);
6842 safi = bgp_node_safi(vty);
6843 if ((SAFI_UNICAST != safi) || ((AFI_IP != afi) && (AFI_IP6 != afi))) {
6844 vty_out(vty, "%% import|export vpn valid only for unicast ipv4|ipv6\n");
6845 return CMD_WARNING_CONFIG_FAILED;
6846 }
6847
6848 if (!strcmp(direction_str, "import")) {
6849 flag = BGP_CONFIG_MPLSVPN_TO_VRF_IMPORT;
6850 dir = BGP_VPN_POLICY_DIR_FROMVPN;
6851 } else if (!strcmp(direction_str, "export")) {
6852 flag = BGP_CONFIG_VRF_TO_MPLSVPN_EXPORT;
6853 dir = BGP_VPN_POLICY_DIR_TOVPN;
6854 } else {
6855 vty_out(vty, "%% unknown direction %s\n", direction_str);
6856 return CMD_WARNING_CONFIG_FAILED;
6857 }
6858
6859 previous_state = CHECK_FLAG(bgp->af_flags[afi][safi], flag);
6860
6861 if (yes) {
6862 SET_FLAG(bgp->af_flags[afi][safi], flag);
6863 if (!previous_state) {
6864 /* trigger export current vrf */
6865 vpn_leak_postchange(dir, afi, bgp_get_default(), bgp);
6866 }
6867 } else {
6868 if (previous_state) {
6869 /* trigger un-export current vrf */
6870 vpn_leak_prechange(dir, afi, bgp_get_default(), bgp);
6871 }
6872 UNSET_FLAG(bgp->af_flags[afi][safi], flag);
6873 }
6874
6875 return CMD_SUCCESS;
6876 }
6877
6878 DEFPY (af_routetarget_import,
6879 af_routetarget_import_cmd,
6880 "[no] <rt|route-target> redirect import RTLIST...",
6881 NO_STR
6882 "Specify route target list\n"
6883 "Specify route target list\n"
6884 "Flow-spec redirect type route target\n"
6885 "Import routes to this address-family\n"
6886 "Space separated route target list (A.B.C.D:MN|EF:OPQR|GHJK:MN)\n")
6887 {
6888 VTY_DECLVAR_CONTEXT(bgp, bgp);
6889 int ret;
6890 struct ecommunity *ecom = NULL;
6891 afi_t afi;
6892 int idx = 0;
6893 int yes = 1;
6894
6895 if (argv_find(argv, argc, "no", &idx))
6896 yes = 0;
6897
6898 afi = vpn_policy_getafi(vty, bgp, false);
6899 if (afi == AFI_MAX)
6900 return CMD_WARNING_CONFIG_FAILED;
6901
6902 if (yes) {
6903 if (!argv_find(argv, argc, "RTLIST", &idx)) {
6904 vty_out(vty, "%% Missing RTLIST\n");
6905 return CMD_WARNING_CONFIG_FAILED;
6906 }
6907 ret = set_ecom_list(vty, argc - idx, argv + idx, &ecom);
6908 if (ret != CMD_SUCCESS)
6909 return ret;
6910 }
6911
6912 if (yes) {
6913 if (bgp->vpn_policy[afi].import_redirect_rtlist)
6914 ecommunity_free(&bgp->vpn_policy[afi]
6915 .import_redirect_rtlist);
6916 bgp->vpn_policy[afi].import_redirect_rtlist =
6917 ecommunity_dup(ecom);
6918 } else {
6919 if (bgp->vpn_policy[afi].import_redirect_rtlist)
6920 ecommunity_free(&bgp->vpn_policy[afi]
6921 .import_redirect_rtlist);
6922 bgp->vpn_policy[afi].import_redirect_rtlist = NULL;
6923 }
6924
6925 if (ecom)
6926 ecommunity_free(&ecom);
6927
6928 return CMD_SUCCESS;
6929 }
6930
6931 DEFUN_NOSH (address_family_ipv4_safi,
6932 address_family_ipv4_safi_cmd,
6933 "address-family ipv4 [<unicast|multicast|vpn|labeled-unicast|flowspec>]",
6934 "Enter Address Family command mode\n"
6935 "Address Family\n"
6936 BGP_SAFI_WITH_LABEL_HELP_STR)
6937 {
6938
6939 if (argc == 3) {
6940 VTY_DECLVAR_CONTEXT(bgp, bgp);
6941 safi_t safi = bgp_vty_safi_from_str(argv[2]->text);
6942 if (bgp->inst_type != BGP_INSTANCE_TYPE_DEFAULT
6943 && safi != SAFI_UNICAST && safi != SAFI_MULTICAST
6944 && safi != SAFI_EVPN) {
6945 vty_out(vty,
6946 "Only Unicast/Multicast/EVPN SAFIs supported in non-core instances.\n");
6947 return CMD_WARNING_CONFIG_FAILED;
6948 }
6949 vty->node = bgp_node_type(AFI_IP, safi);
6950 } else
6951 vty->node = BGP_IPV4_NODE;
6952
6953 return CMD_SUCCESS;
6954 }
6955
6956 DEFUN_NOSH (address_family_ipv6_safi,
6957 address_family_ipv6_safi_cmd,
6958 "address-family ipv6 [<unicast|multicast|vpn|labeled-unicast|flowspec>]",
6959 "Enter Address Family command mode\n"
6960 "Address Family\n"
6961 BGP_SAFI_WITH_LABEL_HELP_STR)
6962 {
6963 if (argc == 3) {
6964 VTY_DECLVAR_CONTEXT(bgp, bgp);
6965 safi_t safi = bgp_vty_safi_from_str(argv[2]->text);
6966 if (bgp->inst_type != BGP_INSTANCE_TYPE_DEFAULT
6967 && safi != SAFI_UNICAST && safi != SAFI_MULTICAST
6968 && safi != SAFI_EVPN) {
6969 vty_out(vty,
6970 "Only Unicast/Multicast/EVPN SAFIs supported in non-core instances.\n");
6971 return CMD_WARNING_CONFIG_FAILED;
6972 }
6973 vty->node = bgp_node_type(AFI_IP6, safi);
6974 } else
6975 vty->node = BGP_IPV6_NODE;
6976
6977 return CMD_SUCCESS;
6978 }
6979
6980 #ifdef KEEP_OLD_VPN_COMMANDS
6981 DEFUN_NOSH (address_family_vpnv4,
6982 address_family_vpnv4_cmd,
6983 "address-family vpnv4 [unicast]",
6984 "Enter Address Family command mode\n"
6985 "Address Family\n"
6986 "Address Family modifier\n")
6987 {
6988 vty->node = BGP_VPNV4_NODE;
6989 return CMD_SUCCESS;
6990 }
6991
6992 DEFUN_NOSH (address_family_vpnv6,
6993 address_family_vpnv6_cmd,
6994 "address-family vpnv6 [unicast]",
6995 "Enter Address Family command mode\n"
6996 "Address Family\n"
6997 "Address Family modifier\n")
6998 {
6999 vty->node = BGP_VPNV6_NODE;
7000 return CMD_SUCCESS;
7001 }
7002 #endif
7003
7004 DEFUN_NOSH (address_family_evpn,
7005 address_family_evpn_cmd,
7006 "address-family l2vpn evpn",
7007 "Enter Address Family command mode\n"
7008 "Address Family\n"
7009 "Address Family modifier\n")
7010 {
7011 VTY_DECLVAR_CONTEXT(bgp, bgp);
7012 vty->node = BGP_EVPN_NODE;
7013 return CMD_SUCCESS;
7014 }
7015
7016 DEFUN_NOSH (exit_address_family,
7017 exit_address_family_cmd,
7018 "exit-address-family",
7019 "Exit from Address Family configuration mode\n")
7020 {
7021 if (vty->node == BGP_IPV4_NODE || vty->node == BGP_IPV4M_NODE
7022 || vty->node == BGP_IPV4L_NODE || vty->node == BGP_VPNV4_NODE
7023 || vty->node == BGP_IPV6_NODE || vty->node == BGP_IPV6M_NODE
7024 || vty->node == BGP_IPV6L_NODE || vty->node == BGP_VPNV6_NODE
7025 || vty->node == BGP_EVPN_NODE
7026 || vty->node == BGP_FLOWSPECV4_NODE
7027 || vty->node == BGP_FLOWSPECV6_NODE)
7028 vty->node = BGP_NODE;
7029 return CMD_SUCCESS;
7030 }
7031
7032 /* Recalculate bestpath and re-advertise a prefix */
7033 static int bgp_clear_prefix(struct vty *vty, const char *view_name,
7034 const char *ip_str, afi_t afi, safi_t safi,
7035 struct prefix_rd *prd)
7036 {
7037 int ret;
7038 struct prefix match;
7039 struct bgp_node *rn;
7040 struct bgp_node *rm;
7041 struct bgp *bgp;
7042 struct bgp_table *table;
7043 struct bgp_table *rib;
7044
7045 /* BGP structure lookup. */
7046 if (view_name) {
7047 bgp = bgp_lookup_by_name(view_name);
7048 if (bgp == NULL) {
7049 vty_out(vty, "%% Can't find BGP instance %s\n",
7050 view_name);
7051 return CMD_WARNING;
7052 }
7053 } else {
7054 bgp = bgp_get_default();
7055 if (bgp == NULL) {
7056 vty_out(vty, "%% No BGP process is configured\n");
7057 return CMD_WARNING;
7058 }
7059 }
7060
7061 /* Check IP address argument. */
7062 ret = str2prefix(ip_str, &match);
7063 if (!ret) {
7064 vty_out(vty, "%% address is malformed\n");
7065 return CMD_WARNING;
7066 }
7067
7068 match.family = afi2family(afi);
7069 rib = bgp->rib[afi][safi];
7070
7071 if (safi == SAFI_MPLS_VPN) {
7072 for (rn = bgp_table_top(rib); rn; rn = bgp_route_next(rn)) {
7073 if (prd && memcmp(rn->p.u.val, prd->val, 8) != 0)
7074 continue;
7075
7076 if ((table = rn->info) != NULL) {
7077 if ((rm = bgp_node_match(table, &match))
7078 != NULL) {
7079 if (rm->p.prefixlen
7080 == match.prefixlen) {
7081 SET_FLAG(rm->flags,
7082 BGP_NODE_USER_CLEAR);
7083 bgp_process(bgp, rm, afi, safi);
7084 }
7085 bgp_unlock_node(rm);
7086 }
7087 }
7088 }
7089 } else {
7090 if ((rn = bgp_node_match(rib, &match)) != NULL) {
7091 if (rn->p.prefixlen == match.prefixlen) {
7092 SET_FLAG(rn->flags, BGP_NODE_USER_CLEAR);
7093 bgp_process(bgp, rn, afi, safi);
7094 }
7095 bgp_unlock_node(rn);
7096 }
7097 }
7098
7099 return CMD_SUCCESS;
7100 }
7101
7102 /* one clear bgp command to rule them all */
7103 DEFUN (clear_ip_bgp_all,
7104 clear_ip_bgp_all_cmd,
7105 "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>]",
7106 CLEAR_STR
7107 IP_STR
7108 BGP_STR
7109 BGP_INSTANCE_HELP_STR
7110 BGP_AFI_HELP_STR
7111 BGP_SAFI_WITH_LABEL_HELP_STR
7112 "Clear all peers\n"
7113 "BGP neighbor address to clear\n"
7114 "BGP IPv6 neighbor to clear\n"
7115 "BGP neighbor on interface to clear\n"
7116 "Clear peers with the AS number\n"
7117 "Clear all external peers\n"
7118 "Clear all members of peer-group\n"
7119 "BGP peer-group name\n"
7120 BGP_SOFT_STR
7121 BGP_SOFT_IN_STR
7122 BGP_SOFT_OUT_STR
7123 BGP_SOFT_IN_STR
7124 "Push out prefix-list ORF and do inbound soft reconfig\n"
7125 BGP_SOFT_OUT_STR)
7126 {
7127 char *vrf = NULL;
7128
7129 afi_t afi = AFI_IP6;
7130 safi_t safi = SAFI_UNICAST;
7131 enum clear_sort clr_sort = clear_peer;
7132 enum bgp_clear_type clr_type;
7133 char *clr_arg = NULL;
7134
7135 int idx = 0;
7136
7137 /* clear [ip] bgp */
7138 if (argv_find(argv, argc, "ip", &idx))
7139 afi = AFI_IP;
7140
7141 /* [<view|vrf> VIEWVRFNAME] */
7142 if (argv_find(argv, argc, "view", &idx)
7143 || argv_find(argv, argc, "vrf", &idx)) {
7144 vrf = argv[idx + 1]->arg;
7145 idx += 2;
7146 }
7147
7148 /* ["BGP_AFI_CMD_STR" ["BGP_SAFI_CMD_STR"]] */
7149 if (argv_find_and_parse_afi(argv, argc, &idx, &afi))
7150 argv_find_and_parse_safi(argv, argc, &idx, &safi);
7151
7152 /* <*|A.B.C.D|X:X::X:X|WORD|(1-4294967295)|external|peer-group WORD> */
7153 if (argv_find(argv, argc, "*", &idx)) {
7154 clr_sort = clear_all;
7155 } else if (argv_find(argv, argc, "A.B.C.D", &idx)) {
7156 clr_sort = clear_peer;
7157 clr_arg = argv[idx]->arg;
7158 } else if (argv_find(argv, argc, "X:X::X:X", &idx)) {
7159 clr_sort = clear_peer;
7160 clr_arg = argv[idx]->arg;
7161 } else if (argv_find(argv, argc, "peer-group", &idx)) {
7162 clr_sort = clear_group;
7163 idx++;
7164 clr_arg = argv[idx]->arg;
7165 } else if (argv_find(argv, argc, "WORD", &idx)) {
7166 clr_sort = clear_peer;
7167 clr_arg = argv[idx]->arg;
7168 } else if (argv_find(argv, argc, "(1-4294967295)", &idx)) {
7169 clr_sort = clear_as;
7170 clr_arg = argv[idx]->arg;
7171 } else if (argv_find(argv, argc, "external", &idx)) {
7172 clr_sort = clear_external;
7173 }
7174
7175 /* [<soft [<in|out>]|in [prefix-filter]|out>] */
7176 if (argv_find(argv, argc, "soft", &idx)) {
7177 if (argv_find(argv, argc, "in", &idx)
7178 || argv_find(argv, argc, "out", &idx))
7179 clr_type = strmatch(argv[idx]->text, "in")
7180 ? BGP_CLEAR_SOFT_IN
7181 : BGP_CLEAR_SOFT_OUT;
7182 else
7183 clr_type = BGP_CLEAR_SOFT_BOTH;
7184 } else if (argv_find(argv, argc, "in", &idx)) {
7185 clr_type = argv_find(argv, argc, "prefix-filter", &idx)
7186 ? BGP_CLEAR_SOFT_IN_ORF_PREFIX
7187 : BGP_CLEAR_SOFT_IN;
7188 } else if (argv_find(argv, argc, "out", &idx)) {
7189 clr_type = BGP_CLEAR_SOFT_OUT;
7190 } else
7191 clr_type = BGP_CLEAR_SOFT_NONE;
7192
7193 return bgp_clear_vty(vty, vrf, afi, safi, clr_sort, clr_type, clr_arg);
7194 }
7195
7196 DEFUN (clear_ip_bgp_prefix,
7197 clear_ip_bgp_prefix_cmd,
7198 "clear [ip] bgp [<view|vrf> VIEWVRFNAME] prefix A.B.C.D/M",
7199 CLEAR_STR
7200 IP_STR
7201 BGP_STR
7202 BGP_INSTANCE_HELP_STR
7203 "Clear bestpath and re-advertise\n"
7204 "IPv4 prefix\n")
7205 {
7206 char *vrf = NULL;
7207 char *prefix = NULL;
7208
7209 int idx = 0;
7210
7211 /* [<view|vrf> VIEWVRFNAME] */
7212 if (argv_find(argv, argc, "VIEWVRFNAME", &idx))
7213 vrf = argv[idx]->arg;
7214
7215 prefix = argv[argc - 1]->arg;
7216
7217 return bgp_clear_prefix(vty, vrf, prefix, AFI_IP, SAFI_UNICAST, NULL);
7218 }
7219
7220 DEFUN (clear_bgp_ipv6_safi_prefix,
7221 clear_bgp_ipv6_safi_prefix_cmd,
7222 "clear [ip] bgp ipv6 "BGP_SAFI_CMD_STR" prefix X:X::X:X/M",
7223 CLEAR_STR
7224 IP_STR
7225 BGP_STR
7226 "Address Family\n"
7227 BGP_SAFI_HELP_STR
7228 "Clear bestpath and re-advertise\n"
7229 "IPv6 prefix\n")
7230 {
7231 int idx_safi = 0;
7232 int idx_ipv6_prefix = 0;
7233 safi_t safi = SAFI_UNICAST;
7234 char *prefix = argv_find(argv, argc, "X:X::X:X/M", &idx_ipv6_prefix) ?
7235 argv[idx_ipv6_prefix]->arg : NULL;
7236
7237 argv_find_and_parse_safi(argv, argc, &idx_safi, &safi);
7238 return bgp_clear_prefix(
7239 vty, NULL, prefix, AFI_IP6,
7240 safi, NULL);
7241 }
7242
7243 DEFUN (clear_bgp_instance_ipv6_safi_prefix,
7244 clear_bgp_instance_ipv6_safi_prefix_cmd,
7245 "clear [ip] bgp <view|vrf> VIEWVRFNAME ipv6 "BGP_SAFI_CMD_STR" prefix X:X::X:X/M",
7246 CLEAR_STR
7247 IP_STR
7248 BGP_STR
7249 BGP_INSTANCE_HELP_STR
7250 "Address Family\n"
7251 BGP_SAFI_HELP_STR
7252 "Clear bestpath and re-advertise\n"
7253 "IPv6 prefix\n")
7254 {
7255 int idx_word = 3;
7256 int idx_safi = 0;
7257 int idx_ipv6_prefix = 0;
7258 safi_t safi = SAFI_UNICAST;
7259 char *prefix = argv_find(argv, argc, "X:X::X:X/M", &idx_ipv6_prefix) ?
7260 argv[idx_ipv6_prefix]->arg : NULL;
7261 /* [<view|vrf> VIEWVRFNAME] */
7262 char *vrfview = argv_find(argv, argc, "VIEWVRFNAME", &idx_word) ?
7263 argv[idx_word]->arg : NULL;
7264
7265 argv_find_and_parse_safi(argv, argc, &idx_safi, &safi);
7266
7267 return bgp_clear_prefix(
7268 vty, vrfview, prefix,
7269 AFI_IP6, safi, NULL);
7270 }
7271
7272 DEFUN (show_bgp_views,
7273 show_bgp_views_cmd,
7274 "show [ip] bgp views",
7275 SHOW_STR
7276 IP_STR
7277 BGP_STR
7278 "Show the defined BGP views\n")
7279 {
7280 struct list *inst = bm->bgp;
7281 struct listnode *node;
7282 struct bgp *bgp;
7283
7284 if (!bgp_option_check(BGP_OPT_MULTIPLE_INSTANCE)) {
7285 vty_out(vty, "BGP Multiple Instance is not enabled\n");
7286 return CMD_WARNING;
7287 }
7288
7289 vty_out(vty, "Defined BGP views:\n");
7290 for (ALL_LIST_ELEMENTS_RO(inst, node, bgp)) {
7291 /* Skip VRFs. */
7292 if (bgp->inst_type == BGP_INSTANCE_TYPE_VRF)
7293 continue;
7294 vty_out(vty, "\t%s (AS%u)\n", bgp->name ? bgp->name : "(null)",
7295 bgp->as);
7296 }
7297
7298 return CMD_SUCCESS;
7299 }
7300
7301 DEFUN (show_bgp_vrfs,
7302 show_bgp_vrfs_cmd,
7303 "show [ip] bgp vrfs [json]",
7304 SHOW_STR
7305 IP_STR
7306 BGP_STR
7307 "Show BGP VRFs\n"
7308 JSON_STR)
7309 {
7310 char buf[ETHER_ADDR_STRLEN];
7311 struct list *inst = bm->bgp;
7312 struct listnode *node;
7313 struct bgp *bgp;
7314 uint8_t uj = use_json(argc, argv);
7315 json_object *json = NULL;
7316 json_object *json_vrfs = NULL;
7317 int count = 0;
7318
7319 if (!bgp_option_check(BGP_OPT_MULTIPLE_INSTANCE)) {
7320 vty_out(vty, "BGP Multiple Instance is not enabled\n");
7321 return CMD_WARNING;
7322 }
7323
7324 if (uj) {
7325 json = json_object_new_object();
7326 json_vrfs = json_object_new_object();
7327 }
7328
7329 for (ALL_LIST_ELEMENTS_RO(inst, node, bgp)) {
7330 const char *name, *type;
7331 struct peer *peer;
7332 struct listnode *node, *nnode;
7333 int peers_cfg, peers_estb;
7334 json_object *json_vrf = NULL;
7335
7336 /* Skip Views. */
7337 if (bgp->inst_type == BGP_INSTANCE_TYPE_VIEW)
7338 continue;
7339
7340 count++;
7341 if (!uj && count == 1)
7342 vty_out(vty,
7343 "%4s %-5s %-16s %9s %10s %-37s %-10s %-15s\n",
7344 "Type", "Id", "routerId", "#PeersVfg",
7345 "#PeersEstb", "Name", "L3-VNI", "Rmac");
7346
7347 peers_cfg = peers_estb = 0;
7348 if (uj)
7349 json_vrf = json_object_new_object();
7350
7351
7352 for (ALL_LIST_ELEMENTS(bgp->peer, node, nnode, peer)) {
7353 if (!CHECK_FLAG(peer->flags, PEER_FLAG_CONFIG_NODE))
7354 continue;
7355 peers_cfg++;
7356 if (peer->status == Established)
7357 peers_estb++;
7358 }
7359
7360 if (bgp->inst_type == BGP_INSTANCE_TYPE_DEFAULT) {
7361 name = "Default";
7362 type = "DFLT";
7363 } else {
7364 name = bgp->name;
7365 type = "VRF";
7366 }
7367
7368
7369 if (uj) {
7370 int64_t vrf_id_ui = (bgp->vrf_id == VRF_UNKNOWN)
7371 ? -1
7372 : (int64_t)bgp->vrf_id;
7373 json_object_string_add(json_vrf, "type", type);
7374 json_object_int_add(json_vrf, "vrfId", vrf_id_ui);
7375 json_object_string_add(json_vrf, "routerId",
7376 inet_ntoa(bgp->router_id));
7377 json_object_int_add(json_vrf, "numConfiguredPeers",
7378 peers_cfg);
7379 json_object_int_add(json_vrf, "numEstablishedPeers",
7380 peers_estb);
7381
7382 json_object_int_add(json_vrf, "l3vni", bgp->l3vni);
7383 json_object_string_add(
7384 json_vrf, "rmac",
7385 prefix_mac2str(&bgp->rmac, buf, sizeof(buf)));
7386 json_object_object_add(json_vrfs, name, json_vrf);
7387 } else
7388 vty_out(vty,
7389 "%4s %-5d %-16s %9u %10u %-37s %-10u %-15s\n",
7390 type,
7391 bgp->vrf_id == VRF_UNKNOWN ? -1
7392 : (int)bgp->vrf_id,
7393 inet_ntoa(bgp->router_id), peers_cfg,
7394 peers_estb, name, bgp->l3vni,
7395 prefix_mac2str(&bgp->rmac, buf, sizeof(buf)));
7396 }
7397
7398 if (uj) {
7399 json_object_object_add(json, "vrfs", json_vrfs);
7400
7401 json_object_int_add(json, "totalVrfs", count);
7402
7403 vty_out(vty, "%s\n", json_object_to_json_string_ext(
7404 json, JSON_C_TO_STRING_PRETTY));
7405 json_object_free(json);
7406 } else {
7407 if (count)
7408 vty_out(vty,
7409 "\nTotal number of VRFs (including default): %d\n",
7410 count);
7411 }
7412
7413 return CMD_SUCCESS;
7414 }
7415
7416 static void show_address_entry(struct hash_backet *backet, void *args)
7417 {
7418 struct vty *vty = (struct vty *)args;
7419 struct bgp_addr *addr = (struct bgp_addr *)backet->data;
7420
7421 vty_out(vty, "addr: %s, count: %d\n", inet_ntoa(addr->addr),
7422 addr->refcnt);
7423 }
7424
7425 static void show_tip_entry(struct hash_backet *backet, void *args)
7426 {
7427 struct vty *vty = (struct vty *)args;
7428 struct tip_addr *tip = (struct tip_addr *)backet->data;
7429
7430 vty_out(vty, "addr: %s, count: %d\n", inet_ntoa(tip->addr),
7431 tip->refcnt);
7432 }
7433
7434 static void bgp_show_martian_nexthops(struct vty *vty, struct bgp *bgp)
7435 {
7436 vty_out(vty, "self nexthop database:\n");
7437 hash_iterate(bgp->address_hash,
7438 (void (*)(struct hash_backet *, void *))show_address_entry,
7439 vty);
7440
7441 vty_out(vty, "Tunnel-ip database:\n");
7442 hash_iterate(bgp->tip_hash,
7443 (void (*)(struct hash_backet *, void *))show_tip_entry,
7444 vty);
7445 }
7446
7447 DEFUN(show_bgp_martian_nexthop_db, show_bgp_martian_nexthop_db_cmd,
7448 "show bgp [<view|vrf> VIEWVRFNAME] martian next-hop",
7449 SHOW_STR BGP_STR BGP_INSTANCE_HELP_STR
7450 "martian next-hops\n"
7451 "martian next-hop database\n")
7452 {
7453 struct bgp *bgp = NULL;
7454 int idx = 0;
7455
7456 if (argv_find(argv, argc, "view", &idx)
7457 || argv_find(argv, argc, "vrf", &idx))
7458 bgp = bgp_lookup_by_name(argv[idx + 1]->arg);
7459 else
7460 bgp = bgp_get_default();
7461
7462 if (!bgp) {
7463 vty_out(vty, "%% No BGP process is configured\n");
7464 return CMD_WARNING;
7465 }
7466 bgp_show_martian_nexthops(vty, bgp);
7467
7468 return CMD_SUCCESS;
7469 }
7470
7471 DEFUN (show_bgp_memory,
7472 show_bgp_memory_cmd,
7473 "show [ip] bgp memory",
7474 SHOW_STR
7475 IP_STR
7476 BGP_STR
7477 "Global BGP memory statistics\n")
7478 {
7479 char memstrbuf[MTYPE_MEMSTR_LEN];
7480 unsigned long count;
7481
7482 /* RIB related usage stats */
7483 count = mtype_stats_alloc(MTYPE_BGP_NODE);
7484 vty_out(vty, "%ld RIB nodes, using %s of memory\n", count,
7485 mtype_memstr(memstrbuf, sizeof(memstrbuf),
7486 count * sizeof(struct bgp_node)));
7487
7488 count = mtype_stats_alloc(MTYPE_BGP_ROUTE);
7489 vty_out(vty, "%ld BGP routes, using %s of memory\n", count,
7490 mtype_memstr(memstrbuf, sizeof(memstrbuf),
7491 count * sizeof(struct bgp_info)));
7492 if ((count = mtype_stats_alloc(MTYPE_BGP_ROUTE_EXTRA)))
7493 vty_out(vty, "%ld BGP route ancillaries, using %s of memory\n",
7494 count,
7495 mtype_memstr(memstrbuf, sizeof(memstrbuf),
7496 count * sizeof(struct bgp_info_extra)));
7497
7498 if ((count = mtype_stats_alloc(MTYPE_BGP_STATIC)))
7499 vty_out(vty, "%ld Static routes, using %s of memory\n", count,
7500 mtype_memstr(memstrbuf, sizeof(memstrbuf),
7501 count * sizeof(struct bgp_static)));
7502
7503 if ((count = mtype_stats_alloc(MTYPE_BGP_PACKET)))
7504 vty_out(vty, "%ld Packets, using %s of memory\n", count,
7505 mtype_memstr(memstrbuf, sizeof(memstrbuf),
7506 count * sizeof(struct bpacket)));
7507
7508 /* Adj-In/Out */
7509 if ((count = mtype_stats_alloc(MTYPE_BGP_ADJ_IN)))
7510 vty_out(vty, "%ld Adj-In entries, using %s of memory\n", count,
7511 mtype_memstr(memstrbuf, sizeof(memstrbuf),
7512 count * sizeof(struct bgp_adj_in)));
7513 if ((count = mtype_stats_alloc(MTYPE_BGP_ADJ_OUT)))
7514 vty_out(vty, "%ld Adj-Out entries, using %s of memory\n", count,
7515 mtype_memstr(memstrbuf, sizeof(memstrbuf),
7516 count * sizeof(struct bgp_adj_out)));
7517
7518 if ((count = mtype_stats_alloc(MTYPE_BGP_NEXTHOP_CACHE)))
7519 vty_out(vty, "%ld Nexthop cache entries, using %s of memory\n",
7520 count,
7521 mtype_memstr(memstrbuf, sizeof(memstrbuf),
7522 count * sizeof(struct bgp_nexthop_cache)));
7523
7524 if ((count = mtype_stats_alloc(MTYPE_BGP_DAMP_INFO)))
7525 vty_out(vty, "%ld Dampening entries, using %s of memory\n",
7526 count,
7527 mtype_memstr(memstrbuf, sizeof(memstrbuf),
7528 count * sizeof(struct bgp_damp_info)));
7529
7530 /* Attributes */
7531 count = attr_count();
7532 vty_out(vty, "%ld BGP attributes, using %s of memory\n", count,
7533 mtype_memstr(memstrbuf, sizeof(memstrbuf),
7534 count * sizeof(struct attr)));
7535
7536 if ((count = attr_unknown_count()))
7537 vty_out(vty, "%ld unknown attributes\n", count);
7538
7539 /* AS_PATH attributes */
7540 count = aspath_count();
7541 vty_out(vty, "%ld BGP AS-PATH entries, using %s of memory\n", count,
7542 mtype_memstr(memstrbuf, sizeof(memstrbuf),
7543 count * sizeof(struct aspath)));
7544
7545 count = mtype_stats_alloc(MTYPE_AS_SEG);
7546 vty_out(vty, "%ld BGP AS-PATH segments, using %s of memory\n", count,
7547 mtype_memstr(memstrbuf, sizeof(memstrbuf),
7548 count * sizeof(struct assegment)));
7549
7550 /* Other attributes */
7551 if ((count = community_count()))
7552 vty_out(vty, "%ld BGP community entries, using %s of memory\n",
7553 count, mtype_memstr(memstrbuf, sizeof(memstrbuf),
7554 count * sizeof(struct community)));
7555 if ((count = mtype_stats_alloc(MTYPE_ECOMMUNITY)))
7556 vty_out(vty, "%ld BGP community entries, using %s of memory\n",
7557 count, mtype_memstr(memstrbuf, sizeof(memstrbuf),
7558 count * sizeof(struct ecommunity)));
7559 if ((count = mtype_stats_alloc(MTYPE_LCOMMUNITY)))
7560 vty_out(vty,
7561 "%ld BGP large-community entries, using %s of memory\n",
7562 count, mtype_memstr(memstrbuf, sizeof(memstrbuf),
7563 count * sizeof(struct lcommunity)));
7564
7565 if ((count = mtype_stats_alloc(MTYPE_CLUSTER)))
7566 vty_out(vty, "%ld Cluster lists, using %s of memory\n", count,
7567 mtype_memstr(memstrbuf, sizeof(memstrbuf),
7568 count * sizeof(struct cluster_list)));
7569
7570 /* Peer related usage */
7571 count = mtype_stats_alloc(MTYPE_BGP_PEER);
7572 vty_out(vty, "%ld peers, using %s of memory\n", count,
7573 mtype_memstr(memstrbuf, sizeof(memstrbuf),
7574 count * sizeof(struct peer)));
7575
7576 if ((count = mtype_stats_alloc(MTYPE_PEER_GROUP)))
7577 vty_out(vty, "%ld peer groups, using %s of memory\n", count,
7578 mtype_memstr(memstrbuf, sizeof(memstrbuf),
7579 count * sizeof(struct peer_group)));
7580
7581 /* Other */
7582 if ((count = mtype_stats_alloc(MTYPE_HASH)))
7583 vty_out(vty, "%ld hash tables, using %s of memory\n", count,
7584 mtype_memstr(memstrbuf, sizeof(memstrbuf),
7585 count * sizeof(struct hash)));
7586 if ((count = mtype_stats_alloc(MTYPE_HASH_BACKET)))
7587 vty_out(vty, "%ld hash buckets, using %s of memory\n", count,
7588 mtype_memstr(memstrbuf, sizeof(memstrbuf),
7589 count * sizeof(struct hash_backet)));
7590 if ((count = mtype_stats_alloc(MTYPE_BGP_REGEXP)))
7591 vty_out(vty, "%ld compiled regexes, using %s of memory\n",
7592 count, mtype_memstr(memstrbuf, sizeof(memstrbuf),
7593 count * sizeof(regex_t)));
7594 return CMD_SUCCESS;
7595 }
7596
7597 static void bgp_show_bestpath_json(struct bgp *bgp, json_object *json)
7598 {
7599 json_object *bestpath = json_object_new_object();
7600
7601 if (bgp_flag_check(bgp, BGP_FLAG_ASPATH_IGNORE))
7602 json_object_string_add(bestpath, "asPath", "ignore");
7603
7604 if (bgp_flag_check(bgp, BGP_FLAG_ASPATH_CONFED))
7605 json_object_string_add(bestpath, "asPath", "confed");
7606
7607 if (bgp_flag_check(bgp, BGP_FLAG_ASPATH_MULTIPATH_RELAX)) {
7608 if (bgp_flag_check(bgp, BGP_FLAG_MULTIPATH_RELAX_AS_SET))
7609 json_object_string_add(bestpath, "multiPathRelax",
7610 "as-set");
7611 else
7612 json_object_string_add(bestpath, "multiPathRelax",
7613 "true");
7614 } else
7615 json_object_string_add(bestpath, "multiPathRelax", "false");
7616
7617 if (bgp_flag_check(bgp, BGP_FLAG_COMPARE_ROUTER_ID))
7618 json_object_string_add(bestpath, "compareRouterId", "true");
7619 if (bgp_flag_check(bgp, BGP_FLAG_MED_CONFED)
7620 || bgp_flag_check(bgp, BGP_FLAG_MED_MISSING_AS_WORST)) {
7621 if (bgp_flag_check(bgp, BGP_FLAG_MED_CONFED))
7622 json_object_string_add(bestpath, "med", "confed");
7623 if (bgp_flag_check(bgp, BGP_FLAG_MED_MISSING_AS_WORST))
7624 json_object_string_add(bestpath, "med",
7625 "missing-as-worst");
7626 else
7627 json_object_string_add(bestpath, "med", "true");
7628 }
7629
7630 json_object_object_add(json, "bestPath", bestpath);
7631 }
7632
7633 /* Show BGP peer's summary information. */
7634 static int bgp_show_summary(struct vty *vty, struct bgp *bgp, int afi, int safi,
7635 uint8_t use_json, json_object *json)
7636 {
7637 struct peer *peer;
7638 struct listnode *node, *nnode;
7639 unsigned int count = 0, dn_count = 0;
7640 char timebuf[BGP_UPTIME_LEN], dn_flag[2];
7641 char neighbor_buf[VTY_BUFSIZ];
7642 int neighbor_col_default_width = 16;
7643 int len;
7644 int max_neighbor_width = 0;
7645 int pfx_rcd_safi;
7646 json_object *json_peer = NULL;
7647 json_object *json_peers = NULL;
7648
7649 /* labeled-unicast routes are installed in the unicast table so in order
7650 * to
7651 * display the correct PfxRcd value we must look at SAFI_UNICAST
7652 */
7653 if (safi == SAFI_LABELED_UNICAST)
7654 pfx_rcd_safi = SAFI_UNICAST;
7655 else
7656 pfx_rcd_safi = safi;
7657
7658 if (use_json) {
7659 if (json == NULL)
7660 json = json_object_new_object();
7661
7662 json_peers = json_object_new_object();
7663 } else {
7664 /* Loop over all neighbors that will be displayed to determine
7665 * how many
7666 * characters are needed for the Neighbor column
7667 */
7668 for (ALL_LIST_ELEMENTS(bgp->peer, node, nnode, peer)) {
7669 if (!CHECK_FLAG(peer->flags, PEER_FLAG_CONFIG_NODE))
7670 continue;
7671
7672 if (peer->afc[afi][safi]) {
7673 memset(dn_flag, '\0', sizeof(dn_flag));
7674 if (peer_dynamic_neighbor(peer))
7675 dn_flag[0] = '*';
7676
7677 if (peer->hostname
7678 && bgp_flag_check(bgp,
7679 BGP_FLAG_SHOW_HOSTNAME))
7680 sprintf(neighbor_buf, "%s%s(%s) ",
7681 dn_flag, peer->hostname,
7682 peer->host);
7683 else
7684 sprintf(neighbor_buf, "%s%s ", dn_flag,
7685 peer->host);
7686
7687 len = strlen(neighbor_buf);
7688
7689 if (len > max_neighbor_width)
7690 max_neighbor_width = len;
7691 }
7692 }
7693
7694 /* Originally we displayed the Neighbor column as 16
7695 * characters wide so make that the default
7696 */
7697 if (max_neighbor_width < neighbor_col_default_width)
7698 max_neighbor_width = neighbor_col_default_width;
7699 }
7700
7701 for (ALL_LIST_ELEMENTS(bgp->peer, node, nnode, peer)) {
7702 if (!CHECK_FLAG(peer->flags, PEER_FLAG_CONFIG_NODE))
7703 continue;
7704
7705 if (!peer->afc[afi][safi])
7706 continue;
7707
7708 if (!count) {
7709 unsigned long ents;
7710 char memstrbuf[MTYPE_MEMSTR_LEN];
7711 int64_t vrf_id_ui;
7712
7713 vrf_id_ui = (bgp->vrf_id == VRF_UNKNOWN)
7714 ? -1
7715 : (int64_t)bgp->vrf_id;
7716
7717 /* Usage summary and header */
7718 if (use_json) {
7719 json_object_string_add(
7720 json, "routerId",
7721 inet_ntoa(bgp->router_id));
7722 json_object_int_add(json, "as", bgp->as);
7723 json_object_int_add(json, "vrfId", vrf_id_ui);
7724 json_object_string_add(
7725 json, "vrfName",
7726 (bgp->inst_type
7727 == BGP_INSTANCE_TYPE_DEFAULT)
7728 ? "Default"
7729 : bgp->name);
7730 } else {
7731 vty_out(vty,
7732 "BGP router identifier %s, local AS number %u vrf-id %d",
7733 inet_ntoa(bgp->router_id), bgp->as,
7734 bgp->vrf_id == VRF_UNKNOWN
7735 ? -1
7736 : (int)bgp->vrf_id);
7737 vty_out(vty, "\n");
7738 }
7739
7740 if (bgp_update_delay_configured(bgp)) {
7741 if (use_json) {
7742 json_object_int_add(
7743 json, "updateDelayLimit",
7744 bgp->v_update_delay);
7745
7746 if (bgp->v_update_delay
7747 != bgp->v_establish_wait)
7748 json_object_int_add(
7749 json,
7750 "updateDelayEstablishWait",
7751 bgp->v_establish_wait);
7752
7753 if (bgp_update_delay_active(bgp)) {
7754 json_object_string_add(
7755 json,
7756 "updateDelayFirstNeighbor",
7757 bgp->update_delay_begin_time);
7758 json_object_boolean_true_add(
7759 json,
7760 "updateDelayInProgress");
7761 } else {
7762 if (bgp->update_delay_over) {
7763 json_object_string_add(
7764 json,
7765 "updateDelayFirstNeighbor",
7766 bgp->update_delay_begin_time);
7767 json_object_string_add(
7768 json,
7769 "updateDelayBestpathResumed",
7770 bgp->update_delay_end_time);
7771 json_object_string_add(
7772 json,
7773 "updateDelayZebraUpdateResume",
7774 bgp->update_delay_zebra_resume_time);
7775 json_object_string_add(
7776 json,
7777 "updateDelayPeerUpdateResume",
7778 bgp->update_delay_peers_resume_time);
7779 }
7780 }
7781 } else {
7782 vty_out(vty,
7783 "Read-only mode update-delay limit: %d seconds\n",
7784 bgp->v_update_delay);
7785 if (bgp->v_update_delay
7786 != bgp->v_establish_wait)
7787 vty_out(vty,
7788 " Establish wait: %d seconds\n",
7789 bgp->v_establish_wait);
7790
7791 if (bgp_update_delay_active(bgp)) {
7792 vty_out(vty,
7793 " First neighbor established: %s\n",
7794 bgp->update_delay_begin_time);
7795 vty_out(vty,
7796 " Delay in progress\n");
7797 } else {
7798 if (bgp->update_delay_over) {
7799 vty_out(vty,
7800 " First neighbor established: %s\n",
7801 bgp->update_delay_begin_time);
7802 vty_out(vty,
7803 " Best-paths resumed: %s\n",
7804 bgp->update_delay_end_time);
7805 vty_out(vty,
7806 " zebra update resumed: %s\n",
7807 bgp->update_delay_zebra_resume_time);
7808 vty_out(vty,
7809 " peers update resumed: %s\n",
7810 bgp->update_delay_peers_resume_time);
7811 }
7812 }
7813 }
7814 }
7815
7816 if (use_json) {
7817 if (bgp_maxmed_onstartup_configured(bgp)
7818 && bgp->maxmed_active)
7819 json_object_boolean_true_add(
7820 json, "maxMedOnStartup");
7821 if (bgp->v_maxmed_admin)
7822 json_object_boolean_true_add(
7823 json, "maxMedAdministrative");
7824
7825 json_object_int_add(
7826 json, "tableVersion",
7827 bgp_table_version(bgp->rib[afi][safi]));
7828
7829 ents = bgp_table_count(bgp->rib[afi][safi]);
7830 json_object_int_add(json, "ribCount", ents);
7831 json_object_int_add(
7832 json, "ribMemory",
7833 ents * sizeof(struct bgp_node));
7834
7835 ents = listcount(bgp->peer);
7836 json_object_int_add(json, "peerCount", ents);
7837 json_object_int_add(json, "peerMemory",
7838 ents * sizeof(struct peer));
7839
7840 if ((ents = listcount(bgp->group))) {
7841 json_object_int_add(
7842 json, "peerGroupCount", ents);
7843 json_object_int_add(
7844 json, "peerGroupMemory",
7845 ents * sizeof(struct
7846 peer_group));
7847 }
7848
7849 if (CHECK_FLAG(bgp->af_flags[afi][safi],
7850 BGP_CONFIG_DAMPENING))
7851 json_object_boolean_true_add(
7852 json, "dampeningEnabled");
7853 } else {
7854 if (bgp_maxmed_onstartup_configured(bgp)
7855 && bgp->maxmed_active)
7856 vty_out(vty,
7857 "Max-med on-startup active\n");
7858 if (bgp->v_maxmed_admin)
7859 vty_out(vty,
7860 "Max-med administrative active\n");
7861
7862 vty_out(vty, "BGP table version %" PRIu64 "\n",
7863 bgp_table_version(bgp->rib[afi][safi]));
7864
7865 ents = bgp_table_count(bgp->rib[afi][safi]);
7866 vty_out(vty,
7867 "RIB entries %ld, using %s of memory\n",
7868 ents,
7869 mtype_memstr(memstrbuf,
7870 sizeof(memstrbuf),
7871 ents * sizeof(struct
7872 bgp_node)));
7873
7874 /* Peer related usage */
7875 ents = listcount(bgp->peer);
7876 vty_out(vty, "Peers %ld, using %s of memory\n",
7877 ents,
7878 mtype_memstr(
7879 memstrbuf, sizeof(memstrbuf),
7880 ents * sizeof(struct peer)));
7881
7882 if ((ents = listcount(bgp->group)))
7883 vty_out(vty,
7884 "Peer groups %ld, using %s of memory\n",
7885 ents,
7886 mtype_memstr(
7887 memstrbuf,
7888 sizeof(memstrbuf),
7889 ents * sizeof(struct
7890 peer_group)));
7891
7892 if (CHECK_FLAG(bgp->af_flags[afi][safi],
7893 BGP_CONFIG_DAMPENING))
7894 vty_out(vty, "Dampening enabled.\n");
7895 vty_out(vty, "\n");
7896
7897 /* Subtract 8 here because 'Neighbor' is
7898 * 8 characters */
7899 vty_out(vty, "Neighbor");
7900 vty_out(vty, "%*s", max_neighbor_width - 8,
7901 " ");
7902 vty_out(vty,
7903 "V AS MsgRcvd MsgSent TblVer InQ OutQ Up/Down State/PfxRcd\n");
7904 }
7905 }
7906
7907 count++;
7908
7909 if (use_json) {
7910 json_peer = json_object_new_object();
7911
7912 if (peer_dynamic_neighbor(peer))
7913 json_object_boolean_true_add(json_peer,
7914 "dynamicPeer");
7915
7916 if (peer->hostname)
7917 json_object_string_add(json_peer, "hostname",
7918 peer->hostname);
7919
7920 if (peer->domainname)
7921 json_object_string_add(json_peer, "domainname",
7922 peer->domainname);
7923
7924 json_object_int_add(json_peer, "remoteAs", peer->as);
7925 json_object_int_add(json_peer, "version", 4);
7926 json_object_int_add(json_peer, "msgRcvd",
7927 PEER_TOTAL_RX(peer));
7928 json_object_int_add(json_peer, "msgSent",
7929 PEER_TOTAL_TX(peer));
7930
7931 json_object_int_add(json_peer, "tableVersion",
7932 peer->version[afi][safi]);
7933 json_object_int_add(json_peer, "outq",
7934 peer->obuf->count);
7935 json_object_int_add(json_peer, "inq", 0);
7936 peer_uptime(peer->uptime, timebuf, BGP_UPTIME_LEN,
7937 use_json, json_peer);
7938 json_object_int_add(json_peer, "prefixReceivedCount",
7939 peer->pcount[afi][pfx_rcd_safi]);
7940
7941 if (CHECK_FLAG(peer->flags, PEER_FLAG_SHUTDOWN))
7942 json_object_string_add(json_peer, "state",
7943 "Idle (Admin)");
7944 else if (peer->afc_recv[afi][safi])
7945 json_object_string_add(
7946 json_peer, "state",
7947 lookup_msg(bgp_status_msg, peer->status,
7948 NULL));
7949 else if (CHECK_FLAG(peer->sflags,
7950 PEER_STATUS_PREFIX_OVERFLOW))
7951 json_object_string_add(json_peer, "state",
7952 "Idle (PfxCt)");
7953 else
7954 json_object_string_add(
7955 json_peer, "state",
7956 lookup_msg(bgp_status_msg, peer->status,
7957 NULL));
7958
7959 if (peer->conf_if)
7960 json_object_string_add(json_peer, "idType",
7961 "interface");
7962 else if (peer->su.sa.sa_family == AF_INET)
7963 json_object_string_add(json_peer, "idType",
7964 "ipv4");
7965 else if (peer->su.sa.sa_family == AF_INET6)
7966 json_object_string_add(json_peer, "idType",
7967 "ipv6");
7968
7969 json_object_object_add(json_peers, peer->host,
7970 json_peer);
7971 } else {
7972 memset(dn_flag, '\0', sizeof(dn_flag));
7973 if (peer_dynamic_neighbor(peer)) {
7974 dn_count++;
7975 dn_flag[0] = '*';
7976 }
7977
7978 if (peer->hostname
7979 && bgp_flag_check(bgp, BGP_FLAG_SHOW_HOSTNAME))
7980 len = vty_out(vty, "%s%s(%s)", dn_flag,
7981 peer->hostname, peer->host);
7982 else
7983 len = vty_out(vty, "%s%s", dn_flag, peer->host);
7984
7985 /* pad the neighbor column with spaces */
7986 if (len < max_neighbor_width)
7987 vty_out(vty, "%*s", max_neighbor_width - len,
7988 " ");
7989
7990 vty_out(vty, "4 %10u %7u %7u %8" PRIu64 " %4d %4zd %8s",
7991 peer->as, PEER_TOTAL_RX(peer),
7992 PEER_TOTAL_TX(peer), peer->version[afi][safi],
7993 0, peer->obuf->count,
7994 peer_uptime(peer->uptime, timebuf,
7995 BGP_UPTIME_LEN, 0, NULL));
7996
7997 if (peer->status == Established)
7998 if (peer->afc_recv[afi][safi])
7999 vty_out(vty, " %12ld",
8000 peer->pcount[afi]
8001 [pfx_rcd_safi]);
8002 else
8003 vty_out(vty, " NoNeg");
8004 else {
8005 if (CHECK_FLAG(peer->flags, PEER_FLAG_SHUTDOWN))
8006 vty_out(vty, " Idle (Admin)");
8007 else if (CHECK_FLAG(
8008 peer->sflags,
8009 PEER_STATUS_PREFIX_OVERFLOW))
8010 vty_out(vty, " Idle (PfxCt)");
8011 else
8012 vty_out(vty, " %12s",
8013 lookup_msg(bgp_status_msg,
8014 peer->status, NULL));
8015 }
8016 vty_out(vty, "\n");
8017 }
8018 }
8019
8020 if (use_json) {
8021 json_object_object_add(json, "peers", json_peers);
8022
8023 json_object_int_add(json, "totalPeers", count);
8024 json_object_int_add(json, "dynamicPeers", dn_count);
8025
8026 bgp_show_bestpath_json(bgp, json);
8027
8028 vty_out(vty, "%s\n", json_object_to_json_string_ext(
8029 json, JSON_C_TO_STRING_PRETTY));
8030 json_object_free(json);
8031 } else {
8032 if (count)
8033 vty_out(vty, "\nTotal number of neighbors %d\n", count);
8034 else {
8035 vty_out(vty, "No %s neighbor is configured\n",
8036 afi_safi_print(afi, safi));
8037 }
8038
8039 if (dn_count) {
8040 vty_out(vty, "* - dynamic neighbor\n");
8041 vty_out(vty, "%d dynamic neighbor(s), limit %d\n",
8042 dn_count, bgp->dynamic_neighbors_limit);
8043 }
8044 }
8045
8046 return CMD_SUCCESS;
8047 }
8048
8049 static void bgp_show_summary_afi_safi(struct vty *vty, struct bgp *bgp, int afi,
8050 int safi, uint8_t use_json,
8051 json_object *json)
8052 {
8053 int is_first = 1;
8054 int afi_wildcard = (afi == AFI_MAX);
8055 int safi_wildcard = (safi == SAFI_MAX);
8056 int is_wildcard = (afi_wildcard || safi_wildcard);
8057 bool json_output = false;
8058
8059 if (use_json && is_wildcard)
8060 vty_out(vty, "{\n");
8061 if (afi_wildcard)
8062 afi = 1; /* AFI_IP */
8063 while (afi < AFI_MAX) {
8064 if (safi_wildcard)
8065 safi = 1; /* SAFI_UNICAST */
8066 while (safi < SAFI_MAX) {
8067 if (bgp_afi_safi_peer_exists(bgp, afi, safi)) {
8068 json_output = true;
8069 if (is_wildcard) {
8070 /*
8071 * So limit output to those afi/safi
8072 * pairs that
8073 * actualy have something interesting in
8074 * them
8075 */
8076 if (use_json) {
8077 json = json_object_new_object();
8078
8079 if (!is_first)
8080 vty_out(vty, ",\n");
8081 else
8082 is_first = 0;
8083
8084 vty_out(vty, "\"%s\":",
8085 afi_safi_json(afi,
8086 safi));
8087 } else {
8088 vty_out(vty, "\n%s Summary:\n",
8089 afi_safi_print(afi,
8090 safi));
8091 }
8092 }
8093 bgp_show_summary(vty, bgp, afi, safi, use_json,
8094 json);
8095 }
8096 safi++;
8097 if (!safi_wildcard)
8098 safi = SAFI_MAX;
8099 }
8100 afi++;
8101 if (!afi_wildcard)
8102 afi = AFI_MAX;
8103 }
8104
8105 if (use_json && is_wildcard)
8106 vty_out(vty, "}\n");
8107 else if (use_json && !json_output)
8108 vty_out(vty, "{}\n");
8109 }
8110
8111 static void bgp_show_all_instances_summary_vty(struct vty *vty, afi_t afi,
8112 safi_t safi, uint8_t use_json)
8113 {
8114 struct listnode *node, *nnode;
8115 struct bgp *bgp;
8116 json_object *json = NULL;
8117 int is_first = 1;
8118
8119 if (use_json)
8120 vty_out(vty, "{\n");
8121
8122 for (ALL_LIST_ELEMENTS(bm->bgp, node, nnode, bgp)) {
8123 if (use_json) {
8124 json = json_object_new_object();
8125
8126 if (!is_first)
8127 vty_out(vty, ",\n");
8128 else
8129 is_first = 0;
8130
8131 vty_out(vty, "\"%s\":",
8132 (bgp->inst_type == BGP_INSTANCE_TYPE_DEFAULT)
8133 ? "Default"
8134 : bgp->name);
8135 } else {
8136 vty_out(vty, "\nInstance %s:\n",
8137 (bgp->inst_type == BGP_INSTANCE_TYPE_DEFAULT)
8138 ? "Default"
8139 : bgp->name);
8140 }
8141 bgp_show_summary_afi_safi(vty, bgp, afi, safi, use_json, json);
8142 }
8143
8144 if (use_json)
8145 vty_out(vty, "}\n");
8146 }
8147
8148 int bgp_show_summary_vty(struct vty *vty, const char *name, afi_t afi,
8149 safi_t safi, uint8_t use_json)
8150 {
8151 struct bgp *bgp;
8152
8153 if (name) {
8154 if (strmatch(name, "all")) {
8155 bgp_show_all_instances_summary_vty(vty, afi, safi,
8156 use_json);
8157 return CMD_SUCCESS;
8158 } else {
8159 bgp = bgp_lookup_by_name(name);
8160
8161 if (!bgp) {
8162 if (use_json)
8163 vty_out(vty, "{}\n");
8164 else
8165 vty_out(vty,
8166 "%% No such BGP instance exist\n");
8167 return CMD_WARNING;
8168 }
8169
8170 bgp_show_summary_afi_safi(vty, bgp, afi, safi, use_json,
8171 NULL);
8172 return CMD_SUCCESS;
8173 }
8174 }
8175
8176 bgp = bgp_get_default();
8177
8178 if (bgp)
8179 bgp_show_summary_afi_safi(vty, bgp, afi, safi, use_json, NULL);
8180
8181 return CMD_SUCCESS;
8182 }
8183
8184 /* `show [ip] bgp summary' commands. */
8185 DEFUN (show_ip_bgp_summary,
8186 show_ip_bgp_summary_cmd,
8187 "show [ip] bgp [<view|vrf> VIEWVRFNAME] ["BGP_AFI_CMD_STR" ["BGP_SAFI_WITH_LABEL_CMD_STR"]] summary [json]",
8188 SHOW_STR
8189 IP_STR
8190 BGP_STR
8191 BGP_INSTANCE_HELP_STR
8192 BGP_AFI_HELP_STR
8193 BGP_SAFI_WITH_LABEL_HELP_STR
8194 "Summary of BGP neighbor status\n"
8195 JSON_STR)
8196 {
8197 char *vrf = NULL;
8198 afi_t afi = AFI_MAX;
8199 safi_t safi = SAFI_MAX;
8200
8201 int idx = 0;
8202
8203 /* show [ip] bgp */
8204 if (argv_find(argv, argc, "ip", &idx))
8205 afi = AFI_IP;
8206 /* [<view|vrf> VIEWVRFNAME] */
8207 if (argv_find(argv, argc, "view", &idx)
8208 || argv_find(argv, argc, "vrf", &idx))
8209 vrf = argv[++idx]->arg;
8210 /* ["BGP_AFI_CMD_STR" ["BGP_SAFI_CMD_STR"]] */
8211 if (argv_find_and_parse_afi(argv, argc, &idx, &afi)) {
8212 argv_find_and_parse_safi(argv, argc, &idx, &safi);
8213 }
8214
8215 int uj = use_json(argc, argv);
8216
8217 return bgp_show_summary_vty(vty, vrf, afi, safi, uj);
8218 }
8219
8220 const char *afi_safi_print(afi_t afi, safi_t safi)
8221 {
8222 if (afi == AFI_IP && safi == SAFI_UNICAST)
8223 return "IPv4 Unicast";
8224 else if (afi == AFI_IP && safi == SAFI_MULTICAST)
8225 return "IPv4 Multicast";
8226 else if (afi == AFI_IP && safi == SAFI_LABELED_UNICAST)
8227 return "IPv4 Labeled Unicast";
8228 else if (afi == AFI_IP && safi == SAFI_MPLS_VPN)
8229 return "IPv4 VPN";
8230 else if (afi == AFI_IP && safi == SAFI_ENCAP)
8231 return "IPv4 Encap";
8232 else if (afi == AFI_IP && safi == SAFI_FLOWSPEC)
8233 return "IPv4 Flowspec";
8234 else if (afi == AFI_IP6 && safi == SAFI_UNICAST)
8235 return "IPv6 Unicast";
8236 else if (afi == AFI_IP6 && safi == SAFI_MULTICAST)
8237 return "IPv6 Multicast";
8238 else if (afi == AFI_IP6 && safi == SAFI_LABELED_UNICAST)
8239 return "IPv6 Labeled Unicast";
8240 else if (afi == AFI_IP6 && safi == SAFI_MPLS_VPN)
8241 return "IPv6 VPN";
8242 else if (afi == AFI_IP6 && safi == SAFI_ENCAP)
8243 return "IPv6 Encap";
8244 else if (afi == AFI_IP6 && safi == SAFI_FLOWSPEC)
8245 return "IPv6 Flowspec";
8246 else if (afi == AFI_L2VPN && safi == SAFI_EVPN)
8247 return "L2VPN EVPN";
8248 else
8249 return "Unknown";
8250 }
8251
8252 /*
8253 * Please note that we have intentionally camelCased
8254 * the return strings here. So if you want
8255 * to use this function, please ensure you
8256 * are doing this within json output
8257 */
8258 const char *afi_safi_json(afi_t afi, safi_t safi)
8259 {
8260 if (afi == AFI_IP && safi == SAFI_UNICAST)
8261 return "ipv4Unicast";
8262 else if (afi == AFI_IP && safi == SAFI_MULTICAST)
8263 return "ipv4Multicast";
8264 else if (afi == AFI_IP && safi == SAFI_LABELED_UNICAST)
8265 return "ipv4LabeledUnicast";
8266 else if (afi == AFI_IP && safi == SAFI_MPLS_VPN)
8267 return "ipv4Vpn";
8268 else if (afi == AFI_IP && safi == SAFI_ENCAP)
8269 return "ipv4Encap";
8270 else if (afi == AFI_IP && safi == SAFI_FLOWSPEC)
8271 return "ipv4Flowspec";
8272 else if (afi == AFI_IP6 && safi == SAFI_UNICAST)
8273 return "ipv6Unicast";
8274 else if (afi == AFI_IP6 && safi == SAFI_MULTICAST)
8275 return "ipv6Multicast";
8276 else if (afi == AFI_IP6 && safi == SAFI_LABELED_UNICAST)
8277 return "ipv6LabeledUnicast";
8278 else if (afi == AFI_IP6 && safi == SAFI_MPLS_VPN)
8279 return "ipv6Vpn";
8280 else if (afi == AFI_IP6 && safi == SAFI_ENCAP)
8281 return "ipv6Encap";
8282 else if (afi == AFI_IP6 && safi == SAFI_FLOWSPEC)
8283 return "ipv6Flowspec";
8284 else if (afi == AFI_L2VPN && safi == SAFI_EVPN)
8285 return "l2VpnEvpn";
8286 else
8287 return "Unknown";
8288 }
8289
8290 /* Show BGP peer's information. */
8291 enum show_type { show_all, show_peer };
8292
8293 static void bgp_show_peer_afi_orf_cap(struct vty *vty, struct peer *p,
8294 afi_t afi, safi_t safi,
8295 uint16_t adv_smcap, uint16_t adv_rmcap,
8296 uint16_t rcv_smcap, uint16_t rcv_rmcap,
8297 uint8_t use_json, json_object *json_pref)
8298 {
8299 /* Send-Mode */
8300 if (CHECK_FLAG(p->af_cap[afi][safi], adv_smcap)
8301 || CHECK_FLAG(p->af_cap[afi][safi], rcv_smcap)) {
8302 if (use_json) {
8303 if (CHECK_FLAG(p->af_cap[afi][safi], adv_smcap)
8304 && CHECK_FLAG(p->af_cap[afi][safi], rcv_smcap))
8305 json_object_string_add(json_pref, "sendMode",
8306 "advertisedAndReceived");
8307 else if (CHECK_FLAG(p->af_cap[afi][safi], adv_smcap))
8308 json_object_string_add(json_pref, "sendMode",
8309 "advertised");
8310 else if (CHECK_FLAG(p->af_cap[afi][safi], rcv_smcap))
8311 json_object_string_add(json_pref, "sendMode",
8312 "received");
8313 } else {
8314 vty_out(vty, " Send-mode: ");
8315 if (CHECK_FLAG(p->af_cap[afi][safi], adv_smcap))
8316 vty_out(vty, "advertised");
8317 if (CHECK_FLAG(p->af_cap[afi][safi], rcv_smcap))
8318 vty_out(vty, "%sreceived",
8319 CHECK_FLAG(p->af_cap[afi][safi],
8320 adv_smcap)
8321 ? ", "
8322 : "");
8323 vty_out(vty, "\n");
8324 }
8325 }
8326
8327 /* Receive-Mode */
8328 if (CHECK_FLAG(p->af_cap[afi][safi], adv_rmcap)
8329 || CHECK_FLAG(p->af_cap[afi][safi], rcv_rmcap)) {
8330 if (use_json) {
8331 if (CHECK_FLAG(p->af_cap[afi][safi], adv_rmcap)
8332 && CHECK_FLAG(p->af_cap[afi][safi], rcv_rmcap))
8333 json_object_string_add(json_pref, "recvMode",
8334 "advertisedAndReceived");
8335 else if (CHECK_FLAG(p->af_cap[afi][safi], adv_rmcap))
8336 json_object_string_add(json_pref, "recvMode",
8337 "advertised");
8338 else if (CHECK_FLAG(p->af_cap[afi][safi], rcv_rmcap))
8339 json_object_string_add(json_pref, "recvMode",
8340 "received");
8341 } else {
8342 vty_out(vty, " Receive-mode: ");
8343 if (CHECK_FLAG(p->af_cap[afi][safi], adv_rmcap))
8344 vty_out(vty, "advertised");
8345 if (CHECK_FLAG(p->af_cap[afi][safi], rcv_rmcap))
8346 vty_out(vty, "%sreceived",
8347 CHECK_FLAG(p->af_cap[afi][safi],
8348 adv_rmcap)
8349 ? ", "
8350 : "");
8351 vty_out(vty, "\n");
8352 }
8353 }
8354 }
8355
8356 static void bgp_show_peer_afi(struct vty *vty, struct peer *p, afi_t afi,
8357 safi_t safi, uint8_t use_json,
8358 json_object *json_neigh)
8359 {
8360 struct bgp_filter *filter;
8361 struct peer_af *paf;
8362 char orf_pfx_name[BUFSIZ];
8363 int orf_pfx_count;
8364 json_object *json_af = NULL;
8365 json_object *json_prefA = NULL;
8366 json_object *json_prefB = NULL;
8367 json_object *json_addr = NULL;
8368
8369 if (use_json) {
8370 json_addr = json_object_new_object();
8371 json_af = json_object_new_object();
8372 filter = &p->filter[afi][safi];
8373
8374 if (peer_group_active(p))
8375 json_object_string_add(json_addr, "peerGroupMember",
8376 p->group->name);
8377
8378 paf = peer_af_find(p, afi, safi);
8379 if (paf && PAF_SUBGRP(paf)) {
8380 json_object_int_add(json_addr, "updateGroupId",
8381 PAF_UPDGRP(paf)->id);
8382 json_object_int_add(json_addr, "subGroupId",
8383 PAF_SUBGRP(paf)->id);
8384 json_object_int_add(json_addr, "packetQueueLength",
8385 bpacket_queue_virtual_length(paf));
8386 }
8387
8388 if (CHECK_FLAG(p->af_cap[afi][safi], PEER_CAP_ORF_PREFIX_SM_ADV)
8389 || CHECK_FLAG(p->af_cap[afi][safi],
8390 PEER_CAP_ORF_PREFIX_SM_RCV)
8391 || CHECK_FLAG(p->af_cap[afi][safi],
8392 PEER_CAP_ORF_PREFIX_RM_ADV)
8393 || CHECK_FLAG(p->af_cap[afi][safi],
8394 PEER_CAP_ORF_PREFIX_RM_RCV)) {
8395 json_object_int_add(json_af, "orfType",
8396 ORF_TYPE_PREFIX);
8397 json_prefA = json_object_new_object();
8398 bgp_show_peer_afi_orf_cap(vty, p, afi, safi,
8399 PEER_CAP_ORF_PREFIX_SM_ADV,
8400 PEER_CAP_ORF_PREFIX_RM_ADV,
8401 PEER_CAP_ORF_PREFIX_SM_RCV,
8402 PEER_CAP_ORF_PREFIX_RM_RCV,
8403 use_json, json_prefA);
8404 json_object_object_add(json_af, "orfPrefixList",
8405 json_prefA);
8406 }
8407
8408 if (CHECK_FLAG(p->af_cap[afi][safi], PEER_CAP_ORF_PREFIX_SM_ADV)
8409 || CHECK_FLAG(p->af_cap[afi][safi],
8410 PEER_CAP_ORF_PREFIX_SM_OLD_RCV)
8411 || CHECK_FLAG(p->af_cap[afi][safi],
8412 PEER_CAP_ORF_PREFIX_RM_ADV)
8413 || CHECK_FLAG(p->af_cap[afi][safi],
8414 PEER_CAP_ORF_PREFIX_RM_OLD_RCV)) {
8415 json_object_int_add(json_af, "orfOldType",
8416 ORF_TYPE_PREFIX_OLD);
8417 json_prefB = json_object_new_object();
8418 bgp_show_peer_afi_orf_cap(
8419 vty, p, afi, safi, PEER_CAP_ORF_PREFIX_SM_ADV,
8420 PEER_CAP_ORF_PREFIX_RM_ADV,
8421 PEER_CAP_ORF_PREFIX_SM_OLD_RCV,
8422 PEER_CAP_ORF_PREFIX_RM_OLD_RCV, use_json,
8423 json_prefB);
8424 json_object_object_add(json_af, "orfOldPrefixList",
8425 json_prefB);
8426 }
8427
8428 if (CHECK_FLAG(p->af_cap[afi][safi], PEER_CAP_ORF_PREFIX_SM_ADV)
8429 || CHECK_FLAG(p->af_cap[afi][safi],
8430 PEER_CAP_ORF_PREFIX_SM_RCV)
8431 || CHECK_FLAG(p->af_cap[afi][safi],
8432 PEER_CAP_ORF_PREFIX_SM_OLD_RCV)
8433 || CHECK_FLAG(p->af_cap[afi][safi],
8434 PEER_CAP_ORF_PREFIX_RM_ADV)
8435 || CHECK_FLAG(p->af_cap[afi][safi],
8436 PEER_CAP_ORF_PREFIX_RM_RCV)
8437 || CHECK_FLAG(p->af_cap[afi][safi],
8438 PEER_CAP_ORF_PREFIX_RM_OLD_RCV))
8439 json_object_object_add(json_addr, "afDependentCap",
8440 json_af);
8441 else
8442 json_object_free(json_af);
8443
8444 sprintf(orf_pfx_name, "%s.%d.%d", p->host, afi, safi);
8445 orf_pfx_count = prefix_bgp_show_prefix_list(
8446 NULL, afi, orf_pfx_name, use_json);
8447
8448 if (CHECK_FLAG(p->af_sflags[afi][safi],
8449 PEER_STATUS_ORF_PREFIX_SEND)
8450 || orf_pfx_count) {
8451 if (CHECK_FLAG(p->af_sflags[afi][safi],
8452 PEER_STATUS_ORF_PREFIX_SEND))
8453 json_object_boolean_true_add(json_neigh,
8454 "orfSent");
8455 if (orf_pfx_count)
8456 json_object_int_add(json_addr, "orfRecvCounter",
8457 orf_pfx_count);
8458 }
8459 if (CHECK_FLAG(p->af_sflags[afi][safi],
8460 PEER_STATUS_ORF_WAIT_REFRESH))
8461 json_object_string_add(
8462 json_addr, "orfFirstUpdate",
8463 "deferredUntilORFOrRouteRefreshRecvd");
8464
8465 if (CHECK_FLAG(p->af_flags[afi][safi],
8466 PEER_FLAG_REFLECTOR_CLIENT))
8467 json_object_boolean_true_add(json_addr,
8468 "routeReflectorClient");
8469 if (CHECK_FLAG(p->af_flags[afi][safi],
8470 PEER_FLAG_RSERVER_CLIENT))
8471 json_object_boolean_true_add(json_addr,
8472 "routeServerClient");
8473 if (CHECK_FLAG(p->af_flags[afi][safi], PEER_FLAG_SOFT_RECONFIG))
8474 json_object_boolean_true_add(json_addr,
8475 "inboundSoftConfigPermit");
8476
8477 if (CHECK_FLAG(p->af_flags[afi][safi],
8478 PEER_FLAG_REMOVE_PRIVATE_AS_ALL_REPLACE))
8479 json_object_boolean_true_add(
8480 json_addr,
8481 "privateAsNumsAllReplacedInUpdatesToNbr");
8482 else if (CHECK_FLAG(p->af_flags[afi][safi],
8483 PEER_FLAG_REMOVE_PRIVATE_AS_REPLACE))
8484 json_object_boolean_true_add(
8485 json_addr,
8486 "privateAsNumsReplacedInUpdatesToNbr");
8487 else if (CHECK_FLAG(p->af_flags[afi][safi],
8488 PEER_FLAG_REMOVE_PRIVATE_AS_ALL))
8489 json_object_boolean_true_add(
8490 json_addr,
8491 "privateAsNumsAllRemovedInUpdatesToNbr");
8492 else if (CHECK_FLAG(p->af_flags[afi][safi],
8493 PEER_FLAG_REMOVE_PRIVATE_AS))
8494 json_object_boolean_true_add(
8495 json_addr,
8496 "privateAsNumsRemovedInUpdatesToNbr");
8497
8498 if (CHECK_FLAG(p->af_flags[afi][safi],
8499 PEER_FLAG_ADDPATH_TX_ALL_PATHS))
8500 json_object_boolean_true_add(json_addr,
8501 "addpathTxAllPaths");
8502
8503 if (CHECK_FLAG(p->af_flags[afi][safi],
8504 PEER_FLAG_ADDPATH_TX_BESTPATH_PER_AS))
8505 json_object_boolean_true_add(json_addr,
8506 "addpathTxBestpathPerAS");
8507
8508 if (CHECK_FLAG(p->af_flags[afi][safi], PEER_FLAG_AS_OVERRIDE))
8509 json_object_string_add(json_addr,
8510 "overrideASNsInOutboundUpdates",
8511 "ifAspathEqualRemoteAs");
8512
8513 if (CHECK_FLAG(p->af_flags[afi][safi], PEER_FLAG_NEXTHOP_SELF)
8514 || CHECK_FLAG(p->af_flags[afi][safi],
8515 PEER_FLAG_FORCE_NEXTHOP_SELF))
8516 json_object_boolean_true_add(json_addr,
8517 "routerAlwaysNextHop");
8518 if (CHECK_FLAG(p->af_flags[afi][safi],
8519 PEER_FLAG_AS_PATH_UNCHANGED))
8520 json_object_boolean_true_add(
8521 json_addr, "unchangedAsPathPropogatedToNbr");
8522 if (CHECK_FLAG(p->af_flags[afi][safi],
8523 PEER_FLAG_NEXTHOP_UNCHANGED))
8524 json_object_boolean_true_add(
8525 json_addr, "unchangedNextHopPropogatedToNbr");
8526 if (CHECK_FLAG(p->af_flags[afi][safi], PEER_FLAG_MED_UNCHANGED))
8527 json_object_boolean_true_add(
8528 json_addr, "unchangedMedPropogatedToNbr");
8529 if (CHECK_FLAG(p->af_flags[afi][safi], PEER_FLAG_SEND_COMMUNITY)
8530 || CHECK_FLAG(p->af_flags[afi][safi],
8531 PEER_FLAG_SEND_EXT_COMMUNITY)) {
8532 if (CHECK_FLAG(p->af_flags[afi][safi],
8533 PEER_FLAG_SEND_COMMUNITY)
8534 && CHECK_FLAG(p->af_flags[afi][safi],
8535 PEER_FLAG_SEND_EXT_COMMUNITY))
8536 json_object_string_add(json_addr,
8537 "commAttriSentToNbr",
8538 "extendedAndStandard");
8539 else if (CHECK_FLAG(p->af_flags[afi][safi],
8540 PEER_FLAG_SEND_EXT_COMMUNITY))
8541 json_object_string_add(json_addr,
8542 "commAttriSentToNbr",
8543 "extended");
8544 else
8545 json_object_string_add(json_addr,
8546 "commAttriSentToNbr",
8547 "standard");
8548 }
8549 if (CHECK_FLAG(p->af_flags[afi][safi],
8550 PEER_FLAG_DEFAULT_ORIGINATE)) {
8551 if (p->default_rmap[afi][safi].name)
8552 json_object_string_add(
8553 json_addr, "defaultRouteMap",
8554 p->default_rmap[afi][safi].name);
8555
8556 if (paf && PAF_SUBGRP(paf)
8557 && CHECK_FLAG(PAF_SUBGRP(paf)->sflags,
8558 SUBGRP_STATUS_DEFAULT_ORIGINATE))
8559 json_object_boolean_true_add(json_addr,
8560 "defaultSent");
8561 else
8562 json_object_boolean_true_add(json_addr,
8563 "defaultNotSent");
8564 }
8565
8566 if (afi == AFI_L2VPN && safi == SAFI_EVPN) {
8567 if (is_evpn_enabled())
8568 json_object_boolean_true_add(
8569 json_addr, "advertiseAllVnis");
8570 }
8571
8572 if (filter->plist[FILTER_IN].name
8573 || filter->dlist[FILTER_IN].name
8574 || filter->aslist[FILTER_IN].name
8575 || filter->map[RMAP_IN].name)
8576 json_object_boolean_true_add(json_addr,
8577 "inboundPathPolicyConfig");
8578 if (filter->plist[FILTER_OUT].name
8579 || filter->dlist[FILTER_OUT].name
8580 || filter->aslist[FILTER_OUT].name
8581 || filter->map[RMAP_OUT].name || filter->usmap.name)
8582 json_object_boolean_true_add(
8583 json_addr, "outboundPathPolicyConfig");
8584
8585 /* prefix-list */
8586 if (filter->plist[FILTER_IN].name)
8587 json_object_string_add(json_addr,
8588 "incomingUpdatePrefixFilterList",
8589 filter->plist[FILTER_IN].name);
8590 if (filter->plist[FILTER_OUT].name)
8591 json_object_string_add(json_addr,
8592 "outgoingUpdatePrefixFilterList",
8593 filter->plist[FILTER_OUT].name);
8594
8595 /* distribute-list */
8596 if (filter->dlist[FILTER_IN].name)
8597 json_object_string_add(
8598 json_addr, "incomingUpdateNetworkFilterList",
8599 filter->dlist[FILTER_IN].name);
8600 if (filter->dlist[FILTER_OUT].name)
8601 json_object_string_add(
8602 json_addr, "outgoingUpdateNetworkFilterList",
8603 filter->dlist[FILTER_OUT].name);
8604
8605 /* filter-list. */
8606 if (filter->aslist[FILTER_IN].name)
8607 json_object_string_add(json_addr,
8608 "incomingUpdateAsPathFilterList",
8609 filter->aslist[FILTER_IN].name);
8610 if (filter->aslist[FILTER_OUT].name)
8611 json_object_string_add(json_addr,
8612 "outgoingUpdateAsPathFilterList",
8613 filter->aslist[FILTER_OUT].name);
8614
8615 /* route-map. */
8616 if (filter->map[RMAP_IN].name)
8617 json_object_string_add(
8618 json_addr, "routeMapForIncomingAdvertisements",
8619 filter->map[RMAP_IN].name);
8620 if (filter->map[RMAP_OUT].name)
8621 json_object_string_add(
8622 json_addr, "routeMapForOutgoingAdvertisements",
8623 filter->map[RMAP_OUT].name);
8624
8625 /* unsuppress-map */
8626 if (filter->usmap.name)
8627 json_object_string_add(json_addr,
8628 "selectiveUnsuppressRouteMap",
8629 filter->usmap.name);
8630
8631 /* Receive prefix count */
8632 json_object_int_add(json_addr, "acceptedPrefixCounter",
8633 p->pcount[afi][safi]);
8634
8635 /* Maximum prefix */
8636 if (CHECK_FLAG(p->af_flags[afi][safi], PEER_FLAG_MAX_PREFIX)) {
8637 json_object_int_add(json_addr, "prefixAllowedMax",
8638 p->pmax[afi][safi]);
8639 if (CHECK_FLAG(p->af_flags[afi][safi],
8640 PEER_FLAG_MAX_PREFIX_WARNING))
8641 json_object_boolean_true_add(
8642 json_addr, "prefixAllowedMaxWarning");
8643 json_object_int_add(json_addr,
8644 "prefixAllowedWarningThresh",
8645 p->pmax_threshold[afi][safi]);
8646 if (p->pmax_restart[afi][safi])
8647 json_object_int_add(
8648 json_addr,
8649 "prefixAllowedRestartIntervalMsecs",
8650 p->pmax_restart[afi][safi] * 60000);
8651 }
8652 json_object_object_add(json_neigh, afi_safi_print(afi, safi),
8653 json_addr);
8654
8655 } else {
8656 filter = &p->filter[afi][safi];
8657
8658 vty_out(vty, " For address family: %s\n",
8659 afi_safi_print(afi, safi));
8660
8661 if (peer_group_active(p))
8662 vty_out(vty, " %s peer-group member\n",
8663 p->group->name);
8664
8665 paf = peer_af_find(p, afi, safi);
8666 if (paf && PAF_SUBGRP(paf)) {
8667 vty_out(vty, " Update group %" PRIu64
8668 ", subgroup %" PRIu64 "\n",
8669 PAF_UPDGRP(paf)->id, PAF_SUBGRP(paf)->id);
8670 vty_out(vty, " Packet Queue length %d\n",
8671 bpacket_queue_virtual_length(paf));
8672 } else {
8673 vty_out(vty, " Not part of any update group\n");
8674 }
8675 if (CHECK_FLAG(p->af_cap[afi][safi], PEER_CAP_ORF_PREFIX_SM_ADV)
8676 || CHECK_FLAG(p->af_cap[afi][safi],
8677 PEER_CAP_ORF_PREFIX_SM_RCV)
8678 || CHECK_FLAG(p->af_cap[afi][safi],
8679 PEER_CAP_ORF_PREFIX_SM_OLD_RCV)
8680 || CHECK_FLAG(p->af_cap[afi][safi],
8681 PEER_CAP_ORF_PREFIX_RM_ADV)
8682 || CHECK_FLAG(p->af_cap[afi][safi],
8683 PEER_CAP_ORF_PREFIX_RM_RCV)
8684 || CHECK_FLAG(p->af_cap[afi][safi],
8685 PEER_CAP_ORF_PREFIX_RM_OLD_RCV))
8686 vty_out(vty, " AF-dependant capabilities:\n");
8687
8688 if (CHECK_FLAG(p->af_cap[afi][safi], PEER_CAP_ORF_PREFIX_SM_ADV)
8689 || CHECK_FLAG(p->af_cap[afi][safi],
8690 PEER_CAP_ORF_PREFIX_SM_RCV)
8691 || CHECK_FLAG(p->af_cap[afi][safi],
8692 PEER_CAP_ORF_PREFIX_RM_ADV)
8693 || CHECK_FLAG(p->af_cap[afi][safi],
8694 PEER_CAP_ORF_PREFIX_RM_RCV)) {
8695 vty_out(vty,
8696 " Outbound Route Filter (ORF) type (%d) Prefix-list:\n",
8697 ORF_TYPE_PREFIX);
8698 bgp_show_peer_afi_orf_cap(
8699 vty, p, afi, safi, PEER_CAP_ORF_PREFIX_SM_ADV,
8700 PEER_CAP_ORF_PREFIX_RM_ADV,
8701 PEER_CAP_ORF_PREFIX_SM_RCV,
8702 PEER_CAP_ORF_PREFIX_RM_RCV, use_json, NULL);
8703 }
8704 if (CHECK_FLAG(p->af_cap[afi][safi], PEER_CAP_ORF_PREFIX_SM_ADV)
8705 || CHECK_FLAG(p->af_cap[afi][safi],
8706 PEER_CAP_ORF_PREFIX_SM_OLD_RCV)
8707 || CHECK_FLAG(p->af_cap[afi][safi],
8708 PEER_CAP_ORF_PREFIX_RM_ADV)
8709 || CHECK_FLAG(p->af_cap[afi][safi],
8710 PEER_CAP_ORF_PREFIX_RM_OLD_RCV)) {
8711 vty_out(vty,
8712 " Outbound Route Filter (ORF) type (%d) Prefix-list:\n",
8713 ORF_TYPE_PREFIX_OLD);
8714 bgp_show_peer_afi_orf_cap(
8715 vty, p, afi, safi, PEER_CAP_ORF_PREFIX_SM_ADV,
8716 PEER_CAP_ORF_PREFIX_RM_ADV,
8717 PEER_CAP_ORF_PREFIX_SM_OLD_RCV,
8718 PEER_CAP_ORF_PREFIX_RM_OLD_RCV, use_json, NULL);
8719 }
8720
8721 sprintf(orf_pfx_name, "%s.%d.%d", p->host, afi, safi);
8722 orf_pfx_count = prefix_bgp_show_prefix_list(
8723 NULL, afi, orf_pfx_name, use_json);
8724
8725 if (CHECK_FLAG(p->af_sflags[afi][safi],
8726 PEER_STATUS_ORF_PREFIX_SEND)
8727 || orf_pfx_count) {
8728 vty_out(vty, " Outbound Route Filter (ORF):");
8729 if (CHECK_FLAG(p->af_sflags[afi][safi],
8730 PEER_STATUS_ORF_PREFIX_SEND))
8731 vty_out(vty, " sent;");
8732 if (orf_pfx_count)
8733 vty_out(vty, " received (%d entries)",
8734 orf_pfx_count);
8735 vty_out(vty, "\n");
8736 }
8737 if (CHECK_FLAG(p->af_sflags[afi][safi],
8738 PEER_STATUS_ORF_WAIT_REFRESH))
8739 vty_out(vty,
8740 " First update is deferred until ORF or ROUTE-REFRESH is received\n");
8741
8742 if (CHECK_FLAG(p->af_flags[afi][safi],
8743 PEER_FLAG_REFLECTOR_CLIENT))
8744 vty_out(vty, " Route-Reflector Client\n");
8745 if (CHECK_FLAG(p->af_flags[afi][safi],
8746 PEER_FLAG_RSERVER_CLIENT))
8747 vty_out(vty, " Route-Server Client\n");
8748 if (CHECK_FLAG(p->af_flags[afi][safi], PEER_FLAG_SOFT_RECONFIG))
8749 vty_out(vty,
8750 " Inbound soft reconfiguration allowed\n");
8751
8752 if (CHECK_FLAG(p->af_flags[afi][safi],
8753 PEER_FLAG_REMOVE_PRIVATE_AS_ALL_REPLACE))
8754 vty_out(vty,
8755 " Private AS numbers (all) replaced in updates to this neighbor\n");
8756 else if (CHECK_FLAG(p->af_flags[afi][safi],
8757 PEER_FLAG_REMOVE_PRIVATE_AS_REPLACE))
8758 vty_out(vty,
8759 " Private AS numbers replaced in updates to this neighbor\n");
8760 else if (CHECK_FLAG(p->af_flags[afi][safi],
8761 PEER_FLAG_REMOVE_PRIVATE_AS_ALL))
8762 vty_out(vty,
8763 " Private AS numbers (all) removed in updates to this neighbor\n");
8764 else if (CHECK_FLAG(p->af_flags[afi][safi],
8765 PEER_FLAG_REMOVE_PRIVATE_AS))
8766 vty_out(vty,
8767 " Private AS numbers removed in updates to this neighbor\n");
8768
8769 if (CHECK_FLAG(p->af_flags[afi][safi],
8770 PEER_FLAG_ADDPATH_TX_ALL_PATHS))
8771 vty_out(vty, " Advertise all paths via addpath\n");
8772
8773 if (CHECK_FLAG(p->af_flags[afi][safi],
8774 PEER_FLAG_ADDPATH_TX_BESTPATH_PER_AS))
8775 vty_out(vty,
8776 " Advertise bestpath per AS via addpath\n");
8777
8778 if (CHECK_FLAG(p->af_flags[afi][safi], PEER_FLAG_AS_OVERRIDE))
8779 vty_out(vty,
8780 " Override ASNs in outbound updates if aspath equals remote-as\n");
8781
8782 if (CHECK_FLAG(p->af_flags[afi][safi], PEER_FLAG_NEXTHOP_SELF)
8783 || CHECK_FLAG(p->af_flags[afi][safi],
8784 PEER_FLAG_FORCE_NEXTHOP_SELF))
8785 vty_out(vty, " NEXT_HOP is always this router\n");
8786 if (CHECK_FLAG(p->af_flags[afi][safi],
8787 PEER_FLAG_AS_PATH_UNCHANGED))
8788 vty_out(vty,
8789 " AS_PATH is propagated unchanged to this neighbor\n");
8790 if (CHECK_FLAG(p->af_flags[afi][safi],
8791 PEER_FLAG_NEXTHOP_UNCHANGED))
8792 vty_out(vty,
8793 " NEXT_HOP is propagated unchanged to this neighbor\n");
8794 if (CHECK_FLAG(p->af_flags[afi][safi], PEER_FLAG_MED_UNCHANGED))
8795 vty_out(vty,
8796 " MED is propagated unchanged to this neighbor\n");
8797 if (CHECK_FLAG(p->af_flags[afi][safi], PEER_FLAG_SEND_COMMUNITY)
8798 || CHECK_FLAG(p->af_flags[afi][safi],
8799 PEER_FLAG_SEND_EXT_COMMUNITY)
8800 || CHECK_FLAG(p->af_flags[afi][safi],
8801 PEER_FLAG_SEND_LARGE_COMMUNITY)) {
8802 vty_out(vty,
8803 " Community attribute sent to this neighbor");
8804 if (CHECK_FLAG(p->af_flags[afi][safi],
8805 PEER_FLAG_SEND_COMMUNITY)
8806 && CHECK_FLAG(p->af_flags[afi][safi],
8807 PEER_FLAG_SEND_EXT_COMMUNITY)
8808 && CHECK_FLAG(p->af_flags[afi][safi],
8809 PEER_FLAG_SEND_LARGE_COMMUNITY))
8810 vty_out(vty, "(all)\n");
8811 else if (CHECK_FLAG(p->af_flags[afi][safi],
8812 PEER_FLAG_SEND_LARGE_COMMUNITY))
8813 vty_out(vty, "(large)\n");
8814 else if (CHECK_FLAG(p->af_flags[afi][safi],
8815 PEER_FLAG_SEND_EXT_COMMUNITY))
8816 vty_out(vty, "(extended)\n");
8817 else
8818 vty_out(vty, "(standard)\n");
8819 }
8820 if (CHECK_FLAG(p->af_flags[afi][safi],
8821 PEER_FLAG_DEFAULT_ORIGINATE)) {
8822 vty_out(vty, " Default information originate,");
8823
8824 if (p->default_rmap[afi][safi].name)
8825 vty_out(vty, " default route-map %s%s,",
8826 p->default_rmap[afi][safi].map ? "*"
8827 : "",
8828 p->default_rmap[afi][safi].name);
8829 if (paf && PAF_SUBGRP(paf)
8830 && CHECK_FLAG(PAF_SUBGRP(paf)->sflags,
8831 SUBGRP_STATUS_DEFAULT_ORIGINATE))
8832 vty_out(vty, " default sent\n");
8833 else
8834 vty_out(vty, " default not sent\n");
8835 }
8836
8837 /* advertise-vni-all */
8838 if (afi == AFI_L2VPN && safi == SAFI_EVPN) {
8839 if (is_evpn_enabled())
8840 vty_out(vty, " advertise-all-vni\n");
8841 }
8842
8843 if (filter->plist[FILTER_IN].name
8844 || filter->dlist[FILTER_IN].name
8845 || filter->aslist[FILTER_IN].name
8846 || filter->map[RMAP_IN].name)
8847 vty_out(vty, " Inbound path policy configured\n");
8848 if (filter->plist[FILTER_OUT].name
8849 || filter->dlist[FILTER_OUT].name
8850 || filter->aslist[FILTER_OUT].name
8851 || filter->map[RMAP_OUT].name || filter->usmap.name)
8852 vty_out(vty, " Outbound path policy configured\n");
8853
8854 /* prefix-list */
8855 if (filter->plist[FILTER_IN].name)
8856 vty_out(vty,
8857 " Incoming update prefix filter list is %s%s\n",
8858 filter->plist[FILTER_IN].plist ? "*" : "",
8859 filter->plist[FILTER_IN].name);
8860 if (filter->plist[FILTER_OUT].name)
8861 vty_out(vty,
8862 " Outgoing update prefix filter list is %s%s\n",
8863 filter->plist[FILTER_OUT].plist ? "*" : "",
8864 filter->plist[FILTER_OUT].name);
8865
8866 /* distribute-list */
8867 if (filter->dlist[FILTER_IN].name)
8868 vty_out(vty,
8869 " Incoming update network filter list is %s%s\n",
8870 filter->dlist[FILTER_IN].alist ? "*" : "",
8871 filter->dlist[FILTER_IN].name);
8872 if (filter->dlist[FILTER_OUT].name)
8873 vty_out(vty,
8874 " Outgoing update network filter list is %s%s\n",
8875 filter->dlist[FILTER_OUT].alist ? "*" : "",
8876 filter->dlist[FILTER_OUT].name);
8877
8878 /* filter-list. */
8879 if (filter->aslist[FILTER_IN].name)
8880 vty_out(vty,
8881 " Incoming update AS path filter list is %s%s\n",
8882 filter->aslist[FILTER_IN].aslist ? "*" : "",
8883 filter->aslist[FILTER_IN].name);
8884 if (filter->aslist[FILTER_OUT].name)
8885 vty_out(vty,
8886 " Outgoing update AS path filter list is %s%s\n",
8887 filter->aslist[FILTER_OUT].aslist ? "*" : "",
8888 filter->aslist[FILTER_OUT].name);
8889
8890 /* route-map. */
8891 if (filter->map[RMAP_IN].name)
8892 vty_out(vty,
8893 " Route map for incoming advertisements is %s%s\n",
8894 filter->map[RMAP_IN].map ? "*" : "",
8895 filter->map[RMAP_IN].name);
8896 if (filter->map[RMAP_OUT].name)
8897 vty_out(vty,
8898 " Route map for outgoing advertisements is %s%s\n",
8899 filter->map[RMAP_OUT].map ? "*" : "",
8900 filter->map[RMAP_OUT].name);
8901
8902 /* unsuppress-map */
8903 if (filter->usmap.name)
8904 vty_out(vty,
8905 " Route map for selective unsuppress is %s%s\n",
8906 filter->usmap.map ? "*" : "",
8907 filter->usmap.name);
8908
8909 /* Receive prefix count */
8910 vty_out(vty, " %ld accepted prefixes\n", p->pcount[afi][safi]);
8911
8912 /* Maximum prefix */
8913 if (CHECK_FLAG(p->af_flags[afi][safi], PEER_FLAG_MAX_PREFIX)) {
8914 vty_out(vty, " Maximum prefixes allowed %ld%s\n",
8915 p->pmax[afi][safi],
8916 CHECK_FLAG(p->af_flags[afi][safi],
8917 PEER_FLAG_MAX_PREFIX_WARNING)
8918 ? " (warning-only)"
8919 : "");
8920 vty_out(vty, " Threshold for warning message %d%%",
8921 p->pmax_threshold[afi][safi]);
8922 if (p->pmax_restart[afi][safi])
8923 vty_out(vty, ", restart interval %d min",
8924 p->pmax_restart[afi][safi]);
8925 vty_out(vty, "\n");
8926 }
8927
8928 vty_out(vty, "\n");
8929 }
8930 }
8931
8932 static void bgp_show_peer(struct vty *vty, struct peer *p, uint8_t use_json,
8933 json_object *json)
8934 {
8935 struct bgp *bgp;
8936 char buf1[PREFIX2STR_BUFFER], buf[SU_ADDRSTRLEN];
8937 char timebuf[BGP_UPTIME_LEN];
8938 char dn_flag[2];
8939 const char *subcode_str;
8940 const char *code_str;
8941 afi_t afi;
8942 safi_t safi;
8943 uint16_t i;
8944 uint8_t *msg;
8945 json_object *json_neigh = NULL;
8946 time_t epoch_tbuf;
8947
8948 bgp = p->bgp;
8949
8950 if (use_json)
8951 json_neigh = json_object_new_object();
8952
8953 memset(dn_flag, '\0', sizeof(dn_flag));
8954 if (!p->conf_if && peer_dynamic_neighbor(p))
8955 dn_flag[0] = '*';
8956
8957 if (!use_json) {
8958 if (p->conf_if) /* Configured interface name. */
8959 vty_out(vty, "BGP neighbor on %s: %s, ", p->conf_if,
8960 BGP_PEER_SU_UNSPEC(p)
8961 ? "None"
8962 : sockunion2str(&p->su, buf,
8963 SU_ADDRSTRLEN));
8964 else /* Configured IP address. */
8965 vty_out(vty, "BGP neighbor is %s%s, ", dn_flag,
8966 p->host);
8967 }
8968
8969 if (use_json) {
8970 if (p->conf_if && BGP_PEER_SU_UNSPEC(p))
8971 json_object_string_add(json_neigh, "bgpNeighborAddr",
8972 "none");
8973 else if (p->conf_if && !BGP_PEER_SU_UNSPEC(p))
8974 json_object_string_add(
8975 json_neigh, "bgpNeighborAddr",
8976 sockunion2str(&p->su, buf, SU_ADDRSTRLEN));
8977
8978 json_object_int_add(json_neigh, "remoteAs", p->as);
8979
8980 if (p->change_local_as)
8981 json_object_int_add(json_neigh, "localAs",
8982 p->change_local_as);
8983 else
8984 json_object_int_add(json_neigh, "localAs", p->local_as);
8985
8986 if (CHECK_FLAG(p->flags, PEER_FLAG_LOCAL_AS_NO_PREPEND))
8987 json_object_boolean_true_add(json_neigh,
8988 "localAsNoPrepend");
8989
8990 if (CHECK_FLAG(p->flags, PEER_FLAG_LOCAL_AS_REPLACE_AS))
8991 json_object_boolean_true_add(json_neigh,
8992 "localAsReplaceAs");
8993 } else {
8994 if ((p->as_type == AS_SPECIFIED) || (p->as_type == AS_EXTERNAL)
8995 || (p->as_type == AS_INTERNAL))
8996 vty_out(vty, "remote AS %u, ", p->as);
8997 else
8998 vty_out(vty, "remote AS Unspecified, ");
8999 vty_out(vty, "local AS %u%s%s, ",
9000 p->change_local_as ? p->change_local_as : p->local_as,
9001 CHECK_FLAG(p->flags, PEER_FLAG_LOCAL_AS_NO_PREPEND)
9002 ? " no-prepend"
9003 : "",
9004 CHECK_FLAG(p->flags, PEER_FLAG_LOCAL_AS_REPLACE_AS)
9005 ? " replace-as"
9006 : "");
9007 }
9008 /* peer type internal, external, confed-internal or confed-external */
9009 if (p->as == p->local_as) {
9010 if (use_json) {
9011 if (CHECK_FLAG(bgp->config, BGP_CONFIG_CONFEDERATION))
9012 json_object_boolean_true_add(
9013 json_neigh, "nbrConfedInternalLink");
9014 else
9015 json_object_boolean_true_add(json_neigh,
9016 "nbrInternalLink");
9017 } else {
9018 if (CHECK_FLAG(bgp->config, BGP_CONFIG_CONFEDERATION))
9019 vty_out(vty, "confed-internal link\n");
9020 else
9021 vty_out(vty, "internal link\n");
9022 }
9023 } else {
9024 if (use_json) {
9025 if (CHECK_FLAG(bgp->config, BGP_CONFIG_CONFEDERATION))
9026 json_object_boolean_true_add(
9027 json_neigh, "nbrConfedExternalLink");
9028 else
9029 json_object_boolean_true_add(json_neigh,
9030 "nbrExternalLink");
9031 } else {
9032 if (bgp_confederation_peers_check(bgp, p->as))
9033 vty_out(vty, "confed-external link\n");
9034 else
9035 vty_out(vty, "external link\n");
9036 }
9037 }
9038
9039 /* Description. */
9040 if (p->desc) {
9041 if (use_json)
9042 json_object_string_add(json_neigh, "nbrDesc", p->desc);
9043 else
9044 vty_out(vty, " Description: %s\n", p->desc);
9045 }
9046
9047 if (p->hostname) {
9048 if (use_json) {
9049 if (p->hostname)
9050 json_object_string_add(json_neigh, "hostname",
9051 p->hostname);
9052
9053 if (p->domainname)
9054 json_object_string_add(json_neigh, "domainname",
9055 p->domainname);
9056 } else {
9057 if (p->domainname && (p->domainname[0] != '\0'))
9058 vty_out(vty, "Hostname: %s.%s\n", p->hostname,
9059 p->domainname);
9060 else
9061 vty_out(vty, "Hostname: %s\n", p->hostname);
9062 }
9063 }
9064
9065 /* Peer-group */
9066 if (p->group) {
9067 if (use_json) {
9068 json_object_string_add(json_neigh, "peerGroup",
9069 p->group->name);
9070
9071 if (dn_flag[0]) {
9072 struct prefix prefix, *range = NULL;
9073
9074 sockunion2hostprefix(&(p->su), &prefix);
9075 range = peer_group_lookup_dynamic_neighbor_range(
9076 p->group, &prefix);
9077
9078 if (range) {
9079 prefix2str(range, buf1, sizeof(buf1));
9080 json_object_string_add(
9081 json_neigh,
9082 "peerSubnetRangeGroup", buf1);
9083 }
9084 }
9085 } else {
9086 vty_out(vty,
9087 " Member of peer-group %s for session parameters\n",
9088 p->group->name);
9089
9090 if (dn_flag[0]) {
9091 struct prefix prefix, *range = NULL;
9092
9093 sockunion2hostprefix(&(p->su), &prefix);
9094 range = peer_group_lookup_dynamic_neighbor_range(
9095 p->group, &prefix);
9096
9097 if (range) {
9098 prefix2str(range, buf1, sizeof(buf1));
9099 vty_out(vty,
9100 " Belongs to the subnet range group: %s\n",
9101 buf1);
9102 }
9103 }
9104 }
9105 }
9106
9107 if (use_json) {
9108 /* Administrative shutdown. */
9109 if (CHECK_FLAG(p->flags, PEER_FLAG_SHUTDOWN))
9110 json_object_boolean_true_add(json_neigh,
9111 "adminShutDown");
9112
9113 /* BGP Version. */
9114 json_object_int_add(json_neigh, "bgpVersion", 4);
9115 json_object_string_add(
9116 json_neigh, "remoteRouterId",
9117 inet_ntop(AF_INET, &p->remote_id, buf1, sizeof(buf1)));
9118 json_object_string_add(
9119 json_neigh, "localRouterId",
9120 inet_ntop(AF_INET, &bgp->router_id, buf1,
9121 sizeof(buf1)));
9122
9123 /* Confederation */
9124 if (CHECK_FLAG(bgp->config, BGP_CONFIG_CONFEDERATION)
9125 && bgp_confederation_peers_check(bgp, p->as))
9126 json_object_boolean_true_add(json_neigh,
9127 "nbrCommonAdmin");
9128
9129 /* Status. */
9130 json_object_string_add(
9131 json_neigh, "bgpState",
9132 lookup_msg(bgp_status_msg, p->status, NULL));
9133
9134 if (p->status == Established) {
9135 time_t uptime;
9136
9137 uptime = bgp_clock();
9138 uptime -= p->uptime;
9139 epoch_tbuf = time(NULL) - uptime;
9140
9141 #if defined(VERSION_TYPE_DEV) && CONFDATE > 20200101
9142 CPP_NOTICE(
9143 "bgpTimerUp should be deprecated and can be removed now");
9144 #endif
9145 /*
9146 * bgpTimerUp was miliseconds that was accurate
9147 * up to 1 day, then the value returned
9148 * became garbage. So in order to provide
9149 * some level of backwards compatability,
9150 * we still provde the data, but now
9151 * we are returning the correct value
9152 * and also adding a new bgpTimerUpMsec
9153 * which will allow us to deprecate
9154 * this eventually
9155 */
9156 json_object_int_add(json_neigh, "bgpTimerUp",
9157 uptime * 1000);
9158 json_object_int_add(json_neigh, "bgpTimerUpMsec",
9159 uptime * 1000);
9160 json_object_string_add(json_neigh, "bgpTimerUpString",
9161 peer_uptime(p->uptime, timebuf,
9162 BGP_UPTIME_LEN, 0,
9163 NULL));
9164 json_object_int_add(json_neigh,
9165 "bgpTimerUpEstablishedEpoch",
9166 epoch_tbuf);
9167 }
9168
9169 else if (p->status == Active) {
9170 if (CHECK_FLAG(p->flags, PEER_FLAG_PASSIVE))
9171 json_object_string_add(json_neigh, "bgpStateIs",
9172 "passive");
9173 else if (CHECK_FLAG(p->sflags, PEER_STATUS_NSF_WAIT))
9174 json_object_string_add(json_neigh, "bgpStateIs",
9175 "passiveNSF");
9176 }
9177
9178 /* read timer */
9179 time_t uptime;
9180 struct tm *tm;
9181
9182 uptime = bgp_clock();
9183 uptime -= p->readtime;
9184 tm = gmtime(&uptime);
9185 json_object_int_add(json_neigh, "bgpTimerLastRead",
9186 (tm->tm_sec * 1000) + (tm->tm_min * 60000)
9187 + (tm->tm_hour * 3600000));
9188
9189 uptime = bgp_clock();
9190 uptime -= p->last_write;
9191 tm = gmtime(&uptime);
9192 json_object_int_add(json_neigh, "bgpTimerLastWrite",
9193 (tm->tm_sec * 1000) + (tm->tm_min * 60000)
9194 + (tm->tm_hour * 3600000));
9195
9196 uptime = bgp_clock();
9197 uptime -= p->update_time;
9198 tm = gmtime(&uptime);
9199 json_object_int_add(json_neigh, "bgpInUpdateElapsedTimeMsecs",
9200 (tm->tm_sec * 1000) + (tm->tm_min * 60000)
9201 + (tm->tm_hour * 3600000));
9202
9203 /* Configured timer values. */
9204 json_object_int_add(json_neigh, "bgpTimerHoldTimeMsecs",
9205 p->v_holdtime * 1000);
9206 json_object_int_add(json_neigh,
9207 "bgpTimerKeepAliveIntervalMsecs",
9208 p->v_keepalive * 1000);
9209 if (CHECK_FLAG(p->flags, PEER_FLAG_TIMER)) {
9210 json_object_int_add(json_neigh,
9211 "bgpTimerConfiguredHoldTimeMsecs",
9212 p->holdtime * 1000);
9213 json_object_int_add(
9214 json_neigh,
9215 "bgpTimerConfiguredKeepAliveIntervalMsecs",
9216 p->keepalive * 1000);
9217 } else if ((bgp->default_holdtime != BGP_DEFAULT_HOLDTIME)
9218 || (bgp->default_keepalive
9219 != BGP_DEFAULT_KEEPALIVE)) {
9220 json_object_int_add(json_neigh,
9221 "bgpTimerConfiguredHoldTimeMsecs",
9222 bgp->default_holdtime);
9223 json_object_int_add(
9224 json_neigh,
9225 "bgpTimerConfiguredKeepAliveIntervalMsecs",
9226 bgp->default_keepalive);
9227 }
9228 } else {
9229 /* Administrative shutdown. */
9230 if (CHECK_FLAG(p->flags, PEER_FLAG_SHUTDOWN))
9231 vty_out(vty, " Administratively shut down\n");
9232
9233 /* BGP Version. */
9234 vty_out(vty, " BGP version 4");
9235 vty_out(vty, ", remote router ID %s",
9236 inet_ntop(AF_INET, &p->remote_id, buf1, sizeof(buf1)));
9237 vty_out(vty, ", local router ID %s\n",
9238 inet_ntop(AF_INET, &bgp->router_id, buf1,
9239 sizeof(buf1)));
9240
9241 /* Confederation */
9242 if (CHECK_FLAG(bgp->config, BGP_CONFIG_CONFEDERATION)
9243 && bgp_confederation_peers_check(bgp, p->as))
9244 vty_out(vty,
9245 " Neighbor under common administration\n");
9246
9247 /* Status. */
9248 vty_out(vty, " BGP state = %s",
9249 lookup_msg(bgp_status_msg, p->status, NULL));
9250
9251 if (p->status == Established)
9252 vty_out(vty, ", up for %8s",
9253 peer_uptime(p->uptime, timebuf, BGP_UPTIME_LEN,
9254 0, NULL));
9255
9256 else if (p->status == Active) {
9257 if (CHECK_FLAG(p->flags, PEER_FLAG_PASSIVE))
9258 vty_out(vty, " (passive)");
9259 else if (CHECK_FLAG(p->sflags, PEER_STATUS_NSF_WAIT))
9260 vty_out(vty, " (NSF passive)");
9261 }
9262 vty_out(vty, "\n");
9263
9264 /* read timer */
9265 vty_out(vty, " Last read %s",
9266 peer_uptime(p->readtime, timebuf, BGP_UPTIME_LEN, 0,
9267 NULL));
9268 vty_out(vty, ", Last write %s\n",
9269 peer_uptime(p->last_write, timebuf, BGP_UPTIME_LEN, 0,
9270 NULL));
9271
9272 /* Configured timer values. */
9273 vty_out(vty,
9274 " Hold time is %d, keepalive interval is %d seconds\n",
9275 p->v_holdtime, p->v_keepalive);
9276 if (CHECK_FLAG(p->flags, PEER_FLAG_TIMER)) {
9277 vty_out(vty, " Configured hold time is %d",
9278 p->holdtime);
9279 vty_out(vty, ", keepalive interval is %d seconds\n",
9280 p->keepalive);
9281 } else if ((bgp->default_holdtime != BGP_DEFAULT_HOLDTIME)
9282 || (bgp->default_keepalive
9283 != BGP_DEFAULT_KEEPALIVE)) {
9284 vty_out(vty, " Configured hold time is %d",
9285 bgp->default_holdtime);
9286 vty_out(vty, ", keepalive interval is %d seconds\n",
9287 bgp->default_keepalive);
9288 }
9289 }
9290 /* Capability. */
9291 if (p->status == Established) {
9292 if (p->cap || p->afc_adv[AFI_IP][SAFI_UNICAST]
9293 || p->afc_recv[AFI_IP][SAFI_UNICAST]
9294 || p->afc_adv[AFI_IP][SAFI_MULTICAST]
9295 || p->afc_recv[AFI_IP][SAFI_MULTICAST]
9296 || p->afc_adv[AFI_IP6][SAFI_UNICAST]
9297 || p->afc_recv[AFI_IP6][SAFI_UNICAST]
9298 || p->afc_adv[AFI_IP6][SAFI_MULTICAST]
9299 || p->afc_recv[AFI_IP6][SAFI_MULTICAST]
9300 || p->afc_adv[AFI_IP6][SAFI_MPLS_VPN]
9301 || p->afc_recv[AFI_IP6][SAFI_MPLS_VPN]
9302 || p->afc_adv[AFI_IP6][SAFI_ENCAP]
9303 || p->afc_recv[AFI_IP6][SAFI_ENCAP]
9304 || p->afc_adv[AFI_IP6][SAFI_FLOWSPEC]
9305 || p->afc_recv[AFI_IP6][SAFI_FLOWSPEC]
9306 || p->afc_adv[AFI_IP][SAFI_ENCAP]
9307 || p->afc_recv[AFI_IP][SAFI_ENCAP]
9308 || p->afc_adv[AFI_IP][SAFI_FLOWSPEC]
9309 || p->afc_recv[AFI_IP][SAFI_FLOWSPEC]
9310 || p->afc_adv[AFI_IP][SAFI_MPLS_VPN]
9311 || p->afc_recv[AFI_IP][SAFI_MPLS_VPN]) {
9312 if (use_json) {
9313 json_object *json_cap = NULL;
9314
9315 json_cap = json_object_new_object();
9316
9317 /* AS4 */
9318 if (CHECK_FLAG(p->cap, PEER_CAP_AS4_RCV)
9319 || CHECK_FLAG(p->cap, PEER_CAP_AS4_ADV)) {
9320 if (CHECK_FLAG(p->cap, PEER_CAP_AS4_ADV)
9321 && CHECK_FLAG(p->cap,
9322 PEER_CAP_AS4_RCV))
9323 json_object_string_add(
9324 json_cap, "4byteAs",
9325 "advertisedAndReceived");
9326 else if (CHECK_FLAG(p->cap,
9327 PEER_CAP_AS4_ADV))
9328 json_object_string_add(
9329 json_cap, "4byteAs",
9330 "advertised");
9331 else if (CHECK_FLAG(p->cap,
9332 PEER_CAP_AS4_RCV))
9333 json_object_string_add(
9334 json_cap, "4byteAs",
9335 "received");
9336 }
9337
9338 /* AddPath */
9339 if (CHECK_FLAG(p->cap, PEER_CAP_ADDPATH_RCV)
9340 || CHECK_FLAG(p->cap,
9341 PEER_CAP_ADDPATH_ADV)) {
9342 json_object *json_add = NULL;
9343 const char *print_store;
9344
9345 json_add = json_object_new_object();
9346
9347 FOREACH_AFI_SAFI (afi, safi) {
9348 json_object *json_sub = NULL;
9349 json_sub =
9350 json_object_new_object();
9351 print_store = afi_safi_print(
9352 afi, safi);
9353
9354 if (CHECK_FLAG(
9355 p->af_cap[afi]
9356 [safi],
9357 PEER_CAP_ADDPATH_AF_TX_ADV)
9358 || CHECK_FLAG(
9359 p->af_cap[afi]
9360 [safi],
9361 PEER_CAP_ADDPATH_AF_TX_RCV)) {
9362 if (CHECK_FLAG(
9363 p->af_cap
9364 [afi]
9365 [safi],
9366 PEER_CAP_ADDPATH_AF_TX_ADV)
9367 && CHECK_FLAG(
9368 p->af_cap
9369 [afi]
9370 [safi],
9371 PEER_CAP_ADDPATH_AF_TX_RCV))
9372 json_object_boolean_true_add(
9373 json_sub,
9374 "txAdvertisedAndReceived");
9375 else if (
9376 CHECK_FLAG(
9377 p->af_cap
9378 [afi]
9379 [safi],
9380 PEER_CAP_ADDPATH_AF_TX_ADV))
9381 json_object_boolean_true_add(
9382 json_sub,
9383 "txAdvertised");
9384 else if (
9385 CHECK_FLAG(
9386 p->af_cap
9387 [afi]
9388 [safi],
9389 PEER_CAP_ADDPATH_AF_TX_RCV))
9390 json_object_boolean_true_add(
9391 json_sub,
9392 "txReceived");
9393 }
9394
9395 if (CHECK_FLAG(
9396 p->af_cap[afi]
9397 [safi],
9398 PEER_CAP_ADDPATH_AF_RX_ADV)
9399 || CHECK_FLAG(
9400 p->af_cap[afi]
9401 [safi],
9402 PEER_CAP_ADDPATH_AF_RX_RCV)) {
9403 if (CHECK_FLAG(
9404 p->af_cap
9405 [afi]
9406 [safi],
9407 PEER_CAP_ADDPATH_AF_RX_ADV)
9408 && CHECK_FLAG(
9409 p->af_cap
9410 [afi]
9411 [safi],
9412 PEER_CAP_ADDPATH_AF_RX_RCV))
9413 json_object_boolean_true_add(
9414 json_sub,
9415 "rxAdvertisedAndReceived");
9416 else if (
9417 CHECK_FLAG(
9418 p->af_cap
9419 [afi]
9420 [safi],
9421 PEER_CAP_ADDPATH_AF_RX_ADV))
9422 json_object_boolean_true_add(
9423 json_sub,
9424 "rxAdvertised");
9425 else if (
9426 CHECK_FLAG(
9427 p->af_cap
9428 [afi]
9429 [safi],
9430 PEER_CAP_ADDPATH_AF_RX_RCV))
9431 json_object_boolean_true_add(
9432 json_sub,
9433 "rxReceived");
9434 }
9435
9436 if (CHECK_FLAG(
9437 p->af_cap[afi]
9438 [safi],
9439 PEER_CAP_ADDPATH_AF_TX_ADV)
9440 || CHECK_FLAG(
9441 p->af_cap[afi]
9442 [safi],
9443 PEER_CAP_ADDPATH_AF_TX_RCV)
9444 || CHECK_FLAG(
9445 p->af_cap[afi]
9446 [safi],
9447 PEER_CAP_ADDPATH_AF_RX_ADV)
9448 || CHECK_FLAG(
9449 p->af_cap[afi]
9450 [safi],
9451 PEER_CAP_ADDPATH_AF_RX_RCV))
9452 json_object_object_add(
9453 json_add,
9454 print_store,
9455 json_sub);
9456 else
9457 json_object_free(
9458 json_sub);
9459 }
9460
9461 json_object_object_add(
9462 json_cap, "addPath", json_add);
9463 }
9464
9465 /* Dynamic */
9466 if (CHECK_FLAG(p->cap, PEER_CAP_DYNAMIC_RCV)
9467 || CHECK_FLAG(p->cap,
9468 PEER_CAP_DYNAMIC_ADV)) {
9469 if (CHECK_FLAG(p->cap,
9470 PEER_CAP_DYNAMIC_ADV)
9471 && CHECK_FLAG(p->cap,
9472 PEER_CAP_DYNAMIC_RCV))
9473 json_object_string_add(
9474 json_cap, "dynamic",
9475 "advertisedAndReceived");
9476 else if (CHECK_FLAG(
9477 p->cap,
9478 PEER_CAP_DYNAMIC_ADV))
9479 json_object_string_add(
9480 json_cap, "dynamic",
9481 "advertised");
9482 else if (CHECK_FLAG(
9483 p->cap,
9484 PEER_CAP_DYNAMIC_RCV))
9485 json_object_string_add(
9486 json_cap, "dynamic",
9487 "received");
9488 }
9489
9490 /* Extended nexthop */
9491 if (CHECK_FLAG(p->cap, PEER_CAP_ENHE_RCV)
9492 || CHECK_FLAG(p->cap, PEER_CAP_ENHE_ADV)) {
9493 json_object *json_nxt = NULL;
9494 const char *print_store;
9495
9496
9497 if (CHECK_FLAG(p->cap,
9498 PEER_CAP_ENHE_ADV)
9499 && CHECK_FLAG(p->cap,
9500 PEER_CAP_ENHE_RCV))
9501 json_object_string_add(
9502 json_cap,
9503 "extendedNexthop",
9504 "advertisedAndReceived");
9505 else if (CHECK_FLAG(p->cap,
9506 PEER_CAP_ENHE_ADV))
9507 json_object_string_add(
9508 json_cap,
9509 "extendedNexthop",
9510 "advertised");
9511 else if (CHECK_FLAG(p->cap,
9512 PEER_CAP_ENHE_RCV))
9513 json_object_string_add(
9514 json_cap,
9515 "extendedNexthop",
9516 "received");
9517
9518 if (CHECK_FLAG(p->cap,
9519 PEER_CAP_ENHE_RCV)) {
9520 json_nxt =
9521 json_object_new_object();
9522
9523 for (safi = SAFI_UNICAST;
9524 safi < SAFI_MAX; safi++) {
9525 if (CHECK_FLAG(
9526 p->af_cap
9527 [AFI_IP]
9528 [safi],
9529 PEER_CAP_ENHE_AF_RCV)) {
9530 print_store = afi_safi_print(
9531 AFI_IP,
9532 safi);
9533 json_object_string_add(
9534 json_nxt,
9535 print_store,
9536 "recieved");
9537 }
9538 }
9539 json_object_object_add(
9540 json_cap,
9541 "extendedNexthopFamililesByPeer",
9542 json_nxt);
9543 }
9544 }
9545
9546 /* Route Refresh */
9547 if (CHECK_FLAG(p->cap, PEER_CAP_REFRESH_ADV)
9548 || CHECK_FLAG(p->cap,
9549 PEER_CAP_REFRESH_NEW_RCV)
9550 || CHECK_FLAG(p->cap,
9551 PEER_CAP_REFRESH_OLD_RCV)) {
9552 if (CHECK_FLAG(p->cap,
9553 PEER_CAP_REFRESH_ADV)
9554 && (CHECK_FLAG(
9555 p->cap,
9556 PEER_CAP_REFRESH_NEW_RCV)
9557 || CHECK_FLAG(
9558 p->cap,
9559 PEER_CAP_REFRESH_OLD_RCV))) {
9560 if (CHECK_FLAG(
9561 p->cap,
9562 PEER_CAP_REFRESH_OLD_RCV)
9563 && CHECK_FLAG(
9564 p->cap,
9565 PEER_CAP_REFRESH_NEW_RCV))
9566 json_object_string_add(
9567 json_cap,
9568 "routeRefresh",
9569 "advertisedAndReceivedOldNew");
9570 else {
9571 if (CHECK_FLAG(
9572 p->cap,
9573 PEER_CAP_REFRESH_OLD_RCV))
9574 json_object_string_add(
9575 json_cap,
9576 "routeRefresh",
9577 "advertisedAndReceivedOld");
9578 else
9579 json_object_string_add(
9580 json_cap,
9581 "routeRefresh",
9582 "advertisedAndReceivedNew");
9583 }
9584 } else if (
9585 CHECK_FLAG(
9586 p->cap,
9587 PEER_CAP_REFRESH_ADV))
9588 json_object_string_add(
9589 json_cap,
9590 "routeRefresh",
9591 "advertised");
9592 else if (
9593 CHECK_FLAG(
9594 p->cap,
9595 PEER_CAP_REFRESH_NEW_RCV)
9596 || CHECK_FLAG(
9597 p->cap,
9598 PEER_CAP_REFRESH_OLD_RCV))
9599 json_object_string_add(
9600 json_cap,
9601 "routeRefresh",
9602 "received");
9603 }
9604
9605 /* Multiprotocol Extensions */
9606 json_object *json_multi = NULL;
9607 json_multi = json_object_new_object();
9608
9609 FOREACH_AFI_SAFI (afi, safi) {
9610 if (p->afc_adv[afi][safi]
9611 || p->afc_recv[afi][safi]) {
9612 json_object *json_exten = NULL;
9613 json_exten =
9614 json_object_new_object();
9615
9616 if (p->afc_adv[afi][safi]
9617 && p->afc_recv[afi][safi])
9618 json_object_boolean_true_add(
9619 json_exten,
9620 "advertisedAndReceived");
9621 else if (p->afc_adv[afi][safi])
9622 json_object_boolean_true_add(
9623 json_exten,
9624 "advertised");
9625 else if (p->afc_recv[afi][safi])
9626 json_object_boolean_true_add(
9627 json_exten,
9628 "received");
9629
9630 json_object_object_add(
9631 json_multi,
9632 afi_safi_print(afi,
9633 safi),
9634 json_exten);
9635 }
9636 }
9637 json_object_object_add(
9638 json_cap, "multiprotocolExtensions",
9639 json_multi);
9640
9641 /* Hostname capabilities */
9642 json_object *json_hname = NULL;
9643
9644 json_hname = json_object_new_object();
9645
9646 if (CHECK_FLAG(p->cap, PEER_CAP_HOSTNAME_ADV)) {
9647 json_object_string_add(
9648 json_hname, "advHostName",
9649 bgp->peer_self->hostname
9650 ? bgp->peer_self
9651 ->hostname
9652 : "n/a");
9653 json_object_string_add(
9654 json_hname, "advDomainName",
9655 bgp->peer_self->domainname
9656 ? bgp->peer_self
9657 ->domainname
9658 : "n/a");
9659 }
9660
9661
9662 if (CHECK_FLAG(p->cap, PEER_CAP_HOSTNAME_RCV)) {
9663 json_object_string_add(
9664 json_hname, "rcvHostName",
9665 p->hostname ? p->hostname
9666 : "n/a");
9667 json_object_string_add(
9668 json_hname, "rcvDomainName",
9669 p->domainname ? p->domainname
9670 : "n/a");
9671 }
9672
9673 json_object_object_add(json_cap, "hostName",
9674 json_hname);
9675
9676 /* Gracefull Restart */
9677 if (CHECK_FLAG(p->cap, PEER_CAP_RESTART_RCV)
9678 || CHECK_FLAG(p->cap,
9679 PEER_CAP_RESTART_ADV)) {
9680 if (CHECK_FLAG(p->cap,
9681 PEER_CAP_RESTART_ADV)
9682 && CHECK_FLAG(p->cap,
9683 PEER_CAP_RESTART_RCV))
9684 json_object_string_add(
9685 json_cap,
9686 "gracefulRestart",
9687 "advertisedAndReceived");
9688 else if (CHECK_FLAG(
9689 p->cap,
9690 PEER_CAP_RESTART_ADV))
9691 json_object_string_add(
9692 json_cap,
9693 "gracefulRestartCapability",
9694 "advertised");
9695 else if (CHECK_FLAG(
9696 p->cap,
9697 PEER_CAP_RESTART_RCV))
9698 json_object_string_add(
9699 json_cap,
9700 "gracefulRestartCapability",
9701 "received");
9702
9703 if (CHECK_FLAG(p->cap,
9704 PEER_CAP_RESTART_RCV)) {
9705 int restart_af_count = 0;
9706 json_object *json_restart =
9707 NULL;
9708 json_restart =
9709 json_object_new_object();
9710
9711 json_object_int_add(
9712 json_cap,
9713 "gracefulRestartRemoteTimerMsecs",
9714 p->v_gr_restart * 1000);
9715
9716 FOREACH_AFI_SAFI (afi, safi) {
9717 if (CHECK_FLAG(
9718 p->af_cap
9719 [afi]
9720 [safi],
9721 PEER_CAP_RESTART_AF_RCV)) {
9722 json_object *
9723 json_sub =
9724 NULL;
9725 json_sub =
9726 json_object_new_object();
9727
9728 if (CHECK_FLAG(
9729 p->af_cap
9730 [afi]
9731 [safi],
9732 PEER_CAP_RESTART_AF_PRESERVE_RCV))
9733 json_object_boolean_true_add(
9734 json_sub,
9735 "preserved");
9736 restart_af_count++;
9737 json_object_object_add(
9738 json_restart,
9739 afi_safi_print(
9740 afi,
9741 safi),
9742 json_sub);
9743 }
9744 }
9745 if (!restart_af_count) {
9746 json_object_string_add(
9747 json_cap,
9748 "addressFamiliesByPeer",
9749 "none");
9750 json_object_free(
9751 json_restart);
9752 } else
9753 json_object_object_add(
9754 json_cap,
9755 "addressFamiliesByPeer",
9756 json_restart);
9757 }
9758 }
9759 json_object_object_add(json_neigh,
9760 "neighborCapabilities",
9761 json_cap);
9762 } else {
9763 vty_out(vty, " Neighbor capabilities:\n");
9764
9765 /* AS4 */
9766 if (CHECK_FLAG(p->cap, PEER_CAP_AS4_RCV)
9767 || CHECK_FLAG(p->cap, PEER_CAP_AS4_ADV)) {
9768 vty_out(vty, " 4 Byte AS:");
9769 if (CHECK_FLAG(p->cap,
9770 PEER_CAP_AS4_ADV))
9771 vty_out(vty, " advertised");
9772 if (CHECK_FLAG(p->cap,
9773 PEER_CAP_AS4_RCV))
9774 vty_out(vty, " %sreceived",
9775 CHECK_FLAG(
9776 p->cap,
9777 PEER_CAP_AS4_ADV)
9778 ? "and "
9779 : "");
9780 vty_out(vty, "\n");
9781 }
9782
9783 /* AddPath */
9784 if (CHECK_FLAG(p->cap, PEER_CAP_ADDPATH_RCV)
9785 || CHECK_FLAG(p->cap,
9786 PEER_CAP_ADDPATH_ADV)) {
9787 vty_out(vty, " AddPath:\n");
9788
9789 FOREACH_AFI_SAFI (afi, safi) {
9790 if (CHECK_FLAG(
9791 p->af_cap[afi]
9792 [safi],
9793 PEER_CAP_ADDPATH_AF_TX_ADV)
9794 || CHECK_FLAG(
9795 p->af_cap[afi]
9796 [safi],
9797 PEER_CAP_ADDPATH_AF_TX_RCV)) {
9798 vty_out(vty,
9799 " %s: TX ",
9800 afi_safi_print(
9801 afi,
9802 safi));
9803
9804 if (CHECK_FLAG(
9805 p->af_cap
9806 [afi]
9807 [safi],
9808 PEER_CAP_ADDPATH_AF_TX_ADV))
9809 vty_out(vty,
9810 "advertised %s",
9811 afi_safi_print(
9812 afi,
9813 safi));
9814
9815 if (CHECK_FLAG(
9816 p->af_cap
9817 [afi]
9818 [safi],
9819 PEER_CAP_ADDPATH_AF_TX_RCV))
9820 vty_out(vty,
9821 "%sreceived",
9822 CHECK_FLAG(
9823 p->af_cap
9824 [afi]
9825 [safi],
9826 PEER_CAP_ADDPATH_AF_TX_ADV)
9827 ? " and "
9828 : "");
9829
9830 vty_out(vty, "\n");
9831 }
9832
9833 if (CHECK_FLAG(
9834 p->af_cap[afi]
9835 [safi],
9836 PEER_CAP_ADDPATH_AF_RX_ADV)
9837 || CHECK_FLAG(
9838 p->af_cap[afi]
9839 [safi],
9840 PEER_CAP_ADDPATH_AF_RX_RCV)) {
9841 vty_out(vty,
9842 " %s: RX ",
9843 afi_safi_print(
9844 afi,
9845 safi));
9846
9847 if (CHECK_FLAG(
9848 p->af_cap
9849 [afi]
9850 [safi],
9851 PEER_CAP_ADDPATH_AF_RX_ADV))
9852 vty_out(vty,
9853 "advertised %s",
9854 afi_safi_print(
9855 afi,
9856 safi));
9857
9858 if (CHECK_FLAG(
9859 p->af_cap
9860 [afi]
9861 [safi],
9862 PEER_CAP_ADDPATH_AF_RX_RCV))
9863 vty_out(vty,
9864 "%sreceived",
9865 CHECK_FLAG(
9866 p->af_cap
9867 [afi]
9868 [safi],
9869 PEER_CAP_ADDPATH_AF_RX_ADV)
9870 ? " and "
9871 : "");
9872
9873 vty_out(vty, "\n");
9874 }
9875 }
9876 }
9877
9878 /* Dynamic */
9879 if (CHECK_FLAG(p->cap, PEER_CAP_DYNAMIC_RCV)
9880 || CHECK_FLAG(p->cap,
9881 PEER_CAP_DYNAMIC_ADV)) {
9882 vty_out(vty, " Dynamic:");
9883 if (CHECK_FLAG(p->cap,
9884 PEER_CAP_DYNAMIC_ADV))
9885 vty_out(vty, " advertised");
9886 if (CHECK_FLAG(p->cap,
9887 PEER_CAP_DYNAMIC_RCV))
9888 vty_out(vty, " %sreceived",
9889 CHECK_FLAG(
9890 p->cap,
9891 PEER_CAP_DYNAMIC_ADV)
9892 ? "and "
9893 : "");
9894 vty_out(vty, "\n");
9895 }
9896
9897 /* Extended nexthop */
9898 if (CHECK_FLAG(p->cap, PEER_CAP_ENHE_RCV)
9899 || CHECK_FLAG(p->cap, PEER_CAP_ENHE_ADV)) {
9900 vty_out(vty, " Extended nexthop:");
9901 if (CHECK_FLAG(p->cap,
9902 PEER_CAP_ENHE_ADV))
9903 vty_out(vty, " advertised");
9904 if (CHECK_FLAG(p->cap,
9905 PEER_CAP_ENHE_RCV))
9906 vty_out(vty, " %sreceived",
9907 CHECK_FLAG(
9908 p->cap,
9909 PEER_CAP_ENHE_ADV)
9910 ? "and "
9911 : "");
9912 vty_out(vty, "\n");
9913
9914 if (CHECK_FLAG(p->cap,
9915 PEER_CAP_ENHE_RCV)) {
9916 vty_out(vty,
9917 " Address families by peer:\n ");
9918 for (safi = SAFI_UNICAST;
9919 safi < SAFI_MAX; safi++)
9920 if (CHECK_FLAG(
9921 p->af_cap
9922 [AFI_IP]
9923 [safi],
9924 PEER_CAP_ENHE_AF_RCV))
9925 vty_out(vty,
9926 " %s\n",
9927 afi_safi_print(
9928 AFI_IP,
9929 safi));
9930 }
9931 }
9932
9933 /* Route Refresh */
9934 if (CHECK_FLAG(p->cap, PEER_CAP_REFRESH_ADV)
9935 || CHECK_FLAG(p->cap,
9936 PEER_CAP_REFRESH_NEW_RCV)
9937 || CHECK_FLAG(p->cap,
9938 PEER_CAP_REFRESH_OLD_RCV)) {
9939 vty_out(vty, " Route refresh:");
9940 if (CHECK_FLAG(p->cap,
9941 PEER_CAP_REFRESH_ADV))
9942 vty_out(vty, " advertised");
9943 if (CHECK_FLAG(p->cap,
9944 PEER_CAP_REFRESH_NEW_RCV)
9945 || CHECK_FLAG(
9946 p->cap,
9947 PEER_CAP_REFRESH_OLD_RCV))
9948 vty_out(vty, " %sreceived(%s)",
9949 CHECK_FLAG(
9950 p->cap,
9951 PEER_CAP_REFRESH_ADV)
9952 ? "and "
9953 : "",
9954 (CHECK_FLAG(
9955 p->cap,
9956 PEER_CAP_REFRESH_OLD_RCV)
9957 && CHECK_FLAG(
9958 p->cap,
9959 PEER_CAP_REFRESH_NEW_RCV))
9960 ? "old & new"
9961 : CHECK_FLAG(
9962 p->cap,
9963 PEER_CAP_REFRESH_OLD_RCV)
9964 ? "old"
9965 : "new");
9966
9967 vty_out(vty, "\n");
9968 }
9969
9970 /* Multiprotocol Extensions */
9971 FOREACH_AFI_SAFI (afi, safi)
9972 if (p->afc_adv[afi][safi]
9973 || p->afc_recv[afi][safi]) {
9974 vty_out(vty,
9975 " Address Family %s:",
9976 afi_safi_print(afi,
9977 safi));
9978 if (p->afc_adv[afi][safi])
9979 vty_out(vty,
9980 " advertised");
9981 if (p->afc_recv[afi][safi])
9982 vty_out(vty,
9983 " %sreceived",
9984 p->afc_adv[afi]
9985 [safi]
9986 ? "and "
9987 : "");
9988 vty_out(vty, "\n");
9989 }
9990
9991 /* Hostname capability */
9992 vty_out(vty, " Hostname Capability:");
9993
9994 if (CHECK_FLAG(p->cap, PEER_CAP_HOSTNAME_ADV)) {
9995 vty_out(vty,
9996 " advertised (name: %s,domain name: %s)",
9997 bgp->peer_self->hostname
9998 ? bgp->peer_self
9999 ->hostname
10000 : "n/a",
10001 bgp->peer_self->domainname
10002 ? bgp->peer_self
10003 ->domainname
10004 : "n/a");
10005 } else {
10006 vty_out(vty, " not advertised");
10007 }
10008
10009 if (CHECK_FLAG(p->cap, PEER_CAP_HOSTNAME_RCV)) {
10010 vty_out(vty,
10011 " received (name: %s,domain name: %s)",
10012 p->hostname ? p->hostname
10013 : "n/a",
10014 p->domainname ? p->domainname
10015 : "n/a");
10016 } else {
10017 vty_out(vty, " not received");
10018 }
10019
10020 vty_out(vty, "\n");
10021
10022 /* Gracefull Restart */
10023 if (CHECK_FLAG(p->cap, PEER_CAP_RESTART_RCV)
10024 || CHECK_FLAG(p->cap,
10025 PEER_CAP_RESTART_ADV)) {
10026 vty_out(vty,
10027 " Graceful Restart Capabilty:");
10028 if (CHECK_FLAG(p->cap,
10029 PEER_CAP_RESTART_ADV))
10030 vty_out(vty, " advertised");
10031 if (CHECK_FLAG(p->cap,
10032 PEER_CAP_RESTART_RCV))
10033 vty_out(vty, " %sreceived",
10034 CHECK_FLAG(
10035 p->cap,
10036 PEER_CAP_RESTART_ADV)
10037 ? "and "
10038 : "");
10039 vty_out(vty, "\n");
10040
10041 if (CHECK_FLAG(p->cap,
10042 PEER_CAP_RESTART_RCV)) {
10043 int restart_af_count = 0;
10044
10045 vty_out(vty,
10046 " Remote Restart timer is %d seconds\n",
10047 p->v_gr_restart);
10048 vty_out(vty,
10049 " Address families by peer:\n ");
10050
10051 FOREACH_AFI_SAFI (afi, safi)
10052 if (CHECK_FLAG(
10053 p->af_cap
10054 [afi]
10055 [safi],
10056 PEER_CAP_RESTART_AF_RCV)) {
10057 vty_out(vty,
10058 "%s%s(%s)",
10059 restart_af_count
10060 ? ", "
10061 : "",
10062 afi_safi_print(
10063 afi,
10064 safi),
10065 CHECK_FLAG(
10066 p->af_cap
10067 [afi]
10068 [safi],
10069 PEER_CAP_RESTART_AF_PRESERVE_RCV)
10070 ? "preserved"
10071 : "not preserved");
10072 restart_af_count++;
10073 }
10074 if (!restart_af_count)
10075 vty_out(vty, "none");
10076 vty_out(vty, "\n");
10077 }
10078 }
10079 }
10080 }
10081 }
10082
10083 /* graceful restart information */
10084 if (CHECK_FLAG(p->cap, PEER_CAP_RESTART_RCV) || p->t_gr_restart
10085 || p->t_gr_stale) {
10086 json_object *json_grace = NULL;
10087 json_object *json_grace_send = NULL;
10088 json_object *json_grace_recv = NULL;
10089 int eor_send_af_count = 0;
10090 int eor_receive_af_count = 0;
10091
10092 if (use_json) {
10093 json_grace = json_object_new_object();
10094 json_grace_send = json_object_new_object();
10095 json_grace_recv = json_object_new_object();
10096
10097 if (p->status == Established) {
10098 FOREACH_AFI_SAFI (afi, safi) {
10099 if (CHECK_FLAG(p->af_sflags[afi][safi],
10100 PEER_STATUS_EOR_SEND)) {
10101 json_object_boolean_true_add(
10102 json_grace_send,
10103 afi_safi_print(afi,
10104 safi));
10105 eor_send_af_count++;
10106 }
10107 }
10108 FOREACH_AFI_SAFI (afi, safi) {
10109 if (CHECK_FLAG(
10110 p->af_sflags[afi][safi],
10111 PEER_STATUS_EOR_RECEIVED)) {
10112 json_object_boolean_true_add(
10113 json_grace_recv,
10114 afi_safi_print(afi,
10115 safi));
10116 eor_receive_af_count++;
10117 }
10118 }
10119 }
10120
10121 json_object_object_add(json_grace, "endOfRibSend",
10122 json_grace_send);
10123 json_object_object_add(json_grace, "endOfRibRecv",
10124 json_grace_recv);
10125
10126 if (p->t_gr_restart)
10127 json_object_int_add(json_grace,
10128 "gracefulRestartTimerMsecs",
10129 thread_timer_remain_second(
10130 p->t_gr_restart)
10131 * 1000);
10132
10133 if (p->t_gr_stale)
10134 json_object_int_add(
10135 json_grace,
10136 "gracefulStalepathTimerMsecs",
10137 thread_timer_remain_second(
10138 p->t_gr_stale)
10139 * 1000);
10140
10141 json_object_object_add(
10142 json_neigh, "gracefulRestartInfo", json_grace);
10143 } else {
10144 vty_out(vty, " Graceful restart informations:\n");
10145 if (p->status == Established) {
10146 vty_out(vty, " End-of-RIB send: ");
10147 FOREACH_AFI_SAFI (afi, safi) {
10148 if (CHECK_FLAG(p->af_sflags[afi][safi],
10149 PEER_STATUS_EOR_SEND)) {
10150 vty_out(vty, "%s%s",
10151 eor_send_af_count ? ", "
10152 : "",
10153 afi_safi_print(afi,
10154 safi));
10155 eor_send_af_count++;
10156 }
10157 }
10158 vty_out(vty, "\n");
10159 vty_out(vty, " End-of-RIB received: ");
10160 FOREACH_AFI_SAFI (afi, safi) {
10161 if (CHECK_FLAG(
10162 p->af_sflags[afi][safi],
10163 PEER_STATUS_EOR_RECEIVED)) {
10164 vty_out(vty, "%s%s",
10165 eor_receive_af_count
10166 ? ", "
10167 : "",
10168 afi_safi_print(afi,
10169 safi));
10170 eor_receive_af_count++;
10171 }
10172 }
10173 vty_out(vty, "\n");
10174 }
10175
10176 if (p->t_gr_restart)
10177 vty_out(vty,
10178 " The remaining time of restart timer is %ld\n",
10179 thread_timer_remain_second(
10180 p->t_gr_restart));
10181
10182 if (p->t_gr_stale)
10183 vty_out(vty,
10184 " The remaining time of stalepath timer is %ld\n",
10185 thread_timer_remain_second(
10186 p->t_gr_stale));
10187 }
10188 }
10189 if (use_json) {
10190 json_object *json_stat = NULL;
10191 json_stat = json_object_new_object();
10192 /* Packet counts. */
10193 json_object_int_add(json_stat, "depthInq", 0);
10194 json_object_int_add(json_stat, "depthOutq",
10195 (unsigned long)p->obuf->count);
10196 json_object_int_add(json_stat, "opensSent",
10197 atomic_load_explicit(&p->open_out,
10198 memory_order_relaxed));
10199 json_object_int_add(json_stat, "opensRecv",
10200 atomic_load_explicit(&p->open_in,
10201 memory_order_relaxed));
10202 json_object_int_add(json_stat, "notificationsSent",
10203 atomic_load_explicit(&p->notify_out,
10204 memory_order_relaxed));
10205 json_object_int_add(json_stat, "notificationsRecv",
10206 atomic_load_explicit(&p->notify_in,
10207 memory_order_relaxed));
10208 json_object_int_add(json_stat, "updatesSent",
10209 atomic_load_explicit(&p->update_out,
10210 memory_order_relaxed));
10211 json_object_int_add(json_stat, "updatesRecv",
10212 atomic_load_explicit(&p->update_in,
10213 memory_order_relaxed));
10214 json_object_int_add(json_stat, "keepalivesSent",
10215 atomic_load_explicit(&p->keepalive_out,
10216 memory_order_relaxed));
10217 json_object_int_add(json_stat, "keepalivesRecv",
10218 atomic_load_explicit(&p->keepalive_in,
10219 memory_order_relaxed));
10220 json_object_int_add(json_stat, "routeRefreshSent",
10221 atomic_load_explicit(&p->refresh_out,
10222 memory_order_relaxed));
10223 json_object_int_add(json_stat, "routeRefreshRecv",
10224 atomic_load_explicit(&p->refresh_in,
10225 memory_order_relaxed));
10226 json_object_int_add(json_stat, "capabilitySent",
10227 atomic_load_explicit(&p->dynamic_cap_out,
10228 memory_order_relaxed));
10229 json_object_int_add(json_stat, "capabilityRecv",
10230 atomic_load_explicit(&p->dynamic_cap_in,
10231 memory_order_relaxed));
10232 json_object_int_add(json_stat, "totalSent", PEER_TOTAL_TX(p));
10233 json_object_int_add(json_stat, "totalRecv", PEER_TOTAL_RX(p));
10234 json_object_object_add(json_neigh, "messageStats", json_stat);
10235 } else {
10236 /* Packet counts. */
10237 vty_out(vty, " Message statistics:\n");
10238 vty_out(vty, " Inq depth is 0\n");
10239 vty_out(vty, " Outq depth is %lu\n",
10240 (unsigned long)p->obuf->count);
10241 vty_out(vty, " Sent Rcvd\n");
10242 vty_out(vty, " Opens: %10d %10d\n",
10243 atomic_load_explicit(&p->open_out,
10244 memory_order_relaxed),
10245 atomic_load_explicit(&p->open_in,
10246 memory_order_relaxed));
10247 vty_out(vty, " Notifications: %10d %10d\n",
10248 atomic_load_explicit(&p->notify_out,
10249 memory_order_relaxed),
10250 atomic_load_explicit(&p->notify_in,
10251 memory_order_relaxed));
10252 vty_out(vty, " Updates: %10d %10d\n",
10253 atomic_load_explicit(&p->update_out,
10254 memory_order_relaxed),
10255 atomic_load_explicit(&p->update_in,
10256 memory_order_relaxed));
10257 vty_out(vty, " Keepalives: %10d %10d\n",
10258 atomic_load_explicit(&p->keepalive_out,
10259 memory_order_relaxed),
10260 atomic_load_explicit(&p->keepalive_in,
10261 memory_order_relaxed));
10262 vty_out(vty, " Route Refresh: %10d %10d\n",
10263 atomic_load_explicit(&p->refresh_out,
10264 memory_order_relaxed),
10265 atomic_load_explicit(&p->refresh_in,
10266 memory_order_relaxed));
10267 vty_out(vty, " Capability: %10d %10d\n",
10268 atomic_load_explicit(&p->dynamic_cap_out,
10269 memory_order_relaxed),
10270 atomic_load_explicit(&p->dynamic_cap_in,
10271 memory_order_relaxed));
10272 vty_out(vty, " Total: %10d %10d\n", PEER_TOTAL_TX(p),
10273 PEER_TOTAL_RX(p));
10274 }
10275
10276 if (use_json) {
10277 /* advertisement-interval */
10278 json_object_int_add(json_neigh,
10279 "minBtwnAdvertisementRunsTimerMsecs",
10280 p->v_routeadv * 1000);
10281
10282 /* Update-source. */
10283 if (p->update_if || p->update_source) {
10284 if (p->update_if)
10285 json_object_string_add(json_neigh,
10286 "updateSource",
10287 p->update_if);
10288 else if (p->update_source)
10289 json_object_string_add(
10290 json_neigh, "updateSource",
10291 sockunion2str(p->update_source, buf1,
10292 SU_ADDRSTRLEN));
10293 }
10294 } else {
10295 /* advertisement-interval */
10296 vty_out(vty,
10297 " Minimum time between advertisement runs is %d seconds\n",
10298 p->v_routeadv);
10299
10300 /* Update-source. */
10301 if (p->update_if || p->update_source) {
10302 vty_out(vty, " Update source is ");
10303 if (p->update_if)
10304 vty_out(vty, "%s", p->update_if);
10305 else if (p->update_source)
10306 vty_out(vty, "%s",
10307 sockunion2str(p->update_source, buf1,
10308 SU_ADDRSTRLEN));
10309 vty_out(vty, "\n");
10310 }
10311
10312 vty_out(vty, "\n");
10313 }
10314
10315 /* Address Family Information */
10316 json_object *json_hold = NULL;
10317
10318 if (use_json)
10319 json_hold = json_object_new_object();
10320
10321 FOREACH_AFI_SAFI (afi, safi)
10322 if (p->afc[afi][safi])
10323 bgp_show_peer_afi(vty, p, afi, safi, use_json,
10324 json_hold);
10325
10326 if (use_json) {
10327 json_object_object_add(json_neigh, "addressFamilyInfo",
10328 json_hold);
10329 json_object_int_add(json_neigh, "connectionsEstablished",
10330 p->established);
10331 json_object_int_add(json_neigh, "connectionsDropped",
10332 p->dropped);
10333 } else
10334 vty_out(vty, " Connections established %d; dropped %d\n",
10335 p->established, p->dropped);
10336
10337 if (!p->last_reset) {
10338 if (use_json)
10339 json_object_string_add(json_neigh, "lastReset",
10340 "never");
10341 else
10342 vty_out(vty, " Last reset never\n");
10343 } else {
10344 if (use_json) {
10345 time_t uptime;
10346 struct tm *tm;
10347
10348 uptime = bgp_clock();
10349 uptime -= p->resettime;
10350 tm = gmtime(&uptime);
10351 json_object_int_add(json_neigh, "lastResetTimerMsecs",
10352 (tm->tm_sec * 1000)
10353 + (tm->tm_min * 60000)
10354 + (tm->tm_hour * 3600000));
10355 json_object_string_add(
10356 json_neigh, "lastResetDueTo",
10357 peer_down_str[(int)p->last_reset]);
10358 if (p->last_reset == PEER_DOWN_NOTIFY_SEND
10359 || p->last_reset == PEER_DOWN_NOTIFY_RECEIVED) {
10360 char errorcodesubcode_hexstr[5];
10361 char errorcodesubcode_str[256];
10362
10363 code_str = bgp_notify_code_str(p->notify.code);
10364 subcode_str = bgp_notify_subcode_str(
10365 p->notify.code, p->notify.subcode);
10366
10367 sprintf(errorcodesubcode_hexstr, "%02X%02X",
10368 p->notify.code, p->notify.subcode);
10369 json_object_string_add(json_neigh,
10370 "lastErrorCodeSubcode",
10371 errorcodesubcode_hexstr);
10372 snprintf(errorcodesubcode_str, 255, "%s%s",
10373 code_str, subcode_str);
10374 json_object_string_add(json_neigh,
10375 "lastNotificationReason",
10376 errorcodesubcode_str);
10377 if (p->last_reset == PEER_DOWN_NOTIFY_RECEIVED
10378 && p->notify.code == BGP_NOTIFY_CEASE
10379 && (p->notify.subcode
10380 == BGP_NOTIFY_CEASE_ADMIN_SHUTDOWN
10381 || p->notify.subcode
10382 == BGP_NOTIFY_CEASE_ADMIN_RESET)
10383 && p->notify.length) {
10384 char msgbuf[1024];
10385 const char *msg_str;
10386
10387 msg_str = bgp_notify_admin_message(
10388 msgbuf, sizeof(msgbuf),
10389 (uint8_t *)p->notify.data,
10390 p->notify.length);
10391 if (msg_str)
10392 json_object_string_add(
10393 json_neigh,
10394 "lastShutdownDescription",
10395 msg_str);
10396 }
10397 }
10398 } else {
10399 vty_out(vty, " Last reset %s, ",
10400 peer_uptime(p->resettime, timebuf,
10401 BGP_UPTIME_LEN, 0, NULL));
10402
10403 if (p->last_reset == PEER_DOWN_NOTIFY_SEND
10404 || p->last_reset == PEER_DOWN_NOTIFY_RECEIVED) {
10405 code_str = bgp_notify_code_str(p->notify.code);
10406 subcode_str = bgp_notify_subcode_str(
10407 p->notify.code, p->notify.subcode);
10408 vty_out(vty, "due to NOTIFICATION %s (%s%s)\n",
10409 p->last_reset == PEER_DOWN_NOTIFY_SEND
10410 ? "sent"
10411 : "received",
10412 code_str, subcode_str);
10413 if (p->last_reset == PEER_DOWN_NOTIFY_RECEIVED
10414 && p->notify.code == BGP_NOTIFY_CEASE
10415 && (p->notify.subcode
10416 == BGP_NOTIFY_CEASE_ADMIN_SHUTDOWN
10417 || p->notify.subcode
10418 == BGP_NOTIFY_CEASE_ADMIN_RESET)
10419 && p->notify.length) {
10420 char msgbuf[1024];
10421 const char *msg_str;
10422
10423 msg_str = bgp_notify_admin_message(
10424 msgbuf, sizeof(msgbuf),
10425 (uint8_t *)p->notify.data,
10426 p->notify.length);
10427 if (msg_str)
10428 vty_out(vty,
10429 " Message: \"%s\"\n",
10430 msg_str);
10431 }
10432 } else {
10433 vty_out(vty, "due to %s\n",
10434 peer_down_str[(int)p->last_reset]);
10435 }
10436
10437 if (p->last_reset_cause_size) {
10438 msg = p->last_reset_cause;
10439 vty_out(vty,
10440 " Message received that caused BGP to send a NOTIFICATION:\n ");
10441 for (i = 1; i <= p->last_reset_cause_size;
10442 i++) {
10443 vty_out(vty, "%02X", *msg++);
10444
10445 if (i != p->last_reset_cause_size) {
10446 if (i % 16 == 0) {
10447 vty_out(vty, "\n ");
10448 } else if (i % 4 == 0) {
10449 vty_out(vty, " ");
10450 }
10451 }
10452 }
10453 vty_out(vty, "\n");
10454 }
10455 }
10456 }
10457
10458 if (CHECK_FLAG(p->sflags, PEER_STATUS_PREFIX_OVERFLOW)) {
10459 if (use_json)
10460 json_object_boolean_true_add(json_neigh,
10461 "prefixesConfigExceedMax");
10462 else
10463 vty_out(vty,
10464 " Peer had exceeded the max. no. of prefixes configured.\n");
10465
10466 if (p->t_pmax_restart) {
10467 if (use_json) {
10468 json_object_boolean_true_add(
10469 json_neigh, "reducePrefixNumFrom");
10470 json_object_int_add(json_neigh,
10471 "restartInTimerMsec",
10472 thread_timer_remain_second(
10473 p->t_pmax_restart)
10474 * 1000);
10475 } else
10476 vty_out(vty,
10477 " Reduce the no. of prefix from %s, will restart in %ld seconds\n",
10478 p->host, thread_timer_remain_second(
10479 p->t_pmax_restart));
10480 } else {
10481 if (use_json)
10482 json_object_boolean_true_add(
10483 json_neigh,
10484 "reducePrefixNumAndClearIpBgp");
10485 else
10486 vty_out(vty,
10487 " Reduce the no. of prefix and clear ip bgp %s to restore peering\n",
10488 p->host);
10489 }
10490 }
10491
10492 /* EBGP Multihop and GTSM */
10493 if (p->sort != BGP_PEER_IBGP) {
10494 if (use_json) {
10495 if (p->gtsm_hops > 0)
10496 json_object_int_add(json_neigh,
10497 "externalBgpNbrMaxHopsAway",
10498 p->gtsm_hops);
10499 else if (p->ttl > 1)
10500 json_object_int_add(json_neigh,
10501 "externalBgpNbrMaxHopsAway",
10502 p->ttl);
10503 } else {
10504 if (p->gtsm_hops > 0)
10505 vty_out(vty,
10506 " External BGP neighbor may be up to %d hops away.\n",
10507 p->gtsm_hops);
10508 else if (p->ttl > 1)
10509 vty_out(vty,
10510 " External BGP neighbor may be up to %d hops away.\n",
10511 p->ttl);
10512 }
10513 } else {
10514 if (p->gtsm_hops > 0) {
10515 if (use_json)
10516 json_object_int_add(json_neigh,
10517 "internalBgpNbrMaxHopsAway",
10518 p->gtsm_hops);
10519 else
10520 vty_out(vty,
10521 " Internal BGP neighbor may be up to %d hops away.\n",
10522 p->gtsm_hops);
10523 }
10524 }
10525
10526 /* Local address. */
10527 if (p->su_local) {
10528 if (use_json) {
10529 json_object_string_add(json_neigh, "hostLocal",
10530 sockunion2str(p->su_local, buf1,
10531 SU_ADDRSTRLEN));
10532 json_object_int_add(json_neigh, "portLocal",
10533 ntohs(p->su_local->sin.sin_port));
10534 } else
10535 vty_out(vty, "Local host: %s, Local port: %d\n",
10536 sockunion2str(p->su_local, buf1, SU_ADDRSTRLEN),
10537 ntohs(p->su_local->sin.sin_port));
10538 }
10539
10540 /* Remote address. */
10541 if (p->su_remote) {
10542 if (use_json) {
10543 json_object_string_add(json_neigh, "hostForeign",
10544 sockunion2str(p->su_remote, buf1,
10545 SU_ADDRSTRLEN));
10546 json_object_int_add(json_neigh, "portForeign",
10547 ntohs(p->su_remote->sin.sin_port));
10548 } else
10549 vty_out(vty, "Foreign host: %s, Foreign port: %d\n",
10550 sockunion2str(p->su_remote, buf1,
10551 SU_ADDRSTRLEN),
10552 ntohs(p->su_remote->sin.sin_port));
10553 }
10554
10555 /* Nexthop display. */
10556 if (p->su_local) {
10557 if (use_json) {
10558 json_object_string_add(json_neigh, "nexthop",
10559 inet_ntop(AF_INET,
10560 &p->nexthop.v4, buf1,
10561 sizeof(buf1)));
10562 json_object_string_add(json_neigh, "nexthopGlobal",
10563 inet_ntop(AF_INET6,
10564 &p->nexthop.v6_global,
10565 buf1, sizeof(buf1)));
10566 json_object_string_add(json_neigh, "nexthopLocal",
10567 inet_ntop(AF_INET6,
10568 &p->nexthop.v6_local,
10569 buf1, sizeof(buf1)));
10570 if (p->shared_network)
10571 json_object_string_add(json_neigh,
10572 "bgpConnection",
10573 "sharedNetwork");
10574 else
10575 json_object_string_add(json_neigh,
10576 "bgpConnection",
10577 "nonSharedNetwork");
10578 } else {
10579 vty_out(vty, "Nexthop: %s\n",
10580 inet_ntop(AF_INET, &p->nexthop.v4, buf1,
10581 sizeof(buf1)));
10582 vty_out(vty, "Nexthop global: %s\n",
10583 inet_ntop(AF_INET6, &p->nexthop.v6_global, buf1,
10584 sizeof(buf1)));
10585 vty_out(vty, "Nexthop local: %s\n",
10586 inet_ntop(AF_INET6, &p->nexthop.v6_local, buf1,
10587 sizeof(buf1)));
10588 vty_out(vty, "BGP connection: %s\n",
10589 p->shared_network ? "shared network"
10590 : "non shared network");
10591 }
10592 }
10593
10594 /* Timer information. */
10595 if (use_json) {
10596 json_object_int_add(json_neigh, "connectRetryTimer",
10597 p->v_connect);
10598 if (p->status == Established && p->rtt)
10599 json_object_int_add(json_neigh, "estimatedRttInMsecs",
10600 p->rtt);
10601 if (p->t_start)
10602 json_object_int_add(
10603 json_neigh, "nextStartTimerDueInMsecs",
10604 thread_timer_remain_second(p->t_start) * 1000);
10605 if (p->t_connect)
10606 json_object_int_add(
10607 json_neigh, "nextConnectTimerDueInMsecs",
10608 thread_timer_remain_second(p->t_connect)
10609 * 1000);
10610 if (p->t_routeadv) {
10611 json_object_int_add(json_neigh, "mraiInterval",
10612 p->v_routeadv);
10613 json_object_int_add(
10614 json_neigh, "mraiTimerExpireInMsecs",
10615 thread_timer_remain_second(p->t_routeadv)
10616 * 1000);
10617 }
10618 if (p->password)
10619 json_object_int_add(json_neigh, "authenticationEnabled",
10620 1);
10621
10622 if (p->t_read)
10623 json_object_string_add(json_neigh, "readThread", "on");
10624 else
10625 json_object_string_add(json_neigh, "readThread", "off");
10626
10627 if (CHECK_FLAG(p->thread_flags, PEER_THREAD_WRITES_ON))
10628 json_object_string_add(json_neigh, "writeThread", "on");
10629 else
10630 json_object_string_add(json_neigh, "writeThread",
10631 "off");
10632 } else {
10633 vty_out(vty, "BGP Connect Retry Timer in Seconds: %d\n",
10634 p->v_connect);
10635 if (p->status == Established && p->rtt)
10636 vty_out(vty, "Estimated round trip time: %d ms\n",
10637 p->rtt);
10638 if (p->t_start)
10639 vty_out(vty, "Next start timer due in %ld seconds\n",
10640 thread_timer_remain_second(p->t_start));
10641 if (p->t_connect)
10642 vty_out(vty, "Next connect timer due in %ld seconds\n",
10643 thread_timer_remain_second(p->t_connect));
10644 if (p->t_routeadv)
10645 vty_out(vty,
10646 "MRAI (interval %u) timer expires in %ld seconds\n",
10647 p->v_routeadv,
10648 thread_timer_remain_second(p->t_routeadv));
10649 if (p->password)
10650 vty_out(vty, "Peer Authentication Enabled\n");
10651
10652 vty_out(vty, "Read thread: %s Write thread: %s\n",
10653 p->t_read ? "on" : "off",
10654 CHECK_FLAG(p->thread_flags, PEER_THREAD_WRITES_ON)
10655 ? "on"
10656 : "off");
10657 }
10658
10659 if (p->notify.code == BGP_NOTIFY_OPEN_ERR
10660 && p->notify.subcode == BGP_NOTIFY_OPEN_UNSUP_CAPBL)
10661 bgp_capability_vty_out(vty, p, use_json, json_neigh);
10662
10663 if (!use_json)
10664 vty_out(vty, "\n");
10665
10666 /* BFD information. */
10667 bgp_bfd_show_info(vty, p, use_json, json_neigh);
10668
10669 if (use_json) {
10670 if (p->conf_if) /* Configured interface name. */
10671 json_object_object_add(json, p->conf_if, json_neigh);
10672 else /* Configured IP address. */
10673 json_object_object_add(json, p->host, json_neigh);
10674 }
10675 }
10676
10677 static int bgp_show_neighbor(struct vty *vty, struct bgp *bgp,
10678 enum show_type type, union sockunion *su,
10679 const char *conf_if, uint8_t use_json,
10680 json_object *json)
10681 {
10682 struct listnode *node, *nnode;
10683 struct peer *peer;
10684 int find = 0;
10685
10686 for (ALL_LIST_ELEMENTS(bgp->peer, node, nnode, peer)) {
10687 if (!CHECK_FLAG(peer->flags, PEER_FLAG_CONFIG_NODE))
10688 continue;
10689
10690 switch (type) {
10691 case show_all:
10692 bgp_show_peer(vty, peer, use_json, json);
10693 break;
10694 case show_peer:
10695 if (conf_if) {
10696 if ((peer->conf_if
10697 && !strcmp(peer->conf_if, conf_if))
10698 || (peer->hostname
10699 && !strcmp(peer->hostname, conf_if))) {
10700 find = 1;
10701 bgp_show_peer(vty, peer, use_json,
10702 json);
10703 }
10704 } else {
10705 if (sockunion_same(&peer->su, su)) {
10706 find = 1;
10707 bgp_show_peer(vty, peer, use_json,
10708 json);
10709 }
10710 }
10711 break;
10712 }
10713 }
10714
10715 if (type == show_peer && !find) {
10716 if (use_json)
10717 json_object_boolean_true_add(json, "bgpNoSuchNeighbor");
10718 else
10719 vty_out(vty, "%% No such neighbor in this view/vrf\n");
10720 }
10721
10722 if (use_json) {
10723 vty_out(vty, "%s\n", json_object_to_json_string_ext(
10724 json, JSON_C_TO_STRING_PRETTY));
10725 json_object_free(json);
10726 } else {
10727 vty_out(vty, "\n");
10728 }
10729
10730 return CMD_SUCCESS;
10731 }
10732
10733 static void bgp_show_all_instances_neighbors_vty(struct vty *vty,
10734 enum show_type type,
10735 const char *ip_str,
10736 uint8_t use_json)
10737 {
10738 struct listnode *node, *nnode;
10739 struct bgp *bgp;
10740 union sockunion su;
10741 json_object *json = NULL;
10742 int ret, is_first = 1;
10743
10744 if (use_json)
10745 vty_out(vty, "{\n");
10746
10747 for (ALL_LIST_ELEMENTS(bm->bgp, node, nnode, bgp)) {
10748 if (use_json) {
10749 if (!(json = json_object_new_object())) {
10750 zlog_err(
10751 "Unable to allocate memory for JSON object");
10752 vty_out(vty,
10753 "{\"error\": {\"message:\": \"Unable to allocate memory for JSON object\"}}}\n");
10754 return;
10755 }
10756
10757 json_object_int_add(json, "vrfId",
10758 (bgp->vrf_id == VRF_UNKNOWN)
10759 ? -1
10760 : (int64_t)bgp->vrf_id);
10761 json_object_string_add(
10762 json, "vrfName",
10763 (bgp->inst_type == BGP_INSTANCE_TYPE_DEFAULT)
10764 ? "Default"
10765 : bgp->name);
10766
10767 if (!is_first)
10768 vty_out(vty, ",\n");
10769 else
10770 is_first = 0;
10771
10772 vty_out(vty, "\"%s\":",
10773 (bgp->inst_type == BGP_INSTANCE_TYPE_DEFAULT)
10774 ? "Default"
10775 : bgp->name);
10776 } else {
10777 vty_out(vty, "\nInstance %s:\n",
10778 (bgp->inst_type == BGP_INSTANCE_TYPE_DEFAULT)
10779 ? "Default"
10780 : bgp->name);
10781 }
10782
10783 if (type == show_peer) {
10784 ret = str2sockunion(ip_str, &su);
10785 if (ret < 0)
10786 bgp_show_neighbor(vty, bgp, type, NULL, ip_str,
10787 use_json, json);
10788 else
10789 bgp_show_neighbor(vty, bgp, type, &su, NULL,
10790 use_json, json);
10791 } else {
10792 bgp_show_neighbor(vty, bgp, show_all, NULL, NULL,
10793 use_json, json);
10794 }
10795 }
10796
10797 if (use_json)
10798 vty_out(vty, "}\n");
10799 }
10800
10801 static int bgp_show_neighbor_vty(struct vty *vty, const char *name,
10802 enum show_type type, const char *ip_str,
10803 uint8_t use_json)
10804 {
10805 int ret;
10806 struct bgp *bgp;
10807 union sockunion su;
10808 json_object *json = NULL;
10809
10810 if (name) {
10811 if (strmatch(name, "all")) {
10812 bgp_show_all_instances_neighbors_vty(vty, type, ip_str,
10813 use_json);
10814 return CMD_SUCCESS;
10815 } else {
10816 bgp = bgp_lookup_by_name(name);
10817 if (!bgp) {
10818 if (use_json) {
10819 json = json_object_new_object();
10820 json_object_boolean_true_add(
10821 json, "bgpNoSuchInstance");
10822 vty_out(vty, "%s\n",
10823 json_object_to_json_string_ext(
10824 json,
10825 JSON_C_TO_STRING_PRETTY));
10826 json_object_free(json);
10827 } else
10828 vty_out(vty,
10829 "%% No such BGP instance exist\n");
10830
10831 return CMD_WARNING;
10832 }
10833 }
10834 } else {
10835 bgp = bgp_get_default();
10836 }
10837
10838 if (bgp) {
10839 json = json_object_new_object();
10840 if (ip_str) {
10841 ret = str2sockunion(ip_str, &su);
10842 if (ret < 0)
10843 bgp_show_neighbor(vty, bgp, type, NULL, ip_str,
10844 use_json, json);
10845 else
10846 bgp_show_neighbor(vty, bgp, type, &su, NULL,
10847 use_json, json);
10848 } else {
10849 bgp_show_neighbor(vty, bgp, type, NULL, NULL, use_json,
10850 json);
10851 }
10852 json_object_free(json);
10853 }
10854
10855 return CMD_SUCCESS;
10856 }
10857
10858 /* "show [ip] bgp neighbors" commands. */
10859 DEFUN (show_ip_bgp_neighbors,
10860 show_ip_bgp_neighbors_cmd,
10861 "show [ip] bgp [<view|vrf> VIEWVRFNAME] [<ipv4|ipv6>] neighbors [<A.B.C.D|X:X::X:X|WORD>] [json]",
10862 SHOW_STR
10863 IP_STR
10864 BGP_STR
10865 BGP_INSTANCE_HELP_STR
10866 "Address Family\n"
10867 "Address Family\n"
10868 "Detailed information on TCP and BGP neighbor connections\n"
10869 "Neighbor to display information about\n"
10870 "Neighbor to display information about\n"
10871 "Neighbor on BGP configured interface\n"
10872 JSON_STR)
10873 {
10874 char *vrf = NULL;
10875 char *sh_arg = NULL;
10876 enum show_type sh_type;
10877
10878 uint8_t uj = use_json(argc, argv);
10879
10880 int idx = 0;
10881
10882 if (argv_find(argv, argc, "view", &idx)
10883 || argv_find(argv, argc, "vrf", &idx))
10884 vrf = argv[idx + 1]->arg;
10885
10886 idx++;
10887 if (argv_find(argv, argc, "A.B.C.D", &idx)
10888 || argv_find(argv, argc, "X:X::X:X", &idx)
10889 || argv_find(argv, argc, "WORD", &idx)) {
10890 sh_type = show_peer;
10891 sh_arg = argv[idx]->arg;
10892 } else
10893 sh_type = show_all;
10894
10895 return bgp_show_neighbor_vty(vty, vrf, sh_type, sh_arg, uj);
10896 }
10897
10898 /* Show BGP's AS paths internal data. There are both `show [ip] bgp
10899 paths' and `show ip mbgp paths'. Those functions results are the
10900 same.*/
10901 DEFUN (show_ip_bgp_paths,
10902 show_ip_bgp_paths_cmd,
10903 "show [ip] bgp ["BGP_SAFI_CMD_STR"] paths",
10904 SHOW_STR
10905 IP_STR
10906 BGP_STR
10907 BGP_SAFI_HELP_STR
10908 "Path information\n")
10909 {
10910 vty_out(vty, "Address Refcnt Path\n");
10911 aspath_print_all_vty(vty);
10912 return CMD_SUCCESS;
10913 }
10914
10915 #include "hash.h"
10916
10917 static void community_show_all_iterator(struct hash_backet *backet,
10918 struct vty *vty)
10919 {
10920 struct community *com;
10921
10922 com = (struct community *)backet->data;
10923 vty_out(vty, "[%p] (%ld) %s\n", (void *)com, com->refcnt,
10924 community_str(com, false));
10925 }
10926
10927 /* Show BGP's community internal data. */
10928 DEFUN (show_ip_bgp_community_info,
10929 show_ip_bgp_community_info_cmd,
10930 "show [ip] bgp community-info",
10931 SHOW_STR
10932 IP_STR
10933 BGP_STR
10934 "List all bgp community information\n")
10935 {
10936 vty_out(vty, "Address Refcnt Community\n");
10937
10938 hash_iterate(community_hash(),
10939 (void (*)(struct hash_backet *,
10940 void *))community_show_all_iterator,
10941 vty);
10942
10943 return CMD_SUCCESS;
10944 }
10945
10946 static void lcommunity_show_all_iterator(struct hash_backet *backet,
10947 struct vty *vty)
10948 {
10949 struct lcommunity *lcom;
10950
10951 lcom = (struct lcommunity *)backet->data;
10952 vty_out(vty, "[%p] (%ld) %s\n", (void *)lcom, lcom->refcnt,
10953 lcommunity_str(lcom, false));
10954 }
10955
10956 /* Show BGP's community internal data. */
10957 DEFUN (show_ip_bgp_lcommunity_info,
10958 show_ip_bgp_lcommunity_info_cmd,
10959 "show ip bgp large-community-info",
10960 SHOW_STR
10961 IP_STR
10962 BGP_STR
10963 "List all bgp large-community information\n")
10964 {
10965 vty_out(vty, "Address Refcnt Large-community\n");
10966
10967 hash_iterate(lcommunity_hash(),
10968 (void (*)(struct hash_backet *,
10969 void *))lcommunity_show_all_iterator,
10970 vty);
10971
10972 return CMD_SUCCESS;
10973 }
10974
10975
10976 DEFUN (show_ip_bgp_attr_info,
10977 show_ip_bgp_attr_info_cmd,
10978 "show [ip] bgp attribute-info",
10979 SHOW_STR
10980 IP_STR
10981 BGP_STR
10982 "List all bgp attribute information\n")
10983 {
10984 attr_show_all(vty);
10985 return CMD_SUCCESS;
10986 }
10987
10988 static int bgp_show_route_leak_vty(struct vty *vty, const char *name,
10989 afi_t afi, safi_t safi)
10990 {
10991 struct bgp *bgp;
10992 struct listnode *node;
10993 char *vname;
10994 char buf1[INET6_ADDRSTRLEN];
10995 char *ecom_str;
10996 vpn_policy_direction_t dir;
10997
10998 if (name) {
10999 bgp = bgp_lookup_by_name(name);
11000 if (!bgp) {
11001 vty_out(vty, "%% No such BGP instance exist\n");
11002 return CMD_WARNING;
11003 }
11004 } else {
11005 bgp = bgp_get_default();
11006 if (!bgp) {
11007 vty_out(vty,
11008 "%% Default BGP instance does not exist\n");
11009 return CMD_WARNING;
11010 }
11011 }
11012
11013 if (!CHECK_FLAG(bgp->af_flags[afi][safi],
11014 BGP_CONFIG_VRF_TO_VRF_IMPORT)) {
11015 vty_out(vty,
11016 "This VRF is not importing %s routes from any other VRF\n",
11017 afi_safi_print(afi, safi));
11018 } else {
11019 vty_out(vty,
11020 "This VRF is importing %s routes from the following VRFs:\n",
11021 afi_safi_print(afi, safi));
11022 for (ALL_LIST_ELEMENTS_RO(bgp->vpn_policy[afi].import_vrf, node,
11023 vname)) {
11024 vty_out(vty, " %s\n", vname);
11025 }
11026 dir = BGP_VPN_POLICY_DIR_FROMVPN;
11027 ecom_str = ecommunity_ecom2str(
11028 bgp->vpn_policy[afi].rtlist[dir],
11029 ECOMMUNITY_FORMAT_ROUTE_MAP, 0);
11030 vty_out(vty, "Import RT(s): %s\n", ecom_str);
11031 XFREE(MTYPE_ECOMMUNITY_STR, ecom_str);
11032 }
11033
11034 if (!CHECK_FLAG(bgp->af_flags[afi][safi],
11035 BGP_CONFIG_VRF_TO_VRF_EXPORT)) {
11036 vty_out(vty,
11037 "This VRF is not exporting %s routes to any other VRF\n",
11038 afi_safi_print(afi, safi));
11039 } else {
11040 vty_out(vty,
11041 "This VRF is exporting %s routes to the following VRFs:\n",
11042 afi_safi_print(afi, safi));
11043 for (ALL_LIST_ELEMENTS_RO(bgp->vpn_policy[afi].export_vrf, node,
11044 vname)) {
11045 vty_out(vty, " %s\n", vname);
11046 }
11047 vty_out(vty, "RD: %s\n",
11048 prefix_rd2str(&bgp->vpn_policy[afi].tovpn_rd,
11049 buf1, RD_ADDRSTRLEN));
11050 dir = BGP_VPN_POLICY_DIR_TOVPN;
11051 ecom_str = ecommunity_ecom2str(
11052 bgp->vpn_policy[afi].rtlist[dir],
11053 ECOMMUNITY_FORMAT_ROUTE_MAP, 0);
11054 vty_out(vty, "Emport RT: %s\n", ecom_str);
11055 XFREE(MTYPE_ECOMMUNITY_STR, ecom_str);
11056 }
11057
11058 return CMD_SUCCESS;
11059 }
11060
11061 /* "show [ip] bgp route-leak" command. */
11062 DEFUN (show_ip_bgp_route_leak,
11063 show_ip_bgp_route_leak_cmd,
11064 "show [ip] bgp [<view|vrf> VIEWVRFNAME] ["BGP_AFI_CMD_STR" ["BGP_SAFI_CMD_STR"]] route-leak",
11065 SHOW_STR
11066 IP_STR
11067 BGP_STR
11068 BGP_INSTANCE_HELP_STR
11069 BGP_AFI_HELP_STR
11070 BGP_SAFI_HELP_STR
11071 "Route leaking information\n")
11072 {
11073 char *vrf = NULL;
11074 afi_t afi = AFI_MAX;
11075 safi_t safi = SAFI_MAX;
11076
11077 int idx = 0;
11078
11079 /* show [ip] bgp */
11080 if (argv_find(argv, argc, "ip", &idx)) {
11081 afi = AFI_IP;
11082 safi = SAFI_UNICAST;
11083 }
11084 /* [vrf VIEWVRFNAME] */
11085 if (argv_find(argv, argc, "view", &idx)) {
11086 vty_out(vty,
11087 "%% This command is not applicable to BGP views\n");
11088 return CMD_WARNING;
11089 }
11090
11091 if (argv_find(argv, argc, "vrf", &idx))
11092 vrf = argv[++idx]->arg;
11093 /* ["BGP_AFI_CMD_STR" ["BGP_SAFI_CMD_STR"]] */
11094 if (argv_find_and_parse_afi(argv, argc, &idx, &afi)) {
11095 argv_find_and_parse_safi(argv, argc, &idx, &safi);
11096 }
11097
11098 if (!((afi == AFI_IP || afi == AFI_IP6) && safi == SAFI_UNICAST)) {
11099 vty_out(vty,
11100 "%% This command is applicable only for unicast ipv4|ipv6\n");
11101 return CMD_WARNING;
11102 }
11103
11104 return bgp_show_route_leak_vty(vty, vrf, afi, safi);
11105 }
11106
11107 static void bgp_show_all_instances_updgrps_vty(struct vty *vty, afi_t afi,
11108 safi_t safi)
11109 {
11110 struct listnode *node, *nnode;
11111 struct bgp *bgp;
11112
11113 for (ALL_LIST_ELEMENTS(bm->bgp, node, nnode, bgp)) {
11114 vty_out(vty, "\nInstance %s:\n",
11115 (bgp->inst_type == BGP_INSTANCE_TYPE_DEFAULT)
11116 ? "Default"
11117 : bgp->name);
11118 update_group_show(bgp, afi, safi, vty, 0);
11119 }
11120 }
11121
11122 static int bgp_show_update_groups(struct vty *vty, const char *name, int afi,
11123 int safi, uint64_t subgrp_id)
11124 {
11125 struct bgp *bgp;
11126
11127 if (name) {
11128 if (strmatch(name, "all")) {
11129 bgp_show_all_instances_updgrps_vty(vty, afi, safi);
11130 return CMD_SUCCESS;
11131 } else {
11132 bgp = bgp_lookup_by_name(name);
11133 }
11134 } else {
11135 bgp = bgp_get_default();
11136 }
11137
11138 if (bgp)
11139 update_group_show(bgp, afi, safi, vty, subgrp_id);
11140 return CMD_SUCCESS;
11141 }
11142
11143 DEFUN (show_ip_bgp_updgrps,
11144 show_ip_bgp_updgrps_cmd,
11145 "show [ip] bgp [<view|vrf> VIEWVRFNAME] ["BGP_AFI_CMD_STR" ["BGP_SAFI_WITH_LABEL_CMD_STR"]] update-groups [SUBGROUP-ID]",
11146 SHOW_STR
11147 IP_STR
11148 BGP_STR
11149 BGP_INSTANCE_HELP_STR
11150 BGP_AFI_HELP_STR
11151 BGP_SAFI_WITH_LABEL_HELP_STR
11152 "Detailed info about dynamic update groups\n"
11153 "Specific subgroup to display detailed info for\n")
11154 {
11155 char *vrf = NULL;
11156 afi_t afi = AFI_IP6;
11157 safi_t safi = SAFI_UNICAST;
11158 uint64_t subgrp_id = 0;
11159
11160 int idx = 0;
11161
11162 /* show [ip] bgp */
11163 if (argv_find(argv, argc, "ip", &idx))
11164 afi = AFI_IP;
11165 /* [<view|vrf> VIEWVRFNAME] */
11166 if (argv_find(argv, argc, "view", &idx)
11167 || argv_find(argv, argc, "vrf", &idx))
11168 vrf = argv[++idx]->arg;
11169 /* ["BGP_AFI_CMD_STR" ["BGP_SAFI_CMD_STR"]] */
11170 if (argv_find_and_parse_afi(argv, argc, &idx, &afi)) {
11171 argv_find_and_parse_safi(argv, argc, &idx, &safi);
11172 }
11173
11174 /* get subgroup id, if provided */
11175 idx = argc - 1;
11176 if (argv[idx]->type == VARIABLE_TKN)
11177 subgrp_id = strtoull(argv[idx]->arg, NULL, 10);
11178
11179 return (bgp_show_update_groups(vty, vrf, afi, safi, subgrp_id));
11180 }
11181
11182 DEFUN (show_bgp_instance_all_ipv6_updgrps,
11183 show_bgp_instance_all_ipv6_updgrps_cmd,
11184 "show [ip] bgp <view|vrf> all update-groups",
11185 SHOW_STR
11186 IP_STR
11187 BGP_STR
11188 BGP_INSTANCE_ALL_HELP_STR
11189 "Detailed info about dynamic update groups\n")
11190 {
11191 bgp_show_all_instances_updgrps_vty(vty, AFI_IP6, SAFI_UNICAST);
11192 return CMD_SUCCESS;
11193 }
11194
11195 DEFUN (show_bgp_updgrps_stats,
11196 show_bgp_updgrps_stats_cmd,
11197 "show [ip] bgp update-groups statistics",
11198 SHOW_STR
11199 IP_STR
11200 BGP_STR
11201 "Detailed info about dynamic update groups\n"
11202 "Statistics\n")
11203 {
11204 struct bgp *bgp;
11205
11206 bgp = bgp_get_default();
11207 if (bgp)
11208 update_group_show_stats(bgp, vty);
11209
11210 return CMD_SUCCESS;
11211 }
11212
11213 DEFUN (show_bgp_instance_updgrps_stats,
11214 show_bgp_instance_updgrps_stats_cmd,
11215 "show [ip] bgp <view|vrf> VIEWVRFNAME update-groups statistics",
11216 SHOW_STR
11217 IP_STR
11218 BGP_STR
11219 BGP_INSTANCE_HELP_STR
11220 "Detailed info about dynamic update groups\n"
11221 "Statistics\n")
11222 {
11223 int idx_word = 3;
11224 struct bgp *bgp;
11225
11226 bgp = bgp_lookup_by_name(argv[idx_word]->arg);
11227 if (bgp)
11228 update_group_show_stats(bgp, vty);
11229
11230 return CMD_SUCCESS;
11231 }
11232
11233 static void show_bgp_updgrps_adj_info_aux(struct vty *vty, const char *name,
11234 afi_t afi, safi_t safi,
11235 const char *what, uint64_t subgrp_id)
11236 {
11237 struct bgp *bgp;
11238
11239 if (name)
11240 bgp = bgp_lookup_by_name(name);
11241 else
11242 bgp = bgp_get_default();
11243
11244 if (bgp) {
11245 if (!strcmp(what, "advertise-queue"))
11246 update_group_show_adj_queue(bgp, afi, safi, vty,
11247 subgrp_id);
11248 else if (!strcmp(what, "advertised-routes"))
11249 update_group_show_advertised(bgp, afi, safi, vty,
11250 subgrp_id);
11251 else if (!strcmp(what, "packet-queue"))
11252 update_group_show_packet_queue(bgp, afi, safi, vty,
11253 subgrp_id);
11254 }
11255 }
11256
11257 DEFPY(show_ip_bgp_instance_updgrps_adj_s,
11258 show_ip_bgp_instance_updgrps_adj_s_cmd,
11259 "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",
11260 SHOW_STR IP_STR BGP_STR BGP_INSTANCE_HELP_STR BGP_AFI_HELP_STR
11261 BGP_SAFI_HELP_STR
11262 "Detailed info about dynamic update groups\n"
11263 "Specific subgroup to display info for\n"
11264 "Advertisement queue\n"
11265 "Announced routes\n"
11266 "Packet queue\n")
11267 {
11268 uint64_t subgrp_id = 0;
11269 afi_t afiz;
11270 safi_t safiz;
11271 if (sgid)
11272 subgrp_id = strtoull(sgid, NULL, 10);
11273
11274 if (!ip && !afi)
11275 afiz = AFI_IP6;
11276 if (!ip && afi)
11277 afiz = bgp_vty_afi_from_str(afi);
11278 if (ip && !afi)
11279 afiz = AFI_IP;
11280 if (ip && afi) {
11281 afiz = bgp_vty_afi_from_str(afi);
11282 if (afiz != AFI_IP)
11283 vty_out(vty,
11284 "%% Cannot specify both 'ip' and 'ipv6'\n");
11285 return CMD_WARNING;
11286 }
11287
11288 safiz = safi ? bgp_vty_safi_from_str(safi) : SAFI_UNICAST;
11289
11290 show_bgp_updgrps_adj_info_aux(vty, vrf, afiz, safiz, rtq, subgrp_id);
11291 return CMD_SUCCESS;
11292 }
11293
11294 static int bgp_show_one_peer_group(struct vty *vty, struct peer_group *group)
11295 {
11296 struct listnode *node, *nnode;
11297 struct prefix *range;
11298 struct peer *conf;
11299 struct peer *peer;
11300 char buf[PREFIX2STR_BUFFER];
11301 afi_t afi;
11302 safi_t safi;
11303 const char *peer_status;
11304 const char *af_str;
11305 int lr_count;
11306 int dynamic;
11307 int af_cfgd;
11308
11309 conf = group->conf;
11310
11311 if (conf->as_type == AS_SPECIFIED || conf->as_type == AS_EXTERNAL) {
11312 vty_out(vty, "\nBGP peer-group %s, remote AS %d\n", group->name,
11313 conf->as);
11314 } else if (conf->as_type == AS_INTERNAL) {
11315 vty_out(vty, "\nBGP peer-group %s, remote AS %d\n", group->name,
11316 group->bgp->as);
11317 } else {
11318 vty_out(vty, "\nBGP peer-group %s\n", group->name);
11319 }
11320
11321 if ((group->bgp->as == conf->as) || (conf->as_type == AS_INTERNAL))
11322 vty_out(vty, " Peer-group type is internal\n");
11323 else
11324 vty_out(vty, " Peer-group type is external\n");
11325
11326 /* Display AFs configured. */
11327 vty_out(vty, " Configured address-families:");
11328 FOREACH_AFI_SAFI (afi, safi) {
11329 if (conf->afc[afi][safi]) {
11330 af_cfgd = 1;
11331 vty_out(vty, " %s;", afi_safi_print(afi, safi));
11332 }
11333 }
11334 if (!af_cfgd)
11335 vty_out(vty, " none\n");
11336 else
11337 vty_out(vty, "\n");
11338
11339 /* Display listen ranges (for dynamic neighbors), if any */
11340 for (afi = AFI_IP; afi < AFI_MAX; afi++) {
11341 if (afi == AFI_IP)
11342 af_str = "IPv4";
11343 else if (afi == AFI_IP6)
11344 af_str = "IPv6";
11345 else
11346 af_str = "???";
11347 lr_count = listcount(group->listen_range[afi]);
11348 if (lr_count) {
11349 vty_out(vty, " %d %s listen range(s)\n", lr_count,
11350 af_str);
11351
11352
11353 for (ALL_LIST_ELEMENTS(group->listen_range[afi], node,
11354 nnode, range)) {
11355 prefix2str(range, buf, sizeof(buf));
11356 vty_out(vty, " %s\n", buf);
11357 }
11358 }
11359 }
11360
11361 /* Display group members and their status */
11362 if (listcount(group->peer)) {
11363 vty_out(vty, " Peer-group members:\n");
11364 for (ALL_LIST_ELEMENTS(group->peer, node, nnode, peer)) {
11365 if (CHECK_FLAG(peer->flags, PEER_FLAG_SHUTDOWN))
11366 peer_status = "Idle (Admin)";
11367 else if (CHECK_FLAG(peer->sflags,
11368 PEER_STATUS_PREFIX_OVERFLOW))
11369 peer_status = "Idle (PfxCt)";
11370 else
11371 peer_status = lookup_msg(bgp_status_msg,
11372 peer->status, NULL);
11373
11374 dynamic = peer_dynamic_neighbor(peer);
11375 vty_out(vty, " %s %s %s \n", peer->host,
11376 dynamic ? "(dynamic)" : "", peer_status);
11377 }
11378 }
11379
11380 return CMD_SUCCESS;
11381 }
11382
11383 static int bgp_show_peer_group_vty(struct vty *vty, const char *name,
11384 const char *group_name)
11385 {
11386 struct bgp *bgp;
11387 struct listnode *node, *nnode;
11388 struct peer_group *group;
11389 bool found = false;
11390
11391 bgp = name ? bgp_lookup_by_name(name) : bgp_get_default();
11392
11393 if (!bgp) {
11394 vty_out(vty, "%% No such BGP instance exists\n");
11395 return CMD_WARNING;
11396 }
11397
11398 for (ALL_LIST_ELEMENTS(bgp->group, node, nnode, group)) {
11399 if (group_name) {
11400 if (strmatch(group->name, group_name)) {
11401 bgp_show_one_peer_group(vty, group);
11402 found = true;
11403 break;
11404 }
11405 } else {
11406 bgp_show_one_peer_group(vty, group);
11407 }
11408 }
11409
11410 if (group_name && !found)
11411 vty_out(vty, "%% No such peer-group\n");
11412
11413 return CMD_SUCCESS;
11414 }
11415
11416 DEFUN (show_ip_bgp_peer_groups,
11417 show_ip_bgp_peer_groups_cmd,
11418 "show [ip] bgp [<view|vrf> VIEWVRFNAME] peer-group [PGNAME]",
11419 SHOW_STR
11420 IP_STR
11421 BGP_STR
11422 BGP_INSTANCE_HELP_STR
11423 "Detailed information on BGP peer groups\n"
11424 "Peer group name\n")
11425 {
11426 char *vrf, *pg;
11427 int idx = 0;
11428
11429 vrf = argv_find(argv, argc, "VIEWVRFNAME", &idx) ? argv[idx]->arg
11430 : NULL;
11431 pg = argv_find(argv, argc, "PGNAME", &idx) ? argv[idx]->arg : NULL;
11432
11433 return bgp_show_peer_group_vty(vty, vrf, pg);
11434 }
11435
11436
11437 /* Redistribute VTY commands. */
11438
11439 DEFUN (bgp_redistribute_ipv4,
11440 bgp_redistribute_ipv4_cmd,
11441 "redistribute " FRR_IP_REDIST_STR_BGPD,
11442 "Redistribute information from another routing protocol\n"
11443 FRR_IP_REDIST_HELP_STR_BGPD)
11444 {
11445 VTY_DECLVAR_CONTEXT(bgp, bgp);
11446 int idx_protocol = 1;
11447 int type;
11448
11449 type = proto_redistnum(AFI_IP, argv[idx_protocol]->text);
11450 if (type < 0) {
11451 vty_out(vty, "%% Invalid route type\n");
11452 return CMD_WARNING_CONFIG_FAILED;
11453 }
11454
11455 bgp_redist_add(bgp, AFI_IP, type, 0);
11456 return bgp_redistribute_set(bgp, AFI_IP, type, 0);
11457 }
11458
11459 ALIAS_HIDDEN(
11460 bgp_redistribute_ipv4, bgp_redistribute_ipv4_hidden_cmd,
11461 "redistribute " FRR_IP_REDIST_STR_BGPD,
11462 "Redistribute information from another routing protocol\n" FRR_IP_REDIST_HELP_STR_BGPD)
11463
11464 DEFUN (bgp_redistribute_ipv4_rmap,
11465 bgp_redistribute_ipv4_rmap_cmd,
11466 "redistribute " FRR_IP_REDIST_STR_BGPD " route-map WORD",
11467 "Redistribute information from another routing protocol\n"
11468 FRR_IP_REDIST_HELP_STR_BGPD
11469 "Route map reference\n"
11470 "Pointer to route-map entries\n")
11471 {
11472 VTY_DECLVAR_CONTEXT(bgp, bgp);
11473 int idx_protocol = 1;
11474 int idx_word = 3;
11475 int type;
11476 struct bgp_redist *red;
11477
11478 type = proto_redistnum(AFI_IP, argv[idx_protocol]->text);
11479 if (type < 0) {
11480 vty_out(vty, "%% Invalid route type\n");
11481 return CMD_WARNING_CONFIG_FAILED;
11482 }
11483
11484 red = bgp_redist_add(bgp, AFI_IP, type, 0);
11485 bgp_redistribute_rmap_set(red, argv[idx_word]->arg);
11486 return bgp_redistribute_set(bgp, AFI_IP, type, 0);
11487 }
11488
11489 ALIAS_HIDDEN(
11490 bgp_redistribute_ipv4_rmap, bgp_redistribute_ipv4_rmap_hidden_cmd,
11491 "redistribute " FRR_IP_REDIST_STR_BGPD " route-map WORD",
11492 "Redistribute information from another routing protocol\n" FRR_IP_REDIST_HELP_STR_BGPD
11493 "Route map reference\n"
11494 "Pointer to route-map entries\n")
11495
11496 DEFUN (bgp_redistribute_ipv4_metric,
11497 bgp_redistribute_ipv4_metric_cmd,
11498 "redistribute " FRR_IP_REDIST_STR_BGPD " metric (0-4294967295)",
11499 "Redistribute information from another routing protocol\n"
11500 FRR_IP_REDIST_HELP_STR_BGPD
11501 "Metric for redistributed routes\n"
11502 "Default metric\n")
11503 {
11504 VTY_DECLVAR_CONTEXT(bgp, bgp);
11505 int idx_protocol = 1;
11506 int idx_number = 3;
11507 int type;
11508 uint32_t metric;
11509 struct bgp_redist *red;
11510
11511 type = proto_redistnum(AFI_IP, argv[idx_protocol]->text);
11512 if (type < 0) {
11513 vty_out(vty, "%% Invalid route type\n");
11514 return CMD_WARNING_CONFIG_FAILED;
11515 }
11516 metric = strtoul(argv[idx_number]->arg, NULL, 10);
11517
11518 red = bgp_redist_add(bgp, AFI_IP, type, 0);
11519 bgp_redistribute_metric_set(bgp, red, AFI_IP, type, metric);
11520 return bgp_redistribute_set(bgp, AFI_IP, type, 0);
11521 }
11522
11523 ALIAS_HIDDEN(
11524 bgp_redistribute_ipv4_metric, bgp_redistribute_ipv4_metric_hidden_cmd,
11525 "redistribute " FRR_IP_REDIST_STR_BGPD " metric (0-4294967295)",
11526 "Redistribute information from another routing protocol\n" FRR_IP_REDIST_HELP_STR_BGPD
11527 "Metric for redistributed routes\n"
11528 "Default metric\n")
11529
11530 DEFUN (bgp_redistribute_ipv4_rmap_metric,
11531 bgp_redistribute_ipv4_rmap_metric_cmd,
11532 "redistribute " FRR_IP_REDIST_STR_BGPD " route-map WORD metric (0-4294967295)",
11533 "Redistribute information from another routing protocol\n"
11534 FRR_IP_REDIST_HELP_STR_BGPD
11535 "Route map reference\n"
11536 "Pointer to route-map entries\n"
11537 "Metric for redistributed routes\n"
11538 "Default metric\n")
11539 {
11540 VTY_DECLVAR_CONTEXT(bgp, bgp);
11541 int idx_protocol = 1;
11542 int idx_word = 3;
11543 int idx_number = 5;
11544 int type;
11545 uint32_t metric;
11546 struct bgp_redist *red;
11547
11548 type = proto_redistnum(AFI_IP, argv[idx_protocol]->text);
11549 if (type < 0) {
11550 vty_out(vty, "%% Invalid route type\n");
11551 return CMD_WARNING_CONFIG_FAILED;
11552 }
11553 metric = strtoul(argv[idx_number]->arg, NULL, 10);
11554
11555 red = bgp_redist_add(bgp, AFI_IP, type, 0);
11556 bgp_redistribute_rmap_set(red, argv[idx_word]->arg);
11557 bgp_redistribute_metric_set(bgp, red, AFI_IP, type, metric);
11558 return bgp_redistribute_set(bgp, AFI_IP, type, 0);
11559 }
11560
11561 ALIAS_HIDDEN(
11562 bgp_redistribute_ipv4_rmap_metric,
11563 bgp_redistribute_ipv4_rmap_metric_hidden_cmd,
11564 "redistribute " FRR_IP_REDIST_STR_BGPD
11565 " route-map WORD metric (0-4294967295)",
11566 "Redistribute information from another routing protocol\n" FRR_IP_REDIST_HELP_STR_BGPD
11567 "Route map reference\n"
11568 "Pointer to route-map entries\n"
11569 "Metric for redistributed routes\n"
11570 "Default metric\n")
11571
11572 DEFUN (bgp_redistribute_ipv4_metric_rmap,
11573 bgp_redistribute_ipv4_metric_rmap_cmd,
11574 "redistribute " FRR_IP_REDIST_STR_BGPD " metric (0-4294967295) route-map WORD",
11575 "Redistribute information from another routing protocol\n"
11576 FRR_IP_REDIST_HELP_STR_BGPD
11577 "Metric for redistributed routes\n"
11578 "Default metric\n"
11579 "Route map reference\n"
11580 "Pointer to route-map entries\n")
11581 {
11582 VTY_DECLVAR_CONTEXT(bgp, bgp);
11583 int idx_protocol = 1;
11584 int idx_number = 3;
11585 int idx_word = 5;
11586 int type;
11587 uint32_t metric;
11588 struct bgp_redist *red;
11589
11590 type = proto_redistnum(AFI_IP, argv[idx_protocol]->text);
11591 if (type < 0) {
11592 vty_out(vty, "%% Invalid route type\n");
11593 return CMD_WARNING_CONFIG_FAILED;
11594 }
11595 metric = strtoul(argv[idx_number]->arg, NULL, 10);
11596
11597 red = bgp_redist_add(bgp, AFI_IP, type, 0);
11598 bgp_redistribute_metric_set(bgp, red, AFI_IP, type, metric);
11599 bgp_redistribute_rmap_set(red, argv[idx_word]->arg);
11600 return bgp_redistribute_set(bgp, AFI_IP, type, 0);
11601 }
11602
11603 ALIAS_HIDDEN(
11604 bgp_redistribute_ipv4_metric_rmap,
11605 bgp_redistribute_ipv4_metric_rmap_hidden_cmd,
11606 "redistribute " FRR_IP_REDIST_STR_BGPD
11607 " metric (0-4294967295) route-map WORD",
11608 "Redistribute information from another routing protocol\n" FRR_IP_REDIST_HELP_STR_BGPD
11609 "Metric for redistributed routes\n"
11610 "Default metric\n"
11611 "Route map reference\n"
11612 "Pointer to route-map entries\n")
11613
11614 DEFUN (bgp_redistribute_ipv4_ospf,
11615 bgp_redistribute_ipv4_ospf_cmd,
11616 "redistribute <ospf|table> (1-65535)",
11617 "Redistribute information from another routing protocol\n"
11618 "Open Shortest Path First (OSPFv2)\n"
11619 "Non-main Kernel Routing Table\n"
11620 "Instance ID/Table ID\n")
11621 {
11622 VTY_DECLVAR_CONTEXT(bgp, bgp);
11623 int idx_ospf_table = 1;
11624 int idx_number = 2;
11625 unsigned short instance;
11626 unsigned short protocol;
11627
11628 instance = strtoul(argv[idx_number]->arg, NULL, 10);
11629
11630 if (strncmp(argv[idx_ospf_table]->arg, "o", 1) == 0)
11631 protocol = ZEBRA_ROUTE_OSPF;
11632 else
11633 protocol = ZEBRA_ROUTE_TABLE;
11634
11635 bgp_redist_add(bgp, AFI_IP, protocol, instance);
11636 return bgp_redistribute_set(bgp, AFI_IP, protocol, instance);
11637 }
11638
11639 ALIAS_HIDDEN(bgp_redistribute_ipv4_ospf, bgp_redistribute_ipv4_ospf_hidden_cmd,
11640 "redistribute <ospf|table> (1-65535)",
11641 "Redistribute information from another routing protocol\n"
11642 "Open Shortest Path First (OSPFv2)\n"
11643 "Non-main Kernel Routing Table\n"
11644 "Instance ID/Table ID\n")
11645
11646 DEFUN (bgp_redistribute_ipv4_ospf_rmap,
11647 bgp_redistribute_ipv4_ospf_rmap_cmd,
11648 "redistribute <ospf|table> (1-65535) route-map WORD",
11649 "Redistribute information from another routing protocol\n"
11650 "Open Shortest Path First (OSPFv2)\n"
11651 "Non-main Kernel Routing Table\n"
11652 "Instance ID/Table ID\n"
11653 "Route map reference\n"
11654 "Pointer to route-map entries\n")
11655 {
11656 VTY_DECLVAR_CONTEXT(bgp, bgp);
11657 int idx_ospf_table = 1;
11658 int idx_number = 2;
11659 int idx_word = 4;
11660 struct bgp_redist *red;
11661 unsigned short instance;
11662 int protocol;
11663
11664 if (strncmp(argv[idx_ospf_table]->arg, "o", 1) == 0)
11665 protocol = ZEBRA_ROUTE_OSPF;
11666 else
11667 protocol = ZEBRA_ROUTE_TABLE;
11668
11669 instance = strtoul(argv[idx_number]->arg, NULL, 10);
11670 red = bgp_redist_add(bgp, AFI_IP, protocol, instance);
11671 bgp_redistribute_rmap_set(red, argv[idx_word]->arg);
11672 return bgp_redistribute_set(bgp, AFI_IP, protocol, instance);
11673 }
11674
11675 ALIAS_HIDDEN(bgp_redistribute_ipv4_ospf_rmap,
11676 bgp_redistribute_ipv4_ospf_rmap_hidden_cmd,
11677 "redistribute <ospf|table> (1-65535) route-map WORD",
11678 "Redistribute information from another routing protocol\n"
11679 "Open Shortest Path First (OSPFv2)\n"
11680 "Non-main Kernel Routing Table\n"
11681 "Instance ID/Table ID\n"
11682 "Route map reference\n"
11683 "Pointer to route-map entries\n")
11684
11685 DEFUN (bgp_redistribute_ipv4_ospf_metric,
11686 bgp_redistribute_ipv4_ospf_metric_cmd,
11687 "redistribute <ospf|table> (1-65535) metric (0-4294967295)",
11688 "Redistribute information from another routing protocol\n"
11689 "Open Shortest Path First (OSPFv2)\n"
11690 "Non-main Kernel Routing Table\n"
11691 "Instance ID/Table ID\n"
11692 "Metric for redistributed routes\n"
11693 "Default metric\n")
11694 {
11695 VTY_DECLVAR_CONTEXT(bgp, bgp);
11696 int idx_ospf_table = 1;
11697 int idx_number = 2;
11698 int idx_number_2 = 4;
11699 uint32_t metric;
11700 struct bgp_redist *red;
11701 unsigned short instance;
11702 int protocol;
11703
11704 if (strncmp(argv[idx_ospf_table]->arg, "o", 1) == 0)
11705 protocol = ZEBRA_ROUTE_OSPF;
11706 else
11707 protocol = ZEBRA_ROUTE_TABLE;
11708
11709 instance = strtoul(argv[idx_number]->arg, NULL, 10);
11710 metric = strtoul(argv[idx_number_2]->arg, NULL, 10);
11711
11712 red = bgp_redist_add(bgp, AFI_IP, protocol, instance);
11713 bgp_redistribute_metric_set(bgp, red, AFI_IP, protocol, metric);
11714 return bgp_redistribute_set(bgp, AFI_IP, protocol, instance);
11715 }
11716
11717 ALIAS_HIDDEN(bgp_redistribute_ipv4_ospf_metric,
11718 bgp_redistribute_ipv4_ospf_metric_hidden_cmd,
11719 "redistribute <ospf|table> (1-65535) metric (0-4294967295)",
11720 "Redistribute information from another routing protocol\n"
11721 "Open Shortest Path First (OSPFv2)\n"
11722 "Non-main Kernel Routing Table\n"
11723 "Instance ID/Table ID\n"
11724 "Metric for redistributed routes\n"
11725 "Default metric\n")
11726
11727 DEFUN (bgp_redistribute_ipv4_ospf_rmap_metric,
11728 bgp_redistribute_ipv4_ospf_rmap_metric_cmd,
11729 "redistribute <ospf|table> (1-65535) route-map WORD metric (0-4294967295)",
11730 "Redistribute information from another routing protocol\n"
11731 "Open Shortest Path First (OSPFv2)\n"
11732 "Non-main Kernel Routing Table\n"
11733 "Instance ID/Table ID\n"
11734 "Route map reference\n"
11735 "Pointer to route-map entries\n"
11736 "Metric for redistributed routes\n"
11737 "Default metric\n")
11738 {
11739 VTY_DECLVAR_CONTEXT(bgp, bgp);
11740 int idx_ospf_table = 1;
11741 int idx_number = 2;
11742 int idx_word = 4;
11743 int idx_number_2 = 6;
11744 uint32_t metric;
11745 struct bgp_redist *red;
11746 unsigned short instance;
11747 int protocol;
11748
11749 if (strncmp(argv[idx_ospf_table]->arg, "o", 1) == 0)
11750 protocol = ZEBRA_ROUTE_OSPF;
11751 else
11752 protocol = ZEBRA_ROUTE_TABLE;
11753
11754 instance = strtoul(argv[idx_number]->arg, NULL, 10);
11755 metric = strtoul(argv[idx_number_2]->arg, NULL, 10);
11756
11757 red = bgp_redist_add(bgp, AFI_IP, protocol, instance);
11758 bgp_redistribute_rmap_set(red, argv[idx_word]->arg);
11759 bgp_redistribute_metric_set(bgp, red, AFI_IP, protocol, metric);
11760 return bgp_redistribute_set(bgp, AFI_IP, protocol, instance);
11761 }
11762
11763 ALIAS_HIDDEN(
11764 bgp_redistribute_ipv4_ospf_rmap_metric,
11765 bgp_redistribute_ipv4_ospf_rmap_metric_hidden_cmd,
11766 "redistribute <ospf|table> (1-65535) route-map WORD metric (0-4294967295)",
11767 "Redistribute information from another routing protocol\n"
11768 "Open Shortest Path First (OSPFv2)\n"
11769 "Non-main Kernel Routing Table\n"
11770 "Instance ID/Table ID\n"
11771 "Route map reference\n"
11772 "Pointer to route-map entries\n"
11773 "Metric for redistributed routes\n"
11774 "Default metric\n")
11775
11776 DEFUN (bgp_redistribute_ipv4_ospf_metric_rmap,
11777 bgp_redistribute_ipv4_ospf_metric_rmap_cmd,
11778 "redistribute <ospf|table> (1-65535) metric (0-4294967295) route-map WORD",
11779 "Redistribute information from another routing protocol\n"
11780 "Open Shortest Path First (OSPFv2)\n"
11781 "Non-main Kernel Routing Table\n"
11782 "Instance ID/Table ID\n"
11783 "Metric for redistributed routes\n"
11784 "Default metric\n"
11785 "Route map reference\n"
11786 "Pointer to route-map entries\n")
11787 {
11788 VTY_DECLVAR_CONTEXT(bgp, bgp);
11789 int idx_ospf_table = 1;
11790 int idx_number = 2;
11791 int idx_number_2 = 4;
11792 int idx_word = 6;
11793 uint32_t metric;
11794 struct bgp_redist *red;
11795 unsigned short instance;
11796 int protocol;
11797
11798 if (strncmp(argv[idx_ospf_table]->arg, "o", 1) == 0)
11799 protocol = ZEBRA_ROUTE_OSPF;
11800 else
11801 protocol = ZEBRA_ROUTE_TABLE;
11802
11803 instance = strtoul(argv[idx_number]->arg, NULL, 10);
11804 metric = strtoul(argv[idx_number_2]->arg, NULL, 10);
11805
11806 red = bgp_redist_add(bgp, AFI_IP, protocol, instance);
11807 bgp_redistribute_metric_set(bgp, red, AFI_IP, protocol, metric);
11808 bgp_redistribute_rmap_set(red, argv[idx_word]->arg);
11809 return bgp_redistribute_set(bgp, AFI_IP, protocol, instance);
11810 }
11811
11812 ALIAS_HIDDEN(
11813 bgp_redistribute_ipv4_ospf_metric_rmap,
11814 bgp_redistribute_ipv4_ospf_metric_rmap_hidden_cmd,
11815 "redistribute <ospf|table> (1-65535) metric (0-4294967295) route-map WORD",
11816 "Redistribute information from another routing protocol\n"
11817 "Open Shortest Path First (OSPFv2)\n"
11818 "Non-main Kernel Routing Table\n"
11819 "Instance ID/Table ID\n"
11820 "Metric for redistributed routes\n"
11821 "Default metric\n"
11822 "Route map reference\n"
11823 "Pointer to route-map entries\n")
11824
11825 DEFUN (no_bgp_redistribute_ipv4_ospf,
11826 no_bgp_redistribute_ipv4_ospf_cmd,
11827 "no redistribute <ospf|table> (1-65535) [metric (0-4294967295)] [route-map WORD]",
11828 NO_STR
11829 "Redistribute information from another routing protocol\n"
11830 "Open Shortest Path First (OSPFv2)\n"
11831 "Non-main Kernel Routing Table\n"
11832 "Instance ID/Table ID\n"
11833 "Metric for redistributed routes\n"
11834 "Default metric\n"
11835 "Route map reference\n"
11836 "Pointer to route-map entries\n")
11837 {
11838 VTY_DECLVAR_CONTEXT(bgp, bgp);
11839 int idx_ospf_table = 2;
11840 int idx_number = 3;
11841 unsigned short instance;
11842 int protocol;
11843
11844 if (strncmp(argv[idx_ospf_table]->arg, "o", 1) == 0)
11845 protocol = ZEBRA_ROUTE_OSPF;
11846 else
11847 protocol = ZEBRA_ROUTE_TABLE;
11848
11849 instance = strtoul(argv[idx_number]->arg, NULL, 10);
11850 return bgp_redistribute_unset(bgp, AFI_IP, protocol, instance);
11851 }
11852
11853 ALIAS_HIDDEN(
11854 no_bgp_redistribute_ipv4_ospf, no_bgp_redistribute_ipv4_ospf_hidden_cmd,
11855 "no redistribute <ospf|table> (1-65535) [metric (0-4294967295)] [route-map WORD]",
11856 NO_STR
11857 "Redistribute information from another routing protocol\n"
11858 "Open Shortest Path First (OSPFv2)\n"
11859 "Non-main Kernel Routing Table\n"
11860 "Instance ID/Table ID\n"
11861 "Metric for redistributed routes\n"
11862 "Default metric\n"
11863 "Route map reference\n"
11864 "Pointer to route-map entries\n")
11865
11866 DEFUN (no_bgp_redistribute_ipv4,
11867 no_bgp_redistribute_ipv4_cmd,
11868 "no redistribute " FRR_IP_REDIST_STR_BGPD " [metric (0-4294967295)] [route-map WORD]",
11869 NO_STR
11870 "Redistribute information from another routing protocol\n"
11871 FRR_IP_REDIST_HELP_STR_BGPD
11872 "Metric for redistributed routes\n"
11873 "Default metric\n"
11874 "Route map reference\n"
11875 "Pointer to route-map entries\n")
11876 {
11877 VTY_DECLVAR_CONTEXT(bgp, bgp);
11878 int idx_protocol = 2;
11879 int type;
11880
11881 type = proto_redistnum(AFI_IP, argv[idx_protocol]->text);
11882 if (type < 0) {
11883 vty_out(vty, "%% Invalid route type\n");
11884 return CMD_WARNING_CONFIG_FAILED;
11885 }
11886 return bgp_redistribute_unset(bgp, AFI_IP, type, 0);
11887 }
11888
11889 ALIAS_HIDDEN(
11890 no_bgp_redistribute_ipv4, no_bgp_redistribute_ipv4_hidden_cmd,
11891 "no redistribute " FRR_IP_REDIST_STR_BGPD
11892 " [metric (0-4294967295)] [route-map WORD]",
11893 NO_STR
11894 "Redistribute information from another routing protocol\n" FRR_IP_REDIST_HELP_STR_BGPD
11895 "Metric for redistributed routes\n"
11896 "Default metric\n"
11897 "Route map reference\n"
11898 "Pointer to route-map entries\n")
11899
11900 DEFUN (bgp_redistribute_ipv6,
11901 bgp_redistribute_ipv6_cmd,
11902 "redistribute " FRR_IP6_REDIST_STR_BGPD,
11903 "Redistribute information from another routing protocol\n"
11904 FRR_IP6_REDIST_HELP_STR_BGPD)
11905 {
11906 VTY_DECLVAR_CONTEXT(bgp, bgp);
11907 int idx_protocol = 1;
11908 int type;
11909
11910 type = proto_redistnum(AFI_IP6, argv[idx_protocol]->text);
11911 if (type < 0) {
11912 vty_out(vty, "%% Invalid route type\n");
11913 return CMD_WARNING_CONFIG_FAILED;
11914 }
11915
11916 bgp_redist_add(bgp, AFI_IP6, type, 0);
11917 return bgp_redistribute_set(bgp, AFI_IP6, type, 0);
11918 }
11919
11920 DEFUN (bgp_redistribute_ipv6_rmap,
11921 bgp_redistribute_ipv6_rmap_cmd,
11922 "redistribute " FRR_IP6_REDIST_STR_BGPD " route-map WORD",
11923 "Redistribute information from another routing protocol\n"
11924 FRR_IP6_REDIST_HELP_STR_BGPD
11925 "Route map reference\n"
11926 "Pointer to route-map entries\n")
11927 {
11928 VTY_DECLVAR_CONTEXT(bgp, bgp);
11929 int idx_protocol = 1;
11930 int idx_word = 3;
11931 int type;
11932 struct bgp_redist *red;
11933
11934 type = proto_redistnum(AFI_IP6, argv[idx_protocol]->text);
11935 if (type < 0) {
11936 vty_out(vty, "%% Invalid route type\n");
11937 return CMD_WARNING_CONFIG_FAILED;
11938 }
11939
11940 red = bgp_redist_add(bgp, AFI_IP6, type, 0);
11941 bgp_redistribute_rmap_set(red, argv[idx_word]->arg);
11942 return bgp_redistribute_set(bgp, AFI_IP6, type, 0);
11943 }
11944
11945 DEFUN (bgp_redistribute_ipv6_metric,
11946 bgp_redistribute_ipv6_metric_cmd,
11947 "redistribute " FRR_IP6_REDIST_STR_BGPD " metric (0-4294967295)",
11948 "Redistribute information from another routing protocol\n"
11949 FRR_IP6_REDIST_HELP_STR_BGPD
11950 "Metric for redistributed routes\n"
11951 "Default metric\n")
11952 {
11953 VTY_DECLVAR_CONTEXT(bgp, bgp);
11954 int idx_protocol = 1;
11955 int idx_number = 3;
11956 int type;
11957 uint32_t metric;
11958 struct bgp_redist *red;
11959
11960 type = proto_redistnum(AFI_IP6, argv[idx_protocol]->text);
11961 if (type < 0) {
11962 vty_out(vty, "%% Invalid route type\n");
11963 return CMD_WARNING_CONFIG_FAILED;
11964 }
11965 metric = strtoul(argv[idx_number]->arg, NULL, 10);
11966
11967 red = bgp_redist_add(bgp, AFI_IP6, type, 0);
11968 bgp_redistribute_metric_set(bgp, red, AFI_IP6, type, metric);
11969 return bgp_redistribute_set(bgp, AFI_IP6, type, 0);
11970 }
11971
11972 DEFUN (bgp_redistribute_ipv6_rmap_metric,
11973 bgp_redistribute_ipv6_rmap_metric_cmd,
11974 "redistribute " FRR_IP6_REDIST_STR_BGPD " route-map WORD metric (0-4294967295)",
11975 "Redistribute information from another routing protocol\n"
11976 FRR_IP6_REDIST_HELP_STR_BGPD
11977 "Route map reference\n"
11978 "Pointer to route-map entries\n"
11979 "Metric for redistributed routes\n"
11980 "Default metric\n")
11981 {
11982 VTY_DECLVAR_CONTEXT(bgp, bgp);
11983 int idx_protocol = 1;
11984 int idx_word = 3;
11985 int idx_number = 5;
11986 int type;
11987 uint32_t metric;
11988 struct bgp_redist *red;
11989
11990 type = proto_redistnum(AFI_IP6, argv[idx_protocol]->text);
11991 if (type < 0) {
11992 vty_out(vty, "%% Invalid route type\n");
11993 return CMD_WARNING_CONFIG_FAILED;
11994 }
11995 metric = strtoul(argv[idx_number]->arg, NULL, 10);
11996
11997 red = bgp_redist_add(bgp, AFI_IP6, type, 0);
11998 bgp_redistribute_rmap_set(red, argv[idx_word]->arg);
11999 bgp_redistribute_metric_set(bgp, red, AFI_IP6, type, metric);
12000 return bgp_redistribute_set(bgp, AFI_IP6, type, 0);
12001 }
12002
12003 DEFUN (bgp_redistribute_ipv6_metric_rmap,
12004 bgp_redistribute_ipv6_metric_rmap_cmd,
12005 "redistribute " FRR_IP6_REDIST_STR_BGPD " metric (0-4294967295) route-map WORD",
12006 "Redistribute information from another routing protocol\n"
12007 FRR_IP6_REDIST_HELP_STR_BGPD
12008 "Metric for redistributed routes\n"
12009 "Default metric\n"
12010 "Route map reference\n"
12011 "Pointer to route-map entries\n")
12012 {
12013 VTY_DECLVAR_CONTEXT(bgp, bgp);
12014 int idx_protocol = 1;
12015 int idx_number = 3;
12016 int idx_word = 5;
12017 int type;
12018 uint32_t metric;
12019 struct bgp_redist *red;
12020
12021 type = proto_redistnum(AFI_IP6, argv[idx_protocol]->text);
12022 if (type < 0) {
12023 vty_out(vty, "%% Invalid route type\n");
12024 return CMD_WARNING_CONFIG_FAILED;
12025 }
12026 metric = strtoul(argv[idx_number]->arg, NULL, 10);
12027
12028 red = bgp_redist_add(bgp, AFI_IP6, type, 0);
12029 bgp_redistribute_metric_set(bgp, red, AFI_IP6, SAFI_UNICAST, metric);
12030 bgp_redistribute_rmap_set(red, argv[idx_word]->arg);
12031 return bgp_redistribute_set(bgp, AFI_IP6, type, 0);
12032 }
12033
12034 DEFUN (no_bgp_redistribute_ipv6,
12035 no_bgp_redistribute_ipv6_cmd,
12036 "no redistribute " FRR_IP6_REDIST_STR_BGPD " [metric (0-4294967295)] [route-map WORD]",
12037 NO_STR
12038 "Redistribute information from another routing protocol\n"
12039 FRR_IP6_REDIST_HELP_STR_BGPD
12040 "Metric for redistributed routes\n"
12041 "Default metric\n"
12042 "Route map reference\n"
12043 "Pointer to route-map entries\n")
12044 {
12045 VTY_DECLVAR_CONTEXT(bgp, bgp);
12046 int idx_protocol = 2;
12047 int type;
12048
12049 type = proto_redistnum(AFI_IP6, argv[idx_protocol]->text);
12050 if (type < 0) {
12051 vty_out(vty, "%% Invalid route type\n");
12052 return CMD_WARNING_CONFIG_FAILED;
12053 }
12054
12055 return bgp_redistribute_unset(bgp, AFI_IP6, type, 0);
12056 }
12057
12058 void bgp_config_write_redistribute(struct vty *vty, struct bgp *bgp, afi_t afi,
12059 safi_t safi)
12060 {
12061 int i;
12062
12063 /* Unicast redistribution only. */
12064 if (safi != SAFI_UNICAST)
12065 return;
12066
12067 for (i = 0; i < ZEBRA_ROUTE_MAX; i++) {
12068 /* Redistribute BGP does not make sense. */
12069 if (i != ZEBRA_ROUTE_BGP) {
12070 struct list *red_list;
12071 struct listnode *node;
12072 struct bgp_redist *red;
12073
12074 red_list = bgp->redist[afi][i];
12075 if (!red_list)
12076 continue;
12077
12078 for (ALL_LIST_ELEMENTS_RO(red_list, node, red)) {
12079 /* "redistribute" configuration. */
12080 vty_out(vty, " redistribute %s",
12081 zebra_route_string(i));
12082 if (red->instance)
12083 vty_out(vty, " %d", red->instance);
12084 if (red->redist_metric_flag)
12085 vty_out(vty, " metric %u",
12086 red->redist_metric);
12087 if (red->rmap.name)
12088 vty_out(vty, " route-map %s",
12089 red->rmap.name);
12090 vty_out(vty, "\n");
12091 }
12092 }
12093 }
12094 }
12095
12096 /* This is part of the address-family block (unicast only) */
12097 void bgp_vpn_policy_config_write_afi(struct vty *vty, struct bgp *bgp,
12098 afi_t afi)
12099 {
12100 int indent = 2;
12101
12102 if (bgp->vpn_policy[afi].rmap_name[BGP_VPN_POLICY_DIR_FROMVPN])
12103 vty_out(vty, "%*simport vrf route-map %s\n", indent, "",
12104 bgp->vpn_policy[afi]
12105 .rmap_name[BGP_VPN_POLICY_DIR_FROMVPN]);
12106
12107 if (CHECK_FLAG(bgp->af_flags[afi][SAFI_UNICAST],
12108 BGP_CONFIG_VRF_TO_VRF_IMPORT)
12109 || CHECK_FLAG(bgp->af_flags[afi][SAFI_UNICAST],
12110 BGP_CONFIG_VRF_TO_VRF_EXPORT))
12111 return;
12112
12113 if (CHECK_FLAG(bgp->vpn_policy[afi].flags,
12114 BGP_VPN_POLICY_TOVPN_LABEL_AUTO)) {
12115
12116 vty_out(vty, "%*slabel vpn export %s\n", indent, "", "auto");
12117
12118 } else {
12119 if (bgp->vpn_policy[afi].tovpn_label != MPLS_LABEL_NONE) {
12120 vty_out(vty, "%*slabel vpn export %u\n", indent, "",
12121 bgp->vpn_policy[afi].tovpn_label);
12122 }
12123 }
12124 if (CHECK_FLAG(bgp->vpn_policy[afi].flags,
12125 BGP_VPN_POLICY_TOVPN_RD_SET)) {
12126 char buf[RD_ADDRSTRLEN];
12127 vty_out(vty, "%*srd vpn export %s\n", indent, "",
12128 prefix_rd2str(&bgp->vpn_policy[afi].tovpn_rd, buf,
12129 sizeof(buf)));
12130 }
12131 if (CHECK_FLAG(bgp->vpn_policy[afi].flags,
12132 BGP_VPN_POLICY_TOVPN_NEXTHOP_SET)) {
12133
12134 char buf[PREFIX_STRLEN];
12135 if (inet_ntop(bgp->vpn_policy[afi].tovpn_nexthop.family,
12136 &bgp->vpn_policy[afi].tovpn_nexthop.u.prefix, buf,
12137 sizeof(buf))) {
12138
12139 vty_out(vty, "%*snexthop vpn export %s\n",
12140 indent, "", buf);
12141 }
12142 }
12143 if (bgp->vpn_policy[afi].rtlist[BGP_VPN_POLICY_DIR_FROMVPN]
12144 && bgp->vpn_policy[afi].rtlist[BGP_VPN_POLICY_DIR_TOVPN]
12145 && ecommunity_cmp(
12146 bgp->vpn_policy[afi].rtlist[BGP_VPN_POLICY_DIR_FROMVPN],
12147 bgp->vpn_policy[afi].rtlist[BGP_VPN_POLICY_DIR_TOVPN])) {
12148
12149 char *b = ecommunity_ecom2str(
12150 bgp->vpn_policy[afi].rtlist[BGP_VPN_POLICY_DIR_TOVPN],
12151 ECOMMUNITY_FORMAT_ROUTE_MAP, ECOMMUNITY_ROUTE_TARGET);
12152 vty_out(vty, "%*srt vpn both %s\n", indent, "", b);
12153 XFREE(MTYPE_ECOMMUNITY_STR, b);
12154 } else {
12155 if (bgp->vpn_policy[afi].rtlist[BGP_VPN_POLICY_DIR_FROMVPN]) {
12156 char *b = ecommunity_ecom2str(
12157 bgp->vpn_policy[afi]
12158 .rtlist[BGP_VPN_POLICY_DIR_FROMVPN],
12159 ECOMMUNITY_FORMAT_ROUTE_MAP,
12160 ECOMMUNITY_ROUTE_TARGET);
12161 vty_out(vty, "%*srt vpn import %s\n", indent, "", b);
12162 XFREE(MTYPE_ECOMMUNITY_STR, b);
12163 }
12164 if (bgp->vpn_policy[afi].rtlist[BGP_VPN_POLICY_DIR_TOVPN]) {
12165 char *b = ecommunity_ecom2str(
12166 bgp->vpn_policy[afi]
12167 .rtlist[BGP_VPN_POLICY_DIR_TOVPN],
12168 ECOMMUNITY_FORMAT_ROUTE_MAP,
12169 ECOMMUNITY_ROUTE_TARGET);
12170 vty_out(vty, "%*srt vpn export %s\n", indent, "", b);
12171 XFREE(MTYPE_ECOMMUNITY_STR, b);
12172 }
12173 }
12174
12175 if (bgp->vpn_policy[afi].rmap_name[BGP_VPN_POLICY_DIR_TOVPN])
12176 vty_out(vty, "%*sroute-map vpn export %s\n", indent, "",
12177 bgp->vpn_policy[afi]
12178 .rmap_name[BGP_VPN_POLICY_DIR_TOVPN]);
12179
12180 if (bgp->vpn_policy[afi].import_redirect_rtlist) {
12181 char *b = ecommunity_ecom2str(
12182 bgp->vpn_policy[afi]
12183 .import_redirect_rtlist,
12184 ECOMMUNITY_FORMAT_ROUTE_MAP,
12185 ECOMMUNITY_ROUTE_TARGET);
12186
12187 vty_out(vty, "%*srt redirect import %s\n", indent, "", b);
12188 XFREE(MTYPE_ECOMMUNITY_STR, b);
12189 }
12190 }
12191
12192
12193 /* BGP node structure. */
12194 static struct cmd_node bgp_node = {
12195 BGP_NODE, "%s(config-router)# ", 1,
12196 };
12197
12198 static struct cmd_node bgp_ipv4_unicast_node = {
12199 BGP_IPV4_NODE, "%s(config-router-af)# ", 1,
12200 };
12201
12202 static struct cmd_node bgp_ipv4_multicast_node = {
12203 BGP_IPV4M_NODE, "%s(config-router-af)# ", 1,
12204 };
12205
12206 static struct cmd_node bgp_ipv4_labeled_unicast_node = {
12207 BGP_IPV4L_NODE, "%s(config-router-af)# ", 1,
12208 };
12209
12210 static struct cmd_node bgp_ipv6_unicast_node = {
12211 BGP_IPV6_NODE, "%s(config-router-af)# ", 1,
12212 };
12213
12214 static struct cmd_node bgp_ipv6_multicast_node = {
12215 BGP_IPV6M_NODE, "%s(config-router-af)# ", 1,
12216 };
12217
12218 static struct cmd_node bgp_ipv6_labeled_unicast_node = {
12219 BGP_IPV6L_NODE, "%s(config-router-af)# ", 1,
12220 };
12221
12222 static struct cmd_node bgp_vpnv4_node = {BGP_VPNV4_NODE,
12223 "%s(config-router-af)# ", 1};
12224
12225 static struct cmd_node bgp_vpnv6_node = {BGP_VPNV6_NODE,
12226 "%s(config-router-af-vpnv6)# ", 1};
12227
12228 static struct cmd_node bgp_evpn_node = {BGP_EVPN_NODE,
12229 "%s(config-router-evpn)# ", 1};
12230
12231 static struct cmd_node bgp_evpn_vni_node = {BGP_EVPN_VNI_NODE,
12232 "%s(config-router-af-vni)# ", 1};
12233
12234 static struct cmd_node bgp_flowspecv4_node = {BGP_FLOWSPECV4_NODE,
12235 "%s(config-router-af)# ", 1};
12236
12237 static struct cmd_node bgp_flowspecv6_node = {BGP_FLOWSPECV6_NODE,
12238 "%s(config-router-af-vpnv6)# ", 1};
12239
12240 static void community_list_vty(void);
12241
12242 static void bgp_ac_neighbor(vector comps, struct cmd_token *token)
12243 {
12244 struct bgp *bgp;
12245 struct peer *peer;
12246 struct listnode *lnbgp, *lnpeer;
12247
12248 for (ALL_LIST_ELEMENTS_RO(bm->bgp, lnbgp, bgp)) {
12249 for (ALL_LIST_ELEMENTS_RO(bgp->peer, lnpeer, peer)) {
12250 /* only provide suggestions on the appropriate input
12251 * token type,
12252 * they'll otherwise show up multiple times */
12253 enum cmd_token_type match_type;
12254 char *name = peer->host;
12255
12256 if (peer->conf_if) {
12257 match_type = VARIABLE_TKN;
12258 name = peer->conf_if;
12259 } else if (strchr(peer->host, ':'))
12260 match_type = IPV6_TKN;
12261 else
12262 match_type = IPV4_TKN;
12263
12264 if (token->type != match_type)
12265 continue;
12266
12267 vector_set(comps, XSTRDUP(MTYPE_COMPLETION, name));
12268 }
12269 }
12270 }
12271
12272 static const struct cmd_variable_handler bgp_var_neighbor[] = {
12273 {.varname = "neighbor", .completions = bgp_ac_neighbor},
12274 {.varname = "neighbors", .completions = bgp_ac_neighbor},
12275 {.varname = "peer", .completions = bgp_ac_neighbor},
12276 {.completions = NULL}};
12277
12278 static void bgp_ac_peergroup(vector comps, struct cmd_token *token)
12279 {
12280 struct bgp *bgp;
12281 struct peer_group *group;
12282 struct listnode *lnbgp, *lnpeer;
12283
12284 for (ALL_LIST_ELEMENTS_RO(bm->bgp, lnbgp, bgp)) {
12285 for (ALL_LIST_ELEMENTS_RO(bgp->group, lnpeer, group))
12286 vector_set(comps, XSTRDUP(MTYPE_COMPLETION,
12287 group->name));
12288 }
12289 }
12290
12291 static const struct cmd_variable_handler bgp_var_peergroup[] = {
12292 {.tokenname = "PGNAME", .completions = bgp_ac_peergroup},
12293 {.completions = NULL} };
12294
12295 void bgp_vty_init(void)
12296 {
12297 cmd_variable_handler_register(bgp_var_neighbor);
12298 cmd_variable_handler_register(bgp_var_peergroup);
12299
12300 /* Install bgp top node. */
12301 install_node(&bgp_node, bgp_config_write);
12302 install_node(&bgp_ipv4_unicast_node, NULL);
12303 install_node(&bgp_ipv4_multicast_node, NULL);
12304 install_node(&bgp_ipv4_labeled_unicast_node, NULL);
12305 install_node(&bgp_ipv6_unicast_node, NULL);
12306 install_node(&bgp_ipv6_multicast_node, NULL);
12307 install_node(&bgp_ipv6_labeled_unicast_node, NULL);
12308 install_node(&bgp_vpnv4_node, NULL);
12309 install_node(&bgp_vpnv6_node, NULL);
12310 install_node(&bgp_evpn_node, NULL);
12311 install_node(&bgp_evpn_vni_node, NULL);
12312 install_node(&bgp_flowspecv4_node, NULL);
12313 install_node(&bgp_flowspecv6_node, NULL);
12314
12315 /* Install default VTY commands to new nodes. */
12316 install_default(BGP_NODE);
12317 install_default(BGP_IPV4_NODE);
12318 install_default(BGP_IPV4M_NODE);
12319 install_default(BGP_IPV4L_NODE);
12320 install_default(BGP_IPV6_NODE);
12321 install_default(BGP_IPV6M_NODE);
12322 install_default(BGP_IPV6L_NODE);
12323 install_default(BGP_VPNV4_NODE);
12324 install_default(BGP_VPNV6_NODE);
12325 install_default(BGP_FLOWSPECV4_NODE);
12326 install_default(BGP_FLOWSPECV6_NODE);
12327 install_default(BGP_EVPN_NODE);
12328 install_default(BGP_EVPN_VNI_NODE);
12329
12330 /* "bgp multiple-instance" commands. */
12331 install_element(CONFIG_NODE, &bgp_multiple_instance_cmd);
12332 install_element(CONFIG_NODE, &no_bgp_multiple_instance_cmd);
12333
12334 /* "bgp config-type" commands. */
12335 install_element(CONFIG_NODE, &bgp_config_type_cmd);
12336 install_element(CONFIG_NODE, &no_bgp_config_type_cmd);
12337
12338 /* bgp route-map delay-timer commands. */
12339 install_element(CONFIG_NODE, &bgp_set_route_map_delay_timer_cmd);
12340 install_element(CONFIG_NODE, &no_bgp_set_route_map_delay_timer_cmd);
12341
12342 /* Dummy commands (Currently not supported) */
12343 install_element(BGP_NODE, &no_synchronization_cmd);
12344 install_element(BGP_NODE, &no_auto_summary_cmd);
12345
12346 /* "router bgp" commands. */
12347 install_element(CONFIG_NODE, &router_bgp_cmd);
12348
12349 /* "no router bgp" commands. */
12350 install_element(CONFIG_NODE, &no_router_bgp_cmd);
12351
12352 /* "bgp router-id" commands. */
12353 install_element(BGP_NODE, &bgp_router_id_cmd);
12354 install_element(BGP_NODE, &no_bgp_router_id_cmd);
12355
12356 /* "bgp cluster-id" commands. */
12357 install_element(BGP_NODE, &bgp_cluster_id_cmd);
12358 install_element(BGP_NODE, &no_bgp_cluster_id_cmd);
12359
12360 /* "bgp confederation" commands. */
12361 install_element(BGP_NODE, &bgp_confederation_identifier_cmd);
12362 install_element(BGP_NODE, &no_bgp_confederation_identifier_cmd);
12363
12364 /* "bgp confederation peers" commands. */
12365 install_element(BGP_NODE, &bgp_confederation_peers_cmd);
12366 install_element(BGP_NODE, &no_bgp_confederation_peers_cmd);
12367
12368 /* bgp max-med command */
12369 install_element(BGP_NODE, &bgp_maxmed_admin_cmd);
12370 install_element(BGP_NODE, &no_bgp_maxmed_admin_cmd);
12371 install_element(BGP_NODE, &bgp_maxmed_admin_medv_cmd);
12372 install_element(BGP_NODE, &bgp_maxmed_onstartup_cmd);
12373 install_element(BGP_NODE, &no_bgp_maxmed_onstartup_cmd);
12374
12375 /* bgp disable-ebgp-connected-nh-check */
12376 install_element(BGP_NODE, &bgp_disable_connected_route_check_cmd);
12377 install_element(BGP_NODE, &no_bgp_disable_connected_route_check_cmd);
12378
12379 /* bgp update-delay command */
12380 install_element(BGP_NODE, &bgp_update_delay_cmd);
12381 install_element(BGP_NODE, &no_bgp_update_delay_cmd);
12382 install_element(BGP_NODE, &bgp_update_delay_establish_wait_cmd);
12383
12384 install_element(BGP_NODE, &bgp_wpkt_quanta_cmd);
12385 install_element(BGP_NODE, &no_bgp_wpkt_quanta_cmd);
12386 install_element(BGP_NODE, &bgp_rpkt_quanta_cmd);
12387 install_element(BGP_NODE, &no_bgp_rpkt_quanta_cmd);
12388
12389 install_element(BGP_NODE, &bgp_coalesce_time_cmd);
12390 install_element(BGP_NODE, &no_bgp_coalesce_time_cmd);
12391
12392 /* "maximum-paths" commands. */
12393 install_element(BGP_NODE, &bgp_maxpaths_hidden_cmd);
12394 install_element(BGP_NODE, &no_bgp_maxpaths_hidden_cmd);
12395 install_element(BGP_IPV4_NODE, &bgp_maxpaths_cmd);
12396 install_element(BGP_IPV4_NODE, &no_bgp_maxpaths_cmd);
12397 install_element(BGP_IPV6_NODE, &bgp_maxpaths_cmd);
12398 install_element(BGP_IPV6_NODE, &no_bgp_maxpaths_cmd);
12399 install_element(BGP_NODE, &bgp_maxpaths_ibgp_hidden_cmd);
12400 install_element(BGP_NODE, &bgp_maxpaths_ibgp_cluster_hidden_cmd);
12401 install_element(BGP_NODE, &no_bgp_maxpaths_ibgp_hidden_cmd);
12402 install_element(BGP_IPV4_NODE, &bgp_maxpaths_ibgp_cmd);
12403 install_element(BGP_IPV4_NODE, &bgp_maxpaths_ibgp_cluster_cmd);
12404 install_element(BGP_IPV4_NODE, &no_bgp_maxpaths_ibgp_cmd);
12405 install_element(BGP_IPV6_NODE, &bgp_maxpaths_ibgp_cmd);
12406 install_element(BGP_IPV6_NODE, &bgp_maxpaths_ibgp_cluster_cmd);
12407 install_element(BGP_IPV6_NODE, &no_bgp_maxpaths_ibgp_cmd);
12408
12409 install_element(BGP_IPV6L_NODE, &bgp_maxpaths_cmd);
12410 install_element(BGP_IPV6L_NODE, &no_bgp_maxpaths_cmd);
12411 install_element(BGP_IPV6L_NODE, &bgp_maxpaths_ibgp_cmd);
12412 install_element(BGP_IPV6L_NODE, &bgp_maxpaths_ibgp_cluster_cmd);
12413 install_element(BGP_IPV6L_NODE, &no_bgp_maxpaths_ibgp_cmd);
12414
12415 /* "timers bgp" commands. */
12416 install_element(BGP_NODE, &bgp_timers_cmd);
12417 install_element(BGP_NODE, &no_bgp_timers_cmd);
12418
12419 /* route-map delay-timer commands - per instance for backwards compat.
12420 */
12421 install_element(BGP_NODE, &bgp_set_route_map_delay_timer_cmd);
12422 install_element(BGP_NODE, &no_bgp_set_route_map_delay_timer_cmd);
12423
12424 /* "bgp client-to-client reflection" commands */
12425 install_element(BGP_NODE, &no_bgp_client_to_client_reflection_cmd);
12426 install_element(BGP_NODE, &bgp_client_to_client_reflection_cmd);
12427
12428 /* "bgp always-compare-med" commands */
12429 install_element(BGP_NODE, &bgp_always_compare_med_cmd);
12430 install_element(BGP_NODE, &no_bgp_always_compare_med_cmd);
12431
12432 /* "bgp deterministic-med" commands */
12433 install_element(BGP_NODE, &bgp_deterministic_med_cmd);
12434 install_element(BGP_NODE, &no_bgp_deterministic_med_cmd);
12435
12436 /* "bgp graceful-restart" commands */
12437 install_element(BGP_NODE, &bgp_graceful_restart_cmd);
12438 install_element(BGP_NODE, &no_bgp_graceful_restart_cmd);
12439 install_element(BGP_NODE, &bgp_graceful_restart_stalepath_time_cmd);
12440 install_element(BGP_NODE, &no_bgp_graceful_restart_stalepath_time_cmd);
12441 install_element(BGP_NODE, &bgp_graceful_restart_restart_time_cmd);
12442 install_element(BGP_NODE, &no_bgp_graceful_restart_restart_time_cmd);
12443
12444 install_element(BGP_NODE, &bgp_graceful_restart_preserve_fw_cmd);
12445 install_element(BGP_NODE, &no_bgp_graceful_restart_preserve_fw_cmd);
12446
12447 /* "bgp graceful-shutdown" commands */
12448 install_element(BGP_NODE, &bgp_graceful_shutdown_cmd);
12449 install_element(BGP_NODE, &no_bgp_graceful_shutdown_cmd);
12450
12451 /* "bgp fast-external-failover" commands */
12452 install_element(BGP_NODE, &bgp_fast_external_failover_cmd);
12453 install_element(BGP_NODE, &no_bgp_fast_external_failover_cmd);
12454
12455 /* "bgp enforce-first-as" commands */
12456 install_element(BGP_NODE, &bgp_enforce_first_as_cmd);
12457
12458 /* "bgp bestpath compare-routerid" commands */
12459 install_element(BGP_NODE, &bgp_bestpath_compare_router_id_cmd);
12460 install_element(BGP_NODE, &no_bgp_bestpath_compare_router_id_cmd);
12461
12462 /* "bgp bestpath as-path ignore" commands */
12463 install_element(BGP_NODE, &bgp_bestpath_aspath_ignore_cmd);
12464 install_element(BGP_NODE, &no_bgp_bestpath_aspath_ignore_cmd);
12465
12466 /* "bgp bestpath as-path confed" commands */
12467 install_element(BGP_NODE, &bgp_bestpath_aspath_confed_cmd);
12468 install_element(BGP_NODE, &no_bgp_bestpath_aspath_confed_cmd);
12469
12470 /* "bgp bestpath as-path multipath-relax" commands */
12471 install_element(BGP_NODE, &bgp_bestpath_aspath_multipath_relax_cmd);
12472 install_element(BGP_NODE, &no_bgp_bestpath_aspath_multipath_relax_cmd);
12473
12474 /* "bgp log-neighbor-changes" commands */
12475 install_element(BGP_NODE, &bgp_log_neighbor_changes_cmd);
12476 install_element(BGP_NODE, &no_bgp_log_neighbor_changes_cmd);
12477
12478 /* "bgp bestpath med" commands */
12479 install_element(BGP_NODE, &bgp_bestpath_med_cmd);
12480 install_element(BGP_NODE, &no_bgp_bestpath_med_cmd);
12481
12482 /* "no bgp default ipv4-unicast" commands. */
12483 install_element(BGP_NODE, &no_bgp_default_ipv4_unicast_cmd);
12484 install_element(BGP_NODE, &bgp_default_ipv4_unicast_cmd);
12485
12486 /* "bgp network import-check" commands. */
12487 install_element(BGP_NODE, &bgp_network_import_check_cmd);
12488 install_element(BGP_NODE, &bgp_network_import_check_exact_cmd);
12489 install_element(BGP_NODE, &no_bgp_network_import_check_cmd);
12490
12491 /* "bgp default local-preference" commands. */
12492 install_element(BGP_NODE, &bgp_default_local_preference_cmd);
12493 install_element(BGP_NODE, &no_bgp_default_local_preference_cmd);
12494
12495 /* bgp default show-hostname */
12496 install_element(BGP_NODE, &bgp_default_show_hostname_cmd);
12497 install_element(BGP_NODE, &no_bgp_default_show_hostname_cmd);
12498
12499 /* "bgp default subgroup-pkt-queue-max" commands. */
12500 install_element(BGP_NODE, &bgp_default_subgroup_pkt_queue_max_cmd);
12501 install_element(BGP_NODE, &no_bgp_default_subgroup_pkt_queue_max_cmd);
12502
12503 /* bgp ibgp-allow-policy-mods command */
12504 install_element(BGP_NODE, &bgp_rr_allow_outbound_policy_cmd);
12505 install_element(BGP_NODE, &no_bgp_rr_allow_outbound_policy_cmd);
12506
12507 /* "bgp listen limit" commands. */
12508 install_element(BGP_NODE, &bgp_listen_limit_cmd);
12509 install_element(BGP_NODE, &no_bgp_listen_limit_cmd);
12510
12511 /* "bgp listen range" commands. */
12512 install_element(BGP_NODE, &bgp_listen_range_cmd);
12513 install_element(BGP_NODE, &no_bgp_listen_range_cmd);
12514
12515 /* "bgp default shutdown" command */
12516 install_element(BGP_NODE, &bgp_default_shutdown_cmd);
12517
12518 /* "neighbor remote-as" commands. */
12519 install_element(BGP_NODE, &neighbor_remote_as_cmd);
12520 install_element(BGP_NODE, &neighbor_interface_config_cmd);
12521 install_element(BGP_NODE, &neighbor_interface_config_v6only_cmd);
12522 install_element(BGP_NODE, &neighbor_interface_config_remote_as_cmd);
12523 install_element(BGP_NODE,
12524 &neighbor_interface_v6only_config_remote_as_cmd);
12525 install_element(BGP_NODE, &no_neighbor_cmd);
12526 install_element(BGP_NODE, &no_neighbor_interface_config_cmd);
12527
12528 /* "neighbor peer-group" commands. */
12529 install_element(BGP_NODE, &neighbor_peer_group_cmd);
12530 install_element(BGP_NODE, &no_neighbor_peer_group_cmd);
12531 install_element(BGP_NODE,
12532 &no_neighbor_interface_peer_group_remote_as_cmd);
12533
12534 /* "neighbor local-as" commands. */
12535 install_element(BGP_NODE, &neighbor_local_as_cmd);
12536 install_element(BGP_NODE, &neighbor_local_as_no_prepend_cmd);
12537 install_element(BGP_NODE, &neighbor_local_as_no_prepend_replace_as_cmd);
12538 install_element(BGP_NODE, &no_neighbor_local_as_cmd);
12539
12540 /* "neighbor solo" commands. */
12541 install_element(BGP_NODE, &neighbor_solo_cmd);
12542 install_element(BGP_NODE, &no_neighbor_solo_cmd);
12543
12544 /* "neighbor password" commands. */
12545 install_element(BGP_NODE, &neighbor_password_cmd);
12546 install_element(BGP_NODE, &no_neighbor_password_cmd);
12547
12548 /* "neighbor activate" commands. */
12549 install_element(BGP_NODE, &neighbor_activate_hidden_cmd);
12550 install_element(BGP_IPV4_NODE, &neighbor_activate_cmd);
12551 install_element(BGP_IPV4M_NODE, &neighbor_activate_cmd);
12552 install_element(BGP_IPV4L_NODE, &neighbor_activate_cmd);
12553 install_element(BGP_IPV6_NODE, &neighbor_activate_cmd);
12554 install_element(BGP_IPV6M_NODE, &neighbor_activate_cmd);
12555 install_element(BGP_IPV6L_NODE, &neighbor_activate_cmd);
12556 install_element(BGP_VPNV4_NODE, &neighbor_activate_cmd);
12557 install_element(BGP_VPNV6_NODE, &neighbor_activate_cmd);
12558 install_element(BGP_FLOWSPECV4_NODE, &neighbor_activate_cmd);
12559 install_element(BGP_FLOWSPECV6_NODE, &neighbor_activate_cmd);
12560 install_element(BGP_EVPN_NODE, &neighbor_activate_cmd);
12561
12562 /* "no neighbor activate" commands. */
12563 install_element(BGP_NODE, &no_neighbor_activate_hidden_cmd);
12564 install_element(BGP_IPV4_NODE, &no_neighbor_activate_cmd);
12565 install_element(BGP_IPV4M_NODE, &no_neighbor_activate_cmd);
12566 install_element(BGP_IPV4L_NODE, &no_neighbor_activate_cmd);
12567 install_element(BGP_IPV6_NODE, &no_neighbor_activate_cmd);
12568 install_element(BGP_IPV6M_NODE, &no_neighbor_activate_cmd);
12569 install_element(BGP_IPV6L_NODE, &no_neighbor_activate_cmd);
12570 install_element(BGP_VPNV4_NODE, &no_neighbor_activate_cmd);
12571 install_element(BGP_VPNV6_NODE, &no_neighbor_activate_cmd);
12572 install_element(BGP_FLOWSPECV4_NODE, &no_neighbor_activate_cmd);
12573 install_element(BGP_FLOWSPECV6_NODE, &no_neighbor_activate_cmd);
12574 install_element(BGP_EVPN_NODE, &no_neighbor_activate_cmd);
12575
12576 /* "neighbor peer-group" set commands. */
12577 install_element(BGP_NODE, &neighbor_set_peer_group_cmd);
12578 install_element(BGP_IPV4_NODE, &neighbor_set_peer_group_hidden_cmd);
12579 install_element(BGP_IPV4M_NODE, &neighbor_set_peer_group_hidden_cmd);
12580 install_element(BGP_IPV6_NODE, &neighbor_set_peer_group_hidden_cmd);
12581 install_element(BGP_IPV6M_NODE, &neighbor_set_peer_group_hidden_cmd);
12582 install_element(BGP_IPV6L_NODE, &neighbor_set_peer_group_hidden_cmd);
12583 install_element(BGP_VPNV4_NODE, &neighbor_set_peer_group_hidden_cmd);
12584 install_element(BGP_VPNV6_NODE, &neighbor_set_peer_group_hidden_cmd);
12585 install_element(BGP_FLOWSPECV4_NODE,
12586 &neighbor_set_peer_group_hidden_cmd);
12587 install_element(BGP_FLOWSPECV6_NODE,
12588 &neighbor_set_peer_group_hidden_cmd);
12589
12590 /* "no neighbor peer-group unset" commands. */
12591 install_element(BGP_NODE, &no_neighbor_set_peer_group_cmd);
12592 install_element(BGP_IPV4_NODE, &no_neighbor_set_peer_group_hidden_cmd);
12593 install_element(BGP_IPV4M_NODE, &no_neighbor_set_peer_group_hidden_cmd);
12594 install_element(BGP_IPV6_NODE, &no_neighbor_set_peer_group_hidden_cmd);
12595 install_element(BGP_IPV6M_NODE, &no_neighbor_set_peer_group_hidden_cmd);
12596 install_element(BGP_IPV6L_NODE, &no_neighbor_set_peer_group_hidden_cmd);
12597 install_element(BGP_VPNV4_NODE, &no_neighbor_set_peer_group_hidden_cmd);
12598 install_element(BGP_VPNV6_NODE, &no_neighbor_set_peer_group_hidden_cmd);
12599 install_element(BGP_FLOWSPECV4_NODE,
12600 &no_neighbor_set_peer_group_hidden_cmd);
12601 install_element(BGP_FLOWSPECV6_NODE,
12602 &no_neighbor_set_peer_group_hidden_cmd);
12603
12604 /* "neighbor softreconfiguration inbound" commands.*/
12605 install_element(BGP_NODE, &neighbor_soft_reconfiguration_hidden_cmd);
12606 install_element(BGP_NODE, &no_neighbor_soft_reconfiguration_hidden_cmd);
12607 install_element(BGP_IPV4_NODE, &neighbor_soft_reconfiguration_cmd);
12608 install_element(BGP_IPV4_NODE, &no_neighbor_soft_reconfiguration_cmd);
12609 install_element(BGP_IPV4L_NODE, &neighbor_soft_reconfiguration_cmd);
12610 install_element(BGP_IPV4L_NODE, &no_neighbor_soft_reconfiguration_cmd);
12611 install_element(BGP_IPV4M_NODE, &neighbor_soft_reconfiguration_cmd);
12612 install_element(BGP_IPV4M_NODE, &no_neighbor_soft_reconfiguration_cmd);
12613 install_element(BGP_IPV6_NODE, &neighbor_soft_reconfiguration_cmd);
12614 install_element(BGP_IPV6_NODE, &no_neighbor_soft_reconfiguration_cmd);
12615 install_element(BGP_IPV6M_NODE, &neighbor_soft_reconfiguration_cmd);
12616 install_element(BGP_IPV6M_NODE, &no_neighbor_soft_reconfiguration_cmd);
12617 install_element(BGP_IPV6L_NODE, &neighbor_soft_reconfiguration_cmd);
12618 install_element(BGP_IPV6L_NODE, &no_neighbor_soft_reconfiguration_cmd);
12619 install_element(BGP_VPNV4_NODE, &neighbor_soft_reconfiguration_cmd);
12620 install_element(BGP_VPNV4_NODE, &no_neighbor_soft_reconfiguration_cmd);
12621 install_element(BGP_VPNV6_NODE, &neighbor_soft_reconfiguration_cmd);
12622 install_element(BGP_VPNV6_NODE, &no_neighbor_soft_reconfiguration_cmd);
12623 install_element(BGP_FLOWSPECV4_NODE,
12624 &neighbor_soft_reconfiguration_cmd);
12625 install_element(BGP_FLOWSPECV4_NODE,
12626 &no_neighbor_soft_reconfiguration_cmd);
12627 install_element(BGP_FLOWSPECV6_NODE,
12628 &neighbor_soft_reconfiguration_cmd);
12629 install_element(BGP_FLOWSPECV6_NODE,
12630 &no_neighbor_soft_reconfiguration_cmd);
12631
12632 /* "neighbor attribute-unchanged" commands. */
12633 install_element(BGP_NODE, &neighbor_attr_unchanged_hidden_cmd);
12634 install_element(BGP_NODE, &no_neighbor_attr_unchanged_hidden_cmd);
12635 install_element(BGP_IPV4_NODE, &neighbor_attr_unchanged_cmd);
12636 install_element(BGP_IPV4_NODE, &no_neighbor_attr_unchanged_cmd);
12637 install_element(BGP_IPV4M_NODE, &neighbor_attr_unchanged_cmd);
12638 install_element(BGP_IPV4M_NODE, &no_neighbor_attr_unchanged_cmd);
12639 install_element(BGP_IPV4L_NODE, &neighbor_attr_unchanged_cmd);
12640 install_element(BGP_IPV4L_NODE, &no_neighbor_attr_unchanged_cmd);
12641 install_element(BGP_IPV6_NODE, &neighbor_attr_unchanged_cmd);
12642 install_element(BGP_IPV6_NODE, &no_neighbor_attr_unchanged_cmd);
12643 install_element(BGP_IPV6M_NODE, &neighbor_attr_unchanged_cmd);
12644 install_element(BGP_IPV6M_NODE, &no_neighbor_attr_unchanged_cmd);
12645 install_element(BGP_IPV6L_NODE, &neighbor_attr_unchanged_cmd);
12646 install_element(BGP_IPV6L_NODE, &no_neighbor_attr_unchanged_cmd);
12647 install_element(BGP_VPNV4_NODE, &neighbor_attr_unchanged_cmd);
12648 install_element(BGP_VPNV4_NODE, &no_neighbor_attr_unchanged_cmd);
12649 install_element(BGP_VPNV6_NODE, &neighbor_attr_unchanged_cmd);
12650 install_element(BGP_VPNV6_NODE, &no_neighbor_attr_unchanged_cmd);
12651
12652 install_element(BGP_EVPN_NODE, &neighbor_attr_unchanged_cmd);
12653 install_element(BGP_EVPN_NODE, &no_neighbor_attr_unchanged_cmd);
12654
12655 /* "nexthop-local unchanged" commands */
12656 install_element(BGP_IPV6_NODE, &neighbor_nexthop_local_unchanged_cmd);
12657 install_element(BGP_IPV6_NODE,
12658 &no_neighbor_nexthop_local_unchanged_cmd);
12659
12660 /* "neighbor next-hop-self" commands. */
12661 install_element(BGP_NODE, &neighbor_nexthop_self_hidden_cmd);
12662 install_element(BGP_NODE, &no_neighbor_nexthop_self_hidden_cmd);
12663 install_element(BGP_IPV4_NODE, &neighbor_nexthop_self_cmd);
12664 install_element(BGP_IPV4_NODE, &no_neighbor_nexthop_self_cmd);
12665 install_element(BGP_IPV4M_NODE, &neighbor_nexthop_self_cmd);
12666 install_element(BGP_IPV4M_NODE, &no_neighbor_nexthop_self_cmd);
12667 install_element(BGP_IPV4L_NODE, &neighbor_nexthop_self_cmd);
12668 install_element(BGP_IPV4L_NODE, &no_neighbor_nexthop_self_cmd);
12669 install_element(BGP_IPV6_NODE, &neighbor_nexthop_self_cmd);
12670 install_element(BGP_IPV6_NODE, &no_neighbor_nexthop_self_cmd);
12671 install_element(BGP_IPV6M_NODE, &neighbor_nexthop_self_cmd);
12672 install_element(BGP_IPV6M_NODE, &no_neighbor_nexthop_self_cmd);
12673 install_element(BGP_IPV6L_NODE, &neighbor_nexthop_self_cmd);
12674 install_element(BGP_IPV6L_NODE, &no_neighbor_nexthop_self_cmd);
12675 install_element(BGP_VPNV4_NODE, &neighbor_nexthop_self_cmd);
12676 install_element(BGP_VPNV4_NODE, &no_neighbor_nexthop_self_cmd);
12677 install_element(BGP_VPNV6_NODE, &neighbor_nexthop_self_cmd);
12678 install_element(BGP_VPNV6_NODE, &no_neighbor_nexthop_self_cmd);
12679 install_element(BGP_EVPN_NODE, &neighbor_nexthop_self_cmd);
12680 install_element(BGP_EVPN_NODE, &no_neighbor_nexthop_self_cmd);
12681
12682 /* "neighbor next-hop-self force" commands. */
12683 install_element(BGP_NODE, &neighbor_nexthop_self_force_hidden_cmd);
12684 install_element(BGP_NODE, &no_neighbor_nexthop_self_force_hidden_cmd);
12685 install_element(BGP_IPV4_NODE, &neighbor_nexthop_self_force_cmd);
12686 install_element(BGP_IPV4_NODE, &no_neighbor_nexthop_self_force_cmd);
12687 install_element(BGP_IPV4M_NODE, &neighbor_nexthop_self_force_cmd);
12688 install_element(BGP_IPV4M_NODE, &no_neighbor_nexthop_self_force_cmd);
12689 install_element(BGP_IPV4L_NODE, &neighbor_nexthop_self_force_cmd);
12690 install_element(BGP_IPV4L_NODE, &no_neighbor_nexthop_self_force_cmd);
12691 install_element(BGP_IPV6_NODE, &neighbor_nexthop_self_force_cmd);
12692 install_element(BGP_IPV6_NODE, &no_neighbor_nexthop_self_force_cmd);
12693 install_element(BGP_IPV6M_NODE, &neighbor_nexthop_self_force_cmd);
12694 install_element(BGP_IPV6M_NODE, &no_neighbor_nexthop_self_force_cmd);
12695 install_element(BGP_IPV6L_NODE, &neighbor_nexthop_self_force_cmd);
12696 install_element(BGP_IPV6L_NODE, &no_neighbor_nexthop_self_force_cmd);
12697 install_element(BGP_VPNV4_NODE, &neighbor_nexthop_self_force_cmd);
12698 install_element(BGP_VPNV4_NODE, &no_neighbor_nexthop_self_force_cmd);
12699 install_element(BGP_VPNV6_NODE, &neighbor_nexthop_self_force_cmd);
12700 install_element(BGP_VPNV6_NODE, &no_neighbor_nexthop_self_force_cmd);
12701
12702 /* "neighbor as-override" commands. */
12703 install_element(BGP_NODE, &neighbor_as_override_hidden_cmd);
12704 install_element(BGP_NODE, &no_neighbor_as_override_hidden_cmd);
12705 install_element(BGP_IPV4_NODE, &neighbor_as_override_cmd);
12706 install_element(BGP_IPV4_NODE, &no_neighbor_as_override_cmd);
12707 install_element(BGP_IPV4M_NODE, &neighbor_as_override_cmd);
12708 install_element(BGP_IPV4M_NODE, &no_neighbor_as_override_cmd);
12709 install_element(BGP_IPV4L_NODE, &neighbor_as_override_cmd);
12710 install_element(BGP_IPV4L_NODE, &no_neighbor_as_override_cmd);
12711 install_element(BGP_IPV6_NODE, &neighbor_as_override_cmd);
12712 install_element(BGP_IPV6_NODE, &no_neighbor_as_override_cmd);
12713 install_element(BGP_IPV6M_NODE, &neighbor_as_override_cmd);
12714 install_element(BGP_IPV6M_NODE, &no_neighbor_as_override_cmd);
12715 install_element(BGP_IPV6L_NODE, &neighbor_as_override_cmd);
12716 install_element(BGP_IPV6L_NODE, &no_neighbor_as_override_cmd);
12717 install_element(BGP_VPNV4_NODE, &neighbor_as_override_cmd);
12718 install_element(BGP_VPNV4_NODE, &no_neighbor_as_override_cmd);
12719 install_element(BGP_VPNV6_NODE, &neighbor_as_override_cmd);
12720 install_element(BGP_VPNV6_NODE, &no_neighbor_as_override_cmd);
12721
12722 /* "neighbor remove-private-AS" commands. */
12723 install_element(BGP_NODE, &neighbor_remove_private_as_hidden_cmd);
12724 install_element(BGP_NODE, &no_neighbor_remove_private_as_hidden_cmd);
12725 install_element(BGP_NODE, &neighbor_remove_private_as_all_hidden_cmd);
12726 install_element(BGP_NODE,
12727 &no_neighbor_remove_private_as_all_hidden_cmd);
12728 install_element(BGP_NODE,
12729 &neighbor_remove_private_as_replace_as_hidden_cmd);
12730 install_element(BGP_NODE,
12731 &no_neighbor_remove_private_as_replace_as_hidden_cmd);
12732 install_element(BGP_NODE,
12733 &neighbor_remove_private_as_all_replace_as_hidden_cmd);
12734 install_element(
12735 BGP_NODE,
12736 &no_neighbor_remove_private_as_all_replace_as_hidden_cmd);
12737 install_element(BGP_IPV4_NODE, &neighbor_remove_private_as_cmd);
12738 install_element(BGP_IPV4_NODE, &no_neighbor_remove_private_as_cmd);
12739 install_element(BGP_IPV4_NODE, &neighbor_remove_private_as_all_cmd);
12740 install_element(BGP_IPV4_NODE, &no_neighbor_remove_private_as_all_cmd);
12741 install_element(BGP_IPV4_NODE,
12742 &neighbor_remove_private_as_replace_as_cmd);
12743 install_element(BGP_IPV4_NODE,
12744 &no_neighbor_remove_private_as_replace_as_cmd);
12745 install_element(BGP_IPV4_NODE,
12746 &neighbor_remove_private_as_all_replace_as_cmd);
12747 install_element(BGP_IPV4_NODE,
12748 &no_neighbor_remove_private_as_all_replace_as_cmd);
12749 install_element(BGP_IPV4M_NODE, &neighbor_remove_private_as_cmd);
12750 install_element(BGP_IPV4M_NODE, &no_neighbor_remove_private_as_cmd);
12751 install_element(BGP_IPV4M_NODE, &neighbor_remove_private_as_all_cmd);
12752 install_element(BGP_IPV4M_NODE, &no_neighbor_remove_private_as_all_cmd);
12753 install_element(BGP_IPV4M_NODE,
12754 &neighbor_remove_private_as_replace_as_cmd);
12755 install_element(BGP_IPV4M_NODE,
12756 &no_neighbor_remove_private_as_replace_as_cmd);
12757 install_element(BGP_IPV4M_NODE,
12758 &neighbor_remove_private_as_all_replace_as_cmd);
12759 install_element(BGP_IPV4M_NODE,
12760 &no_neighbor_remove_private_as_all_replace_as_cmd);
12761 install_element(BGP_IPV4L_NODE, &neighbor_remove_private_as_cmd);
12762 install_element(BGP_IPV4L_NODE, &no_neighbor_remove_private_as_cmd);
12763 install_element(BGP_IPV4L_NODE, &neighbor_remove_private_as_all_cmd);
12764 install_element(BGP_IPV4L_NODE, &no_neighbor_remove_private_as_all_cmd);
12765 install_element(BGP_IPV4L_NODE,
12766 &neighbor_remove_private_as_replace_as_cmd);
12767 install_element(BGP_IPV4L_NODE,
12768 &no_neighbor_remove_private_as_replace_as_cmd);
12769 install_element(BGP_IPV4L_NODE,
12770 &neighbor_remove_private_as_all_replace_as_cmd);
12771 install_element(BGP_IPV4L_NODE,
12772 &no_neighbor_remove_private_as_all_replace_as_cmd);
12773 install_element(BGP_IPV6_NODE, &neighbor_remove_private_as_cmd);
12774 install_element(BGP_IPV6_NODE, &no_neighbor_remove_private_as_cmd);
12775 install_element(BGP_IPV6_NODE, &neighbor_remove_private_as_all_cmd);
12776 install_element(BGP_IPV6_NODE, &no_neighbor_remove_private_as_all_cmd);
12777 install_element(BGP_IPV6_NODE,
12778 &neighbor_remove_private_as_replace_as_cmd);
12779 install_element(BGP_IPV6_NODE,
12780 &no_neighbor_remove_private_as_replace_as_cmd);
12781 install_element(BGP_IPV6_NODE,
12782 &neighbor_remove_private_as_all_replace_as_cmd);
12783 install_element(BGP_IPV6_NODE,
12784 &no_neighbor_remove_private_as_all_replace_as_cmd);
12785 install_element(BGP_IPV6M_NODE, &neighbor_remove_private_as_cmd);
12786 install_element(BGP_IPV6M_NODE, &no_neighbor_remove_private_as_cmd);
12787 install_element(BGP_IPV6M_NODE, &neighbor_remove_private_as_all_cmd);
12788 install_element(BGP_IPV6M_NODE, &no_neighbor_remove_private_as_all_cmd);
12789 install_element(BGP_IPV6M_NODE,
12790 &neighbor_remove_private_as_replace_as_cmd);
12791 install_element(BGP_IPV6M_NODE,
12792 &no_neighbor_remove_private_as_replace_as_cmd);
12793 install_element(BGP_IPV6M_NODE,
12794 &neighbor_remove_private_as_all_replace_as_cmd);
12795 install_element(BGP_IPV6M_NODE,
12796 &no_neighbor_remove_private_as_all_replace_as_cmd);
12797 install_element(BGP_IPV6L_NODE, &neighbor_remove_private_as_cmd);
12798 install_element(BGP_IPV6L_NODE, &no_neighbor_remove_private_as_cmd);
12799 install_element(BGP_IPV6L_NODE, &neighbor_remove_private_as_all_cmd);
12800 install_element(BGP_IPV6L_NODE, &no_neighbor_remove_private_as_all_cmd);
12801 install_element(BGP_IPV6L_NODE,
12802 &neighbor_remove_private_as_replace_as_cmd);
12803 install_element(BGP_IPV6L_NODE,
12804 &no_neighbor_remove_private_as_replace_as_cmd);
12805 install_element(BGP_IPV6L_NODE,
12806 &neighbor_remove_private_as_all_replace_as_cmd);
12807 install_element(BGP_IPV6L_NODE,
12808 &no_neighbor_remove_private_as_all_replace_as_cmd);
12809 install_element(BGP_VPNV4_NODE, &neighbor_remove_private_as_cmd);
12810 install_element(BGP_VPNV4_NODE, &no_neighbor_remove_private_as_cmd);
12811 install_element(BGP_VPNV4_NODE, &neighbor_remove_private_as_all_cmd);
12812 install_element(BGP_VPNV4_NODE, &no_neighbor_remove_private_as_all_cmd);
12813 install_element(BGP_VPNV4_NODE,
12814 &neighbor_remove_private_as_replace_as_cmd);
12815 install_element(BGP_VPNV4_NODE,
12816 &no_neighbor_remove_private_as_replace_as_cmd);
12817 install_element(BGP_VPNV4_NODE,
12818 &neighbor_remove_private_as_all_replace_as_cmd);
12819 install_element(BGP_VPNV4_NODE,
12820 &no_neighbor_remove_private_as_all_replace_as_cmd);
12821 install_element(BGP_VPNV6_NODE, &neighbor_remove_private_as_cmd);
12822 install_element(BGP_VPNV6_NODE, &no_neighbor_remove_private_as_cmd);
12823 install_element(BGP_VPNV6_NODE, &neighbor_remove_private_as_all_cmd);
12824 install_element(BGP_VPNV6_NODE, &no_neighbor_remove_private_as_all_cmd);
12825 install_element(BGP_VPNV6_NODE,
12826 &neighbor_remove_private_as_replace_as_cmd);
12827 install_element(BGP_VPNV6_NODE,
12828 &no_neighbor_remove_private_as_replace_as_cmd);
12829 install_element(BGP_VPNV6_NODE,
12830 &neighbor_remove_private_as_all_replace_as_cmd);
12831 install_element(BGP_VPNV6_NODE,
12832 &no_neighbor_remove_private_as_all_replace_as_cmd);
12833
12834 /* "neighbor send-community" commands.*/
12835 install_element(BGP_NODE, &neighbor_send_community_hidden_cmd);
12836 install_element(BGP_NODE, &neighbor_send_community_type_hidden_cmd);
12837 install_element(BGP_NODE, &no_neighbor_send_community_hidden_cmd);
12838 install_element(BGP_NODE, &no_neighbor_send_community_type_hidden_cmd);
12839 install_element(BGP_IPV4_NODE, &neighbor_send_community_cmd);
12840 install_element(BGP_IPV4_NODE, &neighbor_send_community_type_cmd);
12841 install_element(BGP_IPV4_NODE, &no_neighbor_send_community_cmd);
12842 install_element(BGP_IPV4_NODE, &no_neighbor_send_community_type_cmd);
12843 install_element(BGP_IPV4M_NODE, &neighbor_send_community_cmd);
12844 install_element(BGP_IPV4M_NODE, &neighbor_send_community_type_cmd);
12845 install_element(BGP_IPV4M_NODE, &no_neighbor_send_community_cmd);
12846 install_element(BGP_IPV4M_NODE, &no_neighbor_send_community_type_cmd);
12847 install_element(BGP_IPV4L_NODE, &neighbor_send_community_cmd);
12848 install_element(BGP_IPV4L_NODE, &neighbor_send_community_type_cmd);
12849 install_element(BGP_IPV4L_NODE, &no_neighbor_send_community_cmd);
12850 install_element(BGP_IPV4L_NODE, &no_neighbor_send_community_type_cmd);
12851 install_element(BGP_IPV6_NODE, &neighbor_send_community_cmd);
12852 install_element(BGP_IPV6_NODE, &neighbor_send_community_type_cmd);
12853 install_element(BGP_IPV6_NODE, &no_neighbor_send_community_cmd);
12854 install_element(BGP_IPV6_NODE, &no_neighbor_send_community_type_cmd);
12855 install_element(BGP_IPV6M_NODE, &neighbor_send_community_cmd);
12856 install_element(BGP_IPV6M_NODE, &neighbor_send_community_type_cmd);
12857 install_element(BGP_IPV6M_NODE, &no_neighbor_send_community_cmd);
12858 install_element(BGP_IPV6M_NODE, &no_neighbor_send_community_type_cmd);
12859 install_element(BGP_IPV6L_NODE, &neighbor_send_community_cmd);
12860 install_element(BGP_IPV6L_NODE, &neighbor_send_community_type_cmd);
12861 install_element(BGP_IPV6L_NODE, &no_neighbor_send_community_cmd);
12862 install_element(BGP_IPV6L_NODE, &no_neighbor_send_community_type_cmd);
12863 install_element(BGP_VPNV4_NODE, &neighbor_send_community_cmd);
12864 install_element(BGP_VPNV4_NODE, &neighbor_send_community_type_cmd);
12865 install_element(BGP_VPNV4_NODE, &no_neighbor_send_community_cmd);
12866 install_element(BGP_VPNV4_NODE, &no_neighbor_send_community_type_cmd);
12867 install_element(BGP_VPNV6_NODE, &neighbor_send_community_cmd);
12868 install_element(BGP_VPNV6_NODE, &neighbor_send_community_type_cmd);
12869 install_element(BGP_VPNV6_NODE, &no_neighbor_send_community_cmd);
12870 install_element(BGP_VPNV6_NODE, &no_neighbor_send_community_type_cmd);
12871
12872 /* "neighbor route-reflector" commands.*/
12873 install_element(BGP_NODE, &neighbor_route_reflector_client_hidden_cmd);
12874 install_element(BGP_NODE,
12875 &no_neighbor_route_reflector_client_hidden_cmd);
12876 install_element(BGP_IPV4_NODE, &neighbor_route_reflector_client_cmd);
12877 install_element(BGP_IPV4_NODE, &no_neighbor_route_reflector_client_cmd);
12878 install_element(BGP_IPV4M_NODE, &neighbor_route_reflector_client_cmd);
12879 install_element(BGP_IPV4M_NODE,
12880 &no_neighbor_route_reflector_client_cmd);
12881 install_element(BGP_IPV4L_NODE, &neighbor_route_reflector_client_cmd);
12882 install_element(BGP_IPV4L_NODE,
12883 &no_neighbor_route_reflector_client_cmd);
12884 install_element(BGP_IPV6_NODE, &neighbor_route_reflector_client_cmd);
12885 install_element(BGP_IPV6_NODE, &no_neighbor_route_reflector_client_cmd);
12886 install_element(BGP_IPV6M_NODE, &neighbor_route_reflector_client_cmd);
12887 install_element(BGP_IPV6M_NODE,
12888 &no_neighbor_route_reflector_client_cmd);
12889 install_element(BGP_IPV6L_NODE, &neighbor_route_reflector_client_cmd);
12890 install_element(BGP_IPV6L_NODE,
12891 &no_neighbor_route_reflector_client_cmd);
12892 install_element(BGP_VPNV4_NODE, &neighbor_route_reflector_client_cmd);
12893 install_element(BGP_VPNV4_NODE,
12894 &no_neighbor_route_reflector_client_cmd);
12895 install_element(BGP_VPNV6_NODE, &neighbor_route_reflector_client_cmd);
12896 install_element(BGP_VPNV6_NODE,
12897 &no_neighbor_route_reflector_client_cmd);
12898 install_element(BGP_FLOWSPECV4_NODE,
12899 &neighbor_route_reflector_client_cmd);
12900 install_element(BGP_FLOWSPECV4_NODE,
12901 &no_neighbor_route_reflector_client_cmd);
12902 install_element(BGP_FLOWSPECV6_NODE,
12903 &neighbor_route_reflector_client_cmd);
12904 install_element(BGP_FLOWSPECV6_NODE,
12905 &no_neighbor_route_reflector_client_cmd);
12906 install_element(BGP_EVPN_NODE, &neighbor_route_reflector_client_cmd);
12907 install_element(BGP_EVPN_NODE, &no_neighbor_route_reflector_client_cmd);
12908
12909 /* "neighbor route-server" commands.*/
12910 install_element(BGP_NODE, &neighbor_route_server_client_hidden_cmd);
12911 install_element(BGP_NODE, &no_neighbor_route_server_client_hidden_cmd);
12912 install_element(BGP_IPV4_NODE, &neighbor_route_server_client_cmd);
12913 install_element(BGP_IPV4_NODE, &no_neighbor_route_server_client_cmd);
12914 install_element(BGP_IPV4M_NODE, &neighbor_route_server_client_cmd);
12915 install_element(BGP_IPV4M_NODE, &no_neighbor_route_server_client_cmd);
12916 install_element(BGP_IPV4L_NODE, &neighbor_route_server_client_cmd);
12917 install_element(BGP_IPV4L_NODE, &no_neighbor_route_server_client_cmd);
12918 install_element(BGP_IPV6_NODE, &neighbor_route_server_client_cmd);
12919 install_element(BGP_IPV6_NODE, &no_neighbor_route_server_client_cmd);
12920 install_element(BGP_IPV6M_NODE, &neighbor_route_server_client_cmd);
12921 install_element(BGP_IPV6M_NODE, &no_neighbor_route_server_client_cmd);
12922 install_element(BGP_IPV6L_NODE, &neighbor_route_server_client_cmd);
12923 install_element(BGP_IPV6L_NODE, &no_neighbor_route_server_client_cmd);
12924 install_element(BGP_VPNV4_NODE, &neighbor_route_server_client_cmd);
12925 install_element(BGP_VPNV4_NODE, &no_neighbor_route_server_client_cmd);
12926 install_element(BGP_VPNV6_NODE, &neighbor_route_server_client_cmd);
12927 install_element(BGP_VPNV6_NODE, &no_neighbor_route_server_client_cmd);
12928 install_element(BGP_FLOWSPECV4_NODE, &neighbor_route_server_client_cmd);
12929 install_element(BGP_FLOWSPECV4_NODE,
12930 &no_neighbor_route_server_client_cmd);
12931 install_element(BGP_FLOWSPECV6_NODE, &neighbor_route_server_client_cmd);
12932 install_element(BGP_FLOWSPECV6_NODE,
12933 &no_neighbor_route_server_client_cmd);
12934
12935 /* "neighbor addpath-tx-all-paths" commands.*/
12936 install_element(BGP_NODE, &neighbor_addpath_tx_all_paths_hidden_cmd);
12937 install_element(BGP_NODE, &no_neighbor_addpath_tx_all_paths_hidden_cmd);
12938 install_element(BGP_IPV4_NODE, &neighbor_addpath_tx_all_paths_cmd);
12939 install_element(BGP_IPV4_NODE, &no_neighbor_addpath_tx_all_paths_cmd);
12940 install_element(BGP_IPV4M_NODE, &neighbor_addpath_tx_all_paths_cmd);
12941 install_element(BGP_IPV4M_NODE, &no_neighbor_addpath_tx_all_paths_cmd);
12942 install_element(BGP_IPV4L_NODE, &neighbor_addpath_tx_all_paths_cmd);
12943 install_element(BGP_IPV4L_NODE, &no_neighbor_addpath_tx_all_paths_cmd);
12944 install_element(BGP_IPV6_NODE, &neighbor_addpath_tx_all_paths_cmd);
12945 install_element(BGP_IPV6_NODE, &no_neighbor_addpath_tx_all_paths_cmd);
12946 install_element(BGP_IPV6M_NODE, &neighbor_addpath_tx_all_paths_cmd);
12947 install_element(BGP_IPV6M_NODE, &no_neighbor_addpath_tx_all_paths_cmd);
12948 install_element(BGP_IPV6L_NODE, &neighbor_addpath_tx_all_paths_cmd);
12949 install_element(BGP_IPV6L_NODE, &no_neighbor_addpath_tx_all_paths_cmd);
12950 install_element(BGP_VPNV4_NODE, &neighbor_addpath_tx_all_paths_cmd);
12951 install_element(BGP_VPNV4_NODE, &no_neighbor_addpath_tx_all_paths_cmd);
12952 install_element(BGP_VPNV6_NODE, &neighbor_addpath_tx_all_paths_cmd);
12953 install_element(BGP_VPNV6_NODE, &no_neighbor_addpath_tx_all_paths_cmd);
12954
12955 /* "neighbor addpath-tx-bestpath-per-AS" commands.*/
12956 install_element(BGP_NODE,
12957 &neighbor_addpath_tx_bestpath_per_as_hidden_cmd);
12958 install_element(BGP_NODE,
12959 &no_neighbor_addpath_tx_bestpath_per_as_hidden_cmd);
12960 install_element(BGP_IPV4_NODE,
12961 &neighbor_addpath_tx_bestpath_per_as_cmd);
12962 install_element(BGP_IPV4_NODE,
12963 &no_neighbor_addpath_tx_bestpath_per_as_cmd);
12964 install_element(BGP_IPV4M_NODE,
12965 &neighbor_addpath_tx_bestpath_per_as_cmd);
12966 install_element(BGP_IPV4M_NODE,
12967 &no_neighbor_addpath_tx_bestpath_per_as_cmd);
12968 install_element(BGP_IPV4L_NODE,
12969 &neighbor_addpath_tx_bestpath_per_as_cmd);
12970 install_element(BGP_IPV4L_NODE,
12971 &no_neighbor_addpath_tx_bestpath_per_as_cmd);
12972 install_element(BGP_IPV6_NODE,
12973 &neighbor_addpath_tx_bestpath_per_as_cmd);
12974 install_element(BGP_IPV6_NODE,
12975 &no_neighbor_addpath_tx_bestpath_per_as_cmd);
12976 install_element(BGP_IPV6M_NODE,
12977 &neighbor_addpath_tx_bestpath_per_as_cmd);
12978 install_element(BGP_IPV6M_NODE,
12979 &no_neighbor_addpath_tx_bestpath_per_as_cmd);
12980 install_element(BGP_IPV6L_NODE,
12981 &neighbor_addpath_tx_bestpath_per_as_cmd);
12982 install_element(BGP_IPV6L_NODE,
12983 &no_neighbor_addpath_tx_bestpath_per_as_cmd);
12984 install_element(BGP_VPNV4_NODE,
12985 &neighbor_addpath_tx_bestpath_per_as_cmd);
12986 install_element(BGP_VPNV4_NODE,
12987 &no_neighbor_addpath_tx_bestpath_per_as_cmd);
12988 install_element(BGP_VPNV6_NODE,
12989 &neighbor_addpath_tx_bestpath_per_as_cmd);
12990 install_element(BGP_VPNV6_NODE,
12991 &no_neighbor_addpath_tx_bestpath_per_as_cmd);
12992
12993 /* "neighbor passive" commands. */
12994 install_element(BGP_NODE, &neighbor_passive_cmd);
12995 install_element(BGP_NODE, &no_neighbor_passive_cmd);
12996
12997
12998 /* "neighbor shutdown" commands. */
12999 install_element(BGP_NODE, &neighbor_shutdown_cmd);
13000 install_element(BGP_NODE, &no_neighbor_shutdown_cmd);
13001 install_element(BGP_NODE, &neighbor_shutdown_msg_cmd);
13002 install_element(BGP_NODE, &no_neighbor_shutdown_msg_cmd);
13003
13004 /* "neighbor capability extended-nexthop" commands.*/
13005 install_element(BGP_NODE, &neighbor_capability_enhe_cmd);
13006 install_element(BGP_NODE, &no_neighbor_capability_enhe_cmd);
13007
13008 /* "neighbor capability orf prefix-list" commands.*/
13009 install_element(BGP_NODE, &neighbor_capability_orf_prefix_hidden_cmd);
13010 install_element(BGP_NODE,
13011 &no_neighbor_capability_orf_prefix_hidden_cmd);
13012 install_element(BGP_IPV4_NODE, &neighbor_capability_orf_prefix_cmd);
13013 install_element(BGP_IPV4_NODE, &no_neighbor_capability_orf_prefix_cmd);
13014 install_element(BGP_IPV4M_NODE, &neighbor_capability_orf_prefix_cmd);
13015 install_element(BGP_IPV4M_NODE, &no_neighbor_capability_orf_prefix_cmd);
13016 install_element(BGP_IPV4L_NODE, &neighbor_capability_orf_prefix_cmd);
13017 install_element(BGP_IPV4L_NODE, &no_neighbor_capability_orf_prefix_cmd);
13018 install_element(BGP_IPV6_NODE, &neighbor_capability_orf_prefix_cmd);
13019 install_element(BGP_IPV6_NODE, &no_neighbor_capability_orf_prefix_cmd);
13020 install_element(BGP_IPV6M_NODE, &neighbor_capability_orf_prefix_cmd);
13021 install_element(BGP_IPV6M_NODE, &no_neighbor_capability_orf_prefix_cmd);
13022 install_element(BGP_IPV6L_NODE, &neighbor_capability_orf_prefix_cmd);
13023 install_element(BGP_IPV6L_NODE, &no_neighbor_capability_orf_prefix_cmd);
13024
13025 /* "neighbor capability dynamic" commands.*/
13026 install_element(BGP_NODE, &neighbor_capability_dynamic_cmd);
13027 install_element(BGP_NODE, &no_neighbor_capability_dynamic_cmd);
13028
13029 /* "neighbor dont-capability-negotiate" commands. */
13030 install_element(BGP_NODE, &neighbor_dont_capability_negotiate_cmd);
13031 install_element(BGP_NODE, &no_neighbor_dont_capability_negotiate_cmd);
13032
13033 /* "neighbor ebgp-multihop" commands. */
13034 install_element(BGP_NODE, &neighbor_ebgp_multihop_cmd);
13035 install_element(BGP_NODE, &neighbor_ebgp_multihop_ttl_cmd);
13036 install_element(BGP_NODE, &no_neighbor_ebgp_multihop_cmd);
13037
13038 /* "neighbor disable-connected-check" commands. */
13039 install_element(BGP_NODE, &neighbor_disable_connected_check_cmd);
13040 install_element(BGP_NODE, &no_neighbor_disable_connected_check_cmd);
13041
13042 /* "neighbor enforce-first-as" commands. */
13043 install_element(BGP_NODE, &neighbor_enforce_first_as_cmd);
13044 install_element(BGP_NODE, &no_neighbor_enforce_first_as_cmd);
13045
13046 /* "neighbor description" commands. */
13047 install_element(BGP_NODE, &neighbor_description_cmd);
13048 install_element(BGP_NODE, &no_neighbor_description_cmd);
13049 install_element(BGP_NODE, &no_neighbor_description_comment_cmd);
13050
13051 /* "neighbor update-source" commands. "*/
13052 install_element(BGP_NODE, &neighbor_update_source_cmd);
13053 install_element(BGP_NODE, &no_neighbor_update_source_cmd);
13054
13055 /* "neighbor default-originate" commands. */
13056 install_element(BGP_NODE, &neighbor_default_originate_hidden_cmd);
13057 install_element(BGP_NODE, &neighbor_default_originate_rmap_hidden_cmd);
13058 install_element(BGP_NODE, &no_neighbor_default_originate_hidden_cmd);
13059 install_element(BGP_IPV4_NODE, &neighbor_default_originate_cmd);
13060 install_element(BGP_IPV4_NODE, &neighbor_default_originate_rmap_cmd);
13061 install_element(BGP_IPV4_NODE, &no_neighbor_default_originate_cmd);
13062 install_element(BGP_IPV4M_NODE, &neighbor_default_originate_cmd);
13063 install_element(BGP_IPV4M_NODE, &neighbor_default_originate_rmap_cmd);
13064 install_element(BGP_IPV4M_NODE, &no_neighbor_default_originate_cmd);
13065 install_element(BGP_IPV4L_NODE, &neighbor_default_originate_cmd);
13066 install_element(BGP_IPV4L_NODE, &neighbor_default_originate_rmap_cmd);
13067 install_element(BGP_IPV4L_NODE, &no_neighbor_default_originate_cmd);
13068 install_element(BGP_IPV6_NODE, &neighbor_default_originate_cmd);
13069 install_element(BGP_IPV6_NODE, &neighbor_default_originate_rmap_cmd);
13070 install_element(BGP_IPV6_NODE, &no_neighbor_default_originate_cmd);
13071 install_element(BGP_IPV6M_NODE, &neighbor_default_originate_cmd);
13072 install_element(BGP_IPV6M_NODE, &neighbor_default_originate_rmap_cmd);
13073 install_element(BGP_IPV6M_NODE, &no_neighbor_default_originate_cmd);
13074 install_element(BGP_IPV6L_NODE, &neighbor_default_originate_cmd);
13075 install_element(BGP_IPV6L_NODE, &neighbor_default_originate_rmap_cmd);
13076 install_element(BGP_IPV6L_NODE, &no_neighbor_default_originate_cmd);
13077
13078 /* "neighbor port" commands. */
13079 install_element(BGP_NODE, &neighbor_port_cmd);
13080 install_element(BGP_NODE, &no_neighbor_port_cmd);
13081
13082 /* "neighbor weight" commands. */
13083 install_element(BGP_NODE, &neighbor_weight_hidden_cmd);
13084 install_element(BGP_NODE, &no_neighbor_weight_hidden_cmd);
13085
13086 install_element(BGP_IPV4_NODE, &neighbor_weight_cmd);
13087 install_element(BGP_IPV4_NODE, &no_neighbor_weight_cmd);
13088 install_element(BGP_IPV4M_NODE, &neighbor_weight_cmd);
13089 install_element(BGP_IPV4M_NODE, &no_neighbor_weight_cmd);
13090 install_element(BGP_IPV4L_NODE, &neighbor_weight_cmd);
13091 install_element(BGP_IPV4L_NODE, &no_neighbor_weight_cmd);
13092 install_element(BGP_IPV6_NODE, &neighbor_weight_cmd);
13093 install_element(BGP_IPV6_NODE, &no_neighbor_weight_cmd);
13094 install_element(BGP_IPV6M_NODE, &neighbor_weight_cmd);
13095 install_element(BGP_IPV6M_NODE, &no_neighbor_weight_cmd);
13096 install_element(BGP_IPV6L_NODE, &neighbor_weight_cmd);
13097 install_element(BGP_IPV6L_NODE, &no_neighbor_weight_cmd);
13098 install_element(BGP_VPNV4_NODE, &neighbor_weight_cmd);
13099 install_element(BGP_VPNV4_NODE, &no_neighbor_weight_cmd);
13100 install_element(BGP_VPNV6_NODE, &neighbor_weight_cmd);
13101 install_element(BGP_VPNV6_NODE, &no_neighbor_weight_cmd);
13102
13103 /* "neighbor override-capability" commands. */
13104 install_element(BGP_NODE, &neighbor_override_capability_cmd);
13105 install_element(BGP_NODE, &no_neighbor_override_capability_cmd);
13106
13107 /* "neighbor strict-capability-match" commands. */
13108 install_element(BGP_NODE, &neighbor_strict_capability_cmd);
13109 install_element(BGP_NODE, &no_neighbor_strict_capability_cmd);
13110
13111 /* "neighbor timers" commands. */
13112 install_element(BGP_NODE, &neighbor_timers_cmd);
13113 install_element(BGP_NODE, &no_neighbor_timers_cmd);
13114
13115 /* "neighbor timers connect" commands. */
13116 install_element(BGP_NODE, &neighbor_timers_connect_cmd);
13117 install_element(BGP_NODE, &no_neighbor_timers_connect_cmd);
13118
13119 /* "neighbor advertisement-interval" commands. */
13120 install_element(BGP_NODE, &neighbor_advertise_interval_cmd);
13121 install_element(BGP_NODE, &no_neighbor_advertise_interval_cmd);
13122
13123 /* "neighbor interface" commands. */
13124 install_element(BGP_NODE, &neighbor_interface_cmd);
13125 install_element(BGP_NODE, &no_neighbor_interface_cmd);
13126
13127 /* "neighbor distribute" commands. */
13128 install_element(BGP_NODE, &neighbor_distribute_list_hidden_cmd);
13129 install_element(BGP_NODE, &no_neighbor_distribute_list_hidden_cmd);
13130 install_element(BGP_IPV4_NODE, &neighbor_distribute_list_cmd);
13131 install_element(BGP_IPV4_NODE, &no_neighbor_distribute_list_cmd);
13132 install_element(BGP_IPV4M_NODE, &neighbor_distribute_list_cmd);
13133 install_element(BGP_IPV4M_NODE, &no_neighbor_distribute_list_cmd);
13134 install_element(BGP_IPV4L_NODE, &neighbor_distribute_list_cmd);
13135 install_element(BGP_IPV4L_NODE, &no_neighbor_distribute_list_cmd);
13136 install_element(BGP_IPV6_NODE, &neighbor_distribute_list_cmd);
13137 install_element(BGP_IPV6_NODE, &no_neighbor_distribute_list_cmd);
13138 install_element(BGP_IPV6M_NODE, &neighbor_distribute_list_cmd);
13139 install_element(BGP_IPV6M_NODE, &no_neighbor_distribute_list_cmd);
13140 install_element(BGP_IPV6L_NODE, &neighbor_distribute_list_cmd);
13141 install_element(BGP_IPV6L_NODE, &no_neighbor_distribute_list_cmd);
13142 install_element(BGP_VPNV4_NODE, &neighbor_distribute_list_cmd);
13143 install_element(BGP_VPNV4_NODE, &no_neighbor_distribute_list_cmd);
13144 install_element(BGP_VPNV6_NODE, &neighbor_distribute_list_cmd);
13145 install_element(BGP_VPNV6_NODE, &no_neighbor_distribute_list_cmd);
13146
13147 /* "neighbor prefix-list" commands. */
13148 install_element(BGP_NODE, &neighbor_prefix_list_hidden_cmd);
13149 install_element(BGP_NODE, &no_neighbor_prefix_list_hidden_cmd);
13150 install_element(BGP_IPV4_NODE, &neighbor_prefix_list_cmd);
13151 install_element(BGP_IPV4_NODE, &no_neighbor_prefix_list_cmd);
13152 install_element(BGP_IPV4M_NODE, &neighbor_prefix_list_cmd);
13153 install_element(BGP_IPV4M_NODE, &no_neighbor_prefix_list_cmd);
13154 install_element(BGP_IPV4L_NODE, &neighbor_prefix_list_cmd);
13155 install_element(BGP_IPV4L_NODE, &no_neighbor_prefix_list_cmd);
13156 install_element(BGP_IPV6_NODE, &neighbor_prefix_list_cmd);
13157 install_element(BGP_IPV6_NODE, &no_neighbor_prefix_list_cmd);
13158 install_element(BGP_IPV6M_NODE, &neighbor_prefix_list_cmd);
13159 install_element(BGP_IPV6M_NODE, &no_neighbor_prefix_list_cmd);
13160 install_element(BGP_IPV6L_NODE, &neighbor_prefix_list_cmd);
13161 install_element(BGP_IPV6L_NODE, &no_neighbor_prefix_list_cmd);
13162 install_element(BGP_VPNV4_NODE, &neighbor_prefix_list_cmd);
13163 install_element(BGP_VPNV4_NODE, &no_neighbor_prefix_list_cmd);
13164 install_element(BGP_VPNV6_NODE, &neighbor_prefix_list_cmd);
13165 install_element(BGP_VPNV6_NODE, &no_neighbor_prefix_list_cmd);
13166 install_element(BGP_FLOWSPECV4_NODE, &neighbor_prefix_list_cmd);
13167 install_element(BGP_FLOWSPECV4_NODE, &no_neighbor_prefix_list_cmd);
13168 install_element(BGP_FLOWSPECV6_NODE, &neighbor_prefix_list_cmd);
13169 install_element(BGP_FLOWSPECV6_NODE, &no_neighbor_prefix_list_cmd);
13170
13171 /* "neighbor filter-list" commands. */
13172 install_element(BGP_NODE, &neighbor_filter_list_hidden_cmd);
13173 install_element(BGP_NODE, &no_neighbor_filter_list_hidden_cmd);
13174 install_element(BGP_IPV4_NODE, &neighbor_filter_list_cmd);
13175 install_element(BGP_IPV4_NODE, &no_neighbor_filter_list_cmd);
13176 install_element(BGP_IPV4M_NODE, &neighbor_filter_list_cmd);
13177 install_element(BGP_IPV4M_NODE, &no_neighbor_filter_list_cmd);
13178 install_element(BGP_IPV4L_NODE, &neighbor_filter_list_cmd);
13179 install_element(BGP_IPV4L_NODE, &no_neighbor_filter_list_cmd);
13180 install_element(BGP_IPV6_NODE, &neighbor_filter_list_cmd);
13181 install_element(BGP_IPV6_NODE, &no_neighbor_filter_list_cmd);
13182 install_element(BGP_IPV6M_NODE, &neighbor_filter_list_cmd);
13183 install_element(BGP_IPV6M_NODE, &no_neighbor_filter_list_cmd);
13184 install_element(BGP_IPV6L_NODE, &neighbor_filter_list_cmd);
13185 install_element(BGP_IPV6L_NODE, &no_neighbor_filter_list_cmd);
13186 install_element(BGP_VPNV4_NODE, &neighbor_filter_list_cmd);
13187 install_element(BGP_VPNV4_NODE, &no_neighbor_filter_list_cmd);
13188 install_element(BGP_VPNV6_NODE, &neighbor_filter_list_cmd);
13189 install_element(BGP_VPNV6_NODE, &no_neighbor_filter_list_cmd);
13190 install_element(BGP_FLOWSPECV4_NODE, &neighbor_filter_list_cmd);
13191 install_element(BGP_FLOWSPECV4_NODE, &no_neighbor_filter_list_cmd);
13192 install_element(BGP_FLOWSPECV6_NODE, &neighbor_filter_list_cmd);
13193 install_element(BGP_FLOWSPECV6_NODE, &no_neighbor_filter_list_cmd);
13194
13195 /* "neighbor route-map" commands. */
13196 install_element(BGP_NODE, &neighbor_route_map_hidden_cmd);
13197 install_element(BGP_NODE, &no_neighbor_route_map_hidden_cmd);
13198 install_element(BGP_IPV4_NODE, &neighbor_route_map_cmd);
13199 install_element(BGP_IPV4_NODE, &no_neighbor_route_map_cmd);
13200 install_element(BGP_IPV4M_NODE, &neighbor_route_map_cmd);
13201 install_element(BGP_IPV4M_NODE, &no_neighbor_route_map_cmd);
13202 install_element(BGP_IPV4L_NODE, &neighbor_route_map_cmd);
13203 install_element(BGP_IPV4L_NODE, &no_neighbor_route_map_cmd);
13204 install_element(BGP_IPV6_NODE, &neighbor_route_map_cmd);
13205 install_element(BGP_IPV6_NODE, &no_neighbor_route_map_cmd);
13206 install_element(BGP_IPV6M_NODE, &neighbor_route_map_cmd);
13207 install_element(BGP_IPV6M_NODE, &no_neighbor_route_map_cmd);
13208 install_element(BGP_IPV6L_NODE, &neighbor_route_map_cmd);
13209 install_element(BGP_IPV6L_NODE, &no_neighbor_route_map_cmd);
13210 install_element(BGP_VPNV4_NODE, &neighbor_route_map_cmd);
13211 install_element(BGP_VPNV4_NODE, &no_neighbor_route_map_cmd);
13212 install_element(BGP_VPNV6_NODE, &neighbor_route_map_cmd);
13213 install_element(BGP_VPNV6_NODE, &no_neighbor_route_map_cmd);
13214 install_element(BGP_FLOWSPECV4_NODE, &neighbor_route_map_cmd);
13215 install_element(BGP_FLOWSPECV4_NODE, &no_neighbor_route_map_cmd);
13216 install_element(BGP_FLOWSPECV6_NODE, &neighbor_route_map_cmd);
13217 install_element(BGP_FLOWSPECV6_NODE, &no_neighbor_route_map_cmd);
13218 install_element(BGP_EVPN_NODE, &neighbor_route_map_cmd);
13219 install_element(BGP_EVPN_NODE, &no_neighbor_route_map_cmd);
13220
13221 /* "neighbor unsuppress-map" commands. */
13222 install_element(BGP_NODE, &neighbor_unsuppress_map_hidden_cmd);
13223 install_element(BGP_NODE, &no_neighbor_unsuppress_map_hidden_cmd);
13224 install_element(BGP_IPV4_NODE, &neighbor_unsuppress_map_cmd);
13225 install_element(BGP_IPV4_NODE, &no_neighbor_unsuppress_map_cmd);
13226 install_element(BGP_IPV4M_NODE, &neighbor_unsuppress_map_cmd);
13227 install_element(BGP_IPV4M_NODE, &no_neighbor_unsuppress_map_cmd);
13228 install_element(BGP_IPV4L_NODE, &neighbor_unsuppress_map_cmd);
13229 install_element(BGP_IPV4L_NODE, &no_neighbor_unsuppress_map_cmd);
13230 install_element(BGP_IPV6_NODE, &neighbor_unsuppress_map_cmd);
13231 install_element(BGP_IPV6_NODE, &no_neighbor_unsuppress_map_cmd);
13232 install_element(BGP_IPV6M_NODE, &neighbor_unsuppress_map_cmd);
13233 install_element(BGP_IPV6M_NODE, &no_neighbor_unsuppress_map_cmd);
13234 install_element(BGP_IPV6L_NODE, &neighbor_unsuppress_map_cmd);
13235 install_element(BGP_IPV6L_NODE, &no_neighbor_unsuppress_map_cmd);
13236 install_element(BGP_VPNV4_NODE, &neighbor_unsuppress_map_cmd);
13237 install_element(BGP_VPNV4_NODE, &no_neighbor_unsuppress_map_cmd);
13238 install_element(BGP_VPNV6_NODE, &neighbor_unsuppress_map_cmd);
13239 install_element(BGP_VPNV6_NODE, &no_neighbor_unsuppress_map_cmd);
13240
13241 /* "neighbor maximum-prefix" commands. */
13242 install_element(BGP_NODE, &neighbor_maximum_prefix_hidden_cmd);
13243 install_element(BGP_NODE,
13244 &neighbor_maximum_prefix_threshold_hidden_cmd);
13245 install_element(BGP_NODE, &neighbor_maximum_prefix_warning_hidden_cmd);
13246 install_element(BGP_NODE,
13247 &neighbor_maximum_prefix_threshold_warning_hidden_cmd);
13248 install_element(BGP_NODE, &neighbor_maximum_prefix_restart_hidden_cmd);
13249 install_element(BGP_NODE,
13250 &neighbor_maximum_prefix_threshold_restart_hidden_cmd);
13251 install_element(BGP_NODE, &no_neighbor_maximum_prefix_hidden_cmd);
13252 install_element(BGP_IPV4_NODE, &neighbor_maximum_prefix_cmd);
13253 install_element(BGP_IPV4_NODE, &neighbor_maximum_prefix_threshold_cmd);
13254 install_element(BGP_IPV4_NODE, &neighbor_maximum_prefix_warning_cmd);
13255 install_element(BGP_IPV4_NODE,
13256 &neighbor_maximum_prefix_threshold_warning_cmd);
13257 install_element(BGP_IPV4_NODE, &neighbor_maximum_prefix_restart_cmd);
13258 install_element(BGP_IPV4_NODE,
13259 &neighbor_maximum_prefix_threshold_restart_cmd);
13260 install_element(BGP_IPV4_NODE, &no_neighbor_maximum_prefix_cmd);
13261 install_element(BGP_IPV4M_NODE, &neighbor_maximum_prefix_cmd);
13262 install_element(BGP_IPV4M_NODE, &neighbor_maximum_prefix_threshold_cmd);
13263 install_element(BGP_IPV4M_NODE, &neighbor_maximum_prefix_warning_cmd);
13264 install_element(BGP_IPV4M_NODE,
13265 &neighbor_maximum_prefix_threshold_warning_cmd);
13266 install_element(BGP_IPV4M_NODE, &neighbor_maximum_prefix_restart_cmd);
13267 install_element(BGP_IPV4M_NODE,
13268 &neighbor_maximum_prefix_threshold_restart_cmd);
13269 install_element(BGP_IPV4M_NODE, &no_neighbor_maximum_prefix_cmd);
13270 install_element(BGP_IPV4L_NODE, &neighbor_maximum_prefix_cmd);
13271 install_element(BGP_IPV4L_NODE, &neighbor_maximum_prefix_threshold_cmd);
13272 install_element(BGP_IPV4L_NODE, &neighbor_maximum_prefix_warning_cmd);
13273 install_element(BGP_IPV4L_NODE,
13274 &neighbor_maximum_prefix_threshold_warning_cmd);
13275 install_element(BGP_IPV4L_NODE, &neighbor_maximum_prefix_restart_cmd);
13276 install_element(BGP_IPV4L_NODE,
13277 &neighbor_maximum_prefix_threshold_restart_cmd);
13278 install_element(BGP_IPV4L_NODE, &no_neighbor_maximum_prefix_cmd);
13279 install_element(BGP_IPV6_NODE, &neighbor_maximum_prefix_cmd);
13280 install_element(BGP_IPV6_NODE, &neighbor_maximum_prefix_threshold_cmd);
13281 install_element(BGP_IPV6_NODE, &neighbor_maximum_prefix_warning_cmd);
13282 install_element(BGP_IPV6_NODE,
13283 &neighbor_maximum_prefix_threshold_warning_cmd);
13284 install_element(BGP_IPV6_NODE, &neighbor_maximum_prefix_restart_cmd);
13285 install_element(BGP_IPV6_NODE,
13286 &neighbor_maximum_prefix_threshold_restart_cmd);
13287 install_element(BGP_IPV6_NODE, &no_neighbor_maximum_prefix_cmd);
13288 install_element(BGP_IPV6M_NODE, &neighbor_maximum_prefix_cmd);
13289 install_element(BGP_IPV6M_NODE, &neighbor_maximum_prefix_threshold_cmd);
13290 install_element(BGP_IPV6M_NODE, &neighbor_maximum_prefix_warning_cmd);
13291 install_element(BGP_IPV6M_NODE,
13292 &neighbor_maximum_prefix_threshold_warning_cmd);
13293 install_element(BGP_IPV6M_NODE, &neighbor_maximum_prefix_restart_cmd);
13294 install_element(BGP_IPV6M_NODE,
13295 &neighbor_maximum_prefix_threshold_restart_cmd);
13296 install_element(BGP_IPV6M_NODE, &no_neighbor_maximum_prefix_cmd);
13297 install_element(BGP_IPV6L_NODE, &neighbor_maximum_prefix_cmd);
13298 install_element(BGP_IPV6L_NODE, &neighbor_maximum_prefix_threshold_cmd);
13299 install_element(BGP_IPV6L_NODE, &neighbor_maximum_prefix_warning_cmd);
13300 install_element(BGP_IPV6L_NODE,
13301 &neighbor_maximum_prefix_threshold_warning_cmd);
13302 install_element(BGP_IPV6L_NODE, &neighbor_maximum_prefix_restart_cmd);
13303 install_element(BGP_IPV6L_NODE,
13304 &neighbor_maximum_prefix_threshold_restart_cmd);
13305 install_element(BGP_IPV6L_NODE, &no_neighbor_maximum_prefix_cmd);
13306 install_element(BGP_VPNV4_NODE, &neighbor_maximum_prefix_cmd);
13307 install_element(BGP_VPNV4_NODE, &neighbor_maximum_prefix_threshold_cmd);
13308 install_element(BGP_VPNV4_NODE, &neighbor_maximum_prefix_warning_cmd);
13309 install_element(BGP_VPNV4_NODE,
13310 &neighbor_maximum_prefix_threshold_warning_cmd);
13311 install_element(BGP_VPNV4_NODE, &neighbor_maximum_prefix_restart_cmd);
13312 install_element(BGP_VPNV4_NODE,
13313 &neighbor_maximum_prefix_threshold_restart_cmd);
13314 install_element(BGP_VPNV4_NODE, &no_neighbor_maximum_prefix_cmd);
13315 install_element(BGP_VPNV6_NODE, &neighbor_maximum_prefix_cmd);
13316 install_element(BGP_VPNV6_NODE, &neighbor_maximum_prefix_threshold_cmd);
13317 install_element(BGP_VPNV6_NODE, &neighbor_maximum_prefix_warning_cmd);
13318 install_element(BGP_VPNV6_NODE,
13319 &neighbor_maximum_prefix_threshold_warning_cmd);
13320 install_element(BGP_VPNV6_NODE, &neighbor_maximum_prefix_restart_cmd);
13321 install_element(BGP_VPNV6_NODE,
13322 &neighbor_maximum_prefix_threshold_restart_cmd);
13323 install_element(BGP_VPNV6_NODE, &no_neighbor_maximum_prefix_cmd);
13324
13325 /* "neighbor allowas-in" */
13326 install_element(BGP_NODE, &neighbor_allowas_in_hidden_cmd);
13327 install_element(BGP_NODE, &no_neighbor_allowas_in_hidden_cmd);
13328 install_element(BGP_IPV4_NODE, &neighbor_allowas_in_cmd);
13329 install_element(BGP_IPV4_NODE, &no_neighbor_allowas_in_cmd);
13330 install_element(BGP_IPV4M_NODE, &neighbor_allowas_in_cmd);
13331 install_element(BGP_IPV4M_NODE, &no_neighbor_allowas_in_cmd);
13332 install_element(BGP_IPV4L_NODE, &neighbor_allowas_in_cmd);
13333 install_element(BGP_IPV4L_NODE, &no_neighbor_allowas_in_cmd);
13334 install_element(BGP_IPV6_NODE, &neighbor_allowas_in_cmd);
13335 install_element(BGP_IPV6_NODE, &no_neighbor_allowas_in_cmd);
13336 install_element(BGP_IPV6M_NODE, &neighbor_allowas_in_cmd);
13337 install_element(BGP_IPV6M_NODE, &no_neighbor_allowas_in_cmd);
13338 install_element(BGP_IPV6L_NODE, &neighbor_allowas_in_cmd);
13339 install_element(BGP_IPV6L_NODE, &no_neighbor_allowas_in_cmd);
13340 install_element(BGP_VPNV4_NODE, &neighbor_allowas_in_cmd);
13341 install_element(BGP_VPNV4_NODE, &no_neighbor_allowas_in_cmd);
13342 install_element(BGP_VPNV6_NODE, &neighbor_allowas_in_cmd);
13343 install_element(BGP_VPNV6_NODE, &no_neighbor_allowas_in_cmd);
13344 install_element(BGP_EVPN_NODE, &neighbor_allowas_in_cmd);
13345 install_element(BGP_EVPN_NODE, &no_neighbor_allowas_in_cmd);
13346
13347 /* address-family commands. */
13348 install_element(BGP_NODE, &address_family_ipv4_safi_cmd);
13349 install_element(BGP_NODE, &address_family_ipv6_safi_cmd);
13350 #ifdef KEEP_OLD_VPN_COMMANDS
13351 install_element(BGP_NODE, &address_family_vpnv4_cmd);
13352 install_element(BGP_NODE, &address_family_vpnv6_cmd);
13353 #endif /* KEEP_OLD_VPN_COMMANDS */
13354
13355 install_element(BGP_NODE, &address_family_evpn_cmd);
13356
13357 /* "exit-address-family" command. */
13358 install_element(BGP_IPV4_NODE, &exit_address_family_cmd);
13359 install_element(BGP_IPV4M_NODE, &exit_address_family_cmd);
13360 install_element(BGP_IPV4L_NODE, &exit_address_family_cmd);
13361 install_element(BGP_IPV6_NODE, &exit_address_family_cmd);
13362 install_element(BGP_IPV6M_NODE, &exit_address_family_cmd);
13363 install_element(BGP_IPV6L_NODE, &exit_address_family_cmd);
13364 install_element(BGP_VPNV4_NODE, &exit_address_family_cmd);
13365 install_element(BGP_VPNV6_NODE, &exit_address_family_cmd);
13366 install_element(BGP_FLOWSPECV4_NODE, &exit_address_family_cmd);
13367 install_element(BGP_FLOWSPECV6_NODE, &exit_address_family_cmd);
13368 install_element(BGP_EVPN_NODE, &exit_address_family_cmd);
13369
13370 /* "clear ip bgp commands" */
13371 install_element(ENABLE_NODE, &clear_ip_bgp_all_cmd);
13372
13373 /* clear ip bgp prefix */
13374 install_element(ENABLE_NODE, &clear_ip_bgp_prefix_cmd);
13375 install_element(ENABLE_NODE, &clear_bgp_ipv6_safi_prefix_cmd);
13376 install_element(ENABLE_NODE, &clear_bgp_instance_ipv6_safi_prefix_cmd);
13377
13378 /* "show [ip] bgp summary" commands. */
13379 install_element(VIEW_NODE, &show_bgp_instance_all_ipv6_updgrps_cmd);
13380 install_element(VIEW_NODE, &show_bgp_instance_updgrps_stats_cmd);
13381 install_element(VIEW_NODE, &show_bgp_updgrps_stats_cmd);
13382 install_element(VIEW_NODE, &show_ip_bgp_instance_updgrps_adj_s_cmd);
13383 install_element(VIEW_NODE, &show_ip_bgp_summary_cmd);
13384 install_element(VIEW_NODE, &show_ip_bgp_updgrps_cmd);
13385
13386 /* "show [ip] bgp neighbors" commands. */
13387 install_element(VIEW_NODE, &show_ip_bgp_neighbors_cmd);
13388
13389 /* "show [ip] bgp peer-group" commands. */
13390 install_element(VIEW_NODE, &show_ip_bgp_peer_groups_cmd);
13391
13392 /* "show [ip] bgp paths" commands. */
13393 install_element(VIEW_NODE, &show_ip_bgp_paths_cmd);
13394
13395 /* "show [ip] bgp community" commands. */
13396 install_element(VIEW_NODE, &show_ip_bgp_community_info_cmd);
13397
13398 /* "show ip bgp large-community" commands. */
13399 install_element(VIEW_NODE, &show_ip_bgp_lcommunity_info_cmd);
13400 /* "show [ip] bgp attribute-info" commands. */
13401 install_element(VIEW_NODE, &show_ip_bgp_attr_info_cmd);
13402 /* "show [ip] bgp route-leak" command */
13403 install_element(VIEW_NODE, &show_ip_bgp_route_leak_cmd);
13404
13405 /* "redistribute" commands. */
13406 install_element(BGP_NODE, &bgp_redistribute_ipv4_hidden_cmd);
13407 install_element(BGP_NODE, &no_bgp_redistribute_ipv4_hidden_cmd);
13408 install_element(BGP_NODE, &bgp_redistribute_ipv4_rmap_hidden_cmd);
13409 install_element(BGP_NODE, &bgp_redistribute_ipv4_metric_hidden_cmd);
13410 install_element(BGP_NODE,
13411 &bgp_redistribute_ipv4_rmap_metric_hidden_cmd);
13412 install_element(BGP_NODE,
13413 &bgp_redistribute_ipv4_metric_rmap_hidden_cmd);
13414 install_element(BGP_NODE, &bgp_redistribute_ipv4_ospf_hidden_cmd);
13415 install_element(BGP_NODE, &no_bgp_redistribute_ipv4_ospf_hidden_cmd);
13416 install_element(BGP_NODE, &bgp_redistribute_ipv4_ospf_rmap_hidden_cmd);
13417 install_element(BGP_NODE,
13418 &bgp_redistribute_ipv4_ospf_metric_hidden_cmd);
13419 install_element(BGP_NODE,
13420 &bgp_redistribute_ipv4_ospf_rmap_metric_hidden_cmd);
13421 install_element(BGP_NODE,
13422 &bgp_redistribute_ipv4_ospf_metric_rmap_hidden_cmd);
13423 install_element(BGP_IPV4_NODE, &bgp_redistribute_ipv4_cmd);
13424 install_element(BGP_IPV4_NODE, &no_bgp_redistribute_ipv4_cmd);
13425 install_element(BGP_IPV4_NODE, &bgp_redistribute_ipv4_rmap_cmd);
13426 install_element(BGP_IPV4_NODE, &bgp_redistribute_ipv4_metric_cmd);
13427 install_element(BGP_IPV4_NODE, &bgp_redistribute_ipv4_rmap_metric_cmd);
13428 install_element(BGP_IPV4_NODE, &bgp_redistribute_ipv4_metric_rmap_cmd);
13429 install_element(BGP_IPV4_NODE, &bgp_redistribute_ipv4_ospf_cmd);
13430 install_element(BGP_IPV4_NODE, &no_bgp_redistribute_ipv4_ospf_cmd);
13431 install_element(BGP_IPV4_NODE, &bgp_redistribute_ipv4_ospf_rmap_cmd);
13432 install_element(BGP_IPV4_NODE, &bgp_redistribute_ipv4_ospf_metric_cmd);
13433 install_element(BGP_IPV4_NODE,
13434 &bgp_redistribute_ipv4_ospf_rmap_metric_cmd);
13435 install_element(BGP_IPV4_NODE,
13436 &bgp_redistribute_ipv4_ospf_metric_rmap_cmd);
13437 install_element(BGP_IPV6_NODE, &bgp_redistribute_ipv6_cmd);
13438 install_element(BGP_IPV6_NODE, &no_bgp_redistribute_ipv6_cmd);
13439 install_element(BGP_IPV6_NODE, &bgp_redistribute_ipv6_rmap_cmd);
13440 install_element(BGP_IPV6_NODE, &bgp_redistribute_ipv6_metric_cmd);
13441 install_element(BGP_IPV6_NODE, &bgp_redistribute_ipv6_rmap_metric_cmd);
13442 install_element(BGP_IPV6_NODE, &bgp_redistribute_ipv6_metric_rmap_cmd);
13443
13444 /* import|export vpn [route-map WORD] */
13445 install_element(BGP_IPV4_NODE, &bgp_imexport_vpn_cmd);
13446 install_element(BGP_IPV6_NODE, &bgp_imexport_vpn_cmd);
13447
13448 install_element(BGP_IPV4_NODE, &bgp_imexport_vrf_cmd);
13449 install_element(BGP_IPV6_NODE, &bgp_imexport_vrf_cmd);
13450
13451 /* ttl_security commands */
13452 install_element(BGP_NODE, &neighbor_ttl_security_cmd);
13453 install_element(BGP_NODE, &no_neighbor_ttl_security_cmd);
13454
13455 /* "show [ip] bgp memory" commands. */
13456 install_element(VIEW_NODE, &show_bgp_memory_cmd);
13457
13458 /* "show bgp martian next-hop" */
13459 install_element(VIEW_NODE, &show_bgp_martian_nexthop_db_cmd);
13460
13461 /* "show [ip] bgp views" commands. */
13462 install_element(VIEW_NODE, &show_bgp_views_cmd);
13463
13464 /* "show [ip] bgp vrfs" commands. */
13465 install_element(VIEW_NODE, &show_bgp_vrfs_cmd);
13466
13467 /* Community-list. */
13468 community_list_vty();
13469
13470 /* vpn-policy commands */
13471 install_element(BGP_IPV4_NODE, &af_rd_vpn_export_cmd);
13472 install_element(BGP_IPV6_NODE, &af_rd_vpn_export_cmd);
13473 install_element(BGP_IPV4_NODE, &af_label_vpn_export_cmd);
13474 install_element(BGP_IPV6_NODE, &af_label_vpn_export_cmd);
13475 install_element(BGP_IPV4_NODE, &af_nexthop_vpn_export_cmd);
13476 install_element(BGP_IPV6_NODE, &af_nexthop_vpn_export_cmd);
13477 install_element(BGP_IPV4_NODE, &af_rt_vpn_imexport_cmd);
13478 install_element(BGP_IPV6_NODE, &af_rt_vpn_imexport_cmd);
13479 install_element(BGP_IPV4_NODE, &af_route_map_vpn_imexport_cmd);
13480 install_element(BGP_IPV6_NODE, &af_route_map_vpn_imexport_cmd);
13481 install_element(BGP_IPV4_NODE, &af_import_vrf_route_map_cmd);
13482 install_element(BGP_IPV6_NODE, &af_import_vrf_route_map_cmd);
13483
13484 install_element(BGP_IPV4_NODE, &af_routetarget_import_cmd);
13485 install_element(BGP_IPV6_NODE, &af_routetarget_import_cmd);
13486
13487 install_element(BGP_IPV4_NODE, &af_no_rd_vpn_export_cmd);
13488 install_element(BGP_IPV6_NODE, &af_no_rd_vpn_export_cmd);
13489 install_element(BGP_IPV4_NODE, &af_no_label_vpn_export_cmd);
13490 install_element(BGP_IPV6_NODE, &af_no_label_vpn_export_cmd);
13491 install_element(BGP_IPV4_NODE, &af_no_nexthop_vpn_export_cmd);
13492 install_element(BGP_IPV6_NODE, &af_no_nexthop_vpn_export_cmd);
13493 install_element(BGP_IPV4_NODE, &af_no_rt_vpn_imexport_cmd);
13494 install_element(BGP_IPV6_NODE, &af_no_rt_vpn_imexport_cmd);
13495 install_element(BGP_IPV4_NODE, &af_no_route_map_vpn_imexport_cmd);
13496 install_element(BGP_IPV6_NODE, &af_no_route_map_vpn_imexport_cmd);
13497 install_element(BGP_IPV4_NODE, &af_no_import_vrf_route_map_cmd);
13498 install_element(BGP_IPV6_NODE, &af_no_import_vrf_route_map_cmd);
13499 }
13500
13501 #include "memory.h"
13502 #include "bgp_regex.h"
13503 #include "bgp_clist.h"
13504 #include "bgp_ecommunity.h"
13505
13506 /* VTY functions. */
13507
13508 /* Direction value to string conversion. */
13509 static const char *community_direct_str(int direct)
13510 {
13511 switch (direct) {
13512 case COMMUNITY_DENY:
13513 return "deny";
13514 case COMMUNITY_PERMIT:
13515 return "permit";
13516 default:
13517 return "unknown";
13518 }
13519 }
13520
13521 /* Display error string. */
13522 static void community_list_perror(struct vty *vty, int ret)
13523 {
13524 switch (ret) {
13525 case COMMUNITY_LIST_ERR_CANT_FIND_LIST:
13526 vty_out(vty, "%% Can't find community-list\n");
13527 break;
13528 case COMMUNITY_LIST_ERR_MALFORMED_VAL:
13529 vty_out(vty, "%% Malformed community-list value\n");
13530 break;
13531 case COMMUNITY_LIST_ERR_STANDARD_CONFLICT:
13532 vty_out(vty,
13533 "%% Community name conflict, previously defined as standard community\n");
13534 break;
13535 case COMMUNITY_LIST_ERR_EXPANDED_CONFLICT:
13536 vty_out(vty,
13537 "%% Community name conflict, previously defined as expanded community\n");
13538 break;
13539 }
13540 }
13541
13542 /* "community-list" keyword help string. */
13543 #define COMMUNITY_LIST_STR "Add a community list entry\n"
13544
13545 /* ip community-list standard */
13546 DEFUN (ip_community_list_standard,
13547 ip_community_list_standard_cmd,
13548 "ip community-list <(1-99)|standard WORD> <deny|permit> AA:NN...",
13549 IP_STR
13550 COMMUNITY_LIST_STR
13551 "Community list number (standard)\n"
13552 "Add an standard community-list entry\n"
13553 "Community list name\n"
13554 "Specify community to reject\n"
13555 "Specify community to accept\n"
13556 COMMUNITY_VAL_STR)
13557 {
13558 char *cl_name_or_number = NULL;
13559 int direct = 0;
13560 int style = COMMUNITY_LIST_STANDARD;
13561
13562 int idx = 0;
13563 argv_find(argv, argc, "(1-99)", &idx);
13564 argv_find(argv, argc, "WORD", &idx);
13565 cl_name_or_number = argv[idx]->arg;
13566 direct = argv_find(argv, argc, "permit", &idx) ? COMMUNITY_PERMIT
13567 : COMMUNITY_DENY;
13568 argv_find(argv, argc, "AA:NN", &idx);
13569 char *str = argv_concat(argv, argc, idx);
13570
13571 int ret = community_list_set(bgp_clist, cl_name_or_number, str, direct,
13572 style);
13573
13574 XFREE(MTYPE_TMP, str);
13575
13576 if (ret < 0) {
13577 /* Display error string. */
13578 community_list_perror(vty, ret);
13579 return CMD_WARNING_CONFIG_FAILED;
13580 }
13581
13582 return CMD_SUCCESS;
13583 }
13584
13585 DEFUN (no_ip_community_list_standard_all,
13586 no_ip_community_list_standard_all_cmd,
13587 "no ip community-list <(1-99)|standard WORD> <deny|permit> AA:NN...",
13588 NO_STR
13589 IP_STR
13590 COMMUNITY_LIST_STR
13591 "Community list number (standard)\n"
13592 "Add an standard community-list entry\n"
13593 "Community list name\n"
13594 "Specify community to reject\n"
13595 "Specify community to accept\n"
13596 COMMUNITY_VAL_STR)
13597 {
13598 char *cl_name_or_number = NULL;
13599 int direct = 0;
13600 int style = COMMUNITY_LIST_STANDARD;
13601
13602 int idx = 0;
13603 argv_find(argv, argc, "(1-99)", &idx);
13604 argv_find(argv, argc, "WORD", &idx);
13605 cl_name_or_number = argv[idx]->arg;
13606 direct = argv_find(argv, argc, "permit", &idx) ? COMMUNITY_PERMIT
13607 : COMMUNITY_DENY;
13608 argv_find(argv, argc, "AA:NN", &idx);
13609 char *str = argv_concat(argv, argc, idx);
13610
13611 int ret = community_list_unset(bgp_clist, cl_name_or_number, str,
13612 direct, style);
13613
13614 XFREE(MTYPE_TMP, str);
13615
13616 if (ret < 0) {
13617 community_list_perror(vty, ret);
13618 return CMD_WARNING_CONFIG_FAILED;
13619 }
13620
13621 return CMD_SUCCESS;
13622 }
13623
13624 /* ip community-list expanded */
13625 DEFUN (ip_community_list_expanded_all,
13626 ip_community_list_expanded_all_cmd,
13627 "ip community-list <(100-500)|expanded WORD> <deny|permit> AA:NN...",
13628 IP_STR
13629 COMMUNITY_LIST_STR
13630 "Community list number (expanded)\n"
13631 "Add an expanded community-list entry\n"
13632 "Community list name\n"
13633 "Specify community to reject\n"
13634 "Specify community to accept\n"
13635 COMMUNITY_VAL_STR)
13636 {
13637 char *cl_name_or_number = NULL;
13638 int direct = 0;
13639 int style = COMMUNITY_LIST_EXPANDED;
13640
13641 int idx = 0;
13642 argv_find(argv, argc, "(100-500)", &idx);
13643 argv_find(argv, argc, "WORD", &idx);
13644 cl_name_or_number = argv[idx]->arg;
13645 direct = argv_find(argv, argc, "permit", &idx) ? COMMUNITY_PERMIT
13646 : COMMUNITY_DENY;
13647 argv_find(argv, argc, "AA:NN", &idx);
13648 char *str = argv_concat(argv, argc, idx);
13649
13650 int ret = community_list_set(bgp_clist, cl_name_or_number, str, direct,
13651 style);
13652
13653 XFREE(MTYPE_TMP, str);
13654
13655 if (ret < 0) {
13656 /* Display error string. */
13657 community_list_perror(vty, ret);
13658 return CMD_WARNING_CONFIG_FAILED;
13659 }
13660
13661 return CMD_SUCCESS;
13662 }
13663
13664 DEFUN (no_ip_community_list_expanded_all,
13665 no_ip_community_list_expanded_all_cmd,
13666 "no ip community-list <(100-500)|expanded WORD> <deny|permit> AA:NN...",
13667 NO_STR
13668 IP_STR
13669 COMMUNITY_LIST_STR
13670 "Community list number (expanded)\n"
13671 "Add an expanded community-list entry\n"
13672 "Community list name\n"
13673 "Specify community to reject\n"
13674 "Specify community to accept\n"
13675 COMMUNITY_VAL_STR)
13676 {
13677 char *cl_name_or_number = NULL;
13678 int direct = 0;
13679 int style = COMMUNITY_LIST_EXPANDED;
13680
13681 int idx = 0;
13682 argv_find(argv, argc, "(100-500)", &idx);
13683 argv_find(argv, argc, "WORD", &idx);
13684 cl_name_or_number = argv[idx]->arg;
13685 direct = argv_find(argv, argc, "permit", &idx) ? COMMUNITY_PERMIT
13686 : COMMUNITY_DENY;
13687 argv_find(argv, argc, "AA:NN", &idx);
13688 char *str = argv_concat(argv, argc, idx);
13689
13690 int ret = community_list_unset(bgp_clist, cl_name_or_number, str,
13691 direct, style);
13692
13693 XFREE(MTYPE_TMP, str);
13694
13695 if (ret < 0) {
13696 community_list_perror(vty, ret);
13697 return CMD_WARNING_CONFIG_FAILED;
13698 }
13699
13700 return CMD_SUCCESS;
13701 }
13702
13703 /* Return configuration string of community-list entry. */
13704 static const char *community_list_config_str(struct community_entry *entry)
13705 {
13706 const char *str;
13707
13708 if (entry->any)
13709 str = "";
13710 else {
13711 if (entry->style == COMMUNITY_LIST_STANDARD)
13712 str = community_str(entry->u.com, false);
13713 else if (entry->style == LARGE_COMMUNITY_LIST_STANDARD)
13714 str = lcommunity_str(entry->u.lcom, false);
13715 else
13716 str = entry->config;
13717 }
13718 return str;
13719 }
13720
13721 static void community_list_show(struct vty *vty, struct community_list *list)
13722 {
13723 struct community_entry *entry;
13724
13725 for (entry = list->head; entry; entry = entry->next) {
13726 if (entry == list->head) {
13727 if (all_digit(list->name))
13728 vty_out(vty, "Community %s list %s\n",
13729 entry->style == COMMUNITY_LIST_STANDARD
13730 ? "standard"
13731 : "(expanded) access",
13732 list->name);
13733 else
13734 vty_out(vty, "Named Community %s list %s\n",
13735 entry->style == COMMUNITY_LIST_STANDARD
13736 ? "standard"
13737 : "expanded",
13738 list->name);
13739 }
13740 if (entry->any)
13741 vty_out(vty, " %s\n",
13742 community_direct_str(entry->direct));
13743 else
13744 vty_out(vty, " %s %s\n",
13745 community_direct_str(entry->direct),
13746 community_list_config_str(entry));
13747 }
13748 }
13749
13750 DEFUN (show_ip_community_list,
13751 show_ip_community_list_cmd,
13752 "show ip community-list",
13753 SHOW_STR
13754 IP_STR
13755 "List community-list\n")
13756 {
13757 struct community_list *list;
13758 struct community_list_master *cm;
13759
13760 cm = community_list_master_lookup(bgp_clist, COMMUNITY_LIST_MASTER);
13761 if (!cm)
13762 return CMD_SUCCESS;
13763
13764 for (list = cm->num.head; list; list = list->next)
13765 community_list_show(vty, list);
13766
13767 for (list = cm->str.head; list; list = list->next)
13768 community_list_show(vty, list);
13769
13770 return CMD_SUCCESS;
13771 }
13772
13773 DEFUN (show_ip_community_list_arg,
13774 show_ip_community_list_arg_cmd,
13775 "show ip community-list <(1-500)|WORD>",
13776 SHOW_STR
13777 IP_STR
13778 "List community-list\n"
13779 "Community-list number\n"
13780 "Community-list name\n")
13781 {
13782 int idx_comm_list = 3;
13783 struct community_list *list;
13784
13785 list = community_list_lookup(bgp_clist, argv[idx_comm_list]->arg,
13786 COMMUNITY_LIST_MASTER);
13787 if (!list) {
13788 vty_out(vty, "%% Can't find community-list\n");
13789 return CMD_WARNING;
13790 }
13791
13792 community_list_show(vty, list);
13793
13794 return CMD_SUCCESS;
13795 }
13796
13797 /*
13798 * Large Community code.
13799 */
13800 static int lcommunity_list_set_vty(struct vty *vty, int argc,
13801 struct cmd_token **argv, int style,
13802 int reject_all_digit_name)
13803 {
13804 int ret;
13805 int direct;
13806 char *str;
13807 int idx = 0;
13808 char *cl_name;
13809
13810 direct = argv_find(argv, argc, "permit", &idx) ? COMMUNITY_PERMIT
13811 : COMMUNITY_DENY;
13812
13813 /* All digit name check. */
13814 idx = 0;
13815 argv_find(argv, argc, "WORD", &idx);
13816 argv_find(argv, argc, "(1-99)", &idx);
13817 argv_find(argv, argc, "(100-500)", &idx);
13818 cl_name = argv[idx]->arg;
13819 if (reject_all_digit_name && all_digit(cl_name)) {
13820 vty_out(vty, "%% Community name cannot have all digits\n");
13821 return CMD_WARNING_CONFIG_FAILED;
13822 }
13823
13824 idx = 0;
13825 argv_find(argv, argc, "AA:BB:CC", &idx);
13826 argv_find(argv, argc, "LINE", &idx);
13827 /* Concat community string argument. */
13828 if (idx)
13829 str = argv_concat(argv, argc, idx);
13830 else
13831 str = NULL;
13832
13833 ret = lcommunity_list_set(bgp_clist, cl_name, str, direct, style);
13834
13835 /* Free temporary community list string allocated by
13836 argv_concat(). */
13837 if (str)
13838 XFREE(MTYPE_TMP, str);
13839
13840 if (ret < 0) {
13841 community_list_perror(vty, ret);
13842 return CMD_WARNING_CONFIG_FAILED;
13843 }
13844 return CMD_SUCCESS;
13845 }
13846
13847 static int lcommunity_list_unset_vty(struct vty *vty, int argc,
13848 struct cmd_token **argv, int style)
13849 {
13850 int ret;
13851 int direct = 0;
13852 char *str = NULL;
13853 int idx = 0;
13854
13855 argv_find(argv, argc, "permit", &idx);
13856 argv_find(argv, argc, "deny", &idx);
13857
13858 if (idx) {
13859 /* Check the list direct. */
13860 if (strncmp(argv[idx]->arg, "p", 1) == 0)
13861 direct = COMMUNITY_PERMIT;
13862 else
13863 direct = COMMUNITY_DENY;
13864
13865 idx = 0;
13866 argv_find(argv, argc, "LINE", &idx);
13867 argv_find(argv, argc, "AA:AA:NN", &idx);
13868 /* Concat community string argument. */
13869 str = argv_concat(argv, argc, idx);
13870 }
13871
13872 idx = 0;
13873 argv_find(argv, argc, "(1-99)", &idx);
13874 argv_find(argv, argc, "(100-500)", &idx);
13875 argv_find(argv, argc, "WORD", &idx);
13876
13877 /* Unset community list. */
13878 ret = lcommunity_list_unset(bgp_clist, argv[idx]->arg, str, direct,
13879 style);
13880
13881 /* Free temporary community list string allocated by
13882 argv_concat(). */
13883 if (str)
13884 XFREE(MTYPE_TMP, str);
13885
13886 if (ret < 0) {
13887 community_list_perror(vty, ret);
13888 return CMD_WARNING_CONFIG_FAILED;
13889 }
13890
13891 return CMD_SUCCESS;
13892 }
13893
13894 /* "large-community-list" keyword help string. */
13895 #define LCOMMUNITY_LIST_STR "Add a large community list entry\n"
13896 #define LCOMMUNITY_VAL_STR "large community in 'aa:bb:cc' format\n"
13897
13898 DEFUN (ip_lcommunity_list_standard,
13899 ip_lcommunity_list_standard_cmd,
13900 "ip large-community-list (1-99) <deny|permit>",
13901 IP_STR
13902 LCOMMUNITY_LIST_STR
13903 "Large Community list number (standard)\n"
13904 "Specify large community to reject\n"
13905 "Specify large community to accept\n")
13906 {
13907 return lcommunity_list_set_vty(vty, argc, argv,
13908 LARGE_COMMUNITY_LIST_STANDARD, 0);
13909 }
13910
13911 DEFUN (ip_lcommunity_list_standard1,
13912 ip_lcommunity_list_standard1_cmd,
13913 "ip large-community-list (1-99) <deny|permit> AA:BB:CC...",
13914 IP_STR
13915 LCOMMUNITY_LIST_STR
13916 "Large Community list number (standard)\n"
13917 "Specify large community to reject\n"
13918 "Specify large community to accept\n"
13919 LCOMMUNITY_VAL_STR)
13920 {
13921 return lcommunity_list_set_vty(vty, argc, argv,
13922 LARGE_COMMUNITY_LIST_STANDARD, 0);
13923 }
13924
13925 DEFUN (ip_lcommunity_list_expanded,
13926 ip_lcommunity_list_expanded_cmd,
13927 "ip large-community-list (100-500) <deny|permit> LINE...",
13928 IP_STR
13929 LCOMMUNITY_LIST_STR
13930 "Large Community list number (expanded)\n"
13931 "Specify large community to reject\n"
13932 "Specify large community to accept\n"
13933 "An ordered list as a regular-expression\n")
13934 {
13935 return lcommunity_list_set_vty(vty, argc, argv,
13936 LARGE_COMMUNITY_LIST_EXPANDED, 0);
13937 }
13938
13939 DEFUN (ip_lcommunity_list_name_standard,
13940 ip_lcommunity_list_name_standard_cmd,
13941 "ip large-community-list standard WORD <deny|permit>",
13942 IP_STR
13943 LCOMMUNITY_LIST_STR
13944 "Specify standard large-community-list\n"
13945 "Large Community list name\n"
13946 "Specify large community to reject\n"
13947 "Specify large community to accept\n")
13948 {
13949 return lcommunity_list_set_vty(vty, argc, argv,
13950 LARGE_COMMUNITY_LIST_STANDARD, 1);
13951 }
13952
13953 DEFUN (ip_lcommunity_list_name_standard1,
13954 ip_lcommunity_list_name_standard1_cmd,
13955 "ip large-community-list standard WORD <deny|permit> AA:BB:CC...",
13956 IP_STR
13957 LCOMMUNITY_LIST_STR
13958 "Specify standard large-community-list\n"
13959 "Large Community list name\n"
13960 "Specify large community to reject\n"
13961 "Specify large community to accept\n"
13962 LCOMMUNITY_VAL_STR)
13963 {
13964 return lcommunity_list_set_vty(vty, argc, argv,
13965 LARGE_COMMUNITY_LIST_STANDARD, 1);
13966 }
13967
13968 DEFUN (ip_lcommunity_list_name_expanded,
13969 ip_lcommunity_list_name_expanded_cmd,
13970 "ip large-community-list expanded WORD <deny|permit> LINE...",
13971 IP_STR
13972 LCOMMUNITY_LIST_STR
13973 "Specify expanded large-community-list\n"
13974 "Large Community list name\n"
13975 "Specify large community to reject\n"
13976 "Specify large community to accept\n"
13977 "An ordered list as a regular-expression\n")
13978 {
13979 return lcommunity_list_set_vty(vty, argc, argv,
13980 LARGE_COMMUNITY_LIST_EXPANDED, 1);
13981 }
13982
13983 DEFUN (no_ip_lcommunity_list_standard_all,
13984 no_ip_lcommunity_list_standard_all_cmd,
13985 "no ip large-community-list <(1-99)|(100-500)|WORD>",
13986 NO_STR
13987 IP_STR
13988 LCOMMUNITY_LIST_STR
13989 "Large Community list number (standard)\n"
13990 "Large Community list number (expanded)\n"
13991 "Large Community list name\n")
13992 {
13993 return lcommunity_list_unset_vty(vty, argc, argv,
13994 LARGE_COMMUNITY_LIST_STANDARD);
13995 }
13996
13997 DEFUN (no_ip_lcommunity_list_name_expanded_all,
13998 no_ip_lcommunity_list_name_expanded_all_cmd,
13999 "no ip large-community-list expanded WORD",
14000 NO_STR
14001 IP_STR
14002 LCOMMUNITY_LIST_STR
14003 "Specify expanded large-community-list\n"
14004 "Large Community list name\n")
14005 {
14006 return lcommunity_list_unset_vty(vty, argc, argv,
14007 LARGE_COMMUNITY_LIST_EXPANDED);
14008 }
14009
14010 DEFUN (no_ip_lcommunity_list_standard,
14011 no_ip_lcommunity_list_standard_cmd,
14012 "no ip large-community-list (1-99) <deny|permit> AA:AA:NN...",
14013 NO_STR
14014 IP_STR
14015 LCOMMUNITY_LIST_STR
14016 "Large Community list number (standard)\n"
14017 "Specify large community to reject\n"
14018 "Specify large community to accept\n"
14019 LCOMMUNITY_VAL_STR)
14020 {
14021 return lcommunity_list_unset_vty(vty, argc, argv,
14022 LARGE_COMMUNITY_LIST_STANDARD);
14023 }
14024
14025 DEFUN (no_ip_lcommunity_list_expanded,
14026 no_ip_lcommunity_list_expanded_cmd,
14027 "no ip large-community-list (100-500) <deny|permit> LINE...",
14028 NO_STR
14029 IP_STR
14030 LCOMMUNITY_LIST_STR
14031 "Large Community list number (expanded)\n"
14032 "Specify large community to reject\n"
14033 "Specify large community to accept\n"
14034 "An ordered list as a regular-expression\n")
14035 {
14036 return lcommunity_list_unset_vty(vty, argc, argv,
14037 LARGE_COMMUNITY_LIST_EXPANDED);
14038 }
14039
14040 DEFUN (no_ip_lcommunity_list_name_standard,
14041 no_ip_lcommunity_list_name_standard_cmd,
14042 "no ip large-community-list standard WORD <deny|permit> AA:AA:NN...",
14043 NO_STR
14044 IP_STR
14045 LCOMMUNITY_LIST_STR
14046 "Specify standard large-community-list\n"
14047 "Large Community list name\n"
14048 "Specify large community to reject\n"
14049 "Specify large community to accept\n"
14050 LCOMMUNITY_VAL_STR)
14051 {
14052 return lcommunity_list_unset_vty(vty, argc, argv,
14053 LARGE_COMMUNITY_LIST_STANDARD);
14054 }
14055
14056 DEFUN (no_ip_lcommunity_list_name_expanded,
14057 no_ip_lcommunity_list_name_expanded_cmd,
14058 "no ip large-community-list expanded WORD <deny|permit> LINE...",
14059 NO_STR
14060 IP_STR
14061 LCOMMUNITY_LIST_STR
14062 "Specify expanded large-community-list\n"
14063 "Large community list name\n"
14064 "Specify large community to reject\n"
14065 "Specify large community to accept\n"
14066 "An ordered list as a regular-expression\n")
14067 {
14068 return lcommunity_list_unset_vty(vty, argc, argv,
14069 LARGE_COMMUNITY_LIST_EXPANDED);
14070 }
14071
14072 static void lcommunity_list_show(struct vty *vty, struct community_list *list)
14073 {
14074 struct community_entry *entry;
14075
14076 for (entry = list->head; entry; entry = entry->next) {
14077 if (entry == list->head) {
14078 if (all_digit(list->name))
14079 vty_out(vty, "Large community %s list %s\n",
14080 entry->style == EXTCOMMUNITY_LIST_STANDARD
14081 ? "standard"
14082 : "(expanded) access",
14083 list->name);
14084 else
14085 vty_out(vty,
14086 "Named large community %s list %s\n",
14087 entry->style == EXTCOMMUNITY_LIST_STANDARD
14088 ? "standard"
14089 : "expanded",
14090 list->name);
14091 }
14092 if (entry->any)
14093 vty_out(vty, " %s\n",
14094 community_direct_str(entry->direct));
14095 else
14096 vty_out(vty, " %s %s\n",
14097 community_direct_str(entry->direct),
14098 community_list_config_str(entry));
14099 }
14100 }
14101
14102 DEFUN (show_ip_lcommunity_list,
14103 show_ip_lcommunity_list_cmd,
14104 "show ip large-community-list",
14105 SHOW_STR
14106 IP_STR
14107 "List large-community list\n")
14108 {
14109 struct community_list *list;
14110 struct community_list_master *cm;
14111
14112 cm = community_list_master_lookup(bgp_clist,
14113 LARGE_COMMUNITY_LIST_MASTER);
14114 if (!cm)
14115 return CMD_SUCCESS;
14116
14117 for (list = cm->num.head; list; list = list->next)
14118 lcommunity_list_show(vty, list);
14119
14120 for (list = cm->str.head; list; list = list->next)
14121 lcommunity_list_show(vty, list);
14122
14123 return CMD_SUCCESS;
14124 }
14125
14126 DEFUN (show_ip_lcommunity_list_arg,
14127 show_ip_lcommunity_list_arg_cmd,
14128 "show ip large-community-list <(1-500)|WORD>",
14129 SHOW_STR
14130 IP_STR
14131 "List large-community list\n"
14132 "large-community-list number\n"
14133 "large-community-list name\n")
14134 {
14135 struct community_list *list;
14136
14137 list = community_list_lookup(bgp_clist, argv[3]->arg,
14138 LARGE_COMMUNITY_LIST_MASTER);
14139 if (!list) {
14140 vty_out(vty, "%% Can't find extcommunity-list\n");
14141 return CMD_WARNING;
14142 }
14143
14144 lcommunity_list_show(vty, list);
14145
14146 return CMD_SUCCESS;
14147 }
14148
14149 /* "extcommunity-list" keyword help string. */
14150 #define EXTCOMMUNITY_LIST_STR "Add a extended community list entry\n"
14151 #define EXTCOMMUNITY_VAL_STR "Extended community attribute in 'rt aa:nn_or_IPaddr:nn' OR 'soo aa:nn_or_IPaddr:nn' format\n"
14152
14153 DEFUN (ip_extcommunity_list_standard,
14154 ip_extcommunity_list_standard_cmd,
14155 "ip extcommunity-list <(1-99)|standard WORD> <deny|permit> AA:NN...",
14156 IP_STR
14157 EXTCOMMUNITY_LIST_STR
14158 "Extended Community list number (standard)\n"
14159 "Specify standard extcommunity-list\n"
14160 "Community list name\n"
14161 "Specify community to reject\n"
14162 "Specify community to accept\n"
14163 EXTCOMMUNITY_VAL_STR)
14164 {
14165 int style = EXTCOMMUNITY_LIST_STANDARD;
14166 int direct = 0;
14167 char *cl_number_or_name = NULL;
14168
14169 int idx = 0;
14170 argv_find(argv, argc, "(1-99)", &idx);
14171 argv_find(argv, argc, "WORD", &idx);
14172 cl_number_or_name = argv[idx]->arg;
14173 direct = argv_find(argv, argc, "permit", &idx) ? COMMUNITY_PERMIT
14174 : COMMUNITY_DENY;
14175 argv_find(argv, argc, "AA:NN", &idx);
14176 char *str = argv_concat(argv, argc, idx);
14177
14178 int ret = extcommunity_list_set(bgp_clist, cl_number_or_name, str,
14179 direct, style);
14180
14181 XFREE(MTYPE_TMP, str);
14182
14183 if (ret < 0) {
14184 community_list_perror(vty, ret);
14185 return CMD_WARNING_CONFIG_FAILED;
14186 }
14187
14188 return CMD_SUCCESS;
14189 }
14190
14191 DEFUN (ip_extcommunity_list_name_expanded,
14192 ip_extcommunity_list_name_expanded_cmd,
14193 "ip extcommunity-list <(100-500)|expanded WORD> <deny|permit> LINE...",
14194 IP_STR
14195 EXTCOMMUNITY_LIST_STR
14196 "Extended Community list number (expanded)\n"
14197 "Specify expanded extcommunity-list\n"
14198 "Extended Community list name\n"
14199 "Specify community to reject\n"
14200 "Specify community to accept\n"
14201 "An ordered list as a regular-expression\n")
14202 {
14203 int style = EXTCOMMUNITY_LIST_EXPANDED;
14204 int direct = 0;
14205 char *cl_number_or_name = NULL;
14206
14207 int idx = 0;
14208 argv_find(argv, argc, "(100-500)", &idx);
14209 argv_find(argv, argc, "WORD", &idx);
14210 cl_number_or_name = argv[idx]->arg;
14211 direct = argv_find(argv, argc, "permit", &idx) ? COMMUNITY_PERMIT
14212 : COMMUNITY_DENY;
14213 argv_find(argv, argc, "LINE", &idx);
14214 char *str = argv_concat(argv, argc, idx);
14215
14216 int ret = extcommunity_list_set(bgp_clist, cl_number_or_name, str,
14217 direct, style);
14218
14219 XFREE(MTYPE_TMP, str);
14220
14221 if (ret < 0) {
14222 community_list_perror(vty, ret);
14223 return CMD_WARNING_CONFIG_FAILED;
14224 }
14225
14226 return CMD_SUCCESS;
14227 }
14228
14229 DEFUN (no_ip_extcommunity_list_standard_all,
14230 no_ip_extcommunity_list_standard_all_cmd,
14231 "no ip extcommunity-list <(1-99)|standard WORD> <deny|permit> AA:NN...",
14232 NO_STR
14233 IP_STR
14234 EXTCOMMUNITY_LIST_STR
14235 "Extended Community list number (standard)\n"
14236 "Specify standard extcommunity-list\n"
14237 "Community list name\n"
14238 "Specify community to reject\n"
14239 "Specify community to accept\n"
14240 EXTCOMMUNITY_VAL_STR)
14241 {
14242 int style = EXTCOMMUNITY_LIST_STANDARD;
14243 int direct = 0;
14244 char *cl_number_or_name = NULL;
14245
14246 int idx = 0;
14247 argv_find(argv, argc, "(1-99)", &idx);
14248 argv_find(argv, argc, "WORD", &idx);
14249 cl_number_or_name = argv[idx]->arg;
14250 direct = argv_find(argv, argc, "permit", &idx) ? COMMUNITY_PERMIT
14251 : COMMUNITY_DENY;
14252 argv_find(argv, argc, "AA:NN", &idx);
14253 char *str = argv_concat(argv, argc, idx);
14254
14255 int ret = extcommunity_list_unset(bgp_clist, cl_number_or_name, str,
14256 direct, style);
14257
14258 XFREE(MTYPE_TMP, str);
14259
14260 if (ret < 0) {
14261 community_list_perror(vty, ret);
14262 return CMD_WARNING_CONFIG_FAILED;
14263 }
14264
14265 return CMD_SUCCESS;
14266 }
14267
14268 DEFUN (no_ip_extcommunity_list_expanded_all,
14269 no_ip_extcommunity_list_expanded_all_cmd,
14270 "no ip extcommunity-list <(100-500)|expanded WORD> <deny|permit> LINE...",
14271 NO_STR
14272 IP_STR
14273 EXTCOMMUNITY_LIST_STR
14274 "Extended Community list number (expanded)\n"
14275 "Specify expanded extcommunity-list\n"
14276 "Extended Community list name\n"
14277 "Specify community to reject\n"
14278 "Specify community to accept\n"
14279 "An ordered list as a regular-expression\n")
14280 {
14281 int style = EXTCOMMUNITY_LIST_EXPANDED;
14282 int direct = 0;
14283 char *cl_number_or_name = NULL;
14284
14285 int idx = 0;
14286 argv_find(argv, argc, "(100-500)", &idx);
14287 argv_find(argv, argc, "WORD", &idx);
14288 cl_number_or_name = argv[idx]->arg;
14289 direct = argv_find(argv, argc, "permit", &idx) ? COMMUNITY_PERMIT
14290 : COMMUNITY_DENY;
14291 argv_find(argv, argc, "LINE", &idx);
14292 char *str = argv_concat(argv, argc, idx);
14293
14294 int ret = extcommunity_list_unset(bgp_clist, cl_number_or_name, str,
14295 direct, style);
14296
14297 XFREE(MTYPE_TMP, str);
14298
14299 if (ret < 0) {
14300 community_list_perror(vty, ret);
14301 return CMD_WARNING_CONFIG_FAILED;
14302 }
14303
14304 return CMD_SUCCESS;
14305 }
14306
14307 static void extcommunity_list_show(struct vty *vty, struct community_list *list)
14308 {
14309 struct community_entry *entry;
14310
14311 for (entry = list->head; entry; entry = entry->next) {
14312 if (entry == list->head) {
14313 if (all_digit(list->name))
14314 vty_out(vty, "Extended community %s list %s\n",
14315 entry->style == EXTCOMMUNITY_LIST_STANDARD
14316 ? "standard"
14317 : "(expanded) access",
14318 list->name);
14319 else
14320 vty_out(vty,
14321 "Named extended community %s list %s\n",
14322 entry->style == EXTCOMMUNITY_LIST_STANDARD
14323 ? "standard"
14324 : "expanded",
14325 list->name);
14326 }
14327 if (entry->any)
14328 vty_out(vty, " %s\n",
14329 community_direct_str(entry->direct));
14330 else
14331 vty_out(vty, " %s %s\n",
14332 community_direct_str(entry->direct),
14333 community_list_config_str(entry));
14334 }
14335 }
14336
14337 DEFUN (show_ip_extcommunity_list,
14338 show_ip_extcommunity_list_cmd,
14339 "show ip extcommunity-list",
14340 SHOW_STR
14341 IP_STR
14342 "List extended-community list\n")
14343 {
14344 struct community_list *list;
14345 struct community_list_master *cm;
14346
14347 cm = community_list_master_lookup(bgp_clist, EXTCOMMUNITY_LIST_MASTER);
14348 if (!cm)
14349 return CMD_SUCCESS;
14350
14351 for (list = cm->num.head; list; list = list->next)
14352 extcommunity_list_show(vty, list);
14353
14354 for (list = cm->str.head; list; list = list->next)
14355 extcommunity_list_show(vty, list);
14356
14357 return CMD_SUCCESS;
14358 }
14359
14360 DEFUN (show_ip_extcommunity_list_arg,
14361 show_ip_extcommunity_list_arg_cmd,
14362 "show ip extcommunity-list <(1-500)|WORD>",
14363 SHOW_STR
14364 IP_STR
14365 "List extended-community list\n"
14366 "Extcommunity-list number\n"
14367 "Extcommunity-list name\n")
14368 {
14369 int idx_comm_list = 3;
14370 struct community_list *list;
14371
14372 list = community_list_lookup(bgp_clist, argv[idx_comm_list]->arg,
14373 EXTCOMMUNITY_LIST_MASTER);
14374 if (!list) {
14375 vty_out(vty, "%% Can't find extcommunity-list\n");
14376 return CMD_WARNING;
14377 }
14378
14379 extcommunity_list_show(vty, list);
14380
14381 return CMD_SUCCESS;
14382 }
14383
14384 /* Display community-list and extcommunity-list configuration. */
14385 static int community_list_config_write(struct vty *vty)
14386 {
14387 struct community_list *list;
14388 struct community_entry *entry;
14389 struct community_list_master *cm;
14390 int write = 0;
14391
14392 /* Community-list. */
14393 cm = community_list_master_lookup(bgp_clist, COMMUNITY_LIST_MASTER);
14394
14395 for (list = cm->num.head; list; list = list->next)
14396 for (entry = list->head; entry; entry = entry->next) {
14397 vty_out(vty, "ip community-list %s %s %s\n", list->name,
14398 community_direct_str(entry->direct),
14399 community_list_config_str(entry));
14400 write++;
14401 }
14402 for (list = cm->str.head; list; list = list->next)
14403 for (entry = list->head; entry; entry = entry->next) {
14404 vty_out(vty, "ip community-list %s %s %s %s\n",
14405 entry->style == COMMUNITY_LIST_STANDARD
14406 ? "standard"
14407 : "expanded",
14408 list->name, community_direct_str(entry->direct),
14409 community_list_config_str(entry));
14410 write++;
14411 }
14412
14413 /* Extcommunity-list. */
14414 cm = community_list_master_lookup(bgp_clist, EXTCOMMUNITY_LIST_MASTER);
14415
14416 for (list = cm->num.head; list; list = list->next)
14417 for (entry = list->head; entry; entry = entry->next) {
14418 vty_out(vty, "ip extcommunity-list %s %s %s\n",
14419 list->name, community_direct_str(entry->direct),
14420 community_list_config_str(entry));
14421 write++;
14422 }
14423 for (list = cm->str.head; list; list = list->next)
14424 for (entry = list->head; entry; entry = entry->next) {
14425 vty_out(vty, "ip extcommunity-list %s %s %s %s\n",
14426 entry->style == EXTCOMMUNITY_LIST_STANDARD
14427 ? "standard"
14428 : "expanded",
14429 list->name, community_direct_str(entry->direct),
14430 community_list_config_str(entry));
14431 write++;
14432 }
14433
14434
14435 /* lcommunity-list. */
14436 cm = community_list_master_lookup(bgp_clist,
14437 LARGE_COMMUNITY_LIST_MASTER);
14438
14439 for (list = cm->num.head; list; list = list->next)
14440 for (entry = list->head; entry; entry = entry->next) {
14441 vty_out(vty, "ip large-community-list %s %s %s\n",
14442 list->name, community_direct_str(entry->direct),
14443 community_list_config_str(entry));
14444 write++;
14445 }
14446 for (list = cm->str.head; list; list = list->next)
14447 for (entry = list->head; entry; entry = entry->next) {
14448 vty_out(vty, "ip large-community-list %s %s %s %s\n",
14449 entry->style == LARGE_COMMUNITY_LIST_STANDARD
14450 ? "standard"
14451 : "expanded",
14452 list->name, community_direct_str(entry->direct),
14453 community_list_config_str(entry));
14454 write++;
14455 }
14456
14457 return write;
14458 }
14459
14460 static struct cmd_node community_list_node = {
14461 COMMUNITY_LIST_NODE, "", 1 /* Export to vtysh. */
14462 };
14463
14464 static void community_list_vty(void)
14465 {
14466 install_node(&community_list_node, community_list_config_write);
14467
14468 /* Community-list. */
14469 install_element(CONFIG_NODE, &ip_community_list_standard_cmd);
14470 install_element(CONFIG_NODE, &ip_community_list_expanded_all_cmd);
14471 install_element(CONFIG_NODE, &no_ip_community_list_standard_all_cmd);
14472 install_element(CONFIG_NODE, &no_ip_community_list_expanded_all_cmd);
14473 install_element(VIEW_NODE, &show_ip_community_list_cmd);
14474 install_element(VIEW_NODE, &show_ip_community_list_arg_cmd);
14475
14476 /* Extcommunity-list. */
14477 install_element(CONFIG_NODE, &ip_extcommunity_list_standard_cmd);
14478 install_element(CONFIG_NODE, &ip_extcommunity_list_name_expanded_cmd);
14479 install_element(CONFIG_NODE, &no_ip_extcommunity_list_standard_all_cmd);
14480 install_element(CONFIG_NODE, &no_ip_extcommunity_list_expanded_all_cmd);
14481 install_element(VIEW_NODE, &show_ip_extcommunity_list_cmd);
14482 install_element(VIEW_NODE, &show_ip_extcommunity_list_arg_cmd);
14483
14484 /* Large Community List */
14485 install_element(CONFIG_NODE, &ip_lcommunity_list_standard_cmd);
14486 install_element(CONFIG_NODE, &ip_lcommunity_list_standard1_cmd);
14487 install_element(CONFIG_NODE, &ip_lcommunity_list_expanded_cmd);
14488 install_element(CONFIG_NODE, &ip_lcommunity_list_name_standard_cmd);
14489 install_element(CONFIG_NODE, &ip_lcommunity_list_name_standard1_cmd);
14490 install_element(CONFIG_NODE, &ip_lcommunity_list_name_expanded_cmd);
14491 install_element(CONFIG_NODE, &no_ip_lcommunity_list_standard_all_cmd);
14492 install_element(CONFIG_NODE,
14493 &no_ip_lcommunity_list_name_expanded_all_cmd);
14494 install_element(CONFIG_NODE, &no_ip_lcommunity_list_standard_cmd);
14495 install_element(CONFIG_NODE, &no_ip_lcommunity_list_expanded_cmd);
14496 install_element(CONFIG_NODE, &no_ip_lcommunity_list_name_standard_cmd);
14497 install_element(CONFIG_NODE, &no_ip_lcommunity_list_name_expanded_cmd);
14498 install_element(VIEW_NODE, &show_ip_lcommunity_list_cmd);
14499 install_element(VIEW_NODE, &show_ip_lcommunity_list_arg_cmd);
14500 }