]> git.proxmox.com Git - mirror_frr.git/blob - bgpd/bgp_vty.c
Merge pull request #2495 from pacovn/fixme_all_digit
[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 /* Pending: handle when user tries to change a view to vrf n vv.
932 */
933 }
934
935 /* unset the auto created flag as the user config is now present */
936 UNSET_FLAG(bgp->vrf_flags, BGP_VRF_AUTO);
937 VTY_PUSH_CONTEXT(BGP_NODE, bgp);
938
939 return CMD_SUCCESS;
940 }
941
942 /* "no router bgp" commands. */
943 DEFUN (no_router_bgp,
944 no_router_bgp_cmd,
945 "no router bgp [(1-4294967295) [<view|vrf> VIEWVRFNAME]]",
946 NO_STR
947 ROUTER_STR
948 BGP_STR
949 AS_STR
950 BGP_INSTANCE_HELP_STR)
951 {
952 int idx_asn = 3;
953 int idx_vrf = 5;
954 as_t as;
955 struct bgp *bgp;
956 const char *name = NULL;
957
958 // "no router bgp" without an ASN
959 if (argc == 3) {
960 // Pending: Make VRF option available for ASN less config
961 bgp = bgp_get_default();
962
963 if (bgp == NULL) {
964 vty_out(vty, "%% No BGP process is configured\n");
965 return CMD_WARNING_CONFIG_FAILED;
966 }
967
968 if (listcount(bm->bgp) > 1) {
969 vty_out(vty, "%% Please specify ASN and VRF\n");
970 return CMD_WARNING_CONFIG_FAILED;
971 }
972
973 if (bgp->l3vni) {
974 vty_out(vty, "%% Please unconfigure l3vni %u",
975 bgp->l3vni);
976 return CMD_WARNING_CONFIG_FAILED;
977 }
978 } else {
979 as = strtoul(argv[idx_asn]->arg, NULL, 10);
980
981 if (argc > 4)
982 name = argv[idx_vrf]->arg;
983
984 /* Lookup bgp structure. */
985 bgp = bgp_lookup(as, name);
986 if (!bgp) {
987 vty_out(vty, "%% Can't find BGP instance\n");
988 return CMD_WARNING_CONFIG_FAILED;
989 }
990
991 if (bgp->l3vni) {
992 vty_out(vty, "%% Please unconfigure l3vni %u",
993 bgp->l3vni);
994 return CMD_WARNING_CONFIG_FAILED;
995 }
996 }
997
998 bgp_delete(bgp);
999
1000 return CMD_SUCCESS;
1001 }
1002
1003
1004 /* BGP router-id. */
1005
1006 DEFPY (bgp_router_id,
1007 bgp_router_id_cmd,
1008 "bgp router-id A.B.C.D",
1009 BGP_STR
1010 "Override configured router identifier\n"
1011 "Manually configured router identifier\n")
1012 {
1013 VTY_DECLVAR_CONTEXT(bgp, bgp);
1014 bgp_router_id_static_set(bgp, router_id);
1015 return CMD_SUCCESS;
1016 }
1017
1018 DEFPY (no_bgp_router_id,
1019 no_bgp_router_id_cmd,
1020 "no bgp router-id [A.B.C.D]",
1021 NO_STR
1022 BGP_STR
1023 "Override configured router identifier\n"
1024 "Manually configured router identifier\n")
1025 {
1026 VTY_DECLVAR_CONTEXT(bgp, bgp);
1027
1028 if (router_id_str) {
1029 if (!IPV4_ADDR_SAME(&bgp->router_id_static, &router_id)) {
1030 vty_out(vty, "%% BGP router-id doesn't match\n");
1031 return CMD_WARNING_CONFIG_FAILED;
1032 }
1033 }
1034
1035 router_id.s_addr = 0;
1036 bgp_router_id_static_set(bgp, router_id);
1037
1038 return CMD_SUCCESS;
1039 }
1040
1041
1042 /* BGP Cluster ID. */
1043 DEFUN (bgp_cluster_id,
1044 bgp_cluster_id_cmd,
1045 "bgp cluster-id <A.B.C.D|(1-4294967295)>",
1046 BGP_STR
1047 "Configure Route-Reflector Cluster-id\n"
1048 "Route-Reflector Cluster-id in IP address format\n"
1049 "Route-Reflector Cluster-id as 32 bit quantity\n")
1050 {
1051 VTY_DECLVAR_CONTEXT(bgp, bgp);
1052 int idx_ipv4 = 2;
1053 int ret;
1054 struct in_addr cluster;
1055
1056 ret = inet_aton(argv[idx_ipv4]->arg, &cluster);
1057 if (!ret) {
1058 vty_out(vty, "%% Malformed bgp cluster identifier\n");
1059 return CMD_WARNING_CONFIG_FAILED;
1060 }
1061
1062 bgp_cluster_id_set(bgp, &cluster);
1063 bgp_clear_star_soft_out(vty, bgp->name);
1064
1065 return CMD_SUCCESS;
1066 }
1067
1068 DEFUN (no_bgp_cluster_id,
1069 no_bgp_cluster_id_cmd,
1070 "no bgp cluster-id [<A.B.C.D|(1-4294967295)>]",
1071 NO_STR
1072 BGP_STR
1073 "Configure Route-Reflector Cluster-id\n"
1074 "Route-Reflector Cluster-id in IP address format\n"
1075 "Route-Reflector Cluster-id as 32 bit quantity\n")
1076 {
1077 VTY_DECLVAR_CONTEXT(bgp, bgp);
1078 bgp_cluster_id_unset(bgp);
1079 bgp_clear_star_soft_out(vty, bgp->name);
1080
1081 return CMD_SUCCESS;
1082 }
1083
1084 DEFUN (bgp_confederation_identifier,
1085 bgp_confederation_identifier_cmd,
1086 "bgp confederation identifier (1-4294967295)",
1087 "BGP specific commands\n"
1088 "AS confederation parameters\n"
1089 "AS number\n"
1090 "Set routing domain confederation AS\n")
1091 {
1092 VTY_DECLVAR_CONTEXT(bgp, bgp);
1093 int idx_number = 3;
1094 as_t as;
1095
1096 as = strtoul(argv[idx_number]->arg, NULL, 10);
1097
1098 bgp_confederation_id_set(bgp, as);
1099
1100 return CMD_SUCCESS;
1101 }
1102
1103 DEFUN (no_bgp_confederation_identifier,
1104 no_bgp_confederation_identifier_cmd,
1105 "no bgp confederation identifier [(1-4294967295)]",
1106 NO_STR
1107 "BGP specific commands\n"
1108 "AS confederation parameters\n"
1109 "AS number\n"
1110 "Set routing domain confederation AS\n")
1111 {
1112 VTY_DECLVAR_CONTEXT(bgp, bgp);
1113 bgp_confederation_id_unset(bgp);
1114
1115 return CMD_SUCCESS;
1116 }
1117
1118 DEFUN (bgp_confederation_peers,
1119 bgp_confederation_peers_cmd,
1120 "bgp confederation peers (1-4294967295)...",
1121 "BGP specific commands\n"
1122 "AS confederation parameters\n"
1123 "Peer ASs in BGP confederation\n"
1124 AS_STR)
1125 {
1126 VTY_DECLVAR_CONTEXT(bgp, bgp);
1127 int idx_asn = 3;
1128 as_t as;
1129 int i;
1130
1131 for (i = idx_asn; i < argc; i++) {
1132 as = strtoul(argv[i]->arg, NULL, 10);
1133
1134 if (bgp->as == as) {
1135 vty_out(vty,
1136 "%% Local member-AS not allowed in confed peer list\n");
1137 continue;
1138 }
1139
1140 bgp_confederation_peers_add(bgp, as);
1141 }
1142 return CMD_SUCCESS;
1143 }
1144
1145 DEFUN (no_bgp_confederation_peers,
1146 no_bgp_confederation_peers_cmd,
1147 "no bgp confederation peers (1-4294967295)...",
1148 NO_STR
1149 "BGP specific commands\n"
1150 "AS confederation parameters\n"
1151 "Peer ASs in BGP confederation\n"
1152 AS_STR)
1153 {
1154 VTY_DECLVAR_CONTEXT(bgp, bgp);
1155 int idx_asn = 4;
1156 as_t as;
1157 int i;
1158
1159 for (i = idx_asn; i < argc; i++) {
1160 as = strtoul(argv[i]->arg, NULL, 10);
1161
1162 bgp_confederation_peers_remove(bgp, as);
1163 }
1164 return CMD_SUCCESS;
1165 }
1166
1167 /**
1168 * Central routine for maximum-paths configuration.
1169 * @peer_type: BGP_PEER_EBGP or BGP_PEER_IBGP
1170 * @set: 1 for setting values, 0 for removing the max-paths config.
1171 */
1172 static int bgp_maxpaths_config_vty(struct vty *vty, int peer_type,
1173 const char *mpaths, uint16_t options,
1174 int set)
1175 {
1176 VTY_DECLVAR_CONTEXT(bgp, bgp);
1177 uint16_t maxpaths = 0;
1178 int ret;
1179 afi_t afi;
1180 safi_t safi;
1181
1182 afi = bgp_node_afi(vty);
1183 safi = bgp_node_safi(vty);
1184
1185 if (set) {
1186 maxpaths = strtol(mpaths, NULL, 10);
1187 if (maxpaths > multipath_num) {
1188 vty_out(vty,
1189 "%% Maxpaths Specified: %d is > than multipath num specified on bgp command line %d",
1190 maxpaths, multipath_num);
1191 return CMD_WARNING_CONFIG_FAILED;
1192 }
1193 ret = bgp_maximum_paths_set(bgp, afi, safi, peer_type, maxpaths,
1194 options);
1195 } else
1196 ret = bgp_maximum_paths_unset(bgp, afi, safi, peer_type);
1197
1198 if (ret < 0) {
1199 vty_out(vty,
1200 "%% Failed to %sset maximum-paths %s %u for afi %u, safi %u\n",
1201 (set == 1) ? "" : "un",
1202 (peer_type == BGP_PEER_EBGP) ? "ebgp" : "ibgp",
1203 maxpaths, afi, safi);
1204 return CMD_WARNING_CONFIG_FAILED;
1205 }
1206
1207 bgp_recalculate_all_bestpaths(bgp);
1208
1209 return CMD_SUCCESS;
1210 }
1211
1212 DEFUN (bgp_maxmed_admin,
1213 bgp_maxmed_admin_cmd,
1214 "bgp max-med administrative ",
1215 BGP_STR
1216 "Advertise routes with max-med\n"
1217 "Administratively applied, for an indefinite period\n")
1218 {
1219 VTY_DECLVAR_CONTEXT(bgp, bgp);
1220
1221 bgp->v_maxmed_admin = 1;
1222 bgp->maxmed_admin_value = BGP_MAXMED_VALUE_DEFAULT;
1223
1224 bgp_maxmed_update(bgp);
1225
1226 return CMD_SUCCESS;
1227 }
1228
1229 DEFUN (bgp_maxmed_admin_medv,
1230 bgp_maxmed_admin_medv_cmd,
1231 "bgp max-med administrative (0-4294967295)",
1232 BGP_STR
1233 "Advertise routes with max-med\n"
1234 "Administratively applied, for an indefinite period\n"
1235 "Max MED value to be used\n")
1236 {
1237 VTY_DECLVAR_CONTEXT(bgp, bgp);
1238 int idx_number = 3;
1239
1240 bgp->v_maxmed_admin = 1;
1241 bgp->maxmed_admin_value = strtoul(argv[idx_number]->arg, NULL, 10);
1242
1243 bgp_maxmed_update(bgp);
1244
1245 return CMD_SUCCESS;
1246 }
1247
1248 DEFUN (no_bgp_maxmed_admin,
1249 no_bgp_maxmed_admin_cmd,
1250 "no bgp max-med administrative [(0-4294967295)]",
1251 NO_STR
1252 BGP_STR
1253 "Advertise routes with max-med\n"
1254 "Administratively applied, for an indefinite period\n"
1255 "Max MED value to be used\n")
1256 {
1257 VTY_DECLVAR_CONTEXT(bgp, bgp);
1258 bgp->v_maxmed_admin = BGP_MAXMED_ADMIN_UNCONFIGURED;
1259 bgp->maxmed_admin_value = BGP_MAXMED_VALUE_DEFAULT;
1260 bgp_maxmed_update(bgp);
1261
1262 return CMD_SUCCESS;
1263 }
1264
1265 DEFUN (bgp_maxmed_onstartup,
1266 bgp_maxmed_onstartup_cmd,
1267 "bgp max-med on-startup (5-86400) [(0-4294967295)]",
1268 BGP_STR
1269 "Advertise routes with max-med\n"
1270 "Effective on a startup\n"
1271 "Time (seconds) period for max-med\n"
1272 "Max MED value to be used\n")
1273 {
1274 VTY_DECLVAR_CONTEXT(bgp, bgp);
1275 int idx = 0;
1276
1277 argv_find(argv, argc, "(5-86400)", &idx);
1278 bgp->v_maxmed_onstartup = strtoul(argv[idx]->arg, NULL, 10);
1279 if (argv_find(argv, argc, "(0-4294967295)", &idx))
1280 bgp->maxmed_onstartup_value = strtoul(argv[idx]->arg, NULL, 10);
1281 else
1282 bgp->maxmed_onstartup_value = BGP_MAXMED_VALUE_DEFAULT;
1283
1284 bgp_maxmed_update(bgp);
1285
1286 return CMD_SUCCESS;
1287 }
1288
1289 DEFUN (no_bgp_maxmed_onstartup,
1290 no_bgp_maxmed_onstartup_cmd,
1291 "no bgp max-med on-startup [(5-86400) [(0-4294967295)]]",
1292 NO_STR
1293 BGP_STR
1294 "Advertise routes with max-med\n"
1295 "Effective on a startup\n"
1296 "Time (seconds) period for max-med\n"
1297 "Max MED value to be used\n")
1298 {
1299 VTY_DECLVAR_CONTEXT(bgp, bgp);
1300
1301 /* Cancel max-med onstartup if its on */
1302 if (bgp->t_maxmed_onstartup) {
1303 THREAD_TIMER_OFF(bgp->t_maxmed_onstartup);
1304 bgp->maxmed_onstartup_over = 1;
1305 }
1306
1307 bgp->v_maxmed_onstartup = BGP_MAXMED_ONSTARTUP_UNCONFIGURED;
1308 bgp->maxmed_onstartup_value = BGP_MAXMED_VALUE_DEFAULT;
1309
1310 bgp_maxmed_update(bgp);
1311
1312 return CMD_SUCCESS;
1313 }
1314
1315 static int bgp_update_delay_config_vty(struct vty *vty, const char *delay,
1316 const char *wait)
1317 {
1318 VTY_DECLVAR_CONTEXT(bgp, bgp);
1319 uint16_t update_delay;
1320 uint16_t establish_wait;
1321
1322 update_delay = strtoul(delay, NULL, 10);
1323
1324 if (!wait) /* update-delay <delay> */
1325 {
1326 bgp->v_update_delay = update_delay;
1327 bgp->v_establish_wait = bgp->v_update_delay;
1328 return CMD_SUCCESS;
1329 }
1330
1331 /* update-delay <delay> <establish-wait> */
1332 establish_wait = atoi(wait);
1333 if (update_delay < establish_wait) {
1334 vty_out(vty,
1335 "%%Failed: update-delay less than the establish-wait!\n");
1336 return CMD_WARNING_CONFIG_FAILED;
1337 }
1338
1339 bgp->v_update_delay = update_delay;
1340 bgp->v_establish_wait = establish_wait;
1341
1342 return CMD_SUCCESS;
1343 }
1344
1345 static int bgp_update_delay_deconfig_vty(struct vty *vty)
1346 {
1347 VTY_DECLVAR_CONTEXT(bgp, bgp);
1348
1349 bgp->v_update_delay = BGP_UPDATE_DELAY_DEF;
1350 bgp->v_establish_wait = bgp->v_update_delay;
1351
1352 return CMD_SUCCESS;
1353 }
1354
1355 void bgp_config_write_update_delay(struct vty *vty, struct bgp *bgp)
1356 {
1357 if (bgp->v_update_delay != BGP_UPDATE_DELAY_DEF) {
1358 vty_out(vty, " update-delay %d", bgp->v_update_delay);
1359 if (bgp->v_update_delay != bgp->v_establish_wait)
1360 vty_out(vty, " %d", bgp->v_establish_wait);
1361 vty_out(vty, "\n");
1362 }
1363 }
1364
1365
1366 /* Update-delay configuration */
1367 DEFUN (bgp_update_delay,
1368 bgp_update_delay_cmd,
1369 "update-delay (0-3600)",
1370 "Force initial delay for best-path and updates\n"
1371 "Seconds\n")
1372 {
1373 int idx_number = 1;
1374 return bgp_update_delay_config_vty(vty, argv[idx_number]->arg, NULL);
1375 }
1376
1377 DEFUN (bgp_update_delay_establish_wait,
1378 bgp_update_delay_establish_wait_cmd,
1379 "update-delay (0-3600) (1-3600)",
1380 "Force initial delay for best-path and updates\n"
1381 "Seconds\n"
1382 "Seconds\n")
1383 {
1384 int idx_number = 1;
1385 int idx_number_2 = 2;
1386 return bgp_update_delay_config_vty(vty, argv[idx_number]->arg,
1387 argv[idx_number_2]->arg);
1388 }
1389
1390 /* Update-delay deconfiguration */
1391 DEFUN (no_bgp_update_delay,
1392 no_bgp_update_delay_cmd,
1393 "no update-delay [(0-3600) [(1-3600)]]",
1394 NO_STR
1395 "Force initial delay for best-path and updates\n"
1396 "Seconds\n"
1397 "Seconds\n")
1398 {
1399 return bgp_update_delay_deconfig_vty(vty);
1400 }
1401
1402
1403 static int bgp_wpkt_quanta_config_vty(struct vty *vty, const char *num,
1404 char set)
1405 {
1406 VTY_DECLVAR_CONTEXT(bgp, bgp);
1407
1408 if (set) {
1409 uint32_t quanta = strtoul(num, NULL, 10);
1410 atomic_store_explicit(&bgp->wpkt_quanta, quanta,
1411 memory_order_relaxed);
1412 } else {
1413 atomic_store_explicit(&bgp->wpkt_quanta, BGP_WRITE_PACKET_MAX,
1414 memory_order_relaxed);
1415 }
1416
1417 return CMD_SUCCESS;
1418 }
1419
1420 static int bgp_rpkt_quanta_config_vty(struct vty *vty, const char *num,
1421 char set)
1422 {
1423 VTY_DECLVAR_CONTEXT(bgp, bgp);
1424
1425 if (set) {
1426 uint32_t quanta = strtoul(num, NULL, 10);
1427 atomic_store_explicit(&bgp->rpkt_quanta, quanta,
1428 memory_order_relaxed);
1429 } else {
1430 atomic_store_explicit(&bgp->rpkt_quanta, BGP_READ_PACKET_MAX,
1431 memory_order_relaxed);
1432 }
1433
1434 return CMD_SUCCESS;
1435 }
1436
1437 void bgp_config_write_wpkt_quanta(struct vty *vty, struct bgp *bgp)
1438 {
1439 uint32_t quanta =
1440 atomic_load_explicit(&bgp->wpkt_quanta, memory_order_relaxed);
1441 if (quanta != BGP_WRITE_PACKET_MAX)
1442 vty_out(vty, " write-quanta %d\n", quanta);
1443 }
1444
1445 void bgp_config_write_rpkt_quanta(struct vty *vty, struct bgp *bgp)
1446 {
1447 uint32_t quanta =
1448 atomic_load_explicit(&bgp->rpkt_quanta, memory_order_relaxed);
1449 if (quanta != BGP_READ_PACKET_MAX)
1450 vty_out(vty, " read-quanta %d\n", quanta);
1451 }
1452
1453 /* Packet quanta configuration */
1454 DEFUN (bgp_wpkt_quanta,
1455 bgp_wpkt_quanta_cmd,
1456 "write-quanta (1-10)",
1457 "How many packets to write to peer socket per run\n"
1458 "Number of packets\n")
1459 {
1460 int idx_number = 1;
1461 return bgp_wpkt_quanta_config_vty(vty, argv[idx_number]->arg, 1);
1462 }
1463
1464 DEFUN (no_bgp_wpkt_quanta,
1465 no_bgp_wpkt_quanta_cmd,
1466 "no write-quanta (1-10)",
1467 NO_STR
1468 "How many packets to write to peer socket per I/O cycle\n"
1469 "Number of packets\n")
1470 {
1471 int idx_number = 2;
1472 return bgp_wpkt_quanta_config_vty(vty, argv[idx_number]->arg, 0);
1473 }
1474
1475 DEFUN (bgp_rpkt_quanta,
1476 bgp_rpkt_quanta_cmd,
1477 "read-quanta (1-10)",
1478 "How many packets to read from peer socket per I/O cycle\n"
1479 "Number of packets\n")
1480 {
1481 int idx_number = 1;
1482 return bgp_rpkt_quanta_config_vty(vty, argv[idx_number]->arg, 1);
1483 }
1484
1485 DEFUN (no_bgp_rpkt_quanta,
1486 no_bgp_rpkt_quanta_cmd,
1487 "no read-quanta (1-10)",
1488 NO_STR
1489 "How many packets to read from peer socket per I/O cycle\n"
1490 "Number of packets\n")
1491 {
1492 int idx_number = 2;
1493 return bgp_rpkt_quanta_config_vty(vty, argv[idx_number]->arg, 0);
1494 }
1495
1496 void bgp_config_write_coalesce_time(struct vty *vty, struct bgp *bgp)
1497 {
1498 if (!bgp->heuristic_coalesce)
1499 vty_out(vty, " coalesce-time %u\n", bgp->coalesce_time);
1500 }
1501
1502
1503 DEFUN (bgp_coalesce_time,
1504 bgp_coalesce_time_cmd,
1505 "coalesce-time (0-4294967295)",
1506 "Subgroup coalesce timer\n"
1507 "Subgroup coalesce timer value (in ms)\n")
1508 {
1509 VTY_DECLVAR_CONTEXT(bgp, bgp);
1510
1511 int idx = 0;
1512 argv_find(argv, argc, "(0-4294967295)", &idx);
1513 bgp->heuristic_coalesce = false;
1514 bgp->coalesce_time = strtoul(argv[idx]->arg, NULL, 10);
1515 return CMD_SUCCESS;
1516 }
1517
1518 DEFUN (no_bgp_coalesce_time,
1519 no_bgp_coalesce_time_cmd,
1520 "no coalesce-time (0-4294967295)",
1521 NO_STR
1522 "Subgroup coalesce timer\n"
1523 "Subgroup coalesce timer value (in ms)\n")
1524 {
1525 VTY_DECLVAR_CONTEXT(bgp, bgp);
1526
1527 bgp->heuristic_coalesce = true;
1528 bgp->coalesce_time = BGP_DEFAULT_SUBGROUP_COALESCE_TIME;
1529 return CMD_SUCCESS;
1530 }
1531
1532 /* Maximum-paths configuration */
1533 DEFUN (bgp_maxpaths,
1534 bgp_maxpaths_cmd,
1535 "maximum-paths " CMD_RANGE_STR(1, MULTIPATH_NUM),
1536 "Forward packets over multiple paths\n"
1537 "Number of paths\n")
1538 {
1539 int idx_number = 1;
1540 return bgp_maxpaths_config_vty(vty, BGP_PEER_EBGP,
1541 argv[idx_number]->arg, 0, 1);
1542 }
1543
1544 ALIAS_HIDDEN(bgp_maxpaths, bgp_maxpaths_hidden_cmd,
1545 "maximum-paths " CMD_RANGE_STR(1, MULTIPATH_NUM),
1546 "Forward packets over multiple paths\n"
1547 "Number of paths\n")
1548
1549 DEFUN (bgp_maxpaths_ibgp,
1550 bgp_maxpaths_ibgp_cmd,
1551 "maximum-paths ibgp " CMD_RANGE_STR(1, MULTIPATH_NUM),
1552 "Forward packets over multiple paths\n"
1553 "iBGP-multipath\n"
1554 "Number of paths\n")
1555 {
1556 int idx_number = 2;
1557 return bgp_maxpaths_config_vty(vty, BGP_PEER_IBGP,
1558 argv[idx_number]->arg, 0, 1);
1559 }
1560
1561 ALIAS_HIDDEN(bgp_maxpaths_ibgp, bgp_maxpaths_ibgp_hidden_cmd,
1562 "maximum-paths ibgp " CMD_RANGE_STR(1, MULTIPATH_NUM),
1563 "Forward packets over multiple paths\n"
1564 "iBGP-multipath\n"
1565 "Number of paths\n")
1566
1567 DEFUN (bgp_maxpaths_ibgp_cluster,
1568 bgp_maxpaths_ibgp_cluster_cmd,
1569 "maximum-paths ibgp " CMD_RANGE_STR(1, MULTIPATH_NUM) " equal-cluster-length",
1570 "Forward packets over multiple paths\n"
1571 "iBGP-multipath\n"
1572 "Number of paths\n"
1573 "Match the cluster length\n")
1574 {
1575 int idx_number = 2;
1576 return bgp_maxpaths_config_vty(
1577 vty, BGP_PEER_IBGP, argv[idx_number]->arg,
1578 BGP_FLAG_IBGP_MULTIPATH_SAME_CLUSTERLEN, 1);
1579 }
1580
1581 ALIAS_HIDDEN(bgp_maxpaths_ibgp_cluster, bgp_maxpaths_ibgp_cluster_hidden_cmd,
1582 "maximum-paths ibgp " CMD_RANGE_STR(
1583 1, MULTIPATH_NUM) " equal-cluster-length",
1584 "Forward packets over multiple paths\n"
1585 "iBGP-multipath\n"
1586 "Number of paths\n"
1587 "Match the cluster length\n")
1588
1589 DEFUN (no_bgp_maxpaths,
1590 no_bgp_maxpaths_cmd,
1591 "no maximum-paths [" CMD_RANGE_STR(1, MULTIPATH_NUM) "]",
1592 NO_STR
1593 "Forward packets over multiple paths\n"
1594 "Number of paths\n")
1595 {
1596 return bgp_maxpaths_config_vty(vty, BGP_PEER_EBGP, NULL, 0, 0);
1597 }
1598
1599 ALIAS_HIDDEN(no_bgp_maxpaths, no_bgp_maxpaths_hidden_cmd,
1600 "no maximum-paths [" CMD_RANGE_STR(1, MULTIPATH_NUM) "]", NO_STR
1601 "Forward packets over multiple paths\n"
1602 "Number of paths\n")
1603
1604 DEFUN (no_bgp_maxpaths_ibgp,
1605 no_bgp_maxpaths_ibgp_cmd,
1606 "no maximum-paths ibgp [" CMD_RANGE_STR(1, MULTIPATH_NUM) " [equal-cluster-length]]",
1607 NO_STR
1608 "Forward packets over multiple paths\n"
1609 "iBGP-multipath\n"
1610 "Number of paths\n"
1611 "Match the cluster length\n")
1612 {
1613 return bgp_maxpaths_config_vty(vty, BGP_PEER_IBGP, NULL, 0, 0);
1614 }
1615
1616 ALIAS_HIDDEN(no_bgp_maxpaths_ibgp, no_bgp_maxpaths_ibgp_hidden_cmd,
1617 "no maximum-paths ibgp [" CMD_RANGE_STR(
1618 1, MULTIPATH_NUM) " [equal-cluster-length]]",
1619 NO_STR
1620 "Forward packets over multiple paths\n"
1621 "iBGP-multipath\n"
1622 "Number of paths\n"
1623 "Match the cluster length\n")
1624
1625 void bgp_config_write_maxpaths(struct vty *vty, struct bgp *bgp, afi_t afi,
1626 safi_t safi)
1627 {
1628 if (bgp->maxpaths[afi][safi].maxpaths_ebgp != MULTIPATH_NUM) {
1629 vty_out(vty, " maximum-paths %d\n",
1630 bgp->maxpaths[afi][safi].maxpaths_ebgp);
1631 }
1632
1633 if (bgp->maxpaths[afi][safi].maxpaths_ibgp != MULTIPATH_NUM) {
1634 vty_out(vty, " maximum-paths ibgp %d",
1635 bgp->maxpaths[afi][safi].maxpaths_ibgp);
1636 if (CHECK_FLAG(bgp->maxpaths[afi][safi].ibgp_flags,
1637 BGP_FLAG_IBGP_MULTIPATH_SAME_CLUSTERLEN))
1638 vty_out(vty, " equal-cluster-length");
1639 vty_out(vty, "\n");
1640 }
1641 }
1642
1643 /* BGP timers. */
1644
1645 DEFUN (bgp_timers,
1646 bgp_timers_cmd,
1647 "timers bgp (0-65535) (0-65535)",
1648 "Adjust routing timers\n"
1649 "BGP timers\n"
1650 "Keepalive interval\n"
1651 "Holdtime\n")
1652 {
1653 VTY_DECLVAR_CONTEXT(bgp, bgp);
1654 int idx_number = 2;
1655 int idx_number_2 = 3;
1656 unsigned long keepalive = 0;
1657 unsigned long holdtime = 0;
1658
1659 keepalive = strtoul(argv[idx_number]->arg, NULL, 10);
1660 holdtime = strtoul(argv[idx_number_2]->arg, NULL, 10);
1661
1662 /* Holdtime value check. */
1663 if (holdtime < 3 && holdtime != 0) {
1664 vty_out(vty,
1665 "%% hold time value must be either 0 or greater than 3\n");
1666 return CMD_WARNING_CONFIG_FAILED;
1667 }
1668
1669 bgp_timers_set(bgp, keepalive, holdtime);
1670
1671 return CMD_SUCCESS;
1672 }
1673
1674 DEFUN (no_bgp_timers,
1675 no_bgp_timers_cmd,
1676 "no timers bgp [(0-65535) (0-65535)]",
1677 NO_STR
1678 "Adjust routing timers\n"
1679 "BGP timers\n"
1680 "Keepalive interval\n"
1681 "Holdtime\n")
1682 {
1683 VTY_DECLVAR_CONTEXT(bgp, bgp);
1684 bgp_timers_unset(bgp);
1685
1686 return CMD_SUCCESS;
1687 }
1688
1689
1690 DEFUN (bgp_client_to_client_reflection,
1691 bgp_client_to_client_reflection_cmd,
1692 "bgp client-to-client reflection",
1693 "BGP specific commands\n"
1694 "Configure client to client route reflection\n"
1695 "reflection of routes allowed\n")
1696 {
1697 VTY_DECLVAR_CONTEXT(bgp, bgp);
1698 bgp_flag_unset(bgp, BGP_FLAG_NO_CLIENT_TO_CLIENT);
1699 bgp_clear_star_soft_out(vty, bgp->name);
1700
1701 return CMD_SUCCESS;
1702 }
1703
1704 DEFUN (no_bgp_client_to_client_reflection,
1705 no_bgp_client_to_client_reflection_cmd,
1706 "no bgp client-to-client reflection",
1707 NO_STR
1708 "BGP specific commands\n"
1709 "Configure client to client route reflection\n"
1710 "reflection of routes allowed\n")
1711 {
1712 VTY_DECLVAR_CONTEXT(bgp, bgp);
1713 bgp_flag_set(bgp, BGP_FLAG_NO_CLIENT_TO_CLIENT);
1714 bgp_clear_star_soft_out(vty, bgp->name);
1715
1716 return CMD_SUCCESS;
1717 }
1718
1719 /* "bgp always-compare-med" configuration. */
1720 DEFUN (bgp_always_compare_med,
1721 bgp_always_compare_med_cmd,
1722 "bgp always-compare-med",
1723 "BGP specific commands\n"
1724 "Allow comparing MED from different neighbors\n")
1725 {
1726 VTY_DECLVAR_CONTEXT(bgp, bgp);
1727 bgp_flag_set(bgp, BGP_FLAG_ALWAYS_COMPARE_MED);
1728 bgp_recalculate_all_bestpaths(bgp);
1729
1730 return CMD_SUCCESS;
1731 }
1732
1733 DEFUN (no_bgp_always_compare_med,
1734 no_bgp_always_compare_med_cmd,
1735 "no bgp always-compare-med",
1736 NO_STR
1737 "BGP specific commands\n"
1738 "Allow comparing MED from different neighbors\n")
1739 {
1740 VTY_DECLVAR_CONTEXT(bgp, bgp);
1741 bgp_flag_unset(bgp, BGP_FLAG_ALWAYS_COMPARE_MED);
1742 bgp_recalculate_all_bestpaths(bgp);
1743
1744 return CMD_SUCCESS;
1745 }
1746
1747 /* "bgp deterministic-med" configuration. */
1748 DEFUN (bgp_deterministic_med,
1749 bgp_deterministic_med_cmd,
1750 "bgp deterministic-med",
1751 "BGP specific commands\n"
1752 "Pick the best-MED path among paths advertised from the neighboring AS\n")
1753 {
1754 VTY_DECLVAR_CONTEXT(bgp, bgp);
1755
1756 if (!bgp_flag_check(bgp, BGP_FLAG_DETERMINISTIC_MED)) {
1757 bgp_flag_set(bgp, BGP_FLAG_DETERMINISTIC_MED);
1758 bgp_recalculate_all_bestpaths(bgp);
1759 }
1760
1761 return CMD_SUCCESS;
1762 }
1763
1764 DEFUN (no_bgp_deterministic_med,
1765 no_bgp_deterministic_med_cmd,
1766 "no bgp deterministic-med",
1767 NO_STR
1768 "BGP specific commands\n"
1769 "Pick the best-MED path among paths advertised from the neighboring AS\n")
1770 {
1771 VTY_DECLVAR_CONTEXT(bgp, bgp);
1772 int bestpath_per_as_used;
1773 afi_t afi;
1774 safi_t safi;
1775 struct peer *peer;
1776 struct listnode *node, *nnode;
1777
1778 if (bgp_flag_check(bgp, BGP_FLAG_DETERMINISTIC_MED)) {
1779 bestpath_per_as_used = 0;
1780
1781 for (ALL_LIST_ELEMENTS(bgp->peer, node, nnode, peer)) {
1782 FOREACH_AFI_SAFI (afi, safi)
1783 if (CHECK_FLAG(
1784 peer->af_flags[afi][safi],
1785 PEER_FLAG_ADDPATH_TX_BESTPATH_PER_AS)) {
1786 bestpath_per_as_used = 1;
1787 break;
1788 }
1789
1790 if (bestpath_per_as_used)
1791 break;
1792 }
1793
1794 if (bestpath_per_as_used) {
1795 vty_out(vty,
1796 "bgp deterministic-med cannot be disabled while addpath-tx-bestpath-per-AS is in use\n");
1797 return CMD_WARNING_CONFIG_FAILED;
1798 } else {
1799 bgp_flag_unset(bgp, BGP_FLAG_DETERMINISTIC_MED);
1800 bgp_recalculate_all_bestpaths(bgp);
1801 }
1802 }
1803
1804 return CMD_SUCCESS;
1805 }
1806
1807 /* "bgp graceful-restart" configuration. */
1808 DEFUN (bgp_graceful_restart,
1809 bgp_graceful_restart_cmd,
1810 "bgp graceful-restart",
1811 "BGP specific commands\n"
1812 "Graceful restart capability parameters\n")
1813 {
1814 VTY_DECLVAR_CONTEXT(bgp, bgp);
1815 bgp_flag_set(bgp, BGP_FLAG_GRACEFUL_RESTART);
1816 return CMD_SUCCESS;
1817 }
1818
1819 DEFUN (no_bgp_graceful_restart,
1820 no_bgp_graceful_restart_cmd,
1821 "no bgp graceful-restart",
1822 NO_STR
1823 "BGP specific commands\n"
1824 "Graceful restart capability parameters\n")
1825 {
1826 VTY_DECLVAR_CONTEXT(bgp, bgp);
1827 bgp_flag_unset(bgp, BGP_FLAG_GRACEFUL_RESTART);
1828 return CMD_SUCCESS;
1829 }
1830
1831 DEFUN (bgp_graceful_restart_stalepath_time,
1832 bgp_graceful_restart_stalepath_time_cmd,
1833 "bgp graceful-restart stalepath-time (1-3600)",
1834 "BGP specific commands\n"
1835 "Graceful restart capability parameters\n"
1836 "Set the max time to hold onto restarting peer's stale paths\n"
1837 "Delay value (seconds)\n")
1838 {
1839 VTY_DECLVAR_CONTEXT(bgp, bgp);
1840 int idx_number = 3;
1841 uint32_t stalepath;
1842
1843 stalepath = strtoul(argv[idx_number]->arg, NULL, 10);
1844 bgp->stalepath_time = stalepath;
1845 return CMD_SUCCESS;
1846 }
1847
1848 DEFUN (bgp_graceful_restart_restart_time,
1849 bgp_graceful_restart_restart_time_cmd,
1850 "bgp graceful-restart restart-time (1-3600)",
1851 "BGP specific commands\n"
1852 "Graceful restart capability parameters\n"
1853 "Set the time to wait to delete stale routes before a BGP open message is received\n"
1854 "Delay value (seconds)\n")
1855 {
1856 VTY_DECLVAR_CONTEXT(bgp, bgp);
1857 int idx_number = 3;
1858 uint32_t restart;
1859
1860 restart = strtoul(argv[idx_number]->arg, NULL, 10);
1861 bgp->restart_time = restart;
1862 return CMD_SUCCESS;
1863 }
1864
1865 DEFUN (no_bgp_graceful_restart_stalepath_time,
1866 no_bgp_graceful_restart_stalepath_time_cmd,
1867 "no bgp graceful-restart stalepath-time [(1-3600)]",
1868 NO_STR
1869 "BGP specific commands\n"
1870 "Graceful restart capability parameters\n"
1871 "Set the max time to hold onto restarting peer's stale paths\n"
1872 "Delay value (seconds)\n")
1873 {
1874 VTY_DECLVAR_CONTEXT(bgp, bgp);
1875
1876 bgp->stalepath_time = BGP_DEFAULT_STALEPATH_TIME;
1877 return CMD_SUCCESS;
1878 }
1879
1880 DEFUN (no_bgp_graceful_restart_restart_time,
1881 no_bgp_graceful_restart_restart_time_cmd,
1882 "no bgp graceful-restart restart-time [(1-3600)]",
1883 NO_STR
1884 "BGP specific commands\n"
1885 "Graceful restart capability parameters\n"
1886 "Set the time to wait to delete stale routes before a BGP open message is received\n"
1887 "Delay value (seconds)\n")
1888 {
1889 VTY_DECLVAR_CONTEXT(bgp, bgp);
1890
1891 bgp->restart_time = BGP_DEFAULT_RESTART_TIME;
1892 return CMD_SUCCESS;
1893 }
1894
1895 DEFUN (bgp_graceful_restart_preserve_fw,
1896 bgp_graceful_restart_preserve_fw_cmd,
1897 "bgp graceful-restart preserve-fw-state",
1898 "BGP specific commands\n"
1899 "Graceful restart capability parameters\n"
1900 "Sets F-bit indication that fib is preserved while doing Graceful Restart\n")
1901 {
1902 VTY_DECLVAR_CONTEXT(bgp, bgp);
1903 bgp_flag_set(bgp, BGP_FLAG_GR_PRESERVE_FWD);
1904 return CMD_SUCCESS;
1905 }
1906
1907 DEFUN (no_bgp_graceful_restart_preserve_fw,
1908 no_bgp_graceful_restart_preserve_fw_cmd,
1909 "no bgp graceful-restart preserve-fw-state",
1910 NO_STR
1911 "BGP specific commands\n"
1912 "Graceful restart capability parameters\n"
1913 "Unsets F-bit indication that fib is preserved while doing Graceful Restart\n")
1914 {
1915 VTY_DECLVAR_CONTEXT(bgp, bgp);
1916 bgp_flag_unset(bgp, BGP_FLAG_GR_PRESERVE_FWD);
1917 return CMD_SUCCESS;
1918 }
1919
1920 static void bgp_redistribute_redo(struct bgp *bgp)
1921 {
1922 afi_t afi;
1923 int i;
1924 struct list *red_list;
1925 struct listnode *node;
1926 struct bgp_redist *red;
1927
1928 for (afi = AFI_IP; afi < AFI_MAX; afi++) {
1929 for (i = 0; i < ZEBRA_ROUTE_MAX; i++) {
1930
1931 red_list = bgp->redist[afi][i];
1932 if (!red_list)
1933 continue;
1934
1935 for (ALL_LIST_ELEMENTS_RO(red_list, node, red)) {
1936 bgp_redistribute_resend(bgp, afi, i,
1937 red->instance);
1938 }
1939 }
1940 }
1941 }
1942
1943 /* "bgp graceful-shutdown" configuration */
1944 DEFUN (bgp_graceful_shutdown,
1945 bgp_graceful_shutdown_cmd,
1946 "bgp graceful-shutdown",
1947 BGP_STR
1948 "Graceful shutdown parameters\n")
1949 {
1950 VTY_DECLVAR_CONTEXT(bgp, bgp);
1951
1952 if (!bgp_flag_check(bgp, BGP_FLAG_GRACEFUL_SHUTDOWN)) {
1953 bgp_flag_set(bgp, BGP_FLAG_GRACEFUL_SHUTDOWN);
1954 bgp_static_redo_import_check(bgp);
1955 bgp_redistribute_redo(bgp);
1956 bgp_clear_star_soft_out(vty, bgp->name);
1957 bgp_clear_star_soft_in(vty, bgp->name);
1958 }
1959
1960 return CMD_SUCCESS;
1961 }
1962
1963 DEFUN (no_bgp_graceful_shutdown,
1964 no_bgp_graceful_shutdown_cmd,
1965 "no bgp graceful-shutdown",
1966 NO_STR
1967 BGP_STR
1968 "Graceful shutdown parameters\n")
1969 {
1970 VTY_DECLVAR_CONTEXT(bgp, bgp);
1971
1972 if (bgp_flag_check(bgp, BGP_FLAG_GRACEFUL_SHUTDOWN)) {
1973 bgp_flag_unset(bgp, BGP_FLAG_GRACEFUL_SHUTDOWN);
1974 bgp_static_redo_import_check(bgp);
1975 bgp_redistribute_redo(bgp);
1976 bgp_clear_star_soft_out(vty, bgp->name);
1977 bgp_clear_star_soft_in(vty, bgp->name);
1978 }
1979
1980 return CMD_SUCCESS;
1981 }
1982
1983 /* "bgp fast-external-failover" configuration. */
1984 DEFUN (bgp_fast_external_failover,
1985 bgp_fast_external_failover_cmd,
1986 "bgp fast-external-failover",
1987 BGP_STR
1988 "Immediately reset session if a link to a directly connected external peer goes down\n")
1989 {
1990 VTY_DECLVAR_CONTEXT(bgp, bgp);
1991 bgp_flag_unset(bgp, BGP_FLAG_NO_FAST_EXT_FAILOVER);
1992 return CMD_SUCCESS;
1993 }
1994
1995 DEFUN (no_bgp_fast_external_failover,
1996 no_bgp_fast_external_failover_cmd,
1997 "no bgp fast-external-failover",
1998 NO_STR
1999 BGP_STR
2000 "Immediately reset session if a link to a directly connected external peer goes down\n")
2001 {
2002 VTY_DECLVAR_CONTEXT(bgp, bgp);
2003 bgp_flag_set(bgp, BGP_FLAG_NO_FAST_EXT_FAILOVER);
2004 return CMD_SUCCESS;
2005 }
2006
2007 /* "bgp enforce-first-as" configuration. */
2008 #if defined(VERSION_TYPE_DEV) && CONFDATE > 20180517
2009 CPP_NOTICE("bgpd: remove deprecated '[no] bgp enforce-first-as' commands")
2010 #endif
2011
2012 DEFUN_DEPRECATED (bgp_enforce_first_as,
2013 bgp_enforce_first_as_cmd,
2014 "bgp enforce-first-as",
2015 BGP_STR
2016 "Enforce the first AS for EBGP routes\n")
2017 {
2018 VTY_DECLVAR_CONTEXT(bgp, bgp);
2019 bgp_flag_set(bgp, BGP_FLAG_ENFORCE_FIRST_AS);
2020
2021 return CMD_SUCCESS;
2022 }
2023
2024 DEFUN_DEPRECATED (no_bgp_enforce_first_as,
2025 no_bgp_enforce_first_as_cmd,
2026 "no bgp enforce-first-as",
2027 NO_STR
2028 BGP_STR
2029 "Enforce the first AS for EBGP routes\n")
2030 {
2031 VTY_DECLVAR_CONTEXT(bgp, bgp);
2032 bgp_flag_unset(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 peer = NULL;
3384
3385 ret = str2sockunion(argv[idx_peer]->arg, &su);
3386 if (ret < 0) {
3387 peer = peer_lookup_by_conf_if(bgp, argv[idx_peer]->arg);
3388 if (!peer) {
3389 vty_out(vty, "%% Malformed address or name: %s\n",
3390 argv[idx_peer]->arg);
3391 return CMD_WARNING_CONFIG_FAILED;
3392 }
3393 } else {
3394 if (peer_address_self_check(bgp, &su)) {
3395 vty_out(vty,
3396 "%% Can not configure the local system as neighbor\n");
3397 return CMD_WARNING_CONFIG_FAILED;
3398 }
3399
3400 /* Disallow for dynamic neighbor. */
3401 peer = peer_lookup(bgp, &su);
3402 if (peer && peer_dynamic_neighbor(peer)) {
3403 vty_out(vty,
3404 "%% Operation not allowed on a dynamic neighbor\n");
3405 return CMD_WARNING_CONFIG_FAILED;
3406 }
3407 }
3408
3409 group = peer_group_lookup(bgp, argv[idx_word]->arg);
3410 if (!group) {
3411 vty_out(vty, "%% Configure the peer-group first\n");
3412 return CMD_WARNING_CONFIG_FAILED;
3413 }
3414
3415 ret = peer_group_bind(bgp, &su, peer, group, &as);
3416
3417 if (ret == BGP_ERR_PEER_GROUP_PEER_TYPE_DIFFERENT) {
3418 vty_out(vty,
3419 "%% Peer with AS %u cannot be in this peer-group, members must be all internal or all external\n",
3420 as);
3421 return CMD_WARNING_CONFIG_FAILED;
3422 }
3423
3424 return bgp_vty_return(vty, ret);
3425 }
3426
3427 ALIAS_HIDDEN(neighbor_set_peer_group, neighbor_set_peer_group_hidden_cmd,
3428 "neighbor <A.B.C.D|X:X::X:X|WORD> peer-group WORD",
3429 NEIGHBOR_STR NEIGHBOR_ADDR_STR2
3430 "Member of the peer-group\n"
3431 "Peer-group name\n")
3432
3433 DEFUN (no_neighbor_set_peer_group,
3434 no_neighbor_set_peer_group_cmd,
3435 "no neighbor <A.B.C.D|X:X::X:X|WORD> peer-group WORD",
3436 NO_STR
3437 NEIGHBOR_STR
3438 NEIGHBOR_ADDR_STR2
3439 "Member of the peer-group\n"
3440 "Peer-group name\n")
3441 {
3442 VTY_DECLVAR_CONTEXT(bgp, bgp);
3443 int idx_peer = 2;
3444 int idx_word = 4;
3445 int ret;
3446 struct peer *peer;
3447 struct peer_group *group;
3448
3449 peer = peer_lookup_vty(vty, argv[idx_peer]->arg);
3450 if (!peer)
3451 return CMD_WARNING_CONFIG_FAILED;
3452
3453 group = peer_group_lookup(bgp, argv[idx_word]->arg);
3454 if (!group) {
3455 vty_out(vty, "%% Configure the peer-group first\n");
3456 return CMD_WARNING_CONFIG_FAILED;
3457 }
3458
3459 ret = peer_delete(peer);
3460
3461 return bgp_vty_return(vty, ret);
3462 }
3463
3464 ALIAS_HIDDEN(no_neighbor_set_peer_group, no_neighbor_set_peer_group_hidden_cmd,
3465 "no neighbor <A.B.C.D|X:X::X:X|WORD> peer-group WORD",
3466 NO_STR NEIGHBOR_STR NEIGHBOR_ADDR_STR2
3467 "Member of the peer-group\n"
3468 "Peer-group name\n")
3469
3470 static int peer_flag_modify_vty(struct vty *vty, const char *ip_str,
3471 uint32_t flag, int set)
3472 {
3473 int ret;
3474 struct peer *peer;
3475
3476 peer = peer_and_group_lookup_vty(vty, ip_str);
3477 if (!peer)
3478 return CMD_WARNING_CONFIG_FAILED;
3479
3480 /*
3481 * If 'neighbor <interface>', then this is for directly connected peers,
3482 * we should not accept disable-connected-check.
3483 */
3484 if (peer->conf_if && (flag == PEER_FLAG_DISABLE_CONNECTED_CHECK)) {
3485 vty_out(vty,
3486 "%s is directly connected peer, cannot accept disable-"
3487 "connected-check\n",
3488 ip_str);
3489 return CMD_WARNING_CONFIG_FAILED;
3490 }
3491
3492 if (!set && flag == PEER_FLAG_SHUTDOWN)
3493 peer_tx_shutdown_message_unset(peer);
3494
3495 if (set)
3496 ret = peer_flag_set(peer, flag);
3497 else
3498 ret = peer_flag_unset(peer, flag);
3499
3500 return bgp_vty_return(vty, ret);
3501 }
3502
3503 static int peer_flag_set_vty(struct vty *vty, const char *ip_str, uint32_t flag)
3504 {
3505 return peer_flag_modify_vty(vty, ip_str, flag, 1);
3506 }
3507
3508 static int peer_flag_unset_vty(struct vty *vty, const char *ip_str,
3509 uint32_t flag)
3510 {
3511 return peer_flag_modify_vty(vty, ip_str, flag, 0);
3512 }
3513
3514 /* neighbor passive. */
3515 DEFUN (neighbor_passive,
3516 neighbor_passive_cmd,
3517 "neighbor <A.B.C.D|X:X::X:X|WORD> passive",
3518 NEIGHBOR_STR
3519 NEIGHBOR_ADDR_STR2
3520 "Don't send open messages to this neighbor\n")
3521 {
3522 int idx_peer = 1;
3523 return peer_flag_set_vty(vty, argv[idx_peer]->arg, PEER_FLAG_PASSIVE);
3524 }
3525
3526 DEFUN (no_neighbor_passive,
3527 no_neighbor_passive_cmd,
3528 "no neighbor <A.B.C.D|X:X::X:X|WORD> passive",
3529 NO_STR
3530 NEIGHBOR_STR
3531 NEIGHBOR_ADDR_STR2
3532 "Don't send open messages to this neighbor\n")
3533 {
3534 int idx_peer = 2;
3535 return peer_flag_unset_vty(vty, argv[idx_peer]->arg, PEER_FLAG_PASSIVE);
3536 }
3537
3538 /* neighbor shutdown. */
3539 DEFUN (neighbor_shutdown_msg,
3540 neighbor_shutdown_msg_cmd,
3541 "neighbor <A.B.C.D|X:X::X:X|WORD> shutdown message MSG...",
3542 NEIGHBOR_STR
3543 NEIGHBOR_ADDR_STR2
3544 "Administratively shut down this neighbor\n"
3545 "Add a shutdown message (draft-ietf-idr-shutdown-06)\n"
3546 "Shutdown message\n")
3547 {
3548 int idx_peer = 1;
3549
3550 if (argc >= 5) {
3551 struct peer *peer =
3552 peer_and_group_lookup_vty(vty, argv[idx_peer]->arg);
3553 char *message;
3554
3555 if (!peer)
3556 return CMD_WARNING_CONFIG_FAILED;
3557 message = argv_concat(argv, argc, 4);
3558 peer_tx_shutdown_message_set(peer, message);
3559 XFREE(MTYPE_TMP, message);
3560 }
3561
3562 return peer_flag_set_vty(vty, argv[idx_peer]->arg, PEER_FLAG_SHUTDOWN);
3563 }
3564
3565 ALIAS(neighbor_shutdown_msg, neighbor_shutdown_cmd,
3566 "neighbor <A.B.C.D|X:X::X:X|WORD> shutdown",
3567 NEIGHBOR_STR NEIGHBOR_ADDR_STR2
3568 "Administratively shut down this neighbor\n")
3569
3570 DEFUN (no_neighbor_shutdown_msg,
3571 no_neighbor_shutdown_msg_cmd,
3572 "no neighbor <A.B.C.D|X:X::X:X|WORD> shutdown message MSG...",
3573 NO_STR
3574 NEIGHBOR_STR
3575 NEIGHBOR_ADDR_STR2
3576 "Administratively shut down this neighbor\n"
3577 "Remove a shutdown message (draft-ietf-idr-shutdown-06)\n"
3578 "Shutdown message\n")
3579 {
3580 int idx_peer = 2;
3581
3582 return peer_flag_unset_vty(vty, argv[idx_peer]->arg,
3583 PEER_FLAG_SHUTDOWN);
3584 }
3585
3586 ALIAS(no_neighbor_shutdown_msg, no_neighbor_shutdown_cmd,
3587 "no neighbor <A.B.C.D|X:X::X:X|WORD> shutdown",
3588 NO_STR NEIGHBOR_STR NEIGHBOR_ADDR_STR2
3589 "Administratively shut down this neighbor\n")
3590
3591 /* neighbor capability dynamic. */
3592 DEFUN (neighbor_capability_dynamic,
3593 neighbor_capability_dynamic_cmd,
3594 "neighbor <A.B.C.D|X:X::X:X|WORD> capability dynamic",
3595 NEIGHBOR_STR
3596 NEIGHBOR_ADDR_STR2
3597 "Advertise capability to the peer\n"
3598 "Advertise dynamic capability to this neighbor\n")
3599 {
3600 int idx_peer = 1;
3601 return peer_flag_set_vty(vty, argv[idx_peer]->arg,
3602 PEER_FLAG_DYNAMIC_CAPABILITY);
3603 }
3604
3605 DEFUN (no_neighbor_capability_dynamic,
3606 no_neighbor_capability_dynamic_cmd,
3607 "no neighbor <A.B.C.D|X:X::X:X|WORD> capability dynamic",
3608 NO_STR
3609 NEIGHBOR_STR
3610 NEIGHBOR_ADDR_STR2
3611 "Advertise capability to the peer\n"
3612 "Advertise dynamic capability to this neighbor\n")
3613 {
3614 int idx_peer = 2;
3615 return peer_flag_unset_vty(vty, argv[idx_peer]->arg,
3616 PEER_FLAG_DYNAMIC_CAPABILITY);
3617 }
3618
3619 /* neighbor dont-capability-negotiate */
3620 DEFUN (neighbor_dont_capability_negotiate,
3621 neighbor_dont_capability_negotiate_cmd,
3622 "neighbor <A.B.C.D|X:X::X:X|WORD> dont-capability-negotiate",
3623 NEIGHBOR_STR
3624 NEIGHBOR_ADDR_STR2
3625 "Do not perform capability negotiation\n")
3626 {
3627 int idx_peer = 1;
3628 return peer_flag_set_vty(vty, argv[idx_peer]->arg,
3629 PEER_FLAG_DONT_CAPABILITY);
3630 }
3631
3632 DEFUN (no_neighbor_dont_capability_negotiate,
3633 no_neighbor_dont_capability_negotiate_cmd,
3634 "no neighbor <A.B.C.D|X:X::X:X|WORD> dont-capability-negotiate",
3635 NO_STR
3636 NEIGHBOR_STR
3637 NEIGHBOR_ADDR_STR2
3638 "Do not perform capability negotiation\n")
3639 {
3640 int idx_peer = 2;
3641 return peer_flag_unset_vty(vty, argv[idx_peer]->arg,
3642 PEER_FLAG_DONT_CAPABILITY);
3643 }
3644
3645 /* neighbor capability extended next hop encoding */
3646 DEFUN (neighbor_capability_enhe,
3647 neighbor_capability_enhe_cmd,
3648 "neighbor <A.B.C.D|X:X::X:X|WORD> capability extended-nexthop",
3649 NEIGHBOR_STR
3650 NEIGHBOR_ADDR_STR2
3651 "Advertise capability to the peer\n"
3652 "Advertise extended next-hop capability to the peer\n")
3653 {
3654 int idx_peer = 1;
3655 return peer_flag_set_vty(vty, argv[idx_peer]->arg,
3656 PEER_FLAG_CAPABILITY_ENHE);
3657 }
3658
3659 DEFUN (no_neighbor_capability_enhe,
3660 no_neighbor_capability_enhe_cmd,
3661 "no neighbor <A.B.C.D|X:X::X:X|WORD> capability extended-nexthop",
3662 NO_STR
3663 NEIGHBOR_STR
3664 NEIGHBOR_ADDR_STR2
3665 "Advertise capability to the peer\n"
3666 "Advertise extended next-hop capability to the peer\n")
3667 {
3668 int idx_peer = 2;
3669 return peer_flag_unset_vty(vty, argv[idx_peer]->arg,
3670 PEER_FLAG_CAPABILITY_ENHE);
3671 }
3672
3673 static int peer_af_flag_modify_vty(struct vty *vty, const char *peer_str,
3674 afi_t afi, safi_t safi, uint32_t flag,
3675 int set)
3676 {
3677 int ret;
3678 struct peer *peer;
3679
3680 peer = peer_and_group_lookup_vty(vty, peer_str);
3681 if (!peer)
3682 return CMD_WARNING_CONFIG_FAILED;
3683
3684 if (set)
3685 ret = peer_af_flag_set(peer, afi, safi, flag);
3686 else
3687 ret = peer_af_flag_unset(peer, afi, safi, flag);
3688
3689 return bgp_vty_return(vty, ret);
3690 }
3691
3692 static int peer_af_flag_set_vty(struct vty *vty, const char *peer_str,
3693 afi_t afi, safi_t safi, uint32_t flag)
3694 {
3695 return peer_af_flag_modify_vty(vty, peer_str, afi, safi, flag, 1);
3696 }
3697
3698 static int peer_af_flag_unset_vty(struct vty *vty, const char *peer_str,
3699 afi_t afi, safi_t safi, uint32_t flag)
3700 {
3701 return peer_af_flag_modify_vty(vty, peer_str, afi, safi, flag, 0);
3702 }
3703
3704 /* neighbor capability orf prefix-list. */
3705 DEFUN (neighbor_capability_orf_prefix,
3706 neighbor_capability_orf_prefix_cmd,
3707 "neighbor <A.B.C.D|X:X::X:X|WORD> capability orf prefix-list <both|send|receive>",
3708 NEIGHBOR_STR
3709 NEIGHBOR_ADDR_STR2
3710 "Advertise capability to the peer\n"
3711 "Advertise ORF capability to the peer\n"
3712 "Advertise prefixlist ORF capability to this neighbor\n"
3713 "Capability to SEND and RECEIVE the ORF to/from this neighbor\n"
3714 "Capability to RECEIVE the ORF from this neighbor\n"
3715 "Capability to SEND the ORF to this neighbor\n")
3716 {
3717 int idx_peer = 1;
3718 int idx_send_recv = 5;
3719 uint16_t flag = 0;
3720
3721 if (strmatch(argv[idx_send_recv]->text, "send"))
3722 flag = PEER_FLAG_ORF_PREFIX_SM;
3723 else if (strmatch(argv[idx_send_recv]->text, "receive"))
3724 flag = PEER_FLAG_ORF_PREFIX_RM;
3725 else if (strmatch(argv[idx_send_recv]->text, "both"))
3726 flag = PEER_FLAG_ORF_PREFIX_SM | PEER_FLAG_ORF_PREFIX_RM;
3727 else {
3728 vty_out(vty, "%% BGP invalid orf prefix-list option\n");
3729 return CMD_WARNING_CONFIG_FAILED;
3730 }
3731
3732 return peer_af_flag_set_vty(vty, argv[idx_peer]->arg, bgp_node_afi(vty),
3733 bgp_node_safi(vty), flag);
3734 }
3735
3736 ALIAS_HIDDEN(
3737 neighbor_capability_orf_prefix,
3738 neighbor_capability_orf_prefix_hidden_cmd,
3739 "neighbor <A.B.C.D|X:X::X:X|WORD> capability orf prefix-list <both|send|receive>",
3740 NEIGHBOR_STR NEIGHBOR_ADDR_STR2
3741 "Advertise capability to the peer\n"
3742 "Advertise ORF capability to the peer\n"
3743 "Advertise prefixlist ORF capability to this neighbor\n"
3744 "Capability to SEND and RECEIVE the ORF to/from this neighbor\n"
3745 "Capability to RECEIVE the ORF from this neighbor\n"
3746 "Capability to SEND the ORF to this neighbor\n")
3747
3748 DEFUN (no_neighbor_capability_orf_prefix,
3749 no_neighbor_capability_orf_prefix_cmd,
3750 "no neighbor <A.B.C.D|X:X::X:X|WORD> capability orf prefix-list <both|send|receive>",
3751 NO_STR
3752 NEIGHBOR_STR
3753 NEIGHBOR_ADDR_STR2
3754 "Advertise capability to the peer\n"
3755 "Advertise ORF capability to the peer\n"
3756 "Advertise prefixlist ORF capability to this neighbor\n"
3757 "Capability to SEND and RECEIVE the ORF to/from this neighbor\n"
3758 "Capability to RECEIVE the ORF from this neighbor\n"
3759 "Capability to SEND the ORF to this neighbor\n")
3760 {
3761 int idx_peer = 2;
3762 int idx_send_recv = 6;
3763 uint16_t flag = 0;
3764
3765 if (strmatch(argv[idx_send_recv]->text, "send"))
3766 flag = PEER_FLAG_ORF_PREFIX_SM;
3767 else if (strmatch(argv[idx_send_recv]->text, "receive"))
3768 flag = PEER_FLAG_ORF_PREFIX_RM;
3769 else if (strmatch(argv[idx_send_recv]->text, "both"))
3770 flag = PEER_FLAG_ORF_PREFIX_SM | PEER_FLAG_ORF_PREFIX_RM;
3771 else {
3772 vty_out(vty, "%% BGP invalid orf prefix-list option\n");
3773 return CMD_WARNING_CONFIG_FAILED;
3774 }
3775
3776 return peer_af_flag_unset_vty(vty, argv[idx_peer]->arg,
3777 bgp_node_afi(vty), bgp_node_safi(vty),
3778 flag);
3779 }
3780
3781 ALIAS_HIDDEN(
3782 no_neighbor_capability_orf_prefix,
3783 no_neighbor_capability_orf_prefix_hidden_cmd,
3784 "no neighbor <A.B.C.D|X:X::X:X|WORD> capability orf prefix-list <both|send|receive>",
3785 NO_STR NEIGHBOR_STR NEIGHBOR_ADDR_STR2
3786 "Advertise capability to the peer\n"
3787 "Advertise ORF capability to the peer\n"
3788 "Advertise prefixlist ORF capability to this neighbor\n"
3789 "Capability to SEND and RECEIVE the ORF to/from this neighbor\n"
3790 "Capability to RECEIVE the ORF from this neighbor\n"
3791 "Capability to SEND the ORF to this neighbor\n")
3792
3793 /* neighbor next-hop-self. */
3794 DEFUN (neighbor_nexthop_self,
3795 neighbor_nexthop_self_cmd,
3796 "neighbor <A.B.C.D|X:X::X:X|WORD> next-hop-self",
3797 NEIGHBOR_STR
3798 NEIGHBOR_ADDR_STR2
3799 "Disable the next hop calculation for this neighbor\n")
3800 {
3801 int idx_peer = 1;
3802 return peer_af_flag_set_vty(vty, argv[idx_peer]->arg, bgp_node_afi(vty),
3803 bgp_node_safi(vty), PEER_FLAG_NEXTHOP_SELF);
3804 }
3805
3806 ALIAS_HIDDEN(neighbor_nexthop_self, neighbor_nexthop_self_hidden_cmd,
3807 "neighbor <A.B.C.D|X:X::X:X|WORD> next-hop-self",
3808 NEIGHBOR_STR NEIGHBOR_ADDR_STR2
3809 "Disable the next hop calculation for this neighbor\n")
3810
3811 /* neighbor next-hop-self. */
3812 DEFUN (neighbor_nexthop_self_force,
3813 neighbor_nexthop_self_force_cmd,
3814 "neighbor <A.B.C.D|X:X::X:X|WORD> next-hop-self force",
3815 NEIGHBOR_STR
3816 NEIGHBOR_ADDR_STR2
3817 "Disable the next hop calculation for this neighbor\n"
3818 "Set the next hop to self for reflected routes\n")
3819 {
3820 int idx_peer = 1;
3821 return peer_af_flag_set_vty(vty, argv[idx_peer]->arg, bgp_node_afi(vty),
3822 bgp_node_safi(vty),
3823 PEER_FLAG_FORCE_NEXTHOP_SELF);
3824 }
3825
3826 ALIAS_HIDDEN(neighbor_nexthop_self_force,
3827 neighbor_nexthop_self_force_hidden_cmd,
3828 "neighbor <A.B.C.D|X:X::X:X|WORD> next-hop-self force",
3829 NEIGHBOR_STR NEIGHBOR_ADDR_STR2
3830 "Disable the next hop calculation for this neighbor\n"
3831 "Set the next hop to self for reflected routes\n")
3832
3833 DEFUN (no_neighbor_nexthop_self,
3834 no_neighbor_nexthop_self_cmd,
3835 "no neighbor <A.B.C.D|X:X::X:X|WORD> next-hop-self",
3836 NO_STR
3837 NEIGHBOR_STR
3838 NEIGHBOR_ADDR_STR2
3839 "Disable the next hop calculation for this neighbor\n")
3840 {
3841 int idx_peer = 2;
3842 return peer_af_flag_unset_vty(vty, argv[idx_peer]->arg,
3843 bgp_node_afi(vty), bgp_node_safi(vty),
3844 PEER_FLAG_NEXTHOP_SELF);
3845 }
3846
3847 ALIAS_HIDDEN(no_neighbor_nexthop_self, no_neighbor_nexthop_self_hidden_cmd,
3848 "no neighbor <A.B.C.D|X:X::X:X|WORD> next-hop-self",
3849 NO_STR NEIGHBOR_STR NEIGHBOR_ADDR_STR2
3850 "Disable the next hop calculation for this neighbor\n")
3851
3852 DEFUN (no_neighbor_nexthop_self_force,
3853 no_neighbor_nexthop_self_force_cmd,
3854 "no neighbor <A.B.C.D|X:X::X:X|WORD> next-hop-self force",
3855 NO_STR
3856 NEIGHBOR_STR
3857 NEIGHBOR_ADDR_STR2
3858 "Disable the next hop calculation for this neighbor\n"
3859 "Set the next hop to self for reflected routes\n")
3860 {
3861 int idx_peer = 2;
3862 return peer_af_flag_unset_vty(vty, argv[idx_peer]->arg,
3863 bgp_node_afi(vty), bgp_node_safi(vty),
3864 PEER_FLAG_FORCE_NEXTHOP_SELF);
3865 }
3866
3867 ALIAS_HIDDEN(no_neighbor_nexthop_self_force,
3868 no_neighbor_nexthop_self_force_hidden_cmd,
3869 "no neighbor <A.B.C.D|X:X::X:X|WORD> next-hop-self force",
3870 NO_STR NEIGHBOR_STR NEIGHBOR_ADDR_STR2
3871 "Disable the next hop calculation for this neighbor\n"
3872 "Set the next hop to self for reflected routes\n")
3873
3874 /* neighbor as-override */
3875 DEFUN (neighbor_as_override,
3876 neighbor_as_override_cmd,
3877 "neighbor <A.B.C.D|X:X::X:X|WORD> as-override",
3878 NEIGHBOR_STR
3879 NEIGHBOR_ADDR_STR2
3880 "Override ASNs in outbound updates if aspath equals remote-as\n")
3881 {
3882 int idx_peer = 1;
3883 return peer_af_flag_set_vty(vty, argv[idx_peer]->arg, bgp_node_afi(vty),
3884 bgp_node_safi(vty), PEER_FLAG_AS_OVERRIDE);
3885 }
3886
3887 ALIAS_HIDDEN(neighbor_as_override, neighbor_as_override_hidden_cmd,
3888 "neighbor <A.B.C.D|X:X::X:X|WORD> as-override",
3889 NEIGHBOR_STR NEIGHBOR_ADDR_STR2
3890 "Override ASNs in outbound updates if aspath equals remote-as\n")
3891
3892 DEFUN (no_neighbor_as_override,
3893 no_neighbor_as_override_cmd,
3894 "no neighbor <A.B.C.D|X:X::X:X|WORD> as-override",
3895 NO_STR
3896 NEIGHBOR_STR
3897 NEIGHBOR_ADDR_STR2
3898 "Override ASNs in outbound updates if aspath equals remote-as\n")
3899 {
3900 int idx_peer = 2;
3901 return peer_af_flag_unset_vty(vty, argv[idx_peer]->arg,
3902 bgp_node_afi(vty), bgp_node_safi(vty),
3903 PEER_FLAG_AS_OVERRIDE);
3904 }
3905
3906 ALIAS_HIDDEN(no_neighbor_as_override, no_neighbor_as_override_hidden_cmd,
3907 "no neighbor <A.B.C.D|X:X::X:X|WORD> as-override",
3908 NO_STR NEIGHBOR_STR NEIGHBOR_ADDR_STR2
3909 "Override ASNs in outbound updates if aspath equals remote-as\n")
3910
3911 /* neighbor remove-private-AS. */
3912 DEFUN (neighbor_remove_private_as,
3913 neighbor_remove_private_as_cmd,
3914 "neighbor <A.B.C.D|X:X::X:X|WORD> remove-private-AS",
3915 NEIGHBOR_STR
3916 NEIGHBOR_ADDR_STR2
3917 "Remove private ASNs in outbound updates\n")
3918 {
3919 int idx_peer = 1;
3920 return peer_af_flag_set_vty(vty, argv[idx_peer]->arg, bgp_node_afi(vty),
3921 bgp_node_safi(vty),
3922 PEER_FLAG_REMOVE_PRIVATE_AS);
3923 }
3924
3925 ALIAS_HIDDEN(neighbor_remove_private_as, neighbor_remove_private_as_hidden_cmd,
3926 "neighbor <A.B.C.D|X:X::X:X|WORD> remove-private-AS",
3927 NEIGHBOR_STR NEIGHBOR_ADDR_STR2
3928 "Remove private ASNs in outbound updates\n")
3929
3930 DEFUN (neighbor_remove_private_as_all,
3931 neighbor_remove_private_as_all_cmd,
3932 "neighbor <A.B.C.D|X:X::X:X|WORD> remove-private-AS all",
3933 NEIGHBOR_STR
3934 NEIGHBOR_ADDR_STR2
3935 "Remove private ASNs in outbound updates\n"
3936 "Apply to all AS numbers\n")
3937 {
3938 int idx_peer = 1;
3939 return peer_af_flag_set_vty(vty, argv[idx_peer]->arg, bgp_node_afi(vty),
3940 bgp_node_safi(vty),
3941 PEER_FLAG_REMOVE_PRIVATE_AS_ALL);
3942 }
3943
3944 ALIAS_HIDDEN(neighbor_remove_private_as_all,
3945 neighbor_remove_private_as_all_hidden_cmd,
3946 "neighbor <A.B.C.D|X:X::X:X|WORD> remove-private-AS all",
3947 NEIGHBOR_STR NEIGHBOR_ADDR_STR2
3948 "Remove private ASNs in outbound updates\n"
3949 "Apply to all AS numbers")
3950
3951 DEFUN (neighbor_remove_private_as_replace_as,
3952 neighbor_remove_private_as_replace_as_cmd,
3953 "neighbor <A.B.C.D|X:X::X:X|WORD> remove-private-AS replace-AS",
3954 NEIGHBOR_STR
3955 NEIGHBOR_ADDR_STR2
3956 "Remove private ASNs in outbound updates\n"
3957 "Replace private ASNs with our ASN in outbound updates\n")
3958 {
3959 int idx_peer = 1;
3960 return peer_af_flag_set_vty(vty, argv[idx_peer]->arg, bgp_node_afi(vty),
3961 bgp_node_safi(vty),
3962 PEER_FLAG_REMOVE_PRIVATE_AS_REPLACE);
3963 }
3964
3965 ALIAS_HIDDEN(neighbor_remove_private_as_replace_as,
3966 neighbor_remove_private_as_replace_as_hidden_cmd,
3967 "neighbor <A.B.C.D|X:X::X:X|WORD> remove-private-AS replace-AS",
3968 NEIGHBOR_STR NEIGHBOR_ADDR_STR2
3969 "Remove private ASNs in outbound updates\n"
3970 "Replace private ASNs with our ASN in outbound updates\n")
3971
3972 DEFUN (neighbor_remove_private_as_all_replace_as,
3973 neighbor_remove_private_as_all_replace_as_cmd,
3974 "neighbor <A.B.C.D|X:X::X:X|WORD> remove-private-AS all replace-AS",
3975 NEIGHBOR_STR
3976 NEIGHBOR_ADDR_STR2
3977 "Remove private ASNs in outbound updates\n"
3978 "Apply to all AS numbers\n"
3979 "Replace private ASNs with our ASN in outbound updates\n")
3980 {
3981 int idx_peer = 1;
3982 return peer_af_flag_set_vty(vty, argv[idx_peer]->arg, bgp_node_afi(vty),
3983 bgp_node_safi(vty),
3984 PEER_FLAG_REMOVE_PRIVATE_AS_ALL_REPLACE);
3985 }
3986
3987 ALIAS_HIDDEN(
3988 neighbor_remove_private_as_all_replace_as,
3989 neighbor_remove_private_as_all_replace_as_hidden_cmd,
3990 "neighbor <A.B.C.D|X:X::X:X|WORD> remove-private-AS all replace-AS",
3991 NEIGHBOR_STR NEIGHBOR_ADDR_STR2
3992 "Remove private ASNs in outbound updates\n"
3993 "Apply to all AS numbers\n"
3994 "Replace private ASNs with our ASN in outbound updates\n")
3995
3996 DEFUN (no_neighbor_remove_private_as,
3997 no_neighbor_remove_private_as_cmd,
3998 "no neighbor <A.B.C.D|X:X::X:X|WORD> remove-private-AS",
3999 NO_STR
4000 NEIGHBOR_STR
4001 NEIGHBOR_ADDR_STR2
4002 "Remove private ASNs in outbound updates\n")
4003 {
4004 int idx_peer = 2;
4005 return peer_af_flag_unset_vty(vty, argv[idx_peer]->arg,
4006 bgp_node_afi(vty), bgp_node_safi(vty),
4007 PEER_FLAG_REMOVE_PRIVATE_AS);
4008 }
4009
4010 ALIAS_HIDDEN(no_neighbor_remove_private_as,
4011 no_neighbor_remove_private_as_hidden_cmd,
4012 "no neighbor <A.B.C.D|X:X::X:X|WORD> remove-private-AS",
4013 NO_STR NEIGHBOR_STR NEIGHBOR_ADDR_STR2
4014 "Remove private ASNs in outbound updates\n")
4015
4016 DEFUN (no_neighbor_remove_private_as_all,
4017 no_neighbor_remove_private_as_all_cmd,
4018 "no neighbor <A.B.C.D|X:X::X:X|WORD> remove-private-AS all",
4019 NO_STR
4020 NEIGHBOR_STR
4021 NEIGHBOR_ADDR_STR2
4022 "Remove private ASNs in outbound updates\n"
4023 "Apply to all AS numbers\n")
4024 {
4025 int idx_peer = 2;
4026 return peer_af_flag_unset_vty(vty, argv[idx_peer]->arg,
4027 bgp_node_afi(vty), bgp_node_safi(vty),
4028 PEER_FLAG_REMOVE_PRIVATE_AS_ALL);
4029 }
4030
4031 ALIAS_HIDDEN(no_neighbor_remove_private_as_all,
4032 no_neighbor_remove_private_as_all_hidden_cmd,
4033 "no neighbor <A.B.C.D|X:X::X:X|WORD> remove-private-AS all",
4034 NO_STR NEIGHBOR_STR NEIGHBOR_ADDR_STR2
4035 "Remove private ASNs in outbound updates\n"
4036 "Apply to all AS numbers\n")
4037
4038 DEFUN (no_neighbor_remove_private_as_replace_as,
4039 no_neighbor_remove_private_as_replace_as_cmd,
4040 "no neighbor <A.B.C.D|X:X::X:X|WORD> remove-private-AS replace-AS",
4041 NO_STR
4042 NEIGHBOR_STR
4043 NEIGHBOR_ADDR_STR2
4044 "Remove private ASNs in outbound updates\n"
4045 "Replace private ASNs with our ASN in outbound updates\n")
4046 {
4047 int idx_peer = 2;
4048 return peer_af_flag_unset_vty(vty, argv[idx_peer]->arg,
4049 bgp_node_afi(vty), bgp_node_safi(vty),
4050 PEER_FLAG_REMOVE_PRIVATE_AS_REPLACE);
4051 }
4052
4053 ALIAS_HIDDEN(no_neighbor_remove_private_as_replace_as,
4054 no_neighbor_remove_private_as_replace_as_hidden_cmd,
4055 "no neighbor <A.B.C.D|X:X::X:X|WORD> remove-private-AS replace-AS",
4056 NO_STR NEIGHBOR_STR NEIGHBOR_ADDR_STR2
4057 "Remove private ASNs in outbound updates\n"
4058 "Replace private ASNs with our ASN in outbound updates\n")
4059
4060 DEFUN (no_neighbor_remove_private_as_all_replace_as,
4061 no_neighbor_remove_private_as_all_replace_as_cmd,
4062 "no neighbor <A.B.C.D|X:X::X:X|WORD> remove-private-AS all replace-AS",
4063 NO_STR
4064 NEIGHBOR_STR
4065 NEIGHBOR_ADDR_STR2
4066 "Remove private ASNs in outbound updates\n"
4067 "Apply to all AS numbers\n"
4068 "Replace private ASNs with our ASN in outbound updates\n")
4069 {
4070 int idx_peer = 2;
4071 return peer_af_flag_unset_vty(vty, argv[idx_peer]->arg,
4072 bgp_node_afi(vty), bgp_node_safi(vty),
4073 PEER_FLAG_REMOVE_PRIVATE_AS_ALL_REPLACE);
4074 }
4075
4076 ALIAS_HIDDEN(
4077 no_neighbor_remove_private_as_all_replace_as,
4078 no_neighbor_remove_private_as_all_replace_as_hidden_cmd,
4079 "no neighbor <A.B.C.D|X:X::X:X|WORD> remove-private-AS all replace-AS",
4080 NO_STR NEIGHBOR_STR NEIGHBOR_ADDR_STR2
4081 "Remove private ASNs in outbound updates\n"
4082 "Apply to all AS numbers\n"
4083 "Replace private ASNs with our ASN in outbound updates\n")
4084
4085
4086 /* neighbor send-community. */
4087 DEFUN (neighbor_send_community,
4088 neighbor_send_community_cmd,
4089 "neighbor <A.B.C.D|X:X::X:X|WORD> send-community",
4090 NEIGHBOR_STR
4091 NEIGHBOR_ADDR_STR2
4092 "Send Community attribute to this neighbor\n")
4093 {
4094 int idx_peer = 1;
4095
4096 return peer_af_flag_set_vty(vty, argv[idx_peer]->arg, bgp_node_afi(vty),
4097 bgp_node_safi(vty),
4098 PEER_FLAG_SEND_COMMUNITY);
4099 }
4100
4101 ALIAS_HIDDEN(neighbor_send_community, neighbor_send_community_hidden_cmd,
4102 "neighbor <A.B.C.D|X:X::X:X|WORD> send-community",
4103 NEIGHBOR_STR NEIGHBOR_ADDR_STR2
4104 "Send Community attribute to this neighbor\n")
4105
4106 DEFUN (no_neighbor_send_community,
4107 no_neighbor_send_community_cmd,
4108 "no neighbor <A.B.C.D|X:X::X:X|WORD> send-community",
4109 NO_STR
4110 NEIGHBOR_STR
4111 NEIGHBOR_ADDR_STR2
4112 "Send Community attribute to this neighbor\n")
4113 {
4114 int idx_peer = 2;
4115
4116 return peer_af_flag_unset_vty(vty, argv[idx_peer]->arg,
4117 bgp_node_afi(vty), bgp_node_safi(vty),
4118 PEER_FLAG_SEND_COMMUNITY);
4119 }
4120
4121 ALIAS_HIDDEN(no_neighbor_send_community, no_neighbor_send_community_hidden_cmd,
4122 "no neighbor <A.B.C.D|X:X::X:X|WORD> send-community",
4123 NO_STR NEIGHBOR_STR NEIGHBOR_ADDR_STR2
4124 "Send Community attribute to this neighbor\n")
4125
4126 /* neighbor send-community extended. */
4127 DEFUN (neighbor_send_community_type,
4128 neighbor_send_community_type_cmd,
4129 "neighbor <A.B.C.D|X:X::X:X|WORD> send-community <both|all|extended|standard|large>",
4130 NEIGHBOR_STR
4131 NEIGHBOR_ADDR_STR2
4132 "Send Community attribute to this neighbor\n"
4133 "Send Standard and Extended Community attributes\n"
4134 "Send Standard, Large and Extended Community attributes\n"
4135 "Send Extended Community attributes\n"
4136 "Send Standard Community attributes\n"
4137 "Send Large Community attributes\n")
4138 {
4139 int idx_peer = 1;
4140 uint32_t flag = 0;
4141 const char *type = argv[argc - 1]->text;
4142
4143 if (strmatch(type, "standard")) {
4144 SET_FLAG(flag, PEER_FLAG_SEND_COMMUNITY);
4145 } else if (strmatch(type, "extended")) {
4146 SET_FLAG(flag, PEER_FLAG_SEND_EXT_COMMUNITY);
4147 } else if (strmatch(type, "large")) {
4148 SET_FLAG(flag, PEER_FLAG_SEND_LARGE_COMMUNITY);
4149 } else if (strmatch(type, "both")) {
4150 SET_FLAG(flag, PEER_FLAG_SEND_COMMUNITY);
4151 SET_FLAG(flag, PEER_FLAG_SEND_EXT_COMMUNITY);
4152 } else { /* if (strmatch(type, "all")) */
4153 SET_FLAG(flag, PEER_FLAG_SEND_COMMUNITY);
4154 SET_FLAG(flag, PEER_FLAG_SEND_EXT_COMMUNITY);
4155 SET_FLAG(flag, PEER_FLAG_SEND_LARGE_COMMUNITY);
4156 }
4157
4158 return peer_af_flag_set_vty(vty, argv[idx_peer]->arg, bgp_node_afi(vty),
4159 bgp_node_safi(vty), flag);
4160 }
4161
4162 ALIAS_HIDDEN(
4163 neighbor_send_community_type, neighbor_send_community_type_hidden_cmd,
4164 "neighbor <A.B.C.D|X:X::X:X|WORD> send-community <both|all|extended|standard|large>",
4165 NEIGHBOR_STR NEIGHBOR_ADDR_STR2
4166 "Send Community attribute to this neighbor\n"
4167 "Send Standard and Extended Community attributes\n"
4168 "Send Standard, Large and Extended Community attributes\n"
4169 "Send Extended Community attributes\n"
4170 "Send Standard Community attributes\n"
4171 "Send Large Community attributes\n")
4172
4173 DEFUN (no_neighbor_send_community_type,
4174 no_neighbor_send_community_type_cmd,
4175 "no neighbor <A.B.C.D|X:X::X:X|WORD> send-community <both|all|extended|standard|large>",
4176 NO_STR
4177 NEIGHBOR_STR
4178 NEIGHBOR_ADDR_STR2
4179 "Send Community attribute to this neighbor\n"
4180 "Send Standard and Extended Community attributes\n"
4181 "Send Standard, Large and Extended Community attributes\n"
4182 "Send Extended Community attributes\n"
4183 "Send Standard Community attributes\n"
4184 "Send Large Community attributes\n")
4185 {
4186 int idx_peer = 2;
4187 uint32_t flag = 0;
4188 const char *type = argv[argc - 1]->text;
4189
4190 if (strmatch(type, "standard")) {
4191 SET_FLAG(flag, PEER_FLAG_SEND_COMMUNITY);
4192 } else if (strmatch(type, "extended")) {
4193 SET_FLAG(flag, PEER_FLAG_SEND_EXT_COMMUNITY);
4194 } else if (strmatch(type, "large")) {
4195 SET_FLAG(flag, PEER_FLAG_SEND_LARGE_COMMUNITY);
4196 } else if (strmatch(type, "both")) {
4197 SET_FLAG(flag, PEER_FLAG_SEND_COMMUNITY);
4198 SET_FLAG(flag, PEER_FLAG_SEND_EXT_COMMUNITY);
4199 } else { /* if (strmatch(type, "all")) */
4200 SET_FLAG(flag, PEER_FLAG_SEND_COMMUNITY);
4201 SET_FLAG(flag, PEER_FLAG_SEND_EXT_COMMUNITY);
4202 SET_FLAG(flag, PEER_FLAG_SEND_LARGE_COMMUNITY);
4203 }
4204
4205 return peer_af_flag_unset_vty(vty, argv[idx_peer]->arg,
4206 bgp_node_afi(vty), bgp_node_safi(vty),
4207 flag);
4208 }
4209
4210 ALIAS_HIDDEN(
4211 no_neighbor_send_community_type,
4212 no_neighbor_send_community_type_hidden_cmd,
4213 "no neighbor <A.B.C.D|X:X::X:X|WORD> send-community <both|all|extended|standard|large>",
4214 NO_STR NEIGHBOR_STR NEIGHBOR_ADDR_STR2
4215 "Send Community attribute to this neighbor\n"
4216 "Send Standard and Extended Community attributes\n"
4217 "Send Standard, Large and Extended Community attributes\n"
4218 "Send Extended Community attributes\n"
4219 "Send Standard Community attributes\n"
4220 "Send Large Community attributes\n")
4221
4222 /* neighbor soft-reconfig. */
4223 DEFUN (neighbor_soft_reconfiguration,
4224 neighbor_soft_reconfiguration_cmd,
4225 "neighbor <A.B.C.D|X:X::X:X|WORD> soft-reconfiguration inbound",
4226 NEIGHBOR_STR
4227 NEIGHBOR_ADDR_STR2
4228 "Per neighbor soft reconfiguration\n"
4229 "Allow inbound soft reconfiguration for this neighbor\n")
4230 {
4231 int idx_peer = 1;
4232 return peer_af_flag_set_vty(vty, argv[idx_peer]->arg, bgp_node_afi(vty),
4233 bgp_node_safi(vty),
4234 PEER_FLAG_SOFT_RECONFIG);
4235 }
4236
4237 ALIAS_HIDDEN(neighbor_soft_reconfiguration,
4238 neighbor_soft_reconfiguration_hidden_cmd,
4239 "neighbor <A.B.C.D|X:X::X:X|WORD> soft-reconfiguration inbound",
4240 NEIGHBOR_STR NEIGHBOR_ADDR_STR2
4241 "Per neighbor soft reconfiguration\n"
4242 "Allow inbound soft reconfiguration for this neighbor\n")
4243
4244 DEFUN (no_neighbor_soft_reconfiguration,
4245 no_neighbor_soft_reconfiguration_cmd,
4246 "no neighbor <A.B.C.D|X:X::X:X|WORD> soft-reconfiguration inbound",
4247 NO_STR
4248 NEIGHBOR_STR
4249 NEIGHBOR_ADDR_STR2
4250 "Per neighbor soft reconfiguration\n"
4251 "Allow inbound soft reconfiguration for this neighbor\n")
4252 {
4253 int idx_peer = 2;
4254 return peer_af_flag_unset_vty(vty, argv[idx_peer]->arg,
4255 bgp_node_afi(vty), bgp_node_safi(vty),
4256 PEER_FLAG_SOFT_RECONFIG);
4257 }
4258
4259 ALIAS_HIDDEN(no_neighbor_soft_reconfiguration,
4260 no_neighbor_soft_reconfiguration_hidden_cmd,
4261 "no neighbor <A.B.C.D|X:X::X:X|WORD> soft-reconfiguration inbound",
4262 NO_STR NEIGHBOR_STR NEIGHBOR_ADDR_STR2
4263 "Per neighbor soft reconfiguration\n"
4264 "Allow inbound soft reconfiguration for this neighbor\n")
4265
4266 DEFUN (neighbor_route_reflector_client,
4267 neighbor_route_reflector_client_cmd,
4268 "neighbor <A.B.C.D|X:X::X:X|WORD> route-reflector-client",
4269 NEIGHBOR_STR
4270 NEIGHBOR_ADDR_STR2
4271 "Configure a neighbor as Route Reflector client\n")
4272 {
4273 int idx_peer = 1;
4274 struct peer *peer;
4275
4276
4277 peer = peer_and_group_lookup_vty(vty, argv[idx_peer]->arg);
4278 if (!peer)
4279 return CMD_WARNING_CONFIG_FAILED;
4280
4281 return peer_af_flag_set_vty(vty, argv[idx_peer]->arg, bgp_node_afi(vty),
4282 bgp_node_safi(vty),
4283 PEER_FLAG_REFLECTOR_CLIENT);
4284 }
4285
4286 ALIAS_HIDDEN(neighbor_route_reflector_client,
4287 neighbor_route_reflector_client_hidden_cmd,
4288 "neighbor <A.B.C.D|X:X::X:X|WORD> route-reflector-client",
4289 NEIGHBOR_STR NEIGHBOR_ADDR_STR2
4290 "Configure a neighbor as Route Reflector client\n")
4291
4292 DEFUN (no_neighbor_route_reflector_client,
4293 no_neighbor_route_reflector_client_cmd,
4294 "no neighbor <A.B.C.D|X:X::X:X|WORD> route-reflector-client",
4295 NO_STR
4296 NEIGHBOR_STR
4297 NEIGHBOR_ADDR_STR2
4298 "Configure a neighbor as Route Reflector client\n")
4299 {
4300 int idx_peer = 2;
4301 return peer_af_flag_unset_vty(vty, argv[idx_peer]->arg,
4302 bgp_node_afi(vty), bgp_node_safi(vty),
4303 PEER_FLAG_REFLECTOR_CLIENT);
4304 }
4305
4306 ALIAS_HIDDEN(no_neighbor_route_reflector_client,
4307 no_neighbor_route_reflector_client_hidden_cmd,
4308 "no neighbor <A.B.C.D|X:X::X:X|WORD> route-reflector-client",
4309 NO_STR NEIGHBOR_STR NEIGHBOR_ADDR_STR2
4310 "Configure a neighbor as Route Reflector client\n")
4311
4312 /* neighbor route-server-client. */
4313 DEFUN (neighbor_route_server_client,
4314 neighbor_route_server_client_cmd,
4315 "neighbor <A.B.C.D|X:X::X:X|WORD> route-server-client",
4316 NEIGHBOR_STR
4317 NEIGHBOR_ADDR_STR2
4318 "Configure a neighbor as Route Server client\n")
4319 {
4320 int idx_peer = 1;
4321 struct peer *peer;
4322
4323 peer = peer_and_group_lookup_vty(vty, argv[idx_peer]->arg);
4324 if (!peer)
4325 return CMD_WARNING_CONFIG_FAILED;
4326 return peer_af_flag_set_vty(vty, argv[idx_peer]->arg, bgp_node_afi(vty),
4327 bgp_node_safi(vty),
4328 PEER_FLAG_RSERVER_CLIENT);
4329 }
4330
4331 ALIAS_HIDDEN(neighbor_route_server_client,
4332 neighbor_route_server_client_hidden_cmd,
4333 "neighbor <A.B.C.D|X:X::X:X|WORD> route-server-client",
4334 NEIGHBOR_STR NEIGHBOR_ADDR_STR2
4335 "Configure a neighbor as Route Server client\n")
4336
4337 DEFUN (no_neighbor_route_server_client,
4338 no_neighbor_route_server_client_cmd,
4339 "no neighbor <A.B.C.D|X:X::X:X|WORD> route-server-client",
4340 NO_STR
4341 NEIGHBOR_STR
4342 NEIGHBOR_ADDR_STR2
4343 "Configure a neighbor as Route Server client\n")
4344 {
4345 int idx_peer = 2;
4346 return peer_af_flag_unset_vty(vty, argv[idx_peer]->arg,
4347 bgp_node_afi(vty), bgp_node_safi(vty),
4348 PEER_FLAG_RSERVER_CLIENT);
4349 }
4350
4351 ALIAS_HIDDEN(no_neighbor_route_server_client,
4352 no_neighbor_route_server_client_hidden_cmd,
4353 "no neighbor <A.B.C.D|X:X::X:X|WORD> route-server-client",
4354 NO_STR NEIGHBOR_STR NEIGHBOR_ADDR_STR2
4355 "Configure a neighbor as Route Server client\n")
4356
4357 DEFUN (neighbor_nexthop_local_unchanged,
4358 neighbor_nexthop_local_unchanged_cmd,
4359 "neighbor <A.B.C.D|X:X::X:X|WORD> nexthop-local unchanged",
4360 NEIGHBOR_STR
4361 NEIGHBOR_ADDR_STR2
4362 "Configure treatment of outgoing link-local nexthop attribute\n"
4363 "Leave link-local nexthop unchanged for this peer\n")
4364 {
4365 int idx_peer = 1;
4366 return peer_af_flag_set_vty(vty, argv[idx_peer]->arg, bgp_node_afi(vty),
4367 bgp_node_safi(vty),
4368 PEER_FLAG_NEXTHOP_LOCAL_UNCHANGED);
4369 }
4370
4371 DEFUN (no_neighbor_nexthop_local_unchanged,
4372 no_neighbor_nexthop_local_unchanged_cmd,
4373 "no neighbor <A.B.C.D|X:X::X:X|WORD> nexthop-local unchanged",
4374 NO_STR
4375 NEIGHBOR_STR
4376 NEIGHBOR_ADDR_STR2
4377 "Configure treatment of outgoing link-local-nexthop attribute\n"
4378 "Leave link-local nexthop unchanged for this peer\n")
4379 {
4380 int idx_peer = 2;
4381 return peer_af_flag_unset_vty(vty, argv[idx_peer]->arg,
4382 bgp_node_afi(vty), bgp_node_safi(vty),
4383 PEER_FLAG_NEXTHOP_LOCAL_UNCHANGED);
4384 }
4385
4386 DEFUN (neighbor_attr_unchanged,
4387 neighbor_attr_unchanged_cmd,
4388 "neighbor <A.B.C.D|X:X::X:X|WORD> attribute-unchanged [{as-path|next-hop|med}]",
4389 NEIGHBOR_STR
4390 NEIGHBOR_ADDR_STR2
4391 "BGP attribute is propagated unchanged to this neighbor\n"
4392 "As-path attribute\n"
4393 "Nexthop attribute\n"
4394 "Med attribute\n")
4395 {
4396 int idx = 0;
4397 char *peer_str = argv[1]->arg;
4398 struct peer *peer;
4399 uint16_t flags = 0;
4400 afi_t afi = bgp_node_afi(vty);
4401 safi_t safi = bgp_node_safi(vty);
4402
4403 peer = peer_and_group_lookup_vty(vty, peer_str);
4404 if (!peer)
4405 return CMD_WARNING_CONFIG_FAILED;
4406
4407 if (argv_find(argv, argc, "as-path", &idx))
4408 SET_FLAG(flags, PEER_FLAG_AS_PATH_UNCHANGED);
4409 idx = 0;
4410 if (argv_find(argv, argc, "next-hop", &idx))
4411 SET_FLAG(flags, PEER_FLAG_NEXTHOP_UNCHANGED);
4412 idx = 0;
4413 if (argv_find(argv, argc, "med", &idx))
4414 SET_FLAG(flags, PEER_FLAG_MED_UNCHANGED);
4415
4416 /* no flags means all of them! */
4417 if (!flags) {
4418 SET_FLAG(flags, PEER_FLAG_AS_PATH_UNCHANGED);
4419 SET_FLAG(flags, PEER_FLAG_NEXTHOP_UNCHANGED);
4420 SET_FLAG(flags, PEER_FLAG_MED_UNCHANGED);
4421 } else {
4422 if (!CHECK_FLAG(flags, PEER_FLAG_AS_PATH_UNCHANGED)
4423 && peer_af_flag_check(peer, afi, safi,
4424 PEER_FLAG_AS_PATH_UNCHANGED)) {
4425 peer_af_flag_unset_vty(vty, peer_str, afi, safi,
4426 PEER_FLAG_AS_PATH_UNCHANGED);
4427 }
4428
4429 if (!CHECK_FLAG(flags, PEER_FLAG_NEXTHOP_UNCHANGED)
4430 && peer_af_flag_check(peer, afi, safi,
4431 PEER_FLAG_NEXTHOP_UNCHANGED)) {
4432 peer_af_flag_unset_vty(vty, peer_str, afi, safi,
4433 PEER_FLAG_NEXTHOP_UNCHANGED);
4434 }
4435
4436 if (!CHECK_FLAG(flags, PEER_FLAG_MED_UNCHANGED)
4437 && peer_af_flag_check(peer, afi, safi,
4438 PEER_FLAG_MED_UNCHANGED)) {
4439 peer_af_flag_unset_vty(vty, peer_str, afi, safi,
4440 PEER_FLAG_MED_UNCHANGED);
4441 }
4442 }
4443
4444 return peer_af_flag_set_vty(vty, peer_str, afi, safi, flags);
4445 }
4446
4447 ALIAS_HIDDEN(
4448 neighbor_attr_unchanged, neighbor_attr_unchanged_hidden_cmd,
4449 "neighbor <A.B.C.D|X:X::X:X|WORD> attribute-unchanged [{as-path|next-hop|med}]",
4450 NEIGHBOR_STR NEIGHBOR_ADDR_STR2
4451 "BGP attribute is propagated unchanged to this neighbor\n"
4452 "As-path attribute\n"
4453 "Nexthop attribute\n"
4454 "Med attribute\n")
4455
4456 DEFUN (no_neighbor_attr_unchanged,
4457 no_neighbor_attr_unchanged_cmd,
4458 "no neighbor <A.B.C.D|X:X::X:X|WORD> attribute-unchanged [{as-path|next-hop|med}]",
4459 NO_STR
4460 NEIGHBOR_STR
4461 NEIGHBOR_ADDR_STR2
4462 "BGP attribute is propagated unchanged to this neighbor\n"
4463 "As-path attribute\n"
4464 "Nexthop attribute\n"
4465 "Med attribute\n")
4466 {
4467 int idx = 0;
4468 char *peer = argv[2]->arg;
4469 uint16_t flags = 0;
4470
4471 if (argv_find(argv, argc, "as-path", &idx))
4472 SET_FLAG(flags, PEER_FLAG_AS_PATH_UNCHANGED);
4473 idx = 0;
4474 if (argv_find(argv, argc, "next-hop", &idx))
4475 SET_FLAG(flags, PEER_FLAG_NEXTHOP_UNCHANGED);
4476 idx = 0;
4477 if (argv_find(argv, argc, "med", &idx))
4478 SET_FLAG(flags, PEER_FLAG_MED_UNCHANGED);
4479
4480 if (!flags) // no flags means all of them!
4481 {
4482 SET_FLAG(flags, PEER_FLAG_AS_PATH_UNCHANGED);
4483 SET_FLAG(flags, PEER_FLAG_NEXTHOP_UNCHANGED);
4484 SET_FLAG(flags, PEER_FLAG_MED_UNCHANGED);
4485 }
4486
4487 return peer_af_flag_unset_vty(vty, peer, bgp_node_afi(vty),
4488 bgp_node_safi(vty), flags);
4489 }
4490
4491 ALIAS_HIDDEN(
4492 no_neighbor_attr_unchanged, no_neighbor_attr_unchanged_hidden_cmd,
4493 "no neighbor <A.B.C.D|X:X::X:X|WORD> attribute-unchanged [{as-path|next-hop|med}]",
4494 NO_STR NEIGHBOR_STR NEIGHBOR_ADDR_STR2
4495 "BGP attribute is propagated unchanged to this neighbor\n"
4496 "As-path attribute\n"
4497 "Nexthop attribute\n"
4498 "Med attribute\n")
4499
4500 /* EBGP multihop configuration. */
4501 static int peer_ebgp_multihop_set_vty(struct vty *vty, const char *ip_str,
4502 const char *ttl_str)
4503 {
4504 struct peer *peer;
4505 unsigned int ttl;
4506
4507 peer = peer_and_group_lookup_vty(vty, ip_str);
4508 if (!peer)
4509 return CMD_WARNING_CONFIG_FAILED;
4510
4511 if (peer->conf_if)
4512 return bgp_vty_return(vty, BGP_ERR_INVALID_FOR_DIRECT_PEER);
4513
4514 if (!ttl_str)
4515 ttl = MAXTTL;
4516 else
4517 ttl = strtoul(ttl_str, NULL, 10);
4518
4519 return bgp_vty_return(vty, peer_ebgp_multihop_set(peer, ttl));
4520 }
4521
4522 static int peer_ebgp_multihop_unset_vty(struct vty *vty, const char *ip_str)
4523 {
4524 struct peer *peer;
4525
4526 peer = peer_and_group_lookup_vty(vty, ip_str);
4527 if (!peer)
4528 return CMD_WARNING_CONFIG_FAILED;
4529
4530 return bgp_vty_return(vty, peer_ebgp_multihop_unset(peer));
4531 }
4532
4533 /* neighbor ebgp-multihop. */
4534 DEFUN (neighbor_ebgp_multihop,
4535 neighbor_ebgp_multihop_cmd,
4536 "neighbor <A.B.C.D|X:X::X:X|WORD> ebgp-multihop",
4537 NEIGHBOR_STR
4538 NEIGHBOR_ADDR_STR2
4539 "Allow EBGP neighbors not on directly connected networks\n")
4540 {
4541 int idx_peer = 1;
4542 return peer_ebgp_multihop_set_vty(vty, argv[idx_peer]->arg, NULL);
4543 }
4544
4545 DEFUN (neighbor_ebgp_multihop_ttl,
4546 neighbor_ebgp_multihop_ttl_cmd,
4547 "neighbor <A.B.C.D|X:X::X:X|WORD> ebgp-multihop (1-255)",
4548 NEIGHBOR_STR
4549 NEIGHBOR_ADDR_STR2
4550 "Allow EBGP neighbors not on directly connected networks\n"
4551 "maximum hop count\n")
4552 {
4553 int idx_peer = 1;
4554 int idx_number = 3;
4555 return peer_ebgp_multihop_set_vty(vty, argv[idx_peer]->arg,
4556 argv[idx_number]->arg);
4557 }
4558
4559 DEFUN (no_neighbor_ebgp_multihop,
4560 no_neighbor_ebgp_multihop_cmd,
4561 "no neighbor <A.B.C.D|X:X::X:X|WORD> ebgp-multihop [(1-255)]",
4562 NO_STR
4563 NEIGHBOR_STR
4564 NEIGHBOR_ADDR_STR2
4565 "Allow EBGP neighbors not on directly connected networks\n"
4566 "maximum hop count\n")
4567 {
4568 int idx_peer = 2;
4569 return peer_ebgp_multihop_unset_vty(vty, argv[idx_peer]->arg);
4570 }
4571
4572
4573 /* disable-connected-check */
4574 DEFUN (neighbor_disable_connected_check,
4575 neighbor_disable_connected_check_cmd,
4576 "neighbor <A.B.C.D|X:X::X:X|WORD> <disable-connected-check|enforce-multihop>",
4577 NEIGHBOR_STR
4578 NEIGHBOR_ADDR_STR2
4579 "one-hop away EBGP peer using loopback address\n"
4580 "Enforce EBGP neighbors perform multihop\n")
4581 {
4582 int idx_peer = 1;
4583 return peer_flag_set_vty(vty, argv[idx_peer]->arg,
4584 PEER_FLAG_DISABLE_CONNECTED_CHECK);
4585 }
4586
4587 DEFUN (no_neighbor_disable_connected_check,
4588 no_neighbor_disable_connected_check_cmd,
4589 "no neighbor <A.B.C.D|X:X::X:X|WORD> <disable-connected-check|enforce-multihop>",
4590 NO_STR
4591 NEIGHBOR_STR
4592 NEIGHBOR_ADDR_STR2
4593 "one-hop away EBGP peer using loopback address\n"
4594 "Enforce EBGP neighbors perform multihop\n")
4595 {
4596 int idx_peer = 2;
4597 return peer_flag_unset_vty(vty, argv[idx_peer]->arg,
4598 PEER_FLAG_DISABLE_CONNECTED_CHECK);
4599 }
4600
4601
4602 /* enforce-first-as */
4603 DEFUN (neighbor_enforce_first_as,
4604 neighbor_enforce_first_as_cmd,
4605 "neighbor <A.B.C.D|X:X::X:X|WORD> enforce-first-as",
4606 NEIGHBOR_STR
4607 NEIGHBOR_ADDR_STR2
4608 "Enforce the first AS for EBGP routes\n")
4609 {
4610 int idx_peer = 1;
4611
4612 return peer_flag_set_vty(vty, argv[idx_peer]->arg,
4613 PEER_FLAG_ENFORCE_FIRST_AS);
4614 }
4615
4616 DEFUN (no_neighbor_enforce_first_as,
4617 no_neighbor_enforce_first_as_cmd,
4618 "no neighbor <A.B.C.D|X:X::X:X|WORD> enforce-first-as",
4619 NO_STR
4620 NEIGHBOR_STR
4621 NEIGHBOR_ADDR_STR2
4622 "Enforce the first AS for EBGP routes\n")
4623 {
4624 int idx_peer = 2;
4625
4626 return peer_flag_unset_vty(vty, argv[idx_peer]->arg,
4627 PEER_FLAG_ENFORCE_FIRST_AS);
4628 }
4629
4630
4631 DEFUN (neighbor_description,
4632 neighbor_description_cmd,
4633 "neighbor <A.B.C.D|X:X::X:X|WORD> description LINE...",
4634 NEIGHBOR_STR
4635 NEIGHBOR_ADDR_STR2
4636 "Neighbor specific description\n"
4637 "Up to 80 characters describing this neighbor\n")
4638 {
4639 int idx_peer = 1;
4640 int idx_line = 3;
4641 struct peer *peer;
4642 char *str;
4643
4644 peer = peer_and_group_lookup_vty(vty, argv[idx_peer]->arg);
4645 if (!peer)
4646 return CMD_WARNING_CONFIG_FAILED;
4647
4648 str = argv_concat(argv, argc, idx_line);
4649
4650 peer_description_set(peer, str);
4651
4652 XFREE(MTYPE_TMP, str);
4653
4654 return CMD_SUCCESS;
4655 }
4656
4657 DEFUN (no_neighbor_description,
4658 no_neighbor_description_cmd,
4659 "no neighbor <A.B.C.D|X:X::X:X|WORD> description",
4660 NO_STR
4661 NEIGHBOR_STR
4662 NEIGHBOR_ADDR_STR2
4663 "Neighbor specific description\n")
4664 {
4665 int idx_peer = 2;
4666 struct peer *peer;
4667
4668 peer = peer_and_group_lookup_vty(vty, argv[idx_peer]->arg);
4669 if (!peer)
4670 return CMD_WARNING_CONFIG_FAILED;
4671
4672 peer_description_unset(peer);
4673
4674 return CMD_SUCCESS;
4675 }
4676
4677 ALIAS(no_neighbor_description, no_neighbor_description_comment_cmd,
4678 "no neighbor <A.B.C.D|X:X::X:X|WORD> description LINE...",
4679 NO_STR NEIGHBOR_STR NEIGHBOR_ADDR_STR2
4680 "Neighbor specific description\n"
4681 "Up to 80 characters describing this neighbor\n")
4682
4683 /* Neighbor update-source. */
4684 static int peer_update_source_vty(struct vty *vty, const char *peer_str,
4685 const char *source_str)
4686 {
4687 struct peer *peer;
4688 struct prefix p;
4689 union sockunion su;
4690
4691 peer = peer_and_group_lookup_vty(vty, peer_str);
4692 if (!peer)
4693 return CMD_WARNING_CONFIG_FAILED;
4694
4695 if (peer->conf_if)
4696 return CMD_WARNING;
4697
4698 if (source_str) {
4699 if (str2sockunion(source_str, &su) == 0)
4700 peer_update_source_addr_set(peer, &su);
4701 else {
4702 if (str2prefix(source_str, &p)) {
4703 vty_out(vty,
4704 "%% Invalid update-source, remove prefix length \n");
4705 return CMD_WARNING_CONFIG_FAILED;
4706 } else
4707 peer_update_source_if_set(peer, source_str);
4708 }
4709 } else
4710 peer_update_source_unset(peer);
4711
4712 return CMD_SUCCESS;
4713 }
4714
4715 #define BGP_UPDATE_SOURCE_HELP_STR \
4716 "IPv4 address\n" \
4717 "IPv6 address\n" \
4718 "Interface name (requires zebra to be running)\n"
4719
4720 DEFUN (neighbor_update_source,
4721 neighbor_update_source_cmd,
4722 "neighbor <A.B.C.D|X:X::X:X|WORD> update-source <A.B.C.D|X:X::X:X|WORD>",
4723 NEIGHBOR_STR
4724 NEIGHBOR_ADDR_STR2
4725 "Source of routing updates\n"
4726 BGP_UPDATE_SOURCE_HELP_STR)
4727 {
4728 int idx_peer = 1;
4729 int idx_peer_2 = 3;
4730 return peer_update_source_vty(vty, argv[idx_peer]->arg,
4731 argv[idx_peer_2]->arg);
4732 }
4733
4734 DEFUN (no_neighbor_update_source,
4735 no_neighbor_update_source_cmd,
4736 "no neighbor <A.B.C.D|X:X::X:X|WORD> update-source [<A.B.C.D|X:X::X:X|WORD>]",
4737 NO_STR
4738 NEIGHBOR_STR
4739 NEIGHBOR_ADDR_STR2
4740 "Source of routing updates\n"
4741 BGP_UPDATE_SOURCE_HELP_STR)
4742 {
4743 int idx_peer = 2;
4744 return peer_update_source_vty(vty, argv[idx_peer]->arg, NULL);
4745 }
4746
4747 static int peer_default_originate_set_vty(struct vty *vty, const char *peer_str,
4748 afi_t afi, safi_t safi,
4749 const char *rmap, int set)
4750 {
4751 int ret;
4752 struct peer *peer;
4753
4754 peer = peer_and_group_lookup_vty(vty, peer_str);
4755 if (!peer)
4756 return CMD_WARNING_CONFIG_FAILED;
4757
4758 if (set)
4759 ret = peer_default_originate_set(peer, afi, safi, rmap);
4760 else
4761 ret = peer_default_originate_unset(peer, afi, safi);
4762
4763 return bgp_vty_return(vty, ret);
4764 }
4765
4766 /* neighbor default-originate. */
4767 DEFUN (neighbor_default_originate,
4768 neighbor_default_originate_cmd,
4769 "neighbor <A.B.C.D|X:X::X:X|WORD> default-originate",
4770 NEIGHBOR_STR
4771 NEIGHBOR_ADDR_STR2
4772 "Originate default route to this neighbor\n")
4773 {
4774 int idx_peer = 1;
4775 return peer_default_originate_set_vty(vty, argv[idx_peer]->arg,
4776 bgp_node_afi(vty),
4777 bgp_node_safi(vty), NULL, 1);
4778 }
4779
4780 ALIAS_HIDDEN(neighbor_default_originate, neighbor_default_originate_hidden_cmd,
4781 "neighbor <A.B.C.D|X:X::X:X|WORD> default-originate",
4782 NEIGHBOR_STR NEIGHBOR_ADDR_STR2
4783 "Originate default route to this neighbor\n")
4784
4785 DEFUN (neighbor_default_originate_rmap,
4786 neighbor_default_originate_rmap_cmd,
4787 "neighbor <A.B.C.D|X:X::X:X|WORD> default-originate route-map WORD",
4788 NEIGHBOR_STR
4789 NEIGHBOR_ADDR_STR2
4790 "Originate default route to this neighbor\n"
4791 "Route-map to specify criteria to originate default\n"
4792 "route-map name\n")
4793 {
4794 int idx_peer = 1;
4795 int idx_word = 4;
4796 return peer_default_originate_set_vty(
4797 vty, argv[idx_peer]->arg, bgp_node_afi(vty), bgp_node_safi(vty),
4798 argv[idx_word]->arg, 1);
4799 }
4800
4801 ALIAS_HIDDEN(
4802 neighbor_default_originate_rmap,
4803 neighbor_default_originate_rmap_hidden_cmd,
4804 "neighbor <A.B.C.D|X:X::X:X|WORD> default-originate route-map WORD",
4805 NEIGHBOR_STR NEIGHBOR_ADDR_STR2
4806 "Originate default route to this neighbor\n"
4807 "Route-map to specify criteria to originate default\n"
4808 "route-map name\n")
4809
4810 DEFUN (no_neighbor_default_originate,
4811 no_neighbor_default_originate_cmd,
4812 "no neighbor <A.B.C.D|X:X::X:X|WORD> default-originate [route-map WORD]",
4813 NO_STR
4814 NEIGHBOR_STR
4815 NEIGHBOR_ADDR_STR2
4816 "Originate default route to this neighbor\n"
4817 "Route-map to specify criteria to originate default\n"
4818 "route-map name\n")
4819 {
4820 int idx_peer = 2;
4821 return peer_default_originate_set_vty(vty, argv[idx_peer]->arg,
4822 bgp_node_afi(vty),
4823 bgp_node_safi(vty), NULL, 0);
4824 }
4825
4826 ALIAS_HIDDEN(
4827 no_neighbor_default_originate, no_neighbor_default_originate_hidden_cmd,
4828 "no neighbor <A.B.C.D|X:X::X:X|WORD> default-originate [route-map WORD]",
4829 NO_STR NEIGHBOR_STR NEIGHBOR_ADDR_STR2
4830 "Originate default route to this neighbor\n"
4831 "Route-map to specify criteria to originate default\n"
4832 "route-map name\n")
4833
4834
4835 /* Set neighbor's BGP port. */
4836 static int peer_port_vty(struct vty *vty, const char *ip_str, int afi,
4837 const char *port_str)
4838 {
4839 struct peer *peer;
4840 uint16_t port;
4841 struct servent *sp;
4842
4843 peer = peer_lookup_vty(vty, ip_str);
4844 if (!peer)
4845 return CMD_WARNING_CONFIG_FAILED;
4846
4847 if (!port_str) {
4848 sp = getservbyname("bgp", "tcp");
4849 port = (sp == NULL) ? BGP_PORT_DEFAULT : ntohs(sp->s_port);
4850 } else {
4851 port = strtoul(port_str, NULL, 10);
4852 }
4853
4854 peer_port_set(peer, port);
4855
4856 return CMD_SUCCESS;
4857 }
4858
4859 /* Set specified peer's BGP port. */
4860 DEFUN (neighbor_port,
4861 neighbor_port_cmd,
4862 "neighbor <A.B.C.D|X:X::X:X> port (0-65535)",
4863 NEIGHBOR_STR
4864 NEIGHBOR_ADDR_STR
4865 "Neighbor's BGP port\n"
4866 "TCP port number\n")
4867 {
4868 int idx_ip = 1;
4869 int idx_number = 3;
4870 return peer_port_vty(vty, argv[idx_ip]->arg, AFI_IP,
4871 argv[idx_number]->arg);
4872 }
4873
4874 DEFUN (no_neighbor_port,
4875 no_neighbor_port_cmd,
4876 "no neighbor <A.B.C.D|X:X::X:X> port [(0-65535)]",
4877 NO_STR
4878 NEIGHBOR_STR
4879 NEIGHBOR_ADDR_STR
4880 "Neighbor's BGP port\n"
4881 "TCP port number\n")
4882 {
4883 int idx_ip = 2;
4884 return peer_port_vty(vty, argv[idx_ip]->arg, AFI_IP, NULL);
4885 }
4886
4887
4888 /* neighbor weight. */
4889 static int peer_weight_set_vty(struct vty *vty, const char *ip_str, afi_t afi,
4890 safi_t safi, const char *weight_str)
4891 {
4892 int ret;
4893 struct peer *peer;
4894 unsigned long weight;
4895
4896 peer = peer_and_group_lookup_vty(vty, ip_str);
4897 if (!peer)
4898 return CMD_WARNING_CONFIG_FAILED;
4899
4900 weight = strtoul(weight_str, NULL, 10);
4901
4902 ret = peer_weight_set(peer, afi, safi, weight);
4903 return bgp_vty_return(vty, ret);
4904 }
4905
4906 static int peer_weight_unset_vty(struct vty *vty, const char *ip_str, afi_t afi,
4907 safi_t safi)
4908 {
4909 int ret;
4910 struct peer *peer;
4911
4912 peer = peer_and_group_lookup_vty(vty, ip_str);
4913 if (!peer)
4914 return CMD_WARNING_CONFIG_FAILED;
4915
4916 ret = peer_weight_unset(peer, afi, safi);
4917 return bgp_vty_return(vty, ret);
4918 }
4919
4920 DEFUN (neighbor_weight,
4921 neighbor_weight_cmd,
4922 "neighbor <A.B.C.D|X:X::X:X|WORD> weight (0-65535)",
4923 NEIGHBOR_STR
4924 NEIGHBOR_ADDR_STR2
4925 "Set default weight for routes from this neighbor\n"
4926 "default weight\n")
4927 {
4928 int idx_peer = 1;
4929 int idx_number = 3;
4930 return peer_weight_set_vty(vty, argv[idx_peer]->arg, bgp_node_afi(vty),
4931 bgp_node_safi(vty), argv[idx_number]->arg);
4932 }
4933
4934 ALIAS_HIDDEN(neighbor_weight, neighbor_weight_hidden_cmd,
4935 "neighbor <A.B.C.D|X:X::X:X|WORD> weight (0-65535)",
4936 NEIGHBOR_STR NEIGHBOR_ADDR_STR2
4937 "Set default weight for routes from this neighbor\n"
4938 "default weight\n")
4939
4940 DEFUN (no_neighbor_weight,
4941 no_neighbor_weight_cmd,
4942 "no neighbor <A.B.C.D|X:X::X:X|WORD> weight [(0-65535)]",
4943 NO_STR
4944 NEIGHBOR_STR
4945 NEIGHBOR_ADDR_STR2
4946 "Set default weight for routes from this neighbor\n"
4947 "default weight\n")
4948 {
4949 int idx_peer = 2;
4950 return peer_weight_unset_vty(vty, argv[idx_peer]->arg,
4951 bgp_node_afi(vty), bgp_node_safi(vty));
4952 }
4953
4954 ALIAS_HIDDEN(no_neighbor_weight, no_neighbor_weight_hidden_cmd,
4955 "no neighbor <A.B.C.D|X:X::X:X|WORD> weight [(0-65535)]",
4956 NO_STR NEIGHBOR_STR NEIGHBOR_ADDR_STR2
4957 "Set default weight for routes from this neighbor\n"
4958 "default weight\n")
4959
4960
4961 /* Override capability negotiation. */
4962 DEFUN (neighbor_override_capability,
4963 neighbor_override_capability_cmd,
4964 "neighbor <A.B.C.D|X:X::X:X|WORD> override-capability",
4965 NEIGHBOR_STR
4966 NEIGHBOR_ADDR_STR2
4967 "Override capability negotiation result\n")
4968 {
4969 int idx_peer = 1;
4970 return peer_flag_set_vty(vty, argv[idx_peer]->arg,
4971 PEER_FLAG_OVERRIDE_CAPABILITY);
4972 }
4973
4974 DEFUN (no_neighbor_override_capability,
4975 no_neighbor_override_capability_cmd,
4976 "no neighbor <A.B.C.D|X:X::X:X|WORD> override-capability",
4977 NO_STR
4978 NEIGHBOR_STR
4979 NEIGHBOR_ADDR_STR2
4980 "Override capability negotiation result\n")
4981 {
4982 int idx_peer = 2;
4983 return peer_flag_unset_vty(vty, argv[idx_peer]->arg,
4984 PEER_FLAG_OVERRIDE_CAPABILITY);
4985 }
4986
4987 DEFUN (neighbor_strict_capability,
4988 neighbor_strict_capability_cmd,
4989 "neighbor <A.B.C.D|X:X::X:X|WORD> strict-capability-match",
4990 NEIGHBOR_STR
4991 NEIGHBOR_ADDR_STR2
4992 "Strict capability negotiation match\n")
4993 {
4994 int idx_peer = 1;
4995
4996 return peer_flag_set_vty(vty, argv[idx_peer]->arg,
4997 PEER_FLAG_STRICT_CAP_MATCH);
4998 }
4999
5000 DEFUN (no_neighbor_strict_capability,
5001 no_neighbor_strict_capability_cmd,
5002 "no neighbor <A.B.C.D|X:X::X:X|WORD> strict-capability-match",
5003 NO_STR
5004 NEIGHBOR_STR
5005 NEIGHBOR_ADDR_STR2
5006 "Strict capability negotiation match\n")
5007 {
5008 int idx_peer = 2;
5009
5010 return peer_flag_unset_vty(vty, argv[idx_peer]->arg,
5011 PEER_FLAG_STRICT_CAP_MATCH);
5012 }
5013
5014 static int peer_timers_set_vty(struct vty *vty, const char *ip_str,
5015 const char *keep_str, const char *hold_str)
5016 {
5017 int ret;
5018 struct peer *peer;
5019 uint32_t keepalive;
5020 uint32_t holdtime;
5021
5022 peer = peer_and_group_lookup_vty(vty, ip_str);
5023 if (!peer)
5024 return CMD_WARNING_CONFIG_FAILED;
5025
5026 keepalive = strtoul(keep_str, NULL, 10);
5027 holdtime = strtoul(hold_str, NULL, 10);
5028
5029 ret = peer_timers_set(peer, keepalive, holdtime);
5030
5031 return bgp_vty_return(vty, ret);
5032 }
5033
5034 static int peer_timers_unset_vty(struct vty *vty, const char *ip_str)
5035 {
5036 int ret;
5037 struct peer *peer;
5038
5039 peer = peer_and_group_lookup_vty(vty, ip_str);
5040 if (!peer)
5041 return CMD_WARNING_CONFIG_FAILED;
5042
5043 ret = peer_timers_unset(peer);
5044
5045 return bgp_vty_return(vty, ret);
5046 }
5047
5048 DEFUN (neighbor_timers,
5049 neighbor_timers_cmd,
5050 "neighbor <A.B.C.D|X:X::X:X|WORD> timers (0-65535) (0-65535)",
5051 NEIGHBOR_STR
5052 NEIGHBOR_ADDR_STR2
5053 "BGP per neighbor timers\n"
5054 "Keepalive interval\n"
5055 "Holdtime\n")
5056 {
5057 int idx_peer = 1;
5058 int idx_number = 3;
5059 int idx_number_2 = 4;
5060 return peer_timers_set_vty(vty, argv[idx_peer]->arg,
5061 argv[idx_number]->arg,
5062 argv[idx_number_2]->arg);
5063 }
5064
5065 DEFUN (no_neighbor_timers,
5066 no_neighbor_timers_cmd,
5067 "no neighbor <A.B.C.D|X:X::X:X|WORD> timers [(0-65535) (0-65535)]",
5068 NO_STR
5069 NEIGHBOR_STR
5070 NEIGHBOR_ADDR_STR2
5071 "BGP per neighbor timers\n"
5072 "Keepalive interval\n"
5073 "Holdtime\n")
5074 {
5075 int idx_peer = 2;
5076 return peer_timers_unset_vty(vty, argv[idx_peer]->arg);
5077 }
5078
5079
5080 static int peer_timers_connect_set_vty(struct vty *vty, const char *ip_str,
5081 const char *time_str)
5082 {
5083 int ret;
5084 struct peer *peer;
5085 uint32_t connect;
5086
5087 peer = peer_and_group_lookup_vty(vty, ip_str);
5088 if (!peer)
5089 return CMD_WARNING_CONFIG_FAILED;
5090
5091 connect = strtoul(time_str, NULL, 10);
5092
5093 ret = peer_timers_connect_set(peer, connect);
5094
5095 return bgp_vty_return(vty, ret);
5096 }
5097
5098 static int peer_timers_connect_unset_vty(struct vty *vty, const char *ip_str)
5099 {
5100 int ret;
5101 struct peer *peer;
5102
5103 peer = peer_and_group_lookup_vty(vty, ip_str);
5104 if (!peer)
5105 return CMD_WARNING_CONFIG_FAILED;
5106
5107 ret = peer_timers_connect_unset(peer);
5108
5109 return bgp_vty_return(vty, ret);
5110 }
5111
5112 DEFUN (neighbor_timers_connect,
5113 neighbor_timers_connect_cmd,
5114 "neighbor <A.B.C.D|X:X::X:X|WORD> timers connect (1-65535)",
5115 NEIGHBOR_STR
5116 NEIGHBOR_ADDR_STR2
5117 "BGP per neighbor timers\n"
5118 "BGP connect timer\n"
5119 "Connect timer\n")
5120 {
5121 int idx_peer = 1;
5122 int idx_number = 4;
5123 return peer_timers_connect_set_vty(vty, argv[idx_peer]->arg,
5124 argv[idx_number]->arg);
5125 }
5126
5127 DEFUN (no_neighbor_timers_connect,
5128 no_neighbor_timers_connect_cmd,
5129 "no neighbor <A.B.C.D|X:X::X:X|WORD> timers connect [(1-65535)]",
5130 NO_STR
5131 NEIGHBOR_STR
5132 NEIGHBOR_ADDR_STR2
5133 "BGP per neighbor timers\n"
5134 "BGP connect timer\n"
5135 "Connect timer\n")
5136 {
5137 int idx_peer = 2;
5138 return peer_timers_connect_unset_vty(vty, argv[idx_peer]->arg);
5139 }
5140
5141
5142 static int peer_advertise_interval_vty(struct vty *vty, const char *ip_str,
5143 const char *time_str, int set)
5144 {
5145 int ret;
5146 struct peer *peer;
5147 uint32_t routeadv = 0;
5148
5149 peer = peer_and_group_lookup_vty(vty, ip_str);
5150 if (!peer)
5151 return CMD_WARNING_CONFIG_FAILED;
5152
5153 if (time_str)
5154 routeadv = strtoul(time_str, NULL, 10);
5155
5156 if (set)
5157 ret = peer_advertise_interval_set(peer, routeadv);
5158 else
5159 ret = peer_advertise_interval_unset(peer);
5160
5161 return bgp_vty_return(vty, ret);
5162 }
5163
5164 DEFUN (neighbor_advertise_interval,
5165 neighbor_advertise_interval_cmd,
5166 "neighbor <A.B.C.D|X:X::X:X|WORD> advertisement-interval (0-600)",
5167 NEIGHBOR_STR
5168 NEIGHBOR_ADDR_STR2
5169 "Minimum interval between sending BGP routing updates\n"
5170 "time in seconds\n")
5171 {
5172 int idx_peer = 1;
5173 int idx_number = 3;
5174 return peer_advertise_interval_vty(vty, argv[idx_peer]->arg,
5175 argv[idx_number]->arg, 1);
5176 }
5177
5178 DEFUN (no_neighbor_advertise_interval,
5179 no_neighbor_advertise_interval_cmd,
5180 "no neighbor <A.B.C.D|X:X::X:X|WORD> advertisement-interval [(0-600)]",
5181 NO_STR
5182 NEIGHBOR_STR
5183 NEIGHBOR_ADDR_STR2
5184 "Minimum interval between sending BGP routing updates\n"
5185 "time in seconds\n")
5186 {
5187 int idx_peer = 2;
5188 return peer_advertise_interval_vty(vty, argv[idx_peer]->arg, NULL, 0);
5189 }
5190
5191
5192 /* Time to wait before processing route-map updates */
5193 DEFUN (bgp_set_route_map_delay_timer,
5194 bgp_set_route_map_delay_timer_cmd,
5195 "bgp route-map delay-timer (0-600)",
5196 SET_STR
5197 "BGP route-map delay timer\n"
5198 "Time in secs to wait before processing route-map changes\n"
5199 "0 disables the timer, no route updates happen when route-maps change\n")
5200 {
5201 int idx_number = 3;
5202 uint32_t rmap_delay_timer;
5203
5204 if (argv[idx_number]->arg) {
5205 rmap_delay_timer = strtoul(argv[idx_number]->arg, NULL, 10);
5206 bm->rmap_update_timer = rmap_delay_timer;
5207
5208 /* if the dynamic update handling is being disabled, and a timer
5209 * is
5210 * running, stop the timer and act as if the timer has already
5211 * fired.
5212 */
5213 if (!rmap_delay_timer && bm->t_rmap_update) {
5214 BGP_TIMER_OFF(bm->t_rmap_update);
5215 thread_execute(bm->master, bgp_route_map_update_timer,
5216 NULL, 0);
5217 }
5218 return CMD_SUCCESS;
5219 } else {
5220 vty_out(vty, "%% BGP invalid route-map delay-timer\n");
5221 return CMD_WARNING_CONFIG_FAILED;
5222 }
5223 }
5224
5225 DEFUN (no_bgp_set_route_map_delay_timer,
5226 no_bgp_set_route_map_delay_timer_cmd,
5227 "no bgp route-map delay-timer [(0-600)]",
5228 NO_STR
5229 BGP_STR
5230 "Default BGP route-map delay timer\n"
5231 "Reset to default time to wait for processing route-map changes\n"
5232 "0 disables the timer, no route updates happen when route-maps change\n")
5233 {
5234
5235 bm->rmap_update_timer = RMAP_DEFAULT_UPDATE_TIMER;
5236
5237 return CMD_SUCCESS;
5238 }
5239
5240
5241 /* neighbor interface */
5242 static int peer_interface_vty(struct vty *vty, const char *ip_str,
5243 const char *str)
5244 {
5245 struct peer *peer;
5246
5247 peer = peer_lookup_vty(vty, ip_str);
5248 if (!peer || peer->conf_if) {
5249 vty_out(vty, "%% BGP invalid peer %s\n", ip_str);
5250 return CMD_WARNING_CONFIG_FAILED;
5251 }
5252
5253 if (str)
5254 peer_interface_set(peer, str);
5255 else
5256 peer_interface_unset(peer);
5257
5258 return CMD_SUCCESS;
5259 }
5260
5261 DEFUN (neighbor_interface,
5262 neighbor_interface_cmd,
5263 "neighbor <A.B.C.D|X:X::X:X> interface WORD",
5264 NEIGHBOR_STR
5265 NEIGHBOR_ADDR_STR
5266 "Interface\n"
5267 "Interface name\n")
5268 {
5269 int idx_ip = 1;
5270 int idx_word = 3;
5271 return peer_interface_vty(vty, argv[idx_ip]->arg, argv[idx_word]->arg);
5272 }
5273
5274 DEFUN (no_neighbor_interface,
5275 no_neighbor_interface_cmd,
5276 "no neighbor <A.B.C.D|X:X::X:X|WORD> interface WORD",
5277 NO_STR
5278 NEIGHBOR_STR
5279 NEIGHBOR_ADDR_STR2
5280 "Interface\n"
5281 "Interface name\n")
5282 {
5283 int idx_peer = 2;
5284 return peer_interface_vty(vty, argv[idx_peer]->arg, NULL);
5285 }
5286
5287 DEFUN (neighbor_distribute_list,
5288 neighbor_distribute_list_cmd,
5289 "neighbor <A.B.C.D|X:X::X:X|WORD> distribute-list <(1-199)|(1300-2699)|WORD> <in|out>",
5290 NEIGHBOR_STR
5291 NEIGHBOR_ADDR_STR2
5292 "Filter updates to/from this neighbor\n"
5293 "IP access-list number\n"
5294 "IP access-list number (expanded range)\n"
5295 "IP Access-list name\n"
5296 "Filter incoming updates\n"
5297 "Filter outgoing updates\n")
5298 {
5299 int idx_peer = 1;
5300 int idx_acl = 3;
5301 int direct, ret;
5302 struct peer *peer;
5303
5304 const char *pstr = argv[idx_peer]->arg;
5305 const char *acl = argv[idx_acl]->arg;
5306 const char *inout = argv[argc - 1]->text;
5307
5308 peer = peer_and_group_lookup_vty(vty, pstr);
5309 if (!peer)
5310 return CMD_WARNING_CONFIG_FAILED;
5311
5312 /* Check filter direction. */
5313 direct = strmatch(inout, "in") ? FILTER_IN : FILTER_OUT;
5314 ret = peer_distribute_set(peer, bgp_node_afi(vty), bgp_node_safi(vty),
5315 direct, acl);
5316
5317 return bgp_vty_return(vty, ret);
5318 }
5319
5320 ALIAS_HIDDEN(
5321 neighbor_distribute_list, neighbor_distribute_list_hidden_cmd,
5322 "neighbor <A.B.C.D|X:X::X:X|WORD> distribute-list <(1-199)|(1300-2699)|WORD> <in|out>",
5323 NEIGHBOR_STR NEIGHBOR_ADDR_STR2
5324 "Filter updates to/from this neighbor\n"
5325 "IP access-list number\n"
5326 "IP access-list number (expanded range)\n"
5327 "IP Access-list name\n"
5328 "Filter incoming updates\n"
5329 "Filter outgoing updates\n")
5330
5331 DEFUN (no_neighbor_distribute_list,
5332 no_neighbor_distribute_list_cmd,
5333 "no neighbor <A.B.C.D|X:X::X:X|WORD> distribute-list <(1-199)|(1300-2699)|WORD> <in|out>",
5334 NO_STR
5335 NEIGHBOR_STR
5336 NEIGHBOR_ADDR_STR2
5337 "Filter updates to/from this neighbor\n"
5338 "IP access-list number\n"
5339 "IP access-list number (expanded range)\n"
5340 "IP Access-list name\n"
5341 "Filter incoming updates\n"
5342 "Filter outgoing updates\n")
5343 {
5344 int idx_peer = 2;
5345 int direct, ret;
5346 struct peer *peer;
5347
5348 const char *pstr = argv[idx_peer]->arg;
5349 const char *inout = argv[argc - 1]->text;
5350
5351 peer = peer_and_group_lookup_vty(vty, pstr);
5352 if (!peer)
5353 return CMD_WARNING_CONFIG_FAILED;
5354
5355 /* Check filter direction. */
5356 direct = strmatch(inout, "in") ? FILTER_IN : FILTER_OUT;
5357 ret = peer_distribute_unset(peer, bgp_node_afi(vty), bgp_node_safi(vty),
5358 direct);
5359
5360 return bgp_vty_return(vty, ret);
5361 }
5362
5363 ALIAS_HIDDEN(
5364 no_neighbor_distribute_list, no_neighbor_distribute_list_hidden_cmd,
5365 "no neighbor <A.B.C.D|X:X::X:X|WORD> distribute-list <(1-199)|(1300-2699)|WORD> <in|out>",
5366 NO_STR NEIGHBOR_STR NEIGHBOR_ADDR_STR2
5367 "Filter updates to/from this neighbor\n"
5368 "IP access-list number\n"
5369 "IP access-list number (expanded range)\n"
5370 "IP Access-list name\n"
5371 "Filter incoming updates\n"
5372 "Filter outgoing updates\n")
5373
5374 /* Set prefix list to the peer. */
5375 static int peer_prefix_list_set_vty(struct vty *vty, const char *ip_str,
5376 afi_t afi, safi_t safi,
5377 const char *name_str,
5378 const char *direct_str)
5379 {
5380 int ret;
5381 int direct = FILTER_IN;
5382 struct peer *peer;
5383
5384 peer = peer_and_group_lookup_vty(vty, ip_str);
5385 if (!peer)
5386 return CMD_WARNING_CONFIG_FAILED;
5387
5388 /* Check filter direction. */
5389 if (strncmp(direct_str, "i", 1) == 0)
5390 direct = FILTER_IN;
5391 else if (strncmp(direct_str, "o", 1) == 0)
5392 direct = FILTER_OUT;
5393
5394 ret = peer_prefix_list_set(peer, afi, safi, direct, name_str);
5395
5396 return bgp_vty_return(vty, ret);
5397 }
5398
5399 static int peer_prefix_list_unset_vty(struct vty *vty, const char *ip_str,
5400 afi_t afi, safi_t safi,
5401 const char *direct_str)
5402 {
5403 int ret;
5404 struct peer *peer;
5405 int direct = FILTER_IN;
5406
5407 peer = peer_and_group_lookup_vty(vty, ip_str);
5408 if (!peer)
5409 return CMD_WARNING_CONFIG_FAILED;
5410
5411 /* Check filter direction. */
5412 if (strncmp(direct_str, "i", 1) == 0)
5413 direct = FILTER_IN;
5414 else if (strncmp(direct_str, "o", 1) == 0)
5415 direct = FILTER_OUT;
5416
5417 ret = peer_prefix_list_unset(peer, afi, safi, direct);
5418
5419 return bgp_vty_return(vty, ret);
5420 }
5421
5422 DEFUN (neighbor_prefix_list,
5423 neighbor_prefix_list_cmd,
5424 "neighbor <A.B.C.D|X:X::X:X|WORD> prefix-list WORD <in|out>",
5425 NEIGHBOR_STR
5426 NEIGHBOR_ADDR_STR2
5427 "Filter updates to/from this neighbor\n"
5428 "Name of a prefix list\n"
5429 "Filter incoming updates\n"
5430 "Filter outgoing updates\n")
5431 {
5432 int idx_peer = 1;
5433 int idx_word = 3;
5434 int idx_in_out = 4;
5435 return peer_prefix_list_set_vty(
5436 vty, argv[idx_peer]->arg, bgp_node_afi(vty), bgp_node_safi(vty),
5437 argv[idx_word]->arg, argv[idx_in_out]->arg);
5438 }
5439
5440 ALIAS_HIDDEN(neighbor_prefix_list, neighbor_prefix_list_hidden_cmd,
5441 "neighbor <A.B.C.D|X:X::X:X|WORD> prefix-list WORD <in|out>",
5442 NEIGHBOR_STR NEIGHBOR_ADDR_STR2
5443 "Filter updates to/from this neighbor\n"
5444 "Name of a prefix list\n"
5445 "Filter incoming updates\n"
5446 "Filter outgoing updates\n")
5447
5448 DEFUN (no_neighbor_prefix_list,
5449 no_neighbor_prefix_list_cmd,
5450 "no neighbor <A.B.C.D|X:X::X:X|WORD> prefix-list WORD <in|out>",
5451 NO_STR
5452 NEIGHBOR_STR
5453 NEIGHBOR_ADDR_STR2
5454 "Filter updates to/from this neighbor\n"
5455 "Name of a prefix list\n"
5456 "Filter incoming updates\n"
5457 "Filter outgoing updates\n")
5458 {
5459 int idx_peer = 2;
5460 int idx_in_out = 5;
5461 return peer_prefix_list_unset_vty(vty, argv[idx_peer]->arg,
5462 bgp_node_afi(vty), bgp_node_safi(vty),
5463 argv[idx_in_out]->arg);
5464 }
5465
5466 ALIAS_HIDDEN(no_neighbor_prefix_list, no_neighbor_prefix_list_hidden_cmd,
5467 "no neighbor <A.B.C.D|X:X::X:X|WORD> prefix-list WORD <in|out>",
5468 NO_STR NEIGHBOR_STR NEIGHBOR_ADDR_STR2
5469 "Filter updates to/from this neighbor\n"
5470 "Name of a prefix list\n"
5471 "Filter incoming updates\n"
5472 "Filter outgoing updates\n")
5473
5474 static int peer_aslist_set_vty(struct vty *vty, const char *ip_str, afi_t afi,
5475 safi_t safi, const char *name_str,
5476 const char *direct_str)
5477 {
5478 int ret;
5479 struct peer *peer;
5480 int direct = FILTER_IN;
5481
5482 peer = peer_and_group_lookup_vty(vty, ip_str);
5483 if (!peer)
5484 return CMD_WARNING_CONFIG_FAILED;
5485
5486 /* Check filter direction. */
5487 if (strncmp(direct_str, "i", 1) == 0)
5488 direct = FILTER_IN;
5489 else if (strncmp(direct_str, "o", 1) == 0)
5490 direct = FILTER_OUT;
5491
5492 ret = peer_aslist_set(peer, afi, safi, direct, name_str);
5493
5494 return bgp_vty_return(vty, ret);
5495 }
5496
5497 static int peer_aslist_unset_vty(struct vty *vty, const char *ip_str, afi_t afi,
5498 safi_t safi, const char *direct_str)
5499 {
5500 int ret;
5501 struct peer *peer;
5502 int direct = FILTER_IN;
5503
5504 peer = peer_and_group_lookup_vty(vty, ip_str);
5505 if (!peer)
5506 return CMD_WARNING_CONFIG_FAILED;
5507
5508 /* Check filter direction. */
5509 if (strncmp(direct_str, "i", 1) == 0)
5510 direct = FILTER_IN;
5511 else if (strncmp(direct_str, "o", 1) == 0)
5512 direct = FILTER_OUT;
5513
5514 ret = peer_aslist_unset(peer, afi, safi, direct);
5515
5516 return bgp_vty_return(vty, ret);
5517 }
5518
5519 DEFUN (neighbor_filter_list,
5520 neighbor_filter_list_cmd,
5521 "neighbor <A.B.C.D|X:X::X:X|WORD> filter-list WORD <in|out>",
5522 NEIGHBOR_STR
5523 NEIGHBOR_ADDR_STR2
5524 "Establish BGP filters\n"
5525 "AS path access-list name\n"
5526 "Filter incoming routes\n"
5527 "Filter outgoing routes\n")
5528 {
5529 int idx_peer = 1;
5530 int idx_word = 3;
5531 int idx_in_out = 4;
5532 return peer_aslist_set_vty(vty, argv[idx_peer]->arg, bgp_node_afi(vty),
5533 bgp_node_safi(vty), argv[idx_word]->arg,
5534 argv[idx_in_out]->arg);
5535 }
5536
5537 ALIAS_HIDDEN(neighbor_filter_list, neighbor_filter_list_hidden_cmd,
5538 "neighbor <A.B.C.D|X:X::X:X|WORD> filter-list WORD <in|out>",
5539 NEIGHBOR_STR NEIGHBOR_ADDR_STR2
5540 "Establish BGP filters\n"
5541 "AS path access-list name\n"
5542 "Filter incoming routes\n"
5543 "Filter outgoing routes\n")
5544
5545 DEFUN (no_neighbor_filter_list,
5546 no_neighbor_filter_list_cmd,
5547 "no neighbor <A.B.C.D|X:X::X:X|WORD> filter-list WORD <in|out>",
5548 NO_STR
5549 NEIGHBOR_STR
5550 NEIGHBOR_ADDR_STR2
5551 "Establish BGP filters\n"
5552 "AS path access-list name\n"
5553 "Filter incoming routes\n"
5554 "Filter outgoing routes\n")
5555 {
5556 int idx_peer = 2;
5557 int idx_in_out = 5;
5558 return peer_aslist_unset_vty(vty, argv[idx_peer]->arg,
5559 bgp_node_afi(vty), bgp_node_safi(vty),
5560 argv[idx_in_out]->arg);
5561 }
5562
5563 ALIAS_HIDDEN(no_neighbor_filter_list, no_neighbor_filter_list_hidden_cmd,
5564 "no neighbor <A.B.C.D|X:X::X:X|WORD> filter-list WORD <in|out>",
5565 NO_STR NEIGHBOR_STR NEIGHBOR_ADDR_STR2
5566 "Establish BGP filters\n"
5567 "AS path access-list name\n"
5568 "Filter incoming routes\n"
5569 "Filter outgoing routes\n")
5570
5571 /* Set route-map to the peer. */
5572 static int peer_route_map_set_vty(struct vty *vty, const char *ip_str,
5573 afi_t afi, safi_t safi, const char *name_str,
5574 const char *direct_str)
5575 {
5576 int ret;
5577 struct peer *peer;
5578 int direct = RMAP_IN;
5579
5580 peer = peer_and_group_lookup_vty(vty, ip_str);
5581 if (!peer)
5582 return CMD_WARNING_CONFIG_FAILED;
5583
5584 /* Check filter direction. */
5585 if (strncmp(direct_str, "in", 2) == 0)
5586 direct = RMAP_IN;
5587 else if (strncmp(direct_str, "o", 1) == 0)
5588 direct = RMAP_OUT;
5589
5590 ret = peer_route_map_set(peer, afi, safi, direct, name_str);
5591
5592 return bgp_vty_return(vty, ret);
5593 }
5594
5595 static int peer_route_map_unset_vty(struct vty *vty, const char *ip_str,
5596 afi_t afi, safi_t safi,
5597 const char *direct_str)
5598 {
5599 int ret;
5600 struct peer *peer;
5601 int direct = RMAP_IN;
5602
5603 peer = peer_and_group_lookup_vty(vty, ip_str);
5604 if (!peer)
5605 return CMD_WARNING_CONFIG_FAILED;
5606
5607 /* Check filter direction. */
5608 if (strncmp(direct_str, "in", 2) == 0)
5609 direct = RMAP_IN;
5610 else if (strncmp(direct_str, "o", 1) == 0)
5611 direct = RMAP_OUT;
5612
5613 ret = peer_route_map_unset(peer, afi, safi, direct);
5614
5615 return bgp_vty_return(vty, ret);
5616 }
5617
5618 DEFUN (neighbor_route_map,
5619 neighbor_route_map_cmd,
5620 "neighbor <A.B.C.D|X:X::X:X|WORD> route-map WORD <in|out>",
5621 NEIGHBOR_STR
5622 NEIGHBOR_ADDR_STR2
5623 "Apply route map to neighbor\n"
5624 "Name of route map\n"
5625 "Apply map to incoming routes\n"
5626 "Apply map to outbound routes\n")
5627 {
5628 int idx_peer = 1;
5629 int idx_word = 3;
5630 int idx_in_out = 4;
5631 return peer_route_map_set_vty(
5632 vty, argv[idx_peer]->arg, bgp_node_afi(vty), bgp_node_safi(vty),
5633 argv[idx_word]->arg, argv[idx_in_out]->arg);
5634 }
5635
5636 ALIAS_HIDDEN(neighbor_route_map, neighbor_route_map_hidden_cmd,
5637 "neighbor <A.B.C.D|X:X::X:X|WORD> route-map WORD <in|out>",
5638 NEIGHBOR_STR NEIGHBOR_ADDR_STR2
5639 "Apply route map to neighbor\n"
5640 "Name of route map\n"
5641 "Apply map to incoming routes\n"
5642 "Apply map to outbound routes\n")
5643
5644 DEFUN (no_neighbor_route_map,
5645 no_neighbor_route_map_cmd,
5646 "no neighbor <A.B.C.D|X:X::X:X|WORD> route-map WORD <in|out>",
5647 NO_STR
5648 NEIGHBOR_STR
5649 NEIGHBOR_ADDR_STR2
5650 "Apply route map to neighbor\n"
5651 "Name of route map\n"
5652 "Apply map to incoming routes\n"
5653 "Apply map to outbound routes\n")
5654 {
5655 int idx_peer = 2;
5656 int idx_in_out = 5;
5657 return peer_route_map_unset_vty(vty, argv[idx_peer]->arg,
5658 bgp_node_afi(vty), bgp_node_safi(vty),
5659 argv[idx_in_out]->arg);
5660 }
5661
5662 ALIAS_HIDDEN(no_neighbor_route_map, no_neighbor_route_map_hidden_cmd,
5663 "no neighbor <A.B.C.D|X:X::X:X|WORD> route-map WORD <in|out>",
5664 NO_STR NEIGHBOR_STR NEIGHBOR_ADDR_STR2
5665 "Apply route map to neighbor\n"
5666 "Name of route map\n"
5667 "Apply map to incoming routes\n"
5668 "Apply map to outbound routes\n")
5669
5670 /* Set unsuppress-map to the peer. */
5671 static int peer_unsuppress_map_set_vty(struct vty *vty, const char *ip_str,
5672 afi_t afi, safi_t safi,
5673 const char *name_str)
5674 {
5675 int ret;
5676 struct peer *peer;
5677
5678 peer = peer_and_group_lookup_vty(vty, ip_str);
5679 if (!peer)
5680 return CMD_WARNING_CONFIG_FAILED;
5681
5682 ret = peer_unsuppress_map_set(peer, afi, safi, name_str);
5683
5684 return bgp_vty_return(vty, ret);
5685 }
5686
5687 /* Unset route-map from the peer. */
5688 static int peer_unsuppress_map_unset_vty(struct vty *vty, const char *ip_str,
5689 afi_t afi, safi_t safi)
5690 {
5691 int ret;
5692 struct peer *peer;
5693
5694 peer = peer_and_group_lookup_vty(vty, ip_str);
5695 if (!peer)
5696 return CMD_WARNING_CONFIG_FAILED;
5697
5698 ret = peer_unsuppress_map_unset(peer, afi, safi);
5699
5700 return bgp_vty_return(vty, ret);
5701 }
5702
5703 DEFUN (neighbor_unsuppress_map,
5704 neighbor_unsuppress_map_cmd,
5705 "neighbor <A.B.C.D|X:X::X:X|WORD> unsuppress-map WORD",
5706 NEIGHBOR_STR
5707 NEIGHBOR_ADDR_STR2
5708 "Route-map to selectively unsuppress suppressed routes\n"
5709 "Name of route map\n")
5710 {
5711 int idx_peer = 1;
5712 int idx_word = 3;
5713 return peer_unsuppress_map_set_vty(
5714 vty, argv[idx_peer]->arg, bgp_node_afi(vty), bgp_node_safi(vty),
5715 argv[idx_word]->arg);
5716 }
5717
5718 ALIAS_HIDDEN(neighbor_unsuppress_map, neighbor_unsuppress_map_hidden_cmd,
5719 "neighbor <A.B.C.D|X:X::X:X|WORD> unsuppress-map WORD",
5720 NEIGHBOR_STR NEIGHBOR_ADDR_STR2
5721 "Route-map to selectively unsuppress suppressed routes\n"
5722 "Name of route map\n")
5723
5724 DEFUN (no_neighbor_unsuppress_map,
5725 no_neighbor_unsuppress_map_cmd,
5726 "no neighbor <A.B.C.D|X:X::X:X|WORD> unsuppress-map WORD",
5727 NO_STR
5728 NEIGHBOR_STR
5729 NEIGHBOR_ADDR_STR2
5730 "Route-map to selectively unsuppress suppressed routes\n"
5731 "Name of route map\n")
5732 {
5733 int idx_peer = 2;
5734 return peer_unsuppress_map_unset_vty(vty, argv[idx_peer]->arg,
5735 bgp_node_afi(vty),
5736 bgp_node_safi(vty));
5737 }
5738
5739 ALIAS_HIDDEN(no_neighbor_unsuppress_map, no_neighbor_unsuppress_map_hidden_cmd,
5740 "no neighbor <A.B.C.D|X:X::X:X|WORD> unsuppress-map WORD",
5741 NO_STR NEIGHBOR_STR NEIGHBOR_ADDR_STR2
5742 "Route-map to selectively unsuppress suppressed routes\n"
5743 "Name of route map\n")
5744
5745 static int peer_maximum_prefix_set_vty(struct vty *vty, const char *ip_str,
5746 afi_t afi, safi_t safi,
5747 const char *num_str,
5748 const char *threshold_str, int warning,
5749 const char *restart_str)
5750 {
5751 int ret;
5752 struct peer *peer;
5753 uint32_t max;
5754 uint8_t threshold;
5755 uint16_t restart;
5756
5757 peer = peer_and_group_lookup_vty(vty, ip_str);
5758 if (!peer)
5759 return CMD_WARNING_CONFIG_FAILED;
5760
5761 max = strtoul(num_str, NULL, 10);
5762 if (threshold_str)
5763 threshold = atoi(threshold_str);
5764 else
5765 threshold = MAXIMUM_PREFIX_THRESHOLD_DEFAULT;
5766
5767 if (restart_str)
5768 restart = atoi(restart_str);
5769 else
5770 restart = 0;
5771
5772 ret = peer_maximum_prefix_set(peer, afi, safi, max, threshold, warning,
5773 restart);
5774
5775 return bgp_vty_return(vty, ret);
5776 }
5777
5778 static int peer_maximum_prefix_unset_vty(struct vty *vty, const char *ip_str,
5779 afi_t afi, safi_t safi)
5780 {
5781 int ret;
5782 struct peer *peer;
5783
5784 peer = peer_and_group_lookup_vty(vty, ip_str);
5785 if (!peer)
5786 return CMD_WARNING_CONFIG_FAILED;
5787
5788 ret = peer_maximum_prefix_unset(peer, afi, safi);
5789
5790 return bgp_vty_return(vty, ret);
5791 }
5792
5793 /* Maximum number of prefix configuration. prefix count is different
5794 for each peer configuration. So this configuration can be set for
5795 each peer configuration. */
5796 DEFUN (neighbor_maximum_prefix,
5797 neighbor_maximum_prefix_cmd,
5798 "neighbor <A.B.C.D|X:X::X:X|WORD> maximum-prefix (1-4294967295)",
5799 NEIGHBOR_STR
5800 NEIGHBOR_ADDR_STR2
5801 "Maximum number of prefix accept from this peer\n"
5802 "maximum no. of prefix limit\n")
5803 {
5804 int idx_peer = 1;
5805 int idx_number = 3;
5806 return peer_maximum_prefix_set_vty(
5807 vty, argv[idx_peer]->arg, bgp_node_afi(vty), bgp_node_safi(vty),
5808 argv[idx_number]->arg, NULL, 0, NULL);
5809 }
5810
5811 ALIAS_HIDDEN(neighbor_maximum_prefix, neighbor_maximum_prefix_hidden_cmd,
5812 "neighbor <A.B.C.D|X:X::X:X|WORD> maximum-prefix (1-4294967295)",
5813 NEIGHBOR_STR NEIGHBOR_ADDR_STR2
5814 "Maximum number of prefix accept from this peer\n"
5815 "maximum no. of prefix limit\n")
5816
5817 DEFUN (neighbor_maximum_prefix_threshold,
5818 neighbor_maximum_prefix_threshold_cmd,
5819 "neighbor <A.B.C.D|X:X::X:X|WORD> maximum-prefix (1-4294967295) (1-100)",
5820 NEIGHBOR_STR
5821 NEIGHBOR_ADDR_STR2
5822 "Maximum number of prefix accept from this peer\n"
5823 "maximum no. of prefix limit\n"
5824 "Threshold value (%) at which to generate a warning msg\n")
5825 {
5826 int idx_peer = 1;
5827 int idx_number = 3;
5828 int idx_number_2 = 4;
5829 return peer_maximum_prefix_set_vty(
5830 vty, argv[idx_peer]->arg, bgp_node_afi(vty), bgp_node_safi(vty),
5831 argv[idx_number]->arg, argv[idx_number_2]->arg, 0, NULL);
5832 }
5833
5834 ALIAS_HIDDEN(
5835 neighbor_maximum_prefix_threshold,
5836 neighbor_maximum_prefix_threshold_hidden_cmd,
5837 "neighbor <A.B.C.D|X:X::X:X|WORD> maximum-prefix (1-4294967295) (1-100)",
5838 NEIGHBOR_STR NEIGHBOR_ADDR_STR2
5839 "Maximum number of prefix accept from this peer\n"
5840 "maximum no. of prefix limit\n"
5841 "Threshold value (%) at which to generate a warning msg\n")
5842
5843 DEFUN (neighbor_maximum_prefix_warning,
5844 neighbor_maximum_prefix_warning_cmd,
5845 "neighbor <A.B.C.D|X:X::X:X|WORD> maximum-prefix (1-4294967295) warning-only",
5846 NEIGHBOR_STR
5847 NEIGHBOR_ADDR_STR2
5848 "Maximum number of prefix accept from this peer\n"
5849 "maximum no. of prefix limit\n"
5850 "Only give warning message when limit is exceeded\n")
5851 {
5852 int idx_peer = 1;
5853 int idx_number = 3;
5854 return peer_maximum_prefix_set_vty(
5855 vty, argv[idx_peer]->arg, bgp_node_afi(vty), bgp_node_safi(vty),
5856 argv[idx_number]->arg, NULL, 1, NULL);
5857 }
5858
5859 ALIAS_HIDDEN(
5860 neighbor_maximum_prefix_warning,
5861 neighbor_maximum_prefix_warning_hidden_cmd,
5862 "neighbor <A.B.C.D|X:X::X:X|WORD> maximum-prefix (1-4294967295) warning-only",
5863 NEIGHBOR_STR NEIGHBOR_ADDR_STR2
5864 "Maximum number of prefix accept from this peer\n"
5865 "maximum no. of prefix limit\n"
5866 "Only give warning message when limit is exceeded\n")
5867
5868 DEFUN (neighbor_maximum_prefix_threshold_warning,
5869 neighbor_maximum_prefix_threshold_warning_cmd,
5870 "neighbor <A.B.C.D|X:X::X:X|WORD> maximum-prefix (1-4294967295) (1-100) warning-only",
5871 NEIGHBOR_STR
5872 NEIGHBOR_ADDR_STR2
5873 "Maximum number of prefix accept from this peer\n"
5874 "maximum no. of prefix limit\n"
5875 "Threshold value (%) at which to generate a warning msg\n"
5876 "Only give warning message when limit is exceeded\n")
5877 {
5878 int idx_peer = 1;
5879 int idx_number = 3;
5880 int idx_number_2 = 4;
5881 return peer_maximum_prefix_set_vty(
5882 vty, argv[idx_peer]->arg, bgp_node_afi(vty), bgp_node_safi(vty),
5883 argv[idx_number]->arg, argv[idx_number_2]->arg, 1, NULL);
5884 }
5885
5886 ALIAS_HIDDEN(
5887 neighbor_maximum_prefix_threshold_warning,
5888 neighbor_maximum_prefix_threshold_warning_hidden_cmd,
5889 "neighbor <A.B.C.D|X:X::X:X|WORD> maximum-prefix (1-4294967295) (1-100) warning-only",
5890 NEIGHBOR_STR NEIGHBOR_ADDR_STR2
5891 "Maximum number of prefix accept from this peer\n"
5892 "maximum no. of prefix limit\n"
5893 "Threshold value (%) at which to generate a warning msg\n"
5894 "Only give warning message when limit is exceeded\n")
5895
5896 DEFUN (neighbor_maximum_prefix_restart,
5897 neighbor_maximum_prefix_restart_cmd,
5898 "neighbor <A.B.C.D|X:X::X:X|WORD> maximum-prefix (1-4294967295) restart (1-65535)",
5899 NEIGHBOR_STR
5900 NEIGHBOR_ADDR_STR2
5901 "Maximum number of prefix accept from this peer\n"
5902 "maximum no. of prefix limit\n"
5903 "Restart bgp connection after limit is exceeded\n"
5904 "Restart interval in minutes\n")
5905 {
5906 int idx_peer = 1;
5907 int idx_number = 3;
5908 int idx_number_2 = 5;
5909 return peer_maximum_prefix_set_vty(
5910 vty, argv[idx_peer]->arg, bgp_node_afi(vty), bgp_node_safi(vty),
5911 argv[idx_number]->arg, NULL, 0, argv[idx_number_2]->arg);
5912 }
5913
5914 ALIAS_HIDDEN(
5915 neighbor_maximum_prefix_restart,
5916 neighbor_maximum_prefix_restart_hidden_cmd,
5917 "neighbor <A.B.C.D|X:X::X:X|WORD> maximum-prefix (1-4294967295) restart (1-65535)",
5918 NEIGHBOR_STR NEIGHBOR_ADDR_STR2
5919 "Maximum number of prefix accept from this peer\n"
5920 "maximum no. of prefix limit\n"
5921 "Restart bgp connection after limit is exceeded\n"
5922 "Restart interval in minutes\n")
5923
5924 DEFUN (neighbor_maximum_prefix_threshold_restart,
5925 neighbor_maximum_prefix_threshold_restart_cmd,
5926 "neighbor <A.B.C.D|X:X::X:X|WORD> maximum-prefix (1-4294967295) (1-100) restart (1-65535)",
5927 NEIGHBOR_STR
5928 NEIGHBOR_ADDR_STR2
5929 "Maximum number of prefixes to accept from this peer\n"
5930 "maximum no. of prefix limit\n"
5931 "Threshold value (%) at which to generate a warning msg\n"
5932 "Restart bgp connection after limit is exceeded\n"
5933 "Restart interval in minutes\n")
5934 {
5935 int idx_peer = 1;
5936 int idx_number = 3;
5937 int idx_number_2 = 4;
5938 int idx_number_3 = 6;
5939 return peer_maximum_prefix_set_vty(
5940 vty, argv[idx_peer]->arg, bgp_node_afi(vty), bgp_node_safi(vty),
5941 argv[idx_number]->arg, argv[idx_number_2]->arg, 0,
5942 argv[idx_number_3]->arg);
5943 }
5944
5945 ALIAS_HIDDEN(
5946 neighbor_maximum_prefix_threshold_restart,
5947 neighbor_maximum_prefix_threshold_restart_hidden_cmd,
5948 "neighbor <A.B.C.D|X:X::X:X|WORD> maximum-prefix (1-4294967295) (1-100) restart (1-65535)",
5949 NEIGHBOR_STR NEIGHBOR_ADDR_STR2
5950 "Maximum number of prefixes to accept from this peer\n"
5951 "maximum no. of prefix limit\n"
5952 "Threshold value (%) at which to generate a warning msg\n"
5953 "Restart bgp connection after limit is exceeded\n"
5954 "Restart interval in minutes\n")
5955
5956 DEFUN (no_neighbor_maximum_prefix,
5957 no_neighbor_maximum_prefix_cmd,
5958 "no neighbor <A.B.C.D|X:X::X:X|WORD> maximum-prefix [(1-4294967295) [(1-100)] [restart (1-65535)] [warning-only]]",
5959 NO_STR
5960 NEIGHBOR_STR
5961 NEIGHBOR_ADDR_STR2
5962 "Maximum number of prefixes to accept from this peer\n"
5963 "maximum no. of prefix limit\n"
5964 "Threshold value (%) at which to generate a warning msg\n"
5965 "Restart bgp connection after limit is exceeded\n"
5966 "Restart interval in minutes\n"
5967 "Only give warning message when limit is exceeded\n")
5968 {
5969 int idx_peer = 2;
5970 return peer_maximum_prefix_unset_vty(vty, argv[idx_peer]->arg,
5971 bgp_node_afi(vty),
5972 bgp_node_safi(vty));
5973 }
5974
5975 ALIAS_HIDDEN(
5976 no_neighbor_maximum_prefix, no_neighbor_maximum_prefix_hidden_cmd,
5977 "no neighbor <A.B.C.D|X:X::X:X|WORD> maximum-prefix [(1-4294967295) [(1-100)] [restart (1-65535)] [warning-only]]",
5978 NO_STR NEIGHBOR_STR NEIGHBOR_ADDR_STR2
5979 "Maximum number of prefixes to accept from this peer\n"
5980 "maximum no. of prefix limit\n"
5981 "Threshold value (%) at which to generate a warning msg\n"
5982 "Restart bgp connection after limit is exceeded\n"
5983 "Restart interval in minutes\n"
5984 "Only give warning message when limit is exceeded\n")
5985
5986
5987 /* "neighbor allowas-in" */
5988 DEFUN (neighbor_allowas_in,
5989 neighbor_allowas_in_cmd,
5990 "neighbor <A.B.C.D|X:X::X:X|WORD> allowas-in [<(1-10)|origin>]",
5991 NEIGHBOR_STR
5992 NEIGHBOR_ADDR_STR2
5993 "Accept as-path with my AS present in it\n"
5994 "Number of occurances of AS number\n"
5995 "Only accept my AS in the as-path if the route was originated in my AS\n")
5996 {
5997 int idx_peer = 1;
5998 int idx_number_origin = 3;
5999 int ret;
6000 int origin = 0;
6001 struct peer *peer;
6002 int allow_num = 0;
6003
6004 peer = peer_and_group_lookup_vty(vty, argv[idx_peer]->arg);
6005 if (!peer)
6006 return CMD_WARNING_CONFIG_FAILED;
6007
6008 if (argc <= idx_number_origin)
6009 allow_num = 3;
6010 else {
6011 if (argv[idx_number_origin]->type == WORD_TKN)
6012 origin = 1;
6013 else
6014 allow_num = atoi(argv[idx_number_origin]->arg);
6015 }
6016
6017 ret = peer_allowas_in_set(peer, bgp_node_afi(vty), bgp_node_safi(vty),
6018 allow_num, origin);
6019
6020 return bgp_vty_return(vty, ret);
6021 }
6022
6023 ALIAS_HIDDEN(
6024 neighbor_allowas_in, neighbor_allowas_in_hidden_cmd,
6025 "neighbor <A.B.C.D|X:X::X:X|WORD> allowas-in [<(1-10)|origin>]",
6026 NEIGHBOR_STR NEIGHBOR_ADDR_STR2
6027 "Accept as-path with my AS present in it\n"
6028 "Number of occurances of AS number\n"
6029 "Only accept my AS in the as-path if the route was originated in my AS\n")
6030
6031 DEFUN (no_neighbor_allowas_in,
6032 no_neighbor_allowas_in_cmd,
6033 "no neighbor <A.B.C.D|X:X::X:X|WORD> allowas-in [<(1-10)|origin>]",
6034 NO_STR
6035 NEIGHBOR_STR
6036 NEIGHBOR_ADDR_STR2
6037 "allow local ASN appears in aspath attribute\n"
6038 "Number of occurances of AS number\n"
6039 "Only accept my AS in the as-path if the route was originated in my AS\n")
6040 {
6041 int idx_peer = 2;
6042 int ret;
6043 struct peer *peer;
6044
6045 peer = peer_and_group_lookup_vty(vty, argv[idx_peer]->arg);
6046 if (!peer)
6047 return CMD_WARNING_CONFIG_FAILED;
6048
6049 ret = peer_allowas_in_unset(peer, bgp_node_afi(vty),
6050 bgp_node_safi(vty));
6051
6052 return bgp_vty_return(vty, ret);
6053 }
6054
6055 ALIAS_HIDDEN(
6056 no_neighbor_allowas_in, no_neighbor_allowas_in_hidden_cmd,
6057 "no neighbor <A.B.C.D|X:X::X:X|WORD> allowas-in [<(1-10)|origin>]",
6058 NO_STR NEIGHBOR_STR NEIGHBOR_ADDR_STR2
6059 "allow local ASN appears in aspath attribute\n"
6060 "Number of occurances of AS number\n"
6061 "Only accept my AS in the as-path if the route was originated in my AS\n")
6062
6063 DEFUN (neighbor_ttl_security,
6064 neighbor_ttl_security_cmd,
6065 "neighbor <A.B.C.D|X:X::X:X|WORD> ttl-security hops (1-254)",
6066 NEIGHBOR_STR
6067 NEIGHBOR_ADDR_STR2
6068 "BGP ttl-security parameters\n"
6069 "Specify the maximum number of hops to the BGP peer\n"
6070 "Number of hops to BGP peer\n")
6071 {
6072 int idx_peer = 1;
6073 int idx_number = 4;
6074 struct peer *peer;
6075 int gtsm_hops;
6076
6077 peer = peer_and_group_lookup_vty(vty, argv[idx_peer]->arg);
6078 if (!peer)
6079 return CMD_WARNING_CONFIG_FAILED;
6080
6081 gtsm_hops = strtoul(argv[idx_number]->arg, NULL, 10);
6082
6083 /*
6084 * If 'neighbor swpX', then this is for directly connected peers,
6085 * we should not accept a ttl-security hops value greater than 1.
6086 */
6087 if (peer->conf_if && (gtsm_hops > 1)) {
6088 vty_out(vty,
6089 "%s is directly connected peer, hops cannot exceed 1\n",
6090 argv[idx_peer]->arg);
6091 return CMD_WARNING_CONFIG_FAILED;
6092 }
6093
6094 return bgp_vty_return(vty, peer_ttl_security_hops_set(peer, gtsm_hops));
6095 }
6096
6097 DEFUN (no_neighbor_ttl_security,
6098 no_neighbor_ttl_security_cmd,
6099 "no neighbor <A.B.C.D|X:X::X:X|WORD> ttl-security hops (1-254)",
6100 NO_STR
6101 NEIGHBOR_STR
6102 NEIGHBOR_ADDR_STR2
6103 "BGP ttl-security parameters\n"
6104 "Specify the maximum number of hops to the BGP peer\n"
6105 "Number of hops to BGP peer\n")
6106 {
6107 int idx_peer = 2;
6108 struct peer *peer;
6109
6110 peer = peer_and_group_lookup_vty(vty, argv[idx_peer]->arg);
6111 if (!peer)
6112 return CMD_WARNING_CONFIG_FAILED;
6113
6114 return bgp_vty_return(vty, peer_ttl_security_hops_unset(peer));
6115 }
6116
6117 DEFUN (neighbor_addpath_tx_all_paths,
6118 neighbor_addpath_tx_all_paths_cmd,
6119 "neighbor <A.B.C.D|X:X::X:X|WORD> addpath-tx-all-paths",
6120 NEIGHBOR_STR
6121 NEIGHBOR_ADDR_STR2
6122 "Use addpath to advertise all paths to a neighbor\n")
6123 {
6124 int idx_peer = 1;
6125 struct peer *peer;
6126
6127 peer = peer_and_group_lookup_vty(vty, argv[idx_peer]->arg);
6128 if (!peer)
6129 return CMD_WARNING_CONFIG_FAILED;
6130
6131 return peer_af_flag_set_vty(vty, argv[idx_peer]->arg, bgp_node_afi(vty),
6132 bgp_node_safi(vty),
6133 PEER_FLAG_ADDPATH_TX_ALL_PATHS);
6134 }
6135
6136 ALIAS_HIDDEN(neighbor_addpath_tx_all_paths,
6137 neighbor_addpath_tx_all_paths_hidden_cmd,
6138 "neighbor <A.B.C.D|X:X::X:X|WORD> addpath-tx-all-paths",
6139 NEIGHBOR_STR NEIGHBOR_ADDR_STR2
6140 "Use addpath to advertise all paths to a neighbor\n")
6141
6142 DEFUN (no_neighbor_addpath_tx_all_paths,
6143 no_neighbor_addpath_tx_all_paths_cmd,
6144 "no neighbor <A.B.C.D|X:X::X:X|WORD> addpath-tx-all-paths",
6145 NO_STR
6146 NEIGHBOR_STR
6147 NEIGHBOR_ADDR_STR2
6148 "Use addpath to advertise all paths to a neighbor\n")
6149 {
6150 int idx_peer = 2;
6151 return peer_af_flag_unset_vty(vty, argv[idx_peer]->arg,
6152 bgp_node_afi(vty), bgp_node_safi(vty),
6153 PEER_FLAG_ADDPATH_TX_ALL_PATHS);
6154 }
6155
6156 ALIAS_HIDDEN(no_neighbor_addpath_tx_all_paths,
6157 no_neighbor_addpath_tx_all_paths_hidden_cmd,
6158 "no neighbor <A.B.C.D|X:X::X:X|WORD> addpath-tx-all-paths",
6159 NO_STR NEIGHBOR_STR NEIGHBOR_ADDR_STR2
6160 "Use addpath to advertise all paths to a neighbor\n")
6161
6162 DEFUN (neighbor_addpath_tx_bestpath_per_as,
6163 neighbor_addpath_tx_bestpath_per_as_cmd,
6164 "neighbor <A.B.C.D|X:X::X:X|WORD> addpath-tx-bestpath-per-AS",
6165 NEIGHBOR_STR
6166 NEIGHBOR_ADDR_STR2
6167 "Use addpath to advertise the bestpath per each neighboring AS\n")
6168 {
6169 int idx_peer = 1;
6170 struct peer *peer;
6171
6172 peer = peer_and_group_lookup_vty(vty, argv[idx_peer]->arg);
6173 if (!peer)
6174 return CMD_WARNING_CONFIG_FAILED;
6175
6176 return peer_af_flag_set_vty(vty, argv[idx_peer]->arg, bgp_node_afi(vty),
6177 bgp_node_safi(vty),
6178 PEER_FLAG_ADDPATH_TX_BESTPATH_PER_AS);
6179 }
6180
6181 ALIAS_HIDDEN(neighbor_addpath_tx_bestpath_per_as,
6182 neighbor_addpath_tx_bestpath_per_as_hidden_cmd,
6183 "neighbor <A.B.C.D|X:X::X:X|WORD> addpath-tx-bestpath-per-AS",
6184 NEIGHBOR_STR NEIGHBOR_ADDR_STR2
6185 "Use addpath to advertise the bestpath per each neighboring AS\n")
6186
6187 DEFUN (no_neighbor_addpath_tx_bestpath_per_as,
6188 no_neighbor_addpath_tx_bestpath_per_as_cmd,
6189 "no neighbor <A.B.C.D|X:X::X:X|WORD> addpath-tx-bestpath-per-AS",
6190 NO_STR
6191 NEIGHBOR_STR
6192 NEIGHBOR_ADDR_STR2
6193 "Use addpath to advertise the bestpath per each neighboring AS\n")
6194 {
6195 int idx_peer = 2;
6196 return peer_af_flag_unset_vty(vty, argv[idx_peer]->arg,
6197 bgp_node_afi(vty), bgp_node_safi(vty),
6198 PEER_FLAG_ADDPATH_TX_BESTPATH_PER_AS);
6199 }
6200
6201 ALIAS_HIDDEN(no_neighbor_addpath_tx_bestpath_per_as,
6202 no_neighbor_addpath_tx_bestpath_per_as_hidden_cmd,
6203 "no neighbor <A.B.C.D|X:X::X:X|WORD> addpath-tx-bestpath-per-AS",
6204 NO_STR NEIGHBOR_STR NEIGHBOR_ADDR_STR2
6205 "Use addpath to advertise the bestpath per each neighboring AS\n")
6206
6207 static int set_ecom_list(struct vty *vty, int argc, struct cmd_token **argv,
6208 struct ecommunity **list)
6209 {
6210 struct ecommunity *ecom = NULL;
6211 struct ecommunity *ecomadd;
6212
6213 for (; argc; --argc, ++argv) {
6214
6215 ecomadd = ecommunity_str2com(argv[0]->arg,
6216 ECOMMUNITY_ROUTE_TARGET, 0);
6217 if (!ecomadd) {
6218 vty_out(vty, "Malformed community-list value\n");
6219 if (ecom)
6220 ecommunity_free(&ecom);
6221 return CMD_WARNING_CONFIG_FAILED;
6222 }
6223
6224 if (ecom) {
6225 ecommunity_merge(ecom, ecomadd);
6226 ecommunity_free(&ecomadd);
6227 } else {
6228 ecom = ecomadd;
6229 }
6230 }
6231
6232 if (*list) {
6233 ecommunity_free(&*list);
6234 }
6235 *list = ecom;
6236
6237 return CMD_SUCCESS;
6238 }
6239
6240 /*
6241 * v2vimport is true if we are handling a `import vrf ...` command
6242 */
6243 static afi_t vpn_policy_getafi(struct vty *vty, struct bgp *bgp, bool v2vimport)
6244 {
6245 afi_t afi;
6246
6247 switch (vty->node) {
6248 case BGP_IPV4_NODE:
6249 afi = AFI_IP;
6250 break;
6251 case BGP_IPV6_NODE:
6252 afi = AFI_IP6;
6253 break;
6254 default:
6255 vty_out(vty,
6256 "%% context error: valid only in address-family <ipv4|ipv6> unicast block\n");
6257 return AFI_MAX;
6258 }
6259
6260 if (!v2vimport) {
6261 if (CHECK_FLAG(bgp->af_flags[afi][SAFI_UNICAST],
6262 BGP_CONFIG_VRF_TO_VRF_IMPORT)
6263 || CHECK_FLAG(bgp->af_flags[afi][SAFI_UNICAST],
6264 BGP_CONFIG_VRF_TO_VRF_EXPORT)) {
6265 vty_out(vty,
6266 "%% error: Please unconfigure import vrf commands before using vpn commands\n");
6267 return AFI_MAX;
6268 }
6269 } else {
6270 if (CHECK_FLAG(bgp->af_flags[afi][SAFI_UNICAST],
6271 BGP_CONFIG_VRF_TO_MPLSVPN_EXPORT)
6272 || CHECK_FLAG(bgp->af_flags[afi][SAFI_UNICAST],
6273 BGP_CONFIG_MPLSVPN_TO_VRF_IMPORT)) {
6274 vty_out(vty,
6275 "%% error: Please unconfigure vpn to vrf commands before using import vrf commands\n");
6276 return AFI_MAX;
6277 }
6278 }
6279 return afi;
6280 }
6281
6282 DEFPY (af_rd_vpn_export,
6283 af_rd_vpn_export_cmd,
6284 "[no] rd vpn export ASN:NN_OR_IP-ADDRESS:NN$rd_str",
6285 NO_STR
6286 "Specify route distinguisher\n"
6287 "Between current address-family and vpn\n"
6288 "For routes leaked from current address-family to vpn\n"
6289 "Route Distinguisher (<as-number>:<number> | <ip-address>:<number>)\n")
6290 {
6291 VTY_DECLVAR_CONTEXT(bgp, bgp);
6292 struct prefix_rd prd;
6293 int ret;
6294 afi_t afi;
6295 int idx = 0;
6296 int yes = 1;
6297
6298 if (argv_find(argv, argc, "no", &idx))
6299 yes = 0;
6300
6301 if (yes) {
6302 ret = str2prefix_rd(rd_str, &prd);
6303 if (!ret) {
6304 vty_out(vty, "%% Malformed rd\n");
6305 return CMD_WARNING_CONFIG_FAILED;
6306 }
6307 }
6308
6309 afi = vpn_policy_getafi(vty, bgp, false);
6310 if (afi == AFI_MAX)
6311 return CMD_WARNING_CONFIG_FAILED;
6312
6313 /*
6314 * pre-change: un-export vpn routes (vpn->vrf routes unaffected)
6315 */
6316 vpn_leak_prechange(BGP_VPN_POLICY_DIR_TOVPN, afi,
6317 bgp_get_default(), bgp);
6318
6319 if (yes) {
6320 bgp->vpn_policy[afi].tovpn_rd = prd;
6321 SET_FLAG(bgp->vpn_policy[afi].flags,
6322 BGP_VPN_POLICY_TOVPN_RD_SET);
6323 } else {
6324 UNSET_FLAG(bgp->vpn_policy[afi].flags,
6325 BGP_VPN_POLICY_TOVPN_RD_SET);
6326 }
6327
6328 /* post-change: re-export vpn routes */
6329 vpn_leak_postchange(BGP_VPN_POLICY_DIR_TOVPN, afi,
6330 bgp_get_default(), bgp);
6331
6332 return CMD_SUCCESS;
6333 }
6334
6335 ALIAS (af_rd_vpn_export,
6336 af_no_rd_vpn_export_cmd,
6337 "no rd vpn export",
6338 NO_STR
6339 "Specify route distinguisher\n"
6340 "Between current address-family and vpn\n"
6341 "For routes leaked from current address-family to vpn\n")
6342
6343 DEFPY (af_label_vpn_export,
6344 af_label_vpn_export_cmd,
6345 "[no] label vpn export <(0-1048575)$label_val|auto$label_auto>",
6346 NO_STR
6347 "label value for VRF\n"
6348 "Between current address-family and vpn\n"
6349 "For routes leaked from current address-family to vpn\n"
6350 "Label Value <0-1048575>\n"
6351 "Automatically assign a label\n")
6352 {
6353 VTY_DECLVAR_CONTEXT(bgp, bgp);
6354 mpls_label_t label = MPLS_LABEL_NONE;
6355 afi_t afi;
6356 int idx = 0;
6357 int yes = 1;
6358
6359 if (argv_find(argv, argc, "no", &idx))
6360 yes = 0;
6361
6362 /* If "no ...", squash trailing parameter */
6363 if (!yes)
6364 label_auto = NULL;
6365
6366 if (yes) {
6367 if (!label_auto)
6368 label = label_val; /* parser should force unsigned */
6369 }
6370
6371 afi = vpn_policy_getafi(vty, bgp, false);
6372 if (afi == AFI_MAX)
6373 return CMD_WARNING_CONFIG_FAILED;
6374
6375
6376 if (label_auto && CHECK_FLAG(bgp->vpn_policy[afi].flags,
6377 BGP_VPN_POLICY_TOVPN_LABEL_AUTO))
6378 /* no change */
6379 return CMD_SUCCESS;
6380
6381 /*
6382 * pre-change: un-export vpn routes (vpn->vrf routes unaffected)
6383 */
6384 vpn_leak_prechange(BGP_VPN_POLICY_DIR_TOVPN, afi,
6385 bgp_get_default(), bgp);
6386
6387 if (!label_auto && CHECK_FLAG(bgp->vpn_policy[afi].flags,
6388 BGP_VPN_POLICY_TOVPN_LABEL_AUTO)) {
6389
6390 if (bgp->vpn_policy[afi].tovpn_label != MPLS_LABEL_NONE) {
6391
6392 /*
6393 * label has previously been automatically
6394 * assigned by labelpool: release it
6395 *
6396 * NB if tovpn_label == MPLS_LABEL_NONE it
6397 * means the automatic assignment is in flight
6398 * and therefore the labelpool callback must
6399 * detect that the auto label is not needed.
6400 */
6401
6402 bgp_lp_release(LP_TYPE_VRF,
6403 &bgp->vpn_policy[afi],
6404 bgp->vpn_policy[afi].tovpn_label);
6405 }
6406 UNSET_FLAG(bgp->vpn_policy[afi].flags,
6407 BGP_VPN_POLICY_TOVPN_LABEL_AUTO);
6408 }
6409
6410 bgp->vpn_policy[afi].tovpn_label = label;
6411 if (label_auto) {
6412 SET_FLAG(bgp->vpn_policy[afi].flags,
6413 BGP_VPN_POLICY_TOVPN_LABEL_AUTO);
6414 bgp_lp_get(LP_TYPE_VRF, &bgp->vpn_policy[afi],
6415 vpn_leak_label_callback);
6416 }
6417
6418 /* post-change: re-export vpn routes */
6419 vpn_leak_postchange(BGP_VPN_POLICY_DIR_TOVPN, afi,
6420 bgp_get_default(), bgp);
6421
6422 return CMD_SUCCESS;
6423 }
6424
6425 ALIAS (af_label_vpn_export,
6426 af_no_label_vpn_export_cmd,
6427 "no label vpn export",
6428 NO_STR
6429 "label value for VRF\n"
6430 "Between current address-family and vpn\n"
6431 "For routes leaked from current address-family to vpn\n")
6432
6433 DEFPY (af_nexthop_vpn_export,
6434 af_nexthop_vpn_export_cmd,
6435 "[no] nexthop vpn export <A.B.C.D|X:X::X:X>$nexthop_str",
6436 NO_STR
6437 "Specify next hop to use for VRF advertised prefixes\n"
6438 "Between current address-family and vpn\n"
6439 "For routes leaked from current address-family to vpn\n"
6440 "IPv4 prefix\n"
6441 "IPv6 prefix\n")
6442 {
6443 VTY_DECLVAR_CONTEXT(bgp, bgp);
6444 afi_t afi;
6445 struct prefix p;
6446 int idx = 0;
6447 int yes = 1;
6448
6449 if (argv_find(argv, argc, "no", &idx))
6450 yes = 0;
6451
6452 if (yes) {
6453 if (!sockunion2hostprefix(nexthop_str, &p))
6454 return CMD_WARNING_CONFIG_FAILED;
6455 }
6456
6457 afi = vpn_policy_getafi(vty, bgp, false);
6458 if (afi == AFI_MAX)
6459 return CMD_WARNING_CONFIG_FAILED;
6460
6461 /*
6462 * pre-change: un-export vpn routes (vpn->vrf routes unaffected)
6463 */
6464 vpn_leak_prechange(BGP_VPN_POLICY_DIR_TOVPN, afi,
6465 bgp_get_default(), bgp);
6466
6467 if (yes) {
6468 bgp->vpn_policy[afi].tovpn_nexthop = p;
6469 SET_FLAG(bgp->vpn_policy[afi].flags,
6470 BGP_VPN_POLICY_TOVPN_NEXTHOP_SET);
6471 } else {
6472 UNSET_FLAG(bgp->vpn_policy[afi].flags,
6473 BGP_VPN_POLICY_TOVPN_NEXTHOP_SET);
6474 }
6475
6476 /* post-change: re-export vpn routes */
6477 vpn_leak_postchange(BGP_VPN_POLICY_DIR_TOVPN, afi,
6478 bgp_get_default(), bgp);
6479
6480 return CMD_SUCCESS;
6481 }
6482
6483 ALIAS (af_nexthop_vpn_export,
6484 af_no_nexthop_vpn_export_cmd,
6485 "no nexthop vpn export",
6486 NO_STR
6487 "Specify next hop to use for VRF advertised prefixes\n"
6488 "Between current address-family and vpn\n"
6489 "For routes leaked from current address-family to vpn\n")
6490
6491 static int vpn_policy_getdirs(struct vty *vty, const char *dstr, int *dodir)
6492 {
6493 if (!strcmp(dstr, "import")) {
6494 dodir[BGP_VPN_POLICY_DIR_FROMVPN] = 1;
6495 } else if (!strcmp(dstr, "export")) {
6496 dodir[BGP_VPN_POLICY_DIR_TOVPN] = 1;
6497 } else if (!strcmp(dstr, "both")) {
6498 dodir[BGP_VPN_POLICY_DIR_FROMVPN] = 1;
6499 dodir[BGP_VPN_POLICY_DIR_TOVPN] = 1;
6500 } else {
6501 vty_out(vty, "%% direction parse error\n");
6502 return CMD_WARNING_CONFIG_FAILED;
6503 }
6504 return CMD_SUCCESS;
6505 }
6506
6507 DEFPY (af_rt_vpn_imexport,
6508 af_rt_vpn_imexport_cmd,
6509 "[no] <rt|route-target> vpn <import|export|both>$direction_str RTLIST...",
6510 NO_STR
6511 "Specify route target list\n"
6512 "Specify route target list\n"
6513 "Between current address-family and vpn\n"
6514 "For routes leaked from vpn to current address-family: match any\n"
6515 "For routes leaked from current address-family to vpn: set\n"
6516 "both import: match any and export: set\n"
6517 "Space separated route target list (A.B.C.D:MN|EF:OPQR|GHJK:MN)\n")
6518 {
6519 VTY_DECLVAR_CONTEXT(bgp, bgp);
6520 int ret;
6521 struct ecommunity *ecom = NULL;
6522 int dodir[BGP_VPN_POLICY_DIR_MAX] = {0};
6523 vpn_policy_direction_t dir;
6524 afi_t afi;
6525 int idx = 0;
6526 int yes = 1;
6527
6528 if (argv_find(argv, argc, "no", &idx))
6529 yes = 0;
6530
6531 afi = vpn_policy_getafi(vty, bgp, false);
6532 if (afi == AFI_MAX)
6533 return CMD_WARNING_CONFIG_FAILED;
6534
6535 ret = vpn_policy_getdirs(vty, direction_str, dodir);
6536 if (ret != CMD_SUCCESS)
6537 return ret;
6538
6539 if (yes) {
6540 if (!argv_find(argv, argc, "RTLIST", &idx)) {
6541 vty_out(vty, "%% Missing RTLIST\n");
6542 return CMD_WARNING_CONFIG_FAILED;
6543 }
6544 ret = set_ecom_list(vty, argc - idx, argv + idx, &ecom);
6545 if (ret != CMD_SUCCESS) {
6546 return ret;
6547 }
6548 }
6549
6550 for (dir = 0; dir < BGP_VPN_POLICY_DIR_MAX; ++dir) {
6551 if (!dodir[dir])
6552 continue;
6553
6554 vpn_leak_prechange(dir, afi, bgp_get_default(), bgp);
6555
6556 if (yes) {
6557 if (bgp->vpn_policy[afi].rtlist[dir])
6558 ecommunity_free(
6559 &bgp->vpn_policy[afi].rtlist[dir]);
6560 bgp->vpn_policy[afi].rtlist[dir] =
6561 ecommunity_dup(ecom);
6562 } else {
6563 if (bgp->vpn_policy[afi].rtlist[dir])
6564 ecommunity_free(
6565 &bgp->vpn_policy[afi].rtlist[dir]);
6566 bgp->vpn_policy[afi].rtlist[dir] = NULL;
6567 }
6568
6569 vpn_leak_postchange(dir, afi, bgp_get_default(), bgp);
6570 }
6571
6572 if (ecom)
6573 ecommunity_free(&ecom);
6574
6575 return CMD_SUCCESS;
6576 }
6577
6578 ALIAS (af_rt_vpn_imexport,
6579 af_no_rt_vpn_imexport_cmd,
6580 "no <rt|route-target> vpn <import|export|both>$direction_str",
6581 NO_STR
6582 "Specify route target list\n"
6583 "Specify route target list\n"
6584 "Between current address-family and vpn\n"
6585 "For routes leaked from vpn to current address-family\n"
6586 "For routes leaked from current address-family to vpn\n"
6587 "both import and export\n")
6588
6589 DEFPY (af_route_map_vpn_imexport,
6590 af_route_map_vpn_imexport_cmd,
6591 /* future: "route-map <vpn|evpn|vrf NAME> <import|export> RMAP" */
6592 "[no] route-map vpn <import|export>$direction_str RMAP$rmap_str",
6593 NO_STR
6594 "Specify route map\n"
6595 "Between current address-family and vpn\n"
6596 "For routes leaked from vpn to current address-family\n"
6597 "For routes leaked from current address-family to vpn\n"
6598 "name of route-map\n")
6599 {
6600 VTY_DECLVAR_CONTEXT(bgp, bgp);
6601 int ret;
6602 int dodir[BGP_VPN_POLICY_DIR_MAX] = {0};
6603 vpn_policy_direction_t dir;
6604 afi_t afi;
6605 int idx = 0;
6606 int yes = 1;
6607
6608 if (argv_find(argv, argc, "no", &idx))
6609 yes = 0;
6610
6611 afi = vpn_policy_getafi(vty, bgp, false);
6612 if (afi == AFI_MAX)
6613 return CMD_WARNING_CONFIG_FAILED;
6614
6615 ret = vpn_policy_getdirs(vty, direction_str, dodir);
6616 if (ret != CMD_SUCCESS)
6617 return ret;
6618
6619 for (dir = 0; dir < BGP_VPN_POLICY_DIR_MAX; ++dir) {
6620 if (!dodir[dir])
6621 continue;
6622
6623 vpn_leak_prechange(dir, afi, bgp_get_default(), bgp);
6624
6625 if (yes) {
6626 if (bgp->vpn_policy[afi].rmap_name[dir])
6627 XFREE(MTYPE_ROUTE_MAP_NAME,
6628 bgp->vpn_policy[afi].rmap_name[dir]);
6629 bgp->vpn_policy[afi].rmap_name[dir] = XSTRDUP(
6630 MTYPE_ROUTE_MAP_NAME, rmap_str);
6631 bgp->vpn_policy[afi].rmap[dir] =
6632 route_map_lookup_by_name(rmap_str);
6633 if (!bgp->vpn_policy[afi].rmap[dir])
6634 return CMD_SUCCESS;
6635 } else {
6636 if (bgp->vpn_policy[afi].rmap_name[dir])
6637 XFREE(MTYPE_ROUTE_MAP_NAME,
6638 bgp->vpn_policy[afi].rmap_name[dir]);
6639 bgp->vpn_policy[afi].rmap_name[dir] = NULL;
6640 bgp->vpn_policy[afi].rmap[dir] = NULL;
6641 }
6642
6643 vpn_leak_postchange(dir, afi, bgp_get_default(), bgp);
6644 }
6645
6646 return CMD_SUCCESS;
6647 }
6648
6649 ALIAS (af_route_map_vpn_imexport,
6650 af_no_route_map_vpn_imexport_cmd,
6651 "no route-map vpn <import|export>$direction_str",
6652 NO_STR
6653 "Specify route map\n"
6654 "Between current address-family and vpn\n"
6655 "For routes leaked from vpn to current address-family\n"
6656 "For routes leaked from current address-family to vpn\n")
6657
6658 DEFPY(af_import_vrf_route_map, af_import_vrf_route_map_cmd,
6659 "[no] import vrf route-map RMAP$rmap_str",
6660 NO_STR
6661 "Import routes from another VRF\n"
6662 "Vrf routes being filtered\n"
6663 "Specify route map\n"
6664 "name of route-map\n")
6665 {
6666 VTY_DECLVAR_CONTEXT(bgp, bgp);
6667 vpn_policy_direction_t dir = BGP_VPN_POLICY_DIR_FROMVPN;
6668 afi_t afi;
6669 int idx = 0;
6670 int yes = 1;
6671 struct bgp *bgp_default;
6672
6673 if (argv_find(argv, argc, "no", &idx))
6674 yes = 0;
6675
6676 afi = vpn_policy_getafi(vty, bgp, true);
6677 if (afi == AFI_MAX)
6678 return CMD_WARNING_CONFIG_FAILED;
6679
6680 bgp_default = bgp_get_default();
6681 if (!bgp_default) {
6682 int32_t ret;
6683 as_t as = bgp->as;
6684
6685 /* Auto-create assuming the same AS */
6686 ret = bgp_get(&bgp_default, &as, NULL,
6687 BGP_INSTANCE_TYPE_DEFAULT);
6688
6689 if (ret) {
6690 vty_out(vty,
6691 "VRF default is not configured as a bgp instance\n");
6692 return CMD_WARNING;
6693 }
6694 }
6695
6696 vpn_leak_prechange(dir, afi, bgp_get_default(), bgp);
6697
6698 if (yes) {
6699 if (bgp->vpn_policy[afi].rmap_name[dir])
6700 XFREE(MTYPE_ROUTE_MAP_NAME,
6701 bgp->vpn_policy[afi].rmap_name[dir]);
6702 bgp->vpn_policy[afi].rmap_name[dir] =
6703 XSTRDUP(MTYPE_ROUTE_MAP_NAME, rmap_str);
6704 bgp->vpn_policy[afi].rmap[dir] =
6705 route_map_lookup_by_name(rmap_str);
6706 if (!bgp->vpn_policy[afi].rmap[dir])
6707 return CMD_SUCCESS;
6708 } else {
6709 if (bgp->vpn_policy[afi].rmap_name[dir])
6710 XFREE(MTYPE_ROUTE_MAP_NAME,
6711 bgp->vpn_policy[afi].rmap_name[dir]);
6712 bgp->vpn_policy[afi].rmap_name[dir] = NULL;
6713 bgp->vpn_policy[afi].rmap[dir] = NULL;
6714 }
6715
6716 vpn_leak_postchange(dir, afi, bgp_get_default(), bgp);
6717
6718 return CMD_SUCCESS;
6719 }
6720
6721 ALIAS(af_import_vrf_route_map, af_no_import_vrf_route_map_cmd,
6722 "no import vrf route-map",
6723 NO_STR
6724 "Import routes from another VRF\n"
6725 "Vrf routes being filtered\n"
6726 "Specify route map\n")
6727
6728 DEFPY (bgp_imexport_vrf,
6729 bgp_imexport_vrf_cmd,
6730 "[no] import vrf NAME$import_name",
6731 NO_STR
6732 "Import routes from another VRF\n"
6733 "VRF to import from\n"
6734 "The name of the VRF\n")
6735 {
6736 VTY_DECLVAR_CONTEXT(bgp, bgp);
6737 struct listnode *node;
6738 struct bgp *vrf_bgp, *bgp_default;
6739 int32_t ret = 0;
6740 as_t as = bgp->as;
6741 bool remove = false;
6742 int32_t idx = 0;
6743 char *vname;
6744 enum bgp_instance_type bgp_type = BGP_INSTANCE_TYPE_VRF;
6745 safi_t safi;
6746 afi_t afi;
6747
6748 if (argv_find(argv, argc, "no", &idx))
6749 remove = true;
6750
6751 afi = vpn_policy_getafi(vty, bgp, true);
6752 if (afi == AFI_MAX)
6753 return CMD_WARNING_CONFIG_FAILED;
6754
6755 safi = bgp_node_safi(vty);
6756
6757 if (((BGP_INSTANCE_TYPE_DEFAULT == bgp->inst_type)
6758 && (strcmp(import_name, BGP_DEFAULT_NAME) == 0))
6759 || (bgp->name && (strcmp(import_name, bgp->name) == 0))) {
6760 vty_out(vty, "%% Cannot %s vrf %s into itself\n",
6761 remove ? "unimport" : "import", import_name);
6762 return CMD_WARNING;
6763 }
6764
6765 bgp_default = bgp_get_default();
6766 if (!bgp_default) {
6767 /* Auto-create assuming the same AS */
6768 ret = bgp_get(&bgp_default, &as, NULL,
6769 BGP_INSTANCE_TYPE_DEFAULT);
6770
6771 if (ret) {
6772 vty_out(vty,
6773 "VRF default is not configured as a bgp instance\n");
6774 return CMD_WARNING;
6775 }
6776 }
6777
6778 vrf_bgp = bgp_lookup_by_name(import_name);
6779 if (!vrf_bgp) {
6780 if (strcmp(import_name, BGP_DEFAULT_NAME) == 0)
6781 vrf_bgp = bgp_default;
6782 else
6783 /* Auto-create assuming the same AS */
6784 ret = bgp_get(&vrf_bgp, &as, import_name, bgp_type);
6785
6786 if (ret) {
6787 vty_out(vty,
6788 "VRF %s is not configured as a bgp instance\n",
6789 import_name);
6790 return CMD_WARNING;
6791 }
6792 }
6793
6794 if (remove) {
6795 vrf_unimport_from_vrf(bgp, vrf_bgp, afi, safi);
6796 } else {
6797 /* Already importing from "import_vrf"? */
6798 for (ALL_LIST_ELEMENTS_RO(bgp->vpn_policy[afi].import_vrf, node,
6799 vname)) {
6800 if (strcmp(vname, import_name) == 0)
6801 return CMD_WARNING;
6802 }
6803
6804 vrf_import_from_vrf(bgp, vrf_bgp, afi, safi);
6805 }
6806
6807 return CMD_SUCCESS;
6808 }
6809
6810 /* This command is valid only in a bgp vrf instance or the default instance */
6811 DEFPY (bgp_imexport_vpn,
6812 bgp_imexport_vpn_cmd,
6813 "[no] <import|export>$direction_str vpn",
6814 NO_STR
6815 "Import routes to this address-family\n"
6816 "Export routes from this address-family\n"
6817 "to/from default instance VPN RIB\n")
6818 {
6819 VTY_DECLVAR_CONTEXT(bgp, bgp);
6820 int previous_state;
6821 afi_t afi;
6822 safi_t safi;
6823 int idx = 0;
6824 int yes = 1;
6825 int flag;
6826 vpn_policy_direction_t dir;
6827
6828 if (argv_find(argv, argc, "no", &idx))
6829 yes = 0;
6830
6831 if (BGP_INSTANCE_TYPE_VRF != bgp->inst_type &&
6832 BGP_INSTANCE_TYPE_DEFAULT != bgp->inst_type) {
6833
6834 vty_out(vty, "%% import|export vpn valid only for bgp vrf or default instance\n");
6835 return CMD_WARNING_CONFIG_FAILED;
6836 }
6837
6838 afi = bgp_node_afi(vty);
6839 safi = bgp_node_safi(vty);
6840 if ((SAFI_UNICAST != safi) || ((AFI_IP != afi) && (AFI_IP6 != afi))) {
6841 vty_out(vty, "%% import|export vpn valid only for unicast ipv4|ipv6\n");
6842 return CMD_WARNING_CONFIG_FAILED;
6843 }
6844
6845 if (!strcmp(direction_str, "import")) {
6846 flag = BGP_CONFIG_MPLSVPN_TO_VRF_IMPORT;
6847 dir = BGP_VPN_POLICY_DIR_FROMVPN;
6848 } else if (!strcmp(direction_str, "export")) {
6849 flag = BGP_CONFIG_VRF_TO_MPLSVPN_EXPORT;
6850 dir = BGP_VPN_POLICY_DIR_TOVPN;
6851 } else {
6852 vty_out(vty, "%% unknown direction %s\n", direction_str);
6853 return CMD_WARNING_CONFIG_FAILED;
6854 }
6855
6856 previous_state = CHECK_FLAG(bgp->af_flags[afi][safi], flag);
6857
6858 if (yes) {
6859 SET_FLAG(bgp->af_flags[afi][safi], flag);
6860 if (!previous_state) {
6861 /* trigger export current vrf */
6862 vpn_leak_postchange(dir, afi, bgp_get_default(), bgp);
6863 }
6864 } else {
6865 if (previous_state) {
6866 /* trigger un-export current vrf */
6867 vpn_leak_prechange(dir, afi, bgp_get_default(), bgp);
6868 }
6869 UNSET_FLAG(bgp->af_flags[afi][safi], flag);
6870 }
6871
6872 return CMD_SUCCESS;
6873 }
6874
6875 DEFPY (af_routetarget_import,
6876 af_routetarget_import_cmd,
6877 "[no] <rt|route-target> redirect import RTLIST...",
6878 NO_STR
6879 "Specify route target list\n"
6880 "Specify route target list\n"
6881 "Flow-spec redirect type route target\n"
6882 "Import routes to this address-family\n"
6883 "Space separated route target list (A.B.C.D:MN|EF:OPQR|GHJK:MN)\n")
6884 {
6885 VTY_DECLVAR_CONTEXT(bgp, bgp);
6886 int ret;
6887 struct ecommunity *ecom = NULL;
6888 afi_t afi;
6889 int idx = 0;
6890 int yes = 1;
6891
6892 if (argv_find(argv, argc, "no", &idx))
6893 yes = 0;
6894
6895 afi = vpn_policy_getafi(vty, bgp, false);
6896 if (afi == AFI_MAX)
6897 return CMD_WARNING_CONFIG_FAILED;
6898
6899 if (yes) {
6900 if (!argv_find(argv, argc, "RTLIST", &idx)) {
6901 vty_out(vty, "%% Missing RTLIST\n");
6902 return CMD_WARNING_CONFIG_FAILED;
6903 }
6904 ret = set_ecom_list(vty, argc - idx, argv + idx, &ecom);
6905 if (ret != CMD_SUCCESS)
6906 return ret;
6907 }
6908
6909 if (yes) {
6910 if (bgp->vpn_policy[afi].import_redirect_rtlist)
6911 ecommunity_free(&bgp->vpn_policy[afi]
6912 .import_redirect_rtlist);
6913 bgp->vpn_policy[afi].import_redirect_rtlist =
6914 ecommunity_dup(ecom);
6915 } else {
6916 if (bgp->vpn_policy[afi].import_redirect_rtlist)
6917 ecommunity_free(&bgp->vpn_policy[afi]
6918 .import_redirect_rtlist);
6919 bgp->vpn_policy[afi].import_redirect_rtlist = NULL;
6920 }
6921
6922 if (ecom)
6923 ecommunity_free(&ecom);
6924
6925 return CMD_SUCCESS;
6926 }
6927
6928 DEFUN_NOSH (address_family_ipv4_safi,
6929 address_family_ipv4_safi_cmd,
6930 "address-family ipv4 [<unicast|multicast|vpn|labeled-unicast|flowspec>]",
6931 "Enter Address Family command mode\n"
6932 "Address Family\n"
6933 BGP_SAFI_WITH_LABEL_HELP_STR)
6934 {
6935
6936 if (argc == 3) {
6937 VTY_DECLVAR_CONTEXT(bgp, bgp);
6938 safi_t safi = bgp_vty_safi_from_str(argv[2]->text);
6939 if (bgp->inst_type != BGP_INSTANCE_TYPE_DEFAULT
6940 && safi != SAFI_UNICAST && safi != SAFI_MULTICAST
6941 && safi != SAFI_EVPN) {
6942 vty_out(vty,
6943 "Only Unicast/Multicast/EVPN SAFIs supported in non-core instances.\n");
6944 return CMD_WARNING_CONFIG_FAILED;
6945 }
6946 vty->node = bgp_node_type(AFI_IP, safi);
6947 } else
6948 vty->node = BGP_IPV4_NODE;
6949
6950 return CMD_SUCCESS;
6951 }
6952
6953 DEFUN_NOSH (address_family_ipv6_safi,
6954 address_family_ipv6_safi_cmd,
6955 "address-family ipv6 [<unicast|multicast|vpn|labeled-unicast|flowspec>]",
6956 "Enter Address Family command mode\n"
6957 "Address Family\n"
6958 BGP_SAFI_WITH_LABEL_HELP_STR)
6959 {
6960 if (argc == 3) {
6961 VTY_DECLVAR_CONTEXT(bgp, bgp);
6962 safi_t safi = bgp_vty_safi_from_str(argv[2]->text);
6963 if (bgp->inst_type != BGP_INSTANCE_TYPE_DEFAULT
6964 && safi != SAFI_UNICAST && safi != SAFI_MULTICAST
6965 && safi != SAFI_EVPN) {
6966 vty_out(vty,
6967 "Only Unicast/Multicast/EVPN SAFIs supported in non-core instances.\n");
6968 return CMD_WARNING_CONFIG_FAILED;
6969 }
6970 vty->node = bgp_node_type(AFI_IP6, safi);
6971 } else
6972 vty->node = BGP_IPV6_NODE;
6973
6974 return CMD_SUCCESS;
6975 }
6976
6977 #ifdef KEEP_OLD_VPN_COMMANDS
6978 DEFUN_NOSH (address_family_vpnv4,
6979 address_family_vpnv4_cmd,
6980 "address-family vpnv4 [unicast]",
6981 "Enter Address Family command mode\n"
6982 "Address Family\n"
6983 "Address Family modifier\n")
6984 {
6985 vty->node = BGP_VPNV4_NODE;
6986 return CMD_SUCCESS;
6987 }
6988
6989 DEFUN_NOSH (address_family_vpnv6,
6990 address_family_vpnv6_cmd,
6991 "address-family vpnv6 [unicast]",
6992 "Enter Address Family command mode\n"
6993 "Address Family\n"
6994 "Address Family modifier\n")
6995 {
6996 vty->node = BGP_VPNV6_NODE;
6997 return CMD_SUCCESS;
6998 }
6999 #endif
7000
7001 DEFUN_NOSH (address_family_evpn,
7002 address_family_evpn_cmd,
7003 "address-family l2vpn evpn",
7004 "Enter Address Family command mode\n"
7005 "Address Family\n"
7006 "Address Family modifier\n")
7007 {
7008 VTY_DECLVAR_CONTEXT(bgp, bgp);
7009 vty->node = BGP_EVPN_NODE;
7010 return CMD_SUCCESS;
7011 }
7012
7013 DEFUN_NOSH (exit_address_family,
7014 exit_address_family_cmd,
7015 "exit-address-family",
7016 "Exit from Address Family configuration mode\n")
7017 {
7018 if (vty->node == BGP_IPV4_NODE || vty->node == BGP_IPV4M_NODE
7019 || vty->node == BGP_IPV4L_NODE || vty->node == BGP_VPNV4_NODE
7020 || vty->node == BGP_IPV6_NODE || vty->node == BGP_IPV6M_NODE
7021 || vty->node == BGP_IPV6L_NODE || vty->node == BGP_VPNV6_NODE
7022 || vty->node == BGP_EVPN_NODE
7023 || vty->node == BGP_FLOWSPECV4_NODE
7024 || vty->node == BGP_FLOWSPECV6_NODE)
7025 vty->node = BGP_NODE;
7026 return CMD_SUCCESS;
7027 }
7028
7029 /* Recalculate bestpath and re-advertise a prefix */
7030 static int bgp_clear_prefix(struct vty *vty, const char *view_name,
7031 const char *ip_str, afi_t afi, safi_t safi,
7032 struct prefix_rd *prd)
7033 {
7034 int ret;
7035 struct prefix match;
7036 struct bgp_node *rn;
7037 struct bgp_node *rm;
7038 struct bgp *bgp;
7039 struct bgp_table *table;
7040 struct bgp_table *rib;
7041
7042 /* BGP structure lookup. */
7043 if (view_name) {
7044 bgp = bgp_lookup_by_name(view_name);
7045 if (bgp == NULL) {
7046 vty_out(vty, "%% Can't find BGP instance %s\n",
7047 view_name);
7048 return CMD_WARNING;
7049 }
7050 } else {
7051 bgp = bgp_get_default();
7052 if (bgp == NULL) {
7053 vty_out(vty, "%% No BGP process is configured\n");
7054 return CMD_WARNING;
7055 }
7056 }
7057
7058 /* Check IP address argument. */
7059 ret = str2prefix(ip_str, &match);
7060 if (!ret) {
7061 vty_out(vty, "%% address is malformed\n");
7062 return CMD_WARNING;
7063 }
7064
7065 match.family = afi2family(afi);
7066 rib = bgp->rib[afi][safi];
7067
7068 if (safi == SAFI_MPLS_VPN) {
7069 for (rn = bgp_table_top(rib); rn; rn = bgp_route_next(rn)) {
7070 if (prd && memcmp(rn->p.u.val, prd->val, 8) != 0)
7071 continue;
7072
7073 if ((table = rn->info) != NULL) {
7074 if ((rm = bgp_node_match(table, &match))
7075 != NULL) {
7076 if (rm->p.prefixlen
7077 == match.prefixlen) {
7078 SET_FLAG(rn->flags,
7079 BGP_NODE_USER_CLEAR);
7080 bgp_process(bgp, rm, afi, safi);
7081 }
7082 bgp_unlock_node(rm);
7083 }
7084 }
7085 }
7086 } else {
7087 if ((rn = bgp_node_match(rib, &match)) != NULL) {
7088 if (rn->p.prefixlen == match.prefixlen) {
7089 SET_FLAG(rn->flags, BGP_NODE_USER_CLEAR);
7090 bgp_process(bgp, rn, afi, safi);
7091 }
7092 bgp_unlock_node(rn);
7093 }
7094 }
7095
7096 return CMD_SUCCESS;
7097 }
7098
7099 /* one clear bgp command to rule them all */
7100 DEFUN (clear_ip_bgp_all,
7101 clear_ip_bgp_all_cmd,
7102 "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>]",
7103 CLEAR_STR
7104 IP_STR
7105 BGP_STR
7106 BGP_INSTANCE_HELP_STR
7107 BGP_AFI_HELP_STR
7108 BGP_SAFI_WITH_LABEL_HELP_STR
7109 "Clear all peers\n"
7110 "BGP neighbor address to clear\n"
7111 "BGP IPv6 neighbor to clear\n"
7112 "BGP neighbor on interface to clear\n"
7113 "Clear peers with the AS number\n"
7114 "Clear all external peers\n"
7115 "Clear all members of peer-group\n"
7116 "BGP peer-group name\n"
7117 BGP_SOFT_STR
7118 BGP_SOFT_IN_STR
7119 BGP_SOFT_OUT_STR
7120 BGP_SOFT_IN_STR
7121 "Push out prefix-list ORF and do inbound soft reconfig\n"
7122 BGP_SOFT_OUT_STR)
7123 {
7124 char *vrf = NULL;
7125
7126 afi_t afi = AFI_IP6;
7127 safi_t safi = SAFI_UNICAST;
7128 enum clear_sort clr_sort = clear_peer;
7129 enum bgp_clear_type clr_type;
7130 char *clr_arg = NULL;
7131
7132 int idx = 0;
7133
7134 /* clear [ip] bgp */
7135 if (argv_find(argv, argc, "ip", &idx))
7136 afi = AFI_IP;
7137
7138 /* [<view|vrf> VIEWVRFNAME] */
7139 if (argv_find(argv, argc, "view", &idx)
7140 || argv_find(argv, argc, "vrf", &idx)) {
7141 vrf = argv[idx + 1]->arg;
7142 idx += 2;
7143 }
7144
7145 /* ["BGP_AFI_CMD_STR" ["BGP_SAFI_CMD_STR"]] */
7146 if (argv_find_and_parse_afi(argv, argc, &idx, &afi))
7147 argv_find_and_parse_safi(argv, argc, &idx, &safi);
7148
7149 /* <*|A.B.C.D|X:X::X:X|WORD|(1-4294967295)|external|peer-group WORD> */
7150 if (argv_find(argv, argc, "*", &idx)) {
7151 clr_sort = clear_all;
7152 } else if (argv_find(argv, argc, "A.B.C.D", &idx)) {
7153 clr_sort = clear_peer;
7154 clr_arg = argv[idx]->arg;
7155 } else if (argv_find(argv, argc, "X:X::X:X", &idx)) {
7156 clr_sort = clear_peer;
7157 clr_arg = argv[idx]->arg;
7158 } else if (argv_find(argv, argc, "peer-group", &idx)) {
7159 clr_sort = clear_group;
7160 idx++;
7161 clr_arg = argv[idx]->arg;
7162 } else if (argv_find(argv, argc, "WORD", &idx)) {
7163 clr_sort = clear_peer;
7164 clr_arg = argv[idx]->arg;
7165 } else if (argv_find(argv, argc, "(1-4294967295)", &idx)) {
7166 clr_sort = clear_as;
7167 clr_arg = argv[idx]->arg;
7168 } else if (argv_find(argv, argc, "external", &idx)) {
7169 clr_sort = clear_external;
7170 }
7171
7172 /* [<soft [<in|out>]|in [prefix-filter]|out>] */
7173 if (argv_find(argv, argc, "soft", &idx)) {
7174 if (argv_find(argv, argc, "in", &idx)
7175 || argv_find(argv, argc, "out", &idx))
7176 clr_type = strmatch(argv[idx]->text, "in")
7177 ? BGP_CLEAR_SOFT_IN
7178 : BGP_CLEAR_SOFT_OUT;
7179 else
7180 clr_type = BGP_CLEAR_SOFT_BOTH;
7181 } else if (argv_find(argv, argc, "in", &idx)) {
7182 clr_type = argv_find(argv, argc, "prefix-filter", &idx)
7183 ? BGP_CLEAR_SOFT_IN_ORF_PREFIX
7184 : BGP_CLEAR_SOFT_IN;
7185 } else if (argv_find(argv, argc, "out", &idx)) {
7186 clr_type = BGP_CLEAR_SOFT_OUT;
7187 } else
7188 clr_type = BGP_CLEAR_SOFT_NONE;
7189
7190 return bgp_clear_vty(vty, vrf, afi, safi, clr_sort, clr_type, clr_arg);
7191 }
7192
7193 DEFUN (clear_ip_bgp_prefix,
7194 clear_ip_bgp_prefix_cmd,
7195 "clear [ip] bgp [<view|vrf> VIEWVRFNAME] prefix A.B.C.D/M",
7196 CLEAR_STR
7197 IP_STR
7198 BGP_STR
7199 BGP_INSTANCE_HELP_STR
7200 "Clear bestpath and re-advertise\n"
7201 "IPv4 prefix\n")
7202 {
7203 char *vrf = NULL;
7204 char *prefix = NULL;
7205
7206 int idx = 0;
7207
7208 /* [<view|vrf> VIEWVRFNAME] */
7209 if (argv_find(argv, argc, "VIEWVRFNAME", &idx))
7210 vrf = argv[idx]->arg;
7211
7212 prefix = argv[argc - 1]->arg;
7213
7214 return bgp_clear_prefix(vty, vrf, prefix, AFI_IP, SAFI_UNICAST, NULL);
7215 }
7216
7217 DEFUN (clear_bgp_ipv6_safi_prefix,
7218 clear_bgp_ipv6_safi_prefix_cmd,
7219 "clear [ip] bgp ipv6 "BGP_SAFI_CMD_STR" prefix X:X::X:X/M",
7220 CLEAR_STR
7221 IP_STR
7222 BGP_STR
7223 "Address Family\n"
7224 BGP_SAFI_HELP_STR
7225 "Clear bestpath and re-advertise\n"
7226 "IPv6 prefix\n")
7227 {
7228 int idx_safi = 0;
7229 int idx_ipv6_prefix = 0;
7230 safi_t safi = SAFI_UNICAST;
7231 char *prefix = argv_find(argv, argc, "X:X::X:X/M", &idx_ipv6_prefix) ?
7232 argv[idx_ipv6_prefix]->arg : NULL;
7233
7234 argv_find_and_parse_safi(argv, argc, &idx_safi, &safi);
7235 return bgp_clear_prefix(
7236 vty, NULL, prefix, AFI_IP6,
7237 safi, NULL);
7238 }
7239
7240 DEFUN (clear_bgp_instance_ipv6_safi_prefix,
7241 clear_bgp_instance_ipv6_safi_prefix_cmd,
7242 "clear [ip] bgp <view|vrf> VIEWVRFNAME ipv6 "BGP_SAFI_CMD_STR" prefix X:X::X:X/M",
7243 CLEAR_STR
7244 IP_STR
7245 BGP_STR
7246 BGP_INSTANCE_HELP_STR
7247 "Address Family\n"
7248 BGP_SAFI_HELP_STR
7249 "Clear bestpath and re-advertise\n"
7250 "IPv6 prefix\n")
7251 {
7252 int idx_word = 3;
7253 int idx_safi = 0;
7254 int idx_ipv6_prefix = 0;
7255 safi_t safi = SAFI_UNICAST;
7256 char *prefix = argv_find(argv, argc, "X:X::X:X/M", &idx_ipv6_prefix) ?
7257 argv[idx_ipv6_prefix]->arg : NULL;
7258 /* [<view|vrf> VIEWVRFNAME] */
7259 char *vrfview = argv_find(argv, argc, "VIEWVRFNAME", &idx_word) ?
7260 argv[idx_word]->arg : NULL;
7261
7262 argv_find_and_parse_safi(argv, argc, &idx_safi, &safi);
7263
7264 return bgp_clear_prefix(
7265 vty, vrfview, prefix,
7266 AFI_IP6, safi, NULL);
7267 }
7268
7269 DEFUN (show_bgp_views,
7270 show_bgp_views_cmd,
7271 "show [ip] bgp views",
7272 SHOW_STR
7273 IP_STR
7274 BGP_STR
7275 "Show the defined BGP views\n")
7276 {
7277 struct list *inst = bm->bgp;
7278 struct listnode *node;
7279 struct bgp *bgp;
7280
7281 if (!bgp_option_check(BGP_OPT_MULTIPLE_INSTANCE)) {
7282 vty_out(vty, "BGP Multiple Instance is not enabled\n");
7283 return CMD_WARNING;
7284 }
7285
7286 vty_out(vty, "Defined BGP views:\n");
7287 for (ALL_LIST_ELEMENTS_RO(inst, node, bgp)) {
7288 /* Skip VRFs. */
7289 if (bgp->inst_type == BGP_INSTANCE_TYPE_VRF)
7290 continue;
7291 vty_out(vty, "\t%s (AS%u)\n", bgp->name ? bgp->name : "(null)",
7292 bgp->as);
7293 }
7294
7295 return CMD_SUCCESS;
7296 }
7297
7298 DEFUN (show_bgp_vrfs,
7299 show_bgp_vrfs_cmd,
7300 "show [ip] bgp vrfs [json]",
7301 SHOW_STR
7302 IP_STR
7303 BGP_STR
7304 "Show BGP VRFs\n"
7305 JSON_STR)
7306 {
7307 char buf[ETHER_ADDR_STRLEN];
7308 struct list *inst = bm->bgp;
7309 struct listnode *node;
7310 struct bgp *bgp;
7311 uint8_t uj = use_json(argc, argv);
7312 json_object *json = NULL;
7313 json_object *json_vrfs = NULL;
7314 int count = 0;
7315
7316 if (!bgp_option_check(BGP_OPT_MULTIPLE_INSTANCE)) {
7317 vty_out(vty, "BGP Multiple Instance is not enabled\n");
7318 return CMD_WARNING;
7319 }
7320
7321 if (uj) {
7322 json = json_object_new_object();
7323 json_vrfs = json_object_new_object();
7324 }
7325
7326 for (ALL_LIST_ELEMENTS_RO(inst, node, bgp)) {
7327 const char *name, *type;
7328 struct peer *peer;
7329 struct listnode *node, *nnode;
7330 int peers_cfg, peers_estb;
7331 json_object *json_vrf = NULL;
7332
7333 /* Skip Views. */
7334 if (bgp->inst_type == BGP_INSTANCE_TYPE_VIEW)
7335 continue;
7336
7337 count++;
7338 if (!uj && count == 1)
7339 vty_out(vty,
7340 "%4s %-5s %-16s %9s %10s %-37s %-10s %-15s\n",
7341 "Type", "Id", "routerId", "#PeersVfg",
7342 "#PeersEstb", "Name", "L3-VNI", "Rmac");
7343
7344 peers_cfg = peers_estb = 0;
7345 if (uj)
7346 json_vrf = json_object_new_object();
7347
7348
7349 for (ALL_LIST_ELEMENTS(bgp->peer, node, nnode, peer)) {
7350 if (!CHECK_FLAG(peer->flags, PEER_FLAG_CONFIG_NODE))
7351 continue;
7352 peers_cfg++;
7353 if (peer->status == Established)
7354 peers_estb++;
7355 }
7356
7357 if (bgp->inst_type == BGP_INSTANCE_TYPE_DEFAULT) {
7358 name = "Default";
7359 type = "DFLT";
7360 } else {
7361 name = bgp->name;
7362 type = "VRF";
7363 }
7364
7365
7366 if (uj) {
7367 int64_t vrf_id_ui = (bgp->vrf_id == VRF_UNKNOWN)
7368 ? -1
7369 : (int64_t)bgp->vrf_id;
7370 json_object_string_add(json_vrf, "type", type);
7371 json_object_int_add(json_vrf, "vrfId", vrf_id_ui);
7372 json_object_string_add(json_vrf, "routerId",
7373 inet_ntoa(bgp->router_id));
7374 json_object_int_add(json_vrf, "numConfiguredPeers",
7375 peers_cfg);
7376 json_object_int_add(json_vrf, "numEstablishedPeers",
7377 peers_estb);
7378
7379 json_object_int_add(json_vrf, "l3vni", bgp->l3vni);
7380 json_object_string_add(
7381 json_vrf, "rmac",
7382 prefix_mac2str(&bgp->rmac, buf, sizeof(buf)));
7383 json_object_object_add(json_vrfs, name, json_vrf);
7384 } else
7385 vty_out(vty,
7386 "%4s %-5d %-16s %9u %10u %-37s %-10u %-15s\n",
7387 type,
7388 bgp->vrf_id == VRF_UNKNOWN ? -1
7389 : (int)bgp->vrf_id,
7390 inet_ntoa(bgp->router_id), peers_cfg,
7391 peers_estb, name, bgp->l3vni,
7392 prefix_mac2str(&bgp->rmac, buf, sizeof(buf)));
7393 }
7394
7395 if (uj) {
7396 json_object_object_add(json, "vrfs", json_vrfs);
7397
7398 json_object_int_add(json, "totalVrfs", count);
7399
7400 vty_out(vty, "%s\n", json_object_to_json_string_ext(
7401 json, JSON_C_TO_STRING_PRETTY));
7402 json_object_free(json);
7403 } else {
7404 if (count)
7405 vty_out(vty,
7406 "\nTotal number of VRFs (including default): %d\n",
7407 count);
7408 }
7409
7410 return CMD_SUCCESS;
7411 }
7412
7413 static void show_address_entry(struct hash_backet *backet, void *args)
7414 {
7415 struct vty *vty = (struct vty *)args;
7416 struct bgp_addr *addr = (struct bgp_addr *)backet->data;
7417
7418 vty_out(vty, "addr: %s, count: %d\n", inet_ntoa(addr->addr),
7419 addr->refcnt);
7420 }
7421
7422 static void show_tip_entry(struct hash_backet *backet, void *args)
7423 {
7424 struct vty *vty = (struct vty *)args;
7425 struct tip_addr *tip = (struct tip_addr *)backet->data;
7426
7427 vty_out(vty, "addr: %s, count: %d\n", inet_ntoa(tip->addr),
7428 tip->refcnt);
7429 }
7430
7431 static void bgp_show_martian_nexthops(struct vty *vty, struct bgp *bgp)
7432 {
7433 vty_out(vty, "self nexthop database:\n");
7434 hash_iterate(bgp->address_hash,
7435 (void (*)(struct hash_backet *, void *))show_address_entry,
7436 vty);
7437
7438 vty_out(vty, "Tunnel-ip database:\n");
7439 hash_iterate(bgp->tip_hash,
7440 (void (*)(struct hash_backet *, void *))show_tip_entry,
7441 vty);
7442 }
7443
7444 DEFUN(show_bgp_martian_nexthop_db, show_bgp_martian_nexthop_db_cmd,
7445 "show bgp [<view|vrf> VIEWVRFNAME] martian next-hop",
7446 SHOW_STR BGP_STR BGP_INSTANCE_HELP_STR
7447 "martian next-hops\n"
7448 "martian next-hop database\n")
7449 {
7450 struct bgp *bgp = NULL;
7451 int idx = 0;
7452
7453 if (argv_find(argv, argc, "view", &idx)
7454 || argv_find(argv, argc, "vrf", &idx))
7455 bgp = bgp_lookup_by_name(argv[idx + 1]->arg);
7456 else
7457 bgp = bgp_get_default();
7458
7459 if (!bgp) {
7460 vty_out(vty, "%% No BGP process is configured\n");
7461 return CMD_WARNING;
7462 }
7463 bgp_show_martian_nexthops(vty, bgp);
7464
7465 return CMD_SUCCESS;
7466 }
7467
7468 DEFUN (show_bgp_memory,
7469 show_bgp_memory_cmd,
7470 "show [ip] bgp memory",
7471 SHOW_STR
7472 IP_STR
7473 BGP_STR
7474 "Global BGP memory statistics\n")
7475 {
7476 char memstrbuf[MTYPE_MEMSTR_LEN];
7477 unsigned long count;
7478
7479 /* RIB related usage stats */
7480 count = mtype_stats_alloc(MTYPE_BGP_NODE);
7481 vty_out(vty, "%ld RIB nodes, using %s of memory\n", count,
7482 mtype_memstr(memstrbuf, sizeof(memstrbuf),
7483 count * sizeof(struct bgp_node)));
7484
7485 count = mtype_stats_alloc(MTYPE_BGP_ROUTE);
7486 vty_out(vty, "%ld BGP routes, using %s of memory\n", count,
7487 mtype_memstr(memstrbuf, sizeof(memstrbuf),
7488 count * sizeof(struct bgp_info)));
7489 if ((count = mtype_stats_alloc(MTYPE_BGP_ROUTE_EXTRA)))
7490 vty_out(vty, "%ld BGP route ancillaries, using %s of memory\n",
7491 count,
7492 mtype_memstr(memstrbuf, sizeof(memstrbuf),
7493 count * sizeof(struct bgp_info_extra)));
7494
7495 if ((count = mtype_stats_alloc(MTYPE_BGP_STATIC)))
7496 vty_out(vty, "%ld Static routes, using %s of memory\n", count,
7497 mtype_memstr(memstrbuf, sizeof(memstrbuf),
7498 count * sizeof(struct bgp_static)));
7499
7500 if ((count = mtype_stats_alloc(MTYPE_BGP_PACKET)))
7501 vty_out(vty, "%ld Packets, using %s of memory\n", count,
7502 mtype_memstr(memstrbuf, sizeof(memstrbuf),
7503 count * sizeof(struct bpacket)));
7504
7505 /* Adj-In/Out */
7506 if ((count = mtype_stats_alloc(MTYPE_BGP_ADJ_IN)))
7507 vty_out(vty, "%ld Adj-In entries, using %s of memory\n", count,
7508 mtype_memstr(memstrbuf, sizeof(memstrbuf),
7509 count * sizeof(struct bgp_adj_in)));
7510 if ((count = mtype_stats_alloc(MTYPE_BGP_ADJ_OUT)))
7511 vty_out(vty, "%ld Adj-Out entries, using %s of memory\n", count,
7512 mtype_memstr(memstrbuf, sizeof(memstrbuf),
7513 count * sizeof(struct bgp_adj_out)));
7514
7515 if ((count = mtype_stats_alloc(MTYPE_BGP_NEXTHOP_CACHE)))
7516 vty_out(vty, "%ld Nexthop cache entries, using %s of memory\n",
7517 count,
7518 mtype_memstr(memstrbuf, sizeof(memstrbuf),
7519 count * sizeof(struct bgp_nexthop_cache)));
7520
7521 if ((count = mtype_stats_alloc(MTYPE_BGP_DAMP_INFO)))
7522 vty_out(vty, "%ld Dampening entries, using %s of memory\n",
7523 count,
7524 mtype_memstr(memstrbuf, sizeof(memstrbuf),
7525 count * sizeof(struct bgp_damp_info)));
7526
7527 /* Attributes */
7528 count = attr_count();
7529 vty_out(vty, "%ld BGP attributes, using %s of memory\n", count,
7530 mtype_memstr(memstrbuf, sizeof(memstrbuf),
7531 count * sizeof(struct attr)));
7532
7533 if ((count = attr_unknown_count()))
7534 vty_out(vty, "%ld unknown attributes\n", count);
7535
7536 /* AS_PATH attributes */
7537 count = aspath_count();
7538 vty_out(vty, "%ld BGP AS-PATH entries, using %s of memory\n", count,
7539 mtype_memstr(memstrbuf, sizeof(memstrbuf),
7540 count * sizeof(struct aspath)));
7541
7542 count = mtype_stats_alloc(MTYPE_AS_SEG);
7543 vty_out(vty, "%ld BGP AS-PATH segments, using %s of memory\n", count,
7544 mtype_memstr(memstrbuf, sizeof(memstrbuf),
7545 count * sizeof(struct assegment)));
7546
7547 /* Other attributes */
7548 if ((count = community_count()))
7549 vty_out(vty, "%ld BGP community entries, using %s of memory\n",
7550 count, mtype_memstr(memstrbuf, sizeof(memstrbuf),
7551 count * sizeof(struct community)));
7552 if ((count = mtype_stats_alloc(MTYPE_ECOMMUNITY)))
7553 vty_out(vty, "%ld BGP community entries, using %s of memory\n",
7554 count, mtype_memstr(memstrbuf, sizeof(memstrbuf),
7555 count * sizeof(struct ecommunity)));
7556 if ((count = mtype_stats_alloc(MTYPE_LCOMMUNITY)))
7557 vty_out(vty,
7558 "%ld BGP large-community entries, using %s of memory\n",
7559 count, mtype_memstr(memstrbuf, sizeof(memstrbuf),
7560 count * sizeof(struct lcommunity)));
7561
7562 if ((count = mtype_stats_alloc(MTYPE_CLUSTER)))
7563 vty_out(vty, "%ld Cluster lists, using %s of memory\n", count,
7564 mtype_memstr(memstrbuf, sizeof(memstrbuf),
7565 count * sizeof(struct cluster_list)));
7566
7567 /* Peer related usage */
7568 count = mtype_stats_alloc(MTYPE_BGP_PEER);
7569 vty_out(vty, "%ld peers, using %s of memory\n", count,
7570 mtype_memstr(memstrbuf, sizeof(memstrbuf),
7571 count * sizeof(struct peer)));
7572
7573 if ((count = mtype_stats_alloc(MTYPE_PEER_GROUP)))
7574 vty_out(vty, "%ld peer groups, using %s of memory\n", count,
7575 mtype_memstr(memstrbuf, sizeof(memstrbuf),
7576 count * sizeof(struct peer_group)));
7577
7578 /* Other */
7579 if ((count = mtype_stats_alloc(MTYPE_HASH)))
7580 vty_out(vty, "%ld hash tables, using %s of memory\n", count,
7581 mtype_memstr(memstrbuf, sizeof(memstrbuf),
7582 count * sizeof(struct hash)));
7583 if ((count = mtype_stats_alloc(MTYPE_HASH_BACKET)))
7584 vty_out(vty, "%ld hash buckets, using %s of memory\n", count,
7585 mtype_memstr(memstrbuf, sizeof(memstrbuf),
7586 count * sizeof(struct hash_backet)));
7587 if ((count = mtype_stats_alloc(MTYPE_BGP_REGEXP)))
7588 vty_out(vty, "%ld compiled regexes, using %s of memory\n",
7589 count, mtype_memstr(memstrbuf, sizeof(memstrbuf),
7590 count * sizeof(regex_t)));
7591 return CMD_SUCCESS;
7592 }
7593
7594 static void bgp_show_bestpath_json(struct bgp *bgp, json_object *json)
7595 {
7596 json_object *bestpath = json_object_new_object();
7597
7598 if (bgp_flag_check(bgp, BGP_FLAG_ASPATH_IGNORE))
7599 json_object_string_add(bestpath, "asPath", "ignore");
7600
7601 if (bgp_flag_check(bgp, BGP_FLAG_ASPATH_CONFED))
7602 json_object_string_add(bestpath, "asPath", "confed");
7603
7604 if (bgp_flag_check(bgp, BGP_FLAG_ASPATH_MULTIPATH_RELAX)) {
7605 if (bgp_flag_check(bgp, BGP_FLAG_MULTIPATH_RELAX_AS_SET))
7606 json_object_string_add(bestpath, "multiPathRelax",
7607 "as-set");
7608 else
7609 json_object_string_add(bestpath, "multiPathRelax",
7610 "true");
7611 } else
7612 json_object_string_add(bestpath, "multiPathRelax", "false");
7613
7614 if (bgp_flag_check(bgp, BGP_FLAG_COMPARE_ROUTER_ID))
7615 json_object_string_add(bestpath, "compareRouterId", "true");
7616 if (bgp_flag_check(bgp, BGP_FLAG_MED_CONFED)
7617 || bgp_flag_check(bgp, BGP_FLAG_MED_MISSING_AS_WORST)) {
7618 if (bgp_flag_check(bgp, BGP_FLAG_MED_CONFED))
7619 json_object_string_add(bestpath, "med", "confed");
7620 if (bgp_flag_check(bgp, BGP_FLAG_MED_MISSING_AS_WORST))
7621 json_object_string_add(bestpath, "med",
7622 "missing-as-worst");
7623 else
7624 json_object_string_add(bestpath, "med", "true");
7625 }
7626
7627 json_object_object_add(json, "bestPath", bestpath);
7628 }
7629
7630 /* Show BGP peer's summary information. */
7631 static int bgp_show_summary(struct vty *vty, struct bgp *bgp, int afi, int safi,
7632 uint8_t use_json, json_object *json)
7633 {
7634 struct peer *peer;
7635 struct listnode *node, *nnode;
7636 unsigned int count = 0, dn_count = 0;
7637 char timebuf[BGP_UPTIME_LEN], dn_flag[2];
7638 char neighbor_buf[VTY_BUFSIZ];
7639 int neighbor_col_default_width = 16;
7640 int len;
7641 int max_neighbor_width = 0;
7642 int pfx_rcd_safi;
7643 json_object *json_peer = NULL;
7644 json_object *json_peers = NULL;
7645
7646 /* labeled-unicast routes are installed in the unicast table so in order
7647 * to
7648 * display the correct PfxRcd value we must look at SAFI_UNICAST
7649 */
7650 if (safi == SAFI_LABELED_UNICAST)
7651 pfx_rcd_safi = SAFI_UNICAST;
7652 else
7653 pfx_rcd_safi = safi;
7654
7655 if (use_json) {
7656 if (json == NULL)
7657 json = json_object_new_object();
7658
7659 json_peers = json_object_new_object();
7660 } else {
7661 /* Loop over all neighbors that will be displayed to determine
7662 * how many
7663 * characters are needed for the Neighbor column
7664 */
7665 for (ALL_LIST_ELEMENTS(bgp->peer, node, nnode, peer)) {
7666 if (!CHECK_FLAG(peer->flags, PEER_FLAG_CONFIG_NODE))
7667 continue;
7668
7669 if (peer->afc[afi][safi]) {
7670 memset(dn_flag, '\0', sizeof(dn_flag));
7671 if (peer_dynamic_neighbor(peer))
7672 dn_flag[0] = '*';
7673
7674 if (peer->hostname
7675 && bgp_flag_check(bgp,
7676 BGP_FLAG_SHOW_HOSTNAME))
7677 sprintf(neighbor_buf, "%s%s(%s) ",
7678 dn_flag, peer->hostname,
7679 peer->host);
7680 else
7681 sprintf(neighbor_buf, "%s%s ", dn_flag,
7682 peer->host);
7683
7684 len = strlen(neighbor_buf);
7685
7686 if (len > max_neighbor_width)
7687 max_neighbor_width = len;
7688 }
7689 }
7690
7691 /* Originally we displayed the Neighbor column as 16
7692 * characters wide so make that the default
7693 */
7694 if (max_neighbor_width < neighbor_col_default_width)
7695 max_neighbor_width = neighbor_col_default_width;
7696 }
7697
7698 for (ALL_LIST_ELEMENTS(bgp->peer, node, nnode, peer)) {
7699 if (!CHECK_FLAG(peer->flags, PEER_FLAG_CONFIG_NODE))
7700 continue;
7701
7702 if (!peer->afc[afi][safi])
7703 continue;
7704
7705 if (!count) {
7706 unsigned long ents;
7707 char memstrbuf[MTYPE_MEMSTR_LEN];
7708 int64_t vrf_id_ui;
7709
7710 vrf_id_ui = (bgp->vrf_id == VRF_UNKNOWN)
7711 ? -1
7712 : (int64_t)bgp->vrf_id;
7713
7714 /* Usage summary and header */
7715 if (use_json) {
7716 json_object_string_add(
7717 json, "routerId",
7718 inet_ntoa(bgp->router_id));
7719 json_object_int_add(json, "as", bgp->as);
7720 json_object_int_add(json, "vrfId", vrf_id_ui);
7721 json_object_string_add(
7722 json, "vrfName",
7723 (bgp->inst_type
7724 == BGP_INSTANCE_TYPE_DEFAULT)
7725 ? "Default"
7726 : bgp->name);
7727 } else {
7728 vty_out(vty,
7729 "BGP router identifier %s, local AS number %u vrf-id %d",
7730 inet_ntoa(bgp->router_id), bgp->as,
7731 bgp->vrf_id == VRF_UNKNOWN
7732 ? -1
7733 : (int)bgp->vrf_id);
7734 vty_out(vty, "\n");
7735 }
7736
7737 if (bgp_update_delay_configured(bgp)) {
7738 if (use_json) {
7739 json_object_int_add(
7740 json, "updateDelayLimit",
7741 bgp->v_update_delay);
7742
7743 if (bgp->v_update_delay
7744 != bgp->v_establish_wait)
7745 json_object_int_add(
7746 json,
7747 "updateDelayEstablishWait",
7748 bgp->v_establish_wait);
7749
7750 if (bgp_update_delay_active(bgp)) {
7751 json_object_string_add(
7752 json,
7753 "updateDelayFirstNeighbor",
7754 bgp->update_delay_begin_time);
7755 json_object_boolean_true_add(
7756 json,
7757 "updateDelayInProgress");
7758 } else {
7759 if (bgp->update_delay_over) {
7760 json_object_string_add(
7761 json,
7762 "updateDelayFirstNeighbor",
7763 bgp->update_delay_begin_time);
7764 json_object_string_add(
7765 json,
7766 "updateDelayBestpathResumed",
7767 bgp->update_delay_end_time);
7768 json_object_string_add(
7769 json,
7770 "updateDelayZebraUpdateResume",
7771 bgp->update_delay_zebra_resume_time);
7772 json_object_string_add(
7773 json,
7774 "updateDelayPeerUpdateResume",
7775 bgp->update_delay_peers_resume_time);
7776 }
7777 }
7778 } else {
7779 vty_out(vty,
7780 "Read-only mode update-delay limit: %d seconds\n",
7781 bgp->v_update_delay);
7782 if (bgp->v_update_delay
7783 != bgp->v_establish_wait)
7784 vty_out(vty,
7785 " Establish wait: %d seconds\n",
7786 bgp->v_establish_wait);
7787
7788 if (bgp_update_delay_active(bgp)) {
7789 vty_out(vty,
7790 " First neighbor established: %s\n",
7791 bgp->update_delay_begin_time);
7792 vty_out(vty,
7793 " Delay in progress\n");
7794 } else {
7795 if (bgp->update_delay_over) {
7796 vty_out(vty,
7797 " First neighbor established: %s\n",
7798 bgp->update_delay_begin_time);
7799 vty_out(vty,
7800 " Best-paths resumed: %s\n",
7801 bgp->update_delay_end_time);
7802 vty_out(vty,
7803 " zebra update resumed: %s\n",
7804 bgp->update_delay_zebra_resume_time);
7805 vty_out(vty,
7806 " peers update resumed: %s\n",
7807 bgp->update_delay_peers_resume_time);
7808 }
7809 }
7810 }
7811 }
7812
7813 if (use_json) {
7814 if (bgp_maxmed_onstartup_configured(bgp)
7815 && bgp->maxmed_active)
7816 json_object_boolean_true_add(
7817 json, "maxMedOnStartup");
7818 if (bgp->v_maxmed_admin)
7819 json_object_boolean_true_add(
7820 json, "maxMedAdministrative");
7821
7822 json_object_int_add(
7823 json, "tableVersion",
7824 bgp_table_version(bgp->rib[afi][safi]));
7825
7826 ents = bgp_table_count(bgp->rib[afi][safi]);
7827 json_object_int_add(json, "ribCount", ents);
7828 json_object_int_add(
7829 json, "ribMemory",
7830 ents * sizeof(struct bgp_node));
7831
7832 ents = listcount(bgp->peer);
7833 json_object_int_add(json, "peerCount", ents);
7834 json_object_int_add(json, "peerMemory",
7835 ents * sizeof(struct peer));
7836
7837 if ((ents = listcount(bgp->group))) {
7838 json_object_int_add(
7839 json, "peerGroupCount", ents);
7840 json_object_int_add(
7841 json, "peerGroupMemory",
7842 ents * sizeof(struct
7843 peer_group));
7844 }
7845
7846 if (CHECK_FLAG(bgp->af_flags[afi][safi],
7847 BGP_CONFIG_DAMPENING))
7848 json_object_boolean_true_add(
7849 json, "dampeningEnabled");
7850 } else {
7851 if (bgp_maxmed_onstartup_configured(bgp)
7852 && bgp->maxmed_active)
7853 vty_out(vty,
7854 "Max-med on-startup active\n");
7855 if (bgp->v_maxmed_admin)
7856 vty_out(vty,
7857 "Max-med administrative active\n");
7858
7859 vty_out(vty, "BGP table version %" PRIu64 "\n",
7860 bgp_table_version(bgp->rib[afi][safi]));
7861
7862 ents = bgp_table_count(bgp->rib[afi][safi]);
7863 vty_out(vty,
7864 "RIB entries %ld, using %s of memory\n",
7865 ents,
7866 mtype_memstr(memstrbuf,
7867 sizeof(memstrbuf),
7868 ents * sizeof(struct
7869 bgp_node)));
7870
7871 /* Peer related usage */
7872 ents = listcount(bgp->peer);
7873 vty_out(vty, "Peers %ld, using %s of memory\n",
7874 ents,
7875 mtype_memstr(
7876 memstrbuf, sizeof(memstrbuf),
7877 ents * sizeof(struct peer)));
7878
7879 if ((ents = listcount(bgp->group)))
7880 vty_out(vty,
7881 "Peer groups %ld, using %s of memory\n",
7882 ents,
7883 mtype_memstr(
7884 memstrbuf,
7885 sizeof(memstrbuf),
7886 ents * sizeof(struct
7887 peer_group)));
7888
7889 if (CHECK_FLAG(bgp->af_flags[afi][safi],
7890 BGP_CONFIG_DAMPENING))
7891 vty_out(vty, "Dampening enabled.\n");
7892 vty_out(vty, "\n");
7893
7894 /* Subtract 8 here because 'Neighbor' is
7895 * 8 characters */
7896 vty_out(vty, "Neighbor");
7897 vty_out(vty, "%*s", max_neighbor_width - 8,
7898 " ");
7899 vty_out(vty,
7900 "V AS MsgRcvd MsgSent TblVer InQ OutQ Up/Down State/PfxRcd\n");
7901 }
7902 }
7903
7904 count++;
7905
7906 if (use_json) {
7907 json_peer = json_object_new_object();
7908
7909 if (peer_dynamic_neighbor(peer))
7910 json_object_boolean_true_add(json_peer,
7911 "dynamicPeer");
7912
7913 if (peer->hostname)
7914 json_object_string_add(json_peer, "hostname",
7915 peer->hostname);
7916
7917 if (peer->domainname)
7918 json_object_string_add(json_peer, "domainname",
7919 peer->domainname);
7920
7921 json_object_int_add(json_peer, "remoteAs", peer->as);
7922 json_object_int_add(json_peer, "version", 4);
7923 json_object_int_add(json_peer, "msgRcvd",
7924 PEER_TOTAL_RX(peer));
7925 json_object_int_add(json_peer, "msgSent",
7926 PEER_TOTAL_TX(peer));
7927
7928 json_object_int_add(json_peer, "tableVersion",
7929 peer->version[afi][safi]);
7930 json_object_int_add(json_peer, "outq",
7931 peer->obuf->count);
7932 json_object_int_add(json_peer, "inq", 0);
7933 peer_uptime(peer->uptime, timebuf, BGP_UPTIME_LEN,
7934 use_json, json_peer);
7935 json_object_int_add(json_peer, "prefixReceivedCount",
7936 peer->pcount[afi][pfx_rcd_safi]);
7937
7938 if (CHECK_FLAG(peer->flags, PEER_FLAG_SHUTDOWN))
7939 json_object_string_add(json_peer, "state",
7940 "Idle (Admin)");
7941 else if (CHECK_FLAG(peer->sflags,
7942 PEER_STATUS_PREFIX_OVERFLOW))
7943 json_object_string_add(json_peer, "state",
7944 "Idle (PfxCt)");
7945 else
7946 json_object_string_add(
7947 json_peer, "state",
7948 lookup_msg(bgp_status_msg, peer->status,
7949 NULL));
7950
7951 if (peer->conf_if)
7952 json_object_string_add(json_peer, "idType",
7953 "interface");
7954 else if (peer->su.sa.sa_family == AF_INET)
7955 json_object_string_add(json_peer, "idType",
7956 "ipv4");
7957 else if (peer->su.sa.sa_family == AF_INET6)
7958 json_object_string_add(json_peer, "idType",
7959 "ipv6");
7960
7961 json_object_object_add(json_peers, peer->host,
7962 json_peer);
7963 } else {
7964 memset(dn_flag, '\0', sizeof(dn_flag));
7965 if (peer_dynamic_neighbor(peer)) {
7966 dn_count++;
7967 dn_flag[0] = '*';
7968 }
7969
7970 if (peer->hostname
7971 && bgp_flag_check(bgp, BGP_FLAG_SHOW_HOSTNAME))
7972 len = vty_out(vty, "%s%s(%s)", dn_flag,
7973 peer->hostname, peer->host);
7974 else
7975 len = vty_out(vty, "%s%s", dn_flag, peer->host);
7976
7977 /* pad the neighbor column with spaces */
7978 if (len < max_neighbor_width)
7979 vty_out(vty, "%*s", max_neighbor_width - len,
7980 " ");
7981
7982 vty_out(vty, "4 %10u %7u %7u %8" PRIu64 " %4d %4zd %8s",
7983 peer->as, PEER_TOTAL_RX(peer),
7984 PEER_TOTAL_TX(peer), peer->version[afi][safi],
7985 0, peer->obuf->count,
7986 peer_uptime(peer->uptime, timebuf,
7987 BGP_UPTIME_LEN, 0, NULL));
7988
7989 if (peer->status == Established)
7990 if (peer->afc_recv[afi][safi])
7991 vty_out(vty, " %12ld",
7992 peer->pcount[afi]
7993 [pfx_rcd_safi]);
7994 else
7995 vty_out(vty, " NoNeg");
7996 else {
7997 if (CHECK_FLAG(peer->flags, PEER_FLAG_SHUTDOWN))
7998 vty_out(vty, " Idle (Admin)");
7999 else if (CHECK_FLAG(
8000 peer->sflags,
8001 PEER_STATUS_PREFIX_OVERFLOW))
8002 vty_out(vty, " Idle (PfxCt)");
8003 else
8004 vty_out(vty, " %12s",
8005 lookup_msg(bgp_status_msg,
8006 peer->status, NULL));
8007 }
8008 vty_out(vty, "\n");
8009 }
8010 }
8011
8012 if (use_json) {
8013 json_object_object_add(json, "peers", json_peers);
8014
8015 json_object_int_add(json, "totalPeers", count);
8016 json_object_int_add(json, "dynamicPeers", dn_count);
8017
8018 bgp_show_bestpath_json(bgp, json);
8019
8020 vty_out(vty, "%s\n", json_object_to_json_string_ext(
8021 json, JSON_C_TO_STRING_PRETTY));
8022 json_object_free(json);
8023 } else {
8024 if (count)
8025 vty_out(vty, "\nTotal number of neighbors %d\n", count);
8026 else {
8027 vty_out(vty, "No %s neighbor is configured\n",
8028 afi_safi_print(afi, safi));
8029 }
8030
8031 if (dn_count) {
8032 vty_out(vty, "* - dynamic neighbor\n");
8033 vty_out(vty, "%d dynamic neighbor(s), limit %d\n",
8034 dn_count, bgp->dynamic_neighbors_limit);
8035 }
8036 }
8037
8038 return CMD_SUCCESS;
8039 }
8040
8041 static void bgp_show_summary_afi_safi(struct vty *vty, struct bgp *bgp, int afi,
8042 int safi, uint8_t use_json,
8043 json_object *json)
8044 {
8045 int is_first = 1;
8046 int afi_wildcard = (afi == AFI_MAX);
8047 int safi_wildcard = (safi == SAFI_MAX);
8048 int is_wildcard = (afi_wildcard || safi_wildcard);
8049 bool json_output = false;
8050
8051 if (use_json && is_wildcard)
8052 vty_out(vty, "{\n");
8053 if (afi_wildcard)
8054 afi = 1; /* AFI_IP */
8055 while (afi < AFI_MAX) {
8056 if (safi_wildcard)
8057 safi = 1; /* SAFI_UNICAST */
8058 while (safi < SAFI_MAX) {
8059 if (bgp_afi_safi_peer_exists(bgp, afi, safi)) {
8060 json_output = true;
8061 if (is_wildcard) {
8062 /*
8063 * So limit output to those afi/safi
8064 * pairs that
8065 * actualy have something interesting in
8066 * them
8067 */
8068 if (use_json) {
8069 json = json_object_new_object();
8070
8071 if (!is_first)
8072 vty_out(vty, ",\n");
8073 else
8074 is_first = 0;
8075
8076 vty_out(vty, "\"%s\":",
8077 afi_safi_json(afi,
8078 safi));
8079 } else {
8080 vty_out(vty, "\n%s Summary:\n",
8081 afi_safi_print(afi,
8082 safi));
8083 }
8084 }
8085 bgp_show_summary(vty, bgp, afi, safi, use_json,
8086 json);
8087 }
8088 safi++;
8089 if (!safi_wildcard)
8090 safi = SAFI_MAX;
8091 }
8092 afi++;
8093 if (!afi_wildcard)
8094 afi = AFI_MAX;
8095 }
8096
8097 if (use_json && is_wildcard)
8098 vty_out(vty, "}\n");
8099 else if (use_json && !json_output)
8100 vty_out(vty, "{}\n");
8101 }
8102
8103 static void bgp_show_all_instances_summary_vty(struct vty *vty, afi_t afi,
8104 safi_t safi, uint8_t use_json)
8105 {
8106 struct listnode *node, *nnode;
8107 struct bgp *bgp;
8108 json_object *json = NULL;
8109 int is_first = 1;
8110
8111 if (use_json)
8112 vty_out(vty, "{\n");
8113
8114 for (ALL_LIST_ELEMENTS(bm->bgp, node, nnode, bgp)) {
8115 if (use_json) {
8116 json = json_object_new_object();
8117
8118 if (!is_first)
8119 vty_out(vty, ",\n");
8120 else
8121 is_first = 0;
8122
8123 vty_out(vty, "\"%s\":",
8124 (bgp->inst_type == BGP_INSTANCE_TYPE_DEFAULT)
8125 ? "Default"
8126 : bgp->name);
8127 } else {
8128 vty_out(vty, "\nInstance %s:\n",
8129 (bgp->inst_type == BGP_INSTANCE_TYPE_DEFAULT)
8130 ? "Default"
8131 : bgp->name);
8132 }
8133 bgp_show_summary_afi_safi(vty, bgp, afi, safi, use_json, json);
8134 }
8135
8136 if (use_json)
8137 vty_out(vty, "}\n");
8138 }
8139
8140 int bgp_show_summary_vty(struct vty *vty, const char *name, afi_t afi,
8141 safi_t safi, uint8_t use_json)
8142 {
8143 struct bgp *bgp;
8144
8145 if (name) {
8146 if (strmatch(name, "all")) {
8147 bgp_show_all_instances_summary_vty(vty, afi, safi,
8148 use_json);
8149 return CMD_SUCCESS;
8150 } else {
8151 bgp = bgp_lookup_by_name(name);
8152
8153 if (!bgp) {
8154 if (use_json)
8155 vty_out(vty, "{}\n");
8156 else
8157 vty_out(vty,
8158 "%% No such BGP instance exist\n");
8159 return CMD_WARNING;
8160 }
8161
8162 bgp_show_summary_afi_safi(vty, bgp, afi, safi, use_json,
8163 NULL);
8164 return CMD_SUCCESS;
8165 }
8166 }
8167
8168 bgp = bgp_get_default();
8169
8170 if (bgp)
8171 bgp_show_summary_afi_safi(vty, bgp, afi, safi, use_json, NULL);
8172
8173 return CMD_SUCCESS;
8174 }
8175
8176 /* `show [ip] bgp summary' commands. */
8177 DEFUN (show_ip_bgp_summary,
8178 show_ip_bgp_summary_cmd,
8179 "show [ip] bgp [<view|vrf> VIEWVRFNAME] ["BGP_AFI_CMD_STR" ["BGP_SAFI_WITH_LABEL_CMD_STR"]] summary [json]",
8180 SHOW_STR
8181 IP_STR
8182 BGP_STR
8183 BGP_INSTANCE_HELP_STR
8184 BGP_AFI_HELP_STR
8185 BGP_SAFI_WITH_LABEL_HELP_STR
8186 "Summary of BGP neighbor status\n"
8187 JSON_STR)
8188 {
8189 char *vrf = NULL;
8190 afi_t afi = AFI_MAX;
8191 safi_t safi = SAFI_MAX;
8192
8193 int idx = 0;
8194
8195 /* show [ip] bgp */
8196 if (argv_find(argv, argc, "ip", &idx))
8197 afi = AFI_IP;
8198 /* [<view|vrf> VIEWVRFNAME] */
8199 if (argv_find(argv, argc, "view", &idx)
8200 || argv_find(argv, argc, "vrf", &idx))
8201 vrf = argv[++idx]->arg;
8202 /* ["BGP_AFI_CMD_STR" ["BGP_SAFI_CMD_STR"]] */
8203 if (argv_find_and_parse_afi(argv, argc, &idx, &afi)) {
8204 argv_find_and_parse_safi(argv, argc, &idx, &safi);
8205 }
8206
8207 int uj = use_json(argc, argv);
8208
8209 return bgp_show_summary_vty(vty, vrf, afi, safi, uj);
8210 }
8211
8212 const char *afi_safi_print(afi_t afi, safi_t safi)
8213 {
8214 if (afi == AFI_IP && safi == SAFI_UNICAST)
8215 return "IPv4 Unicast";
8216 else if (afi == AFI_IP && safi == SAFI_MULTICAST)
8217 return "IPv4 Multicast";
8218 else if (afi == AFI_IP && safi == SAFI_LABELED_UNICAST)
8219 return "IPv4 Labeled Unicast";
8220 else if (afi == AFI_IP && safi == SAFI_MPLS_VPN)
8221 return "IPv4 VPN";
8222 else if (afi == AFI_IP && safi == SAFI_ENCAP)
8223 return "IPv4 Encap";
8224 else if (afi == AFI_IP && safi == SAFI_FLOWSPEC)
8225 return "IPv4 Flowspec";
8226 else if (afi == AFI_IP6 && safi == SAFI_UNICAST)
8227 return "IPv6 Unicast";
8228 else if (afi == AFI_IP6 && safi == SAFI_MULTICAST)
8229 return "IPv6 Multicast";
8230 else if (afi == AFI_IP6 && safi == SAFI_LABELED_UNICAST)
8231 return "IPv6 Labeled Unicast";
8232 else if (afi == AFI_IP6 && safi == SAFI_MPLS_VPN)
8233 return "IPv6 VPN";
8234 else if (afi == AFI_IP6 && safi == SAFI_ENCAP)
8235 return "IPv6 Encap";
8236 else if (afi == AFI_IP6 && safi == SAFI_FLOWSPEC)
8237 return "IPv6 Flowspec";
8238 else if (afi == AFI_L2VPN && safi == SAFI_EVPN)
8239 return "L2VPN EVPN";
8240 else
8241 return "Unknown";
8242 }
8243
8244 /*
8245 * Please note that we have intentionally camelCased
8246 * the return strings here. So if you want
8247 * to use this function, please ensure you
8248 * are doing this within json output
8249 */
8250 const char *afi_safi_json(afi_t afi, safi_t safi)
8251 {
8252 if (afi == AFI_IP && safi == SAFI_UNICAST)
8253 return "ipv4Unicast";
8254 else if (afi == AFI_IP && safi == SAFI_MULTICAST)
8255 return "ipv4Multicast";
8256 else if (afi == AFI_IP && safi == SAFI_LABELED_UNICAST)
8257 return "ipv4LabeledUnicast";
8258 else if (afi == AFI_IP && safi == SAFI_MPLS_VPN)
8259 return "ipv4Vpn";
8260 else if (afi == AFI_IP && safi == SAFI_ENCAP)
8261 return "ipv4Encap";
8262 else if (afi == AFI_IP && safi == SAFI_FLOWSPEC)
8263 return "ipv4Flowspec";
8264 else if (afi == AFI_IP6 && safi == SAFI_UNICAST)
8265 return "ipv6Unicast";
8266 else if (afi == AFI_IP6 && safi == SAFI_MULTICAST)
8267 return "ipv6Multicast";
8268 else if (afi == AFI_IP6 && safi == SAFI_LABELED_UNICAST)
8269 return "ipv6LabeledUnicast";
8270 else if (afi == AFI_IP6 && safi == SAFI_MPLS_VPN)
8271 return "ipv6Vpn";
8272 else if (afi == AFI_IP6 && safi == SAFI_ENCAP)
8273 return "ipv6Encap";
8274 else if (afi == AFI_IP6 && safi == SAFI_FLOWSPEC)
8275 return "ipv6Flowspec";
8276 else if (afi == AFI_L2VPN && safi == SAFI_EVPN)
8277 return "l2VpnEvpn";
8278 else
8279 return "Unknown";
8280 }
8281
8282 /* Show BGP peer's information. */
8283 enum show_type { show_all, show_peer };
8284
8285 static void bgp_show_peer_afi_orf_cap(struct vty *vty, struct peer *p,
8286 afi_t afi, safi_t safi,
8287 uint16_t adv_smcap, uint16_t adv_rmcap,
8288 uint16_t rcv_smcap, uint16_t rcv_rmcap,
8289 uint8_t use_json, json_object *json_pref)
8290 {
8291 /* Send-Mode */
8292 if (CHECK_FLAG(p->af_cap[afi][safi], adv_smcap)
8293 || CHECK_FLAG(p->af_cap[afi][safi], rcv_smcap)) {
8294 if (use_json) {
8295 if (CHECK_FLAG(p->af_cap[afi][safi], adv_smcap)
8296 && CHECK_FLAG(p->af_cap[afi][safi], rcv_smcap))
8297 json_object_string_add(json_pref, "sendMode",
8298 "advertisedAndReceived");
8299 else if (CHECK_FLAG(p->af_cap[afi][safi], adv_smcap))
8300 json_object_string_add(json_pref, "sendMode",
8301 "advertised");
8302 else if (CHECK_FLAG(p->af_cap[afi][safi], rcv_smcap))
8303 json_object_string_add(json_pref, "sendMode",
8304 "received");
8305 } else {
8306 vty_out(vty, " Send-mode: ");
8307 if (CHECK_FLAG(p->af_cap[afi][safi], adv_smcap))
8308 vty_out(vty, "advertised");
8309 if (CHECK_FLAG(p->af_cap[afi][safi], rcv_smcap))
8310 vty_out(vty, "%sreceived",
8311 CHECK_FLAG(p->af_cap[afi][safi],
8312 adv_smcap)
8313 ? ", "
8314 : "");
8315 vty_out(vty, "\n");
8316 }
8317 }
8318
8319 /* Receive-Mode */
8320 if (CHECK_FLAG(p->af_cap[afi][safi], adv_rmcap)
8321 || CHECK_FLAG(p->af_cap[afi][safi], rcv_rmcap)) {
8322 if (use_json) {
8323 if (CHECK_FLAG(p->af_cap[afi][safi], adv_rmcap)
8324 && CHECK_FLAG(p->af_cap[afi][safi], rcv_rmcap))
8325 json_object_string_add(json_pref, "recvMode",
8326 "advertisedAndReceived");
8327 else if (CHECK_FLAG(p->af_cap[afi][safi], adv_rmcap))
8328 json_object_string_add(json_pref, "recvMode",
8329 "advertised");
8330 else if (CHECK_FLAG(p->af_cap[afi][safi], rcv_rmcap))
8331 json_object_string_add(json_pref, "recvMode",
8332 "received");
8333 } else {
8334 vty_out(vty, " Receive-mode: ");
8335 if (CHECK_FLAG(p->af_cap[afi][safi], adv_rmcap))
8336 vty_out(vty, "advertised");
8337 if (CHECK_FLAG(p->af_cap[afi][safi], rcv_rmcap))
8338 vty_out(vty, "%sreceived",
8339 CHECK_FLAG(p->af_cap[afi][safi],
8340 adv_rmcap)
8341 ? ", "
8342 : "");
8343 vty_out(vty, "\n");
8344 }
8345 }
8346 }
8347
8348 static void bgp_show_peer_afi(struct vty *vty, struct peer *p, afi_t afi,
8349 safi_t safi, uint8_t use_json,
8350 json_object *json_neigh)
8351 {
8352 struct bgp_filter *filter;
8353 struct peer_af *paf;
8354 char orf_pfx_name[BUFSIZ];
8355 int orf_pfx_count;
8356 json_object *json_af = NULL;
8357 json_object *json_prefA = NULL;
8358 json_object *json_prefB = NULL;
8359 json_object *json_addr = NULL;
8360
8361 if (use_json) {
8362 json_addr = json_object_new_object();
8363 json_af = json_object_new_object();
8364 filter = &p->filter[afi][safi];
8365
8366 if (peer_group_active(p))
8367 json_object_string_add(json_addr, "peerGroupMember",
8368 p->group->name);
8369
8370 paf = peer_af_find(p, afi, safi);
8371 if (paf && PAF_SUBGRP(paf)) {
8372 json_object_int_add(json_addr, "updateGroupId",
8373 PAF_UPDGRP(paf)->id);
8374 json_object_int_add(json_addr, "subGroupId",
8375 PAF_SUBGRP(paf)->id);
8376 json_object_int_add(json_addr, "packetQueueLength",
8377 bpacket_queue_virtual_length(paf));
8378 }
8379
8380 if (CHECK_FLAG(p->af_cap[afi][safi], PEER_CAP_ORF_PREFIX_SM_ADV)
8381 || CHECK_FLAG(p->af_cap[afi][safi],
8382 PEER_CAP_ORF_PREFIX_SM_RCV)
8383 || CHECK_FLAG(p->af_cap[afi][safi],
8384 PEER_CAP_ORF_PREFIX_RM_ADV)
8385 || CHECK_FLAG(p->af_cap[afi][safi],
8386 PEER_CAP_ORF_PREFIX_RM_RCV)) {
8387 json_object_int_add(json_af, "orfType",
8388 ORF_TYPE_PREFIX);
8389 json_prefA = json_object_new_object();
8390 bgp_show_peer_afi_orf_cap(vty, p, afi, safi,
8391 PEER_CAP_ORF_PREFIX_SM_ADV,
8392 PEER_CAP_ORF_PREFIX_RM_ADV,
8393 PEER_CAP_ORF_PREFIX_SM_RCV,
8394 PEER_CAP_ORF_PREFIX_RM_RCV,
8395 use_json, json_prefA);
8396 json_object_object_add(json_af, "orfPrefixList",
8397 json_prefA);
8398 }
8399
8400 if (CHECK_FLAG(p->af_cap[afi][safi], PEER_CAP_ORF_PREFIX_SM_ADV)
8401 || CHECK_FLAG(p->af_cap[afi][safi],
8402 PEER_CAP_ORF_PREFIX_SM_OLD_RCV)
8403 || CHECK_FLAG(p->af_cap[afi][safi],
8404 PEER_CAP_ORF_PREFIX_RM_ADV)
8405 || CHECK_FLAG(p->af_cap[afi][safi],
8406 PEER_CAP_ORF_PREFIX_RM_OLD_RCV)) {
8407 json_object_int_add(json_af, "orfOldType",
8408 ORF_TYPE_PREFIX_OLD);
8409 json_prefB = json_object_new_object();
8410 bgp_show_peer_afi_orf_cap(
8411 vty, p, afi, safi, PEER_CAP_ORF_PREFIX_SM_ADV,
8412 PEER_CAP_ORF_PREFIX_RM_ADV,
8413 PEER_CAP_ORF_PREFIX_SM_OLD_RCV,
8414 PEER_CAP_ORF_PREFIX_RM_OLD_RCV, use_json,
8415 json_prefB);
8416 json_object_object_add(json_af, "orfOldPrefixList",
8417 json_prefB);
8418 }
8419
8420 if (CHECK_FLAG(p->af_cap[afi][safi], PEER_CAP_ORF_PREFIX_SM_ADV)
8421 || CHECK_FLAG(p->af_cap[afi][safi],
8422 PEER_CAP_ORF_PREFIX_SM_RCV)
8423 || CHECK_FLAG(p->af_cap[afi][safi],
8424 PEER_CAP_ORF_PREFIX_SM_OLD_RCV)
8425 || CHECK_FLAG(p->af_cap[afi][safi],
8426 PEER_CAP_ORF_PREFIX_RM_ADV)
8427 || CHECK_FLAG(p->af_cap[afi][safi],
8428 PEER_CAP_ORF_PREFIX_RM_RCV)
8429 || CHECK_FLAG(p->af_cap[afi][safi],
8430 PEER_CAP_ORF_PREFIX_RM_OLD_RCV))
8431 json_object_object_add(json_addr, "afDependentCap",
8432 json_af);
8433 else
8434 json_object_free(json_af);
8435
8436 sprintf(orf_pfx_name, "%s.%d.%d", p->host, afi, safi);
8437 orf_pfx_count = prefix_bgp_show_prefix_list(
8438 NULL, afi, orf_pfx_name, use_json);
8439
8440 if (CHECK_FLAG(p->af_sflags[afi][safi],
8441 PEER_STATUS_ORF_PREFIX_SEND)
8442 || orf_pfx_count) {
8443 if (CHECK_FLAG(p->af_sflags[afi][safi],
8444 PEER_STATUS_ORF_PREFIX_SEND))
8445 json_object_boolean_true_add(json_neigh,
8446 "orfSent");
8447 if (orf_pfx_count)
8448 json_object_int_add(json_addr, "orfRecvCounter",
8449 orf_pfx_count);
8450 }
8451 if (CHECK_FLAG(p->af_sflags[afi][safi],
8452 PEER_STATUS_ORF_WAIT_REFRESH))
8453 json_object_string_add(
8454 json_addr, "orfFirstUpdate",
8455 "deferredUntilORFOrRouteRefreshRecvd");
8456
8457 if (CHECK_FLAG(p->af_flags[afi][safi],
8458 PEER_FLAG_REFLECTOR_CLIENT))
8459 json_object_boolean_true_add(json_addr,
8460 "routeReflectorClient");
8461 if (CHECK_FLAG(p->af_flags[afi][safi],
8462 PEER_FLAG_RSERVER_CLIENT))
8463 json_object_boolean_true_add(json_addr,
8464 "routeServerClient");
8465 if (CHECK_FLAG(p->af_flags[afi][safi], PEER_FLAG_SOFT_RECONFIG))
8466 json_object_boolean_true_add(json_addr,
8467 "inboundSoftConfigPermit");
8468
8469 if (CHECK_FLAG(p->af_flags[afi][safi],
8470 PEER_FLAG_REMOVE_PRIVATE_AS_ALL_REPLACE))
8471 json_object_boolean_true_add(
8472 json_addr,
8473 "privateAsNumsAllReplacedInUpdatesToNbr");
8474 else if (CHECK_FLAG(p->af_flags[afi][safi],
8475 PEER_FLAG_REMOVE_PRIVATE_AS_REPLACE))
8476 json_object_boolean_true_add(
8477 json_addr,
8478 "privateAsNumsReplacedInUpdatesToNbr");
8479 else if (CHECK_FLAG(p->af_flags[afi][safi],
8480 PEER_FLAG_REMOVE_PRIVATE_AS_ALL))
8481 json_object_boolean_true_add(
8482 json_addr,
8483 "privateAsNumsAllRemovedInUpdatesToNbr");
8484 else if (CHECK_FLAG(p->af_flags[afi][safi],
8485 PEER_FLAG_REMOVE_PRIVATE_AS))
8486 json_object_boolean_true_add(
8487 json_addr,
8488 "privateAsNumsRemovedInUpdatesToNbr");
8489
8490 if (CHECK_FLAG(p->af_flags[afi][safi],
8491 PEER_FLAG_ADDPATH_TX_ALL_PATHS))
8492 json_object_boolean_true_add(json_addr,
8493 "addpathTxAllPaths");
8494
8495 if (CHECK_FLAG(p->af_flags[afi][safi],
8496 PEER_FLAG_ADDPATH_TX_BESTPATH_PER_AS))
8497 json_object_boolean_true_add(json_addr,
8498 "addpathTxBestpathPerAS");
8499
8500 if (CHECK_FLAG(p->af_flags[afi][safi], PEER_FLAG_AS_OVERRIDE))
8501 json_object_string_add(json_addr,
8502 "overrideASNsInOutboundUpdates",
8503 "ifAspathEqualRemoteAs");
8504
8505 if (CHECK_FLAG(p->af_flags[afi][safi], PEER_FLAG_NEXTHOP_SELF)
8506 || CHECK_FLAG(p->af_flags[afi][safi],
8507 PEER_FLAG_FORCE_NEXTHOP_SELF))
8508 json_object_boolean_true_add(json_addr,
8509 "routerAlwaysNextHop");
8510 if (CHECK_FLAG(p->af_flags[afi][safi],
8511 PEER_FLAG_AS_PATH_UNCHANGED))
8512 json_object_boolean_true_add(
8513 json_addr, "unchangedAsPathPropogatedToNbr");
8514 if (CHECK_FLAG(p->af_flags[afi][safi],
8515 PEER_FLAG_NEXTHOP_UNCHANGED))
8516 json_object_boolean_true_add(
8517 json_addr, "unchangedNextHopPropogatedToNbr");
8518 if (CHECK_FLAG(p->af_flags[afi][safi], PEER_FLAG_MED_UNCHANGED))
8519 json_object_boolean_true_add(
8520 json_addr, "unchangedMedPropogatedToNbr");
8521 if (CHECK_FLAG(p->af_flags[afi][safi], PEER_FLAG_SEND_COMMUNITY)
8522 || CHECK_FLAG(p->af_flags[afi][safi],
8523 PEER_FLAG_SEND_EXT_COMMUNITY)) {
8524 if (CHECK_FLAG(p->af_flags[afi][safi],
8525 PEER_FLAG_SEND_COMMUNITY)
8526 && CHECK_FLAG(p->af_flags[afi][safi],
8527 PEER_FLAG_SEND_EXT_COMMUNITY))
8528 json_object_string_add(json_addr,
8529 "commAttriSentToNbr",
8530 "extendedAndStandard");
8531 else if (CHECK_FLAG(p->af_flags[afi][safi],
8532 PEER_FLAG_SEND_EXT_COMMUNITY))
8533 json_object_string_add(json_addr,
8534 "commAttriSentToNbr",
8535 "extended");
8536 else
8537 json_object_string_add(json_addr,
8538 "commAttriSentToNbr",
8539 "standard");
8540 }
8541 if (CHECK_FLAG(p->af_flags[afi][safi],
8542 PEER_FLAG_DEFAULT_ORIGINATE)) {
8543 if (p->default_rmap[afi][safi].name)
8544 json_object_string_add(
8545 json_addr, "defaultRouteMap",
8546 p->default_rmap[afi][safi].name);
8547
8548 if (paf && PAF_SUBGRP(paf)
8549 && CHECK_FLAG(PAF_SUBGRP(paf)->sflags,
8550 SUBGRP_STATUS_DEFAULT_ORIGINATE))
8551 json_object_boolean_true_add(json_addr,
8552 "defaultSent");
8553 else
8554 json_object_boolean_true_add(json_addr,
8555 "defaultNotSent");
8556 }
8557
8558 if (afi == AFI_L2VPN && safi == SAFI_EVPN) {
8559 if (is_evpn_enabled())
8560 json_object_boolean_true_add(
8561 json_addr, "advertiseAllVnis");
8562 }
8563
8564 if (filter->plist[FILTER_IN].name
8565 || filter->dlist[FILTER_IN].name
8566 || filter->aslist[FILTER_IN].name
8567 || filter->map[RMAP_IN].name)
8568 json_object_boolean_true_add(json_addr,
8569 "inboundPathPolicyConfig");
8570 if (filter->plist[FILTER_OUT].name
8571 || filter->dlist[FILTER_OUT].name
8572 || filter->aslist[FILTER_OUT].name
8573 || filter->map[RMAP_OUT].name || filter->usmap.name)
8574 json_object_boolean_true_add(
8575 json_addr, "outboundPathPolicyConfig");
8576
8577 /* prefix-list */
8578 if (filter->plist[FILTER_IN].name)
8579 json_object_string_add(json_addr,
8580 "incomingUpdatePrefixFilterList",
8581 filter->plist[FILTER_IN].name);
8582 if (filter->plist[FILTER_OUT].name)
8583 json_object_string_add(json_addr,
8584 "outgoingUpdatePrefixFilterList",
8585 filter->plist[FILTER_OUT].name);
8586
8587 /* distribute-list */
8588 if (filter->dlist[FILTER_IN].name)
8589 json_object_string_add(
8590 json_addr, "incomingUpdateNetworkFilterList",
8591 filter->dlist[FILTER_IN].name);
8592 if (filter->dlist[FILTER_OUT].name)
8593 json_object_string_add(
8594 json_addr, "outgoingUpdateNetworkFilterList",
8595 filter->dlist[FILTER_OUT].name);
8596
8597 /* filter-list. */
8598 if (filter->aslist[FILTER_IN].name)
8599 json_object_string_add(json_addr,
8600 "incomingUpdateAsPathFilterList",
8601 filter->aslist[FILTER_IN].name);
8602 if (filter->aslist[FILTER_OUT].name)
8603 json_object_string_add(json_addr,
8604 "outgoingUpdateAsPathFilterList",
8605 filter->aslist[FILTER_OUT].name);
8606
8607 /* route-map. */
8608 if (filter->map[RMAP_IN].name)
8609 json_object_string_add(
8610 json_addr, "routeMapForIncomingAdvertisements",
8611 filter->map[RMAP_IN].name);
8612 if (filter->map[RMAP_OUT].name)
8613 json_object_string_add(
8614 json_addr, "routeMapForOutgoingAdvertisements",
8615 filter->map[RMAP_OUT].name);
8616
8617 /* unsuppress-map */
8618 if (filter->usmap.name)
8619 json_object_string_add(json_addr,
8620 "selectiveUnsuppressRouteMap",
8621 filter->usmap.name);
8622
8623 /* Receive prefix count */
8624 json_object_int_add(json_addr, "acceptedPrefixCounter",
8625 p->pcount[afi][safi]);
8626
8627 /* Maximum prefix */
8628 if (CHECK_FLAG(p->af_flags[afi][safi], PEER_FLAG_MAX_PREFIX)) {
8629 json_object_int_add(json_addr, "prefixAllowedMax",
8630 p->pmax[afi][safi]);
8631 if (CHECK_FLAG(p->af_flags[afi][safi],
8632 PEER_FLAG_MAX_PREFIX_WARNING))
8633 json_object_boolean_true_add(
8634 json_addr, "prefixAllowedMaxWarning");
8635 json_object_int_add(json_addr,
8636 "prefixAllowedWarningThresh",
8637 p->pmax_threshold[afi][safi]);
8638 if (p->pmax_restart[afi][safi])
8639 json_object_int_add(
8640 json_addr,
8641 "prefixAllowedRestartIntervalMsecs",
8642 p->pmax_restart[afi][safi] * 60000);
8643 }
8644 json_object_object_add(json_neigh, afi_safi_print(afi, safi),
8645 json_addr);
8646
8647 } else {
8648 filter = &p->filter[afi][safi];
8649
8650 vty_out(vty, " For address family: %s\n",
8651 afi_safi_print(afi, safi));
8652
8653 if (peer_group_active(p))
8654 vty_out(vty, " %s peer-group member\n",
8655 p->group->name);
8656
8657 paf = peer_af_find(p, afi, safi);
8658 if (paf && PAF_SUBGRP(paf)) {
8659 vty_out(vty, " Update group %" PRIu64
8660 ", subgroup %" PRIu64 "\n",
8661 PAF_UPDGRP(paf)->id, PAF_SUBGRP(paf)->id);
8662 vty_out(vty, " Packet Queue length %d\n",
8663 bpacket_queue_virtual_length(paf));
8664 } else {
8665 vty_out(vty, " Not part of any update group\n");
8666 }
8667 if (CHECK_FLAG(p->af_cap[afi][safi], PEER_CAP_ORF_PREFIX_SM_ADV)
8668 || CHECK_FLAG(p->af_cap[afi][safi],
8669 PEER_CAP_ORF_PREFIX_SM_RCV)
8670 || CHECK_FLAG(p->af_cap[afi][safi],
8671 PEER_CAP_ORF_PREFIX_SM_OLD_RCV)
8672 || CHECK_FLAG(p->af_cap[afi][safi],
8673 PEER_CAP_ORF_PREFIX_RM_ADV)
8674 || CHECK_FLAG(p->af_cap[afi][safi],
8675 PEER_CAP_ORF_PREFIX_RM_RCV)
8676 || CHECK_FLAG(p->af_cap[afi][safi],
8677 PEER_CAP_ORF_PREFIX_RM_OLD_RCV))
8678 vty_out(vty, " AF-dependant capabilities:\n");
8679
8680 if (CHECK_FLAG(p->af_cap[afi][safi], PEER_CAP_ORF_PREFIX_SM_ADV)
8681 || CHECK_FLAG(p->af_cap[afi][safi],
8682 PEER_CAP_ORF_PREFIX_SM_RCV)
8683 || CHECK_FLAG(p->af_cap[afi][safi],
8684 PEER_CAP_ORF_PREFIX_RM_ADV)
8685 || CHECK_FLAG(p->af_cap[afi][safi],
8686 PEER_CAP_ORF_PREFIX_RM_RCV)) {
8687 vty_out(vty,
8688 " Outbound Route Filter (ORF) type (%d) Prefix-list:\n",
8689 ORF_TYPE_PREFIX);
8690 bgp_show_peer_afi_orf_cap(
8691 vty, p, afi, safi, PEER_CAP_ORF_PREFIX_SM_ADV,
8692 PEER_CAP_ORF_PREFIX_RM_ADV,
8693 PEER_CAP_ORF_PREFIX_SM_RCV,
8694 PEER_CAP_ORF_PREFIX_RM_RCV, use_json, NULL);
8695 }
8696 if (CHECK_FLAG(p->af_cap[afi][safi], PEER_CAP_ORF_PREFIX_SM_ADV)
8697 || CHECK_FLAG(p->af_cap[afi][safi],
8698 PEER_CAP_ORF_PREFIX_SM_OLD_RCV)
8699 || CHECK_FLAG(p->af_cap[afi][safi],
8700 PEER_CAP_ORF_PREFIX_RM_ADV)
8701 || CHECK_FLAG(p->af_cap[afi][safi],
8702 PEER_CAP_ORF_PREFIX_RM_OLD_RCV)) {
8703 vty_out(vty,
8704 " Outbound Route Filter (ORF) type (%d) Prefix-list:\n",
8705 ORF_TYPE_PREFIX_OLD);
8706 bgp_show_peer_afi_orf_cap(
8707 vty, p, afi, safi, PEER_CAP_ORF_PREFIX_SM_ADV,
8708 PEER_CAP_ORF_PREFIX_RM_ADV,
8709 PEER_CAP_ORF_PREFIX_SM_OLD_RCV,
8710 PEER_CAP_ORF_PREFIX_RM_OLD_RCV, use_json, NULL);
8711 }
8712
8713 sprintf(orf_pfx_name, "%s.%d.%d", p->host, afi, safi);
8714 orf_pfx_count = prefix_bgp_show_prefix_list(
8715 NULL, afi, orf_pfx_name, use_json);
8716
8717 if (CHECK_FLAG(p->af_sflags[afi][safi],
8718 PEER_STATUS_ORF_PREFIX_SEND)
8719 || orf_pfx_count) {
8720 vty_out(vty, " Outbound Route Filter (ORF):");
8721 if (CHECK_FLAG(p->af_sflags[afi][safi],
8722 PEER_STATUS_ORF_PREFIX_SEND))
8723 vty_out(vty, " sent;");
8724 if (orf_pfx_count)
8725 vty_out(vty, " received (%d entries)",
8726 orf_pfx_count);
8727 vty_out(vty, "\n");
8728 }
8729 if (CHECK_FLAG(p->af_sflags[afi][safi],
8730 PEER_STATUS_ORF_WAIT_REFRESH))
8731 vty_out(vty,
8732 " First update is deferred until ORF or ROUTE-REFRESH is received\n");
8733
8734 if (CHECK_FLAG(p->af_flags[afi][safi],
8735 PEER_FLAG_REFLECTOR_CLIENT))
8736 vty_out(vty, " Route-Reflector Client\n");
8737 if (CHECK_FLAG(p->af_flags[afi][safi],
8738 PEER_FLAG_RSERVER_CLIENT))
8739 vty_out(vty, " Route-Server Client\n");
8740 if (CHECK_FLAG(p->af_flags[afi][safi], PEER_FLAG_SOFT_RECONFIG))
8741 vty_out(vty,
8742 " Inbound soft reconfiguration allowed\n");
8743
8744 if (CHECK_FLAG(p->af_flags[afi][safi],
8745 PEER_FLAG_REMOVE_PRIVATE_AS_ALL_REPLACE))
8746 vty_out(vty,
8747 " Private AS numbers (all) replaced in updates to this neighbor\n");
8748 else if (CHECK_FLAG(p->af_flags[afi][safi],
8749 PEER_FLAG_REMOVE_PRIVATE_AS_REPLACE))
8750 vty_out(vty,
8751 " Private AS numbers replaced in updates to this neighbor\n");
8752 else if (CHECK_FLAG(p->af_flags[afi][safi],
8753 PEER_FLAG_REMOVE_PRIVATE_AS_ALL))
8754 vty_out(vty,
8755 " Private AS numbers (all) removed in updates to this neighbor\n");
8756 else if (CHECK_FLAG(p->af_flags[afi][safi],
8757 PEER_FLAG_REMOVE_PRIVATE_AS))
8758 vty_out(vty,
8759 " Private AS numbers removed in updates to this neighbor\n");
8760
8761 if (CHECK_FLAG(p->af_flags[afi][safi],
8762 PEER_FLAG_ADDPATH_TX_ALL_PATHS))
8763 vty_out(vty, " Advertise all paths via addpath\n");
8764
8765 if (CHECK_FLAG(p->af_flags[afi][safi],
8766 PEER_FLAG_ADDPATH_TX_BESTPATH_PER_AS))
8767 vty_out(vty,
8768 " Advertise bestpath per AS via addpath\n");
8769
8770 if (CHECK_FLAG(p->af_flags[afi][safi], PEER_FLAG_AS_OVERRIDE))
8771 vty_out(vty,
8772 " Override ASNs in outbound updates if aspath equals remote-as\n");
8773
8774 if (CHECK_FLAG(p->af_flags[afi][safi], PEER_FLAG_NEXTHOP_SELF)
8775 || CHECK_FLAG(p->af_flags[afi][safi],
8776 PEER_FLAG_FORCE_NEXTHOP_SELF))
8777 vty_out(vty, " NEXT_HOP is always this router\n");
8778 if (CHECK_FLAG(p->af_flags[afi][safi],
8779 PEER_FLAG_AS_PATH_UNCHANGED))
8780 vty_out(vty,
8781 " AS_PATH is propagated unchanged to this neighbor\n");
8782 if (CHECK_FLAG(p->af_flags[afi][safi],
8783 PEER_FLAG_NEXTHOP_UNCHANGED))
8784 vty_out(vty,
8785 " NEXT_HOP is propagated unchanged to this neighbor\n");
8786 if (CHECK_FLAG(p->af_flags[afi][safi], PEER_FLAG_MED_UNCHANGED))
8787 vty_out(vty,
8788 " MED is propagated unchanged to this neighbor\n");
8789 if (CHECK_FLAG(p->af_flags[afi][safi], PEER_FLAG_SEND_COMMUNITY)
8790 || CHECK_FLAG(p->af_flags[afi][safi],
8791 PEER_FLAG_SEND_EXT_COMMUNITY)
8792 || CHECK_FLAG(p->af_flags[afi][safi],
8793 PEER_FLAG_SEND_LARGE_COMMUNITY)) {
8794 vty_out(vty,
8795 " Community attribute sent to this neighbor");
8796 if (CHECK_FLAG(p->af_flags[afi][safi],
8797 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, "(all)\n");
8803 else if (CHECK_FLAG(p->af_flags[afi][safi],
8804 PEER_FLAG_SEND_LARGE_COMMUNITY))
8805 vty_out(vty, "(large)\n");
8806 else if (CHECK_FLAG(p->af_flags[afi][safi],
8807 PEER_FLAG_SEND_EXT_COMMUNITY))
8808 vty_out(vty, "(extended)\n");
8809 else
8810 vty_out(vty, "(standard)\n");
8811 }
8812 if (CHECK_FLAG(p->af_flags[afi][safi],
8813 PEER_FLAG_DEFAULT_ORIGINATE)) {
8814 vty_out(vty, " Default information originate,");
8815
8816 if (p->default_rmap[afi][safi].name)
8817 vty_out(vty, " default route-map %s%s,",
8818 p->default_rmap[afi][safi].map ? "*"
8819 : "",
8820 p->default_rmap[afi][safi].name);
8821 if (paf && PAF_SUBGRP(paf)
8822 && CHECK_FLAG(PAF_SUBGRP(paf)->sflags,
8823 SUBGRP_STATUS_DEFAULT_ORIGINATE))
8824 vty_out(vty, " default sent\n");
8825 else
8826 vty_out(vty, " default not sent\n");
8827 }
8828
8829 /* advertise-vni-all */
8830 if (afi == AFI_L2VPN && safi == SAFI_EVPN) {
8831 if (is_evpn_enabled())
8832 vty_out(vty, " advertise-all-vni\n");
8833 }
8834
8835 if (filter->plist[FILTER_IN].name
8836 || filter->dlist[FILTER_IN].name
8837 || filter->aslist[FILTER_IN].name
8838 || filter->map[RMAP_IN].name)
8839 vty_out(vty, " Inbound path policy configured\n");
8840 if (filter->plist[FILTER_OUT].name
8841 || filter->dlist[FILTER_OUT].name
8842 || filter->aslist[FILTER_OUT].name
8843 || filter->map[RMAP_OUT].name || filter->usmap.name)
8844 vty_out(vty, " Outbound path policy configured\n");
8845
8846 /* prefix-list */
8847 if (filter->plist[FILTER_IN].name)
8848 vty_out(vty,
8849 " Incoming update prefix filter list is %s%s\n",
8850 filter->plist[FILTER_IN].plist ? "*" : "",
8851 filter->plist[FILTER_IN].name);
8852 if (filter->plist[FILTER_OUT].name)
8853 vty_out(vty,
8854 " Outgoing update prefix filter list is %s%s\n",
8855 filter->plist[FILTER_OUT].plist ? "*" : "",
8856 filter->plist[FILTER_OUT].name);
8857
8858 /* distribute-list */
8859 if (filter->dlist[FILTER_IN].name)
8860 vty_out(vty,
8861 " Incoming update network filter list is %s%s\n",
8862 filter->dlist[FILTER_IN].alist ? "*" : "",
8863 filter->dlist[FILTER_IN].name);
8864 if (filter->dlist[FILTER_OUT].name)
8865 vty_out(vty,
8866 " Outgoing update network filter list is %s%s\n",
8867 filter->dlist[FILTER_OUT].alist ? "*" : "",
8868 filter->dlist[FILTER_OUT].name);
8869
8870 /* filter-list. */
8871 if (filter->aslist[FILTER_IN].name)
8872 vty_out(vty,
8873 " Incoming update AS path filter list is %s%s\n",
8874 filter->aslist[FILTER_IN].aslist ? "*" : "",
8875 filter->aslist[FILTER_IN].name);
8876 if (filter->aslist[FILTER_OUT].name)
8877 vty_out(vty,
8878 " Outgoing update AS path filter list is %s%s\n",
8879 filter->aslist[FILTER_OUT].aslist ? "*" : "",
8880 filter->aslist[FILTER_OUT].name);
8881
8882 /* route-map. */
8883 if (filter->map[RMAP_IN].name)
8884 vty_out(vty,
8885 " Route map for incoming advertisements is %s%s\n",
8886 filter->map[RMAP_IN].map ? "*" : "",
8887 filter->map[RMAP_IN].name);
8888 if (filter->map[RMAP_OUT].name)
8889 vty_out(vty,
8890 " Route map for outgoing advertisements is %s%s\n",
8891 filter->map[RMAP_OUT].map ? "*" : "",
8892 filter->map[RMAP_OUT].name);
8893
8894 /* unsuppress-map */
8895 if (filter->usmap.name)
8896 vty_out(vty,
8897 " Route map for selective unsuppress is %s%s\n",
8898 filter->usmap.map ? "*" : "",
8899 filter->usmap.name);
8900
8901 /* Receive prefix count */
8902 vty_out(vty, " %ld accepted prefixes\n", p->pcount[afi][safi]);
8903
8904 /* Maximum prefix */
8905 if (CHECK_FLAG(p->af_flags[afi][safi], PEER_FLAG_MAX_PREFIX)) {
8906 vty_out(vty, " Maximum prefixes allowed %ld%s\n",
8907 p->pmax[afi][safi],
8908 CHECK_FLAG(p->af_flags[afi][safi],
8909 PEER_FLAG_MAX_PREFIX_WARNING)
8910 ? " (warning-only)"
8911 : "");
8912 vty_out(vty, " Threshold for warning message %d%%",
8913 p->pmax_threshold[afi][safi]);
8914 if (p->pmax_restart[afi][safi])
8915 vty_out(vty, ", restart interval %d min",
8916 p->pmax_restart[afi][safi]);
8917 vty_out(vty, "\n");
8918 }
8919
8920 vty_out(vty, "\n");
8921 }
8922 }
8923
8924 static void bgp_show_peer(struct vty *vty, struct peer *p, uint8_t use_json,
8925 json_object *json)
8926 {
8927 struct bgp *bgp;
8928 char buf1[PREFIX2STR_BUFFER], buf[SU_ADDRSTRLEN];
8929 char timebuf[BGP_UPTIME_LEN];
8930 char dn_flag[2];
8931 const char *subcode_str;
8932 const char *code_str;
8933 afi_t afi;
8934 safi_t safi;
8935 uint16_t i;
8936 uint8_t *msg;
8937 json_object *json_neigh = NULL;
8938 time_t epoch_tbuf;
8939
8940 bgp = p->bgp;
8941
8942 if (use_json)
8943 json_neigh = json_object_new_object();
8944
8945 memset(dn_flag, '\0', sizeof(dn_flag));
8946 if (!p->conf_if && peer_dynamic_neighbor(p))
8947 dn_flag[0] = '*';
8948
8949 if (!use_json) {
8950 if (p->conf_if) /* Configured interface name. */
8951 vty_out(vty, "BGP neighbor on %s: %s, ", p->conf_if,
8952 BGP_PEER_SU_UNSPEC(p)
8953 ? "None"
8954 : sockunion2str(&p->su, buf,
8955 SU_ADDRSTRLEN));
8956 else /* Configured IP address. */
8957 vty_out(vty, "BGP neighbor is %s%s, ", dn_flag,
8958 p->host);
8959 }
8960
8961 if (use_json) {
8962 if (p->conf_if && BGP_PEER_SU_UNSPEC(p))
8963 json_object_string_add(json_neigh, "bgpNeighborAddr",
8964 "none");
8965 else if (p->conf_if && !BGP_PEER_SU_UNSPEC(p))
8966 json_object_string_add(
8967 json_neigh, "bgpNeighborAddr",
8968 sockunion2str(&p->su, buf, SU_ADDRSTRLEN));
8969
8970 json_object_int_add(json_neigh, "remoteAs", p->as);
8971
8972 if (p->change_local_as)
8973 json_object_int_add(json_neigh, "localAs",
8974 p->change_local_as);
8975 else
8976 json_object_int_add(json_neigh, "localAs", p->local_as);
8977
8978 if (CHECK_FLAG(p->flags, PEER_FLAG_LOCAL_AS_NO_PREPEND))
8979 json_object_boolean_true_add(json_neigh,
8980 "localAsNoPrepend");
8981
8982 if (CHECK_FLAG(p->flags, PEER_FLAG_LOCAL_AS_REPLACE_AS))
8983 json_object_boolean_true_add(json_neigh,
8984 "localAsReplaceAs");
8985 } else {
8986 if ((p->as_type == AS_SPECIFIED) || (p->as_type == AS_EXTERNAL)
8987 || (p->as_type == AS_INTERNAL))
8988 vty_out(vty, "remote AS %u, ", p->as);
8989 else
8990 vty_out(vty, "remote AS Unspecified, ");
8991 vty_out(vty, "local AS %u%s%s, ",
8992 p->change_local_as ? p->change_local_as : p->local_as,
8993 CHECK_FLAG(p->flags, PEER_FLAG_LOCAL_AS_NO_PREPEND)
8994 ? " no-prepend"
8995 : "",
8996 CHECK_FLAG(p->flags, PEER_FLAG_LOCAL_AS_REPLACE_AS)
8997 ? " replace-as"
8998 : "");
8999 }
9000 /* peer type internal, external, confed-internal or confed-external */
9001 if (p->as == p->local_as) {
9002 if (use_json) {
9003 if (CHECK_FLAG(bgp->config, BGP_CONFIG_CONFEDERATION))
9004 json_object_boolean_true_add(
9005 json_neigh, "nbrConfedInternalLink");
9006 else
9007 json_object_boolean_true_add(json_neigh,
9008 "nbrInternalLink");
9009 } else {
9010 if (CHECK_FLAG(bgp->config, BGP_CONFIG_CONFEDERATION))
9011 vty_out(vty, "confed-internal link\n");
9012 else
9013 vty_out(vty, "internal link\n");
9014 }
9015 } else {
9016 if (use_json) {
9017 if (CHECK_FLAG(bgp->config, BGP_CONFIG_CONFEDERATION))
9018 json_object_boolean_true_add(
9019 json_neigh, "nbrConfedExternalLink");
9020 else
9021 json_object_boolean_true_add(json_neigh,
9022 "nbrExternalLink");
9023 } else {
9024 if (bgp_confederation_peers_check(bgp, p->as))
9025 vty_out(vty, "confed-external link\n");
9026 else
9027 vty_out(vty, "external link\n");
9028 }
9029 }
9030
9031 /* Description. */
9032 if (p->desc) {
9033 if (use_json)
9034 json_object_string_add(json_neigh, "nbrDesc", p->desc);
9035 else
9036 vty_out(vty, " Description: %s\n", p->desc);
9037 }
9038
9039 if (p->hostname) {
9040 if (use_json) {
9041 if (p->hostname)
9042 json_object_string_add(json_neigh, "hostname",
9043 p->hostname);
9044
9045 if (p->domainname)
9046 json_object_string_add(json_neigh, "domainname",
9047 p->domainname);
9048 } else {
9049 if (p->domainname && (p->domainname[0] != '\0'))
9050 vty_out(vty, "Hostname: %s.%s\n", p->hostname,
9051 p->domainname);
9052 else
9053 vty_out(vty, "Hostname: %s\n", p->hostname);
9054 }
9055 }
9056
9057 /* Peer-group */
9058 if (p->group) {
9059 if (use_json) {
9060 json_object_string_add(json_neigh, "peerGroup",
9061 p->group->name);
9062
9063 if (dn_flag[0]) {
9064 struct prefix prefix, *range = NULL;
9065
9066 sockunion2hostprefix(&(p->su), &prefix);
9067 range = peer_group_lookup_dynamic_neighbor_range(
9068 p->group, &prefix);
9069
9070 if (range) {
9071 prefix2str(range, buf1, sizeof(buf1));
9072 json_object_string_add(
9073 json_neigh,
9074 "peerSubnetRangeGroup", buf1);
9075 }
9076 }
9077 } else {
9078 vty_out(vty,
9079 " Member of peer-group %s for session parameters\n",
9080 p->group->name);
9081
9082 if (dn_flag[0]) {
9083 struct prefix prefix, *range = NULL;
9084
9085 sockunion2hostprefix(&(p->su), &prefix);
9086 range = peer_group_lookup_dynamic_neighbor_range(
9087 p->group, &prefix);
9088
9089 if (range) {
9090 prefix2str(range, buf1, sizeof(buf1));
9091 vty_out(vty,
9092 " Belongs to the subnet range group: %s\n",
9093 buf1);
9094 }
9095 }
9096 }
9097 }
9098
9099 if (use_json) {
9100 /* Administrative shutdown. */
9101 if (CHECK_FLAG(p->flags, PEER_FLAG_SHUTDOWN))
9102 json_object_boolean_true_add(json_neigh,
9103 "adminShutDown");
9104
9105 /* BGP Version. */
9106 json_object_int_add(json_neigh, "bgpVersion", 4);
9107 json_object_string_add(
9108 json_neigh, "remoteRouterId",
9109 inet_ntop(AF_INET, &p->remote_id, buf1, sizeof(buf1)));
9110
9111 /* Confederation */
9112 if (CHECK_FLAG(bgp->config, BGP_CONFIG_CONFEDERATION)
9113 && bgp_confederation_peers_check(bgp, p->as))
9114 json_object_boolean_true_add(json_neigh,
9115 "nbrCommonAdmin");
9116
9117 /* Status. */
9118 json_object_string_add(
9119 json_neigh, "bgpState",
9120 lookup_msg(bgp_status_msg, p->status, NULL));
9121
9122 if (p->status == Established) {
9123 time_t uptime;
9124
9125 uptime = bgp_clock();
9126 uptime -= p->uptime;
9127 epoch_tbuf = time(NULL) - uptime;
9128
9129 #if defined(VERSION_TYPE_DEV) && CONFDATE > 20200101
9130 CPP_NOTICE(
9131 "bgpTimerUp should be deprecated and can be removed now");
9132 #endif
9133 /*
9134 * bgpTimerUp was miliseconds that was accurate
9135 * up to 1 day, then the value returned
9136 * became garbage. So in order to provide
9137 * some level of backwards compatability,
9138 * we still provde the data, but now
9139 * we are returning the correct value
9140 * and also adding a new bgpTimerUpMsec
9141 * which will allow us to deprecate
9142 * this eventually
9143 */
9144 json_object_int_add(json_neigh, "bgpTimerUp",
9145 uptime * 1000);
9146 json_object_int_add(json_neigh, "bgpTimerUpMsec",
9147 uptime * 1000);
9148 json_object_string_add(json_neigh, "bgpTimerUpString",
9149 peer_uptime(p->uptime, timebuf,
9150 BGP_UPTIME_LEN, 0,
9151 NULL));
9152 json_object_int_add(json_neigh,
9153 "bgpTimerUpEstablishedEpoch",
9154 epoch_tbuf);
9155 }
9156
9157 else if (p->status == Active) {
9158 if (CHECK_FLAG(p->flags, PEER_FLAG_PASSIVE))
9159 json_object_string_add(json_neigh, "bgpStateIs",
9160 "passive");
9161 else if (CHECK_FLAG(p->sflags, PEER_STATUS_NSF_WAIT))
9162 json_object_string_add(json_neigh, "bgpStateIs",
9163 "passiveNSF");
9164 }
9165
9166 /* read timer */
9167 time_t uptime;
9168 struct tm *tm;
9169
9170 uptime = bgp_clock();
9171 uptime -= p->readtime;
9172 tm = gmtime(&uptime);
9173 json_object_int_add(json_neigh, "bgpTimerLastRead",
9174 (tm->tm_sec * 1000) + (tm->tm_min * 60000)
9175 + (tm->tm_hour * 3600000));
9176
9177 uptime = bgp_clock();
9178 uptime -= p->last_write;
9179 tm = gmtime(&uptime);
9180 json_object_int_add(json_neigh, "bgpTimerLastWrite",
9181 (tm->tm_sec * 1000) + (tm->tm_min * 60000)
9182 + (tm->tm_hour * 3600000));
9183
9184 uptime = bgp_clock();
9185 uptime -= p->update_time;
9186 tm = gmtime(&uptime);
9187 json_object_int_add(json_neigh, "bgpInUpdateElapsedTimeMsecs",
9188 (tm->tm_sec * 1000) + (tm->tm_min * 60000)
9189 + (tm->tm_hour * 3600000));
9190
9191 /* Configured timer values. */
9192 json_object_int_add(json_neigh, "bgpTimerHoldTimeMsecs",
9193 p->v_holdtime * 1000);
9194 json_object_int_add(json_neigh,
9195 "bgpTimerKeepAliveIntervalMsecs",
9196 p->v_keepalive * 1000);
9197 if (CHECK_FLAG(p->flags, PEER_FLAG_TIMER)) {
9198 json_object_int_add(json_neigh,
9199 "bgpTimerConfiguredHoldTimeMsecs",
9200 p->holdtime * 1000);
9201 json_object_int_add(
9202 json_neigh,
9203 "bgpTimerConfiguredKeepAliveIntervalMsecs",
9204 p->keepalive * 1000);
9205 } else if ((bgp->default_holdtime != BGP_DEFAULT_HOLDTIME)
9206 || (bgp->default_keepalive
9207 != BGP_DEFAULT_KEEPALIVE)) {
9208 json_object_int_add(json_neigh,
9209 "bgpTimerConfiguredHoldTimeMsecs",
9210 bgp->default_holdtime);
9211 json_object_int_add(
9212 json_neigh,
9213 "bgpTimerConfiguredKeepAliveIntervalMsecs",
9214 bgp->default_keepalive);
9215 }
9216 } else {
9217 /* Administrative shutdown. */
9218 if (CHECK_FLAG(p->flags, PEER_FLAG_SHUTDOWN))
9219 vty_out(vty, " Administratively shut down\n");
9220
9221 /* BGP Version. */
9222 vty_out(vty, " BGP version 4");
9223 vty_out(vty, ", remote router ID %s\n",
9224 inet_ntop(AF_INET, &p->remote_id, buf1, sizeof(buf1)));
9225
9226 /* Confederation */
9227 if (CHECK_FLAG(bgp->config, BGP_CONFIG_CONFEDERATION)
9228 && bgp_confederation_peers_check(bgp, p->as))
9229 vty_out(vty,
9230 " Neighbor under common administration\n");
9231
9232 /* Status. */
9233 vty_out(vty, " BGP state = %s",
9234 lookup_msg(bgp_status_msg, p->status, NULL));
9235
9236 if (p->status == Established)
9237 vty_out(vty, ", up for %8s",
9238 peer_uptime(p->uptime, timebuf, BGP_UPTIME_LEN,
9239 0, NULL));
9240
9241 else if (p->status == Active) {
9242 if (CHECK_FLAG(p->flags, PEER_FLAG_PASSIVE))
9243 vty_out(vty, " (passive)");
9244 else if (CHECK_FLAG(p->sflags, PEER_STATUS_NSF_WAIT))
9245 vty_out(vty, " (NSF passive)");
9246 }
9247 vty_out(vty, "\n");
9248
9249 /* read timer */
9250 vty_out(vty, " Last read %s",
9251 peer_uptime(p->readtime, timebuf, BGP_UPTIME_LEN, 0,
9252 NULL));
9253 vty_out(vty, ", Last write %s\n",
9254 peer_uptime(p->last_write, timebuf, BGP_UPTIME_LEN, 0,
9255 NULL));
9256
9257 /* Configured timer values. */
9258 vty_out(vty,
9259 " Hold time is %d, keepalive interval is %d seconds\n",
9260 p->v_holdtime, p->v_keepalive);
9261 if (CHECK_FLAG(p->flags, PEER_FLAG_TIMER)) {
9262 vty_out(vty, " Configured hold time is %d",
9263 p->holdtime);
9264 vty_out(vty, ", keepalive interval is %d seconds\n",
9265 p->keepalive);
9266 } else if ((bgp->default_holdtime != BGP_DEFAULT_HOLDTIME)
9267 || (bgp->default_keepalive
9268 != BGP_DEFAULT_KEEPALIVE)) {
9269 vty_out(vty, " Configured hold time is %d",
9270 bgp->default_holdtime);
9271 vty_out(vty, ", keepalive interval is %d seconds\n",
9272 bgp->default_keepalive);
9273 }
9274 }
9275 /* Capability. */
9276 if (p->status == Established) {
9277 if (p->cap || p->afc_adv[AFI_IP][SAFI_UNICAST]
9278 || p->afc_recv[AFI_IP][SAFI_UNICAST]
9279 || p->afc_adv[AFI_IP][SAFI_MULTICAST]
9280 || p->afc_recv[AFI_IP][SAFI_MULTICAST]
9281 || p->afc_adv[AFI_IP6][SAFI_UNICAST]
9282 || p->afc_recv[AFI_IP6][SAFI_UNICAST]
9283 || p->afc_adv[AFI_IP6][SAFI_MULTICAST]
9284 || p->afc_recv[AFI_IP6][SAFI_MULTICAST]
9285 || p->afc_adv[AFI_IP6][SAFI_MPLS_VPN]
9286 || p->afc_recv[AFI_IP6][SAFI_MPLS_VPN]
9287 || p->afc_adv[AFI_IP6][SAFI_ENCAP]
9288 || p->afc_recv[AFI_IP6][SAFI_ENCAP]
9289 || p->afc_adv[AFI_IP6][SAFI_FLOWSPEC]
9290 || p->afc_recv[AFI_IP6][SAFI_FLOWSPEC]
9291 || p->afc_adv[AFI_IP][SAFI_ENCAP]
9292 || p->afc_recv[AFI_IP][SAFI_ENCAP]
9293 || p->afc_adv[AFI_IP][SAFI_FLOWSPEC]
9294 || p->afc_recv[AFI_IP][SAFI_FLOWSPEC]
9295 || p->afc_adv[AFI_IP][SAFI_MPLS_VPN]
9296 || p->afc_recv[AFI_IP][SAFI_MPLS_VPN]) {
9297 if (use_json) {
9298 json_object *json_cap = NULL;
9299
9300 json_cap = json_object_new_object();
9301
9302 /* AS4 */
9303 if (CHECK_FLAG(p->cap, PEER_CAP_AS4_RCV)
9304 || CHECK_FLAG(p->cap, PEER_CAP_AS4_ADV)) {
9305 if (CHECK_FLAG(p->cap, PEER_CAP_AS4_ADV)
9306 && CHECK_FLAG(p->cap,
9307 PEER_CAP_AS4_RCV))
9308 json_object_string_add(
9309 json_cap, "4byteAs",
9310 "advertisedAndReceived");
9311 else if (CHECK_FLAG(p->cap,
9312 PEER_CAP_AS4_ADV))
9313 json_object_string_add(
9314 json_cap, "4byteAs",
9315 "advertised");
9316 else if (CHECK_FLAG(p->cap,
9317 PEER_CAP_AS4_RCV))
9318 json_object_string_add(
9319 json_cap, "4byteAs",
9320 "received");
9321 }
9322
9323 /* AddPath */
9324 if (CHECK_FLAG(p->cap, PEER_CAP_ADDPATH_RCV)
9325 || CHECK_FLAG(p->cap,
9326 PEER_CAP_ADDPATH_ADV)) {
9327 json_object *json_add = NULL;
9328 const char *print_store;
9329
9330 json_add = json_object_new_object();
9331
9332 FOREACH_AFI_SAFI (afi, safi) {
9333 json_object *json_sub = NULL;
9334 json_sub =
9335 json_object_new_object();
9336 print_store = afi_safi_print(
9337 afi, safi);
9338
9339 if (CHECK_FLAG(
9340 p->af_cap[afi]
9341 [safi],
9342 PEER_CAP_ADDPATH_AF_TX_ADV)
9343 || CHECK_FLAG(
9344 p->af_cap[afi]
9345 [safi],
9346 PEER_CAP_ADDPATH_AF_TX_RCV)) {
9347 if (CHECK_FLAG(
9348 p->af_cap
9349 [afi]
9350 [safi],
9351 PEER_CAP_ADDPATH_AF_TX_ADV)
9352 && CHECK_FLAG(
9353 p->af_cap
9354 [afi]
9355 [safi],
9356 PEER_CAP_ADDPATH_AF_TX_RCV))
9357 json_object_boolean_true_add(
9358 json_sub,
9359 "txAdvertisedAndReceived");
9360 else if (
9361 CHECK_FLAG(
9362 p->af_cap
9363 [afi]
9364 [safi],
9365 PEER_CAP_ADDPATH_AF_TX_ADV))
9366 json_object_boolean_true_add(
9367 json_sub,
9368 "txAdvertised");
9369 else if (
9370 CHECK_FLAG(
9371 p->af_cap
9372 [afi]
9373 [safi],
9374 PEER_CAP_ADDPATH_AF_TX_RCV))
9375 json_object_boolean_true_add(
9376 json_sub,
9377 "txReceived");
9378 }
9379
9380 if (CHECK_FLAG(
9381 p->af_cap[afi]
9382 [safi],
9383 PEER_CAP_ADDPATH_AF_RX_ADV)
9384 || CHECK_FLAG(
9385 p->af_cap[afi]
9386 [safi],
9387 PEER_CAP_ADDPATH_AF_RX_RCV)) {
9388 if (CHECK_FLAG(
9389 p->af_cap
9390 [afi]
9391 [safi],
9392 PEER_CAP_ADDPATH_AF_RX_ADV)
9393 && CHECK_FLAG(
9394 p->af_cap
9395 [afi]
9396 [safi],
9397 PEER_CAP_ADDPATH_AF_RX_RCV))
9398 json_object_boolean_true_add(
9399 json_sub,
9400 "rxAdvertisedAndReceived");
9401 else if (
9402 CHECK_FLAG(
9403 p->af_cap
9404 [afi]
9405 [safi],
9406 PEER_CAP_ADDPATH_AF_RX_ADV))
9407 json_object_boolean_true_add(
9408 json_sub,
9409 "rxAdvertised");
9410 else if (
9411 CHECK_FLAG(
9412 p->af_cap
9413 [afi]
9414 [safi],
9415 PEER_CAP_ADDPATH_AF_RX_RCV))
9416 json_object_boolean_true_add(
9417 json_sub,
9418 "rxReceived");
9419 }
9420
9421 if (CHECK_FLAG(
9422 p->af_cap[afi]
9423 [safi],
9424 PEER_CAP_ADDPATH_AF_TX_ADV)
9425 || CHECK_FLAG(
9426 p->af_cap[afi]
9427 [safi],
9428 PEER_CAP_ADDPATH_AF_TX_RCV)
9429 || CHECK_FLAG(
9430 p->af_cap[afi]
9431 [safi],
9432 PEER_CAP_ADDPATH_AF_RX_ADV)
9433 || CHECK_FLAG(
9434 p->af_cap[afi]
9435 [safi],
9436 PEER_CAP_ADDPATH_AF_RX_RCV))
9437 json_object_object_add(
9438 json_add,
9439 print_store,
9440 json_sub);
9441 else
9442 json_object_free(
9443 json_sub);
9444 }
9445
9446 json_object_object_add(
9447 json_cap, "addPath", json_add);
9448 }
9449
9450 /* Dynamic */
9451 if (CHECK_FLAG(p->cap, PEER_CAP_DYNAMIC_RCV)
9452 || CHECK_FLAG(p->cap,
9453 PEER_CAP_DYNAMIC_ADV)) {
9454 if (CHECK_FLAG(p->cap,
9455 PEER_CAP_DYNAMIC_ADV)
9456 && CHECK_FLAG(p->cap,
9457 PEER_CAP_DYNAMIC_RCV))
9458 json_object_string_add(
9459 json_cap, "dynamic",
9460 "advertisedAndReceived");
9461 else if (CHECK_FLAG(
9462 p->cap,
9463 PEER_CAP_DYNAMIC_ADV))
9464 json_object_string_add(
9465 json_cap, "dynamic",
9466 "advertised");
9467 else if (CHECK_FLAG(
9468 p->cap,
9469 PEER_CAP_DYNAMIC_RCV))
9470 json_object_string_add(
9471 json_cap, "dynamic",
9472 "received");
9473 }
9474
9475 /* Extended nexthop */
9476 if (CHECK_FLAG(p->cap, PEER_CAP_ENHE_RCV)
9477 || CHECK_FLAG(p->cap, PEER_CAP_ENHE_ADV)) {
9478 json_object *json_nxt = NULL;
9479 const char *print_store;
9480
9481
9482 if (CHECK_FLAG(p->cap,
9483 PEER_CAP_ENHE_ADV)
9484 && CHECK_FLAG(p->cap,
9485 PEER_CAP_ENHE_RCV))
9486 json_object_string_add(
9487 json_cap,
9488 "extendedNexthop",
9489 "advertisedAndReceived");
9490 else if (CHECK_FLAG(p->cap,
9491 PEER_CAP_ENHE_ADV))
9492 json_object_string_add(
9493 json_cap,
9494 "extendedNexthop",
9495 "advertised");
9496 else if (CHECK_FLAG(p->cap,
9497 PEER_CAP_ENHE_RCV))
9498 json_object_string_add(
9499 json_cap,
9500 "extendedNexthop",
9501 "received");
9502
9503 if (CHECK_FLAG(p->cap,
9504 PEER_CAP_ENHE_RCV)) {
9505 json_nxt =
9506 json_object_new_object();
9507
9508 for (safi = SAFI_UNICAST;
9509 safi < SAFI_MAX; safi++) {
9510 if (CHECK_FLAG(
9511 p->af_cap
9512 [AFI_IP]
9513 [safi],
9514 PEER_CAP_ENHE_AF_RCV)) {
9515 print_store = afi_safi_print(
9516 AFI_IP,
9517 safi);
9518 json_object_string_add(
9519 json_nxt,
9520 print_store,
9521 "recieved");
9522 }
9523 }
9524 json_object_object_add(
9525 json_cap,
9526 "extendedNexthopFamililesByPeer",
9527 json_nxt);
9528 }
9529 }
9530
9531 /* Route Refresh */
9532 if (CHECK_FLAG(p->cap, PEER_CAP_REFRESH_ADV)
9533 || CHECK_FLAG(p->cap,
9534 PEER_CAP_REFRESH_NEW_RCV)
9535 || CHECK_FLAG(p->cap,
9536 PEER_CAP_REFRESH_OLD_RCV)) {
9537 if (CHECK_FLAG(p->cap,
9538 PEER_CAP_REFRESH_ADV)
9539 && (CHECK_FLAG(
9540 p->cap,
9541 PEER_CAP_REFRESH_NEW_RCV)
9542 || CHECK_FLAG(
9543 p->cap,
9544 PEER_CAP_REFRESH_OLD_RCV))) {
9545 if (CHECK_FLAG(
9546 p->cap,
9547 PEER_CAP_REFRESH_OLD_RCV)
9548 && CHECK_FLAG(
9549 p->cap,
9550 PEER_CAP_REFRESH_NEW_RCV))
9551 json_object_string_add(
9552 json_cap,
9553 "routeRefresh",
9554 "advertisedAndReceivedOldNew");
9555 else {
9556 if (CHECK_FLAG(
9557 p->cap,
9558 PEER_CAP_REFRESH_OLD_RCV))
9559 json_object_string_add(
9560 json_cap,
9561 "routeRefresh",
9562 "advertisedAndReceivedOld");
9563 else
9564 json_object_string_add(
9565 json_cap,
9566 "routeRefresh",
9567 "advertisedAndReceivedNew");
9568 }
9569 } else if (
9570 CHECK_FLAG(
9571 p->cap,
9572 PEER_CAP_REFRESH_ADV))
9573 json_object_string_add(
9574 json_cap,
9575 "routeRefresh",
9576 "advertised");
9577 else if (
9578 CHECK_FLAG(
9579 p->cap,
9580 PEER_CAP_REFRESH_NEW_RCV)
9581 || CHECK_FLAG(
9582 p->cap,
9583 PEER_CAP_REFRESH_OLD_RCV))
9584 json_object_string_add(
9585 json_cap,
9586 "routeRefresh",
9587 "received");
9588 }
9589
9590 /* Multiprotocol Extensions */
9591 json_object *json_multi = NULL;
9592 json_multi = json_object_new_object();
9593
9594 FOREACH_AFI_SAFI (afi, safi) {
9595 if (p->afc_adv[afi][safi]
9596 || p->afc_recv[afi][safi]) {
9597 json_object *json_exten = NULL;
9598 json_exten =
9599 json_object_new_object();
9600
9601 if (p->afc_adv[afi][safi]
9602 && p->afc_recv[afi][safi])
9603 json_object_boolean_true_add(
9604 json_exten,
9605 "advertisedAndReceived");
9606 else if (p->afc_adv[afi][safi])
9607 json_object_boolean_true_add(
9608 json_exten,
9609 "advertised");
9610 else if (p->afc_recv[afi][safi])
9611 json_object_boolean_true_add(
9612 json_exten,
9613 "received");
9614
9615 json_object_object_add(
9616 json_multi,
9617 afi_safi_print(afi,
9618 safi),
9619 json_exten);
9620 }
9621 }
9622 json_object_object_add(
9623 json_cap, "multiprotocolExtensions",
9624 json_multi);
9625
9626 /* Hostname capabilities */
9627 json_object *json_hname = NULL;
9628
9629 json_hname = json_object_new_object();
9630
9631 if (CHECK_FLAG(p->cap, PEER_CAP_HOSTNAME_ADV)) {
9632 json_object_string_add(
9633 json_hname, "advHostName",
9634 bgp->peer_self->hostname
9635 ? bgp->peer_self
9636 ->hostname
9637 : "n/a");
9638 json_object_string_add(
9639 json_hname, "advDomainName",
9640 bgp->peer_self->domainname
9641 ? bgp->peer_self
9642 ->domainname
9643 : "n/a");
9644 }
9645
9646
9647 if (CHECK_FLAG(p->cap, PEER_CAP_HOSTNAME_RCV)) {
9648 json_object_string_add(
9649 json_hname, "rcvHostName",
9650 p->hostname ? p->hostname
9651 : "n/a");
9652 json_object_string_add(
9653 json_hname, "rcvDomainName",
9654 p->domainname ? p->domainname
9655 : "n/a");
9656 }
9657
9658 json_object_object_add(json_cap, "hostName",
9659 json_hname);
9660
9661 /* Gracefull Restart */
9662 if (CHECK_FLAG(p->cap, PEER_CAP_RESTART_RCV)
9663 || CHECK_FLAG(p->cap,
9664 PEER_CAP_RESTART_ADV)) {
9665 if (CHECK_FLAG(p->cap,
9666 PEER_CAP_RESTART_ADV)
9667 && CHECK_FLAG(p->cap,
9668 PEER_CAP_RESTART_RCV))
9669 json_object_string_add(
9670 json_cap,
9671 "gracefulRestart",
9672 "advertisedAndReceived");
9673 else if (CHECK_FLAG(
9674 p->cap,
9675 PEER_CAP_RESTART_ADV))
9676 json_object_string_add(
9677 json_cap,
9678 "gracefulRestartCapability",
9679 "advertised");
9680 else if (CHECK_FLAG(
9681 p->cap,
9682 PEER_CAP_RESTART_RCV))
9683 json_object_string_add(
9684 json_cap,
9685 "gracefulRestartCapability",
9686 "received");
9687
9688 if (CHECK_FLAG(p->cap,
9689 PEER_CAP_RESTART_RCV)) {
9690 int restart_af_count = 0;
9691 json_object *json_restart =
9692 NULL;
9693 json_restart =
9694 json_object_new_object();
9695
9696 json_object_int_add(
9697 json_cap,
9698 "gracefulRestartRemoteTimerMsecs",
9699 p->v_gr_restart * 1000);
9700
9701 FOREACH_AFI_SAFI (afi, safi) {
9702 if (CHECK_FLAG(
9703 p->af_cap
9704 [afi]
9705 [safi],
9706 PEER_CAP_RESTART_AF_RCV)) {
9707 json_object *
9708 json_sub =
9709 NULL;
9710 json_sub =
9711 json_object_new_object();
9712
9713 if (CHECK_FLAG(
9714 p->af_cap
9715 [afi]
9716 [safi],
9717 PEER_CAP_RESTART_AF_PRESERVE_RCV))
9718 json_object_boolean_true_add(
9719 json_sub,
9720 "preserved");
9721 restart_af_count++;
9722 json_object_object_add(
9723 json_restart,
9724 afi_safi_print(
9725 afi,
9726 safi),
9727 json_sub);
9728 }
9729 }
9730 if (!restart_af_count) {
9731 json_object_string_add(
9732 json_cap,
9733 "addressFamiliesByPeer",
9734 "none");
9735 json_object_free(
9736 json_restart);
9737 } else
9738 json_object_object_add(
9739 json_cap,
9740 "addressFamiliesByPeer",
9741 json_restart);
9742 }
9743 }
9744 json_object_object_add(json_neigh,
9745 "neighborCapabilities",
9746 json_cap);
9747 } else {
9748 vty_out(vty, " Neighbor capabilities:\n");
9749
9750 /* AS4 */
9751 if (CHECK_FLAG(p->cap, PEER_CAP_AS4_RCV)
9752 || CHECK_FLAG(p->cap, PEER_CAP_AS4_ADV)) {
9753 vty_out(vty, " 4 Byte AS:");
9754 if (CHECK_FLAG(p->cap,
9755 PEER_CAP_AS4_ADV))
9756 vty_out(vty, " advertised");
9757 if (CHECK_FLAG(p->cap,
9758 PEER_CAP_AS4_RCV))
9759 vty_out(vty, " %sreceived",
9760 CHECK_FLAG(
9761 p->cap,
9762 PEER_CAP_AS4_ADV)
9763 ? "and "
9764 : "");
9765 vty_out(vty, "\n");
9766 }
9767
9768 /* AddPath */
9769 if (CHECK_FLAG(p->cap, PEER_CAP_ADDPATH_RCV)
9770 || CHECK_FLAG(p->cap,
9771 PEER_CAP_ADDPATH_ADV)) {
9772 vty_out(vty, " AddPath:\n");
9773
9774 FOREACH_AFI_SAFI (afi, safi) {
9775 if (CHECK_FLAG(
9776 p->af_cap[afi]
9777 [safi],
9778 PEER_CAP_ADDPATH_AF_TX_ADV)
9779 || CHECK_FLAG(
9780 p->af_cap[afi]
9781 [safi],
9782 PEER_CAP_ADDPATH_AF_TX_RCV)) {
9783 vty_out(vty,
9784 " %s: TX ",
9785 afi_safi_print(
9786 afi,
9787 safi));
9788
9789 if (CHECK_FLAG(
9790 p->af_cap
9791 [afi]
9792 [safi],
9793 PEER_CAP_ADDPATH_AF_TX_ADV))
9794 vty_out(vty,
9795 "advertised %s",
9796 afi_safi_print(
9797 afi,
9798 safi));
9799
9800 if (CHECK_FLAG(
9801 p->af_cap
9802 [afi]
9803 [safi],
9804 PEER_CAP_ADDPATH_AF_TX_RCV))
9805 vty_out(vty,
9806 "%sreceived",
9807 CHECK_FLAG(
9808 p->af_cap
9809 [afi]
9810 [safi],
9811 PEER_CAP_ADDPATH_AF_TX_ADV)
9812 ? " and "
9813 : "");
9814
9815 vty_out(vty, "\n");
9816 }
9817
9818 if (CHECK_FLAG(
9819 p->af_cap[afi]
9820 [safi],
9821 PEER_CAP_ADDPATH_AF_RX_ADV)
9822 || CHECK_FLAG(
9823 p->af_cap[afi]
9824 [safi],
9825 PEER_CAP_ADDPATH_AF_RX_RCV)) {
9826 vty_out(vty,
9827 " %s: RX ",
9828 afi_safi_print(
9829 afi,
9830 safi));
9831
9832 if (CHECK_FLAG(
9833 p->af_cap
9834 [afi]
9835 [safi],
9836 PEER_CAP_ADDPATH_AF_RX_ADV))
9837 vty_out(vty,
9838 "advertised %s",
9839 afi_safi_print(
9840 afi,
9841 safi));
9842
9843 if (CHECK_FLAG(
9844 p->af_cap
9845 [afi]
9846 [safi],
9847 PEER_CAP_ADDPATH_AF_RX_RCV))
9848 vty_out(vty,
9849 "%sreceived",
9850 CHECK_FLAG(
9851 p->af_cap
9852 [afi]
9853 [safi],
9854 PEER_CAP_ADDPATH_AF_RX_ADV)
9855 ? " and "
9856 : "");
9857
9858 vty_out(vty, "\n");
9859 }
9860 }
9861 }
9862
9863 /* Dynamic */
9864 if (CHECK_FLAG(p->cap, PEER_CAP_DYNAMIC_RCV)
9865 || CHECK_FLAG(p->cap,
9866 PEER_CAP_DYNAMIC_ADV)) {
9867 vty_out(vty, " Dynamic:");
9868 if (CHECK_FLAG(p->cap,
9869 PEER_CAP_DYNAMIC_ADV))
9870 vty_out(vty, " advertised");
9871 if (CHECK_FLAG(p->cap,
9872 PEER_CAP_DYNAMIC_RCV))
9873 vty_out(vty, " %sreceived",
9874 CHECK_FLAG(
9875 p->cap,
9876 PEER_CAP_DYNAMIC_ADV)
9877 ? "and "
9878 : "");
9879 vty_out(vty, "\n");
9880 }
9881
9882 /* Extended nexthop */
9883 if (CHECK_FLAG(p->cap, PEER_CAP_ENHE_RCV)
9884 || CHECK_FLAG(p->cap, PEER_CAP_ENHE_ADV)) {
9885 vty_out(vty, " Extended nexthop:");
9886 if (CHECK_FLAG(p->cap,
9887 PEER_CAP_ENHE_ADV))
9888 vty_out(vty, " advertised");
9889 if (CHECK_FLAG(p->cap,
9890 PEER_CAP_ENHE_RCV))
9891 vty_out(vty, " %sreceived",
9892 CHECK_FLAG(
9893 p->cap,
9894 PEER_CAP_ENHE_ADV)
9895 ? "and "
9896 : "");
9897 vty_out(vty, "\n");
9898
9899 if (CHECK_FLAG(p->cap,
9900 PEER_CAP_ENHE_RCV)) {
9901 vty_out(vty,
9902 " Address families by peer:\n ");
9903 for (safi = SAFI_UNICAST;
9904 safi < SAFI_MAX; safi++)
9905 if (CHECK_FLAG(
9906 p->af_cap
9907 [AFI_IP]
9908 [safi],
9909 PEER_CAP_ENHE_AF_RCV))
9910 vty_out(vty,
9911 " %s\n",
9912 afi_safi_print(
9913 AFI_IP,
9914 safi));
9915 }
9916 }
9917
9918 /* Route Refresh */
9919 if (CHECK_FLAG(p->cap, PEER_CAP_REFRESH_ADV)
9920 || CHECK_FLAG(p->cap,
9921 PEER_CAP_REFRESH_NEW_RCV)
9922 || CHECK_FLAG(p->cap,
9923 PEER_CAP_REFRESH_OLD_RCV)) {
9924 vty_out(vty, " Route refresh:");
9925 if (CHECK_FLAG(p->cap,
9926 PEER_CAP_REFRESH_ADV))
9927 vty_out(vty, " advertised");
9928 if (CHECK_FLAG(p->cap,
9929 PEER_CAP_REFRESH_NEW_RCV)
9930 || CHECK_FLAG(
9931 p->cap,
9932 PEER_CAP_REFRESH_OLD_RCV))
9933 vty_out(vty, " %sreceived(%s)",
9934 CHECK_FLAG(
9935 p->cap,
9936 PEER_CAP_REFRESH_ADV)
9937 ? "and "
9938 : "",
9939 (CHECK_FLAG(
9940 p->cap,
9941 PEER_CAP_REFRESH_OLD_RCV)
9942 && CHECK_FLAG(
9943 p->cap,
9944 PEER_CAP_REFRESH_NEW_RCV))
9945 ? "old & new"
9946 : CHECK_FLAG(
9947 p->cap,
9948 PEER_CAP_REFRESH_OLD_RCV)
9949 ? "old"
9950 : "new");
9951
9952 vty_out(vty, "\n");
9953 }
9954
9955 /* Multiprotocol Extensions */
9956 FOREACH_AFI_SAFI (afi, safi)
9957 if (p->afc_adv[afi][safi]
9958 || p->afc_recv[afi][safi]) {
9959 vty_out(vty,
9960 " Address Family %s:",
9961 afi_safi_print(afi,
9962 safi));
9963 if (p->afc_adv[afi][safi])
9964 vty_out(vty,
9965 " advertised");
9966 if (p->afc_recv[afi][safi])
9967 vty_out(vty,
9968 " %sreceived",
9969 p->afc_adv[afi]
9970 [safi]
9971 ? "and "
9972 : "");
9973 vty_out(vty, "\n");
9974 }
9975
9976 /* Hostname capability */
9977 vty_out(vty, " Hostname Capability:");
9978
9979 if (CHECK_FLAG(p->cap, PEER_CAP_HOSTNAME_ADV)) {
9980 vty_out(vty,
9981 " advertised (name: %s,domain name: %s)",
9982 bgp->peer_self->hostname
9983 ? bgp->peer_self
9984 ->hostname
9985 : "n/a",
9986 bgp->peer_self->domainname
9987 ? bgp->peer_self
9988 ->domainname
9989 : "n/a");
9990 } else {
9991 vty_out(vty, " not advertised");
9992 }
9993
9994 if (CHECK_FLAG(p->cap, PEER_CAP_HOSTNAME_RCV)) {
9995 vty_out(vty,
9996 " received (name: %s,domain name: %s)",
9997 p->hostname ? p->hostname
9998 : "n/a",
9999 p->domainname ? p->domainname
10000 : "n/a");
10001 } else {
10002 vty_out(vty, " not received");
10003 }
10004
10005 vty_out(vty, "\n");
10006
10007 /* Gracefull Restart */
10008 if (CHECK_FLAG(p->cap, PEER_CAP_RESTART_RCV)
10009 || CHECK_FLAG(p->cap,
10010 PEER_CAP_RESTART_ADV)) {
10011 vty_out(vty,
10012 " Graceful Restart Capabilty:");
10013 if (CHECK_FLAG(p->cap,
10014 PEER_CAP_RESTART_ADV))
10015 vty_out(vty, " advertised");
10016 if (CHECK_FLAG(p->cap,
10017 PEER_CAP_RESTART_RCV))
10018 vty_out(vty, " %sreceived",
10019 CHECK_FLAG(
10020 p->cap,
10021 PEER_CAP_RESTART_ADV)
10022 ? "and "
10023 : "");
10024 vty_out(vty, "\n");
10025
10026 if (CHECK_FLAG(p->cap,
10027 PEER_CAP_RESTART_RCV)) {
10028 int restart_af_count = 0;
10029
10030 vty_out(vty,
10031 " Remote Restart timer is %d seconds\n",
10032 p->v_gr_restart);
10033 vty_out(vty,
10034 " Address families by peer:\n ");
10035
10036 FOREACH_AFI_SAFI (afi, safi)
10037 if (CHECK_FLAG(
10038 p->af_cap
10039 [afi]
10040 [safi],
10041 PEER_CAP_RESTART_AF_RCV)) {
10042 vty_out(vty,
10043 "%s%s(%s)",
10044 restart_af_count
10045 ? ", "
10046 : "",
10047 afi_safi_print(
10048 afi,
10049 safi),
10050 CHECK_FLAG(
10051 p->af_cap
10052 [afi]
10053 [safi],
10054 PEER_CAP_RESTART_AF_PRESERVE_RCV)
10055 ? "preserved"
10056 : "not preserved");
10057 restart_af_count++;
10058 }
10059 if (!restart_af_count)
10060 vty_out(vty, "none");
10061 vty_out(vty, "\n");
10062 }
10063 }
10064 }
10065 }
10066 }
10067
10068 /* graceful restart information */
10069 if (CHECK_FLAG(p->cap, PEER_CAP_RESTART_RCV) || p->t_gr_restart
10070 || p->t_gr_stale) {
10071 json_object *json_grace = NULL;
10072 json_object *json_grace_send = NULL;
10073 json_object *json_grace_recv = NULL;
10074 int eor_send_af_count = 0;
10075 int eor_receive_af_count = 0;
10076
10077 if (use_json) {
10078 json_grace = json_object_new_object();
10079 json_grace_send = json_object_new_object();
10080 json_grace_recv = json_object_new_object();
10081
10082 if (p->status == Established) {
10083 FOREACH_AFI_SAFI (afi, safi) {
10084 if (CHECK_FLAG(p->af_sflags[afi][safi],
10085 PEER_STATUS_EOR_SEND)) {
10086 json_object_boolean_true_add(
10087 json_grace_send,
10088 afi_safi_print(afi,
10089 safi));
10090 eor_send_af_count++;
10091 }
10092 }
10093 FOREACH_AFI_SAFI (afi, safi) {
10094 if (CHECK_FLAG(
10095 p->af_sflags[afi][safi],
10096 PEER_STATUS_EOR_RECEIVED)) {
10097 json_object_boolean_true_add(
10098 json_grace_recv,
10099 afi_safi_print(afi,
10100 safi));
10101 eor_receive_af_count++;
10102 }
10103 }
10104 }
10105
10106 json_object_object_add(json_grace, "endOfRibSend",
10107 json_grace_send);
10108 json_object_object_add(json_grace, "endOfRibRecv",
10109 json_grace_recv);
10110
10111 if (p->t_gr_restart)
10112 json_object_int_add(json_grace,
10113 "gracefulRestartTimerMsecs",
10114 thread_timer_remain_second(
10115 p->t_gr_restart)
10116 * 1000);
10117
10118 if (p->t_gr_stale)
10119 json_object_int_add(
10120 json_grace,
10121 "gracefulStalepathTimerMsecs",
10122 thread_timer_remain_second(
10123 p->t_gr_stale)
10124 * 1000);
10125
10126 json_object_object_add(
10127 json_neigh, "gracefulRestartInfo", json_grace);
10128 } else {
10129 vty_out(vty, " Graceful restart informations:\n");
10130 if (p->status == Established) {
10131 vty_out(vty, " End-of-RIB send: ");
10132 FOREACH_AFI_SAFI (afi, safi) {
10133 if (CHECK_FLAG(p->af_sflags[afi][safi],
10134 PEER_STATUS_EOR_SEND)) {
10135 vty_out(vty, "%s%s",
10136 eor_send_af_count ? ", "
10137 : "",
10138 afi_safi_print(afi,
10139 safi));
10140 eor_send_af_count++;
10141 }
10142 }
10143 vty_out(vty, "\n");
10144 vty_out(vty, " End-of-RIB received: ");
10145 FOREACH_AFI_SAFI (afi, safi) {
10146 if (CHECK_FLAG(
10147 p->af_sflags[afi][safi],
10148 PEER_STATUS_EOR_RECEIVED)) {
10149 vty_out(vty, "%s%s",
10150 eor_receive_af_count
10151 ? ", "
10152 : "",
10153 afi_safi_print(afi,
10154 safi));
10155 eor_receive_af_count++;
10156 }
10157 }
10158 vty_out(vty, "\n");
10159 }
10160
10161 if (p->t_gr_restart)
10162 vty_out(vty,
10163 " The remaining time of restart timer is %ld\n",
10164 thread_timer_remain_second(
10165 p->t_gr_restart));
10166
10167 if (p->t_gr_stale)
10168 vty_out(vty,
10169 " The remaining time of stalepath timer is %ld\n",
10170 thread_timer_remain_second(
10171 p->t_gr_stale));
10172 }
10173 }
10174 if (use_json) {
10175 json_object *json_stat = NULL;
10176 json_stat = json_object_new_object();
10177 /* Packet counts. */
10178 json_object_int_add(json_stat, "depthInq", 0);
10179 json_object_int_add(json_stat, "depthOutq",
10180 (unsigned long)p->obuf->count);
10181 json_object_int_add(json_stat, "opensSent",
10182 atomic_load_explicit(&p->open_out,
10183 memory_order_relaxed));
10184 json_object_int_add(json_stat, "opensRecv",
10185 atomic_load_explicit(&p->open_in,
10186 memory_order_relaxed));
10187 json_object_int_add(json_stat, "notificationsSent",
10188 atomic_load_explicit(&p->notify_out,
10189 memory_order_relaxed));
10190 json_object_int_add(json_stat, "notificationsRecv",
10191 atomic_load_explicit(&p->notify_in,
10192 memory_order_relaxed));
10193 json_object_int_add(json_stat, "updatesSent",
10194 atomic_load_explicit(&p->update_out,
10195 memory_order_relaxed));
10196 json_object_int_add(json_stat, "updatesRecv",
10197 atomic_load_explicit(&p->update_in,
10198 memory_order_relaxed));
10199 json_object_int_add(json_stat, "keepalivesSent",
10200 atomic_load_explicit(&p->keepalive_out,
10201 memory_order_relaxed));
10202 json_object_int_add(json_stat, "keepalivesRecv",
10203 atomic_load_explicit(&p->keepalive_in,
10204 memory_order_relaxed));
10205 json_object_int_add(json_stat, "routeRefreshSent",
10206 atomic_load_explicit(&p->refresh_out,
10207 memory_order_relaxed));
10208 json_object_int_add(json_stat, "routeRefreshRecv",
10209 atomic_load_explicit(&p->refresh_in,
10210 memory_order_relaxed));
10211 json_object_int_add(json_stat, "capabilitySent",
10212 atomic_load_explicit(&p->dynamic_cap_out,
10213 memory_order_relaxed));
10214 json_object_int_add(json_stat, "capabilityRecv",
10215 atomic_load_explicit(&p->dynamic_cap_in,
10216 memory_order_relaxed));
10217 json_object_int_add(json_stat, "totalSent", PEER_TOTAL_TX(p));
10218 json_object_int_add(json_stat, "totalRecv", PEER_TOTAL_RX(p));
10219 json_object_object_add(json_neigh, "messageStats", json_stat);
10220 } else {
10221 /* Packet counts. */
10222 vty_out(vty, " Message statistics:\n");
10223 vty_out(vty, " Inq depth is 0\n");
10224 vty_out(vty, " Outq depth is %lu\n",
10225 (unsigned long)p->obuf->count);
10226 vty_out(vty, " Sent Rcvd\n");
10227 vty_out(vty, " Opens: %10d %10d\n",
10228 atomic_load_explicit(&p->open_out,
10229 memory_order_relaxed),
10230 atomic_load_explicit(&p->open_in,
10231 memory_order_relaxed));
10232 vty_out(vty, " Notifications: %10d %10d\n",
10233 atomic_load_explicit(&p->notify_out,
10234 memory_order_relaxed),
10235 atomic_load_explicit(&p->notify_in,
10236 memory_order_relaxed));
10237 vty_out(vty, " Updates: %10d %10d\n",
10238 atomic_load_explicit(&p->update_out,
10239 memory_order_relaxed),
10240 atomic_load_explicit(&p->update_in,
10241 memory_order_relaxed));
10242 vty_out(vty, " Keepalives: %10d %10d\n",
10243 atomic_load_explicit(&p->keepalive_out,
10244 memory_order_relaxed),
10245 atomic_load_explicit(&p->keepalive_in,
10246 memory_order_relaxed));
10247 vty_out(vty, " Route Refresh: %10d %10d\n",
10248 atomic_load_explicit(&p->refresh_out,
10249 memory_order_relaxed),
10250 atomic_load_explicit(&p->refresh_in,
10251 memory_order_relaxed));
10252 vty_out(vty, " Capability: %10d %10d\n",
10253 atomic_load_explicit(&p->dynamic_cap_out,
10254 memory_order_relaxed),
10255 atomic_load_explicit(&p->dynamic_cap_in,
10256 memory_order_relaxed));
10257 vty_out(vty, " Total: %10d %10d\n", PEER_TOTAL_TX(p),
10258 PEER_TOTAL_RX(p));
10259 }
10260
10261 if (use_json) {
10262 /* advertisement-interval */
10263 json_object_int_add(json_neigh,
10264 "minBtwnAdvertisementRunsTimerMsecs",
10265 p->v_routeadv * 1000);
10266
10267 /* Update-source. */
10268 if (p->update_if || p->update_source) {
10269 if (p->update_if)
10270 json_object_string_add(json_neigh,
10271 "updateSource",
10272 p->update_if);
10273 else if (p->update_source)
10274 json_object_string_add(
10275 json_neigh, "updateSource",
10276 sockunion2str(p->update_source, buf1,
10277 SU_ADDRSTRLEN));
10278 }
10279 } else {
10280 /* advertisement-interval */
10281 vty_out(vty,
10282 " Minimum time between advertisement runs is %d seconds\n",
10283 p->v_routeadv);
10284
10285 /* Update-source. */
10286 if (p->update_if || p->update_source) {
10287 vty_out(vty, " Update source is ");
10288 if (p->update_if)
10289 vty_out(vty, "%s", p->update_if);
10290 else if (p->update_source)
10291 vty_out(vty, "%s",
10292 sockunion2str(p->update_source, buf1,
10293 SU_ADDRSTRLEN));
10294 vty_out(vty, "\n");
10295 }
10296
10297 vty_out(vty, "\n");
10298 }
10299
10300 /* Address Family Information */
10301 json_object *json_hold = NULL;
10302
10303 if (use_json)
10304 json_hold = json_object_new_object();
10305
10306 FOREACH_AFI_SAFI (afi, safi)
10307 if (p->afc[afi][safi])
10308 bgp_show_peer_afi(vty, p, afi, safi, use_json,
10309 json_hold);
10310
10311 if (use_json) {
10312 json_object_object_add(json_neigh, "addressFamilyInfo",
10313 json_hold);
10314 json_object_int_add(json_neigh, "connectionsEstablished",
10315 p->established);
10316 json_object_int_add(json_neigh, "connectionsDropped",
10317 p->dropped);
10318 } else
10319 vty_out(vty, " Connections established %d; dropped %d\n",
10320 p->established, p->dropped);
10321
10322 if (!p->last_reset) {
10323 if (use_json)
10324 json_object_string_add(json_neigh, "lastReset",
10325 "never");
10326 else
10327 vty_out(vty, " Last reset never\n");
10328 } else {
10329 if (use_json) {
10330 time_t uptime;
10331 struct tm *tm;
10332
10333 uptime = bgp_clock();
10334 uptime -= p->resettime;
10335 tm = gmtime(&uptime);
10336 json_object_int_add(json_neigh, "lastResetTimerMsecs",
10337 (tm->tm_sec * 1000)
10338 + (tm->tm_min * 60000)
10339 + (tm->tm_hour * 3600000));
10340 json_object_string_add(
10341 json_neigh, "lastResetDueTo",
10342 peer_down_str[(int)p->last_reset]);
10343 if (p->last_reset == PEER_DOWN_NOTIFY_SEND
10344 || p->last_reset == PEER_DOWN_NOTIFY_RECEIVED) {
10345 char errorcodesubcode_hexstr[5];
10346 char errorcodesubcode_str[256];
10347
10348 code_str = bgp_notify_code_str(p->notify.code);
10349 subcode_str = bgp_notify_subcode_str(
10350 p->notify.code, p->notify.subcode);
10351
10352 sprintf(errorcodesubcode_hexstr, "%02X%02X",
10353 p->notify.code, p->notify.subcode);
10354 json_object_string_add(json_neigh,
10355 "lastErrorCodeSubcode",
10356 errorcodesubcode_hexstr);
10357 snprintf(errorcodesubcode_str, 255, "%s%s",
10358 code_str, subcode_str);
10359 json_object_string_add(json_neigh,
10360 "lastNotificationReason",
10361 errorcodesubcode_str);
10362 if (p->last_reset == PEER_DOWN_NOTIFY_RECEIVED
10363 && p->notify.code == BGP_NOTIFY_CEASE
10364 && (p->notify.subcode
10365 == BGP_NOTIFY_CEASE_ADMIN_SHUTDOWN
10366 || p->notify.subcode
10367 == BGP_NOTIFY_CEASE_ADMIN_RESET)
10368 && p->notify.length) {
10369 char msgbuf[1024];
10370 const char *msg_str;
10371
10372 msg_str = bgp_notify_admin_message(
10373 msgbuf, sizeof(msgbuf),
10374 (uint8_t *)p->notify.data,
10375 p->notify.length);
10376 if (msg_str)
10377 json_object_string_add(
10378 json_neigh,
10379 "lastShutdownDescription",
10380 msg_str);
10381 }
10382 }
10383 } else {
10384 vty_out(vty, " Last reset %s, ",
10385 peer_uptime(p->resettime, timebuf,
10386 BGP_UPTIME_LEN, 0, NULL));
10387
10388 if (p->last_reset == PEER_DOWN_NOTIFY_SEND
10389 || p->last_reset == PEER_DOWN_NOTIFY_RECEIVED) {
10390 code_str = bgp_notify_code_str(p->notify.code);
10391 subcode_str = bgp_notify_subcode_str(
10392 p->notify.code, p->notify.subcode);
10393 vty_out(vty, "due to NOTIFICATION %s (%s%s)\n",
10394 p->last_reset == PEER_DOWN_NOTIFY_SEND
10395 ? "sent"
10396 : "received",
10397 code_str, subcode_str);
10398 if (p->last_reset == PEER_DOWN_NOTIFY_RECEIVED
10399 && p->notify.code == BGP_NOTIFY_CEASE
10400 && (p->notify.subcode
10401 == BGP_NOTIFY_CEASE_ADMIN_SHUTDOWN
10402 || p->notify.subcode
10403 == BGP_NOTIFY_CEASE_ADMIN_RESET)
10404 && p->notify.length) {
10405 char msgbuf[1024];
10406 const char *msg_str;
10407
10408 msg_str = bgp_notify_admin_message(
10409 msgbuf, sizeof(msgbuf),
10410 (uint8_t *)p->notify.data,
10411 p->notify.length);
10412 if (msg_str)
10413 vty_out(vty,
10414 " Message: \"%s\"\n",
10415 msg_str);
10416 }
10417 } else {
10418 vty_out(vty, "due to %s\n",
10419 peer_down_str[(int)p->last_reset]);
10420 }
10421
10422 if (p->last_reset_cause_size) {
10423 msg = p->last_reset_cause;
10424 vty_out(vty,
10425 " Message received that caused BGP to send a NOTIFICATION:\n ");
10426 for (i = 1; i <= p->last_reset_cause_size;
10427 i++) {
10428 vty_out(vty, "%02X", *msg++);
10429
10430 if (i != p->last_reset_cause_size) {
10431 if (i % 16 == 0) {
10432 vty_out(vty, "\n ");
10433 } else if (i % 4 == 0) {
10434 vty_out(vty, " ");
10435 }
10436 }
10437 }
10438 vty_out(vty, "\n");
10439 }
10440 }
10441 }
10442
10443 if (CHECK_FLAG(p->sflags, PEER_STATUS_PREFIX_OVERFLOW)) {
10444 if (use_json)
10445 json_object_boolean_true_add(json_neigh,
10446 "prefixesConfigExceedMax");
10447 else
10448 vty_out(vty,
10449 " Peer had exceeded the max. no. of prefixes configured.\n");
10450
10451 if (p->t_pmax_restart) {
10452 if (use_json) {
10453 json_object_boolean_true_add(
10454 json_neigh, "reducePrefixNumFrom");
10455 json_object_int_add(json_neigh,
10456 "restartInTimerMsec",
10457 thread_timer_remain_second(
10458 p->t_pmax_restart)
10459 * 1000);
10460 } else
10461 vty_out(vty,
10462 " Reduce the no. of prefix from %s, will restart in %ld seconds\n",
10463 p->host, thread_timer_remain_second(
10464 p->t_pmax_restart));
10465 } else {
10466 if (use_json)
10467 json_object_boolean_true_add(
10468 json_neigh,
10469 "reducePrefixNumAndClearIpBgp");
10470 else
10471 vty_out(vty,
10472 " Reduce the no. of prefix and clear ip bgp %s to restore peering\n",
10473 p->host);
10474 }
10475 }
10476
10477 /* EBGP Multihop and GTSM */
10478 if (p->sort != BGP_PEER_IBGP) {
10479 if (use_json) {
10480 if (p->gtsm_hops > 0)
10481 json_object_int_add(json_neigh,
10482 "externalBgpNbrMaxHopsAway",
10483 p->gtsm_hops);
10484 else if (p->ttl > 1)
10485 json_object_int_add(json_neigh,
10486 "externalBgpNbrMaxHopsAway",
10487 p->ttl);
10488 } else {
10489 if (p->gtsm_hops > 0)
10490 vty_out(vty,
10491 " External BGP neighbor may be up to %d hops away.\n",
10492 p->gtsm_hops);
10493 else if (p->ttl > 1)
10494 vty_out(vty,
10495 " External BGP neighbor may be up to %d hops away.\n",
10496 p->ttl);
10497 }
10498 } else {
10499 if (p->gtsm_hops > 0) {
10500 if (use_json)
10501 json_object_int_add(json_neigh,
10502 "internalBgpNbrMaxHopsAway",
10503 p->gtsm_hops);
10504 else
10505 vty_out(vty,
10506 " Internal BGP neighbor may be up to %d hops away.\n",
10507 p->gtsm_hops);
10508 }
10509 }
10510
10511 /* Local address. */
10512 if (p->su_local) {
10513 if (use_json) {
10514 json_object_string_add(json_neigh, "hostLocal",
10515 sockunion2str(p->su_local, buf1,
10516 SU_ADDRSTRLEN));
10517 json_object_int_add(json_neigh, "portLocal",
10518 ntohs(p->su_local->sin.sin_port));
10519 } else
10520 vty_out(vty, "Local host: %s, Local port: %d\n",
10521 sockunion2str(p->su_local, buf1, SU_ADDRSTRLEN),
10522 ntohs(p->su_local->sin.sin_port));
10523 }
10524
10525 /* Remote address. */
10526 if (p->su_remote) {
10527 if (use_json) {
10528 json_object_string_add(json_neigh, "hostForeign",
10529 sockunion2str(p->su_remote, buf1,
10530 SU_ADDRSTRLEN));
10531 json_object_int_add(json_neigh, "portForeign",
10532 ntohs(p->su_remote->sin.sin_port));
10533 } else
10534 vty_out(vty, "Foreign host: %s, Foreign port: %d\n",
10535 sockunion2str(p->su_remote, buf1,
10536 SU_ADDRSTRLEN),
10537 ntohs(p->su_remote->sin.sin_port));
10538 }
10539
10540 /* Nexthop display. */
10541 if (p->su_local) {
10542 if (use_json) {
10543 json_object_string_add(json_neigh, "nexthop",
10544 inet_ntop(AF_INET,
10545 &p->nexthop.v4, buf1,
10546 sizeof(buf1)));
10547 json_object_string_add(json_neigh, "nexthopGlobal",
10548 inet_ntop(AF_INET6,
10549 &p->nexthop.v6_global,
10550 buf1, sizeof(buf1)));
10551 json_object_string_add(json_neigh, "nexthopLocal",
10552 inet_ntop(AF_INET6,
10553 &p->nexthop.v6_local,
10554 buf1, sizeof(buf1)));
10555 if (p->shared_network)
10556 json_object_string_add(json_neigh,
10557 "bgpConnection",
10558 "sharedNetwork");
10559 else
10560 json_object_string_add(json_neigh,
10561 "bgpConnection",
10562 "nonSharedNetwork");
10563 } else {
10564 vty_out(vty, "Nexthop: %s\n",
10565 inet_ntop(AF_INET, &p->nexthop.v4, buf1,
10566 sizeof(buf1)));
10567 vty_out(vty, "Nexthop global: %s\n",
10568 inet_ntop(AF_INET6, &p->nexthop.v6_global, buf1,
10569 sizeof(buf1)));
10570 vty_out(vty, "Nexthop local: %s\n",
10571 inet_ntop(AF_INET6, &p->nexthop.v6_local, buf1,
10572 sizeof(buf1)));
10573 vty_out(vty, "BGP connection: %s\n",
10574 p->shared_network ? "shared network"
10575 : "non shared network");
10576 }
10577 }
10578
10579 /* Timer information. */
10580 if (use_json) {
10581 json_object_int_add(json_neigh, "connectRetryTimer",
10582 p->v_connect);
10583 if (p->status == Established && p->rtt)
10584 json_object_int_add(json_neigh, "estimatedRttInMsecs",
10585 p->rtt);
10586 if (p->t_start)
10587 json_object_int_add(
10588 json_neigh, "nextStartTimerDueInMsecs",
10589 thread_timer_remain_second(p->t_start) * 1000);
10590 if (p->t_connect)
10591 json_object_int_add(
10592 json_neigh, "nextConnectTimerDueInMsecs",
10593 thread_timer_remain_second(p->t_connect)
10594 * 1000);
10595 if (p->t_routeadv) {
10596 json_object_int_add(json_neigh, "mraiInterval",
10597 p->v_routeadv);
10598 json_object_int_add(
10599 json_neigh, "mraiTimerExpireInMsecs",
10600 thread_timer_remain_second(p->t_routeadv)
10601 * 1000);
10602 }
10603 if (p->password)
10604 json_object_int_add(json_neigh, "authenticationEnabled",
10605 1);
10606
10607 if (p->t_read)
10608 json_object_string_add(json_neigh, "readThread", "on");
10609 else
10610 json_object_string_add(json_neigh, "readThread", "off");
10611
10612 if (CHECK_FLAG(p->thread_flags, PEER_THREAD_WRITES_ON))
10613 json_object_string_add(json_neigh, "writeThread", "on");
10614 else
10615 json_object_string_add(json_neigh, "writeThread",
10616 "off");
10617 } else {
10618 vty_out(vty, "BGP Connect Retry Timer in Seconds: %d\n",
10619 p->v_connect);
10620 if (p->status == Established && p->rtt)
10621 vty_out(vty, "Estimated round trip time: %d ms\n",
10622 p->rtt);
10623 if (p->t_start)
10624 vty_out(vty, "Next start timer due in %ld seconds\n",
10625 thread_timer_remain_second(p->t_start));
10626 if (p->t_connect)
10627 vty_out(vty, "Next connect timer due in %ld seconds\n",
10628 thread_timer_remain_second(p->t_connect));
10629 if (p->t_routeadv)
10630 vty_out(vty,
10631 "MRAI (interval %u) timer expires in %ld seconds\n",
10632 p->v_routeadv,
10633 thread_timer_remain_second(p->t_routeadv));
10634 if (p->password)
10635 vty_out(vty, "Peer Authentication Enabled\n");
10636
10637 vty_out(vty, "Read thread: %s Write thread: %s\n",
10638 p->t_read ? "on" : "off",
10639 CHECK_FLAG(p->thread_flags, PEER_THREAD_WRITES_ON)
10640 ? "on"
10641 : "off");
10642 }
10643
10644 if (p->notify.code == BGP_NOTIFY_OPEN_ERR
10645 && p->notify.subcode == BGP_NOTIFY_OPEN_UNSUP_CAPBL)
10646 bgp_capability_vty_out(vty, p, use_json, json_neigh);
10647
10648 if (!use_json)
10649 vty_out(vty, "\n");
10650
10651 /* BFD information. */
10652 bgp_bfd_show_info(vty, p, use_json, json_neigh);
10653
10654 if (use_json) {
10655 if (p->conf_if) /* Configured interface name. */
10656 json_object_object_add(json, p->conf_if, json_neigh);
10657 else /* Configured IP address. */
10658 json_object_object_add(json, p->host, json_neigh);
10659 }
10660 }
10661
10662 static int bgp_show_neighbor(struct vty *vty, struct bgp *bgp,
10663 enum show_type type, union sockunion *su,
10664 const char *conf_if, uint8_t use_json,
10665 json_object *json)
10666 {
10667 struct listnode *node, *nnode;
10668 struct peer *peer;
10669 int find = 0;
10670
10671 for (ALL_LIST_ELEMENTS(bgp->peer, node, nnode, peer)) {
10672 if (!CHECK_FLAG(peer->flags, PEER_FLAG_CONFIG_NODE))
10673 continue;
10674
10675 switch (type) {
10676 case show_all:
10677 bgp_show_peer(vty, peer, use_json, json);
10678 break;
10679 case show_peer:
10680 if (conf_if) {
10681 if ((peer->conf_if
10682 && !strcmp(peer->conf_if, conf_if))
10683 || (peer->hostname
10684 && !strcmp(peer->hostname, conf_if))) {
10685 find = 1;
10686 bgp_show_peer(vty, peer, use_json,
10687 json);
10688 }
10689 } else {
10690 if (sockunion_same(&peer->su, su)) {
10691 find = 1;
10692 bgp_show_peer(vty, peer, use_json,
10693 json);
10694 }
10695 }
10696 break;
10697 }
10698 }
10699
10700 if (type == show_peer && !find) {
10701 if (use_json)
10702 json_object_boolean_true_add(json, "bgpNoSuchNeighbor");
10703 else
10704 vty_out(vty, "%% No such neighbor in this view/vrf\n");
10705 }
10706
10707 if (use_json) {
10708 vty_out(vty, "%s\n", json_object_to_json_string_ext(
10709 json, JSON_C_TO_STRING_PRETTY));
10710 json_object_free(json);
10711 } else {
10712 vty_out(vty, "\n");
10713 }
10714
10715 return CMD_SUCCESS;
10716 }
10717
10718 static void bgp_show_all_instances_neighbors_vty(struct vty *vty,
10719 enum show_type type,
10720 const char *ip_str,
10721 uint8_t use_json)
10722 {
10723 struct listnode *node, *nnode;
10724 struct bgp *bgp;
10725 union sockunion su;
10726 json_object *json = NULL;
10727 int ret, is_first = 1;
10728
10729 if (use_json)
10730 vty_out(vty, "{\n");
10731
10732 for (ALL_LIST_ELEMENTS(bm->bgp, node, nnode, bgp)) {
10733 if (use_json) {
10734 if (!(json = json_object_new_object())) {
10735 zlog_err(
10736 "Unable to allocate memory for JSON object");
10737 vty_out(vty,
10738 "{\"error\": {\"message:\": \"Unable to allocate memory for JSON object\"}}}\n");
10739 return;
10740 }
10741
10742 json_object_int_add(json, "vrfId",
10743 (bgp->vrf_id == VRF_UNKNOWN)
10744 ? -1
10745 : (int64_t)bgp->vrf_id);
10746 json_object_string_add(
10747 json, "vrfName",
10748 (bgp->inst_type == BGP_INSTANCE_TYPE_DEFAULT)
10749 ? "Default"
10750 : bgp->name);
10751
10752 if (!is_first)
10753 vty_out(vty, ",\n");
10754 else
10755 is_first = 0;
10756
10757 vty_out(vty, "\"%s\":",
10758 (bgp->inst_type == BGP_INSTANCE_TYPE_DEFAULT)
10759 ? "Default"
10760 : bgp->name);
10761 } else {
10762 vty_out(vty, "\nInstance %s:\n",
10763 (bgp->inst_type == BGP_INSTANCE_TYPE_DEFAULT)
10764 ? "Default"
10765 : bgp->name);
10766 }
10767
10768 if (type == show_peer) {
10769 ret = str2sockunion(ip_str, &su);
10770 if (ret < 0)
10771 bgp_show_neighbor(vty, bgp, type, NULL, ip_str,
10772 use_json, json);
10773 else
10774 bgp_show_neighbor(vty, bgp, type, &su, NULL,
10775 use_json, json);
10776 } else {
10777 bgp_show_neighbor(vty, bgp, show_all, NULL, NULL,
10778 use_json, json);
10779 }
10780 }
10781
10782 if (use_json)
10783 vty_out(vty, "}\n");
10784 }
10785
10786 static int bgp_show_neighbor_vty(struct vty *vty, const char *name,
10787 enum show_type type, const char *ip_str,
10788 uint8_t use_json)
10789 {
10790 int ret;
10791 struct bgp *bgp;
10792 union sockunion su;
10793 json_object *json = NULL;
10794
10795 if (name) {
10796 if (strmatch(name, "all")) {
10797 bgp_show_all_instances_neighbors_vty(vty, type, ip_str,
10798 use_json);
10799 return CMD_SUCCESS;
10800 } else {
10801 bgp = bgp_lookup_by_name(name);
10802 if (!bgp) {
10803 if (use_json) {
10804 json = json_object_new_object();
10805 json_object_boolean_true_add(
10806 json, "bgpNoSuchInstance");
10807 vty_out(vty, "%s\n",
10808 json_object_to_json_string_ext(
10809 json,
10810 JSON_C_TO_STRING_PRETTY));
10811 json_object_free(json);
10812 } else
10813 vty_out(vty,
10814 "%% No such BGP instance exist\n");
10815
10816 return CMD_WARNING;
10817 }
10818 }
10819 } else {
10820 bgp = bgp_get_default();
10821 }
10822
10823 if (bgp) {
10824 json = json_object_new_object();
10825 if (ip_str) {
10826 ret = str2sockunion(ip_str, &su);
10827 if (ret < 0)
10828 bgp_show_neighbor(vty, bgp, type, NULL, ip_str,
10829 use_json, json);
10830 else
10831 bgp_show_neighbor(vty, bgp, type, &su, NULL,
10832 use_json, json);
10833 } else {
10834 bgp_show_neighbor(vty, bgp, type, NULL, NULL, use_json,
10835 json);
10836 }
10837 json_object_free(json);
10838 }
10839
10840 return CMD_SUCCESS;
10841 }
10842
10843 /* "show [ip] bgp neighbors" commands. */
10844 DEFUN (show_ip_bgp_neighbors,
10845 show_ip_bgp_neighbors_cmd,
10846 "show [ip] bgp [<view|vrf> VIEWVRFNAME] [<ipv4|ipv6>] neighbors [<A.B.C.D|X:X::X:X|WORD>] [json]",
10847 SHOW_STR
10848 IP_STR
10849 BGP_STR
10850 BGP_INSTANCE_HELP_STR
10851 "Address Family\n"
10852 "Address Family\n"
10853 "Detailed information on TCP and BGP neighbor connections\n"
10854 "Neighbor to display information about\n"
10855 "Neighbor to display information about\n"
10856 "Neighbor on BGP configured interface\n"
10857 JSON_STR)
10858 {
10859 char *vrf = NULL;
10860 char *sh_arg = NULL;
10861 enum show_type sh_type;
10862
10863 uint8_t uj = use_json(argc, argv);
10864
10865 int idx = 0;
10866
10867 if (argv_find(argv, argc, "view", &idx)
10868 || argv_find(argv, argc, "vrf", &idx))
10869 vrf = argv[idx + 1]->arg;
10870
10871 idx++;
10872 if (argv_find(argv, argc, "A.B.C.D", &idx)
10873 || argv_find(argv, argc, "X:X::X:X", &idx)
10874 || argv_find(argv, argc, "WORD", &idx)) {
10875 sh_type = show_peer;
10876 sh_arg = argv[idx]->arg;
10877 } else
10878 sh_type = show_all;
10879
10880 return bgp_show_neighbor_vty(vty, vrf, sh_type, sh_arg, uj);
10881 }
10882
10883 /* Show BGP's AS paths internal data. There are both `show [ip] bgp
10884 paths' and `show ip mbgp paths'. Those functions results are the
10885 same.*/
10886 DEFUN (show_ip_bgp_paths,
10887 show_ip_bgp_paths_cmd,
10888 "show [ip] bgp ["BGP_SAFI_CMD_STR"] paths",
10889 SHOW_STR
10890 IP_STR
10891 BGP_STR
10892 BGP_SAFI_HELP_STR
10893 "Path information\n")
10894 {
10895 vty_out(vty, "Address Refcnt Path\n");
10896 aspath_print_all_vty(vty);
10897 return CMD_SUCCESS;
10898 }
10899
10900 #include "hash.h"
10901
10902 static void community_show_all_iterator(struct hash_backet *backet,
10903 struct vty *vty)
10904 {
10905 struct community *com;
10906
10907 com = (struct community *)backet->data;
10908 vty_out(vty, "[%p] (%ld) %s\n", (void *)com, com->refcnt,
10909 community_str(com, false));
10910 }
10911
10912 /* Show BGP's community internal data. */
10913 DEFUN (show_ip_bgp_community_info,
10914 show_ip_bgp_community_info_cmd,
10915 "show [ip] bgp community-info",
10916 SHOW_STR
10917 IP_STR
10918 BGP_STR
10919 "List all bgp community information\n")
10920 {
10921 vty_out(vty, "Address Refcnt Community\n");
10922
10923 hash_iterate(community_hash(),
10924 (void (*)(struct hash_backet *,
10925 void *))community_show_all_iterator,
10926 vty);
10927
10928 return CMD_SUCCESS;
10929 }
10930
10931 static void lcommunity_show_all_iterator(struct hash_backet *backet,
10932 struct vty *vty)
10933 {
10934 struct lcommunity *lcom;
10935
10936 lcom = (struct lcommunity *)backet->data;
10937 vty_out(vty, "[%p] (%ld) %s\n", (void *)lcom, lcom->refcnt,
10938 lcommunity_str(lcom, false));
10939 }
10940
10941 /* Show BGP's community internal data. */
10942 DEFUN (show_ip_bgp_lcommunity_info,
10943 show_ip_bgp_lcommunity_info_cmd,
10944 "show ip bgp large-community-info",
10945 SHOW_STR
10946 IP_STR
10947 BGP_STR
10948 "List all bgp large-community information\n")
10949 {
10950 vty_out(vty, "Address Refcnt Large-community\n");
10951
10952 hash_iterate(lcommunity_hash(),
10953 (void (*)(struct hash_backet *,
10954 void *))lcommunity_show_all_iterator,
10955 vty);
10956
10957 return CMD_SUCCESS;
10958 }
10959
10960
10961 DEFUN (show_ip_bgp_attr_info,
10962 show_ip_bgp_attr_info_cmd,
10963 "show [ip] bgp attribute-info",
10964 SHOW_STR
10965 IP_STR
10966 BGP_STR
10967 "List all bgp attribute information\n")
10968 {
10969 attr_show_all(vty);
10970 return CMD_SUCCESS;
10971 }
10972
10973 static int bgp_show_route_leak_vty(struct vty *vty, const char *name,
10974 afi_t afi, safi_t safi)
10975 {
10976 struct bgp *bgp;
10977 struct listnode *node;
10978 char *vname;
10979 char buf1[INET6_ADDRSTRLEN];
10980 char *ecom_str;
10981 vpn_policy_direction_t dir;
10982
10983 if (name) {
10984 bgp = bgp_lookup_by_name(name);
10985 if (!bgp) {
10986 vty_out(vty, "%% No such BGP instance exist\n");
10987 return CMD_WARNING;
10988 }
10989 } else {
10990 bgp = bgp_get_default();
10991 if (!bgp) {
10992 vty_out(vty,
10993 "%% Default BGP instance does not exist\n");
10994 return CMD_WARNING;
10995 }
10996 }
10997
10998 if (!CHECK_FLAG(bgp->af_flags[afi][safi],
10999 BGP_CONFIG_VRF_TO_VRF_IMPORT)) {
11000 vty_out(vty,
11001 "This VRF is not importing %s routes from any other VRF\n",
11002 afi_safi_print(afi, safi));
11003 } else {
11004 vty_out(vty,
11005 "This VRF is importing %s routes from the following VRFs:\n",
11006 afi_safi_print(afi, safi));
11007 for (ALL_LIST_ELEMENTS_RO(bgp->vpn_policy[afi].import_vrf, node,
11008 vname)) {
11009 vty_out(vty, " %s\n", vname);
11010 }
11011 dir = BGP_VPN_POLICY_DIR_FROMVPN;
11012 ecom_str = ecommunity_ecom2str(
11013 bgp->vpn_policy[afi].rtlist[dir],
11014 ECOMMUNITY_FORMAT_ROUTE_MAP, 0);
11015 vty_out(vty, "Import RT(s): %s\n", ecom_str);
11016 XFREE(MTYPE_ECOMMUNITY_STR, ecom_str);
11017 }
11018
11019 if (!CHECK_FLAG(bgp->af_flags[afi][safi],
11020 BGP_CONFIG_VRF_TO_VRF_EXPORT)) {
11021 vty_out(vty,
11022 "This VRF is not exporting %s routes to any other VRF\n",
11023 afi_safi_print(afi, safi));
11024 } else {
11025 vty_out(vty,
11026 "This VRF is exporting %s routes to the following VRFs:\n",
11027 afi_safi_print(afi, safi));
11028 for (ALL_LIST_ELEMENTS_RO(bgp->vpn_policy[afi].export_vrf, node,
11029 vname)) {
11030 vty_out(vty, " %s\n", vname);
11031 }
11032 vty_out(vty, "RD: %s\n",
11033 prefix_rd2str(&bgp->vpn_policy[afi].tovpn_rd,
11034 buf1, RD_ADDRSTRLEN));
11035 dir = BGP_VPN_POLICY_DIR_TOVPN;
11036 ecom_str = ecommunity_ecom2str(
11037 bgp->vpn_policy[afi].rtlist[dir],
11038 ECOMMUNITY_FORMAT_ROUTE_MAP, 0);
11039 vty_out(vty, "Emport RT: %s\n", ecom_str);
11040 XFREE(MTYPE_ECOMMUNITY_STR, ecom_str);
11041 }
11042
11043 return CMD_SUCCESS;
11044 }
11045
11046 /* "show [ip] bgp route-leak" command. */
11047 DEFUN (show_ip_bgp_route_leak,
11048 show_ip_bgp_route_leak_cmd,
11049 "show [ip] bgp [<view|vrf> VIEWVRFNAME] ["BGP_AFI_CMD_STR" ["BGP_SAFI_CMD_STR"]] route-leak",
11050 SHOW_STR
11051 IP_STR
11052 BGP_STR
11053 BGP_INSTANCE_HELP_STR
11054 BGP_AFI_HELP_STR
11055 BGP_SAFI_HELP_STR
11056 "Route leaking information\n")
11057 {
11058 char *vrf = NULL;
11059 afi_t afi = AFI_MAX;
11060 safi_t safi = SAFI_MAX;
11061
11062 int idx = 0;
11063
11064 /* show [ip] bgp */
11065 if (argv_find(argv, argc, "ip", &idx)) {
11066 afi = AFI_IP;
11067 safi = SAFI_UNICAST;
11068 }
11069 /* [vrf VIEWVRFNAME] */
11070 if (argv_find(argv, argc, "view", &idx)) {
11071 vty_out(vty,
11072 "%% This command is not applicable to BGP views\n");
11073 return CMD_WARNING;
11074 }
11075
11076 if (argv_find(argv, argc, "vrf", &idx))
11077 vrf = argv[++idx]->arg;
11078 /* ["BGP_AFI_CMD_STR" ["BGP_SAFI_CMD_STR"]] */
11079 if (argv_find_and_parse_afi(argv, argc, &idx, &afi)) {
11080 argv_find_and_parse_safi(argv, argc, &idx, &safi);
11081 }
11082
11083 if (!((afi == AFI_IP || afi == AFI_IP6) && safi == SAFI_UNICAST)) {
11084 vty_out(vty,
11085 "%% This command is applicable only for unicast ipv4|ipv6\n");
11086 return CMD_WARNING;
11087 }
11088
11089 return bgp_show_route_leak_vty(vty, vrf, afi, safi);
11090 }
11091
11092 static void bgp_show_all_instances_updgrps_vty(struct vty *vty, afi_t afi,
11093 safi_t safi)
11094 {
11095 struct listnode *node, *nnode;
11096 struct bgp *bgp;
11097
11098 for (ALL_LIST_ELEMENTS(bm->bgp, node, nnode, bgp)) {
11099 vty_out(vty, "\nInstance %s:\n",
11100 (bgp->inst_type == BGP_INSTANCE_TYPE_DEFAULT)
11101 ? "Default"
11102 : bgp->name);
11103 update_group_show(bgp, afi, safi, vty, 0);
11104 }
11105 }
11106
11107 static int bgp_show_update_groups(struct vty *vty, const char *name, int afi,
11108 int safi, uint64_t subgrp_id)
11109 {
11110 struct bgp *bgp;
11111
11112 if (name) {
11113 if (strmatch(name, "all")) {
11114 bgp_show_all_instances_updgrps_vty(vty, afi, safi);
11115 return CMD_SUCCESS;
11116 } else {
11117 bgp = bgp_lookup_by_name(name);
11118 }
11119 } else {
11120 bgp = bgp_get_default();
11121 }
11122
11123 if (bgp)
11124 update_group_show(bgp, afi, safi, vty, subgrp_id);
11125 return CMD_SUCCESS;
11126 }
11127
11128 DEFUN (show_ip_bgp_updgrps,
11129 show_ip_bgp_updgrps_cmd,
11130 "show [ip] bgp [<view|vrf> VIEWVRFNAME] ["BGP_AFI_CMD_STR" ["BGP_SAFI_WITH_LABEL_CMD_STR"]] update-groups [SUBGROUP-ID]",
11131 SHOW_STR
11132 IP_STR
11133 BGP_STR
11134 BGP_INSTANCE_HELP_STR
11135 BGP_AFI_HELP_STR
11136 BGP_SAFI_WITH_LABEL_HELP_STR
11137 "Detailed info about dynamic update groups\n"
11138 "Specific subgroup to display detailed info for\n")
11139 {
11140 char *vrf = NULL;
11141 afi_t afi = AFI_IP6;
11142 safi_t safi = SAFI_UNICAST;
11143 uint64_t subgrp_id = 0;
11144
11145 int idx = 0;
11146
11147 /* show [ip] bgp */
11148 if (argv_find(argv, argc, "ip", &idx))
11149 afi = AFI_IP;
11150 /* [<view|vrf> VIEWVRFNAME] */
11151 if (argv_find(argv, argc, "view", &idx)
11152 || argv_find(argv, argc, "vrf", &idx))
11153 vrf = argv[++idx]->arg;
11154 /* ["BGP_AFI_CMD_STR" ["BGP_SAFI_CMD_STR"]] */
11155 if (argv_find_and_parse_afi(argv, argc, &idx, &afi)) {
11156 argv_find_and_parse_safi(argv, argc, &idx, &safi);
11157 }
11158
11159 /* get subgroup id, if provided */
11160 idx = argc - 1;
11161 if (argv[idx]->type == VARIABLE_TKN)
11162 subgrp_id = strtoull(argv[idx]->arg, NULL, 10);
11163
11164 return (bgp_show_update_groups(vty, vrf, afi, safi, subgrp_id));
11165 }
11166
11167 DEFUN (show_bgp_instance_all_ipv6_updgrps,
11168 show_bgp_instance_all_ipv6_updgrps_cmd,
11169 "show [ip] bgp <view|vrf> all update-groups",
11170 SHOW_STR
11171 IP_STR
11172 BGP_STR
11173 BGP_INSTANCE_ALL_HELP_STR
11174 "Detailed info about dynamic update groups\n")
11175 {
11176 bgp_show_all_instances_updgrps_vty(vty, AFI_IP6, SAFI_UNICAST);
11177 return CMD_SUCCESS;
11178 }
11179
11180 DEFUN (show_bgp_updgrps_stats,
11181 show_bgp_updgrps_stats_cmd,
11182 "show [ip] bgp update-groups statistics",
11183 SHOW_STR
11184 IP_STR
11185 BGP_STR
11186 "Detailed info about dynamic update groups\n"
11187 "Statistics\n")
11188 {
11189 struct bgp *bgp;
11190
11191 bgp = bgp_get_default();
11192 if (bgp)
11193 update_group_show_stats(bgp, vty);
11194
11195 return CMD_SUCCESS;
11196 }
11197
11198 DEFUN (show_bgp_instance_updgrps_stats,
11199 show_bgp_instance_updgrps_stats_cmd,
11200 "show [ip] bgp <view|vrf> VIEWVRFNAME update-groups statistics",
11201 SHOW_STR
11202 IP_STR
11203 BGP_STR
11204 BGP_INSTANCE_HELP_STR
11205 "Detailed info about dynamic update groups\n"
11206 "Statistics\n")
11207 {
11208 int idx_word = 3;
11209 struct bgp *bgp;
11210
11211 bgp = bgp_lookup_by_name(argv[idx_word]->arg);
11212 if (bgp)
11213 update_group_show_stats(bgp, vty);
11214
11215 return CMD_SUCCESS;
11216 }
11217
11218 static void show_bgp_updgrps_adj_info_aux(struct vty *vty, const char *name,
11219 afi_t afi, safi_t safi,
11220 const char *what, uint64_t subgrp_id)
11221 {
11222 struct bgp *bgp;
11223
11224 if (name)
11225 bgp = bgp_lookup_by_name(name);
11226 else
11227 bgp = bgp_get_default();
11228
11229 if (bgp) {
11230 if (!strcmp(what, "advertise-queue"))
11231 update_group_show_adj_queue(bgp, afi, safi, vty,
11232 subgrp_id);
11233 else if (!strcmp(what, "advertised-routes"))
11234 update_group_show_advertised(bgp, afi, safi, vty,
11235 subgrp_id);
11236 else if (!strcmp(what, "packet-queue"))
11237 update_group_show_packet_queue(bgp, afi, safi, vty,
11238 subgrp_id);
11239 }
11240 }
11241
11242 DEFPY(show_ip_bgp_instance_updgrps_adj_s,
11243 show_ip_bgp_instance_updgrps_adj_s_cmd,
11244 "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",
11245 SHOW_STR IP_STR BGP_STR BGP_INSTANCE_HELP_STR BGP_AFI_HELP_STR
11246 BGP_SAFI_HELP_STR
11247 "Detailed info about dynamic update groups\n"
11248 "Specific subgroup to display info for\n"
11249 "Advertisement queue\n"
11250 "Announced routes\n"
11251 "Packet queue\n")
11252 {
11253 uint64_t subgrp_id = 0;
11254 afi_t afiz;
11255 safi_t safiz;
11256 if (sgid)
11257 subgrp_id = strtoull(sgid, NULL, 10);
11258
11259 if (!ip && !afi)
11260 afiz = AFI_IP6;
11261 if (!ip && afi)
11262 afiz = bgp_vty_afi_from_str(afi);
11263 if (ip && !afi)
11264 afiz = AFI_IP;
11265 if (ip && afi) {
11266 afiz = bgp_vty_afi_from_str(afi);
11267 if (afiz != AFI_IP)
11268 vty_out(vty,
11269 "%% Cannot specify both 'ip' and 'ipv6'\n");
11270 return CMD_WARNING;
11271 }
11272
11273 safiz = safi ? bgp_vty_safi_from_str(safi) : SAFI_UNICAST;
11274
11275 show_bgp_updgrps_adj_info_aux(vty, vrf, afiz, safiz, rtq, subgrp_id);
11276 return CMD_SUCCESS;
11277 }
11278
11279 static int bgp_show_one_peer_group(struct vty *vty, struct peer_group *group)
11280 {
11281 struct listnode *node, *nnode;
11282 struct prefix *range;
11283 struct peer *conf;
11284 struct peer *peer;
11285 char buf[PREFIX2STR_BUFFER];
11286 afi_t afi;
11287 safi_t safi;
11288 const char *peer_status;
11289 const char *af_str;
11290 int lr_count;
11291 int dynamic;
11292 int af_cfgd;
11293
11294 conf = group->conf;
11295
11296 if (conf->as_type == AS_SPECIFIED || conf->as_type == AS_EXTERNAL) {
11297 vty_out(vty, "\nBGP peer-group %s, remote AS %d\n", group->name,
11298 conf->as);
11299 } else if (conf->as_type == AS_INTERNAL) {
11300 vty_out(vty, "\nBGP peer-group %s, remote AS %d\n", group->name,
11301 group->bgp->as);
11302 } else {
11303 vty_out(vty, "\nBGP peer-group %s\n", group->name);
11304 }
11305
11306 if ((group->bgp->as == conf->as) || (conf->as_type == AS_INTERNAL))
11307 vty_out(vty, " Peer-group type is internal\n");
11308 else
11309 vty_out(vty, " Peer-group type is external\n");
11310
11311 /* Display AFs configured. */
11312 vty_out(vty, " Configured address-families:");
11313 FOREACH_AFI_SAFI (afi, safi) {
11314 if (conf->afc[afi][safi]) {
11315 af_cfgd = 1;
11316 vty_out(vty, " %s;", afi_safi_print(afi, safi));
11317 }
11318 }
11319 if (!af_cfgd)
11320 vty_out(vty, " none\n");
11321 else
11322 vty_out(vty, "\n");
11323
11324 /* Display listen ranges (for dynamic neighbors), if any */
11325 for (afi = AFI_IP; afi < AFI_MAX; afi++) {
11326 if (afi == AFI_IP)
11327 af_str = "IPv4";
11328 else if (afi == AFI_IP6)
11329 af_str = "IPv6";
11330 else
11331 af_str = "???";
11332 lr_count = listcount(group->listen_range[afi]);
11333 if (lr_count) {
11334 vty_out(vty, " %d %s listen range(s)\n", lr_count,
11335 af_str);
11336
11337
11338 for (ALL_LIST_ELEMENTS(group->listen_range[afi], node,
11339 nnode, range)) {
11340 prefix2str(range, buf, sizeof(buf));
11341 vty_out(vty, " %s\n", buf);
11342 }
11343 }
11344 }
11345
11346 /* Display group members and their status */
11347 if (listcount(group->peer)) {
11348 vty_out(vty, " Peer-group members:\n");
11349 for (ALL_LIST_ELEMENTS(group->peer, node, nnode, peer)) {
11350 if (CHECK_FLAG(peer->flags, PEER_FLAG_SHUTDOWN))
11351 peer_status = "Idle (Admin)";
11352 else if (CHECK_FLAG(peer->sflags,
11353 PEER_STATUS_PREFIX_OVERFLOW))
11354 peer_status = "Idle (PfxCt)";
11355 else
11356 peer_status = lookup_msg(bgp_status_msg,
11357 peer->status, NULL);
11358
11359 dynamic = peer_dynamic_neighbor(peer);
11360 vty_out(vty, " %s %s %s \n", peer->host,
11361 dynamic ? "(dynamic)" : "", peer_status);
11362 }
11363 }
11364
11365 return CMD_SUCCESS;
11366 }
11367
11368 static int bgp_show_peer_group_vty(struct vty *vty, const char *name,
11369 const char *group_name)
11370 {
11371 struct bgp *bgp;
11372 struct listnode *node, *nnode;
11373 struct peer_group *group;
11374 bool found = false;
11375
11376 bgp = name ? bgp_lookup_by_name(name) : bgp_get_default();
11377
11378 if (!bgp) {
11379 vty_out(vty, "%% No such BGP instance exists\n");
11380 return CMD_WARNING;
11381 }
11382
11383 for (ALL_LIST_ELEMENTS(bgp->group, node, nnode, group)) {
11384 if (group_name) {
11385 if (strmatch(group->name, group_name)) {
11386 bgp_show_one_peer_group(vty, group);
11387 found = true;
11388 break;
11389 }
11390 } else {
11391 bgp_show_one_peer_group(vty, group);
11392 }
11393 }
11394
11395 if (group_name && !found)
11396 vty_out(vty, "%% No such peer-group\n");
11397
11398 return CMD_SUCCESS;
11399 }
11400
11401 DEFUN (show_ip_bgp_peer_groups,
11402 show_ip_bgp_peer_groups_cmd,
11403 "show [ip] bgp [<view|vrf> VIEWVRFNAME] peer-group [PGNAME]",
11404 SHOW_STR
11405 IP_STR
11406 BGP_STR
11407 BGP_INSTANCE_HELP_STR
11408 "Detailed information on BGP peer groups\n"
11409 "Peer group name\n")
11410 {
11411 char *vrf, *pg;
11412 vrf = pg = NULL;
11413 int idx = 0;
11414
11415 vrf = argv_find(argv, argc, "VIEWVRFNAME", &idx) ? argv[idx]->arg
11416 : NULL;
11417 pg = argv_find(argv, argc, "PGNAME", &idx) ? argv[idx]->arg : NULL;
11418
11419 return bgp_show_peer_group_vty(vty, vrf, pg);
11420 }
11421
11422
11423 /* Redistribute VTY commands. */
11424
11425 DEFUN (bgp_redistribute_ipv4,
11426 bgp_redistribute_ipv4_cmd,
11427 "redistribute " FRR_IP_REDIST_STR_BGPD,
11428 "Redistribute information from another routing protocol\n"
11429 FRR_IP_REDIST_HELP_STR_BGPD)
11430 {
11431 VTY_DECLVAR_CONTEXT(bgp, bgp);
11432 int idx_protocol = 1;
11433 int type;
11434
11435 type = proto_redistnum(AFI_IP, argv[idx_protocol]->text);
11436 if (type < 0) {
11437 vty_out(vty, "%% Invalid route type\n");
11438 return CMD_WARNING_CONFIG_FAILED;
11439 }
11440
11441 bgp_redist_add(bgp, AFI_IP, type, 0);
11442 return bgp_redistribute_set(bgp, AFI_IP, type, 0);
11443 }
11444
11445 ALIAS_HIDDEN(
11446 bgp_redistribute_ipv4, bgp_redistribute_ipv4_hidden_cmd,
11447 "redistribute " FRR_IP_REDIST_STR_BGPD,
11448 "Redistribute information from another routing protocol\n" FRR_IP_REDIST_HELP_STR_BGPD)
11449
11450 DEFUN (bgp_redistribute_ipv4_rmap,
11451 bgp_redistribute_ipv4_rmap_cmd,
11452 "redistribute " FRR_IP_REDIST_STR_BGPD " route-map WORD",
11453 "Redistribute information from another routing protocol\n"
11454 FRR_IP_REDIST_HELP_STR_BGPD
11455 "Route map reference\n"
11456 "Pointer to route-map entries\n")
11457 {
11458 VTY_DECLVAR_CONTEXT(bgp, bgp);
11459 int idx_protocol = 1;
11460 int idx_word = 3;
11461 int type;
11462 struct bgp_redist *red;
11463
11464 type = proto_redistnum(AFI_IP, argv[idx_protocol]->text);
11465 if (type < 0) {
11466 vty_out(vty, "%% Invalid route type\n");
11467 return CMD_WARNING_CONFIG_FAILED;
11468 }
11469
11470 red = bgp_redist_add(bgp, AFI_IP, type, 0);
11471 bgp_redistribute_rmap_set(red, argv[idx_word]->arg);
11472 return bgp_redistribute_set(bgp, AFI_IP, type, 0);
11473 }
11474
11475 ALIAS_HIDDEN(
11476 bgp_redistribute_ipv4_rmap, bgp_redistribute_ipv4_rmap_hidden_cmd,
11477 "redistribute " FRR_IP_REDIST_STR_BGPD " route-map WORD",
11478 "Redistribute information from another routing protocol\n" FRR_IP_REDIST_HELP_STR_BGPD
11479 "Route map reference\n"
11480 "Pointer to route-map entries\n")
11481
11482 DEFUN (bgp_redistribute_ipv4_metric,
11483 bgp_redistribute_ipv4_metric_cmd,
11484 "redistribute " FRR_IP_REDIST_STR_BGPD " metric (0-4294967295)",
11485 "Redistribute information from another routing protocol\n"
11486 FRR_IP_REDIST_HELP_STR_BGPD
11487 "Metric for redistributed routes\n"
11488 "Default metric\n")
11489 {
11490 VTY_DECLVAR_CONTEXT(bgp, bgp);
11491 int idx_protocol = 1;
11492 int idx_number = 3;
11493 int type;
11494 uint32_t metric;
11495 struct bgp_redist *red;
11496
11497 type = proto_redistnum(AFI_IP, argv[idx_protocol]->text);
11498 if (type < 0) {
11499 vty_out(vty, "%% Invalid route type\n");
11500 return CMD_WARNING_CONFIG_FAILED;
11501 }
11502 metric = strtoul(argv[idx_number]->arg, NULL, 10);
11503
11504 red = bgp_redist_add(bgp, AFI_IP, type, 0);
11505 bgp_redistribute_metric_set(bgp, red, AFI_IP, type, metric);
11506 return bgp_redistribute_set(bgp, AFI_IP, type, 0);
11507 }
11508
11509 ALIAS_HIDDEN(
11510 bgp_redistribute_ipv4_metric, bgp_redistribute_ipv4_metric_hidden_cmd,
11511 "redistribute " FRR_IP_REDIST_STR_BGPD " metric (0-4294967295)",
11512 "Redistribute information from another routing protocol\n" FRR_IP_REDIST_HELP_STR_BGPD
11513 "Metric for redistributed routes\n"
11514 "Default metric\n")
11515
11516 DEFUN (bgp_redistribute_ipv4_rmap_metric,
11517 bgp_redistribute_ipv4_rmap_metric_cmd,
11518 "redistribute " FRR_IP_REDIST_STR_BGPD " route-map WORD metric (0-4294967295)",
11519 "Redistribute information from another routing protocol\n"
11520 FRR_IP_REDIST_HELP_STR_BGPD
11521 "Route map reference\n"
11522 "Pointer to route-map entries\n"
11523 "Metric for redistributed routes\n"
11524 "Default metric\n")
11525 {
11526 VTY_DECLVAR_CONTEXT(bgp, bgp);
11527 int idx_protocol = 1;
11528 int idx_word = 3;
11529 int idx_number = 5;
11530 int type;
11531 uint32_t metric;
11532 struct bgp_redist *red;
11533
11534 type = proto_redistnum(AFI_IP, argv[idx_protocol]->text);
11535 if (type < 0) {
11536 vty_out(vty, "%% Invalid route type\n");
11537 return CMD_WARNING_CONFIG_FAILED;
11538 }
11539 metric = strtoul(argv[idx_number]->arg, NULL, 10);
11540
11541 red = bgp_redist_add(bgp, AFI_IP, type, 0);
11542 bgp_redistribute_rmap_set(red, argv[idx_word]->arg);
11543 bgp_redistribute_metric_set(bgp, red, AFI_IP, type, metric);
11544 return bgp_redistribute_set(bgp, AFI_IP, type, 0);
11545 }
11546
11547 ALIAS_HIDDEN(
11548 bgp_redistribute_ipv4_rmap_metric,
11549 bgp_redistribute_ipv4_rmap_metric_hidden_cmd,
11550 "redistribute " FRR_IP_REDIST_STR_BGPD
11551 " route-map WORD metric (0-4294967295)",
11552 "Redistribute information from another routing protocol\n" FRR_IP_REDIST_HELP_STR_BGPD
11553 "Route map reference\n"
11554 "Pointer to route-map entries\n"
11555 "Metric for redistributed routes\n"
11556 "Default metric\n")
11557
11558 DEFUN (bgp_redistribute_ipv4_metric_rmap,
11559 bgp_redistribute_ipv4_metric_rmap_cmd,
11560 "redistribute " FRR_IP_REDIST_STR_BGPD " metric (0-4294967295) route-map WORD",
11561 "Redistribute information from another routing protocol\n"
11562 FRR_IP_REDIST_HELP_STR_BGPD
11563 "Metric for redistributed routes\n"
11564 "Default metric\n"
11565 "Route map reference\n"
11566 "Pointer to route-map entries\n")
11567 {
11568 VTY_DECLVAR_CONTEXT(bgp, bgp);
11569 int idx_protocol = 1;
11570 int idx_number = 3;
11571 int idx_word = 5;
11572 int type;
11573 uint32_t metric;
11574 struct bgp_redist *red;
11575
11576 type = proto_redistnum(AFI_IP, argv[idx_protocol]->text);
11577 if (type < 0) {
11578 vty_out(vty, "%% Invalid route type\n");
11579 return CMD_WARNING_CONFIG_FAILED;
11580 }
11581 metric = strtoul(argv[idx_number]->arg, NULL, 10);
11582
11583 red = bgp_redist_add(bgp, AFI_IP, type, 0);
11584 bgp_redistribute_metric_set(bgp, red, AFI_IP, type, metric);
11585 bgp_redistribute_rmap_set(red, argv[idx_word]->arg);
11586 return bgp_redistribute_set(bgp, AFI_IP, type, 0);
11587 }
11588
11589 ALIAS_HIDDEN(
11590 bgp_redistribute_ipv4_metric_rmap,
11591 bgp_redistribute_ipv4_metric_rmap_hidden_cmd,
11592 "redistribute " FRR_IP_REDIST_STR_BGPD
11593 " metric (0-4294967295) route-map WORD",
11594 "Redistribute information from another routing protocol\n" FRR_IP_REDIST_HELP_STR_BGPD
11595 "Metric for redistributed routes\n"
11596 "Default metric\n"
11597 "Route map reference\n"
11598 "Pointer to route-map entries\n")
11599
11600 DEFUN (bgp_redistribute_ipv4_ospf,
11601 bgp_redistribute_ipv4_ospf_cmd,
11602 "redistribute <ospf|table> (1-65535)",
11603 "Redistribute information from another routing protocol\n"
11604 "Open Shortest Path First (OSPFv2)\n"
11605 "Non-main Kernel Routing Table\n"
11606 "Instance ID/Table ID\n")
11607 {
11608 VTY_DECLVAR_CONTEXT(bgp, bgp);
11609 int idx_ospf_table = 1;
11610 int idx_number = 2;
11611 unsigned short instance;
11612 unsigned short protocol;
11613
11614 instance = strtoul(argv[idx_number]->arg, NULL, 10);
11615
11616 if (strncmp(argv[idx_ospf_table]->arg, "o", 1) == 0)
11617 protocol = ZEBRA_ROUTE_OSPF;
11618 else
11619 protocol = ZEBRA_ROUTE_TABLE;
11620
11621 bgp_redist_add(bgp, AFI_IP, protocol, instance);
11622 return bgp_redistribute_set(bgp, AFI_IP, protocol, instance);
11623 }
11624
11625 ALIAS_HIDDEN(bgp_redistribute_ipv4_ospf, bgp_redistribute_ipv4_ospf_hidden_cmd,
11626 "redistribute <ospf|table> (1-65535)",
11627 "Redistribute information from another routing protocol\n"
11628 "Open Shortest Path First (OSPFv2)\n"
11629 "Non-main Kernel Routing Table\n"
11630 "Instance ID/Table ID\n")
11631
11632 DEFUN (bgp_redistribute_ipv4_ospf_rmap,
11633 bgp_redistribute_ipv4_ospf_rmap_cmd,
11634 "redistribute <ospf|table> (1-65535) route-map WORD",
11635 "Redistribute information from another routing protocol\n"
11636 "Open Shortest Path First (OSPFv2)\n"
11637 "Non-main Kernel Routing Table\n"
11638 "Instance ID/Table ID\n"
11639 "Route map reference\n"
11640 "Pointer to route-map entries\n")
11641 {
11642 VTY_DECLVAR_CONTEXT(bgp, bgp);
11643 int idx_ospf_table = 1;
11644 int idx_number = 2;
11645 int idx_word = 4;
11646 struct bgp_redist *red;
11647 unsigned short instance;
11648 int protocol;
11649
11650 if (strncmp(argv[idx_ospf_table]->arg, "o", 1) == 0)
11651 protocol = ZEBRA_ROUTE_OSPF;
11652 else
11653 protocol = ZEBRA_ROUTE_TABLE;
11654
11655 instance = strtoul(argv[idx_number]->arg, NULL, 10);
11656 red = bgp_redist_add(bgp, AFI_IP, protocol, instance);
11657 bgp_redistribute_rmap_set(red, argv[idx_word]->arg);
11658 return bgp_redistribute_set(bgp, AFI_IP, protocol, instance);
11659 }
11660
11661 ALIAS_HIDDEN(bgp_redistribute_ipv4_ospf_rmap,
11662 bgp_redistribute_ipv4_ospf_rmap_hidden_cmd,
11663 "redistribute <ospf|table> (1-65535) route-map WORD",
11664 "Redistribute information from another routing protocol\n"
11665 "Open Shortest Path First (OSPFv2)\n"
11666 "Non-main Kernel Routing Table\n"
11667 "Instance ID/Table ID\n"
11668 "Route map reference\n"
11669 "Pointer to route-map entries\n")
11670
11671 DEFUN (bgp_redistribute_ipv4_ospf_metric,
11672 bgp_redistribute_ipv4_ospf_metric_cmd,
11673 "redistribute <ospf|table> (1-65535) metric (0-4294967295)",
11674 "Redistribute information from another routing protocol\n"
11675 "Open Shortest Path First (OSPFv2)\n"
11676 "Non-main Kernel Routing Table\n"
11677 "Instance ID/Table ID\n"
11678 "Metric for redistributed routes\n"
11679 "Default metric\n")
11680 {
11681 VTY_DECLVAR_CONTEXT(bgp, bgp);
11682 int idx_ospf_table = 1;
11683 int idx_number = 2;
11684 int idx_number_2 = 4;
11685 uint32_t metric;
11686 struct bgp_redist *red;
11687 unsigned short instance;
11688 int protocol;
11689
11690 if (strncmp(argv[idx_ospf_table]->arg, "o", 1) == 0)
11691 protocol = ZEBRA_ROUTE_OSPF;
11692 else
11693 protocol = ZEBRA_ROUTE_TABLE;
11694
11695 instance = strtoul(argv[idx_number]->arg, NULL, 10);
11696 metric = strtoul(argv[idx_number_2]->arg, NULL, 10);
11697
11698 red = bgp_redist_add(bgp, AFI_IP, protocol, instance);
11699 bgp_redistribute_metric_set(bgp, red, AFI_IP, protocol, metric);
11700 return bgp_redistribute_set(bgp, AFI_IP, protocol, instance);
11701 }
11702
11703 ALIAS_HIDDEN(bgp_redistribute_ipv4_ospf_metric,
11704 bgp_redistribute_ipv4_ospf_metric_hidden_cmd,
11705 "redistribute <ospf|table> (1-65535) metric (0-4294967295)",
11706 "Redistribute information from another routing protocol\n"
11707 "Open Shortest Path First (OSPFv2)\n"
11708 "Non-main Kernel Routing Table\n"
11709 "Instance ID/Table ID\n"
11710 "Metric for redistributed routes\n"
11711 "Default metric\n")
11712
11713 DEFUN (bgp_redistribute_ipv4_ospf_rmap_metric,
11714 bgp_redistribute_ipv4_ospf_rmap_metric_cmd,
11715 "redistribute <ospf|table> (1-65535) route-map WORD metric (0-4294967295)",
11716 "Redistribute information from another routing protocol\n"
11717 "Open Shortest Path First (OSPFv2)\n"
11718 "Non-main Kernel Routing Table\n"
11719 "Instance ID/Table ID\n"
11720 "Route map reference\n"
11721 "Pointer to route-map entries\n"
11722 "Metric for redistributed routes\n"
11723 "Default metric\n")
11724 {
11725 VTY_DECLVAR_CONTEXT(bgp, bgp);
11726 int idx_ospf_table = 1;
11727 int idx_number = 2;
11728 int idx_word = 4;
11729 int idx_number_2 = 6;
11730 uint32_t metric;
11731 struct bgp_redist *red;
11732 unsigned short instance;
11733 int protocol;
11734
11735 if (strncmp(argv[idx_ospf_table]->arg, "o", 1) == 0)
11736 protocol = ZEBRA_ROUTE_OSPF;
11737 else
11738 protocol = ZEBRA_ROUTE_TABLE;
11739
11740 instance = strtoul(argv[idx_number]->arg, NULL, 10);
11741 metric = strtoul(argv[idx_number_2]->arg, NULL, 10);
11742
11743 red = bgp_redist_add(bgp, AFI_IP, protocol, instance);
11744 bgp_redistribute_rmap_set(red, argv[idx_word]->arg);
11745 bgp_redistribute_metric_set(bgp, red, AFI_IP, protocol, metric);
11746 return bgp_redistribute_set(bgp, AFI_IP, protocol, instance);
11747 }
11748
11749 ALIAS_HIDDEN(
11750 bgp_redistribute_ipv4_ospf_rmap_metric,
11751 bgp_redistribute_ipv4_ospf_rmap_metric_hidden_cmd,
11752 "redistribute <ospf|table> (1-65535) route-map WORD metric (0-4294967295)",
11753 "Redistribute information from another routing protocol\n"
11754 "Open Shortest Path First (OSPFv2)\n"
11755 "Non-main Kernel Routing Table\n"
11756 "Instance ID/Table ID\n"
11757 "Route map reference\n"
11758 "Pointer to route-map entries\n"
11759 "Metric for redistributed routes\n"
11760 "Default metric\n")
11761
11762 DEFUN (bgp_redistribute_ipv4_ospf_metric_rmap,
11763 bgp_redistribute_ipv4_ospf_metric_rmap_cmd,
11764 "redistribute <ospf|table> (1-65535) metric (0-4294967295) route-map WORD",
11765 "Redistribute information from another routing protocol\n"
11766 "Open Shortest Path First (OSPFv2)\n"
11767 "Non-main Kernel Routing Table\n"
11768 "Instance ID/Table ID\n"
11769 "Metric for redistributed routes\n"
11770 "Default metric\n"
11771 "Route map reference\n"
11772 "Pointer to route-map entries\n")
11773 {
11774 VTY_DECLVAR_CONTEXT(bgp, bgp);
11775 int idx_ospf_table = 1;
11776 int idx_number = 2;
11777 int idx_number_2 = 4;
11778 int idx_word = 6;
11779 uint32_t metric;
11780 struct bgp_redist *red;
11781 unsigned short instance;
11782 int protocol;
11783
11784 if (strncmp(argv[idx_ospf_table]->arg, "o", 1) == 0)
11785 protocol = ZEBRA_ROUTE_OSPF;
11786 else
11787 protocol = ZEBRA_ROUTE_TABLE;
11788
11789 instance = strtoul(argv[idx_number]->arg, NULL, 10);
11790 metric = strtoul(argv[idx_number_2]->arg, NULL, 10);
11791
11792 red = bgp_redist_add(bgp, AFI_IP, protocol, instance);
11793 bgp_redistribute_metric_set(bgp, red, AFI_IP, protocol, metric);
11794 bgp_redistribute_rmap_set(red, argv[idx_word]->arg);
11795 return bgp_redistribute_set(bgp, AFI_IP, protocol, instance);
11796 }
11797
11798 ALIAS_HIDDEN(
11799 bgp_redistribute_ipv4_ospf_metric_rmap,
11800 bgp_redistribute_ipv4_ospf_metric_rmap_hidden_cmd,
11801 "redistribute <ospf|table> (1-65535) metric (0-4294967295) route-map WORD",
11802 "Redistribute information from another routing protocol\n"
11803 "Open Shortest Path First (OSPFv2)\n"
11804 "Non-main Kernel Routing Table\n"
11805 "Instance ID/Table ID\n"
11806 "Metric for redistributed routes\n"
11807 "Default metric\n"
11808 "Route map reference\n"
11809 "Pointer to route-map entries\n")
11810
11811 DEFUN (no_bgp_redistribute_ipv4_ospf,
11812 no_bgp_redistribute_ipv4_ospf_cmd,
11813 "no redistribute <ospf|table> (1-65535) [metric (0-4294967295)] [route-map WORD]",
11814 NO_STR
11815 "Redistribute information from another routing protocol\n"
11816 "Open Shortest Path First (OSPFv2)\n"
11817 "Non-main Kernel Routing Table\n"
11818 "Instance ID/Table ID\n"
11819 "Metric for redistributed routes\n"
11820 "Default metric\n"
11821 "Route map reference\n"
11822 "Pointer to route-map entries\n")
11823 {
11824 VTY_DECLVAR_CONTEXT(bgp, bgp);
11825 int idx_ospf_table = 2;
11826 int idx_number = 3;
11827 unsigned short instance;
11828 int protocol;
11829
11830 if (strncmp(argv[idx_ospf_table]->arg, "o", 1) == 0)
11831 protocol = ZEBRA_ROUTE_OSPF;
11832 else
11833 protocol = ZEBRA_ROUTE_TABLE;
11834
11835 instance = strtoul(argv[idx_number]->arg, NULL, 10);
11836 return bgp_redistribute_unset(bgp, AFI_IP, protocol, instance);
11837 }
11838
11839 ALIAS_HIDDEN(
11840 no_bgp_redistribute_ipv4_ospf, no_bgp_redistribute_ipv4_ospf_hidden_cmd,
11841 "no redistribute <ospf|table> (1-65535) [metric (0-4294967295)] [route-map WORD]",
11842 NO_STR
11843 "Redistribute information from another routing protocol\n"
11844 "Open Shortest Path First (OSPFv2)\n"
11845 "Non-main Kernel Routing Table\n"
11846 "Instance ID/Table ID\n"
11847 "Metric for redistributed routes\n"
11848 "Default metric\n"
11849 "Route map reference\n"
11850 "Pointer to route-map entries\n")
11851
11852 DEFUN (no_bgp_redistribute_ipv4,
11853 no_bgp_redistribute_ipv4_cmd,
11854 "no redistribute " FRR_IP_REDIST_STR_BGPD " [metric (0-4294967295)] [route-map WORD]",
11855 NO_STR
11856 "Redistribute information from another routing protocol\n"
11857 FRR_IP_REDIST_HELP_STR_BGPD
11858 "Metric for redistributed routes\n"
11859 "Default metric\n"
11860 "Route map reference\n"
11861 "Pointer to route-map entries\n")
11862 {
11863 VTY_DECLVAR_CONTEXT(bgp, bgp);
11864 int idx_protocol = 2;
11865 int type;
11866
11867 type = proto_redistnum(AFI_IP, argv[idx_protocol]->text);
11868 if (type < 0) {
11869 vty_out(vty, "%% Invalid route type\n");
11870 return CMD_WARNING_CONFIG_FAILED;
11871 }
11872 return bgp_redistribute_unset(bgp, AFI_IP, type, 0);
11873 }
11874
11875 ALIAS_HIDDEN(
11876 no_bgp_redistribute_ipv4, no_bgp_redistribute_ipv4_hidden_cmd,
11877 "no redistribute " FRR_IP_REDIST_STR_BGPD
11878 " [metric (0-4294967295)] [route-map WORD]",
11879 NO_STR
11880 "Redistribute information from another routing protocol\n" FRR_IP_REDIST_HELP_STR_BGPD
11881 "Metric for redistributed routes\n"
11882 "Default metric\n"
11883 "Route map reference\n"
11884 "Pointer to route-map entries\n")
11885
11886 DEFUN (bgp_redistribute_ipv6,
11887 bgp_redistribute_ipv6_cmd,
11888 "redistribute " FRR_IP6_REDIST_STR_BGPD,
11889 "Redistribute information from another routing protocol\n"
11890 FRR_IP6_REDIST_HELP_STR_BGPD)
11891 {
11892 VTY_DECLVAR_CONTEXT(bgp, bgp);
11893 int idx_protocol = 1;
11894 int type;
11895
11896 type = proto_redistnum(AFI_IP6, argv[idx_protocol]->text);
11897 if (type < 0) {
11898 vty_out(vty, "%% Invalid route type\n");
11899 return CMD_WARNING_CONFIG_FAILED;
11900 }
11901
11902 bgp_redist_add(bgp, AFI_IP6, type, 0);
11903 return bgp_redistribute_set(bgp, AFI_IP6, type, 0);
11904 }
11905
11906 DEFUN (bgp_redistribute_ipv6_rmap,
11907 bgp_redistribute_ipv6_rmap_cmd,
11908 "redistribute " FRR_IP6_REDIST_STR_BGPD " route-map WORD",
11909 "Redistribute information from another routing protocol\n"
11910 FRR_IP6_REDIST_HELP_STR_BGPD
11911 "Route map reference\n"
11912 "Pointer to route-map entries\n")
11913 {
11914 VTY_DECLVAR_CONTEXT(bgp, bgp);
11915 int idx_protocol = 1;
11916 int idx_word = 3;
11917 int type;
11918 struct bgp_redist *red;
11919
11920 type = proto_redistnum(AFI_IP6, argv[idx_protocol]->text);
11921 if (type < 0) {
11922 vty_out(vty, "%% Invalid route type\n");
11923 return CMD_WARNING_CONFIG_FAILED;
11924 }
11925
11926 red = bgp_redist_add(bgp, AFI_IP6, type, 0);
11927 bgp_redistribute_rmap_set(red, argv[idx_word]->arg);
11928 return bgp_redistribute_set(bgp, AFI_IP6, type, 0);
11929 }
11930
11931 DEFUN (bgp_redistribute_ipv6_metric,
11932 bgp_redistribute_ipv6_metric_cmd,
11933 "redistribute " FRR_IP6_REDIST_STR_BGPD " metric (0-4294967295)",
11934 "Redistribute information from another routing protocol\n"
11935 FRR_IP6_REDIST_HELP_STR_BGPD
11936 "Metric for redistributed routes\n"
11937 "Default metric\n")
11938 {
11939 VTY_DECLVAR_CONTEXT(bgp, bgp);
11940 int idx_protocol = 1;
11941 int idx_number = 3;
11942 int type;
11943 uint32_t metric;
11944 struct bgp_redist *red;
11945
11946 type = proto_redistnum(AFI_IP6, argv[idx_protocol]->text);
11947 if (type < 0) {
11948 vty_out(vty, "%% Invalid route type\n");
11949 return CMD_WARNING_CONFIG_FAILED;
11950 }
11951 metric = strtoul(argv[idx_number]->arg, NULL, 10);
11952
11953 red = bgp_redist_add(bgp, AFI_IP6, type, 0);
11954 bgp_redistribute_metric_set(bgp, red, AFI_IP6, type, metric);
11955 return bgp_redistribute_set(bgp, AFI_IP6, type, 0);
11956 }
11957
11958 DEFUN (bgp_redistribute_ipv6_rmap_metric,
11959 bgp_redistribute_ipv6_rmap_metric_cmd,
11960 "redistribute " FRR_IP6_REDIST_STR_BGPD " route-map WORD metric (0-4294967295)",
11961 "Redistribute information from another routing protocol\n"
11962 FRR_IP6_REDIST_HELP_STR_BGPD
11963 "Route map reference\n"
11964 "Pointer to route-map entries\n"
11965 "Metric for redistributed routes\n"
11966 "Default metric\n")
11967 {
11968 VTY_DECLVAR_CONTEXT(bgp, bgp);
11969 int idx_protocol = 1;
11970 int idx_word = 3;
11971 int idx_number = 5;
11972 int type;
11973 uint32_t metric;
11974 struct bgp_redist *red;
11975
11976 type = proto_redistnum(AFI_IP6, argv[idx_protocol]->text);
11977 if (type < 0) {
11978 vty_out(vty, "%% Invalid route type\n");
11979 return CMD_WARNING_CONFIG_FAILED;
11980 }
11981 metric = strtoul(argv[idx_number]->arg, NULL, 10);
11982
11983 red = bgp_redist_add(bgp, AFI_IP6, type, 0);
11984 bgp_redistribute_rmap_set(red, argv[idx_word]->arg);
11985 bgp_redistribute_metric_set(bgp, red, AFI_IP6, type, metric);
11986 return bgp_redistribute_set(bgp, AFI_IP6, type, 0);
11987 }
11988
11989 DEFUN (bgp_redistribute_ipv6_metric_rmap,
11990 bgp_redistribute_ipv6_metric_rmap_cmd,
11991 "redistribute " FRR_IP6_REDIST_STR_BGPD " metric (0-4294967295) route-map WORD",
11992 "Redistribute information from another routing protocol\n"
11993 FRR_IP6_REDIST_HELP_STR_BGPD
11994 "Metric for redistributed routes\n"
11995 "Default metric\n"
11996 "Route map reference\n"
11997 "Pointer to route-map entries\n")
11998 {
11999 VTY_DECLVAR_CONTEXT(bgp, bgp);
12000 int idx_protocol = 1;
12001 int idx_number = 3;
12002 int idx_word = 5;
12003 int type;
12004 uint32_t metric;
12005 struct bgp_redist *red;
12006
12007 type = proto_redistnum(AFI_IP6, argv[idx_protocol]->text);
12008 if (type < 0) {
12009 vty_out(vty, "%% Invalid route type\n");
12010 return CMD_WARNING_CONFIG_FAILED;
12011 }
12012 metric = strtoul(argv[idx_number]->arg, NULL, 10);
12013
12014 red = bgp_redist_add(bgp, AFI_IP6, type, 0);
12015 bgp_redistribute_metric_set(bgp, red, AFI_IP6, SAFI_UNICAST, metric);
12016 bgp_redistribute_rmap_set(red, argv[idx_word]->arg);
12017 return bgp_redistribute_set(bgp, AFI_IP6, type, 0);
12018 }
12019
12020 DEFUN (no_bgp_redistribute_ipv6,
12021 no_bgp_redistribute_ipv6_cmd,
12022 "no redistribute " FRR_IP6_REDIST_STR_BGPD " [metric (0-4294967295)] [route-map WORD]",
12023 NO_STR
12024 "Redistribute information from another routing protocol\n"
12025 FRR_IP6_REDIST_HELP_STR_BGPD
12026 "Metric for redistributed routes\n"
12027 "Default metric\n"
12028 "Route map reference\n"
12029 "Pointer to route-map entries\n")
12030 {
12031 VTY_DECLVAR_CONTEXT(bgp, bgp);
12032 int idx_protocol = 2;
12033 int type;
12034
12035 type = proto_redistnum(AFI_IP6, argv[idx_protocol]->text);
12036 if (type < 0) {
12037 vty_out(vty, "%% Invalid route type\n");
12038 return CMD_WARNING_CONFIG_FAILED;
12039 }
12040
12041 return bgp_redistribute_unset(bgp, AFI_IP6, type, 0);
12042 }
12043
12044 void bgp_config_write_redistribute(struct vty *vty, struct bgp *bgp, afi_t afi,
12045 safi_t safi)
12046 {
12047 int i;
12048
12049 /* Unicast redistribution only. */
12050 if (safi != SAFI_UNICAST)
12051 return;
12052
12053 for (i = 0; i < ZEBRA_ROUTE_MAX; i++) {
12054 /* Redistribute BGP does not make sense. */
12055 if (i != ZEBRA_ROUTE_BGP) {
12056 struct list *red_list;
12057 struct listnode *node;
12058 struct bgp_redist *red;
12059
12060 red_list = bgp->redist[afi][i];
12061 if (!red_list)
12062 continue;
12063
12064 for (ALL_LIST_ELEMENTS_RO(red_list, node, red)) {
12065 /* "redistribute" configuration. */
12066 vty_out(vty, " redistribute %s",
12067 zebra_route_string(i));
12068 if (red->instance)
12069 vty_out(vty, " %d", red->instance);
12070 if (red->redist_metric_flag)
12071 vty_out(vty, " metric %u",
12072 red->redist_metric);
12073 if (red->rmap.name)
12074 vty_out(vty, " route-map %s",
12075 red->rmap.name);
12076 vty_out(vty, "\n");
12077 }
12078 }
12079 }
12080 }
12081
12082 /* This is part of the address-family block (unicast only) */
12083 void bgp_vpn_policy_config_write_afi(struct vty *vty, struct bgp *bgp,
12084 afi_t afi)
12085 {
12086 int indent = 2;
12087
12088 if (bgp->vpn_policy[afi].rmap_name[BGP_VPN_POLICY_DIR_FROMVPN])
12089 vty_out(vty, "%*simport vrf route-map %s\n", indent, "",
12090 bgp->vpn_policy[afi]
12091 .rmap_name[BGP_VPN_POLICY_DIR_FROMVPN]);
12092
12093 if (CHECK_FLAG(bgp->af_flags[afi][SAFI_UNICAST],
12094 BGP_CONFIG_VRF_TO_VRF_IMPORT)
12095 || CHECK_FLAG(bgp->af_flags[afi][SAFI_UNICAST],
12096 BGP_CONFIG_VRF_TO_VRF_EXPORT))
12097 return;
12098
12099 if (CHECK_FLAG(bgp->vpn_policy[afi].flags,
12100 BGP_VPN_POLICY_TOVPN_LABEL_AUTO)) {
12101
12102 vty_out(vty, "%*slabel vpn export %s\n", indent, "", "auto");
12103
12104 } else {
12105 if (bgp->vpn_policy[afi].tovpn_label != MPLS_LABEL_NONE) {
12106 vty_out(vty, "%*slabel vpn export %u\n", indent, "",
12107 bgp->vpn_policy[afi].tovpn_label);
12108 }
12109 }
12110 if (CHECK_FLAG(bgp->vpn_policy[afi].flags,
12111 BGP_VPN_POLICY_TOVPN_RD_SET)) {
12112 char buf[RD_ADDRSTRLEN];
12113 vty_out(vty, "%*srd vpn export %s\n", indent, "",
12114 prefix_rd2str(&bgp->vpn_policy[afi].tovpn_rd, buf,
12115 sizeof(buf)));
12116 }
12117 if (CHECK_FLAG(bgp->vpn_policy[afi].flags,
12118 BGP_VPN_POLICY_TOVPN_NEXTHOP_SET)) {
12119
12120 char buf[PREFIX_STRLEN];
12121 if (inet_ntop(bgp->vpn_policy[afi].tovpn_nexthop.family,
12122 &bgp->vpn_policy[afi].tovpn_nexthop.u.prefix, buf,
12123 sizeof(buf))) {
12124
12125 vty_out(vty, "%*snexthop vpn export %s\n",
12126 indent, "", buf);
12127 }
12128 }
12129 if (bgp->vpn_policy[afi].rtlist[BGP_VPN_POLICY_DIR_FROMVPN]
12130 && bgp->vpn_policy[afi].rtlist[BGP_VPN_POLICY_DIR_TOVPN]
12131 && ecommunity_cmp(
12132 bgp->vpn_policy[afi].rtlist[BGP_VPN_POLICY_DIR_FROMVPN],
12133 bgp->vpn_policy[afi].rtlist[BGP_VPN_POLICY_DIR_TOVPN])) {
12134
12135 char *b = ecommunity_ecom2str(
12136 bgp->vpn_policy[afi].rtlist[BGP_VPN_POLICY_DIR_TOVPN],
12137 ECOMMUNITY_FORMAT_ROUTE_MAP, ECOMMUNITY_ROUTE_TARGET);
12138 vty_out(vty, "%*srt vpn both %s\n", indent, "", b);
12139 XFREE(MTYPE_ECOMMUNITY_STR, b);
12140 } else {
12141 if (bgp->vpn_policy[afi].rtlist[BGP_VPN_POLICY_DIR_FROMVPN]) {
12142 char *b = ecommunity_ecom2str(
12143 bgp->vpn_policy[afi]
12144 .rtlist[BGP_VPN_POLICY_DIR_FROMVPN],
12145 ECOMMUNITY_FORMAT_ROUTE_MAP,
12146 ECOMMUNITY_ROUTE_TARGET);
12147 vty_out(vty, "%*srt vpn import %s\n", indent, "", b);
12148 XFREE(MTYPE_ECOMMUNITY_STR, b);
12149 }
12150 if (bgp->vpn_policy[afi].rtlist[BGP_VPN_POLICY_DIR_TOVPN]) {
12151 char *b = ecommunity_ecom2str(
12152 bgp->vpn_policy[afi]
12153 .rtlist[BGP_VPN_POLICY_DIR_TOVPN],
12154 ECOMMUNITY_FORMAT_ROUTE_MAP,
12155 ECOMMUNITY_ROUTE_TARGET);
12156 vty_out(vty, "%*srt vpn export %s\n", indent, "", b);
12157 XFREE(MTYPE_ECOMMUNITY_STR, b);
12158 }
12159 }
12160
12161 if (bgp->vpn_policy[afi].rmap_name[BGP_VPN_POLICY_DIR_TOVPN])
12162 vty_out(vty, "%*sroute-map vpn export %s\n", indent, "",
12163 bgp->vpn_policy[afi]
12164 .rmap_name[BGP_VPN_POLICY_DIR_TOVPN]);
12165
12166 if (bgp->vpn_policy[afi].import_redirect_rtlist) {
12167 char *b = ecommunity_ecom2str(
12168 bgp->vpn_policy[afi]
12169 .import_redirect_rtlist,
12170 ECOMMUNITY_FORMAT_ROUTE_MAP,
12171 ECOMMUNITY_ROUTE_TARGET);
12172
12173 vty_out(vty, "%*srt redirect import %s\n", indent, "", b);
12174 XFREE(MTYPE_ECOMMUNITY_STR, b);
12175 }
12176 }
12177
12178
12179 /* BGP node structure. */
12180 static struct cmd_node bgp_node = {
12181 BGP_NODE, "%s(config-router)# ", 1,
12182 };
12183
12184 static struct cmd_node bgp_ipv4_unicast_node = {
12185 BGP_IPV4_NODE, "%s(config-router-af)# ", 1,
12186 };
12187
12188 static struct cmd_node bgp_ipv4_multicast_node = {
12189 BGP_IPV4M_NODE, "%s(config-router-af)# ", 1,
12190 };
12191
12192 static struct cmd_node bgp_ipv4_labeled_unicast_node = {
12193 BGP_IPV4L_NODE, "%s(config-router-af)# ", 1,
12194 };
12195
12196 static struct cmd_node bgp_ipv6_unicast_node = {
12197 BGP_IPV6_NODE, "%s(config-router-af)# ", 1,
12198 };
12199
12200 static struct cmd_node bgp_ipv6_multicast_node = {
12201 BGP_IPV6M_NODE, "%s(config-router-af)# ", 1,
12202 };
12203
12204 static struct cmd_node bgp_ipv6_labeled_unicast_node = {
12205 BGP_IPV6L_NODE, "%s(config-router-af)# ", 1,
12206 };
12207
12208 static struct cmd_node bgp_vpnv4_node = {BGP_VPNV4_NODE,
12209 "%s(config-router-af)# ", 1};
12210
12211 static struct cmd_node bgp_vpnv6_node = {BGP_VPNV6_NODE,
12212 "%s(config-router-af-vpnv6)# ", 1};
12213
12214 static struct cmd_node bgp_evpn_node = {BGP_EVPN_NODE,
12215 "%s(config-router-evpn)# ", 1};
12216
12217 static struct cmd_node bgp_evpn_vni_node = {BGP_EVPN_VNI_NODE,
12218 "%s(config-router-af-vni)# ", 1};
12219
12220 static struct cmd_node bgp_flowspecv4_node = {BGP_FLOWSPECV4_NODE,
12221 "%s(config-router-af)# ", 1};
12222
12223 static struct cmd_node bgp_flowspecv6_node = {BGP_FLOWSPECV6_NODE,
12224 "%s(config-router-af-vpnv6)# ", 1};
12225
12226 static void community_list_vty(void);
12227
12228 static void bgp_ac_neighbor(vector comps, struct cmd_token *token)
12229 {
12230 struct bgp *bgp;
12231 struct peer *peer;
12232 struct listnode *lnbgp, *lnpeer;
12233
12234 for (ALL_LIST_ELEMENTS_RO(bm->bgp, lnbgp, bgp)) {
12235 for (ALL_LIST_ELEMENTS_RO(bgp->peer, lnpeer, peer)) {
12236 /* only provide suggestions on the appropriate input
12237 * token type,
12238 * they'll otherwise show up multiple times */
12239 enum cmd_token_type match_type;
12240 char *name = peer->host;
12241
12242 if (peer->conf_if) {
12243 match_type = VARIABLE_TKN;
12244 name = peer->conf_if;
12245 } else if (strchr(peer->host, ':'))
12246 match_type = IPV6_TKN;
12247 else
12248 match_type = IPV4_TKN;
12249
12250 if (token->type != match_type)
12251 continue;
12252
12253 vector_set(comps, XSTRDUP(MTYPE_COMPLETION, name));
12254 }
12255 }
12256 }
12257
12258 static const struct cmd_variable_handler bgp_var_neighbor[] = {
12259 {.varname = "neighbor", .completions = bgp_ac_neighbor},
12260 {.varname = "neighbors", .completions = bgp_ac_neighbor},
12261 {.varname = "peer", .completions = bgp_ac_neighbor},
12262 {.completions = NULL}};
12263
12264 static void bgp_ac_peergroup(vector comps, struct cmd_token *token)
12265 {
12266 struct bgp *bgp;
12267 struct peer_group *group;
12268 struct listnode *lnbgp, *lnpeer;
12269
12270 for (ALL_LIST_ELEMENTS_RO(bm->bgp, lnbgp, bgp)) {
12271 for (ALL_LIST_ELEMENTS_RO(bgp->group, lnpeer, group))
12272 vector_set(comps, XSTRDUP(MTYPE_COMPLETION,
12273 group->name));
12274 }
12275 }
12276
12277 static const struct cmd_variable_handler bgp_var_peergroup[] = {
12278 {.tokenname = "PGNAME", .completions = bgp_ac_peergroup},
12279 {.completions = NULL} };
12280
12281 void bgp_vty_init(void)
12282 {
12283 cmd_variable_handler_register(bgp_var_neighbor);
12284 cmd_variable_handler_register(bgp_var_peergroup);
12285
12286 /* Install bgp top node. */
12287 install_node(&bgp_node, bgp_config_write);
12288 install_node(&bgp_ipv4_unicast_node, NULL);
12289 install_node(&bgp_ipv4_multicast_node, NULL);
12290 install_node(&bgp_ipv4_labeled_unicast_node, NULL);
12291 install_node(&bgp_ipv6_unicast_node, NULL);
12292 install_node(&bgp_ipv6_multicast_node, NULL);
12293 install_node(&bgp_ipv6_labeled_unicast_node, NULL);
12294 install_node(&bgp_vpnv4_node, NULL);
12295 install_node(&bgp_vpnv6_node, NULL);
12296 install_node(&bgp_evpn_node, NULL);
12297 install_node(&bgp_evpn_vni_node, NULL);
12298 install_node(&bgp_flowspecv4_node, NULL);
12299 install_node(&bgp_flowspecv6_node, NULL);
12300
12301 /* Install default VTY commands to new nodes. */
12302 install_default(BGP_NODE);
12303 install_default(BGP_IPV4_NODE);
12304 install_default(BGP_IPV4M_NODE);
12305 install_default(BGP_IPV4L_NODE);
12306 install_default(BGP_IPV6_NODE);
12307 install_default(BGP_IPV6M_NODE);
12308 install_default(BGP_IPV6L_NODE);
12309 install_default(BGP_VPNV4_NODE);
12310 install_default(BGP_VPNV6_NODE);
12311 install_default(BGP_FLOWSPECV4_NODE);
12312 install_default(BGP_FLOWSPECV6_NODE);
12313 install_default(BGP_EVPN_NODE);
12314 install_default(BGP_EVPN_VNI_NODE);
12315
12316 /* "bgp multiple-instance" commands. */
12317 install_element(CONFIG_NODE, &bgp_multiple_instance_cmd);
12318 install_element(CONFIG_NODE, &no_bgp_multiple_instance_cmd);
12319
12320 /* "bgp config-type" commands. */
12321 install_element(CONFIG_NODE, &bgp_config_type_cmd);
12322 install_element(CONFIG_NODE, &no_bgp_config_type_cmd);
12323
12324 /* bgp route-map delay-timer commands. */
12325 install_element(CONFIG_NODE, &bgp_set_route_map_delay_timer_cmd);
12326 install_element(CONFIG_NODE, &no_bgp_set_route_map_delay_timer_cmd);
12327
12328 /* Dummy commands (Currently not supported) */
12329 install_element(BGP_NODE, &no_synchronization_cmd);
12330 install_element(BGP_NODE, &no_auto_summary_cmd);
12331
12332 /* "router bgp" commands. */
12333 install_element(CONFIG_NODE, &router_bgp_cmd);
12334
12335 /* "no router bgp" commands. */
12336 install_element(CONFIG_NODE, &no_router_bgp_cmd);
12337
12338 /* "bgp router-id" commands. */
12339 install_element(BGP_NODE, &bgp_router_id_cmd);
12340 install_element(BGP_NODE, &no_bgp_router_id_cmd);
12341
12342 /* "bgp cluster-id" commands. */
12343 install_element(BGP_NODE, &bgp_cluster_id_cmd);
12344 install_element(BGP_NODE, &no_bgp_cluster_id_cmd);
12345
12346 /* "bgp confederation" commands. */
12347 install_element(BGP_NODE, &bgp_confederation_identifier_cmd);
12348 install_element(BGP_NODE, &no_bgp_confederation_identifier_cmd);
12349
12350 /* "bgp confederation peers" commands. */
12351 install_element(BGP_NODE, &bgp_confederation_peers_cmd);
12352 install_element(BGP_NODE, &no_bgp_confederation_peers_cmd);
12353
12354 /* bgp max-med command */
12355 install_element(BGP_NODE, &bgp_maxmed_admin_cmd);
12356 install_element(BGP_NODE, &no_bgp_maxmed_admin_cmd);
12357 install_element(BGP_NODE, &bgp_maxmed_admin_medv_cmd);
12358 install_element(BGP_NODE, &bgp_maxmed_onstartup_cmd);
12359 install_element(BGP_NODE, &no_bgp_maxmed_onstartup_cmd);
12360
12361 /* bgp disable-ebgp-connected-nh-check */
12362 install_element(BGP_NODE, &bgp_disable_connected_route_check_cmd);
12363 install_element(BGP_NODE, &no_bgp_disable_connected_route_check_cmd);
12364
12365 /* bgp update-delay command */
12366 install_element(BGP_NODE, &bgp_update_delay_cmd);
12367 install_element(BGP_NODE, &no_bgp_update_delay_cmd);
12368 install_element(BGP_NODE, &bgp_update_delay_establish_wait_cmd);
12369
12370 install_element(BGP_NODE, &bgp_wpkt_quanta_cmd);
12371 install_element(BGP_NODE, &no_bgp_wpkt_quanta_cmd);
12372 install_element(BGP_NODE, &bgp_rpkt_quanta_cmd);
12373 install_element(BGP_NODE, &no_bgp_rpkt_quanta_cmd);
12374
12375 install_element(BGP_NODE, &bgp_coalesce_time_cmd);
12376 install_element(BGP_NODE, &no_bgp_coalesce_time_cmd);
12377
12378 /* "maximum-paths" commands. */
12379 install_element(BGP_NODE, &bgp_maxpaths_hidden_cmd);
12380 install_element(BGP_NODE, &no_bgp_maxpaths_hidden_cmd);
12381 install_element(BGP_IPV4_NODE, &bgp_maxpaths_cmd);
12382 install_element(BGP_IPV4_NODE, &no_bgp_maxpaths_cmd);
12383 install_element(BGP_IPV6_NODE, &bgp_maxpaths_cmd);
12384 install_element(BGP_IPV6_NODE, &no_bgp_maxpaths_cmd);
12385 install_element(BGP_NODE, &bgp_maxpaths_ibgp_hidden_cmd);
12386 install_element(BGP_NODE, &bgp_maxpaths_ibgp_cluster_hidden_cmd);
12387 install_element(BGP_NODE, &no_bgp_maxpaths_ibgp_hidden_cmd);
12388 install_element(BGP_IPV4_NODE, &bgp_maxpaths_ibgp_cmd);
12389 install_element(BGP_IPV4_NODE, &bgp_maxpaths_ibgp_cluster_cmd);
12390 install_element(BGP_IPV4_NODE, &no_bgp_maxpaths_ibgp_cmd);
12391 install_element(BGP_IPV6_NODE, &bgp_maxpaths_ibgp_cmd);
12392 install_element(BGP_IPV6_NODE, &bgp_maxpaths_ibgp_cluster_cmd);
12393 install_element(BGP_IPV6_NODE, &no_bgp_maxpaths_ibgp_cmd);
12394
12395 install_element(BGP_IPV6L_NODE, &bgp_maxpaths_cmd);
12396 install_element(BGP_IPV6L_NODE, &no_bgp_maxpaths_cmd);
12397 install_element(BGP_IPV6L_NODE, &bgp_maxpaths_ibgp_cmd);
12398 install_element(BGP_IPV6L_NODE, &bgp_maxpaths_ibgp_cluster_cmd);
12399 install_element(BGP_IPV6L_NODE, &no_bgp_maxpaths_ibgp_cmd);
12400
12401 /* "timers bgp" commands. */
12402 install_element(BGP_NODE, &bgp_timers_cmd);
12403 install_element(BGP_NODE, &no_bgp_timers_cmd);
12404
12405 /* route-map delay-timer commands - per instance for backwards compat.
12406 */
12407 install_element(BGP_NODE, &bgp_set_route_map_delay_timer_cmd);
12408 install_element(BGP_NODE, &no_bgp_set_route_map_delay_timer_cmd);
12409
12410 /* "bgp client-to-client reflection" commands */
12411 install_element(BGP_NODE, &no_bgp_client_to_client_reflection_cmd);
12412 install_element(BGP_NODE, &bgp_client_to_client_reflection_cmd);
12413
12414 /* "bgp always-compare-med" commands */
12415 install_element(BGP_NODE, &bgp_always_compare_med_cmd);
12416 install_element(BGP_NODE, &no_bgp_always_compare_med_cmd);
12417
12418 /* "bgp deterministic-med" commands */
12419 install_element(BGP_NODE, &bgp_deterministic_med_cmd);
12420 install_element(BGP_NODE, &no_bgp_deterministic_med_cmd);
12421
12422 /* "bgp graceful-restart" commands */
12423 install_element(BGP_NODE, &bgp_graceful_restart_cmd);
12424 install_element(BGP_NODE, &no_bgp_graceful_restart_cmd);
12425 install_element(BGP_NODE, &bgp_graceful_restart_stalepath_time_cmd);
12426 install_element(BGP_NODE, &no_bgp_graceful_restart_stalepath_time_cmd);
12427 install_element(BGP_NODE, &bgp_graceful_restart_restart_time_cmd);
12428 install_element(BGP_NODE, &no_bgp_graceful_restart_restart_time_cmd);
12429
12430 install_element(BGP_NODE, &bgp_graceful_restart_preserve_fw_cmd);
12431 install_element(BGP_NODE, &no_bgp_graceful_restart_preserve_fw_cmd);
12432
12433 /* "bgp graceful-shutdown" commands */
12434 install_element(BGP_NODE, &bgp_graceful_shutdown_cmd);
12435 install_element(BGP_NODE, &no_bgp_graceful_shutdown_cmd);
12436
12437 /* "bgp fast-external-failover" commands */
12438 install_element(BGP_NODE, &bgp_fast_external_failover_cmd);
12439 install_element(BGP_NODE, &no_bgp_fast_external_failover_cmd);
12440
12441 /* "bgp enforce-first-as" commands */
12442 install_element(BGP_NODE, &bgp_enforce_first_as_cmd);
12443 install_element(BGP_NODE, &no_bgp_enforce_first_as_cmd);
12444
12445 /* "bgp bestpath compare-routerid" commands */
12446 install_element(BGP_NODE, &bgp_bestpath_compare_router_id_cmd);
12447 install_element(BGP_NODE, &no_bgp_bestpath_compare_router_id_cmd);
12448
12449 /* "bgp bestpath as-path ignore" commands */
12450 install_element(BGP_NODE, &bgp_bestpath_aspath_ignore_cmd);
12451 install_element(BGP_NODE, &no_bgp_bestpath_aspath_ignore_cmd);
12452
12453 /* "bgp bestpath as-path confed" commands */
12454 install_element(BGP_NODE, &bgp_bestpath_aspath_confed_cmd);
12455 install_element(BGP_NODE, &no_bgp_bestpath_aspath_confed_cmd);
12456
12457 /* "bgp bestpath as-path multipath-relax" commands */
12458 install_element(BGP_NODE, &bgp_bestpath_aspath_multipath_relax_cmd);
12459 install_element(BGP_NODE, &no_bgp_bestpath_aspath_multipath_relax_cmd);
12460
12461 /* "bgp log-neighbor-changes" commands */
12462 install_element(BGP_NODE, &bgp_log_neighbor_changes_cmd);
12463 install_element(BGP_NODE, &no_bgp_log_neighbor_changes_cmd);
12464
12465 /* "bgp bestpath med" commands */
12466 install_element(BGP_NODE, &bgp_bestpath_med_cmd);
12467 install_element(BGP_NODE, &no_bgp_bestpath_med_cmd);
12468
12469 /* "no bgp default ipv4-unicast" commands. */
12470 install_element(BGP_NODE, &no_bgp_default_ipv4_unicast_cmd);
12471 install_element(BGP_NODE, &bgp_default_ipv4_unicast_cmd);
12472
12473 /* "bgp network import-check" commands. */
12474 install_element(BGP_NODE, &bgp_network_import_check_cmd);
12475 install_element(BGP_NODE, &bgp_network_import_check_exact_cmd);
12476 install_element(BGP_NODE, &no_bgp_network_import_check_cmd);
12477
12478 /* "bgp default local-preference" commands. */
12479 install_element(BGP_NODE, &bgp_default_local_preference_cmd);
12480 install_element(BGP_NODE, &no_bgp_default_local_preference_cmd);
12481
12482 /* bgp default show-hostname */
12483 install_element(BGP_NODE, &bgp_default_show_hostname_cmd);
12484 install_element(BGP_NODE, &no_bgp_default_show_hostname_cmd);
12485
12486 /* "bgp default subgroup-pkt-queue-max" commands. */
12487 install_element(BGP_NODE, &bgp_default_subgroup_pkt_queue_max_cmd);
12488 install_element(BGP_NODE, &no_bgp_default_subgroup_pkt_queue_max_cmd);
12489
12490 /* bgp ibgp-allow-policy-mods command */
12491 install_element(BGP_NODE, &bgp_rr_allow_outbound_policy_cmd);
12492 install_element(BGP_NODE, &no_bgp_rr_allow_outbound_policy_cmd);
12493
12494 /* "bgp listen limit" commands. */
12495 install_element(BGP_NODE, &bgp_listen_limit_cmd);
12496 install_element(BGP_NODE, &no_bgp_listen_limit_cmd);
12497
12498 /* "bgp listen range" commands. */
12499 install_element(BGP_NODE, &bgp_listen_range_cmd);
12500 install_element(BGP_NODE, &no_bgp_listen_range_cmd);
12501
12502 /* "bgp default shutdown" command */
12503 install_element(BGP_NODE, &bgp_default_shutdown_cmd);
12504
12505 /* "neighbor remote-as" commands. */
12506 install_element(BGP_NODE, &neighbor_remote_as_cmd);
12507 install_element(BGP_NODE, &neighbor_interface_config_cmd);
12508 install_element(BGP_NODE, &neighbor_interface_config_v6only_cmd);
12509 install_element(BGP_NODE, &neighbor_interface_config_remote_as_cmd);
12510 install_element(BGP_NODE,
12511 &neighbor_interface_v6only_config_remote_as_cmd);
12512 install_element(BGP_NODE, &no_neighbor_cmd);
12513 install_element(BGP_NODE, &no_neighbor_interface_config_cmd);
12514
12515 /* "neighbor peer-group" commands. */
12516 install_element(BGP_NODE, &neighbor_peer_group_cmd);
12517 install_element(BGP_NODE, &no_neighbor_peer_group_cmd);
12518 install_element(BGP_NODE,
12519 &no_neighbor_interface_peer_group_remote_as_cmd);
12520
12521 /* "neighbor local-as" commands. */
12522 install_element(BGP_NODE, &neighbor_local_as_cmd);
12523 install_element(BGP_NODE, &neighbor_local_as_no_prepend_cmd);
12524 install_element(BGP_NODE, &neighbor_local_as_no_prepend_replace_as_cmd);
12525 install_element(BGP_NODE, &no_neighbor_local_as_cmd);
12526
12527 /* "neighbor solo" commands. */
12528 install_element(BGP_NODE, &neighbor_solo_cmd);
12529 install_element(BGP_NODE, &no_neighbor_solo_cmd);
12530
12531 /* "neighbor password" commands. */
12532 install_element(BGP_NODE, &neighbor_password_cmd);
12533 install_element(BGP_NODE, &no_neighbor_password_cmd);
12534
12535 /* "neighbor activate" commands. */
12536 install_element(BGP_NODE, &neighbor_activate_hidden_cmd);
12537 install_element(BGP_IPV4_NODE, &neighbor_activate_cmd);
12538 install_element(BGP_IPV4M_NODE, &neighbor_activate_cmd);
12539 install_element(BGP_IPV4L_NODE, &neighbor_activate_cmd);
12540 install_element(BGP_IPV6_NODE, &neighbor_activate_cmd);
12541 install_element(BGP_IPV6M_NODE, &neighbor_activate_cmd);
12542 install_element(BGP_IPV6L_NODE, &neighbor_activate_cmd);
12543 install_element(BGP_VPNV4_NODE, &neighbor_activate_cmd);
12544 install_element(BGP_VPNV6_NODE, &neighbor_activate_cmd);
12545 install_element(BGP_FLOWSPECV4_NODE, &neighbor_activate_cmd);
12546 install_element(BGP_FLOWSPECV6_NODE, &neighbor_activate_cmd);
12547 install_element(BGP_EVPN_NODE, &neighbor_activate_cmd);
12548
12549 /* "no neighbor activate" commands. */
12550 install_element(BGP_NODE, &no_neighbor_activate_hidden_cmd);
12551 install_element(BGP_IPV4_NODE, &no_neighbor_activate_cmd);
12552 install_element(BGP_IPV4M_NODE, &no_neighbor_activate_cmd);
12553 install_element(BGP_IPV4L_NODE, &no_neighbor_activate_cmd);
12554 install_element(BGP_IPV6_NODE, &no_neighbor_activate_cmd);
12555 install_element(BGP_IPV6M_NODE, &no_neighbor_activate_cmd);
12556 install_element(BGP_IPV6L_NODE, &no_neighbor_activate_cmd);
12557 install_element(BGP_VPNV4_NODE, &no_neighbor_activate_cmd);
12558 install_element(BGP_VPNV6_NODE, &no_neighbor_activate_cmd);
12559 install_element(BGP_FLOWSPECV4_NODE, &no_neighbor_activate_cmd);
12560 install_element(BGP_FLOWSPECV6_NODE, &no_neighbor_activate_cmd);
12561 install_element(BGP_EVPN_NODE, &no_neighbor_activate_cmd);
12562
12563 /* "neighbor peer-group" set commands. */
12564 install_element(BGP_NODE, &neighbor_set_peer_group_cmd);
12565 install_element(BGP_IPV4_NODE, &neighbor_set_peer_group_hidden_cmd);
12566 install_element(BGP_IPV4M_NODE, &neighbor_set_peer_group_hidden_cmd);
12567 install_element(BGP_IPV6_NODE, &neighbor_set_peer_group_hidden_cmd);
12568 install_element(BGP_IPV6M_NODE, &neighbor_set_peer_group_hidden_cmd);
12569 install_element(BGP_IPV6L_NODE, &neighbor_set_peer_group_hidden_cmd);
12570 install_element(BGP_VPNV4_NODE, &neighbor_set_peer_group_hidden_cmd);
12571 install_element(BGP_VPNV6_NODE, &neighbor_set_peer_group_hidden_cmd);
12572 install_element(BGP_FLOWSPECV4_NODE,
12573 &neighbor_set_peer_group_hidden_cmd);
12574 install_element(BGP_FLOWSPECV6_NODE,
12575 &neighbor_set_peer_group_hidden_cmd);
12576
12577 /* "no neighbor peer-group unset" commands. */
12578 install_element(BGP_NODE, &no_neighbor_set_peer_group_cmd);
12579 install_element(BGP_IPV4_NODE, &no_neighbor_set_peer_group_hidden_cmd);
12580 install_element(BGP_IPV4M_NODE, &no_neighbor_set_peer_group_hidden_cmd);
12581 install_element(BGP_IPV6_NODE, &no_neighbor_set_peer_group_hidden_cmd);
12582 install_element(BGP_IPV6M_NODE, &no_neighbor_set_peer_group_hidden_cmd);
12583 install_element(BGP_IPV6L_NODE, &no_neighbor_set_peer_group_hidden_cmd);
12584 install_element(BGP_VPNV4_NODE, &no_neighbor_set_peer_group_hidden_cmd);
12585 install_element(BGP_VPNV6_NODE, &no_neighbor_set_peer_group_hidden_cmd);
12586 install_element(BGP_FLOWSPECV4_NODE,
12587 &no_neighbor_set_peer_group_hidden_cmd);
12588 install_element(BGP_FLOWSPECV6_NODE,
12589 &no_neighbor_set_peer_group_hidden_cmd);
12590
12591 /* "neighbor softreconfiguration inbound" commands.*/
12592 install_element(BGP_NODE, &neighbor_soft_reconfiguration_hidden_cmd);
12593 install_element(BGP_NODE, &no_neighbor_soft_reconfiguration_hidden_cmd);
12594 install_element(BGP_IPV4_NODE, &neighbor_soft_reconfiguration_cmd);
12595 install_element(BGP_IPV4_NODE, &no_neighbor_soft_reconfiguration_cmd);
12596 install_element(BGP_IPV4L_NODE, &neighbor_soft_reconfiguration_cmd);
12597 install_element(BGP_IPV4L_NODE, &no_neighbor_soft_reconfiguration_cmd);
12598 install_element(BGP_IPV4M_NODE, &neighbor_soft_reconfiguration_cmd);
12599 install_element(BGP_IPV4M_NODE, &no_neighbor_soft_reconfiguration_cmd);
12600 install_element(BGP_IPV6_NODE, &neighbor_soft_reconfiguration_cmd);
12601 install_element(BGP_IPV6_NODE, &no_neighbor_soft_reconfiguration_cmd);
12602 install_element(BGP_IPV6M_NODE, &neighbor_soft_reconfiguration_cmd);
12603 install_element(BGP_IPV6M_NODE, &no_neighbor_soft_reconfiguration_cmd);
12604 install_element(BGP_IPV6L_NODE, &neighbor_soft_reconfiguration_cmd);
12605 install_element(BGP_IPV6L_NODE, &no_neighbor_soft_reconfiguration_cmd);
12606 install_element(BGP_VPNV4_NODE, &neighbor_soft_reconfiguration_cmd);
12607 install_element(BGP_VPNV4_NODE, &no_neighbor_soft_reconfiguration_cmd);
12608 install_element(BGP_VPNV6_NODE, &neighbor_soft_reconfiguration_cmd);
12609 install_element(BGP_VPNV6_NODE, &no_neighbor_soft_reconfiguration_cmd);
12610 install_element(BGP_FLOWSPECV4_NODE,
12611 &neighbor_soft_reconfiguration_cmd);
12612 install_element(BGP_FLOWSPECV4_NODE,
12613 &no_neighbor_soft_reconfiguration_cmd);
12614 install_element(BGP_FLOWSPECV6_NODE,
12615 &neighbor_soft_reconfiguration_cmd);
12616 install_element(BGP_FLOWSPECV6_NODE,
12617 &no_neighbor_soft_reconfiguration_cmd);
12618
12619 /* "neighbor attribute-unchanged" commands. */
12620 install_element(BGP_NODE, &neighbor_attr_unchanged_hidden_cmd);
12621 install_element(BGP_NODE, &no_neighbor_attr_unchanged_hidden_cmd);
12622 install_element(BGP_IPV4_NODE, &neighbor_attr_unchanged_cmd);
12623 install_element(BGP_IPV4_NODE, &no_neighbor_attr_unchanged_cmd);
12624 install_element(BGP_IPV4M_NODE, &neighbor_attr_unchanged_cmd);
12625 install_element(BGP_IPV4M_NODE, &no_neighbor_attr_unchanged_cmd);
12626 install_element(BGP_IPV4L_NODE, &neighbor_attr_unchanged_cmd);
12627 install_element(BGP_IPV4L_NODE, &no_neighbor_attr_unchanged_cmd);
12628 install_element(BGP_IPV6_NODE, &neighbor_attr_unchanged_cmd);
12629 install_element(BGP_IPV6_NODE, &no_neighbor_attr_unchanged_cmd);
12630 install_element(BGP_IPV6M_NODE, &neighbor_attr_unchanged_cmd);
12631 install_element(BGP_IPV6M_NODE, &no_neighbor_attr_unchanged_cmd);
12632 install_element(BGP_IPV6L_NODE, &neighbor_attr_unchanged_cmd);
12633 install_element(BGP_IPV6L_NODE, &no_neighbor_attr_unchanged_cmd);
12634 install_element(BGP_VPNV4_NODE, &neighbor_attr_unchanged_cmd);
12635 install_element(BGP_VPNV4_NODE, &no_neighbor_attr_unchanged_cmd);
12636 install_element(BGP_VPNV6_NODE, &neighbor_attr_unchanged_cmd);
12637 install_element(BGP_VPNV6_NODE, &no_neighbor_attr_unchanged_cmd);
12638
12639 install_element(BGP_EVPN_NODE, &neighbor_attr_unchanged_cmd);
12640 install_element(BGP_EVPN_NODE, &no_neighbor_attr_unchanged_cmd);
12641
12642 /* "nexthop-local unchanged" commands */
12643 install_element(BGP_IPV6_NODE, &neighbor_nexthop_local_unchanged_cmd);
12644 install_element(BGP_IPV6_NODE,
12645 &no_neighbor_nexthop_local_unchanged_cmd);
12646
12647 /* "neighbor next-hop-self" commands. */
12648 install_element(BGP_NODE, &neighbor_nexthop_self_hidden_cmd);
12649 install_element(BGP_NODE, &no_neighbor_nexthop_self_hidden_cmd);
12650 install_element(BGP_IPV4_NODE, &neighbor_nexthop_self_cmd);
12651 install_element(BGP_IPV4_NODE, &no_neighbor_nexthop_self_cmd);
12652 install_element(BGP_IPV4M_NODE, &neighbor_nexthop_self_cmd);
12653 install_element(BGP_IPV4M_NODE, &no_neighbor_nexthop_self_cmd);
12654 install_element(BGP_IPV4L_NODE, &neighbor_nexthop_self_cmd);
12655 install_element(BGP_IPV4L_NODE, &no_neighbor_nexthop_self_cmd);
12656 install_element(BGP_IPV6_NODE, &neighbor_nexthop_self_cmd);
12657 install_element(BGP_IPV6_NODE, &no_neighbor_nexthop_self_cmd);
12658 install_element(BGP_IPV6M_NODE, &neighbor_nexthop_self_cmd);
12659 install_element(BGP_IPV6M_NODE, &no_neighbor_nexthop_self_cmd);
12660 install_element(BGP_IPV6L_NODE, &neighbor_nexthop_self_cmd);
12661 install_element(BGP_IPV6L_NODE, &no_neighbor_nexthop_self_cmd);
12662 install_element(BGP_VPNV4_NODE, &neighbor_nexthop_self_cmd);
12663 install_element(BGP_VPNV4_NODE, &no_neighbor_nexthop_self_cmd);
12664 install_element(BGP_VPNV6_NODE, &neighbor_nexthop_self_cmd);
12665 install_element(BGP_VPNV6_NODE, &no_neighbor_nexthop_self_cmd);
12666 install_element(BGP_EVPN_NODE, &neighbor_nexthop_self_cmd);
12667 install_element(BGP_EVPN_NODE, &no_neighbor_nexthop_self_cmd);
12668
12669 /* "neighbor next-hop-self force" commands. */
12670 install_element(BGP_NODE, &neighbor_nexthop_self_force_hidden_cmd);
12671 install_element(BGP_NODE, &no_neighbor_nexthop_self_force_hidden_cmd);
12672 install_element(BGP_IPV4_NODE, &neighbor_nexthop_self_force_cmd);
12673 install_element(BGP_IPV4_NODE, &no_neighbor_nexthop_self_force_cmd);
12674 install_element(BGP_IPV4M_NODE, &neighbor_nexthop_self_force_cmd);
12675 install_element(BGP_IPV4M_NODE, &no_neighbor_nexthop_self_force_cmd);
12676 install_element(BGP_IPV4L_NODE, &neighbor_nexthop_self_force_cmd);
12677 install_element(BGP_IPV4L_NODE, &no_neighbor_nexthop_self_force_cmd);
12678 install_element(BGP_IPV6_NODE, &neighbor_nexthop_self_force_cmd);
12679 install_element(BGP_IPV6_NODE, &no_neighbor_nexthop_self_force_cmd);
12680 install_element(BGP_IPV6M_NODE, &neighbor_nexthop_self_force_cmd);
12681 install_element(BGP_IPV6M_NODE, &no_neighbor_nexthop_self_force_cmd);
12682 install_element(BGP_IPV6L_NODE, &neighbor_nexthop_self_force_cmd);
12683 install_element(BGP_IPV6L_NODE, &no_neighbor_nexthop_self_force_cmd);
12684 install_element(BGP_VPNV4_NODE, &neighbor_nexthop_self_force_cmd);
12685 install_element(BGP_VPNV4_NODE, &no_neighbor_nexthop_self_force_cmd);
12686 install_element(BGP_VPNV6_NODE, &neighbor_nexthop_self_force_cmd);
12687 install_element(BGP_VPNV6_NODE, &no_neighbor_nexthop_self_force_cmd);
12688
12689 /* "neighbor as-override" commands. */
12690 install_element(BGP_NODE, &neighbor_as_override_hidden_cmd);
12691 install_element(BGP_NODE, &no_neighbor_as_override_hidden_cmd);
12692 install_element(BGP_IPV4_NODE, &neighbor_as_override_cmd);
12693 install_element(BGP_IPV4_NODE, &no_neighbor_as_override_cmd);
12694 install_element(BGP_IPV4M_NODE, &neighbor_as_override_cmd);
12695 install_element(BGP_IPV4M_NODE, &no_neighbor_as_override_cmd);
12696 install_element(BGP_IPV4L_NODE, &neighbor_as_override_cmd);
12697 install_element(BGP_IPV4L_NODE, &no_neighbor_as_override_cmd);
12698 install_element(BGP_IPV6_NODE, &neighbor_as_override_cmd);
12699 install_element(BGP_IPV6_NODE, &no_neighbor_as_override_cmd);
12700 install_element(BGP_IPV6M_NODE, &neighbor_as_override_cmd);
12701 install_element(BGP_IPV6M_NODE, &no_neighbor_as_override_cmd);
12702 install_element(BGP_IPV6L_NODE, &neighbor_as_override_cmd);
12703 install_element(BGP_IPV6L_NODE, &no_neighbor_as_override_cmd);
12704 install_element(BGP_VPNV4_NODE, &neighbor_as_override_cmd);
12705 install_element(BGP_VPNV4_NODE, &no_neighbor_as_override_cmd);
12706 install_element(BGP_VPNV6_NODE, &neighbor_as_override_cmd);
12707 install_element(BGP_VPNV6_NODE, &no_neighbor_as_override_cmd);
12708
12709 /* "neighbor remove-private-AS" commands. */
12710 install_element(BGP_NODE, &neighbor_remove_private_as_hidden_cmd);
12711 install_element(BGP_NODE, &no_neighbor_remove_private_as_hidden_cmd);
12712 install_element(BGP_NODE, &neighbor_remove_private_as_all_hidden_cmd);
12713 install_element(BGP_NODE,
12714 &no_neighbor_remove_private_as_all_hidden_cmd);
12715 install_element(BGP_NODE,
12716 &neighbor_remove_private_as_replace_as_hidden_cmd);
12717 install_element(BGP_NODE,
12718 &no_neighbor_remove_private_as_replace_as_hidden_cmd);
12719 install_element(BGP_NODE,
12720 &neighbor_remove_private_as_all_replace_as_hidden_cmd);
12721 install_element(
12722 BGP_NODE,
12723 &no_neighbor_remove_private_as_all_replace_as_hidden_cmd);
12724 install_element(BGP_IPV4_NODE, &neighbor_remove_private_as_cmd);
12725 install_element(BGP_IPV4_NODE, &no_neighbor_remove_private_as_cmd);
12726 install_element(BGP_IPV4_NODE, &neighbor_remove_private_as_all_cmd);
12727 install_element(BGP_IPV4_NODE, &no_neighbor_remove_private_as_all_cmd);
12728 install_element(BGP_IPV4_NODE,
12729 &neighbor_remove_private_as_replace_as_cmd);
12730 install_element(BGP_IPV4_NODE,
12731 &no_neighbor_remove_private_as_replace_as_cmd);
12732 install_element(BGP_IPV4_NODE,
12733 &neighbor_remove_private_as_all_replace_as_cmd);
12734 install_element(BGP_IPV4_NODE,
12735 &no_neighbor_remove_private_as_all_replace_as_cmd);
12736 install_element(BGP_IPV4M_NODE, &neighbor_remove_private_as_cmd);
12737 install_element(BGP_IPV4M_NODE, &no_neighbor_remove_private_as_cmd);
12738 install_element(BGP_IPV4M_NODE, &neighbor_remove_private_as_all_cmd);
12739 install_element(BGP_IPV4M_NODE, &no_neighbor_remove_private_as_all_cmd);
12740 install_element(BGP_IPV4M_NODE,
12741 &neighbor_remove_private_as_replace_as_cmd);
12742 install_element(BGP_IPV4M_NODE,
12743 &no_neighbor_remove_private_as_replace_as_cmd);
12744 install_element(BGP_IPV4M_NODE,
12745 &neighbor_remove_private_as_all_replace_as_cmd);
12746 install_element(BGP_IPV4M_NODE,
12747 &no_neighbor_remove_private_as_all_replace_as_cmd);
12748 install_element(BGP_IPV4L_NODE, &neighbor_remove_private_as_cmd);
12749 install_element(BGP_IPV4L_NODE, &no_neighbor_remove_private_as_cmd);
12750 install_element(BGP_IPV4L_NODE, &neighbor_remove_private_as_all_cmd);
12751 install_element(BGP_IPV4L_NODE, &no_neighbor_remove_private_as_all_cmd);
12752 install_element(BGP_IPV4L_NODE,
12753 &neighbor_remove_private_as_replace_as_cmd);
12754 install_element(BGP_IPV4L_NODE,
12755 &no_neighbor_remove_private_as_replace_as_cmd);
12756 install_element(BGP_IPV4L_NODE,
12757 &neighbor_remove_private_as_all_replace_as_cmd);
12758 install_element(BGP_IPV4L_NODE,
12759 &no_neighbor_remove_private_as_all_replace_as_cmd);
12760 install_element(BGP_IPV6_NODE, &neighbor_remove_private_as_cmd);
12761 install_element(BGP_IPV6_NODE, &no_neighbor_remove_private_as_cmd);
12762 install_element(BGP_IPV6_NODE, &neighbor_remove_private_as_all_cmd);
12763 install_element(BGP_IPV6_NODE, &no_neighbor_remove_private_as_all_cmd);
12764 install_element(BGP_IPV6_NODE,
12765 &neighbor_remove_private_as_replace_as_cmd);
12766 install_element(BGP_IPV6_NODE,
12767 &no_neighbor_remove_private_as_replace_as_cmd);
12768 install_element(BGP_IPV6_NODE,
12769 &neighbor_remove_private_as_all_replace_as_cmd);
12770 install_element(BGP_IPV6_NODE,
12771 &no_neighbor_remove_private_as_all_replace_as_cmd);
12772 install_element(BGP_IPV6M_NODE, &neighbor_remove_private_as_cmd);
12773 install_element(BGP_IPV6M_NODE, &no_neighbor_remove_private_as_cmd);
12774 install_element(BGP_IPV6M_NODE, &neighbor_remove_private_as_all_cmd);
12775 install_element(BGP_IPV6M_NODE, &no_neighbor_remove_private_as_all_cmd);
12776 install_element(BGP_IPV6M_NODE,
12777 &neighbor_remove_private_as_replace_as_cmd);
12778 install_element(BGP_IPV6M_NODE,
12779 &no_neighbor_remove_private_as_replace_as_cmd);
12780 install_element(BGP_IPV6M_NODE,
12781 &neighbor_remove_private_as_all_replace_as_cmd);
12782 install_element(BGP_IPV6M_NODE,
12783 &no_neighbor_remove_private_as_all_replace_as_cmd);
12784 install_element(BGP_IPV6L_NODE, &neighbor_remove_private_as_cmd);
12785 install_element(BGP_IPV6L_NODE, &no_neighbor_remove_private_as_cmd);
12786 install_element(BGP_IPV6L_NODE, &neighbor_remove_private_as_all_cmd);
12787 install_element(BGP_IPV6L_NODE, &no_neighbor_remove_private_as_all_cmd);
12788 install_element(BGP_IPV6L_NODE,
12789 &neighbor_remove_private_as_replace_as_cmd);
12790 install_element(BGP_IPV6L_NODE,
12791 &no_neighbor_remove_private_as_replace_as_cmd);
12792 install_element(BGP_IPV6L_NODE,
12793 &neighbor_remove_private_as_all_replace_as_cmd);
12794 install_element(BGP_IPV6L_NODE,
12795 &no_neighbor_remove_private_as_all_replace_as_cmd);
12796 install_element(BGP_VPNV4_NODE, &neighbor_remove_private_as_cmd);
12797 install_element(BGP_VPNV4_NODE, &no_neighbor_remove_private_as_cmd);
12798 install_element(BGP_VPNV4_NODE, &neighbor_remove_private_as_all_cmd);
12799 install_element(BGP_VPNV4_NODE, &no_neighbor_remove_private_as_all_cmd);
12800 install_element(BGP_VPNV4_NODE,
12801 &neighbor_remove_private_as_replace_as_cmd);
12802 install_element(BGP_VPNV4_NODE,
12803 &no_neighbor_remove_private_as_replace_as_cmd);
12804 install_element(BGP_VPNV4_NODE,
12805 &neighbor_remove_private_as_all_replace_as_cmd);
12806 install_element(BGP_VPNV4_NODE,
12807 &no_neighbor_remove_private_as_all_replace_as_cmd);
12808 install_element(BGP_VPNV6_NODE, &neighbor_remove_private_as_cmd);
12809 install_element(BGP_VPNV6_NODE, &no_neighbor_remove_private_as_cmd);
12810 install_element(BGP_VPNV6_NODE, &neighbor_remove_private_as_all_cmd);
12811 install_element(BGP_VPNV6_NODE, &no_neighbor_remove_private_as_all_cmd);
12812 install_element(BGP_VPNV6_NODE,
12813 &neighbor_remove_private_as_replace_as_cmd);
12814 install_element(BGP_VPNV6_NODE,
12815 &no_neighbor_remove_private_as_replace_as_cmd);
12816 install_element(BGP_VPNV6_NODE,
12817 &neighbor_remove_private_as_all_replace_as_cmd);
12818 install_element(BGP_VPNV6_NODE,
12819 &no_neighbor_remove_private_as_all_replace_as_cmd);
12820
12821 /* "neighbor send-community" commands.*/
12822 install_element(BGP_NODE, &neighbor_send_community_hidden_cmd);
12823 install_element(BGP_NODE, &neighbor_send_community_type_hidden_cmd);
12824 install_element(BGP_NODE, &no_neighbor_send_community_hidden_cmd);
12825 install_element(BGP_NODE, &no_neighbor_send_community_type_hidden_cmd);
12826 install_element(BGP_IPV4_NODE, &neighbor_send_community_cmd);
12827 install_element(BGP_IPV4_NODE, &neighbor_send_community_type_cmd);
12828 install_element(BGP_IPV4_NODE, &no_neighbor_send_community_cmd);
12829 install_element(BGP_IPV4_NODE, &no_neighbor_send_community_type_cmd);
12830 install_element(BGP_IPV4M_NODE, &neighbor_send_community_cmd);
12831 install_element(BGP_IPV4M_NODE, &neighbor_send_community_type_cmd);
12832 install_element(BGP_IPV4M_NODE, &no_neighbor_send_community_cmd);
12833 install_element(BGP_IPV4M_NODE, &no_neighbor_send_community_type_cmd);
12834 install_element(BGP_IPV4L_NODE, &neighbor_send_community_cmd);
12835 install_element(BGP_IPV4L_NODE, &neighbor_send_community_type_cmd);
12836 install_element(BGP_IPV4L_NODE, &no_neighbor_send_community_cmd);
12837 install_element(BGP_IPV4L_NODE, &no_neighbor_send_community_type_cmd);
12838 install_element(BGP_IPV6_NODE, &neighbor_send_community_cmd);
12839 install_element(BGP_IPV6_NODE, &neighbor_send_community_type_cmd);
12840 install_element(BGP_IPV6_NODE, &no_neighbor_send_community_cmd);
12841 install_element(BGP_IPV6_NODE, &no_neighbor_send_community_type_cmd);
12842 install_element(BGP_IPV6M_NODE, &neighbor_send_community_cmd);
12843 install_element(BGP_IPV6M_NODE, &neighbor_send_community_type_cmd);
12844 install_element(BGP_IPV6M_NODE, &no_neighbor_send_community_cmd);
12845 install_element(BGP_IPV6M_NODE, &no_neighbor_send_community_type_cmd);
12846 install_element(BGP_IPV6L_NODE, &neighbor_send_community_cmd);
12847 install_element(BGP_IPV6L_NODE, &neighbor_send_community_type_cmd);
12848 install_element(BGP_IPV6L_NODE, &no_neighbor_send_community_cmd);
12849 install_element(BGP_IPV6L_NODE, &no_neighbor_send_community_type_cmd);
12850 install_element(BGP_VPNV4_NODE, &neighbor_send_community_cmd);
12851 install_element(BGP_VPNV4_NODE, &neighbor_send_community_type_cmd);
12852 install_element(BGP_VPNV4_NODE, &no_neighbor_send_community_cmd);
12853 install_element(BGP_VPNV4_NODE, &no_neighbor_send_community_type_cmd);
12854 install_element(BGP_VPNV6_NODE, &neighbor_send_community_cmd);
12855 install_element(BGP_VPNV6_NODE, &neighbor_send_community_type_cmd);
12856 install_element(BGP_VPNV6_NODE, &no_neighbor_send_community_cmd);
12857 install_element(BGP_VPNV6_NODE, &no_neighbor_send_community_type_cmd);
12858
12859 /* "neighbor route-reflector" commands.*/
12860 install_element(BGP_NODE, &neighbor_route_reflector_client_hidden_cmd);
12861 install_element(BGP_NODE,
12862 &no_neighbor_route_reflector_client_hidden_cmd);
12863 install_element(BGP_IPV4_NODE, &neighbor_route_reflector_client_cmd);
12864 install_element(BGP_IPV4_NODE, &no_neighbor_route_reflector_client_cmd);
12865 install_element(BGP_IPV4M_NODE, &neighbor_route_reflector_client_cmd);
12866 install_element(BGP_IPV4M_NODE,
12867 &no_neighbor_route_reflector_client_cmd);
12868 install_element(BGP_IPV4L_NODE, &neighbor_route_reflector_client_cmd);
12869 install_element(BGP_IPV4L_NODE,
12870 &no_neighbor_route_reflector_client_cmd);
12871 install_element(BGP_IPV6_NODE, &neighbor_route_reflector_client_cmd);
12872 install_element(BGP_IPV6_NODE, &no_neighbor_route_reflector_client_cmd);
12873 install_element(BGP_IPV6M_NODE, &neighbor_route_reflector_client_cmd);
12874 install_element(BGP_IPV6M_NODE,
12875 &no_neighbor_route_reflector_client_cmd);
12876 install_element(BGP_IPV6L_NODE, &neighbor_route_reflector_client_cmd);
12877 install_element(BGP_IPV6L_NODE,
12878 &no_neighbor_route_reflector_client_cmd);
12879 install_element(BGP_VPNV4_NODE, &neighbor_route_reflector_client_cmd);
12880 install_element(BGP_VPNV4_NODE,
12881 &no_neighbor_route_reflector_client_cmd);
12882 install_element(BGP_VPNV6_NODE, &neighbor_route_reflector_client_cmd);
12883 install_element(BGP_VPNV6_NODE,
12884 &no_neighbor_route_reflector_client_cmd);
12885 install_element(BGP_FLOWSPECV4_NODE,
12886 &neighbor_route_reflector_client_cmd);
12887 install_element(BGP_FLOWSPECV4_NODE,
12888 &no_neighbor_route_reflector_client_cmd);
12889 install_element(BGP_FLOWSPECV6_NODE,
12890 &neighbor_route_reflector_client_cmd);
12891 install_element(BGP_FLOWSPECV6_NODE,
12892 &no_neighbor_route_reflector_client_cmd);
12893 install_element(BGP_EVPN_NODE, &neighbor_route_reflector_client_cmd);
12894 install_element(BGP_EVPN_NODE, &no_neighbor_route_reflector_client_cmd);
12895
12896 /* "neighbor route-server" commands.*/
12897 install_element(BGP_NODE, &neighbor_route_server_client_hidden_cmd);
12898 install_element(BGP_NODE, &no_neighbor_route_server_client_hidden_cmd);
12899 install_element(BGP_IPV4_NODE, &neighbor_route_server_client_cmd);
12900 install_element(BGP_IPV4_NODE, &no_neighbor_route_server_client_cmd);
12901 install_element(BGP_IPV4M_NODE, &neighbor_route_server_client_cmd);
12902 install_element(BGP_IPV4M_NODE, &no_neighbor_route_server_client_cmd);
12903 install_element(BGP_IPV4L_NODE, &neighbor_route_server_client_cmd);
12904 install_element(BGP_IPV4L_NODE, &no_neighbor_route_server_client_cmd);
12905 install_element(BGP_IPV6_NODE, &neighbor_route_server_client_cmd);
12906 install_element(BGP_IPV6_NODE, &no_neighbor_route_server_client_cmd);
12907 install_element(BGP_IPV6M_NODE, &neighbor_route_server_client_cmd);
12908 install_element(BGP_IPV6M_NODE, &no_neighbor_route_server_client_cmd);
12909 install_element(BGP_IPV6L_NODE, &neighbor_route_server_client_cmd);
12910 install_element(BGP_IPV6L_NODE, &no_neighbor_route_server_client_cmd);
12911 install_element(BGP_VPNV4_NODE, &neighbor_route_server_client_cmd);
12912 install_element(BGP_VPNV4_NODE, &no_neighbor_route_server_client_cmd);
12913 install_element(BGP_VPNV6_NODE, &neighbor_route_server_client_cmd);
12914 install_element(BGP_VPNV6_NODE, &no_neighbor_route_server_client_cmd);
12915 install_element(BGP_FLOWSPECV4_NODE, &neighbor_route_server_client_cmd);
12916 install_element(BGP_FLOWSPECV4_NODE,
12917 &no_neighbor_route_server_client_cmd);
12918 install_element(BGP_FLOWSPECV6_NODE, &neighbor_route_server_client_cmd);
12919 install_element(BGP_FLOWSPECV6_NODE,
12920 &no_neighbor_route_server_client_cmd);
12921
12922 /* "neighbor addpath-tx-all-paths" commands.*/
12923 install_element(BGP_NODE, &neighbor_addpath_tx_all_paths_hidden_cmd);
12924 install_element(BGP_NODE, &no_neighbor_addpath_tx_all_paths_hidden_cmd);
12925 install_element(BGP_IPV4_NODE, &neighbor_addpath_tx_all_paths_cmd);
12926 install_element(BGP_IPV4_NODE, &no_neighbor_addpath_tx_all_paths_cmd);
12927 install_element(BGP_IPV4M_NODE, &neighbor_addpath_tx_all_paths_cmd);
12928 install_element(BGP_IPV4M_NODE, &no_neighbor_addpath_tx_all_paths_cmd);
12929 install_element(BGP_IPV4L_NODE, &neighbor_addpath_tx_all_paths_cmd);
12930 install_element(BGP_IPV4L_NODE, &no_neighbor_addpath_tx_all_paths_cmd);
12931 install_element(BGP_IPV6_NODE, &neighbor_addpath_tx_all_paths_cmd);
12932 install_element(BGP_IPV6_NODE, &no_neighbor_addpath_tx_all_paths_cmd);
12933 install_element(BGP_IPV6M_NODE, &neighbor_addpath_tx_all_paths_cmd);
12934 install_element(BGP_IPV6M_NODE, &no_neighbor_addpath_tx_all_paths_cmd);
12935 install_element(BGP_IPV6L_NODE, &neighbor_addpath_tx_all_paths_cmd);
12936 install_element(BGP_IPV6L_NODE, &no_neighbor_addpath_tx_all_paths_cmd);
12937 install_element(BGP_VPNV4_NODE, &neighbor_addpath_tx_all_paths_cmd);
12938 install_element(BGP_VPNV4_NODE, &no_neighbor_addpath_tx_all_paths_cmd);
12939 install_element(BGP_VPNV6_NODE, &neighbor_addpath_tx_all_paths_cmd);
12940 install_element(BGP_VPNV6_NODE, &no_neighbor_addpath_tx_all_paths_cmd);
12941
12942 /* "neighbor addpath-tx-bestpath-per-AS" commands.*/
12943 install_element(BGP_NODE,
12944 &neighbor_addpath_tx_bestpath_per_as_hidden_cmd);
12945 install_element(BGP_NODE,
12946 &no_neighbor_addpath_tx_bestpath_per_as_hidden_cmd);
12947 install_element(BGP_IPV4_NODE,
12948 &neighbor_addpath_tx_bestpath_per_as_cmd);
12949 install_element(BGP_IPV4_NODE,
12950 &no_neighbor_addpath_tx_bestpath_per_as_cmd);
12951 install_element(BGP_IPV4M_NODE,
12952 &neighbor_addpath_tx_bestpath_per_as_cmd);
12953 install_element(BGP_IPV4M_NODE,
12954 &no_neighbor_addpath_tx_bestpath_per_as_cmd);
12955 install_element(BGP_IPV4L_NODE,
12956 &neighbor_addpath_tx_bestpath_per_as_cmd);
12957 install_element(BGP_IPV4L_NODE,
12958 &no_neighbor_addpath_tx_bestpath_per_as_cmd);
12959 install_element(BGP_IPV6_NODE,
12960 &neighbor_addpath_tx_bestpath_per_as_cmd);
12961 install_element(BGP_IPV6_NODE,
12962 &no_neighbor_addpath_tx_bestpath_per_as_cmd);
12963 install_element(BGP_IPV6M_NODE,
12964 &neighbor_addpath_tx_bestpath_per_as_cmd);
12965 install_element(BGP_IPV6M_NODE,
12966 &no_neighbor_addpath_tx_bestpath_per_as_cmd);
12967 install_element(BGP_IPV6L_NODE,
12968 &neighbor_addpath_tx_bestpath_per_as_cmd);
12969 install_element(BGP_IPV6L_NODE,
12970 &no_neighbor_addpath_tx_bestpath_per_as_cmd);
12971 install_element(BGP_VPNV4_NODE,
12972 &neighbor_addpath_tx_bestpath_per_as_cmd);
12973 install_element(BGP_VPNV4_NODE,
12974 &no_neighbor_addpath_tx_bestpath_per_as_cmd);
12975 install_element(BGP_VPNV6_NODE,
12976 &neighbor_addpath_tx_bestpath_per_as_cmd);
12977 install_element(BGP_VPNV6_NODE,
12978 &no_neighbor_addpath_tx_bestpath_per_as_cmd);
12979
12980 /* "neighbor passive" commands. */
12981 install_element(BGP_NODE, &neighbor_passive_cmd);
12982 install_element(BGP_NODE, &no_neighbor_passive_cmd);
12983
12984
12985 /* "neighbor shutdown" commands. */
12986 install_element(BGP_NODE, &neighbor_shutdown_cmd);
12987 install_element(BGP_NODE, &no_neighbor_shutdown_cmd);
12988 install_element(BGP_NODE, &neighbor_shutdown_msg_cmd);
12989 install_element(BGP_NODE, &no_neighbor_shutdown_msg_cmd);
12990
12991 /* "neighbor capability extended-nexthop" commands.*/
12992 install_element(BGP_NODE, &neighbor_capability_enhe_cmd);
12993 install_element(BGP_NODE, &no_neighbor_capability_enhe_cmd);
12994
12995 /* "neighbor capability orf prefix-list" commands.*/
12996 install_element(BGP_NODE, &neighbor_capability_orf_prefix_hidden_cmd);
12997 install_element(BGP_NODE,
12998 &no_neighbor_capability_orf_prefix_hidden_cmd);
12999 install_element(BGP_IPV4_NODE, &neighbor_capability_orf_prefix_cmd);
13000 install_element(BGP_IPV4_NODE, &no_neighbor_capability_orf_prefix_cmd);
13001 install_element(BGP_IPV4M_NODE, &neighbor_capability_orf_prefix_cmd);
13002 install_element(BGP_IPV4M_NODE, &no_neighbor_capability_orf_prefix_cmd);
13003 install_element(BGP_IPV4L_NODE, &neighbor_capability_orf_prefix_cmd);
13004 install_element(BGP_IPV4L_NODE, &no_neighbor_capability_orf_prefix_cmd);
13005 install_element(BGP_IPV6_NODE, &neighbor_capability_orf_prefix_cmd);
13006 install_element(BGP_IPV6_NODE, &no_neighbor_capability_orf_prefix_cmd);
13007 install_element(BGP_IPV6M_NODE, &neighbor_capability_orf_prefix_cmd);
13008 install_element(BGP_IPV6M_NODE, &no_neighbor_capability_orf_prefix_cmd);
13009 install_element(BGP_IPV6L_NODE, &neighbor_capability_orf_prefix_cmd);
13010 install_element(BGP_IPV6L_NODE, &no_neighbor_capability_orf_prefix_cmd);
13011
13012 /* "neighbor capability dynamic" commands.*/
13013 install_element(BGP_NODE, &neighbor_capability_dynamic_cmd);
13014 install_element(BGP_NODE, &no_neighbor_capability_dynamic_cmd);
13015
13016 /* "neighbor dont-capability-negotiate" commands. */
13017 install_element(BGP_NODE, &neighbor_dont_capability_negotiate_cmd);
13018 install_element(BGP_NODE, &no_neighbor_dont_capability_negotiate_cmd);
13019
13020 /* "neighbor ebgp-multihop" commands. */
13021 install_element(BGP_NODE, &neighbor_ebgp_multihop_cmd);
13022 install_element(BGP_NODE, &neighbor_ebgp_multihop_ttl_cmd);
13023 install_element(BGP_NODE, &no_neighbor_ebgp_multihop_cmd);
13024
13025 /* "neighbor disable-connected-check" commands. */
13026 install_element(BGP_NODE, &neighbor_disable_connected_check_cmd);
13027 install_element(BGP_NODE, &no_neighbor_disable_connected_check_cmd);
13028
13029 /* "neighbor enforce-first-as" commands. */
13030 install_element(BGP_NODE, &neighbor_enforce_first_as_cmd);
13031 install_element(BGP_NODE, &no_neighbor_enforce_first_as_cmd);
13032
13033 /* "neighbor description" commands. */
13034 install_element(BGP_NODE, &neighbor_description_cmd);
13035 install_element(BGP_NODE, &no_neighbor_description_cmd);
13036 install_element(BGP_NODE, &no_neighbor_description_comment_cmd);
13037
13038 /* "neighbor update-source" commands. "*/
13039 install_element(BGP_NODE, &neighbor_update_source_cmd);
13040 install_element(BGP_NODE, &no_neighbor_update_source_cmd);
13041
13042 /* "neighbor default-originate" commands. */
13043 install_element(BGP_NODE, &neighbor_default_originate_hidden_cmd);
13044 install_element(BGP_NODE, &neighbor_default_originate_rmap_hidden_cmd);
13045 install_element(BGP_NODE, &no_neighbor_default_originate_hidden_cmd);
13046 install_element(BGP_IPV4_NODE, &neighbor_default_originate_cmd);
13047 install_element(BGP_IPV4_NODE, &neighbor_default_originate_rmap_cmd);
13048 install_element(BGP_IPV4_NODE, &no_neighbor_default_originate_cmd);
13049 install_element(BGP_IPV4M_NODE, &neighbor_default_originate_cmd);
13050 install_element(BGP_IPV4M_NODE, &neighbor_default_originate_rmap_cmd);
13051 install_element(BGP_IPV4M_NODE, &no_neighbor_default_originate_cmd);
13052 install_element(BGP_IPV4L_NODE, &neighbor_default_originate_cmd);
13053 install_element(BGP_IPV4L_NODE, &neighbor_default_originate_rmap_cmd);
13054 install_element(BGP_IPV4L_NODE, &no_neighbor_default_originate_cmd);
13055 install_element(BGP_IPV6_NODE, &neighbor_default_originate_cmd);
13056 install_element(BGP_IPV6_NODE, &neighbor_default_originate_rmap_cmd);
13057 install_element(BGP_IPV6_NODE, &no_neighbor_default_originate_cmd);
13058 install_element(BGP_IPV6M_NODE, &neighbor_default_originate_cmd);
13059 install_element(BGP_IPV6M_NODE, &neighbor_default_originate_rmap_cmd);
13060 install_element(BGP_IPV6M_NODE, &no_neighbor_default_originate_cmd);
13061 install_element(BGP_IPV6L_NODE, &neighbor_default_originate_cmd);
13062 install_element(BGP_IPV6L_NODE, &neighbor_default_originate_rmap_cmd);
13063 install_element(BGP_IPV6L_NODE, &no_neighbor_default_originate_cmd);
13064
13065 /* "neighbor port" commands. */
13066 install_element(BGP_NODE, &neighbor_port_cmd);
13067 install_element(BGP_NODE, &no_neighbor_port_cmd);
13068
13069 /* "neighbor weight" commands. */
13070 install_element(BGP_NODE, &neighbor_weight_hidden_cmd);
13071 install_element(BGP_NODE, &no_neighbor_weight_hidden_cmd);
13072
13073 install_element(BGP_IPV4_NODE, &neighbor_weight_cmd);
13074 install_element(BGP_IPV4_NODE, &no_neighbor_weight_cmd);
13075 install_element(BGP_IPV4M_NODE, &neighbor_weight_cmd);
13076 install_element(BGP_IPV4M_NODE, &no_neighbor_weight_cmd);
13077 install_element(BGP_IPV4L_NODE, &neighbor_weight_cmd);
13078 install_element(BGP_IPV4L_NODE, &no_neighbor_weight_cmd);
13079 install_element(BGP_IPV6_NODE, &neighbor_weight_cmd);
13080 install_element(BGP_IPV6_NODE, &no_neighbor_weight_cmd);
13081 install_element(BGP_IPV6M_NODE, &neighbor_weight_cmd);
13082 install_element(BGP_IPV6M_NODE, &no_neighbor_weight_cmd);
13083 install_element(BGP_IPV6L_NODE, &neighbor_weight_cmd);
13084 install_element(BGP_IPV6L_NODE, &no_neighbor_weight_cmd);
13085 install_element(BGP_VPNV4_NODE, &neighbor_weight_cmd);
13086 install_element(BGP_VPNV4_NODE, &no_neighbor_weight_cmd);
13087 install_element(BGP_VPNV6_NODE, &neighbor_weight_cmd);
13088 install_element(BGP_VPNV6_NODE, &no_neighbor_weight_cmd);
13089
13090 /* "neighbor override-capability" commands. */
13091 install_element(BGP_NODE, &neighbor_override_capability_cmd);
13092 install_element(BGP_NODE, &no_neighbor_override_capability_cmd);
13093
13094 /* "neighbor strict-capability-match" commands. */
13095 install_element(BGP_NODE, &neighbor_strict_capability_cmd);
13096 install_element(BGP_NODE, &no_neighbor_strict_capability_cmd);
13097
13098 /* "neighbor timers" commands. */
13099 install_element(BGP_NODE, &neighbor_timers_cmd);
13100 install_element(BGP_NODE, &no_neighbor_timers_cmd);
13101
13102 /* "neighbor timers connect" commands. */
13103 install_element(BGP_NODE, &neighbor_timers_connect_cmd);
13104 install_element(BGP_NODE, &no_neighbor_timers_connect_cmd);
13105
13106 /* "neighbor advertisement-interval" commands. */
13107 install_element(BGP_NODE, &neighbor_advertise_interval_cmd);
13108 install_element(BGP_NODE, &no_neighbor_advertise_interval_cmd);
13109
13110 /* "neighbor interface" commands. */
13111 install_element(BGP_NODE, &neighbor_interface_cmd);
13112 install_element(BGP_NODE, &no_neighbor_interface_cmd);
13113
13114 /* "neighbor distribute" commands. */
13115 install_element(BGP_NODE, &neighbor_distribute_list_hidden_cmd);
13116 install_element(BGP_NODE, &no_neighbor_distribute_list_hidden_cmd);
13117 install_element(BGP_IPV4_NODE, &neighbor_distribute_list_cmd);
13118 install_element(BGP_IPV4_NODE, &no_neighbor_distribute_list_cmd);
13119 install_element(BGP_IPV4M_NODE, &neighbor_distribute_list_cmd);
13120 install_element(BGP_IPV4M_NODE, &no_neighbor_distribute_list_cmd);
13121 install_element(BGP_IPV4L_NODE, &neighbor_distribute_list_cmd);
13122 install_element(BGP_IPV4L_NODE, &no_neighbor_distribute_list_cmd);
13123 install_element(BGP_IPV6_NODE, &neighbor_distribute_list_cmd);
13124 install_element(BGP_IPV6_NODE, &no_neighbor_distribute_list_cmd);
13125 install_element(BGP_IPV6M_NODE, &neighbor_distribute_list_cmd);
13126 install_element(BGP_IPV6M_NODE, &no_neighbor_distribute_list_cmd);
13127 install_element(BGP_IPV6L_NODE, &neighbor_distribute_list_cmd);
13128 install_element(BGP_IPV6L_NODE, &no_neighbor_distribute_list_cmd);
13129 install_element(BGP_VPNV4_NODE, &neighbor_distribute_list_cmd);
13130 install_element(BGP_VPNV4_NODE, &no_neighbor_distribute_list_cmd);
13131 install_element(BGP_VPNV6_NODE, &neighbor_distribute_list_cmd);
13132 install_element(BGP_VPNV6_NODE, &no_neighbor_distribute_list_cmd);
13133
13134 /* "neighbor prefix-list" commands. */
13135 install_element(BGP_NODE, &neighbor_prefix_list_hidden_cmd);
13136 install_element(BGP_NODE, &no_neighbor_prefix_list_hidden_cmd);
13137 install_element(BGP_IPV4_NODE, &neighbor_prefix_list_cmd);
13138 install_element(BGP_IPV4_NODE, &no_neighbor_prefix_list_cmd);
13139 install_element(BGP_IPV4M_NODE, &neighbor_prefix_list_cmd);
13140 install_element(BGP_IPV4M_NODE, &no_neighbor_prefix_list_cmd);
13141 install_element(BGP_IPV4L_NODE, &neighbor_prefix_list_cmd);
13142 install_element(BGP_IPV4L_NODE, &no_neighbor_prefix_list_cmd);
13143 install_element(BGP_IPV6_NODE, &neighbor_prefix_list_cmd);
13144 install_element(BGP_IPV6_NODE, &no_neighbor_prefix_list_cmd);
13145 install_element(BGP_IPV6M_NODE, &neighbor_prefix_list_cmd);
13146 install_element(BGP_IPV6M_NODE, &no_neighbor_prefix_list_cmd);
13147 install_element(BGP_IPV6L_NODE, &neighbor_prefix_list_cmd);
13148 install_element(BGP_IPV6L_NODE, &no_neighbor_prefix_list_cmd);
13149 install_element(BGP_VPNV4_NODE, &neighbor_prefix_list_cmd);
13150 install_element(BGP_VPNV4_NODE, &no_neighbor_prefix_list_cmd);
13151 install_element(BGP_VPNV6_NODE, &neighbor_prefix_list_cmd);
13152 install_element(BGP_VPNV6_NODE, &no_neighbor_prefix_list_cmd);
13153 install_element(BGP_FLOWSPECV4_NODE, &neighbor_prefix_list_cmd);
13154 install_element(BGP_FLOWSPECV4_NODE, &no_neighbor_prefix_list_cmd);
13155 install_element(BGP_FLOWSPECV6_NODE, &neighbor_prefix_list_cmd);
13156 install_element(BGP_FLOWSPECV6_NODE, &no_neighbor_prefix_list_cmd);
13157
13158 /* "neighbor filter-list" commands. */
13159 install_element(BGP_NODE, &neighbor_filter_list_hidden_cmd);
13160 install_element(BGP_NODE, &no_neighbor_filter_list_hidden_cmd);
13161 install_element(BGP_IPV4_NODE, &neighbor_filter_list_cmd);
13162 install_element(BGP_IPV4_NODE, &no_neighbor_filter_list_cmd);
13163 install_element(BGP_IPV4M_NODE, &neighbor_filter_list_cmd);
13164 install_element(BGP_IPV4M_NODE, &no_neighbor_filter_list_cmd);
13165 install_element(BGP_IPV4L_NODE, &neighbor_filter_list_cmd);
13166 install_element(BGP_IPV4L_NODE, &no_neighbor_filter_list_cmd);
13167 install_element(BGP_IPV6_NODE, &neighbor_filter_list_cmd);
13168 install_element(BGP_IPV6_NODE, &no_neighbor_filter_list_cmd);
13169 install_element(BGP_IPV6M_NODE, &neighbor_filter_list_cmd);
13170 install_element(BGP_IPV6M_NODE, &no_neighbor_filter_list_cmd);
13171 install_element(BGP_IPV6L_NODE, &neighbor_filter_list_cmd);
13172 install_element(BGP_IPV6L_NODE, &no_neighbor_filter_list_cmd);
13173 install_element(BGP_VPNV4_NODE, &neighbor_filter_list_cmd);
13174 install_element(BGP_VPNV4_NODE, &no_neighbor_filter_list_cmd);
13175 install_element(BGP_VPNV6_NODE, &neighbor_filter_list_cmd);
13176 install_element(BGP_VPNV6_NODE, &no_neighbor_filter_list_cmd);
13177 install_element(BGP_FLOWSPECV4_NODE, &neighbor_filter_list_cmd);
13178 install_element(BGP_FLOWSPECV4_NODE, &no_neighbor_filter_list_cmd);
13179 install_element(BGP_FLOWSPECV6_NODE, &neighbor_filter_list_cmd);
13180 install_element(BGP_FLOWSPECV6_NODE, &no_neighbor_filter_list_cmd);
13181
13182 /* "neighbor route-map" commands. */
13183 install_element(BGP_NODE, &neighbor_route_map_hidden_cmd);
13184 install_element(BGP_NODE, &no_neighbor_route_map_hidden_cmd);
13185 install_element(BGP_IPV4_NODE, &neighbor_route_map_cmd);
13186 install_element(BGP_IPV4_NODE, &no_neighbor_route_map_cmd);
13187 install_element(BGP_IPV4M_NODE, &neighbor_route_map_cmd);
13188 install_element(BGP_IPV4M_NODE, &no_neighbor_route_map_cmd);
13189 install_element(BGP_IPV4L_NODE, &neighbor_route_map_cmd);
13190 install_element(BGP_IPV4L_NODE, &no_neighbor_route_map_cmd);
13191 install_element(BGP_IPV6_NODE, &neighbor_route_map_cmd);
13192 install_element(BGP_IPV6_NODE, &no_neighbor_route_map_cmd);
13193 install_element(BGP_IPV6M_NODE, &neighbor_route_map_cmd);
13194 install_element(BGP_IPV6M_NODE, &no_neighbor_route_map_cmd);
13195 install_element(BGP_IPV6L_NODE, &neighbor_route_map_cmd);
13196 install_element(BGP_IPV6L_NODE, &no_neighbor_route_map_cmd);
13197 install_element(BGP_VPNV4_NODE, &neighbor_route_map_cmd);
13198 install_element(BGP_VPNV4_NODE, &no_neighbor_route_map_cmd);
13199 install_element(BGP_VPNV6_NODE, &neighbor_route_map_cmd);
13200 install_element(BGP_VPNV6_NODE, &no_neighbor_route_map_cmd);
13201 install_element(BGP_FLOWSPECV4_NODE, &neighbor_route_map_cmd);
13202 install_element(BGP_FLOWSPECV4_NODE, &no_neighbor_route_map_cmd);
13203 install_element(BGP_FLOWSPECV6_NODE, &neighbor_route_map_cmd);
13204 install_element(BGP_FLOWSPECV6_NODE, &no_neighbor_route_map_cmd);
13205 install_element(BGP_EVPN_NODE, &neighbor_route_map_cmd);
13206 install_element(BGP_EVPN_NODE, &no_neighbor_route_map_cmd);
13207
13208 /* "neighbor unsuppress-map" commands. */
13209 install_element(BGP_NODE, &neighbor_unsuppress_map_hidden_cmd);
13210 install_element(BGP_NODE, &no_neighbor_unsuppress_map_hidden_cmd);
13211 install_element(BGP_IPV4_NODE, &neighbor_unsuppress_map_cmd);
13212 install_element(BGP_IPV4_NODE, &no_neighbor_unsuppress_map_cmd);
13213 install_element(BGP_IPV4M_NODE, &neighbor_unsuppress_map_cmd);
13214 install_element(BGP_IPV4M_NODE, &no_neighbor_unsuppress_map_cmd);
13215 install_element(BGP_IPV4L_NODE, &neighbor_unsuppress_map_cmd);
13216 install_element(BGP_IPV4L_NODE, &no_neighbor_unsuppress_map_cmd);
13217 install_element(BGP_IPV6_NODE, &neighbor_unsuppress_map_cmd);
13218 install_element(BGP_IPV6_NODE, &no_neighbor_unsuppress_map_cmd);
13219 install_element(BGP_IPV6M_NODE, &neighbor_unsuppress_map_cmd);
13220 install_element(BGP_IPV6M_NODE, &no_neighbor_unsuppress_map_cmd);
13221 install_element(BGP_IPV6L_NODE, &neighbor_unsuppress_map_cmd);
13222 install_element(BGP_IPV6L_NODE, &no_neighbor_unsuppress_map_cmd);
13223 install_element(BGP_VPNV4_NODE, &neighbor_unsuppress_map_cmd);
13224 install_element(BGP_VPNV4_NODE, &no_neighbor_unsuppress_map_cmd);
13225 install_element(BGP_VPNV6_NODE, &neighbor_unsuppress_map_cmd);
13226 install_element(BGP_VPNV6_NODE, &no_neighbor_unsuppress_map_cmd);
13227
13228 /* "neighbor maximum-prefix" commands. */
13229 install_element(BGP_NODE, &neighbor_maximum_prefix_hidden_cmd);
13230 install_element(BGP_NODE,
13231 &neighbor_maximum_prefix_threshold_hidden_cmd);
13232 install_element(BGP_NODE, &neighbor_maximum_prefix_warning_hidden_cmd);
13233 install_element(BGP_NODE,
13234 &neighbor_maximum_prefix_threshold_warning_hidden_cmd);
13235 install_element(BGP_NODE, &neighbor_maximum_prefix_restart_hidden_cmd);
13236 install_element(BGP_NODE,
13237 &neighbor_maximum_prefix_threshold_restart_hidden_cmd);
13238 install_element(BGP_NODE, &no_neighbor_maximum_prefix_hidden_cmd);
13239 install_element(BGP_IPV4_NODE, &neighbor_maximum_prefix_cmd);
13240 install_element(BGP_IPV4_NODE, &neighbor_maximum_prefix_threshold_cmd);
13241 install_element(BGP_IPV4_NODE, &neighbor_maximum_prefix_warning_cmd);
13242 install_element(BGP_IPV4_NODE,
13243 &neighbor_maximum_prefix_threshold_warning_cmd);
13244 install_element(BGP_IPV4_NODE, &neighbor_maximum_prefix_restart_cmd);
13245 install_element(BGP_IPV4_NODE,
13246 &neighbor_maximum_prefix_threshold_restart_cmd);
13247 install_element(BGP_IPV4_NODE, &no_neighbor_maximum_prefix_cmd);
13248 install_element(BGP_IPV4M_NODE, &neighbor_maximum_prefix_cmd);
13249 install_element(BGP_IPV4M_NODE, &neighbor_maximum_prefix_threshold_cmd);
13250 install_element(BGP_IPV4M_NODE, &neighbor_maximum_prefix_warning_cmd);
13251 install_element(BGP_IPV4M_NODE,
13252 &neighbor_maximum_prefix_threshold_warning_cmd);
13253 install_element(BGP_IPV4M_NODE, &neighbor_maximum_prefix_restart_cmd);
13254 install_element(BGP_IPV4M_NODE,
13255 &neighbor_maximum_prefix_threshold_restart_cmd);
13256 install_element(BGP_IPV4M_NODE, &no_neighbor_maximum_prefix_cmd);
13257 install_element(BGP_IPV4L_NODE, &neighbor_maximum_prefix_cmd);
13258 install_element(BGP_IPV4L_NODE, &neighbor_maximum_prefix_threshold_cmd);
13259 install_element(BGP_IPV4L_NODE, &neighbor_maximum_prefix_warning_cmd);
13260 install_element(BGP_IPV4L_NODE,
13261 &neighbor_maximum_prefix_threshold_warning_cmd);
13262 install_element(BGP_IPV4L_NODE, &neighbor_maximum_prefix_restart_cmd);
13263 install_element(BGP_IPV4L_NODE,
13264 &neighbor_maximum_prefix_threshold_restart_cmd);
13265 install_element(BGP_IPV4L_NODE, &no_neighbor_maximum_prefix_cmd);
13266 install_element(BGP_IPV6_NODE, &neighbor_maximum_prefix_cmd);
13267 install_element(BGP_IPV6_NODE, &neighbor_maximum_prefix_threshold_cmd);
13268 install_element(BGP_IPV6_NODE, &neighbor_maximum_prefix_warning_cmd);
13269 install_element(BGP_IPV6_NODE,
13270 &neighbor_maximum_prefix_threshold_warning_cmd);
13271 install_element(BGP_IPV6_NODE, &neighbor_maximum_prefix_restart_cmd);
13272 install_element(BGP_IPV6_NODE,
13273 &neighbor_maximum_prefix_threshold_restart_cmd);
13274 install_element(BGP_IPV6_NODE, &no_neighbor_maximum_prefix_cmd);
13275 install_element(BGP_IPV6M_NODE, &neighbor_maximum_prefix_cmd);
13276 install_element(BGP_IPV6M_NODE, &neighbor_maximum_prefix_threshold_cmd);
13277 install_element(BGP_IPV6M_NODE, &neighbor_maximum_prefix_warning_cmd);
13278 install_element(BGP_IPV6M_NODE,
13279 &neighbor_maximum_prefix_threshold_warning_cmd);
13280 install_element(BGP_IPV6M_NODE, &neighbor_maximum_prefix_restart_cmd);
13281 install_element(BGP_IPV6M_NODE,
13282 &neighbor_maximum_prefix_threshold_restart_cmd);
13283 install_element(BGP_IPV6M_NODE, &no_neighbor_maximum_prefix_cmd);
13284 install_element(BGP_IPV6L_NODE, &neighbor_maximum_prefix_cmd);
13285 install_element(BGP_IPV6L_NODE, &neighbor_maximum_prefix_threshold_cmd);
13286 install_element(BGP_IPV6L_NODE, &neighbor_maximum_prefix_warning_cmd);
13287 install_element(BGP_IPV6L_NODE,
13288 &neighbor_maximum_prefix_threshold_warning_cmd);
13289 install_element(BGP_IPV6L_NODE, &neighbor_maximum_prefix_restart_cmd);
13290 install_element(BGP_IPV6L_NODE,
13291 &neighbor_maximum_prefix_threshold_restart_cmd);
13292 install_element(BGP_IPV6L_NODE, &no_neighbor_maximum_prefix_cmd);
13293 install_element(BGP_VPNV4_NODE, &neighbor_maximum_prefix_cmd);
13294 install_element(BGP_VPNV4_NODE, &neighbor_maximum_prefix_threshold_cmd);
13295 install_element(BGP_VPNV4_NODE, &neighbor_maximum_prefix_warning_cmd);
13296 install_element(BGP_VPNV4_NODE,
13297 &neighbor_maximum_prefix_threshold_warning_cmd);
13298 install_element(BGP_VPNV4_NODE, &neighbor_maximum_prefix_restart_cmd);
13299 install_element(BGP_VPNV4_NODE,
13300 &neighbor_maximum_prefix_threshold_restart_cmd);
13301 install_element(BGP_VPNV4_NODE, &no_neighbor_maximum_prefix_cmd);
13302 install_element(BGP_VPNV6_NODE, &neighbor_maximum_prefix_cmd);
13303 install_element(BGP_VPNV6_NODE, &neighbor_maximum_prefix_threshold_cmd);
13304 install_element(BGP_VPNV6_NODE, &neighbor_maximum_prefix_warning_cmd);
13305 install_element(BGP_VPNV6_NODE,
13306 &neighbor_maximum_prefix_threshold_warning_cmd);
13307 install_element(BGP_VPNV6_NODE, &neighbor_maximum_prefix_restart_cmd);
13308 install_element(BGP_VPNV6_NODE,
13309 &neighbor_maximum_prefix_threshold_restart_cmd);
13310 install_element(BGP_VPNV6_NODE, &no_neighbor_maximum_prefix_cmd);
13311
13312 /* "neighbor allowas-in" */
13313 install_element(BGP_NODE, &neighbor_allowas_in_hidden_cmd);
13314 install_element(BGP_NODE, &no_neighbor_allowas_in_hidden_cmd);
13315 install_element(BGP_IPV4_NODE, &neighbor_allowas_in_cmd);
13316 install_element(BGP_IPV4_NODE, &no_neighbor_allowas_in_cmd);
13317 install_element(BGP_IPV4M_NODE, &neighbor_allowas_in_cmd);
13318 install_element(BGP_IPV4M_NODE, &no_neighbor_allowas_in_cmd);
13319 install_element(BGP_IPV4L_NODE, &neighbor_allowas_in_cmd);
13320 install_element(BGP_IPV4L_NODE, &no_neighbor_allowas_in_cmd);
13321 install_element(BGP_IPV6_NODE, &neighbor_allowas_in_cmd);
13322 install_element(BGP_IPV6_NODE, &no_neighbor_allowas_in_cmd);
13323 install_element(BGP_IPV6M_NODE, &neighbor_allowas_in_cmd);
13324 install_element(BGP_IPV6M_NODE, &no_neighbor_allowas_in_cmd);
13325 install_element(BGP_IPV6L_NODE, &neighbor_allowas_in_cmd);
13326 install_element(BGP_IPV6L_NODE, &no_neighbor_allowas_in_cmd);
13327 install_element(BGP_VPNV4_NODE, &neighbor_allowas_in_cmd);
13328 install_element(BGP_VPNV4_NODE, &no_neighbor_allowas_in_cmd);
13329 install_element(BGP_VPNV6_NODE, &neighbor_allowas_in_cmd);
13330 install_element(BGP_VPNV6_NODE, &no_neighbor_allowas_in_cmd);
13331 install_element(BGP_EVPN_NODE, &neighbor_allowas_in_cmd);
13332 install_element(BGP_EVPN_NODE, &no_neighbor_allowas_in_cmd);
13333
13334 /* address-family commands. */
13335 install_element(BGP_NODE, &address_family_ipv4_safi_cmd);
13336 install_element(BGP_NODE, &address_family_ipv6_safi_cmd);
13337 #ifdef KEEP_OLD_VPN_COMMANDS
13338 install_element(BGP_NODE, &address_family_vpnv4_cmd);
13339 install_element(BGP_NODE, &address_family_vpnv6_cmd);
13340 #endif /* KEEP_OLD_VPN_COMMANDS */
13341
13342 install_element(BGP_NODE, &address_family_evpn_cmd);
13343
13344 /* "exit-address-family" command. */
13345 install_element(BGP_IPV4_NODE, &exit_address_family_cmd);
13346 install_element(BGP_IPV4M_NODE, &exit_address_family_cmd);
13347 install_element(BGP_IPV4L_NODE, &exit_address_family_cmd);
13348 install_element(BGP_IPV6_NODE, &exit_address_family_cmd);
13349 install_element(BGP_IPV6M_NODE, &exit_address_family_cmd);
13350 install_element(BGP_IPV6L_NODE, &exit_address_family_cmd);
13351 install_element(BGP_VPNV4_NODE, &exit_address_family_cmd);
13352 install_element(BGP_VPNV6_NODE, &exit_address_family_cmd);
13353 install_element(BGP_FLOWSPECV4_NODE, &exit_address_family_cmd);
13354 install_element(BGP_FLOWSPECV6_NODE, &exit_address_family_cmd);
13355 install_element(BGP_EVPN_NODE, &exit_address_family_cmd);
13356
13357 /* "clear ip bgp commands" */
13358 install_element(ENABLE_NODE, &clear_ip_bgp_all_cmd);
13359
13360 /* clear ip bgp prefix */
13361 install_element(ENABLE_NODE, &clear_ip_bgp_prefix_cmd);
13362 install_element(ENABLE_NODE, &clear_bgp_ipv6_safi_prefix_cmd);
13363 install_element(ENABLE_NODE, &clear_bgp_instance_ipv6_safi_prefix_cmd);
13364
13365 /* "show [ip] bgp summary" commands. */
13366 install_element(VIEW_NODE, &show_bgp_instance_all_ipv6_updgrps_cmd);
13367 install_element(VIEW_NODE, &show_bgp_instance_updgrps_stats_cmd);
13368 install_element(VIEW_NODE, &show_bgp_updgrps_stats_cmd);
13369 install_element(VIEW_NODE, &show_ip_bgp_instance_updgrps_adj_s_cmd);
13370 install_element(VIEW_NODE, &show_ip_bgp_summary_cmd);
13371 install_element(VIEW_NODE, &show_ip_bgp_updgrps_cmd);
13372
13373 /* "show [ip] bgp neighbors" commands. */
13374 install_element(VIEW_NODE, &show_ip_bgp_neighbors_cmd);
13375
13376 /* "show [ip] bgp peer-group" commands. */
13377 install_element(VIEW_NODE, &show_ip_bgp_peer_groups_cmd);
13378
13379 /* "show [ip] bgp paths" commands. */
13380 install_element(VIEW_NODE, &show_ip_bgp_paths_cmd);
13381
13382 /* "show [ip] bgp community" commands. */
13383 install_element(VIEW_NODE, &show_ip_bgp_community_info_cmd);
13384
13385 /* "show ip bgp large-community" commands. */
13386 install_element(VIEW_NODE, &show_ip_bgp_lcommunity_info_cmd);
13387 /* "show [ip] bgp attribute-info" commands. */
13388 install_element(VIEW_NODE, &show_ip_bgp_attr_info_cmd);
13389 /* "show [ip] bgp route-leak" command */
13390 install_element(VIEW_NODE, &show_ip_bgp_route_leak_cmd);
13391
13392 /* "redistribute" commands. */
13393 install_element(BGP_NODE, &bgp_redistribute_ipv4_hidden_cmd);
13394 install_element(BGP_NODE, &no_bgp_redistribute_ipv4_hidden_cmd);
13395 install_element(BGP_NODE, &bgp_redistribute_ipv4_rmap_hidden_cmd);
13396 install_element(BGP_NODE, &bgp_redistribute_ipv4_metric_hidden_cmd);
13397 install_element(BGP_NODE,
13398 &bgp_redistribute_ipv4_rmap_metric_hidden_cmd);
13399 install_element(BGP_NODE,
13400 &bgp_redistribute_ipv4_metric_rmap_hidden_cmd);
13401 install_element(BGP_NODE, &bgp_redistribute_ipv4_ospf_hidden_cmd);
13402 install_element(BGP_NODE, &no_bgp_redistribute_ipv4_ospf_hidden_cmd);
13403 install_element(BGP_NODE, &bgp_redistribute_ipv4_ospf_rmap_hidden_cmd);
13404 install_element(BGP_NODE,
13405 &bgp_redistribute_ipv4_ospf_metric_hidden_cmd);
13406 install_element(BGP_NODE,
13407 &bgp_redistribute_ipv4_ospf_rmap_metric_hidden_cmd);
13408 install_element(BGP_NODE,
13409 &bgp_redistribute_ipv4_ospf_metric_rmap_hidden_cmd);
13410 install_element(BGP_IPV4_NODE, &bgp_redistribute_ipv4_cmd);
13411 install_element(BGP_IPV4_NODE, &no_bgp_redistribute_ipv4_cmd);
13412 install_element(BGP_IPV4_NODE, &bgp_redistribute_ipv4_rmap_cmd);
13413 install_element(BGP_IPV4_NODE, &bgp_redistribute_ipv4_metric_cmd);
13414 install_element(BGP_IPV4_NODE, &bgp_redistribute_ipv4_rmap_metric_cmd);
13415 install_element(BGP_IPV4_NODE, &bgp_redistribute_ipv4_metric_rmap_cmd);
13416 install_element(BGP_IPV4_NODE, &bgp_redistribute_ipv4_ospf_cmd);
13417 install_element(BGP_IPV4_NODE, &no_bgp_redistribute_ipv4_ospf_cmd);
13418 install_element(BGP_IPV4_NODE, &bgp_redistribute_ipv4_ospf_rmap_cmd);
13419 install_element(BGP_IPV4_NODE, &bgp_redistribute_ipv4_ospf_metric_cmd);
13420 install_element(BGP_IPV4_NODE,
13421 &bgp_redistribute_ipv4_ospf_rmap_metric_cmd);
13422 install_element(BGP_IPV4_NODE,
13423 &bgp_redistribute_ipv4_ospf_metric_rmap_cmd);
13424 install_element(BGP_IPV6_NODE, &bgp_redistribute_ipv6_cmd);
13425 install_element(BGP_IPV6_NODE, &no_bgp_redistribute_ipv6_cmd);
13426 install_element(BGP_IPV6_NODE, &bgp_redistribute_ipv6_rmap_cmd);
13427 install_element(BGP_IPV6_NODE, &bgp_redistribute_ipv6_metric_cmd);
13428 install_element(BGP_IPV6_NODE, &bgp_redistribute_ipv6_rmap_metric_cmd);
13429 install_element(BGP_IPV6_NODE, &bgp_redistribute_ipv6_metric_rmap_cmd);
13430
13431 /* import|export vpn [route-map WORD] */
13432 install_element(BGP_IPV4_NODE, &bgp_imexport_vpn_cmd);
13433 install_element(BGP_IPV6_NODE, &bgp_imexport_vpn_cmd);
13434
13435 install_element(BGP_IPV4_NODE, &bgp_imexport_vrf_cmd);
13436 install_element(BGP_IPV6_NODE, &bgp_imexport_vrf_cmd);
13437
13438 /* ttl_security commands */
13439 install_element(BGP_NODE, &neighbor_ttl_security_cmd);
13440 install_element(BGP_NODE, &no_neighbor_ttl_security_cmd);
13441
13442 /* "show [ip] bgp memory" commands. */
13443 install_element(VIEW_NODE, &show_bgp_memory_cmd);
13444
13445 /* "show bgp martian next-hop" */
13446 install_element(VIEW_NODE, &show_bgp_martian_nexthop_db_cmd);
13447
13448 /* "show [ip] bgp views" commands. */
13449 install_element(VIEW_NODE, &show_bgp_views_cmd);
13450
13451 /* "show [ip] bgp vrfs" commands. */
13452 install_element(VIEW_NODE, &show_bgp_vrfs_cmd);
13453
13454 /* Community-list. */
13455 community_list_vty();
13456
13457 /* vpn-policy commands */
13458 install_element(BGP_IPV4_NODE, &af_rd_vpn_export_cmd);
13459 install_element(BGP_IPV6_NODE, &af_rd_vpn_export_cmd);
13460 install_element(BGP_IPV4_NODE, &af_label_vpn_export_cmd);
13461 install_element(BGP_IPV6_NODE, &af_label_vpn_export_cmd);
13462 install_element(BGP_IPV4_NODE, &af_nexthop_vpn_export_cmd);
13463 install_element(BGP_IPV6_NODE, &af_nexthop_vpn_export_cmd);
13464 install_element(BGP_IPV4_NODE, &af_rt_vpn_imexport_cmd);
13465 install_element(BGP_IPV6_NODE, &af_rt_vpn_imexport_cmd);
13466 install_element(BGP_IPV4_NODE, &af_route_map_vpn_imexport_cmd);
13467 install_element(BGP_IPV6_NODE, &af_route_map_vpn_imexport_cmd);
13468 install_element(BGP_IPV4_NODE, &af_import_vrf_route_map_cmd);
13469 install_element(BGP_IPV6_NODE, &af_import_vrf_route_map_cmd);
13470
13471 install_element(BGP_IPV4_NODE, &af_routetarget_import_cmd);
13472 install_element(BGP_IPV6_NODE, &af_routetarget_import_cmd);
13473
13474 install_element(BGP_IPV4_NODE, &af_no_rd_vpn_export_cmd);
13475 install_element(BGP_IPV6_NODE, &af_no_rd_vpn_export_cmd);
13476 install_element(BGP_IPV4_NODE, &af_no_label_vpn_export_cmd);
13477 install_element(BGP_IPV6_NODE, &af_no_label_vpn_export_cmd);
13478 install_element(BGP_IPV4_NODE, &af_no_nexthop_vpn_export_cmd);
13479 install_element(BGP_IPV6_NODE, &af_no_nexthop_vpn_export_cmd);
13480 install_element(BGP_IPV4_NODE, &af_no_rt_vpn_imexport_cmd);
13481 install_element(BGP_IPV6_NODE, &af_no_rt_vpn_imexport_cmd);
13482 install_element(BGP_IPV4_NODE, &af_no_route_map_vpn_imexport_cmd);
13483 install_element(BGP_IPV6_NODE, &af_no_route_map_vpn_imexport_cmd);
13484 install_element(BGP_IPV4_NODE, &af_no_import_vrf_route_map_cmd);
13485 install_element(BGP_IPV6_NODE, &af_no_import_vrf_route_map_cmd);
13486 }
13487
13488 #include "memory.h"
13489 #include "bgp_regex.h"
13490 #include "bgp_clist.h"
13491 #include "bgp_ecommunity.h"
13492
13493 /* VTY functions. */
13494
13495 /* Direction value to string conversion. */
13496 static const char *community_direct_str(int direct)
13497 {
13498 switch (direct) {
13499 case COMMUNITY_DENY:
13500 return "deny";
13501 case COMMUNITY_PERMIT:
13502 return "permit";
13503 default:
13504 return "unknown";
13505 }
13506 }
13507
13508 /* Display error string. */
13509 static void community_list_perror(struct vty *vty, int ret)
13510 {
13511 switch (ret) {
13512 case COMMUNITY_LIST_ERR_CANT_FIND_LIST:
13513 vty_out(vty, "%% Can't find community-list\n");
13514 break;
13515 case COMMUNITY_LIST_ERR_MALFORMED_VAL:
13516 vty_out(vty, "%% Malformed community-list value\n");
13517 break;
13518 case COMMUNITY_LIST_ERR_STANDARD_CONFLICT:
13519 vty_out(vty,
13520 "%% Community name conflict, previously defined as standard community\n");
13521 break;
13522 case COMMUNITY_LIST_ERR_EXPANDED_CONFLICT:
13523 vty_out(vty,
13524 "%% Community name conflict, previously defined as expanded community\n");
13525 break;
13526 }
13527 }
13528
13529 /* "community-list" keyword help string. */
13530 #define COMMUNITY_LIST_STR "Add a community list entry\n"
13531
13532 /* ip community-list standard */
13533 DEFUN (ip_community_list_standard,
13534 ip_community_list_standard_cmd,
13535 "ip community-list <(1-99)|standard WORD> <deny|permit> AA:NN...",
13536 IP_STR
13537 COMMUNITY_LIST_STR
13538 "Community list number (standard)\n"
13539 "Add an standard community-list entry\n"
13540 "Community list name\n"
13541 "Specify community to reject\n"
13542 "Specify community to accept\n"
13543 COMMUNITY_VAL_STR)
13544 {
13545 char *cl_name_or_number = NULL;
13546 int direct = 0;
13547 int style = COMMUNITY_LIST_STANDARD;
13548
13549 int idx = 0;
13550 argv_find(argv, argc, "(1-99)", &idx);
13551 argv_find(argv, argc, "WORD", &idx);
13552 cl_name_or_number = argv[idx]->arg;
13553 direct = argv_find(argv, argc, "permit", &idx) ? COMMUNITY_PERMIT
13554 : COMMUNITY_DENY;
13555 argv_find(argv, argc, "AA:NN", &idx);
13556 char *str = argv_concat(argv, argc, idx);
13557
13558 int ret = community_list_set(bgp_clist, cl_name_or_number, str, direct,
13559 style);
13560
13561 XFREE(MTYPE_TMP, str);
13562
13563 if (ret < 0) {
13564 /* Display error string. */
13565 community_list_perror(vty, ret);
13566 return CMD_WARNING_CONFIG_FAILED;
13567 }
13568
13569 return CMD_SUCCESS;
13570 }
13571
13572 DEFUN (no_ip_community_list_standard_all,
13573 no_ip_community_list_standard_all_cmd,
13574 "no ip community-list <(1-99)|standard WORD> <deny|permit> AA:NN...",
13575 NO_STR
13576 IP_STR
13577 COMMUNITY_LIST_STR
13578 "Community list number (standard)\n"
13579 "Add an standard community-list entry\n"
13580 "Community list name\n"
13581 "Specify community to reject\n"
13582 "Specify community to accept\n"
13583 COMMUNITY_VAL_STR)
13584 {
13585 char *cl_name_or_number = NULL;
13586 int direct = 0;
13587 int style = COMMUNITY_LIST_STANDARD;
13588
13589 int idx = 0;
13590 argv_find(argv, argc, "(1-99)", &idx);
13591 argv_find(argv, argc, "WORD", &idx);
13592 cl_name_or_number = argv[idx]->arg;
13593 direct = argv_find(argv, argc, "permit", &idx) ? COMMUNITY_PERMIT
13594 : COMMUNITY_DENY;
13595 argv_find(argv, argc, "AA:NN", &idx);
13596 char *str = argv_concat(argv, argc, idx);
13597
13598 int ret = community_list_unset(bgp_clist, cl_name_or_number, str,
13599 direct, style);
13600
13601 XFREE(MTYPE_TMP, str);
13602
13603 if (ret < 0) {
13604 community_list_perror(vty, ret);
13605 return CMD_WARNING_CONFIG_FAILED;
13606 }
13607
13608 return CMD_SUCCESS;
13609 }
13610
13611 /* ip community-list expanded */
13612 DEFUN (ip_community_list_expanded_all,
13613 ip_community_list_expanded_all_cmd,
13614 "ip community-list <(100-500)|expanded WORD> <deny|permit> AA:NN...",
13615 IP_STR
13616 COMMUNITY_LIST_STR
13617 "Community list number (expanded)\n"
13618 "Add an expanded community-list entry\n"
13619 "Community list name\n"
13620 "Specify community to reject\n"
13621 "Specify community to accept\n"
13622 COMMUNITY_VAL_STR)
13623 {
13624 char *cl_name_or_number = NULL;
13625 int direct = 0;
13626 int style = COMMUNITY_LIST_EXPANDED;
13627
13628 int idx = 0;
13629 argv_find(argv, argc, "(100-500)", &idx);
13630 argv_find(argv, argc, "WORD", &idx);
13631 cl_name_or_number = argv[idx]->arg;
13632 direct = argv_find(argv, argc, "permit", &idx) ? COMMUNITY_PERMIT
13633 : COMMUNITY_DENY;
13634 argv_find(argv, argc, "AA:NN", &idx);
13635 char *str = argv_concat(argv, argc, idx);
13636
13637 int ret = community_list_set(bgp_clist, cl_name_or_number, str, direct,
13638 style);
13639
13640 XFREE(MTYPE_TMP, str);
13641
13642 if (ret < 0) {
13643 /* Display error string. */
13644 community_list_perror(vty, ret);
13645 return CMD_WARNING_CONFIG_FAILED;
13646 }
13647
13648 return CMD_SUCCESS;
13649 }
13650
13651 DEFUN (no_ip_community_list_expanded_all,
13652 no_ip_community_list_expanded_all_cmd,
13653 "no ip community-list <(100-500)|expanded WORD> <deny|permit> AA:NN...",
13654 NO_STR
13655 IP_STR
13656 COMMUNITY_LIST_STR
13657 "Community list number (expanded)\n"
13658 "Add an expanded community-list entry\n"
13659 "Community list name\n"
13660 "Specify community to reject\n"
13661 "Specify community to accept\n"
13662 COMMUNITY_VAL_STR)
13663 {
13664 char *cl_name_or_number = NULL;
13665 int direct = 0;
13666 int style = COMMUNITY_LIST_EXPANDED;
13667
13668 int idx = 0;
13669 argv_find(argv, argc, "(100-500)", &idx);
13670 argv_find(argv, argc, "WORD", &idx);
13671 cl_name_or_number = argv[idx]->arg;
13672 direct = argv_find(argv, argc, "permit", &idx) ? COMMUNITY_PERMIT
13673 : COMMUNITY_DENY;
13674 argv_find(argv, argc, "AA:NN", &idx);
13675 char *str = argv_concat(argv, argc, idx);
13676
13677 int ret = community_list_unset(bgp_clist, cl_name_or_number, str,
13678 direct, style);
13679
13680 XFREE(MTYPE_TMP, str);
13681
13682 if (ret < 0) {
13683 community_list_perror(vty, ret);
13684 return CMD_WARNING_CONFIG_FAILED;
13685 }
13686
13687 return CMD_SUCCESS;
13688 }
13689
13690 /* Return configuration string of community-list entry. */
13691 static const char *community_list_config_str(struct community_entry *entry)
13692 {
13693 const char *str;
13694
13695 if (entry->any)
13696 str = "";
13697 else {
13698 if (entry->style == COMMUNITY_LIST_STANDARD)
13699 str = community_str(entry->u.com, false);
13700 else if (entry->style == LARGE_COMMUNITY_LIST_STANDARD)
13701 str = lcommunity_str(entry->u.lcom, false);
13702 else
13703 str = entry->config;
13704 }
13705 return str;
13706 }
13707
13708 static void community_list_show(struct vty *vty, struct community_list *list)
13709 {
13710 struct community_entry *entry;
13711
13712 for (entry = list->head; entry; entry = entry->next) {
13713 if (entry == list->head) {
13714 if (all_digit(list->name))
13715 vty_out(vty, "Community %s list %s\n",
13716 entry->style == COMMUNITY_LIST_STANDARD
13717 ? "standard"
13718 : "(expanded) access",
13719 list->name);
13720 else
13721 vty_out(vty, "Named Community %s list %s\n",
13722 entry->style == COMMUNITY_LIST_STANDARD
13723 ? "standard"
13724 : "expanded",
13725 list->name);
13726 }
13727 if (entry->any)
13728 vty_out(vty, " %s\n",
13729 community_direct_str(entry->direct));
13730 else
13731 vty_out(vty, " %s %s\n",
13732 community_direct_str(entry->direct),
13733 community_list_config_str(entry));
13734 }
13735 }
13736
13737 DEFUN (show_ip_community_list,
13738 show_ip_community_list_cmd,
13739 "show ip community-list",
13740 SHOW_STR
13741 IP_STR
13742 "List community-list\n")
13743 {
13744 struct community_list *list;
13745 struct community_list_master *cm;
13746
13747 cm = community_list_master_lookup(bgp_clist, COMMUNITY_LIST_MASTER);
13748 if (!cm)
13749 return CMD_SUCCESS;
13750
13751 for (list = cm->num.head; list; list = list->next)
13752 community_list_show(vty, list);
13753
13754 for (list = cm->str.head; list; list = list->next)
13755 community_list_show(vty, list);
13756
13757 return CMD_SUCCESS;
13758 }
13759
13760 DEFUN (show_ip_community_list_arg,
13761 show_ip_community_list_arg_cmd,
13762 "show ip community-list <(1-500)|WORD>",
13763 SHOW_STR
13764 IP_STR
13765 "List community-list\n"
13766 "Community-list number\n"
13767 "Community-list name\n")
13768 {
13769 int idx_comm_list = 3;
13770 struct community_list *list;
13771
13772 list = community_list_lookup(bgp_clist, argv[idx_comm_list]->arg,
13773 COMMUNITY_LIST_MASTER);
13774 if (!list) {
13775 vty_out(vty, "%% Can't find community-list\n");
13776 return CMD_WARNING;
13777 }
13778
13779 community_list_show(vty, list);
13780
13781 return CMD_SUCCESS;
13782 }
13783
13784 /*
13785 * Large Community code.
13786 */
13787 static int lcommunity_list_set_vty(struct vty *vty, int argc,
13788 struct cmd_token **argv, int style,
13789 int reject_all_digit_name)
13790 {
13791 int ret;
13792 int direct;
13793 char *str;
13794 int idx = 0;
13795 char *cl_name;
13796
13797 direct = argv_find(argv, argc, "permit", &idx) ? COMMUNITY_PERMIT
13798 : COMMUNITY_DENY;
13799
13800 /* All digit name check. */
13801 idx = 0;
13802 argv_find(argv, argc, "WORD", &idx);
13803 argv_find(argv, argc, "(1-99)", &idx);
13804 argv_find(argv, argc, "(100-500)", &idx);
13805 cl_name = argv[idx]->arg;
13806 if (reject_all_digit_name && all_digit(cl_name)) {
13807 vty_out(vty, "%% Community name cannot have all digits\n");
13808 return CMD_WARNING_CONFIG_FAILED;
13809 }
13810
13811 idx = 0;
13812 argv_find(argv, argc, "AA:BB:CC", &idx);
13813 argv_find(argv, argc, "LINE", &idx);
13814 /* Concat community string argument. */
13815 if (idx)
13816 str = argv_concat(argv, argc, idx);
13817 else
13818 str = NULL;
13819
13820 ret = lcommunity_list_set(bgp_clist, cl_name, str, direct, style);
13821
13822 /* Free temporary community list string allocated by
13823 argv_concat(). */
13824 if (str)
13825 XFREE(MTYPE_TMP, str);
13826
13827 if (ret < 0) {
13828 community_list_perror(vty, ret);
13829 return CMD_WARNING_CONFIG_FAILED;
13830 }
13831 return CMD_SUCCESS;
13832 }
13833
13834 static int lcommunity_list_unset_vty(struct vty *vty, int argc,
13835 struct cmd_token **argv, int style)
13836 {
13837 int ret;
13838 int direct = 0;
13839 char *str = NULL;
13840 int idx = 0;
13841
13842 argv_find(argv, argc, "permit", &idx);
13843 argv_find(argv, argc, "deny", &idx);
13844
13845 if (idx) {
13846 /* Check the list direct. */
13847 if (strncmp(argv[idx]->arg, "p", 1) == 0)
13848 direct = COMMUNITY_PERMIT;
13849 else
13850 direct = COMMUNITY_DENY;
13851
13852 idx = 0;
13853 argv_find(argv, argc, "LINE", &idx);
13854 argv_find(argv, argc, "AA:AA:NN", &idx);
13855 /* Concat community string argument. */
13856 str = argv_concat(argv, argc, idx);
13857 }
13858
13859 idx = 0;
13860 argv_find(argv, argc, "(1-99)", &idx);
13861 argv_find(argv, argc, "(100-500)", &idx);
13862 argv_find(argv, argc, "WORD", &idx);
13863
13864 /* Unset community list. */
13865 ret = lcommunity_list_unset(bgp_clist, argv[idx]->arg, str, direct,
13866 style);
13867
13868 /* Free temporary community list string allocated by
13869 argv_concat(). */
13870 if (str)
13871 XFREE(MTYPE_TMP, str);
13872
13873 if (ret < 0) {
13874 community_list_perror(vty, ret);
13875 return CMD_WARNING_CONFIG_FAILED;
13876 }
13877
13878 return CMD_SUCCESS;
13879 }
13880
13881 /* "large-community-list" keyword help string. */
13882 #define LCOMMUNITY_LIST_STR "Add a large community list entry\n"
13883 #define LCOMMUNITY_VAL_STR "large community in 'aa:bb:cc' format\n"
13884
13885 DEFUN (ip_lcommunity_list_standard,
13886 ip_lcommunity_list_standard_cmd,
13887 "ip large-community-list (1-99) <deny|permit>",
13888 IP_STR
13889 LCOMMUNITY_LIST_STR
13890 "Large Community list number (standard)\n"
13891 "Specify large community to reject\n"
13892 "Specify large community to accept\n")
13893 {
13894 return lcommunity_list_set_vty(vty, argc, argv,
13895 LARGE_COMMUNITY_LIST_STANDARD, 0);
13896 }
13897
13898 DEFUN (ip_lcommunity_list_standard1,
13899 ip_lcommunity_list_standard1_cmd,
13900 "ip large-community-list (1-99) <deny|permit> AA:BB:CC...",
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 LCOMMUNITY_VAL_STR)
13907 {
13908 return lcommunity_list_set_vty(vty, argc, argv,
13909 LARGE_COMMUNITY_LIST_STANDARD, 0);
13910 }
13911
13912 DEFUN (ip_lcommunity_list_expanded,
13913 ip_lcommunity_list_expanded_cmd,
13914 "ip large-community-list (100-500) <deny|permit> LINE...",
13915 IP_STR
13916 LCOMMUNITY_LIST_STR
13917 "Large Community list number (expanded)\n"
13918 "Specify large community to reject\n"
13919 "Specify large community to accept\n"
13920 "An ordered list as a regular-expression\n")
13921 {
13922 return lcommunity_list_set_vty(vty, argc, argv,
13923 LARGE_COMMUNITY_LIST_EXPANDED, 0);
13924 }
13925
13926 DEFUN (ip_lcommunity_list_name_standard,
13927 ip_lcommunity_list_name_standard_cmd,
13928 "ip large-community-list standard WORD <deny|permit>",
13929 IP_STR
13930 LCOMMUNITY_LIST_STR
13931 "Specify standard large-community-list\n"
13932 "Large Community list name\n"
13933 "Specify large community to reject\n"
13934 "Specify large community to accept\n")
13935 {
13936 return lcommunity_list_set_vty(vty, argc, argv,
13937 LARGE_COMMUNITY_LIST_STANDARD, 1);
13938 }
13939
13940 DEFUN (ip_lcommunity_list_name_standard1,
13941 ip_lcommunity_list_name_standard1_cmd,
13942 "ip large-community-list standard WORD <deny|permit> AA:BB:CC...",
13943 IP_STR
13944 LCOMMUNITY_LIST_STR
13945 "Specify standard large-community-list\n"
13946 "Large Community list name\n"
13947 "Specify large community to reject\n"
13948 "Specify large community to accept\n"
13949 LCOMMUNITY_VAL_STR)
13950 {
13951 return lcommunity_list_set_vty(vty, argc, argv,
13952 LARGE_COMMUNITY_LIST_STANDARD, 1);
13953 }
13954
13955 DEFUN (ip_lcommunity_list_name_expanded,
13956 ip_lcommunity_list_name_expanded_cmd,
13957 "ip large-community-list expanded WORD <deny|permit> LINE...",
13958 IP_STR
13959 LCOMMUNITY_LIST_STR
13960 "Specify expanded large-community-list\n"
13961 "Large Community list name\n"
13962 "Specify large community to reject\n"
13963 "Specify large community to accept\n"
13964 "An ordered list as a regular-expression\n")
13965 {
13966 return lcommunity_list_set_vty(vty, argc, argv,
13967 LARGE_COMMUNITY_LIST_EXPANDED, 1);
13968 }
13969
13970 DEFUN (no_ip_lcommunity_list_standard_all,
13971 no_ip_lcommunity_list_standard_all_cmd,
13972 "no ip large-community-list <(1-99)|(100-500)|WORD>",
13973 NO_STR
13974 IP_STR
13975 LCOMMUNITY_LIST_STR
13976 "Large Community list number (standard)\n"
13977 "Large Community list number (expanded)\n"
13978 "Large Community list name\n")
13979 {
13980 return lcommunity_list_unset_vty(vty, argc, argv,
13981 LARGE_COMMUNITY_LIST_STANDARD);
13982 }
13983
13984 DEFUN (no_ip_lcommunity_list_name_expanded_all,
13985 no_ip_lcommunity_list_name_expanded_all_cmd,
13986 "no ip large-community-list expanded WORD",
13987 NO_STR
13988 IP_STR
13989 LCOMMUNITY_LIST_STR
13990 "Specify expanded large-community-list\n"
13991 "Large Community list name\n")
13992 {
13993 return lcommunity_list_unset_vty(vty, argc, argv,
13994 LARGE_COMMUNITY_LIST_EXPANDED);
13995 }
13996
13997 DEFUN (no_ip_lcommunity_list_standard,
13998 no_ip_lcommunity_list_standard_cmd,
13999 "no ip large-community-list (1-99) <deny|permit> AA:AA:NN...",
14000 NO_STR
14001 IP_STR
14002 LCOMMUNITY_LIST_STR
14003 "Large Community list number (standard)\n"
14004 "Specify large community to reject\n"
14005 "Specify large community to accept\n"
14006 LCOMMUNITY_VAL_STR)
14007 {
14008 return lcommunity_list_unset_vty(vty, argc, argv,
14009 LARGE_COMMUNITY_LIST_STANDARD);
14010 }
14011
14012 DEFUN (no_ip_lcommunity_list_expanded,
14013 no_ip_lcommunity_list_expanded_cmd,
14014 "no ip large-community-list (100-500) <deny|permit> LINE...",
14015 NO_STR
14016 IP_STR
14017 LCOMMUNITY_LIST_STR
14018 "Large Community list number (expanded)\n"
14019 "Specify large community to reject\n"
14020 "Specify large community to accept\n"
14021 "An ordered list as a regular-expression\n")
14022 {
14023 return lcommunity_list_unset_vty(vty, argc, argv,
14024 LARGE_COMMUNITY_LIST_EXPANDED);
14025 }
14026
14027 DEFUN (no_ip_lcommunity_list_name_standard,
14028 no_ip_lcommunity_list_name_standard_cmd,
14029 "no ip large-community-list standard WORD <deny|permit> AA:AA:NN...",
14030 NO_STR
14031 IP_STR
14032 LCOMMUNITY_LIST_STR
14033 "Specify standard large-community-list\n"
14034 "Large Community list name\n"
14035 "Specify large community to reject\n"
14036 "Specify large community to accept\n"
14037 LCOMMUNITY_VAL_STR)
14038 {
14039 return lcommunity_list_unset_vty(vty, argc, argv,
14040 LARGE_COMMUNITY_LIST_STANDARD);
14041 }
14042
14043 DEFUN (no_ip_lcommunity_list_name_expanded,
14044 no_ip_lcommunity_list_name_expanded_cmd,
14045 "no ip large-community-list expanded WORD <deny|permit> LINE...",
14046 NO_STR
14047 IP_STR
14048 LCOMMUNITY_LIST_STR
14049 "Specify expanded large-community-list\n"
14050 "Large community list name\n"
14051 "Specify large community to reject\n"
14052 "Specify large community to accept\n"
14053 "An ordered list as a regular-expression\n")
14054 {
14055 return lcommunity_list_unset_vty(vty, argc, argv,
14056 LARGE_COMMUNITY_LIST_EXPANDED);
14057 }
14058
14059 static void lcommunity_list_show(struct vty *vty, struct community_list *list)
14060 {
14061 struct community_entry *entry;
14062
14063 for (entry = list->head; entry; entry = entry->next) {
14064 if (entry == list->head) {
14065 if (all_digit(list->name))
14066 vty_out(vty, "Large community %s list %s\n",
14067 entry->style == EXTCOMMUNITY_LIST_STANDARD
14068 ? "standard"
14069 : "(expanded) access",
14070 list->name);
14071 else
14072 vty_out(vty,
14073 "Named large community %s list %s\n",
14074 entry->style == EXTCOMMUNITY_LIST_STANDARD
14075 ? "standard"
14076 : "expanded",
14077 list->name);
14078 }
14079 if (entry->any)
14080 vty_out(vty, " %s\n",
14081 community_direct_str(entry->direct));
14082 else
14083 vty_out(vty, " %s %s\n",
14084 community_direct_str(entry->direct),
14085 community_list_config_str(entry));
14086 }
14087 }
14088
14089 DEFUN (show_ip_lcommunity_list,
14090 show_ip_lcommunity_list_cmd,
14091 "show ip large-community-list",
14092 SHOW_STR
14093 IP_STR
14094 "List large-community list\n")
14095 {
14096 struct community_list *list;
14097 struct community_list_master *cm;
14098
14099 cm = community_list_master_lookup(bgp_clist,
14100 LARGE_COMMUNITY_LIST_MASTER);
14101 if (!cm)
14102 return CMD_SUCCESS;
14103
14104 for (list = cm->num.head; list; list = list->next)
14105 lcommunity_list_show(vty, list);
14106
14107 for (list = cm->str.head; list; list = list->next)
14108 lcommunity_list_show(vty, list);
14109
14110 return CMD_SUCCESS;
14111 }
14112
14113 DEFUN (show_ip_lcommunity_list_arg,
14114 show_ip_lcommunity_list_arg_cmd,
14115 "show ip large-community-list <(1-500)|WORD>",
14116 SHOW_STR
14117 IP_STR
14118 "List large-community list\n"
14119 "large-community-list number\n"
14120 "large-community-list name\n")
14121 {
14122 struct community_list *list;
14123
14124 list = community_list_lookup(bgp_clist, argv[3]->arg,
14125 LARGE_COMMUNITY_LIST_MASTER);
14126 if (!list) {
14127 vty_out(vty, "%% Can't find extcommunity-list\n");
14128 return CMD_WARNING;
14129 }
14130
14131 lcommunity_list_show(vty, list);
14132
14133 return CMD_SUCCESS;
14134 }
14135
14136 /* "extcommunity-list" keyword help string. */
14137 #define EXTCOMMUNITY_LIST_STR "Add a extended community list entry\n"
14138 #define EXTCOMMUNITY_VAL_STR "Extended community attribute in 'rt aa:nn_or_IPaddr:nn' OR 'soo aa:nn_or_IPaddr:nn' format\n"
14139
14140 DEFUN (ip_extcommunity_list_standard,
14141 ip_extcommunity_list_standard_cmd,
14142 "ip extcommunity-list <(1-99)|standard WORD> <deny|permit> AA:NN...",
14143 IP_STR
14144 EXTCOMMUNITY_LIST_STR
14145 "Extended Community list number (standard)\n"
14146 "Specify standard extcommunity-list\n"
14147 "Community list name\n"
14148 "Specify community to reject\n"
14149 "Specify community to accept\n"
14150 EXTCOMMUNITY_VAL_STR)
14151 {
14152 int style = EXTCOMMUNITY_LIST_STANDARD;
14153 int direct = 0;
14154 char *cl_number_or_name = NULL;
14155
14156 int idx = 0;
14157 argv_find(argv, argc, "(1-99)", &idx);
14158 argv_find(argv, argc, "WORD", &idx);
14159 cl_number_or_name = argv[idx]->arg;
14160 direct = argv_find(argv, argc, "permit", &idx) ? COMMUNITY_PERMIT
14161 : COMMUNITY_DENY;
14162 argv_find(argv, argc, "AA:NN", &idx);
14163 char *str = argv_concat(argv, argc, idx);
14164
14165 int ret = extcommunity_list_set(bgp_clist, cl_number_or_name, str,
14166 direct, style);
14167
14168 XFREE(MTYPE_TMP, str);
14169
14170 if (ret < 0) {
14171 community_list_perror(vty, ret);
14172 return CMD_WARNING_CONFIG_FAILED;
14173 }
14174
14175 return CMD_SUCCESS;
14176 }
14177
14178 DEFUN (ip_extcommunity_list_name_expanded,
14179 ip_extcommunity_list_name_expanded_cmd,
14180 "ip extcommunity-list <(100-500)|expanded WORD> <deny|permit> LINE...",
14181 IP_STR
14182 EXTCOMMUNITY_LIST_STR
14183 "Extended Community list number (expanded)\n"
14184 "Specify expanded extcommunity-list\n"
14185 "Extended Community list name\n"
14186 "Specify community to reject\n"
14187 "Specify community to accept\n"
14188 "An ordered list as a regular-expression\n")
14189 {
14190 int style = EXTCOMMUNITY_LIST_EXPANDED;
14191 int direct = 0;
14192 char *cl_number_or_name = NULL;
14193
14194 int idx = 0;
14195 argv_find(argv, argc, "(100-500)", &idx);
14196 argv_find(argv, argc, "WORD", &idx);
14197 cl_number_or_name = argv[idx]->arg;
14198 direct = argv_find(argv, argc, "permit", &idx) ? COMMUNITY_PERMIT
14199 : COMMUNITY_DENY;
14200 argv_find(argv, argc, "LINE", &idx);
14201 char *str = argv_concat(argv, argc, idx);
14202
14203 int ret = extcommunity_list_set(bgp_clist, cl_number_or_name, str,
14204 direct, style);
14205
14206 XFREE(MTYPE_TMP, str);
14207
14208 if (ret < 0) {
14209 community_list_perror(vty, ret);
14210 return CMD_WARNING_CONFIG_FAILED;
14211 }
14212
14213 return CMD_SUCCESS;
14214 }
14215
14216 DEFUN (no_ip_extcommunity_list_standard_all,
14217 no_ip_extcommunity_list_standard_all_cmd,
14218 "no ip extcommunity-list <(1-99)|standard WORD> <deny|permit> AA:NN...",
14219 NO_STR
14220 IP_STR
14221 EXTCOMMUNITY_LIST_STR
14222 "Extended Community list number (standard)\n"
14223 "Specify standard extcommunity-list\n"
14224 "Community list name\n"
14225 "Specify community to reject\n"
14226 "Specify community to accept\n"
14227 EXTCOMMUNITY_VAL_STR)
14228 {
14229 int style = EXTCOMMUNITY_LIST_STANDARD;
14230 int direct = 0;
14231 char *cl_number_or_name = NULL;
14232
14233 int idx = 0;
14234 argv_find(argv, argc, "(1-99)", &idx);
14235 argv_find(argv, argc, "WORD", &idx);
14236 cl_number_or_name = argv[idx]->arg;
14237 direct = argv_find(argv, argc, "permit", &idx) ? COMMUNITY_PERMIT
14238 : COMMUNITY_DENY;
14239 argv_find(argv, argc, "AA:NN", &idx);
14240 char *str = argv_concat(argv, argc, idx);
14241
14242 int ret = extcommunity_list_unset(bgp_clist, cl_number_or_name, str,
14243 direct, style);
14244
14245 XFREE(MTYPE_TMP, str);
14246
14247 if (ret < 0) {
14248 community_list_perror(vty, ret);
14249 return CMD_WARNING_CONFIG_FAILED;
14250 }
14251
14252 return CMD_SUCCESS;
14253 }
14254
14255 DEFUN (no_ip_extcommunity_list_expanded_all,
14256 no_ip_extcommunity_list_expanded_all_cmd,
14257 "no ip extcommunity-list <(100-500)|expanded WORD> <deny|permit> LINE...",
14258 NO_STR
14259 IP_STR
14260 EXTCOMMUNITY_LIST_STR
14261 "Extended Community list number (expanded)\n"
14262 "Specify expanded extcommunity-list\n"
14263 "Extended Community list name\n"
14264 "Specify community to reject\n"
14265 "Specify community to accept\n"
14266 "An ordered list as a regular-expression\n")
14267 {
14268 int style = EXTCOMMUNITY_LIST_EXPANDED;
14269 int direct = 0;
14270 char *cl_number_or_name = NULL;
14271
14272 int idx = 0;
14273 argv_find(argv, argc, "(100-500)", &idx);
14274 argv_find(argv, argc, "WORD", &idx);
14275 cl_number_or_name = argv[idx]->arg;
14276 direct = argv_find(argv, argc, "permit", &idx) ? COMMUNITY_PERMIT
14277 : COMMUNITY_DENY;
14278 argv_find(argv, argc, "LINE", &idx);
14279 char *str = argv_concat(argv, argc, idx);
14280
14281 int ret = extcommunity_list_unset(bgp_clist, cl_number_or_name, str,
14282 direct, style);
14283
14284 XFREE(MTYPE_TMP, str);
14285
14286 if (ret < 0) {
14287 community_list_perror(vty, ret);
14288 return CMD_WARNING_CONFIG_FAILED;
14289 }
14290
14291 return CMD_SUCCESS;
14292 }
14293
14294 static void extcommunity_list_show(struct vty *vty, struct community_list *list)
14295 {
14296 struct community_entry *entry;
14297
14298 for (entry = list->head; entry; entry = entry->next) {
14299 if (entry == list->head) {
14300 if (all_digit(list->name))
14301 vty_out(vty, "Extended community %s list %s\n",
14302 entry->style == EXTCOMMUNITY_LIST_STANDARD
14303 ? "standard"
14304 : "(expanded) access",
14305 list->name);
14306 else
14307 vty_out(vty,
14308 "Named extended community %s list %s\n",
14309 entry->style == EXTCOMMUNITY_LIST_STANDARD
14310 ? "standard"
14311 : "expanded",
14312 list->name);
14313 }
14314 if (entry->any)
14315 vty_out(vty, " %s\n",
14316 community_direct_str(entry->direct));
14317 else
14318 vty_out(vty, " %s %s\n",
14319 community_direct_str(entry->direct),
14320 community_list_config_str(entry));
14321 }
14322 }
14323
14324 DEFUN (show_ip_extcommunity_list,
14325 show_ip_extcommunity_list_cmd,
14326 "show ip extcommunity-list",
14327 SHOW_STR
14328 IP_STR
14329 "List extended-community list\n")
14330 {
14331 struct community_list *list;
14332 struct community_list_master *cm;
14333
14334 cm = community_list_master_lookup(bgp_clist, EXTCOMMUNITY_LIST_MASTER);
14335 if (!cm)
14336 return CMD_SUCCESS;
14337
14338 for (list = cm->num.head; list; list = list->next)
14339 extcommunity_list_show(vty, list);
14340
14341 for (list = cm->str.head; list; list = list->next)
14342 extcommunity_list_show(vty, list);
14343
14344 return CMD_SUCCESS;
14345 }
14346
14347 DEFUN (show_ip_extcommunity_list_arg,
14348 show_ip_extcommunity_list_arg_cmd,
14349 "show ip extcommunity-list <(1-500)|WORD>",
14350 SHOW_STR
14351 IP_STR
14352 "List extended-community list\n"
14353 "Extcommunity-list number\n"
14354 "Extcommunity-list name\n")
14355 {
14356 int idx_comm_list = 3;
14357 struct community_list *list;
14358
14359 list = community_list_lookup(bgp_clist, argv[idx_comm_list]->arg,
14360 EXTCOMMUNITY_LIST_MASTER);
14361 if (!list) {
14362 vty_out(vty, "%% Can't find extcommunity-list\n");
14363 return CMD_WARNING;
14364 }
14365
14366 extcommunity_list_show(vty, list);
14367
14368 return CMD_SUCCESS;
14369 }
14370
14371 /* Display community-list and extcommunity-list configuration. */
14372 static int community_list_config_write(struct vty *vty)
14373 {
14374 struct community_list *list;
14375 struct community_entry *entry;
14376 struct community_list_master *cm;
14377 int write = 0;
14378
14379 /* Community-list. */
14380 cm = community_list_master_lookup(bgp_clist, COMMUNITY_LIST_MASTER);
14381
14382 for (list = cm->num.head; list; list = list->next)
14383 for (entry = list->head; entry; entry = entry->next) {
14384 vty_out(vty, "ip community-list %s %s %s\n", list->name,
14385 community_direct_str(entry->direct),
14386 community_list_config_str(entry));
14387 write++;
14388 }
14389 for (list = cm->str.head; list; list = list->next)
14390 for (entry = list->head; entry; entry = entry->next) {
14391 vty_out(vty, "ip community-list %s %s %s %s\n",
14392 entry->style == COMMUNITY_LIST_STANDARD
14393 ? "standard"
14394 : "expanded",
14395 list->name, community_direct_str(entry->direct),
14396 community_list_config_str(entry));
14397 write++;
14398 }
14399
14400 /* Extcommunity-list. */
14401 cm = community_list_master_lookup(bgp_clist, EXTCOMMUNITY_LIST_MASTER);
14402
14403 for (list = cm->num.head; list; list = list->next)
14404 for (entry = list->head; entry; entry = entry->next) {
14405 vty_out(vty, "ip extcommunity-list %s %s %s\n",
14406 list->name, community_direct_str(entry->direct),
14407 community_list_config_str(entry));
14408 write++;
14409 }
14410 for (list = cm->str.head; list; list = list->next)
14411 for (entry = list->head; entry; entry = entry->next) {
14412 vty_out(vty, "ip extcommunity-list %s %s %s %s\n",
14413 entry->style == EXTCOMMUNITY_LIST_STANDARD
14414 ? "standard"
14415 : "expanded",
14416 list->name, community_direct_str(entry->direct),
14417 community_list_config_str(entry));
14418 write++;
14419 }
14420
14421
14422 /* lcommunity-list. */
14423 cm = community_list_master_lookup(bgp_clist,
14424 LARGE_COMMUNITY_LIST_MASTER);
14425
14426 for (list = cm->num.head; list; list = list->next)
14427 for (entry = list->head; entry; entry = entry->next) {
14428 vty_out(vty, "ip large-community-list %s %s %s\n",
14429 list->name, community_direct_str(entry->direct),
14430 community_list_config_str(entry));
14431 write++;
14432 }
14433 for (list = cm->str.head; list; list = list->next)
14434 for (entry = list->head; entry; entry = entry->next) {
14435 vty_out(vty, "ip large-community-list %s %s %s %s\n",
14436 entry->style == LARGE_COMMUNITY_LIST_STANDARD
14437 ? "standard"
14438 : "expanded",
14439 list->name, community_direct_str(entry->direct),
14440 community_list_config_str(entry));
14441 write++;
14442 }
14443
14444 return write;
14445 }
14446
14447 static struct cmd_node community_list_node = {
14448 COMMUNITY_LIST_NODE, "", 1 /* Export to vtysh. */
14449 };
14450
14451 static void community_list_vty(void)
14452 {
14453 install_node(&community_list_node, community_list_config_write);
14454
14455 /* Community-list. */
14456 install_element(CONFIG_NODE, &ip_community_list_standard_cmd);
14457 install_element(CONFIG_NODE, &ip_community_list_expanded_all_cmd);
14458 install_element(CONFIG_NODE, &no_ip_community_list_standard_all_cmd);
14459 install_element(CONFIG_NODE, &no_ip_community_list_expanded_all_cmd);
14460 install_element(VIEW_NODE, &show_ip_community_list_cmd);
14461 install_element(VIEW_NODE, &show_ip_community_list_arg_cmd);
14462
14463 /* Extcommunity-list. */
14464 install_element(CONFIG_NODE, &ip_extcommunity_list_standard_cmd);
14465 install_element(CONFIG_NODE, &ip_extcommunity_list_name_expanded_cmd);
14466 install_element(CONFIG_NODE, &no_ip_extcommunity_list_standard_all_cmd);
14467 install_element(CONFIG_NODE, &no_ip_extcommunity_list_expanded_all_cmd);
14468 install_element(VIEW_NODE, &show_ip_extcommunity_list_cmd);
14469 install_element(VIEW_NODE, &show_ip_extcommunity_list_arg_cmd);
14470
14471 /* Large Community List */
14472 install_element(CONFIG_NODE, &ip_lcommunity_list_standard_cmd);
14473 install_element(CONFIG_NODE, &ip_lcommunity_list_standard1_cmd);
14474 install_element(CONFIG_NODE, &ip_lcommunity_list_expanded_cmd);
14475 install_element(CONFIG_NODE, &ip_lcommunity_list_name_standard_cmd);
14476 install_element(CONFIG_NODE, &ip_lcommunity_list_name_standard1_cmd);
14477 install_element(CONFIG_NODE, &ip_lcommunity_list_name_expanded_cmd);
14478 install_element(CONFIG_NODE, &no_ip_lcommunity_list_standard_all_cmd);
14479 install_element(CONFIG_NODE,
14480 &no_ip_lcommunity_list_name_expanded_all_cmd);
14481 install_element(CONFIG_NODE, &no_ip_lcommunity_list_standard_cmd);
14482 install_element(CONFIG_NODE, &no_ip_lcommunity_list_expanded_cmd);
14483 install_element(CONFIG_NODE, &no_ip_lcommunity_list_name_standard_cmd);
14484 install_element(CONFIG_NODE, &no_ip_lcommunity_list_name_expanded_cmd);
14485 install_element(VIEW_NODE, &show_ip_lcommunity_list_cmd);
14486 install_element(VIEW_NODE, &show_ip_lcommunity_list_arg_cmd);
14487 }