]> git.proxmox.com Git - mirror_frr.git/blob - bgpd/bgp_vty.c
Merge pull request #2335 from donaldsharp/bgp_memory_hooliganism
[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
38 #include "bgpd/bgpd.h"
39 #include "bgpd/bgp_advertise.h"
40 #include "bgpd/bgp_attr.h"
41 #include "bgpd/bgp_aspath.h"
42 #include "bgpd/bgp_community.h"
43 #include "bgpd/bgp_ecommunity.h"
44 #include "bgpd/bgp_lcommunity.h"
45 #include "bgpd/bgp_damp.h"
46 #include "bgpd/bgp_debug.h"
47 #include "bgpd/bgp_fsm.h"
48 #include "bgpd/bgp_nexthop.h"
49 #include "bgpd/bgp_open.h"
50 #include "bgpd/bgp_regex.h"
51 #include "bgpd/bgp_route.h"
52 #include "bgpd/bgp_mplsvpn.h"
53 #include "bgpd/bgp_zebra.h"
54 #include "bgpd/bgp_table.h"
55 #include "bgpd/bgp_vty.h"
56 #include "bgpd/bgp_mpath.h"
57 #include "bgpd/bgp_packet.h"
58 #include "bgpd/bgp_updgrp.h"
59 #include "bgpd/bgp_bfd.h"
60 #include "bgpd/bgp_io.h"
61 #include "bgpd/bgp_evpn.h"
62
63 static struct peer_group *listen_range_exists(struct bgp *bgp,
64 struct prefix *range, int exact);
65
66 static enum node_type bgp_node_type(afi_t afi, safi_t safi)
67 {
68 switch (afi) {
69 case AFI_IP:
70 switch (safi) {
71 case SAFI_UNICAST:
72 return BGP_IPV4_NODE;
73 break;
74 case SAFI_MULTICAST:
75 return BGP_IPV4M_NODE;
76 break;
77 case SAFI_LABELED_UNICAST:
78 return BGP_IPV4L_NODE;
79 break;
80 case SAFI_MPLS_VPN:
81 return BGP_VPNV4_NODE;
82 break;
83 case SAFI_FLOWSPEC:
84 return BGP_FLOWSPECV4_NODE;
85 default:
86 /* not expected */
87 return BGP_IPV4_NODE;
88 break;
89 }
90 break;
91 case AFI_IP6:
92 switch (safi) {
93 case SAFI_UNICAST:
94 return BGP_IPV6_NODE;
95 break;
96 case SAFI_MULTICAST:
97 return BGP_IPV6M_NODE;
98 break;
99 case SAFI_LABELED_UNICAST:
100 return BGP_IPV6L_NODE;
101 break;
102 case SAFI_MPLS_VPN:
103 return BGP_VPNV6_NODE;
104 break;
105 case SAFI_FLOWSPEC:
106 return BGP_FLOWSPECV6_NODE;
107 default:
108 /* not expected */
109 return BGP_IPV4_NODE;
110 break;
111 }
112 break;
113 case AFI_L2VPN:
114 return BGP_EVPN_NODE;
115 break;
116 case AFI_MAX:
117 // We should never be here but to clarify the switch statement..
118 return BGP_IPV4_NODE;
119 break;
120 }
121
122 // Impossible to happen
123 return BGP_IPV4_NODE;
124 }
125
126 /* Utility function to get address family from current node. */
127 afi_t bgp_node_afi(struct vty *vty)
128 {
129 afi_t afi;
130 switch (vty->node) {
131 case BGP_IPV6_NODE:
132 case BGP_IPV6M_NODE:
133 case BGP_IPV6L_NODE:
134 case BGP_VPNV6_NODE:
135 case BGP_FLOWSPECV6_NODE:
136 afi = AFI_IP6;
137 break;
138 case BGP_EVPN_NODE:
139 afi = AFI_L2VPN;
140 break;
141 default:
142 afi = AFI_IP;
143 break;
144 }
145 return afi;
146 }
147
148 /* Utility function to get subsequent address family from current
149 node. */
150 safi_t bgp_node_safi(struct vty *vty)
151 {
152 safi_t safi;
153 switch (vty->node) {
154 case BGP_VPNV4_NODE:
155 case BGP_VPNV6_NODE:
156 safi = SAFI_MPLS_VPN;
157 break;
158 case BGP_IPV4M_NODE:
159 case BGP_IPV6M_NODE:
160 safi = SAFI_MULTICAST;
161 break;
162 case BGP_EVPN_NODE:
163 safi = SAFI_EVPN;
164 break;
165 case BGP_IPV4L_NODE:
166 case BGP_IPV6L_NODE:
167 safi = SAFI_LABELED_UNICAST;
168 break;
169 case BGP_FLOWSPECV4_NODE:
170 case BGP_FLOWSPECV6_NODE:
171 safi = SAFI_FLOWSPEC;
172 break;
173 default:
174 safi = SAFI_UNICAST;
175 break;
176 }
177 return safi;
178 }
179
180 /**
181 * Converts an AFI in string form to afi_t
182 *
183 * @param afi string, one of
184 * - "ipv4"
185 * - "ipv6"
186 * @return the corresponding afi_t
187 */
188 afi_t bgp_vty_afi_from_str(const char *afi_str)
189 {
190 afi_t afi = AFI_MAX; /* unknown */
191 if (strmatch(afi_str, "ipv4"))
192 afi = AFI_IP;
193 else if (strmatch(afi_str, "ipv6"))
194 afi = AFI_IP6;
195 return afi;
196 }
197
198 int argv_find_and_parse_afi(struct cmd_token **argv, int argc, int *index,
199 afi_t *afi)
200 {
201 int ret = 0;
202 if (argv_find(argv, argc, "ipv4", index)) {
203 ret = 1;
204 if (afi)
205 *afi = AFI_IP;
206 } else if (argv_find(argv, argc, "ipv6", index)) {
207 ret = 1;
208 if (afi)
209 *afi = AFI_IP6;
210 }
211 return ret;
212 }
213
214 /* supports <unicast|multicast|vpn|labeled-unicast> */
215 safi_t bgp_vty_safi_from_str(const char *safi_str)
216 {
217 safi_t safi = SAFI_MAX; /* unknown */
218 if (strmatch(safi_str, "multicast"))
219 safi = SAFI_MULTICAST;
220 else if (strmatch(safi_str, "unicast"))
221 safi = SAFI_UNICAST;
222 else if (strmatch(safi_str, "vpn"))
223 safi = SAFI_MPLS_VPN;
224 else if (strmatch(safi_str, "labeled-unicast"))
225 safi = SAFI_LABELED_UNICAST;
226 else if (strmatch(safi_str, "flowspec"))
227 safi = SAFI_FLOWSPEC;
228 return safi;
229 }
230
231 int argv_find_and_parse_safi(struct cmd_token **argv, int argc, int *index,
232 safi_t *safi)
233 {
234 int ret = 0;
235 if (argv_find(argv, argc, "unicast", index)) {
236 ret = 1;
237 if (safi)
238 *safi = SAFI_UNICAST;
239 } else if (argv_find(argv, argc, "multicast", index)) {
240 ret = 1;
241 if (safi)
242 *safi = SAFI_MULTICAST;
243 } else if (argv_find(argv, argc, "labeled-unicast", index)) {
244 ret = 1;
245 if (safi)
246 *safi = SAFI_LABELED_UNICAST;
247 } else if (argv_find(argv, argc, "vpn", index)) {
248 ret = 1;
249 if (safi)
250 *safi = SAFI_MPLS_VPN;
251 } else if (argv_find(argv, argc, "flowspec", index)) {
252 ret = 1;
253 if (safi)
254 *safi = SAFI_FLOWSPEC;
255 }
256 return ret;
257 }
258
259 /*
260 * bgp_vty_find_and_parse_afi_safi_bgp
261 *
262 * For a given 'show ...' command, correctly parse the afi/safi/bgp out from it
263 * This function *assumes* that the calling function pre-sets the afi/safi/bgp
264 * to appropriate values for the calling function. This is to allow the
265 * calling function to make decisions appropriate for the show command
266 * that is being parsed.
267 *
268 * The show commands are generally of the form:
269 * "show [ip] bgp [<view|vrf> VIEWVRFNAME] [<ipv4|ipv6>
270 * [<unicast|multicast|vpn|labeled-unicast>]] ..."
271 *
272 * Since we use argv_find if the show command in particular doesn't have:
273 * [ip]
274 * [<view|vrf> VIEWVRFNAME]
275 * [<ipv4|ipv6> [<unicast|multicast|vpn|labeled-unicast>]]
276 * The command parsing should still be ok.
277 *
278 * vty -> The vty for the command so we can output some useful data in
279 * the event of a parse error in the vrf.
280 * argv -> The command tokens
281 * argc -> How many command tokens we have
282 * idx -> The current place in the command, generally should be 0 for this
283 * function
284 * afi -> The parsed afi if it was included in the show command, returned here
285 * safi -> The parsed safi if it was included in the show command, returned here
286 * bgp -> Pointer to the bgp data structure we need to fill in.
287 *
288 * The function returns the correct location in the parse tree for the
289 * last token found.
290 *
291 * Returns 0 for failure to parse correctly, else the idx position of where
292 * it found the last token.
293 */
294 int bgp_vty_find_and_parse_afi_safi_bgp(struct vty *vty,
295 struct cmd_token **argv, int argc,
296 int *idx, afi_t *afi, safi_t *safi,
297 struct bgp **bgp)
298 {
299 char *vrf_name = NULL;
300
301 assert(afi);
302 assert(safi);
303 assert(bgp);
304
305 if (argv_find(argv, argc, "ip", idx))
306 *afi = AFI_IP;
307
308 if (argv_find(argv, argc, "view", idx)
309 || argv_find(argv, argc, "vrf", idx)) {
310 vrf_name = argv[*idx + 1]->arg;
311
312 if (strmatch(vrf_name, "all"))
313 *bgp = NULL;
314 else {
315 *bgp = bgp_lookup_by_name(vrf_name);
316 if (!*bgp) {
317 vty_out(vty,
318 "View/Vrf specified is unknown: %s\n",
319 vrf_name);
320 *idx = 0;
321 return 0;
322 }
323 }
324 } else {
325 *bgp = bgp_get_default();
326 if (!*bgp) {
327 vty_out(vty, "Unable to find default BGP instance\n");
328 *idx = 0;
329 return 0;
330 }
331 }
332
333 if (argv_find_and_parse_afi(argv, argc, idx, afi))
334 argv_find_and_parse_safi(argv, argc, idx, safi);
335
336 *idx += 1;
337 return *idx;
338 }
339
340 static int peer_address_self_check(struct bgp *bgp, union sockunion *su)
341 {
342 struct interface *ifp = NULL;
343
344 if (su->sa.sa_family == AF_INET)
345 ifp = if_lookup_by_ipv4_exact(&su->sin.sin_addr, bgp->vrf_id);
346 else if (su->sa.sa_family == AF_INET6)
347 ifp = if_lookup_by_ipv6_exact(&su->sin6.sin6_addr,
348 su->sin6.sin6_scope_id,
349 bgp->vrf_id);
350
351 if (ifp)
352 return 1;
353
354 return 0;
355 }
356
357 /* Utility function for looking up peer from VTY. */
358 /* This is used only for configuration, so disallow if attempted on
359 * a dynamic neighbor.
360 */
361 static struct peer *peer_lookup_vty(struct vty *vty, const char *ip_str)
362 {
363 struct bgp *bgp = VTY_GET_CONTEXT(bgp);
364 int ret;
365 union sockunion su;
366 struct peer *peer;
367
368 if (!bgp) {
369 return NULL;
370 }
371
372 ret = str2sockunion(ip_str, &su);
373 if (ret < 0) {
374 peer = peer_lookup_by_conf_if(bgp, ip_str);
375 if (!peer) {
376 if ((peer = peer_lookup_by_hostname(bgp, ip_str))
377 == NULL) {
378 vty_out(vty,
379 "%% Malformed address or name: %s\n",
380 ip_str);
381 return NULL;
382 }
383 }
384 } else {
385 peer = peer_lookup(bgp, &su);
386 if (!peer) {
387 vty_out(vty,
388 "%% Specify remote-as or peer-group commands first\n");
389 return NULL;
390 }
391 if (peer_dynamic_neighbor(peer)) {
392 vty_out(vty,
393 "%% Operation not allowed on a dynamic neighbor\n");
394 return NULL;
395 }
396 }
397 return peer;
398 }
399
400 /* Utility function for looking up peer or peer group. */
401 /* This is used only for configuration, so disallow if attempted on
402 * a dynamic neighbor.
403 */
404 struct peer *peer_and_group_lookup_vty(struct vty *vty, const char *peer_str)
405 {
406 struct bgp *bgp = VTY_GET_CONTEXT(bgp);
407 int ret;
408 union sockunion su;
409 struct peer *peer = NULL;
410 struct peer_group *group = NULL;
411
412 if (!bgp) {
413 return NULL;
414 }
415
416 ret = str2sockunion(peer_str, &su);
417 if (ret == 0) {
418 /* IP address, locate peer. */
419 peer = peer_lookup(bgp, &su);
420 } else {
421 /* Not IP, could match either peer configured on interface or a
422 * group. */
423 peer = peer_lookup_by_conf_if(bgp, peer_str);
424 if (!peer)
425 group = peer_group_lookup(bgp, peer_str);
426 }
427
428 if (peer) {
429 if (peer_dynamic_neighbor(peer)) {
430 vty_out(vty,
431 "%% Operation not allowed on a dynamic neighbor\n");
432 return NULL;
433 }
434
435 return peer;
436 }
437
438 if (group)
439 return group->conf;
440
441 vty_out(vty, "%% Specify remote-as or peer-group commands first\n");
442
443 return NULL;
444 }
445
446 int bgp_vty_return(struct vty *vty, int ret)
447 {
448 const char *str = NULL;
449
450 switch (ret) {
451 case BGP_ERR_INVALID_VALUE:
452 str = "Invalid value";
453 break;
454 case BGP_ERR_INVALID_FLAG:
455 str = "Invalid flag";
456 break;
457 case BGP_ERR_PEER_GROUP_SHUTDOWN:
458 str = "Peer-group has been shutdown. Activate the peer-group first";
459 break;
460 case BGP_ERR_PEER_FLAG_CONFLICT:
461 str = "Can't set override-capability and strict-capability-match at the same time";
462 break;
463 case BGP_ERR_PEER_GROUP_NO_REMOTE_AS:
464 str = "Specify remote-as or peer-group remote AS first";
465 break;
466 case BGP_ERR_PEER_GROUP_CANT_CHANGE:
467 str = "Cannot change the peer-group. Deconfigure first";
468 break;
469 case BGP_ERR_PEER_GROUP_MISMATCH:
470 str = "Peer is not a member of this peer-group";
471 break;
472 case BGP_ERR_PEER_FILTER_CONFLICT:
473 str = "Prefix/distribute list can not co-exist";
474 break;
475 case BGP_ERR_NOT_INTERNAL_PEER:
476 str = "Invalid command. Not an internal neighbor";
477 break;
478 case BGP_ERR_REMOVE_PRIVATE_AS:
479 str = "remove-private-AS cannot be configured for IBGP peers";
480 break;
481 case BGP_ERR_LOCAL_AS_ALLOWED_ONLY_FOR_EBGP:
482 str = "Local-AS allowed only for EBGP peers";
483 break;
484 case BGP_ERR_CANNOT_HAVE_LOCAL_AS_SAME_AS:
485 str = "Cannot have local-as same as BGP AS number";
486 break;
487 case BGP_ERR_TCPSIG_FAILED:
488 str = "Error while applying TCP-Sig to session(s)";
489 break;
490 case BGP_ERR_NO_EBGP_MULTIHOP_WITH_TTLHACK:
491 str = "ebgp-multihop and ttl-security cannot be configured together";
492 break;
493 case BGP_ERR_NO_IBGP_WITH_TTLHACK:
494 str = "ttl-security only allowed for EBGP peers";
495 break;
496 case BGP_ERR_AS_OVERRIDE:
497 str = "as-override cannot be configured for IBGP peers";
498 break;
499 case BGP_ERR_INVALID_DYNAMIC_NEIGHBORS_LIMIT:
500 str = "Invalid limit for number of dynamic neighbors";
501 break;
502 case BGP_ERR_DYNAMIC_NEIGHBORS_RANGE_EXISTS:
503 str = "Dynamic neighbor listen range already exists";
504 break;
505 case BGP_ERR_INVALID_FOR_DYNAMIC_PEER:
506 str = "Operation not allowed on a dynamic neighbor";
507 break;
508 case BGP_ERR_INVALID_FOR_DIRECT_PEER:
509 str = "Operation not allowed on a directly connected neighbor";
510 break;
511 case BGP_ERR_PEER_SAFI_CONFLICT:
512 str = "Cannot activate peer for both 'ipv4 unicast' and 'ipv4 labeled-unicast'";
513 break;
514 }
515 if (str) {
516 vty_out(vty, "%% %s\n", str);
517 return CMD_WARNING_CONFIG_FAILED;
518 }
519 return CMD_SUCCESS;
520 }
521
522 /* BGP clear sort. */
523 enum clear_sort {
524 clear_all,
525 clear_peer,
526 clear_group,
527 clear_external,
528 clear_as
529 };
530
531 static void bgp_clear_vty_error(struct vty *vty, struct peer *peer, afi_t afi,
532 safi_t safi, int error)
533 {
534 switch (error) {
535 case BGP_ERR_AF_UNCONFIGURED:
536 vty_out(vty,
537 "%%BGP: Enable %s address family for the neighbor %s\n",
538 afi_safi_print(afi, safi), peer->host);
539 break;
540 case BGP_ERR_SOFT_RECONFIG_UNCONFIGURED:
541 vty_out(vty,
542 "%%BGP: Inbound soft reconfig for %s not possible as it\n has neither refresh capability, nor inbound soft reconfig\n",
543 peer->host);
544 break;
545 default:
546 break;
547 }
548 }
549
550 /* `clear ip bgp' functions. */
551 static int bgp_clear(struct vty *vty, struct bgp *bgp, afi_t afi, safi_t safi,
552 enum clear_sort sort, enum bgp_clear_type stype,
553 const char *arg)
554 {
555 int ret;
556 bool found = false;
557 struct peer *peer;
558 struct listnode *node, *nnode;
559
560 /* Clear all neighbors. */
561 /*
562 * Pass along pointer to next node to peer_clear() when walking all
563 * nodes on the BGP instance as that may get freed if it is a
564 * doppelganger
565 */
566 if (sort == clear_all) {
567 for (ALL_LIST_ELEMENTS(bgp->peer, node, nnode, peer)) {
568 if (!peer->afc[afi][safi])
569 continue;
570
571 if (stype == BGP_CLEAR_SOFT_NONE)
572 ret = peer_clear(peer, &nnode);
573 else
574 ret = peer_clear_soft(peer, afi, safi, stype);
575
576 if (ret < 0)
577 bgp_clear_vty_error(vty, peer, afi, safi, ret);
578 else
579 found = true;
580 }
581
582 /* This is to apply read-only mode on this clear. */
583 if (stype == BGP_CLEAR_SOFT_NONE)
584 bgp->update_delay_over = 0;
585
586 if (!found)
587 vty_out(vty, "%%BGP: No %s peer configured",
588 afi_safi_print(afi, safi));
589
590 return CMD_SUCCESS;
591 }
592
593 /* Clear specified neighbor. */
594 if (sort == clear_peer) {
595 union sockunion su;
596
597 /* Make sockunion for lookup. */
598 ret = str2sockunion(arg, &su);
599 if (ret < 0) {
600 peer = peer_lookup_by_conf_if(bgp, arg);
601 if (!peer) {
602 peer = peer_lookup_by_hostname(bgp, arg);
603 if (!peer) {
604 vty_out(vty,
605 "Malformed address or name: %s\n",
606 arg);
607 return CMD_WARNING;
608 }
609 }
610 } else {
611 peer = peer_lookup(bgp, &su);
612 if (!peer) {
613 vty_out(vty,
614 "%%BGP: Unknown neighbor - \"%s\"\n",
615 arg);
616 return CMD_WARNING;
617 }
618 }
619
620 if (!peer->afc[afi][safi])
621 ret = BGP_ERR_AF_UNCONFIGURED;
622 else if (stype == BGP_CLEAR_SOFT_NONE)
623 ret = peer_clear(peer, NULL);
624 else
625 ret = peer_clear_soft(peer, afi, safi, stype);
626
627 if (ret < 0)
628 bgp_clear_vty_error(vty, peer, afi, safi, ret);
629
630 return CMD_SUCCESS;
631 }
632
633 /* Clear all neighbors belonging to a specific peer-group. */
634 if (sort == clear_group) {
635 struct peer_group *group;
636
637 group = peer_group_lookup(bgp, arg);
638 if (!group) {
639 vty_out(vty, "%%BGP: No such peer-group %s\n", arg);
640 return CMD_WARNING;
641 }
642
643 for (ALL_LIST_ELEMENTS(group->peer, node, nnode, peer)) {
644 if (!peer->afc[afi][safi])
645 continue;
646
647 if (stype == BGP_CLEAR_SOFT_NONE)
648 ret = peer_clear(peer, NULL);
649 else
650 ret = peer_clear_soft(peer, afi, safi, stype);
651
652 if (ret < 0)
653 bgp_clear_vty_error(vty, peer, afi, safi, ret);
654 else
655 found = true;
656 }
657
658 if (!found)
659 vty_out(vty,
660 "%%BGP: No %s peer belonging to peer-group %s is configured\n",
661 afi_safi_print(afi, safi), arg);
662
663 return CMD_SUCCESS;
664 }
665
666 /* Clear all external (eBGP) neighbors. */
667 if (sort == clear_external) {
668 for (ALL_LIST_ELEMENTS(bgp->peer, node, nnode, peer)) {
669 if (peer->sort == BGP_PEER_IBGP)
670 continue;
671
672 if (!peer->afc[afi][safi])
673 continue;
674
675 if (stype == BGP_CLEAR_SOFT_NONE)
676 ret = peer_clear(peer, &nnode);
677 else
678 ret = peer_clear_soft(peer, afi, safi, stype);
679
680 if (ret < 0)
681 bgp_clear_vty_error(vty, peer, afi, safi, ret);
682 else
683 found = true;
684 }
685
686 if (!found)
687 vty_out(vty,
688 "%%BGP: No external %s peer is configured\n",
689 afi_safi_print(afi, safi));
690
691 return CMD_SUCCESS;
692 }
693
694 /* Clear all neighbors belonging to a specific AS. */
695 if (sort == clear_as) {
696 as_t as = strtoul(arg, NULL, 10);
697
698 for (ALL_LIST_ELEMENTS(bgp->peer, node, nnode, peer)) {
699 if (peer->as != as)
700 continue;
701
702 if (!peer->afc[afi][safi])
703 ret = BGP_ERR_AF_UNCONFIGURED;
704 else if (stype == BGP_CLEAR_SOFT_NONE)
705 ret = peer_clear(peer, &nnode);
706 else
707 ret = peer_clear_soft(peer, afi, safi, stype);
708
709 if (ret < 0)
710 bgp_clear_vty_error(vty, peer, afi, safi, ret);
711 else
712 found = true;
713 }
714
715 if (!found)
716 vty_out(vty,
717 "%%BGP: No %s peer is configured with AS %s\n",
718 afi_safi_print(afi, safi), arg);
719
720 return CMD_SUCCESS;
721 }
722
723 return CMD_SUCCESS;
724 }
725
726 static int bgp_clear_vty(struct vty *vty, const char *name, afi_t afi,
727 safi_t safi, enum clear_sort sort,
728 enum bgp_clear_type stype, const char *arg)
729 {
730 struct bgp *bgp;
731
732 /* BGP structure lookup. */
733 if (name) {
734 bgp = bgp_lookup_by_name(name);
735 if (bgp == NULL) {
736 vty_out(vty, "Can't find BGP instance %s\n", name);
737 return CMD_WARNING;
738 }
739 } else {
740 bgp = bgp_get_default();
741 if (bgp == NULL) {
742 vty_out(vty, "No BGP process is configured\n");
743 return CMD_WARNING;
744 }
745 }
746
747 return bgp_clear(vty, bgp, afi, safi, sort, stype, arg);
748 }
749
750 /* clear soft inbound */
751 static void bgp_clear_star_soft_in(struct vty *vty, const char *name)
752 {
753 bgp_clear_vty(vty, name, AFI_IP, SAFI_UNICAST, clear_all,
754 BGP_CLEAR_SOFT_IN, NULL);
755 bgp_clear_vty(vty, name, AFI_IP6, SAFI_UNICAST, clear_all,
756 BGP_CLEAR_SOFT_IN, NULL);
757 }
758
759 /* clear soft outbound */
760 static void bgp_clear_star_soft_out(struct vty *vty, const char *name)
761 {
762 bgp_clear_vty(vty, name, AFI_IP, SAFI_UNICAST, clear_all,
763 BGP_CLEAR_SOFT_OUT, NULL);
764 bgp_clear_vty(vty, name, AFI_IP6, SAFI_UNICAST, clear_all,
765 BGP_CLEAR_SOFT_OUT, NULL);
766 }
767
768
769 #ifndef VTYSH_EXTRACT_PL
770 #include "bgpd/bgp_vty_clippy.c"
771 #endif
772
773 /* BGP global configuration. */
774 #if defined(VERSION_TYPE_DEV) && (CONFDATE > 20190601)
775 CPP_NOTICE("bgpd: time to remove deprecated bgp multiple-instance")
776 CPP_NOTICE("This includes BGP_OPT_MULTIPLE_INSTANCE")
777 #endif
778 DEFUN_HIDDEN (bgp_multiple_instance_func,
779 bgp_multiple_instance_cmd,
780 "bgp multiple-instance",
781 BGP_STR
782 "Enable bgp multiple instance\n")
783 {
784 bgp_option_set(BGP_OPT_MULTIPLE_INSTANCE);
785 return CMD_SUCCESS;
786 }
787
788 DEFUN_HIDDEN (no_bgp_multiple_instance,
789 no_bgp_multiple_instance_cmd,
790 "no bgp multiple-instance",
791 NO_STR
792 BGP_STR
793 "BGP multiple instance\n")
794 {
795 int ret;
796
797 vty_out(vty, "This config option is deprecated, and is scheduled for removal.\n");
798 vty_out(vty, "if you are using this please let the developers know\n");
799 zlog_warn("Deprecated option: `bgp multiple-instance` being used");
800 ret = bgp_option_unset(BGP_OPT_MULTIPLE_INSTANCE);
801 if (ret < 0) {
802 vty_out(vty, "%% There are more than two BGP instances\n");
803 return CMD_WARNING_CONFIG_FAILED;
804 }
805 return CMD_SUCCESS;
806 }
807
808 #if defined(VERSION_TYPE_DEV) && (CONFDATE > 20190601)
809 CPP_NOTICE("bgpd: time to remove deprecated cli bgp config-type cisco")
810 CPP_NOTICE("This includes BGP_OPT_CISCO_CONFIG")
811 #endif
812 DEFUN_HIDDEN (bgp_config_type,
813 bgp_config_type_cmd,
814 "bgp config-type <cisco|zebra>",
815 BGP_STR
816 "Configuration type\n"
817 "cisco\n"
818 "zebra\n")
819 {
820 int idx = 0;
821 if (argv_find(argv, argc, "cisco", &idx)) {
822 vty_out(vty, "This config option is deprecated, and is scheduled for removal.\n");
823 vty_out(vty, "if you are using this please let the developers know!\n");
824 zlog_warn("Deprecated option: `bgp config-type cisco` being used");
825 bgp_option_set(BGP_OPT_CONFIG_CISCO);
826 } else
827 bgp_option_unset(BGP_OPT_CONFIG_CISCO);
828
829 return CMD_SUCCESS;
830 }
831
832 DEFUN_HIDDEN (no_bgp_config_type,
833 no_bgp_config_type_cmd,
834 "no bgp config-type [<cisco|zebra>]",
835 NO_STR
836 BGP_STR
837 "Display configuration type\n"
838 "cisco\n"
839 "zebra\n")
840 {
841 bgp_option_unset(BGP_OPT_CONFIG_CISCO);
842 return CMD_SUCCESS;
843 }
844
845
846 DEFUN (no_synchronization,
847 no_synchronization_cmd,
848 "no synchronization",
849 NO_STR
850 "Perform IGP synchronization\n")
851 {
852 return CMD_SUCCESS;
853 }
854
855 DEFUN (no_auto_summary,
856 no_auto_summary_cmd,
857 "no auto-summary",
858 NO_STR
859 "Enable automatic network number summarization\n")
860 {
861 return CMD_SUCCESS;
862 }
863
864 /* "router bgp" commands. */
865 DEFUN_NOSH (router_bgp,
866 router_bgp_cmd,
867 "router bgp [(1-4294967295) [<view|vrf> VIEWVRFNAME]]",
868 ROUTER_STR
869 BGP_STR
870 AS_STR
871 BGP_INSTANCE_HELP_STR)
872 {
873 int idx_asn = 2;
874 int idx_view_vrf = 3;
875 int idx_vrf = 4;
876 int ret;
877 as_t as;
878 struct bgp *bgp;
879 const char *name = NULL;
880 enum bgp_instance_type inst_type;
881
882 // "router bgp" without an ASN
883 if (argc == 2) {
884 // Pending: Make VRF option available for ASN less config
885 bgp = bgp_get_default();
886
887 if (bgp == NULL) {
888 vty_out(vty, "%% No BGP process is configured\n");
889 return CMD_WARNING_CONFIG_FAILED;
890 }
891
892 if (listcount(bm->bgp) > 1) {
893 vty_out(vty, "%% Please specify ASN and VRF\n");
894 return CMD_WARNING_CONFIG_FAILED;
895 }
896 }
897
898 // "router bgp X"
899 else {
900 as = strtoul(argv[idx_asn]->arg, NULL, 10);
901
902 inst_type = BGP_INSTANCE_TYPE_DEFAULT;
903 if (argc > 3) {
904 name = argv[idx_vrf]->arg;
905
906 if (!strcmp(argv[idx_view_vrf]->text, "vrf"))
907 inst_type = BGP_INSTANCE_TYPE_VRF;
908 else if (!strcmp(argv[idx_view_vrf]->text, "view"))
909 inst_type = BGP_INSTANCE_TYPE_VIEW;
910 }
911
912 ret = bgp_get(&bgp, &as, name, inst_type);
913 switch (ret) {
914 case BGP_ERR_MULTIPLE_INSTANCE_NOT_SET:
915 vty_out(vty,
916 "Please specify 'bgp multiple-instance' first\n");
917 return CMD_WARNING_CONFIG_FAILED;
918 case BGP_ERR_AS_MISMATCH:
919 vty_out(vty, "BGP is already running; AS is %u\n", as);
920 return CMD_WARNING_CONFIG_FAILED;
921 case BGP_ERR_INSTANCE_MISMATCH:
922 vty_out(vty,
923 "BGP instance name and AS number mismatch\n");
924 vty_out(vty,
925 "BGP instance is already running; AS is %u\n",
926 as);
927 return CMD_WARNING_CONFIG_FAILED;
928 }
929
930 /* Pending: handle when user tries to change a view to vrf n vv.
931 */
932 }
933
934 /* unset the auto created flag as the user config is now present */
935 UNSET_FLAG(bgp->vrf_flags, BGP_VRF_AUTO);
936 VTY_PUSH_CONTEXT(BGP_NODE, bgp);
937
938 return CMD_SUCCESS;
939 }
940
941 /* "no router bgp" commands. */
942 DEFUN (no_router_bgp,
943 no_router_bgp_cmd,
944 "no router bgp [(1-4294967295) [<view|vrf> VIEWVRFNAME]]",
945 NO_STR
946 ROUTER_STR
947 BGP_STR
948 AS_STR
949 BGP_INSTANCE_HELP_STR)
950 {
951 int idx_asn = 3;
952 int idx_vrf = 5;
953 as_t as;
954 struct bgp *bgp;
955 const char *name = NULL;
956
957 // "no router bgp" without an ASN
958 if (argc == 3) {
959 // Pending: Make VRF option available for ASN less config
960 bgp = bgp_get_default();
961
962 if (bgp == NULL) {
963 vty_out(vty, "%% No BGP process is configured\n");
964 return CMD_WARNING_CONFIG_FAILED;
965 }
966
967 if (listcount(bm->bgp) > 1) {
968 vty_out(vty, "%% Please specify ASN and VRF\n");
969 return CMD_WARNING_CONFIG_FAILED;
970 }
971
972 if (bgp->l3vni) {
973 vty_out(vty, "%% Please unconfigure l3vni %u",
974 bgp->l3vni);
975 return CMD_WARNING_CONFIG_FAILED;
976 }
977 } else {
978 as = strtoul(argv[idx_asn]->arg, NULL, 10);
979
980 if (argc > 4)
981 name = argv[idx_vrf]->arg;
982
983 /* Lookup bgp structure. */
984 bgp = bgp_lookup(as, name);
985 if (!bgp) {
986 vty_out(vty, "%% Can't find BGP instance\n");
987 return CMD_WARNING_CONFIG_FAILED;
988 }
989
990 if (bgp->l3vni) {
991 vty_out(vty, "%% Please unconfigure l3vni %u",
992 bgp->l3vni);
993 return CMD_WARNING_CONFIG_FAILED;
994 }
995 }
996
997 bgp_delete(bgp);
998
999 return CMD_SUCCESS;
1000 }
1001
1002
1003 /* BGP router-id. */
1004
1005 DEFPY (bgp_router_id,
1006 bgp_router_id_cmd,
1007 "bgp router-id A.B.C.D",
1008 BGP_STR
1009 "Override configured router identifier\n"
1010 "Manually configured router identifier\n")
1011 {
1012 VTY_DECLVAR_CONTEXT(bgp, bgp);
1013 bgp_router_id_static_set(bgp, router_id);
1014 return CMD_SUCCESS;
1015 }
1016
1017 DEFPY (no_bgp_router_id,
1018 no_bgp_router_id_cmd,
1019 "no bgp router-id [A.B.C.D]",
1020 NO_STR
1021 BGP_STR
1022 "Override configured router identifier\n"
1023 "Manually configured router identifier\n")
1024 {
1025 VTY_DECLVAR_CONTEXT(bgp, bgp);
1026
1027 if (router_id_str) {
1028 if (!IPV4_ADDR_SAME(&bgp->router_id_static, &router_id)) {
1029 vty_out(vty, "%% BGP router-id doesn't match\n");
1030 return CMD_WARNING_CONFIG_FAILED;
1031 }
1032 }
1033
1034 router_id.s_addr = 0;
1035 bgp_router_id_static_set(bgp, router_id);
1036
1037 return CMD_SUCCESS;
1038 }
1039
1040
1041 /* BGP Cluster ID. */
1042 DEFUN (bgp_cluster_id,
1043 bgp_cluster_id_cmd,
1044 "bgp cluster-id <A.B.C.D|(1-4294967295)>",
1045 BGP_STR
1046 "Configure Route-Reflector Cluster-id\n"
1047 "Route-Reflector Cluster-id in IP address format\n"
1048 "Route-Reflector Cluster-id as 32 bit quantity\n")
1049 {
1050 VTY_DECLVAR_CONTEXT(bgp, bgp);
1051 int idx_ipv4 = 2;
1052 int ret;
1053 struct in_addr cluster;
1054
1055 ret = inet_aton(argv[idx_ipv4]->arg, &cluster);
1056 if (!ret) {
1057 vty_out(vty, "%% Malformed bgp cluster identifier\n");
1058 return CMD_WARNING_CONFIG_FAILED;
1059 }
1060
1061 bgp_cluster_id_set(bgp, &cluster);
1062 bgp_clear_star_soft_out(vty, bgp->name);
1063
1064 return CMD_SUCCESS;
1065 }
1066
1067 DEFUN (no_bgp_cluster_id,
1068 no_bgp_cluster_id_cmd,
1069 "no bgp cluster-id [<A.B.C.D|(1-4294967295)>]",
1070 NO_STR
1071 BGP_STR
1072 "Configure Route-Reflector Cluster-id\n"
1073 "Route-Reflector Cluster-id in IP address format\n"
1074 "Route-Reflector Cluster-id as 32 bit quantity\n")
1075 {
1076 VTY_DECLVAR_CONTEXT(bgp, bgp);
1077 bgp_cluster_id_unset(bgp);
1078 bgp_clear_star_soft_out(vty, bgp->name);
1079
1080 return CMD_SUCCESS;
1081 }
1082
1083 DEFUN (bgp_confederation_identifier,
1084 bgp_confederation_identifier_cmd,
1085 "bgp confederation identifier (1-4294967295)",
1086 "BGP specific commands\n"
1087 "AS confederation parameters\n"
1088 "AS number\n"
1089 "Set routing domain confederation AS\n")
1090 {
1091 VTY_DECLVAR_CONTEXT(bgp, bgp);
1092 int idx_number = 3;
1093 as_t as;
1094
1095 as = strtoul(argv[idx_number]->arg, NULL, 10);
1096
1097 bgp_confederation_id_set(bgp, as);
1098
1099 return CMD_SUCCESS;
1100 }
1101
1102 DEFUN (no_bgp_confederation_identifier,
1103 no_bgp_confederation_identifier_cmd,
1104 "no bgp confederation identifier [(1-4294967295)]",
1105 NO_STR
1106 "BGP specific commands\n"
1107 "AS confederation parameters\n"
1108 "AS number\n"
1109 "Set routing domain confederation AS\n")
1110 {
1111 VTY_DECLVAR_CONTEXT(bgp, bgp);
1112 bgp_confederation_id_unset(bgp);
1113
1114 return CMD_SUCCESS;
1115 }
1116
1117 DEFUN (bgp_confederation_peers,
1118 bgp_confederation_peers_cmd,
1119 "bgp confederation peers (1-4294967295)...",
1120 "BGP specific commands\n"
1121 "AS confederation parameters\n"
1122 "Peer ASs in BGP confederation\n"
1123 AS_STR)
1124 {
1125 VTY_DECLVAR_CONTEXT(bgp, bgp);
1126 int idx_asn = 3;
1127 as_t as;
1128 int i;
1129
1130 for (i = idx_asn; i < argc; i++) {
1131 as = strtoul(argv[i]->arg, NULL, 10);
1132
1133 if (bgp->as == as) {
1134 vty_out(vty,
1135 "%% Local member-AS not allowed in confed peer list\n");
1136 continue;
1137 }
1138
1139 bgp_confederation_peers_add(bgp, as);
1140 }
1141 return CMD_SUCCESS;
1142 }
1143
1144 DEFUN (no_bgp_confederation_peers,
1145 no_bgp_confederation_peers_cmd,
1146 "no bgp confederation peers (1-4294967295)...",
1147 NO_STR
1148 "BGP specific commands\n"
1149 "AS confederation parameters\n"
1150 "Peer ASs in BGP confederation\n"
1151 AS_STR)
1152 {
1153 VTY_DECLVAR_CONTEXT(bgp, bgp);
1154 int idx_asn = 4;
1155 as_t as;
1156 int i;
1157
1158 for (i = idx_asn; i < argc; i++) {
1159 as = strtoul(argv[i]->arg, NULL, 10);
1160
1161 bgp_confederation_peers_remove(bgp, as);
1162 }
1163 return CMD_SUCCESS;
1164 }
1165
1166 /**
1167 * Central routine for maximum-paths configuration.
1168 * @peer_type: BGP_PEER_EBGP or BGP_PEER_IBGP
1169 * @set: 1 for setting values, 0 for removing the max-paths config.
1170 */
1171 static int bgp_maxpaths_config_vty(struct vty *vty, int peer_type,
1172 const char *mpaths, uint16_t options,
1173 int set)
1174 {
1175 VTY_DECLVAR_CONTEXT(bgp, bgp);
1176 uint16_t maxpaths = 0;
1177 int ret;
1178 afi_t afi;
1179 safi_t safi;
1180
1181 afi = bgp_node_afi(vty);
1182 safi = bgp_node_safi(vty);
1183
1184 if (set) {
1185 maxpaths = strtol(mpaths, NULL, 10);
1186 if (maxpaths > multipath_num) {
1187 vty_out(vty,
1188 "%% Maxpaths Specified: %d is > than multipath num specified on bgp command line %d",
1189 maxpaths, multipath_num);
1190 return CMD_WARNING_CONFIG_FAILED;
1191 }
1192 ret = bgp_maximum_paths_set(bgp, afi, safi, peer_type, maxpaths,
1193 options);
1194 } else
1195 ret = bgp_maximum_paths_unset(bgp, afi, safi, peer_type);
1196
1197 if (ret < 0) {
1198 vty_out(vty,
1199 "%% Failed to %sset maximum-paths %s %u for afi %u, safi %u\n",
1200 (set == 1) ? "" : "un",
1201 (peer_type == BGP_PEER_EBGP) ? "ebgp" : "ibgp",
1202 maxpaths, afi, safi);
1203 return CMD_WARNING_CONFIG_FAILED;
1204 }
1205
1206 bgp_recalculate_all_bestpaths(bgp);
1207
1208 return CMD_SUCCESS;
1209 }
1210
1211 DEFUN (bgp_maxmed_admin,
1212 bgp_maxmed_admin_cmd,
1213 "bgp max-med administrative ",
1214 BGP_STR
1215 "Advertise routes with max-med\n"
1216 "Administratively applied, for an indefinite period\n")
1217 {
1218 VTY_DECLVAR_CONTEXT(bgp, bgp);
1219
1220 bgp->v_maxmed_admin = 1;
1221 bgp->maxmed_admin_value = BGP_MAXMED_VALUE_DEFAULT;
1222
1223 bgp_maxmed_update(bgp);
1224
1225 return CMD_SUCCESS;
1226 }
1227
1228 DEFUN (bgp_maxmed_admin_medv,
1229 bgp_maxmed_admin_medv_cmd,
1230 "bgp max-med administrative (0-4294967295)",
1231 BGP_STR
1232 "Advertise routes with max-med\n"
1233 "Administratively applied, for an indefinite period\n"
1234 "Max MED value to be used\n")
1235 {
1236 VTY_DECLVAR_CONTEXT(bgp, bgp);
1237 int idx_number = 3;
1238
1239 bgp->v_maxmed_admin = 1;
1240 bgp->maxmed_admin_value = strtoul(argv[idx_number]->arg, NULL, 10);
1241
1242 bgp_maxmed_update(bgp);
1243
1244 return CMD_SUCCESS;
1245 }
1246
1247 DEFUN (no_bgp_maxmed_admin,
1248 no_bgp_maxmed_admin_cmd,
1249 "no bgp max-med administrative [(0-4294967295)]",
1250 NO_STR
1251 BGP_STR
1252 "Advertise routes with max-med\n"
1253 "Administratively applied, for an indefinite period\n"
1254 "Max MED value to be used\n")
1255 {
1256 VTY_DECLVAR_CONTEXT(bgp, bgp);
1257 bgp->v_maxmed_admin = BGP_MAXMED_ADMIN_UNCONFIGURED;
1258 bgp->maxmed_admin_value = BGP_MAXMED_VALUE_DEFAULT;
1259 bgp_maxmed_update(bgp);
1260
1261 return CMD_SUCCESS;
1262 }
1263
1264 DEFUN (bgp_maxmed_onstartup,
1265 bgp_maxmed_onstartup_cmd,
1266 "bgp max-med on-startup (5-86400) [(0-4294967295)]",
1267 BGP_STR
1268 "Advertise routes with max-med\n"
1269 "Effective on a startup\n"
1270 "Time (seconds) period for max-med\n"
1271 "Max MED value to be used\n")
1272 {
1273 VTY_DECLVAR_CONTEXT(bgp, bgp);
1274 int idx = 0;
1275
1276 argv_find(argv, argc, "(5-86400)", &idx);
1277 bgp->v_maxmed_onstartup = strtoul(argv[idx]->arg, NULL, 10);
1278 if (argv_find(argv, argc, "(0-4294967295)", &idx))
1279 bgp->maxmed_onstartup_value = strtoul(argv[idx]->arg, NULL, 10);
1280 else
1281 bgp->maxmed_onstartup_value = BGP_MAXMED_VALUE_DEFAULT;
1282
1283 bgp_maxmed_update(bgp);
1284
1285 return CMD_SUCCESS;
1286 }
1287
1288 DEFUN (no_bgp_maxmed_onstartup,
1289 no_bgp_maxmed_onstartup_cmd,
1290 "no bgp max-med on-startup [(5-86400) [(0-4294967295)]]",
1291 NO_STR
1292 BGP_STR
1293 "Advertise routes with max-med\n"
1294 "Effective on a startup\n"
1295 "Time (seconds) period for max-med\n"
1296 "Max MED value to be used\n")
1297 {
1298 VTY_DECLVAR_CONTEXT(bgp, bgp);
1299
1300 /* Cancel max-med onstartup if its on */
1301 if (bgp->t_maxmed_onstartup) {
1302 THREAD_TIMER_OFF(bgp->t_maxmed_onstartup);
1303 bgp->maxmed_onstartup_over = 1;
1304 }
1305
1306 bgp->v_maxmed_onstartup = BGP_MAXMED_ONSTARTUP_UNCONFIGURED;
1307 bgp->maxmed_onstartup_value = BGP_MAXMED_VALUE_DEFAULT;
1308
1309 bgp_maxmed_update(bgp);
1310
1311 return CMD_SUCCESS;
1312 }
1313
1314 static int bgp_update_delay_config_vty(struct vty *vty, const char *delay,
1315 const char *wait)
1316 {
1317 VTY_DECLVAR_CONTEXT(bgp, bgp);
1318 uint16_t update_delay;
1319 uint16_t establish_wait;
1320
1321 update_delay = strtoul(delay, NULL, 10);
1322
1323 if (!wait) /* update-delay <delay> */
1324 {
1325 bgp->v_update_delay = update_delay;
1326 bgp->v_establish_wait = bgp->v_update_delay;
1327 return CMD_SUCCESS;
1328 }
1329
1330 /* update-delay <delay> <establish-wait> */
1331 establish_wait = atoi(wait);
1332 if (update_delay < establish_wait) {
1333 vty_out(vty,
1334 "%%Failed: update-delay less than the establish-wait!\n");
1335 return CMD_WARNING_CONFIG_FAILED;
1336 }
1337
1338 bgp->v_update_delay = update_delay;
1339 bgp->v_establish_wait = establish_wait;
1340
1341 return CMD_SUCCESS;
1342 }
1343
1344 static int bgp_update_delay_deconfig_vty(struct vty *vty)
1345 {
1346 VTY_DECLVAR_CONTEXT(bgp, bgp);
1347
1348 bgp->v_update_delay = BGP_UPDATE_DELAY_DEF;
1349 bgp->v_establish_wait = bgp->v_update_delay;
1350
1351 return CMD_SUCCESS;
1352 }
1353
1354 void bgp_config_write_update_delay(struct vty *vty, struct bgp *bgp)
1355 {
1356 if (bgp->v_update_delay != BGP_UPDATE_DELAY_DEF) {
1357 vty_out(vty, " update-delay %d", bgp->v_update_delay);
1358 if (bgp->v_update_delay != bgp->v_establish_wait)
1359 vty_out(vty, " %d", bgp->v_establish_wait);
1360 vty_out(vty, "\n");
1361 }
1362 }
1363
1364
1365 /* Update-delay configuration */
1366 DEFUN (bgp_update_delay,
1367 bgp_update_delay_cmd,
1368 "update-delay (0-3600)",
1369 "Force initial delay for best-path and updates\n"
1370 "Seconds\n")
1371 {
1372 int idx_number = 1;
1373 return bgp_update_delay_config_vty(vty, argv[idx_number]->arg, NULL);
1374 }
1375
1376 DEFUN (bgp_update_delay_establish_wait,
1377 bgp_update_delay_establish_wait_cmd,
1378 "update-delay (0-3600) (1-3600)",
1379 "Force initial delay for best-path and updates\n"
1380 "Seconds\n"
1381 "Seconds\n")
1382 {
1383 int idx_number = 1;
1384 int idx_number_2 = 2;
1385 return bgp_update_delay_config_vty(vty, argv[idx_number]->arg,
1386 argv[idx_number_2]->arg);
1387 }
1388
1389 /* Update-delay deconfiguration */
1390 DEFUN (no_bgp_update_delay,
1391 no_bgp_update_delay_cmd,
1392 "no update-delay [(0-3600) [(1-3600)]]",
1393 NO_STR
1394 "Force initial delay for best-path and updates\n"
1395 "Seconds\n"
1396 "Seconds\n")
1397 {
1398 return bgp_update_delay_deconfig_vty(vty);
1399 }
1400
1401
1402 static int bgp_wpkt_quanta_config_vty(struct vty *vty, const char *num,
1403 char set)
1404 {
1405 VTY_DECLVAR_CONTEXT(bgp, bgp);
1406
1407 if (set) {
1408 uint32_t quanta = strtoul(num, NULL, 10);
1409 atomic_store_explicit(&bgp->wpkt_quanta, quanta,
1410 memory_order_relaxed);
1411 } else {
1412 atomic_store_explicit(&bgp->wpkt_quanta, BGP_WRITE_PACKET_MAX,
1413 memory_order_relaxed);
1414 }
1415
1416 return CMD_SUCCESS;
1417 }
1418
1419 static int bgp_rpkt_quanta_config_vty(struct vty *vty, const char *num,
1420 char set)
1421 {
1422 VTY_DECLVAR_CONTEXT(bgp, bgp);
1423
1424 if (set) {
1425 uint32_t quanta = strtoul(num, NULL, 10);
1426 atomic_store_explicit(&bgp->rpkt_quanta, quanta,
1427 memory_order_relaxed);
1428 } else {
1429 atomic_store_explicit(&bgp->rpkt_quanta, BGP_READ_PACKET_MAX,
1430 memory_order_relaxed);
1431 }
1432
1433 return CMD_SUCCESS;
1434 }
1435
1436 void bgp_config_write_wpkt_quanta(struct vty *vty, struct bgp *bgp)
1437 {
1438 uint32_t quanta =
1439 atomic_load_explicit(&bgp->wpkt_quanta, memory_order_relaxed);
1440 if (quanta != BGP_WRITE_PACKET_MAX)
1441 vty_out(vty, " write-quanta %d\n", quanta);
1442 }
1443
1444 void bgp_config_write_rpkt_quanta(struct vty *vty, struct bgp *bgp)
1445 {
1446 uint32_t quanta =
1447 atomic_load_explicit(&bgp->rpkt_quanta, memory_order_relaxed);
1448 if (quanta != BGP_READ_PACKET_MAX)
1449 vty_out(vty, " read-quanta %d\n", quanta);
1450 }
1451
1452 /* Packet quanta configuration */
1453 DEFUN (bgp_wpkt_quanta,
1454 bgp_wpkt_quanta_cmd,
1455 "write-quanta (1-10)",
1456 "How many packets to write to peer socket per run\n"
1457 "Number of packets\n")
1458 {
1459 int idx_number = 1;
1460 return bgp_wpkt_quanta_config_vty(vty, argv[idx_number]->arg, 1);
1461 }
1462
1463 DEFUN (no_bgp_wpkt_quanta,
1464 no_bgp_wpkt_quanta_cmd,
1465 "no write-quanta (1-10)",
1466 NO_STR
1467 "How many packets to write to peer socket per I/O cycle\n"
1468 "Number of packets\n")
1469 {
1470 int idx_number = 2;
1471 return bgp_wpkt_quanta_config_vty(vty, argv[idx_number]->arg, 0);
1472 }
1473
1474 DEFUN (bgp_rpkt_quanta,
1475 bgp_rpkt_quanta_cmd,
1476 "read-quanta (1-10)",
1477 "How many packets to read from peer socket per I/O cycle\n"
1478 "Number of packets\n")
1479 {
1480 int idx_number = 1;
1481 return bgp_rpkt_quanta_config_vty(vty, argv[idx_number]->arg, 1);
1482 }
1483
1484 DEFUN (no_bgp_rpkt_quanta,
1485 no_bgp_rpkt_quanta_cmd,
1486 "no read-quanta (1-10)",
1487 NO_STR
1488 "How many packets to read from peer socket per I/O cycle\n"
1489 "Number of packets\n")
1490 {
1491 int idx_number = 2;
1492 return bgp_rpkt_quanta_config_vty(vty, argv[idx_number]->arg, 0);
1493 }
1494
1495 void bgp_config_write_coalesce_time(struct vty *vty, struct bgp *bgp)
1496 {
1497 if (!bgp->heuristic_coalesce)
1498 vty_out(vty, " coalesce-time %u\n", bgp->coalesce_time);
1499 }
1500
1501
1502 DEFUN (bgp_coalesce_time,
1503 bgp_coalesce_time_cmd,
1504 "coalesce-time (0-4294967295)",
1505 "Subgroup coalesce timer\n"
1506 "Subgroup coalesce timer value (in ms)\n")
1507 {
1508 VTY_DECLVAR_CONTEXT(bgp, bgp);
1509
1510 int idx = 0;
1511 argv_find(argv, argc, "(0-4294967295)", &idx);
1512 bgp->heuristic_coalesce = false;
1513 bgp->coalesce_time = strtoul(argv[idx]->arg, NULL, 10);
1514 return CMD_SUCCESS;
1515 }
1516
1517 DEFUN (no_bgp_coalesce_time,
1518 no_bgp_coalesce_time_cmd,
1519 "no coalesce-time (0-4294967295)",
1520 NO_STR
1521 "Subgroup coalesce timer\n"
1522 "Subgroup coalesce timer value (in ms)\n")
1523 {
1524 VTY_DECLVAR_CONTEXT(bgp, bgp);
1525
1526 bgp->heuristic_coalesce = true;
1527 bgp->coalesce_time = BGP_DEFAULT_SUBGROUP_COALESCE_TIME;
1528 return CMD_SUCCESS;
1529 }
1530
1531 /* Maximum-paths configuration */
1532 DEFUN (bgp_maxpaths,
1533 bgp_maxpaths_cmd,
1534 "maximum-paths " CMD_RANGE_STR(1, MULTIPATH_NUM),
1535 "Forward packets over multiple paths\n"
1536 "Number of paths\n")
1537 {
1538 int idx_number = 1;
1539 return bgp_maxpaths_config_vty(vty, BGP_PEER_EBGP,
1540 argv[idx_number]->arg, 0, 1);
1541 }
1542
1543 ALIAS_HIDDEN(bgp_maxpaths, bgp_maxpaths_hidden_cmd,
1544 "maximum-paths " CMD_RANGE_STR(1, MULTIPATH_NUM),
1545 "Forward packets over multiple paths\n"
1546 "Number of paths\n")
1547
1548 DEFUN (bgp_maxpaths_ibgp,
1549 bgp_maxpaths_ibgp_cmd,
1550 "maximum-paths ibgp " CMD_RANGE_STR(1, MULTIPATH_NUM),
1551 "Forward packets over multiple paths\n"
1552 "iBGP-multipath\n"
1553 "Number of paths\n")
1554 {
1555 int idx_number = 2;
1556 return bgp_maxpaths_config_vty(vty, BGP_PEER_IBGP,
1557 argv[idx_number]->arg, 0, 1);
1558 }
1559
1560 ALIAS_HIDDEN(bgp_maxpaths_ibgp, bgp_maxpaths_ibgp_hidden_cmd,
1561 "maximum-paths ibgp " CMD_RANGE_STR(1, MULTIPATH_NUM),
1562 "Forward packets over multiple paths\n"
1563 "iBGP-multipath\n"
1564 "Number of paths\n")
1565
1566 DEFUN (bgp_maxpaths_ibgp_cluster,
1567 bgp_maxpaths_ibgp_cluster_cmd,
1568 "maximum-paths ibgp " CMD_RANGE_STR(1, MULTIPATH_NUM) " equal-cluster-length",
1569 "Forward packets over multiple paths\n"
1570 "iBGP-multipath\n"
1571 "Number of paths\n"
1572 "Match the cluster length\n")
1573 {
1574 int idx_number = 2;
1575 return bgp_maxpaths_config_vty(
1576 vty, BGP_PEER_IBGP, argv[idx_number]->arg,
1577 BGP_FLAG_IBGP_MULTIPATH_SAME_CLUSTERLEN, 1);
1578 }
1579
1580 ALIAS_HIDDEN(bgp_maxpaths_ibgp_cluster, bgp_maxpaths_ibgp_cluster_hidden_cmd,
1581 "maximum-paths ibgp " CMD_RANGE_STR(
1582 1, MULTIPATH_NUM) " equal-cluster-length",
1583 "Forward packets over multiple paths\n"
1584 "iBGP-multipath\n"
1585 "Number of paths\n"
1586 "Match the cluster length\n")
1587
1588 DEFUN (no_bgp_maxpaths,
1589 no_bgp_maxpaths_cmd,
1590 "no maximum-paths [" CMD_RANGE_STR(1, MULTIPATH_NUM) "]",
1591 NO_STR
1592 "Forward packets over multiple paths\n"
1593 "Number of paths\n")
1594 {
1595 return bgp_maxpaths_config_vty(vty, BGP_PEER_EBGP, NULL, 0, 0);
1596 }
1597
1598 ALIAS_HIDDEN(no_bgp_maxpaths, no_bgp_maxpaths_hidden_cmd,
1599 "no maximum-paths [" CMD_RANGE_STR(1, MULTIPATH_NUM) "]", NO_STR
1600 "Forward packets over multiple paths\n"
1601 "Number of paths\n")
1602
1603 DEFUN (no_bgp_maxpaths_ibgp,
1604 no_bgp_maxpaths_ibgp_cmd,
1605 "no maximum-paths ibgp [" CMD_RANGE_STR(1, MULTIPATH_NUM) " [equal-cluster-length]]",
1606 NO_STR
1607 "Forward packets over multiple paths\n"
1608 "iBGP-multipath\n"
1609 "Number of paths\n"
1610 "Match the cluster length\n")
1611 {
1612 return bgp_maxpaths_config_vty(vty, BGP_PEER_IBGP, NULL, 0, 0);
1613 }
1614
1615 ALIAS_HIDDEN(no_bgp_maxpaths_ibgp, no_bgp_maxpaths_ibgp_hidden_cmd,
1616 "no maximum-paths ibgp [" CMD_RANGE_STR(
1617 1, MULTIPATH_NUM) " [equal-cluster-length]]",
1618 NO_STR
1619 "Forward packets over multiple paths\n"
1620 "iBGP-multipath\n"
1621 "Number of paths\n"
1622 "Match the cluster length\n")
1623
1624 void bgp_config_write_maxpaths(struct vty *vty, struct bgp *bgp, afi_t afi,
1625 safi_t safi)
1626 {
1627 if (bgp->maxpaths[afi][safi].maxpaths_ebgp != MULTIPATH_NUM) {
1628 vty_out(vty, " maximum-paths %d\n",
1629 bgp->maxpaths[afi][safi].maxpaths_ebgp);
1630 }
1631
1632 if (bgp->maxpaths[afi][safi].maxpaths_ibgp != MULTIPATH_NUM) {
1633 vty_out(vty, " maximum-paths ibgp %d",
1634 bgp->maxpaths[afi][safi].maxpaths_ibgp);
1635 if (CHECK_FLAG(bgp->maxpaths[afi][safi].ibgp_flags,
1636 BGP_FLAG_IBGP_MULTIPATH_SAME_CLUSTERLEN))
1637 vty_out(vty, " equal-cluster-length");
1638 vty_out(vty, "\n");
1639 }
1640 }
1641
1642 /* BGP timers. */
1643
1644 DEFUN (bgp_timers,
1645 bgp_timers_cmd,
1646 "timers bgp (0-65535) (0-65535)",
1647 "Adjust routing timers\n"
1648 "BGP timers\n"
1649 "Keepalive interval\n"
1650 "Holdtime\n")
1651 {
1652 VTY_DECLVAR_CONTEXT(bgp, bgp);
1653 int idx_number = 2;
1654 int idx_number_2 = 3;
1655 unsigned long keepalive = 0;
1656 unsigned long holdtime = 0;
1657
1658 keepalive = strtoul(argv[idx_number]->arg, NULL, 10);
1659 holdtime = strtoul(argv[idx_number_2]->arg, NULL, 10);
1660
1661 /* Holdtime value check. */
1662 if (holdtime < 3 && holdtime != 0) {
1663 vty_out(vty,
1664 "%% hold time value must be either 0 or greater than 3\n");
1665 return CMD_WARNING_CONFIG_FAILED;
1666 }
1667
1668 bgp_timers_set(bgp, keepalive, holdtime);
1669
1670 return CMD_SUCCESS;
1671 }
1672
1673 DEFUN (no_bgp_timers,
1674 no_bgp_timers_cmd,
1675 "no timers bgp [(0-65535) (0-65535)]",
1676 NO_STR
1677 "Adjust routing timers\n"
1678 "BGP timers\n"
1679 "Keepalive interval\n"
1680 "Holdtime\n")
1681 {
1682 VTY_DECLVAR_CONTEXT(bgp, bgp);
1683 bgp_timers_unset(bgp);
1684
1685 return CMD_SUCCESS;
1686 }
1687
1688
1689 DEFUN (bgp_client_to_client_reflection,
1690 bgp_client_to_client_reflection_cmd,
1691 "bgp client-to-client reflection",
1692 "BGP specific commands\n"
1693 "Configure client to client route reflection\n"
1694 "reflection of routes allowed\n")
1695 {
1696 VTY_DECLVAR_CONTEXT(bgp, bgp);
1697 bgp_flag_unset(bgp, BGP_FLAG_NO_CLIENT_TO_CLIENT);
1698 bgp_clear_star_soft_out(vty, bgp->name);
1699
1700 return CMD_SUCCESS;
1701 }
1702
1703 DEFUN (no_bgp_client_to_client_reflection,
1704 no_bgp_client_to_client_reflection_cmd,
1705 "no bgp client-to-client reflection",
1706 NO_STR
1707 "BGP specific commands\n"
1708 "Configure client to client route reflection\n"
1709 "reflection of routes allowed\n")
1710 {
1711 VTY_DECLVAR_CONTEXT(bgp, bgp);
1712 bgp_flag_set(bgp, BGP_FLAG_NO_CLIENT_TO_CLIENT);
1713 bgp_clear_star_soft_out(vty, bgp->name);
1714
1715 return CMD_SUCCESS;
1716 }
1717
1718 /* "bgp always-compare-med" configuration. */
1719 DEFUN (bgp_always_compare_med,
1720 bgp_always_compare_med_cmd,
1721 "bgp always-compare-med",
1722 "BGP specific commands\n"
1723 "Allow comparing MED from different neighbors\n")
1724 {
1725 VTY_DECLVAR_CONTEXT(bgp, bgp);
1726 bgp_flag_set(bgp, BGP_FLAG_ALWAYS_COMPARE_MED);
1727 bgp_recalculate_all_bestpaths(bgp);
1728
1729 return CMD_SUCCESS;
1730 }
1731
1732 DEFUN (no_bgp_always_compare_med,
1733 no_bgp_always_compare_med_cmd,
1734 "no bgp always-compare-med",
1735 NO_STR
1736 "BGP specific commands\n"
1737 "Allow comparing MED from different neighbors\n")
1738 {
1739 VTY_DECLVAR_CONTEXT(bgp, bgp);
1740 bgp_flag_unset(bgp, BGP_FLAG_ALWAYS_COMPARE_MED);
1741 bgp_recalculate_all_bestpaths(bgp);
1742
1743 return CMD_SUCCESS;
1744 }
1745
1746 /* "bgp deterministic-med" configuration. */
1747 DEFUN (bgp_deterministic_med,
1748 bgp_deterministic_med_cmd,
1749 "bgp deterministic-med",
1750 "BGP specific commands\n"
1751 "Pick the best-MED path among paths advertised from the neighboring AS\n")
1752 {
1753 VTY_DECLVAR_CONTEXT(bgp, bgp);
1754
1755 if (!bgp_flag_check(bgp, BGP_FLAG_DETERMINISTIC_MED)) {
1756 bgp_flag_set(bgp, BGP_FLAG_DETERMINISTIC_MED);
1757 bgp_recalculate_all_bestpaths(bgp);
1758 }
1759
1760 return CMD_SUCCESS;
1761 }
1762
1763 DEFUN (no_bgp_deterministic_med,
1764 no_bgp_deterministic_med_cmd,
1765 "no bgp deterministic-med",
1766 NO_STR
1767 "BGP specific commands\n"
1768 "Pick the best-MED path among paths advertised from the neighboring AS\n")
1769 {
1770 VTY_DECLVAR_CONTEXT(bgp, bgp);
1771 int bestpath_per_as_used;
1772 afi_t afi;
1773 safi_t safi;
1774 struct peer *peer;
1775 struct listnode *node, *nnode;
1776
1777 if (bgp_flag_check(bgp, BGP_FLAG_DETERMINISTIC_MED)) {
1778 bestpath_per_as_used = 0;
1779
1780 for (ALL_LIST_ELEMENTS(bgp->peer, node, nnode, peer)) {
1781 FOREACH_AFI_SAFI (afi, safi)
1782 if (CHECK_FLAG(
1783 peer->af_flags[afi][safi],
1784 PEER_FLAG_ADDPATH_TX_BESTPATH_PER_AS)) {
1785 bestpath_per_as_used = 1;
1786 break;
1787 }
1788
1789 if (bestpath_per_as_used)
1790 break;
1791 }
1792
1793 if (bestpath_per_as_used) {
1794 vty_out(vty,
1795 "bgp deterministic-med cannot be disabled while addpath-tx-bestpath-per-AS is in use\n");
1796 return CMD_WARNING_CONFIG_FAILED;
1797 } else {
1798 bgp_flag_unset(bgp, BGP_FLAG_DETERMINISTIC_MED);
1799 bgp_recalculate_all_bestpaths(bgp);
1800 }
1801 }
1802
1803 return CMD_SUCCESS;
1804 }
1805
1806 /* "bgp graceful-restart" configuration. */
1807 DEFUN (bgp_graceful_restart,
1808 bgp_graceful_restart_cmd,
1809 "bgp graceful-restart",
1810 "BGP specific commands\n"
1811 "Graceful restart capability parameters\n")
1812 {
1813 VTY_DECLVAR_CONTEXT(bgp, bgp);
1814 bgp_flag_set(bgp, BGP_FLAG_GRACEFUL_RESTART);
1815 return CMD_SUCCESS;
1816 }
1817
1818 DEFUN (no_bgp_graceful_restart,
1819 no_bgp_graceful_restart_cmd,
1820 "no bgp graceful-restart",
1821 NO_STR
1822 "BGP specific commands\n"
1823 "Graceful restart capability parameters\n")
1824 {
1825 VTY_DECLVAR_CONTEXT(bgp, bgp);
1826 bgp_flag_unset(bgp, BGP_FLAG_GRACEFUL_RESTART);
1827 return CMD_SUCCESS;
1828 }
1829
1830 DEFUN (bgp_graceful_restart_stalepath_time,
1831 bgp_graceful_restart_stalepath_time_cmd,
1832 "bgp graceful-restart stalepath-time (1-3600)",
1833 "BGP specific commands\n"
1834 "Graceful restart capability parameters\n"
1835 "Set the max time to hold onto restarting peer's stale paths\n"
1836 "Delay value (seconds)\n")
1837 {
1838 VTY_DECLVAR_CONTEXT(bgp, bgp);
1839 int idx_number = 3;
1840 uint32_t stalepath;
1841
1842 stalepath = strtoul(argv[idx_number]->arg, NULL, 10);
1843 bgp->stalepath_time = stalepath;
1844 return CMD_SUCCESS;
1845 }
1846
1847 DEFUN (bgp_graceful_restart_restart_time,
1848 bgp_graceful_restart_restart_time_cmd,
1849 "bgp graceful-restart restart-time (1-3600)",
1850 "BGP specific commands\n"
1851 "Graceful restart capability parameters\n"
1852 "Set the time to wait to delete stale routes before a BGP open message is received\n"
1853 "Delay value (seconds)\n")
1854 {
1855 VTY_DECLVAR_CONTEXT(bgp, bgp);
1856 int idx_number = 3;
1857 uint32_t restart;
1858
1859 restart = strtoul(argv[idx_number]->arg, NULL, 10);
1860 bgp->restart_time = restart;
1861 return CMD_SUCCESS;
1862 }
1863
1864 DEFUN (no_bgp_graceful_restart_stalepath_time,
1865 no_bgp_graceful_restart_stalepath_time_cmd,
1866 "no bgp graceful-restart stalepath-time [(1-3600)]",
1867 NO_STR
1868 "BGP specific commands\n"
1869 "Graceful restart capability parameters\n"
1870 "Set the max time to hold onto restarting peer's stale paths\n"
1871 "Delay value (seconds)\n")
1872 {
1873 VTY_DECLVAR_CONTEXT(bgp, bgp);
1874
1875 bgp->stalepath_time = BGP_DEFAULT_STALEPATH_TIME;
1876 return CMD_SUCCESS;
1877 }
1878
1879 DEFUN (no_bgp_graceful_restart_restart_time,
1880 no_bgp_graceful_restart_restart_time_cmd,
1881 "no bgp graceful-restart restart-time [(1-3600)]",
1882 NO_STR
1883 "BGP specific commands\n"
1884 "Graceful restart capability parameters\n"
1885 "Set the time to wait to delete stale routes before a BGP open message is received\n"
1886 "Delay value (seconds)\n")
1887 {
1888 VTY_DECLVAR_CONTEXT(bgp, bgp);
1889
1890 bgp->restart_time = BGP_DEFAULT_RESTART_TIME;
1891 return CMD_SUCCESS;
1892 }
1893
1894 DEFUN (bgp_graceful_restart_preserve_fw,
1895 bgp_graceful_restart_preserve_fw_cmd,
1896 "bgp graceful-restart preserve-fw-state",
1897 "BGP specific commands\n"
1898 "Graceful restart capability parameters\n"
1899 "Sets F-bit indication that fib is preserved while doing Graceful Restart\n")
1900 {
1901 VTY_DECLVAR_CONTEXT(bgp, bgp);
1902 bgp_flag_set(bgp, BGP_FLAG_GR_PRESERVE_FWD);
1903 return CMD_SUCCESS;
1904 }
1905
1906 DEFUN (no_bgp_graceful_restart_preserve_fw,
1907 no_bgp_graceful_restart_preserve_fw_cmd,
1908 "no bgp graceful-restart preserve-fw-state",
1909 NO_STR
1910 "BGP specific commands\n"
1911 "Graceful restart capability parameters\n"
1912 "Unsets F-bit indication that fib is preserved while doing Graceful Restart\n")
1913 {
1914 VTY_DECLVAR_CONTEXT(bgp, bgp);
1915 bgp_flag_unset(bgp, BGP_FLAG_GR_PRESERVE_FWD);
1916 return CMD_SUCCESS;
1917 }
1918
1919 static void bgp_redistribute_redo(struct bgp *bgp)
1920 {
1921 afi_t afi;
1922 int i;
1923 struct list *red_list;
1924 struct listnode *node;
1925 struct bgp_redist *red;
1926
1927 for (afi = AFI_IP; afi < AFI_MAX; afi++) {
1928 for (i = 0; i < ZEBRA_ROUTE_MAX; i++) {
1929
1930 red_list = bgp->redist[afi][i];
1931 if (!red_list)
1932 continue;
1933
1934 for (ALL_LIST_ELEMENTS_RO(red_list, node, red)) {
1935 bgp_redistribute_resend(bgp, afi, i,
1936 red->instance);
1937 }
1938 }
1939 }
1940 }
1941
1942 /* "bgp graceful-shutdown" configuration */
1943 DEFUN (bgp_graceful_shutdown,
1944 bgp_graceful_shutdown_cmd,
1945 "bgp graceful-shutdown",
1946 BGP_STR
1947 "Graceful shutdown parameters\n")
1948 {
1949 VTY_DECLVAR_CONTEXT(bgp, bgp);
1950
1951 if (!bgp_flag_check(bgp, BGP_FLAG_GRACEFUL_SHUTDOWN)) {
1952 bgp_flag_set(bgp, BGP_FLAG_GRACEFUL_SHUTDOWN);
1953 bgp_static_redo_import_check(bgp);
1954 bgp_redistribute_redo(bgp);
1955 bgp_clear_star_soft_out(vty, bgp->name);
1956 bgp_clear_star_soft_in(vty, bgp->name);
1957 }
1958
1959 return CMD_SUCCESS;
1960 }
1961
1962 DEFUN (no_bgp_graceful_shutdown,
1963 no_bgp_graceful_shutdown_cmd,
1964 "no bgp graceful-shutdown",
1965 NO_STR
1966 BGP_STR
1967 "Graceful shutdown parameters\n")
1968 {
1969 VTY_DECLVAR_CONTEXT(bgp, bgp);
1970
1971 if (bgp_flag_check(bgp, BGP_FLAG_GRACEFUL_SHUTDOWN)) {
1972 bgp_flag_unset(bgp, BGP_FLAG_GRACEFUL_SHUTDOWN);
1973 bgp_static_redo_import_check(bgp);
1974 bgp_redistribute_redo(bgp);
1975 bgp_clear_star_soft_out(vty, bgp->name);
1976 bgp_clear_star_soft_in(vty, bgp->name);
1977 }
1978
1979 return CMD_SUCCESS;
1980 }
1981
1982 /* "bgp fast-external-failover" configuration. */
1983 DEFUN (bgp_fast_external_failover,
1984 bgp_fast_external_failover_cmd,
1985 "bgp fast-external-failover",
1986 BGP_STR
1987 "Immediately reset session if a link to a directly connected external peer goes down\n")
1988 {
1989 VTY_DECLVAR_CONTEXT(bgp, bgp);
1990 bgp_flag_unset(bgp, BGP_FLAG_NO_FAST_EXT_FAILOVER);
1991 return CMD_SUCCESS;
1992 }
1993
1994 DEFUN (no_bgp_fast_external_failover,
1995 no_bgp_fast_external_failover_cmd,
1996 "no bgp fast-external-failover",
1997 NO_STR
1998 BGP_STR
1999 "Immediately reset session if a link to a directly connected external peer goes down\n")
2000 {
2001 VTY_DECLVAR_CONTEXT(bgp, bgp);
2002 bgp_flag_set(bgp, BGP_FLAG_NO_FAST_EXT_FAILOVER);
2003 return CMD_SUCCESS;
2004 }
2005
2006 /* "bgp enforce-first-as" configuration. */
2007 #if defined(VERSION_TYPE_DEV) && CONFDATE > 20180517
2008 CPP_NOTICE("bgpd: remove deprecated '[no] bgp enforce-first-as' commands")
2009 #endif
2010
2011 DEFUN_DEPRECATED (bgp_enforce_first_as,
2012 bgp_enforce_first_as_cmd,
2013 "bgp enforce-first-as",
2014 BGP_STR
2015 "Enforce the first AS for EBGP routes\n")
2016 {
2017 VTY_DECLVAR_CONTEXT(bgp, bgp);
2018 bgp_flag_set(bgp, BGP_FLAG_ENFORCE_FIRST_AS);
2019
2020 return CMD_SUCCESS;
2021 }
2022
2023 DEFUN_DEPRECATED (no_bgp_enforce_first_as,
2024 no_bgp_enforce_first_as_cmd,
2025 "no bgp enforce-first-as",
2026 NO_STR
2027 BGP_STR
2028 "Enforce the first AS for EBGP routes\n")
2029 {
2030 VTY_DECLVAR_CONTEXT(bgp, bgp);
2031 bgp_flag_unset(bgp, BGP_FLAG_ENFORCE_FIRST_AS);
2032
2033 return CMD_SUCCESS;
2034 }
2035
2036 /* "bgp bestpath compare-routerid" configuration. */
2037 DEFUN (bgp_bestpath_compare_router_id,
2038 bgp_bestpath_compare_router_id_cmd,
2039 "bgp bestpath compare-routerid",
2040 "BGP specific commands\n"
2041 "Change the default bestpath selection\n"
2042 "Compare router-id for identical EBGP paths\n")
2043 {
2044 VTY_DECLVAR_CONTEXT(bgp, bgp);
2045 bgp_flag_set(bgp, BGP_FLAG_COMPARE_ROUTER_ID);
2046 bgp_recalculate_all_bestpaths(bgp);
2047
2048 return CMD_SUCCESS;
2049 }
2050
2051 DEFUN (no_bgp_bestpath_compare_router_id,
2052 no_bgp_bestpath_compare_router_id_cmd,
2053 "no bgp bestpath compare-routerid",
2054 NO_STR
2055 "BGP specific commands\n"
2056 "Change the default bestpath selection\n"
2057 "Compare router-id for identical EBGP paths\n")
2058 {
2059 VTY_DECLVAR_CONTEXT(bgp, bgp);
2060 bgp_flag_unset(bgp, BGP_FLAG_COMPARE_ROUTER_ID);
2061 bgp_recalculate_all_bestpaths(bgp);
2062
2063 return CMD_SUCCESS;
2064 }
2065
2066 /* "bgp bestpath as-path ignore" configuration. */
2067 DEFUN (bgp_bestpath_aspath_ignore,
2068 bgp_bestpath_aspath_ignore_cmd,
2069 "bgp bestpath as-path ignore",
2070 "BGP specific commands\n"
2071 "Change the default bestpath selection\n"
2072 "AS-path attribute\n"
2073 "Ignore as-path length in selecting a route\n")
2074 {
2075 VTY_DECLVAR_CONTEXT(bgp, bgp);
2076 bgp_flag_set(bgp, BGP_FLAG_ASPATH_IGNORE);
2077 bgp_recalculate_all_bestpaths(bgp);
2078
2079 return CMD_SUCCESS;
2080 }
2081
2082 DEFUN (no_bgp_bestpath_aspath_ignore,
2083 no_bgp_bestpath_aspath_ignore_cmd,
2084 "no bgp bestpath as-path ignore",
2085 NO_STR
2086 "BGP specific commands\n"
2087 "Change the default bestpath selection\n"
2088 "AS-path attribute\n"
2089 "Ignore as-path length in selecting a route\n")
2090 {
2091 VTY_DECLVAR_CONTEXT(bgp, bgp);
2092 bgp_flag_unset(bgp, BGP_FLAG_ASPATH_IGNORE);
2093 bgp_recalculate_all_bestpaths(bgp);
2094
2095 return CMD_SUCCESS;
2096 }
2097
2098 /* "bgp bestpath as-path confed" configuration. */
2099 DEFUN (bgp_bestpath_aspath_confed,
2100 bgp_bestpath_aspath_confed_cmd,
2101 "bgp bestpath as-path confed",
2102 "BGP specific commands\n"
2103 "Change the default bestpath selection\n"
2104 "AS-path attribute\n"
2105 "Compare path lengths including confederation sets & sequences in selecting a route\n")
2106 {
2107 VTY_DECLVAR_CONTEXT(bgp, bgp);
2108 bgp_flag_set(bgp, BGP_FLAG_ASPATH_CONFED);
2109 bgp_recalculate_all_bestpaths(bgp);
2110
2111 return CMD_SUCCESS;
2112 }
2113
2114 DEFUN (no_bgp_bestpath_aspath_confed,
2115 no_bgp_bestpath_aspath_confed_cmd,
2116 "no bgp bestpath as-path confed",
2117 NO_STR
2118 "BGP specific commands\n"
2119 "Change the default bestpath selection\n"
2120 "AS-path attribute\n"
2121 "Compare path lengths including confederation sets & sequences in selecting a route\n")
2122 {
2123 VTY_DECLVAR_CONTEXT(bgp, bgp);
2124 bgp_flag_unset(bgp, BGP_FLAG_ASPATH_CONFED);
2125 bgp_recalculate_all_bestpaths(bgp);
2126
2127 return CMD_SUCCESS;
2128 }
2129
2130 /* "bgp bestpath as-path multipath-relax" configuration. */
2131 DEFUN (bgp_bestpath_aspath_multipath_relax,
2132 bgp_bestpath_aspath_multipath_relax_cmd,
2133 "bgp bestpath as-path multipath-relax [<as-set|no-as-set>]",
2134 "BGP specific commands\n"
2135 "Change the default bestpath selection\n"
2136 "AS-path attribute\n"
2137 "Allow load sharing across routes that have different AS paths (but same length)\n"
2138 "Generate an AS_SET\n"
2139 "Do not generate an AS_SET\n")
2140 {
2141 VTY_DECLVAR_CONTEXT(bgp, bgp);
2142 int idx = 0;
2143 bgp_flag_set(bgp, BGP_FLAG_ASPATH_MULTIPATH_RELAX);
2144
2145 /* no-as-set is now the default behavior so we can silently
2146 * ignore it */
2147 if (argv_find(argv, argc, "as-set", &idx))
2148 bgp_flag_set(bgp, BGP_FLAG_MULTIPATH_RELAX_AS_SET);
2149 else
2150 bgp_flag_unset(bgp, BGP_FLAG_MULTIPATH_RELAX_AS_SET);
2151
2152 bgp_recalculate_all_bestpaths(bgp);
2153
2154 return CMD_SUCCESS;
2155 }
2156
2157 DEFUN (no_bgp_bestpath_aspath_multipath_relax,
2158 no_bgp_bestpath_aspath_multipath_relax_cmd,
2159 "no bgp bestpath as-path multipath-relax [<as-set|no-as-set>]",
2160 NO_STR
2161 "BGP specific commands\n"
2162 "Change the default bestpath selection\n"
2163 "AS-path attribute\n"
2164 "Allow load sharing across routes that have different AS paths (but same length)\n"
2165 "Generate an AS_SET\n"
2166 "Do not generate an AS_SET\n")
2167 {
2168 VTY_DECLVAR_CONTEXT(bgp, bgp);
2169 bgp_flag_unset(bgp, BGP_FLAG_ASPATH_MULTIPATH_RELAX);
2170 bgp_flag_unset(bgp, BGP_FLAG_MULTIPATH_RELAX_AS_SET);
2171 bgp_recalculate_all_bestpaths(bgp);
2172
2173 return CMD_SUCCESS;
2174 }
2175
2176 /* "bgp log-neighbor-changes" configuration. */
2177 DEFUN (bgp_log_neighbor_changes,
2178 bgp_log_neighbor_changes_cmd,
2179 "bgp log-neighbor-changes",
2180 "BGP specific commands\n"
2181 "Log neighbor up/down and reset reason\n")
2182 {
2183 VTY_DECLVAR_CONTEXT(bgp, bgp);
2184 bgp_flag_set(bgp, BGP_FLAG_LOG_NEIGHBOR_CHANGES);
2185 return CMD_SUCCESS;
2186 }
2187
2188 DEFUN (no_bgp_log_neighbor_changes,
2189 no_bgp_log_neighbor_changes_cmd,
2190 "no bgp log-neighbor-changes",
2191 NO_STR
2192 "BGP specific commands\n"
2193 "Log neighbor up/down and reset reason\n")
2194 {
2195 VTY_DECLVAR_CONTEXT(bgp, bgp);
2196 bgp_flag_unset(bgp, BGP_FLAG_LOG_NEIGHBOR_CHANGES);
2197 return CMD_SUCCESS;
2198 }
2199
2200 /* "bgp bestpath med" configuration. */
2201 DEFUN (bgp_bestpath_med,
2202 bgp_bestpath_med_cmd,
2203 "bgp bestpath med <confed [missing-as-worst]|missing-as-worst [confed]>",
2204 "BGP specific commands\n"
2205 "Change the default bestpath selection\n"
2206 "MED attribute\n"
2207 "Compare MED among confederation paths\n"
2208 "Treat missing MED as the least preferred one\n"
2209 "Treat missing MED as the least preferred one\n"
2210 "Compare MED among confederation paths\n")
2211 {
2212 VTY_DECLVAR_CONTEXT(bgp, bgp);
2213
2214 int idx = 0;
2215 if (argv_find(argv, argc, "confed", &idx))
2216 bgp_flag_set(bgp, BGP_FLAG_MED_CONFED);
2217 idx = 0;
2218 if (argv_find(argv, argc, "missing-as-worst", &idx))
2219 bgp_flag_set(bgp, BGP_FLAG_MED_MISSING_AS_WORST);
2220
2221 bgp_recalculate_all_bestpaths(bgp);
2222
2223 return CMD_SUCCESS;
2224 }
2225
2226 DEFUN (no_bgp_bestpath_med,
2227 no_bgp_bestpath_med_cmd,
2228 "no bgp bestpath med <confed [missing-as-worst]|missing-as-worst [confed]>",
2229 NO_STR
2230 "BGP specific commands\n"
2231 "Change the default bestpath selection\n"
2232 "MED attribute\n"
2233 "Compare MED among confederation paths\n"
2234 "Treat missing MED as the least preferred one\n"
2235 "Treat missing MED as the least preferred one\n"
2236 "Compare MED among confederation paths\n")
2237 {
2238 VTY_DECLVAR_CONTEXT(bgp, bgp);
2239
2240 int idx = 0;
2241 if (argv_find(argv, argc, "confed", &idx))
2242 bgp_flag_unset(bgp, BGP_FLAG_MED_CONFED);
2243 idx = 0;
2244 if (argv_find(argv, argc, "missing-as-worst", &idx))
2245 bgp_flag_unset(bgp, BGP_FLAG_MED_MISSING_AS_WORST);
2246
2247 bgp_recalculate_all_bestpaths(bgp);
2248
2249 return CMD_SUCCESS;
2250 }
2251
2252 /* "no bgp default ipv4-unicast". */
2253 DEFUN (no_bgp_default_ipv4_unicast,
2254 no_bgp_default_ipv4_unicast_cmd,
2255 "no bgp default ipv4-unicast",
2256 NO_STR
2257 "BGP specific commands\n"
2258 "Configure BGP defaults\n"
2259 "Activate ipv4-unicast for a peer by default\n")
2260 {
2261 VTY_DECLVAR_CONTEXT(bgp, bgp);
2262 bgp_flag_set(bgp, BGP_FLAG_NO_DEFAULT_IPV4);
2263 return CMD_SUCCESS;
2264 }
2265
2266 DEFUN (bgp_default_ipv4_unicast,
2267 bgp_default_ipv4_unicast_cmd,
2268 "bgp default ipv4-unicast",
2269 "BGP specific commands\n"
2270 "Configure BGP defaults\n"
2271 "Activate ipv4-unicast for a peer by default\n")
2272 {
2273 VTY_DECLVAR_CONTEXT(bgp, bgp);
2274 bgp_flag_unset(bgp, BGP_FLAG_NO_DEFAULT_IPV4);
2275 return CMD_SUCCESS;
2276 }
2277
2278 /* Display hostname in certain command outputs */
2279 DEFUN (bgp_default_show_hostname,
2280 bgp_default_show_hostname_cmd,
2281 "bgp default show-hostname",
2282 "BGP specific commands\n"
2283 "Configure BGP defaults\n"
2284 "Show hostname in certain command ouputs\n")
2285 {
2286 VTY_DECLVAR_CONTEXT(bgp, bgp);
2287 bgp_flag_set(bgp, BGP_FLAG_SHOW_HOSTNAME);
2288 return CMD_SUCCESS;
2289 }
2290
2291 DEFUN (no_bgp_default_show_hostname,
2292 no_bgp_default_show_hostname_cmd,
2293 "no bgp default show-hostname",
2294 NO_STR
2295 "BGP specific commands\n"
2296 "Configure BGP defaults\n"
2297 "Show hostname in certain command ouputs\n")
2298 {
2299 VTY_DECLVAR_CONTEXT(bgp, bgp);
2300 bgp_flag_unset(bgp, BGP_FLAG_SHOW_HOSTNAME);
2301 return CMD_SUCCESS;
2302 }
2303
2304 /* "bgp network import-check" configuration. */
2305 DEFUN (bgp_network_import_check,
2306 bgp_network_import_check_cmd,
2307 "bgp network import-check",
2308 "BGP specific commands\n"
2309 "BGP network command\n"
2310 "Check BGP network route exists in IGP\n")
2311 {
2312 VTY_DECLVAR_CONTEXT(bgp, bgp);
2313 if (!bgp_flag_check(bgp, BGP_FLAG_IMPORT_CHECK)) {
2314 bgp_flag_set(bgp, BGP_FLAG_IMPORT_CHECK);
2315 bgp_static_redo_import_check(bgp);
2316 }
2317
2318 return CMD_SUCCESS;
2319 }
2320
2321 ALIAS_HIDDEN(bgp_network_import_check, bgp_network_import_check_exact_cmd,
2322 "bgp network import-check exact",
2323 "BGP specific commands\n"
2324 "BGP network command\n"
2325 "Check BGP network route exists in IGP\n"
2326 "Match route precisely\n")
2327
2328 DEFUN (no_bgp_network_import_check,
2329 no_bgp_network_import_check_cmd,
2330 "no bgp network import-check",
2331 NO_STR
2332 "BGP specific commands\n"
2333 "BGP network command\n"
2334 "Check BGP network route exists in IGP\n")
2335 {
2336 VTY_DECLVAR_CONTEXT(bgp, bgp);
2337 if (bgp_flag_check(bgp, BGP_FLAG_IMPORT_CHECK)) {
2338 bgp_flag_unset(bgp, BGP_FLAG_IMPORT_CHECK);
2339 bgp_static_redo_import_check(bgp);
2340 }
2341
2342 return CMD_SUCCESS;
2343 }
2344
2345 DEFUN (bgp_default_local_preference,
2346 bgp_default_local_preference_cmd,
2347 "bgp default local-preference (0-4294967295)",
2348 "BGP specific commands\n"
2349 "Configure BGP defaults\n"
2350 "local preference (higher=more preferred)\n"
2351 "Configure default local preference value\n")
2352 {
2353 VTY_DECLVAR_CONTEXT(bgp, bgp);
2354 int idx_number = 3;
2355 uint32_t local_pref;
2356
2357 local_pref = strtoul(argv[idx_number]->arg, NULL, 10);
2358
2359 bgp_default_local_preference_set(bgp, local_pref);
2360 bgp_clear_star_soft_in(vty, bgp->name);
2361
2362 return CMD_SUCCESS;
2363 }
2364
2365 DEFUN (no_bgp_default_local_preference,
2366 no_bgp_default_local_preference_cmd,
2367 "no bgp default local-preference [(0-4294967295)]",
2368 NO_STR
2369 "BGP specific commands\n"
2370 "Configure BGP defaults\n"
2371 "local preference (higher=more preferred)\n"
2372 "Configure default local preference value\n")
2373 {
2374 VTY_DECLVAR_CONTEXT(bgp, bgp);
2375 bgp_default_local_preference_unset(bgp);
2376 bgp_clear_star_soft_in(vty, bgp->name);
2377
2378 return CMD_SUCCESS;
2379 }
2380
2381
2382 DEFUN (bgp_default_subgroup_pkt_queue_max,
2383 bgp_default_subgroup_pkt_queue_max_cmd,
2384 "bgp default subgroup-pkt-queue-max (20-100)",
2385 "BGP specific commands\n"
2386 "Configure BGP defaults\n"
2387 "subgroup-pkt-queue-max\n"
2388 "Configure subgroup packet queue max\n")
2389 {
2390 VTY_DECLVAR_CONTEXT(bgp, bgp);
2391 int idx_number = 3;
2392 uint32_t max_size;
2393
2394 max_size = strtoul(argv[idx_number]->arg, NULL, 10);
2395
2396 bgp_default_subgroup_pkt_queue_max_set(bgp, max_size);
2397
2398 return CMD_SUCCESS;
2399 }
2400
2401 DEFUN (no_bgp_default_subgroup_pkt_queue_max,
2402 no_bgp_default_subgroup_pkt_queue_max_cmd,
2403 "no bgp default subgroup-pkt-queue-max [(20-100)]",
2404 NO_STR
2405 "BGP specific commands\n"
2406 "Configure BGP defaults\n"
2407 "subgroup-pkt-queue-max\n"
2408 "Configure subgroup packet queue max\n")
2409 {
2410 VTY_DECLVAR_CONTEXT(bgp, bgp);
2411 bgp_default_subgroup_pkt_queue_max_unset(bgp);
2412 return CMD_SUCCESS;
2413 }
2414
2415
2416 DEFUN (bgp_rr_allow_outbound_policy,
2417 bgp_rr_allow_outbound_policy_cmd,
2418 "bgp route-reflector allow-outbound-policy",
2419 "BGP specific commands\n"
2420 "Allow modifications made by out route-map\n"
2421 "on ibgp neighbors\n")
2422 {
2423 VTY_DECLVAR_CONTEXT(bgp, bgp);
2424
2425 if (!bgp_flag_check(bgp, BGP_FLAG_RR_ALLOW_OUTBOUND_POLICY)) {
2426 bgp_flag_set(bgp, BGP_FLAG_RR_ALLOW_OUTBOUND_POLICY);
2427 update_group_announce_rrclients(bgp);
2428 bgp_clear_star_soft_out(vty, bgp->name);
2429 }
2430
2431 return CMD_SUCCESS;
2432 }
2433
2434 DEFUN (no_bgp_rr_allow_outbound_policy,
2435 no_bgp_rr_allow_outbound_policy_cmd,
2436 "no bgp route-reflector allow-outbound-policy",
2437 NO_STR
2438 "BGP specific commands\n"
2439 "Allow modifications made by out route-map\n"
2440 "on ibgp neighbors\n")
2441 {
2442 VTY_DECLVAR_CONTEXT(bgp, bgp);
2443
2444 if (bgp_flag_check(bgp, BGP_FLAG_RR_ALLOW_OUTBOUND_POLICY)) {
2445 bgp_flag_unset(bgp, BGP_FLAG_RR_ALLOW_OUTBOUND_POLICY);
2446 update_group_announce_rrclients(bgp);
2447 bgp_clear_star_soft_out(vty, bgp->name);
2448 }
2449
2450 return CMD_SUCCESS;
2451 }
2452
2453 DEFUN (bgp_listen_limit,
2454 bgp_listen_limit_cmd,
2455 "bgp listen limit (1-5000)",
2456 "BGP specific commands\n"
2457 "Configure BGP defaults\n"
2458 "maximum number of BGP Dynamic Neighbors that can be created\n"
2459 "Configure Dynamic Neighbors listen limit value\n")
2460 {
2461 VTY_DECLVAR_CONTEXT(bgp, bgp);
2462 int idx_number = 3;
2463 int listen_limit;
2464
2465 listen_limit = strtoul(argv[idx_number]->arg, NULL, 10);
2466
2467 bgp_listen_limit_set(bgp, listen_limit);
2468
2469 return CMD_SUCCESS;
2470 }
2471
2472 DEFUN (no_bgp_listen_limit,
2473 no_bgp_listen_limit_cmd,
2474 "no bgp listen limit [(1-5000)]",
2475 "BGP specific commands\n"
2476 "Configure BGP defaults\n"
2477 "unset maximum number of BGP Dynamic Neighbors that can be created\n"
2478 "Configure Dynamic Neighbors listen limit value to default\n"
2479 "Configure Dynamic Neighbors listen limit value\n")
2480 {
2481 VTY_DECLVAR_CONTEXT(bgp, bgp);
2482 bgp_listen_limit_unset(bgp);
2483 return CMD_SUCCESS;
2484 }
2485
2486
2487 /*
2488 * Check if this listen range is already configured. Check for exact
2489 * match or overlap based on input.
2490 */
2491 static struct peer_group *listen_range_exists(struct bgp *bgp,
2492 struct prefix *range, int exact)
2493 {
2494 struct listnode *node, *nnode;
2495 struct listnode *node1, *nnode1;
2496 struct peer_group *group;
2497 struct prefix *lr;
2498 afi_t afi;
2499 int match;
2500
2501 afi = family2afi(range->family);
2502 for (ALL_LIST_ELEMENTS(bgp->group, node, nnode, group)) {
2503 for (ALL_LIST_ELEMENTS(group->listen_range[afi], node1, nnode1,
2504 lr)) {
2505 if (exact)
2506 match = prefix_same(range, lr);
2507 else
2508 match = (prefix_match(range, lr)
2509 || prefix_match(lr, range));
2510 if (match)
2511 return group;
2512 }
2513 }
2514
2515 return NULL;
2516 }
2517
2518 DEFUN (bgp_listen_range,
2519 bgp_listen_range_cmd,
2520 "bgp listen range <A.B.C.D/M|X:X::X:X/M> peer-group WORD",
2521 "BGP specific commands\n"
2522 "Configure BGP dynamic neighbors listen range\n"
2523 "Configure BGP dynamic neighbors listen range\n"
2524 NEIGHBOR_ADDR_STR
2525 "Member of the peer-group\n"
2526 "Peer-group name\n")
2527 {
2528 VTY_DECLVAR_CONTEXT(bgp, bgp);
2529 struct prefix range;
2530 struct peer_group *group, *existing_group;
2531 afi_t afi;
2532 int ret;
2533 int idx = 0;
2534
2535 argv_find(argv, argc, "A.B.C.D/M", &idx);
2536 argv_find(argv, argc, "X:X::X:X/M", &idx);
2537 char *prefix = argv[idx]->arg;
2538 argv_find(argv, argc, "WORD", &idx);
2539 char *peergroup = argv[idx]->arg;
2540
2541 /* Convert IP prefix string to struct prefix. */
2542 ret = str2prefix(prefix, &range);
2543 if (!ret) {
2544 vty_out(vty, "%% Malformed listen range\n");
2545 return CMD_WARNING_CONFIG_FAILED;
2546 }
2547
2548 afi = family2afi(range.family);
2549
2550 if (afi == AFI_IP6 && IN6_IS_ADDR_LINKLOCAL(&range.u.prefix6)) {
2551 vty_out(vty,
2552 "%% Malformed listen range (link-local address)\n");
2553 return CMD_WARNING_CONFIG_FAILED;
2554 }
2555
2556 apply_mask(&range);
2557
2558 /* Check if same listen range is already configured. */
2559 existing_group = listen_range_exists(bgp, &range, 1);
2560 if (existing_group) {
2561 if (strcmp(existing_group->name, peergroup) == 0)
2562 return CMD_SUCCESS;
2563 else {
2564 vty_out(vty,
2565 "%% Same listen range is attached to peer-group %s\n",
2566 existing_group->name);
2567 return CMD_WARNING_CONFIG_FAILED;
2568 }
2569 }
2570
2571 /* Check if an overlapping listen range exists. */
2572 if (listen_range_exists(bgp, &range, 0)) {
2573 vty_out(vty,
2574 "%% Listen range overlaps with existing listen range\n");
2575 return CMD_WARNING_CONFIG_FAILED;
2576 }
2577
2578 group = peer_group_lookup(bgp, peergroup);
2579 if (!group) {
2580 vty_out(vty, "%% Configure the peer-group first\n");
2581 return CMD_WARNING_CONFIG_FAILED;
2582 }
2583
2584 ret = peer_group_listen_range_add(group, &range);
2585 return bgp_vty_return(vty, ret);
2586 }
2587
2588 DEFUN (no_bgp_listen_range,
2589 no_bgp_listen_range_cmd,
2590 "no bgp listen range <A.B.C.D/M|X:X::X:X/M> peer-group WORD",
2591 NO_STR
2592 "BGP specific commands\n"
2593 "Unconfigure BGP dynamic neighbors listen range\n"
2594 "Unconfigure BGP dynamic neighbors listen range\n"
2595 NEIGHBOR_ADDR_STR
2596 "Member of the peer-group\n"
2597 "Peer-group name\n")
2598 {
2599 VTY_DECLVAR_CONTEXT(bgp, bgp);
2600 struct prefix range;
2601 struct peer_group *group;
2602 afi_t afi;
2603 int ret;
2604 int idx = 0;
2605
2606 argv_find(argv, argc, "A.B.C.D/M", &idx);
2607 argv_find(argv, argc, "X:X::X:X/M", &idx);
2608 char *prefix = argv[idx]->arg;
2609 argv_find(argv, argc, "WORD", &idx);
2610 char *peergroup = argv[idx]->arg;
2611
2612 /* Convert IP prefix string to struct prefix. */
2613 ret = str2prefix(prefix, &range);
2614 if (!ret) {
2615 vty_out(vty, "%% Malformed listen range\n");
2616 return CMD_WARNING_CONFIG_FAILED;
2617 }
2618
2619 afi = family2afi(range.family);
2620
2621 if (afi == AFI_IP6 && IN6_IS_ADDR_LINKLOCAL(&range.u.prefix6)) {
2622 vty_out(vty,
2623 "%% Malformed listen range (link-local address)\n");
2624 return CMD_WARNING_CONFIG_FAILED;
2625 }
2626
2627 apply_mask(&range);
2628
2629 group = peer_group_lookup(bgp, peergroup);
2630 if (!group) {
2631 vty_out(vty, "%% Peer-group does not exist\n");
2632 return CMD_WARNING_CONFIG_FAILED;
2633 }
2634
2635 ret = peer_group_listen_range_del(group, &range);
2636 return bgp_vty_return(vty, ret);
2637 }
2638
2639 void bgp_config_write_listen(struct vty *vty, struct bgp *bgp)
2640 {
2641 struct peer_group *group;
2642 struct listnode *node, *nnode, *rnode, *nrnode;
2643 struct prefix *range;
2644 afi_t afi;
2645 char buf[PREFIX2STR_BUFFER];
2646
2647 if (bgp->dynamic_neighbors_limit != BGP_DYNAMIC_NEIGHBORS_LIMIT_DEFAULT)
2648 vty_out(vty, " bgp listen limit %d\n",
2649 bgp->dynamic_neighbors_limit);
2650
2651 for (ALL_LIST_ELEMENTS(bgp->group, node, nnode, group)) {
2652 for (afi = AFI_IP; afi < AFI_MAX; afi++) {
2653 for (ALL_LIST_ELEMENTS(group->listen_range[afi], rnode,
2654 nrnode, range)) {
2655 prefix2str(range, buf, sizeof(buf));
2656 vty_out(vty,
2657 " bgp listen range %s peer-group %s\n",
2658 buf, group->name);
2659 }
2660 }
2661 }
2662 }
2663
2664
2665 DEFUN (bgp_disable_connected_route_check,
2666 bgp_disable_connected_route_check_cmd,
2667 "bgp disable-ebgp-connected-route-check",
2668 "BGP specific commands\n"
2669 "Disable checking if nexthop is connected on ebgp sessions\n")
2670 {
2671 VTY_DECLVAR_CONTEXT(bgp, bgp);
2672 bgp_flag_set(bgp, BGP_FLAG_DISABLE_NH_CONNECTED_CHK);
2673 bgp_clear_star_soft_in(vty, bgp->name);
2674
2675 return CMD_SUCCESS;
2676 }
2677
2678 DEFUN (no_bgp_disable_connected_route_check,
2679 no_bgp_disable_connected_route_check_cmd,
2680 "no bgp disable-ebgp-connected-route-check",
2681 NO_STR
2682 "BGP specific commands\n"
2683 "Disable checking if nexthop is connected on ebgp sessions\n")
2684 {
2685 VTY_DECLVAR_CONTEXT(bgp, bgp);
2686 bgp_flag_unset(bgp, BGP_FLAG_DISABLE_NH_CONNECTED_CHK);
2687 bgp_clear_star_soft_in(vty, bgp->name);
2688
2689 return CMD_SUCCESS;
2690 }
2691
2692
2693 static int peer_remote_as_vty(struct vty *vty, const char *peer_str,
2694 const char *as_str, afi_t afi, safi_t safi)
2695 {
2696 VTY_DECLVAR_CONTEXT(bgp, bgp);
2697 int ret;
2698 as_t as;
2699 int as_type = AS_SPECIFIED;
2700 union sockunion su;
2701
2702 if (as_str[0] == 'i') {
2703 as = 0;
2704 as_type = AS_INTERNAL;
2705 } else if (as_str[0] == 'e') {
2706 as = 0;
2707 as_type = AS_EXTERNAL;
2708 } else {
2709 /* Get AS number. */
2710 as = strtoul(as_str, NULL, 10);
2711 }
2712
2713 /* If peer is peer group, call proper function. */
2714 ret = str2sockunion(peer_str, &su);
2715 if (ret < 0) {
2716 /* Check for peer by interface */
2717 ret = peer_remote_as(bgp, NULL, peer_str, &as, as_type, afi,
2718 safi);
2719 if (ret < 0) {
2720 ret = peer_group_remote_as(bgp, peer_str, &as, as_type);
2721 if (ret < 0) {
2722 vty_out(vty,
2723 "%% Create the peer-group or interface first\n");
2724 return CMD_WARNING_CONFIG_FAILED;
2725 }
2726 return CMD_SUCCESS;
2727 }
2728 } else {
2729 if (peer_address_self_check(bgp, &su)) {
2730 vty_out(vty,
2731 "%% Can not configure the local system as neighbor\n");
2732 return CMD_WARNING_CONFIG_FAILED;
2733 }
2734 ret = peer_remote_as(bgp, &su, NULL, &as, as_type, afi, safi);
2735 }
2736
2737 /* This peer belongs to peer group. */
2738 switch (ret) {
2739 case BGP_ERR_PEER_GROUP_MEMBER:
2740 vty_out(vty,
2741 "%% Peer-group AS %u. Cannot configure remote-as for member\n",
2742 as);
2743 return CMD_WARNING_CONFIG_FAILED;
2744 case BGP_ERR_PEER_GROUP_PEER_TYPE_DIFFERENT:
2745 vty_out(vty,
2746 "%% The AS# can not be changed from %u to %s, peer-group members must be all internal or all external\n",
2747 as, as_str);
2748 return CMD_WARNING_CONFIG_FAILED;
2749 }
2750 return bgp_vty_return(vty, ret);
2751 }
2752
2753 DEFUN (bgp_default_shutdown,
2754 bgp_default_shutdown_cmd,
2755 "[no] bgp default shutdown",
2756 NO_STR
2757 BGP_STR
2758 "Configure BGP defaults\n"
2759 "Apply administrative shutdown to newly configured peers\n")
2760 {
2761 VTY_DECLVAR_CONTEXT(bgp, bgp);
2762 bgp->autoshutdown = !strmatch(argv[0]->text, "no");
2763 return CMD_SUCCESS;
2764 }
2765
2766 DEFUN (neighbor_remote_as,
2767 neighbor_remote_as_cmd,
2768 "neighbor <A.B.C.D|X:X::X:X|WORD> remote-as <(1-4294967295)|internal|external>",
2769 NEIGHBOR_STR
2770 NEIGHBOR_ADDR_STR2
2771 "Specify a BGP neighbor\n"
2772 AS_STR
2773 "Internal BGP peer\n"
2774 "External BGP peer\n")
2775 {
2776 int idx_peer = 1;
2777 int idx_remote_as = 3;
2778 return peer_remote_as_vty(vty, argv[idx_peer]->arg,
2779 argv[idx_remote_as]->arg, AFI_IP,
2780 SAFI_UNICAST);
2781 }
2782
2783 static int peer_conf_interface_get(struct vty *vty, const char *conf_if,
2784 afi_t afi, safi_t safi, int v6only,
2785 const char *peer_group_name,
2786 const char *as_str)
2787 {
2788 VTY_DECLVAR_CONTEXT(bgp, bgp);
2789 as_t as = 0;
2790 int as_type = AS_UNSPECIFIED;
2791 struct peer *peer;
2792 struct peer_group *group;
2793 int ret = 0;
2794 union sockunion su;
2795
2796 group = peer_group_lookup(bgp, conf_if);
2797
2798 if (group) {
2799 vty_out(vty, "%% Name conflict with peer-group \n");
2800 return CMD_WARNING_CONFIG_FAILED;
2801 }
2802
2803 if (as_str) {
2804 if (as_str[0] == 'i') {
2805 as_type = AS_INTERNAL;
2806 } else if (as_str[0] == 'e') {
2807 as_type = AS_EXTERNAL;
2808 } else {
2809 /* Get AS number. */
2810 as = strtoul(as_str, NULL, 10);
2811 as_type = AS_SPECIFIED;
2812 }
2813 }
2814
2815 peer = peer_lookup_by_conf_if(bgp, conf_if);
2816 if (peer) {
2817 if (as_str)
2818 ret = peer_remote_as(bgp, &su, conf_if, &as, as_type,
2819 afi, safi);
2820 } else {
2821 if (bgp_flag_check(bgp, BGP_FLAG_NO_DEFAULT_IPV4)
2822 && afi == AFI_IP && safi == SAFI_UNICAST)
2823 peer = peer_create(NULL, conf_if, bgp, bgp->as, as,
2824 as_type, 0, 0, NULL);
2825 else
2826 peer = peer_create(NULL, conf_if, bgp, bgp->as, as,
2827 as_type, afi, safi, NULL);
2828
2829 if (!peer) {
2830 vty_out(vty, "%% BGP failed to create peer\n");
2831 return CMD_WARNING_CONFIG_FAILED;
2832 }
2833
2834 if (v6only)
2835 SET_FLAG(peer->flags, PEER_FLAG_IFPEER_V6ONLY);
2836
2837 /* Request zebra to initiate IPv6 RAs on this interface. We do
2838 * this
2839 * any unnumbered peer in order to not worry about run-time
2840 * transitions
2841 * (e.g., peering is initially IPv4, but the IPv4 /30 or /31
2842 * address
2843 * gets deleted later etc.)
2844 */
2845 if (peer->ifp)
2846 bgp_zebra_initiate_radv(bgp, peer);
2847 }
2848
2849 if ((v6only && !CHECK_FLAG(peer->flags, PEER_FLAG_IFPEER_V6ONLY))
2850 || (!v6only && CHECK_FLAG(peer->flags, PEER_FLAG_IFPEER_V6ONLY))) {
2851 if (v6only)
2852 SET_FLAG(peer->flags, PEER_FLAG_IFPEER_V6ONLY);
2853 else
2854 UNSET_FLAG(peer->flags, PEER_FLAG_IFPEER_V6ONLY);
2855
2856 /* v6only flag changed. Reset bgp seesion */
2857 if (BGP_IS_VALID_STATE_FOR_NOTIF(peer->status)) {
2858 peer->last_reset = PEER_DOWN_V6ONLY_CHANGE;
2859 bgp_notify_send(peer, BGP_NOTIFY_CEASE,
2860 BGP_NOTIFY_CEASE_CONFIG_CHANGE);
2861 } else
2862 bgp_session_reset(peer);
2863 }
2864
2865 if (!CHECK_FLAG(peer->flags, PEER_FLAG_CAPABILITY_ENHE))
2866 peer_flag_set(peer, PEER_FLAG_CAPABILITY_ENHE);
2867
2868 if (peer_group_name) {
2869 group = peer_group_lookup(bgp, peer_group_name);
2870 if (!group) {
2871 vty_out(vty, "%% Configure the peer-group first\n");
2872 return CMD_WARNING_CONFIG_FAILED;
2873 }
2874
2875 ret = peer_group_bind(bgp, &su, peer, group, &as);
2876 }
2877
2878 return bgp_vty_return(vty, ret);
2879 }
2880
2881 DEFUN (neighbor_interface_config,
2882 neighbor_interface_config_cmd,
2883 "neighbor WORD interface [peer-group WORD]",
2884 NEIGHBOR_STR
2885 "Interface name or neighbor tag\n"
2886 "Enable BGP on interface\n"
2887 "Member of the peer-group\n"
2888 "Peer-group name\n")
2889 {
2890 int idx_word = 1;
2891 int idx_peer_group_word = 4;
2892
2893 if (argc > idx_peer_group_word)
2894 return peer_conf_interface_get(
2895 vty, argv[idx_word]->arg, AFI_IP, SAFI_UNICAST, 0,
2896 argv[idx_peer_group_word]->arg, NULL);
2897 else
2898 return peer_conf_interface_get(vty, argv[idx_word]->arg, AFI_IP,
2899 SAFI_UNICAST, 0, NULL, NULL);
2900 }
2901
2902 DEFUN (neighbor_interface_config_v6only,
2903 neighbor_interface_config_v6only_cmd,
2904 "neighbor WORD interface v6only [peer-group WORD]",
2905 NEIGHBOR_STR
2906 "Interface name or neighbor tag\n"
2907 "Enable BGP on interface\n"
2908 "Enable BGP with v6 link-local only\n"
2909 "Member of the peer-group\n"
2910 "Peer-group name\n")
2911 {
2912 int idx_word = 1;
2913 int idx_peer_group_word = 5;
2914
2915 if (argc > idx_peer_group_word)
2916 return peer_conf_interface_get(
2917 vty, argv[idx_word]->arg, AFI_IP, SAFI_UNICAST, 1,
2918 argv[idx_peer_group_word]->arg, NULL);
2919
2920 return peer_conf_interface_get(vty, argv[idx_word]->arg, AFI_IP,
2921 SAFI_UNICAST, 1, NULL, NULL);
2922 }
2923
2924
2925 DEFUN (neighbor_interface_config_remote_as,
2926 neighbor_interface_config_remote_as_cmd,
2927 "neighbor WORD interface remote-as <(1-4294967295)|internal|external>",
2928 NEIGHBOR_STR
2929 "Interface name or neighbor tag\n"
2930 "Enable BGP on interface\n"
2931 "Specify a BGP neighbor\n"
2932 AS_STR
2933 "Internal BGP peer\n"
2934 "External BGP peer\n")
2935 {
2936 int idx_word = 1;
2937 int idx_remote_as = 4;
2938 return peer_conf_interface_get(vty, argv[idx_word]->arg, AFI_IP,
2939 SAFI_UNICAST, 0, NULL,
2940 argv[idx_remote_as]->arg);
2941 }
2942
2943 DEFUN (neighbor_interface_v6only_config_remote_as,
2944 neighbor_interface_v6only_config_remote_as_cmd,
2945 "neighbor WORD interface v6only remote-as <(1-4294967295)|internal|external>",
2946 NEIGHBOR_STR
2947 "Interface name or neighbor tag\n"
2948 "Enable BGP with v6 link-local only\n"
2949 "Enable BGP on interface\n"
2950 "Specify a BGP neighbor\n"
2951 AS_STR
2952 "Internal BGP peer\n"
2953 "External BGP peer\n")
2954 {
2955 int idx_word = 1;
2956 int idx_remote_as = 5;
2957 return peer_conf_interface_get(vty, argv[idx_word]->arg, AFI_IP,
2958 SAFI_UNICAST, 1, NULL,
2959 argv[idx_remote_as]->arg);
2960 }
2961
2962 DEFUN (neighbor_peer_group,
2963 neighbor_peer_group_cmd,
2964 "neighbor WORD peer-group",
2965 NEIGHBOR_STR
2966 "Interface name or neighbor tag\n"
2967 "Configure peer-group\n")
2968 {
2969 VTY_DECLVAR_CONTEXT(bgp, bgp);
2970 int idx_word = 1;
2971 struct peer *peer;
2972 struct peer_group *group;
2973
2974 peer = peer_lookup_by_conf_if(bgp, argv[idx_word]->arg);
2975 if (peer) {
2976 vty_out(vty, "%% Name conflict with interface: \n");
2977 return CMD_WARNING_CONFIG_FAILED;
2978 }
2979
2980 group = peer_group_get(bgp, argv[idx_word]->arg);
2981 if (!group) {
2982 vty_out(vty, "%% BGP failed to find or create peer-group\n");
2983 return CMD_WARNING_CONFIG_FAILED;
2984 }
2985
2986 return CMD_SUCCESS;
2987 }
2988
2989 DEFUN (no_neighbor,
2990 no_neighbor_cmd,
2991 "no neighbor <WORD|<A.B.C.D|X:X::X:X> [remote-as <(1-4294967295)|internal|external>]>",
2992 NO_STR
2993 NEIGHBOR_STR
2994 NEIGHBOR_ADDR_STR2
2995 "Specify a BGP neighbor\n"
2996 AS_STR
2997 "Internal BGP peer\n"
2998 "External BGP peer\n")
2999 {
3000 VTY_DECLVAR_CONTEXT(bgp, bgp);
3001 int idx_peer = 2;
3002 int ret;
3003 union sockunion su;
3004 struct peer_group *group;
3005 struct peer *peer;
3006 struct peer *other;
3007
3008 ret = str2sockunion(argv[idx_peer]->arg, &su);
3009 if (ret < 0) {
3010 /* look up for neighbor by interface name config. */
3011 peer = peer_lookup_by_conf_if(bgp, argv[idx_peer]->arg);
3012 if (peer) {
3013 /* Request zebra to terminate IPv6 RAs on this
3014 * interface. */
3015 if (peer->ifp)
3016 bgp_zebra_terminate_radv(peer->bgp, peer);
3017 peer_delete(peer);
3018 return CMD_SUCCESS;
3019 }
3020
3021 group = peer_group_lookup(bgp, argv[idx_peer]->arg);
3022 if (group)
3023 peer_group_delete(group);
3024 else {
3025 vty_out(vty, "%% Create the peer-group first\n");
3026 return CMD_WARNING_CONFIG_FAILED;
3027 }
3028 } else {
3029 peer = peer_lookup(bgp, &su);
3030 if (peer) {
3031 if (peer_dynamic_neighbor(peer)) {
3032 vty_out(vty,
3033 "%% Operation not allowed on a dynamic neighbor\n");
3034 return CMD_WARNING_CONFIG_FAILED;
3035 }
3036
3037 other = peer->doppelganger;
3038 peer_delete(peer);
3039 if (other && other->status != Deleted)
3040 peer_delete(other);
3041 }
3042 }
3043
3044 return CMD_SUCCESS;
3045 }
3046
3047 DEFUN (no_neighbor_interface_config,
3048 no_neighbor_interface_config_cmd,
3049 "no neighbor WORD interface [v6only] [peer-group WORD] [remote-as <(1-4294967295)|internal|external>]",
3050 NO_STR
3051 NEIGHBOR_STR
3052 "Interface name\n"
3053 "Configure BGP on interface\n"
3054 "Enable BGP with v6 link-local only\n"
3055 "Member of the peer-group\n"
3056 "Peer-group name\n"
3057 "Specify a BGP neighbor\n"
3058 AS_STR
3059 "Internal BGP peer\n"
3060 "External BGP peer\n")
3061 {
3062 VTY_DECLVAR_CONTEXT(bgp, bgp);
3063 int idx_word = 2;
3064 struct peer *peer;
3065
3066 /* look up for neighbor by interface name config. */
3067 peer = peer_lookup_by_conf_if(bgp, argv[idx_word]->arg);
3068 if (peer) {
3069 /* Request zebra to terminate IPv6 RAs on this interface. */
3070 if (peer->ifp)
3071 bgp_zebra_terminate_radv(peer->bgp, peer);
3072 peer_delete(peer);
3073 } else {
3074 vty_out(vty, "%% Create the bgp interface first\n");
3075 return CMD_WARNING_CONFIG_FAILED;
3076 }
3077 return CMD_SUCCESS;
3078 }
3079
3080 DEFUN (no_neighbor_peer_group,
3081 no_neighbor_peer_group_cmd,
3082 "no neighbor WORD peer-group",
3083 NO_STR
3084 NEIGHBOR_STR
3085 "Neighbor tag\n"
3086 "Configure peer-group\n")
3087 {
3088 VTY_DECLVAR_CONTEXT(bgp, bgp);
3089 int idx_word = 2;
3090 struct peer_group *group;
3091
3092 group = peer_group_lookup(bgp, argv[idx_word]->arg);
3093 if (group)
3094 peer_group_delete(group);
3095 else {
3096 vty_out(vty, "%% Create the peer-group first\n");
3097 return CMD_WARNING_CONFIG_FAILED;
3098 }
3099 return CMD_SUCCESS;
3100 }
3101
3102 DEFUN (no_neighbor_interface_peer_group_remote_as,
3103 no_neighbor_interface_peer_group_remote_as_cmd,
3104 "no neighbor WORD remote-as <(1-4294967295)|internal|external>",
3105 NO_STR
3106 NEIGHBOR_STR
3107 "Interface name or neighbor tag\n"
3108 "Specify a BGP neighbor\n"
3109 AS_STR
3110 "Internal BGP peer\n"
3111 "External BGP peer\n")
3112 {
3113 VTY_DECLVAR_CONTEXT(bgp, bgp);
3114 int idx_word = 2;
3115 struct peer_group *group;
3116 struct peer *peer;
3117
3118 /* look up for neighbor by interface name config. */
3119 peer = peer_lookup_by_conf_if(bgp, argv[idx_word]->arg);
3120 if (peer) {
3121 peer_as_change(peer, 0, AS_SPECIFIED);
3122 return CMD_SUCCESS;
3123 }
3124
3125 group = peer_group_lookup(bgp, argv[idx_word]->arg);
3126 if (group)
3127 peer_group_remote_as_delete(group);
3128 else {
3129 vty_out(vty, "%% Create the peer-group or interface first\n");
3130 return CMD_WARNING_CONFIG_FAILED;
3131 }
3132 return CMD_SUCCESS;
3133 }
3134
3135 DEFUN (neighbor_local_as,
3136 neighbor_local_as_cmd,
3137 "neighbor <A.B.C.D|X:X::X:X|WORD> local-as (1-4294967295)",
3138 NEIGHBOR_STR
3139 NEIGHBOR_ADDR_STR2
3140 "Specify a local-as number\n"
3141 "AS number used as local AS\n")
3142 {
3143 int idx_peer = 1;
3144 int idx_number = 3;
3145 struct peer *peer;
3146 int ret;
3147 as_t as;
3148
3149 peer = peer_and_group_lookup_vty(vty, argv[idx_peer]->arg);
3150 if (!peer)
3151 return CMD_WARNING_CONFIG_FAILED;
3152
3153 as = strtoul(argv[idx_number]->arg, NULL, 10);
3154 ret = peer_local_as_set(peer, as, 0, 0);
3155 return bgp_vty_return(vty, ret);
3156 }
3157
3158 DEFUN (neighbor_local_as_no_prepend,
3159 neighbor_local_as_no_prepend_cmd,
3160 "neighbor <A.B.C.D|X:X::X:X|WORD> local-as (1-4294967295) no-prepend",
3161 NEIGHBOR_STR
3162 NEIGHBOR_ADDR_STR2
3163 "Specify a local-as number\n"
3164 "AS number used as local AS\n"
3165 "Do not prepend local-as to updates from ebgp peers\n")
3166 {
3167 int idx_peer = 1;
3168 int idx_number = 3;
3169 struct peer *peer;
3170 int ret;
3171 as_t as;
3172
3173 peer = peer_and_group_lookup_vty(vty, argv[idx_peer]->arg);
3174 if (!peer)
3175 return CMD_WARNING_CONFIG_FAILED;
3176
3177 as = strtoul(argv[idx_number]->arg, NULL, 10);
3178 ret = peer_local_as_set(peer, as, 1, 0);
3179 return bgp_vty_return(vty, ret);
3180 }
3181
3182 DEFUN (neighbor_local_as_no_prepend_replace_as,
3183 neighbor_local_as_no_prepend_replace_as_cmd,
3184 "neighbor <A.B.C.D|X:X::X:X|WORD> local-as (1-4294967295) no-prepend replace-as",
3185 NEIGHBOR_STR
3186 NEIGHBOR_ADDR_STR2
3187 "Specify a local-as number\n"
3188 "AS number used as local AS\n"
3189 "Do not prepend local-as to updates from ebgp peers\n"
3190 "Do not prepend local-as to updates from ibgp peers\n")
3191 {
3192 int idx_peer = 1;
3193 int idx_number = 3;
3194 struct peer *peer;
3195 int ret;
3196 as_t as;
3197
3198 peer = peer_and_group_lookup_vty(vty, argv[idx_peer]->arg);
3199 if (!peer)
3200 return CMD_WARNING_CONFIG_FAILED;
3201
3202 as = strtoul(argv[idx_number]->arg, NULL, 10);
3203 ret = peer_local_as_set(peer, as, 1, 1);
3204 return bgp_vty_return(vty, ret);
3205 }
3206
3207 DEFUN (no_neighbor_local_as,
3208 no_neighbor_local_as_cmd,
3209 "no neighbor <A.B.C.D|X:X::X:X|WORD> local-as [(1-4294967295) [no-prepend [replace-as]]]",
3210 NO_STR
3211 NEIGHBOR_STR
3212 NEIGHBOR_ADDR_STR2
3213 "Specify a local-as number\n"
3214 "AS number used as local AS\n"
3215 "Do not prepend local-as to updates from ebgp peers\n"
3216 "Do not prepend local-as to updates from ibgp peers\n")
3217 {
3218 int idx_peer = 2;
3219 struct peer *peer;
3220 int ret;
3221
3222 peer = peer_and_group_lookup_vty(vty, argv[idx_peer]->arg);
3223 if (!peer)
3224 return CMD_WARNING_CONFIG_FAILED;
3225
3226 ret = peer_local_as_unset(peer);
3227 return bgp_vty_return(vty, ret);
3228 }
3229
3230
3231 DEFUN (neighbor_solo,
3232 neighbor_solo_cmd,
3233 "neighbor <A.B.C.D|X:X::X:X|WORD> solo",
3234 NEIGHBOR_STR
3235 NEIGHBOR_ADDR_STR2
3236 "Solo peer - part of its own update group\n")
3237 {
3238 int idx_peer = 1;
3239 struct peer *peer;
3240 int ret;
3241
3242 peer = peer_and_group_lookup_vty(vty, argv[idx_peer]->arg);
3243 if (!peer)
3244 return CMD_WARNING_CONFIG_FAILED;
3245
3246 ret = update_group_adjust_soloness(peer, 1);
3247 return bgp_vty_return(vty, ret);
3248 }
3249
3250 DEFUN (no_neighbor_solo,
3251 no_neighbor_solo_cmd,
3252 "no neighbor <A.B.C.D|X:X::X:X|WORD> solo",
3253 NO_STR
3254 NEIGHBOR_STR
3255 NEIGHBOR_ADDR_STR2
3256 "Solo peer - part of its own update group\n")
3257 {
3258 int idx_peer = 2;
3259 struct peer *peer;
3260 int ret;
3261
3262 peer = peer_and_group_lookup_vty(vty, argv[idx_peer]->arg);
3263 if (!peer)
3264 return CMD_WARNING_CONFIG_FAILED;
3265
3266 ret = update_group_adjust_soloness(peer, 0);
3267 return bgp_vty_return(vty, ret);
3268 }
3269
3270 DEFUN (neighbor_password,
3271 neighbor_password_cmd,
3272 "neighbor <A.B.C.D|X:X::X:X|WORD> password LINE",
3273 NEIGHBOR_STR
3274 NEIGHBOR_ADDR_STR2
3275 "Set a password\n"
3276 "The password\n")
3277 {
3278 int idx_peer = 1;
3279 int idx_line = 3;
3280 struct peer *peer;
3281 int ret;
3282
3283 peer = peer_and_group_lookup_vty(vty, argv[idx_peer]->arg);
3284 if (!peer)
3285 return CMD_WARNING_CONFIG_FAILED;
3286
3287 ret = peer_password_set(peer, argv[idx_line]->arg);
3288 return bgp_vty_return(vty, ret);
3289 }
3290
3291 DEFUN (no_neighbor_password,
3292 no_neighbor_password_cmd,
3293 "no neighbor <A.B.C.D|X:X::X:X|WORD> password [LINE]",
3294 NO_STR
3295 NEIGHBOR_STR
3296 NEIGHBOR_ADDR_STR2
3297 "Set a password\n"
3298 "The password\n")
3299 {
3300 int idx_peer = 2;
3301 struct peer *peer;
3302 int ret;
3303
3304 peer = peer_and_group_lookup_vty(vty, argv[idx_peer]->arg);
3305 if (!peer)
3306 return CMD_WARNING_CONFIG_FAILED;
3307
3308 ret = peer_password_unset(peer);
3309 return bgp_vty_return(vty, ret);
3310 }
3311
3312 DEFUN (neighbor_activate,
3313 neighbor_activate_cmd,
3314 "neighbor <A.B.C.D|X:X::X:X|WORD> activate",
3315 NEIGHBOR_STR
3316 NEIGHBOR_ADDR_STR2
3317 "Enable the Address Family for this Neighbor\n")
3318 {
3319 int idx_peer = 1;
3320 int ret;
3321 struct peer *peer;
3322
3323 peer = peer_and_group_lookup_vty(vty, argv[idx_peer]->arg);
3324 if (!peer)
3325 return CMD_WARNING_CONFIG_FAILED;
3326
3327 ret = peer_activate(peer, bgp_node_afi(vty), bgp_node_safi(vty));
3328 return bgp_vty_return(vty, ret);
3329 }
3330
3331 ALIAS_HIDDEN(neighbor_activate, neighbor_activate_hidden_cmd,
3332 "neighbor <A.B.C.D|X:X::X:X|WORD> activate",
3333 NEIGHBOR_STR NEIGHBOR_ADDR_STR2
3334 "Enable the Address Family for this Neighbor\n")
3335
3336 DEFUN (no_neighbor_activate,
3337 no_neighbor_activate_cmd,
3338 "no neighbor <A.B.C.D|X:X::X:X|WORD> activate",
3339 NO_STR
3340 NEIGHBOR_STR
3341 NEIGHBOR_ADDR_STR2
3342 "Enable the Address Family for this Neighbor\n")
3343 {
3344 int idx_peer = 2;
3345 int ret;
3346 struct peer *peer;
3347
3348 /* Lookup peer. */
3349 peer = peer_and_group_lookup_vty(vty, argv[idx_peer]->arg);
3350 if (!peer)
3351 return CMD_WARNING_CONFIG_FAILED;
3352
3353 ret = peer_deactivate(peer, bgp_node_afi(vty), bgp_node_safi(vty));
3354 return bgp_vty_return(vty, ret);
3355 }
3356
3357 ALIAS_HIDDEN(no_neighbor_activate, no_neighbor_activate_hidden_cmd,
3358 "no neighbor <A.B.C.D|X:X::X:X|WORD> activate",
3359 NO_STR NEIGHBOR_STR NEIGHBOR_ADDR_STR2
3360 "Enable the Address Family for this Neighbor\n")
3361
3362 DEFUN (neighbor_set_peer_group,
3363 neighbor_set_peer_group_cmd,
3364 "neighbor <A.B.C.D|X:X::X:X|WORD> peer-group WORD",
3365 NEIGHBOR_STR
3366 NEIGHBOR_ADDR_STR2
3367 "Member of the peer-group\n"
3368 "Peer-group name\n")
3369 {
3370 VTY_DECLVAR_CONTEXT(bgp, bgp);
3371 int idx_peer = 1;
3372 int idx_word = 3;
3373 int ret;
3374 as_t as;
3375 union sockunion su;
3376 struct peer *peer;
3377 struct peer_group *group;
3378
3379 peer = NULL;
3380
3381 ret = str2sockunion(argv[idx_peer]->arg, &su);
3382 if (ret < 0) {
3383 peer = peer_lookup_by_conf_if(bgp, argv[idx_peer]->arg);
3384 if (!peer) {
3385 vty_out(vty, "%% Malformed address or name: %s\n",
3386 argv[idx_peer]->arg);
3387 return CMD_WARNING_CONFIG_FAILED;
3388 }
3389 } else {
3390 if (peer_address_self_check(bgp, &su)) {
3391 vty_out(vty,
3392 "%% Can not configure the local system as neighbor\n");
3393 return CMD_WARNING_CONFIG_FAILED;
3394 }
3395
3396 /* Disallow for dynamic neighbor. */
3397 peer = peer_lookup(bgp, &su);
3398 if (peer && peer_dynamic_neighbor(peer)) {
3399 vty_out(vty,
3400 "%% Operation not allowed on a dynamic neighbor\n");
3401 return CMD_WARNING_CONFIG_FAILED;
3402 }
3403 }
3404
3405 group = peer_group_lookup(bgp, argv[idx_word]->arg);
3406 if (!group) {
3407 vty_out(vty, "%% Configure the peer-group first\n");
3408 return CMD_WARNING_CONFIG_FAILED;
3409 }
3410
3411 ret = peer_group_bind(bgp, &su, peer, group, &as);
3412
3413 if (ret == BGP_ERR_PEER_GROUP_PEER_TYPE_DIFFERENT) {
3414 vty_out(vty,
3415 "%% Peer with AS %u cannot be in this peer-group, members must be all internal or all external\n",
3416 as);
3417 return CMD_WARNING_CONFIG_FAILED;
3418 }
3419
3420 return bgp_vty_return(vty, ret);
3421 }
3422
3423 ALIAS_HIDDEN(neighbor_set_peer_group, neighbor_set_peer_group_hidden_cmd,
3424 "neighbor <A.B.C.D|X:X::X:X|WORD> peer-group WORD",
3425 NEIGHBOR_STR NEIGHBOR_ADDR_STR2
3426 "Member of the peer-group\n"
3427 "Peer-group name\n")
3428
3429 DEFUN (no_neighbor_set_peer_group,
3430 no_neighbor_set_peer_group_cmd,
3431 "no neighbor <A.B.C.D|X:X::X:X|WORD> peer-group WORD",
3432 NO_STR
3433 NEIGHBOR_STR
3434 NEIGHBOR_ADDR_STR2
3435 "Member of the peer-group\n"
3436 "Peer-group name\n")
3437 {
3438 VTY_DECLVAR_CONTEXT(bgp, bgp);
3439 int idx_peer = 2;
3440 int idx_word = 4;
3441 int ret;
3442 struct peer *peer;
3443 struct peer_group *group;
3444
3445 peer = peer_lookup_vty(vty, argv[idx_peer]->arg);
3446 if (!peer)
3447 return CMD_WARNING_CONFIG_FAILED;
3448
3449 group = peer_group_lookup(bgp, argv[idx_word]->arg);
3450 if (!group) {
3451 vty_out(vty, "%% Configure the peer-group first\n");
3452 return CMD_WARNING_CONFIG_FAILED;
3453 }
3454
3455 ret = peer_delete(peer);
3456
3457 return bgp_vty_return(vty, ret);
3458 }
3459
3460 ALIAS_HIDDEN(no_neighbor_set_peer_group, no_neighbor_set_peer_group_hidden_cmd,
3461 "no neighbor <A.B.C.D|X:X::X:X|WORD> peer-group WORD",
3462 NO_STR NEIGHBOR_STR NEIGHBOR_ADDR_STR2
3463 "Member of the peer-group\n"
3464 "Peer-group name\n")
3465
3466 static int peer_flag_modify_vty(struct vty *vty, const char *ip_str,
3467 uint32_t flag, int set)
3468 {
3469 int ret;
3470 struct peer *peer;
3471
3472 peer = peer_and_group_lookup_vty(vty, ip_str);
3473 if (!peer)
3474 return CMD_WARNING_CONFIG_FAILED;
3475
3476 /*
3477 * If 'neighbor <interface>', then this is for directly connected peers,
3478 * we should not accept disable-connected-check.
3479 */
3480 if (peer->conf_if && (flag == PEER_FLAG_DISABLE_CONNECTED_CHECK)) {
3481 vty_out(vty,
3482 "%s is directly connected peer, cannot accept disable-"
3483 "connected-check\n",
3484 ip_str);
3485 return CMD_WARNING_CONFIG_FAILED;
3486 }
3487
3488 if (!set && flag == PEER_FLAG_SHUTDOWN)
3489 peer_tx_shutdown_message_unset(peer);
3490
3491 if (set)
3492 ret = peer_flag_set(peer, flag);
3493 else
3494 ret = peer_flag_unset(peer, flag);
3495
3496 return bgp_vty_return(vty, ret);
3497 }
3498
3499 static int peer_flag_set_vty(struct vty *vty, const char *ip_str, uint32_t flag)
3500 {
3501 return peer_flag_modify_vty(vty, ip_str, flag, 1);
3502 }
3503
3504 static int peer_flag_unset_vty(struct vty *vty, const char *ip_str,
3505 uint32_t flag)
3506 {
3507 return peer_flag_modify_vty(vty, ip_str, flag, 0);
3508 }
3509
3510 /* neighbor passive. */
3511 DEFUN (neighbor_passive,
3512 neighbor_passive_cmd,
3513 "neighbor <A.B.C.D|X:X::X:X|WORD> passive",
3514 NEIGHBOR_STR
3515 NEIGHBOR_ADDR_STR2
3516 "Don't send open messages to this neighbor\n")
3517 {
3518 int idx_peer = 1;
3519 return peer_flag_set_vty(vty, argv[idx_peer]->arg, PEER_FLAG_PASSIVE);
3520 }
3521
3522 DEFUN (no_neighbor_passive,
3523 no_neighbor_passive_cmd,
3524 "no neighbor <A.B.C.D|X:X::X:X|WORD> passive",
3525 NO_STR
3526 NEIGHBOR_STR
3527 NEIGHBOR_ADDR_STR2
3528 "Don't send open messages to this neighbor\n")
3529 {
3530 int idx_peer = 2;
3531 return peer_flag_unset_vty(vty, argv[idx_peer]->arg, PEER_FLAG_PASSIVE);
3532 }
3533
3534 /* neighbor shutdown. */
3535 DEFUN (neighbor_shutdown_msg,
3536 neighbor_shutdown_msg_cmd,
3537 "neighbor <A.B.C.D|X:X::X:X|WORD> shutdown message MSG...",
3538 NEIGHBOR_STR
3539 NEIGHBOR_ADDR_STR2
3540 "Administratively shut down this neighbor\n"
3541 "Add a shutdown message (draft-ietf-idr-shutdown-06)\n"
3542 "Shutdown message\n")
3543 {
3544 int idx_peer = 1;
3545
3546 if (argc >= 5) {
3547 struct peer *peer =
3548 peer_and_group_lookup_vty(vty, argv[idx_peer]->arg);
3549 char *message;
3550
3551 if (!peer)
3552 return CMD_WARNING_CONFIG_FAILED;
3553 message = argv_concat(argv, argc, 4);
3554 peer_tx_shutdown_message_set(peer, message);
3555 XFREE(MTYPE_TMP, message);
3556 }
3557
3558 return peer_flag_set_vty(vty, argv[idx_peer]->arg, PEER_FLAG_SHUTDOWN);
3559 }
3560
3561 ALIAS(neighbor_shutdown_msg, neighbor_shutdown_cmd,
3562 "neighbor <A.B.C.D|X:X::X:X|WORD> shutdown",
3563 NEIGHBOR_STR NEIGHBOR_ADDR_STR2
3564 "Administratively shut down this neighbor\n")
3565
3566 DEFUN (no_neighbor_shutdown_msg,
3567 no_neighbor_shutdown_msg_cmd,
3568 "no neighbor <A.B.C.D|X:X::X:X|WORD> shutdown message MSG...",
3569 NO_STR
3570 NEIGHBOR_STR
3571 NEIGHBOR_ADDR_STR2
3572 "Administratively shut down this neighbor\n"
3573 "Remove a shutdown message (draft-ietf-idr-shutdown-06)\n"
3574 "Shutdown message\n")
3575 {
3576 int idx_peer = 2;
3577
3578 return peer_flag_unset_vty(vty, argv[idx_peer]->arg,
3579 PEER_FLAG_SHUTDOWN);
3580 }
3581
3582 ALIAS(no_neighbor_shutdown_msg, no_neighbor_shutdown_cmd,
3583 "no neighbor <A.B.C.D|X:X::X:X|WORD> shutdown",
3584 NO_STR NEIGHBOR_STR NEIGHBOR_ADDR_STR2
3585 "Administratively shut down this neighbor\n")
3586
3587 /* neighbor capability dynamic. */
3588 DEFUN (neighbor_capability_dynamic,
3589 neighbor_capability_dynamic_cmd,
3590 "neighbor <A.B.C.D|X:X::X:X|WORD> capability dynamic",
3591 NEIGHBOR_STR
3592 NEIGHBOR_ADDR_STR2
3593 "Advertise capability to the peer\n"
3594 "Advertise dynamic capability to this neighbor\n")
3595 {
3596 int idx_peer = 1;
3597 return peer_flag_set_vty(vty, argv[idx_peer]->arg,
3598 PEER_FLAG_DYNAMIC_CAPABILITY);
3599 }
3600
3601 DEFUN (no_neighbor_capability_dynamic,
3602 no_neighbor_capability_dynamic_cmd,
3603 "no neighbor <A.B.C.D|X:X::X:X|WORD> capability dynamic",
3604 NO_STR
3605 NEIGHBOR_STR
3606 NEIGHBOR_ADDR_STR2
3607 "Advertise capability to the peer\n"
3608 "Advertise dynamic capability to this neighbor\n")
3609 {
3610 int idx_peer = 2;
3611 return peer_flag_unset_vty(vty, argv[idx_peer]->arg,
3612 PEER_FLAG_DYNAMIC_CAPABILITY);
3613 }
3614
3615 /* neighbor dont-capability-negotiate */
3616 DEFUN (neighbor_dont_capability_negotiate,
3617 neighbor_dont_capability_negotiate_cmd,
3618 "neighbor <A.B.C.D|X:X::X:X|WORD> dont-capability-negotiate",
3619 NEIGHBOR_STR
3620 NEIGHBOR_ADDR_STR2
3621 "Do not perform capability negotiation\n")
3622 {
3623 int idx_peer = 1;
3624 return peer_flag_set_vty(vty, argv[idx_peer]->arg,
3625 PEER_FLAG_DONT_CAPABILITY);
3626 }
3627
3628 DEFUN (no_neighbor_dont_capability_negotiate,
3629 no_neighbor_dont_capability_negotiate_cmd,
3630 "no neighbor <A.B.C.D|X:X::X:X|WORD> dont-capability-negotiate",
3631 NO_STR
3632 NEIGHBOR_STR
3633 NEIGHBOR_ADDR_STR2
3634 "Do not perform capability negotiation\n")
3635 {
3636 int idx_peer = 2;
3637 return peer_flag_unset_vty(vty, argv[idx_peer]->arg,
3638 PEER_FLAG_DONT_CAPABILITY);
3639 }
3640
3641 /* neighbor capability extended next hop encoding */
3642 DEFUN (neighbor_capability_enhe,
3643 neighbor_capability_enhe_cmd,
3644 "neighbor <A.B.C.D|X:X::X:X|WORD> capability extended-nexthop",
3645 NEIGHBOR_STR
3646 NEIGHBOR_ADDR_STR2
3647 "Advertise capability to the peer\n"
3648 "Advertise extended next-hop capability to the peer\n")
3649 {
3650 int idx_peer = 1;
3651 return peer_flag_set_vty(vty, argv[idx_peer]->arg,
3652 PEER_FLAG_CAPABILITY_ENHE);
3653 }
3654
3655 DEFUN (no_neighbor_capability_enhe,
3656 no_neighbor_capability_enhe_cmd,
3657 "no neighbor <A.B.C.D|X:X::X:X|WORD> capability extended-nexthop",
3658 NO_STR
3659 NEIGHBOR_STR
3660 NEIGHBOR_ADDR_STR2
3661 "Advertise capability to the peer\n"
3662 "Advertise extended next-hop capability to the peer\n")
3663 {
3664 int idx_peer = 2;
3665 return peer_flag_unset_vty(vty, argv[idx_peer]->arg,
3666 PEER_FLAG_CAPABILITY_ENHE);
3667 }
3668
3669 static int peer_af_flag_modify_vty(struct vty *vty, const char *peer_str,
3670 afi_t afi, safi_t safi, uint32_t flag,
3671 int set)
3672 {
3673 int ret;
3674 struct peer *peer;
3675
3676 peer = peer_and_group_lookup_vty(vty, peer_str);
3677 if (!peer)
3678 return CMD_WARNING_CONFIG_FAILED;
3679
3680 if (set)
3681 ret = peer_af_flag_set(peer, afi, safi, flag);
3682 else
3683 ret = peer_af_flag_unset(peer, afi, safi, flag);
3684
3685 return bgp_vty_return(vty, ret);
3686 }
3687
3688 static int peer_af_flag_set_vty(struct vty *vty, const char *peer_str,
3689 afi_t afi, safi_t safi, uint32_t flag)
3690 {
3691 return peer_af_flag_modify_vty(vty, peer_str, afi, safi, flag, 1);
3692 }
3693
3694 static int peer_af_flag_unset_vty(struct vty *vty, const char *peer_str,
3695 afi_t afi, safi_t safi, uint32_t flag)
3696 {
3697 return peer_af_flag_modify_vty(vty, peer_str, afi, safi, flag, 0);
3698 }
3699
3700 /* neighbor capability orf prefix-list. */
3701 DEFUN (neighbor_capability_orf_prefix,
3702 neighbor_capability_orf_prefix_cmd,
3703 "neighbor <A.B.C.D|X:X::X:X|WORD> capability orf prefix-list <both|send|receive>",
3704 NEIGHBOR_STR
3705 NEIGHBOR_ADDR_STR2
3706 "Advertise capability to the peer\n"
3707 "Advertise ORF capability to the peer\n"
3708 "Advertise prefixlist ORF capability to this neighbor\n"
3709 "Capability to SEND and RECEIVE the ORF to/from this neighbor\n"
3710 "Capability to RECEIVE the ORF from this neighbor\n"
3711 "Capability to SEND the ORF to this neighbor\n")
3712 {
3713 int idx_peer = 1;
3714 int idx_send_recv = 5;
3715 uint16_t flag = 0;
3716
3717 if (strmatch(argv[idx_send_recv]->text, "send"))
3718 flag = PEER_FLAG_ORF_PREFIX_SM;
3719 else if (strmatch(argv[idx_send_recv]->text, "receive"))
3720 flag = PEER_FLAG_ORF_PREFIX_RM;
3721 else if (strmatch(argv[idx_send_recv]->text, "both"))
3722 flag = PEER_FLAG_ORF_PREFIX_SM | PEER_FLAG_ORF_PREFIX_RM;
3723 else {
3724 vty_out(vty, "%% BGP invalid orf prefix-list option\n");
3725 return CMD_WARNING_CONFIG_FAILED;
3726 }
3727
3728 return peer_af_flag_set_vty(vty, argv[idx_peer]->arg, bgp_node_afi(vty),
3729 bgp_node_safi(vty), flag);
3730 }
3731
3732 ALIAS_HIDDEN(
3733 neighbor_capability_orf_prefix,
3734 neighbor_capability_orf_prefix_hidden_cmd,
3735 "neighbor <A.B.C.D|X:X::X:X|WORD> capability orf prefix-list <both|send|receive>",
3736 NEIGHBOR_STR NEIGHBOR_ADDR_STR2
3737 "Advertise capability to the peer\n"
3738 "Advertise ORF capability to the peer\n"
3739 "Advertise prefixlist ORF capability to this neighbor\n"
3740 "Capability to SEND and RECEIVE the ORF to/from this neighbor\n"
3741 "Capability to RECEIVE the ORF from this neighbor\n"
3742 "Capability to SEND the ORF to this neighbor\n")
3743
3744 DEFUN (no_neighbor_capability_orf_prefix,
3745 no_neighbor_capability_orf_prefix_cmd,
3746 "no neighbor <A.B.C.D|X:X::X:X|WORD> capability orf prefix-list <both|send|receive>",
3747 NO_STR
3748 NEIGHBOR_STR
3749 NEIGHBOR_ADDR_STR2
3750 "Advertise capability to the peer\n"
3751 "Advertise ORF capability to the peer\n"
3752 "Advertise prefixlist ORF capability to this neighbor\n"
3753 "Capability to SEND and RECEIVE the ORF to/from this neighbor\n"
3754 "Capability to RECEIVE the ORF from this neighbor\n"
3755 "Capability to SEND the ORF to this neighbor\n")
3756 {
3757 int idx_peer = 2;
3758 int idx_send_recv = 6;
3759 uint16_t flag = 0;
3760
3761 if (strmatch(argv[idx_send_recv]->text, "send"))
3762 flag = PEER_FLAG_ORF_PREFIX_SM;
3763 else if (strmatch(argv[idx_send_recv]->text, "receive"))
3764 flag = PEER_FLAG_ORF_PREFIX_RM;
3765 else if (strmatch(argv[idx_send_recv]->text, "both"))
3766 flag = PEER_FLAG_ORF_PREFIX_SM | PEER_FLAG_ORF_PREFIX_RM;
3767 else {
3768 vty_out(vty, "%% BGP invalid orf prefix-list option\n");
3769 return CMD_WARNING_CONFIG_FAILED;
3770 }
3771
3772 return peer_af_flag_unset_vty(vty, argv[idx_peer]->arg,
3773 bgp_node_afi(vty), bgp_node_safi(vty),
3774 flag);
3775 }
3776
3777 ALIAS_HIDDEN(
3778 no_neighbor_capability_orf_prefix,
3779 no_neighbor_capability_orf_prefix_hidden_cmd,
3780 "no neighbor <A.B.C.D|X:X::X:X|WORD> capability orf prefix-list <both|send|receive>",
3781 NO_STR NEIGHBOR_STR NEIGHBOR_ADDR_STR2
3782 "Advertise capability to the peer\n"
3783 "Advertise ORF capability to the peer\n"
3784 "Advertise prefixlist ORF capability to this neighbor\n"
3785 "Capability to SEND and RECEIVE the ORF to/from this neighbor\n"
3786 "Capability to RECEIVE the ORF from this neighbor\n"
3787 "Capability to SEND the ORF to this neighbor\n")
3788
3789 /* neighbor next-hop-self. */
3790 DEFUN (neighbor_nexthop_self,
3791 neighbor_nexthop_self_cmd,
3792 "neighbor <A.B.C.D|X:X::X:X|WORD> next-hop-self",
3793 NEIGHBOR_STR
3794 NEIGHBOR_ADDR_STR2
3795 "Disable the next hop calculation for this neighbor\n")
3796 {
3797 int idx_peer = 1;
3798 return peer_af_flag_set_vty(vty, argv[idx_peer]->arg, bgp_node_afi(vty),
3799 bgp_node_safi(vty), PEER_FLAG_NEXTHOP_SELF);
3800 }
3801
3802 ALIAS_HIDDEN(neighbor_nexthop_self, neighbor_nexthop_self_hidden_cmd,
3803 "neighbor <A.B.C.D|X:X::X:X|WORD> next-hop-self",
3804 NEIGHBOR_STR NEIGHBOR_ADDR_STR2
3805 "Disable the next hop calculation for this neighbor\n")
3806
3807 /* neighbor next-hop-self. */
3808 DEFUN (neighbor_nexthop_self_force,
3809 neighbor_nexthop_self_force_cmd,
3810 "neighbor <A.B.C.D|X:X::X:X|WORD> next-hop-self force",
3811 NEIGHBOR_STR
3812 NEIGHBOR_ADDR_STR2
3813 "Disable the next hop calculation for this neighbor\n"
3814 "Set the next hop to self for reflected routes\n")
3815 {
3816 int idx_peer = 1;
3817 return peer_af_flag_set_vty(vty, argv[idx_peer]->arg, bgp_node_afi(vty),
3818 bgp_node_safi(vty),
3819 PEER_FLAG_FORCE_NEXTHOP_SELF);
3820 }
3821
3822 ALIAS_HIDDEN(neighbor_nexthop_self_force,
3823 neighbor_nexthop_self_force_hidden_cmd,
3824 "neighbor <A.B.C.D|X:X::X:X|WORD> next-hop-self force",
3825 NEIGHBOR_STR NEIGHBOR_ADDR_STR2
3826 "Disable the next hop calculation for this neighbor\n"
3827 "Set the next hop to self for reflected routes\n")
3828
3829 DEFUN (no_neighbor_nexthop_self,
3830 no_neighbor_nexthop_self_cmd,
3831 "no neighbor <A.B.C.D|X:X::X:X|WORD> next-hop-self",
3832 NO_STR
3833 NEIGHBOR_STR
3834 NEIGHBOR_ADDR_STR2
3835 "Disable the next hop calculation for this neighbor\n")
3836 {
3837 int idx_peer = 2;
3838 return peer_af_flag_unset_vty(vty, argv[idx_peer]->arg,
3839 bgp_node_afi(vty), bgp_node_safi(vty),
3840 PEER_FLAG_NEXTHOP_SELF);
3841 }
3842
3843 ALIAS_HIDDEN(no_neighbor_nexthop_self, no_neighbor_nexthop_self_hidden_cmd,
3844 "no neighbor <A.B.C.D|X:X::X:X|WORD> next-hop-self",
3845 NO_STR NEIGHBOR_STR NEIGHBOR_ADDR_STR2
3846 "Disable the next hop calculation for this neighbor\n")
3847
3848 DEFUN (no_neighbor_nexthop_self_force,
3849 no_neighbor_nexthop_self_force_cmd,
3850 "no neighbor <A.B.C.D|X:X::X:X|WORD> next-hop-self force",
3851 NO_STR
3852 NEIGHBOR_STR
3853 NEIGHBOR_ADDR_STR2
3854 "Disable the next hop calculation for this neighbor\n"
3855 "Set the next hop to self for reflected routes\n")
3856 {
3857 int idx_peer = 2;
3858 return peer_af_flag_unset_vty(vty, argv[idx_peer]->arg,
3859 bgp_node_afi(vty), bgp_node_safi(vty),
3860 PEER_FLAG_FORCE_NEXTHOP_SELF);
3861 }
3862
3863 ALIAS_HIDDEN(no_neighbor_nexthop_self_force,
3864 no_neighbor_nexthop_self_force_hidden_cmd,
3865 "no neighbor <A.B.C.D|X:X::X:X|WORD> next-hop-self force",
3866 NO_STR NEIGHBOR_STR NEIGHBOR_ADDR_STR2
3867 "Disable the next hop calculation for this neighbor\n"
3868 "Set the next hop to self for reflected routes\n")
3869
3870 /* neighbor as-override */
3871 DEFUN (neighbor_as_override,
3872 neighbor_as_override_cmd,
3873 "neighbor <A.B.C.D|X:X::X:X|WORD> as-override",
3874 NEIGHBOR_STR
3875 NEIGHBOR_ADDR_STR2
3876 "Override ASNs in outbound updates if aspath equals remote-as\n")
3877 {
3878 int idx_peer = 1;
3879 return peer_af_flag_set_vty(vty, argv[idx_peer]->arg, bgp_node_afi(vty),
3880 bgp_node_safi(vty), PEER_FLAG_AS_OVERRIDE);
3881 }
3882
3883 ALIAS_HIDDEN(neighbor_as_override, neighbor_as_override_hidden_cmd,
3884 "neighbor <A.B.C.D|X:X::X:X|WORD> as-override",
3885 NEIGHBOR_STR NEIGHBOR_ADDR_STR2
3886 "Override ASNs in outbound updates if aspath equals remote-as\n")
3887
3888 DEFUN (no_neighbor_as_override,
3889 no_neighbor_as_override_cmd,
3890 "no neighbor <A.B.C.D|X:X::X:X|WORD> as-override",
3891 NO_STR
3892 NEIGHBOR_STR
3893 NEIGHBOR_ADDR_STR2
3894 "Override ASNs in outbound updates if aspath equals remote-as\n")
3895 {
3896 int idx_peer = 2;
3897 return peer_af_flag_unset_vty(vty, argv[idx_peer]->arg,
3898 bgp_node_afi(vty), bgp_node_safi(vty),
3899 PEER_FLAG_AS_OVERRIDE);
3900 }
3901
3902 ALIAS_HIDDEN(no_neighbor_as_override, no_neighbor_as_override_hidden_cmd,
3903 "no neighbor <A.B.C.D|X:X::X:X|WORD> as-override",
3904 NO_STR NEIGHBOR_STR NEIGHBOR_ADDR_STR2
3905 "Override ASNs in outbound updates if aspath equals remote-as\n")
3906
3907 /* neighbor remove-private-AS. */
3908 DEFUN (neighbor_remove_private_as,
3909 neighbor_remove_private_as_cmd,
3910 "neighbor <A.B.C.D|X:X::X:X|WORD> remove-private-AS",
3911 NEIGHBOR_STR
3912 NEIGHBOR_ADDR_STR2
3913 "Remove private ASNs in outbound updates\n")
3914 {
3915 int idx_peer = 1;
3916 return peer_af_flag_set_vty(vty, argv[idx_peer]->arg, bgp_node_afi(vty),
3917 bgp_node_safi(vty),
3918 PEER_FLAG_REMOVE_PRIVATE_AS);
3919 }
3920
3921 ALIAS_HIDDEN(neighbor_remove_private_as, neighbor_remove_private_as_hidden_cmd,
3922 "neighbor <A.B.C.D|X:X::X:X|WORD> remove-private-AS",
3923 NEIGHBOR_STR NEIGHBOR_ADDR_STR2
3924 "Remove private ASNs in outbound updates\n")
3925
3926 DEFUN (neighbor_remove_private_as_all,
3927 neighbor_remove_private_as_all_cmd,
3928 "neighbor <A.B.C.D|X:X::X:X|WORD> remove-private-AS all",
3929 NEIGHBOR_STR
3930 NEIGHBOR_ADDR_STR2
3931 "Remove private ASNs in outbound updates\n"
3932 "Apply to all AS numbers\n")
3933 {
3934 int idx_peer = 1;
3935 return peer_af_flag_set_vty(vty, argv[idx_peer]->arg, bgp_node_afi(vty),
3936 bgp_node_safi(vty),
3937 PEER_FLAG_REMOVE_PRIVATE_AS_ALL);
3938 }
3939
3940 ALIAS_HIDDEN(neighbor_remove_private_as_all,
3941 neighbor_remove_private_as_all_hidden_cmd,
3942 "neighbor <A.B.C.D|X:X::X:X|WORD> remove-private-AS all",
3943 NEIGHBOR_STR NEIGHBOR_ADDR_STR2
3944 "Remove private ASNs in outbound updates\n"
3945 "Apply to all AS numbers")
3946
3947 DEFUN (neighbor_remove_private_as_replace_as,
3948 neighbor_remove_private_as_replace_as_cmd,
3949 "neighbor <A.B.C.D|X:X::X:X|WORD> remove-private-AS replace-AS",
3950 NEIGHBOR_STR
3951 NEIGHBOR_ADDR_STR2
3952 "Remove private ASNs in outbound updates\n"
3953 "Replace private ASNs with our ASN in outbound updates\n")
3954 {
3955 int idx_peer = 1;
3956 return peer_af_flag_set_vty(vty, argv[idx_peer]->arg, bgp_node_afi(vty),
3957 bgp_node_safi(vty),
3958 PEER_FLAG_REMOVE_PRIVATE_AS_REPLACE);
3959 }
3960
3961 ALIAS_HIDDEN(neighbor_remove_private_as_replace_as,
3962 neighbor_remove_private_as_replace_as_hidden_cmd,
3963 "neighbor <A.B.C.D|X:X::X:X|WORD> remove-private-AS replace-AS",
3964 NEIGHBOR_STR NEIGHBOR_ADDR_STR2
3965 "Remove private ASNs in outbound updates\n"
3966 "Replace private ASNs with our ASN in outbound updates\n")
3967
3968 DEFUN (neighbor_remove_private_as_all_replace_as,
3969 neighbor_remove_private_as_all_replace_as_cmd,
3970 "neighbor <A.B.C.D|X:X::X:X|WORD> remove-private-AS all replace-AS",
3971 NEIGHBOR_STR
3972 NEIGHBOR_ADDR_STR2
3973 "Remove private ASNs in outbound updates\n"
3974 "Apply to all AS numbers\n"
3975 "Replace private ASNs with our ASN in outbound updates\n")
3976 {
3977 int idx_peer = 1;
3978 return peer_af_flag_set_vty(vty, argv[idx_peer]->arg, bgp_node_afi(vty),
3979 bgp_node_safi(vty),
3980 PEER_FLAG_REMOVE_PRIVATE_AS_ALL_REPLACE);
3981 }
3982
3983 ALIAS_HIDDEN(
3984 neighbor_remove_private_as_all_replace_as,
3985 neighbor_remove_private_as_all_replace_as_hidden_cmd,
3986 "neighbor <A.B.C.D|X:X::X:X|WORD> remove-private-AS all replace-AS",
3987 NEIGHBOR_STR NEIGHBOR_ADDR_STR2
3988 "Remove private ASNs in outbound updates\n"
3989 "Apply to all AS numbers\n"
3990 "Replace private ASNs with our ASN in outbound updates\n")
3991
3992 DEFUN (no_neighbor_remove_private_as,
3993 no_neighbor_remove_private_as_cmd,
3994 "no neighbor <A.B.C.D|X:X::X:X|WORD> remove-private-AS",
3995 NO_STR
3996 NEIGHBOR_STR
3997 NEIGHBOR_ADDR_STR2
3998 "Remove private ASNs in outbound updates\n")
3999 {
4000 int idx_peer = 2;
4001 return peer_af_flag_unset_vty(vty, argv[idx_peer]->arg,
4002 bgp_node_afi(vty), bgp_node_safi(vty),
4003 PEER_FLAG_REMOVE_PRIVATE_AS);
4004 }
4005
4006 ALIAS_HIDDEN(no_neighbor_remove_private_as,
4007 no_neighbor_remove_private_as_hidden_cmd,
4008 "no neighbor <A.B.C.D|X:X::X:X|WORD> remove-private-AS",
4009 NO_STR NEIGHBOR_STR NEIGHBOR_ADDR_STR2
4010 "Remove private ASNs in outbound updates\n")
4011
4012 DEFUN (no_neighbor_remove_private_as_all,
4013 no_neighbor_remove_private_as_all_cmd,
4014 "no neighbor <A.B.C.D|X:X::X:X|WORD> remove-private-AS all",
4015 NO_STR
4016 NEIGHBOR_STR
4017 NEIGHBOR_ADDR_STR2
4018 "Remove private ASNs in outbound updates\n"
4019 "Apply to all AS numbers\n")
4020 {
4021 int idx_peer = 2;
4022 return peer_af_flag_unset_vty(vty, argv[idx_peer]->arg,
4023 bgp_node_afi(vty), bgp_node_safi(vty),
4024 PEER_FLAG_REMOVE_PRIVATE_AS_ALL);
4025 }
4026
4027 ALIAS_HIDDEN(no_neighbor_remove_private_as_all,
4028 no_neighbor_remove_private_as_all_hidden_cmd,
4029 "no neighbor <A.B.C.D|X:X::X:X|WORD> remove-private-AS all",
4030 NO_STR NEIGHBOR_STR NEIGHBOR_ADDR_STR2
4031 "Remove private ASNs in outbound updates\n"
4032 "Apply to all AS numbers\n")
4033
4034 DEFUN (no_neighbor_remove_private_as_replace_as,
4035 no_neighbor_remove_private_as_replace_as_cmd,
4036 "no neighbor <A.B.C.D|X:X::X:X|WORD> remove-private-AS replace-AS",
4037 NO_STR
4038 NEIGHBOR_STR
4039 NEIGHBOR_ADDR_STR2
4040 "Remove private ASNs in outbound updates\n"
4041 "Replace private ASNs with our ASN in outbound updates\n")
4042 {
4043 int idx_peer = 2;
4044 return peer_af_flag_unset_vty(vty, argv[idx_peer]->arg,
4045 bgp_node_afi(vty), bgp_node_safi(vty),
4046 PEER_FLAG_REMOVE_PRIVATE_AS_REPLACE);
4047 }
4048
4049 ALIAS_HIDDEN(no_neighbor_remove_private_as_replace_as,
4050 no_neighbor_remove_private_as_replace_as_hidden_cmd,
4051 "no neighbor <A.B.C.D|X:X::X:X|WORD> remove-private-AS replace-AS",
4052 NO_STR NEIGHBOR_STR NEIGHBOR_ADDR_STR2
4053 "Remove private ASNs in outbound updates\n"
4054 "Replace private ASNs with our ASN in outbound updates\n")
4055
4056 DEFUN (no_neighbor_remove_private_as_all_replace_as,
4057 no_neighbor_remove_private_as_all_replace_as_cmd,
4058 "no neighbor <A.B.C.D|X:X::X:X|WORD> remove-private-AS all replace-AS",
4059 NO_STR
4060 NEIGHBOR_STR
4061 NEIGHBOR_ADDR_STR2
4062 "Remove private ASNs in outbound updates\n"
4063 "Apply to all AS numbers\n"
4064 "Replace private ASNs with our ASN in outbound updates\n")
4065 {
4066 int idx_peer = 2;
4067 return peer_af_flag_unset_vty(vty, argv[idx_peer]->arg,
4068 bgp_node_afi(vty), bgp_node_safi(vty),
4069 PEER_FLAG_REMOVE_PRIVATE_AS_ALL_REPLACE);
4070 }
4071
4072 ALIAS_HIDDEN(
4073 no_neighbor_remove_private_as_all_replace_as,
4074 no_neighbor_remove_private_as_all_replace_as_hidden_cmd,
4075 "no neighbor <A.B.C.D|X:X::X:X|WORD> remove-private-AS all replace-AS",
4076 NO_STR NEIGHBOR_STR NEIGHBOR_ADDR_STR2
4077 "Remove private ASNs in outbound updates\n"
4078 "Apply to all AS numbers\n"
4079 "Replace private ASNs with our ASN in outbound updates\n")
4080
4081
4082 /* neighbor send-community. */
4083 DEFUN (neighbor_send_community,
4084 neighbor_send_community_cmd,
4085 "neighbor <A.B.C.D|X:X::X:X|WORD> send-community",
4086 NEIGHBOR_STR
4087 NEIGHBOR_ADDR_STR2
4088 "Send Community attribute to this neighbor\n")
4089 {
4090 int idx_peer = 1;
4091
4092 return peer_af_flag_set_vty(vty, argv[idx_peer]->arg, bgp_node_afi(vty),
4093 bgp_node_safi(vty),
4094 PEER_FLAG_SEND_COMMUNITY);
4095 }
4096
4097 ALIAS_HIDDEN(neighbor_send_community, neighbor_send_community_hidden_cmd,
4098 "neighbor <A.B.C.D|X:X::X:X|WORD> send-community",
4099 NEIGHBOR_STR NEIGHBOR_ADDR_STR2
4100 "Send Community attribute to this neighbor\n")
4101
4102 DEFUN (no_neighbor_send_community,
4103 no_neighbor_send_community_cmd,
4104 "no neighbor <A.B.C.D|X:X::X:X|WORD> send-community",
4105 NO_STR
4106 NEIGHBOR_STR
4107 NEIGHBOR_ADDR_STR2
4108 "Send Community attribute to this neighbor\n")
4109 {
4110 int idx_peer = 2;
4111
4112 return peer_af_flag_unset_vty(vty, argv[idx_peer]->arg,
4113 bgp_node_afi(vty), bgp_node_safi(vty),
4114 PEER_FLAG_SEND_COMMUNITY);
4115 }
4116
4117 ALIAS_HIDDEN(no_neighbor_send_community, no_neighbor_send_community_hidden_cmd,
4118 "no neighbor <A.B.C.D|X:X::X:X|WORD> send-community",
4119 NO_STR NEIGHBOR_STR NEIGHBOR_ADDR_STR2
4120 "Send Community attribute to this neighbor\n")
4121
4122 /* neighbor send-community extended. */
4123 DEFUN (neighbor_send_community_type,
4124 neighbor_send_community_type_cmd,
4125 "neighbor <A.B.C.D|X:X::X:X|WORD> send-community <both|all|extended|standard|large>",
4126 NEIGHBOR_STR
4127 NEIGHBOR_ADDR_STR2
4128 "Send Community attribute to this neighbor\n"
4129 "Send Standard and Extended Community attributes\n"
4130 "Send Standard, Large and Extended Community attributes\n"
4131 "Send Extended Community attributes\n"
4132 "Send Standard Community attributes\n"
4133 "Send Large Community attributes\n")
4134 {
4135 int idx_peer = 1;
4136 uint32_t flag = 0;
4137 const char *type = argv[argc - 1]->text;
4138
4139 if (strmatch(type, "standard")) {
4140 SET_FLAG(flag, PEER_FLAG_SEND_COMMUNITY);
4141 } else if (strmatch(type, "extended")) {
4142 SET_FLAG(flag, PEER_FLAG_SEND_EXT_COMMUNITY);
4143 } else if (strmatch(type, "large")) {
4144 SET_FLAG(flag, PEER_FLAG_SEND_LARGE_COMMUNITY);
4145 } else if (strmatch(type, "both")) {
4146 SET_FLAG(flag, PEER_FLAG_SEND_COMMUNITY);
4147 SET_FLAG(flag, PEER_FLAG_SEND_EXT_COMMUNITY);
4148 } else { /* if (strmatch(type, "all")) */
4149 SET_FLAG(flag, PEER_FLAG_SEND_COMMUNITY);
4150 SET_FLAG(flag, PEER_FLAG_SEND_EXT_COMMUNITY);
4151 SET_FLAG(flag, PEER_FLAG_SEND_LARGE_COMMUNITY);
4152 }
4153
4154 return peer_af_flag_set_vty(vty, argv[idx_peer]->arg, bgp_node_afi(vty),
4155 bgp_node_safi(vty), flag);
4156 }
4157
4158 ALIAS_HIDDEN(
4159 neighbor_send_community_type, neighbor_send_community_type_hidden_cmd,
4160 "neighbor <A.B.C.D|X:X::X:X|WORD> send-community <both|all|extended|standard|large>",
4161 NEIGHBOR_STR NEIGHBOR_ADDR_STR2
4162 "Send Community attribute to this neighbor\n"
4163 "Send Standard and Extended Community attributes\n"
4164 "Send Standard, Large and Extended Community attributes\n"
4165 "Send Extended Community attributes\n"
4166 "Send Standard Community attributes\n"
4167 "Send Large Community attributes\n")
4168
4169 DEFUN (no_neighbor_send_community_type,
4170 no_neighbor_send_community_type_cmd,
4171 "no neighbor <A.B.C.D|X:X::X:X|WORD> send-community <both|all|extended|standard|large>",
4172 NO_STR
4173 NEIGHBOR_STR
4174 NEIGHBOR_ADDR_STR2
4175 "Send Community attribute to this neighbor\n"
4176 "Send Standard and Extended Community attributes\n"
4177 "Send Standard, Large and Extended Community attributes\n"
4178 "Send Extended Community attributes\n"
4179 "Send Standard Community attributes\n"
4180 "Send Large Community attributes\n")
4181 {
4182 int idx_peer = 2;
4183 uint32_t flag = 0;
4184 const char *type = argv[argc - 1]->text;
4185
4186 if (strmatch(type, "standard")) {
4187 SET_FLAG(flag, PEER_FLAG_SEND_COMMUNITY);
4188 } else if (strmatch(type, "extended")) {
4189 SET_FLAG(flag, PEER_FLAG_SEND_EXT_COMMUNITY);
4190 } else if (strmatch(type, "large")) {
4191 SET_FLAG(flag, PEER_FLAG_SEND_LARGE_COMMUNITY);
4192 } else if (strmatch(type, "both")) {
4193 SET_FLAG(flag, PEER_FLAG_SEND_COMMUNITY);
4194 SET_FLAG(flag, PEER_FLAG_SEND_EXT_COMMUNITY);
4195 } else { /* if (strmatch(type, "all")) */
4196 SET_FLAG(flag, PEER_FLAG_SEND_COMMUNITY);
4197 SET_FLAG(flag, PEER_FLAG_SEND_EXT_COMMUNITY);
4198 SET_FLAG(flag, PEER_FLAG_SEND_LARGE_COMMUNITY);
4199 }
4200
4201 return peer_af_flag_unset_vty(vty, argv[idx_peer]->arg,
4202 bgp_node_afi(vty), bgp_node_safi(vty),
4203 flag);
4204 }
4205
4206 ALIAS_HIDDEN(
4207 no_neighbor_send_community_type,
4208 no_neighbor_send_community_type_hidden_cmd,
4209 "no neighbor <A.B.C.D|X:X::X:X|WORD> send-community <both|all|extended|standard|large>",
4210 NO_STR NEIGHBOR_STR NEIGHBOR_ADDR_STR2
4211 "Send Community attribute to this neighbor\n"
4212 "Send Standard and Extended Community attributes\n"
4213 "Send Standard, Large and Extended Community attributes\n"
4214 "Send Extended Community attributes\n"
4215 "Send Standard Community attributes\n"
4216 "Send Large Community attributes\n")
4217
4218 /* neighbor soft-reconfig. */
4219 DEFUN (neighbor_soft_reconfiguration,
4220 neighbor_soft_reconfiguration_cmd,
4221 "neighbor <A.B.C.D|X:X::X:X|WORD> soft-reconfiguration inbound",
4222 NEIGHBOR_STR
4223 NEIGHBOR_ADDR_STR2
4224 "Per neighbor soft reconfiguration\n"
4225 "Allow inbound soft reconfiguration for this neighbor\n")
4226 {
4227 int idx_peer = 1;
4228 return peer_af_flag_set_vty(vty, argv[idx_peer]->arg, bgp_node_afi(vty),
4229 bgp_node_safi(vty),
4230 PEER_FLAG_SOFT_RECONFIG);
4231 }
4232
4233 ALIAS_HIDDEN(neighbor_soft_reconfiguration,
4234 neighbor_soft_reconfiguration_hidden_cmd,
4235 "neighbor <A.B.C.D|X:X::X:X|WORD> soft-reconfiguration inbound",
4236 NEIGHBOR_STR NEIGHBOR_ADDR_STR2
4237 "Per neighbor soft reconfiguration\n"
4238 "Allow inbound soft reconfiguration for this neighbor\n")
4239
4240 DEFUN (no_neighbor_soft_reconfiguration,
4241 no_neighbor_soft_reconfiguration_cmd,
4242 "no neighbor <A.B.C.D|X:X::X:X|WORD> soft-reconfiguration inbound",
4243 NO_STR
4244 NEIGHBOR_STR
4245 NEIGHBOR_ADDR_STR2
4246 "Per neighbor soft reconfiguration\n"
4247 "Allow inbound soft reconfiguration for this neighbor\n")
4248 {
4249 int idx_peer = 2;
4250 return peer_af_flag_unset_vty(vty, argv[idx_peer]->arg,
4251 bgp_node_afi(vty), bgp_node_safi(vty),
4252 PEER_FLAG_SOFT_RECONFIG);
4253 }
4254
4255 ALIAS_HIDDEN(no_neighbor_soft_reconfiguration,
4256 no_neighbor_soft_reconfiguration_hidden_cmd,
4257 "no neighbor <A.B.C.D|X:X::X:X|WORD> soft-reconfiguration inbound",
4258 NO_STR NEIGHBOR_STR NEIGHBOR_ADDR_STR2
4259 "Per neighbor soft reconfiguration\n"
4260 "Allow inbound soft reconfiguration for this neighbor\n")
4261
4262 DEFUN (neighbor_route_reflector_client,
4263 neighbor_route_reflector_client_cmd,
4264 "neighbor <A.B.C.D|X:X::X:X|WORD> route-reflector-client",
4265 NEIGHBOR_STR
4266 NEIGHBOR_ADDR_STR2
4267 "Configure a neighbor as Route Reflector client\n")
4268 {
4269 int idx_peer = 1;
4270 struct peer *peer;
4271
4272
4273 peer = peer_and_group_lookup_vty(vty, argv[idx_peer]->arg);
4274 if (!peer)
4275 return CMD_WARNING_CONFIG_FAILED;
4276
4277 return peer_af_flag_set_vty(vty, argv[idx_peer]->arg, bgp_node_afi(vty),
4278 bgp_node_safi(vty),
4279 PEER_FLAG_REFLECTOR_CLIENT);
4280 }
4281
4282 ALIAS_HIDDEN(neighbor_route_reflector_client,
4283 neighbor_route_reflector_client_hidden_cmd,
4284 "neighbor <A.B.C.D|X:X::X:X|WORD> route-reflector-client",
4285 NEIGHBOR_STR NEIGHBOR_ADDR_STR2
4286 "Configure a neighbor as Route Reflector client\n")
4287
4288 DEFUN (no_neighbor_route_reflector_client,
4289 no_neighbor_route_reflector_client_cmd,
4290 "no neighbor <A.B.C.D|X:X::X:X|WORD> route-reflector-client",
4291 NO_STR
4292 NEIGHBOR_STR
4293 NEIGHBOR_ADDR_STR2
4294 "Configure a neighbor as Route Reflector client\n")
4295 {
4296 int idx_peer = 2;
4297 return peer_af_flag_unset_vty(vty, argv[idx_peer]->arg,
4298 bgp_node_afi(vty), bgp_node_safi(vty),
4299 PEER_FLAG_REFLECTOR_CLIENT);
4300 }
4301
4302 ALIAS_HIDDEN(no_neighbor_route_reflector_client,
4303 no_neighbor_route_reflector_client_hidden_cmd,
4304 "no neighbor <A.B.C.D|X:X::X:X|WORD> route-reflector-client",
4305 NO_STR NEIGHBOR_STR NEIGHBOR_ADDR_STR2
4306 "Configure a neighbor as Route Reflector client\n")
4307
4308 /* neighbor route-server-client. */
4309 DEFUN (neighbor_route_server_client,
4310 neighbor_route_server_client_cmd,
4311 "neighbor <A.B.C.D|X:X::X:X|WORD> route-server-client",
4312 NEIGHBOR_STR
4313 NEIGHBOR_ADDR_STR2
4314 "Configure a neighbor as Route Server client\n")
4315 {
4316 int idx_peer = 1;
4317 struct peer *peer;
4318
4319 peer = peer_and_group_lookup_vty(vty, argv[idx_peer]->arg);
4320 if (!peer)
4321 return CMD_WARNING_CONFIG_FAILED;
4322 return peer_af_flag_set_vty(vty, argv[idx_peer]->arg, bgp_node_afi(vty),
4323 bgp_node_safi(vty),
4324 PEER_FLAG_RSERVER_CLIENT);
4325 }
4326
4327 ALIAS_HIDDEN(neighbor_route_server_client,
4328 neighbor_route_server_client_hidden_cmd,
4329 "neighbor <A.B.C.D|X:X::X:X|WORD> route-server-client",
4330 NEIGHBOR_STR NEIGHBOR_ADDR_STR2
4331 "Configure a neighbor as Route Server client\n")
4332
4333 DEFUN (no_neighbor_route_server_client,
4334 no_neighbor_route_server_client_cmd,
4335 "no neighbor <A.B.C.D|X:X::X:X|WORD> route-server-client",
4336 NO_STR
4337 NEIGHBOR_STR
4338 NEIGHBOR_ADDR_STR2
4339 "Configure a neighbor as Route Server client\n")
4340 {
4341 int idx_peer = 2;
4342 return peer_af_flag_unset_vty(vty, argv[idx_peer]->arg,
4343 bgp_node_afi(vty), bgp_node_safi(vty),
4344 PEER_FLAG_RSERVER_CLIENT);
4345 }
4346
4347 ALIAS_HIDDEN(no_neighbor_route_server_client,
4348 no_neighbor_route_server_client_hidden_cmd,
4349 "no neighbor <A.B.C.D|X:X::X:X|WORD> route-server-client",
4350 NO_STR NEIGHBOR_STR NEIGHBOR_ADDR_STR2
4351 "Configure a neighbor as Route Server client\n")
4352
4353 DEFUN (neighbor_nexthop_local_unchanged,
4354 neighbor_nexthop_local_unchanged_cmd,
4355 "neighbor <A.B.C.D|X:X::X:X|WORD> nexthop-local unchanged",
4356 NEIGHBOR_STR
4357 NEIGHBOR_ADDR_STR2
4358 "Configure treatment of outgoing link-local nexthop attribute\n"
4359 "Leave link-local nexthop unchanged for this peer\n")
4360 {
4361 int idx_peer = 1;
4362 return peer_af_flag_set_vty(vty, argv[idx_peer]->arg, bgp_node_afi(vty),
4363 bgp_node_safi(vty),
4364 PEER_FLAG_NEXTHOP_LOCAL_UNCHANGED);
4365 }
4366
4367 DEFUN (no_neighbor_nexthop_local_unchanged,
4368 no_neighbor_nexthop_local_unchanged_cmd,
4369 "no neighbor <A.B.C.D|X:X::X:X|WORD> nexthop-local unchanged",
4370 NO_STR
4371 NEIGHBOR_STR
4372 NEIGHBOR_ADDR_STR2
4373 "Configure treatment of outgoing link-local-nexthop attribute\n"
4374 "Leave link-local nexthop unchanged for this peer\n")
4375 {
4376 int idx_peer = 2;
4377 return peer_af_flag_unset_vty(vty, argv[idx_peer]->arg,
4378 bgp_node_afi(vty), bgp_node_safi(vty),
4379 PEER_FLAG_NEXTHOP_LOCAL_UNCHANGED);
4380 }
4381
4382 DEFUN (neighbor_attr_unchanged,
4383 neighbor_attr_unchanged_cmd,
4384 "neighbor <A.B.C.D|X:X::X:X|WORD> attribute-unchanged [{as-path|next-hop|med}]",
4385 NEIGHBOR_STR
4386 NEIGHBOR_ADDR_STR2
4387 "BGP attribute is propagated unchanged to this neighbor\n"
4388 "As-path attribute\n"
4389 "Nexthop attribute\n"
4390 "Med attribute\n")
4391 {
4392 int idx = 0;
4393 char *peer_str = argv[1]->arg;
4394 struct peer *peer;
4395 uint16_t flags = 0;
4396 afi_t afi = bgp_node_afi(vty);
4397 safi_t safi = bgp_node_safi(vty);
4398
4399 peer = peer_and_group_lookup_vty(vty, peer_str);
4400 if (!peer)
4401 return CMD_WARNING_CONFIG_FAILED;
4402
4403 if (argv_find(argv, argc, "as-path", &idx))
4404 SET_FLAG(flags, PEER_FLAG_AS_PATH_UNCHANGED);
4405 idx = 0;
4406 if (argv_find(argv, argc, "next-hop", &idx))
4407 SET_FLAG(flags, PEER_FLAG_NEXTHOP_UNCHANGED);
4408 idx = 0;
4409 if (argv_find(argv, argc, "med", &idx))
4410 SET_FLAG(flags, PEER_FLAG_MED_UNCHANGED);
4411
4412 /* no flags means all of them! */
4413 if (!flags) {
4414 SET_FLAG(flags, PEER_FLAG_AS_PATH_UNCHANGED);
4415 SET_FLAG(flags, PEER_FLAG_NEXTHOP_UNCHANGED);
4416 SET_FLAG(flags, PEER_FLAG_MED_UNCHANGED);
4417 } else {
4418 if (!CHECK_FLAG(flags, PEER_FLAG_AS_PATH_UNCHANGED)
4419 && peer_af_flag_check(peer, afi, safi,
4420 PEER_FLAG_AS_PATH_UNCHANGED)) {
4421 peer_af_flag_unset_vty(vty, peer_str, afi, safi,
4422 PEER_FLAG_AS_PATH_UNCHANGED);
4423 }
4424
4425 if (!CHECK_FLAG(flags, PEER_FLAG_NEXTHOP_UNCHANGED)
4426 && peer_af_flag_check(peer, afi, safi,
4427 PEER_FLAG_NEXTHOP_UNCHANGED)) {
4428 peer_af_flag_unset_vty(vty, peer_str, afi, safi,
4429 PEER_FLAG_NEXTHOP_UNCHANGED);
4430 }
4431
4432 if (!CHECK_FLAG(flags, PEER_FLAG_MED_UNCHANGED)
4433 && peer_af_flag_check(peer, afi, safi,
4434 PEER_FLAG_MED_UNCHANGED)) {
4435 peer_af_flag_unset_vty(vty, peer_str, afi, safi,
4436 PEER_FLAG_MED_UNCHANGED);
4437 }
4438 }
4439
4440 return peer_af_flag_set_vty(vty, peer_str, afi, safi, flags);
4441 }
4442
4443 ALIAS_HIDDEN(
4444 neighbor_attr_unchanged, neighbor_attr_unchanged_hidden_cmd,
4445 "neighbor <A.B.C.D|X:X::X:X|WORD> attribute-unchanged [{as-path|next-hop|med}]",
4446 NEIGHBOR_STR NEIGHBOR_ADDR_STR2
4447 "BGP attribute is propagated unchanged to this neighbor\n"
4448 "As-path attribute\n"
4449 "Nexthop attribute\n"
4450 "Med attribute\n")
4451
4452 DEFUN (no_neighbor_attr_unchanged,
4453 no_neighbor_attr_unchanged_cmd,
4454 "no neighbor <A.B.C.D|X:X::X:X|WORD> attribute-unchanged [{as-path|next-hop|med}]",
4455 NO_STR
4456 NEIGHBOR_STR
4457 NEIGHBOR_ADDR_STR2
4458 "BGP attribute is propagated unchanged to this neighbor\n"
4459 "As-path attribute\n"
4460 "Nexthop attribute\n"
4461 "Med attribute\n")
4462 {
4463 int idx = 0;
4464 char *peer = argv[2]->arg;
4465 uint16_t flags = 0;
4466
4467 if (argv_find(argv, argc, "as-path", &idx))
4468 SET_FLAG(flags, PEER_FLAG_AS_PATH_UNCHANGED);
4469 idx = 0;
4470 if (argv_find(argv, argc, "next-hop", &idx))
4471 SET_FLAG(flags, PEER_FLAG_NEXTHOP_UNCHANGED);
4472 idx = 0;
4473 if (argv_find(argv, argc, "med", &idx))
4474 SET_FLAG(flags, PEER_FLAG_MED_UNCHANGED);
4475
4476 if (!flags) // no flags means all of them!
4477 {
4478 SET_FLAG(flags, PEER_FLAG_AS_PATH_UNCHANGED);
4479 SET_FLAG(flags, PEER_FLAG_NEXTHOP_UNCHANGED);
4480 SET_FLAG(flags, PEER_FLAG_MED_UNCHANGED);
4481 }
4482
4483 return peer_af_flag_unset_vty(vty, peer, bgp_node_afi(vty),
4484 bgp_node_safi(vty), flags);
4485 }
4486
4487 ALIAS_HIDDEN(
4488 no_neighbor_attr_unchanged, no_neighbor_attr_unchanged_hidden_cmd,
4489 "no neighbor <A.B.C.D|X:X::X:X|WORD> attribute-unchanged [{as-path|next-hop|med}]",
4490 NO_STR NEIGHBOR_STR NEIGHBOR_ADDR_STR2
4491 "BGP attribute is propagated unchanged to this neighbor\n"
4492 "As-path attribute\n"
4493 "Nexthop attribute\n"
4494 "Med attribute\n")
4495
4496 /* EBGP multihop configuration. */
4497 static int peer_ebgp_multihop_set_vty(struct vty *vty, const char *ip_str,
4498 const char *ttl_str)
4499 {
4500 struct peer *peer;
4501 unsigned int ttl;
4502
4503 peer = peer_and_group_lookup_vty(vty, ip_str);
4504 if (!peer)
4505 return CMD_WARNING_CONFIG_FAILED;
4506
4507 if (peer->conf_if)
4508 return bgp_vty_return(vty, BGP_ERR_INVALID_FOR_DIRECT_PEER);
4509
4510 if (!ttl_str)
4511 ttl = MAXTTL;
4512 else
4513 ttl = strtoul(ttl_str, NULL, 10);
4514
4515 return bgp_vty_return(vty, peer_ebgp_multihop_set(peer, ttl));
4516 }
4517
4518 static int peer_ebgp_multihop_unset_vty(struct vty *vty, const char *ip_str)
4519 {
4520 struct peer *peer;
4521
4522 peer = peer_and_group_lookup_vty(vty, ip_str);
4523 if (!peer)
4524 return CMD_WARNING_CONFIG_FAILED;
4525
4526 return bgp_vty_return(vty, peer_ebgp_multihop_unset(peer));
4527 }
4528
4529 /* neighbor ebgp-multihop. */
4530 DEFUN (neighbor_ebgp_multihop,
4531 neighbor_ebgp_multihop_cmd,
4532 "neighbor <A.B.C.D|X:X::X:X|WORD> ebgp-multihop",
4533 NEIGHBOR_STR
4534 NEIGHBOR_ADDR_STR2
4535 "Allow EBGP neighbors not on directly connected networks\n")
4536 {
4537 int idx_peer = 1;
4538 return peer_ebgp_multihop_set_vty(vty, argv[idx_peer]->arg, NULL);
4539 }
4540
4541 DEFUN (neighbor_ebgp_multihop_ttl,
4542 neighbor_ebgp_multihop_ttl_cmd,
4543 "neighbor <A.B.C.D|X:X::X:X|WORD> ebgp-multihop (1-255)",
4544 NEIGHBOR_STR
4545 NEIGHBOR_ADDR_STR2
4546 "Allow EBGP neighbors not on directly connected networks\n"
4547 "maximum hop count\n")
4548 {
4549 int idx_peer = 1;
4550 int idx_number = 3;
4551 return peer_ebgp_multihop_set_vty(vty, argv[idx_peer]->arg,
4552 argv[idx_number]->arg);
4553 }
4554
4555 DEFUN (no_neighbor_ebgp_multihop,
4556 no_neighbor_ebgp_multihop_cmd,
4557 "no neighbor <A.B.C.D|X:X::X:X|WORD> ebgp-multihop [(1-255)]",
4558 NO_STR
4559 NEIGHBOR_STR
4560 NEIGHBOR_ADDR_STR2
4561 "Allow EBGP neighbors not on directly connected networks\n"
4562 "maximum hop count\n")
4563 {
4564 int idx_peer = 2;
4565 return peer_ebgp_multihop_unset_vty(vty, argv[idx_peer]->arg);
4566 }
4567
4568
4569 /* disable-connected-check */
4570 DEFUN (neighbor_disable_connected_check,
4571 neighbor_disable_connected_check_cmd,
4572 "neighbor <A.B.C.D|X:X::X:X|WORD> <disable-connected-check|enforce-multihop>",
4573 NEIGHBOR_STR
4574 NEIGHBOR_ADDR_STR2
4575 "one-hop away EBGP peer using loopback address\n"
4576 "Enforce EBGP neighbors perform multihop\n")
4577 {
4578 int idx_peer = 1;
4579 return peer_flag_set_vty(vty, argv[idx_peer]->arg,
4580 PEER_FLAG_DISABLE_CONNECTED_CHECK);
4581 }
4582
4583 DEFUN (no_neighbor_disable_connected_check,
4584 no_neighbor_disable_connected_check_cmd,
4585 "no neighbor <A.B.C.D|X:X::X:X|WORD> <disable-connected-check|enforce-multihop>",
4586 NO_STR
4587 NEIGHBOR_STR
4588 NEIGHBOR_ADDR_STR2
4589 "one-hop away EBGP peer using loopback address\n"
4590 "Enforce EBGP neighbors perform multihop\n")
4591 {
4592 int idx_peer = 2;
4593 return peer_flag_unset_vty(vty, argv[idx_peer]->arg,
4594 PEER_FLAG_DISABLE_CONNECTED_CHECK);
4595 }
4596
4597
4598 /* enforce-first-as */
4599 DEFUN (neighbor_enforce_first_as,
4600 neighbor_enforce_first_as_cmd,
4601 "neighbor <A.B.C.D|X:X::X:X|WORD> enforce-first-as",
4602 NEIGHBOR_STR
4603 NEIGHBOR_ADDR_STR2
4604 "Enforce the first AS for EBGP routes\n")
4605 {
4606 int idx_peer = 1;
4607
4608 return peer_flag_set_vty(vty, argv[idx_peer]->arg,
4609 PEER_FLAG_ENFORCE_FIRST_AS);
4610 }
4611
4612 DEFUN (no_neighbor_enforce_first_as,
4613 no_neighbor_enforce_first_as_cmd,
4614 "no neighbor <A.B.C.D|X:X::X:X|WORD> enforce-first-as",
4615 NO_STR
4616 NEIGHBOR_STR
4617 NEIGHBOR_ADDR_STR2
4618 "Enforce the first AS for EBGP routes\n")
4619 {
4620 int idx_peer = 2;
4621
4622 return peer_flag_unset_vty(vty, argv[idx_peer]->arg,
4623 PEER_FLAG_ENFORCE_FIRST_AS);
4624 }
4625
4626
4627 DEFUN (neighbor_description,
4628 neighbor_description_cmd,
4629 "neighbor <A.B.C.D|X:X::X:X|WORD> description LINE...",
4630 NEIGHBOR_STR
4631 NEIGHBOR_ADDR_STR2
4632 "Neighbor specific description\n"
4633 "Up to 80 characters describing this neighbor\n")
4634 {
4635 int idx_peer = 1;
4636 int idx_line = 3;
4637 struct peer *peer;
4638 char *str;
4639
4640 peer = peer_and_group_lookup_vty(vty, argv[idx_peer]->arg);
4641 if (!peer)
4642 return CMD_WARNING_CONFIG_FAILED;
4643
4644 str = argv_concat(argv, argc, idx_line);
4645
4646 peer_description_set(peer, str);
4647
4648 XFREE(MTYPE_TMP, str);
4649
4650 return CMD_SUCCESS;
4651 }
4652
4653 DEFUN (no_neighbor_description,
4654 no_neighbor_description_cmd,
4655 "no neighbor <A.B.C.D|X:X::X:X|WORD> description [LINE]",
4656 NO_STR
4657 NEIGHBOR_STR
4658 NEIGHBOR_ADDR_STR2
4659 "Neighbor specific description\n"
4660 "Up to 80 characters describing this neighbor\n")
4661 {
4662 int idx_peer = 2;
4663 struct peer *peer;
4664
4665 peer = peer_and_group_lookup_vty(vty, argv[idx_peer]->arg);
4666 if (!peer)
4667 return CMD_WARNING_CONFIG_FAILED;
4668
4669 peer_description_unset(peer);
4670
4671 return CMD_SUCCESS;
4672 }
4673
4674
4675 /* Neighbor update-source. */
4676 static int peer_update_source_vty(struct vty *vty, const char *peer_str,
4677 const char *source_str)
4678 {
4679 struct peer *peer;
4680 struct prefix p;
4681
4682 peer = peer_and_group_lookup_vty(vty, peer_str);
4683 if (!peer)
4684 return CMD_WARNING_CONFIG_FAILED;
4685
4686 if (peer->conf_if)
4687 return CMD_WARNING;
4688
4689 if (source_str) {
4690 union sockunion su;
4691 int ret = str2sockunion(source_str, &su);
4692
4693 if (ret == 0)
4694 peer_update_source_addr_set(peer, &su);
4695 else {
4696 if (str2prefix(source_str, &p)) {
4697 vty_out(vty,
4698 "%% Invalid update-source, remove prefix length \n");
4699 return CMD_WARNING_CONFIG_FAILED;
4700 } else
4701 peer_update_source_if_set(peer, source_str);
4702 }
4703 } else
4704 peer_update_source_unset(peer);
4705
4706 return CMD_SUCCESS;
4707 }
4708
4709 #define BGP_UPDATE_SOURCE_HELP_STR \
4710 "IPv4 address\n" \
4711 "IPv6 address\n" \
4712 "Interface name (requires zebra to be running)\n"
4713
4714 DEFUN (neighbor_update_source,
4715 neighbor_update_source_cmd,
4716 "neighbor <A.B.C.D|X:X::X:X|WORD> update-source <A.B.C.D|X:X::X:X|WORD>",
4717 NEIGHBOR_STR
4718 NEIGHBOR_ADDR_STR2
4719 "Source of routing updates\n"
4720 BGP_UPDATE_SOURCE_HELP_STR)
4721 {
4722 int idx_peer = 1;
4723 int idx_peer_2 = 3;
4724 return peer_update_source_vty(vty, argv[idx_peer]->arg,
4725 argv[idx_peer_2]->arg);
4726 }
4727
4728 DEFUN (no_neighbor_update_source,
4729 no_neighbor_update_source_cmd,
4730 "no neighbor <A.B.C.D|X:X::X:X|WORD> update-source [<A.B.C.D|X:X::X:X|WORD>]",
4731 NO_STR
4732 NEIGHBOR_STR
4733 NEIGHBOR_ADDR_STR2
4734 "Source of routing updates\n"
4735 BGP_UPDATE_SOURCE_HELP_STR)
4736 {
4737 int idx_peer = 2;
4738 return peer_update_source_vty(vty, argv[idx_peer]->arg, NULL);
4739 }
4740
4741 static int peer_default_originate_set_vty(struct vty *vty, const char *peer_str,
4742 afi_t afi, safi_t safi,
4743 const char *rmap, int set)
4744 {
4745 int ret;
4746 struct peer *peer;
4747
4748 peer = peer_and_group_lookup_vty(vty, peer_str);
4749 if (!peer)
4750 return CMD_WARNING_CONFIG_FAILED;
4751
4752 if (set)
4753 ret = peer_default_originate_set(peer, afi, safi, rmap);
4754 else
4755 ret = peer_default_originate_unset(peer, afi, safi);
4756
4757 return bgp_vty_return(vty, ret);
4758 }
4759
4760 /* neighbor default-originate. */
4761 DEFUN (neighbor_default_originate,
4762 neighbor_default_originate_cmd,
4763 "neighbor <A.B.C.D|X:X::X:X|WORD> default-originate",
4764 NEIGHBOR_STR
4765 NEIGHBOR_ADDR_STR2
4766 "Originate default route to this neighbor\n")
4767 {
4768 int idx_peer = 1;
4769 return peer_default_originate_set_vty(vty, argv[idx_peer]->arg,
4770 bgp_node_afi(vty),
4771 bgp_node_safi(vty), NULL, 1);
4772 }
4773
4774 ALIAS_HIDDEN(neighbor_default_originate, neighbor_default_originate_hidden_cmd,
4775 "neighbor <A.B.C.D|X:X::X:X|WORD> default-originate",
4776 NEIGHBOR_STR NEIGHBOR_ADDR_STR2
4777 "Originate default route to this neighbor\n")
4778
4779 DEFUN (neighbor_default_originate_rmap,
4780 neighbor_default_originate_rmap_cmd,
4781 "neighbor <A.B.C.D|X:X::X:X|WORD> default-originate route-map WORD",
4782 NEIGHBOR_STR
4783 NEIGHBOR_ADDR_STR2
4784 "Originate default route to this neighbor\n"
4785 "Route-map to specify criteria to originate default\n"
4786 "route-map name\n")
4787 {
4788 int idx_peer = 1;
4789 int idx_word = 4;
4790 return peer_default_originate_set_vty(
4791 vty, argv[idx_peer]->arg, bgp_node_afi(vty), bgp_node_safi(vty),
4792 argv[idx_word]->arg, 1);
4793 }
4794
4795 ALIAS_HIDDEN(
4796 neighbor_default_originate_rmap,
4797 neighbor_default_originate_rmap_hidden_cmd,
4798 "neighbor <A.B.C.D|X:X::X:X|WORD> default-originate route-map WORD",
4799 NEIGHBOR_STR NEIGHBOR_ADDR_STR2
4800 "Originate default route to this neighbor\n"
4801 "Route-map to specify criteria to originate default\n"
4802 "route-map name\n")
4803
4804 DEFUN (no_neighbor_default_originate,
4805 no_neighbor_default_originate_cmd,
4806 "no neighbor <A.B.C.D|X:X::X:X|WORD> default-originate [route-map WORD]",
4807 NO_STR
4808 NEIGHBOR_STR
4809 NEIGHBOR_ADDR_STR2
4810 "Originate default route to this neighbor\n"
4811 "Route-map to specify criteria to originate default\n"
4812 "route-map name\n")
4813 {
4814 int idx_peer = 2;
4815 return peer_default_originate_set_vty(vty, argv[idx_peer]->arg,
4816 bgp_node_afi(vty),
4817 bgp_node_safi(vty), NULL, 0);
4818 }
4819
4820 ALIAS_HIDDEN(
4821 no_neighbor_default_originate, no_neighbor_default_originate_hidden_cmd,
4822 "no neighbor <A.B.C.D|X:X::X:X|WORD> default-originate [route-map WORD]",
4823 NO_STR NEIGHBOR_STR NEIGHBOR_ADDR_STR2
4824 "Originate default route to this neighbor\n"
4825 "Route-map to specify criteria to originate default\n"
4826 "route-map name\n")
4827
4828
4829 /* Set neighbor's BGP port. */
4830 static int peer_port_vty(struct vty *vty, const char *ip_str, int afi,
4831 const char *port_str)
4832 {
4833 struct peer *peer;
4834 uint16_t port;
4835 struct servent *sp;
4836
4837 peer = peer_lookup_vty(vty, ip_str);
4838 if (!peer)
4839 return CMD_WARNING_CONFIG_FAILED;
4840
4841 if (!port_str) {
4842 sp = getservbyname("bgp", "tcp");
4843 port = (sp == NULL) ? BGP_PORT_DEFAULT : ntohs(sp->s_port);
4844 } else {
4845 port = strtoul(port_str, NULL, 10);
4846 }
4847
4848 peer_port_set(peer, port);
4849
4850 return CMD_SUCCESS;
4851 }
4852
4853 /* Set specified peer's BGP port. */
4854 DEFUN (neighbor_port,
4855 neighbor_port_cmd,
4856 "neighbor <A.B.C.D|X:X::X:X> port (0-65535)",
4857 NEIGHBOR_STR
4858 NEIGHBOR_ADDR_STR
4859 "Neighbor's BGP port\n"
4860 "TCP port number\n")
4861 {
4862 int idx_ip = 1;
4863 int idx_number = 3;
4864 return peer_port_vty(vty, argv[idx_ip]->arg, AFI_IP,
4865 argv[idx_number]->arg);
4866 }
4867
4868 DEFUN (no_neighbor_port,
4869 no_neighbor_port_cmd,
4870 "no neighbor <A.B.C.D|X:X::X:X> port [(0-65535)]",
4871 NO_STR
4872 NEIGHBOR_STR
4873 NEIGHBOR_ADDR_STR
4874 "Neighbor's BGP port\n"
4875 "TCP port number\n")
4876 {
4877 int idx_ip = 2;
4878 return peer_port_vty(vty, argv[idx_ip]->arg, AFI_IP, NULL);
4879 }
4880
4881
4882 /* neighbor weight. */
4883 static int peer_weight_set_vty(struct vty *vty, const char *ip_str, afi_t afi,
4884 safi_t safi, const char *weight_str)
4885 {
4886 int ret;
4887 struct peer *peer;
4888 unsigned long weight;
4889
4890 peer = peer_and_group_lookup_vty(vty, ip_str);
4891 if (!peer)
4892 return CMD_WARNING_CONFIG_FAILED;
4893
4894 weight = strtoul(weight_str, NULL, 10);
4895
4896 ret = peer_weight_set(peer, afi, safi, weight);
4897 return bgp_vty_return(vty, ret);
4898 }
4899
4900 static int peer_weight_unset_vty(struct vty *vty, const char *ip_str, afi_t afi,
4901 safi_t safi)
4902 {
4903 int ret;
4904 struct peer *peer;
4905
4906 peer = peer_and_group_lookup_vty(vty, ip_str);
4907 if (!peer)
4908 return CMD_WARNING_CONFIG_FAILED;
4909
4910 ret = peer_weight_unset(peer, afi, safi);
4911 return bgp_vty_return(vty, ret);
4912 }
4913
4914 DEFUN (neighbor_weight,
4915 neighbor_weight_cmd,
4916 "neighbor <A.B.C.D|X:X::X:X|WORD> weight (0-65535)",
4917 NEIGHBOR_STR
4918 NEIGHBOR_ADDR_STR2
4919 "Set default weight for routes from this neighbor\n"
4920 "default weight\n")
4921 {
4922 int idx_peer = 1;
4923 int idx_number = 3;
4924 return peer_weight_set_vty(vty, argv[idx_peer]->arg, bgp_node_afi(vty),
4925 bgp_node_safi(vty), argv[idx_number]->arg);
4926 }
4927
4928 ALIAS_HIDDEN(neighbor_weight, neighbor_weight_hidden_cmd,
4929 "neighbor <A.B.C.D|X:X::X:X|WORD> weight (0-65535)",
4930 NEIGHBOR_STR NEIGHBOR_ADDR_STR2
4931 "Set default weight for routes from this neighbor\n"
4932 "default weight\n")
4933
4934 DEFUN (no_neighbor_weight,
4935 no_neighbor_weight_cmd,
4936 "no neighbor <A.B.C.D|X:X::X:X|WORD> weight [(0-65535)]",
4937 NO_STR
4938 NEIGHBOR_STR
4939 NEIGHBOR_ADDR_STR2
4940 "Set default weight for routes from this neighbor\n"
4941 "default weight\n")
4942 {
4943 int idx_peer = 2;
4944 return peer_weight_unset_vty(vty, argv[idx_peer]->arg,
4945 bgp_node_afi(vty), bgp_node_safi(vty));
4946 }
4947
4948 ALIAS_HIDDEN(no_neighbor_weight, no_neighbor_weight_hidden_cmd,
4949 "no neighbor <A.B.C.D|X:X::X:X|WORD> weight [(0-65535)]",
4950 NO_STR NEIGHBOR_STR NEIGHBOR_ADDR_STR2
4951 "Set default weight for routes from this neighbor\n"
4952 "default weight\n")
4953
4954
4955 /* Override capability negotiation. */
4956 DEFUN (neighbor_override_capability,
4957 neighbor_override_capability_cmd,
4958 "neighbor <A.B.C.D|X:X::X:X|WORD> override-capability",
4959 NEIGHBOR_STR
4960 NEIGHBOR_ADDR_STR2
4961 "Override capability negotiation result\n")
4962 {
4963 int idx_peer = 1;
4964 return peer_flag_set_vty(vty, argv[idx_peer]->arg,
4965 PEER_FLAG_OVERRIDE_CAPABILITY);
4966 }
4967
4968 DEFUN (no_neighbor_override_capability,
4969 no_neighbor_override_capability_cmd,
4970 "no neighbor <A.B.C.D|X:X::X:X|WORD> override-capability",
4971 NO_STR
4972 NEIGHBOR_STR
4973 NEIGHBOR_ADDR_STR2
4974 "Override capability negotiation result\n")
4975 {
4976 int idx_peer = 2;
4977 return peer_flag_unset_vty(vty, argv[idx_peer]->arg,
4978 PEER_FLAG_OVERRIDE_CAPABILITY);
4979 }
4980
4981 DEFUN (neighbor_strict_capability,
4982 neighbor_strict_capability_cmd,
4983 "neighbor <A.B.C.D|X:X::X:X> strict-capability-match",
4984 NEIGHBOR_STR
4985 NEIGHBOR_ADDR_STR
4986 "Strict capability negotiation match\n")
4987 {
4988 int idx_ip = 1;
4989 return peer_flag_set_vty(vty, argv[idx_ip]->arg,
4990 PEER_FLAG_STRICT_CAP_MATCH);
4991 }
4992
4993 DEFUN (no_neighbor_strict_capability,
4994 no_neighbor_strict_capability_cmd,
4995 "no neighbor <A.B.C.D|X:X::X:X> strict-capability-match",
4996 NO_STR
4997 NEIGHBOR_STR
4998 NEIGHBOR_ADDR_STR
4999 "Strict capability negotiation match\n")
5000 {
5001 int idx_ip = 2;
5002 return peer_flag_unset_vty(vty, argv[idx_ip]->arg,
5003 PEER_FLAG_STRICT_CAP_MATCH);
5004 }
5005
5006 static int peer_timers_set_vty(struct vty *vty, const char *ip_str,
5007 const char *keep_str, const char *hold_str)
5008 {
5009 int ret;
5010 struct peer *peer;
5011 uint32_t keepalive;
5012 uint32_t holdtime;
5013
5014 peer = peer_and_group_lookup_vty(vty, ip_str);
5015 if (!peer)
5016 return CMD_WARNING_CONFIG_FAILED;
5017
5018 keepalive = strtoul(keep_str, NULL, 10);
5019 holdtime = strtoul(hold_str, NULL, 10);
5020
5021 ret = peer_timers_set(peer, keepalive, holdtime);
5022
5023 return bgp_vty_return(vty, ret);
5024 }
5025
5026 static int peer_timers_unset_vty(struct vty *vty, const char *ip_str)
5027 {
5028 int ret;
5029 struct peer *peer;
5030
5031 peer = peer_and_group_lookup_vty(vty, ip_str);
5032 if (!peer)
5033 return CMD_WARNING_CONFIG_FAILED;
5034
5035 ret = peer_timers_unset(peer);
5036
5037 return bgp_vty_return(vty, ret);
5038 }
5039
5040 DEFUN (neighbor_timers,
5041 neighbor_timers_cmd,
5042 "neighbor <A.B.C.D|X:X::X:X|WORD> timers (0-65535) (0-65535)",
5043 NEIGHBOR_STR
5044 NEIGHBOR_ADDR_STR2
5045 "BGP per neighbor timers\n"
5046 "Keepalive interval\n"
5047 "Holdtime\n")
5048 {
5049 int idx_peer = 1;
5050 int idx_number = 3;
5051 int idx_number_2 = 4;
5052 return peer_timers_set_vty(vty, argv[idx_peer]->arg,
5053 argv[idx_number]->arg,
5054 argv[idx_number_2]->arg);
5055 }
5056
5057 DEFUN (no_neighbor_timers,
5058 no_neighbor_timers_cmd,
5059 "no neighbor <A.B.C.D|X:X::X:X|WORD> timers [(0-65535) (0-65535)]",
5060 NO_STR
5061 NEIGHBOR_STR
5062 NEIGHBOR_ADDR_STR2
5063 "BGP per neighbor timers\n"
5064 "Keepalive interval\n"
5065 "Holdtime\n")
5066 {
5067 int idx_peer = 2;
5068 return peer_timers_unset_vty(vty, argv[idx_peer]->arg);
5069 }
5070
5071
5072 static int peer_timers_connect_set_vty(struct vty *vty, const char *ip_str,
5073 const char *time_str)
5074 {
5075 int ret;
5076 struct peer *peer;
5077 uint32_t connect;
5078
5079 peer = peer_and_group_lookup_vty(vty, ip_str);
5080 if (!peer)
5081 return CMD_WARNING_CONFIG_FAILED;
5082
5083 connect = strtoul(time_str, NULL, 10);
5084
5085 ret = peer_timers_connect_set(peer, connect);
5086
5087 return bgp_vty_return(vty, ret);
5088 }
5089
5090 static int peer_timers_connect_unset_vty(struct vty *vty, const char *ip_str)
5091 {
5092 int ret;
5093 struct peer *peer;
5094
5095 peer = peer_and_group_lookup_vty(vty, ip_str);
5096 if (!peer)
5097 return CMD_WARNING_CONFIG_FAILED;
5098
5099 ret = peer_timers_connect_unset(peer);
5100
5101 return bgp_vty_return(vty, ret);
5102 }
5103
5104 DEFUN (neighbor_timers_connect,
5105 neighbor_timers_connect_cmd,
5106 "neighbor <A.B.C.D|X:X::X:X|WORD> timers connect (1-65535)",
5107 NEIGHBOR_STR
5108 NEIGHBOR_ADDR_STR2
5109 "BGP per neighbor timers\n"
5110 "BGP connect timer\n"
5111 "Connect timer\n")
5112 {
5113 int idx_peer = 1;
5114 int idx_number = 4;
5115 return peer_timers_connect_set_vty(vty, argv[idx_peer]->arg,
5116 argv[idx_number]->arg);
5117 }
5118
5119 DEFUN (no_neighbor_timers_connect,
5120 no_neighbor_timers_connect_cmd,
5121 "no neighbor <A.B.C.D|X:X::X:X|WORD> timers connect [(1-65535)]",
5122 NO_STR
5123 NEIGHBOR_STR
5124 NEIGHBOR_ADDR_STR2
5125 "BGP per neighbor timers\n"
5126 "BGP connect timer\n"
5127 "Connect timer\n")
5128 {
5129 int idx_peer = 2;
5130 return peer_timers_connect_unset_vty(vty, argv[idx_peer]->arg);
5131 }
5132
5133
5134 static int peer_advertise_interval_vty(struct vty *vty, const char *ip_str,
5135 const char *time_str, int set)
5136 {
5137 int ret;
5138 struct peer *peer;
5139 uint32_t routeadv = 0;
5140
5141 peer = peer_and_group_lookup_vty(vty, ip_str);
5142 if (!peer)
5143 return CMD_WARNING_CONFIG_FAILED;
5144
5145 if (time_str)
5146 routeadv = strtoul(time_str, NULL, 10);
5147
5148 if (set)
5149 ret = peer_advertise_interval_set(peer, routeadv);
5150 else
5151 ret = peer_advertise_interval_unset(peer);
5152
5153 return bgp_vty_return(vty, ret);
5154 }
5155
5156 DEFUN (neighbor_advertise_interval,
5157 neighbor_advertise_interval_cmd,
5158 "neighbor <A.B.C.D|X:X::X:X|WORD> advertisement-interval (0-600)",
5159 NEIGHBOR_STR
5160 NEIGHBOR_ADDR_STR2
5161 "Minimum interval between sending BGP routing updates\n"
5162 "time in seconds\n")
5163 {
5164 int idx_peer = 1;
5165 int idx_number = 3;
5166 return peer_advertise_interval_vty(vty, argv[idx_peer]->arg,
5167 argv[idx_number]->arg, 1);
5168 }
5169
5170 DEFUN (no_neighbor_advertise_interval,
5171 no_neighbor_advertise_interval_cmd,
5172 "no neighbor <A.B.C.D|X:X::X:X|WORD> advertisement-interval [(0-600)]",
5173 NO_STR
5174 NEIGHBOR_STR
5175 NEIGHBOR_ADDR_STR2
5176 "Minimum interval between sending BGP routing updates\n"
5177 "time in seconds\n")
5178 {
5179 int idx_peer = 2;
5180 return peer_advertise_interval_vty(vty, argv[idx_peer]->arg, NULL, 0);
5181 }
5182
5183
5184 /* Time to wait before processing route-map updates */
5185 DEFUN (bgp_set_route_map_delay_timer,
5186 bgp_set_route_map_delay_timer_cmd,
5187 "bgp route-map delay-timer (0-600)",
5188 SET_STR
5189 "BGP route-map delay timer\n"
5190 "Time in secs to wait before processing route-map changes\n"
5191 "0 disables the timer, no route updates happen when route-maps change\n")
5192 {
5193 int idx_number = 3;
5194 uint32_t rmap_delay_timer;
5195
5196 if (argv[idx_number]->arg) {
5197 rmap_delay_timer = strtoul(argv[idx_number]->arg, NULL, 10);
5198 bm->rmap_update_timer = rmap_delay_timer;
5199
5200 /* if the dynamic update handling is being disabled, and a timer
5201 * is
5202 * running, stop the timer and act as if the timer has already
5203 * fired.
5204 */
5205 if (!rmap_delay_timer && bm->t_rmap_update) {
5206 BGP_TIMER_OFF(bm->t_rmap_update);
5207 thread_execute(bm->master, bgp_route_map_update_timer,
5208 NULL, 0);
5209 }
5210 return CMD_SUCCESS;
5211 } else {
5212 vty_out(vty, "%% BGP invalid route-map delay-timer\n");
5213 return CMD_WARNING_CONFIG_FAILED;
5214 }
5215 }
5216
5217 DEFUN (no_bgp_set_route_map_delay_timer,
5218 no_bgp_set_route_map_delay_timer_cmd,
5219 "no bgp route-map delay-timer [(0-600)]",
5220 NO_STR
5221 BGP_STR
5222 "Default BGP route-map delay timer\n"
5223 "Reset to default time to wait for processing route-map changes\n"
5224 "0 disables the timer, no route updates happen when route-maps change\n")
5225 {
5226
5227 bm->rmap_update_timer = RMAP_DEFAULT_UPDATE_TIMER;
5228
5229 return CMD_SUCCESS;
5230 }
5231
5232
5233 /* neighbor interface */
5234 static int peer_interface_vty(struct vty *vty, const char *ip_str,
5235 const char *str)
5236 {
5237 struct peer *peer;
5238
5239 peer = peer_lookup_vty(vty, ip_str);
5240 if (!peer || peer->conf_if) {
5241 vty_out(vty, "%% BGP invalid peer %s\n", ip_str);
5242 return CMD_WARNING_CONFIG_FAILED;
5243 }
5244
5245 if (str)
5246 peer_interface_set(peer, str);
5247 else
5248 peer_interface_unset(peer);
5249
5250 return CMD_SUCCESS;
5251 }
5252
5253 DEFUN (neighbor_interface,
5254 neighbor_interface_cmd,
5255 "neighbor <A.B.C.D|X:X::X:X> interface WORD",
5256 NEIGHBOR_STR
5257 NEIGHBOR_ADDR_STR
5258 "Interface\n"
5259 "Interface name\n")
5260 {
5261 int idx_ip = 1;
5262 int idx_word = 3;
5263 return peer_interface_vty(vty, argv[idx_ip]->arg, argv[idx_word]->arg);
5264 }
5265
5266 DEFUN (no_neighbor_interface,
5267 no_neighbor_interface_cmd,
5268 "no neighbor <A.B.C.D|X:X::X:X|WORD> interface WORD",
5269 NO_STR
5270 NEIGHBOR_STR
5271 NEIGHBOR_ADDR_STR2
5272 "Interface\n"
5273 "Interface name\n")
5274 {
5275 int idx_peer = 2;
5276 return peer_interface_vty(vty, argv[idx_peer]->arg, NULL);
5277 }
5278
5279 DEFUN (neighbor_distribute_list,
5280 neighbor_distribute_list_cmd,
5281 "neighbor <A.B.C.D|X:X::X:X|WORD> distribute-list <(1-199)|(1300-2699)|WORD> <in|out>",
5282 NEIGHBOR_STR
5283 NEIGHBOR_ADDR_STR2
5284 "Filter updates to/from this neighbor\n"
5285 "IP access-list number\n"
5286 "IP access-list number (expanded range)\n"
5287 "IP Access-list name\n"
5288 "Filter incoming updates\n"
5289 "Filter outgoing updates\n")
5290 {
5291 int idx_peer = 1;
5292 int idx_acl = 3;
5293 int direct, ret;
5294 struct peer *peer;
5295
5296 const char *pstr = argv[idx_peer]->arg;
5297 const char *acl = argv[idx_acl]->arg;
5298 const char *inout = argv[argc - 1]->text;
5299
5300 peer = peer_and_group_lookup_vty(vty, pstr);
5301 if (!peer)
5302 return CMD_WARNING_CONFIG_FAILED;
5303
5304 /* Check filter direction. */
5305 direct = strmatch(inout, "in") ? FILTER_IN : FILTER_OUT;
5306 ret = peer_distribute_set(peer, bgp_node_afi(vty), bgp_node_safi(vty),
5307 direct, acl);
5308
5309 return bgp_vty_return(vty, ret);
5310 }
5311
5312 ALIAS_HIDDEN(
5313 neighbor_distribute_list, neighbor_distribute_list_hidden_cmd,
5314 "neighbor <A.B.C.D|X:X::X:X|WORD> distribute-list <(1-199)|(1300-2699)|WORD> <in|out>",
5315 NEIGHBOR_STR NEIGHBOR_ADDR_STR2
5316 "Filter updates to/from this neighbor\n"
5317 "IP access-list number\n"
5318 "IP access-list number (expanded range)\n"
5319 "IP Access-list name\n"
5320 "Filter incoming updates\n"
5321 "Filter outgoing updates\n")
5322
5323 DEFUN (no_neighbor_distribute_list,
5324 no_neighbor_distribute_list_cmd,
5325 "no neighbor <A.B.C.D|X:X::X:X|WORD> distribute-list <(1-199)|(1300-2699)|WORD> <in|out>",
5326 NO_STR
5327 NEIGHBOR_STR
5328 NEIGHBOR_ADDR_STR2
5329 "Filter updates to/from this neighbor\n"
5330 "IP access-list number\n"
5331 "IP access-list number (expanded range)\n"
5332 "IP Access-list name\n"
5333 "Filter incoming updates\n"
5334 "Filter outgoing updates\n")
5335 {
5336 int idx_peer = 2;
5337 int direct, ret;
5338 struct peer *peer;
5339
5340 const char *pstr = argv[idx_peer]->arg;
5341 const char *inout = argv[argc - 1]->text;
5342
5343 peer = peer_and_group_lookup_vty(vty, pstr);
5344 if (!peer)
5345 return CMD_WARNING_CONFIG_FAILED;
5346
5347 /* Check filter direction. */
5348 direct = strmatch(inout, "in") ? FILTER_IN : FILTER_OUT;
5349 ret = peer_distribute_unset(peer, bgp_node_afi(vty), bgp_node_safi(vty),
5350 direct);
5351
5352 return bgp_vty_return(vty, ret);
5353 }
5354
5355 ALIAS_HIDDEN(
5356 no_neighbor_distribute_list, no_neighbor_distribute_list_hidden_cmd,
5357 "no neighbor <A.B.C.D|X:X::X:X|WORD> distribute-list <(1-199)|(1300-2699)|WORD> <in|out>",
5358 NO_STR NEIGHBOR_STR NEIGHBOR_ADDR_STR2
5359 "Filter updates to/from this neighbor\n"
5360 "IP access-list number\n"
5361 "IP access-list number (expanded range)\n"
5362 "IP Access-list name\n"
5363 "Filter incoming updates\n"
5364 "Filter outgoing updates\n")
5365
5366 /* Set prefix list to the peer. */
5367 static int peer_prefix_list_set_vty(struct vty *vty, const char *ip_str,
5368 afi_t afi, safi_t safi,
5369 const char *name_str,
5370 const char *direct_str)
5371 {
5372 int ret;
5373 int direct = FILTER_IN;
5374 struct peer *peer;
5375
5376 peer = peer_and_group_lookup_vty(vty, ip_str);
5377 if (!peer)
5378 return CMD_WARNING_CONFIG_FAILED;
5379
5380 /* Check filter direction. */
5381 if (strncmp(direct_str, "i", 1) == 0)
5382 direct = FILTER_IN;
5383 else if (strncmp(direct_str, "o", 1) == 0)
5384 direct = FILTER_OUT;
5385
5386 ret = peer_prefix_list_set(peer, afi, safi, direct, name_str);
5387
5388 return bgp_vty_return(vty, ret);
5389 }
5390
5391 static int peer_prefix_list_unset_vty(struct vty *vty, const char *ip_str,
5392 afi_t afi, safi_t safi,
5393 const char *direct_str)
5394 {
5395 int ret;
5396 struct peer *peer;
5397 int direct = FILTER_IN;
5398
5399 peer = peer_and_group_lookup_vty(vty, ip_str);
5400 if (!peer)
5401 return CMD_WARNING_CONFIG_FAILED;
5402
5403 /* Check filter direction. */
5404 if (strncmp(direct_str, "i", 1) == 0)
5405 direct = FILTER_IN;
5406 else if (strncmp(direct_str, "o", 1) == 0)
5407 direct = FILTER_OUT;
5408
5409 ret = peer_prefix_list_unset(peer, afi, safi, direct);
5410
5411 return bgp_vty_return(vty, ret);
5412 }
5413
5414 DEFUN (neighbor_prefix_list,
5415 neighbor_prefix_list_cmd,
5416 "neighbor <A.B.C.D|X:X::X:X|WORD> prefix-list WORD <in|out>",
5417 NEIGHBOR_STR
5418 NEIGHBOR_ADDR_STR2
5419 "Filter updates to/from this neighbor\n"
5420 "Name of a prefix list\n"
5421 "Filter incoming updates\n"
5422 "Filter outgoing updates\n")
5423 {
5424 int idx_peer = 1;
5425 int idx_word = 3;
5426 int idx_in_out = 4;
5427 return peer_prefix_list_set_vty(
5428 vty, argv[idx_peer]->arg, bgp_node_afi(vty), bgp_node_safi(vty),
5429 argv[idx_word]->arg, argv[idx_in_out]->arg);
5430 }
5431
5432 ALIAS_HIDDEN(neighbor_prefix_list, neighbor_prefix_list_hidden_cmd,
5433 "neighbor <A.B.C.D|X:X::X:X|WORD> prefix-list WORD <in|out>",
5434 NEIGHBOR_STR NEIGHBOR_ADDR_STR2
5435 "Filter updates to/from this neighbor\n"
5436 "Name of a prefix list\n"
5437 "Filter incoming updates\n"
5438 "Filter outgoing updates\n")
5439
5440 DEFUN (no_neighbor_prefix_list,
5441 no_neighbor_prefix_list_cmd,
5442 "no neighbor <A.B.C.D|X:X::X:X|WORD> prefix-list WORD <in|out>",
5443 NO_STR
5444 NEIGHBOR_STR
5445 NEIGHBOR_ADDR_STR2
5446 "Filter updates to/from this neighbor\n"
5447 "Name of a prefix list\n"
5448 "Filter incoming updates\n"
5449 "Filter outgoing updates\n")
5450 {
5451 int idx_peer = 2;
5452 int idx_in_out = 5;
5453 return peer_prefix_list_unset_vty(vty, argv[idx_peer]->arg,
5454 bgp_node_afi(vty), bgp_node_safi(vty),
5455 argv[idx_in_out]->arg);
5456 }
5457
5458 ALIAS_HIDDEN(no_neighbor_prefix_list, no_neighbor_prefix_list_hidden_cmd,
5459 "no neighbor <A.B.C.D|X:X::X:X|WORD> prefix-list WORD <in|out>",
5460 NO_STR NEIGHBOR_STR NEIGHBOR_ADDR_STR2
5461 "Filter updates to/from this neighbor\n"
5462 "Name of a prefix list\n"
5463 "Filter incoming updates\n"
5464 "Filter outgoing updates\n")
5465
5466 static int peer_aslist_set_vty(struct vty *vty, const char *ip_str, afi_t afi,
5467 safi_t safi, const char *name_str,
5468 const char *direct_str)
5469 {
5470 int ret;
5471 struct peer *peer;
5472 int direct = FILTER_IN;
5473
5474 peer = peer_and_group_lookup_vty(vty, ip_str);
5475 if (!peer)
5476 return CMD_WARNING_CONFIG_FAILED;
5477
5478 /* Check filter direction. */
5479 if (strncmp(direct_str, "i", 1) == 0)
5480 direct = FILTER_IN;
5481 else if (strncmp(direct_str, "o", 1) == 0)
5482 direct = FILTER_OUT;
5483
5484 ret = peer_aslist_set(peer, afi, safi, direct, name_str);
5485
5486 return bgp_vty_return(vty, ret);
5487 }
5488
5489 static int peer_aslist_unset_vty(struct vty *vty, const char *ip_str, afi_t afi,
5490 safi_t safi, const char *direct_str)
5491 {
5492 int ret;
5493 struct peer *peer;
5494 int direct = FILTER_IN;
5495
5496 peer = peer_and_group_lookup_vty(vty, ip_str);
5497 if (!peer)
5498 return CMD_WARNING_CONFIG_FAILED;
5499
5500 /* Check filter direction. */
5501 if (strncmp(direct_str, "i", 1) == 0)
5502 direct = FILTER_IN;
5503 else if (strncmp(direct_str, "o", 1) == 0)
5504 direct = FILTER_OUT;
5505
5506 ret = peer_aslist_unset(peer, afi, safi, direct);
5507
5508 return bgp_vty_return(vty, ret);
5509 }
5510
5511 DEFUN (neighbor_filter_list,
5512 neighbor_filter_list_cmd,
5513 "neighbor <A.B.C.D|X:X::X:X|WORD> filter-list WORD <in|out>",
5514 NEIGHBOR_STR
5515 NEIGHBOR_ADDR_STR2
5516 "Establish BGP filters\n"
5517 "AS path access-list name\n"
5518 "Filter incoming routes\n"
5519 "Filter outgoing routes\n")
5520 {
5521 int idx_peer = 1;
5522 int idx_word = 3;
5523 int idx_in_out = 4;
5524 return peer_aslist_set_vty(vty, argv[idx_peer]->arg, bgp_node_afi(vty),
5525 bgp_node_safi(vty), argv[idx_word]->arg,
5526 argv[idx_in_out]->arg);
5527 }
5528
5529 ALIAS_HIDDEN(neighbor_filter_list, neighbor_filter_list_hidden_cmd,
5530 "neighbor <A.B.C.D|X:X::X:X|WORD> filter-list WORD <in|out>",
5531 NEIGHBOR_STR NEIGHBOR_ADDR_STR2
5532 "Establish BGP filters\n"
5533 "AS path access-list name\n"
5534 "Filter incoming routes\n"
5535 "Filter outgoing routes\n")
5536
5537 DEFUN (no_neighbor_filter_list,
5538 no_neighbor_filter_list_cmd,
5539 "no neighbor <A.B.C.D|X:X::X:X|WORD> filter-list WORD <in|out>",
5540 NO_STR
5541 NEIGHBOR_STR
5542 NEIGHBOR_ADDR_STR2
5543 "Establish BGP filters\n"
5544 "AS path access-list name\n"
5545 "Filter incoming routes\n"
5546 "Filter outgoing routes\n")
5547 {
5548 int idx_peer = 2;
5549 int idx_in_out = 5;
5550 return peer_aslist_unset_vty(vty, argv[idx_peer]->arg,
5551 bgp_node_afi(vty), bgp_node_safi(vty),
5552 argv[idx_in_out]->arg);
5553 }
5554
5555 ALIAS_HIDDEN(no_neighbor_filter_list, no_neighbor_filter_list_hidden_cmd,
5556 "no neighbor <A.B.C.D|X:X::X:X|WORD> filter-list WORD <in|out>",
5557 NO_STR NEIGHBOR_STR NEIGHBOR_ADDR_STR2
5558 "Establish BGP filters\n"
5559 "AS path access-list name\n"
5560 "Filter incoming routes\n"
5561 "Filter outgoing routes\n")
5562
5563 /* Set route-map to the peer. */
5564 static int peer_route_map_set_vty(struct vty *vty, const char *ip_str,
5565 afi_t afi, safi_t safi, const char *name_str,
5566 const char *direct_str)
5567 {
5568 int ret;
5569 struct peer *peer;
5570 int direct = RMAP_IN;
5571
5572 peer = peer_and_group_lookup_vty(vty, ip_str);
5573 if (!peer)
5574 return CMD_WARNING_CONFIG_FAILED;
5575
5576 /* Check filter direction. */
5577 if (strncmp(direct_str, "in", 2) == 0)
5578 direct = RMAP_IN;
5579 else if (strncmp(direct_str, "o", 1) == 0)
5580 direct = RMAP_OUT;
5581
5582 ret = peer_route_map_set(peer, afi, safi, direct, name_str);
5583
5584 return bgp_vty_return(vty, ret);
5585 }
5586
5587 static int peer_route_map_unset_vty(struct vty *vty, const char *ip_str,
5588 afi_t afi, safi_t safi,
5589 const char *direct_str)
5590 {
5591 int ret;
5592 struct peer *peer;
5593 int direct = RMAP_IN;
5594
5595 peer = peer_and_group_lookup_vty(vty, ip_str);
5596 if (!peer)
5597 return CMD_WARNING_CONFIG_FAILED;
5598
5599 /* Check filter direction. */
5600 if (strncmp(direct_str, "in", 2) == 0)
5601 direct = RMAP_IN;
5602 else if (strncmp(direct_str, "o", 1) == 0)
5603 direct = RMAP_OUT;
5604
5605 ret = peer_route_map_unset(peer, afi, safi, direct);
5606
5607 return bgp_vty_return(vty, ret);
5608 }
5609
5610 DEFUN (neighbor_route_map,
5611 neighbor_route_map_cmd,
5612 "neighbor <A.B.C.D|X:X::X:X|WORD> route-map WORD <in|out>",
5613 NEIGHBOR_STR
5614 NEIGHBOR_ADDR_STR2
5615 "Apply route map to neighbor\n"
5616 "Name of route map\n"
5617 "Apply map to incoming routes\n"
5618 "Apply map to outbound routes\n")
5619 {
5620 int idx_peer = 1;
5621 int idx_word = 3;
5622 int idx_in_out = 4;
5623 return peer_route_map_set_vty(
5624 vty, argv[idx_peer]->arg, bgp_node_afi(vty), bgp_node_safi(vty),
5625 argv[idx_word]->arg, argv[idx_in_out]->arg);
5626 }
5627
5628 ALIAS_HIDDEN(neighbor_route_map, neighbor_route_map_hidden_cmd,
5629 "neighbor <A.B.C.D|X:X::X:X|WORD> route-map WORD <in|out>",
5630 NEIGHBOR_STR NEIGHBOR_ADDR_STR2
5631 "Apply route map to neighbor\n"
5632 "Name of route map\n"
5633 "Apply map to incoming routes\n"
5634 "Apply map to outbound routes\n")
5635
5636 DEFUN (no_neighbor_route_map,
5637 no_neighbor_route_map_cmd,
5638 "no neighbor <A.B.C.D|X:X::X:X|WORD> route-map WORD <in|out>",
5639 NO_STR
5640 NEIGHBOR_STR
5641 NEIGHBOR_ADDR_STR2
5642 "Apply route map to neighbor\n"
5643 "Name of route map\n"
5644 "Apply map to incoming routes\n"
5645 "Apply map to outbound routes\n")
5646 {
5647 int idx_peer = 2;
5648 int idx_in_out = 5;
5649 return peer_route_map_unset_vty(vty, argv[idx_peer]->arg,
5650 bgp_node_afi(vty), bgp_node_safi(vty),
5651 argv[idx_in_out]->arg);
5652 }
5653
5654 ALIAS_HIDDEN(no_neighbor_route_map, no_neighbor_route_map_hidden_cmd,
5655 "no neighbor <A.B.C.D|X:X::X:X|WORD> route-map WORD <in|out>",
5656 NO_STR NEIGHBOR_STR NEIGHBOR_ADDR_STR2
5657 "Apply route map to neighbor\n"
5658 "Name of route map\n"
5659 "Apply map to incoming routes\n"
5660 "Apply map to outbound routes\n")
5661
5662 /* Set unsuppress-map to the peer. */
5663 static int peer_unsuppress_map_set_vty(struct vty *vty, const char *ip_str,
5664 afi_t afi, safi_t safi,
5665 const char *name_str)
5666 {
5667 int ret;
5668 struct peer *peer;
5669
5670 peer = peer_and_group_lookup_vty(vty, ip_str);
5671 if (!peer)
5672 return CMD_WARNING_CONFIG_FAILED;
5673
5674 ret = peer_unsuppress_map_set(peer, afi, safi, name_str);
5675
5676 return bgp_vty_return(vty, ret);
5677 }
5678
5679 /* Unset route-map from the peer. */
5680 static int peer_unsuppress_map_unset_vty(struct vty *vty, const char *ip_str,
5681 afi_t afi, safi_t safi)
5682 {
5683 int ret;
5684 struct peer *peer;
5685
5686 peer = peer_and_group_lookup_vty(vty, ip_str);
5687 if (!peer)
5688 return CMD_WARNING_CONFIG_FAILED;
5689
5690 ret = peer_unsuppress_map_unset(peer, afi, safi);
5691
5692 return bgp_vty_return(vty, ret);
5693 }
5694
5695 DEFUN (neighbor_unsuppress_map,
5696 neighbor_unsuppress_map_cmd,
5697 "neighbor <A.B.C.D|X:X::X:X|WORD> unsuppress-map WORD",
5698 NEIGHBOR_STR
5699 NEIGHBOR_ADDR_STR2
5700 "Route-map to selectively unsuppress suppressed routes\n"
5701 "Name of route map\n")
5702 {
5703 int idx_peer = 1;
5704 int idx_word = 3;
5705 return peer_unsuppress_map_set_vty(
5706 vty, argv[idx_peer]->arg, bgp_node_afi(vty), bgp_node_safi(vty),
5707 argv[idx_word]->arg);
5708 }
5709
5710 ALIAS_HIDDEN(neighbor_unsuppress_map, neighbor_unsuppress_map_hidden_cmd,
5711 "neighbor <A.B.C.D|X:X::X:X|WORD> unsuppress-map WORD",
5712 NEIGHBOR_STR NEIGHBOR_ADDR_STR2
5713 "Route-map to selectively unsuppress suppressed routes\n"
5714 "Name of route map\n")
5715
5716 DEFUN (no_neighbor_unsuppress_map,
5717 no_neighbor_unsuppress_map_cmd,
5718 "no neighbor <A.B.C.D|X:X::X:X|WORD> unsuppress-map WORD",
5719 NO_STR
5720 NEIGHBOR_STR
5721 NEIGHBOR_ADDR_STR2
5722 "Route-map to selectively unsuppress suppressed routes\n"
5723 "Name of route map\n")
5724 {
5725 int idx_peer = 2;
5726 return peer_unsuppress_map_unset_vty(vty, argv[idx_peer]->arg,
5727 bgp_node_afi(vty),
5728 bgp_node_safi(vty));
5729 }
5730
5731 ALIAS_HIDDEN(no_neighbor_unsuppress_map, no_neighbor_unsuppress_map_hidden_cmd,
5732 "no neighbor <A.B.C.D|X:X::X:X|WORD> unsuppress-map WORD",
5733 NO_STR NEIGHBOR_STR NEIGHBOR_ADDR_STR2
5734 "Route-map to selectively unsuppress suppressed routes\n"
5735 "Name of route map\n")
5736
5737 static int peer_maximum_prefix_set_vty(struct vty *vty, const char *ip_str,
5738 afi_t afi, safi_t safi,
5739 const char *num_str,
5740 const char *threshold_str, int warning,
5741 const char *restart_str)
5742 {
5743 int ret;
5744 struct peer *peer;
5745 uint32_t max;
5746 uint8_t threshold;
5747 uint16_t restart;
5748
5749 peer = peer_and_group_lookup_vty(vty, ip_str);
5750 if (!peer)
5751 return CMD_WARNING_CONFIG_FAILED;
5752
5753 max = strtoul(num_str, NULL, 10);
5754 if (threshold_str)
5755 threshold = atoi(threshold_str);
5756 else
5757 threshold = MAXIMUM_PREFIX_THRESHOLD_DEFAULT;
5758
5759 if (restart_str)
5760 restart = atoi(restart_str);
5761 else
5762 restart = 0;
5763
5764 ret = peer_maximum_prefix_set(peer, afi, safi, max, threshold, warning,
5765 restart);
5766
5767 return bgp_vty_return(vty, ret);
5768 }
5769
5770 static int peer_maximum_prefix_unset_vty(struct vty *vty, const char *ip_str,
5771 afi_t afi, safi_t safi)
5772 {
5773 int ret;
5774 struct peer *peer;
5775
5776 peer = peer_and_group_lookup_vty(vty, ip_str);
5777 if (!peer)
5778 return CMD_WARNING_CONFIG_FAILED;
5779
5780 ret = peer_maximum_prefix_unset(peer, afi, safi);
5781
5782 return bgp_vty_return(vty, ret);
5783 }
5784
5785 /* Maximum number of prefix configuration. prefix count is different
5786 for each peer configuration. So this configuration can be set for
5787 each peer configuration. */
5788 DEFUN (neighbor_maximum_prefix,
5789 neighbor_maximum_prefix_cmd,
5790 "neighbor <A.B.C.D|X:X::X:X|WORD> maximum-prefix (1-4294967295)",
5791 NEIGHBOR_STR
5792 NEIGHBOR_ADDR_STR2
5793 "Maximum number of prefix accept from this peer\n"
5794 "maximum no. of prefix limit\n")
5795 {
5796 int idx_peer = 1;
5797 int idx_number = 3;
5798 return peer_maximum_prefix_set_vty(
5799 vty, argv[idx_peer]->arg, bgp_node_afi(vty), bgp_node_safi(vty),
5800 argv[idx_number]->arg, NULL, 0, NULL);
5801 }
5802
5803 ALIAS_HIDDEN(neighbor_maximum_prefix, neighbor_maximum_prefix_hidden_cmd,
5804 "neighbor <A.B.C.D|X:X::X:X|WORD> maximum-prefix (1-4294967295)",
5805 NEIGHBOR_STR NEIGHBOR_ADDR_STR2
5806 "Maximum number of prefix accept from this peer\n"
5807 "maximum no. of prefix limit\n")
5808
5809 DEFUN (neighbor_maximum_prefix_threshold,
5810 neighbor_maximum_prefix_threshold_cmd,
5811 "neighbor <A.B.C.D|X:X::X:X|WORD> maximum-prefix (1-4294967295) (1-100)",
5812 NEIGHBOR_STR
5813 NEIGHBOR_ADDR_STR2
5814 "Maximum number of prefix accept from this peer\n"
5815 "maximum no. of prefix limit\n"
5816 "Threshold value (%) at which to generate a warning msg\n")
5817 {
5818 int idx_peer = 1;
5819 int idx_number = 3;
5820 int idx_number_2 = 4;
5821 return peer_maximum_prefix_set_vty(
5822 vty, argv[idx_peer]->arg, bgp_node_afi(vty), bgp_node_safi(vty),
5823 argv[idx_number]->arg, argv[idx_number_2]->arg, 0, NULL);
5824 }
5825
5826 ALIAS_HIDDEN(
5827 neighbor_maximum_prefix_threshold,
5828 neighbor_maximum_prefix_threshold_hidden_cmd,
5829 "neighbor <A.B.C.D|X:X::X:X|WORD> maximum-prefix (1-4294967295) (1-100)",
5830 NEIGHBOR_STR NEIGHBOR_ADDR_STR2
5831 "Maximum number of prefix accept from this peer\n"
5832 "maximum no. of prefix limit\n"
5833 "Threshold value (%) at which to generate a warning msg\n")
5834
5835 DEFUN (neighbor_maximum_prefix_warning,
5836 neighbor_maximum_prefix_warning_cmd,
5837 "neighbor <A.B.C.D|X:X::X:X|WORD> maximum-prefix (1-4294967295) warning-only",
5838 NEIGHBOR_STR
5839 NEIGHBOR_ADDR_STR2
5840 "Maximum number of prefix accept from this peer\n"
5841 "maximum no. of prefix limit\n"
5842 "Only give warning message when limit is exceeded\n")
5843 {
5844 int idx_peer = 1;
5845 int idx_number = 3;
5846 return peer_maximum_prefix_set_vty(
5847 vty, argv[idx_peer]->arg, bgp_node_afi(vty), bgp_node_safi(vty),
5848 argv[idx_number]->arg, NULL, 1, NULL);
5849 }
5850
5851 ALIAS_HIDDEN(
5852 neighbor_maximum_prefix_warning,
5853 neighbor_maximum_prefix_warning_hidden_cmd,
5854 "neighbor <A.B.C.D|X:X::X:X|WORD> maximum-prefix (1-4294967295) warning-only",
5855 NEIGHBOR_STR NEIGHBOR_ADDR_STR2
5856 "Maximum number of prefix accept from this peer\n"
5857 "maximum no. of prefix limit\n"
5858 "Only give warning message when limit is exceeded\n")
5859
5860 DEFUN (neighbor_maximum_prefix_threshold_warning,
5861 neighbor_maximum_prefix_threshold_warning_cmd,
5862 "neighbor <A.B.C.D|X:X::X:X|WORD> maximum-prefix (1-4294967295) (1-100) warning-only",
5863 NEIGHBOR_STR
5864 NEIGHBOR_ADDR_STR2
5865 "Maximum number of prefix accept from this peer\n"
5866 "maximum no. of prefix limit\n"
5867 "Threshold value (%) at which to generate a warning msg\n"
5868 "Only give warning message when limit is exceeded\n")
5869 {
5870 int idx_peer = 1;
5871 int idx_number = 3;
5872 int idx_number_2 = 4;
5873 return peer_maximum_prefix_set_vty(
5874 vty, argv[idx_peer]->arg, bgp_node_afi(vty), bgp_node_safi(vty),
5875 argv[idx_number]->arg, argv[idx_number_2]->arg, 1, NULL);
5876 }
5877
5878 ALIAS_HIDDEN(
5879 neighbor_maximum_prefix_threshold_warning,
5880 neighbor_maximum_prefix_threshold_warning_hidden_cmd,
5881 "neighbor <A.B.C.D|X:X::X:X|WORD> maximum-prefix (1-4294967295) (1-100) warning-only",
5882 NEIGHBOR_STR NEIGHBOR_ADDR_STR2
5883 "Maximum number of prefix accept from this peer\n"
5884 "maximum no. of prefix limit\n"
5885 "Threshold value (%) at which to generate a warning msg\n"
5886 "Only give warning message when limit is exceeded\n")
5887
5888 DEFUN (neighbor_maximum_prefix_restart,
5889 neighbor_maximum_prefix_restart_cmd,
5890 "neighbor <A.B.C.D|X:X::X:X|WORD> maximum-prefix (1-4294967295) restart (1-65535)",
5891 NEIGHBOR_STR
5892 NEIGHBOR_ADDR_STR2
5893 "Maximum number of prefix accept from this peer\n"
5894 "maximum no. of prefix limit\n"
5895 "Restart bgp connection after limit is exceeded\n"
5896 "Restart interval in minutes\n")
5897 {
5898 int idx_peer = 1;
5899 int idx_number = 3;
5900 int idx_number_2 = 5;
5901 return peer_maximum_prefix_set_vty(
5902 vty, argv[idx_peer]->arg, bgp_node_afi(vty), bgp_node_safi(vty),
5903 argv[idx_number]->arg, NULL, 0, argv[idx_number_2]->arg);
5904 }
5905
5906 ALIAS_HIDDEN(
5907 neighbor_maximum_prefix_restart,
5908 neighbor_maximum_prefix_restart_hidden_cmd,
5909 "neighbor <A.B.C.D|X:X::X:X|WORD> maximum-prefix (1-4294967295) restart (1-65535)",
5910 NEIGHBOR_STR NEIGHBOR_ADDR_STR2
5911 "Maximum number of prefix accept from this peer\n"
5912 "maximum no. of prefix limit\n"
5913 "Restart bgp connection after limit is exceeded\n"
5914 "Restart interval in minutes\n")
5915
5916 DEFUN (neighbor_maximum_prefix_threshold_restart,
5917 neighbor_maximum_prefix_threshold_restart_cmd,
5918 "neighbor <A.B.C.D|X:X::X:X|WORD> maximum-prefix (1-4294967295) (1-100) restart (1-65535)",
5919 NEIGHBOR_STR
5920 NEIGHBOR_ADDR_STR2
5921 "Maximum number of prefixes to accept from this peer\n"
5922 "maximum no. of prefix limit\n"
5923 "Threshold value (%) at which to generate a warning msg\n"
5924 "Restart bgp connection after limit is exceeded\n"
5925 "Restart interval in minutes\n")
5926 {
5927 int idx_peer = 1;
5928 int idx_number = 3;
5929 int idx_number_2 = 4;
5930 int idx_number_3 = 6;
5931 return peer_maximum_prefix_set_vty(
5932 vty, argv[idx_peer]->arg, bgp_node_afi(vty), bgp_node_safi(vty),
5933 argv[idx_number]->arg, argv[idx_number_2]->arg, 0,
5934 argv[idx_number_3]->arg);
5935 }
5936
5937 ALIAS_HIDDEN(
5938 neighbor_maximum_prefix_threshold_restart,
5939 neighbor_maximum_prefix_threshold_restart_hidden_cmd,
5940 "neighbor <A.B.C.D|X:X::X:X|WORD> maximum-prefix (1-4294967295) (1-100) restart (1-65535)",
5941 NEIGHBOR_STR NEIGHBOR_ADDR_STR2
5942 "Maximum number of prefixes to accept from this peer\n"
5943 "maximum no. of prefix limit\n"
5944 "Threshold value (%) at which to generate a warning msg\n"
5945 "Restart bgp connection after limit is exceeded\n"
5946 "Restart interval in minutes\n")
5947
5948 DEFUN (no_neighbor_maximum_prefix,
5949 no_neighbor_maximum_prefix_cmd,
5950 "no neighbor <A.B.C.D|X:X::X:X|WORD> maximum-prefix [(1-4294967295) [(1-100)] [restart (1-65535)] [warning-only]]",
5951 NO_STR
5952 NEIGHBOR_STR
5953 NEIGHBOR_ADDR_STR2
5954 "Maximum number of prefixes to accept from this peer\n"
5955 "maximum no. of prefix limit\n"
5956 "Threshold value (%) at which to generate a warning msg\n"
5957 "Restart bgp connection after limit is exceeded\n"
5958 "Restart interval in minutes\n"
5959 "Only give warning message when limit is exceeded\n")
5960 {
5961 int idx_peer = 2;
5962 return peer_maximum_prefix_unset_vty(vty, argv[idx_peer]->arg,
5963 bgp_node_afi(vty),
5964 bgp_node_safi(vty));
5965 }
5966
5967 ALIAS_HIDDEN(
5968 no_neighbor_maximum_prefix, no_neighbor_maximum_prefix_hidden_cmd,
5969 "no neighbor <A.B.C.D|X:X::X:X|WORD> maximum-prefix [(1-4294967295) [(1-100)] [restart (1-65535)] [warning-only]]",
5970 NO_STR NEIGHBOR_STR NEIGHBOR_ADDR_STR2
5971 "Maximum number of prefixes to accept from this peer\n"
5972 "maximum no. of prefix limit\n"
5973 "Threshold value (%) at which to generate a warning msg\n"
5974 "Restart bgp connection after limit is exceeded\n"
5975 "Restart interval in minutes\n"
5976 "Only give warning message when limit is exceeded\n")
5977
5978
5979 /* "neighbor allowas-in" */
5980 DEFUN (neighbor_allowas_in,
5981 neighbor_allowas_in_cmd,
5982 "neighbor <A.B.C.D|X:X::X:X|WORD> allowas-in [<(1-10)|origin>]",
5983 NEIGHBOR_STR
5984 NEIGHBOR_ADDR_STR2
5985 "Accept as-path with my AS present in it\n"
5986 "Number of occurances of AS number\n"
5987 "Only accept my AS in the as-path if the route was originated in my AS\n")
5988 {
5989 int idx_peer = 1;
5990 int idx_number_origin = 3;
5991 int ret;
5992 int origin = 0;
5993 struct peer *peer;
5994 int allow_num = 0;
5995
5996 peer = peer_and_group_lookup_vty(vty, argv[idx_peer]->arg);
5997 if (!peer)
5998 return CMD_WARNING_CONFIG_FAILED;
5999
6000 if (argc <= idx_number_origin)
6001 allow_num = 3;
6002 else {
6003 if (argv[idx_number_origin]->type == WORD_TKN)
6004 origin = 1;
6005 else
6006 allow_num = atoi(argv[idx_number_origin]->arg);
6007 }
6008
6009 ret = peer_allowas_in_set(peer, bgp_node_afi(vty), bgp_node_safi(vty),
6010 allow_num, origin);
6011
6012 return bgp_vty_return(vty, ret);
6013 }
6014
6015 ALIAS_HIDDEN(
6016 neighbor_allowas_in, neighbor_allowas_in_hidden_cmd,
6017 "neighbor <A.B.C.D|X:X::X:X|WORD> allowas-in [<(1-10)|origin>]",
6018 NEIGHBOR_STR NEIGHBOR_ADDR_STR2
6019 "Accept as-path with my AS present in it\n"
6020 "Number of occurances of AS number\n"
6021 "Only accept my AS in the as-path if the route was originated in my AS\n")
6022
6023 DEFUN (no_neighbor_allowas_in,
6024 no_neighbor_allowas_in_cmd,
6025 "no neighbor <A.B.C.D|X:X::X:X|WORD> allowas-in [<(1-10)|origin>]",
6026 NO_STR
6027 NEIGHBOR_STR
6028 NEIGHBOR_ADDR_STR2
6029 "allow local ASN appears in aspath attribute\n"
6030 "Number of occurances of AS number\n"
6031 "Only accept my AS in the as-path if the route was originated in my AS\n")
6032 {
6033 int idx_peer = 2;
6034 int ret;
6035 struct peer *peer;
6036
6037 peer = peer_and_group_lookup_vty(vty, argv[idx_peer]->arg);
6038 if (!peer)
6039 return CMD_WARNING_CONFIG_FAILED;
6040
6041 ret = peer_allowas_in_unset(peer, bgp_node_afi(vty),
6042 bgp_node_safi(vty));
6043
6044 return bgp_vty_return(vty, ret);
6045 }
6046
6047 ALIAS_HIDDEN(
6048 no_neighbor_allowas_in, no_neighbor_allowas_in_hidden_cmd,
6049 "no neighbor <A.B.C.D|X:X::X:X|WORD> allowas-in [<(1-10)|origin>]",
6050 NO_STR NEIGHBOR_STR NEIGHBOR_ADDR_STR2
6051 "allow local ASN appears in aspath attribute\n"
6052 "Number of occurances of AS number\n"
6053 "Only accept my AS in the as-path if the route was originated in my AS\n")
6054
6055 DEFUN (neighbor_ttl_security,
6056 neighbor_ttl_security_cmd,
6057 "neighbor <A.B.C.D|X:X::X:X|WORD> ttl-security hops (1-254)",
6058 NEIGHBOR_STR
6059 NEIGHBOR_ADDR_STR2
6060 "BGP ttl-security parameters\n"
6061 "Specify the maximum number of hops to the BGP peer\n"
6062 "Number of hops to BGP peer\n")
6063 {
6064 int idx_peer = 1;
6065 int idx_number = 4;
6066 struct peer *peer;
6067 int gtsm_hops;
6068
6069 peer = peer_and_group_lookup_vty(vty, argv[idx_peer]->arg);
6070 if (!peer)
6071 return CMD_WARNING_CONFIG_FAILED;
6072
6073 gtsm_hops = strtoul(argv[idx_number]->arg, NULL, 10);
6074
6075 /*
6076 * If 'neighbor swpX', then this is for directly connected peers,
6077 * we should not accept a ttl-security hops value greater than 1.
6078 */
6079 if (peer->conf_if && (gtsm_hops > 1)) {
6080 vty_out(vty,
6081 "%s is directly connected peer, hops cannot exceed 1\n",
6082 argv[idx_peer]->arg);
6083 return CMD_WARNING_CONFIG_FAILED;
6084 }
6085
6086 return bgp_vty_return(vty, peer_ttl_security_hops_set(peer, gtsm_hops));
6087 }
6088
6089 DEFUN (no_neighbor_ttl_security,
6090 no_neighbor_ttl_security_cmd,
6091 "no neighbor <A.B.C.D|X:X::X:X|WORD> ttl-security hops (1-254)",
6092 NO_STR
6093 NEIGHBOR_STR
6094 NEIGHBOR_ADDR_STR2
6095 "BGP ttl-security parameters\n"
6096 "Specify the maximum number of hops to the BGP peer\n"
6097 "Number of hops to BGP peer\n")
6098 {
6099 int idx_peer = 2;
6100 struct peer *peer;
6101
6102 peer = peer_and_group_lookup_vty(vty, argv[idx_peer]->arg);
6103 if (!peer)
6104 return CMD_WARNING_CONFIG_FAILED;
6105
6106 return bgp_vty_return(vty, peer_ttl_security_hops_unset(peer));
6107 }
6108
6109 DEFUN (neighbor_addpath_tx_all_paths,
6110 neighbor_addpath_tx_all_paths_cmd,
6111 "neighbor <A.B.C.D|X:X::X:X|WORD> addpath-tx-all-paths",
6112 NEIGHBOR_STR
6113 NEIGHBOR_ADDR_STR2
6114 "Use addpath to advertise all paths to a neighbor\n")
6115 {
6116 int idx_peer = 1;
6117 struct peer *peer;
6118
6119 peer = peer_and_group_lookup_vty(vty, argv[idx_peer]->arg);
6120 if (!peer)
6121 return CMD_WARNING_CONFIG_FAILED;
6122
6123 return peer_af_flag_set_vty(vty, argv[idx_peer]->arg, bgp_node_afi(vty),
6124 bgp_node_safi(vty),
6125 PEER_FLAG_ADDPATH_TX_ALL_PATHS);
6126 }
6127
6128 ALIAS_HIDDEN(neighbor_addpath_tx_all_paths,
6129 neighbor_addpath_tx_all_paths_hidden_cmd,
6130 "neighbor <A.B.C.D|X:X::X:X|WORD> addpath-tx-all-paths",
6131 NEIGHBOR_STR NEIGHBOR_ADDR_STR2
6132 "Use addpath to advertise all paths to a neighbor\n")
6133
6134 DEFUN (no_neighbor_addpath_tx_all_paths,
6135 no_neighbor_addpath_tx_all_paths_cmd,
6136 "no neighbor <A.B.C.D|X:X::X:X|WORD> addpath-tx-all-paths",
6137 NO_STR
6138 NEIGHBOR_STR
6139 NEIGHBOR_ADDR_STR2
6140 "Use addpath to advertise all paths to a neighbor\n")
6141 {
6142 int idx_peer = 2;
6143 return peer_af_flag_unset_vty(vty, argv[idx_peer]->arg,
6144 bgp_node_afi(vty), bgp_node_safi(vty),
6145 PEER_FLAG_ADDPATH_TX_ALL_PATHS);
6146 }
6147
6148 ALIAS_HIDDEN(no_neighbor_addpath_tx_all_paths,
6149 no_neighbor_addpath_tx_all_paths_hidden_cmd,
6150 "no neighbor <A.B.C.D|X:X::X:X|WORD> addpath-tx-all-paths",
6151 NO_STR NEIGHBOR_STR NEIGHBOR_ADDR_STR2
6152 "Use addpath to advertise all paths to a neighbor\n")
6153
6154 DEFUN (neighbor_addpath_tx_bestpath_per_as,
6155 neighbor_addpath_tx_bestpath_per_as_cmd,
6156 "neighbor <A.B.C.D|X:X::X:X|WORD> addpath-tx-bestpath-per-AS",
6157 NEIGHBOR_STR
6158 NEIGHBOR_ADDR_STR2
6159 "Use addpath to advertise the bestpath per each neighboring AS\n")
6160 {
6161 int idx_peer = 1;
6162 struct peer *peer;
6163
6164 peer = peer_and_group_lookup_vty(vty, argv[idx_peer]->arg);
6165 if (!peer)
6166 return CMD_WARNING_CONFIG_FAILED;
6167
6168 return peer_af_flag_set_vty(vty, argv[idx_peer]->arg, bgp_node_afi(vty),
6169 bgp_node_safi(vty),
6170 PEER_FLAG_ADDPATH_TX_BESTPATH_PER_AS);
6171 }
6172
6173 ALIAS_HIDDEN(neighbor_addpath_tx_bestpath_per_as,
6174 neighbor_addpath_tx_bestpath_per_as_hidden_cmd,
6175 "neighbor <A.B.C.D|X:X::X:X|WORD> addpath-tx-bestpath-per-AS",
6176 NEIGHBOR_STR NEIGHBOR_ADDR_STR2
6177 "Use addpath to advertise the bestpath per each neighboring AS\n")
6178
6179 DEFUN (no_neighbor_addpath_tx_bestpath_per_as,
6180 no_neighbor_addpath_tx_bestpath_per_as_cmd,
6181 "no neighbor <A.B.C.D|X:X::X:X|WORD> addpath-tx-bestpath-per-AS",
6182 NO_STR
6183 NEIGHBOR_STR
6184 NEIGHBOR_ADDR_STR2
6185 "Use addpath to advertise the bestpath per each neighboring AS\n")
6186 {
6187 int idx_peer = 2;
6188 return peer_af_flag_unset_vty(vty, argv[idx_peer]->arg,
6189 bgp_node_afi(vty), bgp_node_safi(vty),
6190 PEER_FLAG_ADDPATH_TX_BESTPATH_PER_AS);
6191 }
6192
6193 ALIAS_HIDDEN(no_neighbor_addpath_tx_bestpath_per_as,
6194 no_neighbor_addpath_tx_bestpath_per_as_hidden_cmd,
6195 "no neighbor <A.B.C.D|X:X::X:X|WORD> addpath-tx-bestpath-per-AS",
6196 NO_STR NEIGHBOR_STR NEIGHBOR_ADDR_STR2
6197 "Use addpath to advertise the bestpath per each neighboring AS\n")
6198
6199 static int set_ecom_list(struct vty *vty, int argc, struct cmd_token **argv,
6200 struct ecommunity **list)
6201 {
6202 struct ecommunity *ecom = NULL;
6203 struct ecommunity *ecomadd;
6204
6205 for (; argc; --argc, ++argv) {
6206
6207 ecomadd = ecommunity_str2com(argv[0]->arg,
6208 ECOMMUNITY_ROUTE_TARGET, 0);
6209 if (!ecomadd) {
6210 vty_out(vty, "Malformed community-list value\n");
6211 if (ecom)
6212 ecommunity_free(&ecom);
6213 return CMD_WARNING_CONFIG_FAILED;
6214 }
6215
6216 if (ecom) {
6217 ecommunity_merge(ecom, ecomadd);
6218 ecommunity_free(&ecomadd);
6219 } else {
6220 ecom = ecomadd;
6221 }
6222 }
6223
6224 if (*list) {
6225 ecommunity_free(&*list);
6226 }
6227 *list = ecom;
6228
6229 return CMD_SUCCESS;
6230 }
6231
6232 /*
6233 * v2vimport is true if we are handling a `import vrf ...` command
6234 */
6235 static afi_t vpn_policy_getafi(struct vty *vty, struct bgp *bgp, bool v2vimport)
6236 {
6237 afi_t afi;
6238
6239 switch (vty->node) {
6240 case BGP_IPV4_NODE:
6241 afi = AFI_IP;
6242 break;
6243 case BGP_IPV6_NODE:
6244 afi = AFI_IP6;
6245 break;
6246 default:
6247 vty_out(vty,
6248 "%% context error: valid only in address-family <ipv4|ipv6> unicast block\n");
6249 return AFI_MAX;
6250 }
6251
6252 if (!v2vimport) {
6253 if (CHECK_FLAG(bgp->af_flags[afi][SAFI_UNICAST],
6254 BGP_CONFIG_VRF_TO_VRF_IMPORT)
6255 || CHECK_FLAG(bgp->af_flags[afi][SAFI_UNICAST],
6256 BGP_CONFIG_VRF_TO_VRF_EXPORT)) {
6257 vty_out(vty,
6258 "%% error: Please unconfigure import vrf commands before using vpn commands\n");
6259 return AFI_MAX;
6260 }
6261 } else {
6262 if (CHECK_FLAG(bgp->af_flags[afi][SAFI_UNICAST],
6263 BGP_CONFIG_VRF_TO_MPLSVPN_EXPORT)
6264 || CHECK_FLAG(bgp->af_flags[afi][SAFI_UNICAST],
6265 BGP_CONFIG_MPLSVPN_TO_VRF_IMPORT)) {
6266 vty_out(vty,
6267 "%% error: Please unconfigure vpn to vrf commands before using import vrf commands\n");
6268 return AFI_MAX;
6269 }
6270 }
6271 return afi;
6272 }
6273
6274 DEFPY (af_rd_vpn_export,
6275 af_rd_vpn_export_cmd,
6276 "[no] rd vpn export ASN:NN_OR_IP-ADDRESS:NN$rd_str",
6277 NO_STR
6278 "Specify route distinguisher\n"
6279 "Between current address-family and vpn\n"
6280 "For routes leaked from current address-family to vpn\n"
6281 "Route Distinguisher (<as-number>:<number> | <ip-address>:<number>)\n")
6282 {
6283 VTY_DECLVAR_CONTEXT(bgp, bgp);
6284 struct prefix_rd prd;
6285 int ret;
6286 afi_t afi;
6287 int idx = 0;
6288 int yes = 1;
6289
6290 if (argv_find(argv, argc, "no", &idx))
6291 yes = 0;
6292
6293 if (yes) {
6294 ret = str2prefix_rd(rd_str, &prd);
6295 if (!ret) {
6296 vty_out(vty, "%% Malformed rd\n");
6297 return CMD_WARNING_CONFIG_FAILED;
6298 }
6299 }
6300
6301 afi = vpn_policy_getafi(vty, bgp, false);
6302 if (afi == AFI_MAX)
6303 return CMD_WARNING_CONFIG_FAILED;
6304
6305 /*
6306 * pre-change: un-export vpn routes (vpn->vrf routes unaffected)
6307 */
6308 vpn_leak_prechange(BGP_VPN_POLICY_DIR_TOVPN, afi,
6309 bgp_get_default(), bgp);
6310
6311 if (yes) {
6312 bgp->vpn_policy[afi].tovpn_rd = prd;
6313 SET_FLAG(bgp->vpn_policy[afi].flags,
6314 BGP_VPN_POLICY_TOVPN_RD_SET);
6315 } else {
6316 UNSET_FLAG(bgp->vpn_policy[afi].flags,
6317 BGP_VPN_POLICY_TOVPN_RD_SET);
6318 }
6319
6320 /* post-change: re-export vpn routes */
6321 vpn_leak_postchange(BGP_VPN_POLICY_DIR_TOVPN, afi,
6322 bgp_get_default(), bgp);
6323
6324 return CMD_SUCCESS;
6325 }
6326
6327 ALIAS (af_rd_vpn_export,
6328 af_no_rd_vpn_export_cmd,
6329 "no rd vpn export",
6330 NO_STR
6331 "Specify route distinguisher\n"
6332 "Between current address-family and vpn\n"
6333 "For routes leaked from current address-family to vpn\n")
6334
6335 DEFPY (af_label_vpn_export,
6336 af_label_vpn_export_cmd,
6337 "[no] label vpn export <(0-1048575)$label_val|auto$label_auto>",
6338 NO_STR
6339 "label value for VRF\n"
6340 "Between current address-family and vpn\n"
6341 "For routes leaked from current address-family to vpn\n"
6342 "Label Value <0-1048575>\n"
6343 "Automatically assign a label\n")
6344 {
6345 VTY_DECLVAR_CONTEXT(bgp, bgp);
6346 mpls_label_t label = MPLS_LABEL_NONE;
6347 afi_t afi;
6348 int idx = 0;
6349 int yes = 1;
6350
6351 if (argv_find(argv, argc, "no", &idx))
6352 yes = 0;
6353
6354 /* If "no ...", squash trailing parameter */
6355 if (!yes)
6356 label_auto = NULL;
6357
6358 if (yes) {
6359 if (!label_auto)
6360 label = label_val; /* parser should force unsigned */
6361 }
6362
6363 afi = vpn_policy_getafi(vty, bgp, false);
6364 if (afi == AFI_MAX)
6365 return CMD_WARNING_CONFIG_FAILED;
6366
6367
6368 if (label_auto && CHECK_FLAG(bgp->vpn_policy[afi].flags,
6369 BGP_VPN_POLICY_TOVPN_LABEL_AUTO))
6370 /* no change */
6371 return CMD_SUCCESS;
6372
6373 /*
6374 * pre-change: un-export vpn routes (vpn->vrf routes unaffected)
6375 */
6376 vpn_leak_prechange(BGP_VPN_POLICY_DIR_TOVPN, afi,
6377 bgp_get_default(), bgp);
6378
6379 if (!label_auto && CHECK_FLAG(bgp->vpn_policy[afi].flags,
6380 BGP_VPN_POLICY_TOVPN_LABEL_AUTO)) {
6381
6382 if (bgp->vpn_policy[afi].tovpn_label != MPLS_LABEL_NONE) {
6383
6384 /*
6385 * label has previously been automatically
6386 * assigned by labelpool: release it
6387 *
6388 * NB if tovpn_label == MPLS_LABEL_NONE it
6389 * means the automatic assignment is in flight
6390 * and therefore the labelpool callback must
6391 * detect that the auto label is not needed.
6392 */
6393
6394 bgp_lp_release(LP_TYPE_VRF,
6395 &bgp->vpn_policy[afi],
6396 bgp->vpn_policy[afi].tovpn_label);
6397 }
6398 UNSET_FLAG(bgp->vpn_policy[afi].flags,
6399 BGP_VPN_POLICY_TOVPN_LABEL_AUTO);
6400 }
6401
6402 bgp->vpn_policy[afi].tovpn_label = label;
6403 if (label_auto) {
6404 SET_FLAG(bgp->vpn_policy[afi].flags,
6405 BGP_VPN_POLICY_TOVPN_LABEL_AUTO);
6406 bgp_lp_get(LP_TYPE_VRF, &bgp->vpn_policy[afi],
6407 vpn_leak_label_callback);
6408 }
6409
6410 /* post-change: re-export vpn routes */
6411 vpn_leak_postchange(BGP_VPN_POLICY_DIR_TOVPN, afi,
6412 bgp_get_default(), bgp);
6413
6414 return CMD_SUCCESS;
6415 }
6416
6417 ALIAS (af_label_vpn_export,
6418 af_no_label_vpn_export_cmd,
6419 "no label vpn export",
6420 NO_STR
6421 "label value for VRF\n"
6422 "Between current address-family and vpn\n"
6423 "For routes leaked from current address-family to vpn\n")
6424
6425 DEFPY (af_nexthop_vpn_export,
6426 af_nexthop_vpn_export_cmd,
6427 "[no] nexthop vpn export <A.B.C.D|X:X::X:X>$nexthop_str",
6428 NO_STR
6429 "Specify next hop to use for VRF advertised prefixes\n"
6430 "Between current address-family and vpn\n"
6431 "For routes leaked from current address-family to vpn\n"
6432 "IPv4 prefix\n"
6433 "IPv6 prefix\n")
6434 {
6435 VTY_DECLVAR_CONTEXT(bgp, bgp);
6436 afi_t afi;
6437 struct prefix p;
6438 int idx = 0;
6439 int yes = 1;
6440
6441 if (argv_find(argv, argc, "no", &idx))
6442 yes = 0;
6443
6444 if (yes) {
6445 if (!sockunion2hostprefix(nexthop_str, &p))
6446 return CMD_WARNING_CONFIG_FAILED;
6447 }
6448
6449 afi = vpn_policy_getafi(vty, bgp, false);
6450 if (afi == AFI_MAX)
6451 return CMD_WARNING_CONFIG_FAILED;
6452
6453 /*
6454 * pre-change: un-export vpn routes (vpn->vrf routes unaffected)
6455 */
6456 vpn_leak_prechange(BGP_VPN_POLICY_DIR_TOVPN, afi,
6457 bgp_get_default(), bgp);
6458
6459 if (yes) {
6460 bgp->vpn_policy[afi].tovpn_nexthop = p;
6461 SET_FLAG(bgp->vpn_policy[afi].flags,
6462 BGP_VPN_POLICY_TOVPN_NEXTHOP_SET);
6463 } else {
6464 UNSET_FLAG(bgp->vpn_policy[afi].flags,
6465 BGP_VPN_POLICY_TOVPN_NEXTHOP_SET);
6466 }
6467
6468 /* post-change: re-export vpn routes */
6469 vpn_leak_postchange(BGP_VPN_POLICY_DIR_TOVPN, afi,
6470 bgp_get_default(), bgp);
6471
6472 return CMD_SUCCESS;
6473 }
6474
6475 ALIAS (af_nexthop_vpn_export,
6476 af_no_nexthop_vpn_export_cmd,
6477 "no nexthop vpn export",
6478 NO_STR
6479 "Specify next hop to use for VRF advertised prefixes\n"
6480 "Between current address-family and vpn\n"
6481 "For routes leaked from current address-family to vpn\n")
6482
6483 static int vpn_policy_getdirs(struct vty *vty, const char *dstr, int *dodir)
6484 {
6485 if (!strcmp(dstr, "import")) {
6486 dodir[BGP_VPN_POLICY_DIR_FROMVPN] = 1;
6487 } else if (!strcmp(dstr, "export")) {
6488 dodir[BGP_VPN_POLICY_DIR_TOVPN] = 1;
6489 } else if (!strcmp(dstr, "both")) {
6490 dodir[BGP_VPN_POLICY_DIR_FROMVPN] = 1;
6491 dodir[BGP_VPN_POLICY_DIR_TOVPN] = 1;
6492 } else {
6493 vty_out(vty, "%% direction parse error\n");
6494 return CMD_WARNING_CONFIG_FAILED;
6495 }
6496 return CMD_SUCCESS;
6497 }
6498
6499 DEFPY (af_rt_vpn_imexport,
6500 af_rt_vpn_imexport_cmd,
6501 "[no] <rt|route-target> vpn <import|export|both>$direction_str RTLIST...",
6502 NO_STR
6503 "Specify route target list\n"
6504 "Specify route target list\n"
6505 "Between current address-family and vpn\n"
6506 "For routes leaked from vpn to current address-family: match any\n"
6507 "For routes leaked from current address-family to vpn: set\n"
6508 "both import: match any and export: set\n"
6509 "Space separated route target list (A.B.C.D:MN|EF:OPQR|GHJK:MN)\n")
6510 {
6511 VTY_DECLVAR_CONTEXT(bgp, bgp);
6512 int ret;
6513 struct ecommunity *ecom = NULL;
6514 int dodir[BGP_VPN_POLICY_DIR_MAX] = {0};
6515 vpn_policy_direction_t dir;
6516 afi_t afi;
6517 int idx = 0;
6518 int yes = 1;
6519
6520 if (argv_find(argv, argc, "no", &idx))
6521 yes = 0;
6522
6523 afi = vpn_policy_getafi(vty, bgp, false);
6524 if (afi == AFI_MAX)
6525 return CMD_WARNING_CONFIG_FAILED;
6526
6527 ret = vpn_policy_getdirs(vty, direction_str, dodir);
6528 if (ret != CMD_SUCCESS)
6529 return ret;
6530
6531 if (yes) {
6532 if (!argv_find(argv, argc, "RTLIST", &idx)) {
6533 vty_out(vty, "%% Missing RTLIST\n");
6534 return CMD_WARNING_CONFIG_FAILED;
6535 }
6536 ret = set_ecom_list(vty, argc - idx, argv + idx, &ecom);
6537 if (ret != CMD_SUCCESS) {
6538 return ret;
6539 }
6540 }
6541
6542 for (dir = 0; dir < BGP_VPN_POLICY_DIR_MAX; ++dir) {
6543 if (!dodir[dir])
6544 continue;
6545
6546 vpn_leak_prechange(dir, afi, bgp_get_default(), bgp);
6547
6548 if (yes) {
6549 if (bgp->vpn_policy[afi].rtlist[dir])
6550 ecommunity_free(
6551 &bgp->vpn_policy[afi].rtlist[dir]);
6552 bgp->vpn_policy[afi].rtlist[dir] =
6553 ecommunity_dup(ecom);
6554 } else {
6555 if (bgp->vpn_policy[afi].rtlist[dir])
6556 ecommunity_free(
6557 &bgp->vpn_policy[afi].rtlist[dir]);
6558 bgp->vpn_policy[afi].rtlist[dir] = NULL;
6559 }
6560
6561 vpn_leak_postchange(dir, afi, bgp_get_default(), bgp);
6562 }
6563
6564 if (ecom)
6565 ecommunity_free(&ecom);
6566
6567 return CMD_SUCCESS;
6568 }
6569
6570 ALIAS (af_rt_vpn_imexport,
6571 af_no_rt_vpn_imexport_cmd,
6572 "no <rt|route-target> vpn <import|export|both>$direction_str",
6573 NO_STR
6574 "Specify route target list\n"
6575 "Specify route target list\n"
6576 "Between current address-family and vpn\n"
6577 "For routes leaked from vpn to current address-family\n"
6578 "For routes leaked from current address-family to vpn\n"
6579 "both import and export\n")
6580
6581 DEFPY (af_route_map_vpn_imexport,
6582 af_route_map_vpn_imexport_cmd,
6583 /* future: "route-map <vpn|evpn|vrf NAME> <import|export> RMAP" */
6584 "[no] route-map vpn <import|export>$direction_str RMAP$rmap_str",
6585 NO_STR
6586 "Specify route map\n"
6587 "Between current address-family and vpn\n"
6588 "For routes leaked from vpn to current address-family\n"
6589 "For routes leaked from current address-family to vpn\n"
6590 "name of route-map\n")
6591 {
6592 VTY_DECLVAR_CONTEXT(bgp, bgp);
6593 int ret;
6594 int dodir[BGP_VPN_POLICY_DIR_MAX] = {0};
6595 vpn_policy_direction_t dir;
6596 afi_t afi;
6597 int idx = 0;
6598 int yes = 1;
6599
6600 if (argv_find(argv, argc, "no", &idx))
6601 yes = 0;
6602
6603 afi = vpn_policy_getafi(vty, bgp, false);
6604 if (afi == AFI_MAX)
6605 return CMD_WARNING_CONFIG_FAILED;
6606
6607 ret = vpn_policy_getdirs(vty, direction_str, dodir);
6608 if (ret != CMD_SUCCESS)
6609 return ret;
6610
6611 for (dir = 0; dir < BGP_VPN_POLICY_DIR_MAX; ++dir) {
6612 if (!dodir[dir])
6613 continue;
6614
6615 vpn_leak_prechange(dir, afi, bgp_get_default(), bgp);
6616
6617 if (yes) {
6618 if (bgp->vpn_policy[afi].rmap_name[dir])
6619 XFREE(MTYPE_ROUTE_MAP_NAME,
6620 bgp->vpn_policy[afi].rmap_name[dir]);
6621 bgp->vpn_policy[afi].rmap_name[dir] = XSTRDUP(
6622 MTYPE_ROUTE_MAP_NAME, rmap_str);
6623 bgp->vpn_policy[afi].rmap[dir] =
6624 route_map_lookup_by_name(rmap_str);
6625 if (!bgp->vpn_policy[afi].rmap[dir])
6626 return CMD_SUCCESS;
6627 } else {
6628 if (bgp->vpn_policy[afi].rmap_name[dir])
6629 XFREE(MTYPE_ROUTE_MAP_NAME,
6630 bgp->vpn_policy[afi].rmap_name[dir]);
6631 bgp->vpn_policy[afi].rmap_name[dir] = NULL;
6632 bgp->vpn_policy[afi].rmap[dir] = NULL;
6633 }
6634
6635 vpn_leak_postchange(dir, afi, bgp_get_default(), bgp);
6636 }
6637
6638 return CMD_SUCCESS;
6639 }
6640
6641 ALIAS (af_route_map_vpn_imexport,
6642 af_no_route_map_vpn_imexport_cmd,
6643 "no route-map vpn <import|export>$direction_str",
6644 NO_STR
6645 "Specify route map\n"
6646 "Between current address-family and vpn\n"
6647 "For routes leaked from vpn to current address-family\n"
6648 "For routes leaked from current address-family to vpn\n")
6649
6650 DEFPY(af_import_vrf_route_map, af_import_vrf_route_map_cmd,
6651 "[no] import vrf route-map RMAP$rmap_str",
6652 NO_STR
6653 "Import routes from another VRF\n"
6654 "Vrf routes being filtered\n"
6655 "Specify route map\n"
6656 "name of route-map\n")
6657 {
6658 VTY_DECLVAR_CONTEXT(bgp, bgp);
6659 vpn_policy_direction_t dir = BGP_VPN_POLICY_DIR_FROMVPN;
6660 afi_t afi;
6661 int idx = 0;
6662 int yes = 1;
6663 struct bgp *bgp_default;
6664
6665 if (argv_find(argv, argc, "no", &idx))
6666 yes = 0;
6667
6668 afi = vpn_policy_getafi(vty, bgp, true);
6669 if (afi == AFI_MAX)
6670 return CMD_WARNING_CONFIG_FAILED;
6671
6672 bgp_default = bgp_get_default();
6673 if (!bgp_default) {
6674 int32_t ret;
6675 as_t as = bgp->as;
6676
6677 /* Auto-create assuming the same AS */
6678 ret = bgp_get(&bgp_default, &as, NULL,
6679 BGP_INSTANCE_TYPE_DEFAULT);
6680
6681 if (ret) {
6682 vty_out(vty,
6683 "VRF default is not configured as a bgp instance\n");
6684 return CMD_WARNING;
6685 }
6686 }
6687
6688 vpn_leak_prechange(dir, afi, bgp_get_default(), bgp);
6689
6690 if (yes) {
6691 if (bgp->vpn_policy[afi].rmap_name[dir])
6692 XFREE(MTYPE_ROUTE_MAP_NAME,
6693 bgp->vpn_policy[afi].rmap_name[dir]);
6694 bgp->vpn_policy[afi].rmap_name[dir] =
6695 XSTRDUP(MTYPE_ROUTE_MAP_NAME, rmap_str);
6696 bgp->vpn_policy[afi].rmap[dir] =
6697 route_map_lookup_by_name(rmap_str);
6698 if (!bgp->vpn_policy[afi].rmap[dir])
6699 return CMD_SUCCESS;
6700 } else {
6701 if (bgp->vpn_policy[afi].rmap_name[dir])
6702 XFREE(MTYPE_ROUTE_MAP_NAME,
6703 bgp->vpn_policy[afi].rmap_name[dir]);
6704 bgp->vpn_policy[afi].rmap_name[dir] = NULL;
6705 bgp->vpn_policy[afi].rmap[dir] = NULL;
6706 }
6707
6708 vpn_leak_postchange(dir, afi, bgp_get_default(), bgp);
6709
6710 return CMD_SUCCESS;
6711 }
6712
6713 ALIAS(af_import_vrf_route_map, af_no_import_vrf_route_map_cmd,
6714 "no import vrf route-map",
6715 NO_STR
6716 "Import routes from another VRF\n"
6717 "Vrf routes being filtered\n"
6718 "Specify route map\n")
6719
6720 DEFPY (bgp_imexport_vrf,
6721 bgp_imexport_vrf_cmd,
6722 "[no] import vrf NAME$import_name",
6723 NO_STR
6724 "Import routes from another VRF\n"
6725 "VRF to import from\n"
6726 "The name of the VRF\n")
6727 {
6728 VTY_DECLVAR_CONTEXT(bgp, bgp);
6729 struct listnode *node;
6730 struct bgp *vrf_bgp, *bgp_default;
6731 int32_t ret = 0;
6732 as_t as = bgp->as;
6733 bool remove = false;
6734 int32_t idx = 0;
6735 char *vname;
6736 enum bgp_instance_type bgp_type = BGP_INSTANCE_TYPE_VRF;
6737 safi_t safi;
6738 afi_t afi;
6739
6740 if (argv_find(argv, argc, "no", &idx))
6741 remove = true;
6742
6743 afi = vpn_policy_getafi(vty, bgp, true);
6744 if (afi == AFI_MAX)
6745 return CMD_WARNING_CONFIG_FAILED;
6746
6747 safi = bgp_node_safi(vty);
6748
6749 if (((BGP_INSTANCE_TYPE_DEFAULT == bgp->inst_type)
6750 && (strcmp(import_name, BGP_DEFAULT_NAME) == 0))
6751 || (bgp->name && (strcmp(import_name, bgp->name) == 0))) {
6752 vty_out(vty, "%% Cannot %s vrf %s into itself\n",
6753 remove ? "unimport" : "import", import_name);
6754 return CMD_WARNING;
6755 }
6756
6757 bgp_default = bgp_get_default();
6758 if (!bgp_default) {
6759 /* Auto-create assuming the same AS */
6760 ret = bgp_get(&bgp_default, &as, NULL,
6761 BGP_INSTANCE_TYPE_DEFAULT);
6762
6763 if (ret) {
6764 vty_out(vty,
6765 "VRF default is not configured as a bgp instance\n");
6766 return CMD_WARNING;
6767 }
6768 }
6769
6770 vrf_bgp = bgp_lookup_by_name(import_name);
6771 if (!vrf_bgp) {
6772 if (strcmp(import_name, BGP_DEFAULT_NAME) == 0)
6773 vrf_bgp = bgp_default;
6774 else
6775 /* Auto-create assuming the same AS */
6776 ret = bgp_get(&vrf_bgp, &as, import_name, bgp_type);
6777
6778 if (ret) {
6779 vty_out(vty,
6780 "VRF %s is not configured as a bgp instance\n",
6781 import_name);
6782 return CMD_WARNING;
6783 }
6784 }
6785
6786 if (remove) {
6787 vrf_unimport_from_vrf(bgp, vrf_bgp, afi, safi);
6788 } else {
6789 /* Already importing from "import_vrf"? */
6790 for (ALL_LIST_ELEMENTS_RO(bgp->vpn_policy[afi].import_vrf, node,
6791 vname)) {
6792 if (strcmp(vname, import_name) == 0)
6793 return CMD_WARNING;
6794 }
6795
6796 vrf_import_from_vrf(bgp, vrf_bgp, afi, safi);
6797 }
6798
6799 return CMD_SUCCESS;
6800 }
6801
6802 /* This command is valid only in a bgp vrf instance or the default instance */
6803 DEFPY (bgp_imexport_vpn,
6804 bgp_imexport_vpn_cmd,
6805 "[no] <import|export>$direction_str vpn",
6806 NO_STR
6807 "Import routes to this address-family\n"
6808 "Export routes from this address-family\n"
6809 "to/from default instance VPN RIB\n")
6810 {
6811 VTY_DECLVAR_CONTEXT(bgp, bgp);
6812 int previous_state;
6813 afi_t afi;
6814 safi_t safi;
6815 int idx = 0;
6816 int yes = 1;
6817 int flag;
6818 vpn_policy_direction_t dir;
6819
6820 if (argv_find(argv, argc, "no", &idx))
6821 yes = 0;
6822
6823 if (BGP_INSTANCE_TYPE_VRF != bgp->inst_type &&
6824 BGP_INSTANCE_TYPE_DEFAULT != bgp->inst_type) {
6825
6826 vty_out(vty, "%% import|export vpn valid only for bgp vrf or default instance\n");
6827 return CMD_WARNING_CONFIG_FAILED;
6828 }
6829
6830 afi = bgp_node_afi(vty);
6831 safi = bgp_node_safi(vty);
6832 if ((SAFI_UNICAST != safi) || ((AFI_IP != afi) && (AFI_IP6 != afi))) {
6833 vty_out(vty, "%% import|export vpn valid only for unicast ipv4|ipv6\n");
6834 return CMD_WARNING_CONFIG_FAILED;
6835 }
6836
6837 if (!strcmp(direction_str, "import")) {
6838 flag = BGP_CONFIG_MPLSVPN_TO_VRF_IMPORT;
6839 dir = BGP_VPN_POLICY_DIR_FROMVPN;
6840 } else if (!strcmp(direction_str, "export")) {
6841 flag = BGP_CONFIG_VRF_TO_MPLSVPN_EXPORT;
6842 dir = BGP_VPN_POLICY_DIR_TOVPN;
6843 } else {
6844 vty_out(vty, "%% unknown direction %s\n", direction_str);
6845 return CMD_WARNING_CONFIG_FAILED;
6846 }
6847
6848 previous_state = CHECK_FLAG(bgp->af_flags[afi][safi], flag);
6849
6850 if (yes) {
6851 SET_FLAG(bgp->af_flags[afi][safi], flag);
6852 if (!previous_state) {
6853 /* trigger export current vrf */
6854 vpn_leak_postchange(dir, afi, bgp_get_default(), bgp);
6855 }
6856 } else {
6857 if (previous_state) {
6858 /* trigger un-export current vrf */
6859 vpn_leak_prechange(dir, afi, bgp_get_default(), bgp);
6860 }
6861 UNSET_FLAG(bgp->af_flags[afi][safi], flag);
6862 }
6863
6864 return CMD_SUCCESS;
6865 }
6866
6867 DEFPY (af_routetarget_import,
6868 af_routetarget_import_cmd,
6869 "[no] <rt|route-target> redirect import RTLIST...",
6870 NO_STR
6871 "Specify route target list\n"
6872 "Specify route target list\n"
6873 "Flow-spec redirect type route target\n"
6874 "Import routes to this address-family\n"
6875 "Space separated route target list (A.B.C.D:MN|EF:OPQR|GHJK:MN)\n")
6876 {
6877 VTY_DECLVAR_CONTEXT(bgp, bgp);
6878 int ret;
6879 struct ecommunity *ecom = NULL;
6880 afi_t afi;
6881 int idx = 0;
6882 int yes = 1;
6883
6884 if (argv_find(argv, argc, "no", &idx))
6885 yes = 0;
6886
6887 afi = vpn_policy_getafi(vty, bgp, false);
6888 if (afi == AFI_MAX)
6889 return CMD_WARNING_CONFIG_FAILED;
6890
6891 if (yes) {
6892 if (!argv_find(argv, argc, "RTLIST", &idx)) {
6893 vty_out(vty, "%% Missing RTLIST\n");
6894 return CMD_WARNING_CONFIG_FAILED;
6895 }
6896 ret = set_ecom_list(vty, argc - idx, argv + idx, &ecom);
6897 if (ret != CMD_SUCCESS)
6898 return ret;
6899 }
6900
6901 if (yes) {
6902 if (bgp->vpn_policy[afi].import_redirect_rtlist)
6903 ecommunity_free(&bgp->vpn_policy[afi]
6904 .import_redirect_rtlist);
6905 bgp->vpn_policy[afi].import_redirect_rtlist =
6906 ecommunity_dup(ecom);
6907 } else {
6908 if (bgp->vpn_policy[afi].import_redirect_rtlist)
6909 ecommunity_free(&bgp->vpn_policy[afi]
6910 .import_redirect_rtlist);
6911 bgp->vpn_policy[afi].import_redirect_rtlist = NULL;
6912 }
6913
6914 if (ecom)
6915 ecommunity_free(&ecom);
6916
6917 return CMD_SUCCESS;
6918 }
6919
6920 DEFUN_NOSH (address_family_ipv4_safi,
6921 address_family_ipv4_safi_cmd,
6922 "address-family ipv4 [<unicast|multicast|vpn|labeled-unicast|flowspec>]",
6923 "Enter Address Family command mode\n"
6924 "Address Family\n"
6925 BGP_SAFI_WITH_LABEL_HELP_STR)
6926 {
6927
6928 if (argc == 3) {
6929 VTY_DECLVAR_CONTEXT(bgp, bgp);
6930 safi_t safi = bgp_vty_safi_from_str(argv[2]->text);
6931 if (bgp->inst_type != BGP_INSTANCE_TYPE_DEFAULT
6932 && safi != SAFI_UNICAST && safi != SAFI_MULTICAST
6933 && safi != SAFI_EVPN) {
6934 vty_out(vty,
6935 "Only Unicast/Multicast/EVPN SAFIs supported in non-core instances.\n");
6936 return CMD_WARNING_CONFIG_FAILED;
6937 }
6938 vty->node = bgp_node_type(AFI_IP, safi);
6939 } else
6940 vty->node = BGP_IPV4_NODE;
6941
6942 return CMD_SUCCESS;
6943 }
6944
6945 DEFUN_NOSH (address_family_ipv6_safi,
6946 address_family_ipv6_safi_cmd,
6947 "address-family ipv6 [<unicast|multicast|vpn|labeled-unicast|flowspec>]",
6948 "Enter Address Family command mode\n"
6949 "Address Family\n"
6950 BGP_SAFI_WITH_LABEL_HELP_STR)
6951 {
6952 if (argc == 3) {
6953 VTY_DECLVAR_CONTEXT(bgp, bgp);
6954 safi_t safi = bgp_vty_safi_from_str(argv[2]->text);
6955 if (bgp->inst_type != BGP_INSTANCE_TYPE_DEFAULT
6956 && safi != SAFI_UNICAST && safi != SAFI_MULTICAST
6957 && safi != SAFI_EVPN) {
6958 vty_out(vty,
6959 "Only Unicast/Multicast/EVPN SAFIs supported in non-core instances.\n");
6960 return CMD_WARNING_CONFIG_FAILED;
6961 }
6962 vty->node = bgp_node_type(AFI_IP6, safi);
6963 } else
6964 vty->node = BGP_IPV6_NODE;
6965
6966 return CMD_SUCCESS;
6967 }
6968
6969 #ifdef KEEP_OLD_VPN_COMMANDS
6970 DEFUN_NOSH (address_family_vpnv4,
6971 address_family_vpnv4_cmd,
6972 "address-family vpnv4 [unicast]",
6973 "Enter Address Family command mode\n"
6974 "Address Family\n"
6975 "Address Family modifier\n")
6976 {
6977 vty->node = BGP_VPNV4_NODE;
6978 return CMD_SUCCESS;
6979 }
6980
6981 DEFUN_NOSH (address_family_vpnv6,
6982 address_family_vpnv6_cmd,
6983 "address-family vpnv6 [unicast]",
6984 "Enter Address Family command mode\n"
6985 "Address Family\n"
6986 "Address Family modifier\n")
6987 {
6988 vty->node = BGP_VPNV6_NODE;
6989 return CMD_SUCCESS;
6990 }
6991 #endif
6992
6993 DEFUN_NOSH (address_family_evpn,
6994 address_family_evpn_cmd,
6995 "address-family l2vpn evpn",
6996 "Enter Address Family command mode\n"
6997 "Address Family\n"
6998 "Address Family modifier\n")
6999 {
7000 VTY_DECLVAR_CONTEXT(bgp, bgp);
7001 vty->node = BGP_EVPN_NODE;
7002 return CMD_SUCCESS;
7003 }
7004
7005 DEFUN_NOSH (exit_address_family,
7006 exit_address_family_cmd,
7007 "exit-address-family",
7008 "Exit from Address Family configuration mode\n")
7009 {
7010 if (vty->node == BGP_IPV4_NODE || vty->node == BGP_IPV4M_NODE
7011 || vty->node == BGP_IPV4L_NODE || vty->node == BGP_VPNV4_NODE
7012 || vty->node == BGP_IPV6_NODE || vty->node == BGP_IPV6M_NODE
7013 || vty->node == BGP_IPV6L_NODE || vty->node == BGP_VPNV6_NODE
7014 || vty->node == BGP_EVPN_NODE
7015 || vty->node == BGP_FLOWSPECV4_NODE
7016 || vty->node == BGP_FLOWSPECV6_NODE)
7017 vty->node = BGP_NODE;
7018 return CMD_SUCCESS;
7019 }
7020
7021 /* Recalculate bestpath and re-advertise a prefix */
7022 static int bgp_clear_prefix(struct vty *vty, const char *view_name,
7023 const char *ip_str, afi_t afi, safi_t safi,
7024 struct prefix_rd *prd)
7025 {
7026 int ret;
7027 struct prefix match;
7028 struct bgp_node *rn;
7029 struct bgp_node *rm;
7030 struct bgp *bgp;
7031 struct bgp_table *table;
7032 struct bgp_table *rib;
7033
7034 /* BGP structure lookup. */
7035 if (view_name) {
7036 bgp = bgp_lookup_by_name(view_name);
7037 if (bgp == NULL) {
7038 vty_out(vty, "%% Can't find BGP instance %s\n",
7039 view_name);
7040 return CMD_WARNING;
7041 }
7042 } else {
7043 bgp = bgp_get_default();
7044 if (bgp == NULL) {
7045 vty_out(vty, "%% No BGP process is configured\n");
7046 return CMD_WARNING;
7047 }
7048 }
7049
7050 /* Check IP address argument. */
7051 ret = str2prefix(ip_str, &match);
7052 if (!ret) {
7053 vty_out(vty, "%% address is malformed\n");
7054 return CMD_WARNING;
7055 }
7056
7057 match.family = afi2family(afi);
7058 rib = bgp->rib[afi][safi];
7059
7060 if (safi == SAFI_MPLS_VPN) {
7061 for (rn = bgp_table_top(rib); rn; rn = bgp_route_next(rn)) {
7062 if (prd && memcmp(rn->p.u.val, prd->val, 8) != 0)
7063 continue;
7064
7065 if ((table = rn->info) != NULL) {
7066 if ((rm = bgp_node_match(table, &match))
7067 != NULL) {
7068 if (rm->p.prefixlen
7069 == match.prefixlen) {
7070 SET_FLAG(rn->flags,
7071 BGP_NODE_USER_CLEAR);
7072 bgp_process(bgp, rm, afi, safi);
7073 }
7074 bgp_unlock_node(rm);
7075 }
7076 }
7077 }
7078 } else {
7079 if ((rn = bgp_node_match(rib, &match)) != NULL) {
7080 if (rn->p.prefixlen == match.prefixlen) {
7081 SET_FLAG(rn->flags, BGP_NODE_USER_CLEAR);
7082 bgp_process(bgp, rn, afi, safi);
7083 }
7084 bgp_unlock_node(rn);
7085 }
7086 }
7087
7088 return CMD_SUCCESS;
7089 }
7090
7091 /* one clear bgp command to rule them all */
7092 DEFUN (clear_ip_bgp_all,
7093 clear_ip_bgp_all_cmd,
7094 "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>]",
7095 CLEAR_STR
7096 IP_STR
7097 BGP_STR
7098 BGP_INSTANCE_HELP_STR
7099 BGP_AFI_HELP_STR
7100 BGP_SAFI_WITH_LABEL_HELP_STR
7101 "Clear all peers\n"
7102 "BGP neighbor address to clear\n"
7103 "BGP IPv6 neighbor to clear\n"
7104 "BGP neighbor on interface to clear\n"
7105 "Clear peers with the AS number\n"
7106 "Clear all external peers\n"
7107 "Clear all members of peer-group\n"
7108 "BGP peer-group name\n"
7109 BGP_SOFT_STR
7110 BGP_SOFT_IN_STR
7111 BGP_SOFT_OUT_STR
7112 BGP_SOFT_IN_STR
7113 "Push out prefix-list ORF and do inbound soft reconfig\n"
7114 BGP_SOFT_OUT_STR)
7115 {
7116 char *vrf = NULL;
7117
7118 afi_t afi = AFI_IP6;
7119 safi_t safi = SAFI_UNICAST;
7120 enum clear_sort clr_sort = clear_peer;
7121 enum bgp_clear_type clr_type;
7122 char *clr_arg = NULL;
7123
7124 int idx = 0;
7125
7126 /* clear [ip] bgp */
7127 if (argv_find(argv, argc, "ip", &idx))
7128 afi = AFI_IP;
7129
7130 /* [<view|vrf> VIEWVRFNAME] */
7131 if (argv_find(argv, argc, "view", &idx)
7132 || argv_find(argv, argc, "vrf", &idx)) {
7133 vrf = argv[idx + 1]->arg;
7134 idx += 2;
7135 }
7136
7137 /* ["BGP_AFI_CMD_STR" ["BGP_SAFI_CMD_STR"]] */
7138 if (argv_find_and_parse_afi(argv, argc, &idx, &afi))
7139 argv_find_and_parse_safi(argv, argc, &idx, &safi);
7140
7141 /* <*|A.B.C.D|X:X::X:X|WORD|(1-4294967295)|external|peer-group WORD> */
7142 if (argv_find(argv, argc, "*", &idx)) {
7143 clr_sort = clear_all;
7144 } else if (argv_find(argv, argc, "A.B.C.D", &idx)) {
7145 clr_sort = clear_peer;
7146 clr_arg = argv[idx]->arg;
7147 } else if (argv_find(argv, argc, "X:X::X:X", &idx)) {
7148 clr_sort = clear_peer;
7149 clr_arg = argv[idx]->arg;
7150 } else if (argv_find(argv, argc, "peer-group", &idx)) {
7151 clr_sort = clear_group;
7152 idx++;
7153 clr_arg = argv[idx]->arg;
7154 } else if (argv_find(argv, argc, "WORD", &idx)) {
7155 clr_sort = clear_peer;
7156 clr_arg = argv[idx]->arg;
7157 } else if (argv_find(argv, argc, "(1-4294967295)", &idx)) {
7158 clr_sort = clear_as;
7159 clr_arg = argv[idx]->arg;
7160 } else if (argv_find(argv, argc, "external", &idx)) {
7161 clr_sort = clear_external;
7162 }
7163
7164 /* [<soft [<in|out>]|in [prefix-filter]|out>] */
7165 if (argv_find(argv, argc, "soft", &idx)) {
7166 if (argv_find(argv, argc, "in", &idx)
7167 || argv_find(argv, argc, "out", &idx))
7168 clr_type = strmatch(argv[idx]->text, "in")
7169 ? BGP_CLEAR_SOFT_IN
7170 : BGP_CLEAR_SOFT_OUT;
7171 else
7172 clr_type = BGP_CLEAR_SOFT_BOTH;
7173 } else if (argv_find(argv, argc, "in", &idx)) {
7174 clr_type = argv_find(argv, argc, "prefix-filter", &idx)
7175 ? BGP_CLEAR_SOFT_IN_ORF_PREFIX
7176 : BGP_CLEAR_SOFT_IN;
7177 } else if (argv_find(argv, argc, "out", &idx)) {
7178 clr_type = BGP_CLEAR_SOFT_OUT;
7179 } else
7180 clr_type = BGP_CLEAR_SOFT_NONE;
7181
7182 return bgp_clear_vty(vty, vrf, afi, safi, clr_sort, clr_type, clr_arg);
7183 }
7184
7185 DEFUN (clear_ip_bgp_prefix,
7186 clear_ip_bgp_prefix_cmd,
7187 "clear [ip] bgp [<view|vrf> VIEWVRFNAME] prefix A.B.C.D/M",
7188 CLEAR_STR
7189 IP_STR
7190 BGP_STR
7191 BGP_INSTANCE_HELP_STR
7192 "Clear bestpath and re-advertise\n"
7193 "IPv4 prefix\n")
7194 {
7195 char *vrf = NULL;
7196 char *prefix = NULL;
7197
7198 int idx = 0;
7199
7200 /* [<view|vrf> VIEWVRFNAME] */
7201 if (argv_find(argv, argc, "VIEWVRFNAME", &idx))
7202 vrf = argv[idx]->arg;
7203
7204 prefix = argv[argc - 1]->arg;
7205
7206 return bgp_clear_prefix(vty, vrf, prefix, AFI_IP, SAFI_UNICAST, NULL);
7207 }
7208
7209 DEFUN (clear_bgp_ipv6_safi_prefix,
7210 clear_bgp_ipv6_safi_prefix_cmd,
7211 "clear [ip] bgp ipv6 "BGP_SAFI_CMD_STR" prefix X:X::X:X/M",
7212 CLEAR_STR
7213 IP_STR
7214 BGP_STR
7215 "Address Family\n"
7216 BGP_SAFI_HELP_STR
7217 "Clear bestpath and re-advertise\n"
7218 "IPv6 prefix\n")
7219 {
7220 int idx_safi = 0;
7221 int idx_ipv6_prefix = 0;
7222 safi_t safi = SAFI_UNICAST;
7223 char *prefix = argv_find(argv, argc, "X:X::X:X/M", &idx_ipv6_prefix) ?
7224 argv[idx_ipv6_prefix]->arg : NULL;
7225
7226 argv_find_and_parse_safi(argv, argc, &idx_safi, &safi);
7227 return bgp_clear_prefix(
7228 vty, NULL, prefix, AFI_IP6,
7229 safi, NULL);
7230 }
7231
7232 DEFUN (clear_bgp_instance_ipv6_safi_prefix,
7233 clear_bgp_instance_ipv6_safi_prefix_cmd,
7234 "clear [ip] bgp <view|vrf> VIEWVRFNAME ipv6 "BGP_SAFI_CMD_STR" prefix X:X::X:X/M",
7235 CLEAR_STR
7236 IP_STR
7237 BGP_STR
7238 BGP_INSTANCE_HELP_STR
7239 "Address Family\n"
7240 BGP_SAFI_HELP_STR
7241 "Clear bestpath and re-advertise\n"
7242 "IPv6 prefix\n")
7243 {
7244 int idx_word = 3;
7245 int idx_safi = 0;
7246 int idx_ipv6_prefix = 0;
7247 safi_t safi = SAFI_UNICAST;
7248 char *prefix = argv_find(argv, argc, "X:X::X:X/M", &idx_ipv6_prefix) ?
7249 argv[idx_ipv6_prefix]->arg : NULL;
7250 /* [<view|vrf> VIEWVRFNAME] */
7251 char *vrfview = argv_find(argv, argc, "VIEWVRFNAME", &idx_word) ?
7252 argv[idx_word]->arg : NULL;
7253
7254 argv_find_and_parse_safi(argv, argc, &idx_safi, &safi);
7255
7256 return bgp_clear_prefix(
7257 vty, vrfview, prefix,
7258 AFI_IP6, safi, NULL);
7259 }
7260
7261 DEFUN (show_bgp_views,
7262 show_bgp_views_cmd,
7263 "show [ip] bgp views",
7264 SHOW_STR
7265 IP_STR
7266 BGP_STR
7267 "Show the defined BGP views\n")
7268 {
7269 struct list *inst = bm->bgp;
7270 struct listnode *node;
7271 struct bgp *bgp;
7272
7273 if (!bgp_option_check(BGP_OPT_MULTIPLE_INSTANCE)) {
7274 vty_out(vty, "BGP Multiple Instance is not enabled\n");
7275 return CMD_WARNING;
7276 }
7277
7278 vty_out(vty, "Defined BGP views:\n");
7279 for (ALL_LIST_ELEMENTS_RO(inst, node, bgp)) {
7280 /* Skip VRFs. */
7281 if (bgp->inst_type == BGP_INSTANCE_TYPE_VRF)
7282 continue;
7283 vty_out(vty, "\t%s (AS%u)\n", bgp->name ? bgp->name : "(null)",
7284 bgp->as);
7285 }
7286
7287 return CMD_SUCCESS;
7288 }
7289
7290 DEFUN (show_bgp_vrfs,
7291 show_bgp_vrfs_cmd,
7292 "show [ip] bgp vrfs [json]",
7293 SHOW_STR
7294 IP_STR
7295 BGP_STR
7296 "Show BGP VRFs\n"
7297 JSON_STR)
7298 {
7299 char buf[ETHER_ADDR_STRLEN];
7300 struct list *inst = bm->bgp;
7301 struct listnode *node;
7302 struct bgp *bgp;
7303 uint8_t uj = use_json(argc, argv);
7304 json_object *json = NULL;
7305 json_object *json_vrfs = NULL;
7306 int count = 0;
7307
7308 if (!bgp_option_check(BGP_OPT_MULTIPLE_INSTANCE)) {
7309 vty_out(vty, "BGP Multiple Instance is not enabled\n");
7310 return CMD_WARNING;
7311 }
7312
7313 if (uj) {
7314 json = json_object_new_object();
7315 json_vrfs = json_object_new_object();
7316 }
7317
7318 for (ALL_LIST_ELEMENTS_RO(inst, node, bgp)) {
7319 const char *name, *type;
7320 struct peer *peer;
7321 struct listnode *node, *nnode;
7322 int peers_cfg, peers_estb;
7323 json_object *json_vrf = NULL;
7324
7325 /* Skip Views. */
7326 if (bgp->inst_type == BGP_INSTANCE_TYPE_VIEW)
7327 continue;
7328
7329 count++;
7330 if (!uj && count == 1)
7331 vty_out(vty,
7332 "%4s %-5s %-16s %9s %10s %-37s %-10s %-15s\n",
7333 "Type", "Id", "routerId", "#PeersVfg",
7334 "#PeersEstb", "Name", "L3-VNI", "Rmac");
7335
7336 peers_cfg = peers_estb = 0;
7337 if (uj)
7338 json_vrf = json_object_new_object();
7339
7340
7341 for (ALL_LIST_ELEMENTS(bgp->peer, node, nnode, peer)) {
7342 if (!CHECK_FLAG(peer->flags, PEER_FLAG_CONFIG_NODE))
7343 continue;
7344 peers_cfg++;
7345 if (peer->status == Established)
7346 peers_estb++;
7347 }
7348
7349 if (bgp->inst_type == BGP_INSTANCE_TYPE_DEFAULT) {
7350 name = "Default";
7351 type = "DFLT";
7352 } else {
7353 name = bgp->name;
7354 type = "VRF";
7355 }
7356
7357
7358 if (uj) {
7359 int64_t vrf_id_ui = (bgp->vrf_id == VRF_UNKNOWN)
7360 ? -1
7361 : (int64_t)bgp->vrf_id;
7362 json_object_string_add(json_vrf, "type", type);
7363 json_object_int_add(json_vrf, "vrfId", vrf_id_ui);
7364 json_object_string_add(json_vrf, "routerId",
7365 inet_ntoa(bgp->router_id));
7366 json_object_int_add(json_vrf, "numConfiguredPeers",
7367 peers_cfg);
7368 json_object_int_add(json_vrf, "numEstablishedPeers",
7369 peers_estb);
7370
7371 json_object_int_add(json_vrf, "l3vni", bgp->l3vni);
7372 json_object_string_add(
7373 json_vrf, "rmac",
7374 prefix_mac2str(&bgp->rmac, buf, sizeof(buf)));
7375 json_object_object_add(json_vrfs, name, json_vrf);
7376 } else
7377 vty_out(vty,
7378 "%4s %-5d %-16s %9u %10u %-37s %-10u %-15s\n",
7379 type,
7380 bgp->vrf_id == VRF_UNKNOWN ? -1
7381 : (int)bgp->vrf_id,
7382 inet_ntoa(bgp->router_id), peers_cfg,
7383 peers_estb, name, bgp->l3vni,
7384 prefix_mac2str(&bgp->rmac, buf, sizeof(buf)));
7385 }
7386
7387 if (uj) {
7388 json_object_object_add(json, "vrfs", json_vrfs);
7389
7390 json_object_int_add(json, "totalVrfs", count);
7391
7392 vty_out(vty, "%s\n", json_object_to_json_string_ext(
7393 json, JSON_C_TO_STRING_PRETTY));
7394 json_object_free(json);
7395 } else {
7396 if (count)
7397 vty_out(vty,
7398 "\nTotal number of VRFs (including default): %d\n",
7399 count);
7400 }
7401
7402 return CMD_SUCCESS;
7403 }
7404
7405 static void show_address_entry(struct hash_backet *backet, void *args)
7406 {
7407 struct vty *vty = (struct vty *)args;
7408 struct bgp_addr *addr = (struct bgp_addr *)backet->data;
7409
7410 vty_out(vty, "addr: %s, count: %d\n", inet_ntoa(addr->addr),
7411 addr->refcnt);
7412 }
7413
7414 static void show_tip_entry(struct hash_backet *backet, void *args)
7415 {
7416 struct vty *vty = (struct vty *)args;
7417 struct tip_addr *tip = (struct tip_addr *)backet->data;
7418
7419 vty_out(vty, "addr: %s, count: %d\n", inet_ntoa(tip->addr),
7420 tip->refcnt);
7421 }
7422
7423 static void bgp_show_martian_nexthops(struct vty *vty, struct bgp *bgp)
7424 {
7425 vty_out(vty, "self nexthop database:\n");
7426 hash_iterate(bgp->address_hash,
7427 (void (*)(struct hash_backet *, void *))show_address_entry,
7428 vty);
7429
7430 vty_out(vty, "Tunnel-ip database:\n");
7431 hash_iterate(bgp->tip_hash,
7432 (void (*)(struct hash_backet *, void *))show_tip_entry,
7433 vty);
7434 }
7435
7436 DEFUN(show_bgp_martian_nexthop_db, show_bgp_martian_nexthop_db_cmd,
7437 "show bgp [<view|vrf> VIEWVRFNAME] martian next-hop",
7438 SHOW_STR BGP_STR BGP_INSTANCE_HELP_STR
7439 "martian next-hops\n"
7440 "martian next-hop database\n")
7441 {
7442 struct bgp *bgp = NULL;
7443 int idx = 0;
7444
7445 if (argv_find(argv, argc, "view", &idx)
7446 || argv_find(argv, argc, "vrf", &idx))
7447 bgp = bgp_lookup_by_name(argv[idx + 1]->arg);
7448 else
7449 bgp = bgp_get_default();
7450
7451 if (!bgp) {
7452 vty_out(vty, "%% No BGP process is configured\n");
7453 return CMD_WARNING;
7454 }
7455 bgp_show_martian_nexthops(vty, bgp);
7456
7457 return CMD_SUCCESS;
7458 }
7459
7460 DEFUN (show_bgp_memory,
7461 show_bgp_memory_cmd,
7462 "show [ip] bgp memory",
7463 SHOW_STR
7464 IP_STR
7465 BGP_STR
7466 "Global BGP memory statistics\n")
7467 {
7468 char memstrbuf[MTYPE_MEMSTR_LEN];
7469 unsigned long count;
7470
7471 /* RIB related usage stats */
7472 count = mtype_stats_alloc(MTYPE_BGP_NODE);
7473 vty_out(vty, "%ld RIB nodes, using %s of memory\n", count,
7474 mtype_memstr(memstrbuf, sizeof(memstrbuf),
7475 count * sizeof(struct bgp_node)));
7476
7477 count = mtype_stats_alloc(MTYPE_BGP_ROUTE);
7478 vty_out(vty, "%ld BGP routes, using %s of memory\n", count,
7479 mtype_memstr(memstrbuf, sizeof(memstrbuf),
7480 count * sizeof(struct bgp_info)));
7481 if ((count = mtype_stats_alloc(MTYPE_BGP_ROUTE_EXTRA)))
7482 vty_out(vty, "%ld BGP route ancillaries, using %s of memory\n",
7483 count,
7484 mtype_memstr(memstrbuf, sizeof(memstrbuf),
7485 count * sizeof(struct bgp_info_extra)));
7486
7487 if ((count = mtype_stats_alloc(MTYPE_BGP_STATIC)))
7488 vty_out(vty, "%ld Static routes, using %s of memory\n", count,
7489 mtype_memstr(memstrbuf, sizeof(memstrbuf),
7490 count * sizeof(struct bgp_static)));
7491
7492 if ((count = mtype_stats_alloc(MTYPE_BGP_PACKET)))
7493 vty_out(vty, "%ld Packets, using %s of memory\n", count,
7494 mtype_memstr(memstrbuf, sizeof(memstrbuf),
7495 count * sizeof(struct bpacket)));
7496
7497 /* Adj-In/Out */
7498 if ((count = mtype_stats_alloc(MTYPE_BGP_ADJ_IN)))
7499 vty_out(vty, "%ld Adj-In entries, using %s of memory\n", count,
7500 mtype_memstr(memstrbuf, sizeof(memstrbuf),
7501 count * sizeof(struct bgp_adj_in)));
7502 if ((count = mtype_stats_alloc(MTYPE_BGP_ADJ_OUT)))
7503 vty_out(vty, "%ld Adj-Out entries, using %s of memory\n", count,
7504 mtype_memstr(memstrbuf, sizeof(memstrbuf),
7505 count * sizeof(struct bgp_adj_out)));
7506
7507 if ((count = mtype_stats_alloc(MTYPE_BGP_NEXTHOP_CACHE)))
7508 vty_out(vty, "%ld Nexthop cache entries, using %s of memory\n",
7509 count,
7510 mtype_memstr(memstrbuf, sizeof(memstrbuf),
7511 count * sizeof(struct bgp_nexthop_cache)));
7512
7513 if ((count = mtype_stats_alloc(MTYPE_BGP_DAMP_INFO)))
7514 vty_out(vty, "%ld Dampening entries, using %s of memory\n",
7515 count,
7516 mtype_memstr(memstrbuf, sizeof(memstrbuf),
7517 count * sizeof(struct bgp_damp_info)));
7518
7519 /* Attributes */
7520 count = attr_count();
7521 vty_out(vty, "%ld BGP attributes, using %s of memory\n", count,
7522 mtype_memstr(memstrbuf, sizeof(memstrbuf),
7523 count * sizeof(struct attr)));
7524
7525 if ((count = attr_unknown_count()))
7526 vty_out(vty, "%ld unknown attributes\n", count);
7527
7528 /* AS_PATH attributes */
7529 count = aspath_count();
7530 vty_out(vty, "%ld BGP AS-PATH entries, using %s of memory\n", count,
7531 mtype_memstr(memstrbuf, sizeof(memstrbuf),
7532 count * sizeof(struct aspath)));
7533
7534 count = mtype_stats_alloc(MTYPE_AS_SEG);
7535 vty_out(vty, "%ld BGP AS-PATH segments, using %s of memory\n", count,
7536 mtype_memstr(memstrbuf, sizeof(memstrbuf),
7537 count * sizeof(struct assegment)));
7538
7539 /* Other attributes */
7540 if ((count = community_count()))
7541 vty_out(vty, "%ld BGP community entries, using %s of memory\n",
7542 count, mtype_memstr(memstrbuf, sizeof(memstrbuf),
7543 count * sizeof(struct community)));
7544 if ((count = mtype_stats_alloc(MTYPE_ECOMMUNITY)))
7545 vty_out(vty, "%ld BGP community entries, using %s of memory\n",
7546 count, mtype_memstr(memstrbuf, sizeof(memstrbuf),
7547 count * sizeof(struct ecommunity)));
7548 if ((count = mtype_stats_alloc(MTYPE_LCOMMUNITY)))
7549 vty_out(vty,
7550 "%ld BGP large-community entries, using %s of memory\n",
7551 count, mtype_memstr(memstrbuf, sizeof(memstrbuf),
7552 count * sizeof(struct lcommunity)));
7553
7554 if ((count = mtype_stats_alloc(MTYPE_CLUSTER)))
7555 vty_out(vty, "%ld Cluster lists, using %s of memory\n", count,
7556 mtype_memstr(memstrbuf, sizeof(memstrbuf),
7557 count * sizeof(struct cluster_list)));
7558
7559 /* Peer related usage */
7560 count = mtype_stats_alloc(MTYPE_BGP_PEER);
7561 vty_out(vty, "%ld peers, using %s of memory\n", count,
7562 mtype_memstr(memstrbuf, sizeof(memstrbuf),
7563 count * sizeof(struct peer)));
7564
7565 if ((count = mtype_stats_alloc(MTYPE_PEER_GROUP)))
7566 vty_out(vty, "%ld peer groups, using %s of memory\n", count,
7567 mtype_memstr(memstrbuf, sizeof(memstrbuf),
7568 count * sizeof(struct peer_group)));
7569
7570 /* Other */
7571 if ((count = mtype_stats_alloc(MTYPE_HASH)))
7572 vty_out(vty, "%ld hash tables, using %s of memory\n", count,
7573 mtype_memstr(memstrbuf, sizeof(memstrbuf),
7574 count * sizeof(struct hash)));
7575 if ((count = mtype_stats_alloc(MTYPE_HASH_BACKET)))
7576 vty_out(vty, "%ld hash buckets, using %s of memory\n", count,
7577 mtype_memstr(memstrbuf, sizeof(memstrbuf),
7578 count * sizeof(struct hash_backet)));
7579 if ((count = mtype_stats_alloc(MTYPE_BGP_REGEXP)))
7580 vty_out(vty, "%ld compiled regexes, using %s of memory\n",
7581 count, mtype_memstr(memstrbuf, sizeof(memstrbuf),
7582 count * sizeof(regex_t)));
7583 return CMD_SUCCESS;
7584 }
7585
7586 static void bgp_show_bestpath_json(struct bgp *bgp, json_object *json)
7587 {
7588 json_object *bestpath = json_object_new_object();
7589
7590 if (bgp_flag_check(bgp, BGP_FLAG_ASPATH_IGNORE))
7591 json_object_string_add(bestpath, "asPath", "ignore");
7592
7593 if (bgp_flag_check(bgp, BGP_FLAG_ASPATH_CONFED))
7594 json_object_string_add(bestpath, "asPath", "confed");
7595
7596 if (bgp_flag_check(bgp, BGP_FLAG_ASPATH_MULTIPATH_RELAX)) {
7597 if (bgp_flag_check(bgp, BGP_FLAG_MULTIPATH_RELAX_AS_SET))
7598 json_object_string_add(bestpath, "multiPathRelax",
7599 "as-set");
7600 else
7601 json_object_string_add(bestpath, "multiPathRelax",
7602 "true");
7603 } else
7604 json_object_string_add(bestpath, "multiPathRelax", "false");
7605
7606 if (bgp_flag_check(bgp, BGP_FLAG_COMPARE_ROUTER_ID))
7607 json_object_string_add(bestpath, "compareRouterId", "true");
7608 if (bgp_flag_check(bgp, BGP_FLAG_MED_CONFED)
7609 || bgp_flag_check(bgp, BGP_FLAG_MED_MISSING_AS_WORST)) {
7610 if (bgp_flag_check(bgp, BGP_FLAG_MED_CONFED))
7611 json_object_string_add(bestpath, "med", "confed");
7612 if (bgp_flag_check(bgp, BGP_FLAG_MED_MISSING_AS_WORST))
7613 json_object_string_add(bestpath, "med",
7614 "missing-as-worst");
7615 else
7616 json_object_string_add(bestpath, "med", "true");
7617 }
7618
7619 json_object_object_add(json, "bestPath", bestpath);
7620 }
7621
7622 /* Show BGP peer's summary information. */
7623 static int bgp_show_summary(struct vty *vty, struct bgp *bgp, int afi, int safi,
7624 uint8_t use_json, json_object *json)
7625 {
7626 struct peer *peer;
7627 struct listnode *node, *nnode;
7628 unsigned int count = 0, dn_count = 0;
7629 char timebuf[BGP_UPTIME_LEN], dn_flag[2];
7630 char neighbor_buf[VTY_BUFSIZ];
7631 int neighbor_col_default_width = 16;
7632 int len;
7633 int max_neighbor_width = 0;
7634 int pfx_rcd_safi;
7635 json_object *json_peer = NULL;
7636 json_object *json_peers = NULL;
7637
7638 /* labeled-unicast routes are installed in the unicast table so in order
7639 * to
7640 * display the correct PfxRcd value we must look at SAFI_UNICAST
7641 */
7642 if (safi == SAFI_LABELED_UNICAST)
7643 pfx_rcd_safi = SAFI_UNICAST;
7644 else
7645 pfx_rcd_safi = safi;
7646
7647 if (use_json) {
7648 if (json == NULL)
7649 json = json_object_new_object();
7650
7651 json_peers = json_object_new_object();
7652 } else {
7653 /* Loop over all neighbors that will be displayed to determine
7654 * how many
7655 * characters are needed for the Neighbor column
7656 */
7657 for (ALL_LIST_ELEMENTS(bgp->peer, node, nnode, peer)) {
7658 if (!CHECK_FLAG(peer->flags, PEER_FLAG_CONFIG_NODE))
7659 continue;
7660
7661 if (peer->afc[afi][safi]) {
7662 memset(dn_flag, '\0', sizeof(dn_flag));
7663 if (peer_dynamic_neighbor(peer))
7664 dn_flag[0] = '*';
7665
7666 if (peer->hostname
7667 && bgp_flag_check(bgp,
7668 BGP_FLAG_SHOW_HOSTNAME))
7669 sprintf(neighbor_buf, "%s%s(%s) ",
7670 dn_flag, peer->hostname,
7671 peer->host);
7672 else
7673 sprintf(neighbor_buf, "%s%s ", dn_flag,
7674 peer->host);
7675
7676 len = strlen(neighbor_buf);
7677
7678 if (len > max_neighbor_width)
7679 max_neighbor_width = len;
7680 }
7681 }
7682
7683 /* Originally we displayed the Neighbor column as 16
7684 * characters wide so make that the default
7685 */
7686 if (max_neighbor_width < neighbor_col_default_width)
7687 max_neighbor_width = neighbor_col_default_width;
7688 }
7689
7690 for (ALL_LIST_ELEMENTS(bgp->peer, node, nnode, peer)) {
7691 if (!CHECK_FLAG(peer->flags, PEER_FLAG_CONFIG_NODE))
7692 continue;
7693
7694 if (!peer->afc[afi][safi])
7695 continue;
7696
7697 if (!count) {
7698 unsigned long ents;
7699 char memstrbuf[MTYPE_MEMSTR_LEN];
7700 int64_t vrf_id_ui;
7701
7702 vrf_id_ui = (bgp->vrf_id == VRF_UNKNOWN)
7703 ? -1
7704 : (int64_t)bgp->vrf_id;
7705
7706 /* Usage summary and header */
7707 if (use_json) {
7708 json_object_string_add(
7709 json, "routerId",
7710 inet_ntoa(bgp->router_id));
7711 json_object_int_add(json, "as", bgp->as);
7712 json_object_int_add(json, "vrfId", vrf_id_ui);
7713 json_object_string_add(
7714 json, "vrfName",
7715 (bgp->inst_type
7716 == BGP_INSTANCE_TYPE_DEFAULT)
7717 ? "Default"
7718 : bgp->name);
7719 } else {
7720 vty_out(vty,
7721 "BGP router identifier %s, local AS number %u vrf-id %d",
7722 inet_ntoa(bgp->router_id), bgp->as,
7723 bgp->vrf_id == VRF_UNKNOWN
7724 ? -1
7725 : (int)bgp->vrf_id);
7726 vty_out(vty, "\n");
7727 }
7728
7729 if (bgp_update_delay_configured(bgp)) {
7730 if (use_json) {
7731 json_object_int_add(
7732 json, "updateDelayLimit",
7733 bgp->v_update_delay);
7734
7735 if (bgp->v_update_delay
7736 != bgp->v_establish_wait)
7737 json_object_int_add(
7738 json,
7739 "updateDelayEstablishWait",
7740 bgp->v_establish_wait);
7741
7742 if (bgp_update_delay_active(bgp)) {
7743 json_object_string_add(
7744 json,
7745 "updateDelayFirstNeighbor",
7746 bgp->update_delay_begin_time);
7747 json_object_boolean_true_add(
7748 json,
7749 "updateDelayInProgress");
7750 } else {
7751 if (bgp->update_delay_over) {
7752 json_object_string_add(
7753 json,
7754 "updateDelayFirstNeighbor",
7755 bgp->update_delay_begin_time);
7756 json_object_string_add(
7757 json,
7758 "updateDelayBestpathResumed",
7759 bgp->update_delay_end_time);
7760 json_object_string_add(
7761 json,
7762 "updateDelayZebraUpdateResume",
7763 bgp->update_delay_zebra_resume_time);
7764 json_object_string_add(
7765 json,
7766 "updateDelayPeerUpdateResume",
7767 bgp->update_delay_peers_resume_time);
7768 }
7769 }
7770 } else {
7771 vty_out(vty,
7772 "Read-only mode update-delay limit: %d seconds\n",
7773 bgp->v_update_delay);
7774 if (bgp->v_update_delay
7775 != bgp->v_establish_wait)
7776 vty_out(vty,
7777 " Establish wait: %d seconds\n",
7778 bgp->v_establish_wait);
7779
7780 if (bgp_update_delay_active(bgp)) {
7781 vty_out(vty,
7782 " First neighbor established: %s\n",
7783 bgp->update_delay_begin_time);
7784 vty_out(vty,
7785 " Delay in progress\n");
7786 } else {
7787 if (bgp->update_delay_over) {
7788 vty_out(vty,
7789 " First neighbor established: %s\n",
7790 bgp->update_delay_begin_time);
7791 vty_out(vty,
7792 " Best-paths resumed: %s\n",
7793 bgp->update_delay_end_time);
7794 vty_out(vty,
7795 " zebra update resumed: %s\n",
7796 bgp->update_delay_zebra_resume_time);
7797 vty_out(vty,
7798 " peers update resumed: %s\n",
7799 bgp->update_delay_peers_resume_time);
7800 }
7801 }
7802 }
7803 }
7804
7805 if (use_json) {
7806 if (bgp_maxmed_onstartup_configured(bgp)
7807 && bgp->maxmed_active)
7808 json_object_boolean_true_add(
7809 json, "maxMedOnStartup");
7810 if (bgp->v_maxmed_admin)
7811 json_object_boolean_true_add(
7812 json, "maxMedAdministrative");
7813
7814 json_object_int_add(
7815 json, "tableVersion",
7816 bgp_table_version(bgp->rib[afi][safi]));
7817
7818 ents = bgp_table_count(bgp->rib[afi][safi]);
7819 json_object_int_add(json, "ribCount", ents);
7820 json_object_int_add(
7821 json, "ribMemory",
7822 ents * sizeof(struct bgp_node));
7823
7824 ents = listcount(bgp->peer);
7825 json_object_int_add(json, "peerCount", ents);
7826 json_object_int_add(json, "peerMemory",
7827 ents * sizeof(struct peer));
7828
7829 if ((ents = listcount(bgp->group))) {
7830 json_object_int_add(
7831 json, "peerGroupCount", ents);
7832 json_object_int_add(
7833 json, "peerGroupMemory",
7834 ents * sizeof(struct
7835 peer_group));
7836 }
7837
7838 if (CHECK_FLAG(bgp->af_flags[afi][safi],
7839 BGP_CONFIG_DAMPENING))
7840 json_object_boolean_true_add(
7841 json, "dampeningEnabled");
7842 } else {
7843 if (bgp_maxmed_onstartup_configured(bgp)
7844 && bgp->maxmed_active)
7845 vty_out(vty,
7846 "Max-med on-startup active\n");
7847 if (bgp->v_maxmed_admin)
7848 vty_out(vty,
7849 "Max-med administrative active\n");
7850
7851 vty_out(vty, "BGP table version %" PRIu64 "\n",
7852 bgp_table_version(bgp->rib[afi][safi]));
7853
7854 ents = bgp_table_count(bgp->rib[afi][safi]);
7855 vty_out(vty,
7856 "RIB entries %ld, using %s of memory\n",
7857 ents,
7858 mtype_memstr(memstrbuf,
7859 sizeof(memstrbuf),
7860 ents * sizeof(struct
7861 bgp_node)));
7862
7863 /* Peer related usage */
7864 ents = listcount(bgp->peer);
7865 vty_out(vty, "Peers %ld, using %s of memory\n",
7866 ents,
7867 mtype_memstr(
7868 memstrbuf, sizeof(memstrbuf),
7869 ents * sizeof(struct peer)));
7870
7871 if ((ents = listcount(bgp->group)))
7872 vty_out(vty,
7873 "Peer groups %ld, using %s of memory\n",
7874 ents,
7875 mtype_memstr(
7876 memstrbuf,
7877 sizeof(memstrbuf),
7878 ents * sizeof(struct
7879 peer_group)));
7880
7881 if (CHECK_FLAG(bgp->af_flags[afi][safi],
7882 BGP_CONFIG_DAMPENING))
7883 vty_out(vty, "Dampening enabled.\n");
7884 vty_out(vty, "\n");
7885
7886 /* Subtract 8 here because 'Neighbor' is
7887 * 8 characters */
7888 vty_out(vty, "Neighbor");
7889 vty_out(vty, "%*s", max_neighbor_width - 8,
7890 " ");
7891 vty_out(vty,
7892 "V AS MsgRcvd MsgSent TblVer InQ OutQ Up/Down State/PfxRcd\n");
7893 }
7894 }
7895
7896 count++;
7897
7898 if (use_json) {
7899 json_peer = json_object_new_object();
7900
7901 if (peer_dynamic_neighbor(peer))
7902 json_object_boolean_true_add(json_peer,
7903 "dynamicPeer");
7904
7905 if (peer->hostname)
7906 json_object_string_add(json_peer, "hostname",
7907 peer->hostname);
7908
7909 if (peer->domainname)
7910 json_object_string_add(json_peer, "domainname",
7911 peer->domainname);
7912
7913 json_object_int_add(json_peer, "remoteAs", peer->as);
7914 json_object_int_add(json_peer, "version", 4);
7915 json_object_int_add(json_peer, "msgRcvd",
7916 PEER_TOTAL_RX(peer));
7917 json_object_int_add(json_peer, "msgSent",
7918 PEER_TOTAL_TX(peer));
7919
7920 json_object_int_add(json_peer, "tableVersion",
7921 peer->version[afi][safi]);
7922 json_object_int_add(json_peer, "outq",
7923 peer->obuf->count);
7924 json_object_int_add(json_peer, "inq", 0);
7925 peer_uptime(peer->uptime, timebuf, BGP_UPTIME_LEN,
7926 use_json, json_peer);
7927 json_object_int_add(json_peer, "prefixReceivedCount",
7928 peer->pcount[afi][pfx_rcd_safi]);
7929
7930 if (CHECK_FLAG(peer->flags, PEER_FLAG_SHUTDOWN))
7931 json_object_string_add(json_peer, "state",
7932 "Idle (Admin)");
7933 else if (CHECK_FLAG(peer->sflags,
7934 PEER_STATUS_PREFIX_OVERFLOW))
7935 json_object_string_add(json_peer, "state",
7936 "Idle (PfxCt)");
7937 else
7938 json_object_string_add(
7939 json_peer, "state",
7940 lookup_msg(bgp_status_msg, peer->status,
7941 NULL));
7942
7943 if (peer->conf_if)
7944 json_object_string_add(json_peer, "idType",
7945 "interface");
7946 else if (peer->su.sa.sa_family == AF_INET)
7947 json_object_string_add(json_peer, "idType",
7948 "ipv4");
7949 else if (peer->su.sa.sa_family == AF_INET6)
7950 json_object_string_add(json_peer, "idType",
7951 "ipv6");
7952
7953 json_object_object_add(json_peers, peer->host,
7954 json_peer);
7955 } else {
7956 memset(dn_flag, '\0', sizeof(dn_flag));
7957 if (peer_dynamic_neighbor(peer)) {
7958 dn_count++;
7959 dn_flag[0] = '*';
7960 }
7961
7962 if (peer->hostname
7963 && bgp_flag_check(bgp, BGP_FLAG_SHOW_HOSTNAME))
7964 len = vty_out(vty, "%s%s(%s)", dn_flag,
7965 peer->hostname, peer->host);
7966 else
7967 len = vty_out(vty, "%s%s", dn_flag, peer->host);
7968
7969 /* pad the neighbor column with spaces */
7970 if (len < max_neighbor_width)
7971 vty_out(vty, "%*s", max_neighbor_width - len,
7972 " ");
7973
7974 vty_out(vty, "4 %10u %7u %7u %8" PRIu64 " %4d %4zd %8s",
7975 peer->as, PEER_TOTAL_RX(peer),
7976 PEER_TOTAL_TX(peer), peer->version[afi][safi],
7977 0, peer->obuf->count,
7978 peer_uptime(peer->uptime, timebuf,
7979 BGP_UPTIME_LEN, 0, NULL));
7980
7981 if (peer->status == Established)
7982 if (peer->afc_recv[afi][pfx_rcd_safi])
7983 vty_out(vty, " %12ld",
7984 peer->pcount[afi]
7985 [pfx_rcd_safi]);
7986 else
7987 vty_out(vty, " NoNeg");
7988 else {
7989 if (CHECK_FLAG(peer->flags, PEER_FLAG_SHUTDOWN))
7990 vty_out(vty, " Idle (Admin)");
7991 else if (CHECK_FLAG(
7992 peer->sflags,
7993 PEER_STATUS_PREFIX_OVERFLOW))
7994 vty_out(vty, " Idle (PfxCt)");
7995 else
7996 vty_out(vty, " %12s",
7997 lookup_msg(bgp_status_msg,
7998 peer->status, NULL));
7999 }
8000 vty_out(vty, "\n");
8001 }
8002 }
8003
8004 if (use_json) {
8005 json_object_object_add(json, "peers", json_peers);
8006
8007 json_object_int_add(json, "totalPeers", count);
8008 json_object_int_add(json, "dynamicPeers", dn_count);
8009
8010 bgp_show_bestpath_json(bgp, json);
8011
8012 vty_out(vty, "%s\n", json_object_to_json_string_ext(
8013 json, JSON_C_TO_STRING_PRETTY));
8014 json_object_free(json);
8015 } else {
8016 if (count)
8017 vty_out(vty, "\nTotal number of neighbors %d\n", count);
8018 else {
8019 if (use_json)
8020 vty_out(vty,
8021 "{\"error\": {\"message\": \"No %s neighbor configured\"}}\n",
8022 afi_safi_print(afi, safi));
8023 else
8024 vty_out(vty, "No %s neighbor is configured\n",
8025 afi_safi_print(afi, safi));
8026 }
8027
8028 if (dn_count && !use_json) {
8029 vty_out(vty, "* - dynamic neighbor\n");
8030 vty_out(vty, "%d dynamic neighbor(s), limit %d\n",
8031 dn_count, bgp->dynamic_neighbors_limit);
8032 }
8033 }
8034
8035 return CMD_SUCCESS;
8036 }
8037
8038 static void bgp_show_summary_afi_safi(struct vty *vty, struct bgp *bgp, int afi,
8039 int safi, uint8_t use_json,
8040 json_object *json)
8041 {
8042 int is_first = 1;
8043 int afi_wildcard = (afi == AFI_MAX);
8044 int safi_wildcard = (safi == SAFI_MAX);
8045 int is_wildcard = (afi_wildcard || safi_wildcard);
8046 bool json_output = false;
8047
8048 if (use_json && is_wildcard)
8049 vty_out(vty, "{\n");
8050 if (afi_wildcard)
8051 afi = 1; /* AFI_IP */
8052 while (afi < AFI_MAX) {
8053 if (safi_wildcard)
8054 safi = 1; /* SAFI_UNICAST */
8055 while (safi < SAFI_MAX) {
8056 if (bgp_afi_safi_peer_exists(bgp, afi, safi)) {
8057 json_output = true;
8058 if (is_wildcard) {
8059 /*
8060 * So limit output to those afi/safi
8061 * pairs that
8062 * actualy have something interesting in
8063 * them
8064 */
8065 if (use_json) {
8066 json = json_object_new_object();
8067
8068 if (!is_first)
8069 vty_out(vty, ",\n");
8070 else
8071 is_first = 0;
8072
8073 vty_out(vty, "\"%s\":",
8074 afi_safi_json(afi,
8075 safi));
8076 } else {
8077 vty_out(vty, "\n%s Summary:\n",
8078 afi_safi_print(afi,
8079 safi));
8080 }
8081 }
8082 bgp_show_summary(vty, bgp, afi, safi, use_json,
8083 json);
8084 }
8085 safi++;
8086 if (!safi_wildcard)
8087 safi = SAFI_MAX;
8088 }
8089 afi++;
8090 if (!afi_wildcard)
8091 afi = AFI_MAX;
8092 }
8093
8094 if (use_json && is_wildcard)
8095 vty_out(vty, "}\n");
8096 else if (use_json && !json_output)
8097 vty_out(vty, "{}\n");
8098 }
8099
8100 static void bgp_show_all_instances_summary_vty(struct vty *vty, afi_t afi,
8101 safi_t safi, uint8_t use_json)
8102 {
8103 struct listnode *node, *nnode;
8104 struct bgp *bgp;
8105 json_object *json = NULL;
8106 int is_first = 1;
8107
8108 if (use_json)
8109 vty_out(vty, "{\n");
8110
8111 for (ALL_LIST_ELEMENTS(bm->bgp, node, nnode, bgp)) {
8112 if (use_json) {
8113 json = json_object_new_object();
8114
8115 if (!is_first)
8116 vty_out(vty, ",\n");
8117 else
8118 is_first = 0;
8119
8120 vty_out(vty, "\"%s\":",
8121 (bgp->inst_type == BGP_INSTANCE_TYPE_DEFAULT)
8122 ? "Default"
8123 : bgp->name);
8124 } else {
8125 vty_out(vty, "\nInstance %s:\n",
8126 (bgp->inst_type == BGP_INSTANCE_TYPE_DEFAULT)
8127 ? "Default"
8128 : bgp->name);
8129 }
8130 bgp_show_summary_afi_safi(vty, bgp, afi, safi, use_json, json);
8131 }
8132
8133 if (use_json)
8134 vty_out(vty, "}\n");
8135 }
8136
8137 int bgp_show_summary_vty(struct vty *vty, const char *name, afi_t afi,
8138 safi_t safi, uint8_t use_json)
8139 {
8140 struct bgp *bgp;
8141
8142 if (name) {
8143 if (strmatch(name, "all")) {
8144 bgp_show_all_instances_summary_vty(vty, afi, safi,
8145 use_json);
8146 return CMD_SUCCESS;
8147 } else {
8148 bgp = bgp_lookup_by_name(name);
8149
8150 if (!bgp) {
8151 if (use_json)
8152 vty_out(vty, "{}\n");
8153 else
8154 vty_out(vty,
8155 "%% No such BGP instance exist\n");
8156 return CMD_WARNING;
8157 }
8158
8159 bgp_show_summary_afi_safi(vty, bgp, afi, safi, use_json,
8160 NULL);
8161 return CMD_SUCCESS;
8162 }
8163 }
8164
8165 bgp = bgp_get_default();
8166
8167 if (bgp)
8168 bgp_show_summary_afi_safi(vty, bgp, afi, safi, use_json, NULL);
8169
8170 return CMD_SUCCESS;
8171 }
8172
8173 /* `show [ip] bgp summary' commands. */
8174 DEFUN (show_ip_bgp_summary,
8175 show_ip_bgp_summary_cmd,
8176 "show [ip] bgp [<view|vrf> VIEWVRFNAME] ["BGP_AFI_CMD_STR" ["BGP_SAFI_WITH_LABEL_CMD_STR"]] summary [json]",
8177 SHOW_STR
8178 IP_STR
8179 BGP_STR
8180 BGP_INSTANCE_HELP_STR
8181 BGP_AFI_HELP_STR
8182 BGP_SAFI_WITH_LABEL_HELP_STR
8183 "Summary of BGP neighbor status\n"
8184 JSON_STR)
8185 {
8186 char *vrf = NULL;
8187 afi_t afi = AFI_MAX;
8188 safi_t safi = SAFI_MAX;
8189
8190 int idx = 0;
8191
8192 /* show [ip] bgp */
8193 if (argv_find(argv, argc, "ip", &idx))
8194 afi = AFI_IP;
8195 /* [<view|vrf> VIEWVRFNAME] */
8196 if (argv_find(argv, argc, "view", &idx)
8197 || argv_find(argv, argc, "vrf", &idx))
8198 vrf = argv[++idx]->arg;
8199 /* ["BGP_AFI_CMD_STR" ["BGP_SAFI_CMD_STR"]] */
8200 if (argv_find_and_parse_afi(argv, argc, &idx, &afi)) {
8201 argv_find_and_parse_safi(argv, argc, &idx, &safi);
8202 }
8203
8204 int uj = use_json(argc, argv);
8205
8206 return bgp_show_summary_vty(vty, vrf, afi, safi, uj);
8207 }
8208
8209 const char *afi_safi_print(afi_t afi, safi_t safi)
8210 {
8211 if (afi == AFI_IP && safi == SAFI_UNICAST)
8212 return "IPv4 Unicast";
8213 else if (afi == AFI_IP && safi == SAFI_MULTICAST)
8214 return "IPv4 Multicast";
8215 else if (afi == AFI_IP && safi == SAFI_LABELED_UNICAST)
8216 return "IPv4 Labeled Unicast";
8217 else if (afi == AFI_IP && safi == SAFI_MPLS_VPN)
8218 return "IPv4 VPN";
8219 else if (afi == AFI_IP && safi == SAFI_ENCAP)
8220 return "IPv4 Encap";
8221 else if (afi == AFI_IP && safi == SAFI_FLOWSPEC)
8222 return "IPv4 Flowspec";
8223 else if (afi == AFI_IP6 && safi == SAFI_UNICAST)
8224 return "IPv6 Unicast";
8225 else if (afi == AFI_IP6 && safi == SAFI_MULTICAST)
8226 return "IPv6 Multicast";
8227 else if (afi == AFI_IP6 && safi == SAFI_LABELED_UNICAST)
8228 return "IPv6 Labeled Unicast";
8229 else if (afi == AFI_IP6 && safi == SAFI_MPLS_VPN)
8230 return "IPv6 VPN";
8231 else if (afi == AFI_IP6 && safi == SAFI_ENCAP)
8232 return "IPv6 Encap";
8233 else if (afi == AFI_IP6 && safi == SAFI_FLOWSPEC)
8234 return "IPv6 Flowspec";
8235 else if (afi == AFI_L2VPN && safi == SAFI_EVPN)
8236 return "L2VPN EVPN";
8237 else
8238 return "Unknown";
8239 }
8240
8241 /*
8242 * Please note that we have intentionally camelCased
8243 * the return strings here. So if you want
8244 * to use this function, please ensure you
8245 * are doing this within json output
8246 */
8247 const char *afi_safi_json(afi_t afi, safi_t safi)
8248 {
8249 if (afi == AFI_IP && safi == SAFI_UNICAST)
8250 return "ipv4Unicast";
8251 else if (afi == AFI_IP && safi == SAFI_MULTICAST)
8252 return "ipv4Multicast";
8253 else if (afi == AFI_IP && safi == SAFI_LABELED_UNICAST)
8254 return "ipv4LabeledUnicast";
8255 else if (afi == AFI_IP && safi == SAFI_MPLS_VPN)
8256 return "ipv4Vpn";
8257 else if (afi == AFI_IP && safi == SAFI_ENCAP)
8258 return "ipv4Encap";
8259 else if (afi == AFI_IP && safi == SAFI_FLOWSPEC)
8260 return "ipv4Flowspec";
8261 else if (afi == AFI_IP6 && safi == SAFI_UNICAST)
8262 return "ipv6Unicast";
8263 else if (afi == AFI_IP6 && safi == SAFI_MULTICAST)
8264 return "ipv6Multicast";
8265 else if (afi == AFI_IP6 && safi == SAFI_LABELED_UNICAST)
8266 return "ipv6LabeledUnicast";
8267 else if (afi == AFI_IP6 && safi == SAFI_MPLS_VPN)
8268 return "ipv6Vpn";
8269 else if (afi == AFI_IP6 && safi == SAFI_ENCAP)
8270 return "ipv6Encap";
8271 else if (afi == AFI_IP6 && safi == SAFI_FLOWSPEC)
8272 return "ipv6Flowspec";
8273 else if (afi == AFI_L2VPN && safi == SAFI_EVPN)
8274 return "l2VpnEvpn";
8275 else
8276 return "Unknown";
8277 }
8278
8279 /* Show BGP peer's information. */
8280 enum show_type { show_all, show_peer };
8281
8282 static void bgp_show_peer_afi_orf_cap(struct vty *vty, struct peer *p,
8283 afi_t afi, safi_t safi,
8284 uint16_t adv_smcap, uint16_t adv_rmcap,
8285 uint16_t rcv_smcap, uint16_t rcv_rmcap,
8286 uint8_t use_json, json_object *json_pref)
8287 {
8288 /* Send-Mode */
8289 if (CHECK_FLAG(p->af_cap[afi][safi], adv_smcap)
8290 || CHECK_FLAG(p->af_cap[afi][safi], rcv_smcap)) {
8291 if (use_json) {
8292 if (CHECK_FLAG(p->af_cap[afi][safi], adv_smcap)
8293 && CHECK_FLAG(p->af_cap[afi][safi], rcv_smcap))
8294 json_object_string_add(json_pref, "sendMode",
8295 "advertisedAndReceived");
8296 else if (CHECK_FLAG(p->af_cap[afi][safi], adv_smcap))
8297 json_object_string_add(json_pref, "sendMode",
8298 "advertised");
8299 else if (CHECK_FLAG(p->af_cap[afi][safi], rcv_smcap))
8300 json_object_string_add(json_pref, "sendMode",
8301 "received");
8302 } else {
8303 vty_out(vty, " Send-mode: ");
8304 if (CHECK_FLAG(p->af_cap[afi][safi], adv_smcap))
8305 vty_out(vty, "advertised");
8306 if (CHECK_FLAG(p->af_cap[afi][safi], rcv_smcap))
8307 vty_out(vty, "%sreceived",
8308 CHECK_FLAG(p->af_cap[afi][safi],
8309 adv_smcap)
8310 ? ", "
8311 : "");
8312 vty_out(vty, "\n");
8313 }
8314 }
8315
8316 /* Receive-Mode */
8317 if (CHECK_FLAG(p->af_cap[afi][safi], adv_rmcap)
8318 || CHECK_FLAG(p->af_cap[afi][safi], rcv_rmcap)) {
8319 if (use_json) {
8320 if (CHECK_FLAG(p->af_cap[afi][safi], adv_rmcap)
8321 && CHECK_FLAG(p->af_cap[afi][safi], rcv_rmcap))
8322 json_object_string_add(json_pref, "recvMode",
8323 "advertisedAndReceived");
8324 else if (CHECK_FLAG(p->af_cap[afi][safi], adv_rmcap))
8325 json_object_string_add(json_pref, "recvMode",
8326 "advertised");
8327 else if (CHECK_FLAG(p->af_cap[afi][safi], rcv_rmcap))
8328 json_object_string_add(json_pref, "recvMode",
8329 "received");
8330 } else {
8331 vty_out(vty, " Receive-mode: ");
8332 if (CHECK_FLAG(p->af_cap[afi][safi], adv_rmcap))
8333 vty_out(vty, "advertised");
8334 if (CHECK_FLAG(p->af_cap[afi][safi], rcv_rmcap))
8335 vty_out(vty, "%sreceived",
8336 CHECK_FLAG(p->af_cap[afi][safi],
8337 adv_rmcap)
8338 ? ", "
8339 : "");
8340 vty_out(vty, "\n");
8341 }
8342 }
8343 }
8344
8345 static void bgp_show_peer_afi(struct vty *vty, struct peer *p, afi_t afi,
8346 safi_t safi, uint8_t use_json,
8347 json_object *json_neigh)
8348 {
8349 struct bgp_filter *filter;
8350 struct peer_af *paf;
8351 char orf_pfx_name[BUFSIZ];
8352 int orf_pfx_count;
8353 json_object *json_af = NULL;
8354 json_object *json_prefA = NULL;
8355 json_object *json_prefB = NULL;
8356 json_object *json_addr = NULL;
8357
8358 if (use_json) {
8359 json_addr = json_object_new_object();
8360 json_af = json_object_new_object();
8361 filter = &p->filter[afi][safi];
8362
8363 if (peer_group_active(p))
8364 json_object_string_add(json_addr, "peerGroupMember",
8365 p->group->name);
8366
8367 paf = peer_af_find(p, afi, safi);
8368 if (paf && PAF_SUBGRP(paf)) {
8369 json_object_int_add(json_addr, "updateGroupId",
8370 PAF_UPDGRP(paf)->id);
8371 json_object_int_add(json_addr, "subGroupId",
8372 PAF_SUBGRP(paf)->id);
8373 json_object_int_add(json_addr, "packetQueueLength",
8374 bpacket_queue_virtual_length(paf));
8375 }
8376
8377 if (CHECK_FLAG(p->af_cap[afi][safi], PEER_CAP_ORF_PREFIX_SM_ADV)
8378 || CHECK_FLAG(p->af_cap[afi][safi],
8379 PEER_CAP_ORF_PREFIX_SM_RCV)
8380 || CHECK_FLAG(p->af_cap[afi][safi],
8381 PEER_CAP_ORF_PREFIX_RM_ADV)
8382 || CHECK_FLAG(p->af_cap[afi][safi],
8383 PEER_CAP_ORF_PREFIX_RM_RCV)) {
8384 json_object_int_add(json_af, "orfType",
8385 ORF_TYPE_PREFIX);
8386 json_prefA = json_object_new_object();
8387 bgp_show_peer_afi_orf_cap(vty, p, afi, safi,
8388 PEER_CAP_ORF_PREFIX_SM_ADV,
8389 PEER_CAP_ORF_PREFIX_RM_ADV,
8390 PEER_CAP_ORF_PREFIX_SM_RCV,
8391 PEER_CAP_ORF_PREFIX_RM_RCV,
8392 use_json, json_prefA);
8393 json_object_object_add(json_af, "orfPrefixList",
8394 json_prefA);
8395 }
8396
8397 if (CHECK_FLAG(p->af_cap[afi][safi], PEER_CAP_ORF_PREFIX_SM_ADV)
8398 || CHECK_FLAG(p->af_cap[afi][safi],
8399 PEER_CAP_ORF_PREFIX_SM_OLD_RCV)
8400 || CHECK_FLAG(p->af_cap[afi][safi],
8401 PEER_CAP_ORF_PREFIX_RM_ADV)
8402 || CHECK_FLAG(p->af_cap[afi][safi],
8403 PEER_CAP_ORF_PREFIX_RM_OLD_RCV)) {
8404 json_object_int_add(json_af, "orfOldType",
8405 ORF_TYPE_PREFIX_OLD);
8406 json_prefB = json_object_new_object();
8407 bgp_show_peer_afi_orf_cap(
8408 vty, p, afi, safi, PEER_CAP_ORF_PREFIX_SM_ADV,
8409 PEER_CAP_ORF_PREFIX_RM_ADV,
8410 PEER_CAP_ORF_PREFIX_SM_OLD_RCV,
8411 PEER_CAP_ORF_PREFIX_RM_OLD_RCV, use_json,
8412 json_prefB);
8413 json_object_object_add(json_af, "orfOldPrefixList",
8414 json_prefB);
8415 }
8416
8417 if (CHECK_FLAG(p->af_cap[afi][safi], PEER_CAP_ORF_PREFIX_SM_ADV)
8418 || CHECK_FLAG(p->af_cap[afi][safi],
8419 PEER_CAP_ORF_PREFIX_SM_RCV)
8420 || CHECK_FLAG(p->af_cap[afi][safi],
8421 PEER_CAP_ORF_PREFIX_SM_OLD_RCV)
8422 || CHECK_FLAG(p->af_cap[afi][safi],
8423 PEER_CAP_ORF_PREFIX_RM_ADV)
8424 || CHECK_FLAG(p->af_cap[afi][safi],
8425 PEER_CAP_ORF_PREFIX_RM_RCV)
8426 || CHECK_FLAG(p->af_cap[afi][safi],
8427 PEER_CAP_ORF_PREFIX_RM_OLD_RCV))
8428 json_object_object_add(json_addr, "afDependentCap",
8429 json_af);
8430 else
8431 json_object_free(json_af);
8432
8433 sprintf(orf_pfx_name, "%s.%d.%d", p->host, afi, safi);
8434 orf_pfx_count = prefix_bgp_show_prefix_list(
8435 NULL, afi, orf_pfx_name, use_json);
8436
8437 if (CHECK_FLAG(p->af_sflags[afi][safi],
8438 PEER_STATUS_ORF_PREFIX_SEND)
8439 || orf_pfx_count) {
8440 if (CHECK_FLAG(p->af_sflags[afi][safi],
8441 PEER_STATUS_ORF_PREFIX_SEND))
8442 json_object_boolean_true_add(json_neigh,
8443 "orfSent");
8444 if (orf_pfx_count)
8445 json_object_int_add(json_addr, "orfRecvCounter",
8446 orf_pfx_count);
8447 }
8448 if (CHECK_FLAG(p->af_sflags[afi][safi],
8449 PEER_STATUS_ORF_WAIT_REFRESH))
8450 json_object_string_add(
8451 json_addr, "orfFirstUpdate",
8452 "deferredUntilORFOrRouteRefreshRecvd");
8453
8454 if (CHECK_FLAG(p->af_flags[afi][safi],
8455 PEER_FLAG_REFLECTOR_CLIENT))
8456 json_object_boolean_true_add(json_addr,
8457 "routeReflectorClient");
8458 if (CHECK_FLAG(p->af_flags[afi][safi],
8459 PEER_FLAG_RSERVER_CLIENT))
8460 json_object_boolean_true_add(json_addr,
8461 "routeServerClient");
8462 if (CHECK_FLAG(p->af_flags[afi][safi], PEER_FLAG_SOFT_RECONFIG))
8463 json_object_boolean_true_add(json_addr,
8464 "inboundSoftConfigPermit");
8465
8466 if (CHECK_FLAG(p->af_flags[afi][safi],
8467 PEER_FLAG_REMOVE_PRIVATE_AS_ALL_REPLACE))
8468 json_object_boolean_true_add(
8469 json_addr,
8470 "privateAsNumsAllReplacedInUpdatesToNbr");
8471 else if (CHECK_FLAG(p->af_flags[afi][safi],
8472 PEER_FLAG_REMOVE_PRIVATE_AS_REPLACE))
8473 json_object_boolean_true_add(
8474 json_addr,
8475 "privateAsNumsReplacedInUpdatesToNbr");
8476 else if (CHECK_FLAG(p->af_flags[afi][safi],
8477 PEER_FLAG_REMOVE_PRIVATE_AS_ALL))
8478 json_object_boolean_true_add(
8479 json_addr,
8480 "privateAsNumsAllRemovedInUpdatesToNbr");
8481 else if (CHECK_FLAG(p->af_flags[afi][safi],
8482 PEER_FLAG_REMOVE_PRIVATE_AS))
8483 json_object_boolean_true_add(
8484 json_addr,
8485 "privateAsNumsRemovedInUpdatesToNbr");
8486
8487 if (CHECK_FLAG(p->af_flags[afi][safi],
8488 PEER_FLAG_ADDPATH_TX_ALL_PATHS))
8489 json_object_boolean_true_add(json_addr,
8490 "addpathTxAllPaths");
8491
8492 if (CHECK_FLAG(p->af_flags[afi][safi],
8493 PEER_FLAG_ADDPATH_TX_BESTPATH_PER_AS))
8494 json_object_boolean_true_add(json_addr,
8495 "addpathTxBestpathPerAS");
8496
8497 if (CHECK_FLAG(p->af_flags[afi][safi], PEER_FLAG_AS_OVERRIDE))
8498 json_object_string_add(json_addr,
8499 "overrideASNsInOutboundUpdates",
8500 "ifAspathEqualRemoteAs");
8501
8502 if (CHECK_FLAG(p->af_flags[afi][safi], PEER_FLAG_NEXTHOP_SELF)
8503 || CHECK_FLAG(p->af_flags[afi][safi],
8504 PEER_FLAG_FORCE_NEXTHOP_SELF))
8505 json_object_boolean_true_add(json_addr,
8506 "routerAlwaysNextHop");
8507 if (CHECK_FLAG(p->af_flags[afi][safi],
8508 PEER_FLAG_AS_PATH_UNCHANGED))
8509 json_object_boolean_true_add(
8510 json_addr, "unchangedAsPathPropogatedToNbr");
8511 if (CHECK_FLAG(p->af_flags[afi][safi],
8512 PEER_FLAG_NEXTHOP_UNCHANGED))
8513 json_object_boolean_true_add(
8514 json_addr, "unchangedNextHopPropogatedToNbr");
8515 if (CHECK_FLAG(p->af_flags[afi][safi], PEER_FLAG_MED_UNCHANGED))
8516 json_object_boolean_true_add(
8517 json_addr, "unchangedMedPropogatedToNbr");
8518 if (CHECK_FLAG(p->af_flags[afi][safi], PEER_FLAG_SEND_COMMUNITY)
8519 || CHECK_FLAG(p->af_flags[afi][safi],
8520 PEER_FLAG_SEND_EXT_COMMUNITY)) {
8521 if (CHECK_FLAG(p->af_flags[afi][safi],
8522 PEER_FLAG_SEND_COMMUNITY)
8523 && CHECK_FLAG(p->af_flags[afi][safi],
8524 PEER_FLAG_SEND_EXT_COMMUNITY))
8525 json_object_string_add(json_addr,
8526 "commAttriSentToNbr",
8527 "extendedAndStandard");
8528 else if (CHECK_FLAG(p->af_flags[afi][safi],
8529 PEER_FLAG_SEND_EXT_COMMUNITY))
8530 json_object_string_add(json_addr,
8531 "commAttriSentToNbr",
8532 "extended");
8533 else
8534 json_object_string_add(json_addr,
8535 "commAttriSentToNbr",
8536 "standard");
8537 }
8538 if (CHECK_FLAG(p->af_flags[afi][safi],
8539 PEER_FLAG_DEFAULT_ORIGINATE)) {
8540 if (p->default_rmap[afi][safi].name)
8541 json_object_string_add(
8542 json_addr, "defaultRouteMap",
8543 p->default_rmap[afi][safi].name);
8544
8545 if (paf && PAF_SUBGRP(paf)
8546 && CHECK_FLAG(PAF_SUBGRP(paf)->sflags,
8547 SUBGRP_STATUS_DEFAULT_ORIGINATE))
8548 json_object_boolean_true_add(json_addr,
8549 "defaultSent");
8550 else
8551 json_object_boolean_true_add(json_addr,
8552 "defaultNotSent");
8553 }
8554
8555 if (afi == AFI_L2VPN && safi == SAFI_EVPN) {
8556 if (is_evpn_enabled())
8557 json_object_boolean_true_add(
8558 json_addr, "advertiseAllVnis");
8559 }
8560
8561 if (filter->plist[FILTER_IN].name
8562 || filter->dlist[FILTER_IN].name
8563 || filter->aslist[FILTER_IN].name
8564 || filter->map[RMAP_IN].name)
8565 json_object_boolean_true_add(json_addr,
8566 "inboundPathPolicyConfig");
8567 if (filter->plist[FILTER_OUT].name
8568 || filter->dlist[FILTER_OUT].name
8569 || filter->aslist[FILTER_OUT].name
8570 || filter->map[RMAP_OUT].name || filter->usmap.name)
8571 json_object_boolean_true_add(
8572 json_addr, "outboundPathPolicyConfig");
8573
8574 /* prefix-list */
8575 if (filter->plist[FILTER_IN].name)
8576 json_object_string_add(json_addr,
8577 "incomingUpdatePrefixFilterList",
8578 filter->plist[FILTER_IN].name);
8579 if (filter->plist[FILTER_OUT].name)
8580 json_object_string_add(json_addr,
8581 "outgoingUpdatePrefixFilterList",
8582 filter->plist[FILTER_OUT].name);
8583
8584 /* distribute-list */
8585 if (filter->dlist[FILTER_IN].name)
8586 json_object_string_add(
8587 json_addr, "incomingUpdateNetworkFilterList",
8588 filter->dlist[FILTER_IN].name);
8589 if (filter->dlist[FILTER_OUT].name)
8590 json_object_string_add(
8591 json_addr, "outgoingUpdateNetworkFilterList",
8592 filter->dlist[FILTER_OUT].name);
8593
8594 /* filter-list. */
8595 if (filter->aslist[FILTER_IN].name)
8596 json_object_string_add(json_addr,
8597 "incomingUpdateAsPathFilterList",
8598 filter->aslist[FILTER_IN].name);
8599 if (filter->aslist[FILTER_OUT].name)
8600 json_object_string_add(json_addr,
8601 "outgoingUpdateAsPathFilterList",
8602 filter->aslist[FILTER_OUT].name);
8603
8604 /* route-map. */
8605 if (filter->map[RMAP_IN].name)
8606 json_object_string_add(
8607 json_addr, "routeMapForIncomingAdvertisements",
8608 filter->map[RMAP_IN].name);
8609 if (filter->map[RMAP_OUT].name)
8610 json_object_string_add(
8611 json_addr, "routeMapForOutgoingAdvertisements",
8612 filter->map[RMAP_OUT].name);
8613
8614 /* unsuppress-map */
8615 if (filter->usmap.name)
8616 json_object_string_add(json_addr,
8617 "selectiveUnsuppressRouteMap",
8618 filter->usmap.name);
8619
8620 /* Receive prefix count */
8621 json_object_int_add(json_addr, "acceptedPrefixCounter",
8622 p->pcount[afi][safi]);
8623
8624 /* Maximum prefix */
8625 if (CHECK_FLAG(p->af_flags[afi][safi], PEER_FLAG_MAX_PREFIX)) {
8626 json_object_int_add(json_addr, "prefixAllowedMax",
8627 p->pmax[afi][safi]);
8628 if (CHECK_FLAG(p->af_flags[afi][safi],
8629 PEER_FLAG_MAX_PREFIX_WARNING))
8630 json_object_boolean_true_add(
8631 json_addr, "prefixAllowedMaxWarning");
8632 json_object_int_add(json_addr,
8633 "prefixAllowedWarningThresh",
8634 p->pmax_threshold[afi][safi]);
8635 if (p->pmax_restart[afi][safi])
8636 json_object_int_add(
8637 json_addr,
8638 "prefixAllowedRestartIntervalMsecs",
8639 p->pmax_restart[afi][safi] * 60000);
8640 }
8641 json_object_object_add(json_neigh, afi_safi_print(afi, safi),
8642 json_addr);
8643
8644 } else {
8645 filter = &p->filter[afi][safi];
8646
8647 vty_out(vty, " For address family: %s\n",
8648 afi_safi_print(afi, safi));
8649
8650 if (peer_group_active(p))
8651 vty_out(vty, " %s peer-group member\n",
8652 p->group->name);
8653
8654 paf = peer_af_find(p, afi, safi);
8655 if (paf && PAF_SUBGRP(paf)) {
8656 vty_out(vty, " Update group %" PRIu64
8657 ", subgroup %" PRIu64 "\n",
8658 PAF_UPDGRP(paf)->id, PAF_SUBGRP(paf)->id);
8659 vty_out(vty, " Packet Queue length %d\n",
8660 bpacket_queue_virtual_length(paf));
8661 } else {
8662 vty_out(vty, " Not part of any update group\n");
8663 }
8664 if (CHECK_FLAG(p->af_cap[afi][safi], PEER_CAP_ORF_PREFIX_SM_ADV)
8665 || CHECK_FLAG(p->af_cap[afi][safi],
8666 PEER_CAP_ORF_PREFIX_SM_RCV)
8667 || CHECK_FLAG(p->af_cap[afi][safi],
8668 PEER_CAP_ORF_PREFIX_SM_OLD_RCV)
8669 || CHECK_FLAG(p->af_cap[afi][safi],
8670 PEER_CAP_ORF_PREFIX_RM_ADV)
8671 || CHECK_FLAG(p->af_cap[afi][safi],
8672 PEER_CAP_ORF_PREFIX_RM_RCV)
8673 || CHECK_FLAG(p->af_cap[afi][safi],
8674 PEER_CAP_ORF_PREFIX_RM_OLD_RCV))
8675 vty_out(vty, " AF-dependant capabilities:\n");
8676
8677 if (CHECK_FLAG(p->af_cap[afi][safi], PEER_CAP_ORF_PREFIX_SM_ADV)
8678 || CHECK_FLAG(p->af_cap[afi][safi],
8679 PEER_CAP_ORF_PREFIX_SM_RCV)
8680 || CHECK_FLAG(p->af_cap[afi][safi],
8681 PEER_CAP_ORF_PREFIX_RM_ADV)
8682 || CHECK_FLAG(p->af_cap[afi][safi],
8683 PEER_CAP_ORF_PREFIX_RM_RCV)) {
8684 vty_out(vty,
8685 " Outbound Route Filter (ORF) type (%d) Prefix-list:\n",
8686 ORF_TYPE_PREFIX);
8687 bgp_show_peer_afi_orf_cap(
8688 vty, p, afi, safi, PEER_CAP_ORF_PREFIX_SM_ADV,
8689 PEER_CAP_ORF_PREFIX_RM_ADV,
8690 PEER_CAP_ORF_PREFIX_SM_RCV,
8691 PEER_CAP_ORF_PREFIX_RM_RCV, use_json, NULL);
8692 }
8693 if (CHECK_FLAG(p->af_cap[afi][safi], PEER_CAP_ORF_PREFIX_SM_ADV)
8694 || CHECK_FLAG(p->af_cap[afi][safi],
8695 PEER_CAP_ORF_PREFIX_SM_OLD_RCV)
8696 || CHECK_FLAG(p->af_cap[afi][safi],
8697 PEER_CAP_ORF_PREFIX_RM_ADV)
8698 || CHECK_FLAG(p->af_cap[afi][safi],
8699 PEER_CAP_ORF_PREFIX_RM_OLD_RCV)) {
8700 vty_out(vty,
8701 " Outbound Route Filter (ORF) type (%d) Prefix-list:\n",
8702 ORF_TYPE_PREFIX_OLD);
8703 bgp_show_peer_afi_orf_cap(
8704 vty, p, afi, safi, PEER_CAP_ORF_PREFIX_SM_ADV,
8705 PEER_CAP_ORF_PREFIX_RM_ADV,
8706 PEER_CAP_ORF_PREFIX_SM_OLD_RCV,
8707 PEER_CAP_ORF_PREFIX_RM_OLD_RCV, use_json, NULL);
8708 }
8709
8710 sprintf(orf_pfx_name, "%s.%d.%d", p->host, afi, safi);
8711 orf_pfx_count = prefix_bgp_show_prefix_list(
8712 NULL, afi, orf_pfx_name, use_json);
8713
8714 if (CHECK_FLAG(p->af_sflags[afi][safi],
8715 PEER_STATUS_ORF_PREFIX_SEND)
8716 || orf_pfx_count) {
8717 vty_out(vty, " Outbound Route Filter (ORF):");
8718 if (CHECK_FLAG(p->af_sflags[afi][safi],
8719 PEER_STATUS_ORF_PREFIX_SEND))
8720 vty_out(vty, " sent;");
8721 if (orf_pfx_count)
8722 vty_out(vty, " received (%d entries)",
8723 orf_pfx_count);
8724 vty_out(vty, "\n");
8725 }
8726 if (CHECK_FLAG(p->af_sflags[afi][safi],
8727 PEER_STATUS_ORF_WAIT_REFRESH))
8728 vty_out(vty,
8729 " First update is deferred until ORF or ROUTE-REFRESH is received\n");
8730
8731 if (CHECK_FLAG(p->af_flags[afi][safi],
8732 PEER_FLAG_REFLECTOR_CLIENT))
8733 vty_out(vty, " Route-Reflector Client\n");
8734 if (CHECK_FLAG(p->af_flags[afi][safi],
8735 PEER_FLAG_RSERVER_CLIENT))
8736 vty_out(vty, " Route-Server Client\n");
8737 if (CHECK_FLAG(p->af_flags[afi][safi], PEER_FLAG_SOFT_RECONFIG))
8738 vty_out(vty,
8739 " Inbound soft reconfiguration allowed\n");
8740
8741 if (CHECK_FLAG(p->af_flags[afi][safi],
8742 PEER_FLAG_REMOVE_PRIVATE_AS_ALL_REPLACE))
8743 vty_out(vty,
8744 " Private AS numbers (all) replaced in updates to this neighbor\n");
8745 else if (CHECK_FLAG(p->af_flags[afi][safi],
8746 PEER_FLAG_REMOVE_PRIVATE_AS_REPLACE))
8747 vty_out(vty,
8748 " Private AS numbers replaced in updates to this neighbor\n");
8749 else if (CHECK_FLAG(p->af_flags[afi][safi],
8750 PEER_FLAG_REMOVE_PRIVATE_AS_ALL))
8751 vty_out(vty,
8752 " Private AS numbers (all) removed in updates to this neighbor\n");
8753 else if (CHECK_FLAG(p->af_flags[afi][safi],
8754 PEER_FLAG_REMOVE_PRIVATE_AS))
8755 vty_out(vty,
8756 " Private AS numbers removed in updates to this neighbor\n");
8757
8758 if (CHECK_FLAG(p->af_flags[afi][safi],
8759 PEER_FLAG_ADDPATH_TX_ALL_PATHS))
8760 vty_out(vty, " Advertise all paths via addpath\n");
8761
8762 if (CHECK_FLAG(p->af_flags[afi][safi],
8763 PEER_FLAG_ADDPATH_TX_BESTPATH_PER_AS))
8764 vty_out(vty,
8765 " Advertise bestpath per AS via addpath\n");
8766
8767 if (CHECK_FLAG(p->af_flags[afi][safi], PEER_FLAG_AS_OVERRIDE))
8768 vty_out(vty,
8769 " Override ASNs in outbound updates if aspath equals remote-as\n");
8770
8771 if (CHECK_FLAG(p->af_flags[afi][safi], PEER_FLAG_NEXTHOP_SELF)
8772 || CHECK_FLAG(p->af_flags[afi][safi],
8773 PEER_FLAG_FORCE_NEXTHOP_SELF))
8774 vty_out(vty, " NEXT_HOP is always this router\n");
8775 if (CHECK_FLAG(p->af_flags[afi][safi],
8776 PEER_FLAG_AS_PATH_UNCHANGED))
8777 vty_out(vty,
8778 " AS_PATH is propagated unchanged to this neighbor\n");
8779 if (CHECK_FLAG(p->af_flags[afi][safi],
8780 PEER_FLAG_NEXTHOP_UNCHANGED))
8781 vty_out(vty,
8782 " NEXT_HOP is propagated unchanged to this neighbor\n");
8783 if (CHECK_FLAG(p->af_flags[afi][safi], PEER_FLAG_MED_UNCHANGED))
8784 vty_out(vty,
8785 " MED is propagated unchanged to this neighbor\n");
8786 if (CHECK_FLAG(p->af_flags[afi][safi], PEER_FLAG_SEND_COMMUNITY)
8787 || CHECK_FLAG(p->af_flags[afi][safi],
8788 PEER_FLAG_SEND_EXT_COMMUNITY)
8789 || CHECK_FLAG(p->af_flags[afi][safi],
8790 PEER_FLAG_SEND_LARGE_COMMUNITY)) {
8791 vty_out(vty,
8792 " Community attribute sent to this neighbor");
8793 if (CHECK_FLAG(p->af_flags[afi][safi],
8794 PEER_FLAG_SEND_COMMUNITY)
8795 && CHECK_FLAG(p->af_flags[afi][safi],
8796 PEER_FLAG_SEND_EXT_COMMUNITY)
8797 && CHECK_FLAG(p->af_flags[afi][safi],
8798 PEER_FLAG_SEND_LARGE_COMMUNITY))
8799 vty_out(vty, "(all)\n");
8800 else if (CHECK_FLAG(p->af_flags[afi][safi],
8801 PEER_FLAG_SEND_LARGE_COMMUNITY))
8802 vty_out(vty, "(large)\n");
8803 else if (CHECK_FLAG(p->af_flags[afi][safi],
8804 PEER_FLAG_SEND_EXT_COMMUNITY))
8805 vty_out(vty, "(extended)\n");
8806 else
8807 vty_out(vty, "(standard)\n");
8808 }
8809 if (CHECK_FLAG(p->af_flags[afi][safi],
8810 PEER_FLAG_DEFAULT_ORIGINATE)) {
8811 vty_out(vty, " Default information originate,");
8812
8813 if (p->default_rmap[afi][safi].name)
8814 vty_out(vty, " default route-map %s%s,",
8815 p->default_rmap[afi][safi].map ? "*"
8816 : "",
8817 p->default_rmap[afi][safi].name);
8818 if (paf && PAF_SUBGRP(paf)
8819 && CHECK_FLAG(PAF_SUBGRP(paf)->sflags,
8820 SUBGRP_STATUS_DEFAULT_ORIGINATE))
8821 vty_out(vty, " default sent\n");
8822 else
8823 vty_out(vty, " default not sent\n");
8824 }
8825
8826 /* advertise-vni-all */
8827 if (afi == AFI_L2VPN && safi == SAFI_EVPN) {
8828 if (is_evpn_enabled())
8829 vty_out(vty, " advertise-all-vni\n");
8830 }
8831
8832 if (filter->plist[FILTER_IN].name
8833 || filter->dlist[FILTER_IN].name
8834 || filter->aslist[FILTER_IN].name
8835 || filter->map[RMAP_IN].name)
8836 vty_out(vty, " Inbound path policy configured\n");
8837 if (filter->plist[FILTER_OUT].name
8838 || filter->dlist[FILTER_OUT].name
8839 || filter->aslist[FILTER_OUT].name
8840 || filter->map[RMAP_OUT].name || filter->usmap.name)
8841 vty_out(vty, " Outbound path policy configured\n");
8842
8843 /* prefix-list */
8844 if (filter->plist[FILTER_IN].name)
8845 vty_out(vty,
8846 " Incoming update prefix filter list is %s%s\n",
8847 filter->plist[FILTER_IN].plist ? "*" : "",
8848 filter->plist[FILTER_IN].name);
8849 if (filter->plist[FILTER_OUT].name)
8850 vty_out(vty,
8851 " Outgoing update prefix filter list is %s%s\n",
8852 filter->plist[FILTER_OUT].plist ? "*" : "",
8853 filter->plist[FILTER_OUT].name);
8854
8855 /* distribute-list */
8856 if (filter->dlist[FILTER_IN].name)
8857 vty_out(vty,
8858 " Incoming update network filter list is %s%s\n",
8859 filter->dlist[FILTER_IN].alist ? "*" : "",
8860 filter->dlist[FILTER_IN].name);
8861 if (filter->dlist[FILTER_OUT].name)
8862 vty_out(vty,
8863 " Outgoing update network filter list is %s%s\n",
8864 filter->dlist[FILTER_OUT].alist ? "*" : "",
8865 filter->dlist[FILTER_OUT].name);
8866
8867 /* filter-list. */
8868 if (filter->aslist[FILTER_IN].name)
8869 vty_out(vty,
8870 " Incoming update AS path filter list is %s%s\n",
8871 filter->aslist[FILTER_IN].aslist ? "*" : "",
8872 filter->aslist[FILTER_IN].name);
8873 if (filter->aslist[FILTER_OUT].name)
8874 vty_out(vty,
8875 " Outgoing update AS path filter list is %s%s\n",
8876 filter->aslist[FILTER_OUT].aslist ? "*" : "",
8877 filter->aslist[FILTER_OUT].name);
8878
8879 /* route-map. */
8880 if (filter->map[RMAP_IN].name)
8881 vty_out(vty,
8882 " Route map for incoming advertisements is %s%s\n",
8883 filter->map[RMAP_IN].map ? "*" : "",
8884 filter->map[RMAP_IN].name);
8885 if (filter->map[RMAP_OUT].name)
8886 vty_out(vty,
8887 " Route map for outgoing advertisements is %s%s\n",
8888 filter->map[RMAP_OUT].map ? "*" : "",
8889 filter->map[RMAP_OUT].name);
8890
8891 /* unsuppress-map */
8892 if (filter->usmap.name)
8893 vty_out(vty,
8894 " Route map for selective unsuppress is %s%s\n",
8895 filter->usmap.map ? "*" : "",
8896 filter->usmap.name);
8897
8898 /* Receive prefix count */
8899 vty_out(vty, " %ld accepted prefixes\n", p->pcount[afi][safi]);
8900
8901 /* Maximum prefix */
8902 if (CHECK_FLAG(p->af_flags[afi][safi], PEER_FLAG_MAX_PREFIX)) {
8903 vty_out(vty, " Maximum prefixes allowed %ld%s\n",
8904 p->pmax[afi][safi],
8905 CHECK_FLAG(p->af_flags[afi][safi],
8906 PEER_FLAG_MAX_PREFIX_WARNING)
8907 ? " (warning-only)"
8908 : "");
8909 vty_out(vty, " Threshold for warning message %d%%",
8910 p->pmax_threshold[afi][safi]);
8911 if (p->pmax_restart[afi][safi])
8912 vty_out(vty, ", restart interval %d min",
8913 p->pmax_restart[afi][safi]);
8914 vty_out(vty, "\n");
8915 }
8916
8917 vty_out(vty, "\n");
8918 }
8919 }
8920
8921 static void bgp_show_peer(struct vty *vty, struct peer *p, uint8_t use_json,
8922 json_object *json)
8923 {
8924 struct bgp *bgp;
8925 char buf1[PREFIX2STR_BUFFER], buf[SU_ADDRSTRLEN];
8926 char timebuf[BGP_UPTIME_LEN];
8927 char dn_flag[2];
8928 const char *subcode_str;
8929 const char *code_str;
8930 afi_t afi;
8931 safi_t safi;
8932 uint16_t i;
8933 uint8_t *msg;
8934 json_object *json_neigh = NULL;
8935 time_t epoch_tbuf;
8936
8937 bgp = p->bgp;
8938
8939 if (use_json)
8940 json_neigh = json_object_new_object();
8941
8942 memset(dn_flag, '\0', sizeof(dn_flag));
8943 if (!p->conf_if && peer_dynamic_neighbor(p))
8944 dn_flag[0] = '*';
8945
8946 if (!use_json) {
8947 if (p->conf_if) /* Configured interface name. */
8948 vty_out(vty, "BGP neighbor on %s: %s, ", p->conf_if,
8949 BGP_PEER_SU_UNSPEC(p)
8950 ? "None"
8951 : sockunion2str(&p->su, buf,
8952 SU_ADDRSTRLEN));
8953 else /* Configured IP address. */
8954 vty_out(vty, "BGP neighbor is %s%s, ", dn_flag,
8955 p->host);
8956 }
8957
8958 if (use_json) {
8959 if (p->conf_if && BGP_PEER_SU_UNSPEC(p))
8960 json_object_string_add(json_neigh, "bgpNeighborAddr",
8961 "none");
8962 else if (p->conf_if && !BGP_PEER_SU_UNSPEC(p))
8963 json_object_string_add(
8964 json_neigh, "bgpNeighborAddr",
8965 sockunion2str(&p->su, buf, SU_ADDRSTRLEN));
8966
8967 json_object_int_add(json_neigh, "remoteAs", p->as);
8968
8969 if (p->change_local_as)
8970 json_object_int_add(json_neigh, "localAs",
8971 p->change_local_as);
8972 else
8973 json_object_int_add(json_neigh, "localAs", p->local_as);
8974
8975 if (CHECK_FLAG(p->flags, PEER_FLAG_LOCAL_AS_NO_PREPEND))
8976 json_object_boolean_true_add(json_neigh,
8977 "localAsNoPrepend");
8978
8979 if (CHECK_FLAG(p->flags, PEER_FLAG_LOCAL_AS_REPLACE_AS))
8980 json_object_boolean_true_add(json_neigh,
8981 "localAsReplaceAs");
8982 } else {
8983 if ((p->as_type == AS_SPECIFIED) || (p->as_type == AS_EXTERNAL)
8984 || (p->as_type == AS_INTERNAL))
8985 vty_out(vty, "remote AS %u, ", p->as);
8986 else
8987 vty_out(vty, "remote AS Unspecified, ");
8988 vty_out(vty, "local AS %u%s%s, ",
8989 p->change_local_as ? p->change_local_as : p->local_as,
8990 CHECK_FLAG(p->flags, PEER_FLAG_LOCAL_AS_NO_PREPEND)
8991 ? " no-prepend"
8992 : "",
8993 CHECK_FLAG(p->flags, PEER_FLAG_LOCAL_AS_REPLACE_AS)
8994 ? " replace-as"
8995 : "");
8996 }
8997 /* peer type internal, external, confed-internal or confed-external */
8998 if (p->as == p->local_as) {
8999 if (use_json) {
9000 if (CHECK_FLAG(bgp->config, BGP_CONFIG_CONFEDERATION))
9001 json_object_boolean_true_add(
9002 json_neigh, "nbrConfedInternalLink");
9003 else
9004 json_object_boolean_true_add(json_neigh,
9005 "nbrInternalLink");
9006 } else {
9007 if (CHECK_FLAG(bgp->config, BGP_CONFIG_CONFEDERATION))
9008 vty_out(vty, "confed-internal link\n");
9009 else
9010 vty_out(vty, "internal link\n");
9011 }
9012 } else {
9013 if (use_json) {
9014 if (CHECK_FLAG(bgp->config, BGP_CONFIG_CONFEDERATION))
9015 json_object_boolean_true_add(
9016 json_neigh, "nbrConfedExternalLink");
9017 else
9018 json_object_boolean_true_add(json_neigh,
9019 "nbrExternalLink");
9020 } else {
9021 if (bgp_confederation_peers_check(bgp, p->as))
9022 vty_out(vty, "confed-external link\n");
9023 else
9024 vty_out(vty, "external link\n");
9025 }
9026 }
9027
9028 /* Description. */
9029 if (p->desc) {
9030 if (use_json)
9031 json_object_string_add(json_neigh, "nbrDesc", p->desc);
9032 else
9033 vty_out(vty, " Description: %s\n", p->desc);
9034 }
9035
9036 if (p->hostname) {
9037 if (use_json) {
9038 if (p->hostname)
9039 json_object_string_add(json_neigh, "hostname",
9040 p->hostname);
9041
9042 if (p->domainname)
9043 json_object_string_add(json_neigh, "domainname",
9044 p->domainname);
9045 } else {
9046 if (p->domainname && (p->domainname[0] != '\0'))
9047 vty_out(vty, "Hostname: %s.%s\n", p->hostname,
9048 p->domainname);
9049 else
9050 vty_out(vty, "Hostname: %s\n", p->hostname);
9051 }
9052 }
9053
9054 /* Peer-group */
9055 if (p->group) {
9056 if (use_json) {
9057 json_object_string_add(json_neigh, "peerGroup",
9058 p->group->name);
9059
9060 if (dn_flag[0]) {
9061 struct prefix prefix, *range = NULL;
9062
9063 sockunion2hostprefix(&(p->su), &prefix);
9064 range = peer_group_lookup_dynamic_neighbor_range(
9065 p->group, &prefix);
9066
9067 if (range) {
9068 prefix2str(range, buf1, sizeof(buf1));
9069 json_object_string_add(
9070 json_neigh,
9071 "peerSubnetRangeGroup", buf1);
9072 }
9073 }
9074 } else {
9075 vty_out(vty,
9076 " Member of peer-group %s for session parameters\n",
9077 p->group->name);
9078
9079 if (dn_flag[0]) {
9080 struct prefix prefix, *range = NULL;
9081
9082 sockunion2hostprefix(&(p->su), &prefix);
9083 range = peer_group_lookup_dynamic_neighbor_range(
9084 p->group, &prefix);
9085
9086 if (range) {
9087 prefix2str(range, buf1, sizeof(buf1));
9088 vty_out(vty,
9089 " Belongs to the subnet range group: %s\n",
9090 buf1);
9091 }
9092 }
9093 }
9094 }
9095
9096 if (use_json) {
9097 /* Administrative shutdown. */
9098 if (CHECK_FLAG(p->flags, PEER_FLAG_SHUTDOWN))
9099 json_object_boolean_true_add(json_neigh,
9100 "adminShutDown");
9101
9102 /* BGP Version. */
9103 json_object_int_add(json_neigh, "bgpVersion", 4);
9104 json_object_string_add(
9105 json_neigh, "remoteRouterId",
9106 inet_ntop(AF_INET, &p->remote_id, buf1, sizeof(buf1)));
9107
9108 /* Confederation */
9109 if (CHECK_FLAG(bgp->config, BGP_CONFIG_CONFEDERATION)
9110 && bgp_confederation_peers_check(bgp, p->as))
9111 json_object_boolean_true_add(json_neigh,
9112 "nbrCommonAdmin");
9113
9114 /* Status. */
9115 json_object_string_add(
9116 json_neigh, "bgpState",
9117 lookup_msg(bgp_status_msg, p->status, NULL));
9118
9119 if (p->status == Established) {
9120 time_t uptime;
9121
9122 uptime = bgp_clock();
9123 uptime -= p->uptime;
9124 epoch_tbuf = time(NULL) - uptime;
9125
9126 #if defined(VERSION_TYPE_DEV) && CONFDATE > 20200101
9127 CPP_NOTICE(
9128 "bgpTimerUp should be deprecated and can be removed now");
9129 #endif
9130 /*
9131 * bgpTimerUp was miliseconds that was accurate
9132 * up to 1 day, then the value returned
9133 * became garbage. So in order to provide
9134 * some level of backwards compatability,
9135 * we still provde the data, but now
9136 * we are returning the correct value
9137 * and also adding a new bgpTimerUpMsec
9138 * which will allow us to deprecate
9139 * this eventually
9140 */
9141 json_object_int_add(json_neigh, "bgpTimerUp",
9142 uptime * 1000);
9143 json_object_int_add(json_neigh, "bgpTimerUpMsec",
9144 uptime * 1000);
9145 json_object_string_add(json_neigh, "bgpTimerUpString",
9146 peer_uptime(p->uptime, timebuf,
9147 BGP_UPTIME_LEN, 0,
9148 NULL));
9149 json_object_int_add(json_neigh,
9150 "bgpTimerUpEstablishedEpoch",
9151 epoch_tbuf);
9152 }
9153
9154 else if (p->status == Active) {
9155 if (CHECK_FLAG(p->flags, PEER_FLAG_PASSIVE))
9156 json_object_string_add(json_neigh, "bgpStateIs",
9157 "passive");
9158 else if (CHECK_FLAG(p->sflags, PEER_STATUS_NSF_WAIT))
9159 json_object_string_add(json_neigh, "bgpStateIs",
9160 "passiveNSF");
9161 }
9162
9163 /* read timer */
9164 time_t uptime;
9165 struct tm *tm;
9166
9167 uptime = bgp_clock();
9168 uptime -= p->readtime;
9169 tm = gmtime(&uptime);
9170 json_object_int_add(json_neigh, "bgpTimerLastRead",
9171 (tm->tm_sec * 1000) + (tm->tm_min * 60000)
9172 + (tm->tm_hour * 3600000));
9173
9174 uptime = bgp_clock();
9175 uptime -= p->last_write;
9176 tm = gmtime(&uptime);
9177 json_object_int_add(json_neigh, "bgpTimerLastWrite",
9178 (tm->tm_sec * 1000) + (tm->tm_min * 60000)
9179 + (tm->tm_hour * 3600000));
9180
9181 uptime = bgp_clock();
9182 uptime -= p->update_time;
9183 tm = gmtime(&uptime);
9184 json_object_int_add(json_neigh, "bgpInUpdateElapsedTimeMsecs",
9185 (tm->tm_sec * 1000) + (tm->tm_min * 60000)
9186 + (tm->tm_hour * 3600000));
9187
9188 /* Configured timer values. */
9189 json_object_int_add(json_neigh, "bgpTimerHoldTimeMsecs",
9190 p->v_holdtime * 1000);
9191 json_object_int_add(json_neigh,
9192 "bgpTimerKeepAliveIntervalMsecs",
9193 p->v_keepalive * 1000);
9194
9195 if (PEER_OR_GROUP_TIMER_SET(p)) {
9196 json_object_int_add(json_neigh,
9197 "bgpTimerConfiguredHoldTimeMsecs",
9198 p->holdtime * 1000);
9199 json_object_int_add(
9200 json_neigh,
9201 "bgpTimerConfiguredKeepAliveIntervalMsecs",
9202 p->keepalive * 1000);
9203 } else if ((bgp->default_holdtime != BGP_DEFAULT_HOLDTIME)
9204 || (bgp->default_keepalive
9205 != BGP_DEFAULT_KEEPALIVE)) {
9206 json_object_int_add(json_neigh,
9207 "bgpTimerConfiguredHoldTimeMsecs",
9208 bgp->default_holdtime);
9209 json_object_int_add(
9210 json_neigh,
9211 "bgpTimerConfiguredKeepAliveIntervalMsecs",
9212 bgp->default_keepalive);
9213 }
9214 } else {
9215 /* Administrative shutdown. */
9216 if (CHECK_FLAG(p->flags, PEER_FLAG_SHUTDOWN))
9217 vty_out(vty, " Administratively shut down\n");
9218
9219 /* BGP Version. */
9220 vty_out(vty, " BGP version 4");
9221 vty_out(vty, ", remote router ID %s\n",
9222 inet_ntop(AF_INET, &p->remote_id, buf1, sizeof(buf1)));
9223
9224 /* Confederation */
9225 if (CHECK_FLAG(bgp->config, BGP_CONFIG_CONFEDERATION)
9226 && bgp_confederation_peers_check(bgp, p->as))
9227 vty_out(vty,
9228 " Neighbor under common administration\n");
9229
9230 /* Status. */
9231 vty_out(vty, " BGP state = %s",
9232 lookup_msg(bgp_status_msg, p->status, NULL));
9233
9234 if (p->status == Established)
9235 vty_out(vty, ", up for %8s",
9236 peer_uptime(p->uptime, timebuf, BGP_UPTIME_LEN,
9237 0, NULL));
9238
9239 else if (p->status == Active) {
9240 if (CHECK_FLAG(p->flags, PEER_FLAG_PASSIVE))
9241 vty_out(vty, " (passive)");
9242 else if (CHECK_FLAG(p->sflags, PEER_STATUS_NSF_WAIT))
9243 vty_out(vty, " (NSF passive)");
9244 }
9245 vty_out(vty, "\n");
9246
9247 /* read timer */
9248 vty_out(vty, " Last read %s",
9249 peer_uptime(p->readtime, timebuf, BGP_UPTIME_LEN, 0,
9250 NULL));
9251 vty_out(vty, ", Last write %s\n",
9252 peer_uptime(p->last_write, timebuf, BGP_UPTIME_LEN, 0,
9253 NULL));
9254
9255 /* Configured timer values. */
9256 vty_out(vty,
9257 " Hold time is %d, keepalive interval is %d seconds\n",
9258 p->v_holdtime, p->v_keepalive);
9259 if (PEER_OR_GROUP_TIMER_SET(p)) {
9260 vty_out(vty, " Configured hold time is %d",
9261 p->holdtime);
9262 vty_out(vty, ", keepalive interval is %d seconds\n",
9263 p->keepalive);
9264 } else if ((bgp->default_holdtime != BGP_DEFAULT_HOLDTIME)
9265 || (bgp->default_keepalive
9266 != BGP_DEFAULT_KEEPALIVE)) {
9267 vty_out(vty, " Configured hold time is %d",
9268 bgp->default_holdtime);
9269 vty_out(vty, ", keepalive interval is %d seconds\n",
9270 bgp->default_keepalive);
9271 }
9272 }
9273 /* Capability. */
9274 if (p->status == Established) {
9275 if (p->cap || p->afc_adv[AFI_IP][SAFI_UNICAST]
9276 || p->afc_recv[AFI_IP][SAFI_UNICAST]
9277 || p->afc_adv[AFI_IP][SAFI_MULTICAST]
9278 || p->afc_recv[AFI_IP][SAFI_MULTICAST]
9279 || p->afc_adv[AFI_IP6][SAFI_UNICAST]
9280 || p->afc_recv[AFI_IP6][SAFI_UNICAST]
9281 || p->afc_adv[AFI_IP6][SAFI_MULTICAST]
9282 || p->afc_recv[AFI_IP6][SAFI_MULTICAST]
9283 || p->afc_adv[AFI_IP6][SAFI_MPLS_VPN]
9284 || p->afc_recv[AFI_IP6][SAFI_MPLS_VPN]
9285 || p->afc_adv[AFI_IP6][SAFI_ENCAP]
9286 || p->afc_recv[AFI_IP6][SAFI_ENCAP]
9287 || p->afc_adv[AFI_IP6][SAFI_FLOWSPEC]
9288 || p->afc_recv[AFI_IP6][SAFI_FLOWSPEC]
9289 || p->afc_adv[AFI_IP][SAFI_ENCAP]
9290 || p->afc_recv[AFI_IP][SAFI_ENCAP]
9291 || p->afc_adv[AFI_IP][SAFI_FLOWSPEC]
9292 || p->afc_recv[AFI_IP][SAFI_FLOWSPEC]
9293 || p->afc_adv[AFI_IP][SAFI_MPLS_VPN]
9294 || p->afc_recv[AFI_IP][SAFI_MPLS_VPN]) {
9295 if (use_json) {
9296 json_object *json_cap = NULL;
9297
9298 json_cap = json_object_new_object();
9299
9300 /* AS4 */
9301 if (CHECK_FLAG(p->cap, PEER_CAP_AS4_RCV)
9302 || CHECK_FLAG(p->cap, PEER_CAP_AS4_ADV)) {
9303 if (CHECK_FLAG(p->cap, PEER_CAP_AS4_ADV)
9304 && CHECK_FLAG(p->cap,
9305 PEER_CAP_AS4_RCV))
9306 json_object_string_add(
9307 json_cap, "4byteAs",
9308 "advertisedAndReceived");
9309 else if (CHECK_FLAG(p->cap,
9310 PEER_CAP_AS4_ADV))
9311 json_object_string_add(
9312 json_cap, "4byteAs",
9313 "advertised");
9314 else if (CHECK_FLAG(p->cap,
9315 PEER_CAP_AS4_RCV))
9316 json_object_string_add(
9317 json_cap, "4byteAs",
9318 "received");
9319 }
9320
9321 /* AddPath */
9322 if (CHECK_FLAG(p->cap, PEER_CAP_ADDPATH_RCV)
9323 || CHECK_FLAG(p->cap,
9324 PEER_CAP_ADDPATH_ADV)) {
9325 json_object *json_add = NULL;
9326 const char *print_store;
9327
9328 json_add = json_object_new_object();
9329
9330 FOREACH_AFI_SAFI (afi, safi) {
9331 json_object *json_sub = NULL;
9332 json_sub =
9333 json_object_new_object();
9334 print_store = afi_safi_print(
9335 afi, safi);
9336
9337 if (CHECK_FLAG(
9338 p->af_cap[afi]
9339 [safi],
9340 PEER_CAP_ADDPATH_AF_TX_ADV)
9341 || CHECK_FLAG(
9342 p->af_cap[afi]
9343 [safi],
9344 PEER_CAP_ADDPATH_AF_TX_RCV)) {
9345 if (CHECK_FLAG(
9346 p->af_cap
9347 [afi]
9348 [safi],
9349 PEER_CAP_ADDPATH_AF_TX_ADV)
9350 && CHECK_FLAG(
9351 p->af_cap
9352 [afi]
9353 [safi],
9354 PEER_CAP_ADDPATH_AF_TX_RCV))
9355 json_object_boolean_true_add(
9356 json_sub,
9357 "txAdvertisedAndReceived");
9358 else if (
9359 CHECK_FLAG(
9360 p->af_cap
9361 [afi]
9362 [safi],
9363 PEER_CAP_ADDPATH_AF_TX_ADV))
9364 json_object_boolean_true_add(
9365 json_sub,
9366 "txAdvertised");
9367 else if (
9368 CHECK_FLAG(
9369 p->af_cap
9370 [afi]
9371 [safi],
9372 PEER_CAP_ADDPATH_AF_TX_RCV))
9373 json_object_boolean_true_add(
9374 json_sub,
9375 "txReceived");
9376 }
9377
9378 if (CHECK_FLAG(
9379 p->af_cap[afi]
9380 [safi],
9381 PEER_CAP_ADDPATH_AF_RX_ADV)
9382 || CHECK_FLAG(
9383 p->af_cap[afi]
9384 [safi],
9385 PEER_CAP_ADDPATH_AF_RX_RCV)) {
9386 if (CHECK_FLAG(
9387 p->af_cap
9388 [afi]
9389 [safi],
9390 PEER_CAP_ADDPATH_AF_RX_ADV)
9391 && CHECK_FLAG(
9392 p->af_cap
9393 [afi]
9394 [safi],
9395 PEER_CAP_ADDPATH_AF_RX_RCV))
9396 json_object_boolean_true_add(
9397 json_sub,
9398 "rxAdvertisedAndReceived");
9399 else if (
9400 CHECK_FLAG(
9401 p->af_cap
9402 [afi]
9403 [safi],
9404 PEER_CAP_ADDPATH_AF_RX_ADV))
9405 json_object_boolean_true_add(
9406 json_sub,
9407 "rxAdvertised");
9408 else if (
9409 CHECK_FLAG(
9410 p->af_cap
9411 [afi]
9412 [safi],
9413 PEER_CAP_ADDPATH_AF_RX_RCV))
9414 json_object_boolean_true_add(
9415 json_sub,
9416 "rxReceived");
9417 }
9418
9419 if (CHECK_FLAG(
9420 p->af_cap[afi]
9421 [safi],
9422 PEER_CAP_ADDPATH_AF_TX_ADV)
9423 || CHECK_FLAG(
9424 p->af_cap[afi]
9425 [safi],
9426 PEER_CAP_ADDPATH_AF_TX_RCV)
9427 || CHECK_FLAG(
9428 p->af_cap[afi]
9429 [safi],
9430 PEER_CAP_ADDPATH_AF_RX_ADV)
9431 || CHECK_FLAG(
9432 p->af_cap[afi]
9433 [safi],
9434 PEER_CAP_ADDPATH_AF_RX_RCV))
9435 json_object_object_add(
9436 json_add,
9437 print_store,
9438 json_sub);
9439 else
9440 json_object_free(
9441 json_sub);
9442 }
9443
9444 json_object_object_add(
9445 json_cap, "addPath", json_add);
9446 }
9447
9448 /* Dynamic */
9449 if (CHECK_FLAG(p->cap, PEER_CAP_DYNAMIC_RCV)
9450 || CHECK_FLAG(p->cap,
9451 PEER_CAP_DYNAMIC_ADV)) {
9452 if (CHECK_FLAG(p->cap,
9453 PEER_CAP_DYNAMIC_ADV)
9454 && CHECK_FLAG(p->cap,
9455 PEER_CAP_DYNAMIC_RCV))
9456 json_object_string_add(
9457 json_cap, "dynamic",
9458 "advertisedAndReceived");
9459 else if (CHECK_FLAG(
9460 p->cap,
9461 PEER_CAP_DYNAMIC_ADV))
9462 json_object_string_add(
9463 json_cap, "dynamic",
9464 "advertised");
9465 else if (CHECK_FLAG(
9466 p->cap,
9467 PEER_CAP_DYNAMIC_RCV))
9468 json_object_string_add(
9469 json_cap, "dynamic",
9470 "received");
9471 }
9472
9473 /* Extended nexthop */
9474 if (CHECK_FLAG(p->cap, PEER_CAP_ENHE_RCV)
9475 || CHECK_FLAG(p->cap, PEER_CAP_ENHE_ADV)) {
9476 json_object *json_nxt = NULL;
9477 const char *print_store;
9478
9479
9480 if (CHECK_FLAG(p->cap,
9481 PEER_CAP_ENHE_ADV)
9482 && CHECK_FLAG(p->cap,
9483 PEER_CAP_ENHE_RCV))
9484 json_object_string_add(
9485 json_cap,
9486 "extendedNexthop",
9487 "advertisedAndReceived");
9488 else if (CHECK_FLAG(p->cap,
9489 PEER_CAP_ENHE_ADV))
9490 json_object_string_add(
9491 json_cap,
9492 "extendedNexthop",
9493 "advertised");
9494 else if (CHECK_FLAG(p->cap,
9495 PEER_CAP_ENHE_RCV))
9496 json_object_string_add(
9497 json_cap,
9498 "extendedNexthop",
9499 "received");
9500
9501 if (CHECK_FLAG(p->cap,
9502 PEER_CAP_ENHE_RCV)) {
9503 json_nxt =
9504 json_object_new_object();
9505
9506 for (safi = SAFI_UNICAST;
9507 safi < SAFI_MAX; safi++) {
9508 if (CHECK_FLAG(
9509 p->af_cap
9510 [AFI_IP]
9511 [safi],
9512 PEER_CAP_ENHE_AF_RCV)) {
9513 print_store = afi_safi_print(
9514 AFI_IP,
9515 safi);
9516 json_object_string_add(
9517 json_nxt,
9518 print_store,
9519 "recieved");
9520 }
9521 }
9522 json_object_object_add(
9523 json_cap,
9524 "extendedNexthopFamililesByPeer",
9525 json_nxt);
9526 }
9527 }
9528
9529 /* Route Refresh */
9530 if (CHECK_FLAG(p->cap, PEER_CAP_REFRESH_ADV)
9531 || CHECK_FLAG(p->cap,
9532 PEER_CAP_REFRESH_NEW_RCV)
9533 || CHECK_FLAG(p->cap,
9534 PEER_CAP_REFRESH_OLD_RCV)) {
9535 if (CHECK_FLAG(p->cap,
9536 PEER_CAP_REFRESH_ADV)
9537 && (CHECK_FLAG(
9538 p->cap,
9539 PEER_CAP_REFRESH_NEW_RCV)
9540 || CHECK_FLAG(
9541 p->cap,
9542 PEER_CAP_REFRESH_OLD_RCV))) {
9543 if (CHECK_FLAG(
9544 p->cap,
9545 PEER_CAP_REFRESH_OLD_RCV)
9546 && CHECK_FLAG(
9547 p->cap,
9548 PEER_CAP_REFRESH_NEW_RCV))
9549 json_object_string_add(
9550 json_cap,
9551 "routeRefresh",
9552 "advertisedAndReceivedOldNew");
9553 else {
9554 if (CHECK_FLAG(
9555 p->cap,
9556 PEER_CAP_REFRESH_OLD_RCV))
9557 json_object_string_add(
9558 json_cap,
9559 "routeRefresh",
9560 "advertisedAndReceivedOld");
9561 else
9562 json_object_string_add(
9563 json_cap,
9564 "routeRefresh",
9565 "advertisedAndReceivedNew");
9566 }
9567 } else if (
9568 CHECK_FLAG(
9569 p->cap,
9570 PEER_CAP_REFRESH_ADV))
9571 json_object_string_add(
9572 json_cap,
9573 "routeRefresh",
9574 "advertised");
9575 else if (
9576 CHECK_FLAG(
9577 p->cap,
9578 PEER_CAP_REFRESH_NEW_RCV)
9579 || CHECK_FLAG(
9580 p->cap,
9581 PEER_CAP_REFRESH_OLD_RCV))
9582 json_object_string_add(
9583 json_cap,
9584 "routeRefresh",
9585 "received");
9586 }
9587
9588 /* Multiprotocol Extensions */
9589 json_object *json_multi = NULL;
9590 json_multi = json_object_new_object();
9591
9592 FOREACH_AFI_SAFI (afi, safi) {
9593 if (p->afc_adv[afi][safi]
9594 || p->afc_recv[afi][safi]) {
9595 json_object *json_exten = NULL;
9596 json_exten =
9597 json_object_new_object();
9598
9599 if (p->afc_adv[afi][safi]
9600 && p->afc_recv[afi][safi])
9601 json_object_boolean_true_add(
9602 json_exten,
9603 "advertisedAndReceived");
9604 else if (p->afc_adv[afi][safi])
9605 json_object_boolean_true_add(
9606 json_exten,
9607 "advertised");
9608 else if (p->afc_recv[afi][safi])
9609 json_object_boolean_true_add(
9610 json_exten,
9611 "received");
9612
9613 json_object_object_add(
9614 json_multi,
9615 afi_safi_print(afi,
9616 safi),
9617 json_exten);
9618 }
9619 }
9620 json_object_object_add(
9621 json_cap, "multiprotocolExtensions",
9622 json_multi);
9623
9624 /* Hostname capabilities */
9625 json_object *json_hname = NULL;
9626
9627 json_hname = json_object_new_object();
9628
9629 if (CHECK_FLAG(p->cap, PEER_CAP_HOSTNAME_ADV)) {
9630 json_object_string_add(
9631 json_hname, "advHostName",
9632 bgp->peer_self->hostname
9633 ? bgp->peer_self
9634 ->hostname
9635 : "n/a");
9636 json_object_string_add(
9637 json_hname, "advDomainName",
9638 bgp->peer_self->domainname
9639 ? bgp->peer_self
9640 ->domainname
9641 : "n/a");
9642 }
9643
9644
9645 if (CHECK_FLAG(p->cap, PEER_CAP_HOSTNAME_RCV)) {
9646 json_object_string_add(
9647 json_hname, "rcvHostName",
9648 p->hostname ? p->hostname
9649 : "n/a");
9650 json_object_string_add(
9651 json_hname, "rcvDomainName",
9652 p->domainname ? p->domainname
9653 : "n/a");
9654 }
9655
9656 json_object_object_add(json_cap, "hostName",
9657 json_hname);
9658
9659 /* Gracefull Restart */
9660 if (CHECK_FLAG(p->cap, PEER_CAP_RESTART_RCV)
9661 || CHECK_FLAG(p->cap,
9662 PEER_CAP_RESTART_ADV)) {
9663 if (CHECK_FLAG(p->cap,
9664 PEER_CAP_RESTART_ADV)
9665 && CHECK_FLAG(p->cap,
9666 PEER_CAP_RESTART_RCV))
9667 json_object_string_add(
9668 json_cap,
9669 "gracefulRestart",
9670 "advertisedAndReceived");
9671 else if (CHECK_FLAG(
9672 p->cap,
9673 PEER_CAP_RESTART_ADV))
9674 json_object_string_add(
9675 json_cap,
9676 "gracefulRestartCapability",
9677 "advertised");
9678 else if (CHECK_FLAG(
9679 p->cap,
9680 PEER_CAP_RESTART_RCV))
9681 json_object_string_add(
9682 json_cap,
9683 "gracefulRestartCapability",
9684 "received");
9685
9686 if (CHECK_FLAG(p->cap,
9687 PEER_CAP_RESTART_RCV)) {
9688 int restart_af_count = 0;
9689 json_object *json_restart =
9690 NULL;
9691 json_restart =
9692 json_object_new_object();
9693
9694 json_object_int_add(
9695 json_cap,
9696 "gracefulRestartRemoteTimerMsecs",
9697 p->v_gr_restart * 1000);
9698
9699 FOREACH_AFI_SAFI (afi, safi) {
9700 if (CHECK_FLAG(
9701 p->af_cap
9702 [afi]
9703 [safi],
9704 PEER_CAP_RESTART_AF_RCV)) {
9705 json_object *
9706 json_sub =
9707 NULL;
9708 json_sub =
9709 json_object_new_object();
9710
9711 if (CHECK_FLAG(
9712 p->af_cap
9713 [afi]
9714 [safi],
9715 PEER_CAP_RESTART_AF_PRESERVE_RCV))
9716 json_object_boolean_true_add(
9717 json_sub,
9718 "preserved");
9719 restart_af_count++;
9720 json_object_object_add(
9721 json_restart,
9722 afi_safi_print(
9723 afi,
9724 safi),
9725 json_sub);
9726 }
9727 }
9728 if (!restart_af_count) {
9729 json_object_string_add(
9730 json_cap,
9731 "addressFamiliesByPeer",
9732 "none");
9733 json_object_free(
9734 json_restart);
9735 } else
9736 json_object_object_add(
9737 json_cap,
9738 "addressFamiliesByPeer",
9739 json_restart);
9740 }
9741 }
9742 json_object_object_add(json_neigh,
9743 "neighborCapabilities",
9744 json_cap);
9745 } else {
9746 vty_out(vty, " Neighbor capabilities:\n");
9747
9748 /* AS4 */
9749 if (CHECK_FLAG(p->cap, PEER_CAP_AS4_RCV)
9750 || CHECK_FLAG(p->cap, PEER_CAP_AS4_ADV)) {
9751 vty_out(vty, " 4 Byte AS:");
9752 if (CHECK_FLAG(p->cap,
9753 PEER_CAP_AS4_ADV))
9754 vty_out(vty, " advertised");
9755 if (CHECK_FLAG(p->cap,
9756 PEER_CAP_AS4_RCV))
9757 vty_out(vty, " %sreceived",
9758 CHECK_FLAG(
9759 p->cap,
9760 PEER_CAP_AS4_ADV)
9761 ? "and "
9762 : "");
9763 vty_out(vty, "\n");
9764 }
9765
9766 /* AddPath */
9767 if (CHECK_FLAG(p->cap, PEER_CAP_ADDPATH_RCV)
9768 || CHECK_FLAG(p->cap,
9769 PEER_CAP_ADDPATH_ADV)) {
9770 vty_out(vty, " AddPath:\n");
9771
9772 FOREACH_AFI_SAFI (afi, safi) {
9773 if (CHECK_FLAG(
9774 p->af_cap[afi]
9775 [safi],
9776 PEER_CAP_ADDPATH_AF_TX_ADV)
9777 || CHECK_FLAG(
9778 p->af_cap[afi]
9779 [safi],
9780 PEER_CAP_ADDPATH_AF_TX_RCV)) {
9781 vty_out(vty,
9782 " %s: TX ",
9783 afi_safi_print(
9784 afi,
9785 safi));
9786
9787 if (CHECK_FLAG(
9788 p->af_cap
9789 [afi]
9790 [safi],
9791 PEER_CAP_ADDPATH_AF_TX_ADV))
9792 vty_out(vty,
9793 "advertised %s",
9794 afi_safi_print(
9795 afi,
9796 safi));
9797
9798 if (CHECK_FLAG(
9799 p->af_cap
9800 [afi]
9801 [safi],
9802 PEER_CAP_ADDPATH_AF_TX_RCV))
9803 vty_out(vty,
9804 "%sreceived",
9805 CHECK_FLAG(
9806 p->af_cap
9807 [afi]
9808 [safi],
9809 PEER_CAP_ADDPATH_AF_TX_ADV)
9810 ? " and "
9811 : "");
9812
9813 vty_out(vty, "\n");
9814 }
9815
9816 if (CHECK_FLAG(
9817 p->af_cap[afi]
9818 [safi],
9819 PEER_CAP_ADDPATH_AF_RX_ADV)
9820 || CHECK_FLAG(
9821 p->af_cap[afi]
9822 [safi],
9823 PEER_CAP_ADDPATH_AF_RX_RCV)) {
9824 vty_out(vty,
9825 " %s: RX ",
9826 afi_safi_print(
9827 afi,
9828 safi));
9829
9830 if (CHECK_FLAG(
9831 p->af_cap
9832 [afi]
9833 [safi],
9834 PEER_CAP_ADDPATH_AF_RX_ADV))
9835 vty_out(vty,
9836 "advertised %s",
9837 afi_safi_print(
9838 afi,
9839 safi));
9840
9841 if (CHECK_FLAG(
9842 p->af_cap
9843 [afi]
9844 [safi],
9845 PEER_CAP_ADDPATH_AF_RX_RCV))
9846 vty_out(vty,
9847 "%sreceived",
9848 CHECK_FLAG(
9849 p->af_cap
9850 [afi]
9851 [safi],
9852 PEER_CAP_ADDPATH_AF_RX_ADV)
9853 ? " and "
9854 : "");
9855
9856 vty_out(vty, "\n");
9857 }
9858 }
9859 }
9860
9861 /* Dynamic */
9862 if (CHECK_FLAG(p->cap, PEER_CAP_DYNAMIC_RCV)
9863 || CHECK_FLAG(p->cap,
9864 PEER_CAP_DYNAMIC_ADV)) {
9865 vty_out(vty, " Dynamic:");
9866 if (CHECK_FLAG(p->cap,
9867 PEER_CAP_DYNAMIC_ADV))
9868 vty_out(vty, " advertised");
9869 if (CHECK_FLAG(p->cap,
9870 PEER_CAP_DYNAMIC_RCV))
9871 vty_out(vty, " %sreceived",
9872 CHECK_FLAG(
9873 p->cap,
9874 PEER_CAP_DYNAMIC_ADV)
9875 ? "and "
9876 : "");
9877 vty_out(vty, "\n");
9878 }
9879
9880 /* Extended nexthop */
9881 if (CHECK_FLAG(p->cap, PEER_CAP_ENHE_RCV)
9882 || CHECK_FLAG(p->cap, PEER_CAP_ENHE_ADV)) {
9883 vty_out(vty, " Extended nexthop:");
9884 if (CHECK_FLAG(p->cap,
9885 PEER_CAP_ENHE_ADV))
9886 vty_out(vty, " advertised");
9887 if (CHECK_FLAG(p->cap,
9888 PEER_CAP_ENHE_RCV))
9889 vty_out(vty, " %sreceived",
9890 CHECK_FLAG(
9891 p->cap,
9892 PEER_CAP_ENHE_ADV)
9893 ? "and "
9894 : "");
9895 vty_out(vty, "\n");
9896
9897 if (CHECK_FLAG(p->cap,
9898 PEER_CAP_ENHE_RCV)) {
9899 vty_out(vty,
9900 " Address families by peer:\n ");
9901 for (safi = SAFI_UNICAST;
9902 safi < SAFI_MAX; safi++)
9903 if (CHECK_FLAG(
9904 p->af_cap
9905 [AFI_IP]
9906 [safi],
9907 PEER_CAP_ENHE_AF_RCV))
9908 vty_out(vty,
9909 " %s\n",
9910 afi_safi_print(
9911 AFI_IP,
9912 safi));
9913 }
9914 }
9915
9916 /* Route Refresh */
9917 if (CHECK_FLAG(p->cap, PEER_CAP_REFRESH_ADV)
9918 || CHECK_FLAG(p->cap,
9919 PEER_CAP_REFRESH_NEW_RCV)
9920 || CHECK_FLAG(p->cap,
9921 PEER_CAP_REFRESH_OLD_RCV)) {
9922 vty_out(vty, " Route refresh:");
9923 if (CHECK_FLAG(p->cap,
9924 PEER_CAP_REFRESH_ADV))
9925 vty_out(vty, " advertised");
9926 if (CHECK_FLAG(p->cap,
9927 PEER_CAP_REFRESH_NEW_RCV)
9928 || CHECK_FLAG(
9929 p->cap,
9930 PEER_CAP_REFRESH_OLD_RCV))
9931 vty_out(vty, " %sreceived(%s)",
9932 CHECK_FLAG(
9933 p->cap,
9934 PEER_CAP_REFRESH_ADV)
9935 ? "and "
9936 : "",
9937 (CHECK_FLAG(
9938 p->cap,
9939 PEER_CAP_REFRESH_OLD_RCV)
9940 && CHECK_FLAG(
9941 p->cap,
9942 PEER_CAP_REFRESH_NEW_RCV))
9943 ? "old & new"
9944 : CHECK_FLAG(
9945 p->cap,
9946 PEER_CAP_REFRESH_OLD_RCV)
9947 ? "old"
9948 : "new");
9949
9950 vty_out(vty, "\n");
9951 }
9952
9953 /* Multiprotocol Extensions */
9954 FOREACH_AFI_SAFI (afi, safi)
9955 if (p->afc_adv[afi][safi]
9956 || p->afc_recv[afi][safi]) {
9957 vty_out(vty,
9958 " Address Family %s:",
9959 afi_safi_print(afi,
9960 safi));
9961 if (p->afc_adv[afi][safi])
9962 vty_out(vty,
9963 " advertised");
9964 if (p->afc_recv[afi][safi])
9965 vty_out(vty,
9966 " %sreceived",
9967 p->afc_adv[afi]
9968 [safi]
9969 ? "and "
9970 : "");
9971 vty_out(vty, "\n");
9972 }
9973
9974 /* Hostname capability */
9975 vty_out(vty, " Hostname Capability:");
9976
9977 if (CHECK_FLAG(p->cap, PEER_CAP_HOSTNAME_ADV)) {
9978 vty_out(vty,
9979 " advertised (name: %s,domain name: %s)",
9980 bgp->peer_self->hostname
9981 ? bgp->peer_self
9982 ->hostname
9983 : "n/a",
9984 bgp->peer_self->domainname
9985 ? bgp->peer_self
9986 ->domainname
9987 : "n/a");
9988 } else {
9989 vty_out(vty, " not advertised");
9990 }
9991
9992 if (CHECK_FLAG(p->cap, PEER_CAP_HOSTNAME_RCV)) {
9993 vty_out(vty,
9994 " received (name: %s,domain name: %s)",
9995 p->hostname ? p->hostname
9996 : "n/a",
9997 p->domainname ? p->domainname
9998 : "n/a");
9999 } else {
10000 vty_out(vty, " not received");
10001 }
10002
10003 vty_out(vty, "\n");
10004
10005 /* Gracefull Restart */
10006 if (CHECK_FLAG(p->cap, PEER_CAP_RESTART_RCV)
10007 || CHECK_FLAG(p->cap,
10008 PEER_CAP_RESTART_ADV)) {
10009 vty_out(vty,
10010 " Graceful Restart Capabilty:");
10011 if (CHECK_FLAG(p->cap,
10012 PEER_CAP_RESTART_ADV))
10013 vty_out(vty, " advertised");
10014 if (CHECK_FLAG(p->cap,
10015 PEER_CAP_RESTART_RCV))
10016 vty_out(vty, " %sreceived",
10017 CHECK_FLAG(
10018 p->cap,
10019 PEER_CAP_RESTART_ADV)
10020 ? "and "
10021 : "");
10022 vty_out(vty, "\n");
10023
10024 if (CHECK_FLAG(p->cap,
10025 PEER_CAP_RESTART_RCV)) {
10026 int restart_af_count = 0;
10027
10028 vty_out(vty,
10029 " Remote Restart timer is %d seconds\n",
10030 p->v_gr_restart);
10031 vty_out(vty,
10032 " Address families by peer:\n ");
10033
10034 FOREACH_AFI_SAFI (afi, safi)
10035 if (CHECK_FLAG(
10036 p->af_cap
10037 [afi]
10038 [safi],
10039 PEER_CAP_RESTART_AF_RCV)) {
10040 vty_out(vty,
10041 "%s%s(%s)",
10042 restart_af_count
10043 ? ", "
10044 : "",
10045 afi_safi_print(
10046 afi,
10047 safi),
10048 CHECK_FLAG(
10049 p->af_cap
10050 [afi]
10051 [safi],
10052 PEER_CAP_RESTART_AF_PRESERVE_RCV)
10053 ? "preserved"
10054 : "not preserved");
10055 restart_af_count++;
10056 }
10057 if (!restart_af_count)
10058 vty_out(vty, "none");
10059 vty_out(vty, "\n");
10060 }
10061 }
10062 }
10063 }
10064 }
10065
10066 /* graceful restart information */
10067 if (CHECK_FLAG(p->cap, PEER_CAP_RESTART_RCV) || p->t_gr_restart
10068 || p->t_gr_stale) {
10069 json_object *json_grace = NULL;
10070 json_object *json_grace_send = NULL;
10071 json_object *json_grace_recv = NULL;
10072 int eor_send_af_count = 0;
10073 int eor_receive_af_count = 0;
10074
10075 if (use_json) {
10076 json_grace = json_object_new_object();
10077 json_grace_send = json_object_new_object();
10078 json_grace_recv = json_object_new_object();
10079
10080 if (p->status == Established) {
10081 FOREACH_AFI_SAFI (afi, safi) {
10082 if (CHECK_FLAG(p->af_sflags[afi][safi],
10083 PEER_STATUS_EOR_SEND)) {
10084 json_object_boolean_true_add(
10085 json_grace_send,
10086 afi_safi_print(afi,
10087 safi));
10088 eor_send_af_count++;
10089 }
10090 }
10091 FOREACH_AFI_SAFI (afi, safi) {
10092 if (CHECK_FLAG(
10093 p->af_sflags[afi][safi],
10094 PEER_STATUS_EOR_RECEIVED)) {
10095 json_object_boolean_true_add(
10096 json_grace_recv,
10097 afi_safi_print(afi,
10098 safi));
10099 eor_receive_af_count++;
10100 }
10101 }
10102 }
10103
10104 json_object_object_add(json_grace, "endOfRibSend",
10105 json_grace_send);
10106 json_object_object_add(json_grace, "endOfRibRecv",
10107 json_grace_recv);
10108
10109 if (p->t_gr_restart)
10110 json_object_int_add(json_grace,
10111 "gracefulRestartTimerMsecs",
10112 thread_timer_remain_second(
10113 p->t_gr_restart)
10114 * 1000);
10115
10116 if (p->t_gr_stale)
10117 json_object_int_add(
10118 json_grace,
10119 "gracefulStalepathTimerMsecs",
10120 thread_timer_remain_second(
10121 p->t_gr_stale)
10122 * 1000);
10123
10124 json_object_object_add(
10125 json_neigh, "gracefulRestartInfo", json_grace);
10126 } else {
10127 vty_out(vty, " Graceful restart informations:\n");
10128 if (p->status == Established) {
10129 vty_out(vty, " End-of-RIB send: ");
10130 FOREACH_AFI_SAFI (afi, safi) {
10131 if (CHECK_FLAG(p->af_sflags[afi][safi],
10132 PEER_STATUS_EOR_SEND)) {
10133 vty_out(vty, "%s%s",
10134 eor_send_af_count ? ", "
10135 : "",
10136 afi_safi_print(afi,
10137 safi));
10138 eor_send_af_count++;
10139 }
10140 }
10141 vty_out(vty, "\n");
10142 vty_out(vty, " End-of-RIB received: ");
10143 FOREACH_AFI_SAFI (afi, safi) {
10144 if (CHECK_FLAG(
10145 p->af_sflags[afi][safi],
10146 PEER_STATUS_EOR_RECEIVED)) {
10147 vty_out(vty, "%s%s",
10148 eor_receive_af_count
10149 ? ", "
10150 : "",
10151 afi_safi_print(afi,
10152 safi));
10153 eor_receive_af_count++;
10154 }
10155 }
10156 vty_out(vty, "\n");
10157 }
10158
10159 if (p->t_gr_restart)
10160 vty_out(vty,
10161 " The remaining time of restart timer is %ld\n",
10162 thread_timer_remain_second(
10163 p->t_gr_restart));
10164
10165 if (p->t_gr_stale)
10166 vty_out(vty,
10167 " The remaining time of stalepath timer is %ld\n",
10168 thread_timer_remain_second(
10169 p->t_gr_stale));
10170 }
10171 }
10172 if (use_json) {
10173 json_object *json_stat = NULL;
10174 json_stat = json_object_new_object();
10175 /* Packet counts. */
10176 json_object_int_add(json_stat, "depthInq", 0);
10177 json_object_int_add(json_stat, "depthOutq",
10178 (unsigned long)p->obuf->count);
10179 json_object_int_add(json_stat, "opensSent",
10180 atomic_load_explicit(&p->open_out,
10181 memory_order_relaxed));
10182 json_object_int_add(json_stat, "opensRecv",
10183 atomic_load_explicit(&p->open_in,
10184 memory_order_relaxed));
10185 json_object_int_add(json_stat, "notificationsSent",
10186 atomic_load_explicit(&p->notify_out,
10187 memory_order_relaxed));
10188 json_object_int_add(json_stat, "notificationsRecv",
10189 atomic_load_explicit(&p->notify_in,
10190 memory_order_relaxed));
10191 json_object_int_add(json_stat, "updatesSent",
10192 atomic_load_explicit(&p->update_out,
10193 memory_order_relaxed));
10194 json_object_int_add(json_stat, "updatesRecv",
10195 atomic_load_explicit(&p->update_in,
10196 memory_order_relaxed));
10197 json_object_int_add(json_stat, "keepalivesSent",
10198 atomic_load_explicit(&p->keepalive_out,
10199 memory_order_relaxed));
10200 json_object_int_add(json_stat, "keepalivesRecv",
10201 atomic_load_explicit(&p->keepalive_in,
10202 memory_order_relaxed));
10203 json_object_int_add(json_stat, "routeRefreshSent",
10204 atomic_load_explicit(&p->refresh_out,
10205 memory_order_relaxed));
10206 json_object_int_add(json_stat, "routeRefreshRecv",
10207 atomic_load_explicit(&p->refresh_in,
10208 memory_order_relaxed));
10209 json_object_int_add(json_stat, "capabilitySent",
10210 atomic_load_explicit(&p->dynamic_cap_out,
10211 memory_order_relaxed));
10212 json_object_int_add(json_stat, "capabilityRecv",
10213 atomic_load_explicit(&p->dynamic_cap_in,
10214 memory_order_relaxed));
10215 json_object_int_add(json_stat, "totalSent", PEER_TOTAL_TX(p));
10216 json_object_int_add(json_stat, "totalRecv", PEER_TOTAL_RX(p));
10217 json_object_object_add(json_neigh, "messageStats", json_stat);
10218 } else {
10219 /* Packet counts. */
10220 vty_out(vty, " Message statistics:\n");
10221 vty_out(vty, " Inq depth is 0\n");
10222 vty_out(vty, " Outq depth is %lu\n",
10223 (unsigned long)p->obuf->count);
10224 vty_out(vty, " Sent Rcvd\n");
10225 vty_out(vty, " Opens: %10d %10d\n",
10226 atomic_load_explicit(&p->open_out,
10227 memory_order_relaxed),
10228 atomic_load_explicit(&p->open_in,
10229 memory_order_relaxed));
10230 vty_out(vty, " Notifications: %10d %10d\n",
10231 atomic_load_explicit(&p->notify_out,
10232 memory_order_relaxed),
10233 atomic_load_explicit(&p->notify_in,
10234 memory_order_relaxed));
10235 vty_out(vty, " Updates: %10d %10d\n",
10236 atomic_load_explicit(&p->update_out,
10237 memory_order_relaxed),
10238 atomic_load_explicit(&p->update_in,
10239 memory_order_relaxed));
10240 vty_out(vty, " Keepalives: %10d %10d\n",
10241 atomic_load_explicit(&p->keepalive_out,
10242 memory_order_relaxed),
10243 atomic_load_explicit(&p->keepalive_in,
10244 memory_order_relaxed));
10245 vty_out(vty, " Route Refresh: %10d %10d\n",
10246 atomic_load_explicit(&p->refresh_out,
10247 memory_order_relaxed),
10248 atomic_load_explicit(&p->refresh_in,
10249 memory_order_relaxed));
10250 vty_out(vty, " Capability: %10d %10d\n",
10251 atomic_load_explicit(&p->dynamic_cap_out,
10252 memory_order_relaxed),
10253 atomic_load_explicit(&p->dynamic_cap_in,
10254 memory_order_relaxed));
10255 vty_out(vty, " Total: %10d %10d\n", PEER_TOTAL_TX(p),
10256 PEER_TOTAL_RX(p));
10257 }
10258
10259 if (use_json) {
10260 /* advertisement-interval */
10261 json_object_int_add(json_neigh,
10262 "minBtwnAdvertisementRunsTimerMsecs",
10263 p->v_routeadv * 1000);
10264
10265 /* Update-source. */
10266 if (p->update_if || p->update_source) {
10267 if (p->update_if)
10268 json_object_string_add(json_neigh,
10269 "updateSource",
10270 p->update_if);
10271 else if (p->update_source)
10272 json_object_string_add(
10273 json_neigh, "updateSource",
10274 sockunion2str(p->update_source, buf1,
10275 SU_ADDRSTRLEN));
10276 }
10277 } else {
10278 /* advertisement-interval */
10279 vty_out(vty,
10280 " Minimum time between advertisement runs is %d seconds\n",
10281 p->v_routeadv);
10282
10283 /* Update-source. */
10284 if (p->update_if || p->update_source) {
10285 vty_out(vty, " Update source is ");
10286 if (p->update_if)
10287 vty_out(vty, "%s", p->update_if);
10288 else if (p->update_source)
10289 vty_out(vty, "%s",
10290 sockunion2str(p->update_source, buf1,
10291 SU_ADDRSTRLEN));
10292 vty_out(vty, "\n");
10293 }
10294
10295 vty_out(vty, "\n");
10296 }
10297
10298 /* Address Family Information */
10299 json_object *json_hold = NULL;
10300
10301 if (use_json)
10302 json_hold = json_object_new_object();
10303
10304 FOREACH_AFI_SAFI (afi, safi)
10305 if (p->afc[afi][safi])
10306 bgp_show_peer_afi(vty, p, afi, safi, use_json,
10307 json_hold);
10308
10309 if (use_json) {
10310 json_object_object_add(json_neigh, "addressFamilyInfo",
10311 json_hold);
10312 json_object_int_add(json_neigh, "connectionsEstablished",
10313 p->established);
10314 json_object_int_add(json_neigh, "connectionsDropped",
10315 p->dropped);
10316 } else
10317 vty_out(vty, " Connections established %d; dropped %d\n",
10318 p->established, p->dropped);
10319
10320 if (!p->last_reset) {
10321 if (use_json)
10322 json_object_string_add(json_neigh, "lastReset",
10323 "never");
10324 else
10325 vty_out(vty, " Last reset never\n");
10326 } else {
10327 if (use_json) {
10328 time_t uptime;
10329 struct tm *tm;
10330
10331 uptime = bgp_clock();
10332 uptime -= p->resettime;
10333 tm = gmtime(&uptime);
10334 json_object_int_add(json_neigh, "lastResetTimerMsecs",
10335 (tm->tm_sec * 1000)
10336 + (tm->tm_min * 60000)
10337 + (tm->tm_hour * 3600000));
10338 json_object_string_add(
10339 json_neigh, "lastResetDueTo",
10340 peer_down_str[(int)p->last_reset]);
10341 if (p->last_reset == PEER_DOWN_NOTIFY_SEND
10342 || p->last_reset == PEER_DOWN_NOTIFY_RECEIVED) {
10343 char errorcodesubcode_hexstr[5];
10344 char errorcodesubcode_str[256];
10345
10346 code_str = bgp_notify_code_str(p->notify.code);
10347 subcode_str = bgp_notify_subcode_str(
10348 p->notify.code, p->notify.subcode);
10349
10350 sprintf(errorcodesubcode_hexstr, "%02X%02X",
10351 p->notify.code, p->notify.subcode);
10352 json_object_string_add(json_neigh,
10353 "lastErrorCodeSubcode",
10354 errorcodesubcode_hexstr);
10355 snprintf(errorcodesubcode_str, 255, "%s%s",
10356 code_str, subcode_str);
10357 json_object_string_add(json_neigh,
10358 "lastNotificationReason",
10359 errorcodesubcode_str);
10360 if (p->last_reset == PEER_DOWN_NOTIFY_RECEIVED
10361 && p->notify.code == BGP_NOTIFY_CEASE
10362 && (p->notify.subcode
10363 == BGP_NOTIFY_CEASE_ADMIN_SHUTDOWN
10364 || p->notify.subcode
10365 == BGP_NOTIFY_CEASE_ADMIN_RESET)
10366 && p->notify.length) {
10367 char msgbuf[1024];
10368 const char *msg_str;
10369
10370 msg_str = bgp_notify_admin_message(
10371 msgbuf, sizeof(msgbuf),
10372 (uint8_t *)p->notify.data,
10373 p->notify.length);
10374 if (msg_str)
10375 json_object_string_add(
10376 json_neigh,
10377 "lastShutdownDescription",
10378 msg_str);
10379 }
10380 }
10381 } else {
10382 vty_out(vty, " Last reset %s, ",
10383 peer_uptime(p->resettime, timebuf,
10384 BGP_UPTIME_LEN, 0, NULL));
10385
10386 if (p->last_reset == PEER_DOWN_NOTIFY_SEND
10387 || p->last_reset == PEER_DOWN_NOTIFY_RECEIVED) {
10388 code_str = bgp_notify_code_str(p->notify.code);
10389 subcode_str = bgp_notify_subcode_str(
10390 p->notify.code, p->notify.subcode);
10391 vty_out(vty, "due to NOTIFICATION %s (%s%s)\n",
10392 p->last_reset == PEER_DOWN_NOTIFY_SEND
10393 ? "sent"
10394 : "received",
10395 code_str, subcode_str);
10396 if (p->last_reset == PEER_DOWN_NOTIFY_RECEIVED
10397 && p->notify.code == BGP_NOTIFY_CEASE
10398 && (p->notify.subcode
10399 == BGP_NOTIFY_CEASE_ADMIN_SHUTDOWN
10400 || p->notify.subcode
10401 == BGP_NOTIFY_CEASE_ADMIN_RESET)
10402 && p->notify.length) {
10403 char msgbuf[1024];
10404 const char *msg_str;
10405
10406 msg_str = bgp_notify_admin_message(
10407 msgbuf, sizeof(msgbuf),
10408 (uint8_t *)p->notify.data,
10409 p->notify.length);
10410 if (msg_str)
10411 vty_out(vty,
10412 " Message: \"%s\"\n",
10413 msg_str);
10414 }
10415 } else {
10416 vty_out(vty, "due to %s\n",
10417 peer_down_str[(int)p->last_reset]);
10418 }
10419
10420 if (p->last_reset_cause_size) {
10421 msg = p->last_reset_cause;
10422 vty_out(vty,
10423 " Message received that caused BGP to send a NOTIFICATION:\n ");
10424 for (i = 1; i <= p->last_reset_cause_size;
10425 i++) {
10426 vty_out(vty, "%02X", *msg++);
10427
10428 if (i != p->last_reset_cause_size) {
10429 if (i % 16 == 0) {
10430 vty_out(vty, "\n ");
10431 } else if (i % 4 == 0) {
10432 vty_out(vty, " ");
10433 }
10434 }
10435 }
10436 vty_out(vty, "\n");
10437 }
10438 }
10439 }
10440
10441 if (CHECK_FLAG(p->sflags, PEER_STATUS_PREFIX_OVERFLOW)) {
10442 if (use_json)
10443 json_object_boolean_true_add(json_neigh,
10444 "prefixesConfigExceedMax");
10445 else
10446 vty_out(vty,
10447 " Peer had exceeded the max. no. of prefixes configured.\n");
10448
10449 if (p->t_pmax_restart) {
10450 if (use_json) {
10451 json_object_boolean_true_add(
10452 json_neigh, "reducePrefixNumFrom");
10453 json_object_int_add(json_neigh,
10454 "restartInTimerMsec",
10455 thread_timer_remain_second(
10456 p->t_pmax_restart)
10457 * 1000);
10458 } else
10459 vty_out(vty,
10460 " Reduce the no. of prefix from %s, will restart in %ld seconds\n",
10461 p->host, thread_timer_remain_second(
10462 p->t_pmax_restart));
10463 } else {
10464 if (use_json)
10465 json_object_boolean_true_add(
10466 json_neigh,
10467 "reducePrefixNumAndClearIpBgp");
10468 else
10469 vty_out(vty,
10470 " Reduce the no. of prefix and clear ip bgp %s to restore peering\n",
10471 p->host);
10472 }
10473 }
10474
10475 /* EBGP Multihop and GTSM */
10476 if (p->sort != BGP_PEER_IBGP) {
10477 if (use_json) {
10478 if (p->gtsm_hops > 0)
10479 json_object_int_add(json_neigh,
10480 "externalBgpNbrMaxHopsAway",
10481 p->gtsm_hops);
10482 else if (p->ttl > 1)
10483 json_object_int_add(json_neigh,
10484 "externalBgpNbrMaxHopsAway",
10485 p->ttl);
10486 } else {
10487 if (p->gtsm_hops > 0)
10488 vty_out(vty,
10489 " External BGP neighbor may be up to %d hops away.\n",
10490 p->gtsm_hops);
10491 else if (p->ttl > 1)
10492 vty_out(vty,
10493 " External BGP neighbor may be up to %d hops away.\n",
10494 p->ttl);
10495 }
10496 } else {
10497 if (p->gtsm_hops > 0) {
10498 if (use_json)
10499 json_object_int_add(json_neigh,
10500 "internalBgpNbrMaxHopsAway",
10501 p->gtsm_hops);
10502 else
10503 vty_out(vty,
10504 " Internal BGP neighbor may be up to %d hops away.\n",
10505 p->gtsm_hops);
10506 }
10507 }
10508
10509 /* Local address. */
10510 if (p->su_local) {
10511 if (use_json) {
10512 json_object_string_add(json_neigh, "hostLocal",
10513 sockunion2str(p->su_local, buf1,
10514 SU_ADDRSTRLEN));
10515 json_object_int_add(json_neigh, "portLocal",
10516 ntohs(p->su_local->sin.sin_port));
10517 } else
10518 vty_out(vty, "Local host: %s, Local port: %d\n",
10519 sockunion2str(p->su_local, buf1, SU_ADDRSTRLEN),
10520 ntohs(p->su_local->sin.sin_port));
10521 }
10522
10523 /* Remote address. */
10524 if (p->su_remote) {
10525 if (use_json) {
10526 json_object_string_add(json_neigh, "hostForeign",
10527 sockunion2str(p->su_remote, buf1,
10528 SU_ADDRSTRLEN));
10529 json_object_int_add(json_neigh, "portForeign",
10530 ntohs(p->su_remote->sin.sin_port));
10531 } else
10532 vty_out(vty, "Foreign host: %s, Foreign port: %d\n",
10533 sockunion2str(p->su_remote, buf1,
10534 SU_ADDRSTRLEN),
10535 ntohs(p->su_remote->sin.sin_port));
10536 }
10537
10538 /* Nexthop display. */
10539 if (p->su_local) {
10540 if (use_json) {
10541 json_object_string_add(json_neigh, "nexthop",
10542 inet_ntop(AF_INET,
10543 &p->nexthop.v4, buf1,
10544 sizeof(buf1)));
10545 json_object_string_add(json_neigh, "nexthopGlobal",
10546 inet_ntop(AF_INET6,
10547 &p->nexthop.v6_global,
10548 buf1, sizeof(buf1)));
10549 json_object_string_add(json_neigh, "nexthopLocal",
10550 inet_ntop(AF_INET6,
10551 &p->nexthop.v6_local,
10552 buf1, sizeof(buf1)));
10553 if (p->shared_network)
10554 json_object_string_add(json_neigh,
10555 "bgpConnection",
10556 "sharedNetwork");
10557 else
10558 json_object_string_add(json_neigh,
10559 "bgpConnection",
10560 "nonSharedNetwork");
10561 } else {
10562 vty_out(vty, "Nexthop: %s\n",
10563 inet_ntop(AF_INET, &p->nexthop.v4, buf1,
10564 sizeof(buf1)));
10565 vty_out(vty, "Nexthop global: %s\n",
10566 inet_ntop(AF_INET6, &p->nexthop.v6_global, buf1,
10567 sizeof(buf1)));
10568 vty_out(vty, "Nexthop local: %s\n",
10569 inet_ntop(AF_INET6, &p->nexthop.v6_local, buf1,
10570 sizeof(buf1)));
10571 vty_out(vty, "BGP connection: %s\n",
10572 p->shared_network ? "shared network"
10573 : "non shared network");
10574 }
10575 }
10576
10577 /* Timer information. */
10578 if (use_json) {
10579 json_object_int_add(json_neigh, "connectRetryTimer",
10580 p->v_connect);
10581 if (p->status == Established && p->rtt)
10582 json_object_int_add(json_neigh, "estimatedRttInMsecs",
10583 p->rtt);
10584 if (p->t_start)
10585 json_object_int_add(
10586 json_neigh, "nextStartTimerDueInMsecs",
10587 thread_timer_remain_second(p->t_start) * 1000);
10588 if (p->t_connect)
10589 json_object_int_add(
10590 json_neigh, "nextConnectTimerDueInMsecs",
10591 thread_timer_remain_second(p->t_connect)
10592 * 1000);
10593 if (p->t_routeadv) {
10594 json_object_int_add(json_neigh, "mraiInterval",
10595 p->v_routeadv);
10596 json_object_int_add(
10597 json_neigh, "mraiTimerExpireInMsecs",
10598 thread_timer_remain_second(p->t_routeadv)
10599 * 1000);
10600 }
10601 if (p->password)
10602 json_object_int_add(json_neigh, "authenticationEnabled",
10603 1);
10604
10605 if (p->t_read)
10606 json_object_string_add(json_neigh, "readThread", "on");
10607 else
10608 json_object_string_add(json_neigh, "readThread", "off");
10609
10610 if (CHECK_FLAG(p->thread_flags, PEER_THREAD_WRITES_ON))
10611 json_object_string_add(json_neigh, "writeThread", "on");
10612 else
10613 json_object_string_add(json_neigh, "writeThread",
10614 "off");
10615 } else {
10616 vty_out(vty, "BGP Connect Retry Timer in Seconds: %d\n",
10617 p->v_connect);
10618 if (p->status == Established && p->rtt)
10619 vty_out(vty, "Estimated round trip time: %d ms\n",
10620 p->rtt);
10621 if (p->t_start)
10622 vty_out(vty, "Next start timer due in %ld seconds\n",
10623 thread_timer_remain_second(p->t_start));
10624 if (p->t_connect)
10625 vty_out(vty, "Next connect timer due in %ld seconds\n",
10626 thread_timer_remain_second(p->t_connect));
10627 if (p->t_routeadv)
10628 vty_out(vty,
10629 "MRAI (interval %u) timer expires in %ld seconds\n",
10630 p->v_routeadv,
10631 thread_timer_remain_second(p->t_routeadv));
10632 if (p->password)
10633 vty_out(vty, "Peer Authentication Enabled\n");
10634
10635 vty_out(vty, "Read thread: %s Write thread: %s\n",
10636 p->t_read ? "on" : "off",
10637 CHECK_FLAG(p->thread_flags, PEER_THREAD_WRITES_ON)
10638 ? "on"
10639 : "off");
10640 }
10641
10642 if (p->notify.code == BGP_NOTIFY_OPEN_ERR
10643 && p->notify.subcode == BGP_NOTIFY_OPEN_UNSUP_CAPBL)
10644 bgp_capability_vty_out(vty, p, use_json, json_neigh);
10645
10646 if (!use_json)
10647 vty_out(vty, "\n");
10648
10649 /* BFD information. */
10650 bgp_bfd_show_info(vty, p, use_json, json_neigh);
10651
10652 if (use_json) {
10653 if (p->conf_if) /* Configured interface name. */
10654 json_object_object_add(json, p->conf_if, json_neigh);
10655 else /* Configured IP address. */
10656 json_object_object_add(json, p->host, json_neigh);
10657 }
10658 }
10659
10660 static int bgp_show_neighbor(struct vty *vty, struct bgp *bgp,
10661 enum show_type type, union sockunion *su,
10662 const char *conf_if, uint8_t use_json,
10663 json_object *json)
10664 {
10665 struct listnode *node, *nnode;
10666 struct peer *peer;
10667 int find = 0;
10668
10669 for (ALL_LIST_ELEMENTS(bgp->peer, node, nnode, peer)) {
10670 if (!CHECK_FLAG(peer->flags, PEER_FLAG_CONFIG_NODE))
10671 continue;
10672
10673 switch (type) {
10674 case show_all:
10675 bgp_show_peer(vty, peer, use_json, json);
10676 break;
10677 case show_peer:
10678 if (conf_if) {
10679 if ((peer->conf_if
10680 && !strcmp(peer->conf_if, conf_if))
10681 || (peer->hostname
10682 && !strcmp(peer->hostname, conf_if))) {
10683 find = 1;
10684 bgp_show_peer(vty, peer, use_json,
10685 json);
10686 }
10687 } else {
10688 if (sockunion_same(&peer->su, su)) {
10689 find = 1;
10690 bgp_show_peer(vty, peer, use_json,
10691 json);
10692 }
10693 }
10694 break;
10695 }
10696 }
10697
10698 if (type == show_peer && !find) {
10699 if (use_json)
10700 json_object_boolean_true_add(json, "bgpNoSuchNeighbor");
10701 else
10702 vty_out(vty, "%% No such neighbor in this view/vrf\n");
10703 }
10704
10705 if (use_json) {
10706 vty_out(vty, "%s\n", json_object_to_json_string_ext(
10707 json, JSON_C_TO_STRING_PRETTY));
10708 json_object_free(json);
10709 } else {
10710 vty_out(vty, "\n");
10711 }
10712
10713 return CMD_SUCCESS;
10714 }
10715
10716 static void bgp_show_all_instances_neighbors_vty(struct vty *vty,
10717 enum show_type type,
10718 const char *ip_str,
10719 uint8_t use_json)
10720 {
10721 struct listnode *node, *nnode;
10722 struct bgp *bgp;
10723 union sockunion su;
10724 json_object *json = NULL;
10725 int ret, is_first = 1;
10726
10727 if (use_json)
10728 vty_out(vty, "{\n");
10729
10730 for (ALL_LIST_ELEMENTS(bm->bgp, node, nnode, bgp)) {
10731 if (use_json) {
10732 if (!(json = json_object_new_object())) {
10733 zlog_err(
10734 "Unable to allocate memory for JSON object");
10735 vty_out(vty,
10736 "{\"error\": {\"message:\": \"Unable to allocate memory for JSON object\"}}}\n");
10737 return;
10738 }
10739
10740 json_object_int_add(json, "vrfId",
10741 (bgp->vrf_id == VRF_UNKNOWN)
10742 ? -1
10743 : (int64_t)bgp->vrf_id);
10744 json_object_string_add(
10745 json, "vrfName",
10746 (bgp->inst_type == BGP_INSTANCE_TYPE_DEFAULT)
10747 ? "Default"
10748 : bgp->name);
10749
10750 if (!is_first)
10751 vty_out(vty, ",\n");
10752 else
10753 is_first = 0;
10754
10755 vty_out(vty, "\"%s\":",
10756 (bgp->inst_type == BGP_INSTANCE_TYPE_DEFAULT)
10757 ? "Default"
10758 : bgp->name);
10759 } else {
10760 vty_out(vty, "\nInstance %s:\n",
10761 (bgp->inst_type == BGP_INSTANCE_TYPE_DEFAULT)
10762 ? "Default"
10763 : bgp->name);
10764 }
10765
10766 if (type == show_peer) {
10767 ret = str2sockunion(ip_str, &su);
10768 if (ret < 0)
10769 bgp_show_neighbor(vty, bgp, type, NULL, ip_str,
10770 use_json, json);
10771 else
10772 bgp_show_neighbor(vty, bgp, type, &su, NULL,
10773 use_json, json);
10774 } else {
10775 bgp_show_neighbor(vty, bgp, show_all, NULL, NULL,
10776 use_json, json);
10777 }
10778 }
10779
10780 if (use_json)
10781 vty_out(vty, "}\n");
10782 }
10783
10784 static int bgp_show_neighbor_vty(struct vty *vty, const char *name,
10785 enum show_type type, const char *ip_str,
10786 uint8_t use_json)
10787 {
10788 int ret;
10789 struct bgp *bgp;
10790 union sockunion su;
10791 json_object *json = NULL;
10792
10793 if (name) {
10794 if (strmatch(name, "all")) {
10795 bgp_show_all_instances_neighbors_vty(vty, type, ip_str,
10796 use_json);
10797 return CMD_SUCCESS;
10798 } else {
10799 bgp = bgp_lookup_by_name(name);
10800 if (!bgp) {
10801 if (use_json) {
10802 json = json_object_new_object();
10803 json_object_boolean_true_add(
10804 json, "bgpNoSuchInstance");
10805 vty_out(vty, "%s\n",
10806 json_object_to_json_string_ext(
10807 json,
10808 JSON_C_TO_STRING_PRETTY));
10809 json_object_free(json);
10810 } else
10811 vty_out(vty,
10812 "%% No such BGP instance exist\n");
10813
10814 return CMD_WARNING;
10815 }
10816 }
10817 } else {
10818 bgp = bgp_get_default();
10819 }
10820
10821 if (bgp) {
10822 json = json_object_new_object();
10823 if (ip_str) {
10824 ret = str2sockunion(ip_str, &su);
10825 if (ret < 0)
10826 bgp_show_neighbor(vty, bgp, type, NULL, ip_str,
10827 use_json, json);
10828 else
10829 bgp_show_neighbor(vty, bgp, type, &su, NULL,
10830 use_json, json);
10831 } else {
10832 bgp_show_neighbor(vty, bgp, type, NULL, NULL, use_json,
10833 json);
10834 }
10835 json_object_free(json);
10836 }
10837
10838 return CMD_SUCCESS;
10839 }
10840
10841 /* "show [ip] bgp neighbors" commands. */
10842 DEFUN (show_ip_bgp_neighbors,
10843 show_ip_bgp_neighbors_cmd,
10844 "show [ip] bgp [<view|vrf> VIEWVRFNAME] [<ipv4|ipv6>] neighbors [<A.B.C.D|X:X::X:X|WORD>] [json]",
10845 SHOW_STR
10846 IP_STR
10847 BGP_STR
10848 BGP_INSTANCE_HELP_STR
10849 "Address Family\n"
10850 "Address Family\n"
10851 "Detailed information on TCP and BGP neighbor connections\n"
10852 "Neighbor to display information about\n"
10853 "Neighbor to display information about\n"
10854 "Neighbor on BGP configured interface\n"
10855 JSON_STR)
10856 {
10857 char *vrf = NULL;
10858 char *sh_arg = NULL;
10859 enum show_type sh_type;
10860
10861 uint8_t uj = use_json(argc, argv);
10862
10863 int idx = 0;
10864
10865 if (argv_find(argv, argc, "view", &idx)
10866 || argv_find(argv, argc, "vrf", &idx))
10867 vrf = argv[idx + 1]->arg;
10868
10869 idx++;
10870 if (argv_find(argv, argc, "A.B.C.D", &idx)
10871 || argv_find(argv, argc, "X:X::X:X", &idx)
10872 || argv_find(argv, argc, "WORD", &idx)) {
10873 sh_type = show_peer;
10874 sh_arg = argv[idx]->arg;
10875 } else
10876 sh_type = show_all;
10877
10878 return bgp_show_neighbor_vty(vty, vrf, sh_type, sh_arg, uj);
10879 }
10880
10881 /* Show BGP's AS paths internal data. There are both `show [ip] bgp
10882 paths' and `show ip mbgp paths'. Those functions results are the
10883 same.*/
10884 DEFUN (show_ip_bgp_paths,
10885 show_ip_bgp_paths_cmd,
10886 "show [ip] bgp ["BGP_SAFI_CMD_STR"] paths",
10887 SHOW_STR
10888 IP_STR
10889 BGP_STR
10890 BGP_SAFI_HELP_STR
10891 "Path information\n")
10892 {
10893 vty_out(vty, "Address Refcnt Path\n");
10894 aspath_print_all_vty(vty);
10895 return CMD_SUCCESS;
10896 }
10897
10898 #include "hash.h"
10899
10900 static void community_show_all_iterator(struct hash_backet *backet,
10901 struct vty *vty)
10902 {
10903 struct community *com;
10904
10905 com = (struct community *)backet->data;
10906 vty_out(vty, "[%p] (%ld) %s\n", (void *)com, com->refcnt,
10907 community_str(com, false));
10908 }
10909
10910 /* Show BGP's community internal data. */
10911 DEFUN (show_ip_bgp_community_info,
10912 show_ip_bgp_community_info_cmd,
10913 "show [ip] bgp community-info",
10914 SHOW_STR
10915 IP_STR
10916 BGP_STR
10917 "List all bgp community information\n")
10918 {
10919 vty_out(vty, "Address Refcnt Community\n");
10920
10921 hash_iterate(community_hash(),
10922 (void (*)(struct hash_backet *,
10923 void *))community_show_all_iterator,
10924 vty);
10925
10926 return CMD_SUCCESS;
10927 }
10928
10929 static void lcommunity_show_all_iterator(struct hash_backet *backet,
10930 struct vty *vty)
10931 {
10932 struct lcommunity *lcom;
10933
10934 lcom = (struct lcommunity *)backet->data;
10935 vty_out(vty, "[%p] (%ld) %s\n", (void *)lcom, lcom->refcnt,
10936 lcommunity_str(lcom, false));
10937 }
10938
10939 /* Show BGP's community internal data. */
10940 DEFUN (show_ip_bgp_lcommunity_info,
10941 show_ip_bgp_lcommunity_info_cmd,
10942 "show ip bgp large-community-info",
10943 SHOW_STR
10944 IP_STR
10945 BGP_STR
10946 "List all bgp large-community information\n")
10947 {
10948 vty_out(vty, "Address Refcnt Large-community\n");
10949
10950 hash_iterate(lcommunity_hash(),
10951 (void (*)(struct hash_backet *,
10952 void *))lcommunity_show_all_iterator,
10953 vty);
10954
10955 return CMD_SUCCESS;
10956 }
10957
10958
10959 DEFUN (show_ip_bgp_attr_info,
10960 show_ip_bgp_attr_info_cmd,
10961 "show [ip] bgp attribute-info",
10962 SHOW_STR
10963 IP_STR
10964 BGP_STR
10965 "List all bgp attribute information\n")
10966 {
10967 attr_show_all(vty);
10968 return CMD_SUCCESS;
10969 }
10970
10971 static int bgp_show_route_leak_vty(struct vty *vty, const char *name,
10972 afi_t afi, safi_t safi)
10973 {
10974 struct bgp *bgp;
10975 struct listnode *node;
10976 char *vname;
10977 char buf1[INET6_ADDRSTRLEN];
10978 char *ecom_str;
10979 vpn_policy_direction_t dir;
10980
10981 if (name) {
10982 bgp = bgp_lookup_by_name(name);
10983 if (!bgp) {
10984 vty_out(vty, "%% No such BGP instance exist\n");
10985 return CMD_WARNING;
10986 }
10987 } else {
10988 bgp = bgp_get_default();
10989 if (!bgp) {
10990 vty_out(vty,
10991 "%% Default BGP instance does not exist\n");
10992 return CMD_WARNING;
10993 }
10994 }
10995
10996 if (!CHECK_FLAG(bgp->af_flags[afi][safi],
10997 BGP_CONFIG_VRF_TO_VRF_IMPORT)) {
10998 vty_out(vty,
10999 "This VRF is not importing %s routes from any other VRF\n",
11000 afi_safi_print(afi, safi));
11001 } else {
11002 vty_out(vty,
11003 "This VRF is importing %s routes from the following VRFs:\n",
11004 afi_safi_print(afi, safi));
11005 for (ALL_LIST_ELEMENTS_RO(bgp->vpn_policy[afi].import_vrf, node,
11006 vname)) {
11007 vty_out(vty, " %s\n", vname);
11008 }
11009 dir = BGP_VPN_POLICY_DIR_FROMVPN;
11010 ecom_str = ecommunity_ecom2str(
11011 bgp->vpn_policy[afi].rtlist[dir],
11012 ECOMMUNITY_FORMAT_ROUTE_MAP, 0);
11013 vty_out(vty, "Import RT(s): %s\n", ecom_str);
11014 XFREE(MTYPE_ECOMMUNITY_STR, ecom_str);
11015 }
11016
11017 if (!CHECK_FLAG(bgp->af_flags[afi][safi],
11018 BGP_CONFIG_VRF_TO_VRF_EXPORT)) {
11019 vty_out(vty,
11020 "This VRF is not exporting %s routes to any other VRF\n",
11021 afi_safi_print(afi, safi));
11022 } else {
11023 vty_out(vty,
11024 "This VRF is exporting %s routes to the following VRFs:\n",
11025 afi_safi_print(afi, safi));
11026 for (ALL_LIST_ELEMENTS_RO(bgp->vpn_policy[afi].export_vrf, node,
11027 vname)) {
11028 vty_out(vty, " %s\n", vname);
11029 }
11030 vty_out(vty, "RD: %s\n",
11031 prefix_rd2str(&bgp->vpn_policy[afi].tovpn_rd,
11032 buf1, RD_ADDRSTRLEN));
11033 dir = BGP_VPN_POLICY_DIR_TOVPN;
11034 ecom_str = ecommunity_ecom2str(
11035 bgp->vpn_policy[afi].rtlist[dir],
11036 ECOMMUNITY_FORMAT_ROUTE_MAP, 0);
11037 vty_out(vty, "Emport RT: %s\n", ecom_str);
11038 XFREE(MTYPE_ECOMMUNITY_STR, ecom_str);
11039 }
11040
11041 return CMD_SUCCESS;
11042 }
11043
11044 /* "show [ip] bgp route-leak" command. */
11045 DEFUN (show_ip_bgp_route_leak,
11046 show_ip_bgp_route_leak_cmd,
11047 "show [ip] bgp [<view|vrf> VIEWVRFNAME] ["BGP_AFI_CMD_STR" ["BGP_SAFI_CMD_STR"]] route-leak",
11048 SHOW_STR
11049 IP_STR
11050 BGP_STR
11051 BGP_INSTANCE_HELP_STR
11052 BGP_AFI_HELP_STR
11053 BGP_SAFI_HELP_STR
11054 "Route leaking information\n")
11055 {
11056 char *vrf = NULL;
11057 afi_t afi = AFI_MAX;
11058 safi_t safi = SAFI_MAX;
11059
11060 int idx = 0;
11061
11062 /* show [ip] bgp */
11063 if (argv_find(argv, argc, "ip", &idx)) {
11064 afi = AFI_IP;
11065 safi = SAFI_UNICAST;
11066 }
11067 /* [vrf VIEWVRFNAME] */
11068 if (argv_find(argv, argc, "view", &idx)) {
11069 vty_out(vty,
11070 "%% This command is not applicable to BGP views\n");
11071 return CMD_WARNING;
11072 }
11073
11074 if (argv_find(argv, argc, "vrf", &idx))
11075 vrf = argv[++idx]->arg;
11076 /* ["BGP_AFI_CMD_STR" ["BGP_SAFI_CMD_STR"]] */
11077 if (argv_find_and_parse_afi(argv, argc, &idx, &afi)) {
11078 argv_find_and_parse_safi(argv, argc, &idx, &safi);
11079 }
11080
11081 if (!((afi == AFI_IP || afi == AFI_IP6) && safi == SAFI_UNICAST)) {
11082 vty_out(vty,
11083 "%% This command is applicable only for unicast ipv4|ipv6\n");
11084 return CMD_WARNING;
11085 }
11086
11087 return bgp_show_route_leak_vty(vty, vrf, afi, safi);
11088 }
11089
11090 static void bgp_show_all_instances_updgrps_vty(struct vty *vty, afi_t afi,
11091 safi_t safi)
11092 {
11093 struct listnode *node, *nnode;
11094 struct bgp *bgp;
11095
11096 for (ALL_LIST_ELEMENTS(bm->bgp, node, nnode, bgp)) {
11097 vty_out(vty, "\nInstance %s:\n",
11098 (bgp->inst_type == BGP_INSTANCE_TYPE_DEFAULT)
11099 ? "Default"
11100 : bgp->name);
11101 update_group_show(bgp, afi, safi, vty, 0);
11102 }
11103 }
11104
11105 static int bgp_show_update_groups(struct vty *vty, const char *name, int afi,
11106 int safi, uint64_t subgrp_id)
11107 {
11108 struct bgp *bgp;
11109
11110 if (name) {
11111 if (strmatch(name, "all")) {
11112 bgp_show_all_instances_updgrps_vty(vty, afi, safi);
11113 return CMD_SUCCESS;
11114 } else {
11115 bgp = bgp_lookup_by_name(name);
11116 }
11117 } else {
11118 bgp = bgp_get_default();
11119 }
11120
11121 if (bgp)
11122 update_group_show(bgp, afi, safi, vty, subgrp_id);
11123 return CMD_SUCCESS;
11124 }
11125
11126 DEFUN (show_ip_bgp_updgrps,
11127 show_ip_bgp_updgrps_cmd,
11128 "show [ip] bgp [<view|vrf> VIEWVRFNAME] ["BGP_AFI_CMD_STR" ["BGP_SAFI_WITH_LABEL_CMD_STR"]] update-groups [SUBGROUP-ID]",
11129 SHOW_STR
11130 IP_STR
11131 BGP_STR
11132 BGP_INSTANCE_HELP_STR
11133 BGP_AFI_HELP_STR
11134 BGP_SAFI_WITH_LABEL_HELP_STR
11135 "Detailed info about dynamic update groups\n"
11136 "Specific subgroup to display detailed info for\n")
11137 {
11138 char *vrf = NULL;
11139 afi_t afi = AFI_IP6;
11140 safi_t safi = SAFI_UNICAST;
11141 uint64_t subgrp_id = 0;
11142
11143 int idx = 0;
11144
11145 /* show [ip] bgp */
11146 if (argv_find(argv, argc, "ip", &idx))
11147 afi = AFI_IP;
11148 /* [<view|vrf> VIEWVRFNAME] */
11149 if (argv_find(argv, argc, "view", &idx)
11150 || argv_find(argv, argc, "vrf", &idx))
11151 vrf = argv[++idx]->arg;
11152 /* ["BGP_AFI_CMD_STR" ["BGP_SAFI_CMD_STR"]] */
11153 if (argv_find_and_parse_afi(argv, argc, &idx, &afi)) {
11154 argv_find_and_parse_safi(argv, argc, &idx, &safi);
11155 }
11156
11157 /* get subgroup id, if provided */
11158 idx = argc - 1;
11159 if (argv[idx]->type == VARIABLE_TKN)
11160 subgrp_id = strtoull(argv[idx]->arg, NULL, 10);
11161
11162 return (bgp_show_update_groups(vty, vrf, afi, safi, subgrp_id));
11163 }
11164
11165 DEFUN (show_bgp_instance_all_ipv6_updgrps,
11166 show_bgp_instance_all_ipv6_updgrps_cmd,
11167 "show [ip] bgp <view|vrf> all update-groups",
11168 SHOW_STR
11169 IP_STR
11170 BGP_STR
11171 BGP_INSTANCE_ALL_HELP_STR
11172 "Detailed info about dynamic update groups\n")
11173 {
11174 bgp_show_all_instances_updgrps_vty(vty, AFI_IP6, SAFI_UNICAST);
11175 return CMD_SUCCESS;
11176 }
11177
11178 DEFUN (show_bgp_updgrps_stats,
11179 show_bgp_updgrps_stats_cmd,
11180 "show [ip] bgp update-groups statistics",
11181 SHOW_STR
11182 IP_STR
11183 BGP_STR
11184 "Detailed info about dynamic update groups\n"
11185 "Statistics\n")
11186 {
11187 struct bgp *bgp;
11188
11189 bgp = bgp_get_default();
11190 if (bgp)
11191 update_group_show_stats(bgp, vty);
11192
11193 return CMD_SUCCESS;
11194 }
11195
11196 DEFUN (show_bgp_instance_updgrps_stats,
11197 show_bgp_instance_updgrps_stats_cmd,
11198 "show [ip] bgp <view|vrf> VIEWVRFNAME update-groups statistics",
11199 SHOW_STR
11200 IP_STR
11201 BGP_STR
11202 BGP_INSTANCE_HELP_STR
11203 "Detailed info about dynamic update groups\n"
11204 "Statistics\n")
11205 {
11206 int idx_word = 3;
11207 struct bgp *bgp;
11208
11209 bgp = bgp_lookup_by_name(argv[idx_word]->arg);
11210 if (bgp)
11211 update_group_show_stats(bgp, vty);
11212
11213 return CMD_SUCCESS;
11214 }
11215
11216 static void show_bgp_updgrps_adj_info_aux(struct vty *vty, const char *name,
11217 afi_t afi, safi_t safi,
11218 const char *what, uint64_t subgrp_id)
11219 {
11220 struct bgp *bgp;
11221
11222 if (name)
11223 bgp = bgp_lookup_by_name(name);
11224 else
11225 bgp = bgp_get_default();
11226
11227 if (bgp) {
11228 if (!strcmp(what, "advertise-queue"))
11229 update_group_show_adj_queue(bgp, afi, safi, vty,
11230 subgrp_id);
11231 else if (!strcmp(what, "advertised-routes"))
11232 update_group_show_advertised(bgp, afi, safi, vty,
11233 subgrp_id);
11234 else if (!strcmp(what, "packet-queue"))
11235 update_group_show_packet_queue(bgp, afi, safi, vty,
11236 subgrp_id);
11237 }
11238 }
11239
11240 DEFPY(show_ip_bgp_instance_updgrps_adj_s,
11241 show_ip_bgp_instance_updgrps_adj_s_cmd,
11242 "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",
11243 SHOW_STR IP_STR BGP_STR BGP_INSTANCE_HELP_STR BGP_AFI_HELP_STR
11244 BGP_SAFI_HELP_STR
11245 "Detailed info about dynamic update groups\n"
11246 "Specific subgroup to display info for\n"
11247 "Advertisement queue\n"
11248 "Announced routes\n"
11249 "Packet queue\n")
11250 {
11251 uint64_t subgrp_id = 0;
11252 afi_t afiz;
11253 safi_t safiz;
11254 if (sgid)
11255 subgrp_id = strtoull(sgid, NULL, 10);
11256
11257 if (!ip && !afi)
11258 afiz = AFI_IP6;
11259 if (!ip && afi)
11260 afiz = bgp_vty_afi_from_str(afi);
11261 if (ip && !afi)
11262 afiz = AFI_IP;
11263 if (ip && afi) {
11264 afiz = bgp_vty_afi_from_str(afi);
11265 if (afiz != AFI_IP)
11266 vty_out(vty,
11267 "%% Cannot specify both 'ip' and 'ipv6'\n");
11268 return CMD_WARNING;
11269 }
11270
11271 safiz = safi ? bgp_vty_safi_from_str(safi) : SAFI_UNICAST;
11272
11273 show_bgp_updgrps_adj_info_aux(vty, vrf, afiz, safiz, rtq, subgrp_id);
11274 return CMD_SUCCESS;
11275 }
11276
11277 static int bgp_show_one_peer_group(struct vty *vty, struct peer_group *group)
11278 {
11279 struct listnode *node, *nnode;
11280 struct prefix *range;
11281 struct peer *conf;
11282 struct peer *peer;
11283 char buf[PREFIX2STR_BUFFER];
11284 afi_t afi;
11285 safi_t safi;
11286 const char *peer_status;
11287 const char *af_str;
11288 int lr_count;
11289 int dynamic;
11290 int af_cfgd;
11291
11292 conf = group->conf;
11293
11294 if (conf->as_type == AS_SPECIFIED || conf->as_type == AS_EXTERNAL) {
11295 vty_out(vty, "\nBGP peer-group %s, remote AS %d\n", group->name,
11296 conf->as);
11297 } else if (conf->as_type == AS_INTERNAL) {
11298 vty_out(vty, "\nBGP peer-group %s, remote AS %d\n", group->name,
11299 group->bgp->as);
11300 } else {
11301 vty_out(vty, "\nBGP peer-group %s\n", group->name);
11302 }
11303
11304 if ((group->bgp->as == conf->as) || (conf->as_type == AS_INTERNAL))
11305 vty_out(vty, " Peer-group type is internal\n");
11306 else
11307 vty_out(vty, " Peer-group type is external\n");
11308
11309 /* Display AFs configured. */
11310 vty_out(vty, " Configured address-families:");
11311 FOREACH_AFI_SAFI (afi, safi) {
11312 if (conf->afc[afi][safi]) {
11313 af_cfgd = 1;
11314 vty_out(vty, " %s;", afi_safi_print(afi, safi));
11315 }
11316 }
11317 if (!af_cfgd)
11318 vty_out(vty, " none\n");
11319 else
11320 vty_out(vty, "\n");
11321
11322 /* Display listen ranges (for dynamic neighbors), if any */
11323 for (afi = AFI_IP; afi < AFI_MAX; afi++) {
11324 if (afi == AFI_IP)
11325 af_str = "IPv4";
11326 else if (afi == AFI_IP6)
11327 af_str = "IPv6";
11328 else
11329 af_str = "???";
11330 lr_count = listcount(group->listen_range[afi]);
11331 if (lr_count) {
11332 vty_out(vty, " %d %s listen range(s)\n", lr_count,
11333 af_str);
11334
11335
11336 for (ALL_LIST_ELEMENTS(group->listen_range[afi], node,
11337 nnode, range)) {
11338 prefix2str(range, buf, sizeof(buf));
11339 vty_out(vty, " %s\n", buf);
11340 }
11341 }
11342 }
11343
11344 /* Display group members and their status */
11345 if (listcount(group->peer)) {
11346 vty_out(vty, " Peer-group members:\n");
11347 for (ALL_LIST_ELEMENTS(group->peer, node, nnode, peer)) {
11348 if (CHECK_FLAG(peer->flags, PEER_FLAG_SHUTDOWN))
11349 peer_status = "Idle (Admin)";
11350 else if (CHECK_FLAG(peer->sflags,
11351 PEER_STATUS_PREFIX_OVERFLOW))
11352 peer_status = "Idle (PfxCt)";
11353 else
11354 peer_status = lookup_msg(bgp_status_msg,
11355 peer->status, NULL);
11356
11357 dynamic = peer_dynamic_neighbor(peer);
11358 vty_out(vty, " %s %s %s \n", peer->host,
11359 dynamic ? "(dynamic)" : "", peer_status);
11360 }
11361 }
11362
11363 return CMD_SUCCESS;
11364 }
11365
11366 static int bgp_show_peer_group_vty(struct vty *vty, const char *name,
11367 const char *group_name)
11368 {
11369 struct bgp *bgp;
11370 struct listnode *node, *nnode;
11371 struct peer_group *group;
11372 bool found = false;
11373
11374 bgp = name ? bgp_lookup_by_name(name) : bgp_get_default();
11375
11376 if (!bgp) {
11377 vty_out(vty, "%% No such BGP instance exists\n");
11378 return CMD_WARNING;
11379 }
11380
11381 for (ALL_LIST_ELEMENTS(bgp->group, node, nnode, group)) {
11382 if (group_name) {
11383 if (strmatch(group->name, group_name)) {
11384 bgp_show_one_peer_group(vty, group);
11385 found = true;
11386 break;
11387 }
11388 } else {
11389 bgp_show_one_peer_group(vty, group);
11390 }
11391 }
11392
11393 if (group_name && !found)
11394 vty_out(vty, "%% No such peer-group\n");
11395
11396 return CMD_SUCCESS;
11397 }
11398
11399 DEFUN (show_ip_bgp_peer_groups,
11400 show_ip_bgp_peer_groups_cmd,
11401 "show [ip] bgp [<view|vrf> VIEWVRFNAME] peer-group [PGNAME]",
11402 SHOW_STR
11403 IP_STR
11404 BGP_STR
11405 BGP_INSTANCE_HELP_STR
11406 "Detailed information on BGP peer groups\n"
11407 "Peer group name\n")
11408 {
11409 char *vrf, *pg;
11410 vrf = pg = NULL;
11411 int idx = 0;
11412
11413 vrf = argv_find(argv, argc, "VIEWVRFNAME", &idx) ? argv[idx]->arg
11414 : NULL;
11415 pg = argv_find(argv, argc, "PGNAME", &idx) ? argv[idx]->arg : NULL;
11416
11417 return bgp_show_peer_group_vty(vty, vrf, pg);
11418 }
11419
11420
11421 /* Redistribute VTY commands. */
11422
11423 DEFUN (bgp_redistribute_ipv4,
11424 bgp_redistribute_ipv4_cmd,
11425 "redistribute " FRR_IP_REDIST_STR_BGPD,
11426 "Redistribute information from another routing protocol\n"
11427 FRR_IP_REDIST_HELP_STR_BGPD)
11428 {
11429 VTY_DECLVAR_CONTEXT(bgp, bgp);
11430 int idx_protocol = 1;
11431 int type;
11432
11433 type = proto_redistnum(AFI_IP, argv[idx_protocol]->text);
11434 if (type < 0) {
11435 vty_out(vty, "%% Invalid route type\n");
11436 return CMD_WARNING_CONFIG_FAILED;
11437 }
11438
11439 bgp_redist_add(bgp, AFI_IP, type, 0);
11440 return bgp_redistribute_set(bgp, AFI_IP, type, 0);
11441 }
11442
11443 ALIAS_HIDDEN(
11444 bgp_redistribute_ipv4, bgp_redistribute_ipv4_hidden_cmd,
11445 "redistribute " FRR_IP_REDIST_STR_BGPD,
11446 "Redistribute information from another routing protocol\n" FRR_IP_REDIST_HELP_STR_BGPD)
11447
11448 DEFUN (bgp_redistribute_ipv4_rmap,
11449 bgp_redistribute_ipv4_rmap_cmd,
11450 "redistribute " FRR_IP_REDIST_STR_BGPD " route-map WORD",
11451 "Redistribute information from another routing protocol\n"
11452 FRR_IP_REDIST_HELP_STR_BGPD
11453 "Route map reference\n"
11454 "Pointer to route-map entries\n")
11455 {
11456 VTY_DECLVAR_CONTEXT(bgp, bgp);
11457 int idx_protocol = 1;
11458 int idx_word = 3;
11459 int type;
11460 struct bgp_redist *red;
11461
11462 type = proto_redistnum(AFI_IP, argv[idx_protocol]->text);
11463 if (type < 0) {
11464 vty_out(vty, "%% Invalid route type\n");
11465 return CMD_WARNING_CONFIG_FAILED;
11466 }
11467
11468 red = bgp_redist_add(bgp, AFI_IP, type, 0);
11469 bgp_redistribute_rmap_set(red, argv[idx_word]->arg);
11470 return bgp_redistribute_set(bgp, AFI_IP, type, 0);
11471 }
11472
11473 ALIAS_HIDDEN(
11474 bgp_redistribute_ipv4_rmap, bgp_redistribute_ipv4_rmap_hidden_cmd,
11475 "redistribute " FRR_IP_REDIST_STR_BGPD " route-map WORD",
11476 "Redistribute information from another routing protocol\n" FRR_IP_REDIST_HELP_STR_BGPD
11477 "Route map reference\n"
11478 "Pointer to route-map entries\n")
11479
11480 DEFUN (bgp_redistribute_ipv4_metric,
11481 bgp_redistribute_ipv4_metric_cmd,
11482 "redistribute " FRR_IP_REDIST_STR_BGPD " metric (0-4294967295)",
11483 "Redistribute information from another routing protocol\n"
11484 FRR_IP_REDIST_HELP_STR_BGPD
11485 "Metric for redistributed routes\n"
11486 "Default metric\n")
11487 {
11488 VTY_DECLVAR_CONTEXT(bgp, bgp);
11489 int idx_protocol = 1;
11490 int idx_number = 3;
11491 int type;
11492 uint32_t metric;
11493 struct bgp_redist *red;
11494
11495 type = proto_redistnum(AFI_IP, argv[idx_protocol]->text);
11496 if (type < 0) {
11497 vty_out(vty, "%% Invalid route type\n");
11498 return CMD_WARNING_CONFIG_FAILED;
11499 }
11500 metric = strtoul(argv[idx_number]->arg, NULL, 10);
11501
11502 red = bgp_redist_add(bgp, AFI_IP, type, 0);
11503 bgp_redistribute_metric_set(bgp, red, AFI_IP, type, metric);
11504 return bgp_redistribute_set(bgp, AFI_IP, type, 0);
11505 }
11506
11507 ALIAS_HIDDEN(
11508 bgp_redistribute_ipv4_metric, bgp_redistribute_ipv4_metric_hidden_cmd,
11509 "redistribute " FRR_IP_REDIST_STR_BGPD " metric (0-4294967295)",
11510 "Redistribute information from another routing protocol\n" FRR_IP_REDIST_HELP_STR_BGPD
11511 "Metric for redistributed routes\n"
11512 "Default metric\n")
11513
11514 DEFUN (bgp_redistribute_ipv4_rmap_metric,
11515 bgp_redistribute_ipv4_rmap_metric_cmd,
11516 "redistribute " FRR_IP_REDIST_STR_BGPD " route-map WORD metric (0-4294967295)",
11517 "Redistribute information from another routing protocol\n"
11518 FRR_IP_REDIST_HELP_STR_BGPD
11519 "Route map reference\n"
11520 "Pointer to route-map entries\n"
11521 "Metric for redistributed routes\n"
11522 "Default metric\n")
11523 {
11524 VTY_DECLVAR_CONTEXT(bgp, bgp);
11525 int idx_protocol = 1;
11526 int idx_word = 3;
11527 int idx_number = 5;
11528 int type;
11529 uint32_t metric;
11530 struct bgp_redist *red;
11531
11532 type = proto_redistnum(AFI_IP, argv[idx_protocol]->text);
11533 if (type < 0) {
11534 vty_out(vty, "%% Invalid route type\n");
11535 return CMD_WARNING_CONFIG_FAILED;
11536 }
11537 metric = strtoul(argv[idx_number]->arg, NULL, 10);
11538
11539 red = bgp_redist_add(bgp, AFI_IP, type, 0);
11540 bgp_redistribute_rmap_set(red, argv[idx_word]->arg);
11541 bgp_redistribute_metric_set(bgp, red, AFI_IP, type, metric);
11542 return bgp_redistribute_set(bgp, AFI_IP, type, 0);
11543 }
11544
11545 ALIAS_HIDDEN(
11546 bgp_redistribute_ipv4_rmap_metric,
11547 bgp_redistribute_ipv4_rmap_metric_hidden_cmd,
11548 "redistribute " FRR_IP_REDIST_STR_BGPD
11549 " route-map WORD metric (0-4294967295)",
11550 "Redistribute information from another routing protocol\n" FRR_IP_REDIST_HELP_STR_BGPD
11551 "Route map reference\n"
11552 "Pointer to route-map entries\n"
11553 "Metric for redistributed routes\n"
11554 "Default metric\n")
11555
11556 DEFUN (bgp_redistribute_ipv4_metric_rmap,
11557 bgp_redistribute_ipv4_metric_rmap_cmd,
11558 "redistribute " FRR_IP_REDIST_STR_BGPD " metric (0-4294967295) route-map WORD",
11559 "Redistribute information from another routing protocol\n"
11560 FRR_IP_REDIST_HELP_STR_BGPD
11561 "Metric for redistributed routes\n"
11562 "Default metric\n"
11563 "Route map reference\n"
11564 "Pointer to route-map entries\n")
11565 {
11566 VTY_DECLVAR_CONTEXT(bgp, bgp);
11567 int idx_protocol = 1;
11568 int idx_number = 3;
11569 int idx_word = 5;
11570 int type;
11571 uint32_t metric;
11572 struct bgp_redist *red;
11573
11574 type = proto_redistnum(AFI_IP, argv[idx_protocol]->text);
11575 if (type < 0) {
11576 vty_out(vty, "%% Invalid route type\n");
11577 return CMD_WARNING_CONFIG_FAILED;
11578 }
11579 metric = strtoul(argv[idx_number]->arg, NULL, 10);
11580
11581 red = bgp_redist_add(bgp, AFI_IP, type, 0);
11582 bgp_redistribute_metric_set(bgp, red, AFI_IP, type, metric);
11583 bgp_redistribute_rmap_set(red, argv[idx_word]->arg);
11584 return bgp_redistribute_set(bgp, AFI_IP, type, 0);
11585 }
11586
11587 ALIAS_HIDDEN(
11588 bgp_redistribute_ipv4_metric_rmap,
11589 bgp_redistribute_ipv4_metric_rmap_hidden_cmd,
11590 "redistribute " FRR_IP_REDIST_STR_BGPD
11591 " metric (0-4294967295) route-map WORD",
11592 "Redistribute information from another routing protocol\n" FRR_IP_REDIST_HELP_STR_BGPD
11593 "Metric for redistributed routes\n"
11594 "Default metric\n"
11595 "Route map reference\n"
11596 "Pointer to route-map entries\n")
11597
11598 DEFUN (bgp_redistribute_ipv4_ospf,
11599 bgp_redistribute_ipv4_ospf_cmd,
11600 "redistribute <ospf|table> (1-65535)",
11601 "Redistribute information from another routing protocol\n"
11602 "Open Shortest Path First (OSPFv2)\n"
11603 "Non-main Kernel Routing Table\n"
11604 "Instance ID/Table ID\n")
11605 {
11606 VTY_DECLVAR_CONTEXT(bgp, bgp);
11607 int idx_ospf_table = 1;
11608 int idx_number = 2;
11609 unsigned short instance;
11610 unsigned short protocol;
11611
11612 instance = strtoul(argv[idx_number]->arg, NULL, 10);
11613
11614 if (strncmp(argv[idx_ospf_table]->arg, "o", 1) == 0)
11615 protocol = ZEBRA_ROUTE_OSPF;
11616 else
11617 protocol = ZEBRA_ROUTE_TABLE;
11618
11619 bgp_redist_add(bgp, AFI_IP, protocol, instance);
11620 return bgp_redistribute_set(bgp, AFI_IP, protocol, instance);
11621 }
11622
11623 ALIAS_HIDDEN(bgp_redistribute_ipv4_ospf, bgp_redistribute_ipv4_ospf_hidden_cmd,
11624 "redistribute <ospf|table> (1-65535)",
11625 "Redistribute information from another routing protocol\n"
11626 "Open Shortest Path First (OSPFv2)\n"
11627 "Non-main Kernel Routing Table\n"
11628 "Instance ID/Table ID\n")
11629
11630 DEFUN (bgp_redistribute_ipv4_ospf_rmap,
11631 bgp_redistribute_ipv4_ospf_rmap_cmd,
11632 "redistribute <ospf|table> (1-65535) route-map WORD",
11633 "Redistribute information from another routing protocol\n"
11634 "Open Shortest Path First (OSPFv2)\n"
11635 "Non-main Kernel Routing Table\n"
11636 "Instance ID/Table ID\n"
11637 "Route map reference\n"
11638 "Pointer to route-map entries\n")
11639 {
11640 VTY_DECLVAR_CONTEXT(bgp, bgp);
11641 int idx_ospf_table = 1;
11642 int idx_number = 2;
11643 int idx_word = 4;
11644 struct bgp_redist *red;
11645 unsigned short instance;
11646 int protocol;
11647
11648 if (strncmp(argv[idx_ospf_table]->arg, "o", 1) == 0)
11649 protocol = ZEBRA_ROUTE_OSPF;
11650 else
11651 protocol = ZEBRA_ROUTE_TABLE;
11652
11653 instance = strtoul(argv[idx_number]->arg, NULL, 10);
11654 red = bgp_redist_add(bgp, AFI_IP, protocol, instance);
11655 bgp_redistribute_rmap_set(red, argv[idx_word]->arg);
11656 return bgp_redistribute_set(bgp, AFI_IP, protocol, instance);
11657 }
11658
11659 ALIAS_HIDDEN(bgp_redistribute_ipv4_ospf_rmap,
11660 bgp_redistribute_ipv4_ospf_rmap_hidden_cmd,
11661 "redistribute <ospf|table> (1-65535) route-map WORD",
11662 "Redistribute information from another routing protocol\n"
11663 "Open Shortest Path First (OSPFv2)\n"
11664 "Non-main Kernel Routing Table\n"
11665 "Instance ID/Table ID\n"
11666 "Route map reference\n"
11667 "Pointer to route-map entries\n")
11668
11669 DEFUN (bgp_redistribute_ipv4_ospf_metric,
11670 bgp_redistribute_ipv4_ospf_metric_cmd,
11671 "redistribute <ospf|table> (1-65535) metric (0-4294967295)",
11672 "Redistribute information from another routing protocol\n"
11673 "Open Shortest Path First (OSPFv2)\n"
11674 "Non-main Kernel Routing Table\n"
11675 "Instance ID/Table ID\n"
11676 "Metric for redistributed routes\n"
11677 "Default metric\n")
11678 {
11679 VTY_DECLVAR_CONTEXT(bgp, bgp);
11680 int idx_ospf_table = 1;
11681 int idx_number = 2;
11682 int idx_number_2 = 4;
11683 uint32_t metric;
11684 struct bgp_redist *red;
11685 unsigned short instance;
11686 int protocol;
11687
11688 if (strncmp(argv[idx_ospf_table]->arg, "o", 1) == 0)
11689 protocol = ZEBRA_ROUTE_OSPF;
11690 else
11691 protocol = ZEBRA_ROUTE_TABLE;
11692
11693 instance = strtoul(argv[idx_number]->arg, NULL, 10);
11694 metric = strtoul(argv[idx_number_2]->arg, NULL, 10);
11695
11696 red = bgp_redist_add(bgp, AFI_IP, protocol, instance);
11697 bgp_redistribute_metric_set(bgp, red, AFI_IP, protocol, metric);
11698 return bgp_redistribute_set(bgp, AFI_IP, protocol, instance);
11699 }
11700
11701 ALIAS_HIDDEN(bgp_redistribute_ipv4_ospf_metric,
11702 bgp_redistribute_ipv4_ospf_metric_hidden_cmd,
11703 "redistribute <ospf|table> (1-65535) metric (0-4294967295)",
11704 "Redistribute information from another routing protocol\n"
11705 "Open Shortest Path First (OSPFv2)\n"
11706 "Non-main Kernel Routing Table\n"
11707 "Instance ID/Table ID\n"
11708 "Metric for redistributed routes\n"
11709 "Default metric\n")
11710
11711 DEFUN (bgp_redistribute_ipv4_ospf_rmap_metric,
11712 bgp_redistribute_ipv4_ospf_rmap_metric_cmd,
11713 "redistribute <ospf|table> (1-65535) route-map WORD metric (0-4294967295)",
11714 "Redistribute information from another routing protocol\n"
11715 "Open Shortest Path First (OSPFv2)\n"
11716 "Non-main Kernel Routing Table\n"
11717 "Instance ID/Table ID\n"
11718 "Route map reference\n"
11719 "Pointer to route-map entries\n"
11720 "Metric for redistributed routes\n"
11721 "Default metric\n")
11722 {
11723 VTY_DECLVAR_CONTEXT(bgp, bgp);
11724 int idx_ospf_table = 1;
11725 int idx_number = 2;
11726 int idx_word = 4;
11727 int idx_number_2 = 6;
11728 uint32_t metric;
11729 struct bgp_redist *red;
11730 unsigned short instance;
11731 int protocol;
11732
11733 if (strncmp(argv[idx_ospf_table]->arg, "o", 1) == 0)
11734 protocol = ZEBRA_ROUTE_OSPF;
11735 else
11736 protocol = ZEBRA_ROUTE_TABLE;
11737
11738 instance = strtoul(argv[idx_number]->arg, NULL, 10);
11739 metric = strtoul(argv[idx_number_2]->arg, NULL, 10);
11740
11741 red = bgp_redist_add(bgp, AFI_IP, protocol, instance);
11742 bgp_redistribute_rmap_set(red, argv[idx_word]->arg);
11743 bgp_redistribute_metric_set(bgp, red, AFI_IP, protocol, metric);
11744 return bgp_redistribute_set(bgp, AFI_IP, protocol, instance);
11745 }
11746
11747 ALIAS_HIDDEN(
11748 bgp_redistribute_ipv4_ospf_rmap_metric,
11749 bgp_redistribute_ipv4_ospf_rmap_metric_hidden_cmd,
11750 "redistribute <ospf|table> (1-65535) route-map WORD metric (0-4294967295)",
11751 "Redistribute information from another routing protocol\n"
11752 "Open Shortest Path First (OSPFv2)\n"
11753 "Non-main Kernel Routing Table\n"
11754 "Instance ID/Table ID\n"
11755 "Route map reference\n"
11756 "Pointer to route-map entries\n"
11757 "Metric for redistributed routes\n"
11758 "Default metric\n")
11759
11760 DEFUN (bgp_redistribute_ipv4_ospf_metric_rmap,
11761 bgp_redistribute_ipv4_ospf_metric_rmap_cmd,
11762 "redistribute <ospf|table> (1-65535) metric (0-4294967295) route-map WORD",
11763 "Redistribute information from another routing protocol\n"
11764 "Open Shortest Path First (OSPFv2)\n"
11765 "Non-main Kernel Routing Table\n"
11766 "Instance ID/Table ID\n"
11767 "Metric for redistributed routes\n"
11768 "Default metric\n"
11769 "Route map reference\n"
11770 "Pointer to route-map entries\n")
11771 {
11772 VTY_DECLVAR_CONTEXT(bgp, bgp);
11773 int idx_ospf_table = 1;
11774 int idx_number = 2;
11775 int idx_number_2 = 4;
11776 int idx_word = 6;
11777 uint32_t metric;
11778 struct bgp_redist *red;
11779 unsigned short instance;
11780 int protocol;
11781
11782 if (strncmp(argv[idx_ospf_table]->arg, "o", 1) == 0)
11783 protocol = ZEBRA_ROUTE_OSPF;
11784 else
11785 protocol = ZEBRA_ROUTE_TABLE;
11786
11787 instance = strtoul(argv[idx_number]->arg, NULL, 10);
11788 metric = strtoul(argv[idx_number_2]->arg, NULL, 10);
11789
11790 red = bgp_redist_add(bgp, AFI_IP, protocol, instance);
11791 bgp_redistribute_metric_set(bgp, red, AFI_IP, protocol, metric);
11792 bgp_redistribute_rmap_set(red, argv[idx_word]->arg);
11793 return bgp_redistribute_set(bgp, AFI_IP, protocol, instance);
11794 }
11795
11796 ALIAS_HIDDEN(
11797 bgp_redistribute_ipv4_ospf_metric_rmap,
11798 bgp_redistribute_ipv4_ospf_metric_rmap_hidden_cmd,
11799 "redistribute <ospf|table> (1-65535) metric (0-4294967295) route-map WORD",
11800 "Redistribute information from another routing protocol\n"
11801 "Open Shortest Path First (OSPFv2)\n"
11802 "Non-main Kernel Routing Table\n"
11803 "Instance ID/Table ID\n"
11804 "Metric for redistributed routes\n"
11805 "Default metric\n"
11806 "Route map reference\n"
11807 "Pointer to route-map entries\n")
11808
11809 DEFUN (no_bgp_redistribute_ipv4_ospf,
11810 no_bgp_redistribute_ipv4_ospf_cmd,
11811 "no redistribute <ospf|table> (1-65535) [metric (0-4294967295)] [route-map WORD]",
11812 NO_STR
11813 "Redistribute information from another routing protocol\n"
11814 "Open Shortest Path First (OSPFv2)\n"
11815 "Non-main Kernel Routing Table\n"
11816 "Instance ID/Table ID\n"
11817 "Metric for redistributed routes\n"
11818 "Default metric\n"
11819 "Route map reference\n"
11820 "Pointer to route-map entries\n")
11821 {
11822 VTY_DECLVAR_CONTEXT(bgp, bgp);
11823 int idx_ospf_table = 2;
11824 int idx_number = 3;
11825 unsigned short instance;
11826 int protocol;
11827
11828 if (strncmp(argv[idx_ospf_table]->arg, "o", 1) == 0)
11829 protocol = ZEBRA_ROUTE_OSPF;
11830 else
11831 protocol = ZEBRA_ROUTE_TABLE;
11832
11833 instance = strtoul(argv[idx_number]->arg, NULL, 10);
11834 return bgp_redistribute_unset(bgp, AFI_IP, protocol, instance);
11835 }
11836
11837 ALIAS_HIDDEN(
11838 no_bgp_redistribute_ipv4_ospf, no_bgp_redistribute_ipv4_ospf_hidden_cmd,
11839 "no redistribute <ospf|table> (1-65535) [metric (0-4294967295)] [route-map WORD]",
11840 NO_STR
11841 "Redistribute information from another routing protocol\n"
11842 "Open Shortest Path First (OSPFv2)\n"
11843 "Non-main Kernel Routing Table\n"
11844 "Instance ID/Table ID\n"
11845 "Metric for redistributed routes\n"
11846 "Default metric\n"
11847 "Route map reference\n"
11848 "Pointer to route-map entries\n")
11849
11850 DEFUN (no_bgp_redistribute_ipv4,
11851 no_bgp_redistribute_ipv4_cmd,
11852 "no redistribute " FRR_IP_REDIST_STR_BGPD " [metric (0-4294967295)] [route-map WORD]",
11853 NO_STR
11854 "Redistribute information from another routing protocol\n"
11855 FRR_IP_REDIST_HELP_STR_BGPD
11856 "Metric for redistributed routes\n"
11857 "Default metric\n"
11858 "Route map reference\n"
11859 "Pointer to route-map entries\n")
11860 {
11861 VTY_DECLVAR_CONTEXT(bgp, bgp);
11862 int idx_protocol = 2;
11863 int type;
11864
11865 type = proto_redistnum(AFI_IP, argv[idx_protocol]->text);
11866 if (type < 0) {
11867 vty_out(vty, "%% Invalid route type\n");
11868 return CMD_WARNING_CONFIG_FAILED;
11869 }
11870 return bgp_redistribute_unset(bgp, AFI_IP, type, 0);
11871 }
11872
11873 ALIAS_HIDDEN(
11874 no_bgp_redistribute_ipv4, no_bgp_redistribute_ipv4_hidden_cmd,
11875 "no redistribute " FRR_IP_REDIST_STR_BGPD
11876 " [metric (0-4294967295)] [route-map WORD]",
11877 NO_STR
11878 "Redistribute information from another routing protocol\n" FRR_IP_REDIST_HELP_STR_BGPD
11879 "Metric for redistributed routes\n"
11880 "Default metric\n"
11881 "Route map reference\n"
11882 "Pointer to route-map entries\n")
11883
11884 DEFUN (bgp_redistribute_ipv6,
11885 bgp_redistribute_ipv6_cmd,
11886 "redistribute " FRR_IP6_REDIST_STR_BGPD,
11887 "Redistribute information from another routing protocol\n"
11888 FRR_IP6_REDIST_HELP_STR_BGPD)
11889 {
11890 VTY_DECLVAR_CONTEXT(bgp, bgp);
11891 int idx_protocol = 1;
11892 int type;
11893
11894 type = proto_redistnum(AFI_IP6, argv[idx_protocol]->text);
11895 if (type < 0) {
11896 vty_out(vty, "%% Invalid route type\n");
11897 return CMD_WARNING_CONFIG_FAILED;
11898 }
11899
11900 bgp_redist_add(bgp, AFI_IP6, type, 0);
11901 return bgp_redistribute_set(bgp, AFI_IP6, type, 0);
11902 }
11903
11904 DEFUN (bgp_redistribute_ipv6_rmap,
11905 bgp_redistribute_ipv6_rmap_cmd,
11906 "redistribute " FRR_IP6_REDIST_STR_BGPD " route-map WORD",
11907 "Redistribute information from another routing protocol\n"
11908 FRR_IP6_REDIST_HELP_STR_BGPD
11909 "Route map reference\n"
11910 "Pointer to route-map entries\n")
11911 {
11912 VTY_DECLVAR_CONTEXT(bgp, bgp);
11913 int idx_protocol = 1;
11914 int idx_word = 3;
11915 int type;
11916 struct bgp_redist *red;
11917
11918 type = proto_redistnum(AFI_IP6, argv[idx_protocol]->text);
11919 if (type < 0) {
11920 vty_out(vty, "%% Invalid route type\n");
11921 return CMD_WARNING_CONFIG_FAILED;
11922 }
11923
11924 red = bgp_redist_add(bgp, AFI_IP6, type, 0);
11925 bgp_redistribute_rmap_set(red, argv[idx_word]->arg);
11926 return bgp_redistribute_set(bgp, AFI_IP6, type, 0);
11927 }
11928
11929 DEFUN (bgp_redistribute_ipv6_metric,
11930 bgp_redistribute_ipv6_metric_cmd,
11931 "redistribute " FRR_IP6_REDIST_STR_BGPD " metric (0-4294967295)",
11932 "Redistribute information from another routing protocol\n"
11933 FRR_IP6_REDIST_HELP_STR_BGPD
11934 "Metric for redistributed routes\n"
11935 "Default metric\n")
11936 {
11937 VTY_DECLVAR_CONTEXT(bgp, bgp);
11938 int idx_protocol = 1;
11939 int idx_number = 3;
11940 int type;
11941 uint32_t metric;
11942 struct bgp_redist *red;
11943
11944 type = proto_redistnum(AFI_IP6, argv[idx_protocol]->text);
11945 if (type < 0) {
11946 vty_out(vty, "%% Invalid route type\n");
11947 return CMD_WARNING_CONFIG_FAILED;
11948 }
11949 metric = strtoul(argv[idx_number]->arg, NULL, 10);
11950
11951 red = bgp_redist_add(bgp, AFI_IP6, type, 0);
11952 bgp_redistribute_metric_set(bgp, red, AFI_IP6, type, metric);
11953 return bgp_redistribute_set(bgp, AFI_IP6, type, 0);
11954 }
11955
11956 DEFUN (bgp_redistribute_ipv6_rmap_metric,
11957 bgp_redistribute_ipv6_rmap_metric_cmd,
11958 "redistribute " FRR_IP6_REDIST_STR_BGPD " route-map WORD metric (0-4294967295)",
11959 "Redistribute information from another routing protocol\n"
11960 FRR_IP6_REDIST_HELP_STR_BGPD
11961 "Route map reference\n"
11962 "Pointer to route-map entries\n"
11963 "Metric for redistributed routes\n"
11964 "Default metric\n")
11965 {
11966 VTY_DECLVAR_CONTEXT(bgp, bgp);
11967 int idx_protocol = 1;
11968 int idx_word = 3;
11969 int idx_number = 5;
11970 int type;
11971 uint32_t metric;
11972 struct bgp_redist *red;
11973
11974 type = proto_redistnum(AFI_IP6, argv[idx_protocol]->text);
11975 if (type < 0) {
11976 vty_out(vty, "%% Invalid route type\n");
11977 return CMD_WARNING_CONFIG_FAILED;
11978 }
11979 metric = strtoul(argv[idx_number]->arg, NULL, 10);
11980
11981 red = bgp_redist_add(bgp, AFI_IP6, type, 0);
11982 bgp_redistribute_rmap_set(red, argv[idx_word]->arg);
11983 bgp_redistribute_metric_set(bgp, red, AFI_IP6, type, metric);
11984 return bgp_redistribute_set(bgp, AFI_IP6, type, 0);
11985 }
11986
11987 DEFUN (bgp_redistribute_ipv6_metric_rmap,
11988 bgp_redistribute_ipv6_metric_rmap_cmd,
11989 "redistribute " FRR_IP6_REDIST_STR_BGPD " metric (0-4294967295) route-map WORD",
11990 "Redistribute information from another routing protocol\n"
11991 FRR_IP6_REDIST_HELP_STR_BGPD
11992 "Metric for redistributed routes\n"
11993 "Default metric\n"
11994 "Route map reference\n"
11995 "Pointer to route-map entries\n")
11996 {
11997 VTY_DECLVAR_CONTEXT(bgp, bgp);
11998 int idx_protocol = 1;
11999 int idx_number = 3;
12000 int idx_word = 5;
12001 int type;
12002 uint32_t metric;
12003 struct bgp_redist *red;
12004
12005 type = proto_redistnum(AFI_IP6, argv[idx_protocol]->text);
12006 if (type < 0) {
12007 vty_out(vty, "%% Invalid route type\n");
12008 return CMD_WARNING_CONFIG_FAILED;
12009 }
12010 metric = strtoul(argv[idx_number]->arg, NULL, 10);
12011
12012 red = bgp_redist_add(bgp, AFI_IP6, type, 0);
12013 bgp_redistribute_metric_set(bgp, red, AFI_IP6, SAFI_UNICAST, metric);
12014 bgp_redistribute_rmap_set(red, argv[idx_word]->arg);
12015 return bgp_redistribute_set(bgp, AFI_IP6, type, 0);
12016 }
12017
12018 DEFUN (no_bgp_redistribute_ipv6,
12019 no_bgp_redistribute_ipv6_cmd,
12020 "no redistribute " FRR_IP6_REDIST_STR_BGPD " [metric (0-4294967295)] [route-map WORD]",
12021 NO_STR
12022 "Redistribute information from another routing protocol\n"
12023 FRR_IP6_REDIST_HELP_STR_BGPD
12024 "Metric for redistributed routes\n"
12025 "Default metric\n"
12026 "Route map reference\n"
12027 "Pointer to route-map entries\n")
12028 {
12029 VTY_DECLVAR_CONTEXT(bgp, bgp);
12030 int idx_protocol = 2;
12031 int type;
12032
12033 type = proto_redistnum(AFI_IP6, argv[idx_protocol]->text);
12034 if (type < 0) {
12035 vty_out(vty, "%% Invalid route type\n");
12036 return CMD_WARNING_CONFIG_FAILED;
12037 }
12038
12039 return bgp_redistribute_unset(bgp, AFI_IP6, type, 0);
12040 }
12041
12042 void bgp_config_write_redistribute(struct vty *vty, struct bgp *bgp, afi_t afi,
12043 safi_t safi)
12044 {
12045 int i;
12046
12047 /* Unicast redistribution only. */
12048 if (safi != SAFI_UNICAST)
12049 return;
12050
12051 for (i = 0; i < ZEBRA_ROUTE_MAX; i++) {
12052 /* Redistribute BGP does not make sense. */
12053 if (i != ZEBRA_ROUTE_BGP) {
12054 struct list *red_list;
12055 struct listnode *node;
12056 struct bgp_redist *red;
12057
12058 red_list = bgp->redist[afi][i];
12059 if (!red_list)
12060 continue;
12061
12062 for (ALL_LIST_ELEMENTS_RO(red_list, node, red)) {
12063 /* "redistribute" configuration. */
12064 vty_out(vty, " redistribute %s",
12065 zebra_route_string(i));
12066 if (red->instance)
12067 vty_out(vty, " %d", red->instance);
12068 if (red->redist_metric_flag)
12069 vty_out(vty, " metric %u",
12070 red->redist_metric);
12071 if (red->rmap.name)
12072 vty_out(vty, " route-map %s",
12073 red->rmap.name);
12074 vty_out(vty, "\n");
12075 }
12076 }
12077 }
12078 }
12079
12080 /* This is part of the address-family block (unicast only) */
12081 void bgp_vpn_policy_config_write_afi(struct vty *vty, struct bgp *bgp,
12082 afi_t afi)
12083 {
12084 int indent = 2;
12085
12086 if (bgp->vpn_policy[afi].rmap_name[BGP_VPN_POLICY_DIR_FROMVPN])
12087 vty_out(vty, "%*simport vrf route-map %s\n", indent, "",
12088 bgp->vpn_policy[afi]
12089 .rmap_name[BGP_VPN_POLICY_DIR_FROMVPN]);
12090
12091 if (CHECK_FLAG(bgp->af_flags[afi][SAFI_UNICAST],
12092 BGP_CONFIG_VRF_TO_VRF_IMPORT)
12093 || CHECK_FLAG(bgp->af_flags[afi][SAFI_UNICAST],
12094 BGP_CONFIG_VRF_TO_VRF_EXPORT))
12095 return;
12096
12097 if (CHECK_FLAG(bgp->vpn_policy[afi].flags,
12098 BGP_VPN_POLICY_TOVPN_LABEL_AUTO)) {
12099
12100 vty_out(vty, "%*slabel vpn export %s\n", indent, "", "auto");
12101
12102 } else {
12103 if (bgp->vpn_policy[afi].tovpn_label != MPLS_LABEL_NONE) {
12104 vty_out(vty, "%*slabel vpn export %u\n", indent, "",
12105 bgp->vpn_policy[afi].tovpn_label);
12106 }
12107 }
12108 if (CHECK_FLAG(bgp->vpn_policy[afi].flags,
12109 BGP_VPN_POLICY_TOVPN_RD_SET)) {
12110 char buf[RD_ADDRSTRLEN];
12111 vty_out(vty, "%*srd vpn export %s\n", indent, "",
12112 prefix_rd2str(&bgp->vpn_policy[afi].tovpn_rd, buf,
12113 sizeof(buf)));
12114 }
12115 if (CHECK_FLAG(bgp->vpn_policy[afi].flags,
12116 BGP_VPN_POLICY_TOVPN_NEXTHOP_SET)) {
12117
12118 char buf[PREFIX_STRLEN];
12119 if (inet_ntop(bgp->vpn_policy[afi].tovpn_nexthop.family,
12120 &bgp->vpn_policy[afi].tovpn_nexthop.u.prefix, buf,
12121 sizeof(buf))) {
12122
12123 vty_out(vty, "%*snexthop vpn export %s\n",
12124 indent, "", buf);
12125 }
12126 }
12127 if (bgp->vpn_policy[afi].rtlist[BGP_VPN_POLICY_DIR_FROMVPN]
12128 && bgp->vpn_policy[afi].rtlist[BGP_VPN_POLICY_DIR_TOVPN]
12129 && ecommunity_cmp(
12130 bgp->vpn_policy[afi].rtlist[BGP_VPN_POLICY_DIR_FROMVPN],
12131 bgp->vpn_policy[afi].rtlist[BGP_VPN_POLICY_DIR_TOVPN])) {
12132
12133 char *b = ecommunity_ecom2str(
12134 bgp->vpn_policy[afi].rtlist[BGP_VPN_POLICY_DIR_TOVPN],
12135 ECOMMUNITY_FORMAT_ROUTE_MAP, ECOMMUNITY_ROUTE_TARGET);
12136 vty_out(vty, "%*srt vpn both %s\n", indent, "", b);
12137 XFREE(MTYPE_ECOMMUNITY_STR, b);
12138 } else {
12139 if (bgp->vpn_policy[afi].rtlist[BGP_VPN_POLICY_DIR_FROMVPN]) {
12140 char *b = ecommunity_ecom2str(
12141 bgp->vpn_policy[afi]
12142 .rtlist[BGP_VPN_POLICY_DIR_FROMVPN],
12143 ECOMMUNITY_FORMAT_ROUTE_MAP,
12144 ECOMMUNITY_ROUTE_TARGET);
12145 vty_out(vty, "%*srt vpn import %s\n", indent, "", b);
12146 XFREE(MTYPE_ECOMMUNITY_STR, b);
12147 }
12148 if (bgp->vpn_policy[afi].rtlist[BGP_VPN_POLICY_DIR_TOVPN]) {
12149 char *b = ecommunity_ecom2str(
12150 bgp->vpn_policy[afi]
12151 .rtlist[BGP_VPN_POLICY_DIR_TOVPN],
12152 ECOMMUNITY_FORMAT_ROUTE_MAP,
12153 ECOMMUNITY_ROUTE_TARGET);
12154 vty_out(vty, "%*srt vpn export %s\n", indent, "", b);
12155 XFREE(MTYPE_ECOMMUNITY_STR, b);
12156 }
12157 }
12158
12159 if (bgp->vpn_policy[afi].rmap_name[BGP_VPN_POLICY_DIR_TOVPN])
12160 vty_out(vty, "%*sroute-map vpn export %s\n", indent, "",
12161 bgp->vpn_policy[afi]
12162 .rmap_name[BGP_VPN_POLICY_DIR_TOVPN]);
12163
12164 if (bgp->vpn_policy[afi].import_redirect_rtlist) {
12165 char *b = ecommunity_ecom2str(
12166 bgp->vpn_policy[afi]
12167 .import_redirect_rtlist,
12168 ECOMMUNITY_FORMAT_ROUTE_MAP,
12169 ECOMMUNITY_ROUTE_TARGET);
12170
12171 vty_out(vty, "%*srt redirect import %s\n", indent, "", b);
12172 XFREE(MTYPE_ECOMMUNITY_STR, b);
12173 }
12174 }
12175
12176
12177 /* BGP node structure. */
12178 static struct cmd_node bgp_node = {
12179 BGP_NODE, "%s(config-router)# ", 1,
12180 };
12181
12182 static struct cmd_node bgp_ipv4_unicast_node = {
12183 BGP_IPV4_NODE, "%s(config-router-af)# ", 1,
12184 };
12185
12186 static struct cmd_node bgp_ipv4_multicast_node = {
12187 BGP_IPV4M_NODE, "%s(config-router-af)# ", 1,
12188 };
12189
12190 static struct cmd_node bgp_ipv4_labeled_unicast_node = {
12191 BGP_IPV4L_NODE, "%s(config-router-af)# ", 1,
12192 };
12193
12194 static struct cmd_node bgp_ipv6_unicast_node = {
12195 BGP_IPV6_NODE, "%s(config-router-af)# ", 1,
12196 };
12197
12198 static struct cmd_node bgp_ipv6_multicast_node = {
12199 BGP_IPV6M_NODE, "%s(config-router-af)# ", 1,
12200 };
12201
12202 static struct cmd_node bgp_ipv6_labeled_unicast_node = {
12203 BGP_IPV6L_NODE, "%s(config-router-af)# ", 1,
12204 };
12205
12206 static struct cmd_node bgp_vpnv4_node = {BGP_VPNV4_NODE,
12207 "%s(config-router-af)# ", 1};
12208
12209 static struct cmd_node bgp_vpnv6_node = {BGP_VPNV6_NODE,
12210 "%s(config-router-af-vpnv6)# ", 1};
12211
12212 static struct cmd_node bgp_evpn_node = {BGP_EVPN_NODE,
12213 "%s(config-router-evpn)# ", 1};
12214
12215 static struct cmd_node bgp_evpn_vni_node = {BGP_EVPN_VNI_NODE,
12216 "%s(config-router-af-vni)# ", 1};
12217
12218 static struct cmd_node bgp_flowspecv4_node = {BGP_FLOWSPECV4_NODE,
12219 "%s(config-router-af)# ", 1};
12220
12221 static struct cmd_node bgp_flowspecv6_node = {BGP_FLOWSPECV6_NODE,
12222 "%s(config-router-af-vpnv6)# ", 1};
12223
12224 static void community_list_vty(void);
12225
12226 static void bgp_ac_neighbor(vector comps, struct cmd_token *token)
12227 {
12228 struct bgp *bgp;
12229 struct peer *peer;
12230 struct listnode *lnbgp, *lnpeer;
12231
12232 for (ALL_LIST_ELEMENTS_RO(bm->bgp, lnbgp, bgp)) {
12233 for (ALL_LIST_ELEMENTS_RO(bgp->peer, lnpeer, peer)) {
12234 /* only provide suggestions on the appropriate input
12235 * token type,
12236 * they'll otherwise show up multiple times */
12237 enum cmd_token_type match_type;
12238 char *name = peer->host;
12239
12240 if (peer->conf_if) {
12241 match_type = VARIABLE_TKN;
12242 name = peer->conf_if;
12243 } else if (strchr(peer->host, ':'))
12244 match_type = IPV6_TKN;
12245 else
12246 match_type = IPV4_TKN;
12247
12248 if (token->type != match_type)
12249 continue;
12250
12251 vector_set(comps, XSTRDUP(MTYPE_COMPLETION, name));
12252 }
12253 }
12254 }
12255
12256 static const struct cmd_variable_handler bgp_var_neighbor[] = {
12257 {.varname = "neighbor", .completions = bgp_ac_neighbor},
12258 {.varname = "neighbors", .completions = bgp_ac_neighbor},
12259 {.varname = "peer", .completions = bgp_ac_neighbor},
12260 {.completions = NULL}};
12261
12262 static void bgp_ac_peergroup(vector comps, struct cmd_token *token)
12263 {
12264 struct bgp *bgp;
12265 struct peer_group *group;
12266 struct listnode *lnbgp, *lnpeer;
12267
12268 for (ALL_LIST_ELEMENTS_RO(bm->bgp, lnbgp, bgp)) {
12269 for (ALL_LIST_ELEMENTS_RO(bgp->group, lnpeer, group))
12270 vector_set(comps, XSTRDUP(MTYPE_COMPLETION,
12271 group->name));
12272 }
12273 }
12274
12275 static const struct cmd_variable_handler bgp_var_peergroup[] = {
12276 {.tokenname = "PGNAME", .completions = bgp_ac_peergroup},
12277 {.completions = NULL} };
12278
12279 void bgp_vty_init(void)
12280 {
12281 cmd_variable_handler_register(bgp_var_neighbor);
12282 cmd_variable_handler_register(bgp_var_peergroup);
12283
12284 /* Install bgp top node. */
12285 install_node(&bgp_node, bgp_config_write);
12286 install_node(&bgp_ipv4_unicast_node, NULL);
12287 install_node(&bgp_ipv4_multicast_node, NULL);
12288 install_node(&bgp_ipv4_labeled_unicast_node, NULL);
12289 install_node(&bgp_ipv6_unicast_node, NULL);
12290 install_node(&bgp_ipv6_multicast_node, NULL);
12291 install_node(&bgp_ipv6_labeled_unicast_node, NULL);
12292 install_node(&bgp_vpnv4_node, NULL);
12293 install_node(&bgp_vpnv6_node, NULL);
12294 install_node(&bgp_evpn_node, NULL);
12295 install_node(&bgp_evpn_vni_node, NULL);
12296 install_node(&bgp_flowspecv4_node, NULL);
12297 install_node(&bgp_flowspecv6_node, NULL);
12298
12299 /* Install default VTY commands to new nodes. */
12300 install_default(BGP_NODE);
12301 install_default(BGP_IPV4_NODE);
12302 install_default(BGP_IPV4M_NODE);
12303 install_default(BGP_IPV4L_NODE);
12304 install_default(BGP_IPV6_NODE);
12305 install_default(BGP_IPV6M_NODE);
12306 install_default(BGP_IPV6L_NODE);
12307 install_default(BGP_VPNV4_NODE);
12308 install_default(BGP_VPNV6_NODE);
12309 install_default(BGP_FLOWSPECV4_NODE);
12310 install_default(BGP_FLOWSPECV6_NODE);
12311 install_default(BGP_EVPN_NODE);
12312 install_default(BGP_EVPN_VNI_NODE);
12313
12314 /* "bgp multiple-instance" commands. */
12315 install_element(CONFIG_NODE, &bgp_multiple_instance_cmd);
12316 install_element(CONFIG_NODE, &no_bgp_multiple_instance_cmd);
12317
12318 /* "bgp config-type" commands. */
12319 install_element(CONFIG_NODE, &bgp_config_type_cmd);
12320 install_element(CONFIG_NODE, &no_bgp_config_type_cmd);
12321
12322 /* bgp route-map delay-timer commands. */
12323 install_element(CONFIG_NODE, &bgp_set_route_map_delay_timer_cmd);
12324 install_element(CONFIG_NODE, &no_bgp_set_route_map_delay_timer_cmd);
12325
12326 /* Dummy commands (Currently not supported) */
12327 install_element(BGP_NODE, &no_synchronization_cmd);
12328 install_element(BGP_NODE, &no_auto_summary_cmd);
12329
12330 /* "router bgp" commands. */
12331 install_element(CONFIG_NODE, &router_bgp_cmd);
12332
12333 /* "no router bgp" commands. */
12334 install_element(CONFIG_NODE, &no_router_bgp_cmd);
12335
12336 /* "bgp router-id" commands. */
12337 install_element(BGP_NODE, &bgp_router_id_cmd);
12338 install_element(BGP_NODE, &no_bgp_router_id_cmd);
12339
12340 /* "bgp cluster-id" commands. */
12341 install_element(BGP_NODE, &bgp_cluster_id_cmd);
12342 install_element(BGP_NODE, &no_bgp_cluster_id_cmd);
12343
12344 /* "bgp confederation" commands. */
12345 install_element(BGP_NODE, &bgp_confederation_identifier_cmd);
12346 install_element(BGP_NODE, &no_bgp_confederation_identifier_cmd);
12347
12348 /* "bgp confederation peers" commands. */
12349 install_element(BGP_NODE, &bgp_confederation_peers_cmd);
12350 install_element(BGP_NODE, &no_bgp_confederation_peers_cmd);
12351
12352 /* bgp max-med command */
12353 install_element(BGP_NODE, &bgp_maxmed_admin_cmd);
12354 install_element(BGP_NODE, &no_bgp_maxmed_admin_cmd);
12355 install_element(BGP_NODE, &bgp_maxmed_admin_medv_cmd);
12356 install_element(BGP_NODE, &bgp_maxmed_onstartup_cmd);
12357 install_element(BGP_NODE, &no_bgp_maxmed_onstartup_cmd);
12358
12359 /* bgp disable-ebgp-connected-nh-check */
12360 install_element(BGP_NODE, &bgp_disable_connected_route_check_cmd);
12361 install_element(BGP_NODE, &no_bgp_disable_connected_route_check_cmd);
12362
12363 /* bgp update-delay command */
12364 install_element(BGP_NODE, &bgp_update_delay_cmd);
12365 install_element(BGP_NODE, &no_bgp_update_delay_cmd);
12366 install_element(BGP_NODE, &bgp_update_delay_establish_wait_cmd);
12367
12368 install_element(BGP_NODE, &bgp_wpkt_quanta_cmd);
12369 install_element(BGP_NODE, &no_bgp_wpkt_quanta_cmd);
12370 install_element(BGP_NODE, &bgp_rpkt_quanta_cmd);
12371 install_element(BGP_NODE, &no_bgp_rpkt_quanta_cmd);
12372
12373 install_element(BGP_NODE, &bgp_coalesce_time_cmd);
12374 install_element(BGP_NODE, &no_bgp_coalesce_time_cmd);
12375
12376 /* "maximum-paths" commands. */
12377 install_element(BGP_NODE, &bgp_maxpaths_hidden_cmd);
12378 install_element(BGP_NODE, &no_bgp_maxpaths_hidden_cmd);
12379 install_element(BGP_IPV4_NODE, &bgp_maxpaths_cmd);
12380 install_element(BGP_IPV4_NODE, &no_bgp_maxpaths_cmd);
12381 install_element(BGP_IPV6_NODE, &bgp_maxpaths_cmd);
12382 install_element(BGP_IPV6_NODE, &no_bgp_maxpaths_cmd);
12383 install_element(BGP_NODE, &bgp_maxpaths_ibgp_hidden_cmd);
12384 install_element(BGP_NODE, &bgp_maxpaths_ibgp_cluster_hidden_cmd);
12385 install_element(BGP_NODE, &no_bgp_maxpaths_ibgp_hidden_cmd);
12386 install_element(BGP_IPV4_NODE, &bgp_maxpaths_ibgp_cmd);
12387 install_element(BGP_IPV4_NODE, &bgp_maxpaths_ibgp_cluster_cmd);
12388 install_element(BGP_IPV4_NODE, &no_bgp_maxpaths_ibgp_cmd);
12389 install_element(BGP_IPV6_NODE, &bgp_maxpaths_ibgp_cmd);
12390 install_element(BGP_IPV6_NODE, &bgp_maxpaths_ibgp_cluster_cmd);
12391 install_element(BGP_IPV6_NODE, &no_bgp_maxpaths_ibgp_cmd);
12392
12393 install_element(BGP_IPV6L_NODE, &bgp_maxpaths_cmd);
12394 install_element(BGP_IPV6L_NODE, &no_bgp_maxpaths_cmd);
12395 install_element(BGP_IPV6L_NODE, &bgp_maxpaths_ibgp_cmd);
12396 install_element(BGP_IPV6L_NODE, &bgp_maxpaths_ibgp_cluster_cmd);
12397 install_element(BGP_IPV6L_NODE, &no_bgp_maxpaths_ibgp_cmd);
12398
12399 /* "timers bgp" commands. */
12400 install_element(BGP_NODE, &bgp_timers_cmd);
12401 install_element(BGP_NODE, &no_bgp_timers_cmd);
12402
12403 /* route-map delay-timer commands - per instance for backwards compat.
12404 */
12405 install_element(BGP_NODE, &bgp_set_route_map_delay_timer_cmd);
12406 install_element(BGP_NODE, &no_bgp_set_route_map_delay_timer_cmd);
12407
12408 /* "bgp client-to-client reflection" commands */
12409 install_element(BGP_NODE, &no_bgp_client_to_client_reflection_cmd);
12410 install_element(BGP_NODE, &bgp_client_to_client_reflection_cmd);
12411
12412 /* "bgp always-compare-med" commands */
12413 install_element(BGP_NODE, &bgp_always_compare_med_cmd);
12414 install_element(BGP_NODE, &no_bgp_always_compare_med_cmd);
12415
12416 /* "bgp deterministic-med" commands */
12417 install_element(BGP_NODE, &bgp_deterministic_med_cmd);
12418 install_element(BGP_NODE, &no_bgp_deterministic_med_cmd);
12419
12420 /* "bgp graceful-restart" commands */
12421 install_element(BGP_NODE, &bgp_graceful_restart_cmd);
12422 install_element(BGP_NODE, &no_bgp_graceful_restart_cmd);
12423 install_element(BGP_NODE, &bgp_graceful_restart_stalepath_time_cmd);
12424 install_element(BGP_NODE, &no_bgp_graceful_restart_stalepath_time_cmd);
12425 install_element(BGP_NODE, &bgp_graceful_restart_restart_time_cmd);
12426 install_element(BGP_NODE, &no_bgp_graceful_restart_restart_time_cmd);
12427
12428 install_element(BGP_NODE, &bgp_graceful_restart_preserve_fw_cmd);
12429 install_element(BGP_NODE, &no_bgp_graceful_restart_preserve_fw_cmd);
12430
12431 /* "bgp graceful-shutdown" commands */
12432 install_element(BGP_NODE, &bgp_graceful_shutdown_cmd);
12433 install_element(BGP_NODE, &no_bgp_graceful_shutdown_cmd);
12434
12435 /* "bgp fast-external-failover" commands */
12436 install_element(BGP_NODE, &bgp_fast_external_failover_cmd);
12437 install_element(BGP_NODE, &no_bgp_fast_external_failover_cmd);
12438
12439 /* "bgp enforce-first-as" commands */
12440 install_element(BGP_NODE, &bgp_enforce_first_as_cmd);
12441 install_element(BGP_NODE, &no_bgp_enforce_first_as_cmd);
12442
12443 /* "bgp bestpath compare-routerid" commands */
12444 install_element(BGP_NODE, &bgp_bestpath_compare_router_id_cmd);
12445 install_element(BGP_NODE, &no_bgp_bestpath_compare_router_id_cmd);
12446
12447 /* "bgp bestpath as-path ignore" commands */
12448 install_element(BGP_NODE, &bgp_bestpath_aspath_ignore_cmd);
12449 install_element(BGP_NODE, &no_bgp_bestpath_aspath_ignore_cmd);
12450
12451 /* "bgp bestpath as-path confed" commands */
12452 install_element(BGP_NODE, &bgp_bestpath_aspath_confed_cmd);
12453 install_element(BGP_NODE, &no_bgp_bestpath_aspath_confed_cmd);
12454
12455 /* "bgp bestpath as-path multipath-relax" commands */
12456 install_element(BGP_NODE, &bgp_bestpath_aspath_multipath_relax_cmd);
12457 install_element(BGP_NODE, &no_bgp_bestpath_aspath_multipath_relax_cmd);
12458
12459 /* "bgp log-neighbor-changes" commands */
12460 install_element(BGP_NODE, &bgp_log_neighbor_changes_cmd);
12461 install_element(BGP_NODE, &no_bgp_log_neighbor_changes_cmd);
12462
12463 /* "bgp bestpath med" commands */
12464 install_element(BGP_NODE, &bgp_bestpath_med_cmd);
12465 install_element(BGP_NODE, &no_bgp_bestpath_med_cmd);
12466
12467 /* "no bgp default ipv4-unicast" commands. */
12468 install_element(BGP_NODE, &no_bgp_default_ipv4_unicast_cmd);
12469 install_element(BGP_NODE, &bgp_default_ipv4_unicast_cmd);
12470
12471 /* "bgp network import-check" commands. */
12472 install_element(BGP_NODE, &bgp_network_import_check_cmd);
12473 install_element(BGP_NODE, &bgp_network_import_check_exact_cmd);
12474 install_element(BGP_NODE, &no_bgp_network_import_check_cmd);
12475
12476 /* "bgp default local-preference" commands. */
12477 install_element(BGP_NODE, &bgp_default_local_preference_cmd);
12478 install_element(BGP_NODE, &no_bgp_default_local_preference_cmd);
12479
12480 /* bgp default show-hostname */
12481 install_element(BGP_NODE, &bgp_default_show_hostname_cmd);
12482 install_element(BGP_NODE, &no_bgp_default_show_hostname_cmd);
12483
12484 /* "bgp default subgroup-pkt-queue-max" commands. */
12485 install_element(BGP_NODE, &bgp_default_subgroup_pkt_queue_max_cmd);
12486 install_element(BGP_NODE, &no_bgp_default_subgroup_pkt_queue_max_cmd);
12487
12488 /* bgp ibgp-allow-policy-mods command */
12489 install_element(BGP_NODE, &bgp_rr_allow_outbound_policy_cmd);
12490 install_element(BGP_NODE, &no_bgp_rr_allow_outbound_policy_cmd);
12491
12492 /* "bgp listen limit" commands. */
12493 install_element(BGP_NODE, &bgp_listen_limit_cmd);
12494 install_element(BGP_NODE, &no_bgp_listen_limit_cmd);
12495
12496 /* "bgp listen range" commands. */
12497 install_element(BGP_NODE, &bgp_listen_range_cmd);
12498 install_element(BGP_NODE, &no_bgp_listen_range_cmd);
12499
12500 /* "bgp default shutdown" command */
12501 install_element(BGP_NODE, &bgp_default_shutdown_cmd);
12502
12503 /* "neighbor remote-as" commands. */
12504 install_element(BGP_NODE, &neighbor_remote_as_cmd);
12505 install_element(BGP_NODE, &neighbor_interface_config_cmd);
12506 install_element(BGP_NODE, &neighbor_interface_config_v6only_cmd);
12507 install_element(BGP_NODE, &neighbor_interface_config_remote_as_cmd);
12508 install_element(BGP_NODE,
12509 &neighbor_interface_v6only_config_remote_as_cmd);
12510 install_element(BGP_NODE, &no_neighbor_cmd);
12511 install_element(BGP_NODE, &no_neighbor_interface_config_cmd);
12512
12513 /* "neighbor peer-group" commands. */
12514 install_element(BGP_NODE, &neighbor_peer_group_cmd);
12515 install_element(BGP_NODE, &no_neighbor_peer_group_cmd);
12516 install_element(BGP_NODE,
12517 &no_neighbor_interface_peer_group_remote_as_cmd);
12518
12519 /* "neighbor local-as" commands. */
12520 install_element(BGP_NODE, &neighbor_local_as_cmd);
12521 install_element(BGP_NODE, &neighbor_local_as_no_prepend_cmd);
12522 install_element(BGP_NODE, &neighbor_local_as_no_prepend_replace_as_cmd);
12523 install_element(BGP_NODE, &no_neighbor_local_as_cmd);
12524
12525 /* "neighbor solo" commands. */
12526 install_element(BGP_NODE, &neighbor_solo_cmd);
12527 install_element(BGP_NODE, &no_neighbor_solo_cmd);
12528
12529 /* "neighbor password" commands. */
12530 install_element(BGP_NODE, &neighbor_password_cmd);
12531 install_element(BGP_NODE, &no_neighbor_password_cmd);
12532
12533 /* "neighbor activate" commands. */
12534 install_element(BGP_NODE, &neighbor_activate_hidden_cmd);
12535 install_element(BGP_IPV4_NODE, &neighbor_activate_cmd);
12536 install_element(BGP_IPV4M_NODE, &neighbor_activate_cmd);
12537 install_element(BGP_IPV4L_NODE, &neighbor_activate_cmd);
12538 install_element(BGP_IPV6_NODE, &neighbor_activate_cmd);
12539 install_element(BGP_IPV6M_NODE, &neighbor_activate_cmd);
12540 install_element(BGP_IPV6L_NODE, &neighbor_activate_cmd);
12541 install_element(BGP_VPNV4_NODE, &neighbor_activate_cmd);
12542 install_element(BGP_VPNV6_NODE, &neighbor_activate_cmd);
12543 install_element(BGP_FLOWSPECV4_NODE, &neighbor_activate_cmd);
12544 install_element(BGP_FLOWSPECV6_NODE, &neighbor_activate_cmd);
12545 install_element(BGP_EVPN_NODE, &neighbor_activate_cmd);
12546
12547 /* "no neighbor activate" commands. */
12548 install_element(BGP_NODE, &no_neighbor_activate_hidden_cmd);
12549 install_element(BGP_IPV4_NODE, &no_neighbor_activate_cmd);
12550 install_element(BGP_IPV4M_NODE, &no_neighbor_activate_cmd);
12551 install_element(BGP_IPV4L_NODE, &no_neighbor_activate_cmd);
12552 install_element(BGP_IPV6_NODE, &no_neighbor_activate_cmd);
12553 install_element(BGP_IPV6M_NODE, &no_neighbor_activate_cmd);
12554 install_element(BGP_IPV6L_NODE, &no_neighbor_activate_cmd);
12555 install_element(BGP_VPNV4_NODE, &no_neighbor_activate_cmd);
12556 install_element(BGP_VPNV6_NODE, &no_neighbor_activate_cmd);
12557 install_element(BGP_FLOWSPECV4_NODE, &no_neighbor_activate_cmd);
12558 install_element(BGP_FLOWSPECV6_NODE, &no_neighbor_activate_cmd);
12559 install_element(BGP_EVPN_NODE, &no_neighbor_activate_cmd);
12560
12561 /* "neighbor peer-group" set commands. */
12562 install_element(BGP_NODE, &neighbor_set_peer_group_cmd);
12563 install_element(BGP_IPV4_NODE, &neighbor_set_peer_group_hidden_cmd);
12564 install_element(BGP_IPV4M_NODE, &neighbor_set_peer_group_hidden_cmd);
12565 install_element(BGP_IPV6_NODE, &neighbor_set_peer_group_hidden_cmd);
12566 install_element(BGP_IPV6M_NODE, &neighbor_set_peer_group_hidden_cmd);
12567 install_element(BGP_IPV6L_NODE, &neighbor_set_peer_group_hidden_cmd);
12568 install_element(BGP_VPNV4_NODE, &neighbor_set_peer_group_hidden_cmd);
12569 install_element(BGP_VPNV6_NODE, &neighbor_set_peer_group_hidden_cmd);
12570 install_element(BGP_FLOWSPECV4_NODE,
12571 &neighbor_set_peer_group_hidden_cmd);
12572 install_element(BGP_FLOWSPECV6_NODE,
12573 &neighbor_set_peer_group_hidden_cmd);
12574
12575 /* "no neighbor peer-group unset" commands. */
12576 install_element(BGP_NODE, &no_neighbor_set_peer_group_cmd);
12577 install_element(BGP_IPV4_NODE, &no_neighbor_set_peer_group_hidden_cmd);
12578 install_element(BGP_IPV4M_NODE, &no_neighbor_set_peer_group_hidden_cmd);
12579 install_element(BGP_IPV6_NODE, &no_neighbor_set_peer_group_hidden_cmd);
12580 install_element(BGP_IPV6M_NODE, &no_neighbor_set_peer_group_hidden_cmd);
12581 install_element(BGP_IPV6L_NODE, &no_neighbor_set_peer_group_hidden_cmd);
12582 install_element(BGP_VPNV4_NODE, &no_neighbor_set_peer_group_hidden_cmd);
12583 install_element(BGP_VPNV6_NODE, &no_neighbor_set_peer_group_hidden_cmd);
12584 install_element(BGP_FLOWSPECV4_NODE,
12585 &no_neighbor_set_peer_group_hidden_cmd);
12586 install_element(BGP_FLOWSPECV6_NODE,
12587 &no_neighbor_set_peer_group_hidden_cmd);
12588
12589 /* "neighbor softreconfiguration inbound" commands.*/
12590 install_element(BGP_NODE, &neighbor_soft_reconfiguration_hidden_cmd);
12591 install_element(BGP_NODE, &no_neighbor_soft_reconfiguration_hidden_cmd);
12592 install_element(BGP_IPV4_NODE, &neighbor_soft_reconfiguration_cmd);
12593 install_element(BGP_IPV4_NODE, &no_neighbor_soft_reconfiguration_cmd);
12594 install_element(BGP_IPV4L_NODE, &neighbor_soft_reconfiguration_cmd);
12595 install_element(BGP_IPV4L_NODE, &no_neighbor_soft_reconfiguration_cmd);
12596 install_element(BGP_IPV4M_NODE, &neighbor_soft_reconfiguration_cmd);
12597 install_element(BGP_IPV4M_NODE, &no_neighbor_soft_reconfiguration_cmd);
12598 install_element(BGP_IPV6_NODE, &neighbor_soft_reconfiguration_cmd);
12599 install_element(BGP_IPV6_NODE, &no_neighbor_soft_reconfiguration_cmd);
12600 install_element(BGP_IPV6M_NODE, &neighbor_soft_reconfiguration_cmd);
12601 install_element(BGP_IPV6M_NODE, &no_neighbor_soft_reconfiguration_cmd);
12602 install_element(BGP_IPV6L_NODE, &neighbor_soft_reconfiguration_cmd);
12603 install_element(BGP_IPV6L_NODE, &no_neighbor_soft_reconfiguration_cmd);
12604 install_element(BGP_VPNV4_NODE, &neighbor_soft_reconfiguration_cmd);
12605 install_element(BGP_VPNV4_NODE, &no_neighbor_soft_reconfiguration_cmd);
12606 install_element(BGP_VPNV6_NODE, &neighbor_soft_reconfiguration_cmd);
12607 install_element(BGP_VPNV6_NODE, &no_neighbor_soft_reconfiguration_cmd);
12608 install_element(BGP_FLOWSPECV4_NODE,
12609 &neighbor_soft_reconfiguration_cmd);
12610 install_element(BGP_FLOWSPECV4_NODE,
12611 &no_neighbor_soft_reconfiguration_cmd);
12612 install_element(BGP_FLOWSPECV6_NODE,
12613 &neighbor_soft_reconfiguration_cmd);
12614 install_element(BGP_FLOWSPECV6_NODE,
12615 &no_neighbor_soft_reconfiguration_cmd);
12616
12617 /* "neighbor attribute-unchanged" commands. */
12618 install_element(BGP_NODE, &neighbor_attr_unchanged_hidden_cmd);
12619 install_element(BGP_NODE, &no_neighbor_attr_unchanged_hidden_cmd);
12620 install_element(BGP_IPV4_NODE, &neighbor_attr_unchanged_cmd);
12621 install_element(BGP_IPV4_NODE, &no_neighbor_attr_unchanged_cmd);
12622 install_element(BGP_IPV4M_NODE, &neighbor_attr_unchanged_cmd);
12623 install_element(BGP_IPV4M_NODE, &no_neighbor_attr_unchanged_cmd);
12624 install_element(BGP_IPV4L_NODE, &neighbor_attr_unchanged_cmd);
12625 install_element(BGP_IPV4L_NODE, &no_neighbor_attr_unchanged_cmd);
12626 install_element(BGP_IPV6_NODE, &neighbor_attr_unchanged_cmd);
12627 install_element(BGP_IPV6_NODE, &no_neighbor_attr_unchanged_cmd);
12628 install_element(BGP_IPV6M_NODE, &neighbor_attr_unchanged_cmd);
12629 install_element(BGP_IPV6M_NODE, &no_neighbor_attr_unchanged_cmd);
12630 install_element(BGP_IPV6L_NODE, &neighbor_attr_unchanged_cmd);
12631 install_element(BGP_IPV6L_NODE, &no_neighbor_attr_unchanged_cmd);
12632 install_element(BGP_VPNV4_NODE, &neighbor_attr_unchanged_cmd);
12633 install_element(BGP_VPNV4_NODE, &no_neighbor_attr_unchanged_cmd);
12634 install_element(BGP_VPNV6_NODE, &neighbor_attr_unchanged_cmd);
12635 install_element(BGP_VPNV6_NODE, &no_neighbor_attr_unchanged_cmd);
12636
12637 install_element(BGP_EVPN_NODE, &neighbor_attr_unchanged_cmd);
12638 install_element(BGP_EVPN_NODE, &no_neighbor_attr_unchanged_cmd);
12639
12640 /* "nexthop-local unchanged" commands */
12641 install_element(BGP_IPV6_NODE, &neighbor_nexthop_local_unchanged_cmd);
12642 install_element(BGP_IPV6_NODE,
12643 &no_neighbor_nexthop_local_unchanged_cmd);
12644
12645 /* "neighbor next-hop-self" commands. */
12646 install_element(BGP_NODE, &neighbor_nexthop_self_hidden_cmd);
12647 install_element(BGP_NODE, &no_neighbor_nexthop_self_hidden_cmd);
12648 install_element(BGP_IPV4_NODE, &neighbor_nexthop_self_cmd);
12649 install_element(BGP_IPV4_NODE, &no_neighbor_nexthop_self_cmd);
12650 install_element(BGP_IPV4M_NODE, &neighbor_nexthop_self_cmd);
12651 install_element(BGP_IPV4M_NODE, &no_neighbor_nexthop_self_cmd);
12652 install_element(BGP_IPV4L_NODE, &neighbor_nexthop_self_cmd);
12653 install_element(BGP_IPV4L_NODE, &no_neighbor_nexthop_self_cmd);
12654 install_element(BGP_IPV6_NODE, &neighbor_nexthop_self_cmd);
12655 install_element(BGP_IPV6_NODE, &no_neighbor_nexthop_self_cmd);
12656 install_element(BGP_IPV6M_NODE, &neighbor_nexthop_self_cmd);
12657 install_element(BGP_IPV6M_NODE, &no_neighbor_nexthop_self_cmd);
12658 install_element(BGP_IPV6L_NODE, &neighbor_nexthop_self_cmd);
12659 install_element(BGP_IPV6L_NODE, &no_neighbor_nexthop_self_cmd);
12660 install_element(BGP_VPNV4_NODE, &neighbor_nexthop_self_cmd);
12661 install_element(BGP_VPNV4_NODE, &no_neighbor_nexthop_self_cmd);
12662 install_element(BGP_VPNV6_NODE, &neighbor_nexthop_self_cmd);
12663 install_element(BGP_VPNV6_NODE, &no_neighbor_nexthop_self_cmd);
12664 install_element(BGP_EVPN_NODE, &neighbor_nexthop_self_cmd);
12665 install_element(BGP_EVPN_NODE, &no_neighbor_nexthop_self_cmd);
12666
12667 /* "neighbor next-hop-self force" commands. */
12668 install_element(BGP_NODE, &neighbor_nexthop_self_force_hidden_cmd);
12669 install_element(BGP_NODE, &no_neighbor_nexthop_self_force_hidden_cmd);
12670 install_element(BGP_IPV4_NODE, &neighbor_nexthop_self_force_cmd);
12671 install_element(BGP_IPV4_NODE, &no_neighbor_nexthop_self_force_cmd);
12672 install_element(BGP_IPV4M_NODE, &neighbor_nexthop_self_force_cmd);
12673 install_element(BGP_IPV4M_NODE, &no_neighbor_nexthop_self_force_cmd);
12674 install_element(BGP_IPV4L_NODE, &neighbor_nexthop_self_force_cmd);
12675 install_element(BGP_IPV4L_NODE, &no_neighbor_nexthop_self_force_cmd);
12676 install_element(BGP_IPV6_NODE, &neighbor_nexthop_self_force_cmd);
12677 install_element(BGP_IPV6_NODE, &no_neighbor_nexthop_self_force_cmd);
12678 install_element(BGP_IPV6M_NODE, &neighbor_nexthop_self_force_cmd);
12679 install_element(BGP_IPV6M_NODE, &no_neighbor_nexthop_self_force_cmd);
12680 install_element(BGP_IPV6L_NODE, &neighbor_nexthop_self_force_cmd);
12681 install_element(BGP_IPV6L_NODE, &no_neighbor_nexthop_self_force_cmd);
12682 install_element(BGP_VPNV4_NODE, &neighbor_nexthop_self_force_cmd);
12683 install_element(BGP_VPNV4_NODE, &no_neighbor_nexthop_self_force_cmd);
12684 install_element(BGP_VPNV6_NODE, &neighbor_nexthop_self_force_cmd);
12685 install_element(BGP_VPNV6_NODE, &no_neighbor_nexthop_self_force_cmd);
12686
12687 /* "neighbor as-override" commands. */
12688 install_element(BGP_NODE, &neighbor_as_override_hidden_cmd);
12689 install_element(BGP_NODE, &no_neighbor_as_override_hidden_cmd);
12690 install_element(BGP_IPV4_NODE, &neighbor_as_override_cmd);
12691 install_element(BGP_IPV4_NODE, &no_neighbor_as_override_cmd);
12692 install_element(BGP_IPV4M_NODE, &neighbor_as_override_cmd);
12693 install_element(BGP_IPV4M_NODE, &no_neighbor_as_override_cmd);
12694 install_element(BGP_IPV4L_NODE, &neighbor_as_override_cmd);
12695 install_element(BGP_IPV4L_NODE, &no_neighbor_as_override_cmd);
12696 install_element(BGP_IPV6_NODE, &neighbor_as_override_cmd);
12697 install_element(BGP_IPV6_NODE, &no_neighbor_as_override_cmd);
12698 install_element(BGP_IPV6M_NODE, &neighbor_as_override_cmd);
12699 install_element(BGP_IPV6M_NODE, &no_neighbor_as_override_cmd);
12700 install_element(BGP_IPV6L_NODE, &neighbor_as_override_cmd);
12701 install_element(BGP_IPV6L_NODE, &no_neighbor_as_override_cmd);
12702 install_element(BGP_VPNV4_NODE, &neighbor_as_override_cmd);
12703 install_element(BGP_VPNV4_NODE, &no_neighbor_as_override_cmd);
12704 install_element(BGP_VPNV6_NODE, &neighbor_as_override_cmd);
12705 install_element(BGP_VPNV6_NODE, &no_neighbor_as_override_cmd);
12706
12707 /* "neighbor remove-private-AS" commands. */
12708 install_element(BGP_NODE, &neighbor_remove_private_as_hidden_cmd);
12709 install_element(BGP_NODE, &no_neighbor_remove_private_as_hidden_cmd);
12710 install_element(BGP_NODE, &neighbor_remove_private_as_all_hidden_cmd);
12711 install_element(BGP_NODE,
12712 &no_neighbor_remove_private_as_all_hidden_cmd);
12713 install_element(BGP_NODE,
12714 &neighbor_remove_private_as_replace_as_hidden_cmd);
12715 install_element(BGP_NODE,
12716 &no_neighbor_remove_private_as_replace_as_hidden_cmd);
12717 install_element(BGP_NODE,
12718 &neighbor_remove_private_as_all_replace_as_hidden_cmd);
12719 install_element(
12720 BGP_NODE,
12721 &no_neighbor_remove_private_as_all_replace_as_hidden_cmd);
12722 install_element(BGP_IPV4_NODE, &neighbor_remove_private_as_cmd);
12723 install_element(BGP_IPV4_NODE, &no_neighbor_remove_private_as_cmd);
12724 install_element(BGP_IPV4_NODE, &neighbor_remove_private_as_all_cmd);
12725 install_element(BGP_IPV4_NODE, &no_neighbor_remove_private_as_all_cmd);
12726 install_element(BGP_IPV4_NODE,
12727 &neighbor_remove_private_as_replace_as_cmd);
12728 install_element(BGP_IPV4_NODE,
12729 &no_neighbor_remove_private_as_replace_as_cmd);
12730 install_element(BGP_IPV4_NODE,
12731 &neighbor_remove_private_as_all_replace_as_cmd);
12732 install_element(BGP_IPV4_NODE,
12733 &no_neighbor_remove_private_as_all_replace_as_cmd);
12734 install_element(BGP_IPV4M_NODE, &neighbor_remove_private_as_cmd);
12735 install_element(BGP_IPV4M_NODE, &no_neighbor_remove_private_as_cmd);
12736 install_element(BGP_IPV4M_NODE, &neighbor_remove_private_as_all_cmd);
12737 install_element(BGP_IPV4M_NODE, &no_neighbor_remove_private_as_all_cmd);
12738 install_element(BGP_IPV4M_NODE,
12739 &neighbor_remove_private_as_replace_as_cmd);
12740 install_element(BGP_IPV4M_NODE,
12741 &no_neighbor_remove_private_as_replace_as_cmd);
12742 install_element(BGP_IPV4M_NODE,
12743 &neighbor_remove_private_as_all_replace_as_cmd);
12744 install_element(BGP_IPV4M_NODE,
12745 &no_neighbor_remove_private_as_all_replace_as_cmd);
12746 install_element(BGP_IPV4L_NODE, &neighbor_remove_private_as_cmd);
12747 install_element(BGP_IPV4L_NODE, &no_neighbor_remove_private_as_cmd);
12748 install_element(BGP_IPV4L_NODE, &neighbor_remove_private_as_all_cmd);
12749 install_element(BGP_IPV4L_NODE, &no_neighbor_remove_private_as_all_cmd);
12750 install_element(BGP_IPV4L_NODE,
12751 &neighbor_remove_private_as_replace_as_cmd);
12752 install_element(BGP_IPV4L_NODE,
12753 &no_neighbor_remove_private_as_replace_as_cmd);
12754 install_element(BGP_IPV4L_NODE,
12755 &neighbor_remove_private_as_all_replace_as_cmd);
12756 install_element(BGP_IPV4L_NODE,
12757 &no_neighbor_remove_private_as_all_replace_as_cmd);
12758 install_element(BGP_IPV6_NODE, &neighbor_remove_private_as_cmd);
12759 install_element(BGP_IPV6_NODE, &no_neighbor_remove_private_as_cmd);
12760 install_element(BGP_IPV6_NODE, &neighbor_remove_private_as_all_cmd);
12761 install_element(BGP_IPV6_NODE, &no_neighbor_remove_private_as_all_cmd);
12762 install_element(BGP_IPV6_NODE,
12763 &neighbor_remove_private_as_replace_as_cmd);
12764 install_element(BGP_IPV6_NODE,
12765 &no_neighbor_remove_private_as_replace_as_cmd);
12766 install_element(BGP_IPV6_NODE,
12767 &neighbor_remove_private_as_all_replace_as_cmd);
12768 install_element(BGP_IPV6_NODE,
12769 &no_neighbor_remove_private_as_all_replace_as_cmd);
12770 install_element(BGP_IPV6M_NODE, &neighbor_remove_private_as_cmd);
12771 install_element(BGP_IPV6M_NODE, &no_neighbor_remove_private_as_cmd);
12772 install_element(BGP_IPV6M_NODE, &neighbor_remove_private_as_all_cmd);
12773 install_element(BGP_IPV6M_NODE, &no_neighbor_remove_private_as_all_cmd);
12774 install_element(BGP_IPV6M_NODE,
12775 &neighbor_remove_private_as_replace_as_cmd);
12776 install_element(BGP_IPV6M_NODE,
12777 &no_neighbor_remove_private_as_replace_as_cmd);
12778 install_element(BGP_IPV6M_NODE,
12779 &neighbor_remove_private_as_all_replace_as_cmd);
12780 install_element(BGP_IPV6M_NODE,
12781 &no_neighbor_remove_private_as_all_replace_as_cmd);
12782 install_element(BGP_IPV6L_NODE, &neighbor_remove_private_as_cmd);
12783 install_element(BGP_IPV6L_NODE, &no_neighbor_remove_private_as_cmd);
12784 install_element(BGP_IPV6L_NODE, &neighbor_remove_private_as_all_cmd);
12785 install_element(BGP_IPV6L_NODE, &no_neighbor_remove_private_as_all_cmd);
12786 install_element(BGP_IPV6L_NODE,
12787 &neighbor_remove_private_as_replace_as_cmd);
12788 install_element(BGP_IPV6L_NODE,
12789 &no_neighbor_remove_private_as_replace_as_cmd);
12790 install_element(BGP_IPV6L_NODE,
12791 &neighbor_remove_private_as_all_replace_as_cmd);
12792 install_element(BGP_IPV6L_NODE,
12793 &no_neighbor_remove_private_as_all_replace_as_cmd);
12794 install_element(BGP_VPNV4_NODE, &neighbor_remove_private_as_cmd);
12795 install_element(BGP_VPNV4_NODE, &no_neighbor_remove_private_as_cmd);
12796 install_element(BGP_VPNV4_NODE, &neighbor_remove_private_as_all_cmd);
12797 install_element(BGP_VPNV4_NODE, &no_neighbor_remove_private_as_all_cmd);
12798 install_element(BGP_VPNV4_NODE,
12799 &neighbor_remove_private_as_replace_as_cmd);
12800 install_element(BGP_VPNV4_NODE,
12801 &no_neighbor_remove_private_as_replace_as_cmd);
12802 install_element(BGP_VPNV4_NODE,
12803 &neighbor_remove_private_as_all_replace_as_cmd);
12804 install_element(BGP_VPNV4_NODE,
12805 &no_neighbor_remove_private_as_all_replace_as_cmd);
12806 install_element(BGP_VPNV6_NODE, &neighbor_remove_private_as_cmd);
12807 install_element(BGP_VPNV6_NODE, &no_neighbor_remove_private_as_cmd);
12808 install_element(BGP_VPNV6_NODE, &neighbor_remove_private_as_all_cmd);
12809 install_element(BGP_VPNV6_NODE, &no_neighbor_remove_private_as_all_cmd);
12810 install_element(BGP_VPNV6_NODE,
12811 &neighbor_remove_private_as_replace_as_cmd);
12812 install_element(BGP_VPNV6_NODE,
12813 &no_neighbor_remove_private_as_replace_as_cmd);
12814 install_element(BGP_VPNV6_NODE,
12815 &neighbor_remove_private_as_all_replace_as_cmd);
12816 install_element(BGP_VPNV6_NODE,
12817 &no_neighbor_remove_private_as_all_replace_as_cmd);
12818
12819 /* "neighbor send-community" commands.*/
12820 install_element(BGP_NODE, &neighbor_send_community_hidden_cmd);
12821 install_element(BGP_NODE, &neighbor_send_community_type_hidden_cmd);
12822 install_element(BGP_NODE, &no_neighbor_send_community_hidden_cmd);
12823 install_element(BGP_NODE, &no_neighbor_send_community_type_hidden_cmd);
12824 install_element(BGP_IPV4_NODE, &neighbor_send_community_cmd);
12825 install_element(BGP_IPV4_NODE, &neighbor_send_community_type_cmd);
12826 install_element(BGP_IPV4_NODE, &no_neighbor_send_community_cmd);
12827 install_element(BGP_IPV4_NODE, &no_neighbor_send_community_type_cmd);
12828 install_element(BGP_IPV4M_NODE, &neighbor_send_community_cmd);
12829 install_element(BGP_IPV4M_NODE, &neighbor_send_community_type_cmd);
12830 install_element(BGP_IPV4M_NODE, &no_neighbor_send_community_cmd);
12831 install_element(BGP_IPV4M_NODE, &no_neighbor_send_community_type_cmd);
12832 install_element(BGP_IPV4L_NODE, &neighbor_send_community_cmd);
12833 install_element(BGP_IPV4L_NODE, &neighbor_send_community_type_cmd);
12834 install_element(BGP_IPV4L_NODE, &no_neighbor_send_community_cmd);
12835 install_element(BGP_IPV4L_NODE, &no_neighbor_send_community_type_cmd);
12836 install_element(BGP_IPV6_NODE, &neighbor_send_community_cmd);
12837 install_element(BGP_IPV6_NODE, &neighbor_send_community_type_cmd);
12838 install_element(BGP_IPV6_NODE, &no_neighbor_send_community_cmd);
12839 install_element(BGP_IPV6_NODE, &no_neighbor_send_community_type_cmd);
12840 install_element(BGP_IPV6M_NODE, &neighbor_send_community_cmd);
12841 install_element(BGP_IPV6M_NODE, &neighbor_send_community_type_cmd);
12842 install_element(BGP_IPV6M_NODE, &no_neighbor_send_community_cmd);
12843 install_element(BGP_IPV6M_NODE, &no_neighbor_send_community_type_cmd);
12844 install_element(BGP_IPV6L_NODE, &neighbor_send_community_cmd);
12845 install_element(BGP_IPV6L_NODE, &neighbor_send_community_type_cmd);
12846 install_element(BGP_IPV6L_NODE, &no_neighbor_send_community_cmd);
12847 install_element(BGP_IPV6L_NODE, &no_neighbor_send_community_type_cmd);
12848 install_element(BGP_VPNV4_NODE, &neighbor_send_community_cmd);
12849 install_element(BGP_VPNV4_NODE, &neighbor_send_community_type_cmd);
12850 install_element(BGP_VPNV4_NODE, &no_neighbor_send_community_cmd);
12851 install_element(BGP_VPNV4_NODE, &no_neighbor_send_community_type_cmd);
12852 install_element(BGP_VPNV6_NODE, &neighbor_send_community_cmd);
12853 install_element(BGP_VPNV6_NODE, &neighbor_send_community_type_cmd);
12854 install_element(BGP_VPNV6_NODE, &no_neighbor_send_community_cmd);
12855 install_element(BGP_VPNV6_NODE, &no_neighbor_send_community_type_cmd);
12856
12857 /* "neighbor route-reflector" commands.*/
12858 install_element(BGP_NODE, &neighbor_route_reflector_client_hidden_cmd);
12859 install_element(BGP_NODE,
12860 &no_neighbor_route_reflector_client_hidden_cmd);
12861 install_element(BGP_IPV4_NODE, &neighbor_route_reflector_client_cmd);
12862 install_element(BGP_IPV4_NODE, &no_neighbor_route_reflector_client_cmd);
12863 install_element(BGP_IPV4M_NODE, &neighbor_route_reflector_client_cmd);
12864 install_element(BGP_IPV4M_NODE,
12865 &no_neighbor_route_reflector_client_cmd);
12866 install_element(BGP_IPV4L_NODE, &neighbor_route_reflector_client_cmd);
12867 install_element(BGP_IPV4L_NODE,
12868 &no_neighbor_route_reflector_client_cmd);
12869 install_element(BGP_IPV6_NODE, &neighbor_route_reflector_client_cmd);
12870 install_element(BGP_IPV6_NODE, &no_neighbor_route_reflector_client_cmd);
12871 install_element(BGP_IPV6M_NODE, &neighbor_route_reflector_client_cmd);
12872 install_element(BGP_IPV6M_NODE,
12873 &no_neighbor_route_reflector_client_cmd);
12874 install_element(BGP_IPV6L_NODE, &neighbor_route_reflector_client_cmd);
12875 install_element(BGP_IPV6L_NODE,
12876 &no_neighbor_route_reflector_client_cmd);
12877 install_element(BGP_VPNV4_NODE, &neighbor_route_reflector_client_cmd);
12878 install_element(BGP_VPNV4_NODE,
12879 &no_neighbor_route_reflector_client_cmd);
12880 install_element(BGP_VPNV6_NODE, &neighbor_route_reflector_client_cmd);
12881 install_element(BGP_VPNV6_NODE,
12882 &no_neighbor_route_reflector_client_cmd);
12883 install_element(BGP_FLOWSPECV4_NODE,
12884 &neighbor_route_reflector_client_cmd);
12885 install_element(BGP_FLOWSPECV4_NODE,
12886 &no_neighbor_route_reflector_client_cmd);
12887 install_element(BGP_FLOWSPECV6_NODE,
12888 &neighbor_route_reflector_client_cmd);
12889 install_element(BGP_FLOWSPECV6_NODE,
12890 &no_neighbor_route_reflector_client_cmd);
12891 install_element(BGP_EVPN_NODE, &neighbor_route_reflector_client_cmd);
12892 install_element(BGP_EVPN_NODE, &no_neighbor_route_reflector_client_cmd);
12893
12894 /* "neighbor route-server" commands.*/
12895 install_element(BGP_NODE, &neighbor_route_server_client_hidden_cmd);
12896 install_element(BGP_NODE, &no_neighbor_route_server_client_hidden_cmd);
12897 install_element(BGP_IPV4_NODE, &neighbor_route_server_client_cmd);
12898 install_element(BGP_IPV4_NODE, &no_neighbor_route_server_client_cmd);
12899 install_element(BGP_IPV4M_NODE, &neighbor_route_server_client_cmd);
12900 install_element(BGP_IPV4M_NODE, &no_neighbor_route_server_client_cmd);
12901 install_element(BGP_IPV4L_NODE, &neighbor_route_server_client_cmd);
12902 install_element(BGP_IPV4L_NODE, &no_neighbor_route_server_client_cmd);
12903 install_element(BGP_IPV6_NODE, &neighbor_route_server_client_cmd);
12904 install_element(BGP_IPV6_NODE, &no_neighbor_route_server_client_cmd);
12905 install_element(BGP_IPV6M_NODE, &neighbor_route_server_client_cmd);
12906 install_element(BGP_IPV6M_NODE, &no_neighbor_route_server_client_cmd);
12907 install_element(BGP_IPV6L_NODE, &neighbor_route_server_client_cmd);
12908 install_element(BGP_IPV6L_NODE, &no_neighbor_route_server_client_cmd);
12909 install_element(BGP_VPNV4_NODE, &neighbor_route_server_client_cmd);
12910 install_element(BGP_VPNV4_NODE, &no_neighbor_route_server_client_cmd);
12911 install_element(BGP_VPNV6_NODE, &neighbor_route_server_client_cmd);
12912 install_element(BGP_VPNV6_NODE, &no_neighbor_route_server_client_cmd);
12913 install_element(BGP_FLOWSPECV4_NODE, &neighbor_route_server_client_cmd);
12914 install_element(BGP_FLOWSPECV4_NODE,
12915 &no_neighbor_route_server_client_cmd);
12916 install_element(BGP_FLOWSPECV6_NODE, &neighbor_route_server_client_cmd);
12917 install_element(BGP_FLOWSPECV6_NODE,
12918 &no_neighbor_route_server_client_cmd);
12919
12920 /* "neighbor addpath-tx-all-paths" commands.*/
12921 install_element(BGP_NODE, &neighbor_addpath_tx_all_paths_hidden_cmd);
12922 install_element(BGP_NODE, &no_neighbor_addpath_tx_all_paths_hidden_cmd);
12923 install_element(BGP_IPV4_NODE, &neighbor_addpath_tx_all_paths_cmd);
12924 install_element(BGP_IPV4_NODE, &no_neighbor_addpath_tx_all_paths_cmd);
12925 install_element(BGP_IPV4M_NODE, &neighbor_addpath_tx_all_paths_cmd);
12926 install_element(BGP_IPV4M_NODE, &no_neighbor_addpath_tx_all_paths_cmd);
12927 install_element(BGP_IPV4L_NODE, &neighbor_addpath_tx_all_paths_cmd);
12928 install_element(BGP_IPV4L_NODE, &no_neighbor_addpath_tx_all_paths_cmd);
12929 install_element(BGP_IPV6_NODE, &neighbor_addpath_tx_all_paths_cmd);
12930 install_element(BGP_IPV6_NODE, &no_neighbor_addpath_tx_all_paths_cmd);
12931 install_element(BGP_IPV6M_NODE, &neighbor_addpath_tx_all_paths_cmd);
12932 install_element(BGP_IPV6M_NODE, &no_neighbor_addpath_tx_all_paths_cmd);
12933 install_element(BGP_IPV6L_NODE, &neighbor_addpath_tx_all_paths_cmd);
12934 install_element(BGP_IPV6L_NODE, &no_neighbor_addpath_tx_all_paths_cmd);
12935 install_element(BGP_VPNV4_NODE, &neighbor_addpath_tx_all_paths_cmd);
12936 install_element(BGP_VPNV4_NODE, &no_neighbor_addpath_tx_all_paths_cmd);
12937 install_element(BGP_VPNV6_NODE, &neighbor_addpath_tx_all_paths_cmd);
12938 install_element(BGP_VPNV6_NODE, &no_neighbor_addpath_tx_all_paths_cmd);
12939
12940 /* "neighbor addpath-tx-bestpath-per-AS" commands.*/
12941 install_element(BGP_NODE,
12942 &neighbor_addpath_tx_bestpath_per_as_hidden_cmd);
12943 install_element(BGP_NODE,
12944 &no_neighbor_addpath_tx_bestpath_per_as_hidden_cmd);
12945 install_element(BGP_IPV4_NODE,
12946 &neighbor_addpath_tx_bestpath_per_as_cmd);
12947 install_element(BGP_IPV4_NODE,
12948 &no_neighbor_addpath_tx_bestpath_per_as_cmd);
12949 install_element(BGP_IPV4M_NODE,
12950 &neighbor_addpath_tx_bestpath_per_as_cmd);
12951 install_element(BGP_IPV4M_NODE,
12952 &no_neighbor_addpath_tx_bestpath_per_as_cmd);
12953 install_element(BGP_IPV4L_NODE,
12954 &neighbor_addpath_tx_bestpath_per_as_cmd);
12955 install_element(BGP_IPV4L_NODE,
12956 &no_neighbor_addpath_tx_bestpath_per_as_cmd);
12957 install_element(BGP_IPV6_NODE,
12958 &neighbor_addpath_tx_bestpath_per_as_cmd);
12959 install_element(BGP_IPV6_NODE,
12960 &no_neighbor_addpath_tx_bestpath_per_as_cmd);
12961 install_element(BGP_IPV6M_NODE,
12962 &neighbor_addpath_tx_bestpath_per_as_cmd);
12963 install_element(BGP_IPV6M_NODE,
12964 &no_neighbor_addpath_tx_bestpath_per_as_cmd);
12965 install_element(BGP_IPV6L_NODE,
12966 &neighbor_addpath_tx_bestpath_per_as_cmd);
12967 install_element(BGP_IPV6L_NODE,
12968 &no_neighbor_addpath_tx_bestpath_per_as_cmd);
12969 install_element(BGP_VPNV4_NODE,
12970 &neighbor_addpath_tx_bestpath_per_as_cmd);
12971 install_element(BGP_VPNV4_NODE,
12972 &no_neighbor_addpath_tx_bestpath_per_as_cmd);
12973 install_element(BGP_VPNV6_NODE,
12974 &neighbor_addpath_tx_bestpath_per_as_cmd);
12975 install_element(BGP_VPNV6_NODE,
12976 &no_neighbor_addpath_tx_bestpath_per_as_cmd);
12977
12978 /* "neighbor passive" commands. */
12979 install_element(BGP_NODE, &neighbor_passive_cmd);
12980 install_element(BGP_NODE, &no_neighbor_passive_cmd);
12981
12982
12983 /* "neighbor shutdown" commands. */
12984 install_element(BGP_NODE, &neighbor_shutdown_cmd);
12985 install_element(BGP_NODE, &no_neighbor_shutdown_cmd);
12986 install_element(BGP_NODE, &neighbor_shutdown_msg_cmd);
12987 install_element(BGP_NODE, &no_neighbor_shutdown_msg_cmd);
12988
12989 /* "neighbor capability extended-nexthop" commands.*/
12990 install_element(BGP_NODE, &neighbor_capability_enhe_cmd);
12991 install_element(BGP_NODE, &no_neighbor_capability_enhe_cmd);
12992
12993 /* "neighbor capability orf prefix-list" commands.*/
12994 install_element(BGP_NODE, &neighbor_capability_orf_prefix_hidden_cmd);
12995 install_element(BGP_NODE,
12996 &no_neighbor_capability_orf_prefix_hidden_cmd);
12997 install_element(BGP_IPV4_NODE, &neighbor_capability_orf_prefix_cmd);
12998 install_element(BGP_IPV4_NODE, &no_neighbor_capability_orf_prefix_cmd);
12999 install_element(BGP_IPV4M_NODE, &neighbor_capability_orf_prefix_cmd);
13000 install_element(BGP_IPV4M_NODE, &no_neighbor_capability_orf_prefix_cmd);
13001 install_element(BGP_IPV4L_NODE, &neighbor_capability_orf_prefix_cmd);
13002 install_element(BGP_IPV4L_NODE, &no_neighbor_capability_orf_prefix_cmd);
13003 install_element(BGP_IPV6_NODE, &neighbor_capability_orf_prefix_cmd);
13004 install_element(BGP_IPV6_NODE, &no_neighbor_capability_orf_prefix_cmd);
13005 install_element(BGP_IPV6M_NODE, &neighbor_capability_orf_prefix_cmd);
13006 install_element(BGP_IPV6M_NODE, &no_neighbor_capability_orf_prefix_cmd);
13007 install_element(BGP_IPV6L_NODE, &neighbor_capability_orf_prefix_cmd);
13008 install_element(BGP_IPV6L_NODE, &no_neighbor_capability_orf_prefix_cmd);
13009
13010 /* "neighbor capability dynamic" commands.*/
13011 install_element(BGP_NODE, &neighbor_capability_dynamic_cmd);
13012 install_element(BGP_NODE, &no_neighbor_capability_dynamic_cmd);
13013
13014 /* "neighbor dont-capability-negotiate" commands. */
13015 install_element(BGP_NODE, &neighbor_dont_capability_negotiate_cmd);
13016 install_element(BGP_NODE, &no_neighbor_dont_capability_negotiate_cmd);
13017
13018 /* "neighbor ebgp-multihop" commands. */
13019 install_element(BGP_NODE, &neighbor_ebgp_multihop_cmd);
13020 install_element(BGP_NODE, &neighbor_ebgp_multihop_ttl_cmd);
13021 install_element(BGP_NODE, &no_neighbor_ebgp_multihop_cmd);
13022
13023 /* "neighbor disable-connected-check" commands. */
13024 install_element(BGP_NODE, &neighbor_disable_connected_check_cmd);
13025 install_element(BGP_NODE, &no_neighbor_disable_connected_check_cmd);
13026
13027 /* "neighbor enforce-first-as" commands. */
13028 install_element(BGP_NODE, &neighbor_enforce_first_as_cmd);
13029 install_element(BGP_NODE, &no_neighbor_enforce_first_as_cmd);
13030
13031 /* "neighbor description" commands. */
13032 install_element(BGP_NODE, &neighbor_description_cmd);
13033 install_element(BGP_NODE, &no_neighbor_description_cmd);
13034
13035 /* "neighbor update-source" commands. "*/
13036 install_element(BGP_NODE, &neighbor_update_source_cmd);
13037 install_element(BGP_NODE, &no_neighbor_update_source_cmd);
13038
13039 /* "neighbor default-originate" commands. */
13040 install_element(BGP_NODE, &neighbor_default_originate_hidden_cmd);
13041 install_element(BGP_NODE, &neighbor_default_originate_rmap_hidden_cmd);
13042 install_element(BGP_NODE, &no_neighbor_default_originate_hidden_cmd);
13043 install_element(BGP_IPV4_NODE, &neighbor_default_originate_cmd);
13044 install_element(BGP_IPV4_NODE, &neighbor_default_originate_rmap_cmd);
13045 install_element(BGP_IPV4_NODE, &no_neighbor_default_originate_cmd);
13046 install_element(BGP_IPV4M_NODE, &neighbor_default_originate_cmd);
13047 install_element(BGP_IPV4M_NODE, &neighbor_default_originate_rmap_cmd);
13048 install_element(BGP_IPV4M_NODE, &no_neighbor_default_originate_cmd);
13049 install_element(BGP_IPV4L_NODE, &neighbor_default_originate_cmd);
13050 install_element(BGP_IPV4L_NODE, &neighbor_default_originate_rmap_cmd);
13051 install_element(BGP_IPV4L_NODE, &no_neighbor_default_originate_cmd);
13052 install_element(BGP_IPV6_NODE, &neighbor_default_originate_cmd);
13053 install_element(BGP_IPV6_NODE, &neighbor_default_originate_rmap_cmd);
13054 install_element(BGP_IPV6_NODE, &no_neighbor_default_originate_cmd);
13055 install_element(BGP_IPV6M_NODE, &neighbor_default_originate_cmd);
13056 install_element(BGP_IPV6M_NODE, &neighbor_default_originate_rmap_cmd);
13057 install_element(BGP_IPV6M_NODE, &no_neighbor_default_originate_cmd);
13058 install_element(BGP_IPV6L_NODE, &neighbor_default_originate_cmd);
13059 install_element(BGP_IPV6L_NODE, &neighbor_default_originate_rmap_cmd);
13060 install_element(BGP_IPV6L_NODE, &no_neighbor_default_originate_cmd);
13061
13062 /* "neighbor port" commands. */
13063 install_element(BGP_NODE, &neighbor_port_cmd);
13064 install_element(BGP_NODE, &no_neighbor_port_cmd);
13065
13066 /* "neighbor weight" commands. */
13067 install_element(BGP_NODE, &neighbor_weight_hidden_cmd);
13068 install_element(BGP_NODE, &no_neighbor_weight_hidden_cmd);
13069
13070 install_element(BGP_IPV4_NODE, &neighbor_weight_cmd);
13071 install_element(BGP_IPV4_NODE, &no_neighbor_weight_cmd);
13072 install_element(BGP_IPV4M_NODE, &neighbor_weight_cmd);
13073 install_element(BGP_IPV4M_NODE, &no_neighbor_weight_cmd);
13074 install_element(BGP_IPV4L_NODE, &neighbor_weight_cmd);
13075 install_element(BGP_IPV4L_NODE, &no_neighbor_weight_cmd);
13076 install_element(BGP_IPV6_NODE, &neighbor_weight_cmd);
13077 install_element(BGP_IPV6_NODE, &no_neighbor_weight_cmd);
13078 install_element(BGP_IPV6M_NODE, &neighbor_weight_cmd);
13079 install_element(BGP_IPV6M_NODE, &no_neighbor_weight_cmd);
13080 install_element(BGP_IPV6L_NODE, &neighbor_weight_cmd);
13081 install_element(BGP_IPV6L_NODE, &no_neighbor_weight_cmd);
13082 install_element(BGP_VPNV4_NODE, &neighbor_weight_cmd);
13083 install_element(BGP_VPNV4_NODE, &no_neighbor_weight_cmd);
13084 install_element(BGP_VPNV6_NODE, &neighbor_weight_cmd);
13085 install_element(BGP_VPNV6_NODE, &no_neighbor_weight_cmd);
13086
13087 /* "neighbor override-capability" commands. */
13088 install_element(BGP_NODE, &neighbor_override_capability_cmd);
13089 install_element(BGP_NODE, &no_neighbor_override_capability_cmd);
13090
13091 /* "neighbor strict-capability-match" commands. */
13092 install_element(BGP_NODE, &neighbor_strict_capability_cmd);
13093 install_element(BGP_NODE, &no_neighbor_strict_capability_cmd);
13094
13095 /* "neighbor timers" commands. */
13096 install_element(BGP_NODE, &neighbor_timers_cmd);
13097 install_element(BGP_NODE, &no_neighbor_timers_cmd);
13098
13099 /* "neighbor timers connect" commands. */
13100 install_element(BGP_NODE, &neighbor_timers_connect_cmd);
13101 install_element(BGP_NODE, &no_neighbor_timers_connect_cmd);
13102
13103 /* "neighbor advertisement-interval" commands. */
13104 install_element(BGP_NODE, &neighbor_advertise_interval_cmd);
13105 install_element(BGP_NODE, &no_neighbor_advertise_interval_cmd);
13106
13107 /* "neighbor interface" commands. */
13108 install_element(BGP_NODE, &neighbor_interface_cmd);
13109 install_element(BGP_NODE, &no_neighbor_interface_cmd);
13110
13111 /* "neighbor distribute" commands. */
13112 install_element(BGP_NODE, &neighbor_distribute_list_hidden_cmd);
13113 install_element(BGP_NODE, &no_neighbor_distribute_list_hidden_cmd);
13114 install_element(BGP_IPV4_NODE, &neighbor_distribute_list_cmd);
13115 install_element(BGP_IPV4_NODE, &no_neighbor_distribute_list_cmd);
13116 install_element(BGP_IPV4M_NODE, &neighbor_distribute_list_cmd);
13117 install_element(BGP_IPV4M_NODE, &no_neighbor_distribute_list_cmd);
13118 install_element(BGP_IPV4L_NODE, &neighbor_distribute_list_cmd);
13119 install_element(BGP_IPV4L_NODE, &no_neighbor_distribute_list_cmd);
13120 install_element(BGP_IPV6_NODE, &neighbor_distribute_list_cmd);
13121 install_element(BGP_IPV6_NODE, &no_neighbor_distribute_list_cmd);
13122 install_element(BGP_IPV6M_NODE, &neighbor_distribute_list_cmd);
13123 install_element(BGP_IPV6M_NODE, &no_neighbor_distribute_list_cmd);
13124 install_element(BGP_IPV6L_NODE, &neighbor_distribute_list_cmd);
13125 install_element(BGP_IPV6L_NODE, &no_neighbor_distribute_list_cmd);
13126 install_element(BGP_VPNV4_NODE, &neighbor_distribute_list_cmd);
13127 install_element(BGP_VPNV4_NODE, &no_neighbor_distribute_list_cmd);
13128 install_element(BGP_VPNV6_NODE, &neighbor_distribute_list_cmd);
13129 install_element(BGP_VPNV6_NODE, &no_neighbor_distribute_list_cmd);
13130
13131 /* "neighbor prefix-list" commands. */
13132 install_element(BGP_NODE, &neighbor_prefix_list_hidden_cmd);
13133 install_element(BGP_NODE, &no_neighbor_prefix_list_hidden_cmd);
13134 install_element(BGP_IPV4_NODE, &neighbor_prefix_list_cmd);
13135 install_element(BGP_IPV4_NODE, &no_neighbor_prefix_list_cmd);
13136 install_element(BGP_IPV4M_NODE, &neighbor_prefix_list_cmd);
13137 install_element(BGP_IPV4M_NODE, &no_neighbor_prefix_list_cmd);
13138 install_element(BGP_IPV4L_NODE, &neighbor_prefix_list_cmd);
13139 install_element(BGP_IPV4L_NODE, &no_neighbor_prefix_list_cmd);
13140 install_element(BGP_IPV6_NODE, &neighbor_prefix_list_cmd);
13141 install_element(BGP_IPV6_NODE, &no_neighbor_prefix_list_cmd);
13142 install_element(BGP_IPV6M_NODE, &neighbor_prefix_list_cmd);
13143 install_element(BGP_IPV6M_NODE, &no_neighbor_prefix_list_cmd);
13144 install_element(BGP_IPV6L_NODE, &neighbor_prefix_list_cmd);
13145 install_element(BGP_IPV6L_NODE, &no_neighbor_prefix_list_cmd);
13146 install_element(BGP_VPNV4_NODE, &neighbor_prefix_list_cmd);
13147 install_element(BGP_VPNV4_NODE, &no_neighbor_prefix_list_cmd);
13148 install_element(BGP_VPNV6_NODE, &neighbor_prefix_list_cmd);
13149 install_element(BGP_VPNV6_NODE, &no_neighbor_prefix_list_cmd);
13150 install_element(BGP_FLOWSPECV4_NODE, &neighbor_prefix_list_cmd);
13151 install_element(BGP_FLOWSPECV4_NODE, &no_neighbor_prefix_list_cmd);
13152 install_element(BGP_FLOWSPECV6_NODE, &neighbor_prefix_list_cmd);
13153 install_element(BGP_FLOWSPECV6_NODE, &no_neighbor_prefix_list_cmd);
13154
13155 /* "neighbor filter-list" commands. */
13156 install_element(BGP_NODE, &neighbor_filter_list_hidden_cmd);
13157 install_element(BGP_NODE, &no_neighbor_filter_list_hidden_cmd);
13158 install_element(BGP_IPV4_NODE, &neighbor_filter_list_cmd);
13159 install_element(BGP_IPV4_NODE, &no_neighbor_filter_list_cmd);
13160 install_element(BGP_IPV4M_NODE, &neighbor_filter_list_cmd);
13161 install_element(BGP_IPV4M_NODE, &no_neighbor_filter_list_cmd);
13162 install_element(BGP_IPV4L_NODE, &neighbor_filter_list_cmd);
13163 install_element(BGP_IPV4L_NODE, &no_neighbor_filter_list_cmd);
13164 install_element(BGP_IPV6_NODE, &neighbor_filter_list_cmd);
13165 install_element(BGP_IPV6_NODE, &no_neighbor_filter_list_cmd);
13166 install_element(BGP_IPV6M_NODE, &neighbor_filter_list_cmd);
13167 install_element(BGP_IPV6M_NODE, &no_neighbor_filter_list_cmd);
13168 install_element(BGP_IPV6L_NODE, &neighbor_filter_list_cmd);
13169 install_element(BGP_IPV6L_NODE, &no_neighbor_filter_list_cmd);
13170 install_element(BGP_VPNV4_NODE, &neighbor_filter_list_cmd);
13171 install_element(BGP_VPNV4_NODE, &no_neighbor_filter_list_cmd);
13172 install_element(BGP_VPNV6_NODE, &neighbor_filter_list_cmd);
13173 install_element(BGP_VPNV6_NODE, &no_neighbor_filter_list_cmd);
13174 install_element(BGP_FLOWSPECV4_NODE, &neighbor_filter_list_cmd);
13175 install_element(BGP_FLOWSPECV4_NODE, &no_neighbor_filter_list_cmd);
13176 install_element(BGP_FLOWSPECV6_NODE, &neighbor_filter_list_cmd);
13177 install_element(BGP_FLOWSPECV6_NODE, &no_neighbor_filter_list_cmd);
13178
13179 /* "neighbor route-map" commands. */
13180 install_element(BGP_NODE, &neighbor_route_map_hidden_cmd);
13181 install_element(BGP_NODE, &no_neighbor_route_map_hidden_cmd);
13182 install_element(BGP_IPV4_NODE, &neighbor_route_map_cmd);
13183 install_element(BGP_IPV4_NODE, &no_neighbor_route_map_cmd);
13184 install_element(BGP_IPV4M_NODE, &neighbor_route_map_cmd);
13185 install_element(BGP_IPV4M_NODE, &no_neighbor_route_map_cmd);
13186 install_element(BGP_IPV4L_NODE, &neighbor_route_map_cmd);
13187 install_element(BGP_IPV4L_NODE, &no_neighbor_route_map_cmd);
13188 install_element(BGP_IPV6_NODE, &neighbor_route_map_cmd);
13189 install_element(BGP_IPV6_NODE, &no_neighbor_route_map_cmd);
13190 install_element(BGP_IPV6M_NODE, &neighbor_route_map_cmd);
13191 install_element(BGP_IPV6M_NODE, &no_neighbor_route_map_cmd);
13192 install_element(BGP_IPV6L_NODE, &neighbor_route_map_cmd);
13193 install_element(BGP_IPV6L_NODE, &no_neighbor_route_map_cmd);
13194 install_element(BGP_VPNV4_NODE, &neighbor_route_map_cmd);
13195 install_element(BGP_VPNV4_NODE, &no_neighbor_route_map_cmd);
13196 install_element(BGP_VPNV6_NODE, &neighbor_route_map_cmd);
13197 install_element(BGP_VPNV6_NODE, &no_neighbor_route_map_cmd);
13198 install_element(BGP_FLOWSPECV4_NODE, &neighbor_route_map_cmd);
13199 install_element(BGP_FLOWSPECV4_NODE, &no_neighbor_route_map_cmd);
13200 install_element(BGP_FLOWSPECV6_NODE, &neighbor_route_map_cmd);
13201 install_element(BGP_FLOWSPECV6_NODE, &no_neighbor_route_map_cmd);
13202 install_element(BGP_EVPN_NODE, &neighbor_route_map_cmd);
13203 install_element(BGP_EVPN_NODE, &no_neighbor_route_map_cmd);
13204
13205 /* "neighbor unsuppress-map" commands. */
13206 install_element(BGP_NODE, &neighbor_unsuppress_map_hidden_cmd);
13207 install_element(BGP_NODE, &no_neighbor_unsuppress_map_hidden_cmd);
13208 install_element(BGP_IPV4_NODE, &neighbor_unsuppress_map_cmd);
13209 install_element(BGP_IPV4_NODE, &no_neighbor_unsuppress_map_cmd);
13210 install_element(BGP_IPV4M_NODE, &neighbor_unsuppress_map_cmd);
13211 install_element(BGP_IPV4M_NODE, &no_neighbor_unsuppress_map_cmd);
13212 install_element(BGP_IPV4L_NODE, &neighbor_unsuppress_map_cmd);
13213 install_element(BGP_IPV4L_NODE, &no_neighbor_unsuppress_map_cmd);
13214 install_element(BGP_IPV6_NODE, &neighbor_unsuppress_map_cmd);
13215 install_element(BGP_IPV6_NODE, &no_neighbor_unsuppress_map_cmd);
13216 install_element(BGP_IPV6M_NODE, &neighbor_unsuppress_map_cmd);
13217 install_element(BGP_IPV6M_NODE, &no_neighbor_unsuppress_map_cmd);
13218 install_element(BGP_IPV6L_NODE, &neighbor_unsuppress_map_cmd);
13219 install_element(BGP_IPV6L_NODE, &no_neighbor_unsuppress_map_cmd);
13220 install_element(BGP_VPNV4_NODE, &neighbor_unsuppress_map_cmd);
13221 install_element(BGP_VPNV4_NODE, &no_neighbor_unsuppress_map_cmd);
13222 install_element(BGP_VPNV6_NODE, &neighbor_unsuppress_map_cmd);
13223 install_element(BGP_VPNV6_NODE, &no_neighbor_unsuppress_map_cmd);
13224
13225 /* "neighbor maximum-prefix" commands. */
13226 install_element(BGP_NODE, &neighbor_maximum_prefix_hidden_cmd);
13227 install_element(BGP_NODE,
13228 &neighbor_maximum_prefix_threshold_hidden_cmd);
13229 install_element(BGP_NODE, &neighbor_maximum_prefix_warning_hidden_cmd);
13230 install_element(BGP_NODE,
13231 &neighbor_maximum_prefix_threshold_warning_hidden_cmd);
13232 install_element(BGP_NODE, &neighbor_maximum_prefix_restart_hidden_cmd);
13233 install_element(BGP_NODE,
13234 &neighbor_maximum_prefix_threshold_restart_hidden_cmd);
13235 install_element(BGP_NODE, &no_neighbor_maximum_prefix_hidden_cmd);
13236 install_element(BGP_IPV4_NODE, &neighbor_maximum_prefix_cmd);
13237 install_element(BGP_IPV4_NODE, &neighbor_maximum_prefix_threshold_cmd);
13238 install_element(BGP_IPV4_NODE, &neighbor_maximum_prefix_warning_cmd);
13239 install_element(BGP_IPV4_NODE,
13240 &neighbor_maximum_prefix_threshold_warning_cmd);
13241 install_element(BGP_IPV4_NODE, &neighbor_maximum_prefix_restart_cmd);
13242 install_element(BGP_IPV4_NODE,
13243 &neighbor_maximum_prefix_threshold_restart_cmd);
13244 install_element(BGP_IPV4_NODE, &no_neighbor_maximum_prefix_cmd);
13245 install_element(BGP_IPV4M_NODE, &neighbor_maximum_prefix_cmd);
13246 install_element(BGP_IPV4M_NODE, &neighbor_maximum_prefix_threshold_cmd);
13247 install_element(BGP_IPV4M_NODE, &neighbor_maximum_prefix_warning_cmd);
13248 install_element(BGP_IPV4M_NODE,
13249 &neighbor_maximum_prefix_threshold_warning_cmd);
13250 install_element(BGP_IPV4M_NODE, &neighbor_maximum_prefix_restart_cmd);
13251 install_element(BGP_IPV4M_NODE,
13252 &neighbor_maximum_prefix_threshold_restart_cmd);
13253 install_element(BGP_IPV4M_NODE, &no_neighbor_maximum_prefix_cmd);
13254 install_element(BGP_IPV4L_NODE, &neighbor_maximum_prefix_cmd);
13255 install_element(BGP_IPV4L_NODE, &neighbor_maximum_prefix_threshold_cmd);
13256 install_element(BGP_IPV4L_NODE, &neighbor_maximum_prefix_warning_cmd);
13257 install_element(BGP_IPV4L_NODE,
13258 &neighbor_maximum_prefix_threshold_warning_cmd);
13259 install_element(BGP_IPV4L_NODE, &neighbor_maximum_prefix_restart_cmd);
13260 install_element(BGP_IPV4L_NODE,
13261 &neighbor_maximum_prefix_threshold_restart_cmd);
13262 install_element(BGP_IPV4L_NODE, &no_neighbor_maximum_prefix_cmd);
13263 install_element(BGP_IPV6_NODE, &neighbor_maximum_prefix_cmd);
13264 install_element(BGP_IPV6_NODE, &neighbor_maximum_prefix_threshold_cmd);
13265 install_element(BGP_IPV6_NODE, &neighbor_maximum_prefix_warning_cmd);
13266 install_element(BGP_IPV6_NODE,
13267 &neighbor_maximum_prefix_threshold_warning_cmd);
13268 install_element(BGP_IPV6_NODE, &neighbor_maximum_prefix_restart_cmd);
13269 install_element(BGP_IPV6_NODE,
13270 &neighbor_maximum_prefix_threshold_restart_cmd);
13271 install_element(BGP_IPV6_NODE, &no_neighbor_maximum_prefix_cmd);
13272 install_element(BGP_IPV6M_NODE, &neighbor_maximum_prefix_cmd);
13273 install_element(BGP_IPV6M_NODE, &neighbor_maximum_prefix_threshold_cmd);
13274 install_element(BGP_IPV6M_NODE, &neighbor_maximum_prefix_warning_cmd);
13275 install_element(BGP_IPV6M_NODE,
13276 &neighbor_maximum_prefix_threshold_warning_cmd);
13277 install_element(BGP_IPV6M_NODE, &neighbor_maximum_prefix_restart_cmd);
13278 install_element(BGP_IPV6M_NODE,
13279 &neighbor_maximum_prefix_threshold_restart_cmd);
13280 install_element(BGP_IPV6M_NODE, &no_neighbor_maximum_prefix_cmd);
13281 install_element(BGP_IPV6L_NODE, &neighbor_maximum_prefix_cmd);
13282 install_element(BGP_IPV6L_NODE, &neighbor_maximum_prefix_threshold_cmd);
13283 install_element(BGP_IPV6L_NODE, &neighbor_maximum_prefix_warning_cmd);
13284 install_element(BGP_IPV6L_NODE,
13285 &neighbor_maximum_prefix_threshold_warning_cmd);
13286 install_element(BGP_IPV6L_NODE, &neighbor_maximum_prefix_restart_cmd);
13287 install_element(BGP_IPV6L_NODE,
13288 &neighbor_maximum_prefix_threshold_restart_cmd);
13289 install_element(BGP_IPV6L_NODE, &no_neighbor_maximum_prefix_cmd);
13290 install_element(BGP_VPNV4_NODE, &neighbor_maximum_prefix_cmd);
13291 install_element(BGP_VPNV4_NODE, &neighbor_maximum_prefix_threshold_cmd);
13292 install_element(BGP_VPNV4_NODE, &neighbor_maximum_prefix_warning_cmd);
13293 install_element(BGP_VPNV4_NODE,
13294 &neighbor_maximum_prefix_threshold_warning_cmd);
13295 install_element(BGP_VPNV4_NODE, &neighbor_maximum_prefix_restart_cmd);
13296 install_element(BGP_VPNV4_NODE,
13297 &neighbor_maximum_prefix_threshold_restart_cmd);
13298 install_element(BGP_VPNV4_NODE, &no_neighbor_maximum_prefix_cmd);
13299 install_element(BGP_VPNV6_NODE, &neighbor_maximum_prefix_cmd);
13300 install_element(BGP_VPNV6_NODE, &neighbor_maximum_prefix_threshold_cmd);
13301 install_element(BGP_VPNV6_NODE, &neighbor_maximum_prefix_warning_cmd);
13302 install_element(BGP_VPNV6_NODE,
13303 &neighbor_maximum_prefix_threshold_warning_cmd);
13304 install_element(BGP_VPNV6_NODE, &neighbor_maximum_prefix_restart_cmd);
13305 install_element(BGP_VPNV6_NODE,
13306 &neighbor_maximum_prefix_threshold_restart_cmd);
13307 install_element(BGP_VPNV6_NODE, &no_neighbor_maximum_prefix_cmd);
13308
13309 /* "neighbor allowas-in" */
13310 install_element(BGP_NODE, &neighbor_allowas_in_hidden_cmd);
13311 install_element(BGP_NODE, &no_neighbor_allowas_in_hidden_cmd);
13312 install_element(BGP_IPV4_NODE, &neighbor_allowas_in_cmd);
13313 install_element(BGP_IPV4_NODE, &no_neighbor_allowas_in_cmd);
13314 install_element(BGP_IPV4M_NODE, &neighbor_allowas_in_cmd);
13315 install_element(BGP_IPV4M_NODE, &no_neighbor_allowas_in_cmd);
13316 install_element(BGP_IPV4L_NODE, &neighbor_allowas_in_cmd);
13317 install_element(BGP_IPV4L_NODE, &no_neighbor_allowas_in_cmd);
13318 install_element(BGP_IPV6_NODE, &neighbor_allowas_in_cmd);
13319 install_element(BGP_IPV6_NODE, &no_neighbor_allowas_in_cmd);
13320 install_element(BGP_IPV6M_NODE, &neighbor_allowas_in_cmd);
13321 install_element(BGP_IPV6M_NODE, &no_neighbor_allowas_in_cmd);
13322 install_element(BGP_IPV6L_NODE, &neighbor_allowas_in_cmd);
13323 install_element(BGP_IPV6L_NODE, &no_neighbor_allowas_in_cmd);
13324 install_element(BGP_VPNV4_NODE, &neighbor_allowas_in_cmd);
13325 install_element(BGP_VPNV4_NODE, &no_neighbor_allowas_in_cmd);
13326 install_element(BGP_VPNV6_NODE, &neighbor_allowas_in_cmd);
13327 install_element(BGP_VPNV6_NODE, &no_neighbor_allowas_in_cmd);
13328 install_element(BGP_EVPN_NODE, &neighbor_allowas_in_cmd);
13329 install_element(BGP_EVPN_NODE, &no_neighbor_allowas_in_cmd);
13330
13331 /* address-family commands. */
13332 install_element(BGP_NODE, &address_family_ipv4_safi_cmd);
13333 install_element(BGP_NODE, &address_family_ipv6_safi_cmd);
13334 #ifdef KEEP_OLD_VPN_COMMANDS
13335 install_element(BGP_NODE, &address_family_vpnv4_cmd);
13336 install_element(BGP_NODE, &address_family_vpnv6_cmd);
13337 #endif /* KEEP_OLD_VPN_COMMANDS */
13338
13339 install_element(BGP_NODE, &address_family_evpn_cmd);
13340
13341 /* "exit-address-family" command. */
13342 install_element(BGP_IPV4_NODE, &exit_address_family_cmd);
13343 install_element(BGP_IPV4M_NODE, &exit_address_family_cmd);
13344 install_element(BGP_IPV4L_NODE, &exit_address_family_cmd);
13345 install_element(BGP_IPV6_NODE, &exit_address_family_cmd);
13346 install_element(BGP_IPV6M_NODE, &exit_address_family_cmd);
13347 install_element(BGP_IPV6L_NODE, &exit_address_family_cmd);
13348 install_element(BGP_VPNV4_NODE, &exit_address_family_cmd);
13349 install_element(BGP_VPNV6_NODE, &exit_address_family_cmd);
13350 install_element(BGP_FLOWSPECV4_NODE, &exit_address_family_cmd);
13351 install_element(BGP_FLOWSPECV6_NODE, &exit_address_family_cmd);
13352 install_element(BGP_EVPN_NODE, &exit_address_family_cmd);
13353
13354 /* "clear ip bgp commands" */
13355 install_element(ENABLE_NODE, &clear_ip_bgp_all_cmd);
13356
13357 /* clear ip bgp prefix */
13358 install_element(ENABLE_NODE, &clear_ip_bgp_prefix_cmd);
13359 install_element(ENABLE_NODE, &clear_bgp_ipv6_safi_prefix_cmd);
13360 install_element(ENABLE_NODE, &clear_bgp_instance_ipv6_safi_prefix_cmd);
13361
13362 /* "show [ip] bgp summary" commands. */
13363 install_element(VIEW_NODE, &show_bgp_instance_all_ipv6_updgrps_cmd);
13364 install_element(VIEW_NODE, &show_bgp_instance_updgrps_stats_cmd);
13365 install_element(VIEW_NODE, &show_bgp_updgrps_stats_cmd);
13366 install_element(VIEW_NODE, &show_ip_bgp_instance_updgrps_adj_s_cmd);
13367 install_element(VIEW_NODE, &show_ip_bgp_summary_cmd);
13368 install_element(VIEW_NODE, &show_ip_bgp_updgrps_cmd);
13369
13370 /* "show [ip] bgp neighbors" commands. */
13371 install_element(VIEW_NODE, &show_ip_bgp_neighbors_cmd);
13372
13373 /* "show [ip] bgp peer-group" commands. */
13374 install_element(VIEW_NODE, &show_ip_bgp_peer_groups_cmd);
13375
13376 /* "show [ip] bgp paths" commands. */
13377 install_element(VIEW_NODE, &show_ip_bgp_paths_cmd);
13378
13379 /* "show [ip] bgp community" commands. */
13380 install_element(VIEW_NODE, &show_ip_bgp_community_info_cmd);
13381
13382 /* "show ip bgp large-community" commands. */
13383 install_element(VIEW_NODE, &show_ip_bgp_lcommunity_info_cmd);
13384 /* "show [ip] bgp attribute-info" commands. */
13385 install_element(VIEW_NODE, &show_ip_bgp_attr_info_cmd);
13386 /* "show [ip] bgp route-leak" command */
13387 install_element(VIEW_NODE, &show_ip_bgp_route_leak_cmd);
13388
13389 /* "redistribute" commands. */
13390 install_element(BGP_NODE, &bgp_redistribute_ipv4_hidden_cmd);
13391 install_element(BGP_NODE, &no_bgp_redistribute_ipv4_hidden_cmd);
13392 install_element(BGP_NODE, &bgp_redistribute_ipv4_rmap_hidden_cmd);
13393 install_element(BGP_NODE, &bgp_redistribute_ipv4_metric_hidden_cmd);
13394 install_element(BGP_NODE,
13395 &bgp_redistribute_ipv4_rmap_metric_hidden_cmd);
13396 install_element(BGP_NODE,
13397 &bgp_redistribute_ipv4_metric_rmap_hidden_cmd);
13398 install_element(BGP_NODE, &bgp_redistribute_ipv4_ospf_hidden_cmd);
13399 install_element(BGP_NODE, &no_bgp_redistribute_ipv4_ospf_hidden_cmd);
13400 install_element(BGP_NODE, &bgp_redistribute_ipv4_ospf_rmap_hidden_cmd);
13401 install_element(BGP_NODE,
13402 &bgp_redistribute_ipv4_ospf_metric_hidden_cmd);
13403 install_element(BGP_NODE,
13404 &bgp_redistribute_ipv4_ospf_rmap_metric_hidden_cmd);
13405 install_element(BGP_NODE,
13406 &bgp_redistribute_ipv4_ospf_metric_rmap_hidden_cmd);
13407 install_element(BGP_IPV4_NODE, &bgp_redistribute_ipv4_cmd);
13408 install_element(BGP_IPV4_NODE, &no_bgp_redistribute_ipv4_cmd);
13409 install_element(BGP_IPV4_NODE, &bgp_redistribute_ipv4_rmap_cmd);
13410 install_element(BGP_IPV4_NODE, &bgp_redistribute_ipv4_metric_cmd);
13411 install_element(BGP_IPV4_NODE, &bgp_redistribute_ipv4_rmap_metric_cmd);
13412 install_element(BGP_IPV4_NODE, &bgp_redistribute_ipv4_metric_rmap_cmd);
13413 install_element(BGP_IPV4_NODE, &bgp_redistribute_ipv4_ospf_cmd);
13414 install_element(BGP_IPV4_NODE, &no_bgp_redistribute_ipv4_ospf_cmd);
13415 install_element(BGP_IPV4_NODE, &bgp_redistribute_ipv4_ospf_rmap_cmd);
13416 install_element(BGP_IPV4_NODE, &bgp_redistribute_ipv4_ospf_metric_cmd);
13417 install_element(BGP_IPV4_NODE,
13418 &bgp_redistribute_ipv4_ospf_rmap_metric_cmd);
13419 install_element(BGP_IPV4_NODE,
13420 &bgp_redistribute_ipv4_ospf_metric_rmap_cmd);
13421 install_element(BGP_IPV6_NODE, &bgp_redistribute_ipv6_cmd);
13422 install_element(BGP_IPV6_NODE, &no_bgp_redistribute_ipv6_cmd);
13423 install_element(BGP_IPV6_NODE, &bgp_redistribute_ipv6_rmap_cmd);
13424 install_element(BGP_IPV6_NODE, &bgp_redistribute_ipv6_metric_cmd);
13425 install_element(BGP_IPV6_NODE, &bgp_redistribute_ipv6_rmap_metric_cmd);
13426 install_element(BGP_IPV6_NODE, &bgp_redistribute_ipv6_metric_rmap_cmd);
13427
13428 /* import|export vpn [route-map WORD] */
13429 install_element(BGP_IPV4_NODE, &bgp_imexport_vpn_cmd);
13430 install_element(BGP_IPV6_NODE, &bgp_imexport_vpn_cmd);
13431
13432 install_element(BGP_IPV4_NODE, &bgp_imexport_vrf_cmd);
13433 install_element(BGP_IPV6_NODE, &bgp_imexport_vrf_cmd);
13434
13435 /* ttl_security commands */
13436 install_element(BGP_NODE, &neighbor_ttl_security_cmd);
13437 install_element(BGP_NODE, &no_neighbor_ttl_security_cmd);
13438
13439 /* "show [ip] bgp memory" commands. */
13440 install_element(VIEW_NODE, &show_bgp_memory_cmd);
13441
13442 /* "show bgp martian next-hop" */
13443 install_element(VIEW_NODE, &show_bgp_martian_nexthop_db_cmd);
13444
13445 /* "show [ip] bgp views" commands. */
13446 install_element(VIEW_NODE, &show_bgp_views_cmd);
13447
13448 /* "show [ip] bgp vrfs" commands. */
13449 install_element(VIEW_NODE, &show_bgp_vrfs_cmd);
13450
13451 /* Community-list. */
13452 community_list_vty();
13453
13454 /* vpn-policy commands */
13455 install_element(BGP_IPV4_NODE, &af_rd_vpn_export_cmd);
13456 install_element(BGP_IPV6_NODE, &af_rd_vpn_export_cmd);
13457 install_element(BGP_IPV4_NODE, &af_label_vpn_export_cmd);
13458 install_element(BGP_IPV6_NODE, &af_label_vpn_export_cmd);
13459 install_element(BGP_IPV4_NODE, &af_nexthop_vpn_export_cmd);
13460 install_element(BGP_IPV6_NODE, &af_nexthop_vpn_export_cmd);
13461 install_element(BGP_IPV4_NODE, &af_rt_vpn_imexport_cmd);
13462 install_element(BGP_IPV6_NODE, &af_rt_vpn_imexport_cmd);
13463 install_element(BGP_IPV4_NODE, &af_route_map_vpn_imexport_cmd);
13464 install_element(BGP_IPV6_NODE, &af_route_map_vpn_imexport_cmd);
13465 install_element(BGP_IPV4_NODE, &af_import_vrf_route_map_cmd);
13466 install_element(BGP_IPV6_NODE, &af_import_vrf_route_map_cmd);
13467
13468 install_element(BGP_IPV4_NODE, &af_routetarget_import_cmd);
13469 install_element(BGP_IPV6_NODE, &af_routetarget_import_cmd);
13470
13471 install_element(BGP_IPV4_NODE, &af_no_rd_vpn_export_cmd);
13472 install_element(BGP_IPV6_NODE, &af_no_rd_vpn_export_cmd);
13473 install_element(BGP_IPV4_NODE, &af_no_label_vpn_export_cmd);
13474 install_element(BGP_IPV6_NODE, &af_no_label_vpn_export_cmd);
13475 install_element(BGP_IPV4_NODE, &af_no_nexthop_vpn_export_cmd);
13476 install_element(BGP_IPV6_NODE, &af_no_nexthop_vpn_export_cmd);
13477 install_element(BGP_IPV4_NODE, &af_no_rt_vpn_imexport_cmd);
13478 install_element(BGP_IPV6_NODE, &af_no_rt_vpn_imexport_cmd);
13479 install_element(BGP_IPV4_NODE, &af_no_route_map_vpn_imexport_cmd);
13480 install_element(BGP_IPV6_NODE, &af_no_route_map_vpn_imexport_cmd);
13481 install_element(BGP_IPV4_NODE, &af_no_import_vrf_route_map_cmd);
13482 install_element(BGP_IPV6_NODE, &af_no_import_vrf_route_map_cmd);
13483 }
13484
13485 #include "memory.h"
13486 #include "bgp_regex.h"
13487 #include "bgp_clist.h"
13488 #include "bgp_ecommunity.h"
13489
13490 /* VTY functions. */
13491
13492 /* Direction value to string conversion. */
13493 static const char *community_direct_str(int direct)
13494 {
13495 switch (direct) {
13496 case COMMUNITY_DENY:
13497 return "deny";
13498 case COMMUNITY_PERMIT:
13499 return "permit";
13500 default:
13501 return "unknown";
13502 }
13503 }
13504
13505 /* Display error string. */
13506 static void community_list_perror(struct vty *vty, int ret)
13507 {
13508 switch (ret) {
13509 case COMMUNITY_LIST_ERR_CANT_FIND_LIST:
13510 vty_out(vty, "%% Can't find community-list\n");
13511 break;
13512 case COMMUNITY_LIST_ERR_MALFORMED_VAL:
13513 vty_out(vty, "%% Malformed community-list value\n");
13514 break;
13515 case COMMUNITY_LIST_ERR_STANDARD_CONFLICT:
13516 vty_out(vty,
13517 "%% Community name conflict, previously defined as standard community\n");
13518 break;
13519 case COMMUNITY_LIST_ERR_EXPANDED_CONFLICT:
13520 vty_out(vty,
13521 "%% Community name conflict, previously defined as expanded community\n");
13522 break;
13523 }
13524 }
13525
13526 /* "community-list" keyword help string. */
13527 #define COMMUNITY_LIST_STR "Add a community list entry\n"
13528
13529 /* ip community-list standard */
13530 DEFUN (ip_community_list_standard,
13531 ip_community_list_standard_cmd,
13532 "ip community-list <(1-99)|standard WORD> <deny|permit> AA:NN...",
13533 IP_STR
13534 COMMUNITY_LIST_STR
13535 "Community list number (standard)\n"
13536 "Add an standard community-list entry\n"
13537 "Community list name\n"
13538 "Specify community to reject\n"
13539 "Specify community to accept\n"
13540 COMMUNITY_VAL_STR)
13541 {
13542 char *cl_name_or_number = NULL;
13543 int direct = 0;
13544 int style = COMMUNITY_LIST_STANDARD;
13545
13546 int idx = 0;
13547 argv_find(argv, argc, "(1-99)", &idx);
13548 argv_find(argv, argc, "WORD", &idx);
13549 cl_name_or_number = argv[idx]->arg;
13550 direct = argv_find(argv, argc, "permit", &idx) ? COMMUNITY_PERMIT
13551 : COMMUNITY_DENY;
13552 argv_find(argv, argc, "AA:NN", &idx);
13553 char *str = argv_concat(argv, argc, idx);
13554
13555 int ret = community_list_set(bgp_clist, cl_name_or_number, str, direct,
13556 style);
13557
13558 XFREE(MTYPE_TMP, str);
13559
13560 if (ret < 0) {
13561 /* Display error string. */
13562 community_list_perror(vty, ret);
13563 return CMD_WARNING_CONFIG_FAILED;
13564 }
13565
13566 return CMD_SUCCESS;
13567 }
13568
13569 DEFUN (no_ip_community_list_standard_all,
13570 no_ip_community_list_standard_all_cmd,
13571 "no ip community-list <(1-99)|standard WORD> <deny|permit> AA:NN...",
13572 NO_STR
13573 IP_STR
13574 COMMUNITY_LIST_STR
13575 "Community list number (standard)\n"
13576 "Add an standard community-list entry\n"
13577 "Community list name\n"
13578 "Specify community to reject\n"
13579 "Specify community to accept\n"
13580 COMMUNITY_VAL_STR)
13581 {
13582 char *cl_name_or_number = NULL;
13583 int direct = 0;
13584 int style = COMMUNITY_LIST_STANDARD;
13585
13586 int idx = 0;
13587 argv_find(argv, argc, "(1-99)", &idx);
13588 argv_find(argv, argc, "WORD", &idx);
13589 cl_name_or_number = argv[idx]->arg;
13590 direct = argv_find(argv, argc, "permit", &idx) ? COMMUNITY_PERMIT
13591 : COMMUNITY_DENY;
13592 argv_find(argv, argc, "AA:NN", &idx);
13593 char *str = argv_concat(argv, argc, idx);
13594
13595 int ret = community_list_unset(bgp_clist, cl_name_or_number, str,
13596 direct, style);
13597
13598 XFREE(MTYPE_TMP, str);
13599
13600 if (ret < 0) {
13601 community_list_perror(vty, ret);
13602 return CMD_WARNING_CONFIG_FAILED;
13603 }
13604
13605 return CMD_SUCCESS;
13606 }
13607
13608 /* ip community-list expanded */
13609 DEFUN (ip_community_list_expanded_all,
13610 ip_community_list_expanded_all_cmd,
13611 "ip community-list <(100-500)|expanded WORD> <deny|permit> AA:NN...",
13612 IP_STR
13613 COMMUNITY_LIST_STR
13614 "Community list number (expanded)\n"
13615 "Add an expanded community-list entry\n"
13616 "Community list name\n"
13617 "Specify community to reject\n"
13618 "Specify community to accept\n"
13619 COMMUNITY_VAL_STR)
13620 {
13621 char *cl_name_or_number = NULL;
13622 int direct = 0;
13623 int style = COMMUNITY_LIST_EXPANDED;
13624
13625 int idx = 0;
13626 argv_find(argv, argc, "(100-500)", &idx);
13627 argv_find(argv, argc, "WORD", &idx);
13628 cl_name_or_number = argv[idx]->arg;
13629 direct = argv_find(argv, argc, "permit", &idx) ? COMMUNITY_PERMIT
13630 : COMMUNITY_DENY;
13631 argv_find(argv, argc, "AA:NN", &idx);
13632 char *str = argv_concat(argv, argc, idx);
13633
13634 int ret = community_list_set(bgp_clist, cl_name_or_number, str, direct,
13635 style);
13636
13637 XFREE(MTYPE_TMP, str);
13638
13639 if (ret < 0) {
13640 /* Display error string. */
13641 community_list_perror(vty, ret);
13642 return CMD_WARNING_CONFIG_FAILED;
13643 }
13644
13645 return CMD_SUCCESS;
13646 }
13647
13648 DEFUN (no_ip_community_list_expanded_all,
13649 no_ip_community_list_expanded_all_cmd,
13650 "no ip community-list <(100-500)|expanded WORD> <deny|permit> AA:NN...",
13651 NO_STR
13652 IP_STR
13653 COMMUNITY_LIST_STR
13654 "Community list number (expanded)\n"
13655 "Add an expanded community-list entry\n"
13656 "Community list name\n"
13657 "Specify community to reject\n"
13658 "Specify community to accept\n"
13659 COMMUNITY_VAL_STR)
13660 {
13661 char *cl_name_or_number = NULL;
13662 int direct = 0;
13663 int style = COMMUNITY_LIST_EXPANDED;
13664
13665 int idx = 0;
13666 argv_find(argv, argc, "(100-500)", &idx);
13667 argv_find(argv, argc, "WORD", &idx);
13668 cl_name_or_number = argv[idx]->arg;
13669 direct = argv_find(argv, argc, "permit", &idx) ? COMMUNITY_PERMIT
13670 : COMMUNITY_DENY;
13671 argv_find(argv, argc, "AA:NN", &idx);
13672 char *str = argv_concat(argv, argc, idx);
13673
13674 int ret = community_list_unset(bgp_clist, cl_name_or_number, str,
13675 direct, style);
13676
13677 XFREE(MTYPE_TMP, str);
13678
13679 if (ret < 0) {
13680 community_list_perror(vty, ret);
13681 return CMD_WARNING_CONFIG_FAILED;
13682 }
13683
13684 return CMD_SUCCESS;
13685 }
13686
13687 /* Return configuration string of community-list entry. */
13688 static const char *community_list_config_str(struct community_entry *entry)
13689 {
13690 const char *str;
13691
13692 if (entry->any)
13693 str = "";
13694 else {
13695 if (entry->style == COMMUNITY_LIST_STANDARD)
13696 str = community_str(entry->u.com, false);
13697 else if (entry->style == LARGE_COMMUNITY_LIST_STANDARD)
13698 str = lcommunity_str(entry->u.lcom, false);
13699 else
13700 str = entry->config;
13701 }
13702 return str;
13703 }
13704
13705 static void community_list_show(struct vty *vty, struct community_list *list)
13706 {
13707 struct community_entry *entry;
13708
13709 for (entry = list->head; entry; entry = entry->next) {
13710 if (entry == list->head) {
13711 if (all_digit(list->name))
13712 vty_out(vty, "Community %s list %s\n",
13713 entry->style == COMMUNITY_LIST_STANDARD
13714 ? "standard"
13715 : "(expanded) access",
13716 list->name);
13717 else
13718 vty_out(vty, "Named Community %s list %s\n",
13719 entry->style == COMMUNITY_LIST_STANDARD
13720 ? "standard"
13721 : "expanded",
13722 list->name);
13723 }
13724 if (entry->any)
13725 vty_out(vty, " %s\n",
13726 community_direct_str(entry->direct));
13727 else
13728 vty_out(vty, " %s %s\n",
13729 community_direct_str(entry->direct),
13730 community_list_config_str(entry));
13731 }
13732 }
13733
13734 DEFUN (show_ip_community_list,
13735 show_ip_community_list_cmd,
13736 "show ip community-list",
13737 SHOW_STR
13738 IP_STR
13739 "List community-list\n")
13740 {
13741 struct community_list *list;
13742 struct community_list_master *cm;
13743
13744 cm = community_list_master_lookup(bgp_clist, COMMUNITY_LIST_MASTER);
13745 if (!cm)
13746 return CMD_SUCCESS;
13747
13748 for (list = cm->num.head; list; list = list->next)
13749 community_list_show(vty, list);
13750
13751 for (list = cm->str.head; list; list = list->next)
13752 community_list_show(vty, list);
13753
13754 return CMD_SUCCESS;
13755 }
13756
13757 DEFUN (show_ip_community_list_arg,
13758 show_ip_community_list_arg_cmd,
13759 "show ip community-list <(1-500)|WORD>",
13760 SHOW_STR
13761 IP_STR
13762 "List community-list\n"
13763 "Community-list number\n"
13764 "Community-list name\n")
13765 {
13766 int idx_comm_list = 3;
13767 struct community_list *list;
13768
13769 list = community_list_lookup(bgp_clist, argv[idx_comm_list]->arg,
13770 COMMUNITY_LIST_MASTER);
13771 if (!list) {
13772 vty_out(vty, "%% Can't find community-list\n");
13773 return CMD_WARNING;
13774 }
13775
13776 community_list_show(vty, list);
13777
13778 return CMD_SUCCESS;
13779 }
13780
13781 /*
13782 * Large Community code.
13783 */
13784 static int lcommunity_list_set_vty(struct vty *vty, int argc,
13785 struct cmd_token **argv, int style,
13786 int reject_all_digit_name)
13787 {
13788 int ret;
13789 int direct;
13790 char *str;
13791 int idx = 0;
13792 char *cl_name;
13793
13794 direct = argv_find(argv, argc, "permit", &idx) ? COMMUNITY_PERMIT
13795 : COMMUNITY_DENY;
13796
13797 /* All digit name check. */
13798 idx = 0;
13799 argv_find(argv, argc, "WORD", &idx);
13800 argv_find(argv, argc, "(1-99)", &idx);
13801 argv_find(argv, argc, "(100-500)", &idx);
13802 cl_name = argv[idx]->arg;
13803 if (reject_all_digit_name && all_digit(cl_name)) {
13804 vty_out(vty, "%% Community name cannot have all digits\n");
13805 return CMD_WARNING_CONFIG_FAILED;
13806 }
13807
13808 idx = 0;
13809 argv_find(argv, argc, "AA:BB:CC", &idx);
13810 argv_find(argv, argc, "LINE", &idx);
13811 /* Concat community string argument. */
13812 if (idx)
13813 str = argv_concat(argv, argc, idx);
13814 else
13815 str = NULL;
13816
13817 ret = lcommunity_list_set(bgp_clist, cl_name, str, direct, style);
13818
13819 /* Free temporary community list string allocated by
13820 argv_concat(). */
13821 if (str)
13822 XFREE(MTYPE_TMP, str);
13823
13824 if (ret < 0) {
13825 community_list_perror(vty, ret);
13826 return CMD_WARNING_CONFIG_FAILED;
13827 }
13828 return CMD_SUCCESS;
13829 }
13830
13831 static int lcommunity_list_unset_vty(struct vty *vty, int argc,
13832 struct cmd_token **argv, int style)
13833 {
13834 int ret;
13835 int direct = 0;
13836 char *str = NULL;
13837 int idx = 0;
13838
13839 argv_find(argv, argc, "permit", &idx);
13840 argv_find(argv, argc, "deny", &idx);
13841
13842 if (idx) {
13843 /* Check the list direct. */
13844 if (strncmp(argv[idx]->arg, "p", 1) == 0)
13845 direct = COMMUNITY_PERMIT;
13846 else
13847 direct = COMMUNITY_DENY;
13848
13849 idx = 0;
13850 argv_find(argv, argc, "LINE", &idx);
13851 argv_find(argv, argc, "AA:AA:NN", &idx);
13852 /* Concat community string argument. */
13853 str = argv_concat(argv, argc, idx);
13854 }
13855
13856 idx = 0;
13857 argv_find(argv, argc, "(1-99)", &idx);
13858 argv_find(argv, argc, "(100-500)", &idx);
13859 argv_find(argv, argc, "WORD", &idx);
13860
13861 /* Unset community list. */
13862 ret = lcommunity_list_unset(bgp_clist, argv[idx]->arg, str, direct,
13863 style);
13864
13865 /* Free temporary community list string allocated by
13866 argv_concat(). */
13867 if (str)
13868 XFREE(MTYPE_TMP, str);
13869
13870 if (ret < 0) {
13871 community_list_perror(vty, ret);
13872 return CMD_WARNING_CONFIG_FAILED;
13873 }
13874
13875 return CMD_SUCCESS;
13876 }
13877
13878 /* "large-community-list" keyword help string. */
13879 #define LCOMMUNITY_LIST_STR "Add a large community list entry\n"
13880 #define LCOMMUNITY_VAL_STR "large community in 'aa:bb:cc' format\n"
13881
13882 DEFUN (ip_lcommunity_list_standard,
13883 ip_lcommunity_list_standard_cmd,
13884 "ip large-community-list (1-99) <deny|permit>",
13885 IP_STR
13886 LCOMMUNITY_LIST_STR
13887 "Large Community list number (standard)\n"
13888 "Specify large community to reject\n"
13889 "Specify large community to accept\n")
13890 {
13891 return lcommunity_list_set_vty(vty, argc, argv,
13892 LARGE_COMMUNITY_LIST_STANDARD, 0);
13893 }
13894
13895 DEFUN (ip_lcommunity_list_standard1,
13896 ip_lcommunity_list_standard1_cmd,
13897 "ip large-community-list (1-99) <deny|permit> AA:BB:CC...",
13898 IP_STR
13899 LCOMMUNITY_LIST_STR
13900 "Large Community list number (standard)\n"
13901 "Specify large community to reject\n"
13902 "Specify large community to accept\n"
13903 LCOMMUNITY_VAL_STR)
13904 {
13905 return lcommunity_list_set_vty(vty, argc, argv,
13906 LARGE_COMMUNITY_LIST_STANDARD, 0);
13907 }
13908
13909 DEFUN (ip_lcommunity_list_expanded,
13910 ip_lcommunity_list_expanded_cmd,
13911 "ip large-community-list (100-500) <deny|permit> LINE...",
13912 IP_STR
13913 LCOMMUNITY_LIST_STR
13914 "Large Community list number (expanded)\n"
13915 "Specify large community to reject\n"
13916 "Specify large community to accept\n"
13917 "An ordered list as a regular-expression\n")
13918 {
13919 return lcommunity_list_set_vty(vty, argc, argv,
13920 LARGE_COMMUNITY_LIST_EXPANDED, 0);
13921 }
13922
13923 DEFUN (ip_lcommunity_list_name_standard,
13924 ip_lcommunity_list_name_standard_cmd,
13925 "ip large-community-list standard WORD <deny|permit>",
13926 IP_STR
13927 LCOMMUNITY_LIST_STR
13928 "Specify standard large-community-list\n"
13929 "Large Community list name\n"
13930 "Specify large community to reject\n"
13931 "Specify large community to accept\n")
13932 {
13933 return lcommunity_list_set_vty(vty, argc, argv,
13934 LARGE_COMMUNITY_LIST_STANDARD, 1);
13935 }
13936
13937 DEFUN (ip_lcommunity_list_name_standard1,
13938 ip_lcommunity_list_name_standard1_cmd,
13939 "ip large-community-list standard WORD <deny|permit> AA:BB:CC...",
13940 IP_STR
13941 LCOMMUNITY_LIST_STR
13942 "Specify standard large-community-list\n"
13943 "Large Community list name\n"
13944 "Specify large community to reject\n"
13945 "Specify large community to accept\n"
13946 LCOMMUNITY_VAL_STR)
13947 {
13948 return lcommunity_list_set_vty(vty, argc, argv,
13949 LARGE_COMMUNITY_LIST_STANDARD, 1);
13950 }
13951
13952 DEFUN (ip_lcommunity_list_name_expanded,
13953 ip_lcommunity_list_name_expanded_cmd,
13954 "ip large-community-list expanded WORD <deny|permit> LINE...",
13955 IP_STR
13956 LCOMMUNITY_LIST_STR
13957 "Specify expanded large-community-list\n"
13958 "Large Community list name\n"
13959 "Specify large community to reject\n"
13960 "Specify large community to accept\n"
13961 "An ordered list as a regular-expression\n")
13962 {
13963 return lcommunity_list_set_vty(vty, argc, argv,
13964 LARGE_COMMUNITY_LIST_EXPANDED, 1);
13965 }
13966
13967 DEFUN (no_ip_lcommunity_list_standard_all,
13968 no_ip_lcommunity_list_standard_all_cmd,
13969 "no ip large-community-list <(1-99)|(100-500)|WORD>",
13970 NO_STR
13971 IP_STR
13972 LCOMMUNITY_LIST_STR
13973 "Large Community list number (standard)\n"
13974 "Large Community list number (expanded)\n"
13975 "Large Community list name\n")
13976 {
13977 return lcommunity_list_unset_vty(vty, argc, argv,
13978 LARGE_COMMUNITY_LIST_STANDARD);
13979 }
13980
13981 DEFUN (no_ip_lcommunity_list_name_expanded_all,
13982 no_ip_lcommunity_list_name_expanded_all_cmd,
13983 "no ip large-community-list expanded WORD",
13984 NO_STR
13985 IP_STR
13986 LCOMMUNITY_LIST_STR
13987 "Specify expanded large-community-list\n"
13988 "Large Community list name\n")
13989 {
13990 return lcommunity_list_unset_vty(vty, argc, argv,
13991 LARGE_COMMUNITY_LIST_EXPANDED);
13992 }
13993
13994 DEFUN (no_ip_lcommunity_list_standard,
13995 no_ip_lcommunity_list_standard_cmd,
13996 "no ip large-community-list (1-99) <deny|permit> AA:AA:NN...",
13997 NO_STR
13998 IP_STR
13999 LCOMMUNITY_LIST_STR
14000 "Large Community list number (standard)\n"
14001 "Specify large community to reject\n"
14002 "Specify large community to accept\n"
14003 LCOMMUNITY_VAL_STR)
14004 {
14005 return lcommunity_list_unset_vty(vty, argc, argv,
14006 LARGE_COMMUNITY_LIST_STANDARD);
14007 }
14008
14009 DEFUN (no_ip_lcommunity_list_expanded,
14010 no_ip_lcommunity_list_expanded_cmd,
14011 "no ip large-community-list (100-500) <deny|permit> LINE...",
14012 NO_STR
14013 IP_STR
14014 LCOMMUNITY_LIST_STR
14015 "Large Community list number (expanded)\n"
14016 "Specify large community to reject\n"
14017 "Specify large community to accept\n"
14018 "An ordered list as a regular-expression\n")
14019 {
14020 return lcommunity_list_unset_vty(vty, argc, argv,
14021 LARGE_COMMUNITY_LIST_EXPANDED);
14022 }
14023
14024 DEFUN (no_ip_lcommunity_list_name_standard,
14025 no_ip_lcommunity_list_name_standard_cmd,
14026 "no ip large-community-list standard WORD <deny|permit> AA:AA:NN...",
14027 NO_STR
14028 IP_STR
14029 LCOMMUNITY_LIST_STR
14030 "Specify standard large-community-list\n"
14031 "Large Community list name\n"
14032 "Specify large community to reject\n"
14033 "Specify large community to accept\n"
14034 LCOMMUNITY_VAL_STR)
14035 {
14036 return lcommunity_list_unset_vty(vty, argc, argv,
14037 LARGE_COMMUNITY_LIST_STANDARD);
14038 }
14039
14040 DEFUN (no_ip_lcommunity_list_name_expanded,
14041 no_ip_lcommunity_list_name_expanded_cmd,
14042 "no ip large-community-list expanded WORD <deny|permit> LINE...",
14043 NO_STR
14044 IP_STR
14045 LCOMMUNITY_LIST_STR
14046 "Specify expanded large-community-list\n"
14047 "Large community list name\n"
14048 "Specify large community to reject\n"
14049 "Specify large community to accept\n"
14050 "An ordered list as a regular-expression\n")
14051 {
14052 return lcommunity_list_unset_vty(vty, argc, argv,
14053 LARGE_COMMUNITY_LIST_EXPANDED);
14054 }
14055
14056 static void lcommunity_list_show(struct vty *vty, struct community_list *list)
14057 {
14058 struct community_entry *entry;
14059
14060 for (entry = list->head; entry; entry = entry->next) {
14061 if (entry == list->head) {
14062 if (all_digit(list->name))
14063 vty_out(vty, "Large community %s list %s\n",
14064 entry->style == EXTCOMMUNITY_LIST_STANDARD
14065 ? "standard"
14066 : "(expanded) access",
14067 list->name);
14068 else
14069 vty_out(vty,
14070 "Named large community %s list %s\n",
14071 entry->style == EXTCOMMUNITY_LIST_STANDARD
14072 ? "standard"
14073 : "expanded",
14074 list->name);
14075 }
14076 if (entry->any)
14077 vty_out(vty, " %s\n",
14078 community_direct_str(entry->direct));
14079 else
14080 vty_out(vty, " %s %s\n",
14081 community_direct_str(entry->direct),
14082 community_list_config_str(entry));
14083 }
14084 }
14085
14086 DEFUN (show_ip_lcommunity_list,
14087 show_ip_lcommunity_list_cmd,
14088 "show ip large-community-list",
14089 SHOW_STR
14090 IP_STR
14091 "List large-community list\n")
14092 {
14093 struct community_list *list;
14094 struct community_list_master *cm;
14095
14096 cm = community_list_master_lookup(bgp_clist,
14097 LARGE_COMMUNITY_LIST_MASTER);
14098 if (!cm)
14099 return CMD_SUCCESS;
14100
14101 for (list = cm->num.head; list; list = list->next)
14102 lcommunity_list_show(vty, list);
14103
14104 for (list = cm->str.head; list; list = list->next)
14105 lcommunity_list_show(vty, list);
14106
14107 return CMD_SUCCESS;
14108 }
14109
14110 DEFUN (show_ip_lcommunity_list_arg,
14111 show_ip_lcommunity_list_arg_cmd,
14112 "show ip large-community-list <(1-500)|WORD>",
14113 SHOW_STR
14114 IP_STR
14115 "List large-community list\n"
14116 "large-community-list number\n"
14117 "large-community-list name\n")
14118 {
14119 struct community_list *list;
14120
14121 list = community_list_lookup(bgp_clist, argv[3]->arg,
14122 LARGE_COMMUNITY_LIST_MASTER);
14123 if (!list) {
14124 vty_out(vty, "%% Can't find extcommunity-list\n");
14125 return CMD_WARNING;
14126 }
14127
14128 lcommunity_list_show(vty, list);
14129
14130 return CMD_SUCCESS;
14131 }
14132
14133 /* "extcommunity-list" keyword help string. */
14134 #define EXTCOMMUNITY_LIST_STR "Add a extended community list entry\n"
14135 #define EXTCOMMUNITY_VAL_STR "Extended community attribute in 'rt aa:nn_or_IPaddr:nn' OR 'soo aa:nn_or_IPaddr:nn' format\n"
14136
14137 DEFUN (ip_extcommunity_list_standard,
14138 ip_extcommunity_list_standard_cmd,
14139 "ip extcommunity-list <(1-99)|standard WORD> <deny|permit> AA:NN...",
14140 IP_STR
14141 EXTCOMMUNITY_LIST_STR
14142 "Extended Community list number (standard)\n"
14143 "Specify standard extcommunity-list\n"
14144 "Community list name\n"
14145 "Specify community to reject\n"
14146 "Specify community to accept\n"
14147 EXTCOMMUNITY_VAL_STR)
14148 {
14149 int style = EXTCOMMUNITY_LIST_STANDARD;
14150 int direct = 0;
14151 char *cl_number_or_name = NULL;
14152
14153 int idx = 0;
14154 argv_find(argv, argc, "(1-99)", &idx);
14155 argv_find(argv, argc, "WORD", &idx);
14156 cl_number_or_name = argv[idx]->arg;
14157 direct = argv_find(argv, argc, "permit", &idx) ? COMMUNITY_PERMIT
14158 : COMMUNITY_DENY;
14159 argv_find(argv, argc, "AA:NN", &idx);
14160 char *str = argv_concat(argv, argc, idx);
14161
14162 int ret = extcommunity_list_set(bgp_clist, cl_number_or_name, str,
14163 direct, style);
14164
14165 XFREE(MTYPE_TMP, str);
14166
14167 if (ret < 0) {
14168 community_list_perror(vty, ret);
14169 return CMD_WARNING_CONFIG_FAILED;
14170 }
14171
14172 return CMD_SUCCESS;
14173 }
14174
14175 DEFUN (ip_extcommunity_list_name_expanded,
14176 ip_extcommunity_list_name_expanded_cmd,
14177 "ip extcommunity-list <(100-500)|expanded WORD> <deny|permit> LINE...",
14178 IP_STR
14179 EXTCOMMUNITY_LIST_STR
14180 "Extended Community list number (expanded)\n"
14181 "Specify expanded extcommunity-list\n"
14182 "Extended Community list name\n"
14183 "Specify community to reject\n"
14184 "Specify community to accept\n"
14185 "An ordered list as a regular-expression\n")
14186 {
14187 int style = EXTCOMMUNITY_LIST_EXPANDED;
14188 int direct = 0;
14189 char *cl_number_or_name = NULL;
14190
14191 int idx = 0;
14192 argv_find(argv, argc, "(100-500)", &idx);
14193 argv_find(argv, argc, "WORD", &idx);
14194 cl_number_or_name = argv[idx]->arg;
14195 direct = argv_find(argv, argc, "permit", &idx) ? COMMUNITY_PERMIT
14196 : COMMUNITY_DENY;
14197 argv_find(argv, argc, "LINE", &idx);
14198 char *str = argv_concat(argv, argc, idx);
14199
14200 int ret = extcommunity_list_set(bgp_clist, cl_number_or_name, str,
14201 direct, style);
14202
14203 XFREE(MTYPE_TMP, str);
14204
14205 if (ret < 0) {
14206 community_list_perror(vty, ret);
14207 return CMD_WARNING_CONFIG_FAILED;
14208 }
14209
14210 return CMD_SUCCESS;
14211 }
14212
14213 DEFUN (no_ip_extcommunity_list_standard_all,
14214 no_ip_extcommunity_list_standard_all_cmd,
14215 "no ip extcommunity-list <(1-99)|standard WORD> <deny|permit> AA:NN...",
14216 NO_STR
14217 IP_STR
14218 EXTCOMMUNITY_LIST_STR
14219 "Extended Community list number (standard)\n"
14220 "Specify standard extcommunity-list\n"
14221 "Community list name\n"
14222 "Specify community to reject\n"
14223 "Specify community to accept\n"
14224 EXTCOMMUNITY_VAL_STR)
14225 {
14226 int style = EXTCOMMUNITY_LIST_STANDARD;
14227 int direct = 0;
14228 char *cl_number_or_name = NULL;
14229
14230 int idx = 0;
14231 argv_find(argv, argc, "(1-99)", &idx);
14232 argv_find(argv, argc, "WORD", &idx);
14233 cl_number_or_name = argv[idx]->arg;
14234 direct = argv_find(argv, argc, "permit", &idx) ? COMMUNITY_PERMIT
14235 : COMMUNITY_DENY;
14236 argv_find(argv, argc, "AA:NN", &idx);
14237 char *str = argv_concat(argv, argc, idx);
14238
14239 int ret = extcommunity_list_unset(bgp_clist, cl_number_or_name, str,
14240 direct, style);
14241
14242 XFREE(MTYPE_TMP, str);
14243
14244 if (ret < 0) {
14245 community_list_perror(vty, ret);
14246 return CMD_WARNING_CONFIG_FAILED;
14247 }
14248
14249 return CMD_SUCCESS;
14250 }
14251
14252 DEFUN (no_ip_extcommunity_list_expanded_all,
14253 no_ip_extcommunity_list_expanded_all_cmd,
14254 "no ip extcommunity-list <(100-500)|expanded WORD> <deny|permit> LINE...",
14255 NO_STR
14256 IP_STR
14257 EXTCOMMUNITY_LIST_STR
14258 "Extended Community list number (expanded)\n"
14259 "Specify expanded extcommunity-list\n"
14260 "Extended Community list name\n"
14261 "Specify community to reject\n"
14262 "Specify community to accept\n"
14263 "An ordered list as a regular-expression\n")
14264 {
14265 int style = EXTCOMMUNITY_LIST_EXPANDED;
14266 int direct = 0;
14267 char *cl_number_or_name = NULL;
14268
14269 int idx = 0;
14270 argv_find(argv, argc, "(100-500)", &idx);
14271 argv_find(argv, argc, "WORD", &idx);
14272 cl_number_or_name = argv[idx]->arg;
14273 direct = argv_find(argv, argc, "permit", &idx) ? COMMUNITY_PERMIT
14274 : COMMUNITY_DENY;
14275 argv_find(argv, argc, "LINE", &idx);
14276 char *str = argv_concat(argv, argc, idx);
14277
14278 int ret = extcommunity_list_unset(bgp_clist, cl_number_or_name, str,
14279 direct, style);
14280
14281 XFREE(MTYPE_TMP, str);
14282
14283 if (ret < 0) {
14284 community_list_perror(vty, ret);
14285 return CMD_WARNING_CONFIG_FAILED;
14286 }
14287
14288 return CMD_SUCCESS;
14289 }
14290
14291 static void extcommunity_list_show(struct vty *vty, struct community_list *list)
14292 {
14293 struct community_entry *entry;
14294
14295 for (entry = list->head; entry; entry = entry->next) {
14296 if (entry == list->head) {
14297 if (all_digit(list->name))
14298 vty_out(vty, "Extended community %s list %s\n",
14299 entry->style == EXTCOMMUNITY_LIST_STANDARD
14300 ? "standard"
14301 : "(expanded) access",
14302 list->name);
14303 else
14304 vty_out(vty,
14305 "Named extended community %s list %s\n",
14306 entry->style == EXTCOMMUNITY_LIST_STANDARD
14307 ? "standard"
14308 : "expanded",
14309 list->name);
14310 }
14311 if (entry->any)
14312 vty_out(vty, " %s\n",
14313 community_direct_str(entry->direct));
14314 else
14315 vty_out(vty, " %s %s\n",
14316 community_direct_str(entry->direct),
14317 community_list_config_str(entry));
14318 }
14319 }
14320
14321 DEFUN (show_ip_extcommunity_list,
14322 show_ip_extcommunity_list_cmd,
14323 "show ip extcommunity-list",
14324 SHOW_STR
14325 IP_STR
14326 "List extended-community list\n")
14327 {
14328 struct community_list *list;
14329 struct community_list_master *cm;
14330
14331 cm = community_list_master_lookup(bgp_clist, EXTCOMMUNITY_LIST_MASTER);
14332 if (!cm)
14333 return CMD_SUCCESS;
14334
14335 for (list = cm->num.head; list; list = list->next)
14336 extcommunity_list_show(vty, list);
14337
14338 for (list = cm->str.head; list; list = list->next)
14339 extcommunity_list_show(vty, list);
14340
14341 return CMD_SUCCESS;
14342 }
14343
14344 DEFUN (show_ip_extcommunity_list_arg,
14345 show_ip_extcommunity_list_arg_cmd,
14346 "show ip extcommunity-list <(1-500)|WORD>",
14347 SHOW_STR
14348 IP_STR
14349 "List extended-community list\n"
14350 "Extcommunity-list number\n"
14351 "Extcommunity-list name\n")
14352 {
14353 int idx_comm_list = 3;
14354 struct community_list *list;
14355
14356 list = community_list_lookup(bgp_clist, argv[idx_comm_list]->arg,
14357 EXTCOMMUNITY_LIST_MASTER);
14358 if (!list) {
14359 vty_out(vty, "%% Can't find extcommunity-list\n");
14360 return CMD_WARNING;
14361 }
14362
14363 extcommunity_list_show(vty, list);
14364
14365 return CMD_SUCCESS;
14366 }
14367
14368 /* Display community-list and extcommunity-list configuration. */
14369 static int community_list_config_write(struct vty *vty)
14370 {
14371 struct community_list *list;
14372 struct community_entry *entry;
14373 struct community_list_master *cm;
14374 int write = 0;
14375
14376 /* Community-list. */
14377 cm = community_list_master_lookup(bgp_clist, COMMUNITY_LIST_MASTER);
14378
14379 for (list = cm->num.head; list; list = list->next)
14380 for (entry = list->head; entry; entry = entry->next) {
14381 vty_out(vty, "ip community-list %s %s %s\n", list->name,
14382 community_direct_str(entry->direct),
14383 community_list_config_str(entry));
14384 write++;
14385 }
14386 for (list = cm->str.head; list; list = list->next)
14387 for (entry = list->head; entry; entry = entry->next) {
14388 vty_out(vty, "ip community-list %s %s %s %s\n",
14389 entry->style == COMMUNITY_LIST_STANDARD
14390 ? "standard"
14391 : "expanded",
14392 list->name, community_direct_str(entry->direct),
14393 community_list_config_str(entry));
14394 write++;
14395 }
14396
14397 /* Extcommunity-list. */
14398 cm = community_list_master_lookup(bgp_clist, EXTCOMMUNITY_LIST_MASTER);
14399
14400 for (list = cm->num.head; list; list = list->next)
14401 for (entry = list->head; entry; entry = entry->next) {
14402 vty_out(vty, "ip extcommunity-list %s %s %s\n",
14403 list->name, community_direct_str(entry->direct),
14404 community_list_config_str(entry));
14405 write++;
14406 }
14407 for (list = cm->str.head; list; list = list->next)
14408 for (entry = list->head; entry; entry = entry->next) {
14409 vty_out(vty, "ip extcommunity-list %s %s %s %s\n",
14410 entry->style == EXTCOMMUNITY_LIST_STANDARD
14411 ? "standard"
14412 : "expanded",
14413 list->name, community_direct_str(entry->direct),
14414 community_list_config_str(entry));
14415 write++;
14416 }
14417
14418
14419 /* lcommunity-list. */
14420 cm = community_list_master_lookup(bgp_clist,
14421 LARGE_COMMUNITY_LIST_MASTER);
14422
14423 for (list = cm->num.head; list; list = list->next)
14424 for (entry = list->head; entry; entry = entry->next) {
14425 vty_out(vty, "ip large-community-list %s %s %s\n",
14426 list->name, community_direct_str(entry->direct),
14427 community_list_config_str(entry));
14428 write++;
14429 }
14430 for (list = cm->str.head; list; list = list->next)
14431 for (entry = list->head; entry; entry = entry->next) {
14432 vty_out(vty, "ip large-community-list %s %s %s %s\n",
14433 entry->style == LARGE_COMMUNITY_LIST_STANDARD
14434 ? "standard"
14435 : "expanded",
14436 list->name, community_direct_str(entry->direct),
14437 community_list_config_str(entry));
14438 write++;
14439 }
14440
14441 return write;
14442 }
14443
14444 static struct cmd_node community_list_node = {
14445 COMMUNITY_LIST_NODE, "", 1 /* Export to vtysh. */
14446 };
14447
14448 static void community_list_vty(void)
14449 {
14450 install_node(&community_list_node, community_list_config_write);
14451
14452 /* Community-list. */
14453 install_element(CONFIG_NODE, &ip_community_list_standard_cmd);
14454 install_element(CONFIG_NODE, &ip_community_list_expanded_all_cmd);
14455 install_element(CONFIG_NODE, &no_ip_community_list_standard_all_cmd);
14456 install_element(CONFIG_NODE, &no_ip_community_list_expanded_all_cmd);
14457 install_element(VIEW_NODE, &show_ip_community_list_cmd);
14458 install_element(VIEW_NODE, &show_ip_community_list_arg_cmd);
14459
14460 /* Extcommunity-list. */
14461 install_element(CONFIG_NODE, &ip_extcommunity_list_standard_cmd);
14462 install_element(CONFIG_NODE, &ip_extcommunity_list_name_expanded_cmd);
14463 install_element(CONFIG_NODE, &no_ip_extcommunity_list_standard_all_cmd);
14464 install_element(CONFIG_NODE, &no_ip_extcommunity_list_expanded_all_cmd);
14465 install_element(VIEW_NODE, &show_ip_extcommunity_list_cmd);
14466 install_element(VIEW_NODE, &show_ip_extcommunity_list_arg_cmd);
14467
14468 /* Large Community List */
14469 install_element(CONFIG_NODE, &ip_lcommunity_list_standard_cmd);
14470 install_element(CONFIG_NODE, &ip_lcommunity_list_standard1_cmd);
14471 install_element(CONFIG_NODE, &ip_lcommunity_list_expanded_cmd);
14472 install_element(CONFIG_NODE, &ip_lcommunity_list_name_standard_cmd);
14473 install_element(CONFIG_NODE, &ip_lcommunity_list_name_standard1_cmd);
14474 install_element(CONFIG_NODE, &ip_lcommunity_list_name_expanded_cmd);
14475 install_element(CONFIG_NODE, &no_ip_lcommunity_list_standard_all_cmd);
14476 install_element(CONFIG_NODE,
14477 &no_ip_lcommunity_list_name_expanded_all_cmd);
14478 install_element(CONFIG_NODE, &no_ip_lcommunity_list_standard_cmd);
14479 install_element(CONFIG_NODE, &no_ip_lcommunity_list_expanded_cmd);
14480 install_element(CONFIG_NODE, &no_ip_lcommunity_list_name_standard_cmd);
14481 install_element(CONFIG_NODE, &no_ip_lcommunity_list_name_expanded_cmd);
14482 install_element(VIEW_NODE, &show_ip_lcommunity_list_cmd);
14483 install_element(VIEW_NODE, &show_ip_lcommunity_list_arg_cmd);
14484 }