]> git.proxmox.com Git - mirror_frr.git/blob - bgpd/bgp_vty.c
Merge pull request #2272 from msablic/vtysh_reconnect
[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
775 DEFUN (bgp_multiple_instance_func,
776 bgp_multiple_instance_cmd,
777 "bgp multiple-instance",
778 BGP_STR
779 "Enable bgp multiple instance\n")
780 {
781 bgp_option_set(BGP_OPT_MULTIPLE_INSTANCE);
782 return CMD_SUCCESS;
783 }
784
785 DEFUN (no_bgp_multiple_instance,
786 no_bgp_multiple_instance_cmd,
787 "no bgp multiple-instance",
788 NO_STR
789 BGP_STR
790 "BGP multiple instance\n")
791 {
792 int ret;
793
794 ret = bgp_option_unset(BGP_OPT_MULTIPLE_INSTANCE);
795 if (ret < 0) {
796 vty_out(vty, "%% There are more than two BGP instances\n");
797 return CMD_WARNING_CONFIG_FAILED;
798 }
799 return CMD_SUCCESS;
800 }
801
802 DEFUN (bgp_config_type,
803 bgp_config_type_cmd,
804 "bgp config-type <cisco|zebra>",
805 BGP_STR
806 "Configuration type\n"
807 "cisco\n"
808 "zebra\n")
809 {
810 int idx = 0;
811 if (argv_find(argv, argc, "cisco", &idx))
812 bgp_option_set(BGP_OPT_CONFIG_CISCO);
813 else
814 bgp_option_unset(BGP_OPT_CONFIG_CISCO);
815
816 return CMD_SUCCESS;
817 }
818
819 DEFUN (no_bgp_config_type,
820 no_bgp_config_type_cmd,
821 "no bgp config-type [<cisco|zebra>]",
822 NO_STR
823 BGP_STR
824 "Display configuration type\n"
825 "cisco\n"
826 "zebra\n")
827 {
828 bgp_option_unset(BGP_OPT_CONFIG_CISCO);
829 return CMD_SUCCESS;
830 }
831
832
833 DEFUN (no_synchronization,
834 no_synchronization_cmd,
835 "no synchronization",
836 NO_STR
837 "Perform IGP synchronization\n")
838 {
839 return CMD_SUCCESS;
840 }
841
842 DEFUN (no_auto_summary,
843 no_auto_summary_cmd,
844 "no auto-summary",
845 NO_STR
846 "Enable automatic network number summarization\n")
847 {
848 return CMD_SUCCESS;
849 }
850
851 /* "router bgp" commands. */
852 DEFUN_NOSH (router_bgp,
853 router_bgp_cmd,
854 "router bgp [(1-4294967295) [<view|vrf> VIEWVRFNAME]]",
855 ROUTER_STR
856 BGP_STR
857 AS_STR
858 BGP_INSTANCE_HELP_STR)
859 {
860 int idx_asn = 2;
861 int idx_view_vrf = 3;
862 int idx_vrf = 4;
863 int ret;
864 as_t as;
865 struct bgp *bgp;
866 const char *name = NULL;
867 enum bgp_instance_type inst_type;
868
869 // "router bgp" without an ASN
870 if (argc == 2) {
871 // Pending: Make VRF option available for ASN less config
872 bgp = bgp_get_default();
873
874 if (bgp == NULL) {
875 vty_out(vty, "%% No BGP process is configured\n");
876 return CMD_WARNING_CONFIG_FAILED;
877 }
878
879 if (listcount(bm->bgp) > 1) {
880 vty_out(vty, "%% Please specify ASN and VRF\n");
881 return CMD_WARNING_CONFIG_FAILED;
882 }
883 }
884
885 // "router bgp X"
886 else {
887 as = strtoul(argv[idx_asn]->arg, NULL, 10);
888
889 inst_type = BGP_INSTANCE_TYPE_DEFAULT;
890 if (argc > 3) {
891 name = argv[idx_vrf]->arg;
892
893 if (!strcmp(argv[idx_view_vrf]->text, "vrf"))
894 inst_type = BGP_INSTANCE_TYPE_VRF;
895 else if (!strcmp(argv[idx_view_vrf]->text, "view"))
896 inst_type = BGP_INSTANCE_TYPE_VIEW;
897 }
898
899 ret = bgp_get(&bgp, &as, name, inst_type);
900 switch (ret) {
901 case BGP_ERR_MULTIPLE_INSTANCE_NOT_SET:
902 vty_out(vty,
903 "Please specify 'bgp multiple-instance' first\n");
904 return CMD_WARNING_CONFIG_FAILED;
905 case BGP_ERR_AS_MISMATCH:
906 vty_out(vty, "BGP is already running; AS is %u\n", as);
907 return CMD_WARNING_CONFIG_FAILED;
908 case BGP_ERR_INSTANCE_MISMATCH:
909 vty_out(vty,
910 "BGP instance name and AS number mismatch\n");
911 vty_out(vty,
912 "BGP instance is already running; AS is %u\n",
913 as);
914 return CMD_WARNING_CONFIG_FAILED;
915 }
916
917 /* Pending: handle when user tries to change a view to vrf n vv.
918 */
919 }
920
921 /* unset the auto created flag as the user config is now present */
922 UNSET_FLAG(bgp->vrf_flags, BGP_VRF_AUTO);
923 VTY_PUSH_CONTEXT(BGP_NODE, bgp);
924
925 return CMD_SUCCESS;
926 }
927
928 /* "no router bgp" commands. */
929 DEFUN (no_router_bgp,
930 no_router_bgp_cmd,
931 "no router bgp [(1-4294967295) [<view|vrf> VIEWVRFNAME]]",
932 NO_STR
933 ROUTER_STR
934 BGP_STR
935 AS_STR
936 BGP_INSTANCE_HELP_STR)
937 {
938 int idx_asn = 3;
939 int idx_vrf = 5;
940 as_t as;
941 struct bgp *bgp;
942 const char *name = NULL;
943
944 // "no router bgp" without an ASN
945 if (argc == 3) {
946 // Pending: Make VRF option available for ASN less config
947 bgp = bgp_get_default();
948
949 if (bgp == NULL) {
950 vty_out(vty, "%% No BGP process is configured\n");
951 return CMD_WARNING_CONFIG_FAILED;
952 }
953
954 if (listcount(bm->bgp) > 1) {
955 vty_out(vty, "%% Please specify ASN and VRF\n");
956 return CMD_WARNING_CONFIG_FAILED;
957 }
958
959 if (bgp->l3vni) {
960 vty_out(vty, "%% Please unconfigure l3vni %u",
961 bgp->l3vni);
962 return CMD_WARNING_CONFIG_FAILED;
963 }
964 } else {
965 as = strtoul(argv[idx_asn]->arg, NULL, 10);
966
967 if (argc > 4)
968 name = argv[idx_vrf]->arg;
969
970 /* Lookup bgp structure. */
971 bgp = bgp_lookup(as, name);
972 if (!bgp) {
973 vty_out(vty, "%% Can't find BGP instance\n");
974 return CMD_WARNING_CONFIG_FAILED;
975 }
976
977 if (bgp->l3vni) {
978 vty_out(vty, "%% Please unconfigure l3vni %u",
979 bgp->l3vni);
980 return CMD_WARNING_CONFIG_FAILED;
981 }
982 }
983
984 bgp_delete(bgp);
985
986 return CMD_SUCCESS;
987 }
988
989
990 /* BGP router-id. */
991
992 DEFPY (bgp_router_id,
993 bgp_router_id_cmd,
994 "bgp router-id A.B.C.D",
995 BGP_STR
996 "Override configured router identifier\n"
997 "Manually configured router identifier\n")
998 {
999 VTY_DECLVAR_CONTEXT(bgp, bgp);
1000 bgp_router_id_static_set(bgp, router_id);
1001 return CMD_SUCCESS;
1002 }
1003
1004 DEFPY (no_bgp_router_id,
1005 no_bgp_router_id_cmd,
1006 "no bgp router-id [A.B.C.D]",
1007 NO_STR
1008 BGP_STR
1009 "Override configured router identifier\n"
1010 "Manually configured router identifier\n")
1011 {
1012 VTY_DECLVAR_CONTEXT(bgp, bgp);
1013
1014 if (router_id_str) {
1015 if (!IPV4_ADDR_SAME(&bgp->router_id_static, &router_id)) {
1016 vty_out(vty, "%% BGP router-id doesn't match\n");
1017 return CMD_WARNING_CONFIG_FAILED;
1018 }
1019 }
1020
1021 router_id.s_addr = 0;
1022 bgp_router_id_static_set(bgp, router_id);
1023
1024 return CMD_SUCCESS;
1025 }
1026
1027
1028 /* BGP Cluster ID. */
1029 DEFUN (bgp_cluster_id,
1030 bgp_cluster_id_cmd,
1031 "bgp cluster-id <A.B.C.D|(1-4294967295)>",
1032 BGP_STR
1033 "Configure Route-Reflector Cluster-id\n"
1034 "Route-Reflector Cluster-id in IP address format\n"
1035 "Route-Reflector Cluster-id as 32 bit quantity\n")
1036 {
1037 VTY_DECLVAR_CONTEXT(bgp, bgp);
1038 int idx_ipv4 = 2;
1039 int ret;
1040 struct in_addr cluster;
1041
1042 ret = inet_aton(argv[idx_ipv4]->arg, &cluster);
1043 if (!ret) {
1044 vty_out(vty, "%% Malformed bgp cluster identifier\n");
1045 return CMD_WARNING_CONFIG_FAILED;
1046 }
1047
1048 bgp_cluster_id_set(bgp, &cluster);
1049 bgp_clear_star_soft_out(vty, bgp->name);
1050
1051 return CMD_SUCCESS;
1052 }
1053
1054 DEFUN (no_bgp_cluster_id,
1055 no_bgp_cluster_id_cmd,
1056 "no bgp cluster-id [<A.B.C.D|(1-4294967295)>]",
1057 NO_STR
1058 BGP_STR
1059 "Configure Route-Reflector Cluster-id\n"
1060 "Route-Reflector Cluster-id in IP address format\n"
1061 "Route-Reflector Cluster-id as 32 bit quantity\n")
1062 {
1063 VTY_DECLVAR_CONTEXT(bgp, bgp);
1064 bgp_cluster_id_unset(bgp);
1065 bgp_clear_star_soft_out(vty, bgp->name);
1066
1067 return CMD_SUCCESS;
1068 }
1069
1070 DEFUN (bgp_confederation_identifier,
1071 bgp_confederation_identifier_cmd,
1072 "bgp confederation identifier (1-4294967295)",
1073 "BGP specific commands\n"
1074 "AS confederation parameters\n"
1075 "AS number\n"
1076 "Set routing domain confederation AS\n")
1077 {
1078 VTY_DECLVAR_CONTEXT(bgp, bgp);
1079 int idx_number = 3;
1080 as_t as;
1081
1082 as = strtoul(argv[idx_number]->arg, NULL, 10);
1083
1084 bgp_confederation_id_set(bgp, as);
1085
1086 return CMD_SUCCESS;
1087 }
1088
1089 DEFUN (no_bgp_confederation_identifier,
1090 no_bgp_confederation_identifier_cmd,
1091 "no bgp confederation identifier [(1-4294967295)]",
1092 NO_STR
1093 "BGP specific commands\n"
1094 "AS confederation parameters\n"
1095 "AS number\n"
1096 "Set routing domain confederation AS\n")
1097 {
1098 VTY_DECLVAR_CONTEXT(bgp, bgp);
1099 bgp_confederation_id_unset(bgp);
1100
1101 return CMD_SUCCESS;
1102 }
1103
1104 DEFUN (bgp_confederation_peers,
1105 bgp_confederation_peers_cmd,
1106 "bgp confederation peers (1-4294967295)...",
1107 "BGP specific commands\n"
1108 "AS confederation parameters\n"
1109 "Peer ASs in BGP confederation\n"
1110 AS_STR)
1111 {
1112 VTY_DECLVAR_CONTEXT(bgp, bgp);
1113 int idx_asn = 3;
1114 as_t as;
1115 int i;
1116
1117 for (i = idx_asn; i < argc; i++) {
1118 as = strtoul(argv[i]->arg, NULL, 10);
1119
1120 if (bgp->as == as) {
1121 vty_out(vty,
1122 "%% Local member-AS not allowed in confed peer list\n");
1123 continue;
1124 }
1125
1126 bgp_confederation_peers_add(bgp, as);
1127 }
1128 return CMD_SUCCESS;
1129 }
1130
1131 DEFUN (no_bgp_confederation_peers,
1132 no_bgp_confederation_peers_cmd,
1133 "no bgp confederation peers (1-4294967295)...",
1134 NO_STR
1135 "BGP specific commands\n"
1136 "AS confederation parameters\n"
1137 "Peer ASs in BGP confederation\n"
1138 AS_STR)
1139 {
1140 VTY_DECLVAR_CONTEXT(bgp, bgp);
1141 int idx_asn = 4;
1142 as_t as;
1143 int i;
1144
1145 for (i = idx_asn; i < argc; i++) {
1146 as = strtoul(argv[i]->arg, NULL, 10);
1147
1148 bgp_confederation_peers_remove(bgp, as);
1149 }
1150 return CMD_SUCCESS;
1151 }
1152
1153 /**
1154 * Central routine for maximum-paths configuration.
1155 * @peer_type: BGP_PEER_EBGP or BGP_PEER_IBGP
1156 * @set: 1 for setting values, 0 for removing the max-paths config.
1157 */
1158 static int bgp_maxpaths_config_vty(struct vty *vty, int peer_type,
1159 const char *mpaths, uint16_t options,
1160 int set)
1161 {
1162 VTY_DECLVAR_CONTEXT(bgp, bgp);
1163 uint16_t maxpaths = 0;
1164 int ret;
1165 afi_t afi;
1166 safi_t safi;
1167
1168 afi = bgp_node_afi(vty);
1169 safi = bgp_node_safi(vty);
1170
1171 if (set) {
1172 maxpaths = strtol(mpaths, NULL, 10);
1173 if (maxpaths > multipath_num) {
1174 vty_out(vty,
1175 "%% Maxpaths Specified: %d is > than multipath num specified on bgp command line %d",
1176 maxpaths, multipath_num);
1177 return CMD_WARNING_CONFIG_FAILED;
1178 }
1179 ret = bgp_maximum_paths_set(bgp, afi, safi, peer_type, maxpaths,
1180 options);
1181 } else
1182 ret = bgp_maximum_paths_unset(bgp, afi, safi, peer_type);
1183
1184 if (ret < 0) {
1185 vty_out(vty,
1186 "%% Failed to %sset maximum-paths %s %u for afi %u, safi %u\n",
1187 (set == 1) ? "" : "un",
1188 (peer_type == BGP_PEER_EBGP) ? "ebgp" : "ibgp",
1189 maxpaths, afi, safi);
1190 return CMD_WARNING_CONFIG_FAILED;
1191 }
1192
1193 bgp_recalculate_all_bestpaths(bgp);
1194
1195 return CMD_SUCCESS;
1196 }
1197
1198 DEFUN (bgp_maxmed_admin,
1199 bgp_maxmed_admin_cmd,
1200 "bgp max-med administrative ",
1201 BGP_STR
1202 "Advertise routes with max-med\n"
1203 "Administratively applied, for an indefinite period\n")
1204 {
1205 VTY_DECLVAR_CONTEXT(bgp, bgp);
1206
1207 bgp->v_maxmed_admin = 1;
1208 bgp->maxmed_admin_value = BGP_MAXMED_VALUE_DEFAULT;
1209
1210 bgp_maxmed_update(bgp);
1211
1212 return CMD_SUCCESS;
1213 }
1214
1215 DEFUN (bgp_maxmed_admin_medv,
1216 bgp_maxmed_admin_medv_cmd,
1217 "bgp max-med administrative (0-4294967295)",
1218 BGP_STR
1219 "Advertise routes with max-med\n"
1220 "Administratively applied, for an indefinite period\n"
1221 "Max MED value to be used\n")
1222 {
1223 VTY_DECLVAR_CONTEXT(bgp, bgp);
1224 int idx_number = 3;
1225
1226 bgp->v_maxmed_admin = 1;
1227 bgp->maxmed_admin_value = strtoul(argv[idx_number]->arg, NULL, 10);
1228
1229 bgp_maxmed_update(bgp);
1230
1231 return CMD_SUCCESS;
1232 }
1233
1234 DEFUN (no_bgp_maxmed_admin,
1235 no_bgp_maxmed_admin_cmd,
1236 "no bgp max-med administrative [(0-4294967295)]",
1237 NO_STR
1238 BGP_STR
1239 "Advertise routes with max-med\n"
1240 "Administratively applied, for an indefinite period\n"
1241 "Max MED value to be used\n")
1242 {
1243 VTY_DECLVAR_CONTEXT(bgp, bgp);
1244 bgp->v_maxmed_admin = BGP_MAXMED_ADMIN_UNCONFIGURED;
1245 bgp->maxmed_admin_value = BGP_MAXMED_VALUE_DEFAULT;
1246 bgp_maxmed_update(bgp);
1247
1248 return CMD_SUCCESS;
1249 }
1250
1251 DEFUN (bgp_maxmed_onstartup,
1252 bgp_maxmed_onstartup_cmd,
1253 "bgp max-med on-startup (5-86400) [(0-4294967295)]",
1254 BGP_STR
1255 "Advertise routes with max-med\n"
1256 "Effective on a startup\n"
1257 "Time (seconds) period for max-med\n"
1258 "Max MED value to be used\n")
1259 {
1260 VTY_DECLVAR_CONTEXT(bgp, bgp);
1261 int idx = 0;
1262
1263 argv_find(argv, argc, "(5-86400)", &idx);
1264 bgp->v_maxmed_onstartup = strtoul(argv[idx]->arg, NULL, 10);
1265 if (argv_find(argv, argc, "(0-4294967295)", &idx))
1266 bgp->maxmed_onstartup_value = strtoul(argv[idx]->arg, NULL, 10);
1267 else
1268 bgp->maxmed_onstartup_value = BGP_MAXMED_VALUE_DEFAULT;
1269
1270 bgp_maxmed_update(bgp);
1271
1272 return CMD_SUCCESS;
1273 }
1274
1275 DEFUN (no_bgp_maxmed_onstartup,
1276 no_bgp_maxmed_onstartup_cmd,
1277 "no bgp max-med on-startup [(5-86400) [(0-4294967295)]]",
1278 NO_STR
1279 BGP_STR
1280 "Advertise routes with max-med\n"
1281 "Effective on a startup\n"
1282 "Time (seconds) period for max-med\n"
1283 "Max MED value to be used\n")
1284 {
1285 VTY_DECLVAR_CONTEXT(bgp, bgp);
1286
1287 /* Cancel max-med onstartup if its on */
1288 if (bgp->t_maxmed_onstartup) {
1289 THREAD_TIMER_OFF(bgp->t_maxmed_onstartup);
1290 bgp->maxmed_onstartup_over = 1;
1291 }
1292
1293 bgp->v_maxmed_onstartup = BGP_MAXMED_ONSTARTUP_UNCONFIGURED;
1294 bgp->maxmed_onstartup_value = BGP_MAXMED_VALUE_DEFAULT;
1295
1296 bgp_maxmed_update(bgp);
1297
1298 return CMD_SUCCESS;
1299 }
1300
1301 static int bgp_update_delay_config_vty(struct vty *vty, const char *delay,
1302 const char *wait)
1303 {
1304 VTY_DECLVAR_CONTEXT(bgp, bgp);
1305 uint16_t update_delay;
1306 uint16_t establish_wait;
1307
1308 update_delay = strtoul(delay, NULL, 10);
1309
1310 if (!wait) /* update-delay <delay> */
1311 {
1312 bgp->v_update_delay = update_delay;
1313 bgp->v_establish_wait = bgp->v_update_delay;
1314 return CMD_SUCCESS;
1315 }
1316
1317 /* update-delay <delay> <establish-wait> */
1318 establish_wait = atoi(wait);
1319 if (update_delay < establish_wait) {
1320 vty_out(vty,
1321 "%%Failed: update-delay less than the establish-wait!\n");
1322 return CMD_WARNING_CONFIG_FAILED;
1323 }
1324
1325 bgp->v_update_delay = update_delay;
1326 bgp->v_establish_wait = establish_wait;
1327
1328 return CMD_SUCCESS;
1329 }
1330
1331 static int bgp_update_delay_deconfig_vty(struct vty *vty)
1332 {
1333 VTY_DECLVAR_CONTEXT(bgp, bgp);
1334
1335 bgp->v_update_delay = BGP_UPDATE_DELAY_DEF;
1336 bgp->v_establish_wait = bgp->v_update_delay;
1337
1338 return CMD_SUCCESS;
1339 }
1340
1341 void bgp_config_write_update_delay(struct vty *vty, struct bgp *bgp)
1342 {
1343 if (bgp->v_update_delay != BGP_UPDATE_DELAY_DEF) {
1344 vty_out(vty, " update-delay %d", bgp->v_update_delay);
1345 if (bgp->v_update_delay != bgp->v_establish_wait)
1346 vty_out(vty, " %d", bgp->v_establish_wait);
1347 vty_out(vty, "\n");
1348 }
1349 }
1350
1351
1352 /* Update-delay configuration */
1353 DEFUN (bgp_update_delay,
1354 bgp_update_delay_cmd,
1355 "update-delay (0-3600)",
1356 "Force initial delay for best-path and updates\n"
1357 "Seconds\n")
1358 {
1359 int idx_number = 1;
1360 return bgp_update_delay_config_vty(vty, argv[idx_number]->arg, NULL);
1361 }
1362
1363 DEFUN (bgp_update_delay_establish_wait,
1364 bgp_update_delay_establish_wait_cmd,
1365 "update-delay (0-3600) (1-3600)",
1366 "Force initial delay for best-path and updates\n"
1367 "Seconds\n"
1368 "Seconds\n")
1369 {
1370 int idx_number = 1;
1371 int idx_number_2 = 2;
1372 return bgp_update_delay_config_vty(vty, argv[idx_number]->arg,
1373 argv[idx_number_2]->arg);
1374 }
1375
1376 /* Update-delay deconfiguration */
1377 DEFUN (no_bgp_update_delay,
1378 no_bgp_update_delay_cmd,
1379 "no update-delay [(0-3600) [(1-3600)]]",
1380 NO_STR
1381 "Force initial delay for best-path and updates\n"
1382 "Seconds\n"
1383 "Seconds\n")
1384 {
1385 return bgp_update_delay_deconfig_vty(vty);
1386 }
1387
1388
1389 static int bgp_wpkt_quanta_config_vty(struct vty *vty, const char *num,
1390 char set)
1391 {
1392 VTY_DECLVAR_CONTEXT(bgp, bgp);
1393
1394 if (set) {
1395 uint32_t quanta = strtoul(num, NULL, 10);
1396 atomic_store_explicit(&bgp->wpkt_quanta, quanta,
1397 memory_order_relaxed);
1398 } else {
1399 atomic_store_explicit(&bgp->wpkt_quanta, BGP_WRITE_PACKET_MAX,
1400 memory_order_relaxed);
1401 }
1402
1403 return CMD_SUCCESS;
1404 }
1405
1406 static int bgp_rpkt_quanta_config_vty(struct vty *vty, const char *num,
1407 char set)
1408 {
1409 VTY_DECLVAR_CONTEXT(bgp, bgp);
1410
1411 if (set) {
1412 uint32_t quanta = strtoul(num, NULL, 10);
1413 atomic_store_explicit(&bgp->rpkt_quanta, quanta,
1414 memory_order_relaxed);
1415 } else {
1416 atomic_store_explicit(&bgp->rpkt_quanta, BGP_READ_PACKET_MAX,
1417 memory_order_relaxed);
1418 }
1419
1420 return CMD_SUCCESS;
1421 }
1422
1423 void bgp_config_write_wpkt_quanta(struct vty *vty, struct bgp *bgp)
1424 {
1425 uint32_t quanta =
1426 atomic_load_explicit(&bgp->wpkt_quanta, memory_order_relaxed);
1427 if (quanta != BGP_WRITE_PACKET_MAX)
1428 vty_out(vty, " write-quanta %d\n", quanta);
1429 }
1430
1431 void bgp_config_write_rpkt_quanta(struct vty *vty, struct bgp *bgp)
1432 {
1433 uint32_t quanta =
1434 atomic_load_explicit(&bgp->rpkt_quanta, memory_order_relaxed);
1435 if (quanta != BGP_READ_PACKET_MAX)
1436 vty_out(vty, " read-quanta %d\n", quanta);
1437 }
1438
1439 /* Packet quanta configuration */
1440 DEFUN (bgp_wpkt_quanta,
1441 bgp_wpkt_quanta_cmd,
1442 "write-quanta (1-10)",
1443 "How many packets to write to peer socket per run\n"
1444 "Number of packets\n")
1445 {
1446 int idx_number = 1;
1447 return bgp_wpkt_quanta_config_vty(vty, argv[idx_number]->arg, 1);
1448 }
1449
1450 DEFUN (no_bgp_wpkt_quanta,
1451 no_bgp_wpkt_quanta_cmd,
1452 "no write-quanta (1-10)",
1453 NO_STR
1454 "How many packets to write to peer socket per I/O cycle\n"
1455 "Number of packets\n")
1456 {
1457 int idx_number = 2;
1458 return bgp_wpkt_quanta_config_vty(vty, argv[idx_number]->arg, 0);
1459 }
1460
1461 DEFUN (bgp_rpkt_quanta,
1462 bgp_rpkt_quanta_cmd,
1463 "read-quanta (1-10)",
1464 "How many packets to read from peer socket per I/O cycle\n"
1465 "Number of packets\n")
1466 {
1467 int idx_number = 1;
1468 return bgp_rpkt_quanta_config_vty(vty, argv[idx_number]->arg, 1);
1469 }
1470
1471 DEFUN (no_bgp_rpkt_quanta,
1472 no_bgp_rpkt_quanta_cmd,
1473 "no read-quanta (1-10)",
1474 NO_STR
1475 "How many packets to read from peer socket per I/O cycle\n"
1476 "Number of packets\n")
1477 {
1478 int idx_number = 2;
1479 return bgp_rpkt_quanta_config_vty(vty, argv[idx_number]->arg, 0);
1480 }
1481
1482 void bgp_config_write_coalesce_time(struct vty *vty, struct bgp *bgp)
1483 {
1484 if (!bgp->heuristic_coalesce)
1485 vty_out(vty, " coalesce-time %u\n", bgp->coalesce_time);
1486 }
1487
1488
1489 DEFUN (bgp_coalesce_time,
1490 bgp_coalesce_time_cmd,
1491 "coalesce-time (0-4294967295)",
1492 "Subgroup coalesce timer\n"
1493 "Subgroup coalesce timer value (in ms)\n")
1494 {
1495 VTY_DECLVAR_CONTEXT(bgp, bgp);
1496
1497 int idx = 0;
1498 argv_find(argv, argc, "(0-4294967295)", &idx);
1499 bgp->heuristic_coalesce = false;
1500 bgp->coalesce_time = strtoul(argv[idx]->arg, NULL, 10);
1501 return CMD_SUCCESS;
1502 }
1503
1504 DEFUN (no_bgp_coalesce_time,
1505 no_bgp_coalesce_time_cmd,
1506 "no coalesce-time (0-4294967295)",
1507 NO_STR
1508 "Subgroup coalesce timer\n"
1509 "Subgroup coalesce timer value (in ms)\n")
1510 {
1511 VTY_DECLVAR_CONTEXT(bgp, bgp);
1512
1513 bgp->heuristic_coalesce = true;
1514 bgp->coalesce_time = BGP_DEFAULT_SUBGROUP_COALESCE_TIME;
1515 return CMD_SUCCESS;
1516 }
1517
1518 /* Maximum-paths configuration */
1519 DEFUN (bgp_maxpaths,
1520 bgp_maxpaths_cmd,
1521 "maximum-paths " CMD_RANGE_STR(1, MULTIPATH_NUM),
1522 "Forward packets over multiple paths\n"
1523 "Number of paths\n")
1524 {
1525 int idx_number = 1;
1526 return bgp_maxpaths_config_vty(vty, BGP_PEER_EBGP,
1527 argv[idx_number]->arg, 0, 1);
1528 }
1529
1530 ALIAS_HIDDEN(bgp_maxpaths, bgp_maxpaths_hidden_cmd,
1531 "maximum-paths " CMD_RANGE_STR(1, MULTIPATH_NUM),
1532 "Forward packets over multiple paths\n"
1533 "Number of paths\n")
1534
1535 DEFUN (bgp_maxpaths_ibgp,
1536 bgp_maxpaths_ibgp_cmd,
1537 "maximum-paths ibgp " CMD_RANGE_STR(1, MULTIPATH_NUM),
1538 "Forward packets over multiple paths\n"
1539 "iBGP-multipath\n"
1540 "Number of paths\n")
1541 {
1542 int idx_number = 2;
1543 return bgp_maxpaths_config_vty(vty, BGP_PEER_IBGP,
1544 argv[idx_number]->arg, 0, 1);
1545 }
1546
1547 ALIAS_HIDDEN(bgp_maxpaths_ibgp, bgp_maxpaths_ibgp_hidden_cmd,
1548 "maximum-paths ibgp " CMD_RANGE_STR(1, MULTIPATH_NUM),
1549 "Forward packets over multiple paths\n"
1550 "iBGP-multipath\n"
1551 "Number of paths\n")
1552
1553 DEFUN (bgp_maxpaths_ibgp_cluster,
1554 bgp_maxpaths_ibgp_cluster_cmd,
1555 "maximum-paths ibgp " CMD_RANGE_STR(1, MULTIPATH_NUM) " equal-cluster-length",
1556 "Forward packets over multiple paths\n"
1557 "iBGP-multipath\n"
1558 "Number of paths\n"
1559 "Match the cluster length\n")
1560 {
1561 int idx_number = 2;
1562 return bgp_maxpaths_config_vty(
1563 vty, BGP_PEER_IBGP, argv[idx_number]->arg,
1564 BGP_FLAG_IBGP_MULTIPATH_SAME_CLUSTERLEN, 1);
1565 }
1566
1567 ALIAS_HIDDEN(bgp_maxpaths_ibgp_cluster, bgp_maxpaths_ibgp_cluster_hidden_cmd,
1568 "maximum-paths ibgp " CMD_RANGE_STR(
1569 1, MULTIPATH_NUM) " equal-cluster-length",
1570 "Forward packets over multiple paths\n"
1571 "iBGP-multipath\n"
1572 "Number of paths\n"
1573 "Match the cluster length\n")
1574
1575 DEFUN (no_bgp_maxpaths,
1576 no_bgp_maxpaths_cmd,
1577 "no maximum-paths [" CMD_RANGE_STR(1, MULTIPATH_NUM) "]",
1578 NO_STR
1579 "Forward packets over multiple paths\n"
1580 "Number of paths\n")
1581 {
1582 return bgp_maxpaths_config_vty(vty, BGP_PEER_EBGP, NULL, 0, 0);
1583 }
1584
1585 ALIAS_HIDDEN(no_bgp_maxpaths, no_bgp_maxpaths_hidden_cmd,
1586 "no maximum-paths [" CMD_RANGE_STR(1, MULTIPATH_NUM) "]", NO_STR
1587 "Forward packets over multiple paths\n"
1588 "Number of paths\n")
1589
1590 DEFUN (no_bgp_maxpaths_ibgp,
1591 no_bgp_maxpaths_ibgp_cmd,
1592 "no maximum-paths ibgp [" CMD_RANGE_STR(1, MULTIPATH_NUM) " [equal-cluster-length]]",
1593 NO_STR
1594 "Forward packets over multiple paths\n"
1595 "iBGP-multipath\n"
1596 "Number of paths\n"
1597 "Match the cluster length\n")
1598 {
1599 return bgp_maxpaths_config_vty(vty, BGP_PEER_IBGP, NULL, 0, 0);
1600 }
1601
1602 ALIAS_HIDDEN(no_bgp_maxpaths_ibgp, no_bgp_maxpaths_ibgp_hidden_cmd,
1603 "no maximum-paths ibgp [" CMD_RANGE_STR(
1604 1, MULTIPATH_NUM) " [equal-cluster-length]]",
1605 NO_STR
1606 "Forward packets over multiple paths\n"
1607 "iBGP-multipath\n"
1608 "Number of paths\n"
1609 "Match the cluster length\n")
1610
1611 void bgp_config_write_maxpaths(struct vty *vty, struct bgp *bgp, afi_t afi,
1612 safi_t safi)
1613 {
1614 if (bgp->maxpaths[afi][safi].maxpaths_ebgp != MULTIPATH_NUM) {
1615 vty_out(vty, " maximum-paths %d\n",
1616 bgp->maxpaths[afi][safi].maxpaths_ebgp);
1617 }
1618
1619 if (bgp->maxpaths[afi][safi].maxpaths_ibgp != MULTIPATH_NUM) {
1620 vty_out(vty, " maximum-paths ibgp %d",
1621 bgp->maxpaths[afi][safi].maxpaths_ibgp);
1622 if (CHECK_FLAG(bgp->maxpaths[afi][safi].ibgp_flags,
1623 BGP_FLAG_IBGP_MULTIPATH_SAME_CLUSTERLEN))
1624 vty_out(vty, " equal-cluster-length");
1625 vty_out(vty, "\n");
1626 }
1627 }
1628
1629 /* BGP timers. */
1630
1631 DEFUN (bgp_timers,
1632 bgp_timers_cmd,
1633 "timers bgp (0-65535) (0-65535)",
1634 "Adjust routing timers\n"
1635 "BGP timers\n"
1636 "Keepalive interval\n"
1637 "Holdtime\n")
1638 {
1639 VTY_DECLVAR_CONTEXT(bgp, bgp);
1640 int idx_number = 2;
1641 int idx_number_2 = 3;
1642 unsigned long keepalive = 0;
1643 unsigned long holdtime = 0;
1644
1645 keepalive = strtoul(argv[idx_number]->arg, NULL, 10);
1646 holdtime = strtoul(argv[idx_number_2]->arg, NULL, 10);
1647
1648 /* Holdtime value check. */
1649 if (holdtime < 3 && holdtime != 0) {
1650 vty_out(vty,
1651 "%% hold time value must be either 0 or greater than 3\n");
1652 return CMD_WARNING_CONFIG_FAILED;
1653 }
1654
1655 bgp_timers_set(bgp, keepalive, holdtime);
1656
1657 return CMD_SUCCESS;
1658 }
1659
1660 DEFUN (no_bgp_timers,
1661 no_bgp_timers_cmd,
1662 "no timers bgp [(0-65535) (0-65535)]",
1663 NO_STR
1664 "Adjust routing timers\n"
1665 "BGP timers\n"
1666 "Keepalive interval\n"
1667 "Holdtime\n")
1668 {
1669 VTY_DECLVAR_CONTEXT(bgp, bgp);
1670 bgp_timers_unset(bgp);
1671
1672 return CMD_SUCCESS;
1673 }
1674
1675
1676 DEFUN (bgp_client_to_client_reflection,
1677 bgp_client_to_client_reflection_cmd,
1678 "bgp client-to-client reflection",
1679 "BGP specific commands\n"
1680 "Configure client to client route reflection\n"
1681 "reflection of routes allowed\n")
1682 {
1683 VTY_DECLVAR_CONTEXT(bgp, bgp);
1684 bgp_flag_unset(bgp, BGP_FLAG_NO_CLIENT_TO_CLIENT);
1685 bgp_clear_star_soft_out(vty, bgp->name);
1686
1687 return CMD_SUCCESS;
1688 }
1689
1690 DEFUN (no_bgp_client_to_client_reflection,
1691 no_bgp_client_to_client_reflection_cmd,
1692 "no bgp client-to-client reflection",
1693 NO_STR
1694 "BGP specific commands\n"
1695 "Configure client to client route reflection\n"
1696 "reflection of routes allowed\n")
1697 {
1698 VTY_DECLVAR_CONTEXT(bgp, bgp);
1699 bgp_flag_set(bgp, BGP_FLAG_NO_CLIENT_TO_CLIENT);
1700 bgp_clear_star_soft_out(vty, bgp->name);
1701
1702 return CMD_SUCCESS;
1703 }
1704
1705 /* "bgp always-compare-med" configuration. */
1706 DEFUN (bgp_always_compare_med,
1707 bgp_always_compare_med_cmd,
1708 "bgp always-compare-med",
1709 "BGP specific commands\n"
1710 "Allow comparing MED from different neighbors\n")
1711 {
1712 VTY_DECLVAR_CONTEXT(bgp, bgp);
1713 bgp_flag_set(bgp, BGP_FLAG_ALWAYS_COMPARE_MED);
1714 bgp_recalculate_all_bestpaths(bgp);
1715
1716 return CMD_SUCCESS;
1717 }
1718
1719 DEFUN (no_bgp_always_compare_med,
1720 no_bgp_always_compare_med_cmd,
1721 "no bgp always-compare-med",
1722 NO_STR
1723 "BGP specific commands\n"
1724 "Allow comparing MED from different neighbors\n")
1725 {
1726 VTY_DECLVAR_CONTEXT(bgp, bgp);
1727 bgp_flag_unset(bgp, BGP_FLAG_ALWAYS_COMPARE_MED);
1728 bgp_recalculate_all_bestpaths(bgp);
1729
1730 return CMD_SUCCESS;
1731 }
1732
1733 /* "bgp deterministic-med" configuration. */
1734 DEFUN (bgp_deterministic_med,
1735 bgp_deterministic_med_cmd,
1736 "bgp deterministic-med",
1737 "BGP specific commands\n"
1738 "Pick the best-MED path among paths advertised from the neighboring AS\n")
1739 {
1740 VTY_DECLVAR_CONTEXT(bgp, bgp);
1741
1742 if (!bgp_flag_check(bgp, BGP_FLAG_DETERMINISTIC_MED)) {
1743 bgp_flag_set(bgp, BGP_FLAG_DETERMINISTIC_MED);
1744 bgp_recalculate_all_bestpaths(bgp);
1745 }
1746
1747 return CMD_SUCCESS;
1748 }
1749
1750 DEFUN (no_bgp_deterministic_med,
1751 no_bgp_deterministic_med_cmd,
1752 "no bgp deterministic-med",
1753 NO_STR
1754 "BGP specific commands\n"
1755 "Pick the best-MED path among paths advertised from the neighboring AS\n")
1756 {
1757 VTY_DECLVAR_CONTEXT(bgp, bgp);
1758 int bestpath_per_as_used;
1759 afi_t afi;
1760 safi_t safi;
1761 struct peer *peer;
1762 struct listnode *node, *nnode;
1763
1764 if (bgp_flag_check(bgp, BGP_FLAG_DETERMINISTIC_MED)) {
1765 bestpath_per_as_used = 0;
1766
1767 for (ALL_LIST_ELEMENTS(bgp->peer, node, nnode, peer)) {
1768 FOREACH_AFI_SAFI (afi, safi)
1769 if (CHECK_FLAG(
1770 peer->af_flags[afi][safi],
1771 PEER_FLAG_ADDPATH_TX_BESTPATH_PER_AS)) {
1772 bestpath_per_as_used = 1;
1773 break;
1774 }
1775
1776 if (bestpath_per_as_used)
1777 break;
1778 }
1779
1780 if (bestpath_per_as_used) {
1781 vty_out(vty,
1782 "bgp deterministic-med cannot be disabled while addpath-tx-bestpath-per-AS is in use\n");
1783 return CMD_WARNING_CONFIG_FAILED;
1784 } else {
1785 bgp_flag_unset(bgp, BGP_FLAG_DETERMINISTIC_MED);
1786 bgp_recalculate_all_bestpaths(bgp);
1787 }
1788 }
1789
1790 return CMD_SUCCESS;
1791 }
1792
1793 /* "bgp graceful-restart" configuration. */
1794 DEFUN (bgp_graceful_restart,
1795 bgp_graceful_restart_cmd,
1796 "bgp graceful-restart",
1797 "BGP specific commands\n"
1798 "Graceful restart capability parameters\n")
1799 {
1800 VTY_DECLVAR_CONTEXT(bgp, bgp);
1801 bgp_flag_set(bgp, BGP_FLAG_GRACEFUL_RESTART);
1802 return CMD_SUCCESS;
1803 }
1804
1805 DEFUN (no_bgp_graceful_restart,
1806 no_bgp_graceful_restart_cmd,
1807 "no bgp graceful-restart",
1808 NO_STR
1809 "BGP specific commands\n"
1810 "Graceful restart capability parameters\n")
1811 {
1812 VTY_DECLVAR_CONTEXT(bgp, bgp);
1813 bgp_flag_unset(bgp, BGP_FLAG_GRACEFUL_RESTART);
1814 return CMD_SUCCESS;
1815 }
1816
1817 DEFUN (bgp_graceful_restart_stalepath_time,
1818 bgp_graceful_restart_stalepath_time_cmd,
1819 "bgp graceful-restart stalepath-time (1-3600)",
1820 "BGP specific commands\n"
1821 "Graceful restart capability parameters\n"
1822 "Set the max time to hold onto restarting peer's stale paths\n"
1823 "Delay value (seconds)\n")
1824 {
1825 VTY_DECLVAR_CONTEXT(bgp, bgp);
1826 int idx_number = 3;
1827 uint32_t stalepath;
1828
1829 stalepath = strtoul(argv[idx_number]->arg, NULL, 10);
1830 bgp->stalepath_time = stalepath;
1831 return CMD_SUCCESS;
1832 }
1833
1834 DEFUN (bgp_graceful_restart_restart_time,
1835 bgp_graceful_restart_restart_time_cmd,
1836 "bgp graceful-restart restart-time (1-3600)",
1837 "BGP specific commands\n"
1838 "Graceful restart capability parameters\n"
1839 "Set the time to wait to delete stale routes before a BGP open message is received\n"
1840 "Delay value (seconds)\n")
1841 {
1842 VTY_DECLVAR_CONTEXT(bgp, bgp);
1843 int idx_number = 3;
1844 uint32_t restart;
1845
1846 restart = strtoul(argv[idx_number]->arg, NULL, 10);
1847 bgp->restart_time = restart;
1848 return CMD_SUCCESS;
1849 }
1850
1851 DEFUN (no_bgp_graceful_restart_stalepath_time,
1852 no_bgp_graceful_restart_stalepath_time_cmd,
1853 "no bgp graceful-restart stalepath-time [(1-3600)]",
1854 NO_STR
1855 "BGP specific commands\n"
1856 "Graceful restart capability parameters\n"
1857 "Set the max time to hold onto restarting peer's stale paths\n"
1858 "Delay value (seconds)\n")
1859 {
1860 VTY_DECLVAR_CONTEXT(bgp, bgp);
1861
1862 bgp->stalepath_time = BGP_DEFAULT_STALEPATH_TIME;
1863 return CMD_SUCCESS;
1864 }
1865
1866 DEFUN (no_bgp_graceful_restart_restart_time,
1867 no_bgp_graceful_restart_restart_time_cmd,
1868 "no bgp graceful-restart restart-time [(1-3600)]",
1869 NO_STR
1870 "BGP specific commands\n"
1871 "Graceful restart capability parameters\n"
1872 "Set the time to wait to delete stale routes before a BGP open message is received\n"
1873 "Delay value (seconds)\n")
1874 {
1875 VTY_DECLVAR_CONTEXT(bgp, bgp);
1876
1877 bgp->restart_time = BGP_DEFAULT_RESTART_TIME;
1878 return CMD_SUCCESS;
1879 }
1880
1881 DEFUN (bgp_graceful_restart_preserve_fw,
1882 bgp_graceful_restart_preserve_fw_cmd,
1883 "bgp graceful-restart preserve-fw-state",
1884 "BGP specific commands\n"
1885 "Graceful restart capability parameters\n"
1886 "Sets F-bit indication that fib is preserved while doing Graceful Restart\n")
1887 {
1888 VTY_DECLVAR_CONTEXT(bgp, bgp);
1889 bgp_flag_set(bgp, BGP_FLAG_GR_PRESERVE_FWD);
1890 return CMD_SUCCESS;
1891 }
1892
1893 DEFUN (no_bgp_graceful_restart_preserve_fw,
1894 no_bgp_graceful_restart_preserve_fw_cmd,
1895 "no bgp graceful-restart preserve-fw-state",
1896 NO_STR
1897 "BGP specific commands\n"
1898 "Graceful restart capability parameters\n"
1899 "Unsets F-bit indication that fib is preserved while doing Graceful Restart\n")
1900 {
1901 VTY_DECLVAR_CONTEXT(bgp, bgp);
1902 bgp_flag_unset(bgp, BGP_FLAG_GR_PRESERVE_FWD);
1903 return CMD_SUCCESS;
1904 }
1905
1906 static void bgp_redistribute_redo(struct bgp *bgp)
1907 {
1908 afi_t afi;
1909 int i;
1910 struct list *red_list;
1911 struct listnode *node;
1912 struct bgp_redist *red;
1913
1914 for (afi = AFI_IP; afi < AFI_MAX; afi++) {
1915 for (i = 0; i < ZEBRA_ROUTE_MAX; i++) {
1916
1917 red_list = bgp->redist[afi][i];
1918 if (!red_list)
1919 continue;
1920
1921 for (ALL_LIST_ELEMENTS_RO(red_list, node, red)) {
1922 bgp_redistribute_resend(bgp, afi, i,
1923 red->instance);
1924 }
1925 }
1926 }
1927 }
1928
1929 /* "bgp graceful-shutdown" configuration */
1930 DEFUN (bgp_graceful_shutdown,
1931 bgp_graceful_shutdown_cmd,
1932 "bgp graceful-shutdown",
1933 BGP_STR
1934 "Graceful shutdown parameters\n")
1935 {
1936 VTY_DECLVAR_CONTEXT(bgp, bgp);
1937
1938 if (!bgp_flag_check(bgp, BGP_FLAG_GRACEFUL_SHUTDOWN)) {
1939 bgp_flag_set(bgp, BGP_FLAG_GRACEFUL_SHUTDOWN);
1940 bgp_static_redo_import_check(bgp);
1941 bgp_redistribute_redo(bgp);
1942 bgp_clear_star_soft_out(vty, bgp->name);
1943 bgp_clear_star_soft_in(vty, bgp->name);
1944 }
1945
1946 return CMD_SUCCESS;
1947 }
1948
1949 DEFUN (no_bgp_graceful_shutdown,
1950 no_bgp_graceful_shutdown_cmd,
1951 "no bgp graceful-shutdown",
1952 NO_STR
1953 BGP_STR
1954 "Graceful shutdown parameters\n")
1955 {
1956 VTY_DECLVAR_CONTEXT(bgp, bgp);
1957
1958 if (bgp_flag_check(bgp, BGP_FLAG_GRACEFUL_SHUTDOWN)) {
1959 bgp_flag_unset(bgp, BGP_FLAG_GRACEFUL_SHUTDOWN);
1960 bgp_static_redo_import_check(bgp);
1961 bgp_redistribute_redo(bgp);
1962 bgp_clear_star_soft_out(vty, bgp->name);
1963 bgp_clear_star_soft_in(vty, bgp->name);
1964 }
1965
1966 return CMD_SUCCESS;
1967 }
1968
1969 /* "bgp fast-external-failover" configuration. */
1970 DEFUN (bgp_fast_external_failover,
1971 bgp_fast_external_failover_cmd,
1972 "bgp fast-external-failover",
1973 BGP_STR
1974 "Immediately reset session if a link to a directly connected external peer goes down\n")
1975 {
1976 VTY_DECLVAR_CONTEXT(bgp, bgp);
1977 bgp_flag_unset(bgp, BGP_FLAG_NO_FAST_EXT_FAILOVER);
1978 return CMD_SUCCESS;
1979 }
1980
1981 DEFUN (no_bgp_fast_external_failover,
1982 no_bgp_fast_external_failover_cmd,
1983 "no bgp fast-external-failover",
1984 NO_STR
1985 BGP_STR
1986 "Immediately reset session if a link to a directly connected external peer goes down\n")
1987 {
1988 VTY_DECLVAR_CONTEXT(bgp, bgp);
1989 bgp_flag_set(bgp, BGP_FLAG_NO_FAST_EXT_FAILOVER);
1990 return CMD_SUCCESS;
1991 }
1992
1993 /* "bgp enforce-first-as" configuration. */
1994 DEFUN (bgp_enforce_first_as,
1995 bgp_enforce_first_as_cmd,
1996 "bgp enforce-first-as",
1997 BGP_STR
1998 "Enforce the first AS for EBGP routes\n")
1999 {
2000 VTY_DECLVAR_CONTEXT(bgp, bgp);
2001 bgp_flag_set(bgp, BGP_FLAG_ENFORCE_FIRST_AS);
2002 bgp_clear_star_soft_in(vty, bgp->name);
2003
2004 return CMD_SUCCESS;
2005 }
2006
2007 DEFUN (no_bgp_enforce_first_as,
2008 no_bgp_enforce_first_as_cmd,
2009 "no bgp enforce-first-as",
2010 NO_STR
2011 BGP_STR
2012 "Enforce the first AS for EBGP routes\n")
2013 {
2014 VTY_DECLVAR_CONTEXT(bgp, bgp);
2015 bgp_flag_unset(bgp, BGP_FLAG_ENFORCE_FIRST_AS);
2016 bgp_clear_star_soft_in(vty, bgp->name);
2017
2018 return CMD_SUCCESS;
2019 }
2020
2021 /* "bgp bestpath compare-routerid" configuration. */
2022 DEFUN (bgp_bestpath_compare_router_id,
2023 bgp_bestpath_compare_router_id_cmd,
2024 "bgp bestpath compare-routerid",
2025 "BGP specific commands\n"
2026 "Change the default bestpath selection\n"
2027 "Compare router-id for identical EBGP paths\n")
2028 {
2029 VTY_DECLVAR_CONTEXT(bgp, bgp);
2030 bgp_flag_set(bgp, BGP_FLAG_COMPARE_ROUTER_ID);
2031 bgp_recalculate_all_bestpaths(bgp);
2032
2033 return CMD_SUCCESS;
2034 }
2035
2036 DEFUN (no_bgp_bestpath_compare_router_id,
2037 no_bgp_bestpath_compare_router_id_cmd,
2038 "no bgp bestpath compare-routerid",
2039 NO_STR
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_unset(bgp, BGP_FLAG_COMPARE_ROUTER_ID);
2046 bgp_recalculate_all_bestpaths(bgp);
2047
2048 return CMD_SUCCESS;
2049 }
2050
2051 /* "bgp bestpath as-path ignore" configuration. */
2052 DEFUN (bgp_bestpath_aspath_ignore,
2053 bgp_bestpath_aspath_ignore_cmd,
2054 "bgp bestpath as-path ignore",
2055 "BGP specific commands\n"
2056 "Change the default bestpath selection\n"
2057 "AS-path attribute\n"
2058 "Ignore as-path length in selecting a route\n")
2059 {
2060 VTY_DECLVAR_CONTEXT(bgp, bgp);
2061 bgp_flag_set(bgp, BGP_FLAG_ASPATH_IGNORE);
2062 bgp_recalculate_all_bestpaths(bgp);
2063
2064 return CMD_SUCCESS;
2065 }
2066
2067 DEFUN (no_bgp_bestpath_aspath_ignore,
2068 no_bgp_bestpath_aspath_ignore_cmd,
2069 "no bgp bestpath as-path ignore",
2070 NO_STR
2071 "BGP specific commands\n"
2072 "Change the default bestpath selection\n"
2073 "AS-path attribute\n"
2074 "Ignore as-path length in selecting a route\n")
2075 {
2076 VTY_DECLVAR_CONTEXT(bgp, bgp);
2077 bgp_flag_unset(bgp, BGP_FLAG_ASPATH_IGNORE);
2078 bgp_recalculate_all_bestpaths(bgp);
2079
2080 return CMD_SUCCESS;
2081 }
2082
2083 /* "bgp bestpath as-path confed" configuration. */
2084 DEFUN (bgp_bestpath_aspath_confed,
2085 bgp_bestpath_aspath_confed_cmd,
2086 "bgp bestpath as-path confed",
2087 "BGP specific commands\n"
2088 "Change the default bestpath selection\n"
2089 "AS-path attribute\n"
2090 "Compare path lengths including confederation sets & sequences in selecting a route\n")
2091 {
2092 VTY_DECLVAR_CONTEXT(bgp, bgp);
2093 bgp_flag_set(bgp, BGP_FLAG_ASPATH_CONFED);
2094 bgp_recalculate_all_bestpaths(bgp);
2095
2096 return CMD_SUCCESS;
2097 }
2098
2099 DEFUN (no_bgp_bestpath_aspath_confed,
2100 no_bgp_bestpath_aspath_confed_cmd,
2101 "no bgp bestpath as-path confed",
2102 NO_STR
2103 "BGP specific commands\n"
2104 "Change the default bestpath selection\n"
2105 "AS-path attribute\n"
2106 "Compare path lengths including confederation sets & sequences in selecting a route\n")
2107 {
2108 VTY_DECLVAR_CONTEXT(bgp, bgp);
2109 bgp_flag_unset(bgp, BGP_FLAG_ASPATH_CONFED);
2110 bgp_recalculate_all_bestpaths(bgp);
2111
2112 return CMD_SUCCESS;
2113 }
2114
2115 /* "bgp bestpath as-path multipath-relax" configuration. */
2116 DEFUN (bgp_bestpath_aspath_multipath_relax,
2117 bgp_bestpath_aspath_multipath_relax_cmd,
2118 "bgp bestpath as-path multipath-relax [<as-set|no-as-set>]",
2119 "BGP specific commands\n"
2120 "Change the default bestpath selection\n"
2121 "AS-path attribute\n"
2122 "Allow load sharing across routes that have different AS paths (but same length)\n"
2123 "Generate an AS_SET\n"
2124 "Do not generate an AS_SET\n")
2125 {
2126 VTY_DECLVAR_CONTEXT(bgp, bgp);
2127 int idx = 0;
2128 bgp_flag_set(bgp, BGP_FLAG_ASPATH_MULTIPATH_RELAX);
2129
2130 /* no-as-set is now the default behavior so we can silently
2131 * ignore it */
2132 if (argv_find(argv, argc, "as-set", &idx))
2133 bgp_flag_set(bgp, BGP_FLAG_MULTIPATH_RELAX_AS_SET);
2134 else
2135 bgp_flag_unset(bgp, BGP_FLAG_MULTIPATH_RELAX_AS_SET);
2136
2137 bgp_recalculate_all_bestpaths(bgp);
2138
2139 return CMD_SUCCESS;
2140 }
2141
2142 DEFUN (no_bgp_bestpath_aspath_multipath_relax,
2143 no_bgp_bestpath_aspath_multipath_relax_cmd,
2144 "no bgp bestpath as-path multipath-relax [<as-set|no-as-set>]",
2145 NO_STR
2146 "BGP specific commands\n"
2147 "Change the default bestpath selection\n"
2148 "AS-path attribute\n"
2149 "Allow load sharing across routes that have different AS paths (but same length)\n"
2150 "Generate an AS_SET\n"
2151 "Do not generate an AS_SET\n")
2152 {
2153 VTY_DECLVAR_CONTEXT(bgp, bgp);
2154 bgp_flag_unset(bgp, BGP_FLAG_ASPATH_MULTIPATH_RELAX);
2155 bgp_flag_unset(bgp, BGP_FLAG_MULTIPATH_RELAX_AS_SET);
2156 bgp_recalculate_all_bestpaths(bgp);
2157
2158 return CMD_SUCCESS;
2159 }
2160
2161 /* "bgp log-neighbor-changes" configuration. */
2162 DEFUN (bgp_log_neighbor_changes,
2163 bgp_log_neighbor_changes_cmd,
2164 "bgp log-neighbor-changes",
2165 "BGP specific commands\n"
2166 "Log neighbor up/down and reset reason\n")
2167 {
2168 VTY_DECLVAR_CONTEXT(bgp, bgp);
2169 bgp_flag_set(bgp, BGP_FLAG_LOG_NEIGHBOR_CHANGES);
2170 return CMD_SUCCESS;
2171 }
2172
2173 DEFUN (no_bgp_log_neighbor_changes,
2174 no_bgp_log_neighbor_changes_cmd,
2175 "no bgp log-neighbor-changes",
2176 NO_STR
2177 "BGP specific commands\n"
2178 "Log neighbor up/down and reset reason\n")
2179 {
2180 VTY_DECLVAR_CONTEXT(bgp, bgp);
2181 bgp_flag_unset(bgp, BGP_FLAG_LOG_NEIGHBOR_CHANGES);
2182 return CMD_SUCCESS;
2183 }
2184
2185 /* "bgp bestpath med" configuration. */
2186 DEFUN (bgp_bestpath_med,
2187 bgp_bestpath_med_cmd,
2188 "bgp bestpath med <confed [missing-as-worst]|missing-as-worst [confed]>",
2189 "BGP specific commands\n"
2190 "Change the default bestpath selection\n"
2191 "MED attribute\n"
2192 "Compare MED among confederation paths\n"
2193 "Treat missing MED as the least preferred one\n"
2194 "Treat missing MED as the least preferred one\n"
2195 "Compare MED among confederation paths\n")
2196 {
2197 VTY_DECLVAR_CONTEXT(bgp, bgp);
2198
2199 int idx = 0;
2200 if (argv_find(argv, argc, "confed", &idx))
2201 bgp_flag_set(bgp, BGP_FLAG_MED_CONFED);
2202 idx = 0;
2203 if (argv_find(argv, argc, "missing-as-worst", &idx))
2204 bgp_flag_set(bgp, BGP_FLAG_MED_MISSING_AS_WORST);
2205
2206 bgp_recalculate_all_bestpaths(bgp);
2207
2208 return CMD_SUCCESS;
2209 }
2210
2211 DEFUN (no_bgp_bestpath_med,
2212 no_bgp_bestpath_med_cmd,
2213 "no bgp bestpath med <confed [missing-as-worst]|missing-as-worst [confed]>",
2214 NO_STR
2215 "BGP specific commands\n"
2216 "Change the default bestpath selection\n"
2217 "MED attribute\n"
2218 "Compare MED among confederation paths\n"
2219 "Treat missing MED as the least preferred one\n"
2220 "Treat missing MED as the least preferred one\n"
2221 "Compare MED among confederation paths\n")
2222 {
2223 VTY_DECLVAR_CONTEXT(bgp, bgp);
2224
2225 int idx = 0;
2226 if (argv_find(argv, argc, "confed", &idx))
2227 bgp_flag_unset(bgp, BGP_FLAG_MED_CONFED);
2228 idx = 0;
2229 if (argv_find(argv, argc, "missing-as-worst", &idx))
2230 bgp_flag_unset(bgp, BGP_FLAG_MED_MISSING_AS_WORST);
2231
2232 bgp_recalculate_all_bestpaths(bgp);
2233
2234 return CMD_SUCCESS;
2235 }
2236
2237 /* "no bgp default ipv4-unicast". */
2238 DEFUN (no_bgp_default_ipv4_unicast,
2239 no_bgp_default_ipv4_unicast_cmd,
2240 "no bgp default ipv4-unicast",
2241 NO_STR
2242 "BGP specific commands\n"
2243 "Configure BGP defaults\n"
2244 "Activate ipv4-unicast for a peer by default\n")
2245 {
2246 VTY_DECLVAR_CONTEXT(bgp, bgp);
2247 bgp_flag_set(bgp, BGP_FLAG_NO_DEFAULT_IPV4);
2248 return CMD_SUCCESS;
2249 }
2250
2251 DEFUN (bgp_default_ipv4_unicast,
2252 bgp_default_ipv4_unicast_cmd,
2253 "bgp default ipv4-unicast",
2254 "BGP specific commands\n"
2255 "Configure BGP defaults\n"
2256 "Activate ipv4-unicast for a peer by default\n")
2257 {
2258 VTY_DECLVAR_CONTEXT(bgp, bgp);
2259 bgp_flag_unset(bgp, BGP_FLAG_NO_DEFAULT_IPV4);
2260 return CMD_SUCCESS;
2261 }
2262
2263 /* Display hostname in certain command outputs */
2264 DEFUN (bgp_default_show_hostname,
2265 bgp_default_show_hostname_cmd,
2266 "bgp default show-hostname",
2267 "BGP specific commands\n"
2268 "Configure BGP defaults\n"
2269 "Show hostname in certain command ouputs\n")
2270 {
2271 VTY_DECLVAR_CONTEXT(bgp, bgp);
2272 bgp_flag_set(bgp, BGP_FLAG_SHOW_HOSTNAME);
2273 return CMD_SUCCESS;
2274 }
2275
2276 DEFUN (no_bgp_default_show_hostname,
2277 no_bgp_default_show_hostname_cmd,
2278 "no bgp default show-hostname",
2279 NO_STR
2280 "BGP specific commands\n"
2281 "Configure BGP defaults\n"
2282 "Show hostname in certain command ouputs\n")
2283 {
2284 VTY_DECLVAR_CONTEXT(bgp, bgp);
2285 bgp_flag_unset(bgp, BGP_FLAG_SHOW_HOSTNAME);
2286 return CMD_SUCCESS;
2287 }
2288
2289 /* "bgp network import-check" configuration. */
2290 DEFUN (bgp_network_import_check,
2291 bgp_network_import_check_cmd,
2292 "bgp network import-check",
2293 "BGP specific commands\n"
2294 "BGP network command\n"
2295 "Check BGP network route exists in IGP\n")
2296 {
2297 VTY_DECLVAR_CONTEXT(bgp, bgp);
2298 if (!bgp_flag_check(bgp, BGP_FLAG_IMPORT_CHECK)) {
2299 bgp_flag_set(bgp, BGP_FLAG_IMPORT_CHECK);
2300 bgp_static_redo_import_check(bgp);
2301 }
2302
2303 return CMD_SUCCESS;
2304 }
2305
2306 ALIAS_HIDDEN(bgp_network_import_check, bgp_network_import_check_exact_cmd,
2307 "bgp network import-check exact",
2308 "BGP specific commands\n"
2309 "BGP network command\n"
2310 "Check BGP network route exists in IGP\n"
2311 "Match route precisely\n")
2312
2313 DEFUN (no_bgp_network_import_check,
2314 no_bgp_network_import_check_cmd,
2315 "no bgp network import-check",
2316 NO_STR
2317 "BGP specific commands\n"
2318 "BGP network command\n"
2319 "Check BGP network route exists in IGP\n")
2320 {
2321 VTY_DECLVAR_CONTEXT(bgp, bgp);
2322 if (bgp_flag_check(bgp, BGP_FLAG_IMPORT_CHECK)) {
2323 bgp_flag_unset(bgp, BGP_FLAG_IMPORT_CHECK);
2324 bgp_static_redo_import_check(bgp);
2325 }
2326
2327 return CMD_SUCCESS;
2328 }
2329
2330 DEFUN (bgp_default_local_preference,
2331 bgp_default_local_preference_cmd,
2332 "bgp default local-preference (0-4294967295)",
2333 "BGP specific commands\n"
2334 "Configure BGP defaults\n"
2335 "local preference (higher=more preferred)\n"
2336 "Configure default local preference value\n")
2337 {
2338 VTY_DECLVAR_CONTEXT(bgp, bgp);
2339 int idx_number = 3;
2340 uint32_t local_pref;
2341
2342 local_pref = strtoul(argv[idx_number]->arg, NULL, 10);
2343
2344 bgp_default_local_preference_set(bgp, local_pref);
2345 bgp_clear_star_soft_in(vty, bgp->name);
2346
2347 return CMD_SUCCESS;
2348 }
2349
2350 DEFUN (no_bgp_default_local_preference,
2351 no_bgp_default_local_preference_cmd,
2352 "no bgp default local-preference [(0-4294967295)]",
2353 NO_STR
2354 "BGP specific commands\n"
2355 "Configure BGP defaults\n"
2356 "local preference (higher=more preferred)\n"
2357 "Configure default local preference value\n")
2358 {
2359 VTY_DECLVAR_CONTEXT(bgp, bgp);
2360 bgp_default_local_preference_unset(bgp);
2361 bgp_clear_star_soft_in(vty, bgp->name);
2362
2363 return CMD_SUCCESS;
2364 }
2365
2366
2367 DEFUN (bgp_default_subgroup_pkt_queue_max,
2368 bgp_default_subgroup_pkt_queue_max_cmd,
2369 "bgp default subgroup-pkt-queue-max (20-100)",
2370 "BGP specific commands\n"
2371 "Configure BGP defaults\n"
2372 "subgroup-pkt-queue-max\n"
2373 "Configure subgroup packet queue max\n")
2374 {
2375 VTY_DECLVAR_CONTEXT(bgp, bgp);
2376 int idx_number = 3;
2377 uint32_t max_size;
2378
2379 max_size = strtoul(argv[idx_number]->arg, NULL, 10);
2380
2381 bgp_default_subgroup_pkt_queue_max_set(bgp, max_size);
2382
2383 return CMD_SUCCESS;
2384 }
2385
2386 DEFUN (no_bgp_default_subgroup_pkt_queue_max,
2387 no_bgp_default_subgroup_pkt_queue_max_cmd,
2388 "no bgp default subgroup-pkt-queue-max [(20-100)]",
2389 NO_STR
2390 "BGP specific commands\n"
2391 "Configure BGP defaults\n"
2392 "subgroup-pkt-queue-max\n"
2393 "Configure subgroup packet queue max\n")
2394 {
2395 VTY_DECLVAR_CONTEXT(bgp, bgp);
2396 bgp_default_subgroup_pkt_queue_max_unset(bgp);
2397 return CMD_SUCCESS;
2398 }
2399
2400
2401 DEFUN (bgp_rr_allow_outbound_policy,
2402 bgp_rr_allow_outbound_policy_cmd,
2403 "bgp route-reflector allow-outbound-policy",
2404 "BGP specific commands\n"
2405 "Allow modifications made by out route-map\n"
2406 "on ibgp neighbors\n")
2407 {
2408 VTY_DECLVAR_CONTEXT(bgp, bgp);
2409
2410 if (!bgp_flag_check(bgp, BGP_FLAG_RR_ALLOW_OUTBOUND_POLICY)) {
2411 bgp_flag_set(bgp, BGP_FLAG_RR_ALLOW_OUTBOUND_POLICY);
2412 update_group_announce_rrclients(bgp);
2413 bgp_clear_star_soft_out(vty, bgp->name);
2414 }
2415
2416 return CMD_SUCCESS;
2417 }
2418
2419 DEFUN (no_bgp_rr_allow_outbound_policy,
2420 no_bgp_rr_allow_outbound_policy_cmd,
2421 "no bgp route-reflector allow-outbound-policy",
2422 NO_STR
2423 "BGP specific commands\n"
2424 "Allow modifications made by out route-map\n"
2425 "on ibgp neighbors\n")
2426 {
2427 VTY_DECLVAR_CONTEXT(bgp, bgp);
2428
2429 if (bgp_flag_check(bgp, BGP_FLAG_RR_ALLOW_OUTBOUND_POLICY)) {
2430 bgp_flag_unset(bgp, BGP_FLAG_RR_ALLOW_OUTBOUND_POLICY);
2431 update_group_announce_rrclients(bgp);
2432 bgp_clear_star_soft_out(vty, bgp->name);
2433 }
2434
2435 return CMD_SUCCESS;
2436 }
2437
2438 DEFUN (bgp_listen_limit,
2439 bgp_listen_limit_cmd,
2440 "bgp listen limit (1-5000)",
2441 "BGP specific commands\n"
2442 "Configure BGP defaults\n"
2443 "maximum number of BGP Dynamic Neighbors that can be created\n"
2444 "Configure Dynamic Neighbors listen limit value\n")
2445 {
2446 VTY_DECLVAR_CONTEXT(bgp, bgp);
2447 int idx_number = 3;
2448 int listen_limit;
2449
2450 listen_limit = strtoul(argv[idx_number]->arg, NULL, 10);
2451
2452 bgp_listen_limit_set(bgp, listen_limit);
2453
2454 return CMD_SUCCESS;
2455 }
2456
2457 DEFUN (no_bgp_listen_limit,
2458 no_bgp_listen_limit_cmd,
2459 "no bgp listen limit [(1-5000)]",
2460 "BGP specific commands\n"
2461 "Configure BGP defaults\n"
2462 "unset maximum number of BGP Dynamic Neighbors that can be created\n"
2463 "Configure Dynamic Neighbors listen limit value to default\n"
2464 "Configure Dynamic Neighbors listen limit value\n")
2465 {
2466 VTY_DECLVAR_CONTEXT(bgp, bgp);
2467 bgp_listen_limit_unset(bgp);
2468 return CMD_SUCCESS;
2469 }
2470
2471
2472 /*
2473 * Check if this listen range is already configured. Check for exact
2474 * match or overlap based on input.
2475 */
2476 static struct peer_group *listen_range_exists(struct bgp *bgp,
2477 struct prefix *range, int exact)
2478 {
2479 struct listnode *node, *nnode;
2480 struct listnode *node1, *nnode1;
2481 struct peer_group *group;
2482 struct prefix *lr;
2483 afi_t afi;
2484 int match;
2485
2486 afi = family2afi(range->family);
2487 for (ALL_LIST_ELEMENTS(bgp->group, node, nnode, group)) {
2488 for (ALL_LIST_ELEMENTS(group->listen_range[afi], node1, nnode1,
2489 lr)) {
2490 if (exact)
2491 match = prefix_same(range, lr);
2492 else
2493 match = (prefix_match(range, lr)
2494 || prefix_match(lr, range));
2495 if (match)
2496 return group;
2497 }
2498 }
2499
2500 return NULL;
2501 }
2502
2503 DEFUN (bgp_listen_range,
2504 bgp_listen_range_cmd,
2505 "bgp listen range <A.B.C.D/M|X:X::X:X/M> peer-group WORD",
2506 "BGP specific commands\n"
2507 "Configure BGP dynamic neighbors listen range\n"
2508 "Configure BGP dynamic neighbors listen range\n"
2509 NEIGHBOR_ADDR_STR
2510 "Member of the peer-group\n"
2511 "Peer-group name\n")
2512 {
2513 VTY_DECLVAR_CONTEXT(bgp, bgp);
2514 struct prefix range;
2515 struct peer_group *group, *existing_group;
2516 afi_t afi;
2517 int ret;
2518 int idx = 0;
2519
2520 argv_find(argv, argc, "A.B.C.D/M", &idx);
2521 argv_find(argv, argc, "X:X::X:X/M", &idx);
2522 char *prefix = argv[idx]->arg;
2523 argv_find(argv, argc, "WORD", &idx);
2524 char *peergroup = argv[idx]->arg;
2525
2526 /* Convert IP prefix string to struct prefix. */
2527 ret = str2prefix(prefix, &range);
2528 if (!ret) {
2529 vty_out(vty, "%% Malformed listen range\n");
2530 return CMD_WARNING_CONFIG_FAILED;
2531 }
2532
2533 afi = family2afi(range.family);
2534
2535 if (afi == AFI_IP6 && IN6_IS_ADDR_LINKLOCAL(&range.u.prefix6)) {
2536 vty_out(vty,
2537 "%% Malformed listen range (link-local address)\n");
2538 return CMD_WARNING_CONFIG_FAILED;
2539 }
2540
2541 apply_mask(&range);
2542
2543 /* Check if same listen range is already configured. */
2544 existing_group = listen_range_exists(bgp, &range, 1);
2545 if (existing_group) {
2546 if (strcmp(existing_group->name, peergroup) == 0)
2547 return CMD_SUCCESS;
2548 else {
2549 vty_out(vty,
2550 "%% Same listen range is attached to peer-group %s\n",
2551 existing_group->name);
2552 return CMD_WARNING_CONFIG_FAILED;
2553 }
2554 }
2555
2556 /* Check if an overlapping listen range exists. */
2557 if (listen_range_exists(bgp, &range, 0)) {
2558 vty_out(vty,
2559 "%% Listen range overlaps with existing listen range\n");
2560 return CMD_WARNING_CONFIG_FAILED;
2561 }
2562
2563 group = peer_group_lookup(bgp, peergroup);
2564 if (!group) {
2565 vty_out(vty, "%% Configure the peer-group first\n");
2566 return CMD_WARNING_CONFIG_FAILED;
2567 }
2568
2569 ret = peer_group_listen_range_add(group, &range);
2570 return bgp_vty_return(vty, ret);
2571 }
2572
2573 DEFUN (no_bgp_listen_range,
2574 no_bgp_listen_range_cmd,
2575 "no bgp listen range <A.B.C.D/M|X:X::X:X/M> peer-group WORD",
2576 NO_STR
2577 "BGP specific commands\n"
2578 "Unconfigure BGP dynamic neighbors listen range\n"
2579 "Unconfigure BGP dynamic neighbors listen range\n"
2580 NEIGHBOR_ADDR_STR
2581 "Member of the peer-group\n"
2582 "Peer-group name\n")
2583 {
2584 VTY_DECLVAR_CONTEXT(bgp, bgp);
2585 struct prefix range;
2586 struct peer_group *group;
2587 afi_t afi;
2588 int ret;
2589 int idx = 0;
2590
2591 argv_find(argv, argc, "A.B.C.D/M", &idx);
2592 argv_find(argv, argc, "X:X::X:X/M", &idx);
2593 char *prefix = argv[idx]->arg;
2594 argv_find(argv, argc, "WORD", &idx);
2595 char *peergroup = argv[idx]->arg;
2596
2597 /* Convert IP prefix string to struct prefix. */
2598 ret = str2prefix(prefix, &range);
2599 if (!ret) {
2600 vty_out(vty, "%% Malformed listen range\n");
2601 return CMD_WARNING_CONFIG_FAILED;
2602 }
2603
2604 afi = family2afi(range.family);
2605
2606 if (afi == AFI_IP6 && IN6_IS_ADDR_LINKLOCAL(&range.u.prefix6)) {
2607 vty_out(vty,
2608 "%% Malformed listen range (link-local address)\n");
2609 return CMD_WARNING_CONFIG_FAILED;
2610 }
2611
2612 apply_mask(&range);
2613
2614 group = peer_group_lookup(bgp, peergroup);
2615 if (!group) {
2616 vty_out(vty, "%% Peer-group does not exist\n");
2617 return CMD_WARNING_CONFIG_FAILED;
2618 }
2619
2620 ret = peer_group_listen_range_del(group, &range);
2621 return bgp_vty_return(vty, ret);
2622 }
2623
2624 void bgp_config_write_listen(struct vty *vty, struct bgp *bgp)
2625 {
2626 struct peer_group *group;
2627 struct listnode *node, *nnode, *rnode, *nrnode;
2628 struct prefix *range;
2629 afi_t afi;
2630 char buf[PREFIX2STR_BUFFER];
2631
2632 if (bgp->dynamic_neighbors_limit != BGP_DYNAMIC_NEIGHBORS_LIMIT_DEFAULT)
2633 vty_out(vty, " bgp listen limit %d\n",
2634 bgp->dynamic_neighbors_limit);
2635
2636 for (ALL_LIST_ELEMENTS(bgp->group, node, nnode, group)) {
2637 for (afi = AFI_IP; afi < AFI_MAX; afi++) {
2638 for (ALL_LIST_ELEMENTS(group->listen_range[afi], rnode,
2639 nrnode, range)) {
2640 prefix2str(range, buf, sizeof(buf));
2641 vty_out(vty,
2642 " bgp listen range %s peer-group %s\n",
2643 buf, group->name);
2644 }
2645 }
2646 }
2647 }
2648
2649
2650 DEFUN (bgp_disable_connected_route_check,
2651 bgp_disable_connected_route_check_cmd,
2652 "bgp disable-ebgp-connected-route-check",
2653 "BGP specific commands\n"
2654 "Disable checking if nexthop is connected on ebgp sessions\n")
2655 {
2656 VTY_DECLVAR_CONTEXT(bgp, bgp);
2657 bgp_flag_set(bgp, BGP_FLAG_DISABLE_NH_CONNECTED_CHK);
2658 bgp_clear_star_soft_in(vty, bgp->name);
2659
2660 return CMD_SUCCESS;
2661 }
2662
2663 DEFUN (no_bgp_disable_connected_route_check,
2664 no_bgp_disable_connected_route_check_cmd,
2665 "no bgp disable-ebgp-connected-route-check",
2666 NO_STR
2667 "BGP specific commands\n"
2668 "Disable checking if nexthop is connected on ebgp sessions\n")
2669 {
2670 VTY_DECLVAR_CONTEXT(bgp, bgp);
2671 bgp_flag_unset(bgp, BGP_FLAG_DISABLE_NH_CONNECTED_CHK);
2672 bgp_clear_star_soft_in(vty, bgp->name);
2673
2674 return CMD_SUCCESS;
2675 }
2676
2677
2678 static int peer_remote_as_vty(struct vty *vty, const char *peer_str,
2679 const char *as_str, afi_t afi, safi_t safi)
2680 {
2681 VTY_DECLVAR_CONTEXT(bgp, bgp);
2682 int ret;
2683 as_t as;
2684 int as_type = AS_SPECIFIED;
2685 union sockunion su;
2686
2687 if (as_str[0] == 'i') {
2688 as = 0;
2689 as_type = AS_INTERNAL;
2690 } else if (as_str[0] == 'e') {
2691 as = 0;
2692 as_type = AS_EXTERNAL;
2693 } else {
2694 /* Get AS number. */
2695 as = strtoul(as_str, NULL, 10);
2696 }
2697
2698 /* If peer is peer group, call proper function. */
2699 ret = str2sockunion(peer_str, &su);
2700 if (ret < 0) {
2701 /* Check for peer by interface */
2702 ret = peer_remote_as(bgp, NULL, peer_str, &as, as_type, afi,
2703 safi);
2704 if (ret < 0) {
2705 ret = peer_group_remote_as(bgp, peer_str, &as, as_type);
2706 if (ret < 0) {
2707 vty_out(vty,
2708 "%% Create the peer-group or interface first\n");
2709 return CMD_WARNING_CONFIG_FAILED;
2710 }
2711 return CMD_SUCCESS;
2712 }
2713 } else {
2714 if (peer_address_self_check(bgp, &su)) {
2715 vty_out(vty,
2716 "%% Can not configure the local system as neighbor\n");
2717 return CMD_WARNING_CONFIG_FAILED;
2718 }
2719 ret = peer_remote_as(bgp, &su, NULL, &as, as_type, afi, safi);
2720 }
2721
2722 /* This peer belongs to peer group. */
2723 switch (ret) {
2724 case BGP_ERR_PEER_GROUP_MEMBER:
2725 vty_out(vty,
2726 "%% Peer-group AS %u. Cannot configure remote-as for member\n",
2727 as);
2728 return CMD_WARNING_CONFIG_FAILED;
2729 case BGP_ERR_PEER_GROUP_PEER_TYPE_DIFFERENT:
2730 vty_out(vty,
2731 "%% The AS# can not be changed from %u to %s, peer-group members must be all internal or all external\n",
2732 as, as_str);
2733 return CMD_WARNING_CONFIG_FAILED;
2734 }
2735 return bgp_vty_return(vty, ret);
2736 }
2737
2738 DEFUN (bgp_default_shutdown,
2739 bgp_default_shutdown_cmd,
2740 "[no] bgp default shutdown",
2741 NO_STR
2742 BGP_STR
2743 "Configure BGP defaults\n"
2744 "Apply administrative shutdown to newly configured peers\n")
2745 {
2746 VTY_DECLVAR_CONTEXT(bgp, bgp);
2747 bgp->autoshutdown = !strmatch(argv[0]->text, "no");
2748 return CMD_SUCCESS;
2749 }
2750
2751 DEFUN (neighbor_remote_as,
2752 neighbor_remote_as_cmd,
2753 "neighbor <A.B.C.D|X:X::X:X|WORD> remote-as <(1-4294967295)|internal|external>",
2754 NEIGHBOR_STR
2755 NEIGHBOR_ADDR_STR2
2756 "Specify a BGP neighbor\n"
2757 AS_STR
2758 "Internal BGP peer\n"
2759 "External BGP peer\n")
2760 {
2761 int idx_peer = 1;
2762 int idx_remote_as = 3;
2763 return peer_remote_as_vty(vty, argv[idx_peer]->arg,
2764 argv[idx_remote_as]->arg, AFI_IP,
2765 SAFI_UNICAST);
2766 }
2767
2768 static int peer_conf_interface_get(struct vty *vty, const char *conf_if,
2769 afi_t afi, safi_t safi, int v6only,
2770 const char *peer_group_name,
2771 const char *as_str)
2772 {
2773 VTY_DECLVAR_CONTEXT(bgp, bgp);
2774 as_t as = 0;
2775 int as_type = AS_UNSPECIFIED;
2776 struct peer *peer;
2777 struct peer_group *group;
2778 int ret = 0;
2779 union sockunion su;
2780
2781 group = peer_group_lookup(bgp, conf_if);
2782
2783 if (group) {
2784 vty_out(vty, "%% Name conflict with peer-group \n");
2785 return CMD_WARNING_CONFIG_FAILED;
2786 }
2787
2788 if (as_str) {
2789 if (as_str[0] == 'i') {
2790 as_type = AS_INTERNAL;
2791 } else if (as_str[0] == 'e') {
2792 as_type = AS_EXTERNAL;
2793 } else {
2794 /* Get AS number. */
2795 as = strtoul(as_str, NULL, 10);
2796 as_type = AS_SPECIFIED;
2797 }
2798 }
2799
2800 peer = peer_lookup_by_conf_if(bgp, conf_if);
2801 if (peer) {
2802 if (as_str)
2803 ret = peer_remote_as(bgp, &su, conf_if, &as, as_type,
2804 afi, safi);
2805 } else {
2806 if (bgp_flag_check(bgp, BGP_FLAG_NO_DEFAULT_IPV4)
2807 && afi == AFI_IP && safi == SAFI_UNICAST)
2808 peer = peer_create(NULL, conf_if, bgp, bgp->as, as,
2809 as_type, 0, 0, NULL);
2810 else
2811 peer = peer_create(NULL, conf_if, bgp, bgp->as, as,
2812 as_type, afi, safi, NULL);
2813
2814 if (!peer) {
2815 vty_out(vty, "%% BGP failed to create peer\n");
2816 return CMD_WARNING_CONFIG_FAILED;
2817 }
2818
2819 if (v6only)
2820 SET_FLAG(peer->flags, PEER_FLAG_IFPEER_V6ONLY);
2821
2822 /* Request zebra to initiate IPv6 RAs on this interface. We do
2823 * this
2824 * any unnumbered peer in order to not worry about run-time
2825 * transitions
2826 * (e.g., peering is initially IPv4, but the IPv4 /30 or /31
2827 * address
2828 * gets deleted later etc.)
2829 */
2830 if (peer->ifp)
2831 bgp_zebra_initiate_radv(bgp, peer);
2832 }
2833
2834 if ((v6only && !CHECK_FLAG(peer->flags, PEER_FLAG_IFPEER_V6ONLY))
2835 || (!v6only && CHECK_FLAG(peer->flags, PEER_FLAG_IFPEER_V6ONLY))) {
2836 if (v6only)
2837 SET_FLAG(peer->flags, PEER_FLAG_IFPEER_V6ONLY);
2838 else
2839 UNSET_FLAG(peer->flags, PEER_FLAG_IFPEER_V6ONLY);
2840
2841 /* v6only flag changed. Reset bgp seesion */
2842 if (BGP_IS_VALID_STATE_FOR_NOTIF(peer->status)) {
2843 peer->last_reset = PEER_DOWN_V6ONLY_CHANGE;
2844 bgp_notify_send(peer, BGP_NOTIFY_CEASE,
2845 BGP_NOTIFY_CEASE_CONFIG_CHANGE);
2846 } else
2847 bgp_session_reset(peer);
2848 }
2849
2850 if (!CHECK_FLAG(peer->flags, PEER_FLAG_CAPABILITY_ENHE))
2851 peer_flag_set(peer, PEER_FLAG_CAPABILITY_ENHE);
2852
2853 if (peer_group_name) {
2854 group = peer_group_lookup(bgp, peer_group_name);
2855 if (!group) {
2856 vty_out(vty, "%% Configure the peer-group first\n");
2857 return CMD_WARNING_CONFIG_FAILED;
2858 }
2859
2860 ret = peer_group_bind(bgp, &su, peer, group, &as);
2861 }
2862
2863 return bgp_vty_return(vty, ret);
2864 }
2865
2866 DEFUN (neighbor_interface_config,
2867 neighbor_interface_config_cmd,
2868 "neighbor WORD interface [peer-group WORD]",
2869 NEIGHBOR_STR
2870 "Interface name or neighbor tag\n"
2871 "Enable BGP on interface\n"
2872 "Member of the peer-group\n"
2873 "Peer-group name\n")
2874 {
2875 int idx_word = 1;
2876 int idx_peer_group_word = 4;
2877
2878 if (argc > idx_peer_group_word)
2879 return peer_conf_interface_get(
2880 vty, argv[idx_word]->arg, AFI_IP, SAFI_UNICAST, 0,
2881 argv[idx_peer_group_word]->arg, NULL);
2882 else
2883 return peer_conf_interface_get(vty, argv[idx_word]->arg, AFI_IP,
2884 SAFI_UNICAST, 0, NULL, NULL);
2885 }
2886
2887 DEFUN (neighbor_interface_config_v6only,
2888 neighbor_interface_config_v6only_cmd,
2889 "neighbor WORD interface v6only [peer-group WORD]",
2890 NEIGHBOR_STR
2891 "Interface name or neighbor tag\n"
2892 "Enable BGP on interface\n"
2893 "Enable BGP with v6 link-local only\n"
2894 "Member of the peer-group\n"
2895 "Peer-group name\n")
2896 {
2897 int idx_word = 1;
2898 int idx_peer_group_word = 5;
2899
2900 if (argc > idx_peer_group_word)
2901 return peer_conf_interface_get(
2902 vty, argv[idx_word]->arg, AFI_IP, SAFI_UNICAST, 1,
2903 argv[idx_peer_group_word]->arg, NULL);
2904
2905 return peer_conf_interface_get(vty, argv[idx_word]->arg, AFI_IP,
2906 SAFI_UNICAST, 1, NULL, NULL);
2907 }
2908
2909
2910 DEFUN (neighbor_interface_config_remote_as,
2911 neighbor_interface_config_remote_as_cmd,
2912 "neighbor WORD interface remote-as <(1-4294967295)|internal|external>",
2913 NEIGHBOR_STR
2914 "Interface name or neighbor tag\n"
2915 "Enable BGP on interface\n"
2916 "Specify a BGP neighbor\n"
2917 AS_STR
2918 "Internal BGP peer\n"
2919 "External BGP peer\n")
2920 {
2921 int idx_word = 1;
2922 int idx_remote_as = 4;
2923 return peer_conf_interface_get(vty, argv[idx_word]->arg, AFI_IP,
2924 SAFI_UNICAST, 0, NULL,
2925 argv[idx_remote_as]->arg);
2926 }
2927
2928 DEFUN (neighbor_interface_v6only_config_remote_as,
2929 neighbor_interface_v6only_config_remote_as_cmd,
2930 "neighbor WORD interface v6only remote-as <(1-4294967295)|internal|external>",
2931 NEIGHBOR_STR
2932 "Interface name or neighbor tag\n"
2933 "Enable BGP with v6 link-local only\n"
2934 "Enable BGP on interface\n"
2935 "Specify a BGP neighbor\n"
2936 AS_STR
2937 "Internal BGP peer\n"
2938 "External BGP peer\n")
2939 {
2940 int idx_word = 1;
2941 int idx_remote_as = 5;
2942 return peer_conf_interface_get(vty, argv[idx_word]->arg, AFI_IP,
2943 SAFI_UNICAST, 1, NULL,
2944 argv[idx_remote_as]->arg);
2945 }
2946
2947 DEFUN (neighbor_peer_group,
2948 neighbor_peer_group_cmd,
2949 "neighbor WORD peer-group",
2950 NEIGHBOR_STR
2951 "Interface name or neighbor tag\n"
2952 "Configure peer-group\n")
2953 {
2954 VTY_DECLVAR_CONTEXT(bgp, bgp);
2955 int idx_word = 1;
2956 struct peer *peer;
2957 struct peer_group *group;
2958
2959 peer = peer_lookup_by_conf_if(bgp, argv[idx_word]->arg);
2960 if (peer) {
2961 vty_out(vty, "%% Name conflict with interface: \n");
2962 return CMD_WARNING_CONFIG_FAILED;
2963 }
2964
2965 group = peer_group_get(bgp, argv[idx_word]->arg);
2966 if (!group) {
2967 vty_out(vty, "%% BGP failed to find or create peer-group\n");
2968 return CMD_WARNING_CONFIG_FAILED;
2969 }
2970
2971 return CMD_SUCCESS;
2972 }
2973
2974 DEFUN (no_neighbor,
2975 no_neighbor_cmd,
2976 "no neighbor <WORD|<A.B.C.D|X:X::X:X> [remote-as <(1-4294967295)|internal|external>]>",
2977 NO_STR
2978 NEIGHBOR_STR
2979 NEIGHBOR_ADDR_STR2
2980 "Specify a BGP neighbor\n"
2981 AS_STR
2982 "Internal BGP peer\n"
2983 "External BGP peer\n")
2984 {
2985 VTY_DECLVAR_CONTEXT(bgp, bgp);
2986 int idx_peer = 2;
2987 int ret;
2988 union sockunion su;
2989 struct peer_group *group;
2990 struct peer *peer;
2991 struct peer *other;
2992
2993 ret = str2sockunion(argv[idx_peer]->arg, &su);
2994 if (ret < 0) {
2995 /* look up for neighbor by interface name config. */
2996 peer = peer_lookup_by_conf_if(bgp, argv[idx_peer]->arg);
2997 if (peer) {
2998 /* Request zebra to terminate IPv6 RAs on this
2999 * interface. */
3000 if (peer->ifp)
3001 bgp_zebra_terminate_radv(peer->bgp, peer);
3002 peer_delete(peer);
3003 return CMD_SUCCESS;
3004 }
3005
3006 group = peer_group_lookup(bgp, argv[idx_peer]->arg);
3007 if (group)
3008 peer_group_delete(group);
3009 else {
3010 vty_out(vty, "%% Create the peer-group first\n");
3011 return CMD_WARNING_CONFIG_FAILED;
3012 }
3013 } else {
3014 peer = peer_lookup(bgp, &su);
3015 if (peer) {
3016 if (peer_dynamic_neighbor(peer)) {
3017 vty_out(vty,
3018 "%% Operation not allowed on a dynamic neighbor\n");
3019 return CMD_WARNING_CONFIG_FAILED;
3020 }
3021
3022 other = peer->doppelganger;
3023 peer_delete(peer);
3024 if (other && other->status != Deleted)
3025 peer_delete(other);
3026 }
3027 }
3028
3029 return CMD_SUCCESS;
3030 }
3031
3032 DEFUN (no_neighbor_interface_config,
3033 no_neighbor_interface_config_cmd,
3034 "no neighbor WORD interface [v6only] [peer-group WORD] [remote-as <(1-4294967295)|internal|external>]",
3035 NO_STR
3036 NEIGHBOR_STR
3037 "Interface name\n"
3038 "Configure BGP on interface\n"
3039 "Enable BGP with v6 link-local only\n"
3040 "Member of the peer-group\n"
3041 "Peer-group name\n"
3042 "Specify a BGP neighbor\n"
3043 AS_STR
3044 "Internal BGP peer\n"
3045 "External BGP peer\n")
3046 {
3047 VTY_DECLVAR_CONTEXT(bgp, bgp);
3048 int idx_word = 2;
3049 struct peer *peer;
3050
3051 /* look up for neighbor by interface name config. */
3052 peer = peer_lookup_by_conf_if(bgp, argv[idx_word]->arg);
3053 if (peer) {
3054 /* Request zebra to terminate IPv6 RAs on this interface. */
3055 if (peer->ifp)
3056 bgp_zebra_terminate_radv(peer->bgp, peer);
3057 peer_delete(peer);
3058 } else {
3059 vty_out(vty, "%% Create the bgp interface first\n");
3060 return CMD_WARNING_CONFIG_FAILED;
3061 }
3062 return CMD_SUCCESS;
3063 }
3064
3065 DEFUN (no_neighbor_peer_group,
3066 no_neighbor_peer_group_cmd,
3067 "no neighbor WORD peer-group",
3068 NO_STR
3069 NEIGHBOR_STR
3070 "Neighbor tag\n"
3071 "Configure peer-group\n")
3072 {
3073 VTY_DECLVAR_CONTEXT(bgp, bgp);
3074 int idx_word = 2;
3075 struct peer_group *group;
3076
3077 group = peer_group_lookup(bgp, argv[idx_word]->arg);
3078 if (group)
3079 peer_group_delete(group);
3080 else {
3081 vty_out(vty, "%% Create the peer-group first\n");
3082 return CMD_WARNING_CONFIG_FAILED;
3083 }
3084 return CMD_SUCCESS;
3085 }
3086
3087 DEFUN (no_neighbor_interface_peer_group_remote_as,
3088 no_neighbor_interface_peer_group_remote_as_cmd,
3089 "no neighbor WORD remote-as <(1-4294967295)|internal|external>",
3090 NO_STR
3091 NEIGHBOR_STR
3092 "Interface name or neighbor tag\n"
3093 "Specify a BGP neighbor\n"
3094 AS_STR
3095 "Internal BGP peer\n"
3096 "External BGP peer\n")
3097 {
3098 VTY_DECLVAR_CONTEXT(bgp, bgp);
3099 int idx_word = 2;
3100 struct peer_group *group;
3101 struct peer *peer;
3102
3103 /* look up for neighbor by interface name config. */
3104 peer = peer_lookup_by_conf_if(bgp, argv[idx_word]->arg);
3105 if (peer) {
3106 peer_as_change(peer, 0, AS_SPECIFIED);
3107 return CMD_SUCCESS;
3108 }
3109
3110 group = peer_group_lookup(bgp, argv[idx_word]->arg);
3111 if (group)
3112 peer_group_remote_as_delete(group);
3113 else {
3114 vty_out(vty, "%% Create the peer-group or interface first\n");
3115 return CMD_WARNING_CONFIG_FAILED;
3116 }
3117 return CMD_SUCCESS;
3118 }
3119
3120 DEFUN (neighbor_local_as,
3121 neighbor_local_as_cmd,
3122 "neighbor <A.B.C.D|X:X::X:X|WORD> local-as (1-4294967295)",
3123 NEIGHBOR_STR
3124 NEIGHBOR_ADDR_STR2
3125 "Specify a local-as number\n"
3126 "AS number used as local AS\n")
3127 {
3128 int idx_peer = 1;
3129 int idx_number = 3;
3130 struct peer *peer;
3131 int ret;
3132 as_t as;
3133
3134 peer = peer_and_group_lookup_vty(vty, argv[idx_peer]->arg);
3135 if (!peer)
3136 return CMD_WARNING_CONFIG_FAILED;
3137
3138 as = strtoul(argv[idx_number]->arg, NULL, 10);
3139 ret = peer_local_as_set(peer, as, 0, 0);
3140 return bgp_vty_return(vty, ret);
3141 }
3142
3143 DEFUN (neighbor_local_as_no_prepend,
3144 neighbor_local_as_no_prepend_cmd,
3145 "neighbor <A.B.C.D|X:X::X:X|WORD> local-as (1-4294967295) no-prepend",
3146 NEIGHBOR_STR
3147 NEIGHBOR_ADDR_STR2
3148 "Specify a local-as number\n"
3149 "AS number used as local AS\n"
3150 "Do not prepend local-as to updates from ebgp peers\n")
3151 {
3152 int idx_peer = 1;
3153 int idx_number = 3;
3154 struct peer *peer;
3155 int ret;
3156 as_t as;
3157
3158 peer = peer_and_group_lookup_vty(vty, argv[idx_peer]->arg);
3159 if (!peer)
3160 return CMD_WARNING_CONFIG_FAILED;
3161
3162 as = strtoul(argv[idx_number]->arg, NULL, 10);
3163 ret = peer_local_as_set(peer, as, 1, 0);
3164 return bgp_vty_return(vty, ret);
3165 }
3166
3167 DEFUN (neighbor_local_as_no_prepend_replace_as,
3168 neighbor_local_as_no_prepend_replace_as_cmd,
3169 "neighbor <A.B.C.D|X:X::X:X|WORD> local-as (1-4294967295) no-prepend replace-as",
3170 NEIGHBOR_STR
3171 NEIGHBOR_ADDR_STR2
3172 "Specify a local-as number\n"
3173 "AS number used as local AS\n"
3174 "Do not prepend local-as to updates from ebgp peers\n"
3175 "Do not prepend local-as to updates from ibgp peers\n")
3176 {
3177 int idx_peer = 1;
3178 int idx_number = 3;
3179 struct peer *peer;
3180 int ret;
3181 as_t as;
3182
3183 peer = peer_and_group_lookup_vty(vty, argv[idx_peer]->arg);
3184 if (!peer)
3185 return CMD_WARNING_CONFIG_FAILED;
3186
3187 as = strtoul(argv[idx_number]->arg, NULL, 10);
3188 ret = peer_local_as_set(peer, as, 1, 1);
3189 return bgp_vty_return(vty, ret);
3190 }
3191
3192 DEFUN (no_neighbor_local_as,
3193 no_neighbor_local_as_cmd,
3194 "no neighbor <A.B.C.D|X:X::X:X|WORD> local-as [(1-4294967295) [no-prepend [replace-as]]]",
3195 NO_STR
3196 NEIGHBOR_STR
3197 NEIGHBOR_ADDR_STR2
3198 "Specify a local-as number\n"
3199 "AS number used as local AS\n"
3200 "Do not prepend local-as to updates from ebgp peers\n"
3201 "Do not prepend local-as to updates from ibgp peers\n")
3202 {
3203 int idx_peer = 2;
3204 struct peer *peer;
3205 int ret;
3206
3207 peer = peer_and_group_lookup_vty(vty, argv[idx_peer]->arg);
3208 if (!peer)
3209 return CMD_WARNING_CONFIG_FAILED;
3210
3211 ret = peer_local_as_unset(peer);
3212 return bgp_vty_return(vty, ret);
3213 }
3214
3215
3216 DEFUN (neighbor_solo,
3217 neighbor_solo_cmd,
3218 "neighbor <A.B.C.D|X:X::X:X|WORD> solo",
3219 NEIGHBOR_STR
3220 NEIGHBOR_ADDR_STR2
3221 "Solo peer - part of its own update group\n")
3222 {
3223 int idx_peer = 1;
3224 struct peer *peer;
3225 int ret;
3226
3227 peer = peer_and_group_lookup_vty(vty, argv[idx_peer]->arg);
3228 if (!peer)
3229 return CMD_WARNING_CONFIG_FAILED;
3230
3231 ret = update_group_adjust_soloness(peer, 1);
3232 return bgp_vty_return(vty, ret);
3233 }
3234
3235 DEFUN (no_neighbor_solo,
3236 no_neighbor_solo_cmd,
3237 "no neighbor <A.B.C.D|X:X::X:X|WORD> solo",
3238 NO_STR
3239 NEIGHBOR_STR
3240 NEIGHBOR_ADDR_STR2
3241 "Solo peer - part of its own update group\n")
3242 {
3243 int idx_peer = 2;
3244 struct peer *peer;
3245 int ret;
3246
3247 peer = peer_and_group_lookup_vty(vty, argv[idx_peer]->arg);
3248 if (!peer)
3249 return CMD_WARNING_CONFIG_FAILED;
3250
3251 ret = update_group_adjust_soloness(peer, 0);
3252 return bgp_vty_return(vty, ret);
3253 }
3254
3255 DEFUN (neighbor_password,
3256 neighbor_password_cmd,
3257 "neighbor <A.B.C.D|X:X::X:X|WORD> password LINE",
3258 NEIGHBOR_STR
3259 NEIGHBOR_ADDR_STR2
3260 "Set a password\n"
3261 "The password\n")
3262 {
3263 int idx_peer = 1;
3264 int idx_line = 3;
3265 struct peer *peer;
3266 int ret;
3267
3268 peer = peer_and_group_lookup_vty(vty, argv[idx_peer]->arg);
3269 if (!peer)
3270 return CMD_WARNING_CONFIG_FAILED;
3271
3272 ret = peer_password_set(peer, argv[idx_line]->arg);
3273 return bgp_vty_return(vty, ret);
3274 }
3275
3276 DEFUN (no_neighbor_password,
3277 no_neighbor_password_cmd,
3278 "no neighbor <A.B.C.D|X:X::X:X|WORD> password [LINE]",
3279 NO_STR
3280 NEIGHBOR_STR
3281 NEIGHBOR_ADDR_STR2
3282 "Set a password\n"
3283 "The password\n")
3284 {
3285 int idx_peer = 2;
3286 struct peer *peer;
3287 int ret;
3288
3289 peer = peer_and_group_lookup_vty(vty, argv[idx_peer]->arg);
3290 if (!peer)
3291 return CMD_WARNING_CONFIG_FAILED;
3292
3293 ret = peer_password_unset(peer);
3294 return bgp_vty_return(vty, ret);
3295 }
3296
3297 DEFUN (neighbor_activate,
3298 neighbor_activate_cmd,
3299 "neighbor <A.B.C.D|X:X::X:X|WORD> activate",
3300 NEIGHBOR_STR
3301 NEIGHBOR_ADDR_STR2
3302 "Enable the Address Family for this Neighbor\n")
3303 {
3304 int idx_peer = 1;
3305 int ret;
3306 struct peer *peer;
3307
3308 peer = peer_and_group_lookup_vty(vty, argv[idx_peer]->arg);
3309 if (!peer)
3310 return CMD_WARNING_CONFIG_FAILED;
3311
3312 ret = peer_activate(peer, bgp_node_afi(vty), bgp_node_safi(vty));
3313 return bgp_vty_return(vty, ret);
3314 }
3315
3316 ALIAS_HIDDEN(neighbor_activate, neighbor_activate_hidden_cmd,
3317 "neighbor <A.B.C.D|X:X::X:X|WORD> activate",
3318 NEIGHBOR_STR NEIGHBOR_ADDR_STR2
3319 "Enable the Address Family for this Neighbor\n")
3320
3321 DEFUN (no_neighbor_activate,
3322 no_neighbor_activate_cmd,
3323 "no neighbor <A.B.C.D|X:X::X:X|WORD> activate",
3324 NO_STR
3325 NEIGHBOR_STR
3326 NEIGHBOR_ADDR_STR2
3327 "Enable the Address Family for this Neighbor\n")
3328 {
3329 int idx_peer = 2;
3330 int ret;
3331 struct peer *peer;
3332
3333 /* Lookup peer. */
3334 peer = peer_and_group_lookup_vty(vty, argv[idx_peer]->arg);
3335 if (!peer)
3336 return CMD_WARNING_CONFIG_FAILED;
3337
3338 ret = peer_deactivate(peer, bgp_node_afi(vty), bgp_node_safi(vty));
3339 return bgp_vty_return(vty, ret);
3340 }
3341
3342 ALIAS_HIDDEN(no_neighbor_activate, no_neighbor_activate_hidden_cmd,
3343 "no neighbor <A.B.C.D|X:X::X:X|WORD> activate",
3344 NO_STR NEIGHBOR_STR NEIGHBOR_ADDR_STR2
3345 "Enable the Address Family for this Neighbor\n")
3346
3347 DEFUN (neighbor_set_peer_group,
3348 neighbor_set_peer_group_cmd,
3349 "neighbor <A.B.C.D|X:X::X:X|WORD> peer-group WORD",
3350 NEIGHBOR_STR
3351 NEIGHBOR_ADDR_STR2
3352 "Member of the peer-group\n"
3353 "Peer-group name\n")
3354 {
3355 VTY_DECLVAR_CONTEXT(bgp, bgp);
3356 int idx_peer = 1;
3357 int idx_word = 3;
3358 int ret;
3359 as_t as;
3360 union sockunion su;
3361 struct peer *peer;
3362 struct peer_group *group;
3363
3364 peer = NULL;
3365
3366 ret = str2sockunion(argv[idx_peer]->arg, &su);
3367 if (ret < 0) {
3368 peer = peer_lookup_by_conf_if(bgp, argv[idx_peer]->arg);
3369 if (!peer) {
3370 vty_out(vty, "%% Malformed address or name: %s\n",
3371 argv[idx_peer]->arg);
3372 return CMD_WARNING_CONFIG_FAILED;
3373 }
3374 } else {
3375 if (peer_address_self_check(bgp, &su)) {
3376 vty_out(vty,
3377 "%% Can not configure the local system as neighbor\n");
3378 return CMD_WARNING_CONFIG_FAILED;
3379 }
3380
3381 /* Disallow for dynamic neighbor. */
3382 peer = peer_lookup(bgp, &su);
3383 if (peer && peer_dynamic_neighbor(peer)) {
3384 vty_out(vty,
3385 "%% Operation not allowed on a dynamic neighbor\n");
3386 return CMD_WARNING_CONFIG_FAILED;
3387 }
3388 }
3389
3390 group = peer_group_lookup(bgp, argv[idx_word]->arg);
3391 if (!group) {
3392 vty_out(vty, "%% Configure the peer-group first\n");
3393 return CMD_WARNING_CONFIG_FAILED;
3394 }
3395
3396 ret = peer_group_bind(bgp, &su, peer, group, &as);
3397
3398 if (ret == BGP_ERR_PEER_GROUP_PEER_TYPE_DIFFERENT) {
3399 vty_out(vty,
3400 "%% Peer with AS %u cannot be in this peer-group, members must be all internal or all external\n",
3401 as);
3402 return CMD_WARNING_CONFIG_FAILED;
3403 }
3404
3405 return bgp_vty_return(vty, ret);
3406 }
3407
3408 ALIAS_HIDDEN(neighbor_set_peer_group, neighbor_set_peer_group_hidden_cmd,
3409 "neighbor <A.B.C.D|X:X::X:X|WORD> peer-group WORD",
3410 NEIGHBOR_STR NEIGHBOR_ADDR_STR2
3411 "Member of the peer-group\n"
3412 "Peer-group name\n")
3413
3414 DEFUN (no_neighbor_set_peer_group,
3415 no_neighbor_set_peer_group_cmd,
3416 "no neighbor <A.B.C.D|X:X::X:X|WORD> peer-group WORD",
3417 NO_STR
3418 NEIGHBOR_STR
3419 NEIGHBOR_ADDR_STR2
3420 "Member of the peer-group\n"
3421 "Peer-group name\n")
3422 {
3423 VTY_DECLVAR_CONTEXT(bgp, bgp);
3424 int idx_peer = 2;
3425 int idx_word = 4;
3426 int ret;
3427 struct peer *peer;
3428 struct peer_group *group;
3429
3430 peer = peer_lookup_vty(vty, argv[idx_peer]->arg);
3431 if (!peer)
3432 return CMD_WARNING_CONFIG_FAILED;
3433
3434 group = peer_group_lookup(bgp, argv[idx_word]->arg);
3435 if (!group) {
3436 vty_out(vty, "%% Configure the peer-group first\n");
3437 return CMD_WARNING_CONFIG_FAILED;
3438 }
3439
3440 ret = peer_delete(peer);
3441
3442 return bgp_vty_return(vty, ret);
3443 }
3444
3445 ALIAS_HIDDEN(no_neighbor_set_peer_group, no_neighbor_set_peer_group_hidden_cmd,
3446 "no neighbor <A.B.C.D|X:X::X:X|WORD> peer-group WORD",
3447 NO_STR NEIGHBOR_STR NEIGHBOR_ADDR_STR2
3448 "Member of the peer-group\n"
3449 "Peer-group name\n")
3450
3451 static int peer_flag_modify_vty(struct vty *vty, const char *ip_str,
3452 uint16_t flag, int set)
3453 {
3454 int ret;
3455 struct peer *peer;
3456
3457 peer = peer_and_group_lookup_vty(vty, ip_str);
3458 if (!peer)
3459 return CMD_WARNING_CONFIG_FAILED;
3460
3461 /*
3462 * If 'neighbor <interface>', then this is for directly connected peers,
3463 * we should not accept disable-connected-check.
3464 */
3465 if (peer->conf_if && (flag == PEER_FLAG_DISABLE_CONNECTED_CHECK)) {
3466 vty_out(vty,
3467 "%s is directly connected peer, cannot accept disable-"
3468 "connected-check\n",
3469 ip_str);
3470 return CMD_WARNING_CONFIG_FAILED;
3471 }
3472
3473 if (!set && flag == PEER_FLAG_SHUTDOWN)
3474 peer_tx_shutdown_message_unset(peer);
3475
3476 if (set)
3477 ret = peer_flag_set(peer, flag);
3478 else
3479 ret = peer_flag_unset(peer, flag);
3480
3481 return bgp_vty_return(vty, ret);
3482 }
3483
3484 static int peer_flag_set_vty(struct vty *vty, const char *ip_str, uint16_t flag)
3485 {
3486 return peer_flag_modify_vty(vty, ip_str, flag, 1);
3487 }
3488
3489 static int peer_flag_unset_vty(struct vty *vty, const char *ip_str,
3490 uint16_t flag)
3491 {
3492 return peer_flag_modify_vty(vty, ip_str, flag, 0);
3493 }
3494
3495 /* neighbor passive. */
3496 DEFUN (neighbor_passive,
3497 neighbor_passive_cmd,
3498 "neighbor <A.B.C.D|X:X::X:X|WORD> passive",
3499 NEIGHBOR_STR
3500 NEIGHBOR_ADDR_STR2
3501 "Don't send open messages to this neighbor\n")
3502 {
3503 int idx_peer = 1;
3504 return peer_flag_set_vty(vty, argv[idx_peer]->arg, PEER_FLAG_PASSIVE);
3505 }
3506
3507 DEFUN (no_neighbor_passive,
3508 no_neighbor_passive_cmd,
3509 "no neighbor <A.B.C.D|X:X::X:X|WORD> passive",
3510 NO_STR
3511 NEIGHBOR_STR
3512 NEIGHBOR_ADDR_STR2
3513 "Don't send open messages to this neighbor\n")
3514 {
3515 int idx_peer = 2;
3516 return peer_flag_unset_vty(vty, argv[idx_peer]->arg, PEER_FLAG_PASSIVE);
3517 }
3518
3519 /* neighbor shutdown. */
3520 DEFUN (neighbor_shutdown_msg,
3521 neighbor_shutdown_msg_cmd,
3522 "neighbor <A.B.C.D|X:X::X:X|WORD> shutdown message MSG...",
3523 NEIGHBOR_STR
3524 NEIGHBOR_ADDR_STR2
3525 "Administratively shut down this neighbor\n"
3526 "Add a shutdown message (draft-ietf-idr-shutdown-06)\n"
3527 "Shutdown message\n")
3528 {
3529 int idx_peer = 1;
3530
3531 if (argc >= 5) {
3532 struct peer *peer =
3533 peer_and_group_lookup_vty(vty, argv[idx_peer]->arg);
3534 char *message;
3535
3536 if (!peer)
3537 return CMD_WARNING_CONFIG_FAILED;
3538 message = argv_concat(argv, argc, 4);
3539 peer_tx_shutdown_message_set(peer, message);
3540 XFREE(MTYPE_TMP, message);
3541 }
3542
3543 return peer_flag_set_vty(vty, argv[idx_peer]->arg, PEER_FLAG_SHUTDOWN);
3544 }
3545
3546 ALIAS(neighbor_shutdown_msg, neighbor_shutdown_cmd,
3547 "neighbor <A.B.C.D|X:X::X:X|WORD> shutdown",
3548 NEIGHBOR_STR NEIGHBOR_ADDR_STR2
3549 "Administratively shut down this neighbor\n")
3550
3551 DEFUN (no_neighbor_shutdown_msg,
3552 no_neighbor_shutdown_msg_cmd,
3553 "no neighbor <A.B.C.D|X:X::X:X|WORD> shutdown message MSG...",
3554 NO_STR
3555 NEIGHBOR_STR
3556 NEIGHBOR_ADDR_STR2
3557 "Administratively shut down this neighbor\n"
3558 "Remove a shutdown message (draft-ietf-idr-shutdown-06)\n"
3559 "Shutdown message\n")
3560 {
3561 int idx_peer = 2;
3562
3563 return peer_flag_unset_vty(vty, argv[idx_peer]->arg,
3564 PEER_FLAG_SHUTDOWN);
3565 }
3566
3567 ALIAS(no_neighbor_shutdown_msg, no_neighbor_shutdown_cmd,
3568 "no neighbor <A.B.C.D|X:X::X:X|WORD> shutdown",
3569 NO_STR NEIGHBOR_STR NEIGHBOR_ADDR_STR2
3570 "Administratively shut down this neighbor\n")
3571
3572 /* neighbor capability dynamic. */
3573 DEFUN (neighbor_capability_dynamic,
3574 neighbor_capability_dynamic_cmd,
3575 "neighbor <A.B.C.D|X:X::X:X|WORD> capability dynamic",
3576 NEIGHBOR_STR
3577 NEIGHBOR_ADDR_STR2
3578 "Advertise capability to the peer\n"
3579 "Advertise dynamic capability to this neighbor\n")
3580 {
3581 int idx_peer = 1;
3582 return peer_flag_set_vty(vty, argv[idx_peer]->arg,
3583 PEER_FLAG_DYNAMIC_CAPABILITY);
3584 }
3585
3586 DEFUN (no_neighbor_capability_dynamic,
3587 no_neighbor_capability_dynamic_cmd,
3588 "no neighbor <A.B.C.D|X:X::X:X|WORD> capability dynamic",
3589 NO_STR
3590 NEIGHBOR_STR
3591 NEIGHBOR_ADDR_STR2
3592 "Advertise capability to the peer\n"
3593 "Advertise dynamic capability to this neighbor\n")
3594 {
3595 int idx_peer = 2;
3596 return peer_flag_unset_vty(vty, argv[idx_peer]->arg,
3597 PEER_FLAG_DYNAMIC_CAPABILITY);
3598 }
3599
3600 /* neighbor dont-capability-negotiate */
3601 DEFUN (neighbor_dont_capability_negotiate,
3602 neighbor_dont_capability_negotiate_cmd,
3603 "neighbor <A.B.C.D|X:X::X:X|WORD> dont-capability-negotiate",
3604 NEIGHBOR_STR
3605 NEIGHBOR_ADDR_STR2
3606 "Do not perform capability negotiation\n")
3607 {
3608 int idx_peer = 1;
3609 return peer_flag_set_vty(vty, argv[idx_peer]->arg,
3610 PEER_FLAG_DONT_CAPABILITY);
3611 }
3612
3613 DEFUN (no_neighbor_dont_capability_negotiate,
3614 no_neighbor_dont_capability_negotiate_cmd,
3615 "no neighbor <A.B.C.D|X:X::X:X|WORD> dont-capability-negotiate",
3616 NO_STR
3617 NEIGHBOR_STR
3618 NEIGHBOR_ADDR_STR2
3619 "Do not perform capability negotiation\n")
3620 {
3621 int idx_peer = 2;
3622 return peer_flag_unset_vty(vty, argv[idx_peer]->arg,
3623 PEER_FLAG_DONT_CAPABILITY);
3624 }
3625
3626 /* neighbor capability extended next hop encoding */
3627 DEFUN (neighbor_capability_enhe,
3628 neighbor_capability_enhe_cmd,
3629 "neighbor <A.B.C.D|X:X::X:X|WORD> capability extended-nexthop",
3630 NEIGHBOR_STR
3631 NEIGHBOR_ADDR_STR2
3632 "Advertise capability to the peer\n"
3633 "Advertise extended next-hop capability to the peer\n")
3634 {
3635 int idx_peer = 1;
3636 return peer_flag_set_vty(vty, argv[idx_peer]->arg,
3637 PEER_FLAG_CAPABILITY_ENHE);
3638 }
3639
3640 DEFUN (no_neighbor_capability_enhe,
3641 no_neighbor_capability_enhe_cmd,
3642 "no neighbor <A.B.C.D|X:X::X:X|WORD> capability extended-nexthop",
3643 NO_STR
3644 NEIGHBOR_STR
3645 NEIGHBOR_ADDR_STR2
3646 "Advertise capability to the peer\n"
3647 "Advertise extended next-hop capability to the peer\n")
3648 {
3649 int idx_peer = 2;
3650 return peer_flag_unset_vty(vty, argv[idx_peer]->arg,
3651 PEER_FLAG_CAPABILITY_ENHE);
3652 }
3653
3654 static int peer_af_flag_modify_vty(struct vty *vty, const char *peer_str,
3655 afi_t afi, safi_t safi, uint32_t flag,
3656 int set)
3657 {
3658 int ret;
3659 struct peer *peer;
3660
3661 peer = peer_and_group_lookup_vty(vty, peer_str);
3662 if (!peer)
3663 return CMD_WARNING_CONFIG_FAILED;
3664
3665 if (set)
3666 ret = peer_af_flag_set(peer, afi, safi, flag);
3667 else
3668 ret = peer_af_flag_unset(peer, afi, safi, flag);
3669
3670 return bgp_vty_return(vty, ret);
3671 }
3672
3673 static int peer_af_flag_set_vty(struct vty *vty, const char *peer_str,
3674 afi_t afi, safi_t safi, uint32_t flag)
3675 {
3676 return peer_af_flag_modify_vty(vty, peer_str, afi, safi, flag, 1);
3677 }
3678
3679 static int peer_af_flag_unset_vty(struct vty *vty, const char *peer_str,
3680 afi_t afi, safi_t safi, uint32_t flag)
3681 {
3682 return peer_af_flag_modify_vty(vty, peer_str, afi, safi, flag, 0);
3683 }
3684
3685 /* neighbor capability orf prefix-list. */
3686 DEFUN (neighbor_capability_orf_prefix,
3687 neighbor_capability_orf_prefix_cmd,
3688 "neighbor <A.B.C.D|X:X::X:X|WORD> capability orf prefix-list <both|send|receive>",
3689 NEIGHBOR_STR
3690 NEIGHBOR_ADDR_STR2
3691 "Advertise capability to the peer\n"
3692 "Advertise ORF capability to the peer\n"
3693 "Advertise prefixlist ORF capability to this neighbor\n"
3694 "Capability to SEND and RECEIVE the ORF to/from this neighbor\n"
3695 "Capability to RECEIVE the ORF from this neighbor\n"
3696 "Capability to SEND the ORF to this neighbor\n")
3697 {
3698 int idx_peer = 1;
3699 int idx_send_recv = 5;
3700 uint16_t flag = 0;
3701
3702 if (strmatch(argv[idx_send_recv]->text, "send"))
3703 flag = PEER_FLAG_ORF_PREFIX_SM;
3704 else if (strmatch(argv[idx_send_recv]->text, "receive"))
3705 flag = PEER_FLAG_ORF_PREFIX_RM;
3706 else if (strmatch(argv[idx_send_recv]->text, "both"))
3707 flag = PEER_FLAG_ORF_PREFIX_SM | PEER_FLAG_ORF_PREFIX_RM;
3708 else {
3709 vty_out(vty, "%% BGP invalid orf prefix-list option\n");
3710 return CMD_WARNING_CONFIG_FAILED;
3711 }
3712
3713 return peer_af_flag_set_vty(vty, argv[idx_peer]->arg, bgp_node_afi(vty),
3714 bgp_node_safi(vty), flag);
3715 }
3716
3717 ALIAS_HIDDEN(
3718 neighbor_capability_orf_prefix,
3719 neighbor_capability_orf_prefix_hidden_cmd,
3720 "neighbor <A.B.C.D|X:X::X:X|WORD> capability orf prefix-list <both|send|receive>",
3721 NEIGHBOR_STR NEIGHBOR_ADDR_STR2
3722 "Advertise capability to the peer\n"
3723 "Advertise ORF capability to the peer\n"
3724 "Advertise prefixlist ORF capability to this neighbor\n"
3725 "Capability to SEND and RECEIVE the ORF to/from this neighbor\n"
3726 "Capability to RECEIVE the ORF from this neighbor\n"
3727 "Capability to SEND the ORF to this neighbor\n")
3728
3729 DEFUN (no_neighbor_capability_orf_prefix,
3730 no_neighbor_capability_orf_prefix_cmd,
3731 "no neighbor <A.B.C.D|X:X::X:X|WORD> capability orf prefix-list <both|send|receive>",
3732 NO_STR
3733 NEIGHBOR_STR
3734 NEIGHBOR_ADDR_STR2
3735 "Advertise capability to the peer\n"
3736 "Advertise ORF capability to the peer\n"
3737 "Advertise prefixlist ORF capability to this neighbor\n"
3738 "Capability to SEND and RECEIVE the ORF to/from this neighbor\n"
3739 "Capability to RECEIVE the ORF from this neighbor\n"
3740 "Capability to SEND the ORF to this neighbor\n")
3741 {
3742 int idx_peer = 2;
3743 int idx_send_recv = 6;
3744 uint16_t flag = 0;
3745
3746 if (strmatch(argv[idx_send_recv]->text, "send"))
3747 flag = PEER_FLAG_ORF_PREFIX_SM;
3748 else if (strmatch(argv[idx_send_recv]->text, "receive"))
3749 flag = PEER_FLAG_ORF_PREFIX_RM;
3750 else if (strmatch(argv[idx_send_recv]->text, "both"))
3751 flag = PEER_FLAG_ORF_PREFIX_SM | PEER_FLAG_ORF_PREFIX_RM;
3752 else {
3753 vty_out(vty, "%% BGP invalid orf prefix-list option\n");
3754 return CMD_WARNING_CONFIG_FAILED;
3755 }
3756
3757 return peer_af_flag_unset_vty(vty, argv[idx_peer]->arg,
3758 bgp_node_afi(vty), bgp_node_safi(vty),
3759 flag);
3760 }
3761
3762 ALIAS_HIDDEN(
3763 no_neighbor_capability_orf_prefix,
3764 no_neighbor_capability_orf_prefix_hidden_cmd,
3765 "no neighbor <A.B.C.D|X:X::X:X|WORD> capability orf prefix-list <both|send|receive>",
3766 NO_STR NEIGHBOR_STR NEIGHBOR_ADDR_STR2
3767 "Advertise capability to the peer\n"
3768 "Advertise ORF capability to the peer\n"
3769 "Advertise prefixlist ORF capability to this neighbor\n"
3770 "Capability to SEND and RECEIVE the ORF to/from this neighbor\n"
3771 "Capability to RECEIVE the ORF from this neighbor\n"
3772 "Capability to SEND the ORF to this neighbor\n")
3773
3774 /* neighbor next-hop-self. */
3775 DEFUN (neighbor_nexthop_self,
3776 neighbor_nexthop_self_cmd,
3777 "neighbor <A.B.C.D|X:X::X:X|WORD> next-hop-self",
3778 NEIGHBOR_STR
3779 NEIGHBOR_ADDR_STR2
3780 "Disable the next hop calculation for this neighbor\n")
3781 {
3782 int idx_peer = 1;
3783 return peer_af_flag_set_vty(vty, argv[idx_peer]->arg, bgp_node_afi(vty),
3784 bgp_node_safi(vty), PEER_FLAG_NEXTHOP_SELF);
3785 }
3786
3787 ALIAS_HIDDEN(neighbor_nexthop_self, neighbor_nexthop_self_hidden_cmd,
3788 "neighbor <A.B.C.D|X:X::X:X|WORD> next-hop-self",
3789 NEIGHBOR_STR NEIGHBOR_ADDR_STR2
3790 "Disable the next hop calculation for this neighbor\n")
3791
3792 /* neighbor next-hop-self. */
3793 DEFUN (neighbor_nexthop_self_force,
3794 neighbor_nexthop_self_force_cmd,
3795 "neighbor <A.B.C.D|X:X::X:X|WORD> next-hop-self force",
3796 NEIGHBOR_STR
3797 NEIGHBOR_ADDR_STR2
3798 "Disable the next hop calculation for this neighbor\n"
3799 "Set the next hop to self for reflected routes\n")
3800 {
3801 int idx_peer = 1;
3802 return peer_af_flag_set_vty(vty, argv[idx_peer]->arg, bgp_node_afi(vty),
3803 bgp_node_safi(vty),
3804 PEER_FLAG_FORCE_NEXTHOP_SELF);
3805 }
3806
3807 ALIAS_HIDDEN(neighbor_nexthop_self_force,
3808 neighbor_nexthop_self_force_hidden_cmd,
3809 "neighbor <A.B.C.D|X:X::X:X|WORD> next-hop-self force",
3810 NEIGHBOR_STR NEIGHBOR_ADDR_STR2
3811 "Disable the next hop calculation for this neighbor\n"
3812 "Set the next hop to self for reflected routes\n")
3813
3814 DEFUN (no_neighbor_nexthop_self,
3815 no_neighbor_nexthop_self_cmd,
3816 "no neighbor <A.B.C.D|X:X::X:X|WORD> next-hop-self",
3817 NO_STR
3818 NEIGHBOR_STR
3819 NEIGHBOR_ADDR_STR2
3820 "Disable the next hop calculation for this neighbor\n")
3821 {
3822 int idx_peer = 2;
3823 return peer_af_flag_unset_vty(vty, argv[idx_peer]->arg,
3824 bgp_node_afi(vty), bgp_node_safi(vty),
3825 PEER_FLAG_NEXTHOP_SELF);
3826 }
3827
3828 ALIAS_HIDDEN(no_neighbor_nexthop_self, no_neighbor_nexthop_self_hidden_cmd,
3829 "no neighbor <A.B.C.D|X:X::X:X|WORD> next-hop-self",
3830 NO_STR NEIGHBOR_STR NEIGHBOR_ADDR_STR2
3831 "Disable the next hop calculation for this neighbor\n")
3832
3833 DEFUN (no_neighbor_nexthop_self_force,
3834 no_neighbor_nexthop_self_force_cmd,
3835 "no neighbor <A.B.C.D|X:X::X:X|WORD> next-hop-self force",
3836 NO_STR
3837 NEIGHBOR_STR
3838 NEIGHBOR_ADDR_STR2
3839 "Disable the next hop calculation for this neighbor\n"
3840 "Set the next hop to self for reflected routes\n")
3841 {
3842 int idx_peer = 2;
3843 return peer_af_flag_unset_vty(vty, argv[idx_peer]->arg,
3844 bgp_node_afi(vty), bgp_node_safi(vty),
3845 PEER_FLAG_FORCE_NEXTHOP_SELF);
3846 }
3847
3848 ALIAS_HIDDEN(no_neighbor_nexthop_self_force,
3849 no_neighbor_nexthop_self_force_hidden_cmd,
3850 "no neighbor <A.B.C.D|X:X::X:X|WORD> next-hop-self force",
3851 NO_STR NEIGHBOR_STR NEIGHBOR_ADDR_STR2
3852 "Disable the next hop calculation for this neighbor\n"
3853 "Set the next hop to self for reflected routes\n")
3854
3855 /* neighbor as-override */
3856 DEFUN (neighbor_as_override,
3857 neighbor_as_override_cmd,
3858 "neighbor <A.B.C.D|X:X::X:X|WORD> as-override",
3859 NEIGHBOR_STR
3860 NEIGHBOR_ADDR_STR2
3861 "Override ASNs in outbound updates if aspath equals remote-as\n")
3862 {
3863 int idx_peer = 1;
3864 return peer_af_flag_set_vty(vty, argv[idx_peer]->arg, bgp_node_afi(vty),
3865 bgp_node_safi(vty), PEER_FLAG_AS_OVERRIDE);
3866 }
3867
3868 ALIAS_HIDDEN(neighbor_as_override, neighbor_as_override_hidden_cmd,
3869 "neighbor <A.B.C.D|X:X::X:X|WORD> as-override",
3870 NEIGHBOR_STR NEIGHBOR_ADDR_STR2
3871 "Override ASNs in outbound updates if aspath equals remote-as\n")
3872
3873 DEFUN (no_neighbor_as_override,
3874 no_neighbor_as_override_cmd,
3875 "no neighbor <A.B.C.D|X:X::X:X|WORD> as-override",
3876 NO_STR
3877 NEIGHBOR_STR
3878 NEIGHBOR_ADDR_STR2
3879 "Override ASNs in outbound updates if aspath equals remote-as\n")
3880 {
3881 int idx_peer = 2;
3882 return peer_af_flag_unset_vty(vty, argv[idx_peer]->arg,
3883 bgp_node_afi(vty), bgp_node_safi(vty),
3884 PEER_FLAG_AS_OVERRIDE);
3885 }
3886
3887 ALIAS_HIDDEN(no_neighbor_as_override, no_neighbor_as_override_hidden_cmd,
3888 "no neighbor <A.B.C.D|X:X::X:X|WORD> as-override",
3889 NO_STR NEIGHBOR_STR NEIGHBOR_ADDR_STR2
3890 "Override ASNs in outbound updates if aspath equals remote-as\n")
3891
3892 /* neighbor remove-private-AS. */
3893 DEFUN (neighbor_remove_private_as,
3894 neighbor_remove_private_as_cmd,
3895 "neighbor <A.B.C.D|X:X::X:X|WORD> remove-private-AS",
3896 NEIGHBOR_STR
3897 NEIGHBOR_ADDR_STR2
3898 "Remove private ASNs in outbound updates\n")
3899 {
3900 int idx_peer = 1;
3901 return peer_af_flag_set_vty(vty, argv[idx_peer]->arg, bgp_node_afi(vty),
3902 bgp_node_safi(vty),
3903 PEER_FLAG_REMOVE_PRIVATE_AS);
3904 }
3905
3906 ALIAS_HIDDEN(neighbor_remove_private_as, neighbor_remove_private_as_hidden_cmd,
3907 "neighbor <A.B.C.D|X:X::X:X|WORD> remove-private-AS",
3908 NEIGHBOR_STR NEIGHBOR_ADDR_STR2
3909 "Remove private ASNs in outbound updates\n")
3910
3911 DEFUN (neighbor_remove_private_as_all,
3912 neighbor_remove_private_as_all_cmd,
3913 "neighbor <A.B.C.D|X:X::X:X|WORD> remove-private-AS all",
3914 NEIGHBOR_STR
3915 NEIGHBOR_ADDR_STR2
3916 "Remove private ASNs in outbound updates\n"
3917 "Apply to all AS numbers\n")
3918 {
3919 int idx_peer = 1;
3920 return peer_af_flag_set_vty(vty, argv[idx_peer]->arg, bgp_node_afi(vty),
3921 bgp_node_safi(vty),
3922 PEER_FLAG_REMOVE_PRIVATE_AS_ALL);
3923 }
3924
3925 ALIAS_HIDDEN(neighbor_remove_private_as_all,
3926 neighbor_remove_private_as_all_hidden_cmd,
3927 "neighbor <A.B.C.D|X:X::X:X|WORD> remove-private-AS all",
3928 NEIGHBOR_STR NEIGHBOR_ADDR_STR2
3929 "Remove private ASNs in outbound updates\n"
3930 "Apply to all AS numbers")
3931
3932 DEFUN (neighbor_remove_private_as_replace_as,
3933 neighbor_remove_private_as_replace_as_cmd,
3934 "neighbor <A.B.C.D|X:X::X:X|WORD> remove-private-AS replace-AS",
3935 NEIGHBOR_STR
3936 NEIGHBOR_ADDR_STR2
3937 "Remove private ASNs in outbound updates\n"
3938 "Replace private ASNs with our ASN in outbound updates\n")
3939 {
3940 int idx_peer = 1;
3941 return peer_af_flag_set_vty(vty, argv[idx_peer]->arg, bgp_node_afi(vty),
3942 bgp_node_safi(vty),
3943 PEER_FLAG_REMOVE_PRIVATE_AS_REPLACE);
3944 }
3945
3946 ALIAS_HIDDEN(neighbor_remove_private_as_replace_as,
3947 neighbor_remove_private_as_replace_as_hidden_cmd,
3948 "neighbor <A.B.C.D|X:X::X:X|WORD> remove-private-AS replace-AS",
3949 NEIGHBOR_STR NEIGHBOR_ADDR_STR2
3950 "Remove private ASNs in outbound updates\n"
3951 "Replace private ASNs with our ASN in outbound updates\n")
3952
3953 DEFUN (neighbor_remove_private_as_all_replace_as,
3954 neighbor_remove_private_as_all_replace_as_cmd,
3955 "neighbor <A.B.C.D|X:X::X:X|WORD> remove-private-AS all replace-AS",
3956 NEIGHBOR_STR
3957 NEIGHBOR_ADDR_STR2
3958 "Remove private ASNs in outbound updates\n"
3959 "Apply to all AS numbers\n"
3960 "Replace private ASNs with our ASN in outbound updates\n")
3961 {
3962 int idx_peer = 1;
3963 return peer_af_flag_set_vty(vty, argv[idx_peer]->arg, bgp_node_afi(vty),
3964 bgp_node_safi(vty),
3965 PEER_FLAG_REMOVE_PRIVATE_AS_ALL_REPLACE);
3966 }
3967
3968 ALIAS_HIDDEN(
3969 neighbor_remove_private_as_all_replace_as,
3970 neighbor_remove_private_as_all_replace_as_hidden_cmd,
3971 "neighbor <A.B.C.D|X:X::X:X|WORD> remove-private-AS all replace-AS",
3972 NEIGHBOR_STR 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 DEFUN (no_neighbor_remove_private_as,
3978 no_neighbor_remove_private_as_cmd,
3979 "no neighbor <A.B.C.D|X:X::X:X|WORD> remove-private-AS",
3980 NO_STR
3981 NEIGHBOR_STR
3982 NEIGHBOR_ADDR_STR2
3983 "Remove private ASNs in outbound updates\n")
3984 {
3985 int idx_peer = 2;
3986 return peer_af_flag_unset_vty(vty, argv[idx_peer]->arg,
3987 bgp_node_afi(vty), bgp_node_safi(vty),
3988 PEER_FLAG_REMOVE_PRIVATE_AS);
3989 }
3990
3991 ALIAS_HIDDEN(no_neighbor_remove_private_as,
3992 no_neighbor_remove_private_as_hidden_cmd,
3993 "no neighbor <A.B.C.D|X:X::X:X|WORD> remove-private-AS",
3994 NO_STR NEIGHBOR_STR NEIGHBOR_ADDR_STR2
3995 "Remove private ASNs in outbound updates\n")
3996
3997 DEFUN (no_neighbor_remove_private_as_all,
3998 no_neighbor_remove_private_as_all_cmd,
3999 "no neighbor <A.B.C.D|X:X::X:X|WORD> remove-private-AS all",
4000 NO_STR
4001 NEIGHBOR_STR
4002 NEIGHBOR_ADDR_STR2
4003 "Remove private ASNs in outbound updates\n"
4004 "Apply to all AS numbers\n")
4005 {
4006 int idx_peer = 2;
4007 return peer_af_flag_unset_vty(vty, argv[idx_peer]->arg,
4008 bgp_node_afi(vty), bgp_node_safi(vty),
4009 PEER_FLAG_REMOVE_PRIVATE_AS_ALL);
4010 }
4011
4012 ALIAS_HIDDEN(no_neighbor_remove_private_as_all,
4013 no_neighbor_remove_private_as_all_hidden_cmd,
4014 "no neighbor <A.B.C.D|X:X::X:X|WORD> remove-private-AS all",
4015 NO_STR NEIGHBOR_STR NEIGHBOR_ADDR_STR2
4016 "Remove private ASNs in outbound updates\n"
4017 "Apply to all AS numbers\n")
4018
4019 DEFUN (no_neighbor_remove_private_as_replace_as,
4020 no_neighbor_remove_private_as_replace_as_cmd,
4021 "no neighbor <A.B.C.D|X:X::X:X|WORD> remove-private-AS replace-AS",
4022 NO_STR
4023 NEIGHBOR_STR
4024 NEIGHBOR_ADDR_STR2
4025 "Remove private ASNs in outbound updates\n"
4026 "Replace private ASNs with our ASN in outbound updates\n")
4027 {
4028 int idx_peer = 2;
4029 return peer_af_flag_unset_vty(vty, argv[idx_peer]->arg,
4030 bgp_node_afi(vty), bgp_node_safi(vty),
4031 PEER_FLAG_REMOVE_PRIVATE_AS_REPLACE);
4032 }
4033
4034 ALIAS_HIDDEN(no_neighbor_remove_private_as_replace_as,
4035 no_neighbor_remove_private_as_replace_as_hidden_cmd,
4036 "no neighbor <A.B.C.D|X:X::X:X|WORD> remove-private-AS replace-AS",
4037 NO_STR NEIGHBOR_STR NEIGHBOR_ADDR_STR2
4038 "Remove private ASNs in outbound updates\n"
4039 "Replace private ASNs with our ASN in outbound updates\n")
4040
4041 DEFUN (no_neighbor_remove_private_as_all_replace_as,
4042 no_neighbor_remove_private_as_all_replace_as_cmd,
4043 "no neighbor <A.B.C.D|X:X::X:X|WORD> remove-private-AS all replace-AS",
4044 NO_STR
4045 NEIGHBOR_STR
4046 NEIGHBOR_ADDR_STR2
4047 "Remove private ASNs in outbound updates\n"
4048 "Apply to all AS numbers\n"
4049 "Replace private ASNs with our ASN in outbound updates\n")
4050 {
4051 int idx_peer = 2;
4052 return peer_af_flag_unset_vty(vty, argv[idx_peer]->arg,
4053 bgp_node_afi(vty), bgp_node_safi(vty),
4054 PEER_FLAG_REMOVE_PRIVATE_AS_ALL_REPLACE);
4055 }
4056
4057 ALIAS_HIDDEN(
4058 no_neighbor_remove_private_as_all_replace_as,
4059 no_neighbor_remove_private_as_all_replace_as_hidden_cmd,
4060 "no neighbor <A.B.C.D|X:X::X:X|WORD> remove-private-AS all replace-AS",
4061 NO_STR NEIGHBOR_STR 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
4067 /* neighbor send-community. */
4068 DEFUN (neighbor_send_community,
4069 neighbor_send_community_cmd,
4070 "neighbor <A.B.C.D|X:X::X:X|WORD> send-community",
4071 NEIGHBOR_STR
4072 NEIGHBOR_ADDR_STR2
4073 "Send Community attribute to this neighbor\n")
4074 {
4075 int idx_peer = 1;
4076 return peer_af_flag_set_vty(vty, argv[idx_peer]->arg, bgp_node_afi(vty),
4077 bgp_node_safi(vty),
4078 PEER_FLAG_SEND_COMMUNITY);
4079 }
4080
4081 ALIAS_HIDDEN(neighbor_send_community, neighbor_send_community_hidden_cmd,
4082 "neighbor <A.B.C.D|X:X::X:X|WORD> send-community",
4083 NEIGHBOR_STR NEIGHBOR_ADDR_STR2
4084 "Send Community attribute to this neighbor\n")
4085
4086 DEFUN (no_neighbor_send_community,
4087 no_neighbor_send_community_cmd,
4088 "no neighbor <A.B.C.D|X:X::X:X|WORD> send-community",
4089 NO_STR
4090 NEIGHBOR_STR
4091 NEIGHBOR_ADDR_STR2
4092 "Send Community attribute to this neighbor\n")
4093 {
4094 int idx_peer = 2;
4095 return peer_af_flag_unset_vty(vty, argv[idx_peer]->arg,
4096 bgp_node_afi(vty), bgp_node_safi(vty),
4097 PEER_FLAG_SEND_COMMUNITY);
4098 }
4099
4100 ALIAS_HIDDEN(no_neighbor_send_community, no_neighbor_send_community_hidden_cmd,
4101 "no neighbor <A.B.C.D|X:X::X:X|WORD> send-community",
4102 NO_STR NEIGHBOR_STR NEIGHBOR_ADDR_STR2
4103 "Send Community attribute to this neighbor\n")
4104
4105 /* neighbor send-community extended. */
4106 DEFUN (neighbor_send_community_type,
4107 neighbor_send_community_type_cmd,
4108 "neighbor <A.B.C.D|X:X::X:X|WORD> send-community <both|all|extended|standard|large>",
4109 NEIGHBOR_STR
4110 NEIGHBOR_ADDR_STR2
4111 "Send Community attribute to this neighbor\n"
4112 "Send Standard and Extended Community attributes\n"
4113 "Send Standard, Large and Extended Community attributes\n"
4114 "Send Extended Community attributes\n"
4115 "Send Standard Community attributes\n"
4116 "Send Large Community attributes\n")
4117 {
4118 int idx = 0;
4119 uint32_t flag = 0;
4120
4121 char *peer = argv[1]->arg;
4122
4123 if (argv_find(argv, argc, "standard", &idx))
4124 SET_FLAG(flag, PEER_FLAG_SEND_COMMUNITY);
4125 else if (argv_find(argv, argc, "extended", &idx))
4126 SET_FLAG(flag, PEER_FLAG_SEND_EXT_COMMUNITY);
4127 else if (argv_find(argv, argc, "large", &idx))
4128 SET_FLAG(flag, PEER_FLAG_SEND_LARGE_COMMUNITY);
4129 else if (argv_find(argv, argc, "both", &idx)) {
4130 SET_FLAG(flag, PEER_FLAG_SEND_COMMUNITY);
4131 SET_FLAG(flag, PEER_FLAG_SEND_EXT_COMMUNITY);
4132 } else {
4133 SET_FLAG(flag, PEER_FLAG_SEND_COMMUNITY);
4134 SET_FLAG(flag, PEER_FLAG_SEND_EXT_COMMUNITY);
4135 SET_FLAG(flag, PEER_FLAG_SEND_LARGE_COMMUNITY);
4136 }
4137
4138 return peer_af_flag_set_vty(vty, peer, bgp_node_afi(vty),
4139 bgp_node_safi(vty), flag);
4140 }
4141
4142 ALIAS_HIDDEN(
4143 neighbor_send_community_type, neighbor_send_community_type_hidden_cmd,
4144 "neighbor <A.B.C.D|X:X::X:X|WORD> send-community <both|all|extended|standard|large>",
4145 NEIGHBOR_STR NEIGHBOR_ADDR_STR2
4146 "Send Community attribute to this neighbor\n"
4147 "Send Standard and Extended Community attributes\n"
4148 "Send Standard, Large and Extended Community attributes\n"
4149 "Send Extended Community attributes\n"
4150 "Send Standard Community attributes\n"
4151 "Send Large Community attributes\n")
4152
4153 DEFUN (no_neighbor_send_community_type,
4154 no_neighbor_send_community_type_cmd,
4155 "no neighbor <A.B.C.D|X:X::X:X|WORD> send-community <both|all|extended|standard|large>",
4156 NO_STR
4157 NEIGHBOR_STR
4158 NEIGHBOR_ADDR_STR2
4159 "Send Community attribute to this neighbor\n"
4160 "Send Standard and Extended Community attributes\n"
4161 "Send Standard, Large and Extended Community attributes\n"
4162 "Send Extended Community attributes\n"
4163 "Send Standard Community attributes\n"
4164 "Send Large Community attributes\n")
4165 {
4166 int idx_peer = 2;
4167
4168 const char *type = argv[argc - 1]->text;
4169
4170 if (strmatch(type, "standard"))
4171 return peer_af_flag_unset_vty(
4172 vty, argv[idx_peer]->arg, bgp_node_afi(vty),
4173 bgp_node_safi(vty), PEER_FLAG_SEND_COMMUNITY);
4174 if (strmatch(type, "extended"))
4175 return peer_af_flag_unset_vty(
4176 vty, argv[idx_peer]->arg, bgp_node_afi(vty),
4177 bgp_node_safi(vty), PEER_FLAG_SEND_EXT_COMMUNITY);
4178 if (strmatch(type, "large"))
4179 return peer_af_flag_unset_vty(
4180 vty, argv[idx_peer]->arg, bgp_node_afi(vty),
4181 bgp_node_safi(vty), PEER_FLAG_SEND_LARGE_COMMUNITY);
4182 if (strmatch(type, "both"))
4183 return peer_af_flag_unset_vty(
4184 vty, argv[idx_peer]->arg, bgp_node_afi(vty),
4185 bgp_node_safi(vty),
4186 PEER_FLAG_SEND_COMMUNITY
4187 | PEER_FLAG_SEND_EXT_COMMUNITY);
4188
4189 /* if (strmatch (type, "all")) */
4190 return peer_af_flag_unset_vty(
4191 vty, argv[idx_peer]->arg, bgp_node_afi(vty), bgp_node_safi(vty),
4192 (PEER_FLAG_SEND_COMMUNITY | PEER_FLAG_SEND_EXT_COMMUNITY
4193 | PEER_FLAG_SEND_LARGE_COMMUNITY));
4194 }
4195
4196 ALIAS_HIDDEN(
4197 no_neighbor_send_community_type,
4198 no_neighbor_send_community_type_hidden_cmd,
4199 "no neighbor <A.B.C.D|X:X::X:X|WORD> send-community <both|all|extended|standard|large>",
4200 NO_STR NEIGHBOR_STR NEIGHBOR_ADDR_STR2
4201 "Send Community attribute to this neighbor\n"
4202 "Send Standard and Extended Community attributes\n"
4203 "Send Standard, Large and Extended Community attributes\n"
4204 "Send Extended Community attributes\n"
4205 "Send Standard Community attributes\n"
4206 "Send Large Community attributes\n")
4207
4208 /* neighbor soft-reconfig. */
4209 DEFUN (neighbor_soft_reconfiguration,
4210 neighbor_soft_reconfiguration_cmd,
4211 "neighbor <A.B.C.D|X:X::X:X|WORD> soft-reconfiguration inbound",
4212 NEIGHBOR_STR
4213 NEIGHBOR_ADDR_STR2
4214 "Per neighbor soft reconfiguration\n"
4215 "Allow inbound soft reconfiguration for this neighbor\n")
4216 {
4217 int idx_peer = 1;
4218 return peer_af_flag_set_vty(vty, argv[idx_peer]->arg, bgp_node_afi(vty),
4219 bgp_node_safi(vty),
4220 PEER_FLAG_SOFT_RECONFIG);
4221 }
4222
4223 ALIAS_HIDDEN(neighbor_soft_reconfiguration,
4224 neighbor_soft_reconfiguration_hidden_cmd,
4225 "neighbor <A.B.C.D|X:X::X:X|WORD> soft-reconfiguration inbound",
4226 NEIGHBOR_STR NEIGHBOR_ADDR_STR2
4227 "Per neighbor soft reconfiguration\n"
4228 "Allow inbound soft reconfiguration for this neighbor\n")
4229
4230 DEFUN (no_neighbor_soft_reconfiguration,
4231 no_neighbor_soft_reconfiguration_cmd,
4232 "no neighbor <A.B.C.D|X:X::X:X|WORD> soft-reconfiguration inbound",
4233 NO_STR
4234 NEIGHBOR_STR
4235 NEIGHBOR_ADDR_STR2
4236 "Per neighbor soft reconfiguration\n"
4237 "Allow inbound soft reconfiguration for this neighbor\n")
4238 {
4239 int idx_peer = 2;
4240 return peer_af_flag_unset_vty(vty, argv[idx_peer]->arg,
4241 bgp_node_afi(vty), bgp_node_safi(vty),
4242 PEER_FLAG_SOFT_RECONFIG);
4243 }
4244
4245 ALIAS_HIDDEN(no_neighbor_soft_reconfiguration,
4246 no_neighbor_soft_reconfiguration_hidden_cmd,
4247 "no neighbor <A.B.C.D|X:X::X:X|WORD> soft-reconfiguration inbound",
4248 NO_STR NEIGHBOR_STR NEIGHBOR_ADDR_STR2
4249 "Per neighbor soft reconfiguration\n"
4250 "Allow inbound soft reconfiguration for this neighbor\n")
4251
4252 DEFUN (neighbor_route_reflector_client,
4253 neighbor_route_reflector_client_cmd,
4254 "neighbor <A.B.C.D|X:X::X:X|WORD> route-reflector-client",
4255 NEIGHBOR_STR
4256 NEIGHBOR_ADDR_STR2
4257 "Configure a neighbor as Route Reflector client\n")
4258 {
4259 int idx_peer = 1;
4260 struct peer *peer;
4261
4262
4263 peer = peer_and_group_lookup_vty(vty, argv[idx_peer]->arg);
4264 if (!peer)
4265 return CMD_WARNING_CONFIG_FAILED;
4266
4267 return peer_af_flag_set_vty(vty, argv[idx_peer]->arg, bgp_node_afi(vty),
4268 bgp_node_safi(vty),
4269 PEER_FLAG_REFLECTOR_CLIENT);
4270 }
4271
4272 ALIAS_HIDDEN(neighbor_route_reflector_client,
4273 neighbor_route_reflector_client_hidden_cmd,
4274 "neighbor <A.B.C.D|X:X::X:X|WORD> route-reflector-client",
4275 NEIGHBOR_STR NEIGHBOR_ADDR_STR2
4276 "Configure a neighbor as Route Reflector client\n")
4277
4278 DEFUN (no_neighbor_route_reflector_client,
4279 no_neighbor_route_reflector_client_cmd,
4280 "no neighbor <A.B.C.D|X:X::X:X|WORD> route-reflector-client",
4281 NO_STR
4282 NEIGHBOR_STR
4283 NEIGHBOR_ADDR_STR2
4284 "Configure a neighbor as Route Reflector client\n")
4285 {
4286 int idx_peer = 2;
4287 return peer_af_flag_unset_vty(vty, argv[idx_peer]->arg,
4288 bgp_node_afi(vty), bgp_node_safi(vty),
4289 PEER_FLAG_REFLECTOR_CLIENT);
4290 }
4291
4292 ALIAS_HIDDEN(no_neighbor_route_reflector_client,
4293 no_neighbor_route_reflector_client_hidden_cmd,
4294 "no neighbor <A.B.C.D|X:X::X:X|WORD> route-reflector-client",
4295 NO_STR NEIGHBOR_STR NEIGHBOR_ADDR_STR2
4296 "Configure a neighbor as Route Reflector client\n")
4297
4298 /* neighbor route-server-client. */
4299 DEFUN (neighbor_route_server_client,
4300 neighbor_route_server_client_cmd,
4301 "neighbor <A.B.C.D|X:X::X:X|WORD> route-server-client",
4302 NEIGHBOR_STR
4303 NEIGHBOR_ADDR_STR2
4304 "Configure a neighbor as Route Server client\n")
4305 {
4306 int idx_peer = 1;
4307 struct peer *peer;
4308
4309 peer = peer_and_group_lookup_vty(vty, argv[idx_peer]->arg);
4310 if (!peer)
4311 return CMD_WARNING_CONFIG_FAILED;
4312 return peer_af_flag_set_vty(vty, argv[idx_peer]->arg, bgp_node_afi(vty),
4313 bgp_node_safi(vty),
4314 PEER_FLAG_RSERVER_CLIENT);
4315 }
4316
4317 ALIAS_HIDDEN(neighbor_route_server_client,
4318 neighbor_route_server_client_hidden_cmd,
4319 "neighbor <A.B.C.D|X:X::X:X|WORD> route-server-client",
4320 NEIGHBOR_STR NEIGHBOR_ADDR_STR2
4321 "Configure a neighbor as Route Server client\n")
4322
4323 DEFUN (no_neighbor_route_server_client,
4324 no_neighbor_route_server_client_cmd,
4325 "no neighbor <A.B.C.D|X:X::X:X|WORD> route-server-client",
4326 NO_STR
4327 NEIGHBOR_STR
4328 NEIGHBOR_ADDR_STR2
4329 "Configure a neighbor as Route Server client\n")
4330 {
4331 int idx_peer = 2;
4332 return peer_af_flag_unset_vty(vty, argv[idx_peer]->arg,
4333 bgp_node_afi(vty), bgp_node_safi(vty),
4334 PEER_FLAG_RSERVER_CLIENT);
4335 }
4336
4337 ALIAS_HIDDEN(no_neighbor_route_server_client,
4338 no_neighbor_route_server_client_hidden_cmd,
4339 "no neighbor <A.B.C.D|X:X::X:X|WORD> route-server-client",
4340 NO_STR NEIGHBOR_STR NEIGHBOR_ADDR_STR2
4341 "Configure a neighbor as Route Server client\n")
4342
4343 DEFUN (neighbor_nexthop_local_unchanged,
4344 neighbor_nexthop_local_unchanged_cmd,
4345 "neighbor <A.B.C.D|X:X::X:X|WORD> nexthop-local unchanged",
4346 NEIGHBOR_STR
4347 NEIGHBOR_ADDR_STR2
4348 "Configure treatment of outgoing link-local nexthop attribute\n"
4349 "Leave link-local nexthop unchanged for this peer\n")
4350 {
4351 int idx_peer = 1;
4352 return peer_af_flag_set_vty(vty, argv[idx_peer]->arg, bgp_node_afi(vty),
4353 bgp_node_safi(vty),
4354 PEER_FLAG_NEXTHOP_LOCAL_UNCHANGED);
4355 }
4356
4357 DEFUN (no_neighbor_nexthop_local_unchanged,
4358 no_neighbor_nexthop_local_unchanged_cmd,
4359 "no neighbor <A.B.C.D|X:X::X:X|WORD> nexthop-local unchanged",
4360 NO_STR
4361 NEIGHBOR_STR
4362 NEIGHBOR_ADDR_STR2
4363 "Configure treatment of outgoing link-local-nexthop attribute\n"
4364 "Leave link-local nexthop unchanged for this peer\n")
4365 {
4366 int idx_peer = 2;
4367 return peer_af_flag_unset_vty(vty, argv[idx_peer]->arg,
4368 bgp_node_afi(vty), bgp_node_safi(vty),
4369 PEER_FLAG_NEXTHOP_LOCAL_UNCHANGED);
4370 }
4371
4372 DEFUN (neighbor_attr_unchanged,
4373 neighbor_attr_unchanged_cmd,
4374 "neighbor <A.B.C.D|X:X::X:X|WORD> attribute-unchanged [{as-path|next-hop|med}]",
4375 NEIGHBOR_STR
4376 NEIGHBOR_ADDR_STR2
4377 "BGP attribute is propagated unchanged to this neighbor\n"
4378 "As-path attribute\n"
4379 "Nexthop attribute\n"
4380 "Med attribute\n")
4381 {
4382 int idx = 0;
4383 char *peer_str = argv[1]->arg;
4384 struct peer *peer;
4385 uint16_t flags = 0;
4386 afi_t afi = bgp_node_afi(vty);
4387 safi_t safi = bgp_node_safi(vty);
4388
4389 peer = peer_and_group_lookup_vty(vty, peer_str);
4390 if (!peer)
4391 return CMD_WARNING_CONFIG_FAILED;
4392
4393 if (argv_find(argv, argc, "as-path", &idx))
4394 SET_FLAG(flags, PEER_FLAG_AS_PATH_UNCHANGED);
4395 idx = 0;
4396 if (argv_find(argv, argc, "next-hop", &idx))
4397 SET_FLAG(flags, PEER_FLAG_NEXTHOP_UNCHANGED);
4398 idx = 0;
4399 if (argv_find(argv, argc, "med", &idx))
4400 SET_FLAG(flags, PEER_FLAG_MED_UNCHANGED);
4401
4402 /* no flags means all of them! */
4403 if (!flags) {
4404 SET_FLAG(flags, PEER_FLAG_AS_PATH_UNCHANGED);
4405 SET_FLAG(flags, PEER_FLAG_NEXTHOP_UNCHANGED);
4406 SET_FLAG(flags, PEER_FLAG_MED_UNCHANGED);
4407 } else {
4408 if (!CHECK_FLAG(flags, PEER_FLAG_AS_PATH_UNCHANGED)
4409 && peer_af_flag_check(peer, afi, safi,
4410 PEER_FLAG_AS_PATH_UNCHANGED)) {
4411 peer_af_flag_unset_vty(vty, peer_str, afi, safi,
4412 PEER_FLAG_AS_PATH_UNCHANGED);
4413 }
4414
4415 if (!CHECK_FLAG(flags, PEER_FLAG_NEXTHOP_UNCHANGED)
4416 && peer_af_flag_check(peer, afi, safi,
4417 PEER_FLAG_NEXTHOP_UNCHANGED)) {
4418 peer_af_flag_unset_vty(vty, peer_str, afi, safi,
4419 PEER_FLAG_NEXTHOP_UNCHANGED);
4420 }
4421
4422 if (!CHECK_FLAG(flags, PEER_FLAG_MED_UNCHANGED)
4423 && peer_af_flag_check(peer, afi, safi,
4424 PEER_FLAG_MED_UNCHANGED)) {
4425 peer_af_flag_unset_vty(vty, peer_str, afi, safi,
4426 PEER_FLAG_MED_UNCHANGED);
4427 }
4428 }
4429
4430 return peer_af_flag_set_vty(vty, peer_str, afi, safi, flags);
4431 }
4432
4433 ALIAS_HIDDEN(
4434 neighbor_attr_unchanged, neighbor_attr_unchanged_hidden_cmd,
4435 "neighbor <A.B.C.D|X:X::X:X|WORD> attribute-unchanged [{as-path|next-hop|med}]",
4436 NEIGHBOR_STR NEIGHBOR_ADDR_STR2
4437 "BGP attribute is propagated unchanged to this neighbor\n"
4438 "As-path attribute\n"
4439 "Nexthop attribute\n"
4440 "Med attribute\n")
4441
4442 DEFUN (no_neighbor_attr_unchanged,
4443 no_neighbor_attr_unchanged_cmd,
4444 "no neighbor <A.B.C.D|X:X::X:X|WORD> attribute-unchanged [{as-path|next-hop|med}]",
4445 NO_STR
4446 NEIGHBOR_STR
4447 NEIGHBOR_ADDR_STR2
4448 "BGP attribute is propagated unchanged to this neighbor\n"
4449 "As-path attribute\n"
4450 "Nexthop attribute\n"
4451 "Med attribute\n")
4452 {
4453 int idx = 0;
4454 char *peer = argv[2]->arg;
4455 uint16_t flags = 0;
4456
4457 if (argv_find(argv, argc, "as-path", &idx))
4458 SET_FLAG(flags, PEER_FLAG_AS_PATH_UNCHANGED);
4459 idx = 0;
4460 if (argv_find(argv, argc, "next-hop", &idx))
4461 SET_FLAG(flags, PEER_FLAG_NEXTHOP_UNCHANGED);
4462 idx = 0;
4463 if (argv_find(argv, argc, "med", &idx))
4464 SET_FLAG(flags, PEER_FLAG_MED_UNCHANGED);
4465
4466 if (!flags) // no flags means all of them!
4467 {
4468 SET_FLAG(flags, PEER_FLAG_AS_PATH_UNCHANGED);
4469 SET_FLAG(flags, PEER_FLAG_NEXTHOP_UNCHANGED);
4470 SET_FLAG(flags, PEER_FLAG_MED_UNCHANGED);
4471 }
4472
4473 return peer_af_flag_unset_vty(vty, peer, bgp_node_afi(vty),
4474 bgp_node_safi(vty), flags);
4475 }
4476
4477 ALIAS_HIDDEN(
4478 no_neighbor_attr_unchanged, no_neighbor_attr_unchanged_hidden_cmd,
4479 "no neighbor <A.B.C.D|X:X::X:X|WORD> attribute-unchanged [{as-path|next-hop|med}]",
4480 NO_STR NEIGHBOR_STR NEIGHBOR_ADDR_STR2
4481 "BGP attribute is propagated unchanged to this neighbor\n"
4482 "As-path attribute\n"
4483 "Nexthop attribute\n"
4484 "Med attribute\n")
4485
4486 /* EBGP multihop configuration. */
4487 static int peer_ebgp_multihop_set_vty(struct vty *vty, const char *ip_str,
4488 const char *ttl_str)
4489 {
4490 struct peer *peer;
4491 unsigned int ttl;
4492
4493 peer = peer_and_group_lookup_vty(vty, ip_str);
4494 if (!peer)
4495 return CMD_WARNING_CONFIG_FAILED;
4496
4497 if (peer->conf_if)
4498 return bgp_vty_return(vty, BGP_ERR_INVALID_FOR_DIRECT_PEER);
4499
4500 if (!ttl_str)
4501 ttl = MAXTTL;
4502 else
4503 ttl = strtoul(ttl_str, NULL, 10);
4504
4505 return bgp_vty_return(vty, peer_ebgp_multihop_set(peer, ttl));
4506 }
4507
4508 static int peer_ebgp_multihop_unset_vty(struct vty *vty, const char *ip_str)
4509 {
4510 struct peer *peer;
4511
4512 peer = peer_and_group_lookup_vty(vty, ip_str);
4513 if (!peer)
4514 return CMD_WARNING_CONFIG_FAILED;
4515
4516 return bgp_vty_return(vty, peer_ebgp_multihop_unset(peer));
4517 }
4518
4519 /* neighbor ebgp-multihop. */
4520 DEFUN (neighbor_ebgp_multihop,
4521 neighbor_ebgp_multihop_cmd,
4522 "neighbor <A.B.C.D|X:X::X:X|WORD> ebgp-multihop",
4523 NEIGHBOR_STR
4524 NEIGHBOR_ADDR_STR2
4525 "Allow EBGP neighbors not on directly connected networks\n")
4526 {
4527 int idx_peer = 1;
4528 return peer_ebgp_multihop_set_vty(vty, argv[idx_peer]->arg, NULL);
4529 }
4530
4531 DEFUN (neighbor_ebgp_multihop_ttl,
4532 neighbor_ebgp_multihop_ttl_cmd,
4533 "neighbor <A.B.C.D|X:X::X:X|WORD> ebgp-multihop (1-255)",
4534 NEIGHBOR_STR
4535 NEIGHBOR_ADDR_STR2
4536 "Allow EBGP neighbors not on directly connected networks\n"
4537 "maximum hop count\n")
4538 {
4539 int idx_peer = 1;
4540 int idx_number = 3;
4541 return peer_ebgp_multihop_set_vty(vty, argv[idx_peer]->arg,
4542 argv[idx_number]->arg);
4543 }
4544
4545 DEFUN (no_neighbor_ebgp_multihop,
4546 no_neighbor_ebgp_multihop_cmd,
4547 "no neighbor <A.B.C.D|X:X::X:X|WORD> ebgp-multihop [(1-255)]",
4548 NO_STR
4549 NEIGHBOR_STR
4550 NEIGHBOR_ADDR_STR2
4551 "Allow EBGP neighbors not on directly connected networks\n"
4552 "maximum hop count\n")
4553 {
4554 int idx_peer = 2;
4555 return peer_ebgp_multihop_unset_vty(vty, argv[idx_peer]->arg);
4556 }
4557
4558
4559 /* disable-connected-check */
4560 DEFUN (neighbor_disable_connected_check,
4561 neighbor_disable_connected_check_cmd,
4562 "neighbor <A.B.C.D|X:X::X:X|WORD> <disable-connected-check|enforce-multihop>",
4563 NEIGHBOR_STR
4564 NEIGHBOR_ADDR_STR2
4565 "one-hop away EBGP peer using loopback address\n"
4566 "Enforce EBGP neighbors perform multihop\n")
4567 {
4568 int idx_peer = 1;
4569 return peer_flag_set_vty(vty, argv[idx_peer]->arg,
4570 PEER_FLAG_DISABLE_CONNECTED_CHECK);
4571 }
4572
4573 DEFUN (no_neighbor_disable_connected_check,
4574 no_neighbor_disable_connected_check_cmd,
4575 "no neighbor <A.B.C.D|X:X::X:X|WORD> <disable-connected-check|enforce-multihop>",
4576 NO_STR
4577 NEIGHBOR_STR
4578 NEIGHBOR_ADDR_STR2
4579 "one-hop away EBGP peer using loopback address\n"
4580 "Enforce EBGP neighbors perform multihop\n")
4581 {
4582 int idx_peer = 2;
4583 return peer_flag_unset_vty(vty, argv[idx_peer]->arg,
4584 PEER_FLAG_DISABLE_CONNECTED_CHECK);
4585 }
4586
4587 DEFUN (neighbor_description,
4588 neighbor_description_cmd,
4589 "neighbor <A.B.C.D|X:X::X:X|WORD> description LINE...",
4590 NEIGHBOR_STR
4591 NEIGHBOR_ADDR_STR2
4592 "Neighbor specific description\n"
4593 "Up to 80 characters describing this neighbor\n")
4594 {
4595 int idx_peer = 1;
4596 int idx_line = 3;
4597 struct peer *peer;
4598 char *str;
4599
4600 peer = peer_and_group_lookup_vty(vty, argv[idx_peer]->arg);
4601 if (!peer)
4602 return CMD_WARNING_CONFIG_FAILED;
4603
4604 str = argv_concat(argv, argc, idx_line);
4605
4606 peer_description_set(peer, str);
4607
4608 XFREE(MTYPE_TMP, str);
4609
4610 return CMD_SUCCESS;
4611 }
4612
4613 DEFUN (no_neighbor_description,
4614 no_neighbor_description_cmd,
4615 "no neighbor <A.B.C.D|X:X::X:X|WORD> description [LINE]",
4616 NO_STR
4617 NEIGHBOR_STR
4618 NEIGHBOR_ADDR_STR2
4619 "Neighbor specific description\n"
4620 "Up to 80 characters describing this neighbor\n")
4621 {
4622 int idx_peer = 2;
4623 struct peer *peer;
4624
4625 peer = peer_and_group_lookup_vty(vty, argv[idx_peer]->arg);
4626 if (!peer)
4627 return CMD_WARNING_CONFIG_FAILED;
4628
4629 peer_description_unset(peer);
4630
4631 return CMD_SUCCESS;
4632 }
4633
4634
4635 /* Neighbor update-source. */
4636 static int peer_update_source_vty(struct vty *vty, const char *peer_str,
4637 const char *source_str)
4638 {
4639 struct peer *peer;
4640 struct prefix p;
4641
4642 peer = peer_and_group_lookup_vty(vty, peer_str);
4643 if (!peer)
4644 return CMD_WARNING_CONFIG_FAILED;
4645
4646 if (peer->conf_if)
4647 return CMD_WARNING;
4648
4649 if (source_str) {
4650 union sockunion su;
4651 int ret = str2sockunion(source_str, &su);
4652
4653 if (ret == 0)
4654 peer_update_source_addr_set(peer, &su);
4655 else {
4656 if (str2prefix(source_str, &p)) {
4657 vty_out(vty,
4658 "%% Invalid update-source, remove prefix length \n");
4659 return CMD_WARNING_CONFIG_FAILED;
4660 } else
4661 peer_update_source_if_set(peer, source_str);
4662 }
4663 } else
4664 peer_update_source_unset(peer);
4665
4666 return CMD_SUCCESS;
4667 }
4668
4669 #define BGP_UPDATE_SOURCE_HELP_STR \
4670 "IPv4 address\n" \
4671 "IPv6 address\n" \
4672 "Interface name (requires zebra to be running)\n"
4673
4674 DEFUN (neighbor_update_source,
4675 neighbor_update_source_cmd,
4676 "neighbor <A.B.C.D|X:X::X:X|WORD> update-source <A.B.C.D|X:X::X:X|WORD>",
4677 NEIGHBOR_STR
4678 NEIGHBOR_ADDR_STR2
4679 "Source of routing updates\n"
4680 BGP_UPDATE_SOURCE_HELP_STR)
4681 {
4682 int idx_peer = 1;
4683 int idx_peer_2 = 3;
4684 return peer_update_source_vty(vty, argv[idx_peer]->arg,
4685 argv[idx_peer_2]->arg);
4686 }
4687
4688 DEFUN (no_neighbor_update_source,
4689 no_neighbor_update_source_cmd,
4690 "no neighbor <A.B.C.D|X:X::X:X|WORD> update-source [<A.B.C.D|X:X::X:X|WORD>]",
4691 NO_STR
4692 NEIGHBOR_STR
4693 NEIGHBOR_ADDR_STR2
4694 "Source of routing updates\n"
4695 BGP_UPDATE_SOURCE_HELP_STR)
4696 {
4697 int idx_peer = 2;
4698 return peer_update_source_vty(vty, argv[idx_peer]->arg, NULL);
4699 }
4700
4701 static int peer_default_originate_set_vty(struct vty *vty, const char *peer_str,
4702 afi_t afi, safi_t safi,
4703 const char *rmap, int set)
4704 {
4705 int ret;
4706 struct peer *peer;
4707
4708 peer = peer_and_group_lookup_vty(vty, peer_str);
4709 if (!peer)
4710 return CMD_WARNING_CONFIG_FAILED;
4711
4712 if (set)
4713 ret = peer_default_originate_set(peer, afi, safi, rmap);
4714 else
4715 ret = peer_default_originate_unset(peer, afi, safi);
4716
4717 return bgp_vty_return(vty, ret);
4718 }
4719
4720 /* neighbor default-originate. */
4721 DEFUN (neighbor_default_originate,
4722 neighbor_default_originate_cmd,
4723 "neighbor <A.B.C.D|X:X::X:X|WORD> default-originate",
4724 NEIGHBOR_STR
4725 NEIGHBOR_ADDR_STR2
4726 "Originate default route to this neighbor\n")
4727 {
4728 int idx_peer = 1;
4729 return peer_default_originate_set_vty(vty, argv[idx_peer]->arg,
4730 bgp_node_afi(vty),
4731 bgp_node_safi(vty), NULL, 1);
4732 }
4733
4734 ALIAS_HIDDEN(neighbor_default_originate, neighbor_default_originate_hidden_cmd,
4735 "neighbor <A.B.C.D|X:X::X:X|WORD> default-originate",
4736 NEIGHBOR_STR NEIGHBOR_ADDR_STR2
4737 "Originate default route to this neighbor\n")
4738
4739 DEFUN (neighbor_default_originate_rmap,
4740 neighbor_default_originate_rmap_cmd,
4741 "neighbor <A.B.C.D|X:X::X:X|WORD> default-originate route-map WORD",
4742 NEIGHBOR_STR
4743 NEIGHBOR_ADDR_STR2
4744 "Originate default route to this neighbor\n"
4745 "Route-map to specify criteria to originate default\n"
4746 "route-map name\n")
4747 {
4748 int idx_peer = 1;
4749 int idx_word = 4;
4750 return peer_default_originate_set_vty(
4751 vty, argv[idx_peer]->arg, bgp_node_afi(vty), bgp_node_safi(vty),
4752 argv[idx_word]->arg, 1);
4753 }
4754
4755 ALIAS_HIDDEN(
4756 neighbor_default_originate_rmap,
4757 neighbor_default_originate_rmap_hidden_cmd,
4758 "neighbor <A.B.C.D|X:X::X:X|WORD> default-originate route-map WORD",
4759 NEIGHBOR_STR NEIGHBOR_ADDR_STR2
4760 "Originate default route to this neighbor\n"
4761 "Route-map to specify criteria to originate default\n"
4762 "route-map name\n")
4763
4764 DEFUN (no_neighbor_default_originate,
4765 no_neighbor_default_originate_cmd,
4766 "no neighbor <A.B.C.D|X:X::X:X|WORD> default-originate [route-map WORD]",
4767 NO_STR
4768 NEIGHBOR_STR
4769 NEIGHBOR_ADDR_STR2
4770 "Originate default route to this neighbor\n"
4771 "Route-map to specify criteria to originate default\n"
4772 "route-map name\n")
4773 {
4774 int idx_peer = 2;
4775 return peer_default_originate_set_vty(vty, argv[idx_peer]->arg,
4776 bgp_node_afi(vty),
4777 bgp_node_safi(vty), NULL, 0);
4778 }
4779
4780 ALIAS_HIDDEN(
4781 no_neighbor_default_originate, no_neighbor_default_originate_hidden_cmd,
4782 "no neighbor <A.B.C.D|X:X::X:X|WORD> default-originate [route-map WORD]",
4783 NO_STR NEIGHBOR_STR 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
4789 /* Set neighbor's BGP port. */
4790 static int peer_port_vty(struct vty *vty, const char *ip_str, int afi,
4791 const char *port_str)
4792 {
4793 struct peer *peer;
4794 uint16_t port;
4795 struct servent *sp;
4796
4797 peer = peer_lookup_vty(vty, ip_str);
4798 if (!peer)
4799 return CMD_WARNING_CONFIG_FAILED;
4800
4801 if (!port_str) {
4802 sp = getservbyname("bgp", "tcp");
4803 port = (sp == NULL) ? BGP_PORT_DEFAULT : ntohs(sp->s_port);
4804 } else {
4805 port = strtoul(port_str, NULL, 10);
4806 }
4807
4808 peer_port_set(peer, port);
4809
4810 return CMD_SUCCESS;
4811 }
4812
4813 /* Set specified peer's BGP port. */
4814 DEFUN (neighbor_port,
4815 neighbor_port_cmd,
4816 "neighbor <A.B.C.D|X:X::X:X> port (0-65535)",
4817 NEIGHBOR_STR
4818 NEIGHBOR_ADDR_STR
4819 "Neighbor's BGP port\n"
4820 "TCP port number\n")
4821 {
4822 int idx_ip = 1;
4823 int idx_number = 3;
4824 return peer_port_vty(vty, argv[idx_ip]->arg, AFI_IP,
4825 argv[idx_number]->arg);
4826 }
4827
4828 DEFUN (no_neighbor_port,
4829 no_neighbor_port_cmd,
4830 "no neighbor <A.B.C.D|X:X::X:X> port [(0-65535)]",
4831 NO_STR
4832 NEIGHBOR_STR
4833 NEIGHBOR_ADDR_STR
4834 "Neighbor's BGP port\n"
4835 "TCP port number\n")
4836 {
4837 int idx_ip = 2;
4838 return peer_port_vty(vty, argv[idx_ip]->arg, AFI_IP, NULL);
4839 }
4840
4841
4842 /* neighbor weight. */
4843 static int peer_weight_set_vty(struct vty *vty, const char *ip_str, afi_t afi,
4844 safi_t safi, const char *weight_str)
4845 {
4846 int ret;
4847 struct peer *peer;
4848 unsigned long weight;
4849
4850 peer = peer_and_group_lookup_vty(vty, ip_str);
4851 if (!peer)
4852 return CMD_WARNING_CONFIG_FAILED;
4853
4854 weight = strtoul(weight_str, NULL, 10);
4855
4856 ret = peer_weight_set(peer, afi, safi, weight);
4857 return bgp_vty_return(vty, ret);
4858 }
4859
4860 static int peer_weight_unset_vty(struct vty *vty, const char *ip_str, afi_t afi,
4861 safi_t safi)
4862 {
4863 int ret;
4864 struct peer *peer;
4865
4866 peer = peer_and_group_lookup_vty(vty, ip_str);
4867 if (!peer)
4868 return CMD_WARNING_CONFIG_FAILED;
4869
4870 ret = peer_weight_unset(peer, afi, safi);
4871 return bgp_vty_return(vty, ret);
4872 }
4873
4874 DEFUN (neighbor_weight,
4875 neighbor_weight_cmd,
4876 "neighbor <A.B.C.D|X:X::X:X|WORD> weight (0-65535)",
4877 NEIGHBOR_STR
4878 NEIGHBOR_ADDR_STR2
4879 "Set default weight for routes from this neighbor\n"
4880 "default weight\n")
4881 {
4882 int idx_peer = 1;
4883 int idx_number = 3;
4884 return peer_weight_set_vty(vty, argv[idx_peer]->arg, bgp_node_afi(vty),
4885 bgp_node_safi(vty), argv[idx_number]->arg);
4886 }
4887
4888 ALIAS_HIDDEN(neighbor_weight, neighbor_weight_hidden_cmd,
4889 "neighbor <A.B.C.D|X:X::X:X|WORD> weight (0-65535)",
4890 NEIGHBOR_STR NEIGHBOR_ADDR_STR2
4891 "Set default weight for routes from this neighbor\n"
4892 "default weight\n")
4893
4894 DEFUN (no_neighbor_weight,
4895 no_neighbor_weight_cmd,
4896 "no neighbor <A.B.C.D|X:X::X:X|WORD> weight [(0-65535)]",
4897 NO_STR
4898 NEIGHBOR_STR
4899 NEIGHBOR_ADDR_STR2
4900 "Set default weight for routes from this neighbor\n"
4901 "default weight\n")
4902 {
4903 int idx_peer = 2;
4904 return peer_weight_unset_vty(vty, argv[idx_peer]->arg,
4905 bgp_node_afi(vty), bgp_node_safi(vty));
4906 }
4907
4908 ALIAS_HIDDEN(no_neighbor_weight, no_neighbor_weight_hidden_cmd,
4909 "no neighbor <A.B.C.D|X:X::X:X|WORD> weight [(0-65535)]",
4910 NO_STR NEIGHBOR_STR NEIGHBOR_ADDR_STR2
4911 "Set default weight for routes from this neighbor\n"
4912 "default weight\n")
4913
4914
4915 /* Override capability negotiation. */
4916 DEFUN (neighbor_override_capability,
4917 neighbor_override_capability_cmd,
4918 "neighbor <A.B.C.D|X:X::X:X|WORD> override-capability",
4919 NEIGHBOR_STR
4920 NEIGHBOR_ADDR_STR2
4921 "Override capability negotiation result\n")
4922 {
4923 int idx_peer = 1;
4924 return peer_flag_set_vty(vty, argv[idx_peer]->arg,
4925 PEER_FLAG_OVERRIDE_CAPABILITY);
4926 }
4927
4928 DEFUN (no_neighbor_override_capability,
4929 no_neighbor_override_capability_cmd,
4930 "no neighbor <A.B.C.D|X:X::X:X|WORD> override-capability",
4931 NO_STR
4932 NEIGHBOR_STR
4933 NEIGHBOR_ADDR_STR2
4934 "Override capability negotiation result\n")
4935 {
4936 int idx_peer = 2;
4937 return peer_flag_unset_vty(vty, argv[idx_peer]->arg,
4938 PEER_FLAG_OVERRIDE_CAPABILITY);
4939 }
4940
4941 DEFUN (neighbor_strict_capability,
4942 neighbor_strict_capability_cmd,
4943 "neighbor <A.B.C.D|X:X::X:X> strict-capability-match",
4944 NEIGHBOR_STR
4945 NEIGHBOR_ADDR_STR
4946 "Strict capability negotiation match\n")
4947 {
4948 int idx_ip = 1;
4949 return peer_flag_set_vty(vty, argv[idx_ip]->arg,
4950 PEER_FLAG_STRICT_CAP_MATCH);
4951 }
4952
4953 DEFUN (no_neighbor_strict_capability,
4954 no_neighbor_strict_capability_cmd,
4955 "no neighbor <A.B.C.D|X:X::X:X> strict-capability-match",
4956 NO_STR
4957 NEIGHBOR_STR
4958 NEIGHBOR_ADDR_STR
4959 "Strict capability negotiation match\n")
4960 {
4961 int idx_ip = 2;
4962 return peer_flag_unset_vty(vty, argv[idx_ip]->arg,
4963 PEER_FLAG_STRICT_CAP_MATCH);
4964 }
4965
4966 static int peer_timers_set_vty(struct vty *vty, const char *ip_str,
4967 const char *keep_str, const char *hold_str)
4968 {
4969 int ret;
4970 struct peer *peer;
4971 uint32_t keepalive;
4972 uint32_t holdtime;
4973
4974 peer = peer_and_group_lookup_vty(vty, ip_str);
4975 if (!peer)
4976 return CMD_WARNING_CONFIG_FAILED;
4977
4978 keepalive = strtoul(keep_str, NULL, 10);
4979 holdtime = strtoul(hold_str, NULL, 10);
4980
4981 ret = peer_timers_set(peer, keepalive, holdtime);
4982
4983 return bgp_vty_return(vty, ret);
4984 }
4985
4986 static int peer_timers_unset_vty(struct vty *vty, const char *ip_str)
4987 {
4988 int ret;
4989 struct peer *peer;
4990
4991 peer = peer_and_group_lookup_vty(vty, ip_str);
4992 if (!peer)
4993 return CMD_WARNING_CONFIG_FAILED;
4994
4995 ret = peer_timers_unset(peer);
4996
4997 return bgp_vty_return(vty, ret);
4998 }
4999
5000 DEFUN (neighbor_timers,
5001 neighbor_timers_cmd,
5002 "neighbor <A.B.C.D|X:X::X:X|WORD> timers (0-65535) (0-65535)",
5003 NEIGHBOR_STR
5004 NEIGHBOR_ADDR_STR2
5005 "BGP per neighbor timers\n"
5006 "Keepalive interval\n"
5007 "Holdtime\n")
5008 {
5009 int idx_peer = 1;
5010 int idx_number = 3;
5011 int idx_number_2 = 4;
5012 return peer_timers_set_vty(vty, argv[idx_peer]->arg,
5013 argv[idx_number]->arg,
5014 argv[idx_number_2]->arg);
5015 }
5016
5017 DEFUN (no_neighbor_timers,
5018 no_neighbor_timers_cmd,
5019 "no neighbor <A.B.C.D|X:X::X:X|WORD> timers [(0-65535) (0-65535)]",
5020 NO_STR
5021 NEIGHBOR_STR
5022 NEIGHBOR_ADDR_STR2
5023 "BGP per neighbor timers\n"
5024 "Keepalive interval\n"
5025 "Holdtime\n")
5026 {
5027 int idx_peer = 2;
5028 return peer_timers_unset_vty(vty, argv[idx_peer]->arg);
5029 }
5030
5031
5032 static int peer_timers_connect_set_vty(struct vty *vty, const char *ip_str,
5033 const char *time_str)
5034 {
5035 int ret;
5036 struct peer *peer;
5037 uint32_t connect;
5038
5039 peer = peer_and_group_lookup_vty(vty, ip_str);
5040 if (!peer)
5041 return CMD_WARNING_CONFIG_FAILED;
5042
5043 connect = strtoul(time_str, NULL, 10);
5044
5045 ret = peer_timers_connect_set(peer, connect);
5046
5047 return bgp_vty_return(vty, ret);
5048 }
5049
5050 static int peer_timers_connect_unset_vty(struct vty *vty, const char *ip_str)
5051 {
5052 int ret;
5053 struct peer *peer;
5054
5055 peer = peer_and_group_lookup_vty(vty, ip_str);
5056 if (!peer)
5057 return CMD_WARNING_CONFIG_FAILED;
5058
5059 ret = peer_timers_connect_unset(peer);
5060
5061 return bgp_vty_return(vty, ret);
5062 }
5063
5064 DEFUN (neighbor_timers_connect,
5065 neighbor_timers_connect_cmd,
5066 "neighbor <A.B.C.D|X:X::X:X|WORD> timers connect (1-65535)",
5067 NEIGHBOR_STR
5068 NEIGHBOR_ADDR_STR2
5069 "BGP per neighbor timers\n"
5070 "BGP connect timer\n"
5071 "Connect timer\n")
5072 {
5073 int idx_peer = 1;
5074 int idx_number = 4;
5075 return peer_timers_connect_set_vty(vty, argv[idx_peer]->arg,
5076 argv[idx_number]->arg);
5077 }
5078
5079 DEFUN (no_neighbor_timers_connect,
5080 no_neighbor_timers_connect_cmd,
5081 "no neighbor <A.B.C.D|X:X::X:X|WORD> timers connect [(1-65535)]",
5082 NO_STR
5083 NEIGHBOR_STR
5084 NEIGHBOR_ADDR_STR2
5085 "BGP per neighbor timers\n"
5086 "BGP connect timer\n"
5087 "Connect timer\n")
5088 {
5089 int idx_peer = 2;
5090 return peer_timers_connect_unset_vty(vty, argv[idx_peer]->arg);
5091 }
5092
5093
5094 static int peer_advertise_interval_vty(struct vty *vty, const char *ip_str,
5095 const char *time_str, int set)
5096 {
5097 int ret;
5098 struct peer *peer;
5099 uint32_t routeadv = 0;
5100
5101 peer = peer_and_group_lookup_vty(vty, ip_str);
5102 if (!peer)
5103 return CMD_WARNING_CONFIG_FAILED;
5104
5105 if (time_str)
5106 routeadv = strtoul(time_str, NULL, 10);
5107
5108 if (set)
5109 ret = peer_advertise_interval_set(peer, routeadv);
5110 else
5111 ret = peer_advertise_interval_unset(peer);
5112
5113 return bgp_vty_return(vty, ret);
5114 }
5115
5116 DEFUN (neighbor_advertise_interval,
5117 neighbor_advertise_interval_cmd,
5118 "neighbor <A.B.C.D|X:X::X:X|WORD> advertisement-interval (0-600)",
5119 NEIGHBOR_STR
5120 NEIGHBOR_ADDR_STR2
5121 "Minimum interval between sending BGP routing updates\n"
5122 "time in seconds\n")
5123 {
5124 int idx_peer = 1;
5125 int idx_number = 3;
5126 return peer_advertise_interval_vty(vty, argv[idx_peer]->arg,
5127 argv[idx_number]->arg, 1);
5128 }
5129
5130 DEFUN (no_neighbor_advertise_interval,
5131 no_neighbor_advertise_interval_cmd,
5132 "no neighbor <A.B.C.D|X:X::X:X|WORD> advertisement-interval [(0-600)]",
5133 NO_STR
5134 NEIGHBOR_STR
5135 NEIGHBOR_ADDR_STR2
5136 "Minimum interval between sending BGP routing updates\n"
5137 "time in seconds\n")
5138 {
5139 int idx_peer = 2;
5140 return peer_advertise_interval_vty(vty, argv[idx_peer]->arg, NULL, 0);
5141 }
5142
5143
5144 /* Time to wait before processing route-map updates */
5145 DEFUN (bgp_set_route_map_delay_timer,
5146 bgp_set_route_map_delay_timer_cmd,
5147 "bgp route-map delay-timer (0-600)",
5148 SET_STR
5149 "BGP route-map delay timer\n"
5150 "Time in secs to wait before processing route-map changes\n"
5151 "0 disables the timer, no route updates happen when route-maps change\n")
5152 {
5153 int idx_number = 3;
5154 uint32_t rmap_delay_timer;
5155
5156 if (argv[idx_number]->arg) {
5157 rmap_delay_timer = strtoul(argv[idx_number]->arg, NULL, 10);
5158 bm->rmap_update_timer = rmap_delay_timer;
5159
5160 /* if the dynamic update handling is being disabled, and a timer
5161 * is
5162 * running, stop the timer and act as if the timer has already
5163 * fired.
5164 */
5165 if (!rmap_delay_timer && bm->t_rmap_update) {
5166 BGP_TIMER_OFF(bm->t_rmap_update);
5167 thread_execute(bm->master, bgp_route_map_update_timer,
5168 NULL, 0);
5169 }
5170 return CMD_SUCCESS;
5171 } else {
5172 vty_out(vty, "%% BGP invalid route-map delay-timer\n");
5173 return CMD_WARNING_CONFIG_FAILED;
5174 }
5175 }
5176
5177 DEFUN (no_bgp_set_route_map_delay_timer,
5178 no_bgp_set_route_map_delay_timer_cmd,
5179 "no bgp route-map delay-timer [(0-600)]",
5180 NO_STR
5181 BGP_STR
5182 "Default BGP route-map delay timer\n"
5183 "Reset to default time to wait for processing route-map changes\n"
5184 "0 disables the timer, no route updates happen when route-maps change\n")
5185 {
5186
5187 bm->rmap_update_timer = RMAP_DEFAULT_UPDATE_TIMER;
5188
5189 return CMD_SUCCESS;
5190 }
5191
5192
5193 /* neighbor interface */
5194 static int peer_interface_vty(struct vty *vty, const char *ip_str,
5195 const char *str)
5196 {
5197 struct peer *peer;
5198
5199 peer = peer_lookup_vty(vty, ip_str);
5200 if (!peer || peer->conf_if) {
5201 vty_out(vty, "%% BGP invalid peer %s\n", ip_str);
5202 return CMD_WARNING_CONFIG_FAILED;
5203 }
5204
5205 if (str)
5206 peer_interface_set(peer, str);
5207 else
5208 peer_interface_unset(peer);
5209
5210 return CMD_SUCCESS;
5211 }
5212
5213 DEFUN (neighbor_interface,
5214 neighbor_interface_cmd,
5215 "neighbor <A.B.C.D|X:X::X:X> interface WORD",
5216 NEIGHBOR_STR
5217 NEIGHBOR_ADDR_STR
5218 "Interface\n"
5219 "Interface name\n")
5220 {
5221 int idx_ip = 1;
5222 int idx_word = 3;
5223 return peer_interface_vty(vty, argv[idx_ip]->arg, argv[idx_word]->arg);
5224 }
5225
5226 DEFUN (no_neighbor_interface,
5227 no_neighbor_interface_cmd,
5228 "no neighbor <A.B.C.D|X:X::X:X|WORD> interface WORD",
5229 NO_STR
5230 NEIGHBOR_STR
5231 NEIGHBOR_ADDR_STR2
5232 "Interface\n"
5233 "Interface name\n")
5234 {
5235 int idx_peer = 2;
5236 return peer_interface_vty(vty, argv[idx_peer]->arg, NULL);
5237 }
5238
5239 DEFUN (neighbor_distribute_list,
5240 neighbor_distribute_list_cmd,
5241 "neighbor <A.B.C.D|X:X::X:X|WORD> distribute-list <(1-199)|(1300-2699)|WORD> <in|out>",
5242 NEIGHBOR_STR
5243 NEIGHBOR_ADDR_STR2
5244 "Filter updates to/from this neighbor\n"
5245 "IP access-list number\n"
5246 "IP access-list number (expanded range)\n"
5247 "IP Access-list name\n"
5248 "Filter incoming updates\n"
5249 "Filter outgoing updates\n")
5250 {
5251 int idx_peer = 1;
5252 int idx_acl = 3;
5253 int direct, ret;
5254 struct peer *peer;
5255
5256 const char *pstr = argv[idx_peer]->arg;
5257 const char *acl = argv[idx_acl]->arg;
5258 const char *inout = argv[argc - 1]->text;
5259
5260 peer = peer_and_group_lookup_vty(vty, pstr);
5261 if (!peer)
5262 return CMD_WARNING_CONFIG_FAILED;
5263
5264 /* Check filter direction. */
5265 direct = strmatch(inout, "in") ? FILTER_IN : FILTER_OUT;
5266 ret = peer_distribute_set(peer, bgp_node_afi(vty), bgp_node_safi(vty),
5267 direct, acl);
5268
5269 return bgp_vty_return(vty, ret);
5270 }
5271
5272 ALIAS_HIDDEN(
5273 neighbor_distribute_list, neighbor_distribute_list_hidden_cmd,
5274 "neighbor <A.B.C.D|X:X::X:X|WORD> distribute-list <(1-199)|(1300-2699)|WORD> <in|out>",
5275 NEIGHBOR_STR NEIGHBOR_ADDR_STR2
5276 "Filter updates to/from this neighbor\n"
5277 "IP access-list number\n"
5278 "IP access-list number (expanded range)\n"
5279 "IP Access-list name\n"
5280 "Filter incoming updates\n"
5281 "Filter outgoing updates\n")
5282
5283 DEFUN (no_neighbor_distribute_list,
5284 no_neighbor_distribute_list_cmd,
5285 "no neighbor <A.B.C.D|X:X::X:X|WORD> distribute-list <(1-199)|(1300-2699)|WORD> <in|out>",
5286 NO_STR
5287 NEIGHBOR_STR
5288 NEIGHBOR_ADDR_STR2
5289 "Filter updates to/from this neighbor\n"
5290 "IP access-list number\n"
5291 "IP access-list number (expanded range)\n"
5292 "IP Access-list name\n"
5293 "Filter incoming updates\n"
5294 "Filter outgoing updates\n")
5295 {
5296 int idx_peer = 2;
5297 int direct, ret;
5298 struct peer *peer;
5299
5300 const char *pstr = argv[idx_peer]->arg;
5301 const char *inout = argv[argc - 1]->text;
5302
5303 peer = peer_and_group_lookup_vty(vty, pstr);
5304 if (!peer)
5305 return CMD_WARNING_CONFIG_FAILED;
5306
5307 /* Check filter direction. */
5308 direct = strmatch(inout, "in") ? FILTER_IN : FILTER_OUT;
5309 ret = peer_distribute_unset(peer, bgp_node_afi(vty), bgp_node_safi(vty),
5310 direct);
5311
5312 return bgp_vty_return(vty, ret);
5313 }
5314
5315 ALIAS_HIDDEN(
5316 no_neighbor_distribute_list, no_neighbor_distribute_list_hidden_cmd,
5317 "no neighbor <A.B.C.D|X:X::X:X|WORD> distribute-list <(1-199)|(1300-2699)|WORD> <in|out>",
5318 NO_STR NEIGHBOR_STR NEIGHBOR_ADDR_STR2
5319 "Filter updates to/from this neighbor\n"
5320 "IP access-list number\n"
5321 "IP access-list number (expanded range)\n"
5322 "IP Access-list name\n"
5323 "Filter incoming updates\n"
5324 "Filter outgoing updates\n")
5325
5326 /* Set prefix list to the peer. */
5327 static int peer_prefix_list_set_vty(struct vty *vty, const char *ip_str,
5328 afi_t afi, safi_t safi,
5329 const char *name_str,
5330 const char *direct_str)
5331 {
5332 int ret;
5333 struct peer *peer;
5334 int direct = FILTER_IN;
5335
5336 peer = peer_and_group_lookup_vty(vty, ip_str);
5337 if (!peer)
5338 return CMD_WARNING_CONFIG_FAILED;
5339
5340 /* Check filter direction. */
5341 if (strncmp(direct_str, "i", 1) == 0)
5342 direct = FILTER_IN;
5343 else if (strncmp(direct_str, "o", 1) == 0)
5344 direct = FILTER_OUT;
5345
5346 ret = peer_prefix_list_set(peer, afi, safi, direct, name_str);
5347
5348 return bgp_vty_return(vty, ret);
5349 }
5350
5351 static int peer_prefix_list_unset_vty(struct vty *vty, const char *ip_str,
5352 afi_t afi, safi_t safi,
5353 const char *direct_str)
5354 {
5355 int ret;
5356 struct peer *peer;
5357 int direct = FILTER_IN;
5358
5359 peer = peer_and_group_lookup_vty(vty, ip_str);
5360 if (!peer)
5361 return CMD_WARNING_CONFIG_FAILED;
5362
5363 /* Check filter direction. */
5364 if (strncmp(direct_str, "i", 1) == 0)
5365 direct = FILTER_IN;
5366 else if (strncmp(direct_str, "o", 1) == 0)
5367 direct = FILTER_OUT;
5368
5369 ret = peer_prefix_list_unset(peer, afi, safi, direct);
5370
5371 return bgp_vty_return(vty, ret);
5372 }
5373
5374 DEFUN (neighbor_prefix_list,
5375 neighbor_prefix_list_cmd,
5376 "neighbor <A.B.C.D|X:X::X:X|WORD> prefix-list WORD <in|out>",
5377 NEIGHBOR_STR
5378 NEIGHBOR_ADDR_STR2
5379 "Filter updates to/from this neighbor\n"
5380 "Name of a prefix list\n"
5381 "Filter incoming updates\n"
5382 "Filter outgoing updates\n")
5383 {
5384 int idx_peer = 1;
5385 int idx_word = 3;
5386 int idx_in_out = 4;
5387 return peer_prefix_list_set_vty(
5388 vty, argv[idx_peer]->arg, bgp_node_afi(vty), bgp_node_safi(vty),
5389 argv[idx_word]->arg, argv[idx_in_out]->arg);
5390 }
5391
5392 ALIAS_HIDDEN(neighbor_prefix_list, neighbor_prefix_list_hidden_cmd,
5393 "neighbor <A.B.C.D|X:X::X:X|WORD> prefix-list WORD <in|out>",
5394 NEIGHBOR_STR NEIGHBOR_ADDR_STR2
5395 "Filter updates to/from this neighbor\n"
5396 "Name of a prefix list\n"
5397 "Filter incoming updates\n"
5398 "Filter outgoing updates\n")
5399
5400 DEFUN (no_neighbor_prefix_list,
5401 no_neighbor_prefix_list_cmd,
5402 "no neighbor <A.B.C.D|X:X::X:X|WORD> prefix-list WORD <in|out>",
5403 NO_STR
5404 NEIGHBOR_STR
5405 NEIGHBOR_ADDR_STR2
5406 "Filter updates to/from this neighbor\n"
5407 "Name of a prefix list\n"
5408 "Filter incoming updates\n"
5409 "Filter outgoing updates\n")
5410 {
5411 int idx_peer = 2;
5412 int idx_in_out = 5;
5413 return peer_prefix_list_unset_vty(vty, argv[idx_peer]->arg,
5414 bgp_node_afi(vty), bgp_node_safi(vty),
5415 argv[idx_in_out]->arg);
5416 }
5417
5418 ALIAS_HIDDEN(no_neighbor_prefix_list, no_neighbor_prefix_list_hidden_cmd,
5419 "no neighbor <A.B.C.D|X:X::X:X|WORD> prefix-list WORD <in|out>",
5420 NO_STR NEIGHBOR_STR NEIGHBOR_ADDR_STR2
5421 "Filter updates to/from this neighbor\n"
5422 "Name of a prefix list\n"
5423 "Filter incoming updates\n"
5424 "Filter outgoing updates\n")
5425
5426 static int peer_aslist_set_vty(struct vty *vty, const char *ip_str, afi_t afi,
5427 safi_t safi, const char *name_str,
5428 const char *direct_str)
5429 {
5430 int ret;
5431 struct peer *peer;
5432 int direct = FILTER_IN;
5433
5434 peer = peer_and_group_lookup_vty(vty, ip_str);
5435 if (!peer)
5436 return CMD_WARNING_CONFIG_FAILED;
5437
5438 /* Check filter direction. */
5439 if (strncmp(direct_str, "i", 1) == 0)
5440 direct = FILTER_IN;
5441 else if (strncmp(direct_str, "o", 1) == 0)
5442 direct = FILTER_OUT;
5443
5444 ret = peer_aslist_set(peer, afi, safi, direct, name_str);
5445
5446 return bgp_vty_return(vty, ret);
5447 }
5448
5449 static int peer_aslist_unset_vty(struct vty *vty, const char *ip_str, afi_t afi,
5450 safi_t safi, const char *direct_str)
5451 {
5452 int ret;
5453 struct peer *peer;
5454 int direct = FILTER_IN;
5455
5456 peer = peer_and_group_lookup_vty(vty, ip_str);
5457 if (!peer)
5458 return CMD_WARNING_CONFIG_FAILED;
5459
5460 /* Check filter direction. */
5461 if (strncmp(direct_str, "i", 1) == 0)
5462 direct = FILTER_IN;
5463 else if (strncmp(direct_str, "o", 1) == 0)
5464 direct = FILTER_OUT;
5465
5466 ret = peer_aslist_unset(peer, afi, safi, direct);
5467
5468 return bgp_vty_return(vty, ret);
5469 }
5470
5471 DEFUN (neighbor_filter_list,
5472 neighbor_filter_list_cmd,
5473 "neighbor <A.B.C.D|X:X::X:X|WORD> filter-list WORD <in|out>",
5474 NEIGHBOR_STR
5475 NEIGHBOR_ADDR_STR2
5476 "Establish BGP filters\n"
5477 "AS path access-list name\n"
5478 "Filter incoming routes\n"
5479 "Filter outgoing routes\n")
5480 {
5481 int idx_peer = 1;
5482 int idx_word = 3;
5483 int idx_in_out = 4;
5484 return peer_aslist_set_vty(vty, argv[idx_peer]->arg, bgp_node_afi(vty),
5485 bgp_node_safi(vty), argv[idx_word]->arg,
5486 argv[idx_in_out]->arg);
5487 }
5488
5489 ALIAS_HIDDEN(neighbor_filter_list, neighbor_filter_list_hidden_cmd,
5490 "neighbor <A.B.C.D|X:X::X:X|WORD> filter-list WORD <in|out>",
5491 NEIGHBOR_STR NEIGHBOR_ADDR_STR2
5492 "Establish BGP filters\n"
5493 "AS path access-list name\n"
5494 "Filter incoming routes\n"
5495 "Filter outgoing routes\n")
5496
5497 DEFUN (no_neighbor_filter_list,
5498 no_neighbor_filter_list_cmd,
5499 "no neighbor <A.B.C.D|X:X::X:X|WORD> filter-list WORD <in|out>",
5500 NO_STR
5501 NEIGHBOR_STR
5502 NEIGHBOR_ADDR_STR2
5503 "Establish BGP filters\n"
5504 "AS path access-list name\n"
5505 "Filter incoming routes\n"
5506 "Filter outgoing routes\n")
5507 {
5508 int idx_peer = 2;
5509 int idx_in_out = 5;
5510 return peer_aslist_unset_vty(vty, argv[idx_peer]->arg,
5511 bgp_node_afi(vty), bgp_node_safi(vty),
5512 argv[idx_in_out]->arg);
5513 }
5514
5515 ALIAS_HIDDEN(no_neighbor_filter_list, no_neighbor_filter_list_hidden_cmd,
5516 "no neighbor <A.B.C.D|X:X::X:X|WORD> filter-list WORD <in|out>",
5517 NO_STR NEIGHBOR_STR NEIGHBOR_ADDR_STR2
5518 "Establish BGP filters\n"
5519 "AS path access-list name\n"
5520 "Filter incoming routes\n"
5521 "Filter outgoing routes\n")
5522
5523 /* Set route-map to the peer. */
5524 static int peer_route_map_set_vty(struct vty *vty, const char *ip_str,
5525 afi_t afi, safi_t safi, const char *name_str,
5526 const char *direct_str)
5527 {
5528 int ret;
5529 struct peer *peer;
5530 int direct = RMAP_IN;
5531
5532 peer = peer_and_group_lookup_vty(vty, ip_str);
5533 if (!peer)
5534 return CMD_WARNING_CONFIG_FAILED;
5535
5536 /* Check filter direction. */
5537 if (strncmp(direct_str, "in", 2) == 0)
5538 direct = RMAP_IN;
5539 else if (strncmp(direct_str, "o", 1) == 0)
5540 direct = RMAP_OUT;
5541
5542 ret = peer_route_map_set(peer, afi, safi, direct, name_str);
5543
5544 return bgp_vty_return(vty, ret);
5545 }
5546
5547 static int peer_route_map_unset_vty(struct vty *vty, const char *ip_str,
5548 afi_t afi, safi_t safi,
5549 const char *direct_str)
5550 {
5551 int ret;
5552 struct peer *peer;
5553 int direct = RMAP_IN;
5554
5555 peer = peer_and_group_lookup_vty(vty, ip_str);
5556 if (!peer)
5557 return CMD_WARNING_CONFIG_FAILED;
5558
5559 /* Check filter direction. */
5560 if (strncmp(direct_str, "in", 2) == 0)
5561 direct = RMAP_IN;
5562 else if (strncmp(direct_str, "o", 1) == 0)
5563 direct = RMAP_OUT;
5564
5565 ret = peer_route_map_unset(peer, afi, safi, direct);
5566
5567 return bgp_vty_return(vty, ret);
5568 }
5569
5570 DEFUN (neighbor_route_map,
5571 neighbor_route_map_cmd,
5572 "neighbor <A.B.C.D|X:X::X:X|WORD> route-map WORD <in|out>",
5573 NEIGHBOR_STR
5574 NEIGHBOR_ADDR_STR2
5575 "Apply route map to neighbor\n"
5576 "Name of route map\n"
5577 "Apply map to incoming routes\n"
5578 "Apply map to outbound routes\n")
5579 {
5580 int idx_peer = 1;
5581 int idx_word = 3;
5582 int idx_in_out = 4;
5583 return peer_route_map_set_vty(
5584 vty, argv[idx_peer]->arg, bgp_node_afi(vty), bgp_node_safi(vty),
5585 argv[idx_word]->arg, argv[idx_in_out]->arg);
5586 }
5587
5588 ALIAS_HIDDEN(neighbor_route_map, neighbor_route_map_hidden_cmd,
5589 "neighbor <A.B.C.D|X:X::X:X|WORD> route-map WORD <in|out>",
5590 NEIGHBOR_STR NEIGHBOR_ADDR_STR2
5591 "Apply route map to neighbor\n"
5592 "Name of route map\n"
5593 "Apply map to incoming routes\n"
5594 "Apply map to outbound routes\n")
5595
5596 DEFUN (no_neighbor_route_map,
5597 no_neighbor_route_map_cmd,
5598 "no neighbor <A.B.C.D|X:X::X:X|WORD> route-map WORD <in|out>",
5599 NO_STR
5600 NEIGHBOR_STR
5601 NEIGHBOR_ADDR_STR2
5602 "Apply route map to neighbor\n"
5603 "Name of route map\n"
5604 "Apply map to incoming routes\n"
5605 "Apply map to outbound routes\n")
5606 {
5607 int idx_peer = 2;
5608 int idx_in_out = 5;
5609 return peer_route_map_unset_vty(vty, argv[idx_peer]->arg,
5610 bgp_node_afi(vty), bgp_node_safi(vty),
5611 argv[idx_in_out]->arg);
5612 }
5613
5614 ALIAS_HIDDEN(no_neighbor_route_map, no_neighbor_route_map_hidden_cmd,
5615 "no neighbor <A.B.C.D|X:X::X:X|WORD> route-map WORD <in|out>",
5616 NO_STR NEIGHBOR_STR NEIGHBOR_ADDR_STR2
5617 "Apply route map to neighbor\n"
5618 "Name of route map\n"
5619 "Apply map to incoming routes\n"
5620 "Apply map to outbound routes\n")
5621
5622 /* Set unsuppress-map to the peer. */
5623 static int peer_unsuppress_map_set_vty(struct vty *vty, const char *ip_str,
5624 afi_t afi, safi_t safi,
5625 const char *name_str)
5626 {
5627 int ret;
5628 struct peer *peer;
5629
5630 peer = peer_and_group_lookup_vty(vty, ip_str);
5631 if (!peer)
5632 return CMD_WARNING_CONFIG_FAILED;
5633
5634 ret = peer_unsuppress_map_set(peer, afi, safi, name_str);
5635
5636 return bgp_vty_return(vty, ret);
5637 }
5638
5639 /* Unset route-map from the peer. */
5640 static int peer_unsuppress_map_unset_vty(struct vty *vty, const char *ip_str,
5641 afi_t afi, safi_t safi)
5642 {
5643 int ret;
5644 struct peer *peer;
5645
5646 peer = peer_and_group_lookup_vty(vty, ip_str);
5647 if (!peer)
5648 return CMD_WARNING_CONFIG_FAILED;
5649
5650 ret = peer_unsuppress_map_unset(peer, afi, safi);
5651
5652 return bgp_vty_return(vty, ret);
5653 }
5654
5655 DEFUN (neighbor_unsuppress_map,
5656 neighbor_unsuppress_map_cmd,
5657 "neighbor <A.B.C.D|X:X::X:X|WORD> unsuppress-map WORD",
5658 NEIGHBOR_STR
5659 NEIGHBOR_ADDR_STR2
5660 "Route-map to selectively unsuppress suppressed routes\n"
5661 "Name of route map\n")
5662 {
5663 int idx_peer = 1;
5664 int idx_word = 3;
5665 return peer_unsuppress_map_set_vty(
5666 vty, argv[idx_peer]->arg, bgp_node_afi(vty), bgp_node_safi(vty),
5667 argv[idx_word]->arg);
5668 }
5669
5670 ALIAS_HIDDEN(neighbor_unsuppress_map, neighbor_unsuppress_map_hidden_cmd,
5671 "neighbor <A.B.C.D|X:X::X:X|WORD> unsuppress-map WORD",
5672 NEIGHBOR_STR NEIGHBOR_ADDR_STR2
5673 "Route-map to selectively unsuppress suppressed routes\n"
5674 "Name of route map\n")
5675
5676 DEFUN (no_neighbor_unsuppress_map,
5677 no_neighbor_unsuppress_map_cmd,
5678 "no neighbor <A.B.C.D|X:X::X:X|WORD> unsuppress-map WORD",
5679 NO_STR
5680 NEIGHBOR_STR
5681 NEIGHBOR_ADDR_STR2
5682 "Route-map to selectively unsuppress suppressed routes\n"
5683 "Name of route map\n")
5684 {
5685 int idx_peer = 2;
5686 return peer_unsuppress_map_unset_vty(vty, argv[idx_peer]->arg,
5687 bgp_node_afi(vty),
5688 bgp_node_safi(vty));
5689 }
5690
5691 ALIAS_HIDDEN(no_neighbor_unsuppress_map, no_neighbor_unsuppress_map_hidden_cmd,
5692 "no neighbor <A.B.C.D|X:X::X:X|WORD> unsuppress-map WORD",
5693 NO_STR NEIGHBOR_STR NEIGHBOR_ADDR_STR2
5694 "Route-map to selectively unsuppress suppressed routes\n"
5695 "Name of route map\n")
5696
5697 static int peer_maximum_prefix_set_vty(struct vty *vty, const char *ip_str,
5698 afi_t afi, safi_t safi,
5699 const char *num_str,
5700 const char *threshold_str, int warning,
5701 const char *restart_str)
5702 {
5703 int ret;
5704 struct peer *peer;
5705 uint32_t max;
5706 uint8_t threshold;
5707 uint16_t restart;
5708
5709 peer = peer_and_group_lookup_vty(vty, ip_str);
5710 if (!peer)
5711 return CMD_WARNING_CONFIG_FAILED;
5712
5713 max = strtoul(num_str, NULL, 10);
5714 if (threshold_str)
5715 threshold = atoi(threshold_str);
5716 else
5717 threshold = MAXIMUM_PREFIX_THRESHOLD_DEFAULT;
5718
5719 if (restart_str)
5720 restart = atoi(restart_str);
5721 else
5722 restart = 0;
5723
5724 ret = peer_maximum_prefix_set(peer, afi, safi, max, threshold, warning,
5725 restart);
5726
5727 return bgp_vty_return(vty, ret);
5728 }
5729
5730 static int peer_maximum_prefix_unset_vty(struct vty *vty, const char *ip_str,
5731 afi_t afi, safi_t safi)
5732 {
5733 int ret;
5734 struct peer *peer;
5735
5736 peer = peer_and_group_lookup_vty(vty, ip_str);
5737 if (!peer)
5738 return CMD_WARNING_CONFIG_FAILED;
5739
5740 ret = peer_maximum_prefix_unset(peer, afi, safi);
5741
5742 return bgp_vty_return(vty, ret);
5743 }
5744
5745 /* Maximum number of prefix configuration. prefix count is different
5746 for each peer configuration. So this configuration can be set for
5747 each peer configuration. */
5748 DEFUN (neighbor_maximum_prefix,
5749 neighbor_maximum_prefix_cmd,
5750 "neighbor <A.B.C.D|X:X::X:X|WORD> maximum-prefix (1-4294967295)",
5751 NEIGHBOR_STR
5752 NEIGHBOR_ADDR_STR2
5753 "Maximum number of prefix accept from this peer\n"
5754 "maximum no. of prefix limit\n")
5755 {
5756 int idx_peer = 1;
5757 int idx_number = 3;
5758 return peer_maximum_prefix_set_vty(
5759 vty, argv[idx_peer]->arg, bgp_node_afi(vty), bgp_node_safi(vty),
5760 argv[idx_number]->arg, NULL, 0, NULL);
5761 }
5762
5763 ALIAS_HIDDEN(neighbor_maximum_prefix, neighbor_maximum_prefix_hidden_cmd,
5764 "neighbor <A.B.C.D|X:X::X:X|WORD> maximum-prefix (1-4294967295)",
5765 NEIGHBOR_STR NEIGHBOR_ADDR_STR2
5766 "Maximum number of prefix accept from this peer\n"
5767 "maximum no. of prefix limit\n")
5768
5769 DEFUN (neighbor_maximum_prefix_threshold,
5770 neighbor_maximum_prefix_threshold_cmd,
5771 "neighbor <A.B.C.D|X:X::X:X|WORD> maximum-prefix (1-4294967295) (1-100)",
5772 NEIGHBOR_STR
5773 NEIGHBOR_ADDR_STR2
5774 "Maximum number of prefix accept from this peer\n"
5775 "maximum no. of prefix limit\n"
5776 "Threshold value (%) at which to generate a warning msg\n")
5777 {
5778 int idx_peer = 1;
5779 int idx_number = 3;
5780 int idx_number_2 = 4;
5781 return peer_maximum_prefix_set_vty(
5782 vty, argv[idx_peer]->arg, bgp_node_afi(vty), bgp_node_safi(vty),
5783 argv[idx_number]->arg, argv[idx_number_2]->arg, 0, NULL);
5784 }
5785
5786 ALIAS_HIDDEN(
5787 neighbor_maximum_prefix_threshold,
5788 neighbor_maximum_prefix_threshold_hidden_cmd,
5789 "neighbor <A.B.C.D|X:X::X:X|WORD> maximum-prefix (1-4294967295) (1-100)",
5790 NEIGHBOR_STR NEIGHBOR_ADDR_STR2
5791 "Maximum number of prefix accept from this peer\n"
5792 "maximum no. of prefix limit\n"
5793 "Threshold value (%) at which to generate a warning msg\n")
5794
5795 DEFUN (neighbor_maximum_prefix_warning,
5796 neighbor_maximum_prefix_warning_cmd,
5797 "neighbor <A.B.C.D|X:X::X:X|WORD> maximum-prefix (1-4294967295) warning-only",
5798 NEIGHBOR_STR
5799 NEIGHBOR_ADDR_STR2
5800 "Maximum number of prefix accept from this peer\n"
5801 "maximum no. of prefix limit\n"
5802 "Only give warning message when limit is exceeded\n")
5803 {
5804 int idx_peer = 1;
5805 int idx_number = 3;
5806 return peer_maximum_prefix_set_vty(
5807 vty, argv[idx_peer]->arg, bgp_node_afi(vty), bgp_node_safi(vty),
5808 argv[idx_number]->arg, NULL, 1, NULL);
5809 }
5810
5811 ALIAS_HIDDEN(
5812 neighbor_maximum_prefix_warning,
5813 neighbor_maximum_prefix_warning_hidden_cmd,
5814 "neighbor <A.B.C.D|X:X::X:X|WORD> maximum-prefix (1-4294967295) warning-only",
5815 NEIGHBOR_STR NEIGHBOR_ADDR_STR2
5816 "Maximum number of prefix accept from this peer\n"
5817 "maximum no. of prefix limit\n"
5818 "Only give warning message when limit is exceeded\n")
5819
5820 DEFUN (neighbor_maximum_prefix_threshold_warning,
5821 neighbor_maximum_prefix_threshold_warning_cmd,
5822 "neighbor <A.B.C.D|X:X::X:X|WORD> maximum-prefix (1-4294967295) (1-100) warning-only",
5823 NEIGHBOR_STR
5824 NEIGHBOR_ADDR_STR2
5825 "Maximum number of prefix accept from this peer\n"
5826 "maximum no. of prefix limit\n"
5827 "Threshold value (%) at which to generate a warning msg\n"
5828 "Only give warning message when limit is exceeded\n")
5829 {
5830 int idx_peer = 1;
5831 int idx_number = 3;
5832 int idx_number_2 = 4;
5833 return peer_maximum_prefix_set_vty(
5834 vty, argv[idx_peer]->arg, bgp_node_afi(vty), bgp_node_safi(vty),
5835 argv[idx_number]->arg, argv[idx_number_2]->arg, 1, NULL);
5836 }
5837
5838 ALIAS_HIDDEN(
5839 neighbor_maximum_prefix_threshold_warning,
5840 neighbor_maximum_prefix_threshold_warning_hidden_cmd,
5841 "neighbor <A.B.C.D|X:X::X:X|WORD> maximum-prefix (1-4294967295) (1-100) warning-only",
5842 NEIGHBOR_STR NEIGHBOR_ADDR_STR2
5843 "Maximum number of prefix accept from this peer\n"
5844 "maximum no. of prefix limit\n"
5845 "Threshold value (%) at which to generate a warning msg\n"
5846 "Only give warning message when limit is exceeded\n")
5847
5848 DEFUN (neighbor_maximum_prefix_restart,
5849 neighbor_maximum_prefix_restart_cmd,
5850 "neighbor <A.B.C.D|X:X::X:X|WORD> maximum-prefix (1-4294967295) restart (1-65535)",
5851 NEIGHBOR_STR
5852 NEIGHBOR_ADDR_STR2
5853 "Maximum number of prefix accept from this peer\n"
5854 "maximum no. of prefix limit\n"
5855 "Restart bgp connection after limit is exceeded\n"
5856 "Restart interval in minutes\n")
5857 {
5858 int idx_peer = 1;
5859 int idx_number = 3;
5860 int idx_number_2 = 5;
5861 return peer_maximum_prefix_set_vty(
5862 vty, argv[idx_peer]->arg, bgp_node_afi(vty), bgp_node_safi(vty),
5863 argv[idx_number]->arg, NULL, 0, argv[idx_number_2]->arg);
5864 }
5865
5866 ALIAS_HIDDEN(
5867 neighbor_maximum_prefix_restart,
5868 neighbor_maximum_prefix_restart_hidden_cmd,
5869 "neighbor <A.B.C.D|X:X::X:X|WORD> maximum-prefix (1-4294967295) restart (1-65535)",
5870 NEIGHBOR_STR NEIGHBOR_ADDR_STR2
5871 "Maximum number of prefix accept from this peer\n"
5872 "maximum no. of prefix limit\n"
5873 "Restart bgp connection after limit is exceeded\n"
5874 "Restart interval in minutes\n")
5875
5876 DEFUN (neighbor_maximum_prefix_threshold_restart,
5877 neighbor_maximum_prefix_threshold_restart_cmd,
5878 "neighbor <A.B.C.D|X:X::X:X|WORD> maximum-prefix (1-4294967295) (1-100) restart (1-65535)",
5879 NEIGHBOR_STR
5880 NEIGHBOR_ADDR_STR2
5881 "Maximum number of prefixes to accept from this peer\n"
5882 "maximum no. of prefix limit\n"
5883 "Threshold value (%) at which to generate a warning msg\n"
5884 "Restart bgp connection after limit is exceeded\n"
5885 "Restart interval in minutes\n")
5886 {
5887 int idx_peer = 1;
5888 int idx_number = 3;
5889 int idx_number_2 = 4;
5890 int idx_number_3 = 6;
5891 return peer_maximum_prefix_set_vty(
5892 vty, argv[idx_peer]->arg, bgp_node_afi(vty), bgp_node_safi(vty),
5893 argv[idx_number]->arg, argv[idx_number_2]->arg, 0,
5894 argv[idx_number_3]->arg);
5895 }
5896
5897 ALIAS_HIDDEN(
5898 neighbor_maximum_prefix_threshold_restart,
5899 neighbor_maximum_prefix_threshold_restart_hidden_cmd,
5900 "neighbor <A.B.C.D|X:X::X:X|WORD> maximum-prefix (1-4294967295) (1-100) restart (1-65535)",
5901 NEIGHBOR_STR NEIGHBOR_ADDR_STR2
5902 "Maximum number of prefixes to accept from this peer\n"
5903 "maximum no. of prefix limit\n"
5904 "Threshold value (%) at which to generate a warning msg\n"
5905 "Restart bgp connection after limit is exceeded\n"
5906 "Restart interval in minutes\n")
5907
5908 DEFUN (no_neighbor_maximum_prefix,
5909 no_neighbor_maximum_prefix_cmd,
5910 "no neighbor <A.B.C.D|X:X::X:X|WORD> maximum-prefix [(1-4294967295) [(1-100)] [restart (1-65535)] [warning-only]]",
5911 NO_STR
5912 NEIGHBOR_STR
5913 NEIGHBOR_ADDR_STR2
5914 "Maximum number of prefixes to accept from this peer\n"
5915 "maximum no. of prefix limit\n"
5916 "Threshold value (%) at which to generate a warning msg\n"
5917 "Restart bgp connection after limit is exceeded\n"
5918 "Restart interval in minutes\n"
5919 "Only give warning message when limit is exceeded\n")
5920 {
5921 int idx_peer = 2;
5922 return peer_maximum_prefix_unset_vty(vty, argv[idx_peer]->arg,
5923 bgp_node_afi(vty),
5924 bgp_node_safi(vty));
5925 }
5926
5927 ALIAS_HIDDEN(
5928 no_neighbor_maximum_prefix, no_neighbor_maximum_prefix_hidden_cmd,
5929 "no neighbor <A.B.C.D|X:X::X:X|WORD> maximum-prefix [(1-4294967295) [(1-100)] [restart (1-65535)] [warning-only]]",
5930 NO_STR NEIGHBOR_STR NEIGHBOR_ADDR_STR2
5931 "Maximum number of prefixes to accept from this peer\n"
5932 "maximum no. of prefix limit\n"
5933 "Threshold value (%) at which to generate a warning msg\n"
5934 "Restart bgp connection after limit is exceeded\n"
5935 "Restart interval in minutes\n"
5936 "Only give warning message when limit is exceeded\n")
5937
5938
5939 /* "neighbor allowas-in" */
5940 DEFUN (neighbor_allowas_in,
5941 neighbor_allowas_in_cmd,
5942 "neighbor <A.B.C.D|X:X::X:X|WORD> allowas-in [<(1-10)|origin>]",
5943 NEIGHBOR_STR
5944 NEIGHBOR_ADDR_STR2
5945 "Accept as-path with my AS present in it\n"
5946 "Number of occurances of AS number\n"
5947 "Only accept my AS in the as-path if the route was originated in my AS\n")
5948 {
5949 int idx_peer = 1;
5950 int idx_number_origin = 3;
5951 int ret;
5952 int origin = 0;
5953 struct peer *peer;
5954 int allow_num = 0;
5955
5956 peer = peer_and_group_lookup_vty(vty, argv[idx_peer]->arg);
5957 if (!peer)
5958 return CMD_WARNING_CONFIG_FAILED;
5959
5960 if (argc <= idx_number_origin)
5961 allow_num = 3;
5962 else {
5963 if (argv[idx_number_origin]->type == WORD_TKN)
5964 origin = 1;
5965 else
5966 allow_num = atoi(argv[idx_number_origin]->arg);
5967 }
5968
5969 ret = peer_allowas_in_set(peer, bgp_node_afi(vty), bgp_node_safi(vty),
5970 allow_num, origin);
5971
5972 return bgp_vty_return(vty, ret);
5973 }
5974
5975 ALIAS_HIDDEN(
5976 neighbor_allowas_in, neighbor_allowas_in_hidden_cmd,
5977 "neighbor <A.B.C.D|X:X::X:X|WORD> allowas-in [<(1-10)|origin>]",
5978 NEIGHBOR_STR NEIGHBOR_ADDR_STR2
5979 "Accept as-path with my AS present in it\n"
5980 "Number of occurances of AS number\n"
5981 "Only accept my AS in the as-path if the route was originated in my AS\n")
5982
5983 DEFUN (no_neighbor_allowas_in,
5984 no_neighbor_allowas_in_cmd,
5985 "no neighbor <A.B.C.D|X:X::X:X|WORD> allowas-in [<(1-10)|origin>]",
5986 NO_STR
5987 NEIGHBOR_STR
5988 NEIGHBOR_ADDR_STR2
5989 "allow local ASN appears in aspath attribute\n"
5990 "Number of occurances of AS number\n"
5991 "Only accept my AS in the as-path if the route was originated in my AS\n")
5992 {
5993 int idx_peer = 2;
5994 int ret;
5995 struct peer *peer;
5996
5997 peer = peer_and_group_lookup_vty(vty, argv[idx_peer]->arg);
5998 if (!peer)
5999 return CMD_WARNING_CONFIG_FAILED;
6000
6001 ret = peer_allowas_in_unset(peer, bgp_node_afi(vty),
6002 bgp_node_safi(vty));
6003
6004 return bgp_vty_return(vty, ret);
6005 }
6006
6007 ALIAS_HIDDEN(
6008 no_neighbor_allowas_in, no_neighbor_allowas_in_hidden_cmd,
6009 "no neighbor <A.B.C.D|X:X::X:X|WORD> allowas-in [<(1-10)|origin>]",
6010 NO_STR NEIGHBOR_STR NEIGHBOR_ADDR_STR2
6011 "allow local ASN appears in aspath attribute\n"
6012 "Number of occurances of AS number\n"
6013 "Only accept my AS in the as-path if the route was originated in my AS\n")
6014
6015 DEFUN (neighbor_ttl_security,
6016 neighbor_ttl_security_cmd,
6017 "neighbor <A.B.C.D|X:X::X:X|WORD> ttl-security hops (1-254)",
6018 NEIGHBOR_STR
6019 NEIGHBOR_ADDR_STR2
6020 "BGP ttl-security parameters\n"
6021 "Specify the maximum number of hops to the BGP peer\n"
6022 "Number of hops to BGP peer\n")
6023 {
6024 int idx_peer = 1;
6025 int idx_number = 4;
6026 struct peer *peer;
6027 int gtsm_hops;
6028
6029 peer = peer_and_group_lookup_vty(vty, argv[idx_peer]->arg);
6030 if (!peer)
6031 return CMD_WARNING_CONFIG_FAILED;
6032
6033 gtsm_hops = strtoul(argv[idx_number]->arg, NULL, 10);
6034
6035 /*
6036 * If 'neighbor swpX', then this is for directly connected peers,
6037 * we should not accept a ttl-security hops value greater than 1.
6038 */
6039 if (peer->conf_if && (gtsm_hops > 1)) {
6040 vty_out(vty,
6041 "%s is directly connected peer, hops cannot exceed 1\n",
6042 argv[idx_peer]->arg);
6043 return CMD_WARNING_CONFIG_FAILED;
6044 }
6045
6046 return bgp_vty_return(vty, peer_ttl_security_hops_set(peer, gtsm_hops));
6047 }
6048
6049 DEFUN (no_neighbor_ttl_security,
6050 no_neighbor_ttl_security_cmd,
6051 "no neighbor <A.B.C.D|X:X::X:X|WORD> ttl-security hops (1-254)",
6052 NO_STR
6053 NEIGHBOR_STR
6054 NEIGHBOR_ADDR_STR2
6055 "BGP ttl-security parameters\n"
6056 "Specify the maximum number of hops to the BGP peer\n"
6057 "Number of hops to BGP peer\n")
6058 {
6059 int idx_peer = 2;
6060 struct peer *peer;
6061
6062 peer = peer_and_group_lookup_vty(vty, argv[idx_peer]->arg);
6063 if (!peer)
6064 return CMD_WARNING_CONFIG_FAILED;
6065
6066 return bgp_vty_return(vty, peer_ttl_security_hops_unset(peer));
6067 }
6068
6069 DEFUN (neighbor_addpath_tx_all_paths,
6070 neighbor_addpath_tx_all_paths_cmd,
6071 "neighbor <A.B.C.D|X:X::X:X|WORD> addpath-tx-all-paths",
6072 NEIGHBOR_STR
6073 NEIGHBOR_ADDR_STR2
6074 "Use addpath to advertise all paths to a neighbor\n")
6075 {
6076 int idx_peer = 1;
6077 struct peer *peer;
6078
6079 peer = peer_and_group_lookup_vty(vty, argv[idx_peer]->arg);
6080 if (!peer)
6081 return CMD_WARNING_CONFIG_FAILED;
6082
6083 return peer_af_flag_set_vty(vty, argv[idx_peer]->arg, bgp_node_afi(vty),
6084 bgp_node_safi(vty),
6085 PEER_FLAG_ADDPATH_TX_ALL_PATHS);
6086 }
6087
6088 ALIAS_HIDDEN(neighbor_addpath_tx_all_paths,
6089 neighbor_addpath_tx_all_paths_hidden_cmd,
6090 "neighbor <A.B.C.D|X:X::X:X|WORD> addpath-tx-all-paths",
6091 NEIGHBOR_STR NEIGHBOR_ADDR_STR2
6092 "Use addpath to advertise all paths to a neighbor\n")
6093
6094 DEFUN (no_neighbor_addpath_tx_all_paths,
6095 no_neighbor_addpath_tx_all_paths_cmd,
6096 "no neighbor <A.B.C.D|X:X::X:X|WORD> addpath-tx-all-paths",
6097 NO_STR
6098 NEIGHBOR_STR
6099 NEIGHBOR_ADDR_STR2
6100 "Use addpath to advertise all paths to a neighbor\n")
6101 {
6102 int idx_peer = 2;
6103 return peer_af_flag_unset_vty(vty, argv[idx_peer]->arg,
6104 bgp_node_afi(vty), bgp_node_safi(vty),
6105 PEER_FLAG_ADDPATH_TX_ALL_PATHS);
6106 }
6107
6108 ALIAS_HIDDEN(no_neighbor_addpath_tx_all_paths,
6109 no_neighbor_addpath_tx_all_paths_hidden_cmd,
6110 "no neighbor <A.B.C.D|X:X::X:X|WORD> addpath-tx-all-paths",
6111 NO_STR NEIGHBOR_STR NEIGHBOR_ADDR_STR2
6112 "Use addpath to advertise all paths to a neighbor\n")
6113
6114 DEFUN (neighbor_addpath_tx_bestpath_per_as,
6115 neighbor_addpath_tx_bestpath_per_as_cmd,
6116 "neighbor <A.B.C.D|X:X::X:X|WORD> addpath-tx-bestpath-per-AS",
6117 NEIGHBOR_STR
6118 NEIGHBOR_ADDR_STR2
6119 "Use addpath to advertise the bestpath per each neighboring AS\n")
6120 {
6121 int idx_peer = 1;
6122 struct peer *peer;
6123
6124 peer = peer_and_group_lookup_vty(vty, argv[idx_peer]->arg);
6125 if (!peer)
6126 return CMD_WARNING_CONFIG_FAILED;
6127
6128 return peer_af_flag_set_vty(vty, argv[idx_peer]->arg, bgp_node_afi(vty),
6129 bgp_node_safi(vty),
6130 PEER_FLAG_ADDPATH_TX_BESTPATH_PER_AS);
6131 }
6132
6133 ALIAS_HIDDEN(neighbor_addpath_tx_bestpath_per_as,
6134 neighbor_addpath_tx_bestpath_per_as_hidden_cmd,
6135 "neighbor <A.B.C.D|X:X::X:X|WORD> addpath-tx-bestpath-per-AS",
6136 NEIGHBOR_STR NEIGHBOR_ADDR_STR2
6137 "Use addpath to advertise the bestpath per each neighboring AS\n")
6138
6139 DEFUN (no_neighbor_addpath_tx_bestpath_per_as,
6140 no_neighbor_addpath_tx_bestpath_per_as_cmd,
6141 "no neighbor <A.B.C.D|X:X::X:X|WORD> addpath-tx-bestpath-per-AS",
6142 NO_STR
6143 NEIGHBOR_STR
6144 NEIGHBOR_ADDR_STR2
6145 "Use addpath to advertise the bestpath per each neighboring AS\n")
6146 {
6147 int idx_peer = 2;
6148 return peer_af_flag_unset_vty(vty, argv[idx_peer]->arg,
6149 bgp_node_afi(vty), bgp_node_safi(vty),
6150 PEER_FLAG_ADDPATH_TX_BESTPATH_PER_AS);
6151 }
6152
6153 ALIAS_HIDDEN(no_neighbor_addpath_tx_bestpath_per_as,
6154 no_neighbor_addpath_tx_bestpath_per_as_hidden_cmd,
6155 "no neighbor <A.B.C.D|X:X::X:X|WORD> addpath-tx-bestpath-per-AS",
6156 NO_STR NEIGHBOR_STR NEIGHBOR_ADDR_STR2
6157 "Use addpath to advertise the bestpath per each neighboring AS\n")
6158
6159 static int set_ecom_list(struct vty *vty, int argc, struct cmd_token **argv,
6160 struct ecommunity **list)
6161 {
6162 struct ecommunity *ecom = NULL;
6163 struct ecommunity *ecomadd;
6164
6165 for (; argc; --argc, ++argv) {
6166
6167 ecomadd = ecommunity_str2com(argv[0]->arg,
6168 ECOMMUNITY_ROUTE_TARGET, 0);
6169 if (!ecomadd) {
6170 vty_out(vty, "Malformed community-list value\n");
6171 if (ecom)
6172 ecommunity_free(&ecom);
6173 return CMD_WARNING_CONFIG_FAILED;
6174 }
6175
6176 if (ecom) {
6177 ecommunity_merge(ecom, ecomadd);
6178 ecommunity_free(&ecomadd);
6179 } else {
6180 ecom = ecomadd;
6181 }
6182 }
6183
6184 if (*list) {
6185 ecommunity_free(&*list);
6186 }
6187 *list = ecom;
6188
6189 return CMD_SUCCESS;
6190 }
6191
6192 /*
6193 * v2vimport is true if we are handling a `import vrf ...` command
6194 */
6195 static afi_t vpn_policy_getafi(struct vty *vty, struct bgp *bgp, bool v2vimport)
6196 {
6197 afi_t afi;
6198
6199 switch (vty->node) {
6200 case BGP_IPV4_NODE:
6201 afi = AFI_IP;
6202 break;
6203 case BGP_IPV6_NODE:
6204 afi = AFI_IP6;
6205 break;
6206 default:
6207 vty_out(vty,
6208 "%% context error: valid only in address-family <ipv4|ipv6> unicast block\n");
6209 return AFI_MAX;
6210 }
6211
6212 if (!v2vimport) {
6213 if (CHECK_FLAG(bgp->af_flags[afi][SAFI_UNICAST],
6214 BGP_CONFIG_VRF_TO_VRF_IMPORT)
6215 || CHECK_FLAG(bgp->af_flags[afi][SAFI_UNICAST],
6216 BGP_CONFIG_VRF_TO_VRF_EXPORT)) {
6217 vty_out(vty,
6218 "%% error: Please unconfigure import vrf commands before using vpn commands\n");
6219 return AFI_MAX;
6220 }
6221 } else {
6222 if (CHECK_FLAG(bgp->af_flags[afi][SAFI_UNICAST],
6223 BGP_CONFIG_VRF_TO_MPLSVPN_EXPORT)
6224 || CHECK_FLAG(bgp->af_flags[afi][SAFI_UNICAST],
6225 BGP_CONFIG_MPLSVPN_TO_VRF_IMPORT)) {
6226 vty_out(vty,
6227 "%% error: Please unconfigure vpn to vrf commands before using import vrf commands\n");
6228 return AFI_MAX;
6229 }
6230 }
6231 return afi;
6232 }
6233
6234 DEFPY (af_rd_vpn_export,
6235 af_rd_vpn_export_cmd,
6236 "[no] rd vpn export ASN:NN_OR_IP-ADDRESS:NN$rd_str",
6237 NO_STR
6238 "Specify route distinguisher\n"
6239 "Between current address-family and vpn\n"
6240 "For routes leaked from current address-family to vpn\n"
6241 "Route Distinguisher (<as-number>:<number> | <ip-address>:<number>)\n")
6242 {
6243 VTY_DECLVAR_CONTEXT(bgp, bgp);
6244 struct prefix_rd prd;
6245 int ret;
6246 afi_t afi;
6247 int idx = 0;
6248 int yes = 1;
6249
6250 if (argv_find(argv, argc, "no", &idx))
6251 yes = 0;
6252
6253 if (yes) {
6254 ret = str2prefix_rd(rd_str, &prd);
6255 if (!ret) {
6256 vty_out(vty, "%% Malformed rd\n");
6257 return CMD_WARNING_CONFIG_FAILED;
6258 }
6259 }
6260
6261 afi = vpn_policy_getafi(vty, bgp, false);
6262 if (afi == AFI_MAX)
6263 return CMD_WARNING_CONFIG_FAILED;
6264
6265 /*
6266 * pre-change: un-export vpn routes (vpn->vrf routes unaffected)
6267 */
6268 vpn_leak_prechange(BGP_VPN_POLICY_DIR_TOVPN, afi,
6269 bgp_get_default(), bgp);
6270
6271 if (yes) {
6272 bgp->vpn_policy[afi].tovpn_rd = prd;
6273 SET_FLAG(bgp->vpn_policy[afi].flags,
6274 BGP_VPN_POLICY_TOVPN_RD_SET);
6275 } else {
6276 UNSET_FLAG(bgp->vpn_policy[afi].flags,
6277 BGP_VPN_POLICY_TOVPN_RD_SET);
6278 }
6279
6280 /* post-change: re-export vpn routes */
6281 vpn_leak_postchange(BGP_VPN_POLICY_DIR_TOVPN, afi,
6282 bgp_get_default(), bgp);
6283
6284 return CMD_SUCCESS;
6285 }
6286
6287 ALIAS (af_rd_vpn_export,
6288 af_no_rd_vpn_export_cmd,
6289 "no rd vpn export",
6290 NO_STR
6291 "Specify route distinguisher\n"
6292 "Between current address-family and vpn\n"
6293 "For routes leaked from current address-family to vpn\n")
6294
6295 DEFPY (af_label_vpn_export,
6296 af_label_vpn_export_cmd,
6297 "[no] label vpn export <(0-1048575)$label_val|auto$label_auto>",
6298 NO_STR
6299 "label value for VRF\n"
6300 "Between current address-family and vpn\n"
6301 "For routes leaked from current address-family to vpn\n"
6302 "Label Value <0-1048575>\n"
6303 "Automatically assign a label\n")
6304 {
6305 VTY_DECLVAR_CONTEXT(bgp, bgp);
6306 mpls_label_t label = MPLS_LABEL_NONE;
6307 afi_t afi;
6308 int idx = 0;
6309 int yes = 1;
6310
6311 if (argv_find(argv, argc, "no", &idx))
6312 yes = 0;
6313
6314 if (yes) {
6315 if (!label_auto)
6316 label = label_val; /* parser should force unsigned */
6317 }
6318
6319 afi = vpn_policy_getafi(vty, bgp, false);
6320 if (afi == AFI_MAX)
6321 return CMD_WARNING_CONFIG_FAILED;
6322
6323
6324 if (label_auto && CHECK_FLAG(bgp->vpn_policy[afi].flags,
6325 BGP_VPN_POLICY_TOVPN_LABEL_AUTO))
6326 /* no change */
6327 return CMD_SUCCESS;
6328
6329 /*
6330 * pre-change: un-export vpn routes (vpn->vrf routes unaffected)
6331 */
6332 vpn_leak_prechange(BGP_VPN_POLICY_DIR_TOVPN, afi,
6333 bgp_get_default(), bgp);
6334
6335 if (!label_auto && CHECK_FLAG(bgp->vpn_policy[afi].flags,
6336 BGP_VPN_POLICY_TOVPN_LABEL_AUTO)) {
6337
6338 if (bgp->vpn_policy[afi].tovpn_label != MPLS_LABEL_NONE) {
6339
6340 /*
6341 * label has previously been automatically
6342 * assigned by labelpool: release it
6343 *
6344 * NB if tovpn_label == MPLS_LABEL_NONE it
6345 * means the automatic assignment is in flight
6346 * and therefore the labelpool callback must
6347 * detect that the auto label is not needed.
6348 */
6349
6350 bgp_lp_release(LP_TYPE_VRF,
6351 &bgp->vpn_policy[afi],
6352 bgp->vpn_policy[afi].tovpn_label);
6353 }
6354 UNSET_FLAG(bgp->vpn_policy[afi].flags,
6355 BGP_VPN_POLICY_TOVPN_LABEL_AUTO);
6356 }
6357
6358 bgp->vpn_policy[afi].tovpn_label = label;
6359 if (label_auto) {
6360 SET_FLAG(bgp->vpn_policy[afi].flags,
6361 BGP_VPN_POLICY_TOVPN_LABEL_AUTO);
6362 bgp_lp_get(LP_TYPE_VRF, &bgp->vpn_policy[afi],
6363 vpn_leak_label_callback);
6364 }
6365
6366 /* post-change: re-export vpn routes */
6367 vpn_leak_postchange(BGP_VPN_POLICY_DIR_TOVPN, afi,
6368 bgp_get_default(), bgp);
6369
6370 return CMD_SUCCESS;
6371 }
6372
6373 ALIAS (af_label_vpn_export,
6374 af_no_label_vpn_export_cmd,
6375 "no label vpn export",
6376 NO_STR
6377 "label value for VRF\n"
6378 "Between current address-family and vpn\n"
6379 "For routes leaked from current address-family to vpn\n")
6380
6381 DEFPY (af_nexthop_vpn_export,
6382 af_nexthop_vpn_export_cmd,
6383 "[no] nexthop vpn export <A.B.C.D|X:X::X:X>$nexthop_str",
6384 NO_STR
6385 "Specify next hop to use for VRF advertised prefixes\n"
6386 "Between current address-family and vpn\n"
6387 "For routes leaked from current address-family to vpn\n"
6388 "IPv4 prefix\n"
6389 "IPv6 prefix\n")
6390 {
6391 VTY_DECLVAR_CONTEXT(bgp, bgp);
6392 afi_t afi;
6393 struct prefix p;
6394 int idx = 0;
6395 int yes = 1;
6396
6397 if (argv_find(argv, argc, "no", &idx))
6398 yes = 0;
6399
6400 if (yes) {
6401 if (!sockunion2hostprefix(nexthop_str, &p))
6402 return CMD_WARNING_CONFIG_FAILED;
6403 }
6404
6405 afi = vpn_policy_getafi(vty, bgp, false);
6406 if (afi == AFI_MAX)
6407 return CMD_WARNING_CONFIG_FAILED;
6408
6409 /*
6410 * pre-change: un-export vpn routes (vpn->vrf routes unaffected)
6411 */
6412 vpn_leak_prechange(BGP_VPN_POLICY_DIR_TOVPN, afi,
6413 bgp_get_default(), bgp);
6414
6415 if (yes) {
6416 bgp->vpn_policy[afi].tovpn_nexthop = p;
6417 SET_FLAG(bgp->vpn_policy[afi].flags,
6418 BGP_VPN_POLICY_TOVPN_NEXTHOP_SET);
6419 } else {
6420 UNSET_FLAG(bgp->vpn_policy[afi].flags,
6421 BGP_VPN_POLICY_TOVPN_NEXTHOP_SET);
6422 }
6423
6424 /* post-change: re-export vpn routes */
6425 vpn_leak_postchange(BGP_VPN_POLICY_DIR_TOVPN, afi,
6426 bgp_get_default(), bgp);
6427
6428 return CMD_SUCCESS;
6429 }
6430
6431 ALIAS (af_nexthop_vpn_export,
6432 af_no_nexthop_vpn_export_cmd,
6433 "no nexthop vpn export",
6434 NO_STR
6435 "Specify next hop to use for VRF advertised prefixes\n"
6436 "Between current address-family and vpn\n"
6437 "For routes leaked from current address-family to vpn\n")
6438
6439 static int vpn_policy_getdirs(struct vty *vty, const char *dstr, int *dodir)
6440 {
6441 if (!strcmp(dstr, "import")) {
6442 dodir[BGP_VPN_POLICY_DIR_FROMVPN] = 1;
6443 } else if (!strcmp(dstr, "export")) {
6444 dodir[BGP_VPN_POLICY_DIR_TOVPN] = 1;
6445 } else if (!strcmp(dstr, "both")) {
6446 dodir[BGP_VPN_POLICY_DIR_FROMVPN] = 1;
6447 dodir[BGP_VPN_POLICY_DIR_TOVPN] = 1;
6448 } else {
6449 vty_out(vty, "%% direction parse error\n");
6450 return CMD_WARNING_CONFIG_FAILED;
6451 }
6452 return CMD_SUCCESS;
6453 }
6454
6455 DEFPY (af_rt_vpn_imexport,
6456 af_rt_vpn_imexport_cmd,
6457 "[no] <rt|route-target> vpn <import|export|both>$direction_str RTLIST...",
6458 NO_STR
6459 "Specify route target list\n"
6460 "Specify route target list\n"
6461 "Between current address-family and vpn\n"
6462 "For routes leaked from vpn to current address-family: match any\n"
6463 "For routes leaked from current address-family to vpn: set\n"
6464 "both import: match any and export: set\n"
6465 "Space separated route target list (A.B.C.D:MN|EF:OPQR|GHJK:MN)\n")
6466 {
6467 VTY_DECLVAR_CONTEXT(bgp, bgp);
6468 int ret;
6469 struct ecommunity *ecom = NULL;
6470 int dodir[BGP_VPN_POLICY_DIR_MAX] = {0};
6471 vpn_policy_direction_t dir;
6472 afi_t afi;
6473 int idx = 0;
6474 int yes = 1;
6475
6476 if (argv_find(argv, argc, "no", &idx))
6477 yes = 0;
6478
6479 afi = vpn_policy_getafi(vty, bgp, false);
6480 if (afi == AFI_MAX)
6481 return CMD_WARNING_CONFIG_FAILED;
6482
6483 ret = vpn_policy_getdirs(vty, direction_str, dodir);
6484 if (ret != CMD_SUCCESS)
6485 return ret;
6486
6487 if (yes) {
6488 if (!argv_find(argv, argc, "RTLIST", &idx)) {
6489 vty_out(vty, "%% Missing RTLIST\n");
6490 return CMD_WARNING_CONFIG_FAILED;
6491 }
6492 ret = set_ecom_list(vty, argc - idx, argv + idx, &ecom);
6493 if (ret != CMD_SUCCESS) {
6494 return ret;
6495 }
6496 }
6497
6498 for (dir = 0; dir < BGP_VPN_POLICY_DIR_MAX; ++dir) {
6499 if (!dodir[dir])
6500 continue;
6501
6502 vpn_leak_prechange(dir, afi, bgp_get_default(), bgp);
6503
6504 if (yes) {
6505 if (bgp->vpn_policy[afi].rtlist[dir])
6506 ecommunity_free(
6507 &bgp->vpn_policy[afi].rtlist[dir]);
6508 bgp->vpn_policy[afi].rtlist[dir] =
6509 ecommunity_dup(ecom);
6510 } else {
6511 if (bgp->vpn_policy[afi].rtlist[dir])
6512 ecommunity_free(
6513 &bgp->vpn_policy[afi].rtlist[dir]);
6514 bgp->vpn_policy[afi].rtlist[dir] = NULL;
6515 }
6516
6517 vpn_leak_postchange(dir, afi, bgp_get_default(), bgp);
6518 }
6519
6520 if (ecom)
6521 ecommunity_free(&ecom);
6522
6523 return CMD_SUCCESS;
6524 }
6525
6526 ALIAS (af_rt_vpn_imexport,
6527 af_no_rt_vpn_imexport_cmd,
6528 "no <rt|route-target> vpn <import|export|both>$direction_str",
6529 NO_STR
6530 "Specify route target list\n"
6531 "Specify route target list\n"
6532 "Between current address-family and vpn\n"
6533 "For routes leaked from vpn to current address-family\n"
6534 "For routes leaked from current address-family to vpn\n"
6535 "both import and export\n")
6536
6537 DEFPY (af_route_map_vpn_imexport,
6538 af_route_map_vpn_imexport_cmd,
6539 /* future: "route-map <vpn|evpn|vrf NAME> <import|export> RMAP" */
6540 "[no] route-map vpn <import|export>$direction_str RMAP$rmap_str",
6541 NO_STR
6542 "Specify route map\n"
6543 "Between current address-family and vpn\n"
6544 "For routes leaked from vpn to current address-family\n"
6545 "For routes leaked from current address-family to vpn\n"
6546 "name of route-map\n")
6547 {
6548 VTY_DECLVAR_CONTEXT(bgp, bgp);
6549 int ret;
6550 int dodir[BGP_VPN_POLICY_DIR_MAX] = {0};
6551 vpn_policy_direction_t dir;
6552 afi_t afi;
6553 int idx = 0;
6554 int yes = 1;
6555
6556 if (argv_find(argv, argc, "no", &idx))
6557 yes = 0;
6558
6559 afi = vpn_policy_getafi(vty, bgp, false);
6560 if (afi == AFI_MAX)
6561 return CMD_WARNING_CONFIG_FAILED;
6562
6563 ret = vpn_policy_getdirs(vty, direction_str, dodir);
6564 if (ret != CMD_SUCCESS)
6565 return ret;
6566
6567 for (dir = 0; dir < BGP_VPN_POLICY_DIR_MAX; ++dir) {
6568 if (!dodir[dir])
6569 continue;
6570
6571 vpn_leak_prechange(dir, afi, bgp_get_default(), bgp);
6572
6573 if (yes) {
6574 if (bgp->vpn_policy[afi].rmap_name[dir])
6575 XFREE(MTYPE_ROUTE_MAP_NAME,
6576 bgp->vpn_policy[afi].rmap_name[dir]);
6577 bgp->vpn_policy[afi].rmap_name[dir] = XSTRDUP(
6578 MTYPE_ROUTE_MAP_NAME, rmap_str);
6579 bgp->vpn_policy[afi].rmap[dir] =
6580 route_map_lookup_by_name(rmap_str);
6581 if (!bgp->vpn_policy[afi].rmap[dir])
6582 return CMD_SUCCESS;
6583 } else {
6584 if (bgp->vpn_policy[afi].rmap_name[dir])
6585 XFREE(MTYPE_ROUTE_MAP_NAME,
6586 bgp->vpn_policy[afi].rmap_name[dir]);
6587 bgp->vpn_policy[afi].rmap_name[dir] = NULL;
6588 bgp->vpn_policy[afi].rmap[dir] = NULL;
6589 }
6590
6591 vpn_leak_postchange(dir, afi, bgp_get_default(), bgp);
6592 }
6593
6594 return CMD_SUCCESS;
6595 }
6596
6597 ALIAS (af_route_map_vpn_imexport,
6598 af_no_route_map_vpn_imexport_cmd,
6599 "no route-map vpn <import|export>$direction_str",
6600 NO_STR
6601 "Specify route map\n"
6602 "Between current address-family and vpn\n"
6603 "For routes leaked from vpn to current address-family\n"
6604 "For routes leaked from current address-family to vpn\n")
6605
6606 DEFPY(af_import_vrf_route_map, af_import_vrf_route_map_cmd,
6607 "[no] import vrf route-map RMAP$rmap_str",
6608 NO_STR
6609 "Import routes from another VRF\n"
6610 "Vrf routes being filtered\n"
6611 "Specify route map\n"
6612 "name of route-map\n")
6613 {
6614 VTY_DECLVAR_CONTEXT(bgp, bgp);
6615 vpn_policy_direction_t dir = BGP_VPN_POLICY_DIR_FROMVPN;
6616 afi_t afi;
6617 int idx = 0;
6618 int yes = 1;
6619 struct bgp *bgp_default;
6620
6621 if (argv_find(argv, argc, "no", &idx))
6622 yes = 0;
6623
6624 afi = vpn_policy_getafi(vty, bgp, true);
6625 if (afi == AFI_MAX)
6626 return CMD_WARNING_CONFIG_FAILED;
6627
6628 bgp_default = bgp_get_default();
6629 if (!bgp_default) {
6630 int32_t ret;
6631 as_t as = bgp->as;
6632
6633 /* Auto-create assuming the same AS */
6634 ret = bgp_get(&bgp_default, &as, NULL,
6635 BGP_INSTANCE_TYPE_DEFAULT);
6636
6637 if (ret) {
6638 vty_out(vty,
6639 "VRF default is not configured as a bgp instance\n");
6640 return CMD_WARNING;
6641 }
6642 }
6643
6644 vpn_leak_prechange(dir, afi, bgp_get_default(), bgp);
6645
6646 if (yes) {
6647 if (bgp->vpn_policy[afi].rmap_name[dir])
6648 XFREE(MTYPE_ROUTE_MAP_NAME,
6649 bgp->vpn_policy[afi].rmap_name[dir]);
6650 bgp->vpn_policy[afi].rmap_name[dir] =
6651 XSTRDUP(MTYPE_ROUTE_MAP_NAME, rmap_str);
6652 bgp->vpn_policy[afi].rmap[dir] =
6653 route_map_lookup_by_name(rmap_str);
6654 if (!bgp->vpn_policy[afi].rmap[dir])
6655 return CMD_SUCCESS;
6656 } else {
6657 if (bgp->vpn_policy[afi].rmap_name[dir])
6658 XFREE(MTYPE_ROUTE_MAP_NAME,
6659 bgp->vpn_policy[afi].rmap_name[dir]);
6660 bgp->vpn_policy[afi].rmap_name[dir] = NULL;
6661 bgp->vpn_policy[afi].rmap[dir] = NULL;
6662 }
6663
6664 vpn_leak_postchange(dir, afi, bgp_get_default(), bgp);
6665
6666 return CMD_SUCCESS;
6667 }
6668
6669 ALIAS(af_import_vrf_route_map, af_no_import_vrf_route_map_cmd,
6670 "no import vrf route-map",
6671 NO_STR
6672 "Import routes from another VRF\n"
6673 "Vrf routes being filtered\n"
6674 "Specify route map\n")
6675
6676 DEFPY (bgp_imexport_vrf,
6677 bgp_imexport_vrf_cmd,
6678 "[no] import vrf NAME$import_name",
6679 NO_STR
6680 "Import routes from another VRF\n"
6681 "VRF to import from\n"
6682 "The name of the VRF\n")
6683 {
6684 VTY_DECLVAR_CONTEXT(bgp, bgp);
6685 struct listnode *node;
6686 struct bgp *vrf_bgp, *bgp_default;
6687 int32_t ret = 0;
6688 as_t as = bgp->as;
6689 bool remove = false;
6690 int32_t idx = 0;
6691 char *vname;
6692 enum bgp_instance_type bgp_type = BGP_INSTANCE_TYPE_VRF;
6693 safi_t safi;
6694 afi_t afi;
6695
6696 if (argv_find(argv, argc, "no", &idx))
6697 remove = true;
6698
6699 afi = vpn_policy_getafi(vty, bgp, true);
6700 if (afi == AFI_MAX)
6701 return CMD_WARNING_CONFIG_FAILED;
6702
6703 safi = bgp_node_safi(vty);
6704
6705 if (((BGP_INSTANCE_TYPE_DEFAULT == bgp->inst_type)
6706 && (strcmp(import_name, BGP_DEFAULT_NAME) == 0))
6707 || (bgp->name && (strcmp(import_name, bgp->name) == 0))) {
6708 vty_out(vty, "%% Cannot %s vrf %s into itself\n",
6709 remove ? "unimport" : "import", import_name);
6710 return CMD_WARNING;
6711 }
6712
6713 bgp_default = bgp_get_default();
6714 if (!bgp_default) {
6715 /* Auto-create assuming the same AS */
6716 ret = bgp_get(&bgp_default, &as, NULL,
6717 BGP_INSTANCE_TYPE_DEFAULT);
6718
6719 if (ret) {
6720 vty_out(vty,
6721 "VRF default is not configured as a bgp instance\n");
6722 return CMD_WARNING;
6723 }
6724 }
6725
6726 vrf_bgp = bgp_lookup_by_name(import_name);
6727 if (!vrf_bgp) {
6728 if (strcmp(import_name, BGP_DEFAULT_NAME) == 0)
6729 vrf_bgp = bgp_default;
6730 else
6731 /* Auto-create assuming the same AS */
6732 ret = bgp_get(&vrf_bgp, &as, import_name, bgp_type);
6733
6734 if (ret) {
6735 vty_out(vty,
6736 "VRF %s is not configured as a bgp instance\n",
6737 import_name);
6738 return CMD_WARNING;
6739 }
6740 }
6741
6742 if (remove) {
6743 vrf_unimport_from_vrf(bgp, vrf_bgp, afi, safi);
6744 } else {
6745 /* Already importing from "import_vrf"? */
6746 for (ALL_LIST_ELEMENTS_RO(bgp->vpn_policy[afi].import_vrf, node,
6747 vname)) {
6748 if (strcmp(vname, import_name) == 0)
6749 return CMD_WARNING;
6750 }
6751
6752 vrf_import_from_vrf(bgp, vrf_bgp, afi, safi);
6753 }
6754
6755 return CMD_SUCCESS;
6756 }
6757
6758 /* This command is valid only in a bgp vrf instance or the default instance */
6759 DEFPY (bgp_imexport_vpn,
6760 bgp_imexport_vpn_cmd,
6761 "[no] <import|export>$direction_str vpn",
6762 NO_STR
6763 "Import routes to this address-family\n"
6764 "Export routes from this address-family\n"
6765 "to/from default instance VPN RIB\n")
6766 {
6767 VTY_DECLVAR_CONTEXT(bgp, bgp);
6768 int previous_state;
6769 afi_t afi;
6770 safi_t safi;
6771 int idx = 0;
6772 int yes = 1;
6773 int flag;
6774 vpn_policy_direction_t dir;
6775
6776 if (argv_find(argv, argc, "no", &idx))
6777 yes = 0;
6778
6779 if (BGP_INSTANCE_TYPE_VRF != bgp->inst_type &&
6780 BGP_INSTANCE_TYPE_DEFAULT != bgp->inst_type) {
6781
6782 vty_out(vty, "%% import|export vpn valid only for bgp vrf or default instance\n");
6783 return CMD_WARNING_CONFIG_FAILED;
6784 }
6785
6786 afi = bgp_node_afi(vty);
6787 safi = bgp_node_safi(vty);
6788 if ((SAFI_UNICAST != safi) || ((AFI_IP != afi) && (AFI_IP6 != afi))) {
6789 vty_out(vty, "%% import|export vpn valid only for unicast ipv4|ipv6\n");
6790 return CMD_WARNING_CONFIG_FAILED;
6791 }
6792
6793 if (!strcmp(direction_str, "import")) {
6794 flag = BGP_CONFIG_MPLSVPN_TO_VRF_IMPORT;
6795 dir = BGP_VPN_POLICY_DIR_FROMVPN;
6796 } else if (!strcmp(direction_str, "export")) {
6797 flag = BGP_CONFIG_VRF_TO_MPLSVPN_EXPORT;
6798 dir = BGP_VPN_POLICY_DIR_TOVPN;
6799 } else {
6800 vty_out(vty, "%% unknown direction %s\n", direction_str);
6801 return CMD_WARNING_CONFIG_FAILED;
6802 }
6803
6804 previous_state = CHECK_FLAG(bgp->af_flags[afi][safi], flag);
6805
6806 if (yes) {
6807 SET_FLAG(bgp->af_flags[afi][safi], flag);
6808 if (!previous_state) {
6809 /* trigger export current vrf */
6810 vpn_leak_postchange(dir, afi, bgp_get_default(), bgp);
6811 }
6812 } else {
6813 if (previous_state) {
6814 /* trigger un-export current vrf */
6815 vpn_leak_prechange(dir, afi, bgp_get_default(), bgp);
6816 }
6817 UNSET_FLAG(bgp->af_flags[afi][safi], flag);
6818 }
6819
6820 return CMD_SUCCESS;
6821 }
6822
6823 DEFPY (af_routetarget_import,
6824 af_routetarget_import_cmd,
6825 "[no] <rt|route-target> redirect import RTLIST...",
6826 NO_STR
6827 "Specify route target list\n"
6828 "Specify route target list\n"
6829 "Flow-spec redirect type route target\n"
6830 "Import routes to this address-family\n"
6831 "Space separated route target list (A.B.C.D:MN|EF:OPQR|GHJK:MN)\n")
6832 {
6833 VTY_DECLVAR_CONTEXT(bgp, bgp);
6834 int ret;
6835 struct ecommunity *ecom = NULL;
6836 afi_t afi;
6837 int idx = 0;
6838 int yes = 1;
6839
6840 if (argv_find(argv, argc, "no", &idx))
6841 yes = 0;
6842
6843 afi = vpn_policy_getafi(vty, bgp, false);
6844 if (afi == AFI_MAX)
6845 return CMD_WARNING_CONFIG_FAILED;
6846
6847 if (yes) {
6848 if (!argv_find(argv, argc, "RTLIST", &idx)) {
6849 vty_out(vty, "%% Missing RTLIST\n");
6850 return CMD_WARNING_CONFIG_FAILED;
6851 }
6852 ret = set_ecom_list(vty, argc - idx, argv + idx, &ecom);
6853 if (ret != CMD_SUCCESS)
6854 return ret;
6855 }
6856
6857 if (yes) {
6858 if (bgp->vpn_policy[afi].import_redirect_rtlist)
6859 ecommunity_free(&bgp->vpn_policy[afi]
6860 .import_redirect_rtlist);
6861 bgp->vpn_policy[afi].import_redirect_rtlist =
6862 ecommunity_dup(ecom);
6863 } else {
6864 if (bgp->vpn_policy[afi].import_redirect_rtlist)
6865 ecommunity_free(&bgp->vpn_policy[afi]
6866 .import_redirect_rtlist);
6867 bgp->vpn_policy[afi].import_redirect_rtlist = NULL;
6868 }
6869
6870 if (ecom)
6871 ecommunity_free(&ecom);
6872
6873 return CMD_SUCCESS;
6874 }
6875
6876 DEFUN_NOSH (address_family_ipv4_safi,
6877 address_family_ipv4_safi_cmd,
6878 "address-family ipv4 [<unicast|multicast|vpn|labeled-unicast|flowspec>]",
6879 "Enter Address Family command mode\n"
6880 "Address Family\n"
6881 BGP_SAFI_WITH_LABEL_HELP_STR)
6882 {
6883
6884 if (argc == 3) {
6885 VTY_DECLVAR_CONTEXT(bgp, bgp);
6886 safi_t safi = bgp_vty_safi_from_str(argv[2]->text);
6887 if (bgp->inst_type != BGP_INSTANCE_TYPE_DEFAULT
6888 && safi != SAFI_UNICAST && safi != SAFI_MULTICAST
6889 && safi != SAFI_EVPN) {
6890 vty_out(vty,
6891 "Only Unicast/Multicast/EVPN SAFIs supported in non-core instances.\n");
6892 return CMD_WARNING_CONFIG_FAILED;
6893 }
6894 vty->node = bgp_node_type(AFI_IP, safi);
6895 } else
6896 vty->node = BGP_IPV4_NODE;
6897
6898 return CMD_SUCCESS;
6899 }
6900
6901 DEFUN_NOSH (address_family_ipv6_safi,
6902 address_family_ipv6_safi_cmd,
6903 "address-family ipv6 [<unicast|multicast|vpn|labeled-unicast|flowspec>]",
6904 "Enter Address Family command mode\n"
6905 "Address Family\n"
6906 BGP_SAFI_WITH_LABEL_HELP_STR)
6907 {
6908 if (argc == 3) {
6909 VTY_DECLVAR_CONTEXT(bgp, bgp);
6910 safi_t safi = bgp_vty_safi_from_str(argv[2]->text);
6911 if (bgp->inst_type != BGP_INSTANCE_TYPE_DEFAULT
6912 && safi != SAFI_UNICAST && safi != SAFI_MULTICAST
6913 && safi != SAFI_EVPN) {
6914 vty_out(vty,
6915 "Only Unicast/Multicast/EVPN SAFIs supported in non-core instances.\n");
6916 return CMD_WARNING_CONFIG_FAILED;
6917 }
6918 vty->node = bgp_node_type(AFI_IP6, safi);
6919 } else
6920 vty->node = BGP_IPV6_NODE;
6921
6922 return CMD_SUCCESS;
6923 }
6924
6925 #ifdef KEEP_OLD_VPN_COMMANDS
6926 DEFUN_NOSH (address_family_vpnv4,
6927 address_family_vpnv4_cmd,
6928 "address-family vpnv4 [unicast]",
6929 "Enter Address Family command mode\n"
6930 "Address Family\n"
6931 "Address Family modifier\n")
6932 {
6933 vty->node = BGP_VPNV4_NODE;
6934 return CMD_SUCCESS;
6935 }
6936
6937 DEFUN_NOSH (address_family_vpnv6,
6938 address_family_vpnv6_cmd,
6939 "address-family vpnv6 [unicast]",
6940 "Enter Address Family command mode\n"
6941 "Address Family\n"
6942 "Address Family modifier\n")
6943 {
6944 vty->node = BGP_VPNV6_NODE;
6945 return CMD_SUCCESS;
6946 }
6947 #endif
6948
6949 DEFUN_NOSH (address_family_evpn,
6950 address_family_evpn_cmd,
6951 "address-family l2vpn evpn",
6952 "Enter Address Family command mode\n"
6953 "Address Family\n"
6954 "Address Family modifier\n")
6955 {
6956 VTY_DECLVAR_CONTEXT(bgp, bgp);
6957 vty->node = BGP_EVPN_NODE;
6958 return CMD_SUCCESS;
6959 }
6960
6961 DEFUN_NOSH (exit_address_family,
6962 exit_address_family_cmd,
6963 "exit-address-family",
6964 "Exit from Address Family configuration mode\n")
6965 {
6966 if (vty->node == BGP_IPV4_NODE || vty->node == BGP_IPV4M_NODE
6967 || vty->node == BGP_IPV4L_NODE || vty->node == BGP_VPNV4_NODE
6968 || vty->node == BGP_IPV6_NODE || vty->node == BGP_IPV6M_NODE
6969 || vty->node == BGP_IPV6L_NODE || vty->node == BGP_VPNV6_NODE
6970 || vty->node == BGP_EVPN_NODE
6971 || vty->node == BGP_FLOWSPECV4_NODE
6972 || vty->node == BGP_FLOWSPECV6_NODE)
6973 vty->node = BGP_NODE;
6974 return CMD_SUCCESS;
6975 }
6976
6977 /* Recalculate bestpath and re-advertise a prefix */
6978 static int bgp_clear_prefix(struct vty *vty, const char *view_name,
6979 const char *ip_str, afi_t afi, safi_t safi,
6980 struct prefix_rd *prd)
6981 {
6982 int ret;
6983 struct prefix match;
6984 struct bgp_node *rn;
6985 struct bgp_node *rm;
6986 struct bgp *bgp;
6987 struct bgp_table *table;
6988 struct bgp_table *rib;
6989
6990 /* BGP structure lookup. */
6991 if (view_name) {
6992 bgp = bgp_lookup_by_name(view_name);
6993 if (bgp == NULL) {
6994 vty_out(vty, "%% Can't find BGP instance %s\n",
6995 view_name);
6996 return CMD_WARNING;
6997 }
6998 } else {
6999 bgp = bgp_get_default();
7000 if (bgp == NULL) {
7001 vty_out(vty, "%% No BGP process is configured\n");
7002 return CMD_WARNING;
7003 }
7004 }
7005
7006 /* Check IP address argument. */
7007 ret = str2prefix(ip_str, &match);
7008 if (!ret) {
7009 vty_out(vty, "%% address is malformed\n");
7010 return CMD_WARNING;
7011 }
7012
7013 match.family = afi2family(afi);
7014 rib = bgp->rib[afi][safi];
7015
7016 if (safi == SAFI_MPLS_VPN) {
7017 for (rn = bgp_table_top(rib); rn; rn = bgp_route_next(rn)) {
7018 if (prd && memcmp(rn->p.u.val, prd->val, 8) != 0)
7019 continue;
7020
7021 if ((table = rn->info) != NULL) {
7022 if ((rm = bgp_node_match(table, &match))
7023 != NULL) {
7024 if (rm->p.prefixlen
7025 == match.prefixlen) {
7026 SET_FLAG(rn->flags,
7027 BGP_NODE_USER_CLEAR);
7028 bgp_process(bgp, rm, afi, safi);
7029 }
7030 bgp_unlock_node(rm);
7031 }
7032 }
7033 }
7034 } else {
7035 if ((rn = bgp_node_match(rib, &match)) != NULL) {
7036 if (rn->p.prefixlen == match.prefixlen) {
7037 SET_FLAG(rn->flags, BGP_NODE_USER_CLEAR);
7038 bgp_process(bgp, rn, afi, safi);
7039 }
7040 bgp_unlock_node(rn);
7041 }
7042 }
7043
7044 return CMD_SUCCESS;
7045 }
7046
7047 /* one clear bgp command to rule them all */
7048 DEFUN (clear_ip_bgp_all,
7049 clear_ip_bgp_all_cmd,
7050 "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>]",
7051 CLEAR_STR
7052 IP_STR
7053 BGP_STR
7054 BGP_INSTANCE_HELP_STR
7055 BGP_AFI_HELP_STR
7056 BGP_SAFI_WITH_LABEL_HELP_STR
7057 "Clear all peers\n"
7058 "BGP neighbor address to clear\n"
7059 "BGP IPv6 neighbor to clear\n"
7060 "BGP neighbor on interface to clear\n"
7061 "Clear peers with the AS number\n"
7062 "Clear all external peers\n"
7063 "Clear all members of peer-group\n"
7064 "BGP peer-group name\n"
7065 BGP_SOFT_STR
7066 BGP_SOFT_IN_STR
7067 BGP_SOFT_OUT_STR
7068 BGP_SOFT_IN_STR
7069 "Push out prefix-list ORF and do inbound soft reconfig\n"
7070 BGP_SOFT_OUT_STR)
7071 {
7072 char *vrf = NULL;
7073
7074 afi_t afi = AFI_IP6;
7075 safi_t safi = SAFI_UNICAST;
7076 enum clear_sort clr_sort = clear_peer;
7077 enum bgp_clear_type clr_type;
7078 char *clr_arg = NULL;
7079
7080 int idx = 0;
7081
7082 /* clear [ip] bgp */
7083 if (argv_find(argv, argc, "ip", &idx))
7084 afi = AFI_IP;
7085
7086 /* [<view|vrf> VIEWVRFNAME] */
7087 if (argv_find(argv, argc, "view", &idx)
7088 || argv_find(argv, argc, "vrf", &idx)) {
7089 vrf = argv[idx + 1]->arg;
7090 idx += 2;
7091 }
7092
7093 /* ["BGP_AFI_CMD_STR" ["BGP_SAFI_CMD_STR"]] */
7094 if (argv_find_and_parse_afi(argv, argc, &idx, &afi))
7095 argv_find_and_parse_safi(argv, argc, &idx, &safi);
7096
7097 /* <*|A.B.C.D|X:X::X:X|WORD|(1-4294967295)|external|peer-group WORD> */
7098 if (argv_find(argv, argc, "*", &idx)) {
7099 clr_sort = clear_all;
7100 } else if (argv_find(argv, argc, "A.B.C.D", &idx)) {
7101 clr_sort = clear_peer;
7102 clr_arg = argv[idx]->arg;
7103 } else if (argv_find(argv, argc, "X:X::X:X", &idx)) {
7104 clr_sort = clear_peer;
7105 clr_arg = argv[idx]->arg;
7106 } else if (argv_find(argv, argc, "peer-group", &idx)) {
7107 clr_sort = clear_group;
7108 idx++;
7109 clr_arg = argv[idx]->arg;
7110 } else if (argv_find(argv, argc, "WORD", &idx)) {
7111 clr_sort = clear_peer;
7112 clr_arg = argv[idx]->arg;
7113 } else if (argv_find(argv, argc, "(1-4294967295)", &idx)) {
7114 clr_sort = clear_as;
7115 clr_arg = argv[idx]->arg;
7116 } else if (argv_find(argv, argc, "external", &idx)) {
7117 clr_sort = clear_external;
7118 }
7119
7120 /* [<soft [<in|out>]|in [prefix-filter]|out>] */
7121 if (argv_find(argv, argc, "soft", &idx)) {
7122 if (argv_find(argv, argc, "in", &idx)
7123 || argv_find(argv, argc, "out", &idx))
7124 clr_type = strmatch(argv[idx]->text, "in")
7125 ? BGP_CLEAR_SOFT_IN
7126 : BGP_CLEAR_SOFT_OUT;
7127 else
7128 clr_type = BGP_CLEAR_SOFT_BOTH;
7129 } else if (argv_find(argv, argc, "in", &idx)) {
7130 clr_type = argv_find(argv, argc, "prefix-filter", &idx)
7131 ? BGP_CLEAR_SOFT_IN_ORF_PREFIX
7132 : BGP_CLEAR_SOFT_IN;
7133 } else if (argv_find(argv, argc, "out", &idx)) {
7134 clr_type = BGP_CLEAR_SOFT_OUT;
7135 } else
7136 clr_type = BGP_CLEAR_SOFT_NONE;
7137
7138 return bgp_clear_vty(vty, vrf, afi, safi, clr_sort, clr_type, clr_arg);
7139 }
7140
7141 DEFUN (clear_ip_bgp_prefix,
7142 clear_ip_bgp_prefix_cmd,
7143 "clear [ip] bgp [<view|vrf> VIEWVRFNAME] prefix A.B.C.D/M",
7144 CLEAR_STR
7145 IP_STR
7146 BGP_STR
7147 BGP_INSTANCE_HELP_STR
7148 "Clear bestpath and re-advertise\n"
7149 "IPv4 prefix\n")
7150 {
7151 char *vrf = NULL;
7152 char *prefix = NULL;
7153
7154 int idx = 0;
7155
7156 /* [<view|vrf> VIEWVRFNAME] */
7157 if (argv_find(argv, argc, "VIEWVRFNAME", &idx))
7158 vrf = argv[idx]->arg;
7159
7160 prefix = argv[argc - 1]->arg;
7161
7162 return bgp_clear_prefix(vty, vrf, prefix, AFI_IP, SAFI_UNICAST, NULL);
7163 }
7164
7165 DEFUN (clear_bgp_ipv6_safi_prefix,
7166 clear_bgp_ipv6_safi_prefix_cmd,
7167 "clear [ip] bgp ipv6 "BGP_SAFI_CMD_STR" prefix X:X::X:X/M",
7168 CLEAR_STR
7169 IP_STR
7170 BGP_STR
7171 "Address Family\n"
7172 BGP_SAFI_HELP_STR
7173 "Clear bestpath and re-advertise\n"
7174 "IPv6 prefix\n")
7175 {
7176 int idx_safi = 0;
7177 int idx_ipv6_prefix = 0;
7178 safi_t safi = SAFI_UNICAST;
7179 char *prefix = argv_find(argv, argc, "X:X::X:X/M", &idx_ipv6_prefix) ?
7180 argv[idx_ipv6_prefix]->arg : NULL;
7181
7182 argv_find_and_parse_safi(argv, argc, &idx_safi, &safi);
7183 return bgp_clear_prefix(
7184 vty, NULL, prefix, AFI_IP6,
7185 safi, NULL);
7186 }
7187
7188 DEFUN (clear_bgp_instance_ipv6_safi_prefix,
7189 clear_bgp_instance_ipv6_safi_prefix_cmd,
7190 "clear [ip] bgp <view|vrf> VIEWVRFNAME ipv6 "BGP_SAFI_CMD_STR" prefix X:X::X:X/M",
7191 CLEAR_STR
7192 IP_STR
7193 BGP_STR
7194 BGP_INSTANCE_HELP_STR
7195 "Address Family\n"
7196 BGP_SAFI_HELP_STR
7197 "Clear bestpath and re-advertise\n"
7198 "IPv6 prefix\n")
7199 {
7200 int idx_word = 3;
7201 int idx_safi = 0;
7202 int idx_ipv6_prefix = 0;
7203 safi_t safi = SAFI_UNICAST;
7204 char *prefix = argv_find(argv, argc, "X:X::X:X/M", &idx_ipv6_prefix) ?
7205 argv[idx_ipv6_prefix]->arg : NULL;
7206 /* [<view|vrf> VIEWVRFNAME] */
7207 char *vrfview = argv_find(argv, argc, "VIEWVRFNAME", &idx_word) ?
7208 argv[idx_word]->arg : NULL;
7209
7210 argv_find_and_parse_safi(argv, argc, &idx_safi, &safi);
7211
7212 return bgp_clear_prefix(
7213 vty, vrfview, prefix,
7214 AFI_IP6, safi, NULL);
7215 }
7216
7217 DEFUN (show_bgp_views,
7218 show_bgp_views_cmd,
7219 "show [ip] bgp views",
7220 SHOW_STR
7221 IP_STR
7222 BGP_STR
7223 "Show the defined BGP views\n")
7224 {
7225 struct list *inst = bm->bgp;
7226 struct listnode *node;
7227 struct bgp *bgp;
7228
7229 if (!bgp_option_check(BGP_OPT_MULTIPLE_INSTANCE)) {
7230 vty_out(vty, "BGP Multiple Instance is not enabled\n");
7231 return CMD_WARNING;
7232 }
7233
7234 vty_out(vty, "Defined BGP views:\n");
7235 for (ALL_LIST_ELEMENTS_RO(inst, node, bgp)) {
7236 /* Skip VRFs. */
7237 if (bgp->inst_type == BGP_INSTANCE_TYPE_VRF)
7238 continue;
7239 vty_out(vty, "\t%s (AS%u)\n", bgp->name ? bgp->name : "(null)",
7240 bgp->as);
7241 }
7242
7243 return CMD_SUCCESS;
7244 }
7245
7246 DEFUN (show_bgp_vrfs,
7247 show_bgp_vrfs_cmd,
7248 "show [ip] bgp vrfs [json]",
7249 SHOW_STR
7250 IP_STR
7251 BGP_STR
7252 "Show BGP VRFs\n"
7253 JSON_STR)
7254 {
7255 char buf[ETHER_ADDR_STRLEN];
7256 struct list *inst = bm->bgp;
7257 struct listnode *node;
7258 struct bgp *bgp;
7259 uint8_t uj = use_json(argc, argv);
7260 json_object *json = NULL;
7261 json_object *json_vrfs = NULL;
7262 int count = 0;
7263
7264 if (!bgp_option_check(BGP_OPT_MULTIPLE_INSTANCE)) {
7265 vty_out(vty, "BGP Multiple Instance is not enabled\n");
7266 return CMD_WARNING;
7267 }
7268
7269 if (uj) {
7270 json = json_object_new_object();
7271 json_vrfs = json_object_new_object();
7272 }
7273
7274 for (ALL_LIST_ELEMENTS_RO(inst, node, bgp)) {
7275 const char *name, *type;
7276 struct peer *peer;
7277 struct listnode *node, *nnode;
7278 int peers_cfg, peers_estb;
7279 json_object *json_vrf = NULL;
7280
7281 /* Skip Views. */
7282 if (bgp->inst_type == BGP_INSTANCE_TYPE_VIEW)
7283 continue;
7284
7285 count++;
7286 if (!uj && count == 1)
7287 vty_out(vty,
7288 "%4s %-5s %-16s %9s %10s %-37s %-10s %-15s\n",
7289 "Type", "Id", "routerId", "#PeersVfg",
7290 "#PeersEstb", "Name", "L3-VNI", "Rmac");
7291
7292 peers_cfg = peers_estb = 0;
7293 if (uj)
7294 json_vrf = json_object_new_object();
7295
7296
7297 for (ALL_LIST_ELEMENTS(bgp->peer, node, nnode, peer)) {
7298 if (!CHECK_FLAG(peer->flags, PEER_FLAG_CONFIG_NODE))
7299 continue;
7300 peers_cfg++;
7301 if (peer->status == Established)
7302 peers_estb++;
7303 }
7304
7305 if (bgp->inst_type == BGP_INSTANCE_TYPE_DEFAULT) {
7306 name = "Default";
7307 type = "DFLT";
7308 } else {
7309 name = bgp->name;
7310 type = "VRF";
7311 }
7312
7313
7314 if (uj) {
7315 int64_t vrf_id_ui = (bgp->vrf_id == VRF_UNKNOWN)
7316 ? -1
7317 : (int64_t)bgp->vrf_id;
7318 json_object_string_add(json_vrf, "type", type);
7319 json_object_int_add(json_vrf, "vrfId", vrf_id_ui);
7320 json_object_string_add(json_vrf, "routerId",
7321 inet_ntoa(bgp->router_id));
7322 json_object_int_add(json_vrf, "numConfiguredPeers",
7323 peers_cfg);
7324 json_object_int_add(json_vrf, "numEstablishedPeers",
7325 peers_estb);
7326
7327 json_object_int_add(json_vrf, "l3vni", bgp->l3vni);
7328 json_object_string_add(
7329 json_vrf, "rmac",
7330 prefix_mac2str(&bgp->rmac, buf, sizeof(buf)));
7331 json_object_object_add(json_vrfs, name, json_vrf);
7332 } else
7333 vty_out(vty,
7334 "%4s %-5d %-16s %9u %10u %-37s %-10u %-15s\n",
7335 type,
7336 bgp->vrf_id == VRF_UNKNOWN ? -1
7337 : (int)bgp->vrf_id,
7338 inet_ntoa(bgp->router_id), peers_cfg,
7339 peers_estb, name, bgp->l3vni,
7340 prefix_mac2str(&bgp->rmac, buf, sizeof(buf)));
7341 }
7342
7343 if (uj) {
7344 json_object_object_add(json, "vrfs", json_vrfs);
7345
7346 json_object_int_add(json, "totalVrfs", count);
7347
7348 vty_out(vty, "%s\n", json_object_to_json_string_ext(
7349 json, JSON_C_TO_STRING_PRETTY));
7350 json_object_free(json);
7351 } else {
7352 if (count)
7353 vty_out(vty,
7354 "\nTotal number of VRFs (including default): %d\n",
7355 count);
7356 }
7357
7358 return CMD_SUCCESS;
7359 }
7360
7361 static void show_address_entry(struct hash_backet *backet, void *args)
7362 {
7363 struct vty *vty = (struct vty *)args;
7364 struct bgp_addr *addr = (struct bgp_addr *)backet->data;
7365
7366 vty_out(vty, "addr: %s, count: %d\n", inet_ntoa(addr->addr),
7367 addr->refcnt);
7368 }
7369
7370 static void show_tip_entry(struct hash_backet *backet, void *args)
7371 {
7372 struct vty *vty = (struct vty *)args;
7373 struct tip_addr *tip = (struct tip_addr *)backet->data;
7374
7375 vty_out(vty, "addr: %s, count: %d\n", inet_ntoa(tip->addr),
7376 tip->refcnt);
7377 }
7378
7379 static void bgp_show_martian_nexthops(struct vty *vty, struct bgp *bgp)
7380 {
7381 vty_out(vty, "self nexthop database:\n");
7382 hash_iterate(bgp->address_hash,
7383 (void (*)(struct hash_backet *, void *))show_address_entry,
7384 vty);
7385
7386 vty_out(vty, "Tunnel-ip database:\n");
7387 hash_iterate(bgp->tip_hash,
7388 (void (*)(struct hash_backet *, void *))show_tip_entry,
7389 vty);
7390 }
7391
7392 DEFUN(show_bgp_martian_nexthop_db, show_bgp_martian_nexthop_db_cmd,
7393 "show bgp [<view|vrf> VIEWVRFNAME] martian next-hop",
7394 SHOW_STR BGP_STR BGP_INSTANCE_HELP_STR
7395 "martian next-hops\n"
7396 "martian next-hop database\n")
7397 {
7398 struct bgp *bgp = NULL;
7399 int idx = 0;
7400
7401 if (argv_find(argv, argc, "view", &idx)
7402 || argv_find(argv, argc, "vrf", &idx))
7403 bgp = bgp_lookup_by_name(argv[idx + 1]->arg);
7404 else
7405 bgp = bgp_get_default();
7406
7407 if (!bgp) {
7408 vty_out(vty, "%% No BGP process is configured\n");
7409 return CMD_WARNING;
7410 }
7411 bgp_show_martian_nexthops(vty, bgp);
7412
7413 return CMD_SUCCESS;
7414 }
7415
7416 DEFUN (show_bgp_memory,
7417 show_bgp_memory_cmd,
7418 "show [ip] bgp memory",
7419 SHOW_STR
7420 IP_STR
7421 BGP_STR
7422 "Global BGP memory statistics\n")
7423 {
7424 char memstrbuf[MTYPE_MEMSTR_LEN];
7425 unsigned long count;
7426
7427 /* RIB related usage stats */
7428 count = mtype_stats_alloc(MTYPE_BGP_NODE);
7429 vty_out(vty, "%ld RIB nodes, using %s of memory\n", count,
7430 mtype_memstr(memstrbuf, sizeof(memstrbuf),
7431 count * sizeof(struct bgp_node)));
7432
7433 count = mtype_stats_alloc(MTYPE_BGP_ROUTE);
7434 vty_out(vty, "%ld BGP routes, using %s of memory\n", count,
7435 mtype_memstr(memstrbuf, sizeof(memstrbuf),
7436 count * sizeof(struct bgp_info)));
7437 if ((count = mtype_stats_alloc(MTYPE_BGP_ROUTE_EXTRA)))
7438 vty_out(vty, "%ld BGP route ancillaries, using %s of memory\n",
7439 count,
7440 mtype_memstr(memstrbuf, sizeof(memstrbuf),
7441 count * sizeof(struct bgp_info_extra)));
7442
7443 if ((count = mtype_stats_alloc(MTYPE_BGP_STATIC)))
7444 vty_out(vty, "%ld Static routes, using %s of memory\n", count,
7445 mtype_memstr(memstrbuf, sizeof(memstrbuf),
7446 count * sizeof(struct bgp_static)));
7447
7448 if ((count = mtype_stats_alloc(MTYPE_BGP_PACKET)))
7449 vty_out(vty, "%ld Packets, using %s of memory\n", count,
7450 mtype_memstr(memstrbuf, sizeof(memstrbuf),
7451 count * sizeof(struct bpacket)));
7452
7453 /* Adj-In/Out */
7454 if ((count = mtype_stats_alloc(MTYPE_BGP_ADJ_IN)))
7455 vty_out(vty, "%ld Adj-In entries, using %s of memory\n", count,
7456 mtype_memstr(memstrbuf, sizeof(memstrbuf),
7457 count * sizeof(struct bgp_adj_in)));
7458 if ((count = mtype_stats_alloc(MTYPE_BGP_ADJ_OUT)))
7459 vty_out(vty, "%ld Adj-Out entries, using %s of memory\n", count,
7460 mtype_memstr(memstrbuf, sizeof(memstrbuf),
7461 count * sizeof(struct bgp_adj_out)));
7462
7463 if ((count = mtype_stats_alloc(MTYPE_BGP_NEXTHOP_CACHE)))
7464 vty_out(vty, "%ld Nexthop cache entries, using %s of memory\n",
7465 count,
7466 mtype_memstr(memstrbuf, sizeof(memstrbuf),
7467 count * sizeof(struct bgp_nexthop_cache)));
7468
7469 if ((count = mtype_stats_alloc(MTYPE_BGP_DAMP_INFO)))
7470 vty_out(vty, "%ld Dampening entries, using %s of memory\n",
7471 count,
7472 mtype_memstr(memstrbuf, sizeof(memstrbuf),
7473 count * sizeof(struct bgp_damp_info)));
7474
7475 /* Attributes */
7476 count = attr_count();
7477 vty_out(vty, "%ld BGP attributes, using %s of memory\n", count,
7478 mtype_memstr(memstrbuf, sizeof(memstrbuf),
7479 count * sizeof(struct attr)));
7480
7481 if ((count = attr_unknown_count()))
7482 vty_out(vty, "%ld unknown attributes\n", count);
7483
7484 /* AS_PATH attributes */
7485 count = aspath_count();
7486 vty_out(vty, "%ld BGP AS-PATH entries, using %s of memory\n", count,
7487 mtype_memstr(memstrbuf, sizeof(memstrbuf),
7488 count * sizeof(struct aspath)));
7489
7490 count = mtype_stats_alloc(MTYPE_AS_SEG);
7491 vty_out(vty, "%ld BGP AS-PATH segments, using %s of memory\n", count,
7492 mtype_memstr(memstrbuf, sizeof(memstrbuf),
7493 count * sizeof(struct assegment)));
7494
7495 /* Other attributes */
7496 if ((count = community_count()))
7497 vty_out(vty, "%ld BGP community entries, using %s of memory\n",
7498 count, mtype_memstr(memstrbuf, sizeof(memstrbuf),
7499 count * sizeof(struct community)));
7500 if ((count = mtype_stats_alloc(MTYPE_ECOMMUNITY)))
7501 vty_out(vty, "%ld BGP community entries, using %s of memory\n",
7502 count, mtype_memstr(memstrbuf, sizeof(memstrbuf),
7503 count * sizeof(struct ecommunity)));
7504 if ((count = mtype_stats_alloc(MTYPE_LCOMMUNITY)))
7505 vty_out(vty,
7506 "%ld BGP large-community entries, using %s of memory\n",
7507 count, mtype_memstr(memstrbuf, sizeof(memstrbuf),
7508 count * sizeof(struct lcommunity)));
7509
7510 if ((count = mtype_stats_alloc(MTYPE_CLUSTER)))
7511 vty_out(vty, "%ld Cluster lists, using %s of memory\n", count,
7512 mtype_memstr(memstrbuf, sizeof(memstrbuf),
7513 count * sizeof(struct cluster_list)));
7514
7515 /* Peer related usage */
7516 count = mtype_stats_alloc(MTYPE_BGP_PEER);
7517 vty_out(vty, "%ld peers, using %s of memory\n", count,
7518 mtype_memstr(memstrbuf, sizeof(memstrbuf),
7519 count * sizeof(struct peer)));
7520
7521 if ((count = mtype_stats_alloc(MTYPE_PEER_GROUP)))
7522 vty_out(vty, "%ld peer groups, using %s of memory\n", count,
7523 mtype_memstr(memstrbuf, sizeof(memstrbuf),
7524 count * sizeof(struct peer_group)));
7525
7526 /* Other */
7527 if ((count = mtype_stats_alloc(MTYPE_HASH)))
7528 vty_out(vty, "%ld hash tables, using %s of memory\n", count,
7529 mtype_memstr(memstrbuf, sizeof(memstrbuf),
7530 count * sizeof(struct hash)));
7531 if ((count = mtype_stats_alloc(MTYPE_HASH_BACKET)))
7532 vty_out(vty, "%ld hash buckets, using %s of memory\n", count,
7533 mtype_memstr(memstrbuf, sizeof(memstrbuf),
7534 count * sizeof(struct hash_backet)));
7535 if ((count = mtype_stats_alloc(MTYPE_BGP_REGEXP)))
7536 vty_out(vty, "%ld compiled regexes, using %s of memory\n",
7537 count, mtype_memstr(memstrbuf, sizeof(memstrbuf),
7538 count * sizeof(regex_t)));
7539 return CMD_SUCCESS;
7540 }
7541
7542 static void bgp_show_bestpath_json(struct bgp *bgp, json_object *json)
7543 {
7544 json_object *bestpath = json_object_new_object();
7545
7546 if (bgp_flag_check(bgp, BGP_FLAG_ASPATH_IGNORE))
7547 json_object_string_add(bestpath, "asPath", "ignore");
7548
7549 if (bgp_flag_check(bgp, BGP_FLAG_ASPATH_CONFED))
7550 json_object_string_add(bestpath, "asPath", "confed");
7551
7552 if (bgp_flag_check(bgp, BGP_FLAG_ASPATH_MULTIPATH_RELAX)) {
7553 if (bgp_flag_check(bgp, BGP_FLAG_MULTIPATH_RELAX_AS_SET))
7554 json_object_string_add(bestpath, "multiPathRelax",
7555 "as-set");
7556 else
7557 json_object_string_add(bestpath, "multiPathRelax",
7558 "true");
7559 } else
7560 json_object_string_add(bestpath, "multiPathRelax", "false");
7561
7562 if (bgp_flag_check(bgp, BGP_FLAG_COMPARE_ROUTER_ID))
7563 json_object_string_add(bestpath, "compareRouterId", "true");
7564 if (bgp_flag_check(bgp, BGP_FLAG_MED_CONFED)
7565 || bgp_flag_check(bgp, BGP_FLAG_MED_MISSING_AS_WORST)) {
7566 if (bgp_flag_check(bgp, BGP_FLAG_MED_CONFED))
7567 json_object_string_add(bestpath, "med", "confed");
7568 if (bgp_flag_check(bgp, BGP_FLAG_MED_MISSING_AS_WORST))
7569 json_object_string_add(bestpath, "med",
7570 "missing-as-worst");
7571 else
7572 json_object_string_add(bestpath, "med", "true");
7573 }
7574
7575 json_object_object_add(json, "bestPath", bestpath);
7576 }
7577
7578 /* Show BGP peer's summary information. */
7579 static int bgp_show_summary(struct vty *vty, struct bgp *bgp, int afi, int safi,
7580 uint8_t use_json, json_object *json)
7581 {
7582 struct peer *peer;
7583 struct listnode *node, *nnode;
7584 unsigned int count = 0, dn_count = 0;
7585 char timebuf[BGP_UPTIME_LEN], dn_flag[2];
7586 char neighbor_buf[VTY_BUFSIZ];
7587 int neighbor_col_default_width = 16;
7588 int len;
7589 int max_neighbor_width = 0;
7590 int pfx_rcd_safi;
7591 json_object *json_peer = NULL;
7592 json_object *json_peers = NULL;
7593
7594 /* labeled-unicast routes are installed in the unicast table so in order
7595 * to
7596 * display the correct PfxRcd value we must look at SAFI_UNICAST
7597 */
7598 if (safi == SAFI_LABELED_UNICAST)
7599 pfx_rcd_safi = SAFI_UNICAST;
7600 else
7601 pfx_rcd_safi = safi;
7602
7603 if (use_json) {
7604 if (json == NULL)
7605 json = json_object_new_object();
7606
7607 json_peers = json_object_new_object();
7608 } else {
7609 /* Loop over all neighbors that will be displayed to determine
7610 * how many
7611 * characters are needed for the Neighbor column
7612 */
7613 for (ALL_LIST_ELEMENTS(bgp->peer, node, nnode, peer)) {
7614 if (!CHECK_FLAG(peer->flags, PEER_FLAG_CONFIG_NODE))
7615 continue;
7616
7617 if (peer->afc[afi][safi]) {
7618 memset(dn_flag, '\0', sizeof(dn_flag));
7619 if (peer_dynamic_neighbor(peer))
7620 dn_flag[0] = '*';
7621
7622 if (peer->hostname
7623 && bgp_flag_check(bgp,
7624 BGP_FLAG_SHOW_HOSTNAME))
7625 sprintf(neighbor_buf, "%s%s(%s) ",
7626 dn_flag, peer->hostname,
7627 peer->host);
7628 else
7629 sprintf(neighbor_buf, "%s%s ", dn_flag,
7630 peer->host);
7631
7632 len = strlen(neighbor_buf);
7633
7634 if (len > max_neighbor_width)
7635 max_neighbor_width = len;
7636 }
7637 }
7638
7639 /* Originally we displayed the Neighbor column as 16
7640 * characters wide so make that the default
7641 */
7642 if (max_neighbor_width < neighbor_col_default_width)
7643 max_neighbor_width = neighbor_col_default_width;
7644 }
7645
7646 for (ALL_LIST_ELEMENTS(bgp->peer, node, nnode, peer)) {
7647 if (!CHECK_FLAG(peer->flags, PEER_FLAG_CONFIG_NODE))
7648 continue;
7649
7650 if (!peer->afc[afi][safi])
7651 continue;
7652
7653 if (!count) {
7654 unsigned long ents;
7655 char memstrbuf[MTYPE_MEMSTR_LEN];
7656 int64_t vrf_id_ui;
7657
7658 vrf_id_ui = (bgp->vrf_id == VRF_UNKNOWN)
7659 ? -1
7660 : (int64_t)bgp->vrf_id;
7661
7662 /* Usage summary and header */
7663 if (use_json) {
7664 json_object_string_add(
7665 json, "routerId",
7666 inet_ntoa(bgp->router_id));
7667 json_object_int_add(json, "as", bgp->as);
7668 json_object_int_add(json, "vrfId", vrf_id_ui);
7669 json_object_string_add(
7670 json, "vrfName",
7671 (bgp->inst_type
7672 == BGP_INSTANCE_TYPE_DEFAULT)
7673 ? "Default"
7674 : bgp->name);
7675 } else {
7676 vty_out(vty,
7677 "BGP router identifier %s, local AS number %u vrf-id %d",
7678 inet_ntoa(bgp->router_id), bgp->as,
7679 bgp->vrf_id == VRF_UNKNOWN
7680 ? -1
7681 : (int)bgp->vrf_id);
7682 vty_out(vty, "\n");
7683 }
7684
7685 if (bgp_update_delay_configured(bgp)) {
7686 if (use_json) {
7687 json_object_int_add(
7688 json, "updateDelayLimit",
7689 bgp->v_update_delay);
7690
7691 if (bgp->v_update_delay
7692 != bgp->v_establish_wait)
7693 json_object_int_add(
7694 json,
7695 "updateDelayEstablishWait",
7696 bgp->v_establish_wait);
7697
7698 if (bgp_update_delay_active(bgp)) {
7699 json_object_string_add(
7700 json,
7701 "updateDelayFirstNeighbor",
7702 bgp->update_delay_begin_time);
7703 json_object_boolean_true_add(
7704 json,
7705 "updateDelayInProgress");
7706 } else {
7707 if (bgp->update_delay_over) {
7708 json_object_string_add(
7709 json,
7710 "updateDelayFirstNeighbor",
7711 bgp->update_delay_begin_time);
7712 json_object_string_add(
7713 json,
7714 "updateDelayBestpathResumed",
7715 bgp->update_delay_end_time);
7716 json_object_string_add(
7717 json,
7718 "updateDelayZebraUpdateResume",
7719 bgp->update_delay_zebra_resume_time);
7720 json_object_string_add(
7721 json,
7722 "updateDelayPeerUpdateResume",
7723 bgp->update_delay_peers_resume_time);
7724 }
7725 }
7726 } else {
7727 vty_out(vty,
7728 "Read-only mode update-delay limit: %d seconds\n",
7729 bgp->v_update_delay);
7730 if (bgp->v_update_delay
7731 != bgp->v_establish_wait)
7732 vty_out(vty,
7733 " Establish wait: %d seconds\n",
7734 bgp->v_establish_wait);
7735
7736 if (bgp_update_delay_active(bgp)) {
7737 vty_out(vty,
7738 " First neighbor established: %s\n",
7739 bgp->update_delay_begin_time);
7740 vty_out(vty,
7741 " Delay in progress\n");
7742 } else {
7743 if (bgp->update_delay_over) {
7744 vty_out(vty,
7745 " First neighbor established: %s\n",
7746 bgp->update_delay_begin_time);
7747 vty_out(vty,
7748 " Best-paths resumed: %s\n",
7749 bgp->update_delay_end_time);
7750 vty_out(vty,
7751 " zebra update resumed: %s\n",
7752 bgp->update_delay_zebra_resume_time);
7753 vty_out(vty,
7754 " peers update resumed: %s\n",
7755 bgp->update_delay_peers_resume_time);
7756 }
7757 }
7758 }
7759 }
7760
7761 if (use_json) {
7762 if (bgp_maxmed_onstartup_configured(bgp)
7763 && bgp->maxmed_active)
7764 json_object_boolean_true_add(
7765 json, "maxMedOnStartup");
7766 if (bgp->v_maxmed_admin)
7767 json_object_boolean_true_add(
7768 json, "maxMedAdministrative");
7769
7770 json_object_int_add(
7771 json, "tableVersion",
7772 bgp_table_version(bgp->rib[afi][safi]));
7773
7774 ents = bgp_table_count(bgp->rib[afi][safi]);
7775 json_object_int_add(json, "ribCount", ents);
7776 json_object_int_add(
7777 json, "ribMemory",
7778 ents * sizeof(struct bgp_node));
7779
7780 ents = listcount(bgp->peer);
7781 json_object_int_add(json, "peerCount", ents);
7782 json_object_int_add(json, "peerMemory",
7783 ents * sizeof(struct peer));
7784
7785 if ((ents = listcount(bgp->group))) {
7786 json_object_int_add(
7787 json, "peerGroupCount", ents);
7788 json_object_int_add(
7789 json, "peerGroupMemory",
7790 ents * sizeof(struct
7791 peer_group));
7792 }
7793
7794 if (CHECK_FLAG(bgp->af_flags[afi][safi],
7795 BGP_CONFIG_DAMPENING))
7796 json_object_boolean_true_add(
7797 json, "dampeningEnabled");
7798 } else {
7799 if (bgp_maxmed_onstartup_configured(bgp)
7800 && bgp->maxmed_active)
7801 vty_out(vty,
7802 "Max-med on-startup active\n");
7803 if (bgp->v_maxmed_admin)
7804 vty_out(vty,
7805 "Max-med administrative active\n");
7806
7807 vty_out(vty, "BGP table version %" PRIu64 "\n",
7808 bgp_table_version(bgp->rib[afi][safi]));
7809
7810 ents = bgp_table_count(bgp->rib[afi][safi]);
7811 vty_out(vty,
7812 "RIB entries %ld, using %s of memory\n",
7813 ents,
7814 mtype_memstr(memstrbuf,
7815 sizeof(memstrbuf),
7816 ents * sizeof(struct
7817 bgp_node)));
7818
7819 /* Peer related usage */
7820 ents = listcount(bgp->peer);
7821 vty_out(vty, "Peers %ld, using %s of memory\n",
7822 ents,
7823 mtype_memstr(
7824 memstrbuf, sizeof(memstrbuf),
7825 ents * sizeof(struct peer)));
7826
7827 if ((ents = listcount(bgp->group)))
7828 vty_out(vty,
7829 "Peer groups %ld, using %s of memory\n",
7830 ents,
7831 mtype_memstr(
7832 memstrbuf,
7833 sizeof(memstrbuf),
7834 ents * sizeof(struct
7835 peer_group)));
7836
7837 if (CHECK_FLAG(bgp->af_flags[afi][safi],
7838 BGP_CONFIG_DAMPENING))
7839 vty_out(vty, "Dampening enabled.\n");
7840 vty_out(vty, "\n");
7841
7842 /* Subtract 8 here because 'Neighbor' is
7843 * 8 characters */
7844 vty_out(vty, "Neighbor");
7845 vty_out(vty, "%*s", max_neighbor_width - 8,
7846 " ");
7847 vty_out(vty,
7848 "V AS MsgRcvd MsgSent TblVer InQ OutQ Up/Down State/PfxRcd\n");
7849 }
7850 }
7851
7852 count++;
7853
7854 if (use_json) {
7855 json_peer = json_object_new_object();
7856
7857 if (peer_dynamic_neighbor(peer))
7858 json_object_boolean_true_add(json_peer,
7859 "dynamicPeer");
7860
7861 if (peer->hostname)
7862 json_object_string_add(json_peer, "hostname",
7863 peer->hostname);
7864
7865 if (peer->domainname)
7866 json_object_string_add(json_peer, "domainname",
7867 peer->domainname);
7868
7869 json_object_int_add(json_peer, "remoteAs", peer->as);
7870 json_object_int_add(json_peer, "version", 4);
7871 json_object_int_add(json_peer, "msgRcvd",
7872 PEER_TOTAL_RX(peer));
7873 json_object_int_add(json_peer, "msgSent",
7874 PEER_TOTAL_TX(peer));
7875
7876 json_object_int_add(json_peer, "tableVersion",
7877 peer->version[afi][safi]);
7878 json_object_int_add(json_peer, "outq",
7879 peer->obuf->count);
7880 json_object_int_add(json_peer, "inq", 0);
7881 peer_uptime(peer->uptime, timebuf, BGP_UPTIME_LEN,
7882 use_json, json_peer);
7883 json_object_int_add(json_peer, "prefixReceivedCount",
7884 peer->pcount[afi][pfx_rcd_safi]);
7885
7886 if (CHECK_FLAG(peer->flags, PEER_FLAG_SHUTDOWN))
7887 json_object_string_add(json_peer, "state",
7888 "Idle (Admin)");
7889 else if (CHECK_FLAG(peer->sflags,
7890 PEER_STATUS_PREFIX_OVERFLOW))
7891 json_object_string_add(json_peer, "state",
7892 "Idle (PfxCt)");
7893 else
7894 json_object_string_add(
7895 json_peer, "state",
7896 lookup_msg(bgp_status_msg, peer->status,
7897 NULL));
7898
7899 if (peer->conf_if)
7900 json_object_string_add(json_peer, "idType",
7901 "interface");
7902 else if (peer->su.sa.sa_family == AF_INET)
7903 json_object_string_add(json_peer, "idType",
7904 "ipv4");
7905 else if (peer->su.sa.sa_family == AF_INET6)
7906 json_object_string_add(json_peer, "idType",
7907 "ipv6");
7908
7909 json_object_object_add(json_peers, peer->host,
7910 json_peer);
7911 } else {
7912 memset(dn_flag, '\0', sizeof(dn_flag));
7913 if (peer_dynamic_neighbor(peer)) {
7914 dn_count++;
7915 dn_flag[0] = '*';
7916 }
7917
7918 if (peer->hostname
7919 && bgp_flag_check(bgp, BGP_FLAG_SHOW_HOSTNAME))
7920 len = vty_out(vty, "%s%s(%s)", dn_flag,
7921 peer->hostname, peer->host);
7922 else
7923 len = vty_out(vty, "%s%s", dn_flag, peer->host);
7924
7925 /* pad the neighbor column with spaces */
7926 if (len < max_neighbor_width)
7927 vty_out(vty, "%*s", max_neighbor_width - len,
7928 " ");
7929
7930 vty_out(vty, "4 %10u %7u %7u %8" PRIu64 " %4d %4zd %8s",
7931 peer->as, PEER_TOTAL_RX(peer),
7932 PEER_TOTAL_TX(peer), peer->version[afi][safi],
7933 0, peer->obuf->count,
7934 peer_uptime(peer->uptime, timebuf,
7935 BGP_UPTIME_LEN, 0, NULL));
7936
7937 if (peer->status == Established)
7938 if (peer->afc_recv[afi][pfx_rcd_safi])
7939 vty_out(vty, " %12ld",
7940 peer->pcount[afi]
7941 [pfx_rcd_safi]);
7942 else
7943 vty_out(vty, " NoNeg");
7944 else {
7945 if (CHECK_FLAG(peer->flags, PEER_FLAG_SHUTDOWN))
7946 vty_out(vty, " Idle (Admin)");
7947 else if (CHECK_FLAG(
7948 peer->sflags,
7949 PEER_STATUS_PREFIX_OVERFLOW))
7950 vty_out(vty, " Idle (PfxCt)");
7951 else
7952 vty_out(vty, " %12s",
7953 lookup_msg(bgp_status_msg,
7954 peer->status, NULL));
7955 }
7956 vty_out(vty, "\n");
7957 }
7958 }
7959
7960 if (use_json) {
7961 json_object_object_add(json, "peers", json_peers);
7962
7963 json_object_int_add(json, "totalPeers", count);
7964 json_object_int_add(json, "dynamicPeers", dn_count);
7965
7966 bgp_show_bestpath_json(bgp, json);
7967
7968 vty_out(vty, "%s\n", json_object_to_json_string_ext(
7969 json, JSON_C_TO_STRING_PRETTY));
7970 json_object_free(json);
7971 } else {
7972 if (count)
7973 vty_out(vty, "\nTotal number of neighbors %d\n", count);
7974 else {
7975 if (use_json)
7976 vty_out(vty,
7977 "{\"error\": {\"message\": \"No %s neighbor configured\"}}\n",
7978 afi_safi_print(afi, safi));
7979 else
7980 vty_out(vty, "No %s neighbor is configured\n",
7981 afi_safi_print(afi, safi));
7982 }
7983
7984 if (dn_count && !use_json) {
7985 vty_out(vty, "* - dynamic neighbor\n");
7986 vty_out(vty, "%d dynamic neighbor(s), limit %d\n",
7987 dn_count, bgp->dynamic_neighbors_limit);
7988 }
7989 }
7990
7991 return CMD_SUCCESS;
7992 }
7993
7994 static void bgp_show_summary_afi_safi(struct vty *vty, struct bgp *bgp, int afi,
7995 int safi, uint8_t use_json,
7996 json_object *json)
7997 {
7998 int is_first = 1;
7999 int afi_wildcard = (afi == AFI_MAX);
8000 int safi_wildcard = (safi == SAFI_MAX);
8001 int is_wildcard = (afi_wildcard || safi_wildcard);
8002 bool json_output = false;
8003
8004 if (use_json && is_wildcard)
8005 vty_out(vty, "{\n");
8006 if (afi_wildcard)
8007 afi = 1; /* AFI_IP */
8008 while (afi < AFI_MAX) {
8009 if (safi_wildcard)
8010 safi = 1; /* SAFI_UNICAST */
8011 while (safi < SAFI_MAX) {
8012 if (bgp_afi_safi_peer_exists(bgp, afi, safi)) {
8013 json_output = true;
8014 if (is_wildcard) {
8015 /*
8016 * So limit output to those afi/safi
8017 * pairs that
8018 * actualy have something interesting in
8019 * them
8020 */
8021 if (use_json) {
8022 json = json_object_new_object();
8023
8024 if (!is_first)
8025 vty_out(vty, ",\n");
8026 else
8027 is_first = 0;
8028
8029 vty_out(vty, "\"%s\":",
8030 afi_safi_json(afi,
8031 safi));
8032 } else {
8033 vty_out(vty, "\n%s Summary:\n",
8034 afi_safi_print(afi,
8035 safi));
8036 }
8037 }
8038 bgp_show_summary(vty, bgp, afi, safi, use_json,
8039 json);
8040 }
8041 safi++;
8042 if (!safi_wildcard)
8043 safi = SAFI_MAX;
8044 }
8045 afi++;
8046 if (!afi_wildcard)
8047 afi = AFI_MAX;
8048 }
8049
8050 if (use_json && is_wildcard)
8051 vty_out(vty, "}\n");
8052 else if (use_json && !json_output)
8053 vty_out(vty, "{}\n");
8054 }
8055
8056 static void bgp_show_all_instances_summary_vty(struct vty *vty, afi_t afi,
8057 safi_t safi, uint8_t use_json)
8058 {
8059 struct listnode *node, *nnode;
8060 struct bgp *bgp;
8061 json_object *json = NULL;
8062 int is_first = 1;
8063
8064 if (use_json)
8065 vty_out(vty, "{\n");
8066
8067 for (ALL_LIST_ELEMENTS(bm->bgp, node, nnode, bgp)) {
8068 if (use_json) {
8069 json = json_object_new_object();
8070
8071 if (!is_first)
8072 vty_out(vty, ",\n");
8073 else
8074 is_first = 0;
8075
8076 vty_out(vty, "\"%s\":",
8077 (bgp->inst_type == BGP_INSTANCE_TYPE_DEFAULT)
8078 ? "Default"
8079 : bgp->name);
8080 } else {
8081 vty_out(vty, "\nInstance %s:\n",
8082 (bgp->inst_type == BGP_INSTANCE_TYPE_DEFAULT)
8083 ? "Default"
8084 : bgp->name);
8085 }
8086 bgp_show_summary_afi_safi(vty, bgp, afi, safi, use_json, json);
8087 }
8088
8089 if (use_json)
8090 vty_out(vty, "}\n");
8091 }
8092
8093 int bgp_show_summary_vty(struct vty *vty, const char *name, afi_t afi,
8094 safi_t safi, uint8_t use_json)
8095 {
8096 struct bgp *bgp;
8097
8098 if (name) {
8099 if (strmatch(name, "all")) {
8100 bgp_show_all_instances_summary_vty(vty, afi, safi,
8101 use_json);
8102 return CMD_SUCCESS;
8103 } else {
8104 bgp = bgp_lookup_by_name(name);
8105
8106 if (!bgp) {
8107 if (use_json)
8108 vty_out(vty, "{}\n");
8109 else
8110 vty_out(vty,
8111 "%% No such BGP instance exist\n");
8112 return CMD_WARNING;
8113 }
8114
8115 bgp_show_summary_afi_safi(vty, bgp, afi, safi, use_json,
8116 NULL);
8117 return CMD_SUCCESS;
8118 }
8119 }
8120
8121 bgp = bgp_get_default();
8122
8123 if (bgp)
8124 bgp_show_summary_afi_safi(vty, bgp, afi, safi, use_json, NULL);
8125
8126 return CMD_SUCCESS;
8127 }
8128
8129 /* `show [ip] bgp summary' commands. */
8130 DEFUN (show_ip_bgp_summary,
8131 show_ip_bgp_summary_cmd,
8132 "show [ip] bgp [<view|vrf> VIEWVRFNAME] ["BGP_AFI_CMD_STR" ["BGP_SAFI_WITH_LABEL_CMD_STR"]] summary [json]",
8133 SHOW_STR
8134 IP_STR
8135 BGP_STR
8136 BGP_INSTANCE_HELP_STR
8137 BGP_AFI_HELP_STR
8138 BGP_SAFI_WITH_LABEL_HELP_STR
8139 "Summary of BGP neighbor status\n"
8140 JSON_STR)
8141 {
8142 char *vrf = NULL;
8143 afi_t afi = AFI_MAX;
8144 safi_t safi = SAFI_MAX;
8145
8146 int idx = 0;
8147
8148 /* show [ip] bgp */
8149 if (argv_find(argv, argc, "ip", &idx))
8150 afi = AFI_IP;
8151 /* [<view|vrf> VIEWVRFNAME] */
8152 if (argv_find(argv, argc, "view", &idx)
8153 || argv_find(argv, argc, "vrf", &idx))
8154 vrf = argv[++idx]->arg;
8155 /* ["BGP_AFI_CMD_STR" ["BGP_SAFI_CMD_STR"]] */
8156 if (argv_find_and_parse_afi(argv, argc, &idx, &afi)) {
8157 argv_find_and_parse_safi(argv, argc, &idx, &safi);
8158 }
8159
8160 int uj = use_json(argc, argv);
8161
8162 return bgp_show_summary_vty(vty, vrf, afi, safi, uj);
8163 }
8164
8165 const char *afi_safi_print(afi_t afi, safi_t safi)
8166 {
8167 if (afi == AFI_IP && safi == SAFI_UNICAST)
8168 return "IPv4 Unicast";
8169 else if (afi == AFI_IP && safi == SAFI_MULTICAST)
8170 return "IPv4 Multicast";
8171 else if (afi == AFI_IP && safi == SAFI_LABELED_UNICAST)
8172 return "IPv4 Labeled Unicast";
8173 else if (afi == AFI_IP && safi == SAFI_MPLS_VPN)
8174 return "IPv4 VPN";
8175 else if (afi == AFI_IP && safi == SAFI_ENCAP)
8176 return "IPv4 Encap";
8177 else if (afi == AFI_IP && safi == SAFI_FLOWSPEC)
8178 return "IPv4 Flowspec";
8179 else if (afi == AFI_IP6 && safi == SAFI_UNICAST)
8180 return "IPv6 Unicast";
8181 else if (afi == AFI_IP6 && safi == SAFI_MULTICAST)
8182 return "IPv6 Multicast";
8183 else if (afi == AFI_IP6 && safi == SAFI_LABELED_UNICAST)
8184 return "IPv6 Labeled Unicast";
8185 else if (afi == AFI_IP6 && safi == SAFI_MPLS_VPN)
8186 return "IPv6 VPN";
8187 else if (afi == AFI_IP6 && safi == SAFI_ENCAP)
8188 return "IPv6 Encap";
8189 else if (afi == AFI_IP6 && safi == SAFI_FLOWSPEC)
8190 return "IPv6 Flowspec";
8191 else if (afi == AFI_L2VPN && safi == SAFI_EVPN)
8192 return "L2VPN EVPN";
8193 else
8194 return "Unknown";
8195 }
8196
8197 /*
8198 * Please note that we have intentionally camelCased
8199 * the return strings here. So if you want
8200 * to use this function, please ensure you
8201 * are doing this within json output
8202 */
8203 const char *afi_safi_json(afi_t afi, safi_t safi)
8204 {
8205 if (afi == AFI_IP && safi == SAFI_UNICAST)
8206 return "ipv4Unicast";
8207 else if (afi == AFI_IP && safi == SAFI_MULTICAST)
8208 return "ipv4Multicast";
8209 else if (afi == AFI_IP && safi == SAFI_LABELED_UNICAST)
8210 return "ipv4LabeledUnicast";
8211 else if (afi == AFI_IP && safi == SAFI_MPLS_VPN)
8212 return "ipv4Vpn";
8213 else if (afi == AFI_IP && safi == SAFI_ENCAP)
8214 return "ipv4Encap";
8215 else if (afi == AFI_IP && safi == SAFI_FLOWSPEC)
8216 return "ipv4Flowspec";
8217 else if (afi == AFI_IP6 && safi == SAFI_UNICAST)
8218 return "ipv6Unicast";
8219 else if (afi == AFI_IP6 && safi == SAFI_MULTICAST)
8220 return "ipv6Multicast";
8221 else if (afi == AFI_IP6 && safi == SAFI_LABELED_UNICAST)
8222 return "ipv6LabeledUnicast";
8223 else if (afi == AFI_IP6 && safi == SAFI_MPLS_VPN)
8224 return "ipv6Vpn";
8225 else if (afi == AFI_IP6 && safi == SAFI_ENCAP)
8226 return "ipv6Encap";
8227 else if (afi == AFI_IP6 && safi == SAFI_FLOWSPEC)
8228 return "ipv6Flowspec";
8229 else if (afi == AFI_L2VPN && safi == SAFI_EVPN)
8230 return "l2VpnEvpn";
8231 else
8232 return "Unknown";
8233 }
8234
8235 /* Show BGP peer's information. */
8236 enum show_type { show_all, show_peer };
8237
8238 static void bgp_show_peer_afi_orf_cap(struct vty *vty, struct peer *p,
8239 afi_t afi, safi_t safi,
8240 uint16_t adv_smcap, uint16_t adv_rmcap,
8241 uint16_t rcv_smcap, uint16_t rcv_rmcap,
8242 uint8_t use_json, json_object *json_pref)
8243 {
8244 /* Send-Mode */
8245 if (CHECK_FLAG(p->af_cap[afi][safi], adv_smcap)
8246 || CHECK_FLAG(p->af_cap[afi][safi], rcv_smcap)) {
8247 if (use_json) {
8248 if (CHECK_FLAG(p->af_cap[afi][safi], adv_smcap)
8249 && CHECK_FLAG(p->af_cap[afi][safi], rcv_smcap))
8250 json_object_string_add(json_pref, "sendMode",
8251 "advertisedAndReceived");
8252 else if (CHECK_FLAG(p->af_cap[afi][safi], adv_smcap))
8253 json_object_string_add(json_pref, "sendMode",
8254 "advertised");
8255 else if (CHECK_FLAG(p->af_cap[afi][safi], rcv_smcap))
8256 json_object_string_add(json_pref, "sendMode",
8257 "received");
8258 } else {
8259 vty_out(vty, " Send-mode: ");
8260 if (CHECK_FLAG(p->af_cap[afi][safi], adv_smcap))
8261 vty_out(vty, "advertised");
8262 if (CHECK_FLAG(p->af_cap[afi][safi], rcv_smcap))
8263 vty_out(vty, "%sreceived",
8264 CHECK_FLAG(p->af_cap[afi][safi],
8265 adv_smcap)
8266 ? ", "
8267 : "");
8268 vty_out(vty, "\n");
8269 }
8270 }
8271
8272 /* Receive-Mode */
8273 if (CHECK_FLAG(p->af_cap[afi][safi], adv_rmcap)
8274 || CHECK_FLAG(p->af_cap[afi][safi], rcv_rmcap)) {
8275 if (use_json) {
8276 if (CHECK_FLAG(p->af_cap[afi][safi], adv_rmcap)
8277 && CHECK_FLAG(p->af_cap[afi][safi], rcv_rmcap))
8278 json_object_string_add(json_pref, "recvMode",
8279 "advertisedAndReceived");
8280 else if (CHECK_FLAG(p->af_cap[afi][safi], adv_rmcap))
8281 json_object_string_add(json_pref, "recvMode",
8282 "advertised");
8283 else if (CHECK_FLAG(p->af_cap[afi][safi], rcv_rmcap))
8284 json_object_string_add(json_pref, "recvMode",
8285 "received");
8286 } else {
8287 vty_out(vty, " Receive-mode: ");
8288 if (CHECK_FLAG(p->af_cap[afi][safi], adv_rmcap))
8289 vty_out(vty, "advertised");
8290 if (CHECK_FLAG(p->af_cap[afi][safi], rcv_rmcap))
8291 vty_out(vty, "%sreceived",
8292 CHECK_FLAG(p->af_cap[afi][safi],
8293 adv_rmcap)
8294 ? ", "
8295 : "");
8296 vty_out(vty, "\n");
8297 }
8298 }
8299 }
8300
8301 static void bgp_show_peer_afi(struct vty *vty, struct peer *p, afi_t afi,
8302 safi_t safi, uint8_t use_json,
8303 json_object *json_neigh)
8304 {
8305 struct bgp_filter *filter;
8306 struct peer_af *paf;
8307 char orf_pfx_name[BUFSIZ];
8308 int orf_pfx_count;
8309 json_object *json_af = NULL;
8310 json_object *json_prefA = NULL;
8311 json_object *json_prefB = NULL;
8312 json_object *json_addr = NULL;
8313
8314 if (use_json) {
8315 json_addr = json_object_new_object();
8316 json_af = json_object_new_object();
8317 filter = &p->filter[afi][safi];
8318
8319 if (peer_group_active(p))
8320 json_object_string_add(json_addr, "peerGroupMember",
8321 p->group->name);
8322
8323 paf = peer_af_find(p, afi, safi);
8324 if (paf && PAF_SUBGRP(paf)) {
8325 json_object_int_add(json_addr, "updateGroupId",
8326 PAF_UPDGRP(paf)->id);
8327 json_object_int_add(json_addr, "subGroupId",
8328 PAF_SUBGRP(paf)->id);
8329 json_object_int_add(json_addr, "packetQueueLength",
8330 bpacket_queue_virtual_length(paf));
8331 }
8332
8333 if (CHECK_FLAG(p->af_cap[afi][safi], PEER_CAP_ORF_PREFIX_SM_ADV)
8334 || CHECK_FLAG(p->af_cap[afi][safi],
8335 PEER_CAP_ORF_PREFIX_SM_RCV)
8336 || CHECK_FLAG(p->af_cap[afi][safi],
8337 PEER_CAP_ORF_PREFIX_RM_ADV)
8338 || CHECK_FLAG(p->af_cap[afi][safi],
8339 PEER_CAP_ORF_PREFIX_RM_RCV)) {
8340 json_object_int_add(json_af, "orfType",
8341 ORF_TYPE_PREFIX);
8342 json_prefA = json_object_new_object();
8343 bgp_show_peer_afi_orf_cap(vty, p, afi, safi,
8344 PEER_CAP_ORF_PREFIX_SM_ADV,
8345 PEER_CAP_ORF_PREFIX_RM_ADV,
8346 PEER_CAP_ORF_PREFIX_SM_RCV,
8347 PEER_CAP_ORF_PREFIX_RM_RCV,
8348 use_json, json_prefA);
8349 json_object_object_add(json_af, "orfPrefixList",
8350 json_prefA);
8351 }
8352
8353 if (CHECK_FLAG(p->af_cap[afi][safi], PEER_CAP_ORF_PREFIX_SM_ADV)
8354 || CHECK_FLAG(p->af_cap[afi][safi],
8355 PEER_CAP_ORF_PREFIX_SM_OLD_RCV)
8356 || CHECK_FLAG(p->af_cap[afi][safi],
8357 PEER_CAP_ORF_PREFIX_RM_ADV)
8358 || CHECK_FLAG(p->af_cap[afi][safi],
8359 PEER_CAP_ORF_PREFIX_RM_OLD_RCV)) {
8360 json_object_int_add(json_af, "orfOldType",
8361 ORF_TYPE_PREFIX_OLD);
8362 json_prefB = json_object_new_object();
8363 bgp_show_peer_afi_orf_cap(
8364 vty, p, afi, safi, PEER_CAP_ORF_PREFIX_SM_ADV,
8365 PEER_CAP_ORF_PREFIX_RM_ADV,
8366 PEER_CAP_ORF_PREFIX_SM_OLD_RCV,
8367 PEER_CAP_ORF_PREFIX_RM_OLD_RCV, use_json,
8368 json_prefB);
8369 json_object_object_add(json_af, "orfOldPrefixList",
8370 json_prefB);
8371 }
8372
8373 if (CHECK_FLAG(p->af_cap[afi][safi], PEER_CAP_ORF_PREFIX_SM_ADV)
8374 || CHECK_FLAG(p->af_cap[afi][safi],
8375 PEER_CAP_ORF_PREFIX_SM_RCV)
8376 || CHECK_FLAG(p->af_cap[afi][safi],
8377 PEER_CAP_ORF_PREFIX_SM_OLD_RCV)
8378 || CHECK_FLAG(p->af_cap[afi][safi],
8379 PEER_CAP_ORF_PREFIX_RM_ADV)
8380 || CHECK_FLAG(p->af_cap[afi][safi],
8381 PEER_CAP_ORF_PREFIX_RM_RCV)
8382 || CHECK_FLAG(p->af_cap[afi][safi],
8383 PEER_CAP_ORF_PREFIX_RM_OLD_RCV))
8384 json_object_object_add(json_addr, "afDependentCap",
8385 json_af);
8386 else
8387 json_object_free(json_af);
8388
8389 sprintf(orf_pfx_name, "%s.%d.%d", p->host, afi, safi);
8390 orf_pfx_count = prefix_bgp_show_prefix_list(
8391 NULL, afi, orf_pfx_name, use_json);
8392
8393 if (CHECK_FLAG(p->af_sflags[afi][safi],
8394 PEER_STATUS_ORF_PREFIX_SEND)
8395 || orf_pfx_count) {
8396 if (CHECK_FLAG(p->af_sflags[afi][safi],
8397 PEER_STATUS_ORF_PREFIX_SEND))
8398 json_object_boolean_true_add(json_neigh,
8399 "orfSent");
8400 if (orf_pfx_count)
8401 json_object_int_add(json_addr, "orfRecvCounter",
8402 orf_pfx_count);
8403 }
8404 if (CHECK_FLAG(p->af_sflags[afi][safi],
8405 PEER_STATUS_ORF_WAIT_REFRESH))
8406 json_object_string_add(
8407 json_addr, "orfFirstUpdate",
8408 "deferredUntilORFOrRouteRefreshRecvd");
8409
8410 if (CHECK_FLAG(p->af_flags[afi][safi],
8411 PEER_FLAG_REFLECTOR_CLIENT))
8412 json_object_boolean_true_add(json_addr,
8413 "routeReflectorClient");
8414 if (CHECK_FLAG(p->af_flags[afi][safi],
8415 PEER_FLAG_RSERVER_CLIENT))
8416 json_object_boolean_true_add(json_addr,
8417 "routeServerClient");
8418 if (CHECK_FLAG(p->af_flags[afi][safi], PEER_FLAG_SOFT_RECONFIG))
8419 json_object_boolean_true_add(json_addr,
8420 "inboundSoftConfigPermit");
8421
8422 if (CHECK_FLAG(p->af_flags[afi][safi],
8423 PEER_FLAG_REMOVE_PRIVATE_AS_ALL_REPLACE))
8424 json_object_boolean_true_add(
8425 json_addr,
8426 "privateAsNumsAllReplacedInUpdatesToNbr");
8427 else if (CHECK_FLAG(p->af_flags[afi][safi],
8428 PEER_FLAG_REMOVE_PRIVATE_AS_REPLACE))
8429 json_object_boolean_true_add(
8430 json_addr,
8431 "privateAsNumsReplacedInUpdatesToNbr");
8432 else if (CHECK_FLAG(p->af_flags[afi][safi],
8433 PEER_FLAG_REMOVE_PRIVATE_AS_ALL))
8434 json_object_boolean_true_add(
8435 json_addr,
8436 "privateAsNumsAllRemovedInUpdatesToNbr");
8437 else if (CHECK_FLAG(p->af_flags[afi][safi],
8438 PEER_FLAG_REMOVE_PRIVATE_AS))
8439 json_object_boolean_true_add(
8440 json_addr,
8441 "privateAsNumsRemovedInUpdatesToNbr");
8442
8443 if (CHECK_FLAG(p->af_flags[afi][safi],
8444 PEER_FLAG_ADDPATH_TX_ALL_PATHS))
8445 json_object_boolean_true_add(json_addr,
8446 "addpathTxAllPaths");
8447
8448 if (CHECK_FLAG(p->af_flags[afi][safi],
8449 PEER_FLAG_ADDPATH_TX_BESTPATH_PER_AS))
8450 json_object_boolean_true_add(json_addr,
8451 "addpathTxBestpathPerAS");
8452
8453 if (CHECK_FLAG(p->af_flags[afi][safi], PEER_FLAG_AS_OVERRIDE))
8454 json_object_string_add(json_addr,
8455 "overrideASNsInOutboundUpdates",
8456 "ifAspathEqualRemoteAs");
8457
8458 if (CHECK_FLAG(p->af_flags[afi][safi], PEER_FLAG_NEXTHOP_SELF)
8459 || CHECK_FLAG(p->af_flags[afi][safi],
8460 PEER_FLAG_FORCE_NEXTHOP_SELF))
8461 json_object_boolean_true_add(json_addr,
8462 "routerAlwaysNextHop");
8463 if (CHECK_FLAG(p->af_flags[afi][safi],
8464 PEER_FLAG_AS_PATH_UNCHANGED))
8465 json_object_boolean_true_add(
8466 json_addr, "unchangedAsPathPropogatedToNbr");
8467 if (CHECK_FLAG(p->af_flags[afi][safi],
8468 PEER_FLAG_NEXTHOP_UNCHANGED))
8469 json_object_boolean_true_add(
8470 json_addr, "unchangedNextHopPropogatedToNbr");
8471 if (CHECK_FLAG(p->af_flags[afi][safi], PEER_FLAG_MED_UNCHANGED))
8472 json_object_boolean_true_add(
8473 json_addr, "unchangedMedPropogatedToNbr");
8474 if (CHECK_FLAG(p->af_flags[afi][safi], PEER_FLAG_SEND_COMMUNITY)
8475 || CHECK_FLAG(p->af_flags[afi][safi],
8476 PEER_FLAG_SEND_EXT_COMMUNITY)) {
8477 if (CHECK_FLAG(p->af_flags[afi][safi],
8478 PEER_FLAG_SEND_COMMUNITY)
8479 && CHECK_FLAG(p->af_flags[afi][safi],
8480 PEER_FLAG_SEND_EXT_COMMUNITY))
8481 json_object_string_add(json_addr,
8482 "commAttriSentToNbr",
8483 "extendedAndStandard");
8484 else if (CHECK_FLAG(p->af_flags[afi][safi],
8485 PEER_FLAG_SEND_EXT_COMMUNITY))
8486 json_object_string_add(json_addr,
8487 "commAttriSentToNbr",
8488 "extended");
8489 else
8490 json_object_string_add(json_addr,
8491 "commAttriSentToNbr",
8492 "standard");
8493 }
8494 if (CHECK_FLAG(p->af_flags[afi][safi],
8495 PEER_FLAG_DEFAULT_ORIGINATE)) {
8496 if (p->default_rmap[afi][safi].name)
8497 json_object_string_add(
8498 json_addr, "defaultRouteMap",
8499 p->default_rmap[afi][safi].name);
8500
8501 if (paf && PAF_SUBGRP(paf)
8502 && CHECK_FLAG(PAF_SUBGRP(paf)->sflags,
8503 SUBGRP_STATUS_DEFAULT_ORIGINATE))
8504 json_object_boolean_true_add(json_addr,
8505 "defaultSent");
8506 else
8507 json_object_boolean_true_add(json_addr,
8508 "defaultNotSent");
8509 }
8510
8511 if (afi == AFI_L2VPN && safi == SAFI_EVPN) {
8512 if (is_evpn_enabled())
8513 json_object_boolean_true_add(
8514 json_addr, "advertiseAllVnis");
8515 }
8516
8517 if (filter->plist[FILTER_IN].name
8518 || filter->dlist[FILTER_IN].name
8519 || filter->aslist[FILTER_IN].name
8520 || filter->map[RMAP_IN].name)
8521 json_object_boolean_true_add(json_addr,
8522 "inboundPathPolicyConfig");
8523 if (filter->plist[FILTER_OUT].name
8524 || filter->dlist[FILTER_OUT].name
8525 || filter->aslist[FILTER_OUT].name
8526 || filter->map[RMAP_OUT].name || filter->usmap.name)
8527 json_object_boolean_true_add(
8528 json_addr, "outboundPathPolicyConfig");
8529
8530 /* prefix-list */
8531 if (filter->plist[FILTER_IN].name)
8532 json_object_string_add(json_addr,
8533 "incomingUpdatePrefixFilterList",
8534 filter->plist[FILTER_IN].name);
8535 if (filter->plist[FILTER_OUT].name)
8536 json_object_string_add(json_addr,
8537 "outgoingUpdatePrefixFilterList",
8538 filter->plist[FILTER_OUT].name);
8539
8540 /* distribute-list */
8541 if (filter->dlist[FILTER_IN].name)
8542 json_object_string_add(
8543 json_addr, "incomingUpdateNetworkFilterList",
8544 filter->dlist[FILTER_IN].name);
8545 if (filter->dlist[FILTER_OUT].name)
8546 json_object_string_add(
8547 json_addr, "outgoingUpdateNetworkFilterList",
8548 filter->dlist[FILTER_OUT].name);
8549
8550 /* filter-list. */
8551 if (filter->aslist[FILTER_IN].name)
8552 json_object_string_add(json_addr,
8553 "incomingUpdateAsPathFilterList",
8554 filter->aslist[FILTER_IN].name);
8555 if (filter->aslist[FILTER_OUT].name)
8556 json_object_string_add(json_addr,
8557 "outgoingUpdateAsPathFilterList",
8558 filter->aslist[FILTER_OUT].name);
8559
8560 /* route-map. */
8561 if (filter->map[RMAP_IN].name)
8562 json_object_string_add(
8563 json_addr, "routeMapForIncomingAdvertisements",
8564 filter->map[RMAP_IN].name);
8565 if (filter->map[RMAP_OUT].name)
8566 json_object_string_add(
8567 json_addr, "routeMapForOutgoingAdvertisements",
8568 filter->map[RMAP_OUT].name);
8569
8570 /* unsuppress-map */
8571 if (filter->usmap.name)
8572 json_object_string_add(json_addr,
8573 "selectiveUnsuppressRouteMap",
8574 filter->usmap.name);
8575
8576 /* Receive prefix count */
8577 json_object_int_add(json_addr, "acceptedPrefixCounter",
8578 p->pcount[afi][safi]);
8579
8580 /* Maximum prefix */
8581 if (CHECK_FLAG(p->af_flags[afi][safi], PEER_FLAG_MAX_PREFIX)) {
8582 json_object_int_add(json_addr, "prefixAllowedMax",
8583 p->pmax[afi][safi]);
8584 if (CHECK_FLAG(p->af_flags[afi][safi],
8585 PEER_FLAG_MAX_PREFIX_WARNING))
8586 json_object_boolean_true_add(
8587 json_addr, "prefixAllowedMaxWarning");
8588 json_object_int_add(json_addr,
8589 "prefixAllowedWarningThresh",
8590 p->pmax_threshold[afi][safi]);
8591 if (p->pmax_restart[afi][safi])
8592 json_object_int_add(
8593 json_addr,
8594 "prefixAllowedRestartIntervalMsecs",
8595 p->pmax_restart[afi][safi] * 60000);
8596 }
8597 json_object_object_add(json_neigh, afi_safi_print(afi, safi),
8598 json_addr);
8599
8600 } else {
8601 filter = &p->filter[afi][safi];
8602
8603 vty_out(vty, " For address family: %s\n",
8604 afi_safi_print(afi, safi));
8605
8606 if (peer_group_active(p))
8607 vty_out(vty, " %s peer-group member\n",
8608 p->group->name);
8609
8610 paf = peer_af_find(p, afi, safi);
8611 if (paf && PAF_SUBGRP(paf)) {
8612 vty_out(vty, " Update group %" PRIu64
8613 ", subgroup %" PRIu64 "\n",
8614 PAF_UPDGRP(paf)->id, PAF_SUBGRP(paf)->id);
8615 vty_out(vty, " Packet Queue length %d\n",
8616 bpacket_queue_virtual_length(paf));
8617 } else {
8618 vty_out(vty, " Not part of any update group\n");
8619 }
8620 if (CHECK_FLAG(p->af_cap[afi][safi], PEER_CAP_ORF_PREFIX_SM_ADV)
8621 || CHECK_FLAG(p->af_cap[afi][safi],
8622 PEER_CAP_ORF_PREFIX_SM_RCV)
8623 || CHECK_FLAG(p->af_cap[afi][safi],
8624 PEER_CAP_ORF_PREFIX_SM_OLD_RCV)
8625 || CHECK_FLAG(p->af_cap[afi][safi],
8626 PEER_CAP_ORF_PREFIX_RM_ADV)
8627 || CHECK_FLAG(p->af_cap[afi][safi],
8628 PEER_CAP_ORF_PREFIX_RM_RCV)
8629 || CHECK_FLAG(p->af_cap[afi][safi],
8630 PEER_CAP_ORF_PREFIX_RM_OLD_RCV))
8631 vty_out(vty, " AF-dependant capabilities:\n");
8632
8633 if (CHECK_FLAG(p->af_cap[afi][safi], PEER_CAP_ORF_PREFIX_SM_ADV)
8634 || CHECK_FLAG(p->af_cap[afi][safi],
8635 PEER_CAP_ORF_PREFIX_SM_RCV)
8636 || CHECK_FLAG(p->af_cap[afi][safi],
8637 PEER_CAP_ORF_PREFIX_RM_ADV)
8638 || CHECK_FLAG(p->af_cap[afi][safi],
8639 PEER_CAP_ORF_PREFIX_RM_RCV)) {
8640 vty_out(vty,
8641 " Outbound Route Filter (ORF) type (%d) Prefix-list:\n",
8642 ORF_TYPE_PREFIX);
8643 bgp_show_peer_afi_orf_cap(
8644 vty, p, afi, safi, PEER_CAP_ORF_PREFIX_SM_ADV,
8645 PEER_CAP_ORF_PREFIX_RM_ADV,
8646 PEER_CAP_ORF_PREFIX_SM_RCV,
8647 PEER_CAP_ORF_PREFIX_RM_RCV, use_json, NULL);
8648 }
8649 if (CHECK_FLAG(p->af_cap[afi][safi], PEER_CAP_ORF_PREFIX_SM_ADV)
8650 || CHECK_FLAG(p->af_cap[afi][safi],
8651 PEER_CAP_ORF_PREFIX_SM_OLD_RCV)
8652 || CHECK_FLAG(p->af_cap[afi][safi],
8653 PEER_CAP_ORF_PREFIX_RM_ADV)
8654 || CHECK_FLAG(p->af_cap[afi][safi],
8655 PEER_CAP_ORF_PREFIX_RM_OLD_RCV)) {
8656 vty_out(vty,
8657 " Outbound Route Filter (ORF) type (%d) Prefix-list:\n",
8658 ORF_TYPE_PREFIX_OLD);
8659 bgp_show_peer_afi_orf_cap(
8660 vty, p, afi, safi, PEER_CAP_ORF_PREFIX_SM_ADV,
8661 PEER_CAP_ORF_PREFIX_RM_ADV,
8662 PEER_CAP_ORF_PREFIX_SM_OLD_RCV,
8663 PEER_CAP_ORF_PREFIX_RM_OLD_RCV, use_json, NULL);
8664 }
8665
8666 sprintf(orf_pfx_name, "%s.%d.%d", p->host, afi, safi);
8667 orf_pfx_count = prefix_bgp_show_prefix_list(
8668 NULL, afi, orf_pfx_name, use_json);
8669
8670 if (CHECK_FLAG(p->af_sflags[afi][safi],
8671 PEER_STATUS_ORF_PREFIX_SEND)
8672 || orf_pfx_count) {
8673 vty_out(vty, " Outbound Route Filter (ORF):");
8674 if (CHECK_FLAG(p->af_sflags[afi][safi],
8675 PEER_STATUS_ORF_PREFIX_SEND))
8676 vty_out(vty, " sent;");
8677 if (orf_pfx_count)
8678 vty_out(vty, " received (%d entries)",
8679 orf_pfx_count);
8680 vty_out(vty, "\n");
8681 }
8682 if (CHECK_FLAG(p->af_sflags[afi][safi],
8683 PEER_STATUS_ORF_WAIT_REFRESH))
8684 vty_out(vty,
8685 " First update is deferred until ORF or ROUTE-REFRESH is received\n");
8686
8687 if (CHECK_FLAG(p->af_flags[afi][safi],
8688 PEER_FLAG_REFLECTOR_CLIENT))
8689 vty_out(vty, " Route-Reflector Client\n");
8690 if (CHECK_FLAG(p->af_flags[afi][safi],
8691 PEER_FLAG_RSERVER_CLIENT))
8692 vty_out(vty, " Route-Server Client\n");
8693 if (CHECK_FLAG(p->af_flags[afi][safi], PEER_FLAG_SOFT_RECONFIG))
8694 vty_out(vty,
8695 " Inbound soft reconfiguration allowed\n");
8696
8697 if (CHECK_FLAG(p->af_flags[afi][safi],
8698 PEER_FLAG_REMOVE_PRIVATE_AS_ALL_REPLACE))
8699 vty_out(vty,
8700 " Private AS numbers (all) replaced in updates to this neighbor\n");
8701 else if (CHECK_FLAG(p->af_flags[afi][safi],
8702 PEER_FLAG_REMOVE_PRIVATE_AS_REPLACE))
8703 vty_out(vty,
8704 " Private AS numbers replaced in updates to this neighbor\n");
8705 else if (CHECK_FLAG(p->af_flags[afi][safi],
8706 PEER_FLAG_REMOVE_PRIVATE_AS_ALL))
8707 vty_out(vty,
8708 " Private AS numbers (all) removed in updates to this neighbor\n");
8709 else if (CHECK_FLAG(p->af_flags[afi][safi],
8710 PEER_FLAG_REMOVE_PRIVATE_AS))
8711 vty_out(vty,
8712 " Private AS numbers removed in updates to this neighbor\n");
8713
8714 if (CHECK_FLAG(p->af_flags[afi][safi],
8715 PEER_FLAG_ADDPATH_TX_ALL_PATHS))
8716 vty_out(vty, " Advertise all paths via addpath\n");
8717
8718 if (CHECK_FLAG(p->af_flags[afi][safi],
8719 PEER_FLAG_ADDPATH_TX_BESTPATH_PER_AS))
8720 vty_out(vty,
8721 " Advertise bestpath per AS via addpath\n");
8722
8723 if (CHECK_FLAG(p->af_flags[afi][safi], PEER_FLAG_AS_OVERRIDE))
8724 vty_out(vty,
8725 " Override ASNs in outbound updates if aspath equals remote-as\n");
8726
8727 if (CHECK_FLAG(p->af_flags[afi][safi], PEER_FLAG_NEXTHOP_SELF)
8728 || CHECK_FLAG(p->af_flags[afi][safi],
8729 PEER_FLAG_FORCE_NEXTHOP_SELF))
8730 vty_out(vty, " NEXT_HOP is always this router\n");
8731 if (CHECK_FLAG(p->af_flags[afi][safi],
8732 PEER_FLAG_AS_PATH_UNCHANGED))
8733 vty_out(vty,
8734 " AS_PATH is propagated unchanged to this neighbor\n");
8735 if (CHECK_FLAG(p->af_flags[afi][safi],
8736 PEER_FLAG_NEXTHOP_UNCHANGED))
8737 vty_out(vty,
8738 " NEXT_HOP is propagated unchanged to this neighbor\n");
8739 if (CHECK_FLAG(p->af_flags[afi][safi], PEER_FLAG_MED_UNCHANGED))
8740 vty_out(vty,
8741 " MED is propagated unchanged to this neighbor\n");
8742 if (CHECK_FLAG(p->af_flags[afi][safi], PEER_FLAG_SEND_COMMUNITY)
8743 || CHECK_FLAG(p->af_flags[afi][safi],
8744 PEER_FLAG_SEND_EXT_COMMUNITY)
8745 || CHECK_FLAG(p->af_flags[afi][safi],
8746 PEER_FLAG_SEND_LARGE_COMMUNITY)) {
8747 vty_out(vty,
8748 " Community attribute sent to this neighbor");
8749 if (CHECK_FLAG(p->af_flags[afi][safi],
8750 PEER_FLAG_SEND_COMMUNITY)
8751 && CHECK_FLAG(p->af_flags[afi][safi],
8752 PEER_FLAG_SEND_EXT_COMMUNITY)
8753 && CHECK_FLAG(p->af_flags[afi][safi],
8754 PEER_FLAG_SEND_LARGE_COMMUNITY))
8755 vty_out(vty, "(all)\n");
8756 else if (CHECK_FLAG(p->af_flags[afi][safi],
8757 PEER_FLAG_SEND_LARGE_COMMUNITY))
8758 vty_out(vty, "(large)\n");
8759 else if (CHECK_FLAG(p->af_flags[afi][safi],
8760 PEER_FLAG_SEND_EXT_COMMUNITY))
8761 vty_out(vty, "(extended)\n");
8762 else
8763 vty_out(vty, "(standard)\n");
8764 }
8765 if (CHECK_FLAG(p->af_flags[afi][safi],
8766 PEER_FLAG_DEFAULT_ORIGINATE)) {
8767 vty_out(vty, " Default information originate,");
8768
8769 if (p->default_rmap[afi][safi].name)
8770 vty_out(vty, " default route-map %s%s,",
8771 p->default_rmap[afi][safi].map ? "*"
8772 : "",
8773 p->default_rmap[afi][safi].name);
8774 if (paf && PAF_SUBGRP(paf)
8775 && CHECK_FLAG(PAF_SUBGRP(paf)->sflags,
8776 SUBGRP_STATUS_DEFAULT_ORIGINATE))
8777 vty_out(vty, " default sent\n");
8778 else
8779 vty_out(vty, " default not sent\n");
8780 }
8781
8782 /* advertise-vni-all */
8783 if (afi == AFI_L2VPN && safi == SAFI_EVPN) {
8784 if (is_evpn_enabled())
8785 vty_out(vty, " advertise-all-vni\n");
8786 }
8787
8788 if (filter->plist[FILTER_IN].name
8789 || filter->dlist[FILTER_IN].name
8790 || filter->aslist[FILTER_IN].name
8791 || filter->map[RMAP_IN].name)
8792 vty_out(vty, " Inbound path policy configured\n");
8793 if (filter->plist[FILTER_OUT].name
8794 || filter->dlist[FILTER_OUT].name
8795 || filter->aslist[FILTER_OUT].name
8796 || filter->map[RMAP_OUT].name || filter->usmap.name)
8797 vty_out(vty, " Outbound path policy configured\n");
8798
8799 /* prefix-list */
8800 if (filter->plist[FILTER_IN].name)
8801 vty_out(vty,
8802 " Incoming update prefix filter list is %s%s\n",
8803 filter->plist[FILTER_IN].plist ? "*" : "",
8804 filter->plist[FILTER_IN].name);
8805 if (filter->plist[FILTER_OUT].name)
8806 vty_out(vty,
8807 " Outgoing update prefix filter list is %s%s\n",
8808 filter->plist[FILTER_OUT].plist ? "*" : "",
8809 filter->plist[FILTER_OUT].name);
8810
8811 /* distribute-list */
8812 if (filter->dlist[FILTER_IN].name)
8813 vty_out(vty,
8814 " Incoming update network filter list is %s%s\n",
8815 filter->dlist[FILTER_IN].alist ? "*" : "",
8816 filter->dlist[FILTER_IN].name);
8817 if (filter->dlist[FILTER_OUT].name)
8818 vty_out(vty,
8819 " Outgoing update network filter list is %s%s\n",
8820 filter->dlist[FILTER_OUT].alist ? "*" : "",
8821 filter->dlist[FILTER_OUT].name);
8822
8823 /* filter-list. */
8824 if (filter->aslist[FILTER_IN].name)
8825 vty_out(vty,
8826 " Incoming update AS path filter list is %s%s\n",
8827 filter->aslist[FILTER_IN].aslist ? "*" : "",
8828 filter->aslist[FILTER_IN].name);
8829 if (filter->aslist[FILTER_OUT].name)
8830 vty_out(vty,
8831 " Outgoing update AS path filter list is %s%s\n",
8832 filter->aslist[FILTER_OUT].aslist ? "*" : "",
8833 filter->aslist[FILTER_OUT].name);
8834
8835 /* route-map. */
8836 if (filter->map[RMAP_IN].name)
8837 vty_out(vty,
8838 " Route map for incoming advertisements is %s%s\n",
8839 filter->map[RMAP_IN].map ? "*" : "",
8840 filter->map[RMAP_IN].name);
8841 if (filter->map[RMAP_OUT].name)
8842 vty_out(vty,
8843 " Route map for outgoing advertisements is %s%s\n",
8844 filter->map[RMAP_OUT].map ? "*" : "",
8845 filter->map[RMAP_OUT].name);
8846
8847 /* unsuppress-map */
8848 if (filter->usmap.name)
8849 vty_out(vty,
8850 " Route map for selective unsuppress is %s%s\n",
8851 filter->usmap.map ? "*" : "",
8852 filter->usmap.name);
8853
8854 /* Receive prefix count */
8855 vty_out(vty, " %ld accepted prefixes\n", p->pcount[afi][safi]);
8856
8857 /* Maximum prefix */
8858 if (CHECK_FLAG(p->af_flags[afi][safi], PEER_FLAG_MAX_PREFIX)) {
8859 vty_out(vty, " Maximum prefixes allowed %ld%s\n",
8860 p->pmax[afi][safi],
8861 CHECK_FLAG(p->af_flags[afi][safi],
8862 PEER_FLAG_MAX_PREFIX_WARNING)
8863 ? " (warning-only)"
8864 : "");
8865 vty_out(vty, " Threshold for warning message %d%%",
8866 p->pmax_threshold[afi][safi]);
8867 if (p->pmax_restart[afi][safi])
8868 vty_out(vty, ", restart interval %d min",
8869 p->pmax_restart[afi][safi]);
8870 vty_out(vty, "\n");
8871 }
8872
8873 vty_out(vty, "\n");
8874 }
8875 }
8876
8877 static void bgp_show_peer(struct vty *vty, struct peer *p, uint8_t use_json,
8878 json_object *json)
8879 {
8880 struct bgp *bgp;
8881 char buf1[PREFIX2STR_BUFFER], buf[SU_ADDRSTRLEN];
8882 char timebuf[BGP_UPTIME_LEN];
8883 char dn_flag[2];
8884 const char *subcode_str;
8885 const char *code_str;
8886 afi_t afi;
8887 safi_t safi;
8888 uint16_t i;
8889 uint8_t *msg;
8890 json_object *json_neigh = NULL;
8891 time_t epoch_tbuf;
8892
8893 bgp = p->bgp;
8894
8895 if (use_json)
8896 json_neigh = json_object_new_object();
8897
8898 memset(dn_flag, '\0', sizeof(dn_flag));
8899 if (!p->conf_if && peer_dynamic_neighbor(p))
8900 dn_flag[0] = '*';
8901
8902 if (!use_json) {
8903 if (p->conf_if) /* Configured interface name. */
8904 vty_out(vty, "BGP neighbor on %s: %s, ", p->conf_if,
8905 BGP_PEER_SU_UNSPEC(p)
8906 ? "None"
8907 : sockunion2str(&p->su, buf,
8908 SU_ADDRSTRLEN));
8909 else /* Configured IP address. */
8910 vty_out(vty, "BGP neighbor is %s%s, ", dn_flag,
8911 p->host);
8912 }
8913
8914 if (use_json) {
8915 if (p->conf_if && BGP_PEER_SU_UNSPEC(p))
8916 json_object_string_add(json_neigh, "bgpNeighborAddr",
8917 "none");
8918 else if (p->conf_if && !BGP_PEER_SU_UNSPEC(p))
8919 json_object_string_add(
8920 json_neigh, "bgpNeighborAddr",
8921 sockunion2str(&p->su, buf, SU_ADDRSTRLEN));
8922
8923 json_object_int_add(json_neigh, "remoteAs", p->as);
8924
8925 if (p->change_local_as)
8926 json_object_int_add(json_neigh, "localAs",
8927 p->change_local_as);
8928 else
8929 json_object_int_add(json_neigh, "localAs", p->local_as);
8930
8931 if (CHECK_FLAG(p->flags, PEER_FLAG_LOCAL_AS_NO_PREPEND))
8932 json_object_boolean_true_add(json_neigh,
8933 "localAsNoPrepend");
8934
8935 if (CHECK_FLAG(p->flags, PEER_FLAG_LOCAL_AS_REPLACE_AS))
8936 json_object_boolean_true_add(json_neigh,
8937 "localAsReplaceAs");
8938 } else {
8939 if ((p->as_type == AS_SPECIFIED) || (p->as_type == AS_EXTERNAL)
8940 || (p->as_type == AS_INTERNAL))
8941 vty_out(vty, "remote AS %u, ", p->as);
8942 else
8943 vty_out(vty, "remote AS Unspecified, ");
8944 vty_out(vty, "local AS %u%s%s, ",
8945 p->change_local_as ? p->change_local_as : p->local_as,
8946 CHECK_FLAG(p->flags, PEER_FLAG_LOCAL_AS_NO_PREPEND)
8947 ? " no-prepend"
8948 : "",
8949 CHECK_FLAG(p->flags, PEER_FLAG_LOCAL_AS_REPLACE_AS)
8950 ? " replace-as"
8951 : "");
8952 }
8953 /* peer type internal, external, confed-internal or confed-external */
8954 if (p->as == p->local_as) {
8955 if (use_json) {
8956 if (CHECK_FLAG(bgp->config, BGP_CONFIG_CONFEDERATION))
8957 json_object_boolean_true_add(
8958 json_neigh, "nbrConfedInternalLink");
8959 else
8960 json_object_boolean_true_add(json_neigh,
8961 "nbrInternalLink");
8962 } else {
8963 if (CHECK_FLAG(bgp->config, BGP_CONFIG_CONFEDERATION))
8964 vty_out(vty, "confed-internal link\n");
8965 else
8966 vty_out(vty, "internal link\n");
8967 }
8968 } else {
8969 if (use_json) {
8970 if (CHECK_FLAG(bgp->config, BGP_CONFIG_CONFEDERATION))
8971 json_object_boolean_true_add(
8972 json_neigh, "nbrConfedExternalLink");
8973 else
8974 json_object_boolean_true_add(json_neigh,
8975 "nbrExternalLink");
8976 } else {
8977 if (bgp_confederation_peers_check(bgp, p->as))
8978 vty_out(vty, "confed-external link\n");
8979 else
8980 vty_out(vty, "external link\n");
8981 }
8982 }
8983
8984 /* Description. */
8985 if (p->desc) {
8986 if (use_json)
8987 json_object_string_add(json_neigh, "nbrDesc", p->desc);
8988 else
8989 vty_out(vty, " Description: %s\n", p->desc);
8990 }
8991
8992 if (p->hostname) {
8993 if (use_json) {
8994 if (p->hostname)
8995 json_object_string_add(json_neigh, "hostname",
8996 p->hostname);
8997
8998 if (p->domainname)
8999 json_object_string_add(json_neigh, "domainname",
9000 p->domainname);
9001 } else {
9002 if (p->domainname && (p->domainname[0] != '\0'))
9003 vty_out(vty, "Hostname: %s.%s\n", p->hostname,
9004 p->domainname);
9005 else
9006 vty_out(vty, "Hostname: %s\n", p->hostname);
9007 }
9008 }
9009
9010 /* Peer-group */
9011 if (p->group) {
9012 if (use_json) {
9013 json_object_string_add(json_neigh, "peerGroup",
9014 p->group->name);
9015
9016 if (dn_flag[0]) {
9017 struct prefix prefix, *range = NULL;
9018
9019 sockunion2hostprefix(&(p->su), &prefix);
9020 range = peer_group_lookup_dynamic_neighbor_range(
9021 p->group, &prefix);
9022
9023 if (range) {
9024 prefix2str(range, buf1, sizeof(buf1));
9025 json_object_string_add(
9026 json_neigh,
9027 "peerSubnetRangeGroup", buf1);
9028 }
9029 }
9030 } else {
9031 vty_out(vty,
9032 " Member of peer-group %s for session parameters\n",
9033 p->group->name);
9034
9035 if (dn_flag[0]) {
9036 struct prefix prefix, *range = NULL;
9037
9038 sockunion2hostprefix(&(p->su), &prefix);
9039 range = peer_group_lookup_dynamic_neighbor_range(
9040 p->group, &prefix);
9041
9042 if (range) {
9043 prefix2str(range, buf1, sizeof(buf1));
9044 vty_out(vty,
9045 " Belongs to the subnet range group: %s\n",
9046 buf1);
9047 }
9048 }
9049 }
9050 }
9051
9052 if (use_json) {
9053 /* Administrative shutdown. */
9054 if (CHECK_FLAG(p->flags, PEER_FLAG_SHUTDOWN))
9055 json_object_boolean_true_add(json_neigh,
9056 "adminShutDown");
9057
9058 /* BGP Version. */
9059 json_object_int_add(json_neigh, "bgpVersion", 4);
9060 json_object_string_add(
9061 json_neigh, "remoteRouterId",
9062 inet_ntop(AF_INET, &p->remote_id, buf1, sizeof(buf1)));
9063
9064 /* Confederation */
9065 if (CHECK_FLAG(bgp->config, BGP_CONFIG_CONFEDERATION)
9066 && bgp_confederation_peers_check(bgp, p->as))
9067 json_object_boolean_true_add(json_neigh,
9068 "nbrCommonAdmin");
9069
9070 /* Status. */
9071 json_object_string_add(
9072 json_neigh, "bgpState",
9073 lookup_msg(bgp_status_msg, p->status, NULL));
9074
9075 if (p->status == Established) {
9076 time_t uptime;
9077
9078 uptime = bgp_clock();
9079 uptime -= p->uptime;
9080 epoch_tbuf = time(NULL) - uptime;
9081
9082 #if defined(VERSION_TYPE_DEV) && CONFDATE > 20200101
9083 CPP_NOTICE(
9084 "bgpTimerUp should be deprecated and can be removed now");
9085 #endif
9086 /*
9087 * bgpTimerUp was miliseconds that was accurate
9088 * up to 1 day, then the value returned
9089 * became garbage. So in order to provide
9090 * some level of backwards compatability,
9091 * we still provde the data, but now
9092 * we are returning the correct value
9093 * and also adding a new bgpTimerUpMsec
9094 * which will allow us to deprecate
9095 * this eventually
9096 */
9097 json_object_int_add(json_neigh, "bgpTimerUp",
9098 uptime * 1000);
9099 json_object_int_add(json_neigh, "bgpTimerUpMsec",
9100 uptime * 1000);
9101 json_object_string_add(json_neigh, "bgpTimerUpString",
9102 peer_uptime(p->uptime, timebuf,
9103 BGP_UPTIME_LEN, 0,
9104 NULL));
9105 json_object_int_add(json_neigh,
9106 "bgpTimerUpEstablishedEpoch",
9107 epoch_tbuf);
9108 }
9109
9110 else if (p->status == Active) {
9111 if (CHECK_FLAG(p->flags, PEER_FLAG_PASSIVE))
9112 json_object_string_add(json_neigh, "bgpStateIs",
9113 "passive");
9114 else if (CHECK_FLAG(p->sflags, PEER_STATUS_NSF_WAIT))
9115 json_object_string_add(json_neigh, "bgpStateIs",
9116 "passiveNSF");
9117 }
9118
9119 /* read timer */
9120 time_t uptime;
9121 struct tm *tm;
9122
9123 uptime = bgp_clock();
9124 uptime -= p->readtime;
9125 tm = gmtime(&uptime);
9126 json_object_int_add(json_neigh, "bgpTimerLastRead",
9127 (tm->tm_sec * 1000) + (tm->tm_min * 60000)
9128 + (tm->tm_hour * 3600000));
9129
9130 uptime = bgp_clock();
9131 uptime -= p->last_write;
9132 tm = gmtime(&uptime);
9133 json_object_int_add(json_neigh, "bgpTimerLastWrite",
9134 (tm->tm_sec * 1000) + (tm->tm_min * 60000)
9135 + (tm->tm_hour * 3600000));
9136
9137 uptime = bgp_clock();
9138 uptime -= p->update_time;
9139 tm = gmtime(&uptime);
9140 json_object_int_add(json_neigh, "bgpInUpdateElapsedTimeMsecs",
9141 (tm->tm_sec * 1000) + (tm->tm_min * 60000)
9142 + (tm->tm_hour * 3600000));
9143
9144 /* Configured timer values. */
9145 json_object_int_add(json_neigh, "bgpTimerHoldTimeMsecs",
9146 p->v_holdtime * 1000);
9147 json_object_int_add(json_neigh,
9148 "bgpTimerKeepAliveIntervalMsecs",
9149 p->v_keepalive * 1000);
9150
9151 if (PEER_OR_GROUP_TIMER_SET(p)) {
9152 json_object_int_add(json_neigh,
9153 "bgpTimerConfiguredHoldTimeMsecs",
9154 p->holdtime * 1000);
9155 json_object_int_add(
9156 json_neigh,
9157 "bgpTimerConfiguredKeepAliveIntervalMsecs",
9158 p->keepalive * 1000);
9159 } else if ((bgp->default_holdtime != BGP_DEFAULT_HOLDTIME)
9160 || (bgp->default_keepalive
9161 != BGP_DEFAULT_KEEPALIVE)) {
9162 json_object_int_add(json_neigh,
9163 "bgpTimerConfiguredHoldTimeMsecs",
9164 bgp->default_holdtime);
9165 json_object_int_add(
9166 json_neigh,
9167 "bgpTimerConfiguredKeepAliveIntervalMsecs",
9168 bgp->default_keepalive);
9169 }
9170 } else {
9171 /* Administrative shutdown. */
9172 if (CHECK_FLAG(p->flags, PEER_FLAG_SHUTDOWN))
9173 vty_out(vty, " Administratively shut down\n");
9174
9175 /* BGP Version. */
9176 vty_out(vty, " BGP version 4");
9177 vty_out(vty, ", remote router ID %s\n",
9178 inet_ntop(AF_INET, &p->remote_id, buf1, sizeof(buf1)));
9179
9180 /* Confederation */
9181 if (CHECK_FLAG(bgp->config, BGP_CONFIG_CONFEDERATION)
9182 && bgp_confederation_peers_check(bgp, p->as))
9183 vty_out(vty,
9184 " Neighbor under common administration\n");
9185
9186 /* Status. */
9187 vty_out(vty, " BGP state = %s",
9188 lookup_msg(bgp_status_msg, p->status, NULL));
9189
9190 if (p->status == Established)
9191 vty_out(vty, ", up for %8s",
9192 peer_uptime(p->uptime, timebuf, BGP_UPTIME_LEN,
9193 0, NULL));
9194
9195 else if (p->status == Active) {
9196 if (CHECK_FLAG(p->flags, PEER_FLAG_PASSIVE))
9197 vty_out(vty, " (passive)");
9198 else if (CHECK_FLAG(p->sflags, PEER_STATUS_NSF_WAIT))
9199 vty_out(vty, " (NSF passive)");
9200 }
9201 vty_out(vty, "\n");
9202
9203 /* read timer */
9204 vty_out(vty, " Last read %s",
9205 peer_uptime(p->readtime, timebuf, BGP_UPTIME_LEN, 0,
9206 NULL));
9207 vty_out(vty, ", Last write %s\n",
9208 peer_uptime(p->last_write, timebuf, BGP_UPTIME_LEN, 0,
9209 NULL));
9210
9211 /* Configured timer values. */
9212 vty_out(vty,
9213 " Hold time is %d, keepalive interval is %d seconds\n",
9214 p->v_holdtime, p->v_keepalive);
9215 if (PEER_OR_GROUP_TIMER_SET(p)) {
9216 vty_out(vty, " Configured hold time is %d",
9217 p->holdtime);
9218 vty_out(vty, ", keepalive interval is %d seconds\n",
9219 p->keepalive);
9220 } else if ((bgp->default_holdtime != BGP_DEFAULT_HOLDTIME)
9221 || (bgp->default_keepalive
9222 != BGP_DEFAULT_KEEPALIVE)) {
9223 vty_out(vty, " Configured hold time is %d",
9224 bgp->default_holdtime);
9225 vty_out(vty, ", keepalive interval is %d seconds\n",
9226 bgp->default_keepalive);
9227 }
9228 }
9229 /* Capability. */
9230 if (p->status == Established) {
9231 if (p->cap || p->afc_adv[AFI_IP][SAFI_UNICAST]
9232 || p->afc_recv[AFI_IP][SAFI_UNICAST]
9233 || p->afc_adv[AFI_IP][SAFI_MULTICAST]
9234 || p->afc_recv[AFI_IP][SAFI_MULTICAST]
9235 || p->afc_adv[AFI_IP6][SAFI_UNICAST]
9236 || p->afc_recv[AFI_IP6][SAFI_UNICAST]
9237 || p->afc_adv[AFI_IP6][SAFI_MULTICAST]
9238 || p->afc_recv[AFI_IP6][SAFI_MULTICAST]
9239 || p->afc_adv[AFI_IP6][SAFI_MPLS_VPN]
9240 || p->afc_recv[AFI_IP6][SAFI_MPLS_VPN]
9241 || p->afc_adv[AFI_IP6][SAFI_ENCAP]
9242 || p->afc_recv[AFI_IP6][SAFI_ENCAP]
9243 || p->afc_adv[AFI_IP6][SAFI_FLOWSPEC]
9244 || p->afc_recv[AFI_IP6][SAFI_FLOWSPEC]
9245 || p->afc_adv[AFI_IP][SAFI_ENCAP]
9246 || p->afc_recv[AFI_IP][SAFI_ENCAP]
9247 || p->afc_adv[AFI_IP][SAFI_FLOWSPEC]
9248 || p->afc_recv[AFI_IP][SAFI_FLOWSPEC]
9249 || p->afc_adv[AFI_IP][SAFI_MPLS_VPN]
9250 || p->afc_recv[AFI_IP][SAFI_MPLS_VPN]) {
9251 if (use_json) {
9252 json_object *json_cap = NULL;
9253
9254 json_cap = json_object_new_object();
9255
9256 /* AS4 */
9257 if (CHECK_FLAG(p->cap, PEER_CAP_AS4_RCV)
9258 || CHECK_FLAG(p->cap, PEER_CAP_AS4_ADV)) {
9259 if (CHECK_FLAG(p->cap, PEER_CAP_AS4_ADV)
9260 && CHECK_FLAG(p->cap,
9261 PEER_CAP_AS4_RCV))
9262 json_object_string_add(
9263 json_cap, "4byteAs",
9264 "advertisedAndReceived");
9265 else if (CHECK_FLAG(p->cap,
9266 PEER_CAP_AS4_ADV))
9267 json_object_string_add(
9268 json_cap, "4byteAs",
9269 "advertised");
9270 else if (CHECK_FLAG(p->cap,
9271 PEER_CAP_AS4_RCV))
9272 json_object_string_add(
9273 json_cap, "4byteAs",
9274 "received");
9275 }
9276
9277 /* AddPath */
9278 if (CHECK_FLAG(p->cap, PEER_CAP_ADDPATH_RCV)
9279 || CHECK_FLAG(p->cap,
9280 PEER_CAP_ADDPATH_ADV)) {
9281 json_object *json_add = NULL;
9282 const char *print_store;
9283
9284 json_add = json_object_new_object();
9285
9286 FOREACH_AFI_SAFI (afi, safi) {
9287 json_object *json_sub = NULL;
9288 json_sub =
9289 json_object_new_object();
9290 print_store = afi_safi_print(
9291 afi, safi);
9292
9293 if (CHECK_FLAG(
9294 p->af_cap[afi]
9295 [safi],
9296 PEER_CAP_ADDPATH_AF_TX_ADV)
9297 || CHECK_FLAG(
9298 p->af_cap[afi]
9299 [safi],
9300 PEER_CAP_ADDPATH_AF_TX_RCV)) {
9301 if (CHECK_FLAG(
9302 p->af_cap
9303 [afi]
9304 [safi],
9305 PEER_CAP_ADDPATH_AF_TX_ADV)
9306 && CHECK_FLAG(
9307 p->af_cap
9308 [afi]
9309 [safi],
9310 PEER_CAP_ADDPATH_AF_TX_RCV))
9311 json_object_boolean_true_add(
9312 json_sub,
9313 "txAdvertisedAndReceived");
9314 else if (
9315 CHECK_FLAG(
9316 p->af_cap
9317 [afi]
9318 [safi],
9319 PEER_CAP_ADDPATH_AF_TX_ADV))
9320 json_object_boolean_true_add(
9321 json_sub,
9322 "txAdvertised");
9323 else if (
9324 CHECK_FLAG(
9325 p->af_cap
9326 [afi]
9327 [safi],
9328 PEER_CAP_ADDPATH_AF_TX_RCV))
9329 json_object_boolean_true_add(
9330 json_sub,
9331 "txReceived");
9332 }
9333
9334 if (CHECK_FLAG(
9335 p->af_cap[afi]
9336 [safi],
9337 PEER_CAP_ADDPATH_AF_RX_ADV)
9338 || CHECK_FLAG(
9339 p->af_cap[afi]
9340 [safi],
9341 PEER_CAP_ADDPATH_AF_RX_RCV)) {
9342 if (CHECK_FLAG(
9343 p->af_cap
9344 [afi]
9345 [safi],
9346 PEER_CAP_ADDPATH_AF_RX_ADV)
9347 && CHECK_FLAG(
9348 p->af_cap
9349 [afi]
9350 [safi],
9351 PEER_CAP_ADDPATH_AF_RX_RCV))
9352 json_object_boolean_true_add(
9353 json_sub,
9354 "rxAdvertisedAndReceived");
9355 else if (
9356 CHECK_FLAG(
9357 p->af_cap
9358 [afi]
9359 [safi],
9360 PEER_CAP_ADDPATH_AF_RX_ADV))
9361 json_object_boolean_true_add(
9362 json_sub,
9363 "rxAdvertised");
9364 else if (
9365 CHECK_FLAG(
9366 p->af_cap
9367 [afi]
9368 [safi],
9369 PEER_CAP_ADDPATH_AF_RX_RCV))
9370 json_object_boolean_true_add(
9371 json_sub,
9372 "rxReceived");
9373 }
9374
9375 if (CHECK_FLAG(
9376 p->af_cap[afi]
9377 [safi],
9378 PEER_CAP_ADDPATH_AF_TX_ADV)
9379 || CHECK_FLAG(
9380 p->af_cap[afi]
9381 [safi],
9382 PEER_CAP_ADDPATH_AF_TX_RCV)
9383 || CHECK_FLAG(
9384 p->af_cap[afi]
9385 [safi],
9386 PEER_CAP_ADDPATH_AF_RX_ADV)
9387 || CHECK_FLAG(
9388 p->af_cap[afi]
9389 [safi],
9390 PEER_CAP_ADDPATH_AF_RX_RCV))
9391 json_object_object_add(
9392 json_add,
9393 print_store,
9394 json_sub);
9395 else
9396 json_object_free(
9397 json_sub);
9398 }
9399
9400 json_object_object_add(
9401 json_cap, "addPath", json_add);
9402 }
9403
9404 /* Dynamic */
9405 if (CHECK_FLAG(p->cap, PEER_CAP_DYNAMIC_RCV)
9406 || CHECK_FLAG(p->cap,
9407 PEER_CAP_DYNAMIC_ADV)) {
9408 if (CHECK_FLAG(p->cap,
9409 PEER_CAP_DYNAMIC_ADV)
9410 && CHECK_FLAG(p->cap,
9411 PEER_CAP_DYNAMIC_RCV))
9412 json_object_string_add(
9413 json_cap, "dynamic",
9414 "advertisedAndReceived");
9415 else if (CHECK_FLAG(
9416 p->cap,
9417 PEER_CAP_DYNAMIC_ADV))
9418 json_object_string_add(
9419 json_cap, "dynamic",
9420 "advertised");
9421 else if (CHECK_FLAG(
9422 p->cap,
9423 PEER_CAP_DYNAMIC_RCV))
9424 json_object_string_add(
9425 json_cap, "dynamic",
9426 "received");
9427 }
9428
9429 /* Extended nexthop */
9430 if (CHECK_FLAG(p->cap, PEER_CAP_ENHE_RCV)
9431 || CHECK_FLAG(p->cap, PEER_CAP_ENHE_ADV)) {
9432 json_object *json_nxt = NULL;
9433 const char *print_store;
9434
9435
9436 if (CHECK_FLAG(p->cap,
9437 PEER_CAP_ENHE_ADV)
9438 && CHECK_FLAG(p->cap,
9439 PEER_CAP_ENHE_RCV))
9440 json_object_string_add(
9441 json_cap,
9442 "extendedNexthop",
9443 "advertisedAndReceived");
9444 else if (CHECK_FLAG(p->cap,
9445 PEER_CAP_ENHE_ADV))
9446 json_object_string_add(
9447 json_cap,
9448 "extendedNexthop",
9449 "advertised");
9450 else if (CHECK_FLAG(p->cap,
9451 PEER_CAP_ENHE_RCV))
9452 json_object_string_add(
9453 json_cap,
9454 "extendedNexthop",
9455 "received");
9456
9457 if (CHECK_FLAG(p->cap,
9458 PEER_CAP_ENHE_RCV)) {
9459 json_nxt =
9460 json_object_new_object();
9461
9462 for (safi = SAFI_UNICAST;
9463 safi < SAFI_MAX; safi++) {
9464 if (CHECK_FLAG(
9465 p->af_cap
9466 [AFI_IP]
9467 [safi],
9468 PEER_CAP_ENHE_AF_RCV)) {
9469 print_store = afi_safi_print(
9470 AFI_IP,
9471 safi);
9472 json_object_string_add(
9473 json_nxt,
9474 print_store,
9475 "recieved");
9476 }
9477 }
9478 json_object_object_add(
9479 json_cap,
9480 "extendedNexthopFamililesByPeer",
9481 json_nxt);
9482 }
9483 }
9484
9485 /* Route Refresh */
9486 if (CHECK_FLAG(p->cap, PEER_CAP_REFRESH_ADV)
9487 || CHECK_FLAG(p->cap,
9488 PEER_CAP_REFRESH_NEW_RCV)
9489 || CHECK_FLAG(p->cap,
9490 PEER_CAP_REFRESH_OLD_RCV)) {
9491 if (CHECK_FLAG(p->cap,
9492 PEER_CAP_REFRESH_ADV)
9493 && (CHECK_FLAG(
9494 p->cap,
9495 PEER_CAP_REFRESH_NEW_RCV)
9496 || CHECK_FLAG(
9497 p->cap,
9498 PEER_CAP_REFRESH_OLD_RCV))) {
9499 if (CHECK_FLAG(
9500 p->cap,
9501 PEER_CAP_REFRESH_OLD_RCV)
9502 && CHECK_FLAG(
9503 p->cap,
9504 PEER_CAP_REFRESH_NEW_RCV))
9505 json_object_string_add(
9506 json_cap,
9507 "routeRefresh",
9508 "advertisedAndReceivedOldNew");
9509 else {
9510 if (CHECK_FLAG(
9511 p->cap,
9512 PEER_CAP_REFRESH_OLD_RCV))
9513 json_object_string_add(
9514 json_cap,
9515 "routeRefresh",
9516 "advertisedAndReceivedOld");
9517 else
9518 json_object_string_add(
9519 json_cap,
9520 "routeRefresh",
9521 "advertisedAndReceivedNew");
9522 }
9523 } else if (
9524 CHECK_FLAG(
9525 p->cap,
9526 PEER_CAP_REFRESH_ADV))
9527 json_object_string_add(
9528 json_cap,
9529 "routeRefresh",
9530 "advertised");
9531 else if (
9532 CHECK_FLAG(
9533 p->cap,
9534 PEER_CAP_REFRESH_NEW_RCV)
9535 || CHECK_FLAG(
9536 p->cap,
9537 PEER_CAP_REFRESH_OLD_RCV))
9538 json_object_string_add(
9539 json_cap,
9540 "routeRefresh",
9541 "received");
9542 }
9543
9544 /* Multiprotocol Extensions */
9545 json_object *json_multi = NULL;
9546 json_multi = json_object_new_object();
9547
9548 FOREACH_AFI_SAFI (afi, safi) {
9549 if (p->afc_adv[afi][safi]
9550 || p->afc_recv[afi][safi]) {
9551 json_object *json_exten = NULL;
9552 json_exten =
9553 json_object_new_object();
9554
9555 if (p->afc_adv[afi][safi]
9556 && p->afc_recv[afi][safi])
9557 json_object_boolean_true_add(
9558 json_exten,
9559 "advertisedAndReceived");
9560 else if (p->afc_adv[afi][safi])
9561 json_object_boolean_true_add(
9562 json_exten,
9563 "advertised");
9564 else if (p->afc_recv[afi][safi])
9565 json_object_boolean_true_add(
9566 json_exten,
9567 "received");
9568
9569 json_object_object_add(
9570 json_multi,
9571 afi_safi_print(afi,
9572 safi),
9573 json_exten);
9574 }
9575 }
9576 json_object_object_add(
9577 json_cap, "multiprotocolExtensions",
9578 json_multi);
9579
9580 /* Hostname capabilities */
9581 json_object *json_hname = NULL;
9582
9583 json_hname = json_object_new_object();
9584
9585 if (CHECK_FLAG(p->cap, PEER_CAP_HOSTNAME_ADV)) {
9586 json_object_string_add(
9587 json_hname, "advHostName",
9588 bgp->peer_self->hostname
9589 ? bgp->peer_self
9590 ->hostname
9591 : "n/a");
9592 json_object_string_add(
9593 json_hname, "advDomainName",
9594 bgp->peer_self->domainname
9595 ? bgp->peer_self
9596 ->domainname
9597 : "n/a");
9598 }
9599
9600
9601 if (CHECK_FLAG(p->cap, PEER_CAP_HOSTNAME_RCV)) {
9602 json_object_string_add(
9603 json_hname, "rcvHostName",
9604 p->hostname ? p->hostname
9605 : "n/a");
9606 json_object_string_add(
9607 json_hname, "rcvDomainName",
9608 p->domainname ? p->domainname
9609 : "n/a");
9610 }
9611
9612 json_object_object_add(json_cap, "hostName",
9613 json_hname);
9614
9615 /* Gracefull Restart */
9616 if (CHECK_FLAG(p->cap, PEER_CAP_RESTART_RCV)
9617 || CHECK_FLAG(p->cap,
9618 PEER_CAP_RESTART_ADV)) {
9619 if (CHECK_FLAG(p->cap,
9620 PEER_CAP_RESTART_ADV)
9621 && CHECK_FLAG(p->cap,
9622 PEER_CAP_RESTART_RCV))
9623 json_object_string_add(
9624 json_cap,
9625 "gracefulRestart",
9626 "advertisedAndReceived");
9627 else if (CHECK_FLAG(
9628 p->cap,
9629 PEER_CAP_RESTART_ADV))
9630 json_object_string_add(
9631 json_cap,
9632 "gracefulRestartCapability",
9633 "advertised");
9634 else if (CHECK_FLAG(
9635 p->cap,
9636 PEER_CAP_RESTART_RCV))
9637 json_object_string_add(
9638 json_cap,
9639 "gracefulRestartCapability",
9640 "received");
9641
9642 if (CHECK_FLAG(p->cap,
9643 PEER_CAP_RESTART_RCV)) {
9644 int restart_af_count = 0;
9645 json_object *json_restart =
9646 NULL;
9647 json_restart =
9648 json_object_new_object();
9649
9650 json_object_int_add(
9651 json_cap,
9652 "gracefulRestartRemoteTimerMsecs",
9653 p->v_gr_restart * 1000);
9654
9655 FOREACH_AFI_SAFI (afi, safi) {
9656 if (CHECK_FLAG(
9657 p->af_cap
9658 [afi]
9659 [safi],
9660 PEER_CAP_RESTART_AF_RCV)) {
9661 json_object *
9662 json_sub =
9663 NULL;
9664 json_sub =
9665 json_object_new_object();
9666
9667 if (CHECK_FLAG(
9668 p->af_cap
9669 [afi]
9670 [safi],
9671 PEER_CAP_RESTART_AF_PRESERVE_RCV))
9672 json_object_boolean_true_add(
9673 json_sub,
9674 "preserved");
9675 restart_af_count++;
9676 json_object_object_add(
9677 json_restart,
9678 afi_safi_print(
9679 afi,
9680 safi),
9681 json_sub);
9682 }
9683 }
9684 if (!restart_af_count) {
9685 json_object_string_add(
9686 json_cap,
9687 "addressFamiliesByPeer",
9688 "none");
9689 json_object_free(
9690 json_restart);
9691 } else
9692 json_object_object_add(
9693 json_cap,
9694 "addressFamiliesByPeer",
9695 json_restart);
9696 }
9697 }
9698 json_object_object_add(json_neigh,
9699 "neighborCapabilities",
9700 json_cap);
9701 } else {
9702 vty_out(vty, " Neighbor capabilities:\n");
9703
9704 /* AS4 */
9705 if (CHECK_FLAG(p->cap, PEER_CAP_AS4_RCV)
9706 || CHECK_FLAG(p->cap, PEER_CAP_AS4_ADV)) {
9707 vty_out(vty, " 4 Byte AS:");
9708 if (CHECK_FLAG(p->cap,
9709 PEER_CAP_AS4_ADV))
9710 vty_out(vty, " advertised");
9711 if (CHECK_FLAG(p->cap,
9712 PEER_CAP_AS4_RCV))
9713 vty_out(vty, " %sreceived",
9714 CHECK_FLAG(
9715 p->cap,
9716 PEER_CAP_AS4_ADV)
9717 ? "and "
9718 : "");
9719 vty_out(vty, "\n");
9720 }
9721
9722 /* AddPath */
9723 if (CHECK_FLAG(p->cap, PEER_CAP_ADDPATH_RCV)
9724 || CHECK_FLAG(p->cap,
9725 PEER_CAP_ADDPATH_ADV)) {
9726 vty_out(vty, " AddPath:\n");
9727
9728 FOREACH_AFI_SAFI (afi, safi) {
9729 if (CHECK_FLAG(
9730 p->af_cap[afi]
9731 [safi],
9732 PEER_CAP_ADDPATH_AF_TX_ADV)
9733 || CHECK_FLAG(
9734 p->af_cap[afi]
9735 [safi],
9736 PEER_CAP_ADDPATH_AF_TX_RCV)) {
9737 vty_out(vty,
9738 " %s: TX ",
9739 afi_safi_print(
9740 afi,
9741 safi));
9742
9743 if (CHECK_FLAG(
9744 p->af_cap
9745 [afi]
9746 [safi],
9747 PEER_CAP_ADDPATH_AF_TX_ADV))
9748 vty_out(vty,
9749 "advertised %s",
9750 afi_safi_print(
9751 afi,
9752 safi));
9753
9754 if (CHECK_FLAG(
9755 p->af_cap
9756 [afi]
9757 [safi],
9758 PEER_CAP_ADDPATH_AF_TX_RCV))
9759 vty_out(vty,
9760 "%sreceived",
9761 CHECK_FLAG(
9762 p->af_cap
9763 [afi]
9764 [safi],
9765 PEER_CAP_ADDPATH_AF_TX_ADV)
9766 ? " and "
9767 : "");
9768
9769 vty_out(vty, "\n");
9770 }
9771
9772 if (CHECK_FLAG(
9773 p->af_cap[afi]
9774 [safi],
9775 PEER_CAP_ADDPATH_AF_RX_ADV)
9776 || CHECK_FLAG(
9777 p->af_cap[afi]
9778 [safi],
9779 PEER_CAP_ADDPATH_AF_RX_RCV)) {
9780 vty_out(vty,
9781 " %s: RX ",
9782 afi_safi_print(
9783 afi,
9784 safi));
9785
9786 if (CHECK_FLAG(
9787 p->af_cap
9788 [afi]
9789 [safi],
9790 PEER_CAP_ADDPATH_AF_RX_ADV))
9791 vty_out(vty,
9792 "advertised %s",
9793 afi_safi_print(
9794 afi,
9795 safi));
9796
9797 if (CHECK_FLAG(
9798 p->af_cap
9799 [afi]
9800 [safi],
9801 PEER_CAP_ADDPATH_AF_RX_RCV))
9802 vty_out(vty,
9803 "%sreceived",
9804 CHECK_FLAG(
9805 p->af_cap
9806 [afi]
9807 [safi],
9808 PEER_CAP_ADDPATH_AF_RX_ADV)
9809 ? " and "
9810 : "");
9811
9812 vty_out(vty, "\n");
9813 }
9814 }
9815 }
9816
9817 /* Dynamic */
9818 if (CHECK_FLAG(p->cap, PEER_CAP_DYNAMIC_RCV)
9819 || CHECK_FLAG(p->cap,
9820 PEER_CAP_DYNAMIC_ADV)) {
9821 vty_out(vty, " Dynamic:");
9822 if (CHECK_FLAG(p->cap,
9823 PEER_CAP_DYNAMIC_ADV))
9824 vty_out(vty, " advertised");
9825 if (CHECK_FLAG(p->cap,
9826 PEER_CAP_DYNAMIC_RCV))
9827 vty_out(vty, " %sreceived",
9828 CHECK_FLAG(
9829 p->cap,
9830 PEER_CAP_DYNAMIC_ADV)
9831 ? "and "
9832 : "");
9833 vty_out(vty, "\n");
9834 }
9835
9836 /* Extended nexthop */
9837 if (CHECK_FLAG(p->cap, PEER_CAP_ENHE_RCV)
9838 || CHECK_FLAG(p->cap, PEER_CAP_ENHE_ADV)) {
9839 vty_out(vty, " Extended nexthop:");
9840 if (CHECK_FLAG(p->cap,
9841 PEER_CAP_ENHE_ADV))
9842 vty_out(vty, " advertised");
9843 if (CHECK_FLAG(p->cap,
9844 PEER_CAP_ENHE_RCV))
9845 vty_out(vty, " %sreceived",
9846 CHECK_FLAG(
9847 p->cap,
9848 PEER_CAP_ENHE_ADV)
9849 ? "and "
9850 : "");
9851 vty_out(vty, "\n");
9852
9853 if (CHECK_FLAG(p->cap,
9854 PEER_CAP_ENHE_RCV)) {
9855 vty_out(vty,
9856 " Address families by peer:\n ");
9857 for (safi = SAFI_UNICAST;
9858 safi < SAFI_MAX; safi++)
9859 if (CHECK_FLAG(
9860 p->af_cap
9861 [AFI_IP]
9862 [safi],
9863 PEER_CAP_ENHE_AF_RCV))
9864 vty_out(vty,
9865 " %s\n",
9866 afi_safi_print(
9867 AFI_IP,
9868 safi));
9869 }
9870 }
9871
9872 /* Route Refresh */
9873 if (CHECK_FLAG(p->cap, PEER_CAP_REFRESH_ADV)
9874 || CHECK_FLAG(p->cap,
9875 PEER_CAP_REFRESH_NEW_RCV)
9876 || CHECK_FLAG(p->cap,
9877 PEER_CAP_REFRESH_OLD_RCV)) {
9878 vty_out(vty, " Route refresh:");
9879 if (CHECK_FLAG(p->cap,
9880 PEER_CAP_REFRESH_ADV))
9881 vty_out(vty, " advertised");
9882 if (CHECK_FLAG(p->cap,
9883 PEER_CAP_REFRESH_NEW_RCV)
9884 || CHECK_FLAG(
9885 p->cap,
9886 PEER_CAP_REFRESH_OLD_RCV))
9887 vty_out(vty, " %sreceived(%s)",
9888 CHECK_FLAG(
9889 p->cap,
9890 PEER_CAP_REFRESH_ADV)
9891 ? "and "
9892 : "",
9893 (CHECK_FLAG(
9894 p->cap,
9895 PEER_CAP_REFRESH_OLD_RCV)
9896 && CHECK_FLAG(
9897 p->cap,
9898 PEER_CAP_REFRESH_NEW_RCV))
9899 ? "old & new"
9900 : CHECK_FLAG(
9901 p->cap,
9902 PEER_CAP_REFRESH_OLD_RCV)
9903 ? "old"
9904 : "new");
9905
9906 vty_out(vty, "\n");
9907 }
9908
9909 /* Multiprotocol Extensions */
9910 FOREACH_AFI_SAFI (afi, safi)
9911 if (p->afc_adv[afi][safi]
9912 || p->afc_recv[afi][safi]) {
9913 vty_out(vty,
9914 " Address Family %s:",
9915 afi_safi_print(afi,
9916 safi));
9917 if (p->afc_adv[afi][safi])
9918 vty_out(vty,
9919 " advertised");
9920 if (p->afc_recv[afi][safi])
9921 vty_out(vty,
9922 " %sreceived",
9923 p->afc_adv[afi]
9924 [safi]
9925 ? "and "
9926 : "");
9927 vty_out(vty, "\n");
9928 }
9929
9930 /* Hostname capability */
9931 vty_out(vty, " Hostname Capability:");
9932
9933 if (CHECK_FLAG(p->cap, PEER_CAP_HOSTNAME_ADV)) {
9934 vty_out(vty,
9935 " advertised (name: %s,domain name: %s)",
9936 bgp->peer_self->hostname
9937 ? bgp->peer_self
9938 ->hostname
9939 : "n/a",
9940 bgp->peer_self->domainname
9941 ? bgp->peer_self
9942 ->domainname
9943 : "n/a");
9944 } else {
9945 vty_out(vty, " not advertised");
9946 }
9947
9948 if (CHECK_FLAG(p->cap, PEER_CAP_HOSTNAME_RCV)) {
9949 vty_out(vty,
9950 " received (name: %s,domain name: %s)",
9951 p->hostname ? p->hostname
9952 : "n/a",
9953 p->domainname ? p->domainname
9954 : "n/a");
9955 } else {
9956 vty_out(vty, " not received");
9957 }
9958
9959 vty_out(vty, "\n");
9960
9961 /* Gracefull Restart */
9962 if (CHECK_FLAG(p->cap, PEER_CAP_RESTART_RCV)
9963 || CHECK_FLAG(p->cap,
9964 PEER_CAP_RESTART_ADV)) {
9965 vty_out(vty,
9966 " Graceful Restart Capabilty:");
9967 if (CHECK_FLAG(p->cap,
9968 PEER_CAP_RESTART_ADV))
9969 vty_out(vty, " advertised");
9970 if (CHECK_FLAG(p->cap,
9971 PEER_CAP_RESTART_RCV))
9972 vty_out(vty, " %sreceived",
9973 CHECK_FLAG(
9974 p->cap,
9975 PEER_CAP_RESTART_ADV)
9976 ? "and "
9977 : "");
9978 vty_out(vty, "\n");
9979
9980 if (CHECK_FLAG(p->cap,
9981 PEER_CAP_RESTART_RCV)) {
9982 int restart_af_count = 0;
9983
9984 vty_out(vty,
9985 " Remote Restart timer is %d seconds\n",
9986 p->v_gr_restart);
9987 vty_out(vty,
9988 " Address families by peer:\n ");
9989
9990 FOREACH_AFI_SAFI (afi, safi)
9991 if (CHECK_FLAG(
9992 p->af_cap
9993 [afi]
9994 [safi],
9995 PEER_CAP_RESTART_AF_RCV)) {
9996 vty_out(vty,
9997 "%s%s(%s)",
9998 restart_af_count
9999 ? ", "
10000 : "",
10001 afi_safi_print(
10002 afi,
10003 safi),
10004 CHECK_FLAG(
10005 p->af_cap
10006 [afi]
10007 [safi],
10008 PEER_CAP_RESTART_AF_PRESERVE_RCV)
10009 ? "preserved"
10010 : "not preserved");
10011 restart_af_count++;
10012 }
10013 if (!restart_af_count)
10014 vty_out(vty, "none");
10015 vty_out(vty, "\n");
10016 }
10017 }
10018 }
10019 }
10020 }
10021
10022 /* graceful restart information */
10023 if (CHECK_FLAG(p->cap, PEER_CAP_RESTART_RCV) || p->t_gr_restart
10024 || p->t_gr_stale) {
10025 json_object *json_grace = NULL;
10026 json_object *json_grace_send = NULL;
10027 json_object *json_grace_recv = NULL;
10028 int eor_send_af_count = 0;
10029 int eor_receive_af_count = 0;
10030
10031 if (use_json) {
10032 json_grace = json_object_new_object();
10033 json_grace_send = json_object_new_object();
10034 json_grace_recv = json_object_new_object();
10035
10036 if (p->status == Established) {
10037 FOREACH_AFI_SAFI (afi, safi) {
10038 if (CHECK_FLAG(p->af_sflags[afi][safi],
10039 PEER_STATUS_EOR_SEND)) {
10040 json_object_boolean_true_add(
10041 json_grace_send,
10042 afi_safi_print(afi,
10043 safi));
10044 eor_send_af_count++;
10045 }
10046 }
10047 FOREACH_AFI_SAFI (afi, safi) {
10048 if (CHECK_FLAG(
10049 p->af_sflags[afi][safi],
10050 PEER_STATUS_EOR_RECEIVED)) {
10051 json_object_boolean_true_add(
10052 json_grace_recv,
10053 afi_safi_print(afi,
10054 safi));
10055 eor_receive_af_count++;
10056 }
10057 }
10058 }
10059
10060 json_object_object_add(json_grace, "endOfRibSend",
10061 json_grace_send);
10062 json_object_object_add(json_grace, "endOfRibRecv",
10063 json_grace_recv);
10064
10065 if (p->t_gr_restart)
10066 json_object_int_add(json_grace,
10067 "gracefulRestartTimerMsecs",
10068 thread_timer_remain_second(
10069 p->t_gr_restart)
10070 * 1000);
10071
10072 if (p->t_gr_stale)
10073 json_object_int_add(
10074 json_grace,
10075 "gracefulStalepathTimerMsecs",
10076 thread_timer_remain_second(
10077 p->t_gr_stale)
10078 * 1000);
10079
10080 json_object_object_add(
10081 json_neigh, "gracefulRestartInfo", json_grace);
10082 } else {
10083 vty_out(vty, " Graceful restart informations:\n");
10084 if (p->status == Established) {
10085 vty_out(vty, " End-of-RIB send: ");
10086 FOREACH_AFI_SAFI (afi, safi) {
10087 if (CHECK_FLAG(p->af_sflags[afi][safi],
10088 PEER_STATUS_EOR_SEND)) {
10089 vty_out(vty, "%s%s",
10090 eor_send_af_count ? ", "
10091 : "",
10092 afi_safi_print(afi,
10093 safi));
10094 eor_send_af_count++;
10095 }
10096 }
10097 vty_out(vty, "\n");
10098 vty_out(vty, " End-of-RIB received: ");
10099 FOREACH_AFI_SAFI (afi, safi) {
10100 if (CHECK_FLAG(
10101 p->af_sflags[afi][safi],
10102 PEER_STATUS_EOR_RECEIVED)) {
10103 vty_out(vty, "%s%s",
10104 eor_receive_af_count
10105 ? ", "
10106 : "",
10107 afi_safi_print(afi,
10108 safi));
10109 eor_receive_af_count++;
10110 }
10111 }
10112 vty_out(vty, "\n");
10113 }
10114
10115 if (p->t_gr_restart)
10116 vty_out(vty,
10117 " The remaining time of restart timer is %ld\n",
10118 thread_timer_remain_second(
10119 p->t_gr_restart));
10120
10121 if (p->t_gr_stale)
10122 vty_out(vty,
10123 " The remaining time of stalepath timer is %ld\n",
10124 thread_timer_remain_second(
10125 p->t_gr_stale));
10126 }
10127 }
10128 if (use_json) {
10129 json_object *json_stat = NULL;
10130 json_stat = json_object_new_object();
10131 /* Packet counts. */
10132 json_object_int_add(json_stat, "depthInq", 0);
10133 json_object_int_add(json_stat, "depthOutq",
10134 (unsigned long)p->obuf->count);
10135 json_object_int_add(json_stat, "opensSent",
10136 atomic_load_explicit(&p->open_out,
10137 memory_order_relaxed));
10138 json_object_int_add(json_stat, "opensRecv",
10139 atomic_load_explicit(&p->open_in,
10140 memory_order_relaxed));
10141 json_object_int_add(json_stat, "notificationsSent",
10142 atomic_load_explicit(&p->notify_out,
10143 memory_order_relaxed));
10144 json_object_int_add(json_stat, "notificationsRecv",
10145 atomic_load_explicit(&p->notify_in,
10146 memory_order_relaxed));
10147 json_object_int_add(json_stat, "updatesSent",
10148 atomic_load_explicit(&p->update_out,
10149 memory_order_relaxed));
10150 json_object_int_add(json_stat, "updatesRecv",
10151 atomic_load_explicit(&p->update_in,
10152 memory_order_relaxed));
10153 json_object_int_add(json_stat, "keepalivesSent",
10154 atomic_load_explicit(&p->keepalive_out,
10155 memory_order_relaxed));
10156 json_object_int_add(json_stat, "keepalivesRecv",
10157 atomic_load_explicit(&p->keepalive_in,
10158 memory_order_relaxed));
10159 json_object_int_add(json_stat, "routeRefreshSent",
10160 atomic_load_explicit(&p->refresh_out,
10161 memory_order_relaxed));
10162 json_object_int_add(json_stat, "routeRefreshRecv",
10163 atomic_load_explicit(&p->refresh_in,
10164 memory_order_relaxed));
10165 json_object_int_add(json_stat, "capabilitySent",
10166 atomic_load_explicit(&p->dynamic_cap_out,
10167 memory_order_relaxed));
10168 json_object_int_add(json_stat, "capabilityRecv",
10169 atomic_load_explicit(&p->dynamic_cap_in,
10170 memory_order_relaxed));
10171 json_object_int_add(json_stat, "totalSent", PEER_TOTAL_TX(p));
10172 json_object_int_add(json_stat, "totalRecv", PEER_TOTAL_RX(p));
10173 json_object_object_add(json_neigh, "messageStats", json_stat);
10174 } else {
10175 /* Packet counts. */
10176 vty_out(vty, " Message statistics:\n");
10177 vty_out(vty, " Inq depth is 0\n");
10178 vty_out(vty, " Outq depth is %lu\n",
10179 (unsigned long)p->obuf->count);
10180 vty_out(vty, " Sent Rcvd\n");
10181 vty_out(vty, " Opens: %10d %10d\n",
10182 atomic_load_explicit(&p->open_out,
10183 memory_order_relaxed),
10184 atomic_load_explicit(&p->open_in,
10185 memory_order_relaxed));
10186 vty_out(vty, " Notifications: %10d %10d\n",
10187 atomic_load_explicit(&p->notify_out,
10188 memory_order_relaxed),
10189 atomic_load_explicit(&p->notify_in,
10190 memory_order_relaxed));
10191 vty_out(vty, " Updates: %10d %10d\n",
10192 atomic_load_explicit(&p->update_out,
10193 memory_order_relaxed),
10194 atomic_load_explicit(&p->update_in,
10195 memory_order_relaxed));
10196 vty_out(vty, " Keepalives: %10d %10d\n",
10197 atomic_load_explicit(&p->keepalive_out,
10198 memory_order_relaxed),
10199 atomic_load_explicit(&p->keepalive_in,
10200 memory_order_relaxed));
10201 vty_out(vty, " Route Refresh: %10d %10d\n",
10202 atomic_load_explicit(&p->refresh_out,
10203 memory_order_relaxed),
10204 atomic_load_explicit(&p->refresh_in,
10205 memory_order_relaxed));
10206 vty_out(vty, " Capability: %10d %10d\n",
10207 atomic_load_explicit(&p->dynamic_cap_out,
10208 memory_order_relaxed),
10209 atomic_load_explicit(&p->dynamic_cap_in,
10210 memory_order_relaxed));
10211 vty_out(vty, " Total: %10d %10d\n", PEER_TOTAL_TX(p),
10212 PEER_TOTAL_RX(p));
10213 }
10214
10215 if (use_json) {
10216 /* advertisement-interval */
10217 json_object_int_add(json_neigh,
10218 "minBtwnAdvertisementRunsTimerMsecs",
10219 p->v_routeadv * 1000);
10220
10221 /* Update-source. */
10222 if (p->update_if || p->update_source) {
10223 if (p->update_if)
10224 json_object_string_add(json_neigh,
10225 "updateSource",
10226 p->update_if);
10227 else if (p->update_source)
10228 json_object_string_add(
10229 json_neigh, "updateSource",
10230 sockunion2str(p->update_source, buf1,
10231 SU_ADDRSTRLEN));
10232 }
10233 } else {
10234 /* advertisement-interval */
10235 vty_out(vty,
10236 " Minimum time between advertisement runs is %d seconds\n",
10237 p->v_routeadv);
10238
10239 /* Update-source. */
10240 if (p->update_if || p->update_source) {
10241 vty_out(vty, " Update source is ");
10242 if (p->update_if)
10243 vty_out(vty, "%s", p->update_if);
10244 else if (p->update_source)
10245 vty_out(vty, "%s",
10246 sockunion2str(p->update_source, buf1,
10247 SU_ADDRSTRLEN));
10248 vty_out(vty, "\n");
10249 }
10250
10251 vty_out(vty, "\n");
10252 }
10253
10254 /* Address Family Information */
10255 json_object *json_hold = NULL;
10256
10257 if (use_json)
10258 json_hold = json_object_new_object();
10259
10260 FOREACH_AFI_SAFI (afi, safi)
10261 if (p->afc[afi][safi])
10262 bgp_show_peer_afi(vty, p, afi, safi, use_json,
10263 json_hold);
10264
10265 if (use_json) {
10266 json_object_object_add(json_neigh, "addressFamilyInfo",
10267 json_hold);
10268 json_object_int_add(json_neigh, "connectionsEstablished",
10269 p->established);
10270 json_object_int_add(json_neigh, "connectionsDropped",
10271 p->dropped);
10272 } else
10273 vty_out(vty, " Connections established %d; dropped %d\n",
10274 p->established, p->dropped);
10275
10276 if (!p->last_reset) {
10277 if (use_json)
10278 json_object_string_add(json_neigh, "lastReset",
10279 "never");
10280 else
10281 vty_out(vty, " Last reset never\n");
10282 } else {
10283 if (use_json) {
10284 time_t uptime;
10285 struct tm *tm;
10286
10287 uptime = bgp_clock();
10288 uptime -= p->resettime;
10289 tm = gmtime(&uptime);
10290 json_object_int_add(json_neigh, "lastResetTimerMsecs",
10291 (tm->tm_sec * 1000)
10292 + (tm->tm_min * 60000)
10293 + (tm->tm_hour * 3600000));
10294 json_object_string_add(
10295 json_neigh, "lastResetDueTo",
10296 peer_down_str[(int)p->last_reset]);
10297 if (p->last_reset == PEER_DOWN_NOTIFY_SEND
10298 || p->last_reset == PEER_DOWN_NOTIFY_RECEIVED) {
10299 char errorcodesubcode_hexstr[5];
10300 char errorcodesubcode_str[256];
10301
10302 code_str = bgp_notify_code_str(p->notify.code);
10303 subcode_str = bgp_notify_subcode_str(
10304 p->notify.code, p->notify.subcode);
10305
10306 sprintf(errorcodesubcode_hexstr, "%02X%02X",
10307 p->notify.code, p->notify.subcode);
10308 json_object_string_add(json_neigh,
10309 "lastErrorCodeSubcode",
10310 errorcodesubcode_hexstr);
10311 snprintf(errorcodesubcode_str, 255, "%s%s",
10312 code_str, subcode_str);
10313 json_object_string_add(json_neigh,
10314 "lastNotificationReason",
10315 errorcodesubcode_str);
10316 if (p->last_reset == PEER_DOWN_NOTIFY_RECEIVED
10317 && p->notify.code == BGP_NOTIFY_CEASE
10318 && (p->notify.subcode
10319 == BGP_NOTIFY_CEASE_ADMIN_SHUTDOWN
10320 || p->notify.subcode
10321 == BGP_NOTIFY_CEASE_ADMIN_RESET)
10322 && p->notify.length) {
10323 char msgbuf[1024];
10324 const char *msg_str;
10325
10326 msg_str = bgp_notify_admin_message(
10327 msgbuf, sizeof(msgbuf),
10328 (uint8_t *)p->notify.data,
10329 p->notify.length);
10330 if (msg_str)
10331 json_object_string_add(
10332 json_neigh,
10333 "lastShutdownDescription",
10334 msg_str);
10335 }
10336 }
10337 } else {
10338 vty_out(vty, " Last reset %s, ",
10339 peer_uptime(p->resettime, timebuf,
10340 BGP_UPTIME_LEN, 0, NULL));
10341
10342 if (p->last_reset == PEER_DOWN_NOTIFY_SEND
10343 || p->last_reset == PEER_DOWN_NOTIFY_RECEIVED) {
10344 code_str = bgp_notify_code_str(p->notify.code);
10345 subcode_str = bgp_notify_subcode_str(
10346 p->notify.code, p->notify.subcode);
10347 vty_out(vty, "due to NOTIFICATION %s (%s%s)\n",
10348 p->last_reset == PEER_DOWN_NOTIFY_SEND
10349 ? "sent"
10350 : "received",
10351 code_str, subcode_str);
10352 if (p->last_reset == PEER_DOWN_NOTIFY_RECEIVED
10353 && p->notify.code == BGP_NOTIFY_CEASE
10354 && (p->notify.subcode
10355 == BGP_NOTIFY_CEASE_ADMIN_SHUTDOWN
10356 || p->notify.subcode
10357 == BGP_NOTIFY_CEASE_ADMIN_RESET)
10358 && p->notify.length) {
10359 char msgbuf[1024];
10360 const char *msg_str;
10361
10362 msg_str = bgp_notify_admin_message(
10363 msgbuf, sizeof(msgbuf),
10364 (uint8_t *)p->notify.data,
10365 p->notify.length);
10366 if (msg_str)
10367 vty_out(vty,
10368 " Message: \"%s\"\n",
10369 msg_str);
10370 }
10371 } else {
10372 vty_out(vty, "due to %s\n",
10373 peer_down_str[(int)p->last_reset]);
10374 }
10375
10376 if (p->last_reset_cause_size) {
10377 msg = p->last_reset_cause;
10378 vty_out(vty,
10379 " Message received that caused BGP to send a NOTIFICATION:\n ");
10380 for (i = 1; i <= p->last_reset_cause_size;
10381 i++) {
10382 vty_out(vty, "%02X", *msg++);
10383
10384 if (i != p->last_reset_cause_size) {
10385 if (i % 16 == 0) {
10386 vty_out(vty, "\n ");
10387 } else if (i % 4 == 0) {
10388 vty_out(vty, " ");
10389 }
10390 }
10391 }
10392 vty_out(vty, "\n");
10393 }
10394 }
10395 }
10396
10397 if (CHECK_FLAG(p->sflags, PEER_STATUS_PREFIX_OVERFLOW)) {
10398 if (use_json)
10399 json_object_boolean_true_add(json_neigh,
10400 "prefixesConfigExceedMax");
10401 else
10402 vty_out(vty,
10403 " Peer had exceeded the max. no. of prefixes configured.\n");
10404
10405 if (p->t_pmax_restart) {
10406 if (use_json) {
10407 json_object_boolean_true_add(
10408 json_neigh, "reducePrefixNumFrom");
10409 json_object_int_add(json_neigh,
10410 "restartInTimerMsec",
10411 thread_timer_remain_second(
10412 p->t_pmax_restart)
10413 * 1000);
10414 } else
10415 vty_out(vty,
10416 " Reduce the no. of prefix from %s, will restart in %ld seconds\n",
10417 p->host, thread_timer_remain_second(
10418 p->t_pmax_restart));
10419 } else {
10420 if (use_json)
10421 json_object_boolean_true_add(
10422 json_neigh,
10423 "reducePrefixNumAndClearIpBgp");
10424 else
10425 vty_out(vty,
10426 " Reduce the no. of prefix and clear ip bgp %s to restore peering\n",
10427 p->host);
10428 }
10429 }
10430
10431 /* EBGP Multihop and GTSM */
10432 if (p->sort != BGP_PEER_IBGP) {
10433 if (use_json) {
10434 if (p->gtsm_hops > 0)
10435 json_object_int_add(json_neigh,
10436 "externalBgpNbrMaxHopsAway",
10437 p->gtsm_hops);
10438 else if (p->ttl > 1)
10439 json_object_int_add(json_neigh,
10440 "externalBgpNbrMaxHopsAway",
10441 p->ttl);
10442 } else {
10443 if (p->gtsm_hops > 0)
10444 vty_out(vty,
10445 " External BGP neighbor may be up to %d hops away.\n",
10446 p->gtsm_hops);
10447 else if (p->ttl > 1)
10448 vty_out(vty,
10449 " External BGP neighbor may be up to %d hops away.\n",
10450 p->ttl);
10451 }
10452 } else {
10453 if (p->gtsm_hops > 0) {
10454 if (use_json)
10455 json_object_int_add(json_neigh,
10456 "internalBgpNbrMaxHopsAway",
10457 p->gtsm_hops);
10458 else
10459 vty_out(vty,
10460 " Internal BGP neighbor may be up to %d hops away.\n",
10461 p->gtsm_hops);
10462 }
10463 }
10464
10465 /* Local address. */
10466 if (p->su_local) {
10467 if (use_json) {
10468 json_object_string_add(json_neigh, "hostLocal",
10469 sockunion2str(p->su_local, buf1,
10470 SU_ADDRSTRLEN));
10471 json_object_int_add(json_neigh, "portLocal",
10472 ntohs(p->su_local->sin.sin_port));
10473 } else
10474 vty_out(vty, "Local host: %s, Local port: %d\n",
10475 sockunion2str(p->su_local, buf1, SU_ADDRSTRLEN),
10476 ntohs(p->su_local->sin.sin_port));
10477 }
10478
10479 /* Remote address. */
10480 if (p->su_remote) {
10481 if (use_json) {
10482 json_object_string_add(json_neigh, "hostForeign",
10483 sockunion2str(p->su_remote, buf1,
10484 SU_ADDRSTRLEN));
10485 json_object_int_add(json_neigh, "portForeign",
10486 ntohs(p->su_remote->sin.sin_port));
10487 } else
10488 vty_out(vty, "Foreign host: %s, Foreign port: %d\n",
10489 sockunion2str(p->su_remote, buf1,
10490 SU_ADDRSTRLEN),
10491 ntohs(p->su_remote->sin.sin_port));
10492 }
10493
10494 /* Nexthop display. */
10495 if (p->su_local) {
10496 if (use_json) {
10497 json_object_string_add(json_neigh, "nexthop",
10498 inet_ntop(AF_INET,
10499 &p->nexthop.v4, buf1,
10500 sizeof(buf1)));
10501 json_object_string_add(json_neigh, "nexthopGlobal",
10502 inet_ntop(AF_INET6,
10503 &p->nexthop.v6_global,
10504 buf1, sizeof(buf1)));
10505 json_object_string_add(json_neigh, "nexthopLocal",
10506 inet_ntop(AF_INET6,
10507 &p->nexthop.v6_local,
10508 buf1, sizeof(buf1)));
10509 if (p->shared_network)
10510 json_object_string_add(json_neigh,
10511 "bgpConnection",
10512 "sharedNetwork");
10513 else
10514 json_object_string_add(json_neigh,
10515 "bgpConnection",
10516 "nonSharedNetwork");
10517 } else {
10518 vty_out(vty, "Nexthop: %s\n",
10519 inet_ntop(AF_INET, &p->nexthop.v4, buf1,
10520 sizeof(buf1)));
10521 vty_out(vty, "Nexthop global: %s\n",
10522 inet_ntop(AF_INET6, &p->nexthop.v6_global, buf1,
10523 sizeof(buf1)));
10524 vty_out(vty, "Nexthop local: %s\n",
10525 inet_ntop(AF_INET6, &p->nexthop.v6_local, buf1,
10526 sizeof(buf1)));
10527 vty_out(vty, "BGP connection: %s\n",
10528 p->shared_network ? "shared network"
10529 : "non shared network");
10530 }
10531 }
10532
10533 /* Timer information. */
10534 if (use_json) {
10535 json_object_int_add(json_neigh, "connectRetryTimer",
10536 p->v_connect);
10537 if (p->status == Established && p->rtt)
10538 json_object_int_add(json_neigh, "estimatedRttInMsecs",
10539 p->rtt);
10540 if (p->t_start)
10541 json_object_int_add(
10542 json_neigh, "nextStartTimerDueInMsecs",
10543 thread_timer_remain_second(p->t_start) * 1000);
10544 if (p->t_connect)
10545 json_object_int_add(
10546 json_neigh, "nextConnectTimerDueInMsecs",
10547 thread_timer_remain_second(p->t_connect)
10548 * 1000);
10549 if (p->t_routeadv) {
10550 json_object_int_add(json_neigh, "mraiInterval",
10551 p->v_routeadv);
10552 json_object_int_add(
10553 json_neigh, "mraiTimerExpireInMsecs",
10554 thread_timer_remain_second(p->t_routeadv)
10555 * 1000);
10556 }
10557 if (p->password)
10558 json_object_int_add(json_neigh, "authenticationEnabled",
10559 1);
10560
10561 if (p->t_read)
10562 json_object_string_add(json_neigh, "readThread", "on");
10563 else
10564 json_object_string_add(json_neigh, "readThread", "off");
10565
10566 if (CHECK_FLAG(p->thread_flags, PEER_THREAD_WRITES_ON))
10567 json_object_string_add(json_neigh, "writeThread", "on");
10568 else
10569 json_object_string_add(json_neigh, "writeThread",
10570 "off");
10571 } else {
10572 vty_out(vty, "BGP Connect Retry Timer in Seconds: %d\n",
10573 p->v_connect);
10574 if (p->status == Established && p->rtt)
10575 vty_out(vty, "Estimated round trip time: %d ms\n",
10576 p->rtt);
10577 if (p->t_start)
10578 vty_out(vty, "Next start timer due in %ld seconds\n",
10579 thread_timer_remain_second(p->t_start));
10580 if (p->t_connect)
10581 vty_out(vty, "Next connect timer due in %ld seconds\n",
10582 thread_timer_remain_second(p->t_connect));
10583 if (p->t_routeadv)
10584 vty_out(vty,
10585 "MRAI (interval %u) timer expires in %ld seconds\n",
10586 p->v_routeadv,
10587 thread_timer_remain_second(p->t_routeadv));
10588 if (p->password)
10589 vty_out(vty, "Peer Authentication Enabled\n");
10590
10591 vty_out(vty, "Read thread: %s Write thread: %s\n",
10592 p->t_read ? "on" : "off",
10593 CHECK_FLAG(p->thread_flags, PEER_THREAD_WRITES_ON)
10594 ? "on"
10595 : "off");
10596 }
10597
10598 if (p->notify.code == BGP_NOTIFY_OPEN_ERR
10599 && p->notify.subcode == BGP_NOTIFY_OPEN_UNSUP_CAPBL)
10600 bgp_capability_vty_out(vty, p, use_json, json_neigh);
10601
10602 if (!use_json)
10603 vty_out(vty, "\n");
10604
10605 /* BFD information. */
10606 bgp_bfd_show_info(vty, p, use_json, json_neigh);
10607
10608 if (use_json) {
10609 if (p->conf_if) /* Configured interface name. */
10610 json_object_object_add(json, p->conf_if, json_neigh);
10611 else /* Configured IP address. */
10612 json_object_object_add(json, p->host, json_neigh);
10613 }
10614 }
10615
10616 static int bgp_show_neighbor(struct vty *vty, struct bgp *bgp,
10617 enum show_type type, union sockunion *su,
10618 const char *conf_if, uint8_t use_json,
10619 json_object *json)
10620 {
10621 struct listnode *node, *nnode;
10622 struct peer *peer;
10623 int find = 0;
10624
10625 for (ALL_LIST_ELEMENTS(bgp->peer, node, nnode, peer)) {
10626 if (!CHECK_FLAG(peer->flags, PEER_FLAG_CONFIG_NODE))
10627 continue;
10628
10629 switch (type) {
10630 case show_all:
10631 bgp_show_peer(vty, peer, use_json, json);
10632 break;
10633 case show_peer:
10634 if (conf_if) {
10635 if ((peer->conf_if
10636 && !strcmp(peer->conf_if, conf_if))
10637 || (peer->hostname
10638 && !strcmp(peer->hostname, conf_if))) {
10639 find = 1;
10640 bgp_show_peer(vty, peer, use_json,
10641 json);
10642 }
10643 } else {
10644 if (sockunion_same(&peer->su, su)) {
10645 find = 1;
10646 bgp_show_peer(vty, peer, use_json,
10647 json);
10648 }
10649 }
10650 break;
10651 }
10652 }
10653
10654 if (type == show_peer && !find) {
10655 if (use_json)
10656 json_object_boolean_true_add(json, "bgpNoSuchNeighbor");
10657 else
10658 vty_out(vty, "%% No such neighbor in this view/vrf\n");
10659 }
10660
10661 if (use_json) {
10662 vty_out(vty, "%s\n", json_object_to_json_string_ext(
10663 json, JSON_C_TO_STRING_PRETTY));
10664 json_object_free(json);
10665 } else {
10666 vty_out(vty, "\n");
10667 }
10668
10669 return CMD_SUCCESS;
10670 }
10671
10672 static void bgp_show_all_instances_neighbors_vty(struct vty *vty,
10673 enum show_type type,
10674 const char *ip_str,
10675 uint8_t use_json)
10676 {
10677 struct listnode *node, *nnode;
10678 struct bgp *bgp;
10679 union sockunion su;
10680 json_object *json = NULL;
10681 int ret, is_first = 1;
10682
10683 if (use_json)
10684 vty_out(vty, "{\n");
10685
10686 for (ALL_LIST_ELEMENTS(bm->bgp, node, nnode, bgp)) {
10687 if (use_json) {
10688 if (!(json = json_object_new_object())) {
10689 zlog_err(
10690 "Unable to allocate memory for JSON object");
10691 vty_out(vty,
10692 "{\"error\": {\"message:\": \"Unable to allocate memory for JSON object\"}}}\n");
10693 return;
10694 }
10695
10696 json_object_int_add(json, "vrfId",
10697 (bgp->vrf_id == VRF_UNKNOWN)
10698 ? -1
10699 : (int64_t)bgp->vrf_id);
10700 json_object_string_add(
10701 json, "vrfName",
10702 (bgp->inst_type == BGP_INSTANCE_TYPE_DEFAULT)
10703 ? "Default"
10704 : bgp->name);
10705
10706 if (!is_first)
10707 vty_out(vty, ",\n");
10708 else
10709 is_first = 0;
10710
10711 vty_out(vty, "\"%s\":",
10712 (bgp->inst_type == BGP_INSTANCE_TYPE_DEFAULT)
10713 ? "Default"
10714 : bgp->name);
10715 } else {
10716 vty_out(vty, "\nInstance %s:\n",
10717 (bgp->inst_type == BGP_INSTANCE_TYPE_DEFAULT)
10718 ? "Default"
10719 : bgp->name);
10720 }
10721
10722 if (type == show_peer) {
10723 ret = str2sockunion(ip_str, &su);
10724 if (ret < 0)
10725 bgp_show_neighbor(vty, bgp, type, NULL, ip_str,
10726 use_json, json);
10727 else
10728 bgp_show_neighbor(vty, bgp, type, &su, NULL,
10729 use_json, json);
10730 } else {
10731 bgp_show_neighbor(vty, bgp, show_all, NULL, NULL,
10732 use_json, json);
10733 }
10734 }
10735
10736 if (use_json)
10737 vty_out(vty, "}\n");
10738 }
10739
10740 static int bgp_show_neighbor_vty(struct vty *vty, const char *name,
10741 enum show_type type, const char *ip_str,
10742 uint8_t use_json)
10743 {
10744 int ret;
10745 struct bgp *bgp;
10746 union sockunion su;
10747 json_object *json = NULL;
10748
10749 if (name) {
10750 if (strmatch(name, "all")) {
10751 bgp_show_all_instances_neighbors_vty(vty, type, ip_str,
10752 use_json);
10753 return CMD_SUCCESS;
10754 } else {
10755 bgp = bgp_lookup_by_name(name);
10756 if (!bgp) {
10757 if (use_json) {
10758 json = json_object_new_object();
10759 json_object_boolean_true_add(
10760 json, "bgpNoSuchInstance");
10761 vty_out(vty, "%s\n",
10762 json_object_to_json_string_ext(
10763 json,
10764 JSON_C_TO_STRING_PRETTY));
10765 json_object_free(json);
10766 } else
10767 vty_out(vty,
10768 "%% No such BGP instance exist\n");
10769
10770 return CMD_WARNING;
10771 }
10772 }
10773 } else {
10774 bgp = bgp_get_default();
10775 }
10776
10777 if (bgp) {
10778 json = json_object_new_object();
10779 if (ip_str) {
10780 ret = str2sockunion(ip_str, &su);
10781 if (ret < 0)
10782 bgp_show_neighbor(vty, bgp, type, NULL, ip_str,
10783 use_json, json);
10784 else
10785 bgp_show_neighbor(vty, bgp, type, &su, NULL,
10786 use_json, json);
10787 } else {
10788 bgp_show_neighbor(vty, bgp, type, NULL, NULL, use_json,
10789 json);
10790 }
10791 json_object_free(json);
10792 }
10793
10794 return CMD_SUCCESS;
10795 }
10796
10797 /* "show [ip] bgp neighbors" commands. */
10798 DEFUN (show_ip_bgp_neighbors,
10799 show_ip_bgp_neighbors_cmd,
10800 "show [ip] bgp [<view|vrf> VIEWVRFNAME] [<ipv4|ipv6>] neighbors [<A.B.C.D|X:X::X:X|WORD>] [json]",
10801 SHOW_STR
10802 IP_STR
10803 BGP_STR
10804 BGP_INSTANCE_HELP_STR
10805 "Address Family\n"
10806 "Address Family\n"
10807 "Detailed information on TCP and BGP neighbor connections\n"
10808 "Neighbor to display information about\n"
10809 "Neighbor to display information about\n"
10810 "Neighbor on BGP configured interface\n"
10811 JSON_STR)
10812 {
10813 char *vrf = NULL;
10814 char *sh_arg = NULL;
10815 enum show_type sh_type;
10816
10817 uint8_t uj = use_json(argc, argv);
10818
10819 int idx = 0;
10820
10821 if (argv_find(argv, argc, "view", &idx)
10822 || argv_find(argv, argc, "vrf", &idx))
10823 vrf = argv[idx + 1]->arg;
10824
10825 idx++;
10826 if (argv_find(argv, argc, "A.B.C.D", &idx)
10827 || argv_find(argv, argc, "X:X::X:X", &idx)
10828 || argv_find(argv, argc, "WORD", &idx)) {
10829 sh_type = show_peer;
10830 sh_arg = argv[idx]->arg;
10831 } else
10832 sh_type = show_all;
10833
10834 return bgp_show_neighbor_vty(vty, vrf, sh_type, sh_arg, uj);
10835 }
10836
10837 /* Show BGP's AS paths internal data. There are both `show [ip] bgp
10838 paths' and `show ip mbgp paths'. Those functions results are the
10839 same.*/
10840 DEFUN (show_ip_bgp_paths,
10841 show_ip_bgp_paths_cmd,
10842 "show [ip] bgp ["BGP_SAFI_CMD_STR"] paths",
10843 SHOW_STR
10844 IP_STR
10845 BGP_STR
10846 BGP_SAFI_HELP_STR
10847 "Path information\n")
10848 {
10849 vty_out(vty, "Address Refcnt Path\n");
10850 aspath_print_all_vty(vty);
10851 return CMD_SUCCESS;
10852 }
10853
10854 #include "hash.h"
10855
10856 static void community_show_all_iterator(struct hash_backet *backet,
10857 struct vty *vty)
10858 {
10859 struct community *com;
10860
10861 com = (struct community *)backet->data;
10862 vty_out(vty, "[%p] (%ld) %s\n", (void *)com, com->refcnt,
10863 community_str(com, false));
10864 }
10865
10866 /* Show BGP's community internal data. */
10867 DEFUN (show_ip_bgp_community_info,
10868 show_ip_bgp_community_info_cmd,
10869 "show [ip] bgp community-info",
10870 SHOW_STR
10871 IP_STR
10872 BGP_STR
10873 "List all bgp community information\n")
10874 {
10875 vty_out(vty, "Address Refcnt Community\n");
10876
10877 hash_iterate(community_hash(),
10878 (void (*)(struct hash_backet *,
10879 void *))community_show_all_iterator,
10880 vty);
10881
10882 return CMD_SUCCESS;
10883 }
10884
10885 static void lcommunity_show_all_iterator(struct hash_backet *backet,
10886 struct vty *vty)
10887 {
10888 struct lcommunity *lcom;
10889
10890 lcom = (struct lcommunity *)backet->data;
10891 vty_out(vty, "[%p] (%ld) %s\n", (void *)lcom, lcom->refcnt,
10892 lcommunity_str(lcom, false));
10893 }
10894
10895 /* Show BGP's community internal data. */
10896 DEFUN (show_ip_bgp_lcommunity_info,
10897 show_ip_bgp_lcommunity_info_cmd,
10898 "show ip bgp large-community-info",
10899 SHOW_STR
10900 IP_STR
10901 BGP_STR
10902 "List all bgp large-community information\n")
10903 {
10904 vty_out(vty, "Address Refcnt Large-community\n");
10905
10906 hash_iterate(lcommunity_hash(),
10907 (void (*)(struct hash_backet *,
10908 void *))lcommunity_show_all_iterator,
10909 vty);
10910
10911 return CMD_SUCCESS;
10912 }
10913
10914
10915 DEFUN (show_ip_bgp_attr_info,
10916 show_ip_bgp_attr_info_cmd,
10917 "show [ip] bgp attribute-info",
10918 SHOW_STR
10919 IP_STR
10920 BGP_STR
10921 "List all bgp attribute information\n")
10922 {
10923 attr_show_all(vty);
10924 return CMD_SUCCESS;
10925 }
10926
10927 static int bgp_show_route_leak_vty(struct vty *vty, const char *name,
10928 afi_t afi, safi_t safi)
10929 {
10930 struct bgp *bgp;
10931 struct listnode *node;
10932 char *vname;
10933 char buf1[INET6_ADDRSTRLEN];
10934 char *ecom_str;
10935 vpn_policy_direction_t dir;
10936
10937 if (name) {
10938 bgp = bgp_lookup_by_name(name);
10939 if (!bgp) {
10940 vty_out(vty, "%% No such BGP instance exist\n");
10941 return CMD_WARNING;
10942 }
10943 } else {
10944 bgp = bgp_get_default();
10945 if (!bgp) {
10946 vty_out(vty,
10947 "%% Default BGP instance does not exist\n");
10948 return CMD_WARNING;
10949 }
10950 }
10951
10952 if (!CHECK_FLAG(bgp->af_flags[afi][safi],
10953 BGP_CONFIG_VRF_TO_VRF_IMPORT)) {
10954 vty_out(vty,
10955 "This VRF is not importing %s routes from any other VRF\n",
10956 afi_safi_print(afi, safi));
10957 } else {
10958 vty_out(vty,
10959 "This VRF is importing %s routes from the following VRFs:\n",
10960 afi_safi_print(afi, safi));
10961 for (ALL_LIST_ELEMENTS_RO(bgp->vpn_policy[afi].import_vrf, node,
10962 vname)) {
10963 vty_out(vty, " %s\n", vname);
10964 }
10965 dir = BGP_VPN_POLICY_DIR_FROMVPN;
10966 ecom_str = ecommunity_ecom2str(
10967 bgp->vpn_policy[afi].rtlist[dir],
10968 ECOMMUNITY_FORMAT_ROUTE_MAP, 0);
10969 vty_out(vty, "Import RT(s): %s\n", ecom_str);
10970 XFREE(MTYPE_ECOMMUNITY_STR, ecom_str);
10971 }
10972
10973 if (!CHECK_FLAG(bgp->af_flags[afi][safi],
10974 BGP_CONFIG_VRF_TO_VRF_EXPORT)) {
10975 vty_out(vty,
10976 "This VRF is not exporting %s routes to any other VRF\n",
10977 afi_safi_print(afi, safi));
10978 } else {
10979 vty_out(vty,
10980 "This VRF is exporting %s routes to the following VRFs:\n",
10981 afi_safi_print(afi, safi));
10982 for (ALL_LIST_ELEMENTS_RO(bgp->vpn_policy[afi].export_vrf, node,
10983 vname)) {
10984 vty_out(vty, " %s\n", vname);
10985 }
10986 vty_out(vty, "RD: %s\n",
10987 prefix_rd2str(&bgp->vpn_policy[afi].tovpn_rd,
10988 buf1, RD_ADDRSTRLEN));
10989 dir = BGP_VPN_POLICY_DIR_TOVPN;
10990 ecom_str = ecommunity_ecom2str(
10991 bgp->vpn_policy[afi].rtlist[dir],
10992 ECOMMUNITY_FORMAT_ROUTE_MAP, 0);
10993 vty_out(vty, "Emport RT: %s\n", ecom_str);
10994 XFREE(MTYPE_ECOMMUNITY_STR, ecom_str);
10995 }
10996
10997 return CMD_SUCCESS;
10998 }
10999
11000 /* "show [ip] bgp route-leak" command. */
11001 DEFUN (show_ip_bgp_route_leak,
11002 show_ip_bgp_route_leak_cmd,
11003 "show [ip] bgp [<view|vrf> VIEWVRFNAME] ["BGP_AFI_CMD_STR" ["BGP_SAFI_CMD_STR"]] route-leak",
11004 SHOW_STR
11005 IP_STR
11006 BGP_STR
11007 BGP_INSTANCE_HELP_STR
11008 BGP_AFI_HELP_STR
11009 BGP_SAFI_HELP_STR
11010 "Route leaking information\n")
11011 {
11012 char *vrf = NULL;
11013 afi_t afi = AFI_MAX;
11014 safi_t safi = SAFI_MAX;
11015
11016 int idx = 0;
11017
11018 /* show [ip] bgp */
11019 if (argv_find(argv, argc, "ip", &idx)) {
11020 afi = AFI_IP;
11021 safi = SAFI_UNICAST;
11022 }
11023 /* [vrf VIEWVRFNAME] */
11024 if (argv_find(argv, argc, "view", &idx)) {
11025 vty_out(vty,
11026 "%% This command is not applicable to BGP views\n");
11027 return CMD_WARNING;
11028 }
11029
11030 if (argv_find(argv, argc, "vrf", &idx))
11031 vrf = argv[++idx]->arg;
11032 /* ["BGP_AFI_CMD_STR" ["BGP_SAFI_CMD_STR"]] */
11033 if (argv_find_and_parse_afi(argv, argc, &idx, &afi)) {
11034 argv_find_and_parse_safi(argv, argc, &idx, &safi);
11035 }
11036
11037 if (!((afi == AFI_IP || afi == AFI_IP6) && safi == SAFI_UNICAST)) {
11038 vty_out(vty,
11039 "%% This command is applicable only for unicast ipv4|ipv6\n");
11040 return CMD_WARNING;
11041 }
11042
11043 return bgp_show_route_leak_vty(vty, vrf, afi, safi);
11044 }
11045
11046 static void bgp_show_all_instances_updgrps_vty(struct vty *vty, afi_t afi,
11047 safi_t safi)
11048 {
11049 struct listnode *node, *nnode;
11050 struct bgp *bgp;
11051
11052 for (ALL_LIST_ELEMENTS(bm->bgp, node, nnode, bgp)) {
11053 vty_out(vty, "\nInstance %s:\n",
11054 (bgp->inst_type == BGP_INSTANCE_TYPE_DEFAULT)
11055 ? "Default"
11056 : bgp->name);
11057 update_group_show(bgp, afi, safi, vty, 0);
11058 }
11059 }
11060
11061 static int bgp_show_update_groups(struct vty *vty, const char *name, int afi,
11062 int safi, uint64_t subgrp_id)
11063 {
11064 struct bgp *bgp;
11065
11066 if (name) {
11067 if (strmatch(name, "all")) {
11068 bgp_show_all_instances_updgrps_vty(vty, afi, safi);
11069 return CMD_SUCCESS;
11070 } else {
11071 bgp = bgp_lookup_by_name(name);
11072 }
11073 } else {
11074 bgp = bgp_get_default();
11075 }
11076
11077 if (bgp)
11078 update_group_show(bgp, afi, safi, vty, subgrp_id);
11079 return CMD_SUCCESS;
11080 }
11081
11082 DEFUN (show_ip_bgp_updgrps,
11083 show_ip_bgp_updgrps_cmd,
11084 "show [ip] bgp [<view|vrf> VIEWVRFNAME] ["BGP_AFI_CMD_STR" ["BGP_SAFI_WITH_LABEL_CMD_STR"]] update-groups [SUBGROUP-ID]",
11085 SHOW_STR
11086 IP_STR
11087 BGP_STR
11088 BGP_INSTANCE_HELP_STR
11089 BGP_AFI_HELP_STR
11090 BGP_SAFI_WITH_LABEL_HELP_STR
11091 "Detailed info about dynamic update groups\n"
11092 "Specific subgroup to display detailed info for\n")
11093 {
11094 char *vrf = NULL;
11095 afi_t afi = AFI_IP6;
11096 safi_t safi = SAFI_UNICAST;
11097 uint64_t subgrp_id = 0;
11098
11099 int idx = 0;
11100
11101 /* show [ip] bgp */
11102 if (argv_find(argv, argc, "ip", &idx))
11103 afi = AFI_IP;
11104 /* [<view|vrf> VIEWVRFNAME] */
11105 if (argv_find(argv, argc, "view", &idx)
11106 || argv_find(argv, argc, "vrf", &idx))
11107 vrf = argv[++idx]->arg;
11108 /* ["BGP_AFI_CMD_STR" ["BGP_SAFI_CMD_STR"]] */
11109 if (argv_find_and_parse_afi(argv, argc, &idx, &afi)) {
11110 argv_find_and_parse_safi(argv, argc, &idx, &safi);
11111 }
11112
11113 /* get subgroup id, if provided */
11114 idx = argc - 1;
11115 if (argv[idx]->type == VARIABLE_TKN)
11116 subgrp_id = strtoull(argv[idx]->arg, NULL, 10);
11117
11118 return (bgp_show_update_groups(vty, vrf, afi, safi, subgrp_id));
11119 }
11120
11121 DEFUN (show_bgp_instance_all_ipv6_updgrps,
11122 show_bgp_instance_all_ipv6_updgrps_cmd,
11123 "show [ip] bgp <view|vrf> all update-groups",
11124 SHOW_STR
11125 IP_STR
11126 BGP_STR
11127 BGP_INSTANCE_ALL_HELP_STR
11128 "Detailed info about dynamic update groups\n")
11129 {
11130 bgp_show_all_instances_updgrps_vty(vty, AFI_IP6, SAFI_UNICAST);
11131 return CMD_SUCCESS;
11132 }
11133
11134 DEFUN (show_bgp_updgrps_stats,
11135 show_bgp_updgrps_stats_cmd,
11136 "show [ip] bgp update-groups statistics",
11137 SHOW_STR
11138 IP_STR
11139 BGP_STR
11140 "Detailed info about dynamic update groups\n"
11141 "Statistics\n")
11142 {
11143 struct bgp *bgp;
11144
11145 bgp = bgp_get_default();
11146 if (bgp)
11147 update_group_show_stats(bgp, vty);
11148
11149 return CMD_SUCCESS;
11150 }
11151
11152 DEFUN (show_bgp_instance_updgrps_stats,
11153 show_bgp_instance_updgrps_stats_cmd,
11154 "show [ip] bgp <view|vrf> VIEWVRFNAME update-groups statistics",
11155 SHOW_STR
11156 IP_STR
11157 BGP_STR
11158 BGP_INSTANCE_HELP_STR
11159 "Detailed info about dynamic update groups\n"
11160 "Statistics\n")
11161 {
11162 int idx_word = 3;
11163 struct bgp *bgp;
11164
11165 bgp = bgp_lookup_by_name(argv[idx_word]->arg);
11166 if (bgp)
11167 update_group_show_stats(bgp, vty);
11168
11169 return CMD_SUCCESS;
11170 }
11171
11172 static void show_bgp_updgrps_adj_info_aux(struct vty *vty, const char *name,
11173 afi_t afi, safi_t safi,
11174 const char *what, uint64_t subgrp_id)
11175 {
11176 struct bgp *bgp;
11177
11178 if (name)
11179 bgp = bgp_lookup_by_name(name);
11180 else
11181 bgp = bgp_get_default();
11182
11183 if (bgp) {
11184 if (!strcmp(what, "advertise-queue"))
11185 update_group_show_adj_queue(bgp, afi, safi, vty,
11186 subgrp_id);
11187 else if (!strcmp(what, "advertised-routes"))
11188 update_group_show_advertised(bgp, afi, safi, vty,
11189 subgrp_id);
11190 else if (!strcmp(what, "packet-queue"))
11191 update_group_show_packet_queue(bgp, afi, safi, vty,
11192 subgrp_id);
11193 }
11194 }
11195
11196 DEFPY(show_ip_bgp_instance_updgrps_adj_s,
11197 show_ip_bgp_instance_updgrps_adj_s_cmd,
11198 "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",
11199 SHOW_STR IP_STR BGP_STR BGP_INSTANCE_HELP_STR BGP_AFI_HELP_STR
11200 BGP_SAFI_HELP_STR
11201 "Detailed info about dynamic update groups\n"
11202 "Specific subgroup to display info for\n"
11203 "Advertisement queue\n"
11204 "Announced routes\n"
11205 "Packet queue\n")
11206 {
11207 uint64_t subgrp_id = 0;
11208 afi_t afiz;
11209 safi_t safiz;
11210 if (sgid)
11211 subgrp_id = strtoull(sgid, NULL, 10);
11212
11213 if (!ip && !afi)
11214 afiz = AFI_IP6;
11215 if (!ip && afi)
11216 afiz = bgp_vty_afi_from_str(afi);
11217 if (ip && !afi)
11218 afiz = AFI_IP;
11219 if (ip && afi) {
11220 afiz = bgp_vty_afi_from_str(afi);
11221 if (afiz != AFI_IP)
11222 vty_out(vty,
11223 "%% Cannot specify both 'ip' and 'ipv6'\n");
11224 return CMD_WARNING;
11225 }
11226
11227 safiz = safi ? bgp_vty_safi_from_str(safi) : SAFI_UNICAST;
11228
11229 show_bgp_updgrps_adj_info_aux(vty, vrf, afiz, safiz, rtq, subgrp_id);
11230 return CMD_SUCCESS;
11231 }
11232
11233 static int bgp_show_one_peer_group(struct vty *vty, struct peer_group *group)
11234 {
11235 struct listnode *node, *nnode;
11236 struct prefix *range;
11237 struct peer *conf;
11238 struct peer *peer;
11239 char buf[PREFIX2STR_BUFFER];
11240 afi_t afi;
11241 safi_t safi;
11242 const char *peer_status;
11243 const char *af_str;
11244 int lr_count;
11245 int dynamic;
11246 int af_cfgd;
11247
11248 conf = group->conf;
11249
11250 if (conf->as_type == AS_SPECIFIED || conf->as_type == AS_EXTERNAL) {
11251 vty_out(vty, "\nBGP peer-group %s, remote AS %d\n", group->name,
11252 conf->as);
11253 } else if (conf->as_type == AS_INTERNAL) {
11254 vty_out(vty, "\nBGP peer-group %s, remote AS %d\n", group->name,
11255 group->bgp->as);
11256 } else {
11257 vty_out(vty, "\nBGP peer-group %s\n", group->name);
11258 }
11259
11260 if ((group->bgp->as == conf->as) || (conf->as_type == AS_INTERNAL))
11261 vty_out(vty, " Peer-group type is internal\n");
11262 else
11263 vty_out(vty, " Peer-group type is external\n");
11264
11265 /* Display AFs configured. */
11266 vty_out(vty, " Configured address-families:");
11267 FOREACH_AFI_SAFI (afi, safi) {
11268 if (conf->afc[afi][safi]) {
11269 af_cfgd = 1;
11270 vty_out(vty, " %s;", afi_safi_print(afi, safi));
11271 }
11272 }
11273 if (!af_cfgd)
11274 vty_out(vty, " none\n");
11275 else
11276 vty_out(vty, "\n");
11277
11278 /* Display listen ranges (for dynamic neighbors), if any */
11279 for (afi = AFI_IP; afi < AFI_MAX; afi++) {
11280 if (afi == AFI_IP)
11281 af_str = "IPv4";
11282 else if (afi == AFI_IP6)
11283 af_str = "IPv6";
11284 else
11285 af_str = "???";
11286 lr_count = listcount(group->listen_range[afi]);
11287 if (lr_count) {
11288 vty_out(vty, " %d %s listen range(s)\n", lr_count,
11289 af_str);
11290
11291
11292 for (ALL_LIST_ELEMENTS(group->listen_range[afi], node,
11293 nnode, range)) {
11294 prefix2str(range, buf, sizeof(buf));
11295 vty_out(vty, " %s\n", buf);
11296 }
11297 }
11298 }
11299
11300 /* Display group members and their status */
11301 if (listcount(group->peer)) {
11302 vty_out(vty, " Peer-group members:\n");
11303 for (ALL_LIST_ELEMENTS(group->peer, node, nnode, peer)) {
11304 if (CHECK_FLAG(peer->flags, PEER_FLAG_SHUTDOWN))
11305 peer_status = "Idle (Admin)";
11306 else if (CHECK_FLAG(peer->sflags,
11307 PEER_STATUS_PREFIX_OVERFLOW))
11308 peer_status = "Idle (PfxCt)";
11309 else
11310 peer_status = lookup_msg(bgp_status_msg,
11311 peer->status, NULL);
11312
11313 dynamic = peer_dynamic_neighbor(peer);
11314 vty_out(vty, " %s %s %s \n", peer->host,
11315 dynamic ? "(dynamic)" : "", peer_status);
11316 }
11317 }
11318
11319 return CMD_SUCCESS;
11320 }
11321
11322 static int bgp_show_peer_group_vty(struct vty *vty, const char *name,
11323 const char *group_name)
11324 {
11325 struct bgp *bgp;
11326 struct listnode *node, *nnode;
11327 struct peer_group *group;
11328 bool found = false;
11329
11330 bgp = name ? bgp_lookup_by_name(name) : bgp_get_default();
11331
11332 if (!bgp) {
11333 vty_out(vty, "%% No such BGP instance exists\n");
11334 return CMD_WARNING;
11335 }
11336
11337 for (ALL_LIST_ELEMENTS(bgp->group, node, nnode, group)) {
11338 if (group_name) {
11339 if (strmatch(group->name, group_name)) {
11340 bgp_show_one_peer_group(vty, group);
11341 found = true;
11342 break;
11343 }
11344 } else {
11345 bgp_show_one_peer_group(vty, group);
11346 }
11347 }
11348
11349 if (group_name && !found)
11350 vty_out(vty, "%% No such peer-group\n");
11351
11352 return CMD_SUCCESS;
11353 }
11354
11355 DEFUN (show_ip_bgp_peer_groups,
11356 show_ip_bgp_peer_groups_cmd,
11357 "show [ip] bgp [<view|vrf> VIEWVRFNAME] peer-group [PGNAME]",
11358 SHOW_STR
11359 IP_STR
11360 BGP_STR
11361 BGP_INSTANCE_HELP_STR
11362 "Detailed information on BGP peer groups\n"
11363 "Peer group name\n")
11364 {
11365 char *vrf, *pg;
11366 vrf = pg = NULL;
11367 int idx = 0;
11368
11369 vrf = argv_find(argv, argc, "VIEWVRFNAME", &idx) ? argv[idx]->arg
11370 : NULL;
11371 pg = argv_find(argv, argc, "PGNAME", &idx) ? argv[idx]->arg : NULL;
11372
11373 return bgp_show_peer_group_vty(vty, vrf, pg);
11374 }
11375
11376
11377 /* Redistribute VTY commands. */
11378
11379 DEFUN (bgp_redistribute_ipv4,
11380 bgp_redistribute_ipv4_cmd,
11381 "redistribute " FRR_IP_REDIST_STR_BGPD,
11382 "Redistribute information from another routing protocol\n"
11383 FRR_IP_REDIST_HELP_STR_BGPD)
11384 {
11385 VTY_DECLVAR_CONTEXT(bgp, bgp);
11386 int idx_protocol = 1;
11387 int type;
11388
11389 type = proto_redistnum(AFI_IP, argv[idx_protocol]->text);
11390 if (type < 0) {
11391 vty_out(vty, "%% Invalid route type\n");
11392 return CMD_WARNING_CONFIG_FAILED;
11393 }
11394
11395 bgp_redist_add(bgp, AFI_IP, type, 0);
11396 return bgp_redistribute_set(bgp, AFI_IP, type, 0);
11397 }
11398
11399 ALIAS_HIDDEN(
11400 bgp_redistribute_ipv4, bgp_redistribute_ipv4_hidden_cmd,
11401 "redistribute " FRR_IP_REDIST_STR_BGPD,
11402 "Redistribute information from another routing protocol\n" FRR_IP_REDIST_HELP_STR_BGPD)
11403
11404 DEFUN (bgp_redistribute_ipv4_rmap,
11405 bgp_redistribute_ipv4_rmap_cmd,
11406 "redistribute " FRR_IP_REDIST_STR_BGPD " route-map WORD",
11407 "Redistribute information from another routing protocol\n"
11408 FRR_IP_REDIST_HELP_STR_BGPD
11409 "Route map reference\n"
11410 "Pointer to route-map entries\n")
11411 {
11412 VTY_DECLVAR_CONTEXT(bgp, bgp);
11413 int idx_protocol = 1;
11414 int idx_word = 3;
11415 int type;
11416 struct bgp_redist *red;
11417
11418 type = proto_redistnum(AFI_IP, argv[idx_protocol]->text);
11419 if (type < 0) {
11420 vty_out(vty, "%% Invalid route type\n");
11421 return CMD_WARNING_CONFIG_FAILED;
11422 }
11423
11424 red = bgp_redist_add(bgp, AFI_IP, type, 0);
11425 bgp_redistribute_rmap_set(red, argv[idx_word]->arg);
11426 return bgp_redistribute_set(bgp, AFI_IP, type, 0);
11427 }
11428
11429 ALIAS_HIDDEN(
11430 bgp_redistribute_ipv4_rmap, bgp_redistribute_ipv4_rmap_hidden_cmd,
11431 "redistribute " FRR_IP_REDIST_STR_BGPD " route-map WORD",
11432 "Redistribute information from another routing protocol\n" FRR_IP_REDIST_HELP_STR_BGPD
11433 "Route map reference\n"
11434 "Pointer to route-map entries\n")
11435
11436 DEFUN (bgp_redistribute_ipv4_metric,
11437 bgp_redistribute_ipv4_metric_cmd,
11438 "redistribute " FRR_IP_REDIST_STR_BGPD " metric (0-4294967295)",
11439 "Redistribute information from another routing protocol\n"
11440 FRR_IP_REDIST_HELP_STR_BGPD
11441 "Metric for redistributed routes\n"
11442 "Default metric\n")
11443 {
11444 VTY_DECLVAR_CONTEXT(bgp, bgp);
11445 int idx_protocol = 1;
11446 int idx_number = 3;
11447 int type;
11448 uint32_t metric;
11449 struct bgp_redist *red;
11450
11451 type = proto_redistnum(AFI_IP, argv[idx_protocol]->text);
11452 if (type < 0) {
11453 vty_out(vty, "%% Invalid route type\n");
11454 return CMD_WARNING_CONFIG_FAILED;
11455 }
11456 metric = strtoul(argv[idx_number]->arg, NULL, 10);
11457
11458 red = bgp_redist_add(bgp, AFI_IP, type, 0);
11459 bgp_redistribute_metric_set(bgp, red, AFI_IP, type, metric);
11460 return bgp_redistribute_set(bgp, AFI_IP, type, 0);
11461 }
11462
11463 ALIAS_HIDDEN(
11464 bgp_redistribute_ipv4_metric, bgp_redistribute_ipv4_metric_hidden_cmd,
11465 "redistribute " FRR_IP_REDIST_STR_BGPD " metric (0-4294967295)",
11466 "Redistribute information from another routing protocol\n" FRR_IP_REDIST_HELP_STR_BGPD
11467 "Metric for redistributed routes\n"
11468 "Default metric\n")
11469
11470 DEFUN (bgp_redistribute_ipv4_rmap_metric,
11471 bgp_redistribute_ipv4_rmap_metric_cmd,
11472 "redistribute " FRR_IP_REDIST_STR_BGPD " route-map WORD metric (0-4294967295)",
11473 "Redistribute information from another routing protocol\n"
11474 FRR_IP_REDIST_HELP_STR_BGPD
11475 "Route map reference\n"
11476 "Pointer to route-map entries\n"
11477 "Metric for redistributed routes\n"
11478 "Default metric\n")
11479 {
11480 VTY_DECLVAR_CONTEXT(bgp, bgp);
11481 int idx_protocol = 1;
11482 int idx_word = 3;
11483 int idx_number = 5;
11484 int type;
11485 uint32_t metric;
11486 struct bgp_redist *red;
11487
11488 type = proto_redistnum(AFI_IP, argv[idx_protocol]->text);
11489 if (type < 0) {
11490 vty_out(vty, "%% Invalid route type\n");
11491 return CMD_WARNING_CONFIG_FAILED;
11492 }
11493 metric = strtoul(argv[idx_number]->arg, NULL, 10);
11494
11495 red = bgp_redist_add(bgp, AFI_IP, type, 0);
11496 bgp_redistribute_rmap_set(red, argv[idx_word]->arg);
11497 bgp_redistribute_metric_set(bgp, red, AFI_IP, type, metric);
11498 return bgp_redistribute_set(bgp, AFI_IP, type, 0);
11499 }
11500
11501 ALIAS_HIDDEN(
11502 bgp_redistribute_ipv4_rmap_metric,
11503 bgp_redistribute_ipv4_rmap_metric_hidden_cmd,
11504 "redistribute " FRR_IP_REDIST_STR_BGPD
11505 " route-map WORD metric (0-4294967295)",
11506 "Redistribute information from another routing protocol\n" FRR_IP_REDIST_HELP_STR_BGPD
11507 "Route map reference\n"
11508 "Pointer to route-map entries\n"
11509 "Metric for redistributed routes\n"
11510 "Default metric\n")
11511
11512 DEFUN (bgp_redistribute_ipv4_metric_rmap,
11513 bgp_redistribute_ipv4_metric_rmap_cmd,
11514 "redistribute " FRR_IP_REDIST_STR_BGPD " metric (0-4294967295) route-map WORD",
11515 "Redistribute information from another routing protocol\n"
11516 FRR_IP_REDIST_HELP_STR_BGPD
11517 "Metric for redistributed routes\n"
11518 "Default metric\n"
11519 "Route map reference\n"
11520 "Pointer to route-map entries\n")
11521 {
11522 VTY_DECLVAR_CONTEXT(bgp, bgp);
11523 int idx_protocol = 1;
11524 int idx_number = 3;
11525 int idx_word = 5;
11526 int type;
11527 uint32_t metric;
11528 struct bgp_redist *red;
11529
11530 type = proto_redistnum(AFI_IP, argv[idx_protocol]->text);
11531 if (type < 0) {
11532 vty_out(vty, "%% Invalid route type\n");
11533 return CMD_WARNING_CONFIG_FAILED;
11534 }
11535 metric = strtoul(argv[idx_number]->arg, NULL, 10);
11536
11537 red = bgp_redist_add(bgp, AFI_IP, type, 0);
11538 bgp_redistribute_metric_set(bgp, red, AFI_IP, type, metric);
11539 bgp_redistribute_rmap_set(red, argv[idx_word]->arg);
11540 return bgp_redistribute_set(bgp, AFI_IP, type, 0);
11541 }
11542
11543 ALIAS_HIDDEN(
11544 bgp_redistribute_ipv4_metric_rmap,
11545 bgp_redistribute_ipv4_metric_rmap_hidden_cmd,
11546 "redistribute " FRR_IP_REDIST_STR_BGPD
11547 " metric (0-4294967295) route-map WORD",
11548 "Redistribute information from another routing protocol\n" FRR_IP_REDIST_HELP_STR_BGPD
11549 "Metric for redistributed routes\n"
11550 "Default metric\n"
11551 "Route map reference\n"
11552 "Pointer to route-map entries\n")
11553
11554 DEFUN (bgp_redistribute_ipv4_ospf,
11555 bgp_redistribute_ipv4_ospf_cmd,
11556 "redistribute <ospf|table> (1-65535)",
11557 "Redistribute information from another routing protocol\n"
11558 "Open Shortest Path First (OSPFv2)\n"
11559 "Non-main Kernel Routing Table\n"
11560 "Instance ID/Table ID\n")
11561 {
11562 VTY_DECLVAR_CONTEXT(bgp, bgp);
11563 int idx_ospf_table = 1;
11564 int idx_number = 2;
11565 unsigned short instance;
11566 unsigned short protocol;
11567
11568 instance = strtoul(argv[idx_number]->arg, NULL, 10);
11569
11570 if (strncmp(argv[idx_ospf_table]->arg, "o", 1) == 0)
11571 protocol = ZEBRA_ROUTE_OSPF;
11572 else
11573 protocol = ZEBRA_ROUTE_TABLE;
11574
11575 bgp_redist_add(bgp, AFI_IP, protocol, instance);
11576 return bgp_redistribute_set(bgp, AFI_IP, protocol, instance);
11577 }
11578
11579 ALIAS_HIDDEN(bgp_redistribute_ipv4_ospf, bgp_redistribute_ipv4_ospf_hidden_cmd,
11580 "redistribute <ospf|table> (1-65535)",
11581 "Redistribute information from another routing protocol\n"
11582 "Open Shortest Path First (OSPFv2)\n"
11583 "Non-main Kernel Routing Table\n"
11584 "Instance ID/Table ID\n")
11585
11586 DEFUN (bgp_redistribute_ipv4_ospf_rmap,
11587 bgp_redistribute_ipv4_ospf_rmap_cmd,
11588 "redistribute <ospf|table> (1-65535) route-map WORD",
11589 "Redistribute information from another routing protocol\n"
11590 "Open Shortest Path First (OSPFv2)\n"
11591 "Non-main Kernel Routing Table\n"
11592 "Instance ID/Table ID\n"
11593 "Route map reference\n"
11594 "Pointer to route-map entries\n")
11595 {
11596 VTY_DECLVAR_CONTEXT(bgp, bgp);
11597 int idx_ospf_table = 1;
11598 int idx_number = 2;
11599 int idx_word = 4;
11600 struct bgp_redist *red;
11601 unsigned short instance;
11602 int protocol;
11603
11604 if (strncmp(argv[idx_ospf_table]->arg, "o", 1) == 0)
11605 protocol = ZEBRA_ROUTE_OSPF;
11606 else
11607 protocol = ZEBRA_ROUTE_TABLE;
11608
11609 instance = strtoul(argv[idx_number]->arg, NULL, 10);
11610 red = bgp_redist_add(bgp, AFI_IP, protocol, instance);
11611 bgp_redistribute_rmap_set(red, argv[idx_word]->arg);
11612 return bgp_redistribute_set(bgp, AFI_IP, protocol, instance);
11613 }
11614
11615 ALIAS_HIDDEN(bgp_redistribute_ipv4_ospf_rmap,
11616 bgp_redistribute_ipv4_ospf_rmap_hidden_cmd,
11617 "redistribute <ospf|table> (1-65535) route-map WORD",
11618 "Redistribute information from another routing protocol\n"
11619 "Open Shortest Path First (OSPFv2)\n"
11620 "Non-main Kernel Routing Table\n"
11621 "Instance ID/Table ID\n"
11622 "Route map reference\n"
11623 "Pointer to route-map entries\n")
11624
11625 DEFUN (bgp_redistribute_ipv4_ospf_metric,
11626 bgp_redistribute_ipv4_ospf_metric_cmd,
11627 "redistribute <ospf|table> (1-65535) metric (0-4294967295)",
11628 "Redistribute information from another routing protocol\n"
11629 "Open Shortest Path First (OSPFv2)\n"
11630 "Non-main Kernel Routing Table\n"
11631 "Instance ID/Table ID\n"
11632 "Metric for redistributed routes\n"
11633 "Default metric\n")
11634 {
11635 VTY_DECLVAR_CONTEXT(bgp, bgp);
11636 int idx_ospf_table = 1;
11637 int idx_number = 2;
11638 int idx_number_2 = 4;
11639 uint32_t metric;
11640 struct bgp_redist *red;
11641 unsigned short instance;
11642 int protocol;
11643
11644 if (strncmp(argv[idx_ospf_table]->arg, "o", 1) == 0)
11645 protocol = ZEBRA_ROUTE_OSPF;
11646 else
11647 protocol = ZEBRA_ROUTE_TABLE;
11648
11649 instance = strtoul(argv[idx_number]->arg, NULL, 10);
11650 metric = strtoul(argv[idx_number_2]->arg, NULL, 10);
11651
11652 red = bgp_redist_add(bgp, AFI_IP, protocol, instance);
11653 bgp_redistribute_metric_set(bgp, red, AFI_IP, protocol, metric);
11654 return bgp_redistribute_set(bgp, AFI_IP, protocol, instance);
11655 }
11656
11657 ALIAS_HIDDEN(bgp_redistribute_ipv4_ospf_metric,
11658 bgp_redistribute_ipv4_ospf_metric_hidden_cmd,
11659 "redistribute <ospf|table> (1-65535) metric (0-4294967295)",
11660 "Redistribute information from another routing protocol\n"
11661 "Open Shortest Path First (OSPFv2)\n"
11662 "Non-main Kernel Routing Table\n"
11663 "Instance ID/Table ID\n"
11664 "Metric for redistributed routes\n"
11665 "Default metric\n")
11666
11667 DEFUN (bgp_redistribute_ipv4_ospf_rmap_metric,
11668 bgp_redistribute_ipv4_ospf_rmap_metric_cmd,
11669 "redistribute <ospf|table> (1-65535) route-map WORD metric (0-4294967295)",
11670 "Redistribute information from another routing protocol\n"
11671 "Open Shortest Path First (OSPFv2)\n"
11672 "Non-main Kernel Routing Table\n"
11673 "Instance ID/Table ID\n"
11674 "Route map reference\n"
11675 "Pointer to route-map entries\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_word = 4;
11683 int idx_number_2 = 6;
11684 uint32_t metric;
11685 struct bgp_redist *red;
11686 unsigned short instance;
11687 int protocol;
11688
11689 if (strncmp(argv[idx_ospf_table]->arg, "o", 1) == 0)
11690 protocol = ZEBRA_ROUTE_OSPF;
11691 else
11692 protocol = ZEBRA_ROUTE_TABLE;
11693
11694 instance = strtoul(argv[idx_number]->arg, NULL, 10);
11695 metric = strtoul(argv[idx_number_2]->arg, NULL, 10);
11696
11697 red = bgp_redist_add(bgp, AFI_IP, protocol, instance);
11698 bgp_redistribute_rmap_set(red, argv[idx_word]->arg);
11699 bgp_redistribute_metric_set(bgp, red, AFI_IP, protocol, metric);
11700 return bgp_redistribute_set(bgp, AFI_IP, protocol, instance);
11701 }
11702
11703 ALIAS_HIDDEN(
11704 bgp_redistribute_ipv4_ospf_rmap_metric,
11705 bgp_redistribute_ipv4_ospf_rmap_metric_hidden_cmd,
11706 "redistribute <ospf|table> (1-65535) route-map WORD metric (0-4294967295)",
11707 "Redistribute information from another routing protocol\n"
11708 "Open Shortest Path First (OSPFv2)\n"
11709 "Non-main Kernel Routing Table\n"
11710 "Instance ID/Table ID\n"
11711 "Route map reference\n"
11712 "Pointer to route-map entries\n"
11713 "Metric for redistributed routes\n"
11714 "Default metric\n")
11715
11716 DEFUN (bgp_redistribute_ipv4_ospf_metric_rmap,
11717 bgp_redistribute_ipv4_ospf_metric_rmap_cmd,
11718 "redistribute <ospf|table> (1-65535) metric (0-4294967295) route-map WORD",
11719 "Redistribute information from another routing protocol\n"
11720 "Open Shortest Path First (OSPFv2)\n"
11721 "Non-main Kernel Routing Table\n"
11722 "Instance ID/Table ID\n"
11723 "Metric for redistributed routes\n"
11724 "Default metric\n"
11725 "Route map reference\n"
11726 "Pointer to route-map entries\n")
11727 {
11728 VTY_DECLVAR_CONTEXT(bgp, bgp);
11729 int idx_ospf_table = 1;
11730 int idx_number = 2;
11731 int idx_number_2 = 4;
11732 int idx_word = 6;
11733 uint32_t metric;
11734 struct bgp_redist *red;
11735 unsigned short instance;
11736 int protocol;
11737
11738 if (strncmp(argv[idx_ospf_table]->arg, "o", 1) == 0)
11739 protocol = ZEBRA_ROUTE_OSPF;
11740 else
11741 protocol = ZEBRA_ROUTE_TABLE;
11742
11743 instance = strtoul(argv[idx_number]->arg, NULL, 10);
11744 metric = strtoul(argv[idx_number_2]->arg, NULL, 10);
11745
11746 red = bgp_redist_add(bgp, AFI_IP, protocol, instance);
11747 bgp_redistribute_metric_set(bgp, red, AFI_IP, protocol, metric);
11748 bgp_redistribute_rmap_set(red, argv[idx_word]->arg);
11749 return bgp_redistribute_set(bgp, AFI_IP, protocol, instance);
11750 }
11751
11752 ALIAS_HIDDEN(
11753 bgp_redistribute_ipv4_ospf_metric_rmap,
11754 bgp_redistribute_ipv4_ospf_metric_rmap_hidden_cmd,
11755 "redistribute <ospf|table> (1-65535) metric (0-4294967295) route-map WORD",
11756 "Redistribute information from another routing protocol\n"
11757 "Open Shortest Path First (OSPFv2)\n"
11758 "Non-main Kernel Routing Table\n"
11759 "Instance ID/Table ID\n"
11760 "Metric for redistributed routes\n"
11761 "Default metric\n"
11762 "Route map reference\n"
11763 "Pointer to route-map entries\n")
11764
11765 DEFUN (no_bgp_redistribute_ipv4_ospf,
11766 no_bgp_redistribute_ipv4_ospf_cmd,
11767 "no redistribute <ospf|table> (1-65535) [metric (0-4294967295)] [route-map WORD]",
11768 NO_STR
11769 "Redistribute information from another routing protocol\n"
11770 "Open Shortest Path First (OSPFv2)\n"
11771 "Non-main Kernel Routing Table\n"
11772 "Instance ID/Table ID\n"
11773 "Metric for redistributed routes\n"
11774 "Default metric\n"
11775 "Route map reference\n"
11776 "Pointer to route-map entries\n")
11777 {
11778 VTY_DECLVAR_CONTEXT(bgp, bgp);
11779 int idx_ospf_table = 2;
11780 int idx_number = 3;
11781 unsigned short instance;
11782 int protocol;
11783
11784 if (strncmp(argv[idx_ospf_table]->arg, "o", 1) == 0)
11785 protocol = ZEBRA_ROUTE_OSPF;
11786 else
11787 protocol = ZEBRA_ROUTE_TABLE;
11788
11789 instance = strtoul(argv[idx_number]->arg, NULL, 10);
11790 return bgp_redistribute_unset(bgp, AFI_IP, protocol, instance);
11791 }
11792
11793 ALIAS_HIDDEN(
11794 no_bgp_redistribute_ipv4_ospf, no_bgp_redistribute_ipv4_ospf_hidden_cmd,
11795 "no redistribute <ospf|table> (1-65535) [metric (0-4294967295)] [route-map WORD]",
11796 NO_STR
11797 "Redistribute information from another routing protocol\n"
11798 "Open Shortest Path First (OSPFv2)\n"
11799 "Non-main Kernel Routing Table\n"
11800 "Instance ID/Table ID\n"
11801 "Metric for redistributed routes\n"
11802 "Default metric\n"
11803 "Route map reference\n"
11804 "Pointer to route-map entries\n")
11805
11806 DEFUN (no_bgp_redistribute_ipv4,
11807 no_bgp_redistribute_ipv4_cmd,
11808 "no redistribute " FRR_IP_REDIST_STR_BGPD " [metric (0-4294967295)] [route-map WORD]",
11809 NO_STR
11810 "Redistribute information from another routing protocol\n"
11811 FRR_IP_REDIST_HELP_STR_BGPD
11812 "Metric for redistributed routes\n"
11813 "Default metric\n"
11814 "Route map reference\n"
11815 "Pointer to route-map entries\n")
11816 {
11817 VTY_DECLVAR_CONTEXT(bgp, bgp);
11818 int idx_protocol = 2;
11819 int type;
11820
11821 type = proto_redistnum(AFI_IP, argv[idx_protocol]->text);
11822 if (type < 0) {
11823 vty_out(vty, "%% Invalid route type\n");
11824 return CMD_WARNING_CONFIG_FAILED;
11825 }
11826 return bgp_redistribute_unset(bgp, AFI_IP, type, 0);
11827 }
11828
11829 ALIAS_HIDDEN(
11830 no_bgp_redistribute_ipv4, no_bgp_redistribute_ipv4_hidden_cmd,
11831 "no redistribute " FRR_IP_REDIST_STR_BGPD
11832 " [metric (0-4294967295)] [route-map WORD]",
11833 NO_STR
11834 "Redistribute information from another routing protocol\n" FRR_IP_REDIST_HELP_STR_BGPD
11835 "Metric for redistributed routes\n"
11836 "Default metric\n"
11837 "Route map reference\n"
11838 "Pointer to route-map entries\n")
11839
11840 DEFUN (bgp_redistribute_ipv6,
11841 bgp_redistribute_ipv6_cmd,
11842 "redistribute " FRR_IP6_REDIST_STR_BGPD,
11843 "Redistribute information from another routing protocol\n"
11844 FRR_IP6_REDIST_HELP_STR_BGPD)
11845 {
11846 VTY_DECLVAR_CONTEXT(bgp, bgp);
11847 int idx_protocol = 1;
11848 int type;
11849
11850 type = proto_redistnum(AFI_IP6, argv[idx_protocol]->text);
11851 if (type < 0) {
11852 vty_out(vty, "%% Invalid route type\n");
11853 return CMD_WARNING_CONFIG_FAILED;
11854 }
11855
11856 bgp_redist_add(bgp, AFI_IP6, type, 0);
11857 return bgp_redistribute_set(bgp, AFI_IP6, type, 0);
11858 }
11859
11860 DEFUN (bgp_redistribute_ipv6_rmap,
11861 bgp_redistribute_ipv6_rmap_cmd,
11862 "redistribute " FRR_IP6_REDIST_STR_BGPD " route-map WORD",
11863 "Redistribute information from another routing protocol\n"
11864 FRR_IP6_REDIST_HELP_STR_BGPD
11865 "Route map reference\n"
11866 "Pointer to route-map entries\n")
11867 {
11868 VTY_DECLVAR_CONTEXT(bgp, bgp);
11869 int idx_protocol = 1;
11870 int idx_word = 3;
11871 int type;
11872 struct bgp_redist *red;
11873
11874 type = proto_redistnum(AFI_IP6, argv[idx_protocol]->text);
11875 if (type < 0) {
11876 vty_out(vty, "%% Invalid route type\n");
11877 return CMD_WARNING_CONFIG_FAILED;
11878 }
11879
11880 red = bgp_redist_add(bgp, AFI_IP6, type, 0);
11881 bgp_redistribute_rmap_set(red, argv[idx_word]->arg);
11882 return bgp_redistribute_set(bgp, AFI_IP6, type, 0);
11883 }
11884
11885 DEFUN (bgp_redistribute_ipv6_metric,
11886 bgp_redistribute_ipv6_metric_cmd,
11887 "redistribute " FRR_IP6_REDIST_STR_BGPD " metric (0-4294967295)",
11888 "Redistribute information from another routing protocol\n"
11889 FRR_IP6_REDIST_HELP_STR_BGPD
11890 "Metric for redistributed routes\n"
11891 "Default metric\n")
11892 {
11893 VTY_DECLVAR_CONTEXT(bgp, bgp);
11894 int idx_protocol = 1;
11895 int idx_number = 3;
11896 int type;
11897 uint32_t metric;
11898 struct bgp_redist *red;
11899
11900 type = proto_redistnum(AFI_IP6, argv[idx_protocol]->text);
11901 if (type < 0) {
11902 vty_out(vty, "%% Invalid route type\n");
11903 return CMD_WARNING_CONFIG_FAILED;
11904 }
11905 metric = strtoul(argv[idx_number]->arg, NULL, 10);
11906
11907 red = bgp_redist_add(bgp, AFI_IP6, type, 0);
11908 bgp_redistribute_metric_set(bgp, red, AFI_IP6, type, metric);
11909 return bgp_redistribute_set(bgp, AFI_IP6, type, 0);
11910 }
11911
11912 DEFUN (bgp_redistribute_ipv6_rmap_metric,
11913 bgp_redistribute_ipv6_rmap_metric_cmd,
11914 "redistribute " FRR_IP6_REDIST_STR_BGPD " route-map WORD metric (0-4294967295)",
11915 "Redistribute information from another routing protocol\n"
11916 FRR_IP6_REDIST_HELP_STR_BGPD
11917 "Route map reference\n"
11918 "Pointer to route-map entries\n"
11919 "Metric for redistributed routes\n"
11920 "Default metric\n")
11921 {
11922 VTY_DECLVAR_CONTEXT(bgp, bgp);
11923 int idx_protocol = 1;
11924 int idx_word = 3;
11925 int idx_number = 5;
11926 int type;
11927 uint32_t metric;
11928 struct bgp_redist *red;
11929
11930 type = proto_redistnum(AFI_IP6, argv[idx_protocol]->text);
11931 if (type < 0) {
11932 vty_out(vty, "%% Invalid route type\n");
11933 return CMD_WARNING_CONFIG_FAILED;
11934 }
11935 metric = strtoul(argv[idx_number]->arg, NULL, 10);
11936
11937 red = bgp_redist_add(bgp, AFI_IP6, type, 0);
11938 bgp_redistribute_rmap_set(red, argv[idx_word]->arg);
11939 bgp_redistribute_metric_set(bgp, red, AFI_IP6, type, metric);
11940 return bgp_redistribute_set(bgp, AFI_IP6, type, 0);
11941 }
11942
11943 DEFUN (bgp_redistribute_ipv6_metric_rmap,
11944 bgp_redistribute_ipv6_metric_rmap_cmd,
11945 "redistribute " FRR_IP6_REDIST_STR_BGPD " metric (0-4294967295) route-map WORD",
11946 "Redistribute information from another routing protocol\n"
11947 FRR_IP6_REDIST_HELP_STR_BGPD
11948 "Metric for redistributed routes\n"
11949 "Default metric\n"
11950 "Route map reference\n"
11951 "Pointer to route-map entries\n")
11952 {
11953 VTY_DECLVAR_CONTEXT(bgp, bgp);
11954 int idx_protocol = 1;
11955 int idx_number = 3;
11956 int idx_word = 5;
11957 int type;
11958 uint32_t metric;
11959 struct bgp_redist *red;
11960
11961 type = proto_redistnum(AFI_IP6, argv[idx_protocol]->text);
11962 if (type < 0) {
11963 vty_out(vty, "%% Invalid route type\n");
11964 return CMD_WARNING_CONFIG_FAILED;
11965 }
11966 metric = strtoul(argv[idx_number]->arg, NULL, 10);
11967
11968 red = bgp_redist_add(bgp, AFI_IP6, type, 0);
11969 bgp_redistribute_metric_set(bgp, red, AFI_IP6, SAFI_UNICAST, metric);
11970 bgp_redistribute_rmap_set(red, argv[idx_word]->arg);
11971 return bgp_redistribute_set(bgp, AFI_IP6, type, 0);
11972 }
11973
11974 DEFUN (no_bgp_redistribute_ipv6,
11975 no_bgp_redistribute_ipv6_cmd,
11976 "no redistribute " FRR_IP6_REDIST_STR_BGPD " [metric (0-4294967295)] [route-map WORD]",
11977 NO_STR
11978 "Redistribute information from another routing protocol\n"
11979 FRR_IP6_REDIST_HELP_STR_BGPD
11980 "Metric for redistributed routes\n"
11981 "Default metric\n"
11982 "Route map reference\n"
11983 "Pointer to route-map entries\n")
11984 {
11985 VTY_DECLVAR_CONTEXT(bgp, bgp);
11986 int idx_protocol = 2;
11987 int type;
11988
11989 type = proto_redistnum(AFI_IP6, argv[idx_protocol]->text);
11990 if (type < 0) {
11991 vty_out(vty, "%% Invalid route type\n");
11992 return CMD_WARNING_CONFIG_FAILED;
11993 }
11994
11995 return bgp_redistribute_unset(bgp, AFI_IP6, type, 0);
11996 }
11997
11998 void bgp_config_write_redistribute(struct vty *vty, struct bgp *bgp, afi_t afi,
11999 safi_t safi)
12000 {
12001 int i;
12002
12003 /* Unicast redistribution only. */
12004 if (safi != SAFI_UNICAST)
12005 return;
12006
12007 for (i = 0; i < ZEBRA_ROUTE_MAX; i++) {
12008 /* Redistribute BGP does not make sense. */
12009 if (i != ZEBRA_ROUTE_BGP) {
12010 struct list *red_list;
12011 struct listnode *node;
12012 struct bgp_redist *red;
12013
12014 red_list = bgp->redist[afi][i];
12015 if (!red_list)
12016 continue;
12017
12018 for (ALL_LIST_ELEMENTS_RO(red_list, node, red)) {
12019 /* "redistribute" configuration. */
12020 vty_out(vty, " redistribute %s",
12021 zebra_route_string(i));
12022 if (red->instance)
12023 vty_out(vty, " %d", red->instance);
12024 if (red->redist_metric_flag)
12025 vty_out(vty, " metric %u",
12026 red->redist_metric);
12027 if (red->rmap.name)
12028 vty_out(vty, " route-map %s",
12029 red->rmap.name);
12030 vty_out(vty, "\n");
12031 }
12032 }
12033 }
12034 }
12035
12036 /* This is part of the address-family block (unicast only) */
12037 void bgp_vpn_policy_config_write_afi(struct vty *vty, struct bgp *bgp,
12038 afi_t afi)
12039 {
12040 int indent = 2;
12041
12042 if (bgp->vpn_policy[afi].rmap_name[BGP_VPN_POLICY_DIR_FROMVPN])
12043 vty_out(vty, "%*simport vrf route-map %s\n", indent, "",
12044 bgp->vpn_policy[afi]
12045 .rmap_name[BGP_VPN_POLICY_DIR_FROMVPN]);
12046
12047 if (CHECK_FLAG(bgp->af_flags[afi][SAFI_UNICAST],
12048 BGP_CONFIG_VRF_TO_VRF_IMPORT)
12049 || CHECK_FLAG(bgp->af_flags[afi][SAFI_UNICAST],
12050 BGP_CONFIG_VRF_TO_VRF_EXPORT))
12051 return;
12052
12053 if (CHECK_FLAG(bgp->vpn_policy[afi].flags,
12054 BGP_VPN_POLICY_TOVPN_LABEL_AUTO)) {
12055
12056 vty_out(vty, "%*slabel vpn export %s\n", indent, "", "auto");
12057
12058 } else {
12059 if (bgp->vpn_policy[afi].tovpn_label != MPLS_LABEL_NONE) {
12060 vty_out(vty, "%*slabel vpn export %u\n", indent, "",
12061 bgp->vpn_policy[afi].tovpn_label);
12062 }
12063 }
12064 if (CHECK_FLAG(bgp->vpn_policy[afi].flags,
12065 BGP_VPN_POLICY_TOVPN_RD_SET)) {
12066 char buf[RD_ADDRSTRLEN];
12067 vty_out(vty, "%*srd vpn export %s\n", indent, "",
12068 prefix_rd2str(&bgp->vpn_policy[afi].tovpn_rd, buf,
12069 sizeof(buf)));
12070 }
12071 if (CHECK_FLAG(bgp->vpn_policy[afi].flags,
12072 BGP_VPN_POLICY_TOVPN_NEXTHOP_SET)) {
12073
12074 char buf[PREFIX_STRLEN];
12075 if (inet_ntop(bgp->vpn_policy[afi].tovpn_nexthop.family,
12076 &bgp->vpn_policy[afi].tovpn_nexthop.u.prefix, buf,
12077 sizeof(buf))) {
12078
12079 vty_out(vty, "%*snexthop vpn export %s\n",
12080 indent, "", buf);
12081 }
12082 }
12083 if (bgp->vpn_policy[afi].rtlist[BGP_VPN_POLICY_DIR_FROMVPN]
12084 && bgp->vpn_policy[afi].rtlist[BGP_VPN_POLICY_DIR_TOVPN]
12085 && ecommunity_cmp(
12086 bgp->vpn_policy[afi].rtlist[BGP_VPN_POLICY_DIR_FROMVPN],
12087 bgp->vpn_policy[afi].rtlist[BGP_VPN_POLICY_DIR_TOVPN])) {
12088
12089 char *b = ecommunity_ecom2str(
12090 bgp->vpn_policy[afi].rtlist[BGP_VPN_POLICY_DIR_TOVPN],
12091 ECOMMUNITY_FORMAT_ROUTE_MAP, ECOMMUNITY_ROUTE_TARGET);
12092 vty_out(vty, "%*srt vpn both %s\n", indent, "", b);
12093 XFREE(MTYPE_ECOMMUNITY_STR, b);
12094 } else {
12095 if (bgp->vpn_policy[afi].rtlist[BGP_VPN_POLICY_DIR_FROMVPN]) {
12096 char *b = ecommunity_ecom2str(
12097 bgp->vpn_policy[afi]
12098 .rtlist[BGP_VPN_POLICY_DIR_FROMVPN],
12099 ECOMMUNITY_FORMAT_ROUTE_MAP,
12100 ECOMMUNITY_ROUTE_TARGET);
12101 vty_out(vty, "%*srt vpn import %s\n", indent, "", b);
12102 XFREE(MTYPE_ECOMMUNITY_STR, b);
12103 }
12104 if (bgp->vpn_policy[afi].rtlist[BGP_VPN_POLICY_DIR_TOVPN]) {
12105 char *b = ecommunity_ecom2str(
12106 bgp->vpn_policy[afi]
12107 .rtlist[BGP_VPN_POLICY_DIR_TOVPN],
12108 ECOMMUNITY_FORMAT_ROUTE_MAP,
12109 ECOMMUNITY_ROUTE_TARGET);
12110 vty_out(vty, "%*srt vpn export %s\n", indent, "", b);
12111 XFREE(MTYPE_ECOMMUNITY_STR, b);
12112 }
12113 }
12114
12115 if (bgp->vpn_policy[afi].rmap_name[BGP_VPN_POLICY_DIR_TOVPN])
12116 vty_out(vty, "%*sroute-map vpn export %s\n", indent, "",
12117 bgp->vpn_policy[afi]
12118 .rmap_name[BGP_VPN_POLICY_DIR_TOVPN]);
12119
12120 if (bgp->vpn_policy[afi].import_redirect_rtlist) {
12121 char *b = ecommunity_ecom2str(
12122 bgp->vpn_policy[afi]
12123 .import_redirect_rtlist,
12124 ECOMMUNITY_FORMAT_ROUTE_MAP,
12125 ECOMMUNITY_ROUTE_TARGET);
12126
12127 vty_out(vty, "%*srt redirect import %s\n", indent, "", b);
12128 XFREE(MTYPE_ECOMMUNITY_STR, b);
12129 }
12130 }
12131
12132
12133 /* BGP node structure. */
12134 static struct cmd_node bgp_node = {
12135 BGP_NODE, "%s(config-router)# ", 1,
12136 };
12137
12138 static struct cmd_node bgp_ipv4_unicast_node = {
12139 BGP_IPV4_NODE, "%s(config-router-af)# ", 1,
12140 };
12141
12142 static struct cmd_node bgp_ipv4_multicast_node = {
12143 BGP_IPV4M_NODE, "%s(config-router-af)# ", 1,
12144 };
12145
12146 static struct cmd_node bgp_ipv4_labeled_unicast_node = {
12147 BGP_IPV4L_NODE, "%s(config-router-af)# ", 1,
12148 };
12149
12150 static struct cmd_node bgp_ipv6_unicast_node = {
12151 BGP_IPV6_NODE, "%s(config-router-af)# ", 1,
12152 };
12153
12154 static struct cmd_node bgp_ipv6_multicast_node = {
12155 BGP_IPV6M_NODE, "%s(config-router-af)# ", 1,
12156 };
12157
12158 static struct cmd_node bgp_ipv6_labeled_unicast_node = {
12159 BGP_IPV6L_NODE, "%s(config-router-af)# ", 1,
12160 };
12161
12162 static struct cmd_node bgp_vpnv4_node = {BGP_VPNV4_NODE,
12163 "%s(config-router-af)# ", 1};
12164
12165 static struct cmd_node bgp_vpnv6_node = {BGP_VPNV6_NODE,
12166 "%s(config-router-af-vpnv6)# ", 1};
12167
12168 static struct cmd_node bgp_evpn_node = {BGP_EVPN_NODE,
12169 "%s(config-router-evpn)# ", 1};
12170
12171 static struct cmd_node bgp_evpn_vni_node = {BGP_EVPN_VNI_NODE,
12172 "%s(config-router-af-vni)# ", 1};
12173
12174 static struct cmd_node bgp_flowspecv4_node = {BGP_FLOWSPECV4_NODE,
12175 "%s(config-router-af)# ", 1};
12176
12177 static struct cmd_node bgp_flowspecv6_node = {BGP_FLOWSPECV6_NODE,
12178 "%s(config-router-af-vpnv6)# ", 1};
12179
12180 static void community_list_vty(void);
12181
12182 static void bgp_ac_neighbor(vector comps, struct cmd_token *token)
12183 {
12184 struct bgp *bgp;
12185 struct peer *peer;
12186 struct listnode *lnbgp, *lnpeer;
12187
12188 for (ALL_LIST_ELEMENTS_RO(bm->bgp, lnbgp, bgp)) {
12189 for (ALL_LIST_ELEMENTS_RO(bgp->peer, lnpeer, peer)) {
12190 /* only provide suggestions on the appropriate input
12191 * token type,
12192 * they'll otherwise show up multiple times */
12193 enum cmd_token_type match_type;
12194 char *name = peer->host;
12195
12196 if (peer->conf_if) {
12197 match_type = VARIABLE_TKN;
12198 name = peer->conf_if;
12199 } else if (strchr(peer->host, ':'))
12200 match_type = IPV6_TKN;
12201 else
12202 match_type = IPV4_TKN;
12203
12204 if (token->type != match_type)
12205 continue;
12206
12207 vector_set(comps, XSTRDUP(MTYPE_COMPLETION, name));
12208 }
12209 }
12210 }
12211
12212 static const struct cmd_variable_handler bgp_var_neighbor[] = {
12213 {.varname = "neighbor", .completions = bgp_ac_neighbor},
12214 {.varname = "neighbors", .completions = bgp_ac_neighbor},
12215 {.varname = "peer", .completions = bgp_ac_neighbor},
12216 {.completions = NULL}};
12217
12218 static void bgp_ac_peergroup(vector comps, struct cmd_token *token)
12219 {
12220 struct bgp *bgp;
12221 struct peer_group *group;
12222 struct listnode *lnbgp, *lnpeer;
12223
12224 for (ALL_LIST_ELEMENTS_RO(bm->bgp, lnbgp, bgp)) {
12225 for (ALL_LIST_ELEMENTS_RO(bgp->group, lnpeer, group))
12226 vector_set(comps, XSTRDUP(MTYPE_COMPLETION,
12227 group->name));
12228 }
12229 }
12230
12231 static const struct cmd_variable_handler bgp_var_peergroup[] = {
12232 {.tokenname = "PGNAME", .completions = bgp_ac_peergroup},
12233 {.completions = NULL} };
12234
12235 void bgp_vty_init(void)
12236 {
12237 cmd_variable_handler_register(bgp_var_neighbor);
12238 cmd_variable_handler_register(bgp_var_peergroup);
12239
12240 /* Install bgp top node. */
12241 install_node(&bgp_node, bgp_config_write);
12242 install_node(&bgp_ipv4_unicast_node, NULL);
12243 install_node(&bgp_ipv4_multicast_node, NULL);
12244 install_node(&bgp_ipv4_labeled_unicast_node, NULL);
12245 install_node(&bgp_ipv6_unicast_node, NULL);
12246 install_node(&bgp_ipv6_multicast_node, NULL);
12247 install_node(&bgp_ipv6_labeled_unicast_node, NULL);
12248 install_node(&bgp_vpnv4_node, NULL);
12249 install_node(&bgp_vpnv6_node, NULL);
12250 install_node(&bgp_evpn_node, NULL);
12251 install_node(&bgp_evpn_vni_node, NULL);
12252 install_node(&bgp_flowspecv4_node, NULL);
12253 install_node(&bgp_flowspecv6_node, NULL);
12254
12255 /* Install default VTY commands to new nodes. */
12256 install_default(BGP_NODE);
12257 install_default(BGP_IPV4_NODE);
12258 install_default(BGP_IPV4M_NODE);
12259 install_default(BGP_IPV4L_NODE);
12260 install_default(BGP_IPV6_NODE);
12261 install_default(BGP_IPV6M_NODE);
12262 install_default(BGP_IPV6L_NODE);
12263 install_default(BGP_VPNV4_NODE);
12264 install_default(BGP_VPNV6_NODE);
12265 install_default(BGP_FLOWSPECV4_NODE);
12266 install_default(BGP_FLOWSPECV6_NODE);
12267 install_default(BGP_EVPN_NODE);
12268 install_default(BGP_EVPN_VNI_NODE);
12269
12270 /* "bgp multiple-instance" commands. */
12271 install_element(CONFIG_NODE, &bgp_multiple_instance_cmd);
12272 install_element(CONFIG_NODE, &no_bgp_multiple_instance_cmd);
12273
12274 /* "bgp config-type" commands. */
12275 install_element(CONFIG_NODE, &bgp_config_type_cmd);
12276 install_element(CONFIG_NODE, &no_bgp_config_type_cmd);
12277
12278 /* bgp route-map delay-timer commands. */
12279 install_element(CONFIG_NODE, &bgp_set_route_map_delay_timer_cmd);
12280 install_element(CONFIG_NODE, &no_bgp_set_route_map_delay_timer_cmd);
12281
12282 /* Dummy commands (Currently not supported) */
12283 install_element(BGP_NODE, &no_synchronization_cmd);
12284 install_element(BGP_NODE, &no_auto_summary_cmd);
12285
12286 /* "router bgp" commands. */
12287 install_element(CONFIG_NODE, &router_bgp_cmd);
12288
12289 /* "no router bgp" commands. */
12290 install_element(CONFIG_NODE, &no_router_bgp_cmd);
12291
12292 /* "bgp router-id" commands. */
12293 install_element(BGP_NODE, &bgp_router_id_cmd);
12294 install_element(BGP_NODE, &no_bgp_router_id_cmd);
12295
12296 /* "bgp cluster-id" commands. */
12297 install_element(BGP_NODE, &bgp_cluster_id_cmd);
12298 install_element(BGP_NODE, &no_bgp_cluster_id_cmd);
12299
12300 /* "bgp confederation" commands. */
12301 install_element(BGP_NODE, &bgp_confederation_identifier_cmd);
12302 install_element(BGP_NODE, &no_bgp_confederation_identifier_cmd);
12303
12304 /* "bgp confederation peers" commands. */
12305 install_element(BGP_NODE, &bgp_confederation_peers_cmd);
12306 install_element(BGP_NODE, &no_bgp_confederation_peers_cmd);
12307
12308 /* bgp max-med command */
12309 install_element(BGP_NODE, &bgp_maxmed_admin_cmd);
12310 install_element(BGP_NODE, &no_bgp_maxmed_admin_cmd);
12311 install_element(BGP_NODE, &bgp_maxmed_admin_medv_cmd);
12312 install_element(BGP_NODE, &bgp_maxmed_onstartup_cmd);
12313 install_element(BGP_NODE, &no_bgp_maxmed_onstartup_cmd);
12314
12315 /* bgp disable-ebgp-connected-nh-check */
12316 install_element(BGP_NODE, &bgp_disable_connected_route_check_cmd);
12317 install_element(BGP_NODE, &no_bgp_disable_connected_route_check_cmd);
12318
12319 /* bgp update-delay command */
12320 install_element(BGP_NODE, &bgp_update_delay_cmd);
12321 install_element(BGP_NODE, &no_bgp_update_delay_cmd);
12322 install_element(BGP_NODE, &bgp_update_delay_establish_wait_cmd);
12323
12324 install_element(BGP_NODE, &bgp_wpkt_quanta_cmd);
12325 install_element(BGP_NODE, &no_bgp_wpkt_quanta_cmd);
12326 install_element(BGP_NODE, &bgp_rpkt_quanta_cmd);
12327 install_element(BGP_NODE, &no_bgp_rpkt_quanta_cmd);
12328
12329 install_element(BGP_NODE, &bgp_coalesce_time_cmd);
12330 install_element(BGP_NODE, &no_bgp_coalesce_time_cmd);
12331
12332 /* "maximum-paths" commands. */
12333 install_element(BGP_NODE, &bgp_maxpaths_hidden_cmd);
12334 install_element(BGP_NODE, &no_bgp_maxpaths_hidden_cmd);
12335 install_element(BGP_IPV4_NODE, &bgp_maxpaths_cmd);
12336 install_element(BGP_IPV4_NODE, &no_bgp_maxpaths_cmd);
12337 install_element(BGP_IPV6_NODE, &bgp_maxpaths_cmd);
12338 install_element(BGP_IPV6_NODE, &no_bgp_maxpaths_cmd);
12339 install_element(BGP_NODE, &bgp_maxpaths_ibgp_hidden_cmd);
12340 install_element(BGP_NODE, &bgp_maxpaths_ibgp_cluster_hidden_cmd);
12341 install_element(BGP_NODE, &no_bgp_maxpaths_ibgp_hidden_cmd);
12342 install_element(BGP_IPV4_NODE, &bgp_maxpaths_ibgp_cmd);
12343 install_element(BGP_IPV4_NODE, &bgp_maxpaths_ibgp_cluster_cmd);
12344 install_element(BGP_IPV4_NODE, &no_bgp_maxpaths_ibgp_cmd);
12345 install_element(BGP_IPV6_NODE, &bgp_maxpaths_ibgp_cmd);
12346 install_element(BGP_IPV6_NODE, &bgp_maxpaths_ibgp_cluster_cmd);
12347 install_element(BGP_IPV6_NODE, &no_bgp_maxpaths_ibgp_cmd);
12348
12349 install_element(BGP_IPV6L_NODE, &bgp_maxpaths_cmd);
12350 install_element(BGP_IPV6L_NODE, &no_bgp_maxpaths_cmd);
12351 install_element(BGP_IPV6L_NODE, &bgp_maxpaths_ibgp_cmd);
12352 install_element(BGP_IPV6L_NODE, &bgp_maxpaths_ibgp_cluster_cmd);
12353 install_element(BGP_IPV6L_NODE, &no_bgp_maxpaths_ibgp_cmd);
12354
12355 /* "timers bgp" commands. */
12356 install_element(BGP_NODE, &bgp_timers_cmd);
12357 install_element(BGP_NODE, &no_bgp_timers_cmd);
12358
12359 /* route-map delay-timer commands - per instance for backwards compat.
12360 */
12361 install_element(BGP_NODE, &bgp_set_route_map_delay_timer_cmd);
12362 install_element(BGP_NODE, &no_bgp_set_route_map_delay_timer_cmd);
12363
12364 /* "bgp client-to-client reflection" commands */
12365 install_element(BGP_NODE, &no_bgp_client_to_client_reflection_cmd);
12366 install_element(BGP_NODE, &bgp_client_to_client_reflection_cmd);
12367
12368 /* "bgp always-compare-med" commands */
12369 install_element(BGP_NODE, &bgp_always_compare_med_cmd);
12370 install_element(BGP_NODE, &no_bgp_always_compare_med_cmd);
12371
12372 /* "bgp deterministic-med" commands */
12373 install_element(BGP_NODE, &bgp_deterministic_med_cmd);
12374 install_element(BGP_NODE, &no_bgp_deterministic_med_cmd);
12375
12376 /* "bgp graceful-restart" commands */
12377 install_element(BGP_NODE, &bgp_graceful_restart_cmd);
12378 install_element(BGP_NODE, &no_bgp_graceful_restart_cmd);
12379 install_element(BGP_NODE, &bgp_graceful_restart_stalepath_time_cmd);
12380 install_element(BGP_NODE, &no_bgp_graceful_restart_stalepath_time_cmd);
12381 install_element(BGP_NODE, &bgp_graceful_restart_restart_time_cmd);
12382 install_element(BGP_NODE, &no_bgp_graceful_restart_restart_time_cmd);
12383
12384 install_element(BGP_NODE, &bgp_graceful_restart_preserve_fw_cmd);
12385 install_element(BGP_NODE, &no_bgp_graceful_restart_preserve_fw_cmd);
12386
12387 /* "bgp graceful-shutdown" commands */
12388 install_element(BGP_NODE, &bgp_graceful_shutdown_cmd);
12389 install_element(BGP_NODE, &no_bgp_graceful_shutdown_cmd);
12390
12391 /* "bgp fast-external-failover" commands */
12392 install_element(BGP_NODE, &bgp_fast_external_failover_cmd);
12393 install_element(BGP_NODE, &no_bgp_fast_external_failover_cmd);
12394
12395 /* "bgp enforce-first-as" commands */
12396 install_element(BGP_NODE, &bgp_enforce_first_as_cmd);
12397 install_element(BGP_NODE, &no_bgp_enforce_first_as_cmd);
12398
12399 /* "bgp bestpath compare-routerid" commands */
12400 install_element(BGP_NODE, &bgp_bestpath_compare_router_id_cmd);
12401 install_element(BGP_NODE, &no_bgp_bestpath_compare_router_id_cmd);
12402
12403 /* "bgp bestpath as-path ignore" commands */
12404 install_element(BGP_NODE, &bgp_bestpath_aspath_ignore_cmd);
12405 install_element(BGP_NODE, &no_bgp_bestpath_aspath_ignore_cmd);
12406
12407 /* "bgp bestpath as-path confed" commands */
12408 install_element(BGP_NODE, &bgp_bestpath_aspath_confed_cmd);
12409 install_element(BGP_NODE, &no_bgp_bestpath_aspath_confed_cmd);
12410
12411 /* "bgp bestpath as-path multipath-relax" commands */
12412 install_element(BGP_NODE, &bgp_bestpath_aspath_multipath_relax_cmd);
12413 install_element(BGP_NODE, &no_bgp_bestpath_aspath_multipath_relax_cmd);
12414
12415 /* "bgp log-neighbor-changes" commands */
12416 install_element(BGP_NODE, &bgp_log_neighbor_changes_cmd);
12417 install_element(BGP_NODE, &no_bgp_log_neighbor_changes_cmd);
12418
12419 /* "bgp bestpath med" commands */
12420 install_element(BGP_NODE, &bgp_bestpath_med_cmd);
12421 install_element(BGP_NODE, &no_bgp_bestpath_med_cmd);
12422
12423 /* "no bgp default ipv4-unicast" commands. */
12424 install_element(BGP_NODE, &no_bgp_default_ipv4_unicast_cmd);
12425 install_element(BGP_NODE, &bgp_default_ipv4_unicast_cmd);
12426
12427 /* "bgp network import-check" commands. */
12428 install_element(BGP_NODE, &bgp_network_import_check_cmd);
12429 install_element(BGP_NODE, &bgp_network_import_check_exact_cmd);
12430 install_element(BGP_NODE, &no_bgp_network_import_check_cmd);
12431
12432 /* "bgp default local-preference" commands. */
12433 install_element(BGP_NODE, &bgp_default_local_preference_cmd);
12434 install_element(BGP_NODE, &no_bgp_default_local_preference_cmd);
12435
12436 /* bgp default show-hostname */
12437 install_element(BGP_NODE, &bgp_default_show_hostname_cmd);
12438 install_element(BGP_NODE, &no_bgp_default_show_hostname_cmd);
12439
12440 /* "bgp default subgroup-pkt-queue-max" commands. */
12441 install_element(BGP_NODE, &bgp_default_subgroup_pkt_queue_max_cmd);
12442 install_element(BGP_NODE, &no_bgp_default_subgroup_pkt_queue_max_cmd);
12443
12444 /* bgp ibgp-allow-policy-mods command */
12445 install_element(BGP_NODE, &bgp_rr_allow_outbound_policy_cmd);
12446 install_element(BGP_NODE, &no_bgp_rr_allow_outbound_policy_cmd);
12447
12448 /* "bgp listen limit" commands. */
12449 install_element(BGP_NODE, &bgp_listen_limit_cmd);
12450 install_element(BGP_NODE, &no_bgp_listen_limit_cmd);
12451
12452 /* "bgp listen range" commands. */
12453 install_element(BGP_NODE, &bgp_listen_range_cmd);
12454 install_element(BGP_NODE, &no_bgp_listen_range_cmd);
12455
12456 /* "bgp default shutdown" command */
12457 install_element(BGP_NODE, &bgp_default_shutdown_cmd);
12458
12459 /* "neighbor remote-as" commands. */
12460 install_element(BGP_NODE, &neighbor_remote_as_cmd);
12461 install_element(BGP_NODE, &neighbor_interface_config_cmd);
12462 install_element(BGP_NODE, &neighbor_interface_config_v6only_cmd);
12463 install_element(BGP_NODE, &neighbor_interface_config_remote_as_cmd);
12464 install_element(BGP_NODE,
12465 &neighbor_interface_v6only_config_remote_as_cmd);
12466 install_element(BGP_NODE, &no_neighbor_cmd);
12467 install_element(BGP_NODE, &no_neighbor_interface_config_cmd);
12468
12469 /* "neighbor peer-group" commands. */
12470 install_element(BGP_NODE, &neighbor_peer_group_cmd);
12471 install_element(BGP_NODE, &no_neighbor_peer_group_cmd);
12472 install_element(BGP_NODE,
12473 &no_neighbor_interface_peer_group_remote_as_cmd);
12474
12475 /* "neighbor local-as" commands. */
12476 install_element(BGP_NODE, &neighbor_local_as_cmd);
12477 install_element(BGP_NODE, &neighbor_local_as_no_prepend_cmd);
12478 install_element(BGP_NODE, &neighbor_local_as_no_prepend_replace_as_cmd);
12479 install_element(BGP_NODE, &no_neighbor_local_as_cmd);
12480
12481 /* "neighbor solo" commands. */
12482 install_element(BGP_NODE, &neighbor_solo_cmd);
12483 install_element(BGP_NODE, &no_neighbor_solo_cmd);
12484
12485 /* "neighbor password" commands. */
12486 install_element(BGP_NODE, &neighbor_password_cmd);
12487 install_element(BGP_NODE, &no_neighbor_password_cmd);
12488
12489 /* "neighbor activate" commands. */
12490 install_element(BGP_NODE, &neighbor_activate_hidden_cmd);
12491 install_element(BGP_IPV4_NODE, &neighbor_activate_cmd);
12492 install_element(BGP_IPV4M_NODE, &neighbor_activate_cmd);
12493 install_element(BGP_IPV4L_NODE, &neighbor_activate_cmd);
12494 install_element(BGP_IPV6_NODE, &neighbor_activate_cmd);
12495 install_element(BGP_IPV6M_NODE, &neighbor_activate_cmd);
12496 install_element(BGP_IPV6L_NODE, &neighbor_activate_cmd);
12497 install_element(BGP_VPNV4_NODE, &neighbor_activate_cmd);
12498 install_element(BGP_VPNV6_NODE, &neighbor_activate_cmd);
12499 install_element(BGP_FLOWSPECV4_NODE, &neighbor_activate_cmd);
12500 install_element(BGP_FLOWSPECV6_NODE, &neighbor_activate_cmd);
12501 install_element(BGP_EVPN_NODE, &neighbor_activate_cmd);
12502
12503 /* "no neighbor activate" commands. */
12504 install_element(BGP_NODE, &no_neighbor_activate_hidden_cmd);
12505 install_element(BGP_IPV4_NODE, &no_neighbor_activate_cmd);
12506 install_element(BGP_IPV4M_NODE, &no_neighbor_activate_cmd);
12507 install_element(BGP_IPV4L_NODE, &no_neighbor_activate_cmd);
12508 install_element(BGP_IPV6_NODE, &no_neighbor_activate_cmd);
12509 install_element(BGP_IPV6M_NODE, &no_neighbor_activate_cmd);
12510 install_element(BGP_IPV6L_NODE, &no_neighbor_activate_cmd);
12511 install_element(BGP_VPNV4_NODE, &no_neighbor_activate_cmd);
12512 install_element(BGP_VPNV6_NODE, &no_neighbor_activate_cmd);
12513 install_element(BGP_FLOWSPECV4_NODE, &no_neighbor_activate_cmd);
12514 install_element(BGP_FLOWSPECV6_NODE, &no_neighbor_activate_cmd);
12515 install_element(BGP_EVPN_NODE, &no_neighbor_activate_cmd);
12516
12517 /* "neighbor peer-group" set commands. */
12518 install_element(BGP_NODE, &neighbor_set_peer_group_cmd);
12519 install_element(BGP_IPV4_NODE, &neighbor_set_peer_group_hidden_cmd);
12520 install_element(BGP_IPV4M_NODE, &neighbor_set_peer_group_hidden_cmd);
12521 install_element(BGP_IPV6_NODE, &neighbor_set_peer_group_hidden_cmd);
12522 install_element(BGP_IPV6M_NODE, &neighbor_set_peer_group_hidden_cmd);
12523 install_element(BGP_IPV6L_NODE, &neighbor_set_peer_group_hidden_cmd);
12524 install_element(BGP_VPNV4_NODE, &neighbor_set_peer_group_hidden_cmd);
12525 install_element(BGP_VPNV6_NODE, &neighbor_set_peer_group_hidden_cmd);
12526 install_element(BGP_FLOWSPECV4_NODE,
12527 &neighbor_set_peer_group_hidden_cmd);
12528 install_element(BGP_FLOWSPECV6_NODE,
12529 &neighbor_set_peer_group_hidden_cmd);
12530
12531 /* "no neighbor peer-group unset" commands. */
12532 install_element(BGP_NODE, &no_neighbor_set_peer_group_cmd);
12533 install_element(BGP_IPV4_NODE, &no_neighbor_set_peer_group_hidden_cmd);
12534 install_element(BGP_IPV4M_NODE, &no_neighbor_set_peer_group_hidden_cmd);
12535 install_element(BGP_IPV6_NODE, &no_neighbor_set_peer_group_hidden_cmd);
12536 install_element(BGP_IPV6M_NODE, &no_neighbor_set_peer_group_hidden_cmd);
12537 install_element(BGP_IPV6L_NODE, &no_neighbor_set_peer_group_hidden_cmd);
12538 install_element(BGP_VPNV4_NODE, &no_neighbor_set_peer_group_hidden_cmd);
12539 install_element(BGP_VPNV6_NODE, &no_neighbor_set_peer_group_hidden_cmd);
12540 install_element(BGP_FLOWSPECV4_NODE,
12541 &no_neighbor_set_peer_group_hidden_cmd);
12542 install_element(BGP_FLOWSPECV6_NODE,
12543 &no_neighbor_set_peer_group_hidden_cmd);
12544
12545 /* "neighbor softreconfiguration inbound" commands.*/
12546 install_element(BGP_NODE, &neighbor_soft_reconfiguration_hidden_cmd);
12547 install_element(BGP_NODE, &no_neighbor_soft_reconfiguration_hidden_cmd);
12548 install_element(BGP_IPV4_NODE, &neighbor_soft_reconfiguration_cmd);
12549 install_element(BGP_IPV4_NODE, &no_neighbor_soft_reconfiguration_cmd);
12550 install_element(BGP_IPV4L_NODE, &neighbor_soft_reconfiguration_cmd);
12551 install_element(BGP_IPV4L_NODE, &no_neighbor_soft_reconfiguration_cmd);
12552 install_element(BGP_IPV4M_NODE, &neighbor_soft_reconfiguration_cmd);
12553 install_element(BGP_IPV4M_NODE, &no_neighbor_soft_reconfiguration_cmd);
12554 install_element(BGP_IPV6_NODE, &neighbor_soft_reconfiguration_cmd);
12555 install_element(BGP_IPV6_NODE, &no_neighbor_soft_reconfiguration_cmd);
12556 install_element(BGP_IPV6M_NODE, &neighbor_soft_reconfiguration_cmd);
12557 install_element(BGP_IPV6M_NODE, &no_neighbor_soft_reconfiguration_cmd);
12558 install_element(BGP_IPV6L_NODE, &neighbor_soft_reconfiguration_cmd);
12559 install_element(BGP_IPV6L_NODE, &no_neighbor_soft_reconfiguration_cmd);
12560 install_element(BGP_VPNV4_NODE, &neighbor_soft_reconfiguration_cmd);
12561 install_element(BGP_VPNV4_NODE, &no_neighbor_soft_reconfiguration_cmd);
12562 install_element(BGP_VPNV6_NODE, &neighbor_soft_reconfiguration_cmd);
12563 install_element(BGP_VPNV6_NODE, &no_neighbor_soft_reconfiguration_cmd);
12564 install_element(BGP_FLOWSPECV4_NODE,
12565 &neighbor_soft_reconfiguration_cmd);
12566 install_element(BGP_FLOWSPECV4_NODE,
12567 &no_neighbor_soft_reconfiguration_cmd);
12568 install_element(BGP_FLOWSPECV6_NODE,
12569 &neighbor_soft_reconfiguration_cmd);
12570 install_element(BGP_FLOWSPECV6_NODE,
12571 &no_neighbor_soft_reconfiguration_cmd);
12572
12573 /* "neighbor attribute-unchanged" commands. */
12574 install_element(BGP_NODE, &neighbor_attr_unchanged_hidden_cmd);
12575 install_element(BGP_NODE, &no_neighbor_attr_unchanged_hidden_cmd);
12576 install_element(BGP_IPV4_NODE, &neighbor_attr_unchanged_cmd);
12577 install_element(BGP_IPV4_NODE, &no_neighbor_attr_unchanged_cmd);
12578 install_element(BGP_IPV4M_NODE, &neighbor_attr_unchanged_cmd);
12579 install_element(BGP_IPV4M_NODE, &no_neighbor_attr_unchanged_cmd);
12580 install_element(BGP_IPV4L_NODE, &neighbor_attr_unchanged_cmd);
12581 install_element(BGP_IPV4L_NODE, &no_neighbor_attr_unchanged_cmd);
12582 install_element(BGP_IPV6_NODE, &neighbor_attr_unchanged_cmd);
12583 install_element(BGP_IPV6_NODE, &no_neighbor_attr_unchanged_cmd);
12584 install_element(BGP_IPV6M_NODE, &neighbor_attr_unchanged_cmd);
12585 install_element(BGP_IPV6M_NODE, &no_neighbor_attr_unchanged_cmd);
12586 install_element(BGP_IPV6L_NODE, &neighbor_attr_unchanged_cmd);
12587 install_element(BGP_IPV6L_NODE, &no_neighbor_attr_unchanged_cmd);
12588 install_element(BGP_VPNV4_NODE, &neighbor_attr_unchanged_cmd);
12589 install_element(BGP_VPNV4_NODE, &no_neighbor_attr_unchanged_cmd);
12590 install_element(BGP_VPNV6_NODE, &neighbor_attr_unchanged_cmd);
12591 install_element(BGP_VPNV6_NODE, &no_neighbor_attr_unchanged_cmd);
12592
12593 install_element(BGP_EVPN_NODE, &neighbor_attr_unchanged_cmd);
12594 install_element(BGP_EVPN_NODE, &no_neighbor_attr_unchanged_cmd);
12595
12596 /* "nexthop-local unchanged" commands */
12597 install_element(BGP_IPV6_NODE, &neighbor_nexthop_local_unchanged_cmd);
12598 install_element(BGP_IPV6_NODE,
12599 &no_neighbor_nexthop_local_unchanged_cmd);
12600
12601 /* "neighbor next-hop-self" commands. */
12602 install_element(BGP_NODE, &neighbor_nexthop_self_hidden_cmd);
12603 install_element(BGP_NODE, &no_neighbor_nexthop_self_hidden_cmd);
12604 install_element(BGP_IPV4_NODE, &neighbor_nexthop_self_cmd);
12605 install_element(BGP_IPV4_NODE, &no_neighbor_nexthop_self_cmd);
12606 install_element(BGP_IPV4M_NODE, &neighbor_nexthop_self_cmd);
12607 install_element(BGP_IPV4M_NODE, &no_neighbor_nexthop_self_cmd);
12608 install_element(BGP_IPV4L_NODE, &neighbor_nexthop_self_cmd);
12609 install_element(BGP_IPV4L_NODE, &no_neighbor_nexthop_self_cmd);
12610 install_element(BGP_IPV6_NODE, &neighbor_nexthop_self_cmd);
12611 install_element(BGP_IPV6_NODE, &no_neighbor_nexthop_self_cmd);
12612 install_element(BGP_IPV6M_NODE, &neighbor_nexthop_self_cmd);
12613 install_element(BGP_IPV6M_NODE, &no_neighbor_nexthop_self_cmd);
12614 install_element(BGP_IPV6L_NODE, &neighbor_nexthop_self_cmd);
12615 install_element(BGP_IPV6L_NODE, &no_neighbor_nexthop_self_cmd);
12616 install_element(BGP_VPNV4_NODE, &neighbor_nexthop_self_cmd);
12617 install_element(BGP_VPNV4_NODE, &no_neighbor_nexthop_self_cmd);
12618 install_element(BGP_VPNV6_NODE, &neighbor_nexthop_self_cmd);
12619 install_element(BGP_VPNV6_NODE, &no_neighbor_nexthop_self_cmd);
12620 install_element(BGP_EVPN_NODE, &neighbor_nexthop_self_cmd);
12621 install_element(BGP_EVPN_NODE, &no_neighbor_nexthop_self_cmd);
12622
12623 /* "neighbor next-hop-self force" commands. */
12624 install_element(BGP_NODE, &neighbor_nexthop_self_force_hidden_cmd);
12625 install_element(BGP_NODE, &no_neighbor_nexthop_self_force_hidden_cmd);
12626 install_element(BGP_IPV4_NODE, &neighbor_nexthop_self_force_cmd);
12627 install_element(BGP_IPV4_NODE, &no_neighbor_nexthop_self_force_cmd);
12628 install_element(BGP_IPV4M_NODE, &neighbor_nexthop_self_force_cmd);
12629 install_element(BGP_IPV4M_NODE, &no_neighbor_nexthop_self_force_cmd);
12630 install_element(BGP_IPV4L_NODE, &neighbor_nexthop_self_force_cmd);
12631 install_element(BGP_IPV4L_NODE, &no_neighbor_nexthop_self_force_cmd);
12632 install_element(BGP_IPV6_NODE, &neighbor_nexthop_self_force_cmd);
12633 install_element(BGP_IPV6_NODE, &no_neighbor_nexthop_self_force_cmd);
12634 install_element(BGP_IPV6M_NODE, &neighbor_nexthop_self_force_cmd);
12635 install_element(BGP_IPV6M_NODE, &no_neighbor_nexthop_self_force_cmd);
12636 install_element(BGP_IPV6L_NODE, &neighbor_nexthop_self_force_cmd);
12637 install_element(BGP_IPV6L_NODE, &no_neighbor_nexthop_self_force_cmd);
12638 install_element(BGP_VPNV4_NODE, &neighbor_nexthop_self_force_cmd);
12639 install_element(BGP_VPNV4_NODE, &no_neighbor_nexthop_self_force_cmd);
12640 install_element(BGP_VPNV6_NODE, &neighbor_nexthop_self_force_cmd);
12641 install_element(BGP_VPNV6_NODE, &no_neighbor_nexthop_self_force_cmd);
12642
12643 /* "neighbor as-override" commands. */
12644 install_element(BGP_NODE, &neighbor_as_override_hidden_cmd);
12645 install_element(BGP_NODE, &no_neighbor_as_override_hidden_cmd);
12646 install_element(BGP_IPV4_NODE, &neighbor_as_override_cmd);
12647 install_element(BGP_IPV4_NODE, &no_neighbor_as_override_cmd);
12648 install_element(BGP_IPV4M_NODE, &neighbor_as_override_cmd);
12649 install_element(BGP_IPV4M_NODE, &no_neighbor_as_override_cmd);
12650 install_element(BGP_IPV4L_NODE, &neighbor_as_override_cmd);
12651 install_element(BGP_IPV4L_NODE, &no_neighbor_as_override_cmd);
12652 install_element(BGP_IPV6_NODE, &neighbor_as_override_cmd);
12653 install_element(BGP_IPV6_NODE, &no_neighbor_as_override_cmd);
12654 install_element(BGP_IPV6M_NODE, &neighbor_as_override_cmd);
12655 install_element(BGP_IPV6M_NODE, &no_neighbor_as_override_cmd);
12656 install_element(BGP_IPV6L_NODE, &neighbor_as_override_cmd);
12657 install_element(BGP_IPV6L_NODE, &no_neighbor_as_override_cmd);
12658 install_element(BGP_VPNV4_NODE, &neighbor_as_override_cmd);
12659 install_element(BGP_VPNV4_NODE, &no_neighbor_as_override_cmd);
12660 install_element(BGP_VPNV6_NODE, &neighbor_as_override_cmd);
12661 install_element(BGP_VPNV6_NODE, &no_neighbor_as_override_cmd);
12662
12663 /* "neighbor remove-private-AS" commands. */
12664 install_element(BGP_NODE, &neighbor_remove_private_as_hidden_cmd);
12665 install_element(BGP_NODE, &no_neighbor_remove_private_as_hidden_cmd);
12666 install_element(BGP_NODE, &neighbor_remove_private_as_all_hidden_cmd);
12667 install_element(BGP_NODE,
12668 &no_neighbor_remove_private_as_all_hidden_cmd);
12669 install_element(BGP_NODE,
12670 &neighbor_remove_private_as_replace_as_hidden_cmd);
12671 install_element(BGP_NODE,
12672 &no_neighbor_remove_private_as_replace_as_hidden_cmd);
12673 install_element(BGP_NODE,
12674 &neighbor_remove_private_as_all_replace_as_hidden_cmd);
12675 install_element(
12676 BGP_NODE,
12677 &no_neighbor_remove_private_as_all_replace_as_hidden_cmd);
12678 install_element(BGP_IPV4_NODE, &neighbor_remove_private_as_cmd);
12679 install_element(BGP_IPV4_NODE, &no_neighbor_remove_private_as_cmd);
12680 install_element(BGP_IPV4_NODE, &neighbor_remove_private_as_all_cmd);
12681 install_element(BGP_IPV4_NODE, &no_neighbor_remove_private_as_all_cmd);
12682 install_element(BGP_IPV4_NODE,
12683 &neighbor_remove_private_as_replace_as_cmd);
12684 install_element(BGP_IPV4_NODE,
12685 &no_neighbor_remove_private_as_replace_as_cmd);
12686 install_element(BGP_IPV4_NODE,
12687 &neighbor_remove_private_as_all_replace_as_cmd);
12688 install_element(BGP_IPV4_NODE,
12689 &no_neighbor_remove_private_as_all_replace_as_cmd);
12690 install_element(BGP_IPV4M_NODE, &neighbor_remove_private_as_cmd);
12691 install_element(BGP_IPV4M_NODE, &no_neighbor_remove_private_as_cmd);
12692 install_element(BGP_IPV4M_NODE, &neighbor_remove_private_as_all_cmd);
12693 install_element(BGP_IPV4M_NODE, &no_neighbor_remove_private_as_all_cmd);
12694 install_element(BGP_IPV4M_NODE,
12695 &neighbor_remove_private_as_replace_as_cmd);
12696 install_element(BGP_IPV4M_NODE,
12697 &no_neighbor_remove_private_as_replace_as_cmd);
12698 install_element(BGP_IPV4M_NODE,
12699 &neighbor_remove_private_as_all_replace_as_cmd);
12700 install_element(BGP_IPV4M_NODE,
12701 &no_neighbor_remove_private_as_all_replace_as_cmd);
12702 install_element(BGP_IPV4L_NODE, &neighbor_remove_private_as_cmd);
12703 install_element(BGP_IPV4L_NODE, &no_neighbor_remove_private_as_cmd);
12704 install_element(BGP_IPV4L_NODE, &neighbor_remove_private_as_all_cmd);
12705 install_element(BGP_IPV4L_NODE, &no_neighbor_remove_private_as_all_cmd);
12706 install_element(BGP_IPV4L_NODE,
12707 &neighbor_remove_private_as_replace_as_cmd);
12708 install_element(BGP_IPV4L_NODE,
12709 &no_neighbor_remove_private_as_replace_as_cmd);
12710 install_element(BGP_IPV4L_NODE,
12711 &neighbor_remove_private_as_all_replace_as_cmd);
12712 install_element(BGP_IPV4L_NODE,
12713 &no_neighbor_remove_private_as_all_replace_as_cmd);
12714 install_element(BGP_IPV6_NODE, &neighbor_remove_private_as_cmd);
12715 install_element(BGP_IPV6_NODE, &no_neighbor_remove_private_as_cmd);
12716 install_element(BGP_IPV6_NODE, &neighbor_remove_private_as_all_cmd);
12717 install_element(BGP_IPV6_NODE, &no_neighbor_remove_private_as_all_cmd);
12718 install_element(BGP_IPV6_NODE,
12719 &neighbor_remove_private_as_replace_as_cmd);
12720 install_element(BGP_IPV6_NODE,
12721 &no_neighbor_remove_private_as_replace_as_cmd);
12722 install_element(BGP_IPV6_NODE,
12723 &neighbor_remove_private_as_all_replace_as_cmd);
12724 install_element(BGP_IPV6_NODE,
12725 &no_neighbor_remove_private_as_all_replace_as_cmd);
12726 install_element(BGP_IPV6M_NODE, &neighbor_remove_private_as_cmd);
12727 install_element(BGP_IPV6M_NODE, &no_neighbor_remove_private_as_cmd);
12728 install_element(BGP_IPV6M_NODE, &neighbor_remove_private_as_all_cmd);
12729 install_element(BGP_IPV6M_NODE, &no_neighbor_remove_private_as_all_cmd);
12730 install_element(BGP_IPV6M_NODE,
12731 &neighbor_remove_private_as_replace_as_cmd);
12732 install_element(BGP_IPV6M_NODE,
12733 &no_neighbor_remove_private_as_replace_as_cmd);
12734 install_element(BGP_IPV6M_NODE,
12735 &neighbor_remove_private_as_all_replace_as_cmd);
12736 install_element(BGP_IPV6M_NODE,
12737 &no_neighbor_remove_private_as_all_replace_as_cmd);
12738 install_element(BGP_IPV6L_NODE, &neighbor_remove_private_as_cmd);
12739 install_element(BGP_IPV6L_NODE, &no_neighbor_remove_private_as_cmd);
12740 install_element(BGP_IPV6L_NODE, &neighbor_remove_private_as_all_cmd);
12741 install_element(BGP_IPV6L_NODE, &no_neighbor_remove_private_as_all_cmd);
12742 install_element(BGP_IPV6L_NODE,
12743 &neighbor_remove_private_as_replace_as_cmd);
12744 install_element(BGP_IPV6L_NODE,
12745 &no_neighbor_remove_private_as_replace_as_cmd);
12746 install_element(BGP_IPV6L_NODE,
12747 &neighbor_remove_private_as_all_replace_as_cmd);
12748 install_element(BGP_IPV6L_NODE,
12749 &no_neighbor_remove_private_as_all_replace_as_cmd);
12750 install_element(BGP_VPNV4_NODE, &neighbor_remove_private_as_cmd);
12751 install_element(BGP_VPNV4_NODE, &no_neighbor_remove_private_as_cmd);
12752 install_element(BGP_VPNV4_NODE, &neighbor_remove_private_as_all_cmd);
12753 install_element(BGP_VPNV4_NODE, &no_neighbor_remove_private_as_all_cmd);
12754 install_element(BGP_VPNV4_NODE,
12755 &neighbor_remove_private_as_replace_as_cmd);
12756 install_element(BGP_VPNV4_NODE,
12757 &no_neighbor_remove_private_as_replace_as_cmd);
12758 install_element(BGP_VPNV4_NODE,
12759 &neighbor_remove_private_as_all_replace_as_cmd);
12760 install_element(BGP_VPNV4_NODE,
12761 &no_neighbor_remove_private_as_all_replace_as_cmd);
12762 install_element(BGP_VPNV6_NODE, &neighbor_remove_private_as_cmd);
12763 install_element(BGP_VPNV6_NODE, &no_neighbor_remove_private_as_cmd);
12764 install_element(BGP_VPNV6_NODE, &neighbor_remove_private_as_all_cmd);
12765 install_element(BGP_VPNV6_NODE, &no_neighbor_remove_private_as_all_cmd);
12766 install_element(BGP_VPNV6_NODE,
12767 &neighbor_remove_private_as_replace_as_cmd);
12768 install_element(BGP_VPNV6_NODE,
12769 &no_neighbor_remove_private_as_replace_as_cmd);
12770 install_element(BGP_VPNV6_NODE,
12771 &neighbor_remove_private_as_all_replace_as_cmd);
12772 install_element(BGP_VPNV6_NODE,
12773 &no_neighbor_remove_private_as_all_replace_as_cmd);
12774
12775 /* "neighbor send-community" commands.*/
12776 install_element(BGP_NODE, &neighbor_send_community_hidden_cmd);
12777 install_element(BGP_NODE, &neighbor_send_community_type_hidden_cmd);
12778 install_element(BGP_NODE, &no_neighbor_send_community_hidden_cmd);
12779 install_element(BGP_NODE, &no_neighbor_send_community_type_hidden_cmd);
12780 install_element(BGP_IPV4_NODE, &neighbor_send_community_cmd);
12781 install_element(BGP_IPV4_NODE, &neighbor_send_community_type_cmd);
12782 install_element(BGP_IPV4_NODE, &no_neighbor_send_community_cmd);
12783 install_element(BGP_IPV4_NODE, &no_neighbor_send_community_type_cmd);
12784 install_element(BGP_IPV4M_NODE, &neighbor_send_community_cmd);
12785 install_element(BGP_IPV4M_NODE, &neighbor_send_community_type_cmd);
12786 install_element(BGP_IPV4M_NODE, &no_neighbor_send_community_cmd);
12787 install_element(BGP_IPV4M_NODE, &no_neighbor_send_community_type_cmd);
12788 install_element(BGP_IPV4L_NODE, &neighbor_send_community_cmd);
12789 install_element(BGP_IPV4L_NODE, &neighbor_send_community_type_cmd);
12790 install_element(BGP_IPV4L_NODE, &no_neighbor_send_community_cmd);
12791 install_element(BGP_IPV4L_NODE, &no_neighbor_send_community_type_cmd);
12792 install_element(BGP_IPV6_NODE, &neighbor_send_community_cmd);
12793 install_element(BGP_IPV6_NODE, &neighbor_send_community_type_cmd);
12794 install_element(BGP_IPV6_NODE, &no_neighbor_send_community_cmd);
12795 install_element(BGP_IPV6_NODE, &no_neighbor_send_community_type_cmd);
12796 install_element(BGP_IPV6M_NODE, &neighbor_send_community_cmd);
12797 install_element(BGP_IPV6M_NODE, &neighbor_send_community_type_cmd);
12798 install_element(BGP_IPV6M_NODE, &no_neighbor_send_community_cmd);
12799 install_element(BGP_IPV6M_NODE, &no_neighbor_send_community_type_cmd);
12800 install_element(BGP_IPV6L_NODE, &neighbor_send_community_cmd);
12801 install_element(BGP_IPV6L_NODE, &neighbor_send_community_type_cmd);
12802 install_element(BGP_IPV6L_NODE, &no_neighbor_send_community_cmd);
12803 install_element(BGP_IPV6L_NODE, &no_neighbor_send_community_type_cmd);
12804 install_element(BGP_VPNV4_NODE, &neighbor_send_community_cmd);
12805 install_element(BGP_VPNV4_NODE, &neighbor_send_community_type_cmd);
12806 install_element(BGP_VPNV4_NODE, &no_neighbor_send_community_cmd);
12807 install_element(BGP_VPNV4_NODE, &no_neighbor_send_community_type_cmd);
12808 install_element(BGP_VPNV6_NODE, &neighbor_send_community_cmd);
12809 install_element(BGP_VPNV6_NODE, &neighbor_send_community_type_cmd);
12810 install_element(BGP_VPNV6_NODE, &no_neighbor_send_community_cmd);
12811 install_element(BGP_VPNV6_NODE, &no_neighbor_send_community_type_cmd);
12812
12813 /* "neighbor route-reflector" commands.*/
12814 install_element(BGP_NODE, &neighbor_route_reflector_client_hidden_cmd);
12815 install_element(BGP_NODE,
12816 &no_neighbor_route_reflector_client_hidden_cmd);
12817 install_element(BGP_IPV4_NODE, &neighbor_route_reflector_client_cmd);
12818 install_element(BGP_IPV4_NODE, &no_neighbor_route_reflector_client_cmd);
12819 install_element(BGP_IPV4M_NODE, &neighbor_route_reflector_client_cmd);
12820 install_element(BGP_IPV4M_NODE,
12821 &no_neighbor_route_reflector_client_cmd);
12822 install_element(BGP_IPV4L_NODE, &neighbor_route_reflector_client_cmd);
12823 install_element(BGP_IPV4L_NODE,
12824 &no_neighbor_route_reflector_client_cmd);
12825 install_element(BGP_IPV6_NODE, &neighbor_route_reflector_client_cmd);
12826 install_element(BGP_IPV6_NODE, &no_neighbor_route_reflector_client_cmd);
12827 install_element(BGP_IPV6M_NODE, &neighbor_route_reflector_client_cmd);
12828 install_element(BGP_IPV6M_NODE,
12829 &no_neighbor_route_reflector_client_cmd);
12830 install_element(BGP_IPV6L_NODE, &neighbor_route_reflector_client_cmd);
12831 install_element(BGP_IPV6L_NODE,
12832 &no_neighbor_route_reflector_client_cmd);
12833 install_element(BGP_VPNV4_NODE, &neighbor_route_reflector_client_cmd);
12834 install_element(BGP_VPNV4_NODE,
12835 &no_neighbor_route_reflector_client_cmd);
12836 install_element(BGP_VPNV6_NODE, &neighbor_route_reflector_client_cmd);
12837 install_element(BGP_VPNV6_NODE,
12838 &no_neighbor_route_reflector_client_cmd);
12839 install_element(BGP_FLOWSPECV4_NODE,
12840 &neighbor_route_reflector_client_cmd);
12841 install_element(BGP_FLOWSPECV4_NODE,
12842 &no_neighbor_route_reflector_client_cmd);
12843 install_element(BGP_FLOWSPECV6_NODE,
12844 &neighbor_route_reflector_client_cmd);
12845 install_element(BGP_FLOWSPECV6_NODE,
12846 &no_neighbor_route_reflector_client_cmd);
12847 install_element(BGP_EVPN_NODE, &neighbor_route_reflector_client_cmd);
12848 install_element(BGP_EVPN_NODE, &no_neighbor_route_reflector_client_cmd);
12849
12850 /* "neighbor route-server" commands.*/
12851 install_element(BGP_NODE, &neighbor_route_server_client_hidden_cmd);
12852 install_element(BGP_NODE, &no_neighbor_route_server_client_hidden_cmd);
12853 install_element(BGP_IPV4_NODE, &neighbor_route_server_client_cmd);
12854 install_element(BGP_IPV4_NODE, &no_neighbor_route_server_client_cmd);
12855 install_element(BGP_IPV4M_NODE, &neighbor_route_server_client_cmd);
12856 install_element(BGP_IPV4M_NODE, &no_neighbor_route_server_client_cmd);
12857 install_element(BGP_IPV4L_NODE, &neighbor_route_server_client_cmd);
12858 install_element(BGP_IPV4L_NODE, &no_neighbor_route_server_client_cmd);
12859 install_element(BGP_IPV6_NODE, &neighbor_route_server_client_cmd);
12860 install_element(BGP_IPV6_NODE, &no_neighbor_route_server_client_cmd);
12861 install_element(BGP_IPV6M_NODE, &neighbor_route_server_client_cmd);
12862 install_element(BGP_IPV6M_NODE, &no_neighbor_route_server_client_cmd);
12863 install_element(BGP_IPV6L_NODE, &neighbor_route_server_client_cmd);
12864 install_element(BGP_IPV6L_NODE, &no_neighbor_route_server_client_cmd);
12865 install_element(BGP_VPNV4_NODE, &neighbor_route_server_client_cmd);
12866 install_element(BGP_VPNV4_NODE, &no_neighbor_route_server_client_cmd);
12867 install_element(BGP_VPNV6_NODE, &neighbor_route_server_client_cmd);
12868 install_element(BGP_VPNV6_NODE, &no_neighbor_route_server_client_cmd);
12869 install_element(BGP_FLOWSPECV4_NODE, &neighbor_route_server_client_cmd);
12870 install_element(BGP_FLOWSPECV4_NODE,
12871 &no_neighbor_route_server_client_cmd);
12872 install_element(BGP_FLOWSPECV6_NODE, &neighbor_route_server_client_cmd);
12873 install_element(BGP_FLOWSPECV6_NODE,
12874 &no_neighbor_route_server_client_cmd);
12875
12876 /* "neighbor addpath-tx-all-paths" commands.*/
12877 install_element(BGP_NODE, &neighbor_addpath_tx_all_paths_hidden_cmd);
12878 install_element(BGP_NODE, &no_neighbor_addpath_tx_all_paths_hidden_cmd);
12879 install_element(BGP_IPV4_NODE, &neighbor_addpath_tx_all_paths_cmd);
12880 install_element(BGP_IPV4_NODE, &no_neighbor_addpath_tx_all_paths_cmd);
12881 install_element(BGP_IPV4M_NODE, &neighbor_addpath_tx_all_paths_cmd);
12882 install_element(BGP_IPV4M_NODE, &no_neighbor_addpath_tx_all_paths_cmd);
12883 install_element(BGP_IPV4L_NODE, &neighbor_addpath_tx_all_paths_cmd);
12884 install_element(BGP_IPV4L_NODE, &no_neighbor_addpath_tx_all_paths_cmd);
12885 install_element(BGP_IPV6_NODE, &neighbor_addpath_tx_all_paths_cmd);
12886 install_element(BGP_IPV6_NODE, &no_neighbor_addpath_tx_all_paths_cmd);
12887 install_element(BGP_IPV6M_NODE, &neighbor_addpath_tx_all_paths_cmd);
12888 install_element(BGP_IPV6M_NODE, &no_neighbor_addpath_tx_all_paths_cmd);
12889 install_element(BGP_IPV6L_NODE, &neighbor_addpath_tx_all_paths_cmd);
12890 install_element(BGP_IPV6L_NODE, &no_neighbor_addpath_tx_all_paths_cmd);
12891 install_element(BGP_VPNV4_NODE, &neighbor_addpath_tx_all_paths_cmd);
12892 install_element(BGP_VPNV4_NODE, &no_neighbor_addpath_tx_all_paths_cmd);
12893 install_element(BGP_VPNV6_NODE, &neighbor_addpath_tx_all_paths_cmd);
12894 install_element(BGP_VPNV6_NODE, &no_neighbor_addpath_tx_all_paths_cmd);
12895
12896 /* "neighbor addpath-tx-bestpath-per-AS" commands.*/
12897 install_element(BGP_NODE,
12898 &neighbor_addpath_tx_bestpath_per_as_hidden_cmd);
12899 install_element(BGP_NODE,
12900 &no_neighbor_addpath_tx_bestpath_per_as_hidden_cmd);
12901 install_element(BGP_IPV4_NODE,
12902 &neighbor_addpath_tx_bestpath_per_as_cmd);
12903 install_element(BGP_IPV4_NODE,
12904 &no_neighbor_addpath_tx_bestpath_per_as_cmd);
12905 install_element(BGP_IPV4M_NODE,
12906 &neighbor_addpath_tx_bestpath_per_as_cmd);
12907 install_element(BGP_IPV4M_NODE,
12908 &no_neighbor_addpath_tx_bestpath_per_as_cmd);
12909 install_element(BGP_IPV4L_NODE,
12910 &neighbor_addpath_tx_bestpath_per_as_cmd);
12911 install_element(BGP_IPV4L_NODE,
12912 &no_neighbor_addpath_tx_bestpath_per_as_cmd);
12913 install_element(BGP_IPV6_NODE,
12914 &neighbor_addpath_tx_bestpath_per_as_cmd);
12915 install_element(BGP_IPV6_NODE,
12916 &no_neighbor_addpath_tx_bestpath_per_as_cmd);
12917 install_element(BGP_IPV6M_NODE,
12918 &neighbor_addpath_tx_bestpath_per_as_cmd);
12919 install_element(BGP_IPV6M_NODE,
12920 &no_neighbor_addpath_tx_bestpath_per_as_cmd);
12921 install_element(BGP_IPV6L_NODE,
12922 &neighbor_addpath_tx_bestpath_per_as_cmd);
12923 install_element(BGP_IPV6L_NODE,
12924 &no_neighbor_addpath_tx_bestpath_per_as_cmd);
12925 install_element(BGP_VPNV4_NODE,
12926 &neighbor_addpath_tx_bestpath_per_as_cmd);
12927 install_element(BGP_VPNV4_NODE,
12928 &no_neighbor_addpath_tx_bestpath_per_as_cmd);
12929 install_element(BGP_VPNV6_NODE,
12930 &neighbor_addpath_tx_bestpath_per_as_cmd);
12931 install_element(BGP_VPNV6_NODE,
12932 &no_neighbor_addpath_tx_bestpath_per_as_cmd);
12933
12934 /* "neighbor passive" commands. */
12935 install_element(BGP_NODE, &neighbor_passive_cmd);
12936 install_element(BGP_NODE, &no_neighbor_passive_cmd);
12937
12938
12939 /* "neighbor shutdown" commands. */
12940 install_element(BGP_NODE, &neighbor_shutdown_cmd);
12941 install_element(BGP_NODE, &no_neighbor_shutdown_cmd);
12942 install_element(BGP_NODE, &neighbor_shutdown_msg_cmd);
12943 install_element(BGP_NODE, &no_neighbor_shutdown_msg_cmd);
12944
12945 /* "neighbor capability extended-nexthop" commands.*/
12946 install_element(BGP_NODE, &neighbor_capability_enhe_cmd);
12947 install_element(BGP_NODE, &no_neighbor_capability_enhe_cmd);
12948
12949 /* "neighbor capability orf prefix-list" commands.*/
12950 install_element(BGP_NODE, &neighbor_capability_orf_prefix_hidden_cmd);
12951 install_element(BGP_NODE,
12952 &no_neighbor_capability_orf_prefix_hidden_cmd);
12953 install_element(BGP_IPV4_NODE, &neighbor_capability_orf_prefix_cmd);
12954 install_element(BGP_IPV4_NODE, &no_neighbor_capability_orf_prefix_cmd);
12955 install_element(BGP_IPV4M_NODE, &neighbor_capability_orf_prefix_cmd);
12956 install_element(BGP_IPV4M_NODE, &no_neighbor_capability_orf_prefix_cmd);
12957 install_element(BGP_IPV4L_NODE, &neighbor_capability_orf_prefix_cmd);
12958 install_element(BGP_IPV4L_NODE, &no_neighbor_capability_orf_prefix_cmd);
12959 install_element(BGP_IPV6_NODE, &neighbor_capability_orf_prefix_cmd);
12960 install_element(BGP_IPV6_NODE, &no_neighbor_capability_orf_prefix_cmd);
12961 install_element(BGP_IPV6M_NODE, &neighbor_capability_orf_prefix_cmd);
12962 install_element(BGP_IPV6M_NODE, &no_neighbor_capability_orf_prefix_cmd);
12963 install_element(BGP_IPV6L_NODE, &neighbor_capability_orf_prefix_cmd);
12964 install_element(BGP_IPV6L_NODE, &no_neighbor_capability_orf_prefix_cmd);
12965
12966 /* "neighbor capability dynamic" commands.*/
12967 install_element(BGP_NODE, &neighbor_capability_dynamic_cmd);
12968 install_element(BGP_NODE, &no_neighbor_capability_dynamic_cmd);
12969
12970 /* "neighbor dont-capability-negotiate" commands. */
12971 install_element(BGP_NODE, &neighbor_dont_capability_negotiate_cmd);
12972 install_element(BGP_NODE, &no_neighbor_dont_capability_negotiate_cmd);
12973
12974 /* "neighbor ebgp-multihop" commands. */
12975 install_element(BGP_NODE, &neighbor_ebgp_multihop_cmd);
12976 install_element(BGP_NODE, &neighbor_ebgp_multihop_ttl_cmd);
12977 install_element(BGP_NODE, &no_neighbor_ebgp_multihop_cmd);
12978
12979 /* "neighbor disable-connected-check" commands. */
12980 install_element(BGP_NODE, &neighbor_disable_connected_check_cmd);
12981 install_element(BGP_NODE, &no_neighbor_disable_connected_check_cmd);
12982
12983 /* "neighbor description" commands. */
12984 install_element(BGP_NODE, &neighbor_description_cmd);
12985 install_element(BGP_NODE, &no_neighbor_description_cmd);
12986
12987 /* "neighbor update-source" commands. "*/
12988 install_element(BGP_NODE, &neighbor_update_source_cmd);
12989 install_element(BGP_NODE, &no_neighbor_update_source_cmd);
12990
12991 /* "neighbor default-originate" commands. */
12992 install_element(BGP_NODE, &neighbor_default_originate_hidden_cmd);
12993 install_element(BGP_NODE, &neighbor_default_originate_rmap_hidden_cmd);
12994 install_element(BGP_NODE, &no_neighbor_default_originate_hidden_cmd);
12995 install_element(BGP_IPV4_NODE, &neighbor_default_originate_cmd);
12996 install_element(BGP_IPV4_NODE, &neighbor_default_originate_rmap_cmd);
12997 install_element(BGP_IPV4_NODE, &no_neighbor_default_originate_cmd);
12998 install_element(BGP_IPV4M_NODE, &neighbor_default_originate_cmd);
12999 install_element(BGP_IPV4M_NODE, &neighbor_default_originate_rmap_cmd);
13000 install_element(BGP_IPV4M_NODE, &no_neighbor_default_originate_cmd);
13001 install_element(BGP_IPV4L_NODE, &neighbor_default_originate_cmd);
13002 install_element(BGP_IPV4L_NODE, &neighbor_default_originate_rmap_cmd);
13003 install_element(BGP_IPV4L_NODE, &no_neighbor_default_originate_cmd);
13004 install_element(BGP_IPV6_NODE, &neighbor_default_originate_cmd);
13005 install_element(BGP_IPV6_NODE, &neighbor_default_originate_rmap_cmd);
13006 install_element(BGP_IPV6_NODE, &no_neighbor_default_originate_cmd);
13007 install_element(BGP_IPV6M_NODE, &neighbor_default_originate_cmd);
13008 install_element(BGP_IPV6M_NODE, &neighbor_default_originate_rmap_cmd);
13009 install_element(BGP_IPV6M_NODE, &no_neighbor_default_originate_cmd);
13010 install_element(BGP_IPV6L_NODE, &neighbor_default_originate_cmd);
13011 install_element(BGP_IPV6L_NODE, &neighbor_default_originate_rmap_cmd);
13012 install_element(BGP_IPV6L_NODE, &no_neighbor_default_originate_cmd);
13013
13014 /* "neighbor port" commands. */
13015 install_element(BGP_NODE, &neighbor_port_cmd);
13016 install_element(BGP_NODE, &no_neighbor_port_cmd);
13017
13018 /* "neighbor weight" commands. */
13019 install_element(BGP_NODE, &neighbor_weight_hidden_cmd);
13020 install_element(BGP_NODE, &no_neighbor_weight_hidden_cmd);
13021
13022 install_element(BGP_IPV4_NODE, &neighbor_weight_cmd);
13023 install_element(BGP_IPV4_NODE, &no_neighbor_weight_cmd);
13024 install_element(BGP_IPV4M_NODE, &neighbor_weight_cmd);
13025 install_element(BGP_IPV4M_NODE, &no_neighbor_weight_cmd);
13026 install_element(BGP_IPV4L_NODE, &neighbor_weight_cmd);
13027 install_element(BGP_IPV4L_NODE, &no_neighbor_weight_cmd);
13028 install_element(BGP_IPV6_NODE, &neighbor_weight_cmd);
13029 install_element(BGP_IPV6_NODE, &no_neighbor_weight_cmd);
13030 install_element(BGP_IPV6M_NODE, &neighbor_weight_cmd);
13031 install_element(BGP_IPV6M_NODE, &no_neighbor_weight_cmd);
13032 install_element(BGP_IPV6L_NODE, &neighbor_weight_cmd);
13033 install_element(BGP_IPV6L_NODE, &no_neighbor_weight_cmd);
13034 install_element(BGP_VPNV4_NODE, &neighbor_weight_cmd);
13035 install_element(BGP_VPNV4_NODE, &no_neighbor_weight_cmd);
13036 install_element(BGP_VPNV6_NODE, &neighbor_weight_cmd);
13037 install_element(BGP_VPNV6_NODE, &no_neighbor_weight_cmd);
13038
13039 /* "neighbor override-capability" commands. */
13040 install_element(BGP_NODE, &neighbor_override_capability_cmd);
13041 install_element(BGP_NODE, &no_neighbor_override_capability_cmd);
13042
13043 /* "neighbor strict-capability-match" commands. */
13044 install_element(BGP_NODE, &neighbor_strict_capability_cmd);
13045 install_element(BGP_NODE, &no_neighbor_strict_capability_cmd);
13046
13047 /* "neighbor timers" commands. */
13048 install_element(BGP_NODE, &neighbor_timers_cmd);
13049 install_element(BGP_NODE, &no_neighbor_timers_cmd);
13050
13051 /* "neighbor timers connect" commands. */
13052 install_element(BGP_NODE, &neighbor_timers_connect_cmd);
13053 install_element(BGP_NODE, &no_neighbor_timers_connect_cmd);
13054
13055 /* "neighbor advertisement-interval" commands. */
13056 install_element(BGP_NODE, &neighbor_advertise_interval_cmd);
13057 install_element(BGP_NODE, &no_neighbor_advertise_interval_cmd);
13058
13059 /* "neighbor interface" commands. */
13060 install_element(BGP_NODE, &neighbor_interface_cmd);
13061 install_element(BGP_NODE, &no_neighbor_interface_cmd);
13062
13063 /* "neighbor distribute" commands. */
13064 install_element(BGP_NODE, &neighbor_distribute_list_hidden_cmd);
13065 install_element(BGP_NODE, &no_neighbor_distribute_list_hidden_cmd);
13066 install_element(BGP_IPV4_NODE, &neighbor_distribute_list_cmd);
13067 install_element(BGP_IPV4_NODE, &no_neighbor_distribute_list_cmd);
13068 install_element(BGP_IPV4M_NODE, &neighbor_distribute_list_cmd);
13069 install_element(BGP_IPV4M_NODE, &no_neighbor_distribute_list_cmd);
13070 install_element(BGP_IPV4L_NODE, &neighbor_distribute_list_cmd);
13071 install_element(BGP_IPV4L_NODE, &no_neighbor_distribute_list_cmd);
13072 install_element(BGP_IPV6_NODE, &neighbor_distribute_list_cmd);
13073 install_element(BGP_IPV6_NODE, &no_neighbor_distribute_list_cmd);
13074 install_element(BGP_IPV6M_NODE, &neighbor_distribute_list_cmd);
13075 install_element(BGP_IPV6M_NODE, &no_neighbor_distribute_list_cmd);
13076 install_element(BGP_IPV6L_NODE, &neighbor_distribute_list_cmd);
13077 install_element(BGP_IPV6L_NODE, &no_neighbor_distribute_list_cmd);
13078 install_element(BGP_VPNV4_NODE, &neighbor_distribute_list_cmd);
13079 install_element(BGP_VPNV4_NODE, &no_neighbor_distribute_list_cmd);
13080 install_element(BGP_VPNV6_NODE, &neighbor_distribute_list_cmd);
13081 install_element(BGP_VPNV6_NODE, &no_neighbor_distribute_list_cmd);
13082
13083 /* "neighbor prefix-list" commands. */
13084 install_element(BGP_NODE, &neighbor_prefix_list_hidden_cmd);
13085 install_element(BGP_NODE, &no_neighbor_prefix_list_hidden_cmd);
13086 install_element(BGP_IPV4_NODE, &neighbor_prefix_list_cmd);
13087 install_element(BGP_IPV4_NODE, &no_neighbor_prefix_list_cmd);
13088 install_element(BGP_IPV4M_NODE, &neighbor_prefix_list_cmd);
13089 install_element(BGP_IPV4M_NODE, &no_neighbor_prefix_list_cmd);
13090 install_element(BGP_IPV4L_NODE, &neighbor_prefix_list_cmd);
13091 install_element(BGP_IPV4L_NODE, &no_neighbor_prefix_list_cmd);
13092 install_element(BGP_IPV6_NODE, &neighbor_prefix_list_cmd);
13093 install_element(BGP_IPV6_NODE, &no_neighbor_prefix_list_cmd);
13094 install_element(BGP_IPV6M_NODE, &neighbor_prefix_list_cmd);
13095 install_element(BGP_IPV6M_NODE, &no_neighbor_prefix_list_cmd);
13096 install_element(BGP_IPV6L_NODE, &neighbor_prefix_list_cmd);
13097 install_element(BGP_IPV6L_NODE, &no_neighbor_prefix_list_cmd);
13098 install_element(BGP_VPNV4_NODE, &neighbor_prefix_list_cmd);
13099 install_element(BGP_VPNV4_NODE, &no_neighbor_prefix_list_cmd);
13100 install_element(BGP_VPNV6_NODE, &neighbor_prefix_list_cmd);
13101 install_element(BGP_VPNV6_NODE, &no_neighbor_prefix_list_cmd);
13102 install_element(BGP_FLOWSPECV4_NODE, &neighbor_prefix_list_cmd);
13103 install_element(BGP_FLOWSPECV4_NODE, &no_neighbor_prefix_list_cmd);
13104 install_element(BGP_FLOWSPECV6_NODE, &neighbor_prefix_list_cmd);
13105 install_element(BGP_FLOWSPECV6_NODE, &no_neighbor_prefix_list_cmd);
13106
13107 /* "neighbor filter-list" commands. */
13108 install_element(BGP_NODE, &neighbor_filter_list_hidden_cmd);
13109 install_element(BGP_NODE, &no_neighbor_filter_list_hidden_cmd);
13110 install_element(BGP_IPV4_NODE, &neighbor_filter_list_cmd);
13111 install_element(BGP_IPV4_NODE, &no_neighbor_filter_list_cmd);
13112 install_element(BGP_IPV4M_NODE, &neighbor_filter_list_cmd);
13113 install_element(BGP_IPV4M_NODE, &no_neighbor_filter_list_cmd);
13114 install_element(BGP_IPV4L_NODE, &neighbor_filter_list_cmd);
13115 install_element(BGP_IPV4L_NODE, &no_neighbor_filter_list_cmd);
13116 install_element(BGP_IPV6_NODE, &neighbor_filter_list_cmd);
13117 install_element(BGP_IPV6_NODE, &no_neighbor_filter_list_cmd);
13118 install_element(BGP_IPV6M_NODE, &neighbor_filter_list_cmd);
13119 install_element(BGP_IPV6M_NODE, &no_neighbor_filter_list_cmd);
13120 install_element(BGP_IPV6L_NODE, &neighbor_filter_list_cmd);
13121 install_element(BGP_IPV6L_NODE, &no_neighbor_filter_list_cmd);
13122 install_element(BGP_VPNV4_NODE, &neighbor_filter_list_cmd);
13123 install_element(BGP_VPNV4_NODE, &no_neighbor_filter_list_cmd);
13124 install_element(BGP_VPNV6_NODE, &neighbor_filter_list_cmd);
13125 install_element(BGP_VPNV6_NODE, &no_neighbor_filter_list_cmd);
13126 install_element(BGP_FLOWSPECV4_NODE, &neighbor_filter_list_cmd);
13127 install_element(BGP_FLOWSPECV4_NODE, &no_neighbor_filter_list_cmd);
13128 install_element(BGP_FLOWSPECV6_NODE, &neighbor_filter_list_cmd);
13129 install_element(BGP_FLOWSPECV6_NODE, &no_neighbor_filter_list_cmd);
13130
13131 /* "neighbor route-map" commands. */
13132 install_element(BGP_NODE, &neighbor_route_map_hidden_cmd);
13133 install_element(BGP_NODE, &no_neighbor_route_map_hidden_cmd);
13134 install_element(BGP_IPV4_NODE, &neighbor_route_map_cmd);
13135 install_element(BGP_IPV4_NODE, &no_neighbor_route_map_cmd);
13136 install_element(BGP_IPV4M_NODE, &neighbor_route_map_cmd);
13137 install_element(BGP_IPV4M_NODE, &no_neighbor_route_map_cmd);
13138 install_element(BGP_IPV4L_NODE, &neighbor_route_map_cmd);
13139 install_element(BGP_IPV4L_NODE, &no_neighbor_route_map_cmd);
13140 install_element(BGP_IPV6_NODE, &neighbor_route_map_cmd);
13141 install_element(BGP_IPV6_NODE, &no_neighbor_route_map_cmd);
13142 install_element(BGP_IPV6M_NODE, &neighbor_route_map_cmd);
13143 install_element(BGP_IPV6M_NODE, &no_neighbor_route_map_cmd);
13144 install_element(BGP_IPV6L_NODE, &neighbor_route_map_cmd);
13145 install_element(BGP_IPV6L_NODE, &no_neighbor_route_map_cmd);
13146 install_element(BGP_VPNV4_NODE, &neighbor_route_map_cmd);
13147 install_element(BGP_VPNV4_NODE, &no_neighbor_route_map_cmd);
13148 install_element(BGP_VPNV6_NODE, &neighbor_route_map_cmd);
13149 install_element(BGP_VPNV6_NODE, &no_neighbor_route_map_cmd);
13150 install_element(BGP_FLOWSPECV4_NODE, &neighbor_route_map_cmd);
13151 install_element(BGP_FLOWSPECV4_NODE, &no_neighbor_route_map_cmd);
13152 install_element(BGP_FLOWSPECV6_NODE, &neighbor_route_map_cmd);
13153 install_element(BGP_FLOWSPECV6_NODE, &no_neighbor_route_map_cmd);
13154 install_element(BGP_EVPN_NODE, &neighbor_route_map_cmd);
13155 install_element(BGP_EVPN_NODE, &no_neighbor_route_map_cmd);
13156
13157 /* "neighbor unsuppress-map" commands. */
13158 install_element(BGP_NODE, &neighbor_unsuppress_map_hidden_cmd);
13159 install_element(BGP_NODE, &no_neighbor_unsuppress_map_hidden_cmd);
13160 install_element(BGP_IPV4_NODE, &neighbor_unsuppress_map_cmd);
13161 install_element(BGP_IPV4_NODE, &no_neighbor_unsuppress_map_cmd);
13162 install_element(BGP_IPV4M_NODE, &neighbor_unsuppress_map_cmd);
13163 install_element(BGP_IPV4M_NODE, &no_neighbor_unsuppress_map_cmd);
13164 install_element(BGP_IPV4L_NODE, &neighbor_unsuppress_map_cmd);
13165 install_element(BGP_IPV4L_NODE, &no_neighbor_unsuppress_map_cmd);
13166 install_element(BGP_IPV6_NODE, &neighbor_unsuppress_map_cmd);
13167 install_element(BGP_IPV6_NODE, &no_neighbor_unsuppress_map_cmd);
13168 install_element(BGP_IPV6M_NODE, &neighbor_unsuppress_map_cmd);
13169 install_element(BGP_IPV6M_NODE, &no_neighbor_unsuppress_map_cmd);
13170 install_element(BGP_IPV6L_NODE, &neighbor_unsuppress_map_cmd);
13171 install_element(BGP_IPV6L_NODE, &no_neighbor_unsuppress_map_cmd);
13172 install_element(BGP_VPNV4_NODE, &neighbor_unsuppress_map_cmd);
13173 install_element(BGP_VPNV4_NODE, &no_neighbor_unsuppress_map_cmd);
13174 install_element(BGP_VPNV6_NODE, &neighbor_unsuppress_map_cmd);
13175 install_element(BGP_VPNV6_NODE, &no_neighbor_unsuppress_map_cmd);
13176
13177 /* "neighbor maximum-prefix" commands. */
13178 install_element(BGP_NODE, &neighbor_maximum_prefix_hidden_cmd);
13179 install_element(BGP_NODE,
13180 &neighbor_maximum_prefix_threshold_hidden_cmd);
13181 install_element(BGP_NODE, &neighbor_maximum_prefix_warning_hidden_cmd);
13182 install_element(BGP_NODE,
13183 &neighbor_maximum_prefix_threshold_warning_hidden_cmd);
13184 install_element(BGP_NODE, &neighbor_maximum_prefix_restart_hidden_cmd);
13185 install_element(BGP_NODE,
13186 &neighbor_maximum_prefix_threshold_restart_hidden_cmd);
13187 install_element(BGP_NODE, &no_neighbor_maximum_prefix_hidden_cmd);
13188 install_element(BGP_IPV4_NODE, &neighbor_maximum_prefix_cmd);
13189 install_element(BGP_IPV4_NODE, &neighbor_maximum_prefix_threshold_cmd);
13190 install_element(BGP_IPV4_NODE, &neighbor_maximum_prefix_warning_cmd);
13191 install_element(BGP_IPV4_NODE,
13192 &neighbor_maximum_prefix_threshold_warning_cmd);
13193 install_element(BGP_IPV4_NODE, &neighbor_maximum_prefix_restart_cmd);
13194 install_element(BGP_IPV4_NODE,
13195 &neighbor_maximum_prefix_threshold_restart_cmd);
13196 install_element(BGP_IPV4_NODE, &no_neighbor_maximum_prefix_cmd);
13197 install_element(BGP_IPV4M_NODE, &neighbor_maximum_prefix_cmd);
13198 install_element(BGP_IPV4M_NODE, &neighbor_maximum_prefix_threshold_cmd);
13199 install_element(BGP_IPV4M_NODE, &neighbor_maximum_prefix_warning_cmd);
13200 install_element(BGP_IPV4M_NODE,
13201 &neighbor_maximum_prefix_threshold_warning_cmd);
13202 install_element(BGP_IPV4M_NODE, &neighbor_maximum_prefix_restart_cmd);
13203 install_element(BGP_IPV4M_NODE,
13204 &neighbor_maximum_prefix_threshold_restart_cmd);
13205 install_element(BGP_IPV4M_NODE, &no_neighbor_maximum_prefix_cmd);
13206 install_element(BGP_IPV4L_NODE, &neighbor_maximum_prefix_cmd);
13207 install_element(BGP_IPV4L_NODE, &neighbor_maximum_prefix_threshold_cmd);
13208 install_element(BGP_IPV4L_NODE, &neighbor_maximum_prefix_warning_cmd);
13209 install_element(BGP_IPV4L_NODE,
13210 &neighbor_maximum_prefix_threshold_warning_cmd);
13211 install_element(BGP_IPV4L_NODE, &neighbor_maximum_prefix_restart_cmd);
13212 install_element(BGP_IPV4L_NODE,
13213 &neighbor_maximum_prefix_threshold_restart_cmd);
13214 install_element(BGP_IPV4L_NODE, &no_neighbor_maximum_prefix_cmd);
13215 install_element(BGP_IPV6_NODE, &neighbor_maximum_prefix_cmd);
13216 install_element(BGP_IPV6_NODE, &neighbor_maximum_prefix_threshold_cmd);
13217 install_element(BGP_IPV6_NODE, &neighbor_maximum_prefix_warning_cmd);
13218 install_element(BGP_IPV6_NODE,
13219 &neighbor_maximum_prefix_threshold_warning_cmd);
13220 install_element(BGP_IPV6_NODE, &neighbor_maximum_prefix_restart_cmd);
13221 install_element(BGP_IPV6_NODE,
13222 &neighbor_maximum_prefix_threshold_restart_cmd);
13223 install_element(BGP_IPV6_NODE, &no_neighbor_maximum_prefix_cmd);
13224 install_element(BGP_IPV6M_NODE, &neighbor_maximum_prefix_cmd);
13225 install_element(BGP_IPV6M_NODE, &neighbor_maximum_prefix_threshold_cmd);
13226 install_element(BGP_IPV6M_NODE, &neighbor_maximum_prefix_warning_cmd);
13227 install_element(BGP_IPV6M_NODE,
13228 &neighbor_maximum_prefix_threshold_warning_cmd);
13229 install_element(BGP_IPV6M_NODE, &neighbor_maximum_prefix_restart_cmd);
13230 install_element(BGP_IPV6M_NODE,
13231 &neighbor_maximum_prefix_threshold_restart_cmd);
13232 install_element(BGP_IPV6M_NODE, &no_neighbor_maximum_prefix_cmd);
13233 install_element(BGP_IPV6L_NODE, &neighbor_maximum_prefix_cmd);
13234 install_element(BGP_IPV6L_NODE, &neighbor_maximum_prefix_threshold_cmd);
13235 install_element(BGP_IPV6L_NODE, &neighbor_maximum_prefix_warning_cmd);
13236 install_element(BGP_IPV6L_NODE,
13237 &neighbor_maximum_prefix_threshold_warning_cmd);
13238 install_element(BGP_IPV6L_NODE, &neighbor_maximum_prefix_restart_cmd);
13239 install_element(BGP_IPV6L_NODE,
13240 &neighbor_maximum_prefix_threshold_restart_cmd);
13241 install_element(BGP_IPV6L_NODE, &no_neighbor_maximum_prefix_cmd);
13242 install_element(BGP_VPNV4_NODE, &neighbor_maximum_prefix_cmd);
13243 install_element(BGP_VPNV4_NODE, &neighbor_maximum_prefix_threshold_cmd);
13244 install_element(BGP_VPNV4_NODE, &neighbor_maximum_prefix_warning_cmd);
13245 install_element(BGP_VPNV4_NODE,
13246 &neighbor_maximum_prefix_threshold_warning_cmd);
13247 install_element(BGP_VPNV4_NODE, &neighbor_maximum_prefix_restart_cmd);
13248 install_element(BGP_VPNV4_NODE,
13249 &neighbor_maximum_prefix_threshold_restart_cmd);
13250 install_element(BGP_VPNV4_NODE, &no_neighbor_maximum_prefix_cmd);
13251 install_element(BGP_VPNV6_NODE, &neighbor_maximum_prefix_cmd);
13252 install_element(BGP_VPNV6_NODE, &neighbor_maximum_prefix_threshold_cmd);
13253 install_element(BGP_VPNV6_NODE, &neighbor_maximum_prefix_warning_cmd);
13254 install_element(BGP_VPNV6_NODE,
13255 &neighbor_maximum_prefix_threshold_warning_cmd);
13256 install_element(BGP_VPNV6_NODE, &neighbor_maximum_prefix_restart_cmd);
13257 install_element(BGP_VPNV6_NODE,
13258 &neighbor_maximum_prefix_threshold_restart_cmd);
13259 install_element(BGP_VPNV6_NODE, &no_neighbor_maximum_prefix_cmd);
13260
13261 /* "neighbor allowas-in" */
13262 install_element(BGP_NODE, &neighbor_allowas_in_hidden_cmd);
13263 install_element(BGP_NODE, &no_neighbor_allowas_in_hidden_cmd);
13264 install_element(BGP_IPV4_NODE, &neighbor_allowas_in_cmd);
13265 install_element(BGP_IPV4_NODE, &no_neighbor_allowas_in_cmd);
13266 install_element(BGP_IPV4M_NODE, &neighbor_allowas_in_cmd);
13267 install_element(BGP_IPV4M_NODE, &no_neighbor_allowas_in_cmd);
13268 install_element(BGP_IPV4L_NODE, &neighbor_allowas_in_cmd);
13269 install_element(BGP_IPV4L_NODE, &no_neighbor_allowas_in_cmd);
13270 install_element(BGP_IPV6_NODE, &neighbor_allowas_in_cmd);
13271 install_element(BGP_IPV6_NODE, &no_neighbor_allowas_in_cmd);
13272 install_element(BGP_IPV6M_NODE, &neighbor_allowas_in_cmd);
13273 install_element(BGP_IPV6M_NODE, &no_neighbor_allowas_in_cmd);
13274 install_element(BGP_IPV6L_NODE, &neighbor_allowas_in_cmd);
13275 install_element(BGP_IPV6L_NODE, &no_neighbor_allowas_in_cmd);
13276 install_element(BGP_VPNV4_NODE, &neighbor_allowas_in_cmd);
13277 install_element(BGP_VPNV4_NODE, &no_neighbor_allowas_in_cmd);
13278 install_element(BGP_VPNV6_NODE, &neighbor_allowas_in_cmd);
13279 install_element(BGP_VPNV6_NODE, &no_neighbor_allowas_in_cmd);
13280 install_element(BGP_EVPN_NODE, &neighbor_allowas_in_cmd);
13281 install_element(BGP_EVPN_NODE, &no_neighbor_allowas_in_cmd);
13282
13283 /* address-family commands. */
13284 install_element(BGP_NODE, &address_family_ipv4_safi_cmd);
13285 install_element(BGP_NODE, &address_family_ipv6_safi_cmd);
13286 #ifdef KEEP_OLD_VPN_COMMANDS
13287 install_element(BGP_NODE, &address_family_vpnv4_cmd);
13288 install_element(BGP_NODE, &address_family_vpnv6_cmd);
13289 #endif /* KEEP_OLD_VPN_COMMANDS */
13290
13291 install_element(BGP_NODE, &address_family_evpn_cmd);
13292
13293 /* "exit-address-family" command. */
13294 install_element(BGP_IPV4_NODE, &exit_address_family_cmd);
13295 install_element(BGP_IPV4M_NODE, &exit_address_family_cmd);
13296 install_element(BGP_IPV4L_NODE, &exit_address_family_cmd);
13297 install_element(BGP_IPV6_NODE, &exit_address_family_cmd);
13298 install_element(BGP_IPV6M_NODE, &exit_address_family_cmd);
13299 install_element(BGP_IPV6L_NODE, &exit_address_family_cmd);
13300 install_element(BGP_VPNV4_NODE, &exit_address_family_cmd);
13301 install_element(BGP_VPNV6_NODE, &exit_address_family_cmd);
13302 install_element(BGP_FLOWSPECV4_NODE, &exit_address_family_cmd);
13303 install_element(BGP_FLOWSPECV6_NODE, &exit_address_family_cmd);
13304 install_element(BGP_EVPN_NODE, &exit_address_family_cmd);
13305
13306 /* "clear ip bgp commands" */
13307 install_element(ENABLE_NODE, &clear_ip_bgp_all_cmd);
13308
13309 /* clear ip bgp prefix */
13310 install_element(ENABLE_NODE, &clear_ip_bgp_prefix_cmd);
13311 install_element(ENABLE_NODE, &clear_bgp_ipv6_safi_prefix_cmd);
13312 install_element(ENABLE_NODE, &clear_bgp_instance_ipv6_safi_prefix_cmd);
13313
13314 /* "show [ip] bgp summary" commands. */
13315 install_element(VIEW_NODE, &show_bgp_instance_all_ipv6_updgrps_cmd);
13316 install_element(VIEW_NODE, &show_bgp_instance_updgrps_stats_cmd);
13317 install_element(VIEW_NODE, &show_bgp_updgrps_stats_cmd);
13318 install_element(VIEW_NODE, &show_ip_bgp_instance_updgrps_adj_s_cmd);
13319 install_element(VIEW_NODE, &show_ip_bgp_summary_cmd);
13320 install_element(VIEW_NODE, &show_ip_bgp_updgrps_cmd);
13321
13322 /* "show [ip] bgp neighbors" commands. */
13323 install_element(VIEW_NODE, &show_ip_bgp_neighbors_cmd);
13324
13325 /* "show [ip] bgp peer-group" commands. */
13326 install_element(VIEW_NODE, &show_ip_bgp_peer_groups_cmd);
13327
13328 /* "show [ip] bgp paths" commands. */
13329 install_element(VIEW_NODE, &show_ip_bgp_paths_cmd);
13330
13331 /* "show [ip] bgp community" commands. */
13332 install_element(VIEW_NODE, &show_ip_bgp_community_info_cmd);
13333
13334 /* "show ip bgp large-community" commands. */
13335 install_element(VIEW_NODE, &show_ip_bgp_lcommunity_info_cmd);
13336 /* "show [ip] bgp attribute-info" commands. */
13337 install_element(VIEW_NODE, &show_ip_bgp_attr_info_cmd);
13338 /* "show [ip] bgp route-leak" command */
13339 install_element(VIEW_NODE, &show_ip_bgp_route_leak_cmd);
13340
13341 /* "redistribute" commands. */
13342 install_element(BGP_NODE, &bgp_redistribute_ipv4_hidden_cmd);
13343 install_element(BGP_NODE, &no_bgp_redistribute_ipv4_hidden_cmd);
13344 install_element(BGP_NODE, &bgp_redistribute_ipv4_rmap_hidden_cmd);
13345 install_element(BGP_NODE, &bgp_redistribute_ipv4_metric_hidden_cmd);
13346 install_element(BGP_NODE,
13347 &bgp_redistribute_ipv4_rmap_metric_hidden_cmd);
13348 install_element(BGP_NODE,
13349 &bgp_redistribute_ipv4_metric_rmap_hidden_cmd);
13350 install_element(BGP_NODE, &bgp_redistribute_ipv4_ospf_hidden_cmd);
13351 install_element(BGP_NODE, &no_bgp_redistribute_ipv4_ospf_hidden_cmd);
13352 install_element(BGP_NODE, &bgp_redistribute_ipv4_ospf_rmap_hidden_cmd);
13353 install_element(BGP_NODE,
13354 &bgp_redistribute_ipv4_ospf_metric_hidden_cmd);
13355 install_element(BGP_NODE,
13356 &bgp_redistribute_ipv4_ospf_rmap_metric_hidden_cmd);
13357 install_element(BGP_NODE,
13358 &bgp_redistribute_ipv4_ospf_metric_rmap_hidden_cmd);
13359 install_element(BGP_IPV4_NODE, &bgp_redistribute_ipv4_cmd);
13360 install_element(BGP_IPV4_NODE, &no_bgp_redistribute_ipv4_cmd);
13361 install_element(BGP_IPV4_NODE, &bgp_redistribute_ipv4_rmap_cmd);
13362 install_element(BGP_IPV4_NODE, &bgp_redistribute_ipv4_metric_cmd);
13363 install_element(BGP_IPV4_NODE, &bgp_redistribute_ipv4_rmap_metric_cmd);
13364 install_element(BGP_IPV4_NODE, &bgp_redistribute_ipv4_metric_rmap_cmd);
13365 install_element(BGP_IPV4_NODE, &bgp_redistribute_ipv4_ospf_cmd);
13366 install_element(BGP_IPV4_NODE, &no_bgp_redistribute_ipv4_ospf_cmd);
13367 install_element(BGP_IPV4_NODE, &bgp_redistribute_ipv4_ospf_rmap_cmd);
13368 install_element(BGP_IPV4_NODE, &bgp_redistribute_ipv4_ospf_metric_cmd);
13369 install_element(BGP_IPV4_NODE,
13370 &bgp_redistribute_ipv4_ospf_rmap_metric_cmd);
13371 install_element(BGP_IPV4_NODE,
13372 &bgp_redistribute_ipv4_ospf_metric_rmap_cmd);
13373 install_element(BGP_IPV6_NODE, &bgp_redistribute_ipv6_cmd);
13374 install_element(BGP_IPV6_NODE, &no_bgp_redistribute_ipv6_cmd);
13375 install_element(BGP_IPV6_NODE, &bgp_redistribute_ipv6_rmap_cmd);
13376 install_element(BGP_IPV6_NODE, &bgp_redistribute_ipv6_metric_cmd);
13377 install_element(BGP_IPV6_NODE, &bgp_redistribute_ipv6_rmap_metric_cmd);
13378 install_element(BGP_IPV6_NODE, &bgp_redistribute_ipv6_metric_rmap_cmd);
13379
13380 /* import|export vpn [route-map WORD] */
13381 install_element(BGP_IPV4_NODE, &bgp_imexport_vpn_cmd);
13382 install_element(BGP_IPV6_NODE, &bgp_imexport_vpn_cmd);
13383
13384 install_element(BGP_IPV4_NODE, &bgp_imexport_vrf_cmd);
13385 install_element(BGP_IPV6_NODE, &bgp_imexport_vrf_cmd);
13386
13387 /* ttl_security commands */
13388 install_element(BGP_NODE, &neighbor_ttl_security_cmd);
13389 install_element(BGP_NODE, &no_neighbor_ttl_security_cmd);
13390
13391 /* "show [ip] bgp memory" commands. */
13392 install_element(VIEW_NODE, &show_bgp_memory_cmd);
13393
13394 /* "show bgp martian next-hop" */
13395 install_element(VIEW_NODE, &show_bgp_martian_nexthop_db_cmd);
13396
13397 /* "show [ip] bgp views" commands. */
13398 install_element(VIEW_NODE, &show_bgp_views_cmd);
13399
13400 /* "show [ip] bgp vrfs" commands. */
13401 install_element(VIEW_NODE, &show_bgp_vrfs_cmd);
13402
13403 /* Community-list. */
13404 community_list_vty();
13405
13406 /* vpn-policy commands */
13407 install_element(BGP_IPV4_NODE, &af_rd_vpn_export_cmd);
13408 install_element(BGP_IPV6_NODE, &af_rd_vpn_export_cmd);
13409 install_element(BGP_IPV4_NODE, &af_label_vpn_export_cmd);
13410 install_element(BGP_IPV6_NODE, &af_label_vpn_export_cmd);
13411 install_element(BGP_IPV4_NODE, &af_nexthop_vpn_export_cmd);
13412 install_element(BGP_IPV6_NODE, &af_nexthop_vpn_export_cmd);
13413 install_element(BGP_IPV4_NODE, &af_rt_vpn_imexport_cmd);
13414 install_element(BGP_IPV6_NODE, &af_rt_vpn_imexport_cmd);
13415 install_element(BGP_IPV4_NODE, &af_route_map_vpn_imexport_cmd);
13416 install_element(BGP_IPV6_NODE, &af_route_map_vpn_imexport_cmd);
13417 install_element(BGP_IPV4_NODE, &af_import_vrf_route_map_cmd);
13418 install_element(BGP_IPV6_NODE, &af_import_vrf_route_map_cmd);
13419
13420 install_element(BGP_IPV4_NODE, &af_routetarget_import_cmd);
13421 install_element(BGP_IPV6_NODE, &af_routetarget_import_cmd);
13422
13423 install_element(BGP_IPV4_NODE, &af_no_rd_vpn_export_cmd);
13424 install_element(BGP_IPV6_NODE, &af_no_rd_vpn_export_cmd);
13425 install_element(BGP_IPV4_NODE, &af_no_label_vpn_export_cmd);
13426 install_element(BGP_IPV6_NODE, &af_no_label_vpn_export_cmd);
13427 install_element(BGP_IPV4_NODE, &af_no_nexthop_vpn_export_cmd);
13428 install_element(BGP_IPV6_NODE, &af_no_nexthop_vpn_export_cmd);
13429 install_element(BGP_IPV4_NODE, &af_no_rt_vpn_imexport_cmd);
13430 install_element(BGP_IPV6_NODE, &af_no_rt_vpn_imexport_cmd);
13431 install_element(BGP_IPV4_NODE, &af_no_route_map_vpn_imexport_cmd);
13432 install_element(BGP_IPV6_NODE, &af_no_route_map_vpn_imexport_cmd);
13433 install_element(BGP_IPV4_NODE, &af_no_import_vrf_route_map_cmd);
13434 install_element(BGP_IPV6_NODE, &af_no_import_vrf_route_map_cmd);
13435 }
13436
13437 #include "memory.h"
13438 #include "bgp_regex.h"
13439 #include "bgp_clist.h"
13440 #include "bgp_ecommunity.h"
13441
13442 /* VTY functions. */
13443
13444 /* Direction value to string conversion. */
13445 static const char *community_direct_str(int direct)
13446 {
13447 switch (direct) {
13448 case COMMUNITY_DENY:
13449 return "deny";
13450 case COMMUNITY_PERMIT:
13451 return "permit";
13452 default:
13453 return "unknown";
13454 }
13455 }
13456
13457 /* Display error string. */
13458 static void community_list_perror(struct vty *vty, int ret)
13459 {
13460 switch (ret) {
13461 case COMMUNITY_LIST_ERR_CANT_FIND_LIST:
13462 vty_out(vty, "%% Can't find community-list\n");
13463 break;
13464 case COMMUNITY_LIST_ERR_MALFORMED_VAL:
13465 vty_out(vty, "%% Malformed community-list value\n");
13466 break;
13467 case COMMUNITY_LIST_ERR_STANDARD_CONFLICT:
13468 vty_out(vty,
13469 "%% Community name conflict, previously defined as standard community\n");
13470 break;
13471 case COMMUNITY_LIST_ERR_EXPANDED_CONFLICT:
13472 vty_out(vty,
13473 "%% Community name conflict, previously defined as expanded community\n");
13474 break;
13475 }
13476 }
13477
13478 /* "community-list" keyword help string. */
13479 #define COMMUNITY_LIST_STR "Add a community list entry\n"
13480
13481 /* ip community-list standard */
13482 DEFUN (ip_community_list_standard,
13483 ip_community_list_standard_cmd,
13484 "ip community-list <(1-99)|standard WORD> <deny|permit> AA:NN...",
13485 IP_STR
13486 COMMUNITY_LIST_STR
13487 "Community list number (standard)\n"
13488 "Add an standard community-list entry\n"
13489 "Community list name\n"
13490 "Specify community to reject\n"
13491 "Specify community to accept\n"
13492 COMMUNITY_VAL_STR)
13493 {
13494 char *cl_name_or_number = NULL;
13495 int direct = 0;
13496 int style = COMMUNITY_LIST_STANDARD;
13497
13498 int idx = 0;
13499 argv_find(argv, argc, "(1-99)", &idx);
13500 argv_find(argv, argc, "WORD", &idx);
13501 cl_name_or_number = argv[idx]->arg;
13502 direct = argv_find(argv, argc, "permit", &idx) ? COMMUNITY_PERMIT
13503 : COMMUNITY_DENY;
13504 argv_find(argv, argc, "AA:NN", &idx);
13505 char *str = argv_concat(argv, argc, idx);
13506
13507 int ret = community_list_set(bgp_clist, cl_name_or_number, str, direct,
13508 style);
13509
13510 XFREE(MTYPE_TMP, str);
13511
13512 if (ret < 0) {
13513 /* Display error string. */
13514 community_list_perror(vty, ret);
13515 return CMD_WARNING_CONFIG_FAILED;
13516 }
13517
13518 return CMD_SUCCESS;
13519 }
13520
13521 DEFUN (no_ip_community_list_standard_all,
13522 no_ip_community_list_standard_all_cmd,
13523 "no ip community-list <(1-99)|standard WORD> <deny|permit> AA:NN...",
13524 NO_STR
13525 IP_STR
13526 COMMUNITY_LIST_STR
13527 "Community list number (standard)\n"
13528 "Add an standard community-list entry\n"
13529 "Community list name\n"
13530 "Specify community to reject\n"
13531 "Specify community to accept\n"
13532 COMMUNITY_VAL_STR)
13533 {
13534 char *cl_name_or_number = NULL;
13535 int direct = 0;
13536 int style = COMMUNITY_LIST_STANDARD;
13537
13538 int idx = 0;
13539 argv_find(argv, argc, "(1-99)", &idx);
13540 argv_find(argv, argc, "WORD", &idx);
13541 cl_name_or_number = argv[idx]->arg;
13542 direct = argv_find(argv, argc, "permit", &idx) ? COMMUNITY_PERMIT
13543 : COMMUNITY_DENY;
13544 argv_find(argv, argc, "AA:NN", &idx);
13545 char *str = argv_concat(argv, argc, idx);
13546
13547 int ret = community_list_unset(bgp_clist, cl_name_or_number, str,
13548 direct, style);
13549
13550 XFREE(MTYPE_TMP, str);
13551
13552 if (ret < 0) {
13553 community_list_perror(vty, ret);
13554 return CMD_WARNING_CONFIG_FAILED;
13555 }
13556
13557 return CMD_SUCCESS;
13558 }
13559
13560 /* ip community-list expanded */
13561 DEFUN (ip_community_list_expanded_all,
13562 ip_community_list_expanded_all_cmd,
13563 "ip community-list <(100-500)|expanded WORD> <deny|permit> AA:NN...",
13564 IP_STR
13565 COMMUNITY_LIST_STR
13566 "Community list number (expanded)\n"
13567 "Add an expanded community-list entry\n"
13568 "Community list name\n"
13569 "Specify community to reject\n"
13570 "Specify community to accept\n"
13571 COMMUNITY_VAL_STR)
13572 {
13573 char *cl_name_or_number = NULL;
13574 int direct = 0;
13575 int style = COMMUNITY_LIST_EXPANDED;
13576
13577 int idx = 0;
13578 argv_find(argv, argc, "(100-500)", &idx);
13579 argv_find(argv, argc, "WORD", &idx);
13580 cl_name_or_number = argv[idx]->arg;
13581 direct = argv_find(argv, argc, "permit", &idx) ? COMMUNITY_PERMIT
13582 : COMMUNITY_DENY;
13583 argv_find(argv, argc, "AA:NN", &idx);
13584 char *str = argv_concat(argv, argc, idx);
13585
13586 int ret = community_list_set(bgp_clist, cl_name_or_number, str, direct,
13587 style);
13588
13589 XFREE(MTYPE_TMP, str);
13590
13591 if (ret < 0) {
13592 /* Display error string. */
13593 community_list_perror(vty, ret);
13594 return CMD_WARNING_CONFIG_FAILED;
13595 }
13596
13597 return CMD_SUCCESS;
13598 }
13599
13600 DEFUN (no_ip_community_list_expanded_all,
13601 no_ip_community_list_expanded_all_cmd,
13602 "no ip community-list <(100-500)|expanded WORD> <deny|permit> AA:NN...",
13603 NO_STR
13604 IP_STR
13605 COMMUNITY_LIST_STR
13606 "Community list number (expanded)\n"
13607 "Add an expanded community-list entry\n"
13608 "Community list name\n"
13609 "Specify community to reject\n"
13610 "Specify community to accept\n"
13611 COMMUNITY_VAL_STR)
13612 {
13613 char *cl_name_or_number = NULL;
13614 int direct = 0;
13615 int style = COMMUNITY_LIST_EXPANDED;
13616
13617 int idx = 0;
13618 argv_find(argv, argc, "(100-500)", &idx);
13619 argv_find(argv, argc, "WORD", &idx);
13620 cl_name_or_number = argv[idx]->arg;
13621 direct = argv_find(argv, argc, "permit", &idx) ? COMMUNITY_PERMIT
13622 : COMMUNITY_DENY;
13623 argv_find(argv, argc, "AA:NN", &idx);
13624 char *str = argv_concat(argv, argc, idx);
13625
13626 int ret = community_list_unset(bgp_clist, cl_name_or_number, str,
13627 direct, style);
13628
13629 XFREE(MTYPE_TMP, str);
13630
13631 if (ret < 0) {
13632 community_list_perror(vty, ret);
13633 return CMD_WARNING_CONFIG_FAILED;
13634 }
13635
13636 return CMD_SUCCESS;
13637 }
13638
13639 /* Return configuration string of community-list entry. */
13640 static const char *community_list_config_str(struct community_entry *entry)
13641 {
13642 const char *str;
13643
13644 if (entry->any)
13645 str = "";
13646 else {
13647 if (entry->style == COMMUNITY_LIST_STANDARD)
13648 str = community_str(entry->u.com, false);
13649 else if (entry->style == LARGE_COMMUNITY_LIST_STANDARD)
13650 str = lcommunity_str(entry->u.lcom, false);
13651 else
13652 str = entry->config;
13653 }
13654 return str;
13655 }
13656
13657 static void community_list_show(struct vty *vty, struct community_list *list)
13658 {
13659 struct community_entry *entry;
13660
13661 for (entry = list->head; entry; entry = entry->next) {
13662 if (entry == list->head) {
13663 if (all_digit(list->name))
13664 vty_out(vty, "Community %s list %s\n",
13665 entry->style == COMMUNITY_LIST_STANDARD
13666 ? "standard"
13667 : "(expanded) access",
13668 list->name);
13669 else
13670 vty_out(vty, "Named Community %s list %s\n",
13671 entry->style == COMMUNITY_LIST_STANDARD
13672 ? "standard"
13673 : "expanded",
13674 list->name);
13675 }
13676 if (entry->any)
13677 vty_out(vty, " %s\n",
13678 community_direct_str(entry->direct));
13679 else
13680 vty_out(vty, " %s %s\n",
13681 community_direct_str(entry->direct),
13682 community_list_config_str(entry));
13683 }
13684 }
13685
13686 DEFUN (show_ip_community_list,
13687 show_ip_community_list_cmd,
13688 "show ip community-list",
13689 SHOW_STR
13690 IP_STR
13691 "List community-list\n")
13692 {
13693 struct community_list *list;
13694 struct community_list_master *cm;
13695
13696 cm = community_list_master_lookup(bgp_clist, COMMUNITY_LIST_MASTER);
13697 if (!cm)
13698 return CMD_SUCCESS;
13699
13700 for (list = cm->num.head; list; list = list->next)
13701 community_list_show(vty, list);
13702
13703 for (list = cm->str.head; list; list = list->next)
13704 community_list_show(vty, list);
13705
13706 return CMD_SUCCESS;
13707 }
13708
13709 DEFUN (show_ip_community_list_arg,
13710 show_ip_community_list_arg_cmd,
13711 "show ip community-list <(1-500)|WORD>",
13712 SHOW_STR
13713 IP_STR
13714 "List community-list\n"
13715 "Community-list number\n"
13716 "Community-list name\n")
13717 {
13718 int idx_comm_list = 3;
13719 struct community_list *list;
13720
13721 list = community_list_lookup(bgp_clist, argv[idx_comm_list]->arg,
13722 COMMUNITY_LIST_MASTER);
13723 if (!list) {
13724 vty_out(vty, "%% Can't find community-list\n");
13725 return CMD_WARNING;
13726 }
13727
13728 community_list_show(vty, list);
13729
13730 return CMD_SUCCESS;
13731 }
13732
13733 /*
13734 * Large Community code.
13735 */
13736 static int lcommunity_list_set_vty(struct vty *vty, int argc,
13737 struct cmd_token **argv, int style,
13738 int reject_all_digit_name)
13739 {
13740 int ret;
13741 int direct;
13742 char *str;
13743 int idx = 0;
13744 char *cl_name;
13745
13746 direct = argv_find(argv, argc, "permit", &idx) ? COMMUNITY_PERMIT
13747 : COMMUNITY_DENY;
13748
13749 /* All digit name check. */
13750 idx = 0;
13751 argv_find(argv, argc, "WORD", &idx);
13752 argv_find(argv, argc, "(1-99)", &idx);
13753 argv_find(argv, argc, "(100-500)", &idx);
13754 cl_name = argv[idx]->arg;
13755 if (reject_all_digit_name && all_digit(cl_name)) {
13756 vty_out(vty, "%% Community name cannot have all digits\n");
13757 return CMD_WARNING_CONFIG_FAILED;
13758 }
13759
13760 idx = 0;
13761 argv_find(argv, argc, "AA:BB:CC", &idx);
13762 argv_find(argv, argc, "LINE", &idx);
13763 /* Concat community string argument. */
13764 if (idx)
13765 str = argv_concat(argv, argc, idx);
13766 else
13767 str = NULL;
13768
13769 ret = lcommunity_list_set(bgp_clist, cl_name, str, direct, style);
13770
13771 /* Free temporary community list string allocated by
13772 argv_concat(). */
13773 if (str)
13774 XFREE(MTYPE_TMP, str);
13775
13776 if (ret < 0) {
13777 community_list_perror(vty, ret);
13778 return CMD_WARNING_CONFIG_FAILED;
13779 }
13780 return CMD_SUCCESS;
13781 }
13782
13783 static int lcommunity_list_unset_vty(struct vty *vty, int argc,
13784 struct cmd_token **argv, int style)
13785 {
13786 int ret;
13787 int direct = 0;
13788 char *str = NULL;
13789 int idx = 0;
13790
13791 argv_find(argv, argc, "permit", &idx);
13792 argv_find(argv, argc, "deny", &idx);
13793
13794 if (idx) {
13795 /* Check the list direct. */
13796 if (strncmp(argv[idx]->arg, "p", 1) == 0)
13797 direct = COMMUNITY_PERMIT;
13798 else
13799 direct = COMMUNITY_DENY;
13800
13801 idx = 0;
13802 argv_find(argv, argc, "LINE", &idx);
13803 argv_find(argv, argc, "AA:AA:NN", &idx);
13804 /* Concat community string argument. */
13805 str = argv_concat(argv, argc, idx);
13806 }
13807
13808 idx = 0;
13809 argv_find(argv, argc, "(1-99)", &idx);
13810 argv_find(argv, argc, "(100-500)", &idx);
13811 argv_find(argv, argc, "WORD", &idx);
13812
13813 /* Unset community list. */
13814 ret = lcommunity_list_unset(bgp_clist, argv[idx]->arg, str, direct,
13815 style);
13816
13817 /* Free temporary community list string allocated by
13818 argv_concat(). */
13819 if (str)
13820 XFREE(MTYPE_TMP, str);
13821
13822 if (ret < 0) {
13823 community_list_perror(vty, ret);
13824 return CMD_WARNING_CONFIG_FAILED;
13825 }
13826
13827 return CMD_SUCCESS;
13828 }
13829
13830 /* "large-community-list" keyword help string. */
13831 #define LCOMMUNITY_LIST_STR "Add a large community list entry\n"
13832 #define LCOMMUNITY_VAL_STR "large community in 'aa:bb:cc' format\n"
13833
13834 DEFUN (ip_lcommunity_list_standard,
13835 ip_lcommunity_list_standard_cmd,
13836 "ip large-community-list (1-99) <deny|permit>",
13837 IP_STR
13838 LCOMMUNITY_LIST_STR
13839 "Large Community list number (standard)\n"
13840 "Specify large community to reject\n"
13841 "Specify large community to accept\n")
13842 {
13843 return lcommunity_list_set_vty(vty, argc, argv,
13844 LARGE_COMMUNITY_LIST_STANDARD, 0);
13845 }
13846
13847 DEFUN (ip_lcommunity_list_standard1,
13848 ip_lcommunity_list_standard1_cmd,
13849 "ip large-community-list (1-99) <deny|permit> AA:BB:CC...",
13850 IP_STR
13851 LCOMMUNITY_LIST_STR
13852 "Large Community list number (standard)\n"
13853 "Specify large community to reject\n"
13854 "Specify large community to accept\n"
13855 LCOMMUNITY_VAL_STR)
13856 {
13857 return lcommunity_list_set_vty(vty, argc, argv,
13858 LARGE_COMMUNITY_LIST_STANDARD, 0);
13859 }
13860
13861 DEFUN (ip_lcommunity_list_expanded,
13862 ip_lcommunity_list_expanded_cmd,
13863 "ip large-community-list (100-500) <deny|permit> LINE...",
13864 IP_STR
13865 LCOMMUNITY_LIST_STR
13866 "Large Community list number (expanded)\n"
13867 "Specify large community to reject\n"
13868 "Specify large community to accept\n"
13869 "An ordered list as a regular-expression\n")
13870 {
13871 return lcommunity_list_set_vty(vty, argc, argv,
13872 LARGE_COMMUNITY_LIST_EXPANDED, 0);
13873 }
13874
13875 DEFUN (ip_lcommunity_list_name_standard,
13876 ip_lcommunity_list_name_standard_cmd,
13877 "ip large-community-list standard WORD <deny|permit>",
13878 IP_STR
13879 LCOMMUNITY_LIST_STR
13880 "Specify standard large-community-list\n"
13881 "Large Community list name\n"
13882 "Specify large community to reject\n"
13883 "Specify large community to accept\n")
13884 {
13885 return lcommunity_list_set_vty(vty, argc, argv,
13886 LARGE_COMMUNITY_LIST_STANDARD, 1);
13887 }
13888
13889 DEFUN (ip_lcommunity_list_name_standard1,
13890 ip_lcommunity_list_name_standard1_cmd,
13891 "ip large-community-list standard WORD <deny|permit> AA:BB:CC...",
13892 IP_STR
13893 LCOMMUNITY_LIST_STR
13894 "Specify standard large-community-list\n"
13895 "Large Community list name\n"
13896 "Specify large community to reject\n"
13897 "Specify large community to accept\n"
13898 LCOMMUNITY_VAL_STR)
13899 {
13900 return lcommunity_list_set_vty(vty, argc, argv,
13901 LARGE_COMMUNITY_LIST_STANDARD, 1);
13902 }
13903
13904 DEFUN (ip_lcommunity_list_name_expanded,
13905 ip_lcommunity_list_name_expanded_cmd,
13906 "ip large-community-list expanded WORD <deny|permit> LINE...",
13907 IP_STR
13908 LCOMMUNITY_LIST_STR
13909 "Specify expanded large-community-list\n"
13910 "Large Community list name\n"
13911 "Specify large community to reject\n"
13912 "Specify large community to accept\n"
13913 "An ordered list as a regular-expression\n")
13914 {
13915 return lcommunity_list_set_vty(vty, argc, argv,
13916 LARGE_COMMUNITY_LIST_EXPANDED, 1);
13917 }
13918
13919 DEFUN (no_ip_lcommunity_list_standard_all,
13920 no_ip_lcommunity_list_standard_all_cmd,
13921 "no ip large-community-list <(1-99)|(100-500)|WORD>",
13922 NO_STR
13923 IP_STR
13924 LCOMMUNITY_LIST_STR
13925 "Large Community list number (standard)\n"
13926 "Large Community list number (expanded)\n"
13927 "Large Community list name\n")
13928 {
13929 return lcommunity_list_unset_vty(vty, argc, argv,
13930 LARGE_COMMUNITY_LIST_STANDARD);
13931 }
13932
13933 DEFUN (no_ip_lcommunity_list_name_expanded_all,
13934 no_ip_lcommunity_list_name_expanded_all_cmd,
13935 "no ip large-community-list expanded WORD",
13936 NO_STR
13937 IP_STR
13938 LCOMMUNITY_LIST_STR
13939 "Specify expanded large-community-list\n"
13940 "Large Community list name\n")
13941 {
13942 return lcommunity_list_unset_vty(vty, argc, argv,
13943 LARGE_COMMUNITY_LIST_EXPANDED);
13944 }
13945
13946 DEFUN (no_ip_lcommunity_list_standard,
13947 no_ip_lcommunity_list_standard_cmd,
13948 "no ip large-community-list (1-99) <deny|permit> AA:AA:NN...",
13949 NO_STR
13950 IP_STR
13951 LCOMMUNITY_LIST_STR
13952 "Large Community list number (standard)\n"
13953 "Specify large community to reject\n"
13954 "Specify large community to accept\n"
13955 LCOMMUNITY_VAL_STR)
13956 {
13957 return lcommunity_list_unset_vty(vty, argc, argv,
13958 LARGE_COMMUNITY_LIST_STANDARD);
13959 }
13960
13961 DEFUN (no_ip_lcommunity_list_expanded,
13962 no_ip_lcommunity_list_expanded_cmd,
13963 "no ip large-community-list (100-500) <deny|permit> LINE...",
13964 NO_STR
13965 IP_STR
13966 LCOMMUNITY_LIST_STR
13967 "Large Community list number (expanded)\n"
13968 "Specify large community to reject\n"
13969 "Specify large community to accept\n"
13970 "An ordered list as a regular-expression\n")
13971 {
13972 return lcommunity_list_unset_vty(vty, argc, argv,
13973 LARGE_COMMUNITY_LIST_EXPANDED);
13974 }
13975
13976 DEFUN (no_ip_lcommunity_list_name_standard,
13977 no_ip_lcommunity_list_name_standard_cmd,
13978 "no ip large-community-list standard WORD <deny|permit> AA:AA:NN...",
13979 NO_STR
13980 IP_STR
13981 LCOMMUNITY_LIST_STR
13982 "Specify standard large-community-list\n"
13983 "Large Community list name\n"
13984 "Specify large community to reject\n"
13985 "Specify large community to accept\n"
13986 LCOMMUNITY_VAL_STR)
13987 {
13988 return lcommunity_list_unset_vty(vty, argc, argv,
13989 LARGE_COMMUNITY_LIST_STANDARD);
13990 }
13991
13992 DEFUN (no_ip_lcommunity_list_name_expanded,
13993 no_ip_lcommunity_list_name_expanded_cmd,
13994 "no ip large-community-list expanded WORD <deny|permit> LINE...",
13995 NO_STR
13996 IP_STR
13997 LCOMMUNITY_LIST_STR
13998 "Specify expanded large-community-list\n"
13999 "Large community list name\n"
14000 "Specify large community to reject\n"
14001 "Specify large community to accept\n"
14002 "An ordered list as a regular-expression\n")
14003 {
14004 return lcommunity_list_unset_vty(vty, argc, argv,
14005 LARGE_COMMUNITY_LIST_EXPANDED);
14006 }
14007
14008 static void lcommunity_list_show(struct vty *vty, struct community_list *list)
14009 {
14010 struct community_entry *entry;
14011
14012 for (entry = list->head; entry; entry = entry->next) {
14013 if (entry == list->head) {
14014 if (all_digit(list->name))
14015 vty_out(vty, "Large community %s list %s\n",
14016 entry->style == EXTCOMMUNITY_LIST_STANDARD
14017 ? "standard"
14018 : "(expanded) access",
14019 list->name);
14020 else
14021 vty_out(vty,
14022 "Named large community %s list %s\n",
14023 entry->style == EXTCOMMUNITY_LIST_STANDARD
14024 ? "standard"
14025 : "expanded",
14026 list->name);
14027 }
14028 if (entry->any)
14029 vty_out(vty, " %s\n",
14030 community_direct_str(entry->direct));
14031 else
14032 vty_out(vty, " %s %s\n",
14033 community_direct_str(entry->direct),
14034 community_list_config_str(entry));
14035 }
14036 }
14037
14038 DEFUN (show_ip_lcommunity_list,
14039 show_ip_lcommunity_list_cmd,
14040 "show ip large-community-list",
14041 SHOW_STR
14042 IP_STR
14043 "List large-community list\n")
14044 {
14045 struct community_list *list;
14046 struct community_list_master *cm;
14047
14048 cm = community_list_master_lookup(bgp_clist,
14049 LARGE_COMMUNITY_LIST_MASTER);
14050 if (!cm)
14051 return CMD_SUCCESS;
14052
14053 for (list = cm->num.head; list; list = list->next)
14054 lcommunity_list_show(vty, list);
14055
14056 for (list = cm->str.head; list; list = list->next)
14057 lcommunity_list_show(vty, list);
14058
14059 return CMD_SUCCESS;
14060 }
14061
14062 DEFUN (show_ip_lcommunity_list_arg,
14063 show_ip_lcommunity_list_arg_cmd,
14064 "show ip large-community-list <(1-500)|WORD>",
14065 SHOW_STR
14066 IP_STR
14067 "List large-community list\n"
14068 "large-community-list number\n"
14069 "large-community-list name\n")
14070 {
14071 struct community_list *list;
14072
14073 list = community_list_lookup(bgp_clist, argv[3]->arg,
14074 LARGE_COMMUNITY_LIST_MASTER);
14075 if (!list) {
14076 vty_out(vty, "%% Can't find extcommunity-list\n");
14077 return CMD_WARNING;
14078 }
14079
14080 lcommunity_list_show(vty, list);
14081
14082 return CMD_SUCCESS;
14083 }
14084
14085 /* "extcommunity-list" keyword help string. */
14086 #define EXTCOMMUNITY_LIST_STR "Add a extended community list entry\n"
14087 #define EXTCOMMUNITY_VAL_STR "Extended community attribute in 'rt aa:nn_or_IPaddr:nn' OR 'soo aa:nn_or_IPaddr:nn' format\n"
14088
14089 DEFUN (ip_extcommunity_list_standard,
14090 ip_extcommunity_list_standard_cmd,
14091 "ip extcommunity-list <(1-99)|standard WORD> <deny|permit> AA:NN...",
14092 IP_STR
14093 EXTCOMMUNITY_LIST_STR
14094 "Extended Community list number (standard)\n"
14095 "Specify standard extcommunity-list\n"
14096 "Community list name\n"
14097 "Specify community to reject\n"
14098 "Specify community to accept\n"
14099 EXTCOMMUNITY_VAL_STR)
14100 {
14101 int style = EXTCOMMUNITY_LIST_STANDARD;
14102 int direct = 0;
14103 char *cl_number_or_name = NULL;
14104
14105 int idx = 0;
14106 argv_find(argv, argc, "(1-99)", &idx);
14107 argv_find(argv, argc, "WORD", &idx);
14108 cl_number_or_name = argv[idx]->arg;
14109 direct = argv_find(argv, argc, "permit", &idx) ? COMMUNITY_PERMIT
14110 : COMMUNITY_DENY;
14111 argv_find(argv, argc, "AA:NN", &idx);
14112 char *str = argv_concat(argv, argc, idx);
14113
14114 int ret = extcommunity_list_set(bgp_clist, cl_number_or_name, str,
14115 direct, style);
14116
14117 XFREE(MTYPE_TMP, str);
14118
14119 if (ret < 0) {
14120 community_list_perror(vty, ret);
14121 return CMD_WARNING_CONFIG_FAILED;
14122 }
14123
14124 return CMD_SUCCESS;
14125 }
14126
14127 DEFUN (ip_extcommunity_list_name_expanded,
14128 ip_extcommunity_list_name_expanded_cmd,
14129 "ip extcommunity-list <(100-500)|expanded WORD> <deny|permit> LINE...",
14130 IP_STR
14131 EXTCOMMUNITY_LIST_STR
14132 "Extended Community list number (expanded)\n"
14133 "Specify expanded extcommunity-list\n"
14134 "Extended Community list name\n"
14135 "Specify community to reject\n"
14136 "Specify community to accept\n"
14137 "An ordered list as a regular-expression\n")
14138 {
14139 int style = EXTCOMMUNITY_LIST_EXPANDED;
14140 int direct = 0;
14141 char *cl_number_or_name = NULL;
14142
14143 int idx = 0;
14144 argv_find(argv, argc, "(100-500)", &idx);
14145 argv_find(argv, argc, "WORD", &idx);
14146 cl_number_or_name = argv[idx]->arg;
14147 direct = argv_find(argv, argc, "permit", &idx) ? COMMUNITY_PERMIT
14148 : COMMUNITY_DENY;
14149 argv_find(argv, argc, "LINE", &idx);
14150 char *str = argv_concat(argv, argc, idx);
14151
14152 int ret = extcommunity_list_set(bgp_clist, cl_number_or_name, str,
14153 direct, style);
14154
14155 XFREE(MTYPE_TMP, str);
14156
14157 if (ret < 0) {
14158 community_list_perror(vty, ret);
14159 return CMD_WARNING_CONFIG_FAILED;
14160 }
14161
14162 return CMD_SUCCESS;
14163 }
14164
14165 DEFUN (no_ip_extcommunity_list_standard_all,
14166 no_ip_extcommunity_list_standard_all_cmd,
14167 "no ip extcommunity-list <(1-99)|standard WORD> <deny|permit> AA:NN...",
14168 NO_STR
14169 IP_STR
14170 EXTCOMMUNITY_LIST_STR
14171 "Extended Community list number (standard)\n"
14172 "Specify standard extcommunity-list\n"
14173 "Community list name\n"
14174 "Specify community to reject\n"
14175 "Specify community to accept\n"
14176 EXTCOMMUNITY_VAL_STR)
14177 {
14178 int style = EXTCOMMUNITY_LIST_STANDARD;
14179 int direct = 0;
14180 char *cl_number_or_name = NULL;
14181
14182 int idx = 0;
14183 argv_find(argv, argc, "(1-99)", &idx);
14184 argv_find(argv, argc, "WORD", &idx);
14185 cl_number_or_name = argv[idx]->arg;
14186 direct = argv_find(argv, argc, "permit", &idx) ? COMMUNITY_PERMIT
14187 : COMMUNITY_DENY;
14188 argv_find(argv, argc, "AA:NN", &idx);
14189 char *str = argv_concat(argv, argc, idx);
14190
14191 int ret = extcommunity_list_unset(bgp_clist, cl_number_or_name, str,
14192 direct, style);
14193
14194 XFREE(MTYPE_TMP, str);
14195
14196 if (ret < 0) {
14197 community_list_perror(vty, ret);
14198 return CMD_WARNING_CONFIG_FAILED;
14199 }
14200
14201 return CMD_SUCCESS;
14202 }
14203
14204 DEFUN (no_ip_extcommunity_list_expanded_all,
14205 no_ip_extcommunity_list_expanded_all_cmd,
14206 "no ip extcommunity-list <(100-500)|expanded WORD> <deny|permit> LINE...",
14207 NO_STR
14208 IP_STR
14209 EXTCOMMUNITY_LIST_STR
14210 "Extended Community list number (expanded)\n"
14211 "Specify expanded extcommunity-list\n"
14212 "Extended Community list name\n"
14213 "Specify community to reject\n"
14214 "Specify community to accept\n"
14215 "An ordered list as a regular-expression\n")
14216 {
14217 int style = EXTCOMMUNITY_LIST_EXPANDED;
14218 int direct = 0;
14219 char *cl_number_or_name = NULL;
14220
14221 int idx = 0;
14222 argv_find(argv, argc, "(100-500)", &idx);
14223 argv_find(argv, argc, "WORD", &idx);
14224 cl_number_or_name = argv[idx]->arg;
14225 direct = argv_find(argv, argc, "permit", &idx) ? COMMUNITY_PERMIT
14226 : COMMUNITY_DENY;
14227 argv_find(argv, argc, "LINE", &idx);
14228 char *str = argv_concat(argv, argc, idx);
14229
14230 int ret = extcommunity_list_unset(bgp_clist, cl_number_or_name, str,
14231 direct, style);
14232
14233 XFREE(MTYPE_TMP, str);
14234
14235 if (ret < 0) {
14236 community_list_perror(vty, ret);
14237 return CMD_WARNING_CONFIG_FAILED;
14238 }
14239
14240 return CMD_SUCCESS;
14241 }
14242
14243 static void extcommunity_list_show(struct vty *vty, struct community_list *list)
14244 {
14245 struct community_entry *entry;
14246
14247 for (entry = list->head; entry; entry = entry->next) {
14248 if (entry == list->head) {
14249 if (all_digit(list->name))
14250 vty_out(vty, "Extended community %s list %s\n",
14251 entry->style == EXTCOMMUNITY_LIST_STANDARD
14252 ? "standard"
14253 : "(expanded) access",
14254 list->name);
14255 else
14256 vty_out(vty,
14257 "Named extended community %s list %s\n",
14258 entry->style == EXTCOMMUNITY_LIST_STANDARD
14259 ? "standard"
14260 : "expanded",
14261 list->name);
14262 }
14263 if (entry->any)
14264 vty_out(vty, " %s\n",
14265 community_direct_str(entry->direct));
14266 else
14267 vty_out(vty, " %s %s\n",
14268 community_direct_str(entry->direct),
14269 community_list_config_str(entry));
14270 }
14271 }
14272
14273 DEFUN (show_ip_extcommunity_list,
14274 show_ip_extcommunity_list_cmd,
14275 "show ip extcommunity-list",
14276 SHOW_STR
14277 IP_STR
14278 "List extended-community list\n")
14279 {
14280 struct community_list *list;
14281 struct community_list_master *cm;
14282
14283 cm = community_list_master_lookup(bgp_clist, EXTCOMMUNITY_LIST_MASTER);
14284 if (!cm)
14285 return CMD_SUCCESS;
14286
14287 for (list = cm->num.head; list; list = list->next)
14288 extcommunity_list_show(vty, list);
14289
14290 for (list = cm->str.head; list; list = list->next)
14291 extcommunity_list_show(vty, list);
14292
14293 return CMD_SUCCESS;
14294 }
14295
14296 DEFUN (show_ip_extcommunity_list_arg,
14297 show_ip_extcommunity_list_arg_cmd,
14298 "show ip extcommunity-list <(1-500)|WORD>",
14299 SHOW_STR
14300 IP_STR
14301 "List extended-community list\n"
14302 "Extcommunity-list number\n"
14303 "Extcommunity-list name\n")
14304 {
14305 int idx_comm_list = 3;
14306 struct community_list *list;
14307
14308 list = community_list_lookup(bgp_clist, argv[idx_comm_list]->arg,
14309 EXTCOMMUNITY_LIST_MASTER);
14310 if (!list) {
14311 vty_out(vty, "%% Can't find extcommunity-list\n");
14312 return CMD_WARNING;
14313 }
14314
14315 extcommunity_list_show(vty, list);
14316
14317 return CMD_SUCCESS;
14318 }
14319
14320 /* Display community-list and extcommunity-list configuration. */
14321 static int community_list_config_write(struct vty *vty)
14322 {
14323 struct community_list *list;
14324 struct community_entry *entry;
14325 struct community_list_master *cm;
14326 int write = 0;
14327
14328 /* Community-list. */
14329 cm = community_list_master_lookup(bgp_clist, COMMUNITY_LIST_MASTER);
14330
14331 for (list = cm->num.head; list; list = list->next)
14332 for (entry = list->head; entry; entry = entry->next) {
14333 vty_out(vty, "ip community-list %s %s %s\n", list->name,
14334 community_direct_str(entry->direct),
14335 community_list_config_str(entry));
14336 write++;
14337 }
14338 for (list = cm->str.head; list; list = list->next)
14339 for (entry = list->head; entry; entry = entry->next) {
14340 vty_out(vty, "ip community-list %s %s %s %s\n",
14341 entry->style == COMMUNITY_LIST_STANDARD
14342 ? "standard"
14343 : "expanded",
14344 list->name, community_direct_str(entry->direct),
14345 community_list_config_str(entry));
14346 write++;
14347 }
14348
14349 /* Extcommunity-list. */
14350 cm = community_list_master_lookup(bgp_clist, EXTCOMMUNITY_LIST_MASTER);
14351
14352 for (list = cm->num.head; list; list = list->next)
14353 for (entry = list->head; entry; entry = entry->next) {
14354 vty_out(vty, "ip extcommunity-list %s %s %s\n",
14355 list->name, community_direct_str(entry->direct),
14356 community_list_config_str(entry));
14357 write++;
14358 }
14359 for (list = cm->str.head; list; list = list->next)
14360 for (entry = list->head; entry; entry = entry->next) {
14361 vty_out(vty, "ip extcommunity-list %s %s %s %s\n",
14362 entry->style == EXTCOMMUNITY_LIST_STANDARD
14363 ? "standard"
14364 : "expanded",
14365 list->name, community_direct_str(entry->direct),
14366 community_list_config_str(entry));
14367 write++;
14368 }
14369
14370
14371 /* lcommunity-list. */
14372 cm = community_list_master_lookup(bgp_clist,
14373 LARGE_COMMUNITY_LIST_MASTER);
14374
14375 for (list = cm->num.head; list; list = list->next)
14376 for (entry = list->head; entry; entry = entry->next) {
14377 vty_out(vty, "ip large-community-list %s %s %s\n",
14378 list->name, community_direct_str(entry->direct),
14379 community_list_config_str(entry));
14380 write++;
14381 }
14382 for (list = cm->str.head; list; list = list->next)
14383 for (entry = list->head; entry; entry = entry->next) {
14384 vty_out(vty, "ip large-community-list %s %s %s %s\n",
14385 entry->style == LARGE_COMMUNITY_LIST_STANDARD
14386 ? "standard"
14387 : "expanded",
14388 list->name, community_direct_str(entry->direct),
14389 community_list_config_str(entry));
14390 write++;
14391 }
14392
14393 return write;
14394 }
14395
14396 static struct cmd_node community_list_node = {
14397 COMMUNITY_LIST_NODE, "", 1 /* Export to vtysh. */
14398 };
14399
14400 static void community_list_vty(void)
14401 {
14402 install_node(&community_list_node, community_list_config_write);
14403
14404 /* Community-list. */
14405 install_element(CONFIG_NODE, &ip_community_list_standard_cmd);
14406 install_element(CONFIG_NODE, &ip_community_list_expanded_all_cmd);
14407 install_element(CONFIG_NODE, &no_ip_community_list_standard_all_cmd);
14408 install_element(CONFIG_NODE, &no_ip_community_list_expanded_all_cmd);
14409 install_element(VIEW_NODE, &show_ip_community_list_cmd);
14410 install_element(VIEW_NODE, &show_ip_community_list_arg_cmd);
14411
14412 /* Extcommunity-list. */
14413 install_element(CONFIG_NODE, &ip_extcommunity_list_standard_cmd);
14414 install_element(CONFIG_NODE, &ip_extcommunity_list_name_expanded_cmd);
14415 install_element(CONFIG_NODE, &no_ip_extcommunity_list_standard_all_cmd);
14416 install_element(CONFIG_NODE, &no_ip_extcommunity_list_expanded_all_cmd);
14417 install_element(VIEW_NODE, &show_ip_extcommunity_list_cmd);
14418 install_element(VIEW_NODE, &show_ip_extcommunity_list_arg_cmd);
14419
14420 /* Large Community List */
14421 install_element(CONFIG_NODE, &ip_lcommunity_list_standard_cmd);
14422 install_element(CONFIG_NODE, &ip_lcommunity_list_standard1_cmd);
14423 install_element(CONFIG_NODE, &ip_lcommunity_list_expanded_cmd);
14424 install_element(CONFIG_NODE, &ip_lcommunity_list_name_standard_cmd);
14425 install_element(CONFIG_NODE, &ip_lcommunity_list_name_standard1_cmd);
14426 install_element(CONFIG_NODE, &ip_lcommunity_list_name_expanded_cmd);
14427 install_element(CONFIG_NODE, &no_ip_lcommunity_list_standard_all_cmd);
14428 install_element(CONFIG_NODE,
14429 &no_ip_lcommunity_list_name_expanded_all_cmd);
14430 install_element(CONFIG_NODE, &no_ip_lcommunity_list_standard_cmd);
14431 install_element(CONFIG_NODE, &no_ip_lcommunity_list_expanded_cmd);
14432 install_element(CONFIG_NODE, &no_ip_lcommunity_list_name_standard_cmd);
14433 install_element(CONFIG_NODE, &no_ip_lcommunity_list_name_expanded_cmd);
14434 install_element(VIEW_NODE, &show_ip_lcommunity_list_cmd);
14435 install_element(VIEW_NODE, &show_ip_lcommunity_list_arg_cmd);
14436 }