]> git.proxmox.com Git - mirror_frr.git/blob - bgpd/bgp_vty.c
Merge pull request #3960 from donaldsharp/connected
[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 /* "bgp graceful-shutdown" configuration */
2059 DEFUN (bgp_graceful_shutdown,
2060 bgp_graceful_shutdown_cmd,
2061 "bgp graceful-shutdown",
2062 BGP_STR
2063 "Graceful shutdown parameters\n")
2064 {
2065 VTY_DECLVAR_CONTEXT(bgp, bgp);
2066
2067 if (!bgp_flag_check(bgp, BGP_FLAG_GRACEFUL_SHUTDOWN)) {
2068 bgp_flag_set(bgp, BGP_FLAG_GRACEFUL_SHUTDOWN);
2069 bgp_static_redo_import_check(bgp);
2070 bgp_redistribute_redo(bgp);
2071 bgp_clear_star_soft_out(vty, bgp->name);
2072 bgp_clear_star_soft_in(vty, bgp->name);
2073 }
2074
2075 return CMD_SUCCESS;
2076 }
2077
2078 DEFUN (no_bgp_graceful_shutdown,
2079 no_bgp_graceful_shutdown_cmd,
2080 "no bgp graceful-shutdown",
2081 NO_STR
2082 BGP_STR
2083 "Graceful shutdown parameters\n")
2084 {
2085 VTY_DECLVAR_CONTEXT(bgp, bgp);
2086
2087 if (bgp_flag_check(bgp, BGP_FLAG_GRACEFUL_SHUTDOWN)) {
2088 bgp_flag_unset(bgp, BGP_FLAG_GRACEFUL_SHUTDOWN);
2089 bgp_static_redo_import_check(bgp);
2090 bgp_redistribute_redo(bgp);
2091 bgp_clear_star_soft_out(vty, bgp->name);
2092 bgp_clear_star_soft_in(vty, bgp->name);
2093 }
2094
2095 return CMD_SUCCESS;
2096 }
2097
2098 /* "bgp fast-external-failover" configuration. */
2099 DEFUN (bgp_fast_external_failover,
2100 bgp_fast_external_failover_cmd,
2101 "bgp fast-external-failover",
2102 BGP_STR
2103 "Immediately reset session if a link to a directly connected external peer goes down\n")
2104 {
2105 VTY_DECLVAR_CONTEXT(bgp, bgp);
2106 bgp_flag_unset(bgp, BGP_FLAG_NO_FAST_EXT_FAILOVER);
2107 return CMD_SUCCESS;
2108 }
2109
2110 DEFUN (no_bgp_fast_external_failover,
2111 no_bgp_fast_external_failover_cmd,
2112 "no bgp fast-external-failover",
2113 NO_STR
2114 BGP_STR
2115 "Immediately reset session if a link to a directly connected external peer goes down\n")
2116 {
2117 VTY_DECLVAR_CONTEXT(bgp, bgp);
2118 bgp_flag_set(bgp, BGP_FLAG_NO_FAST_EXT_FAILOVER);
2119 return CMD_SUCCESS;
2120 }
2121
2122 /* "bgp enforce-first-as" configuration. */
2123 #if CONFDATE > 20190517
2124 CPP_NOTICE("bgpd: remove deprecated '[no] bgp enforce-first-as' commands")
2125 #endif
2126
2127 DEFUN_HIDDEN (bgp_enforce_first_as,
2128 bgp_enforce_first_as_cmd,
2129 "[no] bgp enforce-first-as",
2130 NO_STR
2131 BGP_STR
2132 "Enforce the first AS for EBGP routes\n")
2133 {
2134 VTY_DECLVAR_CONTEXT(bgp, bgp);
2135
2136 if (strmatch(argv[0]->text, "no"))
2137 bgp_flag_unset(bgp, BGP_FLAG_ENFORCE_FIRST_AS);
2138 else
2139 bgp_flag_set(bgp, BGP_FLAG_ENFORCE_FIRST_AS);
2140
2141 return CMD_SUCCESS;
2142 }
2143
2144 /* "bgp bestpath compare-routerid" configuration. */
2145 DEFUN (bgp_bestpath_compare_router_id,
2146 bgp_bestpath_compare_router_id_cmd,
2147 "bgp bestpath compare-routerid",
2148 "BGP specific commands\n"
2149 "Change the default bestpath selection\n"
2150 "Compare router-id for identical EBGP paths\n")
2151 {
2152 VTY_DECLVAR_CONTEXT(bgp, bgp);
2153 bgp_flag_set(bgp, BGP_FLAG_COMPARE_ROUTER_ID);
2154 bgp_recalculate_all_bestpaths(bgp);
2155
2156 return CMD_SUCCESS;
2157 }
2158
2159 DEFUN (no_bgp_bestpath_compare_router_id,
2160 no_bgp_bestpath_compare_router_id_cmd,
2161 "no bgp bestpath compare-routerid",
2162 NO_STR
2163 "BGP specific commands\n"
2164 "Change the default bestpath selection\n"
2165 "Compare router-id for identical EBGP paths\n")
2166 {
2167 VTY_DECLVAR_CONTEXT(bgp, bgp);
2168 bgp_flag_unset(bgp, BGP_FLAG_COMPARE_ROUTER_ID);
2169 bgp_recalculate_all_bestpaths(bgp);
2170
2171 return CMD_SUCCESS;
2172 }
2173
2174 /* "bgp bestpath as-path ignore" configuration. */
2175 DEFUN (bgp_bestpath_aspath_ignore,
2176 bgp_bestpath_aspath_ignore_cmd,
2177 "bgp bestpath as-path ignore",
2178 "BGP specific commands\n"
2179 "Change the default bestpath selection\n"
2180 "AS-path attribute\n"
2181 "Ignore as-path length in selecting a route\n")
2182 {
2183 VTY_DECLVAR_CONTEXT(bgp, bgp);
2184 bgp_flag_set(bgp, BGP_FLAG_ASPATH_IGNORE);
2185 bgp_recalculate_all_bestpaths(bgp);
2186
2187 return CMD_SUCCESS;
2188 }
2189
2190 DEFUN (no_bgp_bestpath_aspath_ignore,
2191 no_bgp_bestpath_aspath_ignore_cmd,
2192 "no bgp bestpath as-path ignore",
2193 NO_STR
2194 "BGP specific commands\n"
2195 "Change the default bestpath selection\n"
2196 "AS-path attribute\n"
2197 "Ignore as-path length in selecting a route\n")
2198 {
2199 VTY_DECLVAR_CONTEXT(bgp, bgp);
2200 bgp_flag_unset(bgp, BGP_FLAG_ASPATH_IGNORE);
2201 bgp_recalculate_all_bestpaths(bgp);
2202
2203 return CMD_SUCCESS;
2204 }
2205
2206 /* "bgp bestpath as-path confed" configuration. */
2207 DEFUN (bgp_bestpath_aspath_confed,
2208 bgp_bestpath_aspath_confed_cmd,
2209 "bgp bestpath as-path confed",
2210 "BGP specific commands\n"
2211 "Change the default bestpath selection\n"
2212 "AS-path attribute\n"
2213 "Compare path lengths including confederation sets & sequences in selecting a route\n")
2214 {
2215 VTY_DECLVAR_CONTEXT(bgp, bgp);
2216 bgp_flag_set(bgp, BGP_FLAG_ASPATH_CONFED);
2217 bgp_recalculate_all_bestpaths(bgp);
2218
2219 return CMD_SUCCESS;
2220 }
2221
2222 DEFUN (no_bgp_bestpath_aspath_confed,
2223 no_bgp_bestpath_aspath_confed_cmd,
2224 "no bgp bestpath as-path confed",
2225 NO_STR
2226 "BGP specific commands\n"
2227 "Change the default bestpath selection\n"
2228 "AS-path attribute\n"
2229 "Compare path lengths including confederation sets & sequences in selecting a route\n")
2230 {
2231 VTY_DECLVAR_CONTEXT(bgp, bgp);
2232 bgp_flag_unset(bgp, BGP_FLAG_ASPATH_CONFED);
2233 bgp_recalculate_all_bestpaths(bgp);
2234
2235 return CMD_SUCCESS;
2236 }
2237
2238 /* "bgp bestpath as-path multipath-relax" configuration. */
2239 DEFUN (bgp_bestpath_aspath_multipath_relax,
2240 bgp_bestpath_aspath_multipath_relax_cmd,
2241 "bgp bestpath as-path multipath-relax [<as-set|no-as-set>]",
2242 "BGP specific commands\n"
2243 "Change the default bestpath selection\n"
2244 "AS-path attribute\n"
2245 "Allow load sharing across routes that have different AS paths (but same length)\n"
2246 "Generate an AS_SET\n"
2247 "Do not generate an AS_SET\n")
2248 {
2249 VTY_DECLVAR_CONTEXT(bgp, bgp);
2250 int idx = 0;
2251 bgp_flag_set(bgp, BGP_FLAG_ASPATH_MULTIPATH_RELAX);
2252
2253 /* no-as-set is now the default behavior so we can silently
2254 * ignore it */
2255 if (argv_find(argv, argc, "as-set", &idx))
2256 bgp_flag_set(bgp, BGP_FLAG_MULTIPATH_RELAX_AS_SET);
2257 else
2258 bgp_flag_unset(bgp, BGP_FLAG_MULTIPATH_RELAX_AS_SET);
2259
2260 bgp_recalculate_all_bestpaths(bgp);
2261
2262 return CMD_SUCCESS;
2263 }
2264
2265 DEFUN (no_bgp_bestpath_aspath_multipath_relax,
2266 no_bgp_bestpath_aspath_multipath_relax_cmd,
2267 "no bgp bestpath as-path multipath-relax [<as-set|no-as-set>]",
2268 NO_STR
2269 "BGP specific commands\n"
2270 "Change the default bestpath selection\n"
2271 "AS-path attribute\n"
2272 "Allow load sharing across routes that have different AS paths (but same length)\n"
2273 "Generate an AS_SET\n"
2274 "Do not generate an AS_SET\n")
2275 {
2276 VTY_DECLVAR_CONTEXT(bgp, bgp);
2277 bgp_flag_unset(bgp, BGP_FLAG_ASPATH_MULTIPATH_RELAX);
2278 bgp_flag_unset(bgp, BGP_FLAG_MULTIPATH_RELAX_AS_SET);
2279 bgp_recalculate_all_bestpaths(bgp);
2280
2281 return CMD_SUCCESS;
2282 }
2283
2284 /* "bgp log-neighbor-changes" configuration. */
2285 DEFUN (bgp_log_neighbor_changes,
2286 bgp_log_neighbor_changes_cmd,
2287 "bgp log-neighbor-changes",
2288 "BGP specific commands\n"
2289 "Log neighbor up/down and reset reason\n")
2290 {
2291 VTY_DECLVAR_CONTEXT(bgp, bgp);
2292 bgp_flag_set(bgp, BGP_FLAG_LOG_NEIGHBOR_CHANGES);
2293 return CMD_SUCCESS;
2294 }
2295
2296 DEFUN (no_bgp_log_neighbor_changes,
2297 no_bgp_log_neighbor_changes_cmd,
2298 "no bgp log-neighbor-changes",
2299 NO_STR
2300 "BGP specific commands\n"
2301 "Log neighbor up/down and reset reason\n")
2302 {
2303 VTY_DECLVAR_CONTEXT(bgp, bgp);
2304 bgp_flag_unset(bgp, BGP_FLAG_LOG_NEIGHBOR_CHANGES);
2305 return CMD_SUCCESS;
2306 }
2307
2308 /* "bgp bestpath med" configuration. */
2309 DEFUN (bgp_bestpath_med,
2310 bgp_bestpath_med_cmd,
2311 "bgp bestpath med <confed [missing-as-worst]|missing-as-worst [confed]>",
2312 "BGP specific commands\n"
2313 "Change the default bestpath selection\n"
2314 "MED attribute\n"
2315 "Compare MED among confederation paths\n"
2316 "Treat missing MED as the least preferred one\n"
2317 "Treat missing MED as the least preferred one\n"
2318 "Compare MED among confederation paths\n")
2319 {
2320 VTY_DECLVAR_CONTEXT(bgp, bgp);
2321
2322 int idx = 0;
2323 if (argv_find(argv, argc, "confed", &idx))
2324 bgp_flag_set(bgp, BGP_FLAG_MED_CONFED);
2325 idx = 0;
2326 if (argv_find(argv, argc, "missing-as-worst", &idx))
2327 bgp_flag_set(bgp, BGP_FLAG_MED_MISSING_AS_WORST);
2328
2329 bgp_recalculate_all_bestpaths(bgp);
2330
2331 return CMD_SUCCESS;
2332 }
2333
2334 DEFUN (no_bgp_bestpath_med,
2335 no_bgp_bestpath_med_cmd,
2336 "no bgp bestpath med <confed [missing-as-worst]|missing-as-worst [confed]>",
2337 NO_STR
2338 "BGP specific commands\n"
2339 "Change the default bestpath selection\n"
2340 "MED attribute\n"
2341 "Compare MED among confederation paths\n"
2342 "Treat missing MED as the least preferred one\n"
2343 "Treat missing MED as the least preferred one\n"
2344 "Compare MED among confederation paths\n")
2345 {
2346 VTY_DECLVAR_CONTEXT(bgp, bgp);
2347
2348 int idx = 0;
2349 if (argv_find(argv, argc, "confed", &idx))
2350 bgp_flag_unset(bgp, BGP_FLAG_MED_CONFED);
2351 idx = 0;
2352 if (argv_find(argv, argc, "missing-as-worst", &idx))
2353 bgp_flag_unset(bgp, BGP_FLAG_MED_MISSING_AS_WORST);
2354
2355 bgp_recalculate_all_bestpaths(bgp);
2356
2357 return CMD_SUCCESS;
2358 }
2359
2360 /* "no bgp default ipv4-unicast". */
2361 DEFUN (no_bgp_default_ipv4_unicast,
2362 no_bgp_default_ipv4_unicast_cmd,
2363 "no bgp default ipv4-unicast",
2364 NO_STR
2365 "BGP specific commands\n"
2366 "Configure BGP defaults\n"
2367 "Activate ipv4-unicast for a peer by default\n")
2368 {
2369 VTY_DECLVAR_CONTEXT(bgp, bgp);
2370 bgp_flag_set(bgp, BGP_FLAG_NO_DEFAULT_IPV4);
2371 return CMD_SUCCESS;
2372 }
2373
2374 DEFUN (bgp_default_ipv4_unicast,
2375 bgp_default_ipv4_unicast_cmd,
2376 "bgp default ipv4-unicast",
2377 "BGP specific commands\n"
2378 "Configure BGP defaults\n"
2379 "Activate ipv4-unicast for a peer by default\n")
2380 {
2381 VTY_DECLVAR_CONTEXT(bgp, bgp);
2382 bgp_flag_unset(bgp, BGP_FLAG_NO_DEFAULT_IPV4);
2383 return CMD_SUCCESS;
2384 }
2385
2386 /* Display hostname in certain command outputs */
2387 DEFUN (bgp_default_show_hostname,
2388 bgp_default_show_hostname_cmd,
2389 "bgp default show-hostname",
2390 "BGP specific commands\n"
2391 "Configure BGP defaults\n"
2392 "Show hostname in certain command outputs\n")
2393 {
2394 VTY_DECLVAR_CONTEXT(bgp, bgp);
2395 bgp_flag_set(bgp, BGP_FLAG_SHOW_HOSTNAME);
2396 return CMD_SUCCESS;
2397 }
2398
2399 DEFUN (no_bgp_default_show_hostname,
2400 no_bgp_default_show_hostname_cmd,
2401 "no bgp default show-hostname",
2402 NO_STR
2403 "BGP specific commands\n"
2404 "Configure BGP defaults\n"
2405 "Show hostname in certain command outputs\n")
2406 {
2407 VTY_DECLVAR_CONTEXT(bgp, bgp);
2408 bgp_flag_unset(bgp, BGP_FLAG_SHOW_HOSTNAME);
2409 return CMD_SUCCESS;
2410 }
2411
2412 /* "bgp network import-check" configuration. */
2413 DEFUN (bgp_network_import_check,
2414 bgp_network_import_check_cmd,
2415 "bgp network import-check",
2416 "BGP specific commands\n"
2417 "BGP network command\n"
2418 "Check BGP network route exists in IGP\n")
2419 {
2420 VTY_DECLVAR_CONTEXT(bgp, bgp);
2421 if (!bgp_flag_check(bgp, BGP_FLAG_IMPORT_CHECK)) {
2422 bgp_flag_set(bgp, BGP_FLAG_IMPORT_CHECK);
2423 bgp_static_redo_import_check(bgp);
2424 }
2425
2426 return CMD_SUCCESS;
2427 }
2428
2429 ALIAS_HIDDEN(bgp_network_import_check, bgp_network_import_check_exact_cmd,
2430 "bgp network import-check exact",
2431 "BGP specific commands\n"
2432 "BGP network command\n"
2433 "Check BGP network route exists in IGP\n"
2434 "Match route precisely\n")
2435
2436 DEFUN (no_bgp_network_import_check,
2437 no_bgp_network_import_check_cmd,
2438 "no bgp network import-check",
2439 NO_STR
2440 "BGP specific commands\n"
2441 "BGP network command\n"
2442 "Check BGP network route exists in IGP\n")
2443 {
2444 VTY_DECLVAR_CONTEXT(bgp, bgp);
2445 if (bgp_flag_check(bgp, BGP_FLAG_IMPORT_CHECK)) {
2446 bgp_flag_unset(bgp, BGP_FLAG_IMPORT_CHECK);
2447 bgp_static_redo_import_check(bgp);
2448 }
2449
2450 return CMD_SUCCESS;
2451 }
2452
2453 DEFUN (bgp_default_local_preference,
2454 bgp_default_local_preference_cmd,
2455 "bgp default local-preference (0-4294967295)",
2456 "BGP specific commands\n"
2457 "Configure BGP defaults\n"
2458 "local preference (higher=more preferred)\n"
2459 "Configure default local preference value\n")
2460 {
2461 VTY_DECLVAR_CONTEXT(bgp, bgp);
2462 int idx_number = 3;
2463 uint32_t local_pref;
2464
2465 local_pref = strtoul(argv[idx_number]->arg, NULL, 10);
2466
2467 bgp_default_local_preference_set(bgp, local_pref);
2468 bgp_clear_star_soft_in(vty, bgp->name);
2469
2470 return CMD_SUCCESS;
2471 }
2472
2473 DEFUN (no_bgp_default_local_preference,
2474 no_bgp_default_local_preference_cmd,
2475 "no bgp default local-preference [(0-4294967295)]",
2476 NO_STR
2477 "BGP specific commands\n"
2478 "Configure BGP defaults\n"
2479 "local preference (higher=more preferred)\n"
2480 "Configure default local preference value\n")
2481 {
2482 VTY_DECLVAR_CONTEXT(bgp, bgp);
2483 bgp_default_local_preference_unset(bgp);
2484 bgp_clear_star_soft_in(vty, bgp->name);
2485
2486 return CMD_SUCCESS;
2487 }
2488
2489
2490 DEFUN (bgp_default_subgroup_pkt_queue_max,
2491 bgp_default_subgroup_pkt_queue_max_cmd,
2492 "bgp default subgroup-pkt-queue-max (20-100)",
2493 "BGP specific commands\n"
2494 "Configure BGP defaults\n"
2495 "subgroup-pkt-queue-max\n"
2496 "Configure subgroup packet queue max\n")
2497 {
2498 VTY_DECLVAR_CONTEXT(bgp, bgp);
2499 int idx_number = 3;
2500 uint32_t max_size;
2501
2502 max_size = strtoul(argv[idx_number]->arg, NULL, 10);
2503
2504 bgp_default_subgroup_pkt_queue_max_set(bgp, max_size);
2505
2506 return CMD_SUCCESS;
2507 }
2508
2509 DEFUN (no_bgp_default_subgroup_pkt_queue_max,
2510 no_bgp_default_subgroup_pkt_queue_max_cmd,
2511 "no bgp default subgroup-pkt-queue-max [(20-100)]",
2512 NO_STR
2513 "BGP specific commands\n"
2514 "Configure BGP defaults\n"
2515 "subgroup-pkt-queue-max\n"
2516 "Configure subgroup packet queue max\n")
2517 {
2518 VTY_DECLVAR_CONTEXT(bgp, bgp);
2519 bgp_default_subgroup_pkt_queue_max_unset(bgp);
2520 return CMD_SUCCESS;
2521 }
2522
2523
2524 DEFUN (bgp_rr_allow_outbound_policy,
2525 bgp_rr_allow_outbound_policy_cmd,
2526 "bgp route-reflector allow-outbound-policy",
2527 "BGP specific commands\n"
2528 "Allow modifications made by out route-map\n"
2529 "on ibgp neighbors\n")
2530 {
2531 VTY_DECLVAR_CONTEXT(bgp, bgp);
2532
2533 if (!bgp_flag_check(bgp, BGP_FLAG_RR_ALLOW_OUTBOUND_POLICY)) {
2534 bgp_flag_set(bgp, BGP_FLAG_RR_ALLOW_OUTBOUND_POLICY);
2535 update_group_announce_rrclients(bgp);
2536 bgp_clear_star_soft_out(vty, bgp->name);
2537 }
2538
2539 return CMD_SUCCESS;
2540 }
2541
2542 DEFUN (no_bgp_rr_allow_outbound_policy,
2543 no_bgp_rr_allow_outbound_policy_cmd,
2544 "no bgp route-reflector allow-outbound-policy",
2545 NO_STR
2546 "BGP specific commands\n"
2547 "Allow modifications made by out route-map\n"
2548 "on ibgp neighbors\n")
2549 {
2550 VTY_DECLVAR_CONTEXT(bgp, bgp);
2551
2552 if (bgp_flag_check(bgp, BGP_FLAG_RR_ALLOW_OUTBOUND_POLICY)) {
2553 bgp_flag_unset(bgp, BGP_FLAG_RR_ALLOW_OUTBOUND_POLICY);
2554 update_group_announce_rrclients(bgp);
2555 bgp_clear_star_soft_out(vty, bgp->name);
2556 }
2557
2558 return CMD_SUCCESS;
2559 }
2560
2561 DEFUN (bgp_listen_limit,
2562 bgp_listen_limit_cmd,
2563 "bgp listen limit (1-5000)",
2564 "BGP specific commands\n"
2565 "Configure BGP defaults\n"
2566 "maximum number of BGP Dynamic Neighbors that can be created\n"
2567 "Configure Dynamic Neighbors listen limit value\n")
2568 {
2569 VTY_DECLVAR_CONTEXT(bgp, bgp);
2570 int idx_number = 3;
2571 int listen_limit;
2572
2573 listen_limit = strtoul(argv[idx_number]->arg, NULL, 10);
2574
2575 bgp_listen_limit_set(bgp, listen_limit);
2576
2577 return CMD_SUCCESS;
2578 }
2579
2580 DEFUN (no_bgp_listen_limit,
2581 no_bgp_listen_limit_cmd,
2582 "no bgp listen limit [(1-5000)]",
2583 "BGP specific commands\n"
2584 "Configure BGP defaults\n"
2585 "unset maximum number of BGP Dynamic Neighbors that can be created\n"
2586 "Configure Dynamic Neighbors listen limit value to default\n"
2587 "Configure Dynamic Neighbors listen limit value\n")
2588 {
2589 VTY_DECLVAR_CONTEXT(bgp, bgp);
2590 bgp_listen_limit_unset(bgp);
2591 return CMD_SUCCESS;
2592 }
2593
2594
2595 /*
2596 * Check if this listen range is already configured. Check for exact
2597 * match or overlap based on input.
2598 */
2599 static struct peer_group *listen_range_exists(struct bgp *bgp,
2600 struct prefix *range, int exact)
2601 {
2602 struct listnode *node, *nnode;
2603 struct listnode *node1, *nnode1;
2604 struct peer_group *group;
2605 struct prefix *lr;
2606 afi_t afi;
2607 int match;
2608
2609 afi = family2afi(range->family);
2610 for (ALL_LIST_ELEMENTS(bgp->group, node, nnode, group)) {
2611 for (ALL_LIST_ELEMENTS(group->listen_range[afi], node1, nnode1,
2612 lr)) {
2613 if (exact)
2614 match = prefix_same(range, lr);
2615 else
2616 match = (prefix_match(range, lr)
2617 || prefix_match(lr, range));
2618 if (match)
2619 return group;
2620 }
2621 }
2622
2623 return NULL;
2624 }
2625
2626 DEFUN (bgp_listen_range,
2627 bgp_listen_range_cmd,
2628 "bgp listen range <A.B.C.D/M|X:X::X:X/M> peer-group WORD",
2629 "BGP specific commands\n"
2630 "Configure BGP dynamic neighbors listen range\n"
2631 "Configure BGP dynamic neighbors listen range\n"
2632 NEIGHBOR_ADDR_STR
2633 "Member of the peer-group\n"
2634 "Peer-group name\n")
2635 {
2636 VTY_DECLVAR_CONTEXT(bgp, bgp);
2637 struct prefix range;
2638 struct peer_group *group, *existing_group;
2639 afi_t afi;
2640 int ret;
2641 int idx = 0;
2642
2643 argv_find(argv, argc, "A.B.C.D/M", &idx);
2644 argv_find(argv, argc, "X:X::X:X/M", &idx);
2645 char *prefix = argv[idx]->arg;
2646 argv_find(argv, argc, "WORD", &idx);
2647 char *peergroup = argv[idx]->arg;
2648
2649 /* Convert IP prefix string to struct prefix. */
2650 ret = str2prefix(prefix, &range);
2651 if (!ret) {
2652 vty_out(vty, "%% Malformed listen range\n");
2653 return CMD_WARNING_CONFIG_FAILED;
2654 }
2655
2656 afi = family2afi(range.family);
2657
2658 if (afi == AFI_IP6 && IN6_IS_ADDR_LINKLOCAL(&range.u.prefix6)) {
2659 vty_out(vty,
2660 "%% Malformed listen range (link-local address)\n");
2661 return CMD_WARNING_CONFIG_FAILED;
2662 }
2663
2664 apply_mask(&range);
2665
2666 /* Check if same listen range is already configured. */
2667 existing_group = listen_range_exists(bgp, &range, 1);
2668 if (existing_group) {
2669 if (strcmp(existing_group->name, peergroup) == 0)
2670 return CMD_SUCCESS;
2671 else {
2672 vty_out(vty,
2673 "%% Same listen range is attached to peer-group %s\n",
2674 existing_group->name);
2675 return CMD_WARNING_CONFIG_FAILED;
2676 }
2677 }
2678
2679 /* Check if an overlapping listen range exists. */
2680 if (listen_range_exists(bgp, &range, 0)) {
2681 vty_out(vty,
2682 "%% Listen range overlaps with existing listen range\n");
2683 return CMD_WARNING_CONFIG_FAILED;
2684 }
2685
2686 group = peer_group_lookup(bgp, peergroup);
2687 if (!group) {
2688 vty_out(vty, "%% Configure the peer-group first\n");
2689 return CMD_WARNING_CONFIG_FAILED;
2690 }
2691
2692 ret = peer_group_listen_range_add(group, &range);
2693 return bgp_vty_return(vty, ret);
2694 }
2695
2696 DEFUN (no_bgp_listen_range,
2697 no_bgp_listen_range_cmd,
2698 "no bgp listen range <A.B.C.D/M|X:X::X:X/M> peer-group WORD",
2699 NO_STR
2700 "BGP specific commands\n"
2701 "Unconfigure BGP dynamic neighbors listen range\n"
2702 "Unconfigure BGP dynamic neighbors listen range\n"
2703 NEIGHBOR_ADDR_STR
2704 "Member of the peer-group\n"
2705 "Peer-group name\n")
2706 {
2707 VTY_DECLVAR_CONTEXT(bgp, bgp);
2708 struct prefix range;
2709 struct peer_group *group;
2710 afi_t afi;
2711 int ret;
2712 int idx = 0;
2713
2714 argv_find(argv, argc, "A.B.C.D/M", &idx);
2715 argv_find(argv, argc, "X:X::X:X/M", &idx);
2716 char *prefix = argv[idx]->arg;
2717 argv_find(argv, argc, "WORD", &idx);
2718 char *peergroup = argv[idx]->arg;
2719
2720 /* Convert IP prefix string to struct prefix. */
2721 ret = str2prefix(prefix, &range);
2722 if (!ret) {
2723 vty_out(vty, "%% Malformed listen range\n");
2724 return CMD_WARNING_CONFIG_FAILED;
2725 }
2726
2727 afi = family2afi(range.family);
2728
2729 if (afi == AFI_IP6 && IN6_IS_ADDR_LINKLOCAL(&range.u.prefix6)) {
2730 vty_out(vty,
2731 "%% Malformed listen range (link-local address)\n");
2732 return CMD_WARNING_CONFIG_FAILED;
2733 }
2734
2735 apply_mask(&range);
2736
2737 group = peer_group_lookup(bgp, peergroup);
2738 if (!group) {
2739 vty_out(vty, "%% Peer-group does not exist\n");
2740 return CMD_WARNING_CONFIG_FAILED;
2741 }
2742
2743 ret = peer_group_listen_range_del(group, &range);
2744 return bgp_vty_return(vty, ret);
2745 }
2746
2747 void bgp_config_write_listen(struct vty *vty, struct bgp *bgp)
2748 {
2749 struct peer_group *group;
2750 struct listnode *node, *nnode, *rnode, *nrnode;
2751 struct prefix *range;
2752 afi_t afi;
2753 char buf[PREFIX2STR_BUFFER];
2754
2755 if (bgp->dynamic_neighbors_limit != BGP_DYNAMIC_NEIGHBORS_LIMIT_DEFAULT)
2756 vty_out(vty, " bgp listen limit %d\n",
2757 bgp->dynamic_neighbors_limit);
2758
2759 for (ALL_LIST_ELEMENTS(bgp->group, node, nnode, group)) {
2760 for (afi = AFI_IP; afi < AFI_MAX; afi++) {
2761 for (ALL_LIST_ELEMENTS(group->listen_range[afi], rnode,
2762 nrnode, range)) {
2763 prefix2str(range, buf, sizeof(buf));
2764 vty_out(vty,
2765 " bgp listen range %s peer-group %s\n",
2766 buf, group->name);
2767 }
2768 }
2769 }
2770 }
2771
2772
2773 DEFUN (bgp_disable_connected_route_check,
2774 bgp_disable_connected_route_check_cmd,
2775 "bgp disable-ebgp-connected-route-check",
2776 "BGP specific commands\n"
2777 "Disable checking if nexthop is connected on ebgp sessions\n")
2778 {
2779 VTY_DECLVAR_CONTEXT(bgp, bgp);
2780 bgp_flag_set(bgp, BGP_FLAG_DISABLE_NH_CONNECTED_CHK);
2781 bgp_clear_star_soft_in(vty, bgp->name);
2782
2783 return CMD_SUCCESS;
2784 }
2785
2786 DEFUN (no_bgp_disable_connected_route_check,
2787 no_bgp_disable_connected_route_check_cmd,
2788 "no bgp disable-ebgp-connected-route-check",
2789 NO_STR
2790 "BGP specific commands\n"
2791 "Disable checking if nexthop is connected on ebgp sessions\n")
2792 {
2793 VTY_DECLVAR_CONTEXT(bgp, bgp);
2794 bgp_flag_unset(bgp, BGP_FLAG_DISABLE_NH_CONNECTED_CHK);
2795 bgp_clear_star_soft_in(vty, bgp->name);
2796
2797 return CMD_SUCCESS;
2798 }
2799
2800
2801 static int peer_remote_as_vty(struct vty *vty, const char *peer_str,
2802 const char *as_str, afi_t afi, safi_t safi)
2803 {
2804 VTY_DECLVAR_CONTEXT(bgp, bgp);
2805 int ret;
2806 as_t as;
2807 int as_type = AS_SPECIFIED;
2808 union sockunion su;
2809
2810 if (as_str[0] == 'i') {
2811 as = 0;
2812 as_type = AS_INTERNAL;
2813 } else if (as_str[0] == 'e') {
2814 as = 0;
2815 as_type = AS_EXTERNAL;
2816 } else {
2817 /* Get AS number. */
2818 as = strtoul(as_str, NULL, 10);
2819 }
2820
2821 /* If peer is peer group or interface peer, call proper function. */
2822 ret = str2sockunion(peer_str, &su);
2823 if (ret < 0) {
2824 struct peer *peer;
2825
2826 /* Check if existing interface peer */
2827 peer = peer_lookup_by_conf_if(bgp, peer_str);
2828
2829 ret = peer_remote_as(bgp, NULL, peer_str, &as, as_type, afi,
2830 safi);
2831
2832 /* if not interface peer, check peer-group settings */
2833 if (ret < 0 && !peer) {
2834 ret = peer_group_remote_as(bgp, peer_str, &as, as_type);
2835 if (ret < 0) {
2836 vty_out(vty,
2837 "%% Create the peer-group or interface first\n");
2838 return CMD_WARNING_CONFIG_FAILED;
2839 }
2840 return CMD_SUCCESS;
2841 }
2842 } else {
2843 if (peer_address_self_check(bgp, &su)) {
2844 vty_out(vty,
2845 "%% Can not configure the local system as neighbor\n");
2846 return CMD_WARNING_CONFIG_FAILED;
2847 }
2848 ret = peer_remote_as(bgp, &su, NULL, &as, as_type, afi, safi);
2849 }
2850
2851 /* This peer belongs to peer group. */
2852 switch (ret) {
2853 case BGP_ERR_PEER_GROUP_MEMBER:
2854 vty_out(vty,
2855 "%% Peer-group member cannot override remote-as of peer-group\n");
2856 return CMD_WARNING_CONFIG_FAILED;
2857 case BGP_ERR_PEER_GROUP_PEER_TYPE_DIFFERENT:
2858 vty_out(vty,
2859 "%% Peer-group members must be all internal or all external\n");
2860 return CMD_WARNING_CONFIG_FAILED;
2861 }
2862 return bgp_vty_return(vty, ret);
2863 }
2864
2865 DEFUN (bgp_default_shutdown,
2866 bgp_default_shutdown_cmd,
2867 "[no] bgp default shutdown",
2868 NO_STR
2869 BGP_STR
2870 "Configure BGP defaults\n"
2871 "Apply administrative shutdown to newly configured peers\n")
2872 {
2873 VTY_DECLVAR_CONTEXT(bgp, bgp);
2874 bgp->autoshutdown = !strmatch(argv[0]->text, "no");
2875 return CMD_SUCCESS;
2876 }
2877
2878 DEFUN (neighbor_remote_as,
2879 neighbor_remote_as_cmd,
2880 "neighbor <A.B.C.D|X:X::X:X|WORD> remote-as <(1-4294967295)|internal|external>",
2881 NEIGHBOR_STR
2882 NEIGHBOR_ADDR_STR2
2883 "Specify a BGP neighbor\n"
2884 AS_STR
2885 "Internal BGP peer\n"
2886 "External BGP peer\n")
2887 {
2888 int idx_peer = 1;
2889 int idx_remote_as = 3;
2890 return peer_remote_as_vty(vty, argv[idx_peer]->arg,
2891 argv[idx_remote_as]->arg, AFI_IP,
2892 SAFI_UNICAST);
2893 }
2894
2895 static int peer_conf_interface_get(struct vty *vty, const char *conf_if,
2896 afi_t afi, safi_t safi, int v6only,
2897 const char *peer_group_name,
2898 const char *as_str)
2899 {
2900 VTY_DECLVAR_CONTEXT(bgp, bgp);
2901 as_t as = 0;
2902 int as_type = AS_UNSPECIFIED;
2903 struct peer *peer;
2904 struct peer_group *group;
2905 int ret = 0;
2906 union sockunion su;
2907
2908 group = peer_group_lookup(bgp, conf_if);
2909
2910 if (group) {
2911 vty_out(vty, "%% Name conflict with peer-group \n");
2912 return CMD_WARNING_CONFIG_FAILED;
2913 }
2914
2915 if (as_str) {
2916 if (as_str[0] == 'i') {
2917 as_type = AS_INTERNAL;
2918 } else if (as_str[0] == 'e') {
2919 as_type = AS_EXTERNAL;
2920 } else {
2921 /* Get AS number. */
2922 as = strtoul(as_str, NULL, 10);
2923 as_type = AS_SPECIFIED;
2924 }
2925 }
2926
2927 peer = peer_lookup_by_conf_if(bgp, conf_if);
2928 if (peer) {
2929 if (as_str)
2930 ret = peer_remote_as(bgp, NULL, conf_if, &as, as_type,
2931 afi, safi);
2932 } else {
2933 if (bgp_flag_check(bgp, BGP_FLAG_NO_DEFAULT_IPV4)
2934 && afi == AFI_IP && safi == SAFI_UNICAST)
2935 peer = peer_create(NULL, conf_if, bgp, bgp->as, as,
2936 as_type, 0, 0, NULL);
2937 else
2938 peer = peer_create(NULL, conf_if, bgp, bgp->as, as,
2939 as_type, afi, safi, NULL);
2940
2941 if (!peer) {
2942 vty_out(vty, "%% BGP failed to create peer\n");
2943 return CMD_WARNING_CONFIG_FAILED;
2944 }
2945
2946 if (v6only)
2947 peer_flag_set(peer, PEER_FLAG_IFPEER_V6ONLY);
2948
2949 /* Request zebra to initiate IPv6 RAs on this interface. We do
2950 * this
2951 * any unnumbered peer in order to not worry about run-time
2952 * transitions
2953 * (e.g., peering is initially IPv4, but the IPv4 /30 or /31
2954 * address
2955 * gets deleted later etc.)
2956 */
2957 if (peer->ifp)
2958 bgp_zebra_initiate_radv(bgp, peer);
2959 }
2960
2961 if ((v6only && !CHECK_FLAG(peer->flags, PEER_FLAG_IFPEER_V6ONLY))
2962 || (!v6only && CHECK_FLAG(peer->flags, PEER_FLAG_IFPEER_V6ONLY))) {
2963 if (v6only)
2964 peer_flag_set(peer, PEER_FLAG_IFPEER_V6ONLY);
2965 else
2966 peer_flag_unset(peer, PEER_FLAG_IFPEER_V6ONLY);
2967
2968 /* v6only flag changed. Reset bgp seesion */
2969 if (BGP_IS_VALID_STATE_FOR_NOTIF(peer->status)) {
2970 peer->last_reset = PEER_DOWN_V6ONLY_CHANGE;
2971 bgp_notify_send(peer, BGP_NOTIFY_CEASE,
2972 BGP_NOTIFY_CEASE_CONFIG_CHANGE);
2973 } else
2974 bgp_session_reset(peer);
2975 }
2976
2977 if (!CHECK_FLAG(peer->flags_invert, PEER_FLAG_CAPABILITY_ENHE)) {
2978 SET_FLAG(peer->flags, PEER_FLAG_CAPABILITY_ENHE);
2979 SET_FLAG(peer->flags_invert, PEER_FLAG_CAPABILITY_ENHE);
2980 SET_FLAG(peer->flags_override, PEER_FLAG_CAPABILITY_ENHE);
2981 }
2982
2983 if (peer_group_name) {
2984 group = peer_group_lookup(bgp, peer_group_name);
2985 if (!group) {
2986 vty_out(vty, "%% Configure the peer-group first\n");
2987 return CMD_WARNING_CONFIG_FAILED;
2988 }
2989
2990 ret = peer_group_bind(bgp, &su, peer, group, &as);
2991 }
2992
2993 return bgp_vty_return(vty, ret);
2994 }
2995
2996 DEFUN (neighbor_interface_config,
2997 neighbor_interface_config_cmd,
2998 "neighbor WORD interface [peer-group WORD]",
2999 NEIGHBOR_STR
3000 "Interface name or neighbor tag\n"
3001 "Enable BGP on interface\n"
3002 "Member of the peer-group\n"
3003 "Peer-group name\n")
3004 {
3005 int idx_word = 1;
3006 int idx_peer_group_word = 4;
3007
3008 if (argc > idx_peer_group_word)
3009 return peer_conf_interface_get(
3010 vty, argv[idx_word]->arg, AFI_IP, SAFI_UNICAST, 0,
3011 argv[idx_peer_group_word]->arg, NULL);
3012 else
3013 return peer_conf_interface_get(vty, argv[idx_word]->arg, AFI_IP,
3014 SAFI_UNICAST, 0, NULL, NULL);
3015 }
3016
3017 DEFUN (neighbor_interface_config_v6only,
3018 neighbor_interface_config_v6only_cmd,
3019 "neighbor WORD interface v6only [peer-group WORD]",
3020 NEIGHBOR_STR
3021 "Interface name or neighbor tag\n"
3022 "Enable BGP on interface\n"
3023 "Enable BGP with v6 link-local only\n"
3024 "Member of the peer-group\n"
3025 "Peer-group name\n")
3026 {
3027 int idx_word = 1;
3028 int idx_peer_group_word = 5;
3029
3030 if (argc > idx_peer_group_word)
3031 return peer_conf_interface_get(
3032 vty, argv[idx_word]->arg, AFI_IP, SAFI_UNICAST, 1,
3033 argv[idx_peer_group_word]->arg, NULL);
3034
3035 return peer_conf_interface_get(vty, argv[idx_word]->arg, AFI_IP,
3036 SAFI_UNICAST, 1, NULL, NULL);
3037 }
3038
3039
3040 DEFUN (neighbor_interface_config_remote_as,
3041 neighbor_interface_config_remote_as_cmd,
3042 "neighbor WORD interface remote-as <(1-4294967295)|internal|external>",
3043 NEIGHBOR_STR
3044 "Interface name or neighbor tag\n"
3045 "Enable BGP on interface\n"
3046 "Specify a BGP neighbor\n"
3047 AS_STR
3048 "Internal BGP peer\n"
3049 "External BGP peer\n")
3050 {
3051 int idx_word = 1;
3052 int idx_remote_as = 4;
3053 return peer_conf_interface_get(vty, argv[idx_word]->arg, AFI_IP,
3054 SAFI_UNICAST, 0, NULL,
3055 argv[idx_remote_as]->arg);
3056 }
3057
3058 DEFUN (neighbor_interface_v6only_config_remote_as,
3059 neighbor_interface_v6only_config_remote_as_cmd,
3060 "neighbor WORD interface v6only remote-as <(1-4294967295)|internal|external>",
3061 NEIGHBOR_STR
3062 "Interface name or neighbor tag\n"
3063 "Enable BGP with v6 link-local only\n"
3064 "Enable BGP on interface\n"
3065 "Specify a BGP neighbor\n"
3066 AS_STR
3067 "Internal BGP peer\n"
3068 "External BGP peer\n")
3069 {
3070 int idx_word = 1;
3071 int idx_remote_as = 5;
3072 return peer_conf_interface_get(vty, argv[idx_word]->arg, AFI_IP,
3073 SAFI_UNICAST, 1, NULL,
3074 argv[idx_remote_as]->arg);
3075 }
3076
3077 DEFUN (neighbor_peer_group,
3078 neighbor_peer_group_cmd,
3079 "neighbor WORD peer-group",
3080 NEIGHBOR_STR
3081 "Interface name or neighbor tag\n"
3082 "Configure peer-group\n")
3083 {
3084 VTY_DECLVAR_CONTEXT(bgp, bgp);
3085 int idx_word = 1;
3086 struct peer *peer;
3087 struct peer_group *group;
3088
3089 peer = peer_lookup_by_conf_if(bgp, argv[idx_word]->arg);
3090 if (peer) {
3091 vty_out(vty, "%% Name conflict with interface: \n");
3092 return CMD_WARNING_CONFIG_FAILED;
3093 }
3094
3095 group = peer_group_get(bgp, argv[idx_word]->arg);
3096 if (!group) {
3097 vty_out(vty, "%% BGP failed to find or create peer-group\n");
3098 return CMD_WARNING_CONFIG_FAILED;
3099 }
3100
3101 return CMD_SUCCESS;
3102 }
3103
3104 DEFUN (no_neighbor,
3105 no_neighbor_cmd,
3106 "no neighbor <WORD|<A.B.C.D|X:X::X:X> [remote-as <(1-4294967295)|internal|external>]>",
3107 NO_STR
3108 NEIGHBOR_STR
3109 NEIGHBOR_ADDR_STR2
3110 "Specify a BGP neighbor\n"
3111 AS_STR
3112 "Internal BGP peer\n"
3113 "External BGP peer\n")
3114 {
3115 VTY_DECLVAR_CONTEXT(bgp, bgp);
3116 int idx_peer = 2;
3117 int ret;
3118 union sockunion su;
3119 struct peer_group *group;
3120 struct peer *peer;
3121 struct peer *other;
3122
3123 ret = str2sockunion(argv[idx_peer]->arg, &su);
3124 if (ret < 0) {
3125 /* look up for neighbor by interface name config. */
3126 peer = peer_lookup_by_conf_if(bgp, argv[idx_peer]->arg);
3127 if (peer) {
3128 /* Request zebra to terminate IPv6 RAs on this
3129 * interface. */
3130 if (peer->ifp)
3131 bgp_zebra_terminate_radv(peer->bgp, peer);
3132 peer_delete(peer);
3133 return CMD_SUCCESS;
3134 }
3135
3136 group = peer_group_lookup(bgp, argv[idx_peer]->arg);
3137 if (group)
3138 peer_group_delete(group);
3139 else {
3140 vty_out(vty, "%% Create the peer-group first\n");
3141 return CMD_WARNING_CONFIG_FAILED;
3142 }
3143 } else {
3144 peer = peer_lookup(bgp, &su);
3145 if (peer) {
3146 if (peer_dynamic_neighbor(peer)) {
3147 vty_out(vty,
3148 "%% Operation not allowed on a dynamic neighbor\n");
3149 return CMD_WARNING_CONFIG_FAILED;
3150 }
3151
3152 other = peer->doppelganger;
3153 peer_delete(peer);
3154 if (other && other->status != Deleted)
3155 peer_delete(other);
3156 }
3157 }
3158
3159 return CMD_SUCCESS;
3160 }
3161
3162 DEFUN (no_neighbor_interface_config,
3163 no_neighbor_interface_config_cmd,
3164 "no neighbor WORD interface [v6only] [peer-group WORD] [remote-as <(1-4294967295)|internal|external>]",
3165 NO_STR
3166 NEIGHBOR_STR
3167 "Interface name\n"
3168 "Configure BGP on interface\n"
3169 "Enable BGP with v6 link-local only\n"
3170 "Member of the peer-group\n"
3171 "Peer-group name\n"
3172 "Specify a BGP neighbor\n"
3173 AS_STR
3174 "Internal BGP peer\n"
3175 "External BGP peer\n")
3176 {
3177 VTY_DECLVAR_CONTEXT(bgp, bgp);
3178 int idx_word = 2;
3179 struct peer *peer;
3180
3181 /* look up for neighbor by interface name config. */
3182 peer = peer_lookup_by_conf_if(bgp, argv[idx_word]->arg);
3183 if (peer) {
3184 /* Request zebra to terminate IPv6 RAs on this interface. */
3185 if (peer->ifp)
3186 bgp_zebra_terminate_radv(peer->bgp, peer);
3187 peer_delete(peer);
3188 } else {
3189 vty_out(vty, "%% Create the bgp interface first\n");
3190 return CMD_WARNING_CONFIG_FAILED;
3191 }
3192 return CMD_SUCCESS;
3193 }
3194
3195 DEFUN (no_neighbor_peer_group,
3196 no_neighbor_peer_group_cmd,
3197 "no neighbor WORD peer-group",
3198 NO_STR
3199 NEIGHBOR_STR
3200 "Neighbor tag\n"
3201 "Configure peer-group\n")
3202 {
3203 VTY_DECLVAR_CONTEXT(bgp, bgp);
3204 int idx_word = 2;
3205 struct peer_group *group;
3206
3207 group = peer_group_lookup(bgp, argv[idx_word]->arg);
3208 if (group)
3209 peer_group_delete(group);
3210 else {
3211 vty_out(vty, "%% Create the peer-group first\n");
3212 return CMD_WARNING_CONFIG_FAILED;
3213 }
3214 return CMD_SUCCESS;
3215 }
3216
3217 DEFUN (no_neighbor_interface_peer_group_remote_as,
3218 no_neighbor_interface_peer_group_remote_as_cmd,
3219 "no neighbor WORD remote-as <(1-4294967295)|internal|external>",
3220 NO_STR
3221 NEIGHBOR_STR
3222 "Interface name or neighbor tag\n"
3223 "Specify a BGP neighbor\n"
3224 AS_STR
3225 "Internal BGP peer\n"
3226 "External BGP peer\n")
3227 {
3228 VTY_DECLVAR_CONTEXT(bgp, bgp);
3229 int idx_word = 2;
3230 struct peer_group *group;
3231 struct peer *peer;
3232
3233 /* look up for neighbor by interface name config. */
3234 peer = peer_lookup_by_conf_if(bgp, argv[idx_word]->arg);
3235 if (peer) {
3236 peer_as_change(peer, 0, AS_UNSPECIFIED);
3237 return CMD_SUCCESS;
3238 }
3239
3240 group = peer_group_lookup(bgp, argv[idx_word]->arg);
3241 if (group)
3242 peer_group_remote_as_delete(group);
3243 else {
3244 vty_out(vty, "%% Create the peer-group or interface first\n");
3245 return CMD_WARNING_CONFIG_FAILED;
3246 }
3247 return CMD_SUCCESS;
3248 }
3249
3250 DEFUN (neighbor_local_as,
3251 neighbor_local_as_cmd,
3252 "neighbor <A.B.C.D|X:X::X:X|WORD> local-as (1-4294967295)",
3253 NEIGHBOR_STR
3254 NEIGHBOR_ADDR_STR2
3255 "Specify a local-as number\n"
3256 "AS number used as local AS\n")
3257 {
3258 int idx_peer = 1;
3259 int idx_number = 3;
3260 struct peer *peer;
3261 int ret;
3262 as_t as;
3263
3264 peer = peer_and_group_lookup_vty(vty, argv[idx_peer]->arg);
3265 if (!peer)
3266 return CMD_WARNING_CONFIG_FAILED;
3267
3268 as = strtoul(argv[idx_number]->arg, NULL, 10);
3269 ret = peer_local_as_set(peer, as, 0, 0);
3270 return bgp_vty_return(vty, ret);
3271 }
3272
3273 DEFUN (neighbor_local_as_no_prepend,
3274 neighbor_local_as_no_prepend_cmd,
3275 "neighbor <A.B.C.D|X:X::X:X|WORD> local-as (1-4294967295) no-prepend",
3276 NEIGHBOR_STR
3277 NEIGHBOR_ADDR_STR2
3278 "Specify a local-as number\n"
3279 "AS number used as local AS\n"
3280 "Do not prepend local-as to updates from ebgp peers\n")
3281 {
3282 int idx_peer = 1;
3283 int idx_number = 3;
3284 struct peer *peer;
3285 int ret;
3286 as_t as;
3287
3288 peer = peer_and_group_lookup_vty(vty, argv[idx_peer]->arg);
3289 if (!peer)
3290 return CMD_WARNING_CONFIG_FAILED;
3291
3292 as = strtoul(argv[idx_number]->arg, NULL, 10);
3293 ret = peer_local_as_set(peer, as, 1, 0);
3294 return bgp_vty_return(vty, ret);
3295 }
3296
3297 DEFUN (neighbor_local_as_no_prepend_replace_as,
3298 neighbor_local_as_no_prepend_replace_as_cmd,
3299 "neighbor <A.B.C.D|X:X::X:X|WORD> local-as (1-4294967295) no-prepend replace-as",
3300 NEIGHBOR_STR
3301 NEIGHBOR_ADDR_STR2
3302 "Specify a local-as number\n"
3303 "AS number used as local AS\n"
3304 "Do not prepend local-as to updates from ebgp peers\n"
3305 "Do not prepend local-as to updates from ibgp peers\n")
3306 {
3307 int idx_peer = 1;
3308 int idx_number = 3;
3309 struct peer *peer;
3310 int ret;
3311 as_t as;
3312
3313 peer = peer_and_group_lookup_vty(vty, argv[idx_peer]->arg);
3314 if (!peer)
3315 return CMD_WARNING_CONFIG_FAILED;
3316
3317 as = strtoul(argv[idx_number]->arg, NULL, 10);
3318 ret = peer_local_as_set(peer, as, 1, 1);
3319 return bgp_vty_return(vty, ret);
3320 }
3321
3322 DEFUN (no_neighbor_local_as,
3323 no_neighbor_local_as_cmd,
3324 "no neighbor <A.B.C.D|X:X::X:X|WORD> local-as [(1-4294967295) [no-prepend [replace-as]]]",
3325 NO_STR
3326 NEIGHBOR_STR
3327 NEIGHBOR_ADDR_STR2
3328 "Specify a local-as number\n"
3329 "AS number used as local AS\n"
3330 "Do not prepend local-as to updates from ebgp peers\n"
3331 "Do not prepend local-as to updates from ibgp peers\n")
3332 {
3333 int idx_peer = 2;
3334 struct peer *peer;
3335 int ret;
3336
3337 peer = peer_and_group_lookup_vty(vty, argv[idx_peer]->arg);
3338 if (!peer)
3339 return CMD_WARNING_CONFIG_FAILED;
3340
3341 ret = peer_local_as_unset(peer);
3342 return bgp_vty_return(vty, ret);
3343 }
3344
3345
3346 DEFUN (neighbor_solo,
3347 neighbor_solo_cmd,
3348 "neighbor <A.B.C.D|X:X::X:X|WORD> solo",
3349 NEIGHBOR_STR
3350 NEIGHBOR_ADDR_STR2
3351 "Solo peer - part of its own update group\n")
3352 {
3353 int idx_peer = 1;
3354 struct peer *peer;
3355 int ret;
3356
3357 peer = peer_and_group_lookup_vty(vty, argv[idx_peer]->arg);
3358 if (!peer)
3359 return CMD_WARNING_CONFIG_FAILED;
3360
3361 ret = update_group_adjust_soloness(peer, 1);
3362 return bgp_vty_return(vty, ret);
3363 }
3364
3365 DEFUN (no_neighbor_solo,
3366 no_neighbor_solo_cmd,
3367 "no neighbor <A.B.C.D|X:X::X:X|WORD> solo",
3368 NO_STR
3369 NEIGHBOR_STR
3370 NEIGHBOR_ADDR_STR2
3371 "Solo peer - part of its own update group\n")
3372 {
3373 int idx_peer = 2;
3374 struct peer *peer;
3375 int ret;
3376
3377 peer = peer_and_group_lookup_vty(vty, argv[idx_peer]->arg);
3378 if (!peer)
3379 return CMD_WARNING_CONFIG_FAILED;
3380
3381 ret = update_group_adjust_soloness(peer, 0);
3382 return bgp_vty_return(vty, ret);
3383 }
3384
3385 DEFUN (neighbor_password,
3386 neighbor_password_cmd,
3387 "neighbor <A.B.C.D|X:X::X:X|WORD> password LINE",
3388 NEIGHBOR_STR
3389 NEIGHBOR_ADDR_STR2
3390 "Set a password\n"
3391 "The password\n")
3392 {
3393 int idx_peer = 1;
3394 int idx_line = 3;
3395 struct peer *peer;
3396 int ret;
3397
3398 peer = peer_and_group_lookup_vty(vty, argv[idx_peer]->arg);
3399 if (!peer)
3400 return CMD_WARNING_CONFIG_FAILED;
3401
3402 ret = peer_password_set(peer, argv[idx_line]->arg);
3403 return bgp_vty_return(vty, ret);
3404 }
3405
3406 DEFUN (no_neighbor_password,
3407 no_neighbor_password_cmd,
3408 "no neighbor <A.B.C.D|X:X::X:X|WORD> password [LINE]",
3409 NO_STR
3410 NEIGHBOR_STR
3411 NEIGHBOR_ADDR_STR2
3412 "Set a password\n"
3413 "The password\n")
3414 {
3415 int idx_peer = 2;
3416 struct peer *peer;
3417 int ret;
3418
3419 peer = peer_and_group_lookup_vty(vty, argv[idx_peer]->arg);
3420 if (!peer)
3421 return CMD_WARNING_CONFIG_FAILED;
3422
3423 ret = peer_password_unset(peer);
3424 return bgp_vty_return(vty, ret);
3425 }
3426
3427 DEFUN (neighbor_activate,
3428 neighbor_activate_cmd,
3429 "neighbor <A.B.C.D|X:X::X:X|WORD> activate",
3430 NEIGHBOR_STR
3431 NEIGHBOR_ADDR_STR2
3432 "Enable the Address Family for this Neighbor\n")
3433 {
3434 int idx_peer = 1;
3435 int ret;
3436 struct peer *peer;
3437
3438 peer = peer_and_group_lookup_vty(vty, argv[idx_peer]->arg);
3439 if (!peer)
3440 return CMD_WARNING_CONFIG_FAILED;
3441
3442 ret = peer_activate(peer, bgp_node_afi(vty), bgp_node_safi(vty));
3443 return bgp_vty_return(vty, ret);
3444 }
3445
3446 ALIAS_HIDDEN(neighbor_activate, neighbor_activate_hidden_cmd,
3447 "neighbor <A.B.C.D|X:X::X:X|WORD> activate",
3448 NEIGHBOR_STR NEIGHBOR_ADDR_STR2
3449 "Enable the Address Family for this Neighbor\n")
3450
3451 DEFUN (no_neighbor_activate,
3452 no_neighbor_activate_cmd,
3453 "no neighbor <A.B.C.D|X:X::X:X|WORD> activate",
3454 NO_STR
3455 NEIGHBOR_STR
3456 NEIGHBOR_ADDR_STR2
3457 "Enable the Address Family for this Neighbor\n")
3458 {
3459 int idx_peer = 2;
3460 int ret;
3461 struct peer *peer;
3462
3463 /* Lookup peer. */
3464 peer = peer_and_group_lookup_vty(vty, argv[idx_peer]->arg);
3465 if (!peer)
3466 return CMD_WARNING_CONFIG_FAILED;
3467
3468 ret = peer_deactivate(peer, bgp_node_afi(vty), bgp_node_safi(vty));
3469 return bgp_vty_return(vty, ret);
3470 }
3471
3472 ALIAS_HIDDEN(no_neighbor_activate, no_neighbor_activate_hidden_cmd,
3473 "no neighbor <A.B.C.D|X:X::X:X|WORD> activate",
3474 NO_STR NEIGHBOR_STR NEIGHBOR_ADDR_STR2
3475 "Enable the Address Family for this Neighbor\n")
3476
3477 DEFUN (neighbor_set_peer_group,
3478 neighbor_set_peer_group_cmd,
3479 "neighbor <A.B.C.D|X:X::X:X|WORD> peer-group WORD",
3480 NEIGHBOR_STR
3481 NEIGHBOR_ADDR_STR2
3482 "Member of the peer-group\n"
3483 "Peer-group name\n")
3484 {
3485 VTY_DECLVAR_CONTEXT(bgp, bgp);
3486 int idx_peer = 1;
3487 int idx_word = 3;
3488 int ret;
3489 as_t as;
3490 union sockunion su;
3491 struct peer *peer;
3492 struct peer_group *group;
3493
3494 ret = str2sockunion(argv[idx_peer]->arg, &su);
3495 if (ret < 0) {
3496 peer = peer_lookup_by_conf_if(bgp, argv[idx_peer]->arg);
3497 if (!peer) {
3498 vty_out(vty, "%% Malformed address or name: %s\n",
3499 argv[idx_peer]->arg);
3500 return CMD_WARNING_CONFIG_FAILED;
3501 }
3502 } else {
3503 if (peer_address_self_check(bgp, &su)) {
3504 vty_out(vty,
3505 "%% Can not configure the local system as neighbor\n");
3506 return CMD_WARNING_CONFIG_FAILED;
3507 }
3508
3509 /* Disallow for dynamic neighbor. */
3510 peer = peer_lookup(bgp, &su);
3511 if (peer && peer_dynamic_neighbor(peer)) {
3512 vty_out(vty,
3513 "%% Operation not allowed on a dynamic neighbor\n");
3514 return CMD_WARNING_CONFIG_FAILED;
3515 }
3516 }
3517
3518 group = peer_group_lookup(bgp, argv[idx_word]->arg);
3519 if (!group) {
3520 vty_out(vty, "%% Configure the peer-group first\n");
3521 return CMD_WARNING_CONFIG_FAILED;
3522 }
3523
3524 ret = peer_group_bind(bgp, &su, peer, group, &as);
3525
3526 if (ret == BGP_ERR_PEER_GROUP_PEER_TYPE_DIFFERENT) {
3527 vty_out(vty,
3528 "%% Peer with AS %u cannot be in this peer-group, members must be all internal or all external\n",
3529 as);
3530 return CMD_WARNING_CONFIG_FAILED;
3531 }
3532
3533 return bgp_vty_return(vty, ret);
3534 }
3535
3536 ALIAS_HIDDEN(neighbor_set_peer_group, neighbor_set_peer_group_hidden_cmd,
3537 "neighbor <A.B.C.D|X:X::X:X|WORD> peer-group WORD",
3538 NEIGHBOR_STR NEIGHBOR_ADDR_STR2
3539 "Member of the peer-group\n"
3540 "Peer-group name\n")
3541
3542 DEFUN (no_neighbor_set_peer_group,
3543 no_neighbor_set_peer_group_cmd,
3544 "no neighbor <A.B.C.D|X:X::X:X|WORD> peer-group WORD",
3545 NO_STR
3546 NEIGHBOR_STR
3547 NEIGHBOR_ADDR_STR2
3548 "Member of the peer-group\n"
3549 "Peer-group name\n")
3550 {
3551 VTY_DECLVAR_CONTEXT(bgp, bgp);
3552 int idx_peer = 2;
3553 int idx_word = 4;
3554 int ret;
3555 struct peer *peer;
3556 struct peer_group *group;
3557
3558 peer = peer_lookup_vty(vty, argv[idx_peer]->arg);
3559 if (!peer)
3560 return CMD_WARNING_CONFIG_FAILED;
3561
3562 group = peer_group_lookup(bgp, argv[idx_word]->arg);
3563 if (!group) {
3564 vty_out(vty, "%% Configure the peer-group first\n");
3565 return CMD_WARNING_CONFIG_FAILED;
3566 }
3567
3568 ret = peer_delete(peer);
3569
3570 return bgp_vty_return(vty, ret);
3571 }
3572
3573 ALIAS_HIDDEN(no_neighbor_set_peer_group, no_neighbor_set_peer_group_hidden_cmd,
3574 "no neighbor <A.B.C.D|X:X::X:X|WORD> peer-group WORD",
3575 NO_STR NEIGHBOR_STR NEIGHBOR_ADDR_STR2
3576 "Member of the peer-group\n"
3577 "Peer-group name\n")
3578
3579 static int peer_flag_modify_vty(struct vty *vty, const char *ip_str,
3580 uint32_t flag, int set)
3581 {
3582 int ret;
3583 struct peer *peer;
3584
3585 peer = peer_and_group_lookup_vty(vty, ip_str);
3586 if (!peer)
3587 return CMD_WARNING_CONFIG_FAILED;
3588
3589 /*
3590 * If 'neighbor <interface>', then this is for directly connected peers,
3591 * we should not accept disable-connected-check.
3592 */
3593 if (peer->conf_if && (flag == PEER_FLAG_DISABLE_CONNECTED_CHECK)) {
3594 vty_out(vty,
3595 "%s is directly connected peer, cannot accept disable-"
3596 "connected-check\n",
3597 ip_str);
3598 return CMD_WARNING_CONFIG_FAILED;
3599 }
3600
3601 if (!set && flag == PEER_FLAG_SHUTDOWN)
3602 peer_tx_shutdown_message_unset(peer);
3603
3604 if (set)
3605 ret = peer_flag_set(peer, flag);
3606 else
3607 ret = peer_flag_unset(peer, flag);
3608
3609 return bgp_vty_return(vty, ret);
3610 }
3611
3612 static int peer_flag_set_vty(struct vty *vty, const char *ip_str, uint32_t flag)
3613 {
3614 return peer_flag_modify_vty(vty, ip_str, flag, 1);
3615 }
3616
3617 static int peer_flag_unset_vty(struct vty *vty, const char *ip_str,
3618 uint32_t flag)
3619 {
3620 return peer_flag_modify_vty(vty, ip_str, flag, 0);
3621 }
3622
3623 /* neighbor passive. */
3624 DEFUN (neighbor_passive,
3625 neighbor_passive_cmd,
3626 "neighbor <A.B.C.D|X:X::X:X|WORD> passive",
3627 NEIGHBOR_STR
3628 NEIGHBOR_ADDR_STR2
3629 "Don't send open messages to this neighbor\n")
3630 {
3631 int idx_peer = 1;
3632 return peer_flag_set_vty(vty, argv[idx_peer]->arg, PEER_FLAG_PASSIVE);
3633 }
3634
3635 DEFUN (no_neighbor_passive,
3636 no_neighbor_passive_cmd,
3637 "no neighbor <A.B.C.D|X:X::X:X|WORD> passive",
3638 NO_STR
3639 NEIGHBOR_STR
3640 NEIGHBOR_ADDR_STR2
3641 "Don't send open messages to this neighbor\n")
3642 {
3643 int idx_peer = 2;
3644 return peer_flag_unset_vty(vty, argv[idx_peer]->arg, PEER_FLAG_PASSIVE);
3645 }
3646
3647 /* neighbor shutdown. */
3648 DEFUN (neighbor_shutdown_msg,
3649 neighbor_shutdown_msg_cmd,
3650 "neighbor <A.B.C.D|X:X::X:X|WORD> shutdown message MSG...",
3651 NEIGHBOR_STR
3652 NEIGHBOR_ADDR_STR2
3653 "Administratively shut down this neighbor\n"
3654 "Add a shutdown message (draft-ietf-idr-shutdown-06)\n"
3655 "Shutdown message\n")
3656 {
3657 int idx_peer = 1;
3658
3659 if (argc >= 5) {
3660 struct peer *peer =
3661 peer_and_group_lookup_vty(vty, argv[idx_peer]->arg);
3662 char *message;
3663
3664 if (!peer)
3665 return CMD_WARNING_CONFIG_FAILED;
3666 message = argv_concat(argv, argc, 4);
3667 peer_tx_shutdown_message_set(peer, message);
3668 XFREE(MTYPE_TMP, message);
3669 }
3670
3671 return peer_flag_set_vty(vty, argv[idx_peer]->arg, PEER_FLAG_SHUTDOWN);
3672 }
3673
3674 ALIAS(neighbor_shutdown_msg, neighbor_shutdown_cmd,
3675 "neighbor <A.B.C.D|X:X::X:X|WORD> shutdown",
3676 NEIGHBOR_STR NEIGHBOR_ADDR_STR2
3677 "Administratively shut down this neighbor\n")
3678
3679 DEFUN (no_neighbor_shutdown_msg,
3680 no_neighbor_shutdown_msg_cmd,
3681 "no neighbor <A.B.C.D|X:X::X:X|WORD> shutdown message MSG...",
3682 NO_STR
3683 NEIGHBOR_STR
3684 NEIGHBOR_ADDR_STR2
3685 "Administratively shut down this neighbor\n"
3686 "Remove a shutdown message (draft-ietf-idr-shutdown-06)\n"
3687 "Shutdown message\n")
3688 {
3689 int idx_peer = 2;
3690
3691 return peer_flag_unset_vty(vty, argv[idx_peer]->arg,
3692 PEER_FLAG_SHUTDOWN);
3693 }
3694
3695 ALIAS(no_neighbor_shutdown_msg, no_neighbor_shutdown_cmd,
3696 "no neighbor <A.B.C.D|X:X::X:X|WORD> shutdown",
3697 NO_STR NEIGHBOR_STR NEIGHBOR_ADDR_STR2
3698 "Administratively shut down this neighbor\n")
3699
3700 /* neighbor capability dynamic. */
3701 DEFUN (neighbor_capability_dynamic,
3702 neighbor_capability_dynamic_cmd,
3703 "neighbor <A.B.C.D|X:X::X:X|WORD> capability dynamic",
3704 NEIGHBOR_STR
3705 NEIGHBOR_ADDR_STR2
3706 "Advertise capability to the peer\n"
3707 "Advertise dynamic capability to this neighbor\n")
3708 {
3709 int idx_peer = 1;
3710 return peer_flag_set_vty(vty, argv[idx_peer]->arg,
3711 PEER_FLAG_DYNAMIC_CAPABILITY);
3712 }
3713
3714 DEFUN (no_neighbor_capability_dynamic,
3715 no_neighbor_capability_dynamic_cmd,
3716 "no neighbor <A.B.C.D|X:X::X:X|WORD> capability dynamic",
3717 NO_STR
3718 NEIGHBOR_STR
3719 NEIGHBOR_ADDR_STR2
3720 "Advertise capability to the peer\n"
3721 "Advertise dynamic capability to this neighbor\n")
3722 {
3723 int idx_peer = 2;
3724 return peer_flag_unset_vty(vty, argv[idx_peer]->arg,
3725 PEER_FLAG_DYNAMIC_CAPABILITY);
3726 }
3727
3728 /* neighbor dont-capability-negotiate */
3729 DEFUN (neighbor_dont_capability_negotiate,
3730 neighbor_dont_capability_negotiate_cmd,
3731 "neighbor <A.B.C.D|X:X::X:X|WORD> dont-capability-negotiate",
3732 NEIGHBOR_STR
3733 NEIGHBOR_ADDR_STR2
3734 "Do not perform capability negotiation\n")
3735 {
3736 int idx_peer = 1;
3737 return peer_flag_set_vty(vty, argv[idx_peer]->arg,
3738 PEER_FLAG_DONT_CAPABILITY);
3739 }
3740
3741 DEFUN (no_neighbor_dont_capability_negotiate,
3742 no_neighbor_dont_capability_negotiate_cmd,
3743 "no neighbor <A.B.C.D|X:X::X:X|WORD> dont-capability-negotiate",
3744 NO_STR
3745 NEIGHBOR_STR
3746 NEIGHBOR_ADDR_STR2
3747 "Do not perform capability negotiation\n")
3748 {
3749 int idx_peer = 2;
3750 return peer_flag_unset_vty(vty, argv[idx_peer]->arg,
3751 PEER_FLAG_DONT_CAPABILITY);
3752 }
3753
3754 /* neighbor capability extended next hop encoding */
3755 DEFUN (neighbor_capability_enhe,
3756 neighbor_capability_enhe_cmd,
3757 "neighbor <A.B.C.D|X:X::X:X|WORD> capability extended-nexthop",
3758 NEIGHBOR_STR
3759 NEIGHBOR_ADDR_STR2
3760 "Advertise capability to the peer\n"
3761 "Advertise extended next-hop capability to the peer\n")
3762 {
3763 int idx_peer = 1;
3764 return peer_flag_set_vty(vty, argv[idx_peer]->arg,
3765 PEER_FLAG_CAPABILITY_ENHE);
3766 }
3767
3768 DEFUN (no_neighbor_capability_enhe,
3769 no_neighbor_capability_enhe_cmd,
3770 "no neighbor <A.B.C.D|X:X::X:X|WORD> capability extended-nexthop",
3771 NO_STR
3772 NEIGHBOR_STR
3773 NEIGHBOR_ADDR_STR2
3774 "Advertise capability to the peer\n"
3775 "Advertise extended next-hop capability to the peer\n")
3776 {
3777 int idx_peer = 2;
3778 return peer_flag_unset_vty(vty, argv[idx_peer]->arg,
3779 PEER_FLAG_CAPABILITY_ENHE);
3780 }
3781
3782 static int peer_af_flag_modify_vty(struct vty *vty, const char *peer_str,
3783 afi_t afi, safi_t safi, uint32_t flag,
3784 int set)
3785 {
3786 int ret;
3787 struct peer *peer;
3788
3789 peer = peer_and_group_lookup_vty(vty, peer_str);
3790 if (!peer)
3791 return CMD_WARNING_CONFIG_FAILED;
3792
3793 if (set)
3794 ret = peer_af_flag_set(peer, afi, safi, flag);
3795 else
3796 ret = peer_af_flag_unset(peer, afi, safi, flag);
3797
3798 return bgp_vty_return(vty, ret);
3799 }
3800
3801 static int peer_af_flag_set_vty(struct vty *vty, const char *peer_str,
3802 afi_t afi, safi_t safi, uint32_t flag)
3803 {
3804 return peer_af_flag_modify_vty(vty, peer_str, afi, safi, flag, 1);
3805 }
3806
3807 static int peer_af_flag_unset_vty(struct vty *vty, const char *peer_str,
3808 afi_t afi, safi_t safi, uint32_t flag)
3809 {
3810 return peer_af_flag_modify_vty(vty, peer_str, afi, safi, flag, 0);
3811 }
3812
3813 /* neighbor capability orf prefix-list. */
3814 DEFUN (neighbor_capability_orf_prefix,
3815 neighbor_capability_orf_prefix_cmd,
3816 "neighbor <A.B.C.D|X:X::X:X|WORD> capability orf prefix-list <both|send|receive>",
3817 NEIGHBOR_STR
3818 NEIGHBOR_ADDR_STR2
3819 "Advertise capability to the peer\n"
3820 "Advertise ORF capability to the peer\n"
3821 "Advertise prefixlist ORF capability to this neighbor\n"
3822 "Capability to SEND and RECEIVE the ORF to/from this neighbor\n"
3823 "Capability to RECEIVE the ORF from this neighbor\n"
3824 "Capability to SEND the ORF to this neighbor\n")
3825 {
3826 int idx_peer = 1;
3827 int idx_send_recv = 5;
3828 uint16_t flag = 0;
3829
3830 if (strmatch(argv[idx_send_recv]->text, "send"))
3831 flag = PEER_FLAG_ORF_PREFIX_SM;
3832 else if (strmatch(argv[idx_send_recv]->text, "receive"))
3833 flag = PEER_FLAG_ORF_PREFIX_RM;
3834 else if (strmatch(argv[idx_send_recv]->text, "both"))
3835 flag = PEER_FLAG_ORF_PREFIX_SM | PEER_FLAG_ORF_PREFIX_RM;
3836 else {
3837 vty_out(vty, "%% BGP invalid orf prefix-list option\n");
3838 return CMD_WARNING_CONFIG_FAILED;
3839 }
3840
3841 return peer_af_flag_set_vty(vty, argv[idx_peer]->arg, bgp_node_afi(vty),
3842 bgp_node_safi(vty), flag);
3843 }
3844
3845 ALIAS_HIDDEN(
3846 neighbor_capability_orf_prefix,
3847 neighbor_capability_orf_prefix_hidden_cmd,
3848 "neighbor <A.B.C.D|X:X::X:X|WORD> capability orf prefix-list <both|send|receive>",
3849 NEIGHBOR_STR NEIGHBOR_ADDR_STR2
3850 "Advertise capability to the peer\n"
3851 "Advertise ORF capability to the peer\n"
3852 "Advertise prefixlist ORF capability to this neighbor\n"
3853 "Capability to SEND and RECEIVE the ORF to/from this neighbor\n"
3854 "Capability to RECEIVE the ORF from this neighbor\n"
3855 "Capability to SEND the ORF to this neighbor\n")
3856
3857 DEFUN (no_neighbor_capability_orf_prefix,
3858 no_neighbor_capability_orf_prefix_cmd,
3859 "no neighbor <A.B.C.D|X:X::X:X|WORD> capability orf prefix-list <both|send|receive>",
3860 NO_STR
3861 NEIGHBOR_STR
3862 NEIGHBOR_ADDR_STR2
3863 "Advertise capability to the peer\n"
3864 "Advertise ORF capability to the peer\n"
3865 "Advertise prefixlist ORF capability to this neighbor\n"
3866 "Capability to SEND and RECEIVE the ORF to/from this neighbor\n"
3867 "Capability to RECEIVE the ORF from this neighbor\n"
3868 "Capability to SEND the ORF to this neighbor\n")
3869 {
3870 int idx_peer = 2;
3871 int idx_send_recv = 6;
3872 uint16_t flag = 0;
3873
3874 if (strmatch(argv[idx_send_recv]->text, "send"))
3875 flag = PEER_FLAG_ORF_PREFIX_SM;
3876 else if (strmatch(argv[idx_send_recv]->text, "receive"))
3877 flag = PEER_FLAG_ORF_PREFIX_RM;
3878 else if (strmatch(argv[idx_send_recv]->text, "both"))
3879 flag = PEER_FLAG_ORF_PREFIX_SM | PEER_FLAG_ORF_PREFIX_RM;
3880 else {
3881 vty_out(vty, "%% BGP invalid orf prefix-list option\n");
3882 return CMD_WARNING_CONFIG_FAILED;
3883 }
3884
3885 return peer_af_flag_unset_vty(vty, argv[idx_peer]->arg,
3886 bgp_node_afi(vty), bgp_node_safi(vty),
3887 flag);
3888 }
3889
3890 ALIAS_HIDDEN(
3891 no_neighbor_capability_orf_prefix,
3892 no_neighbor_capability_orf_prefix_hidden_cmd,
3893 "no neighbor <A.B.C.D|X:X::X:X|WORD> capability orf prefix-list <both|send|receive>",
3894 NO_STR NEIGHBOR_STR NEIGHBOR_ADDR_STR2
3895 "Advertise capability to the peer\n"
3896 "Advertise ORF capability to the peer\n"
3897 "Advertise prefixlist ORF capability to this neighbor\n"
3898 "Capability to SEND and RECEIVE the ORF to/from this neighbor\n"
3899 "Capability to RECEIVE the ORF from this neighbor\n"
3900 "Capability to SEND the ORF to this neighbor\n")
3901
3902 /* neighbor next-hop-self. */
3903 DEFUN (neighbor_nexthop_self,
3904 neighbor_nexthop_self_cmd,
3905 "neighbor <A.B.C.D|X:X::X:X|WORD> next-hop-self",
3906 NEIGHBOR_STR
3907 NEIGHBOR_ADDR_STR2
3908 "Disable the next hop calculation for this neighbor\n")
3909 {
3910 int idx_peer = 1;
3911 return peer_af_flag_set_vty(vty, argv[idx_peer]->arg, bgp_node_afi(vty),
3912 bgp_node_safi(vty), PEER_FLAG_NEXTHOP_SELF);
3913 }
3914
3915 ALIAS_HIDDEN(neighbor_nexthop_self, neighbor_nexthop_self_hidden_cmd,
3916 "neighbor <A.B.C.D|X:X::X:X|WORD> next-hop-self",
3917 NEIGHBOR_STR NEIGHBOR_ADDR_STR2
3918 "Disable the next hop calculation for this neighbor\n")
3919
3920 /* neighbor next-hop-self. */
3921 DEFUN (neighbor_nexthop_self_force,
3922 neighbor_nexthop_self_force_cmd,
3923 "neighbor <A.B.C.D|X:X::X:X|WORD> next-hop-self force",
3924 NEIGHBOR_STR
3925 NEIGHBOR_ADDR_STR2
3926 "Disable the next hop calculation for this neighbor\n"
3927 "Set the next hop to self for reflected routes\n")
3928 {
3929 int idx_peer = 1;
3930 return peer_af_flag_set_vty(vty, argv[idx_peer]->arg, bgp_node_afi(vty),
3931 bgp_node_safi(vty),
3932 PEER_FLAG_FORCE_NEXTHOP_SELF);
3933 }
3934
3935 ALIAS_HIDDEN(neighbor_nexthop_self_force,
3936 neighbor_nexthop_self_force_hidden_cmd,
3937 "neighbor <A.B.C.D|X:X::X:X|WORD> next-hop-self force",
3938 NEIGHBOR_STR NEIGHBOR_ADDR_STR2
3939 "Disable the next hop calculation for this neighbor\n"
3940 "Set the next hop to self for reflected routes\n")
3941
3942 DEFUN (no_neighbor_nexthop_self,
3943 no_neighbor_nexthop_self_cmd,
3944 "no neighbor <A.B.C.D|X:X::X:X|WORD> next-hop-self",
3945 NO_STR
3946 NEIGHBOR_STR
3947 NEIGHBOR_ADDR_STR2
3948 "Disable the next hop calculation for this neighbor\n")
3949 {
3950 int idx_peer = 2;
3951 return peer_af_flag_unset_vty(vty, argv[idx_peer]->arg,
3952 bgp_node_afi(vty), bgp_node_safi(vty),
3953 PEER_FLAG_NEXTHOP_SELF);
3954 }
3955
3956 ALIAS_HIDDEN(no_neighbor_nexthop_self, no_neighbor_nexthop_self_hidden_cmd,
3957 "no neighbor <A.B.C.D|X:X::X:X|WORD> next-hop-self",
3958 NO_STR NEIGHBOR_STR NEIGHBOR_ADDR_STR2
3959 "Disable the next hop calculation for this neighbor\n")
3960
3961 DEFUN (no_neighbor_nexthop_self_force,
3962 no_neighbor_nexthop_self_force_cmd,
3963 "no neighbor <A.B.C.D|X:X::X:X|WORD> next-hop-self force",
3964 NO_STR
3965 NEIGHBOR_STR
3966 NEIGHBOR_ADDR_STR2
3967 "Disable the next hop calculation for this neighbor\n"
3968 "Set the next hop to self for reflected routes\n")
3969 {
3970 int idx_peer = 2;
3971 return peer_af_flag_unset_vty(vty, argv[idx_peer]->arg,
3972 bgp_node_afi(vty), bgp_node_safi(vty),
3973 PEER_FLAG_FORCE_NEXTHOP_SELF);
3974 }
3975
3976 ALIAS_HIDDEN(no_neighbor_nexthop_self_force,
3977 no_neighbor_nexthop_self_force_hidden_cmd,
3978 "no neighbor <A.B.C.D|X:X::X:X|WORD> next-hop-self force",
3979 NO_STR NEIGHBOR_STR NEIGHBOR_ADDR_STR2
3980 "Disable the next hop calculation for this neighbor\n"
3981 "Set the next hop to self for reflected routes\n")
3982
3983 /* neighbor as-override */
3984 DEFUN (neighbor_as_override,
3985 neighbor_as_override_cmd,
3986 "neighbor <A.B.C.D|X:X::X:X|WORD> as-override",
3987 NEIGHBOR_STR
3988 NEIGHBOR_ADDR_STR2
3989 "Override ASNs in outbound updates if aspath equals remote-as\n")
3990 {
3991 int idx_peer = 1;
3992 return peer_af_flag_set_vty(vty, argv[idx_peer]->arg, bgp_node_afi(vty),
3993 bgp_node_safi(vty), PEER_FLAG_AS_OVERRIDE);
3994 }
3995
3996 ALIAS_HIDDEN(neighbor_as_override, neighbor_as_override_hidden_cmd,
3997 "neighbor <A.B.C.D|X:X::X:X|WORD> as-override",
3998 NEIGHBOR_STR NEIGHBOR_ADDR_STR2
3999 "Override ASNs in outbound updates if aspath equals remote-as\n")
4000
4001 DEFUN (no_neighbor_as_override,
4002 no_neighbor_as_override_cmd,
4003 "no neighbor <A.B.C.D|X:X::X:X|WORD> as-override",
4004 NO_STR
4005 NEIGHBOR_STR
4006 NEIGHBOR_ADDR_STR2
4007 "Override ASNs in outbound updates if aspath equals remote-as\n")
4008 {
4009 int idx_peer = 2;
4010 return peer_af_flag_unset_vty(vty, argv[idx_peer]->arg,
4011 bgp_node_afi(vty), bgp_node_safi(vty),
4012 PEER_FLAG_AS_OVERRIDE);
4013 }
4014
4015 ALIAS_HIDDEN(no_neighbor_as_override, no_neighbor_as_override_hidden_cmd,
4016 "no neighbor <A.B.C.D|X:X::X:X|WORD> as-override",
4017 NO_STR NEIGHBOR_STR NEIGHBOR_ADDR_STR2
4018 "Override ASNs in outbound updates if aspath equals remote-as\n")
4019
4020 /* neighbor remove-private-AS. */
4021 DEFUN (neighbor_remove_private_as,
4022 neighbor_remove_private_as_cmd,
4023 "neighbor <A.B.C.D|X:X::X:X|WORD> remove-private-AS",
4024 NEIGHBOR_STR
4025 NEIGHBOR_ADDR_STR2
4026 "Remove private ASNs in outbound updates\n")
4027 {
4028 int idx_peer = 1;
4029 return peer_af_flag_set_vty(vty, argv[idx_peer]->arg, bgp_node_afi(vty),
4030 bgp_node_safi(vty),
4031 PEER_FLAG_REMOVE_PRIVATE_AS);
4032 }
4033
4034 ALIAS_HIDDEN(neighbor_remove_private_as, neighbor_remove_private_as_hidden_cmd,
4035 "neighbor <A.B.C.D|X:X::X:X|WORD> remove-private-AS",
4036 NEIGHBOR_STR NEIGHBOR_ADDR_STR2
4037 "Remove private ASNs in outbound updates\n")
4038
4039 DEFUN (neighbor_remove_private_as_all,
4040 neighbor_remove_private_as_all_cmd,
4041 "neighbor <A.B.C.D|X:X::X:X|WORD> remove-private-AS all",
4042 NEIGHBOR_STR
4043 NEIGHBOR_ADDR_STR2
4044 "Remove private ASNs in outbound updates\n"
4045 "Apply to all AS numbers\n")
4046 {
4047 int idx_peer = 1;
4048 return peer_af_flag_set_vty(vty, argv[idx_peer]->arg, bgp_node_afi(vty),
4049 bgp_node_safi(vty),
4050 PEER_FLAG_REMOVE_PRIVATE_AS_ALL);
4051 }
4052
4053 ALIAS_HIDDEN(neighbor_remove_private_as_all,
4054 neighbor_remove_private_as_all_hidden_cmd,
4055 "neighbor <A.B.C.D|X:X::X:X|WORD> remove-private-AS all",
4056 NEIGHBOR_STR NEIGHBOR_ADDR_STR2
4057 "Remove private ASNs in outbound updates\n"
4058 "Apply to all AS numbers")
4059
4060 DEFUN (neighbor_remove_private_as_replace_as,
4061 neighbor_remove_private_as_replace_as_cmd,
4062 "neighbor <A.B.C.D|X:X::X:X|WORD> remove-private-AS replace-AS",
4063 NEIGHBOR_STR
4064 NEIGHBOR_ADDR_STR2
4065 "Remove private ASNs in outbound updates\n"
4066 "Replace private ASNs with our ASN in outbound updates\n")
4067 {
4068 int idx_peer = 1;
4069 return peer_af_flag_set_vty(vty, argv[idx_peer]->arg, bgp_node_afi(vty),
4070 bgp_node_safi(vty),
4071 PEER_FLAG_REMOVE_PRIVATE_AS_REPLACE);
4072 }
4073
4074 ALIAS_HIDDEN(neighbor_remove_private_as_replace_as,
4075 neighbor_remove_private_as_replace_as_hidden_cmd,
4076 "neighbor <A.B.C.D|X:X::X:X|WORD> remove-private-AS replace-AS",
4077 NEIGHBOR_STR NEIGHBOR_ADDR_STR2
4078 "Remove private ASNs in outbound updates\n"
4079 "Replace private ASNs with our ASN in outbound updates\n")
4080
4081 DEFUN (neighbor_remove_private_as_all_replace_as,
4082 neighbor_remove_private_as_all_replace_as_cmd,
4083 "neighbor <A.B.C.D|X:X::X:X|WORD> remove-private-AS all replace-AS",
4084 NEIGHBOR_STR
4085 NEIGHBOR_ADDR_STR2
4086 "Remove private ASNs in outbound updates\n"
4087 "Apply to all AS numbers\n"
4088 "Replace private ASNs with our ASN in outbound updates\n")
4089 {
4090 int idx_peer = 1;
4091 return peer_af_flag_set_vty(vty, argv[idx_peer]->arg, bgp_node_afi(vty),
4092 bgp_node_safi(vty),
4093 PEER_FLAG_REMOVE_PRIVATE_AS_ALL_REPLACE);
4094 }
4095
4096 ALIAS_HIDDEN(
4097 neighbor_remove_private_as_all_replace_as,
4098 neighbor_remove_private_as_all_replace_as_hidden_cmd,
4099 "neighbor <A.B.C.D|X:X::X:X|WORD> remove-private-AS all replace-AS",
4100 NEIGHBOR_STR NEIGHBOR_ADDR_STR2
4101 "Remove private ASNs in outbound updates\n"
4102 "Apply to all AS numbers\n"
4103 "Replace private ASNs with our ASN in outbound updates\n")
4104
4105 DEFUN (no_neighbor_remove_private_as,
4106 no_neighbor_remove_private_as_cmd,
4107 "no neighbor <A.B.C.D|X:X::X:X|WORD> remove-private-AS",
4108 NO_STR
4109 NEIGHBOR_STR
4110 NEIGHBOR_ADDR_STR2
4111 "Remove private ASNs in outbound updates\n")
4112 {
4113 int idx_peer = 2;
4114 return peer_af_flag_unset_vty(vty, argv[idx_peer]->arg,
4115 bgp_node_afi(vty), bgp_node_safi(vty),
4116 PEER_FLAG_REMOVE_PRIVATE_AS);
4117 }
4118
4119 ALIAS_HIDDEN(no_neighbor_remove_private_as,
4120 no_neighbor_remove_private_as_hidden_cmd,
4121 "no neighbor <A.B.C.D|X:X::X:X|WORD> remove-private-AS",
4122 NO_STR NEIGHBOR_STR NEIGHBOR_ADDR_STR2
4123 "Remove private ASNs in outbound updates\n")
4124
4125 DEFUN (no_neighbor_remove_private_as_all,
4126 no_neighbor_remove_private_as_all_cmd,
4127 "no neighbor <A.B.C.D|X:X::X:X|WORD> remove-private-AS all",
4128 NO_STR
4129 NEIGHBOR_STR
4130 NEIGHBOR_ADDR_STR2
4131 "Remove private ASNs in outbound updates\n"
4132 "Apply to all AS numbers\n")
4133 {
4134 int idx_peer = 2;
4135 return peer_af_flag_unset_vty(vty, argv[idx_peer]->arg,
4136 bgp_node_afi(vty), bgp_node_safi(vty),
4137 PEER_FLAG_REMOVE_PRIVATE_AS_ALL);
4138 }
4139
4140 ALIAS_HIDDEN(no_neighbor_remove_private_as_all,
4141 no_neighbor_remove_private_as_all_hidden_cmd,
4142 "no neighbor <A.B.C.D|X:X::X:X|WORD> remove-private-AS all",
4143 NO_STR NEIGHBOR_STR NEIGHBOR_ADDR_STR2
4144 "Remove private ASNs in outbound updates\n"
4145 "Apply to all AS numbers\n")
4146
4147 DEFUN (no_neighbor_remove_private_as_replace_as,
4148 no_neighbor_remove_private_as_replace_as_cmd,
4149 "no neighbor <A.B.C.D|X:X::X:X|WORD> remove-private-AS replace-AS",
4150 NO_STR
4151 NEIGHBOR_STR
4152 NEIGHBOR_ADDR_STR2
4153 "Remove private ASNs in outbound updates\n"
4154 "Replace private ASNs with our ASN in outbound updates\n")
4155 {
4156 int idx_peer = 2;
4157 return peer_af_flag_unset_vty(vty, argv[idx_peer]->arg,
4158 bgp_node_afi(vty), bgp_node_safi(vty),
4159 PEER_FLAG_REMOVE_PRIVATE_AS_REPLACE);
4160 }
4161
4162 ALIAS_HIDDEN(no_neighbor_remove_private_as_replace_as,
4163 no_neighbor_remove_private_as_replace_as_hidden_cmd,
4164 "no neighbor <A.B.C.D|X:X::X:X|WORD> remove-private-AS replace-AS",
4165 NO_STR NEIGHBOR_STR NEIGHBOR_ADDR_STR2
4166 "Remove private ASNs in outbound updates\n"
4167 "Replace private ASNs with our ASN in outbound updates\n")
4168
4169 DEFUN (no_neighbor_remove_private_as_all_replace_as,
4170 no_neighbor_remove_private_as_all_replace_as_cmd,
4171 "no neighbor <A.B.C.D|X:X::X:X|WORD> remove-private-AS all replace-AS",
4172 NO_STR
4173 NEIGHBOR_STR
4174 NEIGHBOR_ADDR_STR2
4175 "Remove private ASNs in outbound updates\n"
4176 "Apply to all AS numbers\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_ALL_REPLACE);
4183 }
4184
4185 ALIAS_HIDDEN(
4186 no_neighbor_remove_private_as_all_replace_as,
4187 no_neighbor_remove_private_as_all_replace_as_hidden_cmd,
4188 "no neighbor <A.B.C.D|X:X::X:X|WORD> remove-private-AS all replace-AS",
4189 NO_STR NEIGHBOR_STR NEIGHBOR_ADDR_STR2
4190 "Remove private ASNs in outbound updates\n"
4191 "Apply to all AS numbers\n"
4192 "Replace private ASNs with our ASN in outbound updates\n")
4193
4194
4195 /* neighbor send-community. */
4196 DEFUN (neighbor_send_community,
4197 neighbor_send_community_cmd,
4198 "neighbor <A.B.C.D|X:X::X:X|WORD> send-community",
4199 NEIGHBOR_STR
4200 NEIGHBOR_ADDR_STR2
4201 "Send Community attribute to this neighbor\n")
4202 {
4203 int idx_peer = 1;
4204
4205 return peer_af_flag_set_vty(vty, argv[idx_peer]->arg, bgp_node_afi(vty),
4206 bgp_node_safi(vty),
4207 PEER_FLAG_SEND_COMMUNITY);
4208 }
4209
4210 ALIAS_HIDDEN(neighbor_send_community, neighbor_send_community_hidden_cmd,
4211 "neighbor <A.B.C.D|X:X::X:X|WORD> send-community",
4212 NEIGHBOR_STR NEIGHBOR_ADDR_STR2
4213 "Send Community attribute to this neighbor\n")
4214
4215 DEFUN (no_neighbor_send_community,
4216 no_neighbor_send_community_cmd,
4217 "no neighbor <A.B.C.D|X:X::X:X|WORD> send-community",
4218 NO_STR
4219 NEIGHBOR_STR
4220 NEIGHBOR_ADDR_STR2
4221 "Send Community attribute to this neighbor\n")
4222 {
4223 int idx_peer = 2;
4224
4225 return peer_af_flag_unset_vty(vty, argv[idx_peer]->arg,
4226 bgp_node_afi(vty), bgp_node_safi(vty),
4227 PEER_FLAG_SEND_COMMUNITY);
4228 }
4229
4230 ALIAS_HIDDEN(no_neighbor_send_community, no_neighbor_send_community_hidden_cmd,
4231 "no neighbor <A.B.C.D|X:X::X:X|WORD> send-community",
4232 NO_STR NEIGHBOR_STR NEIGHBOR_ADDR_STR2
4233 "Send Community attribute to this neighbor\n")
4234
4235 /* neighbor send-community extended. */
4236 DEFUN (neighbor_send_community_type,
4237 neighbor_send_community_type_cmd,
4238 "neighbor <A.B.C.D|X:X::X:X|WORD> send-community <both|all|extended|standard|large>",
4239 NEIGHBOR_STR
4240 NEIGHBOR_ADDR_STR2
4241 "Send Community attribute to this neighbor\n"
4242 "Send Standard and Extended Community attributes\n"
4243 "Send Standard, Large and Extended Community attributes\n"
4244 "Send Extended Community attributes\n"
4245 "Send Standard Community attributes\n"
4246 "Send Large Community attributes\n")
4247 {
4248 int idx_peer = 1;
4249 uint32_t flag = 0;
4250 const char *type = argv[argc - 1]->text;
4251
4252 if (strmatch(type, "standard")) {
4253 SET_FLAG(flag, PEER_FLAG_SEND_COMMUNITY);
4254 } else if (strmatch(type, "extended")) {
4255 SET_FLAG(flag, PEER_FLAG_SEND_EXT_COMMUNITY);
4256 } else if (strmatch(type, "large")) {
4257 SET_FLAG(flag, PEER_FLAG_SEND_LARGE_COMMUNITY);
4258 } else if (strmatch(type, "both")) {
4259 SET_FLAG(flag, PEER_FLAG_SEND_COMMUNITY);
4260 SET_FLAG(flag, PEER_FLAG_SEND_EXT_COMMUNITY);
4261 } else { /* if (strmatch(type, "all")) */
4262 SET_FLAG(flag, PEER_FLAG_SEND_COMMUNITY);
4263 SET_FLAG(flag, PEER_FLAG_SEND_EXT_COMMUNITY);
4264 SET_FLAG(flag, PEER_FLAG_SEND_LARGE_COMMUNITY);
4265 }
4266
4267 return peer_af_flag_set_vty(vty, argv[idx_peer]->arg, bgp_node_afi(vty),
4268 bgp_node_safi(vty), flag);
4269 }
4270
4271 ALIAS_HIDDEN(
4272 neighbor_send_community_type, neighbor_send_community_type_hidden_cmd,
4273 "neighbor <A.B.C.D|X:X::X:X|WORD> send-community <both|all|extended|standard|large>",
4274 NEIGHBOR_STR NEIGHBOR_ADDR_STR2
4275 "Send Community attribute to this neighbor\n"
4276 "Send Standard and Extended Community attributes\n"
4277 "Send Standard, Large and Extended Community attributes\n"
4278 "Send Extended Community attributes\n"
4279 "Send Standard Community attributes\n"
4280 "Send Large Community attributes\n")
4281
4282 DEFUN (no_neighbor_send_community_type,
4283 no_neighbor_send_community_type_cmd,
4284 "no neighbor <A.B.C.D|X:X::X:X|WORD> send-community <both|all|extended|standard|large>",
4285 NO_STR
4286 NEIGHBOR_STR
4287 NEIGHBOR_ADDR_STR2
4288 "Send Community attribute to this neighbor\n"
4289 "Send Standard and Extended Community attributes\n"
4290 "Send Standard, Large and Extended Community attributes\n"
4291 "Send Extended Community attributes\n"
4292 "Send Standard Community attributes\n"
4293 "Send Large Community attributes\n")
4294 {
4295 int idx_peer = 2;
4296 uint32_t flag = 0;
4297 const char *type = argv[argc - 1]->text;
4298
4299 if (strmatch(type, "standard")) {
4300 SET_FLAG(flag, PEER_FLAG_SEND_COMMUNITY);
4301 } else if (strmatch(type, "extended")) {
4302 SET_FLAG(flag, PEER_FLAG_SEND_EXT_COMMUNITY);
4303 } else if (strmatch(type, "large")) {
4304 SET_FLAG(flag, PEER_FLAG_SEND_LARGE_COMMUNITY);
4305 } else if (strmatch(type, "both")) {
4306 SET_FLAG(flag, PEER_FLAG_SEND_COMMUNITY);
4307 SET_FLAG(flag, PEER_FLAG_SEND_EXT_COMMUNITY);
4308 } else { /* if (strmatch(type, "all")) */
4309 SET_FLAG(flag, PEER_FLAG_SEND_COMMUNITY);
4310 SET_FLAG(flag, PEER_FLAG_SEND_EXT_COMMUNITY);
4311 SET_FLAG(flag, PEER_FLAG_SEND_LARGE_COMMUNITY);
4312 }
4313
4314 return peer_af_flag_unset_vty(vty, argv[idx_peer]->arg,
4315 bgp_node_afi(vty), bgp_node_safi(vty),
4316 flag);
4317 }
4318
4319 ALIAS_HIDDEN(
4320 no_neighbor_send_community_type,
4321 no_neighbor_send_community_type_hidden_cmd,
4322 "no neighbor <A.B.C.D|X:X::X:X|WORD> send-community <both|all|extended|standard|large>",
4323 NO_STR NEIGHBOR_STR NEIGHBOR_ADDR_STR2
4324 "Send Community attribute to this neighbor\n"
4325 "Send Standard and Extended Community attributes\n"
4326 "Send Standard, Large and Extended Community attributes\n"
4327 "Send Extended Community attributes\n"
4328 "Send Standard Community attributes\n"
4329 "Send Large Community attributes\n")
4330
4331 /* neighbor soft-reconfig. */
4332 DEFUN (neighbor_soft_reconfiguration,
4333 neighbor_soft_reconfiguration_cmd,
4334 "neighbor <A.B.C.D|X:X::X:X|WORD> soft-reconfiguration inbound",
4335 NEIGHBOR_STR
4336 NEIGHBOR_ADDR_STR2
4337 "Per neighbor soft reconfiguration\n"
4338 "Allow inbound soft reconfiguration for this neighbor\n")
4339 {
4340 int idx_peer = 1;
4341 return peer_af_flag_set_vty(vty, argv[idx_peer]->arg, bgp_node_afi(vty),
4342 bgp_node_safi(vty),
4343 PEER_FLAG_SOFT_RECONFIG);
4344 }
4345
4346 ALIAS_HIDDEN(neighbor_soft_reconfiguration,
4347 neighbor_soft_reconfiguration_hidden_cmd,
4348 "neighbor <A.B.C.D|X:X::X:X|WORD> soft-reconfiguration inbound",
4349 NEIGHBOR_STR NEIGHBOR_ADDR_STR2
4350 "Per neighbor soft reconfiguration\n"
4351 "Allow inbound soft reconfiguration for this neighbor\n")
4352
4353 DEFUN (no_neighbor_soft_reconfiguration,
4354 no_neighbor_soft_reconfiguration_cmd,
4355 "no neighbor <A.B.C.D|X:X::X:X|WORD> soft-reconfiguration inbound",
4356 NO_STR
4357 NEIGHBOR_STR
4358 NEIGHBOR_ADDR_STR2
4359 "Per neighbor soft reconfiguration\n"
4360 "Allow inbound soft reconfiguration for this neighbor\n")
4361 {
4362 int idx_peer = 2;
4363 return peer_af_flag_unset_vty(vty, argv[idx_peer]->arg,
4364 bgp_node_afi(vty), bgp_node_safi(vty),
4365 PEER_FLAG_SOFT_RECONFIG);
4366 }
4367
4368 ALIAS_HIDDEN(no_neighbor_soft_reconfiguration,
4369 no_neighbor_soft_reconfiguration_hidden_cmd,
4370 "no neighbor <A.B.C.D|X:X::X:X|WORD> soft-reconfiguration inbound",
4371 NO_STR NEIGHBOR_STR NEIGHBOR_ADDR_STR2
4372 "Per neighbor soft reconfiguration\n"
4373 "Allow inbound soft reconfiguration for this neighbor\n")
4374
4375 DEFUN (neighbor_route_reflector_client,
4376 neighbor_route_reflector_client_cmd,
4377 "neighbor <A.B.C.D|X:X::X:X|WORD> route-reflector-client",
4378 NEIGHBOR_STR
4379 NEIGHBOR_ADDR_STR2
4380 "Configure a neighbor as Route Reflector client\n")
4381 {
4382 int idx_peer = 1;
4383 struct peer *peer;
4384
4385
4386 peer = peer_and_group_lookup_vty(vty, argv[idx_peer]->arg);
4387 if (!peer)
4388 return CMD_WARNING_CONFIG_FAILED;
4389
4390 return peer_af_flag_set_vty(vty, argv[idx_peer]->arg, bgp_node_afi(vty),
4391 bgp_node_safi(vty),
4392 PEER_FLAG_REFLECTOR_CLIENT);
4393 }
4394
4395 ALIAS_HIDDEN(neighbor_route_reflector_client,
4396 neighbor_route_reflector_client_hidden_cmd,
4397 "neighbor <A.B.C.D|X:X::X:X|WORD> route-reflector-client",
4398 NEIGHBOR_STR NEIGHBOR_ADDR_STR2
4399 "Configure a neighbor as Route Reflector client\n")
4400
4401 DEFUN (no_neighbor_route_reflector_client,
4402 no_neighbor_route_reflector_client_cmd,
4403 "no neighbor <A.B.C.D|X:X::X:X|WORD> route-reflector-client",
4404 NO_STR
4405 NEIGHBOR_STR
4406 NEIGHBOR_ADDR_STR2
4407 "Configure a neighbor as Route Reflector client\n")
4408 {
4409 int idx_peer = 2;
4410 return peer_af_flag_unset_vty(vty, argv[idx_peer]->arg,
4411 bgp_node_afi(vty), bgp_node_safi(vty),
4412 PEER_FLAG_REFLECTOR_CLIENT);
4413 }
4414
4415 ALIAS_HIDDEN(no_neighbor_route_reflector_client,
4416 no_neighbor_route_reflector_client_hidden_cmd,
4417 "no neighbor <A.B.C.D|X:X::X:X|WORD> route-reflector-client",
4418 NO_STR NEIGHBOR_STR NEIGHBOR_ADDR_STR2
4419 "Configure a neighbor as Route Reflector client\n")
4420
4421 /* neighbor route-server-client. */
4422 DEFUN (neighbor_route_server_client,
4423 neighbor_route_server_client_cmd,
4424 "neighbor <A.B.C.D|X:X::X:X|WORD> route-server-client",
4425 NEIGHBOR_STR
4426 NEIGHBOR_ADDR_STR2
4427 "Configure a neighbor as Route Server client\n")
4428 {
4429 int idx_peer = 1;
4430 struct peer *peer;
4431
4432 peer = peer_and_group_lookup_vty(vty, argv[idx_peer]->arg);
4433 if (!peer)
4434 return CMD_WARNING_CONFIG_FAILED;
4435 return peer_af_flag_set_vty(vty, argv[idx_peer]->arg, bgp_node_afi(vty),
4436 bgp_node_safi(vty),
4437 PEER_FLAG_RSERVER_CLIENT);
4438 }
4439
4440 ALIAS_HIDDEN(neighbor_route_server_client,
4441 neighbor_route_server_client_hidden_cmd,
4442 "neighbor <A.B.C.D|X:X::X:X|WORD> route-server-client",
4443 NEIGHBOR_STR NEIGHBOR_ADDR_STR2
4444 "Configure a neighbor as Route Server client\n")
4445
4446 DEFUN (no_neighbor_route_server_client,
4447 no_neighbor_route_server_client_cmd,
4448 "no neighbor <A.B.C.D|X:X::X:X|WORD> route-server-client",
4449 NO_STR
4450 NEIGHBOR_STR
4451 NEIGHBOR_ADDR_STR2
4452 "Configure a neighbor as Route Server client\n")
4453 {
4454 int idx_peer = 2;
4455 return peer_af_flag_unset_vty(vty, argv[idx_peer]->arg,
4456 bgp_node_afi(vty), bgp_node_safi(vty),
4457 PEER_FLAG_RSERVER_CLIENT);
4458 }
4459
4460 ALIAS_HIDDEN(no_neighbor_route_server_client,
4461 no_neighbor_route_server_client_hidden_cmd,
4462 "no neighbor <A.B.C.D|X:X::X:X|WORD> route-server-client",
4463 NO_STR NEIGHBOR_STR NEIGHBOR_ADDR_STR2
4464 "Configure a neighbor as Route Server client\n")
4465
4466 DEFUN (neighbor_nexthop_local_unchanged,
4467 neighbor_nexthop_local_unchanged_cmd,
4468 "neighbor <A.B.C.D|X:X::X:X|WORD> nexthop-local unchanged",
4469 NEIGHBOR_STR
4470 NEIGHBOR_ADDR_STR2
4471 "Configure treatment of outgoing link-local nexthop attribute\n"
4472 "Leave link-local nexthop unchanged for this peer\n")
4473 {
4474 int idx_peer = 1;
4475 return peer_af_flag_set_vty(vty, argv[idx_peer]->arg, bgp_node_afi(vty),
4476 bgp_node_safi(vty),
4477 PEER_FLAG_NEXTHOP_LOCAL_UNCHANGED);
4478 }
4479
4480 DEFUN (no_neighbor_nexthop_local_unchanged,
4481 no_neighbor_nexthop_local_unchanged_cmd,
4482 "no neighbor <A.B.C.D|X:X::X:X|WORD> nexthop-local unchanged",
4483 NO_STR
4484 NEIGHBOR_STR
4485 NEIGHBOR_ADDR_STR2
4486 "Configure treatment of outgoing link-local-nexthop attribute\n"
4487 "Leave link-local nexthop unchanged for this peer\n")
4488 {
4489 int idx_peer = 2;
4490 return peer_af_flag_unset_vty(vty, argv[idx_peer]->arg,
4491 bgp_node_afi(vty), bgp_node_safi(vty),
4492 PEER_FLAG_NEXTHOP_LOCAL_UNCHANGED);
4493 }
4494
4495 DEFUN (neighbor_attr_unchanged,
4496 neighbor_attr_unchanged_cmd,
4497 "neighbor <A.B.C.D|X:X::X:X|WORD> attribute-unchanged [{as-path|next-hop|med}]",
4498 NEIGHBOR_STR
4499 NEIGHBOR_ADDR_STR2
4500 "BGP attribute is propagated unchanged to this neighbor\n"
4501 "As-path attribute\n"
4502 "Nexthop attribute\n"
4503 "Med attribute\n")
4504 {
4505 int idx = 0;
4506 char *peer_str = argv[1]->arg;
4507 struct peer *peer;
4508 uint16_t flags = 0;
4509 afi_t afi = bgp_node_afi(vty);
4510 safi_t safi = bgp_node_safi(vty);
4511
4512 peer = peer_and_group_lookup_vty(vty, peer_str);
4513 if (!peer)
4514 return CMD_WARNING_CONFIG_FAILED;
4515
4516 if (argv_find(argv, argc, "as-path", &idx))
4517 SET_FLAG(flags, PEER_FLAG_AS_PATH_UNCHANGED);
4518 idx = 0;
4519 if (argv_find(argv, argc, "next-hop", &idx))
4520 SET_FLAG(flags, PEER_FLAG_NEXTHOP_UNCHANGED);
4521 idx = 0;
4522 if (argv_find(argv, argc, "med", &idx))
4523 SET_FLAG(flags, PEER_FLAG_MED_UNCHANGED);
4524
4525 /* no flags means all of them! */
4526 if (!flags) {
4527 SET_FLAG(flags, PEER_FLAG_AS_PATH_UNCHANGED);
4528 SET_FLAG(flags, PEER_FLAG_NEXTHOP_UNCHANGED);
4529 SET_FLAG(flags, PEER_FLAG_MED_UNCHANGED);
4530 } else {
4531 if (!CHECK_FLAG(flags, PEER_FLAG_AS_PATH_UNCHANGED)
4532 && peer_af_flag_check(peer, afi, safi,
4533 PEER_FLAG_AS_PATH_UNCHANGED)) {
4534 peer_af_flag_unset_vty(vty, peer_str, afi, safi,
4535 PEER_FLAG_AS_PATH_UNCHANGED);
4536 }
4537
4538 if (!CHECK_FLAG(flags, PEER_FLAG_NEXTHOP_UNCHANGED)
4539 && peer_af_flag_check(peer, afi, safi,
4540 PEER_FLAG_NEXTHOP_UNCHANGED)) {
4541 peer_af_flag_unset_vty(vty, peer_str, afi, safi,
4542 PEER_FLAG_NEXTHOP_UNCHANGED);
4543 }
4544
4545 if (!CHECK_FLAG(flags, PEER_FLAG_MED_UNCHANGED)
4546 && peer_af_flag_check(peer, afi, safi,
4547 PEER_FLAG_MED_UNCHANGED)) {
4548 peer_af_flag_unset_vty(vty, peer_str, afi, safi,
4549 PEER_FLAG_MED_UNCHANGED);
4550 }
4551 }
4552
4553 return peer_af_flag_set_vty(vty, peer_str, afi, safi, flags);
4554 }
4555
4556 ALIAS_HIDDEN(
4557 neighbor_attr_unchanged, neighbor_attr_unchanged_hidden_cmd,
4558 "neighbor <A.B.C.D|X:X::X:X|WORD> attribute-unchanged [{as-path|next-hop|med}]",
4559 NEIGHBOR_STR NEIGHBOR_ADDR_STR2
4560 "BGP attribute is propagated unchanged to this neighbor\n"
4561 "As-path attribute\n"
4562 "Nexthop attribute\n"
4563 "Med attribute\n")
4564
4565 DEFUN (no_neighbor_attr_unchanged,
4566 no_neighbor_attr_unchanged_cmd,
4567 "no neighbor <A.B.C.D|X:X::X:X|WORD> attribute-unchanged [{as-path|next-hop|med}]",
4568 NO_STR
4569 NEIGHBOR_STR
4570 NEIGHBOR_ADDR_STR2
4571 "BGP attribute is propagated unchanged to this neighbor\n"
4572 "As-path attribute\n"
4573 "Nexthop attribute\n"
4574 "Med attribute\n")
4575 {
4576 int idx = 0;
4577 char *peer = argv[2]->arg;
4578 uint16_t flags = 0;
4579
4580 if (argv_find(argv, argc, "as-path", &idx))
4581 SET_FLAG(flags, PEER_FLAG_AS_PATH_UNCHANGED);
4582 idx = 0;
4583 if (argv_find(argv, argc, "next-hop", &idx))
4584 SET_FLAG(flags, PEER_FLAG_NEXTHOP_UNCHANGED);
4585 idx = 0;
4586 if (argv_find(argv, argc, "med", &idx))
4587 SET_FLAG(flags, PEER_FLAG_MED_UNCHANGED);
4588
4589 if (!flags) // no flags means all of them!
4590 {
4591 SET_FLAG(flags, PEER_FLAG_AS_PATH_UNCHANGED);
4592 SET_FLAG(flags, PEER_FLAG_NEXTHOP_UNCHANGED);
4593 SET_FLAG(flags, PEER_FLAG_MED_UNCHANGED);
4594 }
4595
4596 return peer_af_flag_unset_vty(vty, peer, bgp_node_afi(vty),
4597 bgp_node_safi(vty), flags);
4598 }
4599
4600 ALIAS_HIDDEN(
4601 no_neighbor_attr_unchanged, no_neighbor_attr_unchanged_hidden_cmd,
4602 "no neighbor <A.B.C.D|X:X::X:X|WORD> attribute-unchanged [{as-path|next-hop|med}]",
4603 NO_STR NEIGHBOR_STR NEIGHBOR_ADDR_STR2
4604 "BGP attribute is propagated unchanged to this neighbor\n"
4605 "As-path attribute\n"
4606 "Nexthop attribute\n"
4607 "Med attribute\n")
4608
4609 /* EBGP multihop configuration. */
4610 static int peer_ebgp_multihop_set_vty(struct vty *vty, const char *ip_str,
4611 const char *ttl_str)
4612 {
4613 struct peer *peer;
4614 unsigned int ttl;
4615
4616 peer = peer_and_group_lookup_vty(vty, ip_str);
4617 if (!peer)
4618 return CMD_WARNING_CONFIG_FAILED;
4619
4620 if (peer->conf_if)
4621 return bgp_vty_return(vty, BGP_ERR_INVALID_FOR_DIRECT_PEER);
4622
4623 if (!ttl_str)
4624 ttl = MAXTTL;
4625 else
4626 ttl = strtoul(ttl_str, NULL, 10);
4627
4628 return bgp_vty_return(vty, peer_ebgp_multihop_set(peer, ttl));
4629 }
4630
4631 static int peer_ebgp_multihop_unset_vty(struct vty *vty, const char *ip_str)
4632 {
4633 struct peer *peer;
4634
4635 peer = peer_and_group_lookup_vty(vty, ip_str);
4636 if (!peer)
4637 return CMD_WARNING_CONFIG_FAILED;
4638
4639 return bgp_vty_return(vty, peer_ebgp_multihop_unset(peer));
4640 }
4641
4642 /* neighbor ebgp-multihop. */
4643 DEFUN (neighbor_ebgp_multihop,
4644 neighbor_ebgp_multihop_cmd,
4645 "neighbor <A.B.C.D|X:X::X:X|WORD> ebgp-multihop",
4646 NEIGHBOR_STR
4647 NEIGHBOR_ADDR_STR2
4648 "Allow EBGP neighbors not on directly connected networks\n")
4649 {
4650 int idx_peer = 1;
4651 return peer_ebgp_multihop_set_vty(vty, argv[idx_peer]->arg, NULL);
4652 }
4653
4654 DEFUN (neighbor_ebgp_multihop_ttl,
4655 neighbor_ebgp_multihop_ttl_cmd,
4656 "neighbor <A.B.C.D|X:X::X:X|WORD> ebgp-multihop (1-255)",
4657 NEIGHBOR_STR
4658 NEIGHBOR_ADDR_STR2
4659 "Allow EBGP neighbors not on directly connected networks\n"
4660 "maximum hop count\n")
4661 {
4662 int idx_peer = 1;
4663 int idx_number = 3;
4664 return peer_ebgp_multihop_set_vty(vty, argv[idx_peer]->arg,
4665 argv[idx_number]->arg);
4666 }
4667
4668 DEFUN (no_neighbor_ebgp_multihop,
4669 no_neighbor_ebgp_multihop_cmd,
4670 "no neighbor <A.B.C.D|X:X::X:X|WORD> ebgp-multihop [(1-255)]",
4671 NO_STR
4672 NEIGHBOR_STR
4673 NEIGHBOR_ADDR_STR2
4674 "Allow EBGP neighbors not on directly connected networks\n"
4675 "maximum hop count\n")
4676 {
4677 int idx_peer = 2;
4678 return peer_ebgp_multihop_unset_vty(vty, argv[idx_peer]->arg);
4679 }
4680
4681
4682 /* disable-connected-check */
4683 DEFUN (neighbor_disable_connected_check,
4684 neighbor_disable_connected_check_cmd,
4685 "neighbor <A.B.C.D|X:X::X:X|WORD> <disable-connected-check|enforce-multihop>",
4686 NEIGHBOR_STR
4687 NEIGHBOR_ADDR_STR2
4688 "one-hop away EBGP peer using loopback address\n"
4689 "Enforce EBGP neighbors perform multihop\n")
4690 {
4691 int idx_peer = 1;
4692 return peer_flag_set_vty(vty, argv[idx_peer]->arg,
4693 PEER_FLAG_DISABLE_CONNECTED_CHECK);
4694 }
4695
4696 DEFUN (no_neighbor_disable_connected_check,
4697 no_neighbor_disable_connected_check_cmd,
4698 "no neighbor <A.B.C.D|X:X::X:X|WORD> <disable-connected-check|enforce-multihop>",
4699 NO_STR
4700 NEIGHBOR_STR
4701 NEIGHBOR_ADDR_STR2
4702 "one-hop away EBGP peer using loopback address\n"
4703 "Enforce EBGP neighbors perform multihop\n")
4704 {
4705 int idx_peer = 2;
4706 return peer_flag_unset_vty(vty, argv[idx_peer]->arg,
4707 PEER_FLAG_DISABLE_CONNECTED_CHECK);
4708 }
4709
4710
4711 /* enforce-first-as */
4712 DEFUN (neighbor_enforce_first_as,
4713 neighbor_enforce_first_as_cmd,
4714 "neighbor <A.B.C.D|X:X::X:X|WORD> enforce-first-as",
4715 NEIGHBOR_STR
4716 NEIGHBOR_ADDR_STR2
4717 "Enforce the first AS for EBGP routes\n")
4718 {
4719 int idx_peer = 1;
4720
4721 return peer_flag_set_vty(vty, argv[idx_peer]->arg,
4722 PEER_FLAG_ENFORCE_FIRST_AS);
4723 }
4724
4725 DEFUN (no_neighbor_enforce_first_as,
4726 no_neighbor_enforce_first_as_cmd,
4727 "no neighbor <A.B.C.D|X:X::X:X|WORD> enforce-first-as",
4728 NO_STR
4729 NEIGHBOR_STR
4730 NEIGHBOR_ADDR_STR2
4731 "Enforce the first AS for EBGP routes\n")
4732 {
4733 int idx_peer = 2;
4734
4735 return peer_flag_unset_vty(vty, argv[idx_peer]->arg,
4736 PEER_FLAG_ENFORCE_FIRST_AS);
4737 }
4738
4739
4740 DEFUN (neighbor_description,
4741 neighbor_description_cmd,
4742 "neighbor <A.B.C.D|X:X::X:X|WORD> description LINE...",
4743 NEIGHBOR_STR
4744 NEIGHBOR_ADDR_STR2
4745 "Neighbor specific description\n"
4746 "Up to 80 characters describing this neighbor\n")
4747 {
4748 int idx_peer = 1;
4749 int idx_line = 3;
4750 struct peer *peer;
4751 char *str;
4752
4753 peer = peer_and_group_lookup_vty(vty, argv[idx_peer]->arg);
4754 if (!peer)
4755 return CMD_WARNING_CONFIG_FAILED;
4756
4757 str = argv_concat(argv, argc, idx_line);
4758
4759 peer_description_set(peer, str);
4760
4761 XFREE(MTYPE_TMP, str);
4762
4763 return CMD_SUCCESS;
4764 }
4765
4766 DEFUN (no_neighbor_description,
4767 no_neighbor_description_cmd,
4768 "no neighbor <A.B.C.D|X:X::X:X|WORD> description",
4769 NO_STR
4770 NEIGHBOR_STR
4771 NEIGHBOR_ADDR_STR2
4772 "Neighbor specific description\n")
4773 {
4774 int idx_peer = 2;
4775 struct peer *peer;
4776
4777 peer = peer_and_group_lookup_vty(vty, argv[idx_peer]->arg);
4778 if (!peer)
4779 return CMD_WARNING_CONFIG_FAILED;
4780
4781 peer_description_unset(peer);
4782
4783 return CMD_SUCCESS;
4784 }
4785
4786 ALIAS(no_neighbor_description, no_neighbor_description_comment_cmd,
4787 "no neighbor <A.B.C.D|X:X::X:X|WORD> description LINE...",
4788 NO_STR NEIGHBOR_STR NEIGHBOR_ADDR_STR2
4789 "Neighbor specific description\n"
4790 "Up to 80 characters describing this neighbor\n")
4791
4792 /* Neighbor update-source. */
4793 static int peer_update_source_vty(struct vty *vty, const char *peer_str,
4794 const char *source_str)
4795 {
4796 struct peer *peer;
4797 struct prefix p;
4798 union sockunion su;
4799
4800 peer = peer_and_group_lookup_vty(vty, peer_str);
4801 if (!peer)
4802 return CMD_WARNING_CONFIG_FAILED;
4803
4804 if (peer->conf_if)
4805 return CMD_WARNING;
4806
4807 if (source_str) {
4808 if (str2sockunion(source_str, &su) == 0)
4809 peer_update_source_addr_set(peer, &su);
4810 else {
4811 if (str2prefix(source_str, &p)) {
4812 vty_out(vty,
4813 "%% Invalid update-source, remove prefix length \n");
4814 return CMD_WARNING_CONFIG_FAILED;
4815 } else
4816 peer_update_source_if_set(peer, source_str);
4817 }
4818 } else
4819 peer_update_source_unset(peer);
4820
4821 return CMD_SUCCESS;
4822 }
4823
4824 #define BGP_UPDATE_SOURCE_HELP_STR \
4825 "IPv4 address\n" \
4826 "IPv6 address\n" \
4827 "Interface name (requires zebra to be running)\n"
4828
4829 DEFUN (neighbor_update_source,
4830 neighbor_update_source_cmd,
4831 "neighbor <A.B.C.D|X:X::X:X|WORD> update-source <A.B.C.D|X:X::X:X|WORD>",
4832 NEIGHBOR_STR
4833 NEIGHBOR_ADDR_STR2
4834 "Source of routing updates\n"
4835 BGP_UPDATE_SOURCE_HELP_STR)
4836 {
4837 int idx_peer = 1;
4838 int idx_peer_2 = 3;
4839 return peer_update_source_vty(vty, argv[idx_peer]->arg,
4840 argv[idx_peer_2]->arg);
4841 }
4842
4843 DEFUN (no_neighbor_update_source,
4844 no_neighbor_update_source_cmd,
4845 "no neighbor <A.B.C.D|X:X::X:X|WORD> update-source [<A.B.C.D|X:X::X:X|WORD>]",
4846 NO_STR
4847 NEIGHBOR_STR
4848 NEIGHBOR_ADDR_STR2
4849 "Source of routing updates\n"
4850 BGP_UPDATE_SOURCE_HELP_STR)
4851 {
4852 int idx_peer = 2;
4853 return peer_update_source_vty(vty, argv[idx_peer]->arg, NULL);
4854 }
4855
4856 static int peer_default_originate_set_vty(struct vty *vty, const char *peer_str,
4857 afi_t afi, safi_t safi,
4858 const char *rmap, int set)
4859 {
4860 int ret;
4861 struct peer *peer;
4862 struct route_map *route_map;
4863
4864 peer = peer_and_group_lookup_vty(vty, peer_str);
4865 if (!peer)
4866 return CMD_WARNING_CONFIG_FAILED;
4867
4868 if (set) {
4869 route_map = route_map_lookup_warn_noexist(vty, rmap);
4870 ret = peer_default_originate_set(peer, afi, safi,
4871 rmap, route_map);
4872 } else
4873 ret = peer_default_originate_unset(peer, afi, safi);
4874
4875 return bgp_vty_return(vty, ret);
4876 }
4877
4878 /* neighbor default-originate. */
4879 DEFUN (neighbor_default_originate,
4880 neighbor_default_originate_cmd,
4881 "neighbor <A.B.C.D|X:X::X:X|WORD> default-originate",
4882 NEIGHBOR_STR
4883 NEIGHBOR_ADDR_STR2
4884 "Originate default route to this neighbor\n")
4885 {
4886 int idx_peer = 1;
4887 return peer_default_originate_set_vty(vty, argv[idx_peer]->arg,
4888 bgp_node_afi(vty),
4889 bgp_node_safi(vty), NULL, 1);
4890 }
4891
4892 ALIAS_HIDDEN(neighbor_default_originate, neighbor_default_originate_hidden_cmd,
4893 "neighbor <A.B.C.D|X:X::X:X|WORD> default-originate",
4894 NEIGHBOR_STR NEIGHBOR_ADDR_STR2
4895 "Originate default route to this neighbor\n")
4896
4897 DEFUN (neighbor_default_originate_rmap,
4898 neighbor_default_originate_rmap_cmd,
4899 "neighbor <A.B.C.D|X:X::X:X|WORD> default-originate route-map WORD",
4900 NEIGHBOR_STR
4901 NEIGHBOR_ADDR_STR2
4902 "Originate default route to this neighbor\n"
4903 "Route-map to specify criteria to originate default\n"
4904 "route-map name\n")
4905 {
4906 int idx_peer = 1;
4907 int idx_word = 4;
4908 return peer_default_originate_set_vty(
4909 vty, argv[idx_peer]->arg, bgp_node_afi(vty), bgp_node_safi(vty),
4910 argv[idx_word]->arg, 1);
4911 }
4912
4913 ALIAS_HIDDEN(
4914 neighbor_default_originate_rmap,
4915 neighbor_default_originate_rmap_hidden_cmd,
4916 "neighbor <A.B.C.D|X:X::X:X|WORD> default-originate route-map WORD",
4917 NEIGHBOR_STR NEIGHBOR_ADDR_STR2
4918 "Originate default route to this neighbor\n"
4919 "Route-map to specify criteria to originate default\n"
4920 "route-map name\n")
4921
4922 DEFUN (no_neighbor_default_originate,
4923 no_neighbor_default_originate_cmd,
4924 "no neighbor <A.B.C.D|X:X::X:X|WORD> default-originate [route-map WORD]",
4925 NO_STR
4926 NEIGHBOR_STR
4927 NEIGHBOR_ADDR_STR2
4928 "Originate default route to this neighbor\n"
4929 "Route-map to specify criteria to originate default\n"
4930 "route-map name\n")
4931 {
4932 int idx_peer = 2;
4933 return peer_default_originate_set_vty(vty, argv[idx_peer]->arg,
4934 bgp_node_afi(vty),
4935 bgp_node_safi(vty), NULL, 0);
4936 }
4937
4938 ALIAS_HIDDEN(
4939 no_neighbor_default_originate, no_neighbor_default_originate_hidden_cmd,
4940 "no neighbor <A.B.C.D|X:X::X:X|WORD> default-originate [route-map WORD]",
4941 NO_STR NEIGHBOR_STR NEIGHBOR_ADDR_STR2
4942 "Originate default route to this neighbor\n"
4943 "Route-map to specify criteria to originate default\n"
4944 "route-map name\n")
4945
4946
4947 /* Set neighbor's BGP port. */
4948 static int peer_port_vty(struct vty *vty, const char *ip_str, int afi,
4949 const char *port_str)
4950 {
4951 struct peer *peer;
4952 uint16_t port;
4953 struct servent *sp;
4954
4955 peer = peer_lookup_vty(vty, ip_str);
4956 if (!peer)
4957 return CMD_WARNING_CONFIG_FAILED;
4958
4959 if (!port_str) {
4960 sp = getservbyname("bgp", "tcp");
4961 port = (sp == NULL) ? BGP_PORT_DEFAULT : ntohs(sp->s_port);
4962 } else {
4963 port = strtoul(port_str, NULL, 10);
4964 }
4965
4966 peer_port_set(peer, port);
4967
4968 return CMD_SUCCESS;
4969 }
4970
4971 /* Set specified peer's BGP port. */
4972 DEFUN (neighbor_port,
4973 neighbor_port_cmd,
4974 "neighbor <A.B.C.D|X:X::X:X> port (0-65535)",
4975 NEIGHBOR_STR
4976 NEIGHBOR_ADDR_STR
4977 "Neighbor's BGP port\n"
4978 "TCP port number\n")
4979 {
4980 int idx_ip = 1;
4981 int idx_number = 3;
4982 return peer_port_vty(vty, argv[idx_ip]->arg, AFI_IP,
4983 argv[idx_number]->arg);
4984 }
4985
4986 DEFUN (no_neighbor_port,
4987 no_neighbor_port_cmd,
4988 "no neighbor <A.B.C.D|X:X::X:X> port [(0-65535)]",
4989 NO_STR
4990 NEIGHBOR_STR
4991 NEIGHBOR_ADDR_STR
4992 "Neighbor's BGP port\n"
4993 "TCP port number\n")
4994 {
4995 int idx_ip = 2;
4996 return peer_port_vty(vty, argv[idx_ip]->arg, AFI_IP, NULL);
4997 }
4998
4999
5000 /* neighbor weight. */
5001 static int peer_weight_set_vty(struct vty *vty, const char *ip_str, afi_t afi,
5002 safi_t safi, const char *weight_str)
5003 {
5004 int ret;
5005 struct peer *peer;
5006 unsigned long weight;
5007
5008 peer = peer_and_group_lookup_vty(vty, ip_str);
5009 if (!peer)
5010 return CMD_WARNING_CONFIG_FAILED;
5011
5012 weight = strtoul(weight_str, NULL, 10);
5013
5014 ret = peer_weight_set(peer, afi, safi, weight);
5015 return bgp_vty_return(vty, ret);
5016 }
5017
5018 static int peer_weight_unset_vty(struct vty *vty, const char *ip_str, afi_t afi,
5019 safi_t safi)
5020 {
5021 int ret;
5022 struct peer *peer;
5023
5024 peer = peer_and_group_lookup_vty(vty, ip_str);
5025 if (!peer)
5026 return CMD_WARNING_CONFIG_FAILED;
5027
5028 ret = peer_weight_unset(peer, afi, safi);
5029 return bgp_vty_return(vty, ret);
5030 }
5031
5032 DEFUN (neighbor_weight,
5033 neighbor_weight_cmd,
5034 "neighbor <A.B.C.D|X:X::X:X|WORD> weight (0-65535)",
5035 NEIGHBOR_STR
5036 NEIGHBOR_ADDR_STR2
5037 "Set default weight for routes from this neighbor\n"
5038 "default weight\n")
5039 {
5040 int idx_peer = 1;
5041 int idx_number = 3;
5042 return peer_weight_set_vty(vty, argv[idx_peer]->arg, bgp_node_afi(vty),
5043 bgp_node_safi(vty), argv[idx_number]->arg);
5044 }
5045
5046 ALIAS_HIDDEN(neighbor_weight, neighbor_weight_hidden_cmd,
5047 "neighbor <A.B.C.D|X:X::X:X|WORD> weight (0-65535)",
5048 NEIGHBOR_STR NEIGHBOR_ADDR_STR2
5049 "Set default weight for routes from this neighbor\n"
5050 "default weight\n")
5051
5052 DEFUN (no_neighbor_weight,
5053 no_neighbor_weight_cmd,
5054 "no neighbor <A.B.C.D|X:X::X:X|WORD> weight [(0-65535)]",
5055 NO_STR
5056 NEIGHBOR_STR
5057 NEIGHBOR_ADDR_STR2
5058 "Set default weight for routes from this neighbor\n"
5059 "default weight\n")
5060 {
5061 int idx_peer = 2;
5062 return peer_weight_unset_vty(vty, argv[idx_peer]->arg,
5063 bgp_node_afi(vty), bgp_node_safi(vty));
5064 }
5065
5066 ALIAS_HIDDEN(no_neighbor_weight, no_neighbor_weight_hidden_cmd,
5067 "no neighbor <A.B.C.D|X:X::X:X|WORD> weight [(0-65535)]",
5068 NO_STR NEIGHBOR_STR NEIGHBOR_ADDR_STR2
5069 "Set default weight for routes from this neighbor\n"
5070 "default weight\n")
5071
5072
5073 /* Override capability negotiation. */
5074 DEFUN (neighbor_override_capability,
5075 neighbor_override_capability_cmd,
5076 "neighbor <A.B.C.D|X:X::X:X|WORD> override-capability",
5077 NEIGHBOR_STR
5078 NEIGHBOR_ADDR_STR2
5079 "Override capability negotiation result\n")
5080 {
5081 int idx_peer = 1;
5082 return peer_flag_set_vty(vty, argv[idx_peer]->arg,
5083 PEER_FLAG_OVERRIDE_CAPABILITY);
5084 }
5085
5086 DEFUN (no_neighbor_override_capability,
5087 no_neighbor_override_capability_cmd,
5088 "no neighbor <A.B.C.D|X:X::X:X|WORD> override-capability",
5089 NO_STR
5090 NEIGHBOR_STR
5091 NEIGHBOR_ADDR_STR2
5092 "Override capability negotiation result\n")
5093 {
5094 int idx_peer = 2;
5095 return peer_flag_unset_vty(vty, argv[idx_peer]->arg,
5096 PEER_FLAG_OVERRIDE_CAPABILITY);
5097 }
5098
5099 DEFUN (neighbor_strict_capability,
5100 neighbor_strict_capability_cmd,
5101 "neighbor <A.B.C.D|X:X::X:X|WORD> strict-capability-match",
5102 NEIGHBOR_STR
5103 NEIGHBOR_ADDR_STR2
5104 "Strict capability negotiation match\n")
5105 {
5106 int idx_peer = 1;
5107
5108 return peer_flag_set_vty(vty, argv[idx_peer]->arg,
5109 PEER_FLAG_STRICT_CAP_MATCH);
5110 }
5111
5112 DEFUN (no_neighbor_strict_capability,
5113 no_neighbor_strict_capability_cmd,
5114 "no neighbor <A.B.C.D|X:X::X:X|WORD> strict-capability-match",
5115 NO_STR
5116 NEIGHBOR_STR
5117 NEIGHBOR_ADDR_STR2
5118 "Strict capability negotiation match\n")
5119 {
5120 int idx_peer = 2;
5121
5122 return peer_flag_unset_vty(vty, argv[idx_peer]->arg,
5123 PEER_FLAG_STRICT_CAP_MATCH);
5124 }
5125
5126 static int peer_timers_set_vty(struct vty *vty, const char *ip_str,
5127 const char *keep_str, const char *hold_str)
5128 {
5129 int ret;
5130 struct peer *peer;
5131 uint32_t keepalive;
5132 uint32_t holdtime;
5133
5134 peer = peer_and_group_lookup_vty(vty, ip_str);
5135 if (!peer)
5136 return CMD_WARNING_CONFIG_FAILED;
5137
5138 keepalive = strtoul(keep_str, NULL, 10);
5139 holdtime = strtoul(hold_str, NULL, 10);
5140
5141 ret = peer_timers_set(peer, keepalive, holdtime);
5142
5143 return bgp_vty_return(vty, ret);
5144 }
5145
5146 static int peer_timers_unset_vty(struct vty *vty, const char *ip_str)
5147 {
5148 int ret;
5149 struct peer *peer;
5150
5151 peer = peer_and_group_lookup_vty(vty, ip_str);
5152 if (!peer)
5153 return CMD_WARNING_CONFIG_FAILED;
5154
5155 ret = peer_timers_unset(peer);
5156
5157 return bgp_vty_return(vty, ret);
5158 }
5159
5160 DEFUN (neighbor_timers,
5161 neighbor_timers_cmd,
5162 "neighbor <A.B.C.D|X:X::X:X|WORD> timers (0-65535) (0-65535)",
5163 NEIGHBOR_STR
5164 NEIGHBOR_ADDR_STR2
5165 "BGP per neighbor timers\n"
5166 "Keepalive interval\n"
5167 "Holdtime\n")
5168 {
5169 int idx_peer = 1;
5170 int idx_number = 3;
5171 int idx_number_2 = 4;
5172 return peer_timers_set_vty(vty, argv[idx_peer]->arg,
5173 argv[idx_number]->arg,
5174 argv[idx_number_2]->arg);
5175 }
5176
5177 DEFUN (no_neighbor_timers,
5178 no_neighbor_timers_cmd,
5179 "no neighbor <A.B.C.D|X:X::X:X|WORD> timers [(0-65535) (0-65535)]",
5180 NO_STR
5181 NEIGHBOR_STR
5182 NEIGHBOR_ADDR_STR2
5183 "BGP per neighbor timers\n"
5184 "Keepalive interval\n"
5185 "Holdtime\n")
5186 {
5187 int idx_peer = 2;
5188 return peer_timers_unset_vty(vty, argv[idx_peer]->arg);
5189 }
5190
5191
5192 static int peer_timers_connect_set_vty(struct vty *vty, const char *ip_str,
5193 const char *time_str)
5194 {
5195 int ret;
5196 struct peer *peer;
5197 uint32_t connect;
5198
5199 peer = peer_and_group_lookup_vty(vty, ip_str);
5200 if (!peer)
5201 return CMD_WARNING_CONFIG_FAILED;
5202
5203 connect = strtoul(time_str, NULL, 10);
5204
5205 ret = peer_timers_connect_set(peer, connect);
5206
5207 return bgp_vty_return(vty, ret);
5208 }
5209
5210 static int peer_timers_connect_unset_vty(struct vty *vty, const char *ip_str)
5211 {
5212 int ret;
5213 struct peer *peer;
5214
5215 peer = peer_and_group_lookup_vty(vty, ip_str);
5216 if (!peer)
5217 return CMD_WARNING_CONFIG_FAILED;
5218
5219 ret = peer_timers_connect_unset(peer);
5220
5221 return bgp_vty_return(vty, ret);
5222 }
5223
5224 DEFUN (neighbor_timers_connect,
5225 neighbor_timers_connect_cmd,
5226 "neighbor <A.B.C.D|X:X::X:X|WORD> timers connect (1-65535)",
5227 NEIGHBOR_STR
5228 NEIGHBOR_ADDR_STR2
5229 "BGP per neighbor timers\n"
5230 "BGP connect timer\n"
5231 "Connect timer\n")
5232 {
5233 int idx_peer = 1;
5234 int idx_number = 4;
5235 return peer_timers_connect_set_vty(vty, argv[idx_peer]->arg,
5236 argv[idx_number]->arg);
5237 }
5238
5239 DEFUN (no_neighbor_timers_connect,
5240 no_neighbor_timers_connect_cmd,
5241 "no neighbor <A.B.C.D|X:X::X:X|WORD> timers connect [(1-65535)]",
5242 NO_STR
5243 NEIGHBOR_STR
5244 NEIGHBOR_ADDR_STR2
5245 "BGP per neighbor timers\n"
5246 "BGP connect timer\n"
5247 "Connect timer\n")
5248 {
5249 int idx_peer = 2;
5250 return peer_timers_connect_unset_vty(vty, argv[idx_peer]->arg);
5251 }
5252
5253
5254 static int peer_advertise_interval_vty(struct vty *vty, const char *ip_str,
5255 const char *time_str, int set)
5256 {
5257 int ret;
5258 struct peer *peer;
5259 uint32_t routeadv = 0;
5260
5261 peer = peer_and_group_lookup_vty(vty, ip_str);
5262 if (!peer)
5263 return CMD_WARNING_CONFIG_FAILED;
5264
5265 if (time_str)
5266 routeadv = strtoul(time_str, NULL, 10);
5267
5268 if (set)
5269 ret = peer_advertise_interval_set(peer, routeadv);
5270 else
5271 ret = peer_advertise_interval_unset(peer);
5272
5273 return bgp_vty_return(vty, ret);
5274 }
5275
5276 DEFUN (neighbor_advertise_interval,
5277 neighbor_advertise_interval_cmd,
5278 "neighbor <A.B.C.D|X:X::X:X|WORD> advertisement-interval (0-600)",
5279 NEIGHBOR_STR
5280 NEIGHBOR_ADDR_STR2
5281 "Minimum interval between sending BGP routing updates\n"
5282 "time in seconds\n")
5283 {
5284 int idx_peer = 1;
5285 int idx_number = 3;
5286 return peer_advertise_interval_vty(vty, argv[idx_peer]->arg,
5287 argv[idx_number]->arg, 1);
5288 }
5289
5290 DEFUN (no_neighbor_advertise_interval,
5291 no_neighbor_advertise_interval_cmd,
5292 "no neighbor <A.B.C.D|X:X::X:X|WORD> advertisement-interval [(0-600)]",
5293 NO_STR
5294 NEIGHBOR_STR
5295 NEIGHBOR_ADDR_STR2
5296 "Minimum interval between sending BGP routing updates\n"
5297 "time in seconds\n")
5298 {
5299 int idx_peer = 2;
5300 return peer_advertise_interval_vty(vty, argv[idx_peer]->arg, NULL, 0);
5301 }
5302
5303
5304 /* Time to wait before processing route-map updates */
5305 DEFUN (bgp_set_route_map_delay_timer,
5306 bgp_set_route_map_delay_timer_cmd,
5307 "bgp route-map delay-timer (0-600)",
5308 SET_STR
5309 "BGP route-map delay timer\n"
5310 "Time in secs to wait before processing route-map changes\n"
5311 "0 disables the timer, no route updates happen when route-maps change\n")
5312 {
5313 int idx_number = 3;
5314 uint32_t rmap_delay_timer;
5315
5316 if (argv[idx_number]->arg) {
5317 rmap_delay_timer = strtoul(argv[idx_number]->arg, NULL, 10);
5318 bm->rmap_update_timer = rmap_delay_timer;
5319
5320 /* if the dynamic update handling is being disabled, and a timer
5321 * is
5322 * running, stop the timer and act as if the timer has already
5323 * fired.
5324 */
5325 if (!rmap_delay_timer && bm->t_rmap_update) {
5326 BGP_TIMER_OFF(bm->t_rmap_update);
5327 thread_execute(bm->master, bgp_route_map_update_timer,
5328 NULL, 0);
5329 }
5330 return CMD_SUCCESS;
5331 } else {
5332 vty_out(vty, "%% BGP invalid route-map delay-timer\n");
5333 return CMD_WARNING_CONFIG_FAILED;
5334 }
5335 }
5336
5337 DEFUN (no_bgp_set_route_map_delay_timer,
5338 no_bgp_set_route_map_delay_timer_cmd,
5339 "no bgp route-map delay-timer [(0-600)]",
5340 NO_STR
5341 BGP_STR
5342 "Default BGP route-map delay timer\n"
5343 "Reset to default time to wait for processing route-map changes\n"
5344 "0 disables the timer, no route updates happen when route-maps change\n")
5345 {
5346
5347 bm->rmap_update_timer = RMAP_DEFAULT_UPDATE_TIMER;
5348
5349 return CMD_SUCCESS;
5350 }
5351
5352
5353 /* neighbor interface */
5354 static int peer_interface_vty(struct vty *vty, const char *ip_str,
5355 const char *str)
5356 {
5357 struct peer *peer;
5358
5359 peer = peer_lookup_vty(vty, ip_str);
5360 if (!peer || peer->conf_if) {
5361 vty_out(vty, "%% BGP invalid peer %s\n", ip_str);
5362 return CMD_WARNING_CONFIG_FAILED;
5363 }
5364
5365 if (str)
5366 peer_interface_set(peer, str);
5367 else
5368 peer_interface_unset(peer);
5369
5370 return CMD_SUCCESS;
5371 }
5372
5373 DEFUN (neighbor_interface,
5374 neighbor_interface_cmd,
5375 "neighbor <A.B.C.D|X:X::X:X> interface WORD",
5376 NEIGHBOR_STR
5377 NEIGHBOR_ADDR_STR
5378 "Interface\n"
5379 "Interface name\n")
5380 {
5381 int idx_ip = 1;
5382 int idx_word = 3;
5383 return peer_interface_vty(vty, argv[idx_ip]->arg, argv[idx_word]->arg);
5384 }
5385
5386 DEFUN (no_neighbor_interface,
5387 no_neighbor_interface_cmd,
5388 "no neighbor <A.B.C.D|X:X::X:X|WORD> interface WORD",
5389 NO_STR
5390 NEIGHBOR_STR
5391 NEIGHBOR_ADDR_STR2
5392 "Interface\n"
5393 "Interface name\n")
5394 {
5395 int idx_peer = 2;
5396 return peer_interface_vty(vty, argv[idx_peer]->arg, NULL);
5397 }
5398
5399 DEFUN (neighbor_distribute_list,
5400 neighbor_distribute_list_cmd,
5401 "neighbor <A.B.C.D|X:X::X:X|WORD> distribute-list <(1-199)|(1300-2699)|WORD> <in|out>",
5402 NEIGHBOR_STR
5403 NEIGHBOR_ADDR_STR2
5404 "Filter updates to/from this neighbor\n"
5405 "IP access-list number\n"
5406 "IP access-list number (expanded range)\n"
5407 "IP Access-list name\n"
5408 "Filter incoming updates\n"
5409 "Filter outgoing updates\n")
5410 {
5411 int idx_peer = 1;
5412 int idx_acl = 3;
5413 int direct, ret;
5414 struct peer *peer;
5415
5416 const char *pstr = argv[idx_peer]->arg;
5417 const char *acl = argv[idx_acl]->arg;
5418 const char *inout = argv[argc - 1]->text;
5419
5420 peer = peer_and_group_lookup_vty(vty, pstr);
5421 if (!peer)
5422 return CMD_WARNING_CONFIG_FAILED;
5423
5424 /* Check filter direction. */
5425 direct = strmatch(inout, "in") ? FILTER_IN : FILTER_OUT;
5426 ret = peer_distribute_set(peer, bgp_node_afi(vty), bgp_node_safi(vty),
5427 direct, acl);
5428
5429 return bgp_vty_return(vty, ret);
5430 }
5431
5432 ALIAS_HIDDEN(
5433 neighbor_distribute_list, neighbor_distribute_list_hidden_cmd,
5434 "neighbor <A.B.C.D|X:X::X:X|WORD> distribute-list <(1-199)|(1300-2699)|WORD> <in|out>",
5435 NEIGHBOR_STR NEIGHBOR_ADDR_STR2
5436 "Filter updates to/from this neighbor\n"
5437 "IP access-list number\n"
5438 "IP access-list number (expanded range)\n"
5439 "IP Access-list name\n"
5440 "Filter incoming updates\n"
5441 "Filter outgoing updates\n")
5442
5443 DEFUN (no_neighbor_distribute_list,
5444 no_neighbor_distribute_list_cmd,
5445 "no neighbor <A.B.C.D|X:X::X:X|WORD> distribute-list <(1-199)|(1300-2699)|WORD> <in|out>",
5446 NO_STR
5447 NEIGHBOR_STR
5448 NEIGHBOR_ADDR_STR2
5449 "Filter updates to/from this neighbor\n"
5450 "IP access-list number\n"
5451 "IP access-list number (expanded range)\n"
5452 "IP Access-list name\n"
5453 "Filter incoming updates\n"
5454 "Filter outgoing updates\n")
5455 {
5456 int idx_peer = 2;
5457 int direct, ret;
5458 struct peer *peer;
5459
5460 const char *pstr = argv[idx_peer]->arg;
5461 const char *inout = argv[argc - 1]->text;
5462
5463 peer = peer_and_group_lookup_vty(vty, pstr);
5464 if (!peer)
5465 return CMD_WARNING_CONFIG_FAILED;
5466
5467 /* Check filter direction. */
5468 direct = strmatch(inout, "in") ? FILTER_IN : FILTER_OUT;
5469 ret = peer_distribute_unset(peer, bgp_node_afi(vty), bgp_node_safi(vty),
5470 direct);
5471
5472 return bgp_vty_return(vty, ret);
5473 }
5474
5475 ALIAS_HIDDEN(
5476 no_neighbor_distribute_list, no_neighbor_distribute_list_hidden_cmd,
5477 "no neighbor <A.B.C.D|X:X::X:X|WORD> distribute-list <(1-199)|(1300-2699)|WORD> <in|out>",
5478 NO_STR NEIGHBOR_STR NEIGHBOR_ADDR_STR2
5479 "Filter updates to/from this neighbor\n"
5480 "IP access-list number\n"
5481 "IP access-list number (expanded range)\n"
5482 "IP Access-list name\n"
5483 "Filter incoming updates\n"
5484 "Filter outgoing updates\n")
5485
5486 /* Set prefix list to the peer. */
5487 static int peer_prefix_list_set_vty(struct vty *vty, const char *ip_str,
5488 afi_t afi, safi_t safi,
5489 const char *name_str,
5490 const char *direct_str)
5491 {
5492 int ret;
5493 int direct = FILTER_IN;
5494 struct peer *peer;
5495
5496 peer = peer_and_group_lookup_vty(vty, ip_str);
5497 if (!peer)
5498 return CMD_WARNING_CONFIG_FAILED;
5499
5500 /* Check filter direction. */
5501 if (strncmp(direct_str, "i", 1) == 0)
5502 direct = FILTER_IN;
5503 else if (strncmp(direct_str, "o", 1) == 0)
5504 direct = FILTER_OUT;
5505
5506 ret = peer_prefix_list_set(peer, afi, safi, direct, name_str);
5507
5508 return bgp_vty_return(vty, ret);
5509 }
5510
5511 static int peer_prefix_list_unset_vty(struct vty *vty, const char *ip_str,
5512 afi_t afi, safi_t safi,
5513 const char *direct_str)
5514 {
5515 int ret;
5516 struct peer *peer;
5517 int direct = FILTER_IN;
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_unset(peer, afi, safi, direct);
5530
5531 return bgp_vty_return(vty, ret);
5532 }
5533
5534 DEFUN (neighbor_prefix_list,
5535 neighbor_prefix_list_cmd,
5536 "neighbor <A.B.C.D|X:X::X:X|WORD> prefix-list WORD <in|out>",
5537 NEIGHBOR_STR
5538 NEIGHBOR_ADDR_STR2
5539 "Filter updates to/from this neighbor\n"
5540 "Name of a prefix list\n"
5541 "Filter incoming updates\n"
5542 "Filter outgoing updates\n")
5543 {
5544 int idx_peer = 1;
5545 int idx_word = 3;
5546 int idx_in_out = 4;
5547 return peer_prefix_list_set_vty(
5548 vty, argv[idx_peer]->arg, bgp_node_afi(vty), bgp_node_safi(vty),
5549 argv[idx_word]->arg, argv[idx_in_out]->arg);
5550 }
5551
5552 ALIAS_HIDDEN(neighbor_prefix_list, neighbor_prefix_list_hidden_cmd,
5553 "neighbor <A.B.C.D|X:X::X:X|WORD> prefix-list WORD <in|out>",
5554 NEIGHBOR_STR NEIGHBOR_ADDR_STR2
5555 "Filter updates to/from this neighbor\n"
5556 "Name of a prefix list\n"
5557 "Filter incoming updates\n"
5558 "Filter outgoing updates\n")
5559
5560 DEFUN (no_neighbor_prefix_list,
5561 no_neighbor_prefix_list_cmd,
5562 "no neighbor <A.B.C.D|X:X::X:X|WORD> prefix-list WORD <in|out>",
5563 NO_STR
5564 NEIGHBOR_STR
5565 NEIGHBOR_ADDR_STR2
5566 "Filter updates to/from this neighbor\n"
5567 "Name of a prefix list\n"
5568 "Filter incoming updates\n"
5569 "Filter outgoing updates\n")
5570 {
5571 int idx_peer = 2;
5572 int idx_in_out = 5;
5573 return peer_prefix_list_unset_vty(vty, argv[idx_peer]->arg,
5574 bgp_node_afi(vty), bgp_node_safi(vty),
5575 argv[idx_in_out]->arg);
5576 }
5577
5578 ALIAS_HIDDEN(no_neighbor_prefix_list, no_neighbor_prefix_list_hidden_cmd,
5579 "no neighbor <A.B.C.D|X:X::X:X|WORD> prefix-list WORD <in|out>",
5580 NO_STR NEIGHBOR_STR NEIGHBOR_ADDR_STR2
5581 "Filter updates to/from this neighbor\n"
5582 "Name of a prefix list\n"
5583 "Filter incoming updates\n"
5584 "Filter outgoing updates\n")
5585
5586 static int peer_aslist_set_vty(struct vty *vty, const char *ip_str, afi_t afi,
5587 safi_t safi, const char *name_str,
5588 const char *direct_str)
5589 {
5590 int ret;
5591 struct peer *peer;
5592 int direct = FILTER_IN;
5593
5594 peer = peer_and_group_lookup_vty(vty, ip_str);
5595 if (!peer)
5596 return CMD_WARNING_CONFIG_FAILED;
5597
5598 /* Check filter direction. */
5599 if (strncmp(direct_str, "i", 1) == 0)
5600 direct = FILTER_IN;
5601 else if (strncmp(direct_str, "o", 1) == 0)
5602 direct = FILTER_OUT;
5603
5604 ret = peer_aslist_set(peer, afi, safi, direct, name_str);
5605
5606 return bgp_vty_return(vty, ret);
5607 }
5608
5609 static int peer_aslist_unset_vty(struct vty *vty, const char *ip_str, afi_t afi,
5610 safi_t safi, const char *direct_str)
5611 {
5612 int ret;
5613 struct peer *peer;
5614 int direct = FILTER_IN;
5615
5616 peer = peer_and_group_lookup_vty(vty, ip_str);
5617 if (!peer)
5618 return CMD_WARNING_CONFIG_FAILED;
5619
5620 /* Check filter direction. */
5621 if (strncmp(direct_str, "i", 1) == 0)
5622 direct = FILTER_IN;
5623 else if (strncmp(direct_str, "o", 1) == 0)
5624 direct = FILTER_OUT;
5625
5626 ret = peer_aslist_unset(peer, afi, safi, direct);
5627
5628 return bgp_vty_return(vty, ret);
5629 }
5630
5631 DEFUN (neighbor_filter_list,
5632 neighbor_filter_list_cmd,
5633 "neighbor <A.B.C.D|X:X::X:X|WORD> filter-list WORD <in|out>",
5634 NEIGHBOR_STR
5635 NEIGHBOR_ADDR_STR2
5636 "Establish BGP filters\n"
5637 "AS path access-list name\n"
5638 "Filter incoming routes\n"
5639 "Filter outgoing routes\n")
5640 {
5641 int idx_peer = 1;
5642 int idx_word = 3;
5643 int idx_in_out = 4;
5644 return peer_aslist_set_vty(vty, argv[idx_peer]->arg, bgp_node_afi(vty),
5645 bgp_node_safi(vty), argv[idx_word]->arg,
5646 argv[idx_in_out]->arg);
5647 }
5648
5649 ALIAS_HIDDEN(neighbor_filter_list, neighbor_filter_list_hidden_cmd,
5650 "neighbor <A.B.C.D|X:X::X:X|WORD> filter-list WORD <in|out>",
5651 NEIGHBOR_STR NEIGHBOR_ADDR_STR2
5652 "Establish BGP filters\n"
5653 "AS path access-list name\n"
5654 "Filter incoming routes\n"
5655 "Filter outgoing routes\n")
5656
5657 DEFUN (no_neighbor_filter_list,
5658 no_neighbor_filter_list_cmd,
5659 "no neighbor <A.B.C.D|X:X::X:X|WORD> filter-list WORD <in|out>",
5660 NO_STR
5661 NEIGHBOR_STR
5662 NEIGHBOR_ADDR_STR2
5663 "Establish BGP filters\n"
5664 "AS path access-list name\n"
5665 "Filter incoming routes\n"
5666 "Filter outgoing routes\n")
5667 {
5668 int idx_peer = 2;
5669 int idx_in_out = 5;
5670 return peer_aslist_unset_vty(vty, argv[idx_peer]->arg,
5671 bgp_node_afi(vty), bgp_node_safi(vty),
5672 argv[idx_in_out]->arg);
5673 }
5674
5675 ALIAS_HIDDEN(no_neighbor_filter_list, no_neighbor_filter_list_hidden_cmd,
5676 "no neighbor <A.B.C.D|X:X::X:X|WORD> filter-list WORD <in|out>",
5677 NO_STR NEIGHBOR_STR NEIGHBOR_ADDR_STR2
5678 "Establish BGP filters\n"
5679 "AS path access-list name\n"
5680 "Filter incoming routes\n"
5681 "Filter outgoing routes\n")
5682
5683 /* Set route-map to the peer. */
5684 static int peer_route_map_set_vty(struct vty *vty, const char *ip_str,
5685 afi_t afi, safi_t safi, const char *name_str,
5686 const char *direct_str)
5687 {
5688 int ret;
5689 struct peer *peer;
5690 int direct = RMAP_IN;
5691 struct route_map *route_map;
5692
5693 peer = peer_and_group_lookup_vty(vty, ip_str);
5694 if (!peer)
5695 return CMD_WARNING_CONFIG_FAILED;
5696
5697 /* Check filter direction. */
5698 if (strncmp(direct_str, "in", 2) == 0)
5699 direct = RMAP_IN;
5700 else if (strncmp(direct_str, "o", 1) == 0)
5701 direct = RMAP_OUT;
5702
5703 route_map = route_map_lookup_warn_noexist(vty, name_str);
5704 ret = peer_route_map_set(peer, afi, safi, direct, name_str, route_map);
5705
5706 return bgp_vty_return(vty, ret);
5707 }
5708
5709 static int peer_route_map_unset_vty(struct vty *vty, const char *ip_str,
5710 afi_t afi, safi_t safi,
5711 const char *direct_str)
5712 {
5713 int ret;
5714 struct peer *peer;
5715 int direct = RMAP_IN;
5716
5717 peer = peer_and_group_lookup_vty(vty, ip_str);
5718 if (!peer)
5719 return CMD_WARNING_CONFIG_FAILED;
5720
5721 /* Check filter direction. */
5722 if (strncmp(direct_str, "in", 2) == 0)
5723 direct = RMAP_IN;
5724 else if (strncmp(direct_str, "o", 1) == 0)
5725 direct = RMAP_OUT;
5726
5727 ret = peer_route_map_unset(peer, afi, safi, direct);
5728
5729 return bgp_vty_return(vty, ret);
5730 }
5731
5732 DEFUN (neighbor_route_map,
5733 neighbor_route_map_cmd,
5734 "neighbor <A.B.C.D|X:X::X:X|WORD> route-map WORD <in|out>",
5735 NEIGHBOR_STR
5736 NEIGHBOR_ADDR_STR2
5737 "Apply route map to neighbor\n"
5738 "Name of route map\n"
5739 "Apply map to incoming routes\n"
5740 "Apply map to outbound routes\n")
5741 {
5742 int idx_peer = 1;
5743 int idx_word = 3;
5744 int idx_in_out = 4;
5745 return peer_route_map_set_vty(
5746 vty, argv[idx_peer]->arg, bgp_node_afi(vty), bgp_node_safi(vty),
5747 argv[idx_word]->arg, argv[idx_in_out]->arg);
5748 }
5749
5750 ALIAS_HIDDEN(neighbor_route_map, neighbor_route_map_hidden_cmd,
5751 "neighbor <A.B.C.D|X:X::X:X|WORD> route-map WORD <in|out>",
5752 NEIGHBOR_STR NEIGHBOR_ADDR_STR2
5753 "Apply route map to neighbor\n"
5754 "Name of route map\n"
5755 "Apply map to incoming routes\n"
5756 "Apply map to outbound routes\n")
5757
5758 DEFUN (no_neighbor_route_map,
5759 no_neighbor_route_map_cmd,
5760 "no neighbor <A.B.C.D|X:X::X:X|WORD> route-map WORD <in|out>",
5761 NO_STR
5762 NEIGHBOR_STR
5763 NEIGHBOR_ADDR_STR2
5764 "Apply route map to neighbor\n"
5765 "Name of route map\n"
5766 "Apply map to incoming routes\n"
5767 "Apply map to outbound routes\n")
5768 {
5769 int idx_peer = 2;
5770 int idx_in_out = 5;
5771 return peer_route_map_unset_vty(vty, argv[idx_peer]->arg,
5772 bgp_node_afi(vty), bgp_node_safi(vty),
5773 argv[idx_in_out]->arg);
5774 }
5775
5776 ALIAS_HIDDEN(no_neighbor_route_map, no_neighbor_route_map_hidden_cmd,
5777 "no neighbor <A.B.C.D|X:X::X:X|WORD> route-map WORD <in|out>",
5778 NO_STR NEIGHBOR_STR NEIGHBOR_ADDR_STR2
5779 "Apply route map to neighbor\n"
5780 "Name of route map\n"
5781 "Apply map to incoming routes\n"
5782 "Apply map to outbound routes\n")
5783
5784 /* Set unsuppress-map to the peer. */
5785 static int peer_unsuppress_map_set_vty(struct vty *vty, const char *ip_str,
5786 afi_t afi, safi_t safi,
5787 const char *name_str)
5788 {
5789 int ret;
5790 struct peer *peer;
5791 struct route_map *route_map;
5792
5793 peer = peer_and_group_lookup_vty(vty, ip_str);
5794 if (!peer)
5795 return CMD_WARNING_CONFIG_FAILED;
5796
5797 route_map = route_map_lookup_warn_noexist(vty, name_str);
5798 ret = peer_unsuppress_map_set(peer, afi, safi, name_str, route_map);
5799
5800 return bgp_vty_return(vty, ret);
5801 }
5802
5803 /* Unset route-map from the peer. */
5804 static int peer_unsuppress_map_unset_vty(struct vty *vty, const char *ip_str,
5805 afi_t afi, safi_t safi)
5806 {
5807 int ret;
5808 struct peer *peer;
5809
5810 peer = peer_and_group_lookup_vty(vty, ip_str);
5811 if (!peer)
5812 return CMD_WARNING_CONFIG_FAILED;
5813
5814 ret = peer_unsuppress_map_unset(peer, afi, safi);
5815
5816 return bgp_vty_return(vty, ret);
5817 }
5818
5819 DEFUN (neighbor_unsuppress_map,
5820 neighbor_unsuppress_map_cmd,
5821 "neighbor <A.B.C.D|X:X::X:X|WORD> unsuppress-map WORD",
5822 NEIGHBOR_STR
5823 NEIGHBOR_ADDR_STR2
5824 "Route-map to selectively unsuppress suppressed routes\n"
5825 "Name of route map\n")
5826 {
5827 int idx_peer = 1;
5828 int idx_word = 3;
5829 return peer_unsuppress_map_set_vty(
5830 vty, argv[idx_peer]->arg, bgp_node_afi(vty), bgp_node_safi(vty),
5831 argv[idx_word]->arg);
5832 }
5833
5834 ALIAS_HIDDEN(neighbor_unsuppress_map, neighbor_unsuppress_map_hidden_cmd,
5835 "neighbor <A.B.C.D|X:X::X:X|WORD> unsuppress-map WORD",
5836 NEIGHBOR_STR NEIGHBOR_ADDR_STR2
5837 "Route-map to selectively unsuppress suppressed routes\n"
5838 "Name of route map\n")
5839
5840 DEFUN (no_neighbor_unsuppress_map,
5841 no_neighbor_unsuppress_map_cmd,
5842 "no neighbor <A.B.C.D|X:X::X:X|WORD> unsuppress-map WORD",
5843 NO_STR
5844 NEIGHBOR_STR
5845 NEIGHBOR_ADDR_STR2
5846 "Route-map to selectively unsuppress suppressed routes\n"
5847 "Name of route map\n")
5848 {
5849 int idx_peer = 2;
5850 return peer_unsuppress_map_unset_vty(vty, argv[idx_peer]->arg,
5851 bgp_node_afi(vty),
5852 bgp_node_safi(vty));
5853 }
5854
5855 ALIAS_HIDDEN(no_neighbor_unsuppress_map, no_neighbor_unsuppress_map_hidden_cmd,
5856 "no neighbor <A.B.C.D|X:X::X:X|WORD> unsuppress-map WORD",
5857 NO_STR NEIGHBOR_STR NEIGHBOR_ADDR_STR2
5858 "Route-map to selectively unsuppress suppressed routes\n"
5859 "Name of route map\n")
5860
5861 static int peer_maximum_prefix_set_vty(struct vty *vty, const char *ip_str,
5862 afi_t afi, safi_t safi,
5863 const char *num_str,
5864 const char *threshold_str, int warning,
5865 const char *restart_str)
5866 {
5867 int ret;
5868 struct peer *peer;
5869 uint32_t max;
5870 uint8_t threshold;
5871 uint16_t restart;
5872
5873 peer = peer_and_group_lookup_vty(vty, ip_str);
5874 if (!peer)
5875 return CMD_WARNING_CONFIG_FAILED;
5876
5877 max = strtoul(num_str, NULL, 10);
5878 if (threshold_str)
5879 threshold = atoi(threshold_str);
5880 else
5881 threshold = MAXIMUM_PREFIX_THRESHOLD_DEFAULT;
5882
5883 if (restart_str)
5884 restart = atoi(restart_str);
5885 else
5886 restart = 0;
5887
5888 ret = peer_maximum_prefix_set(peer, afi, safi, max, threshold, warning,
5889 restart);
5890
5891 return bgp_vty_return(vty, ret);
5892 }
5893
5894 static int peer_maximum_prefix_unset_vty(struct vty *vty, const char *ip_str,
5895 afi_t afi, safi_t safi)
5896 {
5897 int ret;
5898 struct peer *peer;
5899
5900 peer = peer_and_group_lookup_vty(vty, ip_str);
5901 if (!peer)
5902 return CMD_WARNING_CONFIG_FAILED;
5903
5904 ret = peer_maximum_prefix_unset(peer, afi, safi);
5905
5906 return bgp_vty_return(vty, ret);
5907 }
5908
5909 /* Maximum number of prefix configuration. prefix count is different
5910 for each peer configuration. So this configuration can be set for
5911 each peer configuration. */
5912 DEFUN (neighbor_maximum_prefix,
5913 neighbor_maximum_prefix_cmd,
5914 "neighbor <A.B.C.D|X:X::X:X|WORD> maximum-prefix (1-4294967295)",
5915 NEIGHBOR_STR
5916 NEIGHBOR_ADDR_STR2
5917 "Maximum number of prefix accept from this peer\n"
5918 "maximum no. of prefix limit\n")
5919 {
5920 int idx_peer = 1;
5921 int idx_number = 3;
5922 return peer_maximum_prefix_set_vty(
5923 vty, argv[idx_peer]->arg, bgp_node_afi(vty), bgp_node_safi(vty),
5924 argv[idx_number]->arg, NULL, 0, NULL);
5925 }
5926
5927 ALIAS_HIDDEN(neighbor_maximum_prefix, neighbor_maximum_prefix_hidden_cmd,
5928 "neighbor <A.B.C.D|X:X::X:X|WORD> maximum-prefix (1-4294967295)",
5929 NEIGHBOR_STR NEIGHBOR_ADDR_STR2
5930 "Maximum number of prefix accept from this peer\n"
5931 "maximum no. of prefix limit\n")
5932
5933 DEFUN (neighbor_maximum_prefix_threshold,
5934 neighbor_maximum_prefix_threshold_cmd,
5935 "neighbor <A.B.C.D|X:X::X:X|WORD> maximum-prefix (1-4294967295) (1-100)",
5936 NEIGHBOR_STR
5937 NEIGHBOR_ADDR_STR2
5938 "Maximum number of prefix accept from this peer\n"
5939 "maximum no. of prefix limit\n"
5940 "Threshold value (%) at which to generate a warning msg\n")
5941 {
5942 int idx_peer = 1;
5943 int idx_number = 3;
5944 int idx_number_2 = 4;
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, argv[idx_number_2]->arg, 0, NULL);
5948 }
5949
5950 ALIAS_HIDDEN(
5951 neighbor_maximum_prefix_threshold,
5952 neighbor_maximum_prefix_threshold_hidden_cmd,
5953 "neighbor <A.B.C.D|X:X::X:X|WORD> maximum-prefix (1-4294967295) (1-100)",
5954 NEIGHBOR_STR NEIGHBOR_ADDR_STR2
5955 "Maximum number of prefix accept from this peer\n"
5956 "maximum no. of prefix limit\n"
5957 "Threshold value (%) at which to generate a warning msg\n")
5958
5959 DEFUN (neighbor_maximum_prefix_warning,
5960 neighbor_maximum_prefix_warning_cmd,
5961 "neighbor <A.B.C.D|X:X::X:X|WORD> maximum-prefix (1-4294967295) warning-only",
5962 NEIGHBOR_STR
5963 NEIGHBOR_ADDR_STR2
5964 "Maximum number of prefix accept from this peer\n"
5965 "maximum no. of prefix limit\n"
5966 "Only give warning message when limit is exceeded\n")
5967 {
5968 int idx_peer = 1;
5969 int idx_number = 3;
5970 return peer_maximum_prefix_set_vty(
5971 vty, argv[idx_peer]->arg, bgp_node_afi(vty), bgp_node_safi(vty),
5972 argv[idx_number]->arg, NULL, 1, NULL);
5973 }
5974
5975 ALIAS_HIDDEN(
5976 neighbor_maximum_prefix_warning,
5977 neighbor_maximum_prefix_warning_hidden_cmd,
5978 "neighbor <A.B.C.D|X:X::X:X|WORD> maximum-prefix (1-4294967295) warning-only",
5979 NEIGHBOR_STR NEIGHBOR_ADDR_STR2
5980 "Maximum number of prefix accept from this peer\n"
5981 "maximum no. of prefix limit\n"
5982 "Only give warning message when limit is exceeded\n")
5983
5984 DEFUN (neighbor_maximum_prefix_threshold_warning,
5985 neighbor_maximum_prefix_threshold_warning_cmd,
5986 "neighbor <A.B.C.D|X:X::X:X|WORD> maximum-prefix (1-4294967295) (1-100) warning-only",
5987 NEIGHBOR_STR
5988 NEIGHBOR_ADDR_STR2
5989 "Maximum number of prefix accept from this peer\n"
5990 "maximum no. of prefix limit\n"
5991 "Threshold value (%) at which to generate a warning msg\n"
5992 "Only give warning message when limit is exceeded\n")
5993 {
5994 int idx_peer = 1;
5995 int idx_number = 3;
5996 int idx_number_2 = 4;
5997 return peer_maximum_prefix_set_vty(
5998 vty, argv[idx_peer]->arg, bgp_node_afi(vty), bgp_node_safi(vty),
5999 argv[idx_number]->arg, argv[idx_number_2]->arg, 1, NULL);
6000 }
6001
6002 ALIAS_HIDDEN(
6003 neighbor_maximum_prefix_threshold_warning,
6004 neighbor_maximum_prefix_threshold_warning_hidden_cmd,
6005 "neighbor <A.B.C.D|X:X::X:X|WORD> maximum-prefix (1-4294967295) (1-100) warning-only",
6006 NEIGHBOR_STR NEIGHBOR_ADDR_STR2
6007 "Maximum number of prefix accept from this peer\n"
6008 "maximum no. of prefix limit\n"
6009 "Threshold value (%) at which to generate a warning msg\n"
6010 "Only give warning message when limit is exceeded\n")
6011
6012 DEFUN (neighbor_maximum_prefix_restart,
6013 neighbor_maximum_prefix_restart_cmd,
6014 "neighbor <A.B.C.D|X:X::X:X|WORD> maximum-prefix (1-4294967295) restart (1-65535)",
6015 NEIGHBOR_STR
6016 NEIGHBOR_ADDR_STR2
6017 "Maximum number of prefix accept from this peer\n"
6018 "maximum no. of prefix limit\n"
6019 "Restart bgp connection after limit is exceeded\n"
6020 "Restart interval in minutes\n")
6021 {
6022 int idx_peer = 1;
6023 int idx_number = 3;
6024 int idx_number_2 = 5;
6025 return peer_maximum_prefix_set_vty(
6026 vty, argv[idx_peer]->arg, bgp_node_afi(vty), bgp_node_safi(vty),
6027 argv[idx_number]->arg, NULL, 0, argv[idx_number_2]->arg);
6028 }
6029
6030 ALIAS_HIDDEN(
6031 neighbor_maximum_prefix_restart,
6032 neighbor_maximum_prefix_restart_hidden_cmd,
6033 "neighbor <A.B.C.D|X:X::X:X|WORD> maximum-prefix (1-4294967295) restart (1-65535)",
6034 NEIGHBOR_STR NEIGHBOR_ADDR_STR2
6035 "Maximum number of prefix accept from this peer\n"
6036 "maximum no. of prefix limit\n"
6037 "Restart bgp connection after limit is exceeded\n"
6038 "Restart interval in minutes\n")
6039
6040 DEFUN (neighbor_maximum_prefix_threshold_restart,
6041 neighbor_maximum_prefix_threshold_restart_cmd,
6042 "neighbor <A.B.C.D|X:X::X:X|WORD> maximum-prefix (1-4294967295) (1-100) restart (1-65535)",
6043 NEIGHBOR_STR
6044 NEIGHBOR_ADDR_STR2
6045 "Maximum number of prefixes to accept from this peer\n"
6046 "maximum no. of prefix limit\n"
6047 "Threshold value (%) at which to generate a warning msg\n"
6048 "Restart bgp connection after limit is exceeded\n"
6049 "Restart interval in minutes\n")
6050 {
6051 int idx_peer = 1;
6052 int idx_number = 3;
6053 int idx_number_2 = 4;
6054 int idx_number_3 = 6;
6055 return peer_maximum_prefix_set_vty(
6056 vty, argv[idx_peer]->arg, bgp_node_afi(vty), bgp_node_safi(vty),
6057 argv[idx_number]->arg, argv[idx_number_2]->arg, 0,
6058 argv[idx_number_3]->arg);
6059 }
6060
6061 ALIAS_HIDDEN(
6062 neighbor_maximum_prefix_threshold_restart,
6063 neighbor_maximum_prefix_threshold_restart_hidden_cmd,
6064 "neighbor <A.B.C.D|X:X::X:X|WORD> maximum-prefix (1-4294967295) (1-100) restart (1-65535)",
6065 NEIGHBOR_STR NEIGHBOR_ADDR_STR2
6066 "Maximum number of prefixes to accept from this peer\n"
6067 "maximum no. of prefix limit\n"
6068 "Threshold value (%) at which to generate a warning msg\n"
6069 "Restart bgp connection after limit is exceeded\n"
6070 "Restart interval in minutes\n")
6071
6072 DEFUN (no_neighbor_maximum_prefix,
6073 no_neighbor_maximum_prefix_cmd,
6074 "no neighbor <A.B.C.D|X:X::X:X|WORD> maximum-prefix [(1-4294967295) [(1-100)] [restart (1-65535)] [warning-only]]",
6075 NO_STR
6076 NEIGHBOR_STR
6077 NEIGHBOR_ADDR_STR2
6078 "Maximum number of prefixes to accept from this peer\n"
6079 "maximum no. of prefix limit\n"
6080 "Threshold value (%) at which to generate a warning msg\n"
6081 "Restart bgp connection after limit is exceeded\n"
6082 "Restart interval in minutes\n"
6083 "Only give warning message when limit is exceeded\n")
6084 {
6085 int idx_peer = 2;
6086 return peer_maximum_prefix_unset_vty(vty, argv[idx_peer]->arg,
6087 bgp_node_afi(vty),
6088 bgp_node_safi(vty));
6089 }
6090
6091 ALIAS_HIDDEN(
6092 no_neighbor_maximum_prefix, no_neighbor_maximum_prefix_hidden_cmd,
6093 "no neighbor <A.B.C.D|X:X::X:X|WORD> maximum-prefix [(1-4294967295) [(1-100)] [restart (1-65535)] [warning-only]]",
6094 NO_STR NEIGHBOR_STR NEIGHBOR_ADDR_STR2
6095 "Maximum number of prefixes to accept from this peer\n"
6096 "maximum no. of prefix limit\n"
6097 "Threshold value (%) at which to generate a warning msg\n"
6098 "Restart bgp connection after limit is exceeded\n"
6099 "Restart interval in minutes\n"
6100 "Only give warning message when limit is exceeded\n")
6101
6102
6103 /* "neighbor allowas-in" */
6104 DEFUN (neighbor_allowas_in,
6105 neighbor_allowas_in_cmd,
6106 "neighbor <A.B.C.D|X:X::X:X|WORD> allowas-in [<(1-10)|origin>]",
6107 NEIGHBOR_STR
6108 NEIGHBOR_ADDR_STR2
6109 "Accept as-path with my AS present in it\n"
6110 "Number of occurences of AS number\n"
6111 "Only accept my AS in the as-path if the route was originated in my AS\n")
6112 {
6113 int idx_peer = 1;
6114 int idx_number_origin = 3;
6115 int ret;
6116 int origin = 0;
6117 struct peer *peer;
6118 int allow_num = 0;
6119
6120 peer = peer_and_group_lookup_vty(vty, argv[idx_peer]->arg);
6121 if (!peer)
6122 return CMD_WARNING_CONFIG_FAILED;
6123
6124 if (argc <= idx_number_origin)
6125 allow_num = 3;
6126 else {
6127 if (argv[idx_number_origin]->type == WORD_TKN)
6128 origin = 1;
6129 else
6130 allow_num = atoi(argv[idx_number_origin]->arg);
6131 }
6132
6133 ret = peer_allowas_in_set(peer, bgp_node_afi(vty), bgp_node_safi(vty),
6134 allow_num, origin);
6135
6136 return bgp_vty_return(vty, ret);
6137 }
6138
6139 ALIAS_HIDDEN(
6140 neighbor_allowas_in, neighbor_allowas_in_hidden_cmd,
6141 "neighbor <A.B.C.D|X:X::X:X|WORD> allowas-in [<(1-10)|origin>]",
6142 NEIGHBOR_STR NEIGHBOR_ADDR_STR2
6143 "Accept as-path with my AS present in it\n"
6144 "Number of occurences of AS number\n"
6145 "Only accept my AS in the as-path if the route was originated in my AS\n")
6146
6147 DEFUN (no_neighbor_allowas_in,
6148 no_neighbor_allowas_in_cmd,
6149 "no neighbor <A.B.C.D|X:X::X:X|WORD> allowas-in [<(1-10)|origin>]",
6150 NO_STR
6151 NEIGHBOR_STR
6152 NEIGHBOR_ADDR_STR2
6153 "allow local ASN appears in aspath attribute\n"
6154 "Number of occurences of AS number\n"
6155 "Only accept my AS in the as-path if the route was originated in my AS\n")
6156 {
6157 int idx_peer = 2;
6158 int ret;
6159 struct peer *peer;
6160
6161 peer = peer_and_group_lookup_vty(vty, argv[idx_peer]->arg);
6162 if (!peer)
6163 return CMD_WARNING_CONFIG_FAILED;
6164
6165 ret = peer_allowas_in_unset(peer, bgp_node_afi(vty),
6166 bgp_node_safi(vty));
6167
6168 return bgp_vty_return(vty, ret);
6169 }
6170
6171 ALIAS_HIDDEN(
6172 no_neighbor_allowas_in, no_neighbor_allowas_in_hidden_cmd,
6173 "no neighbor <A.B.C.D|X:X::X:X|WORD> allowas-in [<(1-10)|origin>]",
6174 NO_STR NEIGHBOR_STR NEIGHBOR_ADDR_STR2
6175 "allow local ASN appears in aspath attribute\n"
6176 "Number of occurences of AS number\n"
6177 "Only accept my AS in the as-path if the route was originated in my AS\n")
6178
6179 DEFUN (neighbor_ttl_security,
6180 neighbor_ttl_security_cmd,
6181 "neighbor <A.B.C.D|X:X::X:X|WORD> ttl-security hops (1-254)",
6182 NEIGHBOR_STR
6183 NEIGHBOR_ADDR_STR2
6184 "BGP ttl-security parameters\n"
6185 "Specify the maximum number of hops to the BGP peer\n"
6186 "Number of hops to BGP peer\n")
6187 {
6188 int idx_peer = 1;
6189 int idx_number = 4;
6190 struct peer *peer;
6191 int gtsm_hops;
6192
6193 peer = peer_and_group_lookup_vty(vty, argv[idx_peer]->arg);
6194 if (!peer)
6195 return CMD_WARNING_CONFIG_FAILED;
6196
6197 gtsm_hops = strtoul(argv[idx_number]->arg, NULL, 10);
6198
6199 /*
6200 * If 'neighbor swpX', then this is for directly connected peers,
6201 * we should not accept a ttl-security hops value greater than 1.
6202 */
6203 if (peer->conf_if && (gtsm_hops > 1)) {
6204 vty_out(vty,
6205 "%s is directly connected peer, hops cannot exceed 1\n",
6206 argv[idx_peer]->arg);
6207 return CMD_WARNING_CONFIG_FAILED;
6208 }
6209
6210 return bgp_vty_return(vty, peer_ttl_security_hops_set(peer, gtsm_hops));
6211 }
6212
6213 DEFUN (no_neighbor_ttl_security,
6214 no_neighbor_ttl_security_cmd,
6215 "no neighbor <A.B.C.D|X:X::X:X|WORD> ttl-security hops (1-254)",
6216 NO_STR
6217 NEIGHBOR_STR
6218 NEIGHBOR_ADDR_STR2
6219 "BGP ttl-security parameters\n"
6220 "Specify the maximum number of hops to the BGP peer\n"
6221 "Number of hops to BGP peer\n")
6222 {
6223 int idx_peer = 2;
6224 struct peer *peer;
6225
6226 peer = peer_and_group_lookup_vty(vty, argv[idx_peer]->arg);
6227 if (!peer)
6228 return CMD_WARNING_CONFIG_FAILED;
6229
6230 return bgp_vty_return(vty, peer_ttl_security_hops_unset(peer));
6231 }
6232
6233 DEFUN (neighbor_addpath_tx_all_paths,
6234 neighbor_addpath_tx_all_paths_cmd,
6235 "neighbor <A.B.C.D|X:X::X:X|WORD> addpath-tx-all-paths",
6236 NEIGHBOR_STR
6237 NEIGHBOR_ADDR_STR2
6238 "Use addpath to advertise all paths to a neighbor\n")
6239 {
6240 int idx_peer = 1;
6241 struct peer *peer;
6242
6243 peer = peer_and_group_lookup_vty(vty, argv[idx_peer]->arg);
6244 if (!peer)
6245 return CMD_WARNING_CONFIG_FAILED;
6246
6247 bgp_addpath_set_peer_type(peer, bgp_node_afi(vty), bgp_node_safi(vty),
6248 BGP_ADDPATH_ALL);
6249 return CMD_SUCCESS;
6250 }
6251
6252 ALIAS_HIDDEN(neighbor_addpath_tx_all_paths,
6253 neighbor_addpath_tx_all_paths_hidden_cmd,
6254 "neighbor <A.B.C.D|X:X::X:X|WORD> addpath-tx-all-paths",
6255 NEIGHBOR_STR NEIGHBOR_ADDR_STR2
6256 "Use addpath to advertise all paths to a neighbor\n")
6257
6258 DEFUN (no_neighbor_addpath_tx_all_paths,
6259 no_neighbor_addpath_tx_all_paths_cmd,
6260 "no neighbor <A.B.C.D|X:X::X:X|WORD> addpath-tx-all-paths",
6261 NO_STR
6262 NEIGHBOR_STR
6263 NEIGHBOR_ADDR_STR2
6264 "Use addpath to advertise all paths to a neighbor\n")
6265 {
6266 int idx_peer = 2;
6267 struct peer *peer;
6268
6269 peer = peer_and_group_lookup_vty(vty, argv[idx_peer]->arg);
6270 if (!peer)
6271 return CMD_WARNING_CONFIG_FAILED;
6272
6273 if (peer->addpath_type[bgp_node_afi(vty)][bgp_node_safi(vty)]
6274 != BGP_ADDPATH_ALL) {
6275 vty_out(vty,
6276 "%% Peer not currently configured to transmit all paths.");
6277 return CMD_WARNING_CONFIG_FAILED;
6278 }
6279
6280 bgp_addpath_set_peer_type(peer, bgp_node_afi(vty), bgp_node_safi(vty),
6281 BGP_ADDPATH_NONE);
6282
6283 return CMD_SUCCESS;
6284 }
6285
6286 ALIAS_HIDDEN(no_neighbor_addpath_tx_all_paths,
6287 no_neighbor_addpath_tx_all_paths_hidden_cmd,
6288 "no neighbor <A.B.C.D|X:X::X:X|WORD> addpath-tx-all-paths",
6289 NO_STR NEIGHBOR_STR NEIGHBOR_ADDR_STR2
6290 "Use addpath to advertise all paths to a neighbor\n")
6291
6292 DEFUN (neighbor_addpath_tx_bestpath_per_as,
6293 neighbor_addpath_tx_bestpath_per_as_cmd,
6294 "neighbor <A.B.C.D|X:X::X:X|WORD> addpath-tx-bestpath-per-AS",
6295 NEIGHBOR_STR
6296 NEIGHBOR_ADDR_STR2
6297 "Use addpath to advertise the bestpath per each neighboring AS\n")
6298 {
6299 int idx_peer = 1;
6300 struct peer *peer;
6301
6302 peer = peer_and_group_lookup_vty(vty, argv[idx_peer]->arg);
6303 if (!peer)
6304 return CMD_WARNING_CONFIG_FAILED;
6305
6306 bgp_addpath_set_peer_type(peer, bgp_node_afi(vty), bgp_node_safi(vty),
6307 BGP_ADDPATH_BEST_PER_AS);
6308
6309 return CMD_SUCCESS;
6310 }
6311
6312 ALIAS_HIDDEN(neighbor_addpath_tx_bestpath_per_as,
6313 neighbor_addpath_tx_bestpath_per_as_hidden_cmd,
6314 "neighbor <A.B.C.D|X:X::X:X|WORD> addpath-tx-bestpath-per-AS",
6315 NEIGHBOR_STR NEIGHBOR_ADDR_STR2
6316 "Use addpath to advertise the bestpath per each neighboring AS\n")
6317
6318 DEFUN (no_neighbor_addpath_tx_bestpath_per_as,
6319 no_neighbor_addpath_tx_bestpath_per_as_cmd,
6320 "no neighbor <A.B.C.D|X:X::X:X|WORD> addpath-tx-bestpath-per-AS",
6321 NO_STR
6322 NEIGHBOR_STR
6323 NEIGHBOR_ADDR_STR2
6324 "Use addpath to advertise the bestpath per each neighboring AS\n")
6325 {
6326 int idx_peer = 2;
6327 struct peer *peer;
6328
6329 peer = peer_and_group_lookup_vty(vty, argv[idx_peer]->arg);
6330 if (!peer)
6331 return CMD_WARNING_CONFIG_FAILED;
6332
6333 if (peer->addpath_type[bgp_node_afi(vty)][bgp_node_safi(vty)]
6334 != BGP_ADDPATH_BEST_PER_AS) {
6335 vty_out(vty,
6336 "%% Peer not currently configured to transmit all best path per as.");
6337 return CMD_WARNING_CONFIG_FAILED;
6338 }
6339
6340 bgp_addpath_set_peer_type(peer, bgp_node_afi(vty), bgp_node_safi(vty),
6341 BGP_ADDPATH_NONE);
6342
6343 return CMD_SUCCESS;
6344 }
6345
6346 ALIAS_HIDDEN(no_neighbor_addpath_tx_bestpath_per_as,
6347 no_neighbor_addpath_tx_bestpath_per_as_hidden_cmd,
6348 "no neighbor <A.B.C.D|X:X::X:X|WORD> addpath-tx-bestpath-per-AS",
6349 NO_STR NEIGHBOR_STR NEIGHBOR_ADDR_STR2
6350 "Use addpath to advertise the bestpath per each neighboring AS\n")
6351
6352 static int set_ecom_list(struct vty *vty, int argc, struct cmd_token **argv,
6353 struct ecommunity **list)
6354 {
6355 struct ecommunity *ecom = NULL;
6356 struct ecommunity *ecomadd;
6357
6358 for (; argc; --argc, ++argv) {
6359
6360 ecomadd = ecommunity_str2com(argv[0]->arg,
6361 ECOMMUNITY_ROUTE_TARGET, 0);
6362 if (!ecomadd) {
6363 vty_out(vty, "Malformed community-list value\n");
6364 if (ecom)
6365 ecommunity_free(&ecom);
6366 return CMD_WARNING_CONFIG_FAILED;
6367 }
6368
6369 if (ecom) {
6370 ecommunity_merge(ecom, ecomadd);
6371 ecommunity_free(&ecomadd);
6372 } else {
6373 ecom = ecomadd;
6374 }
6375 }
6376
6377 if (*list) {
6378 ecommunity_free(&*list);
6379 }
6380 *list = ecom;
6381
6382 return CMD_SUCCESS;
6383 }
6384
6385 /*
6386 * v2vimport is true if we are handling a `import vrf ...` command
6387 */
6388 static afi_t vpn_policy_getafi(struct vty *vty, struct bgp *bgp, bool v2vimport)
6389 {
6390 afi_t afi;
6391
6392 switch (vty->node) {
6393 case BGP_IPV4_NODE:
6394 afi = AFI_IP;
6395 break;
6396 case BGP_IPV6_NODE:
6397 afi = AFI_IP6;
6398 break;
6399 default:
6400 vty_out(vty,
6401 "%% context error: valid only in address-family <ipv4|ipv6> unicast block\n");
6402 return AFI_MAX;
6403 }
6404
6405 if (!v2vimport) {
6406 if (CHECK_FLAG(bgp->af_flags[afi][SAFI_UNICAST],
6407 BGP_CONFIG_VRF_TO_VRF_IMPORT)
6408 || CHECK_FLAG(bgp->af_flags[afi][SAFI_UNICAST],
6409 BGP_CONFIG_VRF_TO_VRF_EXPORT)) {
6410 vty_out(vty,
6411 "%% error: Please unconfigure import vrf commands before using vpn commands\n");
6412 return AFI_MAX;
6413 }
6414 } else {
6415 if (CHECK_FLAG(bgp->af_flags[afi][SAFI_UNICAST],
6416 BGP_CONFIG_VRF_TO_MPLSVPN_EXPORT)
6417 || CHECK_FLAG(bgp->af_flags[afi][SAFI_UNICAST],
6418 BGP_CONFIG_MPLSVPN_TO_VRF_IMPORT)) {
6419 vty_out(vty,
6420 "%% error: Please unconfigure vpn to vrf commands before using import vrf commands\n");
6421 return AFI_MAX;
6422 }
6423 }
6424 return afi;
6425 }
6426
6427 DEFPY (af_rd_vpn_export,
6428 af_rd_vpn_export_cmd,
6429 "[no] rd vpn export ASN:NN_OR_IP-ADDRESS:NN$rd_str",
6430 NO_STR
6431 "Specify route distinguisher\n"
6432 "Between current address-family and vpn\n"
6433 "For routes leaked from current address-family to vpn\n"
6434 "Route Distinguisher (<as-number>:<number> | <ip-address>:<number>)\n")
6435 {
6436 VTY_DECLVAR_CONTEXT(bgp, bgp);
6437 struct prefix_rd prd;
6438 int ret;
6439 afi_t afi;
6440 int idx = 0;
6441 int yes = 1;
6442
6443 if (argv_find(argv, argc, "no", &idx))
6444 yes = 0;
6445
6446 if (yes) {
6447 ret = str2prefix_rd(rd_str, &prd);
6448 if (!ret) {
6449 vty_out(vty, "%% Malformed rd\n");
6450 return CMD_WARNING_CONFIG_FAILED;
6451 }
6452 }
6453
6454 afi = vpn_policy_getafi(vty, bgp, false);
6455 if (afi == AFI_MAX)
6456 return CMD_WARNING_CONFIG_FAILED;
6457
6458 /*
6459 * pre-change: un-export vpn routes (vpn->vrf routes unaffected)
6460 */
6461 vpn_leak_prechange(BGP_VPN_POLICY_DIR_TOVPN, afi,
6462 bgp_get_default(), bgp);
6463
6464 if (yes) {
6465 bgp->vpn_policy[afi].tovpn_rd = prd;
6466 SET_FLAG(bgp->vpn_policy[afi].flags,
6467 BGP_VPN_POLICY_TOVPN_RD_SET);
6468 } else {
6469 UNSET_FLAG(bgp->vpn_policy[afi].flags,
6470 BGP_VPN_POLICY_TOVPN_RD_SET);
6471 }
6472
6473 /* post-change: re-export vpn routes */
6474 vpn_leak_postchange(BGP_VPN_POLICY_DIR_TOVPN, afi,
6475 bgp_get_default(), bgp);
6476
6477 return CMD_SUCCESS;
6478 }
6479
6480 ALIAS (af_rd_vpn_export,
6481 af_no_rd_vpn_export_cmd,
6482 "no rd vpn export",
6483 NO_STR
6484 "Specify route distinguisher\n"
6485 "Between current address-family and vpn\n"
6486 "For routes leaked from current address-family to vpn\n")
6487
6488 DEFPY (af_label_vpn_export,
6489 af_label_vpn_export_cmd,
6490 "[no] label vpn export <(0-1048575)$label_val|auto$label_auto>",
6491 NO_STR
6492 "label value for VRF\n"
6493 "Between current address-family and vpn\n"
6494 "For routes leaked from current address-family to vpn\n"
6495 "Label Value <0-1048575>\n"
6496 "Automatically assign a label\n")
6497 {
6498 VTY_DECLVAR_CONTEXT(bgp, bgp);
6499 mpls_label_t label = MPLS_LABEL_NONE;
6500 afi_t afi;
6501 int idx = 0;
6502 int yes = 1;
6503
6504 if (argv_find(argv, argc, "no", &idx))
6505 yes = 0;
6506
6507 /* If "no ...", squash trailing parameter */
6508 if (!yes)
6509 label_auto = NULL;
6510
6511 if (yes) {
6512 if (!label_auto)
6513 label = label_val; /* parser should force unsigned */
6514 }
6515
6516 afi = vpn_policy_getafi(vty, bgp, false);
6517 if (afi == AFI_MAX)
6518 return CMD_WARNING_CONFIG_FAILED;
6519
6520
6521 if (label_auto && CHECK_FLAG(bgp->vpn_policy[afi].flags,
6522 BGP_VPN_POLICY_TOVPN_LABEL_AUTO))
6523 /* no change */
6524 return CMD_SUCCESS;
6525
6526 /*
6527 * pre-change: un-export vpn routes (vpn->vrf routes unaffected)
6528 */
6529 vpn_leak_prechange(BGP_VPN_POLICY_DIR_TOVPN, afi,
6530 bgp_get_default(), bgp);
6531
6532 if (!label_auto && CHECK_FLAG(bgp->vpn_policy[afi].flags,
6533 BGP_VPN_POLICY_TOVPN_LABEL_AUTO)) {
6534
6535 if (bgp->vpn_policy[afi].tovpn_label != MPLS_LABEL_NONE) {
6536
6537 /*
6538 * label has previously been automatically
6539 * assigned by labelpool: release it
6540 *
6541 * NB if tovpn_label == MPLS_LABEL_NONE it
6542 * means the automatic assignment is in flight
6543 * and therefore the labelpool callback must
6544 * detect that the auto label is not needed.
6545 */
6546
6547 bgp_lp_release(LP_TYPE_VRF,
6548 &bgp->vpn_policy[afi],
6549 bgp->vpn_policy[afi].tovpn_label);
6550 }
6551 UNSET_FLAG(bgp->vpn_policy[afi].flags,
6552 BGP_VPN_POLICY_TOVPN_LABEL_AUTO);
6553 }
6554
6555 bgp->vpn_policy[afi].tovpn_label = label;
6556 if (label_auto) {
6557 SET_FLAG(bgp->vpn_policy[afi].flags,
6558 BGP_VPN_POLICY_TOVPN_LABEL_AUTO);
6559 bgp_lp_get(LP_TYPE_VRF, &bgp->vpn_policy[afi],
6560 vpn_leak_label_callback);
6561 }
6562
6563 /* post-change: re-export vpn routes */
6564 vpn_leak_postchange(BGP_VPN_POLICY_DIR_TOVPN, afi,
6565 bgp_get_default(), bgp);
6566
6567 return CMD_SUCCESS;
6568 }
6569
6570 ALIAS (af_label_vpn_export,
6571 af_no_label_vpn_export_cmd,
6572 "no label vpn export",
6573 NO_STR
6574 "label value for VRF\n"
6575 "Between current address-family and vpn\n"
6576 "For routes leaked from current address-family to vpn\n")
6577
6578 DEFPY (af_nexthop_vpn_export,
6579 af_nexthop_vpn_export_cmd,
6580 "[no] nexthop vpn export <A.B.C.D|X:X::X:X>$nexthop_str",
6581 NO_STR
6582 "Specify next hop to use for VRF advertised prefixes\n"
6583 "Between current address-family and vpn\n"
6584 "For routes leaked from current address-family to vpn\n"
6585 "IPv4 prefix\n"
6586 "IPv6 prefix\n")
6587 {
6588 VTY_DECLVAR_CONTEXT(bgp, bgp);
6589 afi_t afi;
6590 struct prefix p;
6591 int idx = 0;
6592 int yes = 1;
6593
6594 if (argv_find(argv, argc, "no", &idx))
6595 yes = 0;
6596
6597 if (yes) {
6598 if (!sockunion2hostprefix(nexthop_str, &p))
6599 return CMD_WARNING_CONFIG_FAILED;
6600 }
6601
6602 afi = vpn_policy_getafi(vty, bgp, false);
6603 if (afi == AFI_MAX)
6604 return CMD_WARNING_CONFIG_FAILED;
6605
6606 /*
6607 * pre-change: un-export vpn routes (vpn->vrf routes unaffected)
6608 */
6609 vpn_leak_prechange(BGP_VPN_POLICY_DIR_TOVPN, afi,
6610 bgp_get_default(), bgp);
6611
6612 if (yes) {
6613 bgp->vpn_policy[afi].tovpn_nexthop = p;
6614 SET_FLAG(bgp->vpn_policy[afi].flags,
6615 BGP_VPN_POLICY_TOVPN_NEXTHOP_SET);
6616 } else {
6617 UNSET_FLAG(bgp->vpn_policy[afi].flags,
6618 BGP_VPN_POLICY_TOVPN_NEXTHOP_SET);
6619 }
6620
6621 /* post-change: re-export vpn routes */
6622 vpn_leak_postchange(BGP_VPN_POLICY_DIR_TOVPN, afi,
6623 bgp_get_default(), bgp);
6624
6625 return CMD_SUCCESS;
6626 }
6627
6628 ALIAS (af_nexthop_vpn_export,
6629 af_no_nexthop_vpn_export_cmd,
6630 "no nexthop vpn export",
6631 NO_STR
6632 "Specify next hop to use for VRF advertised prefixes\n"
6633 "Between current address-family and vpn\n"
6634 "For routes leaked from current address-family to vpn\n")
6635
6636 static int vpn_policy_getdirs(struct vty *vty, const char *dstr, int *dodir)
6637 {
6638 if (!strcmp(dstr, "import")) {
6639 dodir[BGP_VPN_POLICY_DIR_FROMVPN] = 1;
6640 } else if (!strcmp(dstr, "export")) {
6641 dodir[BGP_VPN_POLICY_DIR_TOVPN] = 1;
6642 } else if (!strcmp(dstr, "both")) {
6643 dodir[BGP_VPN_POLICY_DIR_FROMVPN] = 1;
6644 dodir[BGP_VPN_POLICY_DIR_TOVPN] = 1;
6645 } else {
6646 vty_out(vty, "%% direction parse error\n");
6647 return CMD_WARNING_CONFIG_FAILED;
6648 }
6649 return CMD_SUCCESS;
6650 }
6651
6652 DEFPY (af_rt_vpn_imexport,
6653 af_rt_vpn_imexport_cmd,
6654 "[no] <rt|route-target> vpn <import|export|both>$direction_str RTLIST...",
6655 NO_STR
6656 "Specify route target list\n"
6657 "Specify route target list\n"
6658 "Between current address-family and vpn\n"
6659 "For routes leaked from vpn to current address-family: match any\n"
6660 "For routes leaked from current address-family to vpn: set\n"
6661 "both import: match any and export: set\n"
6662 "Space separated route target list (A.B.C.D:MN|EF:OPQR|GHJK:MN)\n")
6663 {
6664 VTY_DECLVAR_CONTEXT(bgp, bgp);
6665 int ret;
6666 struct ecommunity *ecom = NULL;
6667 int dodir[BGP_VPN_POLICY_DIR_MAX] = {0};
6668 vpn_policy_direction_t dir;
6669 afi_t afi;
6670 int idx = 0;
6671 int yes = 1;
6672
6673 if (argv_find(argv, argc, "no", &idx))
6674 yes = 0;
6675
6676 afi = vpn_policy_getafi(vty, bgp, false);
6677 if (afi == AFI_MAX)
6678 return CMD_WARNING_CONFIG_FAILED;
6679
6680 ret = vpn_policy_getdirs(vty, direction_str, dodir);
6681 if (ret != CMD_SUCCESS)
6682 return ret;
6683
6684 if (yes) {
6685 if (!argv_find(argv, argc, "RTLIST", &idx)) {
6686 vty_out(vty, "%% Missing RTLIST\n");
6687 return CMD_WARNING_CONFIG_FAILED;
6688 }
6689 ret = set_ecom_list(vty, argc - idx, argv + idx, &ecom);
6690 if (ret != CMD_SUCCESS) {
6691 return ret;
6692 }
6693 }
6694
6695 for (dir = 0; dir < BGP_VPN_POLICY_DIR_MAX; ++dir) {
6696 if (!dodir[dir])
6697 continue;
6698
6699 vpn_leak_prechange(dir, afi, bgp_get_default(), bgp);
6700
6701 if (yes) {
6702 if (bgp->vpn_policy[afi].rtlist[dir])
6703 ecommunity_free(
6704 &bgp->vpn_policy[afi].rtlist[dir]);
6705 bgp->vpn_policy[afi].rtlist[dir] =
6706 ecommunity_dup(ecom);
6707 } else {
6708 if (bgp->vpn_policy[afi].rtlist[dir])
6709 ecommunity_free(
6710 &bgp->vpn_policy[afi].rtlist[dir]);
6711 bgp->vpn_policy[afi].rtlist[dir] = NULL;
6712 }
6713
6714 vpn_leak_postchange(dir, afi, bgp_get_default(), bgp);
6715 }
6716
6717 if (ecom)
6718 ecommunity_free(&ecom);
6719
6720 return CMD_SUCCESS;
6721 }
6722
6723 ALIAS (af_rt_vpn_imexport,
6724 af_no_rt_vpn_imexport_cmd,
6725 "no <rt|route-target> vpn <import|export|both>$direction_str",
6726 NO_STR
6727 "Specify route target list\n"
6728 "Specify route target list\n"
6729 "Between current address-family and vpn\n"
6730 "For routes leaked from vpn to current address-family\n"
6731 "For routes leaked from current address-family to vpn\n"
6732 "both import and export\n")
6733
6734 DEFPY (af_route_map_vpn_imexport,
6735 af_route_map_vpn_imexport_cmd,
6736 /* future: "route-map <vpn|evpn|vrf NAME> <import|export> RMAP" */
6737 "[no] route-map vpn <import|export>$direction_str RMAP$rmap_str",
6738 NO_STR
6739 "Specify route map\n"
6740 "Between current address-family and vpn\n"
6741 "For routes leaked from vpn to current address-family\n"
6742 "For routes leaked from current address-family to vpn\n"
6743 "name of route-map\n")
6744 {
6745 VTY_DECLVAR_CONTEXT(bgp, bgp);
6746 int ret;
6747 int dodir[BGP_VPN_POLICY_DIR_MAX] = {0};
6748 vpn_policy_direction_t dir;
6749 afi_t afi;
6750 int idx = 0;
6751 int yes = 1;
6752
6753 if (argv_find(argv, argc, "no", &idx))
6754 yes = 0;
6755
6756 afi = vpn_policy_getafi(vty, bgp, false);
6757 if (afi == AFI_MAX)
6758 return CMD_WARNING_CONFIG_FAILED;
6759
6760 ret = vpn_policy_getdirs(vty, direction_str, dodir);
6761 if (ret != CMD_SUCCESS)
6762 return ret;
6763
6764 for (dir = 0; dir < BGP_VPN_POLICY_DIR_MAX; ++dir) {
6765 if (!dodir[dir])
6766 continue;
6767
6768 vpn_leak_prechange(dir, afi, bgp_get_default(), bgp);
6769
6770 if (yes) {
6771 if (bgp->vpn_policy[afi].rmap_name[dir])
6772 XFREE(MTYPE_ROUTE_MAP_NAME,
6773 bgp->vpn_policy[afi].rmap_name[dir]);
6774 bgp->vpn_policy[afi].rmap_name[dir] = XSTRDUP(
6775 MTYPE_ROUTE_MAP_NAME, rmap_str);
6776 bgp->vpn_policy[afi].rmap[dir] =
6777 route_map_lookup_warn_noexist(vty, rmap_str);
6778 if (!bgp->vpn_policy[afi].rmap[dir])
6779 return CMD_SUCCESS;
6780 } else {
6781 if (bgp->vpn_policy[afi].rmap_name[dir])
6782 XFREE(MTYPE_ROUTE_MAP_NAME,
6783 bgp->vpn_policy[afi].rmap_name[dir]);
6784 bgp->vpn_policy[afi].rmap_name[dir] = NULL;
6785 bgp->vpn_policy[afi].rmap[dir] = NULL;
6786 }
6787
6788 vpn_leak_postchange(dir, afi, bgp_get_default(), bgp);
6789 }
6790
6791 return CMD_SUCCESS;
6792 }
6793
6794 ALIAS (af_route_map_vpn_imexport,
6795 af_no_route_map_vpn_imexport_cmd,
6796 "no route-map vpn <import|export>$direction_str",
6797 NO_STR
6798 "Specify route map\n"
6799 "Between current address-family and vpn\n"
6800 "For routes leaked from vpn to current address-family\n"
6801 "For routes leaked from current address-family to vpn\n")
6802
6803 DEFPY(af_import_vrf_route_map, af_import_vrf_route_map_cmd,
6804 "[no] import vrf route-map RMAP$rmap_str",
6805 NO_STR
6806 "Import routes from another VRF\n"
6807 "Vrf routes being filtered\n"
6808 "Specify route map\n"
6809 "name of route-map\n")
6810 {
6811 VTY_DECLVAR_CONTEXT(bgp, bgp);
6812 vpn_policy_direction_t dir = BGP_VPN_POLICY_DIR_FROMVPN;
6813 afi_t afi;
6814 int idx = 0;
6815 int yes = 1;
6816 struct bgp *bgp_default;
6817
6818 if (argv_find(argv, argc, "no", &idx))
6819 yes = 0;
6820
6821 afi = vpn_policy_getafi(vty, bgp, true);
6822 if (afi == AFI_MAX)
6823 return CMD_WARNING_CONFIG_FAILED;
6824
6825 bgp_default = bgp_get_default();
6826 if (!bgp_default) {
6827 int32_t ret;
6828 as_t as = bgp->as;
6829
6830 /* Auto-create assuming the same AS */
6831 ret = bgp_get(&bgp_default, &as, NULL,
6832 BGP_INSTANCE_TYPE_DEFAULT);
6833
6834 if (ret) {
6835 vty_out(vty,
6836 "VRF default is not configured as a bgp instance\n");
6837 return CMD_WARNING;
6838 }
6839 }
6840
6841 vpn_leak_prechange(dir, afi, bgp_get_default(), bgp);
6842
6843 if (yes) {
6844 if (bgp->vpn_policy[afi].rmap_name[dir])
6845 XFREE(MTYPE_ROUTE_MAP_NAME,
6846 bgp->vpn_policy[afi].rmap_name[dir]);
6847 bgp->vpn_policy[afi].rmap_name[dir] =
6848 XSTRDUP(MTYPE_ROUTE_MAP_NAME, rmap_str);
6849 bgp->vpn_policy[afi].rmap[dir] =
6850 route_map_lookup_warn_noexist(vty, rmap_str);
6851 if (!bgp->vpn_policy[afi].rmap[dir])
6852 return CMD_SUCCESS;
6853 } else {
6854 if (bgp->vpn_policy[afi].rmap_name[dir])
6855 XFREE(MTYPE_ROUTE_MAP_NAME,
6856 bgp->vpn_policy[afi].rmap_name[dir]);
6857 bgp->vpn_policy[afi].rmap_name[dir] = NULL;
6858 bgp->vpn_policy[afi].rmap[dir] = NULL;
6859 }
6860
6861 vpn_leak_postchange(dir, afi, bgp_get_default(), bgp);
6862
6863 return CMD_SUCCESS;
6864 }
6865
6866 ALIAS(af_import_vrf_route_map, af_no_import_vrf_route_map_cmd,
6867 "no import vrf route-map",
6868 NO_STR
6869 "Import routes from another VRF\n"
6870 "Vrf routes being filtered\n"
6871 "Specify route map\n")
6872
6873 DEFPY(bgp_imexport_vrf, bgp_imexport_vrf_cmd,
6874 "[no] import vrf VIEWVRFNAME$import_name",
6875 NO_STR
6876 "Import routes from another VRF\n"
6877 "VRF to import from\n"
6878 "The name of the VRF\n")
6879 {
6880 VTY_DECLVAR_CONTEXT(bgp, bgp);
6881 struct listnode *node;
6882 struct bgp *vrf_bgp, *bgp_default;
6883 int32_t ret = 0;
6884 as_t as = bgp->as;
6885 bool remove = false;
6886 int32_t idx = 0;
6887 char *vname;
6888 enum bgp_instance_type bgp_type = BGP_INSTANCE_TYPE_VRF;
6889 safi_t safi;
6890 afi_t afi;
6891
6892 if (import_name == NULL) {
6893 vty_out(vty, "%% Missing import name\n");
6894 return CMD_WARNING;
6895 }
6896
6897 if (argv_find(argv, argc, "no", &idx))
6898 remove = true;
6899
6900 afi = vpn_policy_getafi(vty, bgp, true);
6901 if (afi == AFI_MAX)
6902 return CMD_WARNING_CONFIG_FAILED;
6903
6904 safi = bgp_node_safi(vty);
6905
6906 if (((BGP_INSTANCE_TYPE_DEFAULT == bgp->inst_type)
6907 && (strcmp(import_name, VRF_DEFAULT_NAME) == 0))
6908 || (bgp->name && (strcmp(import_name, bgp->name) == 0))) {
6909 vty_out(vty, "%% Cannot %s vrf %s into itself\n",
6910 remove ? "unimport" : "import", import_name);
6911 return CMD_WARNING;
6912 }
6913
6914 bgp_default = bgp_get_default();
6915 if (!bgp_default) {
6916 /* Auto-create assuming the same AS */
6917 ret = bgp_get(&bgp_default, &as, NULL,
6918 BGP_INSTANCE_TYPE_DEFAULT);
6919
6920 if (ret) {
6921 vty_out(vty,
6922 "VRF default is not configured as a bgp instance\n");
6923 return CMD_WARNING;
6924 }
6925 }
6926
6927 vrf_bgp = bgp_lookup_by_name(import_name);
6928 if (!vrf_bgp) {
6929 if (strcmp(import_name, VRF_DEFAULT_NAME) == 0)
6930 vrf_bgp = bgp_default;
6931 else
6932 /* Auto-create assuming the same AS */
6933 ret = bgp_get(&vrf_bgp, &as, import_name, bgp_type);
6934
6935 if (ret) {
6936 vty_out(vty,
6937 "VRF %s is not configured as a bgp instance\n",
6938 import_name);
6939 return CMD_WARNING;
6940 }
6941 }
6942
6943 if (remove) {
6944 vrf_unimport_from_vrf(bgp, vrf_bgp, afi, safi);
6945 } else {
6946 /* Already importing from "import_vrf"? */
6947 for (ALL_LIST_ELEMENTS_RO(bgp->vpn_policy[afi].import_vrf, node,
6948 vname)) {
6949 if (strcmp(vname, import_name) == 0)
6950 return CMD_WARNING;
6951 }
6952
6953 vrf_import_from_vrf(bgp, vrf_bgp, afi, safi);
6954 }
6955
6956 return CMD_SUCCESS;
6957 }
6958
6959 /* This command is valid only in a bgp vrf instance or the default instance */
6960 DEFPY (bgp_imexport_vpn,
6961 bgp_imexport_vpn_cmd,
6962 "[no] <import|export>$direction_str vpn",
6963 NO_STR
6964 "Import routes to this address-family\n"
6965 "Export routes from this address-family\n"
6966 "to/from default instance VPN RIB\n")
6967 {
6968 VTY_DECLVAR_CONTEXT(bgp, bgp);
6969 int previous_state;
6970 afi_t afi;
6971 safi_t safi;
6972 int idx = 0;
6973 int yes = 1;
6974 int flag;
6975 vpn_policy_direction_t dir;
6976
6977 if (argv_find(argv, argc, "no", &idx))
6978 yes = 0;
6979
6980 if (BGP_INSTANCE_TYPE_VRF != bgp->inst_type &&
6981 BGP_INSTANCE_TYPE_DEFAULT != bgp->inst_type) {
6982
6983 vty_out(vty, "%% import|export vpn valid only for bgp vrf or default instance\n");
6984 return CMD_WARNING_CONFIG_FAILED;
6985 }
6986
6987 afi = bgp_node_afi(vty);
6988 safi = bgp_node_safi(vty);
6989 if ((SAFI_UNICAST != safi) || ((AFI_IP != afi) && (AFI_IP6 != afi))) {
6990 vty_out(vty, "%% import|export vpn valid only for unicast ipv4|ipv6\n");
6991 return CMD_WARNING_CONFIG_FAILED;
6992 }
6993
6994 if (!strcmp(direction_str, "import")) {
6995 flag = BGP_CONFIG_MPLSVPN_TO_VRF_IMPORT;
6996 dir = BGP_VPN_POLICY_DIR_FROMVPN;
6997 } else if (!strcmp(direction_str, "export")) {
6998 flag = BGP_CONFIG_VRF_TO_MPLSVPN_EXPORT;
6999 dir = BGP_VPN_POLICY_DIR_TOVPN;
7000 } else {
7001 vty_out(vty, "%% unknown direction %s\n", direction_str);
7002 return CMD_WARNING_CONFIG_FAILED;
7003 }
7004
7005 previous_state = CHECK_FLAG(bgp->af_flags[afi][safi], flag);
7006
7007 if (yes) {
7008 SET_FLAG(bgp->af_flags[afi][safi], flag);
7009 if (!previous_state) {
7010 /* trigger export current vrf */
7011 vpn_leak_postchange(dir, afi, bgp_get_default(), bgp);
7012 }
7013 } else {
7014 if (previous_state) {
7015 /* trigger un-export current vrf */
7016 vpn_leak_prechange(dir, afi, bgp_get_default(), bgp);
7017 }
7018 UNSET_FLAG(bgp->af_flags[afi][safi], flag);
7019 }
7020
7021 return CMD_SUCCESS;
7022 }
7023
7024 DEFPY (af_routetarget_import,
7025 af_routetarget_import_cmd,
7026 "[no] <rt|route-target> redirect import RTLIST...",
7027 NO_STR
7028 "Specify route target list\n"
7029 "Specify route target list\n"
7030 "Flow-spec redirect type route target\n"
7031 "Import routes to this address-family\n"
7032 "Space separated route target list (A.B.C.D:MN|EF:OPQR|GHJK:MN)\n")
7033 {
7034 VTY_DECLVAR_CONTEXT(bgp, bgp);
7035 int ret;
7036 struct ecommunity *ecom = NULL;
7037 afi_t afi;
7038 int idx = 0;
7039 int yes = 1;
7040
7041 if (argv_find(argv, argc, "no", &idx))
7042 yes = 0;
7043
7044 afi = vpn_policy_getafi(vty, bgp, false);
7045 if (afi == AFI_MAX)
7046 return CMD_WARNING_CONFIG_FAILED;
7047
7048 if (yes) {
7049 if (!argv_find(argv, argc, "RTLIST", &idx)) {
7050 vty_out(vty, "%% Missing RTLIST\n");
7051 return CMD_WARNING_CONFIG_FAILED;
7052 }
7053 ret = set_ecom_list(vty, argc - idx, argv + idx, &ecom);
7054 if (ret != CMD_SUCCESS)
7055 return ret;
7056 }
7057
7058 if (yes) {
7059 if (bgp->vpn_policy[afi].import_redirect_rtlist)
7060 ecommunity_free(&bgp->vpn_policy[afi]
7061 .import_redirect_rtlist);
7062 bgp->vpn_policy[afi].import_redirect_rtlist =
7063 ecommunity_dup(ecom);
7064 } else {
7065 if (bgp->vpn_policy[afi].import_redirect_rtlist)
7066 ecommunity_free(&bgp->vpn_policy[afi]
7067 .import_redirect_rtlist);
7068 bgp->vpn_policy[afi].import_redirect_rtlist = NULL;
7069 }
7070
7071 if (ecom)
7072 ecommunity_free(&ecom);
7073
7074 return CMD_SUCCESS;
7075 }
7076
7077 DEFUN_NOSH (address_family_ipv4_safi,
7078 address_family_ipv4_safi_cmd,
7079 "address-family ipv4 [<unicast|multicast|vpn|labeled-unicast|flowspec>]",
7080 "Enter Address Family command mode\n"
7081 "Address Family\n"
7082 BGP_SAFI_WITH_LABEL_HELP_STR)
7083 {
7084
7085 if (argc == 3) {
7086 VTY_DECLVAR_CONTEXT(bgp, bgp);
7087 safi_t safi = bgp_vty_safi_from_str(argv[2]->text);
7088 if (bgp->inst_type != BGP_INSTANCE_TYPE_DEFAULT
7089 && safi != SAFI_UNICAST && safi != SAFI_MULTICAST
7090 && safi != SAFI_EVPN) {
7091 vty_out(vty,
7092 "Only Unicast/Multicast/EVPN SAFIs supported in non-core instances.\n");
7093 return CMD_WARNING_CONFIG_FAILED;
7094 }
7095 vty->node = bgp_node_type(AFI_IP, safi);
7096 } else
7097 vty->node = BGP_IPV4_NODE;
7098
7099 return CMD_SUCCESS;
7100 }
7101
7102 DEFUN_NOSH (address_family_ipv6_safi,
7103 address_family_ipv6_safi_cmd,
7104 "address-family ipv6 [<unicast|multicast|vpn|labeled-unicast|flowspec>]",
7105 "Enter Address Family command mode\n"
7106 "Address Family\n"
7107 BGP_SAFI_WITH_LABEL_HELP_STR)
7108 {
7109 if (argc == 3) {
7110 VTY_DECLVAR_CONTEXT(bgp, bgp);
7111 safi_t safi = bgp_vty_safi_from_str(argv[2]->text);
7112 if (bgp->inst_type != BGP_INSTANCE_TYPE_DEFAULT
7113 && safi != SAFI_UNICAST && safi != SAFI_MULTICAST
7114 && safi != SAFI_EVPN) {
7115 vty_out(vty,
7116 "Only Unicast/Multicast/EVPN SAFIs supported in non-core instances.\n");
7117 return CMD_WARNING_CONFIG_FAILED;
7118 }
7119 vty->node = bgp_node_type(AFI_IP6, safi);
7120 } else
7121 vty->node = BGP_IPV6_NODE;
7122
7123 return CMD_SUCCESS;
7124 }
7125
7126 #ifdef KEEP_OLD_VPN_COMMANDS
7127 DEFUN_NOSH (address_family_vpnv4,
7128 address_family_vpnv4_cmd,
7129 "address-family vpnv4 [unicast]",
7130 "Enter Address Family command mode\n"
7131 "Address Family\n"
7132 "Address Family modifier\n")
7133 {
7134 vty->node = BGP_VPNV4_NODE;
7135 return CMD_SUCCESS;
7136 }
7137
7138 DEFUN_NOSH (address_family_vpnv6,
7139 address_family_vpnv6_cmd,
7140 "address-family vpnv6 [unicast]",
7141 "Enter Address Family command mode\n"
7142 "Address Family\n"
7143 "Address Family modifier\n")
7144 {
7145 vty->node = BGP_VPNV6_NODE;
7146 return CMD_SUCCESS;
7147 }
7148 #endif /* KEEP_OLD_VPN_COMMANDS */
7149
7150 DEFUN_NOSH (address_family_evpn,
7151 address_family_evpn_cmd,
7152 "address-family l2vpn evpn",
7153 "Enter Address Family command mode\n"
7154 "Address Family\n"
7155 "Address Family modifier\n")
7156 {
7157 VTY_DECLVAR_CONTEXT(bgp, bgp);
7158 vty->node = BGP_EVPN_NODE;
7159 return CMD_SUCCESS;
7160 }
7161
7162 DEFUN_NOSH (exit_address_family,
7163 exit_address_family_cmd,
7164 "exit-address-family",
7165 "Exit from Address Family configuration mode\n")
7166 {
7167 if (vty->node == BGP_IPV4_NODE || vty->node == BGP_IPV4M_NODE
7168 || vty->node == BGP_IPV4L_NODE || vty->node == BGP_VPNV4_NODE
7169 || vty->node == BGP_IPV6_NODE || vty->node == BGP_IPV6M_NODE
7170 || vty->node == BGP_IPV6L_NODE || vty->node == BGP_VPNV6_NODE
7171 || vty->node == BGP_EVPN_NODE
7172 || vty->node == BGP_FLOWSPECV4_NODE
7173 || vty->node == BGP_FLOWSPECV6_NODE)
7174 vty->node = BGP_NODE;
7175 return CMD_SUCCESS;
7176 }
7177
7178 /* Recalculate bestpath and re-advertise a prefix */
7179 static int bgp_clear_prefix(struct vty *vty, const char *view_name,
7180 const char *ip_str, afi_t afi, safi_t safi,
7181 struct prefix_rd *prd)
7182 {
7183 int ret;
7184 struct prefix match;
7185 struct bgp_node *rn;
7186 struct bgp_node *rm;
7187 struct bgp *bgp;
7188 struct bgp_table *table;
7189 struct bgp_table *rib;
7190
7191 /* BGP structure lookup. */
7192 if (view_name) {
7193 bgp = bgp_lookup_by_name(view_name);
7194 if (bgp == NULL) {
7195 vty_out(vty, "%% Can't find BGP instance %s\n",
7196 view_name);
7197 return CMD_WARNING;
7198 }
7199 } else {
7200 bgp = bgp_get_default();
7201 if (bgp == NULL) {
7202 vty_out(vty, "%% No BGP process is configured\n");
7203 return CMD_WARNING;
7204 }
7205 }
7206
7207 /* Check IP address argument. */
7208 ret = str2prefix(ip_str, &match);
7209 if (!ret) {
7210 vty_out(vty, "%% address is malformed\n");
7211 return CMD_WARNING;
7212 }
7213
7214 match.family = afi2family(afi);
7215 rib = bgp->rib[afi][safi];
7216
7217 if (safi == SAFI_MPLS_VPN) {
7218 for (rn = bgp_table_top(rib); rn; rn = bgp_route_next(rn)) {
7219 if (prd && memcmp(rn->p.u.val, prd->val, 8) != 0)
7220 continue;
7221
7222 table = bgp_node_get_bgp_table_info(rn);
7223 if (table != NULL) {
7224
7225 if ((rm = bgp_node_match(table, &match))
7226 != NULL) {
7227 if (rm->p.prefixlen
7228 == match.prefixlen) {
7229 SET_FLAG(rm->flags,
7230 BGP_NODE_USER_CLEAR);
7231 bgp_process(bgp, rm, afi, safi);
7232 }
7233 bgp_unlock_node(rm);
7234 }
7235 }
7236 }
7237 } else {
7238 if ((rn = bgp_node_match(rib, &match)) != NULL) {
7239 if (rn->p.prefixlen == match.prefixlen) {
7240 SET_FLAG(rn->flags, BGP_NODE_USER_CLEAR);
7241 bgp_process(bgp, rn, afi, safi);
7242 }
7243 bgp_unlock_node(rn);
7244 }
7245 }
7246
7247 return CMD_SUCCESS;
7248 }
7249
7250 /* one clear bgp command to rule them all */
7251 DEFUN (clear_ip_bgp_all,
7252 clear_ip_bgp_all_cmd,
7253 "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>]",
7254 CLEAR_STR
7255 IP_STR
7256 BGP_STR
7257 BGP_INSTANCE_HELP_STR
7258 BGP_AFI_HELP_STR
7259 "Address Family\n"
7260 BGP_SAFI_WITH_LABEL_HELP_STR
7261 "Address Family modifier\n"
7262 "Clear all peers\n"
7263 "BGP neighbor address to clear\n"
7264 "BGP IPv6 neighbor to clear\n"
7265 "BGP neighbor on interface to clear\n"
7266 "Clear peers with the AS number\n"
7267 "Clear all external peers\n"
7268 "Clear all members of peer-group\n"
7269 "BGP peer-group name\n"
7270 BGP_SOFT_STR
7271 BGP_SOFT_IN_STR
7272 BGP_SOFT_OUT_STR
7273 BGP_SOFT_IN_STR
7274 "Push out prefix-list ORF and do inbound soft reconfig\n"
7275 BGP_SOFT_OUT_STR)
7276 {
7277 char *vrf = NULL;
7278
7279 afi_t afi = AFI_IP6;
7280 safi_t safi = SAFI_UNICAST;
7281 enum clear_sort clr_sort = clear_peer;
7282 enum bgp_clear_type clr_type;
7283 char *clr_arg = NULL;
7284
7285 int idx = 0;
7286
7287 /* clear [ip] bgp */
7288 if (argv_find(argv, argc, "ip", &idx))
7289 afi = AFI_IP;
7290
7291 /* [<vrf> VIEWVRFNAME] */
7292 if (argv_find(argv, argc, "vrf", &idx)) {
7293 vrf = argv[idx + 1]->arg;
7294 idx += 2;
7295 if (vrf && strmatch(vrf, VRF_DEFAULT_NAME))
7296 vrf = NULL;
7297 } else if (argv_find(argv, argc, "view", &idx)) {
7298 /* [<view> VIEWVRFNAME] */
7299 vrf = argv[idx + 1]->arg;
7300 idx += 2;
7301 }
7302 /* ["BGP_AFI_CMD_STR" ["BGP_SAFI_CMD_STR"]] */
7303 if (argv_find_and_parse_afi(argv, argc, &idx, &afi))
7304 argv_find_and_parse_safi(argv, argc, &idx, &safi);
7305
7306 /* <*|A.B.C.D|X:X::X:X|WORD|(1-4294967295)|external|peer-group WORD> */
7307 if (argv_find(argv, argc, "*", &idx)) {
7308 clr_sort = clear_all;
7309 } else if (argv_find(argv, argc, "A.B.C.D", &idx)) {
7310 clr_sort = clear_peer;
7311 clr_arg = argv[idx]->arg;
7312 } else if (argv_find(argv, argc, "X:X::X:X", &idx)) {
7313 clr_sort = clear_peer;
7314 clr_arg = argv[idx]->arg;
7315 } else if (argv_find(argv, argc, "peer-group", &idx)) {
7316 clr_sort = clear_group;
7317 idx++;
7318 clr_arg = argv[idx]->arg;
7319 } else if (argv_find(argv, argc, "WORD", &idx)) {
7320 clr_sort = clear_peer;
7321 clr_arg = argv[idx]->arg;
7322 } else if (argv_find(argv, argc, "(1-4294967295)", &idx)) {
7323 clr_sort = clear_as;
7324 clr_arg = argv[idx]->arg;
7325 } else if (argv_find(argv, argc, "external", &idx)) {
7326 clr_sort = clear_external;
7327 }
7328
7329 /* [<soft [<in|out>]|in [prefix-filter]|out>] */
7330 if (argv_find(argv, argc, "soft", &idx)) {
7331 if (argv_find(argv, argc, "in", &idx)
7332 || argv_find(argv, argc, "out", &idx))
7333 clr_type = strmatch(argv[idx]->text, "in")
7334 ? BGP_CLEAR_SOFT_IN
7335 : BGP_CLEAR_SOFT_OUT;
7336 else
7337 clr_type = BGP_CLEAR_SOFT_BOTH;
7338 } else if (argv_find(argv, argc, "in", &idx)) {
7339 clr_type = argv_find(argv, argc, "prefix-filter", &idx)
7340 ? BGP_CLEAR_SOFT_IN_ORF_PREFIX
7341 : BGP_CLEAR_SOFT_IN;
7342 } else if (argv_find(argv, argc, "out", &idx)) {
7343 clr_type = BGP_CLEAR_SOFT_OUT;
7344 } else
7345 clr_type = BGP_CLEAR_SOFT_NONE;
7346
7347 return bgp_clear_vty(vty, vrf, afi, safi, clr_sort, clr_type, clr_arg);
7348 }
7349
7350 DEFUN (clear_ip_bgp_prefix,
7351 clear_ip_bgp_prefix_cmd,
7352 "clear [ip] bgp [<view|vrf> VIEWVRFNAME] prefix A.B.C.D/M",
7353 CLEAR_STR
7354 IP_STR
7355 BGP_STR
7356 BGP_INSTANCE_HELP_STR
7357 "Clear bestpath and re-advertise\n"
7358 "IPv4 prefix\n")
7359 {
7360 char *vrf = NULL;
7361 char *prefix = NULL;
7362
7363 int idx = 0;
7364
7365 /* [<view|vrf> VIEWVRFNAME] */
7366 if (argv_find(argv, argc, "vrf", &idx)) {
7367 vrf = argv[idx + 1]->arg;
7368 idx += 2;
7369 if (vrf && strmatch(vrf, VRF_DEFAULT_NAME))
7370 vrf = NULL;
7371 } else if (argv_find(argv, argc, "view", &idx)) {
7372 /* [<view> VIEWVRFNAME] */
7373 vrf = argv[idx + 1]->arg;
7374 idx += 2;
7375 }
7376
7377 prefix = argv[argc - 1]->arg;
7378
7379 return bgp_clear_prefix(vty, vrf, prefix, AFI_IP, SAFI_UNICAST, NULL);
7380 }
7381
7382 DEFUN (clear_bgp_ipv6_safi_prefix,
7383 clear_bgp_ipv6_safi_prefix_cmd,
7384 "clear [ip] bgp ipv6 "BGP_SAFI_CMD_STR" prefix X:X::X:X/M",
7385 CLEAR_STR
7386 IP_STR
7387 BGP_STR
7388 "Address Family\n"
7389 BGP_SAFI_HELP_STR
7390 "Clear bestpath and re-advertise\n"
7391 "IPv6 prefix\n")
7392 {
7393 int idx_safi = 0;
7394 int idx_ipv6_prefix = 0;
7395 safi_t safi = SAFI_UNICAST;
7396 char *prefix = argv_find(argv, argc, "X:X::X:X/M", &idx_ipv6_prefix) ?
7397 argv[idx_ipv6_prefix]->arg : NULL;
7398
7399 argv_find_and_parse_safi(argv, argc, &idx_safi, &safi);
7400 return bgp_clear_prefix(
7401 vty, NULL, prefix, AFI_IP6,
7402 safi, NULL);
7403 }
7404
7405 DEFUN (clear_bgp_instance_ipv6_safi_prefix,
7406 clear_bgp_instance_ipv6_safi_prefix_cmd,
7407 "clear [ip] bgp <view|vrf> VIEWVRFNAME ipv6 "BGP_SAFI_CMD_STR" prefix X:X::X:X/M",
7408 CLEAR_STR
7409 IP_STR
7410 BGP_STR
7411 BGP_INSTANCE_HELP_STR
7412 "Address Family\n"
7413 BGP_SAFI_HELP_STR
7414 "Clear bestpath and re-advertise\n"
7415 "IPv6 prefix\n")
7416 {
7417 int idx_safi = 0;
7418 int idx_vrfview = 0;
7419 int idx_ipv6_prefix = 0;
7420 safi_t safi = SAFI_UNICAST;
7421 char *prefix = argv_find(argv, argc, "X:X::X:X/M", &idx_ipv6_prefix) ?
7422 argv[idx_ipv6_prefix]->arg : NULL;
7423 char *vrfview = NULL;
7424
7425 /* [<view|vrf> VIEWVRFNAME] */
7426 if (argv_find(argv, argc, "vrf", &idx_vrfview)) {
7427 vrfview = argv[idx_vrfview + 1]->arg;
7428 if (vrfview && strmatch(vrfview, VRF_DEFAULT_NAME))
7429 vrfview = NULL;
7430 } else if (argv_find(argv, argc, "view", &idx_vrfview)) {
7431 /* [<view> VIEWVRFNAME] */
7432 vrfview = argv[idx_vrfview + 1]->arg;
7433 }
7434 argv_find_and_parse_safi(argv, argc, &idx_safi, &safi);
7435
7436 return bgp_clear_prefix(
7437 vty, vrfview, prefix,
7438 AFI_IP6, safi, NULL);
7439 }
7440
7441 DEFUN (show_bgp_views,
7442 show_bgp_views_cmd,
7443 "show [ip] bgp views",
7444 SHOW_STR
7445 IP_STR
7446 BGP_STR
7447 "Show the defined BGP views\n")
7448 {
7449 struct list *inst = bm->bgp;
7450 struct listnode *node;
7451 struct bgp *bgp;
7452
7453 if (!bgp_option_check(BGP_OPT_MULTIPLE_INSTANCE)) {
7454 vty_out(vty, "BGP Multiple Instance is not enabled\n");
7455 return CMD_WARNING;
7456 }
7457
7458 vty_out(vty, "Defined BGP views:\n");
7459 for (ALL_LIST_ELEMENTS_RO(inst, node, bgp)) {
7460 /* Skip VRFs. */
7461 if (bgp->inst_type == BGP_INSTANCE_TYPE_VRF)
7462 continue;
7463 vty_out(vty, "\t%s (AS%u)\n", bgp->name ? bgp->name : "(null)",
7464 bgp->as);
7465 }
7466
7467 return CMD_SUCCESS;
7468 }
7469
7470 DEFUN (show_bgp_vrfs,
7471 show_bgp_vrfs_cmd,
7472 "show [ip] bgp vrfs [json]",
7473 SHOW_STR
7474 IP_STR
7475 BGP_STR
7476 "Show BGP VRFs\n"
7477 JSON_STR)
7478 {
7479 char buf[ETHER_ADDR_STRLEN];
7480 struct list *inst = bm->bgp;
7481 struct listnode *node;
7482 struct bgp *bgp;
7483 bool uj = use_json(argc, argv);
7484 json_object *json = NULL;
7485 json_object *json_vrfs = NULL;
7486 int count = 0;
7487
7488 if (!bgp_option_check(BGP_OPT_MULTIPLE_INSTANCE)) {
7489 vty_out(vty, "BGP Multiple Instance is not enabled\n");
7490 return CMD_WARNING;
7491 }
7492
7493 if (uj) {
7494 json = json_object_new_object();
7495 json_vrfs = json_object_new_object();
7496 }
7497
7498 for (ALL_LIST_ELEMENTS_RO(inst, node, bgp)) {
7499 const char *name, *type;
7500 struct peer *peer;
7501 struct listnode *node2, *nnode2;
7502 int peers_cfg, peers_estb;
7503 json_object *json_vrf = NULL;
7504
7505 /* Skip Views. */
7506 if (bgp->inst_type == BGP_INSTANCE_TYPE_VIEW)
7507 continue;
7508
7509 count++;
7510 if (!uj && count == 1)
7511 vty_out(vty,
7512 "%4s %-5s %-16s %9s %10s %-37s %-10s %-15s\n",
7513 "Type", "Id", "routerId", "#PeersVfg",
7514 "#PeersEstb", "Name", "L3-VNI", "Rmac");
7515
7516 peers_cfg = peers_estb = 0;
7517 if (uj)
7518 json_vrf = json_object_new_object();
7519
7520
7521 for (ALL_LIST_ELEMENTS(bgp->peer, node2, nnode2, peer)) {
7522 if (!CHECK_FLAG(peer->flags, PEER_FLAG_CONFIG_NODE))
7523 continue;
7524 peers_cfg++;
7525 if (peer->status == Established)
7526 peers_estb++;
7527 }
7528
7529 if (bgp->inst_type == BGP_INSTANCE_TYPE_DEFAULT) {
7530 name = VRF_DEFAULT_NAME;
7531 type = "DFLT";
7532 } else {
7533 name = bgp->name;
7534 type = "VRF";
7535 }
7536
7537
7538 if (uj) {
7539 int64_t vrf_id_ui = (bgp->vrf_id == VRF_UNKNOWN)
7540 ? -1
7541 : (int64_t)bgp->vrf_id;
7542 json_object_string_add(json_vrf, "type", type);
7543 json_object_int_add(json_vrf, "vrfId", vrf_id_ui);
7544 json_object_string_add(json_vrf, "routerId",
7545 inet_ntoa(bgp->router_id));
7546 json_object_int_add(json_vrf, "numConfiguredPeers",
7547 peers_cfg);
7548 json_object_int_add(json_vrf, "numEstablishedPeers",
7549 peers_estb);
7550
7551 json_object_int_add(json_vrf, "l3vni", bgp->l3vni);
7552 json_object_string_add(
7553 json_vrf, "rmac",
7554 prefix_mac2str(&bgp->rmac, buf, sizeof(buf)));
7555 json_object_object_add(json_vrfs, name, json_vrf);
7556 } else
7557 vty_out(vty,
7558 "%4s %-5d %-16s %9u %10u %-37s %-10u %-15s\n",
7559 type,
7560 bgp->vrf_id == VRF_UNKNOWN ? -1
7561 : (int)bgp->vrf_id,
7562 inet_ntoa(bgp->router_id), peers_cfg,
7563 peers_estb, name, bgp->l3vni,
7564 prefix_mac2str(&bgp->rmac, buf, sizeof(buf)));
7565 }
7566
7567 if (uj) {
7568 json_object_object_add(json, "vrfs", json_vrfs);
7569
7570 json_object_int_add(json, "totalVrfs", count);
7571
7572 vty_out(vty, "%s\n", json_object_to_json_string_ext(
7573 json, JSON_C_TO_STRING_PRETTY));
7574 json_object_free(json);
7575 } else {
7576 if (count)
7577 vty_out(vty,
7578 "\nTotal number of VRFs (including default): %d\n",
7579 count);
7580 }
7581
7582 return CMD_SUCCESS;
7583 }
7584
7585 DEFUN (show_bgp_mac_hash,
7586 show_bgp_mac_hash_cmd,
7587 "show bgp mac hash",
7588 SHOW_STR
7589 BGP_STR
7590 "Mac Address\n"
7591 "Mac Address database\n")
7592 {
7593 bgp_mac_dump_table(vty);
7594
7595 return CMD_SUCCESS;
7596 }
7597
7598 static void show_tip_entry(struct hash_bucket *bucket, void *args)
7599 {
7600 struct vty *vty = (struct vty *)args;
7601 struct tip_addr *tip = (struct tip_addr *)bucket->data;
7602
7603 vty_out(vty, "addr: %s, count: %d\n", inet_ntoa(tip->addr),
7604 tip->refcnt);
7605 }
7606
7607 static void bgp_show_martian_nexthops(struct vty *vty, struct bgp *bgp)
7608 {
7609 vty_out(vty, "self nexthop database:\n");
7610 bgp_nexthop_show_address_hash(vty, bgp);
7611
7612 vty_out(vty, "Tunnel-ip database:\n");
7613 hash_iterate(bgp->tip_hash,
7614 (void (*)(struct hash_bucket *, void *))show_tip_entry,
7615 vty);
7616 }
7617
7618 DEFUN(show_bgp_martian_nexthop_db, show_bgp_martian_nexthop_db_cmd,
7619 "show bgp [<view|vrf> VIEWVRFNAME] martian next-hop",
7620 SHOW_STR BGP_STR BGP_INSTANCE_HELP_STR
7621 "martian next-hops\n"
7622 "martian next-hop database\n")
7623 {
7624 struct bgp *bgp = NULL;
7625 int idx = 0;
7626 char *name = NULL;
7627
7628 /* [<vrf> VIEWVRFNAME] */
7629 if (argv_find(argv, argc, "vrf", &idx)) {
7630 name = argv[idx + 1]->arg;
7631 if (name && strmatch(name, VRF_DEFAULT_NAME))
7632 name = NULL;
7633 } else if (argv_find(argv, argc, "view", &idx))
7634 /* [<view> VIEWVRFNAME] */
7635 name = argv[idx + 1]->arg;
7636 if (name)
7637 bgp = bgp_lookup_by_name(name);
7638 else
7639 bgp = bgp_get_default();
7640
7641 if (!bgp) {
7642 vty_out(vty, "%% No BGP process is configured\n");
7643 return CMD_WARNING;
7644 }
7645 bgp_show_martian_nexthops(vty, bgp);
7646
7647 return CMD_SUCCESS;
7648 }
7649
7650 DEFUN (show_bgp_memory,
7651 show_bgp_memory_cmd,
7652 "show [ip] bgp memory",
7653 SHOW_STR
7654 IP_STR
7655 BGP_STR
7656 "Global BGP memory statistics\n")
7657 {
7658 char memstrbuf[MTYPE_MEMSTR_LEN];
7659 unsigned long count;
7660
7661 /* RIB related usage stats */
7662 count = mtype_stats_alloc(MTYPE_BGP_NODE);
7663 vty_out(vty, "%ld RIB nodes, using %s of memory\n", count,
7664 mtype_memstr(memstrbuf, sizeof(memstrbuf),
7665 count * sizeof(struct bgp_node)));
7666
7667 count = mtype_stats_alloc(MTYPE_BGP_ROUTE);
7668 vty_out(vty, "%ld BGP routes, using %s of memory\n", count,
7669 mtype_memstr(memstrbuf, sizeof(memstrbuf),
7670 count * sizeof(struct bgp_path_info)));
7671 if ((count = mtype_stats_alloc(MTYPE_BGP_ROUTE_EXTRA)))
7672 vty_out(vty, "%ld BGP route ancillaries, using %s of memory\n",
7673 count,
7674 mtype_memstr(
7675 memstrbuf, sizeof(memstrbuf),
7676 count * sizeof(struct bgp_path_info_extra)));
7677
7678 if ((count = mtype_stats_alloc(MTYPE_BGP_STATIC)))
7679 vty_out(vty, "%ld Static routes, using %s of memory\n", count,
7680 mtype_memstr(memstrbuf, sizeof(memstrbuf),
7681 count * sizeof(struct bgp_static)));
7682
7683 if ((count = mtype_stats_alloc(MTYPE_BGP_PACKET)))
7684 vty_out(vty, "%ld Packets, using %s of memory\n", count,
7685 mtype_memstr(memstrbuf, sizeof(memstrbuf),
7686 count * sizeof(struct bpacket)));
7687
7688 /* Adj-In/Out */
7689 if ((count = mtype_stats_alloc(MTYPE_BGP_ADJ_IN)))
7690 vty_out(vty, "%ld Adj-In entries, using %s of memory\n", count,
7691 mtype_memstr(memstrbuf, sizeof(memstrbuf),
7692 count * sizeof(struct bgp_adj_in)));
7693 if ((count = mtype_stats_alloc(MTYPE_BGP_ADJ_OUT)))
7694 vty_out(vty, "%ld Adj-Out entries, using %s of memory\n", count,
7695 mtype_memstr(memstrbuf, sizeof(memstrbuf),
7696 count * sizeof(struct bgp_adj_out)));
7697
7698 if ((count = mtype_stats_alloc(MTYPE_BGP_NEXTHOP_CACHE)))
7699 vty_out(vty, "%ld Nexthop cache entries, using %s of memory\n",
7700 count,
7701 mtype_memstr(memstrbuf, sizeof(memstrbuf),
7702 count * sizeof(struct bgp_nexthop_cache)));
7703
7704 if ((count = mtype_stats_alloc(MTYPE_BGP_DAMP_INFO)))
7705 vty_out(vty, "%ld Dampening entries, using %s of memory\n",
7706 count,
7707 mtype_memstr(memstrbuf, sizeof(memstrbuf),
7708 count * sizeof(struct bgp_damp_info)));
7709
7710 /* Attributes */
7711 count = attr_count();
7712 vty_out(vty, "%ld BGP attributes, using %s of memory\n", count,
7713 mtype_memstr(memstrbuf, sizeof(memstrbuf),
7714 count * sizeof(struct attr)));
7715
7716 if ((count = attr_unknown_count()))
7717 vty_out(vty, "%ld unknown attributes\n", count);
7718
7719 /* AS_PATH attributes */
7720 count = aspath_count();
7721 vty_out(vty, "%ld BGP AS-PATH entries, using %s of memory\n", count,
7722 mtype_memstr(memstrbuf, sizeof(memstrbuf),
7723 count * sizeof(struct aspath)));
7724
7725 count = mtype_stats_alloc(MTYPE_AS_SEG);
7726 vty_out(vty, "%ld BGP AS-PATH segments, using %s of memory\n", count,
7727 mtype_memstr(memstrbuf, sizeof(memstrbuf),
7728 count * sizeof(struct assegment)));
7729
7730 /* Other attributes */
7731 if ((count = community_count()))
7732 vty_out(vty, "%ld BGP community entries, using %s of memory\n",
7733 count, mtype_memstr(memstrbuf, sizeof(memstrbuf),
7734 count * sizeof(struct community)));
7735 if ((count = mtype_stats_alloc(MTYPE_ECOMMUNITY)))
7736 vty_out(vty, "%ld BGP community entries, using %s of memory\n",
7737 count, mtype_memstr(memstrbuf, sizeof(memstrbuf),
7738 count * sizeof(struct ecommunity)));
7739 if ((count = mtype_stats_alloc(MTYPE_LCOMMUNITY)))
7740 vty_out(vty,
7741 "%ld BGP large-community entries, using %s of memory\n",
7742 count, mtype_memstr(memstrbuf, sizeof(memstrbuf),
7743 count * sizeof(struct lcommunity)));
7744
7745 if ((count = mtype_stats_alloc(MTYPE_CLUSTER)))
7746 vty_out(vty, "%ld Cluster lists, using %s of memory\n", count,
7747 mtype_memstr(memstrbuf, sizeof(memstrbuf),
7748 count * sizeof(struct cluster_list)));
7749
7750 /* Peer related usage */
7751 count = mtype_stats_alloc(MTYPE_BGP_PEER);
7752 vty_out(vty, "%ld peers, using %s of memory\n", count,
7753 mtype_memstr(memstrbuf, sizeof(memstrbuf),
7754 count * sizeof(struct peer)));
7755
7756 if ((count = mtype_stats_alloc(MTYPE_PEER_GROUP)))
7757 vty_out(vty, "%ld peer groups, using %s of memory\n", count,
7758 mtype_memstr(memstrbuf, sizeof(memstrbuf),
7759 count * sizeof(struct peer_group)));
7760
7761 /* Other */
7762 if ((count = mtype_stats_alloc(MTYPE_HASH)))
7763 vty_out(vty, "%ld hash tables, using %s of memory\n", count,
7764 mtype_memstr(memstrbuf, sizeof(memstrbuf),
7765 count * sizeof(struct hash)));
7766 if ((count = mtype_stats_alloc(MTYPE_HASH_BACKET)))
7767 vty_out(vty, "%ld hash buckets, using %s of memory\n", count,
7768 mtype_memstr(memstrbuf, sizeof(memstrbuf),
7769 count * sizeof(struct hash_bucket)));
7770 if ((count = mtype_stats_alloc(MTYPE_BGP_REGEXP)))
7771 vty_out(vty, "%ld compiled regexes, using %s of memory\n",
7772 count, mtype_memstr(memstrbuf, sizeof(memstrbuf),
7773 count * sizeof(regex_t)));
7774 return CMD_SUCCESS;
7775 }
7776
7777 static void bgp_show_bestpath_json(struct bgp *bgp, json_object *json)
7778 {
7779 json_object *bestpath = json_object_new_object();
7780
7781 if (bgp_flag_check(bgp, BGP_FLAG_ASPATH_IGNORE))
7782 json_object_string_add(bestpath, "asPath", "ignore");
7783
7784 if (bgp_flag_check(bgp, BGP_FLAG_ASPATH_CONFED))
7785 json_object_string_add(bestpath, "asPath", "confed");
7786
7787 if (bgp_flag_check(bgp, BGP_FLAG_ASPATH_MULTIPATH_RELAX)) {
7788 if (bgp_flag_check(bgp, BGP_FLAG_MULTIPATH_RELAX_AS_SET))
7789 json_object_string_add(bestpath, "multiPathRelax",
7790 "as-set");
7791 else
7792 json_object_string_add(bestpath, "multiPathRelax",
7793 "true");
7794 } else
7795 json_object_string_add(bestpath, "multiPathRelax", "false");
7796
7797 if (bgp_flag_check(bgp, BGP_FLAG_COMPARE_ROUTER_ID))
7798 json_object_string_add(bestpath, "compareRouterId", "true");
7799 if (bgp_flag_check(bgp, BGP_FLAG_MED_CONFED)
7800 || bgp_flag_check(bgp, BGP_FLAG_MED_MISSING_AS_WORST)) {
7801 if (bgp_flag_check(bgp, BGP_FLAG_MED_CONFED))
7802 json_object_string_add(bestpath, "med", "confed");
7803 if (bgp_flag_check(bgp, BGP_FLAG_MED_MISSING_AS_WORST))
7804 json_object_string_add(bestpath, "med",
7805 "missing-as-worst");
7806 else
7807 json_object_string_add(bestpath, "med", "true");
7808 }
7809
7810 json_object_object_add(json, "bestPath", bestpath);
7811 }
7812
7813 /* Show BGP peer's summary information. */
7814 static int bgp_show_summary(struct vty *vty, struct bgp *bgp, int afi, int safi,
7815 bool use_json, json_object *json)
7816 {
7817 struct peer *peer;
7818 struct listnode *node, *nnode;
7819 unsigned int count = 0, dn_count = 0;
7820 char timebuf[BGP_UPTIME_LEN], dn_flag[2];
7821 char neighbor_buf[VTY_BUFSIZ];
7822 int neighbor_col_default_width = 16;
7823 int len;
7824 int max_neighbor_width = 0;
7825 int pfx_rcd_safi;
7826 json_object *json_peer = NULL;
7827 json_object *json_peers = NULL;
7828 struct peer_af *paf;
7829
7830 /* labeled-unicast routes are installed in the unicast table so in order
7831 * to
7832 * display the correct PfxRcd value we must look at SAFI_UNICAST
7833 */
7834 if (safi == SAFI_LABELED_UNICAST)
7835 pfx_rcd_safi = SAFI_UNICAST;
7836 else
7837 pfx_rcd_safi = safi;
7838
7839 if (use_json) {
7840 if (json == NULL)
7841 json = json_object_new_object();
7842
7843 json_peers = json_object_new_object();
7844 } else {
7845 /* Loop over all neighbors that will be displayed to determine
7846 * how many
7847 * characters are needed for the Neighbor column
7848 */
7849 for (ALL_LIST_ELEMENTS(bgp->peer, node, nnode, peer)) {
7850 if (!CHECK_FLAG(peer->flags, PEER_FLAG_CONFIG_NODE))
7851 continue;
7852
7853 if (peer->afc[afi][safi]) {
7854 memset(dn_flag, '\0', sizeof(dn_flag));
7855 if (peer_dynamic_neighbor(peer))
7856 dn_flag[0] = '*';
7857
7858 if (peer->hostname
7859 && bgp_flag_check(bgp,
7860 BGP_FLAG_SHOW_HOSTNAME))
7861 sprintf(neighbor_buf, "%s%s(%s) ",
7862 dn_flag, peer->hostname,
7863 peer->host);
7864 else
7865 sprintf(neighbor_buf, "%s%s ", dn_flag,
7866 peer->host);
7867
7868 len = strlen(neighbor_buf);
7869
7870 if (len > max_neighbor_width)
7871 max_neighbor_width = len;
7872 }
7873 }
7874
7875 /* Originally we displayed the Neighbor column as 16
7876 * characters wide so make that the default
7877 */
7878 if (max_neighbor_width < neighbor_col_default_width)
7879 max_neighbor_width = neighbor_col_default_width;
7880 }
7881
7882 for (ALL_LIST_ELEMENTS(bgp->peer, node, nnode, peer)) {
7883 if (!CHECK_FLAG(peer->flags, PEER_FLAG_CONFIG_NODE))
7884 continue;
7885
7886 if (!peer->afc[afi][safi])
7887 continue;
7888
7889 if (!count) {
7890 unsigned long ents;
7891 char memstrbuf[MTYPE_MEMSTR_LEN];
7892 int64_t vrf_id_ui;
7893
7894 vrf_id_ui = (bgp->vrf_id == VRF_UNKNOWN)
7895 ? -1
7896 : (int64_t)bgp->vrf_id;
7897
7898 /* Usage summary and header */
7899 if (use_json) {
7900 json_object_string_add(
7901 json, "routerId",
7902 inet_ntoa(bgp->router_id));
7903 json_object_int_add(json, "as", bgp->as);
7904 json_object_int_add(json, "vrfId", vrf_id_ui);
7905 json_object_string_add(
7906 json, "vrfName",
7907 (bgp->inst_type
7908 == BGP_INSTANCE_TYPE_DEFAULT)
7909 ? VRF_DEFAULT_NAME
7910 : bgp->name);
7911 } else {
7912 vty_out(vty,
7913 "BGP router identifier %s, local AS number %u vrf-id %d",
7914 inet_ntoa(bgp->router_id), bgp->as,
7915 bgp->vrf_id == VRF_UNKNOWN
7916 ? -1
7917 : (int)bgp->vrf_id);
7918 vty_out(vty, "\n");
7919 }
7920
7921 if (bgp_update_delay_configured(bgp)) {
7922 if (use_json) {
7923 json_object_int_add(
7924 json, "updateDelayLimit",
7925 bgp->v_update_delay);
7926
7927 if (bgp->v_update_delay
7928 != bgp->v_establish_wait)
7929 json_object_int_add(
7930 json,
7931 "updateDelayEstablishWait",
7932 bgp->v_establish_wait);
7933
7934 if (bgp_update_delay_active(bgp)) {
7935 json_object_string_add(
7936 json,
7937 "updateDelayFirstNeighbor",
7938 bgp->update_delay_begin_time);
7939 json_object_boolean_true_add(
7940 json,
7941 "updateDelayInProgress");
7942 } else {
7943 if (bgp->update_delay_over) {
7944 json_object_string_add(
7945 json,
7946 "updateDelayFirstNeighbor",
7947 bgp->update_delay_begin_time);
7948 json_object_string_add(
7949 json,
7950 "updateDelayBestpathResumed",
7951 bgp->update_delay_end_time);
7952 json_object_string_add(
7953 json,
7954 "updateDelayZebraUpdateResume",
7955 bgp->update_delay_zebra_resume_time);
7956 json_object_string_add(
7957 json,
7958 "updateDelayPeerUpdateResume",
7959 bgp->update_delay_peers_resume_time);
7960 }
7961 }
7962 } else {
7963 vty_out(vty,
7964 "Read-only mode update-delay limit: %d seconds\n",
7965 bgp->v_update_delay);
7966 if (bgp->v_update_delay
7967 != bgp->v_establish_wait)
7968 vty_out(vty,
7969 " Establish wait: %d seconds\n",
7970 bgp->v_establish_wait);
7971
7972 if (bgp_update_delay_active(bgp)) {
7973 vty_out(vty,
7974 " First neighbor established: %s\n",
7975 bgp->update_delay_begin_time);
7976 vty_out(vty,
7977 " Delay in progress\n");
7978 } else {
7979 if (bgp->update_delay_over) {
7980 vty_out(vty,
7981 " First neighbor established: %s\n",
7982 bgp->update_delay_begin_time);
7983 vty_out(vty,
7984 " Best-paths resumed: %s\n",
7985 bgp->update_delay_end_time);
7986 vty_out(vty,
7987 " zebra update resumed: %s\n",
7988 bgp->update_delay_zebra_resume_time);
7989 vty_out(vty,
7990 " peers update resumed: %s\n",
7991 bgp->update_delay_peers_resume_time);
7992 }
7993 }
7994 }
7995 }
7996
7997 if (use_json) {
7998 if (bgp_maxmed_onstartup_configured(bgp)
7999 && bgp->maxmed_active)
8000 json_object_boolean_true_add(
8001 json, "maxMedOnStartup");
8002 if (bgp->v_maxmed_admin)
8003 json_object_boolean_true_add(
8004 json, "maxMedAdministrative");
8005
8006 json_object_int_add(
8007 json, "tableVersion",
8008 bgp_table_version(bgp->rib[afi][safi]));
8009
8010 ents = bgp_table_count(bgp->rib[afi][safi]);
8011 json_object_int_add(json, "ribCount", ents);
8012 json_object_int_add(
8013 json, "ribMemory",
8014 ents * sizeof(struct bgp_node));
8015
8016 ents = bgp->af_peer_count[afi][safi];
8017 json_object_int_add(json, "peerCount", ents);
8018 json_object_int_add(json, "peerMemory",
8019 ents * sizeof(struct peer));
8020
8021 if ((ents = listcount(bgp->group))) {
8022 json_object_int_add(
8023 json, "peerGroupCount", ents);
8024 json_object_int_add(
8025 json, "peerGroupMemory",
8026 ents * sizeof(struct
8027 peer_group));
8028 }
8029
8030 if (CHECK_FLAG(bgp->af_flags[afi][safi],
8031 BGP_CONFIG_DAMPENING))
8032 json_object_boolean_true_add(
8033 json, "dampeningEnabled");
8034 } else {
8035 if (bgp_maxmed_onstartup_configured(bgp)
8036 && bgp->maxmed_active)
8037 vty_out(vty,
8038 "Max-med on-startup active\n");
8039 if (bgp->v_maxmed_admin)
8040 vty_out(vty,
8041 "Max-med administrative active\n");
8042
8043 vty_out(vty, "BGP table version %" PRIu64 "\n",
8044 bgp_table_version(bgp->rib[afi][safi]));
8045
8046 ents = bgp_table_count(bgp->rib[afi][safi]);
8047 vty_out(vty,
8048 "RIB entries %ld, using %s of memory\n",
8049 ents,
8050 mtype_memstr(memstrbuf,
8051 sizeof(memstrbuf),
8052 ents * sizeof(struct
8053 bgp_node)));
8054
8055 /* Peer related usage */
8056 ents = bgp->af_peer_count[afi][safi];
8057 vty_out(vty, "Peers %ld, using %s of memory\n",
8058 ents,
8059 mtype_memstr(
8060 memstrbuf, sizeof(memstrbuf),
8061 ents * sizeof(struct peer)));
8062
8063 if ((ents = listcount(bgp->group)))
8064 vty_out(vty,
8065 "Peer groups %ld, using %s of memory\n",
8066 ents,
8067 mtype_memstr(
8068 memstrbuf,
8069 sizeof(memstrbuf),
8070 ents * sizeof(struct
8071 peer_group)));
8072
8073 if (CHECK_FLAG(bgp->af_flags[afi][safi],
8074 BGP_CONFIG_DAMPENING))
8075 vty_out(vty, "Dampening enabled.\n");
8076 vty_out(vty, "\n");
8077
8078 /* Subtract 8 here because 'Neighbor' is
8079 * 8 characters */
8080 vty_out(vty, "Neighbor");
8081 vty_out(vty, "%*s", max_neighbor_width - 8,
8082 " ");
8083 vty_out(vty,
8084 "V AS MsgRcvd MsgSent TblVer InQ OutQ Up/Down State/PfxRcd\n");
8085 }
8086 }
8087
8088 count++;
8089
8090 if (use_json) {
8091 json_peer = json_object_new_object();
8092
8093 if (peer_dynamic_neighbor(peer)) {
8094 dn_count++;
8095 json_object_boolean_true_add(json_peer,
8096 "dynamicPeer");
8097 }
8098
8099 if (peer->hostname)
8100 json_object_string_add(json_peer, "hostname",
8101 peer->hostname);
8102
8103 if (peer->domainname)
8104 json_object_string_add(json_peer, "domainname",
8105 peer->domainname);
8106
8107 json_object_int_add(json_peer, "remoteAs", peer->as);
8108 json_object_int_add(json_peer, "version", 4);
8109 json_object_int_add(json_peer, "msgRcvd",
8110 PEER_TOTAL_RX(peer));
8111 json_object_int_add(json_peer, "msgSent",
8112 PEER_TOTAL_TX(peer));
8113
8114 json_object_int_add(json_peer, "tableVersion",
8115 peer->version[afi][safi]);
8116 json_object_int_add(json_peer, "outq",
8117 peer->obuf->count);
8118 json_object_int_add(json_peer, "inq", 0);
8119 peer_uptime(peer->uptime, timebuf, BGP_UPTIME_LEN,
8120 use_json, json_peer);
8121
8122 /*
8123 * Adding "pfxRcd" field to match with the corresponding
8124 * CLI. "prefixReceivedCount" will be deprecated in
8125 * future.
8126 */
8127 json_object_int_add(json_peer, "prefixReceivedCount",
8128 peer->pcount[afi][pfx_rcd_safi]);
8129 json_object_int_add(json_peer, "pfxRcd",
8130 peer->pcount[afi][pfx_rcd_safi]);
8131
8132 paf = peer_af_find(peer, afi, pfx_rcd_safi);
8133 if (paf && PAF_SUBGRP(paf))
8134 json_object_int_add(json_peer,
8135 "pfxSnt",
8136 (PAF_SUBGRP(paf))->scount);
8137
8138 if (CHECK_FLAG(peer->flags, PEER_FLAG_SHUTDOWN))
8139 json_object_string_add(json_peer, "state",
8140 "Idle (Admin)");
8141 else if (peer->afc_recv[afi][safi])
8142 json_object_string_add(
8143 json_peer, "state",
8144 lookup_msg(bgp_status_msg, peer->status,
8145 NULL));
8146 else if (CHECK_FLAG(peer->sflags,
8147 PEER_STATUS_PREFIX_OVERFLOW))
8148 json_object_string_add(json_peer, "state",
8149 "Idle (PfxCt)");
8150 else
8151 json_object_string_add(
8152 json_peer, "state",
8153 lookup_msg(bgp_status_msg, peer->status,
8154 NULL));
8155
8156 if (peer->conf_if)
8157 json_object_string_add(json_peer, "idType",
8158 "interface");
8159 else if (peer->su.sa.sa_family == AF_INET)
8160 json_object_string_add(json_peer, "idType",
8161 "ipv4");
8162 else if (peer->su.sa.sa_family == AF_INET6)
8163 json_object_string_add(json_peer, "idType",
8164 "ipv6");
8165
8166 json_object_object_add(json_peers, peer->host,
8167 json_peer);
8168 } else {
8169 memset(dn_flag, '\0', sizeof(dn_flag));
8170 if (peer_dynamic_neighbor(peer)) {
8171 dn_count++;
8172 dn_flag[0] = '*';
8173 }
8174
8175 if (peer->hostname
8176 && bgp_flag_check(bgp, BGP_FLAG_SHOW_HOSTNAME))
8177 len = vty_out(vty, "%s%s(%s)", dn_flag,
8178 peer->hostname, peer->host);
8179 else
8180 len = vty_out(vty, "%s%s", dn_flag, peer->host);
8181
8182 /* pad the neighbor column with spaces */
8183 if (len < max_neighbor_width)
8184 vty_out(vty, "%*s", max_neighbor_width - len,
8185 " ");
8186
8187 vty_out(vty, "4 %10u %7u %7u %8" PRIu64 " %4d %4zd %8s",
8188 peer->as, PEER_TOTAL_RX(peer),
8189 PEER_TOTAL_TX(peer), peer->version[afi][safi],
8190 0, peer->obuf->count,
8191 peer_uptime(peer->uptime, timebuf,
8192 BGP_UPTIME_LEN, 0, NULL));
8193
8194 if (peer->status == Established)
8195 if (peer->afc_recv[afi][safi])
8196 vty_out(vty, " %12ld",
8197 peer->pcount[afi]
8198 [pfx_rcd_safi]);
8199 else
8200 vty_out(vty, " NoNeg");
8201 else {
8202 if (CHECK_FLAG(peer->flags, PEER_FLAG_SHUTDOWN))
8203 vty_out(vty, " Idle (Admin)");
8204 else if (CHECK_FLAG(
8205 peer->sflags,
8206 PEER_STATUS_PREFIX_OVERFLOW))
8207 vty_out(vty, " Idle (PfxCt)");
8208 else
8209 vty_out(vty, " %12s",
8210 lookup_msg(bgp_status_msg,
8211 peer->status, NULL));
8212 }
8213 vty_out(vty, "\n");
8214 }
8215 }
8216
8217 if (use_json) {
8218 json_object_object_add(json, "peers", json_peers);
8219
8220 json_object_int_add(json, "totalPeers", count);
8221 json_object_int_add(json, "dynamicPeers", dn_count);
8222
8223 bgp_show_bestpath_json(bgp, json);
8224
8225 vty_out(vty, "%s\n", json_object_to_json_string_ext(
8226 json, JSON_C_TO_STRING_PRETTY));
8227 json_object_free(json);
8228 } else {
8229 if (count)
8230 vty_out(vty, "\nTotal number of neighbors %d\n", count);
8231 else {
8232 vty_out(vty, "No %s neighbor is configured\n",
8233 afi_safi_print(afi, safi));
8234 }
8235
8236 if (dn_count) {
8237 vty_out(vty, "* - dynamic neighbor\n");
8238 vty_out(vty, "%d dynamic neighbor(s), limit %d\n",
8239 dn_count, bgp->dynamic_neighbors_limit);
8240 }
8241 }
8242
8243 return CMD_SUCCESS;
8244 }
8245
8246 static void bgp_show_summary_afi_safi(struct vty *vty, struct bgp *bgp, int afi,
8247 int safi, bool use_json,
8248 json_object *json)
8249 {
8250 int is_first = 1;
8251 int afi_wildcard = (afi == AFI_MAX);
8252 int safi_wildcard = (safi == SAFI_MAX);
8253 int is_wildcard = (afi_wildcard || safi_wildcard);
8254 bool nbr_output = false;
8255
8256 if (use_json && is_wildcard)
8257 vty_out(vty, "{\n");
8258 if (afi_wildcard)
8259 afi = 1; /* AFI_IP */
8260 while (afi < AFI_MAX) {
8261 if (safi_wildcard)
8262 safi = 1; /* SAFI_UNICAST */
8263 while (safi < SAFI_MAX) {
8264 if (bgp_afi_safi_peer_exists(bgp, afi, safi)) {
8265 nbr_output = true;
8266 if (is_wildcard) {
8267 /*
8268 * So limit output to those afi/safi
8269 * pairs that
8270 * actualy have something interesting in
8271 * them
8272 */
8273 if (use_json) {
8274 json = json_object_new_object();
8275
8276 if (!is_first)
8277 vty_out(vty, ",\n");
8278 else
8279 is_first = 0;
8280
8281 vty_out(vty, "\"%s\":",
8282 afi_safi_json(afi,
8283 safi));
8284 } else {
8285 vty_out(vty, "\n%s Summary:\n",
8286 afi_safi_print(afi,
8287 safi));
8288 }
8289 }
8290 bgp_show_summary(vty, bgp, afi, safi, use_json,
8291 json);
8292 }
8293 safi++;
8294 if (!safi_wildcard)
8295 safi = SAFI_MAX;
8296 }
8297 afi++;
8298 if (!afi_wildcard)
8299 afi = AFI_MAX;
8300 }
8301
8302 if (use_json && is_wildcard)
8303 vty_out(vty, "}\n");
8304 else if (!nbr_output) {
8305 if (use_json)
8306 vty_out(vty, "{}\n");
8307 else
8308 vty_out(vty, "%% No BGP neighbors found\n");
8309 }
8310 }
8311
8312 static void bgp_show_all_instances_summary_vty(struct vty *vty, afi_t afi,
8313 safi_t safi, bool use_json)
8314 {
8315 struct listnode *node, *nnode;
8316 struct bgp *bgp;
8317 json_object *json = NULL;
8318 int is_first = 1;
8319 bool nbr_output = false;
8320
8321 if (use_json)
8322 vty_out(vty, "{\n");
8323
8324 for (ALL_LIST_ELEMENTS(bm->bgp, node, nnode, bgp)) {
8325 nbr_output = true;
8326 if (use_json) {
8327 json = json_object_new_object();
8328
8329 if (!is_first)
8330 vty_out(vty, ",\n");
8331 else
8332 is_first = 0;
8333
8334 vty_out(vty, "\"%s\":",
8335 (bgp->inst_type == BGP_INSTANCE_TYPE_DEFAULT)
8336 ? VRF_DEFAULT_NAME
8337 : bgp->name);
8338 } else {
8339 vty_out(vty, "\nInstance %s:\n",
8340 (bgp->inst_type == BGP_INSTANCE_TYPE_DEFAULT)
8341 ? VRF_DEFAULT_NAME
8342 : bgp->name);
8343 }
8344 bgp_show_summary_afi_safi(vty, bgp, afi, safi, use_json, json);
8345 }
8346
8347 if (use_json)
8348 vty_out(vty, "}\n");
8349 else if (!nbr_output)
8350 vty_out(vty, "%% BGP instance not found\n");
8351 }
8352
8353 int bgp_show_summary_vty(struct vty *vty, const char *name, afi_t afi,
8354 safi_t safi, bool use_json)
8355 {
8356 struct bgp *bgp;
8357
8358 if (name) {
8359 if (strmatch(name, "all")) {
8360 bgp_show_all_instances_summary_vty(vty, afi, safi,
8361 use_json);
8362 return CMD_SUCCESS;
8363 } else {
8364 bgp = bgp_lookup_by_name(name);
8365
8366 if (!bgp) {
8367 if (use_json)
8368 vty_out(vty, "{}\n");
8369 else
8370 vty_out(vty,
8371 "%% BGP instance not found\n");
8372 return CMD_WARNING;
8373 }
8374
8375 bgp_show_summary_afi_safi(vty, bgp, afi, safi, use_json,
8376 NULL);
8377 return CMD_SUCCESS;
8378 }
8379 }
8380
8381 bgp = bgp_get_default();
8382
8383 if (bgp)
8384 bgp_show_summary_afi_safi(vty, bgp, afi, safi, use_json, NULL);
8385 else {
8386 if (use_json)
8387 vty_out(vty, "{}\n");
8388 else
8389 vty_out(vty, "%% BGP instance not found\n");
8390 return CMD_WARNING;
8391 }
8392
8393 return CMD_SUCCESS;
8394 }
8395
8396 /* `show [ip] bgp summary' commands. */
8397 DEFUN (show_ip_bgp_summary,
8398 show_ip_bgp_summary_cmd,
8399 "show [ip] bgp [<view|vrf> VIEWVRFNAME] ["BGP_AFI_CMD_STR" ["BGP_SAFI_WITH_LABEL_CMD_STR"]] summary [json]",
8400 SHOW_STR
8401 IP_STR
8402 BGP_STR
8403 BGP_INSTANCE_HELP_STR
8404 BGP_AFI_HELP_STR
8405 BGP_SAFI_WITH_LABEL_HELP_STR
8406 "Summary of BGP neighbor status\n"
8407 JSON_STR)
8408 {
8409 char *vrf = NULL;
8410 afi_t afi = AFI_MAX;
8411 safi_t safi = SAFI_MAX;
8412
8413 int idx = 0;
8414
8415 /* show [ip] bgp */
8416 if (argv_find(argv, argc, "ip", &idx))
8417 afi = AFI_IP;
8418 /* [<vrf> VIEWVRFNAME] */
8419 if (argv_find(argv, argc, "vrf", &idx)) {
8420 vrf = argv[idx + 1]->arg;
8421 if (vrf && strmatch(vrf, VRF_DEFAULT_NAME))
8422 vrf = NULL;
8423 } else if (argv_find(argv, argc, "view", &idx))
8424 /* [<view> VIEWVRFNAME] */
8425 vrf = argv[idx + 1]->arg;
8426 /* ["BGP_AFI_CMD_STR" ["BGP_SAFI_CMD_STR"]] */
8427 if (argv_find_and_parse_afi(argv, argc, &idx, &afi)) {
8428 argv_find_and_parse_safi(argv, argc, &idx, &safi);
8429 }
8430
8431 bool uj = use_json(argc, argv);
8432
8433 return bgp_show_summary_vty(vty, vrf, afi, safi, uj);
8434 }
8435
8436 const char *afi_safi_print(afi_t afi, safi_t safi)
8437 {
8438 if (afi == AFI_IP && safi == SAFI_UNICAST)
8439 return "IPv4 Unicast";
8440 else if (afi == AFI_IP && safi == SAFI_MULTICAST)
8441 return "IPv4 Multicast";
8442 else if (afi == AFI_IP && safi == SAFI_LABELED_UNICAST)
8443 return "IPv4 Labeled Unicast";
8444 else if (afi == AFI_IP && safi == SAFI_MPLS_VPN)
8445 return "IPv4 VPN";
8446 else if (afi == AFI_IP && safi == SAFI_ENCAP)
8447 return "IPv4 Encap";
8448 else if (afi == AFI_IP && safi == SAFI_FLOWSPEC)
8449 return "IPv4 Flowspec";
8450 else if (afi == AFI_IP6 && safi == SAFI_UNICAST)
8451 return "IPv6 Unicast";
8452 else if (afi == AFI_IP6 && safi == SAFI_MULTICAST)
8453 return "IPv6 Multicast";
8454 else if (afi == AFI_IP6 && safi == SAFI_LABELED_UNICAST)
8455 return "IPv6 Labeled Unicast";
8456 else if (afi == AFI_IP6 && safi == SAFI_MPLS_VPN)
8457 return "IPv6 VPN";
8458 else if (afi == AFI_IP6 && safi == SAFI_ENCAP)
8459 return "IPv6 Encap";
8460 else if (afi == AFI_IP6 && safi == SAFI_FLOWSPEC)
8461 return "IPv6 Flowspec";
8462 else if (afi == AFI_L2VPN && safi == SAFI_EVPN)
8463 return "L2VPN EVPN";
8464 else
8465 return "Unknown";
8466 }
8467
8468 /*
8469 * Please note that we have intentionally camelCased
8470 * the return strings here. So if you want
8471 * to use this function, please ensure you
8472 * are doing this within json output
8473 */
8474 const char *afi_safi_json(afi_t afi, safi_t safi)
8475 {
8476 if (afi == AFI_IP && safi == SAFI_UNICAST)
8477 return "ipv4Unicast";
8478 else if (afi == AFI_IP && safi == SAFI_MULTICAST)
8479 return "ipv4Multicast";
8480 else if (afi == AFI_IP && safi == SAFI_LABELED_UNICAST)
8481 return "ipv4LabeledUnicast";
8482 else if (afi == AFI_IP && safi == SAFI_MPLS_VPN)
8483 return "ipv4Vpn";
8484 else if (afi == AFI_IP && safi == SAFI_ENCAP)
8485 return "ipv4Encap";
8486 else if (afi == AFI_IP && safi == SAFI_FLOWSPEC)
8487 return "ipv4Flowspec";
8488 else if (afi == AFI_IP6 && safi == SAFI_UNICAST)
8489 return "ipv6Unicast";
8490 else if (afi == AFI_IP6 && safi == SAFI_MULTICAST)
8491 return "ipv6Multicast";
8492 else if (afi == AFI_IP6 && safi == SAFI_LABELED_UNICAST)
8493 return "ipv6LabeledUnicast";
8494 else if (afi == AFI_IP6 && safi == SAFI_MPLS_VPN)
8495 return "ipv6Vpn";
8496 else if (afi == AFI_IP6 && safi == SAFI_ENCAP)
8497 return "ipv6Encap";
8498 else if (afi == AFI_IP6 && safi == SAFI_FLOWSPEC)
8499 return "ipv6Flowspec";
8500 else if (afi == AFI_L2VPN && safi == SAFI_EVPN)
8501 return "l2VpnEvpn";
8502 else
8503 return "Unknown";
8504 }
8505
8506 /* Show BGP peer's information. */
8507 enum show_type { show_all, show_peer, show_ipv4_all, show_ipv6_all, show_ipv4_peer, show_ipv6_peer };
8508
8509 static void bgp_show_peer_afi_orf_cap(struct vty *vty, struct peer *p,
8510 afi_t afi, safi_t safi,
8511 uint16_t adv_smcap, uint16_t adv_rmcap,
8512 uint16_t rcv_smcap, uint16_t rcv_rmcap,
8513 bool use_json, json_object *json_pref)
8514 {
8515 /* Send-Mode */
8516 if (CHECK_FLAG(p->af_cap[afi][safi], adv_smcap)
8517 || CHECK_FLAG(p->af_cap[afi][safi], rcv_smcap)) {
8518 if (use_json) {
8519 if (CHECK_FLAG(p->af_cap[afi][safi], adv_smcap)
8520 && CHECK_FLAG(p->af_cap[afi][safi], rcv_smcap))
8521 json_object_string_add(json_pref, "sendMode",
8522 "advertisedAndReceived");
8523 else if (CHECK_FLAG(p->af_cap[afi][safi], adv_smcap))
8524 json_object_string_add(json_pref, "sendMode",
8525 "advertised");
8526 else if (CHECK_FLAG(p->af_cap[afi][safi], rcv_smcap))
8527 json_object_string_add(json_pref, "sendMode",
8528 "received");
8529 } else {
8530 vty_out(vty, " Send-mode: ");
8531 if (CHECK_FLAG(p->af_cap[afi][safi], adv_smcap))
8532 vty_out(vty, "advertised");
8533 if (CHECK_FLAG(p->af_cap[afi][safi], rcv_smcap))
8534 vty_out(vty, "%sreceived",
8535 CHECK_FLAG(p->af_cap[afi][safi],
8536 adv_smcap)
8537 ? ", "
8538 : "");
8539 vty_out(vty, "\n");
8540 }
8541 }
8542
8543 /* Receive-Mode */
8544 if (CHECK_FLAG(p->af_cap[afi][safi], adv_rmcap)
8545 || CHECK_FLAG(p->af_cap[afi][safi], rcv_rmcap)) {
8546 if (use_json) {
8547 if (CHECK_FLAG(p->af_cap[afi][safi], adv_rmcap)
8548 && CHECK_FLAG(p->af_cap[afi][safi], rcv_rmcap))
8549 json_object_string_add(json_pref, "recvMode",
8550 "advertisedAndReceived");
8551 else if (CHECK_FLAG(p->af_cap[afi][safi], adv_rmcap))
8552 json_object_string_add(json_pref, "recvMode",
8553 "advertised");
8554 else if (CHECK_FLAG(p->af_cap[afi][safi], rcv_rmcap))
8555 json_object_string_add(json_pref, "recvMode",
8556 "received");
8557 } else {
8558 vty_out(vty, " Receive-mode: ");
8559 if (CHECK_FLAG(p->af_cap[afi][safi], adv_rmcap))
8560 vty_out(vty, "advertised");
8561 if (CHECK_FLAG(p->af_cap[afi][safi], rcv_rmcap))
8562 vty_out(vty, "%sreceived",
8563 CHECK_FLAG(p->af_cap[afi][safi],
8564 adv_rmcap)
8565 ? ", "
8566 : "");
8567 vty_out(vty, "\n");
8568 }
8569 }
8570 }
8571
8572 static void bgp_show_peer_afi(struct vty *vty, struct peer *p, afi_t afi,
8573 safi_t safi, bool use_json,
8574 json_object *json_neigh)
8575 {
8576 struct bgp_filter *filter;
8577 struct peer_af *paf;
8578 char orf_pfx_name[BUFSIZ];
8579 int orf_pfx_count;
8580 json_object *json_af = NULL;
8581 json_object *json_prefA = NULL;
8582 json_object *json_prefB = NULL;
8583 json_object *json_addr = NULL;
8584
8585 if (use_json) {
8586 json_addr = json_object_new_object();
8587 json_af = json_object_new_object();
8588 filter = &p->filter[afi][safi];
8589
8590 if (peer_group_active(p))
8591 json_object_string_add(json_addr, "peerGroupMember",
8592 p->group->name);
8593
8594 paf = peer_af_find(p, afi, safi);
8595 if (paf && PAF_SUBGRP(paf)) {
8596 json_object_int_add(json_addr, "updateGroupId",
8597 PAF_UPDGRP(paf)->id);
8598 json_object_int_add(json_addr, "subGroupId",
8599 PAF_SUBGRP(paf)->id);
8600 json_object_int_add(json_addr, "packetQueueLength",
8601 bpacket_queue_virtual_length(paf));
8602 }
8603
8604 if (CHECK_FLAG(p->af_cap[afi][safi], PEER_CAP_ORF_PREFIX_SM_ADV)
8605 || CHECK_FLAG(p->af_cap[afi][safi],
8606 PEER_CAP_ORF_PREFIX_SM_RCV)
8607 || CHECK_FLAG(p->af_cap[afi][safi],
8608 PEER_CAP_ORF_PREFIX_RM_ADV)
8609 || CHECK_FLAG(p->af_cap[afi][safi],
8610 PEER_CAP_ORF_PREFIX_RM_RCV)) {
8611 json_object_int_add(json_af, "orfType",
8612 ORF_TYPE_PREFIX);
8613 json_prefA = json_object_new_object();
8614 bgp_show_peer_afi_orf_cap(vty, p, afi, safi,
8615 PEER_CAP_ORF_PREFIX_SM_ADV,
8616 PEER_CAP_ORF_PREFIX_RM_ADV,
8617 PEER_CAP_ORF_PREFIX_SM_RCV,
8618 PEER_CAP_ORF_PREFIX_RM_RCV,
8619 use_json, json_prefA);
8620 json_object_object_add(json_af, "orfPrefixList",
8621 json_prefA);
8622 }
8623
8624 if (CHECK_FLAG(p->af_cap[afi][safi], PEER_CAP_ORF_PREFIX_SM_ADV)
8625 || CHECK_FLAG(p->af_cap[afi][safi],
8626 PEER_CAP_ORF_PREFIX_SM_OLD_RCV)
8627 || CHECK_FLAG(p->af_cap[afi][safi],
8628 PEER_CAP_ORF_PREFIX_RM_ADV)
8629 || CHECK_FLAG(p->af_cap[afi][safi],
8630 PEER_CAP_ORF_PREFIX_RM_OLD_RCV)) {
8631 json_object_int_add(json_af, "orfOldType",
8632 ORF_TYPE_PREFIX_OLD);
8633 json_prefB = json_object_new_object();
8634 bgp_show_peer_afi_orf_cap(
8635 vty, p, afi, safi, PEER_CAP_ORF_PREFIX_SM_ADV,
8636 PEER_CAP_ORF_PREFIX_RM_ADV,
8637 PEER_CAP_ORF_PREFIX_SM_OLD_RCV,
8638 PEER_CAP_ORF_PREFIX_RM_OLD_RCV, use_json,
8639 json_prefB);
8640 json_object_object_add(json_af, "orfOldPrefixList",
8641 json_prefB);
8642 }
8643
8644 if (CHECK_FLAG(p->af_cap[afi][safi], PEER_CAP_ORF_PREFIX_SM_ADV)
8645 || CHECK_FLAG(p->af_cap[afi][safi],
8646 PEER_CAP_ORF_PREFIX_SM_RCV)
8647 || CHECK_FLAG(p->af_cap[afi][safi],
8648 PEER_CAP_ORF_PREFIX_SM_OLD_RCV)
8649 || CHECK_FLAG(p->af_cap[afi][safi],
8650 PEER_CAP_ORF_PREFIX_RM_ADV)
8651 || CHECK_FLAG(p->af_cap[afi][safi],
8652 PEER_CAP_ORF_PREFIX_RM_RCV)
8653 || CHECK_FLAG(p->af_cap[afi][safi],
8654 PEER_CAP_ORF_PREFIX_RM_OLD_RCV))
8655 json_object_object_add(json_addr, "afDependentCap",
8656 json_af);
8657 else
8658 json_object_free(json_af);
8659
8660 sprintf(orf_pfx_name, "%s.%d.%d", p->host, afi, safi);
8661 orf_pfx_count = prefix_bgp_show_prefix_list(
8662 NULL, afi, orf_pfx_name, use_json);
8663
8664 if (CHECK_FLAG(p->af_sflags[afi][safi],
8665 PEER_STATUS_ORF_PREFIX_SEND)
8666 || orf_pfx_count) {
8667 if (CHECK_FLAG(p->af_sflags[afi][safi],
8668 PEER_STATUS_ORF_PREFIX_SEND))
8669 json_object_boolean_true_add(json_neigh,
8670 "orfSent");
8671 if (orf_pfx_count)
8672 json_object_int_add(json_addr, "orfRecvCounter",
8673 orf_pfx_count);
8674 }
8675 if (CHECK_FLAG(p->af_sflags[afi][safi],
8676 PEER_STATUS_ORF_WAIT_REFRESH))
8677 json_object_string_add(
8678 json_addr, "orfFirstUpdate",
8679 "deferredUntilORFOrRouteRefreshRecvd");
8680
8681 if (CHECK_FLAG(p->af_flags[afi][safi],
8682 PEER_FLAG_REFLECTOR_CLIENT))
8683 json_object_boolean_true_add(json_addr,
8684 "routeReflectorClient");
8685 if (CHECK_FLAG(p->af_flags[afi][safi],
8686 PEER_FLAG_RSERVER_CLIENT))
8687 json_object_boolean_true_add(json_addr,
8688 "routeServerClient");
8689 if (CHECK_FLAG(p->af_flags[afi][safi], PEER_FLAG_SOFT_RECONFIG))
8690 json_object_boolean_true_add(json_addr,
8691 "inboundSoftConfigPermit");
8692
8693 if (CHECK_FLAG(p->af_flags[afi][safi],
8694 PEER_FLAG_REMOVE_PRIVATE_AS_ALL_REPLACE))
8695 json_object_boolean_true_add(
8696 json_addr,
8697 "privateAsNumsAllReplacedInUpdatesToNbr");
8698 else if (CHECK_FLAG(p->af_flags[afi][safi],
8699 PEER_FLAG_REMOVE_PRIVATE_AS_REPLACE))
8700 json_object_boolean_true_add(
8701 json_addr,
8702 "privateAsNumsReplacedInUpdatesToNbr");
8703 else if (CHECK_FLAG(p->af_flags[afi][safi],
8704 PEER_FLAG_REMOVE_PRIVATE_AS_ALL))
8705 json_object_boolean_true_add(
8706 json_addr,
8707 "privateAsNumsAllRemovedInUpdatesToNbr");
8708 else if (CHECK_FLAG(p->af_flags[afi][safi],
8709 PEER_FLAG_REMOVE_PRIVATE_AS))
8710 json_object_boolean_true_add(
8711 json_addr,
8712 "privateAsNumsRemovedInUpdatesToNbr");
8713
8714 if (p->addpath_type[afi][safi] != BGP_ADDPATH_NONE)
8715 json_object_boolean_true_add(
8716 json_addr,
8717 bgp_addpath_names(p->addpath_type[afi][safi])
8718 ->type_json_name);
8719
8720 if (CHECK_FLAG(p->af_flags[afi][safi], PEER_FLAG_AS_OVERRIDE))
8721 json_object_string_add(json_addr,
8722 "overrideASNsInOutboundUpdates",
8723 "ifAspathEqualRemoteAs");
8724
8725 if (CHECK_FLAG(p->af_flags[afi][safi], PEER_FLAG_NEXTHOP_SELF)
8726 || CHECK_FLAG(p->af_flags[afi][safi],
8727 PEER_FLAG_FORCE_NEXTHOP_SELF))
8728 json_object_boolean_true_add(json_addr,
8729 "routerAlwaysNextHop");
8730 if (CHECK_FLAG(p->af_flags[afi][safi],
8731 PEER_FLAG_AS_PATH_UNCHANGED))
8732 json_object_boolean_true_add(
8733 json_addr, "unchangedAsPathPropogatedToNbr");
8734 if (CHECK_FLAG(p->af_flags[afi][safi],
8735 PEER_FLAG_NEXTHOP_UNCHANGED))
8736 json_object_boolean_true_add(
8737 json_addr, "unchangedNextHopPropogatedToNbr");
8738 if (CHECK_FLAG(p->af_flags[afi][safi], PEER_FLAG_MED_UNCHANGED))
8739 json_object_boolean_true_add(
8740 json_addr, "unchangedMedPropogatedToNbr");
8741 if (CHECK_FLAG(p->af_flags[afi][safi], PEER_FLAG_SEND_COMMUNITY)
8742 || CHECK_FLAG(p->af_flags[afi][safi],
8743 PEER_FLAG_SEND_EXT_COMMUNITY)) {
8744 if (CHECK_FLAG(p->af_flags[afi][safi],
8745 PEER_FLAG_SEND_COMMUNITY)
8746 && CHECK_FLAG(p->af_flags[afi][safi],
8747 PEER_FLAG_SEND_EXT_COMMUNITY))
8748 json_object_string_add(json_addr,
8749 "commAttriSentToNbr",
8750 "extendedAndStandard");
8751 else if (CHECK_FLAG(p->af_flags[afi][safi],
8752 PEER_FLAG_SEND_EXT_COMMUNITY))
8753 json_object_string_add(json_addr,
8754 "commAttriSentToNbr",
8755 "extended");
8756 else
8757 json_object_string_add(json_addr,
8758 "commAttriSentToNbr",
8759 "standard");
8760 }
8761 if (CHECK_FLAG(p->af_flags[afi][safi],
8762 PEER_FLAG_DEFAULT_ORIGINATE)) {
8763 if (p->default_rmap[afi][safi].name)
8764 json_object_string_add(
8765 json_addr, "defaultRouteMap",
8766 p->default_rmap[afi][safi].name);
8767
8768 if (paf && PAF_SUBGRP(paf)
8769 && CHECK_FLAG(PAF_SUBGRP(paf)->sflags,
8770 SUBGRP_STATUS_DEFAULT_ORIGINATE))
8771 json_object_boolean_true_add(json_addr,
8772 "defaultSent");
8773 else
8774 json_object_boolean_true_add(json_addr,
8775 "defaultNotSent");
8776 }
8777
8778 if (afi == AFI_L2VPN && safi == SAFI_EVPN) {
8779 if (is_evpn_enabled())
8780 json_object_boolean_true_add(
8781 json_addr, "advertiseAllVnis");
8782 }
8783
8784 if (filter->plist[FILTER_IN].name
8785 || filter->dlist[FILTER_IN].name
8786 || filter->aslist[FILTER_IN].name
8787 || filter->map[RMAP_IN].name)
8788 json_object_boolean_true_add(json_addr,
8789 "inboundPathPolicyConfig");
8790 if (filter->plist[FILTER_OUT].name
8791 || filter->dlist[FILTER_OUT].name
8792 || filter->aslist[FILTER_OUT].name
8793 || filter->map[RMAP_OUT].name || filter->usmap.name)
8794 json_object_boolean_true_add(
8795 json_addr, "outboundPathPolicyConfig");
8796
8797 /* prefix-list */
8798 if (filter->plist[FILTER_IN].name)
8799 json_object_string_add(json_addr,
8800 "incomingUpdatePrefixFilterList",
8801 filter->plist[FILTER_IN].name);
8802 if (filter->plist[FILTER_OUT].name)
8803 json_object_string_add(json_addr,
8804 "outgoingUpdatePrefixFilterList",
8805 filter->plist[FILTER_OUT].name);
8806
8807 /* distribute-list */
8808 if (filter->dlist[FILTER_IN].name)
8809 json_object_string_add(
8810 json_addr, "incomingUpdateNetworkFilterList",
8811 filter->dlist[FILTER_IN].name);
8812 if (filter->dlist[FILTER_OUT].name)
8813 json_object_string_add(
8814 json_addr, "outgoingUpdateNetworkFilterList",
8815 filter->dlist[FILTER_OUT].name);
8816
8817 /* filter-list. */
8818 if (filter->aslist[FILTER_IN].name)
8819 json_object_string_add(json_addr,
8820 "incomingUpdateAsPathFilterList",
8821 filter->aslist[FILTER_IN].name);
8822 if (filter->aslist[FILTER_OUT].name)
8823 json_object_string_add(json_addr,
8824 "outgoingUpdateAsPathFilterList",
8825 filter->aslist[FILTER_OUT].name);
8826
8827 /* route-map. */
8828 if (filter->map[RMAP_IN].name)
8829 json_object_string_add(
8830 json_addr, "routeMapForIncomingAdvertisements",
8831 filter->map[RMAP_IN].name);
8832 if (filter->map[RMAP_OUT].name)
8833 json_object_string_add(
8834 json_addr, "routeMapForOutgoingAdvertisements",
8835 filter->map[RMAP_OUT].name);
8836
8837 /* ebgp-requires-policy (inbound) */
8838 if (p->bgp->ebgp_requires_policy == DEFAULT_EBGP_POLICY_ENABLED
8839 && !bgp_inbound_policy_exists(p, filter))
8840 json_object_string_add(
8841 json_addr, "inboundEbgpRequiresPolicy",
8842 "Inbound updates discarded due to missing policy");
8843
8844 /* ebgp-requires-policy (outbound) */
8845 if (p->bgp->ebgp_requires_policy == DEFAULT_EBGP_POLICY_ENABLED
8846 && (!bgp_outbound_policy_exists(p, filter)))
8847 json_object_string_add(
8848 json_addr, "outboundEbgpRequiresPolicy",
8849 "Outbound updates discarded due to missing policy");
8850
8851 /* unsuppress-map */
8852 if (filter->usmap.name)
8853 json_object_string_add(json_addr,
8854 "selectiveUnsuppressRouteMap",
8855 filter->usmap.name);
8856
8857 /* Receive prefix count */
8858 json_object_int_add(json_addr, "acceptedPrefixCounter",
8859 p->pcount[afi][safi]);
8860 if (paf && PAF_SUBGRP(paf))
8861 json_object_int_add(json_addr, "sentPrefixCounter",
8862 (PAF_SUBGRP(paf))->scount);
8863
8864 /* Maximum prefix */
8865 if (CHECK_FLAG(p->af_flags[afi][safi], PEER_FLAG_MAX_PREFIX)) {
8866 json_object_int_add(json_addr, "prefixAllowedMax",
8867 p->pmax[afi][safi]);
8868 if (CHECK_FLAG(p->af_flags[afi][safi],
8869 PEER_FLAG_MAX_PREFIX_WARNING))
8870 json_object_boolean_true_add(
8871 json_addr, "prefixAllowedMaxWarning");
8872 json_object_int_add(json_addr,
8873 "prefixAllowedWarningThresh",
8874 p->pmax_threshold[afi][safi]);
8875 if (p->pmax_restart[afi][safi])
8876 json_object_int_add(
8877 json_addr,
8878 "prefixAllowedRestartIntervalMsecs",
8879 p->pmax_restart[afi][safi] * 60000);
8880 }
8881 json_object_object_add(json_neigh, afi_safi_print(afi, safi),
8882 json_addr);
8883
8884 } else {
8885 filter = &p->filter[afi][safi];
8886
8887 vty_out(vty, " For address family: %s\n",
8888 afi_safi_print(afi, safi));
8889
8890 if (peer_group_active(p))
8891 vty_out(vty, " %s peer-group member\n",
8892 p->group->name);
8893
8894 paf = peer_af_find(p, afi, safi);
8895 if (paf && PAF_SUBGRP(paf)) {
8896 vty_out(vty, " Update group %" PRIu64
8897 ", subgroup %" PRIu64 "\n",
8898 PAF_UPDGRP(paf)->id, PAF_SUBGRP(paf)->id);
8899 vty_out(vty, " Packet Queue length %d\n",
8900 bpacket_queue_virtual_length(paf));
8901 } else {
8902 vty_out(vty, " Not part of any update group\n");
8903 }
8904 if (CHECK_FLAG(p->af_cap[afi][safi], PEER_CAP_ORF_PREFIX_SM_ADV)
8905 || CHECK_FLAG(p->af_cap[afi][safi],
8906 PEER_CAP_ORF_PREFIX_SM_RCV)
8907 || CHECK_FLAG(p->af_cap[afi][safi],
8908 PEER_CAP_ORF_PREFIX_SM_OLD_RCV)
8909 || CHECK_FLAG(p->af_cap[afi][safi],
8910 PEER_CAP_ORF_PREFIX_RM_ADV)
8911 || CHECK_FLAG(p->af_cap[afi][safi],
8912 PEER_CAP_ORF_PREFIX_RM_RCV)
8913 || CHECK_FLAG(p->af_cap[afi][safi],
8914 PEER_CAP_ORF_PREFIX_RM_OLD_RCV))
8915 vty_out(vty, " AF-dependant capabilities:\n");
8916
8917 if (CHECK_FLAG(p->af_cap[afi][safi], PEER_CAP_ORF_PREFIX_SM_ADV)
8918 || CHECK_FLAG(p->af_cap[afi][safi],
8919 PEER_CAP_ORF_PREFIX_SM_RCV)
8920 || CHECK_FLAG(p->af_cap[afi][safi],
8921 PEER_CAP_ORF_PREFIX_RM_ADV)
8922 || CHECK_FLAG(p->af_cap[afi][safi],
8923 PEER_CAP_ORF_PREFIX_RM_RCV)) {
8924 vty_out(vty,
8925 " Outbound Route Filter (ORF) type (%d) Prefix-list:\n",
8926 ORF_TYPE_PREFIX);
8927 bgp_show_peer_afi_orf_cap(
8928 vty, p, afi, safi, PEER_CAP_ORF_PREFIX_SM_ADV,
8929 PEER_CAP_ORF_PREFIX_RM_ADV,
8930 PEER_CAP_ORF_PREFIX_SM_RCV,
8931 PEER_CAP_ORF_PREFIX_RM_RCV, use_json, NULL);
8932 }
8933 if (CHECK_FLAG(p->af_cap[afi][safi], PEER_CAP_ORF_PREFIX_SM_ADV)
8934 || CHECK_FLAG(p->af_cap[afi][safi],
8935 PEER_CAP_ORF_PREFIX_SM_OLD_RCV)
8936 || CHECK_FLAG(p->af_cap[afi][safi],
8937 PEER_CAP_ORF_PREFIX_RM_ADV)
8938 || CHECK_FLAG(p->af_cap[afi][safi],
8939 PEER_CAP_ORF_PREFIX_RM_OLD_RCV)) {
8940 vty_out(vty,
8941 " Outbound Route Filter (ORF) type (%d) Prefix-list:\n",
8942 ORF_TYPE_PREFIX_OLD);
8943 bgp_show_peer_afi_orf_cap(
8944 vty, p, afi, safi, PEER_CAP_ORF_PREFIX_SM_ADV,
8945 PEER_CAP_ORF_PREFIX_RM_ADV,
8946 PEER_CAP_ORF_PREFIX_SM_OLD_RCV,
8947 PEER_CAP_ORF_PREFIX_RM_OLD_RCV, use_json, NULL);
8948 }
8949
8950 sprintf(orf_pfx_name, "%s.%d.%d", p->host, afi, safi);
8951 orf_pfx_count = prefix_bgp_show_prefix_list(
8952 NULL, afi, orf_pfx_name, use_json);
8953
8954 if (CHECK_FLAG(p->af_sflags[afi][safi],
8955 PEER_STATUS_ORF_PREFIX_SEND)
8956 || orf_pfx_count) {
8957 vty_out(vty, " Outbound Route Filter (ORF):");
8958 if (CHECK_FLAG(p->af_sflags[afi][safi],
8959 PEER_STATUS_ORF_PREFIX_SEND))
8960 vty_out(vty, " sent;");
8961 if (orf_pfx_count)
8962 vty_out(vty, " received (%d entries)",
8963 orf_pfx_count);
8964 vty_out(vty, "\n");
8965 }
8966 if (CHECK_FLAG(p->af_sflags[afi][safi],
8967 PEER_STATUS_ORF_WAIT_REFRESH))
8968 vty_out(vty,
8969 " First update is deferred until ORF or ROUTE-REFRESH is received\n");
8970
8971 if (CHECK_FLAG(p->af_flags[afi][safi],
8972 PEER_FLAG_REFLECTOR_CLIENT))
8973 vty_out(vty, " Route-Reflector Client\n");
8974 if (CHECK_FLAG(p->af_flags[afi][safi],
8975 PEER_FLAG_RSERVER_CLIENT))
8976 vty_out(vty, " Route-Server Client\n");
8977 if (CHECK_FLAG(p->af_flags[afi][safi], PEER_FLAG_SOFT_RECONFIG))
8978 vty_out(vty,
8979 " Inbound soft reconfiguration allowed\n");
8980
8981 if (CHECK_FLAG(p->af_flags[afi][safi],
8982 PEER_FLAG_REMOVE_PRIVATE_AS_ALL_REPLACE))
8983 vty_out(vty,
8984 " Private AS numbers (all) replaced in updates to this neighbor\n");
8985 else if (CHECK_FLAG(p->af_flags[afi][safi],
8986 PEER_FLAG_REMOVE_PRIVATE_AS_REPLACE))
8987 vty_out(vty,
8988 " Private AS numbers replaced in updates to this neighbor\n");
8989 else if (CHECK_FLAG(p->af_flags[afi][safi],
8990 PEER_FLAG_REMOVE_PRIVATE_AS_ALL))
8991 vty_out(vty,
8992 " Private AS numbers (all) removed in updates to this neighbor\n");
8993 else if (CHECK_FLAG(p->af_flags[afi][safi],
8994 PEER_FLAG_REMOVE_PRIVATE_AS))
8995 vty_out(vty,
8996 " Private AS numbers removed in updates to this neighbor\n");
8997
8998 if (p->addpath_type[afi][safi] != BGP_ADDPATH_NONE)
8999 vty_out(vty, " %s\n",
9000 bgp_addpath_names(p->addpath_type[afi][safi])
9001 ->human_description);
9002
9003 if (CHECK_FLAG(p->af_flags[afi][safi], PEER_FLAG_AS_OVERRIDE))
9004 vty_out(vty,
9005 " Override ASNs in outbound updates if aspath equals remote-as\n");
9006
9007 if (CHECK_FLAG(p->af_flags[afi][safi], PEER_FLAG_NEXTHOP_SELF)
9008 || CHECK_FLAG(p->af_flags[afi][safi],
9009 PEER_FLAG_FORCE_NEXTHOP_SELF))
9010 vty_out(vty, " NEXT_HOP is always this router\n");
9011 if (CHECK_FLAG(p->af_flags[afi][safi],
9012 PEER_FLAG_AS_PATH_UNCHANGED))
9013 vty_out(vty,
9014 " AS_PATH is propagated unchanged to this neighbor\n");
9015 if (CHECK_FLAG(p->af_flags[afi][safi],
9016 PEER_FLAG_NEXTHOP_UNCHANGED))
9017 vty_out(vty,
9018 " NEXT_HOP is propagated unchanged to this neighbor\n");
9019 if (CHECK_FLAG(p->af_flags[afi][safi], PEER_FLAG_MED_UNCHANGED))
9020 vty_out(vty,
9021 " MED is propagated unchanged to this neighbor\n");
9022 if (CHECK_FLAG(p->af_flags[afi][safi], PEER_FLAG_SEND_COMMUNITY)
9023 || CHECK_FLAG(p->af_flags[afi][safi],
9024 PEER_FLAG_SEND_EXT_COMMUNITY)
9025 || CHECK_FLAG(p->af_flags[afi][safi],
9026 PEER_FLAG_SEND_LARGE_COMMUNITY)) {
9027 vty_out(vty,
9028 " Community attribute sent to this neighbor");
9029 if (CHECK_FLAG(p->af_flags[afi][safi],
9030 PEER_FLAG_SEND_COMMUNITY)
9031 && CHECK_FLAG(p->af_flags[afi][safi],
9032 PEER_FLAG_SEND_EXT_COMMUNITY)
9033 && CHECK_FLAG(p->af_flags[afi][safi],
9034 PEER_FLAG_SEND_LARGE_COMMUNITY))
9035 vty_out(vty, "(all)\n");
9036 else if (CHECK_FLAG(p->af_flags[afi][safi],
9037 PEER_FLAG_SEND_LARGE_COMMUNITY))
9038 vty_out(vty, "(large)\n");
9039 else if (CHECK_FLAG(p->af_flags[afi][safi],
9040 PEER_FLAG_SEND_EXT_COMMUNITY))
9041 vty_out(vty, "(extended)\n");
9042 else
9043 vty_out(vty, "(standard)\n");
9044 }
9045 if (CHECK_FLAG(p->af_flags[afi][safi],
9046 PEER_FLAG_DEFAULT_ORIGINATE)) {
9047 vty_out(vty, " Default information originate,");
9048
9049 if (p->default_rmap[afi][safi].name)
9050 vty_out(vty, " default route-map %s%s,",
9051 p->default_rmap[afi][safi].map ? "*"
9052 : "",
9053 p->default_rmap[afi][safi].name);
9054 if (paf && PAF_SUBGRP(paf)
9055 && CHECK_FLAG(PAF_SUBGRP(paf)->sflags,
9056 SUBGRP_STATUS_DEFAULT_ORIGINATE))
9057 vty_out(vty, " default sent\n");
9058 else
9059 vty_out(vty, " default not sent\n");
9060 }
9061
9062 /* advertise-vni-all */
9063 if (afi == AFI_L2VPN && safi == SAFI_EVPN) {
9064 if (is_evpn_enabled())
9065 vty_out(vty, " advertise-all-vni\n");
9066 }
9067
9068 if (filter->plist[FILTER_IN].name
9069 || filter->dlist[FILTER_IN].name
9070 || filter->aslist[FILTER_IN].name
9071 || filter->map[RMAP_IN].name)
9072 vty_out(vty, " Inbound path policy configured\n");
9073 if (filter->plist[FILTER_OUT].name
9074 || filter->dlist[FILTER_OUT].name
9075 || filter->aslist[FILTER_OUT].name
9076 || filter->map[RMAP_OUT].name || filter->usmap.name)
9077 vty_out(vty, " Outbound path policy configured\n");
9078
9079 /* prefix-list */
9080 if (filter->plist[FILTER_IN].name)
9081 vty_out(vty,
9082 " Incoming update prefix filter list is %s%s\n",
9083 filter->plist[FILTER_IN].plist ? "*" : "",
9084 filter->plist[FILTER_IN].name);
9085 if (filter->plist[FILTER_OUT].name)
9086 vty_out(vty,
9087 " Outgoing update prefix filter list is %s%s\n",
9088 filter->plist[FILTER_OUT].plist ? "*" : "",
9089 filter->plist[FILTER_OUT].name);
9090
9091 /* distribute-list */
9092 if (filter->dlist[FILTER_IN].name)
9093 vty_out(vty,
9094 " Incoming update network filter list is %s%s\n",
9095 filter->dlist[FILTER_IN].alist ? "*" : "",
9096 filter->dlist[FILTER_IN].name);
9097 if (filter->dlist[FILTER_OUT].name)
9098 vty_out(vty,
9099 " Outgoing update network filter list is %s%s\n",
9100 filter->dlist[FILTER_OUT].alist ? "*" : "",
9101 filter->dlist[FILTER_OUT].name);
9102
9103 /* filter-list. */
9104 if (filter->aslist[FILTER_IN].name)
9105 vty_out(vty,
9106 " Incoming update AS path filter list is %s%s\n",
9107 filter->aslist[FILTER_IN].aslist ? "*" : "",
9108 filter->aslist[FILTER_IN].name);
9109 if (filter->aslist[FILTER_OUT].name)
9110 vty_out(vty,
9111 " Outgoing update AS path filter list is %s%s\n",
9112 filter->aslist[FILTER_OUT].aslist ? "*" : "",
9113 filter->aslist[FILTER_OUT].name);
9114
9115 /* route-map. */
9116 if (filter->map[RMAP_IN].name)
9117 vty_out(vty,
9118 " Route map for incoming advertisements is %s%s\n",
9119 filter->map[RMAP_IN].map ? "*" : "",
9120 filter->map[RMAP_IN].name);
9121 if (filter->map[RMAP_OUT].name)
9122 vty_out(vty,
9123 " Route map for outgoing advertisements is %s%s\n",
9124 filter->map[RMAP_OUT].map ? "*" : "",
9125 filter->map[RMAP_OUT].name);
9126
9127 /* ebgp-requires-policy (inbound) */
9128 if (p->bgp->ebgp_requires_policy == DEFAULT_EBGP_POLICY_ENABLED
9129 && !bgp_inbound_policy_exists(p, filter))
9130 vty_out(vty,
9131 " Inbound updates discarded due to missing policy\n");
9132
9133 /* ebgp-requires-policy (outbound) */
9134 if (p->bgp->ebgp_requires_policy == DEFAULT_EBGP_POLICY_ENABLED
9135 && !bgp_outbound_policy_exists(p, filter))
9136 vty_out(vty,
9137 " Outbound updates discarded due to missing policy\n");
9138
9139 /* unsuppress-map */
9140 if (filter->usmap.name)
9141 vty_out(vty,
9142 " Route map for selective unsuppress is %s%s\n",
9143 filter->usmap.map ? "*" : "",
9144 filter->usmap.name);
9145
9146 /* Receive prefix count */
9147 vty_out(vty, " %ld accepted prefixes\n", p->pcount[afi][safi]);
9148
9149 /* Maximum prefix */
9150 if (CHECK_FLAG(p->af_flags[afi][safi], PEER_FLAG_MAX_PREFIX)) {
9151 vty_out(vty, " Maximum prefixes allowed %ld%s\n",
9152 p->pmax[afi][safi],
9153 CHECK_FLAG(p->af_flags[afi][safi],
9154 PEER_FLAG_MAX_PREFIX_WARNING)
9155 ? " (warning-only)"
9156 : "");
9157 vty_out(vty, " Threshold for warning message %d%%",
9158 p->pmax_threshold[afi][safi]);
9159 if (p->pmax_restart[afi][safi])
9160 vty_out(vty, ", restart interval %d min",
9161 p->pmax_restart[afi][safi]);
9162 vty_out(vty, "\n");
9163 }
9164
9165 vty_out(vty, "\n");
9166 }
9167 }
9168
9169 static void bgp_show_peer(struct vty *vty, struct peer *p, bool use_json,
9170 json_object *json)
9171 {
9172 struct bgp *bgp;
9173 char buf1[PREFIX2STR_BUFFER], buf[SU_ADDRSTRLEN];
9174 char timebuf[BGP_UPTIME_LEN];
9175 char dn_flag[2];
9176 const char *subcode_str;
9177 const char *code_str;
9178 afi_t afi;
9179 safi_t safi;
9180 uint16_t i;
9181 uint8_t *msg;
9182 json_object *json_neigh = NULL;
9183 time_t epoch_tbuf;
9184
9185 bgp = p->bgp;
9186
9187 if (use_json)
9188 json_neigh = json_object_new_object();
9189
9190 memset(dn_flag, '\0', sizeof(dn_flag));
9191 if (!p->conf_if && peer_dynamic_neighbor(p))
9192 dn_flag[0] = '*';
9193
9194 if (!use_json) {
9195 if (p->conf_if) /* Configured interface name. */
9196 vty_out(vty, "BGP neighbor on %s: %s, ", p->conf_if,
9197 BGP_PEER_SU_UNSPEC(p)
9198 ? "None"
9199 : sockunion2str(&p->su, buf,
9200 SU_ADDRSTRLEN));
9201 else /* Configured IP address. */
9202 vty_out(vty, "BGP neighbor is %s%s, ", dn_flag,
9203 p->host);
9204 }
9205
9206 if (use_json) {
9207 if (p->conf_if && BGP_PEER_SU_UNSPEC(p))
9208 json_object_string_add(json_neigh, "bgpNeighborAddr",
9209 "none");
9210 else if (p->conf_if && !BGP_PEER_SU_UNSPEC(p))
9211 json_object_string_add(
9212 json_neigh, "bgpNeighborAddr",
9213 sockunion2str(&p->su, buf, SU_ADDRSTRLEN));
9214
9215 json_object_int_add(json_neigh, "remoteAs", p->as);
9216
9217 if (p->change_local_as)
9218 json_object_int_add(json_neigh, "localAs",
9219 p->change_local_as);
9220 else
9221 json_object_int_add(json_neigh, "localAs", p->local_as);
9222
9223 if (CHECK_FLAG(p->flags, PEER_FLAG_LOCAL_AS_NO_PREPEND))
9224 json_object_boolean_true_add(json_neigh,
9225 "localAsNoPrepend");
9226
9227 if (CHECK_FLAG(p->flags, PEER_FLAG_LOCAL_AS_REPLACE_AS))
9228 json_object_boolean_true_add(json_neigh,
9229 "localAsReplaceAs");
9230 } else {
9231 if ((p->as_type == AS_SPECIFIED) || (p->as_type == AS_EXTERNAL)
9232 || (p->as_type == AS_INTERNAL))
9233 vty_out(vty, "remote AS %u, ", p->as);
9234 else
9235 vty_out(vty, "remote AS Unspecified, ");
9236 vty_out(vty, "local AS %u%s%s, ",
9237 p->change_local_as ? p->change_local_as : p->local_as,
9238 CHECK_FLAG(p->flags, PEER_FLAG_LOCAL_AS_NO_PREPEND)
9239 ? " no-prepend"
9240 : "",
9241 CHECK_FLAG(p->flags, PEER_FLAG_LOCAL_AS_REPLACE_AS)
9242 ? " replace-as"
9243 : "");
9244 }
9245 /* peer type internal or confed-internal */
9246 if ((p->as == p->local_as) || (p->as_type == AS_INTERNAL)) {
9247 if (use_json) {
9248 if (CHECK_FLAG(bgp->config, BGP_CONFIG_CONFEDERATION))
9249 json_object_boolean_true_add(
9250 json_neigh, "nbrConfedInternalLink");
9251 else
9252 json_object_boolean_true_add(json_neigh,
9253 "nbrInternalLink");
9254 } else {
9255 if (CHECK_FLAG(bgp->config, BGP_CONFIG_CONFEDERATION))
9256 vty_out(vty, "confed-internal link\n");
9257 else
9258 vty_out(vty, "internal link\n");
9259 }
9260 /* peer type external or confed-external */
9261 } else if (p->as || (p->as_type == AS_EXTERNAL)) {
9262 if (use_json) {
9263 if (CHECK_FLAG(bgp->config, BGP_CONFIG_CONFEDERATION))
9264 json_object_boolean_true_add(
9265 json_neigh, "nbrConfedExternalLink");
9266 else
9267 json_object_boolean_true_add(json_neigh,
9268 "nbrExternalLink");
9269 } else {
9270 if (bgp_confederation_peers_check(bgp, p->as))
9271 vty_out(vty, "confed-external link\n");
9272 else
9273 vty_out(vty, "external link\n");
9274 }
9275 } else {
9276 if (use_json)
9277 json_object_boolean_true_add(json_neigh,
9278 "nbrUnspecifiedLink");
9279 else
9280 vty_out(vty, "unspecified link\n");
9281 }
9282
9283 /* Description. */
9284 if (p->desc) {
9285 if (use_json)
9286 json_object_string_add(json_neigh, "nbrDesc", p->desc);
9287 else
9288 vty_out(vty, " Description: %s\n", p->desc);
9289 }
9290
9291 if (p->hostname) {
9292 if (use_json) {
9293 if (p->hostname)
9294 json_object_string_add(json_neigh, "hostname",
9295 p->hostname);
9296
9297 if (p->domainname)
9298 json_object_string_add(json_neigh, "domainname",
9299 p->domainname);
9300 } else {
9301 if (p->domainname && (p->domainname[0] != '\0'))
9302 vty_out(vty, "Hostname: %s.%s\n", p->hostname,
9303 p->domainname);
9304 else
9305 vty_out(vty, "Hostname: %s\n", p->hostname);
9306 }
9307 }
9308
9309 /* Peer-group */
9310 if (p->group) {
9311 if (use_json) {
9312 json_object_string_add(json_neigh, "peerGroup",
9313 p->group->name);
9314
9315 if (dn_flag[0]) {
9316 struct prefix prefix, *range = NULL;
9317
9318 sockunion2hostprefix(&(p->su), &prefix);
9319 range = peer_group_lookup_dynamic_neighbor_range(
9320 p->group, &prefix);
9321
9322 if (range) {
9323 prefix2str(range, buf1, sizeof(buf1));
9324 json_object_string_add(
9325 json_neigh,
9326 "peerSubnetRangeGroup", buf1);
9327 }
9328 }
9329 } else {
9330 vty_out(vty,
9331 " Member of peer-group %s for session parameters\n",
9332 p->group->name);
9333
9334 if (dn_flag[0]) {
9335 struct prefix prefix, *range = NULL;
9336
9337 sockunion2hostprefix(&(p->su), &prefix);
9338 range = peer_group_lookup_dynamic_neighbor_range(
9339 p->group, &prefix);
9340
9341 if (range) {
9342 prefix2str(range, buf1, sizeof(buf1));
9343 vty_out(vty,
9344 " Belongs to the subnet range group: %s\n",
9345 buf1);
9346 }
9347 }
9348 }
9349 }
9350
9351 if (use_json) {
9352 /* Administrative shutdown. */
9353 if (CHECK_FLAG(p->flags, PEER_FLAG_SHUTDOWN))
9354 json_object_boolean_true_add(json_neigh,
9355 "adminShutDown");
9356
9357 /* BGP Version. */
9358 json_object_int_add(json_neigh, "bgpVersion", 4);
9359 json_object_string_add(
9360 json_neigh, "remoteRouterId",
9361 inet_ntop(AF_INET, &p->remote_id, buf1, sizeof(buf1)));
9362 json_object_string_add(
9363 json_neigh, "localRouterId",
9364 inet_ntop(AF_INET, &bgp->router_id, buf1,
9365 sizeof(buf1)));
9366
9367 /* Confederation */
9368 if (CHECK_FLAG(bgp->config, BGP_CONFIG_CONFEDERATION)
9369 && bgp_confederation_peers_check(bgp, p->as))
9370 json_object_boolean_true_add(json_neigh,
9371 "nbrCommonAdmin");
9372
9373 /* Status. */
9374 json_object_string_add(
9375 json_neigh, "bgpState",
9376 lookup_msg(bgp_status_msg, p->status, NULL));
9377
9378 if (p->status == Established) {
9379 time_t uptime;
9380
9381 uptime = bgp_clock();
9382 uptime -= p->uptime;
9383 epoch_tbuf = time(NULL) - uptime;
9384
9385 #if CONFDATE > 20200101
9386 CPP_NOTICE(
9387 "bgpTimerUp should be deprecated and can be removed now");
9388 #endif
9389 /*
9390 * bgpTimerUp was miliseconds that was accurate
9391 * up to 1 day, then the value returned
9392 * became garbage. So in order to provide
9393 * some level of backwards compatability,
9394 * we still provde the data, but now
9395 * we are returning the correct value
9396 * and also adding a new bgpTimerUpMsec
9397 * which will allow us to deprecate
9398 * this eventually
9399 */
9400 json_object_int_add(json_neigh, "bgpTimerUp",
9401 uptime * 1000);
9402 json_object_int_add(json_neigh, "bgpTimerUpMsec",
9403 uptime * 1000);
9404 json_object_string_add(json_neigh, "bgpTimerUpString",
9405 peer_uptime(p->uptime, timebuf,
9406 BGP_UPTIME_LEN, 0,
9407 NULL));
9408 json_object_int_add(json_neigh,
9409 "bgpTimerUpEstablishedEpoch",
9410 epoch_tbuf);
9411 }
9412
9413 else if (p->status == Active) {
9414 if (CHECK_FLAG(p->flags, PEER_FLAG_PASSIVE))
9415 json_object_string_add(json_neigh, "bgpStateIs",
9416 "passive");
9417 else if (CHECK_FLAG(p->sflags, PEER_STATUS_NSF_WAIT))
9418 json_object_string_add(json_neigh, "bgpStateIs",
9419 "passiveNSF");
9420 }
9421
9422 /* read timer */
9423 time_t uptime;
9424 struct tm *tm;
9425
9426 uptime = bgp_clock();
9427 uptime -= p->readtime;
9428 tm = gmtime(&uptime);
9429 json_object_int_add(json_neigh, "bgpTimerLastRead",
9430 (tm->tm_sec * 1000) + (tm->tm_min * 60000)
9431 + (tm->tm_hour * 3600000));
9432
9433 uptime = bgp_clock();
9434 uptime -= p->last_write;
9435 tm = gmtime(&uptime);
9436 json_object_int_add(json_neigh, "bgpTimerLastWrite",
9437 (tm->tm_sec * 1000) + (tm->tm_min * 60000)
9438 + (tm->tm_hour * 3600000));
9439
9440 uptime = bgp_clock();
9441 uptime -= p->update_time;
9442 tm = gmtime(&uptime);
9443 json_object_int_add(json_neigh, "bgpInUpdateElapsedTimeMsecs",
9444 (tm->tm_sec * 1000) + (tm->tm_min * 60000)
9445 + (tm->tm_hour * 3600000));
9446
9447 /* Configured timer values. */
9448 json_object_int_add(json_neigh, "bgpTimerHoldTimeMsecs",
9449 p->v_holdtime * 1000);
9450 json_object_int_add(json_neigh,
9451 "bgpTimerKeepAliveIntervalMsecs",
9452 p->v_keepalive * 1000);
9453 if (CHECK_FLAG(p->flags, PEER_FLAG_TIMER)) {
9454 json_object_int_add(json_neigh,
9455 "bgpTimerConfiguredHoldTimeMsecs",
9456 p->holdtime * 1000);
9457 json_object_int_add(
9458 json_neigh,
9459 "bgpTimerConfiguredKeepAliveIntervalMsecs",
9460 p->keepalive * 1000);
9461 } else if ((bgp->default_holdtime != BGP_DEFAULT_HOLDTIME)
9462 || (bgp->default_keepalive
9463 != BGP_DEFAULT_KEEPALIVE)) {
9464 json_object_int_add(json_neigh,
9465 "bgpTimerConfiguredHoldTimeMsecs",
9466 bgp->default_holdtime);
9467 json_object_int_add(
9468 json_neigh,
9469 "bgpTimerConfiguredKeepAliveIntervalMsecs",
9470 bgp->default_keepalive);
9471 }
9472 } else {
9473 /* Administrative shutdown. */
9474 if (CHECK_FLAG(p->flags, PEER_FLAG_SHUTDOWN))
9475 vty_out(vty, " Administratively shut down\n");
9476
9477 /* BGP Version. */
9478 vty_out(vty, " BGP version 4");
9479 vty_out(vty, ", remote router ID %s",
9480 inet_ntop(AF_INET, &p->remote_id, buf1, sizeof(buf1)));
9481 vty_out(vty, ", local router ID %s\n",
9482 inet_ntop(AF_INET, &bgp->router_id, buf1,
9483 sizeof(buf1)));
9484
9485 /* Confederation */
9486 if (CHECK_FLAG(bgp->config, BGP_CONFIG_CONFEDERATION)
9487 && bgp_confederation_peers_check(bgp, p->as))
9488 vty_out(vty,
9489 " Neighbor under common administration\n");
9490
9491 /* Status. */
9492 vty_out(vty, " BGP state = %s",
9493 lookup_msg(bgp_status_msg, p->status, NULL));
9494
9495 if (p->status == Established)
9496 vty_out(vty, ", up for %8s",
9497 peer_uptime(p->uptime, timebuf, BGP_UPTIME_LEN,
9498 0, NULL));
9499
9500 else if (p->status == Active) {
9501 if (CHECK_FLAG(p->flags, PEER_FLAG_PASSIVE))
9502 vty_out(vty, " (passive)");
9503 else if (CHECK_FLAG(p->sflags, PEER_STATUS_NSF_WAIT))
9504 vty_out(vty, " (NSF passive)");
9505 }
9506 vty_out(vty, "\n");
9507
9508 /* read timer */
9509 vty_out(vty, " Last read %s",
9510 peer_uptime(p->readtime, timebuf, BGP_UPTIME_LEN, 0,
9511 NULL));
9512 vty_out(vty, ", Last write %s\n",
9513 peer_uptime(p->last_write, timebuf, BGP_UPTIME_LEN, 0,
9514 NULL));
9515
9516 /* Configured timer values. */
9517 vty_out(vty,
9518 " Hold time is %d, keepalive interval is %d seconds\n",
9519 p->v_holdtime, p->v_keepalive);
9520 if (CHECK_FLAG(p->flags, PEER_FLAG_TIMER)) {
9521 vty_out(vty, " Configured hold time is %d",
9522 p->holdtime);
9523 vty_out(vty, ", keepalive interval is %d seconds\n",
9524 p->keepalive);
9525 } else if ((bgp->default_holdtime != BGP_DEFAULT_HOLDTIME)
9526 || (bgp->default_keepalive
9527 != BGP_DEFAULT_KEEPALIVE)) {
9528 vty_out(vty, " Configured hold time is %d",
9529 bgp->default_holdtime);
9530 vty_out(vty, ", keepalive interval is %d seconds\n",
9531 bgp->default_keepalive);
9532 }
9533 }
9534 /* Capability. */
9535 if (p->status == Established) {
9536 if (p->cap || p->afc_adv[AFI_IP][SAFI_UNICAST]
9537 || p->afc_recv[AFI_IP][SAFI_UNICAST]
9538 || p->afc_adv[AFI_IP][SAFI_MULTICAST]
9539 || p->afc_recv[AFI_IP][SAFI_MULTICAST]
9540 || p->afc_adv[AFI_IP6][SAFI_UNICAST]
9541 || p->afc_recv[AFI_IP6][SAFI_UNICAST]
9542 || p->afc_adv[AFI_IP6][SAFI_MULTICAST]
9543 || p->afc_recv[AFI_IP6][SAFI_MULTICAST]
9544 || p->afc_adv[AFI_IP6][SAFI_MPLS_VPN]
9545 || p->afc_recv[AFI_IP6][SAFI_MPLS_VPN]
9546 || p->afc_adv[AFI_IP6][SAFI_ENCAP]
9547 || p->afc_recv[AFI_IP6][SAFI_ENCAP]
9548 || p->afc_adv[AFI_IP6][SAFI_FLOWSPEC]
9549 || p->afc_recv[AFI_IP6][SAFI_FLOWSPEC]
9550 || p->afc_adv[AFI_IP][SAFI_ENCAP]
9551 || p->afc_recv[AFI_IP][SAFI_ENCAP]
9552 || p->afc_adv[AFI_IP][SAFI_FLOWSPEC]
9553 || p->afc_recv[AFI_IP][SAFI_FLOWSPEC]
9554 || p->afc_adv[AFI_IP][SAFI_MPLS_VPN]
9555 || p->afc_recv[AFI_IP][SAFI_MPLS_VPN]) {
9556 if (use_json) {
9557 json_object *json_cap = NULL;
9558
9559 json_cap = json_object_new_object();
9560
9561 /* AS4 */
9562 if (CHECK_FLAG(p->cap, PEER_CAP_AS4_RCV)
9563 || CHECK_FLAG(p->cap, PEER_CAP_AS4_ADV)) {
9564 if (CHECK_FLAG(p->cap, PEER_CAP_AS4_ADV)
9565 && CHECK_FLAG(p->cap,
9566 PEER_CAP_AS4_RCV))
9567 json_object_string_add(
9568 json_cap, "4byteAs",
9569 "advertisedAndReceived");
9570 else if (CHECK_FLAG(p->cap,
9571 PEER_CAP_AS4_ADV))
9572 json_object_string_add(
9573 json_cap, "4byteAs",
9574 "advertised");
9575 else if (CHECK_FLAG(p->cap,
9576 PEER_CAP_AS4_RCV))
9577 json_object_string_add(
9578 json_cap, "4byteAs",
9579 "received");
9580 }
9581
9582 /* AddPath */
9583 if (CHECK_FLAG(p->cap, PEER_CAP_ADDPATH_RCV)
9584 || CHECK_FLAG(p->cap,
9585 PEER_CAP_ADDPATH_ADV)) {
9586 json_object *json_add = NULL;
9587 const char *print_store;
9588
9589 json_add = json_object_new_object();
9590
9591 FOREACH_AFI_SAFI (afi, safi) {
9592 json_object *json_sub = NULL;
9593 json_sub =
9594 json_object_new_object();
9595 print_store = afi_safi_print(
9596 afi, safi);
9597
9598 if (CHECK_FLAG(
9599 p->af_cap[afi]
9600 [safi],
9601 PEER_CAP_ADDPATH_AF_TX_ADV)
9602 || CHECK_FLAG(
9603 p->af_cap[afi]
9604 [safi],
9605 PEER_CAP_ADDPATH_AF_TX_RCV)) {
9606 if (CHECK_FLAG(
9607 p->af_cap
9608 [afi]
9609 [safi],
9610 PEER_CAP_ADDPATH_AF_TX_ADV)
9611 && CHECK_FLAG(
9612 p->af_cap
9613 [afi]
9614 [safi],
9615 PEER_CAP_ADDPATH_AF_TX_RCV))
9616 json_object_boolean_true_add(
9617 json_sub,
9618 "txAdvertisedAndReceived");
9619 else if (
9620 CHECK_FLAG(
9621 p->af_cap
9622 [afi]
9623 [safi],
9624 PEER_CAP_ADDPATH_AF_TX_ADV))
9625 json_object_boolean_true_add(
9626 json_sub,
9627 "txAdvertised");
9628 else if (
9629 CHECK_FLAG(
9630 p->af_cap
9631 [afi]
9632 [safi],
9633 PEER_CAP_ADDPATH_AF_TX_RCV))
9634 json_object_boolean_true_add(
9635 json_sub,
9636 "txReceived");
9637 }
9638
9639 if (CHECK_FLAG(
9640 p->af_cap[afi]
9641 [safi],
9642 PEER_CAP_ADDPATH_AF_RX_ADV)
9643 || CHECK_FLAG(
9644 p->af_cap[afi]
9645 [safi],
9646 PEER_CAP_ADDPATH_AF_RX_RCV)) {
9647 if (CHECK_FLAG(
9648 p->af_cap
9649 [afi]
9650 [safi],
9651 PEER_CAP_ADDPATH_AF_RX_ADV)
9652 && CHECK_FLAG(
9653 p->af_cap
9654 [afi]
9655 [safi],
9656 PEER_CAP_ADDPATH_AF_RX_RCV))
9657 json_object_boolean_true_add(
9658 json_sub,
9659 "rxAdvertisedAndReceived");
9660 else if (
9661 CHECK_FLAG(
9662 p->af_cap
9663 [afi]
9664 [safi],
9665 PEER_CAP_ADDPATH_AF_RX_ADV))
9666 json_object_boolean_true_add(
9667 json_sub,
9668 "rxAdvertised");
9669 else if (
9670 CHECK_FLAG(
9671 p->af_cap
9672 [afi]
9673 [safi],
9674 PEER_CAP_ADDPATH_AF_RX_RCV))
9675 json_object_boolean_true_add(
9676 json_sub,
9677 "rxReceived");
9678 }
9679
9680 if (CHECK_FLAG(
9681 p->af_cap[afi]
9682 [safi],
9683 PEER_CAP_ADDPATH_AF_TX_ADV)
9684 || CHECK_FLAG(
9685 p->af_cap[afi]
9686 [safi],
9687 PEER_CAP_ADDPATH_AF_TX_RCV)
9688 || CHECK_FLAG(
9689 p->af_cap[afi]
9690 [safi],
9691 PEER_CAP_ADDPATH_AF_RX_ADV)
9692 || CHECK_FLAG(
9693 p->af_cap[afi]
9694 [safi],
9695 PEER_CAP_ADDPATH_AF_RX_RCV))
9696 json_object_object_add(
9697 json_add,
9698 print_store,
9699 json_sub);
9700 else
9701 json_object_free(
9702 json_sub);
9703 }
9704
9705 json_object_object_add(
9706 json_cap, "addPath", json_add);
9707 }
9708
9709 /* Dynamic */
9710 if (CHECK_FLAG(p->cap, PEER_CAP_DYNAMIC_RCV)
9711 || CHECK_FLAG(p->cap,
9712 PEER_CAP_DYNAMIC_ADV)) {
9713 if (CHECK_FLAG(p->cap,
9714 PEER_CAP_DYNAMIC_ADV)
9715 && CHECK_FLAG(p->cap,
9716 PEER_CAP_DYNAMIC_RCV))
9717 json_object_string_add(
9718 json_cap, "dynamic",
9719 "advertisedAndReceived");
9720 else if (CHECK_FLAG(
9721 p->cap,
9722 PEER_CAP_DYNAMIC_ADV))
9723 json_object_string_add(
9724 json_cap, "dynamic",
9725 "advertised");
9726 else if (CHECK_FLAG(
9727 p->cap,
9728 PEER_CAP_DYNAMIC_RCV))
9729 json_object_string_add(
9730 json_cap, "dynamic",
9731 "received");
9732 }
9733
9734 /* Extended nexthop */
9735 if (CHECK_FLAG(p->cap, PEER_CAP_ENHE_RCV)
9736 || CHECK_FLAG(p->cap, PEER_CAP_ENHE_ADV)) {
9737 json_object *json_nxt = NULL;
9738 const char *print_store;
9739
9740
9741 if (CHECK_FLAG(p->cap,
9742 PEER_CAP_ENHE_ADV)
9743 && CHECK_FLAG(p->cap,
9744 PEER_CAP_ENHE_RCV))
9745 json_object_string_add(
9746 json_cap,
9747 "extendedNexthop",
9748 "advertisedAndReceived");
9749 else if (CHECK_FLAG(p->cap,
9750 PEER_CAP_ENHE_ADV))
9751 json_object_string_add(
9752 json_cap,
9753 "extendedNexthop",
9754 "advertised");
9755 else if (CHECK_FLAG(p->cap,
9756 PEER_CAP_ENHE_RCV))
9757 json_object_string_add(
9758 json_cap,
9759 "extendedNexthop",
9760 "received");
9761
9762 if (CHECK_FLAG(p->cap,
9763 PEER_CAP_ENHE_RCV)) {
9764 json_nxt =
9765 json_object_new_object();
9766
9767 for (safi = SAFI_UNICAST;
9768 safi < SAFI_MAX; safi++) {
9769 if (CHECK_FLAG(
9770 p->af_cap
9771 [AFI_IP]
9772 [safi],
9773 PEER_CAP_ENHE_AF_RCV)) {
9774 print_store = afi_safi_print(
9775 AFI_IP,
9776 safi);
9777 json_object_string_add(
9778 json_nxt,
9779 print_store,
9780 "recieved"); /* misspelled for compatibility */
9781 }
9782 }
9783 json_object_object_add(
9784 json_cap,
9785 "extendedNexthopFamililesByPeer",
9786 json_nxt);
9787 }
9788 }
9789
9790 /* Route Refresh */
9791 if (CHECK_FLAG(p->cap, PEER_CAP_REFRESH_ADV)
9792 || CHECK_FLAG(p->cap,
9793 PEER_CAP_REFRESH_NEW_RCV)
9794 || CHECK_FLAG(p->cap,
9795 PEER_CAP_REFRESH_OLD_RCV)) {
9796 if (CHECK_FLAG(p->cap,
9797 PEER_CAP_REFRESH_ADV)
9798 && (CHECK_FLAG(
9799 p->cap,
9800 PEER_CAP_REFRESH_NEW_RCV)
9801 || CHECK_FLAG(
9802 p->cap,
9803 PEER_CAP_REFRESH_OLD_RCV))) {
9804 if (CHECK_FLAG(
9805 p->cap,
9806 PEER_CAP_REFRESH_OLD_RCV)
9807 && CHECK_FLAG(
9808 p->cap,
9809 PEER_CAP_REFRESH_NEW_RCV))
9810 json_object_string_add(
9811 json_cap,
9812 "routeRefresh",
9813 "advertisedAndReceivedOldNew");
9814 else {
9815 if (CHECK_FLAG(
9816 p->cap,
9817 PEER_CAP_REFRESH_OLD_RCV))
9818 json_object_string_add(
9819 json_cap,
9820 "routeRefresh",
9821 "advertisedAndReceivedOld");
9822 else
9823 json_object_string_add(
9824 json_cap,
9825 "routeRefresh",
9826 "advertisedAndReceivedNew");
9827 }
9828 } else if (
9829 CHECK_FLAG(
9830 p->cap,
9831 PEER_CAP_REFRESH_ADV))
9832 json_object_string_add(
9833 json_cap,
9834 "routeRefresh",
9835 "advertised");
9836 else if (
9837 CHECK_FLAG(
9838 p->cap,
9839 PEER_CAP_REFRESH_NEW_RCV)
9840 || CHECK_FLAG(
9841 p->cap,
9842 PEER_CAP_REFRESH_OLD_RCV))
9843 json_object_string_add(
9844 json_cap,
9845 "routeRefresh",
9846 "received");
9847 }
9848
9849 /* Multiprotocol Extensions */
9850 json_object *json_multi = NULL;
9851 json_multi = json_object_new_object();
9852
9853 FOREACH_AFI_SAFI (afi, safi) {
9854 if (p->afc_adv[afi][safi]
9855 || p->afc_recv[afi][safi]) {
9856 json_object *json_exten = NULL;
9857 json_exten =
9858 json_object_new_object();
9859
9860 if (p->afc_adv[afi][safi]
9861 && p->afc_recv[afi][safi])
9862 json_object_boolean_true_add(
9863 json_exten,
9864 "advertisedAndReceived");
9865 else if (p->afc_adv[afi][safi])
9866 json_object_boolean_true_add(
9867 json_exten,
9868 "advertised");
9869 else if (p->afc_recv[afi][safi])
9870 json_object_boolean_true_add(
9871 json_exten,
9872 "received");
9873
9874 json_object_object_add(
9875 json_multi,
9876 afi_safi_print(afi,
9877 safi),
9878 json_exten);
9879 }
9880 }
9881 json_object_object_add(
9882 json_cap, "multiprotocolExtensions",
9883 json_multi);
9884
9885 /* Hostname capabilities */
9886 json_object *json_hname = NULL;
9887
9888 json_hname = json_object_new_object();
9889
9890 if (CHECK_FLAG(p->cap, PEER_CAP_HOSTNAME_ADV)) {
9891 json_object_string_add(
9892 json_hname, "advHostName",
9893 bgp->peer_self->hostname
9894 ? bgp->peer_self
9895 ->hostname
9896 : "n/a");
9897 json_object_string_add(
9898 json_hname, "advDomainName",
9899 bgp->peer_self->domainname
9900 ? bgp->peer_self
9901 ->domainname
9902 : "n/a");
9903 }
9904
9905
9906 if (CHECK_FLAG(p->cap, PEER_CAP_HOSTNAME_RCV)) {
9907 json_object_string_add(
9908 json_hname, "rcvHostName",
9909 p->hostname ? p->hostname
9910 : "n/a");
9911 json_object_string_add(
9912 json_hname, "rcvDomainName",
9913 p->domainname ? p->domainname
9914 : "n/a");
9915 }
9916
9917 json_object_object_add(json_cap, "hostName",
9918 json_hname);
9919
9920 /* Gracefull Restart */
9921 if (CHECK_FLAG(p->cap, PEER_CAP_RESTART_RCV)
9922 || CHECK_FLAG(p->cap,
9923 PEER_CAP_RESTART_ADV)) {
9924 if (CHECK_FLAG(p->cap,
9925 PEER_CAP_RESTART_ADV)
9926 && CHECK_FLAG(p->cap,
9927 PEER_CAP_RESTART_RCV))
9928 json_object_string_add(
9929 json_cap,
9930 "gracefulRestart",
9931 "advertisedAndReceived");
9932 else if (CHECK_FLAG(
9933 p->cap,
9934 PEER_CAP_RESTART_ADV))
9935 json_object_string_add(
9936 json_cap,
9937 "gracefulRestartCapability",
9938 "advertised");
9939 else if (CHECK_FLAG(
9940 p->cap,
9941 PEER_CAP_RESTART_RCV))
9942 json_object_string_add(
9943 json_cap,
9944 "gracefulRestartCapability",
9945 "received");
9946
9947 if (CHECK_FLAG(p->cap,
9948 PEER_CAP_RESTART_RCV)) {
9949 int restart_af_count = 0;
9950 json_object *json_restart =
9951 NULL;
9952 json_restart =
9953 json_object_new_object();
9954
9955 json_object_int_add(
9956 json_cap,
9957 "gracefulRestartRemoteTimerMsecs",
9958 p->v_gr_restart * 1000);
9959
9960 FOREACH_AFI_SAFI (afi, safi) {
9961 if (CHECK_FLAG(
9962 p->af_cap
9963 [afi]
9964 [safi],
9965 PEER_CAP_RESTART_AF_RCV)) {
9966 json_object *
9967 json_sub =
9968 NULL;
9969 json_sub =
9970 json_object_new_object();
9971
9972 if (CHECK_FLAG(
9973 p->af_cap
9974 [afi]
9975 [safi],
9976 PEER_CAP_RESTART_AF_PRESERVE_RCV))
9977 json_object_boolean_true_add(
9978 json_sub,
9979 "preserved");
9980 restart_af_count++;
9981 json_object_object_add(
9982 json_restart,
9983 afi_safi_print(
9984 afi,
9985 safi),
9986 json_sub);
9987 }
9988 }
9989 if (!restart_af_count) {
9990 json_object_string_add(
9991 json_cap,
9992 "addressFamiliesByPeer",
9993 "none");
9994 json_object_free(
9995 json_restart);
9996 } else
9997 json_object_object_add(
9998 json_cap,
9999 "addressFamiliesByPeer",
10000 json_restart);
10001 }
10002 }
10003 json_object_object_add(json_neigh,
10004 "neighborCapabilities",
10005 json_cap);
10006 } else {
10007 vty_out(vty, " Neighbor capabilities:\n");
10008
10009 /* AS4 */
10010 if (CHECK_FLAG(p->cap, PEER_CAP_AS4_RCV)
10011 || CHECK_FLAG(p->cap, PEER_CAP_AS4_ADV)) {
10012 vty_out(vty, " 4 Byte AS:");
10013 if (CHECK_FLAG(p->cap,
10014 PEER_CAP_AS4_ADV))
10015 vty_out(vty, " advertised");
10016 if (CHECK_FLAG(p->cap,
10017 PEER_CAP_AS4_RCV))
10018 vty_out(vty, " %sreceived",
10019 CHECK_FLAG(
10020 p->cap,
10021 PEER_CAP_AS4_ADV)
10022 ? "and "
10023 : "");
10024 vty_out(vty, "\n");
10025 }
10026
10027 /* AddPath */
10028 if (CHECK_FLAG(p->cap, PEER_CAP_ADDPATH_RCV)
10029 || CHECK_FLAG(p->cap,
10030 PEER_CAP_ADDPATH_ADV)) {
10031 vty_out(vty, " AddPath:\n");
10032
10033 FOREACH_AFI_SAFI (afi, safi) {
10034 if (CHECK_FLAG(
10035 p->af_cap[afi]
10036 [safi],
10037 PEER_CAP_ADDPATH_AF_TX_ADV)
10038 || CHECK_FLAG(
10039 p->af_cap[afi]
10040 [safi],
10041 PEER_CAP_ADDPATH_AF_TX_RCV)) {
10042 vty_out(vty,
10043 " %s: TX ",
10044 afi_safi_print(
10045 afi,
10046 safi));
10047
10048 if (CHECK_FLAG(
10049 p->af_cap
10050 [afi]
10051 [safi],
10052 PEER_CAP_ADDPATH_AF_TX_ADV))
10053 vty_out(vty,
10054 "advertised %s",
10055 afi_safi_print(
10056 afi,
10057 safi));
10058
10059 if (CHECK_FLAG(
10060 p->af_cap
10061 [afi]
10062 [safi],
10063 PEER_CAP_ADDPATH_AF_TX_RCV))
10064 vty_out(vty,
10065 "%sreceived",
10066 CHECK_FLAG(
10067 p->af_cap
10068 [afi]
10069 [safi],
10070 PEER_CAP_ADDPATH_AF_TX_ADV)
10071 ? " and "
10072 : "");
10073
10074 vty_out(vty, "\n");
10075 }
10076
10077 if (CHECK_FLAG(
10078 p->af_cap[afi]
10079 [safi],
10080 PEER_CAP_ADDPATH_AF_RX_ADV)
10081 || CHECK_FLAG(
10082 p->af_cap[afi]
10083 [safi],
10084 PEER_CAP_ADDPATH_AF_RX_RCV)) {
10085 vty_out(vty,
10086 " %s: RX ",
10087 afi_safi_print(
10088 afi,
10089 safi));
10090
10091 if (CHECK_FLAG(
10092 p->af_cap
10093 [afi]
10094 [safi],
10095 PEER_CAP_ADDPATH_AF_RX_ADV))
10096 vty_out(vty,
10097 "advertised %s",
10098 afi_safi_print(
10099 afi,
10100 safi));
10101
10102 if (CHECK_FLAG(
10103 p->af_cap
10104 [afi]
10105 [safi],
10106 PEER_CAP_ADDPATH_AF_RX_RCV))
10107 vty_out(vty,
10108 "%sreceived",
10109 CHECK_FLAG(
10110 p->af_cap
10111 [afi]
10112 [safi],
10113 PEER_CAP_ADDPATH_AF_RX_ADV)
10114 ? " and "
10115 : "");
10116
10117 vty_out(vty, "\n");
10118 }
10119 }
10120 }
10121
10122 /* Dynamic */
10123 if (CHECK_FLAG(p->cap, PEER_CAP_DYNAMIC_RCV)
10124 || CHECK_FLAG(p->cap,
10125 PEER_CAP_DYNAMIC_ADV)) {
10126 vty_out(vty, " Dynamic:");
10127 if (CHECK_FLAG(p->cap,
10128 PEER_CAP_DYNAMIC_ADV))
10129 vty_out(vty, " advertised");
10130 if (CHECK_FLAG(p->cap,
10131 PEER_CAP_DYNAMIC_RCV))
10132 vty_out(vty, " %sreceived",
10133 CHECK_FLAG(
10134 p->cap,
10135 PEER_CAP_DYNAMIC_ADV)
10136 ? "and "
10137 : "");
10138 vty_out(vty, "\n");
10139 }
10140
10141 /* Extended nexthop */
10142 if (CHECK_FLAG(p->cap, PEER_CAP_ENHE_RCV)
10143 || CHECK_FLAG(p->cap, PEER_CAP_ENHE_ADV)) {
10144 vty_out(vty, " Extended nexthop:");
10145 if (CHECK_FLAG(p->cap,
10146 PEER_CAP_ENHE_ADV))
10147 vty_out(vty, " advertised");
10148 if (CHECK_FLAG(p->cap,
10149 PEER_CAP_ENHE_RCV))
10150 vty_out(vty, " %sreceived",
10151 CHECK_FLAG(
10152 p->cap,
10153 PEER_CAP_ENHE_ADV)
10154 ? "and "
10155 : "");
10156 vty_out(vty, "\n");
10157
10158 if (CHECK_FLAG(p->cap,
10159 PEER_CAP_ENHE_RCV)) {
10160 vty_out(vty,
10161 " Address families by peer:\n ");
10162 for (safi = SAFI_UNICAST;
10163 safi < SAFI_MAX; safi++)
10164 if (CHECK_FLAG(
10165 p->af_cap
10166 [AFI_IP]
10167 [safi],
10168 PEER_CAP_ENHE_AF_RCV))
10169 vty_out(vty,
10170 " %s\n",
10171 afi_safi_print(
10172 AFI_IP,
10173 safi));
10174 }
10175 }
10176
10177 /* Route Refresh */
10178 if (CHECK_FLAG(p->cap, PEER_CAP_REFRESH_ADV)
10179 || CHECK_FLAG(p->cap,
10180 PEER_CAP_REFRESH_NEW_RCV)
10181 || CHECK_FLAG(p->cap,
10182 PEER_CAP_REFRESH_OLD_RCV)) {
10183 vty_out(vty, " Route refresh:");
10184 if (CHECK_FLAG(p->cap,
10185 PEER_CAP_REFRESH_ADV))
10186 vty_out(vty, " advertised");
10187 if (CHECK_FLAG(p->cap,
10188 PEER_CAP_REFRESH_NEW_RCV)
10189 || CHECK_FLAG(
10190 p->cap,
10191 PEER_CAP_REFRESH_OLD_RCV))
10192 vty_out(vty, " %sreceived(%s)",
10193 CHECK_FLAG(
10194 p->cap,
10195 PEER_CAP_REFRESH_ADV)
10196 ? "and "
10197 : "",
10198 (CHECK_FLAG(
10199 p->cap,
10200 PEER_CAP_REFRESH_OLD_RCV)
10201 && CHECK_FLAG(
10202 p->cap,
10203 PEER_CAP_REFRESH_NEW_RCV))
10204 ? "old & new"
10205 : CHECK_FLAG(
10206 p->cap,
10207 PEER_CAP_REFRESH_OLD_RCV)
10208 ? "old"
10209 : "new");
10210
10211 vty_out(vty, "\n");
10212 }
10213
10214 /* Multiprotocol Extensions */
10215 FOREACH_AFI_SAFI (afi, safi)
10216 if (p->afc_adv[afi][safi]
10217 || p->afc_recv[afi][safi]) {
10218 vty_out(vty,
10219 " Address Family %s:",
10220 afi_safi_print(afi,
10221 safi));
10222 if (p->afc_adv[afi][safi])
10223 vty_out(vty,
10224 " advertised");
10225 if (p->afc_recv[afi][safi])
10226 vty_out(vty,
10227 " %sreceived",
10228 p->afc_adv[afi]
10229 [safi]
10230 ? "and "
10231 : "");
10232 vty_out(vty, "\n");
10233 }
10234
10235 /* Hostname capability */
10236 vty_out(vty, " Hostname Capability:");
10237
10238 if (CHECK_FLAG(p->cap, PEER_CAP_HOSTNAME_ADV)) {
10239 vty_out(vty,
10240 " advertised (name: %s,domain name: %s)",
10241 bgp->peer_self->hostname
10242 ? bgp->peer_self
10243 ->hostname
10244 : "n/a",
10245 bgp->peer_self->domainname
10246 ? bgp->peer_self
10247 ->domainname
10248 : "n/a");
10249 } else {
10250 vty_out(vty, " not advertised");
10251 }
10252
10253 if (CHECK_FLAG(p->cap, PEER_CAP_HOSTNAME_RCV)) {
10254 vty_out(vty,
10255 " received (name: %s,domain name: %s)",
10256 p->hostname ? p->hostname
10257 : "n/a",
10258 p->domainname ? p->domainname
10259 : "n/a");
10260 } else {
10261 vty_out(vty, " not received");
10262 }
10263
10264 vty_out(vty, "\n");
10265
10266 /* Gracefull Restart */
10267 if (CHECK_FLAG(p->cap, PEER_CAP_RESTART_RCV)
10268 || CHECK_FLAG(p->cap,
10269 PEER_CAP_RESTART_ADV)) {
10270 vty_out(vty,
10271 " Graceful Restart Capabilty:");
10272 if (CHECK_FLAG(p->cap,
10273 PEER_CAP_RESTART_ADV))
10274 vty_out(vty, " advertised");
10275 if (CHECK_FLAG(p->cap,
10276 PEER_CAP_RESTART_RCV))
10277 vty_out(vty, " %sreceived",
10278 CHECK_FLAG(
10279 p->cap,
10280 PEER_CAP_RESTART_ADV)
10281 ? "and "
10282 : "");
10283 vty_out(vty, "\n");
10284
10285 if (CHECK_FLAG(p->cap,
10286 PEER_CAP_RESTART_RCV)) {
10287 int restart_af_count = 0;
10288
10289 vty_out(vty,
10290 " Remote Restart timer is %d seconds\n",
10291 p->v_gr_restart);
10292 vty_out(vty,
10293 " Address families by peer:\n ");
10294
10295 FOREACH_AFI_SAFI (afi, safi)
10296 if (CHECK_FLAG(
10297 p->af_cap
10298 [afi]
10299 [safi],
10300 PEER_CAP_RESTART_AF_RCV)) {
10301 vty_out(vty,
10302 "%s%s(%s)",
10303 restart_af_count
10304 ? ", "
10305 : "",
10306 afi_safi_print(
10307 afi,
10308 safi),
10309 CHECK_FLAG(
10310 p->af_cap
10311 [afi]
10312 [safi],
10313 PEER_CAP_RESTART_AF_PRESERVE_RCV)
10314 ? "preserved"
10315 : "not preserved");
10316 restart_af_count++;
10317 }
10318 if (!restart_af_count)
10319 vty_out(vty, "none");
10320 vty_out(vty, "\n");
10321 }
10322 }
10323 }
10324 }
10325 }
10326
10327 /* graceful restart information */
10328 if (CHECK_FLAG(p->cap, PEER_CAP_RESTART_RCV) || p->t_gr_restart
10329 || p->t_gr_stale) {
10330 json_object *json_grace = NULL;
10331 json_object *json_grace_send = NULL;
10332 json_object *json_grace_recv = NULL;
10333 int eor_send_af_count = 0;
10334 int eor_receive_af_count = 0;
10335
10336 if (use_json) {
10337 json_grace = json_object_new_object();
10338 json_grace_send = json_object_new_object();
10339 json_grace_recv = json_object_new_object();
10340
10341 if (p->status == Established) {
10342 FOREACH_AFI_SAFI (afi, safi) {
10343 if (CHECK_FLAG(p->af_sflags[afi][safi],
10344 PEER_STATUS_EOR_SEND)) {
10345 json_object_boolean_true_add(
10346 json_grace_send,
10347 afi_safi_print(afi,
10348 safi));
10349 eor_send_af_count++;
10350 }
10351 }
10352 FOREACH_AFI_SAFI (afi, safi) {
10353 if (CHECK_FLAG(
10354 p->af_sflags[afi][safi],
10355 PEER_STATUS_EOR_RECEIVED)) {
10356 json_object_boolean_true_add(
10357 json_grace_recv,
10358 afi_safi_print(afi,
10359 safi));
10360 eor_receive_af_count++;
10361 }
10362 }
10363 }
10364
10365 json_object_object_add(json_grace, "endOfRibSend",
10366 json_grace_send);
10367 json_object_object_add(json_grace, "endOfRibRecv",
10368 json_grace_recv);
10369
10370 if (p->t_gr_restart)
10371 json_object_int_add(json_grace,
10372 "gracefulRestartTimerMsecs",
10373 thread_timer_remain_second(
10374 p->t_gr_restart)
10375 * 1000);
10376
10377 if (p->t_gr_stale)
10378 json_object_int_add(
10379 json_grace,
10380 "gracefulStalepathTimerMsecs",
10381 thread_timer_remain_second(
10382 p->t_gr_stale)
10383 * 1000);
10384
10385 json_object_object_add(
10386 json_neigh, "gracefulRestartInfo", json_grace);
10387 } else {
10388 vty_out(vty, " Graceful restart information:\n");
10389 if (p->status == Established) {
10390 vty_out(vty, " End-of-RIB send: ");
10391 FOREACH_AFI_SAFI (afi, safi) {
10392 if (CHECK_FLAG(p->af_sflags[afi][safi],
10393 PEER_STATUS_EOR_SEND)) {
10394 vty_out(vty, "%s%s",
10395 eor_send_af_count ? ", "
10396 : "",
10397 afi_safi_print(afi,
10398 safi));
10399 eor_send_af_count++;
10400 }
10401 }
10402 vty_out(vty, "\n");
10403 vty_out(vty, " End-of-RIB received: ");
10404 FOREACH_AFI_SAFI (afi, safi) {
10405 if (CHECK_FLAG(
10406 p->af_sflags[afi][safi],
10407 PEER_STATUS_EOR_RECEIVED)) {
10408 vty_out(vty, "%s%s",
10409 eor_receive_af_count
10410 ? ", "
10411 : "",
10412 afi_safi_print(afi,
10413 safi));
10414 eor_receive_af_count++;
10415 }
10416 }
10417 vty_out(vty, "\n");
10418 }
10419
10420 if (p->t_gr_restart)
10421 vty_out(vty,
10422 " The remaining time of restart timer is %ld\n",
10423 thread_timer_remain_second(
10424 p->t_gr_restart));
10425
10426 if (p->t_gr_stale)
10427 vty_out(vty,
10428 " The remaining time of stalepath timer is %ld\n",
10429 thread_timer_remain_second(
10430 p->t_gr_stale));
10431 }
10432 }
10433 if (use_json) {
10434 json_object *json_stat = NULL;
10435 json_stat = json_object_new_object();
10436 /* Packet counts. */
10437 json_object_int_add(json_stat, "depthInq", 0);
10438 json_object_int_add(json_stat, "depthOutq",
10439 (unsigned long)p->obuf->count);
10440 json_object_int_add(json_stat, "opensSent",
10441 atomic_load_explicit(&p->open_out,
10442 memory_order_relaxed));
10443 json_object_int_add(json_stat, "opensRecv",
10444 atomic_load_explicit(&p->open_in,
10445 memory_order_relaxed));
10446 json_object_int_add(json_stat, "notificationsSent",
10447 atomic_load_explicit(&p->notify_out,
10448 memory_order_relaxed));
10449 json_object_int_add(json_stat, "notificationsRecv",
10450 atomic_load_explicit(&p->notify_in,
10451 memory_order_relaxed));
10452 json_object_int_add(json_stat, "updatesSent",
10453 atomic_load_explicit(&p->update_out,
10454 memory_order_relaxed));
10455 json_object_int_add(json_stat, "updatesRecv",
10456 atomic_load_explicit(&p->update_in,
10457 memory_order_relaxed));
10458 json_object_int_add(json_stat, "keepalivesSent",
10459 atomic_load_explicit(&p->keepalive_out,
10460 memory_order_relaxed));
10461 json_object_int_add(json_stat, "keepalivesRecv",
10462 atomic_load_explicit(&p->keepalive_in,
10463 memory_order_relaxed));
10464 json_object_int_add(json_stat, "routeRefreshSent",
10465 atomic_load_explicit(&p->refresh_out,
10466 memory_order_relaxed));
10467 json_object_int_add(json_stat, "routeRefreshRecv",
10468 atomic_load_explicit(&p->refresh_in,
10469 memory_order_relaxed));
10470 json_object_int_add(json_stat, "capabilitySent",
10471 atomic_load_explicit(&p->dynamic_cap_out,
10472 memory_order_relaxed));
10473 json_object_int_add(json_stat, "capabilityRecv",
10474 atomic_load_explicit(&p->dynamic_cap_in,
10475 memory_order_relaxed));
10476 json_object_int_add(json_stat, "totalSent", PEER_TOTAL_TX(p));
10477 json_object_int_add(json_stat, "totalRecv", PEER_TOTAL_RX(p));
10478 json_object_object_add(json_neigh, "messageStats", json_stat);
10479 } else {
10480 /* Packet counts. */
10481 vty_out(vty, " Message statistics:\n");
10482 vty_out(vty, " Inq depth is 0\n");
10483 vty_out(vty, " Outq depth is %lu\n",
10484 (unsigned long)p->obuf->count);
10485 vty_out(vty, " Sent Rcvd\n");
10486 vty_out(vty, " Opens: %10d %10d\n",
10487 atomic_load_explicit(&p->open_out,
10488 memory_order_relaxed),
10489 atomic_load_explicit(&p->open_in,
10490 memory_order_relaxed));
10491 vty_out(vty, " Notifications: %10d %10d\n",
10492 atomic_load_explicit(&p->notify_out,
10493 memory_order_relaxed),
10494 atomic_load_explicit(&p->notify_in,
10495 memory_order_relaxed));
10496 vty_out(vty, " Updates: %10d %10d\n",
10497 atomic_load_explicit(&p->update_out,
10498 memory_order_relaxed),
10499 atomic_load_explicit(&p->update_in,
10500 memory_order_relaxed));
10501 vty_out(vty, " Keepalives: %10d %10d\n",
10502 atomic_load_explicit(&p->keepalive_out,
10503 memory_order_relaxed),
10504 atomic_load_explicit(&p->keepalive_in,
10505 memory_order_relaxed));
10506 vty_out(vty, " Route Refresh: %10d %10d\n",
10507 atomic_load_explicit(&p->refresh_out,
10508 memory_order_relaxed),
10509 atomic_load_explicit(&p->refresh_in,
10510 memory_order_relaxed));
10511 vty_out(vty, " Capability: %10d %10d\n",
10512 atomic_load_explicit(&p->dynamic_cap_out,
10513 memory_order_relaxed),
10514 atomic_load_explicit(&p->dynamic_cap_in,
10515 memory_order_relaxed));
10516 vty_out(vty, " Total: %10d %10d\n", PEER_TOTAL_TX(p),
10517 PEER_TOTAL_RX(p));
10518 }
10519
10520 if (use_json) {
10521 /* advertisement-interval */
10522 json_object_int_add(json_neigh,
10523 "minBtwnAdvertisementRunsTimerMsecs",
10524 p->v_routeadv * 1000);
10525
10526 /* Update-source. */
10527 if (p->update_if || p->update_source) {
10528 if (p->update_if)
10529 json_object_string_add(json_neigh,
10530 "updateSource",
10531 p->update_if);
10532 else if (p->update_source)
10533 json_object_string_add(
10534 json_neigh, "updateSource",
10535 sockunion2str(p->update_source, buf1,
10536 SU_ADDRSTRLEN));
10537 }
10538 } else {
10539 /* advertisement-interval */
10540 vty_out(vty,
10541 " Minimum time between advertisement runs is %d seconds\n",
10542 p->v_routeadv);
10543
10544 /* Update-source. */
10545 if (p->update_if || p->update_source) {
10546 vty_out(vty, " Update source is ");
10547 if (p->update_if)
10548 vty_out(vty, "%s", p->update_if);
10549 else if (p->update_source)
10550 vty_out(vty, "%s",
10551 sockunion2str(p->update_source, buf1,
10552 SU_ADDRSTRLEN));
10553 vty_out(vty, "\n");
10554 }
10555
10556 vty_out(vty, "\n");
10557 }
10558
10559 /* Address Family Information */
10560 json_object *json_hold = NULL;
10561
10562 if (use_json)
10563 json_hold = json_object_new_object();
10564
10565 FOREACH_AFI_SAFI (afi, safi)
10566 if (p->afc[afi][safi])
10567 bgp_show_peer_afi(vty, p, afi, safi, use_json,
10568 json_hold);
10569
10570 if (use_json) {
10571 json_object_object_add(json_neigh, "addressFamilyInfo",
10572 json_hold);
10573 json_object_int_add(json_neigh, "connectionsEstablished",
10574 p->established);
10575 json_object_int_add(json_neigh, "connectionsDropped",
10576 p->dropped);
10577 } else
10578 vty_out(vty, " Connections established %d; dropped %d\n",
10579 p->established, p->dropped);
10580
10581 if (!p->last_reset) {
10582 if (use_json)
10583 json_object_string_add(json_neigh, "lastReset",
10584 "never");
10585 else
10586 vty_out(vty, " Last reset never\n");
10587 } else {
10588 if (use_json) {
10589 time_t uptime;
10590 struct tm *tm;
10591
10592 uptime = bgp_clock();
10593 uptime -= p->resettime;
10594 tm = gmtime(&uptime);
10595 json_object_int_add(json_neigh, "lastResetTimerMsecs",
10596 (tm->tm_sec * 1000)
10597 + (tm->tm_min * 60000)
10598 + (tm->tm_hour * 3600000));
10599 json_object_string_add(
10600 json_neigh, "lastResetDueTo",
10601 peer_down_str[(int)p->last_reset]);
10602 if (p->last_reset == PEER_DOWN_NOTIFY_SEND
10603 || p->last_reset == PEER_DOWN_NOTIFY_RECEIVED) {
10604 char errorcodesubcode_hexstr[5];
10605 char errorcodesubcode_str[256];
10606
10607 code_str = bgp_notify_code_str(p->notify.code);
10608 subcode_str = bgp_notify_subcode_str(
10609 p->notify.code, p->notify.subcode);
10610
10611 sprintf(errorcodesubcode_hexstr, "%02X%02X",
10612 p->notify.code, p->notify.subcode);
10613 json_object_string_add(json_neigh,
10614 "lastErrorCodeSubcode",
10615 errorcodesubcode_hexstr);
10616 snprintf(errorcodesubcode_str, 255, "%s%s",
10617 code_str, subcode_str);
10618 json_object_string_add(json_neigh,
10619 "lastNotificationReason",
10620 errorcodesubcode_str);
10621 if (p->last_reset == PEER_DOWN_NOTIFY_RECEIVED
10622 && p->notify.code == BGP_NOTIFY_CEASE
10623 && (p->notify.subcode
10624 == BGP_NOTIFY_CEASE_ADMIN_SHUTDOWN
10625 || p->notify.subcode
10626 == BGP_NOTIFY_CEASE_ADMIN_RESET)
10627 && p->notify.length) {
10628 char msgbuf[1024];
10629 const char *msg_str;
10630
10631 msg_str = bgp_notify_admin_message(
10632 msgbuf, sizeof(msgbuf),
10633 (uint8_t *)p->notify.data,
10634 p->notify.length);
10635 if (msg_str)
10636 json_object_string_add(
10637 json_neigh,
10638 "lastShutdownDescription",
10639 msg_str);
10640 }
10641 }
10642 } else {
10643 vty_out(vty, " Last reset %s, ",
10644 peer_uptime(p->resettime, timebuf,
10645 BGP_UPTIME_LEN, 0, NULL));
10646
10647 if (p->last_reset == PEER_DOWN_NOTIFY_SEND
10648 || p->last_reset == PEER_DOWN_NOTIFY_RECEIVED) {
10649 code_str = bgp_notify_code_str(p->notify.code);
10650 subcode_str = bgp_notify_subcode_str(
10651 p->notify.code, p->notify.subcode);
10652 vty_out(vty, "due to NOTIFICATION %s (%s%s)\n",
10653 p->last_reset == PEER_DOWN_NOTIFY_SEND
10654 ? "sent"
10655 : "received",
10656 code_str, subcode_str);
10657 if (p->last_reset == PEER_DOWN_NOTIFY_RECEIVED
10658 && p->notify.code == BGP_NOTIFY_CEASE
10659 && (p->notify.subcode
10660 == BGP_NOTIFY_CEASE_ADMIN_SHUTDOWN
10661 || p->notify.subcode
10662 == BGP_NOTIFY_CEASE_ADMIN_RESET)
10663 && p->notify.length) {
10664 char msgbuf[1024];
10665 const char *msg_str;
10666
10667 msg_str = bgp_notify_admin_message(
10668 msgbuf, sizeof(msgbuf),
10669 (uint8_t *)p->notify.data,
10670 p->notify.length);
10671 if (msg_str)
10672 vty_out(vty,
10673 " Message: \"%s\"\n",
10674 msg_str);
10675 }
10676 } else {
10677 vty_out(vty, "due to %s\n",
10678 peer_down_str[(int)p->last_reset]);
10679 }
10680
10681 if (p->last_reset_cause_size) {
10682 msg = p->last_reset_cause;
10683 vty_out(vty,
10684 " Message received that caused BGP to send a NOTIFICATION:\n ");
10685 for (i = 1; i <= p->last_reset_cause_size;
10686 i++) {
10687 vty_out(vty, "%02X", *msg++);
10688
10689 if (i != p->last_reset_cause_size) {
10690 if (i % 16 == 0) {
10691 vty_out(vty, "\n ");
10692 } else if (i % 4 == 0) {
10693 vty_out(vty, " ");
10694 }
10695 }
10696 }
10697 vty_out(vty, "\n");
10698 }
10699 }
10700 }
10701
10702 if (CHECK_FLAG(p->sflags, PEER_STATUS_PREFIX_OVERFLOW)) {
10703 if (use_json)
10704 json_object_boolean_true_add(json_neigh,
10705 "prefixesConfigExceedMax");
10706 else
10707 vty_out(vty,
10708 " Peer had exceeded the max. no. of prefixes configured.\n");
10709
10710 if (p->t_pmax_restart) {
10711 if (use_json) {
10712 json_object_boolean_true_add(
10713 json_neigh, "reducePrefixNumFrom");
10714 json_object_int_add(json_neigh,
10715 "restartInTimerMsec",
10716 thread_timer_remain_second(
10717 p->t_pmax_restart)
10718 * 1000);
10719 } else
10720 vty_out(vty,
10721 " Reduce the no. of prefix from %s, will restart in %ld seconds\n",
10722 p->host, thread_timer_remain_second(
10723 p->t_pmax_restart));
10724 } else {
10725 if (use_json)
10726 json_object_boolean_true_add(
10727 json_neigh,
10728 "reducePrefixNumAndClearIpBgp");
10729 else
10730 vty_out(vty,
10731 " Reduce the no. of prefix and clear ip bgp %s to restore peering\n",
10732 p->host);
10733 }
10734 }
10735
10736 /* EBGP Multihop and GTSM */
10737 if (p->sort != BGP_PEER_IBGP) {
10738 if (use_json) {
10739 if (p->gtsm_hops > 0)
10740 json_object_int_add(json_neigh,
10741 "externalBgpNbrMaxHopsAway",
10742 p->gtsm_hops);
10743 else if (p->ttl > 1)
10744 json_object_int_add(json_neigh,
10745 "externalBgpNbrMaxHopsAway",
10746 p->ttl);
10747 } else {
10748 if (p->gtsm_hops > 0)
10749 vty_out(vty,
10750 " External BGP neighbor may be up to %d hops away.\n",
10751 p->gtsm_hops);
10752 else if (p->ttl > 1)
10753 vty_out(vty,
10754 " External BGP neighbor may be up to %d hops away.\n",
10755 p->ttl);
10756 }
10757 } else {
10758 if (p->gtsm_hops > 0) {
10759 if (use_json)
10760 json_object_int_add(json_neigh,
10761 "internalBgpNbrMaxHopsAway",
10762 p->gtsm_hops);
10763 else
10764 vty_out(vty,
10765 " Internal BGP neighbor may be up to %d hops away.\n",
10766 p->gtsm_hops);
10767 }
10768 }
10769
10770 /* Local address. */
10771 if (p->su_local) {
10772 if (use_json) {
10773 json_object_string_add(json_neigh, "hostLocal",
10774 sockunion2str(p->su_local, buf1,
10775 SU_ADDRSTRLEN));
10776 json_object_int_add(json_neigh, "portLocal",
10777 ntohs(p->su_local->sin.sin_port));
10778 } else
10779 vty_out(vty, "Local host: %s, Local port: %d\n",
10780 sockunion2str(p->su_local, buf1, SU_ADDRSTRLEN),
10781 ntohs(p->su_local->sin.sin_port));
10782 }
10783
10784 /* Remote address. */
10785 if (p->su_remote) {
10786 if (use_json) {
10787 json_object_string_add(json_neigh, "hostForeign",
10788 sockunion2str(p->su_remote, buf1,
10789 SU_ADDRSTRLEN));
10790 json_object_int_add(json_neigh, "portForeign",
10791 ntohs(p->su_remote->sin.sin_port));
10792 } else
10793 vty_out(vty, "Foreign host: %s, Foreign port: %d\n",
10794 sockunion2str(p->su_remote, buf1,
10795 SU_ADDRSTRLEN),
10796 ntohs(p->su_remote->sin.sin_port));
10797 }
10798
10799 /* Nexthop display. */
10800 if (p->su_local) {
10801 if (use_json) {
10802 json_object_string_add(json_neigh, "nexthop",
10803 inet_ntop(AF_INET,
10804 &p->nexthop.v4, buf1,
10805 sizeof(buf1)));
10806 json_object_string_add(json_neigh, "nexthopGlobal",
10807 inet_ntop(AF_INET6,
10808 &p->nexthop.v6_global,
10809 buf1, sizeof(buf1)));
10810 json_object_string_add(json_neigh, "nexthopLocal",
10811 inet_ntop(AF_INET6,
10812 &p->nexthop.v6_local,
10813 buf1, sizeof(buf1)));
10814 if (p->shared_network)
10815 json_object_string_add(json_neigh,
10816 "bgpConnection",
10817 "sharedNetwork");
10818 else
10819 json_object_string_add(json_neigh,
10820 "bgpConnection",
10821 "nonSharedNetwork");
10822 } else {
10823 vty_out(vty, "Nexthop: %s\n",
10824 inet_ntop(AF_INET, &p->nexthop.v4, buf1,
10825 sizeof(buf1)));
10826 vty_out(vty, "Nexthop global: %s\n",
10827 inet_ntop(AF_INET6, &p->nexthop.v6_global, buf1,
10828 sizeof(buf1)));
10829 vty_out(vty, "Nexthop local: %s\n",
10830 inet_ntop(AF_INET6, &p->nexthop.v6_local, buf1,
10831 sizeof(buf1)));
10832 vty_out(vty, "BGP connection: %s\n",
10833 p->shared_network ? "shared network"
10834 : "non shared network");
10835 }
10836 }
10837
10838 /* Timer information. */
10839 if (use_json) {
10840 json_object_int_add(json_neigh, "connectRetryTimer",
10841 p->v_connect);
10842 if (p->status == Established && p->rtt)
10843 json_object_int_add(json_neigh, "estimatedRttInMsecs",
10844 p->rtt);
10845 if (p->t_start)
10846 json_object_int_add(
10847 json_neigh, "nextStartTimerDueInMsecs",
10848 thread_timer_remain_second(p->t_start) * 1000);
10849 if (p->t_connect)
10850 json_object_int_add(
10851 json_neigh, "nextConnectTimerDueInMsecs",
10852 thread_timer_remain_second(p->t_connect)
10853 * 1000);
10854 if (p->t_routeadv) {
10855 json_object_int_add(json_neigh, "mraiInterval",
10856 p->v_routeadv);
10857 json_object_int_add(
10858 json_neigh, "mraiTimerExpireInMsecs",
10859 thread_timer_remain_second(p->t_routeadv)
10860 * 1000);
10861 }
10862 if (p->password)
10863 json_object_int_add(json_neigh, "authenticationEnabled",
10864 1);
10865
10866 if (p->t_read)
10867 json_object_string_add(json_neigh, "readThread", "on");
10868 else
10869 json_object_string_add(json_neigh, "readThread", "off");
10870
10871 if (CHECK_FLAG(p->thread_flags, PEER_THREAD_WRITES_ON))
10872 json_object_string_add(json_neigh, "writeThread", "on");
10873 else
10874 json_object_string_add(json_neigh, "writeThread",
10875 "off");
10876 } else {
10877 vty_out(vty, "BGP Connect Retry Timer in Seconds: %d\n",
10878 p->v_connect);
10879 if (p->status == Established && p->rtt)
10880 vty_out(vty, "Estimated round trip time: %d ms\n",
10881 p->rtt);
10882 if (p->t_start)
10883 vty_out(vty, "Next start timer due in %ld seconds\n",
10884 thread_timer_remain_second(p->t_start));
10885 if (p->t_connect)
10886 vty_out(vty, "Next connect timer due in %ld seconds\n",
10887 thread_timer_remain_second(p->t_connect));
10888 if (p->t_routeadv)
10889 vty_out(vty,
10890 "MRAI (interval %u) timer expires in %ld seconds\n",
10891 p->v_routeadv,
10892 thread_timer_remain_second(p->t_routeadv));
10893 if (p->password)
10894 vty_out(vty, "Peer Authentication Enabled\n");
10895
10896 vty_out(vty, "Read thread: %s Write thread: %s\n",
10897 p->t_read ? "on" : "off",
10898 CHECK_FLAG(p->thread_flags, PEER_THREAD_WRITES_ON)
10899 ? "on"
10900 : "off");
10901 }
10902
10903 if (p->notify.code == BGP_NOTIFY_OPEN_ERR
10904 && p->notify.subcode == BGP_NOTIFY_OPEN_UNSUP_CAPBL)
10905 bgp_capability_vty_out(vty, p, use_json, json_neigh);
10906
10907 if (!use_json)
10908 vty_out(vty, "\n");
10909
10910 /* BFD information. */
10911 bgp_bfd_show_info(vty, p, use_json, json_neigh);
10912
10913 if (use_json) {
10914 if (p->conf_if) /* Configured interface name. */
10915 json_object_object_add(json, p->conf_if, json_neigh);
10916 else /* Configured IP address. */
10917 json_object_object_add(json, p->host, json_neigh);
10918 }
10919 }
10920
10921 static int bgp_show_neighbor(struct vty *vty, struct bgp *bgp,
10922 enum show_type type, union sockunion *su,
10923 const char *conf_if, bool use_json,
10924 json_object *json)
10925 {
10926 struct listnode *node, *nnode;
10927 struct peer *peer;
10928 int find = 0;
10929 bool nbr_output = false;
10930 afi_t afi = AFI_MAX;
10931 safi_t safi = SAFI_MAX;
10932
10933 if (type == show_ipv4_peer || type == show_ipv4_all) {
10934 afi = AFI_IP;
10935 } else if (type == show_ipv6_peer || type == show_ipv6_all) {
10936 afi = AFI_IP6;
10937 }
10938
10939 for (ALL_LIST_ELEMENTS(bgp->peer, node, nnode, peer)) {
10940 if (!CHECK_FLAG(peer->flags, PEER_FLAG_CONFIG_NODE))
10941 continue;
10942
10943 switch (type) {
10944 case show_all:
10945 bgp_show_peer(vty, peer, use_json, json);
10946 nbr_output = true;
10947 break;
10948 case show_peer:
10949 if (conf_if) {
10950 if ((peer->conf_if
10951 && !strcmp(peer->conf_if, conf_if))
10952 || (peer->hostname
10953 && !strcmp(peer->hostname, conf_if))) {
10954 find = 1;
10955 bgp_show_peer(vty, peer, use_json,
10956 json);
10957 }
10958 } else {
10959 if (sockunion_same(&peer->su, su)) {
10960 find = 1;
10961 bgp_show_peer(vty, peer, use_json,
10962 json);
10963 }
10964 }
10965 break;
10966 case show_ipv4_peer:
10967 case show_ipv6_peer:
10968 FOREACH_SAFI (safi) {
10969 if (peer->afc[afi][safi]) {
10970 if (conf_if) {
10971 if ((peer->conf_if
10972 && !strcmp(peer->conf_if, conf_if))
10973 || (peer->hostname
10974 && !strcmp(peer->hostname, conf_if))) {
10975 find = 1;
10976 bgp_show_peer(vty, peer, use_json,
10977 json);
10978 break;
10979 }
10980 } else {
10981 if (sockunion_same(&peer->su, su)) {
10982 find = 1;
10983 bgp_show_peer(vty, peer, use_json,
10984 json);
10985 break;
10986 }
10987 }
10988 }
10989 }
10990 break;
10991 case show_ipv4_all:
10992 case show_ipv6_all:
10993 FOREACH_SAFI (safi) {
10994 if (peer->afc[afi][safi]) {
10995 bgp_show_peer(vty, peer, use_json, json);
10996 nbr_output = true;
10997 break;
10998 }
10999 }
11000 break;
11001 }
11002 }
11003
11004 if ((type == show_peer || type == show_ipv4_peer ||
11005 type == show_ipv6_peer) && !find) {
11006 if (use_json)
11007 json_object_boolean_true_add(json, "bgpNoSuchNeighbor");
11008 else
11009 vty_out(vty, "%% No such neighbor in this view/vrf\n");
11010 }
11011
11012 if (type != show_peer && type != show_ipv4_peer &&
11013 type != show_ipv6_peer && !nbr_output && !use_json)
11014 vty_out(vty, "%% No BGP neighbors found\n");
11015
11016 if (use_json) {
11017 vty_out(vty, "%s\n", json_object_to_json_string_ext(
11018 json, JSON_C_TO_STRING_PRETTY));
11019 } else {
11020 vty_out(vty, "\n");
11021 }
11022
11023 return CMD_SUCCESS;
11024 }
11025
11026 static void bgp_show_all_instances_neighbors_vty(struct vty *vty,
11027 enum show_type type,
11028 const char *ip_str,
11029 bool use_json)
11030 {
11031 struct listnode *node, *nnode;
11032 struct bgp *bgp;
11033 union sockunion su;
11034 json_object *json = NULL;
11035 int ret, is_first = 1;
11036 bool nbr_output = false;
11037
11038 if (use_json)
11039 vty_out(vty, "{\n");
11040
11041 for (ALL_LIST_ELEMENTS(bm->bgp, node, nnode, bgp)) {
11042 nbr_output = true;
11043 if (use_json) {
11044 if (!(json = json_object_new_object())) {
11045 flog_err(
11046 EC_BGP_JSON_MEM_ERROR,
11047 "Unable to allocate memory for JSON object");
11048 vty_out(vty,
11049 "{\"error\": {\"message:\": \"Unable to allocate memory for JSON object\"}}}\n");
11050 return;
11051 }
11052
11053 json_object_int_add(json, "vrfId",
11054 (bgp->vrf_id == VRF_UNKNOWN)
11055 ? -1
11056 : (int64_t)bgp->vrf_id);
11057 json_object_string_add(
11058 json, "vrfName",
11059 (bgp->inst_type == BGP_INSTANCE_TYPE_DEFAULT)
11060 ? VRF_DEFAULT_NAME
11061 : bgp->name);
11062
11063 if (!is_first)
11064 vty_out(vty, ",\n");
11065 else
11066 is_first = 0;
11067
11068 vty_out(vty, "\"%s\":",
11069 (bgp->inst_type == BGP_INSTANCE_TYPE_DEFAULT)
11070 ? VRF_DEFAULT_NAME
11071 : bgp->name);
11072 } else {
11073 vty_out(vty, "\nInstance %s:\n",
11074 (bgp->inst_type == BGP_INSTANCE_TYPE_DEFAULT)
11075 ? VRF_DEFAULT_NAME
11076 : bgp->name);
11077 }
11078
11079 if (type == show_peer || type == show_ipv4_peer ||
11080 type == show_ipv6_peer) {
11081 ret = str2sockunion(ip_str, &su);
11082 if (ret < 0)
11083 bgp_show_neighbor(vty, bgp, type, NULL, ip_str,
11084 use_json, json);
11085 else
11086 bgp_show_neighbor(vty, bgp, type, &su, NULL,
11087 use_json, json);
11088 } else {
11089 bgp_show_neighbor(vty, bgp, type, NULL, NULL,
11090 use_json, json);
11091 }
11092 json_object_free(json);
11093 }
11094
11095 if (use_json) {
11096 vty_out(vty, "}\n");
11097 json_object_free(json);
11098 }
11099 else if (!nbr_output)
11100 vty_out(vty, "%% BGP instance not found\n");
11101 }
11102
11103 static int bgp_show_neighbor_vty(struct vty *vty, const char *name,
11104 enum show_type type, const char *ip_str,
11105 bool use_json)
11106 {
11107 int ret;
11108 struct bgp *bgp;
11109 union sockunion su;
11110 json_object *json = NULL;
11111
11112 if (name) {
11113 if (strmatch(name, "all")) {
11114 bgp_show_all_instances_neighbors_vty(vty, type, ip_str,
11115 use_json);
11116 return CMD_SUCCESS;
11117 } else {
11118 bgp = bgp_lookup_by_name(name);
11119 if (!bgp) {
11120 if (use_json) {
11121 json = json_object_new_object();
11122 vty_out(vty, "%s\n",
11123 json_object_to_json_string_ext(
11124 json,
11125 JSON_C_TO_STRING_PRETTY));
11126 json_object_free(json);
11127 } else
11128 vty_out(vty,
11129 "%% BGP instance not found\n");
11130
11131 return CMD_WARNING;
11132 }
11133 }
11134 } else {
11135 bgp = bgp_get_default();
11136 }
11137
11138 if (bgp) {
11139 json = json_object_new_object();
11140 if (ip_str) {
11141 ret = str2sockunion(ip_str, &su);
11142 if (ret < 0)
11143 bgp_show_neighbor(vty, bgp, type, NULL, ip_str,
11144 use_json, json);
11145 else
11146 bgp_show_neighbor(vty, bgp, type, &su, NULL,
11147 use_json, json);
11148 } else {
11149 bgp_show_neighbor(vty, bgp, type, NULL, NULL, use_json,
11150 json);
11151 }
11152 json_object_free(json);
11153 } else {
11154 if (use_json)
11155 vty_out(vty, "{}\n");
11156 else
11157 vty_out(vty, "%% BGP instance not found\n");
11158 }
11159
11160 return CMD_SUCCESS;
11161 }
11162
11163 /* "show [ip] bgp neighbors" commands. */
11164 DEFUN (show_ip_bgp_neighbors,
11165 show_ip_bgp_neighbors_cmd,
11166 "show [ip] bgp [<view|vrf> VIEWVRFNAME] [<ipv4|ipv6>] neighbors [<A.B.C.D|X:X::X:X|WORD>] [json]",
11167 SHOW_STR
11168 IP_STR
11169 BGP_STR
11170 BGP_INSTANCE_HELP_STR
11171 "Address Family\n"
11172 "Address Family\n"
11173 "Detailed information on TCP and BGP neighbor connections\n"
11174 "Neighbor to display information about\n"
11175 "Neighbor to display information about\n"
11176 "Neighbor on BGP configured interface\n"
11177 JSON_STR)
11178 {
11179 char *vrf = NULL;
11180 char *sh_arg = NULL;
11181 enum show_type sh_type;
11182 afi_t afi = AFI_MAX;
11183
11184 bool uj = use_json(argc, argv);
11185
11186 int idx = 0;
11187
11188 /* [<vrf> VIEWVRFNAME] */
11189 if (argv_find(argv, argc, "vrf", &idx)) {
11190 vrf = argv[idx + 1]->arg;
11191 if (vrf && strmatch(vrf, VRF_DEFAULT_NAME))
11192 vrf = NULL;
11193 } else if (argv_find(argv, argc, "view", &idx))
11194 /* [<view> VIEWVRFNAME] */
11195 vrf = argv[idx + 1]->arg;
11196
11197 idx++;
11198
11199 if (argv_find(argv, argc, "ipv4", &idx)) {
11200 sh_type = show_ipv4_all;
11201 afi = AFI_IP;
11202 } else if (argv_find(argv, argc, "ipv6", &idx)) {
11203 sh_type = show_ipv6_all;
11204 afi = AFI_IP6;
11205 } else {
11206 sh_type = show_all;
11207 }
11208
11209 if (argv_find(argv, argc, "A.B.C.D", &idx)
11210 || argv_find(argv, argc, "X:X::X:X", &idx)
11211 || argv_find(argv, argc, "WORD", &idx)) {
11212 sh_type = show_peer;
11213 sh_arg = argv[idx]->arg;
11214 }
11215
11216 if (sh_type == show_peer && afi == AFI_IP) {
11217 sh_type = show_ipv4_peer;
11218 } else if (sh_type == show_peer && afi == AFI_IP6) {
11219 sh_type = show_ipv6_peer;
11220 }
11221
11222 return bgp_show_neighbor_vty(vty, vrf, sh_type, sh_arg, uj);
11223 }
11224
11225 /* Show BGP's AS paths internal data. There are both `show [ip] bgp
11226 paths' and `show ip mbgp paths'. Those functions results are the
11227 same.*/
11228 DEFUN (show_ip_bgp_paths,
11229 show_ip_bgp_paths_cmd,
11230 "show [ip] bgp ["BGP_SAFI_CMD_STR"] paths",
11231 SHOW_STR
11232 IP_STR
11233 BGP_STR
11234 BGP_SAFI_HELP_STR
11235 "Path information\n")
11236 {
11237 vty_out(vty, "Address Refcnt Path\n");
11238 aspath_print_all_vty(vty);
11239 return CMD_SUCCESS;
11240 }
11241
11242 #include "hash.h"
11243
11244 static void community_show_all_iterator(struct hash_bucket *bucket,
11245 struct vty *vty)
11246 {
11247 struct community *com;
11248
11249 com = (struct community *)bucket->data;
11250 vty_out(vty, "[%p] (%ld) %s\n", (void *)com, com->refcnt,
11251 community_str(com, false));
11252 }
11253
11254 /* Show BGP's community internal data. */
11255 DEFUN (show_ip_bgp_community_info,
11256 show_ip_bgp_community_info_cmd,
11257 "show [ip] bgp community-info",
11258 SHOW_STR
11259 IP_STR
11260 BGP_STR
11261 "List all bgp community information\n")
11262 {
11263 vty_out(vty, "Address Refcnt Community\n");
11264
11265 hash_iterate(community_hash(),
11266 (void (*)(struct hash_bucket *,
11267 void *))community_show_all_iterator,
11268 vty);
11269
11270 return CMD_SUCCESS;
11271 }
11272
11273 static void lcommunity_show_all_iterator(struct hash_bucket *bucket,
11274 struct vty *vty)
11275 {
11276 struct lcommunity *lcom;
11277
11278 lcom = (struct lcommunity *)bucket->data;
11279 vty_out(vty, "[%p] (%ld) %s\n", (void *)lcom, lcom->refcnt,
11280 lcommunity_str(lcom, false));
11281 }
11282
11283 /* Show BGP's community internal data. */
11284 DEFUN (show_ip_bgp_lcommunity_info,
11285 show_ip_bgp_lcommunity_info_cmd,
11286 "show ip bgp large-community-info",
11287 SHOW_STR
11288 IP_STR
11289 BGP_STR
11290 "List all bgp large-community information\n")
11291 {
11292 vty_out(vty, "Address Refcnt Large-community\n");
11293
11294 hash_iterate(lcommunity_hash(),
11295 (void (*)(struct hash_bucket *,
11296 void *))lcommunity_show_all_iterator,
11297 vty);
11298
11299 return CMD_SUCCESS;
11300 }
11301
11302
11303 DEFUN (show_ip_bgp_attr_info,
11304 show_ip_bgp_attr_info_cmd,
11305 "show [ip] bgp attribute-info",
11306 SHOW_STR
11307 IP_STR
11308 BGP_STR
11309 "List all bgp attribute information\n")
11310 {
11311 attr_show_all(vty);
11312 return CMD_SUCCESS;
11313 }
11314
11315 static int bgp_show_route_leak_vty(struct vty *vty, const char *name,
11316 afi_t afi, safi_t safi,
11317 bool use_json, json_object *json)
11318 {
11319 struct bgp *bgp;
11320 struct listnode *node;
11321 char *vname;
11322 char buf1[INET6_ADDRSTRLEN];
11323 char *ecom_str;
11324 vpn_policy_direction_t dir;
11325
11326 if (json) {
11327 json_object *json_import_vrfs = NULL;
11328 json_object *json_export_vrfs = NULL;
11329
11330 bgp = name ? bgp_lookup_by_name(name) : bgp_get_default();
11331
11332 if (!bgp) {
11333 vty_out(vty, "%s\n",
11334 json_object_to_json_string_ext(
11335 json,
11336 JSON_C_TO_STRING_PRETTY));
11337 json_object_free(json);
11338
11339 return CMD_WARNING;
11340 }
11341
11342 /* Provide context for the block */
11343 json_object_string_add(json, "vrf", name ? name : "default");
11344 json_object_string_add(json, "afiSafi",
11345 afi_safi_print(afi, safi));
11346
11347 if (!CHECK_FLAG(bgp->af_flags[afi][safi],
11348 BGP_CONFIG_VRF_TO_VRF_IMPORT)) {
11349 json_object_string_add(json, "importFromVrfs", "none");
11350 json_object_string_add(json, "importRts", "none");
11351 } else {
11352 json_import_vrfs = json_object_new_array();
11353
11354 for (ALL_LIST_ELEMENTS_RO(
11355 bgp->vpn_policy[afi].import_vrf,
11356 node, vname))
11357 json_object_array_add(json_import_vrfs,
11358 json_object_new_string(vname));
11359
11360 dir = BGP_VPN_POLICY_DIR_FROMVPN;
11361 ecom_str = ecommunity_ecom2str(
11362 bgp->vpn_policy[afi].rtlist[dir],
11363 ECOMMUNITY_FORMAT_ROUTE_MAP, 0);
11364 json_object_object_add(json, "importFromVrfs",
11365 json_import_vrfs);
11366 json_object_string_add(json, "importRts", ecom_str);
11367
11368 XFREE(MTYPE_ECOMMUNITY_STR, ecom_str);
11369 }
11370
11371 if (!CHECK_FLAG(bgp->af_flags[afi][safi],
11372 BGP_CONFIG_VRF_TO_VRF_EXPORT)) {
11373 json_object_string_add(json, "exportToVrfs", "none");
11374 json_object_string_add(json, "routeDistinguisher",
11375 "none");
11376 json_object_string_add(json, "exportRts", "none");
11377 } else {
11378 json_export_vrfs = json_object_new_array();
11379
11380 for (ALL_LIST_ELEMENTS_RO(
11381 bgp->vpn_policy[afi].export_vrf,
11382 node, vname))
11383 json_object_array_add(json_export_vrfs,
11384 json_object_new_string(vname));
11385 json_object_object_add(json, "exportToVrfs",
11386 json_export_vrfs);
11387 json_object_string_add(json, "routeDistinguisher",
11388 prefix_rd2str(&bgp->vpn_policy[afi].tovpn_rd,
11389 buf1, RD_ADDRSTRLEN));
11390
11391 dir = BGP_VPN_POLICY_DIR_TOVPN;
11392 ecom_str = ecommunity_ecom2str(
11393 bgp->vpn_policy[afi].rtlist[dir],
11394 ECOMMUNITY_FORMAT_ROUTE_MAP, 0);
11395 json_object_string_add(json, "exportRts", ecom_str);
11396
11397 XFREE(MTYPE_ECOMMUNITY_STR, ecom_str);
11398 }
11399
11400 if (use_json) {
11401 vty_out(vty, "%s\n",
11402 json_object_to_json_string_ext(json,
11403 JSON_C_TO_STRING_PRETTY));
11404 json_object_free(json);
11405 }
11406 } else {
11407 bgp = name ? bgp_lookup_by_name(name) : bgp_get_default();
11408
11409 if (!bgp) {
11410 vty_out(vty, "%% No such BGP instance exist\n");
11411 return CMD_WARNING;
11412 }
11413
11414 if (!CHECK_FLAG(bgp->af_flags[afi][safi],
11415 BGP_CONFIG_VRF_TO_VRF_IMPORT))
11416 vty_out(vty,
11417 "This VRF is not importing %s routes from any other VRF\n",
11418 afi_safi_print(afi, safi));
11419 else {
11420 vty_out(vty,
11421 "This VRF is importing %s routes from the following VRFs:\n",
11422 afi_safi_print(afi, safi));
11423
11424 for (ALL_LIST_ELEMENTS_RO(
11425 bgp->vpn_policy[afi].import_vrf,
11426 node, vname))
11427 vty_out(vty, " %s\n", vname);
11428
11429 dir = BGP_VPN_POLICY_DIR_FROMVPN;
11430 ecom_str = ecommunity_ecom2str(
11431 bgp->vpn_policy[afi].rtlist[dir],
11432 ECOMMUNITY_FORMAT_ROUTE_MAP, 0);
11433 vty_out(vty, "Import RT(s): %s\n", ecom_str);
11434
11435 XFREE(MTYPE_ECOMMUNITY_STR, ecom_str);
11436 }
11437
11438 if (!CHECK_FLAG(bgp->af_flags[afi][safi],
11439 BGP_CONFIG_VRF_TO_VRF_EXPORT))
11440 vty_out(vty,
11441 "This VRF is not exporting %s routes to any other VRF\n",
11442 afi_safi_print(afi, safi));
11443 else {
11444 vty_out(vty,
11445 "This VRF is exporting %s routes to the following VRFs:\n",
11446 afi_safi_print(afi, safi));
11447
11448 for (ALL_LIST_ELEMENTS_RO(
11449 bgp->vpn_policy[afi].export_vrf,
11450 node, vname))
11451 vty_out(vty, " %s\n", vname);
11452
11453 vty_out(vty, "RD: %s\n",
11454 prefix_rd2str(&bgp->vpn_policy[afi].tovpn_rd,
11455 buf1, RD_ADDRSTRLEN));
11456
11457 dir = BGP_VPN_POLICY_DIR_TOVPN;
11458 ecom_str = ecommunity_ecom2str(
11459 bgp->vpn_policy[afi].rtlist[dir],
11460 ECOMMUNITY_FORMAT_ROUTE_MAP, 0);
11461 vty_out(vty, "Export RT: %s\n", ecom_str);
11462 XFREE(MTYPE_ECOMMUNITY_STR, ecom_str);
11463 }
11464 }
11465
11466 return CMD_SUCCESS;
11467 }
11468
11469 static int bgp_show_all_instance_route_leak_vty(struct vty *vty, afi_t afi,
11470 safi_t safi, bool use_json)
11471 {
11472 struct listnode *node, *nnode;
11473 struct bgp *bgp;
11474 char *vrf_name = NULL;
11475 json_object *json = NULL;
11476 json_object *json_vrf = NULL;
11477 json_object *json_vrfs = NULL;
11478
11479 if (use_json) {
11480 json = json_object_new_object();
11481 json_vrfs = json_object_new_object();
11482 }
11483
11484 for (ALL_LIST_ELEMENTS(bm->bgp, node, nnode, bgp)) {
11485
11486 if (bgp->inst_type != BGP_INSTANCE_TYPE_DEFAULT)
11487 vrf_name = bgp->name;
11488
11489 if (use_json) {
11490 json_vrf = json_object_new_object();
11491 } else {
11492 vty_out(vty, "\nInstance %s:\n",
11493 (bgp->inst_type == BGP_INSTANCE_TYPE_DEFAULT)
11494 ? VRF_DEFAULT_NAME : bgp->name);
11495 }
11496 bgp_show_route_leak_vty(vty, vrf_name, afi, safi, 0, json_vrf);
11497 if (use_json) {
11498 if (bgp->inst_type == BGP_INSTANCE_TYPE_DEFAULT)
11499 json_object_object_add(json_vrfs,
11500 VRF_DEFAULT_NAME, json_vrf);
11501 else
11502 json_object_object_add(json_vrfs, vrf_name,
11503 json_vrf);
11504 }
11505 }
11506
11507 if (use_json) {
11508 json_object_object_add(json, "vrfs", json_vrfs);
11509 vty_out(vty, "%s\n", json_object_to_json_string_ext(json,
11510 JSON_C_TO_STRING_PRETTY));
11511 json_object_free(json);
11512 }
11513
11514 return CMD_SUCCESS;
11515 }
11516
11517 /* "show [ip] bgp route-leak" command. */
11518 DEFUN (show_ip_bgp_route_leak,
11519 show_ip_bgp_route_leak_cmd,
11520 "show [ip] bgp [<view|vrf> VIEWVRFNAME] ["BGP_AFI_CMD_STR" ["BGP_SAFI_CMD_STR"]] route-leak [json]",
11521 SHOW_STR
11522 IP_STR
11523 BGP_STR
11524 BGP_INSTANCE_HELP_STR
11525 BGP_AFI_HELP_STR
11526 BGP_SAFI_HELP_STR
11527 "Route leaking information\n"
11528 JSON_STR)
11529 {
11530 char *vrf = NULL;
11531 afi_t afi = AFI_MAX;
11532 safi_t safi = SAFI_MAX;
11533
11534 bool uj = use_json(argc, argv);
11535 int idx = 0;
11536 json_object *json = NULL;
11537
11538 /* show [ip] bgp */
11539 if (argv_find(argv, argc, "ip", &idx)) {
11540 afi = AFI_IP;
11541 safi = SAFI_UNICAST;
11542 }
11543 /* [vrf VIEWVRFNAME] */
11544 if (argv_find(argv, argc, "view", &idx)) {
11545 vty_out(vty,
11546 "%% This command is not applicable to BGP views\n");
11547 return CMD_WARNING;
11548 }
11549
11550 if (argv_find(argv, argc, "vrf", &idx)) {
11551 vrf = argv[idx + 1]->arg;
11552 if (vrf && strmatch(vrf, VRF_DEFAULT_NAME))
11553 vrf = NULL;
11554 }
11555 /* ["BGP_AFI_CMD_STR" ["BGP_SAFI_CMD_STR"]] */
11556 if (argv_find_and_parse_afi(argv, argc, &idx, &afi)) {
11557 argv_find_and_parse_safi(argv, argc, &idx, &safi);
11558 }
11559
11560 if (!((afi == AFI_IP || afi == AFI_IP6) && safi == SAFI_UNICAST)) {
11561 vty_out(vty,
11562 "%% This command is applicable only for unicast ipv4|ipv6\n");
11563 return CMD_WARNING;
11564 }
11565
11566 if (vrf && strmatch(vrf, "all"))
11567 return bgp_show_all_instance_route_leak_vty(vty, afi, safi, uj);
11568
11569 if (uj)
11570 json = json_object_new_object();
11571
11572 return bgp_show_route_leak_vty(vty, vrf, afi, safi, uj, json);
11573 }
11574
11575 static void bgp_show_all_instances_updgrps_vty(struct vty *vty, afi_t afi,
11576 safi_t safi)
11577 {
11578 struct listnode *node, *nnode;
11579 struct bgp *bgp;
11580
11581 for (ALL_LIST_ELEMENTS(bm->bgp, node, nnode, bgp)) {
11582 vty_out(vty, "\nInstance %s:\n",
11583 (bgp->inst_type == BGP_INSTANCE_TYPE_DEFAULT)
11584 ? VRF_DEFAULT_NAME
11585 : bgp->name);
11586 update_group_show(bgp, afi, safi, vty, 0);
11587 }
11588 }
11589
11590 static int bgp_show_update_groups(struct vty *vty, const char *name, int afi,
11591 int safi, uint64_t subgrp_id)
11592 {
11593 struct bgp *bgp;
11594
11595 if (name) {
11596 if (strmatch(name, "all")) {
11597 bgp_show_all_instances_updgrps_vty(vty, afi, safi);
11598 return CMD_SUCCESS;
11599 } else {
11600 bgp = bgp_lookup_by_name(name);
11601 }
11602 } else {
11603 bgp = bgp_get_default();
11604 }
11605
11606 if (bgp)
11607 update_group_show(bgp, afi, safi, vty, subgrp_id);
11608 return CMD_SUCCESS;
11609 }
11610
11611 DEFUN (show_ip_bgp_updgrps,
11612 show_ip_bgp_updgrps_cmd,
11613 "show [ip] bgp [<view|vrf> VIEWVRFNAME] ["BGP_AFI_CMD_STR" ["BGP_SAFI_WITH_LABEL_CMD_STR"]] update-groups [SUBGROUP-ID]",
11614 SHOW_STR
11615 IP_STR
11616 BGP_STR
11617 BGP_INSTANCE_HELP_STR
11618 BGP_AFI_HELP_STR
11619 BGP_SAFI_WITH_LABEL_HELP_STR
11620 "Detailed info about dynamic update groups\n"
11621 "Specific subgroup to display detailed info for\n")
11622 {
11623 char *vrf = NULL;
11624 afi_t afi = AFI_IP6;
11625 safi_t safi = SAFI_UNICAST;
11626 uint64_t subgrp_id = 0;
11627
11628 int idx = 0;
11629
11630 /* show [ip] bgp */
11631 if (argv_find(argv, argc, "ip", &idx))
11632 afi = AFI_IP;
11633 /* [<vrf> VIEWVRFNAME] */
11634 if (argv_find(argv, argc, "vrf", &idx)) {
11635 vrf = argv[idx + 1]->arg;
11636 if (vrf && strmatch(vrf, VRF_DEFAULT_NAME))
11637 vrf = NULL;
11638 } else if (argv_find(argv, argc, "view", &idx))
11639 /* [<view> VIEWVRFNAME] */
11640 vrf = argv[idx + 1]->arg;
11641 /* ["BGP_AFI_CMD_STR" ["BGP_SAFI_CMD_STR"]] */
11642 if (argv_find_and_parse_afi(argv, argc, &idx, &afi)) {
11643 argv_find_and_parse_safi(argv, argc, &idx, &safi);
11644 }
11645
11646 /* get subgroup id, if provided */
11647 idx = argc - 1;
11648 if (argv[idx]->type == VARIABLE_TKN)
11649 subgrp_id = strtoull(argv[idx]->arg, NULL, 10);
11650
11651 return (bgp_show_update_groups(vty, vrf, afi, safi, subgrp_id));
11652 }
11653
11654 DEFUN (show_bgp_instance_all_ipv6_updgrps,
11655 show_bgp_instance_all_ipv6_updgrps_cmd,
11656 "show [ip] bgp <view|vrf> all update-groups",
11657 SHOW_STR
11658 IP_STR
11659 BGP_STR
11660 BGP_INSTANCE_ALL_HELP_STR
11661 "Detailed info about dynamic update groups\n")
11662 {
11663 bgp_show_all_instances_updgrps_vty(vty, AFI_IP6, SAFI_UNICAST);
11664 return CMD_SUCCESS;
11665 }
11666
11667 DEFUN (show_bgp_l2vpn_evpn_updgrps,
11668 show_bgp_l2vpn_evpn_updgrps_cmd,
11669 "show [ip] bgp l2vpn evpn update-groups",
11670 SHOW_STR
11671 IP_STR
11672 BGP_STR
11673 "l2vpn address family\n"
11674 "evpn sub-address family\n"
11675 "Detailed info about dynamic update groups\n")
11676 {
11677 char *vrf = NULL;
11678 uint64_t subgrp_id = 0;
11679
11680 bgp_show_update_groups(vty, vrf, AFI_L2VPN, SAFI_EVPN, subgrp_id);
11681 return CMD_SUCCESS;
11682 }
11683
11684 DEFUN (show_bgp_updgrps_stats,
11685 show_bgp_updgrps_stats_cmd,
11686 "show [ip] bgp update-groups statistics",
11687 SHOW_STR
11688 IP_STR
11689 BGP_STR
11690 "Detailed info about dynamic update groups\n"
11691 "Statistics\n")
11692 {
11693 struct bgp *bgp;
11694
11695 bgp = bgp_get_default();
11696 if (bgp)
11697 update_group_show_stats(bgp, vty);
11698
11699 return CMD_SUCCESS;
11700 }
11701
11702 DEFUN (show_bgp_instance_updgrps_stats,
11703 show_bgp_instance_updgrps_stats_cmd,
11704 "show [ip] bgp <view|vrf> VIEWVRFNAME update-groups statistics",
11705 SHOW_STR
11706 IP_STR
11707 BGP_STR
11708 BGP_INSTANCE_HELP_STR
11709 "Detailed info about dynamic update groups\n"
11710 "Statistics\n")
11711 {
11712 int idx_word = 3;
11713 struct bgp *bgp;
11714
11715 bgp = bgp_lookup_by_name(argv[idx_word]->arg);
11716 if (bgp)
11717 update_group_show_stats(bgp, vty);
11718
11719 return CMD_SUCCESS;
11720 }
11721
11722 static void show_bgp_updgrps_adj_info_aux(struct vty *vty, const char *name,
11723 afi_t afi, safi_t safi,
11724 const char *what, uint64_t subgrp_id)
11725 {
11726 struct bgp *bgp;
11727
11728 if (name)
11729 bgp = bgp_lookup_by_name(name);
11730 else
11731 bgp = bgp_get_default();
11732
11733 if (bgp) {
11734 if (!strcmp(what, "advertise-queue"))
11735 update_group_show_adj_queue(bgp, afi, safi, vty,
11736 subgrp_id);
11737 else if (!strcmp(what, "advertised-routes"))
11738 update_group_show_advertised(bgp, afi, safi, vty,
11739 subgrp_id);
11740 else if (!strcmp(what, "packet-queue"))
11741 update_group_show_packet_queue(bgp, afi, safi, vty,
11742 subgrp_id);
11743 }
11744 }
11745
11746 DEFPY(show_ip_bgp_instance_updgrps_adj_s,
11747 show_ip_bgp_instance_updgrps_adj_s_cmd,
11748 "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",
11749 SHOW_STR IP_STR BGP_STR BGP_INSTANCE_HELP_STR BGP_AFI_HELP_STR
11750 BGP_SAFI_HELP_STR
11751 "Detailed info about dynamic update groups\n"
11752 "Specific subgroup to display info for\n"
11753 "Advertisement queue\n"
11754 "Announced routes\n"
11755 "Packet queue\n")
11756 {
11757 uint64_t subgrp_id = 0;
11758 afi_t afiz;
11759 safi_t safiz;
11760 if (sgid)
11761 subgrp_id = strtoull(sgid, NULL, 10);
11762
11763 if (!ip && !afi)
11764 afiz = AFI_IP6;
11765 if (!ip && afi)
11766 afiz = bgp_vty_afi_from_str(afi);
11767 if (ip && !afi)
11768 afiz = AFI_IP;
11769 if (ip && afi) {
11770 afiz = bgp_vty_afi_from_str(afi);
11771 if (afiz != AFI_IP)
11772 vty_out(vty,
11773 "%% Cannot specify both 'ip' and 'ipv6'\n");
11774 return CMD_WARNING;
11775 }
11776
11777 safiz = safi ? bgp_vty_safi_from_str(safi) : SAFI_UNICAST;
11778
11779 show_bgp_updgrps_adj_info_aux(vty, vrf, afiz, safiz, rtq, subgrp_id);
11780 return CMD_SUCCESS;
11781 }
11782
11783 static int bgp_show_one_peer_group(struct vty *vty, struct peer_group *group)
11784 {
11785 struct listnode *node, *nnode;
11786 struct prefix *range;
11787 struct peer *conf;
11788 struct peer *peer;
11789 char buf[PREFIX2STR_BUFFER];
11790 afi_t afi;
11791 safi_t safi;
11792 const char *peer_status;
11793 const char *af_str;
11794 int lr_count;
11795 int dynamic;
11796 int af_cfgd;
11797
11798 conf = group->conf;
11799
11800 if (conf->as_type == AS_SPECIFIED || conf->as_type == AS_EXTERNAL) {
11801 vty_out(vty, "\nBGP peer-group %s, remote AS %" PRIu32 "\n",
11802 group->name, conf->as);
11803 } else if (conf->as_type == AS_INTERNAL) {
11804 vty_out(vty, "\nBGP peer-group %s, remote AS %" PRIu32 "\n",
11805 group->name, group->bgp->as);
11806 } else {
11807 vty_out(vty, "\nBGP peer-group %s\n", group->name);
11808 }
11809
11810 if ((group->bgp->as == conf->as) || (conf->as_type == AS_INTERNAL))
11811 vty_out(vty, " Peer-group type is internal\n");
11812 else
11813 vty_out(vty, " Peer-group type is external\n");
11814
11815 /* Display AFs configured. */
11816 vty_out(vty, " Configured address-families:");
11817 FOREACH_AFI_SAFI (afi, safi) {
11818 if (conf->afc[afi][safi]) {
11819 af_cfgd = 1;
11820 vty_out(vty, " %s;", afi_safi_print(afi, safi));
11821 }
11822 }
11823 if (!af_cfgd)
11824 vty_out(vty, " none\n");
11825 else
11826 vty_out(vty, "\n");
11827
11828 /* Display listen ranges (for dynamic neighbors), if any */
11829 for (afi = AFI_IP; afi < AFI_MAX; afi++) {
11830 if (afi == AFI_IP)
11831 af_str = "IPv4";
11832 else if (afi == AFI_IP6)
11833 af_str = "IPv6";
11834 else
11835 af_str = "???";
11836 lr_count = listcount(group->listen_range[afi]);
11837 if (lr_count) {
11838 vty_out(vty, " %d %s listen range(s)\n", lr_count,
11839 af_str);
11840
11841
11842 for (ALL_LIST_ELEMENTS(group->listen_range[afi], node,
11843 nnode, range)) {
11844 prefix2str(range, buf, sizeof(buf));
11845 vty_out(vty, " %s\n", buf);
11846 }
11847 }
11848 }
11849
11850 /* Display group members and their status */
11851 if (listcount(group->peer)) {
11852 vty_out(vty, " Peer-group members:\n");
11853 for (ALL_LIST_ELEMENTS(group->peer, node, nnode, peer)) {
11854 if (CHECK_FLAG(peer->flags, PEER_FLAG_SHUTDOWN))
11855 peer_status = "Idle (Admin)";
11856 else if (CHECK_FLAG(peer->sflags,
11857 PEER_STATUS_PREFIX_OVERFLOW))
11858 peer_status = "Idle (PfxCt)";
11859 else
11860 peer_status = lookup_msg(bgp_status_msg,
11861 peer->status, NULL);
11862
11863 dynamic = peer_dynamic_neighbor(peer);
11864 vty_out(vty, " %s %s %s \n", peer->host,
11865 dynamic ? "(dynamic)" : "", peer_status);
11866 }
11867 }
11868
11869 return CMD_SUCCESS;
11870 }
11871
11872 static int bgp_show_peer_group_vty(struct vty *vty, const char *name,
11873 const char *group_name)
11874 {
11875 struct bgp *bgp;
11876 struct listnode *node, *nnode;
11877 struct peer_group *group;
11878 bool found = false;
11879
11880 bgp = name ? bgp_lookup_by_name(name) : bgp_get_default();
11881
11882 if (!bgp) {
11883 vty_out(vty, "%% BGP instance not found\n");
11884 return CMD_WARNING;
11885 }
11886
11887 for (ALL_LIST_ELEMENTS(bgp->group, node, nnode, group)) {
11888 if (group_name) {
11889 if (strmatch(group->name, group_name)) {
11890 bgp_show_one_peer_group(vty, group);
11891 found = true;
11892 break;
11893 }
11894 } else {
11895 bgp_show_one_peer_group(vty, group);
11896 }
11897 }
11898
11899 if (group_name && !found)
11900 vty_out(vty, "%% No such peer-group\n");
11901
11902 return CMD_SUCCESS;
11903 }
11904
11905 DEFUN (show_ip_bgp_peer_groups,
11906 show_ip_bgp_peer_groups_cmd,
11907 "show [ip] bgp [<view|vrf> VIEWVRFNAME] peer-group [PGNAME]",
11908 SHOW_STR
11909 IP_STR
11910 BGP_STR
11911 BGP_INSTANCE_HELP_STR
11912 "Detailed information on BGP peer groups\n"
11913 "Peer group name\n")
11914 {
11915 char *vrf, *pg;
11916 int idx = 0;
11917
11918 vrf = argv_find(argv, argc, "VIEWVRFNAME", &idx) ? argv[idx]->arg
11919 : NULL;
11920 pg = argv_find(argv, argc, "PGNAME", &idx) ? argv[idx]->arg : NULL;
11921
11922 return bgp_show_peer_group_vty(vty, vrf, pg);
11923 }
11924
11925
11926 /* Redistribute VTY commands. */
11927
11928 DEFUN (bgp_redistribute_ipv4,
11929 bgp_redistribute_ipv4_cmd,
11930 "redistribute " FRR_IP_REDIST_STR_BGPD,
11931 "Redistribute information from another routing protocol\n"
11932 FRR_IP_REDIST_HELP_STR_BGPD)
11933 {
11934 VTY_DECLVAR_CONTEXT(bgp, bgp);
11935 int idx_protocol = 1;
11936 int type;
11937
11938 type = proto_redistnum(AFI_IP, argv[idx_protocol]->text);
11939 if (type < 0) {
11940 vty_out(vty, "%% Invalid route type\n");
11941 return CMD_WARNING_CONFIG_FAILED;
11942 }
11943
11944 bgp_redist_add(bgp, AFI_IP, type, 0);
11945 return bgp_redistribute_set(bgp, AFI_IP, type, 0, false);
11946 }
11947
11948 ALIAS_HIDDEN(
11949 bgp_redistribute_ipv4, bgp_redistribute_ipv4_hidden_cmd,
11950 "redistribute " FRR_IP_REDIST_STR_BGPD,
11951 "Redistribute information from another routing protocol\n" FRR_IP_REDIST_HELP_STR_BGPD)
11952
11953 DEFUN (bgp_redistribute_ipv4_rmap,
11954 bgp_redistribute_ipv4_rmap_cmd,
11955 "redistribute " FRR_IP_REDIST_STR_BGPD " route-map WORD",
11956 "Redistribute information from another routing protocol\n"
11957 FRR_IP_REDIST_HELP_STR_BGPD
11958 "Route map reference\n"
11959 "Pointer to route-map entries\n")
11960 {
11961 VTY_DECLVAR_CONTEXT(bgp, bgp);
11962 int idx_protocol = 1;
11963 int idx_word = 3;
11964 int type;
11965 struct bgp_redist *red;
11966 bool changed;
11967 struct route_map *route_map = route_map_lookup_warn_noexist(
11968 vty, argv[idx_word]->arg);
11969
11970 type = proto_redistnum(AFI_IP, argv[idx_protocol]->text);
11971 if (type < 0) {
11972 vty_out(vty, "%% Invalid route type\n");
11973 return CMD_WARNING_CONFIG_FAILED;
11974 }
11975
11976 red = bgp_redist_add(bgp, AFI_IP, type, 0);
11977 changed =
11978 bgp_redistribute_rmap_set(red, argv[idx_word]->arg, route_map);
11979 return bgp_redistribute_set(bgp, AFI_IP, type, 0, changed);
11980 }
11981
11982 ALIAS_HIDDEN(
11983 bgp_redistribute_ipv4_rmap, bgp_redistribute_ipv4_rmap_hidden_cmd,
11984 "redistribute " FRR_IP_REDIST_STR_BGPD " route-map WORD",
11985 "Redistribute information from another routing protocol\n" FRR_IP_REDIST_HELP_STR_BGPD
11986 "Route map reference\n"
11987 "Pointer to route-map entries\n")
11988
11989 DEFUN (bgp_redistribute_ipv4_metric,
11990 bgp_redistribute_ipv4_metric_cmd,
11991 "redistribute " FRR_IP_REDIST_STR_BGPD " metric (0-4294967295)",
11992 "Redistribute information from another routing protocol\n"
11993 FRR_IP_REDIST_HELP_STR_BGPD
11994 "Metric for redistributed routes\n"
11995 "Default metric\n")
11996 {
11997 VTY_DECLVAR_CONTEXT(bgp, bgp);
11998 int idx_protocol = 1;
11999 int idx_number = 3;
12000 int type;
12001 uint32_t metric;
12002 struct bgp_redist *red;
12003 bool changed;
12004
12005 type = proto_redistnum(AFI_IP, argv[idx_protocol]->text);
12006 if (type < 0) {
12007 vty_out(vty, "%% Invalid route type\n");
12008 return CMD_WARNING_CONFIG_FAILED;
12009 }
12010 metric = strtoul(argv[idx_number]->arg, NULL, 10);
12011
12012 red = bgp_redist_add(bgp, AFI_IP, type, 0);
12013 changed = bgp_redistribute_metric_set(bgp, red, AFI_IP, type, metric);
12014 return bgp_redistribute_set(bgp, AFI_IP, type, 0, changed);
12015 }
12016
12017 ALIAS_HIDDEN(
12018 bgp_redistribute_ipv4_metric, bgp_redistribute_ipv4_metric_hidden_cmd,
12019 "redistribute " FRR_IP_REDIST_STR_BGPD " metric (0-4294967295)",
12020 "Redistribute information from another routing protocol\n" FRR_IP_REDIST_HELP_STR_BGPD
12021 "Metric for redistributed routes\n"
12022 "Default metric\n")
12023
12024 DEFUN (bgp_redistribute_ipv4_rmap_metric,
12025 bgp_redistribute_ipv4_rmap_metric_cmd,
12026 "redistribute " FRR_IP_REDIST_STR_BGPD " route-map WORD metric (0-4294967295)",
12027 "Redistribute information from another routing protocol\n"
12028 FRR_IP_REDIST_HELP_STR_BGPD
12029 "Route map reference\n"
12030 "Pointer to route-map entries\n"
12031 "Metric for redistributed routes\n"
12032 "Default metric\n")
12033 {
12034 VTY_DECLVAR_CONTEXT(bgp, bgp);
12035 int idx_protocol = 1;
12036 int idx_word = 3;
12037 int idx_number = 5;
12038 int type;
12039 uint32_t metric;
12040 struct bgp_redist *red;
12041 bool changed;
12042 struct route_map *route_map =
12043 route_map_lookup_warn_noexist(vty, argv[idx_word]->arg);
12044
12045 type = proto_redistnum(AFI_IP, argv[idx_protocol]->text);
12046 if (type < 0) {
12047 vty_out(vty, "%% Invalid route type\n");
12048 return CMD_WARNING_CONFIG_FAILED;
12049 }
12050 metric = strtoul(argv[idx_number]->arg, NULL, 10);
12051
12052 red = bgp_redist_add(bgp, AFI_IP, type, 0);
12053 changed =
12054 bgp_redistribute_rmap_set(red, argv[idx_word]->arg, route_map);
12055 changed |= bgp_redistribute_metric_set(bgp, red, AFI_IP, type, metric);
12056 return bgp_redistribute_set(bgp, AFI_IP, type, 0, changed);
12057 }
12058
12059 ALIAS_HIDDEN(
12060 bgp_redistribute_ipv4_rmap_metric,
12061 bgp_redistribute_ipv4_rmap_metric_hidden_cmd,
12062 "redistribute " FRR_IP_REDIST_STR_BGPD
12063 " route-map WORD metric (0-4294967295)",
12064 "Redistribute information from another routing protocol\n" FRR_IP_REDIST_HELP_STR_BGPD
12065 "Route map reference\n"
12066 "Pointer to route-map entries\n"
12067 "Metric for redistributed routes\n"
12068 "Default metric\n")
12069
12070 DEFUN (bgp_redistribute_ipv4_metric_rmap,
12071 bgp_redistribute_ipv4_metric_rmap_cmd,
12072 "redistribute " FRR_IP_REDIST_STR_BGPD " metric (0-4294967295) route-map WORD",
12073 "Redistribute information from another routing protocol\n"
12074 FRR_IP_REDIST_HELP_STR_BGPD
12075 "Metric for redistributed routes\n"
12076 "Default metric\n"
12077 "Route map reference\n"
12078 "Pointer to route-map entries\n")
12079 {
12080 VTY_DECLVAR_CONTEXT(bgp, bgp);
12081 int idx_protocol = 1;
12082 int idx_number = 3;
12083 int idx_word = 5;
12084 int type;
12085 uint32_t metric;
12086 struct bgp_redist *red;
12087 bool changed;
12088 struct route_map *route_map =
12089 route_map_lookup_warn_noexist(vty, argv[idx_word]->arg);
12090
12091 type = proto_redistnum(AFI_IP, argv[idx_protocol]->text);
12092 if (type < 0) {
12093 vty_out(vty, "%% Invalid route type\n");
12094 return CMD_WARNING_CONFIG_FAILED;
12095 }
12096 metric = strtoul(argv[idx_number]->arg, NULL, 10);
12097
12098 red = bgp_redist_add(bgp, AFI_IP, type, 0);
12099 changed = bgp_redistribute_metric_set(bgp, red, AFI_IP, type, metric);
12100 changed |=
12101 bgp_redistribute_rmap_set(red, argv[idx_word]->arg, route_map);
12102 return bgp_redistribute_set(bgp, AFI_IP, type, 0, changed);
12103 }
12104
12105 ALIAS_HIDDEN(
12106 bgp_redistribute_ipv4_metric_rmap,
12107 bgp_redistribute_ipv4_metric_rmap_hidden_cmd,
12108 "redistribute " FRR_IP_REDIST_STR_BGPD
12109 " metric (0-4294967295) route-map WORD",
12110 "Redistribute information from another routing protocol\n" FRR_IP_REDIST_HELP_STR_BGPD
12111 "Metric for redistributed routes\n"
12112 "Default metric\n"
12113 "Route map reference\n"
12114 "Pointer to route-map entries\n")
12115
12116 DEFUN (bgp_redistribute_ipv4_ospf,
12117 bgp_redistribute_ipv4_ospf_cmd,
12118 "redistribute <ospf|table> (1-65535)",
12119 "Redistribute information from another routing protocol\n"
12120 "Open Shortest Path First (OSPFv2)\n"
12121 "Non-main Kernel Routing Table\n"
12122 "Instance ID/Table ID\n")
12123 {
12124 VTY_DECLVAR_CONTEXT(bgp, bgp);
12125 int idx_ospf_table = 1;
12126 int idx_number = 2;
12127 unsigned short instance;
12128 unsigned short protocol;
12129
12130 instance = strtoul(argv[idx_number]->arg, NULL, 10);
12131
12132 if (strncmp(argv[idx_ospf_table]->arg, "o", 1) == 0)
12133 protocol = ZEBRA_ROUTE_OSPF;
12134 else
12135 protocol = ZEBRA_ROUTE_TABLE;
12136
12137 bgp_redist_add(bgp, AFI_IP, protocol, instance);
12138 return bgp_redistribute_set(bgp, AFI_IP, protocol, instance, false);
12139 }
12140
12141 ALIAS_HIDDEN(bgp_redistribute_ipv4_ospf, bgp_redistribute_ipv4_ospf_hidden_cmd,
12142 "redistribute <ospf|table> (1-65535)",
12143 "Redistribute information from another routing protocol\n"
12144 "Open Shortest Path First (OSPFv2)\n"
12145 "Non-main Kernel Routing Table\n"
12146 "Instance ID/Table ID\n")
12147
12148 DEFUN (bgp_redistribute_ipv4_ospf_rmap,
12149 bgp_redistribute_ipv4_ospf_rmap_cmd,
12150 "redistribute <ospf|table> (1-65535) route-map WORD",
12151 "Redistribute information from another routing protocol\n"
12152 "Open Shortest Path First (OSPFv2)\n"
12153 "Non-main Kernel Routing Table\n"
12154 "Instance ID/Table ID\n"
12155 "Route map reference\n"
12156 "Pointer to route-map entries\n")
12157 {
12158 VTY_DECLVAR_CONTEXT(bgp, bgp);
12159 int idx_ospf_table = 1;
12160 int idx_number = 2;
12161 int idx_word = 4;
12162 struct bgp_redist *red;
12163 unsigned short instance;
12164 int protocol;
12165 bool changed;
12166 struct route_map *route_map =
12167 route_map_lookup_warn_noexist(vty, argv[idx_word]->arg);
12168
12169 if (strncmp(argv[idx_ospf_table]->arg, "o", 1) == 0)
12170 protocol = ZEBRA_ROUTE_OSPF;
12171 else
12172 protocol = ZEBRA_ROUTE_TABLE;
12173
12174 instance = strtoul(argv[idx_number]->arg, NULL, 10);
12175 red = bgp_redist_add(bgp, AFI_IP, protocol, instance);
12176 changed =
12177 bgp_redistribute_rmap_set(red, argv[idx_word]->arg, route_map);
12178 return bgp_redistribute_set(bgp, AFI_IP, protocol, instance, changed);
12179 }
12180
12181 ALIAS_HIDDEN(bgp_redistribute_ipv4_ospf_rmap,
12182 bgp_redistribute_ipv4_ospf_rmap_hidden_cmd,
12183 "redistribute <ospf|table> (1-65535) route-map WORD",
12184 "Redistribute information from another routing protocol\n"
12185 "Open Shortest Path First (OSPFv2)\n"
12186 "Non-main Kernel Routing Table\n"
12187 "Instance ID/Table ID\n"
12188 "Route map reference\n"
12189 "Pointer to route-map entries\n")
12190
12191 DEFUN (bgp_redistribute_ipv4_ospf_metric,
12192 bgp_redistribute_ipv4_ospf_metric_cmd,
12193 "redistribute <ospf|table> (1-65535) metric (0-4294967295)",
12194 "Redistribute information from another routing protocol\n"
12195 "Open Shortest Path First (OSPFv2)\n"
12196 "Non-main Kernel Routing Table\n"
12197 "Instance ID/Table ID\n"
12198 "Metric for redistributed routes\n"
12199 "Default metric\n")
12200 {
12201 VTY_DECLVAR_CONTEXT(bgp, bgp);
12202 int idx_ospf_table = 1;
12203 int idx_number = 2;
12204 int idx_number_2 = 4;
12205 uint32_t metric;
12206 struct bgp_redist *red;
12207 unsigned short instance;
12208 int protocol;
12209 bool changed;
12210
12211 if (strncmp(argv[idx_ospf_table]->arg, "o", 1) == 0)
12212 protocol = ZEBRA_ROUTE_OSPF;
12213 else
12214 protocol = ZEBRA_ROUTE_TABLE;
12215
12216 instance = strtoul(argv[idx_number]->arg, NULL, 10);
12217 metric = strtoul(argv[idx_number_2]->arg, NULL, 10);
12218
12219 red = bgp_redist_add(bgp, AFI_IP, protocol, instance);
12220 changed = bgp_redistribute_metric_set(bgp, red, AFI_IP, protocol,
12221 metric);
12222 return bgp_redistribute_set(bgp, AFI_IP, protocol, instance, changed);
12223 }
12224
12225 ALIAS_HIDDEN(bgp_redistribute_ipv4_ospf_metric,
12226 bgp_redistribute_ipv4_ospf_metric_hidden_cmd,
12227 "redistribute <ospf|table> (1-65535) metric (0-4294967295)",
12228 "Redistribute information from another routing protocol\n"
12229 "Open Shortest Path First (OSPFv2)\n"
12230 "Non-main Kernel Routing Table\n"
12231 "Instance ID/Table ID\n"
12232 "Metric for redistributed routes\n"
12233 "Default metric\n")
12234
12235 DEFUN (bgp_redistribute_ipv4_ospf_rmap_metric,
12236 bgp_redistribute_ipv4_ospf_rmap_metric_cmd,
12237 "redistribute <ospf|table> (1-65535) route-map WORD metric (0-4294967295)",
12238 "Redistribute information from another routing protocol\n"
12239 "Open Shortest Path First (OSPFv2)\n"
12240 "Non-main Kernel Routing Table\n"
12241 "Instance ID/Table ID\n"
12242 "Route map reference\n"
12243 "Pointer to route-map entries\n"
12244 "Metric for redistributed routes\n"
12245 "Default metric\n")
12246 {
12247 VTY_DECLVAR_CONTEXT(bgp, bgp);
12248 int idx_ospf_table = 1;
12249 int idx_number = 2;
12250 int idx_word = 4;
12251 int idx_number_2 = 6;
12252 uint32_t metric;
12253 struct bgp_redist *red;
12254 unsigned short instance;
12255 int protocol;
12256 bool changed;
12257 struct route_map *route_map =
12258 route_map_lookup_warn_noexist(vty, argv[idx_word]->arg);
12259
12260 if (strncmp(argv[idx_ospf_table]->arg, "o", 1) == 0)
12261 protocol = ZEBRA_ROUTE_OSPF;
12262 else
12263 protocol = ZEBRA_ROUTE_TABLE;
12264
12265 instance = strtoul(argv[idx_number]->arg, NULL, 10);
12266 metric = strtoul(argv[idx_number_2]->arg, NULL, 10);
12267
12268 red = bgp_redist_add(bgp, AFI_IP, protocol, instance);
12269 changed =
12270 bgp_redistribute_rmap_set(red, argv[idx_word]->arg, route_map);
12271 changed |= bgp_redistribute_metric_set(bgp, red, AFI_IP, protocol,
12272 metric);
12273 return bgp_redistribute_set(bgp, AFI_IP, protocol, instance, changed);
12274 }
12275
12276 ALIAS_HIDDEN(
12277 bgp_redistribute_ipv4_ospf_rmap_metric,
12278 bgp_redistribute_ipv4_ospf_rmap_metric_hidden_cmd,
12279 "redistribute <ospf|table> (1-65535) route-map WORD metric (0-4294967295)",
12280 "Redistribute information from another routing protocol\n"
12281 "Open Shortest Path First (OSPFv2)\n"
12282 "Non-main Kernel Routing Table\n"
12283 "Instance ID/Table ID\n"
12284 "Route map reference\n"
12285 "Pointer to route-map entries\n"
12286 "Metric for redistributed routes\n"
12287 "Default metric\n")
12288
12289 DEFUN (bgp_redistribute_ipv4_ospf_metric_rmap,
12290 bgp_redistribute_ipv4_ospf_metric_rmap_cmd,
12291 "redistribute <ospf|table> (1-65535) metric (0-4294967295) route-map WORD",
12292 "Redistribute information from another routing protocol\n"
12293 "Open Shortest Path First (OSPFv2)\n"
12294 "Non-main Kernel Routing Table\n"
12295 "Instance ID/Table ID\n"
12296 "Metric for redistributed routes\n"
12297 "Default metric\n"
12298 "Route map reference\n"
12299 "Pointer to route-map entries\n")
12300 {
12301 VTY_DECLVAR_CONTEXT(bgp, bgp);
12302 int idx_ospf_table = 1;
12303 int idx_number = 2;
12304 int idx_number_2 = 4;
12305 int idx_word = 6;
12306 uint32_t metric;
12307 struct bgp_redist *red;
12308 unsigned short instance;
12309 int protocol;
12310 bool changed;
12311 struct route_map *route_map =
12312 route_map_lookup_warn_noexist(vty, argv[idx_word]->arg);
12313
12314 if (strncmp(argv[idx_ospf_table]->arg, "o", 1) == 0)
12315 protocol = ZEBRA_ROUTE_OSPF;
12316 else
12317 protocol = ZEBRA_ROUTE_TABLE;
12318
12319 instance = strtoul(argv[idx_number]->arg, NULL, 10);
12320 metric = strtoul(argv[idx_number_2]->arg, NULL, 10);
12321
12322 red = bgp_redist_add(bgp, AFI_IP, protocol, instance);
12323 changed = bgp_redistribute_metric_set(bgp, red, AFI_IP, protocol,
12324 metric);
12325 changed |=
12326 bgp_redistribute_rmap_set(red, argv[idx_word]->arg, route_map);
12327 return bgp_redistribute_set(bgp, AFI_IP, protocol, instance, changed);
12328 }
12329
12330 ALIAS_HIDDEN(
12331 bgp_redistribute_ipv4_ospf_metric_rmap,
12332 bgp_redistribute_ipv4_ospf_metric_rmap_hidden_cmd,
12333 "redistribute <ospf|table> (1-65535) metric (0-4294967295) route-map WORD",
12334 "Redistribute information from another routing protocol\n"
12335 "Open Shortest Path First (OSPFv2)\n"
12336 "Non-main Kernel Routing Table\n"
12337 "Instance ID/Table ID\n"
12338 "Metric for redistributed routes\n"
12339 "Default metric\n"
12340 "Route map reference\n"
12341 "Pointer to route-map entries\n")
12342
12343 DEFUN (no_bgp_redistribute_ipv4_ospf,
12344 no_bgp_redistribute_ipv4_ospf_cmd,
12345 "no redistribute <ospf|table> (1-65535) [metric (0-4294967295)] [route-map WORD]",
12346 NO_STR
12347 "Redistribute information from another routing protocol\n"
12348 "Open Shortest Path First (OSPFv2)\n"
12349 "Non-main Kernel Routing Table\n"
12350 "Instance ID/Table ID\n"
12351 "Metric for redistributed routes\n"
12352 "Default metric\n"
12353 "Route map reference\n"
12354 "Pointer to route-map entries\n")
12355 {
12356 VTY_DECLVAR_CONTEXT(bgp, bgp);
12357 int idx_ospf_table = 2;
12358 int idx_number = 3;
12359 unsigned short instance;
12360 int protocol;
12361
12362 if (strncmp(argv[idx_ospf_table]->arg, "o", 1) == 0)
12363 protocol = ZEBRA_ROUTE_OSPF;
12364 else
12365 protocol = ZEBRA_ROUTE_TABLE;
12366
12367 instance = strtoul(argv[idx_number]->arg, NULL, 10);
12368 return bgp_redistribute_unset(bgp, AFI_IP, protocol, instance);
12369 }
12370
12371 ALIAS_HIDDEN(
12372 no_bgp_redistribute_ipv4_ospf, no_bgp_redistribute_ipv4_ospf_hidden_cmd,
12373 "no redistribute <ospf|table> (1-65535) [metric (0-4294967295)] [route-map WORD]",
12374 NO_STR
12375 "Redistribute information from another routing protocol\n"
12376 "Open Shortest Path First (OSPFv2)\n"
12377 "Non-main Kernel Routing Table\n"
12378 "Instance ID/Table ID\n"
12379 "Metric for redistributed routes\n"
12380 "Default metric\n"
12381 "Route map reference\n"
12382 "Pointer to route-map entries\n")
12383
12384 DEFUN (no_bgp_redistribute_ipv4,
12385 no_bgp_redistribute_ipv4_cmd,
12386 "no redistribute " FRR_IP_REDIST_STR_BGPD " [metric (0-4294967295)] [route-map WORD]",
12387 NO_STR
12388 "Redistribute information from another routing protocol\n"
12389 FRR_IP_REDIST_HELP_STR_BGPD
12390 "Metric for redistributed routes\n"
12391 "Default metric\n"
12392 "Route map reference\n"
12393 "Pointer to route-map entries\n")
12394 {
12395 VTY_DECLVAR_CONTEXT(bgp, bgp);
12396 int idx_protocol = 2;
12397 int type;
12398
12399 type = proto_redistnum(AFI_IP, argv[idx_protocol]->text);
12400 if (type < 0) {
12401 vty_out(vty, "%% Invalid route type\n");
12402 return CMD_WARNING_CONFIG_FAILED;
12403 }
12404 return bgp_redistribute_unset(bgp, AFI_IP, type, 0);
12405 }
12406
12407 ALIAS_HIDDEN(
12408 no_bgp_redistribute_ipv4, no_bgp_redistribute_ipv4_hidden_cmd,
12409 "no redistribute " FRR_IP_REDIST_STR_BGPD
12410 " [metric (0-4294967295)] [route-map WORD]",
12411 NO_STR
12412 "Redistribute information from another routing protocol\n" 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 DEFUN (bgp_redistribute_ipv6,
12419 bgp_redistribute_ipv6_cmd,
12420 "redistribute " FRR_IP6_REDIST_STR_BGPD,
12421 "Redistribute information from another routing protocol\n"
12422 FRR_IP6_REDIST_HELP_STR_BGPD)
12423 {
12424 VTY_DECLVAR_CONTEXT(bgp, bgp);
12425 int idx_protocol = 1;
12426 int type;
12427
12428 type = proto_redistnum(AFI_IP6, argv[idx_protocol]->text);
12429 if (type < 0) {
12430 vty_out(vty, "%% Invalid route type\n");
12431 return CMD_WARNING_CONFIG_FAILED;
12432 }
12433
12434 bgp_redist_add(bgp, AFI_IP6, type, 0);
12435 return bgp_redistribute_set(bgp, AFI_IP6, type, 0, false);
12436 }
12437
12438 DEFUN (bgp_redistribute_ipv6_rmap,
12439 bgp_redistribute_ipv6_rmap_cmd,
12440 "redistribute " FRR_IP6_REDIST_STR_BGPD " route-map WORD",
12441 "Redistribute information from another routing protocol\n"
12442 FRR_IP6_REDIST_HELP_STR_BGPD
12443 "Route map reference\n"
12444 "Pointer to route-map entries\n")
12445 {
12446 VTY_DECLVAR_CONTEXT(bgp, bgp);
12447 int idx_protocol = 1;
12448 int idx_word = 3;
12449 int type;
12450 struct bgp_redist *red;
12451 bool changed;
12452 struct route_map *route_map =
12453 route_map_lookup_warn_noexist(vty, argv[idx_word]->arg);
12454
12455 type = proto_redistnum(AFI_IP6, argv[idx_protocol]->text);
12456 if (type < 0) {
12457 vty_out(vty, "%% Invalid route type\n");
12458 return CMD_WARNING_CONFIG_FAILED;
12459 }
12460
12461 red = bgp_redist_add(bgp, AFI_IP6, type, 0);
12462 changed =
12463 bgp_redistribute_rmap_set(red, argv[idx_word]->arg, route_map);
12464 return bgp_redistribute_set(bgp, AFI_IP6, type, 0, changed);
12465 }
12466
12467 DEFUN (bgp_redistribute_ipv6_metric,
12468 bgp_redistribute_ipv6_metric_cmd,
12469 "redistribute " FRR_IP6_REDIST_STR_BGPD " metric (0-4294967295)",
12470 "Redistribute information from another routing protocol\n"
12471 FRR_IP6_REDIST_HELP_STR_BGPD
12472 "Metric for redistributed routes\n"
12473 "Default metric\n")
12474 {
12475 VTY_DECLVAR_CONTEXT(bgp, bgp);
12476 int idx_protocol = 1;
12477 int idx_number = 3;
12478 int type;
12479 uint32_t metric;
12480 struct bgp_redist *red;
12481 bool changed;
12482
12483 type = proto_redistnum(AFI_IP6, argv[idx_protocol]->text);
12484 if (type < 0) {
12485 vty_out(vty, "%% Invalid route type\n");
12486 return CMD_WARNING_CONFIG_FAILED;
12487 }
12488 metric = strtoul(argv[idx_number]->arg, NULL, 10);
12489
12490 red = bgp_redist_add(bgp, AFI_IP6, type, 0);
12491 changed = bgp_redistribute_metric_set(bgp, red, AFI_IP6, type, metric);
12492 return bgp_redistribute_set(bgp, AFI_IP6, type, 0, changed);
12493 }
12494
12495 DEFUN (bgp_redistribute_ipv6_rmap_metric,
12496 bgp_redistribute_ipv6_rmap_metric_cmd,
12497 "redistribute " FRR_IP6_REDIST_STR_BGPD " route-map WORD metric (0-4294967295)",
12498 "Redistribute information from another routing protocol\n"
12499 FRR_IP6_REDIST_HELP_STR_BGPD
12500 "Route map reference\n"
12501 "Pointer to route-map entries\n"
12502 "Metric for redistributed routes\n"
12503 "Default metric\n")
12504 {
12505 VTY_DECLVAR_CONTEXT(bgp, bgp);
12506 int idx_protocol = 1;
12507 int idx_word = 3;
12508 int idx_number = 5;
12509 int type;
12510 uint32_t metric;
12511 struct bgp_redist *red;
12512 bool changed;
12513 struct route_map *route_map =
12514 route_map_lookup_warn_noexist(vty, argv[idx_word]->arg);
12515
12516 type = proto_redistnum(AFI_IP6, argv[idx_protocol]->text);
12517 if (type < 0) {
12518 vty_out(vty, "%% Invalid route type\n");
12519 return CMD_WARNING_CONFIG_FAILED;
12520 }
12521 metric = strtoul(argv[idx_number]->arg, NULL, 10);
12522
12523 red = bgp_redist_add(bgp, AFI_IP6, type, 0);
12524 changed =
12525 bgp_redistribute_rmap_set(red, argv[idx_word]->arg, route_map);
12526 changed |= bgp_redistribute_metric_set(bgp, red, AFI_IP6, type,
12527 metric);
12528 return bgp_redistribute_set(bgp, AFI_IP6, type, 0, changed);
12529 }
12530
12531 DEFUN (bgp_redistribute_ipv6_metric_rmap,
12532 bgp_redistribute_ipv6_metric_rmap_cmd,
12533 "redistribute " FRR_IP6_REDIST_STR_BGPD " metric (0-4294967295) route-map WORD",
12534 "Redistribute information from another routing protocol\n"
12535 FRR_IP6_REDIST_HELP_STR_BGPD
12536 "Metric for redistributed routes\n"
12537 "Default metric\n"
12538 "Route map reference\n"
12539 "Pointer to route-map entries\n")
12540 {
12541 VTY_DECLVAR_CONTEXT(bgp, bgp);
12542 int idx_protocol = 1;
12543 int idx_number = 3;
12544 int idx_word = 5;
12545 int type;
12546 uint32_t metric;
12547 struct bgp_redist *red;
12548 bool changed;
12549 struct route_map *route_map =
12550 route_map_lookup_warn_noexist(vty, argv[idx_word]->arg);
12551
12552 type = proto_redistnum(AFI_IP6, argv[idx_protocol]->text);
12553 if (type < 0) {
12554 vty_out(vty, "%% Invalid route type\n");
12555 return CMD_WARNING_CONFIG_FAILED;
12556 }
12557 metric = strtoul(argv[idx_number]->arg, NULL, 10);
12558
12559 red = bgp_redist_add(bgp, AFI_IP6, type, 0);
12560 changed = bgp_redistribute_metric_set(bgp, red, AFI_IP6, SAFI_UNICAST,
12561 metric);
12562 changed |=
12563 bgp_redistribute_rmap_set(red, argv[idx_word]->arg, route_map);
12564 return bgp_redistribute_set(bgp, AFI_IP6, type, 0, changed);
12565 }
12566
12567 DEFUN (no_bgp_redistribute_ipv6,
12568 no_bgp_redistribute_ipv6_cmd,
12569 "no redistribute " FRR_IP6_REDIST_STR_BGPD " [metric (0-4294967295)] [route-map WORD]",
12570 NO_STR
12571 "Redistribute information from another routing protocol\n"
12572 FRR_IP6_REDIST_HELP_STR_BGPD
12573 "Metric for redistributed routes\n"
12574 "Default metric\n"
12575 "Route map reference\n"
12576 "Pointer to route-map entries\n")
12577 {
12578 VTY_DECLVAR_CONTEXT(bgp, bgp);
12579 int idx_protocol = 2;
12580 int type;
12581
12582 type = proto_redistnum(AFI_IP6, argv[idx_protocol]->text);
12583 if (type < 0) {
12584 vty_out(vty, "%% Invalid route type\n");
12585 return CMD_WARNING_CONFIG_FAILED;
12586 }
12587
12588 return bgp_redistribute_unset(bgp, AFI_IP6, type, 0);
12589 }
12590
12591 void bgp_config_write_redistribute(struct vty *vty, struct bgp *bgp, afi_t afi,
12592 safi_t safi)
12593 {
12594 int i;
12595
12596 /* Unicast redistribution only. */
12597 if (safi != SAFI_UNICAST)
12598 return;
12599
12600 for (i = 0; i < ZEBRA_ROUTE_MAX; i++) {
12601 /* Redistribute BGP does not make sense. */
12602 if (i != ZEBRA_ROUTE_BGP) {
12603 struct list *red_list;
12604 struct listnode *node;
12605 struct bgp_redist *red;
12606
12607 red_list = bgp->redist[afi][i];
12608 if (!red_list)
12609 continue;
12610
12611 for (ALL_LIST_ELEMENTS_RO(red_list, node, red)) {
12612 /* "redistribute" configuration. */
12613 vty_out(vty, " redistribute %s",
12614 zebra_route_string(i));
12615 if (red->instance)
12616 vty_out(vty, " %d", red->instance);
12617 if (red->redist_metric_flag)
12618 vty_out(vty, " metric %u",
12619 red->redist_metric);
12620 if (red->rmap.name)
12621 vty_out(vty, " route-map %s",
12622 red->rmap.name);
12623 vty_out(vty, "\n");
12624 }
12625 }
12626 }
12627 }
12628
12629 /* This is part of the address-family block (unicast only) */
12630 void bgp_vpn_policy_config_write_afi(struct vty *vty, struct bgp *bgp,
12631 afi_t afi)
12632 {
12633 int indent = 2;
12634
12635 if (bgp->vpn_policy[afi].rmap_name[BGP_VPN_POLICY_DIR_FROMVPN]) {
12636 if (listcount(bgp->vpn_policy[afi].import_vrf))
12637 vty_out(vty, "%*simport vrf route-map %s\n", indent, "",
12638 bgp->vpn_policy[afi]
12639 .rmap_name[BGP_VPN_POLICY_DIR_FROMVPN]);
12640 else
12641 vty_out(vty, "%*sroute-map vpn import %s\n", indent, "",
12642 bgp->vpn_policy[afi]
12643 .rmap_name[BGP_VPN_POLICY_DIR_FROMVPN]);
12644 }
12645 if (CHECK_FLAG(bgp->af_flags[afi][SAFI_UNICAST],
12646 BGP_CONFIG_VRF_TO_VRF_IMPORT)
12647 || CHECK_FLAG(bgp->af_flags[afi][SAFI_UNICAST],
12648 BGP_CONFIG_VRF_TO_VRF_EXPORT))
12649 return;
12650
12651 if (CHECK_FLAG(bgp->vpn_policy[afi].flags,
12652 BGP_VPN_POLICY_TOVPN_LABEL_AUTO)) {
12653
12654 vty_out(vty, "%*slabel vpn export %s\n", indent, "", "auto");
12655
12656 } else {
12657 if (bgp->vpn_policy[afi].tovpn_label != MPLS_LABEL_NONE) {
12658 vty_out(vty, "%*slabel vpn export %u\n", indent, "",
12659 bgp->vpn_policy[afi].tovpn_label);
12660 }
12661 }
12662 if (CHECK_FLAG(bgp->vpn_policy[afi].flags,
12663 BGP_VPN_POLICY_TOVPN_RD_SET)) {
12664 char buf[RD_ADDRSTRLEN];
12665 vty_out(vty, "%*srd vpn export %s\n", indent, "",
12666 prefix_rd2str(&bgp->vpn_policy[afi].tovpn_rd, buf,
12667 sizeof(buf)));
12668 }
12669 if (CHECK_FLAG(bgp->vpn_policy[afi].flags,
12670 BGP_VPN_POLICY_TOVPN_NEXTHOP_SET)) {
12671
12672 char buf[PREFIX_STRLEN];
12673 if (inet_ntop(bgp->vpn_policy[afi].tovpn_nexthop.family,
12674 &bgp->vpn_policy[afi].tovpn_nexthop.u.prefix, buf,
12675 sizeof(buf))) {
12676
12677 vty_out(vty, "%*snexthop vpn export %s\n",
12678 indent, "", buf);
12679 }
12680 }
12681 if (bgp->vpn_policy[afi].rtlist[BGP_VPN_POLICY_DIR_FROMVPN]
12682 && bgp->vpn_policy[afi].rtlist[BGP_VPN_POLICY_DIR_TOVPN]
12683 && ecommunity_cmp(
12684 bgp->vpn_policy[afi].rtlist[BGP_VPN_POLICY_DIR_FROMVPN],
12685 bgp->vpn_policy[afi].rtlist[BGP_VPN_POLICY_DIR_TOVPN])) {
12686
12687 char *b = ecommunity_ecom2str(
12688 bgp->vpn_policy[afi].rtlist[BGP_VPN_POLICY_DIR_TOVPN],
12689 ECOMMUNITY_FORMAT_ROUTE_MAP, ECOMMUNITY_ROUTE_TARGET);
12690 vty_out(vty, "%*srt vpn both %s\n", indent, "", b);
12691 XFREE(MTYPE_ECOMMUNITY_STR, b);
12692 } else {
12693 if (bgp->vpn_policy[afi].rtlist[BGP_VPN_POLICY_DIR_FROMVPN]) {
12694 char *b = ecommunity_ecom2str(
12695 bgp->vpn_policy[afi]
12696 .rtlist[BGP_VPN_POLICY_DIR_FROMVPN],
12697 ECOMMUNITY_FORMAT_ROUTE_MAP,
12698 ECOMMUNITY_ROUTE_TARGET);
12699 vty_out(vty, "%*srt vpn import %s\n", indent, "", b);
12700 XFREE(MTYPE_ECOMMUNITY_STR, b);
12701 }
12702 if (bgp->vpn_policy[afi].rtlist[BGP_VPN_POLICY_DIR_TOVPN]) {
12703 char *b = ecommunity_ecom2str(
12704 bgp->vpn_policy[afi]
12705 .rtlist[BGP_VPN_POLICY_DIR_TOVPN],
12706 ECOMMUNITY_FORMAT_ROUTE_MAP,
12707 ECOMMUNITY_ROUTE_TARGET);
12708 vty_out(vty, "%*srt vpn export %s\n", indent, "", b);
12709 XFREE(MTYPE_ECOMMUNITY_STR, b);
12710 }
12711 }
12712
12713 if (bgp->vpn_policy[afi].rmap_name[BGP_VPN_POLICY_DIR_TOVPN])
12714 vty_out(vty, "%*sroute-map vpn export %s\n", indent, "",
12715 bgp->vpn_policy[afi]
12716 .rmap_name[BGP_VPN_POLICY_DIR_TOVPN]);
12717
12718 if (bgp->vpn_policy[afi].import_redirect_rtlist) {
12719 char *b = ecommunity_ecom2str(
12720 bgp->vpn_policy[afi]
12721 .import_redirect_rtlist,
12722 ECOMMUNITY_FORMAT_ROUTE_MAP,
12723 ECOMMUNITY_ROUTE_TARGET);
12724
12725 vty_out(vty, "%*srt redirect import %s\n", indent, "", b);
12726 XFREE(MTYPE_ECOMMUNITY_STR, b);
12727 }
12728 }
12729
12730
12731 /* BGP node structure. */
12732 static struct cmd_node bgp_node = {
12733 BGP_NODE, "%s(config-router)# ", 1,
12734 };
12735
12736 static struct cmd_node bgp_ipv4_unicast_node = {
12737 BGP_IPV4_NODE, "%s(config-router-af)# ", 1,
12738 };
12739
12740 static struct cmd_node bgp_ipv4_multicast_node = {
12741 BGP_IPV4M_NODE, "%s(config-router-af)# ", 1,
12742 };
12743
12744 static struct cmd_node bgp_ipv4_labeled_unicast_node = {
12745 BGP_IPV4L_NODE, "%s(config-router-af)# ", 1,
12746 };
12747
12748 static struct cmd_node bgp_ipv6_unicast_node = {
12749 BGP_IPV6_NODE, "%s(config-router-af)# ", 1,
12750 };
12751
12752 static struct cmd_node bgp_ipv6_multicast_node = {
12753 BGP_IPV6M_NODE, "%s(config-router-af)# ", 1,
12754 };
12755
12756 static struct cmd_node bgp_ipv6_labeled_unicast_node = {
12757 BGP_IPV6L_NODE, "%s(config-router-af)# ", 1,
12758 };
12759
12760 static struct cmd_node bgp_vpnv4_node = {BGP_VPNV4_NODE,
12761 "%s(config-router-af)# ", 1};
12762
12763 static struct cmd_node bgp_vpnv6_node = {BGP_VPNV6_NODE,
12764 "%s(config-router-af-vpnv6)# ", 1};
12765
12766 static struct cmd_node bgp_evpn_node = {BGP_EVPN_NODE,
12767 "%s(config-router-evpn)# ", 1};
12768
12769 static struct cmd_node bgp_evpn_vni_node = {BGP_EVPN_VNI_NODE,
12770 "%s(config-router-af-vni)# ", 1};
12771
12772 static struct cmd_node bgp_flowspecv4_node = {BGP_FLOWSPECV4_NODE,
12773 "%s(config-router-af)# ", 1};
12774
12775 static struct cmd_node bgp_flowspecv6_node = {BGP_FLOWSPECV6_NODE,
12776 "%s(config-router-af-vpnv6)# ", 1};
12777
12778 static void community_list_vty(void);
12779
12780 static void bgp_ac_neighbor(vector comps, struct cmd_token *token)
12781 {
12782 struct bgp *bgp;
12783 struct peer *peer;
12784 struct listnode *lnbgp, *lnpeer;
12785
12786 for (ALL_LIST_ELEMENTS_RO(bm->bgp, lnbgp, bgp)) {
12787 for (ALL_LIST_ELEMENTS_RO(bgp->peer, lnpeer, peer)) {
12788 /* only provide suggestions on the appropriate input
12789 * token type,
12790 * they'll otherwise show up multiple times */
12791 enum cmd_token_type match_type;
12792 char *name = peer->host;
12793
12794 if (peer->conf_if) {
12795 match_type = VARIABLE_TKN;
12796 name = peer->conf_if;
12797 } else if (strchr(peer->host, ':'))
12798 match_type = IPV6_TKN;
12799 else
12800 match_type = IPV4_TKN;
12801
12802 if (token->type != match_type)
12803 continue;
12804
12805 vector_set(comps, XSTRDUP(MTYPE_COMPLETION, name));
12806 }
12807 }
12808 }
12809
12810 static const struct cmd_variable_handler bgp_var_neighbor[] = {
12811 {.varname = "neighbor", .completions = bgp_ac_neighbor},
12812 {.varname = "neighbors", .completions = bgp_ac_neighbor},
12813 {.varname = "peer", .completions = bgp_ac_neighbor},
12814 {.completions = NULL}};
12815
12816 static void bgp_ac_peergroup(vector comps, struct cmd_token *token)
12817 {
12818 struct bgp *bgp;
12819 struct peer_group *group;
12820 struct listnode *lnbgp, *lnpeer;
12821
12822 for (ALL_LIST_ELEMENTS_RO(bm->bgp, lnbgp, bgp)) {
12823 for (ALL_LIST_ELEMENTS_RO(bgp->group, lnpeer, group))
12824 vector_set(comps, XSTRDUP(MTYPE_COMPLETION,
12825 group->name));
12826 }
12827 }
12828
12829 static const struct cmd_variable_handler bgp_var_peergroup[] = {
12830 {.tokenname = "PGNAME", .completions = bgp_ac_peergroup},
12831 {.completions = NULL} };
12832
12833 void bgp_vty_init(void)
12834 {
12835 cmd_variable_handler_register(bgp_var_neighbor);
12836 cmd_variable_handler_register(bgp_var_peergroup);
12837
12838 /* Install bgp top node. */
12839 install_node(&bgp_node, bgp_config_write);
12840 install_node(&bgp_ipv4_unicast_node, NULL);
12841 install_node(&bgp_ipv4_multicast_node, NULL);
12842 install_node(&bgp_ipv4_labeled_unicast_node, NULL);
12843 install_node(&bgp_ipv6_unicast_node, NULL);
12844 install_node(&bgp_ipv6_multicast_node, NULL);
12845 install_node(&bgp_ipv6_labeled_unicast_node, NULL);
12846 install_node(&bgp_vpnv4_node, NULL);
12847 install_node(&bgp_vpnv6_node, NULL);
12848 install_node(&bgp_evpn_node, NULL);
12849 install_node(&bgp_evpn_vni_node, NULL);
12850 install_node(&bgp_flowspecv4_node, NULL);
12851 install_node(&bgp_flowspecv6_node, NULL);
12852
12853 /* Install default VTY commands to new nodes. */
12854 install_default(BGP_NODE);
12855 install_default(BGP_IPV4_NODE);
12856 install_default(BGP_IPV4M_NODE);
12857 install_default(BGP_IPV4L_NODE);
12858 install_default(BGP_IPV6_NODE);
12859 install_default(BGP_IPV6M_NODE);
12860 install_default(BGP_IPV6L_NODE);
12861 install_default(BGP_VPNV4_NODE);
12862 install_default(BGP_VPNV6_NODE);
12863 install_default(BGP_FLOWSPECV4_NODE);
12864 install_default(BGP_FLOWSPECV6_NODE);
12865 install_default(BGP_EVPN_NODE);
12866 install_default(BGP_EVPN_VNI_NODE);
12867
12868 /* "bgp multiple-instance" commands. */
12869 install_element(CONFIG_NODE, &bgp_multiple_instance_cmd);
12870 install_element(CONFIG_NODE, &no_bgp_multiple_instance_cmd);
12871
12872 /* "bgp config-type" commands. */
12873 install_element(CONFIG_NODE, &bgp_config_type_cmd);
12874 install_element(CONFIG_NODE, &no_bgp_config_type_cmd);
12875
12876 /* "bgp local-mac" hidden commands. */
12877 install_element(CONFIG_NODE, &bgp_local_mac_cmd);
12878 install_element(CONFIG_NODE, &no_bgp_local_mac_cmd);
12879
12880 /* bgp route-map delay-timer commands. */
12881 install_element(CONFIG_NODE, &bgp_set_route_map_delay_timer_cmd);
12882 install_element(CONFIG_NODE, &no_bgp_set_route_map_delay_timer_cmd);
12883
12884 /* Dummy commands (Currently not supported) */
12885 install_element(BGP_NODE, &no_synchronization_cmd);
12886 install_element(BGP_NODE, &no_auto_summary_cmd);
12887
12888 /* "router bgp" commands. */
12889 install_element(CONFIG_NODE, &router_bgp_cmd);
12890
12891 /* "no router bgp" commands. */
12892 install_element(CONFIG_NODE, &no_router_bgp_cmd);
12893
12894 /* "bgp router-id" commands. */
12895 install_element(BGP_NODE, &bgp_router_id_cmd);
12896 install_element(BGP_NODE, &no_bgp_router_id_cmd);
12897
12898 /* "bgp cluster-id" commands. */
12899 install_element(BGP_NODE, &bgp_cluster_id_cmd);
12900 install_element(BGP_NODE, &no_bgp_cluster_id_cmd);
12901
12902 /* "bgp confederation" commands. */
12903 install_element(BGP_NODE, &bgp_confederation_identifier_cmd);
12904 install_element(BGP_NODE, &no_bgp_confederation_identifier_cmd);
12905
12906 /* "bgp confederation peers" commands. */
12907 install_element(BGP_NODE, &bgp_confederation_peers_cmd);
12908 install_element(BGP_NODE, &no_bgp_confederation_peers_cmd);
12909
12910 /* bgp max-med command */
12911 install_element(BGP_NODE, &bgp_maxmed_admin_cmd);
12912 install_element(BGP_NODE, &no_bgp_maxmed_admin_cmd);
12913 install_element(BGP_NODE, &bgp_maxmed_admin_medv_cmd);
12914 install_element(BGP_NODE, &bgp_maxmed_onstartup_cmd);
12915 install_element(BGP_NODE, &no_bgp_maxmed_onstartup_cmd);
12916
12917 /* bgp disable-ebgp-connected-nh-check */
12918 install_element(BGP_NODE, &bgp_disable_connected_route_check_cmd);
12919 install_element(BGP_NODE, &no_bgp_disable_connected_route_check_cmd);
12920
12921 /* bgp update-delay command */
12922 install_element(BGP_NODE, &bgp_update_delay_cmd);
12923 install_element(BGP_NODE, &no_bgp_update_delay_cmd);
12924 install_element(BGP_NODE, &bgp_update_delay_establish_wait_cmd);
12925
12926 install_element(BGP_NODE, &bgp_wpkt_quanta_cmd);
12927 install_element(BGP_NODE, &no_bgp_wpkt_quanta_cmd);
12928 install_element(BGP_NODE, &bgp_rpkt_quanta_cmd);
12929 install_element(BGP_NODE, &no_bgp_rpkt_quanta_cmd);
12930
12931 install_element(BGP_NODE, &bgp_coalesce_time_cmd);
12932 install_element(BGP_NODE, &no_bgp_coalesce_time_cmd);
12933
12934 /* "maximum-paths" commands. */
12935 install_element(BGP_NODE, &bgp_maxpaths_hidden_cmd);
12936 install_element(BGP_NODE, &no_bgp_maxpaths_hidden_cmd);
12937 install_element(BGP_IPV4_NODE, &bgp_maxpaths_cmd);
12938 install_element(BGP_IPV4_NODE, &no_bgp_maxpaths_cmd);
12939 install_element(BGP_IPV6_NODE, &bgp_maxpaths_cmd);
12940 install_element(BGP_IPV6_NODE, &no_bgp_maxpaths_cmd);
12941 install_element(BGP_NODE, &bgp_maxpaths_ibgp_hidden_cmd);
12942 install_element(BGP_NODE, &bgp_maxpaths_ibgp_cluster_hidden_cmd);
12943 install_element(BGP_NODE, &no_bgp_maxpaths_ibgp_hidden_cmd);
12944 install_element(BGP_IPV4_NODE, &bgp_maxpaths_ibgp_cmd);
12945 install_element(BGP_IPV4_NODE, &bgp_maxpaths_ibgp_cluster_cmd);
12946 install_element(BGP_IPV4_NODE, &no_bgp_maxpaths_ibgp_cmd);
12947 install_element(BGP_IPV6_NODE, &bgp_maxpaths_ibgp_cmd);
12948 install_element(BGP_IPV6_NODE, &bgp_maxpaths_ibgp_cluster_cmd);
12949 install_element(BGP_IPV6_NODE, &no_bgp_maxpaths_ibgp_cmd);
12950
12951 install_element(BGP_IPV6L_NODE, &bgp_maxpaths_cmd);
12952 install_element(BGP_IPV6L_NODE, &no_bgp_maxpaths_cmd);
12953 install_element(BGP_IPV6L_NODE, &bgp_maxpaths_ibgp_cmd);
12954 install_element(BGP_IPV6L_NODE, &bgp_maxpaths_ibgp_cluster_cmd);
12955 install_element(BGP_IPV6L_NODE, &no_bgp_maxpaths_ibgp_cmd);
12956
12957 /* "timers bgp" commands. */
12958 install_element(BGP_NODE, &bgp_timers_cmd);
12959 install_element(BGP_NODE, &no_bgp_timers_cmd);
12960
12961 /* route-map delay-timer commands - per instance for backwards compat.
12962 */
12963 install_element(BGP_NODE, &bgp_set_route_map_delay_timer_cmd);
12964 install_element(BGP_NODE, &no_bgp_set_route_map_delay_timer_cmd);
12965
12966 /* "bgp client-to-client reflection" commands */
12967 install_element(BGP_NODE, &no_bgp_client_to_client_reflection_cmd);
12968 install_element(BGP_NODE, &bgp_client_to_client_reflection_cmd);
12969
12970 /* "bgp always-compare-med" commands */
12971 install_element(BGP_NODE, &bgp_always_compare_med_cmd);
12972 install_element(BGP_NODE, &no_bgp_always_compare_med_cmd);
12973
12974 /* bgp ebgp-requires-policy */
12975 install_element(BGP_NODE, &bgp_ebgp_requires_policy_cmd);
12976 install_element(BGP_NODE, &no_bgp_ebgp_requires_policy_cmd);
12977
12978 /* "bgp deterministic-med" commands */
12979 install_element(BGP_NODE, &bgp_deterministic_med_cmd);
12980 install_element(BGP_NODE, &no_bgp_deterministic_med_cmd);
12981
12982 /* "bgp graceful-restart" commands */
12983 install_element(BGP_NODE, &bgp_graceful_restart_cmd);
12984 install_element(BGP_NODE, &no_bgp_graceful_restart_cmd);
12985 install_element(BGP_NODE, &bgp_graceful_restart_stalepath_time_cmd);
12986 install_element(BGP_NODE, &no_bgp_graceful_restart_stalepath_time_cmd);
12987 install_element(BGP_NODE, &bgp_graceful_restart_restart_time_cmd);
12988 install_element(BGP_NODE, &no_bgp_graceful_restart_restart_time_cmd);
12989
12990 install_element(BGP_NODE, &bgp_graceful_restart_preserve_fw_cmd);
12991 install_element(BGP_NODE, &no_bgp_graceful_restart_preserve_fw_cmd);
12992
12993 /* "bgp graceful-shutdown" commands */
12994 install_element(BGP_NODE, &bgp_graceful_shutdown_cmd);
12995 install_element(BGP_NODE, &no_bgp_graceful_shutdown_cmd);
12996
12997 /* "bgp fast-external-failover" commands */
12998 install_element(BGP_NODE, &bgp_fast_external_failover_cmd);
12999 install_element(BGP_NODE, &no_bgp_fast_external_failover_cmd);
13000
13001 /* "bgp enforce-first-as" commands */
13002 install_element(BGP_NODE, &bgp_enforce_first_as_cmd);
13003
13004 /* "bgp bestpath compare-routerid" commands */
13005 install_element(BGP_NODE, &bgp_bestpath_compare_router_id_cmd);
13006 install_element(BGP_NODE, &no_bgp_bestpath_compare_router_id_cmd);
13007
13008 /* "bgp bestpath as-path ignore" commands */
13009 install_element(BGP_NODE, &bgp_bestpath_aspath_ignore_cmd);
13010 install_element(BGP_NODE, &no_bgp_bestpath_aspath_ignore_cmd);
13011
13012 /* "bgp bestpath as-path confed" commands */
13013 install_element(BGP_NODE, &bgp_bestpath_aspath_confed_cmd);
13014 install_element(BGP_NODE, &no_bgp_bestpath_aspath_confed_cmd);
13015
13016 /* "bgp bestpath as-path multipath-relax" commands */
13017 install_element(BGP_NODE, &bgp_bestpath_aspath_multipath_relax_cmd);
13018 install_element(BGP_NODE, &no_bgp_bestpath_aspath_multipath_relax_cmd);
13019
13020 /* "bgp log-neighbor-changes" commands */
13021 install_element(BGP_NODE, &bgp_log_neighbor_changes_cmd);
13022 install_element(BGP_NODE, &no_bgp_log_neighbor_changes_cmd);
13023
13024 /* "bgp bestpath med" commands */
13025 install_element(BGP_NODE, &bgp_bestpath_med_cmd);
13026 install_element(BGP_NODE, &no_bgp_bestpath_med_cmd);
13027
13028 /* "no bgp default ipv4-unicast" commands. */
13029 install_element(BGP_NODE, &no_bgp_default_ipv4_unicast_cmd);
13030 install_element(BGP_NODE, &bgp_default_ipv4_unicast_cmd);
13031
13032 /* "bgp network import-check" commands. */
13033 install_element(BGP_NODE, &bgp_network_import_check_cmd);
13034 install_element(BGP_NODE, &bgp_network_import_check_exact_cmd);
13035 install_element(BGP_NODE, &no_bgp_network_import_check_cmd);
13036
13037 /* "bgp default local-preference" commands. */
13038 install_element(BGP_NODE, &bgp_default_local_preference_cmd);
13039 install_element(BGP_NODE, &no_bgp_default_local_preference_cmd);
13040
13041 /* bgp default show-hostname */
13042 install_element(BGP_NODE, &bgp_default_show_hostname_cmd);
13043 install_element(BGP_NODE, &no_bgp_default_show_hostname_cmd);
13044
13045 /* "bgp default subgroup-pkt-queue-max" commands. */
13046 install_element(BGP_NODE, &bgp_default_subgroup_pkt_queue_max_cmd);
13047 install_element(BGP_NODE, &no_bgp_default_subgroup_pkt_queue_max_cmd);
13048
13049 /* bgp ibgp-allow-policy-mods command */
13050 install_element(BGP_NODE, &bgp_rr_allow_outbound_policy_cmd);
13051 install_element(BGP_NODE, &no_bgp_rr_allow_outbound_policy_cmd);
13052
13053 /* "bgp listen limit" commands. */
13054 install_element(BGP_NODE, &bgp_listen_limit_cmd);
13055 install_element(BGP_NODE, &no_bgp_listen_limit_cmd);
13056
13057 /* "bgp listen range" commands. */
13058 install_element(BGP_NODE, &bgp_listen_range_cmd);
13059 install_element(BGP_NODE, &no_bgp_listen_range_cmd);
13060
13061 /* "bgp default shutdown" command */
13062 install_element(BGP_NODE, &bgp_default_shutdown_cmd);
13063
13064 /* "neighbor remote-as" commands. */
13065 install_element(BGP_NODE, &neighbor_remote_as_cmd);
13066 install_element(BGP_NODE, &neighbor_interface_config_cmd);
13067 install_element(BGP_NODE, &neighbor_interface_config_v6only_cmd);
13068 install_element(BGP_NODE, &neighbor_interface_config_remote_as_cmd);
13069 install_element(BGP_NODE,
13070 &neighbor_interface_v6only_config_remote_as_cmd);
13071 install_element(BGP_NODE, &no_neighbor_cmd);
13072 install_element(BGP_NODE, &no_neighbor_interface_config_cmd);
13073
13074 /* "neighbor peer-group" commands. */
13075 install_element(BGP_NODE, &neighbor_peer_group_cmd);
13076 install_element(BGP_NODE, &no_neighbor_peer_group_cmd);
13077 install_element(BGP_NODE,
13078 &no_neighbor_interface_peer_group_remote_as_cmd);
13079
13080 /* "neighbor local-as" commands. */
13081 install_element(BGP_NODE, &neighbor_local_as_cmd);
13082 install_element(BGP_NODE, &neighbor_local_as_no_prepend_cmd);
13083 install_element(BGP_NODE, &neighbor_local_as_no_prepend_replace_as_cmd);
13084 install_element(BGP_NODE, &no_neighbor_local_as_cmd);
13085
13086 /* "neighbor solo" commands. */
13087 install_element(BGP_NODE, &neighbor_solo_cmd);
13088 install_element(BGP_NODE, &no_neighbor_solo_cmd);
13089
13090 /* "neighbor password" commands. */
13091 install_element(BGP_NODE, &neighbor_password_cmd);
13092 install_element(BGP_NODE, &no_neighbor_password_cmd);
13093
13094 /* "neighbor activate" commands. */
13095 install_element(BGP_NODE, &neighbor_activate_hidden_cmd);
13096 install_element(BGP_IPV4_NODE, &neighbor_activate_cmd);
13097 install_element(BGP_IPV4M_NODE, &neighbor_activate_cmd);
13098 install_element(BGP_IPV4L_NODE, &neighbor_activate_cmd);
13099 install_element(BGP_IPV6_NODE, &neighbor_activate_cmd);
13100 install_element(BGP_IPV6M_NODE, &neighbor_activate_cmd);
13101 install_element(BGP_IPV6L_NODE, &neighbor_activate_cmd);
13102 install_element(BGP_VPNV4_NODE, &neighbor_activate_cmd);
13103 install_element(BGP_VPNV6_NODE, &neighbor_activate_cmd);
13104 install_element(BGP_FLOWSPECV4_NODE, &neighbor_activate_cmd);
13105 install_element(BGP_FLOWSPECV6_NODE, &neighbor_activate_cmd);
13106 install_element(BGP_EVPN_NODE, &neighbor_activate_cmd);
13107
13108 /* "no neighbor activate" commands. */
13109 install_element(BGP_NODE, &no_neighbor_activate_hidden_cmd);
13110 install_element(BGP_IPV4_NODE, &no_neighbor_activate_cmd);
13111 install_element(BGP_IPV4M_NODE, &no_neighbor_activate_cmd);
13112 install_element(BGP_IPV4L_NODE, &no_neighbor_activate_cmd);
13113 install_element(BGP_IPV6_NODE, &no_neighbor_activate_cmd);
13114 install_element(BGP_IPV6M_NODE, &no_neighbor_activate_cmd);
13115 install_element(BGP_IPV6L_NODE, &no_neighbor_activate_cmd);
13116 install_element(BGP_VPNV4_NODE, &no_neighbor_activate_cmd);
13117 install_element(BGP_VPNV6_NODE, &no_neighbor_activate_cmd);
13118 install_element(BGP_FLOWSPECV4_NODE, &no_neighbor_activate_cmd);
13119 install_element(BGP_FLOWSPECV6_NODE, &no_neighbor_activate_cmd);
13120 install_element(BGP_EVPN_NODE, &no_neighbor_activate_cmd);
13121
13122 /* "neighbor peer-group" set commands. */
13123 install_element(BGP_NODE, &neighbor_set_peer_group_cmd);
13124 install_element(BGP_IPV4_NODE, &neighbor_set_peer_group_hidden_cmd);
13125 install_element(BGP_IPV4M_NODE, &neighbor_set_peer_group_hidden_cmd);
13126 install_element(BGP_IPV6_NODE, &neighbor_set_peer_group_hidden_cmd);
13127 install_element(BGP_IPV6M_NODE, &neighbor_set_peer_group_hidden_cmd);
13128 install_element(BGP_IPV6L_NODE, &neighbor_set_peer_group_hidden_cmd);
13129 install_element(BGP_VPNV4_NODE, &neighbor_set_peer_group_hidden_cmd);
13130 install_element(BGP_VPNV6_NODE, &neighbor_set_peer_group_hidden_cmd);
13131 install_element(BGP_FLOWSPECV4_NODE,
13132 &neighbor_set_peer_group_hidden_cmd);
13133 install_element(BGP_FLOWSPECV6_NODE,
13134 &neighbor_set_peer_group_hidden_cmd);
13135
13136 /* "no neighbor peer-group unset" commands. */
13137 install_element(BGP_NODE, &no_neighbor_set_peer_group_cmd);
13138 install_element(BGP_IPV4_NODE, &no_neighbor_set_peer_group_hidden_cmd);
13139 install_element(BGP_IPV4M_NODE, &no_neighbor_set_peer_group_hidden_cmd);
13140 install_element(BGP_IPV6_NODE, &no_neighbor_set_peer_group_hidden_cmd);
13141 install_element(BGP_IPV6M_NODE, &no_neighbor_set_peer_group_hidden_cmd);
13142 install_element(BGP_IPV6L_NODE, &no_neighbor_set_peer_group_hidden_cmd);
13143 install_element(BGP_VPNV4_NODE, &no_neighbor_set_peer_group_hidden_cmd);
13144 install_element(BGP_VPNV6_NODE, &no_neighbor_set_peer_group_hidden_cmd);
13145 install_element(BGP_FLOWSPECV4_NODE,
13146 &no_neighbor_set_peer_group_hidden_cmd);
13147 install_element(BGP_FLOWSPECV6_NODE,
13148 &no_neighbor_set_peer_group_hidden_cmd);
13149
13150 /* "neighbor softreconfiguration inbound" commands.*/
13151 install_element(BGP_NODE, &neighbor_soft_reconfiguration_hidden_cmd);
13152 install_element(BGP_NODE, &no_neighbor_soft_reconfiguration_hidden_cmd);
13153 install_element(BGP_IPV4_NODE, &neighbor_soft_reconfiguration_cmd);
13154 install_element(BGP_IPV4_NODE, &no_neighbor_soft_reconfiguration_cmd);
13155 install_element(BGP_IPV4L_NODE, &neighbor_soft_reconfiguration_cmd);
13156 install_element(BGP_IPV4L_NODE, &no_neighbor_soft_reconfiguration_cmd);
13157 install_element(BGP_IPV4M_NODE, &neighbor_soft_reconfiguration_cmd);
13158 install_element(BGP_IPV4M_NODE, &no_neighbor_soft_reconfiguration_cmd);
13159 install_element(BGP_IPV6_NODE, &neighbor_soft_reconfiguration_cmd);
13160 install_element(BGP_IPV6_NODE, &no_neighbor_soft_reconfiguration_cmd);
13161 install_element(BGP_IPV6M_NODE, &neighbor_soft_reconfiguration_cmd);
13162 install_element(BGP_IPV6M_NODE, &no_neighbor_soft_reconfiguration_cmd);
13163 install_element(BGP_IPV6L_NODE, &neighbor_soft_reconfiguration_cmd);
13164 install_element(BGP_IPV6L_NODE, &no_neighbor_soft_reconfiguration_cmd);
13165 install_element(BGP_VPNV4_NODE, &neighbor_soft_reconfiguration_cmd);
13166 install_element(BGP_VPNV4_NODE, &no_neighbor_soft_reconfiguration_cmd);
13167 install_element(BGP_VPNV6_NODE, &neighbor_soft_reconfiguration_cmd);
13168 install_element(BGP_VPNV6_NODE, &no_neighbor_soft_reconfiguration_cmd);
13169 install_element(BGP_FLOWSPECV4_NODE,
13170 &neighbor_soft_reconfiguration_cmd);
13171 install_element(BGP_FLOWSPECV4_NODE,
13172 &no_neighbor_soft_reconfiguration_cmd);
13173 install_element(BGP_FLOWSPECV6_NODE,
13174 &neighbor_soft_reconfiguration_cmd);
13175 install_element(BGP_FLOWSPECV6_NODE,
13176 &no_neighbor_soft_reconfiguration_cmd);
13177 install_element(BGP_EVPN_NODE, &neighbor_soft_reconfiguration_cmd);
13178 install_element(BGP_EVPN_NODE, &no_neighbor_soft_reconfiguration_cmd);
13179
13180 /* "neighbor attribute-unchanged" commands. */
13181 install_element(BGP_NODE, &neighbor_attr_unchanged_hidden_cmd);
13182 install_element(BGP_NODE, &no_neighbor_attr_unchanged_hidden_cmd);
13183 install_element(BGP_IPV4_NODE, &neighbor_attr_unchanged_cmd);
13184 install_element(BGP_IPV4_NODE, &no_neighbor_attr_unchanged_cmd);
13185 install_element(BGP_IPV4M_NODE, &neighbor_attr_unchanged_cmd);
13186 install_element(BGP_IPV4M_NODE, &no_neighbor_attr_unchanged_cmd);
13187 install_element(BGP_IPV4L_NODE, &neighbor_attr_unchanged_cmd);
13188 install_element(BGP_IPV4L_NODE, &no_neighbor_attr_unchanged_cmd);
13189 install_element(BGP_IPV6_NODE, &neighbor_attr_unchanged_cmd);
13190 install_element(BGP_IPV6_NODE, &no_neighbor_attr_unchanged_cmd);
13191 install_element(BGP_IPV6M_NODE, &neighbor_attr_unchanged_cmd);
13192 install_element(BGP_IPV6M_NODE, &no_neighbor_attr_unchanged_cmd);
13193 install_element(BGP_IPV6L_NODE, &neighbor_attr_unchanged_cmd);
13194 install_element(BGP_IPV6L_NODE, &no_neighbor_attr_unchanged_cmd);
13195 install_element(BGP_VPNV4_NODE, &neighbor_attr_unchanged_cmd);
13196 install_element(BGP_VPNV4_NODE, &no_neighbor_attr_unchanged_cmd);
13197 install_element(BGP_VPNV6_NODE, &neighbor_attr_unchanged_cmd);
13198 install_element(BGP_VPNV6_NODE, &no_neighbor_attr_unchanged_cmd);
13199
13200 install_element(BGP_EVPN_NODE, &neighbor_attr_unchanged_cmd);
13201 install_element(BGP_EVPN_NODE, &no_neighbor_attr_unchanged_cmd);
13202
13203 /* "nexthop-local unchanged" commands */
13204 install_element(BGP_IPV6_NODE, &neighbor_nexthop_local_unchanged_cmd);
13205 install_element(BGP_IPV6_NODE,
13206 &no_neighbor_nexthop_local_unchanged_cmd);
13207
13208 /* "neighbor next-hop-self" commands. */
13209 install_element(BGP_NODE, &neighbor_nexthop_self_hidden_cmd);
13210 install_element(BGP_NODE, &no_neighbor_nexthop_self_hidden_cmd);
13211 install_element(BGP_IPV4_NODE, &neighbor_nexthop_self_cmd);
13212 install_element(BGP_IPV4_NODE, &no_neighbor_nexthop_self_cmd);
13213 install_element(BGP_IPV4M_NODE, &neighbor_nexthop_self_cmd);
13214 install_element(BGP_IPV4M_NODE, &no_neighbor_nexthop_self_cmd);
13215 install_element(BGP_IPV4L_NODE, &neighbor_nexthop_self_cmd);
13216 install_element(BGP_IPV4L_NODE, &no_neighbor_nexthop_self_cmd);
13217 install_element(BGP_IPV6_NODE, &neighbor_nexthop_self_cmd);
13218 install_element(BGP_IPV6_NODE, &no_neighbor_nexthop_self_cmd);
13219 install_element(BGP_IPV6M_NODE, &neighbor_nexthop_self_cmd);
13220 install_element(BGP_IPV6M_NODE, &no_neighbor_nexthop_self_cmd);
13221 install_element(BGP_IPV6L_NODE, &neighbor_nexthop_self_cmd);
13222 install_element(BGP_IPV6L_NODE, &no_neighbor_nexthop_self_cmd);
13223 install_element(BGP_VPNV4_NODE, &neighbor_nexthop_self_cmd);
13224 install_element(BGP_VPNV4_NODE, &no_neighbor_nexthop_self_cmd);
13225 install_element(BGP_VPNV6_NODE, &neighbor_nexthop_self_cmd);
13226 install_element(BGP_VPNV6_NODE, &no_neighbor_nexthop_self_cmd);
13227 install_element(BGP_EVPN_NODE, &neighbor_nexthop_self_cmd);
13228 install_element(BGP_EVPN_NODE, &no_neighbor_nexthop_self_cmd);
13229
13230 /* "neighbor next-hop-self force" commands. */
13231 install_element(BGP_NODE, &neighbor_nexthop_self_force_hidden_cmd);
13232 install_element(BGP_NODE, &no_neighbor_nexthop_self_force_hidden_cmd);
13233 install_element(BGP_IPV4_NODE, &neighbor_nexthop_self_force_cmd);
13234 install_element(BGP_IPV4_NODE, &no_neighbor_nexthop_self_force_cmd);
13235 install_element(BGP_IPV4M_NODE, &neighbor_nexthop_self_force_cmd);
13236 install_element(BGP_IPV4M_NODE, &no_neighbor_nexthop_self_force_cmd);
13237 install_element(BGP_IPV4L_NODE, &neighbor_nexthop_self_force_cmd);
13238 install_element(BGP_IPV4L_NODE, &no_neighbor_nexthop_self_force_cmd);
13239 install_element(BGP_IPV6_NODE, &neighbor_nexthop_self_force_cmd);
13240 install_element(BGP_IPV6_NODE, &no_neighbor_nexthop_self_force_cmd);
13241 install_element(BGP_IPV6M_NODE, &neighbor_nexthop_self_force_cmd);
13242 install_element(BGP_IPV6M_NODE, &no_neighbor_nexthop_self_force_cmd);
13243 install_element(BGP_IPV6L_NODE, &neighbor_nexthop_self_force_cmd);
13244 install_element(BGP_IPV6L_NODE, &no_neighbor_nexthop_self_force_cmd);
13245 install_element(BGP_VPNV4_NODE, &neighbor_nexthop_self_force_cmd);
13246 install_element(BGP_VPNV4_NODE, &no_neighbor_nexthop_self_force_cmd);
13247 install_element(BGP_VPNV6_NODE, &neighbor_nexthop_self_force_cmd);
13248 install_element(BGP_VPNV6_NODE, &no_neighbor_nexthop_self_force_cmd);
13249
13250 /* "neighbor as-override" commands. */
13251 install_element(BGP_NODE, &neighbor_as_override_hidden_cmd);
13252 install_element(BGP_NODE, &no_neighbor_as_override_hidden_cmd);
13253 install_element(BGP_IPV4_NODE, &neighbor_as_override_cmd);
13254 install_element(BGP_IPV4_NODE, &no_neighbor_as_override_cmd);
13255 install_element(BGP_IPV4M_NODE, &neighbor_as_override_cmd);
13256 install_element(BGP_IPV4M_NODE, &no_neighbor_as_override_cmd);
13257 install_element(BGP_IPV4L_NODE, &neighbor_as_override_cmd);
13258 install_element(BGP_IPV4L_NODE, &no_neighbor_as_override_cmd);
13259 install_element(BGP_IPV6_NODE, &neighbor_as_override_cmd);
13260 install_element(BGP_IPV6_NODE, &no_neighbor_as_override_cmd);
13261 install_element(BGP_IPV6M_NODE, &neighbor_as_override_cmd);
13262 install_element(BGP_IPV6M_NODE, &no_neighbor_as_override_cmd);
13263 install_element(BGP_IPV6L_NODE, &neighbor_as_override_cmd);
13264 install_element(BGP_IPV6L_NODE, &no_neighbor_as_override_cmd);
13265 install_element(BGP_VPNV4_NODE, &neighbor_as_override_cmd);
13266 install_element(BGP_VPNV4_NODE, &no_neighbor_as_override_cmd);
13267 install_element(BGP_VPNV6_NODE, &neighbor_as_override_cmd);
13268 install_element(BGP_VPNV6_NODE, &no_neighbor_as_override_cmd);
13269
13270 /* "neighbor remove-private-AS" commands. */
13271 install_element(BGP_NODE, &neighbor_remove_private_as_hidden_cmd);
13272 install_element(BGP_NODE, &no_neighbor_remove_private_as_hidden_cmd);
13273 install_element(BGP_NODE, &neighbor_remove_private_as_all_hidden_cmd);
13274 install_element(BGP_NODE,
13275 &no_neighbor_remove_private_as_all_hidden_cmd);
13276 install_element(BGP_NODE,
13277 &neighbor_remove_private_as_replace_as_hidden_cmd);
13278 install_element(BGP_NODE,
13279 &no_neighbor_remove_private_as_replace_as_hidden_cmd);
13280 install_element(BGP_NODE,
13281 &neighbor_remove_private_as_all_replace_as_hidden_cmd);
13282 install_element(
13283 BGP_NODE,
13284 &no_neighbor_remove_private_as_all_replace_as_hidden_cmd);
13285 install_element(BGP_IPV4_NODE, &neighbor_remove_private_as_cmd);
13286 install_element(BGP_IPV4_NODE, &no_neighbor_remove_private_as_cmd);
13287 install_element(BGP_IPV4_NODE, &neighbor_remove_private_as_all_cmd);
13288 install_element(BGP_IPV4_NODE, &no_neighbor_remove_private_as_all_cmd);
13289 install_element(BGP_IPV4_NODE,
13290 &neighbor_remove_private_as_replace_as_cmd);
13291 install_element(BGP_IPV4_NODE,
13292 &no_neighbor_remove_private_as_replace_as_cmd);
13293 install_element(BGP_IPV4_NODE,
13294 &neighbor_remove_private_as_all_replace_as_cmd);
13295 install_element(BGP_IPV4_NODE,
13296 &no_neighbor_remove_private_as_all_replace_as_cmd);
13297 install_element(BGP_IPV4M_NODE, &neighbor_remove_private_as_cmd);
13298 install_element(BGP_IPV4M_NODE, &no_neighbor_remove_private_as_cmd);
13299 install_element(BGP_IPV4M_NODE, &neighbor_remove_private_as_all_cmd);
13300 install_element(BGP_IPV4M_NODE, &no_neighbor_remove_private_as_all_cmd);
13301 install_element(BGP_IPV4M_NODE,
13302 &neighbor_remove_private_as_replace_as_cmd);
13303 install_element(BGP_IPV4M_NODE,
13304 &no_neighbor_remove_private_as_replace_as_cmd);
13305 install_element(BGP_IPV4M_NODE,
13306 &neighbor_remove_private_as_all_replace_as_cmd);
13307 install_element(BGP_IPV4M_NODE,
13308 &no_neighbor_remove_private_as_all_replace_as_cmd);
13309 install_element(BGP_IPV4L_NODE, &neighbor_remove_private_as_cmd);
13310 install_element(BGP_IPV4L_NODE, &no_neighbor_remove_private_as_cmd);
13311 install_element(BGP_IPV4L_NODE, &neighbor_remove_private_as_all_cmd);
13312 install_element(BGP_IPV4L_NODE, &no_neighbor_remove_private_as_all_cmd);
13313 install_element(BGP_IPV4L_NODE,
13314 &neighbor_remove_private_as_replace_as_cmd);
13315 install_element(BGP_IPV4L_NODE,
13316 &no_neighbor_remove_private_as_replace_as_cmd);
13317 install_element(BGP_IPV4L_NODE,
13318 &neighbor_remove_private_as_all_replace_as_cmd);
13319 install_element(BGP_IPV4L_NODE,
13320 &no_neighbor_remove_private_as_all_replace_as_cmd);
13321 install_element(BGP_IPV6_NODE, &neighbor_remove_private_as_cmd);
13322 install_element(BGP_IPV6_NODE, &no_neighbor_remove_private_as_cmd);
13323 install_element(BGP_IPV6_NODE, &neighbor_remove_private_as_all_cmd);
13324 install_element(BGP_IPV6_NODE, &no_neighbor_remove_private_as_all_cmd);
13325 install_element(BGP_IPV6_NODE,
13326 &neighbor_remove_private_as_replace_as_cmd);
13327 install_element(BGP_IPV6_NODE,
13328 &no_neighbor_remove_private_as_replace_as_cmd);
13329 install_element(BGP_IPV6_NODE,
13330 &neighbor_remove_private_as_all_replace_as_cmd);
13331 install_element(BGP_IPV6_NODE,
13332 &no_neighbor_remove_private_as_all_replace_as_cmd);
13333 install_element(BGP_IPV6M_NODE, &neighbor_remove_private_as_cmd);
13334 install_element(BGP_IPV6M_NODE, &no_neighbor_remove_private_as_cmd);
13335 install_element(BGP_IPV6M_NODE, &neighbor_remove_private_as_all_cmd);
13336 install_element(BGP_IPV6M_NODE, &no_neighbor_remove_private_as_all_cmd);
13337 install_element(BGP_IPV6M_NODE,
13338 &neighbor_remove_private_as_replace_as_cmd);
13339 install_element(BGP_IPV6M_NODE,
13340 &no_neighbor_remove_private_as_replace_as_cmd);
13341 install_element(BGP_IPV6M_NODE,
13342 &neighbor_remove_private_as_all_replace_as_cmd);
13343 install_element(BGP_IPV6M_NODE,
13344 &no_neighbor_remove_private_as_all_replace_as_cmd);
13345 install_element(BGP_IPV6L_NODE, &neighbor_remove_private_as_cmd);
13346 install_element(BGP_IPV6L_NODE, &no_neighbor_remove_private_as_cmd);
13347 install_element(BGP_IPV6L_NODE, &neighbor_remove_private_as_all_cmd);
13348 install_element(BGP_IPV6L_NODE, &no_neighbor_remove_private_as_all_cmd);
13349 install_element(BGP_IPV6L_NODE,
13350 &neighbor_remove_private_as_replace_as_cmd);
13351 install_element(BGP_IPV6L_NODE,
13352 &no_neighbor_remove_private_as_replace_as_cmd);
13353 install_element(BGP_IPV6L_NODE,
13354 &neighbor_remove_private_as_all_replace_as_cmd);
13355 install_element(BGP_IPV6L_NODE,
13356 &no_neighbor_remove_private_as_all_replace_as_cmd);
13357 install_element(BGP_VPNV4_NODE, &neighbor_remove_private_as_cmd);
13358 install_element(BGP_VPNV4_NODE, &no_neighbor_remove_private_as_cmd);
13359 install_element(BGP_VPNV4_NODE, &neighbor_remove_private_as_all_cmd);
13360 install_element(BGP_VPNV4_NODE, &no_neighbor_remove_private_as_all_cmd);
13361 install_element(BGP_VPNV4_NODE,
13362 &neighbor_remove_private_as_replace_as_cmd);
13363 install_element(BGP_VPNV4_NODE,
13364 &no_neighbor_remove_private_as_replace_as_cmd);
13365 install_element(BGP_VPNV4_NODE,
13366 &neighbor_remove_private_as_all_replace_as_cmd);
13367 install_element(BGP_VPNV4_NODE,
13368 &no_neighbor_remove_private_as_all_replace_as_cmd);
13369 install_element(BGP_VPNV6_NODE, &neighbor_remove_private_as_cmd);
13370 install_element(BGP_VPNV6_NODE, &no_neighbor_remove_private_as_cmd);
13371 install_element(BGP_VPNV6_NODE, &neighbor_remove_private_as_all_cmd);
13372 install_element(BGP_VPNV6_NODE, &no_neighbor_remove_private_as_all_cmd);
13373 install_element(BGP_VPNV6_NODE,
13374 &neighbor_remove_private_as_replace_as_cmd);
13375 install_element(BGP_VPNV6_NODE,
13376 &no_neighbor_remove_private_as_replace_as_cmd);
13377 install_element(BGP_VPNV6_NODE,
13378 &neighbor_remove_private_as_all_replace_as_cmd);
13379 install_element(BGP_VPNV6_NODE,
13380 &no_neighbor_remove_private_as_all_replace_as_cmd);
13381
13382 /* "neighbor send-community" commands.*/
13383 install_element(BGP_NODE, &neighbor_send_community_hidden_cmd);
13384 install_element(BGP_NODE, &neighbor_send_community_type_hidden_cmd);
13385 install_element(BGP_NODE, &no_neighbor_send_community_hidden_cmd);
13386 install_element(BGP_NODE, &no_neighbor_send_community_type_hidden_cmd);
13387 install_element(BGP_IPV4_NODE, &neighbor_send_community_cmd);
13388 install_element(BGP_IPV4_NODE, &neighbor_send_community_type_cmd);
13389 install_element(BGP_IPV4_NODE, &no_neighbor_send_community_cmd);
13390 install_element(BGP_IPV4_NODE, &no_neighbor_send_community_type_cmd);
13391 install_element(BGP_IPV4M_NODE, &neighbor_send_community_cmd);
13392 install_element(BGP_IPV4M_NODE, &neighbor_send_community_type_cmd);
13393 install_element(BGP_IPV4M_NODE, &no_neighbor_send_community_cmd);
13394 install_element(BGP_IPV4M_NODE, &no_neighbor_send_community_type_cmd);
13395 install_element(BGP_IPV4L_NODE, &neighbor_send_community_cmd);
13396 install_element(BGP_IPV4L_NODE, &neighbor_send_community_type_cmd);
13397 install_element(BGP_IPV4L_NODE, &no_neighbor_send_community_cmd);
13398 install_element(BGP_IPV4L_NODE, &no_neighbor_send_community_type_cmd);
13399 install_element(BGP_IPV6_NODE, &neighbor_send_community_cmd);
13400 install_element(BGP_IPV6_NODE, &neighbor_send_community_type_cmd);
13401 install_element(BGP_IPV6_NODE, &no_neighbor_send_community_cmd);
13402 install_element(BGP_IPV6_NODE, &no_neighbor_send_community_type_cmd);
13403 install_element(BGP_IPV6M_NODE, &neighbor_send_community_cmd);
13404 install_element(BGP_IPV6M_NODE, &neighbor_send_community_type_cmd);
13405 install_element(BGP_IPV6M_NODE, &no_neighbor_send_community_cmd);
13406 install_element(BGP_IPV6M_NODE, &no_neighbor_send_community_type_cmd);
13407 install_element(BGP_IPV6L_NODE, &neighbor_send_community_cmd);
13408 install_element(BGP_IPV6L_NODE, &neighbor_send_community_type_cmd);
13409 install_element(BGP_IPV6L_NODE, &no_neighbor_send_community_cmd);
13410 install_element(BGP_IPV6L_NODE, &no_neighbor_send_community_type_cmd);
13411 install_element(BGP_VPNV4_NODE, &neighbor_send_community_cmd);
13412 install_element(BGP_VPNV4_NODE, &neighbor_send_community_type_cmd);
13413 install_element(BGP_VPNV4_NODE, &no_neighbor_send_community_cmd);
13414 install_element(BGP_VPNV4_NODE, &no_neighbor_send_community_type_cmd);
13415 install_element(BGP_VPNV6_NODE, &neighbor_send_community_cmd);
13416 install_element(BGP_VPNV6_NODE, &neighbor_send_community_type_cmd);
13417 install_element(BGP_VPNV6_NODE, &no_neighbor_send_community_cmd);
13418 install_element(BGP_VPNV6_NODE, &no_neighbor_send_community_type_cmd);
13419
13420 /* "neighbor route-reflector" commands.*/
13421 install_element(BGP_NODE, &neighbor_route_reflector_client_hidden_cmd);
13422 install_element(BGP_NODE,
13423 &no_neighbor_route_reflector_client_hidden_cmd);
13424 install_element(BGP_IPV4_NODE, &neighbor_route_reflector_client_cmd);
13425 install_element(BGP_IPV4_NODE, &no_neighbor_route_reflector_client_cmd);
13426 install_element(BGP_IPV4M_NODE, &neighbor_route_reflector_client_cmd);
13427 install_element(BGP_IPV4M_NODE,
13428 &no_neighbor_route_reflector_client_cmd);
13429 install_element(BGP_IPV4L_NODE, &neighbor_route_reflector_client_cmd);
13430 install_element(BGP_IPV4L_NODE,
13431 &no_neighbor_route_reflector_client_cmd);
13432 install_element(BGP_IPV6_NODE, &neighbor_route_reflector_client_cmd);
13433 install_element(BGP_IPV6_NODE, &no_neighbor_route_reflector_client_cmd);
13434 install_element(BGP_IPV6M_NODE, &neighbor_route_reflector_client_cmd);
13435 install_element(BGP_IPV6M_NODE,
13436 &no_neighbor_route_reflector_client_cmd);
13437 install_element(BGP_IPV6L_NODE, &neighbor_route_reflector_client_cmd);
13438 install_element(BGP_IPV6L_NODE,
13439 &no_neighbor_route_reflector_client_cmd);
13440 install_element(BGP_VPNV4_NODE, &neighbor_route_reflector_client_cmd);
13441 install_element(BGP_VPNV4_NODE,
13442 &no_neighbor_route_reflector_client_cmd);
13443 install_element(BGP_VPNV6_NODE, &neighbor_route_reflector_client_cmd);
13444 install_element(BGP_VPNV6_NODE,
13445 &no_neighbor_route_reflector_client_cmd);
13446 install_element(BGP_FLOWSPECV4_NODE,
13447 &neighbor_route_reflector_client_cmd);
13448 install_element(BGP_FLOWSPECV4_NODE,
13449 &no_neighbor_route_reflector_client_cmd);
13450 install_element(BGP_FLOWSPECV6_NODE,
13451 &neighbor_route_reflector_client_cmd);
13452 install_element(BGP_FLOWSPECV6_NODE,
13453 &no_neighbor_route_reflector_client_cmd);
13454 install_element(BGP_EVPN_NODE, &neighbor_route_reflector_client_cmd);
13455 install_element(BGP_EVPN_NODE, &no_neighbor_route_reflector_client_cmd);
13456
13457 /* "neighbor route-server" commands.*/
13458 install_element(BGP_NODE, &neighbor_route_server_client_hidden_cmd);
13459 install_element(BGP_NODE, &no_neighbor_route_server_client_hidden_cmd);
13460 install_element(BGP_IPV4_NODE, &neighbor_route_server_client_cmd);
13461 install_element(BGP_IPV4_NODE, &no_neighbor_route_server_client_cmd);
13462 install_element(BGP_IPV4M_NODE, &neighbor_route_server_client_cmd);
13463 install_element(BGP_IPV4M_NODE, &no_neighbor_route_server_client_cmd);
13464 install_element(BGP_IPV4L_NODE, &neighbor_route_server_client_cmd);
13465 install_element(BGP_IPV4L_NODE, &no_neighbor_route_server_client_cmd);
13466 install_element(BGP_IPV6_NODE, &neighbor_route_server_client_cmd);
13467 install_element(BGP_IPV6_NODE, &no_neighbor_route_server_client_cmd);
13468 install_element(BGP_IPV6M_NODE, &neighbor_route_server_client_cmd);
13469 install_element(BGP_IPV6M_NODE, &no_neighbor_route_server_client_cmd);
13470 install_element(BGP_IPV6L_NODE, &neighbor_route_server_client_cmd);
13471 install_element(BGP_IPV6L_NODE, &no_neighbor_route_server_client_cmd);
13472 install_element(BGP_VPNV4_NODE, &neighbor_route_server_client_cmd);
13473 install_element(BGP_VPNV4_NODE, &no_neighbor_route_server_client_cmd);
13474 install_element(BGP_VPNV6_NODE, &neighbor_route_server_client_cmd);
13475 install_element(BGP_VPNV6_NODE, &no_neighbor_route_server_client_cmd);
13476 install_element(BGP_EVPN_NODE, &neighbor_route_server_client_cmd);
13477 install_element(BGP_EVPN_NODE, &no_neighbor_route_server_client_cmd);
13478 install_element(BGP_FLOWSPECV4_NODE, &neighbor_route_server_client_cmd);
13479 install_element(BGP_FLOWSPECV4_NODE,
13480 &no_neighbor_route_server_client_cmd);
13481 install_element(BGP_FLOWSPECV6_NODE, &neighbor_route_server_client_cmd);
13482 install_element(BGP_FLOWSPECV6_NODE,
13483 &no_neighbor_route_server_client_cmd);
13484
13485 /* "neighbor addpath-tx-all-paths" commands.*/
13486 install_element(BGP_NODE, &neighbor_addpath_tx_all_paths_hidden_cmd);
13487 install_element(BGP_NODE, &no_neighbor_addpath_tx_all_paths_hidden_cmd);
13488 install_element(BGP_IPV4_NODE, &neighbor_addpath_tx_all_paths_cmd);
13489 install_element(BGP_IPV4_NODE, &no_neighbor_addpath_tx_all_paths_cmd);
13490 install_element(BGP_IPV4M_NODE, &neighbor_addpath_tx_all_paths_cmd);
13491 install_element(BGP_IPV4M_NODE, &no_neighbor_addpath_tx_all_paths_cmd);
13492 install_element(BGP_IPV4L_NODE, &neighbor_addpath_tx_all_paths_cmd);
13493 install_element(BGP_IPV4L_NODE, &no_neighbor_addpath_tx_all_paths_cmd);
13494 install_element(BGP_IPV6_NODE, &neighbor_addpath_tx_all_paths_cmd);
13495 install_element(BGP_IPV6_NODE, &no_neighbor_addpath_tx_all_paths_cmd);
13496 install_element(BGP_IPV6M_NODE, &neighbor_addpath_tx_all_paths_cmd);
13497 install_element(BGP_IPV6M_NODE, &no_neighbor_addpath_tx_all_paths_cmd);
13498 install_element(BGP_IPV6L_NODE, &neighbor_addpath_tx_all_paths_cmd);
13499 install_element(BGP_IPV6L_NODE, &no_neighbor_addpath_tx_all_paths_cmd);
13500 install_element(BGP_VPNV4_NODE, &neighbor_addpath_tx_all_paths_cmd);
13501 install_element(BGP_VPNV4_NODE, &no_neighbor_addpath_tx_all_paths_cmd);
13502 install_element(BGP_VPNV6_NODE, &neighbor_addpath_tx_all_paths_cmd);
13503 install_element(BGP_VPNV6_NODE, &no_neighbor_addpath_tx_all_paths_cmd);
13504
13505 /* "neighbor addpath-tx-bestpath-per-AS" commands.*/
13506 install_element(BGP_NODE,
13507 &neighbor_addpath_tx_bestpath_per_as_hidden_cmd);
13508 install_element(BGP_NODE,
13509 &no_neighbor_addpath_tx_bestpath_per_as_hidden_cmd);
13510 install_element(BGP_IPV4_NODE,
13511 &neighbor_addpath_tx_bestpath_per_as_cmd);
13512 install_element(BGP_IPV4_NODE,
13513 &no_neighbor_addpath_tx_bestpath_per_as_cmd);
13514 install_element(BGP_IPV4M_NODE,
13515 &neighbor_addpath_tx_bestpath_per_as_cmd);
13516 install_element(BGP_IPV4M_NODE,
13517 &no_neighbor_addpath_tx_bestpath_per_as_cmd);
13518 install_element(BGP_IPV4L_NODE,
13519 &neighbor_addpath_tx_bestpath_per_as_cmd);
13520 install_element(BGP_IPV4L_NODE,
13521 &no_neighbor_addpath_tx_bestpath_per_as_cmd);
13522 install_element(BGP_IPV6_NODE,
13523 &neighbor_addpath_tx_bestpath_per_as_cmd);
13524 install_element(BGP_IPV6_NODE,
13525 &no_neighbor_addpath_tx_bestpath_per_as_cmd);
13526 install_element(BGP_IPV6M_NODE,
13527 &neighbor_addpath_tx_bestpath_per_as_cmd);
13528 install_element(BGP_IPV6M_NODE,
13529 &no_neighbor_addpath_tx_bestpath_per_as_cmd);
13530 install_element(BGP_IPV6L_NODE,
13531 &neighbor_addpath_tx_bestpath_per_as_cmd);
13532 install_element(BGP_IPV6L_NODE,
13533 &no_neighbor_addpath_tx_bestpath_per_as_cmd);
13534 install_element(BGP_VPNV4_NODE,
13535 &neighbor_addpath_tx_bestpath_per_as_cmd);
13536 install_element(BGP_VPNV4_NODE,
13537 &no_neighbor_addpath_tx_bestpath_per_as_cmd);
13538 install_element(BGP_VPNV6_NODE,
13539 &neighbor_addpath_tx_bestpath_per_as_cmd);
13540 install_element(BGP_VPNV6_NODE,
13541 &no_neighbor_addpath_tx_bestpath_per_as_cmd);
13542
13543 /* "neighbor passive" commands. */
13544 install_element(BGP_NODE, &neighbor_passive_cmd);
13545 install_element(BGP_NODE, &no_neighbor_passive_cmd);
13546
13547
13548 /* "neighbor shutdown" commands. */
13549 install_element(BGP_NODE, &neighbor_shutdown_cmd);
13550 install_element(BGP_NODE, &no_neighbor_shutdown_cmd);
13551 install_element(BGP_NODE, &neighbor_shutdown_msg_cmd);
13552 install_element(BGP_NODE, &no_neighbor_shutdown_msg_cmd);
13553
13554 /* "neighbor capability extended-nexthop" commands.*/
13555 install_element(BGP_NODE, &neighbor_capability_enhe_cmd);
13556 install_element(BGP_NODE, &no_neighbor_capability_enhe_cmd);
13557
13558 /* "neighbor capability orf prefix-list" commands.*/
13559 install_element(BGP_NODE, &neighbor_capability_orf_prefix_hidden_cmd);
13560 install_element(BGP_NODE,
13561 &no_neighbor_capability_orf_prefix_hidden_cmd);
13562 install_element(BGP_IPV4_NODE, &neighbor_capability_orf_prefix_cmd);
13563 install_element(BGP_IPV4_NODE, &no_neighbor_capability_orf_prefix_cmd);
13564 install_element(BGP_IPV4M_NODE, &neighbor_capability_orf_prefix_cmd);
13565 install_element(BGP_IPV4M_NODE, &no_neighbor_capability_orf_prefix_cmd);
13566 install_element(BGP_IPV4L_NODE, &neighbor_capability_orf_prefix_cmd);
13567 install_element(BGP_IPV4L_NODE, &no_neighbor_capability_orf_prefix_cmd);
13568 install_element(BGP_IPV6_NODE, &neighbor_capability_orf_prefix_cmd);
13569 install_element(BGP_IPV6_NODE, &no_neighbor_capability_orf_prefix_cmd);
13570 install_element(BGP_IPV6M_NODE, &neighbor_capability_orf_prefix_cmd);
13571 install_element(BGP_IPV6M_NODE, &no_neighbor_capability_orf_prefix_cmd);
13572 install_element(BGP_IPV6L_NODE, &neighbor_capability_orf_prefix_cmd);
13573 install_element(BGP_IPV6L_NODE, &no_neighbor_capability_orf_prefix_cmd);
13574
13575 /* "neighbor capability dynamic" commands.*/
13576 install_element(BGP_NODE, &neighbor_capability_dynamic_cmd);
13577 install_element(BGP_NODE, &no_neighbor_capability_dynamic_cmd);
13578
13579 /* "neighbor dont-capability-negotiate" commands. */
13580 install_element(BGP_NODE, &neighbor_dont_capability_negotiate_cmd);
13581 install_element(BGP_NODE, &no_neighbor_dont_capability_negotiate_cmd);
13582
13583 /* "neighbor ebgp-multihop" commands. */
13584 install_element(BGP_NODE, &neighbor_ebgp_multihop_cmd);
13585 install_element(BGP_NODE, &neighbor_ebgp_multihop_ttl_cmd);
13586 install_element(BGP_NODE, &no_neighbor_ebgp_multihop_cmd);
13587
13588 /* "neighbor disable-connected-check" commands. */
13589 install_element(BGP_NODE, &neighbor_disable_connected_check_cmd);
13590 install_element(BGP_NODE, &no_neighbor_disable_connected_check_cmd);
13591
13592 /* "neighbor enforce-first-as" commands. */
13593 install_element(BGP_NODE, &neighbor_enforce_first_as_cmd);
13594 install_element(BGP_NODE, &no_neighbor_enforce_first_as_cmd);
13595
13596 /* "neighbor description" commands. */
13597 install_element(BGP_NODE, &neighbor_description_cmd);
13598 install_element(BGP_NODE, &no_neighbor_description_cmd);
13599 install_element(BGP_NODE, &no_neighbor_description_comment_cmd);
13600
13601 /* "neighbor update-source" commands. "*/
13602 install_element(BGP_NODE, &neighbor_update_source_cmd);
13603 install_element(BGP_NODE, &no_neighbor_update_source_cmd);
13604
13605 /* "neighbor default-originate" commands. */
13606 install_element(BGP_NODE, &neighbor_default_originate_hidden_cmd);
13607 install_element(BGP_NODE, &neighbor_default_originate_rmap_hidden_cmd);
13608 install_element(BGP_NODE, &no_neighbor_default_originate_hidden_cmd);
13609 install_element(BGP_IPV4_NODE, &neighbor_default_originate_cmd);
13610 install_element(BGP_IPV4_NODE, &neighbor_default_originate_rmap_cmd);
13611 install_element(BGP_IPV4_NODE, &no_neighbor_default_originate_cmd);
13612 install_element(BGP_IPV4M_NODE, &neighbor_default_originate_cmd);
13613 install_element(BGP_IPV4M_NODE, &neighbor_default_originate_rmap_cmd);
13614 install_element(BGP_IPV4M_NODE, &no_neighbor_default_originate_cmd);
13615 install_element(BGP_IPV4L_NODE, &neighbor_default_originate_cmd);
13616 install_element(BGP_IPV4L_NODE, &neighbor_default_originate_rmap_cmd);
13617 install_element(BGP_IPV4L_NODE, &no_neighbor_default_originate_cmd);
13618 install_element(BGP_IPV6_NODE, &neighbor_default_originate_cmd);
13619 install_element(BGP_IPV6_NODE, &neighbor_default_originate_rmap_cmd);
13620 install_element(BGP_IPV6_NODE, &no_neighbor_default_originate_cmd);
13621 install_element(BGP_IPV6M_NODE, &neighbor_default_originate_cmd);
13622 install_element(BGP_IPV6M_NODE, &neighbor_default_originate_rmap_cmd);
13623 install_element(BGP_IPV6M_NODE, &no_neighbor_default_originate_cmd);
13624 install_element(BGP_IPV6L_NODE, &neighbor_default_originate_cmd);
13625 install_element(BGP_IPV6L_NODE, &neighbor_default_originate_rmap_cmd);
13626 install_element(BGP_IPV6L_NODE, &no_neighbor_default_originate_cmd);
13627
13628 /* "neighbor port" commands. */
13629 install_element(BGP_NODE, &neighbor_port_cmd);
13630 install_element(BGP_NODE, &no_neighbor_port_cmd);
13631
13632 /* "neighbor weight" commands. */
13633 install_element(BGP_NODE, &neighbor_weight_hidden_cmd);
13634 install_element(BGP_NODE, &no_neighbor_weight_hidden_cmd);
13635
13636 install_element(BGP_IPV4_NODE, &neighbor_weight_cmd);
13637 install_element(BGP_IPV4_NODE, &no_neighbor_weight_cmd);
13638 install_element(BGP_IPV4M_NODE, &neighbor_weight_cmd);
13639 install_element(BGP_IPV4M_NODE, &no_neighbor_weight_cmd);
13640 install_element(BGP_IPV4L_NODE, &neighbor_weight_cmd);
13641 install_element(BGP_IPV4L_NODE, &no_neighbor_weight_cmd);
13642 install_element(BGP_IPV6_NODE, &neighbor_weight_cmd);
13643 install_element(BGP_IPV6_NODE, &no_neighbor_weight_cmd);
13644 install_element(BGP_IPV6M_NODE, &neighbor_weight_cmd);
13645 install_element(BGP_IPV6M_NODE, &no_neighbor_weight_cmd);
13646 install_element(BGP_IPV6L_NODE, &neighbor_weight_cmd);
13647 install_element(BGP_IPV6L_NODE, &no_neighbor_weight_cmd);
13648 install_element(BGP_VPNV4_NODE, &neighbor_weight_cmd);
13649 install_element(BGP_VPNV4_NODE, &no_neighbor_weight_cmd);
13650 install_element(BGP_VPNV6_NODE, &neighbor_weight_cmd);
13651 install_element(BGP_VPNV6_NODE, &no_neighbor_weight_cmd);
13652
13653 /* "neighbor override-capability" commands. */
13654 install_element(BGP_NODE, &neighbor_override_capability_cmd);
13655 install_element(BGP_NODE, &no_neighbor_override_capability_cmd);
13656
13657 /* "neighbor strict-capability-match" commands. */
13658 install_element(BGP_NODE, &neighbor_strict_capability_cmd);
13659 install_element(BGP_NODE, &no_neighbor_strict_capability_cmd);
13660
13661 /* "neighbor timers" commands. */
13662 install_element(BGP_NODE, &neighbor_timers_cmd);
13663 install_element(BGP_NODE, &no_neighbor_timers_cmd);
13664
13665 /* "neighbor timers connect" commands. */
13666 install_element(BGP_NODE, &neighbor_timers_connect_cmd);
13667 install_element(BGP_NODE, &no_neighbor_timers_connect_cmd);
13668
13669 /* "neighbor advertisement-interval" commands. */
13670 install_element(BGP_NODE, &neighbor_advertise_interval_cmd);
13671 install_element(BGP_NODE, &no_neighbor_advertise_interval_cmd);
13672
13673 /* "neighbor interface" commands. */
13674 install_element(BGP_NODE, &neighbor_interface_cmd);
13675 install_element(BGP_NODE, &no_neighbor_interface_cmd);
13676
13677 /* "neighbor distribute" commands. */
13678 install_element(BGP_NODE, &neighbor_distribute_list_hidden_cmd);
13679 install_element(BGP_NODE, &no_neighbor_distribute_list_hidden_cmd);
13680 install_element(BGP_IPV4_NODE, &neighbor_distribute_list_cmd);
13681 install_element(BGP_IPV4_NODE, &no_neighbor_distribute_list_cmd);
13682 install_element(BGP_IPV4M_NODE, &neighbor_distribute_list_cmd);
13683 install_element(BGP_IPV4M_NODE, &no_neighbor_distribute_list_cmd);
13684 install_element(BGP_IPV4L_NODE, &neighbor_distribute_list_cmd);
13685 install_element(BGP_IPV4L_NODE, &no_neighbor_distribute_list_cmd);
13686 install_element(BGP_IPV6_NODE, &neighbor_distribute_list_cmd);
13687 install_element(BGP_IPV6_NODE, &no_neighbor_distribute_list_cmd);
13688 install_element(BGP_IPV6M_NODE, &neighbor_distribute_list_cmd);
13689 install_element(BGP_IPV6M_NODE, &no_neighbor_distribute_list_cmd);
13690 install_element(BGP_IPV6L_NODE, &neighbor_distribute_list_cmd);
13691 install_element(BGP_IPV6L_NODE, &no_neighbor_distribute_list_cmd);
13692 install_element(BGP_VPNV4_NODE, &neighbor_distribute_list_cmd);
13693 install_element(BGP_VPNV4_NODE, &no_neighbor_distribute_list_cmd);
13694 install_element(BGP_VPNV6_NODE, &neighbor_distribute_list_cmd);
13695 install_element(BGP_VPNV6_NODE, &no_neighbor_distribute_list_cmd);
13696
13697 /* "neighbor prefix-list" commands. */
13698 install_element(BGP_NODE, &neighbor_prefix_list_hidden_cmd);
13699 install_element(BGP_NODE, &no_neighbor_prefix_list_hidden_cmd);
13700 install_element(BGP_IPV4_NODE, &neighbor_prefix_list_cmd);
13701 install_element(BGP_IPV4_NODE, &no_neighbor_prefix_list_cmd);
13702 install_element(BGP_IPV4M_NODE, &neighbor_prefix_list_cmd);
13703 install_element(BGP_IPV4M_NODE, &no_neighbor_prefix_list_cmd);
13704 install_element(BGP_IPV4L_NODE, &neighbor_prefix_list_cmd);
13705 install_element(BGP_IPV4L_NODE, &no_neighbor_prefix_list_cmd);
13706 install_element(BGP_IPV6_NODE, &neighbor_prefix_list_cmd);
13707 install_element(BGP_IPV6_NODE, &no_neighbor_prefix_list_cmd);
13708 install_element(BGP_IPV6M_NODE, &neighbor_prefix_list_cmd);
13709 install_element(BGP_IPV6M_NODE, &no_neighbor_prefix_list_cmd);
13710 install_element(BGP_IPV6L_NODE, &neighbor_prefix_list_cmd);
13711 install_element(BGP_IPV6L_NODE, &no_neighbor_prefix_list_cmd);
13712 install_element(BGP_VPNV4_NODE, &neighbor_prefix_list_cmd);
13713 install_element(BGP_VPNV4_NODE, &no_neighbor_prefix_list_cmd);
13714 install_element(BGP_VPNV6_NODE, &neighbor_prefix_list_cmd);
13715 install_element(BGP_VPNV6_NODE, &no_neighbor_prefix_list_cmd);
13716 install_element(BGP_FLOWSPECV4_NODE, &neighbor_prefix_list_cmd);
13717 install_element(BGP_FLOWSPECV4_NODE, &no_neighbor_prefix_list_cmd);
13718 install_element(BGP_FLOWSPECV6_NODE, &neighbor_prefix_list_cmd);
13719 install_element(BGP_FLOWSPECV6_NODE, &no_neighbor_prefix_list_cmd);
13720
13721 /* "neighbor filter-list" commands. */
13722 install_element(BGP_NODE, &neighbor_filter_list_hidden_cmd);
13723 install_element(BGP_NODE, &no_neighbor_filter_list_hidden_cmd);
13724 install_element(BGP_IPV4_NODE, &neighbor_filter_list_cmd);
13725 install_element(BGP_IPV4_NODE, &no_neighbor_filter_list_cmd);
13726 install_element(BGP_IPV4M_NODE, &neighbor_filter_list_cmd);
13727 install_element(BGP_IPV4M_NODE, &no_neighbor_filter_list_cmd);
13728 install_element(BGP_IPV4L_NODE, &neighbor_filter_list_cmd);
13729 install_element(BGP_IPV4L_NODE, &no_neighbor_filter_list_cmd);
13730 install_element(BGP_IPV6_NODE, &neighbor_filter_list_cmd);
13731 install_element(BGP_IPV6_NODE, &no_neighbor_filter_list_cmd);
13732 install_element(BGP_IPV6M_NODE, &neighbor_filter_list_cmd);
13733 install_element(BGP_IPV6M_NODE, &no_neighbor_filter_list_cmd);
13734 install_element(BGP_IPV6L_NODE, &neighbor_filter_list_cmd);
13735 install_element(BGP_IPV6L_NODE, &no_neighbor_filter_list_cmd);
13736 install_element(BGP_VPNV4_NODE, &neighbor_filter_list_cmd);
13737 install_element(BGP_VPNV4_NODE, &no_neighbor_filter_list_cmd);
13738 install_element(BGP_VPNV6_NODE, &neighbor_filter_list_cmd);
13739 install_element(BGP_VPNV6_NODE, &no_neighbor_filter_list_cmd);
13740 install_element(BGP_FLOWSPECV4_NODE, &neighbor_filter_list_cmd);
13741 install_element(BGP_FLOWSPECV4_NODE, &no_neighbor_filter_list_cmd);
13742 install_element(BGP_FLOWSPECV6_NODE, &neighbor_filter_list_cmd);
13743 install_element(BGP_FLOWSPECV6_NODE, &no_neighbor_filter_list_cmd);
13744
13745 /* "neighbor route-map" commands. */
13746 install_element(BGP_NODE, &neighbor_route_map_hidden_cmd);
13747 install_element(BGP_NODE, &no_neighbor_route_map_hidden_cmd);
13748 install_element(BGP_IPV4_NODE, &neighbor_route_map_cmd);
13749 install_element(BGP_IPV4_NODE, &no_neighbor_route_map_cmd);
13750 install_element(BGP_IPV4M_NODE, &neighbor_route_map_cmd);
13751 install_element(BGP_IPV4M_NODE, &no_neighbor_route_map_cmd);
13752 install_element(BGP_IPV4L_NODE, &neighbor_route_map_cmd);
13753 install_element(BGP_IPV4L_NODE, &no_neighbor_route_map_cmd);
13754 install_element(BGP_IPV6_NODE, &neighbor_route_map_cmd);
13755 install_element(BGP_IPV6_NODE, &no_neighbor_route_map_cmd);
13756 install_element(BGP_IPV6M_NODE, &neighbor_route_map_cmd);
13757 install_element(BGP_IPV6M_NODE, &no_neighbor_route_map_cmd);
13758 install_element(BGP_IPV6L_NODE, &neighbor_route_map_cmd);
13759 install_element(BGP_IPV6L_NODE, &no_neighbor_route_map_cmd);
13760 install_element(BGP_VPNV4_NODE, &neighbor_route_map_cmd);
13761 install_element(BGP_VPNV4_NODE, &no_neighbor_route_map_cmd);
13762 install_element(BGP_VPNV6_NODE, &neighbor_route_map_cmd);
13763 install_element(BGP_VPNV6_NODE, &no_neighbor_route_map_cmd);
13764 install_element(BGP_FLOWSPECV4_NODE, &neighbor_route_map_cmd);
13765 install_element(BGP_FLOWSPECV4_NODE, &no_neighbor_route_map_cmd);
13766 install_element(BGP_FLOWSPECV6_NODE, &neighbor_route_map_cmd);
13767 install_element(BGP_FLOWSPECV6_NODE, &no_neighbor_route_map_cmd);
13768 install_element(BGP_EVPN_NODE, &neighbor_route_map_cmd);
13769 install_element(BGP_EVPN_NODE, &no_neighbor_route_map_cmd);
13770
13771 /* "neighbor unsuppress-map" commands. */
13772 install_element(BGP_NODE, &neighbor_unsuppress_map_hidden_cmd);
13773 install_element(BGP_NODE, &no_neighbor_unsuppress_map_hidden_cmd);
13774 install_element(BGP_IPV4_NODE, &neighbor_unsuppress_map_cmd);
13775 install_element(BGP_IPV4_NODE, &no_neighbor_unsuppress_map_cmd);
13776 install_element(BGP_IPV4M_NODE, &neighbor_unsuppress_map_cmd);
13777 install_element(BGP_IPV4M_NODE, &no_neighbor_unsuppress_map_cmd);
13778 install_element(BGP_IPV4L_NODE, &neighbor_unsuppress_map_cmd);
13779 install_element(BGP_IPV4L_NODE, &no_neighbor_unsuppress_map_cmd);
13780 install_element(BGP_IPV6_NODE, &neighbor_unsuppress_map_cmd);
13781 install_element(BGP_IPV6_NODE, &no_neighbor_unsuppress_map_cmd);
13782 install_element(BGP_IPV6M_NODE, &neighbor_unsuppress_map_cmd);
13783 install_element(BGP_IPV6M_NODE, &no_neighbor_unsuppress_map_cmd);
13784 install_element(BGP_IPV6L_NODE, &neighbor_unsuppress_map_cmd);
13785 install_element(BGP_IPV6L_NODE, &no_neighbor_unsuppress_map_cmd);
13786 install_element(BGP_VPNV4_NODE, &neighbor_unsuppress_map_cmd);
13787 install_element(BGP_VPNV4_NODE, &no_neighbor_unsuppress_map_cmd);
13788 install_element(BGP_VPNV6_NODE, &neighbor_unsuppress_map_cmd);
13789 install_element(BGP_VPNV6_NODE, &no_neighbor_unsuppress_map_cmd);
13790
13791 /* "neighbor maximum-prefix" commands. */
13792 install_element(BGP_NODE, &neighbor_maximum_prefix_hidden_cmd);
13793 install_element(BGP_NODE,
13794 &neighbor_maximum_prefix_threshold_hidden_cmd);
13795 install_element(BGP_NODE, &neighbor_maximum_prefix_warning_hidden_cmd);
13796 install_element(BGP_NODE,
13797 &neighbor_maximum_prefix_threshold_warning_hidden_cmd);
13798 install_element(BGP_NODE, &neighbor_maximum_prefix_restart_hidden_cmd);
13799 install_element(BGP_NODE,
13800 &neighbor_maximum_prefix_threshold_restart_hidden_cmd);
13801 install_element(BGP_NODE, &no_neighbor_maximum_prefix_hidden_cmd);
13802 install_element(BGP_IPV4_NODE, &neighbor_maximum_prefix_cmd);
13803 install_element(BGP_IPV4_NODE, &neighbor_maximum_prefix_threshold_cmd);
13804 install_element(BGP_IPV4_NODE, &neighbor_maximum_prefix_warning_cmd);
13805 install_element(BGP_IPV4_NODE,
13806 &neighbor_maximum_prefix_threshold_warning_cmd);
13807 install_element(BGP_IPV4_NODE, &neighbor_maximum_prefix_restart_cmd);
13808 install_element(BGP_IPV4_NODE,
13809 &neighbor_maximum_prefix_threshold_restart_cmd);
13810 install_element(BGP_IPV4_NODE, &no_neighbor_maximum_prefix_cmd);
13811 install_element(BGP_IPV4M_NODE, &neighbor_maximum_prefix_cmd);
13812 install_element(BGP_IPV4M_NODE, &neighbor_maximum_prefix_threshold_cmd);
13813 install_element(BGP_IPV4M_NODE, &neighbor_maximum_prefix_warning_cmd);
13814 install_element(BGP_IPV4M_NODE,
13815 &neighbor_maximum_prefix_threshold_warning_cmd);
13816 install_element(BGP_IPV4M_NODE, &neighbor_maximum_prefix_restart_cmd);
13817 install_element(BGP_IPV4M_NODE,
13818 &neighbor_maximum_prefix_threshold_restart_cmd);
13819 install_element(BGP_IPV4M_NODE, &no_neighbor_maximum_prefix_cmd);
13820 install_element(BGP_IPV4L_NODE, &neighbor_maximum_prefix_cmd);
13821 install_element(BGP_IPV4L_NODE, &neighbor_maximum_prefix_threshold_cmd);
13822 install_element(BGP_IPV4L_NODE, &neighbor_maximum_prefix_warning_cmd);
13823 install_element(BGP_IPV4L_NODE,
13824 &neighbor_maximum_prefix_threshold_warning_cmd);
13825 install_element(BGP_IPV4L_NODE, &neighbor_maximum_prefix_restart_cmd);
13826 install_element(BGP_IPV4L_NODE,
13827 &neighbor_maximum_prefix_threshold_restart_cmd);
13828 install_element(BGP_IPV4L_NODE, &no_neighbor_maximum_prefix_cmd);
13829 install_element(BGP_IPV6_NODE, &neighbor_maximum_prefix_cmd);
13830 install_element(BGP_IPV6_NODE, &neighbor_maximum_prefix_threshold_cmd);
13831 install_element(BGP_IPV6_NODE, &neighbor_maximum_prefix_warning_cmd);
13832 install_element(BGP_IPV6_NODE,
13833 &neighbor_maximum_prefix_threshold_warning_cmd);
13834 install_element(BGP_IPV6_NODE, &neighbor_maximum_prefix_restart_cmd);
13835 install_element(BGP_IPV6_NODE,
13836 &neighbor_maximum_prefix_threshold_restart_cmd);
13837 install_element(BGP_IPV6_NODE, &no_neighbor_maximum_prefix_cmd);
13838 install_element(BGP_IPV6M_NODE, &neighbor_maximum_prefix_cmd);
13839 install_element(BGP_IPV6M_NODE, &neighbor_maximum_prefix_threshold_cmd);
13840 install_element(BGP_IPV6M_NODE, &neighbor_maximum_prefix_warning_cmd);
13841 install_element(BGP_IPV6M_NODE,
13842 &neighbor_maximum_prefix_threshold_warning_cmd);
13843 install_element(BGP_IPV6M_NODE, &neighbor_maximum_prefix_restart_cmd);
13844 install_element(BGP_IPV6M_NODE,
13845 &neighbor_maximum_prefix_threshold_restart_cmd);
13846 install_element(BGP_IPV6M_NODE, &no_neighbor_maximum_prefix_cmd);
13847 install_element(BGP_IPV6L_NODE, &neighbor_maximum_prefix_cmd);
13848 install_element(BGP_IPV6L_NODE, &neighbor_maximum_prefix_threshold_cmd);
13849 install_element(BGP_IPV6L_NODE, &neighbor_maximum_prefix_warning_cmd);
13850 install_element(BGP_IPV6L_NODE,
13851 &neighbor_maximum_prefix_threshold_warning_cmd);
13852 install_element(BGP_IPV6L_NODE, &neighbor_maximum_prefix_restart_cmd);
13853 install_element(BGP_IPV6L_NODE,
13854 &neighbor_maximum_prefix_threshold_restart_cmd);
13855 install_element(BGP_IPV6L_NODE, &no_neighbor_maximum_prefix_cmd);
13856 install_element(BGP_VPNV4_NODE, &neighbor_maximum_prefix_cmd);
13857 install_element(BGP_VPNV4_NODE, &neighbor_maximum_prefix_threshold_cmd);
13858 install_element(BGP_VPNV4_NODE, &neighbor_maximum_prefix_warning_cmd);
13859 install_element(BGP_VPNV4_NODE,
13860 &neighbor_maximum_prefix_threshold_warning_cmd);
13861 install_element(BGP_VPNV4_NODE, &neighbor_maximum_prefix_restart_cmd);
13862 install_element(BGP_VPNV4_NODE,
13863 &neighbor_maximum_prefix_threshold_restart_cmd);
13864 install_element(BGP_VPNV4_NODE, &no_neighbor_maximum_prefix_cmd);
13865 install_element(BGP_VPNV6_NODE, &neighbor_maximum_prefix_cmd);
13866 install_element(BGP_VPNV6_NODE, &neighbor_maximum_prefix_threshold_cmd);
13867 install_element(BGP_VPNV6_NODE, &neighbor_maximum_prefix_warning_cmd);
13868 install_element(BGP_VPNV6_NODE,
13869 &neighbor_maximum_prefix_threshold_warning_cmd);
13870 install_element(BGP_VPNV6_NODE, &neighbor_maximum_prefix_restart_cmd);
13871 install_element(BGP_VPNV6_NODE,
13872 &neighbor_maximum_prefix_threshold_restart_cmd);
13873 install_element(BGP_VPNV6_NODE, &no_neighbor_maximum_prefix_cmd);
13874
13875 /* "neighbor allowas-in" */
13876 install_element(BGP_NODE, &neighbor_allowas_in_hidden_cmd);
13877 install_element(BGP_NODE, &no_neighbor_allowas_in_hidden_cmd);
13878 install_element(BGP_IPV4_NODE, &neighbor_allowas_in_cmd);
13879 install_element(BGP_IPV4_NODE, &no_neighbor_allowas_in_cmd);
13880 install_element(BGP_IPV4M_NODE, &neighbor_allowas_in_cmd);
13881 install_element(BGP_IPV4M_NODE, &no_neighbor_allowas_in_cmd);
13882 install_element(BGP_IPV4L_NODE, &neighbor_allowas_in_cmd);
13883 install_element(BGP_IPV4L_NODE, &no_neighbor_allowas_in_cmd);
13884 install_element(BGP_IPV6_NODE, &neighbor_allowas_in_cmd);
13885 install_element(BGP_IPV6_NODE, &no_neighbor_allowas_in_cmd);
13886 install_element(BGP_IPV6M_NODE, &neighbor_allowas_in_cmd);
13887 install_element(BGP_IPV6M_NODE, &no_neighbor_allowas_in_cmd);
13888 install_element(BGP_IPV6L_NODE, &neighbor_allowas_in_cmd);
13889 install_element(BGP_IPV6L_NODE, &no_neighbor_allowas_in_cmd);
13890 install_element(BGP_VPNV4_NODE, &neighbor_allowas_in_cmd);
13891 install_element(BGP_VPNV4_NODE, &no_neighbor_allowas_in_cmd);
13892 install_element(BGP_VPNV6_NODE, &neighbor_allowas_in_cmd);
13893 install_element(BGP_VPNV6_NODE, &no_neighbor_allowas_in_cmd);
13894 install_element(BGP_EVPN_NODE, &neighbor_allowas_in_cmd);
13895 install_element(BGP_EVPN_NODE, &no_neighbor_allowas_in_cmd);
13896
13897 /* address-family commands. */
13898 install_element(BGP_NODE, &address_family_ipv4_safi_cmd);
13899 install_element(BGP_NODE, &address_family_ipv6_safi_cmd);
13900 #ifdef KEEP_OLD_VPN_COMMANDS
13901 install_element(BGP_NODE, &address_family_vpnv4_cmd);
13902 install_element(BGP_NODE, &address_family_vpnv6_cmd);
13903 #endif /* KEEP_OLD_VPN_COMMANDS */
13904
13905 install_element(BGP_NODE, &address_family_evpn_cmd);
13906
13907 /* "exit-address-family" command. */
13908 install_element(BGP_IPV4_NODE, &exit_address_family_cmd);
13909 install_element(BGP_IPV4M_NODE, &exit_address_family_cmd);
13910 install_element(BGP_IPV4L_NODE, &exit_address_family_cmd);
13911 install_element(BGP_IPV6_NODE, &exit_address_family_cmd);
13912 install_element(BGP_IPV6M_NODE, &exit_address_family_cmd);
13913 install_element(BGP_IPV6L_NODE, &exit_address_family_cmd);
13914 install_element(BGP_VPNV4_NODE, &exit_address_family_cmd);
13915 install_element(BGP_VPNV6_NODE, &exit_address_family_cmd);
13916 install_element(BGP_FLOWSPECV4_NODE, &exit_address_family_cmd);
13917 install_element(BGP_FLOWSPECV6_NODE, &exit_address_family_cmd);
13918 install_element(BGP_EVPN_NODE, &exit_address_family_cmd);
13919
13920 /* "clear ip bgp commands" */
13921 install_element(ENABLE_NODE, &clear_ip_bgp_all_cmd);
13922
13923 /* clear ip bgp prefix */
13924 install_element(ENABLE_NODE, &clear_ip_bgp_prefix_cmd);
13925 install_element(ENABLE_NODE, &clear_bgp_ipv6_safi_prefix_cmd);
13926 install_element(ENABLE_NODE, &clear_bgp_instance_ipv6_safi_prefix_cmd);
13927
13928 /* "show [ip] bgp summary" commands. */
13929 install_element(VIEW_NODE, &show_bgp_instance_all_ipv6_updgrps_cmd);
13930 install_element(VIEW_NODE, &show_bgp_l2vpn_evpn_updgrps_cmd);
13931 install_element(VIEW_NODE, &show_bgp_instance_updgrps_stats_cmd);
13932 install_element(VIEW_NODE, &show_bgp_updgrps_stats_cmd);
13933 install_element(VIEW_NODE, &show_ip_bgp_instance_updgrps_adj_s_cmd);
13934 install_element(VIEW_NODE, &show_ip_bgp_summary_cmd);
13935 install_element(VIEW_NODE, &show_ip_bgp_updgrps_cmd);
13936
13937 /* "show [ip] bgp neighbors" commands. */
13938 install_element(VIEW_NODE, &show_ip_bgp_neighbors_cmd);
13939
13940 /* "show [ip] bgp peer-group" commands. */
13941 install_element(VIEW_NODE, &show_ip_bgp_peer_groups_cmd);
13942
13943 /* "show [ip] bgp paths" commands. */
13944 install_element(VIEW_NODE, &show_ip_bgp_paths_cmd);
13945
13946 /* "show [ip] bgp community" commands. */
13947 install_element(VIEW_NODE, &show_ip_bgp_community_info_cmd);
13948
13949 /* "show ip bgp large-community" commands. */
13950 install_element(VIEW_NODE, &show_ip_bgp_lcommunity_info_cmd);
13951 /* "show [ip] bgp attribute-info" commands. */
13952 install_element(VIEW_NODE, &show_ip_bgp_attr_info_cmd);
13953 /* "show [ip] bgp route-leak" command */
13954 install_element(VIEW_NODE, &show_ip_bgp_route_leak_cmd);
13955
13956 /* "redistribute" commands. */
13957 install_element(BGP_NODE, &bgp_redistribute_ipv4_hidden_cmd);
13958 install_element(BGP_NODE, &no_bgp_redistribute_ipv4_hidden_cmd);
13959 install_element(BGP_NODE, &bgp_redistribute_ipv4_rmap_hidden_cmd);
13960 install_element(BGP_NODE, &bgp_redistribute_ipv4_metric_hidden_cmd);
13961 install_element(BGP_NODE,
13962 &bgp_redistribute_ipv4_rmap_metric_hidden_cmd);
13963 install_element(BGP_NODE,
13964 &bgp_redistribute_ipv4_metric_rmap_hidden_cmd);
13965 install_element(BGP_NODE, &bgp_redistribute_ipv4_ospf_hidden_cmd);
13966 install_element(BGP_NODE, &no_bgp_redistribute_ipv4_ospf_hidden_cmd);
13967 install_element(BGP_NODE, &bgp_redistribute_ipv4_ospf_rmap_hidden_cmd);
13968 install_element(BGP_NODE,
13969 &bgp_redistribute_ipv4_ospf_metric_hidden_cmd);
13970 install_element(BGP_NODE,
13971 &bgp_redistribute_ipv4_ospf_rmap_metric_hidden_cmd);
13972 install_element(BGP_NODE,
13973 &bgp_redistribute_ipv4_ospf_metric_rmap_hidden_cmd);
13974 install_element(BGP_IPV4_NODE, &bgp_redistribute_ipv4_cmd);
13975 install_element(BGP_IPV4_NODE, &no_bgp_redistribute_ipv4_cmd);
13976 install_element(BGP_IPV4_NODE, &bgp_redistribute_ipv4_rmap_cmd);
13977 install_element(BGP_IPV4_NODE, &bgp_redistribute_ipv4_metric_cmd);
13978 install_element(BGP_IPV4_NODE, &bgp_redistribute_ipv4_rmap_metric_cmd);
13979 install_element(BGP_IPV4_NODE, &bgp_redistribute_ipv4_metric_rmap_cmd);
13980 install_element(BGP_IPV4_NODE, &bgp_redistribute_ipv4_ospf_cmd);
13981 install_element(BGP_IPV4_NODE, &no_bgp_redistribute_ipv4_ospf_cmd);
13982 install_element(BGP_IPV4_NODE, &bgp_redistribute_ipv4_ospf_rmap_cmd);
13983 install_element(BGP_IPV4_NODE, &bgp_redistribute_ipv4_ospf_metric_cmd);
13984 install_element(BGP_IPV4_NODE,
13985 &bgp_redistribute_ipv4_ospf_rmap_metric_cmd);
13986 install_element(BGP_IPV4_NODE,
13987 &bgp_redistribute_ipv4_ospf_metric_rmap_cmd);
13988 install_element(BGP_IPV6_NODE, &bgp_redistribute_ipv6_cmd);
13989 install_element(BGP_IPV6_NODE, &no_bgp_redistribute_ipv6_cmd);
13990 install_element(BGP_IPV6_NODE, &bgp_redistribute_ipv6_rmap_cmd);
13991 install_element(BGP_IPV6_NODE, &bgp_redistribute_ipv6_metric_cmd);
13992 install_element(BGP_IPV6_NODE, &bgp_redistribute_ipv6_rmap_metric_cmd);
13993 install_element(BGP_IPV6_NODE, &bgp_redistribute_ipv6_metric_rmap_cmd);
13994
13995 /* import|export vpn [route-map WORD] */
13996 install_element(BGP_IPV4_NODE, &bgp_imexport_vpn_cmd);
13997 install_element(BGP_IPV6_NODE, &bgp_imexport_vpn_cmd);
13998
13999 install_element(BGP_IPV4_NODE, &bgp_imexport_vrf_cmd);
14000 install_element(BGP_IPV6_NODE, &bgp_imexport_vrf_cmd);
14001
14002 /* ttl_security commands */
14003 install_element(BGP_NODE, &neighbor_ttl_security_cmd);
14004 install_element(BGP_NODE, &no_neighbor_ttl_security_cmd);
14005
14006 /* "show [ip] bgp memory" commands. */
14007 install_element(VIEW_NODE, &show_bgp_memory_cmd);
14008
14009 /* "show bgp martian next-hop" */
14010 install_element(VIEW_NODE, &show_bgp_martian_nexthop_db_cmd);
14011
14012 install_element(VIEW_NODE, &show_bgp_mac_hash_cmd);
14013
14014 /* "show [ip] bgp views" commands. */
14015 install_element(VIEW_NODE, &show_bgp_views_cmd);
14016
14017 /* "show [ip] bgp vrfs" commands. */
14018 install_element(VIEW_NODE, &show_bgp_vrfs_cmd);
14019
14020 /* Community-list. */
14021 community_list_vty();
14022
14023 /* vpn-policy commands */
14024 install_element(BGP_IPV4_NODE, &af_rd_vpn_export_cmd);
14025 install_element(BGP_IPV6_NODE, &af_rd_vpn_export_cmd);
14026 install_element(BGP_IPV4_NODE, &af_label_vpn_export_cmd);
14027 install_element(BGP_IPV6_NODE, &af_label_vpn_export_cmd);
14028 install_element(BGP_IPV4_NODE, &af_nexthop_vpn_export_cmd);
14029 install_element(BGP_IPV6_NODE, &af_nexthop_vpn_export_cmd);
14030 install_element(BGP_IPV4_NODE, &af_rt_vpn_imexport_cmd);
14031 install_element(BGP_IPV6_NODE, &af_rt_vpn_imexport_cmd);
14032 install_element(BGP_IPV4_NODE, &af_route_map_vpn_imexport_cmd);
14033 install_element(BGP_IPV6_NODE, &af_route_map_vpn_imexport_cmd);
14034 install_element(BGP_IPV4_NODE, &af_import_vrf_route_map_cmd);
14035 install_element(BGP_IPV6_NODE, &af_import_vrf_route_map_cmd);
14036
14037 install_element(BGP_IPV4_NODE, &af_routetarget_import_cmd);
14038 install_element(BGP_IPV6_NODE, &af_routetarget_import_cmd);
14039
14040 install_element(BGP_IPV4_NODE, &af_no_rd_vpn_export_cmd);
14041 install_element(BGP_IPV6_NODE, &af_no_rd_vpn_export_cmd);
14042 install_element(BGP_IPV4_NODE, &af_no_label_vpn_export_cmd);
14043 install_element(BGP_IPV6_NODE, &af_no_label_vpn_export_cmd);
14044 install_element(BGP_IPV4_NODE, &af_no_nexthop_vpn_export_cmd);
14045 install_element(BGP_IPV6_NODE, &af_no_nexthop_vpn_export_cmd);
14046 install_element(BGP_IPV4_NODE, &af_no_rt_vpn_imexport_cmd);
14047 install_element(BGP_IPV6_NODE, &af_no_rt_vpn_imexport_cmd);
14048 install_element(BGP_IPV4_NODE, &af_no_route_map_vpn_imexport_cmd);
14049 install_element(BGP_IPV6_NODE, &af_no_route_map_vpn_imexport_cmd);
14050 install_element(BGP_IPV4_NODE, &af_no_import_vrf_route_map_cmd);
14051 install_element(BGP_IPV6_NODE, &af_no_import_vrf_route_map_cmd);
14052 }
14053
14054 #include "memory.h"
14055 #include "bgp_regex.h"
14056 #include "bgp_clist.h"
14057 #include "bgp_ecommunity.h"
14058
14059 /* VTY functions. */
14060
14061 /* Direction value to string conversion. */
14062 static const char *community_direct_str(int direct)
14063 {
14064 switch (direct) {
14065 case COMMUNITY_DENY:
14066 return "deny";
14067 case COMMUNITY_PERMIT:
14068 return "permit";
14069 default:
14070 return "unknown";
14071 }
14072 }
14073
14074 /* Display error string. */
14075 static void community_list_perror(struct vty *vty, int ret)
14076 {
14077 switch (ret) {
14078 case COMMUNITY_LIST_ERR_CANT_FIND_LIST:
14079 vty_out(vty, "%% Can't find community-list\n");
14080 break;
14081 case COMMUNITY_LIST_ERR_MALFORMED_VAL:
14082 vty_out(vty, "%% Malformed community-list value\n");
14083 break;
14084 case COMMUNITY_LIST_ERR_STANDARD_CONFLICT:
14085 vty_out(vty,
14086 "%% Community name conflict, previously defined as standard community\n");
14087 break;
14088 case COMMUNITY_LIST_ERR_EXPANDED_CONFLICT:
14089 vty_out(vty,
14090 "%% Community name conflict, previously defined as expanded community\n");
14091 break;
14092 }
14093 }
14094
14095 /* "community-list" keyword help string. */
14096 #define COMMUNITY_LIST_STR "Add a community list entry\n"
14097
14098 /*community-list standard */
14099 DEFUN (community_list_standard,
14100 bgp_community_list_standard_cmd,
14101 "bgp community-list <(1-99)|standard WORD> <deny|permit> AA:NN...",
14102 BGP_STR
14103 COMMUNITY_LIST_STR
14104 "Community list number (standard)\n"
14105 "Add an standard community-list entry\n"
14106 "Community list name\n"
14107 "Specify community to reject\n"
14108 "Specify community to accept\n"
14109 COMMUNITY_VAL_STR)
14110 {
14111 char *cl_name_or_number = NULL;
14112 int direct = 0;
14113 int style = COMMUNITY_LIST_STANDARD;
14114
14115 int idx = 0;
14116
14117 if (argv_find(argv, argc, "ip", &idx)) {
14118 vty_out(vty, "This config option is deprecated, and is scheduled for removal.\n");
14119 vty_out(vty, "if you are using this please migrate to the below command.\n");
14120 vty_out(vty, "'bgp community-list <(1-99)|(100-500)|standard|expanded> <deny|permit> AA:NN'\n");
14121 zlog_warn("Deprecated option: 'ip community-list <(1-99)|(100-500)|standard|expanded> <deny|permit> AA:NN' being used");
14122 }
14123
14124 argv_find(argv, argc, "(1-99)", &idx);
14125 argv_find(argv, argc, "WORD", &idx);
14126 cl_name_or_number = argv[idx]->arg;
14127 direct = argv_find(argv, argc, "permit", &idx) ? COMMUNITY_PERMIT
14128 : COMMUNITY_DENY;
14129 argv_find(argv, argc, "AA:NN", &idx);
14130 char *str = argv_concat(argv, argc, idx);
14131
14132 int ret = community_list_set(bgp_clist, cl_name_or_number, str, direct,
14133 style);
14134
14135 XFREE(MTYPE_TMP, str);
14136
14137 if (ret < 0) {
14138 /* Display error string. */
14139 community_list_perror(vty, ret);
14140 return CMD_WARNING_CONFIG_FAILED;
14141 }
14142
14143 return CMD_SUCCESS;
14144 }
14145
14146 #if CONFDATE > 20191005
14147 CPP_NOTICE("bgpd: remove deprecated 'ip community-list <(1-99)|(100-500)|standard|expanded> <deny|permit> AA:NN' command")
14148 #endif
14149 ALIAS (community_list_standard,
14150 ip_community_list_standard_cmd,
14151 "ip community-list <(1-99)|standard WORD> <deny|permit> AA:NN...",
14152 IP_STR
14153 COMMUNITY_LIST_STR
14154 "Community list number (standard)\n"
14155 "Add an standard community-list entry\n"
14156 "Community list name\n"
14157 "Specify community to reject\n"
14158 "Specify community to accept\n"
14159 COMMUNITY_VAL_STR)
14160
14161 DEFUN (no_community_list_standard_all,
14162 no_bgp_community_list_standard_all_cmd,
14163 "no bgp community-list <(1-99)|standard WORD> <deny|permit> AA:NN...",
14164 NO_STR
14165 BGP_STR
14166 COMMUNITY_LIST_STR
14167 "Community list number (standard)\n"
14168 "Add an standard community-list entry\n"
14169 "Community list name\n"
14170 "Specify community to reject\n"
14171 "Specify community to accept\n"
14172 COMMUNITY_VAL_STR)
14173 {
14174 char *cl_name_or_number = NULL;
14175 char *str = NULL;
14176 int direct = 0;
14177 int style = COMMUNITY_LIST_STANDARD;
14178
14179 int idx = 0;
14180
14181 if (argv_find(argv, argc, "ip", &idx)) {
14182 vty_out(vty, "This config option is deprecated, and is scheduled for removal\n");
14183 vty_out(vty, "if you are using this please migrate to the below command.\n");
14184 vty_out(vty, "'no bgp community-list <(1-99)|(100-500)|standard|expanded> <deny|permit> AA:NN'\n");
14185 zlog_warn("Deprecated option: 'no ip community-list <(1-99)|(100-500)|standard|expanded> <deny|permit> |AA:NN' being used");
14186 }
14187
14188 argv_find(argv, argc, "permit", &idx);
14189 argv_find(argv, argc, "deny", &idx);
14190
14191 if (idx) {
14192 direct = argv_find(argv, argc, "permit", &idx)
14193 ? COMMUNITY_PERMIT
14194 : COMMUNITY_DENY;
14195
14196 idx = 0;
14197 argv_find(argv, argc, "AA:NN", &idx);
14198 str = argv_concat(argv, argc, idx);
14199 }
14200
14201 idx = 0;
14202 argv_find(argv, argc, "(1-99)", &idx);
14203 argv_find(argv, argc, "WORD", &idx);
14204 cl_name_or_number = argv[idx]->arg;
14205
14206 int ret = community_list_unset(bgp_clist, cl_name_or_number, str,
14207 direct, style);
14208
14209 XFREE(MTYPE_TMP, str);
14210
14211 if (ret < 0) {
14212 community_list_perror(vty, ret);
14213 return CMD_WARNING_CONFIG_FAILED;
14214 }
14215
14216 return CMD_SUCCESS;
14217 }
14218 ALIAS (no_community_list_standard_all,
14219 no_ip_community_list_standard_all_cmd,
14220 "no ip community-list <(1-99)|standard WORD> <deny|permit> AA:NN...",
14221 NO_STR
14222 IP_STR
14223 COMMUNITY_LIST_STR
14224 "Community list number (standard)\n"
14225 "Add an standard community-list entry\n"
14226 "Community list name\n"
14227 "Specify community to reject\n"
14228 "Specify community to accept\n"
14229 COMMUNITY_VAL_STR)
14230
14231 ALIAS(no_community_list_standard_all, no_bgp_community_list_standard_all_list_cmd,
14232 "no bgp community-list <(1-99)|standard WORD>",
14233 NO_STR BGP_STR COMMUNITY_LIST_STR
14234 "Community list number (standard)\n"
14235 "Add an standard community-list entry\n"
14236 "Community list name\n")
14237
14238 ALIAS(no_community_list_standard_all, no_ip_community_list_standard_all_list_cmd,
14239 "no ip community-list <(1-99)|standard WORD>",
14240 NO_STR BGP_STR COMMUNITY_LIST_STR
14241 "Community list number (standard)\n"
14242 "Add an standard community-list entry\n"
14243 "Community list name\n")
14244
14245 /*community-list expanded */
14246 DEFUN (community_list_expanded_all,
14247 bgp_community_list_expanded_all_cmd,
14248 "bgp community-list <(100-500)|expanded WORD> <deny|permit> AA:NN...",
14249 BGP_STR
14250 COMMUNITY_LIST_STR
14251 "Community list number (expanded)\n"
14252 "Add an expanded community-list entry\n"
14253 "Community list name\n"
14254 "Specify community to reject\n"
14255 "Specify community to accept\n"
14256 COMMUNITY_VAL_STR)
14257 {
14258 char *cl_name_or_number = NULL;
14259 int direct = 0;
14260 int style = COMMUNITY_LIST_EXPANDED;
14261
14262 int idx = 0;
14263 if (argv_find(argv, argc, "ip", &idx)) {
14264 vty_out(vty, "This config option is deprecated, and is scheduled for removal.\n");
14265 vty_out(vty, "if you are using this please migrate to the below command.\n");
14266 vty_out(vty, "'bgp community-list <(1-99)|(100-500)|standard|expanded> <deny|permit> AA:NN'\n");
14267 zlog_warn("Deprecated option: 'ip community-list <(1-99)|(100-500)|standard|expanded> <deny|permit> AA:NN' being used");
14268 }
14269 argv_find(argv, argc, "(100-500)", &idx);
14270 argv_find(argv, argc, "WORD", &idx);
14271 cl_name_or_number = argv[idx]->arg;
14272 direct = argv_find(argv, argc, "permit", &idx) ? COMMUNITY_PERMIT
14273 : COMMUNITY_DENY;
14274 argv_find(argv, argc, "AA:NN", &idx);
14275 char *str = argv_concat(argv, argc, idx);
14276
14277 int ret = community_list_set(bgp_clist, cl_name_or_number, str, direct,
14278 style);
14279
14280 XFREE(MTYPE_TMP, str);
14281
14282 if (ret < 0) {
14283 /* Display error string. */
14284 community_list_perror(vty, ret);
14285 return CMD_WARNING_CONFIG_FAILED;
14286 }
14287
14288 return CMD_SUCCESS;
14289 }
14290
14291 ALIAS (community_list_expanded_all,
14292 ip_community_list_expanded_all_cmd,
14293 "ip community-list <(100-500)|expanded WORD> <deny|permit> AA:NN...",
14294 IP_STR
14295 COMMUNITY_LIST_STR
14296 "Community list number (expanded)\n"
14297 "Add an expanded community-list entry\n"
14298 "Community list name\n"
14299 "Specify community to reject\n"
14300 "Specify community to accept\n"
14301 COMMUNITY_VAL_STR)
14302
14303 DEFUN (no_community_list_expanded_all,
14304 no_bgp_community_list_expanded_all_cmd,
14305 "no bgp community-list <(100-500)|expanded WORD> <deny|permit> AA:NN...",
14306 NO_STR
14307 BGP_STR
14308 COMMUNITY_LIST_STR
14309 "Community list number (expanded)\n"
14310 "Add an expanded community-list entry\n"
14311 "Community list name\n"
14312 "Specify community to reject\n"
14313 "Specify community to accept\n"
14314 COMMUNITY_VAL_STR)
14315 {
14316 char *cl_name_or_number = NULL;
14317 char *str = NULL;
14318 int direct = 0;
14319 int style = COMMUNITY_LIST_EXPANDED;
14320
14321 int idx = 0;
14322 if (argv_find(argv, argc, "ip", &idx)) {
14323 vty_out(vty, "This config option is deprecated, and is scheduled for removal.\n");
14324 vty_out(vty, "if you are using this please migrate to the below command.\n");
14325 vty_out(vty, "'no bgp community-list <(1-99)|(100-500)|standard|expanded> <deny|permit> AA:NN'\n");
14326 zlog_warn("Deprecated option: 'no ip community-list <(1-99)|(100-500)|standard|expanded> <deny|permit> AA:NN' being used");
14327 }
14328
14329 idx = 0;
14330 argv_find(argv, argc, "permit", &idx);
14331 argv_find(argv, argc, "deny", &idx);
14332
14333 if (idx) {
14334 direct = argv_find(argv, argc, "permit", &idx)
14335 ? COMMUNITY_PERMIT
14336 : COMMUNITY_DENY;
14337
14338 idx = 0;
14339 argv_find(argv, argc, "AA:NN", &idx);
14340 str = argv_concat(argv, argc, idx);
14341 }
14342
14343 idx = 0;
14344 argv_find(argv, argc, "(100-500)", &idx);
14345 argv_find(argv, argc, "WORD", &idx);
14346 cl_name_or_number = argv[idx]->arg;
14347
14348 int ret = community_list_unset(bgp_clist, cl_name_or_number, str,
14349 direct, style);
14350
14351 XFREE(MTYPE_TMP, str);
14352
14353 if (ret < 0) {
14354 community_list_perror(vty, ret);
14355 return CMD_WARNING_CONFIG_FAILED;
14356 }
14357
14358 return CMD_SUCCESS;
14359 }
14360
14361 ALIAS (no_community_list_expanded_all,
14362 no_ip_community_list_expanded_all_cmd,
14363 "no ip community-list <(100-500)|expanded WORD> <deny|permit> AA:NN...",
14364 NO_STR
14365 IP_STR
14366 COMMUNITY_LIST_STR
14367 "Community list number (expanded)\n"
14368 "Add an expanded community-list entry\n"
14369 "Community list name\n"
14370 "Specify community to reject\n"
14371 "Specify community to accept\n"
14372 COMMUNITY_VAL_STR)
14373
14374 ALIAS(no_community_list_expanded_all, no_bgp_community_list_expanded_all_list_cmd,
14375 "no bgp community-list <(100-500)|expanded WORD>",
14376 NO_STR IP_STR COMMUNITY_LIST_STR
14377 "Community list number (expanded)\n"
14378 "Add an expanded community-list entry\n"
14379 "Community list name\n")
14380
14381 ALIAS(no_community_list_expanded_all, no_ip_community_list_expanded_all_list_cmd,
14382 "no ip community-list <(100-500)|expanded WORD>",
14383 NO_STR IP_STR COMMUNITY_LIST_STR
14384 "Community list number (expanded)\n"
14385 "Add an expanded community-list entry\n"
14386 "Community list name\n")
14387
14388 /* Return configuration string of community-list entry. */
14389 static const char *community_list_config_str(struct community_entry *entry)
14390 {
14391 const char *str;
14392
14393 if (entry->any)
14394 str = "";
14395 else {
14396 if (entry->style == COMMUNITY_LIST_STANDARD)
14397 str = community_str(entry->u.com, false);
14398 else if (entry->style == LARGE_COMMUNITY_LIST_STANDARD)
14399 str = lcommunity_str(entry->u.lcom, false);
14400 else
14401 str = entry->config;
14402 }
14403 return str;
14404 }
14405
14406 static void community_list_show(struct vty *vty, struct community_list *list)
14407 {
14408 struct community_entry *entry;
14409
14410 for (entry = list->head; entry; entry = entry->next) {
14411 if (entry == list->head) {
14412 if (all_digit(list->name))
14413 vty_out(vty, "Community %s list %s\n",
14414 entry->style == COMMUNITY_LIST_STANDARD
14415 ? "standard"
14416 : "(expanded) access",
14417 list->name);
14418 else
14419 vty_out(vty, "Named Community %s list %s\n",
14420 entry->style == COMMUNITY_LIST_STANDARD
14421 ? "standard"
14422 : "expanded",
14423 list->name);
14424 }
14425 if (entry->any)
14426 vty_out(vty, " %s\n",
14427 community_direct_str(entry->direct));
14428 else
14429 vty_out(vty, " %s %s\n",
14430 community_direct_str(entry->direct),
14431 community_list_config_str(entry));
14432 }
14433 }
14434
14435 DEFUN (show_community_list,
14436 show_bgp_community_list_cmd,
14437 "show bgp community-list",
14438 SHOW_STR
14439 BGP_STR
14440 "List community-list\n")
14441 {
14442 struct community_list *list;
14443 struct community_list_master *cm;
14444
14445 int idx = 0;
14446 if (argv_find(argv, argc, "ip", &idx)) {
14447 vty_out(vty, "This config option is deprecated, and is scheduled for removal.\n");
14448 vty_out(vty, "if you are using this please migrate to the below command.\n");
14449 vty_out(vty, "'show bgp community-list <(1-500)|WORD>'\n");
14450 zlog_warn("Deprecated option: 'ip show community-list <(1-500)|WORD>' being used");
14451 }
14452 cm = community_list_master_lookup(bgp_clist, COMMUNITY_LIST_MASTER);
14453 if (!cm)
14454 return CMD_SUCCESS;
14455
14456 for (list = cm->num.head; list; list = list->next)
14457 community_list_show(vty, list);
14458
14459 for (list = cm->str.head; list; list = list->next)
14460 community_list_show(vty, list);
14461
14462 return CMD_SUCCESS;
14463 }
14464
14465 ALIAS (show_community_list,
14466 show_ip_community_list_cmd,
14467 "show ip community-list",
14468 SHOW_STR
14469 IP_STR
14470 "List community-list\n")
14471
14472 DEFUN (show_community_list_arg,
14473 show_bgp_community_list_arg_cmd,
14474 "show bgp community-list <(1-500)|WORD>",
14475 SHOW_STR
14476 BGP_STR
14477 "List community-list\n"
14478 "Community-list number\n"
14479 "Community-list name\n")
14480 {
14481 int idx_comm_list = 3;
14482 struct community_list *list;
14483
14484 int idx = 0;
14485 if (argv_find(argv, argc, "ip", &idx)) {
14486 vty_out(vty, "This config option is deprecated, and is scheduled for removal.\n");
14487 vty_out(vty, "if you are using this please migrate to the below command.\n");
14488 vty_out(vty, "'show bgp community-list <(1-500)|WORD>'\n");
14489 zlog_warn("Deprecated option: 'ip show community-list <(1-500)|WORD>' being used");
14490 }
14491 list = community_list_lookup(bgp_clist, argv[idx_comm_list]->arg, 0,
14492 COMMUNITY_LIST_MASTER);
14493 if (!list) {
14494 vty_out(vty, "%% Can't find community-list\n");
14495 return CMD_WARNING;
14496 }
14497
14498 community_list_show(vty, list);
14499
14500 return CMD_SUCCESS;
14501 }
14502
14503 ALIAS (show_community_list_arg,
14504 show_ip_community_list_arg_cmd,
14505 "show ip community-list <(1-500)|WORD>",
14506 SHOW_STR
14507 IP_STR
14508 "List community-list\n"
14509 "Community-list number\n"
14510 "Community-list name\n")
14511
14512 /*
14513 * Large Community code.
14514 */
14515 static int lcommunity_list_set_vty(struct vty *vty, int argc,
14516 struct cmd_token **argv, int style,
14517 int reject_all_digit_name)
14518 {
14519 int ret;
14520 int direct;
14521 char *str;
14522 int idx = 0;
14523 char *cl_name;
14524
14525 if (argv_find(argv, argc, "ip", &idx)) {
14526 vty_out(vty, "This config option is deprecated, and is scheduled for removal.\n");
14527 vty_out(vty, "if you are using this please migrate to the below command.\n");
14528 vty_out(vty, "'bgp large-community-list <(1-99)|(100-500)|standard|expanded> <deny|permit> <LINE|AA:BB:CC>'\n");
14529 zlog_warn("Deprecated option: 'large-community-list <(1-99)|(100-500)|standard|expanded> <deny|permit> <LINE|AA:BB:CC>' being used");
14530 }
14531 direct = argv_find(argv, argc, "permit", &idx) ? COMMUNITY_PERMIT
14532 : COMMUNITY_DENY;
14533
14534 /* All digit name check. */
14535 idx = 0;
14536 argv_find(argv, argc, "WORD", &idx);
14537 argv_find(argv, argc, "(1-99)", &idx);
14538 argv_find(argv, argc, "(100-500)", &idx);
14539 cl_name = argv[idx]->arg;
14540 if (reject_all_digit_name && all_digit(cl_name)) {
14541 vty_out(vty, "%% Community name cannot have all digits\n");
14542 return CMD_WARNING_CONFIG_FAILED;
14543 }
14544
14545 idx = 0;
14546 argv_find(argv, argc, "AA:BB:CC", &idx);
14547 argv_find(argv, argc, "LINE", &idx);
14548 /* Concat community string argument. */
14549 if (idx)
14550 str = argv_concat(argv, argc, idx);
14551 else
14552 str = NULL;
14553
14554 ret = lcommunity_list_set(bgp_clist, cl_name, str, direct, style);
14555
14556 /* Free temporary community list string allocated by
14557 argv_concat(). */
14558 XFREE(MTYPE_TMP, str);
14559
14560 if (ret < 0) {
14561 community_list_perror(vty, ret);
14562 return CMD_WARNING_CONFIG_FAILED;
14563 }
14564 return CMD_SUCCESS;
14565 }
14566
14567 static int lcommunity_list_unset_vty(struct vty *vty, int argc,
14568 struct cmd_token **argv, int style)
14569 {
14570 int ret;
14571 int direct = 0;
14572 char *str = NULL;
14573 int idx = 0;
14574
14575 if (argv_find(argv, argc, "ip", &idx)) {
14576 vty_out(vty, "This config option is deprecated, and is scheduled for removal.\n");
14577 vty_out(vty, "if you are using this please migrate to the below command.\n");
14578 vty_out(vty, "'no bgp large-community-list <(1-99)|(100-500)|standard|expanded> <deny|permit> <LINE|AA:BB:CC>'\n");
14579 zlog_warn("Deprecated option: 'no ip large-community-list <(1-99)|(100-500)|standard|expanded> <deny|permit> <LINE|AA:BB:CC>' being used");
14580 }
14581 argv_find(argv, argc, "permit", &idx);
14582 argv_find(argv, argc, "deny", &idx);
14583
14584 if (idx) {
14585 /* Check the list direct. */
14586 if (strncmp(argv[idx]->arg, "p", 1) == 0)
14587 direct = COMMUNITY_PERMIT;
14588 else
14589 direct = COMMUNITY_DENY;
14590
14591 idx = 0;
14592 argv_find(argv, argc, "LINE", &idx);
14593 argv_find(argv, argc, "AA:AA:NN", &idx);
14594 /* Concat community string argument. */
14595 str = argv_concat(argv, argc, idx);
14596 }
14597
14598 idx = 0;
14599 argv_find(argv, argc, "(1-99)", &idx);
14600 argv_find(argv, argc, "(100-500)", &idx);
14601 argv_find(argv, argc, "WORD", &idx);
14602
14603 /* Unset community list. */
14604 ret = lcommunity_list_unset(bgp_clist, argv[idx]->arg, str, direct,
14605 style);
14606
14607 /* Free temporary community list string allocated by
14608 argv_concat(). */
14609 XFREE(MTYPE_TMP, str);
14610
14611 if (ret < 0) {
14612 community_list_perror(vty, ret);
14613 return CMD_WARNING_CONFIG_FAILED;
14614 }
14615
14616 return CMD_SUCCESS;
14617 }
14618
14619 /* "large-community-list" keyword help string. */
14620 #define LCOMMUNITY_LIST_STR "Add a large community list entry\n"
14621 #define LCOMMUNITY_VAL_STR "large community in 'aa:bb:cc' format\n"
14622
14623 #if CONFDATE > 20191005
14624 CPP_NOTICE("bgpd: remove deprecated 'ip large-community-list <(1-99)|(100-500)|standard|expanded> <deny|permit> <LINE|AA:BB:CC>' command")
14625 #endif
14626 DEFUN (lcommunity_list_standard,
14627 bgp_lcommunity_list_standard_cmd,
14628 "bgp large-community-list (1-99) <deny|permit>",
14629 BGP_STR
14630 LCOMMUNITY_LIST_STR
14631 "Large Community list number (standard)\n"
14632 "Specify large community to reject\n"
14633 "Specify large community to accept\n")
14634 {
14635 return lcommunity_list_set_vty(vty, argc, argv,
14636 LARGE_COMMUNITY_LIST_STANDARD, 0);
14637 }
14638
14639 ALIAS (lcommunity_list_standard,
14640 ip_lcommunity_list_standard_cmd,
14641 "ip large-community-list (1-99) <deny|permit>",
14642 IP_STR
14643 LCOMMUNITY_LIST_STR
14644 "Large Community list number (standard)\n"
14645 "Specify large community to reject\n"
14646 "Specify large community to accept\n")
14647
14648 DEFUN (lcommunity_list_standard1,
14649 bgp_lcommunity_list_standard1_cmd,
14650 "bgp large-community-list (1-99) <deny|permit> AA:BB:CC...",
14651 BGP_STR
14652 LCOMMUNITY_LIST_STR
14653 "Large Community list number (standard)\n"
14654 "Specify large community to reject\n"
14655 "Specify large community to accept\n"
14656 LCOMMUNITY_VAL_STR)
14657 {
14658 return lcommunity_list_set_vty(vty, argc, argv,
14659 LARGE_COMMUNITY_LIST_STANDARD, 0);
14660 }
14661
14662 ALIAS (lcommunity_list_standard1,
14663 ip_lcommunity_list_standard1_cmd,
14664 "ip large-community-list (1-99) <deny|permit> AA:BB:CC...",
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 LCOMMUNITY_VAL_STR)
14671
14672 DEFUN (lcommunity_list_expanded,
14673 bgp_lcommunity_list_expanded_cmd,
14674 "bgp large-community-list (100-500) <deny|permit> LINE...",
14675 BGP_STR
14676 LCOMMUNITY_LIST_STR
14677 "Large Community list number (expanded)\n"
14678 "Specify large community to reject\n"
14679 "Specify large community to accept\n"
14680 "An ordered list as a regular-expression\n")
14681 {
14682 return lcommunity_list_set_vty(vty, argc, argv,
14683 LARGE_COMMUNITY_LIST_EXPANDED, 0);
14684 }
14685
14686 ALIAS (lcommunity_list_expanded,
14687 ip_lcommunity_list_expanded_cmd,
14688 "ip large-community-list (100-500) <deny|permit> LINE...",
14689 IP_STR
14690 LCOMMUNITY_LIST_STR
14691 "Large Community list number (expanded)\n"
14692 "Specify large community to reject\n"
14693 "Specify large community to accept\n"
14694 "An ordered list as a regular-expression\n")
14695
14696 DEFUN (lcommunity_list_name_standard,
14697 bgp_lcommunity_list_name_standard_cmd,
14698 "bgp large-community-list standard WORD <deny|permit>",
14699 BGP_STR
14700 LCOMMUNITY_LIST_STR
14701 "Specify standard large-community-list\n"
14702 "Large Community list name\n"
14703 "Specify large community to reject\n"
14704 "Specify large community to accept\n")
14705 {
14706 return lcommunity_list_set_vty(vty, argc, argv,
14707 LARGE_COMMUNITY_LIST_STANDARD, 1);
14708 }
14709
14710 ALIAS (lcommunity_list_name_standard,
14711 ip_lcommunity_list_name_standard_cmd,
14712 "ip large-community-list standard WORD <deny|permit>",
14713 IP_STR
14714 LCOMMUNITY_LIST_STR
14715 "Specify standard large-community-list\n"
14716 "Large Community list name\n"
14717 "Specify large community to reject\n"
14718 "Specify large community to accept\n")
14719
14720 DEFUN (lcommunity_list_name_standard1,
14721 bgp_lcommunity_list_name_standard1_cmd,
14722 "bgp large-community-list standard WORD <deny|permit> AA:BB:CC...",
14723 BGP_STR
14724 LCOMMUNITY_LIST_STR
14725 "Specify standard large-community-list\n"
14726 "Large Community list name\n"
14727 "Specify large community to reject\n"
14728 "Specify large community to accept\n"
14729 LCOMMUNITY_VAL_STR)
14730 {
14731 return lcommunity_list_set_vty(vty, argc, argv,
14732 LARGE_COMMUNITY_LIST_STANDARD, 1);
14733 }
14734
14735 ALIAS (lcommunity_list_name_standard1,
14736 ip_lcommunity_list_name_standard1_cmd,
14737 "ip large-community-list standard WORD <deny|permit> AA:BB:CC...",
14738 IP_STR
14739 LCOMMUNITY_LIST_STR
14740 "Specify standard large-community-list\n"
14741 "Large Community list name\n"
14742 "Specify large community to reject\n"
14743 "Specify large community to accept\n"
14744 LCOMMUNITY_VAL_STR)
14745
14746 DEFUN (lcommunity_list_name_expanded,
14747 bgp_lcommunity_list_name_expanded_cmd,
14748 "bgp large-community-list expanded WORD <deny|permit> LINE...",
14749 BGP_STR
14750 LCOMMUNITY_LIST_STR
14751 "Specify expanded large-community-list\n"
14752 "Large Community list name\n"
14753 "Specify large community to reject\n"
14754 "Specify large community to accept\n"
14755 "An ordered list as a regular-expression\n")
14756 {
14757 return lcommunity_list_set_vty(vty, argc, argv,
14758 LARGE_COMMUNITY_LIST_EXPANDED, 1);
14759 }
14760
14761 ALIAS (lcommunity_list_name_expanded,
14762 ip_lcommunity_list_name_expanded_cmd,
14763 "ip large-community-list expanded WORD <deny|permit> LINE...",
14764 IP_STR
14765 LCOMMUNITY_LIST_STR
14766 "Specify expanded large-community-list\n"
14767 "Large Community list name\n"
14768 "Specify large community to reject\n"
14769 "Specify large community to accept\n"
14770 "An ordered list as a regular-expression\n")
14771
14772 DEFUN (no_lcommunity_list_standard_all,
14773 no_bgp_lcommunity_list_standard_all_cmd,
14774 "no bgp large-community-list <(1-99)|(100-500)|WORD>",
14775 NO_STR
14776 BGP_STR
14777 LCOMMUNITY_LIST_STR
14778 "Large Community list number (standard)\n"
14779 "Large Community list number (expanded)\n"
14780 "Large Community list name\n")
14781 {
14782 return lcommunity_list_unset_vty(vty, argc, argv,
14783 LARGE_COMMUNITY_LIST_STANDARD);
14784 }
14785
14786 ALIAS (no_lcommunity_list_standard_all,
14787 no_ip_lcommunity_list_standard_all_cmd,
14788 "no ip large-community-list <(1-99)|(100-500)|WORD>",
14789 NO_STR
14790 IP_STR
14791 LCOMMUNITY_LIST_STR
14792 "Large Community list number (standard)\n"
14793 "Large Community list number (expanded)\n"
14794 "Large Community list name\n")
14795
14796 DEFUN (no_lcommunity_list_name_expanded_all,
14797 no_bgp_lcommunity_list_name_expanded_all_cmd,
14798 "no bgp large-community-list expanded WORD",
14799 NO_STR
14800 BGP_STR
14801 LCOMMUNITY_LIST_STR
14802 "Specify expanded large-community-list\n"
14803 "Large Community list name\n")
14804 {
14805 return lcommunity_list_unset_vty(vty, argc, argv,
14806 LARGE_COMMUNITY_LIST_EXPANDED);
14807 }
14808
14809 ALIAS (no_lcommunity_list_name_expanded_all,
14810 no_ip_lcommunity_list_name_expanded_all_cmd,
14811 "no ip large-community-list expanded WORD",
14812 NO_STR
14813 IP_STR
14814 LCOMMUNITY_LIST_STR
14815 "Specify expanded large-community-list\n"
14816 "Large Community list name\n")
14817
14818 DEFUN (no_lcommunity_list_standard,
14819 no_bgp_lcommunity_list_standard_cmd,
14820 "no bgp large-community-list (1-99) <deny|permit> AA:AA:NN...",
14821 NO_STR
14822 BGP_STR
14823 LCOMMUNITY_LIST_STR
14824 "Large Community list number (standard)\n"
14825 "Specify large community to reject\n"
14826 "Specify large community to accept\n"
14827 LCOMMUNITY_VAL_STR)
14828 {
14829 return lcommunity_list_unset_vty(vty, argc, argv,
14830 LARGE_COMMUNITY_LIST_STANDARD);
14831 }
14832
14833 ALIAS (no_lcommunity_list_standard,
14834 no_ip_lcommunity_list_standard_cmd,
14835 "no ip large-community-list (1-99) <deny|permit> AA:AA:NN...",
14836 NO_STR
14837 IP_STR
14838 LCOMMUNITY_LIST_STR
14839 "Large Community list number (standard)\n"
14840 "Specify large community to reject\n"
14841 "Specify large community to accept\n"
14842 LCOMMUNITY_VAL_STR)
14843
14844 DEFUN (no_lcommunity_list_expanded,
14845 no_bgp_lcommunity_list_expanded_cmd,
14846 "no bgp large-community-list (100-500) <deny|permit> LINE...",
14847 NO_STR
14848 BGP_STR
14849 LCOMMUNITY_LIST_STR
14850 "Large Community list number (expanded)\n"
14851 "Specify large community to reject\n"
14852 "Specify large community to accept\n"
14853 "An ordered list as a regular-expression\n")
14854 {
14855 return lcommunity_list_unset_vty(vty, argc, argv,
14856 LARGE_COMMUNITY_LIST_EXPANDED);
14857 }
14858
14859 ALIAS (no_lcommunity_list_expanded,
14860 no_ip_lcommunity_list_expanded_cmd,
14861 "no ip large-community-list (100-500) <deny|permit> LINE...",
14862 NO_STR
14863 IP_STR
14864 LCOMMUNITY_LIST_STR
14865 "Large Community list number (expanded)\n"
14866 "Specify large community to reject\n"
14867 "Specify large community to accept\n"
14868 "An ordered list as a regular-expression\n")
14869
14870 DEFUN (no_lcommunity_list_name_standard,
14871 no_bgp_lcommunity_list_name_standard_cmd,
14872 "no bgp large-community-list standard WORD <deny|permit> AA:AA:NN...",
14873 NO_STR
14874 BGP_STR
14875 LCOMMUNITY_LIST_STR
14876 "Specify standard large-community-list\n"
14877 "Large Community list name\n"
14878 "Specify large community to reject\n"
14879 "Specify large community to accept\n"
14880 LCOMMUNITY_VAL_STR)
14881 {
14882 return lcommunity_list_unset_vty(vty, argc, argv,
14883 LARGE_COMMUNITY_LIST_STANDARD);
14884 }
14885
14886 ALIAS (no_lcommunity_list_name_standard,
14887 no_ip_lcommunity_list_name_standard_cmd,
14888 "no ip large-community-list standard WORD <deny|permit> AA:AA:NN...",
14889 NO_STR
14890 IP_STR
14891 LCOMMUNITY_LIST_STR
14892 "Specify standard large-community-list\n"
14893 "Large Community list name\n"
14894 "Specify large community to reject\n"
14895 "Specify large community to accept\n"
14896 LCOMMUNITY_VAL_STR)
14897
14898 DEFUN (no_lcommunity_list_name_expanded,
14899 no_bgp_lcommunity_list_name_expanded_cmd,
14900 "no bgp large-community-list expanded WORD <deny|permit> LINE...",
14901 NO_STR
14902 BGP_STR
14903 LCOMMUNITY_LIST_STR
14904 "Specify expanded large-community-list\n"
14905 "Large community list name\n"
14906 "Specify large community to reject\n"
14907 "Specify large community to accept\n"
14908 "An ordered list as a regular-expression\n")
14909 {
14910 return lcommunity_list_unset_vty(vty, argc, argv,
14911 LARGE_COMMUNITY_LIST_EXPANDED);
14912 }
14913
14914 ALIAS (no_lcommunity_list_name_expanded,
14915 no_ip_lcommunity_list_name_expanded_cmd,
14916 "no ip large-community-list expanded WORD <deny|permit> LINE...",
14917 NO_STR
14918 IP_STR
14919 LCOMMUNITY_LIST_STR
14920 "Specify expanded large-community-list\n"
14921 "Large community list name\n"
14922 "Specify large community to reject\n"
14923 "Specify large community to accept\n"
14924 "An ordered list as a regular-expression\n")
14925
14926 static void lcommunity_list_show(struct vty *vty, struct community_list *list)
14927 {
14928 struct community_entry *entry;
14929
14930 for (entry = list->head; entry; entry = entry->next) {
14931 if (entry == list->head) {
14932 if (all_digit(list->name))
14933 vty_out(vty, "Large community %s list %s\n",
14934 entry->style == EXTCOMMUNITY_LIST_STANDARD
14935 ? "standard"
14936 : "(expanded) access",
14937 list->name);
14938 else
14939 vty_out(vty,
14940 "Named large community %s list %s\n",
14941 entry->style == EXTCOMMUNITY_LIST_STANDARD
14942 ? "standard"
14943 : "expanded",
14944 list->name);
14945 }
14946 if (entry->any)
14947 vty_out(vty, " %s\n",
14948 community_direct_str(entry->direct));
14949 else
14950 vty_out(vty, " %s %s\n",
14951 community_direct_str(entry->direct),
14952 community_list_config_str(entry));
14953 }
14954 }
14955
14956 DEFUN (show_lcommunity_list,
14957 show_bgp_lcommunity_list_cmd,
14958 "show bgp large-community-list",
14959 SHOW_STR
14960 BGP_STR
14961 "List large-community list\n")
14962 {
14963 struct community_list *list;
14964 struct community_list_master *cm;
14965 int idx = 0;
14966
14967 if (argv_find(argv, argc, "ip", &idx)) {
14968 vty_out(vty, "This config option is deprecated, and is scheduled for removal.\n");
14969 vty_out(vty, "if you are using this please migrate to the below command.\n");
14970 vty_out(vty, "'show bgp large-community-list <(1-500)|WORD>'\n");
14971 zlog_warn("Deprecated option: 'ip show large-community-list <(1-500)|WORD>' being used");
14972 }
14973
14974 cm = community_list_master_lookup(bgp_clist,
14975 LARGE_COMMUNITY_LIST_MASTER);
14976 if (!cm)
14977 return CMD_SUCCESS;
14978
14979 for (list = cm->num.head; list; list = list->next)
14980 lcommunity_list_show(vty, list);
14981
14982 for (list = cm->str.head; list; list = list->next)
14983 lcommunity_list_show(vty, list);
14984
14985 return CMD_SUCCESS;
14986 }
14987
14988 ALIAS (show_lcommunity_list,
14989 show_ip_lcommunity_list_cmd,
14990 "show ip large-community-list",
14991 SHOW_STR
14992 IP_STR
14993 "List large-community list\n")
14994
14995 DEFUN (show_lcommunity_list_arg,
14996 show_bgp_lcommunity_list_arg_cmd,
14997 "show bgp large-community-list <(1-500)|WORD>",
14998 SHOW_STR
14999 BGP_STR
15000 "List large-community list\n"
15001 "large-community-list number\n"
15002 "large-community-list name\n")
15003 {
15004 struct community_list *list;
15005 int idx = 0;
15006
15007 if (argv_find(argv, argc, "ip", &idx)) {
15008 vty_out(vty, "This config option is deprecated, and is scheduled for removal.\n");
15009 vty_out(vty, "if you are using this please migrate to the below command.\n");
15010 vty_out(vty, "'show bgp large-community-list <(1-500)|WORD>'\n");
15011 zlog_warn("Deprecated option: 'ip show large-community-list <(1-500)|WORD>' being used");
15012 }
15013
15014 list = community_list_lookup(bgp_clist, argv[3]->arg, 0,
15015 LARGE_COMMUNITY_LIST_MASTER);
15016 if (!list) {
15017 vty_out(vty, "%% Can't find extcommunity-list\n");
15018 return CMD_WARNING;
15019 }
15020
15021 lcommunity_list_show(vty, list);
15022
15023 return CMD_SUCCESS;
15024 }
15025
15026 ALIAS (show_lcommunity_list_arg,
15027 show_ip_lcommunity_list_arg_cmd,
15028 "show ip large-community-list <(1-500)|WORD>",
15029 SHOW_STR
15030 IP_STR
15031 "List large-community list\n"
15032 "large-community-list number\n"
15033 "large-community-list name\n")
15034
15035 /* "extcommunity-list" keyword help string. */
15036 #define EXTCOMMUNITY_LIST_STR "Add a extended community list entry\n"
15037 #define EXTCOMMUNITY_VAL_STR "Extended community attribute in 'rt aa:nn_or_IPaddr:nn' OR 'soo aa:nn_or_IPaddr:nn' format\n"
15038
15039 DEFUN (extcommunity_list_standard,
15040 bgp_extcommunity_list_standard_cmd,
15041 "bgp extcommunity-list <(1-99)|standard WORD> <deny|permit> AA:NN...",
15042 BGP_STR
15043 EXTCOMMUNITY_LIST_STR
15044 "Extended Community list number (standard)\n"
15045 "Specify standard extcommunity-list\n"
15046 "Community list name\n"
15047 "Specify community to reject\n"
15048 "Specify community to accept\n"
15049 EXTCOMMUNITY_VAL_STR)
15050 {
15051 int style = EXTCOMMUNITY_LIST_STANDARD;
15052 int direct = 0;
15053 char *cl_number_or_name = NULL;
15054
15055 int idx = 0;
15056 if (argv_find(argv, argc, "ip", &idx)) {
15057 vty_out(vty, "This config option is deprecated, and is scheduled for removal.\n");
15058 vty_out(vty, "if you are using this please migrate to the below command.\n");
15059 vty_out(vty, "'bgp extcommunity-list <(1-99)|(100-500)|standard|expanded> <deny|permit> <LINE|AA:NN>'\n");
15060 zlog_warn("Deprecated option: 'ip extcommunity-list <(1-99)|(100-500)|standard|expanded> <deny|permit> <LINE|AA:NN>' being used");
15061 }
15062 argv_find(argv, argc, "(1-99)", &idx);
15063 argv_find(argv, argc, "WORD", &idx);
15064 cl_number_or_name = argv[idx]->arg;
15065 direct = argv_find(argv, argc, "permit", &idx) ? COMMUNITY_PERMIT
15066 : COMMUNITY_DENY;
15067 argv_find(argv, argc, "AA:NN", &idx);
15068 char *str = argv_concat(argv, argc, idx);
15069
15070 int ret = extcommunity_list_set(bgp_clist, cl_number_or_name, str,
15071 direct, style);
15072
15073 XFREE(MTYPE_TMP, str);
15074
15075 if (ret < 0) {
15076 community_list_perror(vty, ret);
15077 return CMD_WARNING_CONFIG_FAILED;
15078 }
15079
15080 return CMD_SUCCESS;
15081 }
15082
15083 #if CONFDATE > 20191005
15084 CPP_NOTICE("bgpd: remove deprecated 'ip extcommunity-list <(1-99)|(100-500)|standard|expanded> <deny|permit> <LINE|AA:NN>' command")
15085 #endif
15086 ALIAS (extcommunity_list_standard,
15087 ip_extcommunity_list_standard_cmd,
15088 "ip extcommunity-list <(1-99)|standard WORD> <deny|permit> AA:NN...",
15089 IP_STR
15090 EXTCOMMUNITY_LIST_STR
15091 "Extended Community list number (standard)\n"
15092 "Specify standard extcommunity-list\n"
15093 "Community list name\n"
15094 "Specify community to reject\n"
15095 "Specify community to accept\n"
15096 EXTCOMMUNITY_VAL_STR)
15097
15098 DEFUN (extcommunity_list_name_expanded,
15099 bgp_extcommunity_list_name_expanded_cmd,
15100 "bgp extcommunity-list <(100-500)|expanded WORD> <deny|permit> LINE...",
15101 BGP_STR
15102 EXTCOMMUNITY_LIST_STR
15103 "Extended Community list number (expanded)\n"
15104 "Specify expanded extcommunity-list\n"
15105 "Extended Community list name\n"
15106 "Specify community to reject\n"
15107 "Specify community to accept\n"
15108 "An ordered list as a regular-expression\n")
15109 {
15110 int style = EXTCOMMUNITY_LIST_EXPANDED;
15111 int direct = 0;
15112 char *cl_number_or_name = NULL;
15113
15114 int idx = 0;
15115 if (argv_find(argv, argc, "ip", &idx)) {
15116 vty_out(vty, "This config option is deprecated, and is scheduled for removal.\n");
15117 vty_out(vty, "if you are using this please migrate to the below command.\n");
15118 vty_out(vty, "'extcommunity-list <(1-99)|(100-500)|standard|expanded> <deny|permit> <LINE|AA:NN>'\n");
15119 zlog_warn("Deprecated option: ‘ip extcommunity-list <(1-99)|(100-500)|standard|expanded> <deny|permit> <LINE|AA:NN>' being used");
15120 }
15121
15122 argv_find(argv, argc, "(100-500)", &idx);
15123 argv_find(argv, argc, "WORD", &idx);
15124 cl_number_or_name = argv[idx]->arg;
15125 direct = argv_find(argv, argc, "permit", &idx) ? COMMUNITY_PERMIT
15126 : COMMUNITY_DENY;
15127 argv_find(argv, argc, "LINE", &idx);
15128 char *str = argv_concat(argv, argc, idx);
15129
15130 int ret = extcommunity_list_set(bgp_clist, cl_number_or_name, str,
15131 direct, style);
15132
15133 XFREE(MTYPE_TMP, str);
15134
15135 if (ret < 0) {
15136 community_list_perror(vty, ret);
15137 return CMD_WARNING_CONFIG_FAILED;
15138 }
15139
15140 return CMD_SUCCESS;
15141 }
15142
15143 ALIAS (extcommunity_list_name_expanded,
15144 ip_extcommunity_list_name_expanded_cmd,
15145 "ip extcommunity-list <(100-500)|expanded WORD> <deny|permit> LINE...",
15146 IP_STR
15147 EXTCOMMUNITY_LIST_STR
15148 "Extended Community list number (expanded)\n"
15149 "Specify expanded extcommunity-list\n"
15150 "Extended Community list name\n"
15151 "Specify community to reject\n"
15152 "Specify community to accept\n"
15153 "An ordered list as a regular-expression\n")
15154
15155 DEFUN (no_extcommunity_list_standard_all,
15156 no_bgp_extcommunity_list_standard_all_cmd,
15157 "no bgp extcommunity-list <(1-99)|standard WORD> <deny|permit> AA:NN...",
15158 NO_STR
15159 BGP_STR
15160 EXTCOMMUNITY_LIST_STR
15161 "Extended Community list number (standard)\n"
15162 "Specify standard extcommunity-list\n"
15163 "Community list name\n"
15164 "Specify community to reject\n"
15165 "Specify community to accept\n"
15166 EXTCOMMUNITY_VAL_STR)
15167 {
15168 int style = EXTCOMMUNITY_LIST_STANDARD;
15169 int direct = 0;
15170 char *cl_number_or_name = NULL;
15171 char *str = NULL;
15172
15173 int idx = 0;
15174 if (argv_find(argv, argc, "ip", &idx)) {
15175 vty_out(vty, "This config option is deprecated, and is scheduled for removal\n");
15176 vty_out(vty, "if you are using this please migrate to the below command.\n");
15177 vty_out(vty, "'no bgp extcommunity-list <(1-99)|(100-500)|standard|expanded> <deny|permit> <LINE|AA:NN>'\n");
15178 zlog_warn("Deprecated option: ‘no ip extcommunity-list <(1-99)|(100-500)|standard|expanded> <deny|permit> <LINE|AA:NN>' being used");
15179 }
15180
15181 idx = 0;
15182 argv_find(argv, argc, "permit", &idx);
15183 argv_find(argv, argc, "deny", &idx);
15184
15185 if (idx) {
15186 direct = argv_find(argv, argc, "permit", &idx)
15187 ? COMMUNITY_PERMIT
15188 : COMMUNITY_DENY;
15189
15190 idx = 0;
15191 argv_find(argv, argc, "AA:NN", &idx);
15192 str = argv_concat(argv, argc, idx);
15193 }
15194
15195 idx = 0;
15196 argv_find(argv, argc, "(1-99)", &idx);
15197 argv_find(argv, argc, "WORD", &idx);
15198 cl_number_or_name = argv[idx]->arg;
15199
15200 int ret = extcommunity_list_unset(bgp_clist, cl_number_or_name, str,
15201 direct, style);
15202
15203 XFREE(MTYPE_TMP, str);
15204
15205 if (ret < 0) {
15206 community_list_perror(vty, ret);
15207 return CMD_WARNING_CONFIG_FAILED;
15208 }
15209
15210 return CMD_SUCCESS;
15211 }
15212
15213 ALIAS (no_extcommunity_list_standard_all,
15214 no_ip_extcommunity_list_standard_all_cmd,
15215 "no ip extcommunity-list <(1-99)|standard WORD> <deny|permit> AA:NN...",
15216 NO_STR
15217 IP_STR
15218 EXTCOMMUNITY_LIST_STR
15219 "Extended Community list number (standard)\n"
15220 "Specify standard extcommunity-list\n"
15221 "Community list name\n"
15222 "Specify community to reject\n"
15223 "Specify community to accept\n"
15224 EXTCOMMUNITY_VAL_STR)
15225
15226 ALIAS(no_extcommunity_list_standard_all,
15227 no_bgp_extcommunity_list_standard_all_list_cmd,
15228 "no bgp extcommunity-list <(1-99)|standard WORD>",
15229 NO_STR IP_STR EXTCOMMUNITY_LIST_STR
15230 "Extended Community list number (standard)\n"
15231 "Specify standard extcommunity-list\n"
15232 "Community list name\n")
15233
15234 ALIAS(no_extcommunity_list_standard_all,
15235 no_ip_extcommunity_list_standard_all_list_cmd,
15236 "no ip extcommunity-list <(1-99)|standard WORD>",
15237 NO_STR IP_STR EXTCOMMUNITY_LIST_STR
15238 "Extended Community list number (standard)\n"
15239 "Specify standard extcommunity-list\n"
15240 "Community list name\n")
15241
15242 DEFUN (no_extcommunity_list_expanded_all,
15243 no_bgp_extcommunity_list_expanded_all_cmd,
15244 "no bgp extcommunity-list <(100-500)|expanded WORD> <deny|permit> LINE...",
15245 NO_STR
15246 BGP_STR
15247 EXTCOMMUNITY_LIST_STR
15248 "Extended Community list number (expanded)\n"
15249 "Specify expanded extcommunity-list\n"
15250 "Extended Community list name\n"
15251 "Specify community to reject\n"
15252 "Specify community to accept\n"
15253 "An ordered list as a regular-expression\n")
15254 {
15255 int style = EXTCOMMUNITY_LIST_EXPANDED;
15256 int direct = 0;
15257 char *cl_number_or_name = NULL;
15258 char *str = NULL;
15259
15260 int idx = 0;
15261 if (argv_find(argv, argc, "ip", &idx)) {
15262 vty_out(vty, "This config option is deprecated, and is scheduled for removal.\n");
15263 vty_out(vty, "if you are using this please migrate to the below command.\n");
15264 vty_out(vty, "'no bgp extcommunity-list <(1-99)|(100-500)|standard|expanded> <deny|permit> <LINE|AA:NN>'\n");
15265 zlog_warn("Deprecated option: ‘no ip extcommunity-list <(1-99)|(100-500)|standard|expanded> <deny|permit> <LINE|AA:NN>' being used");
15266 }
15267
15268 idx = 0;
15269 argv_find(argv, argc, "permit", &idx);
15270 argv_find(argv, argc, "deny", &idx);
15271
15272 if (idx) {
15273 direct = argv_find(argv, argc, "permit", &idx)
15274 ? COMMUNITY_PERMIT
15275 : COMMUNITY_DENY;
15276
15277 idx = 0;
15278 argv_find(argv, argc, "LINE", &idx);
15279 str = argv_concat(argv, argc, idx);
15280 }
15281
15282 idx = 0;
15283 argv_find(argv, argc, "(100-500)", &idx);
15284 argv_find(argv, argc, "WORD", &idx);
15285 cl_number_or_name = argv[idx]->arg;
15286
15287 int ret = extcommunity_list_unset(bgp_clist, cl_number_or_name, str,
15288 direct, style);
15289
15290 XFREE(MTYPE_TMP, str);
15291
15292 if (ret < 0) {
15293 community_list_perror(vty, ret);
15294 return CMD_WARNING_CONFIG_FAILED;
15295 }
15296
15297 return CMD_SUCCESS;
15298 }
15299
15300 ALIAS (no_extcommunity_list_expanded_all,
15301 no_ip_extcommunity_list_expanded_all_cmd,
15302 "no ip extcommunity-list <(100-500)|expanded WORD> <deny|permit> LINE...",
15303 NO_STR
15304 IP_STR
15305 EXTCOMMUNITY_LIST_STR
15306 "Extended Community list number (expanded)\n"
15307 "Specify expanded extcommunity-list\n"
15308 "Extended Community list name\n"
15309 "Specify community to reject\n"
15310 "Specify community to accept\n"
15311 "An ordered list as a regular-expression\n")
15312
15313 ALIAS(no_extcommunity_list_expanded_all,
15314 no_ip_extcommunity_list_expanded_all_list_cmd,
15315 "no ip extcommunity-list <(100-500)|expanded WORD>",
15316 NO_STR IP_STR EXTCOMMUNITY_LIST_STR
15317 "Extended Community list number (expanded)\n"
15318 "Specify expanded extcommunity-list\n"
15319 "Extended Community list name\n")
15320
15321 ALIAS(no_extcommunity_list_expanded_all,
15322 no_bgp_extcommunity_list_expanded_all_list_cmd,
15323 "no bgp extcommunity-list <(100-500)|expanded WORD>",
15324 NO_STR IP_STR EXTCOMMUNITY_LIST_STR
15325 "Extended Community list number (expanded)\n"
15326 "Specify expanded extcommunity-list\n"
15327 "Extended Community list name\n")
15328
15329 static void extcommunity_list_show(struct vty *vty, struct community_list *list)
15330 {
15331 struct community_entry *entry;
15332
15333 for (entry = list->head; entry; entry = entry->next) {
15334 if (entry == list->head) {
15335 if (all_digit(list->name))
15336 vty_out(vty, "Extended community %s list %s\n",
15337 entry->style == EXTCOMMUNITY_LIST_STANDARD
15338 ? "standard"
15339 : "(expanded) access",
15340 list->name);
15341 else
15342 vty_out(vty,
15343 "Named extended community %s list %s\n",
15344 entry->style == EXTCOMMUNITY_LIST_STANDARD
15345 ? "standard"
15346 : "expanded",
15347 list->name);
15348 }
15349 if (entry->any)
15350 vty_out(vty, " %s\n",
15351 community_direct_str(entry->direct));
15352 else
15353 vty_out(vty, " %s %s\n",
15354 community_direct_str(entry->direct),
15355 community_list_config_str(entry));
15356 }
15357 }
15358
15359 DEFUN (show_extcommunity_list,
15360 show_bgp_extcommunity_list_cmd,
15361 "show bgp extcommunity-list",
15362 SHOW_STR
15363 BGP_STR
15364 "List extended-community list\n")
15365 {
15366 struct community_list *list;
15367 struct community_list_master *cm;
15368 int idx = 0;
15369
15370 if (argv_find(argv, argc, "ip", &idx)) {
15371 vty_out(vty, "This config option is deprecated, and is scheduled for removal\n");
15372 vty_out(vty, "if you are using this please migrate to the below command.\n");
15373 vty_out(vty, "'show bgp extcommunity-list <(1-500)|WORD>'\n");
15374 zlog_warn("Deprecated option: 'ip show extcommunity-list <(1-500)|WORD>' being used");
15375 }
15376 cm = community_list_master_lookup(bgp_clist, EXTCOMMUNITY_LIST_MASTER);
15377 if (!cm)
15378 return CMD_SUCCESS;
15379
15380 for (list = cm->num.head; list; list = list->next)
15381 extcommunity_list_show(vty, list);
15382
15383 for (list = cm->str.head; list; list = list->next)
15384 extcommunity_list_show(vty, list);
15385
15386 return CMD_SUCCESS;
15387 }
15388
15389 ALIAS (show_extcommunity_list,
15390 show_ip_extcommunity_list_cmd,
15391 "show ip extcommunity-list",
15392 SHOW_STR
15393 IP_STR
15394 "List extended-community list\n")
15395
15396 DEFUN (show_extcommunity_list_arg,
15397 show_bgp_extcommunity_list_arg_cmd,
15398 "show bgp extcommunity-list <(1-500)|WORD>",
15399 SHOW_STR
15400 BGP_STR
15401 "List extended-community list\n"
15402 "Extcommunity-list number\n"
15403 "Extcommunity-list name\n")
15404 {
15405 int idx_comm_list = 3;
15406 struct community_list *list;
15407 int idx = 0;
15408
15409 if (argv_find(argv, argc, "ip", &idx)) {
15410 vty_out(vty, "This config option is deprecated, and is scheduled for removal.\n");
15411 vty_out(vty, "if you are using this please migrate to the below command.\n");
15412 vty_out(vty, "'show bgp extcommunity-list <(1-500)|WORD>'\n");
15413 zlog_warn("Deprecated option: 'ip show extcommunity-list <(1-500)|WORD>' being used");
15414 }
15415 list = community_list_lookup(bgp_clist, argv[idx_comm_list]->arg, 0,
15416 EXTCOMMUNITY_LIST_MASTER);
15417 if (!list) {
15418 vty_out(vty, "%% Can't find extcommunity-list\n");
15419 return CMD_WARNING;
15420 }
15421
15422 extcommunity_list_show(vty, list);
15423
15424 return CMD_SUCCESS;
15425 }
15426
15427 ALIAS (show_extcommunity_list_arg,
15428 show_ip_extcommunity_list_arg_cmd,
15429 "show ip extcommunity-list <(1-500)|WORD>",
15430 SHOW_STR
15431 IP_STR
15432 "List extended-community list\n"
15433 "Extcommunity-list number\n"
15434 "Extcommunity-list name\n")
15435
15436 /* Display community-list and extcommunity-list configuration. */
15437 static int community_list_config_write(struct vty *vty)
15438 {
15439 struct community_list *list;
15440 struct community_entry *entry;
15441 struct community_list_master *cm;
15442 int write = 0;
15443
15444 /* Community-list. */
15445 cm = community_list_master_lookup(bgp_clist, COMMUNITY_LIST_MASTER);
15446
15447 for (list = cm->num.head; list; list = list->next)
15448 for (entry = list->head; entry; entry = entry->next) {
15449 vty_out(vty, "bgp community-list %s %s %s\n", list->name,
15450 community_direct_str(entry->direct),
15451 community_list_config_str(entry));
15452 write++;
15453 }
15454 for (list = cm->str.head; list; list = list->next)
15455 for (entry = list->head; entry; entry = entry->next) {
15456 vty_out(vty, "bgp community-list %s %s %s %s\n",
15457 entry->style == COMMUNITY_LIST_STANDARD
15458 ? "standard"
15459 : "expanded",
15460 list->name, community_direct_str(entry->direct),
15461 community_list_config_str(entry));
15462 write++;
15463 }
15464
15465 /* Extcommunity-list. */
15466 cm = community_list_master_lookup(bgp_clist, EXTCOMMUNITY_LIST_MASTER);
15467
15468 for (list = cm->num.head; list; list = list->next)
15469 for (entry = list->head; entry; entry = entry->next) {
15470 vty_out(vty, "bgp extcommunity-list %s %s %s\n",
15471 list->name, community_direct_str(entry->direct),
15472 community_list_config_str(entry));
15473 write++;
15474 }
15475 for (list = cm->str.head; list; list = list->next)
15476 for (entry = list->head; entry; entry = entry->next) {
15477 vty_out(vty, "bgp extcommunity-list %s %s %s %s\n",
15478 entry->style == EXTCOMMUNITY_LIST_STANDARD
15479 ? "standard"
15480 : "expanded",
15481 list->name, community_direct_str(entry->direct),
15482 community_list_config_str(entry));
15483 write++;
15484 }
15485
15486
15487 /* lcommunity-list. */
15488 cm = community_list_master_lookup(bgp_clist,
15489 LARGE_COMMUNITY_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 large-community-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 large-community-list %s %s %s %s\n",
15501 entry->style == LARGE_COMMUNITY_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 return write;
15510 }
15511
15512 static struct cmd_node community_list_node = {
15513 COMMUNITY_LIST_NODE, "", 1 /* Export to vtysh. */
15514 };
15515
15516 static void community_list_vty(void)
15517 {
15518 install_node(&community_list_node, community_list_config_write);
15519
15520 /* Community-list. */
15521 install_element(CONFIG_NODE, &bgp_community_list_standard_cmd);
15522 install_element(CONFIG_NODE, &bgp_community_list_expanded_all_cmd);
15523 install_element(CONFIG_NODE, &no_bgp_community_list_standard_all_cmd);
15524 install_element(CONFIG_NODE, &no_bgp_community_list_standard_all_list_cmd);
15525 install_element(CONFIG_NODE, &no_bgp_community_list_expanded_all_cmd);
15526 install_element(CONFIG_NODE, &no_bgp_community_list_expanded_all_list_cmd);
15527 install_element(VIEW_NODE, &show_bgp_community_list_cmd);
15528 install_element(VIEW_NODE, &show_bgp_community_list_arg_cmd);
15529 install_element(CONFIG_NODE, &ip_community_list_standard_cmd);
15530 install_element(CONFIG_NODE, &ip_community_list_expanded_all_cmd);
15531 install_element(CONFIG_NODE, &no_ip_community_list_standard_all_cmd);
15532 install_element(CONFIG_NODE, &no_ip_community_list_standard_all_list_cmd);
15533 install_element(CONFIG_NODE, &no_ip_community_list_expanded_all_cmd);
15534 install_element(CONFIG_NODE, &no_ip_community_list_expanded_all_list_cmd);
15535 install_element(VIEW_NODE, &show_ip_community_list_cmd);
15536 install_element(VIEW_NODE, &show_ip_community_list_arg_cmd);
15537
15538 /* Extcommunity-list. */
15539 install_element(CONFIG_NODE, &bgp_extcommunity_list_standard_cmd);
15540 install_element(CONFIG_NODE, &bgp_extcommunity_list_name_expanded_cmd);
15541 install_element(CONFIG_NODE, &no_bgp_extcommunity_list_standard_all_cmd);
15542 install_element(CONFIG_NODE,
15543 &no_bgp_extcommunity_list_standard_all_list_cmd);
15544 install_element(CONFIG_NODE, &no_bgp_extcommunity_list_expanded_all_cmd);
15545 install_element(CONFIG_NODE,
15546 &no_bgp_extcommunity_list_expanded_all_list_cmd);
15547 install_element(VIEW_NODE, &show_bgp_extcommunity_list_cmd);
15548 install_element(VIEW_NODE, &show_bgp_extcommunity_list_arg_cmd);
15549 install_element(CONFIG_NODE, &ip_extcommunity_list_standard_cmd);
15550 install_element(CONFIG_NODE, &ip_extcommunity_list_name_expanded_cmd);
15551 install_element(CONFIG_NODE, &no_ip_extcommunity_list_standard_all_cmd);
15552 install_element(CONFIG_NODE, &no_ip_extcommunity_list_standard_all_list_cmd);
15553 install_element(CONFIG_NODE, &no_ip_extcommunity_list_expanded_all_cmd);
15554 install_element(CONFIG_NODE, &no_ip_extcommunity_list_expanded_all_list_cmd);
15555 install_element(VIEW_NODE, &show_ip_extcommunity_list_cmd);
15556 install_element(VIEW_NODE, &show_ip_extcommunity_list_arg_cmd);
15557
15558 /* Large Community List */
15559 install_element(CONFIG_NODE, &bgp_lcommunity_list_standard_cmd);
15560 install_element(CONFIG_NODE, &bgp_lcommunity_list_standard1_cmd);
15561 install_element(CONFIG_NODE, &bgp_lcommunity_list_expanded_cmd);
15562 install_element(CONFIG_NODE, &bgp_lcommunity_list_name_standard_cmd);
15563 install_element(CONFIG_NODE, &bgp_lcommunity_list_name_standard1_cmd);
15564 install_element(CONFIG_NODE, &bgp_lcommunity_list_name_expanded_cmd);
15565 install_element(CONFIG_NODE, &no_bgp_lcommunity_list_standard_all_cmd);
15566 install_element(CONFIG_NODE,
15567 &no_bgp_lcommunity_list_name_expanded_all_cmd);
15568 install_element(CONFIG_NODE, &no_bgp_lcommunity_list_standard_cmd);
15569 install_element(CONFIG_NODE, &no_bgp_lcommunity_list_expanded_cmd);
15570 install_element(CONFIG_NODE, &no_bgp_lcommunity_list_name_standard_cmd);
15571 install_element(CONFIG_NODE, &no_bgp_lcommunity_list_name_expanded_cmd);
15572 install_element(VIEW_NODE, &show_bgp_lcommunity_list_cmd);
15573 install_element(VIEW_NODE, &show_bgp_lcommunity_list_arg_cmd);
15574 install_element(CONFIG_NODE, &ip_lcommunity_list_standard_cmd);
15575 install_element(CONFIG_NODE, &ip_lcommunity_list_standard1_cmd);
15576 install_element(CONFIG_NODE, &ip_lcommunity_list_expanded_cmd);
15577 install_element(CONFIG_NODE, &ip_lcommunity_list_name_standard_cmd);
15578 install_element(CONFIG_NODE, &ip_lcommunity_list_name_standard1_cmd);
15579 install_element(CONFIG_NODE, &ip_lcommunity_list_name_expanded_cmd);
15580 install_element(CONFIG_NODE, &no_ip_lcommunity_list_standard_all_cmd);
15581 install_element(CONFIG_NODE,
15582 &no_ip_lcommunity_list_name_expanded_all_cmd);
15583 install_element(CONFIG_NODE, &no_ip_lcommunity_list_standard_cmd);
15584 install_element(CONFIG_NODE, &no_ip_lcommunity_list_expanded_cmd);
15585 install_element(CONFIG_NODE, &no_ip_lcommunity_list_name_standard_cmd);
15586 install_element(CONFIG_NODE, &no_ip_lcommunity_list_name_expanded_cmd);
15587 install_element(VIEW_NODE, &show_ip_lcommunity_list_cmd);
15588 install_element(VIEW_NODE, &show_ip_lcommunity_list_arg_cmd);
15589 }