]> git.proxmox.com Git - mirror_frr.git/blob - bgpd/bgp_vty.c
Merge pull request #4201 from Orange-OpenSource/SR-isis
[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 "lib/zclient.h"
26 #include "prefix.h"
27 #include "plist.h"
28 #include "buffer.h"
29 #include "linklist.h"
30 #include "stream.h"
31 #include "thread.h"
32 #include "log.h"
33 #include "memory.h"
34 #include "memory_vty.h"
35 #include "hash.h"
36 #include "queue.h"
37 #include "filter.h"
38 #include "frrstr.h"
39
40 #include "bgpd/bgpd.h"
41 #include "bgpd/bgp_attr_evpn.h"
42 #include "bgpd/bgp_advertise.h"
43 #include "bgpd/bgp_attr.h"
44 #include "bgpd/bgp_aspath.h"
45 #include "bgpd/bgp_community.h"
46 #include "bgpd/bgp_ecommunity.h"
47 #include "bgpd/bgp_lcommunity.h"
48 #include "bgpd/bgp_damp.h"
49 #include "bgpd/bgp_debug.h"
50 #include "bgpd/bgp_errors.h"
51 #include "bgpd/bgp_fsm.h"
52 #include "bgpd/bgp_nexthop.h"
53 #include "bgpd/bgp_open.h"
54 #include "bgpd/bgp_regex.h"
55 #include "bgpd/bgp_route.h"
56 #include "bgpd/bgp_mplsvpn.h"
57 #include "bgpd/bgp_zebra.h"
58 #include "bgpd/bgp_table.h"
59 #include "bgpd/bgp_vty.h"
60 #include "bgpd/bgp_mpath.h"
61 #include "bgpd/bgp_packet.h"
62 #include "bgpd/bgp_updgrp.h"
63 #include "bgpd/bgp_bfd.h"
64 #include "bgpd/bgp_io.h"
65 #include "bgpd/bgp_evpn.h"
66 #include "bgpd/bgp_addpath.h"
67 #include "bgpd/bgp_mac.h"
68
69 static struct peer_group *listen_range_exists(struct bgp *bgp,
70 struct prefix *range, int exact);
71
72 static enum node_type bgp_node_type(afi_t afi, safi_t safi)
73 {
74 switch (afi) {
75 case AFI_IP:
76 switch (safi) {
77 case SAFI_UNICAST:
78 return BGP_IPV4_NODE;
79 break;
80 case SAFI_MULTICAST:
81 return BGP_IPV4M_NODE;
82 break;
83 case SAFI_LABELED_UNICAST:
84 return BGP_IPV4L_NODE;
85 break;
86 case SAFI_MPLS_VPN:
87 return BGP_VPNV4_NODE;
88 break;
89 case SAFI_FLOWSPEC:
90 return BGP_FLOWSPECV4_NODE;
91 default:
92 /* not expected */
93 return BGP_IPV4_NODE;
94 break;
95 }
96 break;
97 case AFI_IP6:
98 switch (safi) {
99 case SAFI_UNICAST:
100 return BGP_IPV6_NODE;
101 break;
102 case SAFI_MULTICAST:
103 return BGP_IPV6M_NODE;
104 break;
105 case SAFI_LABELED_UNICAST:
106 return BGP_IPV6L_NODE;
107 break;
108 case SAFI_MPLS_VPN:
109 return BGP_VPNV6_NODE;
110 break;
111 case SAFI_FLOWSPEC:
112 return BGP_FLOWSPECV6_NODE;
113 default:
114 /* not expected */
115 return BGP_IPV4_NODE;
116 break;
117 }
118 break;
119 case AFI_L2VPN:
120 return BGP_EVPN_NODE;
121 break;
122 case AFI_MAX:
123 // We should never be here but to clarify the switch statement..
124 return BGP_IPV4_NODE;
125 break;
126 }
127
128 // Impossible to happen
129 return BGP_IPV4_NODE;
130 }
131
132 /* Utility function to get address family from current node. */
133 afi_t bgp_node_afi(struct vty *vty)
134 {
135 afi_t afi;
136 switch (vty->node) {
137 case BGP_IPV6_NODE:
138 case BGP_IPV6M_NODE:
139 case BGP_IPV6L_NODE:
140 case BGP_VPNV6_NODE:
141 case BGP_FLOWSPECV6_NODE:
142 afi = AFI_IP6;
143 break;
144 case BGP_EVPN_NODE:
145 afi = AFI_L2VPN;
146 break;
147 default:
148 afi = AFI_IP;
149 break;
150 }
151 return afi;
152 }
153
154 /* Utility function to get subsequent address family from current
155 node. */
156 safi_t bgp_node_safi(struct vty *vty)
157 {
158 safi_t safi;
159 switch (vty->node) {
160 case BGP_VPNV4_NODE:
161 case BGP_VPNV6_NODE:
162 safi = SAFI_MPLS_VPN;
163 break;
164 case BGP_IPV4M_NODE:
165 case BGP_IPV6M_NODE:
166 safi = SAFI_MULTICAST;
167 break;
168 case BGP_EVPN_NODE:
169 safi = SAFI_EVPN;
170 break;
171 case BGP_IPV4L_NODE:
172 case BGP_IPV6L_NODE:
173 safi = SAFI_LABELED_UNICAST;
174 break;
175 case BGP_FLOWSPECV4_NODE:
176 case BGP_FLOWSPECV6_NODE:
177 safi = SAFI_FLOWSPEC;
178 break;
179 default:
180 safi = SAFI_UNICAST;
181 break;
182 }
183 return safi;
184 }
185
186 /**
187 * Converts an AFI in string form to afi_t
188 *
189 * @param afi string, one of
190 * - "ipv4"
191 * - "ipv6"
192 * - "l2vpn"
193 * @return the corresponding afi_t
194 */
195 afi_t bgp_vty_afi_from_str(const char *afi_str)
196 {
197 afi_t afi = AFI_MAX; /* unknown */
198 if (strmatch(afi_str, "ipv4"))
199 afi = AFI_IP;
200 else if (strmatch(afi_str, "ipv6"))
201 afi = AFI_IP6;
202 else if (strmatch(afi_str, "l2vpn"))
203 afi = AFI_L2VPN;
204 return afi;
205 }
206
207 int argv_find_and_parse_afi(struct cmd_token **argv, int argc, int *index,
208 afi_t *afi)
209 {
210 int ret = 0;
211 if (argv_find(argv, argc, "ipv4", index)) {
212 ret = 1;
213 if (afi)
214 *afi = AFI_IP;
215 } else if (argv_find(argv, argc, "ipv6", index)) {
216 ret = 1;
217 if (afi)
218 *afi = AFI_IP6;
219 }
220 return ret;
221 }
222
223 /* supports <unicast|multicast|vpn|labeled-unicast> */
224 safi_t bgp_vty_safi_from_str(const char *safi_str)
225 {
226 safi_t safi = SAFI_MAX; /* unknown */
227 if (strmatch(safi_str, "multicast"))
228 safi = SAFI_MULTICAST;
229 else if (strmatch(safi_str, "unicast"))
230 safi = SAFI_UNICAST;
231 else if (strmatch(safi_str, "vpn"))
232 safi = SAFI_MPLS_VPN;
233 else if (strmatch(safi_str, "evpn"))
234 safi = SAFI_EVPN;
235 else if (strmatch(safi_str, "labeled-unicast"))
236 safi = SAFI_LABELED_UNICAST;
237 else if (strmatch(safi_str, "flowspec"))
238 safi = SAFI_FLOWSPEC;
239 return safi;
240 }
241
242 int argv_find_and_parse_safi(struct cmd_token **argv, int argc, int *index,
243 safi_t *safi)
244 {
245 int ret = 0;
246 if (argv_find(argv, argc, "unicast", index)) {
247 ret = 1;
248 if (safi)
249 *safi = SAFI_UNICAST;
250 } else if (argv_find(argv, argc, "multicast", index)) {
251 ret = 1;
252 if (safi)
253 *safi = SAFI_MULTICAST;
254 } else if (argv_find(argv, argc, "labeled-unicast", index)) {
255 ret = 1;
256 if (safi)
257 *safi = SAFI_LABELED_UNICAST;
258 } else if (argv_find(argv, argc, "vpn", index)) {
259 ret = 1;
260 if (safi)
261 *safi = SAFI_MPLS_VPN;
262 } else if (argv_find(argv, argc, "flowspec", index)) {
263 ret = 1;
264 if (safi)
265 *safi = SAFI_FLOWSPEC;
266 }
267 return ret;
268 }
269
270 /*
271 * bgp_vty_find_and_parse_afi_safi_bgp
272 *
273 * For a given 'show ...' command, correctly parse the afi/safi/bgp out from it
274 * This function *assumes* that the calling function pre-sets the afi/safi/bgp
275 * to appropriate values for the calling function. This is to allow the
276 * calling function to make decisions appropriate for the show command
277 * that is being parsed.
278 *
279 * The show commands are generally of the form:
280 * "show [ip] bgp [<view|vrf> VIEWVRFNAME] [<ipv4|ipv6>
281 * [<unicast|multicast|vpn|labeled-unicast>]] ..."
282 *
283 * Since we use argv_find if the show command in particular doesn't have:
284 * [ip]
285 * [<view|vrf> VIEWVRFNAME]
286 * [<ipv4|ipv6> [<unicast|multicast|vpn|labeled-unicast>]]
287 * The command parsing should still be ok.
288 *
289 * vty -> The vty for the command so we can output some useful data in
290 * the event of a parse error in the vrf.
291 * argv -> The command tokens
292 * argc -> How many command tokens we have
293 * idx -> The current place in the command, generally should be 0 for this
294 * function
295 * afi -> The parsed afi if it was included in the show command, returned here
296 * safi -> The parsed safi if it was included in the show command, returned here
297 * bgp -> Pointer to the bgp data structure we need to fill in.
298 *
299 * The function returns the correct location in the parse tree for the
300 * last token found.
301 *
302 * Returns 0 for failure to parse correctly, else the idx position of where
303 * it found the last token.
304 */
305 int bgp_vty_find_and_parse_afi_safi_bgp(struct vty *vty,
306 struct cmd_token **argv, int argc,
307 int *idx, afi_t *afi, safi_t *safi,
308 struct bgp **bgp, bool use_json)
309 {
310 char *vrf_name = NULL;
311
312 assert(afi);
313 assert(safi);
314 assert(bgp);
315
316 if (argv_find(argv, argc, "ip", idx))
317 *afi = AFI_IP;
318
319 if (argv_find(argv, argc, "view", idx))
320 vrf_name = argv[*idx + 1]->arg;
321 else if (argv_find(argv, argc, "vrf", idx)) {
322 vrf_name = argv[*idx + 1]->arg;
323 if (strmatch(vrf_name, VRF_DEFAULT_NAME))
324 vrf_name = NULL;
325 }
326 if (vrf_name) {
327 if (strmatch(vrf_name, "all"))
328 *bgp = NULL;
329 else {
330 *bgp = bgp_lookup_by_name(vrf_name);
331 if (!*bgp) {
332 if (use_json)
333 vty_out(vty, "{}\n");
334 else
335 vty_out(vty, "View/Vrf %s is unknown\n",
336 vrf_name);
337 *idx = 0;
338 return 0;
339 }
340 }
341 } else {
342 *bgp = bgp_get_default();
343 if (!*bgp) {
344 if (use_json)
345 vty_out(vty, "{}\n");
346 else
347 vty_out(vty,
348 "Default BGP instance not found\n");
349 *idx = 0;
350 return 0;
351 }
352 }
353
354 if (argv_find_and_parse_afi(argv, argc, idx, afi))
355 argv_find_and_parse_safi(argv, argc, idx, safi);
356
357 *idx += 1;
358 return *idx;
359 }
360
361 static int peer_address_self_check(struct bgp *bgp, union sockunion *su)
362 {
363 struct interface *ifp = NULL;
364
365 if (su->sa.sa_family == AF_INET)
366 ifp = if_lookup_by_ipv4_exact(&su->sin.sin_addr, bgp->vrf_id);
367 else if (su->sa.sa_family == AF_INET6)
368 ifp = if_lookup_by_ipv6_exact(&su->sin6.sin6_addr,
369 su->sin6.sin6_scope_id,
370 bgp->vrf_id);
371
372 if (ifp)
373 return 1;
374
375 return 0;
376 }
377
378 /* Utility function for looking up peer from VTY. */
379 /* This is used only for configuration, so disallow if attempted on
380 * a dynamic neighbor.
381 */
382 static struct peer *peer_lookup_vty(struct vty *vty, const char *ip_str)
383 {
384 struct bgp *bgp = VTY_GET_CONTEXT(bgp);
385 int ret;
386 union sockunion su;
387 struct peer *peer;
388
389 if (!bgp) {
390 return NULL;
391 }
392
393 ret = str2sockunion(ip_str, &su);
394 if (ret < 0) {
395 peer = peer_lookup_by_conf_if(bgp, ip_str);
396 if (!peer) {
397 if ((peer = peer_lookup_by_hostname(bgp, ip_str))
398 == NULL) {
399 vty_out(vty,
400 "%% Malformed address or name: %s\n",
401 ip_str);
402 return NULL;
403 }
404 }
405 } else {
406 peer = peer_lookup(bgp, &su);
407 if (!peer) {
408 vty_out(vty,
409 "%% Specify remote-as or peer-group commands first\n");
410 return NULL;
411 }
412 if (peer_dynamic_neighbor(peer)) {
413 vty_out(vty,
414 "%% Operation not allowed on a dynamic neighbor\n");
415 return NULL;
416 }
417 }
418 return peer;
419 }
420
421 /* Utility function for looking up peer or peer group. */
422 /* This is used only for configuration, so disallow if attempted on
423 * a dynamic neighbor.
424 */
425 struct peer *peer_and_group_lookup_vty(struct vty *vty, const char *peer_str)
426 {
427 struct bgp *bgp = VTY_GET_CONTEXT(bgp);
428 int ret;
429 union sockunion su;
430 struct peer *peer = NULL;
431 struct peer_group *group = NULL;
432
433 if (!bgp) {
434 return NULL;
435 }
436
437 ret = str2sockunion(peer_str, &su);
438 if (ret == 0) {
439 /* IP address, locate peer. */
440 peer = peer_lookup(bgp, &su);
441 } else {
442 /* Not IP, could match either peer configured on interface or a
443 * group. */
444 peer = peer_lookup_by_conf_if(bgp, peer_str);
445 if (!peer)
446 group = peer_group_lookup(bgp, peer_str);
447 }
448
449 if (peer) {
450 if (peer_dynamic_neighbor(peer)) {
451 vty_out(vty,
452 "%% Operation not allowed on a dynamic neighbor\n");
453 return NULL;
454 }
455
456 return peer;
457 }
458
459 if (group)
460 return group->conf;
461
462 vty_out(vty, "%% Specify remote-as or peer-group commands first\n");
463
464 return NULL;
465 }
466
467 int bgp_vty_return(struct vty *vty, int ret)
468 {
469 const char *str = NULL;
470
471 switch (ret) {
472 case BGP_ERR_INVALID_VALUE:
473 str = "Invalid value";
474 break;
475 case BGP_ERR_INVALID_FLAG:
476 str = "Invalid flag";
477 break;
478 case BGP_ERR_PEER_GROUP_SHUTDOWN:
479 str = "Peer-group has been shutdown. Activate the peer-group first";
480 break;
481 case BGP_ERR_PEER_FLAG_CONFLICT:
482 str = "Can't set override-capability and strict-capability-match at the same time";
483 break;
484 case BGP_ERR_PEER_GROUP_NO_REMOTE_AS:
485 str = "Specify remote-as or peer-group remote AS first";
486 break;
487 case BGP_ERR_PEER_GROUP_CANT_CHANGE:
488 str = "Cannot change the peer-group. Deconfigure first";
489 break;
490 case BGP_ERR_PEER_GROUP_MISMATCH:
491 str = "Peer is not a member of this peer-group";
492 break;
493 case BGP_ERR_PEER_FILTER_CONFLICT:
494 str = "Prefix/distribute list can not co-exist";
495 break;
496 case BGP_ERR_NOT_INTERNAL_PEER:
497 str = "Invalid command. Not an internal neighbor";
498 break;
499 case BGP_ERR_REMOVE_PRIVATE_AS:
500 str = "remove-private-AS cannot be configured for IBGP peers";
501 break;
502 case BGP_ERR_LOCAL_AS_ALLOWED_ONLY_FOR_EBGP:
503 str = "Local-AS allowed only for EBGP peers";
504 break;
505 case BGP_ERR_CANNOT_HAVE_LOCAL_AS_SAME_AS:
506 str = "Cannot have local-as same as BGP AS number";
507 break;
508 case BGP_ERR_TCPSIG_FAILED:
509 str = "Error while applying TCP-Sig to session(s)";
510 break;
511 case BGP_ERR_NO_EBGP_MULTIHOP_WITH_TTLHACK:
512 str = "ebgp-multihop and ttl-security cannot be configured together";
513 break;
514 case BGP_ERR_NO_IBGP_WITH_TTLHACK:
515 str = "ttl-security only allowed for EBGP peers";
516 break;
517 case BGP_ERR_AS_OVERRIDE:
518 str = "as-override cannot be configured for IBGP peers";
519 break;
520 case BGP_ERR_INVALID_DYNAMIC_NEIGHBORS_LIMIT:
521 str = "Invalid limit for number of dynamic neighbors";
522 break;
523 case BGP_ERR_DYNAMIC_NEIGHBORS_RANGE_EXISTS:
524 str = "Dynamic neighbor listen range already exists";
525 break;
526 case BGP_ERR_INVALID_FOR_DYNAMIC_PEER:
527 str = "Operation not allowed on a dynamic neighbor";
528 break;
529 case BGP_ERR_INVALID_FOR_DIRECT_PEER:
530 str = "Operation not allowed on a directly connected neighbor";
531 break;
532 case BGP_ERR_PEER_SAFI_CONFLICT:
533 str = "Cannot activate peer for both 'ipv4 unicast' and 'ipv4 labeled-unicast'";
534 break;
535 }
536 if (str) {
537 vty_out(vty, "%% %s\n", str);
538 return CMD_WARNING_CONFIG_FAILED;
539 }
540 return CMD_SUCCESS;
541 }
542
543 /* BGP clear sort. */
544 enum clear_sort {
545 clear_all,
546 clear_peer,
547 clear_group,
548 clear_external,
549 clear_as
550 };
551
552 static void bgp_clear_vty_error(struct vty *vty, struct peer *peer, afi_t afi,
553 safi_t safi, int error)
554 {
555 switch (error) {
556 case BGP_ERR_AF_UNCONFIGURED:
557 vty_out(vty,
558 "%%BGP: Enable %s address family for the neighbor %s\n",
559 afi_safi_print(afi, safi), peer->host);
560 break;
561 case BGP_ERR_SOFT_RECONFIG_UNCONFIGURED:
562 vty_out(vty,
563 "%%BGP: Inbound soft reconfig for %s not possible as it\n has neither refresh capability, nor inbound soft reconfig\n",
564 peer->host);
565 break;
566 default:
567 break;
568 }
569 }
570
571 /* `clear ip bgp' functions. */
572 static int bgp_clear(struct vty *vty, struct bgp *bgp, afi_t afi, safi_t safi,
573 enum clear_sort sort, enum bgp_clear_type stype,
574 const char *arg)
575 {
576 int ret;
577 bool found = false;
578 struct peer *peer;
579 struct listnode *node, *nnode;
580
581 /* Clear all neighbors. */
582 /*
583 * Pass along pointer to next node to peer_clear() when walking all
584 * nodes on the BGP instance as that may get freed if it is a
585 * doppelganger
586 */
587 if (sort == clear_all) {
588 for (ALL_LIST_ELEMENTS(bgp->peer, node, nnode, peer)) {
589 if (!peer->afc[afi][safi])
590 continue;
591
592 if (stype == BGP_CLEAR_SOFT_NONE)
593 ret = peer_clear(peer, &nnode);
594 else
595 ret = peer_clear_soft(peer, afi, safi, stype);
596
597 if (ret < 0)
598 bgp_clear_vty_error(vty, peer, afi, safi, ret);
599 else
600 found = true;
601 }
602
603 /* This is to apply read-only mode on this clear. */
604 if (stype == BGP_CLEAR_SOFT_NONE)
605 bgp->update_delay_over = 0;
606
607 if (!found)
608 vty_out(vty, "%%BGP: No %s peer configured\n",
609 afi_safi_print(afi, safi));
610
611 return CMD_SUCCESS;
612 }
613
614 /* Clear specified neighbor. */
615 if (sort == clear_peer) {
616 union sockunion su;
617
618 /* Make sockunion for lookup. */
619 ret = str2sockunion(arg, &su);
620 if (ret < 0) {
621 peer = peer_lookup_by_conf_if(bgp, arg);
622 if (!peer) {
623 peer = peer_lookup_by_hostname(bgp, arg);
624 if (!peer) {
625 vty_out(vty,
626 "Malformed address or name: %s\n",
627 arg);
628 return CMD_WARNING;
629 }
630 }
631 } else {
632 peer = peer_lookup(bgp, &su);
633 if (!peer) {
634 vty_out(vty,
635 "%%BGP: Unknown neighbor - \"%s\"\n",
636 arg);
637 return CMD_WARNING;
638 }
639 }
640
641 if (!peer->afc[afi][safi])
642 ret = BGP_ERR_AF_UNCONFIGURED;
643 else if (stype == BGP_CLEAR_SOFT_NONE)
644 ret = peer_clear(peer, NULL);
645 else
646 ret = peer_clear_soft(peer, afi, safi, stype);
647
648 if (ret < 0)
649 bgp_clear_vty_error(vty, peer, afi, safi, ret);
650
651 return CMD_SUCCESS;
652 }
653
654 /* Clear all neighbors belonging to a specific peer-group. */
655 if (sort == clear_group) {
656 struct peer_group *group;
657
658 group = peer_group_lookup(bgp, arg);
659 if (!group) {
660 vty_out(vty, "%%BGP: No such peer-group %s\n", arg);
661 return CMD_WARNING;
662 }
663
664 for (ALL_LIST_ELEMENTS(group->peer, node, nnode, peer)) {
665 if (!peer->afc[afi][safi])
666 continue;
667
668 if (stype == BGP_CLEAR_SOFT_NONE)
669 ret = peer_clear(peer, NULL);
670 else
671 ret = peer_clear_soft(peer, afi, safi, stype);
672
673 if (ret < 0)
674 bgp_clear_vty_error(vty, peer, afi, safi, ret);
675 else
676 found = true;
677 }
678
679 if (!found)
680 vty_out(vty,
681 "%%BGP: No %s peer belonging to peer-group %s is configured\n",
682 afi_safi_print(afi, safi), arg);
683
684 return CMD_SUCCESS;
685 }
686
687 /* Clear all external (eBGP) neighbors. */
688 if (sort == clear_external) {
689 for (ALL_LIST_ELEMENTS(bgp->peer, node, nnode, peer)) {
690 if (peer->sort == BGP_PEER_IBGP)
691 continue;
692
693 if (!peer->afc[afi][safi])
694 continue;
695
696 if (stype == BGP_CLEAR_SOFT_NONE)
697 ret = peer_clear(peer, &nnode);
698 else
699 ret = peer_clear_soft(peer, afi, safi, stype);
700
701 if (ret < 0)
702 bgp_clear_vty_error(vty, peer, afi, safi, ret);
703 else
704 found = true;
705 }
706
707 if (!found)
708 vty_out(vty,
709 "%%BGP: No external %s peer is configured\n",
710 afi_safi_print(afi, safi));
711
712 return CMD_SUCCESS;
713 }
714
715 /* Clear all neighbors belonging to a specific AS. */
716 if (sort == clear_as) {
717 as_t as = strtoul(arg, NULL, 10);
718
719 for (ALL_LIST_ELEMENTS(bgp->peer, node, nnode, peer)) {
720 if (peer->as != as)
721 continue;
722
723 if (!peer->afc[afi][safi])
724 ret = BGP_ERR_AF_UNCONFIGURED;
725 else if (stype == BGP_CLEAR_SOFT_NONE)
726 ret = peer_clear(peer, &nnode);
727 else
728 ret = peer_clear_soft(peer, afi, safi, stype);
729
730 if (ret < 0)
731 bgp_clear_vty_error(vty, peer, afi, safi, ret);
732 else
733 found = true;
734 }
735
736 if (!found)
737 vty_out(vty,
738 "%%BGP: No %s peer is configured with AS %s\n",
739 afi_safi_print(afi, safi), arg);
740
741 return CMD_SUCCESS;
742 }
743
744 return CMD_SUCCESS;
745 }
746
747 static int bgp_clear_vty(struct vty *vty, const char *name, afi_t afi,
748 safi_t safi, enum clear_sort sort,
749 enum bgp_clear_type stype, const char *arg)
750 {
751 struct bgp *bgp;
752
753 /* BGP structure lookup. */
754 if (name) {
755 bgp = bgp_lookup_by_name(name);
756 if (bgp == NULL) {
757 vty_out(vty, "Can't find BGP instance %s\n", name);
758 return CMD_WARNING;
759 }
760 } else {
761 bgp = bgp_get_default();
762 if (bgp == NULL) {
763 vty_out(vty, "No BGP process is configured\n");
764 return CMD_WARNING;
765 }
766 }
767
768 return bgp_clear(vty, bgp, afi, safi, sort, stype, arg);
769 }
770
771 /* clear soft inbound */
772 static void bgp_clear_star_soft_in(struct vty *vty, const char *name)
773 {
774 afi_t afi;
775 safi_t safi;
776
777 FOREACH_AFI_SAFI (afi, safi)
778 bgp_clear_vty(vty, name, afi, safi, clear_all,
779 BGP_CLEAR_SOFT_IN, NULL);
780 }
781
782 /* clear soft outbound */
783 static void bgp_clear_star_soft_out(struct vty *vty, const char *name)
784 {
785 afi_t afi;
786 safi_t safi;
787
788 FOREACH_AFI_SAFI (afi, safi)
789 bgp_clear_vty(vty, name, afi, safi, clear_all,
790 BGP_CLEAR_SOFT_OUT, NULL);
791 }
792
793
794 #ifndef VTYSH_EXTRACT_PL
795 #include "bgpd/bgp_vty_clippy.c"
796 #endif
797
798 /* BGP global configuration. */
799 #if (CONFDATE > 20190601)
800 CPP_NOTICE("bgpd: time to remove deprecated bgp multiple-instance")
801 CPP_NOTICE("This includes BGP_OPT_MULTIPLE_INSTANCE")
802 #endif
803 DEFUN_HIDDEN (bgp_multiple_instance_func,
804 bgp_multiple_instance_cmd,
805 "bgp multiple-instance",
806 BGP_STR
807 "Enable bgp multiple instance\n")
808 {
809 bgp_option_set(BGP_OPT_MULTIPLE_INSTANCE);
810 return CMD_SUCCESS;
811 }
812
813 DEFUN_HIDDEN (no_bgp_multiple_instance,
814 no_bgp_multiple_instance_cmd,
815 "no bgp multiple-instance",
816 NO_STR
817 BGP_STR
818 "BGP multiple instance\n")
819 {
820 int ret;
821
822 vty_out(vty, "This config option is deprecated, and is scheduled for removal.\n");
823 vty_out(vty, "if you are using this please let the developers know\n");
824 zlog_info("Deprecated option: `bgp multiple-instance` being used");
825 ret = bgp_option_unset(BGP_OPT_MULTIPLE_INSTANCE);
826 if (ret < 0) {
827 vty_out(vty, "%% There are more than two BGP instances\n");
828 return CMD_WARNING_CONFIG_FAILED;
829 }
830 return CMD_SUCCESS;
831 }
832
833 DEFUN_HIDDEN (bgp_local_mac,
834 bgp_local_mac_cmd,
835 "bgp local-mac vni " CMD_VNI_RANGE " mac WORD seq (0-4294967295)",
836 BGP_STR
837 "Local MAC config\n"
838 "VxLAN Network Identifier\n"
839 "VNI number\n"
840 "local mac\n"
841 "mac address\n"
842 "mac-mobility sequence\n"
843 "seq number\n")
844 {
845 int rv;
846 vni_t vni;
847 struct ethaddr mac;
848 struct ipaddr ip;
849 uint32_t seq;
850 struct bgp *bgp;
851
852 vni = strtoul(argv[3]->arg, NULL, 10);
853 if (!prefix_str2mac(argv[5]->arg, &mac)) {
854 vty_out(vty, "%% Malformed MAC address\n");
855 return CMD_WARNING;
856 }
857 memset(&ip, 0, sizeof(ip));
858 seq = strtoul(argv[7]->arg, NULL, 10);
859
860 bgp = bgp_get_default();
861 if (!bgp) {
862 vty_out(vty, "Default BGP instance is not there\n");
863 return CMD_WARNING;
864 }
865
866 rv = bgp_evpn_local_macip_add(bgp, vni, &mac, &ip, 0 /* flags */, seq);
867 if (rv < 0) {
868 vty_out(vty, "Internal error\n");
869 return CMD_WARNING;
870 }
871
872 return CMD_SUCCESS;
873 }
874
875 DEFUN_HIDDEN (no_bgp_local_mac,
876 no_bgp_local_mac_cmd,
877 "no bgp local-mac vni " CMD_VNI_RANGE " mac WORD",
878 NO_STR
879 BGP_STR
880 "Local MAC config\n"
881 "VxLAN Network Identifier\n"
882 "VNI number\n"
883 "local mac\n"
884 "mac address\n")
885 {
886 int rv;
887 vni_t vni;
888 struct ethaddr mac;
889 struct ipaddr ip;
890 struct bgp *bgp;
891
892 vni = strtoul(argv[4]->arg, NULL, 10);
893 if (!prefix_str2mac(argv[6]->arg, &mac)) {
894 vty_out(vty, "%% Malformed MAC address\n");
895 return CMD_WARNING;
896 }
897 memset(&ip, 0, sizeof(ip));
898
899 bgp = bgp_get_default();
900 if (!bgp) {
901 vty_out(vty, "Default BGP instance is not there\n");
902 return CMD_WARNING;
903 }
904
905 rv = bgp_evpn_local_macip_del(bgp, vni, &mac, &ip, ZEBRA_NEIGH_ACTIVE);
906 if (rv < 0) {
907 vty_out(vty, "Internal error\n");
908 return CMD_WARNING;
909 }
910
911 return CMD_SUCCESS;
912 }
913
914 #if (CONFDATE > 20190601)
915 CPP_NOTICE("bgpd: time to remove deprecated cli bgp config-type cisco")
916 CPP_NOTICE("This includes BGP_OPT_CISCO_CONFIG")
917 #endif
918 DEFUN_HIDDEN (bgp_config_type,
919 bgp_config_type_cmd,
920 "bgp config-type <cisco|zebra>",
921 BGP_STR
922 "Configuration type\n"
923 "cisco\n"
924 "zebra\n")
925 {
926 int idx = 0;
927 if (argv_find(argv, argc, "cisco", &idx)) {
928 vty_out(vty, "This config option is deprecated, and is scheduled for removal.\n");
929 vty_out(vty, "if you are using this please let the developers know!\n");
930 zlog_info("Deprecated option: `bgp config-type cisco` being used");
931 bgp_option_set(BGP_OPT_CONFIG_CISCO);
932 } else
933 bgp_option_unset(BGP_OPT_CONFIG_CISCO);
934
935 return CMD_SUCCESS;
936 }
937
938 DEFUN_HIDDEN (no_bgp_config_type,
939 no_bgp_config_type_cmd,
940 "no bgp config-type [<cisco|zebra>]",
941 NO_STR
942 BGP_STR
943 "Display configuration type\n"
944 "cisco\n"
945 "zebra\n")
946 {
947 bgp_option_unset(BGP_OPT_CONFIG_CISCO);
948 return CMD_SUCCESS;
949 }
950
951
952 DEFUN (no_synchronization,
953 no_synchronization_cmd,
954 "no synchronization",
955 NO_STR
956 "Perform IGP synchronization\n")
957 {
958 return CMD_SUCCESS;
959 }
960
961 DEFUN (no_auto_summary,
962 no_auto_summary_cmd,
963 "no auto-summary",
964 NO_STR
965 "Enable automatic network number summarization\n")
966 {
967 return CMD_SUCCESS;
968 }
969
970 /* "router bgp" commands. */
971 DEFUN_NOSH (router_bgp,
972 router_bgp_cmd,
973 "router bgp [(1-4294967295) [<view|vrf> VIEWVRFNAME]]",
974 ROUTER_STR
975 BGP_STR
976 AS_STR
977 BGP_INSTANCE_HELP_STR)
978 {
979 int idx_asn = 2;
980 int idx_view_vrf = 3;
981 int idx_vrf = 4;
982 int is_new_bgp = 0;
983 int ret;
984 as_t as;
985 struct bgp *bgp;
986 const char *name = NULL;
987 enum bgp_instance_type inst_type;
988
989 // "router bgp" without an ASN
990 if (argc == 2) {
991 // Pending: Make VRF option available for ASN less config
992 bgp = bgp_get_default();
993
994 if (bgp == NULL) {
995 vty_out(vty, "%% No BGP process is configured\n");
996 return CMD_WARNING_CONFIG_FAILED;
997 }
998
999 if (listcount(bm->bgp) > 1) {
1000 vty_out(vty, "%% Please specify ASN and VRF\n");
1001 return CMD_WARNING_CONFIG_FAILED;
1002 }
1003 }
1004
1005 // "router bgp X"
1006 else {
1007 as = strtoul(argv[idx_asn]->arg, NULL, 10);
1008
1009 inst_type = BGP_INSTANCE_TYPE_DEFAULT;
1010 if (argc > 3) {
1011 name = argv[idx_vrf]->arg;
1012
1013 if (!strcmp(argv[idx_view_vrf]->text, "vrf")) {
1014 if (strmatch(name, VRF_DEFAULT_NAME))
1015 name = NULL;
1016 else
1017 inst_type = BGP_INSTANCE_TYPE_VRF;
1018 } else if (!strcmp(argv[idx_view_vrf]->text, "view"))
1019 inst_type = BGP_INSTANCE_TYPE_VIEW;
1020 }
1021
1022 if (inst_type == BGP_INSTANCE_TYPE_DEFAULT)
1023 is_new_bgp = (bgp_lookup(as, name) == NULL);
1024
1025 ret = bgp_get(&bgp, &as, name, inst_type);
1026 switch (ret) {
1027 case BGP_ERR_MULTIPLE_INSTANCE_NOT_SET:
1028 vty_out(vty,
1029 "Please specify 'bgp multiple-instance' first\n");
1030 return CMD_WARNING_CONFIG_FAILED;
1031 case BGP_ERR_AS_MISMATCH:
1032 vty_out(vty, "BGP is already running; AS is %u\n", as);
1033 return CMD_WARNING_CONFIG_FAILED;
1034 case BGP_ERR_INSTANCE_MISMATCH:
1035 vty_out(vty,
1036 "BGP instance name and AS number mismatch\n");
1037 vty_out(vty,
1038 "BGP instance is already running; AS is %u\n",
1039 as);
1040 return CMD_WARNING_CONFIG_FAILED;
1041 }
1042
1043 /*
1044 * If we just instantiated the default instance, complete
1045 * any pending VRF-VPN leaking that was configured via
1046 * earlier "router bgp X vrf FOO" blocks.
1047 */
1048 if (is_new_bgp && inst_type == BGP_INSTANCE_TYPE_DEFAULT)
1049 vpn_leak_postchange_all();
1050
1051 /* Pending: handle when user tries to change a view to vrf n vv.
1052 */
1053 }
1054
1055 /* unset the auto created flag as the user config is now present */
1056 UNSET_FLAG(bgp->vrf_flags, BGP_VRF_AUTO);
1057 VTY_PUSH_CONTEXT(BGP_NODE, bgp);
1058
1059 return CMD_SUCCESS;
1060 }
1061
1062 /* "no router bgp" commands. */
1063 DEFUN (no_router_bgp,
1064 no_router_bgp_cmd,
1065 "no router bgp [(1-4294967295) [<view|vrf> VIEWVRFNAME]]",
1066 NO_STR
1067 ROUTER_STR
1068 BGP_STR
1069 AS_STR
1070 BGP_INSTANCE_HELP_STR)
1071 {
1072 int idx_asn = 3;
1073 int idx_vrf = 5;
1074 as_t as;
1075 struct bgp *bgp;
1076 const char *name = NULL;
1077
1078 // "no router bgp" without an ASN
1079 if (argc == 3) {
1080 // Pending: Make VRF option available for ASN less config
1081 bgp = bgp_get_default();
1082
1083 if (bgp == NULL) {
1084 vty_out(vty, "%% No BGP process is configured\n");
1085 return CMD_WARNING_CONFIG_FAILED;
1086 }
1087
1088 if (listcount(bm->bgp) > 1) {
1089 vty_out(vty, "%% Please specify ASN and VRF\n");
1090 return CMD_WARNING_CONFIG_FAILED;
1091 }
1092
1093 if (bgp->l3vni) {
1094 vty_out(vty, "%% Please unconfigure l3vni %u",
1095 bgp->l3vni);
1096 return CMD_WARNING_CONFIG_FAILED;
1097 }
1098 } else {
1099 as = strtoul(argv[idx_asn]->arg, NULL, 10);
1100
1101 if (argc > 4)
1102 name = argv[idx_vrf]->arg;
1103
1104 /* Lookup bgp structure. */
1105 bgp = bgp_lookup(as, name);
1106 if (!bgp) {
1107 vty_out(vty, "%% Can't find BGP instance\n");
1108 return CMD_WARNING_CONFIG_FAILED;
1109 }
1110
1111 if (bgp->l3vni) {
1112 vty_out(vty, "%% Please unconfigure l3vni %u",
1113 bgp->l3vni);
1114 return CMD_WARNING_CONFIG_FAILED;
1115 }
1116 }
1117
1118 bgp_delete(bgp);
1119
1120 return CMD_SUCCESS;
1121 }
1122
1123
1124 /* BGP router-id. */
1125
1126 DEFPY (bgp_router_id,
1127 bgp_router_id_cmd,
1128 "bgp router-id A.B.C.D",
1129 BGP_STR
1130 "Override configured router identifier\n"
1131 "Manually configured router identifier\n")
1132 {
1133 VTY_DECLVAR_CONTEXT(bgp, bgp);
1134 bgp_router_id_static_set(bgp, router_id);
1135 return CMD_SUCCESS;
1136 }
1137
1138 DEFPY (no_bgp_router_id,
1139 no_bgp_router_id_cmd,
1140 "no bgp router-id [A.B.C.D]",
1141 NO_STR
1142 BGP_STR
1143 "Override configured router identifier\n"
1144 "Manually configured router identifier\n")
1145 {
1146 VTY_DECLVAR_CONTEXT(bgp, bgp);
1147
1148 if (router_id_str) {
1149 if (!IPV4_ADDR_SAME(&bgp->router_id_static, &router_id)) {
1150 vty_out(vty, "%% BGP router-id doesn't match\n");
1151 return CMD_WARNING_CONFIG_FAILED;
1152 }
1153 }
1154
1155 router_id.s_addr = 0;
1156 bgp_router_id_static_set(bgp, router_id);
1157
1158 return CMD_SUCCESS;
1159 }
1160
1161
1162 /* BGP Cluster ID. */
1163 DEFUN (bgp_cluster_id,
1164 bgp_cluster_id_cmd,
1165 "bgp cluster-id <A.B.C.D|(1-4294967295)>",
1166 BGP_STR
1167 "Configure Route-Reflector Cluster-id\n"
1168 "Route-Reflector Cluster-id in IP address format\n"
1169 "Route-Reflector Cluster-id as 32 bit quantity\n")
1170 {
1171 VTY_DECLVAR_CONTEXT(bgp, bgp);
1172 int idx_ipv4 = 2;
1173 int ret;
1174 struct in_addr cluster;
1175
1176 ret = inet_aton(argv[idx_ipv4]->arg, &cluster);
1177 if (!ret) {
1178 vty_out(vty, "%% Malformed bgp cluster identifier\n");
1179 return CMD_WARNING_CONFIG_FAILED;
1180 }
1181
1182 bgp_cluster_id_set(bgp, &cluster);
1183 bgp_clear_star_soft_out(vty, bgp->name);
1184
1185 return CMD_SUCCESS;
1186 }
1187
1188 DEFUN (no_bgp_cluster_id,
1189 no_bgp_cluster_id_cmd,
1190 "no bgp cluster-id [<A.B.C.D|(1-4294967295)>]",
1191 NO_STR
1192 BGP_STR
1193 "Configure Route-Reflector Cluster-id\n"
1194 "Route-Reflector Cluster-id in IP address format\n"
1195 "Route-Reflector Cluster-id as 32 bit quantity\n")
1196 {
1197 VTY_DECLVAR_CONTEXT(bgp, bgp);
1198 bgp_cluster_id_unset(bgp);
1199 bgp_clear_star_soft_out(vty, bgp->name);
1200
1201 return CMD_SUCCESS;
1202 }
1203
1204 DEFUN (bgp_confederation_identifier,
1205 bgp_confederation_identifier_cmd,
1206 "bgp confederation identifier (1-4294967295)",
1207 "BGP specific commands\n"
1208 "AS confederation parameters\n"
1209 "AS number\n"
1210 "Set routing domain confederation AS\n")
1211 {
1212 VTY_DECLVAR_CONTEXT(bgp, bgp);
1213 int idx_number = 3;
1214 as_t as;
1215
1216 as = strtoul(argv[idx_number]->arg, NULL, 10);
1217
1218 bgp_confederation_id_set(bgp, as);
1219
1220 return CMD_SUCCESS;
1221 }
1222
1223 DEFUN (no_bgp_confederation_identifier,
1224 no_bgp_confederation_identifier_cmd,
1225 "no bgp confederation identifier [(1-4294967295)]",
1226 NO_STR
1227 "BGP specific commands\n"
1228 "AS confederation parameters\n"
1229 "AS number\n"
1230 "Set routing domain confederation AS\n")
1231 {
1232 VTY_DECLVAR_CONTEXT(bgp, bgp);
1233 bgp_confederation_id_unset(bgp);
1234
1235 return CMD_SUCCESS;
1236 }
1237
1238 DEFUN (bgp_confederation_peers,
1239 bgp_confederation_peers_cmd,
1240 "bgp confederation peers (1-4294967295)...",
1241 "BGP specific commands\n"
1242 "AS confederation parameters\n"
1243 "Peer ASs in BGP confederation\n"
1244 AS_STR)
1245 {
1246 VTY_DECLVAR_CONTEXT(bgp, bgp);
1247 int idx_asn = 3;
1248 as_t as;
1249 int i;
1250
1251 for (i = idx_asn; i < argc; i++) {
1252 as = strtoul(argv[i]->arg, NULL, 10);
1253
1254 if (bgp->as == as) {
1255 vty_out(vty,
1256 "%% Local member-AS not allowed in confed peer list\n");
1257 continue;
1258 }
1259
1260 bgp_confederation_peers_add(bgp, as);
1261 }
1262 return CMD_SUCCESS;
1263 }
1264
1265 DEFUN (no_bgp_confederation_peers,
1266 no_bgp_confederation_peers_cmd,
1267 "no bgp confederation peers (1-4294967295)...",
1268 NO_STR
1269 "BGP specific commands\n"
1270 "AS confederation parameters\n"
1271 "Peer ASs in BGP confederation\n"
1272 AS_STR)
1273 {
1274 VTY_DECLVAR_CONTEXT(bgp, bgp);
1275 int idx_asn = 4;
1276 as_t as;
1277 int i;
1278
1279 for (i = idx_asn; i < argc; i++) {
1280 as = strtoul(argv[i]->arg, NULL, 10);
1281
1282 bgp_confederation_peers_remove(bgp, as);
1283 }
1284 return CMD_SUCCESS;
1285 }
1286
1287 /**
1288 * Central routine for maximum-paths configuration.
1289 * @peer_type: BGP_PEER_EBGP or BGP_PEER_IBGP
1290 * @set: 1 for setting values, 0 for removing the max-paths config.
1291 */
1292 static int bgp_maxpaths_config_vty(struct vty *vty, int peer_type,
1293 const char *mpaths, uint16_t options,
1294 int set)
1295 {
1296 VTY_DECLVAR_CONTEXT(bgp, bgp);
1297 uint16_t maxpaths = 0;
1298 int ret;
1299 afi_t afi;
1300 safi_t safi;
1301
1302 afi = bgp_node_afi(vty);
1303 safi = bgp_node_safi(vty);
1304
1305 if (set) {
1306 maxpaths = strtol(mpaths, NULL, 10);
1307 if (maxpaths > multipath_num) {
1308 vty_out(vty,
1309 "%% Maxpaths Specified: %d is > than multipath num specified on bgp command line %d",
1310 maxpaths, multipath_num);
1311 return CMD_WARNING_CONFIG_FAILED;
1312 }
1313 ret = bgp_maximum_paths_set(bgp, afi, safi, peer_type, maxpaths,
1314 options);
1315 } else
1316 ret = bgp_maximum_paths_unset(bgp, afi, safi, peer_type);
1317
1318 if (ret < 0) {
1319 vty_out(vty,
1320 "%% Failed to %sset maximum-paths %s %u for afi %u, safi %u\n",
1321 (set == 1) ? "" : "un",
1322 (peer_type == BGP_PEER_EBGP) ? "ebgp" : "ibgp",
1323 maxpaths, afi, safi);
1324 return CMD_WARNING_CONFIG_FAILED;
1325 }
1326
1327 bgp_recalculate_all_bestpaths(bgp);
1328
1329 return CMD_SUCCESS;
1330 }
1331
1332 DEFUN (bgp_maxmed_admin,
1333 bgp_maxmed_admin_cmd,
1334 "bgp max-med administrative ",
1335 BGP_STR
1336 "Advertise routes with max-med\n"
1337 "Administratively applied, for an indefinite period\n")
1338 {
1339 VTY_DECLVAR_CONTEXT(bgp, bgp);
1340
1341 bgp->v_maxmed_admin = 1;
1342 bgp->maxmed_admin_value = BGP_MAXMED_VALUE_DEFAULT;
1343
1344 bgp_maxmed_update(bgp);
1345
1346 return CMD_SUCCESS;
1347 }
1348
1349 DEFUN (bgp_maxmed_admin_medv,
1350 bgp_maxmed_admin_medv_cmd,
1351 "bgp max-med administrative (0-4294967295)",
1352 BGP_STR
1353 "Advertise routes with max-med\n"
1354 "Administratively applied, for an indefinite period\n"
1355 "Max MED value to be used\n")
1356 {
1357 VTY_DECLVAR_CONTEXT(bgp, bgp);
1358 int idx_number = 3;
1359
1360 bgp->v_maxmed_admin = 1;
1361 bgp->maxmed_admin_value = strtoul(argv[idx_number]->arg, NULL, 10);
1362
1363 bgp_maxmed_update(bgp);
1364
1365 return CMD_SUCCESS;
1366 }
1367
1368 DEFUN (no_bgp_maxmed_admin,
1369 no_bgp_maxmed_admin_cmd,
1370 "no bgp max-med administrative [(0-4294967295)]",
1371 NO_STR
1372 BGP_STR
1373 "Advertise routes with max-med\n"
1374 "Administratively applied, for an indefinite period\n"
1375 "Max MED value to be used\n")
1376 {
1377 VTY_DECLVAR_CONTEXT(bgp, bgp);
1378 bgp->v_maxmed_admin = BGP_MAXMED_ADMIN_UNCONFIGURED;
1379 bgp->maxmed_admin_value = BGP_MAXMED_VALUE_DEFAULT;
1380 bgp_maxmed_update(bgp);
1381
1382 return CMD_SUCCESS;
1383 }
1384
1385 DEFUN (bgp_maxmed_onstartup,
1386 bgp_maxmed_onstartup_cmd,
1387 "bgp max-med on-startup (5-86400) [(0-4294967295)]",
1388 BGP_STR
1389 "Advertise routes with max-med\n"
1390 "Effective on a startup\n"
1391 "Time (seconds) period for max-med\n"
1392 "Max MED value to be used\n")
1393 {
1394 VTY_DECLVAR_CONTEXT(bgp, bgp);
1395 int idx = 0;
1396
1397 argv_find(argv, argc, "(5-86400)", &idx);
1398 bgp->v_maxmed_onstartup = strtoul(argv[idx]->arg, NULL, 10);
1399 if (argv_find(argv, argc, "(0-4294967295)", &idx))
1400 bgp->maxmed_onstartup_value = strtoul(argv[idx]->arg, NULL, 10);
1401 else
1402 bgp->maxmed_onstartup_value = BGP_MAXMED_VALUE_DEFAULT;
1403
1404 bgp_maxmed_update(bgp);
1405
1406 return CMD_SUCCESS;
1407 }
1408
1409 DEFUN (no_bgp_maxmed_onstartup,
1410 no_bgp_maxmed_onstartup_cmd,
1411 "no bgp max-med on-startup [(5-86400) [(0-4294967295)]]",
1412 NO_STR
1413 BGP_STR
1414 "Advertise routes with max-med\n"
1415 "Effective on a startup\n"
1416 "Time (seconds) period for max-med\n"
1417 "Max MED value to be used\n")
1418 {
1419 VTY_DECLVAR_CONTEXT(bgp, bgp);
1420
1421 /* Cancel max-med onstartup if its on */
1422 if (bgp->t_maxmed_onstartup) {
1423 THREAD_TIMER_OFF(bgp->t_maxmed_onstartup);
1424 bgp->maxmed_onstartup_over = 1;
1425 }
1426
1427 bgp->v_maxmed_onstartup = BGP_MAXMED_ONSTARTUP_UNCONFIGURED;
1428 bgp->maxmed_onstartup_value = BGP_MAXMED_VALUE_DEFAULT;
1429
1430 bgp_maxmed_update(bgp);
1431
1432 return CMD_SUCCESS;
1433 }
1434
1435 static int bgp_update_delay_config_vty(struct vty *vty, const char *delay,
1436 const char *wait)
1437 {
1438 VTY_DECLVAR_CONTEXT(bgp, bgp);
1439 uint16_t update_delay;
1440 uint16_t establish_wait;
1441
1442 update_delay = strtoul(delay, NULL, 10);
1443
1444 if (!wait) /* update-delay <delay> */
1445 {
1446 bgp->v_update_delay = update_delay;
1447 bgp->v_establish_wait = bgp->v_update_delay;
1448 return CMD_SUCCESS;
1449 }
1450
1451 /* update-delay <delay> <establish-wait> */
1452 establish_wait = atoi(wait);
1453 if (update_delay < establish_wait) {
1454 vty_out(vty,
1455 "%%Failed: update-delay less than the establish-wait!\n");
1456 return CMD_WARNING_CONFIG_FAILED;
1457 }
1458
1459 bgp->v_update_delay = update_delay;
1460 bgp->v_establish_wait = establish_wait;
1461
1462 return CMD_SUCCESS;
1463 }
1464
1465 static int bgp_update_delay_deconfig_vty(struct vty *vty)
1466 {
1467 VTY_DECLVAR_CONTEXT(bgp, bgp);
1468
1469 bgp->v_update_delay = BGP_UPDATE_DELAY_DEF;
1470 bgp->v_establish_wait = bgp->v_update_delay;
1471
1472 return CMD_SUCCESS;
1473 }
1474
1475 void bgp_config_write_update_delay(struct vty *vty, struct bgp *bgp)
1476 {
1477 if (bgp->v_update_delay != BGP_UPDATE_DELAY_DEF) {
1478 vty_out(vty, " update-delay %d", bgp->v_update_delay);
1479 if (bgp->v_update_delay != bgp->v_establish_wait)
1480 vty_out(vty, " %d", bgp->v_establish_wait);
1481 vty_out(vty, "\n");
1482 }
1483 }
1484
1485
1486 /* Update-delay configuration */
1487 DEFUN (bgp_update_delay,
1488 bgp_update_delay_cmd,
1489 "update-delay (0-3600)",
1490 "Force initial delay for best-path and updates\n"
1491 "Seconds\n")
1492 {
1493 int idx_number = 1;
1494 return bgp_update_delay_config_vty(vty, argv[idx_number]->arg, NULL);
1495 }
1496
1497 DEFUN (bgp_update_delay_establish_wait,
1498 bgp_update_delay_establish_wait_cmd,
1499 "update-delay (0-3600) (1-3600)",
1500 "Force initial delay for best-path and updates\n"
1501 "Seconds\n"
1502 "Seconds\n")
1503 {
1504 int idx_number = 1;
1505 int idx_number_2 = 2;
1506 return bgp_update_delay_config_vty(vty, argv[idx_number]->arg,
1507 argv[idx_number_2]->arg);
1508 }
1509
1510 /* Update-delay deconfiguration */
1511 DEFUN (no_bgp_update_delay,
1512 no_bgp_update_delay_cmd,
1513 "no update-delay [(0-3600) [(1-3600)]]",
1514 NO_STR
1515 "Force initial delay for best-path and updates\n"
1516 "Seconds\n"
1517 "Seconds\n")
1518 {
1519 return bgp_update_delay_deconfig_vty(vty);
1520 }
1521
1522
1523 static int bgp_wpkt_quanta_config_vty(struct vty *vty, const char *num,
1524 char set)
1525 {
1526 VTY_DECLVAR_CONTEXT(bgp, bgp);
1527
1528 if (set) {
1529 uint32_t quanta = strtoul(num, NULL, 10);
1530 atomic_store_explicit(&bgp->wpkt_quanta, quanta,
1531 memory_order_relaxed);
1532 } else {
1533 atomic_store_explicit(&bgp->wpkt_quanta, BGP_WRITE_PACKET_MAX,
1534 memory_order_relaxed);
1535 }
1536
1537 return CMD_SUCCESS;
1538 }
1539
1540 static int bgp_rpkt_quanta_config_vty(struct vty *vty, const char *num,
1541 char set)
1542 {
1543 VTY_DECLVAR_CONTEXT(bgp, bgp);
1544
1545 if (set) {
1546 uint32_t quanta = strtoul(num, NULL, 10);
1547 atomic_store_explicit(&bgp->rpkt_quanta, quanta,
1548 memory_order_relaxed);
1549 } else {
1550 atomic_store_explicit(&bgp->rpkt_quanta, BGP_READ_PACKET_MAX,
1551 memory_order_relaxed);
1552 }
1553
1554 return CMD_SUCCESS;
1555 }
1556
1557 void bgp_config_write_wpkt_quanta(struct vty *vty, struct bgp *bgp)
1558 {
1559 uint32_t quanta =
1560 atomic_load_explicit(&bgp->wpkt_quanta, memory_order_relaxed);
1561 if (quanta != BGP_WRITE_PACKET_MAX)
1562 vty_out(vty, " write-quanta %d\n", quanta);
1563 }
1564
1565 void bgp_config_write_rpkt_quanta(struct vty *vty, struct bgp *bgp)
1566 {
1567 uint32_t quanta =
1568 atomic_load_explicit(&bgp->rpkt_quanta, memory_order_relaxed);
1569 if (quanta != BGP_READ_PACKET_MAX)
1570 vty_out(vty, " read-quanta %d\n", quanta);
1571 }
1572
1573 /* Packet quanta configuration */
1574 DEFUN (bgp_wpkt_quanta,
1575 bgp_wpkt_quanta_cmd,
1576 "write-quanta (1-10)",
1577 "How many packets to write to peer socket per run\n"
1578 "Number of packets\n")
1579 {
1580 int idx_number = 1;
1581 return bgp_wpkt_quanta_config_vty(vty, argv[idx_number]->arg, 1);
1582 }
1583
1584 DEFUN (no_bgp_wpkt_quanta,
1585 no_bgp_wpkt_quanta_cmd,
1586 "no write-quanta (1-10)",
1587 NO_STR
1588 "How many packets to write to peer socket per I/O cycle\n"
1589 "Number of packets\n")
1590 {
1591 int idx_number = 2;
1592 return bgp_wpkt_quanta_config_vty(vty, argv[idx_number]->arg, 0);
1593 }
1594
1595 DEFUN (bgp_rpkt_quanta,
1596 bgp_rpkt_quanta_cmd,
1597 "read-quanta (1-10)",
1598 "How many packets to read from peer socket per I/O cycle\n"
1599 "Number of packets\n")
1600 {
1601 int idx_number = 1;
1602 return bgp_rpkt_quanta_config_vty(vty, argv[idx_number]->arg, 1);
1603 }
1604
1605 DEFUN (no_bgp_rpkt_quanta,
1606 no_bgp_rpkt_quanta_cmd,
1607 "no read-quanta (1-10)",
1608 NO_STR
1609 "How many packets to read from peer socket per I/O cycle\n"
1610 "Number of packets\n")
1611 {
1612 int idx_number = 2;
1613 return bgp_rpkt_quanta_config_vty(vty, argv[idx_number]->arg, 0);
1614 }
1615
1616 void bgp_config_write_coalesce_time(struct vty *vty, struct bgp *bgp)
1617 {
1618 if (!bgp->heuristic_coalesce)
1619 vty_out(vty, " coalesce-time %u\n", bgp->coalesce_time);
1620 }
1621
1622
1623 DEFUN (bgp_coalesce_time,
1624 bgp_coalesce_time_cmd,
1625 "coalesce-time (0-4294967295)",
1626 "Subgroup coalesce timer\n"
1627 "Subgroup coalesce timer value (in ms)\n")
1628 {
1629 VTY_DECLVAR_CONTEXT(bgp, bgp);
1630
1631 int idx = 0;
1632 argv_find(argv, argc, "(0-4294967295)", &idx);
1633 bgp->heuristic_coalesce = false;
1634 bgp->coalesce_time = strtoul(argv[idx]->arg, NULL, 10);
1635 return CMD_SUCCESS;
1636 }
1637
1638 DEFUN (no_bgp_coalesce_time,
1639 no_bgp_coalesce_time_cmd,
1640 "no coalesce-time (0-4294967295)",
1641 NO_STR
1642 "Subgroup coalesce timer\n"
1643 "Subgroup coalesce timer value (in ms)\n")
1644 {
1645 VTY_DECLVAR_CONTEXT(bgp, bgp);
1646
1647 bgp->heuristic_coalesce = true;
1648 bgp->coalesce_time = BGP_DEFAULT_SUBGROUP_COALESCE_TIME;
1649 return CMD_SUCCESS;
1650 }
1651
1652 /* Maximum-paths configuration */
1653 DEFUN (bgp_maxpaths,
1654 bgp_maxpaths_cmd,
1655 "maximum-paths " CMD_RANGE_STR(1, MULTIPATH_NUM),
1656 "Forward packets over multiple paths\n"
1657 "Number of paths\n")
1658 {
1659 int idx_number = 1;
1660 return bgp_maxpaths_config_vty(vty, BGP_PEER_EBGP,
1661 argv[idx_number]->arg, 0, 1);
1662 }
1663
1664 ALIAS_HIDDEN(bgp_maxpaths, bgp_maxpaths_hidden_cmd,
1665 "maximum-paths " CMD_RANGE_STR(1, MULTIPATH_NUM),
1666 "Forward packets over multiple paths\n"
1667 "Number of paths\n")
1668
1669 DEFUN (bgp_maxpaths_ibgp,
1670 bgp_maxpaths_ibgp_cmd,
1671 "maximum-paths ibgp " CMD_RANGE_STR(1, MULTIPATH_NUM),
1672 "Forward packets over multiple paths\n"
1673 "iBGP-multipath\n"
1674 "Number of paths\n")
1675 {
1676 int idx_number = 2;
1677 return bgp_maxpaths_config_vty(vty, BGP_PEER_IBGP,
1678 argv[idx_number]->arg, 0, 1);
1679 }
1680
1681 ALIAS_HIDDEN(bgp_maxpaths_ibgp, bgp_maxpaths_ibgp_hidden_cmd,
1682 "maximum-paths ibgp " CMD_RANGE_STR(1, MULTIPATH_NUM),
1683 "Forward packets over multiple paths\n"
1684 "iBGP-multipath\n"
1685 "Number of paths\n")
1686
1687 DEFUN (bgp_maxpaths_ibgp_cluster,
1688 bgp_maxpaths_ibgp_cluster_cmd,
1689 "maximum-paths ibgp " CMD_RANGE_STR(1, MULTIPATH_NUM) " equal-cluster-length",
1690 "Forward packets over multiple paths\n"
1691 "iBGP-multipath\n"
1692 "Number of paths\n"
1693 "Match the cluster length\n")
1694 {
1695 int idx_number = 2;
1696 return bgp_maxpaths_config_vty(
1697 vty, BGP_PEER_IBGP, argv[idx_number]->arg,
1698 BGP_FLAG_IBGP_MULTIPATH_SAME_CLUSTERLEN, 1);
1699 }
1700
1701 ALIAS_HIDDEN(bgp_maxpaths_ibgp_cluster, bgp_maxpaths_ibgp_cluster_hidden_cmd,
1702 "maximum-paths ibgp " CMD_RANGE_STR(
1703 1, MULTIPATH_NUM) " equal-cluster-length",
1704 "Forward packets over multiple paths\n"
1705 "iBGP-multipath\n"
1706 "Number of paths\n"
1707 "Match the cluster length\n")
1708
1709 DEFUN (no_bgp_maxpaths,
1710 no_bgp_maxpaths_cmd,
1711 "no maximum-paths [" CMD_RANGE_STR(1, MULTIPATH_NUM) "]",
1712 NO_STR
1713 "Forward packets over multiple paths\n"
1714 "Number of paths\n")
1715 {
1716 return bgp_maxpaths_config_vty(vty, BGP_PEER_EBGP, NULL, 0, 0);
1717 }
1718
1719 ALIAS_HIDDEN(no_bgp_maxpaths, no_bgp_maxpaths_hidden_cmd,
1720 "no maximum-paths [" CMD_RANGE_STR(1, MULTIPATH_NUM) "]", NO_STR
1721 "Forward packets over multiple paths\n"
1722 "Number of paths\n")
1723
1724 DEFUN (no_bgp_maxpaths_ibgp,
1725 no_bgp_maxpaths_ibgp_cmd,
1726 "no maximum-paths ibgp [" CMD_RANGE_STR(1, MULTIPATH_NUM) " [equal-cluster-length]]",
1727 NO_STR
1728 "Forward packets over multiple paths\n"
1729 "iBGP-multipath\n"
1730 "Number of paths\n"
1731 "Match the cluster length\n")
1732 {
1733 return bgp_maxpaths_config_vty(vty, BGP_PEER_IBGP, NULL, 0, 0);
1734 }
1735
1736 ALIAS_HIDDEN(no_bgp_maxpaths_ibgp, no_bgp_maxpaths_ibgp_hidden_cmd,
1737 "no maximum-paths ibgp [" CMD_RANGE_STR(
1738 1, MULTIPATH_NUM) " [equal-cluster-length]]",
1739 NO_STR
1740 "Forward packets over multiple paths\n"
1741 "iBGP-multipath\n"
1742 "Number of paths\n"
1743 "Match the cluster length\n")
1744
1745 void bgp_config_write_maxpaths(struct vty *vty, struct bgp *bgp, afi_t afi,
1746 safi_t safi)
1747 {
1748 if (bgp->maxpaths[afi][safi].maxpaths_ebgp != MULTIPATH_NUM) {
1749 vty_out(vty, " maximum-paths %d\n",
1750 bgp->maxpaths[afi][safi].maxpaths_ebgp);
1751 }
1752
1753 if (bgp->maxpaths[afi][safi].maxpaths_ibgp != MULTIPATH_NUM) {
1754 vty_out(vty, " maximum-paths ibgp %d",
1755 bgp->maxpaths[afi][safi].maxpaths_ibgp);
1756 if (CHECK_FLAG(bgp->maxpaths[afi][safi].ibgp_flags,
1757 BGP_FLAG_IBGP_MULTIPATH_SAME_CLUSTERLEN))
1758 vty_out(vty, " equal-cluster-length");
1759 vty_out(vty, "\n");
1760 }
1761 }
1762
1763 /* BGP timers. */
1764
1765 DEFUN (bgp_timers,
1766 bgp_timers_cmd,
1767 "timers bgp (0-65535) (0-65535)",
1768 "Adjust routing timers\n"
1769 "BGP timers\n"
1770 "Keepalive interval\n"
1771 "Holdtime\n")
1772 {
1773 VTY_DECLVAR_CONTEXT(bgp, bgp);
1774 int idx_number = 2;
1775 int idx_number_2 = 3;
1776 unsigned long keepalive = 0;
1777 unsigned long holdtime = 0;
1778
1779 keepalive = strtoul(argv[idx_number]->arg, NULL, 10);
1780 holdtime = strtoul(argv[idx_number_2]->arg, NULL, 10);
1781
1782 /* Holdtime value check. */
1783 if (holdtime < 3 && holdtime != 0) {
1784 vty_out(vty,
1785 "%% hold time value must be either 0 or greater than 3\n");
1786 return CMD_WARNING_CONFIG_FAILED;
1787 }
1788
1789 bgp_timers_set(bgp, keepalive, holdtime);
1790
1791 return CMD_SUCCESS;
1792 }
1793
1794 DEFUN (no_bgp_timers,
1795 no_bgp_timers_cmd,
1796 "no timers bgp [(0-65535) (0-65535)]",
1797 NO_STR
1798 "Adjust routing timers\n"
1799 "BGP timers\n"
1800 "Keepalive interval\n"
1801 "Holdtime\n")
1802 {
1803 VTY_DECLVAR_CONTEXT(bgp, bgp);
1804 bgp_timers_unset(bgp);
1805
1806 return CMD_SUCCESS;
1807 }
1808
1809
1810 DEFUN (bgp_client_to_client_reflection,
1811 bgp_client_to_client_reflection_cmd,
1812 "bgp client-to-client reflection",
1813 "BGP specific commands\n"
1814 "Configure client to client route reflection\n"
1815 "reflection of routes allowed\n")
1816 {
1817 VTY_DECLVAR_CONTEXT(bgp, bgp);
1818 bgp_flag_unset(bgp, BGP_FLAG_NO_CLIENT_TO_CLIENT);
1819 bgp_clear_star_soft_out(vty, bgp->name);
1820
1821 return CMD_SUCCESS;
1822 }
1823
1824 DEFUN (no_bgp_client_to_client_reflection,
1825 no_bgp_client_to_client_reflection_cmd,
1826 "no bgp client-to-client reflection",
1827 NO_STR
1828 "BGP specific commands\n"
1829 "Configure client to client route reflection\n"
1830 "reflection of routes allowed\n")
1831 {
1832 VTY_DECLVAR_CONTEXT(bgp, bgp);
1833 bgp_flag_set(bgp, BGP_FLAG_NO_CLIENT_TO_CLIENT);
1834 bgp_clear_star_soft_out(vty, bgp->name);
1835
1836 return CMD_SUCCESS;
1837 }
1838
1839 /* "bgp always-compare-med" configuration. */
1840 DEFUN (bgp_always_compare_med,
1841 bgp_always_compare_med_cmd,
1842 "bgp always-compare-med",
1843 "BGP specific commands\n"
1844 "Allow comparing MED from different neighbors\n")
1845 {
1846 VTY_DECLVAR_CONTEXT(bgp, bgp);
1847 bgp_flag_set(bgp, BGP_FLAG_ALWAYS_COMPARE_MED);
1848 bgp_recalculate_all_bestpaths(bgp);
1849
1850 return CMD_SUCCESS;
1851 }
1852
1853 DEFUN (no_bgp_always_compare_med,
1854 no_bgp_always_compare_med_cmd,
1855 "no bgp always-compare-med",
1856 NO_STR
1857 "BGP specific commands\n"
1858 "Allow comparing MED from different neighbors\n")
1859 {
1860 VTY_DECLVAR_CONTEXT(bgp, bgp);
1861 bgp_flag_unset(bgp, BGP_FLAG_ALWAYS_COMPARE_MED);
1862 bgp_recalculate_all_bestpaths(bgp);
1863
1864 return CMD_SUCCESS;
1865 }
1866
1867
1868 DEFUN(bgp_ebgp_requires_policy, bgp_ebgp_requires_policy_cmd,
1869 "bgp ebgp-requires-policy",
1870 "BGP specific commands\n"
1871 "Require in and out policy for eBGP peers (RFC8212)\n")
1872 {
1873 VTY_DECLVAR_CONTEXT(bgp, bgp);
1874 bgp->ebgp_requires_policy = DEFAULT_EBGP_POLICY_ENABLED;
1875 return CMD_SUCCESS;
1876 }
1877
1878 DEFUN(no_bgp_ebgp_requires_policy, no_bgp_ebgp_requires_policy_cmd,
1879 "no bgp ebgp-requires-policy",
1880 NO_STR
1881 "BGP specific commands\n"
1882 "Require in and out policy for eBGP peers (RFC8212)\n")
1883 {
1884 VTY_DECLVAR_CONTEXT(bgp, bgp);
1885 bgp->ebgp_requires_policy = DEFAULT_EBGP_POLICY_DISABLED;
1886 return CMD_SUCCESS;
1887 }
1888
1889
1890 /* "bgp deterministic-med" configuration. */
1891 DEFUN (bgp_deterministic_med,
1892 bgp_deterministic_med_cmd,
1893 "bgp deterministic-med",
1894 "BGP specific commands\n"
1895 "Pick the best-MED path among paths advertised from the neighboring AS\n")
1896 {
1897 VTY_DECLVAR_CONTEXT(bgp, bgp);
1898
1899 if (!bgp_flag_check(bgp, BGP_FLAG_DETERMINISTIC_MED)) {
1900 bgp_flag_set(bgp, BGP_FLAG_DETERMINISTIC_MED);
1901 bgp_recalculate_all_bestpaths(bgp);
1902 }
1903
1904 return CMD_SUCCESS;
1905 }
1906
1907 DEFUN (no_bgp_deterministic_med,
1908 no_bgp_deterministic_med_cmd,
1909 "no bgp deterministic-med",
1910 NO_STR
1911 "BGP specific commands\n"
1912 "Pick the best-MED path among paths advertised from the neighboring AS\n")
1913 {
1914 VTY_DECLVAR_CONTEXT(bgp, bgp);
1915 int bestpath_per_as_used;
1916 afi_t afi;
1917 safi_t safi;
1918 struct peer *peer;
1919 struct listnode *node, *nnode;
1920
1921 if (bgp_flag_check(bgp, BGP_FLAG_DETERMINISTIC_MED)) {
1922 bestpath_per_as_used = 0;
1923
1924 for (ALL_LIST_ELEMENTS(bgp->peer, node, nnode, peer)) {
1925 FOREACH_AFI_SAFI (afi, safi)
1926 if (bgp_addpath_dmed_required(
1927 peer->addpath_type[afi][safi])) {
1928 bestpath_per_as_used = 1;
1929 break;
1930 }
1931
1932 if (bestpath_per_as_used)
1933 break;
1934 }
1935
1936 if (bestpath_per_as_used) {
1937 vty_out(vty,
1938 "bgp deterministic-med cannot be disabled while addpath-tx-bestpath-per-AS is in use\n");
1939 return CMD_WARNING_CONFIG_FAILED;
1940 } else {
1941 bgp_flag_unset(bgp, BGP_FLAG_DETERMINISTIC_MED);
1942 bgp_recalculate_all_bestpaths(bgp);
1943 }
1944 }
1945
1946 return CMD_SUCCESS;
1947 }
1948
1949 /* "bgp graceful-restart" configuration. */
1950 DEFUN (bgp_graceful_restart,
1951 bgp_graceful_restart_cmd,
1952 "bgp graceful-restart",
1953 "BGP specific commands\n"
1954 "Graceful restart capability parameters\n")
1955 {
1956 VTY_DECLVAR_CONTEXT(bgp, bgp);
1957 bgp_flag_set(bgp, BGP_FLAG_GRACEFUL_RESTART);
1958 return CMD_SUCCESS;
1959 }
1960
1961 DEFUN (no_bgp_graceful_restart,
1962 no_bgp_graceful_restart_cmd,
1963 "no bgp graceful-restart",
1964 NO_STR
1965 "BGP specific commands\n"
1966 "Graceful restart capability parameters\n")
1967 {
1968 VTY_DECLVAR_CONTEXT(bgp, bgp);
1969 bgp_flag_unset(bgp, BGP_FLAG_GRACEFUL_RESTART);
1970 return CMD_SUCCESS;
1971 }
1972
1973 DEFUN (bgp_graceful_restart_stalepath_time,
1974 bgp_graceful_restart_stalepath_time_cmd,
1975 "bgp graceful-restart stalepath-time (1-4095)",
1976 "BGP specific commands\n"
1977 "Graceful restart capability parameters\n"
1978 "Set the max time to hold onto restarting peer's stale paths\n"
1979 "Delay value (seconds)\n")
1980 {
1981 VTY_DECLVAR_CONTEXT(bgp, bgp);
1982 int idx_number = 3;
1983 uint32_t stalepath;
1984
1985 stalepath = strtoul(argv[idx_number]->arg, NULL, 10);
1986 bgp->stalepath_time = stalepath;
1987 return CMD_SUCCESS;
1988 }
1989
1990 DEFUN (bgp_graceful_restart_restart_time,
1991 bgp_graceful_restart_restart_time_cmd,
1992 "bgp graceful-restart restart-time (1-4095)",
1993 "BGP specific commands\n"
1994 "Graceful restart capability parameters\n"
1995 "Set the time to wait to delete stale routes before a BGP open message is received\n"
1996 "Delay value (seconds)\n")
1997 {
1998 VTY_DECLVAR_CONTEXT(bgp, bgp);
1999 int idx_number = 3;
2000 uint32_t restart;
2001
2002 restart = strtoul(argv[idx_number]->arg, NULL, 10);
2003 bgp->restart_time = restart;
2004 return CMD_SUCCESS;
2005 }
2006
2007 DEFUN (no_bgp_graceful_restart_stalepath_time,
2008 no_bgp_graceful_restart_stalepath_time_cmd,
2009 "no bgp graceful-restart stalepath-time [(1-4095)]",
2010 NO_STR
2011 "BGP specific commands\n"
2012 "Graceful restart capability parameters\n"
2013 "Set the max time to hold onto restarting peer's stale paths\n"
2014 "Delay value (seconds)\n")
2015 {
2016 VTY_DECLVAR_CONTEXT(bgp, bgp);
2017
2018 bgp->stalepath_time = BGP_DEFAULT_STALEPATH_TIME;
2019 return CMD_SUCCESS;
2020 }
2021
2022 DEFUN (no_bgp_graceful_restart_restart_time,
2023 no_bgp_graceful_restart_restart_time_cmd,
2024 "no bgp graceful-restart restart-time [(1-4095)]",
2025 NO_STR
2026 "BGP specific commands\n"
2027 "Graceful restart capability parameters\n"
2028 "Set the time to wait to delete stale routes before a BGP open message is received\n"
2029 "Delay value (seconds)\n")
2030 {
2031 VTY_DECLVAR_CONTEXT(bgp, bgp);
2032
2033 bgp->restart_time = BGP_DEFAULT_RESTART_TIME;
2034 return CMD_SUCCESS;
2035 }
2036
2037 DEFUN (bgp_graceful_restart_preserve_fw,
2038 bgp_graceful_restart_preserve_fw_cmd,
2039 "bgp graceful-restart preserve-fw-state",
2040 "BGP specific commands\n"
2041 "Graceful restart capability parameters\n"
2042 "Sets F-bit indication that fib is preserved while doing Graceful Restart\n")
2043 {
2044 VTY_DECLVAR_CONTEXT(bgp, bgp);
2045 bgp_flag_set(bgp, BGP_FLAG_GR_PRESERVE_FWD);
2046 return CMD_SUCCESS;
2047 }
2048
2049 DEFUN (no_bgp_graceful_restart_preserve_fw,
2050 no_bgp_graceful_restart_preserve_fw_cmd,
2051 "no bgp graceful-restart preserve-fw-state",
2052 NO_STR
2053 "BGP specific commands\n"
2054 "Graceful restart capability parameters\n"
2055 "Unsets F-bit indication that fib is preserved while doing Graceful Restart\n")
2056 {
2057 VTY_DECLVAR_CONTEXT(bgp, bgp);
2058 bgp_flag_unset(bgp, BGP_FLAG_GR_PRESERVE_FWD);
2059 return CMD_SUCCESS;
2060 }
2061
2062 /* "bgp graceful-shutdown" configuration */
2063 DEFUN (bgp_graceful_shutdown,
2064 bgp_graceful_shutdown_cmd,
2065 "bgp graceful-shutdown",
2066 BGP_STR
2067 "Graceful shutdown parameters\n")
2068 {
2069 VTY_DECLVAR_CONTEXT(bgp, bgp);
2070
2071 if (!bgp_flag_check(bgp, BGP_FLAG_GRACEFUL_SHUTDOWN)) {
2072 bgp_flag_set(bgp, BGP_FLAG_GRACEFUL_SHUTDOWN);
2073 bgp_static_redo_import_check(bgp);
2074 bgp_redistribute_redo(bgp);
2075 bgp_clear_star_soft_out(vty, bgp->name);
2076 bgp_clear_star_soft_in(vty, bgp->name);
2077 }
2078
2079 return CMD_SUCCESS;
2080 }
2081
2082 DEFUN (no_bgp_graceful_shutdown,
2083 no_bgp_graceful_shutdown_cmd,
2084 "no bgp graceful-shutdown",
2085 NO_STR
2086 BGP_STR
2087 "Graceful shutdown parameters\n")
2088 {
2089 VTY_DECLVAR_CONTEXT(bgp, bgp);
2090
2091 if (bgp_flag_check(bgp, BGP_FLAG_GRACEFUL_SHUTDOWN)) {
2092 bgp_flag_unset(bgp, BGP_FLAG_GRACEFUL_SHUTDOWN);
2093 bgp_static_redo_import_check(bgp);
2094 bgp_redistribute_redo(bgp);
2095 bgp_clear_star_soft_out(vty, bgp->name);
2096 bgp_clear_star_soft_in(vty, bgp->name);
2097 }
2098
2099 return CMD_SUCCESS;
2100 }
2101
2102 /* "bgp fast-external-failover" configuration. */
2103 DEFUN (bgp_fast_external_failover,
2104 bgp_fast_external_failover_cmd,
2105 "bgp fast-external-failover",
2106 BGP_STR
2107 "Immediately reset session if a link to a directly connected external peer goes down\n")
2108 {
2109 VTY_DECLVAR_CONTEXT(bgp, bgp);
2110 bgp_flag_unset(bgp, BGP_FLAG_NO_FAST_EXT_FAILOVER);
2111 return CMD_SUCCESS;
2112 }
2113
2114 DEFUN (no_bgp_fast_external_failover,
2115 no_bgp_fast_external_failover_cmd,
2116 "no bgp fast-external-failover",
2117 NO_STR
2118 BGP_STR
2119 "Immediately reset session if a link to a directly connected external peer goes down\n")
2120 {
2121 VTY_DECLVAR_CONTEXT(bgp, bgp);
2122 bgp_flag_set(bgp, BGP_FLAG_NO_FAST_EXT_FAILOVER);
2123 return CMD_SUCCESS;
2124 }
2125
2126 /* "bgp enforce-first-as" configuration. */
2127 #if CONFDATE > 20190517
2128 CPP_NOTICE("bgpd: remove deprecated '[no] bgp enforce-first-as' commands")
2129 #endif
2130
2131 DEFUN_HIDDEN (bgp_enforce_first_as,
2132 bgp_enforce_first_as_cmd,
2133 "[no] bgp enforce-first-as",
2134 NO_STR
2135 BGP_STR
2136 "Enforce the first AS for EBGP routes\n")
2137 {
2138 VTY_DECLVAR_CONTEXT(bgp, bgp);
2139
2140 if (strmatch(argv[0]->text, "no"))
2141 bgp_flag_unset(bgp, BGP_FLAG_ENFORCE_FIRST_AS);
2142 else
2143 bgp_flag_set(bgp, BGP_FLAG_ENFORCE_FIRST_AS);
2144
2145 return CMD_SUCCESS;
2146 }
2147
2148 /* "bgp bestpath compare-routerid" configuration. */
2149 DEFUN (bgp_bestpath_compare_router_id,
2150 bgp_bestpath_compare_router_id_cmd,
2151 "bgp bestpath compare-routerid",
2152 "BGP specific commands\n"
2153 "Change the default bestpath selection\n"
2154 "Compare router-id for identical EBGP paths\n")
2155 {
2156 VTY_DECLVAR_CONTEXT(bgp, bgp);
2157 bgp_flag_set(bgp, BGP_FLAG_COMPARE_ROUTER_ID);
2158 bgp_recalculate_all_bestpaths(bgp);
2159
2160 return CMD_SUCCESS;
2161 }
2162
2163 DEFUN (no_bgp_bestpath_compare_router_id,
2164 no_bgp_bestpath_compare_router_id_cmd,
2165 "no bgp bestpath compare-routerid",
2166 NO_STR
2167 "BGP specific commands\n"
2168 "Change the default bestpath selection\n"
2169 "Compare router-id for identical EBGP paths\n")
2170 {
2171 VTY_DECLVAR_CONTEXT(bgp, bgp);
2172 bgp_flag_unset(bgp, BGP_FLAG_COMPARE_ROUTER_ID);
2173 bgp_recalculate_all_bestpaths(bgp);
2174
2175 return CMD_SUCCESS;
2176 }
2177
2178 /* "bgp bestpath as-path ignore" configuration. */
2179 DEFUN (bgp_bestpath_aspath_ignore,
2180 bgp_bestpath_aspath_ignore_cmd,
2181 "bgp bestpath as-path ignore",
2182 "BGP specific commands\n"
2183 "Change the default bestpath selection\n"
2184 "AS-path attribute\n"
2185 "Ignore as-path length in selecting a route\n")
2186 {
2187 VTY_DECLVAR_CONTEXT(bgp, bgp);
2188 bgp_flag_set(bgp, BGP_FLAG_ASPATH_IGNORE);
2189 bgp_recalculate_all_bestpaths(bgp);
2190
2191 return CMD_SUCCESS;
2192 }
2193
2194 DEFUN (no_bgp_bestpath_aspath_ignore,
2195 no_bgp_bestpath_aspath_ignore_cmd,
2196 "no bgp bestpath as-path ignore",
2197 NO_STR
2198 "BGP specific commands\n"
2199 "Change the default bestpath selection\n"
2200 "AS-path attribute\n"
2201 "Ignore as-path length in selecting a route\n")
2202 {
2203 VTY_DECLVAR_CONTEXT(bgp, bgp);
2204 bgp_flag_unset(bgp, BGP_FLAG_ASPATH_IGNORE);
2205 bgp_recalculate_all_bestpaths(bgp);
2206
2207 return CMD_SUCCESS;
2208 }
2209
2210 /* "bgp bestpath as-path confed" configuration. */
2211 DEFUN (bgp_bestpath_aspath_confed,
2212 bgp_bestpath_aspath_confed_cmd,
2213 "bgp bestpath as-path confed",
2214 "BGP specific commands\n"
2215 "Change the default bestpath selection\n"
2216 "AS-path attribute\n"
2217 "Compare path lengths including confederation sets & sequences in selecting a route\n")
2218 {
2219 VTY_DECLVAR_CONTEXT(bgp, bgp);
2220 bgp_flag_set(bgp, BGP_FLAG_ASPATH_CONFED);
2221 bgp_recalculate_all_bestpaths(bgp);
2222
2223 return CMD_SUCCESS;
2224 }
2225
2226 DEFUN (no_bgp_bestpath_aspath_confed,
2227 no_bgp_bestpath_aspath_confed_cmd,
2228 "no bgp bestpath as-path confed",
2229 NO_STR
2230 "BGP specific commands\n"
2231 "Change the default bestpath selection\n"
2232 "AS-path attribute\n"
2233 "Compare path lengths including confederation sets & sequences in selecting a route\n")
2234 {
2235 VTY_DECLVAR_CONTEXT(bgp, bgp);
2236 bgp_flag_unset(bgp, BGP_FLAG_ASPATH_CONFED);
2237 bgp_recalculate_all_bestpaths(bgp);
2238
2239 return CMD_SUCCESS;
2240 }
2241
2242 /* "bgp bestpath as-path multipath-relax" configuration. */
2243 DEFUN (bgp_bestpath_aspath_multipath_relax,
2244 bgp_bestpath_aspath_multipath_relax_cmd,
2245 "bgp bestpath as-path multipath-relax [<as-set|no-as-set>]",
2246 "BGP specific commands\n"
2247 "Change the default bestpath selection\n"
2248 "AS-path attribute\n"
2249 "Allow load sharing across routes that have different AS paths (but same length)\n"
2250 "Generate an AS_SET\n"
2251 "Do not generate an AS_SET\n")
2252 {
2253 VTY_DECLVAR_CONTEXT(bgp, bgp);
2254 int idx = 0;
2255 bgp_flag_set(bgp, BGP_FLAG_ASPATH_MULTIPATH_RELAX);
2256
2257 /* no-as-set is now the default behavior so we can silently
2258 * ignore it */
2259 if (argv_find(argv, argc, "as-set", &idx))
2260 bgp_flag_set(bgp, BGP_FLAG_MULTIPATH_RELAX_AS_SET);
2261 else
2262 bgp_flag_unset(bgp, BGP_FLAG_MULTIPATH_RELAX_AS_SET);
2263
2264 bgp_recalculate_all_bestpaths(bgp);
2265
2266 return CMD_SUCCESS;
2267 }
2268
2269 DEFUN (no_bgp_bestpath_aspath_multipath_relax,
2270 no_bgp_bestpath_aspath_multipath_relax_cmd,
2271 "no bgp bestpath as-path multipath-relax [<as-set|no-as-set>]",
2272 NO_STR
2273 "BGP specific commands\n"
2274 "Change the default bestpath selection\n"
2275 "AS-path attribute\n"
2276 "Allow load sharing across routes that have different AS paths (but same length)\n"
2277 "Generate an AS_SET\n"
2278 "Do not generate an AS_SET\n")
2279 {
2280 VTY_DECLVAR_CONTEXT(bgp, bgp);
2281 bgp_flag_unset(bgp, BGP_FLAG_ASPATH_MULTIPATH_RELAX);
2282 bgp_flag_unset(bgp, BGP_FLAG_MULTIPATH_RELAX_AS_SET);
2283 bgp_recalculate_all_bestpaths(bgp);
2284
2285 return CMD_SUCCESS;
2286 }
2287
2288 /* "bgp log-neighbor-changes" configuration. */
2289 DEFUN (bgp_log_neighbor_changes,
2290 bgp_log_neighbor_changes_cmd,
2291 "bgp log-neighbor-changes",
2292 "BGP specific commands\n"
2293 "Log neighbor up/down and reset reason\n")
2294 {
2295 VTY_DECLVAR_CONTEXT(bgp, bgp);
2296 bgp_flag_set(bgp, BGP_FLAG_LOG_NEIGHBOR_CHANGES);
2297 return CMD_SUCCESS;
2298 }
2299
2300 DEFUN (no_bgp_log_neighbor_changes,
2301 no_bgp_log_neighbor_changes_cmd,
2302 "no bgp log-neighbor-changes",
2303 NO_STR
2304 "BGP specific commands\n"
2305 "Log neighbor up/down and reset reason\n")
2306 {
2307 VTY_DECLVAR_CONTEXT(bgp, bgp);
2308 bgp_flag_unset(bgp, BGP_FLAG_LOG_NEIGHBOR_CHANGES);
2309 return CMD_SUCCESS;
2310 }
2311
2312 /* "bgp bestpath med" configuration. */
2313 DEFUN (bgp_bestpath_med,
2314 bgp_bestpath_med_cmd,
2315 "bgp bestpath med <confed [missing-as-worst]|missing-as-worst [confed]>",
2316 "BGP specific commands\n"
2317 "Change the default bestpath selection\n"
2318 "MED attribute\n"
2319 "Compare MED among confederation paths\n"
2320 "Treat missing MED as the least preferred one\n"
2321 "Treat missing MED as the least preferred one\n"
2322 "Compare MED among confederation paths\n")
2323 {
2324 VTY_DECLVAR_CONTEXT(bgp, bgp);
2325
2326 int idx = 0;
2327 if (argv_find(argv, argc, "confed", &idx))
2328 bgp_flag_set(bgp, BGP_FLAG_MED_CONFED);
2329 idx = 0;
2330 if (argv_find(argv, argc, "missing-as-worst", &idx))
2331 bgp_flag_set(bgp, BGP_FLAG_MED_MISSING_AS_WORST);
2332
2333 bgp_recalculate_all_bestpaths(bgp);
2334
2335 return CMD_SUCCESS;
2336 }
2337
2338 DEFUN (no_bgp_bestpath_med,
2339 no_bgp_bestpath_med_cmd,
2340 "no bgp bestpath med <confed [missing-as-worst]|missing-as-worst [confed]>",
2341 NO_STR
2342 "BGP specific commands\n"
2343 "Change the default bestpath selection\n"
2344 "MED attribute\n"
2345 "Compare MED among confederation paths\n"
2346 "Treat missing MED as the least preferred one\n"
2347 "Treat missing MED as the least preferred one\n"
2348 "Compare MED among confederation paths\n")
2349 {
2350 VTY_DECLVAR_CONTEXT(bgp, bgp);
2351
2352 int idx = 0;
2353 if (argv_find(argv, argc, "confed", &idx))
2354 bgp_flag_unset(bgp, BGP_FLAG_MED_CONFED);
2355 idx = 0;
2356 if (argv_find(argv, argc, "missing-as-worst", &idx))
2357 bgp_flag_unset(bgp, BGP_FLAG_MED_MISSING_AS_WORST);
2358
2359 bgp_recalculate_all_bestpaths(bgp);
2360
2361 return CMD_SUCCESS;
2362 }
2363
2364 /* "no bgp default ipv4-unicast". */
2365 DEFUN (no_bgp_default_ipv4_unicast,
2366 no_bgp_default_ipv4_unicast_cmd,
2367 "no bgp default ipv4-unicast",
2368 NO_STR
2369 "BGP specific commands\n"
2370 "Configure BGP defaults\n"
2371 "Activate ipv4-unicast for a peer by default\n")
2372 {
2373 VTY_DECLVAR_CONTEXT(bgp, bgp);
2374 bgp_flag_set(bgp, BGP_FLAG_NO_DEFAULT_IPV4);
2375 return CMD_SUCCESS;
2376 }
2377
2378 DEFUN (bgp_default_ipv4_unicast,
2379 bgp_default_ipv4_unicast_cmd,
2380 "bgp default ipv4-unicast",
2381 "BGP specific commands\n"
2382 "Configure BGP defaults\n"
2383 "Activate ipv4-unicast for a peer by default\n")
2384 {
2385 VTY_DECLVAR_CONTEXT(bgp, bgp);
2386 bgp_flag_unset(bgp, BGP_FLAG_NO_DEFAULT_IPV4);
2387 return CMD_SUCCESS;
2388 }
2389
2390 /* Display hostname in certain command outputs */
2391 DEFUN (bgp_default_show_hostname,
2392 bgp_default_show_hostname_cmd,
2393 "bgp default show-hostname",
2394 "BGP specific commands\n"
2395 "Configure BGP defaults\n"
2396 "Show hostname in certain command outputs\n")
2397 {
2398 VTY_DECLVAR_CONTEXT(bgp, bgp);
2399 bgp_flag_set(bgp, BGP_FLAG_SHOW_HOSTNAME);
2400 return CMD_SUCCESS;
2401 }
2402
2403 DEFUN (no_bgp_default_show_hostname,
2404 no_bgp_default_show_hostname_cmd,
2405 "no bgp default show-hostname",
2406 NO_STR
2407 "BGP specific commands\n"
2408 "Configure BGP defaults\n"
2409 "Show hostname in certain command outputs\n")
2410 {
2411 VTY_DECLVAR_CONTEXT(bgp, bgp);
2412 bgp_flag_unset(bgp, BGP_FLAG_SHOW_HOSTNAME);
2413 return CMD_SUCCESS;
2414 }
2415
2416 /* "bgp network import-check" configuration. */
2417 DEFUN (bgp_network_import_check,
2418 bgp_network_import_check_cmd,
2419 "bgp network import-check",
2420 "BGP specific commands\n"
2421 "BGP network command\n"
2422 "Check BGP network route exists in IGP\n")
2423 {
2424 VTY_DECLVAR_CONTEXT(bgp, bgp);
2425 if (!bgp_flag_check(bgp, BGP_FLAG_IMPORT_CHECK)) {
2426 bgp_flag_set(bgp, BGP_FLAG_IMPORT_CHECK);
2427 bgp_static_redo_import_check(bgp);
2428 }
2429
2430 return CMD_SUCCESS;
2431 }
2432
2433 ALIAS_HIDDEN(bgp_network_import_check, bgp_network_import_check_exact_cmd,
2434 "bgp network import-check exact",
2435 "BGP specific commands\n"
2436 "BGP network command\n"
2437 "Check BGP network route exists in IGP\n"
2438 "Match route precisely\n")
2439
2440 DEFUN (no_bgp_network_import_check,
2441 no_bgp_network_import_check_cmd,
2442 "no bgp network import-check",
2443 NO_STR
2444 "BGP specific commands\n"
2445 "BGP network command\n"
2446 "Check BGP network route exists in IGP\n")
2447 {
2448 VTY_DECLVAR_CONTEXT(bgp, bgp);
2449 if (bgp_flag_check(bgp, BGP_FLAG_IMPORT_CHECK)) {
2450 bgp_flag_unset(bgp, BGP_FLAG_IMPORT_CHECK);
2451 bgp_static_redo_import_check(bgp);
2452 }
2453
2454 return CMD_SUCCESS;
2455 }
2456
2457 DEFUN (bgp_default_local_preference,
2458 bgp_default_local_preference_cmd,
2459 "bgp default local-preference (0-4294967295)",
2460 "BGP specific commands\n"
2461 "Configure BGP defaults\n"
2462 "local preference (higher=more preferred)\n"
2463 "Configure default local preference value\n")
2464 {
2465 VTY_DECLVAR_CONTEXT(bgp, bgp);
2466 int idx_number = 3;
2467 uint32_t local_pref;
2468
2469 local_pref = strtoul(argv[idx_number]->arg, NULL, 10);
2470
2471 bgp_default_local_preference_set(bgp, local_pref);
2472 bgp_clear_star_soft_in(vty, bgp->name);
2473
2474 return CMD_SUCCESS;
2475 }
2476
2477 DEFUN (no_bgp_default_local_preference,
2478 no_bgp_default_local_preference_cmd,
2479 "no bgp default local-preference [(0-4294967295)]",
2480 NO_STR
2481 "BGP specific commands\n"
2482 "Configure BGP defaults\n"
2483 "local preference (higher=more preferred)\n"
2484 "Configure default local preference value\n")
2485 {
2486 VTY_DECLVAR_CONTEXT(bgp, bgp);
2487 bgp_default_local_preference_unset(bgp);
2488 bgp_clear_star_soft_in(vty, bgp->name);
2489
2490 return CMD_SUCCESS;
2491 }
2492
2493
2494 DEFUN (bgp_default_subgroup_pkt_queue_max,
2495 bgp_default_subgroup_pkt_queue_max_cmd,
2496 "bgp default subgroup-pkt-queue-max (20-100)",
2497 "BGP specific commands\n"
2498 "Configure BGP defaults\n"
2499 "subgroup-pkt-queue-max\n"
2500 "Configure subgroup packet queue max\n")
2501 {
2502 VTY_DECLVAR_CONTEXT(bgp, bgp);
2503 int idx_number = 3;
2504 uint32_t max_size;
2505
2506 max_size = strtoul(argv[idx_number]->arg, NULL, 10);
2507
2508 bgp_default_subgroup_pkt_queue_max_set(bgp, max_size);
2509
2510 return CMD_SUCCESS;
2511 }
2512
2513 DEFUN (no_bgp_default_subgroup_pkt_queue_max,
2514 no_bgp_default_subgroup_pkt_queue_max_cmd,
2515 "no bgp default subgroup-pkt-queue-max [(20-100)]",
2516 NO_STR
2517 "BGP specific commands\n"
2518 "Configure BGP defaults\n"
2519 "subgroup-pkt-queue-max\n"
2520 "Configure subgroup packet queue max\n")
2521 {
2522 VTY_DECLVAR_CONTEXT(bgp, bgp);
2523 bgp_default_subgroup_pkt_queue_max_unset(bgp);
2524 return CMD_SUCCESS;
2525 }
2526
2527
2528 DEFUN (bgp_rr_allow_outbound_policy,
2529 bgp_rr_allow_outbound_policy_cmd,
2530 "bgp route-reflector allow-outbound-policy",
2531 "BGP specific commands\n"
2532 "Allow modifications made by out route-map\n"
2533 "on ibgp neighbors\n")
2534 {
2535 VTY_DECLVAR_CONTEXT(bgp, bgp);
2536
2537 if (!bgp_flag_check(bgp, BGP_FLAG_RR_ALLOW_OUTBOUND_POLICY)) {
2538 bgp_flag_set(bgp, BGP_FLAG_RR_ALLOW_OUTBOUND_POLICY);
2539 update_group_announce_rrclients(bgp);
2540 bgp_clear_star_soft_out(vty, bgp->name);
2541 }
2542
2543 return CMD_SUCCESS;
2544 }
2545
2546 DEFUN (no_bgp_rr_allow_outbound_policy,
2547 no_bgp_rr_allow_outbound_policy_cmd,
2548 "no bgp route-reflector allow-outbound-policy",
2549 NO_STR
2550 "BGP specific commands\n"
2551 "Allow modifications made by out route-map\n"
2552 "on ibgp neighbors\n")
2553 {
2554 VTY_DECLVAR_CONTEXT(bgp, bgp);
2555
2556 if (bgp_flag_check(bgp, BGP_FLAG_RR_ALLOW_OUTBOUND_POLICY)) {
2557 bgp_flag_unset(bgp, BGP_FLAG_RR_ALLOW_OUTBOUND_POLICY);
2558 update_group_announce_rrclients(bgp);
2559 bgp_clear_star_soft_out(vty, bgp->name);
2560 }
2561
2562 return CMD_SUCCESS;
2563 }
2564
2565 DEFUN (bgp_listen_limit,
2566 bgp_listen_limit_cmd,
2567 "bgp listen limit (1-5000)",
2568 "BGP specific commands\n"
2569 "Configure BGP defaults\n"
2570 "maximum number of BGP Dynamic Neighbors that can be created\n"
2571 "Configure Dynamic Neighbors listen limit value\n")
2572 {
2573 VTY_DECLVAR_CONTEXT(bgp, bgp);
2574 int idx_number = 3;
2575 int listen_limit;
2576
2577 listen_limit = strtoul(argv[idx_number]->arg, NULL, 10);
2578
2579 bgp_listen_limit_set(bgp, listen_limit);
2580
2581 return CMD_SUCCESS;
2582 }
2583
2584 DEFUN (no_bgp_listen_limit,
2585 no_bgp_listen_limit_cmd,
2586 "no bgp listen limit [(1-5000)]",
2587 "BGP specific commands\n"
2588 "Configure BGP defaults\n"
2589 "unset maximum number of BGP Dynamic Neighbors that can be created\n"
2590 "Configure Dynamic Neighbors listen limit value to default\n"
2591 "Configure Dynamic Neighbors listen limit value\n")
2592 {
2593 VTY_DECLVAR_CONTEXT(bgp, bgp);
2594 bgp_listen_limit_unset(bgp);
2595 return CMD_SUCCESS;
2596 }
2597
2598
2599 /*
2600 * Check if this listen range is already configured. Check for exact
2601 * match or overlap based on input.
2602 */
2603 static struct peer_group *listen_range_exists(struct bgp *bgp,
2604 struct prefix *range, int exact)
2605 {
2606 struct listnode *node, *nnode;
2607 struct listnode *node1, *nnode1;
2608 struct peer_group *group;
2609 struct prefix *lr;
2610 afi_t afi;
2611 int match;
2612
2613 afi = family2afi(range->family);
2614 for (ALL_LIST_ELEMENTS(bgp->group, node, nnode, group)) {
2615 for (ALL_LIST_ELEMENTS(group->listen_range[afi], node1, nnode1,
2616 lr)) {
2617 if (exact)
2618 match = prefix_same(range, lr);
2619 else
2620 match = (prefix_match(range, lr)
2621 || prefix_match(lr, range));
2622 if (match)
2623 return group;
2624 }
2625 }
2626
2627 return NULL;
2628 }
2629
2630 DEFUN (bgp_listen_range,
2631 bgp_listen_range_cmd,
2632 "bgp listen range <A.B.C.D/M|X:X::X:X/M> peer-group WORD",
2633 "BGP specific commands\n"
2634 "Configure BGP dynamic neighbors listen range\n"
2635 "Configure BGP dynamic neighbors listen range\n"
2636 NEIGHBOR_ADDR_STR
2637 "Member of the peer-group\n"
2638 "Peer-group name\n")
2639 {
2640 VTY_DECLVAR_CONTEXT(bgp, bgp);
2641 struct prefix range;
2642 struct peer_group *group, *existing_group;
2643 afi_t afi;
2644 int ret;
2645 int idx = 0;
2646
2647 argv_find(argv, argc, "A.B.C.D/M", &idx);
2648 argv_find(argv, argc, "X:X::X:X/M", &idx);
2649 char *prefix = argv[idx]->arg;
2650 argv_find(argv, argc, "WORD", &idx);
2651 char *peergroup = argv[idx]->arg;
2652
2653 /* Convert IP prefix string to struct prefix. */
2654 ret = str2prefix(prefix, &range);
2655 if (!ret) {
2656 vty_out(vty, "%% Malformed listen range\n");
2657 return CMD_WARNING_CONFIG_FAILED;
2658 }
2659
2660 afi = family2afi(range.family);
2661
2662 if (afi == AFI_IP6 && IN6_IS_ADDR_LINKLOCAL(&range.u.prefix6)) {
2663 vty_out(vty,
2664 "%% Malformed listen range (link-local address)\n");
2665 return CMD_WARNING_CONFIG_FAILED;
2666 }
2667
2668 apply_mask(&range);
2669
2670 /* Check if same listen range is already configured. */
2671 existing_group = listen_range_exists(bgp, &range, 1);
2672 if (existing_group) {
2673 if (strcmp(existing_group->name, peergroup) == 0)
2674 return CMD_SUCCESS;
2675 else {
2676 vty_out(vty,
2677 "%% Same listen range is attached to peer-group %s\n",
2678 existing_group->name);
2679 return CMD_WARNING_CONFIG_FAILED;
2680 }
2681 }
2682
2683 /* Check if an overlapping listen range exists. */
2684 if (listen_range_exists(bgp, &range, 0)) {
2685 vty_out(vty,
2686 "%% Listen range overlaps with existing listen range\n");
2687 return CMD_WARNING_CONFIG_FAILED;
2688 }
2689
2690 group = peer_group_lookup(bgp, peergroup);
2691 if (!group) {
2692 vty_out(vty, "%% Configure the peer-group first\n");
2693 return CMD_WARNING_CONFIG_FAILED;
2694 }
2695
2696 ret = peer_group_listen_range_add(group, &range);
2697 return bgp_vty_return(vty, ret);
2698 }
2699
2700 DEFUN (no_bgp_listen_range,
2701 no_bgp_listen_range_cmd,
2702 "no bgp listen range <A.B.C.D/M|X:X::X:X/M> peer-group WORD",
2703 NO_STR
2704 "BGP specific commands\n"
2705 "Unconfigure BGP dynamic neighbors listen range\n"
2706 "Unconfigure BGP dynamic neighbors listen range\n"
2707 NEIGHBOR_ADDR_STR
2708 "Member of the peer-group\n"
2709 "Peer-group name\n")
2710 {
2711 VTY_DECLVAR_CONTEXT(bgp, bgp);
2712 struct prefix range;
2713 struct peer_group *group;
2714 afi_t afi;
2715 int ret;
2716 int idx = 0;
2717
2718 argv_find(argv, argc, "A.B.C.D/M", &idx);
2719 argv_find(argv, argc, "X:X::X:X/M", &idx);
2720 char *prefix = argv[idx]->arg;
2721 argv_find(argv, argc, "WORD", &idx);
2722 char *peergroup = argv[idx]->arg;
2723
2724 /* Convert IP prefix string to struct prefix. */
2725 ret = str2prefix(prefix, &range);
2726 if (!ret) {
2727 vty_out(vty, "%% Malformed listen range\n");
2728 return CMD_WARNING_CONFIG_FAILED;
2729 }
2730
2731 afi = family2afi(range.family);
2732
2733 if (afi == AFI_IP6 && IN6_IS_ADDR_LINKLOCAL(&range.u.prefix6)) {
2734 vty_out(vty,
2735 "%% Malformed listen range (link-local address)\n");
2736 return CMD_WARNING_CONFIG_FAILED;
2737 }
2738
2739 apply_mask(&range);
2740
2741 group = peer_group_lookup(bgp, peergroup);
2742 if (!group) {
2743 vty_out(vty, "%% Peer-group does not exist\n");
2744 return CMD_WARNING_CONFIG_FAILED;
2745 }
2746
2747 ret = peer_group_listen_range_del(group, &range);
2748 return bgp_vty_return(vty, ret);
2749 }
2750
2751 void bgp_config_write_listen(struct vty *vty, struct bgp *bgp)
2752 {
2753 struct peer_group *group;
2754 struct listnode *node, *nnode, *rnode, *nrnode;
2755 struct prefix *range;
2756 afi_t afi;
2757 char buf[PREFIX2STR_BUFFER];
2758
2759 if (bgp->dynamic_neighbors_limit != BGP_DYNAMIC_NEIGHBORS_LIMIT_DEFAULT)
2760 vty_out(vty, " bgp listen limit %d\n",
2761 bgp->dynamic_neighbors_limit);
2762
2763 for (ALL_LIST_ELEMENTS(bgp->group, node, nnode, group)) {
2764 for (afi = AFI_IP; afi < AFI_MAX; afi++) {
2765 for (ALL_LIST_ELEMENTS(group->listen_range[afi], rnode,
2766 nrnode, range)) {
2767 prefix2str(range, buf, sizeof(buf));
2768 vty_out(vty,
2769 " bgp listen range %s peer-group %s\n",
2770 buf, group->name);
2771 }
2772 }
2773 }
2774 }
2775
2776
2777 DEFUN (bgp_disable_connected_route_check,
2778 bgp_disable_connected_route_check_cmd,
2779 "bgp disable-ebgp-connected-route-check",
2780 "BGP specific commands\n"
2781 "Disable checking if nexthop is connected on ebgp sessions\n")
2782 {
2783 VTY_DECLVAR_CONTEXT(bgp, bgp);
2784 bgp_flag_set(bgp, BGP_FLAG_DISABLE_NH_CONNECTED_CHK);
2785 bgp_clear_star_soft_in(vty, bgp->name);
2786
2787 return CMD_SUCCESS;
2788 }
2789
2790 DEFUN (no_bgp_disable_connected_route_check,
2791 no_bgp_disable_connected_route_check_cmd,
2792 "no bgp disable-ebgp-connected-route-check",
2793 NO_STR
2794 "BGP specific commands\n"
2795 "Disable checking if nexthop is connected on ebgp sessions\n")
2796 {
2797 VTY_DECLVAR_CONTEXT(bgp, bgp);
2798 bgp_flag_unset(bgp, BGP_FLAG_DISABLE_NH_CONNECTED_CHK);
2799 bgp_clear_star_soft_in(vty, bgp->name);
2800
2801 return CMD_SUCCESS;
2802 }
2803
2804
2805 static int peer_remote_as_vty(struct vty *vty, const char *peer_str,
2806 const char *as_str, afi_t afi, safi_t safi)
2807 {
2808 VTY_DECLVAR_CONTEXT(bgp, bgp);
2809 int ret;
2810 as_t as;
2811 int as_type = AS_SPECIFIED;
2812 union sockunion su;
2813
2814 if (as_str[0] == 'i') {
2815 as = 0;
2816 as_type = AS_INTERNAL;
2817 } else if (as_str[0] == 'e') {
2818 as = 0;
2819 as_type = AS_EXTERNAL;
2820 } else {
2821 /* Get AS number. */
2822 as = strtoul(as_str, NULL, 10);
2823 }
2824
2825 /* If peer is peer group or interface peer, call proper function. */
2826 ret = str2sockunion(peer_str, &su);
2827 if (ret < 0) {
2828 struct peer *peer;
2829
2830 /* Check if existing interface peer */
2831 peer = peer_lookup_by_conf_if(bgp, peer_str);
2832
2833 ret = peer_remote_as(bgp, NULL, peer_str, &as, as_type, afi,
2834 safi);
2835
2836 /* if not interface peer, check peer-group settings */
2837 if (ret < 0 && !peer) {
2838 ret = peer_group_remote_as(bgp, peer_str, &as, as_type);
2839 if (ret < 0) {
2840 vty_out(vty,
2841 "%% Create the peer-group or interface first\n");
2842 return CMD_WARNING_CONFIG_FAILED;
2843 }
2844 return CMD_SUCCESS;
2845 }
2846 } else {
2847 if (peer_address_self_check(bgp, &su)) {
2848 vty_out(vty,
2849 "%% Can not configure the local system as neighbor\n");
2850 return CMD_WARNING_CONFIG_FAILED;
2851 }
2852 ret = peer_remote_as(bgp, &su, NULL, &as, as_type, afi, safi);
2853 }
2854
2855 /* This peer belongs to peer group. */
2856 switch (ret) {
2857 case BGP_ERR_PEER_GROUP_MEMBER:
2858 vty_out(vty,
2859 "%% Peer-group member cannot override remote-as of peer-group\n");
2860 return CMD_WARNING_CONFIG_FAILED;
2861 case BGP_ERR_PEER_GROUP_PEER_TYPE_DIFFERENT:
2862 vty_out(vty,
2863 "%% Peer-group members must be all internal or all external\n");
2864 return CMD_WARNING_CONFIG_FAILED;
2865 }
2866 return bgp_vty_return(vty, ret);
2867 }
2868
2869 DEFUN (bgp_default_shutdown,
2870 bgp_default_shutdown_cmd,
2871 "[no] bgp default shutdown",
2872 NO_STR
2873 BGP_STR
2874 "Configure BGP defaults\n"
2875 "Apply administrative shutdown to newly configured peers\n")
2876 {
2877 VTY_DECLVAR_CONTEXT(bgp, bgp);
2878 bgp->autoshutdown = !strmatch(argv[0]->text, "no");
2879 return CMD_SUCCESS;
2880 }
2881
2882 DEFUN (neighbor_remote_as,
2883 neighbor_remote_as_cmd,
2884 "neighbor <A.B.C.D|X:X::X:X|WORD> remote-as <(1-4294967295)|internal|external>",
2885 NEIGHBOR_STR
2886 NEIGHBOR_ADDR_STR2
2887 "Specify a BGP neighbor\n"
2888 AS_STR
2889 "Internal BGP peer\n"
2890 "External BGP peer\n")
2891 {
2892 int idx_peer = 1;
2893 int idx_remote_as = 3;
2894 return peer_remote_as_vty(vty, argv[idx_peer]->arg,
2895 argv[idx_remote_as]->arg, AFI_IP,
2896 SAFI_UNICAST);
2897 }
2898
2899 static int peer_conf_interface_get(struct vty *vty, const char *conf_if,
2900 afi_t afi, safi_t safi, int v6only,
2901 const char *peer_group_name,
2902 const char *as_str)
2903 {
2904 VTY_DECLVAR_CONTEXT(bgp, bgp);
2905 as_t as = 0;
2906 int as_type = AS_UNSPECIFIED;
2907 struct peer *peer;
2908 struct peer_group *group;
2909 int ret = 0;
2910 union sockunion su;
2911
2912 group = peer_group_lookup(bgp, conf_if);
2913
2914 if (group) {
2915 vty_out(vty, "%% Name conflict with peer-group \n");
2916 return CMD_WARNING_CONFIG_FAILED;
2917 }
2918
2919 if (as_str) {
2920 if (as_str[0] == 'i') {
2921 as_type = AS_INTERNAL;
2922 } else if (as_str[0] == 'e') {
2923 as_type = AS_EXTERNAL;
2924 } else {
2925 /* Get AS number. */
2926 as = strtoul(as_str, NULL, 10);
2927 as_type = AS_SPECIFIED;
2928 }
2929 }
2930
2931 peer = peer_lookup_by_conf_if(bgp, conf_if);
2932 if (peer) {
2933 if (as_str)
2934 ret = peer_remote_as(bgp, NULL, conf_if, &as, as_type,
2935 afi, safi);
2936 } else {
2937 if (bgp_flag_check(bgp, BGP_FLAG_NO_DEFAULT_IPV4)
2938 && afi == AFI_IP && safi == SAFI_UNICAST)
2939 peer = peer_create(NULL, conf_if, bgp, bgp->as, as,
2940 as_type, 0, 0, NULL);
2941 else
2942 peer = peer_create(NULL, conf_if, bgp, bgp->as, as,
2943 as_type, afi, safi, NULL);
2944
2945 if (!peer) {
2946 vty_out(vty, "%% BGP failed to create peer\n");
2947 return CMD_WARNING_CONFIG_FAILED;
2948 }
2949
2950 if (v6only)
2951 peer_flag_set(peer, PEER_FLAG_IFPEER_V6ONLY);
2952
2953 /* Request zebra to initiate IPv6 RAs on this interface. We do
2954 * this
2955 * any unnumbered peer in order to not worry about run-time
2956 * transitions
2957 * (e.g., peering is initially IPv4, but the IPv4 /30 or /31
2958 * address
2959 * gets deleted later etc.)
2960 */
2961 if (peer->ifp)
2962 bgp_zebra_initiate_radv(bgp, peer);
2963 }
2964
2965 if ((v6only && !CHECK_FLAG(peer->flags, PEER_FLAG_IFPEER_V6ONLY))
2966 || (!v6only && CHECK_FLAG(peer->flags, PEER_FLAG_IFPEER_V6ONLY))) {
2967 if (v6only)
2968 peer_flag_set(peer, PEER_FLAG_IFPEER_V6ONLY);
2969 else
2970 peer_flag_unset(peer, PEER_FLAG_IFPEER_V6ONLY);
2971
2972 /* v6only flag changed. Reset bgp seesion */
2973 if (BGP_IS_VALID_STATE_FOR_NOTIF(peer->status)) {
2974 peer->last_reset = PEER_DOWN_V6ONLY_CHANGE;
2975 bgp_notify_send(peer, BGP_NOTIFY_CEASE,
2976 BGP_NOTIFY_CEASE_CONFIG_CHANGE);
2977 } else
2978 bgp_session_reset(peer);
2979 }
2980
2981 if (!CHECK_FLAG(peer->flags_invert, PEER_FLAG_CAPABILITY_ENHE)) {
2982 SET_FLAG(peer->flags, PEER_FLAG_CAPABILITY_ENHE);
2983 SET_FLAG(peer->flags_invert, PEER_FLAG_CAPABILITY_ENHE);
2984 SET_FLAG(peer->flags_override, PEER_FLAG_CAPABILITY_ENHE);
2985 }
2986
2987 if (peer_group_name) {
2988 group = peer_group_lookup(bgp, peer_group_name);
2989 if (!group) {
2990 vty_out(vty, "%% Configure the peer-group first\n");
2991 return CMD_WARNING_CONFIG_FAILED;
2992 }
2993
2994 ret = peer_group_bind(bgp, &su, peer, group, &as);
2995 }
2996
2997 return bgp_vty_return(vty, ret);
2998 }
2999
3000 DEFUN (neighbor_interface_config,
3001 neighbor_interface_config_cmd,
3002 "neighbor WORD interface [peer-group WORD]",
3003 NEIGHBOR_STR
3004 "Interface name or neighbor tag\n"
3005 "Enable BGP on interface\n"
3006 "Member of the peer-group\n"
3007 "Peer-group name\n")
3008 {
3009 int idx_word = 1;
3010 int idx_peer_group_word = 4;
3011
3012 if (argc > idx_peer_group_word)
3013 return peer_conf_interface_get(
3014 vty, argv[idx_word]->arg, AFI_IP, SAFI_UNICAST, 0,
3015 argv[idx_peer_group_word]->arg, NULL);
3016 else
3017 return peer_conf_interface_get(vty, argv[idx_word]->arg, AFI_IP,
3018 SAFI_UNICAST, 0, NULL, NULL);
3019 }
3020
3021 DEFUN (neighbor_interface_config_v6only,
3022 neighbor_interface_config_v6only_cmd,
3023 "neighbor WORD interface v6only [peer-group WORD]",
3024 NEIGHBOR_STR
3025 "Interface name or neighbor tag\n"
3026 "Enable BGP on interface\n"
3027 "Enable BGP with v6 link-local only\n"
3028 "Member of the peer-group\n"
3029 "Peer-group name\n")
3030 {
3031 int idx_word = 1;
3032 int idx_peer_group_word = 5;
3033
3034 if (argc > idx_peer_group_word)
3035 return peer_conf_interface_get(
3036 vty, argv[idx_word]->arg, AFI_IP, SAFI_UNICAST, 1,
3037 argv[idx_peer_group_word]->arg, NULL);
3038
3039 return peer_conf_interface_get(vty, argv[idx_word]->arg, AFI_IP,
3040 SAFI_UNICAST, 1, NULL, NULL);
3041 }
3042
3043
3044 DEFUN (neighbor_interface_config_remote_as,
3045 neighbor_interface_config_remote_as_cmd,
3046 "neighbor WORD interface remote-as <(1-4294967295)|internal|external>",
3047 NEIGHBOR_STR
3048 "Interface name or neighbor tag\n"
3049 "Enable BGP on interface\n"
3050 "Specify a BGP neighbor\n"
3051 AS_STR
3052 "Internal BGP peer\n"
3053 "External BGP peer\n")
3054 {
3055 int idx_word = 1;
3056 int idx_remote_as = 4;
3057 return peer_conf_interface_get(vty, argv[idx_word]->arg, AFI_IP,
3058 SAFI_UNICAST, 0, NULL,
3059 argv[idx_remote_as]->arg);
3060 }
3061
3062 DEFUN (neighbor_interface_v6only_config_remote_as,
3063 neighbor_interface_v6only_config_remote_as_cmd,
3064 "neighbor WORD interface v6only remote-as <(1-4294967295)|internal|external>",
3065 NEIGHBOR_STR
3066 "Interface name or neighbor tag\n"
3067 "Enable BGP with v6 link-local only\n"
3068 "Enable BGP on interface\n"
3069 "Specify a BGP neighbor\n"
3070 AS_STR
3071 "Internal BGP peer\n"
3072 "External BGP peer\n")
3073 {
3074 int idx_word = 1;
3075 int idx_remote_as = 5;
3076 return peer_conf_interface_get(vty, argv[idx_word]->arg, AFI_IP,
3077 SAFI_UNICAST, 1, NULL,
3078 argv[idx_remote_as]->arg);
3079 }
3080
3081 DEFUN (neighbor_peer_group,
3082 neighbor_peer_group_cmd,
3083 "neighbor WORD peer-group",
3084 NEIGHBOR_STR
3085 "Interface name or neighbor tag\n"
3086 "Configure peer-group\n")
3087 {
3088 VTY_DECLVAR_CONTEXT(bgp, bgp);
3089 int idx_word = 1;
3090 struct peer *peer;
3091 struct peer_group *group;
3092
3093 peer = peer_lookup_by_conf_if(bgp, argv[idx_word]->arg);
3094 if (peer) {
3095 vty_out(vty, "%% Name conflict with interface: \n");
3096 return CMD_WARNING_CONFIG_FAILED;
3097 }
3098
3099 group = peer_group_get(bgp, argv[idx_word]->arg);
3100 if (!group) {
3101 vty_out(vty, "%% BGP failed to find or create peer-group\n");
3102 return CMD_WARNING_CONFIG_FAILED;
3103 }
3104
3105 return CMD_SUCCESS;
3106 }
3107
3108 DEFUN (no_neighbor,
3109 no_neighbor_cmd,
3110 "no neighbor <WORD|<A.B.C.D|X:X::X:X> [remote-as <(1-4294967295)|internal|external>]>",
3111 NO_STR
3112 NEIGHBOR_STR
3113 NEIGHBOR_ADDR_STR2
3114 "Specify a BGP neighbor\n"
3115 AS_STR
3116 "Internal BGP peer\n"
3117 "External BGP peer\n")
3118 {
3119 VTY_DECLVAR_CONTEXT(bgp, bgp);
3120 int idx_peer = 2;
3121 int ret;
3122 union sockunion su;
3123 struct peer_group *group;
3124 struct peer *peer;
3125 struct peer *other;
3126
3127 ret = str2sockunion(argv[idx_peer]->arg, &su);
3128 if (ret < 0) {
3129 /* look up for neighbor by interface name config. */
3130 peer = peer_lookup_by_conf_if(bgp, argv[idx_peer]->arg);
3131 if (peer) {
3132 /* Request zebra to terminate IPv6 RAs on this
3133 * interface. */
3134 if (peer->ifp)
3135 bgp_zebra_terminate_radv(peer->bgp, peer);
3136 peer_delete(peer);
3137 return CMD_SUCCESS;
3138 }
3139
3140 group = peer_group_lookup(bgp, argv[idx_peer]->arg);
3141 if (group)
3142 peer_group_delete(group);
3143 else {
3144 vty_out(vty, "%% Create the peer-group first\n");
3145 return CMD_WARNING_CONFIG_FAILED;
3146 }
3147 } else {
3148 peer = peer_lookup(bgp, &su);
3149 if (peer) {
3150 if (peer_dynamic_neighbor(peer)) {
3151 vty_out(vty,
3152 "%% Operation not allowed on a dynamic neighbor\n");
3153 return CMD_WARNING_CONFIG_FAILED;
3154 }
3155
3156 other = peer->doppelganger;
3157 peer_delete(peer);
3158 if (other && other->status != Deleted)
3159 peer_delete(other);
3160 }
3161 }
3162
3163 return CMD_SUCCESS;
3164 }
3165
3166 DEFUN (no_neighbor_interface_config,
3167 no_neighbor_interface_config_cmd,
3168 "no neighbor WORD interface [v6only] [peer-group WORD] [remote-as <(1-4294967295)|internal|external>]",
3169 NO_STR
3170 NEIGHBOR_STR
3171 "Interface name\n"
3172 "Configure BGP on interface\n"
3173 "Enable BGP with v6 link-local only\n"
3174 "Member of the peer-group\n"
3175 "Peer-group name\n"
3176 "Specify a BGP neighbor\n"
3177 AS_STR
3178 "Internal BGP peer\n"
3179 "External BGP peer\n")
3180 {
3181 VTY_DECLVAR_CONTEXT(bgp, bgp);
3182 int idx_word = 2;
3183 struct peer *peer;
3184
3185 /* look up for neighbor by interface name config. */
3186 peer = peer_lookup_by_conf_if(bgp, argv[idx_word]->arg);
3187 if (peer) {
3188 /* Request zebra to terminate IPv6 RAs on this interface. */
3189 if (peer->ifp)
3190 bgp_zebra_terminate_radv(peer->bgp, peer);
3191 peer_delete(peer);
3192 } else {
3193 vty_out(vty, "%% Create the bgp interface first\n");
3194 return CMD_WARNING_CONFIG_FAILED;
3195 }
3196 return CMD_SUCCESS;
3197 }
3198
3199 DEFUN (no_neighbor_peer_group,
3200 no_neighbor_peer_group_cmd,
3201 "no neighbor WORD peer-group",
3202 NO_STR
3203 NEIGHBOR_STR
3204 "Neighbor tag\n"
3205 "Configure peer-group\n")
3206 {
3207 VTY_DECLVAR_CONTEXT(bgp, bgp);
3208 int idx_word = 2;
3209 struct peer_group *group;
3210
3211 group = peer_group_lookup(bgp, argv[idx_word]->arg);
3212 if (group)
3213 peer_group_delete(group);
3214 else {
3215 vty_out(vty, "%% Create the peer-group first\n");
3216 return CMD_WARNING_CONFIG_FAILED;
3217 }
3218 return CMD_SUCCESS;
3219 }
3220
3221 DEFUN (no_neighbor_interface_peer_group_remote_as,
3222 no_neighbor_interface_peer_group_remote_as_cmd,
3223 "no neighbor WORD remote-as <(1-4294967295)|internal|external>",
3224 NO_STR
3225 NEIGHBOR_STR
3226 "Interface name or neighbor tag\n"
3227 "Specify a BGP neighbor\n"
3228 AS_STR
3229 "Internal BGP peer\n"
3230 "External BGP peer\n")
3231 {
3232 VTY_DECLVAR_CONTEXT(bgp, bgp);
3233 int idx_word = 2;
3234 struct peer_group *group;
3235 struct peer *peer;
3236
3237 /* look up for neighbor by interface name config. */
3238 peer = peer_lookup_by_conf_if(bgp, argv[idx_word]->arg);
3239 if (peer) {
3240 peer_as_change(peer, 0, AS_UNSPECIFIED);
3241 return CMD_SUCCESS;
3242 }
3243
3244 group = peer_group_lookup(bgp, argv[idx_word]->arg);
3245 if (group)
3246 peer_group_remote_as_delete(group);
3247 else {
3248 vty_out(vty, "%% Create the peer-group or interface first\n");
3249 return CMD_WARNING_CONFIG_FAILED;
3250 }
3251 return CMD_SUCCESS;
3252 }
3253
3254 DEFUN (neighbor_local_as,
3255 neighbor_local_as_cmd,
3256 "neighbor <A.B.C.D|X:X::X:X|WORD> local-as (1-4294967295)",
3257 NEIGHBOR_STR
3258 NEIGHBOR_ADDR_STR2
3259 "Specify a local-as number\n"
3260 "AS number used as local AS\n")
3261 {
3262 int idx_peer = 1;
3263 int idx_number = 3;
3264 struct peer *peer;
3265 int ret;
3266 as_t as;
3267
3268 peer = peer_and_group_lookup_vty(vty, argv[idx_peer]->arg);
3269 if (!peer)
3270 return CMD_WARNING_CONFIG_FAILED;
3271
3272 as = strtoul(argv[idx_number]->arg, NULL, 10);
3273 ret = peer_local_as_set(peer, as, 0, 0);
3274 return bgp_vty_return(vty, ret);
3275 }
3276
3277 DEFUN (neighbor_local_as_no_prepend,
3278 neighbor_local_as_no_prepend_cmd,
3279 "neighbor <A.B.C.D|X:X::X:X|WORD> local-as (1-4294967295) no-prepend",
3280 NEIGHBOR_STR
3281 NEIGHBOR_ADDR_STR2
3282 "Specify a local-as number\n"
3283 "AS number used as local AS\n"
3284 "Do not prepend local-as to updates from ebgp peers\n")
3285 {
3286 int idx_peer = 1;
3287 int idx_number = 3;
3288 struct peer *peer;
3289 int ret;
3290 as_t as;
3291
3292 peer = peer_and_group_lookup_vty(vty, argv[idx_peer]->arg);
3293 if (!peer)
3294 return CMD_WARNING_CONFIG_FAILED;
3295
3296 as = strtoul(argv[idx_number]->arg, NULL, 10);
3297 ret = peer_local_as_set(peer, as, 1, 0);
3298 return bgp_vty_return(vty, ret);
3299 }
3300
3301 DEFUN (neighbor_local_as_no_prepend_replace_as,
3302 neighbor_local_as_no_prepend_replace_as_cmd,
3303 "neighbor <A.B.C.D|X:X::X:X|WORD> local-as (1-4294967295) no-prepend replace-as",
3304 NEIGHBOR_STR
3305 NEIGHBOR_ADDR_STR2
3306 "Specify a local-as number\n"
3307 "AS number used as local AS\n"
3308 "Do not prepend local-as to updates from ebgp peers\n"
3309 "Do not prepend local-as to updates from ibgp peers\n")
3310 {
3311 int idx_peer = 1;
3312 int idx_number = 3;
3313 struct peer *peer;
3314 int ret;
3315 as_t as;
3316
3317 peer = peer_and_group_lookup_vty(vty, argv[idx_peer]->arg);
3318 if (!peer)
3319 return CMD_WARNING_CONFIG_FAILED;
3320
3321 as = strtoul(argv[idx_number]->arg, NULL, 10);
3322 ret = peer_local_as_set(peer, as, 1, 1);
3323 return bgp_vty_return(vty, ret);
3324 }
3325
3326 DEFUN (no_neighbor_local_as,
3327 no_neighbor_local_as_cmd,
3328 "no neighbor <A.B.C.D|X:X::X:X|WORD> local-as [(1-4294967295) [no-prepend [replace-as]]]",
3329 NO_STR
3330 NEIGHBOR_STR
3331 NEIGHBOR_ADDR_STR2
3332 "Specify a local-as number\n"
3333 "AS number used as local AS\n"
3334 "Do not prepend local-as to updates from ebgp peers\n"
3335 "Do not prepend local-as to updates from ibgp peers\n")
3336 {
3337 int idx_peer = 2;
3338 struct peer *peer;
3339 int ret;
3340
3341 peer = peer_and_group_lookup_vty(vty, argv[idx_peer]->arg);
3342 if (!peer)
3343 return CMD_WARNING_CONFIG_FAILED;
3344
3345 ret = peer_local_as_unset(peer);
3346 return bgp_vty_return(vty, ret);
3347 }
3348
3349
3350 DEFUN (neighbor_solo,
3351 neighbor_solo_cmd,
3352 "neighbor <A.B.C.D|X:X::X:X|WORD> solo",
3353 NEIGHBOR_STR
3354 NEIGHBOR_ADDR_STR2
3355 "Solo peer - part of its own update group\n")
3356 {
3357 int idx_peer = 1;
3358 struct peer *peer;
3359 int ret;
3360
3361 peer = peer_and_group_lookup_vty(vty, argv[idx_peer]->arg);
3362 if (!peer)
3363 return CMD_WARNING_CONFIG_FAILED;
3364
3365 ret = update_group_adjust_soloness(peer, 1);
3366 return bgp_vty_return(vty, ret);
3367 }
3368
3369 DEFUN (no_neighbor_solo,
3370 no_neighbor_solo_cmd,
3371 "no neighbor <A.B.C.D|X:X::X:X|WORD> solo",
3372 NO_STR
3373 NEIGHBOR_STR
3374 NEIGHBOR_ADDR_STR2
3375 "Solo peer - part of its own update group\n")
3376 {
3377 int idx_peer = 2;
3378 struct peer *peer;
3379 int ret;
3380
3381 peer = peer_and_group_lookup_vty(vty, argv[idx_peer]->arg);
3382 if (!peer)
3383 return CMD_WARNING_CONFIG_FAILED;
3384
3385 ret = update_group_adjust_soloness(peer, 0);
3386 return bgp_vty_return(vty, ret);
3387 }
3388
3389 DEFUN (neighbor_password,
3390 neighbor_password_cmd,
3391 "neighbor <A.B.C.D|X:X::X:X|WORD> password LINE",
3392 NEIGHBOR_STR
3393 NEIGHBOR_ADDR_STR2
3394 "Set a password\n"
3395 "The password\n")
3396 {
3397 int idx_peer = 1;
3398 int idx_line = 3;
3399 struct peer *peer;
3400 int ret;
3401
3402 peer = peer_and_group_lookup_vty(vty, argv[idx_peer]->arg);
3403 if (!peer)
3404 return CMD_WARNING_CONFIG_FAILED;
3405
3406 ret = peer_password_set(peer, argv[idx_line]->arg);
3407 return bgp_vty_return(vty, ret);
3408 }
3409
3410 DEFUN (no_neighbor_password,
3411 no_neighbor_password_cmd,
3412 "no neighbor <A.B.C.D|X:X::X:X|WORD> password [LINE]",
3413 NO_STR
3414 NEIGHBOR_STR
3415 NEIGHBOR_ADDR_STR2
3416 "Set a password\n"
3417 "The password\n")
3418 {
3419 int idx_peer = 2;
3420 struct peer *peer;
3421 int ret;
3422
3423 peer = peer_and_group_lookup_vty(vty, argv[idx_peer]->arg);
3424 if (!peer)
3425 return CMD_WARNING_CONFIG_FAILED;
3426
3427 ret = peer_password_unset(peer);
3428 return bgp_vty_return(vty, ret);
3429 }
3430
3431 DEFUN (neighbor_activate,
3432 neighbor_activate_cmd,
3433 "neighbor <A.B.C.D|X:X::X:X|WORD> activate",
3434 NEIGHBOR_STR
3435 NEIGHBOR_ADDR_STR2
3436 "Enable the Address Family for this Neighbor\n")
3437 {
3438 int idx_peer = 1;
3439 int ret;
3440 struct peer *peer;
3441
3442 peer = peer_and_group_lookup_vty(vty, argv[idx_peer]->arg);
3443 if (!peer)
3444 return CMD_WARNING_CONFIG_FAILED;
3445
3446 ret = peer_activate(peer, bgp_node_afi(vty), bgp_node_safi(vty));
3447 return bgp_vty_return(vty, ret);
3448 }
3449
3450 ALIAS_HIDDEN(neighbor_activate, neighbor_activate_hidden_cmd,
3451 "neighbor <A.B.C.D|X:X::X:X|WORD> activate",
3452 NEIGHBOR_STR NEIGHBOR_ADDR_STR2
3453 "Enable the Address Family for this Neighbor\n")
3454
3455 DEFUN (no_neighbor_activate,
3456 no_neighbor_activate_cmd,
3457 "no neighbor <A.B.C.D|X:X::X:X|WORD> activate",
3458 NO_STR
3459 NEIGHBOR_STR
3460 NEIGHBOR_ADDR_STR2
3461 "Enable the Address Family for this Neighbor\n")
3462 {
3463 int idx_peer = 2;
3464 int ret;
3465 struct peer *peer;
3466
3467 /* Lookup peer. */
3468 peer = peer_and_group_lookup_vty(vty, argv[idx_peer]->arg);
3469 if (!peer)
3470 return CMD_WARNING_CONFIG_FAILED;
3471
3472 ret = peer_deactivate(peer, bgp_node_afi(vty), bgp_node_safi(vty));
3473 return bgp_vty_return(vty, ret);
3474 }
3475
3476 ALIAS_HIDDEN(no_neighbor_activate, no_neighbor_activate_hidden_cmd,
3477 "no neighbor <A.B.C.D|X:X::X:X|WORD> activate",
3478 NO_STR NEIGHBOR_STR NEIGHBOR_ADDR_STR2
3479 "Enable the Address Family for this Neighbor\n")
3480
3481 DEFUN (neighbor_set_peer_group,
3482 neighbor_set_peer_group_cmd,
3483 "neighbor <A.B.C.D|X:X::X:X|WORD> peer-group WORD",
3484 NEIGHBOR_STR
3485 NEIGHBOR_ADDR_STR2
3486 "Member of the peer-group\n"
3487 "Peer-group name\n")
3488 {
3489 VTY_DECLVAR_CONTEXT(bgp, bgp);
3490 int idx_peer = 1;
3491 int idx_word = 3;
3492 int ret;
3493 as_t as;
3494 union sockunion su;
3495 struct peer *peer;
3496 struct peer_group *group;
3497
3498 ret = str2sockunion(argv[idx_peer]->arg, &su);
3499 if (ret < 0) {
3500 peer = peer_lookup_by_conf_if(bgp, argv[idx_peer]->arg);
3501 if (!peer) {
3502 vty_out(vty, "%% Malformed address or name: %s\n",
3503 argv[idx_peer]->arg);
3504 return CMD_WARNING_CONFIG_FAILED;
3505 }
3506 } else {
3507 if (peer_address_self_check(bgp, &su)) {
3508 vty_out(vty,
3509 "%% Can not configure the local system as neighbor\n");
3510 return CMD_WARNING_CONFIG_FAILED;
3511 }
3512
3513 /* Disallow for dynamic neighbor. */
3514 peer = peer_lookup(bgp, &su);
3515 if (peer && peer_dynamic_neighbor(peer)) {
3516 vty_out(vty,
3517 "%% Operation not allowed on a dynamic neighbor\n");
3518 return CMD_WARNING_CONFIG_FAILED;
3519 }
3520 }
3521
3522 group = peer_group_lookup(bgp, argv[idx_word]->arg);
3523 if (!group) {
3524 vty_out(vty, "%% Configure the peer-group first\n");
3525 return CMD_WARNING_CONFIG_FAILED;
3526 }
3527
3528 ret = peer_group_bind(bgp, &su, peer, group, &as);
3529
3530 if (ret == BGP_ERR_PEER_GROUP_PEER_TYPE_DIFFERENT) {
3531 vty_out(vty,
3532 "%% Peer with AS %u cannot be in this peer-group, members must be all internal or all external\n",
3533 as);
3534 return CMD_WARNING_CONFIG_FAILED;
3535 }
3536
3537 return bgp_vty_return(vty, ret);
3538 }
3539
3540 ALIAS_HIDDEN(neighbor_set_peer_group, neighbor_set_peer_group_hidden_cmd,
3541 "neighbor <A.B.C.D|X:X::X:X|WORD> peer-group WORD",
3542 NEIGHBOR_STR NEIGHBOR_ADDR_STR2
3543 "Member of the peer-group\n"
3544 "Peer-group name\n")
3545
3546 DEFUN (no_neighbor_set_peer_group,
3547 no_neighbor_set_peer_group_cmd,
3548 "no neighbor <A.B.C.D|X:X::X:X|WORD> peer-group WORD",
3549 NO_STR
3550 NEIGHBOR_STR
3551 NEIGHBOR_ADDR_STR2
3552 "Member of the peer-group\n"
3553 "Peer-group name\n")
3554 {
3555 VTY_DECLVAR_CONTEXT(bgp, bgp);
3556 int idx_peer = 2;
3557 int idx_word = 4;
3558 int ret;
3559 struct peer *peer;
3560 struct peer_group *group;
3561
3562 peer = peer_lookup_vty(vty, argv[idx_peer]->arg);
3563 if (!peer)
3564 return CMD_WARNING_CONFIG_FAILED;
3565
3566 group = peer_group_lookup(bgp, argv[idx_word]->arg);
3567 if (!group) {
3568 vty_out(vty, "%% Configure the peer-group first\n");
3569 return CMD_WARNING_CONFIG_FAILED;
3570 }
3571
3572 ret = peer_delete(peer);
3573
3574 return bgp_vty_return(vty, ret);
3575 }
3576
3577 ALIAS_HIDDEN(no_neighbor_set_peer_group, no_neighbor_set_peer_group_hidden_cmd,
3578 "no neighbor <A.B.C.D|X:X::X:X|WORD> peer-group WORD",
3579 NO_STR NEIGHBOR_STR NEIGHBOR_ADDR_STR2
3580 "Member of the peer-group\n"
3581 "Peer-group name\n")
3582
3583 static int peer_flag_modify_vty(struct vty *vty, const char *ip_str,
3584 uint32_t flag, int set)
3585 {
3586 int ret;
3587 struct peer *peer;
3588
3589 peer = peer_and_group_lookup_vty(vty, ip_str);
3590 if (!peer)
3591 return CMD_WARNING_CONFIG_FAILED;
3592
3593 /*
3594 * If 'neighbor <interface>', then this is for directly connected peers,
3595 * we should not accept disable-connected-check.
3596 */
3597 if (peer->conf_if && (flag == PEER_FLAG_DISABLE_CONNECTED_CHECK)) {
3598 vty_out(vty,
3599 "%s is directly connected peer, cannot accept disable-"
3600 "connected-check\n",
3601 ip_str);
3602 return CMD_WARNING_CONFIG_FAILED;
3603 }
3604
3605 if (!set && flag == PEER_FLAG_SHUTDOWN)
3606 peer_tx_shutdown_message_unset(peer);
3607
3608 if (set)
3609 ret = peer_flag_set(peer, flag);
3610 else
3611 ret = peer_flag_unset(peer, flag);
3612
3613 return bgp_vty_return(vty, ret);
3614 }
3615
3616 static int peer_flag_set_vty(struct vty *vty, const char *ip_str, uint32_t flag)
3617 {
3618 return peer_flag_modify_vty(vty, ip_str, flag, 1);
3619 }
3620
3621 static int peer_flag_unset_vty(struct vty *vty, const char *ip_str,
3622 uint32_t flag)
3623 {
3624 return peer_flag_modify_vty(vty, ip_str, flag, 0);
3625 }
3626
3627 /* neighbor passive. */
3628 DEFUN (neighbor_passive,
3629 neighbor_passive_cmd,
3630 "neighbor <A.B.C.D|X:X::X:X|WORD> passive",
3631 NEIGHBOR_STR
3632 NEIGHBOR_ADDR_STR2
3633 "Don't send open messages to this neighbor\n")
3634 {
3635 int idx_peer = 1;
3636 return peer_flag_set_vty(vty, argv[idx_peer]->arg, PEER_FLAG_PASSIVE);
3637 }
3638
3639 DEFUN (no_neighbor_passive,
3640 no_neighbor_passive_cmd,
3641 "no neighbor <A.B.C.D|X:X::X:X|WORD> passive",
3642 NO_STR
3643 NEIGHBOR_STR
3644 NEIGHBOR_ADDR_STR2
3645 "Don't send open messages to this neighbor\n")
3646 {
3647 int idx_peer = 2;
3648 return peer_flag_unset_vty(vty, argv[idx_peer]->arg, PEER_FLAG_PASSIVE);
3649 }
3650
3651 /* neighbor shutdown. */
3652 DEFUN (neighbor_shutdown_msg,
3653 neighbor_shutdown_msg_cmd,
3654 "neighbor <A.B.C.D|X:X::X:X|WORD> shutdown message MSG...",
3655 NEIGHBOR_STR
3656 NEIGHBOR_ADDR_STR2
3657 "Administratively shut down this neighbor\n"
3658 "Add a shutdown message (draft-ietf-idr-shutdown-06)\n"
3659 "Shutdown message\n")
3660 {
3661 int idx_peer = 1;
3662
3663 if (argc >= 5) {
3664 struct peer *peer =
3665 peer_and_group_lookup_vty(vty, argv[idx_peer]->arg);
3666 char *message;
3667
3668 if (!peer)
3669 return CMD_WARNING_CONFIG_FAILED;
3670 message = argv_concat(argv, argc, 4);
3671 peer_tx_shutdown_message_set(peer, message);
3672 XFREE(MTYPE_TMP, message);
3673 }
3674
3675 return peer_flag_set_vty(vty, argv[idx_peer]->arg, PEER_FLAG_SHUTDOWN);
3676 }
3677
3678 ALIAS(neighbor_shutdown_msg, neighbor_shutdown_cmd,
3679 "neighbor <A.B.C.D|X:X::X:X|WORD> shutdown",
3680 NEIGHBOR_STR NEIGHBOR_ADDR_STR2
3681 "Administratively shut down this neighbor\n")
3682
3683 DEFUN (no_neighbor_shutdown_msg,
3684 no_neighbor_shutdown_msg_cmd,
3685 "no neighbor <A.B.C.D|X:X::X:X|WORD> shutdown message MSG...",
3686 NO_STR
3687 NEIGHBOR_STR
3688 NEIGHBOR_ADDR_STR2
3689 "Administratively shut down this neighbor\n"
3690 "Remove a shutdown message (draft-ietf-idr-shutdown-06)\n"
3691 "Shutdown message\n")
3692 {
3693 int idx_peer = 2;
3694
3695 return peer_flag_unset_vty(vty, argv[idx_peer]->arg,
3696 PEER_FLAG_SHUTDOWN);
3697 }
3698
3699 ALIAS(no_neighbor_shutdown_msg, no_neighbor_shutdown_cmd,
3700 "no neighbor <A.B.C.D|X:X::X:X|WORD> shutdown",
3701 NO_STR NEIGHBOR_STR NEIGHBOR_ADDR_STR2
3702 "Administratively shut down this neighbor\n")
3703
3704 /* neighbor capability dynamic. */
3705 DEFUN (neighbor_capability_dynamic,
3706 neighbor_capability_dynamic_cmd,
3707 "neighbor <A.B.C.D|X:X::X:X|WORD> capability dynamic",
3708 NEIGHBOR_STR
3709 NEIGHBOR_ADDR_STR2
3710 "Advertise capability to the peer\n"
3711 "Advertise dynamic capability to this neighbor\n")
3712 {
3713 int idx_peer = 1;
3714 return peer_flag_set_vty(vty, argv[idx_peer]->arg,
3715 PEER_FLAG_DYNAMIC_CAPABILITY);
3716 }
3717
3718 DEFUN (no_neighbor_capability_dynamic,
3719 no_neighbor_capability_dynamic_cmd,
3720 "no neighbor <A.B.C.D|X:X::X:X|WORD> capability dynamic",
3721 NO_STR
3722 NEIGHBOR_STR
3723 NEIGHBOR_ADDR_STR2
3724 "Advertise capability to the peer\n"
3725 "Advertise dynamic capability to this neighbor\n")
3726 {
3727 int idx_peer = 2;
3728 return peer_flag_unset_vty(vty, argv[idx_peer]->arg,
3729 PEER_FLAG_DYNAMIC_CAPABILITY);
3730 }
3731
3732 /* neighbor dont-capability-negotiate */
3733 DEFUN (neighbor_dont_capability_negotiate,
3734 neighbor_dont_capability_negotiate_cmd,
3735 "neighbor <A.B.C.D|X:X::X:X|WORD> dont-capability-negotiate",
3736 NEIGHBOR_STR
3737 NEIGHBOR_ADDR_STR2
3738 "Do not perform capability negotiation\n")
3739 {
3740 int idx_peer = 1;
3741 return peer_flag_set_vty(vty, argv[idx_peer]->arg,
3742 PEER_FLAG_DONT_CAPABILITY);
3743 }
3744
3745 DEFUN (no_neighbor_dont_capability_negotiate,
3746 no_neighbor_dont_capability_negotiate_cmd,
3747 "no neighbor <A.B.C.D|X:X::X:X|WORD> dont-capability-negotiate",
3748 NO_STR
3749 NEIGHBOR_STR
3750 NEIGHBOR_ADDR_STR2
3751 "Do not perform capability negotiation\n")
3752 {
3753 int idx_peer = 2;
3754 return peer_flag_unset_vty(vty, argv[idx_peer]->arg,
3755 PEER_FLAG_DONT_CAPABILITY);
3756 }
3757
3758 /* neighbor capability extended next hop encoding */
3759 DEFUN (neighbor_capability_enhe,
3760 neighbor_capability_enhe_cmd,
3761 "neighbor <A.B.C.D|X:X::X:X|WORD> capability extended-nexthop",
3762 NEIGHBOR_STR
3763 NEIGHBOR_ADDR_STR2
3764 "Advertise capability to the peer\n"
3765 "Advertise extended next-hop capability to the peer\n")
3766 {
3767 int idx_peer = 1;
3768 return peer_flag_set_vty(vty, argv[idx_peer]->arg,
3769 PEER_FLAG_CAPABILITY_ENHE);
3770 }
3771
3772 DEFUN (no_neighbor_capability_enhe,
3773 no_neighbor_capability_enhe_cmd,
3774 "no neighbor <A.B.C.D|X:X::X:X|WORD> capability extended-nexthop",
3775 NO_STR
3776 NEIGHBOR_STR
3777 NEIGHBOR_ADDR_STR2
3778 "Advertise capability to the peer\n"
3779 "Advertise extended next-hop capability to the peer\n")
3780 {
3781 int idx_peer = 2;
3782 return peer_flag_unset_vty(vty, argv[idx_peer]->arg,
3783 PEER_FLAG_CAPABILITY_ENHE);
3784 }
3785
3786 static int peer_af_flag_modify_vty(struct vty *vty, const char *peer_str,
3787 afi_t afi, safi_t safi, uint32_t flag,
3788 int set)
3789 {
3790 int ret;
3791 struct peer *peer;
3792
3793 peer = peer_and_group_lookup_vty(vty, peer_str);
3794 if (!peer)
3795 return CMD_WARNING_CONFIG_FAILED;
3796
3797 if (set)
3798 ret = peer_af_flag_set(peer, afi, safi, flag);
3799 else
3800 ret = peer_af_flag_unset(peer, afi, safi, flag);
3801
3802 return bgp_vty_return(vty, ret);
3803 }
3804
3805 static int peer_af_flag_set_vty(struct vty *vty, const char *peer_str,
3806 afi_t afi, safi_t safi, uint32_t flag)
3807 {
3808 return peer_af_flag_modify_vty(vty, peer_str, afi, safi, flag, 1);
3809 }
3810
3811 static int peer_af_flag_unset_vty(struct vty *vty, const char *peer_str,
3812 afi_t afi, safi_t safi, uint32_t flag)
3813 {
3814 return peer_af_flag_modify_vty(vty, peer_str, afi, safi, flag, 0);
3815 }
3816
3817 /* neighbor capability orf prefix-list. */
3818 DEFUN (neighbor_capability_orf_prefix,
3819 neighbor_capability_orf_prefix_cmd,
3820 "neighbor <A.B.C.D|X:X::X:X|WORD> capability orf prefix-list <both|send|receive>",
3821 NEIGHBOR_STR
3822 NEIGHBOR_ADDR_STR2
3823 "Advertise capability to the peer\n"
3824 "Advertise ORF capability to the peer\n"
3825 "Advertise prefixlist ORF capability to this neighbor\n"
3826 "Capability to SEND and RECEIVE the ORF to/from this neighbor\n"
3827 "Capability to RECEIVE the ORF from this neighbor\n"
3828 "Capability to SEND the ORF to this neighbor\n")
3829 {
3830 int idx_peer = 1;
3831 int idx_send_recv = 5;
3832 uint16_t flag = 0;
3833
3834 if (strmatch(argv[idx_send_recv]->text, "send"))
3835 flag = PEER_FLAG_ORF_PREFIX_SM;
3836 else if (strmatch(argv[idx_send_recv]->text, "receive"))
3837 flag = PEER_FLAG_ORF_PREFIX_RM;
3838 else if (strmatch(argv[idx_send_recv]->text, "both"))
3839 flag = PEER_FLAG_ORF_PREFIX_SM | PEER_FLAG_ORF_PREFIX_RM;
3840 else {
3841 vty_out(vty, "%% BGP invalid orf prefix-list option\n");
3842 return CMD_WARNING_CONFIG_FAILED;
3843 }
3844
3845 return peer_af_flag_set_vty(vty, argv[idx_peer]->arg, bgp_node_afi(vty),
3846 bgp_node_safi(vty), flag);
3847 }
3848
3849 ALIAS_HIDDEN(
3850 neighbor_capability_orf_prefix,
3851 neighbor_capability_orf_prefix_hidden_cmd,
3852 "neighbor <A.B.C.D|X:X::X:X|WORD> capability orf prefix-list <both|send|receive>",
3853 NEIGHBOR_STR NEIGHBOR_ADDR_STR2
3854 "Advertise capability to the peer\n"
3855 "Advertise ORF capability to the peer\n"
3856 "Advertise prefixlist ORF capability to this neighbor\n"
3857 "Capability to SEND and RECEIVE the ORF to/from this neighbor\n"
3858 "Capability to RECEIVE the ORF from this neighbor\n"
3859 "Capability to SEND the ORF to this neighbor\n")
3860
3861 DEFUN (no_neighbor_capability_orf_prefix,
3862 no_neighbor_capability_orf_prefix_cmd,
3863 "no neighbor <A.B.C.D|X:X::X:X|WORD> capability orf prefix-list <both|send|receive>",
3864 NO_STR
3865 NEIGHBOR_STR
3866 NEIGHBOR_ADDR_STR2
3867 "Advertise capability to the peer\n"
3868 "Advertise ORF capability to the peer\n"
3869 "Advertise prefixlist ORF capability to this neighbor\n"
3870 "Capability to SEND and RECEIVE the ORF to/from this neighbor\n"
3871 "Capability to RECEIVE the ORF from this neighbor\n"
3872 "Capability to SEND the ORF to this neighbor\n")
3873 {
3874 int idx_peer = 2;
3875 int idx_send_recv = 6;
3876 uint16_t flag = 0;
3877
3878 if (strmatch(argv[idx_send_recv]->text, "send"))
3879 flag = PEER_FLAG_ORF_PREFIX_SM;
3880 else if (strmatch(argv[idx_send_recv]->text, "receive"))
3881 flag = PEER_FLAG_ORF_PREFIX_RM;
3882 else if (strmatch(argv[idx_send_recv]->text, "both"))
3883 flag = PEER_FLAG_ORF_PREFIX_SM | PEER_FLAG_ORF_PREFIX_RM;
3884 else {
3885 vty_out(vty, "%% BGP invalid orf prefix-list option\n");
3886 return CMD_WARNING_CONFIG_FAILED;
3887 }
3888
3889 return peer_af_flag_unset_vty(vty, argv[idx_peer]->arg,
3890 bgp_node_afi(vty), bgp_node_safi(vty),
3891 flag);
3892 }
3893
3894 ALIAS_HIDDEN(
3895 no_neighbor_capability_orf_prefix,
3896 no_neighbor_capability_orf_prefix_hidden_cmd,
3897 "no neighbor <A.B.C.D|X:X::X:X|WORD> capability orf prefix-list <both|send|receive>",
3898 NO_STR NEIGHBOR_STR NEIGHBOR_ADDR_STR2
3899 "Advertise capability to the peer\n"
3900 "Advertise ORF capability to the peer\n"
3901 "Advertise prefixlist ORF capability to this neighbor\n"
3902 "Capability to SEND and RECEIVE the ORF to/from this neighbor\n"
3903 "Capability to RECEIVE the ORF from this neighbor\n"
3904 "Capability to SEND the ORF to this neighbor\n")
3905
3906 /* neighbor next-hop-self. */
3907 DEFUN (neighbor_nexthop_self,
3908 neighbor_nexthop_self_cmd,
3909 "neighbor <A.B.C.D|X:X::X:X|WORD> next-hop-self",
3910 NEIGHBOR_STR
3911 NEIGHBOR_ADDR_STR2
3912 "Disable the next hop calculation for this neighbor\n")
3913 {
3914 int idx_peer = 1;
3915 return peer_af_flag_set_vty(vty, argv[idx_peer]->arg, bgp_node_afi(vty),
3916 bgp_node_safi(vty), PEER_FLAG_NEXTHOP_SELF);
3917 }
3918
3919 ALIAS_HIDDEN(neighbor_nexthop_self, neighbor_nexthop_self_hidden_cmd,
3920 "neighbor <A.B.C.D|X:X::X:X|WORD> next-hop-self",
3921 NEIGHBOR_STR NEIGHBOR_ADDR_STR2
3922 "Disable the next hop calculation for this neighbor\n")
3923
3924 /* neighbor next-hop-self. */
3925 DEFUN (neighbor_nexthop_self_force,
3926 neighbor_nexthop_self_force_cmd,
3927 "neighbor <A.B.C.D|X:X::X:X|WORD> next-hop-self force",
3928 NEIGHBOR_STR
3929 NEIGHBOR_ADDR_STR2
3930 "Disable the next hop calculation for this neighbor\n"
3931 "Set the next hop to self for reflected routes\n")
3932 {
3933 int idx_peer = 1;
3934 return peer_af_flag_set_vty(vty, argv[idx_peer]->arg, bgp_node_afi(vty),
3935 bgp_node_safi(vty),
3936 PEER_FLAG_FORCE_NEXTHOP_SELF);
3937 }
3938
3939 ALIAS_HIDDEN(neighbor_nexthop_self_force,
3940 neighbor_nexthop_self_force_hidden_cmd,
3941 "neighbor <A.B.C.D|X:X::X:X|WORD> next-hop-self force",
3942 NEIGHBOR_STR NEIGHBOR_ADDR_STR2
3943 "Disable the next hop calculation for this neighbor\n"
3944 "Set the next hop to self for reflected routes\n")
3945
3946 ALIAS_HIDDEN(neighbor_nexthop_self_force,
3947 neighbor_nexthop_self_all_hidden_cmd,
3948 "neighbor <A.B.C.D|X:X::X:X|WORD> next-hop-self all",
3949 NEIGHBOR_STR NEIGHBOR_ADDR_STR2
3950 "Disable the next hop calculation for this neighbor\n"
3951 "Set the next hop to self for reflected routes\n")
3952
3953 DEFUN (no_neighbor_nexthop_self,
3954 no_neighbor_nexthop_self_cmd,
3955 "no neighbor <A.B.C.D|X:X::X:X|WORD> next-hop-self",
3956 NO_STR
3957 NEIGHBOR_STR
3958 NEIGHBOR_ADDR_STR2
3959 "Disable the next hop calculation for this neighbor\n")
3960 {
3961 int idx_peer = 2;
3962 return peer_af_flag_unset_vty(vty, argv[idx_peer]->arg,
3963 bgp_node_afi(vty), bgp_node_safi(vty),
3964 PEER_FLAG_NEXTHOP_SELF);
3965 }
3966
3967 ALIAS_HIDDEN(no_neighbor_nexthop_self, no_neighbor_nexthop_self_hidden_cmd,
3968 "no neighbor <A.B.C.D|X:X::X:X|WORD> next-hop-self",
3969 NO_STR NEIGHBOR_STR NEIGHBOR_ADDR_STR2
3970 "Disable the next hop calculation for this neighbor\n")
3971
3972 DEFUN (no_neighbor_nexthop_self_force,
3973 no_neighbor_nexthop_self_force_cmd,
3974 "no neighbor <A.B.C.D|X:X::X:X|WORD> next-hop-self force",
3975 NO_STR
3976 NEIGHBOR_STR
3977 NEIGHBOR_ADDR_STR2
3978 "Disable the next hop calculation for this neighbor\n"
3979 "Set the next hop to self for reflected routes\n")
3980 {
3981 int idx_peer = 2;
3982 return peer_af_flag_unset_vty(vty, argv[idx_peer]->arg,
3983 bgp_node_afi(vty), bgp_node_safi(vty),
3984 PEER_FLAG_FORCE_NEXTHOP_SELF);
3985 }
3986
3987 ALIAS_HIDDEN(no_neighbor_nexthop_self_force,
3988 no_neighbor_nexthop_self_force_hidden_cmd,
3989 "no neighbor <A.B.C.D|X:X::X:X|WORD> next-hop-self force",
3990 NO_STR NEIGHBOR_STR NEIGHBOR_ADDR_STR2
3991 "Disable the next hop calculation for this neighbor\n"
3992 "Set the next hop to self for reflected routes\n")
3993
3994 ALIAS_HIDDEN(no_neighbor_nexthop_self_force,
3995 no_neighbor_nexthop_self_all_hidden_cmd,
3996 "no neighbor <A.B.C.D|X:X::X:X|WORD> next-hop-self all",
3997 NO_STR NEIGHBOR_STR NEIGHBOR_ADDR_STR2
3998 "Disable the next hop calculation for this neighbor\n"
3999 "Set the next hop to self for reflected routes\n")
4000
4001 /* neighbor as-override */
4002 DEFUN (neighbor_as_override,
4003 neighbor_as_override_cmd,
4004 "neighbor <A.B.C.D|X:X::X:X|WORD> as-override",
4005 NEIGHBOR_STR
4006 NEIGHBOR_ADDR_STR2
4007 "Override ASNs in outbound updates if aspath equals remote-as\n")
4008 {
4009 int idx_peer = 1;
4010 return peer_af_flag_set_vty(vty, argv[idx_peer]->arg, bgp_node_afi(vty),
4011 bgp_node_safi(vty), PEER_FLAG_AS_OVERRIDE);
4012 }
4013
4014 ALIAS_HIDDEN(neighbor_as_override, neighbor_as_override_hidden_cmd,
4015 "neighbor <A.B.C.D|X:X::X:X|WORD> as-override",
4016 NEIGHBOR_STR NEIGHBOR_ADDR_STR2
4017 "Override ASNs in outbound updates if aspath equals remote-as\n")
4018
4019 DEFUN (no_neighbor_as_override,
4020 no_neighbor_as_override_cmd,
4021 "no neighbor <A.B.C.D|X:X::X:X|WORD> as-override",
4022 NO_STR
4023 NEIGHBOR_STR
4024 NEIGHBOR_ADDR_STR2
4025 "Override ASNs in outbound updates if aspath equals remote-as\n")
4026 {
4027 int idx_peer = 2;
4028 return peer_af_flag_unset_vty(vty, argv[idx_peer]->arg,
4029 bgp_node_afi(vty), bgp_node_safi(vty),
4030 PEER_FLAG_AS_OVERRIDE);
4031 }
4032
4033 ALIAS_HIDDEN(no_neighbor_as_override, no_neighbor_as_override_hidden_cmd,
4034 "no neighbor <A.B.C.D|X:X::X:X|WORD> as-override",
4035 NO_STR NEIGHBOR_STR NEIGHBOR_ADDR_STR2
4036 "Override ASNs in outbound updates if aspath equals remote-as\n")
4037
4038 /* neighbor remove-private-AS. */
4039 DEFUN (neighbor_remove_private_as,
4040 neighbor_remove_private_as_cmd,
4041 "neighbor <A.B.C.D|X:X::X:X|WORD> remove-private-AS",
4042 NEIGHBOR_STR
4043 NEIGHBOR_ADDR_STR2
4044 "Remove private ASNs in outbound updates\n")
4045 {
4046 int idx_peer = 1;
4047 return peer_af_flag_set_vty(vty, argv[idx_peer]->arg, bgp_node_afi(vty),
4048 bgp_node_safi(vty),
4049 PEER_FLAG_REMOVE_PRIVATE_AS);
4050 }
4051
4052 ALIAS_HIDDEN(neighbor_remove_private_as, neighbor_remove_private_as_hidden_cmd,
4053 "neighbor <A.B.C.D|X:X::X:X|WORD> remove-private-AS",
4054 NEIGHBOR_STR NEIGHBOR_ADDR_STR2
4055 "Remove private ASNs in outbound updates\n")
4056
4057 DEFUN (neighbor_remove_private_as_all,
4058 neighbor_remove_private_as_all_cmd,
4059 "neighbor <A.B.C.D|X:X::X:X|WORD> remove-private-AS all",
4060 NEIGHBOR_STR
4061 NEIGHBOR_ADDR_STR2
4062 "Remove private ASNs in outbound updates\n"
4063 "Apply to all AS numbers\n")
4064 {
4065 int idx_peer = 1;
4066 return peer_af_flag_set_vty(vty, argv[idx_peer]->arg, bgp_node_afi(vty),
4067 bgp_node_safi(vty),
4068 PEER_FLAG_REMOVE_PRIVATE_AS_ALL);
4069 }
4070
4071 ALIAS_HIDDEN(neighbor_remove_private_as_all,
4072 neighbor_remove_private_as_all_hidden_cmd,
4073 "neighbor <A.B.C.D|X:X::X:X|WORD> remove-private-AS all",
4074 NEIGHBOR_STR NEIGHBOR_ADDR_STR2
4075 "Remove private ASNs in outbound updates\n"
4076 "Apply to all AS numbers")
4077
4078 DEFUN (neighbor_remove_private_as_replace_as,
4079 neighbor_remove_private_as_replace_as_cmd,
4080 "neighbor <A.B.C.D|X:X::X:X|WORD> remove-private-AS replace-AS",
4081 NEIGHBOR_STR
4082 NEIGHBOR_ADDR_STR2
4083 "Remove private ASNs in outbound updates\n"
4084 "Replace private ASNs with our ASN in outbound updates\n")
4085 {
4086 int idx_peer = 1;
4087 return peer_af_flag_set_vty(vty, argv[idx_peer]->arg, bgp_node_afi(vty),
4088 bgp_node_safi(vty),
4089 PEER_FLAG_REMOVE_PRIVATE_AS_REPLACE);
4090 }
4091
4092 ALIAS_HIDDEN(neighbor_remove_private_as_replace_as,
4093 neighbor_remove_private_as_replace_as_hidden_cmd,
4094 "neighbor <A.B.C.D|X:X::X:X|WORD> remove-private-AS replace-AS",
4095 NEIGHBOR_STR NEIGHBOR_ADDR_STR2
4096 "Remove private ASNs in outbound updates\n"
4097 "Replace private ASNs with our ASN in outbound updates\n")
4098
4099 DEFUN (neighbor_remove_private_as_all_replace_as,
4100 neighbor_remove_private_as_all_replace_as_cmd,
4101 "neighbor <A.B.C.D|X:X::X:X|WORD> remove-private-AS all replace-AS",
4102 NEIGHBOR_STR
4103 NEIGHBOR_ADDR_STR2
4104 "Remove private ASNs in outbound updates\n"
4105 "Apply to all AS numbers\n"
4106 "Replace private ASNs with our ASN in outbound updates\n")
4107 {
4108 int idx_peer = 1;
4109 return peer_af_flag_set_vty(vty, argv[idx_peer]->arg, bgp_node_afi(vty),
4110 bgp_node_safi(vty),
4111 PEER_FLAG_REMOVE_PRIVATE_AS_ALL_REPLACE);
4112 }
4113
4114 ALIAS_HIDDEN(
4115 neighbor_remove_private_as_all_replace_as,
4116 neighbor_remove_private_as_all_replace_as_hidden_cmd,
4117 "neighbor <A.B.C.D|X:X::X:X|WORD> remove-private-AS all replace-AS",
4118 NEIGHBOR_STR NEIGHBOR_ADDR_STR2
4119 "Remove private ASNs in outbound updates\n"
4120 "Apply to all AS numbers\n"
4121 "Replace private ASNs with our ASN in outbound updates\n")
4122
4123 DEFUN (no_neighbor_remove_private_as,
4124 no_neighbor_remove_private_as_cmd,
4125 "no neighbor <A.B.C.D|X:X::X:X|WORD> remove-private-AS",
4126 NO_STR
4127 NEIGHBOR_STR
4128 NEIGHBOR_ADDR_STR2
4129 "Remove private ASNs in outbound updates\n")
4130 {
4131 int idx_peer = 2;
4132 return peer_af_flag_unset_vty(vty, argv[idx_peer]->arg,
4133 bgp_node_afi(vty), bgp_node_safi(vty),
4134 PEER_FLAG_REMOVE_PRIVATE_AS);
4135 }
4136
4137 ALIAS_HIDDEN(no_neighbor_remove_private_as,
4138 no_neighbor_remove_private_as_hidden_cmd,
4139 "no neighbor <A.B.C.D|X:X::X:X|WORD> remove-private-AS",
4140 NO_STR NEIGHBOR_STR NEIGHBOR_ADDR_STR2
4141 "Remove private ASNs in outbound updates\n")
4142
4143 DEFUN (no_neighbor_remove_private_as_all,
4144 no_neighbor_remove_private_as_all_cmd,
4145 "no neighbor <A.B.C.D|X:X::X:X|WORD> remove-private-AS all",
4146 NO_STR
4147 NEIGHBOR_STR
4148 NEIGHBOR_ADDR_STR2
4149 "Remove private ASNs in outbound updates\n"
4150 "Apply to all AS numbers\n")
4151 {
4152 int idx_peer = 2;
4153 return peer_af_flag_unset_vty(vty, argv[idx_peer]->arg,
4154 bgp_node_afi(vty), bgp_node_safi(vty),
4155 PEER_FLAG_REMOVE_PRIVATE_AS_ALL);
4156 }
4157
4158 ALIAS_HIDDEN(no_neighbor_remove_private_as_all,
4159 no_neighbor_remove_private_as_all_hidden_cmd,
4160 "no neighbor <A.B.C.D|X:X::X:X|WORD> remove-private-AS all",
4161 NO_STR NEIGHBOR_STR NEIGHBOR_ADDR_STR2
4162 "Remove private ASNs in outbound updates\n"
4163 "Apply to all AS numbers\n")
4164
4165 DEFUN (no_neighbor_remove_private_as_replace_as,
4166 no_neighbor_remove_private_as_replace_as_cmd,
4167 "no neighbor <A.B.C.D|X:X::X:X|WORD> remove-private-AS replace-AS",
4168 NO_STR
4169 NEIGHBOR_STR
4170 NEIGHBOR_ADDR_STR2
4171 "Remove private ASNs in outbound updates\n"
4172 "Replace private ASNs with our ASN in outbound updates\n")
4173 {
4174 int idx_peer = 2;
4175 return peer_af_flag_unset_vty(vty, argv[idx_peer]->arg,
4176 bgp_node_afi(vty), bgp_node_safi(vty),
4177 PEER_FLAG_REMOVE_PRIVATE_AS_REPLACE);
4178 }
4179
4180 ALIAS_HIDDEN(no_neighbor_remove_private_as_replace_as,
4181 no_neighbor_remove_private_as_replace_as_hidden_cmd,
4182 "no neighbor <A.B.C.D|X:X::X:X|WORD> remove-private-AS replace-AS",
4183 NO_STR NEIGHBOR_STR NEIGHBOR_ADDR_STR2
4184 "Remove private ASNs in outbound updates\n"
4185 "Replace private ASNs with our ASN in outbound updates\n")
4186
4187 DEFUN (no_neighbor_remove_private_as_all_replace_as,
4188 no_neighbor_remove_private_as_all_replace_as_cmd,
4189 "no neighbor <A.B.C.D|X:X::X:X|WORD> remove-private-AS all replace-AS",
4190 NO_STR
4191 NEIGHBOR_STR
4192 NEIGHBOR_ADDR_STR2
4193 "Remove private ASNs in outbound updates\n"
4194 "Apply to all AS numbers\n"
4195 "Replace private ASNs with our ASN in outbound updates\n")
4196 {
4197 int idx_peer = 2;
4198 return peer_af_flag_unset_vty(vty, argv[idx_peer]->arg,
4199 bgp_node_afi(vty), bgp_node_safi(vty),
4200 PEER_FLAG_REMOVE_PRIVATE_AS_ALL_REPLACE);
4201 }
4202
4203 ALIAS_HIDDEN(
4204 no_neighbor_remove_private_as_all_replace_as,
4205 no_neighbor_remove_private_as_all_replace_as_hidden_cmd,
4206 "no neighbor <A.B.C.D|X:X::X:X|WORD> remove-private-AS all replace-AS",
4207 NO_STR NEIGHBOR_STR NEIGHBOR_ADDR_STR2
4208 "Remove private ASNs in outbound updates\n"
4209 "Apply to all AS numbers\n"
4210 "Replace private ASNs with our ASN in outbound updates\n")
4211
4212
4213 /* neighbor send-community. */
4214 DEFUN (neighbor_send_community,
4215 neighbor_send_community_cmd,
4216 "neighbor <A.B.C.D|X:X::X:X|WORD> send-community",
4217 NEIGHBOR_STR
4218 NEIGHBOR_ADDR_STR2
4219 "Send Community attribute to this neighbor\n")
4220 {
4221 int idx_peer = 1;
4222
4223 return peer_af_flag_set_vty(vty, argv[idx_peer]->arg, bgp_node_afi(vty),
4224 bgp_node_safi(vty),
4225 PEER_FLAG_SEND_COMMUNITY);
4226 }
4227
4228 ALIAS_HIDDEN(neighbor_send_community, neighbor_send_community_hidden_cmd,
4229 "neighbor <A.B.C.D|X:X::X:X|WORD> send-community",
4230 NEIGHBOR_STR NEIGHBOR_ADDR_STR2
4231 "Send Community attribute to this neighbor\n")
4232
4233 DEFUN (no_neighbor_send_community,
4234 no_neighbor_send_community_cmd,
4235 "no neighbor <A.B.C.D|X:X::X:X|WORD> send-community",
4236 NO_STR
4237 NEIGHBOR_STR
4238 NEIGHBOR_ADDR_STR2
4239 "Send Community attribute to this neighbor\n")
4240 {
4241 int idx_peer = 2;
4242
4243 return peer_af_flag_unset_vty(vty, argv[idx_peer]->arg,
4244 bgp_node_afi(vty), bgp_node_safi(vty),
4245 PEER_FLAG_SEND_COMMUNITY);
4246 }
4247
4248 ALIAS_HIDDEN(no_neighbor_send_community, no_neighbor_send_community_hidden_cmd,
4249 "no neighbor <A.B.C.D|X:X::X:X|WORD> send-community",
4250 NO_STR NEIGHBOR_STR NEIGHBOR_ADDR_STR2
4251 "Send Community attribute to this neighbor\n")
4252
4253 /* neighbor send-community extended. */
4254 DEFUN (neighbor_send_community_type,
4255 neighbor_send_community_type_cmd,
4256 "neighbor <A.B.C.D|X:X::X:X|WORD> send-community <both|all|extended|standard|large>",
4257 NEIGHBOR_STR
4258 NEIGHBOR_ADDR_STR2
4259 "Send Community attribute to this neighbor\n"
4260 "Send Standard and Extended Community attributes\n"
4261 "Send Standard, Large and Extended Community attributes\n"
4262 "Send Extended Community attributes\n"
4263 "Send Standard Community attributes\n"
4264 "Send Large Community attributes\n")
4265 {
4266 int idx_peer = 1;
4267 uint32_t flag = 0;
4268 const char *type = argv[argc - 1]->text;
4269
4270 if (strmatch(type, "standard")) {
4271 SET_FLAG(flag, PEER_FLAG_SEND_COMMUNITY);
4272 } else if (strmatch(type, "extended")) {
4273 SET_FLAG(flag, PEER_FLAG_SEND_EXT_COMMUNITY);
4274 } else if (strmatch(type, "large")) {
4275 SET_FLAG(flag, PEER_FLAG_SEND_LARGE_COMMUNITY);
4276 } else if (strmatch(type, "both")) {
4277 SET_FLAG(flag, PEER_FLAG_SEND_COMMUNITY);
4278 SET_FLAG(flag, PEER_FLAG_SEND_EXT_COMMUNITY);
4279 } else { /* if (strmatch(type, "all")) */
4280 SET_FLAG(flag, PEER_FLAG_SEND_COMMUNITY);
4281 SET_FLAG(flag, PEER_FLAG_SEND_EXT_COMMUNITY);
4282 SET_FLAG(flag, PEER_FLAG_SEND_LARGE_COMMUNITY);
4283 }
4284
4285 return peer_af_flag_set_vty(vty, argv[idx_peer]->arg, bgp_node_afi(vty),
4286 bgp_node_safi(vty), flag);
4287 }
4288
4289 ALIAS_HIDDEN(
4290 neighbor_send_community_type, neighbor_send_community_type_hidden_cmd,
4291 "neighbor <A.B.C.D|X:X::X:X|WORD> send-community <both|all|extended|standard|large>",
4292 NEIGHBOR_STR NEIGHBOR_ADDR_STR2
4293 "Send Community attribute to this neighbor\n"
4294 "Send Standard and Extended Community attributes\n"
4295 "Send Standard, Large and Extended Community attributes\n"
4296 "Send Extended Community attributes\n"
4297 "Send Standard Community attributes\n"
4298 "Send Large Community attributes\n")
4299
4300 DEFUN (no_neighbor_send_community_type,
4301 no_neighbor_send_community_type_cmd,
4302 "no neighbor <A.B.C.D|X:X::X:X|WORD> send-community <both|all|extended|standard|large>",
4303 NO_STR
4304 NEIGHBOR_STR
4305 NEIGHBOR_ADDR_STR2
4306 "Send Community attribute to this neighbor\n"
4307 "Send Standard and Extended Community attributes\n"
4308 "Send Standard, Large and Extended Community attributes\n"
4309 "Send Extended Community attributes\n"
4310 "Send Standard Community attributes\n"
4311 "Send Large Community attributes\n")
4312 {
4313 int idx_peer = 2;
4314 uint32_t flag = 0;
4315 const char *type = argv[argc - 1]->text;
4316
4317 if (strmatch(type, "standard")) {
4318 SET_FLAG(flag, PEER_FLAG_SEND_COMMUNITY);
4319 } else if (strmatch(type, "extended")) {
4320 SET_FLAG(flag, PEER_FLAG_SEND_EXT_COMMUNITY);
4321 } else if (strmatch(type, "large")) {
4322 SET_FLAG(flag, PEER_FLAG_SEND_LARGE_COMMUNITY);
4323 } else if (strmatch(type, "both")) {
4324 SET_FLAG(flag, PEER_FLAG_SEND_COMMUNITY);
4325 SET_FLAG(flag, PEER_FLAG_SEND_EXT_COMMUNITY);
4326 } else { /* if (strmatch(type, "all")) */
4327 SET_FLAG(flag, PEER_FLAG_SEND_COMMUNITY);
4328 SET_FLAG(flag, PEER_FLAG_SEND_EXT_COMMUNITY);
4329 SET_FLAG(flag, PEER_FLAG_SEND_LARGE_COMMUNITY);
4330 }
4331
4332 return peer_af_flag_unset_vty(vty, argv[idx_peer]->arg,
4333 bgp_node_afi(vty), bgp_node_safi(vty),
4334 flag);
4335 }
4336
4337 ALIAS_HIDDEN(
4338 no_neighbor_send_community_type,
4339 no_neighbor_send_community_type_hidden_cmd,
4340 "no neighbor <A.B.C.D|X:X::X:X|WORD> send-community <both|all|extended|standard|large>",
4341 NO_STR NEIGHBOR_STR NEIGHBOR_ADDR_STR2
4342 "Send Community attribute to this neighbor\n"
4343 "Send Standard and Extended Community attributes\n"
4344 "Send Standard, Large and Extended Community attributes\n"
4345 "Send Extended Community attributes\n"
4346 "Send Standard Community attributes\n"
4347 "Send Large Community attributes\n")
4348
4349 /* neighbor soft-reconfig. */
4350 DEFUN (neighbor_soft_reconfiguration,
4351 neighbor_soft_reconfiguration_cmd,
4352 "neighbor <A.B.C.D|X:X::X:X|WORD> soft-reconfiguration inbound",
4353 NEIGHBOR_STR
4354 NEIGHBOR_ADDR_STR2
4355 "Per neighbor soft reconfiguration\n"
4356 "Allow inbound soft reconfiguration for this neighbor\n")
4357 {
4358 int idx_peer = 1;
4359 return peer_af_flag_set_vty(vty, argv[idx_peer]->arg, bgp_node_afi(vty),
4360 bgp_node_safi(vty),
4361 PEER_FLAG_SOFT_RECONFIG);
4362 }
4363
4364 ALIAS_HIDDEN(neighbor_soft_reconfiguration,
4365 neighbor_soft_reconfiguration_hidden_cmd,
4366 "neighbor <A.B.C.D|X:X::X:X|WORD> soft-reconfiguration inbound",
4367 NEIGHBOR_STR NEIGHBOR_ADDR_STR2
4368 "Per neighbor soft reconfiguration\n"
4369 "Allow inbound soft reconfiguration for this neighbor\n")
4370
4371 DEFUN (no_neighbor_soft_reconfiguration,
4372 no_neighbor_soft_reconfiguration_cmd,
4373 "no neighbor <A.B.C.D|X:X::X:X|WORD> soft-reconfiguration inbound",
4374 NO_STR
4375 NEIGHBOR_STR
4376 NEIGHBOR_ADDR_STR2
4377 "Per neighbor soft reconfiguration\n"
4378 "Allow inbound soft reconfiguration for this neighbor\n")
4379 {
4380 int idx_peer = 2;
4381 return peer_af_flag_unset_vty(vty, argv[idx_peer]->arg,
4382 bgp_node_afi(vty), bgp_node_safi(vty),
4383 PEER_FLAG_SOFT_RECONFIG);
4384 }
4385
4386 ALIAS_HIDDEN(no_neighbor_soft_reconfiguration,
4387 no_neighbor_soft_reconfiguration_hidden_cmd,
4388 "no neighbor <A.B.C.D|X:X::X:X|WORD> soft-reconfiguration inbound",
4389 NO_STR NEIGHBOR_STR NEIGHBOR_ADDR_STR2
4390 "Per neighbor soft reconfiguration\n"
4391 "Allow inbound soft reconfiguration for this neighbor\n")
4392
4393 DEFUN (neighbor_route_reflector_client,
4394 neighbor_route_reflector_client_cmd,
4395 "neighbor <A.B.C.D|X:X::X:X|WORD> route-reflector-client",
4396 NEIGHBOR_STR
4397 NEIGHBOR_ADDR_STR2
4398 "Configure a neighbor as Route Reflector client\n")
4399 {
4400 int idx_peer = 1;
4401 struct peer *peer;
4402
4403
4404 peer = peer_and_group_lookup_vty(vty, argv[idx_peer]->arg);
4405 if (!peer)
4406 return CMD_WARNING_CONFIG_FAILED;
4407
4408 return peer_af_flag_set_vty(vty, argv[idx_peer]->arg, bgp_node_afi(vty),
4409 bgp_node_safi(vty),
4410 PEER_FLAG_REFLECTOR_CLIENT);
4411 }
4412
4413 ALIAS_HIDDEN(neighbor_route_reflector_client,
4414 neighbor_route_reflector_client_hidden_cmd,
4415 "neighbor <A.B.C.D|X:X::X:X|WORD> route-reflector-client",
4416 NEIGHBOR_STR NEIGHBOR_ADDR_STR2
4417 "Configure a neighbor as Route Reflector client\n")
4418
4419 DEFUN (no_neighbor_route_reflector_client,
4420 no_neighbor_route_reflector_client_cmd,
4421 "no neighbor <A.B.C.D|X:X::X:X|WORD> route-reflector-client",
4422 NO_STR
4423 NEIGHBOR_STR
4424 NEIGHBOR_ADDR_STR2
4425 "Configure a neighbor as Route Reflector client\n")
4426 {
4427 int idx_peer = 2;
4428 return peer_af_flag_unset_vty(vty, argv[idx_peer]->arg,
4429 bgp_node_afi(vty), bgp_node_safi(vty),
4430 PEER_FLAG_REFLECTOR_CLIENT);
4431 }
4432
4433 ALIAS_HIDDEN(no_neighbor_route_reflector_client,
4434 no_neighbor_route_reflector_client_hidden_cmd,
4435 "no neighbor <A.B.C.D|X:X::X:X|WORD> route-reflector-client",
4436 NO_STR NEIGHBOR_STR NEIGHBOR_ADDR_STR2
4437 "Configure a neighbor as Route Reflector client\n")
4438
4439 /* neighbor route-server-client. */
4440 DEFUN (neighbor_route_server_client,
4441 neighbor_route_server_client_cmd,
4442 "neighbor <A.B.C.D|X:X::X:X|WORD> route-server-client",
4443 NEIGHBOR_STR
4444 NEIGHBOR_ADDR_STR2
4445 "Configure a neighbor as Route Server client\n")
4446 {
4447 int idx_peer = 1;
4448 struct peer *peer;
4449
4450 peer = peer_and_group_lookup_vty(vty, argv[idx_peer]->arg);
4451 if (!peer)
4452 return CMD_WARNING_CONFIG_FAILED;
4453 return peer_af_flag_set_vty(vty, argv[idx_peer]->arg, bgp_node_afi(vty),
4454 bgp_node_safi(vty),
4455 PEER_FLAG_RSERVER_CLIENT);
4456 }
4457
4458 ALIAS_HIDDEN(neighbor_route_server_client,
4459 neighbor_route_server_client_hidden_cmd,
4460 "neighbor <A.B.C.D|X:X::X:X|WORD> route-server-client",
4461 NEIGHBOR_STR NEIGHBOR_ADDR_STR2
4462 "Configure a neighbor as Route Server client\n")
4463
4464 DEFUN (no_neighbor_route_server_client,
4465 no_neighbor_route_server_client_cmd,
4466 "no neighbor <A.B.C.D|X:X::X:X|WORD> route-server-client",
4467 NO_STR
4468 NEIGHBOR_STR
4469 NEIGHBOR_ADDR_STR2
4470 "Configure a neighbor as Route Server client\n")
4471 {
4472 int idx_peer = 2;
4473 return peer_af_flag_unset_vty(vty, argv[idx_peer]->arg,
4474 bgp_node_afi(vty), bgp_node_safi(vty),
4475 PEER_FLAG_RSERVER_CLIENT);
4476 }
4477
4478 ALIAS_HIDDEN(no_neighbor_route_server_client,
4479 no_neighbor_route_server_client_hidden_cmd,
4480 "no neighbor <A.B.C.D|X:X::X:X|WORD> route-server-client",
4481 NO_STR NEIGHBOR_STR NEIGHBOR_ADDR_STR2
4482 "Configure a neighbor as Route Server client\n")
4483
4484 DEFUN (neighbor_nexthop_local_unchanged,
4485 neighbor_nexthop_local_unchanged_cmd,
4486 "neighbor <A.B.C.D|X:X::X:X|WORD> nexthop-local unchanged",
4487 NEIGHBOR_STR
4488 NEIGHBOR_ADDR_STR2
4489 "Configure treatment of outgoing link-local nexthop attribute\n"
4490 "Leave link-local nexthop unchanged for this peer\n")
4491 {
4492 int idx_peer = 1;
4493 return peer_af_flag_set_vty(vty, argv[idx_peer]->arg, bgp_node_afi(vty),
4494 bgp_node_safi(vty),
4495 PEER_FLAG_NEXTHOP_LOCAL_UNCHANGED);
4496 }
4497
4498 DEFUN (no_neighbor_nexthop_local_unchanged,
4499 no_neighbor_nexthop_local_unchanged_cmd,
4500 "no neighbor <A.B.C.D|X:X::X:X|WORD> nexthop-local unchanged",
4501 NO_STR
4502 NEIGHBOR_STR
4503 NEIGHBOR_ADDR_STR2
4504 "Configure treatment of outgoing link-local-nexthop attribute\n"
4505 "Leave link-local nexthop unchanged for this peer\n")
4506 {
4507 int idx_peer = 2;
4508 return peer_af_flag_unset_vty(vty, argv[idx_peer]->arg,
4509 bgp_node_afi(vty), bgp_node_safi(vty),
4510 PEER_FLAG_NEXTHOP_LOCAL_UNCHANGED);
4511 }
4512
4513 DEFUN (neighbor_attr_unchanged,
4514 neighbor_attr_unchanged_cmd,
4515 "neighbor <A.B.C.D|X:X::X:X|WORD> attribute-unchanged [{as-path|next-hop|med}]",
4516 NEIGHBOR_STR
4517 NEIGHBOR_ADDR_STR2
4518 "BGP attribute is propagated unchanged to this neighbor\n"
4519 "As-path attribute\n"
4520 "Nexthop attribute\n"
4521 "Med attribute\n")
4522 {
4523 int idx = 0;
4524 char *peer_str = argv[1]->arg;
4525 struct peer *peer;
4526 uint16_t flags = 0;
4527 afi_t afi = bgp_node_afi(vty);
4528 safi_t safi = bgp_node_safi(vty);
4529
4530 peer = peer_and_group_lookup_vty(vty, peer_str);
4531 if (!peer)
4532 return CMD_WARNING_CONFIG_FAILED;
4533
4534 if (argv_find(argv, argc, "as-path", &idx))
4535 SET_FLAG(flags, PEER_FLAG_AS_PATH_UNCHANGED);
4536 idx = 0;
4537 if (argv_find(argv, argc, "next-hop", &idx))
4538 SET_FLAG(flags, PEER_FLAG_NEXTHOP_UNCHANGED);
4539 idx = 0;
4540 if (argv_find(argv, argc, "med", &idx))
4541 SET_FLAG(flags, PEER_FLAG_MED_UNCHANGED);
4542
4543 /* no flags means all of them! */
4544 if (!flags) {
4545 SET_FLAG(flags, PEER_FLAG_AS_PATH_UNCHANGED);
4546 SET_FLAG(flags, PEER_FLAG_NEXTHOP_UNCHANGED);
4547 SET_FLAG(flags, PEER_FLAG_MED_UNCHANGED);
4548 } else {
4549 if (!CHECK_FLAG(flags, PEER_FLAG_AS_PATH_UNCHANGED)
4550 && peer_af_flag_check(peer, afi, safi,
4551 PEER_FLAG_AS_PATH_UNCHANGED)) {
4552 peer_af_flag_unset_vty(vty, peer_str, afi, safi,
4553 PEER_FLAG_AS_PATH_UNCHANGED);
4554 }
4555
4556 if (!CHECK_FLAG(flags, PEER_FLAG_NEXTHOP_UNCHANGED)
4557 && peer_af_flag_check(peer, afi, safi,
4558 PEER_FLAG_NEXTHOP_UNCHANGED)) {
4559 peer_af_flag_unset_vty(vty, peer_str, afi, safi,
4560 PEER_FLAG_NEXTHOP_UNCHANGED);
4561 }
4562
4563 if (!CHECK_FLAG(flags, PEER_FLAG_MED_UNCHANGED)
4564 && peer_af_flag_check(peer, afi, safi,
4565 PEER_FLAG_MED_UNCHANGED)) {
4566 peer_af_flag_unset_vty(vty, peer_str, afi, safi,
4567 PEER_FLAG_MED_UNCHANGED);
4568 }
4569 }
4570
4571 return peer_af_flag_set_vty(vty, peer_str, afi, safi, flags);
4572 }
4573
4574 ALIAS_HIDDEN(
4575 neighbor_attr_unchanged, neighbor_attr_unchanged_hidden_cmd,
4576 "neighbor <A.B.C.D|X:X::X:X|WORD> attribute-unchanged [{as-path|next-hop|med}]",
4577 NEIGHBOR_STR NEIGHBOR_ADDR_STR2
4578 "BGP attribute is propagated unchanged to this neighbor\n"
4579 "As-path attribute\n"
4580 "Nexthop attribute\n"
4581 "Med attribute\n")
4582
4583 DEFUN (no_neighbor_attr_unchanged,
4584 no_neighbor_attr_unchanged_cmd,
4585 "no neighbor <A.B.C.D|X:X::X:X|WORD> attribute-unchanged [{as-path|next-hop|med}]",
4586 NO_STR
4587 NEIGHBOR_STR
4588 NEIGHBOR_ADDR_STR2
4589 "BGP attribute is propagated unchanged to this neighbor\n"
4590 "As-path attribute\n"
4591 "Nexthop attribute\n"
4592 "Med attribute\n")
4593 {
4594 int idx = 0;
4595 char *peer = argv[2]->arg;
4596 uint16_t flags = 0;
4597
4598 if (argv_find(argv, argc, "as-path", &idx))
4599 SET_FLAG(flags, PEER_FLAG_AS_PATH_UNCHANGED);
4600 idx = 0;
4601 if (argv_find(argv, argc, "next-hop", &idx))
4602 SET_FLAG(flags, PEER_FLAG_NEXTHOP_UNCHANGED);
4603 idx = 0;
4604 if (argv_find(argv, argc, "med", &idx))
4605 SET_FLAG(flags, PEER_FLAG_MED_UNCHANGED);
4606
4607 if (!flags) // no flags means all of them!
4608 {
4609 SET_FLAG(flags, PEER_FLAG_AS_PATH_UNCHANGED);
4610 SET_FLAG(flags, PEER_FLAG_NEXTHOP_UNCHANGED);
4611 SET_FLAG(flags, PEER_FLAG_MED_UNCHANGED);
4612 }
4613
4614 return peer_af_flag_unset_vty(vty, peer, bgp_node_afi(vty),
4615 bgp_node_safi(vty), flags);
4616 }
4617
4618 ALIAS_HIDDEN(
4619 no_neighbor_attr_unchanged, no_neighbor_attr_unchanged_hidden_cmd,
4620 "no neighbor <A.B.C.D|X:X::X:X|WORD> attribute-unchanged [{as-path|next-hop|med}]",
4621 NO_STR NEIGHBOR_STR NEIGHBOR_ADDR_STR2
4622 "BGP attribute is propagated unchanged to this neighbor\n"
4623 "As-path attribute\n"
4624 "Nexthop attribute\n"
4625 "Med attribute\n")
4626
4627 /* EBGP multihop configuration. */
4628 static int peer_ebgp_multihop_set_vty(struct vty *vty, const char *ip_str,
4629 const char *ttl_str)
4630 {
4631 struct peer *peer;
4632 unsigned int ttl;
4633
4634 peer = peer_and_group_lookup_vty(vty, ip_str);
4635 if (!peer)
4636 return CMD_WARNING_CONFIG_FAILED;
4637
4638 if (peer->conf_if)
4639 return bgp_vty_return(vty, BGP_ERR_INVALID_FOR_DIRECT_PEER);
4640
4641 if (!ttl_str)
4642 ttl = MAXTTL;
4643 else
4644 ttl = strtoul(ttl_str, NULL, 10);
4645
4646 return bgp_vty_return(vty, peer_ebgp_multihop_set(peer, ttl));
4647 }
4648
4649 static int peer_ebgp_multihop_unset_vty(struct vty *vty, const char *ip_str)
4650 {
4651 struct peer *peer;
4652
4653 peer = peer_and_group_lookup_vty(vty, ip_str);
4654 if (!peer)
4655 return CMD_WARNING_CONFIG_FAILED;
4656
4657 return bgp_vty_return(vty, peer_ebgp_multihop_unset(peer));
4658 }
4659
4660 /* neighbor ebgp-multihop. */
4661 DEFUN (neighbor_ebgp_multihop,
4662 neighbor_ebgp_multihop_cmd,
4663 "neighbor <A.B.C.D|X:X::X:X|WORD> ebgp-multihop",
4664 NEIGHBOR_STR
4665 NEIGHBOR_ADDR_STR2
4666 "Allow EBGP neighbors not on directly connected networks\n")
4667 {
4668 int idx_peer = 1;
4669 return peer_ebgp_multihop_set_vty(vty, argv[idx_peer]->arg, NULL);
4670 }
4671
4672 DEFUN (neighbor_ebgp_multihop_ttl,
4673 neighbor_ebgp_multihop_ttl_cmd,
4674 "neighbor <A.B.C.D|X:X::X:X|WORD> ebgp-multihop (1-255)",
4675 NEIGHBOR_STR
4676 NEIGHBOR_ADDR_STR2
4677 "Allow EBGP neighbors not on directly connected networks\n"
4678 "maximum hop count\n")
4679 {
4680 int idx_peer = 1;
4681 int idx_number = 3;
4682 return peer_ebgp_multihop_set_vty(vty, argv[idx_peer]->arg,
4683 argv[idx_number]->arg);
4684 }
4685
4686 DEFUN (no_neighbor_ebgp_multihop,
4687 no_neighbor_ebgp_multihop_cmd,
4688 "no neighbor <A.B.C.D|X:X::X:X|WORD> ebgp-multihop [(1-255)]",
4689 NO_STR
4690 NEIGHBOR_STR
4691 NEIGHBOR_ADDR_STR2
4692 "Allow EBGP neighbors not on directly connected networks\n"
4693 "maximum hop count\n")
4694 {
4695 int idx_peer = 2;
4696 return peer_ebgp_multihop_unset_vty(vty, argv[idx_peer]->arg);
4697 }
4698
4699
4700 /* disable-connected-check */
4701 DEFUN (neighbor_disable_connected_check,
4702 neighbor_disable_connected_check_cmd,
4703 "neighbor <A.B.C.D|X:X::X:X|WORD> <disable-connected-check|enforce-multihop>",
4704 NEIGHBOR_STR
4705 NEIGHBOR_ADDR_STR2
4706 "one-hop away EBGP peer using loopback address\n"
4707 "Enforce EBGP neighbors perform multihop\n")
4708 {
4709 int idx_peer = 1;
4710 return peer_flag_set_vty(vty, argv[idx_peer]->arg,
4711 PEER_FLAG_DISABLE_CONNECTED_CHECK);
4712 }
4713
4714 DEFUN (no_neighbor_disable_connected_check,
4715 no_neighbor_disable_connected_check_cmd,
4716 "no neighbor <A.B.C.D|X:X::X:X|WORD> <disable-connected-check|enforce-multihop>",
4717 NO_STR
4718 NEIGHBOR_STR
4719 NEIGHBOR_ADDR_STR2
4720 "one-hop away EBGP peer using loopback address\n"
4721 "Enforce EBGP neighbors perform multihop\n")
4722 {
4723 int idx_peer = 2;
4724 return peer_flag_unset_vty(vty, argv[idx_peer]->arg,
4725 PEER_FLAG_DISABLE_CONNECTED_CHECK);
4726 }
4727
4728
4729 /* enforce-first-as */
4730 DEFUN (neighbor_enforce_first_as,
4731 neighbor_enforce_first_as_cmd,
4732 "neighbor <A.B.C.D|X:X::X:X|WORD> enforce-first-as",
4733 NEIGHBOR_STR
4734 NEIGHBOR_ADDR_STR2
4735 "Enforce the first AS for EBGP routes\n")
4736 {
4737 int idx_peer = 1;
4738
4739 return peer_flag_set_vty(vty, argv[idx_peer]->arg,
4740 PEER_FLAG_ENFORCE_FIRST_AS);
4741 }
4742
4743 DEFUN (no_neighbor_enforce_first_as,
4744 no_neighbor_enforce_first_as_cmd,
4745 "no neighbor <A.B.C.D|X:X::X:X|WORD> enforce-first-as",
4746 NO_STR
4747 NEIGHBOR_STR
4748 NEIGHBOR_ADDR_STR2
4749 "Enforce the first AS for EBGP routes\n")
4750 {
4751 int idx_peer = 2;
4752
4753 return peer_flag_unset_vty(vty, argv[idx_peer]->arg,
4754 PEER_FLAG_ENFORCE_FIRST_AS);
4755 }
4756
4757
4758 DEFUN (neighbor_description,
4759 neighbor_description_cmd,
4760 "neighbor <A.B.C.D|X:X::X:X|WORD> description LINE...",
4761 NEIGHBOR_STR
4762 NEIGHBOR_ADDR_STR2
4763 "Neighbor specific description\n"
4764 "Up to 80 characters describing this neighbor\n")
4765 {
4766 int idx_peer = 1;
4767 int idx_line = 3;
4768 struct peer *peer;
4769 char *str;
4770
4771 peer = peer_and_group_lookup_vty(vty, argv[idx_peer]->arg);
4772 if (!peer)
4773 return CMD_WARNING_CONFIG_FAILED;
4774
4775 str = argv_concat(argv, argc, idx_line);
4776
4777 peer_description_set(peer, str);
4778
4779 XFREE(MTYPE_TMP, str);
4780
4781 return CMD_SUCCESS;
4782 }
4783
4784 DEFUN (no_neighbor_description,
4785 no_neighbor_description_cmd,
4786 "no neighbor <A.B.C.D|X:X::X:X|WORD> description",
4787 NO_STR
4788 NEIGHBOR_STR
4789 NEIGHBOR_ADDR_STR2
4790 "Neighbor specific description\n")
4791 {
4792 int idx_peer = 2;
4793 struct peer *peer;
4794
4795 peer = peer_and_group_lookup_vty(vty, argv[idx_peer]->arg);
4796 if (!peer)
4797 return CMD_WARNING_CONFIG_FAILED;
4798
4799 peer_description_unset(peer);
4800
4801 return CMD_SUCCESS;
4802 }
4803
4804 ALIAS(no_neighbor_description, no_neighbor_description_comment_cmd,
4805 "no neighbor <A.B.C.D|X:X::X:X|WORD> description LINE...",
4806 NO_STR NEIGHBOR_STR NEIGHBOR_ADDR_STR2
4807 "Neighbor specific description\n"
4808 "Up to 80 characters describing this neighbor\n")
4809
4810 /* Neighbor update-source. */
4811 static int peer_update_source_vty(struct vty *vty, const char *peer_str,
4812 const char *source_str)
4813 {
4814 struct peer *peer;
4815 struct prefix p;
4816 union sockunion su;
4817
4818 peer = peer_and_group_lookup_vty(vty, peer_str);
4819 if (!peer)
4820 return CMD_WARNING_CONFIG_FAILED;
4821
4822 if (peer->conf_if)
4823 return CMD_WARNING;
4824
4825 if (source_str) {
4826 if (str2sockunion(source_str, &su) == 0)
4827 peer_update_source_addr_set(peer, &su);
4828 else {
4829 if (str2prefix(source_str, &p)) {
4830 vty_out(vty,
4831 "%% Invalid update-source, remove prefix length \n");
4832 return CMD_WARNING_CONFIG_FAILED;
4833 } else
4834 peer_update_source_if_set(peer, source_str);
4835 }
4836 } else
4837 peer_update_source_unset(peer);
4838
4839 return CMD_SUCCESS;
4840 }
4841
4842 #define BGP_UPDATE_SOURCE_HELP_STR \
4843 "IPv4 address\n" \
4844 "IPv6 address\n" \
4845 "Interface name (requires zebra to be running)\n"
4846
4847 DEFUN (neighbor_update_source,
4848 neighbor_update_source_cmd,
4849 "neighbor <A.B.C.D|X:X::X:X|WORD> update-source <A.B.C.D|X:X::X:X|WORD>",
4850 NEIGHBOR_STR
4851 NEIGHBOR_ADDR_STR2
4852 "Source of routing updates\n"
4853 BGP_UPDATE_SOURCE_HELP_STR)
4854 {
4855 int idx_peer = 1;
4856 int idx_peer_2 = 3;
4857 return peer_update_source_vty(vty, argv[idx_peer]->arg,
4858 argv[idx_peer_2]->arg);
4859 }
4860
4861 DEFUN (no_neighbor_update_source,
4862 no_neighbor_update_source_cmd,
4863 "no neighbor <A.B.C.D|X:X::X:X|WORD> update-source [<A.B.C.D|X:X::X:X|WORD>]",
4864 NO_STR
4865 NEIGHBOR_STR
4866 NEIGHBOR_ADDR_STR2
4867 "Source of routing updates\n"
4868 BGP_UPDATE_SOURCE_HELP_STR)
4869 {
4870 int idx_peer = 2;
4871 return peer_update_source_vty(vty, argv[idx_peer]->arg, NULL);
4872 }
4873
4874 static int peer_default_originate_set_vty(struct vty *vty, const char *peer_str,
4875 afi_t afi, safi_t safi,
4876 const char *rmap, int set)
4877 {
4878 int ret;
4879 struct peer *peer;
4880 struct route_map *route_map;
4881
4882 peer = peer_and_group_lookup_vty(vty, peer_str);
4883 if (!peer)
4884 return CMD_WARNING_CONFIG_FAILED;
4885
4886 if (set) {
4887 route_map = route_map_lookup_warn_noexist(vty, rmap);
4888 ret = peer_default_originate_set(peer, afi, safi,
4889 rmap, route_map);
4890 } else
4891 ret = peer_default_originate_unset(peer, afi, safi);
4892
4893 return bgp_vty_return(vty, ret);
4894 }
4895
4896 /* neighbor default-originate. */
4897 DEFUN (neighbor_default_originate,
4898 neighbor_default_originate_cmd,
4899 "neighbor <A.B.C.D|X:X::X:X|WORD> default-originate",
4900 NEIGHBOR_STR
4901 NEIGHBOR_ADDR_STR2
4902 "Originate default route to this neighbor\n")
4903 {
4904 int idx_peer = 1;
4905 return peer_default_originate_set_vty(vty, argv[idx_peer]->arg,
4906 bgp_node_afi(vty),
4907 bgp_node_safi(vty), NULL, 1);
4908 }
4909
4910 ALIAS_HIDDEN(neighbor_default_originate, neighbor_default_originate_hidden_cmd,
4911 "neighbor <A.B.C.D|X:X::X:X|WORD> default-originate",
4912 NEIGHBOR_STR NEIGHBOR_ADDR_STR2
4913 "Originate default route to this neighbor\n")
4914
4915 DEFUN (neighbor_default_originate_rmap,
4916 neighbor_default_originate_rmap_cmd,
4917 "neighbor <A.B.C.D|X:X::X:X|WORD> default-originate route-map WORD",
4918 NEIGHBOR_STR
4919 NEIGHBOR_ADDR_STR2
4920 "Originate default route to this neighbor\n"
4921 "Route-map to specify criteria to originate default\n"
4922 "route-map name\n")
4923 {
4924 int idx_peer = 1;
4925 int idx_word = 4;
4926 return peer_default_originate_set_vty(
4927 vty, argv[idx_peer]->arg, bgp_node_afi(vty), bgp_node_safi(vty),
4928 argv[idx_word]->arg, 1);
4929 }
4930
4931 ALIAS_HIDDEN(
4932 neighbor_default_originate_rmap,
4933 neighbor_default_originate_rmap_hidden_cmd,
4934 "neighbor <A.B.C.D|X:X::X:X|WORD> default-originate route-map WORD",
4935 NEIGHBOR_STR NEIGHBOR_ADDR_STR2
4936 "Originate default route to this neighbor\n"
4937 "Route-map to specify criteria to originate default\n"
4938 "route-map name\n")
4939
4940 DEFUN (no_neighbor_default_originate,
4941 no_neighbor_default_originate_cmd,
4942 "no neighbor <A.B.C.D|X:X::X:X|WORD> default-originate [route-map WORD]",
4943 NO_STR
4944 NEIGHBOR_STR
4945 NEIGHBOR_ADDR_STR2
4946 "Originate default route to this neighbor\n"
4947 "Route-map to specify criteria to originate default\n"
4948 "route-map name\n")
4949 {
4950 int idx_peer = 2;
4951 return peer_default_originate_set_vty(vty, argv[idx_peer]->arg,
4952 bgp_node_afi(vty),
4953 bgp_node_safi(vty), NULL, 0);
4954 }
4955
4956 ALIAS_HIDDEN(
4957 no_neighbor_default_originate, no_neighbor_default_originate_hidden_cmd,
4958 "no neighbor <A.B.C.D|X:X::X:X|WORD> default-originate [route-map WORD]",
4959 NO_STR NEIGHBOR_STR NEIGHBOR_ADDR_STR2
4960 "Originate default route to this neighbor\n"
4961 "Route-map to specify criteria to originate default\n"
4962 "route-map name\n")
4963
4964
4965 /* Set neighbor's BGP port. */
4966 static int peer_port_vty(struct vty *vty, const char *ip_str, int afi,
4967 const char *port_str)
4968 {
4969 struct peer *peer;
4970 uint16_t port;
4971 struct servent *sp;
4972
4973 peer = peer_lookup_vty(vty, ip_str);
4974 if (!peer)
4975 return CMD_WARNING_CONFIG_FAILED;
4976
4977 if (!port_str) {
4978 sp = getservbyname("bgp", "tcp");
4979 port = (sp == NULL) ? BGP_PORT_DEFAULT : ntohs(sp->s_port);
4980 } else {
4981 port = strtoul(port_str, NULL, 10);
4982 }
4983
4984 peer_port_set(peer, port);
4985
4986 return CMD_SUCCESS;
4987 }
4988
4989 /* Set specified peer's BGP port. */
4990 DEFUN (neighbor_port,
4991 neighbor_port_cmd,
4992 "neighbor <A.B.C.D|X:X::X:X> port (0-65535)",
4993 NEIGHBOR_STR
4994 NEIGHBOR_ADDR_STR
4995 "Neighbor's BGP port\n"
4996 "TCP port number\n")
4997 {
4998 int idx_ip = 1;
4999 int idx_number = 3;
5000 return peer_port_vty(vty, argv[idx_ip]->arg, AFI_IP,
5001 argv[idx_number]->arg);
5002 }
5003
5004 DEFUN (no_neighbor_port,
5005 no_neighbor_port_cmd,
5006 "no neighbor <A.B.C.D|X:X::X:X> port [(0-65535)]",
5007 NO_STR
5008 NEIGHBOR_STR
5009 NEIGHBOR_ADDR_STR
5010 "Neighbor's BGP port\n"
5011 "TCP port number\n")
5012 {
5013 int idx_ip = 2;
5014 return peer_port_vty(vty, argv[idx_ip]->arg, AFI_IP, NULL);
5015 }
5016
5017
5018 /* neighbor weight. */
5019 static int peer_weight_set_vty(struct vty *vty, const char *ip_str, afi_t afi,
5020 safi_t safi, const char *weight_str)
5021 {
5022 int ret;
5023 struct peer *peer;
5024 unsigned long weight;
5025
5026 peer = peer_and_group_lookup_vty(vty, ip_str);
5027 if (!peer)
5028 return CMD_WARNING_CONFIG_FAILED;
5029
5030 weight = strtoul(weight_str, NULL, 10);
5031
5032 ret = peer_weight_set(peer, afi, safi, weight);
5033 return bgp_vty_return(vty, ret);
5034 }
5035
5036 static int peer_weight_unset_vty(struct vty *vty, const char *ip_str, afi_t afi,
5037 safi_t safi)
5038 {
5039 int ret;
5040 struct peer *peer;
5041
5042 peer = peer_and_group_lookup_vty(vty, ip_str);
5043 if (!peer)
5044 return CMD_WARNING_CONFIG_FAILED;
5045
5046 ret = peer_weight_unset(peer, afi, safi);
5047 return bgp_vty_return(vty, ret);
5048 }
5049
5050 DEFUN (neighbor_weight,
5051 neighbor_weight_cmd,
5052 "neighbor <A.B.C.D|X:X::X:X|WORD> weight (0-65535)",
5053 NEIGHBOR_STR
5054 NEIGHBOR_ADDR_STR2
5055 "Set default weight for routes from this neighbor\n"
5056 "default weight\n")
5057 {
5058 int idx_peer = 1;
5059 int idx_number = 3;
5060 return peer_weight_set_vty(vty, argv[idx_peer]->arg, bgp_node_afi(vty),
5061 bgp_node_safi(vty), argv[idx_number]->arg);
5062 }
5063
5064 ALIAS_HIDDEN(neighbor_weight, neighbor_weight_hidden_cmd,
5065 "neighbor <A.B.C.D|X:X::X:X|WORD> weight (0-65535)",
5066 NEIGHBOR_STR NEIGHBOR_ADDR_STR2
5067 "Set default weight for routes from this neighbor\n"
5068 "default weight\n")
5069
5070 DEFUN (no_neighbor_weight,
5071 no_neighbor_weight_cmd,
5072 "no neighbor <A.B.C.D|X:X::X:X|WORD> weight [(0-65535)]",
5073 NO_STR
5074 NEIGHBOR_STR
5075 NEIGHBOR_ADDR_STR2
5076 "Set default weight for routes from this neighbor\n"
5077 "default weight\n")
5078 {
5079 int idx_peer = 2;
5080 return peer_weight_unset_vty(vty, argv[idx_peer]->arg,
5081 bgp_node_afi(vty), bgp_node_safi(vty));
5082 }
5083
5084 ALIAS_HIDDEN(no_neighbor_weight, no_neighbor_weight_hidden_cmd,
5085 "no neighbor <A.B.C.D|X:X::X:X|WORD> weight [(0-65535)]",
5086 NO_STR NEIGHBOR_STR NEIGHBOR_ADDR_STR2
5087 "Set default weight for routes from this neighbor\n"
5088 "default weight\n")
5089
5090
5091 /* Override capability negotiation. */
5092 DEFUN (neighbor_override_capability,
5093 neighbor_override_capability_cmd,
5094 "neighbor <A.B.C.D|X:X::X:X|WORD> override-capability",
5095 NEIGHBOR_STR
5096 NEIGHBOR_ADDR_STR2
5097 "Override capability negotiation result\n")
5098 {
5099 int idx_peer = 1;
5100 return peer_flag_set_vty(vty, argv[idx_peer]->arg,
5101 PEER_FLAG_OVERRIDE_CAPABILITY);
5102 }
5103
5104 DEFUN (no_neighbor_override_capability,
5105 no_neighbor_override_capability_cmd,
5106 "no neighbor <A.B.C.D|X:X::X:X|WORD> override-capability",
5107 NO_STR
5108 NEIGHBOR_STR
5109 NEIGHBOR_ADDR_STR2
5110 "Override capability negotiation result\n")
5111 {
5112 int idx_peer = 2;
5113 return peer_flag_unset_vty(vty, argv[idx_peer]->arg,
5114 PEER_FLAG_OVERRIDE_CAPABILITY);
5115 }
5116
5117 DEFUN (neighbor_strict_capability,
5118 neighbor_strict_capability_cmd,
5119 "neighbor <A.B.C.D|X:X::X:X|WORD> strict-capability-match",
5120 NEIGHBOR_STR
5121 NEIGHBOR_ADDR_STR2
5122 "Strict capability negotiation match\n")
5123 {
5124 int idx_peer = 1;
5125
5126 return peer_flag_set_vty(vty, argv[idx_peer]->arg,
5127 PEER_FLAG_STRICT_CAP_MATCH);
5128 }
5129
5130 DEFUN (no_neighbor_strict_capability,
5131 no_neighbor_strict_capability_cmd,
5132 "no neighbor <A.B.C.D|X:X::X:X|WORD> strict-capability-match",
5133 NO_STR
5134 NEIGHBOR_STR
5135 NEIGHBOR_ADDR_STR2
5136 "Strict capability negotiation match\n")
5137 {
5138 int idx_peer = 2;
5139
5140 return peer_flag_unset_vty(vty, argv[idx_peer]->arg,
5141 PEER_FLAG_STRICT_CAP_MATCH);
5142 }
5143
5144 static int peer_timers_set_vty(struct vty *vty, const char *ip_str,
5145 const char *keep_str, const char *hold_str)
5146 {
5147 int ret;
5148 struct peer *peer;
5149 uint32_t keepalive;
5150 uint32_t holdtime;
5151
5152 peer = peer_and_group_lookup_vty(vty, ip_str);
5153 if (!peer)
5154 return CMD_WARNING_CONFIG_FAILED;
5155
5156 keepalive = strtoul(keep_str, NULL, 10);
5157 holdtime = strtoul(hold_str, NULL, 10);
5158
5159 ret = peer_timers_set(peer, keepalive, holdtime);
5160
5161 return bgp_vty_return(vty, ret);
5162 }
5163
5164 static int peer_timers_unset_vty(struct vty *vty, const char *ip_str)
5165 {
5166 int ret;
5167 struct peer *peer;
5168
5169 peer = peer_and_group_lookup_vty(vty, ip_str);
5170 if (!peer)
5171 return CMD_WARNING_CONFIG_FAILED;
5172
5173 ret = peer_timers_unset(peer);
5174
5175 return bgp_vty_return(vty, ret);
5176 }
5177
5178 DEFUN (neighbor_timers,
5179 neighbor_timers_cmd,
5180 "neighbor <A.B.C.D|X:X::X:X|WORD> timers (0-65535) (0-65535)",
5181 NEIGHBOR_STR
5182 NEIGHBOR_ADDR_STR2
5183 "BGP per neighbor timers\n"
5184 "Keepalive interval\n"
5185 "Holdtime\n")
5186 {
5187 int idx_peer = 1;
5188 int idx_number = 3;
5189 int idx_number_2 = 4;
5190 return peer_timers_set_vty(vty, argv[idx_peer]->arg,
5191 argv[idx_number]->arg,
5192 argv[idx_number_2]->arg);
5193 }
5194
5195 DEFUN (no_neighbor_timers,
5196 no_neighbor_timers_cmd,
5197 "no neighbor <A.B.C.D|X:X::X:X|WORD> timers [(0-65535) (0-65535)]",
5198 NO_STR
5199 NEIGHBOR_STR
5200 NEIGHBOR_ADDR_STR2
5201 "BGP per neighbor timers\n"
5202 "Keepalive interval\n"
5203 "Holdtime\n")
5204 {
5205 int idx_peer = 2;
5206 return peer_timers_unset_vty(vty, argv[idx_peer]->arg);
5207 }
5208
5209
5210 static int peer_timers_connect_set_vty(struct vty *vty, const char *ip_str,
5211 const char *time_str)
5212 {
5213 int ret;
5214 struct peer *peer;
5215 uint32_t connect;
5216
5217 peer = peer_and_group_lookup_vty(vty, ip_str);
5218 if (!peer)
5219 return CMD_WARNING_CONFIG_FAILED;
5220
5221 connect = strtoul(time_str, NULL, 10);
5222
5223 ret = peer_timers_connect_set(peer, connect);
5224
5225 return bgp_vty_return(vty, ret);
5226 }
5227
5228 static int peer_timers_connect_unset_vty(struct vty *vty, const char *ip_str)
5229 {
5230 int ret;
5231 struct peer *peer;
5232
5233 peer = peer_and_group_lookup_vty(vty, ip_str);
5234 if (!peer)
5235 return CMD_WARNING_CONFIG_FAILED;
5236
5237 ret = peer_timers_connect_unset(peer);
5238
5239 return bgp_vty_return(vty, ret);
5240 }
5241
5242 DEFUN (neighbor_timers_connect,
5243 neighbor_timers_connect_cmd,
5244 "neighbor <A.B.C.D|X:X::X:X|WORD> timers connect (1-65535)",
5245 NEIGHBOR_STR
5246 NEIGHBOR_ADDR_STR2
5247 "BGP per neighbor timers\n"
5248 "BGP connect timer\n"
5249 "Connect timer\n")
5250 {
5251 int idx_peer = 1;
5252 int idx_number = 4;
5253 return peer_timers_connect_set_vty(vty, argv[idx_peer]->arg,
5254 argv[idx_number]->arg);
5255 }
5256
5257 DEFUN (no_neighbor_timers_connect,
5258 no_neighbor_timers_connect_cmd,
5259 "no neighbor <A.B.C.D|X:X::X:X|WORD> timers connect [(1-65535)]",
5260 NO_STR
5261 NEIGHBOR_STR
5262 NEIGHBOR_ADDR_STR2
5263 "BGP per neighbor timers\n"
5264 "BGP connect timer\n"
5265 "Connect timer\n")
5266 {
5267 int idx_peer = 2;
5268 return peer_timers_connect_unset_vty(vty, argv[idx_peer]->arg);
5269 }
5270
5271
5272 static int peer_advertise_interval_vty(struct vty *vty, const char *ip_str,
5273 const char *time_str, int set)
5274 {
5275 int ret;
5276 struct peer *peer;
5277 uint32_t routeadv = 0;
5278
5279 peer = peer_and_group_lookup_vty(vty, ip_str);
5280 if (!peer)
5281 return CMD_WARNING_CONFIG_FAILED;
5282
5283 if (time_str)
5284 routeadv = strtoul(time_str, NULL, 10);
5285
5286 if (set)
5287 ret = peer_advertise_interval_set(peer, routeadv);
5288 else
5289 ret = peer_advertise_interval_unset(peer);
5290
5291 return bgp_vty_return(vty, ret);
5292 }
5293
5294 DEFUN (neighbor_advertise_interval,
5295 neighbor_advertise_interval_cmd,
5296 "neighbor <A.B.C.D|X:X::X:X|WORD> advertisement-interval (0-600)",
5297 NEIGHBOR_STR
5298 NEIGHBOR_ADDR_STR2
5299 "Minimum interval between sending BGP routing updates\n"
5300 "time in seconds\n")
5301 {
5302 int idx_peer = 1;
5303 int idx_number = 3;
5304 return peer_advertise_interval_vty(vty, argv[idx_peer]->arg,
5305 argv[idx_number]->arg, 1);
5306 }
5307
5308 DEFUN (no_neighbor_advertise_interval,
5309 no_neighbor_advertise_interval_cmd,
5310 "no neighbor <A.B.C.D|X:X::X:X|WORD> advertisement-interval [(0-600)]",
5311 NO_STR
5312 NEIGHBOR_STR
5313 NEIGHBOR_ADDR_STR2
5314 "Minimum interval between sending BGP routing updates\n"
5315 "time in seconds\n")
5316 {
5317 int idx_peer = 2;
5318 return peer_advertise_interval_vty(vty, argv[idx_peer]->arg, NULL, 0);
5319 }
5320
5321
5322 /* Time to wait before processing route-map updates */
5323 DEFUN (bgp_set_route_map_delay_timer,
5324 bgp_set_route_map_delay_timer_cmd,
5325 "bgp route-map delay-timer (0-600)",
5326 SET_STR
5327 "BGP route-map delay timer\n"
5328 "Time in secs to wait before processing route-map changes\n"
5329 "0 disables the timer, no route updates happen when route-maps change\n")
5330 {
5331 int idx_number = 3;
5332 uint32_t rmap_delay_timer;
5333
5334 if (argv[idx_number]->arg) {
5335 rmap_delay_timer = strtoul(argv[idx_number]->arg, NULL, 10);
5336 bm->rmap_update_timer = rmap_delay_timer;
5337
5338 /* if the dynamic update handling is being disabled, and a timer
5339 * is
5340 * running, stop the timer and act as if the timer has already
5341 * fired.
5342 */
5343 if (!rmap_delay_timer && bm->t_rmap_update) {
5344 BGP_TIMER_OFF(bm->t_rmap_update);
5345 thread_execute(bm->master, bgp_route_map_update_timer,
5346 NULL, 0);
5347 }
5348 return CMD_SUCCESS;
5349 } else {
5350 vty_out(vty, "%% BGP invalid route-map delay-timer\n");
5351 return CMD_WARNING_CONFIG_FAILED;
5352 }
5353 }
5354
5355 DEFUN (no_bgp_set_route_map_delay_timer,
5356 no_bgp_set_route_map_delay_timer_cmd,
5357 "no bgp route-map delay-timer [(0-600)]",
5358 NO_STR
5359 BGP_STR
5360 "Default BGP route-map delay timer\n"
5361 "Reset to default time to wait for processing route-map changes\n"
5362 "0 disables the timer, no route updates happen when route-maps change\n")
5363 {
5364
5365 bm->rmap_update_timer = RMAP_DEFAULT_UPDATE_TIMER;
5366
5367 return CMD_SUCCESS;
5368 }
5369
5370
5371 /* neighbor interface */
5372 static int peer_interface_vty(struct vty *vty, const char *ip_str,
5373 const char *str)
5374 {
5375 struct peer *peer;
5376
5377 peer = peer_lookup_vty(vty, ip_str);
5378 if (!peer || peer->conf_if) {
5379 vty_out(vty, "%% BGP invalid peer %s\n", ip_str);
5380 return CMD_WARNING_CONFIG_FAILED;
5381 }
5382
5383 if (str)
5384 peer_interface_set(peer, str);
5385 else
5386 peer_interface_unset(peer);
5387
5388 return CMD_SUCCESS;
5389 }
5390
5391 DEFUN (neighbor_interface,
5392 neighbor_interface_cmd,
5393 "neighbor <A.B.C.D|X:X::X:X> interface WORD",
5394 NEIGHBOR_STR
5395 NEIGHBOR_ADDR_STR
5396 "Interface\n"
5397 "Interface name\n")
5398 {
5399 int idx_ip = 1;
5400 int idx_word = 3;
5401 return peer_interface_vty(vty, argv[idx_ip]->arg, argv[idx_word]->arg);
5402 }
5403
5404 DEFUN (no_neighbor_interface,
5405 no_neighbor_interface_cmd,
5406 "no neighbor <A.B.C.D|X:X::X:X|WORD> interface WORD",
5407 NO_STR
5408 NEIGHBOR_STR
5409 NEIGHBOR_ADDR_STR2
5410 "Interface\n"
5411 "Interface name\n")
5412 {
5413 int idx_peer = 2;
5414 return peer_interface_vty(vty, argv[idx_peer]->arg, NULL);
5415 }
5416
5417 DEFUN (neighbor_distribute_list,
5418 neighbor_distribute_list_cmd,
5419 "neighbor <A.B.C.D|X:X::X:X|WORD> distribute-list <(1-199)|(1300-2699)|WORD> <in|out>",
5420 NEIGHBOR_STR
5421 NEIGHBOR_ADDR_STR2
5422 "Filter updates to/from this neighbor\n"
5423 "IP access-list number\n"
5424 "IP access-list number (expanded range)\n"
5425 "IP Access-list name\n"
5426 "Filter incoming updates\n"
5427 "Filter outgoing updates\n")
5428 {
5429 int idx_peer = 1;
5430 int idx_acl = 3;
5431 int direct, ret;
5432 struct peer *peer;
5433
5434 const char *pstr = argv[idx_peer]->arg;
5435 const char *acl = argv[idx_acl]->arg;
5436 const char *inout = argv[argc - 1]->text;
5437
5438 peer = peer_and_group_lookup_vty(vty, pstr);
5439 if (!peer)
5440 return CMD_WARNING_CONFIG_FAILED;
5441
5442 /* Check filter direction. */
5443 direct = strmatch(inout, "in") ? FILTER_IN : FILTER_OUT;
5444 ret = peer_distribute_set(peer, bgp_node_afi(vty), bgp_node_safi(vty),
5445 direct, acl);
5446
5447 return bgp_vty_return(vty, ret);
5448 }
5449
5450 ALIAS_HIDDEN(
5451 neighbor_distribute_list, neighbor_distribute_list_hidden_cmd,
5452 "neighbor <A.B.C.D|X:X::X:X|WORD> distribute-list <(1-199)|(1300-2699)|WORD> <in|out>",
5453 NEIGHBOR_STR NEIGHBOR_ADDR_STR2
5454 "Filter updates to/from this neighbor\n"
5455 "IP access-list number\n"
5456 "IP access-list number (expanded range)\n"
5457 "IP Access-list name\n"
5458 "Filter incoming updates\n"
5459 "Filter outgoing updates\n")
5460
5461 DEFUN (no_neighbor_distribute_list,
5462 no_neighbor_distribute_list_cmd,
5463 "no neighbor <A.B.C.D|X:X::X:X|WORD> distribute-list <(1-199)|(1300-2699)|WORD> <in|out>",
5464 NO_STR
5465 NEIGHBOR_STR
5466 NEIGHBOR_ADDR_STR2
5467 "Filter updates to/from this neighbor\n"
5468 "IP access-list number\n"
5469 "IP access-list number (expanded range)\n"
5470 "IP Access-list name\n"
5471 "Filter incoming updates\n"
5472 "Filter outgoing updates\n")
5473 {
5474 int idx_peer = 2;
5475 int direct, ret;
5476 struct peer *peer;
5477
5478 const char *pstr = argv[idx_peer]->arg;
5479 const char *inout = argv[argc - 1]->text;
5480
5481 peer = peer_and_group_lookup_vty(vty, pstr);
5482 if (!peer)
5483 return CMD_WARNING_CONFIG_FAILED;
5484
5485 /* Check filter direction. */
5486 direct = strmatch(inout, "in") ? FILTER_IN : FILTER_OUT;
5487 ret = peer_distribute_unset(peer, bgp_node_afi(vty), bgp_node_safi(vty),
5488 direct);
5489
5490 return bgp_vty_return(vty, ret);
5491 }
5492
5493 ALIAS_HIDDEN(
5494 no_neighbor_distribute_list, no_neighbor_distribute_list_hidden_cmd,
5495 "no neighbor <A.B.C.D|X:X::X:X|WORD> distribute-list <(1-199)|(1300-2699)|WORD> <in|out>",
5496 NO_STR NEIGHBOR_STR NEIGHBOR_ADDR_STR2
5497 "Filter updates to/from this neighbor\n"
5498 "IP access-list number\n"
5499 "IP access-list number (expanded range)\n"
5500 "IP Access-list name\n"
5501 "Filter incoming updates\n"
5502 "Filter outgoing updates\n")
5503
5504 /* Set prefix list to the peer. */
5505 static int peer_prefix_list_set_vty(struct vty *vty, const char *ip_str,
5506 afi_t afi, safi_t safi,
5507 const char *name_str,
5508 const char *direct_str)
5509 {
5510 int ret;
5511 int direct = FILTER_IN;
5512 struct peer *peer;
5513
5514 peer = peer_and_group_lookup_vty(vty, ip_str);
5515 if (!peer)
5516 return CMD_WARNING_CONFIG_FAILED;
5517
5518 /* Check filter direction. */
5519 if (strncmp(direct_str, "i", 1) == 0)
5520 direct = FILTER_IN;
5521 else if (strncmp(direct_str, "o", 1) == 0)
5522 direct = FILTER_OUT;
5523
5524 ret = peer_prefix_list_set(peer, afi, safi, direct, name_str);
5525
5526 return bgp_vty_return(vty, ret);
5527 }
5528
5529 static int peer_prefix_list_unset_vty(struct vty *vty, const char *ip_str,
5530 afi_t afi, safi_t safi,
5531 const char *direct_str)
5532 {
5533 int ret;
5534 struct peer *peer;
5535 int direct = FILTER_IN;
5536
5537 peer = peer_and_group_lookup_vty(vty, ip_str);
5538 if (!peer)
5539 return CMD_WARNING_CONFIG_FAILED;
5540
5541 /* Check filter direction. */
5542 if (strncmp(direct_str, "i", 1) == 0)
5543 direct = FILTER_IN;
5544 else if (strncmp(direct_str, "o", 1) == 0)
5545 direct = FILTER_OUT;
5546
5547 ret = peer_prefix_list_unset(peer, afi, safi, direct);
5548
5549 return bgp_vty_return(vty, ret);
5550 }
5551
5552 DEFUN (neighbor_prefix_list,
5553 neighbor_prefix_list_cmd,
5554 "neighbor <A.B.C.D|X:X::X:X|WORD> prefix-list WORD <in|out>",
5555 NEIGHBOR_STR
5556 NEIGHBOR_ADDR_STR2
5557 "Filter updates to/from this neighbor\n"
5558 "Name of a prefix list\n"
5559 "Filter incoming updates\n"
5560 "Filter outgoing updates\n")
5561 {
5562 int idx_peer = 1;
5563 int idx_word = 3;
5564 int idx_in_out = 4;
5565 return peer_prefix_list_set_vty(
5566 vty, argv[idx_peer]->arg, bgp_node_afi(vty), bgp_node_safi(vty),
5567 argv[idx_word]->arg, argv[idx_in_out]->arg);
5568 }
5569
5570 ALIAS_HIDDEN(neighbor_prefix_list, neighbor_prefix_list_hidden_cmd,
5571 "neighbor <A.B.C.D|X:X::X:X|WORD> prefix-list WORD <in|out>",
5572 NEIGHBOR_STR NEIGHBOR_ADDR_STR2
5573 "Filter updates to/from this neighbor\n"
5574 "Name of a prefix list\n"
5575 "Filter incoming updates\n"
5576 "Filter outgoing updates\n")
5577
5578 DEFUN (no_neighbor_prefix_list,
5579 no_neighbor_prefix_list_cmd,
5580 "no neighbor <A.B.C.D|X:X::X:X|WORD> prefix-list WORD <in|out>",
5581 NO_STR
5582 NEIGHBOR_STR
5583 NEIGHBOR_ADDR_STR2
5584 "Filter updates to/from this neighbor\n"
5585 "Name of a prefix list\n"
5586 "Filter incoming updates\n"
5587 "Filter outgoing updates\n")
5588 {
5589 int idx_peer = 2;
5590 int idx_in_out = 5;
5591 return peer_prefix_list_unset_vty(vty, argv[idx_peer]->arg,
5592 bgp_node_afi(vty), bgp_node_safi(vty),
5593 argv[idx_in_out]->arg);
5594 }
5595
5596 ALIAS_HIDDEN(no_neighbor_prefix_list, no_neighbor_prefix_list_hidden_cmd,
5597 "no neighbor <A.B.C.D|X:X::X:X|WORD> prefix-list WORD <in|out>",
5598 NO_STR NEIGHBOR_STR NEIGHBOR_ADDR_STR2
5599 "Filter updates to/from this neighbor\n"
5600 "Name of a prefix list\n"
5601 "Filter incoming updates\n"
5602 "Filter outgoing updates\n")
5603
5604 static int peer_aslist_set_vty(struct vty *vty, const char *ip_str, afi_t afi,
5605 safi_t safi, const char *name_str,
5606 const char *direct_str)
5607 {
5608 int ret;
5609 struct peer *peer;
5610 int direct = FILTER_IN;
5611
5612 peer = peer_and_group_lookup_vty(vty, ip_str);
5613 if (!peer)
5614 return CMD_WARNING_CONFIG_FAILED;
5615
5616 /* Check filter direction. */
5617 if (strncmp(direct_str, "i", 1) == 0)
5618 direct = FILTER_IN;
5619 else if (strncmp(direct_str, "o", 1) == 0)
5620 direct = FILTER_OUT;
5621
5622 ret = peer_aslist_set(peer, afi, safi, direct, name_str);
5623
5624 return bgp_vty_return(vty, ret);
5625 }
5626
5627 static int peer_aslist_unset_vty(struct vty *vty, const char *ip_str, afi_t afi,
5628 safi_t safi, const char *direct_str)
5629 {
5630 int ret;
5631 struct peer *peer;
5632 int direct = FILTER_IN;
5633
5634 peer = peer_and_group_lookup_vty(vty, ip_str);
5635 if (!peer)
5636 return CMD_WARNING_CONFIG_FAILED;
5637
5638 /* Check filter direction. */
5639 if (strncmp(direct_str, "i", 1) == 0)
5640 direct = FILTER_IN;
5641 else if (strncmp(direct_str, "o", 1) == 0)
5642 direct = FILTER_OUT;
5643
5644 ret = peer_aslist_unset(peer, afi, safi, direct);
5645
5646 return bgp_vty_return(vty, ret);
5647 }
5648
5649 DEFUN (neighbor_filter_list,
5650 neighbor_filter_list_cmd,
5651 "neighbor <A.B.C.D|X:X::X:X|WORD> filter-list WORD <in|out>",
5652 NEIGHBOR_STR
5653 NEIGHBOR_ADDR_STR2
5654 "Establish BGP filters\n"
5655 "AS path access-list name\n"
5656 "Filter incoming routes\n"
5657 "Filter outgoing routes\n")
5658 {
5659 int idx_peer = 1;
5660 int idx_word = 3;
5661 int idx_in_out = 4;
5662 return peer_aslist_set_vty(vty, argv[idx_peer]->arg, bgp_node_afi(vty),
5663 bgp_node_safi(vty), argv[idx_word]->arg,
5664 argv[idx_in_out]->arg);
5665 }
5666
5667 ALIAS_HIDDEN(neighbor_filter_list, neighbor_filter_list_hidden_cmd,
5668 "neighbor <A.B.C.D|X:X::X:X|WORD> filter-list WORD <in|out>",
5669 NEIGHBOR_STR NEIGHBOR_ADDR_STR2
5670 "Establish BGP filters\n"
5671 "AS path access-list name\n"
5672 "Filter incoming routes\n"
5673 "Filter outgoing routes\n")
5674
5675 DEFUN (no_neighbor_filter_list,
5676 no_neighbor_filter_list_cmd,
5677 "no neighbor <A.B.C.D|X:X::X:X|WORD> filter-list WORD <in|out>",
5678 NO_STR
5679 NEIGHBOR_STR
5680 NEIGHBOR_ADDR_STR2
5681 "Establish BGP filters\n"
5682 "AS path access-list name\n"
5683 "Filter incoming routes\n"
5684 "Filter outgoing routes\n")
5685 {
5686 int idx_peer = 2;
5687 int idx_in_out = 5;
5688 return peer_aslist_unset_vty(vty, argv[idx_peer]->arg,
5689 bgp_node_afi(vty), bgp_node_safi(vty),
5690 argv[idx_in_out]->arg);
5691 }
5692
5693 ALIAS_HIDDEN(no_neighbor_filter_list, no_neighbor_filter_list_hidden_cmd,
5694 "no neighbor <A.B.C.D|X:X::X:X|WORD> filter-list WORD <in|out>",
5695 NO_STR NEIGHBOR_STR NEIGHBOR_ADDR_STR2
5696 "Establish BGP filters\n"
5697 "AS path access-list name\n"
5698 "Filter incoming routes\n"
5699 "Filter outgoing routes\n")
5700
5701 /* Set route-map to the peer. */
5702 static int peer_route_map_set_vty(struct vty *vty, const char *ip_str,
5703 afi_t afi, safi_t safi, const char *name_str,
5704 const char *direct_str)
5705 {
5706 int ret;
5707 struct peer *peer;
5708 int direct = RMAP_IN;
5709 struct route_map *route_map;
5710
5711 peer = peer_and_group_lookup_vty(vty, ip_str);
5712 if (!peer)
5713 return CMD_WARNING_CONFIG_FAILED;
5714
5715 /* Check filter direction. */
5716 if (strncmp(direct_str, "in", 2) == 0)
5717 direct = RMAP_IN;
5718 else if (strncmp(direct_str, "o", 1) == 0)
5719 direct = RMAP_OUT;
5720
5721 route_map = route_map_lookup_warn_noexist(vty, name_str);
5722 ret = peer_route_map_set(peer, afi, safi, direct, name_str, route_map);
5723
5724 return bgp_vty_return(vty, ret);
5725 }
5726
5727 static int peer_route_map_unset_vty(struct vty *vty, const char *ip_str,
5728 afi_t afi, safi_t safi,
5729 const char *direct_str)
5730 {
5731 int ret;
5732 struct peer *peer;
5733 int direct = RMAP_IN;
5734
5735 peer = peer_and_group_lookup_vty(vty, ip_str);
5736 if (!peer)
5737 return CMD_WARNING_CONFIG_FAILED;
5738
5739 /* Check filter direction. */
5740 if (strncmp(direct_str, "in", 2) == 0)
5741 direct = RMAP_IN;
5742 else if (strncmp(direct_str, "o", 1) == 0)
5743 direct = RMAP_OUT;
5744
5745 ret = peer_route_map_unset(peer, afi, safi, direct);
5746
5747 return bgp_vty_return(vty, ret);
5748 }
5749
5750 DEFUN (neighbor_route_map,
5751 neighbor_route_map_cmd,
5752 "neighbor <A.B.C.D|X:X::X:X|WORD> route-map WORD <in|out>",
5753 NEIGHBOR_STR
5754 NEIGHBOR_ADDR_STR2
5755 "Apply route map to neighbor\n"
5756 "Name of route map\n"
5757 "Apply map to incoming routes\n"
5758 "Apply map to outbound routes\n")
5759 {
5760 int idx_peer = 1;
5761 int idx_word = 3;
5762 int idx_in_out = 4;
5763 return peer_route_map_set_vty(
5764 vty, argv[idx_peer]->arg, bgp_node_afi(vty), bgp_node_safi(vty),
5765 argv[idx_word]->arg, argv[idx_in_out]->arg);
5766 }
5767
5768 ALIAS_HIDDEN(neighbor_route_map, neighbor_route_map_hidden_cmd,
5769 "neighbor <A.B.C.D|X:X::X:X|WORD> route-map WORD <in|out>",
5770 NEIGHBOR_STR NEIGHBOR_ADDR_STR2
5771 "Apply route map to neighbor\n"
5772 "Name of route map\n"
5773 "Apply map to incoming routes\n"
5774 "Apply map to outbound routes\n")
5775
5776 DEFUN (no_neighbor_route_map,
5777 no_neighbor_route_map_cmd,
5778 "no neighbor <A.B.C.D|X:X::X:X|WORD> route-map WORD <in|out>",
5779 NO_STR
5780 NEIGHBOR_STR
5781 NEIGHBOR_ADDR_STR2
5782 "Apply route map to neighbor\n"
5783 "Name of route map\n"
5784 "Apply map to incoming routes\n"
5785 "Apply map to outbound routes\n")
5786 {
5787 int idx_peer = 2;
5788 int idx_in_out = 5;
5789 return peer_route_map_unset_vty(vty, argv[idx_peer]->arg,
5790 bgp_node_afi(vty), bgp_node_safi(vty),
5791 argv[idx_in_out]->arg);
5792 }
5793
5794 ALIAS_HIDDEN(no_neighbor_route_map, no_neighbor_route_map_hidden_cmd,
5795 "no neighbor <A.B.C.D|X:X::X:X|WORD> route-map WORD <in|out>",
5796 NO_STR NEIGHBOR_STR NEIGHBOR_ADDR_STR2
5797 "Apply route map to neighbor\n"
5798 "Name of route map\n"
5799 "Apply map to incoming routes\n"
5800 "Apply map to outbound routes\n")
5801
5802 /* Set unsuppress-map to the peer. */
5803 static int peer_unsuppress_map_set_vty(struct vty *vty, const char *ip_str,
5804 afi_t afi, safi_t safi,
5805 const char *name_str)
5806 {
5807 int ret;
5808 struct peer *peer;
5809 struct route_map *route_map;
5810
5811 peer = peer_and_group_lookup_vty(vty, ip_str);
5812 if (!peer)
5813 return CMD_WARNING_CONFIG_FAILED;
5814
5815 route_map = route_map_lookup_warn_noexist(vty, name_str);
5816 ret = peer_unsuppress_map_set(peer, afi, safi, name_str, route_map);
5817
5818 return bgp_vty_return(vty, ret);
5819 }
5820
5821 /* Unset route-map from the peer. */
5822 static int peer_unsuppress_map_unset_vty(struct vty *vty, const char *ip_str,
5823 afi_t afi, safi_t safi)
5824 {
5825 int ret;
5826 struct peer *peer;
5827
5828 peer = peer_and_group_lookup_vty(vty, ip_str);
5829 if (!peer)
5830 return CMD_WARNING_CONFIG_FAILED;
5831
5832 ret = peer_unsuppress_map_unset(peer, afi, safi);
5833
5834 return bgp_vty_return(vty, ret);
5835 }
5836
5837 DEFUN (neighbor_unsuppress_map,
5838 neighbor_unsuppress_map_cmd,
5839 "neighbor <A.B.C.D|X:X::X:X|WORD> unsuppress-map WORD",
5840 NEIGHBOR_STR
5841 NEIGHBOR_ADDR_STR2
5842 "Route-map to selectively unsuppress suppressed routes\n"
5843 "Name of route map\n")
5844 {
5845 int idx_peer = 1;
5846 int idx_word = 3;
5847 return peer_unsuppress_map_set_vty(
5848 vty, argv[idx_peer]->arg, bgp_node_afi(vty), bgp_node_safi(vty),
5849 argv[idx_word]->arg);
5850 }
5851
5852 ALIAS_HIDDEN(neighbor_unsuppress_map, neighbor_unsuppress_map_hidden_cmd,
5853 "neighbor <A.B.C.D|X:X::X:X|WORD> unsuppress-map WORD",
5854 NEIGHBOR_STR NEIGHBOR_ADDR_STR2
5855 "Route-map to selectively unsuppress suppressed routes\n"
5856 "Name of route map\n")
5857
5858 DEFUN (no_neighbor_unsuppress_map,
5859 no_neighbor_unsuppress_map_cmd,
5860 "no neighbor <A.B.C.D|X:X::X:X|WORD> unsuppress-map WORD",
5861 NO_STR
5862 NEIGHBOR_STR
5863 NEIGHBOR_ADDR_STR2
5864 "Route-map to selectively unsuppress suppressed routes\n"
5865 "Name of route map\n")
5866 {
5867 int idx_peer = 2;
5868 return peer_unsuppress_map_unset_vty(vty, argv[idx_peer]->arg,
5869 bgp_node_afi(vty),
5870 bgp_node_safi(vty));
5871 }
5872
5873 ALIAS_HIDDEN(no_neighbor_unsuppress_map, no_neighbor_unsuppress_map_hidden_cmd,
5874 "no neighbor <A.B.C.D|X:X::X:X|WORD> unsuppress-map WORD",
5875 NO_STR NEIGHBOR_STR NEIGHBOR_ADDR_STR2
5876 "Route-map to selectively unsuppress suppressed routes\n"
5877 "Name of route map\n")
5878
5879 static int peer_maximum_prefix_set_vty(struct vty *vty, const char *ip_str,
5880 afi_t afi, safi_t safi,
5881 const char *num_str,
5882 const char *threshold_str, int warning,
5883 const char *restart_str)
5884 {
5885 int ret;
5886 struct peer *peer;
5887 uint32_t max;
5888 uint8_t threshold;
5889 uint16_t restart;
5890
5891 peer = peer_and_group_lookup_vty(vty, ip_str);
5892 if (!peer)
5893 return CMD_WARNING_CONFIG_FAILED;
5894
5895 max = strtoul(num_str, NULL, 10);
5896 if (threshold_str)
5897 threshold = atoi(threshold_str);
5898 else
5899 threshold = MAXIMUM_PREFIX_THRESHOLD_DEFAULT;
5900
5901 if (restart_str)
5902 restart = atoi(restart_str);
5903 else
5904 restart = 0;
5905
5906 ret = peer_maximum_prefix_set(peer, afi, safi, max, threshold, warning,
5907 restart);
5908
5909 return bgp_vty_return(vty, ret);
5910 }
5911
5912 static int peer_maximum_prefix_unset_vty(struct vty *vty, const char *ip_str,
5913 afi_t afi, safi_t safi)
5914 {
5915 int ret;
5916 struct peer *peer;
5917
5918 peer = peer_and_group_lookup_vty(vty, ip_str);
5919 if (!peer)
5920 return CMD_WARNING_CONFIG_FAILED;
5921
5922 ret = peer_maximum_prefix_unset(peer, afi, safi);
5923
5924 return bgp_vty_return(vty, ret);
5925 }
5926
5927 /* Maximum number of prefix configuration. prefix count is different
5928 for each peer configuration. So this configuration can be set for
5929 each peer configuration. */
5930 DEFUN (neighbor_maximum_prefix,
5931 neighbor_maximum_prefix_cmd,
5932 "neighbor <A.B.C.D|X:X::X:X|WORD> maximum-prefix (1-4294967295)",
5933 NEIGHBOR_STR
5934 NEIGHBOR_ADDR_STR2
5935 "Maximum number of prefix accept from this peer\n"
5936 "maximum no. of prefix limit\n")
5937 {
5938 int idx_peer = 1;
5939 int idx_number = 3;
5940 return peer_maximum_prefix_set_vty(
5941 vty, argv[idx_peer]->arg, bgp_node_afi(vty), bgp_node_safi(vty),
5942 argv[idx_number]->arg, NULL, 0, NULL);
5943 }
5944
5945 ALIAS_HIDDEN(neighbor_maximum_prefix, neighbor_maximum_prefix_hidden_cmd,
5946 "neighbor <A.B.C.D|X:X::X:X|WORD> maximum-prefix (1-4294967295)",
5947 NEIGHBOR_STR NEIGHBOR_ADDR_STR2
5948 "Maximum number of prefix accept from this peer\n"
5949 "maximum no. of prefix limit\n")
5950
5951 DEFUN (neighbor_maximum_prefix_threshold,
5952 neighbor_maximum_prefix_threshold_cmd,
5953 "neighbor <A.B.C.D|X:X::X:X|WORD> maximum-prefix (1-4294967295) (1-100)",
5954 NEIGHBOR_STR
5955 NEIGHBOR_ADDR_STR2
5956 "Maximum number of prefix accept from this peer\n"
5957 "maximum no. of prefix limit\n"
5958 "Threshold value (%) at which to generate a warning msg\n")
5959 {
5960 int idx_peer = 1;
5961 int idx_number = 3;
5962 int idx_number_2 = 4;
5963 return peer_maximum_prefix_set_vty(
5964 vty, argv[idx_peer]->arg, bgp_node_afi(vty), bgp_node_safi(vty),
5965 argv[idx_number]->arg, argv[idx_number_2]->arg, 0, NULL);
5966 }
5967
5968 ALIAS_HIDDEN(
5969 neighbor_maximum_prefix_threshold,
5970 neighbor_maximum_prefix_threshold_hidden_cmd,
5971 "neighbor <A.B.C.D|X:X::X:X|WORD> maximum-prefix (1-4294967295) (1-100)",
5972 NEIGHBOR_STR NEIGHBOR_ADDR_STR2
5973 "Maximum number of prefix accept from this peer\n"
5974 "maximum no. of prefix limit\n"
5975 "Threshold value (%) at which to generate a warning msg\n")
5976
5977 DEFUN (neighbor_maximum_prefix_warning,
5978 neighbor_maximum_prefix_warning_cmd,
5979 "neighbor <A.B.C.D|X:X::X:X|WORD> maximum-prefix (1-4294967295) warning-only",
5980 NEIGHBOR_STR
5981 NEIGHBOR_ADDR_STR2
5982 "Maximum number of prefix accept from this peer\n"
5983 "maximum no. of prefix limit\n"
5984 "Only give warning message when limit is exceeded\n")
5985 {
5986 int idx_peer = 1;
5987 int idx_number = 3;
5988 return peer_maximum_prefix_set_vty(
5989 vty, argv[idx_peer]->arg, bgp_node_afi(vty), bgp_node_safi(vty),
5990 argv[idx_number]->arg, NULL, 1, NULL);
5991 }
5992
5993 ALIAS_HIDDEN(
5994 neighbor_maximum_prefix_warning,
5995 neighbor_maximum_prefix_warning_hidden_cmd,
5996 "neighbor <A.B.C.D|X:X::X:X|WORD> maximum-prefix (1-4294967295) warning-only",
5997 NEIGHBOR_STR NEIGHBOR_ADDR_STR2
5998 "Maximum number of prefix accept from this peer\n"
5999 "maximum no. of prefix limit\n"
6000 "Only give warning message when limit is exceeded\n")
6001
6002 DEFUN (neighbor_maximum_prefix_threshold_warning,
6003 neighbor_maximum_prefix_threshold_warning_cmd,
6004 "neighbor <A.B.C.D|X:X::X:X|WORD> maximum-prefix (1-4294967295) (1-100) warning-only",
6005 NEIGHBOR_STR
6006 NEIGHBOR_ADDR_STR2
6007 "Maximum number of prefix accept from this peer\n"
6008 "maximum no. of prefix limit\n"
6009 "Threshold value (%) at which to generate a warning msg\n"
6010 "Only give warning message when limit is exceeded\n")
6011 {
6012 int idx_peer = 1;
6013 int idx_number = 3;
6014 int idx_number_2 = 4;
6015 return peer_maximum_prefix_set_vty(
6016 vty, argv[idx_peer]->arg, bgp_node_afi(vty), bgp_node_safi(vty),
6017 argv[idx_number]->arg, argv[idx_number_2]->arg, 1, NULL);
6018 }
6019
6020 ALIAS_HIDDEN(
6021 neighbor_maximum_prefix_threshold_warning,
6022 neighbor_maximum_prefix_threshold_warning_hidden_cmd,
6023 "neighbor <A.B.C.D|X:X::X:X|WORD> maximum-prefix (1-4294967295) (1-100) warning-only",
6024 NEIGHBOR_STR NEIGHBOR_ADDR_STR2
6025 "Maximum number of prefix accept from this peer\n"
6026 "maximum no. of prefix limit\n"
6027 "Threshold value (%) at which to generate a warning msg\n"
6028 "Only give warning message when limit is exceeded\n")
6029
6030 DEFUN (neighbor_maximum_prefix_restart,
6031 neighbor_maximum_prefix_restart_cmd,
6032 "neighbor <A.B.C.D|X:X::X:X|WORD> maximum-prefix (1-4294967295) restart (1-65535)",
6033 NEIGHBOR_STR
6034 NEIGHBOR_ADDR_STR2
6035 "Maximum number of prefix accept from this peer\n"
6036 "maximum no. of prefix limit\n"
6037 "Restart bgp connection after limit is exceeded\n"
6038 "Restart interval in minutes\n")
6039 {
6040 int idx_peer = 1;
6041 int idx_number = 3;
6042 int idx_number_2 = 5;
6043 return peer_maximum_prefix_set_vty(
6044 vty, argv[idx_peer]->arg, bgp_node_afi(vty), bgp_node_safi(vty),
6045 argv[idx_number]->arg, NULL, 0, argv[idx_number_2]->arg);
6046 }
6047
6048 ALIAS_HIDDEN(
6049 neighbor_maximum_prefix_restart,
6050 neighbor_maximum_prefix_restart_hidden_cmd,
6051 "neighbor <A.B.C.D|X:X::X:X|WORD> maximum-prefix (1-4294967295) restart (1-65535)",
6052 NEIGHBOR_STR NEIGHBOR_ADDR_STR2
6053 "Maximum number of prefix accept from this peer\n"
6054 "maximum no. of prefix limit\n"
6055 "Restart bgp connection after limit is exceeded\n"
6056 "Restart interval in minutes\n")
6057
6058 DEFUN (neighbor_maximum_prefix_threshold_restart,
6059 neighbor_maximum_prefix_threshold_restart_cmd,
6060 "neighbor <A.B.C.D|X:X::X:X|WORD> maximum-prefix (1-4294967295) (1-100) restart (1-65535)",
6061 NEIGHBOR_STR
6062 NEIGHBOR_ADDR_STR2
6063 "Maximum number of prefixes to accept from this peer\n"
6064 "maximum no. of prefix limit\n"
6065 "Threshold value (%) at which to generate a warning msg\n"
6066 "Restart bgp connection after limit is exceeded\n"
6067 "Restart interval in minutes\n")
6068 {
6069 int idx_peer = 1;
6070 int idx_number = 3;
6071 int idx_number_2 = 4;
6072 int idx_number_3 = 6;
6073 return peer_maximum_prefix_set_vty(
6074 vty, argv[idx_peer]->arg, bgp_node_afi(vty), bgp_node_safi(vty),
6075 argv[idx_number]->arg, argv[idx_number_2]->arg, 0,
6076 argv[idx_number_3]->arg);
6077 }
6078
6079 ALIAS_HIDDEN(
6080 neighbor_maximum_prefix_threshold_restart,
6081 neighbor_maximum_prefix_threshold_restart_hidden_cmd,
6082 "neighbor <A.B.C.D|X:X::X:X|WORD> maximum-prefix (1-4294967295) (1-100) restart (1-65535)",
6083 NEIGHBOR_STR NEIGHBOR_ADDR_STR2
6084 "Maximum number of prefixes to accept from this peer\n"
6085 "maximum no. of prefix limit\n"
6086 "Threshold value (%) at which to generate a warning msg\n"
6087 "Restart bgp connection after limit is exceeded\n"
6088 "Restart interval in minutes\n")
6089
6090 DEFUN (no_neighbor_maximum_prefix,
6091 no_neighbor_maximum_prefix_cmd,
6092 "no neighbor <A.B.C.D|X:X::X:X|WORD> maximum-prefix [(1-4294967295) [(1-100)] [restart (1-65535)] [warning-only]]",
6093 NO_STR
6094 NEIGHBOR_STR
6095 NEIGHBOR_ADDR_STR2
6096 "Maximum number of prefixes to accept from this peer\n"
6097 "maximum no. of prefix limit\n"
6098 "Threshold value (%) at which to generate a warning msg\n"
6099 "Restart bgp connection after limit is exceeded\n"
6100 "Restart interval in minutes\n"
6101 "Only give warning message when limit is exceeded\n")
6102 {
6103 int idx_peer = 2;
6104 return peer_maximum_prefix_unset_vty(vty, argv[idx_peer]->arg,
6105 bgp_node_afi(vty),
6106 bgp_node_safi(vty));
6107 }
6108
6109 ALIAS_HIDDEN(
6110 no_neighbor_maximum_prefix, no_neighbor_maximum_prefix_hidden_cmd,
6111 "no neighbor <A.B.C.D|X:X::X:X|WORD> maximum-prefix [(1-4294967295) [(1-100)] [restart (1-65535)] [warning-only]]",
6112 NO_STR NEIGHBOR_STR NEIGHBOR_ADDR_STR2
6113 "Maximum number of prefixes to accept from this peer\n"
6114 "maximum no. of prefix limit\n"
6115 "Threshold value (%) at which to generate a warning msg\n"
6116 "Restart bgp connection after limit is exceeded\n"
6117 "Restart interval in minutes\n"
6118 "Only give warning message when limit is exceeded\n")
6119
6120
6121 /* "neighbor allowas-in" */
6122 DEFUN (neighbor_allowas_in,
6123 neighbor_allowas_in_cmd,
6124 "neighbor <A.B.C.D|X:X::X:X|WORD> allowas-in [<(1-10)|origin>]",
6125 NEIGHBOR_STR
6126 NEIGHBOR_ADDR_STR2
6127 "Accept as-path with my AS present in it\n"
6128 "Number of occurences of AS number\n"
6129 "Only accept my AS in the as-path if the route was originated in my AS\n")
6130 {
6131 int idx_peer = 1;
6132 int idx_number_origin = 3;
6133 int ret;
6134 int origin = 0;
6135 struct peer *peer;
6136 int allow_num = 0;
6137
6138 peer = peer_and_group_lookup_vty(vty, argv[idx_peer]->arg);
6139 if (!peer)
6140 return CMD_WARNING_CONFIG_FAILED;
6141
6142 if (argc <= idx_number_origin)
6143 allow_num = 3;
6144 else {
6145 if (argv[idx_number_origin]->type == WORD_TKN)
6146 origin = 1;
6147 else
6148 allow_num = atoi(argv[idx_number_origin]->arg);
6149 }
6150
6151 ret = peer_allowas_in_set(peer, bgp_node_afi(vty), bgp_node_safi(vty),
6152 allow_num, origin);
6153
6154 return bgp_vty_return(vty, ret);
6155 }
6156
6157 ALIAS_HIDDEN(
6158 neighbor_allowas_in, neighbor_allowas_in_hidden_cmd,
6159 "neighbor <A.B.C.D|X:X::X:X|WORD> allowas-in [<(1-10)|origin>]",
6160 NEIGHBOR_STR NEIGHBOR_ADDR_STR2
6161 "Accept as-path with my AS present in it\n"
6162 "Number of occurences of AS number\n"
6163 "Only accept my AS in the as-path if the route was originated in my AS\n")
6164
6165 DEFUN (no_neighbor_allowas_in,
6166 no_neighbor_allowas_in_cmd,
6167 "no neighbor <A.B.C.D|X:X::X:X|WORD> allowas-in [<(1-10)|origin>]",
6168 NO_STR
6169 NEIGHBOR_STR
6170 NEIGHBOR_ADDR_STR2
6171 "allow local ASN appears in aspath attribute\n"
6172 "Number of occurences of AS number\n"
6173 "Only accept my AS in the as-path if the route was originated in my AS\n")
6174 {
6175 int idx_peer = 2;
6176 int ret;
6177 struct peer *peer;
6178
6179 peer = peer_and_group_lookup_vty(vty, argv[idx_peer]->arg);
6180 if (!peer)
6181 return CMD_WARNING_CONFIG_FAILED;
6182
6183 ret = peer_allowas_in_unset(peer, bgp_node_afi(vty),
6184 bgp_node_safi(vty));
6185
6186 return bgp_vty_return(vty, ret);
6187 }
6188
6189 ALIAS_HIDDEN(
6190 no_neighbor_allowas_in, no_neighbor_allowas_in_hidden_cmd,
6191 "no neighbor <A.B.C.D|X:X::X:X|WORD> allowas-in [<(1-10)|origin>]",
6192 NO_STR NEIGHBOR_STR NEIGHBOR_ADDR_STR2
6193 "allow local ASN appears in aspath attribute\n"
6194 "Number of occurences of AS number\n"
6195 "Only accept my AS in the as-path if the route was originated in my AS\n")
6196
6197 DEFUN (neighbor_ttl_security,
6198 neighbor_ttl_security_cmd,
6199 "neighbor <A.B.C.D|X:X::X:X|WORD> ttl-security hops (1-254)",
6200 NEIGHBOR_STR
6201 NEIGHBOR_ADDR_STR2
6202 "BGP ttl-security parameters\n"
6203 "Specify the maximum number of hops to the BGP peer\n"
6204 "Number of hops to BGP peer\n")
6205 {
6206 int idx_peer = 1;
6207 int idx_number = 4;
6208 struct peer *peer;
6209 int gtsm_hops;
6210
6211 peer = peer_and_group_lookup_vty(vty, argv[idx_peer]->arg);
6212 if (!peer)
6213 return CMD_WARNING_CONFIG_FAILED;
6214
6215 gtsm_hops = strtoul(argv[idx_number]->arg, NULL, 10);
6216
6217 /*
6218 * If 'neighbor swpX', then this is for directly connected peers,
6219 * we should not accept a ttl-security hops value greater than 1.
6220 */
6221 if (peer->conf_if && (gtsm_hops > 1)) {
6222 vty_out(vty,
6223 "%s is directly connected peer, hops cannot exceed 1\n",
6224 argv[idx_peer]->arg);
6225 return CMD_WARNING_CONFIG_FAILED;
6226 }
6227
6228 return bgp_vty_return(vty, peer_ttl_security_hops_set(peer, gtsm_hops));
6229 }
6230
6231 DEFUN (no_neighbor_ttl_security,
6232 no_neighbor_ttl_security_cmd,
6233 "no neighbor <A.B.C.D|X:X::X:X|WORD> ttl-security hops (1-254)",
6234 NO_STR
6235 NEIGHBOR_STR
6236 NEIGHBOR_ADDR_STR2
6237 "BGP ttl-security parameters\n"
6238 "Specify the maximum number of hops to the BGP peer\n"
6239 "Number of hops to BGP peer\n")
6240 {
6241 int idx_peer = 2;
6242 struct peer *peer;
6243
6244 peer = peer_and_group_lookup_vty(vty, argv[idx_peer]->arg);
6245 if (!peer)
6246 return CMD_WARNING_CONFIG_FAILED;
6247
6248 return bgp_vty_return(vty, peer_ttl_security_hops_unset(peer));
6249 }
6250
6251 DEFUN (neighbor_addpath_tx_all_paths,
6252 neighbor_addpath_tx_all_paths_cmd,
6253 "neighbor <A.B.C.D|X:X::X:X|WORD> addpath-tx-all-paths",
6254 NEIGHBOR_STR
6255 NEIGHBOR_ADDR_STR2
6256 "Use addpath to advertise all paths to a neighbor\n")
6257 {
6258 int idx_peer = 1;
6259 struct peer *peer;
6260
6261 peer = peer_and_group_lookup_vty(vty, argv[idx_peer]->arg);
6262 if (!peer)
6263 return CMD_WARNING_CONFIG_FAILED;
6264
6265 bgp_addpath_set_peer_type(peer, bgp_node_afi(vty), bgp_node_safi(vty),
6266 BGP_ADDPATH_ALL);
6267 return CMD_SUCCESS;
6268 }
6269
6270 ALIAS_HIDDEN(neighbor_addpath_tx_all_paths,
6271 neighbor_addpath_tx_all_paths_hidden_cmd,
6272 "neighbor <A.B.C.D|X:X::X:X|WORD> addpath-tx-all-paths",
6273 NEIGHBOR_STR NEIGHBOR_ADDR_STR2
6274 "Use addpath to advertise all paths to a neighbor\n")
6275
6276 DEFUN (no_neighbor_addpath_tx_all_paths,
6277 no_neighbor_addpath_tx_all_paths_cmd,
6278 "no neighbor <A.B.C.D|X:X::X:X|WORD> addpath-tx-all-paths",
6279 NO_STR
6280 NEIGHBOR_STR
6281 NEIGHBOR_ADDR_STR2
6282 "Use addpath to advertise all paths to a neighbor\n")
6283 {
6284 int idx_peer = 2;
6285 struct peer *peer;
6286
6287 peer = peer_and_group_lookup_vty(vty, argv[idx_peer]->arg);
6288 if (!peer)
6289 return CMD_WARNING_CONFIG_FAILED;
6290
6291 if (peer->addpath_type[bgp_node_afi(vty)][bgp_node_safi(vty)]
6292 != BGP_ADDPATH_ALL) {
6293 vty_out(vty,
6294 "%% Peer not currently configured to transmit all paths.");
6295 return CMD_WARNING_CONFIG_FAILED;
6296 }
6297
6298 bgp_addpath_set_peer_type(peer, bgp_node_afi(vty), bgp_node_safi(vty),
6299 BGP_ADDPATH_NONE);
6300
6301 return CMD_SUCCESS;
6302 }
6303
6304 ALIAS_HIDDEN(no_neighbor_addpath_tx_all_paths,
6305 no_neighbor_addpath_tx_all_paths_hidden_cmd,
6306 "no neighbor <A.B.C.D|X:X::X:X|WORD> addpath-tx-all-paths",
6307 NO_STR NEIGHBOR_STR NEIGHBOR_ADDR_STR2
6308 "Use addpath to advertise all paths to a neighbor\n")
6309
6310 DEFUN (neighbor_addpath_tx_bestpath_per_as,
6311 neighbor_addpath_tx_bestpath_per_as_cmd,
6312 "neighbor <A.B.C.D|X:X::X:X|WORD> addpath-tx-bestpath-per-AS",
6313 NEIGHBOR_STR
6314 NEIGHBOR_ADDR_STR2
6315 "Use addpath to advertise the bestpath per each neighboring AS\n")
6316 {
6317 int idx_peer = 1;
6318 struct peer *peer;
6319
6320 peer = peer_and_group_lookup_vty(vty, argv[idx_peer]->arg);
6321 if (!peer)
6322 return CMD_WARNING_CONFIG_FAILED;
6323
6324 bgp_addpath_set_peer_type(peer, bgp_node_afi(vty), bgp_node_safi(vty),
6325 BGP_ADDPATH_BEST_PER_AS);
6326
6327 return CMD_SUCCESS;
6328 }
6329
6330 ALIAS_HIDDEN(neighbor_addpath_tx_bestpath_per_as,
6331 neighbor_addpath_tx_bestpath_per_as_hidden_cmd,
6332 "neighbor <A.B.C.D|X:X::X:X|WORD> addpath-tx-bestpath-per-AS",
6333 NEIGHBOR_STR NEIGHBOR_ADDR_STR2
6334 "Use addpath to advertise the bestpath per each neighboring AS\n")
6335
6336 DEFUN (no_neighbor_addpath_tx_bestpath_per_as,
6337 no_neighbor_addpath_tx_bestpath_per_as_cmd,
6338 "no neighbor <A.B.C.D|X:X::X:X|WORD> addpath-tx-bestpath-per-AS",
6339 NO_STR
6340 NEIGHBOR_STR
6341 NEIGHBOR_ADDR_STR2
6342 "Use addpath to advertise the bestpath per each neighboring AS\n")
6343 {
6344 int idx_peer = 2;
6345 struct peer *peer;
6346
6347 peer = peer_and_group_lookup_vty(vty, argv[idx_peer]->arg);
6348 if (!peer)
6349 return CMD_WARNING_CONFIG_FAILED;
6350
6351 if (peer->addpath_type[bgp_node_afi(vty)][bgp_node_safi(vty)]
6352 != BGP_ADDPATH_BEST_PER_AS) {
6353 vty_out(vty,
6354 "%% Peer not currently configured to transmit all best path per as.");
6355 return CMD_WARNING_CONFIG_FAILED;
6356 }
6357
6358 bgp_addpath_set_peer_type(peer, bgp_node_afi(vty), bgp_node_safi(vty),
6359 BGP_ADDPATH_NONE);
6360
6361 return CMD_SUCCESS;
6362 }
6363
6364 ALIAS_HIDDEN(no_neighbor_addpath_tx_bestpath_per_as,
6365 no_neighbor_addpath_tx_bestpath_per_as_hidden_cmd,
6366 "no neighbor <A.B.C.D|X:X::X:X|WORD> addpath-tx-bestpath-per-AS",
6367 NO_STR NEIGHBOR_STR NEIGHBOR_ADDR_STR2
6368 "Use addpath to advertise the bestpath per each neighboring AS\n")
6369
6370 static int set_ecom_list(struct vty *vty, int argc, struct cmd_token **argv,
6371 struct ecommunity **list)
6372 {
6373 struct ecommunity *ecom = NULL;
6374 struct ecommunity *ecomadd;
6375
6376 for (; argc; --argc, ++argv) {
6377
6378 ecomadd = ecommunity_str2com(argv[0]->arg,
6379 ECOMMUNITY_ROUTE_TARGET, 0);
6380 if (!ecomadd) {
6381 vty_out(vty, "Malformed community-list value\n");
6382 if (ecom)
6383 ecommunity_free(&ecom);
6384 return CMD_WARNING_CONFIG_FAILED;
6385 }
6386
6387 if (ecom) {
6388 ecommunity_merge(ecom, ecomadd);
6389 ecommunity_free(&ecomadd);
6390 } else {
6391 ecom = ecomadd;
6392 }
6393 }
6394
6395 if (*list) {
6396 ecommunity_free(&*list);
6397 }
6398 *list = ecom;
6399
6400 return CMD_SUCCESS;
6401 }
6402
6403 /*
6404 * v2vimport is true if we are handling a `import vrf ...` command
6405 */
6406 static afi_t vpn_policy_getafi(struct vty *vty, struct bgp *bgp, bool v2vimport)
6407 {
6408 afi_t afi;
6409
6410 switch (vty->node) {
6411 case BGP_IPV4_NODE:
6412 afi = AFI_IP;
6413 break;
6414 case BGP_IPV6_NODE:
6415 afi = AFI_IP6;
6416 break;
6417 default:
6418 vty_out(vty,
6419 "%% context error: valid only in address-family <ipv4|ipv6> unicast block\n");
6420 return AFI_MAX;
6421 }
6422
6423 if (!v2vimport) {
6424 if (CHECK_FLAG(bgp->af_flags[afi][SAFI_UNICAST],
6425 BGP_CONFIG_VRF_TO_VRF_IMPORT)
6426 || CHECK_FLAG(bgp->af_flags[afi][SAFI_UNICAST],
6427 BGP_CONFIG_VRF_TO_VRF_EXPORT)) {
6428 vty_out(vty,
6429 "%% error: Please unconfigure import vrf commands before using vpn commands\n");
6430 return AFI_MAX;
6431 }
6432 } else {
6433 if (CHECK_FLAG(bgp->af_flags[afi][SAFI_UNICAST],
6434 BGP_CONFIG_VRF_TO_MPLSVPN_EXPORT)
6435 || CHECK_FLAG(bgp->af_flags[afi][SAFI_UNICAST],
6436 BGP_CONFIG_MPLSVPN_TO_VRF_IMPORT)) {
6437 vty_out(vty,
6438 "%% error: Please unconfigure vpn to vrf commands before using import vrf commands\n");
6439 return AFI_MAX;
6440 }
6441 }
6442 return afi;
6443 }
6444
6445 DEFPY (af_rd_vpn_export,
6446 af_rd_vpn_export_cmd,
6447 "[no] rd vpn export ASN:NN_OR_IP-ADDRESS:NN$rd_str",
6448 NO_STR
6449 "Specify route distinguisher\n"
6450 "Between current address-family and vpn\n"
6451 "For routes leaked from current address-family to vpn\n"
6452 "Route Distinguisher (<as-number>:<number> | <ip-address>:<number>)\n")
6453 {
6454 VTY_DECLVAR_CONTEXT(bgp, bgp);
6455 struct prefix_rd prd;
6456 int ret;
6457 afi_t afi;
6458 int idx = 0;
6459 int yes = 1;
6460
6461 if (argv_find(argv, argc, "no", &idx))
6462 yes = 0;
6463
6464 if (yes) {
6465 ret = str2prefix_rd(rd_str, &prd);
6466 if (!ret) {
6467 vty_out(vty, "%% Malformed rd\n");
6468 return CMD_WARNING_CONFIG_FAILED;
6469 }
6470 }
6471
6472 afi = vpn_policy_getafi(vty, bgp, false);
6473 if (afi == AFI_MAX)
6474 return CMD_WARNING_CONFIG_FAILED;
6475
6476 /*
6477 * pre-change: un-export vpn routes (vpn->vrf routes unaffected)
6478 */
6479 vpn_leak_prechange(BGP_VPN_POLICY_DIR_TOVPN, afi,
6480 bgp_get_default(), bgp);
6481
6482 if (yes) {
6483 bgp->vpn_policy[afi].tovpn_rd = prd;
6484 SET_FLAG(bgp->vpn_policy[afi].flags,
6485 BGP_VPN_POLICY_TOVPN_RD_SET);
6486 } else {
6487 UNSET_FLAG(bgp->vpn_policy[afi].flags,
6488 BGP_VPN_POLICY_TOVPN_RD_SET);
6489 }
6490
6491 /* post-change: re-export vpn routes */
6492 vpn_leak_postchange(BGP_VPN_POLICY_DIR_TOVPN, afi,
6493 bgp_get_default(), bgp);
6494
6495 return CMD_SUCCESS;
6496 }
6497
6498 ALIAS (af_rd_vpn_export,
6499 af_no_rd_vpn_export_cmd,
6500 "no rd vpn export",
6501 NO_STR
6502 "Specify route distinguisher\n"
6503 "Between current address-family and vpn\n"
6504 "For routes leaked from current address-family to vpn\n")
6505
6506 DEFPY (af_label_vpn_export,
6507 af_label_vpn_export_cmd,
6508 "[no] label vpn export <(0-1048575)$label_val|auto$label_auto>",
6509 NO_STR
6510 "label value for VRF\n"
6511 "Between current address-family and vpn\n"
6512 "For routes leaked from current address-family to vpn\n"
6513 "Label Value <0-1048575>\n"
6514 "Automatically assign a label\n")
6515 {
6516 VTY_DECLVAR_CONTEXT(bgp, bgp);
6517 mpls_label_t label = MPLS_LABEL_NONE;
6518 afi_t afi;
6519 int idx = 0;
6520 int yes = 1;
6521
6522 if (argv_find(argv, argc, "no", &idx))
6523 yes = 0;
6524
6525 /* If "no ...", squash trailing parameter */
6526 if (!yes)
6527 label_auto = NULL;
6528
6529 if (yes) {
6530 if (!label_auto)
6531 label = label_val; /* parser should force unsigned */
6532 }
6533
6534 afi = vpn_policy_getafi(vty, bgp, false);
6535 if (afi == AFI_MAX)
6536 return CMD_WARNING_CONFIG_FAILED;
6537
6538
6539 if (label_auto && CHECK_FLAG(bgp->vpn_policy[afi].flags,
6540 BGP_VPN_POLICY_TOVPN_LABEL_AUTO))
6541 /* no change */
6542 return CMD_SUCCESS;
6543
6544 /*
6545 * pre-change: un-export vpn routes (vpn->vrf routes unaffected)
6546 */
6547 vpn_leak_prechange(BGP_VPN_POLICY_DIR_TOVPN, afi,
6548 bgp_get_default(), bgp);
6549
6550 if (!label_auto && CHECK_FLAG(bgp->vpn_policy[afi].flags,
6551 BGP_VPN_POLICY_TOVPN_LABEL_AUTO)) {
6552
6553 if (bgp->vpn_policy[afi].tovpn_label != MPLS_LABEL_NONE) {
6554
6555 /*
6556 * label has previously been automatically
6557 * assigned by labelpool: release it
6558 *
6559 * NB if tovpn_label == MPLS_LABEL_NONE it
6560 * means the automatic assignment is in flight
6561 * and therefore the labelpool callback must
6562 * detect that the auto label is not needed.
6563 */
6564
6565 bgp_lp_release(LP_TYPE_VRF,
6566 &bgp->vpn_policy[afi],
6567 bgp->vpn_policy[afi].tovpn_label);
6568 }
6569 UNSET_FLAG(bgp->vpn_policy[afi].flags,
6570 BGP_VPN_POLICY_TOVPN_LABEL_AUTO);
6571 }
6572
6573 bgp->vpn_policy[afi].tovpn_label = label;
6574 if (label_auto) {
6575 SET_FLAG(bgp->vpn_policy[afi].flags,
6576 BGP_VPN_POLICY_TOVPN_LABEL_AUTO);
6577 bgp_lp_get(LP_TYPE_VRF, &bgp->vpn_policy[afi],
6578 vpn_leak_label_callback);
6579 }
6580
6581 /* post-change: re-export vpn routes */
6582 vpn_leak_postchange(BGP_VPN_POLICY_DIR_TOVPN, afi,
6583 bgp_get_default(), bgp);
6584
6585 return CMD_SUCCESS;
6586 }
6587
6588 ALIAS (af_label_vpn_export,
6589 af_no_label_vpn_export_cmd,
6590 "no label vpn export",
6591 NO_STR
6592 "label value for VRF\n"
6593 "Between current address-family and vpn\n"
6594 "For routes leaked from current address-family to vpn\n")
6595
6596 DEFPY (af_nexthop_vpn_export,
6597 af_nexthop_vpn_export_cmd,
6598 "[no] nexthop vpn export <A.B.C.D|X:X::X:X>$nexthop_str",
6599 NO_STR
6600 "Specify next hop to use for VRF advertised prefixes\n"
6601 "Between current address-family and vpn\n"
6602 "For routes leaked from current address-family to vpn\n"
6603 "IPv4 prefix\n"
6604 "IPv6 prefix\n")
6605 {
6606 VTY_DECLVAR_CONTEXT(bgp, bgp);
6607 afi_t afi;
6608 struct prefix p;
6609 int idx = 0;
6610 int yes = 1;
6611
6612 if (argv_find(argv, argc, "no", &idx))
6613 yes = 0;
6614
6615 if (yes) {
6616 if (!sockunion2hostprefix(nexthop_str, &p))
6617 return CMD_WARNING_CONFIG_FAILED;
6618 }
6619
6620 afi = vpn_policy_getafi(vty, bgp, false);
6621 if (afi == AFI_MAX)
6622 return CMD_WARNING_CONFIG_FAILED;
6623
6624 /*
6625 * pre-change: un-export vpn routes (vpn->vrf routes unaffected)
6626 */
6627 vpn_leak_prechange(BGP_VPN_POLICY_DIR_TOVPN, afi,
6628 bgp_get_default(), bgp);
6629
6630 if (yes) {
6631 bgp->vpn_policy[afi].tovpn_nexthop = p;
6632 SET_FLAG(bgp->vpn_policy[afi].flags,
6633 BGP_VPN_POLICY_TOVPN_NEXTHOP_SET);
6634 } else {
6635 UNSET_FLAG(bgp->vpn_policy[afi].flags,
6636 BGP_VPN_POLICY_TOVPN_NEXTHOP_SET);
6637 }
6638
6639 /* post-change: re-export vpn routes */
6640 vpn_leak_postchange(BGP_VPN_POLICY_DIR_TOVPN, afi,
6641 bgp_get_default(), bgp);
6642
6643 return CMD_SUCCESS;
6644 }
6645
6646 ALIAS (af_nexthop_vpn_export,
6647 af_no_nexthop_vpn_export_cmd,
6648 "no nexthop vpn export",
6649 NO_STR
6650 "Specify next hop to use for VRF advertised prefixes\n"
6651 "Between current address-family and vpn\n"
6652 "For routes leaked from current address-family to vpn\n")
6653
6654 static int vpn_policy_getdirs(struct vty *vty, const char *dstr, int *dodir)
6655 {
6656 if (!strcmp(dstr, "import")) {
6657 dodir[BGP_VPN_POLICY_DIR_FROMVPN] = 1;
6658 } else if (!strcmp(dstr, "export")) {
6659 dodir[BGP_VPN_POLICY_DIR_TOVPN] = 1;
6660 } else if (!strcmp(dstr, "both")) {
6661 dodir[BGP_VPN_POLICY_DIR_FROMVPN] = 1;
6662 dodir[BGP_VPN_POLICY_DIR_TOVPN] = 1;
6663 } else {
6664 vty_out(vty, "%% direction parse error\n");
6665 return CMD_WARNING_CONFIG_FAILED;
6666 }
6667 return CMD_SUCCESS;
6668 }
6669
6670 DEFPY (af_rt_vpn_imexport,
6671 af_rt_vpn_imexport_cmd,
6672 "[no] <rt|route-target> vpn <import|export|both>$direction_str RTLIST...",
6673 NO_STR
6674 "Specify route target list\n"
6675 "Specify route target list\n"
6676 "Between current address-family and vpn\n"
6677 "For routes leaked from vpn to current address-family: match any\n"
6678 "For routes leaked from current address-family to vpn: set\n"
6679 "both import: match any and export: set\n"
6680 "Space separated route target list (A.B.C.D:MN|EF:OPQR|GHJK:MN)\n")
6681 {
6682 VTY_DECLVAR_CONTEXT(bgp, bgp);
6683 int ret;
6684 struct ecommunity *ecom = NULL;
6685 int dodir[BGP_VPN_POLICY_DIR_MAX] = {0};
6686 vpn_policy_direction_t dir;
6687 afi_t afi;
6688 int idx = 0;
6689 int yes = 1;
6690
6691 if (argv_find(argv, argc, "no", &idx))
6692 yes = 0;
6693
6694 afi = vpn_policy_getafi(vty, bgp, false);
6695 if (afi == AFI_MAX)
6696 return CMD_WARNING_CONFIG_FAILED;
6697
6698 ret = vpn_policy_getdirs(vty, direction_str, dodir);
6699 if (ret != CMD_SUCCESS)
6700 return ret;
6701
6702 if (yes) {
6703 if (!argv_find(argv, argc, "RTLIST", &idx)) {
6704 vty_out(vty, "%% Missing RTLIST\n");
6705 return CMD_WARNING_CONFIG_FAILED;
6706 }
6707 ret = set_ecom_list(vty, argc - idx, argv + idx, &ecom);
6708 if (ret != CMD_SUCCESS) {
6709 return ret;
6710 }
6711 }
6712
6713 for (dir = 0; dir < BGP_VPN_POLICY_DIR_MAX; ++dir) {
6714 if (!dodir[dir])
6715 continue;
6716
6717 vpn_leak_prechange(dir, afi, bgp_get_default(), bgp);
6718
6719 if (yes) {
6720 if (bgp->vpn_policy[afi].rtlist[dir])
6721 ecommunity_free(
6722 &bgp->vpn_policy[afi].rtlist[dir]);
6723 bgp->vpn_policy[afi].rtlist[dir] =
6724 ecommunity_dup(ecom);
6725 } else {
6726 if (bgp->vpn_policy[afi].rtlist[dir])
6727 ecommunity_free(
6728 &bgp->vpn_policy[afi].rtlist[dir]);
6729 bgp->vpn_policy[afi].rtlist[dir] = NULL;
6730 }
6731
6732 vpn_leak_postchange(dir, afi, bgp_get_default(), bgp);
6733 }
6734
6735 if (ecom)
6736 ecommunity_free(&ecom);
6737
6738 return CMD_SUCCESS;
6739 }
6740
6741 ALIAS (af_rt_vpn_imexport,
6742 af_no_rt_vpn_imexport_cmd,
6743 "no <rt|route-target> vpn <import|export|both>$direction_str",
6744 NO_STR
6745 "Specify route target list\n"
6746 "Specify route target list\n"
6747 "Between current address-family and vpn\n"
6748 "For routes leaked from vpn to current address-family\n"
6749 "For routes leaked from current address-family to vpn\n"
6750 "both import and export\n")
6751
6752 DEFPY (af_route_map_vpn_imexport,
6753 af_route_map_vpn_imexport_cmd,
6754 /* future: "route-map <vpn|evpn|vrf NAME> <import|export> RMAP" */
6755 "[no] route-map vpn <import|export>$direction_str RMAP$rmap_str",
6756 NO_STR
6757 "Specify route map\n"
6758 "Between current address-family and vpn\n"
6759 "For routes leaked from vpn to current address-family\n"
6760 "For routes leaked from current address-family to vpn\n"
6761 "name of route-map\n")
6762 {
6763 VTY_DECLVAR_CONTEXT(bgp, bgp);
6764 int ret;
6765 int dodir[BGP_VPN_POLICY_DIR_MAX] = {0};
6766 vpn_policy_direction_t dir;
6767 afi_t afi;
6768 int idx = 0;
6769 int yes = 1;
6770
6771 if (argv_find(argv, argc, "no", &idx))
6772 yes = 0;
6773
6774 afi = vpn_policy_getafi(vty, bgp, false);
6775 if (afi == AFI_MAX)
6776 return CMD_WARNING_CONFIG_FAILED;
6777
6778 ret = vpn_policy_getdirs(vty, direction_str, dodir);
6779 if (ret != CMD_SUCCESS)
6780 return ret;
6781
6782 for (dir = 0; dir < BGP_VPN_POLICY_DIR_MAX; ++dir) {
6783 if (!dodir[dir])
6784 continue;
6785
6786 vpn_leak_prechange(dir, afi, bgp_get_default(), bgp);
6787
6788 if (yes) {
6789 if (bgp->vpn_policy[afi].rmap_name[dir])
6790 XFREE(MTYPE_ROUTE_MAP_NAME,
6791 bgp->vpn_policy[afi].rmap_name[dir]);
6792 bgp->vpn_policy[afi].rmap_name[dir] = XSTRDUP(
6793 MTYPE_ROUTE_MAP_NAME, rmap_str);
6794 bgp->vpn_policy[afi].rmap[dir] =
6795 route_map_lookup_warn_noexist(vty, rmap_str);
6796 if (!bgp->vpn_policy[afi].rmap[dir])
6797 return CMD_SUCCESS;
6798 } else {
6799 if (bgp->vpn_policy[afi].rmap_name[dir])
6800 XFREE(MTYPE_ROUTE_MAP_NAME,
6801 bgp->vpn_policy[afi].rmap_name[dir]);
6802 bgp->vpn_policy[afi].rmap_name[dir] = NULL;
6803 bgp->vpn_policy[afi].rmap[dir] = NULL;
6804 }
6805
6806 vpn_leak_postchange(dir, afi, bgp_get_default(), bgp);
6807 }
6808
6809 return CMD_SUCCESS;
6810 }
6811
6812 ALIAS (af_route_map_vpn_imexport,
6813 af_no_route_map_vpn_imexport_cmd,
6814 "no route-map vpn <import|export>$direction_str",
6815 NO_STR
6816 "Specify route map\n"
6817 "Between current address-family and vpn\n"
6818 "For routes leaked from vpn to current address-family\n"
6819 "For routes leaked from current address-family to vpn\n")
6820
6821 DEFPY(af_import_vrf_route_map, af_import_vrf_route_map_cmd,
6822 "[no] import vrf route-map RMAP$rmap_str",
6823 NO_STR
6824 "Import routes from another VRF\n"
6825 "Vrf routes being filtered\n"
6826 "Specify route map\n"
6827 "name of route-map\n")
6828 {
6829 VTY_DECLVAR_CONTEXT(bgp, bgp);
6830 vpn_policy_direction_t dir = BGP_VPN_POLICY_DIR_FROMVPN;
6831 afi_t afi;
6832 int idx = 0;
6833 int yes = 1;
6834 struct bgp *bgp_default;
6835
6836 if (argv_find(argv, argc, "no", &idx))
6837 yes = 0;
6838
6839 afi = vpn_policy_getafi(vty, bgp, true);
6840 if (afi == AFI_MAX)
6841 return CMD_WARNING_CONFIG_FAILED;
6842
6843 bgp_default = bgp_get_default();
6844 if (!bgp_default) {
6845 int32_t ret;
6846 as_t as = bgp->as;
6847
6848 /* Auto-create assuming the same AS */
6849 ret = bgp_get(&bgp_default, &as, NULL,
6850 BGP_INSTANCE_TYPE_DEFAULT);
6851
6852 if (ret) {
6853 vty_out(vty,
6854 "VRF default is not configured as a bgp instance\n");
6855 return CMD_WARNING;
6856 }
6857 }
6858
6859 vpn_leak_prechange(dir, afi, bgp_get_default(), bgp);
6860
6861 if (yes) {
6862 if (bgp->vpn_policy[afi].rmap_name[dir])
6863 XFREE(MTYPE_ROUTE_MAP_NAME,
6864 bgp->vpn_policy[afi].rmap_name[dir]);
6865 bgp->vpn_policy[afi].rmap_name[dir] =
6866 XSTRDUP(MTYPE_ROUTE_MAP_NAME, rmap_str);
6867 bgp->vpn_policy[afi].rmap[dir] =
6868 route_map_lookup_warn_noexist(vty, rmap_str);
6869 if (!bgp->vpn_policy[afi].rmap[dir])
6870 return CMD_SUCCESS;
6871 } else {
6872 if (bgp->vpn_policy[afi].rmap_name[dir])
6873 XFREE(MTYPE_ROUTE_MAP_NAME,
6874 bgp->vpn_policy[afi].rmap_name[dir]);
6875 bgp->vpn_policy[afi].rmap_name[dir] = NULL;
6876 bgp->vpn_policy[afi].rmap[dir] = NULL;
6877 }
6878
6879 vpn_leak_postchange(dir, afi, bgp_get_default(), bgp);
6880
6881 return CMD_SUCCESS;
6882 }
6883
6884 ALIAS(af_import_vrf_route_map, af_no_import_vrf_route_map_cmd,
6885 "no import vrf route-map",
6886 NO_STR
6887 "Import routes from another VRF\n"
6888 "Vrf routes being filtered\n"
6889 "Specify route map\n")
6890
6891 DEFPY(bgp_imexport_vrf, bgp_imexport_vrf_cmd,
6892 "[no] import vrf VIEWVRFNAME$import_name",
6893 NO_STR
6894 "Import routes from another VRF\n"
6895 "VRF to import from\n"
6896 "The name of the VRF\n")
6897 {
6898 VTY_DECLVAR_CONTEXT(bgp, bgp);
6899 struct listnode *node;
6900 struct bgp *vrf_bgp, *bgp_default;
6901 int32_t ret = 0;
6902 as_t as = bgp->as;
6903 bool remove = false;
6904 int32_t idx = 0;
6905 char *vname;
6906 enum bgp_instance_type bgp_type = BGP_INSTANCE_TYPE_VRF;
6907 safi_t safi;
6908 afi_t afi;
6909
6910 if (import_name == NULL) {
6911 vty_out(vty, "%% Missing import name\n");
6912 return CMD_WARNING;
6913 }
6914
6915 if (argv_find(argv, argc, "no", &idx))
6916 remove = true;
6917
6918 afi = vpn_policy_getafi(vty, bgp, true);
6919 if (afi == AFI_MAX)
6920 return CMD_WARNING_CONFIG_FAILED;
6921
6922 safi = bgp_node_safi(vty);
6923
6924 if (((BGP_INSTANCE_TYPE_DEFAULT == bgp->inst_type)
6925 && (strcmp(import_name, VRF_DEFAULT_NAME) == 0))
6926 || (bgp->name && (strcmp(import_name, bgp->name) == 0))) {
6927 vty_out(vty, "%% Cannot %s vrf %s into itself\n",
6928 remove ? "unimport" : "import", import_name);
6929 return CMD_WARNING;
6930 }
6931
6932 bgp_default = bgp_get_default();
6933 if (!bgp_default) {
6934 /* Auto-create assuming the same AS */
6935 ret = bgp_get(&bgp_default, &as, NULL,
6936 BGP_INSTANCE_TYPE_DEFAULT);
6937
6938 if (ret) {
6939 vty_out(vty,
6940 "VRF default is not configured as a bgp instance\n");
6941 return CMD_WARNING;
6942 }
6943 }
6944
6945 vrf_bgp = bgp_lookup_by_name(import_name);
6946 if (!vrf_bgp) {
6947 if (strcmp(import_name, VRF_DEFAULT_NAME) == 0)
6948 vrf_bgp = bgp_default;
6949 else
6950 /* Auto-create assuming the same AS */
6951 ret = bgp_get(&vrf_bgp, &as, import_name, bgp_type);
6952
6953 if (ret) {
6954 vty_out(vty,
6955 "VRF %s is not configured as a bgp instance\n",
6956 import_name);
6957 return CMD_WARNING;
6958 }
6959 }
6960
6961 if (remove) {
6962 vrf_unimport_from_vrf(bgp, vrf_bgp, afi, safi);
6963 } else {
6964 /* Already importing from "import_vrf"? */
6965 for (ALL_LIST_ELEMENTS_RO(bgp->vpn_policy[afi].import_vrf, node,
6966 vname)) {
6967 if (strcmp(vname, import_name) == 0)
6968 return CMD_WARNING;
6969 }
6970
6971 vrf_import_from_vrf(bgp, vrf_bgp, afi, safi);
6972 }
6973
6974 return CMD_SUCCESS;
6975 }
6976
6977 /* This command is valid only in a bgp vrf instance or the default instance */
6978 DEFPY (bgp_imexport_vpn,
6979 bgp_imexport_vpn_cmd,
6980 "[no] <import|export>$direction_str vpn",
6981 NO_STR
6982 "Import routes to this address-family\n"
6983 "Export routes from this address-family\n"
6984 "to/from default instance VPN RIB\n")
6985 {
6986 VTY_DECLVAR_CONTEXT(bgp, bgp);
6987 int previous_state;
6988 afi_t afi;
6989 safi_t safi;
6990 int idx = 0;
6991 int yes = 1;
6992 int flag;
6993 vpn_policy_direction_t dir;
6994
6995 if (argv_find(argv, argc, "no", &idx))
6996 yes = 0;
6997
6998 if (BGP_INSTANCE_TYPE_VRF != bgp->inst_type &&
6999 BGP_INSTANCE_TYPE_DEFAULT != bgp->inst_type) {
7000
7001 vty_out(vty, "%% import|export vpn valid only for bgp vrf or default instance\n");
7002 return CMD_WARNING_CONFIG_FAILED;
7003 }
7004
7005 afi = bgp_node_afi(vty);
7006 safi = bgp_node_safi(vty);
7007 if ((SAFI_UNICAST != safi) || ((AFI_IP != afi) && (AFI_IP6 != afi))) {
7008 vty_out(vty, "%% import|export vpn valid only for unicast ipv4|ipv6\n");
7009 return CMD_WARNING_CONFIG_FAILED;
7010 }
7011
7012 if (!strcmp(direction_str, "import")) {
7013 flag = BGP_CONFIG_MPLSVPN_TO_VRF_IMPORT;
7014 dir = BGP_VPN_POLICY_DIR_FROMVPN;
7015 } else if (!strcmp(direction_str, "export")) {
7016 flag = BGP_CONFIG_VRF_TO_MPLSVPN_EXPORT;
7017 dir = BGP_VPN_POLICY_DIR_TOVPN;
7018 } else {
7019 vty_out(vty, "%% unknown direction %s\n", direction_str);
7020 return CMD_WARNING_CONFIG_FAILED;
7021 }
7022
7023 previous_state = CHECK_FLAG(bgp->af_flags[afi][safi], flag);
7024
7025 if (yes) {
7026 SET_FLAG(bgp->af_flags[afi][safi], flag);
7027 if (!previous_state) {
7028 /* trigger export current vrf */
7029 vpn_leak_postchange(dir, afi, bgp_get_default(), bgp);
7030 }
7031 } else {
7032 if (previous_state) {
7033 /* trigger un-export current vrf */
7034 vpn_leak_prechange(dir, afi, bgp_get_default(), bgp);
7035 }
7036 UNSET_FLAG(bgp->af_flags[afi][safi], flag);
7037 }
7038
7039 return CMD_SUCCESS;
7040 }
7041
7042 DEFPY (af_routetarget_import,
7043 af_routetarget_import_cmd,
7044 "[no] <rt|route-target> redirect import RTLIST...",
7045 NO_STR
7046 "Specify route target list\n"
7047 "Specify route target list\n"
7048 "Flow-spec redirect type route target\n"
7049 "Import routes to this address-family\n"
7050 "Space separated route target list (A.B.C.D:MN|EF:OPQR|GHJK:MN)\n")
7051 {
7052 VTY_DECLVAR_CONTEXT(bgp, bgp);
7053 int ret;
7054 struct ecommunity *ecom = NULL;
7055 afi_t afi;
7056 int idx = 0;
7057 int yes = 1;
7058
7059 if (argv_find(argv, argc, "no", &idx))
7060 yes = 0;
7061
7062 afi = vpn_policy_getafi(vty, bgp, false);
7063 if (afi == AFI_MAX)
7064 return CMD_WARNING_CONFIG_FAILED;
7065
7066 if (yes) {
7067 if (!argv_find(argv, argc, "RTLIST", &idx)) {
7068 vty_out(vty, "%% Missing RTLIST\n");
7069 return CMD_WARNING_CONFIG_FAILED;
7070 }
7071 ret = set_ecom_list(vty, argc - idx, argv + idx, &ecom);
7072 if (ret != CMD_SUCCESS)
7073 return ret;
7074 }
7075
7076 if (yes) {
7077 if (bgp->vpn_policy[afi].import_redirect_rtlist)
7078 ecommunity_free(&bgp->vpn_policy[afi]
7079 .import_redirect_rtlist);
7080 bgp->vpn_policy[afi].import_redirect_rtlist =
7081 ecommunity_dup(ecom);
7082 } else {
7083 if (bgp->vpn_policy[afi].import_redirect_rtlist)
7084 ecommunity_free(&bgp->vpn_policy[afi]
7085 .import_redirect_rtlist);
7086 bgp->vpn_policy[afi].import_redirect_rtlist = NULL;
7087 }
7088
7089 if (ecom)
7090 ecommunity_free(&ecom);
7091
7092 return CMD_SUCCESS;
7093 }
7094
7095 DEFUN_NOSH (address_family_ipv4_safi,
7096 address_family_ipv4_safi_cmd,
7097 "address-family ipv4 [<unicast|multicast|vpn|labeled-unicast|flowspec>]",
7098 "Enter Address Family command mode\n"
7099 "Address Family\n"
7100 BGP_SAFI_WITH_LABEL_HELP_STR)
7101 {
7102
7103 if (argc == 3) {
7104 VTY_DECLVAR_CONTEXT(bgp, bgp);
7105 safi_t safi = bgp_vty_safi_from_str(argv[2]->text);
7106 if (bgp->inst_type != BGP_INSTANCE_TYPE_DEFAULT
7107 && safi != SAFI_UNICAST && safi != SAFI_MULTICAST
7108 && safi != SAFI_EVPN) {
7109 vty_out(vty,
7110 "Only Unicast/Multicast/EVPN SAFIs supported in non-core instances.\n");
7111 return CMD_WARNING_CONFIG_FAILED;
7112 }
7113 vty->node = bgp_node_type(AFI_IP, safi);
7114 } else
7115 vty->node = BGP_IPV4_NODE;
7116
7117 return CMD_SUCCESS;
7118 }
7119
7120 DEFUN_NOSH (address_family_ipv6_safi,
7121 address_family_ipv6_safi_cmd,
7122 "address-family ipv6 [<unicast|multicast|vpn|labeled-unicast|flowspec>]",
7123 "Enter Address Family command mode\n"
7124 "Address Family\n"
7125 BGP_SAFI_WITH_LABEL_HELP_STR)
7126 {
7127 if (argc == 3) {
7128 VTY_DECLVAR_CONTEXT(bgp, bgp);
7129 safi_t safi = bgp_vty_safi_from_str(argv[2]->text);
7130 if (bgp->inst_type != BGP_INSTANCE_TYPE_DEFAULT
7131 && safi != SAFI_UNICAST && safi != SAFI_MULTICAST
7132 && safi != SAFI_EVPN) {
7133 vty_out(vty,
7134 "Only Unicast/Multicast/EVPN SAFIs supported in non-core instances.\n");
7135 return CMD_WARNING_CONFIG_FAILED;
7136 }
7137 vty->node = bgp_node_type(AFI_IP6, safi);
7138 } else
7139 vty->node = BGP_IPV6_NODE;
7140
7141 return CMD_SUCCESS;
7142 }
7143
7144 #ifdef KEEP_OLD_VPN_COMMANDS
7145 DEFUN_NOSH (address_family_vpnv4,
7146 address_family_vpnv4_cmd,
7147 "address-family vpnv4 [unicast]",
7148 "Enter Address Family command mode\n"
7149 "Address Family\n"
7150 "Address Family modifier\n")
7151 {
7152 vty->node = BGP_VPNV4_NODE;
7153 return CMD_SUCCESS;
7154 }
7155
7156 DEFUN_NOSH (address_family_vpnv6,
7157 address_family_vpnv6_cmd,
7158 "address-family vpnv6 [unicast]",
7159 "Enter Address Family command mode\n"
7160 "Address Family\n"
7161 "Address Family modifier\n")
7162 {
7163 vty->node = BGP_VPNV6_NODE;
7164 return CMD_SUCCESS;
7165 }
7166 #endif /* KEEP_OLD_VPN_COMMANDS */
7167
7168 DEFUN_NOSH (address_family_evpn,
7169 address_family_evpn_cmd,
7170 "address-family l2vpn evpn",
7171 "Enter Address Family command mode\n"
7172 "Address Family\n"
7173 "Address Family modifier\n")
7174 {
7175 VTY_DECLVAR_CONTEXT(bgp, bgp);
7176 vty->node = BGP_EVPN_NODE;
7177 return CMD_SUCCESS;
7178 }
7179
7180 DEFUN_NOSH (exit_address_family,
7181 exit_address_family_cmd,
7182 "exit-address-family",
7183 "Exit from Address Family configuration mode\n")
7184 {
7185 if (vty->node == BGP_IPV4_NODE || vty->node == BGP_IPV4M_NODE
7186 || vty->node == BGP_IPV4L_NODE || vty->node == BGP_VPNV4_NODE
7187 || vty->node == BGP_IPV6_NODE || vty->node == BGP_IPV6M_NODE
7188 || vty->node == BGP_IPV6L_NODE || vty->node == BGP_VPNV6_NODE
7189 || vty->node == BGP_EVPN_NODE
7190 || vty->node == BGP_FLOWSPECV4_NODE
7191 || vty->node == BGP_FLOWSPECV6_NODE)
7192 vty->node = BGP_NODE;
7193 return CMD_SUCCESS;
7194 }
7195
7196 /* Recalculate bestpath and re-advertise a prefix */
7197 static int bgp_clear_prefix(struct vty *vty, const char *view_name,
7198 const char *ip_str, afi_t afi, safi_t safi,
7199 struct prefix_rd *prd)
7200 {
7201 int ret;
7202 struct prefix match;
7203 struct bgp_node *rn;
7204 struct bgp_node *rm;
7205 struct bgp *bgp;
7206 struct bgp_table *table;
7207 struct bgp_table *rib;
7208
7209 /* BGP structure lookup. */
7210 if (view_name) {
7211 bgp = bgp_lookup_by_name(view_name);
7212 if (bgp == NULL) {
7213 vty_out(vty, "%% Can't find BGP instance %s\n",
7214 view_name);
7215 return CMD_WARNING;
7216 }
7217 } else {
7218 bgp = bgp_get_default();
7219 if (bgp == NULL) {
7220 vty_out(vty, "%% No BGP process is configured\n");
7221 return CMD_WARNING;
7222 }
7223 }
7224
7225 /* Check IP address argument. */
7226 ret = str2prefix(ip_str, &match);
7227 if (!ret) {
7228 vty_out(vty, "%% address is malformed\n");
7229 return CMD_WARNING;
7230 }
7231
7232 match.family = afi2family(afi);
7233 rib = bgp->rib[afi][safi];
7234
7235 if (safi == SAFI_MPLS_VPN) {
7236 for (rn = bgp_table_top(rib); rn; rn = bgp_route_next(rn)) {
7237 if (prd && memcmp(rn->p.u.val, prd->val, 8) != 0)
7238 continue;
7239
7240 table = bgp_node_get_bgp_table_info(rn);
7241 if (table != NULL) {
7242
7243 if ((rm = bgp_node_match(table, &match))
7244 != NULL) {
7245 if (rm->p.prefixlen
7246 == match.prefixlen) {
7247 SET_FLAG(rm->flags,
7248 BGP_NODE_USER_CLEAR);
7249 bgp_process(bgp, rm, afi, safi);
7250 }
7251 bgp_unlock_node(rm);
7252 }
7253 }
7254 }
7255 } else {
7256 if ((rn = bgp_node_match(rib, &match)) != NULL) {
7257 if (rn->p.prefixlen == match.prefixlen) {
7258 SET_FLAG(rn->flags, BGP_NODE_USER_CLEAR);
7259 bgp_process(bgp, rn, afi, safi);
7260 }
7261 bgp_unlock_node(rn);
7262 }
7263 }
7264
7265 return CMD_SUCCESS;
7266 }
7267
7268 /* one clear bgp command to rule them all */
7269 DEFUN (clear_ip_bgp_all,
7270 clear_ip_bgp_all_cmd,
7271 "clear [ip] bgp [<view|vrf> VIEWVRFNAME] [<ipv4|ipv6|l2vpn> [<unicast|multicast|vpn|labeled-unicast|flowspec|evpn>]] <*|A.B.C.D|X:X::X:X|WORD|(1-4294967295)|external|peer-group WORD> [<soft [<in|out>]|in [prefix-filter]|out>]",
7272 CLEAR_STR
7273 IP_STR
7274 BGP_STR
7275 BGP_INSTANCE_HELP_STR
7276 BGP_AFI_HELP_STR
7277 "Address Family\n"
7278 BGP_SAFI_WITH_LABEL_HELP_STR
7279 "Address Family modifier\n"
7280 "Clear all peers\n"
7281 "BGP neighbor address to clear\n"
7282 "BGP IPv6 neighbor to clear\n"
7283 "BGP neighbor on interface to clear\n"
7284 "Clear peers with the AS number\n"
7285 "Clear all external peers\n"
7286 "Clear all members of peer-group\n"
7287 "BGP peer-group name\n"
7288 BGP_SOFT_STR
7289 BGP_SOFT_IN_STR
7290 BGP_SOFT_OUT_STR
7291 BGP_SOFT_IN_STR
7292 "Push out prefix-list ORF and do inbound soft reconfig\n"
7293 BGP_SOFT_OUT_STR)
7294 {
7295 char *vrf = NULL;
7296
7297 afi_t afi = AFI_IP6;
7298 safi_t safi = SAFI_UNICAST;
7299 enum clear_sort clr_sort = clear_peer;
7300 enum bgp_clear_type clr_type;
7301 char *clr_arg = NULL;
7302
7303 int idx = 0;
7304
7305 /* clear [ip] bgp */
7306 if (argv_find(argv, argc, "ip", &idx))
7307 afi = AFI_IP;
7308
7309 /* [<vrf> VIEWVRFNAME] */
7310 if (argv_find(argv, argc, "vrf", &idx)) {
7311 vrf = argv[idx + 1]->arg;
7312 idx += 2;
7313 if (vrf && strmatch(vrf, VRF_DEFAULT_NAME))
7314 vrf = NULL;
7315 } else if (argv_find(argv, argc, "view", &idx)) {
7316 /* [<view> VIEWVRFNAME] */
7317 vrf = argv[idx + 1]->arg;
7318 idx += 2;
7319 }
7320 /* ["BGP_AFI_CMD_STR" ["BGP_SAFI_CMD_STR"]] */
7321 if (argv_find_and_parse_afi(argv, argc, &idx, &afi))
7322 argv_find_and_parse_safi(argv, argc, &idx, &safi);
7323
7324 /* <*|A.B.C.D|X:X::X:X|WORD|(1-4294967295)|external|peer-group WORD> */
7325 if (argv_find(argv, argc, "*", &idx)) {
7326 clr_sort = clear_all;
7327 } else if (argv_find(argv, argc, "A.B.C.D", &idx)) {
7328 clr_sort = clear_peer;
7329 clr_arg = argv[idx]->arg;
7330 } else if (argv_find(argv, argc, "X:X::X:X", &idx)) {
7331 clr_sort = clear_peer;
7332 clr_arg = argv[idx]->arg;
7333 } else if (argv_find(argv, argc, "peer-group", &idx)) {
7334 clr_sort = clear_group;
7335 idx++;
7336 clr_arg = argv[idx]->arg;
7337 } else if (argv_find(argv, argc, "WORD", &idx)) {
7338 clr_sort = clear_peer;
7339 clr_arg = argv[idx]->arg;
7340 } else if (argv_find(argv, argc, "(1-4294967295)", &idx)) {
7341 clr_sort = clear_as;
7342 clr_arg = argv[idx]->arg;
7343 } else if (argv_find(argv, argc, "external", &idx)) {
7344 clr_sort = clear_external;
7345 }
7346
7347 /* [<soft [<in|out>]|in [prefix-filter]|out>] */
7348 if (argv_find(argv, argc, "soft", &idx)) {
7349 if (argv_find(argv, argc, "in", &idx)
7350 || argv_find(argv, argc, "out", &idx))
7351 clr_type = strmatch(argv[idx]->text, "in")
7352 ? BGP_CLEAR_SOFT_IN
7353 : BGP_CLEAR_SOFT_OUT;
7354 else
7355 clr_type = BGP_CLEAR_SOFT_BOTH;
7356 } else if (argv_find(argv, argc, "in", &idx)) {
7357 clr_type = argv_find(argv, argc, "prefix-filter", &idx)
7358 ? BGP_CLEAR_SOFT_IN_ORF_PREFIX
7359 : BGP_CLEAR_SOFT_IN;
7360 } else if (argv_find(argv, argc, "out", &idx)) {
7361 clr_type = BGP_CLEAR_SOFT_OUT;
7362 } else
7363 clr_type = BGP_CLEAR_SOFT_NONE;
7364
7365 return bgp_clear_vty(vty, vrf, afi, safi, clr_sort, clr_type, clr_arg);
7366 }
7367
7368 DEFUN (clear_ip_bgp_prefix,
7369 clear_ip_bgp_prefix_cmd,
7370 "clear [ip] bgp [<view|vrf> VIEWVRFNAME] prefix A.B.C.D/M",
7371 CLEAR_STR
7372 IP_STR
7373 BGP_STR
7374 BGP_INSTANCE_HELP_STR
7375 "Clear bestpath and re-advertise\n"
7376 "IPv4 prefix\n")
7377 {
7378 char *vrf = NULL;
7379 char *prefix = NULL;
7380
7381 int idx = 0;
7382
7383 /* [<view|vrf> VIEWVRFNAME] */
7384 if (argv_find(argv, argc, "vrf", &idx)) {
7385 vrf = argv[idx + 1]->arg;
7386 idx += 2;
7387 if (vrf && strmatch(vrf, VRF_DEFAULT_NAME))
7388 vrf = NULL;
7389 } else if (argv_find(argv, argc, "view", &idx)) {
7390 /* [<view> VIEWVRFNAME] */
7391 vrf = argv[idx + 1]->arg;
7392 idx += 2;
7393 }
7394
7395 prefix = argv[argc - 1]->arg;
7396
7397 return bgp_clear_prefix(vty, vrf, prefix, AFI_IP, SAFI_UNICAST, NULL);
7398 }
7399
7400 DEFUN (clear_bgp_ipv6_safi_prefix,
7401 clear_bgp_ipv6_safi_prefix_cmd,
7402 "clear [ip] bgp ipv6 "BGP_SAFI_CMD_STR" prefix X:X::X:X/M",
7403 CLEAR_STR
7404 IP_STR
7405 BGP_STR
7406 "Address Family\n"
7407 BGP_SAFI_HELP_STR
7408 "Clear bestpath and re-advertise\n"
7409 "IPv6 prefix\n")
7410 {
7411 int idx_safi = 0;
7412 int idx_ipv6_prefix = 0;
7413 safi_t safi = SAFI_UNICAST;
7414 char *prefix = argv_find(argv, argc, "X:X::X:X/M", &idx_ipv6_prefix) ?
7415 argv[idx_ipv6_prefix]->arg : NULL;
7416
7417 argv_find_and_parse_safi(argv, argc, &idx_safi, &safi);
7418 return bgp_clear_prefix(
7419 vty, NULL, prefix, AFI_IP6,
7420 safi, NULL);
7421 }
7422
7423 DEFUN (clear_bgp_instance_ipv6_safi_prefix,
7424 clear_bgp_instance_ipv6_safi_prefix_cmd,
7425 "clear [ip] bgp <view|vrf> VIEWVRFNAME ipv6 "BGP_SAFI_CMD_STR" prefix X:X::X:X/M",
7426 CLEAR_STR
7427 IP_STR
7428 BGP_STR
7429 BGP_INSTANCE_HELP_STR
7430 "Address Family\n"
7431 BGP_SAFI_HELP_STR
7432 "Clear bestpath and re-advertise\n"
7433 "IPv6 prefix\n")
7434 {
7435 int idx_safi = 0;
7436 int idx_vrfview = 0;
7437 int idx_ipv6_prefix = 0;
7438 safi_t safi = SAFI_UNICAST;
7439 char *prefix = argv_find(argv, argc, "X:X::X:X/M", &idx_ipv6_prefix) ?
7440 argv[idx_ipv6_prefix]->arg : NULL;
7441 char *vrfview = NULL;
7442
7443 /* [<view|vrf> VIEWVRFNAME] */
7444 if (argv_find(argv, argc, "vrf", &idx_vrfview)) {
7445 vrfview = argv[idx_vrfview + 1]->arg;
7446 if (vrfview && strmatch(vrfview, VRF_DEFAULT_NAME))
7447 vrfview = NULL;
7448 } else if (argv_find(argv, argc, "view", &idx_vrfview)) {
7449 /* [<view> VIEWVRFNAME] */
7450 vrfview = argv[idx_vrfview + 1]->arg;
7451 }
7452 argv_find_and_parse_safi(argv, argc, &idx_safi, &safi);
7453
7454 return bgp_clear_prefix(
7455 vty, vrfview, prefix,
7456 AFI_IP6, safi, NULL);
7457 }
7458
7459 DEFUN (show_bgp_views,
7460 show_bgp_views_cmd,
7461 "show [ip] bgp views",
7462 SHOW_STR
7463 IP_STR
7464 BGP_STR
7465 "Show the defined BGP views\n")
7466 {
7467 struct list *inst = bm->bgp;
7468 struct listnode *node;
7469 struct bgp *bgp;
7470
7471 if (!bgp_option_check(BGP_OPT_MULTIPLE_INSTANCE)) {
7472 vty_out(vty, "BGP Multiple Instance is not enabled\n");
7473 return CMD_WARNING;
7474 }
7475
7476 vty_out(vty, "Defined BGP views:\n");
7477 for (ALL_LIST_ELEMENTS_RO(inst, node, bgp)) {
7478 /* Skip VRFs. */
7479 if (bgp->inst_type == BGP_INSTANCE_TYPE_VRF)
7480 continue;
7481 vty_out(vty, "\t%s (AS%u)\n", bgp->name ? bgp->name : "(null)",
7482 bgp->as);
7483 }
7484
7485 return CMD_SUCCESS;
7486 }
7487
7488 DEFUN (show_bgp_vrfs,
7489 show_bgp_vrfs_cmd,
7490 "show [ip] bgp vrfs [json]",
7491 SHOW_STR
7492 IP_STR
7493 BGP_STR
7494 "Show BGP VRFs\n"
7495 JSON_STR)
7496 {
7497 char buf[ETHER_ADDR_STRLEN];
7498 struct list *inst = bm->bgp;
7499 struct listnode *node;
7500 struct bgp *bgp;
7501 bool uj = use_json(argc, argv);
7502 json_object *json = NULL;
7503 json_object *json_vrfs = NULL;
7504 int count = 0;
7505
7506 if (!bgp_option_check(BGP_OPT_MULTIPLE_INSTANCE)) {
7507 vty_out(vty, "BGP Multiple Instance is not enabled\n");
7508 return CMD_WARNING;
7509 }
7510
7511 if (uj) {
7512 json = json_object_new_object();
7513 json_vrfs = json_object_new_object();
7514 }
7515
7516 for (ALL_LIST_ELEMENTS_RO(inst, node, bgp)) {
7517 const char *name, *type;
7518 struct peer *peer;
7519 struct listnode *node2, *nnode2;
7520 int peers_cfg, peers_estb;
7521 json_object *json_vrf = NULL;
7522
7523 /* Skip Views. */
7524 if (bgp->inst_type == BGP_INSTANCE_TYPE_VIEW)
7525 continue;
7526
7527 count++;
7528 if (!uj && count == 1)
7529 vty_out(vty,
7530 "%4s %-5s %-16s %9s %10s %-37s %-10s %-15s\n",
7531 "Type", "Id", "routerId", "#PeersVfg",
7532 "#PeersEstb", "Name", "L3-VNI", "Rmac");
7533
7534 peers_cfg = peers_estb = 0;
7535 if (uj)
7536 json_vrf = json_object_new_object();
7537
7538
7539 for (ALL_LIST_ELEMENTS(bgp->peer, node2, nnode2, peer)) {
7540 if (!CHECK_FLAG(peer->flags, PEER_FLAG_CONFIG_NODE))
7541 continue;
7542 peers_cfg++;
7543 if (peer->status == Established)
7544 peers_estb++;
7545 }
7546
7547 if (bgp->inst_type == BGP_INSTANCE_TYPE_DEFAULT) {
7548 name = VRF_DEFAULT_NAME;
7549 type = "DFLT";
7550 } else {
7551 name = bgp->name;
7552 type = "VRF";
7553 }
7554
7555
7556 if (uj) {
7557 int64_t vrf_id_ui = (bgp->vrf_id == VRF_UNKNOWN)
7558 ? -1
7559 : (int64_t)bgp->vrf_id;
7560 json_object_string_add(json_vrf, "type", type);
7561 json_object_int_add(json_vrf, "vrfId", vrf_id_ui);
7562 json_object_string_add(json_vrf, "routerId",
7563 inet_ntoa(bgp->router_id));
7564 json_object_int_add(json_vrf, "numConfiguredPeers",
7565 peers_cfg);
7566 json_object_int_add(json_vrf, "numEstablishedPeers",
7567 peers_estb);
7568
7569 json_object_int_add(json_vrf, "l3vni", bgp->l3vni);
7570 json_object_string_add(
7571 json_vrf, "rmac",
7572 prefix_mac2str(&bgp->rmac, buf, sizeof(buf)));
7573 json_object_object_add(json_vrfs, name, json_vrf);
7574 } else
7575 vty_out(vty,
7576 "%4s %-5d %-16s %9u %10u %-37s %-10u %-15s\n",
7577 type,
7578 bgp->vrf_id == VRF_UNKNOWN ? -1
7579 : (int)bgp->vrf_id,
7580 inet_ntoa(bgp->router_id), peers_cfg,
7581 peers_estb, name, bgp->l3vni,
7582 prefix_mac2str(&bgp->rmac, buf, sizeof(buf)));
7583 }
7584
7585 if (uj) {
7586 json_object_object_add(json, "vrfs", json_vrfs);
7587
7588 json_object_int_add(json, "totalVrfs", count);
7589
7590 vty_out(vty, "%s\n", json_object_to_json_string_ext(
7591 json, JSON_C_TO_STRING_PRETTY));
7592 json_object_free(json);
7593 } else {
7594 if (count)
7595 vty_out(vty,
7596 "\nTotal number of VRFs (including default): %d\n",
7597 count);
7598 }
7599
7600 return CMD_SUCCESS;
7601 }
7602
7603 DEFUN (show_bgp_mac_hash,
7604 show_bgp_mac_hash_cmd,
7605 "show bgp mac hash",
7606 SHOW_STR
7607 BGP_STR
7608 "Mac Address\n"
7609 "Mac Address database\n")
7610 {
7611 bgp_mac_dump_table(vty);
7612
7613 return CMD_SUCCESS;
7614 }
7615
7616 static void show_tip_entry(struct hash_bucket *bucket, void *args)
7617 {
7618 struct vty *vty = (struct vty *)args;
7619 struct tip_addr *tip = (struct tip_addr *)bucket->data;
7620
7621 vty_out(vty, "addr: %s, count: %d\n", inet_ntoa(tip->addr),
7622 tip->refcnt);
7623 }
7624
7625 static void bgp_show_martian_nexthops(struct vty *vty, struct bgp *bgp)
7626 {
7627 vty_out(vty, "self nexthop database:\n");
7628 bgp_nexthop_show_address_hash(vty, bgp);
7629
7630 vty_out(vty, "Tunnel-ip database:\n");
7631 hash_iterate(bgp->tip_hash,
7632 (void (*)(struct hash_bucket *, void *))show_tip_entry,
7633 vty);
7634 }
7635
7636 DEFUN(show_bgp_martian_nexthop_db, show_bgp_martian_nexthop_db_cmd,
7637 "show bgp [<view|vrf> VIEWVRFNAME] martian next-hop",
7638 SHOW_STR BGP_STR BGP_INSTANCE_HELP_STR
7639 "martian next-hops\n"
7640 "martian next-hop database\n")
7641 {
7642 struct bgp *bgp = NULL;
7643 int idx = 0;
7644 char *name = NULL;
7645
7646 /* [<vrf> VIEWVRFNAME] */
7647 if (argv_find(argv, argc, "vrf", &idx)) {
7648 name = argv[idx + 1]->arg;
7649 if (name && strmatch(name, VRF_DEFAULT_NAME))
7650 name = NULL;
7651 } else if (argv_find(argv, argc, "view", &idx))
7652 /* [<view> VIEWVRFNAME] */
7653 name = argv[idx + 1]->arg;
7654 if (name)
7655 bgp = bgp_lookup_by_name(name);
7656 else
7657 bgp = bgp_get_default();
7658
7659 if (!bgp) {
7660 vty_out(vty, "%% No BGP process is configured\n");
7661 return CMD_WARNING;
7662 }
7663 bgp_show_martian_nexthops(vty, bgp);
7664
7665 return CMD_SUCCESS;
7666 }
7667
7668 DEFUN (show_bgp_memory,
7669 show_bgp_memory_cmd,
7670 "show [ip] bgp memory",
7671 SHOW_STR
7672 IP_STR
7673 BGP_STR
7674 "Global BGP memory statistics\n")
7675 {
7676 char memstrbuf[MTYPE_MEMSTR_LEN];
7677 unsigned long count;
7678
7679 /* RIB related usage stats */
7680 count = mtype_stats_alloc(MTYPE_BGP_NODE);
7681 vty_out(vty, "%ld RIB nodes, using %s of memory\n", count,
7682 mtype_memstr(memstrbuf, sizeof(memstrbuf),
7683 count * sizeof(struct bgp_node)));
7684
7685 count = mtype_stats_alloc(MTYPE_BGP_ROUTE);
7686 vty_out(vty, "%ld BGP routes, using %s of memory\n", count,
7687 mtype_memstr(memstrbuf, sizeof(memstrbuf),
7688 count * sizeof(struct bgp_path_info)));
7689 if ((count = mtype_stats_alloc(MTYPE_BGP_ROUTE_EXTRA)))
7690 vty_out(vty, "%ld BGP route ancillaries, using %s of memory\n",
7691 count,
7692 mtype_memstr(
7693 memstrbuf, sizeof(memstrbuf),
7694 count * sizeof(struct bgp_path_info_extra)));
7695
7696 if ((count = mtype_stats_alloc(MTYPE_BGP_STATIC)))
7697 vty_out(vty, "%ld Static routes, using %s of memory\n", count,
7698 mtype_memstr(memstrbuf, sizeof(memstrbuf),
7699 count * sizeof(struct bgp_static)));
7700
7701 if ((count = mtype_stats_alloc(MTYPE_BGP_PACKET)))
7702 vty_out(vty, "%ld Packets, using %s of memory\n", count,
7703 mtype_memstr(memstrbuf, sizeof(memstrbuf),
7704 count * sizeof(struct bpacket)));
7705
7706 /* Adj-In/Out */
7707 if ((count = mtype_stats_alloc(MTYPE_BGP_ADJ_IN)))
7708 vty_out(vty, "%ld Adj-In entries, using %s of memory\n", count,
7709 mtype_memstr(memstrbuf, sizeof(memstrbuf),
7710 count * sizeof(struct bgp_adj_in)));
7711 if ((count = mtype_stats_alloc(MTYPE_BGP_ADJ_OUT)))
7712 vty_out(vty, "%ld Adj-Out entries, using %s of memory\n", count,
7713 mtype_memstr(memstrbuf, sizeof(memstrbuf),
7714 count * sizeof(struct bgp_adj_out)));
7715
7716 if ((count = mtype_stats_alloc(MTYPE_BGP_NEXTHOP_CACHE)))
7717 vty_out(vty, "%ld Nexthop cache entries, using %s of memory\n",
7718 count,
7719 mtype_memstr(memstrbuf, sizeof(memstrbuf),
7720 count * sizeof(struct bgp_nexthop_cache)));
7721
7722 if ((count = mtype_stats_alloc(MTYPE_BGP_DAMP_INFO)))
7723 vty_out(vty, "%ld Dampening entries, using %s of memory\n",
7724 count,
7725 mtype_memstr(memstrbuf, sizeof(memstrbuf),
7726 count * sizeof(struct bgp_damp_info)));
7727
7728 /* Attributes */
7729 count = attr_count();
7730 vty_out(vty, "%ld BGP attributes, using %s of memory\n", count,
7731 mtype_memstr(memstrbuf, sizeof(memstrbuf),
7732 count * sizeof(struct attr)));
7733
7734 if ((count = attr_unknown_count()))
7735 vty_out(vty, "%ld unknown attributes\n", count);
7736
7737 /* AS_PATH attributes */
7738 count = aspath_count();
7739 vty_out(vty, "%ld BGP AS-PATH entries, using %s of memory\n", count,
7740 mtype_memstr(memstrbuf, sizeof(memstrbuf),
7741 count * sizeof(struct aspath)));
7742
7743 count = mtype_stats_alloc(MTYPE_AS_SEG);
7744 vty_out(vty, "%ld BGP AS-PATH segments, using %s of memory\n", count,
7745 mtype_memstr(memstrbuf, sizeof(memstrbuf),
7746 count * sizeof(struct assegment)));
7747
7748 /* Other attributes */
7749 if ((count = community_count()))
7750 vty_out(vty, "%ld BGP community entries, using %s of memory\n",
7751 count, mtype_memstr(memstrbuf, sizeof(memstrbuf),
7752 count * sizeof(struct community)));
7753 if ((count = mtype_stats_alloc(MTYPE_ECOMMUNITY)))
7754 vty_out(vty, "%ld BGP community entries, using %s of memory\n",
7755 count, mtype_memstr(memstrbuf, sizeof(memstrbuf),
7756 count * sizeof(struct ecommunity)));
7757 if ((count = mtype_stats_alloc(MTYPE_LCOMMUNITY)))
7758 vty_out(vty,
7759 "%ld BGP large-community entries, using %s of memory\n",
7760 count, mtype_memstr(memstrbuf, sizeof(memstrbuf),
7761 count * sizeof(struct lcommunity)));
7762
7763 if ((count = mtype_stats_alloc(MTYPE_CLUSTER)))
7764 vty_out(vty, "%ld Cluster lists, using %s of memory\n", count,
7765 mtype_memstr(memstrbuf, sizeof(memstrbuf),
7766 count * sizeof(struct cluster_list)));
7767
7768 /* Peer related usage */
7769 count = mtype_stats_alloc(MTYPE_BGP_PEER);
7770 vty_out(vty, "%ld peers, using %s of memory\n", count,
7771 mtype_memstr(memstrbuf, sizeof(memstrbuf),
7772 count * sizeof(struct peer)));
7773
7774 if ((count = mtype_stats_alloc(MTYPE_PEER_GROUP)))
7775 vty_out(vty, "%ld peer groups, using %s of memory\n", count,
7776 mtype_memstr(memstrbuf, sizeof(memstrbuf),
7777 count * sizeof(struct peer_group)));
7778
7779 /* Other */
7780 if ((count = mtype_stats_alloc(MTYPE_HASH)))
7781 vty_out(vty, "%ld hash tables, using %s of memory\n", count,
7782 mtype_memstr(memstrbuf, sizeof(memstrbuf),
7783 count * sizeof(struct hash)));
7784 if ((count = mtype_stats_alloc(MTYPE_HASH_BACKET)))
7785 vty_out(vty, "%ld hash buckets, using %s of memory\n", count,
7786 mtype_memstr(memstrbuf, sizeof(memstrbuf),
7787 count * sizeof(struct hash_bucket)));
7788 if ((count = mtype_stats_alloc(MTYPE_BGP_REGEXP)))
7789 vty_out(vty, "%ld compiled regexes, using %s of memory\n",
7790 count, mtype_memstr(memstrbuf, sizeof(memstrbuf),
7791 count * sizeof(regex_t)));
7792 return CMD_SUCCESS;
7793 }
7794
7795 static void bgp_show_bestpath_json(struct bgp *bgp, json_object *json)
7796 {
7797 json_object *bestpath = json_object_new_object();
7798
7799 if (bgp_flag_check(bgp, BGP_FLAG_ASPATH_IGNORE))
7800 json_object_string_add(bestpath, "asPath", "ignore");
7801
7802 if (bgp_flag_check(bgp, BGP_FLAG_ASPATH_CONFED))
7803 json_object_string_add(bestpath, "asPath", "confed");
7804
7805 if (bgp_flag_check(bgp, BGP_FLAG_ASPATH_MULTIPATH_RELAX)) {
7806 if (bgp_flag_check(bgp, BGP_FLAG_MULTIPATH_RELAX_AS_SET))
7807 json_object_string_add(bestpath, "multiPathRelax",
7808 "as-set");
7809 else
7810 json_object_string_add(bestpath, "multiPathRelax",
7811 "true");
7812 } else
7813 json_object_string_add(bestpath, "multiPathRelax", "false");
7814
7815 if (bgp_flag_check(bgp, BGP_FLAG_COMPARE_ROUTER_ID))
7816 json_object_string_add(bestpath, "compareRouterId", "true");
7817 if (bgp_flag_check(bgp, BGP_FLAG_MED_CONFED)
7818 || bgp_flag_check(bgp, BGP_FLAG_MED_MISSING_AS_WORST)) {
7819 if (bgp_flag_check(bgp, BGP_FLAG_MED_CONFED))
7820 json_object_string_add(bestpath, "med", "confed");
7821 if (bgp_flag_check(bgp, BGP_FLAG_MED_MISSING_AS_WORST))
7822 json_object_string_add(bestpath, "med",
7823 "missing-as-worst");
7824 else
7825 json_object_string_add(bestpath, "med", "true");
7826 }
7827
7828 json_object_object_add(json, "bestPath", bestpath);
7829 }
7830
7831 /* Show BGP peer's summary information. */
7832 static int bgp_show_summary(struct vty *vty, struct bgp *bgp, int afi, int safi,
7833 bool use_json, json_object *json)
7834 {
7835 struct peer *peer;
7836 struct listnode *node, *nnode;
7837 unsigned int count = 0, dn_count = 0;
7838 char timebuf[BGP_UPTIME_LEN], dn_flag[2];
7839 char neighbor_buf[VTY_BUFSIZ];
7840 int neighbor_col_default_width = 16;
7841 int len;
7842 int max_neighbor_width = 0;
7843 int pfx_rcd_safi;
7844 json_object *json_peer = NULL;
7845 json_object *json_peers = NULL;
7846 struct peer_af *paf;
7847
7848 /* labeled-unicast routes are installed in the unicast table so in order
7849 * to
7850 * display the correct PfxRcd value we must look at SAFI_UNICAST
7851 */
7852 if (safi == SAFI_LABELED_UNICAST)
7853 pfx_rcd_safi = SAFI_UNICAST;
7854 else
7855 pfx_rcd_safi = safi;
7856
7857 if (use_json) {
7858 if (json == NULL)
7859 json = json_object_new_object();
7860
7861 json_peers = json_object_new_object();
7862 } else {
7863 /* Loop over all neighbors that will be displayed to determine
7864 * how many
7865 * characters are needed for the Neighbor column
7866 */
7867 for (ALL_LIST_ELEMENTS(bgp->peer, node, nnode, peer)) {
7868 if (!CHECK_FLAG(peer->flags, PEER_FLAG_CONFIG_NODE))
7869 continue;
7870
7871 if (peer->afc[afi][safi]) {
7872 memset(dn_flag, '\0', sizeof(dn_flag));
7873 if (peer_dynamic_neighbor(peer))
7874 dn_flag[0] = '*';
7875
7876 if (peer->hostname
7877 && bgp_flag_check(bgp,
7878 BGP_FLAG_SHOW_HOSTNAME))
7879 sprintf(neighbor_buf, "%s%s(%s) ",
7880 dn_flag, peer->hostname,
7881 peer->host);
7882 else
7883 sprintf(neighbor_buf, "%s%s ", dn_flag,
7884 peer->host);
7885
7886 len = strlen(neighbor_buf);
7887
7888 if (len > max_neighbor_width)
7889 max_neighbor_width = len;
7890 }
7891 }
7892
7893 /* Originally we displayed the Neighbor column as 16
7894 * characters wide so make that the default
7895 */
7896 if (max_neighbor_width < neighbor_col_default_width)
7897 max_neighbor_width = neighbor_col_default_width;
7898 }
7899
7900 for (ALL_LIST_ELEMENTS(bgp->peer, node, nnode, peer)) {
7901 if (!CHECK_FLAG(peer->flags, PEER_FLAG_CONFIG_NODE))
7902 continue;
7903
7904 if (!peer->afc[afi][safi])
7905 continue;
7906
7907 if (!count) {
7908 unsigned long ents;
7909 char memstrbuf[MTYPE_MEMSTR_LEN];
7910 int64_t vrf_id_ui;
7911
7912 vrf_id_ui = (bgp->vrf_id == VRF_UNKNOWN)
7913 ? -1
7914 : (int64_t)bgp->vrf_id;
7915
7916 /* Usage summary and header */
7917 if (use_json) {
7918 json_object_string_add(
7919 json, "routerId",
7920 inet_ntoa(bgp->router_id));
7921 json_object_int_add(json, "as", bgp->as);
7922 json_object_int_add(json, "vrfId", vrf_id_ui);
7923 json_object_string_add(
7924 json, "vrfName",
7925 (bgp->inst_type
7926 == BGP_INSTANCE_TYPE_DEFAULT)
7927 ? VRF_DEFAULT_NAME
7928 : bgp->name);
7929 } else {
7930 vty_out(vty,
7931 "BGP router identifier %s, local AS number %u vrf-id %d",
7932 inet_ntoa(bgp->router_id), bgp->as,
7933 bgp->vrf_id == VRF_UNKNOWN
7934 ? -1
7935 : (int)bgp->vrf_id);
7936 vty_out(vty, "\n");
7937 }
7938
7939 if (bgp_update_delay_configured(bgp)) {
7940 if (use_json) {
7941 json_object_int_add(
7942 json, "updateDelayLimit",
7943 bgp->v_update_delay);
7944
7945 if (bgp->v_update_delay
7946 != bgp->v_establish_wait)
7947 json_object_int_add(
7948 json,
7949 "updateDelayEstablishWait",
7950 bgp->v_establish_wait);
7951
7952 if (bgp_update_delay_active(bgp)) {
7953 json_object_string_add(
7954 json,
7955 "updateDelayFirstNeighbor",
7956 bgp->update_delay_begin_time);
7957 json_object_boolean_true_add(
7958 json,
7959 "updateDelayInProgress");
7960 } else {
7961 if (bgp->update_delay_over) {
7962 json_object_string_add(
7963 json,
7964 "updateDelayFirstNeighbor",
7965 bgp->update_delay_begin_time);
7966 json_object_string_add(
7967 json,
7968 "updateDelayBestpathResumed",
7969 bgp->update_delay_end_time);
7970 json_object_string_add(
7971 json,
7972 "updateDelayZebraUpdateResume",
7973 bgp->update_delay_zebra_resume_time);
7974 json_object_string_add(
7975 json,
7976 "updateDelayPeerUpdateResume",
7977 bgp->update_delay_peers_resume_time);
7978 }
7979 }
7980 } else {
7981 vty_out(vty,
7982 "Read-only mode update-delay limit: %d seconds\n",
7983 bgp->v_update_delay);
7984 if (bgp->v_update_delay
7985 != bgp->v_establish_wait)
7986 vty_out(vty,
7987 " Establish wait: %d seconds\n",
7988 bgp->v_establish_wait);
7989
7990 if (bgp_update_delay_active(bgp)) {
7991 vty_out(vty,
7992 " First neighbor established: %s\n",
7993 bgp->update_delay_begin_time);
7994 vty_out(vty,
7995 " Delay in progress\n");
7996 } else {
7997 if (bgp->update_delay_over) {
7998 vty_out(vty,
7999 " First neighbor established: %s\n",
8000 bgp->update_delay_begin_time);
8001 vty_out(vty,
8002 " Best-paths resumed: %s\n",
8003 bgp->update_delay_end_time);
8004 vty_out(vty,
8005 " zebra update resumed: %s\n",
8006 bgp->update_delay_zebra_resume_time);
8007 vty_out(vty,
8008 " peers update resumed: %s\n",
8009 bgp->update_delay_peers_resume_time);
8010 }
8011 }
8012 }
8013 }
8014
8015 if (use_json) {
8016 if (bgp_maxmed_onstartup_configured(bgp)
8017 && bgp->maxmed_active)
8018 json_object_boolean_true_add(
8019 json, "maxMedOnStartup");
8020 if (bgp->v_maxmed_admin)
8021 json_object_boolean_true_add(
8022 json, "maxMedAdministrative");
8023
8024 json_object_int_add(
8025 json, "tableVersion",
8026 bgp_table_version(bgp->rib[afi][safi]));
8027
8028 ents = bgp_table_count(bgp->rib[afi][safi]);
8029 json_object_int_add(json, "ribCount", ents);
8030 json_object_int_add(
8031 json, "ribMemory",
8032 ents * sizeof(struct bgp_node));
8033
8034 ents = bgp->af_peer_count[afi][safi];
8035 json_object_int_add(json, "peerCount", ents);
8036 json_object_int_add(json, "peerMemory",
8037 ents * sizeof(struct peer));
8038
8039 if ((ents = listcount(bgp->group))) {
8040 json_object_int_add(
8041 json, "peerGroupCount", ents);
8042 json_object_int_add(
8043 json, "peerGroupMemory",
8044 ents * sizeof(struct
8045 peer_group));
8046 }
8047
8048 if (CHECK_FLAG(bgp->af_flags[afi][safi],
8049 BGP_CONFIG_DAMPENING))
8050 json_object_boolean_true_add(
8051 json, "dampeningEnabled");
8052 } else {
8053 if (bgp_maxmed_onstartup_configured(bgp)
8054 && bgp->maxmed_active)
8055 vty_out(vty,
8056 "Max-med on-startup active\n");
8057 if (bgp->v_maxmed_admin)
8058 vty_out(vty,
8059 "Max-med administrative active\n");
8060
8061 vty_out(vty, "BGP table version %" PRIu64 "\n",
8062 bgp_table_version(bgp->rib[afi][safi]));
8063
8064 ents = bgp_table_count(bgp->rib[afi][safi]);
8065 vty_out(vty,
8066 "RIB entries %ld, using %s of memory\n",
8067 ents,
8068 mtype_memstr(memstrbuf,
8069 sizeof(memstrbuf),
8070 ents * sizeof(struct
8071 bgp_node)));
8072
8073 /* Peer related usage */
8074 ents = bgp->af_peer_count[afi][safi];
8075 vty_out(vty, "Peers %ld, using %s of memory\n",
8076 ents,
8077 mtype_memstr(
8078 memstrbuf, sizeof(memstrbuf),
8079 ents * sizeof(struct peer)));
8080
8081 if ((ents = listcount(bgp->group)))
8082 vty_out(vty,
8083 "Peer groups %ld, using %s of memory\n",
8084 ents,
8085 mtype_memstr(
8086 memstrbuf,
8087 sizeof(memstrbuf),
8088 ents * sizeof(struct
8089 peer_group)));
8090
8091 if (CHECK_FLAG(bgp->af_flags[afi][safi],
8092 BGP_CONFIG_DAMPENING))
8093 vty_out(vty, "Dampening enabled.\n");
8094 vty_out(vty, "\n");
8095
8096 /* Subtract 8 here because 'Neighbor' is
8097 * 8 characters */
8098 vty_out(vty, "Neighbor");
8099 vty_out(vty, "%*s", max_neighbor_width - 8,
8100 " ");
8101 vty_out(vty,
8102 "V AS MsgRcvd MsgSent TblVer InQ OutQ Up/Down State/PfxRcd\n");
8103 }
8104 }
8105
8106 count++;
8107
8108 if (use_json) {
8109 json_peer = json_object_new_object();
8110
8111 if (peer_dynamic_neighbor(peer)) {
8112 dn_count++;
8113 json_object_boolean_true_add(json_peer,
8114 "dynamicPeer");
8115 }
8116
8117 if (peer->hostname)
8118 json_object_string_add(json_peer, "hostname",
8119 peer->hostname);
8120
8121 if (peer->domainname)
8122 json_object_string_add(json_peer, "domainname",
8123 peer->domainname);
8124
8125 json_object_int_add(json_peer, "remoteAs", peer->as);
8126 json_object_int_add(json_peer, "version", 4);
8127 json_object_int_add(json_peer, "msgRcvd",
8128 PEER_TOTAL_RX(peer));
8129 json_object_int_add(json_peer, "msgSent",
8130 PEER_TOTAL_TX(peer));
8131
8132 json_object_int_add(json_peer, "tableVersion",
8133 peer->version[afi][safi]);
8134 json_object_int_add(json_peer, "outq",
8135 peer->obuf->count);
8136 json_object_int_add(json_peer, "inq", 0);
8137 peer_uptime(peer->uptime, timebuf, BGP_UPTIME_LEN,
8138 use_json, json_peer);
8139
8140 /*
8141 * Adding "pfxRcd" field to match with the corresponding
8142 * CLI. "prefixReceivedCount" will be deprecated in
8143 * future.
8144 */
8145 json_object_int_add(json_peer, "prefixReceivedCount",
8146 peer->pcount[afi][pfx_rcd_safi]);
8147 json_object_int_add(json_peer, "pfxRcd",
8148 peer->pcount[afi][pfx_rcd_safi]);
8149
8150 paf = peer_af_find(peer, afi, pfx_rcd_safi);
8151 if (paf && PAF_SUBGRP(paf))
8152 json_object_int_add(json_peer,
8153 "pfxSnt",
8154 (PAF_SUBGRP(paf))->scount);
8155
8156 if (CHECK_FLAG(peer->flags, PEER_FLAG_SHUTDOWN))
8157 json_object_string_add(json_peer, "state",
8158 "Idle (Admin)");
8159 else if (peer->afc_recv[afi][safi])
8160 json_object_string_add(
8161 json_peer, "state",
8162 lookup_msg(bgp_status_msg, peer->status,
8163 NULL));
8164 else if (CHECK_FLAG(peer->sflags,
8165 PEER_STATUS_PREFIX_OVERFLOW))
8166 json_object_string_add(json_peer, "state",
8167 "Idle (PfxCt)");
8168 else
8169 json_object_string_add(
8170 json_peer, "state",
8171 lookup_msg(bgp_status_msg, peer->status,
8172 NULL));
8173
8174 if (peer->conf_if)
8175 json_object_string_add(json_peer, "idType",
8176 "interface");
8177 else if (peer->su.sa.sa_family == AF_INET)
8178 json_object_string_add(json_peer, "idType",
8179 "ipv4");
8180 else if (peer->su.sa.sa_family == AF_INET6)
8181 json_object_string_add(json_peer, "idType",
8182 "ipv6");
8183
8184 json_object_object_add(json_peers, peer->host,
8185 json_peer);
8186 } else {
8187 memset(dn_flag, '\0', sizeof(dn_flag));
8188 if (peer_dynamic_neighbor(peer)) {
8189 dn_count++;
8190 dn_flag[0] = '*';
8191 }
8192
8193 if (peer->hostname
8194 && bgp_flag_check(bgp, BGP_FLAG_SHOW_HOSTNAME))
8195 len = vty_out(vty, "%s%s(%s)", dn_flag,
8196 peer->hostname, peer->host);
8197 else
8198 len = vty_out(vty, "%s%s", dn_flag, peer->host);
8199
8200 /* pad the neighbor column with spaces */
8201 if (len < max_neighbor_width)
8202 vty_out(vty, "%*s", max_neighbor_width - len,
8203 " ");
8204
8205 vty_out(vty, "4 %10u %7u %7u %8" PRIu64 " %4d %4zd %8s",
8206 peer->as, PEER_TOTAL_RX(peer),
8207 PEER_TOTAL_TX(peer), peer->version[afi][safi],
8208 0, peer->obuf->count,
8209 peer_uptime(peer->uptime, timebuf,
8210 BGP_UPTIME_LEN, 0, NULL));
8211
8212 if (peer->status == Established)
8213 if (peer->afc_recv[afi][safi])
8214 vty_out(vty, " %12ld",
8215 peer->pcount[afi]
8216 [pfx_rcd_safi]);
8217 else
8218 vty_out(vty, " NoNeg");
8219 else {
8220 if (CHECK_FLAG(peer->flags, PEER_FLAG_SHUTDOWN))
8221 vty_out(vty, " Idle (Admin)");
8222 else if (CHECK_FLAG(
8223 peer->sflags,
8224 PEER_STATUS_PREFIX_OVERFLOW))
8225 vty_out(vty, " Idle (PfxCt)");
8226 else
8227 vty_out(vty, " %12s",
8228 lookup_msg(bgp_status_msg,
8229 peer->status, NULL));
8230 }
8231 vty_out(vty, "\n");
8232 }
8233 }
8234
8235 if (use_json) {
8236 json_object_object_add(json, "peers", json_peers);
8237
8238 json_object_int_add(json, "totalPeers", count);
8239 json_object_int_add(json, "dynamicPeers", dn_count);
8240
8241 bgp_show_bestpath_json(bgp, json);
8242
8243 vty_out(vty, "%s\n", json_object_to_json_string_ext(
8244 json, JSON_C_TO_STRING_PRETTY));
8245 json_object_free(json);
8246 } else {
8247 if (count)
8248 vty_out(vty, "\nTotal number of neighbors %d\n", count);
8249 else {
8250 vty_out(vty, "No %s neighbor is configured\n",
8251 afi_safi_print(afi, safi));
8252 }
8253
8254 if (dn_count) {
8255 vty_out(vty, "* - dynamic neighbor\n");
8256 vty_out(vty, "%d dynamic neighbor(s), limit %d\n",
8257 dn_count, bgp->dynamic_neighbors_limit);
8258 }
8259 }
8260
8261 return CMD_SUCCESS;
8262 }
8263
8264 static void bgp_show_summary_afi_safi(struct vty *vty, struct bgp *bgp, int afi,
8265 int safi, bool use_json,
8266 json_object *json)
8267 {
8268 int is_first = 1;
8269 int afi_wildcard = (afi == AFI_MAX);
8270 int safi_wildcard = (safi == SAFI_MAX);
8271 int is_wildcard = (afi_wildcard || safi_wildcard);
8272 bool nbr_output = false;
8273
8274 if (use_json && is_wildcard)
8275 vty_out(vty, "{\n");
8276 if (afi_wildcard)
8277 afi = 1; /* AFI_IP */
8278 while (afi < AFI_MAX) {
8279 if (safi_wildcard)
8280 safi = 1; /* SAFI_UNICAST */
8281 while (safi < SAFI_MAX) {
8282 if (bgp_afi_safi_peer_exists(bgp, afi, safi)) {
8283 nbr_output = true;
8284 if (is_wildcard) {
8285 /*
8286 * So limit output to those afi/safi
8287 * pairs that
8288 * actualy have something interesting in
8289 * them
8290 */
8291 if (use_json) {
8292 json = json_object_new_object();
8293
8294 if (!is_first)
8295 vty_out(vty, ",\n");
8296 else
8297 is_first = 0;
8298
8299 vty_out(vty, "\"%s\":",
8300 afi_safi_json(afi,
8301 safi));
8302 } else {
8303 vty_out(vty, "\n%s Summary:\n",
8304 afi_safi_print(afi,
8305 safi));
8306 }
8307 }
8308 bgp_show_summary(vty, bgp, afi, safi, use_json,
8309 json);
8310 }
8311 safi++;
8312 if (!safi_wildcard)
8313 safi = SAFI_MAX;
8314 }
8315 afi++;
8316 if (!afi_wildcard)
8317 afi = AFI_MAX;
8318 }
8319
8320 if (use_json && is_wildcard)
8321 vty_out(vty, "}\n");
8322 else if (!nbr_output) {
8323 if (use_json)
8324 vty_out(vty, "{}\n");
8325 else
8326 vty_out(vty, "%% No BGP neighbors found\n");
8327 }
8328 }
8329
8330 static void bgp_show_all_instances_summary_vty(struct vty *vty, afi_t afi,
8331 safi_t safi, bool use_json)
8332 {
8333 struct listnode *node, *nnode;
8334 struct bgp *bgp;
8335 json_object *json = NULL;
8336 int is_first = 1;
8337 bool nbr_output = false;
8338
8339 if (use_json)
8340 vty_out(vty, "{\n");
8341
8342 for (ALL_LIST_ELEMENTS(bm->bgp, node, nnode, bgp)) {
8343 nbr_output = true;
8344 if (use_json) {
8345 json = json_object_new_object();
8346
8347 if (!is_first)
8348 vty_out(vty, ",\n");
8349 else
8350 is_first = 0;
8351
8352 vty_out(vty, "\"%s\":",
8353 (bgp->inst_type == BGP_INSTANCE_TYPE_DEFAULT)
8354 ? VRF_DEFAULT_NAME
8355 : bgp->name);
8356 } else {
8357 vty_out(vty, "\nInstance %s:\n",
8358 (bgp->inst_type == BGP_INSTANCE_TYPE_DEFAULT)
8359 ? VRF_DEFAULT_NAME
8360 : bgp->name);
8361 }
8362 bgp_show_summary_afi_safi(vty, bgp, afi, safi, use_json, json);
8363 }
8364
8365 if (use_json)
8366 vty_out(vty, "}\n");
8367 else if (!nbr_output)
8368 vty_out(vty, "%% BGP instance not found\n");
8369 }
8370
8371 int bgp_show_summary_vty(struct vty *vty, const char *name, afi_t afi,
8372 safi_t safi, bool use_json)
8373 {
8374 struct bgp *bgp;
8375
8376 if (name) {
8377 if (strmatch(name, "all")) {
8378 bgp_show_all_instances_summary_vty(vty, afi, safi,
8379 use_json);
8380 return CMD_SUCCESS;
8381 } else {
8382 bgp = bgp_lookup_by_name(name);
8383
8384 if (!bgp) {
8385 if (use_json)
8386 vty_out(vty, "{}\n");
8387 else
8388 vty_out(vty,
8389 "%% BGP instance not found\n");
8390 return CMD_WARNING;
8391 }
8392
8393 bgp_show_summary_afi_safi(vty, bgp, afi, safi, use_json,
8394 NULL);
8395 return CMD_SUCCESS;
8396 }
8397 }
8398
8399 bgp = bgp_get_default();
8400
8401 if (bgp)
8402 bgp_show_summary_afi_safi(vty, bgp, afi, safi, use_json, NULL);
8403 else {
8404 if (use_json)
8405 vty_out(vty, "{}\n");
8406 else
8407 vty_out(vty, "%% BGP instance not found\n");
8408 return CMD_WARNING;
8409 }
8410
8411 return CMD_SUCCESS;
8412 }
8413
8414 /* `show [ip] bgp summary' commands. */
8415 DEFUN (show_ip_bgp_summary,
8416 show_ip_bgp_summary_cmd,
8417 "show [ip] bgp [<view|vrf> VIEWVRFNAME] ["BGP_AFI_CMD_STR" ["BGP_SAFI_WITH_LABEL_CMD_STR"]] summary [json]",
8418 SHOW_STR
8419 IP_STR
8420 BGP_STR
8421 BGP_INSTANCE_HELP_STR
8422 BGP_AFI_HELP_STR
8423 BGP_SAFI_WITH_LABEL_HELP_STR
8424 "Summary of BGP neighbor status\n"
8425 JSON_STR)
8426 {
8427 char *vrf = NULL;
8428 afi_t afi = AFI_MAX;
8429 safi_t safi = SAFI_MAX;
8430
8431 int idx = 0;
8432
8433 /* show [ip] bgp */
8434 if (argv_find(argv, argc, "ip", &idx))
8435 afi = AFI_IP;
8436 /* [<vrf> VIEWVRFNAME] */
8437 if (argv_find(argv, argc, "vrf", &idx)) {
8438 vrf = argv[idx + 1]->arg;
8439 if (vrf && strmatch(vrf, VRF_DEFAULT_NAME))
8440 vrf = NULL;
8441 } else if (argv_find(argv, argc, "view", &idx))
8442 /* [<view> VIEWVRFNAME] */
8443 vrf = argv[idx + 1]->arg;
8444 /* ["BGP_AFI_CMD_STR" ["BGP_SAFI_CMD_STR"]] */
8445 if (argv_find_and_parse_afi(argv, argc, &idx, &afi)) {
8446 argv_find_and_parse_safi(argv, argc, &idx, &safi);
8447 }
8448
8449 bool uj = use_json(argc, argv);
8450
8451 return bgp_show_summary_vty(vty, vrf, afi, safi, uj);
8452 }
8453
8454 const char *afi_safi_print(afi_t afi, safi_t safi)
8455 {
8456 if (afi == AFI_IP && safi == SAFI_UNICAST)
8457 return "IPv4 Unicast";
8458 else if (afi == AFI_IP && safi == SAFI_MULTICAST)
8459 return "IPv4 Multicast";
8460 else if (afi == AFI_IP && safi == SAFI_LABELED_UNICAST)
8461 return "IPv4 Labeled Unicast";
8462 else if (afi == AFI_IP && safi == SAFI_MPLS_VPN)
8463 return "IPv4 VPN";
8464 else if (afi == AFI_IP && safi == SAFI_ENCAP)
8465 return "IPv4 Encap";
8466 else if (afi == AFI_IP && safi == SAFI_FLOWSPEC)
8467 return "IPv4 Flowspec";
8468 else if (afi == AFI_IP6 && safi == SAFI_UNICAST)
8469 return "IPv6 Unicast";
8470 else if (afi == AFI_IP6 && safi == SAFI_MULTICAST)
8471 return "IPv6 Multicast";
8472 else if (afi == AFI_IP6 && safi == SAFI_LABELED_UNICAST)
8473 return "IPv6 Labeled Unicast";
8474 else if (afi == AFI_IP6 && safi == SAFI_MPLS_VPN)
8475 return "IPv6 VPN";
8476 else if (afi == AFI_IP6 && safi == SAFI_ENCAP)
8477 return "IPv6 Encap";
8478 else if (afi == AFI_IP6 && safi == SAFI_FLOWSPEC)
8479 return "IPv6 Flowspec";
8480 else if (afi == AFI_L2VPN && safi == SAFI_EVPN)
8481 return "L2VPN EVPN";
8482 else
8483 return "Unknown";
8484 }
8485
8486 /*
8487 * Please note that we have intentionally camelCased
8488 * the return strings here. So if you want
8489 * to use this function, please ensure you
8490 * are doing this within json output
8491 */
8492 const char *afi_safi_json(afi_t afi, safi_t safi)
8493 {
8494 if (afi == AFI_IP && safi == SAFI_UNICAST)
8495 return "ipv4Unicast";
8496 else if (afi == AFI_IP && safi == SAFI_MULTICAST)
8497 return "ipv4Multicast";
8498 else if (afi == AFI_IP && safi == SAFI_LABELED_UNICAST)
8499 return "ipv4LabeledUnicast";
8500 else if (afi == AFI_IP && safi == SAFI_MPLS_VPN)
8501 return "ipv4Vpn";
8502 else if (afi == AFI_IP && safi == SAFI_ENCAP)
8503 return "ipv4Encap";
8504 else if (afi == AFI_IP && safi == SAFI_FLOWSPEC)
8505 return "ipv4Flowspec";
8506 else if (afi == AFI_IP6 && safi == SAFI_UNICAST)
8507 return "ipv6Unicast";
8508 else if (afi == AFI_IP6 && safi == SAFI_MULTICAST)
8509 return "ipv6Multicast";
8510 else if (afi == AFI_IP6 && safi == SAFI_LABELED_UNICAST)
8511 return "ipv6LabeledUnicast";
8512 else if (afi == AFI_IP6 && safi == SAFI_MPLS_VPN)
8513 return "ipv6Vpn";
8514 else if (afi == AFI_IP6 && safi == SAFI_ENCAP)
8515 return "ipv6Encap";
8516 else if (afi == AFI_IP6 && safi == SAFI_FLOWSPEC)
8517 return "ipv6Flowspec";
8518 else if (afi == AFI_L2VPN && safi == SAFI_EVPN)
8519 return "l2VpnEvpn";
8520 else
8521 return "Unknown";
8522 }
8523
8524 /* Show BGP peer's information. */
8525 enum show_type { show_all, show_peer, show_ipv4_all, show_ipv6_all, show_ipv4_peer, show_ipv6_peer };
8526
8527 static void bgp_show_peer_afi_orf_cap(struct vty *vty, struct peer *p,
8528 afi_t afi, safi_t safi,
8529 uint16_t adv_smcap, uint16_t adv_rmcap,
8530 uint16_t rcv_smcap, uint16_t rcv_rmcap,
8531 bool use_json, json_object *json_pref)
8532 {
8533 /* Send-Mode */
8534 if (CHECK_FLAG(p->af_cap[afi][safi], adv_smcap)
8535 || CHECK_FLAG(p->af_cap[afi][safi], rcv_smcap)) {
8536 if (use_json) {
8537 if (CHECK_FLAG(p->af_cap[afi][safi], adv_smcap)
8538 && CHECK_FLAG(p->af_cap[afi][safi], rcv_smcap))
8539 json_object_string_add(json_pref, "sendMode",
8540 "advertisedAndReceived");
8541 else if (CHECK_FLAG(p->af_cap[afi][safi], adv_smcap))
8542 json_object_string_add(json_pref, "sendMode",
8543 "advertised");
8544 else if (CHECK_FLAG(p->af_cap[afi][safi], rcv_smcap))
8545 json_object_string_add(json_pref, "sendMode",
8546 "received");
8547 } else {
8548 vty_out(vty, " Send-mode: ");
8549 if (CHECK_FLAG(p->af_cap[afi][safi], adv_smcap))
8550 vty_out(vty, "advertised");
8551 if (CHECK_FLAG(p->af_cap[afi][safi], rcv_smcap))
8552 vty_out(vty, "%sreceived",
8553 CHECK_FLAG(p->af_cap[afi][safi],
8554 adv_smcap)
8555 ? ", "
8556 : "");
8557 vty_out(vty, "\n");
8558 }
8559 }
8560
8561 /* Receive-Mode */
8562 if (CHECK_FLAG(p->af_cap[afi][safi], adv_rmcap)
8563 || CHECK_FLAG(p->af_cap[afi][safi], rcv_rmcap)) {
8564 if (use_json) {
8565 if (CHECK_FLAG(p->af_cap[afi][safi], adv_rmcap)
8566 && CHECK_FLAG(p->af_cap[afi][safi], rcv_rmcap))
8567 json_object_string_add(json_pref, "recvMode",
8568 "advertisedAndReceived");
8569 else if (CHECK_FLAG(p->af_cap[afi][safi], adv_rmcap))
8570 json_object_string_add(json_pref, "recvMode",
8571 "advertised");
8572 else if (CHECK_FLAG(p->af_cap[afi][safi], rcv_rmcap))
8573 json_object_string_add(json_pref, "recvMode",
8574 "received");
8575 } else {
8576 vty_out(vty, " Receive-mode: ");
8577 if (CHECK_FLAG(p->af_cap[afi][safi], adv_rmcap))
8578 vty_out(vty, "advertised");
8579 if (CHECK_FLAG(p->af_cap[afi][safi], rcv_rmcap))
8580 vty_out(vty, "%sreceived",
8581 CHECK_FLAG(p->af_cap[afi][safi],
8582 adv_rmcap)
8583 ? ", "
8584 : "");
8585 vty_out(vty, "\n");
8586 }
8587 }
8588 }
8589
8590 static void bgp_show_peer_afi(struct vty *vty, struct peer *p, afi_t afi,
8591 safi_t safi, bool use_json,
8592 json_object *json_neigh)
8593 {
8594 struct bgp_filter *filter;
8595 struct peer_af *paf;
8596 char orf_pfx_name[BUFSIZ];
8597 int orf_pfx_count;
8598 json_object *json_af = NULL;
8599 json_object *json_prefA = NULL;
8600 json_object *json_prefB = NULL;
8601 json_object *json_addr = NULL;
8602
8603 if (use_json) {
8604 json_addr = json_object_new_object();
8605 json_af = json_object_new_object();
8606 filter = &p->filter[afi][safi];
8607
8608 if (peer_group_active(p))
8609 json_object_string_add(json_addr, "peerGroupMember",
8610 p->group->name);
8611
8612 paf = peer_af_find(p, afi, safi);
8613 if (paf && PAF_SUBGRP(paf)) {
8614 json_object_int_add(json_addr, "updateGroupId",
8615 PAF_UPDGRP(paf)->id);
8616 json_object_int_add(json_addr, "subGroupId",
8617 PAF_SUBGRP(paf)->id);
8618 json_object_int_add(json_addr, "packetQueueLength",
8619 bpacket_queue_virtual_length(paf));
8620 }
8621
8622 if (CHECK_FLAG(p->af_cap[afi][safi], PEER_CAP_ORF_PREFIX_SM_ADV)
8623 || CHECK_FLAG(p->af_cap[afi][safi],
8624 PEER_CAP_ORF_PREFIX_SM_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 json_object_int_add(json_af, "orfType",
8630 ORF_TYPE_PREFIX);
8631 json_prefA = json_object_new_object();
8632 bgp_show_peer_afi_orf_cap(vty, p, afi, safi,
8633 PEER_CAP_ORF_PREFIX_SM_ADV,
8634 PEER_CAP_ORF_PREFIX_RM_ADV,
8635 PEER_CAP_ORF_PREFIX_SM_RCV,
8636 PEER_CAP_ORF_PREFIX_RM_RCV,
8637 use_json, json_prefA);
8638 json_object_object_add(json_af, "orfPrefixList",
8639 json_prefA);
8640 }
8641
8642 if (CHECK_FLAG(p->af_cap[afi][safi], PEER_CAP_ORF_PREFIX_SM_ADV)
8643 || CHECK_FLAG(p->af_cap[afi][safi],
8644 PEER_CAP_ORF_PREFIX_SM_OLD_RCV)
8645 || CHECK_FLAG(p->af_cap[afi][safi],
8646 PEER_CAP_ORF_PREFIX_RM_ADV)
8647 || CHECK_FLAG(p->af_cap[afi][safi],
8648 PEER_CAP_ORF_PREFIX_RM_OLD_RCV)) {
8649 json_object_int_add(json_af, "orfOldType",
8650 ORF_TYPE_PREFIX_OLD);
8651 json_prefB = json_object_new_object();
8652 bgp_show_peer_afi_orf_cap(
8653 vty, p, afi, safi, PEER_CAP_ORF_PREFIX_SM_ADV,
8654 PEER_CAP_ORF_PREFIX_RM_ADV,
8655 PEER_CAP_ORF_PREFIX_SM_OLD_RCV,
8656 PEER_CAP_ORF_PREFIX_RM_OLD_RCV, use_json,
8657 json_prefB);
8658 json_object_object_add(json_af, "orfOldPrefixList",
8659 json_prefB);
8660 }
8661
8662 if (CHECK_FLAG(p->af_cap[afi][safi], PEER_CAP_ORF_PREFIX_SM_ADV)
8663 || CHECK_FLAG(p->af_cap[afi][safi],
8664 PEER_CAP_ORF_PREFIX_SM_RCV)
8665 || CHECK_FLAG(p->af_cap[afi][safi],
8666 PEER_CAP_ORF_PREFIX_SM_OLD_RCV)
8667 || CHECK_FLAG(p->af_cap[afi][safi],
8668 PEER_CAP_ORF_PREFIX_RM_ADV)
8669 || CHECK_FLAG(p->af_cap[afi][safi],
8670 PEER_CAP_ORF_PREFIX_RM_RCV)
8671 || CHECK_FLAG(p->af_cap[afi][safi],
8672 PEER_CAP_ORF_PREFIX_RM_OLD_RCV))
8673 json_object_object_add(json_addr, "afDependentCap",
8674 json_af);
8675 else
8676 json_object_free(json_af);
8677
8678 sprintf(orf_pfx_name, "%s.%d.%d", p->host, afi, safi);
8679 orf_pfx_count = prefix_bgp_show_prefix_list(
8680 NULL, afi, orf_pfx_name, use_json);
8681
8682 if (CHECK_FLAG(p->af_sflags[afi][safi],
8683 PEER_STATUS_ORF_PREFIX_SEND)
8684 || orf_pfx_count) {
8685 if (CHECK_FLAG(p->af_sflags[afi][safi],
8686 PEER_STATUS_ORF_PREFIX_SEND))
8687 json_object_boolean_true_add(json_neigh,
8688 "orfSent");
8689 if (orf_pfx_count)
8690 json_object_int_add(json_addr, "orfRecvCounter",
8691 orf_pfx_count);
8692 }
8693 if (CHECK_FLAG(p->af_sflags[afi][safi],
8694 PEER_STATUS_ORF_WAIT_REFRESH))
8695 json_object_string_add(
8696 json_addr, "orfFirstUpdate",
8697 "deferredUntilORFOrRouteRefreshRecvd");
8698
8699 if (CHECK_FLAG(p->af_flags[afi][safi],
8700 PEER_FLAG_REFLECTOR_CLIENT))
8701 json_object_boolean_true_add(json_addr,
8702 "routeReflectorClient");
8703 if (CHECK_FLAG(p->af_flags[afi][safi],
8704 PEER_FLAG_RSERVER_CLIENT))
8705 json_object_boolean_true_add(json_addr,
8706 "routeServerClient");
8707 if (CHECK_FLAG(p->af_flags[afi][safi], PEER_FLAG_SOFT_RECONFIG))
8708 json_object_boolean_true_add(json_addr,
8709 "inboundSoftConfigPermit");
8710
8711 if (CHECK_FLAG(p->af_flags[afi][safi],
8712 PEER_FLAG_REMOVE_PRIVATE_AS_ALL_REPLACE))
8713 json_object_boolean_true_add(
8714 json_addr,
8715 "privateAsNumsAllReplacedInUpdatesToNbr");
8716 else if (CHECK_FLAG(p->af_flags[afi][safi],
8717 PEER_FLAG_REMOVE_PRIVATE_AS_REPLACE))
8718 json_object_boolean_true_add(
8719 json_addr,
8720 "privateAsNumsReplacedInUpdatesToNbr");
8721 else if (CHECK_FLAG(p->af_flags[afi][safi],
8722 PEER_FLAG_REMOVE_PRIVATE_AS_ALL))
8723 json_object_boolean_true_add(
8724 json_addr,
8725 "privateAsNumsAllRemovedInUpdatesToNbr");
8726 else if (CHECK_FLAG(p->af_flags[afi][safi],
8727 PEER_FLAG_REMOVE_PRIVATE_AS))
8728 json_object_boolean_true_add(
8729 json_addr,
8730 "privateAsNumsRemovedInUpdatesToNbr");
8731
8732 if (p->addpath_type[afi][safi] != BGP_ADDPATH_NONE)
8733 json_object_boolean_true_add(
8734 json_addr,
8735 bgp_addpath_names(p->addpath_type[afi][safi])
8736 ->type_json_name);
8737
8738 if (CHECK_FLAG(p->af_flags[afi][safi], PEER_FLAG_AS_OVERRIDE))
8739 json_object_string_add(json_addr,
8740 "overrideASNsInOutboundUpdates",
8741 "ifAspathEqualRemoteAs");
8742
8743 if (CHECK_FLAG(p->af_flags[afi][safi], PEER_FLAG_NEXTHOP_SELF)
8744 || CHECK_FLAG(p->af_flags[afi][safi],
8745 PEER_FLAG_FORCE_NEXTHOP_SELF))
8746 json_object_boolean_true_add(json_addr,
8747 "routerAlwaysNextHop");
8748 if (CHECK_FLAG(p->af_flags[afi][safi],
8749 PEER_FLAG_AS_PATH_UNCHANGED))
8750 json_object_boolean_true_add(
8751 json_addr, "unchangedAsPathPropogatedToNbr");
8752 if (CHECK_FLAG(p->af_flags[afi][safi],
8753 PEER_FLAG_NEXTHOP_UNCHANGED))
8754 json_object_boolean_true_add(
8755 json_addr, "unchangedNextHopPropogatedToNbr");
8756 if (CHECK_FLAG(p->af_flags[afi][safi], PEER_FLAG_MED_UNCHANGED))
8757 json_object_boolean_true_add(
8758 json_addr, "unchangedMedPropogatedToNbr");
8759 if (CHECK_FLAG(p->af_flags[afi][safi], PEER_FLAG_SEND_COMMUNITY)
8760 || CHECK_FLAG(p->af_flags[afi][safi],
8761 PEER_FLAG_SEND_EXT_COMMUNITY)) {
8762 if (CHECK_FLAG(p->af_flags[afi][safi],
8763 PEER_FLAG_SEND_COMMUNITY)
8764 && CHECK_FLAG(p->af_flags[afi][safi],
8765 PEER_FLAG_SEND_EXT_COMMUNITY))
8766 json_object_string_add(json_addr,
8767 "commAttriSentToNbr",
8768 "extendedAndStandard");
8769 else if (CHECK_FLAG(p->af_flags[afi][safi],
8770 PEER_FLAG_SEND_EXT_COMMUNITY))
8771 json_object_string_add(json_addr,
8772 "commAttriSentToNbr",
8773 "extended");
8774 else
8775 json_object_string_add(json_addr,
8776 "commAttriSentToNbr",
8777 "standard");
8778 }
8779 if (CHECK_FLAG(p->af_flags[afi][safi],
8780 PEER_FLAG_DEFAULT_ORIGINATE)) {
8781 if (p->default_rmap[afi][safi].name)
8782 json_object_string_add(
8783 json_addr, "defaultRouteMap",
8784 p->default_rmap[afi][safi].name);
8785
8786 if (paf && PAF_SUBGRP(paf)
8787 && CHECK_FLAG(PAF_SUBGRP(paf)->sflags,
8788 SUBGRP_STATUS_DEFAULT_ORIGINATE))
8789 json_object_boolean_true_add(json_addr,
8790 "defaultSent");
8791 else
8792 json_object_boolean_true_add(json_addr,
8793 "defaultNotSent");
8794 }
8795
8796 if (afi == AFI_L2VPN && safi == SAFI_EVPN) {
8797 if (is_evpn_enabled())
8798 json_object_boolean_true_add(
8799 json_addr, "advertiseAllVnis");
8800 }
8801
8802 if (filter->plist[FILTER_IN].name
8803 || filter->dlist[FILTER_IN].name
8804 || filter->aslist[FILTER_IN].name
8805 || filter->map[RMAP_IN].name)
8806 json_object_boolean_true_add(json_addr,
8807 "inboundPathPolicyConfig");
8808 if (filter->plist[FILTER_OUT].name
8809 || filter->dlist[FILTER_OUT].name
8810 || filter->aslist[FILTER_OUT].name
8811 || filter->map[RMAP_OUT].name || filter->usmap.name)
8812 json_object_boolean_true_add(
8813 json_addr, "outboundPathPolicyConfig");
8814
8815 /* prefix-list */
8816 if (filter->plist[FILTER_IN].name)
8817 json_object_string_add(json_addr,
8818 "incomingUpdatePrefixFilterList",
8819 filter->plist[FILTER_IN].name);
8820 if (filter->plist[FILTER_OUT].name)
8821 json_object_string_add(json_addr,
8822 "outgoingUpdatePrefixFilterList",
8823 filter->plist[FILTER_OUT].name);
8824
8825 /* distribute-list */
8826 if (filter->dlist[FILTER_IN].name)
8827 json_object_string_add(
8828 json_addr, "incomingUpdateNetworkFilterList",
8829 filter->dlist[FILTER_IN].name);
8830 if (filter->dlist[FILTER_OUT].name)
8831 json_object_string_add(
8832 json_addr, "outgoingUpdateNetworkFilterList",
8833 filter->dlist[FILTER_OUT].name);
8834
8835 /* filter-list. */
8836 if (filter->aslist[FILTER_IN].name)
8837 json_object_string_add(json_addr,
8838 "incomingUpdateAsPathFilterList",
8839 filter->aslist[FILTER_IN].name);
8840 if (filter->aslist[FILTER_OUT].name)
8841 json_object_string_add(json_addr,
8842 "outgoingUpdateAsPathFilterList",
8843 filter->aslist[FILTER_OUT].name);
8844
8845 /* route-map. */
8846 if (filter->map[RMAP_IN].name)
8847 json_object_string_add(
8848 json_addr, "routeMapForIncomingAdvertisements",
8849 filter->map[RMAP_IN].name);
8850 if (filter->map[RMAP_OUT].name)
8851 json_object_string_add(
8852 json_addr, "routeMapForOutgoingAdvertisements",
8853 filter->map[RMAP_OUT].name);
8854
8855 /* ebgp-requires-policy (inbound) */
8856 if (p->bgp->ebgp_requires_policy == DEFAULT_EBGP_POLICY_ENABLED
8857 && !bgp_inbound_policy_exists(p, filter))
8858 json_object_string_add(
8859 json_addr, "inboundEbgpRequiresPolicy",
8860 "Inbound updates discarded due to missing policy");
8861
8862 /* ebgp-requires-policy (outbound) */
8863 if (p->bgp->ebgp_requires_policy == DEFAULT_EBGP_POLICY_ENABLED
8864 && (!bgp_outbound_policy_exists(p, filter)))
8865 json_object_string_add(
8866 json_addr, "outboundEbgpRequiresPolicy",
8867 "Outbound updates discarded due to missing policy");
8868
8869 /* unsuppress-map */
8870 if (filter->usmap.name)
8871 json_object_string_add(json_addr,
8872 "selectiveUnsuppressRouteMap",
8873 filter->usmap.name);
8874
8875 /* Receive prefix count */
8876 json_object_int_add(json_addr, "acceptedPrefixCounter",
8877 p->pcount[afi][safi]);
8878 if (paf && PAF_SUBGRP(paf))
8879 json_object_int_add(json_addr, "sentPrefixCounter",
8880 (PAF_SUBGRP(paf))->scount);
8881
8882 /* Maximum prefix */
8883 if (CHECK_FLAG(p->af_flags[afi][safi], PEER_FLAG_MAX_PREFIX)) {
8884 json_object_int_add(json_addr, "prefixAllowedMax",
8885 p->pmax[afi][safi]);
8886 if (CHECK_FLAG(p->af_flags[afi][safi],
8887 PEER_FLAG_MAX_PREFIX_WARNING))
8888 json_object_boolean_true_add(
8889 json_addr, "prefixAllowedMaxWarning");
8890 json_object_int_add(json_addr,
8891 "prefixAllowedWarningThresh",
8892 p->pmax_threshold[afi][safi]);
8893 if (p->pmax_restart[afi][safi])
8894 json_object_int_add(
8895 json_addr,
8896 "prefixAllowedRestartIntervalMsecs",
8897 p->pmax_restart[afi][safi] * 60000);
8898 }
8899 json_object_object_add(json_neigh, afi_safi_print(afi, safi),
8900 json_addr);
8901
8902 } else {
8903 filter = &p->filter[afi][safi];
8904
8905 vty_out(vty, " For address family: %s\n",
8906 afi_safi_print(afi, safi));
8907
8908 if (peer_group_active(p))
8909 vty_out(vty, " %s peer-group member\n",
8910 p->group->name);
8911
8912 paf = peer_af_find(p, afi, safi);
8913 if (paf && PAF_SUBGRP(paf)) {
8914 vty_out(vty, " Update group %" PRIu64
8915 ", subgroup %" PRIu64 "\n",
8916 PAF_UPDGRP(paf)->id, PAF_SUBGRP(paf)->id);
8917 vty_out(vty, " Packet Queue length %d\n",
8918 bpacket_queue_virtual_length(paf));
8919 } else {
8920 vty_out(vty, " Not part of any update group\n");
8921 }
8922 if (CHECK_FLAG(p->af_cap[afi][safi], PEER_CAP_ORF_PREFIX_SM_ADV)
8923 || CHECK_FLAG(p->af_cap[afi][safi],
8924 PEER_CAP_ORF_PREFIX_SM_RCV)
8925 || CHECK_FLAG(p->af_cap[afi][safi],
8926 PEER_CAP_ORF_PREFIX_SM_OLD_RCV)
8927 || CHECK_FLAG(p->af_cap[afi][safi],
8928 PEER_CAP_ORF_PREFIX_RM_ADV)
8929 || CHECK_FLAG(p->af_cap[afi][safi],
8930 PEER_CAP_ORF_PREFIX_RM_RCV)
8931 || CHECK_FLAG(p->af_cap[afi][safi],
8932 PEER_CAP_ORF_PREFIX_RM_OLD_RCV))
8933 vty_out(vty, " AF-dependant capabilities:\n");
8934
8935 if (CHECK_FLAG(p->af_cap[afi][safi], PEER_CAP_ORF_PREFIX_SM_ADV)
8936 || CHECK_FLAG(p->af_cap[afi][safi],
8937 PEER_CAP_ORF_PREFIX_SM_RCV)
8938 || CHECK_FLAG(p->af_cap[afi][safi],
8939 PEER_CAP_ORF_PREFIX_RM_ADV)
8940 || CHECK_FLAG(p->af_cap[afi][safi],
8941 PEER_CAP_ORF_PREFIX_RM_RCV)) {
8942 vty_out(vty,
8943 " Outbound Route Filter (ORF) type (%d) Prefix-list:\n",
8944 ORF_TYPE_PREFIX);
8945 bgp_show_peer_afi_orf_cap(
8946 vty, p, afi, safi, PEER_CAP_ORF_PREFIX_SM_ADV,
8947 PEER_CAP_ORF_PREFIX_RM_ADV,
8948 PEER_CAP_ORF_PREFIX_SM_RCV,
8949 PEER_CAP_ORF_PREFIX_RM_RCV, use_json, NULL);
8950 }
8951 if (CHECK_FLAG(p->af_cap[afi][safi], PEER_CAP_ORF_PREFIX_SM_ADV)
8952 || CHECK_FLAG(p->af_cap[afi][safi],
8953 PEER_CAP_ORF_PREFIX_SM_OLD_RCV)
8954 || CHECK_FLAG(p->af_cap[afi][safi],
8955 PEER_CAP_ORF_PREFIX_RM_ADV)
8956 || CHECK_FLAG(p->af_cap[afi][safi],
8957 PEER_CAP_ORF_PREFIX_RM_OLD_RCV)) {
8958 vty_out(vty,
8959 " Outbound Route Filter (ORF) type (%d) Prefix-list:\n",
8960 ORF_TYPE_PREFIX_OLD);
8961 bgp_show_peer_afi_orf_cap(
8962 vty, p, afi, safi, PEER_CAP_ORF_PREFIX_SM_ADV,
8963 PEER_CAP_ORF_PREFIX_RM_ADV,
8964 PEER_CAP_ORF_PREFIX_SM_OLD_RCV,
8965 PEER_CAP_ORF_PREFIX_RM_OLD_RCV, use_json, NULL);
8966 }
8967
8968 sprintf(orf_pfx_name, "%s.%d.%d", p->host, afi, safi);
8969 orf_pfx_count = prefix_bgp_show_prefix_list(
8970 NULL, afi, orf_pfx_name, use_json);
8971
8972 if (CHECK_FLAG(p->af_sflags[afi][safi],
8973 PEER_STATUS_ORF_PREFIX_SEND)
8974 || orf_pfx_count) {
8975 vty_out(vty, " Outbound Route Filter (ORF):");
8976 if (CHECK_FLAG(p->af_sflags[afi][safi],
8977 PEER_STATUS_ORF_PREFIX_SEND))
8978 vty_out(vty, " sent;");
8979 if (orf_pfx_count)
8980 vty_out(vty, " received (%d entries)",
8981 orf_pfx_count);
8982 vty_out(vty, "\n");
8983 }
8984 if (CHECK_FLAG(p->af_sflags[afi][safi],
8985 PEER_STATUS_ORF_WAIT_REFRESH))
8986 vty_out(vty,
8987 " First update is deferred until ORF or ROUTE-REFRESH is received\n");
8988
8989 if (CHECK_FLAG(p->af_flags[afi][safi],
8990 PEER_FLAG_REFLECTOR_CLIENT))
8991 vty_out(vty, " Route-Reflector Client\n");
8992 if (CHECK_FLAG(p->af_flags[afi][safi],
8993 PEER_FLAG_RSERVER_CLIENT))
8994 vty_out(vty, " Route-Server Client\n");
8995 if (CHECK_FLAG(p->af_flags[afi][safi], PEER_FLAG_SOFT_RECONFIG))
8996 vty_out(vty,
8997 " Inbound soft reconfiguration allowed\n");
8998
8999 if (CHECK_FLAG(p->af_flags[afi][safi],
9000 PEER_FLAG_REMOVE_PRIVATE_AS_ALL_REPLACE))
9001 vty_out(vty,
9002 " Private AS numbers (all) replaced in updates to this neighbor\n");
9003 else if (CHECK_FLAG(p->af_flags[afi][safi],
9004 PEER_FLAG_REMOVE_PRIVATE_AS_REPLACE))
9005 vty_out(vty,
9006 " Private AS numbers replaced in updates to this neighbor\n");
9007 else if (CHECK_FLAG(p->af_flags[afi][safi],
9008 PEER_FLAG_REMOVE_PRIVATE_AS_ALL))
9009 vty_out(vty,
9010 " Private AS numbers (all) removed in updates to this neighbor\n");
9011 else if (CHECK_FLAG(p->af_flags[afi][safi],
9012 PEER_FLAG_REMOVE_PRIVATE_AS))
9013 vty_out(vty,
9014 " Private AS numbers removed in updates to this neighbor\n");
9015
9016 if (p->addpath_type[afi][safi] != BGP_ADDPATH_NONE)
9017 vty_out(vty, " %s\n",
9018 bgp_addpath_names(p->addpath_type[afi][safi])
9019 ->human_description);
9020
9021 if (CHECK_FLAG(p->af_flags[afi][safi], PEER_FLAG_AS_OVERRIDE))
9022 vty_out(vty,
9023 " Override ASNs in outbound updates if aspath equals remote-as\n");
9024
9025 if (CHECK_FLAG(p->af_flags[afi][safi], PEER_FLAG_NEXTHOP_SELF)
9026 || CHECK_FLAG(p->af_flags[afi][safi],
9027 PEER_FLAG_FORCE_NEXTHOP_SELF))
9028 vty_out(vty, " NEXT_HOP is always this router\n");
9029 if (CHECK_FLAG(p->af_flags[afi][safi],
9030 PEER_FLAG_AS_PATH_UNCHANGED))
9031 vty_out(vty,
9032 " AS_PATH is propagated unchanged to this neighbor\n");
9033 if (CHECK_FLAG(p->af_flags[afi][safi],
9034 PEER_FLAG_NEXTHOP_UNCHANGED))
9035 vty_out(vty,
9036 " NEXT_HOP is propagated unchanged to this neighbor\n");
9037 if (CHECK_FLAG(p->af_flags[afi][safi], PEER_FLAG_MED_UNCHANGED))
9038 vty_out(vty,
9039 " MED is propagated unchanged to this neighbor\n");
9040 if (CHECK_FLAG(p->af_flags[afi][safi], PEER_FLAG_SEND_COMMUNITY)
9041 || CHECK_FLAG(p->af_flags[afi][safi],
9042 PEER_FLAG_SEND_EXT_COMMUNITY)
9043 || CHECK_FLAG(p->af_flags[afi][safi],
9044 PEER_FLAG_SEND_LARGE_COMMUNITY)) {
9045 vty_out(vty,
9046 " Community attribute sent to this neighbor");
9047 if (CHECK_FLAG(p->af_flags[afi][safi],
9048 PEER_FLAG_SEND_COMMUNITY)
9049 && CHECK_FLAG(p->af_flags[afi][safi],
9050 PEER_FLAG_SEND_EXT_COMMUNITY)
9051 && CHECK_FLAG(p->af_flags[afi][safi],
9052 PEER_FLAG_SEND_LARGE_COMMUNITY))
9053 vty_out(vty, "(all)\n");
9054 else if (CHECK_FLAG(p->af_flags[afi][safi],
9055 PEER_FLAG_SEND_LARGE_COMMUNITY))
9056 vty_out(vty, "(large)\n");
9057 else if (CHECK_FLAG(p->af_flags[afi][safi],
9058 PEER_FLAG_SEND_EXT_COMMUNITY))
9059 vty_out(vty, "(extended)\n");
9060 else
9061 vty_out(vty, "(standard)\n");
9062 }
9063 if (CHECK_FLAG(p->af_flags[afi][safi],
9064 PEER_FLAG_DEFAULT_ORIGINATE)) {
9065 vty_out(vty, " Default information originate,");
9066
9067 if (p->default_rmap[afi][safi].name)
9068 vty_out(vty, " default route-map %s%s,",
9069 p->default_rmap[afi][safi].map ? "*"
9070 : "",
9071 p->default_rmap[afi][safi].name);
9072 if (paf && PAF_SUBGRP(paf)
9073 && CHECK_FLAG(PAF_SUBGRP(paf)->sflags,
9074 SUBGRP_STATUS_DEFAULT_ORIGINATE))
9075 vty_out(vty, " default sent\n");
9076 else
9077 vty_out(vty, " default not sent\n");
9078 }
9079
9080 /* advertise-vni-all */
9081 if (afi == AFI_L2VPN && safi == SAFI_EVPN) {
9082 if (is_evpn_enabled())
9083 vty_out(vty, " advertise-all-vni\n");
9084 }
9085
9086 if (filter->plist[FILTER_IN].name
9087 || filter->dlist[FILTER_IN].name
9088 || filter->aslist[FILTER_IN].name
9089 || filter->map[RMAP_IN].name)
9090 vty_out(vty, " Inbound path policy configured\n");
9091 if (filter->plist[FILTER_OUT].name
9092 || filter->dlist[FILTER_OUT].name
9093 || filter->aslist[FILTER_OUT].name
9094 || filter->map[RMAP_OUT].name || filter->usmap.name)
9095 vty_out(vty, " Outbound path policy configured\n");
9096
9097 /* prefix-list */
9098 if (filter->plist[FILTER_IN].name)
9099 vty_out(vty,
9100 " Incoming update prefix filter list is %s%s\n",
9101 filter->plist[FILTER_IN].plist ? "*" : "",
9102 filter->plist[FILTER_IN].name);
9103 if (filter->plist[FILTER_OUT].name)
9104 vty_out(vty,
9105 " Outgoing update prefix filter list is %s%s\n",
9106 filter->plist[FILTER_OUT].plist ? "*" : "",
9107 filter->plist[FILTER_OUT].name);
9108
9109 /* distribute-list */
9110 if (filter->dlist[FILTER_IN].name)
9111 vty_out(vty,
9112 " Incoming update network filter list is %s%s\n",
9113 filter->dlist[FILTER_IN].alist ? "*" : "",
9114 filter->dlist[FILTER_IN].name);
9115 if (filter->dlist[FILTER_OUT].name)
9116 vty_out(vty,
9117 " Outgoing update network filter list is %s%s\n",
9118 filter->dlist[FILTER_OUT].alist ? "*" : "",
9119 filter->dlist[FILTER_OUT].name);
9120
9121 /* filter-list. */
9122 if (filter->aslist[FILTER_IN].name)
9123 vty_out(vty,
9124 " Incoming update AS path filter list is %s%s\n",
9125 filter->aslist[FILTER_IN].aslist ? "*" : "",
9126 filter->aslist[FILTER_IN].name);
9127 if (filter->aslist[FILTER_OUT].name)
9128 vty_out(vty,
9129 " Outgoing update AS path filter list is %s%s\n",
9130 filter->aslist[FILTER_OUT].aslist ? "*" : "",
9131 filter->aslist[FILTER_OUT].name);
9132
9133 /* route-map. */
9134 if (filter->map[RMAP_IN].name)
9135 vty_out(vty,
9136 " Route map for incoming advertisements is %s%s\n",
9137 filter->map[RMAP_IN].map ? "*" : "",
9138 filter->map[RMAP_IN].name);
9139 if (filter->map[RMAP_OUT].name)
9140 vty_out(vty,
9141 " Route map for outgoing advertisements is %s%s\n",
9142 filter->map[RMAP_OUT].map ? "*" : "",
9143 filter->map[RMAP_OUT].name);
9144
9145 /* ebgp-requires-policy (inbound) */
9146 if (p->bgp->ebgp_requires_policy == DEFAULT_EBGP_POLICY_ENABLED
9147 && !bgp_inbound_policy_exists(p, filter))
9148 vty_out(vty,
9149 " Inbound updates discarded due to missing policy\n");
9150
9151 /* ebgp-requires-policy (outbound) */
9152 if (p->bgp->ebgp_requires_policy == DEFAULT_EBGP_POLICY_ENABLED
9153 && !bgp_outbound_policy_exists(p, filter))
9154 vty_out(vty,
9155 " Outbound updates discarded due to missing policy\n");
9156
9157 /* unsuppress-map */
9158 if (filter->usmap.name)
9159 vty_out(vty,
9160 " Route map for selective unsuppress is %s%s\n",
9161 filter->usmap.map ? "*" : "",
9162 filter->usmap.name);
9163
9164 /* Receive prefix count */
9165 vty_out(vty, " %ld accepted prefixes\n", p->pcount[afi][safi]);
9166
9167 /* Maximum prefix */
9168 if (CHECK_FLAG(p->af_flags[afi][safi], PEER_FLAG_MAX_PREFIX)) {
9169 vty_out(vty, " Maximum prefixes allowed %ld%s\n",
9170 p->pmax[afi][safi],
9171 CHECK_FLAG(p->af_flags[afi][safi],
9172 PEER_FLAG_MAX_PREFIX_WARNING)
9173 ? " (warning-only)"
9174 : "");
9175 vty_out(vty, " Threshold for warning message %d%%",
9176 p->pmax_threshold[afi][safi]);
9177 if (p->pmax_restart[afi][safi])
9178 vty_out(vty, ", restart interval %d min",
9179 p->pmax_restart[afi][safi]);
9180 vty_out(vty, "\n");
9181 }
9182
9183 vty_out(vty, "\n");
9184 }
9185 }
9186
9187 static void bgp_show_peer(struct vty *vty, struct peer *p, bool use_json,
9188 json_object *json)
9189 {
9190 struct bgp *bgp;
9191 char buf1[PREFIX2STR_BUFFER], buf[SU_ADDRSTRLEN];
9192 char timebuf[BGP_UPTIME_LEN];
9193 char dn_flag[2];
9194 const char *subcode_str;
9195 const char *code_str;
9196 afi_t afi;
9197 safi_t safi;
9198 uint16_t i;
9199 uint8_t *msg;
9200 json_object *json_neigh = NULL;
9201 time_t epoch_tbuf;
9202
9203 bgp = p->bgp;
9204
9205 if (use_json)
9206 json_neigh = json_object_new_object();
9207
9208 memset(dn_flag, '\0', sizeof(dn_flag));
9209 if (!p->conf_if && peer_dynamic_neighbor(p))
9210 dn_flag[0] = '*';
9211
9212 if (!use_json) {
9213 if (p->conf_if) /* Configured interface name. */
9214 vty_out(vty, "BGP neighbor on %s: %s, ", p->conf_if,
9215 BGP_PEER_SU_UNSPEC(p)
9216 ? "None"
9217 : sockunion2str(&p->su, buf,
9218 SU_ADDRSTRLEN));
9219 else /* Configured IP address. */
9220 vty_out(vty, "BGP neighbor is %s%s, ", dn_flag,
9221 p->host);
9222 }
9223
9224 if (use_json) {
9225 if (p->conf_if && BGP_PEER_SU_UNSPEC(p))
9226 json_object_string_add(json_neigh, "bgpNeighborAddr",
9227 "none");
9228 else if (p->conf_if && !BGP_PEER_SU_UNSPEC(p))
9229 json_object_string_add(
9230 json_neigh, "bgpNeighborAddr",
9231 sockunion2str(&p->su, buf, SU_ADDRSTRLEN));
9232
9233 json_object_int_add(json_neigh, "remoteAs", p->as);
9234
9235 if (p->change_local_as)
9236 json_object_int_add(json_neigh, "localAs",
9237 p->change_local_as);
9238 else
9239 json_object_int_add(json_neigh, "localAs", p->local_as);
9240
9241 if (CHECK_FLAG(p->flags, PEER_FLAG_LOCAL_AS_NO_PREPEND))
9242 json_object_boolean_true_add(json_neigh,
9243 "localAsNoPrepend");
9244
9245 if (CHECK_FLAG(p->flags, PEER_FLAG_LOCAL_AS_REPLACE_AS))
9246 json_object_boolean_true_add(json_neigh,
9247 "localAsReplaceAs");
9248 } else {
9249 if ((p->as_type == AS_SPECIFIED) || (p->as_type == AS_EXTERNAL)
9250 || (p->as_type == AS_INTERNAL))
9251 vty_out(vty, "remote AS %u, ", p->as);
9252 else
9253 vty_out(vty, "remote AS Unspecified, ");
9254 vty_out(vty, "local AS %u%s%s, ",
9255 p->change_local_as ? p->change_local_as : p->local_as,
9256 CHECK_FLAG(p->flags, PEER_FLAG_LOCAL_AS_NO_PREPEND)
9257 ? " no-prepend"
9258 : "",
9259 CHECK_FLAG(p->flags, PEER_FLAG_LOCAL_AS_REPLACE_AS)
9260 ? " replace-as"
9261 : "");
9262 }
9263 /* peer type internal or confed-internal */
9264 if ((p->as == p->local_as) || (p->as_type == AS_INTERNAL)) {
9265 if (use_json) {
9266 if (CHECK_FLAG(bgp->config, BGP_CONFIG_CONFEDERATION))
9267 json_object_boolean_true_add(
9268 json_neigh, "nbrConfedInternalLink");
9269 else
9270 json_object_boolean_true_add(json_neigh,
9271 "nbrInternalLink");
9272 } else {
9273 if (CHECK_FLAG(bgp->config, BGP_CONFIG_CONFEDERATION))
9274 vty_out(vty, "confed-internal link\n");
9275 else
9276 vty_out(vty, "internal link\n");
9277 }
9278 /* peer type external or confed-external */
9279 } else if (p->as || (p->as_type == AS_EXTERNAL)) {
9280 if (use_json) {
9281 if (CHECK_FLAG(bgp->config, BGP_CONFIG_CONFEDERATION))
9282 json_object_boolean_true_add(
9283 json_neigh, "nbrConfedExternalLink");
9284 else
9285 json_object_boolean_true_add(json_neigh,
9286 "nbrExternalLink");
9287 } else {
9288 if (bgp_confederation_peers_check(bgp, p->as))
9289 vty_out(vty, "confed-external link\n");
9290 else
9291 vty_out(vty, "external link\n");
9292 }
9293 } else {
9294 if (use_json)
9295 json_object_boolean_true_add(json_neigh,
9296 "nbrUnspecifiedLink");
9297 else
9298 vty_out(vty, "unspecified link\n");
9299 }
9300
9301 /* Description. */
9302 if (p->desc) {
9303 if (use_json)
9304 json_object_string_add(json_neigh, "nbrDesc", p->desc);
9305 else
9306 vty_out(vty, " Description: %s\n", p->desc);
9307 }
9308
9309 if (p->hostname) {
9310 if (use_json) {
9311 if (p->hostname)
9312 json_object_string_add(json_neigh, "hostname",
9313 p->hostname);
9314
9315 if (p->domainname)
9316 json_object_string_add(json_neigh, "domainname",
9317 p->domainname);
9318 } else {
9319 if (p->domainname && (p->domainname[0] != '\0'))
9320 vty_out(vty, "Hostname: %s.%s\n", p->hostname,
9321 p->domainname);
9322 else
9323 vty_out(vty, "Hostname: %s\n", p->hostname);
9324 }
9325 }
9326
9327 /* Peer-group */
9328 if (p->group) {
9329 if (use_json) {
9330 json_object_string_add(json_neigh, "peerGroup",
9331 p->group->name);
9332
9333 if (dn_flag[0]) {
9334 struct prefix prefix, *range = NULL;
9335
9336 sockunion2hostprefix(&(p->su), &prefix);
9337 range = peer_group_lookup_dynamic_neighbor_range(
9338 p->group, &prefix);
9339
9340 if (range) {
9341 prefix2str(range, buf1, sizeof(buf1));
9342 json_object_string_add(
9343 json_neigh,
9344 "peerSubnetRangeGroup", buf1);
9345 }
9346 }
9347 } else {
9348 vty_out(vty,
9349 " Member of peer-group %s for session parameters\n",
9350 p->group->name);
9351
9352 if (dn_flag[0]) {
9353 struct prefix prefix, *range = NULL;
9354
9355 sockunion2hostprefix(&(p->su), &prefix);
9356 range = peer_group_lookup_dynamic_neighbor_range(
9357 p->group, &prefix);
9358
9359 if (range) {
9360 prefix2str(range, buf1, sizeof(buf1));
9361 vty_out(vty,
9362 " Belongs to the subnet range group: %s\n",
9363 buf1);
9364 }
9365 }
9366 }
9367 }
9368
9369 if (use_json) {
9370 /* Administrative shutdown. */
9371 if (CHECK_FLAG(p->flags, PEER_FLAG_SHUTDOWN))
9372 json_object_boolean_true_add(json_neigh,
9373 "adminShutDown");
9374
9375 /* BGP Version. */
9376 json_object_int_add(json_neigh, "bgpVersion", 4);
9377 json_object_string_add(
9378 json_neigh, "remoteRouterId",
9379 inet_ntop(AF_INET, &p->remote_id, buf1, sizeof(buf1)));
9380 json_object_string_add(
9381 json_neigh, "localRouterId",
9382 inet_ntop(AF_INET, &bgp->router_id, buf1,
9383 sizeof(buf1)));
9384
9385 /* Confederation */
9386 if (CHECK_FLAG(bgp->config, BGP_CONFIG_CONFEDERATION)
9387 && bgp_confederation_peers_check(bgp, p->as))
9388 json_object_boolean_true_add(json_neigh,
9389 "nbrCommonAdmin");
9390
9391 /* Status. */
9392 json_object_string_add(
9393 json_neigh, "bgpState",
9394 lookup_msg(bgp_status_msg, p->status, NULL));
9395
9396 if (p->status == Established) {
9397 time_t uptime;
9398
9399 uptime = bgp_clock();
9400 uptime -= p->uptime;
9401 epoch_tbuf = time(NULL) - uptime;
9402
9403 #if CONFDATE > 20200101
9404 CPP_NOTICE(
9405 "bgpTimerUp should be deprecated and can be removed now");
9406 #endif
9407 /*
9408 * bgpTimerUp was miliseconds that was accurate
9409 * up to 1 day, then the value returned
9410 * became garbage. So in order to provide
9411 * some level of backwards compatability,
9412 * we still provde the data, but now
9413 * we are returning the correct value
9414 * and also adding a new bgpTimerUpMsec
9415 * which will allow us to deprecate
9416 * this eventually
9417 */
9418 json_object_int_add(json_neigh, "bgpTimerUp",
9419 uptime * 1000);
9420 json_object_int_add(json_neigh, "bgpTimerUpMsec",
9421 uptime * 1000);
9422 json_object_string_add(json_neigh, "bgpTimerUpString",
9423 peer_uptime(p->uptime, timebuf,
9424 BGP_UPTIME_LEN, 0,
9425 NULL));
9426 json_object_int_add(json_neigh,
9427 "bgpTimerUpEstablishedEpoch",
9428 epoch_tbuf);
9429 }
9430
9431 else if (p->status == Active) {
9432 if (CHECK_FLAG(p->flags, PEER_FLAG_PASSIVE))
9433 json_object_string_add(json_neigh, "bgpStateIs",
9434 "passive");
9435 else if (CHECK_FLAG(p->sflags, PEER_STATUS_NSF_WAIT))
9436 json_object_string_add(json_neigh, "bgpStateIs",
9437 "passiveNSF");
9438 }
9439
9440 /* read timer */
9441 time_t uptime;
9442 struct tm *tm;
9443
9444 uptime = bgp_clock();
9445 uptime -= p->readtime;
9446 tm = gmtime(&uptime);
9447 json_object_int_add(json_neigh, "bgpTimerLastRead",
9448 (tm->tm_sec * 1000) + (tm->tm_min * 60000)
9449 + (tm->tm_hour * 3600000));
9450
9451 uptime = bgp_clock();
9452 uptime -= p->last_write;
9453 tm = gmtime(&uptime);
9454 json_object_int_add(json_neigh, "bgpTimerLastWrite",
9455 (tm->tm_sec * 1000) + (tm->tm_min * 60000)
9456 + (tm->tm_hour * 3600000));
9457
9458 uptime = bgp_clock();
9459 uptime -= p->update_time;
9460 tm = gmtime(&uptime);
9461 json_object_int_add(json_neigh, "bgpInUpdateElapsedTimeMsecs",
9462 (tm->tm_sec * 1000) + (tm->tm_min * 60000)
9463 + (tm->tm_hour * 3600000));
9464
9465 /* Configured timer values. */
9466 json_object_int_add(json_neigh, "bgpTimerHoldTimeMsecs",
9467 p->v_holdtime * 1000);
9468 json_object_int_add(json_neigh,
9469 "bgpTimerKeepAliveIntervalMsecs",
9470 p->v_keepalive * 1000);
9471 if (CHECK_FLAG(p->flags, PEER_FLAG_TIMER)) {
9472 json_object_int_add(json_neigh,
9473 "bgpTimerConfiguredHoldTimeMsecs",
9474 p->holdtime * 1000);
9475 json_object_int_add(
9476 json_neigh,
9477 "bgpTimerConfiguredKeepAliveIntervalMsecs",
9478 p->keepalive * 1000);
9479 } else if ((bgp->default_holdtime != BGP_DEFAULT_HOLDTIME)
9480 || (bgp->default_keepalive
9481 != BGP_DEFAULT_KEEPALIVE)) {
9482 json_object_int_add(json_neigh,
9483 "bgpTimerConfiguredHoldTimeMsecs",
9484 bgp->default_holdtime);
9485 json_object_int_add(
9486 json_neigh,
9487 "bgpTimerConfiguredKeepAliveIntervalMsecs",
9488 bgp->default_keepalive);
9489 }
9490 } else {
9491 /* Administrative shutdown. */
9492 if (CHECK_FLAG(p->flags, PEER_FLAG_SHUTDOWN))
9493 vty_out(vty, " Administratively shut down\n");
9494
9495 /* BGP Version. */
9496 vty_out(vty, " BGP version 4");
9497 vty_out(vty, ", remote router ID %s",
9498 inet_ntop(AF_INET, &p->remote_id, buf1, sizeof(buf1)));
9499 vty_out(vty, ", local router ID %s\n",
9500 inet_ntop(AF_INET, &bgp->router_id, buf1,
9501 sizeof(buf1)));
9502
9503 /* Confederation */
9504 if (CHECK_FLAG(bgp->config, BGP_CONFIG_CONFEDERATION)
9505 && bgp_confederation_peers_check(bgp, p->as))
9506 vty_out(vty,
9507 " Neighbor under common administration\n");
9508
9509 /* Status. */
9510 vty_out(vty, " BGP state = %s",
9511 lookup_msg(bgp_status_msg, p->status, NULL));
9512
9513 if (p->status == Established)
9514 vty_out(vty, ", up for %8s",
9515 peer_uptime(p->uptime, timebuf, BGP_UPTIME_LEN,
9516 0, NULL));
9517
9518 else if (p->status == Active) {
9519 if (CHECK_FLAG(p->flags, PEER_FLAG_PASSIVE))
9520 vty_out(vty, " (passive)");
9521 else if (CHECK_FLAG(p->sflags, PEER_STATUS_NSF_WAIT))
9522 vty_out(vty, " (NSF passive)");
9523 }
9524 vty_out(vty, "\n");
9525
9526 /* read timer */
9527 vty_out(vty, " Last read %s",
9528 peer_uptime(p->readtime, timebuf, BGP_UPTIME_LEN, 0,
9529 NULL));
9530 vty_out(vty, ", Last write %s\n",
9531 peer_uptime(p->last_write, timebuf, BGP_UPTIME_LEN, 0,
9532 NULL));
9533
9534 /* Configured timer values. */
9535 vty_out(vty,
9536 " Hold time is %d, keepalive interval is %d seconds\n",
9537 p->v_holdtime, p->v_keepalive);
9538 if (CHECK_FLAG(p->flags, PEER_FLAG_TIMER)) {
9539 vty_out(vty, " Configured hold time is %d",
9540 p->holdtime);
9541 vty_out(vty, ", keepalive interval is %d seconds\n",
9542 p->keepalive);
9543 } else if ((bgp->default_holdtime != BGP_DEFAULT_HOLDTIME)
9544 || (bgp->default_keepalive
9545 != BGP_DEFAULT_KEEPALIVE)) {
9546 vty_out(vty, " Configured hold time is %d",
9547 bgp->default_holdtime);
9548 vty_out(vty, ", keepalive interval is %d seconds\n",
9549 bgp->default_keepalive);
9550 }
9551 }
9552 /* Capability. */
9553 if (p->status == Established) {
9554 if (p->cap || p->afc_adv[AFI_IP][SAFI_UNICAST]
9555 || p->afc_recv[AFI_IP][SAFI_UNICAST]
9556 || p->afc_adv[AFI_IP][SAFI_MULTICAST]
9557 || p->afc_recv[AFI_IP][SAFI_MULTICAST]
9558 || p->afc_adv[AFI_IP6][SAFI_UNICAST]
9559 || p->afc_recv[AFI_IP6][SAFI_UNICAST]
9560 || p->afc_adv[AFI_IP6][SAFI_MULTICAST]
9561 || p->afc_recv[AFI_IP6][SAFI_MULTICAST]
9562 || p->afc_adv[AFI_IP6][SAFI_MPLS_VPN]
9563 || p->afc_recv[AFI_IP6][SAFI_MPLS_VPN]
9564 || p->afc_adv[AFI_IP6][SAFI_ENCAP]
9565 || p->afc_recv[AFI_IP6][SAFI_ENCAP]
9566 || p->afc_adv[AFI_IP6][SAFI_FLOWSPEC]
9567 || p->afc_recv[AFI_IP6][SAFI_FLOWSPEC]
9568 || p->afc_adv[AFI_IP][SAFI_ENCAP]
9569 || p->afc_recv[AFI_IP][SAFI_ENCAP]
9570 || p->afc_adv[AFI_IP][SAFI_FLOWSPEC]
9571 || p->afc_recv[AFI_IP][SAFI_FLOWSPEC]
9572 || p->afc_adv[AFI_IP][SAFI_MPLS_VPN]
9573 || p->afc_recv[AFI_IP][SAFI_MPLS_VPN]) {
9574 if (use_json) {
9575 json_object *json_cap = NULL;
9576
9577 json_cap = json_object_new_object();
9578
9579 /* AS4 */
9580 if (CHECK_FLAG(p->cap, PEER_CAP_AS4_RCV)
9581 || CHECK_FLAG(p->cap, PEER_CAP_AS4_ADV)) {
9582 if (CHECK_FLAG(p->cap, PEER_CAP_AS4_ADV)
9583 && CHECK_FLAG(p->cap,
9584 PEER_CAP_AS4_RCV))
9585 json_object_string_add(
9586 json_cap, "4byteAs",
9587 "advertisedAndReceived");
9588 else if (CHECK_FLAG(p->cap,
9589 PEER_CAP_AS4_ADV))
9590 json_object_string_add(
9591 json_cap, "4byteAs",
9592 "advertised");
9593 else if (CHECK_FLAG(p->cap,
9594 PEER_CAP_AS4_RCV))
9595 json_object_string_add(
9596 json_cap, "4byteAs",
9597 "received");
9598 }
9599
9600 /* AddPath */
9601 if (CHECK_FLAG(p->cap, PEER_CAP_ADDPATH_RCV)
9602 || CHECK_FLAG(p->cap,
9603 PEER_CAP_ADDPATH_ADV)) {
9604 json_object *json_add = NULL;
9605 const char *print_store;
9606
9607 json_add = json_object_new_object();
9608
9609 FOREACH_AFI_SAFI (afi, safi) {
9610 json_object *json_sub = NULL;
9611 json_sub =
9612 json_object_new_object();
9613 print_store = afi_safi_print(
9614 afi, safi);
9615
9616 if (CHECK_FLAG(
9617 p->af_cap[afi]
9618 [safi],
9619 PEER_CAP_ADDPATH_AF_TX_ADV)
9620 || CHECK_FLAG(
9621 p->af_cap[afi]
9622 [safi],
9623 PEER_CAP_ADDPATH_AF_TX_RCV)) {
9624 if (CHECK_FLAG(
9625 p->af_cap
9626 [afi]
9627 [safi],
9628 PEER_CAP_ADDPATH_AF_TX_ADV)
9629 && CHECK_FLAG(
9630 p->af_cap
9631 [afi]
9632 [safi],
9633 PEER_CAP_ADDPATH_AF_TX_RCV))
9634 json_object_boolean_true_add(
9635 json_sub,
9636 "txAdvertisedAndReceived");
9637 else if (
9638 CHECK_FLAG(
9639 p->af_cap
9640 [afi]
9641 [safi],
9642 PEER_CAP_ADDPATH_AF_TX_ADV))
9643 json_object_boolean_true_add(
9644 json_sub,
9645 "txAdvertised");
9646 else if (
9647 CHECK_FLAG(
9648 p->af_cap
9649 [afi]
9650 [safi],
9651 PEER_CAP_ADDPATH_AF_TX_RCV))
9652 json_object_boolean_true_add(
9653 json_sub,
9654 "txReceived");
9655 }
9656
9657 if (CHECK_FLAG(
9658 p->af_cap[afi]
9659 [safi],
9660 PEER_CAP_ADDPATH_AF_RX_ADV)
9661 || CHECK_FLAG(
9662 p->af_cap[afi]
9663 [safi],
9664 PEER_CAP_ADDPATH_AF_RX_RCV)) {
9665 if (CHECK_FLAG(
9666 p->af_cap
9667 [afi]
9668 [safi],
9669 PEER_CAP_ADDPATH_AF_RX_ADV)
9670 && CHECK_FLAG(
9671 p->af_cap
9672 [afi]
9673 [safi],
9674 PEER_CAP_ADDPATH_AF_RX_RCV))
9675 json_object_boolean_true_add(
9676 json_sub,
9677 "rxAdvertisedAndReceived");
9678 else if (
9679 CHECK_FLAG(
9680 p->af_cap
9681 [afi]
9682 [safi],
9683 PEER_CAP_ADDPATH_AF_RX_ADV))
9684 json_object_boolean_true_add(
9685 json_sub,
9686 "rxAdvertised");
9687 else if (
9688 CHECK_FLAG(
9689 p->af_cap
9690 [afi]
9691 [safi],
9692 PEER_CAP_ADDPATH_AF_RX_RCV))
9693 json_object_boolean_true_add(
9694 json_sub,
9695 "rxReceived");
9696 }
9697
9698 if (CHECK_FLAG(
9699 p->af_cap[afi]
9700 [safi],
9701 PEER_CAP_ADDPATH_AF_TX_ADV)
9702 || CHECK_FLAG(
9703 p->af_cap[afi]
9704 [safi],
9705 PEER_CAP_ADDPATH_AF_TX_RCV)
9706 || CHECK_FLAG(
9707 p->af_cap[afi]
9708 [safi],
9709 PEER_CAP_ADDPATH_AF_RX_ADV)
9710 || CHECK_FLAG(
9711 p->af_cap[afi]
9712 [safi],
9713 PEER_CAP_ADDPATH_AF_RX_RCV))
9714 json_object_object_add(
9715 json_add,
9716 print_store,
9717 json_sub);
9718 else
9719 json_object_free(
9720 json_sub);
9721 }
9722
9723 json_object_object_add(
9724 json_cap, "addPath", json_add);
9725 }
9726
9727 /* Dynamic */
9728 if (CHECK_FLAG(p->cap, PEER_CAP_DYNAMIC_RCV)
9729 || CHECK_FLAG(p->cap,
9730 PEER_CAP_DYNAMIC_ADV)) {
9731 if (CHECK_FLAG(p->cap,
9732 PEER_CAP_DYNAMIC_ADV)
9733 && CHECK_FLAG(p->cap,
9734 PEER_CAP_DYNAMIC_RCV))
9735 json_object_string_add(
9736 json_cap, "dynamic",
9737 "advertisedAndReceived");
9738 else if (CHECK_FLAG(
9739 p->cap,
9740 PEER_CAP_DYNAMIC_ADV))
9741 json_object_string_add(
9742 json_cap, "dynamic",
9743 "advertised");
9744 else if (CHECK_FLAG(
9745 p->cap,
9746 PEER_CAP_DYNAMIC_RCV))
9747 json_object_string_add(
9748 json_cap, "dynamic",
9749 "received");
9750 }
9751
9752 /* Extended nexthop */
9753 if (CHECK_FLAG(p->cap, PEER_CAP_ENHE_RCV)
9754 || CHECK_FLAG(p->cap, PEER_CAP_ENHE_ADV)) {
9755 json_object *json_nxt = NULL;
9756 const char *print_store;
9757
9758
9759 if (CHECK_FLAG(p->cap,
9760 PEER_CAP_ENHE_ADV)
9761 && CHECK_FLAG(p->cap,
9762 PEER_CAP_ENHE_RCV))
9763 json_object_string_add(
9764 json_cap,
9765 "extendedNexthop",
9766 "advertisedAndReceived");
9767 else if (CHECK_FLAG(p->cap,
9768 PEER_CAP_ENHE_ADV))
9769 json_object_string_add(
9770 json_cap,
9771 "extendedNexthop",
9772 "advertised");
9773 else if (CHECK_FLAG(p->cap,
9774 PEER_CAP_ENHE_RCV))
9775 json_object_string_add(
9776 json_cap,
9777 "extendedNexthop",
9778 "received");
9779
9780 if (CHECK_FLAG(p->cap,
9781 PEER_CAP_ENHE_RCV)) {
9782 json_nxt =
9783 json_object_new_object();
9784
9785 for (safi = SAFI_UNICAST;
9786 safi < SAFI_MAX; safi++) {
9787 if (CHECK_FLAG(
9788 p->af_cap
9789 [AFI_IP]
9790 [safi],
9791 PEER_CAP_ENHE_AF_RCV)) {
9792 print_store = afi_safi_print(
9793 AFI_IP,
9794 safi);
9795 json_object_string_add(
9796 json_nxt,
9797 print_store,
9798 "recieved"); /* misspelled for compatibility */
9799 }
9800 }
9801 json_object_object_add(
9802 json_cap,
9803 "extendedNexthopFamililesByPeer",
9804 json_nxt);
9805 }
9806 }
9807
9808 /* Route Refresh */
9809 if (CHECK_FLAG(p->cap, PEER_CAP_REFRESH_ADV)
9810 || CHECK_FLAG(p->cap,
9811 PEER_CAP_REFRESH_NEW_RCV)
9812 || CHECK_FLAG(p->cap,
9813 PEER_CAP_REFRESH_OLD_RCV)) {
9814 if (CHECK_FLAG(p->cap,
9815 PEER_CAP_REFRESH_ADV)
9816 && (CHECK_FLAG(
9817 p->cap,
9818 PEER_CAP_REFRESH_NEW_RCV)
9819 || CHECK_FLAG(
9820 p->cap,
9821 PEER_CAP_REFRESH_OLD_RCV))) {
9822 if (CHECK_FLAG(
9823 p->cap,
9824 PEER_CAP_REFRESH_OLD_RCV)
9825 && CHECK_FLAG(
9826 p->cap,
9827 PEER_CAP_REFRESH_NEW_RCV))
9828 json_object_string_add(
9829 json_cap,
9830 "routeRefresh",
9831 "advertisedAndReceivedOldNew");
9832 else {
9833 if (CHECK_FLAG(
9834 p->cap,
9835 PEER_CAP_REFRESH_OLD_RCV))
9836 json_object_string_add(
9837 json_cap,
9838 "routeRefresh",
9839 "advertisedAndReceivedOld");
9840 else
9841 json_object_string_add(
9842 json_cap,
9843 "routeRefresh",
9844 "advertisedAndReceivedNew");
9845 }
9846 } else if (
9847 CHECK_FLAG(
9848 p->cap,
9849 PEER_CAP_REFRESH_ADV))
9850 json_object_string_add(
9851 json_cap,
9852 "routeRefresh",
9853 "advertised");
9854 else if (
9855 CHECK_FLAG(
9856 p->cap,
9857 PEER_CAP_REFRESH_NEW_RCV)
9858 || CHECK_FLAG(
9859 p->cap,
9860 PEER_CAP_REFRESH_OLD_RCV))
9861 json_object_string_add(
9862 json_cap,
9863 "routeRefresh",
9864 "received");
9865 }
9866
9867 /* Multiprotocol Extensions */
9868 json_object *json_multi = NULL;
9869 json_multi = json_object_new_object();
9870
9871 FOREACH_AFI_SAFI (afi, safi) {
9872 if (p->afc_adv[afi][safi]
9873 || p->afc_recv[afi][safi]) {
9874 json_object *json_exten = NULL;
9875 json_exten =
9876 json_object_new_object();
9877
9878 if (p->afc_adv[afi][safi]
9879 && p->afc_recv[afi][safi])
9880 json_object_boolean_true_add(
9881 json_exten,
9882 "advertisedAndReceived");
9883 else if (p->afc_adv[afi][safi])
9884 json_object_boolean_true_add(
9885 json_exten,
9886 "advertised");
9887 else if (p->afc_recv[afi][safi])
9888 json_object_boolean_true_add(
9889 json_exten,
9890 "received");
9891
9892 json_object_object_add(
9893 json_multi,
9894 afi_safi_print(afi,
9895 safi),
9896 json_exten);
9897 }
9898 }
9899 json_object_object_add(
9900 json_cap, "multiprotocolExtensions",
9901 json_multi);
9902
9903 /* Hostname capabilities */
9904 json_object *json_hname = NULL;
9905
9906 json_hname = json_object_new_object();
9907
9908 if (CHECK_FLAG(p->cap, PEER_CAP_HOSTNAME_ADV)) {
9909 json_object_string_add(
9910 json_hname, "advHostName",
9911 bgp->peer_self->hostname
9912 ? bgp->peer_self
9913 ->hostname
9914 : "n/a");
9915 json_object_string_add(
9916 json_hname, "advDomainName",
9917 bgp->peer_self->domainname
9918 ? bgp->peer_self
9919 ->domainname
9920 : "n/a");
9921 }
9922
9923
9924 if (CHECK_FLAG(p->cap, PEER_CAP_HOSTNAME_RCV)) {
9925 json_object_string_add(
9926 json_hname, "rcvHostName",
9927 p->hostname ? p->hostname
9928 : "n/a");
9929 json_object_string_add(
9930 json_hname, "rcvDomainName",
9931 p->domainname ? p->domainname
9932 : "n/a");
9933 }
9934
9935 json_object_object_add(json_cap, "hostName",
9936 json_hname);
9937
9938 /* Gracefull Restart */
9939 if (CHECK_FLAG(p->cap, PEER_CAP_RESTART_RCV)
9940 || CHECK_FLAG(p->cap,
9941 PEER_CAP_RESTART_ADV)) {
9942 if (CHECK_FLAG(p->cap,
9943 PEER_CAP_RESTART_ADV)
9944 && CHECK_FLAG(p->cap,
9945 PEER_CAP_RESTART_RCV))
9946 json_object_string_add(
9947 json_cap,
9948 "gracefulRestart",
9949 "advertisedAndReceived");
9950 else if (CHECK_FLAG(
9951 p->cap,
9952 PEER_CAP_RESTART_ADV))
9953 json_object_string_add(
9954 json_cap,
9955 "gracefulRestartCapability",
9956 "advertised");
9957 else if (CHECK_FLAG(
9958 p->cap,
9959 PEER_CAP_RESTART_RCV))
9960 json_object_string_add(
9961 json_cap,
9962 "gracefulRestartCapability",
9963 "received");
9964
9965 if (CHECK_FLAG(p->cap,
9966 PEER_CAP_RESTART_RCV)) {
9967 int restart_af_count = 0;
9968 json_object *json_restart =
9969 NULL;
9970 json_restart =
9971 json_object_new_object();
9972
9973 json_object_int_add(
9974 json_cap,
9975 "gracefulRestartRemoteTimerMsecs",
9976 p->v_gr_restart * 1000);
9977
9978 FOREACH_AFI_SAFI (afi, safi) {
9979 if (CHECK_FLAG(
9980 p->af_cap
9981 [afi]
9982 [safi],
9983 PEER_CAP_RESTART_AF_RCV)) {
9984 json_object *
9985 json_sub =
9986 NULL;
9987 json_sub =
9988 json_object_new_object();
9989
9990 if (CHECK_FLAG(
9991 p->af_cap
9992 [afi]
9993 [safi],
9994 PEER_CAP_RESTART_AF_PRESERVE_RCV))
9995 json_object_boolean_true_add(
9996 json_sub,
9997 "preserved");
9998 restart_af_count++;
9999 json_object_object_add(
10000 json_restart,
10001 afi_safi_print(
10002 afi,
10003 safi),
10004 json_sub);
10005 }
10006 }
10007 if (!restart_af_count) {
10008 json_object_string_add(
10009 json_cap,
10010 "addressFamiliesByPeer",
10011 "none");
10012 json_object_free(
10013 json_restart);
10014 } else
10015 json_object_object_add(
10016 json_cap,
10017 "addressFamiliesByPeer",
10018 json_restart);
10019 }
10020 }
10021 json_object_object_add(json_neigh,
10022 "neighborCapabilities",
10023 json_cap);
10024 } else {
10025 vty_out(vty, " Neighbor capabilities:\n");
10026
10027 /* AS4 */
10028 if (CHECK_FLAG(p->cap, PEER_CAP_AS4_RCV)
10029 || CHECK_FLAG(p->cap, PEER_CAP_AS4_ADV)) {
10030 vty_out(vty, " 4 Byte AS:");
10031 if (CHECK_FLAG(p->cap,
10032 PEER_CAP_AS4_ADV))
10033 vty_out(vty, " advertised");
10034 if (CHECK_FLAG(p->cap,
10035 PEER_CAP_AS4_RCV))
10036 vty_out(vty, " %sreceived",
10037 CHECK_FLAG(
10038 p->cap,
10039 PEER_CAP_AS4_ADV)
10040 ? "and "
10041 : "");
10042 vty_out(vty, "\n");
10043 }
10044
10045 /* AddPath */
10046 if (CHECK_FLAG(p->cap, PEER_CAP_ADDPATH_RCV)
10047 || CHECK_FLAG(p->cap,
10048 PEER_CAP_ADDPATH_ADV)) {
10049 vty_out(vty, " AddPath:\n");
10050
10051 FOREACH_AFI_SAFI (afi, safi) {
10052 if (CHECK_FLAG(
10053 p->af_cap[afi]
10054 [safi],
10055 PEER_CAP_ADDPATH_AF_TX_ADV)
10056 || CHECK_FLAG(
10057 p->af_cap[afi]
10058 [safi],
10059 PEER_CAP_ADDPATH_AF_TX_RCV)) {
10060 vty_out(vty,
10061 " %s: TX ",
10062 afi_safi_print(
10063 afi,
10064 safi));
10065
10066 if (CHECK_FLAG(
10067 p->af_cap
10068 [afi]
10069 [safi],
10070 PEER_CAP_ADDPATH_AF_TX_ADV))
10071 vty_out(vty,
10072 "advertised %s",
10073 afi_safi_print(
10074 afi,
10075 safi));
10076
10077 if (CHECK_FLAG(
10078 p->af_cap
10079 [afi]
10080 [safi],
10081 PEER_CAP_ADDPATH_AF_TX_RCV))
10082 vty_out(vty,
10083 "%sreceived",
10084 CHECK_FLAG(
10085 p->af_cap
10086 [afi]
10087 [safi],
10088 PEER_CAP_ADDPATH_AF_TX_ADV)
10089 ? " and "
10090 : "");
10091
10092 vty_out(vty, "\n");
10093 }
10094
10095 if (CHECK_FLAG(
10096 p->af_cap[afi]
10097 [safi],
10098 PEER_CAP_ADDPATH_AF_RX_ADV)
10099 || CHECK_FLAG(
10100 p->af_cap[afi]
10101 [safi],
10102 PEER_CAP_ADDPATH_AF_RX_RCV)) {
10103 vty_out(vty,
10104 " %s: RX ",
10105 afi_safi_print(
10106 afi,
10107 safi));
10108
10109 if (CHECK_FLAG(
10110 p->af_cap
10111 [afi]
10112 [safi],
10113 PEER_CAP_ADDPATH_AF_RX_ADV))
10114 vty_out(vty,
10115 "advertised %s",
10116 afi_safi_print(
10117 afi,
10118 safi));
10119
10120 if (CHECK_FLAG(
10121 p->af_cap
10122 [afi]
10123 [safi],
10124 PEER_CAP_ADDPATH_AF_RX_RCV))
10125 vty_out(vty,
10126 "%sreceived",
10127 CHECK_FLAG(
10128 p->af_cap
10129 [afi]
10130 [safi],
10131 PEER_CAP_ADDPATH_AF_RX_ADV)
10132 ? " and "
10133 : "");
10134
10135 vty_out(vty, "\n");
10136 }
10137 }
10138 }
10139
10140 /* Dynamic */
10141 if (CHECK_FLAG(p->cap, PEER_CAP_DYNAMIC_RCV)
10142 || CHECK_FLAG(p->cap,
10143 PEER_CAP_DYNAMIC_ADV)) {
10144 vty_out(vty, " Dynamic:");
10145 if (CHECK_FLAG(p->cap,
10146 PEER_CAP_DYNAMIC_ADV))
10147 vty_out(vty, " advertised");
10148 if (CHECK_FLAG(p->cap,
10149 PEER_CAP_DYNAMIC_RCV))
10150 vty_out(vty, " %sreceived",
10151 CHECK_FLAG(
10152 p->cap,
10153 PEER_CAP_DYNAMIC_ADV)
10154 ? "and "
10155 : "");
10156 vty_out(vty, "\n");
10157 }
10158
10159 /* Extended nexthop */
10160 if (CHECK_FLAG(p->cap, PEER_CAP_ENHE_RCV)
10161 || CHECK_FLAG(p->cap, PEER_CAP_ENHE_ADV)) {
10162 vty_out(vty, " Extended nexthop:");
10163 if (CHECK_FLAG(p->cap,
10164 PEER_CAP_ENHE_ADV))
10165 vty_out(vty, " advertised");
10166 if (CHECK_FLAG(p->cap,
10167 PEER_CAP_ENHE_RCV))
10168 vty_out(vty, " %sreceived",
10169 CHECK_FLAG(
10170 p->cap,
10171 PEER_CAP_ENHE_ADV)
10172 ? "and "
10173 : "");
10174 vty_out(vty, "\n");
10175
10176 if (CHECK_FLAG(p->cap,
10177 PEER_CAP_ENHE_RCV)) {
10178 vty_out(vty,
10179 " Address families by peer:\n ");
10180 for (safi = SAFI_UNICAST;
10181 safi < SAFI_MAX; safi++)
10182 if (CHECK_FLAG(
10183 p->af_cap
10184 [AFI_IP]
10185 [safi],
10186 PEER_CAP_ENHE_AF_RCV))
10187 vty_out(vty,
10188 " %s\n",
10189 afi_safi_print(
10190 AFI_IP,
10191 safi));
10192 }
10193 }
10194
10195 /* Route Refresh */
10196 if (CHECK_FLAG(p->cap, PEER_CAP_REFRESH_ADV)
10197 || CHECK_FLAG(p->cap,
10198 PEER_CAP_REFRESH_NEW_RCV)
10199 || CHECK_FLAG(p->cap,
10200 PEER_CAP_REFRESH_OLD_RCV)) {
10201 vty_out(vty, " Route refresh:");
10202 if (CHECK_FLAG(p->cap,
10203 PEER_CAP_REFRESH_ADV))
10204 vty_out(vty, " advertised");
10205 if (CHECK_FLAG(p->cap,
10206 PEER_CAP_REFRESH_NEW_RCV)
10207 || CHECK_FLAG(
10208 p->cap,
10209 PEER_CAP_REFRESH_OLD_RCV))
10210 vty_out(vty, " %sreceived(%s)",
10211 CHECK_FLAG(
10212 p->cap,
10213 PEER_CAP_REFRESH_ADV)
10214 ? "and "
10215 : "",
10216 (CHECK_FLAG(
10217 p->cap,
10218 PEER_CAP_REFRESH_OLD_RCV)
10219 && CHECK_FLAG(
10220 p->cap,
10221 PEER_CAP_REFRESH_NEW_RCV))
10222 ? "old & new"
10223 : CHECK_FLAG(
10224 p->cap,
10225 PEER_CAP_REFRESH_OLD_RCV)
10226 ? "old"
10227 : "new");
10228
10229 vty_out(vty, "\n");
10230 }
10231
10232 /* Multiprotocol Extensions */
10233 FOREACH_AFI_SAFI (afi, safi)
10234 if (p->afc_adv[afi][safi]
10235 || p->afc_recv[afi][safi]) {
10236 vty_out(vty,
10237 " Address Family %s:",
10238 afi_safi_print(afi,
10239 safi));
10240 if (p->afc_adv[afi][safi])
10241 vty_out(vty,
10242 " advertised");
10243 if (p->afc_recv[afi][safi])
10244 vty_out(vty,
10245 " %sreceived",
10246 p->afc_adv[afi]
10247 [safi]
10248 ? "and "
10249 : "");
10250 vty_out(vty, "\n");
10251 }
10252
10253 /* Hostname capability */
10254 vty_out(vty, " Hostname Capability:");
10255
10256 if (CHECK_FLAG(p->cap, PEER_CAP_HOSTNAME_ADV)) {
10257 vty_out(vty,
10258 " advertised (name: %s,domain name: %s)",
10259 bgp->peer_self->hostname
10260 ? bgp->peer_self
10261 ->hostname
10262 : "n/a",
10263 bgp->peer_self->domainname
10264 ? bgp->peer_self
10265 ->domainname
10266 : "n/a");
10267 } else {
10268 vty_out(vty, " not advertised");
10269 }
10270
10271 if (CHECK_FLAG(p->cap, PEER_CAP_HOSTNAME_RCV)) {
10272 vty_out(vty,
10273 " received (name: %s,domain name: %s)",
10274 p->hostname ? p->hostname
10275 : "n/a",
10276 p->domainname ? p->domainname
10277 : "n/a");
10278 } else {
10279 vty_out(vty, " not received");
10280 }
10281
10282 vty_out(vty, "\n");
10283
10284 /* Gracefull Restart */
10285 if (CHECK_FLAG(p->cap, PEER_CAP_RESTART_RCV)
10286 || CHECK_FLAG(p->cap,
10287 PEER_CAP_RESTART_ADV)) {
10288 vty_out(vty,
10289 " Graceful Restart Capabilty:");
10290 if (CHECK_FLAG(p->cap,
10291 PEER_CAP_RESTART_ADV))
10292 vty_out(vty, " advertised");
10293 if (CHECK_FLAG(p->cap,
10294 PEER_CAP_RESTART_RCV))
10295 vty_out(vty, " %sreceived",
10296 CHECK_FLAG(
10297 p->cap,
10298 PEER_CAP_RESTART_ADV)
10299 ? "and "
10300 : "");
10301 vty_out(vty, "\n");
10302
10303 if (CHECK_FLAG(p->cap,
10304 PEER_CAP_RESTART_RCV)) {
10305 int restart_af_count = 0;
10306
10307 vty_out(vty,
10308 " Remote Restart timer is %d seconds\n",
10309 p->v_gr_restart);
10310 vty_out(vty,
10311 " Address families by peer:\n ");
10312
10313 FOREACH_AFI_SAFI (afi, safi)
10314 if (CHECK_FLAG(
10315 p->af_cap
10316 [afi]
10317 [safi],
10318 PEER_CAP_RESTART_AF_RCV)) {
10319 vty_out(vty,
10320 "%s%s(%s)",
10321 restart_af_count
10322 ? ", "
10323 : "",
10324 afi_safi_print(
10325 afi,
10326 safi),
10327 CHECK_FLAG(
10328 p->af_cap
10329 [afi]
10330 [safi],
10331 PEER_CAP_RESTART_AF_PRESERVE_RCV)
10332 ? "preserved"
10333 : "not preserved");
10334 restart_af_count++;
10335 }
10336 if (!restart_af_count)
10337 vty_out(vty, "none");
10338 vty_out(vty, "\n");
10339 }
10340 }
10341 }
10342 }
10343 }
10344
10345 /* graceful restart information */
10346 if (CHECK_FLAG(p->cap, PEER_CAP_RESTART_RCV) || p->t_gr_restart
10347 || p->t_gr_stale) {
10348 json_object *json_grace = NULL;
10349 json_object *json_grace_send = NULL;
10350 json_object *json_grace_recv = NULL;
10351 int eor_send_af_count = 0;
10352 int eor_receive_af_count = 0;
10353
10354 if (use_json) {
10355 json_grace = json_object_new_object();
10356 json_grace_send = json_object_new_object();
10357 json_grace_recv = json_object_new_object();
10358
10359 if (p->status == Established) {
10360 FOREACH_AFI_SAFI (afi, safi) {
10361 if (CHECK_FLAG(p->af_sflags[afi][safi],
10362 PEER_STATUS_EOR_SEND)) {
10363 json_object_boolean_true_add(
10364 json_grace_send,
10365 afi_safi_print(afi,
10366 safi));
10367 eor_send_af_count++;
10368 }
10369 }
10370 FOREACH_AFI_SAFI (afi, safi) {
10371 if (CHECK_FLAG(
10372 p->af_sflags[afi][safi],
10373 PEER_STATUS_EOR_RECEIVED)) {
10374 json_object_boolean_true_add(
10375 json_grace_recv,
10376 afi_safi_print(afi,
10377 safi));
10378 eor_receive_af_count++;
10379 }
10380 }
10381 }
10382
10383 json_object_object_add(json_grace, "endOfRibSend",
10384 json_grace_send);
10385 json_object_object_add(json_grace, "endOfRibRecv",
10386 json_grace_recv);
10387
10388 if (p->t_gr_restart)
10389 json_object_int_add(json_grace,
10390 "gracefulRestartTimerMsecs",
10391 thread_timer_remain_second(
10392 p->t_gr_restart)
10393 * 1000);
10394
10395 if (p->t_gr_stale)
10396 json_object_int_add(
10397 json_grace,
10398 "gracefulStalepathTimerMsecs",
10399 thread_timer_remain_second(
10400 p->t_gr_stale)
10401 * 1000);
10402
10403 json_object_object_add(
10404 json_neigh, "gracefulRestartInfo", json_grace);
10405 } else {
10406 vty_out(vty, " Graceful restart information:\n");
10407 if (p->status == Established) {
10408 vty_out(vty, " End-of-RIB send: ");
10409 FOREACH_AFI_SAFI (afi, safi) {
10410 if (CHECK_FLAG(p->af_sflags[afi][safi],
10411 PEER_STATUS_EOR_SEND)) {
10412 vty_out(vty, "%s%s",
10413 eor_send_af_count ? ", "
10414 : "",
10415 afi_safi_print(afi,
10416 safi));
10417 eor_send_af_count++;
10418 }
10419 }
10420 vty_out(vty, "\n");
10421 vty_out(vty, " End-of-RIB received: ");
10422 FOREACH_AFI_SAFI (afi, safi) {
10423 if (CHECK_FLAG(
10424 p->af_sflags[afi][safi],
10425 PEER_STATUS_EOR_RECEIVED)) {
10426 vty_out(vty, "%s%s",
10427 eor_receive_af_count
10428 ? ", "
10429 : "",
10430 afi_safi_print(afi,
10431 safi));
10432 eor_receive_af_count++;
10433 }
10434 }
10435 vty_out(vty, "\n");
10436 }
10437
10438 if (p->t_gr_restart)
10439 vty_out(vty,
10440 " The remaining time of restart timer is %ld\n",
10441 thread_timer_remain_second(
10442 p->t_gr_restart));
10443
10444 if (p->t_gr_stale)
10445 vty_out(vty,
10446 " The remaining time of stalepath timer is %ld\n",
10447 thread_timer_remain_second(
10448 p->t_gr_stale));
10449 }
10450 }
10451 if (use_json) {
10452 json_object *json_stat = NULL;
10453 json_stat = json_object_new_object();
10454 /* Packet counts. */
10455 json_object_int_add(json_stat, "depthInq", 0);
10456 json_object_int_add(json_stat, "depthOutq",
10457 (unsigned long)p->obuf->count);
10458 json_object_int_add(json_stat, "opensSent",
10459 atomic_load_explicit(&p->open_out,
10460 memory_order_relaxed));
10461 json_object_int_add(json_stat, "opensRecv",
10462 atomic_load_explicit(&p->open_in,
10463 memory_order_relaxed));
10464 json_object_int_add(json_stat, "notificationsSent",
10465 atomic_load_explicit(&p->notify_out,
10466 memory_order_relaxed));
10467 json_object_int_add(json_stat, "notificationsRecv",
10468 atomic_load_explicit(&p->notify_in,
10469 memory_order_relaxed));
10470 json_object_int_add(json_stat, "updatesSent",
10471 atomic_load_explicit(&p->update_out,
10472 memory_order_relaxed));
10473 json_object_int_add(json_stat, "updatesRecv",
10474 atomic_load_explicit(&p->update_in,
10475 memory_order_relaxed));
10476 json_object_int_add(json_stat, "keepalivesSent",
10477 atomic_load_explicit(&p->keepalive_out,
10478 memory_order_relaxed));
10479 json_object_int_add(json_stat, "keepalivesRecv",
10480 atomic_load_explicit(&p->keepalive_in,
10481 memory_order_relaxed));
10482 json_object_int_add(json_stat, "routeRefreshSent",
10483 atomic_load_explicit(&p->refresh_out,
10484 memory_order_relaxed));
10485 json_object_int_add(json_stat, "routeRefreshRecv",
10486 atomic_load_explicit(&p->refresh_in,
10487 memory_order_relaxed));
10488 json_object_int_add(json_stat, "capabilitySent",
10489 atomic_load_explicit(&p->dynamic_cap_out,
10490 memory_order_relaxed));
10491 json_object_int_add(json_stat, "capabilityRecv",
10492 atomic_load_explicit(&p->dynamic_cap_in,
10493 memory_order_relaxed));
10494 json_object_int_add(json_stat, "totalSent", PEER_TOTAL_TX(p));
10495 json_object_int_add(json_stat, "totalRecv", PEER_TOTAL_RX(p));
10496 json_object_object_add(json_neigh, "messageStats", json_stat);
10497 } else {
10498 /* Packet counts. */
10499 vty_out(vty, " Message statistics:\n");
10500 vty_out(vty, " Inq depth is 0\n");
10501 vty_out(vty, " Outq depth is %lu\n",
10502 (unsigned long)p->obuf->count);
10503 vty_out(vty, " Sent Rcvd\n");
10504 vty_out(vty, " Opens: %10d %10d\n",
10505 atomic_load_explicit(&p->open_out,
10506 memory_order_relaxed),
10507 atomic_load_explicit(&p->open_in,
10508 memory_order_relaxed));
10509 vty_out(vty, " Notifications: %10d %10d\n",
10510 atomic_load_explicit(&p->notify_out,
10511 memory_order_relaxed),
10512 atomic_load_explicit(&p->notify_in,
10513 memory_order_relaxed));
10514 vty_out(vty, " Updates: %10d %10d\n",
10515 atomic_load_explicit(&p->update_out,
10516 memory_order_relaxed),
10517 atomic_load_explicit(&p->update_in,
10518 memory_order_relaxed));
10519 vty_out(vty, " Keepalives: %10d %10d\n",
10520 atomic_load_explicit(&p->keepalive_out,
10521 memory_order_relaxed),
10522 atomic_load_explicit(&p->keepalive_in,
10523 memory_order_relaxed));
10524 vty_out(vty, " Route Refresh: %10d %10d\n",
10525 atomic_load_explicit(&p->refresh_out,
10526 memory_order_relaxed),
10527 atomic_load_explicit(&p->refresh_in,
10528 memory_order_relaxed));
10529 vty_out(vty, " Capability: %10d %10d\n",
10530 atomic_load_explicit(&p->dynamic_cap_out,
10531 memory_order_relaxed),
10532 atomic_load_explicit(&p->dynamic_cap_in,
10533 memory_order_relaxed));
10534 vty_out(vty, " Total: %10d %10d\n", PEER_TOTAL_TX(p),
10535 PEER_TOTAL_RX(p));
10536 }
10537
10538 if (use_json) {
10539 /* advertisement-interval */
10540 json_object_int_add(json_neigh,
10541 "minBtwnAdvertisementRunsTimerMsecs",
10542 p->v_routeadv * 1000);
10543
10544 /* Update-source. */
10545 if (p->update_if || p->update_source) {
10546 if (p->update_if)
10547 json_object_string_add(json_neigh,
10548 "updateSource",
10549 p->update_if);
10550 else if (p->update_source)
10551 json_object_string_add(
10552 json_neigh, "updateSource",
10553 sockunion2str(p->update_source, buf1,
10554 SU_ADDRSTRLEN));
10555 }
10556 } else {
10557 /* advertisement-interval */
10558 vty_out(vty,
10559 " Minimum time between advertisement runs is %d seconds\n",
10560 p->v_routeadv);
10561
10562 /* Update-source. */
10563 if (p->update_if || p->update_source) {
10564 vty_out(vty, " Update source is ");
10565 if (p->update_if)
10566 vty_out(vty, "%s", p->update_if);
10567 else if (p->update_source)
10568 vty_out(vty, "%s",
10569 sockunion2str(p->update_source, buf1,
10570 SU_ADDRSTRLEN));
10571 vty_out(vty, "\n");
10572 }
10573
10574 vty_out(vty, "\n");
10575 }
10576
10577 /* Address Family Information */
10578 json_object *json_hold = NULL;
10579
10580 if (use_json)
10581 json_hold = json_object_new_object();
10582
10583 FOREACH_AFI_SAFI (afi, safi)
10584 if (p->afc[afi][safi])
10585 bgp_show_peer_afi(vty, p, afi, safi, use_json,
10586 json_hold);
10587
10588 if (use_json) {
10589 json_object_object_add(json_neigh, "addressFamilyInfo",
10590 json_hold);
10591 json_object_int_add(json_neigh, "connectionsEstablished",
10592 p->established);
10593 json_object_int_add(json_neigh, "connectionsDropped",
10594 p->dropped);
10595 } else
10596 vty_out(vty, " Connections established %d; dropped %d\n",
10597 p->established, p->dropped);
10598
10599 if (!p->last_reset) {
10600 if (use_json)
10601 json_object_string_add(json_neigh, "lastReset",
10602 "never");
10603 else
10604 vty_out(vty, " Last reset never\n");
10605 } else {
10606 if (use_json) {
10607 time_t uptime;
10608 struct tm *tm;
10609
10610 uptime = bgp_clock();
10611 uptime -= p->resettime;
10612 tm = gmtime(&uptime);
10613 json_object_int_add(json_neigh, "lastResetTimerMsecs",
10614 (tm->tm_sec * 1000)
10615 + (tm->tm_min * 60000)
10616 + (tm->tm_hour * 3600000));
10617 json_object_string_add(
10618 json_neigh, "lastResetDueTo",
10619 peer_down_str[(int)p->last_reset]);
10620 if (p->last_reset == PEER_DOWN_NOTIFY_SEND
10621 || p->last_reset == PEER_DOWN_NOTIFY_RECEIVED) {
10622 char errorcodesubcode_hexstr[5];
10623 char errorcodesubcode_str[256];
10624
10625 code_str = bgp_notify_code_str(p->notify.code);
10626 subcode_str = bgp_notify_subcode_str(
10627 p->notify.code, p->notify.subcode);
10628
10629 sprintf(errorcodesubcode_hexstr, "%02X%02X",
10630 p->notify.code, p->notify.subcode);
10631 json_object_string_add(json_neigh,
10632 "lastErrorCodeSubcode",
10633 errorcodesubcode_hexstr);
10634 snprintf(errorcodesubcode_str, 255, "%s%s",
10635 code_str, subcode_str);
10636 json_object_string_add(json_neigh,
10637 "lastNotificationReason",
10638 errorcodesubcode_str);
10639 if (p->last_reset == PEER_DOWN_NOTIFY_RECEIVED
10640 && p->notify.code == BGP_NOTIFY_CEASE
10641 && (p->notify.subcode
10642 == BGP_NOTIFY_CEASE_ADMIN_SHUTDOWN
10643 || p->notify.subcode
10644 == BGP_NOTIFY_CEASE_ADMIN_RESET)
10645 && p->notify.length) {
10646 char msgbuf[1024];
10647 const char *msg_str;
10648
10649 msg_str = bgp_notify_admin_message(
10650 msgbuf, sizeof(msgbuf),
10651 (uint8_t *)p->notify.data,
10652 p->notify.length);
10653 if (msg_str)
10654 json_object_string_add(
10655 json_neigh,
10656 "lastShutdownDescription",
10657 msg_str);
10658 }
10659 }
10660 } else {
10661 vty_out(vty, " Last reset %s, ",
10662 peer_uptime(p->resettime, timebuf,
10663 BGP_UPTIME_LEN, 0, NULL));
10664
10665 if (p->last_reset == PEER_DOWN_NOTIFY_SEND
10666 || p->last_reset == PEER_DOWN_NOTIFY_RECEIVED) {
10667 code_str = bgp_notify_code_str(p->notify.code);
10668 subcode_str = bgp_notify_subcode_str(
10669 p->notify.code, p->notify.subcode);
10670 vty_out(vty, "due to NOTIFICATION %s (%s%s)\n",
10671 p->last_reset == PEER_DOWN_NOTIFY_SEND
10672 ? "sent"
10673 : "received",
10674 code_str, subcode_str);
10675 if (p->last_reset == PEER_DOWN_NOTIFY_RECEIVED
10676 && p->notify.code == BGP_NOTIFY_CEASE
10677 && (p->notify.subcode
10678 == BGP_NOTIFY_CEASE_ADMIN_SHUTDOWN
10679 || p->notify.subcode
10680 == BGP_NOTIFY_CEASE_ADMIN_RESET)
10681 && p->notify.length) {
10682 char msgbuf[1024];
10683 const char *msg_str;
10684
10685 msg_str = bgp_notify_admin_message(
10686 msgbuf, sizeof(msgbuf),
10687 (uint8_t *)p->notify.data,
10688 p->notify.length);
10689 if (msg_str)
10690 vty_out(vty,
10691 " Message: \"%s\"\n",
10692 msg_str);
10693 }
10694 } else {
10695 vty_out(vty, "due to %s\n",
10696 peer_down_str[(int)p->last_reset]);
10697 }
10698
10699 if (p->last_reset_cause_size) {
10700 msg = p->last_reset_cause;
10701 vty_out(vty,
10702 " Message received that caused BGP to send a NOTIFICATION:\n ");
10703 for (i = 1; i <= p->last_reset_cause_size;
10704 i++) {
10705 vty_out(vty, "%02X", *msg++);
10706
10707 if (i != p->last_reset_cause_size) {
10708 if (i % 16 == 0) {
10709 vty_out(vty, "\n ");
10710 } else if (i % 4 == 0) {
10711 vty_out(vty, " ");
10712 }
10713 }
10714 }
10715 vty_out(vty, "\n");
10716 }
10717 }
10718 }
10719
10720 if (CHECK_FLAG(p->sflags, PEER_STATUS_PREFIX_OVERFLOW)) {
10721 if (use_json)
10722 json_object_boolean_true_add(json_neigh,
10723 "prefixesConfigExceedMax");
10724 else
10725 vty_out(vty,
10726 " Peer had exceeded the max. no. of prefixes configured.\n");
10727
10728 if (p->t_pmax_restart) {
10729 if (use_json) {
10730 json_object_boolean_true_add(
10731 json_neigh, "reducePrefixNumFrom");
10732 json_object_int_add(json_neigh,
10733 "restartInTimerMsec",
10734 thread_timer_remain_second(
10735 p->t_pmax_restart)
10736 * 1000);
10737 } else
10738 vty_out(vty,
10739 " Reduce the no. of prefix from %s, will restart in %ld seconds\n",
10740 p->host, thread_timer_remain_second(
10741 p->t_pmax_restart));
10742 } else {
10743 if (use_json)
10744 json_object_boolean_true_add(
10745 json_neigh,
10746 "reducePrefixNumAndClearIpBgp");
10747 else
10748 vty_out(vty,
10749 " Reduce the no. of prefix and clear ip bgp %s to restore peering\n",
10750 p->host);
10751 }
10752 }
10753
10754 /* EBGP Multihop and GTSM */
10755 if (p->sort != BGP_PEER_IBGP) {
10756 if (use_json) {
10757 if (p->gtsm_hops > 0)
10758 json_object_int_add(json_neigh,
10759 "externalBgpNbrMaxHopsAway",
10760 p->gtsm_hops);
10761 else if (p->ttl > 1)
10762 json_object_int_add(json_neigh,
10763 "externalBgpNbrMaxHopsAway",
10764 p->ttl);
10765 } else {
10766 if (p->gtsm_hops > 0)
10767 vty_out(vty,
10768 " External BGP neighbor may be up to %d hops away.\n",
10769 p->gtsm_hops);
10770 else if (p->ttl > 1)
10771 vty_out(vty,
10772 " External BGP neighbor may be up to %d hops away.\n",
10773 p->ttl);
10774 }
10775 } else {
10776 if (p->gtsm_hops > 0) {
10777 if (use_json)
10778 json_object_int_add(json_neigh,
10779 "internalBgpNbrMaxHopsAway",
10780 p->gtsm_hops);
10781 else
10782 vty_out(vty,
10783 " Internal BGP neighbor may be up to %d hops away.\n",
10784 p->gtsm_hops);
10785 }
10786 }
10787
10788 /* Local address. */
10789 if (p->su_local) {
10790 if (use_json) {
10791 json_object_string_add(json_neigh, "hostLocal",
10792 sockunion2str(p->su_local, buf1,
10793 SU_ADDRSTRLEN));
10794 json_object_int_add(json_neigh, "portLocal",
10795 ntohs(p->su_local->sin.sin_port));
10796 } else
10797 vty_out(vty, "Local host: %s, Local port: %d\n",
10798 sockunion2str(p->su_local, buf1, SU_ADDRSTRLEN),
10799 ntohs(p->su_local->sin.sin_port));
10800 }
10801
10802 /* Remote address. */
10803 if (p->su_remote) {
10804 if (use_json) {
10805 json_object_string_add(json_neigh, "hostForeign",
10806 sockunion2str(p->su_remote, buf1,
10807 SU_ADDRSTRLEN));
10808 json_object_int_add(json_neigh, "portForeign",
10809 ntohs(p->su_remote->sin.sin_port));
10810 } else
10811 vty_out(vty, "Foreign host: %s, Foreign port: %d\n",
10812 sockunion2str(p->su_remote, buf1,
10813 SU_ADDRSTRLEN),
10814 ntohs(p->su_remote->sin.sin_port));
10815 }
10816
10817 /* Nexthop display. */
10818 if (p->su_local) {
10819 if (use_json) {
10820 json_object_string_add(json_neigh, "nexthop",
10821 inet_ntop(AF_INET,
10822 &p->nexthop.v4, buf1,
10823 sizeof(buf1)));
10824 json_object_string_add(json_neigh, "nexthopGlobal",
10825 inet_ntop(AF_INET6,
10826 &p->nexthop.v6_global,
10827 buf1, sizeof(buf1)));
10828 json_object_string_add(json_neigh, "nexthopLocal",
10829 inet_ntop(AF_INET6,
10830 &p->nexthop.v6_local,
10831 buf1, sizeof(buf1)));
10832 if (p->shared_network)
10833 json_object_string_add(json_neigh,
10834 "bgpConnection",
10835 "sharedNetwork");
10836 else
10837 json_object_string_add(json_neigh,
10838 "bgpConnection",
10839 "nonSharedNetwork");
10840 } else {
10841 vty_out(vty, "Nexthop: %s\n",
10842 inet_ntop(AF_INET, &p->nexthop.v4, buf1,
10843 sizeof(buf1)));
10844 vty_out(vty, "Nexthop global: %s\n",
10845 inet_ntop(AF_INET6, &p->nexthop.v6_global, buf1,
10846 sizeof(buf1)));
10847 vty_out(vty, "Nexthop local: %s\n",
10848 inet_ntop(AF_INET6, &p->nexthop.v6_local, buf1,
10849 sizeof(buf1)));
10850 vty_out(vty, "BGP connection: %s\n",
10851 p->shared_network ? "shared network"
10852 : "non shared network");
10853 }
10854 }
10855
10856 /* Timer information. */
10857 if (use_json) {
10858 json_object_int_add(json_neigh, "connectRetryTimer",
10859 p->v_connect);
10860 if (p->status == Established && p->rtt)
10861 json_object_int_add(json_neigh, "estimatedRttInMsecs",
10862 p->rtt);
10863 if (p->t_start)
10864 json_object_int_add(
10865 json_neigh, "nextStartTimerDueInMsecs",
10866 thread_timer_remain_second(p->t_start) * 1000);
10867 if (p->t_connect)
10868 json_object_int_add(
10869 json_neigh, "nextConnectTimerDueInMsecs",
10870 thread_timer_remain_second(p->t_connect)
10871 * 1000);
10872 if (p->t_routeadv) {
10873 json_object_int_add(json_neigh, "mraiInterval",
10874 p->v_routeadv);
10875 json_object_int_add(
10876 json_neigh, "mraiTimerExpireInMsecs",
10877 thread_timer_remain_second(p->t_routeadv)
10878 * 1000);
10879 }
10880 if (p->password)
10881 json_object_int_add(json_neigh, "authenticationEnabled",
10882 1);
10883
10884 if (p->t_read)
10885 json_object_string_add(json_neigh, "readThread", "on");
10886 else
10887 json_object_string_add(json_neigh, "readThread", "off");
10888
10889 if (CHECK_FLAG(p->thread_flags, PEER_THREAD_WRITES_ON))
10890 json_object_string_add(json_neigh, "writeThread", "on");
10891 else
10892 json_object_string_add(json_neigh, "writeThread",
10893 "off");
10894 } else {
10895 vty_out(vty, "BGP Connect Retry Timer in Seconds: %d\n",
10896 p->v_connect);
10897 if (p->status == Established && p->rtt)
10898 vty_out(vty, "Estimated round trip time: %d ms\n",
10899 p->rtt);
10900 if (p->t_start)
10901 vty_out(vty, "Next start timer due in %ld seconds\n",
10902 thread_timer_remain_second(p->t_start));
10903 if (p->t_connect)
10904 vty_out(vty, "Next connect timer due in %ld seconds\n",
10905 thread_timer_remain_second(p->t_connect));
10906 if (p->t_routeadv)
10907 vty_out(vty,
10908 "MRAI (interval %u) timer expires in %ld seconds\n",
10909 p->v_routeadv,
10910 thread_timer_remain_second(p->t_routeadv));
10911 if (p->password)
10912 vty_out(vty, "Peer Authentication Enabled\n");
10913
10914 vty_out(vty, "Read thread: %s Write thread: %s\n",
10915 p->t_read ? "on" : "off",
10916 CHECK_FLAG(p->thread_flags, PEER_THREAD_WRITES_ON)
10917 ? "on"
10918 : "off");
10919 }
10920
10921 if (p->notify.code == BGP_NOTIFY_OPEN_ERR
10922 && p->notify.subcode == BGP_NOTIFY_OPEN_UNSUP_CAPBL)
10923 bgp_capability_vty_out(vty, p, use_json, json_neigh);
10924
10925 if (!use_json)
10926 vty_out(vty, "\n");
10927
10928 /* BFD information. */
10929 bgp_bfd_show_info(vty, p, use_json, json_neigh);
10930
10931 if (use_json) {
10932 if (p->conf_if) /* Configured interface name. */
10933 json_object_object_add(json, p->conf_if, json_neigh);
10934 else /* Configured IP address. */
10935 json_object_object_add(json, p->host, json_neigh);
10936 }
10937 }
10938
10939 static int bgp_show_neighbor(struct vty *vty, struct bgp *bgp,
10940 enum show_type type, union sockunion *su,
10941 const char *conf_if, bool use_json,
10942 json_object *json)
10943 {
10944 struct listnode *node, *nnode;
10945 struct peer *peer;
10946 int find = 0;
10947 bool nbr_output = false;
10948 afi_t afi = AFI_MAX;
10949 safi_t safi = SAFI_MAX;
10950
10951 if (type == show_ipv4_peer || type == show_ipv4_all) {
10952 afi = AFI_IP;
10953 } else if (type == show_ipv6_peer || type == show_ipv6_all) {
10954 afi = AFI_IP6;
10955 }
10956
10957 for (ALL_LIST_ELEMENTS(bgp->peer, node, nnode, peer)) {
10958 if (!CHECK_FLAG(peer->flags, PEER_FLAG_CONFIG_NODE))
10959 continue;
10960
10961 switch (type) {
10962 case show_all:
10963 bgp_show_peer(vty, peer, use_json, json);
10964 nbr_output = true;
10965 break;
10966 case show_peer:
10967 if (conf_if) {
10968 if ((peer->conf_if
10969 && !strcmp(peer->conf_if, conf_if))
10970 || (peer->hostname
10971 && !strcmp(peer->hostname, conf_if))) {
10972 find = 1;
10973 bgp_show_peer(vty, peer, use_json,
10974 json);
10975 }
10976 } else {
10977 if (sockunion_same(&peer->su, su)) {
10978 find = 1;
10979 bgp_show_peer(vty, peer, use_json,
10980 json);
10981 }
10982 }
10983 break;
10984 case show_ipv4_peer:
10985 case show_ipv6_peer:
10986 FOREACH_SAFI (safi) {
10987 if (peer->afc[afi][safi]) {
10988 if (conf_if) {
10989 if ((peer->conf_if
10990 && !strcmp(peer->conf_if, conf_if))
10991 || (peer->hostname
10992 && !strcmp(peer->hostname, conf_if))) {
10993 find = 1;
10994 bgp_show_peer(vty, peer, use_json,
10995 json);
10996 break;
10997 }
10998 } else {
10999 if (sockunion_same(&peer->su, su)) {
11000 find = 1;
11001 bgp_show_peer(vty, peer, use_json,
11002 json);
11003 break;
11004 }
11005 }
11006 }
11007 }
11008 break;
11009 case show_ipv4_all:
11010 case show_ipv6_all:
11011 FOREACH_SAFI (safi) {
11012 if (peer->afc[afi][safi]) {
11013 bgp_show_peer(vty, peer, use_json, json);
11014 nbr_output = true;
11015 break;
11016 }
11017 }
11018 break;
11019 }
11020 }
11021
11022 if ((type == show_peer || type == show_ipv4_peer ||
11023 type == show_ipv6_peer) && !find) {
11024 if (use_json)
11025 json_object_boolean_true_add(json, "bgpNoSuchNeighbor");
11026 else
11027 vty_out(vty, "%% No such neighbor in this view/vrf\n");
11028 }
11029
11030 if (type != show_peer && type != show_ipv4_peer &&
11031 type != show_ipv6_peer && !nbr_output && !use_json)
11032 vty_out(vty, "%% No BGP neighbors found\n");
11033
11034 if (use_json) {
11035 vty_out(vty, "%s\n", json_object_to_json_string_ext(
11036 json, JSON_C_TO_STRING_PRETTY));
11037 } else {
11038 vty_out(vty, "\n");
11039 }
11040
11041 return CMD_SUCCESS;
11042 }
11043
11044 static void bgp_show_all_instances_neighbors_vty(struct vty *vty,
11045 enum show_type type,
11046 const char *ip_str,
11047 bool use_json)
11048 {
11049 struct listnode *node, *nnode;
11050 struct bgp *bgp;
11051 union sockunion su;
11052 json_object *json = NULL;
11053 int ret, is_first = 1;
11054 bool nbr_output = false;
11055
11056 if (use_json)
11057 vty_out(vty, "{\n");
11058
11059 for (ALL_LIST_ELEMENTS(bm->bgp, node, nnode, bgp)) {
11060 nbr_output = true;
11061 if (use_json) {
11062 if (!(json = json_object_new_object())) {
11063 flog_err(
11064 EC_BGP_JSON_MEM_ERROR,
11065 "Unable to allocate memory for JSON object");
11066 vty_out(vty,
11067 "{\"error\": {\"message:\": \"Unable to allocate memory for JSON object\"}}}\n");
11068 return;
11069 }
11070
11071 json_object_int_add(json, "vrfId",
11072 (bgp->vrf_id == VRF_UNKNOWN)
11073 ? -1
11074 : (int64_t)bgp->vrf_id);
11075 json_object_string_add(
11076 json, "vrfName",
11077 (bgp->inst_type == BGP_INSTANCE_TYPE_DEFAULT)
11078 ? VRF_DEFAULT_NAME
11079 : bgp->name);
11080
11081 if (!is_first)
11082 vty_out(vty, ",\n");
11083 else
11084 is_first = 0;
11085
11086 vty_out(vty, "\"%s\":",
11087 (bgp->inst_type == BGP_INSTANCE_TYPE_DEFAULT)
11088 ? VRF_DEFAULT_NAME
11089 : bgp->name);
11090 } else {
11091 vty_out(vty, "\nInstance %s:\n",
11092 (bgp->inst_type == BGP_INSTANCE_TYPE_DEFAULT)
11093 ? VRF_DEFAULT_NAME
11094 : bgp->name);
11095 }
11096
11097 if (type == show_peer || type == show_ipv4_peer ||
11098 type == show_ipv6_peer) {
11099 ret = str2sockunion(ip_str, &su);
11100 if (ret < 0)
11101 bgp_show_neighbor(vty, bgp, type, NULL, ip_str,
11102 use_json, json);
11103 else
11104 bgp_show_neighbor(vty, bgp, type, &su, NULL,
11105 use_json, json);
11106 } else {
11107 bgp_show_neighbor(vty, bgp, type, NULL, NULL,
11108 use_json, json);
11109 }
11110 json_object_free(json);
11111 }
11112
11113 if (use_json) {
11114 vty_out(vty, "}\n");
11115 json_object_free(json);
11116 }
11117 else if (!nbr_output)
11118 vty_out(vty, "%% BGP instance not found\n");
11119 }
11120
11121 static int bgp_show_neighbor_vty(struct vty *vty, const char *name,
11122 enum show_type type, const char *ip_str,
11123 bool use_json)
11124 {
11125 int ret;
11126 struct bgp *bgp;
11127 union sockunion su;
11128 json_object *json = NULL;
11129
11130 if (name) {
11131 if (strmatch(name, "all")) {
11132 bgp_show_all_instances_neighbors_vty(vty, type, ip_str,
11133 use_json);
11134 return CMD_SUCCESS;
11135 } else {
11136 bgp = bgp_lookup_by_name(name);
11137 if (!bgp) {
11138 if (use_json) {
11139 json = json_object_new_object();
11140 vty_out(vty, "%s\n",
11141 json_object_to_json_string_ext(
11142 json,
11143 JSON_C_TO_STRING_PRETTY));
11144 json_object_free(json);
11145 } else
11146 vty_out(vty,
11147 "%% BGP instance not found\n");
11148
11149 return CMD_WARNING;
11150 }
11151 }
11152 } else {
11153 bgp = bgp_get_default();
11154 }
11155
11156 if (bgp) {
11157 json = json_object_new_object();
11158 if (ip_str) {
11159 ret = str2sockunion(ip_str, &su);
11160 if (ret < 0)
11161 bgp_show_neighbor(vty, bgp, type, NULL, ip_str,
11162 use_json, json);
11163 else
11164 bgp_show_neighbor(vty, bgp, type, &su, NULL,
11165 use_json, json);
11166 } else {
11167 bgp_show_neighbor(vty, bgp, type, NULL, NULL, use_json,
11168 json);
11169 }
11170 json_object_free(json);
11171 } else {
11172 if (use_json)
11173 vty_out(vty, "{}\n");
11174 else
11175 vty_out(vty, "%% BGP instance not found\n");
11176 }
11177
11178 return CMD_SUCCESS;
11179 }
11180
11181 /* "show [ip] bgp neighbors" commands. */
11182 DEFUN (show_ip_bgp_neighbors,
11183 show_ip_bgp_neighbors_cmd,
11184 "show [ip] bgp [<view|vrf> VIEWVRFNAME] [<ipv4|ipv6>] neighbors [<A.B.C.D|X:X::X:X|WORD>] [json]",
11185 SHOW_STR
11186 IP_STR
11187 BGP_STR
11188 BGP_INSTANCE_HELP_STR
11189 "Address Family\n"
11190 "Address Family\n"
11191 "Detailed information on TCP and BGP neighbor connections\n"
11192 "Neighbor to display information about\n"
11193 "Neighbor to display information about\n"
11194 "Neighbor on BGP configured interface\n"
11195 JSON_STR)
11196 {
11197 char *vrf = NULL;
11198 char *sh_arg = NULL;
11199 enum show_type sh_type;
11200 afi_t afi = AFI_MAX;
11201
11202 bool uj = use_json(argc, argv);
11203
11204 int idx = 0;
11205
11206 /* [<vrf> VIEWVRFNAME] */
11207 if (argv_find(argv, argc, "vrf", &idx)) {
11208 vrf = argv[idx + 1]->arg;
11209 if (vrf && strmatch(vrf, VRF_DEFAULT_NAME))
11210 vrf = NULL;
11211 } else if (argv_find(argv, argc, "view", &idx))
11212 /* [<view> VIEWVRFNAME] */
11213 vrf = argv[idx + 1]->arg;
11214
11215 idx++;
11216
11217 if (argv_find(argv, argc, "ipv4", &idx)) {
11218 sh_type = show_ipv4_all;
11219 afi = AFI_IP;
11220 } else if (argv_find(argv, argc, "ipv6", &idx)) {
11221 sh_type = show_ipv6_all;
11222 afi = AFI_IP6;
11223 } else {
11224 sh_type = show_all;
11225 }
11226
11227 if (argv_find(argv, argc, "A.B.C.D", &idx)
11228 || argv_find(argv, argc, "X:X::X:X", &idx)
11229 || argv_find(argv, argc, "WORD", &idx)) {
11230 sh_type = show_peer;
11231 sh_arg = argv[idx]->arg;
11232 }
11233
11234 if (sh_type == show_peer && afi == AFI_IP) {
11235 sh_type = show_ipv4_peer;
11236 } else if (sh_type == show_peer && afi == AFI_IP6) {
11237 sh_type = show_ipv6_peer;
11238 }
11239
11240 return bgp_show_neighbor_vty(vty, vrf, sh_type, sh_arg, uj);
11241 }
11242
11243 /* Show BGP's AS paths internal data. There are both `show [ip] bgp
11244 paths' and `show ip mbgp paths'. Those functions results are the
11245 same.*/
11246 DEFUN (show_ip_bgp_paths,
11247 show_ip_bgp_paths_cmd,
11248 "show [ip] bgp ["BGP_SAFI_CMD_STR"] paths",
11249 SHOW_STR
11250 IP_STR
11251 BGP_STR
11252 BGP_SAFI_HELP_STR
11253 "Path information\n")
11254 {
11255 vty_out(vty, "Address Refcnt Path\n");
11256 aspath_print_all_vty(vty);
11257 return CMD_SUCCESS;
11258 }
11259
11260 #include "hash.h"
11261
11262 static void community_show_all_iterator(struct hash_bucket *bucket,
11263 struct vty *vty)
11264 {
11265 struct community *com;
11266
11267 com = (struct community *)bucket->data;
11268 vty_out(vty, "[%p] (%ld) %s\n", (void *)com, com->refcnt,
11269 community_str(com, false));
11270 }
11271
11272 /* Show BGP's community internal data. */
11273 DEFUN (show_ip_bgp_community_info,
11274 show_ip_bgp_community_info_cmd,
11275 "show [ip] bgp community-info",
11276 SHOW_STR
11277 IP_STR
11278 BGP_STR
11279 "List all bgp community information\n")
11280 {
11281 vty_out(vty, "Address Refcnt Community\n");
11282
11283 hash_iterate(community_hash(),
11284 (void (*)(struct hash_bucket *,
11285 void *))community_show_all_iterator,
11286 vty);
11287
11288 return CMD_SUCCESS;
11289 }
11290
11291 static void lcommunity_show_all_iterator(struct hash_bucket *bucket,
11292 struct vty *vty)
11293 {
11294 struct lcommunity *lcom;
11295
11296 lcom = (struct lcommunity *)bucket->data;
11297 vty_out(vty, "[%p] (%ld) %s\n", (void *)lcom, lcom->refcnt,
11298 lcommunity_str(lcom, false));
11299 }
11300
11301 /* Show BGP's community internal data. */
11302 DEFUN (show_ip_bgp_lcommunity_info,
11303 show_ip_bgp_lcommunity_info_cmd,
11304 "show ip bgp large-community-info",
11305 SHOW_STR
11306 IP_STR
11307 BGP_STR
11308 "List all bgp large-community information\n")
11309 {
11310 vty_out(vty, "Address Refcnt Large-community\n");
11311
11312 hash_iterate(lcommunity_hash(),
11313 (void (*)(struct hash_bucket *,
11314 void *))lcommunity_show_all_iterator,
11315 vty);
11316
11317 return CMD_SUCCESS;
11318 }
11319
11320
11321 DEFUN (show_ip_bgp_attr_info,
11322 show_ip_bgp_attr_info_cmd,
11323 "show [ip] bgp attribute-info",
11324 SHOW_STR
11325 IP_STR
11326 BGP_STR
11327 "List all bgp attribute information\n")
11328 {
11329 attr_show_all(vty);
11330 return CMD_SUCCESS;
11331 }
11332
11333 static int bgp_show_route_leak_vty(struct vty *vty, const char *name,
11334 afi_t afi, safi_t safi,
11335 bool use_json, json_object *json)
11336 {
11337 struct bgp *bgp;
11338 struct listnode *node;
11339 char *vname;
11340 char buf1[INET6_ADDRSTRLEN];
11341 char *ecom_str;
11342 vpn_policy_direction_t dir;
11343
11344 if (json) {
11345 json_object *json_import_vrfs = NULL;
11346 json_object *json_export_vrfs = NULL;
11347
11348 bgp = name ? bgp_lookup_by_name(name) : bgp_get_default();
11349
11350 if (!bgp) {
11351 vty_out(vty, "%s\n",
11352 json_object_to_json_string_ext(
11353 json,
11354 JSON_C_TO_STRING_PRETTY));
11355 json_object_free(json);
11356
11357 return CMD_WARNING;
11358 }
11359
11360 /* Provide context for the block */
11361 json_object_string_add(json, "vrf", name ? name : "default");
11362 json_object_string_add(json, "afiSafi",
11363 afi_safi_print(afi, safi));
11364
11365 if (!CHECK_FLAG(bgp->af_flags[afi][safi],
11366 BGP_CONFIG_VRF_TO_VRF_IMPORT)) {
11367 json_object_string_add(json, "importFromVrfs", "none");
11368 json_object_string_add(json, "importRts", "none");
11369 } else {
11370 json_import_vrfs = json_object_new_array();
11371
11372 for (ALL_LIST_ELEMENTS_RO(
11373 bgp->vpn_policy[afi].import_vrf,
11374 node, vname))
11375 json_object_array_add(json_import_vrfs,
11376 json_object_new_string(vname));
11377
11378 dir = BGP_VPN_POLICY_DIR_FROMVPN;
11379 ecom_str = ecommunity_ecom2str(
11380 bgp->vpn_policy[afi].rtlist[dir],
11381 ECOMMUNITY_FORMAT_ROUTE_MAP, 0);
11382 json_object_object_add(json, "importFromVrfs",
11383 json_import_vrfs);
11384 json_object_string_add(json, "importRts", ecom_str);
11385
11386 XFREE(MTYPE_ECOMMUNITY_STR, ecom_str);
11387 }
11388
11389 if (!CHECK_FLAG(bgp->af_flags[afi][safi],
11390 BGP_CONFIG_VRF_TO_VRF_EXPORT)) {
11391 json_object_string_add(json, "exportToVrfs", "none");
11392 json_object_string_add(json, "routeDistinguisher",
11393 "none");
11394 json_object_string_add(json, "exportRts", "none");
11395 } else {
11396 json_export_vrfs = json_object_new_array();
11397
11398 for (ALL_LIST_ELEMENTS_RO(
11399 bgp->vpn_policy[afi].export_vrf,
11400 node, vname))
11401 json_object_array_add(json_export_vrfs,
11402 json_object_new_string(vname));
11403 json_object_object_add(json, "exportToVrfs",
11404 json_export_vrfs);
11405 json_object_string_add(json, "routeDistinguisher",
11406 prefix_rd2str(&bgp->vpn_policy[afi].tovpn_rd,
11407 buf1, RD_ADDRSTRLEN));
11408
11409 dir = BGP_VPN_POLICY_DIR_TOVPN;
11410 ecom_str = ecommunity_ecom2str(
11411 bgp->vpn_policy[afi].rtlist[dir],
11412 ECOMMUNITY_FORMAT_ROUTE_MAP, 0);
11413 json_object_string_add(json, "exportRts", ecom_str);
11414
11415 XFREE(MTYPE_ECOMMUNITY_STR, ecom_str);
11416 }
11417
11418 if (use_json) {
11419 vty_out(vty, "%s\n",
11420 json_object_to_json_string_ext(json,
11421 JSON_C_TO_STRING_PRETTY));
11422 json_object_free(json);
11423 }
11424 } else {
11425 bgp = name ? bgp_lookup_by_name(name) : bgp_get_default();
11426
11427 if (!bgp) {
11428 vty_out(vty, "%% No such BGP instance exist\n");
11429 return CMD_WARNING;
11430 }
11431
11432 if (!CHECK_FLAG(bgp->af_flags[afi][safi],
11433 BGP_CONFIG_VRF_TO_VRF_IMPORT))
11434 vty_out(vty,
11435 "This VRF is not importing %s routes from any other VRF\n",
11436 afi_safi_print(afi, safi));
11437 else {
11438 vty_out(vty,
11439 "This VRF is importing %s routes from the following VRFs:\n",
11440 afi_safi_print(afi, safi));
11441
11442 for (ALL_LIST_ELEMENTS_RO(
11443 bgp->vpn_policy[afi].import_vrf,
11444 node, vname))
11445 vty_out(vty, " %s\n", vname);
11446
11447 dir = BGP_VPN_POLICY_DIR_FROMVPN;
11448 ecom_str = ecommunity_ecom2str(
11449 bgp->vpn_policy[afi].rtlist[dir],
11450 ECOMMUNITY_FORMAT_ROUTE_MAP, 0);
11451 vty_out(vty, "Import RT(s): %s\n", ecom_str);
11452
11453 XFREE(MTYPE_ECOMMUNITY_STR, ecom_str);
11454 }
11455
11456 if (!CHECK_FLAG(bgp->af_flags[afi][safi],
11457 BGP_CONFIG_VRF_TO_VRF_EXPORT))
11458 vty_out(vty,
11459 "This VRF is not exporting %s routes to any other VRF\n",
11460 afi_safi_print(afi, safi));
11461 else {
11462 vty_out(vty,
11463 "This VRF is exporting %s routes to the following VRFs:\n",
11464 afi_safi_print(afi, safi));
11465
11466 for (ALL_LIST_ELEMENTS_RO(
11467 bgp->vpn_policy[afi].export_vrf,
11468 node, vname))
11469 vty_out(vty, " %s\n", vname);
11470
11471 vty_out(vty, "RD: %s\n",
11472 prefix_rd2str(&bgp->vpn_policy[afi].tovpn_rd,
11473 buf1, RD_ADDRSTRLEN));
11474
11475 dir = BGP_VPN_POLICY_DIR_TOVPN;
11476 ecom_str = ecommunity_ecom2str(
11477 bgp->vpn_policy[afi].rtlist[dir],
11478 ECOMMUNITY_FORMAT_ROUTE_MAP, 0);
11479 vty_out(vty, "Export RT: %s\n", ecom_str);
11480 XFREE(MTYPE_ECOMMUNITY_STR, ecom_str);
11481 }
11482 }
11483
11484 return CMD_SUCCESS;
11485 }
11486
11487 static int bgp_show_all_instance_route_leak_vty(struct vty *vty, afi_t afi,
11488 safi_t safi, bool use_json)
11489 {
11490 struct listnode *node, *nnode;
11491 struct bgp *bgp;
11492 char *vrf_name = NULL;
11493 json_object *json = NULL;
11494 json_object *json_vrf = NULL;
11495 json_object *json_vrfs = NULL;
11496
11497 if (use_json) {
11498 json = json_object_new_object();
11499 json_vrfs = json_object_new_object();
11500 }
11501
11502 for (ALL_LIST_ELEMENTS(bm->bgp, node, nnode, bgp)) {
11503
11504 if (bgp->inst_type != BGP_INSTANCE_TYPE_DEFAULT)
11505 vrf_name = bgp->name;
11506
11507 if (use_json) {
11508 json_vrf = json_object_new_object();
11509 } else {
11510 vty_out(vty, "\nInstance %s:\n",
11511 (bgp->inst_type == BGP_INSTANCE_TYPE_DEFAULT)
11512 ? VRF_DEFAULT_NAME : bgp->name);
11513 }
11514 bgp_show_route_leak_vty(vty, vrf_name, afi, safi, 0, json_vrf);
11515 if (use_json) {
11516 if (bgp->inst_type == BGP_INSTANCE_TYPE_DEFAULT)
11517 json_object_object_add(json_vrfs,
11518 VRF_DEFAULT_NAME, json_vrf);
11519 else
11520 json_object_object_add(json_vrfs, vrf_name,
11521 json_vrf);
11522 }
11523 }
11524
11525 if (use_json) {
11526 json_object_object_add(json, "vrfs", json_vrfs);
11527 vty_out(vty, "%s\n", json_object_to_json_string_ext(json,
11528 JSON_C_TO_STRING_PRETTY));
11529 json_object_free(json);
11530 }
11531
11532 return CMD_SUCCESS;
11533 }
11534
11535 /* "show [ip] bgp route-leak" command. */
11536 DEFUN (show_ip_bgp_route_leak,
11537 show_ip_bgp_route_leak_cmd,
11538 "show [ip] bgp [<view|vrf> VIEWVRFNAME] ["BGP_AFI_CMD_STR" ["BGP_SAFI_CMD_STR"]] route-leak [json]",
11539 SHOW_STR
11540 IP_STR
11541 BGP_STR
11542 BGP_INSTANCE_HELP_STR
11543 BGP_AFI_HELP_STR
11544 BGP_SAFI_HELP_STR
11545 "Route leaking information\n"
11546 JSON_STR)
11547 {
11548 char *vrf = NULL;
11549 afi_t afi = AFI_MAX;
11550 safi_t safi = SAFI_MAX;
11551
11552 bool uj = use_json(argc, argv);
11553 int idx = 0;
11554 json_object *json = NULL;
11555
11556 /* show [ip] bgp */
11557 if (argv_find(argv, argc, "ip", &idx)) {
11558 afi = AFI_IP;
11559 safi = SAFI_UNICAST;
11560 }
11561 /* [vrf VIEWVRFNAME] */
11562 if (argv_find(argv, argc, "view", &idx)) {
11563 vty_out(vty,
11564 "%% This command is not applicable to BGP views\n");
11565 return CMD_WARNING;
11566 }
11567
11568 if (argv_find(argv, argc, "vrf", &idx)) {
11569 vrf = argv[idx + 1]->arg;
11570 if (vrf && strmatch(vrf, VRF_DEFAULT_NAME))
11571 vrf = NULL;
11572 }
11573 /* ["BGP_AFI_CMD_STR" ["BGP_SAFI_CMD_STR"]] */
11574 if (argv_find_and_parse_afi(argv, argc, &idx, &afi)) {
11575 argv_find_and_parse_safi(argv, argc, &idx, &safi);
11576 }
11577
11578 if (!((afi == AFI_IP || afi == AFI_IP6) && safi == SAFI_UNICAST)) {
11579 vty_out(vty,
11580 "%% This command is applicable only for unicast ipv4|ipv6\n");
11581 return CMD_WARNING;
11582 }
11583
11584 if (vrf && strmatch(vrf, "all"))
11585 return bgp_show_all_instance_route_leak_vty(vty, afi, safi, uj);
11586
11587 if (uj)
11588 json = json_object_new_object();
11589
11590 return bgp_show_route_leak_vty(vty, vrf, afi, safi, uj, json);
11591 }
11592
11593 static void bgp_show_all_instances_updgrps_vty(struct vty *vty, afi_t afi,
11594 safi_t safi)
11595 {
11596 struct listnode *node, *nnode;
11597 struct bgp *bgp;
11598
11599 for (ALL_LIST_ELEMENTS(bm->bgp, node, nnode, bgp)) {
11600 vty_out(vty, "\nInstance %s:\n",
11601 (bgp->inst_type == BGP_INSTANCE_TYPE_DEFAULT)
11602 ? VRF_DEFAULT_NAME
11603 : bgp->name);
11604 update_group_show(bgp, afi, safi, vty, 0);
11605 }
11606 }
11607
11608 static int bgp_show_update_groups(struct vty *vty, const char *name, int afi,
11609 int safi, uint64_t subgrp_id)
11610 {
11611 struct bgp *bgp;
11612
11613 if (name) {
11614 if (strmatch(name, "all")) {
11615 bgp_show_all_instances_updgrps_vty(vty, afi, safi);
11616 return CMD_SUCCESS;
11617 } else {
11618 bgp = bgp_lookup_by_name(name);
11619 }
11620 } else {
11621 bgp = bgp_get_default();
11622 }
11623
11624 if (bgp)
11625 update_group_show(bgp, afi, safi, vty, subgrp_id);
11626 return CMD_SUCCESS;
11627 }
11628
11629 DEFUN (show_ip_bgp_updgrps,
11630 show_ip_bgp_updgrps_cmd,
11631 "show [ip] bgp [<view|vrf> VIEWVRFNAME] ["BGP_AFI_CMD_STR" ["BGP_SAFI_WITH_LABEL_CMD_STR"]] update-groups [SUBGROUP-ID]",
11632 SHOW_STR
11633 IP_STR
11634 BGP_STR
11635 BGP_INSTANCE_HELP_STR
11636 BGP_AFI_HELP_STR
11637 BGP_SAFI_WITH_LABEL_HELP_STR
11638 "Detailed info about dynamic update groups\n"
11639 "Specific subgroup to display detailed info for\n")
11640 {
11641 char *vrf = NULL;
11642 afi_t afi = AFI_IP6;
11643 safi_t safi = SAFI_UNICAST;
11644 uint64_t subgrp_id = 0;
11645
11646 int idx = 0;
11647
11648 /* show [ip] bgp */
11649 if (argv_find(argv, argc, "ip", &idx))
11650 afi = AFI_IP;
11651 /* [<vrf> VIEWVRFNAME] */
11652 if (argv_find(argv, argc, "vrf", &idx)) {
11653 vrf = argv[idx + 1]->arg;
11654 if (vrf && strmatch(vrf, VRF_DEFAULT_NAME))
11655 vrf = NULL;
11656 } else if (argv_find(argv, argc, "view", &idx))
11657 /* [<view> VIEWVRFNAME] */
11658 vrf = argv[idx + 1]->arg;
11659 /* ["BGP_AFI_CMD_STR" ["BGP_SAFI_CMD_STR"]] */
11660 if (argv_find_and_parse_afi(argv, argc, &idx, &afi)) {
11661 argv_find_and_parse_safi(argv, argc, &idx, &safi);
11662 }
11663
11664 /* get subgroup id, if provided */
11665 idx = argc - 1;
11666 if (argv[idx]->type == VARIABLE_TKN)
11667 subgrp_id = strtoull(argv[idx]->arg, NULL, 10);
11668
11669 return (bgp_show_update_groups(vty, vrf, afi, safi, subgrp_id));
11670 }
11671
11672 DEFUN (show_bgp_instance_all_ipv6_updgrps,
11673 show_bgp_instance_all_ipv6_updgrps_cmd,
11674 "show [ip] bgp <view|vrf> all update-groups",
11675 SHOW_STR
11676 IP_STR
11677 BGP_STR
11678 BGP_INSTANCE_ALL_HELP_STR
11679 "Detailed info about dynamic update groups\n")
11680 {
11681 bgp_show_all_instances_updgrps_vty(vty, AFI_IP6, SAFI_UNICAST);
11682 return CMD_SUCCESS;
11683 }
11684
11685 DEFUN (show_bgp_l2vpn_evpn_updgrps,
11686 show_bgp_l2vpn_evpn_updgrps_cmd,
11687 "show [ip] bgp l2vpn evpn update-groups",
11688 SHOW_STR
11689 IP_STR
11690 BGP_STR
11691 "l2vpn address family\n"
11692 "evpn sub-address family\n"
11693 "Detailed info about dynamic update groups\n")
11694 {
11695 char *vrf = NULL;
11696 uint64_t subgrp_id = 0;
11697
11698 bgp_show_update_groups(vty, vrf, AFI_L2VPN, SAFI_EVPN, subgrp_id);
11699 return CMD_SUCCESS;
11700 }
11701
11702 DEFUN (show_bgp_updgrps_stats,
11703 show_bgp_updgrps_stats_cmd,
11704 "show [ip] bgp update-groups statistics",
11705 SHOW_STR
11706 IP_STR
11707 BGP_STR
11708 "Detailed info about dynamic update groups\n"
11709 "Statistics\n")
11710 {
11711 struct bgp *bgp;
11712
11713 bgp = bgp_get_default();
11714 if (bgp)
11715 update_group_show_stats(bgp, vty);
11716
11717 return CMD_SUCCESS;
11718 }
11719
11720 DEFUN (show_bgp_instance_updgrps_stats,
11721 show_bgp_instance_updgrps_stats_cmd,
11722 "show [ip] bgp <view|vrf> VIEWVRFNAME update-groups statistics",
11723 SHOW_STR
11724 IP_STR
11725 BGP_STR
11726 BGP_INSTANCE_HELP_STR
11727 "Detailed info about dynamic update groups\n"
11728 "Statistics\n")
11729 {
11730 int idx_word = 3;
11731 struct bgp *bgp;
11732
11733 bgp = bgp_lookup_by_name(argv[idx_word]->arg);
11734 if (bgp)
11735 update_group_show_stats(bgp, vty);
11736
11737 return CMD_SUCCESS;
11738 }
11739
11740 static void show_bgp_updgrps_adj_info_aux(struct vty *vty, const char *name,
11741 afi_t afi, safi_t safi,
11742 const char *what, uint64_t subgrp_id)
11743 {
11744 struct bgp *bgp;
11745
11746 if (name)
11747 bgp = bgp_lookup_by_name(name);
11748 else
11749 bgp = bgp_get_default();
11750
11751 if (bgp) {
11752 if (!strcmp(what, "advertise-queue"))
11753 update_group_show_adj_queue(bgp, afi, safi, vty,
11754 subgrp_id);
11755 else if (!strcmp(what, "advertised-routes"))
11756 update_group_show_advertised(bgp, afi, safi, vty,
11757 subgrp_id);
11758 else if (!strcmp(what, "packet-queue"))
11759 update_group_show_packet_queue(bgp, afi, safi, vty,
11760 subgrp_id);
11761 }
11762 }
11763
11764 DEFPY(show_ip_bgp_instance_updgrps_adj_s,
11765 show_ip_bgp_instance_updgrps_adj_s_cmd,
11766 "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",
11767 SHOW_STR IP_STR BGP_STR BGP_INSTANCE_HELP_STR BGP_AFI_HELP_STR
11768 BGP_SAFI_HELP_STR
11769 "Detailed info about dynamic update groups\n"
11770 "Specific subgroup to display info for\n"
11771 "Advertisement queue\n"
11772 "Announced routes\n"
11773 "Packet queue\n")
11774 {
11775 uint64_t subgrp_id = 0;
11776 afi_t afiz;
11777 safi_t safiz;
11778 if (sgid)
11779 subgrp_id = strtoull(sgid, NULL, 10);
11780
11781 if (!ip && !afi)
11782 afiz = AFI_IP6;
11783 if (!ip && afi)
11784 afiz = bgp_vty_afi_from_str(afi);
11785 if (ip && !afi)
11786 afiz = AFI_IP;
11787 if (ip && afi) {
11788 afiz = bgp_vty_afi_from_str(afi);
11789 if (afiz != AFI_IP)
11790 vty_out(vty,
11791 "%% Cannot specify both 'ip' and 'ipv6'\n");
11792 return CMD_WARNING;
11793 }
11794
11795 safiz = safi ? bgp_vty_safi_from_str(safi) : SAFI_UNICAST;
11796
11797 show_bgp_updgrps_adj_info_aux(vty, vrf, afiz, safiz, rtq, subgrp_id);
11798 return CMD_SUCCESS;
11799 }
11800
11801 static int bgp_show_one_peer_group(struct vty *vty, struct peer_group *group)
11802 {
11803 struct listnode *node, *nnode;
11804 struct prefix *range;
11805 struct peer *conf;
11806 struct peer *peer;
11807 char buf[PREFIX2STR_BUFFER];
11808 afi_t afi;
11809 safi_t safi;
11810 const char *peer_status;
11811 const char *af_str;
11812 int lr_count;
11813 int dynamic;
11814 int af_cfgd;
11815
11816 conf = group->conf;
11817
11818 if (conf->as_type == AS_SPECIFIED || conf->as_type == AS_EXTERNAL) {
11819 vty_out(vty, "\nBGP peer-group %s, remote AS %" PRIu32 "\n",
11820 group->name, conf->as);
11821 } else if (conf->as_type == AS_INTERNAL) {
11822 vty_out(vty, "\nBGP peer-group %s, remote AS %" PRIu32 "\n",
11823 group->name, group->bgp->as);
11824 } else {
11825 vty_out(vty, "\nBGP peer-group %s\n", group->name);
11826 }
11827
11828 if ((group->bgp->as == conf->as) || (conf->as_type == AS_INTERNAL))
11829 vty_out(vty, " Peer-group type is internal\n");
11830 else
11831 vty_out(vty, " Peer-group type is external\n");
11832
11833 /* Display AFs configured. */
11834 vty_out(vty, " Configured address-families:");
11835 FOREACH_AFI_SAFI (afi, safi) {
11836 if (conf->afc[afi][safi]) {
11837 af_cfgd = 1;
11838 vty_out(vty, " %s;", afi_safi_print(afi, safi));
11839 }
11840 }
11841 if (!af_cfgd)
11842 vty_out(vty, " none\n");
11843 else
11844 vty_out(vty, "\n");
11845
11846 /* Display listen ranges (for dynamic neighbors), if any */
11847 for (afi = AFI_IP; afi < AFI_MAX; afi++) {
11848 if (afi == AFI_IP)
11849 af_str = "IPv4";
11850 else if (afi == AFI_IP6)
11851 af_str = "IPv6";
11852 else
11853 af_str = "???";
11854 lr_count = listcount(group->listen_range[afi]);
11855 if (lr_count) {
11856 vty_out(vty, " %d %s listen range(s)\n", lr_count,
11857 af_str);
11858
11859
11860 for (ALL_LIST_ELEMENTS(group->listen_range[afi], node,
11861 nnode, range)) {
11862 prefix2str(range, buf, sizeof(buf));
11863 vty_out(vty, " %s\n", buf);
11864 }
11865 }
11866 }
11867
11868 /* Display group members and their status */
11869 if (listcount(group->peer)) {
11870 vty_out(vty, " Peer-group members:\n");
11871 for (ALL_LIST_ELEMENTS(group->peer, node, nnode, peer)) {
11872 if (CHECK_FLAG(peer->flags, PEER_FLAG_SHUTDOWN))
11873 peer_status = "Idle (Admin)";
11874 else if (CHECK_FLAG(peer->sflags,
11875 PEER_STATUS_PREFIX_OVERFLOW))
11876 peer_status = "Idle (PfxCt)";
11877 else
11878 peer_status = lookup_msg(bgp_status_msg,
11879 peer->status, NULL);
11880
11881 dynamic = peer_dynamic_neighbor(peer);
11882 vty_out(vty, " %s %s %s \n", peer->host,
11883 dynamic ? "(dynamic)" : "", peer_status);
11884 }
11885 }
11886
11887 return CMD_SUCCESS;
11888 }
11889
11890 static int bgp_show_peer_group_vty(struct vty *vty, const char *name,
11891 const char *group_name)
11892 {
11893 struct bgp *bgp;
11894 struct listnode *node, *nnode;
11895 struct peer_group *group;
11896 bool found = false;
11897
11898 bgp = name ? bgp_lookup_by_name(name) : bgp_get_default();
11899
11900 if (!bgp) {
11901 vty_out(vty, "%% BGP instance not found\n");
11902 return CMD_WARNING;
11903 }
11904
11905 for (ALL_LIST_ELEMENTS(bgp->group, node, nnode, group)) {
11906 if (group_name) {
11907 if (strmatch(group->name, group_name)) {
11908 bgp_show_one_peer_group(vty, group);
11909 found = true;
11910 break;
11911 }
11912 } else {
11913 bgp_show_one_peer_group(vty, group);
11914 }
11915 }
11916
11917 if (group_name && !found)
11918 vty_out(vty, "%% No such peer-group\n");
11919
11920 return CMD_SUCCESS;
11921 }
11922
11923 DEFUN (show_ip_bgp_peer_groups,
11924 show_ip_bgp_peer_groups_cmd,
11925 "show [ip] bgp [<view|vrf> VIEWVRFNAME] peer-group [PGNAME]",
11926 SHOW_STR
11927 IP_STR
11928 BGP_STR
11929 BGP_INSTANCE_HELP_STR
11930 "Detailed information on BGP peer groups\n"
11931 "Peer group name\n")
11932 {
11933 char *vrf, *pg;
11934 int idx = 0;
11935
11936 vrf = argv_find(argv, argc, "VIEWVRFNAME", &idx) ? argv[idx]->arg
11937 : NULL;
11938 pg = argv_find(argv, argc, "PGNAME", &idx) ? argv[idx]->arg : NULL;
11939
11940 return bgp_show_peer_group_vty(vty, vrf, pg);
11941 }
11942
11943
11944 /* Redistribute VTY commands. */
11945
11946 DEFUN (bgp_redistribute_ipv4,
11947 bgp_redistribute_ipv4_cmd,
11948 "redistribute " FRR_IP_REDIST_STR_BGPD,
11949 "Redistribute information from another routing protocol\n"
11950 FRR_IP_REDIST_HELP_STR_BGPD)
11951 {
11952 VTY_DECLVAR_CONTEXT(bgp, bgp);
11953 int idx_protocol = 1;
11954 int type;
11955
11956 type = proto_redistnum(AFI_IP, argv[idx_protocol]->text);
11957 if (type < 0) {
11958 vty_out(vty, "%% Invalid route type\n");
11959 return CMD_WARNING_CONFIG_FAILED;
11960 }
11961
11962 bgp_redist_add(bgp, AFI_IP, type, 0);
11963 return bgp_redistribute_set(bgp, AFI_IP, type, 0, false);
11964 }
11965
11966 ALIAS_HIDDEN(
11967 bgp_redistribute_ipv4, bgp_redistribute_ipv4_hidden_cmd,
11968 "redistribute " FRR_IP_REDIST_STR_BGPD,
11969 "Redistribute information from another routing protocol\n" FRR_IP_REDIST_HELP_STR_BGPD)
11970
11971 DEFUN (bgp_redistribute_ipv4_rmap,
11972 bgp_redistribute_ipv4_rmap_cmd,
11973 "redistribute " FRR_IP_REDIST_STR_BGPD " route-map WORD",
11974 "Redistribute information from another routing protocol\n"
11975 FRR_IP_REDIST_HELP_STR_BGPD
11976 "Route map reference\n"
11977 "Pointer to route-map entries\n")
11978 {
11979 VTY_DECLVAR_CONTEXT(bgp, bgp);
11980 int idx_protocol = 1;
11981 int idx_word = 3;
11982 int type;
11983 struct bgp_redist *red;
11984 bool changed;
11985 struct route_map *route_map = route_map_lookup_warn_noexist(
11986 vty, argv[idx_word]->arg);
11987
11988 type = proto_redistnum(AFI_IP, argv[idx_protocol]->text);
11989 if (type < 0) {
11990 vty_out(vty, "%% Invalid route type\n");
11991 return CMD_WARNING_CONFIG_FAILED;
11992 }
11993
11994 red = bgp_redist_add(bgp, AFI_IP, type, 0);
11995 changed =
11996 bgp_redistribute_rmap_set(red, argv[idx_word]->arg, route_map);
11997 return bgp_redistribute_set(bgp, AFI_IP, type, 0, changed);
11998 }
11999
12000 ALIAS_HIDDEN(
12001 bgp_redistribute_ipv4_rmap, bgp_redistribute_ipv4_rmap_hidden_cmd,
12002 "redistribute " FRR_IP_REDIST_STR_BGPD " route-map WORD",
12003 "Redistribute information from another routing protocol\n" FRR_IP_REDIST_HELP_STR_BGPD
12004 "Route map reference\n"
12005 "Pointer to route-map entries\n")
12006
12007 DEFUN (bgp_redistribute_ipv4_metric,
12008 bgp_redistribute_ipv4_metric_cmd,
12009 "redistribute " FRR_IP_REDIST_STR_BGPD " metric (0-4294967295)",
12010 "Redistribute information from another routing protocol\n"
12011 FRR_IP_REDIST_HELP_STR_BGPD
12012 "Metric for redistributed routes\n"
12013 "Default metric\n")
12014 {
12015 VTY_DECLVAR_CONTEXT(bgp, bgp);
12016 int idx_protocol = 1;
12017 int idx_number = 3;
12018 int type;
12019 uint32_t metric;
12020 struct bgp_redist *red;
12021 bool changed;
12022
12023 type = proto_redistnum(AFI_IP, argv[idx_protocol]->text);
12024 if (type < 0) {
12025 vty_out(vty, "%% Invalid route type\n");
12026 return CMD_WARNING_CONFIG_FAILED;
12027 }
12028 metric = strtoul(argv[idx_number]->arg, NULL, 10);
12029
12030 red = bgp_redist_add(bgp, AFI_IP, type, 0);
12031 changed = bgp_redistribute_metric_set(bgp, red, AFI_IP, type, metric);
12032 return bgp_redistribute_set(bgp, AFI_IP, type, 0, changed);
12033 }
12034
12035 ALIAS_HIDDEN(
12036 bgp_redistribute_ipv4_metric, bgp_redistribute_ipv4_metric_hidden_cmd,
12037 "redistribute " FRR_IP_REDIST_STR_BGPD " metric (0-4294967295)",
12038 "Redistribute information from another routing protocol\n" FRR_IP_REDIST_HELP_STR_BGPD
12039 "Metric for redistributed routes\n"
12040 "Default metric\n")
12041
12042 DEFUN (bgp_redistribute_ipv4_rmap_metric,
12043 bgp_redistribute_ipv4_rmap_metric_cmd,
12044 "redistribute " FRR_IP_REDIST_STR_BGPD " route-map WORD metric (0-4294967295)",
12045 "Redistribute information from another routing protocol\n"
12046 FRR_IP_REDIST_HELP_STR_BGPD
12047 "Route map reference\n"
12048 "Pointer to route-map entries\n"
12049 "Metric for redistributed routes\n"
12050 "Default metric\n")
12051 {
12052 VTY_DECLVAR_CONTEXT(bgp, bgp);
12053 int idx_protocol = 1;
12054 int idx_word = 3;
12055 int idx_number = 5;
12056 int type;
12057 uint32_t metric;
12058 struct bgp_redist *red;
12059 bool changed;
12060 struct route_map *route_map =
12061 route_map_lookup_warn_noexist(vty, argv[idx_word]->arg);
12062
12063 type = proto_redistnum(AFI_IP, argv[idx_protocol]->text);
12064 if (type < 0) {
12065 vty_out(vty, "%% Invalid route type\n");
12066 return CMD_WARNING_CONFIG_FAILED;
12067 }
12068 metric = strtoul(argv[idx_number]->arg, NULL, 10);
12069
12070 red = bgp_redist_add(bgp, AFI_IP, type, 0);
12071 changed =
12072 bgp_redistribute_rmap_set(red, argv[idx_word]->arg, route_map);
12073 changed |= bgp_redistribute_metric_set(bgp, red, AFI_IP, type, metric);
12074 return bgp_redistribute_set(bgp, AFI_IP, type, 0, changed);
12075 }
12076
12077 ALIAS_HIDDEN(
12078 bgp_redistribute_ipv4_rmap_metric,
12079 bgp_redistribute_ipv4_rmap_metric_hidden_cmd,
12080 "redistribute " FRR_IP_REDIST_STR_BGPD
12081 " route-map WORD metric (0-4294967295)",
12082 "Redistribute information from another routing protocol\n" FRR_IP_REDIST_HELP_STR_BGPD
12083 "Route map reference\n"
12084 "Pointer to route-map entries\n"
12085 "Metric for redistributed routes\n"
12086 "Default metric\n")
12087
12088 DEFUN (bgp_redistribute_ipv4_metric_rmap,
12089 bgp_redistribute_ipv4_metric_rmap_cmd,
12090 "redistribute " FRR_IP_REDIST_STR_BGPD " metric (0-4294967295) route-map WORD",
12091 "Redistribute information from another routing protocol\n"
12092 FRR_IP_REDIST_HELP_STR_BGPD
12093 "Metric for redistributed routes\n"
12094 "Default metric\n"
12095 "Route map reference\n"
12096 "Pointer to route-map entries\n")
12097 {
12098 VTY_DECLVAR_CONTEXT(bgp, bgp);
12099 int idx_protocol = 1;
12100 int idx_number = 3;
12101 int idx_word = 5;
12102 int type;
12103 uint32_t metric;
12104 struct bgp_redist *red;
12105 bool changed;
12106 struct route_map *route_map =
12107 route_map_lookup_warn_noexist(vty, argv[idx_word]->arg);
12108
12109 type = proto_redistnum(AFI_IP, argv[idx_protocol]->text);
12110 if (type < 0) {
12111 vty_out(vty, "%% Invalid route type\n");
12112 return CMD_WARNING_CONFIG_FAILED;
12113 }
12114 metric = strtoul(argv[idx_number]->arg, NULL, 10);
12115
12116 red = bgp_redist_add(bgp, AFI_IP, type, 0);
12117 changed = bgp_redistribute_metric_set(bgp, red, AFI_IP, type, metric);
12118 changed |=
12119 bgp_redistribute_rmap_set(red, argv[idx_word]->arg, route_map);
12120 return bgp_redistribute_set(bgp, AFI_IP, type, 0, changed);
12121 }
12122
12123 ALIAS_HIDDEN(
12124 bgp_redistribute_ipv4_metric_rmap,
12125 bgp_redistribute_ipv4_metric_rmap_hidden_cmd,
12126 "redistribute " FRR_IP_REDIST_STR_BGPD
12127 " metric (0-4294967295) route-map WORD",
12128 "Redistribute information from another routing protocol\n" FRR_IP_REDIST_HELP_STR_BGPD
12129 "Metric for redistributed routes\n"
12130 "Default metric\n"
12131 "Route map reference\n"
12132 "Pointer to route-map entries\n")
12133
12134 DEFUN (bgp_redistribute_ipv4_ospf,
12135 bgp_redistribute_ipv4_ospf_cmd,
12136 "redistribute <ospf|table> (1-65535)",
12137 "Redistribute information from another routing protocol\n"
12138 "Open Shortest Path First (OSPFv2)\n"
12139 "Non-main Kernel Routing Table\n"
12140 "Instance ID/Table ID\n")
12141 {
12142 VTY_DECLVAR_CONTEXT(bgp, bgp);
12143 int idx_ospf_table = 1;
12144 int idx_number = 2;
12145 unsigned short instance;
12146 unsigned short protocol;
12147
12148 instance = strtoul(argv[idx_number]->arg, NULL, 10);
12149
12150 if (strncmp(argv[idx_ospf_table]->arg, "o", 1) == 0)
12151 protocol = ZEBRA_ROUTE_OSPF;
12152 else
12153 protocol = ZEBRA_ROUTE_TABLE;
12154
12155 bgp_redist_add(bgp, AFI_IP, protocol, instance);
12156 return bgp_redistribute_set(bgp, AFI_IP, protocol, instance, false);
12157 }
12158
12159 ALIAS_HIDDEN(bgp_redistribute_ipv4_ospf, bgp_redistribute_ipv4_ospf_hidden_cmd,
12160 "redistribute <ospf|table> (1-65535)",
12161 "Redistribute information from another routing protocol\n"
12162 "Open Shortest Path First (OSPFv2)\n"
12163 "Non-main Kernel Routing Table\n"
12164 "Instance ID/Table ID\n")
12165
12166 DEFUN (bgp_redistribute_ipv4_ospf_rmap,
12167 bgp_redistribute_ipv4_ospf_rmap_cmd,
12168 "redistribute <ospf|table> (1-65535) route-map WORD",
12169 "Redistribute information from another routing protocol\n"
12170 "Open Shortest Path First (OSPFv2)\n"
12171 "Non-main Kernel Routing Table\n"
12172 "Instance ID/Table ID\n"
12173 "Route map reference\n"
12174 "Pointer to route-map entries\n")
12175 {
12176 VTY_DECLVAR_CONTEXT(bgp, bgp);
12177 int idx_ospf_table = 1;
12178 int idx_number = 2;
12179 int idx_word = 4;
12180 struct bgp_redist *red;
12181 unsigned short instance;
12182 int protocol;
12183 bool changed;
12184 struct route_map *route_map =
12185 route_map_lookup_warn_noexist(vty, argv[idx_word]->arg);
12186
12187 if (strncmp(argv[idx_ospf_table]->arg, "o", 1) == 0)
12188 protocol = ZEBRA_ROUTE_OSPF;
12189 else
12190 protocol = ZEBRA_ROUTE_TABLE;
12191
12192 instance = strtoul(argv[idx_number]->arg, NULL, 10);
12193 red = bgp_redist_add(bgp, AFI_IP, protocol, instance);
12194 changed =
12195 bgp_redistribute_rmap_set(red, argv[idx_word]->arg, route_map);
12196 return bgp_redistribute_set(bgp, AFI_IP, protocol, instance, changed);
12197 }
12198
12199 ALIAS_HIDDEN(bgp_redistribute_ipv4_ospf_rmap,
12200 bgp_redistribute_ipv4_ospf_rmap_hidden_cmd,
12201 "redistribute <ospf|table> (1-65535) route-map WORD",
12202 "Redistribute information from another routing protocol\n"
12203 "Open Shortest Path First (OSPFv2)\n"
12204 "Non-main Kernel Routing Table\n"
12205 "Instance ID/Table ID\n"
12206 "Route map reference\n"
12207 "Pointer to route-map entries\n")
12208
12209 DEFUN (bgp_redistribute_ipv4_ospf_metric,
12210 bgp_redistribute_ipv4_ospf_metric_cmd,
12211 "redistribute <ospf|table> (1-65535) metric (0-4294967295)",
12212 "Redistribute information from another routing protocol\n"
12213 "Open Shortest Path First (OSPFv2)\n"
12214 "Non-main Kernel Routing Table\n"
12215 "Instance ID/Table ID\n"
12216 "Metric for redistributed routes\n"
12217 "Default metric\n")
12218 {
12219 VTY_DECLVAR_CONTEXT(bgp, bgp);
12220 int idx_ospf_table = 1;
12221 int idx_number = 2;
12222 int idx_number_2 = 4;
12223 uint32_t metric;
12224 struct bgp_redist *red;
12225 unsigned short instance;
12226 int protocol;
12227 bool changed;
12228
12229 if (strncmp(argv[idx_ospf_table]->arg, "o", 1) == 0)
12230 protocol = ZEBRA_ROUTE_OSPF;
12231 else
12232 protocol = ZEBRA_ROUTE_TABLE;
12233
12234 instance = strtoul(argv[idx_number]->arg, NULL, 10);
12235 metric = strtoul(argv[idx_number_2]->arg, NULL, 10);
12236
12237 red = bgp_redist_add(bgp, AFI_IP, protocol, instance);
12238 changed = bgp_redistribute_metric_set(bgp, red, AFI_IP, protocol,
12239 metric);
12240 return bgp_redistribute_set(bgp, AFI_IP, protocol, instance, changed);
12241 }
12242
12243 ALIAS_HIDDEN(bgp_redistribute_ipv4_ospf_metric,
12244 bgp_redistribute_ipv4_ospf_metric_hidden_cmd,
12245 "redistribute <ospf|table> (1-65535) metric (0-4294967295)",
12246 "Redistribute information from another routing protocol\n"
12247 "Open Shortest Path First (OSPFv2)\n"
12248 "Non-main Kernel Routing Table\n"
12249 "Instance ID/Table ID\n"
12250 "Metric for redistributed routes\n"
12251 "Default metric\n")
12252
12253 DEFUN (bgp_redistribute_ipv4_ospf_rmap_metric,
12254 bgp_redistribute_ipv4_ospf_rmap_metric_cmd,
12255 "redistribute <ospf|table> (1-65535) route-map WORD metric (0-4294967295)",
12256 "Redistribute information from another routing protocol\n"
12257 "Open Shortest Path First (OSPFv2)\n"
12258 "Non-main Kernel Routing Table\n"
12259 "Instance ID/Table ID\n"
12260 "Route map reference\n"
12261 "Pointer to route-map entries\n"
12262 "Metric for redistributed routes\n"
12263 "Default metric\n")
12264 {
12265 VTY_DECLVAR_CONTEXT(bgp, bgp);
12266 int idx_ospf_table = 1;
12267 int idx_number = 2;
12268 int idx_word = 4;
12269 int idx_number_2 = 6;
12270 uint32_t metric;
12271 struct bgp_redist *red;
12272 unsigned short instance;
12273 int protocol;
12274 bool changed;
12275 struct route_map *route_map =
12276 route_map_lookup_warn_noexist(vty, argv[idx_word]->arg);
12277
12278 if (strncmp(argv[idx_ospf_table]->arg, "o", 1) == 0)
12279 protocol = ZEBRA_ROUTE_OSPF;
12280 else
12281 protocol = ZEBRA_ROUTE_TABLE;
12282
12283 instance = strtoul(argv[idx_number]->arg, NULL, 10);
12284 metric = strtoul(argv[idx_number_2]->arg, NULL, 10);
12285
12286 red = bgp_redist_add(bgp, AFI_IP, protocol, instance);
12287 changed =
12288 bgp_redistribute_rmap_set(red, argv[idx_word]->arg, route_map);
12289 changed |= bgp_redistribute_metric_set(bgp, red, AFI_IP, protocol,
12290 metric);
12291 return bgp_redistribute_set(bgp, AFI_IP, protocol, instance, changed);
12292 }
12293
12294 ALIAS_HIDDEN(
12295 bgp_redistribute_ipv4_ospf_rmap_metric,
12296 bgp_redistribute_ipv4_ospf_rmap_metric_hidden_cmd,
12297 "redistribute <ospf|table> (1-65535) route-map WORD metric (0-4294967295)",
12298 "Redistribute information from another routing protocol\n"
12299 "Open Shortest Path First (OSPFv2)\n"
12300 "Non-main Kernel Routing Table\n"
12301 "Instance ID/Table ID\n"
12302 "Route map reference\n"
12303 "Pointer to route-map entries\n"
12304 "Metric for redistributed routes\n"
12305 "Default metric\n")
12306
12307 DEFUN (bgp_redistribute_ipv4_ospf_metric_rmap,
12308 bgp_redistribute_ipv4_ospf_metric_rmap_cmd,
12309 "redistribute <ospf|table> (1-65535) metric (0-4294967295) route-map WORD",
12310 "Redistribute information from another routing protocol\n"
12311 "Open Shortest Path First (OSPFv2)\n"
12312 "Non-main Kernel Routing Table\n"
12313 "Instance ID/Table ID\n"
12314 "Metric for redistributed routes\n"
12315 "Default metric\n"
12316 "Route map reference\n"
12317 "Pointer to route-map entries\n")
12318 {
12319 VTY_DECLVAR_CONTEXT(bgp, bgp);
12320 int idx_ospf_table = 1;
12321 int idx_number = 2;
12322 int idx_number_2 = 4;
12323 int idx_word = 6;
12324 uint32_t metric;
12325 struct bgp_redist *red;
12326 unsigned short instance;
12327 int protocol;
12328 bool changed;
12329 struct route_map *route_map =
12330 route_map_lookup_warn_noexist(vty, argv[idx_word]->arg);
12331
12332 if (strncmp(argv[idx_ospf_table]->arg, "o", 1) == 0)
12333 protocol = ZEBRA_ROUTE_OSPF;
12334 else
12335 protocol = ZEBRA_ROUTE_TABLE;
12336
12337 instance = strtoul(argv[idx_number]->arg, NULL, 10);
12338 metric = strtoul(argv[idx_number_2]->arg, NULL, 10);
12339
12340 red = bgp_redist_add(bgp, AFI_IP, protocol, instance);
12341 changed = bgp_redistribute_metric_set(bgp, red, AFI_IP, protocol,
12342 metric);
12343 changed |=
12344 bgp_redistribute_rmap_set(red, argv[idx_word]->arg, route_map);
12345 return bgp_redistribute_set(bgp, AFI_IP, protocol, instance, changed);
12346 }
12347
12348 ALIAS_HIDDEN(
12349 bgp_redistribute_ipv4_ospf_metric_rmap,
12350 bgp_redistribute_ipv4_ospf_metric_rmap_hidden_cmd,
12351 "redistribute <ospf|table> (1-65535) metric (0-4294967295) route-map WORD",
12352 "Redistribute information from another routing protocol\n"
12353 "Open Shortest Path First (OSPFv2)\n"
12354 "Non-main Kernel Routing Table\n"
12355 "Instance ID/Table ID\n"
12356 "Metric for redistributed routes\n"
12357 "Default metric\n"
12358 "Route map reference\n"
12359 "Pointer to route-map entries\n")
12360
12361 DEFUN (no_bgp_redistribute_ipv4_ospf,
12362 no_bgp_redistribute_ipv4_ospf_cmd,
12363 "no redistribute <ospf|table> (1-65535) [metric (0-4294967295)] [route-map WORD]",
12364 NO_STR
12365 "Redistribute information from another routing protocol\n"
12366 "Open Shortest Path First (OSPFv2)\n"
12367 "Non-main Kernel Routing Table\n"
12368 "Instance ID/Table ID\n"
12369 "Metric for redistributed routes\n"
12370 "Default metric\n"
12371 "Route map reference\n"
12372 "Pointer to route-map entries\n")
12373 {
12374 VTY_DECLVAR_CONTEXT(bgp, bgp);
12375 int idx_ospf_table = 2;
12376 int idx_number = 3;
12377 unsigned short instance;
12378 int protocol;
12379
12380 if (strncmp(argv[idx_ospf_table]->arg, "o", 1) == 0)
12381 protocol = ZEBRA_ROUTE_OSPF;
12382 else
12383 protocol = ZEBRA_ROUTE_TABLE;
12384
12385 instance = strtoul(argv[idx_number]->arg, NULL, 10);
12386 return bgp_redistribute_unset(bgp, AFI_IP, protocol, instance);
12387 }
12388
12389 ALIAS_HIDDEN(
12390 no_bgp_redistribute_ipv4_ospf, no_bgp_redistribute_ipv4_ospf_hidden_cmd,
12391 "no redistribute <ospf|table> (1-65535) [metric (0-4294967295)] [route-map WORD]",
12392 NO_STR
12393 "Redistribute information from another routing protocol\n"
12394 "Open Shortest Path First (OSPFv2)\n"
12395 "Non-main Kernel Routing Table\n"
12396 "Instance ID/Table ID\n"
12397 "Metric for redistributed routes\n"
12398 "Default metric\n"
12399 "Route map reference\n"
12400 "Pointer to route-map entries\n")
12401
12402 DEFUN (no_bgp_redistribute_ipv4,
12403 no_bgp_redistribute_ipv4_cmd,
12404 "no redistribute " FRR_IP_REDIST_STR_BGPD " [metric (0-4294967295)] [route-map WORD]",
12405 NO_STR
12406 "Redistribute information from another routing protocol\n"
12407 FRR_IP_REDIST_HELP_STR_BGPD
12408 "Metric for redistributed routes\n"
12409 "Default metric\n"
12410 "Route map reference\n"
12411 "Pointer to route-map entries\n")
12412 {
12413 VTY_DECLVAR_CONTEXT(bgp, bgp);
12414 int idx_protocol = 2;
12415 int type;
12416
12417 type = proto_redistnum(AFI_IP, argv[idx_protocol]->text);
12418 if (type < 0) {
12419 vty_out(vty, "%% Invalid route type\n");
12420 return CMD_WARNING_CONFIG_FAILED;
12421 }
12422 return bgp_redistribute_unset(bgp, AFI_IP, type, 0);
12423 }
12424
12425 ALIAS_HIDDEN(
12426 no_bgp_redistribute_ipv4, no_bgp_redistribute_ipv4_hidden_cmd,
12427 "no redistribute " FRR_IP_REDIST_STR_BGPD
12428 " [metric (0-4294967295)] [route-map WORD]",
12429 NO_STR
12430 "Redistribute information from another routing protocol\n" FRR_IP_REDIST_HELP_STR_BGPD
12431 "Metric for redistributed routes\n"
12432 "Default metric\n"
12433 "Route map reference\n"
12434 "Pointer to route-map entries\n")
12435
12436 DEFUN (bgp_redistribute_ipv6,
12437 bgp_redistribute_ipv6_cmd,
12438 "redistribute " FRR_IP6_REDIST_STR_BGPD,
12439 "Redistribute information from another routing protocol\n"
12440 FRR_IP6_REDIST_HELP_STR_BGPD)
12441 {
12442 VTY_DECLVAR_CONTEXT(bgp, bgp);
12443 int idx_protocol = 1;
12444 int type;
12445
12446 type = proto_redistnum(AFI_IP6, argv[idx_protocol]->text);
12447 if (type < 0) {
12448 vty_out(vty, "%% Invalid route type\n");
12449 return CMD_WARNING_CONFIG_FAILED;
12450 }
12451
12452 bgp_redist_add(bgp, AFI_IP6, type, 0);
12453 return bgp_redistribute_set(bgp, AFI_IP6, type, 0, false);
12454 }
12455
12456 DEFUN (bgp_redistribute_ipv6_rmap,
12457 bgp_redistribute_ipv6_rmap_cmd,
12458 "redistribute " FRR_IP6_REDIST_STR_BGPD " route-map WORD",
12459 "Redistribute information from another routing protocol\n"
12460 FRR_IP6_REDIST_HELP_STR_BGPD
12461 "Route map reference\n"
12462 "Pointer to route-map entries\n")
12463 {
12464 VTY_DECLVAR_CONTEXT(bgp, bgp);
12465 int idx_protocol = 1;
12466 int idx_word = 3;
12467 int type;
12468 struct bgp_redist *red;
12469 bool changed;
12470 struct route_map *route_map =
12471 route_map_lookup_warn_noexist(vty, argv[idx_word]->arg);
12472
12473 type = proto_redistnum(AFI_IP6, argv[idx_protocol]->text);
12474 if (type < 0) {
12475 vty_out(vty, "%% Invalid route type\n");
12476 return CMD_WARNING_CONFIG_FAILED;
12477 }
12478
12479 red = bgp_redist_add(bgp, AFI_IP6, type, 0);
12480 changed =
12481 bgp_redistribute_rmap_set(red, argv[idx_word]->arg, route_map);
12482 return bgp_redistribute_set(bgp, AFI_IP6, type, 0, changed);
12483 }
12484
12485 DEFUN (bgp_redistribute_ipv6_metric,
12486 bgp_redistribute_ipv6_metric_cmd,
12487 "redistribute " FRR_IP6_REDIST_STR_BGPD " metric (0-4294967295)",
12488 "Redistribute information from another routing protocol\n"
12489 FRR_IP6_REDIST_HELP_STR_BGPD
12490 "Metric for redistributed routes\n"
12491 "Default metric\n")
12492 {
12493 VTY_DECLVAR_CONTEXT(bgp, bgp);
12494 int idx_protocol = 1;
12495 int idx_number = 3;
12496 int type;
12497 uint32_t metric;
12498 struct bgp_redist *red;
12499 bool changed;
12500
12501 type = proto_redistnum(AFI_IP6, argv[idx_protocol]->text);
12502 if (type < 0) {
12503 vty_out(vty, "%% Invalid route type\n");
12504 return CMD_WARNING_CONFIG_FAILED;
12505 }
12506 metric = strtoul(argv[idx_number]->arg, NULL, 10);
12507
12508 red = bgp_redist_add(bgp, AFI_IP6, type, 0);
12509 changed = bgp_redistribute_metric_set(bgp, red, AFI_IP6, type, metric);
12510 return bgp_redistribute_set(bgp, AFI_IP6, type, 0, changed);
12511 }
12512
12513 DEFUN (bgp_redistribute_ipv6_rmap_metric,
12514 bgp_redistribute_ipv6_rmap_metric_cmd,
12515 "redistribute " FRR_IP6_REDIST_STR_BGPD " route-map WORD metric (0-4294967295)",
12516 "Redistribute information from another routing protocol\n"
12517 FRR_IP6_REDIST_HELP_STR_BGPD
12518 "Route map reference\n"
12519 "Pointer to route-map entries\n"
12520 "Metric for redistributed routes\n"
12521 "Default metric\n")
12522 {
12523 VTY_DECLVAR_CONTEXT(bgp, bgp);
12524 int idx_protocol = 1;
12525 int idx_word = 3;
12526 int idx_number = 5;
12527 int type;
12528 uint32_t metric;
12529 struct bgp_redist *red;
12530 bool changed;
12531 struct route_map *route_map =
12532 route_map_lookup_warn_noexist(vty, argv[idx_word]->arg);
12533
12534 type = proto_redistnum(AFI_IP6, argv[idx_protocol]->text);
12535 if (type < 0) {
12536 vty_out(vty, "%% Invalid route type\n");
12537 return CMD_WARNING_CONFIG_FAILED;
12538 }
12539 metric = strtoul(argv[idx_number]->arg, NULL, 10);
12540
12541 red = bgp_redist_add(bgp, AFI_IP6, type, 0);
12542 changed =
12543 bgp_redistribute_rmap_set(red, argv[idx_word]->arg, route_map);
12544 changed |= bgp_redistribute_metric_set(bgp, red, AFI_IP6, type,
12545 metric);
12546 return bgp_redistribute_set(bgp, AFI_IP6, type, 0, changed);
12547 }
12548
12549 DEFUN (bgp_redistribute_ipv6_metric_rmap,
12550 bgp_redistribute_ipv6_metric_rmap_cmd,
12551 "redistribute " FRR_IP6_REDIST_STR_BGPD " metric (0-4294967295) route-map WORD",
12552 "Redistribute information from another routing protocol\n"
12553 FRR_IP6_REDIST_HELP_STR_BGPD
12554 "Metric for redistributed routes\n"
12555 "Default metric\n"
12556 "Route map reference\n"
12557 "Pointer to route-map entries\n")
12558 {
12559 VTY_DECLVAR_CONTEXT(bgp, bgp);
12560 int idx_protocol = 1;
12561 int idx_number = 3;
12562 int idx_word = 5;
12563 int type;
12564 uint32_t metric;
12565 struct bgp_redist *red;
12566 bool changed;
12567 struct route_map *route_map =
12568 route_map_lookup_warn_noexist(vty, argv[idx_word]->arg);
12569
12570 type = proto_redistnum(AFI_IP6, argv[idx_protocol]->text);
12571 if (type < 0) {
12572 vty_out(vty, "%% Invalid route type\n");
12573 return CMD_WARNING_CONFIG_FAILED;
12574 }
12575 metric = strtoul(argv[idx_number]->arg, NULL, 10);
12576
12577 red = bgp_redist_add(bgp, AFI_IP6, type, 0);
12578 changed = bgp_redistribute_metric_set(bgp, red, AFI_IP6, SAFI_UNICAST,
12579 metric);
12580 changed |=
12581 bgp_redistribute_rmap_set(red, argv[idx_word]->arg, route_map);
12582 return bgp_redistribute_set(bgp, AFI_IP6, type, 0, changed);
12583 }
12584
12585 DEFUN (no_bgp_redistribute_ipv6,
12586 no_bgp_redistribute_ipv6_cmd,
12587 "no redistribute " FRR_IP6_REDIST_STR_BGPD " [metric (0-4294967295)] [route-map WORD]",
12588 NO_STR
12589 "Redistribute information from another routing protocol\n"
12590 FRR_IP6_REDIST_HELP_STR_BGPD
12591 "Metric for redistributed routes\n"
12592 "Default metric\n"
12593 "Route map reference\n"
12594 "Pointer to route-map entries\n")
12595 {
12596 VTY_DECLVAR_CONTEXT(bgp, bgp);
12597 int idx_protocol = 2;
12598 int type;
12599
12600 type = proto_redistnum(AFI_IP6, argv[idx_protocol]->text);
12601 if (type < 0) {
12602 vty_out(vty, "%% Invalid route type\n");
12603 return CMD_WARNING_CONFIG_FAILED;
12604 }
12605
12606 return bgp_redistribute_unset(bgp, AFI_IP6, type, 0);
12607 }
12608
12609 void bgp_config_write_redistribute(struct vty *vty, struct bgp *bgp, afi_t afi,
12610 safi_t safi)
12611 {
12612 int i;
12613
12614 /* Unicast redistribution only. */
12615 if (safi != SAFI_UNICAST)
12616 return;
12617
12618 for (i = 0; i < ZEBRA_ROUTE_MAX; i++) {
12619 /* Redistribute BGP does not make sense. */
12620 if (i != ZEBRA_ROUTE_BGP) {
12621 struct list *red_list;
12622 struct listnode *node;
12623 struct bgp_redist *red;
12624
12625 red_list = bgp->redist[afi][i];
12626 if (!red_list)
12627 continue;
12628
12629 for (ALL_LIST_ELEMENTS_RO(red_list, node, red)) {
12630 /* "redistribute" configuration. */
12631 vty_out(vty, " redistribute %s",
12632 zebra_route_string(i));
12633 if (red->instance)
12634 vty_out(vty, " %d", red->instance);
12635 if (red->redist_metric_flag)
12636 vty_out(vty, " metric %u",
12637 red->redist_metric);
12638 if (red->rmap.name)
12639 vty_out(vty, " route-map %s",
12640 red->rmap.name);
12641 vty_out(vty, "\n");
12642 }
12643 }
12644 }
12645 }
12646
12647 /* This is part of the address-family block (unicast only) */
12648 void bgp_vpn_policy_config_write_afi(struct vty *vty, struct bgp *bgp,
12649 afi_t afi)
12650 {
12651 int indent = 2;
12652
12653 if (bgp->vpn_policy[afi].rmap_name[BGP_VPN_POLICY_DIR_FROMVPN]) {
12654 if (listcount(bgp->vpn_policy[afi].import_vrf))
12655 vty_out(vty, "%*simport vrf route-map %s\n", indent, "",
12656 bgp->vpn_policy[afi]
12657 .rmap_name[BGP_VPN_POLICY_DIR_FROMVPN]);
12658 else
12659 vty_out(vty, "%*sroute-map vpn import %s\n", indent, "",
12660 bgp->vpn_policy[afi]
12661 .rmap_name[BGP_VPN_POLICY_DIR_FROMVPN]);
12662 }
12663 if (CHECK_FLAG(bgp->af_flags[afi][SAFI_UNICAST],
12664 BGP_CONFIG_VRF_TO_VRF_IMPORT)
12665 || CHECK_FLAG(bgp->af_flags[afi][SAFI_UNICAST],
12666 BGP_CONFIG_VRF_TO_VRF_EXPORT))
12667 return;
12668
12669 if (CHECK_FLAG(bgp->vpn_policy[afi].flags,
12670 BGP_VPN_POLICY_TOVPN_LABEL_AUTO)) {
12671
12672 vty_out(vty, "%*slabel vpn export %s\n", indent, "", "auto");
12673
12674 } else {
12675 if (bgp->vpn_policy[afi].tovpn_label != MPLS_LABEL_NONE) {
12676 vty_out(vty, "%*slabel vpn export %u\n", indent, "",
12677 bgp->vpn_policy[afi].tovpn_label);
12678 }
12679 }
12680 if (CHECK_FLAG(bgp->vpn_policy[afi].flags,
12681 BGP_VPN_POLICY_TOVPN_RD_SET)) {
12682 char buf[RD_ADDRSTRLEN];
12683 vty_out(vty, "%*srd vpn export %s\n", indent, "",
12684 prefix_rd2str(&bgp->vpn_policy[afi].tovpn_rd, buf,
12685 sizeof(buf)));
12686 }
12687 if (CHECK_FLAG(bgp->vpn_policy[afi].flags,
12688 BGP_VPN_POLICY_TOVPN_NEXTHOP_SET)) {
12689
12690 char buf[PREFIX_STRLEN];
12691 if (inet_ntop(bgp->vpn_policy[afi].tovpn_nexthop.family,
12692 &bgp->vpn_policy[afi].tovpn_nexthop.u.prefix, buf,
12693 sizeof(buf))) {
12694
12695 vty_out(vty, "%*snexthop vpn export %s\n",
12696 indent, "", buf);
12697 }
12698 }
12699 if (bgp->vpn_policy[afi].rtlist[BGP_VPN_POLICY_DIR_FROMVPN]
12700 && bgp->vpn_policy[afi].rtlist[BGP_VPN_POLICY_DIR_TOVPN]
12701 && ecommunity_cmp(
12702 bgp->vpn_policy[afi].rtlist[BGP_VPN_POLICY_DIR_FROMVPN],
12703 bgp->vpn_policy[afi].rtlist[BGP_VPN_POLICY_DIR_TOVPN])) {
12704
12705 char *b = ecommunity_ecom2str(
12706 bgp->vpn_policy[afi].rtlist[BGP_VPN_POLICY_DIR_TOVPN],
12707 ECOMMUNITY_FORMAT_ROUTE_MAP, ECOMMUNITY_ROUTE_TARGET);
12708 vty_out(vty, "%*srt vpn both %s\n", indent, "", b);
12709 XFREE(MTYPE_ECOMMUNITY_STR, b);
12710 } else {
12711 if (bgp->vpn_policy[afi].rtlist[BGP_VPN_POLICY_DIR_FROMVPN]) {
12712 char *b = ecommunity_ecom2str(
12713 bgp->vpn_policy[afi]
12714 .rtlist[BGP_VPN_POLICY_DIR_FROMVPN],
12715 ECOMMUNITY_FORMAT_ROUTE_MAP,
12716 ECOMMUNITY_ROUTE_TARGET);
12717 vty_out(vty, "%*srt vpn import %s\n", indent, "", b);
12718 XFREE(MTYPE_ECOMMUNITY_STR, b);
12719 }
12720 if (bgp->vpn_policy[afi].rtlist[BGP_VPN_POLICY_DIR_TOVPN]) {
12721 char *b = ecommunity_ecom2str(
12722 bgp->vpn_policy[afi]
12723 .rtlist[BGP_VPN_POLICY_DIR_TOVPN],
12724 ECOMMUNITY_FORMAT_ROUTE_MAP,
12725 ECOMMUNITY_ROUTE_TARGET);
12726 vty_out(vty, "%*srt vpn export %s\n", indent, "", b);
12727 XFREE(MTYPE_ECOMMUNITY_STR, b);
12728 }
12729 }
12730
12731 if (bgp->vpn_policy[afi].rmap_name[BGP_VPN_POLICY_DIR_TOVPN])
12732 vty_out(vty, "%*sroute-map vpn export %s\n", indent, "",
12733 bgp->vpn_policy[afi]
12734 .rmap_name[BGP_VPN_POLICY_DIR_TOVPN]);
12735
12736 if (bgp->vpn_policy[afi].import_redirect_rtlist) {
12737 char *b = ecommunity_ecom2str(
12738 bgp->vpn_policy[afi]
12739 .import_redirect_rtlist,
12740 ECOMMUNITY_FORMAT_ROUTE_MAP,
12741 ECOMMUNITY_ROUTE_TARGET);
12742
12743 vty_out(vty, "%*srt redirect import %s\n", indent, "", b);
12744 XFREE(MTYPE_ECOMMUNITY_STR, b);
12745 }
12746 }
12747
12748
12749 /* BGP node structure. */
12750 static struct cmd_node bgp_node = {
12751 BGP_NODE, "%s(config-router)# ", 1,
12752 };
12753
12754 static struct cmd_node bgp_ipv4_unicast_node = {
12755 BGP_IPV4_NODE, "%s(config-router-af)# ", 1,
12756 };
12757
12758 static struct cmd_node bgp_ipv4_multicast_node = {
12759 BGP_IPV4M_NODE, "%s(config-router-af)# ", 1,
12760 };
12761
12762 static struct cmd_node bgp_ipv4_labeled_unicast_node = {
12763 BGP_IPV4L_NODE, "%s(config-router-af)# ", 1,
12764 };
12765
12766 static struct cmd_node bgp_ipv6_unicast_node = {
12767 BGP_IPV6_NODE, "%s(config-router-af)# ", 1,
12768 };
12769
12770 static struct cmd_node bgp_ipv6_multicast_node = {
12771 BGP_IPV6M_NODE, "%s(config-router-af)# ", 1,
12772 };
12773
12774 static struct cmd_node bgp_ipv6_labeled_unicast_node = {
12775 BGP_IPV6L_NODE, "%s(config-router-af)# ", 1,
12776 };
12777
12778 static struct cmd_node bgp_vpnv4_node = {BGP_VPNV4_NODE,
12779 "%s(config-router-af)# ", 1};
12780
12781 static struct cmd_node bgp_vpnv6_node = {BGP_VPNV6_NODE,
12782 "%s(config-router-af-vpnv6)# ", 1};
12783
12784 static struct cmd_node bgp_evpn_node = {BGP_EVPN_NODE,
12785 "%s(config-router-evpn)# ", 1};
12786
12787 static struct cmd_node bgp_evpn_vni_node = {BGP_EVPN_VNI_NODE,
12788 "%s(config-router-af-vni)# ", 1};
12789
12790 static struct cmd_node bgp_flowspecv4_node = {BGP_FLOWSPECV4_NODE,
12791 "%s(config-router-af)# ", 1};
12792
12793 static struct cmd_node bgp_flowspecv6_node = {BGP_FLOWSPECV6_NODE,
12794 "%s(config-router-af-vpnv6)# ", 1};
12795
12796 static void community_list_vty(void);
12797
12798 static void bgp_ac_neighbor(vector comps, struct cmd_token *token)
12799 {
12800 struct bgp *bgp;
12801 struct peer *peer;
12802 struct listnode *lnbgp, *lnpeer;
12803
12804 for (ALL_LIST_ELEMENTS_RO(bm->bgp, lnbgp, bgp)) {
12805 for (ALL_LIST_ELEMENTS_RO(bgp->peer, lnpeer, peer)) {
12806 /* only provide suggestions on the appropriate input
12807 * token type,
12808 * they'll otherwise show up multiple times */
12809 enum cmd_token_type match_type;
12810 char *name = peer->host;
12811
12812 if (peer->conf_if) {
12813 match_type = VARIABLE_TKN;
12814 name = peer->conf_if;
12815 } else if (strchr(peer->host, ':'))
12816 match_type = IPV6_TKN;
12817 else
12818 match_type = IPV4_TKN;
12819
12820 if (token->type != match_type)
12821 continue;
12822
12823 vector_set(comps, XSTRDUP(MTYPE_COMPLETION, name));
12824 }
12825 }
12826 }
12827
12828 static const struct cmd_variable_handler bgp_var_neighbor[] = {
12829 {.varname = "neighbor", .completions = bgp_ac_neighbor},
12830 {.varname = "neighbors", .completions = bgp_ac_neighbor},
12831 {.varname = "peer", .completions = bgp_ac_neighbor},
12832 {.completions = NULL}};
12833
12834 static void bgp_ac_peergroup(vector comps, struct cmd_token *token)
12835 {
12836 struct bgp *bgp;
12837 struct peer_group *group;
12838 struct listnode *lnbgp, *lnpeer;
12839
12840 for (ALL_LIST_ELEMENTS_RO(bm->bgp, lnbgp, bgp)) {
12841 for (ALL_LIST_ELEMENTS_RO(bgp->group, lnpeer, group))
12842 vector_set(comps, XSTRDUP(MTYPE_COMPLETION,
12843 group->name));
12844 }
12845 }
12846
12847 static const struct cmd_variable_handler bgp_var_peergroup[] = {
12848 {.tokenname = "PGNAME", .completions = bgp_ac_peergroup},
12849 {.completions = NULL} };
12850
12851 void bgp_vty_init(void)
12852 {
12853 cmd_variable_handler_register(bgp_var_neighbor);
12854 cmd_variable_handler_register(bgp_var_peergroup);
12855
12856 /* Install bgp top node. */
12857 install_node(&bgp_node, bgp_config_write);
12858 install_node(&bgp_ipv4_unicast_node, NULL);
12859 install_node(&bgp_ipv4_multicast_node, NULL);
12860 install_node(&bgp_ipv4_labeled_unicast_node, NULL);
12861 install_node(&bgp_ipv6_unicast_node, NULL);
12862 install_node(&bgp_ipv6_multicast_node, NULL);
12863 install_node(&bgp_ipv6_labeled_unicast_node, NULL);
12864 install_node(&bgp_vpnv4_node, NULL);
12865 install_node(&bgp_vpnv6_node, NULL);
12866 install_node(&bgp_evpn_node, NULL);
12867 install_node(&bgp_evpn_vni_node, NULL);
12868 install_node(&bgp_flowspecv4_node, NULL);
12869 install_node(&bgp_flowspecv6_node, NULL);
12870
12871 /* Install default VTY commands to new nodes. */
12872 install_default(BGP_NODE);
12873 install_default(BGP_IPV4_NODE);
12874 install_default(BGP_IPV4M_NODE);
12875 install_default(BGP_IPV4L_NODE);
12876 install_default(BGP_IPV6_NODE);
12877 install_default(BGP_IPV6M_NODE);
12878 install_default(BGP_IPV6L_NODE);
12879 install_default(BGP_VPNV4_NODE);
12880 install_default(BGP_VPNV6_NODE);
12881 install_default(BGP_FLOWSPECV4_NODE);
12882 install_default(BGP_FLOWSPECV6_NODE);
12883 install_default(BGP_EVPN_NODE);
12884 install_default(BGP_EVPN_VNI_NODE);
12885
12886 /* "bgp multiple-instance" commands. */
12887 install_element(CONFIG_NODE, &bgp_multiple_instance_cmd);
12888 install_element(CONFIG_NODE, &no_bgp_multiple_instance_cmd);
12889
12890 /* "bgp config-type" commands. */
12891 install_element(CONFIG_NODE, &bgp_config_type_cmd);
12892 install_element(CONFIG_NODE, &no_bgp_config_type_cmd);
12893
12894 /* "bgp local-mac" hidden commands. */
12895 install_element(CONFIG_NODE, &bgp_local_mac_cmd);
12896 install_element(CONFIG_NODE, &no_bgp_local_mac_cmd);
12897
12898 /* bgp route-map delay-timer commands. */
12899 install_element(CONFIG_NODE, &bgp_set_route_map_delay_timer_cmd);
12900 install_element(CONFIG_NODE, &no_bgp_set_route_map_delay_timer_cmd);
12901
12902 /* Dummy commands (Currently not supported) */
12903 install_element(BGP_NODE, &no_synchronization_cmd);
12904 install_element(BGP_NODE, &no_auto_summary_cmd);
12905
12906 /* "router bgp" commands. */
12907 install_element(CONFIG_NODE, &router_bgp_cmd);
12908
12909 /* "no router bgp" commands. */
12910 install_element(CONFIG_NODE, &no_router_bgp_cmd);
12911
12912 /* "bgp router-id" commands. */
12913 install_element(BGP_NODE, &bgp_router_id_cmd);
12914 install_element(BGP_NODE, &no_bgp_router_id_cmd);
12915
12916 /* "bgp cluster-id" commands. */
12917 install_element(BGP_NODE, &bgp_cluster_id_cmd);
12918 install_element(BGP_NODE, &no_bgp_cluster_id_cmd);
12919
12920 /* "bgp confederation" commands. */
12921 install_element(BGP_NODE, &bgp_confederation_identifier_cmd);
12922 install_element(BGP_NODE, &no_bgp_confederation_identifier_cmd);
12923
12924 /* "bgp confederation peers" commands. */
12925 install_element(BGP_NODE, &bgp_confederation_peers_cmd);
12926 install_element(BGP_NODE, &no_bgp_confederation_peers_cmd);
12927
12928 /* bgp max-med command */
12929 install_element(BGP_NODE, &bgp_maxmed_admin_cmd);
12930 install_element(BGP_NODE, &no_bgp_maxmed_admin_cmd);
12931 install_element(BGP_NODE, &bgp_maxmed_admin_medv_cmd);
12932 install_element(BGP_NODE, &bgp_maxmed_onstartup_cmd);
12933 install_element(BGP_NODE, &no_bgp_maxmed_onstartup_cmd);
12934
12935 /* bgp disable-ebgp-connected-nh-check */
12936 install_element(BGP_NODE, &bgp_disable_connected_route_check_cmd);
12937 install_element(BGP_NODE, &no_bgp_disable_connected_route_check_cmd);
12938
12939 /* bgp update-delay command */
12940 install_element(BGP_NODE, &bgp_update_delay_cmd);
12941 install_element(BGP_NODE, &no_bgp_update_delay_cmd);
12942 install_element(BGP_NODE, &bgp_update_delay_establish_wait_cmd);
12943
12944 install_element(BGP_NODE, &bgp_wpkt_quanta_cmd);
12945 install_element(BGP_NODE, &no_bgp_wpkt_quanta_cmd);
12946 install_element(BGP_NODE, &bgp_rpkt_quanta_cmd);
12947 install_element(BGP_NODE, &no_bgp_rpkt_quanta_cmd);
12948
12949 install_element(BGP_NODE, &bgp_coalesce_time_cmd);
12950 install_element(BGP_NODE, &no_bgp_coalesce_time_cmd);
12951
12952 /* "maximum-paths" commands. */
12953 install_element(BGP_NODE, &bgp_maxpaths_hidden_cmd);
12954 install_element(BGP_NODE, &no_bgp_maxpaths_hidden_cmd);
12955 install_element(BGP_IPV4_NODE, &bgp_maxpaths_cmd);
12956 install_element(BGP_IPV4_NODE, &no_bgp_maxpaths_cmd);
12957 install_element(BGP_IPV6_NODE, &bgp_maxpaths_cmd);
12958 install_element(BGP_IPV6_NODE, &no_bgp_maxpaths_cmd);
12959 install_element(BGP_NODE, &bgp_maxpaths_ibgp_hidden_cmd);
12960 install_element(BGP_NODE, &bgp_maxpaths_ibgp_cluster_hidden_cmd);
12961 install_element(BGP_NODE, &no_bgp_maxpaths_ibgp_hidden_cmd);
12962 install_element(BGP_IPV4_NODE, &bgp_maxpaths_ibgp_cmd);
12963 install_element(BGP_IPV4_NODE, &bgp_maxpaths_ibgp_cluster_cmd);
12964 install_element(BGP_IPV4_NODE, &no_bgp_maxpaths_ibgp_cmd);
12965 install_element(BGP_IPV6_NODE, &bgp_maxpaths_ibgp_cmd);
12966 install_element(BGP_IPV6_NODE, &bgp_maxpaths_ibgp_cluster_cmd);
12967 install_element(BGP_IPV6_NODE, &no_bgp_maxpaths_ibgp_cmd);
12968
12969 install_element(BGP_IPV6L_NODE, &bgp_maxpaths_cmd);
12970 install_element(BGP_IPV6L_NODE, &no_bgp_maxpaths_cmd);
12971 install_element(BGP_IPV6L_NODE, &bgp_maxpaths_ibgp_cmd);
12972 install_element(BGP_IPV6L_NODE, &bgp_maxpaths_ibgp_cluster_cmd);
12973 install_element(BGP_IPV6L_NODE, &no_bgp_maxpaths_ibgp_cmd);
12974
12975 /* "timers bgp" commands. */
12976 install_element(BGP_NODE, &bgp_timers_cmd);
12977 install_element(BGP_NODE, &no_bgp_timers_cmd);
12978
12979 /* route-map delay-timer commands - per instance for backwards compat.
12980 */
12981 install_element(BGP_NODE, &bgp_set_route_map_delay_timer_cmd);
12982 install_element(BGP_NODE, &no_bgp_set_route_map_delay_timer_cmd);
12983
12984 /* "bgp client-to-client reflection" commands */
12985 install_element(BGP_NODE, &no_bgp_client_to_client_reflection_cmd);
12986 install_element(BGP_NODE, &bgp_client_to_client_reflection_cmd);
12987
12988 /* "bgp always-compare-med" commands */
12989 install_element(BGP_NODE, &bgp_always_compare_med_cmd);
12990 install_element(BGP_NODE, &no_bgp_always_compare_med_cmd);
12991
12992 /* bgp ebgp-requires-policy */
12993 install_element(BGP_NODE, &bgp_ebgp_requires_policy_cmd);
12994 install_element(BGP_NODE, &no_bgp_ebgp_requires_policy_cmd);
12995
12996 /* "bgp deterministic-med" commands */
12997 install_element(BGP_NODE, &bgp_deterministic_med_cmd);
12998 install_element(BGP_NODE, &no_bgp_deterministic_med_cmd);
12999
13000 /* "bgp graceful-restart" commands */
13001 install_element(BGP_NODE, &bgp_graceful_restart_cmd);
13002 install_element(BGP_NODE, &no_bgp_graceful_restart_cmd);
13003 install_element(BGP_NODE, &bgp_graceful_restart_stalepath_time_cmd);
13004 install_element(BGP_NODE, &no_bgp_graceful_restart_stalepath_time_cmd);
13005 install_element(BGP_NODE, &bgp_graceful_restart_restart_time_cmd);
13006 install_element(BGP_NODE, &no_bgp_graceful_restart_restart_time_cmd);
13007
13008 install_element(BGP_NODE, &bgp_graceful_restart_preserve_fw_cmd);
13009 install_element(BGP_NODE, &no_bgp_graceful_restart_preserve_fw_cmd);
13010
13011 /* "bgp graceful-shutdown" commands */
13012 install_element(BGP_NODE, &bgp_graceful_shutdown_cmd);
13013 install_element(BGP_NODE, &no_bgp_graceful_shutdown_cmd);
13014
13015 /* "bgp fast-external-failover" commands */
13016 install_element(BGP_NODE, &bgp_fast_external_failover_cmd);
13017 install_element(BGP_NODE, &no_bgp_fast_external_failover_cmd);
13018
13019 /* "bgp enforce-first-as" commands */
13020 install_element(BGP_NODE, &bgp_enforce_first_as_cmd);
13021
13022 /* "bgp bestpath compare-routerid" commands */
13023 install_element(BGP_NODE, &bgp_bestpath_compare_router_id_cmd);
13024 install_element(BGP_NODE, &no_bgp_bestpath_compare_router_id_cmd);
13025
13026 /* "bgp bestpath as-path ignore" commands */
13027 install_element(BGP_NODE, &bgp_bestpath_aspath_ignore_cmd);
13028 install_element(BGP_NODE, &no_bgp_bestpath_aspath_ignore_cmd);
13029
13030 /* "bgp bestpath as-path confed" commands */
13031 install_element(BGP_NODE, &bgp_bestpath_aspath_confed_cmd);
13032 install_element(BGP_NODE, &no_bgp_bestpath_aspath_confed_cmd);
13033
13034 /* "bgp bestpath as-path multipath-relax" commands */
13035 install_element(BGP_NODE, &bgp_bestpath_aspath_multipath_relax_cmd);
13036 install_element(BGP_NODE, &no_bgp_bestpath_aspath_multipath_relax_cmd);
13037
13038 /* "bgp log-neighbor-changes" commands */
13039 install_element(BGP_NODE, &bgp_log_neighbor_changes_cmd);
13040 install_element(BGP_NODE, &no_bgp_log_neighbor_changes_cmd);
13041
13042 /* "bgp bestpath med" commands */
13043 install_element(BGP_NODE, &bgp_bestpath_med_cmd);
13044 install_element(BGP_NODE, &no_bgp_bestpath_med_cmd);
13045
13046 /* "no bgp default ipv4-unicast" commands. */
13047 install_element(BGP_NODE, &no_bgp_default_ipv4_unicast_cmd);
13048 install_element(BGP_NODE, &bgp_default_ipv4_unicast_cmd);
13049
13050 /* "bgp network import-check" commands. */
13051 install_element(BGP_NODE, &bgp_network_import_check_cmd);
13052 install_element(BGP_NODE, &bgp_network_import_check_exact_cmd);
13053 install_element(BGP_NODE, &no_bgp_network_import_check_cmd);
13054
13055 /* "bgp default local-preference" commands. */
13056 install_element(BGP_NODE, &bgp_default_local_preference_cmd);
13057 install_element(BGP_NODE, &no_bgp_default_local_preference_cmd);
13058
13059 /* bgp default show-hostname */
13060 install_element(BGP_NODE, &bgp_default_show_hostname_cmd);
13061 install_element(BGP_NODE, &no_bgp_default_show_hostname_cmd);
13062
13063 /* "bgp default subgroup-pkt-queue-max" commands. */
13064 install_element(BGP_NODE, &bgp_default_subgroup_pkt_queue_max_cmd);
13065 install_element(BGP_NODE, &no_bgp_default_subgroup_pkt_queue_max_cmd);
13066
13067 /* bgp ibgp-allow-policy-mods command */
13068 install_element(BGP_NODE, &bgp_rr_allow_outbound_policy_cmd);
13069 install_element(BGP_NODE, &no_bgp_rr_allow_outbound_policy_cmd);
13070
13071 /* "bgp listen limit" commands. */
13072 install_element(BGP_NODE, &bgp_listen_limit_cmd);
13073 install_element(BGP_NODE, &no_bgp_listen_limit_cmd);
13074
13075 /* "bgp listen range" commands. */
13076 install_element(BGP_NODE, &bgp_listen_range_cmd);
13077 install_element(BGP_NODE, &no_bgp_listen_range_cmd);
13078
13079 /* "bgp default shutdown" command */
13080 install_element(BGP_NODE, &bgp_default_shutdown_cmd);
13081
13082 /* "neighbor remote-as" commands. */
13083 install_element(BGP_NODE, &neighbor_remote_as_cmd);
13084 install_element(BGP_NODE, &neighbor_interface_config_cmd);
13085 install_element(BGP_NODE, &neighbor_interface_config_v6only_cmd);
13086 install_element(BGP_NODE, &neighbor_interface_config_remote_as_cmd);
13087 install_element(BGP_NODE,
13088 &neighbor_interface_v6only_config_remote_as_cmd);
13089 install_element(BGP_NODE, &no_neighbor_cmd);
13090 install_element(BGP_NODE, &no_neighbor_interface_config_cmd);
13091
13092 /* "neighbor peer-group" commands. */
13093 install_element(BGP_NODE, &neighbor_peer_group_cmd);
13094 install_element(BGP_NODE, &no_neighbor_peer_group_cmd);
13095 install_element(BGP_NODE,
13096 &no_neighbor_interface_peer_group_remote_as_cmd);
13097
13098 /* "neighbor local-as" commands. */
13099 install_element(BGP_NODE, &neighbor_local_as_cmd);
13100 install_element(BGP_NODE, &neighbor_local_as_no_prepend_cmd);
13101 install_element(BGP_NODE, &neighbor_local_as_no_prepend_replace_as_cmd);
13102 install_element(BGP_NODE, &no_neighbor_local_as_cmd);
13103
13104 /* "neighbor solo" commands. */
13105 install_element(BGP_NODE, &neighbor_solo_cmd);
13106 install_element(BGP_NODE, &no_neighbor_solo_cmd);
13107
13108 /* "neighbor password" commands. */
13109 install_element(BGP_NODE, &neighbor_password_cmd);
13110 install_element(BGP_NODE, &no_neighbor_password_cmd);
13111
13112 /* "neighbor activate" commands. */
13113 install_element(BGP_NODE, &neighbor_activate_hidden_cmd);
13114 install_element(BGP_IPV4_NODE, &neighbor_activate_cmd);
13115 install_element(BGP_IPV4M_NODE, &neighbor_activate_cmd);
13116 install_element(BGP_IPV4L_NODE, &neighbor_activate_cmd);
13117 install_element(BGP_IPV6_NODE, &neighbor_activate_cmd);
13118 install_element(BGP_IPV6M_NODE, &neighbor_activate_cmd);
13119 install_element(BGP_IPV6L_NODE, &neighbor_activate_cmd);
13120 install_element(BGP_VPNV4_NODE, &neighbor_activate_cmd);
13121 install_element(BGP_VPNV6_NODE, &neighbor_activate_cmd);
13122 install_element(BGP_FLOWSPECV4_NODE, &neighbor_activate_cmd);
13123 install_element(BGP_FLOWSPECV6_NODE, &neighbor_activate_cmd);
13124 install_element(BGP_EVPN_NODE, &neighbor_activate_cmd);
13125
13126 /* "no neighbor activate" commands. */
13127 install_element(BGP_NODE, &no_neighbor_activate_hidden_cmd);
13128 install_element(BGP_IPV4_NODE, &no_neighbor_activate_cmd);
13129 install_element(BGP_IPV4M_NODE, &no_neighbor_activate_cmd);
13130 install_element(BGP_IPV4L_NODE, &no_neighbor_activate_cmd);
13131 install_element(BGP_IPV6_NODE, &no_neighbor_activate_cmd);
13132 install_element(BGP_IPV6M_NODE, &no_neighbor_activate_cmd);
13133 install_element(BGP_IPV6L_NODE, &no_neighbor_activate_cmd);
13134 install_element(BGP_VPNV4_NODE, &no_neighbor_activate_cmd);
13135 install_element(BGP_VPNV6_NODE, &no_neighbor_activate_cmd);
13136 install_element(BGP_FLOWSPECV4_NODE, &no_neighbor_activate_cmd);
13137 install_element(BGP_FLOWSPECV6_NODE, &no_neighbor_activate_cmd);
13138 install_element(BGP_EVPN_NODE, &no_neighbor_activate_cmd);
13139
13140 /* "neighbor peer-group" set commands. */
13141 install_element(BGP_NODE, &neighbor_set_peer_group_cmd);
13142 install_element(BGP_IPV4_NODE, &neighbor_set_peer_group_hidden_cmd);
13143 install_element(BGP_IPV4M_NODE, &neighbor_set_peer_group_hidden_cmd);
13144 install_element(BGP_IPV6_NODE, &neighbor_set_peer_group_hidden_cmd);
13145 install_element(BGP_IPV6M_NODE, &neighbor_set_peer_group_hidden_cmd);
13146 install_element(BGP_IPV6L_NODE, &neighbor_set_peer_group_hidden_cmd);
13147 install_element(BGP_VPNV4_NODE, &neighbor_set_peer_group_hidden_cmd);
13148 install_element(BGP_VPNV6_NODE, &neighbor_set_peer_group_hidden_cmd);
13149 install_element(BGP_FLOWSPECV4_NODE,
13150 &neighbor_set_peer_group_hidden_cmd);
13151 install_element(BGP_FLOWSPECV6_NODE,
13152 &neighbor_set_peer_group_hidden_cmd);
13153
13154 /* "no neighbor peer-group unset" commands. */
13155 install_element(BGP_NODE, &no_neighbor_set_peer_group_cmd);
13156 install_element(BGP_IPV4_NODE, &no_neighbor_set_peer_group_hidden_cmd);
13157 install_element(BGP_IPV4M_NODE, &no_neighbor_set_peer_group_hidden_cmd);
13158 install_element(BGP_IPV6_NODE, &no_neighbor_set_peer_group_hidden_cmd);
13159 install_element(BGP_IPV6M_NODE, &no_neighbor_set_peer_group_hidden_cmd);
13160 install_element(BGP_IPV6L_NODE, &no_neighbor_set_peer_group_hidden_cmd);
13161 install_element(BGP_VPNV4_NODE, &no_neighbor_set_peer_group_hidden_cmd);
13162 install_element(BGP_VPNV6_NODE, &no_neighbor_set_peer_group_hidden_cmd);
13163 install_element(BGP_FLOWSPECV4_NODE,
13164 &no_neighbor_set_peer_group_hidden_cmd);
13165 install_element(BGP_FLOWSPECV6_NODE,
13166 &no_neighbor_set_peer_group_hidden_cmd);
13167
13168 /* "neighbor softreconfiguration inbound" commands.*/
13169 install_element(BGP_NODE, &neighbor_soft_reconfiguration_hidden_cmd);
13170 install_element(BGP_NODE, &no_neighbor_soft_reconfiguration_hidden_cmd);
13171 install_element(BGP_IPV4_NODE, &neighbor_soft_reconfiguration_cmd);
13172 install_element(BGP_IPV4_NODE, &no_neighbor_soft_reconfiguration_cmd);
13173 install_element(BGP_IPV4L_NODE, &neighbor_soft_reconfiguration_cmd);
13174 install_element(BGP_IPV4L_NODE, &no_neighbor_soft_reconfiguration_cmd);
13175 install_element(BGP_IPV4M_NODE, &neighbor_soft_reconfiguration_cmd);
13176 install_element(BGP_IPV4M_NODE, &no_neighbor_soft_reconfiguration_cmd);
13177 install_element(BGP_IPV6_NODE, &neighbor_soft_reconfiguration_cmd);
13178 install_element(BGP_IPV6_NODE, &no_neighbor_soft_reconfiguration_cmd);
13179 install_element(BGP_IPV6M_NODE, &neighbor_soft_reconfiguration_cmd);
13180 install_element(BGP_IPV6M_NODE, &no_neighbor_soft_reconfiguration_cmd);
13181 install_element(BGP_IPV6L_NODE, &neighbor_soft_reconfiguration_cmd);
13182 install_element(BGP_IPV6L_NODE, &no_neighbor_soft_reconfiguration_cmd);
13183 install_element(BGP_VPNV4_NODE, &neighbor_soft_reconfiguration_cmd);
13184 install_element(BGP_VPNV4_NODE, &no_neighbor_soft_reconfiguration_cmd);
13185 install_element(BGP_VPNV6_NODE, &neighbor_soft_reconfiguration_cmd);
13186 install_element(BGP_VPNV6_NODE, &no_neighbor_soft_reconfiguration_cmd);
13187 install_element(BGP_FLOWSPECV4_NODE,
13188 &neighbor_soft_reconfiguration_cmd);
13189 install_element(BGP_FLOWSPECV4_NODE,
13190 &no_neighbor_soft_reconfiguration_cmd);
13191 install_element(BGP_FLOWSPECV6_NODE,
13192 &neighbor_soft_reconfiguration_cmd);
13193 install_element(BGP_FLOWSPECV6_NODE,
13194 &no_neighbor_soft_reconfiguration_cmd);
13195 install_element(BGP_EVPN_NODE, &neighbor_soft_reconfiguration_cmd);
13196 install_element(BGP_EVPN_NODE, &no_neighbor_soft_reconfiguration_cmd);
13197
13198 /* "neighbor attribute-unchanged" commands. */
13199 install_element(BGP_NODE, &neighbor_attr_unchanged_hidden_cmd);
13200 install_element(BGP_NODE, &no_neighbor_attr_unchanged_hidden_cmd);
13201 install_element(BGP_IPV4_NODE, &neighbor_attr_unchanged_cmd);
13202 install_element(BGP_IPV4_NODE, &no_neighbor_attr_unchanged_cmd);
13203 install_element(BGP_IPV4M_NODE, &neighbor_attr_unchanged_cmd);
13204 install_element(BGP_IPV4M_NODE, &no_neighbor_attr_unchanged_cmd);
13205 install_element(BGP_IPV4L_NODE, &neighbor_attr_unchanged_cmd);
13206 install_element(BGP_IPV4L_NODE, &no_neighbor_attr_unchanged_cmd);
13207 install_element(BGP_IPV6_NODE, &neighbor_attr_unchanged_cmd);
13208 install_element(BGP_IPV6_NODE, &no_neighbor_attr_unchanged_cmd);
13209 install_element(BGP_IPV6M_NODE, &neighbor_attr_unchanged_cmd);
13210 install_element(BGP_IPV6M_NODE, &no_neighbor_attr_unchanged_cmd);
13211 install_element(BGP_IPV6L_NODE, &neighbor_attr_unchanged_cmd);
13212 install_element(BGP_IPV6L_NODE, &no_neighbor_attr_unchanged_cmd);
13213 install_element(BGP_VPNV4_NODE, &neighbor_attr_unchanged_cmd);
13214 install_element(BGP_VPNV4_NODE, &no_neighbor_attr_unchanged_cmd);
13215 install_element(BGP_VPNV6_NODE, &neighbor_attr_unchanged_cmd);
13216 install_element(BGP_VPNV6_NODE, &no_neighbor_attr_unchanged_cmd);
13217
13218 install_element(BGP_EVPN_NODE, &neighbor_attr_unchanged_cmd);
13219 install_element(BGP_EVPN_NODE, &no_neighbor_attr_unchanged_cmd);
13220
13221 /* "nexthop-local unchanged" commands */
13222 install_element(BGP_IPV6_NODE, &neighbor_nexthop_local_unchanged_cmd);
13223 install_element(BGP_IPV6_NODE,
13224 &no_neighbor_nexthop_local_unchanged_cmd);
13225
13226 /* "neighbor next-hop-self" commands. */
13227 install_element(BGP_NODE, &neighbor_nexthop_self_hidden_cmd);
13228 install_element(BGP_NODE, &no_neighbor_nexthop_self_hidden_cmd);
13229 install_element(BGP_IPV4_NODE, &neighbor_nexthop_self_cmd);
13230 install_element(BGP_IPV4_NODE, &no_neighbor_nexthop_self_cmd);
13231 install_element(BGP_IPV4M_NODE, &neighbor_nexthop_self_cmd);
13232 install_element(BGP_IPV4M_NODE, &no_neighbor_nexthop_self_cmd);
13233 install_element(BGP_IPV4L_NODE, &neighbor_nexthop_self_cmd);
13234 install_element(BGP_IPV4L_NODE, &no_neighbor_nexthop_self_cmd);
13235 install_element(BGP_IPV6_NODE, &neighbor_nexthop_self_cmd);
13236 install_element(BGP_IPV6_NODE, &no_neighbor_nexthop_self_cmd);
13237 install_element(BGP_IPV6M_NODE, &neighbor_nexthop_self_cmd);
13238 install_element(BGP_IPV6M_NODE, &no_neighbor_nexthop_self_cmd);
13239 install_element(BGP_IPV6L_NODE, &neighbor_nexthop_self_cmd);
13240 install_element(BGP_IPV6L_NODE, &no_neighbor_nexthop_self_cmd);
13241 install_element(BGP_VPNV4_NODE, &neighbor_nexthop_self_cmd);
13242 install_element(BGP_VPNV4_NODE, &no_neighbor_nexthop_self_cmd);
13243 install_element(BGP_VPNV6_NODE, &neighbor_nexthop_self_cmd);
13244 install_element(BGP_VPNV6_NODE, &no_neighbor_nexthop_self_cmd);
13245 install_element(BGP_EVPN_NODE, &neighbor_nexthop_self_cmd);
13246 install_element(BGP_EVPN_NODE, &no_neighbor_nexthop_self_cmd);
13247
13248 /* "neighbor next-hop-self force" commands. */
13249 install_element(BGP_NODE, &neighbor_nexthop_self_force_hidden_cmd);
13250 install_element(BGP_NODE, &no_neighbor_nexthop_self_force_hidden_cmd);
13251 install_element(BGP_NODE, &neighbor_nexthop_self_all_hidden_cmd);
13252 install_element(BGP_NODE, &no_neighbor_nexthop_self_all_hidden_cmd);
13253 install_element(BGP_IPV4_NODE, &neighbor_nexthop_self_force_cmd);
13254 install_element(BGP_IPV4_NODE, &no_neighbor_nexthop_self_force_cmd);
13255 install_element(BGP_IPV4M_NODE, &neighbor_nexthop_self_force_cmd);
13256 install_element(BGP_IPV4M_NODE, &no_neighbor_nexthop_self_force_cmd);
13257 install_element(BGP_IPV4L_NODE, &neighbor_nexthop_self_force_cmd);
13258 install_element(BGP_IPV4L_NODE, &no_neighbor_nexthop_self_force_cmd);
13259 install_element(BGP_IPV6_NODE, &neighbor_nexthop_self_force_cmd);
13260 install_element(BGP_IPV6_NODE, &no_neighbor_nexthop_self_force_cmd);
13261 install_element(BGP_IPV6M_NODE, &neighbor_nexthop_self_force_cmd);
13262 install_element(BGP_IPV6M_NODE, &no_neighbor_nexthop_self_force_cmd);
13263 install_element(BGP_IPV6L_NODE, &neighbor_nexthop_self_force_cmd);
13264 install_element(BGP_IPV6L_NODE, &no_neighbor_nexthop_self_force_cmd);
13265 install_element(BGP_VPNV4_NODE, &neighbor_nexthop_self_force_cmd);
13266 install_element(BGP_VPNV4_NODE, &no_neighbor_nexthop_self_force_cmd);
13267 install_element(BGP_VPNV6_NODE, &neighbor_nexthop_self_force_cmd);
13268 install_element(BGP_VPNV6_NODE, &no_neighbor_nexthop_self_force_cmd);
13269
13270 /* "neighbor as-override" commands. */
13271 install_element(BGP_NODE, &neighbor_as_override_hidden_cmd);
13272 install_element(BGP_NODE, &no_neighbor_as_override_hidden_cmd);
13273 install_element(BGP_IPV4_NODE, &neighbor_as_override_cmd);
13274 install_element(BGP_IPV4_NODE, &no_neighbor_as_override_cmd);
13275 install_element(BGP_IPV4M_NODE, &neighbor_as_override_cmd);
13276 install_element(BGP_IPV4M_NODE, &no_neighbor_as_override_cmd);
13277 install_element(BGP_IPV4L_NODE, &neighbor_as_override_cmd);
13278 install_element(BGP_IPV4L_NODE, &no_neighbor_as_override_cmd);
13279 install_element(BGP_IPV6_NODE, &neighbor_as_override_cmd);
13280 install_element(BGP_IPV6_NODE, &no_neighbor_as_override_cmd);
13281 install_element(BGP_IPV6M_NODE, &neighbor_as_override_cmd);
13282 install_element(BGP_IPV6M_NODE, &no_neighbor_as_override_cmd);
13283 install_element(BGP_IPV6L_NODE, &neighbor_as_override_cmd);
13284 install_element(BGP_IPV6L_NODE, &no_neighbor_as_override_cmd);
13285 install_element(BGP_VPNV4_NODE, &neighbor_as_override_cmd);
13286 install_element(BGP_VPNV4_NODE, &no_neighbor_as_override_cmd);
13287 install_element(BGP_VPNV6_NODE, &neighbor_as_override_cmd);
13288 install_element(BGP_VPNV6_NODE, &no_neighbor_as_override_cmd);
13289
13290 /* "neighbor remove-private-AS" commands. */
13291 install_element(BGP_NODE, &neighbor_remove_private_as_hidden_cmd);
13292 install_element(BGP_NODE, &no_neighbor_remove_private_as_hidden_cmd);
13293 install_element(BGP_NODE, &neighbor_remove_private_as_all_hidden_cmd);
13294 install_element(BGP_NODE,
13295 &no_neighbor_remove_private_as_all_hidden_cmd);
13296 install_element(BGP_NODE,
13297 &neighbor_remove_private_as_replace_as_hidden_cmd);
13298 install_element(BGP_NODE,
13299 &no_neighbor_remove_private_as_replace_as_hidden_cmd);
13300 install_element(BGP_NODE,
13301 &neighbor_remove_private_as_all_replace_as_hidden_cmd);
13302 install_element(
13303 BGP_NODE,
13304 &no_neighbor_remove_private_as_all_replace_as_hidden_cmd);
13305 install_element(BGP_IPV4_NODE, &neighbor_remove_private_as_cmd);
13306 install_element(BGP_IPV4_NODE, &no_neighbor_remove_private_as_cmd);
13307 install_element(BGP_IPV4_NODE, &neighbor_remove_private_as_all_cmd);
13308 install_element(BGP_IPV4_NODE, &no_neighbor_remove_private_as_all_cmd);
13309 install_element(BGP_IPV4_NODE,
13310 &neighbor_remove_private_as_replace_as_cmd);
13311 install_element(BGP_IPV4_NODE,
13312 &no_neighbor_remove_private_as_replace_as_cmd);
13313 install_element(BGP_IPV4_NODE,
13314 &neighbor_remove_private_as_all_replace_as_cmd);
13315 install_element(BGP_IPV4_NODE,
13316 &no_neighbor_remove_private_as_all_replace_as_cmd);
13317 install_element(BGP_IPV4M_NODE, &neighbor_remove_private_as_cmd);
13318 install_element(BGP_IPV4M_NODE, &no_neighbor_remove_private_as_cmd);
13319 install_element(BGP_IPV4M_NODE, &neighbor_remove_private_as_all_cmd);
13320 install_element(BGP_IPV4M_NODE, &no_neighbor_remove_private_as_all_cmd);
13321 install_element(BGP_IPV4M_NODE,
13322 &neighbor_remove_private_as_replace_as_cmd);
13323 install_element(BGP_IPV4M_NODE,
13324 &no_neighbor_remove_private_as_replace_as_cmd);
13325 install_element(BGP_IPV4M_NODE,
13326 &neighbor_remove_private_as_all_replace_as_cmd);
13327 install_element(BGP_IPV4M_NODE,
13328 &no_neighbor_remove_private_as_all_replace_as_cmd);
13329 install_element(BGP_IPV4L_NODE, &neighbor_remove_private_as_cmd);
13330 install_element(BGP_IPV4L_NODE, &no_neighbor_remove_private_as_cmd);
13331 install_element(BGP_IPV4L_NODE, &neighbor_remove_private_as_all_cmd);
13332 install_element(BGP_IPV4L_NODE, &no_neighbor_remove_private_as_all_cmd);
13333 install_element(BGP_IPV4L_NODE,
13334 &neighbor_remove_private_as_replace_as_cmd);
13335 install_element(BGP_IPV4L_NODE,
13336 &no_neighbor_remove_private_as_replace_as_cmd);
13337 install_element(BGP_IPV4L_NODE,
13338 &neighbor_remove_private_as_all_replace_as_cmd);
13339 install_element(BGP_IPV4L_NODE,
13340 &no_neighbor_remove_private_as_all_replace_as_cmd);
13341 install_element(BGP_IPV6_NODE, &neighbor_remove_private_as_cmd);
13342 install_element(BGP_IPV6_NODE, &no_neighbor_remove_private_as_cmd);
13343 install_element(BGP_IPV6_NODE, &neighbor_remove_private_as_all_cmd);
13344 install_element(BGP_IPV6_NODE, &no_neighbor_remove_private_as_all_cmd);
13345 install_element(BGP_IPV6_NODE,
13346 &neighbor_remove_private_as_replace_as_cmd);
13347 install_element(BGP_IPV6_NODE,
13348 &no_neighbor_remove_private_as_replace_as_cmd);
13349 install_element(BGP_IPV6_NODE,
13350 &neighbor_remove_private_as_all_replace_as_cmd);
13351 install_element(BGP_IPV6_NODE,
13352 &no_neighbor_remove_private_as_all_replace_as_cmd);
13353 install_element(BGP_IPV6M_NODE, &neighbor_remove_private_as_cmd);
13354 install_element(BGP_IPV6M_NODE, &no_neighbor_remove_private_as_cmd);
13355 install_element(BGP_IPV6M_NODE, &neighbor_remove_private_as_all_cmd);
13356 install_element(BGP_IPV6M_NODE, &no_neighbor_remove_private_as_all_cmd);
13357 install_element(BGP_IPV6M_NODE,
13358 &neighbor_remove_private_as_replace_as_cmd);
13359 install_element(BGP_IPV6M_NODE,
13360 &no_neighbor_remove_private_as_replace_as_cmd);
13361 install_element(BGP_IPV6M_NODE,
13362 &neighbor_remove_private_as_all_replace_as_cmd);
13363 install_element(BGP_IPV6M_NODE,
13364 &no_neighbor_remove_private_as_all_replace_as_cmd);
13365 install_element(BGP_IPV6L_NODE, &neighbor_remove_private_as_cmd);
13366 install_element(BGP_IPV6L_NODE, &no_neighbor_remove_private_as_cmd);
13367 install_element(BGP_IPV6L_NODE, &neighbor_remove_private_as_all_cmd);
13368 install_element(BGP_IPV6L_NODE, &no_neighbor_remove_private_as_all_cmd);
13369 install_element(BGP_IPV6L_NODE,
13370 &neighbor_remove_private_as_replace_as_cmd);
13371 install_element(BGP_IPV6L_NODE,
13372 &no_neighbor_remove_private_as_replace_as_cmd);
13373 install_element(BGP_IPV6L_NODE,
13374 &neighbor_remove_private_as_all_replace_as_cmd);
13375 install_element(BGP_IPV6L_NODE,
13376 &no_neighbor_remove_private_as_all_replace_as_cmd);
13377 install_element(BGP_VPNV4_NODE, &neighbor_remove_private_as_cmd);
13378 install_element(BGP_VPNV4_NODE, &no_neighbor_remove_private_as_cmd);
13379 install_element(BGP_VPNV4_NODE, &neighbor_remove_private_as_all_cmd);
13380 install_element(BGP_VPNV4_NODE, &no_neighbor_remove_private_as_all_cmd);
13381 install_element(BGP_VPNV4_NODE,
13382 &neighbor_remove_private_as_replace_as_cmd);
13383 install_element(BGP_VPNV4_NODE,
13384 &no_neighbor_remove_private_as_replace_as_cmd);
13385 install_element(BGP_VPNV4_NODE,
13386 &neighbor_remove_private_as_all_replace_as_cmd);
13387 install_element(BGP_VPNV4_NODE,
13388 &no_neighbor_remove_private_as_all_replace_as_cmd);
13389 install_element(BGP_VPNV6_NODE, &neighbor_remove_private_as_cmd);
13390 install_element(BGP_VPNV6_NODE, &no_neighbor_remove_private_as_cmd);
13391 install_element(BGP_VPNV6_NODE, &neighbor_remove_private_as_all_cmd);
13392 install_element(BGP_VPNV6_NODE, &no_neighbor_remove_private_as_all_cmd);
13393 install_element(BGP_VPNV6_NODE,
13394 &neighbor_remove_private_as_replace_as_cmd);
13395 install_element(BGP_VPNV6_NODE,
13396 &no_neighbor_remove_private_as_replace_as_cmd);
13397 install_element(BGP_VPNV6_NODE,
13398 &neighbor_remove_private_as_all_replace_as_cmd);
13399 install_element(BGP_VPNV6_NODE,
13400 &no_neighbor_remove_private_as_all_replace_as_cmd);
13401
13402 /* "neighbor send-community" commands.*/
13403 install_element(BGP_NODE, &neighbor_send_community_hidden_cmd);
13404 install_element(BGP_NODE, &neighbor_send_community_type_hidden_cmd);
13405 install_element(BGP_NODE, &no_neighbor_send_community_hidden_cmd);
13406 install_element(BGP_NODE, &no_neighbor_send_community_type_hidden_cmd);
13407 install_element(BGP_IPV4_NODE, &neighbor_send_community_cmd);
13408 install_element(BGP_IPV4_NODE, &neighbor_send_community_type_cmd);
13409 install_element(BGP_IPV4_NODE, &no_neighbor_send_community_cmd);
13410 install_element(BGP_IPV4_NODE, &no_neighbor_send_community_type_cmd);
13411 install_element(BGP_IPV4M_NODE, &neighbor_send_community_cmd);
13412 install_element(BGP_IPV4M_NODE, &neighbor_send_community_type_cmd);
13413 install_element(BGP_IPV4M_NODE, &no_neighbor_send_community_cmd);
13414 install_element(BGP_IPV4M_NODE, &no_neighbor_send_community_type_cmd);
13415 install_element(BGP_IPV4L_NODE, &neighbor_send_community_cmd);
13416 install_element(BGP_IPV4L_NODE, &neighbor_send_community_type_cmd);
13417 install_element(BGP_IPV4L_NODE, &no_neighbor_send_community_cmd);
13418 install_element(BGP_IPV4L_NODE, &no_neighbor_send_community_type_cmd);
13419 install_element(BGP_IPV6_NODE, &neighbor_send_community_cmd);
13420 install_element(BGP_IPV6_NODE, &neighbor_send_community_type_cmd);
13421 install_element(BGP_IPV6_NODE, &no_neighbor_send_community_cmd);
13422 install_element(BGP_IPV6_NODE, &no_neighbor_send_community_type_cmd);
13423 install_element(BGP_IPV6M_NODE, &neighbor_send_community_cmd);
13424 install_element(BGP_IPV6M_NODE, &neighbor_send_community_type_cmd);
13425 install_element(BGP_IPV6M_NODE, &no_neighbor_send_community_cmd);
13426 install_element(BGP_IPV6M_NODE, &no_neighbor_send_community_type_cmd);
13427 install_element(BGP_IPV6L_NODE, &neighbor_send_community_cmd);
13428 install_element(BGP_IPV6L_NODE, &neighbor_send_community_type_cmd);
13429 install_element(BGP_IPV6L_NODE, &no_neighbor_send_community_cmd);
13430 install_element(BGP_IPV6L_NODE, &no_neighbor_send_community_type_cmd);
13431 install_element(BGP_VPNV4_NODE, &neighbor_send_community_cmd);
13432 install_element(BGP_VPNV4_NODE, &neighbor_send_community_type_cmd);
13433 install_element(BGP_VPNV4_NODE, &no_neighbor_send_community_cmd);
13434 install_element(BGP_VPNV4_NODE, &no_neighbor_send_community_type_cmd);
13435 install_element(BGP_VPNV6_NODE, &neighbor_send_community_cmd);
13436 install_element(BGP_VPNV6_NODE, &neighbor_send_community_type_cmd);
13437 install_element(BGP_VPNV6_NODE, &no_neighbor_send_community_cmd);
13438 install_element(BGP_VPNV6_NODE, &no_neighbor_send_community_type_cmd);
13439
13440 /* "neighbor route-reflector" commands.*/
13441 install_element(BGP_NODE, &neighbor_route_reflector_client_hidden_cmd);
13442 install_element(BGP_NODE,
13443 &no_neighbor_route_reflector_client_hidden_cmd);
13444 install_element(BGP_IPV4_NODE, &neighbor_route_reflector_client_cmd);
13445 install_element(BGP_IPV4_NODE, &no_neighbor_route_reflector_client_cmd);
13446 install_element(BGP_IPV4M_NODE, &neighbor_route_reflector_client_cmd);
13447 install_element(BGP_IPV4M_NODE,
13448 &no_neighbor_route_reflector_client_cmd);
13449 install_element(BGP_IPV4L_NODE, &neighbor_route_reflector_client_cmd);
13450 install_element(BGP_IPV4L_NODE,
13451 &no_neighbor_route_reflector_client_cmd);
13452 install_element(BGP_IPV6_NODE, &neighbor_route_reflector_client_cmd);
13453 install_element(BGP_IPV6_NODE, &no_neighbor_route_reflector_client_cmd);
13454 install_element(BGP_IPV6M_NODE, &neighbor_route_reflector_client_cmd);
13455 install_element(BGP_IPV6M_NODE,
13456 &no_neighbor_route_reflector_client_cmd);
13457 install_element(BGP_IPV6L_NODE, &neighbor_route_reflector_client_cmd);
13458 install_element(BGP_IPV6L_NODE,
13459 &no_neighbor_route_reflector_client_cmd);
13460 install_element(BGP_VPNV4_NODE, &neighbor_route_reflector_client_cmd);
13461 install_element(BGP_VPNV4_NODE,
13462 &no_neighbor_route_reflector_client_cmd);
13463 install_element(BGP_VPNV6_NODE, &neighbor_route_reflector_client_cmd);
13464 install_element(BGP_VPNV6_NODE,
13465 &no_neighbor_route_reflector_client_cmd);
13466 install_element(BGP_FLOWSPECV4_NODE,
13467 &neighbor_route_reflector_client_cmd);
13468 install_element(BGP_FLOWSPECV4_NODE,
13469 &no_neighbor_route_reflector_client_cmd);
13470 install_element(BGP_FLOWSPECV6_NODE,
13471 &neighbor_route_reflector_client_cmd);
13472 install_element(BGP_FLOWSPECV6_NODE,
13473 &no_neighbor_route_reflector_client_cmd);
13474 install_element(BGP_EVPN_NODE, &neighbor_route_reflector_client_cmd);
13475 install_element(BGP_EVPN_NODE, &no_neighbor_route_reflector_client_cmd);
13476
13477 /* "neighbor route-server" commands.*/
13478 install_element(BGP_NODE, &neighbor_route_server_client_hidden_cmd);
13479 install_element(BGP_NODE, &no_neighbor_route_server_client_hidden_cmd);
13480 install_element(BGP_IPV4_NODE, &neighbor_route_server_client_cmd);
13481 install_element(BGP_IPV4_NODE, &no_neighbor_route_server_client_cmd);
13482 install_element(BGP_IPV4M_NODE, &neighbor_route_server_client_cmd);
13483 install_element(BGP_IPV4M_NODE, &no_neighbor_route_server_client_cmd);
13484 install_element(BGP_IPV4L_NODE, &neighbor_route_server_client_cmd);
13485 install_element(BGP_IPV4L_NODE, &no_neighbor_route_server_client_cmd);
13486 install_element(BGP_IPV6_NODE, &neighbor_route_server_client_cmd);
13487 install_element(BGP_IPV6_NODE, &no_neighbor_route_server_client_cmd);
13488 install_element(BGP_IPV6M_NODE, &neighbor_route_server_client_cmd);
13489 install_element(BGP_IPV6M_NODE, &no_neighbor_route_server_client_cmd);
13490 install_element(BGP_IPV6L_NODE, &neighbor_route_server_client_cmd);
13491 install_element(BGP_IPV6L_NODE, &no_neighbor_route_server_client_cmd);
13492 install_element(BGP_VPNV4_NODE, &neighbor_route_server_client_cmd);
13493 install_element(BGP_VPNV4_NODE, &no_neighbor_route_server_client_cmd);
13494 install_element(BGP_VPNV6_NODE, &neighbor_route_server_client_cmd);
13495 install_element(BGP_VPNV6_NODE, &no_neighbor_route_server_client_cmd);
13496 install_element(BGP_EVPN_NODE, &neighbor_route_server_client_cmd);
13497 install_element(BGP_EVPN_NODE, &no_neighbor_route_server_client_cmd);
13498 install_element(BGP_FLOWSPECV4_NODE, &neighbor_route_server_client_cmd);
13499 install_element(BGP_FLOWSPECV4_NODE,
13500 &no_neighbor_route_server_client_cmd);
13501 install_element(BGP_FLOWSPECV6_NODE, &neighbor_route_server_client_cmd);
13502 install_element(BGP_FLOWSPECV6_NODE,
13503 &no_neighbor_route_server_client_cmd);
13504
13505 /* "neighbor addpath-tx-all-paths" commands.*/
13506 install_element(BGP_NODE, &neighbor_addpath_tx_all_paths_hidden_cmd);
13507 install_element(BGP_NODE, &no_neighbor_addpath_tx_all_paths_hidden_cmd);
13508 install_element(BGP_IPV4_NODE, &neighbor_addpath_tx_all_paths_cmd);
13509 install_element(BGP_IPV4_NODE, &no_neighbor_addpath_tx_all_paths_cmd);
13510 install_element(BGP_IPV4M_NODE, &neighbor_addpath_tx_all_paths_cmd);
13511 install_element(BGP_IPV4M_NODE, &no_neighbor_addpath_tx_all_paths_cmd);
13512 install_element(BGP_IPV4L_NODE, &neighbor_addpath_tx_all_paths_cmd);
13513 install_element(BGP_IPV4L_NODE, &no_neighbor_addpath_tx_all_paths_cmd);
13514 install_element(BGP_IPV6_NODE, &neighbor_addpath_tx_all_paths_cmd);
13515 install_element(BGP_IPV6_NODE, &no_neighbor_addpath_tx_all_paths_cmd);
13516 install_element(BGP_IPV6M_NODE, &neighbor_addpath_tx_all_paths_cmd);
13517 install_element(BGP_IPV6M_NODE, &no_neighbor_addpath_tx_all_paths_cmd);
13518 install_element(BGP_IPV6L_NODE, &neighbor_addpath_tx_all_paths_cmd);
13519 install_element(BGP_IPV6L_NODE, &no_neighbor_addpath_tx_all_paths_cmd);
13520 install_element(BGP_VPNV4_NODE, &neighbor_addpath_tx_all_paths_cmd);
13521 install_element(BGP_VPNV4_NODE, &no_neighbor_addpath_tx_all_paths_cmd);
13522 install_element(BGP_VPNV6_NODE, &neighbor_addpath_tx_all_paths_cmd);
13523 install_element(BGP_VPNV6_NODE, &no_neighbor_addpath_tx_all_paths_cmd);
13524
13525 /* "neighbor addpath-tx-bestpath-per-AS" commands.*/
13526 install_element(BGP_NODE,
13527 &neighbor_addpath_tx_bestpath_per_as_hidden_cmd);
13528 install_element(BGP_NODE,
13529 &no_neighbor_addpath_tx_bestpath_per_as_hidden_cmd);
13530 install_element(BGP_IPV4_NODE,
13531 &neighbor_addpath_tx_bestpath_per_as_cmd);
13532 install_element(BGP_IPV4_NODE,
13533 &no_neighbor_addpath_tx_bestpath_per_as_cmd);
13534 install_element(BGP_IPV4M_NODE,
13535 &neighbor_addpath_tx_bestpath_per_as_cmd);
13536 install_element(BGP_IPV4M_NODE,
13537 &no_neighbor_addpath_tx_bestpath_per_as_cmd);
13538 install_element(BGP_IPV4L_NODE,
13539 &neighbor_addpath_tx_bestpath_per_as_cmd);
13540 install_element(BGP_IPV4L_NODE,
13541 &no_neighbor_addpath_tx_bestpath_per_as_cmd);
13542 install_element(BGP_IPV6_NODE,
13543 &neighbor_addpath_tx_bestpath_per_as_cmd);
13544 install_element(BGP_IPV6_NODE,
13545 &no_neighbor_addpath_tx_bestpath_per_as_cmd);
13546 install_element(BGP_IPV6M_NODE,
13547 &neighbor_addpath_tx_bestpath_per_as_cmd);
13548 install_element(BGP_IPV6M_NODE,
13549 &no_neighbor_addpath_tx_bestpath_per_as_cmd);
13550 install_element(BGP_IPV6L_NODE,
13551 &neighbor_addpath_tx_bestpath_per_as_cmd);
13552 install_element(BGP_IPV6L_NODE,
13553 &no_neighbor_addpath_tx_bestpath_per_as_cmd);
13554 install_element(BGP_VPNV4_NODE,
13555 &neighbor_addpath_tx_bestpath_per_as_cmd);
13556 install_element(BGP_VPNV4_NODE,
13557 &no_neighbor_addpath_tx_bestpath_per_as_cmd);
13558 install_element(BGP_VPNV6_NODE,
13559 &neighbor_addpath_tx_bestpath_per_as_cmd);
13560 install_element(BGP_VPNV6_NODE,
13561 &no_neighbor_addpath_tx_bestpath_per_as_cmd);
13562
13563 /* "neighbor passive" commands. */
13564 install_element(BGP_NODE, &neighbor_passive_cmd);
13565 install_element(BGP_NODE, &no_neighbor_passive_cmd);
13566
13567
13568 /* "neighbor shutdown" commands. */
13569 install_element(BGP_NODE, &neighbor_shutdown_cmd);
13570 install_element(BGP_NODE, &no_neighbor_shutdown_cmd);
13571 install_element(BGP_NODE, &neighbor_shutdown_msg_cmd);
13572 install_element(BGP_NODE, &no_neighbor_shutdown_msg_cmd);
13573
13574 /* "neighbor capability extended-nexthop" commands.*/
13575 install_element(BGP_NODE, &neighbor_capability_enhe_cmd);
13576 install_element(BGP_NODE, &no_neighbor_capability_enhe_cmd);
13577
13578 /* "neighbor capability orf prefix-list" commands.*/
13579 install_element(BGP_NODE, &neighbor_capability_orf_prefix_hidden_cmd);
13580 install_element(BGP_NODE,
13581 &no_neighbor_capability_orf_prefix_hidden_cmd);
13582 install_element(BGP_IPV4_NODE, &neighbor_capability_orf_prefix_cmd);
13583 install_element(BGP_IPV4_NODE, &no_neighbor_capability_orf_prefix_cmd);
13584 install_element(BGP_IPV4M_NODE, &neighbor_capability_orf_prefix_cmd);
13585 install_element(BGP_IPV4M_NODE, &no_neighbor_capability_orf_prefix_cmd);
13586 install_element(BGP_IPV4L_NODE, &neighbor_capability_orf_prefix_cmd);
13587 install_element(BGP_IPV4L_NODE, &no_neighbor_capability_orf_prefix_cmd);
13588 install_element(BGP_IPV6_NODE, &neighbor_capability_orf_prefix_cmd);
13589 install_element(BGP_IPV6_NODE, &no_neighbor_capability_orf_prefix_cmd);
13590 install_element(BGP_IPV6M_NODE, &neighbor_capability_orf_prefix_cmd);
13591 install_element(BGP_IPV6M_NODE, &no_neighbor_capability_orf_prefix_cmd);
13592 install_element(BGP_IPV6L_NODE, &neighbor_capability_orf_prefix_cmd);
13593 install_element(BGP_IPV6L_NODE, &no_neighbor_capability_orf_prefix_cmd);
13594
13595 /* "neighbor capability dynamic" commands.*/
13596 install_element(BGP_NODE, &neighbor_capability_dynamic_cmd);
13597 install_element(BGP_NODE, &no_neighbor_capability_dynamic_cmd);
13598
13599 /* "neighbor dont-capability-negotiate" commands. */
13600 install_element(BGP_NODE, &neighbor_dont_capability_negotiate_cmd);
13601 install_element(BGP_NODE, &no_neighbor_dont_capability_negotiate_cmd);
13602
13603 /* "neighbor ebgp-multihop" commands. */
13604 install_element(BGP_NODE, &neighbor_ebgp_multihop_cmd);
13605 install_element(BGP_NODE, &neighbor_ebgp_multihop_ttl_cmd);
13606 install_element(BGP_NODE, &no_neighbor_ebgp_multihop_cmd);
13607
13608 /* "neighbor disable-connected-check" commands. */
13609 install_element(BGP_NODE, &neighbor_disable_connected_check_cmd);
13610 install_element(BGP_NODE, &no_neighbor_disable_connected_check_cmd);
13611
13612 /* "neighbor enforce-first-as" commands. */
13613 install_element(BGP_NODE, &neighbor_enforce_first_as_cmd);
13614 install_element(BGP_NODE, &no_neighbor_enforce_first_as_cmd);
13615
13616 /* "neighbor description" commands. */
13617 install_element(BGP_NODE, &neighbor_description_cmd);
13618 install_element(BGP_NODE, &no_neighbor_description_cmd);
13619 install_element(BGP_NODE, &no_neighbor_description_comment_cmd);
13620
13621 /* "neighbor update-source" commands. "*/
13622 install_element(BGP_NODE, &neighbor_update_source_cmd);
13623 install_element(BGP_NODE, &no_neighbor_update_source_cmd);
13624
13625 /* "neighbor default-originate" commands. */
13626 install_element(BGP_NODE, &neighbor_default_originate_hidden_cmd);
13627 install_element(BGP_NODE, &neighbor_default_originate_rmap_hidden_cmd);
13628 install_element(BGP_NODE, &no_neighbor_default_originate_hidden_cmd);
13629 install_element(BGP_IPV4_NODE, &neighbor_default_originate_cmd);
13630 install_element(BGP_IPV4_NODE, &neighbor_default_originate_rmap_cmd);
13631 install_element(BGP_IPV4_NODE, &no_neighbor_default_originate_cmd);
13632 install_element(BGP_IPV4M_NODE, &neighbor_default_originate_cmd);
13633 install_element(BGP_IPV4M_NODE, &neighbor_default_originate_rmap_cmd);
13634 install_element(BGP_IPV4M_NODE, &no_neighbor_default_originate_cmd);
13635 install_element(BGP_IPV4L_NODE, &neighbor_default_originate_cmd);
13636 install_element(BGP_IPV4L_NODE, &neighbor_default_originate_rmap_cmd);
13637 install_element(BGP_IPV4L_NODE, &no_neighbor_default_originate_cmd);
13638 install_element(BGP_IPV6_NODE, &neighbor_default_originate_cmd);
13639 install_element(BGP_IPV6_NODE, &neighbor_default_originate_rmap_cmd);
13640 install_element(BGP_IPV6_NODE, &no_neighbor_default_originate_cmd);
13641 install_element(BGP_IPV6M_NODE, &neighbor_default_originate_cmd);
13642 install_element(BGP_IPV6M_NODE, &neighbor_default_originate_rmap_cmd);
13643 install_element(BGP_IPV6M_NODE, &no_neighbor_default_originate_cmd);
13644 install_element(BGP_IPV6L_NODE, &neighbor_default_originate_cmd);
13645 install_element(BGP_IPV6L_NODE, &neighbor_default_originate_rmap_cmd);
13646 install_element(BGP_IPV6L_NODE, &no_neighbor_default_originate_cmd);
13647
13648 /* "neighbor port" commands. */
13649 install_element(BGP_NODE, &neighbor_port_cmd);
13650 install_element(BGP_NODE, &no_neighbor_port_cmd);
13651
13652 /* "neighbor weight" commands. */
13653 install_element(BGP_NODE, &neighbor_weight_hidden_cmd);
13654 install_element(BGP_NODE, &no_neighbor_weight_hidden_cmd);
13655
13656 install_element(BGP_IPV4_NODE, &neighbor_weight_cmd);
13657 install_element(BGP_IPV4_NODE, &no_neighbor_weight_cmd);
13658 install_element(BGP_IPV4M_NODE, &neighbor_weight_cmd);
13659 install_element(BGP_IPV4M_NODE, &no_neighbor_weight_cmd);
13660 install_element(BGP_IPV4L_NODE, &neighbor_weight_cmd);
13661 install_element(BGP_IPV4L_NODE, &no_neighbor_weight_cmd);
13662 install_element(BGP_IPV6_NODE, &neighbor_weight_cmd);
13663 install_element(BGP_IPV6_NODE, &no_neighbor_weight_cmd);
13664 install_element(BGP_IPV6M_NODE, &neighbor_weight_cmd);
13665 install_element(BGP_IPV6M_NODE, &no_neighbor_weight_cmd);
13666 install_element(BGP_IPV6L_NODE, &neighbor_weight_cmd);
13667 install_element(BGP_IPV6L_NODE, &no_neighbor_weight_cmd);
13668 install_element(BGP_VPNV4_NODE, &neighbor_weight_cmd);
13669 install_element(BGP_VPNV4_NODE, &no_neighbor_weight_cmd);
13670 install_element(BGP_VPNV6_NODE, &neighbor_weight_cmd);
13671 install_element(BGP_VPNV6_NODE, &no_neighbor_weight_cmd);
13672
13673 /* "neighbor override-capability" commands. */
13674 install_element(BGP_NODE, &neighbor_override_capability_cmd);
13675 install_element(BGP_NODE, &no_neighbor_override_capability_cmd);
13676
13677 /* "neighbor strict-capability-match" commands. */
13678 install_element(BGP_NODE, &neighbor_strict_capability_cmd);
13679 install_element(BGP_NODE, &no_neighbor_strict_capability_cmd);
13680
13681 /* "neighbor timers" commands. */
13682 install_element(BGP_NODE, &neighbor_timers_cmd);
13683 install_element(BGP_NODE, &no_neighbor_timers_cmd);
13684
13685 /* "neighbor timers connect" commands. */
13686 install_element(BGP_NODE, &neighbor_timers_connect_cmd);
13687 install_element(BGP_NODE, &no_neighbor_timers_connect_cmd);
13688
13689 /* "neighbor advertisement-interval" commands. */
13690 install_element(BGP_NODE, &neighbor_advertise_interval_cmd);
13691 install_element(BGP_NODE, &no_neighbor_advertise_interval_cmd);
13692
13693 /* "neighbor interface" commands. */
13694 install_element(BGP_NODE, &neighbor_interface_cmd);
13695 install_element(BGP_NODE, &no_neighbor_interface_cmd);
13696
13697 /* "neighbor distribute" commands. */
13698 install_element(BGP_NODE, &neighbor_distribute_list_hidden_cmd);
13699 install_element(BGP_NODE, &no_neighbor_distribute_list_hidden_cmd);
13700 install_element(BGP_IPV4_NODE, &neighbor_distribute_list_cmd);
13701 install_element(BGP_IPV4_NODE, &no_neighbor_distribute_list_cmd);
13702 install_element(BGP_IPV4M_NODE, &neighbor_distribute_list_cmd);
13703 install_element(BGP_IPV4M_NODE, &no_neighbor_distribute_list_cmd);
13704 install_element(BGP_IPV4L_NODE, &neighbor_distribute_list_cmd);
13705 install_element(BGP_IPV4L_NODE, &no_neighbor_distribute_list_cmd);
13706 install_element(BGP_IPV6_NODE, &neighbor_distribute_list_cmd);
13707 install_element(BGP_IPV6_NODE, &no_neighbor_distribute_list_cmd);
13708 install_element(BGP_IPV6M_NODE, &neighbor_distribute_list_cmd);
13709 install_element(BGP_IPV6M_NODE, &no_neighbor_distribute_list_cmd);
13710 install_element(BGP_IPV6L_NODE, &neighbor_distribute_list_cmd);
13711 install_element(BGP_IPV6L_NODE, &no_neighbor_distribute_list_cmd);
13712 install_element(BGP_VPNV4_NODE, &neighbor_distribute_list_cmd);
13713 install_element(BGP_VPNV4_NODE, &no_neighbor_distribute_list_cmd);
13714 install_element(BGP_VPNV6_NODE, &neighbor_distribute_list_cmd);
13715 install_element(BGP_VPNV6_NODE, &no_neighbor_distribute_list_cmd);
13716
13717 /* "neighbor prefix-list" commands. */
13718 install_element(BGP_NODE, &neighbor_prefix_list_hidden_cmd);
13719 install_element(BGP_NODE, &no_neighbor_prefix_list_hidden_cmd);
13720 install_element(BGP_IPV4_NODE, &neighbor_prefix_list_cmd);
13721 install_element(BGP_IPV4_NODE, &no_neighbor_prefix_list_cmd);
13722 install_element(BGP_IPV4M_NODE, &neighbor_prefix_list_cmd);
13723 install_element(BGP_IPV4M_NODE, &no_neighbor_prefix_list_cmd);
13724 install_element(BGP_IPV4L_NODE, &neighbor_prefix_list_cmd);
13725 install_element(BGP_IPV4L_NODE, &no_neighbor_prefix_list_cmd);
13726 install_element(BGP_IPV6_NODE, &neighbor_prefix_list_cmd);
13727 install_element(BGP_IPV6_NODE, &no_neighbor_prefix_list_cmd);
13728 install_element(BGP_IPV6M_NODE, &neighbor_prefix_list_cmd);
13729 install_element(BGP_IPV6M_NODE, &no_neighbor_prefix_list_cmd);
13730 install_element(BGP_IPV6L_NODE, &neighbor_prefix_list_cmd);
13731 install_element(BGP_IPV6L_NODE, &no_neighbor_prefix_list_cmd);
13732 install_element(BGP_VPNV4_NODE, &neighbor_prefix_list_cmd);
13733 install_element(BGP_VPNV4_NODE, &no_neighbor_prefix_list_cmd);
13734 install_element(BGP_VPNV6_NODE, &neighbor_prefix_list_cmd);
13735 install_element(BGP_VPNV6_NODE, &no_neighbor_prefix_list_cmd);
13736 install_element(BGP_FLOWSPECV4_NODE, &neighbor_prefix_list_cmd);
13737 install_element(BGP_FLOWSPECV4_NODE, &no_neighbor_prefix_list_cmd);
13738 install_element(BGP_FLOWSPECV6_NODE, &neighbor_prefix_list_cmd);
13739 install_element(BGP_FLOWSPECV6_NODE, &no_neighbor_prefix_list_cmd);
13740
13741 /* "neighbor filter-list" commands. */
13742 install_element(BGP_NODE, &neighbor_filter_list_hidden_cmd);
13743 install_element(BGP_NODE, &no_neighbor_filter_list_hidden_cmd);
13744 install_element(BGP_IPV4_NODE, &neighbor_filter_list_cmd);
13745 install_element(BGP_IPV4_NODE, &no_neighbor_filter_list_cmd);
13746 install_element(BGP_IPV4M_NODE, &neighbor_filter_list_cmd);
13747 install_element(BGP_IPV4M_NODE, &no_neighbor_filter_list_cmd);
13748 install_element(BGP_IPV4L_NODE, &neighbor_filter_list_cmd);
13749 install_element(BGP_IPV4L_NODE, &no_neighbor_filter_list_cmd);
13750 install_element(BGP_IPV6_NODE, &neighbor_filter_list_cmd);
13751 install_element(BGP_IPV6_NODE, &no_neighbor_filter_list_cmd);
13752 install_element(BGP_IPV6M_NODE, &neighbor_filter_list_cmd);
13753 install_element(BGP_IPV6M_NODE, &no_neighbor_filter_list_cmd);
13754 install_element(BGP_IPV6L_NODE, &neighbor_filter_list_cmd);
13755 install_element(BGP_IPV6L_NODE, &no_neighbor_filter_list_cmd);
13756 install_element(BGP_VPNV4_NODE, &neighbor_filter_list_cmd);
13757 install_element(BGP_VPNV4_NODE, &no_neighbor_filter_list_cmd);
13758 install_element(BGP_VPNV6_NODE, &neighbor_filter_list_cmd);
13759 install_element(BGP_VPNV6_NODE, &no_neighbor_filter_list_cmd);
13760 install_element(BGP_FLOWSPECV4_NODE, &neighbor_filter_list_cmd);
13761 install_element(BGP_FLOWSPECV4_NODE, &no_neighbor_filter_list_cmd);
13762 install_element(BGP_FLOWSPECV6_NODE, &neighbor_filter_list_cmd);
13763 install_element(BGP_FLOWSPECV6_NODE, &no_neighbor_filter_list_cmd);
13764
13765 /* "neighbor route-map" commands. */
13766 install_element(BGP_NODE, &neighbor_route_map_hidden_cmd);
13767 install_element(BGP_NODE, &no_neighbor_route_map_hidden_cmd);
13768 install_element(BGP_IPV4_NODE, &neighbor_route_map_cmd);
13769 install_element(BGP_IPV4_NODE, &no_neighbor_route_map_cmd);
13770 install_element(BGP_IPV4M_NODE, &neighbor_route_map_cmd);
13771 install_element(BGP_IPV4M_NODE, &no_neighbor_route_map_cmd);
13772 install_element(BGP_IPV4L_NODE, &neighbor_route_map_cmd);
13773 install_element(BGP_IPV4L_NODE, &no_neighbor_route_map_cmd);
13774 install_element(BGP_IPV6_NODE, &neighbor_route_map_cmd);
13775 install_element(BGP_IPV6_NODE, &no_neighbor_route_map_cmd);
13776 install_element(BGP_IPV6M_NODE, &neighbor_route_map_cmd);
13777 install_element(BGP_IPV6M_NODE, &no_neighbor_route_map_cmd);
13778 install_element(BGP_IPV6L_NODE, &neighbor_route_map_cmd);
13779 install_element(BGP_IPV6L_NODE, &no_neighbor_route_map_cmd);
13780 install_element(BGP_VPNV4_NODE, &neighbor_route_map_cmd);
13781 install_element(BGP_VPNV4_NODE, &no_neighbor_route_map_cmd);
13782 install_element(BGP_VPNV6_NODE, &neighbor_route_map_cmd);
13783 install_element(BGP_VPNV6_NODE, &no_neighbor_route_map_cmd);
13784 install_element(BGP_FLOWSPECV4_NODE, &neighbor_route_map_cmd);
13785 install_element(BGP_FLOWSPECV4_NODE, &no_neighbor_route_map_cmd);
13786 install_element(BGP_FLOWSPECV6_NODE, &neighbor_route_map_cmd);
13787 install_element(BGP_FLOWSPECV6_NODE, &no_neighbor_route_map_cmd);
13788 install_element(BGP_EVPN_NODE, &neighbor_route_map_cmd);
13789 install_element(BGP_EVPN_NODE, &no_neighbor_route_map_cmd);
13790
13791 /* "neighbor unsuppress-map" commands. */
13792 install_element(BGP_NODE, &neighbor_unsuppress_map_hidden_cmd);
13793 install_element(BGP_NODE, &no_neighbor_unsuppress_map_hidden_cmd);
13794 install_element(BGP_IPV4_NODE, &neighbor_unsuppress_map_cmd);
13795 install_element(BGP_IPV4_NODE, &no_neighbor_unsuppress_map_cmd);
13796 install_element(BGP_IPV4M_NODE, &neighbor_unsuppress_map_cmd);
13797 install_element(BGP_IPV4M_NODE, &no_neighbor_unsuppress_map_cmd);
13798 install_element(BGP_IPV4L_NODE, &neighbor_unsuppress_map_cmd);
13799 install_element(BGP_IPV4L_NODE, &no_neighbor_unsuppress_map_cmd);
13800 install_element(BGP_IPV6_NODE, &neighbor_unsuppress_map_cmd);
13801 install_element(BGP_IPV6_NODE, &no_neighbor_unsuppress_map_cmd);
13802 install_element(BGP_IPV6M_NODE, &neighbor_unsuppress_map_cmd);
13803 install_element(BGP_IPV6M_NODE, &no_neighbor_unsuppress_map_cmd);
13804 install_element(BGP_IPV6L_NODE, &neighbor_unsuppress_map_cmd);
13805 install_element(BGP_IPV6L_NODE, &no_neighbor_unsuppress_map_cmd);
13806 install_element(BGP_VPNV4_NODE, &neighbor_unsuppress_map_cmd);
13807 install_element(BGP_VPNV4_NODE, &no_neighbor_unsuppress_map_cmd);
13808 install_element(BGP_VPNV6_NODE, &neighbor_unsuppress_map_cmd);
13809 install_element(BGP_VPNV6_NODE, &no_neighbor_unsuppress_map_cmd);
13810
13811 /* "neighbor maximum-prefix" commands. */
13812 install_element(BGP_NODE, &neighbor_maximum_prefix_hidden_cmd);
13813 install_element(BGP_NODE,
13814 &neighbor_maximum_prefix_threshold_hidden_cmd);
13815 install_element(BGP_NODE, &neighbor_maximum_prefix_warning_hidden_cmd);
13816 install_element(BGP_NODE,
13817 &neighbor_maximum_prefix_threshold_warning_hidden_cmd);
13818 install_element(BGP_NODE, &neighbor_maximum_prefix_restart_hidden_cmd);
13819 install_element(BGP_NODE,
13820 &neighbor_maximum_prefix_threshold_restart_hidden_cmd);
13821 install_element(BGP_NODE, &no_neighbor_maximum_prefix_hidden_cmd);
13822 install_element(BGP_IPV4_NODE, &neighbor_maximum_prefix_cmd);
13823 install_element(BGP_IPV4_NODE, &neighbor_maximum_prefix_threshold_cmd);
13824 install_element(BGP_IPV4_NODE, &neighbor_maximum_prefix_warning_cmd);
13825 install_element(BGP_IPV4_NODE,
13826 &neighbor_maximum_prefix_threshold_warning_cmd);
13827 install_element(BGP_IPV4_NODE, &neighbor_maximum_prefix_restart_cmd);
13828 install_element(BGP_IPV4_NODE,
13829 &neighbor_maximum_prefix_threshold_restart_cmd);
13830 install_element(BGP_IPV4_NODE, &no_neighbor_maximum_prefix_cmd);
13831 install_element(BGP_IPV4M_NODE, &neighbor_maximum_prefix_cmd);
13832 install_element(BGP_IPV4M_NODE, &neighbor_maximum_prefix_threshold_cmd);
13833 install_element(BGP_IPV4M_NODE, &neighbor_maximum_prefix_warning_cmd);
13834 install_element(BGP_IPV4M_NODE,
13835 &neighbor_maximum_prefix_threshold_warning_cmd);
13836 install_element(BGP_IPV4M_NODE, &neighbor_maximum_prefix_restart_cmd);
13837 install_element(BGP_IPV4M_NODE,
13838 &neighbor_maximum_prefix_threshold_restart_cmd);
13839 install_element(BGP_IPV4M_NODE, &no_neighbor_maximum_prefix_cmd);
13840 install_element(BGP_IPV4L_NODE, &neighbor_maximum_prefix_cmd);
13841 install_element(BGP_IPV4L_NODE, &neighbor_maximum_prefix_threshold_cmd);
13842 install_element(BGP_IPV4L_NODE, &neighbor_maximum_prefix_warning_cmd);
13843 install_element(BGP_IPV4L_NODE,
13844 &neighbor_maximum_prefix_threshold_warning_cmd);
13845 install_element(BGP_IPV4L_NODE, &neighbor_maximum_prefix_restart_cmd);
13846 install_element(BGP_IPV4L_NODE,
13847 &neighbor_maximum_prefix_threshold_restart_cmd);
13848 install_element(BGP_IPV4L_NODE, &no_neighbor_maximum_prefix_cmd);
13849 install_element(BGP_IPV6_NODE, &neighbor_maximum_prefix_cmd);
13850 install_element(BGP_IPV6_NODE, &neighbor_maximum_prefix_threshold_cmd);
13851 install_element(BGP_IPV6_NODE, &neighbor_maximum_prefix_warning_cmd);
13852 install_element(BGP_IPV6_NODE,
13853 &neighbor_maximum_prefix_threshold_warning_cmd);
13854 install_element(BGP_IPV6_NODE, &neighbor_maximum_prefix_restart_cmd);
13855 install_element(BGP_IPV6_NODE,
13856 &neighbor_maximum_prefix_threshold_restart_cmd);
13857 install_element(BGP_IPV6_NODE, &no_neighbor_maximum_prefix_cmd);
13858 install_element(BGP_IPV6M_NODE, &neighbor_maximum_prefix_cmd);
13859 install_element(BGP_IPV6M_NODE, &neighbor_maximum_prefix_threshold_cmd);
13860 install_element(BGP_IPV6M_NODE, &neighbor_maximum_prefix_warning_cmd);
13861 install_element(BGP_IPV6M_NODE,
13862 &neighbor_maximum_prefix_threshold_warning_cmd);
13863 install_element(BGP_IPV6M_NODE, &neighbor_maximum_prefix_restart_cmd);
13864 install_element(BGP_IPV6M_NODE,
13865 &neighbor_maximum_prefix_threshold_restart_cmd);
13866 install_element(BGP_IPV6M_NODE, &no_neighbor_maximum_prefix_cmd);
13867 install_element(BGP_IPV6L_NODE, &neighbor_maximum_prefix_cmd);
13868 install_element(BGP_IPV6L_NODE, &neighbor_maximum_prefix_threshold_cmd);
13869 install_element(BGP_IPV6L_NODE, &neighbor_maximum_prefix_warning_cmd);
13870 install_element(BGP_IPV6L_NODE,
13871 &neighbor_maximum_prefix_threshold_warning_cmd);
13872 install_element(BGP_IPV6L_NODE, &neighbor_maximum_prefix_restart_cmd);
13873 install_element(BGP_IPV6L_NODE,
13874 &neighbor_maximum_prefix_threshold_restart_cmd);
13875 install_element(BGP_IPV6L_NODE, &no_neighbor_maximum_prefix_cmd);
13876 install_element(BGP_VPNV4_NODE, &neighbor_maximum_prefix_cmd);
13877 install_element(BGP_VPNV4_NODE, &neighbor_maximum_prefix_threshold_cmd);
13878 install_element(BGP_VPNV4_NODE, &neighbor_maximum_prefix_warning_cmd);
13879 install_element(BGP_VPNV4_NODE,
13880 &neighbor_maximum_prefix_threshold_warning_cmd);
13881 install_element(BGP_VPNV4_NODE, &neighbor_maximum_prefix_restart_cmd);
13882 install_element(BGP_VPNV4_NODE,
13883 &neighbor_maximum_prefix_threshold_restart_cmd);
13884 install_element(BGP_VPNV4_NODE, &no_neighbor_maximum_prefix_cmd);
13885 install_element(BGP_VPNV6_NODE, &neighbor_maximum_prefix_cmd);
13886 install_element(BGP_VPNV6_NODE, &neighbor_maximum_prefix_threshold_cmd);
13887 install_element(BGP_VPNV6_NODE, &neighbor_maximum_prefix_warning_cmd);
13888 install_element(BGP_VPNV6_NODE,
13889 &neighbor_maximum_prefix_threshold_warning_cmd);
13890 install_element(BGP_VPNV6_NODE, &neighbor_maximum_prefix_restart_cmd);
13891 install_element(BGP_VPNV6_NODE,
13892 &neighbor_maximum_prefix_threshold_restart_cmd);
13893 install_element(BGP_VPNV6_NODE, &no_neighbor_maximum_prefix_cmd);
13894
13895 /* "neighbor allowas-in" */
13896 install_element(BGP_NODE, &neighbor_allowas_in_hidden_cmd);
13897 install_element(BGP_NODE, &no_neighbor_allowas_in_hidden_cmd);
13898 install_element(BGP_IPV4_NODE, &neighbor_allowas_in_cmd);
13899 install_element(BGP_IPV4_NODE, &no_neighbor_allowas_in_cmd);
13900 install_element(BGP_IPV4M_NODE, &neighbor_allowas_in_cmd);
13901 install_element(BGP_IPV4M_NODE, &no_neighbor_allowas_in_cmd);
13902 install_element(BGP_IPV4L_NODE, &neighbor_allowas_in_cmd);
13903 install_element(BGP_IPV4L_NODE, &no_neighbor_allowas_in_cmd);
13904 install_element(BGP_IPV6_NODE, &neighbor_allowas_in_cmd);
13905 install_element(BGP_IPV6_NODE, &no_neighbor_allowas_in_cmd);
13906 install_element(BGP_IPV6M_NODE, &neighbor_allowas_in_cmd);
13907 install_element(BGP_IPV6M_NODE, &no_neighbor_allowas_in_cmd);
13908 install_element(BGP_IPV6L_NODE, &neighbor_allowas_in_cmd);
13909 install_element(BGP_IPV6L_NODE, &no_neighbor_allowas_in_cmd);
13910 install_element(BGP_VPNV4_NODE, &neighbor_allowas_in_cmd);
13911 install_element(BGP_VPNV4_NODE, &no_neighbor_allowas_in_cmd);
13912 install_element(BGP_VPNV6_NODE, &neighbor_allowas_in_cmd);
13913 install_element(BGP_VPNV6_NODE, &no_neighbor_allowas_in_cmd);
13914 install_element(BGP_EVPN_NODE, &neighbor_allowas_in_cmd);
13915 install_element(BGP_EVPN_NODE, &no_neighbor_allowas_in_cmd);
13916
13917 /* address-family commands. */
13918 install_element(BGP_NODE, &address_family_ipv4_safi_cmd);
13919 install_element(BGP_NODE, &address_family_ipv6_safi_cmd);
13920 #ifdef KEEP_OLD_VPN_COMMANDS
13921 install_element(BGP_NODE, &address_family_vpnv4_cmd);
13922 install_element(BGP_NODE, &address_family_vpnv6_cmd);
13923 #endif /* KEEP_OLD_VPN_COMMANDS */
13924
13925 install_element(BGP_NODE, &address_family_evpn_cmd);
13926
13927 /* "exit-address-family" command. */
13928 install_element(BGP_IPV4_NODE, &exit_address_family_cmd);
13929 install_element(BGP_IPV4M_NODE, &exit_address_family_cmd);
13930 install_element(BGP_IPV4L_NODE, &exit_address_family_cmd);
13931 install_element(BGP_IPV6_NODE, &exit_address_family_cmd);
13932 install_element(BGP_IPV6M_NODE, &exit_address_family_cmd);
13933 install_element(BGP_IPV6L_NODE, &exit_address_family_cmd);
13934 install_element(BGP_VPNV4_NODE, &exit_address_family_cmd);
13935 install_element(BGP_VPNV6_NODE, &exit_address_family_cmd);
13936 install_element(BGP_FLOWSPECV4_NODE, &exit_address_family_cmd);
13937 install_element(BGP_FLOWSPECV6_NODE, &exit_address_family_cmd);
13938 install_element(BGP_EVPN_NODE, &exit_address_family_cmd);
13939
13940 /* "clear ip bgp commands" */
13941 install_element(ENABLE_NODE, &clear_ip_bgp_all_cmd);
13942
13943 /* clear ip bgp prefix */
13944 install_element(ENABLE_NODE, &clear_ip_bgp_prefix_cmd);
13945 install_element(ENABLE_NODE, &clear_bgp_ipv6_safi_prefix_cmd);
13946 install_element(ENABLE_NODE, &clear_bgp_instance_ipv6_safi_prefix_cmd);
13947
13948 /* "show [ip] bgp summary" commands. */
13949 install_element(VIEW_NODE, &show_bgp_instance_all_ipv6_updgrps_cmd);
13950 install_element(VIEW_NODE, &show_bgp_l2vpn_evpn_updgrps_cmd);
13951 install_element(VIEW_NODE, &show_bgp_instance_updgrps_stats_cmd);
13952 install_element(VIEW_NODE, &show_bgp_updgrps_stats_cmd);
13953 install_element(VIEW_NODE, &show_ip_bgp_instance_updgrps_adj_s_cmd);
13954 install_element(VIEW_NODE, &show_ip_bgp_summary_cmd);
13955 install_element(VIEW_NODE, &show_ip_bgp_updgrps_cmd);
13956
13957 /* "show [ip] bgp neighbors" commands. */
13958 install_element(VIEW_NODE, &show_ip_bgp_neighbors_cmd);
13959
13960 /* "show [ip] bgp peer-group" commands. */
13961 install_element(VIEW_NODE, &show_ip_bgp_peer_groups_cmd);
13962
13963 /* "show [ip] bgp paths" commands. */
13964 install_element(VIEW_NODE, &show_ip_bgp_paths_cmd);
13965
13966 /* "show [ip] bgp community" commands. */
13967 install_element(VIEW_NODE, &show_ip_bgp_community_info_cmd);
13968
13969 /* "show ip bgp large-community" commands. */
13970 install_element(VIEW_NODE, &show_ip_bgp_lcommunity_info_cmd);
13971 /* "show [ip] bgp attribute-info" commands. */
13972 install_element(VIEW_NODE, &show_ip_bgp_attr_info_cmd);
13973 /* "show [ip] bgp route-leak" command */
13974 install_element(VIEW_NODE, &show_ip_bgp_route_leak_cmd);
13975
13976 /* "redistribute" commands. */
13977 install_element(BGP_NODE, &bgp_redistribute_ipv4_hidden_cmd);
13978 install_element(BGP_NODE, &no_bgp_redistribute_ipv4_hidden_cmd);
13979 install_element(BGP_NODE, &bgp_redistribute_ipv4_rmap_hidden_cmd);
13980 install_element(BGP_NODE, &bgp_redistribute_ipv4_metric_hidden_cmd);
13981 install_element(BGP_NODE,
13982 &bgp_redistribute_ipv4_rmap_metric_hidden_cmd);
13983 install_element(BGP_NODE,
13984 &bgp_redistribute_ipv4_metric_rmap_hidden_cmd);
13985 install_element(BGP_NODE, &bgp_redistribute_ipv4_ospf_hidden_cmd);
13986 install_element(BGP_NODE, &no_bgp_redistribute_ipv4_ospf_hidden_cmd);
13987 install_element(BGP_NODE, &bgp_redistribute_ipv4_ospf_rmap_hidden_cmd);
13988 install_element(BGP_NODE,
13989 &bgp_redistribute_ipv4_ospf_metric_hidden_cmd);
13990 install_element(BGP_NODE,
13991 &bgp_redistribute_ipv4_ospf_rmap_metric_hidden_cmd);
13992 install_element(BGP_NODE,
13993 &bgp_redistribute_ipv4_ospf_metric_rmap_hidden_cmd);
13994 install_element(BGP_IPV4_NODE, &bgp_redistribute_ipv4_cmd);
13995 install_element(BGP_IPV4_NODE, &no_bgp_redistribute_ipv4_cmd);
13996 install_element(BGP_IPV4_NODE, &bgp_redistribute_ipv4_rmap_cmd);
13997 install_element(BGP_IPV4_NODE, &bgp_redistribute_ipv4_metric_cmd);
13998 install_element(BGP_IPV4_NODE, &bgp_redistribute_ipv4_rmap_metric_cmd);
13999 install_element(BGP_IPV4_NODE, &bgp_redistribute_ipv4_metric_rmap_cmd);
14000 install_element(BGP_IPV4_NODE, &bgp_redistribute_ipv4_ospf_cmd);
14001 install_element(BGP_IPV4_NODE, &no_bgp_redistribute_ipv4_ospf_cmd);
14002 install_element(BGP_IPV4_NODE, &bgp_redistribute_ipv4_ospf_rmap_cmd);
14003 install_element(BGP_IPV4_NODE, &bgp_redistribute_ipv4_ospf_metric_cmd);
14004 install_element(BGP_IPV4_NODE,
14005 &bgp_redistribute_ipv4_ospf_rmap_metric_cmd);
14006 install_element(BGP_IPV4_NODE,
14007 &bgp_redistribute_ipv4_ospf_metric_rmap_cmd);
14008 install_element(BGP_IPV6_NODE, &bgp_redistribute_ipv6_cmd);
14009 install_element(BGP_IPV6_NODE, &no_bgp_redistribute_ipv6_cmd);
14010 install_element(BGP_IPV6_NODE, &bgp_redistribute_ipv6_rmap_cmd);
14011 install_element(BGP_IPV6_NODE, &bgp_redistribute_ipv6_metric_cmd);
14012 install_element(BGP_IPV6_NODE, &bgp_redistribute_ipv6_rmap_metric_cmd);
14013 install_element(BGP_IPV6_NODE, &bgp_redistribute_ipv6_metric_rmap_cmd);
14014
14015 /* import|export vpn [route-map WORD] */
14016 install_element(BGP_IPV4_NODE, &bgp_imexport_vpn_cmd);
14017 install_element(BGP_IPV6_NODE, &bgp_imexport_vpn_cmd);
14018
14019 install_element(BGP_IPV4_NODE, &bgp_imexport_vrf_cmd);
14020 install_element(BGP_IPV6_NODE, &bgp_imexport_vrf_cmd);
14021
14022 /* ttl_security commands */
14023 install_element(BGP_NODE, &neighbor_ttl_security_cmd);
14024 install_element(BGP_NODE, &no_neighbor_ttl_security_cmd);
14025
14026 /* "show [ip] bgp memory" commands. */
14027 install_element(VIEW_NODE, &show_bgp_memory_cmd);
14028
14029 /* "show bgp martian next-hop" */
14030 install_element(VIEW_NODE, &show_bgp_martian_nexthop_db_cmd);
14031
14032 install_element(VIEW_NODE, &show_bgp_mac_hash_cmd);
14033
14034 /* "show [ip] bgp views" commands. */
14035 install_element(VIEW_NODE, &show_bgp_views_cmd);
14036
14037 /* "show [ip] bgp vrfs" commands. */
14038 install_element(VIEW_NODE, &show_bgp_vrfs_cmd);
14039
14040 /* Community-list. */
14041 community_list_vty();
14042
14043 /* vpn-policy commands */
14044 install_element(BGP_IPV4_NODE, &af_rd_vpn_export_cmd);
14045 install_element(BGP_IPV6_NODE, &af_rd_vpn_export_cmd);
14046 install_element(BGP_IPV4_NODE, &af_label_vpn_export_cmd);
14047 install_element(BGP_IPV6_NODE, &af_label_vpn_export_cmd);
14048 install_element(BGP_IPV4_NODE, &af_nexthop_vpn_export_cmd);
14049 install_element(BGP_IPV6_NODE, &af_nexthop_vpn_export_cmd);
14050 install_element(BGP_IPV4_NODE, &af_rt_vpn_imexport_cmd);
14051 install_element(BGP_IPV6_NODE, &af_rt_vpn_imexport_cmd);
14052 install_element(BGP_IPV4_NODE, &af_route_map_vpn_imexport_cmd);
14053 install_element(BGP_IPV6_NODE, &af_route_map_vpn_imexport_cmd);
14054 install_element(BGP_IPV4_NODE, &af_import_vrf_route_map_cmd);
14055 install_element(BGP_IPV6_NODE, &af_import_vrf_route_map_cmd);
14056
14057 install_element(BGP_IPV4_NODE, &af_routetarget_import_cmd);
14058 install_element(BGP_IPV6_NODE, &af_routetarget_import_cmd);
14059
14060 install_element(BGP_IPV4_NODE, &af_no_rd_vpn_export_cmd);
14061 install_element(BGP_IPV6_NODE, &af_no_rd_vpn_export_cmd);
14062 install_element(BGP_IPV4_NODE, &af_no_label_vpn_export_cmd);
14063 install_element(BGP_IPV6_NODE, &af_no_label_vpn_export_cmd);
14064 install_element(BGP_IPV4_NODE, &af_no_nexthop_vpn_export_cmd);
14065 install_element(BGP_IPV6_NODE, &af_no_nexthop_vpn_export_cmd);
14066 install_element(BGP_IPV4_NODE, &af_no_rt_vpn_imexport_cmd);
14067 install_element(BGP_IPV6_NODE, &af_no_rt_vpn_imexport_cmd);
14068 install_element(BGP_IPV4_NODE, &af_no_route_map_vpn_imexport_cmd);
14069 install_element(BGP_IPV6_NODE, &af_no_route_map_vpn_imexport_cmd);
14070 install_element(BGP_IPV4_NODE, &af_no_import_vrf_route_map_cmd);
14071 install_element(BGP_IPV6_NODE, &af_no_import_vrf_route_map_cmd);
14072 }
14073
14074 #include "memory.h"
14075 #include "bgp_regex.h"
14076 #include "bgp_clist.h"
14077 #include "bgp_ecommunity.h"
14078
14079 /* VTY functions. */
14080
14081 /* Direction value to string conversion. */
14082 static const char *community_direct_str(int direct)
14083 {
14084 switch (direct) {
14085 case COMMUNITY_DENY:
14086 return "deny";
14087 case COMMUNITY_PERMIT:
14088 return "permit";
14089 default:
14090 return "unknown";
14091 }
14092 }
14093
14094 /* Display error string. */
14095 static void community_list_perror(struct vty *vty, int ret)
14096 {
14097 switch (ret) {
14098 case COMMUNITY_LIST_ERR_CANT_FIND_LIST:
14099 vty_out(vty, "%% Can't find community-list\n");
14100 break;
14101 case COMMUNITY_LIST_ERR_MALFORMED_VAL:
14102 vty_out(vty, "%% Malformed community-list value\n");
14103 break;
14104 case COMMUNITY_LIST_ERR_STANDARD_CONFLICT:
14105 vty_out(vty,
14106 "%% Community name conflict, previously defined as standard community\n");
14107 break;
14108 case COMMUNITY_LIST_ERR_EXPANDED_CONFLICT:
14109 vty_out(vty,
14110 "%% Community name conflict, previously defined as expanded community\n");
14111 break;
14112 }
14113 }
14114
14115 /* "community-list" keyword help string. */
14116 #define COMMUNITY_LIST_STR "Add a community list entry\n"
14117
14118 /*community-list standard */
14119 DEFUN (community_list_standard,
14120 bgp_community_list_standard_cmd,
14121 "bgp community-list <(1-99)|standard WORD> <deny|permit> AA:NN...",
14122 BGP_STR
14123 COMMUNITY_LIST_STR
14124 "Community list number (standard)\n"
14125 "Add an standard community-list entry\n"
14126 "Community list name\n"
14127 "Specify community to reject\n"
14128 "Specify community to accept\n"
14129 COMMUNITY_VAL_STR)
14130 {
14131 char *cl_name_or_number = NULL;
14132 int direct = 0;
14133 int style = COMMUNITY_LIST_STANDARD;
14134
14135 int idx = 0;
14136
14137 if (argv_find(argv, argc, "ip", &idx)) {
14138 vty_out(vty, "This config option is deprecated, and is scheduled for removal.\n");
14139 vty_out(vty, "if you are using this please migrate to the below command.\n");
14140 vty_out(vty, "'bgp community-list <(1-99)|(100-500)|standard|expanded> <deny|permit> AA:NN'\n");
14141 zlog_warn("Deprecated option: 'ip community-list <(1-99)|(100-500)|standard|expanded> <deny|permit> AA:NN' being used");
14142 }
14143
14144 argv_find(argv, argc, "(1-99)", &idx);
14145 argv_find(argv, argc, "WORD", &idx);
14146 cl_name_or_number = argv[idx]->arg;
14147 direct = argv_find(argv, argc, "permit", &idx) ? COMMUNITY_PERMIT
14148 : COMMUNITY_DENY;
14149 argv_find(argv, argc, "AA:NN", &idx);
14150 char *str = argv_concat(argv, argc, idx);
14151
14152 int ret = community_list_set(bgp_clist, cl_name_or_number, str, direct,
14153 style);
14154
14155 XFREE(MTYPE_TMP, str);
14156
14157 if (ret < 0) {
14158 /* Display error string. */
14159 community_list_perror(vty, ret);
14160 return CMD_WARNING_CONFIG_FAILED;
14161 }
14162
14163 return CMD_SUCCESS;
14164 }
14165
14166 #if CONFDATE > 20191005
14167 CPP_NOTICE("bgpd: remove deprecated 'ip community-list <(1-99)|(100-500)|standard|expanded> <deny|permit> AA:NN' command")
14168 #endif
14169 ALIAS (community_list_standard,
14170 ip_community_list_standard_cmd,
14171 "ip community-list <(1-99)|standard WORD> <deny|permit> AA:NN...",
14172 IP_STR
14173 COMMUNITY_LIST_STR
14174 "Community list number (standard)\n"
14175 "Add an standard community-list entry\n"
14176 "Community list name\n"
14177 "Specify community to reject\n"
14178 "Specify community to accept\n"
14179 COMMUNITY_VAL_STR)
14180
14181 DEFUN (no_community_list_standard_all,
14182 no_bgp_community_list_standard_all_cmd,
14183 "no bgp community-list <(1-99)|standard WORD> <deny|permit> AA:NN...",
14184 NO_STR
14185 BGP_STR
14186 COMMUNITY_LIST_STR
14187 "Community list number (standard)\n"
14188 "Add an standard community-list entry\n"
14189 "Community list name\n"
14190 "Specify community to reject\n"
14191 "Specify community to accept\n"
14192 COMMUNITY_VAL_STR)
14193 {
14194 char *cl_name_or_number = NULL;
14195 char *str = NULL;
14196 int direct = 0;
14197 int style = COMMUNITY_LIST_STANDARD;
14198
14199 int idx = 0;
14200
14201 if (argv_find(argv, argc, "ip", &idx)) {
14202 vty_out(vty, "This config option is deprecated, and is scheduled for removal\n");
14203 vty_out(vty, "if you are using this please migrate to the below command.\n");
14204 vty_out(vty, "'no bgp community-list <(1-99)|(100-500)|standard|expanded> <deny|permit> AA:NN'\n");
14205 zlog_warn("Deprecated option: 'no ip community-list <(1-99)|(100-500)|standard|expanded> <deny|permit> |AA:NN' being used");
14206 }
14207
14208 argv_find(argv, argc, "permit", &idx);
14209 argv_find(argv, argc, "deny", &idx);
14210
14211 if (idx) {
14212 direct = argv_find(argv, argc, "permit", &idx)
14213 ? COMMUNITY_PERMIT
14214 : COMMUNITY_DENY;
14215
14216 idx = 0;
14217 argv_find(argv, argc, "AA:NN", &idx);
14218 str = argv_concat(argv, argc, idx);
14219 }
14220
14221 idx = 0;
14222 argv_find(argv, argc, "(1-99)", &idx);
14223 argv_find(argv, argc, "WORD", &idx);
14224 cl_name_or_number = argv[idx]->arg;
14225
14226 int ret = community_list_unset(bgp_clist, cl_name_or_number, str,
14227 direct, style);
14228
14229 XFREE(MTYPE_TMP, str);
14230
14231 if (ret < 0) {
14232 community_list_perror(vty, ret);
14233 return CMD_WARNING_CONFIG_FAILED;
14234 }
14235
14236 return CMD_SUCCESS;
14237 }
14238 ALIAS (no_community_list_standard_all,
14239 no_ip_community_list_standard_all_cmd,
14240 "no ip community-list <(1-99)|standard WORD> <deny|permit> AA:NN...",
14241 NO_STR
14242 IP_STR
14243 COMMUNITY_LIST_STR
14244 "Community list number (standard)\n"
14245 "Add an standard community-list entry\n"
14246 "Community list name\n"
14247 "Specify community to reject\n"
14248 "Specify community to accept\n"
14249 COMMUNITY_VAL_STR)
14250
14251 ALIAS(no_community_list_standard_all, no_bgp_community_list_standard_all_list_cmd,
14252 "no bgp community-list <(1-99)|standard WORD>",
14253 NO_STR BGP_STR COMMUNITY_LIST_STR
14254 "Community list number (standard)\n"
14255 "Add an standard community-list entry\n"
14256 "Community list name\n")
14257
14258 ALIAS(no_community_list_standard_all, no_ip_community_list_standard_all_list_cmd,
14259 "no ip community-list <(1-99)|standard WORD>",
14260 NO_STR BGP_STR COMMUNITY_LIST_STR
14261 "Community list number (standard)\n"
14262 "Add an standard community-list entry\n"
14263 "Community list name\n")
14264
14265 /*community-list expanded */
14266 DEFUN (community_list_expanded_all,
14267 bgp_community_list_expanded_all_cmd,
14268 "bgp community-list <(100-500)|expanded WORD> <deny|permit> AA:NN...",
14269 BGP_STR
14270 COMMUNITY_LIST_STR
14271 "Community list number (expanded)\n"
14272 "Add an expanded community-list entry\n"
14273 "Community list name\n"
14274 "Specify community to reject\n"
14275 "Specify community to accept\n"
14276 COMMUNITY_VAL_STR)
14277 {
14278 char *cl_name_or_number = NULL;
14279 int direct = 0;
14280 int style = COMMUNITY_LIST_EXPANDED;
14281
14282 int idx = 0;
14283 if (argv_find(argv, argc, "ip", &idx)) {
14284 vty_out(vty, "This config option is deprecated, and is scheduled for removal.\n");
14285 vty_out(vty, "if you are using this please migrate to the below command.\n");
14286 vty_out(vty, "'bgp community-list <(1-99)|(100-500)|standard|expanded> <deny|permit> AA:NN'\n");
14287 zlog_warn("Deprecated option: 'ip community-list <(1-99)|(100-500)|standard|expanded> <deny|permit> AA:NN' being used");
14288 }
14289 argv_find(argv, argc, "(100-500)", &idx);
14290 argv_find(argv, argc, "WORD", &idx);
14291 cl_name_or_number = argv[idx]->arg;
14292 direct = argv_find(argv, argc, "permit", &idx) ? COMMUNITY_PERMIT
14293 : COMMUNITY_DENY;
14294 argv_find(argv, argc, "AA:NN", &idx);
14295 char *str = argv_concat(argv, argc, idx);
14296
14297 int ret = community_list_set(bgp_clist, cl_name_or_number, str, direct,
14298 style);
14299
14300 XFREE(MTYPE_TMP, str);
14301
14302 if (ret < 0) {
14303 /* Display error string. */
14304 community_list_perror(vty, ret);
14305 return CMD_WARNING_CONFIG_FAILED;
14306 }
14307
14308 return CMD_SUCCESS;
14309 }
14310
14311 ALIAS (community_list_expanded_all,
14312 ip_community_list_expanded_all_cmd,
14313 "ip community-list <(100-500)|expanded WORD> <deny|permit> AA:NN...",
14314 IP_STR
14315 COMMUNITY_LIST_STR
14316 "Community list number (expanded)\n"
14317 "Add an expanded community-list entry\n"
14318 "Community list name\n"
14319 "Specify community to reject\n"
14320 "Specify community to accept\n"
14321 COMMUNITY_VAL_STR)
14322
14323 DEFUN (no_community_list_expanded_all,
14324 no_bgp_community_list_expanded_all_cmd,
14325 "no bgp community-list <(100-500)|expanded WORD> <deny|permit> AA:NN...",
14326 NO_STR
14327 BGP_STR
14328 COMMUNITY_LIST_STR
14329 "Community list number (expanded)\n"
14330 "Add an expanded community-list entry\n"
14331 "Community list name\n"
14332 "Specify community to reject\n"
14333 "Specify community to accept\n"
14334 COMMUNITY_VAL_STR)
14335 {
14336 char *cl_name_or_number = NULL;
14337 char *str = NULL;
14338 int direct = 0;
14339 int style = COMMUNITY_LIST_EXPANDED;
14340
14341 int idx = 0;
14342 if (argv_find(argv, argc, "ip", &idx)) {
14343 vty_out(vty, "This config option is deprecated, and is scheduled for removal.\n");
14344 vty_out(vty, "if you are using this please migrate to the below command.\n");
14345 vty_out(vty, "'no bgp community-list <(1-99)|(100-500)|standard|expanded> <deny|permit> AA:NN'\n");
14346 zlog_warn("Deprecated option: 'no ip community-list <(1-99)|(100-500)|standard|expanded> <deny|permit> AA:NN' being used");
14347 }
14348
14349 idx = 0;
14350 argv_find(argv, argc, "permit", &idx);
14351 argv_find(argv, argc, "deny", &idx);
14352
14353 if (idx) {
14354 direct = argv_find(argv, argc, "permit", &idx)
14355 ? COMMUNITY_PERMIT
14356 : COMMUNITY_DENY;
14357
14358 idx = 0;
14359 argv_find(argv, argc, "AA:NN", &idx);
14360 str = argv_concat(argv, argc, idx);
14361 }
14362
14363 idx = 0;
14364 argv_find(argv, argc, "(100-500)", &idx);
14365 argv_find(argv, argc, "WORD", &idx);
14366 cl_name_or_number = argv[idx]->arg;
14367
14368 int ret = community_list_unset(bgp_clist, cl_name_or_number, str,
14369 direct, style);
14370
14371 XFREE(MTYPE_TMP, str);
14372
14373 if (ret < 0) {
14374 community_list_perror(vty, ret);
14375 return CMD_WARNING_CONFIG_FAILED;
14376 }
14377
14378 return CMD_SUCCESS;
14379 }
14380
14381 ALIAS (no_community_list_expanded_all,
14382 no_ip_community_list_expanded_all_cmd,
14383 "no ip community-list <(100-500)|expanded WORD> <deny|permit> AA:NN...",
14384 NO_STR
14385 IP_STR
14386 COMMUNITY_LIST_STR
14387 "Community list number (expanded)\n"
14388 "Add an expanded community-list entry\n"
14389 "Community list name\n"
14390 "Specify community to reject\n"
14391 "Specify community to accept\n"
14392 COMMUNITY_VAL_STR)
14393
14394 ALIAS(no_community_list_expanded_all, no_bgp_community_list_expanded_all_list_cmd,
14395 "no bgp community-list <(100-500)|expanded WORD>",
14396 NO_STR IP_STR COMMUNITY_LIST_STR
14397 "Community list number (expanded)\n"
14398 "Add an expanded community-list entry\n"
14399 "Community list name\n")
14400
14401 ALIAS(no_community_list_expanded_all, no_ip_community_list_expanded_all_list_cmd,
14402 "no ip community-list <(100-500)|expanded WORD>",
14403 NO_STR IP_STR COMMUNITY_LIST_STR
14404 "Community list number (expanded)\n"
14405 "Add an expanded community-list entry\n"
14406 "Community list name\n")
14407
14408 /* Return configuration string of community-list entry. */
14409 static const char *community_list_config_str(struct community_entry *entry)
14410 {
14411 const char *str;
14412
14413 if (entry->any)
14414 str = "";
14415 else {
14416 if (entry->style == COMMUNITY_LIST_STANDARD)
14417 str = community_str(entry->u.com, false);
14418 else if (entry->style == LARGE_COMMUNITY_LIST_STANDARD)
14419 str = lcommunity_str(entry->u.lcom, false);
14420 else
14421 str = entry->config;
14422 }
14423 return str;
14424 }
14425
14426 static void community_list_show(struct vty *vty, struct community_list *list)
14427 {
14428 struct community_entry *entry;
14429
14430 for (entry = list->head; entry; entry = entry->next) {
14431 if (entry == list->head) {
14432 if (all_digit(list->name))
14433 vty_out(vty, "Community %s list %s\n",
14434 entry->style == COMMUNITY_LIST_STANDARD
14435 ? "standard"
14436 : "(expanded) access",
14437 list->name);
14438 else
14439 vty_out(vty, "Named Community %s list %s\n",
14440 entry->style == COMMUNITY_LIST_STANDARD
14441 ? "standard"
14442 : "expanded",
14443 list->name);
14444 }
14445 if (entry->any)
14446 vty_out(vty, " %s\n",
14447 community_direct_str(entry->direct));
14448 else
14449 vty_out(vty, " %s %s\n",
14450 community_direct_str(entry->direct),
14451 community_list_config_str(entry));
14452 }
14453 }
14454
14455 DEFUN (show_community_list,
14456 show_bgp_community_list_cmd,
14457 "show bgp community-list",
14458 SHOW_STR
14459 BGP_STR
14460 "List community-list\n")
14461 {
14462 struct community_list *list;
14463 struct community_list_master *cm;
14464
14465 int idx = 0;
14466 if (argv_find(argv, argc, "ip", &idx)) {
14467 vty_out(vty, "This config option is deprecated, and is scheduled for removal.\n");
14468 vty_out(vty, "if you are using this please migrate to the below command.\n");
14469 vty_out(vty, "'show bgp community-list <(1-500)|WORD>'\n");
14470 zlog_warn("Deprecated option: 'ip show community-list <(1-500)|WORD>' being used");
14471 }
14472 cm = community_list_master_lookup(bgp_clist, COMMUNITY_LIST_MASTER);
14473 if (!cm)
14474 return CMD_SUCCESS;
14475
14476 for (list = cm->num.head; list; list = list->next)
14477 community_list_show(vty, list);
14478
14479 for (list = cm->str.head; list; list = list->next)
14480 community_list_show(vty, list);
14481
14482 return CMD_SUCCESS;
14483 }
14484
14485 ALIAS (show_community_list,
14486 show_ip_community_list_cmd,
14487 "show ip community-list",
14488 SHOW_STR
14489 IP_STR
14490 "List community-list\n")
14491
14492 DEFUN (show_community_list_arg,
14493 show_bgp_community_list_arg_cmd,
14494 "show bgp community-list <(1-500)|WORD>",
14495 SHOW_STR
14496 BGP_STR
14497 "List community-list\n"
14498 "Community-list number\n"
14499 "Community-list name\n")
14500 {
14501 int idx_comm_list = 3;
14502 struct community_list *list;
14503
14504 int idx = 0;
14505 if (argv_find(argv, argc, "ip", &idx)) {
14506 vty_out(vty, "This config option is deprecated, and is scheduled for removal.\n");
14507 vty_out(vty, "if you are using this please migrate to the below command.\n");
14508 vty_out(vty, "'show bgp community-list <(1-500)|WORD>'\n");
14509 zlog_warn("Deprecated option: 'ip show community-list <(1-500)|WORD>' being used");
14510 }
14511 list = community_list_lookup(bgp_clist, argv[idx_comm_list]->arg, 0,
14512 COMMUNITY_LIST_MASTER);
14513 if (!list) {
14514 vty_out(vty, "%% Can't find community-list\n");
14515 return CMD_WARNING;
14516 }
14517
14518 community_list_show(vty, list);
14519
14520 return CMD_SUCCESS;
14521 }
14522
14523 ALIAS (show_community_list_arg,
14524 show_ip_community_list_arg_cmd,
14525 "show ip community-list <(1-500)|WORD>",
14526 SHOW_STR
14527 IP_STR
14528 "List community-list\n"
14529 "Community-list number\n"
14530 "Community-list name\n")
14531
14532 /*
14533 * Large Community code.
14534 */
14535 static int lcommunity_list_set_vty(struct vty *vty, int argc,
14536 struct cmd_token **argv, int style,
14537 int reject_all_digit_name)
14538 {
14539 int ret;
14540 int direct;
14541 char *str;
14542 int idx = 0;
14543 char *cl_name;
14544
14545 if (argv_find(argv, argc, "ip", &idx)) {
14546 vty_out(vty, "This config option is deprecated, and is scheduled for removal.\n");
14547 vty_out(vty, "if you are using this please migrate to the below command.\n");
14548 vty_out(vty, "'bgp large-community-list <(1-99)|(100-500)|standard|expanded> <deny|permit> <LINE|AA:BB:CC>'\n");
14549 zlog_warn("Deprecated option: 'large-community-list <(1-99)|(100-500)|standard|expanded> <deny|permit> <LINE|AA:BB:CC>' being used");
14550 }
14551 direct = argv_find(argv, argc, "permit", &idx) ? COMMUNITY_PERMIT
14552 : COMMUNITY_DENY;
14553
14554 /* All digit name check. */
14555 idx = 0;
14556 argv_find(argv, argc, "WORD", &idx);
14557 argv_find(argv, argc, "(1-99)", &idx);
14558 argv_find(argv, argc, "(100-500)", &idx);
14559 cl_name = argv[idx]->arg;
14560 if (reject_all_digit_name && all_digit(cl_name)) {
14561 vty_out(vty, "%% Community name cannot have all digits\n");
14562 return CMD_WARNING_CONFIG_FAILED;
14563 }
14564
14565 idx = 0;
14566 argv_find(argv, argc, "AA:BB:CC", &idx);
14567 argv_find(argv, argc, "LINE", &idx);
14568 /* Concat community string argument. */
14569 if (idx)
14570 str = argv_concat(argv, argc, idx);
14571 else
14572 str = NULL;
14573
14574 ret = lcommunity_list_set(bgp_clist, cl_name, str, direct, style);
14575
14576 /* Free temporary community list string allocated by
14577 argv_concat(). */
14578 XFREE(MTYPE_TMP, str);
14579
14580 if (ret < 0) {
14581 community_list_perror(vty, ret);
14582 return CMD_WARNING_CONFIG_FAILED;
14583 }
14584 return CMD_SUCCESS;
14585 }
14586
14587 static int lcommunity_list_unset_vty(struct vty *vty, int argc,
14588 struct cmd_token **argv, int style)
14589 {
14590 int ret;
14591 int direct = 0;
14592 char *str = NULL;
14593 int idx = 0;
14594
14595 if (argv_find(argv, argc, "ip", &idx)) {
14596 vty_out(vty, "This config option is deprecated, and is scheduled for removal.\n");
14597 vty_out(vty, "if you are using this please migrate to the below command.\n");
14598 vty_out(vty, "'no bgp large-community-list <(1-99)|(100-500)|standard|expanded> <deny|permit> <LINE|AA:BB:CC>'\n");
14599 zlog_warn("Deprecated option: 'no ip large-community-list <(1-99)|(100-500)|standard|expanded> <deny|permit> <LINE|AA:BB:CC>' being used");
14600 }
14601 argv_find(argv, argc, "permit", &idx);
14602 argv_find(argv, argc, "deny", &idx);
14603
14604 if (idx) {
14605 /* Check the list direct. */
14606 if (strncmp(argv[idx]->arg, "p", 1) == 0)
14607 direct = COMMUNITY_PERMIT;
14608 else
14609 direct = COMMUNITY_DENY;
14610
14611 idx = 0;
14612 argv_find(argv, argc, "LINE", &idx);
14613 argv_find(argv, argc, "AA:AA:NN", &idx);
14614 /* Concat community string argument. */
14615 str = argv_concat(argv, argc, idx);
14616 }
14617
14618 idx = 0;
14619 argv_find(argv, argc, "(1-99)", &idx);
14620 argv_find(argv, argc, "(100-500)", &idx);
14621 argv_find(argv, argc, "WORD", &idx);
14622
14623 /* Unset community list. */
14624 ret = lcommunity_list_unset(bgp_clist, argv[idx]->arg, str, direct,
14625 style);
14626
14627 /* Free temporary community list string allocated by
14628 argv_concat(). */
14629 XFREE(MTYPE_TMP, str);
14630
14631 if (ret < 0) {
14632 community_list_perror(vty, ret);
14633 return CMD_WARNING_CONFIG_FAILED;
14634 }
14635
14636 return CMD_SUCCESS;
14637 }
14638
14639 /* "large-community-list" keyword help string. */
14640 #define LCOMMUNITY_LIST_STR "Add a large community list entry\n"
14641 #define LCOMMUNITY_VAL_STR "large community in 'aa:bb:cc' format\n"
14642
14643 #if CONFDATE > 20191005
14644 CPP_NOTICE("bgpd: remove deprecated 'ip large-community-list <(1-99)|(100-500)|standard|expanded> <deny|permit> <LINE|AA:BB:CC>' command")
14645 #endif
14646 DEFUN (lcommunity_list_standard,
14647 bgp_lcommunity_list_standard_cmd,
14648 "bgp large-community-list (1-99) <deny|permit>",
14649 BGP_STR
14650 LCOMMUNITY_LIST_STR
14651 "Large Community list number (standard)\n"
14652 "Specify large community to reject\n"
14653 "Specify large community to accept\n")
14654 {
14655 return lcommunity_list_set_vty(vty, argc, argv,
14656 LARGE_COMMUNITY_LIST_STANDARD, 0);
14657 }
14658
14659 ALIAS (lcommunity_list_standard,
14660 ip_lcommunity_list_standard_cmd,
14661 "ip large-community-list (1-99) <deny|permit>",
14662 IP_STR
14663 LCOMMUNITY_LIST_STR
14664 "Large Community list number (standard)\n"
14665 "Specify large community to reject\n"
14666 "Specify large community to accept\n")
14667
14668 DEFUN (lcommunity_list_standard1,
14669 bgp_lcommunity_list_standard1_cmd,
14670 "bgp large-community-list (1-99) <deny|permit> AA:BB:CC...",
14671 BGP_STR
14672 LCOMMUNITY_LIST_STR
14673 "Large Community list number (standard)\n"
14674 "Specify large community to reject\n"
14675 "Specify large community to accept\n"
14676 LCOMMUNITY_VAL_STR)
14677 {
14678 return lcommunity_list_set_vty(vty, argc, argv,
14679 LARGE_COMMUNITY_LIST_STANDARD, 0);
14680 }
14681
14682 ALIAS (lcommunity_list_standard1,
14683 ip_lcommunity_list_standard1_cmd,
14684 "ip large-community-list (1-99) <deny|permit> AA:BB:CC...",
14685 IP_STR
14686 LCOMMUNITY_LIST_STR
14687 "Large Community list number (standard)\n"
14688 "Specify large community to reject\n"
14689 "Specify large community to accept\n"
14690 LCOMMUNITY_VAL_STR)
14691
14692 DEFUN (lcommunity_list_expanded,
14693 bgp_lcommunity_list_expanded_cmd,
14694 "bgp large-community-list (100-500) <deny|permit> LINE...",
14695 BGP_STR
14696 LCOMMUNITY_LIST_STR
14697 "Large Community list number (expanded)\n"
14698 "Specify large community to reject\n"
14699 "Specify large community to accept\n"
14700 "An ordered list as a regular-expression\n")
14701 {
14702 return lcommunity_list_set_vty(vty, argc, argv,
14703 LARGE_COMMUNITY_LIST_EXPANDED, 0);
14704 }
14705
14706 ALIAS (lcommunity_list_expanded,
14707 ip_lcommunity_list_expanded_cmd,
14708 "ip large-community-list (100-500) <deny|permit> LINE...",
14709 IP_STR
14710 LCOMMUNITY_LIST_STR
14711 "Large Community list number (expanded)\n"
14712 "Specify large community to reject\n"
14713 "Specify large community to accept\n"
14714 "An ordered list as a regular-expression\n")
14715
14716 DEFUN (lcommunity_list_name_standard,
14717 bgp_lcommunity_list_name_standard_cmd,
14718 "bgp large-community-list standard WORD <deny|permit>",
14719 BGP_STR
14720 LCOMMUNITY_LIST_STR
14721 "Specify standard large-community-list\n"
14722 "Large Community list name\n"
14723 "Specify large community to reject\n"
14724 "Specify large community to accept\n")
14725 {
14726 return lcommunity_list_set_vty(vty, argc, argv,
14727 LARGE_COMMUNITY_LIST_STANDARD, 1);
14728 }
14729
14730 ALIAS (lcommunity_list_name_standard,
14731 ip_lcommunity_list_name_standard_cmd,
14732 "ip large-community-list standard WORD <deny|permit>",
14733 IP_STR
14734 LCOMMUNITY_LIST_STR
14735 "Specify standard large-community-list\n"
14736 "Large Community list name\n"
14737 "Specify large community to reject\n"
14738 "Specify large community to accept\n")
14739
14740 DEFUN (lcommunity_list_name_standard1,
14741 bgp_lcommunity_list_name_standard1_cmd,
14742 "bgp large-community-list standard WORD <deny|permit> AA:BB:CC...",
14743 BGP_STR
14744 LCOMMUNITY_LIST_STR
14745 "Specify standard large-community-list\n"
14746 "Large Community list name\n"
14747 "Specify large community to reject\n"
14748 "Specify large community to accept\n"
14749 LCOMMUNITY_VAL_STR)
14750 {
14751 return lcommunity_list_set_vty(vty, argc, argv,
14752 LARGE_COMMUNITY_LIST_STANDARD, 1);
14753 }
14754
14755 ALIAS (lcommunity_list_name_standard1,
14756 ip_lcommunity_list_name_standard1_cmd,
14757 "ip large-community-list standard WORD <deny|permit> AA:BB:CC...",
14758 IP_STR
14759 LCOMMUNITY_LIST_STR
14760 "Specify standard large-community-list\n"
14761 "Large Community list name\n"
14762 "Specify large community to reject\n"
14763 "Specify large community to accept\n"
14764 LCOMMUNITY_VAL_STR)
14765
14766 DEFUN (lcommunity_list_name_expanded,
14767 bgp_lcommunity_list_name_expanded_cmd,
14768 "bgp large-community-list expanded WORD <deny|permit> LINE...",
14769 BGP_STR
14770 LCOMMUNITY_LIST_STR
14771 "Specify expanded large-community-list\n"
14772 "Large Community list name\n"
14773 "Specify large community to reject\n"
14774 "Specify large community to accept\n"
14775 "An ordered list as a regular-expression\n")
14776 {
14777 return lcommunity_list_set_vty(vty, argc, argv,
14778 LARGE_COMMUNITY_LIST_EXPANDED, 1);
14779 }
14780
14781 ALIAS (lcommunity_list_name_expanded,
14782 ip_lcommunity_list_name_expanded_cmd,
14783 "ip large-community-list expanded WORD <deny|permit> LINE...",
14784 IP_STR
14785 LCOMMUNITY_LIST_STR
14786 "Specify expanded large-community-list\n"
14787 "Large Community list name\n"
14788 "Specify large community to reject\n"
14789 "Specify large community to accept\n"
14790 "An ordered list as a regular-expression\n")
14791
14792 DEFUN (no_lcommunity_list_standard_all,
14793 no_bgp_lcommunity_list_standard_all_cmd,
14794 "no bgp large-community-list <(1-99)|(100-500)|WORD>",
14795 NO_STR
14796 BGP_STR
14797 LCOMMUNITY_LIST_STR
14798 "Large Community list number (standard)\n"
14799 "Large Community list number (expanded)\n"
14800 "Large Community list name\n")
14801 {
14802 return lcommunity_list_unset_vty(vty, argc, argv,
14803 LARGE_COMMUNITY_LIST_STANDARD);
14804 }
14805
14806 ALIAS (no_lcommunity_list_standard_all,
14807 no_ip_lcommunity_list_standard_all_cmd,
14808 "no ip large-community-list <(1-99)|(100-500)|WORD>",
14809 NO_STR
14810 IP_STR
14811 LCOMMUNITY_LIST_STR
14812 "Large Community list number (standard)\n"
14813 "Large Community list number (expanded)\n"
14814 "Large Community list name\n")
14815
14816 DEFUN (no_lcommunity_list_name_expanded_all,
14817 no_bgp_lcommunity_list_name_expanded_all_cmd,
14818 "no bgp large-community-list expanded WORD",
14819 NO_STR
14820 BGP_STR
14821 LCOMMUNITY_LIST_STR
14822 "Specify expanded large-community-list\n"
14823 "Large Community list name\n")
14824 {
14825 return lcommunity_list_unset_vty(vty, argc, argv,
14826 LARGE_COMMUNITY_LIST_EXPANDED);
14827 }
14828
14829 ALIAS (no_lcommunity_list_name_expanded_all,
14830 no_ip_lcommunity_list_name_expanded_all_cmd,
14831 "no ip large-community-list expanded WORD",
14832 NO_STR
14833 IP_STR
14834 LCOMMUNITY_LIST_STR
14835 "Specify expanded large-community-list\n"
14836 "Large Community list name\n")
14837
14838 DEFUN (no_lcommunity_list_standard,
14839 no_bgp_lcommunity_list_standard_cmd,
14840 "no bgp large-community-list (1-99) <deny|permit> AA:AA:NN...",
14841 NO_STR
14842 BGP_STR
14843 LCOMMUNITY_LIST_STR
14844 "Large Community list number (standard)\n"
14845 "Specify large community to reject\n"
14846 "Specify large community to accept\n"
14847 LCOMMUNITY_VAL_STR)
14848 {
14849 return lcommunity_list_unset_vty(vty, argc, argv,
14850 LARGE_COMMUNITY_LIST_STANDARD);
14851 }
14852
14853 ALIAS (no_lcommunity_list_standard,
14854 no_ip_lcommunity_list_standard_cmd,
14855 "no ip large-community-list (1-99) <deny|permit> AA:AA:NN...",
14856 NO_STR
14857 IP_STR
14858 LCOMMUNITY_LIST_STR
14859 "Large Community list number (standard)\n"
14860 "Specify large community to reject\n"
14861 "Specify large community to accept\n"
14862 LCOMMUNITY_VAL_STR)
14863
14864 DEFUN (no_lcommunity_list_expanded,
14865 no_bgp_lcommunity_list_expanded_cmd,
14866 "no bgp large-community-list (100-500) <deny|permit> LINE...",
14867 NO_STR
14868 BGP_STR
14869 LCOMMUNITY_LIST_STR
14870 "Large Community list number (expanded)\n"
14871 "Specify large community to reject\n"
14872 "Specify large community to accept\n"
14873 "An ordered list as a regular-expression\n")
14874 {
14875 return lcommunity_list_unset_vty(vty, argc, argv,
14876 LARGE_COMMUNITY_LIST_EXPANDED);
14877 }
14878
14879 ALIAS (no_lcommunity_list_expanded,
14880 no_ip_lcommunity_list_expanded_cmd,
14881 "no ip large-community-list (100-500) <deny|permit> LINE...",
14882 NO_STR
14883 IP_STR
14884 LCOMMUNITY_LIST_STR
14885 "Large Community list number (expanded)\n"
14886 "Specify large community to reject\n"
14887 "Specify large community to accept\n"
14888 "An ordered list as a regular-expression\n")
14889
14890 DEFUN (no_lcommunity_list_name_standard,
14891 no_bgp_lcommunity_list_name_standard_cmd,
14892 "no bgp large-community-list standard WORD <deny|permit> AA:AA:NN...",
14893 NO_STR
14894 BGP_STR
14895 LCOMMUNITY_LIST_STR
14896 "Specify standard large-community-list\n"
14897 "Large Community list name\n"
14898 "Specify large community to reject\n"
14899 "Specify large community to accept\n"
14900 LCOMMUNITY_VAL_STR)
14901 {
14902 return lcommunity_list_unset_vty(vty, argc, argv,
14903 LARGE_COMMUNITY_LIST_STANDARD);
14904 }
14905
14906 ALIAS (no_lcommunity_list_name_standard,
14907 no_ip_lcommunity_list_name_standard_cmd,
14908 "no ip large-community-list standard WORD <deny|permit> AA:AA:NN...",
14909 NO_STR
14910 IP_STR
14911 LCOMMUNITY_LIST_STR
14912 "Specify standard large-community-list\n"
14913 "Large Community list name\n"
14914 "Specify large community to reject\n"
14915 "Specify large community to accept\n"
14916 LCOMMUNITY_VAL_STR)
14917
14918 DEFUN (no_lcommunity_list_name_expanded,
14919 no_bgp_lcommunity_list_name_expanded_cmd,
14920 "no bgp large-community-list expanded WORD <deny|permit> LINE...",
14921 NO_STR
14922 BGP_STR
14923 LCOMMUNITY_LIST_STR
14924 "Specify expanded large-community-list\n"
14925 "Large community list name\n"
14926 "Specify large community to reject\n"
14927 "Specify large community to accept\n"
14928 "An ordered list as a regular-expression\n")
14929 {
14930 return lcommunity_list_unset_vty(vty, argc, argv,
14931 LARGE_COMMUNITY_LIST_EXPANDED);
14932 }
14933
14934 ALIAS (no_lcommunity_list_name_expanded,
14935 no_ip_lcommunity_list_name_expanded_cmd,
14936 "no ip large-community-list expanded WORD <deny|permit> LINE...",
14937 NO_STR
14938 IP_STR
14939 LCOMMUNITY_LIST_STR
14940 "Specify expanded large-community-list\n"
14941 "Large community list name\n"
14942 "Specify large community to reject\n"
14943 "Specify large community to accept\n"
14944 "An ordered list as a regular-expression\n")
14945
14946 static void lcommunity_list_show(struct vty *vty, struct community_list *list)
14947 {
14948 struct community_entry *entry;
14949
14950 for (entry = list->head; entry; entry = entry->next) {
14951 if (entry == list->head) {
14952 if (all_digit(list->name))
14953 vty_out(vty, "Large community %s list %s\n",
14954 entry->style == EXTCOMMUNITY_LIST_STANDARD
14955 ? "standard"
14956 : "(expanded) access",
14957 list->name);
14958 else
14959 vty_out(vty,
14960 "Named large community %s list %s\n",
14961 entry->style == EXTCOMMUNITY_LIST_STANDARD
14962 ? "standard"
14963 : "expanded",
14964 list->name);
14965 }
14966 if (entry->any)
14967 vty_out(vty, " %s\n",
14968 community_direct_str(entry->direct));
14969 else
14970 vty_out(vty, " %s %s\n",
14971 community_direct_str(entry->direct),
14972 community_list_config_str(entry));
14973 }
14974 }
14975
14976 DEFUN (show_lcommunity_list,
14977 show_bgp_lcommunity_list_cmd,
14978 "show bgp large-community-list",
14979 SHOW_STR
14980 BGP_STR
14981 "List large-community list\n")
14982 {
14983 struct community_list *list;
14984 struct community_list_master *cm;
14985 int idx = 0;
14986
14987 if (argv_find(argv, argc, "ip", &idx)) {
14988 vty_out(vty, "This config option is deprecated, and is scheduled for removal.\n");
14989 vty_out(vty, "if you are using this please migrate to the below command.\n");
14990 vty_out(vty, "'show bgp large-community-list <(1-500)|WORD>'\n");
14991 zlog_warn("Deprecated option: 'ip show large-community-list <(1-500)|WORD>' being used");
14992 }
14993
14994 cm = community_list_master_lookup(bgp_clist,
14995 LARGE_COMMUNITY_LIST_MASTER);
14996 if (!cm)
14997 return CMD_SUCCESS;
14998
14999 for (list = cm->num.head; list; list = list->next)
15000 lcommunity_list_show(vty, list);
15001
15002 for (list = cm->str.head; list; list = list->next)
15003 lcommunity_list_show(vty, list);
15004
15005 return CMD_SUCCESS;
15006 }
15007
15008 ALIAS (show_lcommunity_list,
15009 show_ip_lcommunity_list_cmd,
15010 "show ip large-community-list",
15011 SHOW_STR
15012 IP_STR
15013 "List large-community list\n")
15014
15015 DEFUN (show_lcommunity_list_arg,
15016 show_bgp_lcommunity_list_arg_cmd,
15017 "show bgp large-community-list <(1-500)|WORD>",
15018 SHOW_STR
15019 BGP_STR
15020 "List large-community list\n"
15021 "large-community-list number\n"
15022 "large-community-list name\n")
15023 {
15024 struct community_list *list;
15025 int idx = 0;
15026
15027 if (argv_find(argv, argc, "ip", &idx)) {
15028 vty_out(vty, "This config option is deprecated, and is scheduled for removal.\n");
15029 vty_out(vty, "if you are using this please migrate to the below command.\n");
15030 vty_out(vty, "'show bgp large-community-list <(1-500)|WORD>'\n");
15031 zlog_warn("Deprecated option: 'ip show large-community-list <(1-500)|WORD>' being used");
15032 }
15033
15034 list = community_list_lookup(bgp_clist, argv[3]->arg, 0,
15035 LARGE_COMMUNITY_LIST_MASTER);
15036 if (!list) {
15037 vty_out(vty, "%% Can't find extcommunity-list\n");
15038 return CMD_WARNING;
15039 }
15040
15041 lcommunity_list_show(vty, list);
15042
15043 return CMD_SUCCESS;
15044 }
15045
15046 ALIAS (show_lcommunity_list_arg,
15047 show_ip_lcommunity_list_arg_cmd,
15048 "show ip large-community-list <(1-500)|WORD>",
15049 SHOW_STR
15050 IP_STR
15051 "List large-community list\n"
15052 "large-community-list number\n"
15053 "large-community-list name\n")
15054
15055 /* "extcommunity-list" keyword help string. */
15056 #define EXTCOMMUNITY_LIST_STR "Add a extended community list entry\n"
15057 #define EXTCOMMUNITY_VAL_STR "Extended community attribute in 'rt aa:nn_or_IPaddr:nn' OR 'soo aa:nn_or_IPaddr:nn' format\n"
15058
15059 DEFUN (extcommunity_list_standard,
15060 bgp_extcommunity_list_standard_cmd,
15061 "bgp extcommunity-list <(1-99)|standard WORD> <deny|permit> AA:NN...",
15062 BGP_STR
15063 EXTCOMMUNITY_LIST_STR
15064 "Extended Community list number (standard)\n"
15065 "Specify standard extcommunity-list\n"
15066 "Community list name\n"
15067 "Specify community to reject\n"
15068 "Specify community to accept\n"
15069 EXTCOMMUNITY_VAL_STR)
15070 {
15071 int style = EXTCOMMUNITY_LIST_STANDARD;
15072 int direct = 0;
15073 char *cl_number_or_name = NULL;
15074
15075 int idx = 0;
15076 if (argv_find(argv, argc, "ip", &idx)) {
15077 vty_out(vty, "This config option is deprecated, and is scheduled for removal.\n");
15078 vty_out(vty, "if you are using this please migrate to the below command.\n");
15079 vty_out(vty, "'bgp extcommunity-list <(1-99)|(100-500)|standard|expanded> <deny|permit> <LINE|AA:NN>'\n");
15080 zlog_warn("Deprecated option: 'ip extcommunity-list <(1-99)|(100-500)|standard|expanded> <deny|permit> <LINE|AA:NN>' being used");
15081 }
15082 argv_find(argv, argc, "(1-99)", &idx);
15083 argv_find(argv, argc, "WORD", &idx);
15084 cl_number_or_name = argv[idx]->arg;
15085 direct = argv_find(argv, argc, "permit", &idx) ? COMMUNITY_PERMIT
15086 : COMMUNITY_DENY;
15087 argv_find(argv, argc, "AA:NN", &idx);
15088 char *str = argv_concat(argv, argc, idx);
15089
15090 int ret = extcommunity_list_set(bgp_clist, cl_number_or_name, str,
15091 direct, style);
15092
15093 XFREE(MTYPE_TMP, str);
15094
15095 if (ret < 0) {
15096 community_list_perror(vty, ret);
15097 return CMD_WARNING_CONFIG_FAILED;
15098 }
15099
15100 return CMD_SUCCESS;
15101 }
15102
15103 #if CONFDATE > 20191005
15104 CPP_NOTICE("bgpd: remove deprecated 'ip extcommunity-list <(1-99)|(100-500)|standard|expanded> <deny|permit> <LINE|AA:NN>' command")
15105 #endif
15106 ALIAS (extcommunity_list_standard,
15107 ip_extcommunity_list_standard_cmd,
15108 "ip extcommunity-list <(1-99)|standard WORD> <deny|permit> AA:NN...",
15109 IP_STR
15110 EXTCOMMUNITY_LIST_STR
15111 "Extended Community list number (standard)\n"
15112 "Specify standard extcommunity-list\n"
15113 "Community list name\n"
15114 "Specify community to reject\n"
15115 "Specify community to accept\n"
15116 EXTCOMMUNITY_VAL_STR)
15117
15118 DEFUN (extcommunity_list_name_expanded,
15119 bgp_extcommunity_list_name_expanded_cmd,
15120 "bgp extcommunity-list <(100-500)|expanded WORD> <deny|permit> LINE...",
15121 BGP_STR
15122 EXTCOMMUNITY_LIST_STR
15123 "Extended Community list number (expanded)\n"
15124 "Specify expanded extcommunity-list\n"
15125 "Extended Community list name\n"
15126 "Specify community to reject\n"
15127 "Specify community to accept\n"
15128 "An ordered list as a regular-expression\n")
15129 {
15130 int style = EXTCOMMUNITY_LIST_EXPANDED;
15131 int direct = 0;
15132 char *cl_number_or_name = NULL;
15133
15134 int idx = 0;
15135 if (argv_find(argv, argc, "ip", &idx)) {
15136 vty_out(vty, "This config option is deprecated, and is scheduled for removal.\n");
15137 vty_out(vty, "if you are using this please migrate to the below command.\n");
15138 vty_out(vty, "'extcommunity-list <(1-99)|(100-500)|standard|expanded> <deny|permit> <LINE|AA:NN>'\n");
15139 zlog_warn("Deprecated option: ‘ip extcommunity-list <(1-99)|(100-500)|standard|expanded> <deny|permit> <LINE|AA:NN>' being used");
15140 }
15141
15142 argv_find(argv, argc, "(100-500)", &idx);
15143 argv_find(argv, argc, "WORD", &idx);
15144 cl_number_or_name = argv[idx]->arg;
15145 direct = argv_find(argv, argc, "permit", &idx) ? COMMUNITY_PERMIT
15146 : COMMUNITY_DENY;
15147 argv_find(argv, argc, "LINE", &idx);
15148 char *str = argv_concat(argv, argc, idx);
15149
15150 int ret = extcommunity_list_set(bgp_clist, cl_number_or_name, str,
15151 direct, style);
15152
15153 XFREE(MTYPE_TMP, str);
15154
15155 if (ret < 0) {
15156 community_list_perror(vty, ret);
15157 return CMD_WARNING_CONFIG_FAILED;
15158 }
15159
15160 return CMD_SUCCESS;
15161 }
15162
15163 ALIAS (extcommunity_list_name_expanded,
15164 ip_extcommunity_list_name_expanded_cmd,
15165 "ip extcommunity-list <(100-500)|expanded WORD> <deny|permit> LINE...",
15166 IP_STR
15167 EXTCOMMUNITY_LIST_STR
15168 "Extended Community list number (expanded)\n"
15169 "Specify expanded extcommunity-list\n"
15170 "Extended Community list name\n"
15171 "Specify community to reject\n"
15172 "Specify community to accept\n"
15173 "An ordered list as a regular-expression\n")
15174
15175 DEFUN (no_extcommunity_list_standard_all,
15176 no_bgp_extcommunity_list_standard_all_cmd,
15177 "no bgp extcommunity-list <(1-99)|standard WORD> <deny|permit> AA:NN...",
15178 NO_STR
15179 BGP_STR
15180 EXTCOMMUNITY_LIST_STR
15181 "Extended Community list number (standard)\n"
15182 "Specify standard extcommunity-list\n"
15183 "Community list name\n"
15184 "Specify community to reject\n"
15185 "Specify community to accept\n"
15186 EXTCOMMUNITY_VAL_STR)
15187 {
15188 int style = EXTCOMMUNITY_LIST_STANDARD;
15189 int direct = 0;
15190 char *cl_number_or_name = NULL;
15191 char *str = NULL;
15192
15193 int idx = 0;
15194 if (argv_find(argv, argc, "ip", &idx)) {
15195 vty_out(vty, "This config option is deprecated, and is scheduled for removal\n");
15196 vty_out(vty, "if you are using this please migrate to the below command.\n");
15197 vty_out(vty, "'no bgp extcommunity-list <(1-99)|(100-500)|standard|expanded> <deny|permit> <LINE|AA:NN>'\n");
15198 zlog_warn("Deprecated option: ‘no ip extcommunity-list <(1-99)|(100-500)|standard|expanded> <deny|permit> <LINE|AA:NN>' being used");
15199 }
15200
15201 idx = 0;
15202 argv_find(argv, argc, "permit", &idx);
15203 argv_find(argv, argc, "deny", &idx);
15204
15205 if (idx) {
15206 direct = argv_find(argv, argc, "permit", &idx)
15207 ? COMMUNITY_PERMIT
15208 : COMMUNITY_DENY;
15209
15210 idx = 0;
15211 argv_find(argv, argc, "AA:NN", &idx);
15212 str = argv_concat(argv, argc, idx);
15213 }
15214
15215 idx = 0;
15216 argv_find(argv, argc, "(1-99)", &idx);
15217 argv_find(argv, argc, "WORD", &idx);
15218 cl_number_or_name = argv[idx]->arg;
15219
15220 int ret = extcommunity_list_unset(bgp_clist, cl_number_or_name, str,
15221 direct, style);
15222
15223 XFREE(MTYPE_TMP, str);
15224
15225 if (ret < 0) {
15226 community_list_perror(vty, ret);
15227 return CMD_WARNING_CONFIG_FAILED;
15228 }
15229
15230 return CMD_SUCCESS;
15231 }
15232
15233 ALIAS (no_extcommunity_list_standard_all,
15234 no_ip_extcommunity_list_standard_all_cmd,
15235 "no ip extcommunity-list <(1-99)|standard WORD> <deny|permit> AA:NN...",
15236 NO_STR
15237 IP_STR
15238 EXTCOMMUNITY_LIST_STR
15239 "Extended Community list number (standard)\n"
15240 "Specify standard extcommunity-list\n"
15241 "Community list name\n"
15242 "Specify community to reject\n"
15243 "Specify community to accept\n"
15244 EXTCOMMUNITY_VAL_STR)
15245
15246 ALIAS(no_extcommunity_list_standard_all,
15247 no_bgp_extcommunity_list_standard_all_list_cmd,
15248 "no bgp extcommunity-list <(1-99)|standard WORD>",
15249 NO_STR IP_STR EXTCOMMUNITY_LIST_STR
15250 "Extended Community list number (standard)\n"
15251 "Specify standard extcommunity-list\n"
15252 "Community list name\n")
15253
15254 ALIAS(no_extcommunity_list_standard_all,
15255 no_ip_extcommunity_list_standard_all_list_cmd,
15256 "no ip extcommunity-list <(1-99)|standard WORD>",
15257 NO_STR IP_STR EXTCOMMUNITY_LIST_STR
15258 "Extended Community list number (standard)\n"
15259 "Specify standard extcommunity-list\n"
15260 "Community list name\n")
15261
15262 DEFUN (no_extcommunity_list_expanded_all,
15263 no_bgp_extcommunity_list_expanded_all_cmd,
15264 "no bgp extcommunity-list <(100-500)|expanded WORD> <deny|permit> LINE...",
15265 NO_STR
15266 BGP_STR
15267 EXTCOMMUNITY_LIST_STR
15268 "Extended Community list number (expanded)\n"
15269 "Specify expanded extcommunity-list\n"
15270 "Extended Community list name\n"
15271 "Specify community to reject\n"
15272 "Specify community to accept\n"
15273 "An ordered list as a regular-expression\n")
15274 {
15275 int style = EXTCOMMUNITY_LIST_EXPANDED;
15276 int direct = 0;
15277 char *cl_number_or_name = NULL;
15278 char *str = NULL;
15279
15280 int idx = 0;
15281 if (argv_find(argv, argc, "ip", &idx)) {
15282 vty_out(vty, "This config option is deprecated, and is scheduled for removal.\n");
15283 vty_out(vty, "if you are using this please migrate to the below command.\n");
15284 vty_out(vty, "'no bgp extcommunity-list <(1-99)|(100-500)|standard|expanded> <deny|permit> <LINE|AA:NN>'\n");
15285 zlog_warn("Deprecated option: ‘no ip extcommunity-list <(1-99)|(100-500)|standard|expanded> <deny|permit> <LINE|AA:NN>' being used");
15286 }
15287
15288 idx = 0;
15289 argv_find(argv, argc, "permit", &idx);
15290 argv_find(argv, argc, "deny", &idx);
15291
15292 if (idx) {
15293 direct = argv_find(argv, argc, "permit", &idx)
15294 ? COMMUNITY_PERMIT
15295 : COMMUNITY_DENY;
15296
15297 idx = 0;
15298 argv_find(argv, argc, "LINE", &idx);
15299 str = argv_concat(argv, argc, idx);
15300 }
15301
15302 idx = 0;
15303 argv_find(argv, argc, "(100-500)", &idx);
15304 argv_find(argv, argc, "WORD", &idx);
15305 cl_number_or_name = argv[idx]->arg;
15306
15307 int ret = extcommunity_list_unset(bgp_clist, cl_number_or_name, str,
15308 direct, style);
15309
15310 XFREE(MTYPE_TMP, str);
15311
15312 if (ret < 0) {
15313 community_list_perror(vty, ret);
15314 return CMD_WARNING_CONFIG_FAILED;
15315 }
15316
15317 return CMD_SUCCESS;
15318 }
15319
15320 ALIAS (no_extcommunity_list_expanded_all,
15321 no_ip_extcommunity_list_expanded_all_cmd,
15322 "no ip extcommunity-list <(100-500)|expanded WORD> <deny|permit> LINE...",
15323 NO_STR
15324 IP_STR
15325 EXTCOMMUNITY_LIST_STR
15326 "Extended Community list number (expanded)\n"
15327 "Specify expanded extcommunity-list\n"
15328 "Extended Community list name\n"
15329 "Specify community to reject\n"
15330 "Specify community to accept\n"
15331 "An ordered list as a regular-expression\n")
15332
15333 ALIAS(no_extcommunity_list_expanded_all,
15334 no_ip_extcommunity_list_expanded_all_list_cmd,
15335 "no ip extcommunity-list <(100-500)|expanded WORD>",
15336 NO_STR IP_STR EXTCOMMUNITY_LIST_STR
15337 "Extended Community list number (expanded)\n"
15338 "Specify expanded extcommunity-list\n"
15339 "Extended Community list name\n")
15340
15341 ALIAS(no_extcommunity_list_expanded_all,
15342 no_bgp_extcommunity_list_expanded_all_list_cmd,
15343 "no bgp extcommunity-list <(100-500)|expanded WORD>",
15344 NO_STR IP_STR EXTCOMMUNITY_LIST_STR
15345 "Extended Community list number (expanded)\n"
15346 "Specify expanded extcommunity-list\n"
15347 "Extended Community list name\n")
15348
15349 static void extcommunity_list_show(struct vty *vty, struct community_list *list)
15350 {
15351 struct community_entry *entry;
15352
15353 for (entry = list->head; entry; entry = entry->next) {
15354 if (entry == list->head) {
15355 if (all_digit(list->name))
15356 vty_out(vty, "Extended community %s list %s\n",
15357 entry->style == EXTCOMMUNITY_LIST_STANDARD
15358 ? "standard"
15359 : "(expanded) access",
15360 list->name);
15361 else
15362 vty_out(vty,
15363 "Named extended community %s list %s\n",
15364 entry->style == EXTCOMMUNITY_LIST_STANDARD
15365 ? "standard"
15366 : "expanded",
15367 list->name);
15368 }
15369 if (entry->any)
15370 vty_out(vty, " %s\n",
15371 community_direct_str(entry->direct));
15372 else
15373 vty_out(vty, " %s %s\n",
15374 community_direct_str(entry->direct),
15375 community_list_config_str(entry));
15376 }
15377 }
15378
15379 DEFUN (show_extcommunity_list,
15380 show_bgp_extcommunity_list_cmd,
15381 "show bgp extcommunity-list",
15382 SHOW_STR
15383 BGP_STR
15384 "List extended-community list\n")
15385 {
15386 struct community_list *list;
15387 struct community_list_master *cm;
15388 int idx = 0;
15389
15390 if (argv_find(argv, argc, "ip", &idx)) {
15391 vty_out(vty, "This config option is deprecated, and is scheduled for removal\n");
15392 vty_out(vty, "if you are using this please migrate to the below command.\n");
15393 vty_out(vty, "'show bgp extcommunity-list <(1-500)|WORD>'\n");
15394 zlog_warn("Deprecated option: 'ip show extcommunity-list <(1-500)|WORD>' being used");
15395 }
15396 cm = community_list_master_lookup(bgp_clist, EXTCOMMUNITY_LIST_MASTER);
15397 if (!cm)
15398 return CMD_SUCCESS;
15399
15400 for (list = cm->num.head; list; list = list->next)
15401 extcommunity_list_show(vty, list);
15402
15403 for (list = cm->str.head; list; list = list->next)
15404 extcommunity_list_show(vty, list);
15405
15406 return CMD_SUCCESS;
15407 }
15408
15409 ALIAS (show_extcommunity_list,
15410 show_ip_extcommunity_list_cmd,
15411 "show ip extcommunity-list",
15412 SHOW_STR
15413 IP_STR
15414 "List extended-community list\n")
15415
15416 DEFUN (show_extcommunity_list_arg,
15417 show_bgp_extcommunity_list_arg_cmd,
15418 "show bgp extcommunity-list <(1-500)|WORD>",
15419 SHOW_STR
15420 BGP_STR
15421 "List extended-community list\n"
15422 "Extcommunity-list number\n"
15423 "Extcommunity-list name\n")
15424 {
15425 int idx_comm_list = 3;
15426 struct community_list *list;
15427 int idx = 0;
15428
15429 if (argv_find(argv, argc, "ip", &idx)) {
15430 vty_out(vty, "This config option is deprecated, and is scheduled for removal.\n");
15431 vty_out(vty, "if you are using this please migrate to the below command.\n");
15432 vty_out(vty, "'show bgp extcommunity-list <(1-500)|WORD>'\n");
15433 zlog_warn("Deprecated option: 'ip show extcommunity-list <(1-500)|WORD>' being used");
15434 }
15435 list = community_list_lookup(bgp_clist, argv[idx_comm_list]->arg, 0,
15436 EXTCOMMUNITY_LIST_MASTER);
15437 if (!list) {
15438 vty_out(vty, "%% Can't find extcommunity-list\n");
15439 return CMD_WARNING;
15440 }
15441
15442 extcommunity_list_show(vty, list);
15443
15444 return CMD_SUCCESS;
15445 }
15446
15447 ALIAS (show_extcommunity_list_arg,
15448 show_ip_extcommunity_list_arg_cmd,
15449 "show ip extcommunity-list <(1-500)|WORD>",
15450 SHOW_STR
15451 IP_STR
15452 "List extended-community list\n"
15453 "Extcommunity-list number\n"
15454 "Extcommunity-list name\n")
15455
15456 /* Display community-list and extcommunity-list configuration. */
15457 static int community_list_config_write(struct vty *vty)
15458 {
15459 struct community_list *list;
15460 struct community_entry *entry;
15461 struct community_list_master *cm;
15462 int write = 0;
15463
15464 /* Community-list. */
15465 cm = community_list_master_lookup(bgp_clist, COMMUNITY_LIST_MASTER);
15466
15467 for (list = cm->num.head; list; list = list->next)
15468 for (entry = list->head; entry; entry = entry->next) {
15469 vty_out(vty, "bgp community-list %s %s %s\n", list->name,
15470 community_direct_str(entry->direct),
15471 community_list_config_str(entry));
15472 write++;
15473 }
15474 for (list = cm->str.head; list; list = list->next)
15475 for (entry = list->head; entry; entry = entry->next) {
15476 vty_out(vty, "bgp community-list %s %s %s %s\n",
15477 entry->style == COMMUNITY_LIST_STANDARD
15478 ? "standard"
15479 : "expanded",
15480 list->name, community_direct_str(entry->direct),
15481 community_list_config_str(entry));
15482 write++;
15483 }
15484
15485 /* Extcommunity-list. */
15486 cm = community_list_master_lookup(bgp_clist, EXTCOMMUNITY_LIST_MASTER);
15487
15488 for (list = cm->num.head; list; list = list->next)
15489 for (entry = list->head; entry; entry = entry->next) {
15490 vty_out(vty, "bgp extcommunity-list %s %s %s\n",
15491 list->name, community_direct_str(entry->direct),
15492 community_list_config_str(entry));
15493 write++;
15494 }
15495 for (list = cm->str.head; list; list = list->next)
15496 for (entry = list->head; entry; entry = entry->next) {
15497 vty_out(vty, "bgp extcommunity-list %s %s %s %s\n",
15498 entry->style == EXTCOMMUNITY_LIST_STANDARD
15499 ? "standard"
15500 : "expanded",
15501 list->name, community_direct_str(entry->direct),
15502 community_list_config_str(entry));
15503 write++;
15504 }
15505
15506
15507 /* lcommunity-list. */
15508 cm = community_list_master_lookup(bgp_clist,
15509 LARGE_COMMUNITY_LIST_MASTER);
15510
15511 for (list = cm->num.head; list; list = list->next)
15512 for (entry = list->head; entry; entry = entry->next) {
15513 vty_out(vty, "bgp large-community-list %s %s %s\n",
15514 list->name, community_direct_str(entry->direct),
15515 community_list_config_str(entry));
15516 write++;
15517 }
15518 for (list = cm->str.head; list; list = list->next)
15519 for (entry = list->head; entry; entry = entry->next) {
15520 vty_out(vty, "bgp large-community-list %s %s %s %s\n",
15521 entry->style == LARGE_COMMUNITY_LIST_STANDARD
15522 ? "standard"
15523 : "expanded",
15524 list->name, community_direct_str(entry->direct),
15525 community_list_config_str(entry));
15526 write++;
15527 }
15528
15529 return write;
15530 }
15531
15532 static struct cmd_node community_list_node = {
15533 COMMUNITY_LIST_NODE, "", 1 /* Export to vtysh. */
15534 };
15535
15536 static void community_list_vty(void)
15537 {
15538 install_node(&community_list_node, community_list_config_write);
15539
15540 /* Community-list. */
15541 install_element(CONFIG_NODE, &bgp_community_list_standard_cmd);
15542 install_element(CONFIG_NODE, &bgp_community_list_expanded_all_cmd);
15543 install_element(CONFIG_NODE, &no_bgp_community_list_standard_all_cmd);
15544 install_element(CONFIG_NODE, &no_bgp_community_list_standard_all_list_cmd);
15545 install_element(CONFIG_NODE, &no_bgp_community_list_expanded_all_cmd);
15546 install_element(CONFIG_NODE, &no_bgp_community_list_expanded_all_list_cmd);
15547 install_element(VIEW_NODE, &show_bgp_community_list_cmd);
15548 install_element(VIEW_NODE, &show_bgp_community_list_arg_cmd);
15549 install_element(CONFIG_NODE, &ip_community_list_standard_cmd);
15550 install_element(CONFIG_NODE, &ip_community_list_expanded_all_cmd);
15551 install_element(CONFIG_NODE, &no_ip_community_list_standard_all_cmd);
15552 install_element(CONFIG_NODE, &no_ip_community_list_standard_all_list_cmd);
15553 install_element(CONFIG_NODE, &no_ip_community_list_expanded_all_cmd);
15554 install_element(CONFIG_NODE, &no_ip_community_list_expanded_all_list_cmd);
15555 install_element(VIEW_NODE, &show_ip_community_list_cmd);
15556 install_element(VIEW_NODE, &show_ip_community_list_arg_cmd);
15557
15558 /* Extcommunity-list. */
15559 install_element(CONFIG_NODE, &bgp_extcommunity_list_standard_cmd);
15560 install_element(CONFIG_NODE, &bgp_extcommunity_list_name_expanded_cmd);
15561 install_element(CONFIG_NODE, &no_bgp_extcommunity_list_standard_all_cmd);
15562 install_element(CONFIG_NODE,
15563 &no_bgp_extcommunity_list_standard_all_list_cmd);
15564 install_element(CONFIG_NODE, &no_bgp_extcommunity_list_expanded_all_cmd);
15565 install_element(CONFIG_NODE,
15566 &no_bgp_extcommunity_list_expanded_all_list_cmd);
15567 install_element(VIEW_NODE, &show_bgp_extcommunity_list_cmd);
15568 install_element(VIEW_NODE, &show_bgp_extcommunity_list_arg_cmd);
15569 install_element(CONFIG_NODE, &ip_extcommunity_list_standard_cmd);
15570 install_element(CONFIG_NODE, &ip_extcommunity_list_name_expanded_cmd);
15571 install_element(CONFIG_NODE, &no_ip_extcommunity_list_standard_all_cmd);
15572 install_element(CONFIG_NODE, &no_ip_extcommunity_list_standard_all_list_cmd);
15573 install_element(CONFIG_NODE, &no_ip_extcommunity_list_expanded_all_cmd);
15574 install_element(CONFIG_NODE, &no_ip_extcommunity_list_expanded_all_list_cmd);
15575 install_element(VIEW_NODE, &show_ip_extcommunity_list_cmd);
15576 install_element(VIEW_NODE, &show_ip_extcommunity_list_arg_cmd);
15577
15578 /* Large Community List */
15579 install_element(CONFIG_NODE, &bgp_lcommunity_list_standard_cmd);
15580 install_element(CONFIG_NODE, &bgp_lcommunity_list_standard1_cmd);
15581 install_element(CONFIG_NODE, &bgp_lcommunity_list_expanded_cmd);
15582 install_element(CONFIG_NODE, &bgp_lcommunity_list_name_standard_cmd);
15583 install_element(CONFIG_NODE, &bgp_lcommunity_list_name_standard1_cmd);
15584 install_element(CONFIG_NODE, &bgp_lcommunity_list_name_expanded_cmd);
15585 install_element(CONFIG_NODE, &no_bgp_lcommunity_list_standard_all_cmd);
15586 install_element(CONFIG_NODE,
15587 &no_bgp_lcommunity_list_name_expanded_all_cmd);
15588 install_element(CONFIG_NODE, &no_bgp_lcommunity_list_standard_cmd);
15589 install_element(CONFIG_NODE, &no_bgp_lcommunity_list_expanded_cmd);
15590 install_element(CONFIG_NODE, &no_bgp_lcommunity_list_name_standard_cmd);
15591 install_element(CONFIG_NODE, &no_bgp_lcommunity_list_name_expanded_cmd);
15592 install_element(VIEW_NODE, &show_bgp_lcommunity_list_cmd);
15593 install_element(VIEW_NODE, &show_bgp_lcommunity_list_arg_cmd);
15594 install_element(CONFIG_NODE, &ip_lcommunity_list_standard_cmd);
15595 install_element(CONFIG_NODE, &ip_lcommunity_list_standard1_cmd);
15596 install_element(CONFIG_NODE, &ip_lcommunity_list_expanded_cmd);
15597 install_element(CONFIG_NODE, &ip_lcommunity_list_name_standard_cmd);
15598 install_element(CONFIG_NODE, &ip_lcommunity_list_name_standard1_cmd);
15599 install_element(CONFIG_NODE, &ip_lcommunity_list_name_expanded_cmd);
15600 install_element(CONFIG_NODE, &no_ip_lcommunity_list_standard_all_cmd);
15601 install_element(CONFIG_NODE,
15602 &no_ip_lcommunity_list_name_expanded_all_cmd);
15603 install_element(CONFIG_NODE, &no_ip_lcommunity_list_standard_cmd);
15604 install_element(CONFIG_NODE, &no_ip_lcommunity_list_expanded_cmd);
15605 install_element(CONFIG_NODE, &no_ip_lcommunity_list_name_standard_cmd);
15606 install_element(CONFIG_NODE, &no_ip_lcommunity_list_name_expanded_cmd);
15607 install_element(VIEW_NODE, &show_ip_lcommunity_list_cmd);
15608 install_element(VIEW_NODE, &show_ip_lcommunity_list_arg_cmd);
15609 }