]> git.proxmox.com Git - mirror_frr.git/blob - bgpd/bgp_vty.c
Merge pull request #3949 from qlyoung/remove-zlog-newlines
[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 bgp_clear_vty(vty, name, AFI_IP, SAFI_UNICAST, clear_all,
775 BGP_CLEAR_SOFT_IN, NULL);
776 bgp_clear_vty(vty, name, AFI_IP6, SAFI_UNICAST, clear_all,
777 BGP_CLEAR_SOFT_IN, NULL);
778 }
779
780 /* clear soft outbound */
781 static void bgp_clear_star_soft_out(struct vty *vty, const char *name)
782 {
783 bgp_clear_vty(vty, name, AFI_IP, SAFI_UNICAST, clear_all,
784 BGP_CLEAR_SOFT_OUT, NULL);
785 bgp_clear_vty(vty, name, AFI_IP6, SAFI_UNICAST, clear_all,
786 BGP_CLEAR_SOFT_OUT, NULL);
787 }
788
789
790 #ifndef VTYSH_EXTRACT_PL
791 #include "bgpd/bgp_vty_clippy.c"
792 #endif
793
794 /* BGP global configuration. */
795 #if (CONFDATE > 20190601)
796 CPP_NOTICE("bgpd: time to remove deprecated bgp multiple-instance")
797 CPP_NOTICE("This includes BGP_OPT_MULTIPLE_INSTANCE")
798 #endif
799 DEFUN_HIDDEN (bgp_multiple_instance_func,
800 bgp_multiple_instance_cmd,
801 "bgp multiple-instance",
802 BGP_STR
803 "Enable bgp multiple instance\n")
804 {
805 bgp_option_set(BGP_OPT_MULTIPLE_INSTANCE);
806 return CMD_SUCCESS;
807 }
808
809 DEFUN_HIDDEN (no_bgp_multiple_instance,
810 no_bgp_multiple_instance_cmd,
811 "no bgp multiple-instance",
812 NO_STR
813 BGP_STR
814 "BGP multiple instance\n")
815 {
816 int ret;
817
818 vty_out(vty, "This config option is deprecated, and is scheduled for removal.\n");
819 vty_out(vty, "if you are using this please let the developers know\n");
820 zlog_info("Deprecated option: `bgp multiple-instance` being used");
821 ret = bgp_option_unset(BGP_OPT_MULTIPLE_INSTANCE);
822 if (ret < 0) {
823 vty_out(vty, "%% There are more than two BGP instances\n");
824 return CMD_WARNING_CONFIG_FAILED;
825 }
826 return CMD_SUCCESS;
827 }
828
829 DEFUN_HIDDEN (bgp_local_mac,
830 bgp_local_mac_cmd,
831 "bgp local-mac vni " CMD_VNI_RANGE " mac WORD seq (0-4294967295)",
832 BGP_STR
833 "Local MAC config\n"
834 "VxLAN Network Identifier\n"
835 "VNI number\n"
836 "local mac\n"
837 "mac address\n"
838 "mac-mobility sequence\n"
839 "seq number\n")
840 {
841 int rv;
842 vni_t vni;
843 struct ethaddr mac;
844 struct ipaddr ip;
845 uint32_t seq;
846 struct bgp *bgp;
847
848 vni = strtoul(argv[3]->arg, NULL, 10);
849 if (!prefix_str2mac(argv[5]->arg, &mac)) {
850 vty_out(vty, "%% Malformed MAC address\n");
851 return CMD_WARNING;
852 }
853 memset(&ip, 0, sizeof(ip));
854 seq = strtoul(argv[7]->arg, NULL, 10);
855
856 bgp = bgp_get_default();
857 if (!bgp) {
858 vty_out(vty, "Default BGP instance is not there\n");
859 return CMD_WARNING;
860 }
861
862 rv = bgp_evpn_local_macip_add(bgp, vni, &mac, &ip, 0 /* flags */, seq);
863 if (rv < 0) {
864 vty_out(vty, "Internal error\n");
865 return CMD_WARNING;
866 }
867
868 return CMD_SUCCESS;
869 }
870
871 DEFUN_HIDDEN (no_bgp_local_mac,
872 no_bgp_local_mac_cmd,
873 "no bgp local-mac vni " CMD_VNI_RANGE " mac WORD",
874 NO_STR
875 BGP_STR
876 "Local MAC config\n"
877 "VxLAN Network Identifier\n"
878 "VNI number\n"
879 "local mac\n"
880 "mac address\n")
881 {
882 int rv;
883 vni_t vni;
884 struct ethaddr mac;
885 struct ipaddr ip;
886 struct bgp *bgp;
887
888 vni = strtoul(argv[4]->arg, NULL, 10);
889 if (!prefix_str2mac(argv[6]->arg, &mac)) {
890 vty_out(vty, "%% Malformed MAC address\n");
891 return CMD_WARNING;
892 }
893 memset(&ip, 0, sizeof(ip));
894
895 bgp = bgp_get_default();
896 if (!bgp) {
897 vty_out(vty, "Default BGP instance is not there\n");
898 return CMD_WARNING;
899 }
900
901 rv = bgp_evpn_local_macip_del(bgp, vni, &mac, &ip, ZEBRA_NEIGH_ACTIVE);
902 if (rv < 0) {
903 vty_out(vty, "Internal error\n");
904 return CMD_WARNING;
905 }
906
907 return CMD_SUCCESS;
908 }
909
910 #if (CONFDATE > 20190601)
911 CPP_NOTICE("bgpd: time to remove deprecated cli bgp config-type cisco")
912 CPP_NOTICE("This includes BGP_OPT_CISCO_CONFIG")
913 #endif
914 DEFUN_HIDDEN (bgp_config_type,
915 bgp_config_type_cmd,
916 "bgp config-type <cisco|zebra>",
917 BGP_STR
918 "Configuration type\n"
919 "cisco\n"
920 "zebra\n")
921 {
922 int idx = 0;
923 if (argv_find(argv, argc, "cisco", &idx)) {
924 vty_out(vty, "This config option is deprecated, and is scheduled for removal.\n");
925 vty_out(vty, "if you are using this please let the developers know!\n");
926 zlog_info("Deprecated option: `bgp config-type cisco` being used");
927 bgp_option_set(BGP_OPT_CONFIG_CISCO);
928 } else
929 bgp_option_unset(BGP_OPT_CONFIG_CISCO);
930
931 return CMD_SUCCESS;
932 }
933
934 DEFUN_HIDDEN (no_bgp_config_type,
935 no_bgp_config_type_cmd,
936 "no bgp config-type [<cisco|zebra>]",
937 NO_STR
938 BGP_STR
939 "Display configuration type\n"
940 "cisco\n"
941 "zebra\n")
942 {
943 bgp_option_unset(BGP_OPT_CONFIG_CISCO);
944 return CMD_SUCCESS;
945 }
946
947
948 DEFUN (no_synchronization,
949 no_synchronization_cmd,
950 "no synchronization",
951 NO_STR
952 "Perform IGP synchronization\n")
953 {
954 return CMD_SUCCESS;
955 }
956
957 DEFUN (no_auto_summary,
958 no_auto_summary_cmd,
959 "no auto-summary",
960 NO_STR
961 "Enable automatic network number summarization\n")
962 {
963 return CMD_SUCCESS;
964 }
965
966 /* "router bgp" commands. */
967 DEFUN_NOSH (router_bgp,
968 router_bgp_cmd,
969 "router bgp [(1-4294967295) [<view|vrf> VIEWVRFNAME]]",
970 ROUTER_STR
971 BGP_STR
972 AS_STR
973 BGP_INSTANCE_HELP_STR)
974 {
975 int idx_asn = 2;
976 int idx_view_vrf = 3;
977 int idx_vrf = 4;
978 int is_new_bgp = 0;
979 int ret;
980 as_t as;
981 struct bgp *bgp;
982 const char *name = NULL;
983 enum bgp_instance_type inst_type;
984
985 // "router bgp" without an ASN
986 if (argc == 2) {
987 // Pending: Make VRF option available for ASN less config
988 bgp = bgp_get_default();
989
990 if (bgp == NULL) {
991 vty_out(vty, "%% No BGP process is configured\n");
992 return CMD_WARNING_CONFIG_FAILED;
993 }
994
995 if (listcount(bm->bgp) > 1) {
996 vty_out(vty, "%% Please specify ASN and VRF\n");
997 return CMD_WARNING_CONFIG_FAILED;
998 }
999 }
1000
1001 // "router bgp X"
1002 else {
1003 as = strtoul(argv[idx_asn]->arg, NULL, 10);
1004
1005 inst_type = BGP_INSTANCE_TYPE_DEFAULT;
1006 if (argc > 3) {
1007 name = argv[idx_vrf]->arg;
1008
1009 if (!strcmp(argv[idx_view_vrf]->text, "vrf")) {
1010 if (strmatch(name, VRF_DEFAULT_NAME))
1011 name = NULL;
1012 else
1013 inst_type = BGP_INSTANCE_TYPE_VRF;
1014 } else if (!strcmp(argv[idx_view_vrf]->text, "view"))
1015 inst_type = BGP_INSTANCE_TYPE_VIEW;
1016 }
1017
1018 if (inst_type == BGP_INSTANCE_TYPE_DEFAULT)
1019 is_new_bgp = (bgp_lookup(as, name) == NULL);
1020
1021 ret = bgp_get(&bgp, &as, name, inst_type);
1022 switch (ret) {
1023 case BGP_ERR_MULTIPLE_INSTANCE_NOT_SET:
1024 vty_out(vty,
1025 "Please specify 'bgp multiple-instance' first\n");
1026 return CMD_WARNING_CONFIG_FAILED;
1027 case BGP_ERR_AS_MISMATCH:
1028 vty_out(vty, "BGP is already running; AS is %u\n", as);
1029 return CMD_WARNING_CONFIG_FAILED;
1030 case BGP_ERR_INSTANCE_MISMATCH:
1031 vty_out(vty,
1032 "BGP instance name and AS number mismatch\n");
1033 vty_out(vty,
1034 "BGP instance is already running; AS is %u\n",
1035 as);
1036 return CMD_WARNING_CONFIG_FAILED;
1037 }
1038
1039 /*
1040 * If we just instantiated the default instance, complete
1041 * any pending VRF-VPN leaking that was configured via
1042 * earlier "router bgp X vrf FOO" blocks.
1043 */
1044 if (is_new_bgp && inst_type == BGP_INSTANCE_TYPE_DEFAULT)
1045 vpn_leak_postchange_all();
1046
1047 /* Pending: handle when user tries to change a view to vrf n vv.
1048 */
1049 }
1050
1051 /* unset the auto created flag as the user config is now present */
1052 UNSET_FLAG(bgp->vrf_flags, BGP_VRF_AUTO);
1053 VTY_PUSH_CONTEXT(BGP_NODE, bgp);
1054
1055 return CMD_SUCCESS;
1056 }
1057
1058 /* "no router bgp" commands. */
1059 DEFUN (no_router_bgp,
1060 no_router_bgp_cmd,
1061 "no router bgp [(1-4294967295) [<view|vrf> VIEWVRFNAME]]",
1062 NO_STR
1063 ROUTER_STR
1064 BGP_STR
1065 AS_STR
1066 BGP_INSTANCE_HELP_STR)
1067 {
1068 int idx_asn = 3;
1069 int idx_vrf = 5;
1070 as_t as;
1071 struct bgp *bgp;
1072 const char *name = NULL;
1073
1074 // "no router bgp" without an ASN
1075 if (argc == 3) {
1076 // Pending: Make VRF option available for ASN less config
1077 bgp = bgp_get_default();
1078
1079 if (bgp == NULL) {
1080 vty_out(vty, "%% No BGP process is configured\n");
1081 return CMD_WARNING_CONFIG_FAILED;
1082 }
1083
1084 if (listcount(bm->bgp) > 1) {
1085 vty_out(vty, "%% Please specify ASN and VRF\n");
1086 return CMD_WARNING_CONFIG_FAILED;
1087 }
1088
1089 if (bgp->l3vni) {
1090 vty_out(vty, "%% Please unconfigure l3vni %u",
1091 bgp->l3vni);
1092 return CMD_WARNING_CONFIG_FAILED;
1093 }
1094 } else {
1095 as = strtoul(argv[idx_asn]->arg, NULL, 10);
1096
1097 if (argc > 4)
1098 name = argv[idx_vrf]->arg;
1099
1100 /* Lookup bgp structure. */
1101 bgp = bgp_lookup(as, name);
1102 if (!bgp) {
1103 vty_out(vty, "%% Can't find BGP instance\n");
1104 return CMD_WARNING_CONFIG_FAILED;
1105 }
1106
1107 if (bgp->l3vni) {
1108 vty_out(vty, "%% Please unconfigure l3vni %u",
1109 bgp->l3vni);
1110 return CMD_WARNING_CONFIG_FAILED;
1111 }
1112 }
1113
1114 bgp_delete(bgp);
1115
1116 return CMD_SUCCESS;
1117 }
1118
1119
1120 /* BGP router-id. */
1121
1122 DEFPY (bgp_router_id,
1123 bgp_router_id_cmd,
1124 "bgp router-id A.B.C.D",
1125 BGP_STR
1126 "Override configured router identifier\n"
1127 "Manually configured router identifier\n")
1128 {
1129 VTY_DECLVAR_CONTEXT(bgp, bgp);
1130 bgp_router_id_static_set(bgp, router_id);
1131 return CMD_SUCCESS;
1132 }
1133
1134 DEFPY (no_bgp_router_id,
1135 no_bgp_router_id_cmd,
1136 "no bgp router-id [A.B.C.D]",
1137 NO_STR
1138 BGP_STR
1139 "Override configured router identifier\n"
1140 "Manually configured router identifier\n")
1141 {
1142 VTY_DECLVAR_CONTEXT(bgp, bgp);
1143
1144 if (router_id_str) {
1145 if (!IPV4_ADDR_SAME(&bgp->router_id_static, &router_id)) {
1146 vty_out(vty, "%% BGP router-id doesn't match\n");
1147 return CMD_WARNING_CONFIG_FAILED;
1148 }
1149 }
1150
1151 router_id.s_addr = 0;
1152 bgp_router_id_static_set(bgp, router_id);
1153
1154 return CMD_SUCCESS;
1155 }
1156
1157
1158 /* BGP Cluster ID. */
1159 DEFUN (bgp_cluster_id,
1160 bgp_cluster_id_cmd,
1161 "bgp cluster-id <A.B.C.D|(1-4294967295)>",
1162 BGP_STR
1163 "Configure Route-Reflector Cluster-id\n"
1164 "Route-Reflector Cluster-id in IP address format\n"
1165 "Route-Reflector Cluster-id as 32 bit quantity\n")
1166 {
1167 VTY_DECLVAR_CONTEXT(bgp, bgp);
1168 int idx_ipv4 = 2;
1169 int ret;
1170 struct in_addr cluster;
1171
1172 ret = inet_aton(argv[idx_ipv4]->arg, &cluster);
1173 if (!ret) {
1174 vty_out(vty, "%% Malformed bgp cluster identifier\n");
1175 return CMD_WARNING_CONFIG_FAILED;
1176 }
1177
1178 bgp_cluster_id_set(bgp, &cluster);
1179 bgp_clear_star_soft_out(vty, bgp->name);
1180
1181 return CMD_SUCCESS;
1182 }
1183
1184 DEFUN (no_bgp_cluster_id,
1185 no_bgp_cluster_id_cmd,
1186 "no bgp cluster-id [<A.B.C.D|(1-4294967295)>]",
1187 NO_STR
1188 BGP_STR
1189 "Configure Route-Reflector Cluster-id\n"
1190 "Route-Reflector Cluster-id in IP address format\n"
1191 "Route-Reflector Cluster-id as 32 bit quantity\n")
1192 {
1193 VTY_DECLVAR_CONTEXT(bgp, bgp);
1194 bgp_cluster_id_unset(bgp);
1195 bgp_clear_star_soft_out(vty, bgp->name);
1196
1197 return CMD_SUCCESS;
1198 }
1199
1200 DEFUN (bgp_confederation_identifier,
1201 bgp_confederation_identifier_cmd,
1202 "bgp confederation identifier (1-4294967295)",
1203 "BGP specific commands\n"
1204 "AS confederation parameters\n"
1205 "AS number\n"
1206 "Set routing domain confederation AS\n")
1207 {
1208 VTY_DECLVAR_CONTEXT(bgp, bgp);
1209 int idx_number = 3;
1210 as_t as;
1211
1212 as = strtoul(argv[idx_number]->arg, NULL, 10);
1213
1214 bgp_confederation_id_set(bgp, as);
1215
1216 return CMD_SUCCESS;
1217 }
1218
1219 DEFUN (no_bgp_confederation_identifier,
1220 no_bgp_confederation_identifier_cmd,
1221 "no bgp confederation identifier [(1-4294967295)]",
1222 NO_STR
1223 "BGP specific commands\n"
1224 "AS confederation parameters\n"
1225 "AS number\n"
1226 "Set routing domain confederation AS\n")
1227 {
1228 VTY_DECLVAR_CONTEXT(bgp, bgp);
1229 bgp_confederation_id_unset(bgp);
1230
1231 return CMD_SUCCESS;
1232 }
1233
1234 DEFUN (bgp_confederation_peers,
1235 bgp_confederation_peers_cmd,
1236 "bgp confederation peers (1-4294967295)...",
1237 "BGP specific commands\n"
1238 "AS confederation parameters\n"
1239 "Peer ASs in BGP confederation\n"
1240 AS_STR)
1241 {
1242 VTY_DECLVAR_CONTEXT(bgp, bgp);
1243 int idx_asn = 3;
1244 as_t as;
1245 int i;
1246
1247 for (i = idx_asn; i < argc; i++) {
1248 as = strtoul(argv[i]->arg, NULL, 10);
1249
1250 if (bgp->as == as) {
1251 vty_out(vty,
1252 "%% Local member-AS not allowed in confed peer list\n");
1253 continue;
1254 }
1255
1256 bgp_confederation_peers_add(bgp, as);
1257 }
1258 return CMD_SUCCESS;
1259 }
1260
1261 DEFUN (no_bgp_confederation_peers,
1262 no_bgp_confederation_peers_cmd,
1263 "no bgp confederation peers (1-4294967295)...",
1264 NO_STR
1265 "BGP specific commands\n"
1266 "AS confederation parameters\n"
1267 "Peer ASs in BGP confederation\n"
1268 AS_STR)
1269 {
1270 VTY_DECLVAR_CONTEXT(bgp, bgp);
1271 int idx_asn = 4;
1272 as_t as;
1273 int i;
1274
1275 for (i = idx_asn; i < argc; i++) {
1276 as = strtoul(argv[i]->arg, NULL, 10);
1277
1278 bgp_confederation_peers_remove(bgp, as);
1279 }
1280 return CMD_SUCCESS;
1281 }
1282
1283 /**
1284 * Central routine for maximum-paths configuration.
1285 * @peer_type: BGP_PEER_EBGP or BGP_PEER_IBGP
1286 * @set: 1 for setting values, 0 for removing the max-paths config.
1287 */
1288 static int bgp_maxpaths_config_vty(struct vty *vty, int peer_type,
1289 const char *mpaths, uint16_t options,
1290 int set)
1291 {
1292 VTY_DECLVAR_CONTEXT(bgp, bgp);
1293 uint16_t maxpaths = 0;
1294 int ret;
1295 afi_t afi;
1296 safi_t safi;
1297
1298 afi = bgp_node_afi(vty);
1299 safi = bgp_node_safi(vty);
1300
1301 if (set) {
1302 maxpaths = strtol(mpaths, NULL, 10);
1303 if (maxpaths > multipath_num) {
1304 vty_out(vty,
1305 "%% Maxpaths Specified: %d is > than multipath num specified on bgp command line %d",
1306 maxpaths, multipath_num);
1307 return CMD_WARNING_CONFIG_FAILED;
1308 }
1309 ret = bgp_maximum_paths_set(bgp, afi, safi, peer_type, maxpaths,
1310 options);
1311 } else
1312 ret = bgp_maximum_paths_unset(bgp, afi, safi, peer_type);
1313
1314 if (ret < 0) {
1315 vty_out(vty,
1316 "%% Failed to %sset maximum-paths %s %u for afi %u, safi %u\n",
1317 (set == 1) ? "" : "un",
1318 (peer_type == BGP_PEER_EBGP) ? "ebgp" : "ibgp",
1319 maxpaths, afi, safi);
1320 return CMD_WARNING_CONFIG_FAILED;
1321 }
1322
1323 bgp_recalculate_all_bestpaths(bgp);
1324
1325 return CMD_SUCCESS;
1326 }
1327
1328 DEFUN (bgp_maxmed_admin,
1329 bgp_maxmed_admin_cmd,
1330 "bgp max-med administrative ",
1331 BGP_STR
1332 "Advertise routes with max-med\n"
1333 "Administratively applied, for an indefinite period\n")
1334 {
1335 VTY_DECLVAR_CONTEXT(bgp, bgp);
1336
1337 bgp->v_maxmed_admin = 1;
1338 bgp->maxmed_admin_value = BGP_MAXMED_VALUE_DEFAULT;
1339
1340 bgp_maxmed_update(bgp);
1341
1342 return CMD_SUCCESS;
1343 }
1344
1345 DEFUN (bgp_maxmed_admin_medv,
1346 bgp_maxmed_admin_medv_cmd,
1347 "bgp max-med administrative (0-4294967295)",
1348 BGP_STR
1349 "Advertise routes with max-med\n"
1350 "Administratively applied, for an indefinite period\n"
1351 "Max MED value to be used\n")
1352 {
1353 VTY_DECLVAR_CONTEXT(bgp, bgp);
1354 int idx_number = 3;
1355
1356 bgp->v_maxmed_admin = 1;
1357 bgp->maxmed_admin_value = strtoul(argv[idx_number]->arg, NULL, 10);
1358
1359 bgp_maxmed_update(bgp);
1360
1361 return CMD_SUCCESS;
1362 }
1363
1364 DEFUN (no_bgp_maxmed_admin,
1365 no_bgp_maxmed_admin_cmd,
1366 "no bgp max-med administrative [(0-4294967295)]",
1367 NO_STR
1368 BGP_STR
1369 "Advertise routes with max-med\n"
1370 "Administratively applied, for an indefinite period\n"
1371 "Max MED value to be used\n")
1372 {
1373 VTY_DECLVAR_CONTEXT(bgp, bgp);
1374 bgp->v_maxmed_admin = BGP_MAXMED_ADMIN_UNCONFIGURED;
1375 bgp->maxmed_admin_value = BGP_MAXMED_VALUE_DEFAULT;
1376 bgp_maxmed_update(bgp);
1377
1378 return CMD_SUCCESS;
1379 }
1380
1381 DEFUN (bgp_maxmed_onstartup,
1382 bgp_maxmed_onstartup_cmd,
1383 "bgp max-med on-startup (5-86400) [(0-4294967295)]",
1384 BGP_STR
1385 "Advertise routes with max-med\n"
1386 "Effective on a startup\n"
1387 "Time (seconds) period for max-med\n"
1388 "Max MED value to be used\n")
1389 {
1390 VTY_DECLVAR_CONTEXT(bgp, bgp);
1391 int idx = 0;
1392
1393 argv_find(argv, argc, "(5-86400)", &idx);
1394 bgp->v_maxmed_onstartup = strtoul(argv[idx]->arg, NULL, 10);
1395 if (argv_find(argv, argc, "(0-4294967295)", &idx))
1396 bgp->maxmed_onstartup_value = strtoul(argv[idx]->arg, NULL, 10);
1397 else
1398 bgp->maxmed_onstartup_value = BGP_MAXMED_VALUE_DEFAULT;
1399
1400 bgp_maxmed_update(bgp);
1401
1402 return CMD_SUCCESS;
1403 }
1404
1405 DEFUN (no_bgp_maxmed_onstartup,
1406 no_bgp_maxmed_onstartup_cmd,
1407 "no bgp max-med on-startup [(5-86400) [(0-4294967295)]]",
1408 NO_STR
1409 BGP_STR
1410 "Advertise routes with max-med\n"
1411 "Effective on a startup\n"
1412 "Time (seconds) period for max-med\n"
1413 "Max MED value to be used\n")
1414 {
1415 VTY_DECLVAR_CONTEXT(bgp, bgp);
1416
1417 /* Cancel max-med onstartup if its on */
1418 if (bgp->t_maxmed_onstartup) {
1419 THREAD_TIMER_OFF(bgp->t_maxmed_onstartup);
1420 bgp->maxmed_onstartup_over = 1;
1421 }
1422
1423 bgp->v_maxmed_onstartup = BGP_MAXMED_ONSTARTUP_UNCONFIGURED;
1424 bgp->maxmed_onstartup_value = BGP_MAXMED_VALUE_DEFAULT;
1425
1426 bgp_maxmed_update(bgp);
1427
1428 return CMD_SUCCESS;
1429 }
1430
1431 static int bgp_update_delay_config_vty(struct vty *vty, const char *delay,
1432 const char *wait)
1433 {
1434 VTY_DECLVAR_CONTEXT(bgp, bgp);
1435 uint16_t update_delay;
1436 uint16_t establish_wait;
1437
1438 update_delay = strtoul(delay, NULL, 10);
1439
1440 if (!wait) /* update-delay <delay> */
1441 {
1442 bgp->v_update_delay = update_delay;
1443 bgp->v_establish_wait = bgp->v_update_delay;
1444 return CMD_SUCCESS;
1445 }
1446
1447 /* update-delay <delay> <establish-wait> */
1448 establish_wait = atoi(wait);
1449 if (update_delay < establish_wait) {
1450 vty_out(vty,
1451 "%%Failed: update-delay less than the establish-wait!\n");
1452 return CMD_WARNING_CONFIG_FAILED;
1453 }
1454
1455 bgp->v_update_delay = update_delay;
1456 bgp->v_establish_wait = establish_wait;
1457
1458 return CMD_SUCCESS;
1459 }
1460
1461 static int bgp_update_delay_deconfig_vty(struct vty *vty)
1462 {
1463 VTY_DECLVAR_CONTEXT(bgp, bgp);
1464
1465 bgp->v_update_delay = BGP_UPDATE_DELAY_DEF;
1466 bgp->v_establish_wait = bgp->v_update_delay;
1467
1468 return CMD_SUCCESS;
1469 }
1470
1471 void bgp_config_write_update_delay(struct vty *vty, struct bgp *bgp)
1472 {
1473 if (bgp->v_update_delay != BGP_UPDATE_DELAY_DEF) {
1474 vty_out(vty, " update-delay %d", bgp->v_update_delay);
1475 if (bgp->v_update_delay != bgp->v_establish_wait)
1476 vty_out(vty, " %d", bgp->v_establish_wait);
1477 vty_out(vty, "\n");
1478 }
1479 }
1480
1481
1482 /* Update-delay configuration */
1483 DEFUN (bgp_update_delay,
1484 bgp_update_delay_cmd,
1485 "update-delay (0-3600)",
1486 "Force initial delay for best-path and updates\n"
1487 "Seconds\n")
1488 {
1489 int idx_number = 1;
1490 return bgp_update_delay_config_vty(vty, argv[idx_number]->arg, NULL);
1491 }
1492
1493 DEFUN (bgp_update_delay_establish_wait,
1494 bgp_update_delay_establish_wait_cmd,
1495 "update-delay (0-3600) (1-3600)",
1496 "Force initial delay for best-path and updates\n"
1497 "Seconds\n"
1498 "Seconds\n")
1499 {
1500 int idx_number = 1;
1501 int idx_number_2 = 2;
1502 return bgp_update_delay_config_vty(vty, argv[idx_number]->arg,
1503 argv[idx_number_2]->arg);
1504 }
1505
1506 /* Update-delay deconfiguration */
1507 DEFUN (no_bgp_update_delay,
1508 no_bgp_update_delay_cmd,
1509 "no update-delay [(0-3600) [(1-3600)]]",
1510 NO_STR
1511 "Force initial delay for best-path and updates\n"
1512 "Seconds\n"
1513 "Seconds\n")
1514 {
1515 return bgp_update_delay_deconfig_vty(vty);
1516 }
1517
1518
1519 static int bgp_wpkt_quanta_config_vty(struct vty *vty, const char *num,
1520 char set)
1521 {
1522 VTY_DECLVAR_CONTEXT(bgp, bgp);
1523
1524 if (set) {
1525 uint32_t quanta = strtoul(num, NULL, 10);
1526 atomic_store_explicit(&bgp->wpkt_quanta, quanta,
1527 memory_order_relaxed);
1528 } else {
1529 atomic_store_explicit(&bgp->wpkt_quanta, BGP_WRITE_PACKET_MAX,
1530 memory_order_relaxed);
1531 }
1532
1533 return CMD_SUCCESS;
1534 }
1535
1536 static int bgp_rpkt_quanta_config_vty(struct vty *vty, const char *num,
1537 char set)
1538 {
1539 VTY_DECLVAR_CONTEXT(bgp, bgp);
1540
1541 if (set) {
1542 uint32_t quanta = strtoul(num, NULL, 10);
1543 atomic_store_explicit(&bgp->rpkt_quanta, quanta,
1544 memory_order_relaxed);
1545 } else {
1546 atomic_store_explicit(&bgp->rpkt_quanta, BGP_READ_PACKET_MAX,
1547 memory_order_relaxed);
1548 }
1549
1550 return CMD_SUCCESS;
1551 }
1552
1553 void bgp_config_write_wpkt_quanta(struct vty *vty, struct bgp *bgp)
1554 {
1555 uint32_t quanta =
1556 atomic_load_explicit(&bgp->wpkt_quanta, memory_order_relaxed);
1557 if (quanta != BGP_WRITE_PACKET_MAX)
1558 vty_out(vty, " write-quanta %d\n", quanta);
1559 }
1560
1561 void bgp_config_write_rpkt_quanta(struct vty *vty, struct bgp *bgp)
1562 {
1563 uint32_t quanta =
1564 atomic_load_explicit(&bgp->rpkt_quanta, memory_order_relaxed);
1565 if (quanta != BGP_READ_PACKET_MAX)
1566 vty_out(vty, " read-quanta %d\n", quanta);
1567 }
1568
1569 /* Packet quanta configuration */
1570 DEFUN (bgp_wpkt_quanta,
1571 bgp_wpkt_quanta_cmd,
1572 "write-quanta (1-10)",
1573 "How many packets to write to peer socket per run\n"
1574 "Number of packets\n")
1575 {
1576 int idx_number = 1;
1577 return bgp_wpkt_quanta_config_vty(vty, argv[idx_number]->arg, 1);
1578 }
1579
1580 DEFUN (no_bgp_wpkt_quanta,
1581 no_bgp_wpkt_quanta_cmd,
1582 "no write-quanta (1-10)",
1583 NO_STR
1584 "How many packets to write to peer socket per I/O cycle\n"
1585 "Number of packets\n")
1586 {
1587 int idx_number = 2;
1588 return bgp_wpkt_quanta_config_vty(vty, argv[idx_number]->arg, 0);
1589 }
1590
1591 DEFUN (bgp_rpkt_quanta,
1592 bgp_rpkt_quanta_cmd,
1593 "read-quanta (1-10)",
1594 "How many packets to read from peer socket per I/O cycle\n"
1595 "Number of packets\n")
1596 {
1597 int idx_number = 1;
1598 return bgp_rpkt_quanta_config_vty(vty, argv[idx_number]->arg, 1);
1599 }
1600
1601 DEFUN (no_bgp_rpkt_quanta,
1602 no_bgp_rpkt_quanta_cmd,
1603 "no read-quanta (1-10)",
1604 NO_STR
1605 "How many packets to read from peer socket per I/O cycle\n"
1606 "Number of packets\n")
1607 {
1608 int idx_number = 2;
1609 return bgp_rpkt_quanta_config_vty(vty, argv[idx_number]->arg, 0);
1610 }
1611
1612 void bgp_config_write_coalesce_time(struct vty *vty, struct bgp *bgp)
1613 {
1614 if (!bgp->heuristic_coalesce)
1615 vty_out(vty, " coalesce-time %u\n", bgp->coalesce_time);
1616 }
1617
1618
1619 DEFUN (bgp_coalesce_time,
1620 bgp_coalesce_time_cmd,
1621 "coalesce-time (0-4294967295)",
1622 "Subgroup coalesce timer\n"
1623 "Subgroup coalesce timer value (in ms)\n")
1624 {
1625 VTY_DECLVAR_CONTEXT(bgp, bgp);
1626
1627 int idx = 0;
1628 argv_find(argv, argc, "(0-4294967295)", &idx);
1629 bgp->heuristic_coalesce = false;
1630 bgp->coalesce_time = strtoul(argv[idx]->arg, NULL, 10);
1631 return CMD_SUCCESS;
1632 }
1633
1634 DEFUN (no_bgp_coalesce_time,
1635 no_bgp_coalesce_time_cmd,
1636 "no coalesce-time (0-4294967295)",
1637 NO_STR
1638 "Subgroup coalesce timer\n"
1639 "Subgroup coalesce timer value (in ms)\n")
1640 {
1641 VTY_DECLVAR_CONTEXT(bgp, bgp);
1642
1643 bgp->heuristic_coalesce = true;
1644 bgp->coalesce_time = BGP_DEFAULT_SUBGROUP_COALESCE_TIME;
1645 return CMD_SUCCESS;
1646 }
1647
1648 /* Maximum-paths configuration */
1649 DEFUN (bgp_maxpaths,
1650 bgp_maxpaths_cmd,
1651 "maximum-paths " CMD_RANGE_STR(1, MULTIPATH_NUM),
1652 "Forward packets over multiple paths\n"
1653 "Number of paths\n")
1654 {
1655 int idx_number = 1;
1656 return bgp_maxpaths_config_vty(vty, BGP_PEER_EBGP,
1657 argv[idx_number]->arg, 0, 1);
1658 }
1659
1660 ALIAS_HIDDEN(bgp_maxpaths, bgp_maxpaths_hidden_cmd,
1661 "maximum-paths " CMD_RANGE_STR(1, MULTIPATH_NUM),
1662 "Forward packets over multiple paths\n"
1663 "Number of paths\n")
1664
1665 DEFUN (bgp_maxpaths_ibgp,
1666 bgp_maxpaths_ibgp_cmd,
1667 "maximum-paths ibgp " CMD_RANGE_STR(1, MULTIPATH_NUM),
1668 "Forward packets over multiple paths\n"
1669 "iBGP-multipath\n"
1670 "Number of paths\n")
1671 {
1672 int idx_number = 2;
1673 return bgp_maxpaths_config_vty(vty, BGP_PEER_IBGP,
1674 argv[idx_number]->arg, 0, 1);
1675 }
1676
1677 ALIAS_HIDDEN(bgp_maxpaths_ibgp, bgp_maxpaths_ibgp_hidden_cmd,
1678 "maximum-paths ibgp " CMD_RANGE_STR(1, MULTIPATH_NUM),
1679 "Forward packets over multiple paths\n"
1680 "iBGP-multipath\n"
1681 "Number of paths\n")
1682
1683 DEFUN (bgp_maxpaths_ibgp_cluster,
1684 bgp_maxpaths_ibgp_cluster_cmd,
1685 "maximum-paths ibgp " CMD_RANGE_STR(1, MULTIPATH_NUM) " equal-cluster-length",
1686 "Forward packets over multiple paths\n"
1687 "iBGP-multipath\n"
1688 "Number of paths\n"
1689 "Match the cluster length\n")
1690 {
1691 int idx_number = 2;
1692 return bgp_maxpaths_config_vty(
1693 vty, BGP_PEER_IBGP, argv[idx_number]->arg,
1694 BGP_FLAG_IBGP_MULTIPATH_SAME_CLUSTERLEN, 1);
1695 }
1696
1697 ALIAS_HIDDEN(bgp_maxpaths_ibgp_cluster, bgp_maxpaths_ibgp_cluster_hidden_cmd,
1698 "maximum-paths ibgp " CMD_RANGE_STR(
1699 1, MULTIPATH_NUM) " equal-cluster-length",
1700 "Forward packets over multiple paths\n"
1701 "iBGP-multipath\n"
1702 "Number of paths\n"
1703 "Match the cluster length\n")
1704
1705 DEFUN (no_bgp_maxpaths,
1706 no_bgp_maxpaths_cmd,
1707 "no maximum-paths [" CMD_RANGE_STR(1, MULTIPATH_NUM) "]",
1708 NO_STR
1709 "Forward packets over multiple paths\n"
1710 "Number of paths\n")
1711 {
1712 return bgp_maxpaths_config_vty(vty, BGP_PEER_EBGP, NULL, 0, 0);
1713 }
1714
1715 ALIAS_HIDDEN(no_bgp_maxpaths, no_bgp_maxpaths_hidden_cmd,
1716 "no maximum-paths [" CMD_RANGE_STR(1, MULTIPATH_NUM) "]", NO_STR
1717 "Forward packets over multiple paths\n"
1718 "Number of paths\n")
1719
1720 DEFUN (no_bgp_maxpaths_ibgp,
1721 no_bgp_maxpaths_ibgp_cmd,
1722 "no maximum-paths ibgp [" CMD_RANGE_STR(1, MULTIPATH_NUM) " [equal-cluster-length]]",
1723 NO_STR
1724 "Forward packets over multiple paths\n"
1725 "iBGP-multipath\n"
1726 "Number of paths\n"
1727 "Match the cluster length\n")
1728 {
1729 return bgp_maxpaths_config_vty(vty, BGP_PEER_IBGP, NULL, 0, 0);
1730 }
1731
1732 ALIAS_HIDDEN(no_bgp_maxpaths_ibgp, no_bgp_maxpaths_ibgp_hidden_cmd,
1733 "no maximum-paths ibgp [" CMD_RANGE_STR(
1734 1, MULTIPATH_NUM) " [equal-cluster-length]]",
1735 NO_STR
1736 "Forward packets over multiple paths\n"
1737 "iBGP-multipath\n"
1738 "Number of paths\n"
1739 "Match the cluster length\n")
1740
1741 void bgp_config_write_maxpaths(struct vty *vty, struct bgp *bgp, afi_t afi,
1742 safi_t safi)
1743 {
1744 if (bgp->maxpaths[afi][safi].maxpaths_ebgp != MULTIPATH_NUM) {
1745 vty_out(vty, " maximum-paths %d\n",
1746 bgp->maxpaths[afi][safi].maxpaths_ebgp);
1747 }
1748
1749 if (bgp->maxpaths[afi][safi].maxpaths_ibgp != MULTIPATH_NUM) {
1750 vty_out(vty, " maximum-paths ibgp %d",
1751 bgp->maxpaths[afi][safi].maxpaths_ibgp);
1752 if (CHECK_FLAG(bgp->maxpaths[afi][safi].ibgp_flags,
1753 BGP_FLAG_IBGP_MULTIPATH_SAME_CLUSTERLEN))
1754 vty_out(vty, " equal-cluster-length");
1755 vty_out(vty, "\n");
1756 }
1757 }
1758
1759 /* BGP timers. */
1760
1761 DEFUN (bgp_timers,
1762 bgp_timers_cmd,
1763 "timers bgp (0-65535) (0-65535)",
1764 "Adjust routing timers\n"
1765 "BGP timers\n"
1766 "Keepalive interval\n"
1767 "Holdtime\n")
1768 {
1769 VTY_DECLVAR_CONTEXT(bgp, bgp);
1770 int idx_number = 2;
1771 int idx_number_2 = 3;
1772 unsigned long keepalive = 0;
1773 unsigned long holdtime = 0;
1774
1775 keepalive = strtoul(argv[idx_number]->arg, NULL, 10);
1776 holdtime = strtoul(argv[idx_number_2]->arg, NULL, 10);
1777
1778 /* Holdtime value check. */
1779 if (holdtime < 3 && holdtime != 0) {
1780 vty_out(vty,
1781 "%% hold time value must be either 0 or greater than 3\n");
1782 return CMD_WARNING_CONFIG_FAILED;
1783 }
1784
1785 bgp_timers_set(bgp, keepalive, holdtime);
1786
1787 return CMD_SUCCESS;
1788 }
1789
1790 DEFUN (no_bgp_timers,
1791 no_bgp_timers_cmd,
1792 "no timers bgp [(0-65535) (0-65535)]",
1793 NO_STR
1794 "Adjust routing timers\n"
1795 "BGP timers\n"
1796 "Keepalive interval\n"
1797 "Holdtime\n")
1798 {
1799 VTY_DECLVAR_CONTEXT(bgp, bgp);
1800 bgp_timers_unset(bgp);
1801
1802 return CMD_SUCCESS;
1803 }
1804
1805
1806 DEFUN (bgp_client_to_client_reflection,
1807 bgp_client_to_client_reflection_cmd,
1808 "bgp client-to-client reflection",
1809 "BGP specific commands\n"
1810 "Configure client to client route reflection\n"
1811 "reflection of routes allowed\n")
1812 {
1813 VTY_DECLVAR_CONTEXT(bgp, bgp);
1814 bgp_flag_unset(bgp, BGP_FLAG_NO_CLIENT_TO_CLIENT);
1815 bgp_clear_star_soft_out(vty, bgp->name);
1816
1817 return CMD_SUCCESS;
1818 }
1819
1820 DEFUN (no_bgp_client_to_client_reflection,
1821 no_bgp_client_to_client_reflection_cmd,
1822 "no bgp client-to-client reflection",
1823 NO_STR
1824 "BGP specific commands\n"
1825 "Configure client to client route reflection\n"
1826 "reflection of routes allowed\n")
1827 {
1828 VTY_DECLVAR_CONTEXT(bgp, bgp);
1829 bgp_flag_set(bgp, BGP_FLAG_NO_CLIENT_TO_CLIENT);
1830 bgp_clear_star_soft_out(vty, bgp->name);
1831
1832 return CMD_SUCCESS;
1833 }
1834
1835 /* "bgp always-compare-med" configuration. */
1836 DEFUN (bgp_always_compare_med,
1837 bgp_always_compare_med_cmd,
1838 "bgp always-compare-med",
1839 "BGP specific commands\n"
1840 "Allow comparing MED from different neighbors\n")
1841 {
1842 VTY_DECLVAR_CONTEXT(bgp, bgp);
1843 bgp_flag_set(bgp, BGP_FLAG_ALWAYS_COMPARE_MED);
1844 bgp_recalculate_all_bestpaths(bgp);
1845
1846 return CMD_SUCCESS;
1847 }
1848
1849 DEFUN (no_bgp_always_compare_med,
1850 no_bgp_always_compare_med_cmd,
1851 "no bgp always-compare-med",
1852 NO_STR
1853 "BGP specific commands\n"
1854 "Allow comparing MED from different neighbors\n")
1855 {
1856 VTY_DECLVAR_CONTEXT(bgp, bgp);
1857 bgp_flag_unset(bgp, BGP_FLAG_ALWAYS_COMPARE_MED);
1858 bgp_recalculate_all_bestpaths(bgp);
1859
1860 return CMD_SUCCESS;
1861 }
1862
1863
1864 DEFUN(bgp_ebgp_requires_policy, bgp_ebgp_requires_policy_cmd,
1865 "bgp ebgp-requires-policy",
1866 "BGP specific commands\n"
1867 "Require in and out policy for eBGP peers (RFC8212)\n")
1868 {
1869 VTY_DECLVAR_CONTEXT(bgp, bgp);
1870 bgp->ebgp_requires_policy = DEFAULT_EBGP_POLICY_ENABLED;
1871 return CMD_SUCCESS;
1872 }
1873
1874 DEFUN(no_bgp_ebgp_requires_policy, no_bgp_ebgp_requires_policy_cmd,
1875 "no bgp ebgp-requires-policy",
1876 NO_STR
1877 "BGP specific commands\n"
1878 "Require in and out policy for eBGP peers (RFC8212)\n")
1879 {
1880 VTY_DECLVAR_CONTEXT(bgp, bgp);
1881 bgp->ebgp_requires_policy = DEFAULT_EBGP_POLICY_DISABLED;
1882 return CMD_SUCCESS;
1883 }
1884
1885
1886 /* "bgp deterministic-med" configuration. */
1887 DEFUN (bgp_deterministic_med,
1888 bgp_deterministic_med_cmd,
1889 "bgp deterministic-med",
1890 "BGP specific commands\n"
1891 "Pick the best-MED path among paths advertised from the neighboring AS\n")
1892 {
1893 VTY_DECLVAR_CONTEXT(bgp, bgp);
1894
1895 if (!bgp_flag_check(bgp, BGP_FLAG_DETERMINISTIC_MED)) {
1896 bgp_flag_set(bgp, BGP_FLAG_DETERMINISTIC_MED);
1897 bgp_recalculate_all_bestpaths(bgp);
1898 }
1899
1900 return CMD_SUCCESS;
1901 }
1902
1903 DEFUN (no_bgp_deterministic_med,
1904 no_bgp_deterministic_med_cmd,
1905 "no bgp deterministic-med",
1906 NO_STR
1907 "BGP specific commands\n"
1908 "Pick the best-MED path among paths advertised from the neighboring AS\n")
1909 {
1910 VTY_DECLVAR_CONTEXT(bgp, bgp);
1911 int bestpath_per_as_used;
1912 afi_t afi;
1913 safi_t safi;
1914 struct peer *peer;
1915 struct listnode *node, *nnode;
1916
1917 if (bgp_flag_check(bgp, BGP_FLAG_DETERMINISTIC_MED)) {
1918 bestpath_per_as_used = 0;
1919
1920 for (ALL_LIST_ELEMENTS(bgp->peer, node, nnode, peer)) {
1921 FOREACH_AFI_SAFI (afi, safi)
1922 if (bgp_addpath_dmed_required(
1923 peer->addpath_type[afi][safi])) {
1924 bestpath_per_as_used = 1;
1925 break;
1926 }
1927
1928 if (bestpath_per_as_used)
1929 break;
1930 }
1931
1932 if (bestpath_per_as_used) {
1933 vty_out(vty,
1934 "bgp deterministic-med cannot be disabled while addpath-tx-bestpath-per-AS is in use\n");
1935 return CMD_WARNING_CONFIG_FAILED;
1936 } else {
1937 bgp_flag_unset(bgp, BGP_FLAG_DETERMINISTIC_MED);
1938 bgp_recalculate_all_bestpaths(bgp);
1939 }
1940 }
1941
1942 return CMD_SUCCESS;
1943 }
1944
1945 /* "bgp graceful-restart" configuration. */
1946 DEFUN (bgp_graceful_restart,
1947 bgp_graceful_restart_cmd,
1948 "bgp graceful-restart",
1949 "BGP specific commands\n"
1950 "Graceful restart capability parameters\n")
1951 {
1952 VTY_DECLVAR_CONTEXT(bgp, bgp);
1953 bgp_flag_set(bgp, BGP_FLAG_GRACEFUL_RESTART);
1954 return CMD_SUCCESS;
1955 }
1956
1957 DEFUN (no_bgp_graceful_restart,
1958 no_bgp_graceful_restart_cmd,
1959 "no bgp graceful-restart",
1960 NO_STR
1961 "BGP specific commands\n"
1962 "Graceful restart capability parameters\n")
1963 {
1964 VTY_DECLVAR_CONTEXT(bgp, bgp);
1965 bgp_flag_unset(bgp, BGP_FLAG_GRACEFUL_RESTART);
1966 return CMD_SUCCESS;
1967 }
1968
1969 DEFUN (bgp_graceful_restart_stalepath_time,
1970 bgp_graceful_restart_stalepath_time_cmd,
1971 "bgp graceful-restart stalepath-time (1-4095)",
1972 "BGP specific commands\n"
1973 "Graceful restart capability parameters\n"
1974 "Set the max time to hold onto restarting peer's stale paths\n"
1975 "Delay value (seconds)\n")
1976 {
1977 VTY_DECLVAR_CONTEXT(bgp, bgp);
1978 int idx_number = 3;
1979 uint32_t stalepath;
1980
1981 stalepath = strtoul(argv[idx_number]->arg, NULL, 10);
1982 bgp->stalepath_time = stalepath;
1983 return CMD_SUCCESS;
1984 }
1985
1986 DEFUN (bgp_graceful_restart_restart_time,
1987 bgp_graceful_restart_restart_time_cmd,
1988 "bgp graceful-restart restart-time (1-4095)",
1989 "BGP specific commands\n"
1990 "Graceful restart capability parameters\n"
1991 "Set the time to wait to delete stale routes before a BGP open message is received\n"
1992 "Delay value (seconds)\n")
1993 {
1994 VTY_DECLVAR_CONTEXT(bgp, bgp);
1995 int idx_number = 3;
1996 uint32_t restart;
1997
1998 restart = strtoul(argv[idx_number]->arg, NULL, 10);
1999 bgp->restart_time = restart;
2000 return CMD_SUCCESS;
2001 }
2002
2003 DEFUN (no_bgp_graceful_restart_stalepath_time,
2004 no_bgp_graceful_restart_stalepath_time_cmd,
2005 "no bgp graceful-restart stalepath-time [(1-4095)]",
2006 NO_STR
2007 "BGP specific commands\n"
2008 "Graceful restart capability parameters\n"
2009 "Set the max time to hold onto restarting peer's stale paths\n"
2010 "Delay value (seconds)\n")
2011 {
2012 VTY_DECLVAR_CONTEXT(bgp, bgp);
2013
2014 bgp->stalepath_time = BGP_DEFAULT_STALEPATH_TIME;
2015 return CMD_SUCCESS;
2016 }
2017
2018 DEFUN (no_bgp_graceful_restart_restart_time,
2019 no_bgp_graceful_restart_restart_time_cmd,
2020 "no bgp graceful-restart restart-time [(1-4095)]",
2021 NO_STR
2022 "BGP specific commands\n"
2023 "Graceful restart capability parameters\n"
2024 "Set the time to wait to delete stale routes before a BGP open message is received\n"
2025 "Delay value (seconds)\n")
2026 {
2027 VTY_DECLVAR_CONTEXT(bgp, bgp);
2028
2029 bgp->restart_time = BGP_DEFAULT_RESTART_TIME;
2030 return CMD_SUCCESS;
2031 }
2032
2033 DEFUN (bgp_graceful_restart_preserve_fw,
2034 bgp_graceful_restart_preserve_fw_cmd,
2035 "bgp graceful-restart preserve-fw-state",
2036 "BGP specific commands\n"
2037 "Graceful restart capability parameters\n"
2038 "Sets F-bit indication that fib is preserved while doing Graceful Restart\n")
2039 {
2040 VTY_DECLVAR_CONTEXT(bgp, bgp);
2041 bgp_flag_set(bgp, BGP_FLAG_GR_PRESERVE_FWD);
2042 return CMD_SUCCESS;
2043 }
2044
2045 DEFUN (no_bgp_graceful_restart_preserve_fw,
2046 no_bgp_graceful_restart_preserve_fw_cmd,
2047 "no bgp graceful-restart preserve-fw-state",
2048 NO_STR
2049 "BGP specific commands\n"
2050 "Graceful restart capability parameters\n"
2051 "Unsets F-bit indication that fib is preserved while doing Graceful Restart\n")
2052 {
2053 VTY_DECLVAR_CONTEXT(bgp, bgp);
2054 bgp_flag_unset(bgp, BGP_FLAG_GR_PRESERVE_FWD);
2055 return CMD_SUCCESS;
2056 }
2057
2058 static void bgp_redistribute_redo(struct bgp *bgp)
2059 {
2060 afi_t afi;
2061 int i;
2062 struct list *red_list;
2063 struct listnode *node;
2064 struct bgp_redist *red;
2065
2066 for (afi = AFI_IP; afi < AFI_MAX; afi++) {
2067 for (i = 0; i < ZEBRA_ROUTE_MAX; i++) {
2068
2069 red_list = bgp->redist[afi][i];
2070 if (!red_list)
2071 continue;
2072
2073 for (ALL_LIST_ELEMENTS_RO(red_list, node, red)) {
2074 bgp_redistribute_resend(bgp, afi, i,
2075 red->instance);
2076 }
2077 }
2078 }
2079 }
2080
2081 /* "bgp graceful-shutdown" configuration */
2082 DEFUN (bgp_graceful_shutdown,
2083 bgp_graceful_shutdown_cmd,
2084 "bgp graceful-shutdown",
2085 BGP_STR
2086 "Graceful shutdown parameters\n")
2087 {
2088 VTY_DECLVAR_CONTEXT(bgp, bgp);
2089
2090 if (!bgp_flag_check(bgp, BGP_FLAG_GRACEFUL_SHUTDOWN)) {
2091 bgp_flag_set(bgp, BGP_FLAG_GRACEFUL_SHUTDOWN);
2092 bgp_static_redo_import_check(bgp);
2093 bgp_redistribute_redo(bgp);
2094 bgp_clear_star_soft_out(vty, bgp->name);
2095 bgp_clear_star_soft_in(vty, bgp->name);
2096 }
2097
2098 return CMD_SUCCESS;
2099 }
2100
2101 DEFUN (no_bgp_graceful_shutdown,
2102 no_bgp_graceful_shutdown_cmd,
2103 "no bgp graceful-shutdown",
2104 NO_STR
2105 BGP_STR
2106 "Graceful shutdown parameters\n")
2107 {
2108 VTY_DECLVAR_CONTEXT(bgp, bgp);
2109
2110 if (bgp_flag_check(bgp, BGP_FLAG_GRACEFUL_SHUTDOWN)) {
2111 bgp_flag_unset(bgp, BGP_FLAG_GRACEFUL_SHUTDOWN);
2112 bgp_static_redo_import_check(bgp);
2113 bgp_redistribute_redo(bgp);
2114 bgp_clear_star_soft_out(vty, bgp->name);
2115 bgp_clear_star_soft_in(vty, bgp->name);
2116 }
2117
2118 return CMD_SUCCESS;
2119 }
2120
2121 /* "bgp fast-external-failover" configuration. */
2122 DEFUN (bgp_fast_external_failover,
2123 bgp_fast_external_failover_cmd,
2124 "bgp fast-external-failover",
2125 BGP_STR
2126 "Immediately reset session if a link to a directly connected external peer goes down\n")
2127 {
2128 VTY_DECLVAR_CONTEXT(bgp, bgp);
2129 bgp_flag_unset(bgp, BGP_FLAG_NO_FAST_EXT_FAILOVER);
2130 return CMD_SUCCESS;
2131 }
2132
2133 DEFUN (no_bgp_fast_external_failover,
2134 no_bgp_fast_external_failover_cmd,
2135 "no bgp fast-external-failover",
2136 NO_STR
2137 BGP_STR
2138 "Immediately reset session if a link to a directly connected external peer goes down\n")
2139 {
2140 VTY_DECLVAR_CONTEXT(bgp, bgp);
2141 bgp_flag_set(bgp, BGP_FLAG_NO_FAST_EXT_FAILOVER);
2142 return CMD_SUCCESS;
2143 }
2144
2145 /* "bgp enforce-first-as" configuration. */
2146 #if CONFDATE > 20190517
2147 CPP_NOTICE("bgpd: remove deprecated '[no] bgp enforce-first-as' commands")
2148 #endif
2149
2150 DEFUN_HIDDEN (bgp_enforce_first_as,
2151 bgp_enforce_first_as_cmd,
2152 "[no] bgp enforce-first-as",
2153 NO_STR
2154 BGP_STR
2155 "Enforce the first AS for EBGP routes\n")
2156 {
2157 VTY_DECLVAR_CONTEXT(bgp, bgp);
2158
2159 if (strmatch(argv[0]->text, "no"))
2160 bgp_flag_unset(bgp, BGP_FLAG_ENFORCE_FIRST_AS);
2161 else
2162 bgp_flag_set(bgp, BGP_FLAG_ENFORCE_FIRST_AS);
2163
2164 return CMD_SUCCESS;
2165 }
2166
2167 /* "bgp bestpath compare-routerid" configuration. */
2168 DEFUN (bgp_bestpath_compare_router_id,
2169 bgp_bestpath_compare_router_id_cmd,
2170 "bgp bestpath compare-routerid",
2171 "BGP specific commands\n"
2172 "Change the default bestpath selection\n"
2173 "Compare router-id for identical EBGP paths\n")
2174 {
2175 VTY_DECLVAR_CONTEXT(bgp, bgp);
2176 bgp_flag_set(bgp, BGP_FLAG_COMPARE_ROUTER_ID);
2177 bgp_recalculate_all_bestpaths(bgp);
2178
2179 return CMD_SUCCESS;
2180 }
2181
2182 DEFUN (no_bgp_bestpath_compare_router_id,
2183 no_bgp_bestpath_compare_router_id_cmd,
2184 "no bgp bestpath compare-routerid",
2185 NO_STR
2186 "BGP specific commands\n"
2187 "Change the default bestpath selection\n"
2188 "Compare router-id for identical EBGP paths\n")
2189 {
2190 VTY_DECLVAR_CONTEXT(bgp, bgp);
2191 bgp_flag_unset(bgp, BGP_FLAG_COMPARE_ROUTER_ID);
2192 bgp_recalculate_all_bestpaths(bgp);
2193
2194 return CMD_SUCCESS;
2195 }
2196
2197 /* "bgp bestpath as-path ignore" configuration. */
2198 DEFUN (bgp_bestpath_aspath_ignore,
2199 bgp_bestpath_aspath_ignore_cmd,
2200 "bgp bestpath as-path ignore",
2201 "BGP specific commands\n"
2202 "Change the default bestpath selection\n"
2203 "AS-path attribute\n"
2204 "Ignore as-path length in selecting a route\n")
2205 {
2206 VTY_DECLVAR_CONTEXT(bgp, bgp);
2207 bgp_flag_set(bgp, BGP_FLAG_ASPATH_IGNORE);
2208 bgp_recalculate_all_bestpaths(bgp);
2209
2210 return CMD_SUCCESS;
2211 }
2212
2213 DEFUN (no_bgp_bestpath_aspath_ignore,
2214 no_bgp_bestpath_aspath_ignore_cmd,
2215 "no bgp bestpath as-path ignore",
2216 NO_STR
2217 "BGP specific commands\n"
2218 "Change the default bestpath selection\n"
2219 "AS-path attribute\n"
2220 "Ignore as-path length in selecting a route\n")
2221 {
2222 VTY_DECLVAR_CONTEXT(bgp, bgp);
2223 bgp_flag_unset(bgp, BGP_FLAG_ASPATH_IGNORE);
2224 bgp_recalculate_all_bestpaths(bgp);
2225
2226 return CMD_SUCCESS;
2227 }
2228
2229 /* "bgp bestpath as-path confed" configuration. */
2230 DEFUN (bgp_bestpath_aspath_confed,
2231 bgp_bestpath_aspath_confed_cmd,
2232 "bgp bestpath as-path confed",
2233 "BGP specific commands\n"
2234 "Change the default bestpath selection\n"
2235 "AS-path attribute\n"
2236 "Compare path lengths including confederation sets & sequences in selecting a route\n")
2237 {
2238 VTY_DECLVAR_CONTEXT(bgp, bgp);
2239 bgp_flag_set(bgp, BGP_FLAG_ASPATH_CONFED);
2240 bgp_recalculate_all_bestpaths(bgp);
2241
2242 return CMD_SUCCESS;
2243 }
2244
2245 DEFUN (no_bgp_bestpath_aspath_confed,
2246 no_bgp_bestpath_aspath_confed_cmd,
2247 "no bgp bestpath as-path confed",
2248 NO_STR
2249 "BGP specific commands\n"
2250 "Change the default bestpath selection\n"
2251 "AS-path attribute\n"
2252 "Compare path lengths including confederation sets & sequences in selecting a route\n")
2253 {
2254 VTY_DECLVAR_CONTEXT(bgp, bgp);
2255 bgp_flag_unset(bgp, BGP_FLAG_ASPATH_CONFED);
2256 bgp_recalculate_all_bestpaths(bgp);
2257
2258 return CMD_SUCCESS;
2259 }
2260
2261 /* "bgp bestpath as-path multipath-relax" configuration. */
2262 DEFUN (bgp_bestpath_aspath_multipath_relax,
2263 bgp_bestpath_aspath_multipath_relax_cmd,
2264 "bgp bestpath as-path multipath-relax [<as-set|no-as-set>]",
2265 "BGP specific commands\n"
2266 "Change the default bestpath selection\n"
2267 "AS-path attribute\n"
2268 "Allow load sharing across routes that have different AS paths (but same length)\n"
2269 "Generate an AS_SET\n"
2270 "Do not generate an AS_SET\n")
2271 {
2272 VTY_DECLVAR_CONTEXT(bgp, bgp);
2273 int idx = 0;
2274 bgp_flag_set(bgp, BGP_FLAG_ASPATH_MULTIPATH_RELAX);
2275
2276 /* no-as-set is now the default behavior so we can silently
2277 * ignore it */
2278 if (argv_find(argv, argc, "as-set", &idx))
2279 bgp_flag_set(bgp, BGP_FLAG_MULTIPATH_RELAX_AS_SET);
2280 else
2281 bgp_flag_unset(bgp, BGP_FLAG_MULTIPATH_RELAX_AS_SET);
2282
2283 bgp_recalculate_all_bestpaths(bgp);
2284
2285 return CMD_SUCCESS;
2286 }
2287
2288 DEFUN (no_bgp_bestpath_aspath_multipath_relax,
2289 no_bgp_bestpath_aspath_multipath_relax_cmd,
2290 "no bgp bestpath as-path multipath-relax [<as-set|no-as-set>]",
2291 NO_STR
2292 "BGP specific commands\n"
2293 "Change the default bestpath selection\n"
2294 "AS-path attribute\n"
2295 "Allow load sharing across routes that have different AS paths (but same length)\n"
2296 "Generate an AS_SET\n"
2297 "Do not generate an AS_SET\n")
2298 {
2299 VTY_DECLVAR_CONTEXT(bgp, bgp);
2300 bgp_flag_unset(bgp, BGP_FLAG_ASPATH_MULTIPATH_RELAX);
2301 bgp_flag_unset(bgp, BGP_FLAG_MULTIPATH_RELAX_AS_SET);
2302 bgp_recalculate_all_bestpaths(bgp);
2303
2304 return CMD_SUCCESS;
2305 }
2306
2307 /* "bgp log-neighbor-changes" configuration. */
2308 DEFUN (bgp_log_neighbor_changes,
2309 bgp_log_neighbor_changes_cmd,
2310 "bgp log-neighbor-changes",
2311 "BGP specific commands\n"
2312 "Log neighbor up/down and reset reason\n")
2313 {
2314 VTY_DECLVAR_CONTEXT(bgp, bgp);
2315 bgp_flag_set(bgp, BGP_FLAG_LOG_NEIGHBOR_CHANGES);
2316 return CMD_SUCCESS;
2317 }
2318
2319 DEFUN (no_bgp_log_neighbor_changes,
2320 no_bgp_log_neighbor_changes_cmd,
2321 "no bgp log-neighbor-changes",
2322 NO_STR
2323 "BGP specific commands\n"
2324 "Log neighbor up/down and reset reason\n")
2325 {
2326 VTY_DECLVAR_CONTEXT(bgp, bgp);
2327 bgp_flag_unset(bgp, BGP_FLAG_LOG_NEIGHBOR_CHANGES);
2328 return CMD_SUCCESS;
2329 }
2330
2331 /* "bgp bestpath med" configuration. */
2332 DEFUN (bgp_bestpath_med,
2333 bgp_bestpath_med_cmd,
2334 "bgp bestpath med <confed [missing-as-worst]|missing-as-worst [confed]>",
2335 "BGP specific commands\n"
2336 "Change the default bestpath selection\n"
2337 "MED attribute\n"
2338 "Compare MED among confederation paths\n"
2339 "Treat missing MED as the least preferred one\n"
2340 "Treat missing MED as the least preferred one\n"
2341 "Compare MED among confederation paths\n")
2342 {
2343 VTY_DECLVAR_CONTEXT(bgp, bgp);
2344
2345 int idx = 0;
2346 if (argv_find(argv, argc, "confed", &idx))
2347 bgp_flag_set(bgp, BGP_FLAG_MED_CONFED);
2348 idx = 0;
2349 if (argv_find(argv, argc, "missing-as-worst", &idx))
2350 bgp_flag_set(bgp, BGP_FLAG_MED_MISSING_AS_WORST);
2351
2352 bgp_recalculate_all_bestpaths(bgp);
2353
2354 return CMD_SUCCESS;
2355 }
2356
2357 DEFUN (no_bgp_bestpath_med,
2358 no_bgp_bestpath_med_cmd,
2359 "no bgp bestpath med <confed [missing-as-worst]|missing-as-worst [confed]>",
2360 NO_STR
2361 "BGP specific commands\n"
2362 "Change the default bestpath selection\n"
2363 "MED attribute\n"
2364 "Compare MED among confederation paths\n"
2365 "Treat missing MED as the least preferred one\n"
2366 "Treat missing MED as the least preferred one\n"
2367 "Compare MED among confederation paths\n")
2368 {
2369 VTY_DECLVAR_CONTEXT(bgp, bgp);
2370
2371 int idx = 0;
2372 if (argv_find(argv, argc, "confed", &idx))
2373 bgp_flag_unset(bgp, BGP_FLAG_MED_CONFED);
2374 idx = 0;
2375 if (argv_find(argv, argc, "missing-as-worst", &idx))
2376 bgp_flag_unset(bgp, BGP_FLAG_MED_MISSING_AS_WORST);
2377
2378 bgp_recalculate_all_bestpaths(bgp);
2379
2380 return CMD_SUCCESS;
2381 }
2382
2383 /* "no bgp default ipv4-unicast". */
2384 DEFUN (no_bgp_default_ipv4_unicast,
2385 no_bgp_default_ipv4_unicast_cmd,
2386 "no bgp default ipv4-unicast",
2387 NO_STR
2388 "BGP specific commands\n"
2389 "Configure BGP defaults\n"
2390 "Activate ipv4-unicast for a peer by default\n")
2391 {
2392 VTY_DECLVAR_CONTEXT(bgp, bgp);
2393 bgp_flag_set(bgp, BGP_FLAG_NO_DEFAULT_IPV4);
2394 return CMD_SUCCESS;
2395 }
2396
2397 DEFUN (bgp_default_ipv4_unicast,
2398 bgp_default_ipv4_unicast_cmd,
2399 "bgp default ipv4-unicast",
2400 "BGP specific commands\n"
2401 "Configure BGP defaults\n"
2402 "Activate ipv4-unicast for a peer by default\n")
2403 {
2404 VTY_DECLVAR_CONTEXT(bgp, bgp);
2405 bgp_flag_unset(bgp, BGP_FLAG_NO_DEFAULT_IPV4);
2406 return CMD_SUCCESS;
2407 }
2408
2409 /* Display hostname in certain command outputs */
2410 DEFUN (bgp_default_show_hostname,
2411 bgp_default_show_hostname_cmd,
2412 "bgp default show-hostname",
2413 "BGP specific commands\n"
2414 "Configure BGP defaults\n"
2415 "Show hostname in certain command outputs\n")
2416 {
2417 VTY_DECLVAR_CONTEXT(bgp, bgp);
2418 bgp_flag_set(bgp, BGP_FLAG_SHOW_HOSTNAME);
2419 return CMD_SUCCESS;
2420 }
2421
2422 DEFUN (no_bgp_default_show_hostname,
2423 no_bgp_default_show_hostname_cmd,
2424 "no bgp default show-hostname",
2425 NO_STR
2426 "BGP specific commands\n"
2427 "Configure BGP defaults\n"
2428 "Show hostname in certain command outputs\n")
2429 {
2430 VTY_DECLVAR_CONTEXT(bgp, bgp);
2431 bgp_flag_unset(bgp, BGP_FLAG_SHOW_HOSTNAME);
2432 return CMD_SUCCESS;
2433 }
2434
2435 /* "bgp network import-check" configuration. */
2436 DEFUN (bgp_network_import_check,
2437 bgp_network_import_check_cmd,
2438 "bgp network import-check",
2439 "BGP specific commands\n"
2440 "BGP network command\n"
2441 "Check BGP network route exists in IGP\n")
2442 {
2443 VTY_DECLVAR_CONTEXT(bgp, bgp);
2444 if (!bgp_flag_check(bgp, BGP_FLAG_IMPORT_CHECK)) {
2445 bgp_flag_set(bgp, BGP_FLAG_IMPORT_CHECK);
2446 bgp_static_redo_import_check(bgp);
2447 }
2448
2449 return CMD_SUCCESS;
2450 }
2451
2452 ALIAS_HIDDEN(bgp_network_import_check, bgp_network_import_check_exact_cmd,
2453 "bgp network import-check exact",
2454 "BGP specific commands\n"
2455 "BGP network command\n"
2456 "Check BGP network route exists in IGP\n"
2457 "Match route precisely\n")
2458
2459 DEFUN (no_bgp_network_import_check,
2460 no_bgp_network_import_check_cmd,
2461 "no bgp network import-check",
2462 NO_STR
2463 "BGP specific commands\n"
2464 "BGP network command\n"
2465 "Check BGP network route exists in IGP\n")
2466 {
2467 VTY_DECLVAR_CONTEXT(bgp, bgp);
2468 if (bgp_flag_check(bgp, BGP_FLAG_IMPORT_CHECK)) {
2469 bgp_flag_unset(bgp, BGP_FLAG_IMPORT_CHECK);
2470 bgp_static_redo_import_check(bgp);
2471 }
2472
2473 return CMD_SUCCESS;
2474 }
2475
2476 DEFUN (bgp_default_local_preference,
2477 bgp_default_local_preference_cmd,
2478 "bgp default local-preference (0-4294967295)",
2479 "BGP specific commands\n"
2480 "Configure BGP defaults\n"
2481 "local preference (higher=more preferred)\n"
2482 "Configure default local preference value\n")
2483 {
2484 VTY_DECLVAR_CONTEXT(bgp, bgp);
2485 int idx_number = 3;
2486 uint32_t local_pref;
2487
2488 local_pref = strtoul(argv[idx_number]->arg, NULL, 10);
2489
2490 bgp_default_local_preference_set(bgp, local_pref);
2491 bgp_clear_star_soft_in(vty, bgp->name);
2492
2493 return CMD_SUCCESS;
2494 }
2495
2496 DEFUN (no_bgp_default_local_preference,
2497 no_bgp_default_local_preference_cmd,
2498 "no bgp default local-preference [(0-4294967295)]",
2499 NO_STR
2500 "BGP specific commands\n"
2501 "Configure BGP defaults\n"
2502 "local preference (higher=more preferred)\n"
2503 "Configure default local preference value\n")
2504 {
2505 VTY_DECLVAR_CONTEXT(bgp, bgp);
2506 bgp_default_local_preference_unset(bgp);
2507 bgp_clear_star_soft_in(vty, bgp->name);
2508
2509 return CMD_SUCCESS;
2510 }
2511
2512
2513 DEFUN (bgp_default_subgroup_pkt_queue_max,
2514 bgp_default_subgroup_pkt_queue_max_cmd,
2515 "bgp default subgroup-pkt-queue-max (20-100)",
2516 "BGP specific commands\n"
2517 "Configure BGP defaults\n"
2518 "subgroup-pkt-queue-max\n"
2519 "Configure subgroup packet queue max\n")
2520 {
2521 VTY_DECLVAR_CONTEXT(bgp, bgp);
2522 int idx_number = 3;
2523 uint32_t max_size;
2524
2525 max_size = strtoul(argv[idx_number]->arg, NULL, 10);
2526
2527 bgp_default_subgroup_pkt_queue_max_set(bgp, max_size);
2528
2529 return CMD_SUCCESS;
2530 }
2531
2532 DEFUN (no_bgp_default_subgroup_pkt_queue_max,
2533 no_bgp_default_subgroup_pkt_queue_max_cmd,
2534 "no bgp default subgroup-pkt-queue-max [(20-100)]",
2535 NO_STR
2536 "BGP specific commands\n"
2537 "Configure BGP defaults\n"
2538 "subgroup-pkt-queue-max\n"
2539 "Configure subgroup packet queue max\n")
2540 {
2541 VTY_DECLVAR_CONTEXT(bgp, bgp);
2542 bgp_default_subgroup_pkt_queue_max_unset(bgp);
2543 return CMD_SUCCESS;
2544 }
2545
2546
2547 DEFUN (bgp_rr_allow_outbound_policy,
2548 bgp_rr_allow_outbound_policy_cmd,
2549 "bgp route-reflector allow-outbound-policy",
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_set(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 (no_bgp_rr_allow_outbound_policy,
2566 no_bgp_rr_allow_outbound_policy_cmd,
2567 "no bgp route-reflector allow-outbound-policy",
2568 NO_STR
2569 "BGP specific commands\n"
2570 "Allow modifications made by out route-map\n"
2571 "on ibgp neighbors\n")
2572 {
2573 VTY_DECLVAR_CONTEXT(bgp, bgp);
2574
2575 if (bgp_flag_check(bgp, BGP_FLAG_RR_ALLOW_OUTBOUND_POLICY)) {
2576 bgp_flag_unset(bgp, BGP_FLAG_RR_ALLOW_OUTBOUND_POLICY);
2577 update_group_announce_rrclients(bgp);
2578 bgp_clear_star_soft_out(vty, bgp->name);
2579 }
2580
2581 return CMD_SUCCESS;
2582 }
2583
2584 DEFUN (bgp_listen_limit,
2585 bgp_listen_limit_cmd,
2586 "bgp listen limit (1-5000)",
2587 "BGP specific commands\n"
2588 "Configure BGP defaults\n"
2589 "maximum number of BGP Dynamic Neighbors that can be created\n"
2590 "Configure Dynamic Neighbors listen limit value\n")
2591 {
2592 VTY_DECLVAR_CONTEXT(bgp, bgp);
2593 int idx_number = 3;
2594 int listen_limit;
2595
2596 listen_limit = strtoul(argv[idx_number]->arg, NULL, 10);
2597
2598 bgp_listen_limit_set(bgp, listen_limit);
2599
2600 return CMD_SUCCESS;
2601 }
2602
2603 DEFUN (no_bgp_listen_limit,
2604 no_bgp_listen_limit_cmd,
2605 "no bgp listen limit [(1-5000)]",
2606 "BGP specific commands\n"
2607 "Configure BGP defaults\n"
2608 "unset maximum number of BGP Dynamic Neighbors that can be created\n"
2609 "Configure Dynamic Neighbors listen limit value to default\n"
2610 "Configure Dynamic Neighbors listen limit value\n")
2611 {
2612 VTY_DECLVAR_CONTEXT(bgp, bgp);
2613 bgp_listen_limit_unset(bgp);
2614 return CMD_SUCCESS;
2615 }
2616
2617
2618 /*
2619 * Check if this listen range is already configured. Check for exact
2620 * match or overlap based on input.
2621 */
2622 static struct peer_group *listen_range_exists(struct bgp *bgp,
2623 struct prefix *range, int exact)
2624 {
2625 struct listnode *node, *nnode;
2626 struct listnode *node1, *nnode1;
2627 struct peer_group *group;
2628 struct prefix *lr;
2629 afi_t afi;
2630 int match;
2631
2632 afi = family2afi(range->family);
2633 for (ALL_LIST_ELEMENTS(bgp->group, node, nnode, group)) {
2634 for (ALL_LIST_ELEMENTS(group->listen_range[afi], node1, nnode1,
2635 lr)) {
2636 if (exact)
2637 match = prefix_same(range, lr);
2638 else
2639 match = (prefix_match(range, lr)
2640 || prefix_match(lr, range));
2641 if (match)
2642 return group;
2643 }
2644 }
2645
2646 return NULL;
2647 }
2648
2649 DEFUN (bgp_listen_range,
2650 bgp_listen_range_cmd,
2651 "bgp listen range <A.B.C.D/M|X:X::X:X/M> peer-group WORD",
2652 "BGP specific commands\n"
2653 "Configure BGP dynamic neighbors listen range\n"
2654 "Configure BGP dynamic neighbors listen range\n"
2655 NEIGHBOR_ADDR_STR
2656 "Member of the peer-group\n"
2657 "Peer-group name\n")
2658 {
2659 VTY_DECLVAR_CONTEXT(bgp, bgp);
2660 struct prefix range;
2661 struct peer_group *group, *existing_group;
2662 afi_t afi;
2663 int ret;
2664 int idx = 0;
2665
2666 argv_find(argv, argc, "A.B.C.D/M", &idx);
2667 argv_find(argv, argc, "X:X::X:X/M", &idx);
2668 char *prefix = argv[idx]->arg;
2669 argv_find(argv, argc, "WORD", &idx);
2670 char *peergroup = argv[idx]->arg;
2671
2672 /* Convert IP prefix string to struct prefix. */
2673 ret = str2prefix(prefix, &range);
2674 if (!ret) {
2675 vty_out(vty, "%% Malformed listen range\n");
2676 return CMD_WARNING_CONFIG_FAILED;
2677 }
2678
2679 afi = family2afi(range.family);
2680
2681 if (afi == AFI_IP6 && IN6_IS_ADDR_LINKLOCAL(&range.u.prefix6)) {
2682 vty_out(vty,
2683 "%% Malformed listen range (link-local address)\n");
2684 return CMD_WARNING_CONFIG_FAILED;
2685 }
2686
2687 apply_mask(&range);
2688
2689 /* Check if same listen range is already configured. */
2690 existing_group = listen_range_exists(bgp, &range, 1);
2691 if (existing_group) {
2692 if (strcmp(existing_group->name, peergroup) == 0)
2693 return CMD_SUCCESS;
2694 else {
2695 vty_out(vty,
2696 "%% Same listen range is attached to peer-group %s\n",
2697 existing_group->name);
2698 return CMD_WARNING_CONFIG_FAILED;
2699 }
2700 }
2701
2702 /* Check if an overlapping listen range exists. */
2703 if (listen_range_exists(bgp, &range, 0)) {
2704 vty_out(vty,
2705 "%% Listen range overlaps with existing listen range\n");
2706 return CMD_WARNING_CONFIG_FAILED;
2707 }
2708
2709 group = peer_group_lookup(bgp, peergroup);
2710 if (!group) {
2711 vty_out(vty, "%% Configure the peer-group first\n");
2712 return CMD_WARNING_CONFIG_FAILED;
2713 }
2714
2715 ret = peer_group_listen_range_add(group, &range);
2716 return bgp_vty_return(vty, ret);
2717 }
2718
2719 DEFUN (no_bgp_listen_range,
2720 no_bgp_listen_range_cmd,
2721 "no bgp listen range <A.B.C.D/M|X:X::X:X/M> peer-group WORD",
2722 NO_STR
2723 "BGP specific commands\n"
2724 "Unconfigure BGP dynamic neighbors listen range\n"
2725 "Unconfigure BGP dynamic neighbors listen range\n"
2726 NEIGHBOR_ADDR_STR
2727 "Member of the peer-group\n"
2728 "Peer-group name\n")
2729 {
2730 VTY_DECLVAR_CONTEXT(bgp, bgp);
2731 struct prefix range;
2732 struct peer_group *group;
2733 afi_t afi;
2734 int ret;
2735 int idx = 0;
2736
2737 argv_find(argv, argc, "A.B.C.D/M", &idx);
2738 argv_find(argv, argc, "X:X::X:X/M", &idx);
2739 char *prefix = argv[idx]->arg;
2740 argv_find(argv, argc, "WORD", &idx);
2741 char *peergroup = argv[idx]->arg;
2742
2743 /* Convert IP prefix string to struct prefix. */
2744 ret = str2prefix(prefix, &range);
2745 if (!ret) {
2746 vty_out(vty, "%% Malformed listen range\n");
2747 return CMD_WARNING_CONFIG_FAILED;
2748 }
2749
2750 afi = family2afi(range.family);
2751
2752 if (afi == AFI_IP6 && IN6_IS_ADDR_LINKLOCAL(&range.u.prefix6)) {
2753 vty_out(vty,
2754 "%% Malformed listen range (link-local address)\n");
2755 return CMD_WARNING_CONFIG_FAILED;
2756 }
2757
2758 apply_mask(&range);
2759
2760 group = peer_group_lookup(bgp, peergroup);
2761 if (!group) {
2762 vty_out(vty, "%% Peer-group does not exist\n");
2763 return CMD_WARNING_CONFIG_FAILED;
2764 }
2765
2766 ret = peer_group_listen_range_del(group, &range);
2767 return bgp_vty_return(vty, ret);
2768 }
2769
2770 void bgp_config_write_listen(struct vty *vty, struct bgp *bgp)
2771 {
2772 struct peer_group *group;
2773 struct listnode *node, *nnode, *rnode, *nrnode;
2774 struct prefix *range;
2775 afi_t afi;
2776 char buf[PREFIX2STR_BUFFER];
2777
2778 if (bgp->dynamic_neighbors_limit != BGP_DYNAMIC_NEIGHBORS_LIMIT_DEFAULT)
2779 vty_out(vty, " bgp listen limit %d\n",
2780 bgp->dynamic_neighbors_limit);
2781
2782 for (ALL_LIST_ELEMENTS(bgp->group, node, nnode, group)) {
2783 for (afi = AFI_IP; afi < AFI_MAX; afi++) {
2784 for (ALL_LIST_ELEMENTS(group->listen_range[afi], rnode,
2785 nrnode, range)) {
2786 prefix2str(range, buf, sizeof(buf));
2787 vty_out(vty,
2788 " bgp listen range %s peer-group %s\n",
2789 buf, group->name);
2790 }
2791 }
2792 }
2793 }
2794
2795
2796 DEFUN (bgp_disable_connected_route_check,
2797 bgp_disable_connected_route_check_cmd,
2798 "bgp disable-ebgp-connected-route-check",
2799 "BGP specific commands\n"
2800 "Disable checking if nexthop is connected on ebgp sessions\n")
2801 {
2802 VTY_DECLVAR_CONTEXT(bgp, bgp);
2803 bgp_flag_set(bgp, BGP_FLAG_DISABLE_NH_CONNECTED_CHK);
2804 bgp_clear_star_soft_in(vty, bgp->name);
2805
2806 return CMD_SUCCESS;
2807 }
2808
2809 DEFUN (no_bgp_disable_connected_route_check,
2810 no_bgp_disable_connected_route_check_cmd,
2811 "no bgp disable-ebgp-connected-route-check",
2812 NO_STR
2813 "BGP specific commands\n"
2814 "Disable checking if nexthop is connected on ebgp sessions\n")
2815 {
2816 VTY_DECLVAR_CONTEXT(bgp, bgp);
2817 bgp_flag_unset(bgp, BGP_FLAG_DISABLE_NH_CONNECTED_CHK);
2818 bgp_clear_star_soft_in(vty, bgp->name);
2819
2820 return CMD_SUCCESS;
2821 }
2822
2823
2824 static int peer_remote_as_vty(struct vty *vty, const char *peer_str,
2825 const char *as_str, afi_t afi, safi_t safi)
2826 {
2827 VTY_DECLVAR_CONTEXT(bgp, bgp);
2828 int ret;
2829 as_t as;
2830 int as_type = AS_SPECIFIED;
2831 union sockunion su;
2832
2833 if (as_str[0] == 'i') {
2834 as = 0;
2835 as_type = AS_INTERNAL;
2836 } else if (as_str[0] == 'e') {
2837 as = 0;
2838 as_type = AS_EXTERNAL;
2839 } else {
2840 /* Get AS number. */
2841 as = strtoul(as_str, NULL, 10);
2842 }
2843
2844 /* If peer is peer group or interface peer, call proper function. */
2845 ret = str2sockunion(peer_str, &su);
2846 if (ret < 0) {
2847 struct peer *peer;
2848
2849 /* Check if existing interface peer */
2850 peer = peer_lookup_by_conf_if(bgp, peer_str);
2851
2852 ret = peer_remote_as(bgp, NULL, peer_str, &as, as_type, afi,
2853 safi);
2854
2855 /* if not interface peer, check peer-group settings */
2856 if (ret < 0 && !peer) {
2857 ret = peer_group_remote_as(bgp, peer_str, &as, as_type);
2858 if (ret < 0) {
2859 vty_out(vty,
2860 "%% Create the peer-group or interface first\n");
2861 return CMD_WARNING_CONFIG_FAILED;
2862 }
2863 return CMD_SUCCESS;
2864 }
2865 } else {
2866 if (peer_address_self_check(bgp, &su)) {
2867 vty_out(vty,
2868 "%% Can not configure the local system as neighbor\n");
2869 return CMD_WARNING_CONFIG_FAILED;
2870 }
2871 ret = peer_remote_as(bgp, &su, NULL, &as, as_type, afi, safi);
2872 }
2873
2874 /* This peer belongs to peer group. */
2875 switch (ret) {
2876 case BGP_ERR_PEER_GROUP_MEMBER:
2877 vty_out(vty,
2878 "%% Peer-group member cannot override remote-as of peer-group\n");
2879 return CMD_WARNING_CONFIG_FAILED;
2880 case BGP_ERR_PEER_GROUP_PEER_TYPE_DIFFERENT:
2881 vty_out(vty,
2882 "%% Peer-group members must be all internal or all external\n");
2883 return CMD_WARNING_CONFIG_FAILED;
2884 }
2885 return bgp_vty_return(vty, ret);
2886 }
2887
2888 DEFUN (bgp_default_shutdown,
2889 bgp_default_shutdown_cmd,
2890 "[no] bgp default shutdown",
2891 NO_STR
2892 BGP_STR
2893 "Configure BGP defaults\n"
2894 "Apply administrative shutdown to newly configured peers\n")
2895 {
2896 VTY_DECLVAR_CONTEXT(bgp, bgp);
2897 bgp->autoshutdown = !strmatch(argv[0]->text, "no");
2898 return CMD_SUCCESS;
2899 }
2900
2901 DEFUN (neighbor_remote_as,
2902 neighbor_remote_as_cmd,
2903 "neighbor <A.B.C.D|X:X::X:X|WORD> remote-as <(1-4294967295)|internal|external>",
2904 NEIGHBOR_STR
2905 NEIGHBOR_ADDR_STR2
2906 "Specify a BGP neighbor\n"
2907 AS_STR
2908 "Internal BGP peer\n"
2909 "External BGP peer\n")
2910 {
2911 int idx_peer = 1;
2912 int idx_remote_as = 3;
2913 return peer_remote_as_vty(vty, argv[idx_peer]->arg,
2914 argv[idx_remote_as]->arg, AFI_IP,
2915 SAFI_UNICAST);
2916 }
2917
2918 static int peer_conf_interface_get(struct vty *vty, const char *conf_if,
2919 afi_t afi, safi_t safi, int v6only,
2920 const char *peer_group_name,
2921 const char *as_str)
2922 {
2923 VTY_DECLVAR_CONTEXT(bgp, bgp);
2924 as_t as = 0;
2925 int as_type = AS_UNSPECIFIED;
2926 struct peer *peer;
2927 struct peer_group *group;
2928 int ret = 0;
2929 union sockunion su;
2930
2931 group = peer_group_lookup(bgp, conf_if);
2932
2933 if (group) {
2934 vty_out(vty, "%% Name conflict with peer-group \n");
2935 return CMD_WARNING_CONFIG_FAILED;
2936 }
2937
2938 if (as_str) {
2939 if (as_str[0] == 'i') {
2940 as_type = AS_INTERNAL;
2941 } else if (as_str[0] == 'e') {
2942 as_type = AS_EXTERNAL;
2943 } else {
2944 /* Get AS number. */
2945 as = strtoul(as_str, NULL, 10);
2946 as_type = AS_SPECIFIED;
2947 }
2948 }
2949
2950 peer = peer_lookup_by_conf_if(bgp, conf_if);
2951 if (peer) {
2952 if (as_str)
2953 ret = peer_remote_as(bgp, NULL, conf_if, &as, as_type,
2954 afi, safi);
2955 } else {
2956 if (bgp_flag_check(bgp, BGP_FLAG_NO_DEFAULT_IPV4)
2957 && afi == AFI_IP && safi == SAFI_UNICAST)
2958 peer = peer_create(NULL, conf_if, bgp, bgp->as, as,
2959 as_type, 0, 0, NULL);
2960 else
2961 peer = peer_create(NULL, conf_if, bgp, bgp->as, as,
2962 as_type, afi, safi, NULL);
2963
2964 if (!peer) {
2965 vty_out(vty, "%% BGP failed to create peer\n");
2966 return CMD_WARNING_CONFIG_FAILED;
2967 }
2968
2969 if (v6only)
2970 peer_flag_set(peer, PEER_FLAG_IFPEER_V6ONLY);
2971
2972 /* Request zebra to initiate IPv6 RAs on this interface. We do
2973 * this
2974 * any unnumbered peer in order to not worry about run-time
2975 * transitions
2976 * (e.g., peering is initially IPv4, but the IPv4 /30 or /31
2977 * address
2978 * gets deleted later etc.)
2979 */
2980 if (peer->ifp)
2981 bgp_zebra_initiate_radv(bgp, peer);
2982 }
2983
2984 if ((v6only && !CHECK_FLAG(peer->flags, PEER_FLAG_IFPEER_V6ONLY))
2985 || (!v6only && CHECK_FLAG(peer->flags, PEER_FLAG_IFPEER_V6ONLY))) {
2986 if (v6only)
2987 peer_flag_set(peer, PEER_FLAG_IFPEER_V6ONLY);
2988 else
2989 peer_flag_unset(peer, PEER_FLAG_IFPEER_V6ONLY);
2990
2991 /* v6only flag changed. Reset bgp seesion */
2992 if (BGP_IS_VALID_STATE_FOR_NOTIF(peer->status)) {
2993 peer->last_reset = PEER_DOWN_V6ONLY_CHANGE;
2994 bgp_notify_send(peer, BGP_NOTIFY_CEASE,
2995 BGP_NOTIFY_CEASE_CONFIG_CHANGE);
2996 } else
2997 bgp_session_reset(peer);
2998 }
2999
3000 if (!CHECK_FLAG(peer->flags_invert, PEER_FLAG_CAPABILITY_ENHE)) {
3001 SET_FLAG(peer->flags, PEER_FLAG_CAPABILITY_ENHE);
3002 SET_FLAG(peer->flags_invert, PEER_FLAG_CAPABILITY_ENHE);
3003 SET_FLAG(peer->flags_override, PEER_FLAG_CAPABILITY_ENHE);
3004 }
3005
3006 if (peer_group_name) {
3007 group = peer_group_lookup(bgp, peer_group_name);
3008 if (!group) {
3009 vty_out(vty, "%% Configure the peer-group first\n");
3010 return CMD_WARNING_CONFIG_FAILED;
3011 }
3012
3013 ret = peer_group_bind(bgp, &su, peer, group, &as);
3014 }
3015
3016 return bgp_vty_return(vty, ret);
3017 }
3018
3019 DEFUN (neighbor_interface_config,
3020 neighbor_interface_config_cmd,
3021 "neighbor WORD interface [peer-group WORD]",
3022 NEIGHBOR_STR
3023 "Interface name or neighbor tag\n"
3024 "Enable BGP on interface\n"
3025 "Member of the peer-group\n"
3026 "Peer-group name\n")
3027 {
3028 int idx_word = 1;
3029 int idx_peer_group_word = 4;
3030
3031 if (argc > idx_peer_group_word)
3032 return peer_conf_interface_get(
3033 vty, argv[idx_word]->arg, AFI_IP, SAFI_UNICAST, 0,
3034 argv[idx_peer_group_word]->arg, NULL);
3035 else
3036 return peer_conf_interface_get(vty, argv[idx_word]->arg, AFI_IP,
3037 SAFI_UNICAST, 0, NULL, NULL);
3038 }
3039
3040 DEFUN (neighbor_interface_config_v6only,
3041 neighbor_interface_config_v6only_cmd,
3042 "neighbor WORD interface v6only [peer-group WORD]",
3043 NEIGHBOR_STR
3044 "Interface name or neighbor tag\n"
3045 "Enable BGP on interface\n"
3046 "Enable BGP with v6 link-local only\n"
3047 "Member of the peer-group\n"
3048 "Peer-group name\n")
3049 {
3050 int idx_word = 1;
3051 int idx_peer_group_word = 5;
3052
3053 if (argc > idx_peer_group_word)
3054 return peer_conf_interface_get(
3055 vty, argv[idx_word]->arg, AFI_IP, SAFI_UNICAST, 1,
3056 argv[idx_peer_group_word]->arg, NULL);
3057
3058 return peer_conf_interface_get(vty, argv[idx_word]->arg, AFI_IP,
3059 SAFI_UNICAST, 1, NULL, NULL);
3060 }
3061
3062
3063 DEFUN (neighbor_interface_config_remote_as,
3064 neighbor_interface_config_remote_as_cmd,
3065 "neighbor WORD interface remote-as <(1-4294967295)|internal|external>",
3066 NEIGHBOR_STR
3067 "Interface name or neighbor tag\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 = 4;
3076 return peer_conf_interface_get(vty, argv[idx_word]->arg, AFI_IP,
3077 SAFI_UNICAST, 0, NULL,
3078 argv[idx_remote_as]->arg);
3079 }
3080
3081 DEFUN (neighbor_interface_v6only_config_remote_as,
3082 neighbor_interface_v6only_config_remote_as_cmd,
3083 "neighbor WORD interface v6only remote-as <(1-4294967295)|internal|external>",
3084 NEIGHBOR_STR
3085 "Interface name or neighbor tag\n"
3086 "Enable BGP with v6 link-local only\n"
3087 "Enable BGP on interface\n"
3088 "Specify a BGP neighbor\n"
3089 AS_STR
3090 "Internal BGP peer\n"
3091 "External BGP peer\n")
3092 {
3093 int idx_word = 1;
3094 int idx_remote_as = 5;
3095 return peer_conf_interface_get(vty, argv[idx_word]->arg, AFI_IP,
3096 SAFI_UNICAST, 1, NULL,
3097 argv[idx_remote_as]->arg);
3098 }
3099
3100 DEFUN (neighbor_peer_group,
3101 neighbor_peer_group_cmd,
3102 "neighbor WORD peer-group",
3103 NEIGHBOR_STR
3104 "Interface name or neighbor tag\n"
3105 "Configure peer-group\n")
3106 {
3107 VTY_DECLVAR_CONTEXT(bgp, bgp);
3108 int idx_word = 1;
3109 struct peer *peer;
3110 struct peer_group *group;
3111
3112 peer = peer_lookup_by_conf_if(bgp, argv[idx_word]->arg);
3113 if (peer) {
3114 vty_out(vty, "%% Name conflict with interface: \n");
3115 return CMD_WARNING_CONFIG_FAILED;
3116 }
3117
3118 group = peer_group_get(bgp, argv[idx_word]->arg);
3119 if (!group) {
3120 vty_out(vty, "%% BGP failed to find or create peer-group\n");
3121 return CMD_WARNING_CONFIG_FAILED;
3122 }
3123
3124 return CMD_SUCCESS;
3125 }
3126
3127 DEFUN (no_neighbor,
3128 no_neighbor_cmd,
3129 "no neighbor <WORD|<A.B.C.D|X:X::X:X> [remote-as <(1-4294967295)|internal|external>]>",
3130 NO_STR
3131 NEIGHBOR_STR
3132 NEIGHBOR_ADDR_STR2
3133 "Specify a BGP neighbor\n"
3134 AS_STR
3135 "Internal BGP peer\n"
3136 "External BGP peer\n")
3137 {
3138 VTY_DECLVAR_CONTEXT(bgp, bgp);
3139 int idx_peer = 2;
3140 int ret;
3141 union sockunion su;
3142 struct peer_group *group;
3143 struct peer *peer;
3144 struct peer *other;
3145
3146 ret = str2sockunion(argv[idx_peer]->arg, &su);
3147 if (ret < 0) {
3148 /* look up for neighbor by interface name config. */
3149 peer = peer_lookup_by_conf_if(bgp, argv[idx_peer]->arg);
3150 if (peer) {
3151 /* Request zebra to terminate IPv6 RAs on this
3152 * interface. */
3153 if (peer->ifp)
3154 bgp_zebra_terminate_radv(peer->bgp, peer);
3155 peer_delete(peer);
3156 return CMD_SUCCESS;
3157 }
3158
3159 group = peer_group_lookup(bgp, argv[idx_peer]->arg);
3160 if (group)
3161 peer_group_delete(group);
3162 else {
3163 vty_out(vty, "%% Create the peer-group first\n");
3164 return CMD_WARNING_CONFIG_FAILED;
3165 }
3166 } else {
3167 peer = peer_lookup(bgp, &su);
3168 if (peer) {
3169 if (peer_dynamic_neighbor(peer)) {
3170 vty_out(vty,
3171 "%% Operation not allowed on a dynamic neighbor\n");
3172 return CMD_WARNING_CONFIG_FAILED;
3173 }
3174
3175 other = peer->doppelganger;
3176 peer_delete(peer);
3177 if (other && other->status != Deleted)
3178 peer_delete(other);
3179 }
3180 }
3181
3182 return CMD_SUCCESS;
3183 }
3184
3185 DEFUN (no_neighbor_interface_config,
3186 no_neighbor_interface_config_cmd,
3187 "no neighbor WORD interface [v6only] [peer-group WORD] [remote-as <(1-4294967295)|internal|external>]",
3188 NO_STR
3189 NEIGHBOR_STR
3190 "Interface name\n"
3191 "Configure BGP on interface\n"
3192 "Enable BGP with v6 link-local only\n"
3193 "Member of the peer-group\n"
3194 "Peer-group name\n"
3195 "Specify a BGP neighbor\n"
3196 AS_STR
3197 "Internal BGP peer\n"
3198 "External BGP peer\n")
3199 {
3200 VTY_DECLVAR_CONTEXT(bgp, bgp);
3201 int idx_word = 2;
3202 struct peer *peer;
3203
3204 /* look up for neighbor by interface name config. */
3205 peer = peer_lookup_by_conf_if(bgp, argv[idx_word]->arg);
3206 if (peer) {
3207 /* Request zebra to terminate IPv6 RAs on this interface. */
3208 if (peer->ifp)
3209 bgp_zebra_terminate_radv(peer->bgp, peer);
3210 peer_delete(peer);
3211 } else {
3212 vty_out(vty, "%% Create the bgp interface first\n");
3213 return CMD_WARNING_CONFIG_FAILED;
3214 }
3215 return CMD_SUCCESS;
3216 }
3217
3218 DEFUN (no_neighbor_peer_group,
3219 no_neighbor_peer_group_cmd,
3220 "no neighbor WORD peer-group",
3221 NO_STR
3222 NEIGHBOR_STR
3223 "Neighbor tag\n"
3224 "Configure peer-group\n")
3225 {
3226 VTY_DECLVAR_CONTEXT(bgp, bgp);
3227 int idx_word = 2;
3228 struct peer_group *group;
3229
3230 group = peer_group_lookup(bgp, argv[idx_word]->arg);
3231 if (group)
3232 peer_group_delete(group);
3233 else {
3234 vty_out(vty, "%% Create the peer-group first\n");
3235 return CMD_WARNING_CONFIG_FAILED;
3236 }
3237 return CMD_SUCCESS;
3238 }
3239
3240 DEFUN (no_neighbor_interface_peer_group_remote_as,
3241 no_neighbor_interface_peer_group_remote_as_cmd,
3242 "no neighbor WORD remote-as <(1-4294967295)|internal|external>",
3243 NO_STR
3244 NEIGHBOR_STR
3245 "Interface name or neighbor tag\n"
3246 "Specify a BGP neighbor\n"
3247 AS_STR
3248 "Internal BGP peer\n"
3249 "External BGP peer\n")
3250 {
3251 VTY_DECLVAR_CONTEXT(bgp, bgp);
3252 int idx_word = 2;
3253 struct peer_group *group;
3254 struct peer *peer;
3255
3256 /* look up for neighbor by interface name config. */
3257 peer = peer_lookup_by_conf_if(bgp, argv[idx_word]->arg);
3258 if (peer) {
3259 peer_as_change(peer, 0, AS_UNSPECIFIED);
3260 return CMD_SUCCESS;
3261 }
3262
3263 group = peer_group_lookup(bgp, argv[idx_word]->arg);
3264 if (group)
3265 peer_group_remote_as_delete(group);
3266 else {
3267 vty_out(vty, "%% Create the peer-group or interface first\n");
3268 return CMD_WARNING_CONFIG_FAILED;
3269 }
3270 return CMD_SUCCESS;
3271 }
3272
3273 DEFUN (neighbor_local_as,
3274 neighbor_local_as_cmd,
3275 "neighbor <A.B.C.D|X:X::X:X|WORD> local-as (1-4294967295)",
3276 NEIGHBOR_STR
3277 NEIGHBOR_ADDR_STR2
3278 "Specify a local-as number\n"
3279 "AS number used as local AS\n")
3280 {
3281 int idx_peer = 1;
3282 int idx_number = 3;
3283 struct peer *peer;
3284 int ret;
3285 as_t as;
3286
3287 peer = peer_and_group_lookup_vty(vty, argv[idx_peer]->arg);
3288 if (!peer)
3289 return CMD_WARNING_CONFIG_FAILED;
3290
3291 as = strtoul(argv[idx_number]->arg, NULL, 10);
3292 ret = peer_local_as_set(peer, as, 0, 0);
3293 return bgp_vty_return(vty, ret);
3294 }
3295
3296 DEFUN (neighbor_local_as_no_prepend,
3297 neighbor_local_as_no_prepend_cmd,
3298 "neighbor <A.B.C.D|X:X::X:X|WORD> local-as (1-4294967295) no-prepend",
3299 NEIGHBOR_STR
3300 NEIGHBOR_ADDR_STR2
3301 "Specify a local-as number\n"
3302 "AS number used as local AS\n"
3303 "Do not prepend local-as to updates from ebgp peers\n")
3304 {
3305 int idx_peer = 1;
3306 int idx_number = 3;
3307 struct peer *peer;
3308 int ret;
3309 as_t as;
3310
3311 peer = peer_and_group_lookup_vty(vty, argv[idx_peer]->arg);
3312 if (!peer)
3313 return CMD_WARNING_CONFIG_FAILED;
3314
3315 as = strtoul(argv[idx_number]->arg, NULL, 10);
3316 ret = peer_local_as_set(peer, as, 1, 0);
3317 return bgp_vty_return(vty, ret);
3318 }
3319
3320 DEFUN (neighbor_local_as_no_prepend_replace_as,
3321 neighbor_local_as_no_prepend_replace_as_cmd,
3322 "neighbor <A.B.C.D|X:X::X:X|WORD> local-as (1-4294967295) no-prepend replace-as",
3323 NEIGHBOR_STR
3324 NEIGHBOR_ADDR_STR2
3325 "Specify a local-as number\n"
3326 "AS number used as local AS\n"
3327 "Do not prepend local-as to updates from ebgp peers\n"
3328 "Do not prepend local-as to updates from ibgp peers\n")
3329 {
3330 int idx_peer = 1;
3331 int idx_number = 3;
3332 struct peer *peer;
3333 int ret;
3334 as_t as;
3335
3336 peer = peer_and_group_lookup_vty(vty, argv[idx_peer]->arg);
3337 if (!peer)
3338 return CMD_WARNING_CONFIG_FAILED;
3339
3340 as = strtoul(argv[idx_number]->arg, NULL, 10);
3341 ret = peer_local_as_set(peer, as, 1, 1);
3342 return bgp_vty_return(vty, ret);
3343 }
3344
3345 DEFUN (no_neighbor_local_as,
3346 no_neighbor_local_as_cmd,
3347 "no neighbor <A.B.C.D|X:X::X:X|WORD> local-as [(1-4294967295) [no-prepend [replace-as]]]",
3348 NO_STR
3349 NEIGHBOR_STR
3350 NEIGHBOR_ADDR_STR2
3351 "Specify a local-as number\n"
3352 "AS number used as local AS\n"
3353 "Do not prepend local-as to updates from ebgp peers\n"
3354 "Do not prepend local-as to updates from ibgp peers\n")
3355 {
3356 int idx_peer = 2;
3357 struct peer *peer;
3358 int ret;
3359
3360 peer = peer_and_group_lookup_vty(vty, argv[idx_peer]->arg);
3361 if (!peer)
3362 return CMD_WARNING_CONFIG_FAILED;
3363
3364 ret = peer_local_as_unset(peer);
3365 return bgp_vty_return(vty, ret);
3366 }
3367
3368
3369 DEFUN (neighbor_solo,
3370 neighbor_solo_cmd,
3371 "neighbor <A.B.C.D|X:X::X:X|WORD> solo",
3372 NEIGHBOR_STR
3373 NEIGHBOR_ADDR_STR2
3374 "Solo peer - part of its own update group\n")
3375 {
3376 int idx_peer = 1;
3377 struct peer *peer;
3378 int ret;
3379
3380 peer = peer_and_group_lookup_vty(vty, argv[idx_peer]->arg);
3381 if (!peer)
3382 return CMD_WARNING_CONFIG_FAILED;
3383
3384 ret = update_group_adjust_soloness(peer, 1);
3385 return bgp_vty_return(vty, ret);
3386 }
3387
3388 DEFUN (no_neighbor_solo,
3389 no_neighbor_solo_cmd,
3390 "no neighbor <A.B.C.D|X:X::X:X|WORD> solo",
3391 NO_STR
3392 NEIGHBOR_STR
3393 NEIGHBOR_ADDR_STR2
3394 "Solo peer - part of its own update group\n")
3395 {
3396 int idx_peer = 2;
3397 struct peer *peer;
3398 int ret;
3399
3400 peer = peer_and_group_lookup_vty(vty, argv[idx_peer]->arg);
3401 if (!peer)
3402 return CMD_WARNING_CONFIG_FAILED;
3403
3404 ret = update_group_adjust_soloness(peer, 0);
3405 return bgp_vty_return(vty, ret);
3406 }
3407
3408 DEFUN (neighbor_password,
3409 neighbor_password_cmd,
3410 "neighbor <A.B.C.D|X:X::X:X|WORD> password LINE",
3411 NEIGHBOR_STR
3412 NEIGHBOR_ADDR_STR2
3413 "Set a password\n"
3414 "The password\n")
3415 {
3416 int idx_peer = 1;
3417 int idx_line = 3;
3418 struct peer *peer;
3419 int ret;
3420
3421 peer = peer_and_group_lookup_vty(vty, argv[idx_peer]->arg);
3422 if (!peer)
3423 return CMD_WARNING_CONFIG_FAILED;
3424
3425 ret = peer_password_set(peer, argv[idx_line]->arg);
3426 return bgp_vty_return(vty, ret);
3427 }
3428
3429 DEFUN (no_neighbor_password,
3430 no_neighbor_password_cmd,
3431 "no neighbor <A.B.C.D|X:X::X:X|WORD> password [LINE]",
3432 NO_STR
3433 NEIGHBOR_STR
3434 NEIGHBOR_ADDR_STR2
3435 "Set a password\n"
3436 "The password\n")
3437 {
3438 int idx_peer = 2;
3439 struct peer *peer;
3440 int ret;
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_password_unset(peer);
3447 return bgp_vty_return(vty, ret);
3448 }
3449
3450 DEFUN (neighbor_activate,
3451 neighbor_activate_cmd,
3452 "neighbor <A.B.C.D|X:X::X:X|WORD> activate",
3453 NEIGHBOR_STR
3454 NEIGHBOR_ADDR_STR2
3455 "Enable the Address Family for this Neighbor\n")
3456 {
3457 int idx_peer = 1;
3458 int ret;
3459 struct peer *peer;
3460
3461 peer = peer_and_group_lookup_vty(vty, argv[idx_peer]->arg);
3462 if (!peer)
3463 return CMD_WARNING_CONFIG_FAILED;
3464
3465 ret = peer_activate(peer, bgp_node_afi(vty), bgp_node_safi(vty));
3466 return bgp_vty_return(vty, ret);
3467 }
3468
3469 ALIAS_HIDDEN(neighbor_activate, neighbor_activate_hidden_cmd,
3470 "neighbor <A.B.C.D|X:X::X:X|WORD> activate",
3471 NEIGHBOR_STR NEIGHBOR_ADDR_STR2
3472 "Enable the Address Family for this Neighbor\n")
3473
3474 DEFUN (no_neighbor_activate,
3475 no_neighbor_activate_cmd,
3476 "no neighbor <A.B.C.D|X:X::X:X|WORD> activate",
3477 NO_STR
3478 NEIGHBOR_STR
3479 NEIGHBOR_ADDR_STR2
3480 "Enable the Address Family for this Neighbor\n")
3481 {
3482 int idx_peer = 2;
3483 int ret;
3484 struct peer *peer;
3485
3486 /* Lookup peer. */
3487 peer = peer_and_group_lookup_vty(vty, argv[idx_peer]->arg);
3488 if (!peer)
3489 return CMD_WARNING_CONFIG_FAILED;
3490
3491 ret = peer_deactivate(peer, bgp_node_afi(vty), bgp_node_safi(vty));
3492 return bgp_vty_return(vty, ret);
3493 }
3494
3495 ALIAS_HIDDEN(no_neighbor_activate, no_neighbor_activate_hidden_cmd,
3496 "no neighbor <A.B.C.D|X:X::X:X|WORD> activate",
3497 NO_STR NEIGHBOR_STR NEIGHBOR_ADDR_STR2
3498 "Enable the Address Family for this Neighbor\n")
3499
3500 DEFUN (neighbor_set_peer_group,
3501 neighbor_set_peer_group_cmd,
3502 "neighbor <A.B.C.D|X:X::X:X|WORD> peer-group WORD",
3503 NEIGHBOR_STR
3504 NEIGHBOR_ADDR_STR2
3505 "Member of the peer-group\n"
3506 "Peer-group name\n")
3507 {
3508 VTY_DECLVAR_CONTEXT(bgp, bgp);
3509 int idx_peer = 1;
3510 int idx_word = 3;
3511 int ret;
3512 as_t as;
3513 union sockunion su;
3514 struct peer *peer;
3515 struct peer_group *group;
3516
3517 ret = str2sockunion(argv[idx_peer]->arg, &su);
3518 if (ret < 0) {
3519 peer = peer_lookup_by_conf_if(bgp, argv[idx_peer]->arg);
3520 if (!peer) {
3521 vty_out(vty, "%% Malformed address or name: %s\n",
3522 argv[idx_peer]->arg);
3523 return CMD_WARNING_CONFIG_FAILED;
3524 }
3525 } else {
3526 if (peer_address_self_check(bgp, &su)) {
3527 vty_out(vty,
3528 "%% Can not configure the local system as neighbor\n");
3529 return CMD_WARNING_CONFIG_FAILED;
3530 }
3531
3532 /* Disallow for dynamic neighbor. */
3533 peer = peer_lookup(bgp, &su);
3534 if (peer && peer_dynamic_neighbor(peer)) {
3535 vty_out(vty,
3536 "%% Operation not allowed on a dynamic neighbor\n");
3537 return CMD_WARNING_CONFIG_FAILED;
3538 }
3539 }
3540
3541 group = peer_group_lookup(bgp, argv[idx_word]->arg);
3542 if (!group) {
3543 vty_out(vty, "%% Configure the peer-group first\n");
3544 return CMD_WARNING_CONFIG_FAILED;
3545 }
3546
3547 ret = peer_group_bind(bgp, &su, peer, group, &as);
3548
3549 if (ret == BGP_ERR_PEER_GROUP_PEER_TYPE_DIFFERENT) {
3550 vty_out(vty,
3551 "%% Peer with AS %u cannot be in this peer-group, members must be all internal or all external\n",
3552 as);
3553 return CMD_WARNING_CONFIG_FAILED;
3554 }
3555
3556 return bgp_vty_return(vty, ret);
3557 }
3558
3559 ALIAS_HIDDEN(neighbor_set_peer_group, neighbor_set_peer_group_hidden_cmd,
3560 "neighbor <A.B.C.D|X:X::X:X|WORD> peer-group WORD",
3561 NEIGHBOR_STR NEIGHBOR_ADDR_STR2
3562 "Member of the peer-group\n"
3563 "Peer-group name\n")
3564
3565 DEFUN (no_neighbor_set_peer_group,
3566 no_neighbor_set_peer_group_cmd,
3567 "no neighbor <A.B.C.D|X:X::X:X|WORD> peer-group WORD",
3568 NO_STR
3569 NEIGHBOR_STR
3570 NEIGHBOR_ADDR_STR2
3571 "Member of the peer-group\n"
3572 "Peer-group name\n")
3573 {
3574 VTY_DECLVAR_CONTEXT(bgp, bgp);
3575 int idx_peer = 2;
3576 int idx_word = 4;
3577 int ret;
3578 struct peer *peer;
3579 struct peer_group *group;
3580
3581 peer = peer_lookup_vty(vty, argv[idx_peer]->arg);
3582 if (!peer)
3583 return CMD_WARNING_CONFIG_FAILED;
3584
3585 group = peer_group_lookup(bgp, argv[idx_word]->arg);
3586 if (!group) {
3587 vty_out(vty, "%% Configure the peer-group first\n");
3588 return CMD_WARNING_CONFIG_FAILED;
3589 }
3590
3591 ret = peer_delete(peer);
3592
3593 return bgp_vty_return(vty, ret);
3594 }
3595
3596 ALIAS_HIDDEN(no_neighbor_set_peer_group, no_neighbor_set_peer_group_hidden_cmd,
3597 "no neighbor <A.B.C.D|X:X::X:X|WORD> peer-group WORD",
3598 NO_STR NEIGHBOR_STR NEIGHBOR_ADDR_STR2
3599 "Member of the peer-group\n"
3600 "Peer-group name\n")
3601
3602 static int peer_flag_modify_vty(struct vty *vty, const char *ip_str,
3603 uint32_t flag, int set)
3604 {
3605 int ret;
3606 struct peer *peer;
3607
3608 peer = peer_and_group_lookup_vty(vty, ip_str);
3609 if (!peer)
3610 return CMD_WARNING_CONFIG_FAILED;
3611
3612 /*
3613 * If 'neighbor <interface>', then this is for directly connected peers,
3614 * we should not accept disable-connected-check.
3615 */
3616 if (peer->conf_if && (flag == PEER_FLAG_DISABLE_CONNECTED_CHECK)) {
3617 vty_out(vty,
3618 "%s is directly connected peer, cannot accept disable-"
3619 "connected-check\n",
3620 ip_str);
3621 return CMD_WARNING_CONFIG_FAILED;
3622 }
3623
3624 if (!set && flag == PEER_FLAG_SHUTDOWN)
3625 peer_tx_shutdown_message_unset(peer);
3626
3627 if (set)
3628 ret = peer_flag_set(peer, flag);
3629 else
3630 ret = peer_flag_unset(peer, flag);
3631
3632 return bgp_vty_return(vty, ret);
3633 }
3634
3635 static int peer_flag_set_vty(struct vty *vty, const char *ip_str, uint32_t flag)
3636 {
3637 return peer_flag_modify_vty(vty, ip_str, flag, 1);
3638 }
3639
3640 static int peer_flag_unset_vty(struct vty *vty, const char *ip_str,
3641 uint32_t flag)
3642 {
3643 return peer_flag_modify_vty(vty, ip_str, flag, 0);
3644 }
3645
3646 /* neighbor passive. */
3647 DEFUN (neighbor_passive,
3648 neighbor_passive_cmd,
3649 "neighbor <A.B.C.D|X:X::X:X|WORD> passive",
3650 NEIGHBOR_STR
3651 NEIGHBOR_ADDR_STR2
3652 "Don't send open messages to this neighbor\n")
3653 {
3654 int idx_peer = 1;
3655 return peer_flag_set_vty(vty, argv[idx_peer]->arg, PEER_FLAG_PASSIVE);
3656 }
3657
3658 DEFUN (no_neighbor_passive,
3659 no_neighbor_passive_cmd,
3660 "no neighbor <A.B.C.D|X:X::X:X|WORD> passive",
3661 NO_STR
3662 NEIGHBOR_STR
3663 NEIGHBOR_ADDR_STR2
3664 "Don't send open messages to this neighbor\n")
3665 {
3666 int idx_peer = 2;
3667 return peer_flag_unset_vty(vty, argv[idx_peer]->arg, PEER_FLAG_PASSIVE);
3668 }
3669
3670 /* neighbor shutdown. */
3671 DEFUN (neighbor_shutdown_msg,
3672 neighbor_shutdown_msg_cmd,
3673 "neighbor <A.B.C.D|X:X::X:X|WORD> shutdown message MSG...",
3674 NEIGHBOR_STR
3675 NEIGHBOR_ADDR_STR2
3676 "Administratively shut down this neighbor\n"
3677 "Add a shutdown message (draft-ietf-idr-shutdown-06)\n"
3678 "Shutdown message\n")
3679 {
3680 int idx_peer = 1;
3681
3682 if (argc >= 5) {
3683 struct peer *peer =
3684 peer_and_group_lookup_vty(vty, argv[idx_peer]->arg);
3685 char *message;
3686
3687 if (!peer)
3688 return CMD_WARNING_CONFIG_FAILED;
3689 message = argv_concat(argv, argc, 4);
3690 peer_tx_shutdown_message_set(peer, message);
3691 XFREE(MTYPE_TMP, message);
3692 }
3693
3694 return peer_flag_set_vty(vty, argv[idx_peer]->arg, PEER_FLAG_SHUTDOWN);
3695 }
3696
3697 ALIAS(neighbor_shutdown_msg, neighbor_shutdown_cmd,
3698 "neighbor <A.B.C.D|X:X::X:X|WORD> shutdown",
3699 NEIGHBOR_STR NEIGHBOR_ADDR_STR2
3700 "Administratively shut down this neighbor\n")
3701
3702 DEFUN (no_neighbor_shutdown_msg,
3703 no_neighbor_shutdown_msg_cmd,
3704 "no neighbor <A.B.C.D|X:X::X:X|WORD> shutdown message MSG...",
3705 NO_STR
3706 NEIGHBOR_STR
3707 NEIGHBOR_ADDR_STR2
3708 "Administratively shut down this neighbor\n"
3709 "Remove a shutdown message (draft-ietf-idr-shutdown-06)\n"
3710 "Shutdown message\n")
3711 {
3712 int idx_peer = 2;
3713
3714 return peer_flag_unset_vty(vty, argv[idx_peer]->arg,
3715 PEER_FLAG_SHUTDOWN);
3716 }
3717
3718 ALIAS(no_neighbor_shutdown_msg, no_neighbor_shutdown_cmd,
3719 "no neighbor <A.B.C.D|X:X::X:X|WORD> shutdown",
3720 NO_STR NEIGHBOR_STR NEIGHBOR_ADDR_STR2
3721 "Administratively shut down this neighbor\n")
3722
3723 /* neighbor capability dynamic. */
3724 DEFUN (neighbor_capability_dynamic,
3725 neighbor_capability_dynamic_cmd,
3726 "neighbor <A.B.C.D|X:X::X:X|WORD> capability dynamic",
3727 NEIGHBOR_STR
3728 NEIGHBOR_ADDR_STR2
3729 "Advertise capability to the peer\n"
3730 "Advertise dynamic capability to this neighbor\n")
3731 {
3732 int idx_peer = 1;
3733 return peer_flag_set_vty(vty, argv[idx_peer]->arg,
3734 PEER_FLAG_DYNAMIC_CAPABILITY);
3735 }
3736
3737 DEFUN (no_neighbor_capability_dynamic,
3738 no_neighbor_capability_dynamic_cmd,
3739 "no neighbor <A.B.C.D|X:X::X:X|WORD> capability dynamic",
3740 NO_STR
3741 NEIGHBOR_STR
3742 NEIGHBOR_ADDR_STR2
3743 "Advertise capability to the peer\n"
3744 "Advertise dynamic capability to this neighbor\n")
3745 {
3746 int idx_peer = 2;
3747 return peer_flag_unset_vty(vty, argv[idx_peer]->arg,
3748 PEER_FLAG_DYNAMIC_CAPABILITY);
3749 }
3750
3751 /* neighbor dont-capability-negotiate */
3752 DEFUN (neighbor_dont_capability_negotiate,
3753 neighbor_dont_capability_negotiate_cmd,
3754 "neighbor <A.B.C.D|X:X::X:X|WORD> dont-capability-negotiate",
3755 NEIGHBOR_STR
3756 NEIGHBOR_ADDR_STR2
3757 "Do not perform capability negotiation\n")
3758 {
3759 int idx_peer = 1;
3760 return peer_flag_set_vty(vty, argv[idx_peer]->arg,
3761 PEER_FLAG_DONT_CAPABILITY);
3762 }
3763
3764 DEFUN (no_neighbor_dont_capability_negotiate,
3765 no_neighbor_dont_capability_negotiate_cmd,
3766 "no neighbor <A.B.C.D|X:X::X:X|WORD> dont-capability-negotiate",
3767 NO_STR
3768 NEIGHBOR_STR
3769 NEIGHBOR_ADDR_STR2
3770 "Do not perform capability negotiation\n")
3771 {
3772 int idx_peer = 2;
3773 return peer_flag_unset_vty(vty, argv[idx_peer]->arg,
3774 PEER_FLAG_DONT_CAPABILITY);
3775 }
3776
3777 /* neighbor capability extended next hop encoding */
3778 DEFUN (neighbor_capability_enhe,
3779 neighbor_capability_enhe_cmd,
3780 "neighbor <A.B.C.D|X:X::X:X|WORD> capability extended-nexthop",
3781 NEIGHBOR_STR
3782 NEIGHBOR_ADDR_STR2
3783 "Advertise capability to the peer\n"
3784 "Advertise extended next-hop capability to the peer\n")
3785 {
3786 int idx_peer = 1;
3787 return peer_flag_set_vty(vty, argv[idx_peer]->arg,
3788 PEER_FLAG_CAPABILITY_ENHE);
3789 }
3790
3791 DEFUN (no_neighbor_capability_enhe,
3792 no_neighbor_capability_enhe_cmd,
3793 "no neighbor <A.B.C.D|X:X::X:X|WORD> capability extended-nexthop",
3794 NO_STR
3795 NEIGHBOR_STR
3796 NEIGHBOR_ADDR_STR2
3797 "Advertise capability to the peer\n"
3798 "Advertise extended next-hop capability to the peer\n")
3799 {
3800 int idx_peer = 2;
3801 return peer_flag_unset_vty(vty, argv[idx_peer]->arg,
3802 PEER_FLAG_CAPABILITY_ENHE);
3803 }
3804
3805 static int peer_af_flag_modify_vty(struct vty *vty, const char *peer_str,
3806 afi_t afi, safi_t safi, uint32_t flag,
3807 int set)
3808 {
3809 int ret;
3810 struct peer *peer;
3811
3812 peer = peer_and_group_lookup_vty(vty, peer_str);
3813 if (!peer)
3814 return CMD_WARNING_CONFIG_FAILED;
3815
3816 if (set)
3817 ret = peer_af_flag_set(peer, afi, safi, flag);
3818 else
3819 ret = peer_af_flag_unset(peer, afi, safi, flag);
3820
3821 return bgp_vty_return(vty, ret);
3822 }
3823
3824 static int peer_af_flag_set_vty(struct vty *vty, const char *peer_str,
3825 afi_t afi, safi_t safi, uint32_t flag)
3826 {
3827 return peer_af_flag_modify_vty(vty, peer_str, afi, safi, flag, 1);
3828 }
3829
3830 static int peer_af_flag_unset_vty(struct vty *vty, const char *peer_str,
3831 afi_t afi, safi_t safi, uint32_t flag)
3832 {
3833 return peer_af_flag_modify_vty(vty, peer_str, afi, safi, flag, 0);
3834 }
3835
3836 /* neighbor capability orf prefix-list. */
3837 DEFUN (neighbor_capability_orf_prefix,
3838 neighbor_capability_orf_prefix_cmd,
3839 "neighbor <A.B.C.D|X:X::X:X|WORD> capability orf prefix-list <both|send|receive>",
3840 NEIGHBOR_STR
3841 NEIGHBOR_ADDR_STR2
3842 "Advertise capability to the peer\n"
3843 "Advertise ORF capability to the peer\n"
3844 "Advertise prefixlist ORF capability to this neighbor\n"
3845 "Capability to SEND and RECEIVE the ORF to/from this neighbor\n"
3846 "Capability to RECEIVE the ORF from this neighbor\n"
3847 "Capability to SEND the ORF to this neighbor\n")
3848 {
3849 int idx_peer = 1;
3850 int idx_send_recv = 5;
3851 uint16_t flag = 0;
3852
3853 if (strmatch(argv[idx_send_recv]->text, "send"))
3854 flag = PEER_FLAG_ORF_PREFIX_SM;
3855 else if (strmatch(argv[idx_send_recv]->text, "receive"))
3856 flag = PEER_FLAG_ORF_PREFIX_RM;
3857 else if (strmatch(argv[idx_send_recv]->text, "both"))
3858 flag = PEER_FLAG_ORF_PREFIX_SM | PEER_FLAG_ORF_PREFIX_RM;
3859 else {
3860 vty_out(vty, "%% BGP invalid orf prefix-list option\n");
3861 return CMD_WARNING_CONFIG_FAILED;
3862 }
3863
3864 return peer_af_flag_set_vty(vty, argv[idx_peer]->arg, bgp_node_afi(vty),
3865 bgp_node_safi(vty), flag);
3866 }
3867
3868 ALIAS_HIDDEN(
3869 neighbor_capability_orf_prefix,
3870 neighbor_capability_orf_prefix_hidden_cmd,
3871 "neighbor <A.B.C.D|X:X::X:X|WORD> capability orf prefix-list <both|send|receive>",
3872 NEIGHBOR_STR NEIGHBOR_ADDR_STR2
3873 "Advertise capability to the peer\n"
3874 "Advertise ORF capability to the peer\n"
3875 "Advertise prefixlist ORF capability to this neighbor\n"
3876 "Capability to SEND and RECEIVE the ORF to/from this neighbor\n"
3877 "Capability to RECEIVE the ORF from this neighbor\n"
3878 "Capability to SEND the ORF to this neighbor\n")
3879
3880 DEFUN (no_neighbor_capability_orf_prefix,
3881 no_neighbor_capability_orf_prefix_cmd,
3882 "no neighbor <A.B.C.D|X:X::X:X|WORD> capability orf prefix-list <both|send|receive>",
3883 NO_STR
3884 NEIGHBOR_STR
3885 NEIGHBOR_ADDR_STR2
3886 "Advertise capability to the peer\n"
3887 "Advertise ORF capability to the peer\n"
3888 "Advertise prefixlist ORF capability to this neighbor\n"
3889 "Capability to SEND and RECEIVE the ORF to/from this neighbor\n"
3890 "Capability to RECEIVE the ORF from this neighbor\n"
3891 "Capability to SEND the ORF to this neighbor\n")
3892 {
3893 int idx_peer = 2;
3894 int idx_send_recv = 6;
3895 uint16_t flag = 0;
3896
3897 if (strmatch(argv[idx_send_recv]->text, "send"))
3898 flag = PEER_FLAG_ORF_PREFIX_SM;
3899 else if (strmatch(argv[idx_send_recv]->text, "receive"))
3900 flag = PEER_FLAG_ORF_PREFIX_RM;
3901 else if (strmatch(argv[idx_send_recv]->text, "both"))
3902 flag = PEER_FLAG_ORF_PREFIX_SM | PEER_FLAG_ORF_PREFIX_RM;
3903 else {
3904 vty_out(vty, "%% BGP invalid orf prefix-list option\n");
3905 return CMD_WARNING_CONFIG_FAILED;
3906 }
3907
3908 return peer_af_flag_unset_vty(vty, argv[idx_peer]->arg,
3909 bgp_node_afi(vty), bgp_node_safi(vty),
3910 flag);
3911 }
3912
3913 ALIAS_HIDDEN(
3914 no_neighbor_capability_orf_prefix,
3915 no_neighbor_capability_orf_prefix_hidden_cmd,
3916 "no neighbor <A.B.C.D|X:X::X:X|WORD> capability orf prefix-list <both|send|receive>",
3917 NO_STR NEIGHBOR_STR NEIGHBOR_ADDR_STR2
3918 "Advertise capability to the peer\n"
3919 "Advertise ORF capability to the peer\n"
3920 "Advertise prefixlist ORF capability to this neighbor\n"
3921 "Capability to SEND and RECEIVE the ORF to/from this neighbor\n"
3922 "Capability to RECEIVE the ORF from this neighbor\n"
3923 "Capability to SEND the ORF to this neighbor\n")
3924
3925 /* neighbor next-hop-self. */
3926 DEFUN (neighbor_nexthop_self,
3927 neighbor_nexthop_self_cmd,
3928 "neighbor <A.B.C.D|X:X::X:X|WORD> next-hop-self",
3929 NEIGHBOR_STR
3930 NEIGHBOR_ADDR_STR2
3931 "Disable the next hop calculation for this neighbor\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), PEER_FLAG_NEXTHOP_SELF);
3936 }
3937
3938 ALIAS_HIDDEN(neighbor_nexthop_self, neighbor_nexthop_self_hidden_cmd,
3939 "neighbor <A.B.C.D|X:X::X:X|WORD> next-hop-self",
3940 NEIGHBOR_STR NEIGHBOR_ADDR_STR2
3941 "Disable the next hop calculation for this neighbor\n")
3942
3943 /* neighbor next-hop-self. */
3944 DEFUN (neighbor_nexthop_self_force,
3945 neighbor_nexthop_self_force_cmd,
3946 "neighbor <A.B.C.D|X:X::X:X|WORD> next-hop-self force",
3947 NEIGHBOR_STR
3948 NEIGHBOR_ADDR_STR2
3949 "Disable the next hop calculation for this neighbor\n"
3950 "Set the next hop to self for reflected routes\n")
3951 {
3952 int idx_peer = 1;
3953 return peer_af_flag_set_vty(vty, argv[idx_peer]->arg, bgp_node_afi(vty),
3954 bgp_node_safi(vty),
3955 PEER_FLAG_FORCE_NEXTHOP_SELF);
3956 }
3957
3958 ALIAS_HIDDEN(neighbor_nexthop_self_force,
3959 neighbor_nexthop_self_force_hidden_cmd,
3960 "neighbor <A.B.C.D|X:X::X:X|WORD> next-hop-self force",
3961 NEIGHBOR_STR NEIGHBOR_ADDR_STR2
3962 "Disable the next hop calculation for this neighbor\n"
3963 "Set the next hop to self for reflected routes\n")
3964
3965 DEFUN (no_neighbor_nexthop_self,
3966 no_neighbor_nexthop_self_cmd,
3967 "no neighbor <A.B.C.D|X:X::X:X|WORD> next-hop-self",
3968 NO_STR
3969 NEIGHBOR_STR
3970 NEIGHBOR_ADDR_STR2
3971 "Disable the next hop calculation for this neighbor\n")
3972 {
3973 int idx_peer = 2;
3974 return peer_af_flag_unset_vty(vty, argv[idx_peer]->arg,
3975 bgp_node_afi(vty), bgp_node_safi(vty),
3976 PEER_FLAG_NEXTHOP_SELF);
3977 }
3978
3979 ALIAS_HIDDEN(no_neighbor_nexthop_self, no_neighbor_nexthop_self_hidden_cmd,
3980 "no neighbor <A.B.C.D|X:X::X:X|WORD> next-hop-self",
3981 NO_STR NEIGHBOR_STR NEIGHBOR_ADDR_STR2
3982 "Disable the next hop calculation for this neighbor\n")
3983
3984 DEFUN (no_neighbor_nexthop_self_force,
3985 no_neighbor_nexthop_self_force_cmd,
3986 "no neighbor <A.B.C.D|X:X::X:X|WORD> next-hop-self force",
3987 NO_STR
3988 NEIGHBOR_STR
3989 NEIGHBOR_ADDR_STR2
3990 "Disable the next hop calculation for this neighbor\n"
3991 "Set the next hop to self for reflected routes\n")
3992 {
3993 int idx_peer = 2;
3994 return peer_af_flag_unset_vty(vty, argv[idx_peer]->arg,
3995 bgp_node_afi(vty), bgp_node_safi(vty),
3996 PEER_FLAG_FORCE_NEXTHOP_SELF);
3997 }
3998
3999 ALIAS_HIDDEN(no_neighbor_nexthop_self_force,
4000 no_neighbor_nexthop_self_force_hidden_cmd,
4001 "no neighbor <A.B.C.D|X:X::X:X|WORD> next-hop-self force",
4002 NO_STR NEIGHBOR_STR NEIGHBOR_ADDR_STR2
4003 "Disable the next hop calculation for this neighbor\n"
4004 "Set the next hop to self for reflected routes\n")
4005
4006 /* neighbor as-override */
4007 DEFUN (neighbor_as_override,
4008 neighbor_as_override_cmd,
4009 "neighbor <A.B.C.D|X:X::X:X|WORD> as-override",
4010 NEIGHBOR_STR
4011 NEIGHBOR_ADDR_STR2
4012 "Override ASNs in outbound updates if aspath equals remote-as\n")
4013 {
4014 int idx_peer = 1;
4015 return peer_af_flag_set_vty(vty, argv[idx_peer]->arg, bgp_node_afi(vty),
4016 bgp_node_safi(vty), PEER_FLAG_AS_OVERRIDE);
4017 }
4018
4019 ALIAS_HIDDEN(neighbor_as_override, neighbor_as_override_hidden_cmd,
4020 "neighbor <A.B.C.D|X:X::X:X|WORD> as-override",
4021 NEIGHBOR_STR NEIGHBOR_ADDR_STR2
4022 "Override ASNs in outbound updates if aspath equals remote-as\n")
4023
4024 DEFUN (no_neighbor_as_override,
4025 no_neighbor_as_override_cmd,
4026 "no neighbor <A.B.C.D|X:X::X:X|WORD> as-override",
4027 NO_STR
4028 NEIGHBOR_STR
4029 NEIGHBOR_ADDR_STR2
4030 "Override ASNs in outbound updates if aspath equals remote-as\n")
4031 {
4032 int idx_peer = 2;
4033 return peer_af_flag_unset_vty(vty, argv[idx_peer]->arg,
4034 bgp_node_afi(vty), bgp_node_safi(vty),
4035 PEER_FLAG_AS_OVERRIDE);
4036 }
4037
4038 ALIAS_HIDDEN(no_neighbor_as_override, no_neighbor_as_override_hidden_cmd,
4039 "no neighbor <A.B.C.D|X:X::X:X|WORD> as-override",
4040 NO_STR NEIGHBOR_STR NEIGHBOR_ADDR_STR2
4041 "Override ASNs in outbound updates if aspath equals remote-as\n")
4042
4043 /* neighbor remove-private-AS. */
4044 DEFUN (neighbor_remove_private_as,
4045 neighbor_remove_private_as_cmd,
4046 "neighbor <A.B.C.D|X:X::X:X|WORD> remove-private-AS",
4047 NEIGHBOR_STR
4048 NEIGHBOR_ADDR_STR2
4049 "Remove private ASNs in outbound updates\n")
4050 {
4051 int idx_peer = 1;
4052 return peer_af_flag_set_vty(vty, argv[idx_peer]->arg, bgp_node_afi(vty),
4053 bgp_node_safi(vty),
4054 PEER_FLAG_REMOVE_PRIVATE_AS);
4055 }
4056
4057 ALIAS_HIDDEN(neighbor_remove_private_as, neighbor_remove_private_as_hidden_cmd,
4058 "neighbor <A.B.C.D|X:X::X:X|WORD> remove-private-AS",
4059 NEIGHBOR_STR NEIGHBOR_ADDR_STR2
4060 "Remove private ASNs in outbound updates\n")
4061
4062 DEFUN (neighbor_remove_private_as_all,
4063 neighbor_remove_private_as_all_cmd,
4064 "neighbor <A.B.C.D|X:X::X:X|WORD> remove-private-AS all",
4065 NEIGHBOR_STR
4066 NEIGHBOR_ADDR_STR2
4067 "Remove private ASNs in outbound updates\n"
4068 "Apply to all AS numbers\n")
4069 {
4070 int idx_peer = 1;
4071 return peer_af_flag_set_vty(vty, argv[idx_peer]->arg, bgp_node_afi(vty),
4072 bgp_node_safi(vty),
4073 PEER_FLAG_REMOVE_PRIVATE_AS_ALL);
4074 }
4075
4076 ALIAS_HIDDEN(neighbor_remove_private_as_all,
4077 neighbor_remove_private_as_all_hidden_cmd,
4078 "neighbor <A.B.C.D|X:X::X:X|WORD> remove-private-AS all",
4079 NEIGHBOR_STR NEIGHBOR_ADDR_STR2
4080 "Remove private ASNs in outbound updates\n"
4081 "Apply to all AS numbers")
4082
4083 DEFUN (neighbor_remove_private_as_replace_as,
4084 neighbor_remove_private_as_replace_as_cmd,
4085 "neighbor <A.B.C.D|X:X::X:X|WORD> remove-private-AS replace-AS",
4086 NEIGHBOR_STR
4087 NEIGHBOR_ADDR_STR2
4088 "Remove private ASNs in outbound updates\n"
4089 "Replace private ASNs with our ASN in outbound updates\n")
4090 {
4091 int idx_peer = 1;
4092 return peer_af_flag_set_vty(vty, argv[idx_peer]->arg, bgp_node_afi(vty),
4093 bgp_node_safi(vty),
4094 PEER_FLAG_REMOVE_PRIVATE_AS_REPLACE);
4095 }
4096
4097 ALIAS_HIDDEN(neighbor_remove_private_as_replace_as,
4098 neighbor_remove_private_as_replace_as_hidden_cmd,
4099 "neighbor <A.B.C.D|X:X::X:X|WORD> remove-private-AS replace-AS",
4100 NEIGHBOR_STR NEIGHBOR_ADDR_STR2
4101 "Remove private ASNs in outbound updates\n"
4102 "Replace private ASNs with our ASN in outbound updates\n")
4103
4104 DEFUN (neighbor_remove_private_as_all_replace_as,
4105 neighbor_remove_private_as_all_replace_as_cmd,
4106 "neighbor <A.B.C.D|X:X::X:X|WORD> remove-private-AS all replace-AS",
4107 NEIGHBOR_STR
4108 NEIGHBOR_ADDR_STR2
4109 "Remove private ASNs in outbound updates\n"
4110 "Apply to all AS numbers\n"
4111 "Replace private ASNs with our ASN in outbound updates\n")
4112 {
4113 int idx_peer = 1;
4114 return peer_af_flag_set_vty(vty, argv[idx_peer]->arg, bgp_node_afi(vty),
4115 bgp_node_safi(vty),
4116 PEER_FLAG_REMOVE_PRIVATE_AS_ALL_REPLACE);
4117 }
4118
4119 ALIAS_HIDDEN(
4120 neighbor_remove_private_as_all_replace_as,
4121 neighbor_remove_private_as_all_replace_as_hidden_cmd,
4122 "neighbor <A.B.C.D|X:X::X:X|WORD> remove-private-AS all replace-AS",
4123 NEIGHBOR_STR NEIGHBOR_ADDR_STR2
4124 "Remove private ASNs in outbound updates\n"
4125 "Apply to all AS numbers\n"
4126 "Replace private ASNs with our ASN in outbound updates\n")
4127
4128 DEFUN (no_neighbor_remove_private_as,
4129 no_neighbor_remove_private_as_cmd,
4130 "no neighbor <A.B.C.D|X:X::X:X|WORD> remove-private-AS",
4131 NO_STR
4132 NEIGHBOR_STR
4133 NEIGHBOR_ADDR_STR2
4134 "Remove private ASNs in outbound updates\n")
4135 {
4136 int idx_peer = 2;
4137 return peer_af_flag_unset_vty(vty, argv[idx_peer]->arg,
4138 bgp_node_afi(vty), bgp_node_safi(vty),
4139 PEER_FLAG_REMOVE_PRIVATE_AS);
4140 }
4141
4142 ALIAS_HIDDEN(no_neighbor_remove_private_as,
4143 no_neighbor_remove_private_as_hidden_cmd,
4144 "no neighbor <A.B.C.D|X:X::X:X|WORD> remove-private-AS",
4145 NO_STR NEIGHBOR_STR NEIGHBOR_ADDR_STR2
4146 "Remove private ASNs in outbound updates\n")
4147
4148 DEFUN (no_neighbor_remove_private_as_all,
4149 no_neighbor_remove_private_as_all_cmd,
4150 "no neighbor <A.B.C.D|X:X::X:X|WORD> remove-private-AS all",
4151 NO_STR
4152 NEIGHBOR_STR
4153 NEIGHBOR_ADDR_STR2
4154 "Remove private ASNs in outbound updates\n"
4155 "Apply to all AS numbers\n")
4156 {
4157 int idx_peer = 2;
4158 return peer_af_flag_unset_vty(vty, argv[idx_peer]->arg,
4159 bgp_node_afi(vty), bgp_node_safi(vty),
4160 PEER_FLAG_REMOVE_PRIVATE_AS_ALL);
4161 }
4162
4163 ALIAS_HIDDEN(no_neighbor_remove_private_as_all,
4164 no_neighbor_remove_private_as_all_hidden_cmd,
4165 "no neighbor <A.B.C.D|X:X::X:X|WORD> remove-private-AS all",
4166 NO_STR NEIGHBOR_STR NEIGHBOR_ADDR_STR2
4167 "Remove private ASNs in outbound updates\n"
4168 "Apply to all AS numbers\n")
4169
4170 DEFUN (no_neighbor_remove_private_as_replace_as,
4171 no_neighbor_remove_private_as_replace_as_cmd,
4172 "no neighbor <A.B.C.D|X:X::X:X|WORD> remove-private-AS replace-AS",
4173 NO_STR
4174 NEIGHBOR_STR
4175 NEIGHBOR_ADDR_STR2
4176 "Remove private ASNs in outbound updates\n"
4177 "Replace private ASNs with our ASN in outbound updates\n")
4178 {
4179 int idx_peer = 2;
4180 return peer_af_flag_unset_vty(vty, argv[idx_peer]->arg,
4181 bgp_node_afi(vty), bgp_node_safi(vty),
4182 PEER_FLAG_REMOVE_PRIVATE_AS_REPLACE);
4183 }
4184
4185 ALIAS_HIDDEN(no_neighbor_remove_private_as_replace_as,
4186 no_neighbor_remove_private_as_replace_as_hidden_cmd,
4187 "no neighbor <A.B.C.D|X:X::X:X|WORD> remove-private-AS replace-AS",
4188 NO_STR NEIGHBOR_STR NEIGHBOR_ADDR_STR2
4189 "Remove private ASNs in outbound updates\n"
4190 "Replace private ASNs with our ASN in outbound updates\n")
4191
4192 DEFUN (no_neighbor_remove_private_as_all_replace_as,
4193 no_neighbor_remove_private_as_all_replace_as_cmd,
4194 "no neighbor <A.B.C.D|X:X::X:X|WORD> remove-private-AS all replace-AS",
4195 NO_STR
4196 NEIGHBOR_STR
4197 NEIGHBOR_ADDR_STR2
4198 "Remove private ASNs in outbound updates\n"
4199 "Apply to all AS numbers\n"
4200 "Replace private ASNs with our ASN in outbound updates\n")
4201 {
4202 int idx_peer = 2;
4203 return peer_af_flag_unset_vty(vty, argv[idx_peer]->arg,
4204 bgp_node_afi(vty), bgp_node_safi(vty),
4205 PEER_FLAG_REMOVE_PRIVATE_AS_ALL_REPLACE);
4206 }
4207
4208 ALIAS_HIDDEN(
4209 no_neighbor_remove_private_as_all_replace_as,
4210 no_neighbor_remove_private_as_all_replace_as_hidden_cmd,
4211 "no neighbor <A.B.C.D|X:X::X:X|WORD> remove-private-AS all replace-AS",
4212 NO_STR NEIGHBOR_STR NEIGHBOR_ADDR_STR2
4213 "Remove private ASNs in outbound updates\n"
4214 "Apply to all AS numbers\n"
4215 "Replace private ASNs with our ASN in outbound updates\n")
4216
4217
4218 /* neighbor send-community. */
4219 DEFUN (neighbor_send_community,
4220 neighbor_send_community_cmd,
4221 "neighbor <A.B.C.D|X:X::X:X|WORD> send-community",
4222 NEIGHBOR_STR
4223 NEIGHBOR_ADDR_STR2
4224 "Send Community attribute to this neighbor\n")
4225 {
4226 int idx_peer = 1;
4227
4228 return peer_af_flag_set_vty(vty, argv[idx_peer]->arg, bgp_node_afi(vty),
4229 bgp_node_safi(vty),
4230 PEER_FLAG_SEND_COMMUNITY);
4231 }
4232
4233 ALIAS_HIDDEN(neighbor_send_community, neighbor_send_community_hidden_cmd,
4234 "neighbor <A.B.C.D|X:X::X:X|WORD> send-community",
4235 NEIGHBOR_STR NEIGHBOR_ADDR_STR2
4236 "Send Community attribute to this neighbor\n")
4237
4238 DEFUN (no_neighbor_send_community,
4239 no_neighbor_send_community_cmd,
4240 "no neighbor <A.B.C.D|X:X::X:X|WORD> send-community",
4241 NO_STR
4242 NEIGHBOR_STR
4243 NEIGHBOR_ADDR_STR2
4244 "Send Community attribute to this neighbor\n")
4245 {
4246 int idx_peer = 2;
4247
4248 return peer_af_flag_unset_vty(vty, argv[idx_peer]->arg,
4249 bgp_node_afi(vty), bgp_node_safi(vty),
4250 PEER_FLAG_SEND_COMMUNITY);
4251 }
4252
4253 ALIAS_HIDDEN(no_neighbor_send_community, no_neighbor_send_community_hidden_cmd,
4254 "no neighbor <A.B.C.D|X:X::X:X|WORD> send-community",
4255 NO_STR NEIGHBOR_STR NEIGHBOR_ADDR_STR2
4256 "Send Community attribute to this neighbor\n")
4257
4258 /* neighbor send-community extended. */
4259 DEFUN (neighbor_send_community_type,
4260 neighbor_send_community_type_cmd,
4261 "neighbor <A.B.C.D|X:X::X:X|WORD> send-community <both|all|extended|standard|large>",
4262 NEIGHBOR_STR
4263 NEIGHBOR_ADDR_STR2
4264 "Send Community attribute to this neighbor\n"
4265 "Send Standard and Extended Community attributes\n"
4266 "Send Standard, Large and Extended Community attributes\n"
4267 "Send Extended Community attributes\n"
4268 "Send Standard Community attributes\n"
4269 "Send Large Community attributes\n")
4270 {
4271 int idx_peer = 1;
4272 uint32_t flag = 0;
4273 const char *type = argv[argc - 1]->text;
4274
4275 if (strmatch(type, "standard")) {
4276 SET_FLAG(flag, PEER_FLAG_SEND_COMMUNITY);
4277 } else if (strmatch(type, "extended")) {
4278 SET_FLAG(flag, PEER_FLAG_SEND_EXT_COMMUNITY);
4279 } else if (strmatch(type, "large")) {
4280 SET_FLAG(flag, PEER_FLAG_SEND_LARGE_COMMUNITY);
4281 } else if (strmatch(type, "both")) {
4282 SET_FLAG(flag, PEER_FLAG_SEND_COMMUNITY);
4283 SET_FLAG(flag, PEER_FLAG_SEND_EXT_COMMUNITY);
4284 } else { /* if (strmatch(type, "all")) */
4285 SET_FLAG(flag, PEER_FLAG_SEND_COMMUNITY);
4286 SET_FLAG(flag, PEER_FLAG_SEND_EXT_COMMUNITY);
4287 SET_FLAG(flag, PEER_FLAG_SEND_LARGE_COMMUNITY);
4288 }
4289
4290 return peer_af_flag_set_vty(vty, argv[idx_peer]->arg, bgp_node_afi(vty),
4291 bgp_node_safi(vty), flag);
4292 }
4293
4294 ALIAS_HIDDEN(
4295 neighbor_send_community_type, neighbor_send_community_type_hidden_cmd,
4296 "neighbor <A.B.C.D|X:X::X:X|WORD> send-community <both|all|extended|standard|large>",
4297 NEIGHBOR_STR NEIGHBOR_ADDR_STR2
4298 "Send Community attribute to this neighbor\n"
4299 "Send Standard and Extended Community attributes\n"
4300 "Send Standard, Large and Extended Community attributes\n"
4301 "Send Extended Community attributes\n"
4302 "Send Standard Community attributes\n"
4303 "Send Large Community attributes\n")
4304
4305 DEFUN (no_neighbor_send_community_type,
4306 no_neighbor_send_community_type_cmd,
4307 "no neighbor <A.B.C.D|X:X::X:X|WORD> send-community <both|all|extended|standard|large>",
4308 NO_STR
4309 NEIGHBOR_STR
4310 NEIGHBOR_ADDR_STR2
4311 "Send Community attribute to this neighbor\n"
4312 "Send Standard and Extended Community attributes\n"
4313 "Send Standard, Large and Extended Community attributes\n"
4314 "Send Extended Community attributes\n"
4315 "Send Standard Community attributes\n"
4316 "Send Large Community attributes\n")
4317 {
4318 int idx_peer = 2;
4319 uint32_t flag = 0;
4320 const char *type = argv[argc - 1]->text;
4321
4322 if (strmatch(type, "standard")) {
4323 SET_FLAG(flag, PEER_FLAG_SEND_COMMUNITY);
4324 } else if (strmatch(type, "extended")) {
4325 SET_FLAG(flag, PEER_FLAG_SEND_EXT_COMMUNITY);
4326 } else if (strmatch(type, "large")) {
4327 SET_FLAG(flag, PEER_FLAG_SEND_LARGE_COMMUNITY);
4328 } else if (strmatch(type, "both")) {
4329 SET_FLAG(flag, PEER_FLAG_SEND_COMMUNITY);
4330 SET_FLAG(flag, PEER_FLAG_SEND_EXT_COMMUNITY);
4331 } else { /* if (strmatch(type, "all")) */
4332 SET_FLAG(flag, PEER_FLAG_SEND_COMMUNITY);
4333 SET_FLAG(flag, PEER_FLAG_SEND_EXT_COMMUNITY);
4334 SET_FLAG(flag, PEER_FLAG_SEND_LARGE_COMMUNITY);
4335 }
4336
4337 return peer_af_flag_unset_vty(vty, argv[idx_peer]->arg,
4338 bgp_node_afi(vty), bgp_node_safi(vty),
4339 flag);
4340 }
4341
4342 ALIAS_HIDDEN(
4343 no_neighbor_send_community_type,
4344 no_neighbor_send_community_type_hidden_cmd,
4345 "no neighbor <A.B.C.D|X:X::X:X|WORD> send-community <both|all|extended|standard|large>",
4346 NO_STR NEIGHBOR_STR NEIGHBOR_ADDR_STR2
4347 "Send Community attribute to this neighbor\n"
4348 "Send Standard and Extended Community attributes\n"
4349 "Send Standard, Large and Extended Community attributes\n"
4350 "Send Extended Community attributes\n"
4351 "Send Standard Community attributes\n"
4352 "Send Large Community attributes\n")
4353
4354 /* neighbor soft-reconfig. */
4355 DEFUN (neighbor_soft_reconfiguration,
4356 neighbor_soft_reconfiguration_cmd,
4357 "neighbor <A.B.C.D|X:X::X:X|WORD> soft-reconfiguration inbound",
4358 NEIGHBOR_STR
4359 NEIGHBOR_ADDR_STR2
4360 "Per neighbor soft reconfiguration\n"
4361 "Allow inbound soft reconfiguration for this neighbor\n")
4362 {
4363 int idx_peer = 1;
4364 return peer_af_flag_set_vty(vty, argv[idx_peer]->arg, bgp_node_afi(vty),
4365 bgp_node_safi(vty),
4366 PEER_FLAG_SOFT_RECONFIG);
4367 }
4368
4369 ALIAS_HIDDEN(neighbor_soft_reconfiguration,
4370 neighbor_soft_reconfiguration_hidden_cmd,
4371 "neighbor <A.B.C.D|X:X::X:X|WORD> soft-reconfiguration inbound",
4372 NEIGHBOR_STR NEIGHBOR_ADDR_STR2
4373 "Per neighbor soft reconfiguration\n"
4374 "Allow inbound soft reconfiguration for this neighbor\n")
4375
4376 DEFUN (no_neighbor_soft_reconfiguration,
4377 no_neighbor_soft_reconfiguration_cmd,
4378 "no neighbor <A.B.C.D|X:X::X:X|WORD> soft-reconfiguration inbound",
4379 NO_STR
4380 NEIGHBOR_STR
4381 NEIGHBOR_ADDR_STR2
4382 "Per neighbor soft reconfiguration\n"
4383 "Allow inbound soft reconfiguration for this neighbor\n")
4384 {
4385 int idx_peer = 2;
4386 return peer_af_flag_unset_vty(vty, argv[idx_peer]->arg,
4387 bgp_node_afi(vty), bgp_node_safi(vty),
4388 PEER_FLAG_SOFT_RECONFIG);
4389 }
4390
4391 ALIAS_HIDDEN(no_neighbor_soft_reconfiguration,
4392 no_neighbor_soft_reconfiguration_hidden_cmd,
4393 "no neighbor <A.B.C.D|X:X::X:X|WORD> soft-reconfiguration inbound",
4394 NO_STR NEIGHBOR_STR NEIGHBOR_ADDR_STR2
4395 "Per neighbor soft reconfiguration\n"
4396 "Allow inbound soft reconfiguration for this neighbor\n")
4397
4398 DEFUN (neighbor_route_reflector_client,
4399 neighbor_route_reflector_client_cmd,
4400 "neighbor <A.B.C.D|X:X::X:X|WORD> route-reflector-client",
4401 NEIGHBOR_STR
4402 NEIGHBOR_ADDR_STR2
4403 "Configure a neighbor as Route Reflector client\n")
4404 {
4405 int idx_peer = 1;
4406 struct peer *peer;
4407
4408
4409 peer = peer_and_group_lookup_vty(vty, argv[idx_peer]->arg);
4410 if (!peer)
4411 return CMD_WARNING_CONFIG_FAILED;
4412
4413 return peer_af_flag_set_vty(vty, argv[idx_peer]->arg, bgp_node_afi(vty),
4414 bgp_node_safi(vty),
4415 PEER_FLAG_REFLECTOR_CLIENT);
4416 }
4417
4418 ALIAS_HIDDEN(neighbor_route_reflector_client,
4419 neighbor_route_reflector_client_hidden_cmd,
4420 "neighbor <A.B.C.D|X:X::X:X|WORD> route-reflector-client",
4421 NEIGHBOR_STR NEIGHBOR_ADDR_STR2
4422 "Configure a neighbor as Route Reflector client\n")
4423
4424 DEFUN (no_neighbor_route_reflector_client,
4425 no_neighbor_route_reflector_client_cmd,
4426 "no neighbor <A.B.C.D|X:X::X:X|WORD> route-reflector-client",
4427 NO_STR
4428 NEIGHBOR_STR
4429 NEIGHBOR_ADDR_STR2
4430 "Configure a neighbor as Route Reflector client\n")
4431 {
4432 int idx_peer = 2;
4433 return peer_af_flag_unset_vty(vty, argv[idx_peer]->arg,
4434 bgp_node_afi(vty), bgp_node_safi(vty),
4435 PEER_FLAG_REFLECTOR_CLIENT);
4436 }
4437
4438 ALIAS_HIDDEN(no_neighbor_route_reflector_client,
4439 no_neighbor_route_reflector_client_hidden_cmd,
4440 "no neighbor <A.B.C.D|X:X::X:X|WORD> route-reflector-client",
4441 NO_STR NEIGHBOR_STR NEIGHBOR_ADDR_STR2
4442 "Configure a neighbor as Route Reflector client\n")
4443
4444 /* neighbor route-server-client. */
4445 DEFUN (neighbor_route_server_client,
4446 neighbor_route_server_client_cmd,
4447 "neighbor <A.B.C.D|X:X::X:X|WORD> route-server-client",
4448 NEIGHBOR_STR
4449 NEIGHBOR_ADDR_STR2
4450 "Configure a neighbor as Route Server client\n")
4451 {
4452 int idx_peer = 1;
4453 struct peer *peer;
4454
4455 peer = peer_and_group_lookup_vty(vty, argv[idx_peer]->arg);
4456 if (!peer)
4457 return CMD_WARNING_CONFIG_FAILED;
4458 return peer_af_flag_set_vty(vty, argv[idx_peer]->arg, bgp_node_afi(vty),
4459 bgp_node_safi(vty),
4460 PEER_FLAG_RSERVER_CLIENT);
4461 }
4462
4463 ALIAS_HIDDEN(neighbor_route_server_client,
4464 neighbor_route_server_client_hidden_cmd,
4465 "neighbor <A.B.C.D|X:X::X:X|WORD> route-server-client",
4466 NEIGHBOR_STR NEIGHBOR_ADDR_STR2
4467 "Configure a neighbor as Route Server client\n")
4468
4469 DEFUN (no_neighbor_route_server_client,
4470 no_neighbor_route_server_client_cmd,
4471 "no neighbor <A.B.C.D|X:X::X:X|WORD> route-server-client",
4472 NO_STR
4473 NEIGHBOR_STR
4474 NEIGHBOR_ADDR_STR2
4475 "Configure a neighbor as Route Server client\n")
4476 {
4477 int idx_peer = 2;
4478 return peer_af_flag_unset_vty(vty, argv[idx_peer]->arg,
4479 bgp_node_afi(vty), bgp_node_safi(vty),
4480 PEER_FLAG_RSERVER_CLIENT);
4481 }
4482
4483 ALIAS_HIDDEN(no_neighbor_route_server_client,
4484 no_neighbor_route_server_client_hidden_cmd,
4485 "no neighbor <A.B.C.D|X:X::X:X|WORD> route-server-client",
4486 NO_STR NEIGHBOR_STR NEIGHBOR_ADDR_STR2
4487 "Configure a neighbor as Route Server client\n")
4488
4489 DEFUN (neighbor_nexthop_local_unchanged,
4490 neighbor_nexthop_local_unchanged_cmd,
4491 "neighbor <A.B.C.D|X:X::X:X|WORD> nexthop-local unchanged",
4492 NEIGHBOR_STR
4493 NEIGHBOR_ADDR_STR2
4494 "Configure treatment of outgoing link-local nexthop attribute\n"
4495 "Leave link-local nexthop unchanged for this peer\n")
4496 {
4497 int idx_peer = 1;
4498 return peer_af_flag_set_vty(vty, argv[idx_peer]->arg, bgp_node_afi(vty),
4499 bgp_node_safi(vty),
4500 PEER_FLAG_NEXTHOP_LOCAL_UNCHANGED);
4501 }
4502
4503 DEFUN (no_neighbor_nexthop_local_unchanged,
4504 no_neighbor_nexthop_local_unchanged_cmd,
4505 "no neighbor <A.B.C.D|X:X::X:X|WORD> nexthop-local unchanged",
4506 NO_STR
4507 NEIGHBOR_STR
4508 NEIGHBOR_ADDR_STR2
4509 "Configure treatment of outgoing link-local-nexthop attribute\n"
4510 "Leave link-local nexthop unchanged for this peer\n")
4511 {
4512 int idx_peer = 2;
4513 return peer_af_flag_unset_vty(vty, argv[idx_peer]->arg,
4514 bgp_node_afi(vty), bgp_node_safi(vty),
4515 PEER_FLAG_NEXTHOP_LOCAL_UNCHANGED);
4516 }
4517
4518 DEFUN (neighbor_attr_unchanged,
4519 neighbor_attr_unchanged_cmd,
4520 "neighbor <A.B.C.D|X:X::X:X|WORD> attribute-unchanged [{as-path|next-hop|med}]",
4521 NEIGHBOR_STR
4522 NEIGHBOR_ADDR_STR2
4523 "BGP attribute is propagated unchanged to this neighbor\n"
4524 "As-path attribute\n"
4525 "Nexthop attribute\n"
4526 "Med attribute\n")
4527 {
4528 int idx = 0;
4529 char *peer_str = argv[1]->arg;
4530 struct peer *peer;
4531 uint16_t flags = 0;
4532 afi_t afi = bgp_node_afi(vty);
4533 safi_t safi = bgp_node_safi(vty);
4534
4535 peer = peer_and_group_lookup_vty(vty, peer_str);
4536 if (!peer)
4537 return CMD_WARNING_CONFIG_FAILED;
4538
4539 if (argv_find(argv, argc, "as-path", &idx))
4540 SET_FLAG(flags, PEER_FLAG_AS_PATH_UNCHANGED);
4541 idx = 0;
4542 if (argv_find(argv, argc, "next-hop", &idx))
4543 SET_FLAG(flags, PEER_FLAG_NEXTHOP_UNCHANGED);
4544 idx = 0;
4545 if (argv_find(argv, argc, "med", &idx))
4546 SET_FLAG(flags, PEER_FLAG_MED_UNCHANGED);
4547
4548 /* no flags means all of them! */
4549 if (!flags) {
4550 SET_FLAG(flags, PEER_FLAG_AS_PATH_UNCHANGED);
4551 SET_FLAG(flags, PEER_FLAG_NEXTHOP_UNCHANGED);
4552 SET_FLAG(flags, PEER_FLAG_MED_UNCHANGED);
4553 } else {
4554 if (!CHECK_FLAG(flags, PEER_FLAG_AS_PATH_UNCHANGED)
4555 && peer_af_flag_check(peer, afi, safi,
4556 PEER_FLAG_AS_PATH_UNCHANGED)) {
4557 peer_af_flag_unset_vty(vty, peer_str, afi, safi,
4558 PEER_FLAG_AS_PATH_UNCHANGED);
4559 }
4560
4561 if (!CHECK_FLAG(flags, PEER_FLAG_NEXTHOP_UNCHANGED)
4562 && peer_af_flag_check(peer, afi, safi,
4563 PEER_FLAG_NEXTHOP_UNCHANGED)) {
4564 peer_af_flag_unset_vty(vty, peer_str, afi, safi,
4565 PEER_FLAG_NEXTHOP_UNCHANGED);
4566 }
4567
4568 if (!CHECK_FLAG(flags, PEER_FLAG_MED_UNCHANGED)
4569 && peer_af_flag_check(peer, afi, safi,
4570 PEER_FLAG_MED_UNCHANGED)) {
4571 peer_af_flag_unset_vty(vty, peer_str, afi, safi,
4572 PEER_FLAG_MED_UNCHANGED);
4573 }
4574 }
4575
4576 return peer_af_flag_set_vty(vty, peer_str, afi, safi, flags);
4577 }
4578
4579 ALIAS_HIDDEN(
4580 neighbor_attr_unchanged, neighbor_attr_unchanged_hidden_cmd,
4581 "neighbor <A.B.C.D|X:X::X:X|WORD> attribute-unchanged [{as-path|next-hop|med}]",
4582 NEIGHBOR_STR NEIGHBOR_ADDR_STR2
4583 "BGP attribute is propagated unchanged to this neighbor\n"
4584 "As-path attribute\n"
4585 "Nexthop attribute\n"
4586 "Med attribute\n")
4587
4588 DEFUN (no_neighbor_attr_unchanged,
4589 no_neighbor_attr_unchanged_cmd,
4590 "no neighbor <A.B.C.D|X:X::X:X|WORD> attribute-unchanged [{as-path|next-hop|med}]",
4591 NO_STR
4592 NEIGHBOR_STR
4593 NEIGHBOR_ADDR_STR2
4594 "BGP attribute is propagated unchanged to this neighbor\n"
4595 "As-path attribute\n"
4596 "Nexthop attribute\n"
4597 "Med attribute\n")
4598 {
4599 int idx = 0;
4600 char *peer = argv[2]->arg;
4601 uint16_t flags = 0;
4602
4603 if (argv_find(argv, argc, "as-path", &idx))
4604 SET_FLAG(flags, PEER_FLAG_AS_PATH_UNCHANGED);
4605 idx = 0;
4606 if (argv_find(argv, argc, "next-hop", &idx))
4607 SET_FLAG(flags, PEER_FLAG_NEXTHOP_UNCHANGED);
4608 idx = 0;
4609 if (argv_find(argv, argc, "med", &idx))
4610 SET_FLAG(flags, PEER_FLAG_MED_UNCHANGED);
4611
4612 if (!flags) // no flags means all of them!
4613 {
4614 SET_FLAG(flags, PEER_FLAG_AS_PATH_UNCHANGED);
4615 SET_FLAG(flags, PEER_FLAG_NEXTHOP_UNCHANGED);
4616 SET_FLAG(flags, PEER_FLAG_MED_UNCHANGED);
4617 }
4618
4619 return peer_af_flag_unset_vty(vty, peer, bgp_node_afi(vty),
4620 bgp_node_safi(vty), flags);
4621 }
4622
4623 ALIAS_HIDDEN(
4624 no_neighbor_attr_unchanged, no_neighbor_attr_unchanged_hidden_cmd,
4625 "no neighbor <A.B.C.D|X:X::X:X|WORD> attribute-unchanged [{as-path|next-hop|med}]",
4626 NO_STR NEIGHBOR_STR NEIGHBOR_ADDR_STR2
4627 "BGP attribute is propagated unchanged to this neighbor\n"
4628 "As-path attribute\n"
4629 "Nexthop attribute\n"
4630 "Med attribute\n")
4631
4632 /* EBGP multihop configuration. */
4633 static int peer_ebgp_multihop_set_vty(struct vty *vty, const char *ip_str,
4634 const char *ttl_str)
4635 {
4636 struct peer *peer;
4637 unsigned int ttl;
4638
4639 peer = peer_and_group_lookup_vty(vty, ip_str);
4640 if (!peer)
4641 return CMD_WARNING_CONFIG_FAILED;
4642
4643 if (peer->conf_if)
4644 return bgp_vty_return(vty, BGP_ERR_INVALID_FOR_DIRECT_PEER);
4645
4646 if (!ttl_str)
4647 ttl = MAXTTL;
4648 else
4649 ttl = strtoul(ttl_str, NULL, 10);
4650
4651 return bgp_vty_return(vty, peer_ebgp_multihop_set(peer, ttl));
4652 }
4653
4654 static int peer_ebgp_multihop_unset_vty(struct vty *vty, const char *ip_str)
4655 {
4656 struct peer *peer;
4657
4658 peer = peer_and_group_lookup_vty(vty, ip_str);
4659 if (!peer)
4660 return CMD_WARNING_CONFIG_FAILED;
4661
4662 return bgp_vty_return(vty, peer_ebgp_multihop_unset(peer));
4663 }
4664
4665 /* neighbor ebgp-multihop. */
4666 DEFUN (neighbor_ebgp_multihop,
4667 neighbor_ebgp_multihop_cmd,
4668 "neighbor <A.B.C.D|X:X::X:X|WORD> ebgp-multihop",
4669 NEIGHBOR_STR
4670 NEIGHBOR_ADDR_STR2
4671 "Allow EBGP neighbors not on directly connected networks\n")
4672 {
4673 int idx_peer = 1;
4674 return peer_ebgp_multihop_set_vty(vty, argv[idx_peer]->arg, NULL);
4675 }
4676
4677 DEFUN (neighbor_ebgp_multihop_ttl,
4678 neighbor_ebgp_multihop_ttl_cmd,
4679 "neighbor <A.B.C.D|X:X::X:X|WORD> ebgp-multihop (1-255)",
4680 NEIGHBOR_STR
4681 NEIGHBOR_ADDR_STR2
4682 "Allow EBGP neighbors not on directly connected networks\n"
4683 "maximum hop count\n")
4684 {
4685 int idx_peer = 1;
4686 int idx_number = 3;
4687 return peer_ebgp_multihop_set_vty(vty, argv[idx_peer]->arg,
4688 argv[idx_number]->arg);
4689 }
4690
4691 DEFUN (no_neighbor_ebgp_multihop,
4692 no_neighbor_ebgp_multihop_cmd,
4693 "no neighbor <A.B.C.D|X:X::X:X|WORD> ebgp-multihop [(1-255)]",
4694 NO_STR
4695 NEIGHBOR_STR
4696 NEIGHBOR_ADDR_STR2
4697 "Allow EBGP neighbors not on directly connected networks\n"
4698 "maximum hop count\n")
4699 {
4700 int idx_peer = 2;
4701 return peer_ebgp_multihop_unset_vty(vty, argv[idx_peer]->arg);
4702 }
4703
4704
4705 /* disable-connected-check */
4706 DEFUN (neighbor_disable_connected_check,
4707 neighbor_disable_connected_check_cmd,
4708 "neighbor <A.B.C.D|X:X::X:X|WORD> <disable-connected-check|enforce-multihop>",
4709 NEIGHBOR_STR
4710 NEIGHBOR_ADDR_STR2
4711 "one-hop away EBGP peer using loopback address\n"
4712 "Enforce EBGP neighbors perform multihop\n")
4713 {
4714 int idx_peer = 1;
4715 return peer_flag_set_vty(vty, argv[idx_peer]->arg,
4716 PEER_FLAG_DISABLE_CONNECTED_CHECK);
4717 }
4718
4719 DEFUN (no_neighbor_disable_connected_check,
4720 no_neighbor_disable_connected_check_cmd,
4721 "no neighbor <A.B.C.D|X:X::X:X|WORD> <disable-connected-check|enforce-multihop>",
4722 NO_STR
4723 NEIGHBOR_STR
4724 NEIGHBOR_ADDR_STR2
4725 "one-hop away EBGP peer using loopback address\n"
4726 "Enforce EBGP neighbors perform multihop\n")
4727 {
4728 int idx_peer = 2;
4729 return peer_flag_unset_vty(vty, argv[idx_peer]->arg,
4730 PEER_FLAG_DISABLE_CONNECTED_CHECK);
4731 }
4732
4733
4734 /* enforce-first-as */
4735 DEFUN (neighbor_enforce_first_as,
4736 neighbor_enforce_first_as_cmd,
4737 "neighbor <A.B.C.D|X:X::X:X|WORD> enforce-first-as",
4738 NEIGHBOR_STR
4739 NEIGHBOR_ADDR_STR2
4740 "Enforce the first AS for EBGP routes\n")
4741 {
4742 int idx_peer = 1;
4743
4744 return peer_flag_set_vty(vty, argv[idx_peer]->arg,
4745 PEER_FLAG_ENFORCE_FIRST_AS);
4746 }
4747
4748 DEFUN (no_neighbor_enforce_first_as,
4749 no_neighbor_enforce_first_as_cmd,
4750 "no neighbor <A.B.C.D|X:X::X:X|WORD> enforce-first-as",
4751 NO_STR
4752 NEIGHBOR_STR
4753 NEIGHBOR_ADDR_STR2
4754 "Enforce the first AS for EBGP routes\n")
4755 {
4756 int idx_peer = 2;
4757
4758 return peer_flag_unset_vty(vty, argv[idx_peer]->arg,
4759 PEER_FLAG_ENFORCE_FIRST_AS);
4760 }
4761
4762
4763 DEFUN (neighbor_description,
4764 neighbor_description_cmd,
4765 "neighbor <A.B.C.D|X:X::X:X|WORD> description LINE...",
4766 NEIGHBOR_STR
4767 NEIGHBOR_ADDR_STR2
4768 "Neighbor specific description\n"
4769 "Up to 80 characters describing this neighbor\n")
4770 {
4771 int idx_peer = 1;
4772 int idx_line = 3;
4773 struct peer *peer;
4774 char *str;
4775
4776 peer = peer_and_group_lookup_vty(vty, argv[idx_peer]->arg);
4777 if (!peer)
4778 return CMD_WARNING_CONFIG_FAILED;
4779
4780 str = argv_concat(argv, argc, idx_line);
4781
4782 peer_description_set(peer, str);
4783
4784 XFREE(MTYPE_TMP, str);
4785
4786 return CMD_SUCCESS;
4787 }
4788
4789 DEFUN (no_neighbor_description,
4790 no_neighbor_description_cmd,
4791 "no neighbor <A.B.C.D|X:X::X:X|WORD> description",
4792 NO_STR
4793 NEIGHBOR_STR
4794 NEIGHBOR_ADDR_STR2
4795 "Neighbor specific description\n")
4796 {
4797 int idx_peer = 2;
4798 struct peer *peer;
4799
4800 peer = peer_and_group_lookup_vty(vty, argv[idx_peer]->arg);
4801 if (!peer)
4802 return CMD_WARNING_CONFIG_FAILED;
4803
4804 peer_description_unset(peer);
4805
4806 return CMD_SUCCESS;
4807 }
4808
4809 ALIAS(no_neighbor_description, no_neighbor_description_comment_cmd,
4810 "no neighbor <A.B.C.D|X:X::X:X|WORD> description LINE...",
4811 NO_STR NEIGHBOR_STR NEIGHBOR_ADDR_STR2
4812 "Neighbor specific description\n"
4813 "Up to 80 characters describing this neighbor\n")
4814
4815 /* Neighbor update-source. */
4816 static int peer_update_source_vty(struct vty *vty, const char *peer_str,
4817 const char *source_str)
4818 {
4819 struct peer *peer;
4820 struct prefix p;
4821 union sockunion su;
4822
4823 peer = peer_and_group_lookup_vty(vty, peer_str);
4824 if (!peer)
4825 return CMD_WARNING_CONFIG_FAILED;
4826
4827 if (peer->conf_if)
4828 return CMD_WARNING;
4829
4830 if (source_str) {
4831 if (str2sockunion(source_str, &su) == 0)
4832 peer_update_source_addr_set(peer, &su);
4833 else {
4834 if (str2prefix(source_str, &p)) {
4835 vty_out(vty,
4836 "%% Invalid update-source, remove prefix length \n");
4837 return CMD_WARNING_CONFIG_FAILED;
4838 } else
4839 peer_update_source_if_set(peer, source_str);
4840 }
4841 } else
4842 peer_update_source_unset(peer);
4843
4844 return CMD_SUCCESS;
4845 }
4846
4847 #define BGP_UPDATE_SOURCE_HELP_STR \
4848 "IPv4 address\n" \
4849 "IPv6 address\n" \
4850 "Interface name (requires zebra to be running)\n"
4851
4852 DEFUN (neighbor_update_source,
4853 neighbor_update_source_cmd,
4854 "neighbor <A.B.C.D|X:X::X:X|WORD> update-source <A.B.C.D|X:X::X:X|WORD>",
4855 NEIGHBOR_STR
4856 NEIGHBOR_ADDR_STR2
4857 "Source of routing updates\n"
4858 BGP_UPDATE_SOURCE_HELP_STR)
4859 {
4860 int idx_peer = 1;
4861 int idx_peer_2 = 3;
4862 return peer_update_source_vty(vty, argv[idx_peer]->arg,
4863 argv[idx_peer_2]->arg);
4864 }
4865
4866 DEFUN (no_neighbor_update_source,
4867 no_neighbor_update_source_cmd,
4868 "no neighbor <A.B.C.D|X:X::X:X|WORD> update-source [<A.B.C.D|X:X::X:X|WORD>]",
4869 NO_STR
4870 NEIGHBOR_STR
4871 NEIGHBOR_ADDR_STR2
4872 "Source of routing updates\n"
4873 BGP_UPDATE_SOURCE_HELP_STR)
4874 {
4875 int idx_peer = 2;
4876 return peer_update_source_vty(vty, argv[idx_peer]->arg, NULL);
4877 }
4878
4879 static int peer_default_originate_set_vty(struct vty *vty, const char *peer_str,
4880 afi_t afi, safi_t safi,
4881 const char *rmap, int set)
4882 {
4883 int ret;
4884 struct peer *peer;
4885 struct route_map *route_map;
4886
4887 peer = peer_and_group_lookup_vty(vty, peer_str);
4888 if (!peer)
4889 return CMD_WARNING_CONFIG_FAILED;
4890
4891 if (set) {
4892 route_map = route_map_lookup_warn_noexist(vty, rmap);
4893 ret = peer_default_originate_set(peer, afi, safi,
4894 rmap, route_map);
4895 } else
4896 ret = peer_default_originate_unset(peer, afi, safi);
4897
4898 return bgp_vty_return(vty, ret);
4899 }
4900
4901 /* neighbor default-originate. */
4902 DEFUN (neighbor_default_originate,
4903 neighbor_default_originate_cmd,
4904 "neighbor <A.B.C.D|X:X::X:X|WORD> default-originate",
4905 NEIGHBOR_STR
4906 NEIGHBOR_ADDR_STR2
4907 "Originate default route to this neighbor\n")
4908 {
4909 int idx_peer = 1;
4910 return peer_default_originate_set_vty(vty, argv[idx_peer]->arg,
4911 bgp_node_afi(vty),
4912 bgp_node_safi(vty), NULL, 1);
4913 }
4914
4915 ALIAS_HIDDEN(neighbor_default_originate, neighbor_default_originate_hidden_cmd,
4916 "neighbor <A.B.C.D|X:X::X:X|WORD> default-originate",
4917 NEIGHBOR_STR NEIGHBOR_ADDR_STR2
4918 "Originate default route to this neighbor\n")
4919
4920 DEFUN (neighbor_default_originate_rmap,
4921 neighbor_default_originate_rmap_cmd,
4922 "neighbor <A.B.C.D|X:X::X:X|WORD> default-originate route-map WORD",
4923 NEIGHBOR_STR
4924 NEIGHBOR_ADDR_STR2
4925 "Originate default route to this neighbor\n"
4926 "Route-map to specify criteria to originate default\n"
4927 "route-map name\n")
4928 {
4929 int idx_peer = 1;
4930 int idx_word = 4;
4931 return peer_default_originate_set_vty(
4932 vty, argv[idx_peer]->arg, bgp_node_afi(vty), bgp_node_safi(vty),
4933 argv[idx_word]->arg, 1);
4934 }
4935
4936 ALIAS_HIDDEN(
4937 neighbor_default_originate_rmap,
4938 neighbor_default_originate_rmap_hidden_cmd,
4939 "neighbor <A.B.C.D|X:X::X:X|WORD> default-originate route-map WORD",
4940 NEIGHBOR_STR NEIGHBOR_ADDR_STR2
4941 "Originate default route to this neighbor\n"
4942 "Route-map to specify criteria to originate default\n"
4943 "route-map name\n")
4944
4945 DEFUN (no_neighbor_default_originate,
4946 no_neighbor_default_originate_cmd,
4947 "no neighbor <A.B.C.D|X:X::X:X|WORD> default-originate [route-map WORD]",
4948 NO_STR
4949 NEIGHBOR_STR
4950 NEIGHBOR_ADDR_STR2
4951 "Originate default route to this neighbor\n"
4952 "Route-map to specify criteria to originate default\n"
4953 "route-map name\n")
4954 {
4955 int idx_peer = 2;
4956 return peer_default_originate_set_vty(vty, argv[idx_peer]->arg,
4957 bgp_node_afi(vty),
4958 bgp_node_safi(vty), NULL, 0);
4959 }
4960
4961 ALIAS_HIDDEN(
4962 no_neighbor_default_originate, no_neighbor_default_originate_hidden_cmd,
4963 "no neighbor <A.B.C.D|X:X::X:X|WORD> default-originate [route-map WORD]",
4964 NO_STR NEIGHBOR_STR NEIGHBOR_ADDR_STR2
4965 "Originate default route to this neighbor\n"
4966 "Route-map to specify criteria to originate default\n"
4967 "route-map name\n")
4968
4969
4970 /* Set neighbor's BGP port. */
4971 static int peer_port_vty(struct vty *vty, const char *ip_str, int afi,
4972 const char *port_str)
4973 {
4974 struct peer *peer;
4975 uint16_t port;
4976 struct servent *sp;
4977
4978 peer = peer_lookup_vty(vty, ip_str);
4979 if (!peer)
4980 return CMD_WARNING_CONFIG_FAILED;
4981
4982 if (!port_str) {
4983 sp = getservbyname("bgp", "tcp");
4984 port = (sp == NULL) ? BGP_PORT_DEFAULT : ntohs(sp->s_port);
4985 } else {
4986 port = strtoul(port_str, NULL, 10);
4987 }
4988
4989 peer_port_set(peer, port);
4990
4991 return CMD_SUCCESS;
4992 }
4993
4994 /* Set specified peer's BGP port. */
4995 DEFUN (neighbor_port,
4996 neighbor_port_cmd,
4997 "neighbor <A.B.C.D|X:X::X:X> port (0-65535)",
4998 NEIGHBOR_STR
4999 NEIGHBOR_ADDR_STR
5000 "Neighbor's BGP port\n"
5001 "TCP port number\n")
5002 {
5003 int idx_ip = 1;
5004 int idx_number = 3;
5005 return peer_port_vty(vty, argv[idx_ip]->arg, AFI_IP,
5006 argv[idx_number]->arg);
5007 }
5008
5009 DEFUN (no_neighbor_port,
5010 no_neighbor_port_cmd,
5011 "no neighbor <A.B.C.D|X:X::X:X> port [(0-65535)]",
5012 NO_STR
5013 NEIGHBOR_STR
5014 NEIGHBOR_ADDR_STR
5015 "Neighbor's BGP port\n"
5016 "TCP port number\n")
5017 {
5018 int idx_ip = 2;
5019 return peer_port_vty(vty, argv[idx_ip]->arg, AFI_IP, NULL);
5020 }
5021
5022
5023 /* neighbor weight. */
5024 static int peer_weight_set_vty(struct vty *vty, const char *ip_str, afi_t afi,
5025 safi_t safi, const char *weight_str)
5026 {
5027 int ret;
5028 struct peer *peer;
5029 unsigned long weight;
5030
5031 peer = peer_and_group_lookup_vty(vty, ip_str);
5032 if (!peer)
5033 return CMD_WARNING_CONFIG_FAILED;
5034
5035 weight = strtoul(weight_str, NULL, 10);
5036
5037 ret = peer_weight_set(peer, afi, safi, weight);
5038 return bgp_vty_return(vty, ret);
5039 }
5040
5041 static int peer_weight_unset_vty(struct vty *vty, const char *ip_str, afi_t afi,
5042 safi_t safi)
5043 {
5044 int ret;
5045 struct peer *peer;
5046
5047 peer = peer_and_group_lookup_vty(vty, ip_str);
5048 if (!peer)
5049 return CMD_WARNING_CONFIG_FAILED;
5050
5051 ret = peer_weight_unset(peer, afi, safi);
5052 return bgp_vty_return(vty, ret);
5053 }
5054
5055 DEFUN (neighbor_weight,
5056 neighbor_weight_cmd,
5057 "neighbor <A.B.C.D|X:X::X:X|WORD> weight (0-65535)",
5058 NEIGHBOR_STR
5059 NEIGHBOR_ADDR_STR2
5060 "Set default weight for routes from this neighbor\n"
5061 "default weight\n")
5062 {
5063 int idx_peer = 1;
5064 int idx_number = 3;
5065 return peer_weight_set_vty(vty, argv[idx_peer]->arg, bgp_node_afi(vty),
5066 bgp_node_safi(vty), argv[idx_number]->arg);
5067 }
5068
5069 ALIAS_HIDDEN(neighbor_weight, neighbor_weight_hidden_cmd,
5070 "neighbor <A.B.C.D|X:X::X:X|WORD> weight (0-65535)",
5071 NEIGHBOR_STR NEIGHBOR_ADDR_STR2
5072 "Set default weight for routes from this neighbor\n"
5073 "default weight\n")
5074
5075 DEFUN (no_neighbor_weight,
5076 no_neighbor_weight_cmd,
5077 "no neighbor <A.B.C.D|X:X::X:X|WORD> weight [(0-65535)]",
5078 NO_STR
5079 NEIGHBOR_STR
5080 NEIGHBOR_ADDR_STR2
5081 "Set default weight for routes from this neighbor\n"
5082 "default weight\n")
5083 {
5084 int idx_peer = 2;
5085 return peer_weight_unset_vty(vty, argv[idx_peer]->arg,
5086 bgp_node_afi(vty), bgp_node_safi(vty));
5087 }
5088
5089 ALIAS_HIDDEN(no_neighbor_weight, no_neighbor_weight_hidden_cmd,
5090 "no neighbor <A.B.C.D|X:X::X:X|WORD> weight [(0-65535)]",
5091 NO_STR NEIGHBOR_STR NEIGHBOR_ADDR_STR2
5092 "Set default weight for routes from this neighbor\n"
5093 "default weight\n")
5094
5095
5096 /* Override capability negotiation. */
5097 DEFUN (neighbor_override_capability,
5098 neighbor_override_capability_cmd,
5099 "neighbor <A.B.C.D|X:X::X:X|WORD> override-capability",
5100 NEIGHBOR_STR
5101 NEIGHBOR_ADDR_STR2
5102 "Override capability negotiation result\n")
5103 {
5104 int idx_peer = 1;
5105 return peer_flag_set_vty(vty, argv[idx_peer]->arg,
5106 PEER_FLAG_OVERRIDE_CAPABILITY);
5107 }
5108
5109 DEFUN (no_neighbor_override_capability,
5110 no_neighbor_override_capability_cmd,
5111 "no neighbor <A.B.C.D|X:X::X:X|WORD> override-capability",
5112 NO_STR
5113 NEIGHBOR_STR
5114 NEIGHBOR_ADDR_STR2
5115 "Override capability negotiation result\n")
5116 {
5117 int idx_peer = 2;
5118 return peer_flag_unset_vty(vty, argv[idx_peer]->arg,
5119 PEER_FLAG_OVERRIDE_CAPABILITY);
5120 }
5121
5122 DEFUN (neighbor_strict_capability,
5123 neighbor_strict_capability_cmd,
5124 "neighbor <A.B.C.D|X:X::X:X|WORD> strict-capability-match",
5125 NEIGHBOR_STR
5126 NEIGHBOR_ADDR_STR2
5127 "Strict capability negotiation match\n")
5128 {
5129 int idx_peer = 1;
5130
5131 return peer_flag_set_vty(vty, argv[idx_peer]->arg,
5132 PEER_FLAG_STRICT_CAP_MATCH);
5133 }
5134
5135 DEFUN (no_neighbor_strict_capability,
5136 no_neighbor_strict_capability_cmd,
5137 "no neighbor <A.B.C.D|X:X::X:X|WORD> strict-capability-match",
5138 NO_STR
5139 NEIGHBOR_STR
5140 NEIGHBOR_ADDR_STR2
5141 "Strict capability negotiation match\n")
5142 {
5143 int idx_peer = 2;
5144
5145 return peer_flag_unset_vty(vty, argv[idx_peer]->arg,
5146 PEER_FLAG_STRICT_CAP_MATCH);
5147 }
5148
5149 static int peer_timers_set_vty(struct vty *vty, const char *ip_str,
5150 const char *keep_str, const char *hold_str)
5151 {
5152 int ret;
5153 struct peer *peer;
5154 uint32_t keepalive;
5155 uint32_t holdtime;
5156
5157 peer = peer_and_group_lookup_vty(vty, ip_str);
5158 if (!peer)
5159 return CMD_WARNING_CONFIG_FAILED;
5160
5161 keepalive = strtoul(keep_str, NULL, 10);
5162 holdtime = strtoul(hold_str, NULL, 10);
5163
5164 ret = peer_timers_set(peer, keepalive, holdtime);
5165
5166 return bgp_vty_return(vty, ret);
5167 }
5168
5169 static int peer_timers_unset_vty(struct vty *vty, const char *ip_str)
5170 {
5171 int ret;
5172 struct peer *peer;
5173
5174 peer = peer_and_group_lookup_vty(vty, ip_str);
5175 if (!peer)
5176 return CMD_WARNING_CONFIG_FAILED;
5177
5178 ret = peer_timers_unset(peer);
5179
5180 return bgp_vty_return(vty, ret);
5181 }
5182
5183 DEFUN (neighbor_timers,
5184 neighbor_timers_cmd,
5185 "neighbor <A.B.C.D|X:X::X:X|WORD> timers (0-65535) (0-65535)",
5186 NEIGHBOR_STR
5187 NEIGHBOR_ADDR_STR2
5188 "BGP per neighbor timers\n"
5189 "Keepalive interval\n"
5190 "Holdtime\n")
5191 {
5192 int idx_peer = 1;
5193 int idx_number = 3;
5194 int idx_number_2 = 4;
5195 return peer_timers_set_vty(vty, argv[idx_peer]->arg,
5196 argv[idx_number]->arg,
5197 argv[idx_number_2]->arg);
5198 }
5199
5200 DEFUN (no_neighbor_timers,
5201 no_neighbor_timers_cmd,
5202 "no neighbor <A.B.C.D|X:X::X:X|WORD> timers [(0-65535) (0-65535)]",
5203 NO_STR
5204 NEIGHBOR_STR
5205 NEIGHBOR_ADDR_STR2
5206 "BGP per neighbor timers\n"
5207 "Keepalive interval\n"
5208 "Holdtime\n")
5209 {
5210 int idx_peer = 2;
5211 return peer_timers_unset_vty(vty, argv[idx_peer]->arg);
5212 }
5213
5214
5215 static int peer_timers_connect_set_vty(struct vty *vty, const char *ip_str,
5216 const char *time_str)
5217 {
5218 int ret;
5219 struct peer *peer;
5220 uint32_t connect;
5221
5222 peer = peer_and_group_lookup_vty(vty, ip_str);
5223 if (!peer)
5224 return CMD_WARNING_CONFIG_FAILED;
5225
5226 connect = strtoul(time_str, NULL, 10);
5227
5228 ret = peer_timers_connect_set(peer, connect);
5229
5230 return bgp_vty_return(vty, ret);
5231 }
5232
5233 static int peer_timers_connect_unset_vty(struct vty *vty, const char *ip_str)
5234 {
5235 int ret;
5236 struct peer *peer;
5237
5238 peer = peer_and_group_lookup_vty(vty, ip_str);
5239 if (!peer)
5240 return CMD_WARNING_CONFIG_FAILED;
5241
5242 ret = peer_timers_connect_unset(peer);
5243
5244 return bgp_vty_return(vty, ret);
5245 }
5246
5247 DEFUN (neighbor_timers_connect,
5248 neighbor_timers_connect_cmd,
5249 "neighbor <A.B.C.D|X:X::X:X|WORD> timers connect (1-65535)",
5250 NEIGHBOR_STR
5251 NEIGHBOR_ADDR_STR2
5252 "BGP per neighbor timers\n"
5253 "BGP connect timer\n"
5254 "Connect timer\n")
5255 {
5256 int idx_peer = 1;
5257 int idx_number = 4;
5258 return peer_timers_connect_set_vty(vty, argv[idx_peer]->arg,
5259 argv[idx_number]->arg);
5260 }
5261
5262 DEFUN (no_neighbor_timers_connect,
5263 no_neighbor_timers_connect_cmd,
5264 "no neighbor <A.B.C.D|X:X::X:X|WORD> timers connect [(1-65535)]",
5265 NO_STR
5266 NEIGHBOR_STR
5267 NEIGHBOR_ADDR_STR2
5268 "BGP per neighbor timers\n"
5269 "BGP connect timer\n"
5270 "Connect timer\n")
5271 {
5272 int idx_peer = 2;
5273 return peer_timers_connect_unset_vty(vty, argv[idx_peer]->arg);
5274 }
5275
5276
5277 static int peer_advertise_interval_vty(struct vty *vty, const char *ip_str,
5278 const char *time_str, int set)
5279 {
5280 int ret;
5281 struct peer *peer;
5282 uint32_t routeadv = 0;
5283
5284 peer = peer_and_group_lookup_vty(vty, ip_str);
5285 if (!peer)
5286 return CMD_WARNING_CONFIG_FAILED;
5287
5288 if (time_str)
5289 routeadv = strtoul(time_str, NULL, 10);
5290
5291 if (set)
5292 ret = peer_advertise_interval_set(peer, routeadv);
5293 else
5294 ret = peer_advertise_interval_unset(peer);
5295
5296 return bgp_vty_return(vty, ret);
5297 }
5298
5299 DEFUN (neighbor_advertise_interval,
5300 neighbor_advertise_interval_cmd,
5301 "neighbor <A.B.C.D|X:X::X:X|WORD> advertisement-interval (0-600)",
5302 NEIGHBOR_STR
5303 NEIGHBOR_ADDR_STR2
5304 "Minimum interval between sending BGP routing updates\n"
5305 "time in seconds\n")
5306 {
5307 int idx_peer = 1;
5308 int idx_number = 3;
5309 return peer_advertise_interval_vty(vty, argv[idx_peer]->arg,
5310 argv[idx_number]->arg, 1);
5311 }
5312
5313 DEFUN (no_neighbor_advertise_interval,
5314 no_neighbor_advertise_interval_cmd,
5315 "no neighbor <A.B.C.D|X:X::X:X|WORD> advertisement-interval [(0-600)]",
5316 NO_STR
5317 NEIGHBOR_STR
5318 NEIGHBOR_ADDR_STR2
5319 "Minimum interval between sending BGP routing updates\n"
5320 "time in seconds\n")
5321 {
5322 int idx_peer = 2;
5323 return peer_advertise_interval_vty(vty, argv[idx_peer]->arg, NULL, 0);
5324 }
5325
5326
5327 /* Time to wait before processing route-map updates */
5328 DEFUN (bgp_set_route_map_delay_timer,
5329 bgp_set_route_map_delay_timer_cmd,
5330 "bgp route-map delay-timer (0-600)",
5331 SET_STR
5332 "BGP route-map delay timer\n"
5333 "Time in secs to wait before processing route-map changes\n"
5334 "0 disables the timer, no route updates happen when route-maps change\n")
5335 {
5336 int idx_number = 3;
5337 uint32_t rmap_delay_timer;
5338
5339 if (argv[idx_number]->arg) {
5340 rmap_delay_timer = strtoul(argv[idx_number]->arg, NULL, 10);
5341 bm->rmap_update_timer = rmap_delay_timer;
5342
5343 /* if the dynamic update handling is being disabled, and a timer
5344 * is
5345 * running, stop the timer and act as if the timer has already
5346 * fired.
5347 */
5348 if (!rmap_delay_timer && bm->t_rmap_update) {
5349 BGP_TIMER_OFF(bm->t_rmap_update);
5350 thread_execute(bm->master, bgp_route_map_update_timer,
5351 NULL, 0);
5352 }
5353 return CMD_SUCCESS;
5354 } else {
5355 vty_out(vty, "%% BGP invalid route-map delay-timer\n");
5356 return CMD_WARNING_CONFIG_FAILED;
5357 }
5358 }
5359
5360 DEFUN (no_bgp_set_route_map_delay_timer,
5361 no_bgp_set_route_map_delay_timer_cmd,
5362 "no bgp route-map delay-timer [(0-600)]",
5363 NO_STR
5364 BGP_STR
5365 "Default BGP route-map delay timer\n"
5366 "Reset to default time to wait for processing route-map changes\n"
5367 "0 disables the timer, no route updates happen when route-maps change\n")
5368 {
5369
5370 bm->rmap_update_timer = RMAP_DEFAULT_UPDATE_TIMER;
5371
5372 return CMD_SUCCESS;
5373 }
5374
5375
5376 /* neighbor interface */
5377 static int peer_interface_vty(struct vty *vty, const char *ip_str,
5378 const char *str)
5379 {
5380 struct peer *peer;
5381
5382 peer = peer_lookup_vty(vty, ip_str);
5383 if (!peer || peer->conf_if) {
5384 vty_out(vty, "%% BGP invalid peer %s\n", ip_str);
5385 return CMD_WARNING_CONFIG_FAILED;
5386 }
5387
5388 if (str)
5389 peer_interface_set(peer, str);
5390 else
5391 peer_interface_unset(peer);
5392
5393 return CMD_SUCCESS;
5394 }
5395
5396 DEFUN (neighbor_interface,
5397 neighbor_interface_cmd,
5398 "neighbor <A.B.C.D|X:X::X:X> interface WORD",
5399 NEIGHBOR_STR
5400 NEIGHBOR_ADDR_STR
5401 "Interface\n"
5402 "Interface name\n")
5403 {
5404 int idx_ip = 1;
5405 int idx_word = 3;
5406 return peer_interface_vty(vty, argv[idx_ip]->arg, argv[idx_word]->arg);
5407 }
5408
5409 DEFUN (no_neighbor_interface,
5410 no_neighbor_interface_cmd,
5411 "no neighbor <A.B.C.D|X:X::X:X|WORD> interface WORD",
5412 NO_STR
5413 NEIGHBOR_STR
5414 NEIGHBOR_ADDR_STR2
5415 "Interface\n"
5416 "Interface name\n")
5417 {
5418 int idx_peer = 2;
5419 return peer_interface_vty(vty, argv[idx_peer]->arg, NULL);
5420 }
5421
5422 DEFUN (neighbor_distribute_list,
5423 neighbor_distribute_list_cmd,
5424 "neighbor <A.B.C.D|X:X::X:X|WORD> distribute-list <(1-199)|(1300-2699)|WORD> <in|out>",
5425 NEIGHBOR_STR
5426 NEIGHBOR_ADDR_STR2
5427 "Filter updates to/from this neighbor\n"
5428 "IP access-list number\n"
5429 "IP access-list number (expanded range)\n"
5430 "IP Access-list name\n"
5431 "Filter incoming updates\n"
5432 "Filter outgoing updates\n")
5433 {
5434 int idx_peer = 1;
5435 int idx_acl = 3;
5436 int direct, ret;
5437 struct peer *peer;
5438
5439 const char *pstr = argv[idx_peer]->arg;
5440 const char *acl = argv[idx_acl]->arg;
5441 const char *inout = argv[argc - 1]->text;
5442
5443 peer = peer_and_group_lookup_vty(vty, pstr);
5444 if (!peer)
5445 return CMD_WARNING_CONFIG_FAILED;
5446
5447 /* Check filter direction. */
5448 direct = strmatch(inout, "in") ? FILTER_IN : FILTER_OUT;
5449 ret = peer_distribute_set(peer, bgp_node_afi(vty), bgp_node_safi(vty),
5450 direct, acl);
5451
5452 return bgp_vty_return(vty, ret);
5453 }
5454
5455 ALIAS_HIDDEN(
5456 neighbor_distribute_list, neighbor_distribute_list_hidden_cmd,
5457 "neighbor <A.B.C.D|X:X::X:X|WORD> distribute-list <(1-199)|(1300-2699)|WORD> <in|out>",
5458 NEIGHBOR_STR NEIGHBOR_ADDR_STR2
5459 "Filter updates to/from this neighbor\n"
5460 "IP access-list number\n"
5461 "IP access-list number (expanded range)\n"
5462 "IP Access-list name\n"
5463 "Filter incoming updates\n"
5464 "Filter outgoing updates\n")
5465
5466 DEFUN (no_neighbor_distribute_list,
5467 no_neighbor_distribute_list_cmd,
5468 "no neighbor <A.B.C.D|X:X::X:X|WORD> distribute-list <(1-199)|(1300-2699)|WORD> <in|out>",
5469 NO_STR
5470 NEIGHBOR_STR
5471 NEIGHBOR_ADDR_STR2
5472 "Filter updates to/from this neighbor\n"
5473 "IP access-list number\n"
5474 "IP access-list number (expanded range)\n"
5475 "IP Access-list name\n"
5476 "Filter incoming updates\n"
5477 "Filter outgoing updates\n")
5478 {
5479 int idx_peer = 2;
5480 int direct, ret;
5481 struct peer *peer;
5482
5483 const char *pstr = argv[idx_peer]->arg;
5484 const char *inout = argv[argc - 1]->text;
5485
5486 peer = peer_and_group_lookup_vty(vty, pstr);
5487 if (!peer)
5488 return CMD_WARNING_CONFIG_FAILED;
5489
5490 /* Check filter direction. */
5491 direct = strmatch(inout, "in") ? FILTER_IN : FILTER_OUT;
5492 ret = peer_distribute_unset(peer, bgp_node_afi(vty), bgp_node_safi(vty),
5493 direct);
5494
5495 return bgp_vty_return(vty, ret);
5496 }
5497
5498 ALIAS_HIDDEN(
5499 no_neighbor_distribute_list, no_neighbor_distribute_list_hidden_cmd,
5500 "no neighbor <A.B.C.D|X:X::X:X|WORD> distribute-list <(1-199)|(1300-2699)|WORD> <in|out>",
5501 NO_STR NEIGHBOR_STR NEIGHBOR_ADDR_STR2
5502 "Filter updates to/from this neighbor\n"
5503 "IP access-list number\n"
5504 "IP access-list number (expanded range)\n"
5505 "IP Access-list name\n"
5506 "Filter incoming updates\n"
5507 "Filter outgoing updates\n")
5508
5509 /* Set prefix list to the peer. */
5510 static int peer_prefix_list_set_vty(struct vty *vty, const char *ip_str,
5511 afi_t afi, safi_t safi,
5512 const char *name_str,
5513 const char *direct_str)
5514 {
5515 int ret;
5516 int direct = FILTER_IN;
5517 struct peer *peer;
5518
5519 peer = peer_and_group_lookup_vty(vty, ip_str);
5520 if (!peer)
5521 return CMD_WARNING_CONFIG_FAILED;
5522
5523 /* Check filter direction. */
5524 if (strncmp(direct_str, "i", 1) == 0)
5525 direct = FILTER_IN;
5526 else if (strncmp(direct_str, "o", 1) == 0)
5527 direct = FILTER_OUT;
5528
5529 ret = peer_prefix_list_set(peer, afi, safi, direct, name_str);
5530
5531 return bgp_vty_return(vty, ret);
5532 }
5533
5534 static int peer_prefix_list_unset_vty(struct vty *vty, const char *ip_str,
5535 afi_t afi, safi_t safi,
5536 const char *direct_str)
5537 {
5538 int ret;
5539 struct peer *peer;
5540 int direct = FILTER_IN;
5541
5542 peer = peer_and_group_lookup_vty(vty, ip_str);
5543 if (!peer)
5544 return CMD_WARNING_CONFIG_FAILED;
5545
5546 /* Check filter direction. */
5547 if (strncmp(direct_str, "i", 1) == 0)
5548 direct = FILTER_IN;
5549 else if (strncmp(direct_str, "o", 1) == 0)
5550 direct = FILTER_OUT;
5551
5552 ret = peer_prefix_list_unset(peer, afi, safi, direct);
5553
5554 return bgp_vty_return(vty, ret);
5555 }
5556
5557 DEFUN (neighbor_prefix_list,
5558 neighbor_prefix_list_cmd,
5559 "neighbor <A.B.C.D|X:X::X:X|WORD> prefix-list WORD <in|out>",
5560 NEIGHBOR_STR
5561 NEIGHBOR_ADDR_STR2
5562 "Filter updates to/from this neighbor\n"
5563 "Name of a prefix list\n"
5564 "Filter incoming updates\n"
5565 "Filter outgoing updates\n")
5566 {
5567 int idx_peer = 1;
5568 int idx_word = 3;
5569 int idx_in_out = 4;
5570 return peer_prefix_list_set_vty(
5571 vty, argv[idx_peer]->arg, bgp_node_afi(vty), bgp_node_safi(vty),
5572 argv[idx_word]->arg, argv[idx_in_out]->arg);
5573 }
5574
5575 ALIAS_HIDDEN(neighbor_prefix_list, neighbor_prefix_list_hidden_cmd,
5576 "neighbor <A.B.C.D|X:X::X:X|WORD> prefix-list WORD <in|out>",
5577 NEIGHBOR_STR NEIGHBOR_ADDR_STR2
5578 "Filter updates to/from this neighbor\n"
5579 "Name of a prefix list\n"
5580 "Filter incoming updates\n"
5581 "Filter outgoing updates\n")
5582
5583 DEFUN (no_neighbor_prefix_list,
5584 no_neighbor_prefix_list_cmd,
5585 "no neighbor <A.B.C.D|X:X::X:X|WORD> prefix-list WORD <in|out>",
5586 NO_STR
5587 NEIGHBOR_STR
5588 NEIGHBOR_ADDR_STR2
5589 "Filter updates to/from this neighbor\n"
5590 "Name of a prefix list\n"
5591 "Filter incoming updates\n"
5592 "Filter outgoing updates\n")
5593 {
5594 int idx_peer = 2;
5595 int idx_in_out = 5;
5596 return peer_prefix_list_unset_vty(vty, argv[idx_peer]->arg,
5597 bgp_node_afi(vty), bgp_node_safi(vty),
5598 argv[idx_in_out]->arg);
5599 }
5600
5601 ALIAS_HIDDEN(no_neighbor_prefix_list, no_neighbor_prefix_list_hidden_cmd,
5602 "no neighbor <A.B.C.D|X:X::X:X|WORD> prefix-list WORD <in|out>",
5603 NO_STR NEIGHBOR_STR NEIGHBOR_ADDR_STR2
5604 "Filter updates to/from this neighbor\n"
5605 "Name of a prefix list\n"
5606 "Filter incoming updates\n"
5607 "Filter outgoing updates\n")
5608
5609 static int peer_aslist_set_vty(struct vty *vty, const char *ip_str, afi_t afi,
5610 safi_t safi, const char *name_str,
5611 const char *direct_str)
5612 {
5613 int ret;
5614 struct peer *peer;
5615 int direct = FILTER_IN;
5616
5617 peer = peer_and_group_lookup_vty(vty, ip_str);
5618 if (!peer)
5619 return CMD_WARNING_CONFIG_FAILED;
5620
5621 /* Check filter direction. */
5622 if (strncmp(direct_str, "i", 1) == 0)
5623 direct = FILTER_IN;
5624 else if (strncmp(direct_str, "o", 1) == 0)
5625 direct = FILTER_OUT;
5626
5627 ret = peer_aslist_set(peer, afi, safi, direct, name_str);
5628
5629 return bgp_vty_return(vty, ret);
5630 }
5631
5632 static int peer_aslist_unset_vty(struct vty *vty, const char *ip_str, afi_t afi,
5633 safi_t safi, const char *direct_str)
5634 {
5635 int ret;
5636 struct peer *peer;
5637 int direct = FILTER_IN;
5638
5639 peer = peer_and_group_lookup_vty(vty, ip_str);
5640 if (!peer)
5641 return CMD_WARNING_CONFIG_FAILED;
5642
5643 /* Check filter direction. */
5644 if (strncmp(direct_str, "i", 1) == 0)
5645 direct = FILTER_IN;
5646 else if (strncmp(direct_str, "o", 1) == 0)
5647 direct = FILTER_OUT;
5648
5649 ret = peer_aslist_unset(peer, afi, safi, direct);
5650
5651 return bgp_vty_return(vty, ret);
5652 }
5653
5654 DEFUN (neighbor_filter_list,
5655 neighbor_filter_list_cmd,
5656 "neighbor <A.B.C.D|X:X::X:X|WORD> filter-list WORD <in|out>",
5657 NEIGHBOR_STR
5658 NEIGHBOR_ADDR_STR2
5659 "Establish BGP filters\n"
5660 "AS path access-list name\n"
5661 "Filter incoming routes\n"
5662 "Filter outgoing routes\n")
5663 {
5664 int idx_peer = 1;
5665 int idx_word = 3;
5666 int idx_in_out = 4;
5667 return peer_aslist_set_vty(vty, argv[idx_peer]->arg, bgp_node_afi(vty),
5668 bgp_node_safi(vty), argv[idx_word]->arg,
5669 argv[idx_in_out]->arg);
5670 }
5671
5672 ALIAS_HIDDEN(neighbor_filter_list, neighbor_filter_list_hidden_cmd,
5673 "neighbor <A.B.C.D|X:X::X:X|WORD> filter-list WORD <in|out>",
5674 NEIGHBOR_STR NEIGHBOR_ADDR_STR2
5675 "Establish BGP filters\n"
5676 "AS path access-list name\n"
5677 "Filter incoming routes\n"
5678 "Filter outgoing routes\n")
5679
5680 DEFUN (no_neighbor_filter_list,
5681 no_neighbor_filter_list_cmd,
5682 "no neighbor <A.B.C.D|X:X::X:X|WORD> filter-list WORD <in|out>",
5683 NO_STR
5684 NEIGHBOR_STR
5685 NEIGHBOR_ADDR_STR2
5686 "Establish BGP filters\n"
5687 "AS path access-list name\n"
5688 "Filter incoming routes\n"
5689 "Filter outgoing routes\n")
5690 {
5691 int idx_peer = 2;
5692 int idx_in_out = 5;
5693 return peer_aslist_unset_vty(vty, argv[idx_peer]->arg,
5694 bgp_node_afi(vty), bgp_node_safi(vty),
5695 argv[idx_in_out]->arg);
5696 }
5697
5698 ALIAS_HIDDEN(no_neighbor_filter_list, no_neighbor_filter_list_hidden_cmd,
5699 "no neighbor <A.B.C.D|X:X::X:X|WORD> filter-list WORD <in|out>",
5700 NO_STR NEIGHBOR_STR NEIGHBOR_ADDR_STR2
5701 "Establish BGP filters\n"
5702 "AS path access-list name\n"
5703 "Filter incoming routes\n"
5704 "Filter outgoing routes\n")
5705
5706 /* Set route-map to the peer. */
5707 static int peer_route_map_set_vty(struct vty *vty, const char *ip_str,
5708 afi_t afi, safi_t safi, const char *name_str,
5709 const char *direct_str)
5710 {
5711 int ret;
5712 struct peer *peer;
5713 int direct = RMAP_IN;
5714 struct route_map *route_map;
5715
5716 peer = peer_and_group_lookup_vty(vty, ip_str);
5717 if (!peer)
5718 return CMD_WARNING_CONFIG_FAILED;
5719
5720 /* Check filter direction. */
5721 if (strncmp(direct_str, "in", 2) == 0)
5722 direct = RMAP_IN;
5723 else if (strncmp(direct_str, "o", 1) == 0)
5724 direct = RMAP_OUT;
5725
5726 route_map = route_map_lookup_warn_noexist(vty, name_str);
5727 ret = peer_route_map_set(peer, afi, safi, direct, name_str, route_map);
5728
5729 return bgp_vty_return(vty, ret);
5730 }
5731
5732 static int peer_route_map_unset_vty(struct vty *vty, const char *ip_str,
5733 afi_t afi, safi_t safi,
5734 const char *direct_str)
5735 {
5736 int ret;
5737 struct peer *peer;
5738 int direct = RMAP_IN;
5739
5740 peer = peer_and_group_lookup_vty(vty, ip_str);
5741 if (!peer)
5742 return CMD_WARNING_CONFIG_FAILED;
5743
5744 /* Check filter direction. */
5745 if (strncmp(direct_str, "in", 2) == 0)
5746 direct = RMAP_IN;
5747 else if (strncmp(direct_str, "o", 1) == 0)
5748 direct = RMAP_OUT;
5749
5750 ret = peer_route_map_unset(peer, afi, safi, direct);
5751
5752 return bgp_vty_return(vty, ret);
5753 }
5754
5755 DEFUN (neighbor_route_map,
5756 neighbor_route_map_cmd,
5757 "neighbor <A.B.C.D|X:X::X:X|WORD> route-map WORD <in|out>",
5758 NEIGHBOR_STR
5759 NEIGHBOR_ADDR_STR2
5760 "Apply route map to neighbor\n"
5761 "Name of route map\n"
5762 "Apply map to incoming routes\n"
5763 "Apply map to outbound routes\n")
5764 {
5765 int idx_peer = 1;
5766 int idx_word = 3;
5767 int idx_in_out = 4;
5768 return peer_route_map_set_vty(
5769 vty, argv[idx_peer]->arg, bgp_node_afi(vty), bgp_node_safi(vty),
5770 argv[idx_word]->arg, argv[idx_in_out]->arg);
5771 }
5772
5773 ALIAS_HIDDEN(neighbor_route_map, neighbor_route_map_hidden_cmd,
5774 "neighbor <A.B.C.D|X:X::X:X|WORD> route-map WORD <in|out>",
5775 NEIGHBOR_STR NEIGHBOR_ADDR_STR2
5776 "Apply route map to neighbor\n"
5777 "Name of route map\n"
5778 "Apply map to incoming routes\n"
5779 "Apply map to outbound routes\n")
5780
5781 DEFUN (no_neighbor_route_map,
5782 no_neighbor_route_map_cmd,
5783 "no neighbor <A.B.C.D|X:X::X:X|WORD> route-map WORD <in|out>",
5784 NO_STR
5785 NEIGHBOR_STR
5786 NEIGHBOR_ADDR_STR2
5787 "Apply route map to neighbor\n"
5788 "Name of route map\n"
5789 "Apply map to incoming routes\n"
5790 "Apply map to outbound routes\n")
5791 {
5792 int idx_peer = 2;
5793 int idx_in_out = 5;
5794 return peer_route_map_unset_vty(vty, argv[idx_peer]->arg,
5795 bgp_node_afi(vty), bgp_node_safi(vty),
5796 argv[idx_in_out]->arg);
5797 }
5798
5799 ALIAS_HIDDEN(no_neighbor_route_map, no_neighbor_route_map_hidden_cmd,
5800 "no neighbor <A.B.C.D|X:X::X:X|WORD> route-map WORD <in|out>",
5801 NO_STR NEIGHBOR_STR NEIGHBOR_ADDR_STR2
5802 "Apply route map to neighbor\n"
5803 "Name of route map\n"
5804 "Apply map to incoming routes\n"
5805 "Apply map to outbound routes\n")
5806
5807 /* Set unsuppress-map to the peer. */
5808 static int peer_unsuppress_map_set_vty(struct vty *vty, const char *ip_str,
5809 afi_t afi, safi_t safi,
5810 const char *name_str)
5811 {
5812 int ret;
5813 struct peer *peer;
5814 struct route_map *route_map;
5815
5816 peer = peer_and_group_lookup_vty(vty, ip_str);
5817 if (!peer)
5818 return CMD_WARNING_CONFIG_FAILED;
5819
5820 route_map = route_map_lookup_warn_noexist(vty, name_str);
5821 ret = peer_unsuppress_map_set(peer, afi, safi, name_str, route_map);
5822
5823 return bgp_vty_return(vty, ret);
5824 }
5825
5826 /* Unset route-map from the peer. */
5827 static int peer_unsuppress_map_unset_vty(struct vty *vty, const char *ip_str,
5828 afi_t afi, safi_t safi)
5829 {
5830 int ret;
5831 struct peer *peer;
5832
5833 peer = peer_and_group_lookup_vty(vty, ip_str);
5834 if (!peer)
5835 return CMD_WARNING_CONFIG_FAILED;
5836
5837 ret = peer_unsuppress_map_unset(peer, afi, safi);
5838
5839 return bgp_vty_return(vty, ret);
5840 }
5841
5842 DEFUN (neighbor_unsuppress_map,
5843 neighbor_unsuppress_map_cmd,
5844 "neighbor <A.B.C.D|X:X::X:X|WORD> unsuppress-map WORD",
5845 NEIGHBOR_STR
5846 NEIGHBOR_ADDR_STR2
5847 "Route-map to selectively unsuppress suppressed routes\n"
5848 "Name of route map\n")
5849 {
5850 int idx_peer = 1;
5851 int idx_word = 3;
5852 return peer_unsuppress_map_set_vty(
5853 vty, argv[idx_peer]->arg, bgp_node_afi(vty), bgp_node_safi(vty),
5854 argv[idx_word]->arg);
5855 }
5856
5857 ALIAS_HIDDEN(neighbor_unsuppress_map, neighbor_unsuppress_map_hidden_cmd,
5858 "neighbor <A.B.C.D|X:X::X:X|WORD> unsuppress-map WORD",
5859 NEIGHBOR_STR NEIGHBOR_ADDR_STR2
5860 "Route-map to selectively unsuppress suppressed routes\n"
5861 "Name of route map\n")
5862
5863 DEFUN (no_neighbor_unsuppress_map,
5864 no_neighbor_unsuppress_map_cmd,
5865 "no neighbor <A.B.C.D|X:X::X:X|WORD> unsuppress-map WORD",
5866 NO_STR
5867 NEIGHBOR_STR
5868 NEIGHBOR_ADDR_STR2
5869 "Route-map to selectively unsuppress suppressed routes\n"
5870 "Name of route map\n")
5871 {
5872 int idx_peer = 2;
5873 return peer_unsuppress_map_unset_vty(vty, argv[idx_peer]->arg,
5874 bgp_node_afi(vty),
5875 bgp_node_safi(vty));
5876 }
5877
5878 ALIAS_HIDDEN(no_neighbor_unsuppress_map, no_neighbor_unsuppress_map_hidden_cmd,
5879 "no neighbor <A.B.C.D|X:X::X:X|WORD> unsuppress-map WORD",
5880 NO_STR NEIGHBOR_STR NEIGHBOR_ADDR_STR2
5881 "Route-map to selectively unsuppress suppressed routes\n"
5882 "Name of route map\n")
5883
5884 static int peer_maximum_prefix_set_vty(struct vty *vty, const char *ip_str,
5885 afi_t afi, safi_t safi,
5886 const char *num_str,
5887 const char *threshold_str, int warning,
5888 const char *restart_str)
5889 {
5890 int ret;
5891 struct peer *peer;
5892 uint32_t max;
5893 uint8_t threshold;
5894 uint16_t restart;
5895
5896 peer = peer_and_group_lookup_vty(vty, ip_str);
5897 if (!peer)
5898 return CMD_WARNING_CONFIG_FAILED;
5899
5900 max = strtoul(num_str, NULL, 10);
5901 if (threshold_str)
5902 threshold = atoi(threshold_str);
5903 else
5904 threshold = MAXIMUM_PREFIX_THRESHOLD_DEFAULT;
5905
5906 if (restart_str)
5907 restart = atoi(restart_str);
5908 else
5909 restart = 0;
5910
5911 ret = peer_maximum_prefix_set(peer, afi, safi, max, threshold, warning,
5912 restart);
5913
5914 return bgp_vty_return(vty, ret);
5915 }
5916
5917 static int peer_maximum_prefix_unset_vty(struct vty *vty, const char *ip_str,
5918 afi_t afi, safi_t safi)
5919 {
5920 int ret;
5921 struct peer *peer;
5922
5923 peer = peer_and_group_lookup_vty(vty, ip_str);
5924 if (!peer)
5925 return CMD_WARNING_CONFIG_FAILED;
5926
5927 ret = peer_maximum_prefix_unset(peer, afi, safi);
5928
5929 return bgp_vty_return(vty, ret);
5930 }
5931
5932 /* Maximum number of prefix configuration. prefix count is different
5933 for each peer configuration. So this configuration can be set for
5934 each peer configuration. */
5935 DEFUN (neighbor_maximum_prefix,
5936 neighbor_maximum_prefix_cmd,
5937 "neighbor <A.B.C.D|X:X::X:X|WORD> maximum-prefix (1-4294967295)",
5938 NEIGHBOR_STR
5939 NEIGHBOR_ADDR_STR2
5940 "Maximum number of prefix accept from this peer\n"
5941 "maximum no. of prefix limit\n")
5942 {
5943 int idx_peer = 1;
5944 int idx_number = 3;
5945 return peer_maximum_prefix_set_vty(
5946 vty, argv[idx_peer]->arg, bgp_node_afi(vty), bgp_node_safi(vty),
5947 argv[idx_number]->arg, NULL, 0, NULL);
5948 }
5949
5950 ALIAS_HIDDEN(neighbor_maximum_prefix, neighbor_maximum_prefix_hidden_cmd,
5951 "neighbor <A.B.C.D|X:X::X:X|WORD> maximum-prefix (1-4294967295)",
5952 NEIGHBOR_STR NEIGHBOR_ADDR_STR2
5953 "Maximum number of prefix accept from this peer\n"
5954 "maximum no. of prefix limit\n")
5955
5956 DEFUN (neighbor_maximum_prefix_threshold,
5957 neighbor_maximum_prefix_threshold_cmd,
5958 "neighbor <A.B.C.D|X:X::X:X|WORD> maximum-prefix (1-4294967295) (1-100)",
5959 NEIGHBOR_STR
5960 NEIGHBOR_ADDR_STR2
5961 "Maximum number of prefix accept from this peer\n"
5962 "maximum no. of prefix limit\n"
5963 "Threshold value (%) at which to generate a warning msg\n")
5964 {
5965 int idx_peer = 1;
5966 int idx_number = 3;
5967 int idx_number_2 = 4;
5968 return peer_maximum_prefix_set_vty(
5969 vty, argv[idx_peer]->arg, bgp_node_afi(vty), bgp_node_safi(vty),
5970 argv[idx_number]->arg, argv[idx_number_2]->arg, 0, NULL);
5971 }
5972
5973 ALIAS_HIDDEN(
5974 neighbor_maximum_prefix_threshold,
5975 neighbor_maximum_prefix_threshold_hidden_cmd,
5976 "neighbor <A.B.C.D|X:X::X:X|WORD> maximum-prefix (1-4294967295) (1-100)",
5977 NEIGHBOR_STR NEIGHBOR_ADDR_STR2
5978 "Maximum number of prefix accept from this peer\n"
5979 "maximum no. of prefix limit\n"
5980 "Threshold value (%) at which to generate a warning msg\n")
5981
5982 DEFUN (neighbor_maximum_prefix_warning,
5983 neighbor_maximum_prefix_warning_cmd,
5984 "neighbor <A.B.C.D|X:X::X:X|WORD> maximum-prefix (1-4294967295) warning-only",
5985 NEIGHBOR_STR
5986 NEIGHBOR_ADDR_STR2
5987 "Maximum number of prefix accept from this peer\n"
5988 "maximum no. of prefix limit\n"
5989 "Only give warning message when limit is exceeded\n")
5990 {
5991 int idx_peer = 1;
5992 int idx_number = 3;
5993 return peer_maximum_prefix_set_vty(
5994 vty, argv[idx_peer]->arg, bgp_node_afi(vty), bgp_node_safi(vty),
5995 argv[idx_number]->arg, NULL, 1, NULL);
5996 }
5997
5998 ALIAS_HIDDEN(
5999 neighbor_maximum_prefix_warning,
6000 neighbor_maximum_prefix_warning_hidden_cmd,
6001 "neighbor <A.B.C.D|X:X::X:X|WORD> maximum-prefix (1-4294967295) warning-only",
6002 NEIGHBOR_STR NEIGHBOR_ADDR_STR2
6003 "Maximum number of prefix accept from this peer\n"
6004 "maximum no. of prefix limit\n"
6005 "Only give warning message when limit is exceeded\n")
6006
6007 DEFUN (neighbor_maximum_prefix_threshold_warning,
6008 neighbor_maximum_prefix_threshold_warning_cmd,
6009 "neighbor <A.B.C.D|X:X::X:X|WORD> maximum-prefix (1-4294967295) (1-100) warning-only",
6010 NEIGHBOR_STR
6011 NEIGHBOR_ADDR_STR2
6012 "Maximum number of prefix accept from this peer\n"
6013 "maximum no. of prefix limit\n"
6014 "Threshold value (%) at which to generate a warning msg\n"
6015 "Only give warning message when limit is exceeded\n")
6016 {
6017 int idx_peer = 1;
6018 int idx_number = 3;
6019 int idx_number_2 = 4;
6020 return peer_maximum_prefix_set_vty(
6021 vty, argv[idx_peer]->arg, bgp_node_afi(vty), bgp_node_safi(vty),
6022 argv[idx_number]->arg, argv[idx_number_2]->arg, 1, NULL);
6023 }
6024
6025 ALIAS_HIDDEN(
6026 neighbor_maximum_prefix_threshold_warning,
6027 neighbor_maximum_prefix_threshold_warning_hidden_cmd,
6028 "neighbor <A.B.C.D|X:X::X:X|WORD> maximum-prefix (1-4294967295) (1-100) warning-only",
6029 NEIGHBOR_STR NEIGHBOR_ADDR_STR2
6030 "Maximum number of prefix accept from this peer\n"
6031 "maximum no. of prefix limit\n"
6032 "Threshold value (%) at which to generate a warning msg\n"
6033 "Only give warning message when limit is exceeded\n")
6034
6035 DEFUN (neighbor_maximum_prefix_restart,
6036 neighbor_maximum_prefix_restart_cmd,
6037 "neighbor <A.B.C.D|X:X::X:X|WORD> maximum-prefix (1-4294967295) restart (1-65535)",
6038 NEIGHBOR_STR
6039 NEIGHBOR_ADDR_STR2
6040 "Maximum number of prefix accept from this peer\n"
6041 "maximum no. of prefix limit\n"
6042 "Restart bgp connection after limit is exceeded\n"
6043 "Restart interval in minutes\n")
6044 {
6045 int idx_peer = 1;
6046 int idx_number = 3;
6047 int idx_number_2 = 5;
6048 return peer_maximum_prefix_set_vty(
6049 vty, argv[idx_peer]->arg, bgp_node_afi(vty), bgp_node_safi(vty),
6050 argv[idx_number]->arg, NULL, 0, argv[idx_number_2]->arg);
6051 }
6052
6053 ALIAS_HIDDEN(
6054 neighbor_maximum_prefix_restart,
6055 neighbor_maximum_prefix_restart_hidden_cmd,
6056 "neighbor <A.B.C.D|X:X::X:X|WORD> maximum-prefix (1-4294967295) restart (1-65535)",
6057 NEIGHBOR_STR NEIGHBOR_ADDR_STR2
6058 "Maximum number of prefix accept from this peer\n"
6059 "maximum no. of prefix limit\n"
6060 "Restart bgp connection after limit is exceeded\n"
6061 "Restart interval in minutes\n")
6062
6063 DEFUN (neighbor_maximum_prefix_threshold_restart,
6064 neighbor_maximum_prefix_threshold_restart_cmd,
6065 "neighbor <A.B.C.D|X:X::X:X|WORD> maximum-prefix (1-4294967295) (1-100) restart (1-65535)",
6066 NEIGHBOR_STR
6067 NEIGHBOR_ADDR_STR2
6068 "Maximum number of prefixes to accept from this peer\n"
6069 "maximum no. of prefix limit\n"
6070 "Threshold value (%) at which to generate a warning msg\n"
6071 "Restart bgp connection after limit is exceeded\n"
6072 "Restart interval in minutes\n")
6073 {
6074 int idx_peer = 1;
6075 int idx_number = 3;
6076 int idx_number_2 = 4;
6077 int idx_number_3 = 6;
6078 return peer_maximum_prefix_set_vty(
6079 vty, argv[idx_peer]->arg, bgp_node_afi(vty), bgp_node_safi(vty),
6080 argv[idx_number]->arg, argv[idx_number_2]->arg, 0,
6081 argv[idx_number_3]->arg);
6082 }
6083
6084 ALIAS_HIDDEN(
6085 neighbor_maximum_prefix_threshold_restart,
6086 neighbor_maximum_prefix_threshold_restart_hidden_cmd,
6087 "neighbor <A.B.C.D|X:X::X:X|WORD> maximum-prefix (1-4294967295) (1-100) restart (1-65535)",
6088 NEIGHBOR_STR NEIGHBOR_ADDR_STR2
6089 "Maximum number of prefixes to accept from this peer\n"
6090 "maximum no. of prefix limit\n"
6091 "Threshold value (%) at which to generate a warning msg\n"
6092 "Restart bgp connection after limit is exceeded\n"
6093 "Restart interval in minutes\n")
6094
6095 DEFUN (no_neighbor_maximum_prefix,
6096 no_neighbor_maximum_prefix_cmd,
6097 "no neighbor <A.B.C.D|X:X::X:X|WORD> maximum-prefix [(1-4294967295) [(1-100)] [restart (1-65535)] [warning-only]]",
6098 NO_STR
6099 NEIGHBOR_STR
6100 NEIGHBOR_ADDR_STR2
6101 "Maximum number of prefixes to accept from this peer\n"
6102 "maximum no. of prefix limit\n"
6103 "Threshold value (%) at which to generate a warning msg\n"
6104 "Restart bgp connection after limit is exceeded\n"
6105 "Restart interval in minutes\n"
6106 "Only give warning message when limit is exceeded\n")
6107 {
6108 int idx_peer = 2;
6109 return peer_maximum_prefix_unset_vty(vty, argv[idx_peer]->arg,
6110 bgp_node_afi(vty),
6111 bgp_node_safi(vty));
6112 }
6113
6114 ALIAS_HIDDEN(
6115 no_neighbor_maximum_prefix, no_neighbor_maximum_prefix_hidden_cmd,
6116 "no neighbor <A.B.C.D|X:X::X:X|WORD> maximum-prefix [(1-4294967295) [(1-100)] [restart (1-65535)] [warning-only]]",
6117 NO_STR NEIGHBOR_STR NEIGHBOR_ADDR_STR2
6118 "Maximum number of prefixes to accept from this peer\n"
6119 "maximum no. of prefix limit\n"
6120 "Threshold value (%) at which to generate a warning msg\n"
6121 "Restart bgp connection after limit is exceeded\n"
6122 "Restart interval in minutes\n"
6123 "Only give warning message when limit is exceeded\n")
6124
6125
6126 /* "neighbor allowas-in" */
6127 DEFUN (neighbor_allowas_in,
6128 neighbor_allowas_in_cmd,
6129 "neighbor <A.B.C.D|X:X::X:X|WORD> allowas-in [<(1-10)|origin>]",
6130 NEIGHBOR_STR
6131 NEIGHBOR_ADDR_STR2
6132 "Accept as-path with my AS present in it\n"
6133 "Number of occurences of AS number\n"
6134 "Only accept my AS in the as-path if the route was originated in my AS\n")
6135 {
6136 int idx_peer = 1;
6137 int idx_number_origin = 3;
6138 int ret;
6139 int origin = 0;
6140 struct peer *peer;
6141 int allow_num = 0;
6142
6143 peer = peer_and_group_lookup_vty(vty, argv[idx_peer]->arg);
6144 if (!peer)
6145 return CMD_WARNING_CONFIG_FAILED;
6146
6147 if (argc <= idx_number_origin)
6148 allow_num = 3;
6149 else {
6150 if (argv[idx_number_origin]->type == WORD_TKN)
6151 origin = 1;
6152 else
6153 allow_num = atoi(argv[idx_number_origin]->arg);
6154 }
6155
6156 ret = peer_allowas_in_set(peer, bgp_node_afi(vty), bgp_node_safi(vty),
6157 allow_num, origin);
6158
6159 return bgp_vty_return(vty, ret);
6160 }
6161
6162 ALIAS_HIDDEN(
6163 neighbor_allowas_in, neighbor_allowas_in_hidden_cmd,
6164 "neighbor <A.B.C.D|X:X::X:X|WORD> allowas-in [<(1-10)|origin>]",
6165 NEIGHBOR_STR NEIGHBOR_ADDR_STR2
6166 "Accept as-path with my AS present in it\n"
6167 "Number of occurences of AS number\n"
6168 "Only accept my AS in the as-path if the route was originated in my AS\n")
6169
6170 DEFUN (no_neighbor_allowas_in,
6171 no_neighbor_allowas_in_cmd,
6172 "no neighbor <A.B.C.D|X:X::X:X|WORD> allowas-in [<(1-10)|origin>]",
6173 NO_STR
6174 NEIGHBOR_STR
6175 NEIGHBOR_ADDR_STR2
6176 "allow local ASN appears in aspath attribute\n"
6177 "Number of occurences of AS number\n"
6178 "Only accept my AS in the as-path if the route was originated in my AS\n")
6179 {
6180 int idx_peer = 2;
6181 int ret;
6182 struct peer *peer;
6183
6184 peer = peer_and_group_lookup_vty(vty, argv[idx_peer]->arg);
6185 if (!peer)
6186 return CMD_WARNING_CONFIG_FAILED;
6187
6188 ret = peer_allowas_in_unset(peer, bgp_node_afi(vty),
6189 bgp_node_safi(vty));
6190
6191 return bgp_vty_return(vty, ret);
6192 }
6193
6194 ALIAS_HIDDEN(
6195 no_neighbor_allowas_in, no_neighbor_allowas_in_hidden_cmd,
6196 "no neighbor <A.B.C.D|X:X::X:X|WORD> allowas-in [<(1-10)|origin>]",
6197 NO_STR NEIGHBOR_STR NEIGHBOR_ADDR_STR2
6198 "allow local ASN appears in aspath attribute\n"
6199 "Number of occurences of AS number\n"
6200 "Only accept my AS in the as-path if the route was originated in my AS\n")
6201
6202 DEFUN (neighbor_ttl_security,
6203 neighbor_ttl_security_cmd,
6204 "neighbor <A.B.C.D|X:X::X:X|WORD> ttl-security hops (1-254)",
6205 NEIGHBOR_STR
6206 NEIGHBOR_ADDR_STR2
6207 "BGP ttl-security parameters\n"
6208 "Specify the maximum number of hops to the BGP peer\n"
6209 "Number of hops to BGP peer\n")
6210 {
6211 int idx_peer = 1;
6212 int idx_number = 4;
6213 struct peer *peer;
6214 int gtsm_hops;
6215
6216 peer = peer_and_group_lookup_vty(vty, argv[idx_peer]->arg);
6217 if (!peer)
6218 return CMD_WARNING_CONFIG_FAILED;
6219
6220 gtsm_hops = strtoul(argv[idx_number]->arg, NULL, 10);
6221
6222 /*
6223 * If 'neighbor swpX', then this is for directly connected peers,
6224 * we should not accept a ttl-security hops value greater than 1.
6225 */
6226 if (peer->conf_if && (gtsm_hops > 1)) {
6227 vty_out(vty,
6228 "%s is directly connected peer, hops cannot exceed 1\n",
6229 argv[idx_peer]->arg);
6230 return CMD_WARNING_CONFIG_FAILED;
6231 }
6232
6233 return bgp_vty_return(vty, peer_ttl_security_hops_set(peer, gtsm_hops));
6234 }
6235
6236 DEFUN (no_neighbor_ttl_security,
6237 no_neighbor_ttl_security_cmd,
6238 "no neighbor <A.B.C.D|X:X::X:X|WORD> ttl-security hops (1-254)",
6239 NO_STR
6240 NEIGHBOR_STR
6241 NEIGHBOR_ADDR_STR2
6242 "BGP ttl-security parameters\n"
6243 "Specify the maximum number of hops to the BGP peer\n"
6244 "Number of hops to BGP peer\n")
6245 {
6246 int idx_peer = 2;
6247 struct peer *peer;
6248
6249 peer = peer_and_group_lookup_vty(vty, argv[idx_peer]->arg);
6250 if (!peer)
6251 return CMD_WARNING_CONFIG_FAILED;
6252
6253 return bgp_vty_return(vty, peer_ttl_security_hops_unset(peer));
6254 }
6255
6256 DEFUN (neighbor_addpath_tx_all_paths,
6257 neighbor_addpath_tx_all_paths_cmd,
6258 "neighbor <A.B.C.D|X:X::X:X|WORD> addpath-tx-all-paths",
6259 NEIGHBOR_STR
6260 NEIGHBOR_ADDR_STR2
6261 "Use addpath to advertise all paths to a neighbor\n")
6262 {
6263 int idx_peer = 1;
6264 struct peer *peer;
6265
6266 peer = peer_and_group_lookup_vty(vty, argv[idx_peer]->arg);
6267 if (!peer)
6268 return CMD_WARNING_CONFIG_FAILED;
6269
6270 bgp_addpath_set_peer_type(peer, bgp_node_afi(vty), bgp_node_safi(vty),
6271 BGP_ADDPATH_ALL);
6272 return CMD_SUCCESS;
6273 }
6274
6275 ALIAS_HIDDEN(neighbor_addpath_tx_all_paths,
6276 neighbor_addpath_tx_all_paths_hidden_cmd,
6277 "neighbor <A.B.C.D|X:X::X:X|WORD> addpath-tx-all-paths",
6278 NEIGHBOR_STR NEIGHBOR_ADDR_STR2
6279 "Use addpath to advertise all paths to a neighbor\n")
6280
6281 DEFUN (no_neighbor_addpath_tx_all_paths,
6282 no_neighbor_addpath_tx_all_paths_cmd,
6283 "no neighbor <A.B.C.D|X:X::X:X|WORD> addpath-tx-all-paths",
6284 NO_STR
6285 NEIGHBOR_STR
6286 NEIGHBOR_ADDR_STR2
6287 "Use addpath to advertise all paths to a neighbor\n")
6288 {
6289 int idx_peer = 2;
6290 struct peer *peer;
6291
6292 peer = peer_and_group_lookup_vty(vty, argv[idx_peer]->arg);
6293 if (!peer)
6294 return CMD_WARNING_CONFIG_FAILED;
6295
6296 if (peer->addpath_type[bgp_node_afi(vty)][bgp_node_safi(vty)]
6297 != BGP_ADDPATH_ALL) {
6298 vty_out(vty,
6299 "%% Peer not currently configured to transmit all paths.");
6300 return CMD_WARNING_CONFIG_FAILED;
6301 }
6302
6303 bgp_addpath_set_peer_type(peer, bgp_node_afi(vty), bgp_node_safi(vty),
6304 BGP_ADDPATH_NONE);
6305
6306 return CMD_SUCCESS;
6307 }
6308
6309 ALIAS_HIDDEN(no_neighbor_addpath_tx_all_paths,
6310 no_neighbor_addpath_tx_all_paths_hidden_cmd,
6311 "no neighbor <A.B.C.D|X:X::X:X|WORD> addpath-tx-all-paths",
6312 NO_STR NEIGHBOR_STR NEIGHBOR_ADDR_STR2
6313 "Use addpath to advertise all paths to a neighbor\n")
6314
6315 DEFUN (neighbor_addpath_tx_bestpath_per_as,
6316 neighbor_addpath_tx_bestpath_per_as_cmd,
6317 "neighbor <A.B.C.D|X:X::X:X|WORD> addpath-tx-bestpath-per-AS",
6318 NEIGHBOR_STR
6319 NEIGHBOR_ADDR_STR2
6320 "Use addpath to advertise the bestpath per each neighboring AS\n")
6321 {
6322 int idx_peer = 1;
6323 struct peer *peer;
6324
6325 peer = peer_and_group_lookup_vty(vty, argv[idx_peer]->arg);
6326 if (!peer)
6327 return CMD_WARNING_CONFIG_FAILED;
6328
6329 bgp_addpath_set_peer_type(peer, bgp_node_afi(vty), bgp_node_safi(vty),
6330 BGP_ADDPATH_BEST_PER_AS);
6331
6332 return CMD_SUCCESS;
6333 }
6334
6335 ALIAS_HIDDEN(neighbor_addpath_tx_bestpath_per_as,
6336 neighbor_addpath_tx_bestpath_per_as_hidden_cmd,
6337 "neighbor <A.B.C.D|X:X::X:X|WORD> addpath-tx-bestpath-per-AS",
6338 NEIGHBOR_STR NEIGHBOR_ADDR_STR2
6339 "Use addpath to advertise the bestpath per each neighboring AS\n")
6340
6341 DEFUN (no_neighbor_addpath_tx_bestpath_per_as,
6342 no_neighbor_addpath_tx_bestpath_per_as_cmd,
6343 "no neighbor <A.B.C.D|X:X::X:X|WORD> addpath-tx-bestpath-per-AS",
6344 NO_STR
6345 NEIGHBOR_STR
6346 NEIGHBOR_ADDR_STR2
6347 "Use addpath to advertise the bestpath per each neighboring AS\n")
6348 {
6349 int idx_peer = 2;
6350 struct peer *peer;
6351
6352 peer = peer_and_group_lookup_vty(vty, argv[idx_peer]->arg);
6353 if (!peer)
6354 return CMD_WARNING_CONFIG_FAILED;
6355
6356 if (peer->addpath_type[bgp_node_afi(vty)][bgp_node_safi(vty)]
6357 != BGP_ADDPATH_BEST_PER_AS) {
6358 vty_out(vty,
6359 "%% Peer not currently configured to transmit all best path per as.");
6360 return CMD_WARNING_CONFIG_FAILED;
6361 }
6362
6363 bgp_addpath_set_peer_type(peer, bgp_node_afi(vty), bgp_node_safi(vty),
6364 BGP_ADDPATH_NONE);
6365
6366 return CMD_SUCCESS;
6367 }
6368
6369 ALIAS_HIDDEN(no_neighbor_addpath_tx_bestpath_per_as,
6370 no_neighbor_addpath_tx_bestpath_per_as_hidden_cmd,
6371 "no neighbor <A.B.C.D|X:X::X:X|WORD> addpath-tx-bestpath-per-AS",
6372 NO_STR NEIGHBOR_STR NEIGHBOR_ADDR_STR2
6373 "Use addpath to advertise the bestpath per each neighboring AS\n")
6374
6375 static int set_ecom_list(struct vty *vty, int argc, struct cmd_token **argv,
6376 struct ecommunity **list)
6377 {
6378 struct ecommunity *ecom = NULL;
6379 struct ecommunity *ecomadd;
6380
6381 for (; argc; --argc, ++argv) {
6382
6383 ecomadd = ecommunity_str2com(argv[0]->arg,
6384 ECOMMUNITY_ROUTE_TARGET, 0);
6385 if (!ecomadd) {
6386 vty_out(vty, "Malformed community-list value\n");
6387 if (ecom)
6388 ecommunity_free(&ecom);
6389 return CMD_WARNING_CONFIG_FAILED;
6390 }
6391
6392 if (ecom) {
6393 ecommunity_merge(ecom, ecomadd);
6394 ecommunity_free(&ecomadd);
6395 } else {
6396 ecom = ecomadd;
6397 }
6398 }
6399
6400 if (*list) {
6401 ecommunity_free(&*list);
6402 }
6403 *list = ecom;
6404
6405 return CMD_SUCCESS;
6406 }
6407
6408 /*
6409 * v2vimport is true if we are handling a `import vrf ...` command
6410 */
6411 static afi_t vpn_policy_getafi(struct vty *vty, struct bgp *bgp, bool v2vimport)
6412 {
6413 afi_t afi;
6414
6415 switch (vty->node) {
6416 case BGP_IPV4_NODE:
6417 afi = AFI_IP;
6418 break;
6419 case BGP_IPV6_NODE:
6420 afi = AFI_IP6;
6421 break;
6422 default:
6423 vty_out(vty,
6424 "%% context error: valid only in address-family <ipv4|ipv6> unicast block\n");
6425 return AFI_MAX;
6426 }
6427
6428 if (!v2vimport) {
6429 if (CHECK_FLAG(bgp->af_flags[afi][SAFI_UNICAST],
6430 BGP_CONFIG_VRF_TO_VRF_IMPORT)
6431 || CHECK_FLAG(bgp->af_flags[afi][SAFI_UNICAST],
6432 BGP_CONFIG_VRF_TO_VRF_EXPORT)) {
6433 vty_out(vty,
6434 "%% error: Please unconfigure import vrf commands before using vpn commands\n");
6435 return AFI_MAX;
6436 }
6437 } else {
6438 if (CHECK_FLAG(bgp->af_flags[afi][SAFI_UNICAST],
6439 BGP_CONFIG_VRF_TO_MPLSVPN_EXPORT)
6440 || CHECK_FLAG(bgp->af_flags[afi][SAFI_UNICAST],
6441 BGP_CONFIG_MPLSVPN_TO_VRF_IMPORT)) {
6442 vty_out(vty,
6443 "%% error: Please unconfigure vpn to vrf commands before using import vrf commands\n");
6444 return AFI_MAX;
6445 }
6446 }
6447 return afi;
6448 }
6449
6450 DEFPY (af_rd_vpn_export,
6451 af_rd_vpn_export_cmd,
6452 "[no] rd vpn export ASN:NN_OR_IP-ADDRESS:NN$rd_str",
6453 NO_STR
6454 "Specify route distinguisher\n"
6455 "Between current address-family and vpn\n"
6456 "For routes leaked from current address-family to vpn\n"
6457 "Route Distinguisher (<as-number>:<number> | <ip-address>:<number>)\n")
6458 {
6459 VTY_DECLVAR_CONTEXT(bgp, bgp);
6460 struct prefix_rd prd;
6461 int ret;
6462 afi_t afi;
6463 int idx = 0;
6464 int yes = 1;
6465
6466 if (argv_find(argv, argc, "no", &idx))
6467 yes = 0;
6468
6469 if (yes) {
6470 ret = str2prefix_rd(rd_str, &prd);
6471 if (!ret) {
6472 vty_out(vty, "%% Malformed rd\n");
6473 return CMD_WARNING_CONFIG_FAILED;
6474 }
6475 }
6476
6477 afi = vpn_policy_getafi(vty, bgp, false);
6478 if (afi == AFI_MAX)
6479 return CMD_WARNING_CONFIG_FAILED;
6480
6481 /*
6482 * pre-change: un-export vpn routes (vpn->vrf routes unaffected)
6483 */
6484 vpn_leak_prechange(BGP_VPN_POLICY_DIR_TOVPN, afi,
6485 bgp_get_default(), bgp);
6486
6487 if (yes) {
6488 bgp->vpn_policy[afi].tovpn_rd = prd;
6489 SET_FLAG(bgp->vpn_policy[afi].flags,
6490 BGP_VPN_POLICY_TOVPN_RD_SET);
6491 } else {
6492 UNSET_FLAG(bgp->vpn_policy[afi].flags,
6493 BGP_VPN_POLICY_TOVPN_RD_SET);
6494 }
6495
6496 /* post-change: re-export vpn routes */
6497 vpn_leak_postchange(BGP_VPN_POLICY_DIR_TOVPN, afi,
6498 bgp_get_default(), bgp);
6499
6500 return CMD_SUCCESS;
6501 }
6502
6503 ALIAS (af_rd_vpn_export,
6504 af_no_rd_vpn_export_cmd,
6505 "no rd vpn export",
6506 NO_STR
6507 "Specify route distinguisher\n"
6508 "Between current address-family and vpn\n"
6509 "For routes leaked from current address-family to vpn\n")
6510
6511 DEFPY (af_label_vpn_export,
6512 af_label_vpn_export_cmd,
6513 "[no] label vpn export <(0-1048575)$label_val|auto$label_auto>",
6514 NO_STR
6515 "label value for VRF\n"
6516 "Between current address-family and vpn\n"
6517 "For routes leaked from current address-family to vpn\n"
6518 "Label Value <0-1048575>\n"
6519 "Automatically assign a label\n")
6520 {
6521 VTY_DECLVAR_CONTEXT(bgp, bgp);
6522 mpls_label_t label = MPLS_LABEL_NONE;
6523 afi_t afi;
6524 int idx = 0;
6525 int yes = 1;
6526
6527 if (argv_find(argv, argc, "no", &idx))
6528 yes = 0;
6529
6530 /* If "no ...", squash trailing parameter */
6531 if (!yes)
6532 label_auto = NULL;
6533
6534 if (yes) {
6535 if (!label_auto)
6536 label = label_val; /* parser should force unsigned */
6537 }
6538
6539 afi = vpn_policy_getafi(vty, bgp, false);
6540 if (afi == AFI_MAX)
6541 return CMD_WARNING_CONFIG_FAILED;
6542
6543
6544 if (label_auto && CHECK_FLAG(bgp->vpn_policy[afi].flags,
6545 BGP_VPN_POLICY_TOVPN_LABEL_AUTO))
6546 /* no change */
6547 return CMD_SUCCESS;
6548
6549 /*
6550 * pre-change: un-export vpn routes (vpn->vrf routes unaffected)
6551 */
6552 vpn_leak_prechange(BGP_VPN_POLICY_DIR_TOVPN, afi,
6553 bgp_get_default(), bgp);
6554
6555 if (!label_auto && CHECK_FLAG(bgp->vpn_policy[afi].flags,
6556 BGP_VPN_POLICY_TOVPN_LABEL_AUTO)) {
6557
6558 if (bgp->vpn_policy[afi].tovpn_label != MPLS_LABEL_NONE) {
6559
6560 /*
6561 * label has previously been automatically
6562 * assigned by labelpool: release it
6563 *
6564 * NB if tovpn_label == MPLS_LABEL_NONE it
6565 * means the automatic assignment is in flight
6566 * and therefore the labelpool callback must
6567 * detect that the auto label is not needed.
6568 */
6569
6570 bgp_lp_release(LP_TYPE_VRF,
6571 &bgp->vpn_policy[afi],
6572 bgp->vpn_policy[afi].tovpn_label);
6573 }
6574 UNSET_FLAG(bgp->vpn_policy[afi].flags,
6575 BGP_VPN_POLICY_TOVPN_LABEL_AUTO);
6576 }
6577
6578 bgp->vpn_policy[afi].tovpn_label = label;
6579 if (label_auto) {
6580 SET_FLAG(bgp->vpn_policy[afi].flags,
6581 BGP_VPN_POLICY_TOVPN_LABEL_AUTO);
6582 bgp_lp_get(LP_TYPE_VRF, &bgp->vpn_policy[afi],
6583 vpn_leak_label_callback);
6584 }
6585
6586 /* post-change: re-export vpn routes */
6587 vpn_leak_postchange(BGP_VPN_POLICY_DIR_TOVPN, afi,
6588 bgp_get_default(), bgp);
6589
6590 return CMD_SUCCESS;
6591 }
6592
6593 ALIAS (af_label_vpn_export,
6594 af_no_label_vpn_export_cmd,
6595 "no label vpn export",
6596 NO_STR
6597 "label value for VRF\n"
6598 "Between current address-family and vpn\n"
6599 "For routes leaked from current address-family to vpn\n")
6600
6601 DEFPY (af_nexthop_vpn_export,
6602 af_nexthop_vpn_export_cmd,
6603 "[no] nexthop vpn export <A.B.C.D|X:X::X:X>$nexthop_str",
6604 NO_STR
6605 "Specify next hop to use for VRF advertised prefixes\n"
6606 "Between current address-family and vpn\n"
6607 "For routes leaked from current address-family to vpn\n"
6608 "IPv4 prefix\n"
6609 "IPv6 prefix\n")
6610 {
6611 VTY_DECLVAR_CONTEXT(bgp, bgp);
6612 afi_t afi;
6613 struct prefix p;
6614 int idx = 0;
6615 int yes = 1;
6616
6617 if (argv_find(argv, argc, "no", &idx))
6618 yes = 0;
6619
6620 if (yes) {
6621 if (!sockunion2hostprefix(nexthop_str, &p))
6622 return CMD_WARNING_CONFIG_FAILED;
6623 }
6624
6625 afi = vpn_policy_getafi(vty, bgp, false);
6626 if (afi == AFI_MAX)
6627 return CMD_WARNING_CONFIG_FAILED;
6628
6629 /*
6630 * pre-change: un-export vpn routes (vpn->vrf routes unaffected)
6631 */
6632 vpn_leak_prechange(BGP_VPN_POLICY_DIR_TOVPN, afi,
6633 bgp_get_default(), bgp);
6634
6635 if (yes) {
6636 bgp->vpn_policy[afi].tovpn_nexthop = p;
6637 SET_FLAG(bgp->vpn_policy[afi].flags,
6638 BGP_VPN_POLICY_TOVPN_NEXTHOP_SET);
6639 } else {
6640 UNSET_FLAG(bgp->vpn_policy[afi].flags,
6641 BGP_VPN_POLICY_TOVPN_NEXTHOP_SET);
6642 }
6643
6644 /* post-change: re-export vpn routes */
6645 vpn_leak_postchange(BGP_VPN_POLICY_DIR_TOVPN, afi,
6646 bgp_get_default(), bgp);
6647
6648 return CMD_SUCCESS;
6649 }
6650
6651 ALIAS (af_nexthop_vpn_export,
6652 af_no_nexthop_vpn_export_cmd,
6653 "no nexthop vpn export",
6654 NO_STR
6655 "Specify next hop to use for VRF advertised prefixes\n"
6656 "Between current address-family and vpn\n"
6657 "For routes leaked from current address-family to vpn\n")
6658
6659 static int vpn_policy_getdirs(struct vty *vty, const char *dstr, int *dodir)
6660 {
6661 if (!strcmp(dstr, "import")) {
6662 dodir[BGP_VPN_POLICY_DIR_FROMVPN] = 1;
6663 } else if (!strcmp(dstr, "export")) {
6664 dodir[BGP_VPN_POLICY_DIR_TOVPN] = 1;
6665 } else if (!strcmp(dstr, "both")) {
6666 dodir[BGP_VPN_POLICY_DIR_FROMVPN] = 1;
6667 dodir[BGP_VPN_POLICY_DIR_TOVPN] = 1;
6668 } else {
6669 vty_out(vty, "%% direction parse error\n");
6670 return CMD_WARNING_CONFIG_FAILED;
6671 }
6672 return CMD_SUCCESS;
6673 }
6674
6675 DEFPY (af_rt_vpn_imexport,
6676 af_rt_vpn_imexport_cmd,
6677 "[no] <rt|route-target> vpn <import|export|both>$direction_str RTLIST...",
6678 NO_STR
6679 "Specify route target list\n"
6680 "Specify route target list\n"
6681 "Between current address-family and vpn\n"
6682 "For routes leaked from vpn to current address-family: match any\n"
6683 "For routes leaked from current address-family to vpn: set\n"
6684 "both import: match any and export: set\n"
6685 "Space separated route target list (A.B.C.D:MN|EF:OPQR|GHJK:MN)\n")
6686 {
6687 VTY_DECLVAR_CONTEXT(bgp, bgp);
6688 int ret;
6689 struct ecommunity *ecom = NULL;
6690 int dodir[BGP_VPN_POLICY_DIR_MAX] = {0};
6691 vpn_policy_direction_t dir;
6692 afi_t afi;
6693 int idx = 0;
6694 int yes = 1;
6695
6696 if (argv_find(argv, argc, "no", &idx))
6697 yes = 0;
6698
6699 afi = vpn_policy_getafi(vty, bgp, false);
6700 if (afi == AFI_MAX)
6701 return CMD_WARNING_CONFIG_FAILED;
6702
6703 ret = vpn_policy_getdirs(vty, direction_str, dodir);
6704 if (ret != CMD_SUCCESS)
6705 return ret;
6706
6707 if (yes) {
6708 if (!argv_find(argv, argc, "RTLIST", &idx)) {
6709 vty_out(vty, "%% Missing RTLIST\n");
6710 return CMD_WARNING_CONFIG_FAILED;
6711 }
6712 ret = set_ecom_list(vty, argc - idx, argv + idx, &ecom);
6713 if (ret != CMD_SUCCESS) {
6714 return ret;
6715 }
6716 }
6717
6718 for (dir = 0; dir < BGP_VPN_POLICY_DIR_MAX; ++dir) {
6719 if (!dodir[dir])
6720 continue;
6721
6722 vpn_leak_prechange(dir, afi, bgp_get_default(), bgp);
6723
6724 if (yes) {
6725 if (bgp->vpn_policy[afi].rtlist[dir])
6726 ecommunity_free(
6727 &bgp->vpn_policy[afi].rtlist[dir]);
6728 bgp->vpn_policy[afi].rtlist[dir] =
6729 ecommunity_dup(ecom);
6730 } else {
6731 if (bgp->vpn_policy[afi].rtlist[dir])
6732 ecommunity_free(
6733 &bgp->vpn_policy[afi].rtlist[dir]);
6734 bgp->vpn_policy[afi].rtlist[dir] = NULL;
6735 }
6736
6737 vpn_leak_postchange(dir, afi, bgp_get_default(), bgp);
6738 }
6739
6740 if (ecom)
6741 ecommunity_free(&ecom);
6742
6743 return CMD_SUCCESS;
6744 }
6745
6746 ALIAS (af_rt_vpn_imexport,
6747 af_no_rt_vpn_imexport_cmd,
6748 "no <rt|route-target> vpn <import|export|both>$direction_str",
6749 NO_STR
6750 "Specify route target list\n"
6751 "Specify route target list\n"
6752 "Between current address-family and vpn\n"
6753 "For routes leaked from vpn to current address-family\n"
6754 "For routes leaked from current address-family to vpn\n"
6755 "both import and export\n")
6756
6757 DEFPY (af_route_map_vpn_imexport,
6758 af_route_map_vpn_imexport_cmd,
6759 /* future: "route-map <vpn|evpn|vrf NAME> <import|export> RMAP" */
6760 "[no] route-map vpn <import|export>$direction_str RMAP$rmap_str",
6761 NO_STR
6762 "Specify route map\n"
6763 "Between current address-family and vpn\n"
6764 "For routes leaked from vpn to current address-family\n"
6765 "For routes leaked from current address-family to vpn\n"
6766 "name of route-map\n")
6767 {
6768 VTY_DECLVAR_CONTEXT(bgp, bgp);
6769 int ret;
6770 int dodir[BGP_VPN_POLICY_DIR_MAX] = {0};
6771 vpn_policy_direction_t dir;
6772 afi_t afi;
6773 int idx = 0;
6774 int yes = 1;
6775
6776 if (argv_find(argv, argc, "no", &idx))
6777 yes = 0;
6778
6779 afi = vpn_policy_getafi(vty, bgp, false);
6780 if (afi == AFI_MAX)
6781 return CMD_WARNING_CONFIG_FAILED;
6782
6783 ret = vpn_policy_getdirs(vty, direction_str, dodir);
6784 if (ret != CMD_SUCCESS)
6785 return ret;
6786
6787 for (dir = 0; dir < BGP_VPN_POLICY_DIR_MAX; ++dir) {
6788 if (!dodir[dir])
6789 continue;
6790
6791 vpn_leak_prechange(dir, afi, bgp_get_default(), bgp);
6792
6793 if (yes) {
6794 if (bgp->vpn_policy[afi].rmap_name[dir])
6795 XFREE(MTYPE_ROUTE_MAP_NAME,
6796 bgp->vpn_policy[afi].rmap_name[dir]);
6797 bgp->vpn_policy[afi].rmap_name[dir] = XSTRDUP(
6798 MTYPE_ROUTE_MAP_NAME, rmap_str);
6799 bgp->vpn_policy[afi].rmap[dir] =
6800 route_map_lookup_warn_noexist(vty, rmap_str);
6801 if (!bgp->vpn_policy[afi].rmap[dir])
6802 return CMD_SUCCESS;
6803 } else {
6804 if (bgp->vpn_policy[afi].rmap_name[dir])
6805 XFREE(MTYPE_ROUTE_MAP_NAME,
6806 bgp->vpn_policy[afi].rmap_name[dir]);
6807 bgp->vpn_policy[afi].rmap_name[dir] = NULL;
6808 bgp->vpn_policy[afi].rmap[dir] = NULL;
6809 }
6810
6811 vpn_leak_postchange(dir, afi, bgp_get_default(), bgp);
6812 }
6813
6814 return CMD_SUCCESS;
6815 }
6816
6817 ALIAS (af_route_map_vpn_imexport,
6818 af_no_route_map_vpn_imexport_cmd,
6819 "no route-map vpn <import|export>$direction_str",
6820 NO_STR
6821 "Specify route map\n"
6822 "Between current address-family and vpn\n"
6823 "For routes leaked from vpn to current address-family\n"
6824 "For routes leaked from current address-family to vpn\n")
6825
6826 DEFPY(af_import_vrf_route_map, af_import_vrf_route_map_cmd,
6827 "[no] import vrf route-map RMAP$rmap_str",
6828 NO_STR
6829 "Import routes from another VRF\n"
6830 "Vrf routes being filtered\n"
6831 "Specify route map\n"
6832 "name of route-map\n")
6833 {
6834 VTY_DECLVAR_CONTEXT(bgp, bgp);
6835 vpn_policy_direction_t dir = BGP_VPN_POLICY_DIR_FROMVPN;
6836 afi_t afi;
6837 int idx = 0;
6838 int yes = 1;
6839 struct bgp *bgp_default;
6840
6841 if (argv_find(argv, argc, "no", &idx))
6842 yes = 0;
6843
6844 afi = vpn_policy_getafi(vty, bgp, true);
6845 if (afi == AFI_MAX)
6846 return CMD_WARNING_CONFIG_FAILED;
6847
6848 bgp_default = bgp_get_default();
6849 if (!bgp_default) {
6850 int32_t ret;
6851 as_t as = bgp->as;
6852
6853 /* Auto-create assuming the same AS */
6854 ret = bgp_get(&bgp_default, &as, NULL,
6855 BGP_INSTANCE_TYPE_DEFAULT);
6856
6857 if (ret) {
6858 vty_out(vty,
6859 "VRF default is not configured as a bgp instance\n");
6860 return CMD_WARNING;
6861 }
6862 }
6863
6864 vpn_leak_prechange(dir, afi, bgp_get_default(), bgp);
6865
6866 if (yes) {
6867 if (bgp->vpn_policy[afi].rmap_name[dir])
6868 XFREE(MTYPE_ROUTE_MAP_NAME,
6869 bgp->vpn_policy[afi].rmap_name[dir]);
6870 bgp->vpn_policy[afi].rmap_name[dir] =
6871 XSTRDUP(MTYPE_ROUTE_MAP_NAME, rmap_str);
6872 bgp->vpn_policy[afi].rmap[dir] =
6873 route_map_lookup_warn_noexist(vty, rmap_str);
6874 if (!bgp->vpn_policy[afi].rmap[dir])
6875 return CMD_SUCCESS;
6876 } else {
6877 if (bgp->vpn_policy[afi].rmap_name[dir])
6878 XFREE(MTYPE_ROUTE_MAP_NAME,
6879 bgp->vpn_policy[afi].rmap_name[dir]);
6880 bgp->vpn_policy[afi].rmap_name[dir] = NULL;
6881 bgp->vpn_policy[afi].rmap[dir] = NULL;
6882 }
6883
6884 vpn_leak_postchange(dir, afi, bgp_get_default(), bgp);
6885
6886 return CMD_SUCCESS;
6887 }
6888
6889 ALIAS(af_import_vrf_route_map, af_no_import_vrf_route_map_cmd,
6890 "no import vrf route-map",
6891 NO_STR
6892 "Import routes from another VRF\n"
6893 "Vrf routes being filtered\n"
6894 "Specify route map\n")
6895
6896 DEFPY(bgp_imexport_vrf, bgp_imexport_vrf_cmd,
6897 "[no] import vrf VIEWVRFNAME$import_name",
6898 NO_STR
6899 "Import routes from another VRF\n"
6900 "VRF to import from\n"
6901 "The name of the VRF\n")
6902 {
6903 VTY_DECLVAR_CONTEXT(bgp, bgp);
6904 struct listnode *node;
6905 struct bgp *vrf_bgp, *bgp_default;
6906 int32_t ret = 0;
6907 as_t as = bgp->as;
6908 bool remove = false;
6909 int32_t idx = 0;
6910 char *vname;
6911 enum bgp_instance_type bgp_type = BGP_INSTANCE_TYPE_VRF;
6912 safi_t safi;
6913 afi_t afi;
6914
6915 if (import_name == NULL) {
6916 vty_out(vty, "%% Missing import name\n");
6917 return CMD_WARNING;
6918 }
6919
6920 if (argv_find(argv, argc, "no", &idx))
6921 remove = true;
6922
6923 afi = vpn_policy_getafi(vty, bgp, true);
6924 if (afi == AFI_MAX)
6925 return CMD_WARNING_CONFIG_FAILED;
6926
6927 safi = bgp_node_safi(vty);
6928
6929 if (((BGP_INSTANCE_TYPE_DEFAULT == bgp->inst_type)
6930 && (strcmp(import_name, VRF_DEFAULT_NAME) == 0))
6931 || (bgp->name && (strcmp(import_name, bgp->name) == 0))) {
6932 vty_out(vty, "%% Cannot %s vrf %s into itself\n",
6933 remove ? "unimport" : "import", import_name);
6934 return CMD_WARNING;
6935 }
6936
6937 bgp_default = bgp_get_default();
6938 if (!bgp_default) {
6939 /* Auto-create assuming the same AS */
6940 ret = bgp_get(&bgp_default, &as, NULL,
6941 BGP_INSTANCE_TYPE_DEFAULT);
6942
6943 if (ret) {
6944 vty_out(vty,
6945 "VRF default is not configured as a bgp instance\n");
6946 return CMD_WARNING;
6947 }
6948 }
6949
6950 vrf_bgp = bgp_lookup_by_name(import_name);
6951 if (!vrf_bgp) {
6952 if (strcmp(import_name, VRF_DEFAULT_NAME) == 0)
6953 vrf_bgp = bgp_default;
6954 else
6955 /* Auto-create assuming the same AS */
6956 ret = bgp_get(&vrf_bgp, &as, import_name, bgp_type);
6957
6958 if (ret) {
6959 vty_out(vty,
6960 "VRF %s is not configured as a bgp instance\n",
6961 import_name);
6962 return CMD_WARNING;
6963 }
6964 }
6965
6966 if (remove) {
6967 vrf_unimport_from_vrf(bgp, vrf_bgp, afi, safi);
6968 } else {
6969 /* Already importing from "import_vrf"? */
6970 for (ALL_LIST_ELEMENTS_RO(bgp->vpn_policy[afi].import_vrf, node,
6971 vname)) {
6972 if (strcmp(vname, import_name) == 0)
6973 return CMD_WARNING;
6974 }
6975
6976 vrf_import_from_vrf(bgp, vrf_bgp, afi, safi);
6977 }
6978
6979 return CMD_SUCCESS;
6980 }
6981
6982 /* This command is valid only in a bgp vrf instance or the default instance */
6983 DEFPY (bgp_imexport_vpn,
6984 bgp_imexport_vpn_cmd,
6985 "[no] <import|export>$direction_str vpn",
6986 NO_STR
6987 "Import routes to this address-family\n"
6988 "Export routes from this address-family\n"
6989 "to/from default instance VPN RIB\n")
6990 {
6991 VTY_DECLVAR_CONTEXT(bgp, bgp);
6992 int previous_state;
6993 afi_t afi;
6994 safi_t safi;
6995 int idx = 0;
6996 int yes = 1;
6997 int flag;
6998 vpn_policy_direction_t dir;
6999
7000 if (argv_find(argv, argc, "no", &idx))
7001 yes = 0;
7002
7003 if (BGP_INSTANCE_TYPE_VRF != bgp->inst_type &&
7004 BGP_INSTANCE_TYPE_DEFAULT != bgp->inst_type) {
7005
7006 vty_out(vty, "%% import|export vpn valid only for bgp vrf or default instance\n");
7007 return CMD_WARNING_CONFIG_FAILED;
7008 }
7009
7010 afi = bgp_node_afi(vty);
7011 safi = bgp_node_safi(vty);
7012 if ((SAFI_UNICAST != safi) || ((AFI_IP != afi) && (AFI_IP6 != afi))) {
7013 vty_out(vty, "%% import|export vpn valid only for unicast ipv4|ipv6\n");
7014 return CMD_WARNING_CONFIG_FAILED;
7015 }
7016
7017 if (!strcmp(direction_str, "import")) {
7018 flag = BGP_CONFIG_MPLSVPN_TO_VRF_IMPORT;
7019 dir = BGP_VPN_POLICY_DIR_FROMVPN;
7020 } else if (!strcmp(direction_str, "export")) {
7021 flag = BGP_CONFIG_VRF_TO_MPLSVPN_EXPORT;
7022 dir = BGP_VPN_POLICY_DIR_TOVPN;
7023 } else {
7024 vty_out(vty, "%% unknown direction %s\n", direction_str);
7025 return CMD_WARNING_CONFIG_FAILED;
7026 }
7027
7028 previous_state = CHECK_FLAG(bgp->af_flags[afi][safi], flag);
7029
7030 if (yes) {
7031 SET_FLAG(bgp->af_flags[afi][safi], flag);
7032 if (!previous_state) {
7033 /* trigger export current vrf */
7034 vpn_leak_postchange(dir, afi, bgp_get_default(), bgp);
7035 }
7036 } else {
7037 if (previous_state) {
7038 /* trigger un-export current vrf */
7039 vpn_leak_prechange(dir, afi, bgp_get_default(), bgp);
7040 }
7041 UNSET_FLAG(bgp->af_flags[afi][safi], flag);
7042 }
7043
7044 return CMD_SUCCESS;
7045 }
7046
7047 DEFPY (af_routetarget_import,
7048 af_routetarget_import_cmd,
7049 "[no] <rt|route-target> redirect import RTLIST...",
7050 NO_STR
7051 "Specify route target list\n"
7052 "Specify route target list\n"
7053 "Flow-spec redirect type route target\n"
7054 "Import routes to this address-family\n"
7055 "Space separated route target list (A.B.C.D:MN|EF:OPQR|GHJK:MN)\n")
7056 {
7057 VTY_DECLVAR_CONTEXT(bgp, bgp);
7058 int ret;
7059 struct ecommunity *ecom = NULL;
7060 afi_t afi;
7061 int idx = 0;
7062 int yes = 1;
7063
7064 if (argv_find(argv, argc, "no", &idx))
7065 yes = 0;
7066
7067 afi = vpn_policy_getafi(vty, bgp, false);
7068 if (afi == AFI_MAX)
7069 return CMD_WARNING_CONFIG_FAILED;
7070
7071 if (yes) {
7072 if (!argv_find(argv, argc, "RTLIST", &idx)) {
7073 vty_out(vty, "%% Missing RTLIST\n");
7074 return CMD_WARNING_CONFIG_FAILED;
7075 }
7076 ret = set_ecom_list(vty, argc - idx, argv + idx, &ecom);
7077 if (ret != CMD_SUCCESS)
7078 return ret;
7079 }
7080
7081 if (yes) {
7082 if (bgp->vpn_policy[afi].import_redirect_rtlist)
7083 ecommunity_free(&bgp->vpn_policy[afi]
7084 .import_redirect_rtlist);
7085 bgp->vpn_policy[afi].import_redirect_rtlist =
7086 ecommunity_dup(ecom);
7087 } else {
7088 if (bgp->vpn_policy[afi].import_redirect_rtlist)
7089 ecommunity_free(&bgp->vpn_policy[afi]
7090 .import_redirect_rtlist);
7091 bgp->vpn_policy[afi].import_redirect_rtlist = NULL;
7092 }
7093
7094 if (ecom)
7095 ecommunity_free(&ecom);
7096
7097 return CMD_SUCCESS;
7098 }
7099
7100 DEFUN_NOSH (address_family_ipv4_safi,
7101 address_family_ipv4_safi_cmd,
7102 "address-family ipv4 [<unicast|multicast|vpn|labeled-unicast|flowspec>]",
7103 "Enter Address Family command mode\n"
7104 "Address Family\n"
7105 BGP_SAFI_WITH_LABEL_HELP_STR)
7106 {
7107
7108 if (argc == 3) {
7109 VTY_DECLVAR_CONTEXT(bgp, bgp);
7110 safi_t safi = bgp_vty_safi_from_str(argv[2]->text);
7111 if (bgp->inst_type != BGP_INSTANCE_TYPE_DEFAULT
7112 && safi != SAFI_UNICAST && safi != SAFI_MULTICAST
7113 && safi != SAFI_EVPN) {
7114 vty_out(vty,
7115 "Only Unicast/Multicast/EVPN SAFIs supported in non-core instances.\n");
7116 return CMD_WARNING_CONFIG_FAILED;
7117 }
7118 vty->node = bgp_node_type(AFI_IP, safi);
7119 } else
7120 vty->node = BGP_IPV4_NODE;
7121
7122 return CMD_SUCCESS;
7123 }
7124
7125 DEFUN_NOSH (address_family_ipv6_safi,
7126 address_family_ipv6_safi_cmd,
7127 "address-family ipv6 [<unicast|multicast|vpn|labeled-unicast|flowspec>]",
7128 "Enter Address Family command mode\n"
7129 "Address Family\n"
7130 BGP_SAFI_WITH_LABEL_HELP_STR)
7131 {
7132 if (argc == 3) {
7133 VTY_DECLVAR_CONTEXT(bgp, bgp);
7134 safi_t safi = bgp_vty_safi_from_str(argv[2]->text);
7135 if (bgp->inst_type != BGP_INSTANCE_TYPE_DEFAULT
7136 && safi != SAFI_UNICAST && safi != SAFI_MULTICAST
7137 && safi != SAFI_EVPN) {
7138 vty_out(vty,
7139 "Only Unicast/Multicast/EVPN SAFIs supported in non-core instances.\n");
7140 return CMD_WARNING_CONFIG_FAILED;
7141 }
7142 vty->node = bgp_node_type(AFI_IP6, safi);
7143 } else
7144 vty->node = BGP_IPV6_NODE;
7145
7146 return CMD_SUCCESS;
7147 }
7148
7149 #ifdef KEEP_OLD_VPN_COMMANDS
7150 DEFUN_NOSH (address_family_vpnv4,
7151 address_family_vpnv4_cmd,
7152 "address-family vpnv4 [unicast]",
7153 "Enter Address Family command mode\n"
7154 "Address Family\n"
7155 "Address Family modifier\n")
7156 {
7157 vty->node = BGP_VPNV4_NODE;
7158 return CMD_SUCCESS;
7159 }
7160
7161 DEFUN_NOSH (address_family_vpnv6,
7162 address_family_vpnv6_cmd,
7163 "address-family vpnv6 [unicast]",
7164 "Enter Address Family command mode\n"
7165 "Address Family\n"
7166 "Address Family modifier\n")
7167 {
7168 vty->node = BGP_VPNV6_NODE;
7169 return CMD_SUCCESS;
7170 }
7171 #endif /* KEEP_OLD_VPN_COMMANDS */
7172
7173 DEFUN_NOSH (address_family_evpn,
7174 address_family_evpn_cmd,
7175 "address-family l2vpn evpn",
7176 "Enter Address Family command mode\n"
7177 "Address Family\n"
7178 "Address Family modifier\n")
7179 {
7180 VTY_DECLVAR_CONTEXT(bgp, bgp);
7181 vty->node = BGP_EVPN_NODE;
7182 return CMD_SUCCESS;
7183 }
7184
7185 DEFUN_NOSH (exit_address_family,
7186 exit_address_family_cmd,
7187 "exit-address-family",
7188 "Exit from Address Family configuration mode\n")
7189 {
7190 if (vty->node == BGP_IPV4_NODE || vty->node == BGP_IPV4M_NODE
7191 || vty->node == BGP_IPV4L_NODE || vty->node == BGP_VPNV4_NODE
7192 || vty->node == BGP_IPV6_NODE || vty->node == BGP_IPV6M_NODE
7193 || vty->node == BGP_IPV6L_NODE || vty->node == BGP_VPNV6_NODE
7194 || vty->node == BGP_EVPN_NODE
7195 || vty->node == BGP_FLOWSPECV4_NODE
7196 || vty->node == BGP_FLOWSPECV6_NODE)
7197 vty->node = BGP_NODE;
7198 return CMD_SUCCESS;
7199 }
7200
7201 /* Recalculate bestpath and re-advertise a prefix */
7202 static int bgp_clear_prefix(struct vty *vty, const char *view_name,
7203 const char *ip_str, afi_t afi, safi_t safi,
7204 struct prefix_rd *prd)
7205 {
7206 int ret;
7207 struct prefix match;
7208 struct bgp_node *rn;
7209 struct bgp_node *rm;
7210 struct bgp *bgp;
7211 struct bgp_table *table;
7212 struct bgp_table *rib;
7213
7214 /* BGP structure lookup. */
7215 if (view_name) {
7216 bgp = bgp_lookup_by_name(view_name);
7217 if (bgp == NULL) {
7218 vty_out(vty, "%% Can't find BGP instance %s\n",
7219 view_name);
7220 return CMD_WARNING;
7221 }
7222 } else {
7223 bgp = bgp_get_default();
7224 if (bgp == NULL) {
7225 vty_out(vty, "%% No BGP process is configured\n");
7226 return CMD_WARNING;
7227 }
7228 }
7229
7230 /* Check IP address argument. */
7231 ret = str2prefix(ip_str, &match);
7232 if (!ret) {
7233 vty_out(vty, "%% address is malformed\n");
7234 return CMD_WARNING;
7235 }
7236
7237 match.family = afi2family(afi);
7238 rib = bgp->rib[afi][safi];
7239
7240 if (safi == SAFI_MPLS_VPN) {
7241 for (rn = bgp_table_top(rib); rn; rn = bgp_route_next(rn)) {
7242 if (prd && memcmp(rn->p.u.val, prd->val, 8) != 0)
7243 continue;
7244
7245 table = bgp_node_get_bgp_table_info(rn);
7246 if (table != NULL) {
7247
7248 if ((rm = bgp_node_match(table, &match))
7249 != NULL) {
7250 if (rm->p.prefixlen
7251 == match.prefixlen) {
7252 SET_FLAG(rm->flags,
7253 BGP_NODE_USER_CLEAR);
7254 bgp_process(bgp, rm, afi, safi);
7255 }
7256 bgp_unlock_node(rm);
7257 }
7258 }
7259 }
7260 } else {
7261 if ((rn = bgp_node_match(rib, &match)) != NULL) {
7262 if (rn->p.prefixlen == match.prefixlen) {
7263 SET_FLAG(rn->flags, BGP_NODE_USER_CLEAR);
7264 bgp_process(bgp, rn, afi, safi);
7265 }
7266 bgp_unlock_node(rn);
7267 }
7268 }
7269
7270 return CMD_SUCCESS;
7271 }
7272
7273 /* one clear bgp command to rule them all */
7274 DEFUN (clear_ip_bgp_all,
7275 clear_ip_bgp_all_cmd,
7276 "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>]",
7277 CLEAR_STR
7278 IP_STR
7279 BGP_STR
7280 BGP_INSTANCE_HELP_STR
7281 BGP_AFI_HELP_STR
7282 "Address Family\n"
7283 BGP_SAFI_WITH_LABEL_HELP_STR
7284 "Address Family modifier\n"
7285 "Clear all peers\n"
7286 "BGP neighbor address to clear\n"
7287 "BGP IPv6 neighbor to clear\n"
7288 "BGP neighbor on interface to clear\n"
7289 "Clear peers with the AS number\n"
7290 "Clear all external peers\n"
7291 "Clear all members of peer-group\n"
7292 "BGP peer-group name\n"
7293 BGP_SOFT_STR
7294 BGP_SOFT_IN_STR
7295 BGP_SOFT_OUT_STR
7296 BGP_SOFT_IN_STR
7297 "Push out prefix-list ORF and do inbound soft reconfig\n"
7298 BGP_SOFT_OUT_STR)
7299 {
7300 char *vrf = NULL;
7301
7302 afi_t afi = AFI_IP6;
7303 safi_t safi = SAFI_UNICAST;
7304 enum clear_sort clr_sort = clear_peer;
7305 enum bgp_clear_type clr_type;
7306 char *clr_arg = NULL;
7307
7308 int idx = 0;
7309
7310 /* clear [ip] bgp */
7311 if (argv_find(argv, argc, "ip", &idx))
7312 afi = AFI_IP;
7313
7314 /* [<vrf> VIEWVRFNAME] */
7315 if (argv_find(argv, argc, "vrf", &idx)) {
7316 vrf = argv[idx + 1]->arg;
7317 idx += 2;
7318 if (vrf && strmatch(vrf, VRF_DEFAULT_NAME))
7319 vrf = NULL;
7320 } else if (argv_find(argv, argc, "view", &idx)) {
7321 /* [<view> VIEWVRFNAME] */
7322 vrf = argv[idx + 1]->arg;
7323 idx += 2;
7324 }
7325 /* ["BGP_AFI_CMD_STR" ["BGP_SAFI_CMD_STR"]] */
7326 if (argv_find_and_parse_afi(argv, argc, &idx, &afi))
7327 argv_find_and_parse_safi(argv, argc, &idx, &safi);
7328
7329 /* <*|A.B.C.D|X:X::X:X|WORD|(1-4294967295)|external|peer-group WORD> */
7330 if (argv_find(argv, argc, "*", &idx)) {
7331 clr_sort = clear_all;
7332 } else if (argv_find(argv, argc, "A.B.C.D", &idx)) {
7333 clr_sort = clear_peer;
7334 clr_arg = argv[idx]->arg;
7335 } else if (argv_find(argv, argc, "X:X::X:X", &idx)) {
7336 clr_sort = clear_peer;
7337 clr_arg = argv[idx]->arg;
7338 } else if (argv_find(argv, argc, "peer-group", &idx)) {
7339 clr_sort = clear_group;
7340 idx++;
7341 clr_arg = argv[idx]->arg;
7342 } else if (argv_find(argv, argc, "WORD", &idx)) {
7343 clr_sort = clear_peer;
7344 clr_arg = argv[idx]->arg;
7345 } else if (argv_find(argv, argc, "(1-4294967295)", &idx)) {
7346 clr_sort = clear_as;
7347 clr_arg = argv[idx]->arg;
7348 } else if (argv_find(argv, argc, "external", &idx)) {
7349 clr_sort = clear_external;
7350 }
7351
7352 /* [<soft [<in|out>]|in [prefix-filter]|out>] */
7353 if (argv_find(argv, argc, "soft", &idx)) {
7354 if (argv_find(argv, argc, "in", &idx)
7355 || argv_find(argv, argc, "out", &idx))
7356 clr_type = strmatch(argv[idx]->text, "in")
7357 ? BGP_CLEAR_SOFT_IN
7358 : BGP_CLEAR_SOFT_OUT;
7359 else
7360 clr_type = BGP_CLEAR_SOFT_BOTH;
7361 } else if (argv_find(argv, argc, "in", &idx)) {
7362 clr_type = argv_find(argv, argc, "prefix-filter", &idx)
7363 ? BGP_CLEAR_SOFT_IN_ORF_PREFIX
7364 : BGP_CLEAR_SOFT_IN;
7365 } else if (argv_find(argv, argc, "out", &idx)) {
7366 clr_type = BGP_CLEAR_SOFT_OUT;
7367 } else
7368 clr_type = BGP_CLEAR_SOFT_NONE;
7369
7370 return bgp_clear_vty(vty, vrf, afi, safi, clr_sort, clr_type, clr_arg);
7371 }
7372
7373 DEFUN (clear_ip_bgp_prefix,
7374 clear_ip_bgp_prefix_cmd,
7375 "clear [ip] bgp [<view|vrf> VIEWVRFNAME] prefix A.B.C.D/M",
7376 CLEAR_STR
7377 IP_STR
7378 BGP_STR
7379 BGP_INSTANCE_HELP_STR
7380 "Clear bestpath and re-advertise\n"
7381 "IPv4 prefix\n")
7382 {
7383 char *vrf = NULL;
7384 char *prefix = NULL;
7385
7386 int idx = 0;
7387
7388 /* [<view|vrf> VIEWVRFNAME] */
7389 if (argv_find(argv, argc, "vrf", &idx)) {
7390 vrf = argv[idx + 1]->arg;
7391 idx += 2;
7392 if (vrf && strmatch(vrf, VRF_DEFAULT_NAME))
7393 vrf = NULL;
7394 } else if (argv_find(argv, argc, "view", &idx)) {
7395 /* [<view> VIEWVRFNAME] */
7396 vrf = argv[idx + 1]->arg;
7397 idx += 2;
7398 }
7399
7400 prefix = argv[argc - 1]->arg;
7401
7402 return bgp_clear_prefix(vty, vrf, prefix, AFI_IP, SAFI_UNICAST, NULL);
7403 }
7404
7405 DEFUN (clear_bgp_ipv6_safi_prefix,
7406 clear_bgp_ipv6_safi_prefix_cmd,
7407 "clear [ip] bgp ipv6 "BGP_SAFI_CMD_STR" prefix X:X::X:X/M",
7408 CLEAR_STR
7409 IP_STR
7410 BGP_STR
7411 "Address Family\n"
7412 BGP_SAFI_HELP_STR
7413 "Clear bestpath and re-advertise\n"
7414 "IPv6 prefix\n")
7415 {
7416 int idx_safi = 0;
7417 int idx_ipv6_prefix = 0;
7418 safi_t safi = SAFI_UNICAST;
7419 char *prefix = argv_find(argv, argc, "X:X::X:X/M", &idx_ipv6_prefix) ?
7420 argv[idx_ipv6_prefix]->arg : NULL;
7421
7422 argv_find_and_parse_safi(argv, argc, &idx_safi, &safi);
7423 return bgp_clear_prefix(
7424 vty, NULL, prefix, AFI_IP6,
7425 safi, NULL);
7426 }
7427
7428 DEFUN (clear_bgp_instance_ipv6_safi_prefix,
7429 clear_bgp_instance_ipv6_safi_prefix_cmd,
7430 "clear [ip] bgp <view|vrf> VIEWVRFNAME ipv6 "BGP_SAFI_CMD_STR" prefix X:X::X:X/M",
7431 CLEAR_STR
7432 IP_STR
7433 BGP_STR
7434 BGP_INSTANCE_HELP_STR
7435 "Address Family\n"
7436 BGP_SAFI_HELP_STR
7437 "Clear bestpath and re-advertise\n"
7438 "IPv6 prefix\n")
7439 {
7440 int idx_safi = 0;
7441 int idx_vrfview = 0;
7442 int idx_ipv6_prefix = 0;
7443 safi_t safi = SAFI_UNICAST;
7444 char *prefix = argv_find(argv, argc, "X:X::X:X/M", &idx_ipv6_prefix) ?
7445 argv[idx_ipv6_prefix]->arg : NULL;
7446 char *vrfview = NULL;
7447
7448 /* [<view|vrf> VIEWVRFNAME] */
7449 if (argv_find(argv, argc, "vrf", &idx_vrfview)) {
7450 vrfview = argv[idx_vrfview + 1]->arg;
7451 if (vrfview && strmatch(vrfview, VRF_DEFAULT_NAME))
7452 vrfview = NULL;
7453 } else if (argv_find(argv, argc, "view", &idx_vrfview)) {
7454 /* [<view> VIEWVRFNAME] */
7455 vrfview = argv[idx_vrfview + 1]->arg;
7456 }
7457 argv_find_and_parse_safi(argv, argc, &idx_safi, &safi);
7458
7459 return bgp_clear_prefix(
7460 vty, vrfview, prefix,
7461 AFI_IP6, safi, NULL);
7462 }
7463
7464 DEFUN (show_bgp_views,
7465 show_bgp_views_cmd,
7466 "show [ip] bgp views",
7467 SHOW_STR
7468 IP_STR
7469 BGP_STR
7470 "Show the defined BGP views\n")
7471 {
7472 struct list *inst = bm->bgp;
7473 struct listnode *node;
7474 struct bgp *bgp;
7475
7476 if (!bgp_option_check(BGP_OPT_MULTIPLE_INSTANCE)) {
7477 vty_out(vty, "BGP Multiple Instance is not enabled\n");
7478 return CMD_WARNING;
7479 }
7480
7481 vty_out(vty, "Defined BGP views:\n");
7482 for (ALL_LIST_ELEMENTS_RO(inst, node, bgp)) {
7483 /* Skip VRFs. */
7484 if (bgp->inst_type == BGP_INSTANCE_TYPE_VRF)
7485 continue;
7486 vty_out(vty, "\t%s (AS%u)\n", bgp->name ? bgp->name : "(null)",
7487 bgp->as);
7488 }
7489
7490 return CMD_SUCCESS;
7491 }
7492
7493 DEFUN (show_bgp_vrfs,
7494 show_bgp_vrfs_cmd,
7495 "show [ip] bgp vrfs [json]",
7496 SHOW_STR
7497 IP_STR
7498 BGP_STR
7499 "Show BGP VRFs\n"
7500 JSON_STR)
7501 {
7502 char buf[ETHER_ADDR_STRLEN];
7503 struct list *inst = bm->bgp;
7504 struct listnode *node;
7505 struct bgp *bgp;
7506 bool uj = use_json(argc, argv);
7507 json_object *json = NULL;
7508 json_object *json_vrfs = NULL;
7509 int count = 0;
7510
7511 if (!bgp_option_check(BGP_OPT_MULTIPLE_INSTANCE)) {
7512 vty_out(vty, "BGP Multiple Instance is not enabled\n");
7513 return CMD_WARNING;
7514 }
7515
7516 if (uj) {
7517 json = json_object_new_object();
7518 json_vrfs = json_object_new_object();
7519 }
7520
7521 for (ALL_LIST_ELEMENTS_RO(inst, node, bgp)) {
7522 const char *name, *type;
7523 struct peer *peer;
7524 struct listnode *node2, *nnode2;
7525 int peers_cfg, peers_estb;
7526 json_object *json_vrf = NULL;
7527
7528 /* Skip Views. */
7529 if (bgp->inst_type == BGP_INSTANCE_TYPE_VIEW)
7530 continue;
7531
7532 count++;
7533 if (!uj && count == 1)
7534 vty_out(vty,
7535 "%4s %-5s %-16s %9s %10s %-37s %-10s %-15s\n",
7536 "Type", "Id", "routerId", "#PeersVfg",
7537 "#PeersEstb", "Name", "L3-VNI", "Rmac");
7538
7539 peers_cfg = peers_estb = 0;
7540 if (uj)
7541 json_vrf = json_object_new_object();
7542
7543
7544 for (ALL_LIST_ELEMENTS(bgp->peer, node2, nnode2, peer)) {
7545 if (!CHECK_FLAG(peer->flags, PEER_FLAG_CONFIG_NODE))
7546 continue;
7547 peers_cfg++;
7548 if (peer->status == Established)
7549 peers_estb++;
7550 }
7551
7552 if (bgp->inst_type == BGP_INSTANCE_TYPE_DEFAULT) {
7553 name = VRF_DEFAULT_NAME;
7554 type = "DFLT";
7555 } else {
7556 name = bgp->name;
7557 type = "VRF";
7558 }
7559
7560
7561 if (uj) {
7562 int64_t vrf_id_ui = (bgp->vrf_id == VRF_UNKNOWN)
7563 ? -1
7564 : (int64_t)bgp->vrf_id;
7565 json_object_string_add(json_vrf, "type", type);
7566 json_object_int_add(json_vrf, "vrfId", vrf_id_ui);
7567 json_object_string_add(json_vrf, "routerId",
7568 inet_ntoa(bgp->router_id));
7569 json_object_int_add(json_vrf, "numConfiguredPeers",
7570 peers_cfg);
7571 json_object_int_add(json_vrf, "numEstablishedPeers",
7572 peers_estb);
7573
7574 json_object_int_add(json_vrf, "l3vni", bgp->l3vni);
7575 json_object_string_add(
7576 json_vrf, "rmac",
7577 prefix_mac2str(&bgp->rmac, buf, sizeof(buf)));
7578 json_object_object_add(json_vrfs, name, json_vrf);
7579 } else
7580 vty_out(vty,
7581 "%4s %-5d %-16s %9u %10u %-37s %-10u %-15s\n",
7582 type,
7583 bgp->vrf_id == VRF_UNKNOWN ? -1
7584 : (int)bgp->vrf_id,
7585 inet_ntoa(bgp->router_id), peers_cfg,
7586 peers_estb, name, bgp->l3vni,
7587 prefix_mac2str(&bgp->rmac, buf, sizeof(buf)));
7588 }
7589
7590 if (uj) {
7591 json_object_object_add(json, "vrfs", json_vrfs);
7592
7593 json_object_int_add(json, "totalVrfs", count);
7594
7595 vty_out(vty, "%s\n", json_object_to_json_string_ext(
7596 json, JSON_C_TO_STRING_PRETTY));
7597 json_object_free(json);
7598 } else {
7599 if (count)
7600 vty_out(vty,
7601 "\nTotal number of VRFs (including default): %d\n",
7602 count);
7603 }
7604
7605 return CMD_SUCCESS;
7606 }
7607
7608 DEFUN (show_bgp_mac_hash,
7609 show_bgp_mac_hash_cmd,
7610 "show bgp mac hash",
7611 SHOW_STR
7612 BGP_STR
7613 "Mac Address\n"
7614 "Mac Address database\n")
7615 {
7616 bgp_mac_dump_table(vty);
7617
7618 return CMD_SUCCESS;
7619 }
7620
7621 static void show_tip_entry(struct hash_bucket *bucket, void *args)
7622 {
7623 struct vty *vty = (struct vty *)args;
7624 struct tip_addr *tip = (struct tip_addr *)bucket->data;
7625
7626 vty_out(vty, "addr: %s, count: %d\n", inet_ntoa(tip->addr),
7627 tip->refcnt);
7628 }
7629
7630 static void bgp_show_martian_nexthops(struct vty *vty, struct bgp *bgp)
7631 {
7632 vty_out(vty, "self nexthop database:\n");
7633 bgp_nexthop_show_address_hash(vty, bgp);
7634
7635 vty_out(vty, "Tunnel-ip database:\n");
7636 hash_iterate(bgp->tip_hash,
7637 (void (*)(struct hash_bucket *, void *))show_tip_entry,
7638 vty);
7639 }
7640
7641 DEFUN(show_bgp_martian_nexthop_db, show_bgp_martian_nexthop_db_cmd,
7642 "show bgp [<view|vrf> VIEWVRFNAME] martian next-hop",
7643 SHOW_STR BGP_STR BGP_INSTANCE_HELP_STR
7644 "martian next-hops\n"
7645 "martian next-hop database\n")
7646 {
7647 struct bgp *bgp = NULL;
7648 int idx = 0;
7649 char *name = NULL;
7650
7651 /* [<vrf> VIEWVRFNAME] */
7652 if (argv_find(argv, argc, "vrf", &idx)) {
7653 name = argv[idx + 1]->arg;
7654 if (name && strmatch(name, VRF_DEFAULT_NAME))
7655 name = NULL;
7656 } else if (argv_find(argv, argc, "view", &idx))
7657 /* [<view> VIEWVRFNAME] */
7658 name = argv[idx + 1]->arg;
7659 if (name)
7660 bgp = bgp_lookup_by_name(name);
7661 else
7662 bgp = bgp_get_default();
7663
7664 if (!bgp) {
7665 vty_out(vty, "%% No BGP process is configured\n");
7666 return CMD_WARNING;
7667 }
7668 bgp_show_martian_nexthops(vty, bgp);
7669
7670 return CMD_SUCCESS;
7671 }
7672
7673 DEFUN (show_bgp_memory,
7674 show_bgp_memory_cmd,
7675 "show [ip] bgp memory",
7676 SHOW_STR
7677 IP_STR
7678 BGP_STR
7679 "Global BGP memory statistics\n")
7680 {
7681 char memstrbuf[MTYPE_MEMSTR_LEN];
7682 unsigned long count;
7683
7684 /* RIB related usage stats */
7685 count = mtype_stats_alloc(MTYPE_BGP_NODE);
7686 vty_out(vty, "%ld RIB nodes, using %s of memory\n", count,
7687 mtype_memstr(memstrbuf, sizeof(memstrbuf),
7688 count * sizeof(struct bgp_node)));
7689
7690 count = mtype_stats_alloc(MTYPE_BGP_ROUTE);
7691 vty_out(vty, "%ld BGP routes, using %s of memory\n", count,
7692 mtype_memstr(memstrbuf, sizeof(memstrbuf),
7693 count * sizeof(struct bgp_path_info)));
7694 if ((count = mtype_stats_alloc(MTYPE_BGP_ROUTE_EXTRA)))
7695 vty_out(vty, "%ld BGP route ancillaries, using %s of memory\n",
7696 count,
7697 mtype_memstr(
7698 memstrbuf, sizeof(memstrbuf),
7699 count * sizeof(struct bgp_path_info_extra)));
7700
7701 if ((count = mtype_stats_alloc(MTYPE_BGP_STATIC)))
7702 vty_out(vty, "%ld Static routes, using %s of memory\n", count,
7703 mtype_memstr(memstrbuf, sizeof(memstrbuf),
7704 count * sizeof(struct bgp_static)));
7705
7706 if ((count = mtype_stats_alloc(MTYPE_BGP_PACKET)))
7707 vty_out(vty, "%ld Packets, using %s of memory\n", count,
7708 mtype_memstr(memstrbuf, sizeof(memstrbuf),
7709 count * sizeof(struct bpacket)));
7710
7711 /* Adj-In/Out */
7712 if ((count = mtype_stats_alloc(MTYPE_BGP_ADJ_IN)))
7713 vty_out(vty, "%ld Adj-In entries, using %s of memory\n", count,
7714 mtype_memstr(memstrbuf, sizeof(memstrbuf),
7715 count * sizeof(struct bgp_adj_in)));
7716 if ((count = mtype_stats_alloc(MTYPE_BGP_ADJ_OUT)))
7717 vty_out(vty, "%ld Adj-Out entries, using %s of memory\n", count,
7718 mtype_memstr(memstrbuf, sizeof(memstrbuf),
7719 count * sizeof(struct bgp_adj_out)));
7720
7721 if ((count = mtype_stats_alloc(MTYPE_BGP_NEXTHOP_CACHE)))
7722 vty_out(vty, "%ld Nexthop cache entries, using %s of memory\n",
7723 count,
7724 mtype_memstr(memstrbuf, sizeof(memstrbuf),
7725 count * sizeof(struct bgp_nexthop_cache)));
7726
7727 if ((count = mtype_stats_alloc(MTYPE_BGP_DAMP_INFO)))
7728 vty_out(vty, "%ld Dampening entries, using %s of memory\n",
7729 count,
7730 mtype_memstr(memstrbuf, sizeof(memstrbuf),
7731 count * sizeof(struct bgp_damp_info)));
7732
7733 /* Attributes */
7734 count = attr_count();
7735 vty_out(vty, "%ld BGP attributes, using %s of memory\n", count,
7736 mtype_memstr(memstrbuf, sizeof(memstrbuf),
7737 count * sizeof(struct attr)));
7738
7739 if ((count = attr_unknown_count()))
7740 vty_out(vty, "%ld unknown attributes\n", count);
7741
7742 /* AS_PATH attributes */
7743 count = aspath_count();
7744 vty_out(vty, "%ld BGP AS-PATH entries, using %s of memory\n", count,
7745 mtype_memstr(memstrbuf, sizeof(memstrbuf),
7746 count * sizeof(struct aspath)));
7747
7748 count = mtype_stats_alloc(MTYPE_AS_SEG);
7749 vty_out(vty, "%ld BGP AS-PATH segments, using %s of memory\n", count,
7750 mtype_memstr(memstrbuf, sizeof(memstrbuf),
7751 count * sizeof(struct assegment)));
7752
7753 /* Other attributes */
7754 if ((count = community_count()))
7755 vty_out(vty, "%ld BGP community entries, using %s of memory\n",
7756 count, mtype_memstr(memstrbuf, sizeof(memstrbuf),
7757 count * sizeof(struct community)));
7758 if ((count = mtype_stats_alloc(MTYPE_ECOMMUNITY)))
7759 vty_out(vty, "%ld BGP community entries, using %s of memory\n",
7760 count, mtype_memstr(memstrbuf, sizeof(memstrbuf),
7761 count * sizeof(struct ecommunity)));
7762 if ((count = mtype_stats_alloc(MTYPE_LCOMMUNITY)))
7763 vty_out(vty,
7764 "%ld BGP large-community entries, using %s of memory\n",
7765 count, mtype_memstr(memstrbuf, sizeof(memstrbuf),
7766 count * sizeof(struct lcommunity)));
7767
7768 if ((count = mtype_stats_alloc(MTYPE_CLUSTER)))
7769 vty_out(vty, "%ld Cluster lists, using %s of memory\n", count,
7770 mtype_memstr(memstrbuf, sizeof(memstrbuf),
7771 count * sizeof(struct cluster_list)));
7772
7773 /* Peer related usage */
7774 count = mtype_stats_alloc(MTYPE_BGP_PEER);
7775 vty_out(vty, "%ld peers, using %s of memory\n", count,
7776 mtype_memstr(memstrbuf, sizeof(memstrbuf),
7777 count * sizeof(struct peer)));
7778
7779 if ((count = mtype_stats_alloc(MTYPE_PEER_GROUP)))
7780 vty_out(vty, "%ld peer groups, using %s of memory\n", count,
7781 mtype_memstr(memstrbuf, sizeof(memstrbuf),
7782 count * sizeof(struct peer_group)));
7783
7784 /* Other */
7785 if ((count = mtype_stats_alloc(MTYPE_HASH)))
7786 vty_out(vty, "%ld hash tables, using %s of memory\n", count,
7787 mtype_memstr(memstrbuf, sizeof(memstrbuf),
7788 count * sizeof(struct hash)));
7789 if ((count = mtype_stats_alloc(MTYPE_HASH_BACKET)))
7790 vty_out(vty, "%ld hash buckets, using %s of memory\n", count,
7791 mtype_memstr(memstrbuf, sizeof(memstrbuf),
7792 count * sizeof(struct hash_bucket)));
7793 if ((count = mtype_stats_alloc(MTYPE_BGP_REGEXP)))
7794 vty_out(vty, "%ld compiled regexes, using %s of memory\n",
7795 count, mtype_memstr(memstrbuf, sizeof(memstrbuf),
7796 count * sizeof(regex_t)));
7797 return CMD_SUCCESS;
7798 }
7799
7800 static void bgp_show_bestpath_json(struct bgp *bgp, json_object *json)
7801 {
7802 json_object *bestpath = json_object_new_object();
7803
7804 if (bgp_flag_check(bgp, BGP_FLAG_ASPATH_IGNORE))
7805 json_object_string_add(bestpath, "asPath", "ignore");
7806
7807 if (bgp_flag_check(bgp, BGP_FLAG_ASPATH_CONFED))
7808 json_object_string_add(bestpath, "asPath", "confed");
7809
7810 if (bgp_flag_check(bgp, BGP_FLAG_ASPATH_MULTIPATH_RELAX)) {
7811 if (bgp_flag_check(bgp, BGP_FLAG_MULTIPATH_RELAX_AS_SET))
7812 json_object_string_add(bestpath, "multiPathRelax",
7813 "as-set");
7814 else
7815 json_object_string_add(bestpath, "multiPathRelax",
7816 "true");
7817 } else
7818 json_object_string_add(bestpath, "multiPathRelax", "false");
7819
7820 if (bgp_flag_check(bgp, BGP_FLAG_COMPARE_ROUTER_ID))
7821 json_object_string_add(bestpath, "compareRouterId", "true");
7822 if (bgp_flag_check(bgp, BGP_FLAG_MED_CONFED)
7823 || bgp_flag_check(bgp, BGP_FLAG_MED_MISSING_AS_WORST)) {
7824 if (bgp_flag_check(bgp, BGP_FLAG_MED_CONFED))
7825 json_object_string_add(bestpath, "med", "confed");
7826 if (bgp_flag_check(bgp, BGP_FLAG_MED_MISSING_AS_WORST))
7827 json_object_string_add(bestpath, "med",
7828 "missing-as-worst");
7829 else
7830 json_object_string_add(bestpath, "med", "true");
7831 }
7832
7833 json_object_object_add(json, "bestPath", bestpath);
7834 }
7835
7836 /* Show BGP peer's summary information. */
7837 static int bgp_show_summary(struct vty *vty, struct bgp *bgp, int afi, int safi,
7838 bool use_json, json_object *json)
7839 {
7840 struct peer *peer;
7841 struct listnode *node, *nnode;
7842 unsigned int count = 0, dn_count = 0;
7843 char timebuf[BGP_UPTIME_LEN], dn_flag[2];
7844 char neighbor_buf[VTY_BUFSIZ];
7845 int neighbor_col_default_width = 16;
7846 int len;
7847 int max_neighbor_width = 0;
7848 int pfx_rcd_safi;
7849 json_object *json_peer = NULL;
7850 json_object *json_peers = NULL;
7851 struct peer_af *paf;
7852
7853 /* labeled-unicast routes are installed in the unicast table so in order
7854 * to
7855 * display the correct PfxRcd value we must look at SAFI_UNICAST
7856 */
7857 if (safi == SAFI_LABELED_UNICAST)
7858 pfx_rcd_safi = SAFI_UNICAST;
7859 else
7860 pfx_rcd_safi = safi;
7861
7862 if (use_json) {
7863 if (json == NULL)
7864 json = json_object_new_object();
7865
7866 json_peers = json_object_new_object();
7867 } else {
7868 /* Loop over all neighbors that will be displayed to determine
7869 * how many
7870 * characters are needed for the Neighbor column
7871 */
7872 for (ALL_LIST_ELEMENTS(bgp->peer, node, nnode, peer)) {
7873 if (!CHECK_FLAG(peer->flags, PEER_FLAG_CONFIG_NODE))
7874 continue;
7875
7876 if (peer->afc[afi][safi]) {
7877 memset(dn_flag, '\0', sizeof(dn_flag));
7878 if (peer_dynamic_neighbor(peer))
7879 dn_flag[0] = '*';
7880
7881 if (peer->hostname
7882 && bgp_flag_check(bgp,
7883 BGP_FLAG_SHOW_HOSTNAME))
7884 sprintf(neighbor_buf, "%s%s(%s) ",
7885 dn_flag, peer->hostname,
7886 peer->host);
7887 else
7888 sprintf(neighbor_buf, "%s%s ", dn_flag,
7889 peer->host);
7890
7891 len = strlen(neighbor_buf);
7892
7893 if (len > max_neighbor_width)
7894 max_neighbor_width = len;
7895 }
7896 }
7897
7898 /* Originally we displayed the Neighbor column as 16
7899 * characters wide so make that the default
7900 */
7901 if (max_neighbor_width < neighbor_col_default_width)
7902 max_neighbor_width = neighbor_col_default_width;
7903 }
7904
7905 for (ALL_LIST_ELEMENTS(bgp->peer, node, nnode, peer)) {
7906 if (!CHECK_FLAG(peer->flags, PEER_FLAG_CONFIG_NODE))
7907 continue;
7908
7909 if (!peer->afc[afi][safi])
7910 continue;
7911
7912 if (!count) {
7913 unsigned long ents;
7914 char memstrbuf[MTYPE_MEMSTR_LEN];
7915 int64_t vrf_id_ui;
7916
7917 vrf_id_ui = (bgp->vrf_id == VRF_UNKNOWN)
7918 ? -1
7919 : (int64_t)bgp->vrf_id;
7920
7921 /* Usage summary and header */
7922 if (use_json) {
7923 json_object_string_add(
7924 json, "routerId",
7925 inet_ntoa(bgp->router_id));
7926 json_object_int_add(json, "as", bgp->as);
7927 json_object_int_add(json, "vrfId", vrf_id_ui);
7928 json_object_string_add(
7929 json, "vrfName",
7930 (bgp->inst_type
7931 == BGP_INSTANCE_TYPE_DEFAULT)
7932 ? VRF_DEFAULT_NAME
7933 : bgp->name);
7934 } else {
7935 vty_out(vty,
7936 "BGP router identifier %s, local AS number %u vrf-id %d",
7937 inet_ntoa(bgp->router_id), bgp->as,
7938 bgp->vrf_id == VRF_UNKNOWN
7939 ? -1
7940 : (int)bgp->vrf_id);
7941 vty_out(vty, "\n");
7942 }
7943
7944 if (bgp_update_delay_configured(bgp)) {
7945 if (use_json) {
7946 json_object_int_add(
7947 json, "updateDelayLimit",
7948 bgp->v_update_delay);
7949
7950 if (bgp->v_update_delay
7951 != bgp->v_establish_wait)
7952 json_object_int_add(
7953 json,
7954 "updateDelayEstablishWait",
7955 bgp->v_establish_wait);
7956
7957 if (bgp_update_delay_active(bgp)) {
7958 json_object_string_add(
7959 json,
7960 "updateDelayFirstNeighbor",
7961 bgp->update_delay_begin_time);
7962 json_object_boolean_true_add(
7963 json,
7964 "updateDelayInProgress");
7965 } else {
7966 if (bgp->update_delay_over) {
7967 json_object_string_add(
7968 json,
7969 "updateDelayFirstNeighbor",
7970 bgp->update_delay_begin_time);
7971 json_object_string_add(
7972 json,
7973 "updateDelayBestpathResumed",
7974 bgp->update_delay_end_time);
7975 json_object_string_add(
7976 json,
7977 "updateDelayZebraUpdateResume",
7978 bgp->update_delay_zebra_resume_time);
7979 json_object_string_add(
7980 json,
7981 "updateDelayPeerUpdateResume",
7982 bgp->update_delay_peers_resume_time);
7983 }
7984 }
7985 } else {
7986 vty_out(vty,
7987 "Read-only mode update-delay limit: %d seconds\n",
7988 bgp->v_update_delay);
7989 if (bgp->v_update_delay
7990 != bgp->v_establish_wait)
7991 vty_out(vty,
7992 " Establish wait: %d seconds\n",
7993 bgp->v_establish_wait);
7994
7995 if (bgp_update_delay_active(bgp)) {
7996 vty_out(vty,
7997 " First neighbor established: %s\n",
7998 bgp->update_delay_begin_time);
7999 vty_out(vty,
8000 " Delay in progress\n");
8001 } else {
8002 if (bgp->update_delay_over) {
8003 vty_out(vty,
8004 " First neighbor established: %s\n",
8005 bgp->update_delay_begin_time);
8006 vty_out(vty,
8007 " Best-paths resumed: %s\n",
8008 bgp->update_delay_end_time);
8009 vty_out(vty,
8010 " zebra update resumed: %s\n",
8011 bgp->update_delay_zebra_resume_time);
8012 vty_out(vty,
8013 " peers update resumed: %s\n",
8014 bgp->update_delay_peers_resume_time);
8015 }
8016 }
8017 }
8018 }
8019
8020 if (use_json) {
8021 if (bgp_maxmed_onstartup_configured(bgp)
8022 && bgp->maxmed_active)
8023 json_object_boolean_true_add(
8024 json, "maxMedOnStartup");
8025 if (bgp->v_maxmed_admin)
8026 json_object_boolean_true_add(
8027 json, "maxMedAdministrative");
8028
8029 json_object_int_add(
8030 json, "tableVersion",
8031 bgp_table_version(bgp->rib[afi][safi]));
8032
8033 ents = bgp_table_count(bgp->rib[afi][safi]);
8034 json_object_int_add(json, "ribCount", ents);
8035 json_object_int_add(
8036 json, "ribMemory",
8037 ents * sizeof(struct bgp_node));
8038
8039 ents = bgp->af_peer_count[afi][safi];
8040 json_object_int_add(json, "peerCount", ents);
8041 json_object_int_add(json, "peerMemory",
8042 ents * sizeof(struct peer));
8043
8044 if ((ents = listcount(bgp->group))) {
8045 json_object_int_add(
8046 json, "peerGroupCount", ents);
8047 json_object_int_add(
8048 json, "peerGroupMemory",
8049 ents * sizeof(struct
8050 peer_group));
8051 }
8052
8053 if (CHECK_FLAG(bgp->af_flags[afi][safi],
8054 BGP_CONFIG_DAMPENING))
8055 json_object_boolean_true_add(
8056 json, "dampeningEnabled");
8057 } else {
8058 if (bgp_maxmed_onstartup_configured(bgp)
8059 && bgp->maxmed_active)
8060 vty_out(vty,
8061 "Max-med on-startup active\n");
8062 if (bgp->v_maxmed_admin)
8063 vty_out(vty,
8064 "Max-med administrative active\n");
8065
8066 vty_out(vty, "BGP table version %" PRIu64 "\n",
8067 bgp_table_version(bgp->rib[afi][safi]));
8068
8069 ents = bgp_table_count(bgp->rib[afi][safi]);
8070 vty_out(vty,
8071 "RIB entries %ld, using %s of memory\n",
8072 ents,
8073 mtype_memstr(memstrbuf,
8074 sizeof(memstrbuf),
8075 ents * sizeof(struct
8076 bgp_node)));
8077
8078 /* Peer related usage */
8079 ents = bgp->af_peer_count[afi][safi];
8080 vty_out(vty, "Peers %ld, using %s of memory\n",
8081 ents,
8082 mtype_memstr(
8083 memstrbuf, sizeof(memstrbuf),
8084 ents * sizeof(struct peer)));
8085
8086 if ((ents = listcount(bgp->group)))
8087 vty_out(vty,
8088 "Peer groups %ld, using %s of memory\n",
8089 ents,
8090 mtype_memstr(
8091 memstrbuf,
8092 sizeof(memstrbuf),
8093 ents * sizeof(struct
8094 peer_group)));
8095
8096 if (CHECK_FLAG(bgp->af_flags[afi][safi],
8097 BGP_CONFIG_DAMPENING))
8098 vty_out(vty, "Dampening enabled.\n");
8099 vty_out(vty, "\n");
8100
8101 /* Subtract 8 here because 'Neighbor' is
8102 * 8 characters */
8103 vty_out(vty, "Neighbor");
8104 vty_out(vty, "%*s", max_neighbor_width - 8,
8105 " ");
8106 vty_out(vty,
8107 "V AS MsgRcvd MsgSent TblVer InQ OutQ Up/Down State/PfxRcd\n");
8108 }
8109 }
8110
8111 count++;
8112
8113 if (use_json) {
8114 json_peer = json_object_new_object();
8115
8116 if (peer_dynamic_neighbor(peer)) {
8117 dn_count++;
8118 json_object_boolean_true_add(json_peer,
8119 "dynamicPeer");
8120 }
8121
8122 if (peer->hostname)
8123 json_object_string_add(json_peer, "hostname",
8124 peer->hostname);
8125
8126 if (peer->domainname)
8127 json_object_string_add(json_peer, "domainname",
8128 peer->domainname);
8129
8130 json_object_int_add(json_peer, "remoteAs", peer->as);
8131 json_object_int_add(json_peer, "version", 4);
8132 json_object_int_add(json_peer, "msgRcvd",
8133 PEER_TOTAL_RX(peer));
8134 json_object_int_add(json_peer, "msgSent",
8135 PEER_TOTAL_TX(peer));
8136
8137 json_object_int_add(json_peer, "tableVersion",
8138 peer->version[afi][safi]);
8139 json_object_int_add(json_peer, "outq",
8140 peer->obuf->count);
8141 json_object_int_add(json_peer, "inq", 0);
8142 peer_uptime(peer->uptime, timebuf, BGP_UPTIME_LEN,
8143 use_json, json_peer);
8144
8145 /*
8146 * Adding "pfxRcd" field to match with the corresponding
8147 * CLI. "prefixReceivedCount" will be deprecated in
8148 * future.
8149 */
8150 json_object_int_add(json_peer, "prefixReceivedCount",
8151 peer->pcount[afi][pfx_rcd_safi]);
8152 json_object_int_add(json_peer, "pfxRcd",
8153 peer->pcount[afi][pfx_rcd_safi]);
8154
8155 paf = peer_af_find(peer, afi, pfx_rcd_safi);
8156 if (paf && PAF_SUBGRP(paf))
8157 json_object_int_add(json_peer,
8158 "pfxSnt",
8159 (PAF_SUBGRP(paf))->scount);
8160
8161 if (CHECK_FLAG(peer->flags, PEER_FLAG_SHUTDOWN))
8162 json_object_string_add(json_peer, "state",
8163 "Idle (Admin)");
8164 else if (peer->afc_recv[afi][safi])
8165 json_object_string_add(
8166 json_peer, "state",
8167 lookup_msg(bgp_status_msg, peer->status,
8168 NULL));
8169 else if (CHECK_FLAG(peer->sflags,
8170 PEER_STATUS_PREFIX_OVERFLOW))
8171 json_object_string_add(json_peer, "state",
8172 "Idle (PfxCt)");
8173 else
8174 json_object_string_add(
8175 json_peer, "state",
8176 lookup_msg(bgp_status_msg, peer->status,
8177 NULL));
8178
8179 if (peer->conf_if)
8180 json_object_string_add(json_peer, "idType",
8181 "interface");
8182 else if (peer->su.sa.sa_family == AF_INET)
8183 json_object_string_add(json_peer, "idType",
8184 "ipv4");
8185 else if (peer->su.sa.sa_family == AF_INET6)
8186 json_object_string_add(json_peer, "idType",
8187 "ipv6");
8188
8189 json_object_object_add(json_peers, peer->host,
8190 json_peer);
8191 } else {
8192 memset(dn_flag, '\0', sizeof(dn_flag));
8193 if (peer_dynamic_neighbor(peer)) {
8194 dn_count++;
8195 dn_flag[0] = '*';
8196 }
8197
8198 if (peer->hostname
8199 && bgp_flag_check(bgp, BGP_FLAG_SHOW_HOSTNAME))
8200 len = vty_out(vty, "%s%s(%s)", dn_flag,
8201 peer->hostname, peer->host);
8202 else
8203 len = vty_out(vty, "%s%s", dn_flag, peer->host);
8204
8205 /* pad the neighbor column with spaces */
8206 if (len < max_neighbor_width)
8207 vty_out(vty, "%*s", max_neighbor_width - len,
8208 " ");
8209
8210 vty_out(vty, "4 %10u %7u %7u %8" PRIu64 " %4d %4zd %8s",
8211 peer->as, PEER_TOTAL_RX(peer),
8212 PEER_TOTAL_TX(peer), peer->version[afi][safi],
8213 0, peer->obuf->count,
8214 peer_uptime(peer->uptime, timebuf,
8215 BGP_UPTIME_LEN, 0, NULL));
8216
8217 if (peer->status == Established)
8218 if (peer->afc_recv[afi][safi])
8219 vty_out(vty, " %12ld",
8220 peer->pcount[afi]
8221 [pfx_rcd_safi]);
8222 else
8223 vty_out(vty, " NoNeg");
8224 else {
8225 if (CHECK_FLAG(peer->flags, PEER_FLAG_SHUTDOWN))
8226 vty_out(vty, " Idle (Admin)");
8227 else if (CHECK_FLAG(
8228 peer->sflags,
8229 PEER_STATUS_PREFIX_OVERFLOW))
8230 vty_out(vty, " Idle (PfxCt)");
8231 else
8232 vty_out(vty, " %12s",
8233 lookup_msg(bgp_status_msg,
8234 peer->status, NULL));
8235 }
8236 vty_out(vty, "\n");
8237 }
8238 }
8239
8240 if (use_json) {
8241 json_object_object_add(json, "peers", json_peers);
8242
8243 json_object_int_add(json, "totalPeers", count);
8244 json_object_int_add(json, "dynamicPeers", dn_count);
8245
8246 bgp_show_bestpath_json(bgp, json);
8247
8248 vty_out(vty, "%s\n", json_object_to_json_string_ext(
8249 json, JSON_C_TO_STRING_PRETTY));
8250 json_object_free(json);
8251 } else {
8252 if (count)
8253 vty_out(vty, "\nTotal number of neighbors %d\n", count);
8254 else {
8255 vty_out(vty, "No %s neighbor is configured\n",
8256 afi_safi_print(afi, safi));
8257 }
8258
8259 if (dn_count) {
8260 vty_out(vty, "* - dynamic neighbor\n");
8261 vty_out(vty, "%d dynamic neighbor(s), limit %d\n",
8262 dn_count, bgp->dynamic_neighbors_limit);
8263 }
8264 }
8265
8266 return CMD_SUCCESS;
8267 }
8268
8269 static void bgp_show_summary_afi_safi(struct vty *vty, struct bgp *bgp, int afi,
8270 int safi, bool use_json,
8271 json_object *json)
8272 {
8273 int is_first = 1;
8274 int afi_wildcard = (afi == AFI_MAX);
8275 int safi_wildcard = (safi == SAFI_MAX);
8276 int is_wildcard = (afi_wildcard || safi_wildcard);
8277 bool nbr_output = false;
8278
8279 if (use_json && is_wildcard)
8280 vty_out(vty, "{\n");
8281 if (afi_wildcard)
8282 afi = 1; /* AFI_IP */
8283 while (afi < AFI_MAX) {
8284 if (safi_wildcard)
8285 safi = 1; /* SAFI_UNICAST */
8286 while (safi < SAFI_MAX) {
8287 if (bgp_afi_safi_peer_exists(bgp, afi, safi)) {
8288 nbr_output = true;
8289 if (is_wildcard) {
8290 /*
8291 * So limit output to those afi/safi
8292 * pairs that
8293 * actualy have something interesting in
8294 * them
8295 */
8296 if (use_json) {
8297 json = json_object_new_object();
8298
8299 if (!is_first)
8300 vty_out(vty, ",\n");
8301 else
8302 is_first = 0;
8303
8304 vty_out(vty, "\"%s\":",
8305 afi_safi_json(afi,
8306 safi));
8307 } else {
8308 vty_out(vty, "\n%s Summary:\n",
8309 afi_safi_print(afi,
8310 safi));
8311 }
8312 }
8313 bgp_show_summary(vty, bgp, afi, safi, use_json,
8314 json);
8315 }
8316 safi++;
8317 if (!safi_wildcard)
8318 safi = SAFI_MAX;
8319 }
8320 afi++;
8321 if (!afi_wildcard)
8322 afi = AFI_MAX;
8323 }
8324
8325 if (use_json && is_wildcard)
8326 vty_out(vty, "}\n");
8327 else if (!nbr_output) {
8328 if (use_json)
8329 vty_out(vty, "{}\n");
8330 else
8331 vty_out(vty, "%% No BGP neighbors found\n");
8332 }
8333 }
8334
8335 static void bgp_show_all_instances_summary_vty(struct vty *vty, afi_t afi,
8336 safi_t safi, bool use_json)
8337 {
8338 struct listnode *node, *nnode;
8339 struct bgp *bgp;
8340 json_object *json = NULL;
8341 int is_first = 1;
8342 bool nbr_output = false;
8343
8344 if (use_json)
8345 vty_out(vty, "{\n");
8346
8347 for (ALL_LIST_ELEMENTS(bm->bgp, node, nnode, bgp)) {
8348 nbr_output = true;
8349 if (use_json) {
8350 json = json_object_new_object();
8351
8352 if (!is_first)
8353 vty_out(vty, ",\n");
8354 else
8355 is_first = 0;
8356
8357 vty_out(vty, "\"%s\":",
8358 (bgp->inst_type == BGP_INSTANCE_TYPE_DEFAULT)
8359 ? VRF_DEFAULT_NAME
8360 : bgp->name);
8361 } else {
8362 vty_out(vty, "\nInstance %s:\n",
8363 (bgp->inst_type == BGP_INSTANCE_TYPE_DEFAULT)
8364 ? VRF_DEFAULT_NAME
8365 : bgp->name);
8366 }
8367 bgp_show_summary_afi_safi(vty, bgp, afi, safi, use_json, json);
8368 }
8369
8370 if (use_json)
8371 vty_out(vty, "}\n");
8372 else if (!nbr_output)
8373 vty_out(vty, "%% BGP instance not found\n");
8374 }
8375
8376 int bgp_show_summary_vty(struct vty *vty, const char *name, afi_t afi,
8377 safi_t safi, bool use_json)
8378 {
8379 struct bgp *bgp;
8380
8381 if (name) {
8382 if (strmatch(name, "all")) {
8383 bgp_show_all_instances_summary_vty(vty, afi, safi,
8384 use_json);
8385 return CMD_SUCCESS;
8386 } else {
8387 bgp = bgp_lookup_by_name(name);
8388
8389 if (!bgp) {
8390 if (use_json)
8391 vty_out(vty, "{}\n");
8392 else
8393 vty_out(vty,
8394 "%% BGP instance not found\n");
8395 return CMD_WARNING;
8396 }
8397
8398 bgp_show_summary_afi_safi(vty, bgp, afi, safi, use_json,
8399 NULL);
8400 return CMD_SUCCESS;
8401 }
8402 }
8403
8404 bgp = bgp_get_default();
8405
8406 if (bgp)
8407 bgp_show_summary_afi_safi(vty, bgp, afi, safi, use_json, NULL);
8408 else {
8409 if (use_json)
8410 vty_out(vty, "{}\n");
8411 else
8412 vty_out(vty, "%% BGP instance not found\n");
8413 return CMD_WARNING;
8414 }
8415
8416 return CMD_SUCCESS;
8417 }
8418
8419 /* `show [ip] bgp summary' commands. */
8420 DEFUN (show_ip_bgp_summary,
8421 show_ip_bgp_summary_cmd,
8422 "show [ip] bgp [<view|vrf> VIEWVRFNAME] ["BGP_AFI_CMD_STR" ["BGP_SAFI_WITH_LABEL_CMD_STR"]] summary [json]",
8423 SHOW_STR
8424 IP_STR
8425 BGP_STR
8426 BGP_INSTANCE_HELP_STR
8427 BGP_AFI_HELP_STR
8428 BGP_SAFI_WITH_LABEL_HELP_STR
8429 "Summary of BGP neighbor status\n"
8430 JSON_STR)
8431 {
8432 char *vrf = NULL;
8433 afi_t afi = AFI_MAX;
8434 safi_t safi = SAFI_MAX;
8435
8436 int idx = 0;
8437
8438 /* show [ip] bgp */
8439 if (argv_find(argv, argc, "ip", &idx))
8440 afi = AFI_IP;
8441 /* [<vrf> VIEWVRFNAME] */
8442 if (argv_find(argv, argc, "vrf", &idx)) {
8443 vrf = argv[idx + 1]->arg;
8444 if (vrf && strmatch(vrf, VRF_DEFAULT_NAME))
8445 vrf = NULL;
8446 } else if (argv_find(argv, argc, "view", &idx))
8447 /* [<view> VIEWVRFNAME] */
8448 vrf = argv[idx + 1]->arg;
8449 /* ["BGP_AFI_CMD_STR" ["BGP_SAFI_CMD_STR"]] */
8450 if (argv_find_and_parse_afi(argv, argc, &idx, &afi)) {
8451 argv_find_and_parse_safi(argv, argc, &idx, &safi);
8452 }
8453
8454 bool uj = use_json(argc, argv);
8455
8456 return bgp_show_summary_vty(vty, vrf, afi, safi, uj);
8457 }
8458
8459 const char *afi_safi_print(afi_t afi, safi_t safi)
8460 {
8461 if (afi == AFI_IP && safi == SAFI_UNICAST)
8462 return "IPv4 Unicast";
8463 else if (afi == AFI_IP && safi == SAFI_MULTICAST)
8464 return "IPv4 Multicast";
8465 else if (afi == AFI_IP && safi == SAFI_LABELED_UNICAST)
8466 return "IPv4 Labeled Unicast";
8467 else if (afi == AFI_IP && safi == SAFI_MPLS_VPN)
8468 return "IPv4 VPN";
8469 else if (afi == AFI_IP && safi == SAFI_ENCAP)
8470 return "IPv4 Encap";
8471 else if (afi == AFI_IP && safi == SAFI_FLOWSPEC)
8472 return "IPv4 Flowspec";
8473 else if (afi == AFI_IP6 && safi == SAFI_UNICAST)
8474 return "IPv6 Unicast";
8475 else if (afi == AFI_IP6 && safi == SAFI_MULTICAST)
8476 return "IPv6 Multicast";
8477 else if (afi == AFI_IP6 && safi == SAFI_LABELED_UNICAST)
8478 return "IPv6 Labeled Unicast";
8479 else if (afi == AFI_IP6 && safi == SAFI_MPLS_VPN)
8480 return "IPv6 VPN";
8481 else if (afi == AFI_IP6 && safi == SAFI_ENCAP)
8482 return "IPv6 Encap";
8483 else if (afi == AFI_IP6 && safi == SAFI_FLOWSPEC)
8484 return "IPv6 Flowspec";
8485 else if (afi == AFI_L2VPN && safi == SAFI_EVPN)
8486 return "L2VPN EVPN";
8487 else
8488 return "Unknown";
8489 }
8490
8491 /*
8492 * Please note that we have intentionally camelCased
8493 * the return strings here. So if you want
8494 * to use this function, please ensure you
8495 * are doing this within json output
8496 */
8497 const char *afi_safi_json(afi_t afi, safi_t safi)
8498 {
8499 if (afi == AFI_IP && safi == SAFI_UNICAST)
8500 return "ipv4Unicast";
8501 else if (afi == AFI_IP && safi == SAFI_MULTICAST)
8502 return "ipv4Multicast";
8503 else if (afi == AFI_IP && safi == SAFI_LABELED_UNICAST)
8504 return "ipv4LabeledUnicast";
8505 else if (afi == AFI_IP && safi == SAFI_MPLS_VPN)
8506 return "ipv4Vpn";
8507 else if (afi == AFI_IP && safi == SAFI_ENCAP)
8508 return "ipv4Encap";
8509 else if (afi == AFI_IP && safi == SAFI_FLOWSPEC)
8510 return "ipv4Flowspec";
8511 else if (afi == AFI_IP6 && safi == SAFI_UNICAST)
8512 return "ipv6Unicast";
8513 else if (afi == AFI_IP6 && safi == SAFI_MULTICAST)
8514 return "ipv6Multicast";
8515 else if (afi == AFI_IP6 && safi == SAFI_LABELED_UNICAST)
8516 return "ipv6LabeledUnicast";
8517 else if (afi == AFI_IP6 && safi == SAFI_MPLS_VPN)
8518 return "ipv6Vpn";
8519 else if (afi == AFI_IP6 && safi == SAFI_ENCAP)
8520 return "ipv6Encap";
8521 else if (afi == AFI_IP6 && safi == SAFI_FLOWSPEC)
8522 return "ipv6Flowspec";
8523 else if (afi == AFI_L2VPN && safi == SAFI_EVPN)
8524 return "l2VpnEvpn";
8525 else
8526 return "Unknown";
8527 }
8528
8529 /* Show BGP peer's information. */
8530 enum show_type { show_all, show_peer, show_ipv4_all, show_ipv6_all, show_ipv4_peer, show_ipv6_peer };
8531
8532 static void bgp_show_peer_afi_orf_cap(struct vty *vty, struct peer *p,
8533 afi_t afi, safi_t safi,
8534 uint16_t adv_smcap, uint16_t adv_rmcap,
8535 uint16_t rcv_smcap, uint16_t rcv_rmcap,
8536 bool use_json, json_object *json_pref)
8537 {
8538 /* Send-Mode */
8539 if (CHECK_FLAG(p->af_cap[afi][safi], adv_smcap)
8540 || CHECK_FLAG(p->af_cap[afi][safi], rcv_smcap)) {
8541 if (use_json) {
8542 if (CHECK_FLAG(p->af_cap[afi][safi], adv_smcap)
8543 && CHECK_FLAG(p->af_cap[afi][safi], rcv_smcap))
8544 json_object_string_add(json_pref, "sendMode",
8545 "advertisedAndReceived");
8546 else if (CHECK_FLAG(p->af_cap[afi][safi], adv_smcap))
8547 json_object_string_add(json_pref, "sendMode",
8548 "advertised");
8549 else if (CHECK_FLAG(p->af_cap[afi][safi], rcv_smcap))
8550 json_object_string_add(json_pref, "sendMode",
8551 "received");
8552 } else {
8553 vty_out(vty, " Send-mode: ");
8554 if (CHECK_FLAG(p->af_cap[afi][safi], adv_smcap))
8555 vty_out(vty, "advertised");
8556 if (CHECK_FLAG(p->af_cap[afi][safi], rcv_smcap))
8557 vty_out(vty, "%sreceived",
8558 CHECK_FLAG(p->af_cap[afi][safi],
8559 adv_smcap)
8560 ? ", "
8561 : "");
8562 vty_out(vty, "\n");
8563 }
8564 }
8565
8566 /* Receive-Mode */
8567 if (CHECK_FLAG(p->af_cap[afi][safi], adv_rmcap)
8568 || CHECK_FLAG(p->af_cap[afi][safi], rcv_rmcap)) {
8569 if (use_json) {
8570 if (CHECK_FLAG(p->af_cap[afi][safi], adv_rmcap)
8571 && CHECK_FLAG(p->af_cap[afi][safi], rcv_rmcap))
8572 json_object_string_add(json_pref, "recvMode",
8573 "advertisedAndReceived");
8574 else if (CHECK_FLAG(p->af_cap[afi][safi], adv_rmcap))
8575 json_object_string_add(json_pref, "recvMode",
8576 "advertised");
8577 else if (CHECK_FLAG(p->af_cap[afi][safi], rcv_rmcap))
8578 json_object_string_add(json_pref, "recvMode",
8579 "received");
8580 } else {
8581 vty_out(vty, " Receive-mode: ");
8582 if (CHECK_FLAG(p->af_cap[afi][safi], adv_rmcap))
8583 vty_out(vty, "advertised");
8584 if (CHECK_FLAG(p->af_cap[afi][safi], rcv_rmcap))
8585 vty_out(vty, "%sreceived",
8586 CHECK_FLAG(p->af_cap[afi][safi],
8587 adv_rmcap)
8588 ? ", "
8589 : "");
8590 vty_out(vty, "\n");
8591 }
8592 }
8593 }
8594
8595 static void bgp_show_peer_afi(struct vty *vty, struct peer *p, afi_t afi,
8596 safi_t safi, bool use_json,
8597 json_object *json_neigh)
8598 {
8599 struct bgp_filter *filter;
8600 struct peer_af *paf;
8601 char orf_pfx_name[BUFSIZ];
8602 int orf_pfx_count;
8603 json_object *json_af = NULL;
8604 json_object *json_prefA = NULL;
8605 json_object *json_prefB = NULL;
8606 json_object *json_addr = NULL;
8607
8608 if (use_json) {
8609 json_addr = json_object_new_object();
8610 json_af = json_object_new_object();
8611 filter = &p->filter[afi][safi];
8612
8613 if (peer_group_active(p))
8614 json_object_string_add(json_addr, "peerGroupMember",
8615 p->group->name);
8616
8617 paf = peer_af_find(p, afi, safi);
8618 if (paf && PAF_SUBGRP(paf)) {
8619 json_object_int_add(json_addr, "updateGroupId",
8620 PAF_UPDGRP(paf)->id);
8621 json_object_int_add(json_addr, "subGroupId",
8622 PAF_SUBGRP(paf)->id);
8623 json_object_int_add(json_addr, "packetQueueLength",
8624 bpacket_queue_virtual_length(paf));
8625 }
8626
8627 if (CHECK_FLAG(p->af_cap[afi][safi], PEER_CAP_ORF_PREFIX_SM_ADV)
8628 || CHECK_FLAG(p->af_cap[afi][safi],
8629 PEER_CAP_ORF_PREFIX_SM_RCV)
8630 || CHECK_FLAG(p->af_cap[afi][safi],
8631 PEER_CAP_ORF_PREFIX_RM_ADV)
8632 || CHECK_FLAG(p->af_cap[afi][safi],
8633 PEER_CAP_ORF_PREFIX_RM_RCV)) {
8634 json_object_int_add(json_af, "orfType",
8635 ORF_TYPE_PREFIX);
8636 json_prefA = json_object_new_object();
8637 bgp_show_peer_afi_orf_cap(vty, p, afi, safi,
8638 PEER_CAP_ORF_PREFIX_SM_ADV,
8639 PEER_CAP_ORF_PREFIX_RM_ADV,
8640 PEER_CAP_ORF_PREFIX_SM_RCV,
8641 PEER_CAP_ORF_PREFIX_RM_RCV,
8642 use_json, json_prefA);
8643 json_object_object_add(json_af, "orfPrefixList",
8644 json_prefA);
8645 }
8646
8647 if (CHECK_FLAG(p->af_cap[afi][safi], PEER_CAP_ORF_PREFIX_SM_ADV)
8648 || CHECK_FLAG(p->af_cap[afi][safi],
8649 PEER_CAP_ORF_PREFIX_SM_OLD_RCV)
8650 || CHECK_FLAG(p->af_cap[afi][safi],
8651 PEER_CAP_ORF_PREFIX_RM_ADV)
8652 || CHECK_FLAG(p->af_cap[afi][safi],
8653 PEER_CAP_ORF_PREFIX_RM_OLD_RCV)) {
8654 json_object_int_add(json_af, "orfOldType",
8655 ORF_TYPE_PREFIX_OLD);
8656 json_prefB = json_object_new_object();
8657 bgp_show_peer_afi_orf_cap(
8658 vty, p, afi, safi, PEER_CAP_ORF_PREFIX_SM_ADV,
8659 PEER_CAP_ORF_PREFIX_RM_ADV,
8660 PEER_CAP_ORF_PREFIX_SM_OLD_RCV,
8661 PEER_CAP_ORF_PREFIX_RM_OLD_RCV, use_json,
8662 json_prefB);
8663 json_object_object_add(json_af, "orfOldPrefixList",
8664 json_prefB);
8665 }
8666
8667 if (CHECK_FLAG(p->af_cap[afi][safi], PEER_CAP_ORF_PREFIX_SM_ADV)
8668 || CHECK_FLAG(p->af_cap[afi][safi],
8669 PEER_CAP_ORF_PREFIX_SM_RCV)
8670 || CHECK_FLAG(p->af_cap[afi][safi],
8671 PEER_CAP_ORF_PREFIX_SM_OLD_RCV)
8672 || CHECK_FLAG(p->af_cap[afi][safi],
8673 PEER_CAP_ORF_PREFIX_RM_ADV)
8674 || CHECK_FLAG(p->af_cap[afi][safi],
8675 PEER_CAP_ORF_PREFIX_RM_RCV)
8676 || CHECK_FLAG(p->af_cap[afi][safi],
8677 PEER_CAP_ORF_PREFIX_RM_OLD_RCV))
8678 json_object_object_add(json_addr, "afDependentCap",
8679 json_af);
8680 else
8681 json_object_free(json_af);
8682
8683 sprintf(orf_pfx_name, "%s.%d.%d", p->host, afi, safi);
8684 orf_pfx_count = prefix_bgp_show_prefix_list(
8685 NULL, afi, orf_pfx_name, use_json);
8686
8687 if (CHECK_FLAG(p->af_sflags[afi][safi],
8688 PEER_STATUS_ORF_PREFIX_SEND)
8689 || orf_pfx_count) {
8690 if (CHECK_FLAG(p->af_sflags[afi][safi],
8691 PEER_STATUS_ORF_PREFIX_SEND))
8692 json_object_boolean_true_add(json_neigh,
8693 "orfSent");
8694 if (orf_pfx_count)
8695 json_object_int_add(json_addr, "orfRecvCounter",
8696 orf_pfx_count);
8697 }
8698 if (CHECK_FLAG(p->af_sflags[afi][safi],
8699 PEER_STATUS_ORF_WAIT_REFRESH))
8700 json_object_string_add(
8701 json_addr, "orfFirstUpdate",
8702 "deferredUntilORFOrRouteRefreshRecvd");
8703
8704 if (CHECK_FLAG(p->af_flags[afi][safi],
8705 PEER_FLAG_REFLECTOR_CLIENT))
8706 json_object_boolean_true_add(json_addr,
8707 "routeReflectorClient");
8708 if (CHECK_FLAG(p->af_flags[afi][safi],
8709 PEER_FLAG_RSERVER_CLIENT))
8710 json_object_boolean_true_add(json_addr,
8711 "routeServerClient");
8712 if (CHECK_FLAG(p->af_flags[afi][safi], PEER_FLAG_SOFT_RECONFIG))
8713 json_object_boolean_true_add(json_addr,
8714 "inboundSoftConfigPermit");
8715
8716 if (CHECK_FLAG(p->af_flags[afi][safi],
8717 PEER_FLAG_REMOVE_PRIVATE_AS_ALL_REPLACE))
8718 json_object_boolean_true_add(
8719 json_addr,
8720 "privateAsNumsAllReplacedInUpdatesToNbr");
8721 else if (CHECK_FLAG(p->af_flags[afi][safi],
8722 PEER_FLAG_REMOVE_PRIVATE_AS_REPLACE))
8723 json_object_boolean_true_add(
8724 json_addr,
8725 "privateAsNumsReplacedInUpdatesToNbr");
8726 else if (CHECK_FLAG(p->af_flags[afi][safi],
8727 PEER_FLAG_REMOVE_PRIVATE_AS_ALL))
8728 json_object_boolean_true_add(
8729 json_addr,
8730 "privateAsNumsAllRemovedInUpdatesToNbr");
8731 else if (CHECK_FLAG(p->af_flags[afi][safi],
8732 PEER_FLAG_REMOVE_PRIVATE_AS))
8733 json_object_boolean_true_add(
8734 json_addr,
8735 "privateAsNumsRemovedInUpdatesToNbr");
8736
8737 if (p->addpath_type[afi][safi] != BGP_ADDPATH_NONE)
8738 json_object_boolean_true_add(
8739 json_addr,
8740 bgp_addpath_names(p->addpath_type[afi][safi])
8741 ->type_json_name);
8742
8743 if (CHECK_FLAG(p->af_flags[afi][safi], PEER_FLAG_AS_OVERRIDE))
8744 json_object_string_add(json_addr,
8745 "overrideASNsInOutboundUpdates",
8746 "ifAspathEqualRemoteAs");
8747
8748 if (CHECK_FLAG(p->af_flags[afi][safi], PEER_FLAG_NEXTHOP_SELF)
8749 || CHECK_FLAG(p->af_flags[afi][safi],
8750 PEER_FLAG_FORCE_NEXTHOP_SELF))
8751 json_object_boolean_true_add(json_addr,
8752 "routerAlwaysNextHop");
8753 if (CHECK_FLAG(p->af_flags[afi][safi],
8754 PEER_FLAG_AS_PATH_UNCHANGED))
8755 json_object_boolean_true_add(
8756 json_addr, "unchangedAsPathPropogatedToNbr");
8757 if (CHECK_FLAG(p->af_flags[afi][safi],
8758 PEER_FLAG_NEXTHOP_UNCHANGED))
8759 json_object_boolean_true_add(
8760 json_addr, "unchangedNextHopPropogatedToNbr");
8761 if (CHECK_FLAG(p->af_flags[afi][safi], PEER_FLAG_MED_UNCHANGED))
8762 json_object_boolean_true_add(
8763 json_addr, "unchangedMedPropogatedToNbr");
8764 if (CHECK_FLAG(p->af_flags[afi][safi], PEER_FLAG_SEND_COMMUNITY)
8765 || CHECK_FLAG(p->af_flags[afi][safi],
8766 PEER_FLAG_SEND_EXT_COMMUNITY)) {
8767 if (CHECK_FLAG(p->af_flags[afi][safi],
8768 PEER_FLAG_SEND_COMMUNITY)
8769 && CHECK_FLAG(p->af_flags[afi][safi],
8770 PEER_FLAG_SEND_EXT_COMMUNITY))
8771 json_object_string_add(json_addr,
8772 "commAttriSentToNbr",
8773 "extendedAndStandard");
8774 else if (CHECK_FLAG(p->af_flags[afi][safi],
8775 PEER_FLAG_SEND_EXT_COMMUNITY))
8776 json_object_string_add(json_addr,
8777 "commAttriSentToNbr",
8778 "extended");
8779 else
8780 json_object_string_add(json_addr,
8781 "commAttriSentToNbr",
8782 "standard");
8783 }
8784 if (CHECK_FLAG(p->af_flags[afi][safi],
8785 PEER_FLAG_DEFAULT_ORIGINATE)) {
8786 if (p->default_rmap[afi][safi].name)
8787 json_object_string_add(
8788 json_addr, "defaultRouteMap",
8789 p->default_rmap[afi][safi].name);
8790
8791 if (paf && PAF_SUBGRP(paf)
8792 && CHECK_FLAG(PAF_SUBGRP(paf)->sflags,
8793 SUBGRP_STATUS_DEFAULT_ORIGINATE))
8794 json_object_boolean_true_add(json_addr,
8795 "defaultSent");
8796 else
8797 json_object_boolean_true_add(json_addr,
8798 "defaultNotSent");
8799 }
8800
8801 if (afi == AFI_L2VPN && safi == SAFI_EVPN) {
8802 if (is_evpn_enabled())
8803 json_object_boolean_true_add(
8804 json_addr, "advertiseAllVnis");
8805 }
8806
8807 if (filter->plist[FILTER_IN].name
8808 || filter->dlist[FILTER_IN].name
8809 || filter->aslist[FILTER_IN].name
8810 || filter->map[RMAP_IN].name)
8811 json_object_boolean_true_add(json_addr,
8812 "inboundPathPolicyConfig");
8813 if (filter->plist[FILTER_OUT].name
8814 || filter->dlist[FILTER_OUT].name
8815 || filter->aslist[FILTER_OUT].name
8816 || filter->map[RMAP_OUT].name || filter->usmap.name)
8817 json_object_boolean_true_add(
8818 json_addr, "outboundPathPolicyConfig");
8819
8820 /* prefix-list */
8821 if (filter->plist[FILTER_IN].name)
8822 json_object_string_add(json_addr,
8823 "incomingUpdatePrefixFilterList",
8824 filter->plist[FILTER_IN].name);
8825 if (filter->plist[FILTER_OUT].name)
8826 json_object_string_add(json_addr,
8827 "outgoingUpdatePrefixFilterList",
8828 filter->plist[FILTER_OUT].name);
8829
8830 /* distribute-list */
8831 if (filter->dlist[FILTER_IN].name)
8832 json_object_string_add(
8833 json_addr, "incomingUpdateNetworkFilterList",
8834 filter->dlist[FILTER_IN].name);
8835 if (filter->dlist[FILTER_OUT].name)
8836 json_object_string_add(
8837 json_addr, "outgoingUpdateNetworkFilterList",
8838 filter->dlist[FILTER_OUT].name);
8839
8840 /* filter-list. */
8841 if (filter->aslist[FILTER_IN].name)
8842 json_object_string_add(json_addr,
8843 "incomingUpdateAsPathFilterList",
8844 filter->aslist[FILTER_IN].name);
8845 if (filter->aslist[FILTER_OUT].name)
8846 json_object_string_add(json_addr,
8847 "outgoingUpdateAsPathFilterList",
8848 filter->aslist[FILTER_OUT].name);
8849
8850 /* route-map. */
8851 if (filter->map[RMAP_IN].name)
8852 json_object_string_add(
8853 json_addr, "routeMapForIncomingAdvertisements",
8854 filter->map[RMAP_IN].name);
8855 if (filter->map[RMAP_OUT].name)
8856 json_object_string_add(
8857 json_addr, "routeMapForOutgoingAdvertisements",
8858 filter->map[RMAP_OUT].name);
8859
8860 /* ebgp-requires-policy (inbound) */
8861 if (p->bgp->ebgp_requires_policy == DEFAULT_EBGP_POLICY_ENABLED
8862 && !bgp_inbound_policy_exists(p, filter))
8863 json_object_string_add(
8864 json_addr, "inboundEbgpRequiresPolicy",
8865 "Inbound updates discarded due to missing policy");
8866
8867 /* ebgp-requires-policy (outbound) */
8868 if (p->bgp->ebgp_requires_policy == DEFAULT_EBGP_POLICY_ENABLED
8869 && (!bgp_outbound_policy_exists(p, filter)))
8870 json_object_string_add(
8871 json_addr, "outboundEbgpRequiresPolicy",
8872 "Outbound updates discarded due to missing policy");
8873
8874 /* unsuppress-map */
8875 if (filter->usmap.name)
8876 json_object_string_add(json_addr,
8877 "selectiveUnsuppressRouteMap",
8878 filter->usmap.name);
8879
8880 /* Receive prefix count */
8881 json_object_int_add(json_addr, "acceptedPrefixCounter",
8882 p->pcount[afi][safi]);
8883 if (paf && PAF_SUBGRP(paf))
8884 json_object_int_add(json_addr, "sentPrefixCounter",
8885 (PAF_SUBGRP(paf))->scount);
8886
8887 /* Maximum prefix */
8888 if (CHECK_FLAG(p->af_flags[afi][safi], PEER_FLAG_MAX_PREFIX)) {
8889 json_object_int_add(json_addr, "prefixAllowedMax",
8890 p->pmax[afi][safi]);
8891 if (CHECK_FLAG(p->af_flags[afi][safi],
8892 PEER_FLAG_MAX_PREFIX_WARNING))
8893 json_object_boolean_true_add(
8894 json_addr, "prefixAllowedMaxWarning");
8895 json_object_int_add(json_addr,
8896 "prefixAllowedWarningThresh",
8897 p->pmax_threshold[afi][safi]);
8898 if (p->pmax_restart[afi][safi])
8899 json_object_int_add(
8900 json_addr,
8901 "prefixAllowedRestartIntervalMsecs",
8902 p->pmax_restart[afi][safi] * 60000);
8903 }
8904 json_object_object_add(json_neigh, afi_safi_print(afi, safi),
8905 json_addr);
8906
8907 } else {
8908 filter = &p->filter[afi][safi];
8909
8910 vty_out(vty, " For address family: %s\n",
8911 afi_safi_print(afi, safi));
8912
8913 if (peer_group_active(p))
8914 vty_out(vty, " %s peer-group member\n",
8915 p->group->name);
8916
8917 paf = peer_af_find(p, afi, safi);
8918 if (paf && PAF_SUBGRP(paf)) {
8919 vty_out(vty, " Update group %" PRIu64
8920 ", subgroup %" PRIu64 "\n",
8921 PAF_UPDGRP(paf)->id, PAF_SUBGRP(paf)->id);
8922 vty_out(vty, " Packet Queue length %d\n",
8923 bpacket_queue_virtual_length(paf));
8924 } else {
8925 vty_out(vty, " Not part of any update group\n");
8926 }
8927 if (CHECK_FLAG(p->af_cap[afi][safi], PEER_CAP_ORF_PREFIX_SM_ADV)
8928 || CHECK_FLAG(p->af_cap[afi][safi],
8929 PEER_CAP_ORF_PREFIX_SM_RCV)
8930 || CHECK_FLAG(p->af_cap[afi][safi],
8931 PEER_CAP_ORF_PREFIX_SM_OLD_RCV)
8932 || CHECK_FLAG(p->af_cap[afi][safi],
8933 PEER_CAP_ORF_PREFIX_RM_ADV)
8934 || CHECK_FLAG(p->af_cap[afi][safi],
8935 PEER_CAP_ORF_PREFIX_RM_RCV)
8936 || CHECK_FLAG(p->af_cap[afi][safi],
8937 PEER_CAP_ORF_PREFIX_RM_OLD_RCV))
8938 vty_out(vty, " AF-dependant capabilities:\n");
8939
8940 if (CHECK_FLAG(p->af_cap[afi][safi], PEER_CAP_ORF_PREFIX_SM_ADV)
8941 || CHECK_FLAG(p->af_cap[afi][safi],
8942 PEER_CAP_ORF_PREFIX_SM_RCV)
8943 || CHECK_FLAG(p->af_cap[afi][safi],
8944 PEER_CAP_ORF_PREFIX_RM_ADV)
8945 || CHECK_FLAG(p->af_cap[afi][safi],
8946 PEER_CAP_ORF_PREFIX_RM_RCV)) {
8947 vty_out(vty,
8948 " Outbound Route Filter (ORF) type (%d) Prefix-list:\n",
8949 ORF_TYPE_PREFIX);
8950 bgp_show_peer_afi_orf_cap(
8951 vty, p, afi, safi, PEER_CAP_ORF_PREFIX_SM_ADV,
8952 PEER_CAP_ORF_PREFIX_RM_ADV,
8953 PEER_CAP_ORF_PREFIX_SM_RCV,
8954 PEER_CAP_ORF_PREFIX_RM_RCV, use_json, NULL);
8955 }
8956 if (CHECK_FLAG(p->af_cap[afi][safi], PEER_CAP_ORF_PREFIX_SM_ADV)
8957 || CHECK_FLAG(p->af_cap[afi][safi],
8958 PEER_CAP_ORF_PREFIX_SM_OLD_RCV)
8959 || CHECK_FLAG(p->af_cap[afi][safi],
8960 PEER_CAP_ORF_PREFIX_RM_ADV)
8961 || CHECK_FLAG(p->af_cap[afi][safi],
8962 PEER_CAP_ORF_PREFIX_RM_OLD_RCV)) {
8963 vty_out(vty,
8964 " Outbound Route Filter (ORF) type (%d) Prefix-list:\n",
8965 ORF_TYPE_PREFIX_OLD);
8966 bgp_show_peer_afi_orf_cap(
8967 vty, p, afi, safi, PEER_CAP_ORF_PREFIX_SM_ADV,
8968 PEER_CAP_ORF_PREFIX_RM_ADV,
8969 PEER_CAP_ORF_PREFIX_SM_OLD_RCV,
8970 PEER_CAP_ORF_PREFIX_RM_OLD_RCV, use_json, NULL);
8971 }
8972
8973 sprintf(orf_pfx_name, "%s.%d.%d", p->host, afi, safi);
8974 orf_pfx_count = prefix_bgp_show_prefix_list(
8975 NULL, afi, orf_pfx_name, use_json);
8976
8977 if (CHECK_FLAG(p->af_sflags[afi][safi],
8978 PEER_STATUS_ORF_PREFIX_SEND)
8979 || orf_pfx_count) {
8980 vty_out(vty, " Outbound Route Filter (ORF):");
8981 if (CHECK_FLAG(p->af_sflags[afi][safi],
8982 PEER_STATUS_ORF_PREFIX_SEND))
8983 vty_out(vty, " sent;");
8984 if (orf_pfx_count)
8985 vty_out(vty, " received (%d entries)",
8986 orf_pfx_count);
8987 vty_out(vty, "\n");
8988 }
8989 if (CHECK_FLAG(p->af_sflags[afi][safi],
8990 PEER_STATUS_ORF_WAIT_REFRESH))
8991 vty_out(vty,
8992 " First update is deferred until ORF or ROUTE-REFRESH is received\n");
8993
8994 if (CHECK_FLAG(p->af_flags[afi][safi],
8995 PEER_FLAG_REFLECTOR_CLIENT))
8996 vty_out(vty, " Route-Reflector Client\n");
8997 if (CHECK_FLAG(p->af_flags[afi][safi],
8998 PEER_FLAG_RSERVER_CLIENT))
8999 vty_out(vty, " Route-Server Client\n");
9000 if (CHECK_FLAG(p->af_flags[afi][safi], PEER_FLAG_SOFT_RECONFIG))
9001 vty_out(vty,
9002 " Inbound soft reconfiguration allowed\n");
9003
9004 if (CHECK_FLAG(p->af_flags[afi][safi],
9005 PEER_FLAG_REMOVE_PRIVATE_AS_ALL_REPLACE))
9006 vty_out(vty,
9007 " Private AS numbers (all) replaced in updates to this neighbor\n");
9008 else if (CHECK_FLAG(p->af_flags[afi][safi],
9009 PEER_FLAG_REMOVE_PRIVATE_AS_REPLACE))
9010 vty_out(vty,
9011 " Private AS numbers replaced in updates to this neighbor\n");
9012 else if (CHECK_FLAG(p->af_flags[afi][safi],
9013 PEER_FLAG_REMOVE_PRIVATE_AS_ALL))
9014 vty_out(vty,
9015 " Private AS numbers (all) removed in updates to this neighbor\n");
9016 else if (CHECK_FLAG(p->af_flags[afi][safi],
9017 PEER_FLAG_REMOVE_PRIVATE_AS))
9018 vty_out(vty,
9019 " Private AS numbers removed in updates to this neighbor\n");
9020
9021 if (p->addpath_type[afi][safi] != BGP_ADDPATH_NONE)
9022 vty_out(vty, " %s\n",
9023 bgp_addpath_names(p->addpath_type[afi][safi])
9024 ->human_description);
9025
9026 if (CHECK_FLAG(p->af_flags[afi][safi], PEER_FLAG_AS_OVERRIDE))
9027 vty_out(vty,
9028 " Override ASNs in outbound updates if aspath equals remote-as\n");
9029
9030 if (CHECK_FLAG(p->af_flags[afi][safi], PEER_FLAG_NEXTHOP_SELF)
9031 || CHECK_FLAG(p->af_flags[afi][safi],
9032 PEER_FLAG_FORCE_NEXTHOP_SELF))
9033 vty_out(vty, " NEXT_HOP is always this router\n");
9034 if (CHECK_FLAG(p->af_flags[afi][safi],
9035 PEER_FLAG_AS_PATH_UNCHANGED))
9036 vty_out(vty,
9037 " AS_PATH is propagated unchanged to this neighbor\n");
9038 if (CHECK_FLAG(p->af_flags[afi][safi],
9039 PEER_FLAG_NEXTHOP_UNCHANGED))
9040 vty_out(vty,
9041 " NEXT_HOP is propagated unchanged to this neighbor\n");
9042 if (CHECK_FLAG(p->af_flags[afi][safi], PEER_FLAG_MED_UNCHANGED))
9043 vty_out(vty,
9044 " MED is propagated unchanged to this neighbor\n");
9045 if (CHECK_FLAG(p->af_flags[afi][safi], PEER_FLAG_SEND_COMMUNITY)
9046 || CHECK_FLAG(p->af_flags[afi][safi],
9047 PEER_FLAG_SEND_EXT_COMMUNITY)
9048 || CHECK_FLAG(p->af_flags[afi][safi],
9049 PEER_FLAG_SEND_LARGE_COMMUNITY)) {
9050 vty_out(vty,
9051 " Community attribute sent to this neighbor");
9052 if (CHECK_FLAG(p->af_flags[afi][safi],
9053 PEER_FLAG_SEND_COMMUNITY)
9054 && CHECK_FLAG(p->af_flags[afi][safi],
9055 PEER_FLAG_SEND_EXT_COMMUNITY)
9056 && CHECK_FLAG(p->af_flags[afi][safi],
9057 PEER_FLAG_SEND_LARGE_COMMUNITY))
9058 vty_out(vty, "(all)\n");
9059 else if (CHECK_FLAG(p->af_flags[afi][safi],
9060 PEER_FLAG_SEND_LARGE_COMMUNITY))
9061 vty_out(vty, "(large)\n");
9062 else if (CHECK_FLAG(p->af_flags[afi][safi],
9063 PEER_FLAG_SEND_EXT_COMMUNITY))
9064 vty_out(vty, "(extended)\n");
9065 else
9066 vty_out(vty, "(standard)\n");
9067 }
9068 if (CHECK_FLAG(p->af_flags[afi][safi],
9069 PEER_FLAG_DEFAULT_ORIGINATE)) {
9070 vty_out(vty, " Default information originate,");
9071
9072 if (p->default_rmap[afi][safi].name)
9073 vty_out(vty, " default route-map %s%s,",
9074 p->default_rmap[afi][safi].map ? "*"
9075 : "",
9076 p->default_rmap[afi][safi].name);
9077 if (paf && PAF_SUBGRP(paf)
9078 && CHECK_FLAG(PAF_SUBGRP(paf)->sflags,
9079 SUBGRP_STATUS_DEFAULT_ORIGINATE))
9080 vty_out(vty, " default sent\n");
9081 else
9082 vty_out(vty, " default not sent\n");
9083 }
9084
9085 /* advertise-vni-all */
9086 if (afi == AFI_L2VPN && safi == SAFI_EVPN) {
9087 if (is_evpn_enabled())
9088 vty_out(vty, " advertise-all-vni\n");
9089 }
9090
9091 if (filter->plist[FILTER_IN].name
9092 || filter->dlist[FILTER_IN].name
9093 || filter->aslist[FILTER_IN].name
9094 || filter->map[RMAP_IN].name)
9095 vty_out(vty, " Inbound path policy configured\n");
9096 if (filter->plist[FILTER_OUT].name
9097 || filter->dlist[FILTER_OUT].name
9098 || filter->aslist[FILTER_OUT].name
9099 || filter->map[RMAP_OUT].name || filter->usmap.name)
9100 vty_out(vty, " Outbound path policy configured\n");
9101
9102 /* prefix-list */
9103 if (filter->plist[FILTER_IN].name)
9104 vty_out(vty,
9105 " Incoming update prefix filter list is %s%s\n",
9106 filter->plist[FILTER_IN].plist ? "*" : "",
9107 filter->plist[FILTER_IN].name);
9108 if (filter->plist[FILTER_OUT].name)
9109 vty_out(vty,
9110 " Outgoing update prefix filter list is %s%s\n",
9111 filter->plist[FILTER_OUT].plist ? "*" : "",
9112 filter->plist[FILTER_OUT].name);
9113
9114 /* distribute-list */
9115 if (filter->dlist[FILTER_IN].name)
9116 vty_out(vty,
9117 " Incoming update network filter list is %s%s\n",
9118 filter->dlist[FILTER_IN].alist ? "*" : "",
9119 filter->dlist[FILTER_IN].name);
9120 if (filter->dlist[FILTER_OUT].name)
9121 vty_out(vty,
9122 " Outgoing update network filter list is %s%s\n",
9123 filter->dlist[FILTER_OUT].alist ? "*" : "",
9124 filter->dlist[FILTER_OUT].name);
9125
9126 /* filter-list. */
9127 if (filter->aslist[FILTER_IN].name)
9128 vty_out(vty,
9129 " Incoming update AS path filter list is %s%s\n",
9130 filter->aslist[FILTER_IN].aslist ? "*" : "",
9131 filter->aslist[FILTER_IN].name);
9132 if (filter->aslist[FILTER_OUT].name)
9133 vty_out(vty,
9134 " Outgoing update AS path filter list is %s%s\n",
9135 filter->aslist[FILTER_OUT].aslist ? "*" : "",
9136 filter->aslist[FILTER_OUT].name);
9137
9138 /* route-map. */
9139 if (filter->map[RMAP_IN].name)
9140 vty_out(vty,
9141 " Route map for incoming advertisements is %s%s\n",
9142 filter->map[RMAP_IN].map ? "*" : "",
9143 filter->map[RMAP_IN].name);
9144 if (filter->map[RMAP_OUT].name)
9145 vty_out(vty,
9146 " Route map for outgoing advertisements is %s%s\n",
9147 filter->map[RMAP_OUT].map ? "*" : "",
9148 filter->map[RMAP_OUT].name);
9149
9150 /* ebgp-requires-policy (inbound) */
9151 if (p->bgp->ebgp_requires_policy == DEFAULT_EBGP_POLICY_ENABLED
9152 && !bgp_inbound_policy_exists(p, filter))
9153 vty_out(vty,
9154 " Inbound updates discarded due to missing policy\n");
9155
9156 /* ebgp-requires-policy (outbound) */
9157 if (p->bgp->ebgp_requires_policy == DEFAULT_EBGP_POLICY_ENABLED
9158 && !bgp_outbound_policy_exists(p, filter))
9159 vty_out(vty,
9160 " Outbound updates discarded due to missing policy\n");
9161
9162 /* unsuppress-map */
9163 if (filter->usmap.name)
9164 vty_out(vty,
9165 " Route map for selective unsuppress is %s%s\n",
9166 filter->usmap.map ? "*" : "",
9167 filter->usmap.name);
9168
9169 /* Receive prefix count */
9170 vty_out(vty, " %ld accepted prefixes\n", p->pcount[afi][safi]);
9171
9172 /* Maximum prefix */
9173 if (CHECK_FLAG(p->af_flags[afi][safi], PEER_FLAG_MAX_PREFIX)) {
9174 vty_out(vty, " Maximum prefixes allowed %ld%s\n",
9175 p->pmax[afi][safi],
9176 CHECK_FLAG(p->af_flags[afi][safi],
9177 PEER_FLAG_MAX_PREFIX_WARNING)
9178 ? " (warning-only)"
9179 : "");
9180 vty_out(vty, " Threshold for warning message %d%%",
9181 p->pmax_threshold[afi][safi]);
9182 if (p->pmax_restart[afi][safi])
9183 vty_out(vty, ", restart interval %d min",
9184 p->pmax_restart[afi][safi]);
9185 vty_out(vty, "\n");
9186 }
9187
9188 vty_out(vty, "\n");
9189 }
9190 }
9191
9192 static void bgp_show_peer(struct vty *vty, struct peer *p, bool use_json,
9193 json_object *json)
9194 {
9195 struct bgp *bgp;
9196 char buf1[PREFIX2STR_BUFFER], buf[SU_ADDRSTRLEN];
9197 char timebuf[BGP_UPTIME_LEN];
9198 char dn_flag[2];
9199 const char *subcode_str;
9200 const char *code_str;
9201 afi_t afi;
9202 safi_t safi;
9203 uint16_t i;
9204 uint8_t *msg;
9205 json_object *json_neigh = NULL;
9206 time_t epoch_tbuf;
9207
9208 bgp = p->bgp;
9209
9210 if (use_json)
9211 json_neigh = json_object_new_object();
9212
9213 memset(dn_flag, '\0', sizeof(dn_flag));
9214 if (!p->conf_if && peer_dynamic_neighbor(p))
9215 dn_flag[0] = '*';
9216
9217 if (!use_json) {
9218 if (p->conf_if) /* Configured interface name. */
9219 vty_out(vty, "BGP neighbor on %s: %s, ", p->conf_if,
9220 BGP_PEER_SU_UNSPEC(p)
9221 ? "None"
9222 : sockunion2str(&p->su, buf,
9223 SU_ADDRSTRLEN));
9224 else /* Configured IP address. */
9225 vty_out(vty, "BGP neighbor is %s%s, ", dn_flag,
9226 p->host);
9227 }
9228
9229 if (use_json) {
9230 if (p->conf_if && BGP_PEER_SU_UNSPEC(p))
9231 json_object_string_add(json_neigh, "bgpNeighborAddr",
9232 "none");
9233 else if (p->conf_if && !BGP_PEER_SU_UNSPEC(p))
9234 json_object_string_add(
9235 json_neigh, "bgpNeighborAddr",
9236 sockunion2str(&p->su, buf, SU_ADDRSTRLEN));
9237
9238 json_object_int_add(json_neigh, "remoteAs", p->as);
9239
9240 if (p->change_local_as)
9241 json_object_int_add(json_neigh, "localAs",
9242 p->change_local_as);
9243 else
9244 json_object_int_add(json_neigh, "localAs", p->local_as);
9245
9246 if (CHECK_FLAG(p->flags, PEER_FLAG_LOCAL_AS_NO_PREPEND))
9247 json_object_boolean_true_add(json_neigh,
9248 "localAsNoPrepend");
9249
9250 if (CHECK_FLAG(p->flags, PEER_FLAG_LOCAL_AS_REPLACE_AS))
9251 json_object_boolean_true_add(json_neigh,
9252 "localAsReplaceAs");
9253 } else {
9254 if ((p->as_type == AS_SPECIFIED) || (p->as_type == AS_EXTERNAL)
9255 || (p->as_type == AS_INTERNAL))
9256 vty_out(vty, "remote AS %u, ", p->as);
9257 else
9258 vty_out(vty, "remote AS Unspecified, ");
9259 vty_out(vty, "local AS %u%s%s, ",
9260 p->change_local_as ? p->change_local_as : p->local_as,
9261 CHECK_FLAG(p->flags, PEER_FLAG_LOCAL_AS_NO_PREPEND)
9262 ? " no-prepend"
9263 : "",
9264 CHECK_FLAG(p->flags, PEER_FLAG_LOCAL_AS_REPLACE_AS)
9265 ? " replace-as"
9266 : "");
9267 }
9268 /* peer type internal or confed-internal */
9269 if ((p->as == p->local_as) || (p->as_type == AS_INTERNAL)) {
9270 if (use_json) {
9271 if (CHECK_FLAG(bgp->config, BGP_CONFIG_CONFEDERATION))
9272 json_object_boolean_true_add(
9273 json_neigh, "nbrConfedInternalLink");
9274 else
9275 json_object_boolean_true_add(json_neigh,
9276 "nbrInternalLink");
9277 } else {
9278 if (CHECK_FLAG(bgp->config, BGP_CONFIG_CONFEDERATION))
9279 vty_out(vty, "confed-internal link\n");
9280 else
9281 vty_out(vty, "internal link\n");
9282 }
9283 /* peer type external or confed-external */
9284 } else if (p->as || (p->as_type == AS_EXTERNAL)) {
9285 if (use_json) {
9286 if (CHECK_FLAG(bgp->config, BGP_CONFIG_CONFEDERATION))
9287 json_object_boolean_true_add(
9288 json_neigh, "nbrConfedExternalLink");
9289 else
9290 json_object_boolean_true_add(json_neigh,
9291 "nbrExternalLink");
9292 } else {
9293 if (bgp_confederation_peers_check(bgp, p->as))
9294 vty_out(vty, "confed-external link\n");
9295 else
9296 vty_out(vty, "external link\n");
9297 }
9298 } else {
9299 if (use_json)
9300 json_object_boolean_true_add(json_neigh,
9301 "nbrUnspecifiedLink");
9302 else
9303 vty_out(vty, "unspecified link\n");
9304 }
9305
9306 /* Description. */
9307 if (p->desc) {
9308 if (use_json)
9309 json_object_string_add(json_neigh, "nbrDesc", p->desc);
9310 else
9311 vty_out(vty, " Description: %s\n", p->desc);
9312 }
9313
9314 if (p->hostname) {
9315 if (use_json) {
9316 if (p->hostname)
9317 json_object_string_add(json_neigh, "hostname",
9318 p->hostname);
9319
9320 if (p->domainname)
9321 json_object_string_add(json_neigh, "domainname",
9322 p->domainname);
9323 } else {
9324 if (p->domainname && (p->domainname[0] != '\0'))
9325 vty_out(vty, "Hostname: %s.%s\n", p->hostname,
9326 p->domainname);
9327 else
9328 vty_out(vty, "Hostname: %s\n", p->hostname);
9329 }
9330 }
9331
9332 /* Peer-group */
9333 if (p->group) {
9334 if (use_json) {
9335 json_object_string_add(json_neigh, "peerGroup",
9336 p->group->name);
9337
9338 if (dn_flag[0]) {
9339 struct prefix prefix, *range = NULL;
9340
9341 sockunion2hostprefix(&(p->su), &prefix);
9342 range = peer_group_lookup_dynamic_neighbor_range(
9343 p->group, &prefix);
9344
9345 if (range) {
9346 prefix2str(range, buf1, sizeof(buf1));
9347 json_object_string_add(
9348 json_neigh,
9349 "peerSubnetRangeGroup", buf1);
9350 }
9351 }
9352 } else {
9353 vty_out(vty,
9354 " Member of peer-group %s for session parameters\n",
9355 p->group->name);
9356
9357 if (dn_flag[0]) {
9358 struct prefix prefix, *range = NULL;
9359
9360 sockunion2hostprefix(&(p->su), &prefix);
9361 range = peer_group_lookup_dynamic_neighbor_range(
9362 p->group, &prefix);
9363
9364 if (range) {
9365 prefix2str(range, buf1, sizeof(buf1));
9366 vty_out(vty,
9367 " Belongs to the subnet range group: %s\n",
9368 buf1);
9369 }
9370 }
9371 }
9372 }
9373
9374 if (use_json) {
9375 /* Administrative shutdown. */
9376 if (CHECK_FLAG(p->flags, PEER_FLAG_SHUTDOWN))
9377 json_object_boolean_true_add(json_neigh,
9378 "adminShutDown");
9379
9380 /* BGP Version. */
9381 json_object_int_add(json_neigh, "bgpVersion", 4);
9382 json_object_string_add(
9383 json_neigh, "remoteRouterId",
9384 inet_ntop(AF_INET, &p->remote_id, buf1, sizeof(buf1)));
9385 json_object_string_add(
9386 json_neigh, "localRouterId",
9387 inet_ntop(AF_INET, &bgp->router_id, buf1,
9388 sizeof(buf1)));
9389
9390 /* Confederation */
9391 if (CHECK_FLAG(bgp->config, BGP_CONFIG_CONFEDERATION)
9392 && bgp_confederation_peers_check(bgp, p->as))
9393 json_object_boolean_true_add(json_neigh,
9394 "nbrCommonAdmin");
9395
9396 /* Status. */
9397 json_object_string_add(
9398 json_neigh, "bgpState",
9399 lookup_msg(bgp_status_msg, p->status, NULL));
9400
9401 if (p->status == Established) {
9402 time_t uptime;
9403
9404 uptime = bgp_clock();
9405 uptime -= p->uptime;
9406 epoch_tbuf = time(NULL) - uptime;
9407
9408 #if CONFDATE > 20200101
9409 CPP_NOTICE(
9410 "bgpTimerUp should be deprecated and can be removed now");
9411 #endif
9412 /*
9413 * bgpTimerUp was miliseconds that was accurate
9414 * up to 1 day, then the value returned
9415 * became garbage. So in order to provide
9416 * some level of backwards compatability,
9417 * we still provde the data, but now
9418 * we are returning the correct value
9419 * and also adding a new bgpTimerUpMsec
9420 * which will allow us to deprecate
9421 * this eventually
9422 */
9423 json_object_int_add(json_neigh, "bgpTimerUp",
9424 uptime * 1000);
9425 json_object_int_add(json_neigh, "bgpTimerUpMsec",
9426 uptime * 1000);
9427 json_object_string_add(json_neigh, "bgpTimerUpString",
9428 peer_uptime(p->uptime, timebuf,
9429 BGP_UPTIME_LEN, 0,
9430 NULL));
9431 json_object_int_add(json_neigh,
9432 "bgpTimerUpEstablishedEpoch",
9433 epoch_tbuf);
9434 }
9435
9436 else if (p->status == Active) {
9437 if (CHECK_FLAG(p->flags, PEER_FLAG_PASSIVE))
9438 json_object_string_add(json_neigh, "bgpStateIs",
9439 "passive");
9440 else if (CHECK_FLAG(p->sflags, PEER_STATUS_NSF_WAIT))
9441 json_object_string_add(json_neigh, "bgpStateIs",
9442 "passiveNSF");
9443 }
9444
9445 /* read timer */
9446 time_t uptime;
9447 struct tm *tm;
9448
9449 uptime = bgp_clock();
9450 uptime -= p->readtime;
9451 tm = gmtime(&uptime);
9452 json_object_int_add(json_neigh, "bgpTimerLastRead",
9453 (tm->tm_sec * 1000) + (tm->tm_min * 60000)
9454 + (tm->tm_hour * 3600000));
9455
9456 uptime = bgp_clock();
9457 uptime -= p->last_write;
9458 tm = gmtime(&uptime);
9459 json_object_int_add(json_neigh, "bgpTimerLastWrite",
9460 (tm->tm_sec * 1000) + (tm->tm_min * 60000)
9461 + (tm->tm_hour * 3600000));
9462
9463 uptime = bgp_clock();
9464 uptime -= p->update_time;
9465 tm = gmtime(&uptime);
9466 json_object_int_add(json_neigh, "bgpInUpdateElapsedTimeMsecs",
9467 (tm->tm_sec * 1000) + (tm->tm_min * 60000)
9468 + (tm->tm_hour * 3600000));
9469
9470 /* Configured timer values. */
9471 json_object_int_add(json_neigh, "bgpTimerHoldTimeMsecs",
9472 p->v_holdtime * 1000);
9473 json_object_int_add(json_neigh,
9474 "bgpTimerKeepAliveIntervalMsecs",
9475 p->v_keepalive * 1000);
9476 if (CHECK_FLAG(p->flags, PEER_FLAG_TIMER)) {
9477 json_object_int_add(json_neigh,
9478 "bgpTimerConfiguredHoldTimeMsecs",
9479 p->holdtime * 1000);
9480 json_object_int_add(
9481 json_neigh,
9482 "bgpTimerConfiguredKeepAliveIntervalMsecs",
9483 p->keepalive * 1000);
9484 } else if ((bgp->default_holdtime != BGP_DEFAULT_HOLDTIME)
9485 || (bgp->default_keepalive
9486 != BGP_DEFAULT_KEEPALIVE)) {
9487 json_object_int_add(json_neigh,
9488 "bgpTimerConfiguredHoldTimeMsecs",
9489 bgp->default_holdtime);
9490 json_object_int_add(
9491 json_neigh,
9492 "bgpTimerConfiguredKeepAliveIntervalMsecs",
9493 bgp->default_keepalive);
9494 }
9495 } else {
9496 /* Administrative shutdown. */
9497 if (CHECK_FLAG(p->flags, PEER_FLAG_SHUTDOWN))
9498 vty_out(vty, " Administratively shut down\n");
9499
9500 /* BGP Version. */
9501 vty_out(vty, " BGP version 4");
9502 vty_out(vty, ", remote router ID %s",
9503 inet_ntop(AF_INET, &p->remote_id, buf1, sizeof(buf1)));
9504 vty_out(vty, ", local router ID %s\n",
9505 inet_ntop(AF_INET, &bgp->router_id, buf1,
9506 sizeof(buf1)));
9507
9508 /* Confederation */
9509 if (CHECK_FLAG(bgp->config, BGP_CONFIG_CONFEDERATION)
9510 && bgp_confederation_peers_check(bgp, p->as))
9511 vty_out(vty,
9512 " Neighbor under common administration\n");
9513
9514 /* Status. */
9515 vty_out(vty, " BGP state = %s",
9516 lookup_msg(bgp_status_msg, p->status, NULL));
9517
9518 if (p->status == Established)
9519 vty_out(vty, ", up for %8s",
9520 peer_uptime(p->uptime, timebuf, BGP_UPTIME_LEN,
9521 0, NULL));
9522
9523 else if (p->status == Active) {
9524 if (CHECK_FLAG(p->flags, PEER_FLAG_PASSIVE))
9525 vty_out(vty, " (passive)");
9526 else if (CHECK_FLAG(p->sflags, PEER_STATUS_NSF_WAIT))
9527 vty_out(vty, " (NSF passive)");
9528 }
9529 vty_out(vty, "\n");
9530
9531 /* read timer */
9532 vty_out(vty, " Last read %s",
9533 peer_uptime(p->readtime, timebuf, BGP_UPTIME_LEN, 0,
9534 NULL));
9535 vty_out(vty, ", Last write %s\n",
9536 peer_uptime(p->last_write, timebuf, BGP_UPTIME_LEN, 0,
9537 NULL));
9538
9539 /* Configured timer values. */
9540 vty_out(vty,
9541 " Hold time is %d, keepalive interval is %d seconds\n",
9542 p->v_holdtime, p->v_keepalive);
9543 if (CHECK_FLAG(p->flags, PEER_FLAG_TIMER)) {
9544 vty_out(vty, " Configured hold time is %d",
9545 p->holdtime);
9546 vty_out(vty, ", keepalive interval is %d seconds\n",
9547 p->keepalive);
9548 } else if ((bgp->default_holdtime != BGP_DEFAULT_HOLDTIME)
9549 || (bgp->default_keepalive
9550 != BGP_DEFAULT_KEEPALIVE)) {
9551 vty_out(vty, " Configured hold time is %d",
9552 bgp->default_holdtime);
9553 vty_out(vty, ", keepalive interval is %d seconds\n",
9554 bgp->default_keepalive);
9555 }
9556 }
9557 /* Capability. */
9558 if (p->status == Established) {
9559 if (p->cap || p->afc_adv[AFI_IP][SAFI_UNICAST]
9560 || p->afc_recv[AFI_IP][SAFI_UNICAST]
9561 || p->afc_adv[AFI_IP][SAFI_MULTICAST]
9562 || p->afc_recv[AFI_IP][SAFI_MULTICAST]
9563 || p->afc_adv[AFI_IP6][SAFI_UNICAST]
9564 || p->afc_recv[AFI_IP6][SAFI_UNICAST]
9565 || p->afc_adv[AFI_IP6][SAFI_MULTICAST]
9566 || p->afc_recv[AFI_IP6][SAFI_MULTICAST]
9567 || p->afc_adv[AFI_IP6][SAFI_MPLS_VPN]
9568 || p->afc_recv[AFI_IP6][SAFI_MPLS_VPN]
9569 || p->afc_adv[AFI_IP6][SAFI_ENCAP]
9570 || p->afc_recv[AFI_IP6][SAFI_ENCAP]
9571 || p->afc_adv[AFI_IP6][SAFI_FLOWSPEC]
9572 || p->afc_recv[AFI_IP6][SAFI_FLOWSPEC]
9573 || p->afc_adv[AFI_IP][SAFI_ENCAP]
9574 || p->afc_recv[AFI_IP][SAFI_ENCAP]
9575 || p->afc_adv[AFI_IP][SAFI_FLOWSPEC]
9576 || p->afc_recv[AFI_IP][SAFI_FLOWSPEC]
9577 || p->afc_adv[AFI_IP][SAFI_MPLS_VPN]
9578 || p->afc_recv[AFI_IP][SAFI_MPLS_VPN]) {
9579 if (use_json) {
9580 json_object *json_cap = NULL;
9581
9582 json_cap = json_object_new_object();
9583
9584 /* AS4 */
9585 if (CHECK_FLAG(p->cap, PEER_CAP_AS4_RCV)
9586 || CHECK_FLAG(p->cap, PEER_CAP_AS4_ADV)) {
9587 if (CHECK_FLAG(p->cap, PEER_CAP_AS4_ADV)
9588 && CHECK_FLAG(p->cap,
9589 PEER_CAP_AS4_RCV))
9590 json_object_string_add(
9591 json_cap, "4byteAs",
9592 "advertisedAndReceived");
9593 else if (CHECK_FLAG(p->cap,
9594 PEER_CAP_AS4_ADV))
9595 json_object_string_add(
9596 json_cap, "4byteAs",
9597 "advertised");
9598 else if (CHECK_FLAG(p->cap,
9599 PEER_CAP_AS4_RCV))
9600 json_object_string_add(
9601 json_cap, "4byteAs",
9602 "received");
9603 }
9604
9605 /* AddPath */
9606 if (CHECK_FLAG(p->cap, PEER_CAP_ADDPATH_RCV)
9607 || CHECK_FLAG(p->cap,
9608 PEER_CAP_ADDPATH_ADV)) {
9609 json_object *json_add = NULL;
9610 const char *print_store;
9611
9612 json_add = json_object_new_object();
9613
9614 FOREACH_AFI_SAFI (afi, safi) {
9615 json_object *json_sub = NULL;
9616 json_sub =
9617 json_object_new_object();
9618 print_store = afi_safi_print(
9619 afi, safi);
9620
9621 if (CHECK_FLAG(
9622 p->af_cap[afi]
9623 [safi],
9624 PEER_CAP_ADDPATH_AF_TX_ADV)
9625 || CHECK_FLAG(
9626 p->af_cap[afi]
9627 [safi],
9628 PEER_CAP_ADDPATH_AF_TX_RCV)) {
9629 if (CHECK_FLAG(
9630 p->af_cap
9631 [afi]
9632 [safi],
9633 PEER_CAP_ADDPATH_AF_TX_ADV)
9634 && CHECK_FLAG(
9635 p->af_cap
9636 [afi]
9637 [safi],
9638 PEER_CAP_ADDPATH_AF_TX_RCV))
9639 json_object_boolean_true_add(
9640 json_sub,
9641 "txAdvertisedAndReceived");
9642 else if (
9643 CHECK_FLAG(
9644 p->af_cap
9645 [afi]
9646 [safi],
9647 PEER_CAP_ADDPATH_AF_TX_ADV))
9648 json_object_boolean_true_add(
9649 json_sub,
9650 "txAdvertised");
9651 else if (
9652 CHECK_FLAG(
9653 p->af_cap
9654 [afi]
9655 [safi],
9656 PEER_CAP_ADDPATH_AF_TX_RCV))
9657 json_object_boolean_true_add(
9658 json_sub,
9659 "txReceived");
9660 }
9661
9662 if (CHECK_FLAG(
9663 p->af_cap[afi]
9664 [safi],
9665 PEER_CAP_ADDPATH_AF_RX_ADV)
9666 || CHECK_FLAG(
9667 p->af_cap[afi]
9668 [safi],
9669 PEER_CAP_ADDPATH_AF_RX_RCV)) {
9670 if (CHECK_FLAG(
9671 p->af_cap
9672 [afi]
9673 [safi],
9674 PEER_CAP_ADDPATH_AF_RX_ADV)
9675 && CHECK_FLAG(
9676 p->af_cap
9677 [afi]
9678 [safi],
9679 PEER_CAP_ADDPATH_AF_RX_RCV))
9680 json_object_boolean_true_add(
9681 json_sub,
9682 "rxAdvertisedAndReceived");
9683 else if (
9684 CHECK_FLAG(
9685 p->af_cap
9686 [afi]
9687 [safi],
9688 PEER_CAP_ADDPATH_AF_RX_ADV))
9689 json_object_boolean_true_add(
9690 json_sub,
9691 "rxAdvertised");
9692 else if (
9693 CHECK_FLAG(
9694 p->af_cap
9695 [afi]
9696 [safi],
9697 PEER_CAP_ADDPATH_AF_RX_RCV))
9698 json_object_boolean_true_add(
9699 json_sub,
9700 "rxReceived");
9701 }
9702
9703 if (CHECK_FLAG(
9704 p->af_cap[afi]
9705 [safi],
9706 PEER_CAP_ADDPATH_AF_TX_ADV)
9707 || CHECK_FLAG(
9708 p->af_cap[afi]
9709 [safi],
9710 PEER_CAP_ADDPATH_AF_TX_RCV)
9711 || CHECK_FLAG(
9712 p->af_cap[afi]
9713 [safi],
9714 PEER_CAP_ADDPATH_AF_RX_ADV)
9715 || CHECK_FLAG(
9716 p->af_cap[afi]
9717 [safi],
9718 PEER_CAP_ADDPATH_AF_RX_RCV))
9719 json_object_object_add(
9720 json_add,
9721 print_store,
9722 json_sub);
9723 else
9724 json_object_free(
9725 json_sub);
9726 }
9727
9728 json_object_object_add(
9729 json_cap, "addPath", json_add);
9730 }
9731
9732 /* Dynamic */
9733 if (CHECK_FLAG(p->cap, PEER_CAP_DYNAMIC_RCV)
9734 || CHECK_FLAG(p->cap,
9735 PEER_CAP_DYNAMIC_ADV)) {
9736 if (CHECK_FLAG(p->cap,
9737 PEER_CAP_DYNAMIC_ADV)
9738 && CHECK_FLAG(p->cap,
9739 PEER_CAP_DYNAMIC_RCV))
9740 json_object_string_add(
9741 json_cap, "dynamic",
9742 "advertisedAndReceived");
9743 else if (CHECK_FLAG(
9744 p->cap,
9745 PEER_CAP_DYNAMIC_ADV))
9746 json_object_string_add(
9747 json_cap, "dynamic",
9748 "advertised");
9749 else if (CHECK_FLAG(
9750 p->cap,
9751 PEER_CAP_DYNAMIC_RCV))
9752 json_object_string_add(
9753 json_cap, "dynamic",
9754 "received");
9755 }
9756
9757 /* Extended nexthop */
9758 if (CHECK_FLAG(p->cap, PEER_CAP_ENHE_RCV)
9759 || CHECK_FLAG(p->cap, PEER_CAP_ENHE_ADV)) {
9760 json_object *json_nxt = NULL;
9761 const char *print_store;
9762
9763
9764 if (CHECK_FLAG(p->cap,
9765 PEER_CAP_ENHE_ADV)
9766 && CHECK_FLAG(p->cap,
9767 PEER_CAP_ENHE_RCV))
9768 json_object_string_add(
9769 json_cap,
9770 "extendedNexthop",
9771 "advertisedAndReceived");
9772 else if (CHECK_FLAG(p->cap,
9773 PEER_CAP_ENHE_ADV))
9774 json_object_string_add(
9775 json_cap,
9776 "extendedNexthop",
9777 "advertised");
9778 else if (CHECK_FLAG(p->cap,
9779 PEER_CAP_ENHE_RCV))
9780 json_object_string_add(
9781 json_cap,
9782 "extendedNexthop",
9783 "received");
9784
9785 if (CHECK_FLAG(p->cap,
9786 PEER_CAP_ENHE_RCV)) {
9787 json_nxt =
9788 json_object_new_object();
9789
9790 for (safi = SAFI_UNICAST;
9791 safi < SAFI_MAX; safi++) {
9792 if (CHECK_FLAG(
9793 p->af_cap
9794 [AFI_IP]
9795 [safi],
9796 PEER_CAP_ENHE_AF_RCV)) {
9797 print_store = afi_safi_print(
9798 AFI_IP,
9799 safi);
9800 json_object_string_add(
9801 json_nxt,
9802 print_store,
9803 "recieved"); /* misspelled for compatibility */
9804 }
9805 }
9806 json_object_object_add(
9807 json_cap,
9808 "extendedNexthopFamililesByPeer",
9809 json_nxt);
9810 }
9811 }
9812
9813 /* Route Refresh */
9814 if (CHECK_FLAG(p->cap, PEER_CAP_REFRESH_ADV)
9815 || CHECK_FLAG(p->cap,
9816 PEER_CAP_REFRESH_NEW_RCV)
9817 || CHECK_FLAG(p->cap,
9818 PEER_CAP_REFRESH_OLD_RCV)) {
9819 if (CHECK_FLAG(p->cap,
9820 PEER_CAP_REFRESH_ADV)
9821 && (CHECK_FLAG(
9822 p->cap,
9823 PEER_CAP_REFRESH_NEW_RCV)
9824 || CHECK_FLAG(
9825 p->cap,
9826 PEER_CAP_REFRESH_OLD_RCV))) {
9827 if (CHECK_FLAG(
9828 p->cap,
9829 PEER_CAP_REFRESH_OLD_RCV)
9830 && CHECK_FLAG(
9831 p->cap,
9832 PEER_CAP_REFRESH_NEW_RCV))
9833 json_object_string_add(
9834 json_cap,
9835 "routeRefresh",
9836 "advertisedAndReceivedOldNew");
9837 else {
9838 if (CHECK_FLAG(
9839 p->cap,
9840 PEER_CAP_REFRESH_OLD_RCV))
9841 json_object_string_add(
9842 json_cap,
9843 "routeRefresh",
9844 "advertisedAndReceivedOld");
9845 else
9846 json_object_string_add(
9847 json_cap,
9848 "routeRefresh",
9849 "advertisedAndReceivedNew");
9850 }
9851 } else if (
9852 CHECK_FLAG(
9853 p->cap,
9854 PEER_CAP_REFRESH_ADV))
9855 json_object_string_add(
9856 json_cap,
9857 "routeRefresh",
9858 "advertised");
9859 else if (
9860 CHECK_FLAG(
9861 p->cap,
9862 PEER_CAP_REFRESH_NEW_RCV)
9863 || CHECK_FLAG(
9864 p->cap,
9865 PEER_CAP_REFRESH_OLD_RCV))
9866 json_object_string_add(
9867 json_cap,
9868 "routeRefresh",
9869 "received");
9870 }
9871
9872 /* Multiprotocol Extensions */
9873 json_object *json_multi = NULL;
9874 json_multi = json_object_new_object();
9875
9876 FOREACH_AFI_SAFI (afi, safi) {
9877 if (p->afc_adv[afi][safi]
9878 || p->afc_recv[afi][safi]) {
9879 json_object *json_exten = NULL;
9880 json_exten =
9881 json_object_new_object();
9882
9883 if (p->afc_adv[afi][safi]
9884 && p->afc_recv[afi][safi])
9885 json_object_boolean_true_add(
9886 json_exten,
9887 "advertisedAndReceived");
9888 else if (p->afc_adv[afi][safi])
9889 json_object_boolean_true_add(
9890 json_exten,
9891 "advertised");
9892 else if (p->afc_recv[afi][safi])
9893 json_object_boolean_true_add(
9894 json_exten,
9895 "received");
9896
9897 json_object_object_add(
9898 json_multi,
9899 afi_safi_print(afi,
9900 safi),
9901 json_exten);
9902 }
9903 }
9904 json_object_object_add(
9905 json_cap, "multiprotocolExtensions",
9906 json_multi);
9907
9908 /* Hostname capabilities */
9909 json_object *json_hname = NULL;
9910
9911 json_hname = json_object_new_object();
9912
9913 if (CHECK_FLAG(p->cap, PEER_CAP_HOSTNAME_ADV)) {
9914 json_object_string_add(
9915 json_hname, "advHostName",
9916 bgp->peer_self->hostname
9917 ? bgp->peer_self
9918 ->hostname
9919 : "n/a");
9920 json_object_string_add(
9921 json_hname, "advDomainName",
9922 bgp->peer_self->domainname
9923 ? bgp->peer_self
9924 ->domainname
9925 : "n/a");
9926 }
9927
9928
9929 if (CHECK_FLAG(p->cap, PEER_CAP_HOSTNAME_RCV)) {
9930 json_object_string_add(
9931 json_hname, "rcvHostName",
9932 p->hostname ? p->hostname
9933 : "n/a");
9934 json_object_string_add(
9935 json_hname, "rcvDomainName",
9936 p->domainname ? p->domainname
9937 : "n/a");
9938 }
9939
9940 json_object_object_add(json_cap, "hostName",
9941 json_hname);
9942
9943 /* Gracefull Restart */
9944 if (CHECK_FLAG(p->cap, PEER_CAP_RESTART_RCV)
9945 || CHECK_FLAG(p->cap,
9946 PEER_CAP_RESTART_ADV)) {
9947 if (CHECK_FLAG(p->cap,
9948 PEER_CAP_RESTART_ADV)
9949 && CHECK_FLAG(p->cap,
9950 PEER_CAP_RESTART_RCV))
9951 json_object_string_add(
9952 json_cap,
9953 "gracefulRestart",
9954 "advertisedAndReceived");
9955 else if (CHECK_FLAG(
9956 p->cap,
9957 PEER_CAP_RESTART_ADV))
9958 json_object_string_add(
9959 json_cap,
9960 "gracefulRestartCapability",
9961 "advertised");
9962 else if (CHECK_FLAG(
9963 p->cap,
9964 PEER_CAP_RESTART_RCV))
9965 json_object_string_add(
9966 json_cap,
9967 "gracefulRestartCapability",
9968 "received");
9969
9970 if (CHECK_FLAG(p->cap,
9971 PEER_CAP_RESTART_RCV)) {
9972 int restart_af_count = 0;
9973 json_object *json_restart =
9974 NULL;
9975 json_restart =
9976 json_object_new_object();
9977
9978 json_object_int_add(
9979 json_cap,
9980 "gracefulRestartRemoteTimerMsecs",
9981 p->v_gr_restart * 1000);
9982
9983 FOREACH_AFI_SAFI (afi, safi) {
9984 if (CHECK_FLAG(
9985 p->af_cap
9986 [afi]
9987 [safi],
9988 PEER_CAP_RESTART_AF_RCV)) {
9989 json_object *
9990 json_sub =
9991 NULL;
9992 json_sub =
9993 json_object_new_object();
9994
9995 if (CHECK_FLAG(
9996 p->af_cap
9997 [afi]
9998 [safi],
9999 PEER_CAP_RESTART_AF_PRESERVE_RCV))
10000 json_object_boolean_true_add(
10001 json_sub,
10002 "preserved");
10003 restart_af_count++;
10004 json_object_object_add(
10005 json_restart,
10006 afi_safi_print(
10007 afi,
10008 safi),
10009 json_sub);
10010 }
10011 }
10012 if (!restart_af_count) {
10013 json_object_string_add(
10014 json_cap,
10015 "addressFamiliesByPeer",
10016 "none");
10017 json_object_free(
10018 json_restart);
10019 } else
10020 json_object_object_add(
10021 json_cap,
10022 "addressFamiliesByPeer",
10023 json_restart);
10024 }
10025 }
10026 json_object_object_add(json_neigh,
10027 "neighborCapabilities",
10028 json_cap);
10029 } else {
10030 vty_out(vty, " Neighbor capabilities:\n");
10031
10032 /* AS4 */
10033 if (CHECK_FLAG(p->cap, PEER_CAP_AS4_RCV)
10034 || CHECK_FLAG(p->cap, PEER_CAP_AS4_ADV)) {
10035 vty_out(vty, " 4 Byte AS:");
10036 if (CHECK_FLAG(p->cap,
10037 PEER_CAP_AS4_ADV))
10038 vty_out(vty, " advertised");
10039 if (CHECK_FLAG(p->cap,
10040 PEER_CAP_AS4_RCV))
10041 vty_out(vty, " %sreceived",
10042 CHECK_FLAG(
10043 p->cap,
10044 PEER_CAP_AS4_ADV)
10045 ? "and "
10046 : "");
10047 vty_out(vty, "\n");
10048 }
10049
10050 /* AddPath */
10051 if (CHECK_FLAG(p->cap, PEER_CAP_ADDPATH_RCV)
10052 || CHECK_FLAG(p->cap,
10053 PEER_CAP_ADDPATH_ADV)) {
10054 vty_out(vty, " AddPath:\n");
10055
10056 FOREACH_AFI_SAFI (afi, safi) {
10057 if (CHECK_FLAG(
10058 p->af_cap[afi]
10059 [safi],
10060 PEER_CAP_ADDPATH_AF_TX_ADV)
10061 || CHECK_FLAG(
10062 p->af_cap[afi]
10063 [safi],
10064 PEER_CAP_ADDPATH_AF_TX_RCV)) {
10065 vty_out(vty,
10066 " %s: TX ",
10067 afi_safi_print(
10068 afi,
10069 safi));
10070
10071 if (CHECK_FLAG(
10072 p->af_cap
10073 [afi]
10074 [safi],
10075 PEER_CAP_ADDPATH_AF_TX_ADV))
10076 vty_out(vty,
10077 "advertised %s",
10078 afi_safi_print(
10079 afi,
10080 safi));
10081
10082 if (CHECK_FLAG(
10083 p->af_cap
10084 [afi]
10085 [safi],
10086 PEER_CAP_ADDPATH_AF_TX_RCV))
10087 vty_out(vty,
10088 "%sreceived",
10089 CHECK_FLAG(
10090 p->af_cap
10091 [afi]
10092 [safi],
10093 PEER_CAP_ADDPATH_AF_TX_ADV)
10094 ? " and "
10095 : "");
10096
10097 vty_out(vty, "\n");
10098 }
10099
10100 if (CHECK_FLAG(
10101 p->af_cap[afi]
10102 [safi],
10103 PEER_CAP_ADDPATH_AF_RX_ADV)
10104 || CHECK_FLAG(
10105 p->af_cap[afi]
10106 [safi],
10107 PEER_CAP_ADDPATH_AF_RX_RCV)) {
10108 vty_out(vty,
10109 " %s: RX ",
10110 afi_safi_print(
10111 afi,
10112 safi));
10113
10114 if (CHECK_FLAG(
10115 p->af_cap
10116 [afi]
10117 [safi],
10118 PEER_CAP_ADDPATH_AF_RX_ADV))
10119 vty_out(vty,
10120 "advertised %s",
10121 afi_safi_print(
10122 afi,
10123 safi));
10124
10125 if (CHECK_FLAG(
10126 p->af_cap
10127 [afi]
10128 [safi],
10129 PEER_CAP_ADDPATH_AF_RX_RCV))
10130 vty_out(vty,
10131 "%sreceived",
10132 CHECK_FLAG(
10133 p->af_cap
10134 [afi]
10135 [safi],
10136 PEER_CAP_ADDPATH_AF_RX_ADV)
10137 ? " and "
10138 : "");
10139
10140 vty_out(vty, "\n");
10141 }
10142 }
10143 }
10144
10145 /* Dynamic */
10146 if (CHECK_FLAG(p->cap, PEER_CAP_DYNAMIC_RCV)
10147 || CHECK_FLAG(p->cap,
10148 PEER_CAP_DYNAMIC_ADV)) {
10149 vty_out(vty, " Dynamic:");
10150 if (CHECK_FLAG(p->cap,
10151 PEER_CAP_DYNAMIC_ADV))
10152 vty_out(vty, " advertised");
10153 if (CHECK_FLAG(p->cap,
10154 PEER_CAP_DYNAMIC_RCV))
10155 vty_out(vty, " %sreceived",
10156 CHECK_FLAG(
10157 p->cap,
10158 PEER_CAP_DYNAMIC_ADV)
10159 ? "and "
10160 : "");
10161 vty_out(vty, "\n");
10162 }
10163
10164 /* Extended nexthop */
10165 if (CHECK_FLAG(p->cap, PEER_CAP_ENHE_RCV)
10166 || CHECK_FLAG(p->cap, PEER_CAP_ENHE_ADV)) {
10167 vty_out(vty, " Extended nexthop:");
10168 if (CHECK_FLAG(p->cap,
10169 PEER_CAP_ENHE_ADV))
10170 vty_out(vty, " advertised");
10171 if (CHECK_FLAG(p->cap,
10172 PEER_CAP_ENHE_RCV))
10173 vty_out(vty, " %sreceived",
10174 CHECK_FLAG(
10175 p->cap,
10176 PEER_CAP_ENHE_ADV)
10177 ? "and "
10178 : "");
10179 vty_out(vty, "\n");
10180
10181 if (CHECK_FLAG(p->cap,
10182 PEER_CAP_ENHE_RCV)) {
10183 vty_out(vty,
10184 " Address families by peer:\n ");
10185 for (safi = SAFI_UNICAST;
10186 safi < SAFI_MAX; safi++)
10187 if (CHECK_FLAG(
10188 p->af_cap
10189 [AFI_IP]
10190 [safi],
10191 PEER_CAP_ENHE_AF_RCV))
10192 vty_out(vty,
10193 " %s\n",
10194 afi_safi_print(
10195 AFI_IP,
10196 safi));
10197 }
10198 }
10199
10200 /* Route Refresh */
10201 if (CHECK_FLAG(p->cap, PEER_CAP_REFRESH_ADV)
10202 || CHECK_FLAG(p->cap,
10203 PEER_CAP_REFRESH_NEW_RCV)
10204 || CHECK_FLAG(p->cap,
10205 PEER_CAP_REFRESH_OLD_RCV)) {
10206 vty_out(vty, " Route refresh:");
10207 if (CHECK_FLAG(p->cap,
10208 PEER_CAP_REFRESH_ADV))
10209 vty_out(vty, " advertised");
10210 if (CHECK_FLAG(p->cap,
10211 PEER_CAP_REFRESH_NEW_RCV)
10212 || CHECK_FLAG(
10213 p->cap,
10214 PEER_CAP_REFRESH_OLD_RCV))
10215 vty_out(vty, " %sreceived(%s)",
10216 CHECK_FLAG(
10217 p->cap,
10218 PEER_CAP_REFRESH_ADV)
10219 ? "and "
10220 : "",
10221 (CHECK_FLAG(
10222 p->cap,
10223 PEER_CAP_REFRESH_OLD_RCV)
10224 && CHECK_FLAG(
10225 p->cap,
10226 PEER_CAP_REFRESH_NEW_RCV))
10227 ? "old & new"
10228 : CHECK_FLAG(
10229 p->cap,
10230 PEER_CAP_REFRESH_OLD_RCV)
10231 ? "old"
10232 : "new");
10233
10234 vty_out(vty, "\n");
10235 }
10236
10237 /* Multiprotocol Extensions */
10238 FOREACH_AFI_SAFI (afi, safi)
10239 if (p->afc_adv[afi][safi]
10240 || p->afc_recv[afi][safi]) {
10241 vty_out(vty,
10242 " Address Family %s:",
10243 afi_safi_print(afi,
10244 safi));
10245 if (p->afc_adv[afi][safi])
10246 vty_out(vty,
10247 " advertised");
10248 if (p->afc_recv[afi][safi])
10249 vty_out(vty,
10250 " %sreceived",
10251 p->afc_adv[afi]
10252 [safi]
10253 ? "and "
10254 : "");
10255 vty_out(vty, "\n");
10256 }
10257
10258 /* Hostname capability */
10259 vty_out(vty, " Hostname Capability:");
10260
10261 if (CHECK_FLAG(p->cap, PEER_CAP_HOSTNAME_ADV)) {
10262 vty_out(vty,
10263 " advertised (name: %s,domain name: %s)",
10264 bgp->peer_self->hostname
10265 ? bgp->peer_self
10266 ->hostname
10267 : "n/a",
10268 bgp->peer_self->domainname
10269 ? bgp->peer_self
10270 ->domainname
10271 : "n/a");
10272 } else {
10273 vty_out(vty, " not advertised");
10274 }
10275
10276 if (CHECK_FLAG(p->cap, PEER_CAP_HOSTNAME_RCV)) {
10277 vty_out(vty,
10278 " received (name: %s,domain name: %s)",
10279 p->hostname ? p->hostname
10280 : "n/a",
10281 p->domainname ? p->domainname
10282 : "n/a");
10283 } else {
10284 vty_out(vty, " not received");
10285 }
10286
10287 vty_out(vty, "\n");
10288
10289 /* Gracefull Restart */
10290 if (CHECK_FLAG(p->cap, PEER_CAP_RESTART_RCV)
10291 || CHECK_FLAG(p->cap,
10292 PEER_CAP_RESTART_ADV)) {
10293 vty_out(vty,
10294 " Graceful Restart Capabilty:");
10295 if (CHECK_FLAG(p->cap,
10296 PEER_CAP_RESTART_ADV))
10297 vty_out(vty, " advertised");
10298 if (CHECK_FLAG(p->cap,
10299 PEER_CAP_RESTART_RCV))
10300 vty_out(vty, " %sreceived",
10301 CHECK_FLAG(
10302 p->cap,
10303 PEER_CAP_RESTART_ADV)
10304 ? "and "
10305 : "");
10306 vty_out(vty, "\n");
10307
10308 if (CHECK_FLAG(p->cap,
10309 PEER_CAP_RESTART_RCV)) {
10310 int restart_af_count = 0;
10311
10312 vty_out(vty,
10313 " Remote Restart timer is %d seconds\n",
10314 p->v_gr_restart);
10315 vty_out(vty,
10316 " Address families by peer:\n ");
10317
10318 FOREACH_AFI_SAFI (afi, safi)
10319 if (CHECK_FLAG(
10320 p->af_cap
10321 [afi]
10322 [safi],
10323 PEER_CAP_RESTART_AF_RCV)) {
10324 vty_out(vty,
10325 "%s%s(%s)",
10326 restart_af_count
10327 ? ", "
10328 : "",
10329 afi_safi_print(
10330 afi,
10331 safi),
10332 CHECK_FLAG(
10333 p->af_cap
10334 [afi]
10335 [safi],
10336 PEER_CAP_RESTART_AF_PRESERVE_RCV)
10337 ? "preserved"
10338 : "not preserved");
10339 restart_af_count++;
10340 }
10341 if (!restart_af_count)
10342 vty_out(vty, "none");
10343 vty_out(vty, "\n");
10344 }
10345 }
10346 }
10347 }
10348 }
10349
10350 /* graceful restart information */
10351 if (CHECK_FLAG(p->cap, PEER_CAP_RESTART_RCV) || p->t_gr_restart
10352 || p->t_gr_stale) {
10353 json_object *json_grace = NULL;
10354 json_object *json_grace_send = NULL;
10355 json_object *json_grace_recv = NULL;
10356 int eor_send_af_count = 0;
10357 int eor_receive_af_count = 0;
10358
10359 if (use_json) {
10360 json_grace = json_object_new_object();
10361 json_grace_send = json_object_new_object();
10362 json_grace_recv = json_object_new_object();
10363
10364 if (p->status == Established) {
10365 FOREACH_AFI_SAFI (afi, safi) {
10366 if (CHECK_FLAG(p->af_sflags[afi][safi],
10367 PEER_STATUS_EOR_SEND)) {
10368 json_object_boolean_true_add(
10369 json_grace_send,
10370 afi_safi_print(afi,
10371 safi));
10372 eor_send_af_count++;
10373 }
10374 }
10375 FOREACH_AFI_SAFI (afi, safi) {
10376 if (CHECK_FLAG(
10377 p->af_sflags[afi][safi],
10378 PEER_STATUS_EOR_RECEIVED)) {
10379 json_object_boolean_true_add(
10380 json_grace_recv,
10381 afi_safi_print(afi,
10382 safi));
10383 eor_receive_af_count++;
10384 }
10385 }
10386 }
10387
10388 json_object_object_add(json_grace, "endOfRibSend",
10389 json_grace_send);
10390 json_object_object_add(json_grace, "endOfRibRecv",
10391 json_grace_recv);
10392
10393 if (p->t_gr_restart)
10394 json_object_int_add(json_grace,
10395 "gracefulRestartTimerMsecs",
10396 thread_timer_remain_second(
10397 p->t_gr_restart)
10398 * 1000);
10399
10400 if (p->t_gr_stale)
10401 json_object_int_add(
10402 json_grace,
10403 "gracefulStalepathTimerMsecs",
10404 thread_timer_remain_second(
10405 p->t_gr_stale)
10406 * 1000);
10407
10408 json_object_object_add(
10409 json_neigh, "gracefulRestartInfo", json_grace);
10410 } else {
10411 vty_out(vty, " Graceful restart information:\n");
10412 if (p->status == Established) {
10413 vty_out(vty, " End-of-RIB send: ");
10414 FOREACH_AFI_SAFI (afi, safi) {
10415 if (CHECK_FLAG(p->af_sflags[afi][safi],
10416 PEER_STATUS_EOR_SEND)) {
10417 vty_out(vty, "%s%s",
10418 eor_send_af_count ? ", "
10419 : "",
10420 afi_safi_print(afi,
10421 safi));
10422 eor_send_af_count++;
10423 }
10424 }
10425 vty_out(vty, "\n");
10426 vty_out(vty, " End-of-RIB received: ");
10427 FOREACH_AFI_SAFI (afi, safi) {
10428 if (CHECK_FLAG(
10429 p->af_sflags[afi][safi],
10430 PEER_STATUS_EOR_RECEIVED)) {
10431 vty_out(vty, "%s%s",
10432 eor_receive_af_count
10433 ? ", "
10434 : "",
10435 afi_safi_print(afi,
10436 safi));
10437 eor_receive_af_count++;
10438 }
10439 }
10440 vty_out(vty, "\n");
10441 }
10442
10443 if (p->t_gr_restart)
10444 vty_out(vty,
10445 " The remaining time of restart timer is %ld\n",
10446 thread_timer_remain_second(
10447 p->t_gr_restart));
10448
10449 if (p->t_gr_stale)
10450 vty_out(vty,
10451 " The remaining time of stalepath timer is %ld\n",
10452 thread_timer_remain_second(
10453 p->t_gr_stale));
10454 }
10455 }
10456 if (use_json) {
10457 json_object *json_stat = NULL;
10458 json_stat = json_object_new_object();
10459 /* Packet counts. */
10460 json_object_int_add(json_stat, "depthInq", 0);
10461 json_object_int_add(json_stat, "depthOutq",
10462 (unsigned long)p->obuf->count);
10463 json_object_int_add(json_stat, "opensSent",
10464 atomic_load_explicit(&p->open_out,
10465 memory_order_relaxed));
10466 json_object_int_add(json_stat, "opensRecv",
10467 atomic_load_explicit(&p->open_in,
10468 memory_order_relaxed));
10469 json_object_int_add(json_stat, "notificationsSent",
10470 atomic_load_explicit(&p->notify_out,
10471 memory_order_relaxed));
10472 json_object_int_add(json_stat, "notificationsRecv",
10473 atomic_load_explicit(&p->notify_in,
10474 memory_order_relaxed));
10475 json_object_int_add(json_stat, "updatesSent",
10476 atomic_load_explicit(&p->update_out,
10477 memory_order_relaxed));
10478 json_object_int_add(json_stat, "updatesRecv",
10479 atomic_load_explicit(&p->update_in,
10480 memory_order_relaxed));
10481 json_object_int_add(json_stat, "keepalivesSent",
10482 atomic_load_explicit(&p->keepalive_out,
10483 memory_order_relaxed));
10484 json_object_int_add(json_stat, "keepalivesRecv",
10485 atomic_load_explicit(&p->keepalive_in,
10486 memory_order_relaxed));
10487 json_object_int_add(json_stat, "routeRefreshSent",
10488 atomic_load_explicit(&p->refresh_out,
10489 memory_order_relaxed));
10490 json_object_int_add(json_stat, "routeRefreshRecv",
10491 atomic_load_explicit(&p->refresh_in,
10492 memory_order_relaxed));
10493 json_object_int_add(json_stat, "capabilitySent",
10494 atomic_load_explicit(&p->dynamic_cap_out,
10495 memory_order_relaxed));
10496 json_object_int_add(json_stat, "capabilityRecv",
10497 atomic_load_explicit(&p->dynamic_cap_in,
10498 memory_order_relaxed));
10499 json_object_int_add(json_stat, "totalSent", PEER_TOTAL_TX(p));
10500 json_object_int_add(json_stat, "totalRecv", PEER_TOTAL_RX(p));
10501 json_object_object_add(json_neigh, "messageStats", json_stat);
10502 } else {
10503 /* Packet counts. */
10504 vty_out(vty, " Message statistics:\n");
10505 vty_out(vty, " Inq depth is 0\n");
10506 vty_out(vty, " Outq depth is %lu\n",
10507 (unsigned long)p->obuf->count);
10508 vty_out(vty, " Sent Rcvd\n");
10509 vty_out(vty, " Opens: %10d %10d\n",
10510 atomic_load_explicit(&p->open_out,
10511 memory_order_relaxed),
10512 atomic_load_explicit(&p->open_in,
10513 memory_order_relaxed));
10514 vty_out(vty, " Notifications: %10d %10d\n",
10515 atomic_load_explicit(&p->notify_out,
10516 memory_order_relaxed),
10517 atomic_load_explicit(&p->notify_in,
10518 memory_order_relaxed));
10519 vty_out(vty, " Updates: %10d %10d\n",
10520 atomic_load_explicit(&p->update_out,
10521 memory_order_relaxed),
10522 atomic_load_explicit(&p->update_in,
10523 memory_order_relaxed));
10524 vty_out(vty, " Keepalives: %10d %10d\n",
10525 atomic_load_explicit(&p->keepalive_out,
10526 memory_order_relaxed),
10527 atomic_load_explicit(&p->keepalive_in,
10528 memory_order_relaxed));
10529 vty_out(vty, " Route Refresh: %10d %10d\n",
10530 atomic_load_explicit(&p->refresh_out,
10531 memory_order_relaxed),
10532 atomic_load_explicit(&p->refresh_in,
10533 memory_order_relaxed));
10534 vty_out(vty, " Capability: %10d %10d\n",
10535 atomic_load_explicit(&p->dynamic_cap_out,
10536 memory_order_relaxed),
10537 atomic_load_explicit(&p->dynamic_cap_in,
10538 memory_order_relaxed));
10539 vty_out(vty, " Total: %10d %10d\n", PEER_TOTAL_TX(p),
10540 PEER_TOTAL_RX(p));
10541 }
10542
10543 if (use_json) {
10544 /* advertisement-interval */
10545 json_object_int_add(json_neigh,
10546 "minBtwnAdvertisementRunsTimerMsecs",
10547 p->v_routeadv * 1000);
10548
10549 /* Update-source. */
10550 if (p->update_if || p->update_source) {
10551 if (p->update_if)
10552 json_object_string_add(json_neigh,
10553 "updateSource",
10554 p->update_if);
10555 else if (p->update_source)
10556 json_object_string_add(
10557 json_neigh, "updateSource",
10558 sockunion2str(p->update_source, buf1,
10559 SU_ADDRSTRLEN));
10560 }
10561 } else {
10562 /* advertisement-interval */
10563 vty_out(vty,
10564 " Minimum time between advertisement runs is %d seconds\n",
10565 p->v_routeadv);
10566
10567 /* Update-source. */
10568 if (p->update_if || p->update_source) {
10569 vty_out(vty, " Update source is ");
10570 if (p->update_if)
10571 vty_out(vty, "%s", p->update_if);
10572 else if (p->update_source)
10573 vty_out(vty, "%s",
10574 sockunion2str(p->update_source, buf1,
10575 SU_ADDRSTRLEN));
10576 vty_out(vty, "\n");
10577 }
10578
10579 vty_out(vty, "\n");
10580 }
10581
10582 /* Address Family Information */
10583 json_object *json_hold = NULL;
10584
10585 if (use_json)
10586 json_hold = json_object_new_object();
10587
10588 FOREACH_AFI_SAFI (afi, safi)
10589 if (p->afc[afi][safi])
10590 bgp_show_peer_afi(vty, p, afi, safi, use_json,
10591 json_hold);
10592
10593 if (use_json) {
10594 json_object_object_add(json_neigh, "addressFamilyInfo",
10595 json_hold);
10596 json_object_int_add(json_neigh, "connectionsEstablished",
10597 p->established);
10598 json_object_int_add(json_neigh, "connectionsDropped",
10599 p->dropped);
10600 } else
10601 vty_out(vty, " Connections established %d; dropped %d\n",
10602 p->established, p->dropped);
10603
10604 if (!p->last_reset) {
10605 if (use_json)
10606 json_object_string_add(json_neigh, "lastReset",
10607 "never");
10608 else
10609 vty_out(vty, " Last reset never\n");
10610 } else {
10611 if (use_json) {
10612 time_t uptime;
10613 struct tm *tm;
10614
10615 uptime = bgp_clock();
10616 uptime -= p->resettime;
10617 tm = gmtime(&uptime);
10618 json_object_int_add(json_neigh, "lastResetTimerMsecs",
10619 (tm->tm_sec * 1000)
10620 + (tm->tm_min * 60000)
10621 + (tm->tm_hour * 3600000));
10622 json_object_string_add(
10623 json_neigh, "lastResetDueTo",
10624 peer_down_str[(int)p->last_reset]);
10625 if (p->last_reset == PEER_DOWN_NOTIFY_SEND
10626 || p->last_reset == PEER_DOWN_NOTIFY_RECEIVED) {
10627 char errorcodesubcode_hexstr[5];
10628 char errorcodesubcode_str[256];
10629
10630 code_str = bgp_notify_code_str(p->notify.code);
10631 subcode_str = bgp_notify_subcode_str(
10632 p->notify.code, p->notify.subcode);
10633
10634 sprintf(errorcodesubcode_hexstr, "%02X%02X",
10635 p->notify.code, p->notify.subcode);
10636 json_object_string_add(json_neigh,
10637 "lastErrorCodeSubcode",
10638 errorcodesubcode_hexstr);
10639 snprintf(errorcodesubcode_str, 255, "%s%s",
10640 code_str, subcode_str);
10641 json_object_string_add(json_neigh,
10642 "lastNotificationReason",
10643 errorcodesubcode_str);
10644 if (p->last_reset == PEER_DOWN_NOTIFY_RECEIVED
10645 && p->notify.code == BGP_NOTIFY_CEASE
10646 && (p->notify.subcode
10647 == BGP_NOTIFY_CEASE_ADMIN_SHUTDOWN
10648 || p->notify.subcode
10649 == BGP_NOTIFY_CEASE_ADMIN_RESET)
10650 && p->notify.length) {
10651 char msgbuf[1024];
10652 const char *msg_str;
10653
10654 msg_str = bgp_notify_admin_message(
10655 msgbuf, sizeof(msgbuf),
10656 (uint8_t *)p->notify.data,
10657 p->notify.length);
10658 if (msg_str)
10659 json_object_string_add(
10660 json_neigh,
10661 "lastShutdownDescription",
10662 msg_str);
10663 }
10664 }
10665 } else {
10666 vty_out(vty, " Last reset %s, ",
10667 peer_uptime(p->resettime, timebuf,
10668 BGP_UPTIME_LEN, 0, NULL));
10669
10670 if (p->last_reset == PEER_DOWN_NOTIFY_SEND
10671 || p->last_reset == PEER_DOWN_NOTIFY_RECEIVED) {
10672 code_str = bgp_notify_code_str(p->notify.code);
10673 subcode_str = bgp_notify_subcode_str(
10674 p->notify.code, p->notify.subcode);
10675 vty_out(vty, "due to NOTIFICATION %s (%s%s)\n",
10676 p->last_reset == PEER_DOWN_NOTIFY_SEND
10677 ? "sent"
10678 : "received",
10679 code_str, subcode_str);
10680 if (p->last_reset == PEER_DOWN_NOTIFY_RECEIVED
10681 && p->notify.code == BGP_NOTIFY_CEASE
10682 && (p->notify.subcode
10683 == BGP_NOTIFY_CEASE_ADMIN_SHUTDOWN
10684 || p->notify.subcode
10685 == BGP_NOTIFY_CEASE_ADMIN_RESET)
10686 && p->notify.length) {
10687 char msgbuf[1024];
10688 const char *msg_str;
10689
10690 msg_str = bgp_notify_admin_message(
10691 msgbuf, sizeof(msgbuf),
10692 (uint8_t *)p->notify.data,
10693 p->notify.length);
10694 if (msg_str)
10695 vty_out(vty,
10696 " Message: \"%s\"\n",
10697 msg_str);
10698 }
10699 } else {
10700 vty_out(vty, "due to %s\n",
10701 peer_down_str[(int)p->last_reset]);
10702 }
10703
10704 if (p->last_reset_cause_size) {
10705 msg = p->last_reset_cause;
10706 vty_out(vty,
10707 " Message received that caused BGP to send a NOTIFICATION:\n ");
10708 for (i = 1; i <= p->last_reset_cause_size;
10709 i++) {
10710 vty_out(vty, "%02X", *msg++);
10711
10712 if (i != p->last_reset_cause_size) {
10713 if (i % 16 == 0) {
10714 vty_out(vty, "\n ");
10715 } else if (i % 4 == 0) {
10716 vty_out(vty, " ");
10717 }
10718 }
10719 }
10720 vty_out(vty, "\n");
10721 }
10722 }
10723 }
10724
10725 if (CHECK_FLAG(p->sflags, PEER_STATUS_PREFIX_OVERFLOW)) {
10726 if (use_json)
10727 json_object_boolean_true_add(json_neigh,
10728 "prefixesConfigExceedMax");
10729 else
10730 vty_out(vty,
10731 " Peer had exceeded the max. no. of prefixes configured.\n");
10732
10733 if (p->t_pmax_restart) {
10734 if (use_json) {
10735 json_object_boolean_true_add(
10736 json_neigh, "reducePrefixNumFrom");
10737 json_object_int_add(json_neigh,
10738 "restartInTimerMsec",
10739 thread_timer_remain_second(
10740 p->t_pmax_restart)
10741 * 1000);
10742 } else
10743 vty_out(vty,
10744 " Reduce the no. of prefix from %s, will restart in %ld seconds\n",
10745 p->host, thread_timer_remain_second(
10746 p->t_pmax_restart));
10747 } else {
10748 if (use_json)
10749 json_object_boolean_true_add(
10750 json_neigh,
10751 "reducePrefixNumAndClearIpBgp");
10752 else
10753 vty_out(vty,
10754 " Reduce the no. of prefix and clear ip bgp %s to restore peering\n",
10755 p->host);
10756 }
10757 }
10758
10759 /* EBGP Multihop and GTSM */
10760 if (p->sort != BGP_PEER_IBGP) {
10761 if (use_json) {
10762 if (p->gtsm_hops > 0)
10763 json_object_int_add(json_neigh,
10764 "externalBgpNbrMaxHopsAway",
10765 p->gtsm_hops);
10766 else if (p->ttl > 1)
10767 json_object_int_add(json_neigh,
10768 "externalBgpNbrMaxHopsAway",
10769 p->ttl);
10770 } else {
10771 if (p->gtsm_hops > 0)
10772 vty_out(vty,
10773 " External BGP neighbor may be up to %d hops away.\n",
10774 p->gtsm_hops);
10775 else if (p->ttl > 1)
10776 vty_out(vty,
10777 " External BGP neighbor may be up to %d hops away.\n",
10778 p->ttl);
10779 }
10780 } else {
10781 if (p->gtsm_hops > 0) {
10782 if (use_json)
10783 json_object_int_add(json_neigh,
10784 "internalBgpNbrMaxHopsAway",
10785 p->gtsm_hops);
10786 else
10787 vty_out(vty,
10788 " Internal BGP neighbor may be up to %d hops away.\n",
10789 p->gtsm_hops);
10790 }
10791 }
10792
10793 /* Local address. */
10794 if (p->su_local) {
10795 if (use_json) {
10796 json_object_string_add(json_neigh, "hostLocal",
10797 sockunion2str(p->su_local, buf1,
10798 SU_ADDRSTRLEN));
10799 json_object_int_add(json_neigh, "portLocal",
10800 ntohs(p->su_local->sin.sin_port));
10801 } else
10802 vty_out(vty, "Local host: %s, Local port: %d\n",
10803 sockunion2str(p->su_local, buf1, SU_ADDRSTRLEN),
10804 ntohs(p->su_local->sin.sin_port));
10805 }
10806
10807 /* Remote address. */
10808 if (p->su_remote) {
10809 if (use_json) {
10810 json_object_string_add(json_neigh, "hostForeign",
10811 sockunion2str(p->su_remote, buf1,
10812 SU_ADDRSTRLEN));
10813 json_object_int_add(json_neigh, "portForeign",
10814 ntohs(p->su_remote->sin.sin_port));
10815 } else
10816 vty_out(vty, "Foreign host: %s, Foreign port: %d\n",
10817 sockunion2str(p->su_remote, buf1,
10818 SU_ADDRSTRLEN),
10819 ntohs(p->su_remote->sin.sin_port));
10820 }
10821
10822 /* Nexthop display. */
10823 if (p->su_local) {
10824 if (use_json) {
10825 json_object_string_add(json_neigh, "nexthop",
10826 inet_ntop(AF_INET,
10827 &p->nexthop.v4, buf1,
10828 sizeof(buf1)));
10829 json_object_string_add(json_neigh, "nexthopGlobal",
10830 inet_ntop(AF_INET6,
10831 &p->nexthop.v6_global,
10832 buf1, sizeof(buf1)));
10833 json_object_string_add(json_neigh, "nexthopLocal",
10834 inet_ntop(AF_INET6,
10835 &p->nexthop.v6_local,
10836 buf1, sizeof(buf1)));
10837 if (p->shared_network)
10838 json_object_string_add(json_neigh,
10839 "bgpConnection",
10840 "sharedNetwork");
10841 else
10842 json_object_string_add(json_neigh,
10843 "bgpConnection",
10844 "nonSharedNetwork");
10845 } else {
10846 vty_out(vty, "Nexthop: %s\n",
10847 inet_ntop(AF_INET, &p->nexthop.v4, buf1,
10848 sizeof(buf1)));
10849 vty_out(vty, "Nexthop global: %s\n",
10850 inet_ntop(AF_INET6, &p->nexthop.v6_global, buf1,
10851 sizeof(buf1)));
10852 vty_out(vty, "Nexthop local: %s\n",
10853 inet_ntop(AF_INET6, &p->nexthop.v6_local, buf1,
10854 sizeof(buf1)));
10855 vty_out(vty, "BGP connection: %s\n",
10856 p->shared_network ? "shared network"
10857 : "non shared network");
10858 }
10859 }
10860
10861 /* Timer information. */
10862 if (use_json) {
10863 json_object_int_add(json_neigh, "connectRetryTimer",
10864 p->v_connect);
10865 if (p->status == Established && p->rtt)
10866 json_object_int_add(json_neigh, "estimatedRttInMsecs",
10867 p->rtt);
10868 if (p->t_start)
10869 json_object_int_add(
10870 json_neigh, "nextStartTimerDueInMsecs",
10871 thread_timer_remain_second(p->t_start) * 1000);
10872 if (p->t_connect)
10873 json_object_int_add(
10874 json_neigh, "nextConnectTimerDueInMsecs",
10875 thread_timer_remain_second(p->t_connect)
10876 * 1000);
10877 if (p->t_routeadv) {
10878 json_object_int_add(json_neigh, "mraiInterval",
10879 p->v_routeadv);
10880 json_object_int_add(
10881 json_neigh, "mraiTimerExpireInMsecs",
10882 thread_timer_remain_second(p->t_routeadv)
10883 * 1000);
10884 }
10885 if (p->password)
10886 json_object_int_add(json_neigh, "authenticationEnabled",
10887 1);
10888
10889 if (p->t_read)
10890 json_object_string_add(json_neigh, "readThread", "on");
10891 else
10892 json_object_string_add(json_neigh, "readThread", "off");
10893
10894 if (CHECK_FLAG(p->thread_flags, PEER_THREAD_WRITES_ON))
10895 json_object_string_add(json_neigh, "writeThread", "on");
10896 else
10897 json_object_string_add(json_neigh, "writeThread",
10898 "off");
10899 } else {
10900 vty_out(vty, "BGP Connect Retry Timer in Seconds: %d\n",
10901 p->v_connect);
10902 if (p->status == Established && p->rtt)
10903 vty_out(vty, "Estimated round trip time: %d ms\n",
10904 p->rtt);
10905 if (p->t_start)
10906 vty_out(vty, "Next start timer due in %ld seconds\n",
10907 thread_timer_remain_second(p->t_start));
10908 if (p->t_connect)
10909 vty_out(vty, "Next connect timer due in %ld seconds\n",
10910 thread_timer_remain_second(p->t_connect));
10911 if (p->t_routeadv)
10912 vty_out(vty,
10913 "MRAI (interval %u) timer expires in %ld seconds\n",
10914 p->v_routeadv,
10915 thread_timer_remain_second(p->t_routeadv));
10916 if (p->password)
10917 vty_out(vty, "Peer Authentication Enabled\n");
10918
10919 vty_out(vty, "Read thread: %s Write thread: %s\n",
10920 p->t_read ? "on" : "off",
10921 CHECK_FLAG(p->thread_flags, PEER_THREAD_WRITES_ON)
10922 ? "on"
10923 : "off");
10924 }
10925
10926 if (p->notify.code == BGP_NOTIFY_OPEN_ERR
10927 && p->notify.subcode == BGP_NOTIFY_OPEN_UNSUP_CAPBL)
10928 bgp_capability_vty_out(vty, p, use_json, json_neigh);
10929
10930 if (!use_json)
10931 vty_out(vty, "\n");
10932
10933 /* BFD information. */
10934 bgp_bfd_show_info(vty, p, use_json, json_neigh);
10935
10936 if (use_json) {
10937 if (p->conf_if) /* Configured interface name. */
10938 json_object_object_add(json, p->conf_if, json_neigh);
10939 else /* Configured IP address. */
10940 json_object_object_add(json, p->host, json_neigh);
10941 }
10942 }
10943
10944 static int bgp_show_neighbor(struct vty *vty, struct bgp *bgp,
10945 enum show_type type, union sockunion *su,
10946 const char *conf_if, bool use_json,
10947 json_object *json)
10948 {
10949 struct listnode *node, *nnode;
10950 struct peer *peer;
10951 int find = 0;
10952 bool nbr_output = false;
10953 afi_t afi = AFI_MAX;
10954 safi_t safi = SAFI_MAX;
10955
10956 if (type == show_ipv4_peer || type == show_ipv4_all) {
10957 afi = AFI_IP;
10958 } else if (type == show_ipv6_peer || type == show_ipv6_all) {
10959 afi = AFI_IP6;
10960 }
10961
10962 for (ALL_LIST_ELEMENTS(bgp->peer, node, nnode, peer)) {
10963 if (!CHECK_FLAG(peer->flags, PEER_FLAG_CONFIG_NODE))
10964 continue;
10965
10966 switch (type) {
10967 case show_all:
10968 bgp_show_peer(vty, peer, use_json, json);
10969 nbr_output = true;
10970 break;
10971 case show_peer:
10972 if (conf_if) {
10973 if ((peer->conf_if
10974 && !strcmp(peer->conf_if, conf_if))
10975 || (peer->hostname
10976 && !strcmp(peer->hostname, conf_if))) {
10977 find = 1;
10978 bgp_show_peer(vty, peer, use_json,
10979 json);
10980 }
10981 } else {
10982 if (sockunion_same(&peer->su, su)) {
10983 find = 1;
10984 bgp_show_peer(vty, peer, use_json,
10985 json);
10986 }
10987 }
10988 break;
10989 case show_ipv4_peer:
10990 case show_ipv6_peer:
10991 FOREACH_SAFI (safi) {
10992 if (peer->afc[afi][safi]) {
10993 if (conf_if) {
10994 if ((peer->conf_if
10995 && !strcmp(peer->conf_if, conf_if))
10996 || (peer->hostname
10997 && !strcmp(peer->hostname, conf_if))) {
10998 find = 1;
10999 bgp_show_peer(vty, peer, use_json,
11000 json);
11001 break;
11002 }
11003 } else {
11004 if (sockunion_same(&peer->su, su)) {
11005 find = 1;
11006 bgp_show_peer(vty, peer, use_json,
11007 json);
11008 break;
11009 }
11010 }
11011 }
11012 }
11013 break;
11014 case show_ipv4_all:
11015 case show_ipv6_all:
11016 FOREACH_SAFI (safi) {
11017 if (peer->afc[afi][safi]) {
11018 bgp_show_peer(vty, peer, use_json, json);
11019 nbr_output = true;
11020 break;
11021 }
11022 }
11023 break;
11024 }
11025 }
11026
11027 if ((type == show_peer || type == show_ipv4_peer ||
11028 type == show_ipv6_peer) && !find) {
11029 if (use_json)
11030 json_object_boolean_true_add(json, "bgpNoSuchNeighbor");
11031 else
11032 vty_out(vty, "%% No such neighbor in this view/vrf\n");
11033 }
11034
11035 if (type != show_peer && type != show_ipv4_peer &&
11036 type != show_ipv6_peer && !nbr_output && !use_json)
11037 vty_out(vty, "%% No BGP neighbors found\n");
11038
11039 if (use_json) {
11040 vty_out(vty, "%s\n", json_object_to_json_string_ext(
11041 json, JSON_C_TO_STRING_PRETTY));
11042 } else {
11043 vty_out(vty, "\n");
11044 }
11045
11046 return CMD_SUCCESS;
11047 }
11048
11049 static void bgp_show_all_instances_neighbors_vty(struct vty *vty,
11050 enum show_type type,
11051 const char *ip_str,
11052 bool use_json)
11053 {
11054 struct listnode *node, *nnode;
11055 struct bgp *bgp;
11056 union sockunion su;
11057 json_object *json = NULL;
11058 int ret, is_first = 1;
11059 bool nbr_output = false;
11060
11061 if (use_json)
11062 vty_out(vty, "{\n");
11063
11064 for (ALL_LIST_ELEMENTS(bm->bgp, node, nnode, bgp)) {
11065 nbr_output = true;
11066 if (use_json) {
11067 if (!(json = json_object_new_object())) {
11068 flog_err(
11069 EC_BGP_JSON_MEM_ERROR,
11070 "Unable to allocate memory for JSON object");
11071 vty_out(vty,
11072 "{\"error\": {\"message:\": \"Unable to allocate memory for JSON object\"}}}\n");
11073 return;
11074 }
11075
11076 json_object_int_add(json, "vrfId",
11077 (bgp->vrf_id == VRF_UNKNOWN)
11078 ? -1
11079 : (int64_t)bgp->vrf_id);
11080 json_object_string_add(
11081 json, "vrfName",
11082 (bgp->inst_type == BGP_INSTANCE_TYPE_DEFAULT)
11083 ? VRF_DEFAULT_NAME
11084 : bgp->name);
11085
11086 if (!is_first)
11087 vty_out(vty, ",\n");
11088 else
11089 is_first = 0;
11090
11091 vty_out(vty, "\"%s\":",
11092 (bgp->inst_type == BGP_INSTANCE_TYPE_DEFAULT)
11093 ? VRF_DEFAULT_NAME
11094 : bgp->name);
11095 } else {
11096 vty_out(vty, "\nInstance %s:\n",
11097 (bgp->inst_type == BGP_INSTANCE_TYPE_DEFAULT)
11098 ? VRF_DEFAULT_NAME
11099 : bgp->name);
11100 }
11101
11102 if (type == show_peer || type == show_ipv4_peer ||
11103 type == show_ipv6_peer) {
11104 ret = str2sockunion(ip_str, &su);
11105 if (ret < 0)
11106 bgp_show_neighbor(vty, bgp, type, NULL, ip_str,
11107 use_json, json);
11108 else
11109 bgp_show_neighbor(vty, bgp, type, &su, NULL,
11110 use_json, json);
11111 } else {
11112 bgp_show_neighbor(vty, bgp, type, NULL, NULL,
11113 use_json, json);
11114 }
11115 json_object_free(json);
11116 }
11117
11118 if (use_json) {
11119 vty_out(vty, "}\n");
11120 json_object_free(json);
11121 }
11122 else if (!nbr_output)
11123 vty_out(vty, "%% BGP instance not found\n");
11124 }
11125
11126 static int bgp_show_neighbor_vty(struct vty *vty, const char *name,
11127 enum show_type type, const char *ip_str,
11128 bool use_json)
11129 {
11130 int ret;
11131 struct bgp *bgp;
11132 union sockunion su;
11133 json_object *json = NULL;
11134
11135 if (name) {
11136 if (strmatch(name, "all")) {
11137 bgp_show_all_instances_neighbors_vty(vty, type, ip_str,
11138 use_json);
11139 return CMD_SUCCESS;
11140 } else {
11141 bgp = bgp_lookup_by_name(name);
11142 if (!bgp) {
11143 if (use_json) {
11144 json = json_object_new_object();
11145 vty_out(vty, "%s\n",
11146 json_object_to_json_string_ext(
11147 json,
11148 JSON_C_TO_STRING_PRETTY));
11149 json_object_free(json);
11150 } else
11151 vty_out(vty,
11152 "%% BGP instance not found\n");
11153
11154 return CMD_WARNING;
11155 }
11156 }
11157 } else {
11158 bgp = bgp_get_default();
11159 }
11160
11161 if (bgp) {
11162 json = json_object_new_object();
11163 if (ip_str) {
11164 ret = str2sockunion(ip_str, &su);
11165 if (ret < 0)
11166 bgp_show_neighbor(vty, bgp, type, NULL, ip_str,
11167 use_json, json);
11168 else
11169 bgp_show_neighbor(vty, bgp, type, &su, NULL,
11170 use_json, json);
11171 } else {
11172 bgp_show_neighbor(vty, bgp, type, NULL, NULL, use_json,
11173 json);
11174 }
11175 json_object_free(json);
11176 } else {
11177 if (use_json)
11178 vty_out(vty, "{}\n");
11179 else
11180 vty_out(vty, "%% BGP instance not found\n");
11181 }
11182
11183 return CMD_SUCCESS;
11184 }
11185
11186 /* "show [ip] bgp neighbors" commands. */
11187 DEFUN (show_ip_bgp_neighbors,
11188 show_ip_bgp_neighbors_cmd,
11189 "show [ip] bgp [<view|vrf> VIEWVRFNAME] [<ipv4|ipv6>] neighbors [<A.B.C.D|X:X::X:X|WORD>] [json]",
11190 SHOW_STR
11191 IP_STR
11192 BGP_STR
11193 BGP_INSTANCE_HELP_STR
11194 "Address Family\n"
11195 "Address Family\n"
11196 "Detailed information on TCP and BGP neighbor connections\n"
11197 "Neighbor to display information about\n"
11198 "Neighbor to display information about\n"
11199 "Neighbor on BGP configured interface\n"
11200 JSON_STR)
11201 {
11202 char *vrf = NULL;
11203 char *sh_arg = NULL;
11204 enum show_type sh_type;
11205 afi_t afi = AFI_MAX;
11206
11207 bool uj = use_json(argc, argv);
11208
11209 int idx = 0;
11210
11211 /* [<vrf> VIEWVRFNAME] */
11212 if (argv_find(argv, argc, "vrf", &idx)) {
11213 vrf = argv[idx + 1]->arg;
11214 if (vrf && strmatch(vrf, VRF_DEFAULT_NAME))
11215 vrf = NULL;
11216 } else if (argv_find(argv, argc, "view", &idx))
11217 /* [<view> VIEWVRFNAME] */
11218 vrf = argv[idx + 1]->arg;
11219
11220 idx++;
11221
11222 if (argv_find(argv, argc, "ipv4", &idx)) {
11223 sh_type = show_ipv4_all;
11224 afi = AFI_IP;
11225 } else if (argv_find(argv, argc, "ipv6", &idx)) {
11226 sh_type = show_ipv6_all;
11227 afi = AFI_IP6;
11228 } else {
11229 sh_type = show_all;
11230 }
11231
11232 if (argv_find(argv, argc, "A.B.C.D", &idx)
11233 || argv_find(argv, argc, "X:X::X:X", &idx)
11234 || argv_find(argv, argc, "WORD", &idx)) {
11235 sh_type = show_peer;
11236 sh_arg = argv[idx]->arg;
11237 }
11238
11239 if (sh_type == show_peer && afi == AFI_IP) {
11240 sh_type = show_ipv4_peer;
11241 } else if (sh_type == show_peer && afi == AFI_IP6) {
11242 sh_type = show_ipv6_peer;
11243 }
11244
11245 return bgp_show_neighbor_vty(vty, vrf, sh_type, sh_arg, uj);
11246 }
11247
11248 /* Show BGP's AS paths internal data. There are both `show [ip] bgp
11249 paths' and `show ip mbgp paths'. Those functions results are the
11250 same.*/
11251 DEFUN (show_ip_bgp_paths,
11252 show_ip_bgp_paths_cmd,
11253 "show [ip] bgp ["BGP_SAFI_CMD_STR"] paths",
11254 SHOW_STR
11255 IP_STR
11256 BGP_STR
11257 BGP_SAFI_HELP_STR
11258 "Path information\n")
11259 {
11260 vty_out(vty, "Address Refcnt Path\n");
11261 aspath_print_all_vty(vty);
11262 return CMD_SUCCESS;
11263 }
11264
11265 #include "hash.h"
11266
11267 static void community_show_all_iterator(struct hash_bucket *bucket,
11268 struct vty *vty)
11269 {
11270 struct community *com;
11271
11272 com = (struct community *)bucket->data;
11273 vty_out(vty, "[%p] (%ld) %s\n", (void *)com, com->refcnt,
11274 community_str(com, false));
11275 }
11276
11277 /* Show BGP's community internal data. */
11278 DEFUN (show_ip_bgp_community_info,
11279 show_ip_bgp_community_info_cmd,
11280 "show [ip] bgp community-info",
11281 SHOW_STR
11282 IP_STR
11283 BGP_STR
11284 "List all bgp community information\n")
11285 {
11286 vty_out(vty, "Address Refcnt Community\n");
11287
11288 hash_iterate(community_hash(),
11289 (void (*)(struct hash_bucket *,
11290 void *))community_show_all_iterator,
11291 vty);
11292
11293 return CMD_SUCCESS;
11294 }
11295
11296 static void lcommunity_show_all_iterator(struct hash_bucket *bucket,
11297 struct vty *vty)
11298 {
11299 struct lcommunity *lcom;
11300
11301 lcom = (struct lcommunity *)bucket->data;
11302 vty_out(vty, "[%p] (%ld) %s\n", (void *)lcom, lcom->refcnt,
11303 lcommunity_str(lcom, false));
11304 }
11305
11306 /* Show BGP's community internal data. */
11307 DEFUN (show_ip_bgp_lcommunity_info,
11308 show_ip_bgp_lcommunity_info_cmd,
11309 "show ip bgp large-community-info",
11310 SHOW_STR
11311 IP_STR
11312 BGP_STR
11313 "List all bgp large-community information\n")
11314 {
11315 vty_out(vty, "Address Refcnt Large-community\n");
11316
11317 hash_iterate(lcommunity_hash(),
11318 (void (*)(struct hash_bucket *,
11319 void *))lcommunity_show_all_iterator,
11320 vty);
11321
11322 return CMD_SUCCESS;
11323 }
11324
11325
11326 DEFUN (show_ip_bgp_attr_info,
11327 show_ip_bgp_attr_info_cmd,
11328 "show [ip] bgp attribute-info",
11329 SHOW_STR
11330 IP_STR
11331 BGP_STR
11332 "List all bgp attribute information\n")
11333 {
11334 attr_show_all(vty);
11335 return CMD_SUCCESS;
11336 }
11337
11338 static int bgp_show_route_leak_vty(struct vty *vty, const char *name,
11339 afi_t afi, safi_t safi,
11340 bool use_json, json_object *json)
11341 {
11342 struct bgp *bgp;
11343 struct listnode *node;
11344 char *vname;
11345 char buf1[INET6_ADDRSTRLEN];
11346 char *ecom_str;
11347 vpn_policy_direction_t dir;
11348
11349 if (json) {
11350 json_object *json_import_vrfs = NULL;
11351 json_object *json_export_vrfs = NULL;
11352
11353 bgp = name ? bgp_lookup_by_name(name) : bgp_get_default();
11354
11355 if (!bgp) {
11356 vty_out(vty, "%s\n",
11357 json_object_to_json_string_ext(
11358 json,
11359 JSON_C_TO_STRING_PRETTY));
11360 json_object_free(json);
11361
11362 return CMD_WARNING;
11363 }
11364
11365 /* Provide context for the block */
11366 json_object_string_add(json, "vrf", name ? name : "default");
11367 json_object_string_add(json, "afiSafi",
11368 afi_safi_print(afi, safi));
11369
11370 if (!CHECK_FLAG(bgp->af_flags[afi][safi],
11371 BGP_CONFIG_VRF_TO_VRF_IMPORT)) {
11372 json_object_string_add(json, "importFromVrfs", "none");
11373 json_object_string_add(json, "importRts", "none");
11374 } else {
11375 json_import_vrfs = json_object_new_array();
11376
11377 for (ALL_LIST_ELEMENTS_RO(
11378 bgp->vpn_policy[afi].import_vrf,
11379 node, vname))
11380 json_object_array_add(json_import_vrfs,
11381 json_object_new_string(vname));
11382
11383 dir = BGP_VPN_POLICY_DIR_FROMVPN;
11384 ecom_str = ecommunity_ecom2str(
11385 bgp->vpn_policy[afi].rtlist[dir],
11386 ECOMMUNITY_FORMAT_ROUTE_MAP, 0);
11387 json_object_object_add(json, "importFromVrfs",
11388 json_import_vrfs);
11389 json_object_string_add(json, "importRts", ecom_str);
11390
11391 XFREE(MTYPE_ECOMMUNITY_STR, ecom_str);
11392 }
11393
11394 if (!CHECK_FLAG(bgp->af_flags[afi][safi],
11395 BGP_CONFIG_VRF_TO_VRF_EXPORT)) {
11396 json_object_string_add(json, "exportToVrfs", "none");
11397 json_object_string_add(json, "routeDistinguisher",
11398 "none");
11399 json_object_string_add(json, "exportRts", "none");
11400 } else {
11401 json_export_vrfs = json_object_new_array();
11402
11403 for (ALL_LIST_ELEMENTS_RO(
11404 bgp->vpn_policy[afi].export_vrf,
11405 node, vname))
11406 json_object_array_add(json_export_vrfs,
11407 json_object_new_string(vname));
11408 json_object_object_add(json, "exportToVrfs",
11409 json_export_vrfs);
11410 json_object_string_add(json, "routeDistinguisher",
11411 prefix_rd2str(&bgp->vpn_policy[afi].tovpn_rd,
11412 buf1, RD_ADDRSTRLEN));
11413
11414 dir = BGP_VPN_POLICY_DIR_TOVPN;
11415 ecom_str = ecommunity_ecom2str(
11416 bgp->vpn_policy[afi].rtlist[dir],
11417 ECOMMUNITY_FORMAT_ROUTE_MAP, 0);
11418 json_object_string_add(json, "exportRts", ecom_str);
11419
11420 XFREE(MTYPE_ECOMMUNITY_STR, ecom_str);
11421 }
11422
11423 if (use_json) {
11424 vty_out(vty, "%s\n",
11425 json_object_to_json_string_ext(json,
11426 JSON_C_TO_STRING_PRETTY));
11427 json_object_free(json);
11428 }
11429 } else {
11430 bgp = name ? bgp_lookup_by_name(name) : bgp_get_default();
11431
11432 if (!bgp) {
11433 vty_out(vty, "%% No such BGP instance exist\n");
11434 return CMD_WARNING;
11435 }
11436
11437 if (!CHECK_FLAG(bgp->af_flags[afi][safi],
11438 BGP_CONFIG_VRF_TO_VRF_IMPORT))
11439 vty_out(vty,
11440 "This VRF is not importing %s routes from any other VRF\n",
11441 afi_safi_print(afi, safi));
11442 else {
11443 vty_out(vty,
11444 "This VRF is importing %s routes from the following VRFs:\n",
11445 afi_safi_print(afi, safi));
11446
11447 for (ALL_LIST_ELEMENTS_RO(
11448 bgp->vpn_policy[afi].import_vrf,
11449 node, vname))
11450 vty_out(vty, " %s\n", vname);
11451
11452 dir = BGP_VPN_POLICY_DIR_FROMVPN;
11453 ecom_str = ecommunity_ecom2str(
11454 bgp->vpn_policy[afi].rtlist[dir],
11455 ECOMMUNITY_FORMAT_ROUTE_MAP, 0);
11456 vty_out(vty, "Import RT(s): %s\n", ecom_str);
11457
11458 XFREE(MTYPE_ECOMMUNITY_STR, ecom_str);
11459 }
11460
11461 if (!CHECK_FLAG(bgp->af_flags[afi][safi],
11462 BGP_CONFIG_VRF_TO_VRF_EXPORT))
11463 vty_out(vty,
11464 "This VRF is not exporting %s routes to any other VRF\n",
11465 afi_safi_print(afi, safi));
11466 else {
11467 vty_out(vty,
11468 "This VRF is exporting %s routes to the following VRFs:\n",
11469 afi_safi_print(afi, safi));
11470
11471 for (ALL_LIST_ELEMENTS_RO(
11472 bgp->vpn_policy[afi].export_vrf,
11473 node, vname))
11474 vty_out(vty, " %s\n", vname);
11475
11476 vty_out(vty, "RD: %s\n",
11477 prefix_rd2str(&bgp->vpn_policy[afi].tovpn_rd,
11478 buf1, RD_ADDRSTRLEN));
11479
11480 dir = BGP_VPN_POLICY_DIR_TOVPN;
11481 ecom_str = ecommunity_ecom2str(
11482 bgp->vpn_policy[afi].rtlist[dir],
11483 ECOMMUNITY_FORMAT_ROUTE_MAP, 0);
11484 vty_out(vty, "Export RT: %s\n", ecom_str);
11485 XFREE(MTYPE_ECOMMUNITY_STR, ecom_str);
11486 }
11487 }
11488
11489 return CMD_SUCCESS;
11490 }
11491
11492 static int bgp_show_all_instance_route_leak_vty(struct vty *vty, afi_t afi,
11493 safi_t safi, bool use_json)
11494 {
11495 struct listnode *node, *nnode;
11496 struct bgp *bgp;
11497 char *vrf_name = NULL;
11498 json_object *json = NULL;
11499 json_object *json_vrf = NULL;
11500 json_object *json_vrfs = NULL;
11501
11502 if (use_json) {
11503 json = json_object_new_object();
11504 json_vrfs = json_object_new_object();
11505 }
11506
11507 for (ALL_LIST_ELEMENTS(bm->bgp, node, nnode, bgp)) {
11508
11509 if (bgp->inst_type != BGP_INSTANCE_TYPE_DEFAULT)
11510 vrf_name = bgp->name;
11511
11512 if (use_json) {
11513 json_vrf = json_object_new_object();
11514 } else {
11515 vty_out(vty, "\nInstance %s:\n",
11516 (bgp->inst_type == BGP_INSTANCE_TYPE_DEFAULT)
11517 ? VRF_DEFAULT_NAME : bgp->name);
11518 }
11519 bgp_show_route_leak_vty(vty, vrf_name, afi, safi, 0, json_vrf);
11520 if (use_json) {
11521 if (bgp->inst_type == BGP_INSTANCE_TYPE_DEFAULT)
11522 json_object_object_add(json_vrfs,
11523 VRF_DEFAULT_NAME, json_vrf);
11524 else
11525 json_object_object_add(json_vrfs, vrf_name,
11526 json_vrf);
11527 }
11528 }
11529
11530 if (use_json) {
11531 json_object_object_add(json, "vrfs", json_vrfs);
11532 vty_out(vty, "%s\n", json_object_to_json_string_ext(json,
11533 JSON_C_TO_STRING_PRETTY));
11534 json_object_free(json);
11535 }
11536
11537 return CMD_SUCCESS;
11538 }
11539
11540 /* "show [ip] bgp route-leak" command. */
11541 DEFUN (show_ip_bgp_route_leak,
11542 show_ip_bgp_route_leak_cmd,
11543 "show [ip] bgp [<view|vrf> VIEWVRFNAME] ["BGP_AFI_CMD_STR" ["BGP_SAFI_CMD_STR"]] route-leak [json]",
11544 SHOW_STR
11545 IP_STR
11546 BGP_STR
11547 BGP_INSTANCE_HELP_STR
11548 BGP_AFI_HELP_STR
11549 BGP_SAFI_HELP_STR
11550 "Route leaking information\n"
11551 JSON_STR)
11552 {
11553 char *vrf = NULL;
11554 afi_t afi = AFI_MAX;
11555 safi_t safi = SAFI_MAX;
11556
11557 bool uj = use_json(argc, argv);
11558 int idx = 0;
11559 json_object *json = NULL;
11560
11561 /* show [ip] bgp */
11562 if (argv_find(argv, argc, "ip", &idx)) {
11563 afi = AFI_IP;
11564 safi = SAFI_UNICAST;
11565 }
11566 /* [vrf VIEWVRFNAME] */
11567 if (argv_find(argv, argc, "view", &idx)) {
11568 vty_out(vty,
11569 "%% This command is not applicable to BGP views\n");
11570 return CMD_WARNING;
11571 }
11572
11573 if (argv_find(argv, argc, "vrf", &idx)) {
11574 vrf = argv[idx + 1]->arg;
11575 if (vrf && strmatch(vrf, VRF_DEFAULT_NAME))
11576 vrf = NULL;
11577 }
11578 /* ["BGP_AFI_CMD_STR" ["BGP_SAFI_CMD_STR"]] */
11579 if (argv_find_and_parse_afi(argv, argc, &idx, &afi)) {
11580 argv_find_and_parse_safi(argv, argc, &idx, &safi);
11581 }
11582
11583 if (!((afi == AFI_IP || afi == AFI_IP6) && safi == SAFI_UNICAST)) {
11584 vty_out(vty,
11585 "%% This command is applicable only for unicast ipv4|ipv6\n");
11586 return CMD_WARNING;
11587 }
11588
11589 if (vrf && strmatch(vrf, "all"))
11590 return bgp_show_all_instance_route_leak_vty(vty, afi, safi, uj);
11591
11592 if (uj)
11593 json = json_object_new_object();
11594
11595 return bgp_show_route_leak_vty(vty, vrf, afi, safi, uj, json);
11596 }
11597
11598 static void bgp_show_all_instances_updgrps_vty(struct vty *vty, afi_t afi,
11599 safi_t safi)
11600 {
11601 struct listnode *node, *nnode;
11602 struct bgp *bgp;
11603
11604 for (ALL_LIST_ELEMENTS(bm->bgp, node, nnode, bgp)) {
11605 vty_out(vty, "\nInstance %s:\n",
11606 (bgp->inst_type == BGP_INSTANCE_TYPE_DEFAULT)
11607 ? VRF_DEFAULT_NAME
11608 : bgp->name);
11609 update_group_show(bgp, afi, safi, vty, 0);
11610 }
11611 }
11612
11613 static int bgp_show_update_groups(struct vty *vty, const char *name, int afi,
11614 int safi, uint64_t subgrp_id)
11615 {
11616 struct bgp *bgp;
11617
11618 if (name) {
11619 if (strmatch(name, "all")) {
11620 bgp_show_all_instances_updgrps_vty(vty, afi, safi);
11621 return CMD_SUCCESS;
11622 } else {
11623 bgp = bgp_lookup_by_name(name);
11624 }
11625 } else {
11626 bgp = bgp_get_default();
11627 }
11628
11629 if (bgp)
11630 update_group_show(bgp, afi, safi, vty, subgrp_id);
11631 return CMD_SUCCESS;
11632 }
11633
11634 DEFUN (show_ip_bgp_updgrps,
11635 show_ip_bgp_updgrps_cmd,
11636 "show [ip] bgp [<view|vrf> VIEWVRFNAME] ["BGP_AFI_CMD_STR" ["BGP_SAFI_WITH_LABEL_CMD_STR"]] update-groups [SUBGROUP-ID]",
11637 SHOW_STR
11638 IP_STR
11639 BGP_STR
11640 BGP_INSTANCE_HELP_STR
11641 BGP_AFI_HELP_STR
11642 BGP_SAFI_WITH_LABEL_HELP_STR
11643 "Detailed info about dynamic update groups\n"
11644 "Specific subgroup to display detailed info for\n")
11645 {
11646 char *vrf = NULL;
11647 afi_t afi = AFI_IP6;
11648 safi_t safi = SAFI_UNICAST;
11649 uint64_t subgrp_id = 0;
11650
11651 int idx = 0;
11652
11653 /* show [ip] bgp */
11654 if (argv_find(argv, argc, "ip", &idx))
11655 afi = AFI_IP;
11656 /* [<vrf> VIEWVRFNAME] */
11657 if (argv_find(argv, argc, "vrf", &idx)) {
11658 vrf = argv[idx + 1]->arg;
11659 if (vrf && strmatch(vrf, VRF_DEFAULT_NAME))
11660 vrf = NULL;
11661 } else if (argv_find(argv, argc, "view", &idx))
11662 /* [<view> VIEWVRFNAME] */
11663 vrf = argv[idx + 1]->arg;
11664 /* ["BGP_AFI_CMD_STR" ["BGP_SAFI_CMD_STR"]] */
11665 if (argv_find_and_parse_afi(argv, argc, &idx, &afi)) {
11666 argv_find_and_parse_safi(argv, argc, &idx, &safi);
11667 }
11668
11669 /* get subgroup id, if provided */
11670 idx = argc - 1;
11671 if (argv[idx]->type == VARIABLE_TKN)
11672 subgrp_id = strtoull(argv[idx]->arg, NULL, 10);
11673
11674 return (bgp_show_update_groups(vty, vrf, afi, safi, subgrp_id));
11675 }
11676
11677 DEFUN (show_bgp_instance_all_ipv6_updgrps,
11678 show_bgp_instance_all_ipv6_updgrps_cmd,
11679 "show [ip] bgp <view|vrf> all update-groups",
11680 SHOW_STR
11681 IP_STR
11682 BGP_STR
11683 BGP_INSTANCE_ALL_HELP_STR
11684 "Detailed info about dynamic update groups\n")
11685 {
11686 bgp_show_all_instances_updgrps_vty(vty, AFI_IP6, SAFI_UNICAST);
11687 return CMD_SUCCESS;
11688 }
11689
11690 DEFUN (show_bgp_l2vpn_evpn_updgrps,
11691 show_bgp_l2vpn_evpn_updgrps_cmd,
11692 "show [ip] bgp l2vpn evpn update-groups",
11693 SHOW_STR
11694 IP_STR
11695 BGP_STR
11696 "l2vpn address family\n"
11697 "evpn sub-address family\n"
11698 "Detailed info about dynamic update groups\n")
11699 {
11700 char *vrf = NULL;
11701 uint64_t subgrp_id = 0;
11702
11703 bgp_show_update_groups(vty, vrf, AFI_L2VPN, SAFI_EVPN, subgrp_id);
11704 return CMD_SUCCESS;
11705 }
11706
11707 DEFUN (show_bgp_updgrps_stats,
11708 show_bgp_updgrps_stats_cmd,
11709 "show [ip] bgp update-groups statistics",
11710 SHOW_STR
11711 IP_STR
11712 BGP_STR
11713 "Detailed info about dynamic update groups\n"
11714 "Statistics\n")
11715 {
11716 struct bgp *bgp;
11717
11718 bgp = bgp_get_default();
11719 if (bgp)
11720 update_group_show_stats(bgp, vty);
11721
11722 return CMD_SUCCESS;
11723 }
11724
11725 DEFUN (show_bgp_instance_updgrps_stats,
11726 show_bgp_instance_updgrps_stats_cmd,
11727 "show [ip] bgp <view|vrf> VIEWVRFNAME update-groups statistics",
11728 SHOW_STR
11729 IP_STR
11730 BGP_STR
11731 BGP_INSTANCE_HELP_STR
11732 "Detailed info about dynamic update groups\n"
11733 "Statistics\n")
11734 {
11735 int idx_word = 3;
11736 struct bgp *bgp;
11737
11738 bgp = bgp_lookup_by_name(argv[idx_word]->arg);
11739 if (bgp)
11740 update_group_show_stats(bgp, vty);
11741
11742 return CMD_SUCCESS;
11743 }
11744
11745 static void show_bgp_updgrps_adj_info_aux(struct vty *vty, const char *name,
11746 afi_t afi, safi_t safi,
11747 const char *what, uint64_t subgrp_id)
11748 {
11749 struct bgp *bgp;
11750
11751 if (name)
11752 bgp = bgp_lookup_by_name(name);
11753 else
11754 bgp = bgp_get_default();
11755
11756 if (bgp) {
11757 if (!strcmp(what, "advertise-queue"))
11758 update_group_show_adj_queue(bgp, afi, safi, vty,
11759 subgrp_id);
11760 else if (!strcmp(what, "advertised-routes"))
11761 update_group_show_advertised(bgp, afi, safi, vty,
11762 subgrp_id);
11763 else if (!strcmp(what, "packet-queue"))
11764 update_group_show_packet_queue(bgp, afi, safi, vty,
11765 subgrp_id);
11766 }
11767 }
11768
11769 DEFPY(show_ip_bgp_instance_updgrps_adj_s,
11770 show_ip_bgp_instance_updgrps_adj_s_cmd,
11771 "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",
11772 SHOW_STR IP_STR BGP_STR BGP_INSTANCE_HELP_STR BGP_AFI_HELP_STR
11773 BGP_SAFI_HELP_STR
11774 "Detailed info about dynamic update groups\n"
11775 "Specific subgroup to display info for\n"
11776 "Advertisement queue\n"
11777 "Announced routes\n"
11778 "Packet queue\n")
11779 {
11780 uint64_t subgrp_id = 0;
11781 afi_t afiz;
11782 safi_t safiz;
11783 if (sgid)
11784 subgrp_id = strtoull(sgid, NULL, 10);
11785
11786 if (!ip && !afi)
11787 afiz = AFI_IP6;
11788 if (!ip && afi)
11789 afiz = bgp_vty_afi_from_str(afi);
11790 if (ip && !afi)
11791 afiz = AFI_IP;
11792 if (ip && afi) {
11793 afiz = bgp_vty_afi_from_str(afi);
11794 if (afiz != AFI_IP)
11795 vty_out(vty,
11796 "%% Cannot specify both 'ip' and 'ipv6'\n");
11797 return CMD_WARNING;
11798 }
11799
11800 safiz = safi ? bgp_vty_safi_from_str(safi) : SAFI_UNICAST;
11801
11802 show_bgp_updgrps_adj_info_aux(vty, vrf, afiz, safiz, rtq, subgrp_id);
11803 return CMD_SUCCESS;
11804 }
11805
11806 static int bgp_show_one_peer_group(struct vty *vty, struct peer_group *group)
11807 {
11808 struct listnode *node, *nnode;
11809 struct prefix *range;
11810 struct peer *conf;
11811 struct peer *peer;
11812 char buf[PREFIX2STR_BUFFER];
11813 afi_t afi;
11814 safi_t safi;
11815 const char *peer_status;
11816 const char *af_str;
11817 int lr_count;
11818 int dynamic;
11819 int af_cfgd;
11820
11821 conf = group->conf;
11822
11823 if (conf->as_type == AS_SPECIFIED || conf->as_type == AS_EXTERNAL) {
11824 vty_out(vty, "\nBGP peer-group %s, remote AS %" PRIu32 "\n",
11825 group->name, conf->as);
11826 } else if (conf->as_type == AS_INTERNAL) {
11827 vty_out(vty, "\nBGP peer-group %s, remote AS %" PRIu32 "\n",
11828 group->name, group->bgp->as);
11829 } else {
11830 vty_out(vty, "\nBGP peer-group %s\n", group->name);
11831 }
11832
11833 if ((group->bgp->as == conf->as) || (conf->as_type == AS_INTERNAL))
11834 vty_out(vty, " Peer-group type is internal\n");
11835 else
11836 vty_out(vty, " Peer-group type is external\n");
11837
11838 /* Display AFs configured. */
11839 vty_out(vty, " Configured address-families:");
11840 FOREACH_AFI_SAFI (afi, safi) {
11841 if (conf->afc[afi][safi]) {
11842 af_cfgd = 1;
11843 vty_out(vty, " %s;", afi_safi_print(afi, safi));
11844 }
11845 }
11846 if (!af_cfgd)
11847 vty_out(vty, " none\n");
11848 else
11849 vty_out(vty, "\n");
11850
11851 /* Display listen ranges (for dynamic neighbors), if any */
11852 for (afi = AFI_IP; afi < AFI_MAX; afi++) {
11853 if (afi == AFI_IP)
11854 af_str = "IPv4";
11855 else if (afi == AFI_IP6)
11856 af_str = "IPv6";
11857 else
11858 af_str = "???";
11859 lr_count = listcount(group->listen_range[afi]);
11860 if (lr_count) {
11861 vty_out(vty, " %d %s listen range(s)\n", lr_count,
11862 af_str);
11863
11864
11865 for (ALL_LIST_ELEMENTS(group->listen_range[afi], node,
11866 nnode, range)) {
11867 prefix2str(range, buf, sizeof(buf));
11868 vty_out(vty, " %s\n", buf);
11869 }
11870 }
11871 }
11872
11873 /* Display group members and their status */
11874 if (listcount(group->peer)) {
11875 vty_out(vty, " Peer-group members:\n");
11876 for (ALL_LIST_ELEMENTS(group->peer, node, nnode, peer)) {
11877 if (CHECK_FLAG(peer->flags, PEER_FLAG_SHUTDOWN))
11878 peer_status = "Idle (Admin)";
11879 else if (CHECK_FLAG(peer->sflags,
11880 PEER_STATUS_PREFIX_OVERFLOW))
11881 peer_status = "Idle (PfxCt)";
11882 else
11883 peer_status = lookup_msg(bgp_status_msg,
11884 peer->status, NULL);
11885
11886 dynamic = peer_dynamic_neighbor(peer);
11887 vty_out(vty, " %s %s %s \n", peer->host,
11888 dynamic ? "(dynamic)" : "", peer_status);
11889 }
11890 }
11891
11892 return CMD_SUCCESS;
11893 }
11894
11895 static int bgp_show_peer_group_vty(struct vty *vty, const char *name,
11896 const char *group_name)
11897 {
11898 struct bgp *bgp;
11899 struct listnode *node, *nnode;
11900 struct peer_group *group;
11901 bool found = false;
11902
11903 bgp = name ? bgp_lookup_by_name(name) : bgp_get_default();
11904
11905 if (!bgp) {
11906 vty_out(vty, "%% BGP instance not found\n");
11907 return CMD_WARNING;
11908 }
11909
11910 for (ALL_LIST_ELEMENTS(bgp->group, node, nnode, group)) {
11911 if (group_name) {
11912 if (strmatch(group->name, group_name)) {
11913 bgp_show_one_peer_group(vty, group);
11914 found = true;
11915 break;
11916 }
11917 } else {
11918 bgp_show_one_peer_group(vty, group);
11919 }
11920 }
11921
11922 if (group_name && !found)
11923 vty_out(vty, "%% No such peer-group\n");
11924
11925 return CMD_SUCCESS;
11926 }
11927
11928 DEFUN (show_ip_bgp_peer_groups,
11929 show_ip_bgp_peer_groups_cmd,
11930 "show [ip] bgp [<view|vrf> VIEWVRFNAME] peer-group [PGNAME]",
11931 SHOW_STR
11932 IP_STR
11933 BGP_STR
11934 BGP_INSTANCE_HELP_STR
11935 "Detailed information on BGP peer groups\n"
11936 "Peer group name\n")
11937 {
11938 char *vrf, *pg;
11939 int idx = 0;
11940
11941 vrf = argv_find(argv, argc, "VIEWVRFNAME", &idx) ? argv[idx]->arg
11942 : NULL;
11943 pg = argv_find(argv, argc, "PGNAME", &idx) ? argv[idx]->arg : NULL;
11944
11945 return bgp_show_peer_group_vty(vty, vrf, pg);
11946 }
11947
11948
11949 /* Redistribute VTY commands. */
11950
11951 DEFUN (bgp_redistribute_ipv4,
11952 bgp_redistribute_ipv4_cmd,
11953 "redistribute " FRR_IP_REDIST_STR_BGPD,
11954 "Redistribute information from another routing protocol\n"
11955 FRR_IP_REDIST_HELP_STR_BGPD)
11956 {
11957 VTY_DECLVAR_CONTEXT(bgp, bgp);
11958 int idx_protocol = 1;
11959 int type;
11960
11961 type = proto_redistnum(AFI_IP, argv[idx_protocol]->text);
11962 if (type < 0) {
11963 vty_out(vty, "%% Invalid route type\n");
11964 return CMD_WARNING_CONFIG_FAILED;
11965 }
11966
11967 bgp_redist_add(bgp, AFI_IP, type, 0);
11968 return bgp_redistribute_set(bgp, AFI_IP, type, 0, false);
11969 }
11970
11971 ALIAS_HIDDEN(
11972 bgp_redistribute_ipv4, bgp_redistribute_ipv4_hidden_cmd,
11973 "redistribute " FRR_IP_REDIST_STR_BGPD,
11974 "Redistribute information from another routing protocol\n" FRR_IP_REDIST_HELP_STR_BGPD)
11975
11976 DEFUN (bgp_redistribute_ipv4_rmap,
11977 bgp_redistribute_ipv4_rmap_cmd,
11978 "redistribute " FRR_IP_REDIST_STR_BGPD " route-map WORD",
11979 "Redistribute information from another routing protocol\n"
11980 FRR_IP_REDIST_HELP_STR_BGPD
11981 "Route map reference\n"
11982 "Pointer to route-map entries\n")
11983 {
11984 VTY_DECLVAR_CONTEXT(bgp, bgp);
11985 int idx_protocol = 1;
11986 int idx_word = 3;
11987 int type;
11988 struct bgp_redist *red;
11989 bool changed;
11990 struct route_map *route_map = route_map_lookup_warn_noexist(
11991 vty, argv[idx_word]->arg);
11992
11993 type = proto_redistnum(AFI_IP, argv[idx_protocol]->text);
11994 if (type < 0) {
11995 vty_out(vty, "%% Invalid route type\n");
11996 return CMD_WARNING_CONFIG_FAILED;
11997 }
11998
11999 red = bgp_redist_add(bgp, AFI_IP, type, 0);
12000 changed =
12001 bgp_redistribute_rmap_set(red, argv[idx_word]->arg, route_map);
12002 return bgp_redistribute_set(bgp, AFI_IP, type, 0, changed);
12003 }
12004
12005 ALIAS_HIDDEN(
12006 bgp_redistribute_ipv4_rmap, bgp_redistribute_ipv4_rmap_hidden_cmd,
12007 "redistribute " FRR_IP_REDIST_STR_BGPD " route-map WORD",
12008 "Redistribute information from another routing protocol\n" FRR_IP_REDIST_HELP_STR_BGPD
12009 "Route map reference\n"
12010 "Pointer to route-map entries\n")
12011
12012 DEFUN (bgp_redistribute_ipv4_metric,
12013 bgp_redistribute_ipv4_metric_cmd,
12014 "redistribute " FRR_IP_REDIST_STR_BGPD " metric (0-4294967295)",
12015 "Redistribute information from another routing protocol\n"
12016 FRR_IP_REDIST_HELP_STR_BGPD
12017 "Metric for redistributed routes\n"
12018 "Default metric\n")
12019 {
12020 VTY_DECLVAR_CONTEXT(bgp, bgp);
12021 int idx_protocol = 1;
12022 int idx_number = 3;
12023 int type;
12024 uint32_t metric;
12025 struct bgp_redist *red;
12026 bool changed;
12027
12028 type = proto_redistnum(AFI_IP, argv[idx_protocol]->text);
12029 if (type < 0) {
12030 vty_out(vty, "%% Invalid route type\n");
12031 return CMD_WARNING_CONFIG_FAILED;
12032 }
12033 metric = strtoul(argv[idx_number]->arg, NULL, 10);
12034
12035 red = bgp_redist_add(bgp, AFI_IP, type, 0);
12036 changed = bgp_redistribute_metric_set(bgp, red, AFI_IP, type, metric);
12037 return bgp_redistribute_set(bgp, AFI_IP, type, 0, changed);
12038 }
12039
12040 ALIAS_HIDDEN(
12041 bgp_redistribute_ipv4_metric, bgp_redistribute_ipv4_metric_hidden_cmd,
12042 "redistribute " FRR_IP_REDIST_STR_BGPD " metric (0-4294967295)",
12043 "Redistribute information from another routing protocol\n" FRR_IP_REDIST_HELP_STR_BGPD
12044 "Metric for redistributed routes\n"
12045 "Default metric\n")
12046
12047 DEFUN (bgp_redistribute_ipv4_rmap_metric,
12048 bgp_redistribute_ipv4_rmap_metric_cmd,
12049 "redistribute " FRR_IP_REDIST_STR_BGPD " route-map WORD metric (0-4294967295)",
12050 "Redistribute information from another routing protocol\n"
12051 FRR_IP_REDIST_HELP_STR_BGPD
12052 "Route map reference\n"
12053 "Pointer to route-map entries\n"
12054 "Metric for redistributed routes\n"
12055 "Default metric\n")
12056 {
12057 VTY_DECLVAR_CONTEXT(bgp, bgp);
12058 int idx_protocol = 1;
12059 int idx_word = 3;
12060 int idx_number = 5;
12061 int type;
12062 uint32_t metric;
12063 struct bgp_redist *red;
12064 bool changed;
12065 struct route_map *route_map =
12066 route_map_lookup_warn_noexist(vty, argv[idx_word]->arg);
12067
12068 type = proto_redistnum(AFI_IP, argv[idx_protocol]->text);
12069 if (type < 0) {
12070 vty_out(vty, "%% Invalid route type\n");
12071 return CMD_WARNING_CONFIG_FAILED;
12072 }
12073 metric = strtoul(argv[idx_number]->arg, NULL, 10);
12074
12075 red = bgp_redist_add(bgp, AFI_IP, type, 0);
12076 changed =
12077 bgp_redistribute_rmap_set(red, argv[idx_word]->arg, route_map);
12078 changed |= bgp_redistribute_metric_set(bgp, red, AFI_IP, type, metric);
12079 return bgp_redistribute_set(bgp, AFI_IP, type, 0, changed);
12080 }
12081
12082 ALIAS_HIDDEN(
12083 bgp_redistribute_ipv4_rmap_metric,
12084 bgp_redistribute_ipv4_rmap_metric_hidden_cmd,
12085 "redistribute " FRR_IP_REDIST_STR_BGPD
12086 " route-map WORD metric (0-4294967295)",
12087 "Redistribute information from another routing protocol\n" FRR_IP_REDIST_HELP_STR_BGPD
12088 "Route map reference\n"
12089 "Pointer to route-map entries\n"
12090 "Metric for redistributed routes\n"
12091 "Default metric\n")
12092
12093 DEFUN (bgp_redistribute_ipv4_metric_rmap,
12094 bgp_redistribute_ipv4_metric_rmap_cmd,
12095 "redistribute " FRR_IP_REDIST_STR_BGPD " metric (0-4294967295) route-map WORD",
12096 "Redistribute information from another routing protocol\n"
12097 FRR_IP_REDIST_HELP_STR_BGPD
12098 "Metric for redistributed routes\n"
12099 "Default metric\n"
12100 "Route map reference\n"
12101 "Pointer to route-map entries\n")
12102 {
12103 VTY_DECLVAR_CONTEXT(bgp, bgp);
12104 int idx_protocol = 1;
12105 int idx_number = 3;
12106 int idx_word = 5;
12107 int type;
12108 uint32_t metric;
12109 struct bgp_redist *red;
12110 bool changed;
12111 struct route_map *route_map =
12112 route_map_lookup_warn_noexist(vty, argv[idx_word]->arg);
12113
12114 type = proto_redistnum(AFI_IP, argv[idx_protocol]->text);
12115 if (type < 0) {
12116 vty_out(vty, "%% Invalid route type\n");
12117 return CMD_WARNING_CONFIG_FAILED;
12118 }
12119 metric = strtoul(argv[idx_number]->arg, NULL, 10);
12120
12121 red = bgp_redist_add(bgp, AFI_IP, type, 0);
12122 changed = bgp_redistribute_metric_set(bgp, red, AFI_IP, type, metric);
12123 changed |=
12124 bgp_redistribute_rmap_set(red, argv[idx_word]->arg, route_map);
12125 return bgp_redistribute_set(bgp, AFI_IP, type, 0, changed);
12126 }
12127
12128 ALIAS_HIDDEN(
12129 bgp_redistribute_ipv4_metric_rmap,
12130 bgp_redistribute_ipv4_metric_rmap_hidden_cmd,
12131 "redistribute " FRR_IP_REDIST_STR_BGPD
12132 " metric (0-4294967295) route-map WORD",
12133 "Redistribute information from another routing protocol\n" FRR_IP_REDIST_HELP_STR_BGPD
12134 "Metric for redistributed routes\n"
12135 "Default metric\n"
12136 "Route map reference\n"
12137 "Pointer to route-map entries\n")
12138
12139 DEFUN (bgp_redistribute_ipv4_ospf,
12140 bgp_redistribute_ipv4_ospf_cmd,
12141 "redistribute <ospf|table> (1-65535)",
12142 "Redistribute information from another routing protocol\n"
12143 "Open Shortest Path First (OSPFv2)\n"
12144 "Non-main Kernel Routing Table\n"
12145 "Instance ID/Table ID\n")
12146 {
12147 VTY_DECLVAR_CONTEXT(bgp, bgp);
12148 int idx_ospf_table = 1;
12149 int idx_number = 2;
12150 unsigned short instance;
12151 unsigned short protocol;
12152
12153 instance = strtoul(argv[idx_number]->arg, NULL, 10);
12154
12155 if (strncmp(argv[idx_ospf_table]->arg, "o", 1) == 0)
12156 protocol = ZEBRA_ROUTE_OSPF;
12157 else
12158 protocol = ZEBRA_ROUTE_TABLE;
12159
12160 bgp_redist_add(bgp, AFI_IP, protocol, instance);
12161 return bgp_redistribute_set(bgp, AFI_IP, protocol, instance, false);
12162 }
12163
12164 ALIAS_HIDDEN(bgp_redistribute_ipv4_ospf, bgp_redistribute_ipv4_ospf_hidden_cmd,
12165 "redistribute <ospf|table> (1-65535)",
12166 "Redistribute information from another routing protocol\n"
12167 "Open Shortest Path First (OSPFv2)\n"
12168 "Non-main Kernel Routing Table\n"
12169 "Instance ID/Table ID\n")
12170
12171 DEFUN (bgp_redistribute_ipv4_ospf_rmap,
12172 bgp_redistribute_ipv4_ospf_rmap_cmd,
12173 "redistribute <ospf|table> (1-65535) route-map WORD",
12174 "Redistribute information from another routing protocol\n"
12175 "Open Shortest Path First (OSPFv2)\n"
12176 "Non-main Kernel Routing Table\n"
12177 "Instance ID/Table ID\n"
12178 "Route map reference\n"
12179 "Pointer to route-map entries\n")
12180 {
12181 VTY_DECLVAR_CONTEXT(bgp, bgp);
12182 int idx_ospf_table = 1;
12183 int idx_number = 2;
12184 int idx_word = 4;
12185 struct bgp_redist *red;
12186 unsigned short instance;
12187 int protocol;
12188 bool changed;
12189 struct route_map *route_map =
12190 route_map_lookup_warn_noexist(vty, argv[idx_word]->arg);
12191
12192 if (strncmp(argv[idx_ospf_table]->arg, "o", 1) == 0)
12193 protocol = ZEBRA_ROUTE_OSPF;
12194 else
12195 protocol = ZEBRA_ROUTE_TABLE;
12196
12197 instance = strtoul(argv[idx_number]->arg, NULL, 10);
12198 red = bgp_redist_add(bgp, AFI_IP, protocol, instance);
12199 changed =
12200 bgp_redistribute_rmap_set(red, argv[idx_word]->arg, route_map);
12201 return bgp_redistribute_set(bgp, AFI_IP, protocol, instance, changed);
12202 }
12203
12204 ALIAS_HIDDEN(bgp_redistribute_ipv4_ospf_rmap,
12205 bgp_redistribute_ipv4_ospf_rmap_hidden_cmd,
12206 "redistribute <ospf|table> (1-65535) route-map WORD",
12207 "Redistribute information from another routing protocol\n"
12208 "Open Shortest Path First (OSPFv2)\n"
12209 "Non-main Kernel Routing Table\n"
12210 "Instance ID/Table ID\n"
12211 "Route map reference\n"
12212 "Pointer to route-map entries\n")
12213
12214 DEFUN (bgp_redistribute_ipv4_ospf_metric,
12215 bgp_redistribute_ipv4_ospf_metric_cmd,
12216 "redistribute <ospf|table> (1-65535) metric (0-4294967295)",
12217 "Redistribute information from another routing protocol\n"
12218 "Open Shortest Path First (OSPFv2)\n"
12219 "Non-main Kernel Routing Table\n"
12220 "Instance ID/Table ID\n"
12221 "Metric for redistributed routes\n"
12222 "Default metric\n")
12223 {
12224 VTY_DECLVAR_CONTEXT(bgp, bgp);
12225 int idx_ospf_table = 1;
12226 int idx_number = 2;
12227 int idx_number_2 = 4;
12228 uint32_t metric;
12229 struct bgp_redist *red;
12230 unsigned short instance;
12231 int protocol;
12232 bool changed;
12233
12234 if (strncmp(argv[idx_ospf_table]->arg, "o", 1) == 0)
12235 protocol = ZEBRA_ROUTE_OSPF;
12236 else
12237 protocol = ZEBRA_ROUTE_TABLE;
12238
12239 instance = strtoul(argv[idx_number]->arg, NULL, 10);
12240 metric = strtoul(argv[idx_number_2]->arg, NULL, 10);
12241
12242 red = bgp_redist_add(bgp, AFI_IP, protocol, instance);
12243 changed = bgp_redistribute_metric_set(bgp, red, AFI_IP, protocol,
12244 metric);
12245 return bgp_redistribute_set(bgp, AFI_IP, protocol, instance, changed);
12246 }
12247
12248 ALIAS_HIDDEN(bgp_redistribute_ipv4_ospf_metric,
12249 bgp_redistribute_ipv4_ospf_metric_hidden_cmd,
12250 "redistribute <ospf|table> (1-65535) metric (0-4294967295)",
12251 "Redistribute information from another routing protocol\n"
12252 "Open Shortest Path First (OSPFv2)\n"
12253 "Non-main Kernel Routing Table\n"
12254 "Instance ID/Table ID\n"
12255 "Metric for redistributed routes\n"
12256 "Default metric\n")
12257
12258 DEFUN (bgp_redistribute_ipv4_ospf_rmap_metric,
12259 bgp_redistribute_ipv4_ospf_rmap_metric_cmd,
12260 "redistribute <ospf|table> (1-65535) route-map WORD metric (0-4294967295)",
12261 "Redistribute information from another routing protocol\n"
12262 "Open Shortest Path First (OSPFv2)\n"
12263 "Non-main Kernel Routing Table\n"
12264 "Instance ID/Table ID\n"
12265 "Route map reference\n"
12266 "Pointer to route-map entries\n"
12267 "Metric for redistributed routes\n"
12268 "Default metric\n")
12269 {
12270 VTY_DECLVAR_CONTEXT(bgp, bgp);
12271 int idx_ospf_table = 1;
12272 int idx_number = 2;
12273 int idx_word = 4;
12274 int idx_number_2 = 6;
12275 uint32_t metric;
12276 struct bgp_redist *red;
12277 unsigned short instance;
12278 int protocol;
12279 bool changed;
12280 struct route_map *route_map =
12281 route_map_lookup_warn_noexist(vty, argv[idx_word]->arg);
12282
12283 if (strncmp(argv[idx_ospf_table]->arg, "o", 1) == 0)
12284 protocol = ZEBRA_ROUTE_OSPF;
12285 else
12286 protocol = ZEBRA_ROUTE_TABLE;
12287
12288 instance = strtoul(argv[idx_number]->arg, NULL, 10);
12289 metric = strtoul(argv[idx_number_2]->arg, NULL, 10);
12290
12291 red = bgp_redist_add(bgp, AFI_IP, protocol, instance);
12292 changed =
12293 bgp_redistribute_rmap_set(red, argv[idx_word]->arg, route_map);
12294 changed |= bgp_redistribute_metric_set(bgp, red, AFI_IP, protocol,
12295 metric);
12296 return bgp_redistribute_set(bgp, AFI_IP, protocol, instance, changed);
12297 }
12298
12299 ALIAS_HIDDEN(
12300 bgp_redistribute_ipv4_ospf_rmap_metric,
12301 bgp_redistribute_ipv4_ospf_rmap_metric_hidden_cmd,
12302 "redistribute <ospf|table> (1-65535) route-map WORD metric (0-4294967295)",
12303 "Redistribute information from another routing protocol\n"
12304 "Open Shortest Path First (OSPFv2)\n"
12305 "Non-main Kernel Routing Table\n"
12306 "Instance ID/Table ID\n"
12307 "Route map reference\n"
12308 "Pointer to route-map entries\n"
12309 "Metric for redistributed routes\n"
12310 "Default metric\n")
12311
12312 DEFUN (bgp_redistribute_ipv4_ospf_metric_rmap,
12313 bgp_redistribute_ipv4_ospf_metric_rmap_cmd,
12314 "redistribute <ospf|table> (1-65535) metric (0-4294967295) route-map WORD",
12315 "Redistribute information from another routing protocol\n"
12316 "Open Shortest Path First (OSPFv2)\n"
12317 "Non-main Kernel Routing Table\n"
12318 "Instance ID/Table ID\n"
12319 "Metric for redistributed routes\n"
12320 "Default metric\n"
12321 "Route map reference\n"
12322 "Pointer to route-map entries\n")
12323 {
12324 VTY_DECLVAR_CONTEXT(bgp, bgp);
12325 int idx_ospf_table = 1;
12326 int idx_number = 2;
12327 int idx_number_2 = 4;
12328 int idx_word = 6;
12329 uint32_t metric;
12330 struct bgp_redist *red;
12331 unsigned short instance;
12332 int protocol;
12333 bool changed;
12334 struct route_map *route_map =
12335 route_map_lookup_warn_noexist(vty, argv[idx_word]->arg);
12336
12337 if (strncmp(argv[idx_ospf_table]->arg, "o", 1) == 0)
12338 protocol = ZEBRA_ROUTE_OSPF;
12339 else
12340 protocol = ZEBRA_ROUTE_TABLE;
12341
12342 instance = strtoul(argv[idx_number]->arg, NULL, 10);
12343 metric = strtoul(argv[idx_number_2]->arg, NULL, 10);
12344
12345 red = bgp_redist_add(bgp, AFI_IP, protocol, instance);
12346 changed = bgp_redistribute_metric_set(bgp, red, AFI_IP, protocol,
12347 metric);
12348 changed |=
12349 bgp_redistribute_rmap_set(red, argv[idx_word]->arg, route_map);
12350 return bgp_redistribute_set(bgp, AFI_IP, protocol, instance, changed);
12351 }
12352
12353 ALIAS_HIDDEN(
12354 bgp_redistribute_ipv4_ospf_metric_rmap,
12355 bgp_redistribute_ipv4_ospf_metric_rmap_hidden_cmd,
12356 "redistribute <ospf|table> (1-65535) metric (0-4294967295) route-map WORD",
12357 "Redistribute information from another routing protocol\n"
12358 "Open Shortest Path First (OSPFv2)\n"
12359 "Non-main Kernel Routing Table\n"
12360 "Instance ID/Table ID\n"
12361 "Metric for redistributed routes\n"
12362 "Default metric\n"
12363 "Route map reference\n"
12364 "Pointer to route-map entries\n")
12365
12366 DEFUN (no_bgp_redistribute_ipv4_ospf,
12367 no_bgp_redistribute_ipv4_ospf_cmd,
12368 "no redistribute <ospf|table> (1-65535) [metric (0-4294967295)] [route-map WORD]",
12369 NO_STR
12370 "Redistribute information from another routing protocol\n"
12371 "Open Shortest Path First (OSPFv2)\n"
12372 "Non-main Kernel Routing Table\n"
12373 "Instance ID/Table ID\n"
12374 "Metric for redistributed routes\n"
12375 "Default metric\n"
12376 "Route map reference\n"
12377 "Pointer to route-map entries\n")
12378 {
12379 VTY_DECLVAR_CONTEXT(bgp, bgp);
12380 int idx_ospf_table = 2;
12381 int idx_number = 3;
12382 unsigned short instance;
12383 int protocol;
12384
12385 if (strncmp(argv[idx_ospf_table]->arg, "o", 1) == 0)
12386 protocol = ZEBRA_ROUTE_OSPF;
12387 else
12388 protocol = ZEBRA_ROUTE_TABLE;
12389
12390 instance = strtoul(argv[idx_number]->arg, NULL, 10);
12391 return bgp_redistribute_unset(bgp, AFI_IP, protocol, instance);
12392 }
12393
12394 ALIAS_HIDDEN(
12395 no_bgp_redistribute_ipv4_ospf, no_bgp_redistribute_ipv4_ospf_hidden_cmd,
12396 "no redistribute <ospf|table> (1-65535) [metric (0-4294967295)] [route-map WORD]",
12397 NO_STR
12398 "Redistribute information from another routing protocol\n"
12399 "Open Shortest Path First (OSPFv2)\n"
12400 "Non-main Kernel Routing Table\n"
12401 "Instance ID/Table ID\n"
12402 "Metric for redistributed routes\n"
12403 "Default metric\n"
12404 "Route map reference\n"
12405 "Pointer to route-map entries\n")
12406
12407 DEFUN (no_bgp_redistribute_ipv4,
12408 no_bgp_redistribute_ipv4_cmd,
12409 "no redistribute " FRR_IP_REDIST_STR_BGPD " [metric (0-4294967295)] [route-map WORD]",
12410 NO_STR
12411 "Redistribute information from another routing protocol\n"
12412 FRR_IP_REDIST_HELP_STR_BGPD
12413 "Metric for redistributed routes\n"
12414 "Default metric\n"
12415 "Route map reference\n"
12416 "Pointer to route-map entries\n")
12417 {
12418 VTY_DECLVAR_CONTEXT(bgp, bgp);
12419 int idx_protocol = 2;
12420 int type;
12421
12422 type = proto_redistnum(AFI_IP, argv[idx_protocol]->text);
12423 if (type < 0) {
12424 vty_out(vty, "%% Invalid route type\n");
12425 return CMD_WARNING_CONFIG_FAILED;
12426 }
12427 return bgp_redistribute_unset(bgp, AFI_IP, type, 0);
12428 }
12429
12430 ALIAS_HIDDEN(
12431 no_bgp_redistribute_ipv4, no_bgp_redistribute_ipv4_hidden_cmd,
12432 "no redistribute " FRR_IP_REDIST_STR_BGPD
12433 " [metric (0-4294967295)] [route-map WORD]",
12434 NO_STR
12435 "Redistribute information from another routing protocol\n" FRR_IP_REDIST_HELP_STR_BGPD
12436 "Metric for redistributed routes\n"
12437 "Default metric\n"
12438 "Route map reference\n"
12439 "Pointer to route-map entries\n")
12440
12441 DEFUN (bgp_redistribute_ipv6,
12442 bgp_redistribute_ipv6_cmd,
12443 "redistribute " FRR_IP6_REDIST_STR_BGPD,
12444 "Redistribute information from another routing protocol\n"
12445 FRR_IP6_REDIST_HELP_STR_BGPD)
12446 {
12447 VTY_DECLVAR_CONTEXT(bgp, bgp);
12448 int idx_protocol = 1;
12449 int type;
12450
12451 type = proto_redistnum(AFI_IP6, argv[idx_protocol]->text);
12452 if (type < 0) {
12453 vty_out(vty, "%% Invalid route type\n");
12454 return CMD_WARNING_CONFIG_FAILED;
12455 }
12456
12457 bgp_redist_add(bgp, AFI_IP6, type, 0);
12458 return bgp_redistribute_set(bgp, AFI_IP6, type, 0, false);
12459 }
12460
12461 DEFUN (bgp_redistribute_ipv6_rmap,
12462 bgp_redistribute_ipv6_rmap_cmd,
12463 "redistribute " FRR_IP6_REDIST_STR_BGPD " route-map WORD",
12464 "Redistribute information from another routing protocol\n"
12465 FRR_IP6_REDIST_HELP_STR_BGPD
12466 "Route map reference\n"
12467 "Pointer to route-map entries\n")
12468 {
12469 VTY_DECLVAR_CONTEXT(bgp, bgp);
12470 int idx_protocol = 1;
12471 int idx_word = 3;
12472 int type;
12473 struct bgp_redist *red;
12474 bool changed;
12475 struct route_map *route_map =
12476 route_map_lookup_warn_noexist(vty, argv[idx_word]->arg);
12477
12478 type = proto_redistnum(AFI_IP6, argv[idx_protocol]->text);
12479 if (type < 0) {
12480 vty_out(vty, "%% Invalid route type\n");
12481 return CMD_WARNING_CONFIG_FAILED;
12482 }
12483
12484 red = bgp_redist_add(bgp, AFI_IP6, type, 0);
12485 changed =
12486 bgp_redistribute_rmap_set(red, argv[idx_word]->arg, route_map);
12487 return bgp_redistribute_set(bgp, AFI_IP6, type, 0, changed);
12488 }
12489
12490 DEFUN (bgp_redistribute_ipv6_metric,
12491 bgp_redistribute_ipv6_metric_cmd,
12492 "redistribute " FRR_IP6_REDIST_STR_BGPD " metric (0-4294967295)",
12493 "Redistribute information from another routing protocol\n"
12494 FRR_IP6_REDIST_HELP_STR_BGPD
12495 "Metric for redistributed routes\n"
12496 "Default metric\n")
12497 {
12498 VTY_DECLVAR_CONTEXT(bgp, bgp);
12499 int idx_protocol = 1;
12500 int idx_number = 3;
12501 int type;
12502 uint32_t metric;
12503 struct bgp_redist *red;
12504 bool changed;
12505
12506 type = proto_redistnum(AFI_IP6, argv[idx_protocol]->text);
12507 if (type < 0) {
12508 vty_out(vty, "%% Invalid route type\n");
12509 return CMD_WARNING_CONFIG_FAILED;
12510 }
12511 metric = strtoul(argv[idx_number]->arg, NULL, 10);
12512
12513 red = bgp_redist_add(bgp, AFI_IP6, type, 0);
12514 changed = bgp_redistribute_metric_set(bgp, red, AFI_IP6, type, metric);
12515 return bgp_redistribute_set(bgp, AFI_IP6, type, 0, changed);
12516 }
12517
12518 DEFUN (bgp_redistribute_ipv6_rmap_metric,
12519 bgp_redistribute_ipv6_rmap_metric_cmd,
12520 "redistribute " FRR_IP6_REDIST_STR_BGPD " route-map WORD metric (0-4294967295)",
12521 "Redistribute information from another routing protocol\n"
12522 FRR_IP6_REDIST_HELP_STR_BGPD
12523 "Route map reference\n"
12524 "Pointer to route-map entries\n"
12525 "Metric for redistributed routes\n"
12526 "Default metric\n")
12527 {
12528 VTY_DECLVAR_CONTEXT(bgp, bgp);
12529 int idx_protocol = 1;
12530 int idx_word = 3;
12531 int idx_number = 5;
12532 int type;
12533 uint32_t metric;
12534 struct bgp_redist *red;
12535 bool changed;
12536 struct route_map *route_map =
12537 route_map_lookup_warn_noexist(vty, argv[idx_word]->arg);
12538
12539 type = proto_redistnum(AFI_IP6, argv[idx_protocol]->text);
12540 if (type < 0) {
12541 vty_out(vty, "%% Invalid route type\n");
12542 return CMD_WARNING_CONFIG_FAILED;
12543 }
12544 metric = strtoul(argv[idx_number]->arg, NULL, 10);
12545
12546 red = bgp_redist_add(bgp, AFI_IP6, type, 0);
12547 changed =
12548 bgp_redistribute_rmap_set(red, argv[idx_word]->arg, route_map);
12549 changed |= bgp_redistribute_metric_set(bgp, red, AFI_IP6, type,
12550 metric);
12551 return bgp_redistribute_set(bgp, AFI_IP6, type, 0, changed);
12552 }
12553
12554 DEFUN (bgp_redistribute_ipv6_metric_rmap,
12555 bgp_redistribute_ipv6_metric_rmap_cmd,
12556 "redistribute " FRR_IP6_REDIST_STR_BGPD " metric (0-4294967295) route-map WORD",
12557 "Redistribute information from another routing protocol\n"
12558 FRR_IP6_REDIST_HELP_STR_BGPD
12559 "Metric for redistributed routes\n"
12560 "Default metric\n"
12561 "Route map reference\n"
12562 "Pointer to route-map entries\n")
12563 {
12564 VTY_DECLVAR_CONTEXT(bgp, bgp);
12565 int idx_protocol = 1;
12566 int idx_number = 3;
12567 int idx_word = 5;
12568 int type;
12569 uint32_t metric;
12570 struct bgp_redist *red;
12571 bool changed;
12572 struct route_map *route_map =
12573 route_map_lookup_warn_noexist(vty, argv[idx_word]->arg);
12574
12575 type = proto_redistnum(AFI_IP6, argv[idx_protocol]->text);
12576 if (type < 0) {
12577 vty_out(vty, "%% Invalid route type\n");
12578 return CMD_WARNING_CONFIG_FAILED;
12579 }
12580 metric = strtoul(argv[idx_number]->arg, NULL, 10);
12581
12582 red = bgp_redist_add(bgp, AFI_IP6, type, 0);
12583 changed = bgp_redistribute_metric_set(bgp, red, AFI_IP6, SAFI_UNICAST,
12584 metric);
12585 changed |=
12586 bgp_redistribute_rmap_set(red, argv[idx_word]->arg, route_map);
12587 return bgp_redistribute_set(bgp, AFI_IP6, type, 0, changed);
12588 }
12589
12590 DEFUN (no_bgp_redistribute_ipv6,
12591 no_bgp_redistribute_ipv6_cmd,
12592 "no redistribute " FRR_IP6_REDIST_STR_BGPD " [metric (0-4294967295)] [route-map WORD]",
12593 NO_STR
12594 "Redistribute information from another routing protocol\n"
12595 FRR_IP6_REDIST_HELP_STR_BGPD
12596 "Metric for redistributed routes\n"
12597 "Default metric\n"
12598 "Route map reference\n"
12599 "Pointer to route-map entries\n")
12600 {
12601 VTY_DECLVAR_CONTEXT(bgp, bgp);
12602 int idx_protocol = 2;
12603 int type;
12604
12605 type = proto_redistnum(AFI_IP6, argv[idx_protocol]->text);
12606 if (type < 0) {
12607 vty_out(vty, "%% Invalid route type\n");
12608 return CMD_WARNING_CONFIG_FAILED;
12609 }
12610
12611 return bgp_redistribute_unset(bgp, AFI_IP6, type, 0);
12612 }
12613
12614 void bgp_config_write_redistribute(struct vty *vty, struct bgp *bgp, afi_t afi,
12615 safi_t safi)
12616 {
12617 int i;
12618
12619 /* Unicast redistribution only. */
12620 if (safi != SAFI_UNICAST)
12621 return;
12622
12623 for (i = 0; i < ZEBRA_ROUTE_MAX; i++) {
12624 /* Redistribute BGP does not make sense. */
12625 if (i != ZEBRA_ROUTE_BGP) {
12626 struct list *red_list;
12627 struct listnode *node;
12628 struct bgp_redist *red;
12629
12630 red_list = bgp->redist[afi][i];
12631 if (!red_list)
12632 continue;
12633
12634 for (ALL_LIST_ELEMENTS_RO(red_list, node, red)) {
12635 /* "redistribute" configuration. */
12636 vty_out(vty, " redistribute %s",
12637 zebra_route_string(i));
12638 if (red->instance)
12639 vty_out(vty, " %d", red->instance);
12640 if (red->redist_metric_flag)
12641 vty_out(vty, " metric %u",
12642 red->redist_metric);
12643 if (red->rmap.name)
12644 vty_out(vty, " route-map %s",
12645 red->rmap.name);
12646 vty_out(vty, "\n");
12647 }
12648 }
12649 }
12650 }
12651
12652 /* This is part of the address-family block (unicast only) */
12653 void bgp_vpn_policy_config_write_afi(struct vty *vty, struct bgp *bgp,
12654 afi_t afi)
12655 {
12656 int indent = 2;
12657
12658 if (bgp->vpn_policy[afi].rmap_name[BGP_VPN_POLICY_DIR_FROMVPN]) {
12659 if (listcount(bgp->vpn_policy[afi].import_vrf))
12660 vty_out(vty, "%*simport vrf route-map %s\n", indent, "",
12661 bgp->vpn_policy[afi]
12662 .rmap_name[BGP_VPN_POLICY_DIR_FROMVPN]);
12663 else
12664 vty_out(vty, "%*sroute-map vpn import %s\n", indent, "",
12665 bgp->vpn_policy[afi]
12666 .rmap_name[BGP_VPN_POLICY_DIR_FROMVPN]);
12667 }
12668 if (CHECK_FLAG(bgp->af_flags[afi][SAFI_UNICAST],
12669 BGP_CONFIG_VRF_TO_VRF_IMPORT)
12670 || CHECK_FLAG(bgp->af_flags[afi][SAFI_UNICAST],
12671 BGP_CONFIG_VRF_TO_VRF_EXPORT))
12672 return;
12673
12674 if (CHECK_FLAG(bgp->vpn_policy[afi].flags,
12675 BGP_VPN_POLICY_TOVPN_LABEL_AUTO)) {
12676
12677 vty_out(vty, "%*slabel vpn export %s\n", indent, "", "auto");
12678
12679 } else {
12680 if (bgp->vpn_policy[afi].tovpn_label != MPLS_LABEL_NONE) {
12681 vty_out(vty, "%*slabel vpn export %u\n", indent, "",
12682 bgp->vpn_policy[afi].tovpn_label);
12683 }
12684 }
12685 if (CHECK_FLAG(bgp->vpn_policy[afi].flags,
12686 BGP_VPN_POLICY_TOVPN_RD_SET)) {
12687 char buf[RD_ADDRSTRLEN];
12688 vty_out(vty, "%*srd vpn export %s\n", indent, "",
12689 prefix_rd2str(&bgp->vpn_policy[afi].tovpn_rd, buf,
12690 sizeof(buf)));
12691 }
12692 if (CHECK_FLAG(bgp->vpn_policy[afi].flags,
12693 BGP_VPN_POLICY_TOVPN_NEXTHOP_SET)) {
12694
12695 char buf[PREFIX_STRLEN];
12696 if (inet_ntop(bgp->vpn_policy[afi].tovpn_nexthop.family,
12697 &bgp->vpn_policy[afi].tovpn_nexthop.u.prefix, buf,
12698 sizeof(buf))) {
12699
12700 vty_out(vty, "%*snexthop vpn export %s\n",
12701 indent, "", buf);
12702 }
12703 }
12704 if (bgp->vpn_policy[afi].rtlist[BGP_VPN_POLICY_DIR_FROMVPN]
12705 && bgp->vpn_policy[afi].rtlist[BGP_VPN_POLICY_DIR_TOVPN]
12706 && ecommunity_cmp(
12707 bgp->vpn_policy[afi].rtlist[BGP_VPN_POLICY_DIR_FROMVPN],
12708 bgp->vpn_policy[afi].rtlist[BGP_VPN_POLICY_DIR_TOVPN])) {
12709
12710 char *b = ecommunity_ecom2str(
12711 bgp->vpn_policy[afi].rtlist[BGP_VPN_POLICY_DIR_TOVPN],
12712 ECOMMUNITY_FORMAT_ROUTE_MAP, ECOMMUNITY_ROUTE_TARGET);
12713 vty_out(vty, "%*srt vpn both %s\n", indent, "", b);
12714 XFREE(MTYPE_ECOMMUNITY_STR, b);
12715 } else {
12716 if (bgp->vpn_policy[afi].rtlist[BGP_VPN_POLICY_DIR_FROMVPN]) {
12717 char *b = ecommunity_ecom2str(
12718 bgp->vpn_policy[afi]
12719 .rtlist[BGP_VPN_POLICY_DIR_FROMVPN],
12720 ECOMMUNITY_FORMAT_ROUTE_MAP,
12721 ECOMMUNITY_ROUTE_TARGET);
12722 vty_out(vty, "%*srt vpn import %s\n", indent, "", b);
12723 XFREE(MTYPE_ECOMMUNITY_STR, b);
12724 }
12725 if (bgp->vpn_policy[afi].rtlist[BGP_VPN_POLICY_DIR_TOVPN]) {
12726 char *b = ecommunity_ecom2str(
12727 bgp->vpn_policy[afi]
12728 .rtlist[BGP_VPN_POLICY_DIR_TOVPN],
12729 ECOMMUNITY_FORMAT_ROUTE_MAP,
12730 ECOMMUNITY_ROUTE_TARGET);
12731 vty_out(vty, "%*srt vpn export %s\n", indent, "", b);
12732 XFREE(MTYPE_ECOMMUNITY_STR, b);
12733 }
12734 }
12735
12736 if (bgp->vpn_policy[afi].rmap_name[BGP_VPN_POLICY_DIR_TOVPN])
12737 vty_out(vty, "%*sroute-map vpn export %s\n", indent, "",
12738 bgp->vpn_policy[afi]
12739 .rmap_name[BGP_VPN_POLICY_DIR_TOVPN]);
12740
12741 if (bgp->vpn_policy[afi].import_redirect_rtlist) {
12742 char *b = ecommunity_ecom2str(
12743 bgp->vpn_policy[afi]
12744 .import_redirect_rtlist,
12745 ECOMMUNITY_FORMAT_ROUTE_MAP,
12746 ECOMMUNITY_ROUTE_TARGET);
12747
12748 vty_out(vty, "%*srt redirect import %s\n", indent, "", b);
12749 XFREE(MTYPE_ECOMMUNITY_STR, b);
12750 }
12751 }
12752
12753
12754 /* BGP node structure. */
12755 static struct cmd_node bgp_node = {
12756 BGP_NODE, "%s(config-router)# ", 1,
12757 };
12758
12759 static struct cmd_node bgp_ipv4_unicast_node = {
12760 BGP_IPV4_NODE, "%s(config-router-af)# ", 1,
12761 };
12762
12763 static struct cmd_node bgp_ipv4_multicast_node = {
12764 BGP_IPV4M_NODE, "%s(config-router-af)# ", 1,
12765 };
12766
12767 static struct cmd_node bgp_ipv4_labeled_unicast_node = {
12768 BGP_IPV4L_NODE, "%s(config-router-af)# ", 1,
12769 };
12770
12771 static struct cmd_node bgp_ipv6_unicast_node = {
12772 BGP_IPV6_NODE, "%s(config-router-af)# ", 1,
12773 };
12774
12775 static struct cmd_node bgp_ipv6_multicast_node = {
12776 BGP_IPV6M_NODE, "%s(config-router-af)# ", 1,
12777 };
12778
12779 static struct cmd_node bgp_ipv6_labeled_unicast_node = {
12780 BGP_IPV6L_NODE, "%s(config-router-af)# ", 1,
12781 };
12782
12783 static struct cmd_node bgp_vpnv4_node = {BGP_VPNV4_NODE,
12784 "%s(config-router-af)# ", 1};
12785
12786 static struct cmd_node bgp_vpnv6_node = {BGP_VPNV6_NODE,
12787 "%s(config-router-af-vpnv6)# ", 1};
12788
12789 static struct cmd_node bgp_evpn_node = {BGP_EVPN_NODE,
12790 "%s(config-router-evpn)# ", 1};
12791
12792 static struct cmd_node bgp_evpn_vni_node = {BGP_EVPN_VNI_NODE,
12793 "%s(config-router-af-vni)# ", 1};
12794
12795 static struct cmd_node bgp_flowspecv4_node = {BGP_FLOWSPECV4_NODE,
12796 "%s(config-router-af)# ", 1};
12797
12798 static struct cmd_node bgp_flowspecv6_node = {BGP_FLOWSPECV6_NODE,
12799 "%s(config-router-af-vpnv6)# ", 1};
12800
12801 static void community_list_vty(void);
12802
12803 static void bgp_ac_neighbor(vector comps, struct cmd_token *token)
12804 {
12805 struct bgp *bgp;
12806 struct peer *peer;
12807 struct listnode *lnbgp, *lnpeer;
12808
12809 for (ALL_LIST_ELEMENTS_RO(bm->bgp, lnbgp, bgp)) {
12810 for (ALL_LIST_ELEMENTS_RO(bgp->peer, lnpeer, peer)) {
12811 /* only provide suggestions on the appropriate input
12812 * token type,
12813 * they'll otherwise show up multiple times */
12814 enum cmd_token_type match_type;
12815 char *name = peer->host;
12816
12817 if (peer->conf_if) {
12818 match_type = VARIABLE_TKN;
12819 name = peer->conf_if;
12820 } else if (strchr(peer->host, ':'))
12821 match_type = IPV6_TKN;
12822 else
12823 match_type = IPV4_TKN;
12824
12825 if (token->type != match_type)
12826 continue;
12827
12828 vector_set(comps, XSTRDUP(MTYPE_COMPLETION, name));
12829 }
12830 }
12831 }
12832
12833 static const struct cmd_variable_handler bgp_var_neighbor[] = {
12834 {.varname = "neighbor", .completions = bgp_ac_neighbor},
12835 {.varname = "neighbors", .completions = bgp_ac_neighbor},
12836 {.varname = "peer", .completions = bgp_ac_neighbor},
12837 {.completions = NULL}};
12838
12839 static void bgp_ac_peergroup(vector comps, struct cmd_token *token)
12840 {
12841 struct bgp *bgp;
12842 struct peer_group *group;
12843 struct listnode *lnbgp, *lnpeer;
12844
12845 for (ALL_LIST_ELEMENTS_RO(bm->bgp, lnbgp, bgp)) {
12846 for (ALL_LIST_ELEMENTS_RO(bgp->group, lnpeer, group))
12847 vector_set(comps, XSTRDUP(MTYPE_COMPLETION,
12848 group->name));
12849 }
12850 }
12851
12852 static const struct cmd_variable_handler bgp_var_peergroup[] = {
12853 {.tokenname = "PGNAME", .completions = bgp_ac_peergroup},
12854 {.completions = NULL} };
12855
12856 void bgp_vty_init(void)
12857 {
12858 cmd_variable_handler_register(bgp_var_neighbor);
12859 cmd_variable_handler_register(bgp_var_peergroup);
12860
12861 /* Install bgp top node. */
12862 install_node(&bgp_node, bgp_config_write);
12863 install_node(&bgp_ipv4_unicast_node, NULL);
12864 install_node(&bgp_ipv4_multicast_node, NULL);
12865 install_node(&bgp_ipv4_labeled_unicast_node, NULL);
12866 install_node(&bgp_ipv6_unicast_node, NULL);
12867 install_node(&bgp_ipv6_multicast_node, NULL);
12868 install_node(&bgp_ipv6_labeled_unicast_node, NULL);
12869 install_node(&bgp_vpnv4_node, NULL);
12870 install_node(&bgp_vpnv6_node, NULL);
12871 install_node(&bgp_evpn_node, NULL);
12872 install_node(&bgp_evpn_vni_node, NULL);
12873 install_node(&bgp_flowspecv4_node, NULL);
12874 install_node(&bgp_flowspecv6_node, NULL);
12875
12876 /* Install default VTY commands to new nodes. */
12877 install_default(BGP_NODE);
12878 install_default(BGP_IPV4_NODE);
12879 install_default(BGP_IPV4M_NODE);
12880 install_default(BGP_IPV4L_NODE);
12881 install_default(BGP_IPV6_NODE);
12882 install_default(BGP_IPV6M_NODE);
12883 install_default(BGP_IPV6L_NODE);
12884 install_default(BGP_VPNV4_NODE);
12885 install_default(BGP_VPNV6_NODE);
12886 install_default(BGP_FLOWSPECV4_NODE);
12887 install_default(BGP_FLOWSPECV6_NODE);
12888 install_default(BGP_EVPN_NODE);
12889 install_default(BGP_EVPN_VNI_NODE);
12890
12891 /* "bgp multiple-instance" commands. */
12892 install_element(CONFIG_NODE, &bgp_multiple_instance_cmd);
12893 install_element(CONFIG_NODE, &no_bgp_multiple_instance_cmd);
12894
12895 /* "bgp config-type" commands. */
12896 install_element(CONFIG_NODE, &bgp_config_type_cmd);
12897 install_element(CONFIG_NODE, &no_bgp_config_type_cmd);
12898
12899 /* "bgp local-mac" hidden commands. */
12900 install_element(CONFIG_NODE, &bgp_local_mac_cmd);
12901 install_element(CONFIG_NODE, &no_bgp_local_mac_cmd);
12902
12903 /* bgp route-map delay-timer commands. */
12904 install_element(CONFIG_NODE, &bgp_set_route_map_delay_timer_cmd);
12905 install_element(CONFIG_NODE, &no_bgp_set_route_map_delay_timer_cmd);
12906
12907 /* Dummy commands (Currently not supported) */
12908 install_element(BGP_NODE, &no_synchronization_cmd);
12909 install_element(BGP_NODE, &no_auto_summary_cmd);
12910
12911 /* "router bgp" commands. */
12912 install_element(CONFIG_NODE, &router_bgp_cmd);
12913
12914 /* "no router bgp" commands. */
12915 install_element(CONFIG_NODE, &no_router_bgp_cmd);
12916
12917 /* "bgp router-id" commands. */
12918 install_element(BGP_NODE, &bgp_router_id_cmd);
12919 install_element(BGP_NODE, &no_bgp_router_id_cmd);
12920
12921 /* "bgp cluster-id" commands. */
12922 install_element(BGP_NODE, &bgp_cluster_id_cmd);
12923 install_element(BGP_NODE, &no_bgp_cluster_id_cmd);
12924
12925 /* "bgp confederation" commands. */
12926 install_element(BGP_NODE, &bgp_confederation_identifier_cmd);
12927 install_element(BGP_NODE, &no_bgp_confederation_identifier_cmd);
12928
12929 /* "bgp confederation peers" commands. */
12930 install_element(BGP_NODE, &bgp_confederation_peers_cmd);
12931 install_element(BGP_NODE, &no_bgp_confederation_peers_cmd);
12932
12933 /* bgp max-med command */
12934 install_element(BGP_NODE, &bgp_maxmed_admin_cmd);
12935 install_element(BGP_NODE, &no_bgp_maxmed_admin_cmd);
12936 install_element(BGP_NODE, &bgp_maxmed_admin_medv_cmd);
12937 install_element(BGP_NODE, &bgp_maxmed_onstartup_cmd);
12938 install_element(BGP_NODE, &no_bgp_maxmed_onstartup_cmd);
12939
12940 /* bgp disable-ebgp-connected-nh-check */
12941 install_element(BGP_NODE, &bgp_disable_connected_route_check_cmd);
12942 install_element(BGP_NODE, &no_bgp_disable_connected_route_check_cmd);
12943
12944 /* bgp update-delay command */
12945 install_element(BGP_NODE, &bgp_update_delay_cmd);
12946 install_element(BGP_NODE, &no_bgp_update_delay_cmd);
12947 install_element(BGP_NODE, &bgp_update_delay_establish_wait_cmd);
12948
12949 install_element(BGP_NODE, &bgp_wpkt_quanta_cmd);
12950 install_element(BGP_NODE, &no_bgp_wpkt_quanta_cmd);
12951 install_element(BGP_NODE, &bgp_rpkt_quanta_cmd);
12952 install_element(BGP_NODE, &no_bgp_rpkt_quanta_cmd);
12953
12954 install_element(BGP_NODE, &bgp_coalesce_time_cmd);
12955 install_element(BGP_NODE, &no_bgp_coalesce_time_cmd);
12956
12957 /* "maximum-paths" commands. */
12958 install_element(BGP_NODE, &bgp_maxpaths_hidden_cmd);
12959 install_element(BGP_NODE, &no_bgp_maxpaths_hidden_cmd);
12960 install_element(BGP_IPV4_NODE, &bgp_maxpaths_cmd);
12961 install_element(BGP_IPV4_NODE, &no_bgp_maxpaths_cmd);
12962 install_element(BGP_IPV6_NODE, &bgp_maxpaths_cmd);
12963 install_element(BGP_IPV6_NODE, &no_bgp_maxpaths_cmd);
12964 install_element(BGP_NODE, &bgp_maxpaths_ibgp_hidden_cmd);
12965 install_element(BGP_NODE, &bgp_maxpaths_ibgp_cluster_hidden_cmd);
12966 install_element(BGP_NODE, &no_bgp_maxpaths_ibgp_hidden_cmd);
12967 install_element(BGP_IPV4_NODE, &bgp_maxpaths_ibgp_cmd);
12968 install_element(BGP_IPV4_NODE, &bgp_maxpaths_ibgp_cluster_cmd);
12969 install_element(BGP_IPV4_NODE, &no_bgp_maxpaths_ibgp_cmd);
12970 install_element(BGP_IPV6_NODE, &bgp_maxpaths_ibgp_cmd);
12971 install_element(BGP_IPV6_NODE, &bgp_maxpaths_ibgp_cluster_cmd);
12972 install_element(BGP_IPV6_NODE, &no_bgp_maxpaths_ibgp_cmd);
12973
12974 install_element(BGP_IPV6L_NODE, &bgp_maxpaths_cmd);
12975 install_element(BGP_IPV6L_NODE, &no_bgp_maxpaths_cmd);
12976 install_element(BGP_IPV6L_NODE, &bgp_maxpaths_ibgp_cmd);
12977 install_element(BGP_IPV6L_NODE, &bgp_maxpaths_ibgp_cluster_cmd);
12978 install_element(BGP_IPV6L_NODE, &no_bgp_maxpaths_ibgp_cmd);
12979
12980 /* "timers bgp" commands. */
12981 install_element(BGP_NODE, &bgp_timers_cmd);
12982 install_element(BGP_NODE, &no_bgp_timers_cmd);
12983
12984 /* route-map delay-timer commands - per instance for backwards compat.
12985 */
12986 install_element(BGP_NODE, &bgp_set_route_map_delay_timer_cmd);
12987 install_element(BGP_NODE, &no_bgp_set_route_map_delay_timer_cmd);
12988
12989 /* "bgp client-to-client reflection" commands */
12990 install_element(BGP_NODE, &no_bgp_client_to_client_reflection_cmd);
12991 install_element(BGP_NODE, &bgp_client_to_client_reflection_cmd);
12992
12993 /* "bgp always-compare-med" commands */
12994 install_element(BGP_NODE, &bgp_always_compare_med_cmd);
12995 install_element(BGP_NODE, &no_bgp_always_compare_med_cmd);
12996
12997 /* bgp ebgp-requires-policy */
12998 install_element(BGP_NODE, &bgp_ebgp_requires_policy_cmd);
12999 install_element(BGP_NODE, &no_bgp_ebgp_requires_policy_cmd);
13000
13001 /* "bgp deterministic-med" commands */
13002 install_element(BGP_NODE, &bgp_deterministic_med_cmd);
13003 install_element(BGP_NODE, &no_bgp_deterministic_med_cmd);
13004
13005 /* "bgp graceful-restart" commands */
13006 install_element(BGP_NODE, &bgp_graceful_restart_cmd);
13007 install_element(BGP_NODE, &no_bgp_graceful_restart_cmd);
13008 install_element(BGP_NODE, &bgp_graceful_restart_stalepath_time_cmd);
13009 install_element(BGP_NODE, &no_bgp_graceful_restart_stalepath_time_cmd);
13010 install_element(BGP_NODE, &bgp_graceful_restart_restart_time_cmd);
13011 install_element(BGP_NODE, &no_bgp_graceful_restart_restart_time_cmd);
13012
13013 install_element(BGP_NODE, &bgp_graceful_restart_preserve_fw_cmd);
13014 install_element(BGP_NODE, &no_bgp_graceful_restart_preserve_fw_cmd);
13015
13016 /* "bgp graceful-shutdown" commands */
13017 install_element(BGP_NODE, &bgp_graceful_shutdown_cmd);
13018 install_element(BGP_NODE, &no_bgp_graceful_shutdown_cmd);
13019
13020 /* "bgp fast-external-failover" commands */
13021 install_element(BGP_NODE, &bgp_fast_external_failover_cmd);
13022 install_element(BGP_NODE, &no_bgp_fast_external_failover_cmd);
13023
13024 /* "bgp enforce-first-as" commands */
13025 install_element(BGP_NODE, &bgp_enforce_first_as_cmd);
13026
13027 /* "bgp bestpath compare-routerid" commands */
13028 install_element(BGP_NODE, &bgp_bestpath_compare_router_id_cmd);
13029 install_element(BGP_NODE, &no_bgp_bestpath_compare_router_id_cmd);
13030
13031 /* "bgp bestpath as-path ignore" commands */
13032 install_element(BGP_NODE, &bgp_bestpath_aspath_ignore_cmd);
13033 install_element(BGP_NODE, &no_bgp_bestpath_aspath_ignore_cmd);
13034
13035 /* "bgp bestpath as-path confed" commands */
13036 install_element(BGP_NODE, &bgp_bestpath_aspath_confed_cmd);
13037 install_element(BGP_NODE, &no_bgp_bestpath_aspath_confed_cmd);
13038
13039 /* "bgp bestpath as-path multipath-relax" commands */
13040 install_element(BGP_NODE, &bgp_bestpath_aspath_multipath_relax_cmd);
13041 install_element(BGP_NODE, &no_bgp_bestpath_aspath_multipath_relax_cmd);
13042
13043 /* "bgp log-neighbor-changes" commands */
13044 install_element(BGP_NODE, &bgp_log_neighbor_changes_cmd);
13045 install_element(BGP_NODE, &no_bgp_log_neighbor_changes_cmd);
13046
13047 /* "bgp bestpath med" commands */
13048 install_element(BGP_NODE, &bgp_bestpath_med_cmd);
13049 install_element(BGP_NODE, &no_bgp_bestpath_med_cmd);
13050
13051 /* "no bgp default ipv4-unicast" commands. */
13052 install_element(BGP_NODE, &no_bgp_default_ipv4_unicast_cmd);
13053 install_element(BGP_NODE, &bgp_default_ipv4_unicast_cmd);
13054
13055 /* "bgp network import-check" commands. */
13056 install_element(BGP_NODE, &bgp_network_import_check_cmd);
13057 install_element(BGP_NODE, &bgp_network_import_check_exact_cmd);
13058 install_element(BGP_NODE, &no_bgp_network_import_check_cmd);
13059
13060 /* "bgp default local-preference" commands. */
13061 install_element(BGP_NODE, &bgp_default_local_preference_cmd);
13062 install_element(BGP_NODE, &no_bgp_default_local_preference_cmd);
13063
13064 /* bgp default show-hostname */
13065 install_element(BGP_NODE, &bgp_default_show_hostname_cmd);
13066 install_element(BGP_NODE, &no_bgp_default_show_hostname_cmd);
13067
13068 /* "bgp default subgroup-pkt-queue-max" commands. */
13069 install_element(BGP_NODE, &bgp_default_subgroup_pkt_queue_max_cmd);
13070 install_element(BGP_NODE, &no_bgp_default_subgroup_pkt_queue_max_cmd);
13071
13072 /* bgp ibgp-allow-policy-mods command */
13073 install_element(BGP_NODE, &bgp_rr_allow_outbound_policy_cmd);
13074 install_element(BGP_NODE, &no_bgp_rr_allow_outbound_policy_cmd);
13075
13076 /* "bgp listen limit" commands. */
13077 install_element(BGP_NODE, &bgp_listen_limit_cmd);
13078 install_element(BGP_NODE, &no_bgp_listen_limit_cmd);
13079
13080 /* "bgp listen range" commands. */
13081 install_element(BGP_NODE, &bgp_listen_range_cmd);
13082 install_element(BGP_NODE, &no_bgp_listen_range_cmd);
13083
13084 /* "bgp default shutdown" command */
13085 install_element(BGP_NODE, &bgp_default_shutdown_cmd);
13086
13087 /* "neighbor remote-as" commands. */
13088 install_element(BGP_NODE, &neighbor_remote_as_cmd);
13089 install_element(BGP_NODE, &neighbor_interface_config_cmd);
13090 install_element(BGP_NODE, &neighbor_interface_config_v6only_cmd);
13091 install_element(BGP_NODE, &neighbor_interface_config_remote_as_cmd);
13092 install_element(BGP_NODE,
13093 &neighbor_interface_v6only_config_remote_as_cmd);
13094 install_element(BGP_NODE, &no_neighbor_cmd);
13095 install_element(BGP_NODE, &no_neighbor_interface_config_cmd);
13096
13097 /* "neighbor peer-group" commands. */
13098 install_element(BGP_NODE, &neighbor_peer_group_cmd);
13099 install_element(BGP_NODE, &no_neighbor_peer_group_cmd);
13100 install_element(BGP_NODE,
13101 &no_neighbor_interface_peer_group_remote_as_cmd);
13102
13103 /* "neighbor local-as" commands. */
13104 install_element(BGP_NODE, &neighbor_local_as_cmd);
13105 install_element(BGP_NODE, &neighbor_local_as_no_prepend_cmd);
13106 install_element(BGP_NODE, &neighbor_local_as_no_prepend_replace_as_cmd);
13107 install_element(BGP_NODE, &no_neighbor_local_as_cmd);
13108
13109 /* "neighbor solo" commands. */
13110 install_element(BGP_NODE, &neighbor_solo_cmd);
13111 install_element(BGP_NODE, &no_neighbor_solo_cmd);
13112
13113 /* "neighbor password" commands. */
13114 install_element(BGP_NODE, &neighbor_password_cmd);
13115 install_element(BGP_NODE, &no_neighbor_password_cmd);
13116
13117 /* "neighbor activate" commands. */
13118 install_element(BGP_NODE, &neighbor_activate_hidden_cmd);
13119 install_element(BGP_IPV4_NODE, &neighbor_activate_cmd);
13120 install_element(BGP_IPV4M_NODE, &neighbor_activate_cmd);
13121 install_element(BGP_IPV4L_NODE, &neighbor_activate_cmd);
13122 install_element(BGP_IPV6_NODE, &neighbor_activate_cmd);
13123 install_element(BGP_IPV6M_NODE, &neighbor_activate_cmd);
13124 install_element(BGP_IPV6L_NODE, &neighbor_activate_cmd);
13125 install_element(BGP_VPNV4_NODE, &neighbor_activate_cmd);
13126 install_element(BGP_VPNV6_NODE, &neighbor_activate_cmd);
13127 install_element(BGP_FLOWSPECV4_NODE, &neighbor_activate_cmd);
13128 install_element(BGP_FLOWSPECV6_NODE, &neighbor_activate_cmd);
13129 install_element(BGP_EVPN_NODE, &neighbor_activate_cmd);
13130
13131 /* "no neighbor activate" commands. */
13132 install_element(BGP_NODE, &no_neighbor_activate_hidden_cmd);
13133 install_element(BGP_IPV4_NODE, &no_neighbor_activate_cmd);
13134 install_element(BGP_IPV4M_NODE, &no_neighbor_activate_cmd);
13135 install_element(BGP_IPV4L_NODE, &no_neighbor_activate_cmd);
13136 install_element(BGP_IPV6_NODE, &no_neighbor_activate_cmd);
13137 install_element(BGP_IPV6M_NODE, &no_neighbor_activate_cmd);
13138 install_element(BGP_IPV6L_NODE, &no_neighbor_activate_cmd);
13139 install_element(BGP_VPNV4_NODE, &no_neighbor_activate_cmd);
13140 install_element(BGP_VPNV6_NODE, &no_neighbor_activate_cmd);
13141 install_element(BGP_FLOWSPECV4_NODE, &no_neighbor_activate_cmd);
13142 install_element(BGP_FLOWSPECV6_NODE, &no_neighbor_activate_cmd);
13143 install_element(BGP_EVPN_NODE, &no_neighbor_activate_cmd);
13144
13145 /* "neighbor peer-group" set commands. */
13146 install_element(BGP_NODE, &neighbor_set_peer_group_cmd);
13147 install_element(BGP_IPV4_NODE, &neighbor_set_peer_group_hidden_cmd);
13148 install_element(BGP_IPV4M_NODE, &neighbor_set_peer_group_hidden_cmd);
13149 install_element(BGP_IPV6_NODE, &neighbor_set_peer_group_hidden_cmd);
13150 install_element(BGP_IPV6M_NODE, &neighbor_set_peer_group_hidden_cmd);
13151 install_element(BGP_IPV6L_NODE, &neighbor_set_peer_group_hidden_cmd);
13152 install_element(BGP_VPNV4_NODE, &neighbor_set_peer_group_hidden_cmd);
13153 install_element(BGP_VPNV6_NODE, &neighbor_set_peer_group_hidden_cmd);
13154 install_element(BGP_FLOWSPECV4_NODE,
13155 &neighbor_set_peer_group_hidden_cmd);
13156 install_element(BGP_FLOWSPECV6_NODE,
13157 &neighbor_set_peer_group_hidden_cmd);
13158
13159 /* "no neighbor peer-group unset" commands. */
13160 install_element(BGP_NODE, &no_neighbor_set_peer_group_cmd);
13161 install_element(BGP_IPV4_NODE, &no_neighbor_set_peer_group_hidden_cmd);
13162 install_element(BGP_IPV4M_NODE, &no_neighbor_set_peer_group_hidden_cmd);
13163 install_element(BGP_IPV6_NODE, &no_neighbor_set_peer_group_hidden_cmd);
13164 install_element(BGP_IPV6M_NODE, &no_neighbor_set_peer_group_hidden_cmd);
13165 install_element(BGP_IPV6L_NODE, &no_neighbor_set_peer_group_hidden_cmd);
13166 install_element(BGP_VPNV4_NODE, &no_neighbor_set_peer_group_hidden_cmd);
13167 install_element(BGP_VPNV6_NODE, &no_neighbor_set_peer_group_hidden_cmd);
13168 install_element(BGP_FLOWSPECV4_NODE,
13169 &no_neighbor_set_peer_group_hidden_cmd);
13170 install_element(BGP_FLOWSPECV6_NODE,
13171 &no_neighbor_set_peer_group_hidden_cmd);
13172
13173 /* "neighbor softreconfiguration inbound" commands.*/
13174 install_element(BGP_NODE, &neighbor_soft_reconfiguration_hidden_cmd);
13175 install_element(BGP_NODE, &no_neighbor_soft_reconfiguration_hidden_cmd);
13176 install_element(BGP_IPV4_NODE, &neighbor_soft_reconfiguration_cmd);
13177 install_element(BGP_IPV4_NODE, &no_neighbor_soft_reconfiguration_cmd);
13178 install_element(BGP_IPV4L_NODE, &neighbor_soft_reconfiguration_cmd);
13179 install_element(BGP_IPV4L_NODE, &no_neighbor_soft_reconfiguration_cmd);
13180 install_element(BGP_IPV4M_NODE, &neighbor_soft_reconfiguration_cmd);
13181 install_element(BGP_IPV4M_NODE, &no_neighbor_soft_reconfiguration_cmd);
13182 install_element(BGP_IPV6_NODE, &neighbor_soft_reconfiguration_cmd);
13183 install_element(BGP_IPV6_NODE, &no_neighbor_soft_reconfiguration_cmd);
13184 install_element(BGP_IPV6M_NODE, &neighbor_soft_reconfiguration_cmd);
13185 install_element(BGP_IPV6M_NODE, &no_neighbor_soft_reconfiguration_cmd);
13186 install_element(BGP_IPV6L_NODE, &neighbor_soft_reconfiguration_cmd);
13187 install_element(BGP_IPV6L_NODE, &no_neighbor_soft_reconfiguration_cmd);
13188 install_element(BGP_VPNV4_NODE, &neighbor_soft_reconfiguration_cmd);
13189 install_element(BGP_VPNV4_NODE, &no_neighbor_soft_reconfiguration_cmd);
13190 install_element(BGP_VPNV6_NODE, &neighbor_soft_reconfiguration_cmd);
13191 install_element(BGP_VPNV6_NODE, &no_neighbor_soft_reconfiguration_cmd);
13192 install_element(BGP_FLOWSPECV4_NODE,
13193 &neighbor_soft_reconfiguration_cmd);
13194 install_element(BGP_FLOWSPECV4_NODE,
13195 &no_neighbor_soft_reconfiguration_cmd);
13196 install_element(BGP_FLOWSPECV6_NODE,
13197 &neighbor_soft_reconfiguration_cmd);
13198 install_element(BGP_FLOWSPECV6_NODE,
13199 &no_neighbor_soft_reconfiguration_cmd);
13200 install_element(BGP_EVPN_NODE, &neighbor_soft_reconfiguration_cmd);
13201 install_element(BGP_EVPN_NODE, &no_neighbor_soft_reconfiguration_cmd);
13202
13203 /* "neighbor attribute-unchanged" commands. */
13204 install_element(BGP_NODE, &neighbor_attr_unchanged_hidden_cmd);
13205 install_element(BGP_NODE, &no_neighbor_attr_unchanged_hidden_cmd);
13206 install_element(BGP_IPV4_NODE, &neighbor_attr_unchanged_cmd);
13207 install_element(BGP_IPV4_NODE, &no_neighbor_attr_unchanged_cmd);
13208 install_element(BGP_IPV4M_NODE, &neighbor_attr_unchanged_cmd);
13209 install_element(BGP_IPV4M_NODE, &no_neighbor_attr_unchanged_cmd);
13210 install_element(BGP_IPV4L_NODE, &neighbor_attr_unchanged_cmd);
13211 install_element(BGP_IPV4L_NODE, &no_neighbor_attr_unchanged_cmd);
13212 install_element(BGP_IPV6_NODE, &neighbor_attr_unchanged_cmd);
13213 install_element(BGP_IPV6_NODE, &no_neighbor_attr_unchanged_cmd);
13214 install_element(BGP_IPV6M_NODE, &neighbor_attr_unchanged_cmd);
13215 install_element(BGP_IPV6M_NODE, &no_neighbor_attr_unchanged_cmd);
13216 install_element(BGP_IPV6L_NODE, &neighbor_attr_unchanged_cmd);
13217 install_element(BGP_IPV6L_NODE, &no_neighbor_attr_unchanged_cmd);
13218 install_element(BGP_VPNV4_NODE, &neighbor_attr_unchanged_cmd);
13219 install_element(BGP_VPNV4_NODE, &no_neighbor_attr_unchanged_cmd);
13220 install_element(BGP_VPNV6_NODE, &neighbor_attr_unchanged_cmd);
13221 install_element(BGP_VPNV6_NODE, &no_neighbor_attr_unchanged_cmd);
13222
13223 install_element(BGP_EVPN_NODE, &neighbor_attr_unchanged_cmd);
13224 install_element(BGP_EVPN_NODE, &no_neighbor_attr_unchanged_cmd);
13225
13226 /* "nexthop-local unchanged" commands */
13227 install_element(BGP_IPV6_NODE, &neighbor_nexthop_local_unchanged_cmd);
13228 install_element(BGP_IPV6_NODE,
13229 &no_neighbor_nexthop_local_unchanged_cmd);
13230
13231 /* "neighbor next-hop-self" commands. */
13232 install_element(BGP_NODE, &neighbor_nexthop_self_hidden_cmd);
13233 install_element(BGP_NODE, &no_neighbor_nexthop_self_hidden_cmd);
13234 install_element(BGP_IPV4_NODE, &neighbor_nexthop_self_cmd);
13235 install_element(BGP_IPV4_NODE, &no_neighbor_nexthop_self_cmd);
13236 install_element(BGP_IPV4M_NODE, &neighbor_nexthop_self_cmd);
13237 install_element(BGP_IPV4M_NODE, &no_neighbor_nexthop_self_cmd);
13238 install_element(BGP_IPV4L_NODE, &neighbor_nexthop_self_cmd);
13239 install_element(BGP_IPV4L_NODE, &no_neighbor_nexthop_self_cmd);
13240 install_element(BGP_IPV6_NODE, &neighbor_nexthop_self_cmd);
13241 install_element(BGP_IPV6_NODE, &no_neighbor_nexthop_self_cmd);
13242 install_element(BGP_IPV6M_NODE, &neighbor_nexthop_self_cmd);
13243 install_element(BGP_IPV6M_NODE, &no_neighbor_nexthop_self_cmd);
13244 install_element(BGP_IPV6L_NODE, &neighbor_nexthop_self_cmd);
13245 install_element(BGP_IPV6L_NODE, &no_neighbor_nexthop_self_cmd);
13246 install_element(BGP_VPNV4_NODE, &neighbor_nexthop_self_cmd);
13247 install_element(BGP_VPNV4_NODE, &no_neighbor_nexthop_self_cmd);
13248 install_element(BGP_VPNV6_NODE, &neighbor_nexthop_self_cmd);
13249 install_element(BGP_VPNV6_NODE, &no_neighbor_nexthop_self_cmd);
13250 install_element(BGP_EVPN_NODE, &neighbor_nexthop_self_cmd);
13251 install_element(BGP_EVPN_NODE, &no_neighbor_nexthop_self_cmd);
13252
13253 /* "neighbor next-hop-self force" commands. */
13254 install_element(BGP_NODE, &neighbor_nexthop_self_force_hidden_cmd);
13255 install_element(BGP_NODE, &no_neighbor_nexthop_self_force_hidden_cmd);
13256 install_element(BGP_IPV4_NODE, &neighbor_nexthop_self_force_cmd);
13257 install_element(BGP_IPV4_NODE, &no_neighbor_nexthop_self_force_cmd);
13258 install_element(BGP_IPV4M_NODE, &neighbor_nexthop_self_force_cmd);
13259 install_element(BGP_IPV4M_NODE, &no_neighbor_nexthop_self_force_cmd);
13260 install_element(BGP_IPV4L_NODE, &neighbor_nexthop_self_force_cmd);
13261 install_element(BGP_IPV4L_NODE, &no_neighbor_nexthop_self_force_cmd);
13262 install_element(BGP_IPV6_NODE, &neighbor_nexthop_self_force_cmd);
13263 install_element(BGP_IPV6_NODE, &no_neighbor_nexthop_self_force_cmd);
13264 install_element(BGP_IPV6M_NODE, &neighbor_nexthop_self_force_cmd);
13265 install_element(BGP_IPV6M_NODE, &no_neighbor_nexthop_self_force_cmd);
13266 install_element(BGP_IPV6L_NODE, &neighbor_nexthop_self_force_cmd);
13267 install_element(BGP_IPV6L_NODE, &no_neighbor_nexthop_self_force_cmd);
13268 install_element(BGP_VPNV4_NODE, &neighbor_nexthop_self_force_cmd);
13269 install_element(BGP_VPNV4_NODE, &no_neighbor_nexthop_self_force_cmd);
13270 install_element(BGP_VPNV6_NODE, &neighbor_nexthop_self_force_cmd);
13271 install_element(BGP_VPNV6_NODE, &no_neighbor_nexthop_self_force_cmd);
13272
13273 /* "neighbor as-override" commands. */
13274 install_element(BGP_NODE, &neighbor_as_override_hidden_cmd);
13275 install_element(BGP_NODE, &no_neighbor_as_override_hidden_cmd);
13276 install_element(BGP_IPV4_NODE, &neighbor_as_override_cmd);
13277 install_element(BGP_IPV4_NODE, &no_neighbor_as_override_cmd);
13278 install_element(BGP_IPV4M_NODE, &neighbor_as_override_cmd);
13279 install_element(BGP_IPV4M_NODE, &no_neighbor_as_override_cmd);
13280 install_element(BGP_IPV4L_NODE, &neighbor_as_override_cmd);
13281 install_element(BGP_IPV4L_NODE, &no_neighbor_as_override_cmd);
13282 install_element(BGP_IPV6_NODE, &neighbor_as_override_cmd);
13283 install_element(BGP_IPV6_NODE, &no_neighbor_as_override_cmd);
13284 install_element(BGP_IPV6M_NODE, &neighbor_as_override_cmd);
13285 install_element(BGP_IPV6M_NODE, &no_neighbor_as_override_cmd);
13286 install_element(BGP_IPV6L_NODE, &neighbor_as_override_cmd);
13287 install_element(BGP_IPV6L_NODE, &no_neighbor_as_override_cmd);
13288 install_element(BGP_VPNV4_NODE, &neighbor_as_override_cmd);
13289 install_element(BGP_VPNV4_NODE, &no_neighbor_as_override_cmd);
13290 install_element(BGP_VPNV6_NODE, &neighbor_as_override_cmd);
13291 install_element(BGP_VPNV6_NODE, &no_neighbor_as_override_cmd);
13292
13293 /* "neighbor remove-private-AS" commands. */
13294 install_element(BGP_NODE, &neighbor_remove_private_as_hidden_cmd);
13295 install_element(BGP_NODE, &no_neighbor_remove_private_as_hidden_cmd);
13296 install_element(BGP_NODE, &neighbor_remove_private_as_all_hidden_cmd);
13297 install_element(BGP_NODE,
13298 &no_neighbor_remove_private_as_all_hidden_cmd);
13299 install_element(BGP_NODE,
13300 &neighbor_remove_private_as_replace_as_hidden_cmd);
13301 install_element(BGP_NODE,
13302 &no_neighbor_remove_private_as_replace_as_hidden_cmd);
13303 install_element(BGP_NODE,
13304 &neighbor_remove_private_as_all_replace_as_hidden_cmd);
13305 install_element(
13306 BGP_NODE,
13307 &no_neighbor_remove_private_as_all_replace_as_hidden_cmd);
13308 install_element(BGP_IPV4_NODE, &neighbor_remove_private_as_cmd);
13309 install_element(BGP_IPV4_NODE, &no_neighbor_remove_private_as_cmd);
13310 install_element(BGP_IPV4_NODE, &neighbor_remove_private_as_all_cmd);
13311 install_element(BGP_IPV4_NODE, &no_neighbor_remove_private_as_all_cmd);
13312 install_element(BGP_IPV4_NODE,
13313 &neighbor_remove_private_as_replace_as_cmd);
13314 install_element(BGP_IPV4_NODE,
13315 &no_neighbor_remove_private_as_replace_as_cmd);
13316 install_element(BGP_IPV4_NODE,
13317 &neighbor_remove_private_as_all_replace_as_cmd);
13318 install_element(BGP_IPV4_NODE,
13319 &no_neighbor_remove_private_as_all_replace_as_cmd);
13320 install_element(BGP_IPV4M_NODE, &neighbor_remove_private_as_cmd);
13321 install_element(BGP_IPV4M_NODE, &no_neighbor_remove_private_as_cmd);
13322 install_element(BGP_IPV4M_NODE, &neighbor_remove_private_as_all_cmd);
13323 install_element(BGP_IPV4M_NODE, &no_neighbor_remove_private_as_all_cmd);
13324 install_element(BGP_IPV4M_NODE,
13325 &neighbor_remove_private_as_replace_as_cmd);
13326 install_element(BGP_IPV4M_NODE,
13327 &no_neighbor_remove_private_as_replace_as_cmd);
13328 install_element(BGP_IPV4M_NODE,
13329 &neighbor_remove_private_as_all_replace_as_cmd);
13330 install_element(BGP_IPV4M_NODE,
13331 &no_neighbor_remove_private_as_all_replace_as_cmd);
13332 install_element(BGP_IPV4L_NODE, &neighbor_remove_private_as_cmd);
13333 install_element(BGP_IPV4L_NODE, &no_neighbor_remove_private_as_cmd);
13334 install_element(BGP_IPV4L_NODE, &neighbor_remove_private_as_all_cmd);
13335 install_element(BGP_IPV4L_NODE, &no_neighbor_remove_private_as_all_cmd);
13336 install_element(BGP_IPV4L_NODE,
13337 &neighbor_remove_private_as_replace_as_cmd);
13338 install_element(BGP_IPV4L_NODE,
13339 &no_neighbor_remove_private_as_replace_as_cmd);
13340 install_element(BGP_IPV4L_NODE,
13341 &neighbor_remove_private_as_all_replace_as_cmd);
13342 install_element(BGP_IPV4L_NODE,
13343 &no_neighbor_remove_private_as_all_replace_as_cmd);
13344 install_element(BGP_IPV6_NODE, &neighbor_remove_private_as_cmd);
13345 install_element(BGP_IPV6_NODE, &no_neighbor_remove_private_as_cmd);
13346 install_element(BGP_IPV6_NODE, &neighbor_remove_private_as_all_cmd);
13347 install_element(BGP_IPV6_NODE, &no_neighbor_remove_private_as_all_cmd);
13348 install_element(BGP_IPV6_NODE,
13349 &neighbor_remove_private_as_replace_as_cmd);
13350 install_element(BGP_IPV6_NODE,
13351 &no_neighbor_remove_private_as_replace_as_cmd);
13352 install_element(BGP_IPV6_NODE,
13353 &neighbor_remove_private_as_all_replace_as_cmd);
13354 install_element(BGP_IPV6_NODE,
13355 &no_neighbor_remove_private_as_all_replace_as_cmd);
13356 install_element(BGP_IPV6M_NODE, &neighbor_remove_private_as_cmd);
13357 install_element(BGP_IPV6M_NODE, &no_neighbor_remove_private_as_cmd);
13358 install_element(BGP_IPV6M_NODE, &neighbor_remove_private_as_all_cmd);
13359 install_element(BGP_IPV6M_NODE, &no_neighbor_remove_private_as_all_cmd);
13360 install_element(BGP_IPV6M_NODE,
13361 &neighbor_remove_private_as_replace_as_cmd);
13362 install_element(BGP_IPV6M_NODE,
13363 &no_neighbor_remove_private_as_replace_as_cmd);
13364 install_element(BGP_IPV6M_NODE,
13365 &neighbor_remove_private_as_all_replace_as_cmd);
13366 install_element(BGP_IPV6M_NODE,
13367 &no_neighbor_remove_private_as_all_replace_as_cmd);
13368 install_element(BGP_IPV6L_NODE, &neighbor_remove_private_as_cmd);
13369 install_element(BGP_IPV6L_NODE, &no_neighbor_remove_private_as_cmd);
13370 install_element(BGP_IPV6L_NODE, &neighbor_remove_private_as_all_cmd);
13371 install_element(BGP_IPV6L_NODE, &no_neighbor_remove_private_as_all_cmd);
13372 install_element(BGP_IPV6L_NODE,
13373 &neighbor_remove_private_as_replace_as_cmd);
13374 install_element(BGP_IPV6L_NODE,
13375 &no_neighbor_remove_private_as_replace_as_cmd);
13376 install_element(BGP_IPV6L_NODE,
13377 &neighbor_remove_private_as_all_replace_as_cmd);
13378 install_element(BGP_IPV6L_NODE,
13379 &no_neighbor_remove_private_as_all_replace_as_cmd);
13380 install_element(BGP_VPNV4_NODE, &neighbor_remove_private_as_cmd);
13381 install_element(BGP_VPNV4_NODE, &no_neighbor_remove_private_as_cmd);
13382 install_element(BGP_VPNV4_NODE, &neighbor_remove_private_as_all_cmd);
13383 install_element(BGP_VPNV4_NODE, &no_neighbor_remove_private_as_all_cmd);
13384 install_element(BGP_VPNV4_NODE,
13385 &neighbor_remove_private_as_replace_as_cmd);
13386 install_element(BGP_VPNV4_NODE,
13387 &no_neighbor_remove_private_as_replace_as_cmd);
13388 install_element(BGP_VPNV4_NODE,
13389 &neighbor_remove_private_as_all_replace_as_cmd);
13390 install_element(BGP_VPNV4_NODE,
13391 &no_neighbor_remove_private_as_all_replace_as_cmd);
13392 install_element(BGP_VPNV6_NODE, &neighbor_remove_private_as_cmd);
13393 install_element(BGP_VPNV6_NODE, &no_neighbor_remove_private_as_cmd);
13394 install_element(BGP_VPNV6_NODE, &neighbor_remove_private_as_all_cmd);
13395 install_element(BGP_VPNV6_NODE, &no_neighbor_remove_private_as_all_cmd);
13396 install_element(BGP_VPNV6_NODE,
13397 &neighbor_remove_private_as_replace_as_cmd);
13398 install_element(BGP_VPNV6_NODE,
13399 &no_neighbor_remove_private_as_replace_as_cmd);
13400 install_element(BGP_VPNV6_NODE,
13401 &neighbor_remove_private_as_all_replace_as_cmd);
13402 install_element(BGP_VPNV6_NODE,
13403 &no_neighbor_remove_private_as_all_replace_as_cmd);
13404
13405 /* "neighbor send-community" commands.*/
13406 install_element(BGP_NODE, &neighbor_send_community_hidden_cmd);
13407 install_element(BGP_NODE, &neighbor_send_community_type_hidden_cmd);
13408 install_element(BGP_NODE, &no_neighbor_send_community_hidden_cmd);
13409 install_element(BGP_NODE, &no_neighbor_send_community_type_hidden_cmd);
13410 install_element(BGP_IPV4_NODE, &neighbor_send_community_cmd);
13411 install_element(BGP_IPV4_NODE, &neighbor_send_community_type_cmd);
13412 install_element(BGP_IPV4_NODE, &no_neighbor_send_community_cmd);
13413 install_element(BGP_IPV4_NODE, &no_neighbor_send_community_type_cmd);
13414 install_element(BGP_IPV4M_NODE, &neighbor_send_community_cmd);
13415 install_element(BGP_IPV4M_NODE, &neighbor_send_community_type_cmd);
13416 install_element(BGP_IPV4M_NODE, &no_neighbor_send_community_cmd);
13417 install_element(BGP_IPV4M_NODE, &no_neighbor_send_community_type_cmd);
13418 install_element(BGP_IPV4L_NODE, &neighbor_send_community_cmd);
13419 install_element(BGP_IPV4L_NODE, &neighbor_send_community_type_cmd);
13420 install_element(BGP_IPV4L_NODE, &no_neighbor_send_community_cmd);
13421 install_element(BGP_IPV4L_NODE, &no_neighbor_send_community_type_cmd);
13422 install_element(BGP_IPV6_NODE, &neighbor_send_community_cmd);
13423 install_element(BGP_IPV6_NODE, &neighbor_send_community_type_cmd);
13424 install_element(BGP_IPV6_NODE, &no_neighbor_send_community_cmd);
13425 install_element(BGP_IPV6_NODE, &no_neighbor_send_community_type_cmd);
13426 install_element(BGP_IPV6M_NODE, &neighbor_send_community_cmd);
13427 install_element(BGP_IPV6M_NODE, &neighbor_send_community_type_cmd);
13428 install_element(BGP_IPV6M_NODE, &no_neighbor_send_community_cmd);
13429 install_element(BGP_IPV6M_NODE, &no_neighbor_send_community_type_cmd);
13430 install_element(BGP_IPV6L_NODE, &neighbor_send_community_cmd);
13431 install_element(BGP_IPV6L_NODE, &neighbor_send_community_type_cmd);
13432 install_element(BGP_IPV6L_NODE, &no_neighbor_send_community_cmd);
13433 install_element(BGP_IPV6L_NODE, &no_neighbor_send_community_type_cmd);
13434 install_element(BGP_VPNV4_NODE, &neighbor_send_community_cmd);
13435 install_element(BGP_VPNV4_NODE, &neighbor_send_community_type_cmd);
13436 install_element(BGP_VPNV4_NODE, &no_neighbor_send_community_cmd);
13437 install_element(BGP_VPNV4_NODE, &no_neighbor_send_community_type_cmd);
13438 install_element(BGP_VPNV6_NODE, &neighbor_send_community_cmd);
13439 install_element(BGP_VPNV6_NODE, &neighbor_send_community_type_cmd);
13440 install_element(BGP_VPNV6_NODE, &no_neighbor_send_community_cmd);
13441 install_element(BGP_VPNV6_NODE, &no_neighbor_send_community_type_cmd);
13442
13443 /* "neighbor route-reflector" commands.*/
13444 install_element(BGP_NODE, &neighbor_route_reflector_client_hidden_cmd);
13445 install_element(BGP_NODE,
13446 &no_neighbor_route_reflector_client_hidden_cmd);
13447 install_element(BGP_IPV4_NODE, &neighbor_route_reflector_client_cmd);
13448 install_element(BGP_IPV4_NODE, &no_neighbor_route_reflector_client_cmd);
13449 install_element(BGP_IPV4M_NODE, &neighbor_route_reflector_client_cmd);
13450 install_element(BGP_IPV4M_NODE,
13451 &no_neighbor_route_reflector_client_cmd);
13452 install_element(BGP_IPV4L_NODE, &neighbor_route_reflector_client_cmd);
13453 install_element(BGP_IPV4L_NODE,
13454 &no_neighbor_route_reflector_client_cmd);
13455 install_element(BGP_IPV6_NODE, &neighbor_route_reflector_client_cmd);
13456 install_element(BGP_IPV6_NODE, &no_neighbor_route_reflector_client_cmd);
13457 install_element(BGP_IPV6M_NODE, &neighbor_route_reflector_client_cmd);
13458 install_element(BGP_IPV6M_NODE,
13459 &no_neighbor_route_reflector_client_cmd);
13460 install_element(BGP_IPV6L_NODE, &neighbor_route_reflector_client_cmd);
13461 install_element(BGP_IPV6L_NODE,
13462 &no_neighbor_route_reflector_client_cmd);
13463 install_element(BGP_VPNV4_NODE, &neighbor_route_reflector_client_cmd);
13464 install_element(BGP_VPNV4_NODE,
13465 &no_neighbor_route_reflector_client_cmd);
13466 install_element(BGP_VPNV6_NODE, &neighbor_route_reflector_client_cmd);
13467 install_element(BGP_VPNV6_NODE,
13468 &no_neighbor_route_reflector_client_cmd);
13469 install_element(BGP_FLOWSPECV4_NODE,
13470 &neighbor_route_reflector_client_cmd);
13471 install_element(BGP_FLOWSPECV4_NODE,
13472 &no_neighbor_route_reflector_client_cmd);
13473 install_element(BGP_FLOWSPECV6_NODE,
13474 &neighbor_route_reflector_client_cmd);
13475 install_element(BGP_FLOWSPECV6_NODE,
13476 &no_neighbor_route_reflector_client_cmd);
13477 install_element(BGP_EVPN_NODE, &neighbor_route_reflector_client_cmd);
13478 install_element(BGP_EVPN_NODE, &no_neighbor_route_reflector_client_cmd);
13479
13480 /* "neighbor route-server" commands.*/
13481 install_element(BGP_NODE, &neighbor_route_server_client_hidden_cmd);
13482 install_element(BGP_NODE, &no_neighbor_route_server_client_hidden_cmd);
13483 install_element(BGP_IPV4_NODE, &neighbor_route_server_client_cmd);
13484 install_element(BGP_IPV4_NODE, &no_neighbor_route_server_client_cmd);
13485 install_element(BGP_IPV4M_NODE, &neighbor_route_server_client_cmd);
13486 install_element(BGP_IPV4M_NODE, &no_neighbor_route_server_client_cmd);
13487 install_element(BGP_IPV4L_NODE, &neighbor_route_server_client_cmd);
13488 install_element(BGP_IPV4L_NODE, &no_neighbor_route_server_client_cmd);
13489 install_element(BGP_IPV6_NODE, &neighbor_route_server_client_cmd);
13490 install_element(BGP_IPV6_NODE, &no_neighbor_route_server_client_cmd);
13491 install_element(BGP_IPV6M_NODE, &neighbor_route_server_client_cmd);
13492 install_element(BGP_IPV6M_NODE, &no_neighbor_route_server_client_cmd);
13493 install_element(BGP_IPV6L_NODE, &neighbor_route_server_client_cmd);
13494 install_element(BGP_IPV6L_NODE, &no_neighbor_route_server_client_cmd);
13495 install_element(BGP_VPNV4_NODE, &neighbor_route_server_client_cmd);
13496 install_element(BGP_VPNV4_NODE, &no_neighbor_route_server_client_cmd);
13497 install_element(BGP_VPNV6_NODE, &neighbor_route_server_client_cmd);
13498 install_element(BGP_VPNV6_NODE, &no_neighbor_route_server_client_cmd);
13499 install_element(BGP_EVPN_NODE, &neighbor_route_server_client_cmd);
13500 install_element(BGP_EVPN_NODE, &no_neighbor_route_server_client_cmd);
13501 install_element(BGP_FLOWSPECV4_NODE, &neighbor_route_server_client_cmd);
13502 install_element(BGP_FLOWSPECV4_NODE,
13503 &no_neighbor_route_server_client_cmd);
13504 install_element(BGP_FLOWSPECV6_NODE, &neighbor_route_server_client_cmd);
13505 install_element(BGP_FLOWSPECV6_NODE,
13506 &no_neighbor_route_server_client_cmd);
13507
13508 /* "neighbor addpath-tx-all-paths" commands.*/
13509 install_element(BGP_NODE, &neighbor_addpath_tx_all_paths_hidden_cmd);
13510 install_element(BGP_NODE, &no_neighbor_addpath_tx_all_paths_hidden_cmd);
13511 install_element(BGP_IPV4_NODE, &neighbor_addpath_tx_all_paths_cmd);
13512 install_element(BGP_IPV4_NODE, &no_neighbor_addpath_tx_all_paths_cmd);
13513 install_element(BGP_IPV4M_NODE, &neighbor_addpath_tx_all_paths_cmd);
13514 install_element(BGP_IPV4M_NODE, &no_neighbor_addpath_tx_all_paths_cmd);
13515 install_element(BGP_IPV4L_NODE, &neighbor_addpath_tx_all_paths_cmd);
13516 install_element(BGP_IPV4L_NODE, &no_neighbor_addpath_tx_all_paths_cmd);
13517 install_element(BGP_IPV6_NODE, &neighbor_addpath_tx_all_paths_cmd);
13518 install_element(BGP_IPV6_NODE, &no_neighbor_addpath_tx_all_paths_cmd);
13519 install_element(BGP_IPV6M_NODE, &neighbor_addpath_tx_all_paths_cmd);
13520 install_element(BGP_IPV6M_NODE, &no_neighbor_addpath_tx_all_paths_cmd);
13521 install_element(BGP_IPV6L_NODE, &neighbor_addpath_tx_all_paths_cmd);
13522 install_element(BGP_IPV6L_NODE, &no_neighbor_addpath_tx_all_paths_cmd);
13523 install_element(BGP_VPNV4_NODE, &neighbor_addpath_tx_all_paths_cmd);
13524 install_element(BGP_VPNV4_NODE, &no_neighbor_addpath_tx_all_paths_cmd);
13525 install_element(BGP_VPNV6_NODE, &neighbor_addpath_tx_all_paths_cmd);
13526 install_element(BGP_VPNV6_NODE, &no_neighbor_addpath_tx_all_paths_cmd);
13527
13528 /* "neighbor addpath-tx-bestpath-per-AS" commands.*/
13529 install_element(BGP_NODE,
13530 &neighbor_addpath_tx_bestpath_per_as_hidden_cmd);
13531 install_element(BGP_NODE,
13532 &no_neighbor_addpath_tx_bestpath_per_as_hidden_cmd);
13533 install_element(BGP_IPV4_NODE,
13534 &neighbor_addpath_tx_bestpath_per_as_cmd);
13535 install_element(BGP_IPV4_NODE,
13536 &no_neighbor_addpath_tx_bestpath_per_as_cmd);
13537 install_element(BGP_IPV4M_NODE,
13538 &neighbor_addpath_tx_bestpath_per_as_cmd);
13539 install_element(BGP_IPV4M_NODE,
13540 &no_neighbor_addpath_tx_bestpath_per_as_cmd);
13541 install_element(BGP_IPV4L_NODE,
13542 &neighbor_addpath_tx_bestpath_per_as_cmd);
13543 install_element(BGP_IPV4L_NODE,
13544 &no_neighbor_addpath_tx_bestpath_per_as_cmd);
13545 install_element(BGP_IPV6_NODE,
13546 &neighbor_addpath_tx_bestpath_per_as_cmd);
13547 install_element(BGP_IPV6_NODE,
13548 &no_neighbor_addpath_tx_bestpath_per_as_cmd);
13549 install_element(BGP_IPV6M_NODE,
13550 &neighbor_addpath_tx_bestpath_per_as_cmd);
13551 install_element(BGP_IPV6M_NODE,
13552 &no_neighbor_addpath_tx_bestpath_per_as_cmd);
13553 install_element(BGP_IPV6L_NODE,
13554 &neighbor_addpath_tx_bestpath_per_as_cmd);
13555 install_element(BGP_IPV6L_NODE,
13556 &no_neighbor_addpath_tx_bestpath_per_as_cmd);
13557 install_element(BGP_VPNV4_NODE,
13558 &neighbor_addpath_tx_bestpath_per_as_cmd);
13559 install_element(BGP_VPNV4_NODE,
13560 &no_neighbor_addpath_tx_bestpath_per_as_cmd);
13561 install_element(BGP_VPNV6_NODE,
13562 &neighbor_addpath_tx_bestpath_per_as_cmd);
13563 install_element(BGP_VPNV6_NODE,
13564 &no_neighbor_addpath_tx_bestpath_per_as_cmd);
13565
13566 /* "neighbor passive" commands. */
13567 install_element(BGP_NODE, &neighbor_passive_cmd);
13568 install_element(BGP_NODE, &no_neighbor_passive_cmd);
13569
13570
13571 /* "neighbor shutdown" commands. */
13572 install_element(BGP_NODE, &neighbor_shutdown_cmd);
13573 install_element(BGP_NODE, &no_neighbor_shutdown_cmd);
13574 install_element(BGP_NODE, &neighbor_shutdown_msg_cmd);
13575 install_element(BGP_NODE, &no_neighbor_shutdown_msg_cmd);
13576
13577 /* "neighbor capability extended-nexthop" commands.*/
13578 install_element(BGP_NODE, &neighbor_capability_enhe_cmd);
13579 install_element(BGP_NODE, &no_neighbor_capability_enhe_cmd);
13580
13581 /* "neighbor capability orf prefix-list" commands.*/
13582 install_element(BGP_NODE, &neighbor_capability_orf_prefix_hidden_cmd);
13583 install_element(BGP_NODE,
13584 &no_neighbor_capability_orf_prefix_hidden_cmd);
13585 install_element(BGP_IPV4_NODE, &neighbor_capability_orf_prefix_cmd);
13586 install_element(BGP_IPV4_NODE, &no_neighbor_capability_orf_prefix_cmd);
13587 install_element(BGP_IPV4M_NODE, &neighbor_capability_orf_prefix_cmd);
13588 install_element(BGP_IPV4M_NODE, &no_neighbor_capability_orf_prefix_cmd);
13589 install_element(BGP_IPV4L_NODE, &neighbor_capability_orf_prefix_cmd);
13590 install_element(BGP_IPV4L_NODE, &no_neighbor_capability_orf_prefix_cmd);
13591 install_element(BGP_IPV6_NODE, &neighbor_capability_orf_prefix_cmd);
13592 install_element(BGP_IPV6_NODE, &no_neighbor_capability_orf_prefix_cmd);
13593 install_element(BGP_IPV6M_NODE, &neighbor_capability_orf_prefix_cmd);
13594 install_element(BGP_IPV6M_NODE, &no_neighbor_capability_orf_prefix_cmd);
13595 install_element(BGP_IPV6L_NODE, &neighbor_capability_orf_prefix_cmd);
13596 install_element(BGP_IPV6L_NODE, &no_neighbor_capability_orf_prefix_cmd);
13597
13598 /* "neighbor capability dynamic" commands.*/
13599 install_element(BGP_NODE, &neighbor_capability_dynamic_cmd);
13600 install_element(BGP_NODE, &no_neighbor_capability_dynamic_cmd);
13601
13602 /* "neighbor dont-capability-negotiate" commands. */
13603 install_element(BGP_NODE, &neighbor_dont_capability_negotiate_cmd);
13604 install_element(BGP_NODE, &no_neighbor_dont_capability_negotiate_cmd);
13605
13606 /* "neighbor ebgp-multihop" commands. */
13607 install_element(BGP_NODE, &neighbor_ebgp_multihop_cmd);
13608 install_element(BGP_NODE, &neighbor_ebgp_multihop_ttl_cmd);
13609 install_element(BGP_NODE, &no_neighbor_ebgp_multihop_cmd);
13610
13611 /* "neighbor disable-connected-check" commands. */
13612 install_element(BGP_NODE, &neighbor_disable_connected_check_cmd);
13613 install_element(BGP_NODE, &no_neighbor_disable_connected_check_cmd);
13614
13615 /* "neighbor enforce-first-as" commands. */
13616 install_element(BGP_NODE, &neighbor_enforce_first_as_cmd);
13617 install_element(BGP_NODE, &no_neighbor_enforce_first_as_cmd);
13618
13619 /* "neighbor description" commands. */
13620 install_element(BGP_NODE, &neighbor_description_cmd);
13621 install_element(BGP_NODE, &no_neighbor_description_cmd);
13622 install_element(BGP_NODE, &no_neighbor_description_comment_cmd);
13623
13624 /* "neighbor update-source" commands. "*/
13625 install_element(BGP_NODE, &neighbor_update_source_cmd);
13626 install_element(BGP_NODE, &no_neighbor_update_source_cmd);
13627
13628 /* "neighbor default-originate" commands. */
13629 install_element(BGP_NODE, &neighbor_default_originate_hidden_cmd);
13630 install_element(BGP_NODE, &neighbor_default_originate_rmap_hidden_cmd);
13631 install_element(BGP_NODE, &no_neighbor_default_originate_hidden_cmd);
13632 install_element(BGP_IPV4_NODE, &neighbor_default_originate_cmd);
13633 install_element(BGP_IPV4_NODE, &neighbor_default_originate_rmap_cmd);
13634 install_element(BGP_IPV4_NODE, &no_neighbor_default_originate_cmd);
13635 install_element(BGP_IPV4M_NODE, &neighbor_default_originate_cmd);
13636 install_element(BGP_IPV4M_NODE, &neighbor_default_originate_rmap_cmd);
13637 install_element(BGP_IPV4M_NODE, &no_neighbor_default_originate_cmd);
13638 install_element(BGP_IPV4L_NODE, &neighbor_default_originate_cmd);
13639 install_element(BGP_IPV4L_NODE, &neighbor_default_originate_rmap_cmd);
13640 install_element(BGP_IPV4L_NODE, &no_neighbor_default_originate_cmd);
13641 install_element(BGP_IPV6_NODE, &neighbor_default_originate_cmd);
13642 install_element(BGP_IPV6_NODE, &neighbor_default_originate_rmap_cmd);
13643 install_element(BGP_IPV6_NODE, &no_neighbor_default_originate_cmd);
13644 install_element(BGP_IPV6M_NODE, &neighbor_default_originate_cmd);
13645 install_element(BGP_IPV6M_NODE, &neighbor_default_originate_rmap_cmd);
13646 install_element(BGP_IPV6M_NODE, &no_neighbor_default_originate_cmd);
13647 install_element(BGP_IPV6L_NODE, &neighbor_default_originate_cmd);
13648 install_element(BGP_IPV6L_NODE, &neighbor_default_originate_rmap_cmd);
13649 install_element(BGP_IPV6L_NODE, &no_neighbor_default_originate_cmd);
13650
13651 /* "neighbor port" commands. */
13652 install_element(BGP_NODE, &neighbor_port_cmd);
13653 install_element(BGP_NODE, &no_neighbor_port_cmd);
13654
13655 /* "neighbor weight" commands. */
13656 install_element(BGP_NODE, &neighbor_weight_hidden_cmd);
13657 install_element(BGP_NODE, &no_neighbor_weight_hidden_cmd);
13658
13659 install_element(BGP_IPV4_NODE, &neighbor_weight_cmd);
13660 install_element(BGP_IPV4_NODE, &no_neighbor_weight_cmd);
13661 install_element(BGP_IPV4M_NODE, &neighbor_weight_cmd);
13662 install_element(BGP_IPV4M_NODE, &no_neighbor_weight_cmd);
13663 install_element(BGP_IPV4L_NODE, &neighbor_weight_cmd);
13664 install_element(BGP_IPV4L_NODE, &no_neighbor_weight_cmd);
13665 install_element(BGP_IPV6_NODE, &neighbor_weight_cmd);
13666 install_element(BGP_IPV6_NODE, &no_neighbor_weight_cmd);
13667 install_element(BGP_IPV6M_NODE, &neighbor_weight_cmd);
13668 install_element(BGP_IPV6M_NODE, &no_neighbor_weight_cmd);
13669 install_element(BGP_IPV6L_NODE, &neighbor_weight_cmd);
13670 install_element(BGP_IPV6L_NODE, &no_neighbor_weight_cmd);
13671 install_element(BGP_VPNV4_NODE, &neighbor_weight_cmd);
13672 install_element(BGP_VPNV4_NODE, &no_neighbor_weight_cmd);
13673 install_element(BGP_VPNV6_NODE, &neighbor_weight_cmd);
13674 install_element(BGP_VPNV6_NODE, &no_neighbor_weight_cmd);
13675
13676 /* "neighbor override-capability" commands. */
13677 install_element(BGP_NODE, &neighbor_override_capability_cmd);
13678 install_element(BGP_NODE, &no_neighbor_override_capability_cmd);
13679
13680 /* "neighbor strict-capability-match" commands. */
13681 install_element(BGP_NODE, &neighbor_strict_capability_cmd);
13682 install_element(BGP_NODE, &no_neighbor_strict_capability_cmd);
13683
13684 /* "neighbor timers" commands. */
13685 install_element(BGP_NODE, &neighbor_timers_cmd);
13686 install_element(BGP_NODE, &no_neighbor_timers_cmd);
13687
13688 /* "neighbor timers connect" commands. */
13689 install_element(BGP_NODE, &neighbor_timers_connect_cmd);
13690 install_element(BGP_NODE, &no_neighbor_timers_connect_cmd);
13691
13692 /* "neighbor advertisement-interval" commands. */
13693 install_element(BGP_NODE, &neighbor_advertise_interval_cmd);
13694 install_element(BGP_NODE, &no_neighbor_advertise_interval_cmd);
13695
13696 /* "neighbor interface" commands. */
13697 install_element(BGP_NODE, &neighbor_interface_cmd);
13698 install_element(BGP_NODE, &no_neighbor_interface_cmd);
13699
13700 /* "neighbor distribute" commands. */
13701 install_element(BGP_NODE, &neighbor_distribute_list_hidden_cmd);
13702 install_element(BGP_NODE, &no_neighbor_distribute_list_hidden_cmd);
13703 install_element(BGP_IPV4_NODE, &neighbor_distribute_list_cmd);
13704 install_element(BGP_IPV4_NODE, &no_neighbor_distribute_list_cmd);
13705 install_element(BGP_IPV4M_NODE, &neighbor_distribute_list_cmd);
13706 install_element(BGP_IPV4M_NODE, &no_neighbor_distribute_list_cmd);
13707 install_element(BGP_IPV4L_NODE, &neighbor_distribute_list_cmd);
13708 install_element(BGP_IPV4L_NODE, &no_neighbor_distribute_list_cmd);
13709 install_element(BGP_IPV6_NODE, &neighbor_distribute_list_cmd);
13710 install_element(BGP_IPV6_NODE, &no_neighbor_distribute_list_cmd);
13711 install_element(BGP_IPV6M_NODE, &neighbor_distribute_list_cmd);
13712 install_element(BGP_IPV6M_NODE, &no_neighbor_distribute_list_cmd);
13713 install_element(BGP_IPV6L_NODE, &neighbor_distribute_list_cmd);
13714 install_element(BGP_IPV6L_NODE, &no_neighbor_distribute_list_cmd);
13715 install_element(BGP_VPNV4_NODE, &neighbor_distribute_list_cmd);
13716 install_element(BGP_VPNV4_NODE, &no_neighbor_distribute_list_cmd);
13717 install_element(BGP_VPNV6_NODE, &neighbor_distribute_list_cmd);
13718 install_element(BGP_VPNV6_NODE, &no_neighbor_distribute_list_cmd);
13719
13720 /* "neighbor prefix-list" commands. */
13721 install_element(BGP_NODE, &neighbor_prefix_list_hidden_cmd);
13722 install_element(BGP_NODE, &no_neighbor_prefix_list_hidden_cmd);
13723 install_element(BGP_IPV4_NODE, &neighbor_prefix_list_cmd);
13724 install_element(BGP_IPV4_NODE, &no_neighbor_prefix_list_cmd);
13725 install_element(BGP_IPV4M_NODE, &neighbor_prefix_list_cmd);
13726 install_element(BGP_IPV4M_NODE, &no_neighbor_prefix_list_cmd);
13727 install_element(BGP_IPV4L_NODE, &neighbor_prefix_list_cmd);
13728 install_element(BGP_IPV4L_NODE, &no_neighbor_prefix_list_cmd);
13729 install_element(BGP_IPV6_NODE, &neighbor_prefix_list_cmd);
13730 install_element(BGP_IPV6_NODE, &no_neighbor_prefix_list_cmd);
13731 install_element(BGP_IPV6M_NODE, &neighbor_prefix_list_cmd);
13732 install_element(BGP_IPV6M_NODE, &no_neighbor_prefix_list_cmd);
13733 install_element(BGP_IPV6L_NODE, &neighbor_prefix_list_cmd);
13734 install_element(BGP_IPV6L_NODE, &no_neighbor_prefix_list_cmd);
13735 install_element(BGP_VPNV4_NODE, &neighbor_prefix_list_cmd);
13736 install_element(BGP_VPNV4_NODE, &no_neighbor_prefix_list_cmd);
13737 install_element(BGP_VPNV6_NODE, &neighbor_prefix_list_cmd);
13738 install_element(BGP_VPNV6_NODE, &no_neighbor_prefix_list_cmd);
13739 install_element(BGP_FLOWSPECV4_NODE, &neighbor_prefix_list_cmd);
13740 install_element(BGP_FLOWSPECV4_NODE, &no_neighbor_prefix_list_cmd);
13741 install_element(BGP_FLOWSPECV6_NODE, &neighbor_prefix_list_cmd);
13742 install_element(BGP_FLOWSPECV6_NODE, &no_neighbor_prefix_list_cmd);
13743
13744 /* "neighbor filter-list" commands. */
13745 install_element(BGP_NODE, &neighbor_filter_list_hidden_cmd);
13746 install_element(BGP_NODE, &no_neighbor_filter_list_hidden_cmd);
13747 install_element(BGP_IPV4_NODE, &neighbor_filter_list_cmd);
13748 install_element(BGP_IPV4_NODE, &no_neighbor_filter_list_cmd);
13749 install_element(BGP_IPV4M_NODE, &neighbor_filter_list_cmd);
13750 install_element(BGP_IPV4M_NODE, &no_neighbor_filter_list_cmd);
13751 install_element(BGP_IPV4L_NODE, &neighbor_filter_list_cmd);
13752 install_element(BGP_IPV4L_NODE, &no_neighbor_filter_list_cmd);
13753 install_element(BGP_IPV6_NODE, &neighbor_filter_list_cmd);
13754 install_element(BGP_IPV6_NODE, &no_neighbor_filter_list_cmd);
13755 install_element(BGP_IPV6M_NODE, &neighbor_filter_list_cmd);
13756 install_element(BGP_IPV6M_NODE, &no_neighbor_filter_list_cmd);
13757 install_element(BGP_IPV6L_NODE, &neighbor_filter_list_cmd);
13758 install_element(BGP_IPV6L_NODE, &no_neighbor_filter_list_cmd);
13759 install_element(BGP_VPNV4_NODE, &neighbor_filter_list_cmd);
13760 install_element(BGP_VPNV4_NODE, &no_neighbor_filter_list_cmd);
13761 install_element(BGP_VPNV6_NODE, &neighbor_filter_list_cmd);
13762 install_element(BGP_VPNV6_NODE, &no_neighbor_filter_list_cmd);
13763 install_element(BGP_FLOWSPECV4_NODE, &neighbor_filter_list_cmd);
13764 install_element(BGP_FLOWSPECV4_NODE, &no_neighbor_filter_list_cmd);
13765 install_element(BGP_FLOWSPECV6_NODE, &neighbor_filter_list_cmd);
13766 install_element(BGP_FLOWSPECV6_NODE, &no_neighbor_filter_list_cmd);
13767
13768 /* "neighbor route-map" commands. */
13769 install_element(BGP_NODE, &neighbor_route_map_hidden_cmd);
13770 install_element(BGP_NODE, &no_neighbor_route_map_hidden_cmd);
13771 install_element(BGP_IPV4_NODE, &neighbor_route_map_cmd);
13772 install_element(BGP_IPV4_NODE, &no_neighbor_route_map_cmd);
13773 install_element(BGP_IPV4M_NODE, &neighbor_route_map_cmd);
13774 install_element(BGP_IPV4M_NODE, &no_neighbor_route_map_cmd);
13775 install_element(BGP_IPV4L_NODE, &neighbor_route_map_cmd);
13776 install_element(BGP_IPV4L_NODE, &no_neighbor_route_map_cmd);
13777 install_element(BGP_IPV6_NODE, &neighbor_route_map_cmd);
13778 install_element(BGP_IPV6_NODE, &no_neighbor_route_map_cmd);
13779 install_element(BGP_IPV6M_NODE, &neighbor_route_map_cmd);
13780 install_element(BGP_IPV6M_NODE, &no_neighbor_route_map_cmd);
13781 install_element(BGP_IPV6L_NODE, &neighbor_route_map_cmd);
13782 install_element(BGP_IPV6L_NODE, &no_neighbor_route_map_cmd);
13783 install_element(BGP_VPNV4_NODE, &neighbor_route_map_cmd);
13784 install_element(BGP_VPNV4_NODE, &no_neighbor_route_map_cmd);
13785 install_element(BGP_VPNV6_NODE, &neighbor_route_map_cmd);
13786 install_element(BGP_VPNV6_NODE, &no_neighbor_route_map_cmd);
13787 install_element(BGP_FLOWSPECV4_NODE, &neighbor_route_map_cmd);
13788 install_element(BGP_FLOWSPECV4_NODE, &no_neighbor_route_map_cmd);
13789 install_element(BGP_FLOWSPECV6_NODE, &neighbor_route_map_cmd);
13790 install_element(BGP_FLOWSPECV6_NODE, &no_neighbor_route_map_cmd);
13791 install_element(BGP_EVPN_NODE, &neighbor_route_map_cmd);
13792 install_element(BGP_EVPN_NODE, &no_neighbor_route_map_cmd);
13793
13794 /* "neighbor unsuppress-map" commands. */
13795 install_element(BGP_NODE, &neighbor_unsuppress_map_hidden_cmd);
13796 install_element(BGP_NODE, &no_neighbor_unsuppress_map_hidden_cmd);
13797 install_element(BGP_IPV4_NODE, &neighbor_unsuppress_map_cmd);
13798 install_element(BGP_IPV4_NODE, &no_neighbor_unsuppress_map_cmd);
13799 install_element(BGP_IPV4M_NODE, &neighbor_unsuppress_map_cmd);
13800 install_element(BGP_IPV4M_NODE, &no_neighbor_unsuppress_map_cmd);
13801 install_element(BGP_IPV4L_NODE, &neighbor_unsuppress_map_cmd);
13802 install_element(BGP_IPV4L_NODE, &no_neighbor_unsuppress_map_cmd);
13803 install_element(BGP_IPV6_NODE, &neighbor_unsuppress_map_cmd);
13804 install_element(BGP_IPV6_NODE, &no_neighbor_unsuppress_map_cmd);
13805 install_element(BGP_IPV6M_NODE, &neighbor_unsuppress_map_cmd);
13806 install_element(BGP_IPV6M_NODE, &no_neighbor_unsuppress_map_cmd);
13807 install_element(BGP_IPV6L_NODE, &neighbor_unsuppress_map_cmd);
13808 install_element(BGP_IPV6L_NODE, &no_neighbor_unsuppress_map_cmd);
13809 install_element(BGP_VPNV4_NODE, &neighbor_unsuppress_map_cmd);
13810 install_element(BGP_VPNV4_NODE, &no_neighbor_unsuppress_map_cmd);
13811 install_element(BGP_VPNV6_NODE, &neighbor_unsuppress_map_cmd);
13812 install_element(BGP_VPNV6_NODE, &no_neighbor_unsuppress_map_cmd);
13813
13814 /* "neighbor maximum-prefix" commands. */
13815 install_element(BGP_NODE, &neighbor_maximum_prefix_hidden_cmd);
13816 install_element(BGP_NODE,
13817 &neighbor_maximum_prefix_threshold_hidden_cmd);
13818 install_element(BGP_NODE, &neighbor_maximum_prefix_warning_hidden_cmd);
13819 install_element(BGP_NODE,
13820 &neighbor_maximum_prefix_threshold_warning_hidden_cmd);
13821 install_element(BGP_NODE, &neighbor_maximum_prefix_restart_hidden_cmd);
13822 install_element(BGP_NODE,
13823 &neighbor_maximum_prefix_threshold_restart_hidden_cmd);
13824 install_element(BGP_NODE, &no_neighbor_maximum_prefix_hidden_cmd);
13825 install_element(BGP_IPV4_NODE, &neighbor_maximum_prefix_cmd);
13826 install_element(BGP_IPV4_NODE, &neighbor_maximum_prefix_threshold_cmd);
13827 install_element(BGP_IPV4_NODE, &neighbor_maximum_prefix_warning_cmd);
13828 install_element(BGP_IPV4_NODE,
13829 &neighbor_maximum_prefix_threshold_warning_cmd);
13830 install_element(BGP_IPV4_NODE, &neighbor_maximum_prefix_restart_cmd);
13831 install_element(BGP_IPV4_NODE,
13832 &neighbor_maximum_prefix_threshold_restart_cmd);
13833 install_element(BGP_IPV4_NODE, &no_neighbor_maximum_prefix_cmd);
13834 install_element(BGP_IPV4M_NODE, &neighbor_maximum_prefix_cmd);
13835 install_element(BGP_IPV4M_NODE, &neighbor_maximum_prefix_threshold_cmd);
13836 install_element(BGP_IPV4M_NODE, &neighbor_maximum_prefix_warning_cmd);
13837 install_element(BGP_IPV4M_NODE,
13838 &neighbor_maximum_prefix_threshold_warning_cmd);
13839 install_element(BGP_IPV4M_NODE, &neighbor_maximum_prefix_restart_cmd);
13840 install_element(BGP_IPV4M_NODE,
13841 &neighbor_maximum_prefix_threshold_restart_cmd);
13842 install_element(BGP_IPV4M_NODE, &no_neighbor_maximum_prefix_cmd);
13843 install_element(BGP_IPV4L_NODE, &neighbor_maximum_prefix_cmd);
13844 install_element(BGP_IPV4L_NODE, &neighbor_maximum_prefix_threshold_cmd);
13845 install_element(BGP_IPV4L_NODE, &neighbor_maximum_prefix_warning_cmd);
13846 install_element(BGP_IPV4L_NODE,
13847 &neighbor_maximum_prefix_threshold_warning_cmd);
13848 install_element(BGP_IPV4L_NODE, &neighbor_maximum_prefix_restart_cmd);
13849 install_element(BGP_IPV4L_NODE,
13850 &neighbor_maximum_prefix_threshold_restart_cmd);
13851 install_element(BGP_IPV4L_NODE, &no_neighbor_maximum_prefix_cmd);
13852 install_element(BGP_IPV6_NODE, &neighbor_maximum_prefix_cmd);
13853 install_element(BGP_IPV6_NODE, &neighbor_maximum_prefix_threshold_cmd);
13854 install_element(BGP_IPV6_NODE, &neighbor_maximum_prefix_warning_cmd);
13855 install_element(BGP_IPV6_NODE,
13856 &neighbor_maximum_prefix_threshold_warning_cmd);
13857 install_element(BGP_IPV6_NODE, &neighbor_maximum_prefix_restart_cmd);
13858 install_element(BGP_IPV6_NODE,
13859 &neighbor_maximum_prefix_threshold_restart_cmd);
13860 install_element(BGP_IPV6_NODE, &no_neighbor_maximum_prefix_cmd);
13861 install_element(BGP_IPV6M_NODE, &neighbor_maximum_prefix_cmd);
13862 install_element(BGP_IPV6M_NODE, &neighbor_maximum_prefix_threshold_cmd);
13863 install_element(BGP_IPV6M_NODE, &neighbor_maximum_prefix_warning_cmd);
13864 install_element(BGP_IPV6M_NODE,
13865 &neighbor_maximum_prefix_threshold_warning_cmd);
13866 install_element(BGP_IPV6M_NODE, &neighbor_maximum_prefix_restart_cmd);
13867 install_element(BGP_IPV6M_NODE,
13868 &neighbor_maximum_prefix_threshold_restart_cmd);
13869 install_element(BGP_IPV6M_NODE, &no_neighbor_maximum_prefix_cmd);
13870 install_element(BGP_IPV6L_NODE, &neighbor_maximum_prefix_cmd);
13871 install_element(BGP_IPV6L_NODE, &neighbor_maximum_prefix_threshold_cmd);
13872 install_element(BGP_IPV6L_NODE, &neighbor_maximum_prefix_warning_cmd);
13873 install_element(BGP_IPV6L_NODE,
13874 &neighbor_maximum_prefix_threshold_warning_cmd);
13875 install_element(BGP_IPV6L_NODE, &neighbor_maximum_prefix_restart_cmd);
13876 install_element(BGP_IPV6L_NODE,
13877 &neighbor_maximum_prefix_threshold_restart_cmd);
13878 install_element(BGP_IPV6L_NODE, &no_neighbor_maximum_prefix_cmd);
13879 install_element(BGP_VPNV4_NODE, &neighbor_maximum_prefix_cmd);
13880 install_element(BGP_VPNV4_NODE, &neighbor_maximum_prefix_threshold_cmd);
13881 install_element(BGP_VPNV4_NODE, &neighbor_maximum_prefix_warning_cmd);
13882 install_element(BGP_VPNV4_NODE,
13883 &neighbor_maximum_prefix_threshold_warning_cmd);
13884 install_element(BGP_VPNV4_NODE, &neighbor_maximum_prefix_restart_cmd);
13885 install_element(BGP_VPNV4_NODE,
13886 &neighbor_maximum_prefix_threshold_restart_cmd);
13887 install_element(BGP_VPNV4_NODE, &no_neighbor_maximum_prefix_cmd);
13888 install_element(BGP_VPNV6_NODE, &neighbor_maximum_prefix_cmd);
13889 install_element(BGP_VPNV6_NODE, &neighbor_maximum_prefix_threshold_cmd);
13890 install_element(BGP_VPNV6_NODE, &neighbor_maximum_prefix_warning_cmd);
13891 install_element(BGP_VPNV6_NODE,
13892 &neighbor_maximum_prefix_threshold_warning_cmd);
13893 install_element(BGP_VPNV6_NODE, &neighbor_maximum_prefix_restart_cmd);
13894 install_element(BGP_VPNV6_NODE,
13895 &neighbor_maximum_prefix_threshold_restart_cmd);
13896 install_element(BGP_VPNV6_NODE, &no_neighbor_maximum_prefix_cmd);
13897
13898 /* "neighbor allowas-in" */
13899 install_element(BGP_NODE, &neighbor_allowas_in_hidden_cmd);
13900 install_element(BGP_NODE, &no_neighbor_allowas_in_hidden_cmd);
13901 install_element(BGP_IPV4_NODE, &neighbor_allowas_in_cmd);
13902 install_element(BGP_IPV4_NODE, &no_neighbor_allowas_in_cmd);
13903 install_element(BGP_IPV4M_NODE, &neighbor_allowas_in_cmd);
13904 install_element(BGP_IPV4M_NODE, &no_neighbor_allowas_in_cmd);
13905 install_element(BGP_IPV4L_NODE, &neighbor_allowas_in_cmd);
13906 install_element(BGP_IPV4L_NODE, &no_neighbor_allowas_in_cmd);
13907 install_element(BGP_IPV6_NODE, &neighbor_allowas_in_cmd);
13908 install_element(BGP_IPV6_NODE, &no_neighbor_allowas_in_cmd);
13909 install_element(BGP_IPV6M_NODE, &neighbor_allowas_in_cmd);
13910 install_element(BGP_IPV6M_NODE, &no_neighbor_allowas_in_cmd);
13911 install_element(BGP_IPV6L_NODE, &neighbor_allowas_in_cmd);
13912 install_element(BGP_IPV6L_NODE, &no_neighbor_allowas_in_cmd);
13913 install_element(BGP_VPNV4_NODE, &neighbor_allowas_in_cmd);
13914 install_element(BGP_VPNV4_NODE, &no_neighbor_allowas_in_cmd);
13915 install_element(BGP_VPNV6_NODE, &neighbor_allowas_in_cmd);
13916 install_element(BGP_VPNV6_NODE, &no_neighbor_allowas_in_cmd);
13917 install_element(BGP_EVPN_NODE, &neighbor_allowas_in_cmd);
13918 install_element(BGP_EVPN_NODE, &no_neighbor_allowas_in_cmd);
13919
13920 /* address-family commands. */
13921 install_element(BGP_NODE, &address_family_ipv4_safi_cmd);
13922 install_element(BGP_NODE, &address_family_ipv6_safi_cmd);
13923 #ifdef KEEP_OLD_VPN_COMMANDS
13924 install_element(BGP_NODE, &address_family_vpnv4_cmd);
13925 install_element(BGP_NODE, &address_family_vpnv6_cmd);
13926 #endif /* KEEP_OLD_VPN_COMMANDS */
13927
13928 install_element(BGP_NODE, &address_family_evpn_cmd);
13929
13930 /* "exit-address-family" command. */
13931 install_element(BGP_IPV4_NODE, &exit_address_family_cmd);
13932 install_element(BGP_IPV4M_NODE, &exit_address_family_cmd);
13933 install_element(BGP_IPV4L_NODE, &exit_address_family_cmd);
13934 install_element(BGP_IPV6_NODE, &exit_address_family_cmd);
13935 install_element(BGP_IPV6M_NODE, &exit_address_family_cmd);
13936 install_element(BGP_IPV6L_NODE, &exit_address_family_cmd);
13937 install_element(BGP_VPNV4_NODE, &exit_address_family_cmd);
13938 install_element(BGP_VPNV6_NODE, &exit_address_family_cmd);
13939 install_element(BGP_FLOWSPECV4_NODE, &exit_address_family_cmd);
13940 install_element(BGP_FLOWSPECV6_NODE, &exit_address_family_cmd);
13941 install_element(BGP_EVPN_NODE, &exit_address_family_cmd);
13942
13943 /* "clear ip bgp commands" */
13944 install_element(ENABLE_NODE, &clear_ip_bgp_all_cmd);
13945
13946 /* clear ip bgp prefix */
13947 install_element(ENABLE_NODE, &clear_ip_bgp_prefix_cmd);
13948 install_element(ENABLE_NODE, &clear_bgp_ipv6_safi_prefix_cmd);
13949 install_element(ENABLE_NODE, &clear_bgp_instance_ipv6_safi_prefix_cmd);
13950
13951 /* "show [ip] bgp summary" commands. */
13952 install_element(VIEW_NODE, &show_bgp_instance_all_ipv6_updgrps_cmd);
13953 install_element(VIEW_NODE, &show_bgp_l2vpn_evpn_updgrps_cmd);
13954 install_element(VIEW_NODE, &show_bgp_instance_updgrps_stats_cmd);
13955 install_element(VIEW_NODE, &show_bgp_updgrps_stats_cmd);
13956 install_element(VIEW_NODE, &show_ip_bgp_instance_updgrps_adj_s_cmd);
13957 install_element(VIEW_NODE, &show_ip_bgp_summary_cmd);
13958 install_element(VIEW_NODE, &show_ip_bgp_updgrps_cmd);
13959
13960 /* "show [ip] bgp neighbors" commands. */
13961 install_element(VIEW_NODE, &show_ip_bgp_neighbors_cmd);
13962
13963 /* "show [ip] bgp peer-group" commands. */
13964 install_element(VIEW_NODE, &show_ip_bgp_peer_groups_cmd);
13965
13966 /* "show [ip] bgp paths" commands. */
13967 install_element(VIEW_NODE, &show_ip_bgp_paths_cmd);
13968
13969 /* "show [ip] bgp community" commands. */
13970 install_element(VIEW_NODE, &show_ip_bgp_community_info_cmd);
13971
13972 /* "show ip bgp large-community" commands. */
13973 install_element(VIEW_NODE, &show_ip_bgp_lcommunity_info_cmd);
13974 /* "show [ip] bgp attribute-info" commands. */
13975 install_element(VIEW_NODE, &show_ip_bgp_attr_info_cmd);
13976 /* "show [ip] bgp route-leak" command */
13977 install_element(VIEW_NODE, &show_ip_bgp_route_leak_cmd);
13978
13979 /* "redistribute" commands. */
13980 install_element(BGP_NODE, &bgp_redistribute_ipv4_hidden_cmd);
13981 install_element(BGP_NODE, &no_bgp_redistribute_ipv4_hidden_cmd);
13982 install_element(BGP_NODE, &bgp_redistribute_ipv4_rmap_hidden_cmd);
13983 install_element(BGP_NODE, &bgp_redistribute_ipv4_metric_hidden_cmd);
13984 install_element(BGP_NODE,
13985 &bgp_redistribute_ipv4_rmap_metric_hidden_cmd);
13986 install_element(BGP_NODE,
13987 &bgp_redistribute_ipv4_metric_rmap_hidden_cmd);
13988 install_element(BGP_NODE, &bgp_redistribute_ipv4_ospf_hidden_cmd);
13989 install_element(BGP_NODE, &no_bgp_redistribute_ipv4_ospf_hidden_cmd);
13990 install_element(BGP_NODE, &bgp_redistribute_ipv4_ospf_rmap_hidden_cmd);
13991 install_element(BGP_NODE,
13992 &bgp_redistribute_ipv4_ospf_metric_hidden_cmd);
13993 install_element(BGP_NODE,
13994 &bgp_redistribute_ipv4_ospf_rmap_metric_hidden_cmd);
13995 install_element(BGP_NODE,
13996 &bgp_redistribute_ipv4_ospf_metric_rmap_hidden_cmd);
13997 install_element(BGP_IPV4_NODE, &bgp_redistribute_ipv4_cmd);
13998 install_element(BGP_IPV4_NODE, &no_bgp_redistribute_ipv4_cmd);
13999 install_element(BGP_IPV4_NODE, &bgp_redistribute_ipv4_rmap_cmd);
14000 install_element(BGP_IPV4_NODE, &bgp_redistribute_ipv4_metric_cmd);
14001 install_element(BGP_IPV4_NODE, &bgp_redistribute_ipv4_rmap_metric_cmd);
14002 install_element(BGP_IPV4_NODE, &bgp_redistribute_ipv4_metric_rmap_cmd);
14003 install_element(BGP_IPV4_NODE, &bgp_redistribute_ipv4_ospf_cmd);
14004 install_element(BGP_IPV4_NODE, &no_bgp_redistribute_ipv4_ospf_cmd);
14005 install_element(BGP_IPV4_NODE, &bgp_redistribute_ipv4_ospf_rmap_cmd);
14006 install_element(BGP_IPV4_NODE, &bgp_redistribute_ipv4_ospf_metric_cmd);
14007 install_element(BGP_IPV4_NODE,
14008 &bgp_redistribute_ipv4_ospf_rmap_metric_cmd);
14009 install_element(BGP_IPV4_NODE,
14010 &bgp_redistribute_ipv4_ospf_metric_rmap_cmd);
14011 install_element(BGP_IPV6_NODE, &bgp_redistribute_ipv6_cmd);
14012 install_element(BGP_IPV6_NODE, &no_bgp_redistribute_ipv6_cmd);
14013 install_element(BGP_IPV6_NODE, &bgp_redistribute_ipv6_rmap_cmd);
14014 install_element(BGP_IPV6_NODE, &bgp_redistribute_ipv6_metric_cmd);
14015 install_element(BGP_IPV6_NODE, &bgp_redistribute_ipv6_rmap_metric_cmd);
14016 install_element(BGP_IPV6_NODE, &bgp_redistribute_ipv6_metric_rmap_cmd);
14017
14018 /* import|export vpn [route-map WORD] */
14019 install_element(BGP_IPV4_NODE, &bgp_imexport_vpn_cmd);
14020 install_element(BGP_IPV6_NODE, &bgp_imexport_vpn_cmd);
14021
14022 install_element(BGP_IPV4_NODE, &bgp_imexport_vrf_cmd);
14023 install_element(BGP_IPV6_NODE, &bgp_imexport_vrf_cmd);
14024
14025 /* ttl_security commands */
14026 install_element(BGP_NODE, &neighbor_ttl_security_cmd);
14027 install_element(BGP_NODE, &no_neighbor_ttl_security_cmd);
14028
14029 /* "show [ip] bgp memory" commands. */
14030 install_element(VIEW_NODE, &show_bgp_memory_cmd);
14031
14032 /* "show bgp martian next-hop" */
14033 install_element(VIEW_NODE, &show_bgp_martian_nexthop_db_cmd);
14034
14035 install_element(VIEW_NODE, &show_bgp_mac_hash_cmd);
14036
14037 /* "show [ip] bgp views" commands. */
14038 install_element(VIEW_NODE, &show_bgp_views_cmd);
14039
14040 /* "show [ip] bgp vrfs" commands. */
14041 install_element(VIEW_NODE, &show_bgp_vrfs_cmd);
14042
14043 /* Community-list. */
14044 community_list_vty();
14045
14046 /* vpn-policy commands */
14047 install_element(BGP_IPV4_NODE, &af_rd_vpn_export_cmd);
14048 install_element(BGP_IPV6_NODE, &af_rd_vpn_export_cmd);
14049 install_element(BGP_IPV4_NODE, &af_label_vpn_export_cmd);
14050 install_element(BGP_IPV6_NODE, &af_label_vpn_export_cmd);
14051 install_element(BGP_IPV4_NODE, &af_nexthop_vpn_export_cmd);
14052 install_element(BGP_IPV6_NODE, &af_nexthop_vpn_export_cmd);
14053 install_element(BGP_IPV4_NODE, &af_rt_vpn_imexport_cmd);
14054 install_element(BGP_IPV6_NODE, &af_rt_vpn_imexport_cmd);
14055 install_element(BGP_IPV4_NODE, &af_route_map_vpn_imexport_cmd);
14056 install_element(BGP_IPV6_NODE, &af_route_map_vpn_imexport_cmd);
14057 install_element(BGP_IPV4_NODE, &af_import_vrf_route_map_cmd);
14058 install_element(BGP_IPV6_NODE, &af_import_vrf_route_map_cmd);
14059
14060 install_element(BGP_IPV4_NODE, &af_routetarget_import_cmd);
14061 install_element(BGP_IPV6_NODE, &af_routetarget_import_cmd);
14062
14063 install_element(BGP_IPV4_NODE, &af_no_rd_vpn_export_cmd);
14064 install_element(BGP_IPV6_NODE, &af_no_rd_vpn_export_cmd);
14065 install_element(BGP_IPV4_NODE, &af_no_label_vpn_export_cmd);
14066 install_element(BGP_IPV6_NODE, &af_no_label_vpn_export_cmd);
14067 install_element(BGP_IPV4_NODE, &af_no_nexthop_vpn_export_cmd);
14068 install_element(BGP_IPV6_NODE, &af_no_nexthop_vpn_export_cmd);
14069 install_element(BGP_IPV4_NODE, &af_no_rt_vpn_imexport_cmd);
14070 install_element(BGP_IPV6_NODE, &af_no_rt_vpn_imexport_cmd);
14071 install_element(BGP_IPV4_NODE, &af_no_route_map_vpn_imexport_cmd);
14072 install_element(BGP_IPV6_NODE, &af_no_route_map_vpn_imexport_cmd);
14073 install_element(BGP_IPV4_NODE, &af_no_import_vrf_route_map_cmd);
14074 install_element(BGP_IPV6_NODE, &af_no_import_vrf_route_map_cmd);
14075 }
14076
14077 #include "memory.h"
14078 #include "bgp_regex.h"
14079 #include "bgp_clist.h"
14080 #include "bgp_ecommunity.h"
14081
14082 /* VTY functions. */
14083
14084 /* Direction value to string conversion. */
14085 static const char *community_direct_str(int direct)
14086 {
14087 switch (direct) {
14088 case COMMUNITY_DENY:
14089 return "deny";
14090 case COMMUNITY_PERMIT:
14091 return "permit";
14092 default:
14093 return "unknown";
14094 }
14095 }
14096
14097 /* Display error string. */
14098 static void community_list_perror(struct vty *vty, int ret)
14099 {
14100 switch (ret) {
14101 case COMMUNITY_LIST_ERR_CANT_FIND_LIST:
14102 vty_out(vty, "%% Can't find community-list\n");
14103 break;
14104 case COMMUNITY_LIST_ERR_MALFORMED_VAL:
14105 vty_out(vty, "%% Malformed community-list value\n");
14106 break;
14107 case COMMUNITY_LIST_ERR_STANDARD_CONFLICT:
14108 vty_out(vty,
14109 "%% Community name conflict, previously defined as standard community\n");
14110 break;
14111 case COMMUNITY_LIST_ERR_EXPANDED_CONFLICT:
14112 vty_out(vty,
14113 "%% Community name conflict, previously defined as expanded community\n");
14114 break;
14115 }
14116 }
14117
14118 /* "community-list" keyword help string. */
14119 #define COMMUNITY_LIST_STR "Add a community list entry\n"
14120
14121 /*community-list standard */
14122 DEFUN (community_list_standard,
14123 bgp_community_list_standard_cmd,
14124 "bgp community-list <(1-99)|standard WORD> <deny|permit> AA:NN...",
14125 BGP_STR
14126 COMMUNITY_LIST_STR
14127 "Community list number (standard)\n"
14128 "Add an standard community-list entry\n"
14129 "Community list name\n"
14130 "Specify community to reject\n"
14131 "Specify community to accept\n"
14132 COMMUNITY_VAL_STR)
14133 {
14134 char *cl_name_or_number = NULL;
14135 int direct = 0;
14136 int style = COMMUNITY_LIST_STANDARD;
14137
14138 int idx = 0;
14139
14140 if (argv_find(argv, argc, "ip", &idx)) {
14141 vty_out(vty, "This config option is deprecated, and is scheduled for removal.\n");
14142 vty_out(vty, "if you are using this please migrate to the below command.\n");
14143 vty_out(vty, "'bgp community-list <(1-99)|(100-500)|standard|expanded> <deny|permit> AA:NN'\n");
14144 zlog_warn("Deprecated option: 'ip community-list <(1-99)|(100-500)|standard|expanded> <deny|permit> AA:NN' being used");
14145 }
14146
14147 argv_find(argv, argc, "(1-99)", &idx);
14148 argv_find(argv, argc, "WORD", &idx);
14149 cl_name_or_number = argv[idx]->arg;
14150 direct = argv_find(argv, argc, "permit", &idx) ? COMMUNITY_PERMIT
14151 : COMMUNITY_DENY;
14152 argv_find(argv, argc, "AA:NN", &idx);
14153 char *str = argv_concat(argv, argc, idx);
14154
14155 int ret = community_list_set(bgp_clist, cl_name_or_number, str, direct,
14156 style);
14157
14158 XFREE(MTYPE_TMP, str);
14159
14160 if (ret < 0) {
14161 /* Display error string. */
14162 community_list_perror(vty, ret);
14163 return CMD_WARNING_CONFIG_FAILED;
14164 }
14165
14166 return CMD_SUCCESS;
14167 }
14168
14169 #if CONFDATE > 20191005
14170 CPP_NOTICE("bgpd: remove deprecated 'ip community-list <(1-99)|(100-500)|standard|expanded> <deny|permit> AA:NN' command")
14171 #endif
14172 ALIAS (community_list_standard,
14173 ip_community_list_standard_cmd,
14174 "ip community-list <(1-99)|standard WORD> <deny|permit> AA:NN...",
14175 IP_STR
14176 COMMUNITY_LIST_STR
14177 "Community list number (standard)\n"
14178 "Add an standard community-list entry\n"
14179 "Community list name\n"
14180 "Specify community to reject\n"
14181 "Specify community to accept\n"
14182 COMMUNITY_VAL_STR)
14183
14184 DEFUN (no_community_list_standard_all,
14185 no_bgp_community_list_standard_all_cmd,
14186 "no bgp community-list <(1-99)|standard WORD> <deny|permit> AA:NN...",
14187 NO_STR
14188 BGP_STR
14189 COMMUNITY_LIST_STR
14190 "Community list number (standard)\n"
14191 "Add an standard community-list entry\n"
14192 "Community list name\n"
14193 "Specify community to reject\n"
14194 "Specify community to accept\n"
14195 COMMUNITY_VAL_STR)
14196 {
14197 char *cl_name_or_number = NULL;
14198 char *str = NULL;
14199 int direct = 0;
14200 int style = COMMUNITY_LIST_STANDARD;
14201
14202 int idx = 0;
14203
14204 if (argv_find(argv, argc, "ip", &idx)) {
14205 vty_out(vty, "This config option is deprecated, and is scheduled for removal\n");
14206 vty_out(vty, "if you are using this please migrate to the below command.\n");
14207 vty_out(vty, "'no bgp community-list <(1-99)|(100-500)|standard|expanded> <deny|permit> AA:NN'\n");
14208 zlog_warn("Deprecated option: 'no ip community-list <(1-99)|(100-500)|standard|expanded> <deny|permit> |AA:NN' being used");
14209 }
14210
14211 argv_find(argv, argc, "permit", &idx);
14212 argv_find(argv, argc, "deny", &idx);
14213
14214 if (idx) {
14215 direct = argv_find(argv, argc, "permit", &idx)
14216 ? COMMUNITY_PERMIT
14217 : COMMUNITY_DENY;
14218
14219 idx = 0;
14220 argv_find(argv, argc, "AA:NN", &idx);
14221 str = argv_concat(argv, argc, idx);
14222 }
14223
14224 idx = 0;
14225 argv_find(argv, argc, "(1-99)", &idx);
14226 argv_find(argv, argc, "WORD", &idx);
14227 cl_name_or_number = argv[idx]->arg;
14228
14229 int ret = community_list_unset(bgp_clist, cl_name_or_number, str,
14230 direct, style);
14231
14232 XFREE(MTYPE_TMP, str);
14233
14234 if (ret < 0) {
14235 community_list_perror(vty, ret);
14236 return CMD_WARNING_CONFIG_FAILED;
14237 }
14238
14239 return CMD_SUCCESS;
14240 }
14241 ALIAS (no_community_list_standard_all,
14242 no_ip_community_list_standard_all_cmd,
14243 "no ip community-list <(1-99)|standard WORD> <deny|permit> AA:NN...",
14244 NO_STR
14245 IP_STR
14246 COMMUNITY_LIST_STR
14247 "Community list number (standard)\n"
14248 "Add an standard community-list entry\n"
14249 "Community list name\n"
14250 "Specify community to reject\n"
14251 "Specify community to accept\n"
14252 COMMUNITY_VAL_STR)
14253
14254 ALIAS(no_community_list_standard_all, no_bgp_community_list_standard_all_list_cmd,
14255 "no bgp community-list <(1-99)|standard WORD>",
14256 NO_STR BGP_STR COMMUNITY_LIST_STR
14257 "Community list number (standard)\n"
14258 "Add an standard community-list entry\n"
14259 "Community list name\n")
14260
14261 ALIAS(no_community_list_standard_all, no_ip_community_list_standard_all_list_cmd,
14262 "no ip community-list <(1-99)|standard WORD>",
14263 NO_STR BGP_STR COMMUNITY_LIST_STR
14264 "Community list number (standard)\n"
14265 "Add an standard community-list entry\n"
14266 "Community list name\n")
14267
14268 /*community-list expanded */
14269 DEFUN (community_list_expanded_all,
14270 bgp_community_list_expanded_all_cmd,
14271 "bgp community-list <(100-500)|expanded WORD> <deny|permit> AA:NN...",
14272 BGP_STR
14273 COMMUNITY_LIST_STR
14274 "Community list number (expanded)\n"
14275 "Add an expanded community-list entry\n"
14276 "Community list name\n"
14277 "Specify community to reject\n"
14278 "Specify community to accept\n"
14279 COMMUNITY_VAL_STR)
14280 {
14281 char *cl_name_or_number = NULL;
14282 int direct = 0;
14283 int style = COMMUNITY_LIST_EXPANDED;
14284
14285 int idx = 0;
14286 if (argv_find(argv, argc, "ip", &idx)) {
14287 vty_out(vty, "This config option is deprecated, and is scheduled for removal.\n");
14288 vty_out(vty, "if you are using this please migrate to the below command.\n");
14289 vty_out(vty, "'bgp community-list <(1-99)|(100-500)|standard|expanded> <deny|permit> AA:NN'\n");
14290 zlog_warn("Deprecated option: 'ip community-list <(1-99)|(100-500)|standard|expanded> <deny|permit> AA:NN' being used");
14291 }
14292 argv_find(argv, argc, "(100-500)", &idx);
14293 argv_find(argv, argc, "WORD", &idx);
14294 cl_name_or_number = argv[idx]->arg;
14295 direct = argv_find(argv, argc, "permit", &idx) ? COMMUNITY_PERMIT
14296 : COMMUNITY_DENY;
14297 argv_find(argv, argc, "AA:NN", &idx);
14298 char *str = argv_concat(argv, argc, idx);
14299
14300 int ret = community_list_set(bgp_clist, cl_name_or_number, str, direct,
14301 style);
14302
14303 XFREE(MTYPE_TMP, str);
14304
14305 if (ret < 0) {
14306 /* Display error string. */
14307 community_list_perror(vty, ret);
14308 return CMD_WARNING_CONFIG_FAILED;
14309 }
14310
14311 return CMD_SUCCESS;
14312 }
14313
14314 ALIAS (community_list_expanded_all,
14315 ip_community_list_expanded_all_cmd,
14316 "ip community-list <(100-500)|expanded WORD> <deny|permit> AA:NN...",
14317 IP_STR
14318 COMMUNITY_LIST_STR
14319 "Community list number (expanded)\n"
14320 "Add an expanded community-list entry\n"
14321 "Community list name\n"
14322 "Specify community to reject\n"
14323 "Specify community to accept\n"
14324 COMMUNITY_VAL_STR)
14325
14326 DEFUN (no_community_list_expanded_all,
14327 no_bgp_community_list_expanded_all_cmd,
14328 "no bgp community-list <(100-500)|expanded WORD> <deny|permit> AA:NN...",
14329 NO_STR
14330 BGP_STR
14331 COMMUNITY_LIST_STR
14332 "Community list number (expanded)\n"
14333 "Add an expanded community-list entry\n"
14334 "Community list name\n"
14335 "Specify community to reject\n"
14336 "Specify community to accept\n"
14337 COMMUNITY_VAL_STR)
14338 {
14339 char *cl_name_or_number = NULL;
14340 char *str = NULL;
14341 int direct = 0;
14342 int style = COMMUNITY_LIST_EXPANDED;
14343
14344 int idx = 0;
14345 if (argv_find(argv, argc, "ip", &idx)) {
14346 vty_out(vty, "This config option is deprecated, and is scheduled for removal.\n");
14347 vty_out(vty, "if you are using this please migrate to the below command.\n");
14348 vty_out(vty, "'no bgp community-list <(1-99)|(100-500)|standard|expanded> <deny|permit> AA:NN'\n");
14349 zlog_warn("Deprecated option: 'no ip community-list <(1-99)|(100-500)|standard|expanded> <deny|permit> AA:NN' being used");
14350 }
14351
14352 idx = 0;
14353 argv_find(argv, argc, "permit", &idx);
14354 argv_find(argv, argc, "deny", &idx);
14355
14356 if (idx) {
14357 direct = argv_find(argv, argc, "permit", &idx)
14358 ? COMMUNITY_PERMIT
14359 : COMMUNITY_DENY;
14360
14361 idx = 0;
14362 argv_find(argv, argc, "AA:NN", &idx);
14363 str = argv_concat(argv, argc, idx);
14364 }
14365
14366 idx = 0;
14367 argv_find(argv, argc, "(100-500)", &idx);
14368 argv_find(argv, argc, "WORD", &idx);
14369 cl_name_or_number = argv[idx]->arg;
14370
14371 int ret = community_list_unset(bgp_clist, cl_name_or_number, str,
14372 direct, style);
14373
14374 XFREE(MTYPE_TMP, str);
14375
14376 if (ret < 0) {
14377 community_list_perror(vty, ret);
14378 return CMD_WARNING_CONFIG_FAILED;
14379 }
14380
14381 return CMD_SUCCESS;
14382 }
14383
14384 ALIAS (no_community_list_expanded_all,
14385 no_ip_community_list_expanded_all_cmd,
14386 "no ip community-list <(100-500)|expanded WORD> <deny|permit> AA:NN...",
14387 NO_STR
14388 IP_STR
14389 COMMUNITY_LIST_STR
14390 "Community list number (expanded)\n"
14391 "Add an expanded community-list entry\n"
14392 "Community list name\n"
14393 "Specify community to reject\n"
14394 "Specify community to accept\n"
14395 COMMUNITY_VAL_STR)
14396
14397 ALIAS(no_community_list_expanded_all, no_bgp_community_list_expanded_all_list_cmd,
14398 "no bgp community-list <(100-500)|expanded WORD>",
14399 NO_STR IP_STR COMMUNITY_LIST_STR
14400 "Community list number (expanded)\n"
14401 "Add an expanded community-list entry\n"
14402 "Community list name\n")
14403
14404 ALIAS(no_community_list_expanded_all, no_ip_community_list_expanded_all_list_cmd,
14405 "no ip community-list <(100-500)|expanded WORD>",
14406 NO_STR IP_STR COMMUNITY_LIST_STR
14407 "Community list number (expanded)\n"
14408 "Add an expanded community-list entry\n"
14409 "Community list name\n")
14410
14411 /* Return configuration string of community-list entry. */
14412 static const char *community_list_config_str(struct community_entry *entry)
14413 {
14414 const char *str;
14415
14416 if (entry->any)
14417 str = "";
14418 else {
14419 if (entry->style == COMMUNITY_LIST_STANDARD)
14420 str = community_str(entry->u.com, false);
14421 else if (entry->style == LARGE_COMMUNITY_LIST_STANDARD)
14422 str = lcommunity_str(entry->u.lcom, false);
14423 else
14424 str = entry->config;
14425 }
14426 return str;
14427 }
14428
14429 static void community_list_show(struct vty *vty, struct community_list *list)
14430 {
14431 struct community_entry *entry;
14432
14433 for (entry = list->head; entry; entry = entry->next) {
14434 if (entry == list->head) {
14435 if (all_digit(list->name))
14436 vty_out(vty, "Community %s list %s\n",
14437 entry->style == COMMUNITY_LIST_STANDARD
14438 ? "standard"
14439 : "(expanded) access",
14440 list->name);
14441 else
14442 vty_out(vty, "Named Community %s list %s\n",
14443 entry->style == COMMUNITY_LIST_STANDARD
14444 ? "standard"
14445 : "expanded",
14446 list->name);
14447 }
14448 if (entry->any)
14449 vty_out(vty, " %s\n",
14450 community_direct_str(entry->direct));
14451 else
14452 vty_out(vty, " %s %s\n",
14453 community_direct_str(entry->direct),
14454 community_list_config_str(entry));
14455 }
14456 }
14457
14458 DEFUN (show_community_list,
14459 show_bgp_community_list_cmd,
14460 "show bgp community-list",
14461 SHOW_STR
14462 BGP_STR
14463 "List community-list\n")
14464 {
14465 struct community_list *list;
14466 struct community_list_master *cm;
14467
14468 int idx = 0;
14469 if (argv_find(argv, argc, "ip", &idx)) {
14470 vty_out(vty, "This config option is deprecated, and is scheduled for removal.\n");
14471 vty_out(vty, "if you are using this please migrate to the below command.\n");
14472 vty_out(vty, "'show bgp community-list <(1-500)|WORD>'\n");
14473 zlog_warn("Deprecated option: 'ip show community-list <(1-500)|WORD>' being used");
14474 }
14475 cm = community_list_master_lookup(bgp_clist, COMMUNITY_LIST_MASTER);
14476 if (!cm)
14477 return CMD_SUCCESS;
14478
14479 for (list = cm->num.head; list; list = list->next)
14480 community_list_show(vty, list);
14481
14482 for (list = cm->str.head; list; list = list->next)
14483 community_list_show(vty, list);
14484
14485 return CMD_SUCCESS;
14486 }
14487
14488 ALIAS (show_community_list,
14489 show_ip_community_list_cmd,
14490 "show ip community-list",
14491 SHOW_STR
14492 IP_STR
14493 "List community-list\n")
14494
14495 DEFUN (show_community_list_arg,
14496 show_bgp_community_list_arg_cmd,
14497 "show bgp community-list <(1-500)|WORD>",
14498 SHOW_STR
14499 BGP_STR
14500 "List community-list\n"
14501 "Community-list number\n"
14502 "Community-list name\n")
14503 {
14504 int idx_comm_list = 3;
14505 struct community_list *list;
14506
14507 int idx = 0;
14508 if (argv_find(argv, argc, "ip", &idx)) {
14509 vty_out(vty, "This config option is deprecated, and is scheduled for removal.\n");
14510 vty_out(vty, "if you are using this please migrate to the below command.\n");
14511 vty_out(vty, "'show bgp community-list <(1-500)|WORD>'\n");
14512 zlog_warn("Deprecated option: 'ip show community-list <(1-500)|WORD>' being used");
14513 }
14514 list = community_list_lookup(bgp_clist, argv[idx_comm_list]->arg, 0,
14515 COMMUNITY_LIST_MASTER);
14516 if (!list) {
14517 vty_out(vty, "%% Can't find community-list\n");
14518 return CMD_WARNING;
14519 }
14520
14521 community_list_show(vty, list);
14522
14523 return CMD_SUCCESS;
14524 }
14525
14526 ALIAS (show_community_list_arg,
14527 show_ip_community_list_arg_cmd,
14528 "show ip community-list <(1-500)|WORD>",
14529 SHOW_STR
14530 IP_STR
14531 "List community-list\n"
14532 "Community-list number\n"
14533 "Community-list name\n")
14534
14535 /*
14536 * Large Community code.
14537 */
14538 static int lcommunity_list_set_vty(struct vty *vty, int argc,
14539 struct cmd_token **argv, int style,
14540 int reject_all_digit_name)
14541 {
14542 int ret;
14543 int direct;
14544 char *str;
14545 int idx = 0;
14546 char *cl_name;
14547
14548 if (argv_find(argv, argc, "ip", &idx)) {
14549 vty_out(vty, "This config option is deprecated, and is scheduled for removal.\n");
14550 vty_out(vty, "if you are using this please migrate to the below command.\n");
14551 vty_out(vty, "'bgp large-community-list <(1-99)|(100-500)|standard|expanded> <deny|permit> <LINE|AA:BB:CC>'\n");
14552 zlog_warn("Deprecated option: 'large-community-list <(1-99)|(100-500)|standard|expanded> <deny|permit> <LINE|AA:BB:CC>' being used");
14553 }
14554 direct = argv_find(argv, argc, "permit", &idx) ? COMMUNITY_PERMIT
14555 : COMMUNITY_DENY;
14556
14557 /* All digit name check. */
14558 idx = 0;
14559 argv_find(argv, argc, "WORD", &idx);
14560 argv_find(argv, argc, "(1-99)", &idx);
14561 argv_find(argv, argc, "(100-500)", &idx);
14562 cl_name = argv[idx]->arg;
14563 if (reject_all_digit_name && all_digit(cl_name)) {
14564 vty_out(vty, "%% Community name cannot have all digits\n");
14565 return CMD_WARNING_CONFIG_FAILED;
14566 }
14567
14568 idx = 0;
14569 argv_find(argv, argc, "AA:BB:CC", &idx);
14570 argv_find(argv, argc, "LINE", &idx);
14571 /* Concat community string argument. */
14572 if (idx)
14573 str = argv_concat(argv, argc, idx);
14574 else
14575 str = NULL;
14576
14577 ret = lcommunity_list_set(bgp_clist, cl_name, str, direct, style);
14578
14579 /* Free temporary community list string allocated by
14580 argv_concat(). */
14581 XFREE(MTYPE_TMP, str);
14582
14583 if (ret < 0) {
14584 community_list_perror(vty, ret);
14585 return CMD_WARNING_CONFIG_FAILED;
14586 }
14587 return CMD_SUCCESS;
14588 }
14589
14590 static int lcommunity_list_unset_vty(struct vty *vty, int argc,
14591 struct cmd_token **argv, int style)
14592 {
14593 int ret;
14594 int direct = 0;
14595 char *str = NULL;
14596 int idx = 0;
14597
14598 if (argv_find(argv, argc, "ip", &idx)) {
14599 vty_out(vty, "This config option is deprecated, and is scheduled for removal.\n");
14600 vty_out(vty, "if you are using this please migrate to the below command.\n");
14601 vty_out(vty, "'no bgp large-community-list <(1-99)|(100-500)|standard|expanded> <deny|permit> <LINE|AA:BB:CC>'\n");
14602 zlog_warn("Deprecated option: 'no ip large-community-list <(1-99)|(100-500)|standard|expanded> <deny|permit> <LINE|AA:BB:CC>' being used");
14603 }
14604 argv_find(argv, argc, "permit", &idx);
14605 argv_find(argv, argc, "deny", &idx);
14606
14607 if (idx) {
14608 /* Check the list direct. */
14609 if (strncmp(argv[idx]->arg, "p", 1) == 0)
14610 direct = COMMUNITY_PERMIT;
14611 else
14612 direct = COMMUNITY_DENY;
14613
14614 idx = 0;
14615 argv_find(argv, argc, "LINE", &idx);
14616 argv_find(argv, argc, "AA:AA:NN", &idx);
14617 /* Concat community string argument. */
14618 str = argv_concat(argv, argc, idx);
14619 }
14620
14621 idx = 0;
14622 argv_find(argv, argc, "(1-99)", &idx);
14623 argv_find(argv, argc, "(100-500)", &idx);
14624 argv_find(argv, argc, "WORD", &idx);
14625
14626 /* Unset community list. */
14627 ret = lcommunity_list_unset(bgp_clist, argv[idx]->arg, str, direct,
14628 style);
14629
14630 /* Free temporary community list string allocated by
14631 argv_concat(). */
14632 XFREE(MTYPE_TMP, str);
14633
14634 if (ret < 0) {
14635 community_list_perror(vty, ret);
14636 return CMD_WARNING_CONFIG_FAILED;
14637 }
14638
14639 return CMD_SUCCESS;
14640 }
14641
14642 /* "large-community-list" keyword help string. */
14643 #define LCOMMUNITY_LIST_STR "Add a large community list entry\n"
14644 #define LCOMMUNITY_VAL_STR "large community in 'aa:bb:cc' format\n"
14645
14646 #if CONFDATE > 20191005
14647 CPP_NOTICE("bgpd: remove deprecated 'ip large-community-list <(1-99)|(100-500)|standard|expanded> <deny|permit> <LINE|AA:BB:CC>' command")
14648 #endif
14649 DEFUN (lcommunity_list_standard,
14650 bgp_lcommunity_list_standard_cmd,
14651 "bgp large-community-list (1-99) <deny|permit>",
14652 BGP_STR
14653 LCOMMUNITY_LIST_STR
14654 "Large Community list number (standard)\n"
14655 "Specify large community to reject\n"
14656 "Specify large community to accept\n")
14657 {
14658 return lcommunity_list_set_vty(vty, argc, argv,
14659 LARGE_COMMUNITY_LIST_STANDARD, 0);
14660 }
14661
14662 ALIAS (lcommunity_list_standard,
14663 ip_lcommunity_list_standard_cmd,
14664 "ip large-community-list (1-99) <deny|permit>",
14665 IP_STR
14666 LCOMMUNITY_LIST_STR
14667 "Large Community list number (standard)\n"
14668 "Specify large community to reject\n"
14669 "Specify large community to accept\n")
14670
14671 DEFUN (lcommunity_list_standard1,
14672 bgp_lcommunity_list_standard1_cmd,
14673 "bgp large-community-list (1-99) <deny|permit> AA:BB:CC...",
14674 BGP_STR
14675 LCOMMUNITY_LIST_STR
14676 "Large Community list number (standard)\n"
14677 "Specify large community to reject\n"
14678 "Specify large community to accept\n"
14679 LCOMMUNITY_VAL_STR)
14680 {
14681 return lcommunity_list_set_vty(vty, argc, argv,
14682 LARGE_COMMUNITY_LIST_STANDARD, 0);
14683 }
14684
14685 ALIAS (lcommunity_list_standard1,
14686 ip_lcommunity_list_standard1_cmd,
14687 "ip large-community-list (1-99) <deny|permit> AA:BB:CC...",
14688 IP_STR
14689 LCOMMUNITY_LIST_STR
14690 "Large Community list number (standard)\n"
14691 "Specify large community to reject\n"
14692 "Specify large community to accept\n"
14693 LCOMMUNITY_VAL_STR)
14694
14695 DEFUN (lcommunity_list_expanded,
14696 bgp_lcommunity_list_expanded_cmd,
14697 "bgp large-community-list (100-500) <deny|permit> LINE...",
14698 BGP_STR
14699 LCOMMUNITY_LIST_STR
14700 "Large Community list number (expanded)\n"
14701 "Specify large community to reject\n"
14702 "Specify large community to accept\n"
14703 "An ordered list as a regular-expression\n")
14704 {
14705 return lcommunity_list_set_vty(vty, argc, argv,
14706 LARGE_COMMUNITY_LIST_EXPANDED, 0);
14707 }
14708
14709 ALIAS (lcommunity_list_expanded,
14710 ip_lcommunity_list_expanded_cmd,
14711 "ip large-community-list (100-500) <deny|permit> LINE...",
14712 IP_STR
14713 LCOMMUNITY_LIST_STR
14714 "Large Community list number (expanded)\n"
14715 "Specify large community to reject\n"
14716 "Specify large community to accept\n"
14717 "An ordered list as a regular-expression\n")
14718
14719 DEFUN (lcommunity_list_name_standard,
14720 bgp_lcommunity_list_name_standard_cmd,
14721 "bgp large-community-list standard WORD <deny|permit>",
14722 BGP_STR
14723 LCOMMUNITY_LIST_STR
14724 "Specify standard large-community-list\n"
14725 "Large Community list name\n"
14726 "Specify large community to reject\n"
14727 "Specify large community to accept\n")
14728 {
14729 return lcommunity_list_set_vty(vty, argc, argv,
14730 LARGE_COMMUNITY_LIST_STANDARD, 1);
14731 }
14732
14733 ALIAS (lcommunity_list_name_standard,
14734 ip_lcommunity_list_name_standard_cmd,
14735 "ip large-community-list standard WORD <deny|permit>",
14736 IP_STR
14737 LCOMMUNITY_LIST_STR
14738 "Specify standard large-community-list\n"
14739 "Large Community list name\n"
14740 "Specify large community to reject\n"
14741 "Specify large community to accept\n")
14742
14743 DEFUN (lcommunity_list_name_standard1,
14744 bgp_lcommunity_list_name_standard1_cmd,
14745 "bgp large-community-list standard WORD <deny|permit> AA:BB:CC...",
14746 BGP_STR
14747 LCOMMUNITY_LIST_STR
14748 "Specify standard large-community-list\n"
14749 "Large Community list name\n"
14750 "Specify large community to reject\n"
14751 "Specify large community to accept\n"
14752 LCOMMUNITY_VAL_STR)
14753 {
14754 return lcommunity_list_set_vty(vty, argc, argv,
14755 LARGE_COMMUNITY_LIST_STANDARD, 1);
14756 }
14757
14758 ALIAS (lcommunity_list_name_standard1,
14759 ip_lcommunity_list_name_standard1_cmd,
14760 "ip large-community-list standard WORD <deny|permit> AA:BB:CC...",
14761 IP_STR
14762 LCOMMUNITY_LIST_STR
14763 "Specify standard large-community-list\n"
14764 "Large Community list name\n"
14765 "Specify large community to reject\n"
14766 "Specify large community to accept\n"
14767 LCOMMUNITY_VAL_STR)
14768
14769 DEFUN (lcommunity_list_name_expanded,
14770 bgp_lcommunity_list_name_expanded_cmd,
14771 "bgp large-community-list expanded WORD <deny|permit> LINE...",
14772 BGP_STR
14773 LCOMMUNITY_LIST_STR
14774 "Specify expanded large-community-list\n"
14775 "Large Community list name\n"
14776 "Specify large community to reject\n"
14777 "Specify large community to accept\n"
14778 "An ordered list as a regular-expression\n")
14779 {
14780 return lcommunity_list_set_vty(vty, argc, argv,
14781 LARGE_COMMUNITY_LIST_EXPANDED, 1);
14782 }
14783
14784 ALIAS (lcommunity_list_name_expanded,
14785 ip_lcommunity_list_name_expanded_cmd,
14786 "ip large-community-list expanded WORD <deny|permit> LINE...",
14787 IP_STR
14788 LCOMMUNITY_LIST_STR
14789 "Specify expanded large-community-list\n"
14790 "Large Community list name\n"
14791 "Specify large community to reject\n"
14792 "Specify large community to accept\n"
14793 "An ordered list as a regular-expression\n")
14794
14795 DEFUN (no_lcommunity_list_standard_all,
14796 no_bgp_lcommunity_list_standard_all_cmd,
14797 "no bgp large-community-list <(1-99)|(100-500)|WORD>",
14798 NO_STR
14799 BGP_STR
14800 LCOMMUNITY_LIST_STR
14801 "Large Community list number (standard)\n"
14802 "Large Community list number (expanded)\n"
14803 "Large Community list name\n")
14804 {
14805 return lcommunity_list_unset_vty(vty, argc, argv,
14806 LARGE_COMMUNITY_LIST_STANDARD);
14807 }
14808
14809 ALIAS (no_lcommunity_list_standard_all,
14810 no_ip_lcommunity_list_standard_all_cmd,
14811 "no ip large-community-list <(1-99)|(100-500)|WORD>",
14812 NO_STR
14813 IP_STR
14814 LCOMMUNITY_LIST_STR
14815 "Large Community list number (standard)\n"
14816 "Large Community list number (expanded)\n"
14817 "Large Community list name\n")
14818
14819 DEFUN (no_lcommunity_list_name_expanded_all,
14820 no_bgp_lcommunity_list_name_expanded_all_cmd,
14821 "no bgp large-community-list expanded WORD",
14822 NO_STR
14823 BGP_STR
14824 LCOMMUNITY_LIST_STR
14825 "Specify expanded large-community-list\n"
14826 "Large Community list name\n")
14827 {
14828 return lcommunity_list_unset_vty(vty, argc, argv,
14829 LARGE_COMMUNITY_LIST_EXPANDED);
14830 }
14831
14832 ALIAS (no_lcommunity_list_name_expanded_all,
14833 no_ip_lcommunity_list_name_expanded_all_cmd,
14834 "no ip large-community-list expanded WORD",
14835 NO_STR
14836 IP_STR
14837 LCOMMUNITY_LIST_STR
14838 "Specify expanded large-community-list\n"
14839 "Large Community list name\n")
14840
14841 DEFUN (no_lcommunity_list_standard,
14842 no_bgp_lcommunity_list_standard_cmd,
14843 "no bgp large-community-list (1-99) <deny|permit> AA:AA:NN...",
14844 NO_STR
14845 BGP_STR
14846 LCOMMUNITY_LIST_STR
14847 "Large Community list number (standard)\n"
14848 "Specify large community to reject\n"
14849 "Specify large community to accept\n"
14850 LCOMMUNITY_VAL_STR)
14851 {
14852 return lcommunity_list_unset_vty(vty, argc, argv,
14853 LARGE_COMMUNITY_LIST_STANDARD);
14854 }
14855
14856 ALIAS (no_lcommunity_list_standard,
14857 no_ip_lcommunity_list_standard_cmd,
14858 "no ip large-community-list (1-99) <deny|permit> AA:AA:NN...",
14859 NO_STR
14860 IP_STR
14861 LCOMMUNITY_LIST_STR
14862 "Large Community list number (standard)\n"
14863 "Specify large community to reject\n"
14864 "Specify large community to accept\n"
14865 LCOMMUNITY_VAL_STR)
14866
14867 DEFUN (no_lcommunity_list_expanded,
14868 no_bgp_lcommunity_list_expanded_cmd,
14869 "no bgp large-community-list (100-500) <deny|permit> LINE...",
14870 NO_STR
14871 BGP_STR
14872 LCOMMUNITY_LIST_STR
14873 "Large Community list number (expanded)\n"
14874 "Specify large community to reject\n"
14875 "Specify large community to accept\n"
14876 "An ordered list as a regular-expression\n")
14877 {
14878 return lcommunity_list_unset_vty(vty, argc, argv,
14879 LARGE_COMMUNITY_LIST_EXPANDED);
14880 }
14881
14882 ALIAS (no_lcommunity_list_expanded,
14883 no_ip_lcommunity_list_expanded_cmd,
14884 "no ip large-community-list (100-500) <deny|permit> LINE...",
14885 NO_STR
14886 IP_STR
14887 LCOMMUNITY_LIST_STR
14888 "Large Community list number (expanded)\n"
14889 "Specify large community to reject\n"
14890 "Specify large community to accept\n"
14891 "An ordered list as a regular-expression\n")
14892
14893 DEFUN (no_lcommunity_list_name_standard,
14894 no_bgp_lcommunity_list_name_standard_cmd,
14895 "no bgp large-community-list standard WORD <deny|permit> AA:AA:NN...",
14896 NO_STR
14897 BGP_STR
14898 LCOMMUNITY_LIST_STR
14899 "Specify standard large-community-list\n"
14900 "Large Community list name\n"
14901 "Specify large community to reject\n"
14902 "Specify large community to accept\n"
14903 LCOMMUNITY_VAL_STR)
14904 {
14905 return lcommunity_list_unset_vty(vty, argc, argv,
14906 LARGE_COMMUNITY_LIST_STANDARD);
14907 }
14908
14909 ALIAS (no_lcommunity_list_name_standard,
14910 no_ip_lcommunity_list_name_standard_cmd,
14911 "no ip large-community-list standard WORD <deny|permit> AA:AA:NN...",
14912 NO_STR
14913 IP_STR
14914 LCOMMUNITY_LIST_STR
14915 "Specify standard large-community-list\n"
14916 "Large Community list name\n"
14917 "Specify large community to reject\n"
14918 "Specify large community to accept\n"
14919 LCOMMUNITY_VAL_STR)
14920
14921 DEFUN (no_lcommunity_list_name_expanded,
14922 no_bgp_lcommunity_list_name_expanded_cmd,
14923 "no bgp large-community-list expanded WORD <deny|permit> LINE...",
14924 NO_STR
14925 BGP_STR
14926 LCOMMUNITY_LIST_STR
14927 "Specify expanded large-community-list\n"
14928 "Large community list name\n"
14929 "Specify large community to reject\n"
14930 "Specify large community to accept\n"
14931 "An ordered list as a regular-expression\n")
14932 {
14933 return lcommunity_list_unset_vty(vty, argc, argv,
14934 LARGE_COMMUNITY_LIST_EXPANDED);
14935 }
14936
14937 ALIAS (no_lcommunity_list_name_expanded,
14938 no_ip_lcommunity_list_name_expanded_cmd,
14939 "no ip large-community-list expanded WORD <deny|permit> LINE...",
14940 NO_STR
14941 IP_STR
14942 LCOMMUNITY_LIST_STR
14943 "Specify expanded large-community-list\n"
14944 "Large community list name\n"
14945 "Specify large community to reject\n"
14946 "Specify large community to accept\n"
14947 "An ordered list as a regular-expression\n")
14948
14949 static void lcommunity_list_show(struct vty *vty, struct community_list *list)
14950 {
14951 struct community_entry *entry;
14952
14953 for (entry = list->head; entry; entry = entry->next) {
14954 if (entry == list->head) {
14955 if (all_digit(list->name))
14956 vty_out(vty, "Large community %s list %s\n",
14957 entry->style == EXTCOMMUNITY_LIST_STANDARD
14958 ? "standard"
14959 : "(expanded) access",
14960 list->name);
14961 else
14962 vty_out(vty,
14963 "Named large community %s list %s\n",
14964 entry->style == EXTCOMMUNITY_LIST_STANDARD
14965 ? "standard"
14966 : "expanded",
14967 list->name);
14968 }
14969 if (entry->any)
14970 vty_out(vty, " %s\n",
14971 community_direct_str(entry->direct));
14972 else
14973 vty_out(vty, " %s %s\n",
14974 community_direct_str(entry->direct),
14975 community_list_config_str(entry));
14976 }
14977 }
14978
14979 DEFUN (show_lcommunity_list,
14980 show_bgp_lcommunity_list_cmd,
14981 "show bgp large-community-list",
14982 SHOW_STR
14983 BGP_STR
14984 "List large-community list\n")
14985 {
14986 struct community_list *list;
14987 struct community_list_master *cm;
14988 int idx = 0;
14989
14990 if (argv_find(argv, argc, "ip", &idx)) {
14991 vty_out(vty, "This config option is deprecated, and is scheduled for removal.\n");
14992 vty_out(vty, "if you are using this please migrate to the below command.\n");
14993 vty_out(vty, "'show bgp large-community-list <(1-500)|WORD>'\n");
14994 zlog_warn("Deprecated option: 'ip show large-community-list <(1-500)|WORD>' being used");
14995 }
14996
14997 cm = community_list_master_lookup(bgp_clist,
14998 LARGE_COMMUNITY_LIST_MASTER);
14999 if (!cm)
15000 return CMD_SUCCESS;
15001
15002 for (list = cm->num.head; list; list = list->next)
15003 lcommunity_list_show(vty, list);
15004
15005 for (list = cm->str.head; list; list = list->next)
15006 lcommunity_list_show(vty, list);
15007
15008 return CMD_SUCCESS;
15009 }
15010
15011 ALIAS (show_lcommunity_list,
15012 show_ip_lcommunity_list_cmd,
15013 "show ip large-community-list",
15014 SHOW_STR
15015 IP_STR
15016 "List large-community list\n")
15017
15018 DEFUN (show_lcommunity_list_arg,
15019 show_bgp_lcommunity_list_arg_cmd,
15020 "show bgp large-community-list <(1-500)|WORD>",
15021 SHOW_STR
15022 BGP_STR
15023 "List large-community list\n"
15024 "large-community-list number\n"
15025 "large-community-list name\n")
15026 {
15027 struct community_list *list;
15028 int idx = 0;
15029
15030 if (argv_find(argv, argc, "ip", &idx)) {
15031 vty_out(vty, "This config option is deprecated, and is scheduled for removal.\n");
15032 vty_out(vty, "if you are using this please migrate to the below command.\n");
15033 vty_out(vty, "'show bgp large-community-list <(1-500)|WORD>'\n");
15034 zlog_warn("Deprecated option: 'ip show large-community-list <(1-500)|WORD>' being used");
15035 }
15036
15037 list = community_list_lookup(bgp_clist, argv[3]->arg, 0,
15038 LARGE_COMMUNITY_LIST_MASTER);
15039 if (!list) {
15040 vty_out(vty, "%% Can't find extcommunity-list\n");
15041 return CMD_WARNING;
15042 }
15043
15044 lcommunity_list_show(vty, list);
15045
15046 return CMD_SUCCESS;
15047 }
15048
15049 ALIAS (show_lcommunity_list_arg,
15050 show_ip_lcommunity_list_arg_cmd,
15051 "show ip large-community-list <(1-500)|WORD>",
15052 SHOW_STR
15053 IP_STR
15054 "List large-community list\n"
15055 "large-community-list number\n"
15056 "large-community-list name\n")
15057
15058 /* "extcommunity-list" keyword help string. */
15059 #define EXTCOMMUNITY_LIST_STR "Add a extended community list entry\n"
15060 #define EXTCOMMUNITY_VAL_STR "Extended community attribute in 'rt aa:nn_or_IPaddr:nn' OR 'soo aa:nn_or_IPaddr:nn' format\n"
15061
15062 DEFUN (extcommunity_list_standard,
15063 bgp_extcommunity_list_standard_cmd,
15064 "bgp extcommunity-list <(1-99)|standard WORD> <deny|permit> AA:NN...",
15065 BGP_STR
15066 EXTCOMMUNITY_LIST_STR
15067 "Extended Community list number (standard)\n"
15068 "Specify standard extcommunity-list\n"
15069 "Community list name\n"
15070 "Specify community to reject\n"
15071 "Specify community to accept\n"
15072 EXTCOMMUNITY_VAL_STR)
15073 {
15074 int style = EXTCOMMUNITY_LIST_STANDARD;
15075 int direct = 0;
15076 char *cl_number_or_name = NULL;
15077
15078 int idx = 0;
15079 if (argv_find(argv, argc, "ip", &idx)) {
15080 vty_out(vty, "This config option is deprecated, and is scheduled for removal.\n");
15081 vty_out(vty, "if you are using this please migrate to the below command.\n");
15082 vty_out(vty, "'bgp extcommunity-list <(1-99)|(100-500)|standard|expanded> <deny|permit> <LINE|AA:NN>'\n");
15083 zlog_warn("Deprecated option: 'ip extcommunity-list <(1-99)|(100-500)|standard|expanded> <deny|permit> <LINE|AA:NN>' being used");
15084 }
15085 argv_find(argv, argc, "(1-99)", &idx);
15086 argv_find(argv, argc, "WORD", &idx);
15087 cl_number_or_name = argv[idx]->arg;
15088 direct = argv_find(argv, argc, "permit", &idx) ? COMMUNITY_PERMIT
15089 : COMMUNITY_DENY;
15090 argv_find(argv, argc, "AA:NN", &idx);
15091 char *str = argv_concat(argv, argc, idx);
15092
15093 int ret = extcommunity_list_set(bgp_clist, cl_number_or_name, str,
15094 direct, style);
15095
15096 XFREE(MTYPE_TMP, str);
15097
15098 if (ret < 0) {
15099 community_list_perror(vty, ret);
15100 return CMD_WARNING_CONFIG_FAILED;
15101 }
15102
15103 return CMD_SUCCESS;
15104 }
15105
15106 #if CONFDATE > 20191005
15107 CPP_NOTICE("bgpd: remove deprecated 'ip extcommunity-list <(1-99)|(100-500)|standard|expanded> <deny|permit> <LINE|AA:NN>' command")
15108 #endif
15109 ALIAS (extcommunity_list_standard,
15110 ip_extcommunity_list_standard_cmd,
15111 "ip extcommunity-list <(1-99)|standard WORD> <deny|permit> AA:NN...",
15112 IP_STR
15113 EXTCOMMUNITY_LIST_STR
15114 "Extended Community list number (standard)\n"
15115 "Specify standard extcommunity-list\n"
15116 "Community list name\n"
15117 "Specify community to reject\n"
15118 "Specify community to accept\n"
15119 EXTCOMMUNITY_VAL_STR)
15120
15121 DEFUN (extcommunity_list_name_expanded,
15122 bgp_extcommunity_list_name_expanded_cmd,
15123 "bgp extcommunity-list <(100-500)|expanded WORD> <deny|permit> LINE...",
15124 BGP_STR
15125 EXTCOMMUNITY_LIST_STR
15126 "Extended Community list number (expanded)\n"
15127 "Specify expanded extcommunity-list\n"
15128 "Extended Community list name\n"
15129 "Specify community to reject\n"
15130 "Specify community to accept\n"
15131 "An ordered list as a regular-expression\n")
15132 {
15133 int style = EXTCOMMUNITY_LIST_EXPANDED;
15134 int direct = 0;
15135 char *cl_number_or_name = NULL;
15136
15137 int idx = 0;
15138 if (argv_find(argv, argc, "ip", &idx)) {
15139 vty_out(vty, "This config option is deprecated, and is scheduled for removal.\n");
15140 vty_out(vty, "if you are using this please migrate to the below command.\n");
15141 vty_out(vty, "'extcommunity-list <(1-99)|(100-500)|standard|expanded> <deny|permit> <LINE|AA:NN>'\n");
15142 zlog_warn("Deprecated option: ‘ip extcommunity-list <(1-99)|(100-500)|standard|expanded> <deny|permit> <LINE|AA:NN>' being used");
15143 }
15144
15145 argv_find(argv, argc, "(100-500)", &idx);
15146 argv_find(argv, argc, "WORD", &idx);
15147 cl_number_or_name = argv[idx]->arg;
15148 direct = argv_find(argv, argc, "permit", &idx) ? COMMUNITY_PERMIT
15149 : COMMUNITY_DENY;
15150 argv_find(argv, argc, "LINE", &idx);
15151 char *str = argv_concat(argv, argc, idx);
15152
15153 int ret = extcommunity_list_set(bgp_clist, cl_number_or_name, str,
15154 direct, style);
15155
15156 XFREE(MTYPE_TMP, str);
15157
15158 if (ret < 0) {
15159 community_list_perror(vty, ret);
15160 return CMD_WARNING_CONFIG_FAILED;
15161 }
15162
15163 return CMD_SUCCESS;
15164 }
15165
15166 ALIAS (extcommunity_list_name_expanded,
15167 ip_extcommunity_list_name_expanded_cmd,
15168 "ip extcommunity-list <(100-500)|expanded WORD> <deny|permit> LINE...",
15169 IP_STR
15170 EXTCOMMUNITY_LIST_STR
15171 "Extended Community list number (expanded)\n"
15172 "Specify expanded extcommunity-list\n"
15173 "Extended Community list name\n"
15174 "Specify community to reject\n"
15175 "Specify community to accept\n"
15176 "An ordered list as a regular-expression\n")
15177
15178 DEFUN (no_extcommunity_list_standard_all,
15179 no_bgp_extcommunity_list_standard_all_cmd,
15180 "no bgp extcommunity-list <(1-99)|standard WORD> <deny|permit> AA:NN...",
15181 NO_STR
15182 BGP_STR
15183 EXTCOMMUNITY_LIST_STR
15184 "Extended Community list number (standard)\n"
15185 "Specify standard extcommunity-list\n"
15186 "Community list name\n"
15187 "Specify community to reject\n"
15188 "Specify community to accept\n"
15189 EXTCOMMUNITY_VAL_STR)
15190 {
15191 int style = EXTCOMMUNITY_LIST_STANDARD;
15192 int direct = 0;
15193 char *cl_number_or_name = NULL;
15194 char *str = NULL;
15195
15196 int idx = 0;
15197 if (argv_find(argv, argc, "ip", &idx)) {
15198 vty_out(vty, "This config option is deprecated, and is scheduled for removal\n");
15199 vty_out(vty, "if you are using this please migrate to the below command.\n");
15200 vty_out(vty, "'no bgp extcommunity-list <(1-99)|(100-500)|standard|expanded> <deny|permit> <LINE|AA:NN>'\n");
15201 zlog_warn("Deprecated option: ‘no ip extcommunity-list <(1-99)|(100-500)|standard|expanded> <deny|permit> <LINE|AA:NN>' being used");
15202 }
15203
15204 idx = 0;
15205 argv_find(argv, argc, "permit", &idx);
15206 argv_find(argv, argc, "deny", &idx);
15207
15208 if (idx) {
15209 direct = argv_find(argv, argc, "permit", &idx)
15210 ? COMMUNITY_PERMIT
15211 : COMMUNITY_DENY;
15212
15213 idx = 0;
15214 argv_find(argv, argc, "AA:NN", &idx);
15215 str = argv_concat(argv, argc, idx);
15216 }
15217
15218 idx = 0;
15219 argv_find(argv, argc, "(1-99)", &idx);
15220 argv_find(argv, argc, "WORD", &idx);
15221 cl_number_or_name = argv[idx]->arg;
15222
15223 int ret = extcommunity_list_unset(bgp_clist, cl_number_or_name, str,
15224 direct, style);
15225
15226 XFREE(MTYPE_TMP, str);
15227
15228 if (ret < 0) {
15229 community_list_perror(vty, ret);
15230 return CMD_WARNING_CONFIG_FAILED;
15231 }
15232
15233 return CMD_SUCCESS;
15234 }
15235
15236 ALIAS (no_extcommunity_list_standard_all,
15237 no_ip_extcommunity_list_standard_all_cmd,
15238 "no ip extcommunity-list <(1-99)|standard WORD> <deny|permit> AA:NN...",
15239 NO_STR
15240 IP_STR
15241 EXTCOMMUNITY_LIST_STR
15242 "Extended Community list number (standard)\n"
15243 "Specify standard extcommunity-list\n"
15244 "Community list name\n"
15245 "Specify community to reject\n"
15246 "Specify community to accept\n"
15247 EXTCOMMUNITY_VAL_STR)
15248
15249 ALIAS(no_extcommunity_list_standard_all,
15250 no_bgp_extcommunity_list_standard_all_list_cmd,
15251 "no bgp extcommunity-list <(1-99)|standard WORD>",
15252 NO_STR IP_STR EXTCOMMUNITY_LIST_STR
15253 "Extended Community list number (standard)\n"
15254 "Specify standard extcommunity-list\n"
15255 "Community list name\n")
15256
15257 ALIAS(no_extcommunity_list_standard_all,
15258 no_ip_extcommunity_list_standard_all_list_cmd,
15259 "no ip extcommunity-list <(1-99)|standard WORD>",
15260 NO_STR IP_STR EXTCOMMUNITY_LIST_STR
15261 "Extended Community list number (standard)\n"
15262 "Specify standard extcommunity-list\n"
15263 "Community list name\n")
15264
15265 DEFUN (no_extcommunity_list_expanded_all,
15266 no_bgp_extcommunity_list_expanded_all_cmd,
15267 "no bgp extcommunity-list <(100-500)|expanded WORD> <deny|permit> LINE...",
15268 NO_STR
15269 BGP_STR
15270 EXTCOMMUNITY_LIST_STR
15271 "Extended Community list number (expanded)\n"
15272 "Specify expanded extcommunity-list\n"
15273 "Extended Community list name\n"
15274 "Specify community to reject\n"
15275 "Specify community to accept\n"
15276 "An ordered list as a regular-expression\n")
15277 {
15278 int style = EXTCOMMUNITY_LIST_EXPANDED;
15279 int direct = 0;
15280 char *cl_number_or_name = NULL;
15281 char *str = NULL;
15282
15283 int idx = 0;
15284 if (argv_find(argv, argc, "ip", &idx)) {
15285 vty_out(vty, "This config option is deprecated, and is scheduled for removal.\n");
15286 vty_out(vty, "if you are using this please migrate to the below command.\n");
15287 vty_out(vty, "'no bgp extcommunity-list <(1-99)|(100-500)|standard|expanded> <deny|permit> <LINE|AA:NN>'\n");
15288 zlog_warn("Deprecated option: ‘no ip extcommunity-list <(1-99)|(100-500)|standard|expanded> <deny|permit> <LINE|AA:NN>' being used");
15289 }
15290
15291 idx = 0;
15292 argv_find(argv, argc, "permit", &idx);
15293 argv_find(argv, argc, "deny", &idx);
15294
15295 if (idx) {
15296 direct = argv_find(argv, argc, "permit", &idx)
15297 ? COMMUNITY_PERMIT
15298 : COMMUNITY_DENY;
15299
15300 idx = 0;
15301 argv_find(argv, argc, "LINE", &idx);
15302 str = argv_concat(argv, argc, idx);
15303 }
15304
15305 idx = 0;
15306 argv_find(argv, argc, "(100-500)", &idx);
15307 argv_find(argv, argc, "WORD", &idx);
15308 cl_number_or_name = argv[idx]->arg;
15309
15310 int ret = extcommunity_list_unset(bgp_clist, cl_number_or_name, str,
15311 direct, style);
15312
15313 XFREE(MTYPE_TMP, str);
15314
15315 if (ret < 0) {
15316 community_list_perror(vty, ret);
15317 return CMD_WARNING_CONFIG_FAILED;
15318 }
15319
15320 return CMD_SUCCESS;
15321 }
15322
15323 ALIAS (no_extcommunity_list_expanded_all,
15324 no_ip_extcommunity_list_expanded_all_cmd,
15325 "no ip extcommunity-list <(100-500)|expanded WORD> <deny|permit> LINE...",
15326 NO_STR
15327 IP_STR
15328 EXTCOMMUNITY_LIST_STR
15329 "Extended Community list number (expanded)\n"
15330 "Specify expanded extcommunity-list\n"
15331 "Extended Community list name\n"
15332 "Specify community to reject\n"
15333 "Specify community to accept\n"
15334 "An ordered list as a regular-expression\n")
15335
15336 ALIAS(no_extcommunity_list_expanded_all,
15337 no_ip_extcommunity_list_expanded_all_list_cmd,
15338 "no ip extcommunity-list <(100-500)|expanded WORD>",
15339 NO_STR IP_STR EXTCOMMUNITY_LIST_STR
15340 "Extended Community list number (expanded)\n"
15341 "Specify expanded extcommunity-list\n"
15342 "Extended Community list name\n")
15343
15344 ALIAS(no_extcommunity_list_expanded_all,
15345 no_bgp_extcommunity_list_expanded_all_list_cmd,
15346 "no bgp extcommunity-list <(100-500)|expanded WORD>",
15347 NO_STR IP_STR EXTCOMMUNITY_LIST_STR
15348 "Extended Community list number (expanded)\n"
15349 "Specify expanded extcommunity-list\n"
15350 "Extended Community list name\n")
15351
15352 static void extcommunity_list_show(struct vty *vty, struct community_list *list)
15353 {
15354 struct community_entry *entry;
15355
15356 for (entry = list->head; entry; entry = entry->next) {
15357 if (entry == list->head) {
15358 if (all_digit(list->name))
15359 vty_out(vty, "Extended community %s list %s\n",
15360 entry->style == EXTCOMMUNITY_LIST_STANDARD
15361 ? "standard"
15362 : "(expanded) access",
15363 list->name);
15364 else
15365 vty_out(vty,
15366 "Named extended community %s list %s\n",
15367 entry->style == EXTCOMMUNITY_LIST_STANDARD
15368 ? "standard"
15369 : "expanded",
15370 list->name);
15371 }
15372 if (entry->any)
15373 vty_out(vty, " %s\n",
15374 community_direct_str(entry->direct));
15375 else
15376 vty_out(vty, " %s %s\n",
15377 community_direct_str(entry->direct),
15378 community_list_config_str(entry));
15379 }
15380 }
15381
15382 DEFUN (show_extcommunity_list,
15383 show_bgp_extcommunity_list_cmd,
15384 "show bgp extcommunity-list",
15385 SHOW_STR
15386 BGP_STR
15387 "List extended-community list\n")
15388 {
15389 struct community_list *list;
15390 struct community_list_master *cm;
15391 int idx = 0;
15392
15393 if (argv_find(argv, argc, "ip", &idx)) {
15394 vty_out(vty, "This config option is deprecated, and is scheduled for removal\n");
15395 vty_out(vty, "if you are using this please migrate to the below command.\n");
15396 vty_out(vty, "'show bgp extcommunity-list <(1-500)|WORD>'\n");
15397 zlog_warn("Deprecated option: 'ip show extcommunity-list <(1-500)|WORD>' being used");
15398 }
15399 cm = community_list_master_lookup(bgp_clist, EXTCOMMUNITY_LIST_MASTER);
15400 if (!cm)
15401 return CMD_SUCCESS;
15402
15403 for (list = cm->num.head; list; list = list->next)
15404 extcommunity_list_show(vty, list);
15405
15406 for (list = cm->str.head; list; list = list->next)
15407 extcommunity_list_show(vty, list);
15408
15409 return CMD_SUCCESS;
15410 }
15411
15412 ALIAS (show_extcommunity_list,
15413 show_ip_extcommunity_list_cmd,
15414 "show ip extcommunity-list",
15415 SHOW_STR
15416 IP_STR
15417 "List extended-community list\n")
15418
15419 DEFUN (show_extcommunity_list_arg,
15420 show_bgp_extcommunity_list_arg_cmd,
15421 "show bgp extcommunity-list <(1-500)|WORD>",
15422 SHOW_STR
15423 BGP_STR
15424 "List extended-community list\n"
15425 "Extcommunity-list number\n"
15426 "Extcommunity-list name\n")
15427 {
15428 int idx_comm_list = 3;
15429 struct community_list *list;
15430 int idx = 0;
15431
15432 if (argv_find(argv, argc, "ip", &idx)) {
15433 vty_out(vty, "This config option is deprecated, and is scheduled for removal.\n");
15434 vty_out(vty, "if you are using this please migrate to the below command.\n");
15435 vty_out(vty, "'show bgp extcommunity-list <(1-500)|WORD>'\n");
15436 zlog_warn("Deprecated option: 'ip show extcommunity-list <(1-500)|WORD>' being used");
15437 }
15438 list = community_list_lookup(bgp_clist, argv[idx_comm_list]->arg, 0,
15439 EXTCOMMUNITY_LIST_MASTER);
15440 if (!list) {
15441 vty_out(vty, "%% Can't find extcommunity-list\n");
15442 return CMD_WARNING;
15443 }
15444
15445 extcommunity_list_show(vty, list);
15446
15447 return CMD_SUCCESS;
15448 }
15449
15450 ALIAS (show_extcommunity_list_arg,
15451 show_ip_extcommunity_list_arg_cmd,
15452 "show ip extcommunity-list <(1-500)|WORD>",
15453 SHOW_STR
15454 IP_STR
15455 "List extended-community list\n"
15456 "Extcommunity-list number\n"
15457 "Extcommunity-list name\n")
15458
15459 /* Display community-list and extcommunity-list configuration. */
15460 static int community_list_config_write(struct vty *vty)
15461 {
15462 struct community_list *list;
15463 struct community_entry *entry;
15464 struct community_list_master *cm;
15465 int write = 0;
15466
15467 /* Community-list. */
15468 cm = community_list_master_lookup(bgp_clist, COMMUNITY_LIST_MASTER);
15469
15470 for (list = cm->num.head; list; list = list->next)
15471 for (entry = list->head; entry; entry = entry->next) {
15472 vty_out(vty, "bgp community-list %s %s %s\n", list->name,
15473 community_direct_str(entry->direct),
15474 community_list_config_str(entry));
15475 write++;
15476 }
15477 for (list = cm->str.head; list; list = list->next)
15478 for (entry = list->head; entry; entry = entry->next) {
15479 vty_out(vty, "bgp community-list %s %s %s %s\n",
15480 entry->style == COMMUNITY_LIST_STANDARD
15481 ? "standard"
15482 : "expanded",
15483 list->name, community_direct_str(entry->direct),
15484 community_list_config_str(entry));
15485 write++;
15486 }
15487
15488 /* Extcommunity-list. */
15489 cm = community_list_master_lookup(bgp_clist, EXTCOMMUNITY_LIST_MASTER);
15490
15491 for (list = cm->num.head; list; list = list->next)
15492 for (entry = list->head; entry; entry = entry->next) {
15493 vty_out(vty, "bgp extcommunity-list %s %s %s\n",
15494 list->name, community_direct_str(entry->direct),
15495 community_list_config_str(entry));
15496 write++;
15497 }
15498 for (list = cm->str.head; list; list = list->next)
15499 for (entry = list->head; entry; entry = entry->next) {
15500 vty_out(vty, "bgp extcommunity-list %s %s %s %s\n",
15501 entry->style == EXTCOMMUNITY_LIST_STANDARD
15502 ? "standard"
15503 : "expanded",
15504 list->name, community_direct_str(entry->direct),
15505 community_list_config_str(entry));
15506 write++;
15507 }
15508
15509
15510 /* lcommunity-list. */
15511 cm = community_list_master_lookup(bgp_clist,
15512 LARGE_COMMUNITY_LIST_MASTER);
15513
15514 for (list = cm->num.head; list; list = list->next)
15515 for (entry = list->head; entry; entry = entry->next) {
15516 vty_out(vty, "bgp large-community-list %s %s %s\n",
15517 list->name, community_direct_str(entry->direct),
15518 community_list_config_str(entry));
15519 write++;
15520 }
15521 for (list = cm->str.head; list; list = list->next)
15522 for (entry = list->head; entry; entry = entry->next) {
15523 vty_out(vty, "bgp large-community-list %s %s %s %s\n",
15524 entry->style == LARGE_COMMUNITY_LIST_STANDARD
15525 ? "standard"
15526 : "expanded",
15527 list->name, community_direct_str(entry->direct),
15528 community_list_config_str(entry));
15529 write++;
15530 }
15531
15532 return write;
15533 }
15534
15535 static struct cmd_node community_list_node = {
15536 COMMUNITY_LIST_NODE, "", 1 /* Export to vtysh. */
15537 };
15538
15539 static void community_list_vty(void)
15540 {
15541 install_node(&community_list_node, community_list_config_write);
15542
15543 /* Community-list. */
15544 install_element(CONFIG_NODE, &bgp_community_list_standard_cmd);
15545 install_element(CONFIG_NODE, &bgp_community_list_expanded_all_cmd);
15546 install_element(CONFIG_NODE, &no_bgp_community_list_standard_all_cmd);
15547 install_element(CONFIG_NODE, &no_bgp_community_list_standard_all_list_cmd);
15548 install_element(CONFIG_NODE, &no_bgp_community_list_expanded_all_cmd);
15549 install_element(CONFIG_NODE, &no_bgp_community_list_expanded_all_list_cmd);
15550 install_element(VIEW_NODE, &show_bgp_community_list_cmd);
15551 install_element(VIEW_NODE, &show_bgp_community_list_arg_cmd);
15552 install_element(CONFIG_NODE, &ip_community_list_standard_cmd);
15553 install_element(CONFIG_NODE, &ip_community_list_expanded_all_cmd);
15554 install_element(CONFIG_NODE, &no_ip_community_list_standard_all_cmd);
15555 install_element(CONFIG_NODE, &no_ip_community_list_standard_all_list_cmd);
15556 install_element(CONFIG_NODE, &no_ip_community_list_expanded_all_cmd);
15557 install_element(CONFIG_NODE, &no_ip_community_list_expanded_all_list_cmd);
15558 install_element(VIEW_NODE, &show_ip_community_list_cmd);
15559 install_element(VIEW_NODE, &show_ip_community_list_arg_cmd);
15560
15561 /* Extcommunity-list. */
15562 install_element(CONFIG_NODE, &bgp_extcommunity_list_standard_cmd);
15563 install_element(CONFIG_NODE, &bgp_extcommunity_list_name_expanded_cmd);
15564 install_element(CONFIG_NODE, &no_bgp_extcommunity_list_standard_all_cmd);
15565 install_element(CONFIG_NODE,
15566 &no_bgp_extcommunity_list_standard_all_list_cmd);
15567 install_element(CONFIG_NODE, &no_bgp_extcommunity_list_expanded_all_cmd);
15568 install_element(CONFIG_NODE,
15569 &no_bgp_extcommunity_list_expanded_all_list_cmd);
15570 install_element(VIEW_NODE, &show_bgp_extcommunity_list_cmd);
15571 install_element(VIEW_NODE, &show_bgp_extcommunity_list_arg_cmd);
15572 install_element(CONFIG_NODE, &ip_extcommunity_list_standard_cmd);
15573 install_element(CONFIG_NODE, &ip_extcommunity_list_name_expanded_cmd);
15574 install_element(CONFIG_NODE, &no_ip_extcommunity_list_standard_all_cmd);
15575 install_element(CONFIG_NODE, &no_ip_extcommunity_list_standard_all_list_cmd);
15576 install_element(CONFIG_NODE, &no_ip_extcommunity_list_expanded_all_cmd);
15577 install_element(CONFIG_NODE, &no_ip_extcommunity_list_expanded_all_list_cmd);
15578 install_element(VIEW_NODE, &show_ip_extcommunity_list_cmd);
15579 install_element(VIEW_NODE, &show_ip_extcommunity_list_arg_cmd);
15580
15581 /* Large Community List */
15582 install_element(CONFIG_NODE, &bgp_lcommunity_list_standard_cmd);
15583 install_element(CONFIG_NODE, &bgp_lcommunity_list_standard1_cmd);
15584 install_element(CONFIG_NODE, &bgp_lcommunity_list_expanded_cmd);
15585 install_element(CONFIG_NODE, &bgp_lcommunity_list_name_standard_cmd);
15586 install_element(CONFIG_NODE, &bgp_lcommunity_list_name_standard1_cmd);
15587 install_element(CONFIG_NODE, &bgp_lcommunity_list_name_expanded_cmd);
15588 install_element(CONFIG_NODE, &no_bgp_lcommunity_list_standard_all_cmd);
15589 install_element(CONFIG_NODE,
15590 &no_bgp_lcommunity_list_name_expanded_all_cmd);
15591 install_element(CONFIG_NODE, &no_bgp_lcommunity_list_standard_cmd);
15592 install_element(CONFIG_NODE, &no_bgp_lcommunity_list_expanded_cmd);
15593 install_element(CONFIG_NODE, &no_bgp_lcommunity_list_name_standard_cmd);
15594 install_element(CONFIG_NODE, &no_bgp_lcommunity_list_name_expanded_cmd);
15595 install_element(VIEW_NODE, &show_bgp_lcommunity_list_cmd);
15596 install_element(VIEW_NODE, &show_bgp_lcommunity_list_arg_cmd);
15597 install_element(CONFIG_NODE, &ip_lcommunity_list_standard_cmd);
15598 install_element(CONFIG_NODE, &ip_lcommunity_list_standard1_cmd);
15599 install_element(CONFIG_NODE, &ip_lcommunity_list_expanded_cmd);
15600 install_element(CONFIG_NODE, &ip_lcommunity_list_name_standard_cmd);
15601 install_element(CONFIG_NODE, &ip_lcommunity_list_name_standard1_cmd);
15602 install_element(CONFIG_NODE, &ip_lcommunity_list_name_expanded_cmd);
15603 install_element(CONFIG_NODE, &no_ip_lcommunity_list_standard_all_cmd);
15604 install_element(CONFIG_NODE,
15605 &no_ip_lcommunity_list_name_expanded_all_cmd);
15606 install_element(CONFIG_NODE, &no_ip_lcommunity_list_standard_cmd);
15607 install_element(CONFIG_NODE, &no_ip_lcommunity_list_expanded_cmd);
15608 install_element(CONFIG_NODE, &no_ip_lcommunity_list_name_standard_cmd);
15609 install_element(CONFIG_NODE, &no_ip_lcommunity_list_name_expanded_cmd);
15610 install_element(VIEW_NODE, &show_ip_lcommunity_list_cmd);
15611 install_element(VIEW_NODE, &show_ip_lcommunity_list_arg_cmd);
15612 }