]> git.proxmox.com Git - mirror_frr.git/blob - bgpd/bgp_vty.c
Merge pull request #3899 from ton31337/fix/remove_private_as_with_local_as
[mirror_frr.git] / bgpd / bgp_vty.c
1 /* BGP VTY interface.
2 * Copyright (C) 1996, 97, 98, 99, 2000 Kunihiro Ishiguro
3 *
4 * This file is part of GNU Zebra.
5 *
6 * GNU Zebra is free software; you can redistribute it and/or modify it
7 * under the terms of the GNU General Public License as published by the
8 * Free Software Foundation; either version 2, or (at your option) any
9 * later version.
10 *
11 * GNU Zebra is distributed in the hope that it will be useful, but
12 * WITHOUT ANY WARRANTY; without even the implied warranty of
13 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
14 * General Public License for more details.
15 *
16 * You should have received a copy of the GNU General Public License along
17 * with this program; see the file COPYING; if not, write to the Free Software
18 * Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA
19 */
20
21 #include <zebra.h>
22
23 #include "command.h"
24 #include "lib/json.h"
25 #include "lib/zclient.h"
26 #include "prefix.h"
27 #include "plist.h"
28 #include "buffer.h"
29 #include "linklist.h"
30 #include "stream.h"
31 #include "thread.h"
32 #include "log.h"
33 #include "memory.h"
34 #include "memory_vty.h"
35 #include "hash.h"
36 #include "queue.h"
37 #include "filter.h"
38 #include "frrstr.h"
39
40 #include "bgpd/bgpd.h"
41 #include "bgpd/bgp_attr_evpn.h"
42 #include "bgpd/bgp_advertise.h"
43 #include "bgpd/bgp_attr.h"
44 #include "bgpd/bgp_aspath.h"
45 #include "bgpd/bgp_community.h"
46 #include "bgpd/bgp_ecommunity.h"
47 #include "bgpd/bgp_lcommunity.h"
48 #include "bgpd/bgp_damp.h"
49 #include "bgpd/bgp_debug.h"
50 #include "bgpd/bgp_errors.h"
51 #include "bgpd/bgp_fsm.h"
52 #include "bgpd/bgp_nexthop.h"
53 #include "bgpd/bgp_open.h"
54 #include "bgpd/bgp_regex.h"
55 #include "bgpd/bgp_route.h"
56 #include "bgpd/bgp_mplsvpn.h"
57 #include "bgpd/bgp_zebra.h"
58 #include "bgpd/bgp_table.h"
59 #include "bgpd/bgp_vty.h"
60 #include "bgpd/bgp_mpath.h"
61 #include "bgpd/bgp_packet.h"
62 #include "bgpd/bgp_updgrp.h"
63 #include "bgpd/bgp_bfd.h"
64 #include "bgpd/bgp_io.h"
65 #include "bgpd/bgp_evpn.h"
66 #include "bgpd/bgp_addpath.h"
67 #include "bgpd/bgp_mac.h"
68
69 static struct peer_group *listen_range_exists(struct bgp *bgp,
70 struct prefix *range, int exact);
71
72 static enum node_type bgp_node_type(afi_t afi, safi_t safi)
73 {
74 switch (afi) {
75 case AFI_IP:
76 switch (safi) {
77 case SAFI_UNICAST:
78 return BGP_IPV4_NODE;
79 break;
80 case SAFI_MULTICAST:
81 return BGP_IPV4M_NODE;
82 break;
83 case SAFI_LABELED_UNICAST:
84 return BGP_IPV4L_NODE;
85 break;
86 case SAFI_MPLS_VPN:
87 return BGP_VPNV4_NODE;
88 break;
89 case SAFI_FLOWSPEC:
90 return BGP_FLOWSPECV4_NODE;
91 default:
92 /* not expected */
93 return BGP_IPV4_NODE;
94 break;
95 }
96 break;
97 case AFI_IP6:
98 switch (safi) {
99 case SAFI_UNICAST:
100 return BGP_IPV6_NODE;
101 break;
102 case SAFI_MULTICAST:
103 return BGP_IPV6M_NODE;
104 break;
105 case SAFI_LABELED_UNICAST:
106 return BGP_IPV6L_NODE;
107 break;
108 case SAFI_MPLS_VPN:
109 return BGP_VPNV6_NODE;
110 break;
111 case SAFI_FLOWSPEC:
112 return BGP_FLOWSPECV6_NODE;
113 default:
114 /* not expected */
115 return BGP_IPV4_NODE;
116 break;
117 }
118 break;
119 case AFI_L2VPN:
120 return BGP_EVPN_NODE;
121 break;
122 case AFI_MAX:
123 // We should never be here but to clarify the switch statement..
124 return BGP_IPV4_NODE;
125 break;
126 }
127
128 // Impossible to happen
129 return BGP_IPV4_NODE;
130 }
131
132 /* Utility function to get address family from current node. */
133 afi_t bgp_node_afi(struct vty *vty)
134 {
135 afi_t afi;
136 switch (vty->node) {
137 case BGP_IPV6_NODE:
138 case BGP_IPV6M_NODE:
139 case BGP_IPV6L_NODE:
140 case BGP_VPNV6_NODE:
141 case BGP_FLOWSPECV6_NODE:
142 afi = AFI_IP6;
143 break;
144 case BGP_EVPN_NODE:
145 afi = AFI_L2VPN;
146 break;
147 default:
148 afi = AFI_IP;
149 break;
150 }
151 return afi;
152 }
153
154 /* Utility function to get subsequent address family from current
155 node. */
156 safi_t bgp_node_safi(struct vty *vty)
157 {
158 safi_t safi;
159 switch (vty->node) {
160 case BGP_VPNV4_NODE:
161 case BGP_VPNV6_NODE:
162 safi = SAFI_MPLS_VPN;
163 break;
164 case BGP_IPV4M_NODE:
165 case BGP_IPV6M_NODE:
166 safi = SAFI_MULTICAST;
167 break;
168 case BGP_EVPN_NODE:
169 safi = SAFI_EVPN;
170 break;
171 case BGP_IPV4L_NODE:
172 case BGP_IPV6L_NODE:
173 safi = SAFI_LABELED_UNICAST;
174 break;
175 case BGP_FLOWSPECV4_NODE:
176 case BGP_FLOWSPECV6_NODE:
177 safi = SAFI_FLOWSPEC;
178 break;
179 default:
180 safi = SAFI_UNICAST;
181 break;
182 }
183 return safi;
184 }
185
186 /**
187 * Converts an AFI in string form to afi_t
188 *
189 * @param afi string, one of
190 * - "ipv4"
191 * - "ipv6"
192 * - "l2vpn"
193 * @return the corresponding afi_t
194 */
195 afi_t bgp_vty_afi_from_str(const char *afi_str)
196 {
197 afi_t afi = AFI_MAX; /* unknown */
198 if (strmatch(afi_str, "ipv4"))
199 afi = AFI_IP;
200 else if (strmatch(afi_str, "ipv6"))
201 afi = AFI_IP6;
202 else if (strmatch(afi_str, "l2vpn"))
203 afi = AFI_L2VPN;
204 return afi;
205 }
206
207 int argv_find_and_parse_afi(struct cmd_token **argv, int argc, int *index,
208 afi_t *afi)
209 {
210 int ret = 0;
211 if (argv_find(argv, argc, "ipv4", index)) {
212 ret = 1;
213 if (afi)
214 *afi = AFI_IP;
215 } else if (argv_find(argv, argc, "ipv6", index)) {
216 ret = 1;
217 if (afi)
218 *afi = AFI_IP6;
219 }
220 return ret;
221 }
222
223 /* supports <unicast|multicast|vpn|labeled-unicast> */
224 safi_t bgp_vty_safi_from_str(const char *safi_str)
225 {
226 safi_t safi = SAFI_MAX; /* unknown */
227 if (strmatch(safi_str, "multicast"))
228 safi = SAFI_MULTICAST;
229 else if (strmatch(safi_str, "unicast"))
230 safi = SAFI_UNICAST;
231 else if (strmatch(safi_str, "vpn"))
232 safi = SAFI_MPLS_VPN;
233 else if (strmatch(safi_str, "evpn"))
234 safi = SAFI_EVPN;
235 else if (strmatch(safi_str, "labeled-unicast"))
236 safi = SAFI_LABELED_UNICAST;
237 else if (strmatch(safi_str, "flowspec"))
238 safi = SAFI_FLOWSPEC;
239 return safi;
240 }
241
242 int argv_find_and_parse_safi(struct cmd_token **argv, int argc, int *index,
243 safi_t *safi)
244 {
245 int ret = 0;
246 if (argv_find(argv, argc, "unicast", index)) {
247 ret = 1;
248 if (safi)
249 *safi = SAFI_UNICAST;
250 } else if (argv_find(argv, argc, "multicast", index)) {
251 ret = 1;
252 if (safi)
253 *safi = SAFI_MULTICAST;
254 } else if (argv_find(argv, argc, "labeled-unicast", index)) {
255 ret = 1;
256 if (safi)
257 *safi = SAFI_LABELED_UNICAST;
258 } else if (argv_find(argv, argc, "vpn", index)) {
259 ret = 1;
260 if (safi)
261 *safi = SAFI_MPLS_VPN;
262 } else if (argv_find(argv, argc, "flowspec", index)) {
263 ret = 1;
264 if (safi)
265 *safi = SAFI_FLOWSPEC;
266 }
267 return ret;
268 }
269
270 /*
271 * bgp_vty_find_and_parse_afi_safi_bgp
272 *
273 * For a given 'show ...' command, correctly parse the afi/safi/bgp out from it
274 * This function *assumes* that the calling function pre-sets the afi/safi/bgp
275 * to appropriate values for the calling function. This is to allow the
276 * calling function to make decisions appropriate for the show command
277 * that is being parsed.
278 *
279 * The show commands are generally of the form:
280 * "show [ip] bgp [<view|vrf> VIEWVRFNAME] [<ipv4|ipv6>
281 * [<unicast|multicast|vpn|labeled-unicast>]] ..."
282 *
283 * Since we use argv_find if the show command in particular doesn't have:
284 * [ip]
285 * [<view|vrf> VIEWVRFNAME]
286 * [<ipv4|ipv6> [<unicast|multicast|vpn|labeled-unicast>]]
287 * The command parsing should still be ok.
288 *
289 * vty -> The vty for the command so we can output some useful data in
290 * the event of a parse error in the vrf.
291 * argv -> The command tokens
292 * argc -> How many command tokens we have
293 * idx -> The current place in the command, generally should be 0 for this
294 * function
295 * afi -> The parsed afi if it was included in the show command, returned here
296 * safi -> The parsed safi if it was included in the show command, returned here
297 * bgp -> Pointer to the bgp data structure we need to fill in.
298 *
299 * The function returns the correct location in the parse tree for the
300 * last token found.
301 *
302 * Returns 0 for failure to parse correctly, else the idx position of where
303 * it found the last token.
304 */
305 int bgp_vty_find_and_parse_afi_safi_bgp(struct vty *vty,
306 struct cmd_token **argv, int argc,
307 int *idx, afi_t *afi, safi_t *safi,
308 struct bgp **bgp, bool use_json)
309 {
310 char *vrf_name = NULL;
311
312 assert(afi);
313 assert(safi);
314 assert(bgp);
315
316 if (argv_find(argv, argc, "ip", idx))
317 *afi = AFI_IP;
318
319 if (argv_find(argv, argc, "view", idx))
320 vrf_name = argv[*idx + 1]->arg;
321 else if (argv_find(argv, argc, "vrf", idx)) {
322 vrf_name = argv[*idx + 1]->arg;
323 if (strmatch(vrf_name, VRF_DEFAULT_NAME))
324 vrf_name = NULL;
325 }
326 if (vrf_name) {
327 if (strmatch(vrf_name, "all"))
328 *bgp = NULL;
329 else {
330 *bgp = bgp_lookup_by_name(vrf_name);
331 if (!*bgp) {
332 if (use_json)
333 vty_out(vty, "{}\n");
334 else
335 vty_out(vty, "View/Vrf %s is unknown\n",
336 vrf_name);
337 *idx = 0;
338 return 0;
339 }
340 }
341 } else {
342 *bgp = bgp_get_default();
343 if (!*bgp) {
344 if (use_json)
345 vty_out(vty, "{}\n");
346 else
347 vty_out(vty,
348 "Default BGP instance not found\n");
349 *idx = 0;
350 return 0;
351 }
352 }
353
354 if (argv_find_and_parse_afi(argv, argc, idx, afi))
355 argv_find_and_parse_safi(argv, argc, idx, safi);
356
357 *idx += 1;
358 return *idx;
359 }
360
361 static int peer_address_self_check(struct bgp *bgp, union sockunion *su)
362 {
363 struct interface *ifp = NULL;
364
365 if (su->sa.sa_family == AF_INET)
366 ifp = if_lookup_by_ipv4_exact(&su->sin.sin_addr, bgp->vrf_id);
367 else if (su->sa.sa_family == AF_INET6)
368 ifp = if_lookup_by_ipv6_exact(&su->sin6.sin6_addr,
369 su->sin6.sin6_scope_id,
370 bgp->vrf_id);
371
372 if (ifp)
373 return 1;
374
375 return 0;
376 }
377
378 /* Utility function for looking up peer from VTY. */
379 /* This is used only for configuration, so disallow if attempted on
380 * a dynamic neighbor.
381 */
382 static struct peer *peer_lookup_vty(struct vty *vty, const char *ip_str)
383 {
384 struct bgp *bgp = VTY_GET_CONTEXT(bgp);
385 int ret;
386 union sockunion su;
387 struct peer *peer;
388
389 if (!bgp) {
390 return NULL;
391 }
392
393 ret = str2sockunion(ip_str, &su);
394 if (ret < 0) {
395 peer = peer_lookup_by_conf_if(bgp, ip_str);
396 if (!peer) {
397 if ((peer = peer_lookup_by_hostname(bgp, ip_str))
398 == NULL) {
399 vty_out(vty,
400 "%% Malformed address or name: %s\n",
401 ip_str);
402 return NULL;
403 }
404 }
405 } else {
406 peer = peer_lookup(bgp, &su);
407 if (!peer) {
408 vty_out(vty,
409 "%% Specify remote-as or peer-group commands first\n");
410 return NULL;
411 }
412 if (peer_dynamic_neighbor(peer)) {
413 vty_out(vty,
414 "%% Operation not allowed on a dynamic neighbor\n");
415 return NULL;
416 }
417 }
418 return peer;
419 }
420
421 /* Utility function for looking up peer or peer group. */
422 /* This is used only for configuration, so disallow if attempted on
423 * a dynamic neighbor.
424 */
425 struct peer *peer_and_group_lookup_vty(struct vty *vty, const char *peer_str)
426 {
427 struct bgp *bgp = VTY_GET_CONTEXT(bgp);
428 int ret;
429 union sockunion su;
430 struct peer *peer = NULL;
431 struct peer_group *group = NULL;
432
433 if (!bgp) {
434 return NULL;
435 }
436
437 ret = str2sockunion(peer_str, &su);
438 if (ret == 0) {
439 /* IP address, locate peer. */
440 peer = peer_lookup(bgp, &su);
441 } else {
442 /* Not IP, could match either peer configured on interface or a
443 * group. */
444 peer = peer_lookup_by_conf_if(bgp, peer_str);
445 if (!peer)
446 group = peer_group_lookup(bgp, peer_str);
447 }
448
449 if (peer) {
450 if (peer_dynamic_neighbor(peer)) {
451 vty_out(vty,
452 "%% Operation not allowed on a dynamic neighbor\n");
453 return NULL;
454 }
455
456 return peer;
457 }
458
459 if (group)
460 return group->conf;
461
462 vty_out(vty, "%% Specify remote-as or peer-group commands first\n");
463
464 return NULL;
465 }
466
467 int bgp_vty_return(struct vty *vty, int ret)
468 {
469 const char *str = NULL;
470
471 switch (ret) {
472 case BGP_ERR_INVALID_VALUE:
473 str = "Invalid value";
474 break;
475 case BGP_ERR_INVALID_FLAG:
476 str = "Invalid flag";
477 break;
478 case BGP_ERR_PEER_GROUP_SHUTDOWN:
479 str = "Peer-group has been shutdown. Activate the peer-group first";
480 break;
481 case BGP_ERR_PEER_FLAG_CONFLICT:
482 str = "Can't set override-capability and strict-capability-match at the same time";
483 break;
484 case BGP_ERR_PEER_GROUP_NO_REMOTE_AS:
485 str = "Specify remote-as or peer-group remote AS first";
486 break;
487 case BGP_ERR_PEER_GROUP_CANT_CHANGE:
488 str = "Cannot change the peer-group. Deconfigure first";
489 break;
490 case BGP_ERR_PEER_GROUP_MISMATCH:
491 str = "Peer is not a member of this peer-group";
492 break;
493 case BGP_ERR_PEER_FILTER_CONFLICT:
494 str = "Prefix/distribute list can not co-exist";
495 break;
496 case BGP_ERR_NOT_INTERNAL_PEER:
497 str = "Invalid command. Not an internal neighbor";
498 break;
499 case BGP_ERR_REMOVE_PRIVATE_AS:
500 str = "remove-private-AS cannot be configured for IBGP peers";
501 break;
502 case BGP_ERR_LOCAL_AS_ALLOWED_ONLY_FOR_EBGP:
503 str = "Local-AS allowed only for EBGP peers";
504 break;
505 case BGP_ERR_CANNOT_HAVE_LOCAL_AS_SAME_AS:
506 str = "Cannot have local-as same as BGP AS number";
507 break;
508 case BGP_ERR_TCPSIG_FAILED:
509 str = "Error while applying TCP-Sig to session(s)";
510 break;
511 case BGP_ERR_NO_EBGP_MULTIHOP_WITH_TTLHACK:
512 str = "ebgp-multihop and ttl-security cannot be configured together";
513 break;
514 case BGP_ERR_NO_IBGP_WITH_TTLHACK:
515 str = "ttl-security only allowed for EBGP peers";
516 break;
517 case BGP_ERR_AS_OVERRIDE:
518 str = "as-override cannot be configured for IBGP peers";
519 break;
520 case BGP_ERR_INVALID_DYNAMIC_NEIGHBORS_LIMIT:
521 str = "Invalid limit for number of dynamic neighbors";
522 break;
523 case BGP_ERR_DYNAMIC_NEIGHBORS_RANGE_EXISTS:
524 str = "Dynamic neighbor listen range already exists";
525 break;
526 case BGP_ERR_INVALID_FOR_DYNAMIC_PEER:
527 str = "Operation not allowed on a dynamic neighbor";
528 break;
529 case BGP_ERR_INVALID_FOR_DIRECT_PEER:
530 str = "Operation not allowed on a directly connected neighbor";
531 break;
532 case BGP_ERR_PEER_SAFI_CONFLICT:
533 str = "Cannot activate peer for both 'ipv4 unicast' and 'ipv4 labeled-unicast'";
534 break;
535 }
536 if (str) {
537 vty_out(vty, "%% %s\n", str);
538 return CMD_WARNING_CONFIG_FAILED;
539 }
540 return CMD_SUCCESS;
541 }
542
543 /* BGP clear sort. */
544 enum clear_sort {
545 clear_all,
546 clear_peer,
547 clear_group,
548 clear_external,
549 clear_as
550 };
551
552 static void bgp_clear_vty_error(struct vty *vty, struct peer *peer, afi_t afi,
553 safi_t safi, int error)
554 {
555 switch (error) {
556 case BGP_ERR_AF_UNCONFIGURED:
557 vty_out(vty,
558 "%%BGP: Enable %s address family for the neighbor %s\n",
559 afi_safi_print(afi, safi), peer->host);
560 break;
561 case BGP_ERR_SOFT_RECONFIG_UNCONFIGURED:
562 vty_out(vty,
563 "%%BGP: Inbound soft reconfig for %s not possible as it\n has neither refresh capability, nor inbound soft reconfig\n",
564 peer->host);
565 break;
566 default:
567 break;
568 }
569 }
570
571 /* `clear ip bgp' functions. */
572 static int bgp_clear(struct vty *vty, struct bgp *bgp, afi_t afi, safi_t safi,
573 enum clear_sort sort, enum bgp_clear_type stype,
574 const char *arg)
575 {
576 int ret;
577 bool found = false;
578 struct peer *peer;
579 struct listnode *node, *nnode;
580
581 /* Clear all neighbors. */
582 /*
583 * Pass along pointer to next node to peer_clear() when walking all
584 * nodes on the BGP instance as that may get freed if it is a
585 * doppelganger
586 */
587 if (sort == clear_all) {
588 for (ALL_LIST_ELEMENTS(bgp->peer, node, nnode, peer)) {
589 if (!peer->afc[afi][safi])
590 continue;
591
592 if (stype == BGP_CLEAR_SOFT_NONE)
593 ret = peer_clear(peer, &nnode);
594 else
595 ret = peer_clear_soft(peer, afi, safi, stype);
596
597 if (ret < 0)
598 bgp_clear_vty_error(vty, peer, afi, safi, ret);
599 else
600 found = true;
601 }
602
603 /* This is to apply read-only mode on this clear. */
604 if (stype == BGP_CLEAR_SOFT_NONE)
605 bgp->update_delay_over = 0;
606
607 if (!found)
608 vty_out(vty, "%%BGP: No %s peer configured\n",
609 afi_safi_print(afi, safi));
610
611 return CMD_SUCCESS;
612 }
613
614 /* Clear specified neighbor. */
615 if (sort == clear_peer) {
616 union sockunion su;
617
618 /* Make sockunion for lookup. */
619 ret = str2sockunion(arg, &su);
620 if (ret < 0) {
621 peer = peer_lookup_by_conf_if(bgp, arg);
622 if (!peer) {
623 peer = peer_lookup_by_hostname(bgp, arg);
624 if (!peer) {
625 vty_out(vty,
626 "Malformed address or name: %s\n",
627 arg);
628 return CMD_WARNING;
629 }
630 }
631 } else {
632 peer = peer_lookup(bgp, &su);
633 if (!peer) {
634 vty_out(vty,
635 "%%BGP: Unknown neighbor - \"%s\"\n",
636 arg);
637 return CMD_WARNING;
638 }
639 }
640
641 if (!peer->afc[afi][safi])
642 ret = BGP_ERR_AF_UNCONFIGURED;
643 else if (stype == BGP_CLEAR_SOFT_NONE)
644 ret = peer_clear(peer, NULL);
645 else
646 ret = peer_clear_soft(peer, afi, safi, stype);
647
648 if (ret < 0)
649 bgp_clear_vty_error(vty, peer, afi, safi, ret);
650
651 return CMD_SUCCESS;
652 }
653
654 /* Clear all neighbors belonging to a specific peer-group. */
655 if (sort == clear_group) {
656 struct peer_group *group;
657
658 group = peer_group_lookup(bgp, arg);
659 if (!group) {
660 vty_out(vty, "%%BGP: No such peer-group %s\n", arg);
661 return CMD_WARNING;
662 }
663
664 for (ALL_LIST_ELEMENTS(group->peer, node, nnode, peer)) {
665 if (!peer->afc[afi][safi])
666 continue;
667
668 if (stype == BGP_CLEAR_SOFT_NONE)
669 ret = peer_clear(peer, NULL);
670 else
671 ret = peer_clear_soft(peer, afi, safi, stype);
672
673 if (ret < 0)
674 bgp_clear_vty_error(vty, peer, afi, safi, ret);
675 else
676 found = true;
677 }
678
679 if (!found)
680 vty_out(vty,
681 "%%BGP: No %s peer belonging to peer-group %s is configured\n",
682 afi_safi_print(afi, safi), arg);
683
684 return CMD_SUCCESS;
685 }
686
687 /* Clear all external (eBGP) neighbors. */
688 if (sort == clear_external) {
689 for (ALL_LIST_ELEMENTS(bgp->peer, node, nnode, peer)) {
690 if (peer->sort == BGP_PEER_IBGP)
691 continue;
692
693 if (!peer->afc[afi][safi])
694 continue;
695
696 if (stype == BGP_CLEAR_SOFT_NONE)
697 ret = peer_clear(peer, &nnode);
698 else
699 ret = peer_clear_soft(peer, afi, safi, stype);
700
701 if (ret < 0)
702 bgp_clear_vty_error(vty, peer, afi, safi, ret);
703 else
704 found = true;
705 }
706
707 if (!found)
708 vty_out(vty,
709 "%%BGP: No external %s peer is configured\n",
710 afi_safi_print(afi, safi));
711
712 return CMD_SUCCESS;
713 }
714
715 /* Clear all neighbors belonging to a specific AS. */
716 if (sort == clear_as) {
717 as_t as = strtoul(arg, NULL, 10);
718
719 for (ALL_LIST_ELEMENTS(bgp->peer, node, nnode, peer)) {
720 if (peer->as != as)
721 continue;
722
723 if (!peer->afc[afi][safi])
724 ret = BGP_ERR_AF_UNCONFIGURED;
725 else if (stype == BGP_CLEAR_SOFT_NONE)
726 ret = peer_clear(peer, &nnode);
727 else
728 ret = peer_clear_soft(peer, afi, safi, stype);
729
730 if (ret < 0)
731 bgp_clear_vty_error(vty, peer, afi, safi, ret);
732 else
733 found = true;
734 }
735
736 if (!found)
737 vty_out(vty,
738 "%%BGP: No %s peer is configured with AS %s\n",
739 afi_safi_print(afi, safi), arg);
740
741 return CMD_SUCCESS;
742 }
743
744 return CMD_SUCCESS;
745 }
746
747 static int bgp_clear_vty(struct vty *vty, const char *name, afi_t afi,
748 safi_t safi, enum clear_sort sort,
749 enum bgp_clear_type stype, const char *arg)
750 {
751 struct bgp *bgp;
752
753 /* BGP structure lookup. */
754 if (name) {
755 bgp = bgp_lookup_by_name(name);
756 if (bgp == NULL) {
757 vty_out(vty, "Can't find BGP instance %s\n", name);
758 return CMD_WARNING;
759 }
760 } else {
761 bgp = bgp_get_default();
762 if (bgp == NULL) {
763 vty_out(vty, "No BGP process is configured\n");
764 return CMD_WARNING;
765 }
766 }
767
768 return bgp_clear(vty, bgp, afi, safi, sort, stype, arg);
769 }
770
771 /* clear soft inbound */
772 static void bgp_clear_star_soft_in(struct vty *vty, const char *name)
773 {
774 afi_t afi;
775 safi_t safi;
776
777 FOREACH_AFI_SAFI (afi, safi)
778 bgp_clear_vty(vty, name, afi, safi, clear_all,
779 BGP_CLEAR_SOFT_IN, NULL);
780 }
781
782 /* clear soft outbound */
783 static void bgp_clear_star_soft_out(struct vty *vty, const char *name)
784 {
785 afi_t afi;
786 safi_t safi;
787
788 FOREACH_AFI_SAFI (afi, safi)
789 bgp_clear_vty(vty, name, afi, safi, clear_all,
790 BGP_CLEAR_SOFT_OUT, NULL);
791 }
792
793
794 #ifndef VTYSH_EXTRACT_PL
795 #include "bgpd/bgp_vty_clippy.c"
796 #endif
797
798 /* BGP global configuration. */
799 #if (CONFDATE > 20190601)
800 CPP_NOTICE("bgpd: time to remove deprecated bgp multiple-instance")
801 CPP_NOTICE("This includes BGP_OPT_MULTIPLE_INSTANCE")
802 #endif
803 DEFUN_HIDDEN (bgp_multiple_instance_func,
804 bgp_multiple_instance_cmd,
805 "bgp multiple-instance",
806 BGP_STR
807 "Enable bgp multiple instance\n")
808 {
809 bgp_option_set(BGP_OPT_MULTIPLE_INSTANCE);
810 return CMD_SUCCESS;
811 }
812
813 DEFUN_HIDDEN (no_bgp_multiple_instance,
814 no_bgp_multiple_instance_cmd,
815 "no bgp multiple-instance",
816 NO_STR
817 BGP_STR
818 "BGP multiple instance\n")
819 {
820 int ret;
821
822 vty_out(vty, "This config option is deprecated, and is scheduled for removal.\n");
823 vty_out(vty, "if you are using this please let the developers know\n");
824 zlog_info("Deprecated option: `bgp multiple-instance` being used");
825 ret = bgp_option_unset(BGP_OPT_MULTIPLE_INSTANCE);
826 if (ret < 0) {
827 vty_out(vty, "%% There are more than two BGP instances\n");
828 return CMD_WARNING_CONFIG_FAILED;
829 }
830 return CMD_SUCCESS;
831 }
832
833 DEFUN_HIDDEN (bgp_local_mac,
834 bgp_local_mac_cmd,
835 "bgp local-mac vni " CMD_VNI_RANGE " mac WORD seq (0-4294967295)",
836 BGP_STR
837 "Local MAC config\n"
838 "VxLAN Network Identifier\n"
839 "VNI number\n"
840 "local mac\n"
841 "mac address\n"
842 "mac-mobility sequence\n"
843 "seq number\n")
844 {
845 int rv;
846 vni_t vni;
847 struct ethaddr mac;
848 struct ipaddr ip;
849 uint32_t seq;
850 struct bgp *bgp;
851
852 vni = strtoul(argv[3]->arg, NULL, 10);
853 if (!prefix_str2mac(argv[5]->arg, &mac)) {
854 vty_out(vty, "%% Malformed MAC address\n");
855 return CMD_WARNING;
856 }
857 memset(&ip, 0, sizeof(ip));
858 seq = strtoul(argv[7]->arg, NULL, 10);
859
860 bgp = bgp_get_default();
861 if (!bgp) {
862 vty_out(vty, "Default BGP instance is not there\n");
863 return CMD_WARNING;
864 }
865
866 rv = bgp_evpn_local_macip_add(bgp, vni, &mac, &ip, 0 /* flags */, seq);
867 if (rv < 0) {
868 vty_out(vty, "Internal error\n");
869 return CMD_WARNING;
870 }
871
872 return CMD_SUCCESS;
873 }
874
875 DEFUN_HIDDEN (no_bgp_local_mac,
876 no_bgp_local_mac_cmd,
877 "no bgp local-mac vni " CMD_VNI_RANGE " mac WORD",
878 NO_STR
879 BGP_STR
880 "Local MAC config\n"
881 "VxLAN Network Identifier\n"
882 "VNI number\n"
883 "local mac\n"
884 "mac address\n")
885 {
886 int rv;
887 vni_t vni;
888 struct ethaddr mac;
889 struct ipaddr ip;
890 struct bgp *bgp;
891
892 vni = strtoul(argv[4]->arg, NULL, 10);
893 if (!prefix_str2mac(argv[6]->arg, &mac)) {
894 vty_out(vty, "%% Malformed MAC address\n");
895 return CMD_WARNING;
896 }
897 memset(&ip, 0, sizeof(ip));
898
899 bgp = bgp_get_default();
900 if (!bgp) {
901 vty_out(vty, "Default BGP instance is not there\n");
902 return CMD_WARNING;
903 }
904
905 rv = bgp_evpn_local_macip_del(bgp, vni, &mac, &ip, ZEBRA_NEIGH_ACTIVE);
906 if (rv < 0) {
907 vty_out(vty, "Internal error\n");
908 return CMD_WARNING;
909 }
910
911 return CMD_SUCCESS;
912 }
913
914 #if (CONFDATE > 20190601)
915 CPP_NOTICE("bgpd: time to remove deprecated cli bgp config-type cisco")
916 CPP_NOTICE("This includes BGP_OPT_CISCO_CONFIG")
917 #endif
918 DEFUN_HIDDEN (bgp_config_type,
919 bgp_config_type_cmd,
920 "bgp config-type <cisco|zebra>",
921 BGP_STR
922 "Configuration type\n"
923 "cisco\n"
924 "zebra\n")
925 {
926 int idx = 0;
927 if (argv_find(argv, argc, "cisco", &idx)) {
928 vty_out(vty, "This config option is deprecated, and is scheduled for removal.\n");
929 vty_out(vty, "if you are using this please let the developers know!\n");
930 zlog_info("Deprecated option: `bgp config-type cisco` being used");
931 bgp_option_set(BGP_OPT_CONFIG_CISCO);
932 } else
933 bgp_option_unset(BGP_OPT_CONFIG_CISCO);
934
935 return CMD_SUCCESS;
936 }
937
938 DEFUN_HIDDEN (no_bgp_config_type,
939 no_bgp_config_type_cmd,
940 "no bgp config-type [<cisco|zebra>]",
941 NO_STR
942 BGP_STR
943 "Display configuration type\n"
944 "cisco\n"
945 "zebra\n")
946 {
947 bgp_option_unset(BGP_OPT_CONFIG_CISCO);
948 return CMD_SUCCESS;
949 }
950
951
952 DEFUN (no_synchronization,
953 no_synchronization_cmd,
954 "no synchronization",
955 NO_STR
956 "Perform IGP synchronization\n")
957 {
958 return CMD_SUCCESS;
959 }
960
961 DEFUN (no_auto_summary,
962 no_auto_summary_cmd,
963 "no auto-summary",
964 NO_STR
965 "Enable automatic network number summarization\n")
966 {
967 return CMD_SUCCESS;
968 }
969
970 /* "router bgp" commands. */
971 DEFUN_NOSH (router_bgp,
972 router_bgp_cmd,
973 "router bgp [(1-4294967295) [<view|vrf> VIEWVRFNAME]]",
974 ROUTER_STR
975 BGP_STR
976 AS_STR
977 BGP_INSTANCE_HELP_STR)
978 {
979 int idx_asn = 2;
980 int idx_view_vrf = 3;
981 int idx_vrf = 4;
982 int is_new_bgp = 0;
983 int ret;
984 as_t as;
985 struct bgp *bgp;
986 const char *name = NULL;
987 enum bgp_instance_type inst_type;
988
989 // "router bgp" without an ASN
990 if (argc == 2) {
991 // Pending: Make VRF option available for ASN less config
992 bgp = bgp_get_default();
993
994 if (bgp == NULL) {
995 vty_out(vty, "%% No BGP process is configured\n");
996 return CMD_WARNING_CONFIG_FAILED;
997 }
998
999 if (listcount(bm->bgp) > 1) {
1000 vty_out(vty, "%% Please specify ASN and VRF\n");
1001 return CMD_WARNING_CONFIG_FAILED;
1002 }
1003 }
1004
1005 // "router bgp X"
1006 else {
1007 as = strtoul(argv[idx_asn]->arg, NULL, 10);
1008
1009 inst_type = BGP_INSTANCE_TYPE_DEFAULT;
1010 if (argc > 3) {
1011 name = argv[idx_vrf]->arg;
1012
1013 if (!strcmp(argv[idx_view_vrf]->text, "vrf")) {
1014 if (strmatch(name, VRF_DEFAULT_NAME))
1015 name = NULL;
1016 else
1017 inst_type = BGP_INSTANCE_TYPE_VRF;
1018 } else if (!strcmp(argv[idx_view_vrf]->text, "view"))
1019 inst_type = BGP_INSTANCE_TYPE_VIEW;
1020 }
1021
1022 if (inst_type == BGP_INSTANCE_TYPE_DEFAULT)
1023 is_new_bgp = (bgp_lookup(as, name) == NULL);
1024
1025 ret = bgp_get(&bgp, &as, name, inst_type);
1026 switch (ret) {
1027 case BGP_ERR_MULTIPLE_INSTANCE_NOT_SET:
1028 vty_out(vty,
1029 "Please specify 'bgp multiple-instance' first\n");
1030 return CMD_WARNING_CONFIG_FAILED;
1031 case BGP_ERR_AS_MISMATCH:
1032 vty_out(vty, "BGP is already running; AS is %u\n", as);
1033 return CMD_WARNING_CONFIG_FAILED;
1034 case BGP_ERR_INSTANCE_MISMATCH:
1035 vty_out(vty,
1036 "BGP instance name and AS number mismatch\n");
1037 vty_out(vty,
1038 "BGP instance is already running; AS is %u\n",
1039 as);
1040 return CMD_WARNING_CONFIG_FAILED;
1041 }
1042
1043 /*
1044 * If we just instantiated the default instance, complete
1045 * any pending VRF-VPN leaking that was configured via
1046 * earlier "router bgp X vrf FOO" blocks.
1047 */
1048 if (is_new_bgp && inst_type == BGP_INSTANCE_TYPE_DEFAULT)
1049 vpn_leak_postchange_all();
1050
1051 /* Pending: handle when user tries to change a view to vrf n vv.
1052 */
1053 }
1054
1055 /* unset the auto created flag as the user config is now present */
1056 UNSET_FLAG(bgp->vrf_flags, BGP_VRF_AUTO);
1057 VTY_PUSH_CONTEXT(BGP_NODE, bgp);
1058
1059 return CMD_SUCCESS;
1060 }
1061
1062 /* "no router bgp" commands. */
1063 DEFUN (no_router_bgp,
1064 no_router_bgp_cmd,
1065 "no router bgp [(1-4294967295) [<view|vrf> VIEWVRFNAME]]",
1066 NO_STR
1067 ROUTER_STR
1068 BGP_STR
1069 AS_STR
1070 BGP_INSTANCE_HELP_STR)
1071 {
1072 int idx_asn = 3;
1073 int idx_vrf = 5;
1074 as_t as;
1075 struct bgp *bgp;
1076 const char *name = NULL;
1077
1078 // "no router bgp" without an ASN
1079 if (argc == 3) {
1080 // Pending: Make VRF option available for ASN less config
1081 bgp = bgp_get_default();
1082
1083 if (bgp == NULL) {
1084 vty_out(vty, "%% No BGP process is configured\n");
1085 return CMD_WARNING_CONFIG_FAILED;
1086 }
1087
1088 if (listcount(bm->bgp) > 1) {
1089 vty_out(vty, "%% Please specify ASN and VRF\n");
1090 return CMD_WARNING_CONFIG_FAILED;
1091 }
1092
1093 if (bgp->l3vni) {
1094 vty_out(vty, "%% Please unconfigure l3vni %u",
1095 bgp->l3vni);
1096 return CMD_WARNING_CONFIG_FAILED;
1097 }
1098 } else {
1099 as = strtoul(argv[idx_asn]->arg, NULL, 10);
1100
1101 if (argc > 4)
1102 name = argv[idx_vrf]->arg;
1103
1104 /* Lookup bgp structure. */
1105 bgp = bgp_lookup(as, name);
1106 if (!bgp) {
1107 vty_out(vty, "%% Can't find BGP instance\n");
1108 return CMD_WARNING_CONFIG_FAILED;
1109 }
1110
1111 if (bgp->l3vni) {
1112 vty_out(vty, "%% Please unconfigure l3vni %u",
1113 bgp->l3vni);
1114 return CMD_WARNING_CONFIG_FAILED;
1115 }
1116 }
1117
1118 bgp_delete(bgp);
1119
1120 return CMD_SUCCESS;
1121 }
1122
1123
1124 /* BGP router-id. */
1125
1126 DEFPY (bgp_router_id,
1127 bgp_router_id_cmd,
1128 "bgp router-id A.B.C.D",
1129 BGP_STR
1130 "Override configured router identifier\n"
1131 "Manually configured router identifier\n")
1132 {
1133 VTY_DECLVAR_CONTEXT(bgp, bgp);
1134 bgp_router_id_static_set(bgp, router_id);
1135 return CMD_SUCCESS;
1136 }
1137
1138 DEFPY (no_bgp_router_id,
1139 no_bgp_router_id_cmd,
1140 "no bgp router-id [A.B.C.D]",
1141 NO_STR
1142 BGP_STR
1143 "Override configured router identifier\n"
1144 "Manually configured router identifier\n")
1145 {
1146 VTY_DECLVAR_CONTEXT(bgp, bgp);
1147
1148 if (router_id_str) {
1149 if (!IPV4_ADDR_SAME(&bgp->router_id_static, &router_id)) {
1150 vty_out(vty, "%% BGP router-id doesn't match\n");
1151 return CMD_WARNING_CONFIG_FAILED;
1152 }
1153 }
1154
1155 router_id.s_addr = 0;
1156 bgp_router_id_static_set(bgp, router_id);
1157
1158 return CMD_SUCCESS;
1159 }
1160
1161
1162 /* BGP Cluster ID. */
1163 DEFUN (bgp_cluster_id,
1164 bgp_cluster_id_cmd,
1165 "bgp cluster-id <A.B.C.D|(1-4294967295)>",
1166 BGP_STR
1167 "Configure Route-Reflector Cluster-id\n"
1168 "Route-Reflector Cluster-id in IP address format\n"
1169 "Route-Reflector Cluster-id as 32 bit quantity\n")
1170 {
1171 VTY_DECLVAR_CONTEXT(bgp, bgp);
1172 int idx_ipv4 = 2;
1173 int ret;
1174 struct in_addr cluster;
1175
1176 ret = inet_aton(argv[idx_ipv4]->arg, &cluster);
1177 if (!ret) {
1178 vty_out(vty, "%% Malformed bgp cluster identifier\n");
1179 return CMD_WARNING_CONFIG_FAILED;
1180 }
1181
1182 bgp_cluster_id_set(bgp, &cluster);
1183 bgp_clear_star_soft_out(vty, bgp->name);
1184
1185 return CMD_SUCCESS;
1186 }
1187
1188 DEFUN (no_bgp_cluster_id,
1189 no_bgp_cluster_id_cmd,
1190 "no bgp cluster-id [<A.B.C.D|(1-4294967295)>]",
1191 NO_STR
1192 BGP_STR
1193 "Configure Route-Reflector Cluster-id\n"
1194 "Route-Reflector Cluster-id in IP address format\n"
1195 "Route-Reflector Cluster-id as 32 bit quantity\n")
1196 {
1197 VTY_DECLVAR_CONTEXT(bgp, bgp);
1198 bgp_cluster_id_unset(bgp);
1199 bgp_clear_star_soft_out(vty, bgp->name);
1200
1201 return CMD_SUCCESS;
1202 }
1203
1204 DEFUN (bgp_confederation_identifier,
1205 bgp_confederation_identifier_cmd,
1206 "bgp confederation identifier (1-4294967295)",
1207 "BGP specific commands\n"
1208 "AS confederation parameters\n"
1209 "AS number\n"
1210 "Set routing domain confederation AS\n")
1211 {
1212 VTY_DECLVAR_CONTEXT(bgp, bgp);
1213 int idx_number = 3;
1214 as_t as;
1215
1216 as = strtoul(argv[idx_number]->arg, NULL, 10);
1217
1218 bgp_confederation_id_set(bgp, as);
1219
1220 return CMD_SUCCESS;
1221 }
1222
1223 DEFUN (no_bgp_confederation_identifier,
1224 no_bgp_confederation_identifier_cmd,
1225 "no bgp confederation identifier [(1-4294967295)]",
1226 NO_STR
1227 "BGP specific commands\n"
1228 "AS confederation parameters\n"
1229 "AS number\n"
1230 "Set routing domain confederation AS\n")
1231 {
1232 VTY_DECLVAR_CONTEXT(bgp, bgp);
1233 bgp_confederation_id_unset(bgp);
1234
1235 return CMD_SUCCESS;
1236 }
1237
1238 DEFUN (bgp_confederation_peers,
1239 bgp_confederation_peers_cmd,
1240 "bgp confederation peers (1-4294967295)...",
1241 "BGP specific commands\n"
1242 "AS confederation parameters\n"
1243 "Peer ASs in BGP confederation\n"
1244 AS_STR)
1245 {
1246 VTY_DECLVAR_CONTEXT(bgp, bgp);
1247 int idx_asn = 3;
1248 as_t as;
1249 int i;
1250
1251 for (i = idx_asn; i < argc; i++) {
1252 as = strtoul(argv[i]->arg, NULL, 10);
1253
1254 if (bgp->as == as) {
1255 vty_out(vty,
1256 "%% Local member-AS not allowed in confed peer list\n");
1257 continue;
1258 }
1259
1260 bgp_confederation_peers_add(bgp, as);
1261 }
1262 return CMD_SUCCESS;
1263 }
1264
1265 DEFUN (no_bgp_confederation_peers,
1266 no_bgp_confederation_peers_cmd,
1267 "no bgp confederation peers (1-4294967295)...",
1268 NO_STR
1269 "BGP specific commands\n"
1270 "AS confederation parameters\n"
1271 "Peer ASs in BGP confederation\n"
1272 AS_STR)
1273 {
1274 VTY_DECLVAR_CONTEXT(bgp, bgp);
1275 int idx_asn = 4;
1276 as_t as;
1277 int i;
1278
1279 for (i = idx_asn; i < argc; i++) {
1280 as = strtoul(argv[i]->arg, NULL, 10);
1281
1282 bgp_confederation_peers_remove(bgp, as);
1283 }
1284 return CMD_SUCCESS;
1285 }
1286
1287 /**
1288 * Central routine for maximum-paths configuration.
1289 * @peer_type: BGP_PEER_EBGP or BGP_PEER_IBGP
1290 * @set: 1 for setting values, 0 for removing the max-paths config.
1291 */
1292 static int bgp_maxpaths_config_vty(struct vty *vty, int peer_type,
1293 const char *mpaths, uint16_t options,
1294 int set)
1295 {
1296 VTY_DECLVAR_CONTEXT(bgp, bgp);
1297 uint16_t maxpaths = 0;
1298 int ret;
1299 afi_t afi;
1300 safi_t safi;
1301
1302 afi = bgp_node_afi(vty);
1303 safi = bgp_node_safi(vty);
1304
1305 if (set) {
1306 maxpaths = strtol(mpaths, NULL, 10);
1307 if (maxpaths > multipath_num) {
1308 vty_out(vty,
1309 "%% Maxpaths Specified: %d is > than multipath num specified on bgp command line %d",
1310 maxpaths, multipath_num);
1311 return CMD_WARNING_CONFIG_FAILED;
1312 }
1313 ret = bgp_maximum_paths_set(bgp, afi, safi, peer_type, maxpaths,
1314 options);
1315 } else
1316 ret = bgp_maximum_paths_unset(bgp, afi, safi, peer_type);
1317
1318 if (ret < 0) {
1319 vty_out(vty,
1320 "%% Failed to %sset maximum-paths %s %u for afi %u, safi %u\n",
1321 (set == 1) ? "" : "un",
1322 (peer_type == BGP_PEER_EBGP) ? "ebgp" : "ibgp",
1323 maxpaths, afi, safi);
1324 return CMD_WARNING_CONFIG_FAILED;
1325 }
1326
1327 bgp_recalculate_all_bestpaths(bgp);
1328
1329 return CMD_SUCCESS;
1330 }
1331
1332 DEFUN (bgp_maxmed_admin,
1333 bgp_maxmed_admin_cmd,
1334 "bgp max-med administrative ",
1335 BGP_STR
1336 "Advertise routes with max-med\n"
1337 "Administratively applied, for an indefinite period\n")
1338 {
1339 VTY_DECLVAR_CONTEXT(bgp, bgp);
1340
1341 bgp->v_maxmed_admin = 1;
1342 bgp->maxmed_admin_value = BGP_MAXMED_VALUE_DEFAULT;
1343
1344 bgp_maxmed_update(bgp);
1345
1346 return CMD_SUCCESS;
1347 }
1348
1349 DEFUN (bgp_maxmed_admin_medv,
1350 bgp_maxmed_admin_medv_cmd,
1351 "bgp max-med administrative (0-4294967295)",
1352 BGP_STR
1353 "Advertise routes with max-med\n"
1354 "Administratively applied, for an indefinite period\n"
1355 "Max MED value to be used\n")
1356 {
1357 VTY_DECLVAR_CONTEXT(bgp, bgp);
1358 int idx_number = 3;
1359
1360 bgp->v_maxmed_admin = 1;
1361 bgp->maxmed_admin_value = strtoul(argv[idx_number]->arg, NULL, 10);
1362
1363 bgp_maxmed_update(bgp);
1364
1365 return CMD_SUCCESS;
1366 }
1367
1368 DEFUN (no_bgp_maxmed_admin,
1369 no_bgp_maxmed_admin_cmd,
1370 "no bgp max-med administrative [(0-4294967295)]",
1371 NO_STR
1372 BGP_STR
1373 "Advertise routes with max-med\n"
1374 "Administratively applied, for an indefinite period\n"
1375 "Max MED value to be used\n")
1376 {
1377 VTY_DECLVAR_CONTEXT(bgp, bgp);
1378 bgp->v_maxmed_admin = BGP_MAXMED_ADMIN_UNCONFIGURED;
1379 bgp->maxmed_admin_value = BGP_MAXMED_VALUE_DEFAULT;
1380 bgp_maxmed_update(bgp);
1381
1382 return CMD_SUCCESS;
1383 }
1384
1385 DEFUN (bgp_maxmed_onstartup,
1386 bgp_maxmed_onstartup_cmd,
1387 "bgp max-med on-startup (5-86400) [(0-4294967295)]",
1388 BGP_STR
1389 "Advertise routes with max-med\n"
1390 "Effective on a startup\n"
1391 "Time (seconds) period for max-med\n"
1392 "Max MED value to be used\n")
1393 {
1394 VTY_DECLVAR_CONTEXT(bgp, bgp);
1395 int idx = 0;
1396
1397 argv_find(argv, argc, "(5-86400)", &idx);
1398 bgp->v_maxmed_onstartup = strtoul(argv[idx]->arg, NULL, 10);
1399 if (argv_find(argv, argc, "(0-4294967295)", &idx))
1400 bgp->maxmed_onstartup_value = strtoul(argv[idx]->arg, NULL, 10);
1401 else
1402 bgp->maxmed_onstartup_value = BGP_MAXMED_VALUE_DEFAULT;
1403
1404 bgp_maxmed_update(bgp);
1405
1406 return CMD_SUCCESS;
1407 }
1408
1409 DEFUN (no_bgp_maxmed_onstartup,
1410 no_bgp_maxmed_onstartup_cmd,
1411 "no bgp max-med on-startup [(5-86400) [(0-4294967295)]]",
1412 NO_STR
1413 BGP_STR
1414 "Advertise routes with max-med\n"
1415 "Effective on a startup\n"
1416 "Time (seconds) period for max-med\n"
1417 "Max MED value to be used\n")
1418 {
1419 VTY_DECLVAR_CONTEXT(bgp, bgp);
1420
1421 /* Cancel max-med onstartup if its on */
1422 if (bgp->t_maxmed_onstartup) {
1423 THREAD_TIMER_OFF(bgp->t_maxmed_onstartup);
1424 bgp->maxmed_onstartup_over = 1;
1425 }
1426
1427 bgp->v_maxmed_onstartup = BGP_MAXMED_ONSTARTUP_UNCONFIGURED;
1428 bgp->maxmed_onstartup_value = BGP_MAXMED_VALUE_DEFAULT;
1429
1430 bgp_maxmed_update(bgp);
1431
1432 return CMD_SUCCESS;
1433 }
1434
1435 static int bgp_update_delay_config_vty(struct vty *vty, const char *delay,
1436 const char *wait)
1437 {
1438 VTY_DECLVAR_CONTEXT(bgp, bgp);
1439 uint16_t update_delay;
1440 uint16_t establish_wait;
1441
1442 update_delay = strtoul(delay, NULL, 10);
1443
1444 if (!wait) /* update-delay <delay> */
1445 {
1446 bgp->v_update_delay = update_delay;
1447 bgp->v_establish_wait = bgp->v_update_delay;
1448 return CMD_SUCCESS;
1449 }
1450
1451 /* update-delay <delay> <establish-wait> */
1452 establish_wait = atoi(wait);
1453 if (update_delay < establish_wait) {
1454 vty_out(vty,
1455 "%%Failed: update-delay less than the establish-wait!\n");
1456 return CMD_WARNING_CONFIG_FAILED;
1457 }
1458
1459 bgp->v_update_delay = update_delay;
1460 bgp->v_establish_wait = establish_wait;
1461
1462 return CMD_SUCCESS;
1463 }
1464
1465 static int bgp_update_delay_deconfig_vty(struct vty *vty)
1466 {
1467 VTY_DECLVAR_CONTEXT(bgp, bgp);
1468
1469 bgp->v_update_delay = BGP_UPDATE_DELAY_DEF;
1470 bgp->v_establish_wait = bgp->v_update_delay;
1471
1472 return CMD_SUCCESS;
1473 }
1474
1475 void bgp_config_write_update_delay(struct vty *vty, struct bgp *bgp)
1476 {
1477 if (bgp->v_update_delay != BGP_UPDATE_DELAY_DEF) {
1478 vty_out(vty, " update-delay %d", bgp->v_update_delay);
1479 if (bgp->v_update_delay != bgp->v_establish_wait)
1480 vty_out(vty, " %d", bgp->v_establish_wait);
1481 vty_out(vty, "\n");
1482 }
1483 }
1484
1485
1486 /* Update-delay configuration */
1487 DEFUN (bgp_update_delay,
1488 bgp_update_delay_cmd,
1489 "update-delay (0-3600)",
1490 "Force initial delay for best-path and updates\n"
1491 "Seconds\n")
1492 {
1493 int idx_number = 1;
1494 return bgp_update_delay_config_vty(vty, argv[idx_number]->arg, NULL);
1495 }
1496
1497 DEFUN (bgp_update_delay_establish_wait,
1498 bgp_update_delay_establish_wait_cmd,
1499 "update-delay (0-3600) (1-3600)",
1500 "Force initial delay for best-path and updates\n"
1501 "Seconds\n"
1502 "Seconds\n")
1503 {
1504 int idx_number = 1;
1505 int idx_number_2 = 2;
1506 return bgp_update_delay_config_vty(vty, argv[idx_number]->arg,
1507 argv[idx_number_2]->arg);
1508 }
1509
1510 /* Update-delay deconfiguration */
1511 DEFUN (no_bgp_update_delay,
1512 no_bgp_update_delay_cmd,
1513 "no update-delay [(0-3600) [(1-3600)]]",
1514 NO_STR
1515 "Force initial delay for best-path and updates\n"
1516 "Seconds\n"
1517 "Seconds\n")
1518 {
1519 return bgp_update_delay_deconfig_vty(vty);
1520 }
1521
1522
1523 static int bgp_wpkt_quanta_config_vty(struct vty *vty, const char *num,
1524 char set)
1525 {
1526 VTY_DECLVAR_CONTEXT(bgp, bgp);
1527
1528 if (set) {
1529 uint32_t quanta = strtoul(num, NULL, 10);
1530 atomic_store_explicit(&bgp->wpkt_quanta, quanta,
1531 memory_order_relaxed);
1532 } else {
1533 atomic_store_explicit(&bgp->wpkt_quanta, BGP_WRITE_PACKET_MAX,
1534 memory_order_relaxed);
1535 }
1536
1537 return CMD_SUCCESS;
1538 }
1539
1540 static int bgp_rpkt_quanta_config_vty(struct vty *vty, const char *num,
1541 char set)
1542 {
1543 VTY_DECLVAR_CONTEXT(bgp, bgp);
1544
1545 if (set) {
1546 uint32_t quanta = strtoul(num, NULL, 10);
1547 atomic_store_explicit(&bgp->rpkt_quanta, quanta,
1548 memory_order_relaxed);
1549 } else {
1550 atomic_store_explicit(&bgp->rpkt_quanta, BGP_READ_PACKET_MAX,
1551 memory_order_relaxed);
1552 }
1553
1554 return CMD_SUCCESS;
1555 }
1556
1557 void bgp_config_write_wpkt_quanta(struct vty *vty, struct bgp *bgp)
1558 {
1559 uint32_t quanta =
1560 atomic_load_explicit(&bgp->wpkt_quanta, memory_order_relaxed);
1561 if (quanta != BGP_WRITE_PACKET_MAX)
1562 vty_out(vty, " write-quanta %d\n", quanta);
1563 }
1564
1565 void bgp_config_write_rpkt_quanta(struct vty *vty, struct bgp *bgp)
1566 {
1567 uint32_t quanta =
1568 atomic_load_explicit(&bgp->rpkt_quanta, memory_order_relaxed);
1569 if (quanta != BGP_READ_PACKET_MAX)
1570 vty_out(vty, " read-quanta %d\n", quanta);
1571 }
1572
1573 /* Packet quanta configuration */
1574 DEFUN (bgp_wpkt_quanta,
1575 bgp_wpkt_quanta_cmd,
1576 "write-quanta (1-10)",
1577 "How many packets to write to peer socket per run\n"
1578 "Number of packets\n")
1579 {
1580 int idx_number = 1;
1581 return bgp_wpkt_quanta_config_vty(vty, argv[idx_number]->arg, 1);
1582 }
1583
1584 DEFUN (no_bgp_wpkt_quanta,
1585 no_bgp_wpkt_quanta_cmd,
1586 "no write-quanta (1-10)",
1587 NO_STR
1588 "How many packets to write to peer socket per I/O cycle\n"
1589 "Number of packets\n")
1590 {
1591 int idx_number = 2;
1592 return bgp_wpkt_quanta_config_vty(vty, argv[idx_number]->arg, 0);
1593 }
1594
1595 DEFUN (bgp_rpkt_quanta,
1596 bgp_rpkt_quanta_cmd,
1597 "read-quanta (1-10)",
1598 "How many packets to read from peer socket per I/O cycle\n"
1599 "Number of packets\n")
1600 {
1601 int idx_number = 1;
1602 return bgp_rpkt_quanta_config_vty(vty, argv[idx_number]->arg, 1);
1603 }
1604
1605 DEFUN (no_bgp_rpkt_quanta,
1606 no_bgp_rpkt_quanta_cmd,
1607 "no read-quanta (1-10)",
1608 NO_STR
1609 "How many packets to read from peer socket per I/O cycle\n"
1610 "Number of packets\n")
1611 {
1612 int idx_number = 2;
1613 return bgp_rpkt_quanta_config_vty(vty, argv[idx_number]->arg, 0);
1614 }
1615
1616 void bgp_config_write_coalesce_time(struct vty *vty, struct bgp *bgp)
1617 {
1618 if (!bgp->heuristic_coalesce)
1619 vty_out(vty, " coalesce-time %u\n", bgp->coalesce_time);
1620 }
1621
1622
1623 DEFUN (bgp_coalesce_time,
1624 bgp_coalesce_time_cmd,
1625 "coalesce-time (0-4294967295)",
1626 "Subgroup coalesce timer\n"
1627 "Subgroup coalesce timer value (in ms)\n")
1628 {
1629 VTY_DECLVAR_CONTEXT(bgp, bgp);
1630
1631 int idx = 0;
1632 argv_find(argv, argc, "(0-4294967295)", &idx);
1633 bgp->heuristic_coalesce = false;
1634 bgp->coalesce_time = strtoul(argv[idx]->arg, NULL, 10);
1635 return CMD_SUCCESS;
1636 }
1637
1638 DEFUN (no_bgp_coalesce_time,
1639 no_bgp_coalesce_time_cmd,
1640 "no coalesce-time (0-4294967295)",
1641 NO_STR
1642 "Subgroup coalesce timer\n"
1643 "Subgroup coalesce timer value (in ms)\n")
1644 {
1645 VTY_DECLVAR_CONTEXT(bgp, bgp);
1646
1647 bgp->heuristic_coalesce = true;
1648 bgp->coalesce_time = BGP_DEFAULT_SUBGROUP_COALESCE_TIME;
1649 return CMD_SUCCESS;
1650 }
1651
1652 /* Maximum-paths configuration */
1653 DEFUN (bgp_maxpaths,
1654 bgp_maxpaths_cmd,
1655 "maximum-paths " CMD_RANGE_STR(1, MULTIPATH_NUM),
1656 "Forward packets over multiple paths\n"
1657 "Number of paths\n")
1658 {
1659 int idx_number = 1;
1660 return bgp_maxpaths_config_vty(vty, BGP_PEER_EBGP,
1661 argv[idx_number]->arg, 0, 1);
1662 }
1663
1664 ALIAS_HIDDEN(bgp_maxpaths, bgp_maxpaths_hidden_cmd,
1665 "maximum-paths " CMD_RANGE_STR(1, MULTIPATH_NUM),
1666 "Forward packets over multiple paths\n"
1667 "Number of paths\n")
1668
1669 DEFUN (bgp_maxpaths_ibgp,
1670 bgp_maxpaths_ibgp_cmd,
1671 "maximum-paths ibgp " CMD_RANGE_STR(1, MULTIPATH_NUM),
1672 "Forward packets over multiple paths\n"
1673 "iBGP-multipath\n"
1674 "Number of paths\n")
1675 {
1676 int idx_number = 2;
1677 return bgp_maxpaths_config_vty(vty, BGP_PEER_IBGP,
1678 argv[idx_number]->arg, 0, 1);
1679 }
1680
1681 ALIAS_HIDDEN(bgp_maxpaths_ibgp, bgp_maxpaths_ibgp_hidden_cmd,
1682 "maximum-paths ibgp " CMD_RANGE_STR(1, MULTIPATH_NUM),
1683 "Forward packets over multiple paths\n"
1684 "iBGP-multipath\n"
1685 "Number of paths\n")
1686
1687 DEFUN (bgp_maxpaths_ibgp_cluster,
1688 bgp_maxpaths_ibgp_cluster_cmd,
1689 "maximum-paths ibgp " CMD_RANGE_STR(1, MULTIPATH_NUM) " equal-cluster-length",
1690 "Forward packets over multiple paths\n"
1691 "iBGP-multipath\n"
1692 "Number of paths\n"
1693 "Match the cluster length\n")
1694 {
1695 int idx_number = 2;
1696 return bgp_maxpaths_config_vty(
1697 vty, BGP_PEER_IBGP, argv[idx_number]->arg,
1698 BGP_FLAG_IBGP_MULTIPATH_SAME_CLUSTERLEN, 1);
1699 }
1700
1701 ALIAS_HIDDEN(bgp_maxpaths_ibgp_cluster, bgp_maxpaths_ibgp_cluster_hidden_cmd,
1702 "maximum-paths ibgp " CMD_RANGE_STR(
1703 1, MULTIPATH_NUM) " equal-cluster-length",
1704 "Forward packets over multiple paths\n"
1705 "iBGP-multipath\n"
1706 "Number of paths\n"
1707 "Match the cluster length\n")
1708
1709 DEFUN (no_bgp_maxpaths,
1710 no_bgp_maxpaths_cmd,
1711 "no maximum-paths [" CMD_RANGE_STR(1, MULTIPATH_NUM) "]",
1712 NO_STR
1713 "Forward packets over multiple paths\n"
1714 "Number of paths\n")
1715 {
1716 return bgp_maxpaths_config_vty(vty, BGP_PEER_EBGP, NULL, 0, 0);
1717 }
1718
1719 ALIAS_HIDDEN(no_bgp_maxpaths, no_bgp_maxpaths_hidden_cmd,
1720 "no maximum-paths [" CMD_RANGE_STR(1, MULTIPATH_NUM) "]", NO_STR
1721 "Forward packets over multiple paths\n"
1722 "Number of paths\n")
1723
1724 DEFUN (no_bgp_maxpaths_ibgp,
1725 no_bgp_maxpaths_ibgp_cmd,
1726 "no maximum-paths ibgp [" CMD_RANGE_STR(1, MULTIPATH_NUM) " [equal-cluster-length]]",
1727 NO_STR
1728 "Forward packets over multiple paths\n"
1729 "iBGP-multipath\n"
1730 "Number of paths\n"
1731 "Match the cluster length\n")
1732 {
1733 return bgp_maxpaths_config_vty(vty, BGP_PEER_IBGP, NULL, 0, 0);
1734 }
1735
1736 ALIAS_HIDDEN(no_bgp_maxpaths_ibgp, no_bgp_maxpaths_ibgp_hidden_cmd,
1737 "no maximum-paths ibgp [" CMD_RANGE_STR(
1738 1, MULTIPATH_NUM) " [equal-cluster-length]]",
1739 NO_STR
1740 "Forward packets over multiple paths\n"
1741 "iBGP-multipath\n"
1742 "Number of paths\n"
1743 "Match the cluster length\n")
1744
1745 void bgp_config_write_maxpaths(struct vty *vty, struct bgp *bgp, afi_t afi,
1746 safi_t safi)
1747 {
1748 if (bgp->maxpaths[afi][safi].maxpaths_ebgp != MULTIPATH_NUM) {
1749 vty_out(vty, " maximum-paths %d\n",
1750 bgp->maxpaths[afi][safi].maxpaths_ebgp);
1751 }
1752
1753 if (bgp->maxpaths[afi][safi].maxpaths_ibgp != MULTIPATH_NUM) {
1754 vty_out(vty, " maximum-paths ibgp %d",
1755 bgp->maxpaths[afi][safi].maxpaths_ibgp);
1756 if (CHECK_FLAG(bgp->maxpaths[afi][safi].ibgp_flags,
1757 BGP_FLAG_IBGP_MULTIPATH_SAME_CLUSTERLEN))
1758 vty_out(vty, " equal-cluster-length");
1759 vty_out(vty, "\n");
1760 }
1761 }
1762
1763 /* BGP timers. */
1764
1765 DEFUN (bgp_timers,
1766 bgp_timers_cmd,
1767 "timers bgp (0-65535) (0-65535)",
1768 "Adjust routing timers\n"
1769 "BGP timers\n"
1770 "Keepalive interval\n"
1771 "Holdtime\n")
1772 {
1773 VTY_DECLVAR_CONTEXT(bgp, bgp);
1774 int idx_number = 2;
1775 int idx_number_2 = 3;
1776 unsigned long keepalive = 0;
1777 unsigned long holdtime = 0;
1778
1779 keepalive = strtoul(argv[idx_number]->arg, NULL, 10);
1780 holdtime = strtoul(argv[idx_number_2]->arg, NULL, 10);
1781
1782 /* Holdtime value check. */
1783 if (holdtime < 3 && holdtime != 0) {
1784 vty_out(vty,
1785 "%% hold time value must be either 0 or greater than 3\n");
1786 return CMD_WARNING_CONFIG_FAILED;
1787 }
1788
1789 bgp_timers_set(bgp, keepalive, holdtime);
1790
1791 return CMD_SUCCESS;
1792 }
1793
1794 DEFUN (no_bgp_timers,
1795 no_bgp_timers_cmd,
1796 "no timers bgp [(0-65535) (0-65535)]",
1797 NO_STR
1798 "Adjust routing timers\n"
1799 "BGP timers\n"
1800 "Keepalive interval\n"
1801 "Holdtime\n")
1802 {
1803 VTY_DECLVAR_CONTEXT(bgp, bgp);
1804 bgp_timers_unset(bgp);
1805
1806 return CMD_SUCCESS;
1807 }
1808
1809
1810 DEFUN (bgp_client_to_client_reflection,
1811 bgp_client_to_client_reflection_cmd,
1812 "bgp client-to-client reflection",
1813 "BGP specific commands\n"
1814 "Configure client to client route reflection\n"
1815 "reflection of routes allowed\n")
1816 {
1817 VTY_DECLVAR_CONTEXT(bgp, bgp);
1818 bgp_flag_unset(bgp, BGP_FLAG_NO_CLIENT_TO_CLIENT);
1819 bgp_clear_star_soft_out(vty, bgp->name);
1820
1821 return CMD_SUCCESS;
1822 }
1823
1824 DEFUN (no_bgp_client_to_client_reflection,
1825 no_bgp_client_to_client_reflection_cmd,
1826 "no bgp client-to-client reflection",
1827 NO_STR
1828 "BGP specific commands\n"
1829 "Configure client to client route reflection\n"
1830 "reflection of routes allowed\n")
1831 {
1832 VTY_DECLVAR_CONTEXT(bgp, bgp);
1833 bgp_flag_set(bgp, BGP_FLAG_NO_CLIENT_TO_CLIENT);
1834 bgp_clear_star_soft_out(vty, bgp->name);
1835
1836 return CMD_SUCCESS;
1837 }
1838
1839 /* "bgp always-compare-med" configuration. */
1840 DEFUN (bgp_always_compare_med,
1841 bgp_always_compare_med_cmd,
1842 "bgp always-compare-med",
1843 "BGP specific commands\n"
1844 "Allow comparing MED from different neighbors\n")
1845 {
1846 VTY_DECLVAR_CONTEXT(bgp, bgp);
1847 bgp_flag_set(bgp, BGP_FLAG_ALWAYS_COMPARE_MED);
1848 bgp_recalculate_all_bestpaths(bgp);
1849
1850 return CMD_SUCCESS;
1851 }
1852
1853 DEFUN (no_bgp_always_compare_med,
1854 no_bgp_always_compare_med_cmd,
1855 "no bgp always-compare-med",
1856 NO_STR
1857 "BGP specific commands\n"
1858 "Allow comparing MED from different neighbors\n")
1859 {
1860 VTY_DECLVAR_CONTEXT(bgp, bgp);
1861 bgp_flag_unset(bgp, BGP_FLAG_ALWAYS_COMPARE_MED);
1862 bgp_recalculate_all_bestpaths(bgp);
1863
1864 return CMD_SUCCESS;
1865 }
1866
1867
1868 DEFUN(bgp_ebgp_requires_policy, bgp_ebgp_requires_policy_cmd,
1869 "bgp ebgp-requires-policy",
1870 "BGP specific commands\n"
1871 "Require in and out policy for eBGP peers (RFC8212)\n")
1872 {
1873 VTY_DECLVAR_CONTEXT(bgp, bgp);
1874 bgp->ebgp_requires_policy = DEFAULT_EBGP_POLICY_ENABLED;
1875 return CMD_SUCCESS;
1876 }
1877
1878 DEFUN(no_bgp_ebgp_requires_policy, no_bgp_ebgp_requires_policy_cmd,
1879 "no bgp ebgp-requires-policy",
1880 NO_STR
1881 "BGP specific commands\n"
1882 "Require in and out policy for eBGP peers (RFC8212)\n")
1883 {
1884 VTY_DECLVAR_CONTEXT(bgp, bgp);
1885 bgp->ebgp_requires_policy = DEFAULT_EBGP_POLICY_DISABLED;
1886 return CMD_SUCCESS;
1887 }
1888
1889
1890 /* "bgp deterministic-med" configuration. */
1891 DEFUN (bgp_deterministic_med,
1892 bgp_deterministic_med_cmd,
1893 "bgp deterministic-med",
1894 "BGP specific commands\n"
1895 "Pick the best-MED path among paths advertised from the neighboring AS\n")
1896 {
1897 VTY_DECLVAR_CONTEXT(bgp, bgp);
1898
1899 if (!bgp_flag_check(bgp, BGP_FLAG_DETERMINISTIC_MED)) {
1900 bgp_flag_set(bgp, BGP_FLAG_DETERMINISTIC_MED);
1901 bgp_recalculate_all_bestpaths(bgp);
1902 }
1903
1904 return CMD_SUCCESS;
1905 }
1906
1907 DEFUN (no_bgp_deterministic_med,
1908 no_bgp_deterministic_med_cmd,
1909 "no bgp deterministic-med",
1910 NO_STR
1911 "BGP specific commands\n"
1912 "Pick the best-MED path among paths advertised from the neighboring AS\n")
1913 {
1914 VTY_DECLVAR_CONTEXT(bgp, bgp);
1915 int bestpath_per_as_used;
1916 afi_t afi;
1917 safi_t safi;
1918 struct peer *peer;
1919 struct listnode *node, *nnode;
1920
1921 if (bgp_flag_check(bgp, BGP_FLAG_DETERMINISTIC_MED)) {
1922 bestpath_per_as_used = 0;
1923
1924 for (ALL_LIST_ELEMENTS(bgp->peer, node, nnode, peer)) {
1925 FOREACH_AFI_SAFI (afi, safi)
1926 if (bgp_addpath_dmed_required(
1927 peer->addpath_type[afi][safi])) {
1928 bestpath_per_as_used = 1;
1929 break;
1930 }
1931
1932 if (bestpath_per_as_used)
1933 break;
1934 }
1935
1936 if (bestpath_per_as_used) {
1937 vty_out(vty,
1938 "bgp deterministic-med cannot be disabled while addpath-tx-bestpath-per-AS is in use\n");
1939 return CMD_WARNING_CONFIG_FAILED;
1940 } else {
1941 bgp_flag_unset(bgp, BGP_FLAG_DETERMINISTIC_MED);
1942 bgp_recalculate_all_bestpaths(bgp);
1943 }
1944 }
1945
1946 return CMD_SUCCESS;
1947 }
1948
1949 /* "bgp graceful-restart" configuration. */
1950 DEFUN (bgp_graceful_restart,
1951 bgp_graceful_restart_cmd,
1952 "bgp graceful-restart",
1953 "BGP specific commands\n"
1954 "Graceful restart capability parameters\n")
1955 {
1956 VTY_DECLVAR_CONTEXT(bgp, bgp);
1957 bgp_flag_set(bgp, BGP_FLAG_GRACEFUL_RESTART);
1958 return CMD_SUCCESS;
1959 }
1960
1961 DEFUN (no_bgp_graceful_restart,
1962 no_bgp_graceful_restart_cmd,
1963 "no bgp graceful-restart",
1964 NO_STR
1965 "BGP specific commands\n"
1966 "Graceful restart capability parameters\n")
1967 {
1968 VTY_DECLVAR_CONTEXT(bgp, bgp);
1969 bgp_flag_unset(bgp, BGP_FLAG_GRACEFUL_RESTART);
1970 return CMD_SUCCESS;
1971 }
1972
1973 DEFUN (bgp_graceful_restart_stalepath_time,
1974 bgp_graceful_restart_stalepath_time_cmd,
1975 "bgp graceful-restart stalepath-time (1-4095)",
1976 "BGP specific commands\n"
1977 "Graceful restart capability parameters\n"
1978 "Set the max time to hold onto restarting peer's stale paths\n"
1979 "Delay value (seconds)\n")
1980 {
1981 VTY_DECLVAR_CONTEXT(bgp, bgp);
1982 int idx_number = 3;
1983 uint32_t stalepath;
1984
1985 stalepath = strtoul(argv[idx_number]->arg, NULL, 10);
1986 bgp->stalepath_time = stalepath;
1987 return CMD_SUCCESS;
1988 }
1989
1990 DEFUN (bgp_graceful_restart_restart_time,
1991 bgp_graceful_restart_restart_time_cmd,
1992 "bgp graceful-restart restart-time (1-4095)",
1993 "BGP specific commands\n"
1994 "Graceful restart capability parameters\n"
1995 "Set the time to wait to delete stale routes before a BGP open message is received\n"
1996 "Delay value (seconds)\n")
1997 {
1998 VTY_DECLVAR_CONTEXT(bgp, bgp);
1999 int idx_number = 3;
2000 uint32_t restart;
2001
2002 restart = strtoul(argv[idx_number]->arg, NULL, 10);
2003 bgp->restart_time = restart;
2004 return CMD_SUCCESS;
2005 }
2006
2007 DEFUN (no_bgp_graceful_restart_stalepath_time,
2008 no_bgp_graceful_restart_stalepath_time_cmd,
2009 "no bgp graceful-restart stalepath-time [(1-4095)]",
2010 NO_STR
2011 "BGP specific commands\n"
2012 "Graceful restart capability parameters\n"
2013 "Set the max time to hold onto restarting peer's stale paths\n"
2014 "Delay value (seconds)\n")
2015 {
2016 VTY_DECLVAR_CONTEXT(bgp, bgp);
2017
2018 bgp->stalepath_time = BGP_DEFAULT_STALEPATH_TIME;
2019 return CMD_SUCCESS;
2020 }
2021
2022 DEFUN (no_bgp_graceful_restart_restart_time,
2023 no_bgp_graceful_restart_restart_time_cmd,
2024 "no bgp graceful-restart restart-time [(1-4095)]",
2025 NO_STR
2026 "BGP specific commands\n"
2027 "Graceful restart capability parameters\n"
2028 "Set the time to wait to delete stale routes before a BGP open message is received\n"
2029 "Delay value (seconds)\n")
2030 {
2031 VTY_DECLVAR_CONTEXT(bgp, bgp);
2032
2033 bgp->restart_time = BGP_DEFAULT_RESTART_TIME;
2034 return CMD_SUCCESS;
2035 }
2036
2037 DEFUN (bgp_graceful_restart_preserve_fw,
2038 bgp_graceful_restart_preserve_fw_cmd,
2039 "bgp graceful-restart preserve-fw-state",
2040 "BGP specific commands\n"
2041 "Graceful restart capability parameters\n"
2042 "Sets F-bit indication that fib is preserved while doing Graceful Restart\n")
2043 {
2044 VTY_DECLVAR_CONTEXT(bgp, bgp);
2045 bgp_flag_set(bgp, BGP_FLAG_GR_PRESERVE_FWD);
2046 return CMD_SUCCESS;
2047 }
2048
2049 DEFUN (no_bgp_graceful_restart_preserve_fw,
2050 no_bgp_graceful_restart_preserve_fw_cmd,
2051 "no bgp graceful-restart preserve-fw-state",
2052 NO_STR
2053 "BGP specific commands\n"
2054 "Graceful restart capability parameters\n"
2055 "Unsets F-bit indication that fib is preserved while doing Graceful Restart\n")
2056 {
2057 VTY_DECLVAR_CONTEXT(bgp, bgp);
2058 bgp_flag_unset(bgp, BGP_FLAG_GR_PRESERVE_FWD);
2059 return CMD_SUCCESS;
2060 }
2061
2062 /* "bgp graceful-shutdown" configuration */
2063 DEFUN (bgp_graceful_shutdown,
2064 bgp_graceful_shutdown_cmd,
2065 "bgp graceful-shutdown",
2066 BGP_STR
2067 "Graceful shutdown parameters\n")
2068 {
2069 VTY_DECLVAR_CONTEXT(bgp, bgp);
2070
2071 if (!bgp_flag_check(bgp, BGP_FLAG_GRACEFUL_SHUTDOWN)) {
2072 bgp_flag_set(bgp, BGP_FLAG_GRACEFUL_SHUTDOWN);
2073 bgp_static_redo_import_check(bgp);
2074 bgp_redistribute_redo(bgp);
2075 bgp_clear_star_soft_out(vty, bgp->name);
2076 bgp_clear_star_soft_in(vty, bgp->name);
2077 }
2078
2079 return CMD_SUCCESS;
2080 }
2081
2082 DEFUN (no_bgp_graceful_shutdown,
2083 no_bgp_graceful_shutdown_cmd,
2084 "no bgp graceful-shutdown",
2085 NO_STR
2086 BGP_STR
2087 "Graceful shutdown parameters\n")
2088 {
2089 VTY_DECLVAR_CONTEXT(bgp, bgp);
2090
2091 if (bgp_flag_check(bgp, BGP_FLAG_GRACEFUL_SHUTDOWN)) {
2092 bgp_flag_unset(bgp, BGP_FLAG_GRACEFUL_SHUTDOWN);
2093 bgp_static_redo_import_check(bgp);
2094 bgp_redistribute_redo(bgp);
2095 bgp_clear_star_soft_out(vty, bgp->name);
2096 bgp_clear_star_soft_in(vty, bgp->name);
2097 }
2098
2099 return CMD_SUCCESS;
2100 }
2101
2102 /* "bgp fast-external-failover" configuration. */
2103 DEFUN (bgp_fast_external_failover,
2104 bgp_fast_external_failover_cmd,
2105 "bgp fast-external-failover",
2106 BGP_STR
2107 "Immediately reset session if a link to a directly connected external peer goes down\n")
2108 {
2109 VTY_DECLVAR_CONTEXT(bgp, bgp);
2110 bgp_flag_unset(bgp, BGP_FLAG_NO_FAST_EXT_FAILOVER);
2111 return CMD_SUCCESS;
2112 }
2113
2114 DEFUN (no_bgp_fast_external_failover,
2115 no_bgp_fast_external_failover_cmd,
2116 "no bgp fast-external-failover",
2117 NO_STR
2118 BGP_STR
2119 "Immediately reset session if a link to a directly connected external peer goes down\n")
2120 {
2121 VTY_DECLVAR_CONTEXT(bgp, bgp);
2122 bgp_flag_set(bgp, BGP_FLAG_NO_FAST_EXT_FAILOVER);
2123 return CMD_SUCCESS;
2124 }
2125
2126 /* "bgp enforce-first-as" configuration. */
2127 #if CONFDATE > 20190517
2128 CPP_NOTICE("bgpd: remove deprecated '[no] bgp enforce-first-as' commands")
2129 #endif
2130
2131 DEFUN_HIDDEN (bgp_enforce_first_as,
2132 bgp_enforce_first_as_cmd,
2133 "[no] bgp enforce-first-as",
2134 NO_STR
2135 BGP_STR
2136 "Enforce the first AS for EBGP routes\n")
2137 {
2138 VTY_DECLVAR_CONTEXT(bgp, bgp);
2139
2140 if (strmatch(argv[0]->text, "no"))
2141 bgp_flag_unset(bgp, BGP_FLAG_ENFORCE_FIRST_AS);
2142 else
2143 bgp_flag_set(bgp, BGP_FLAG_ENFORCE_FIRST_AS);
2144
2145 return CMD_SUCCESS;
2146 }
2147
2148 /* "bgp bestpath compare-routerid" configuration. */
2149 DEFUN (bgp_bestpath_compare_router_id,
2150 bgp_bestpath_compare_router_id_cmd,
2151 "bgp bestpath compare-routerid",
2152 "BGP specific commands\n"
2153 "Change the default bestpath selection\n"
2154 "Compare router-id for identical EBGP paths\n")
2155 {
2156 VTY_DECLVAR_CONTEXT(bgp, bgp);
2157 bgp_flag_set(bgp, BGP_FLAG_COMPARE_ROUTER_ID);
2158 bgp_recalculate_all_bestpaths(bgp);
2159
2160 return CMD_SUCCESS;
2161 }
2162
2163 DEFUN (no_bgp_bestpath_compare_router_id,
2164 no_bgp_bestpath_compare_router_id_cmd,
2165 "no bgp bestpath compare-routerid",
2166 NO_STR
2167 "BGP specific commands\n"
2168 "Change the default bestpath selection\n"
2169 "Compare router-id for identical EBGP paths\n")
2170 {
2171 VTY_DECLVAR_CONTEXT(bgp, bgp);
2172 bgp_flag_unset(bgp, BGP_FLAG_COMPARE_ROUTER_ID);
2173 bgp_recalculate_all_bestpaths(bgp);
2174
2175 return CMD_SUCCESS;
2176 }
2177
2178 /* "bgp bestpath as-path ignore" configuration. */
2179 DEFUN (bgp_bestpath_aspath_ignore,
2180 bgp_bestpath_aspath_ignore_cmd,
2181 "bgp bestpath as-path ignore",
2182 "BGP specific commands\n"
2183 "Change the default bestpath selection\n"
2184 "AS-path attribute\n"
2185 "Ignore as-path length in selecting a route\n")
2186 {
2187 VTY_DECLVAR_CONTEXT(bgp, bgp);
2188 bgp_flag_set(bgp, BGP_FLAG_ASPATH_IGNORE);
2189 bgp_recalculate_all_bestpaths(bgp);
2190
2191 return CMD_SUCCESS;
2192 }
2193
2194 DEFUN (no_bgp_bestpath_aspath_ignore,
2195 no_bgp_bestpath_aspath_ignore_cmd,
2196 "no bgp bestpath as-path ignore",
2197 NO_STR
2198 "BGP specific commands\n"
2199 "Change the default bestpath selection\n"
2200 "AS-path attribute\n"
2201 "Ignore as-path length in selecting a route\n")
2202 {
2203 VTY_DECLVAR_CONTEXT(bgp, bgp);
2204 bgp_flag_unset(bgp, BGP_FLAG_ASPATH_IGNORE);
2205 bgp_recalculate_all_bestpaths(bgp);
2206
2207 return CMD_SUCCESS;
2208 }
2209
2210 /* "bgp bestpath as-path confed" configuration. */
2211 DEFUN (bgp_bestpath_aspath_confed,
2212 bgp_bestpath_aspath_confed_cmd,
2213 "bgp bestpath as-path confed",
2214 "BGP specific commands\n"
2215 "Change the default bestpath selection\n"
2216 "AS-path attribute\n"
2217 "Compare path lengths including confederation sets & sequences in selecting a route\n")
2218 {
2219 VTY_DECLVAR_CONTEXT(bgp, bgp);
2220 bgp_flag_set(bgp, BGP_FLAG_ASPATH_CONFED);
2221 bgp_recalculate_all_bestpaths(bgp);
2222
2223 return CMD_SUCCESS;
2224 }
2225
2226 DEFUN (no_bgp_bestpath_aspath_confed,
2227 no_bgp_bestpath_aspath_confed_cmd,
2228 "no bgp bestpath as-path confed",
2229 NO_STR
2230 "BGP specific commands\n"
2231 "Change the default bestpath selection\n"
2232 "AS-path attribute\n"
2233 "Compare path lengths including confederation sets & sequences in selecting a route\n")
2234 {
2235 VTY_DECLVAR_CONTEXT(bgp, bgp);
2236 bgp_flag_unset(bgp, BGP_FLAG_ASPATH_CONFED);
2237 bgp_recalculate_all_bestpaths(bgp);
2238
2239 return CMD_SUCCESS;
2240 }
2241
2242 /* "bgp bestpath as-path multipath-relax" configuration. */
2243 DEFUN (bgp_bestpath_aspath_multipath_relax,
2244 bgp_bestpath_aspath_multipath_relax_cmd,
2245 "bgp bestpath as-path multipath-relax [<as-set|no-as-set>]",
2246 "BGP specific commands\n"
2247 "Change the default bestpath selection\n"
2248 "AS-path attribute\n"
2249 "Allow load sharing across routes that have different AS paths (but same length)\n"
2250 "Generate an AS_SET\n"
2251 "Do not generate an AS_SET\n")
2252 {
2253 VTY_DECLVAR_CONTEXT(bgp, bgp);
2254 int idx = 0;
2255 bgp_flag_set(bgp, BGP_FLAG_ASPATH_MULTIPATH_RELAX);
2256
2257 /* no-as-set is now the default behavior so we can silently
2258 * ignore it */
2259 if (argv_find(argv, argc, "as-set", &idx))
2260 bgp_flag_set(bgp, BGP_FLAG_MULTIPATH_RELAX_AS_SET);
2261 else
2262 bgp_flag_unset(bgp, BGP_FLAG_MULTIPATH_RELAX_AS_SET);
2263
2264 bgp_recalculate_all_bestpaths(bgp);
2265
2266 return CMD_SUCCESS;
2267 }
2268
2269 DEFUN (no_bgp_bestpath_aspath_multipath_relax,
2270 no_bgp_bestpath_aspath_multipath_relax_cmd,
2271 "no bgp bestpath as-path multipath-relax [<as-set|no-as-set>]",
2272 NO_STR
2273 "BGP specific commands\n"
2274 "Change the default bestpath selection\n"
2275 "AS-path attribute\n"
2276 "Allow load sharing across routes that have different AS paths (but same length)\n"
2277 "Generate an AS_SET\n"
2278 "Do not generate an AS_SET\n")
2279 {
2280 VTY_DECLVAR_CONTEXT(bgp, bgp);
2281 bgp_flag_unset(bgp, BGP_FLAG_ASPATH_MULTIPATH_RELAX);
2282 bgp_flag_unset(bgp, BGP_FLAG_MULTIPATH_RELAX_AS_SET);
2283 bgp_recalculate_all_bestpaths(bgp);
2284
2285 return CMD_SUCCESS;
2286 }
2287
2288 /* "bgp log-neighbor-changes" configuration. */
2289 DEFUN (bgp_log_neighbor_changes,
2290 bgp_log_neighbor_changes_cmd,
2291 "bgp log-neighbor-changes",
2292 "BGP specific commands\n"
2293 "Log neighbor up/down and reset reason\n")
2294 {
2295 VTY_DECLVAR_CONTEXT(bgp, bgp);
2296 bgp_flag_set(bgp, BGP_FLAG_LOG_NEIGHBOR_CHANGES);
2297 return CMD_SUCCESS;
2298 }
2299
2300 DEFUN (no_bgp_log_neighbor_changes,
2301 no_bgp_log_neighbor_changes_cmd,
2302 "no bgp log-neighbor-changes",
2303 NO_STR
2304 "BGP specific commands\n"
2305 "Log neighbor up/down and reset reason\n")
2306 {
2307 VTY_DECLVAR_CONTEXT(bgp, bgp);
2308 bgp_flag_unset(bgp, BGP_FLAG_LOG_NEIGHBOR_CHANGES);
2309 return CMD_SUCCESS;
2310 }
2311
2312 /* "bgp bestpath med" configuration. */
2313 DEFUN (bgp_bestpath_med,
2314 bgp_bestpath_med_cmd,
2315 "bgp bestpath med <confed [missing-as-worst]|missing-as-worst [confed]>",
2316 "BGP specific commands\n"
2317 "Change the default bestpath selection\n"
2318 "MED attribute\n"
2319 "Compare MED among confederation paths\n"
2320 "Treat missing MED as the least preferred one\n"
2321 "Treat missing MED as the least preferred one\n"
2322 "Compare MED among confederation paths\n")
2323 {
2324 VTY_DECLVAR_CONTEXT(bgp, bgp);
2325
2326 int idx = 0;
2327 if (argv_find(argv, argc, "confed", &idx))
2328 bgp_flag_set(bgp, BGP_FLAG_MED_CONFED);
2329 idx = 0;
2330 if (argv_find(argv, argc, "missing-as-worst", &idx))
2331 bgp_flag_set(bgp, BGP_FLAG_MED_MISSING_AS_WORST);
2332
2333 bgp_recalculate_all_bestpaths(bgp);
2334
2335 return CMD_SUCCESS;
2336 }
2337
2338 DEFUN (no_bgp_bestpath_med,
2339 no_bgp_bestpath_med_cmd,
2340 "no bgp bestpath med <confed [missing-as-worst]|missing-as-worst [confed]>",
2341 NO_STR
2342 "BGP specific commands\n"
2343 "Change the default bestpath selection\n"
2344 "MED attribute\n"
2345 "Compare MED among confederation paths\n"
2346 "Treat missing MED as the least preferred one\n"
2347 "Treat missing MED as the least preferred one\n"
2348 "Compare MED among confederation paths\n")
2349 {
2350 VTY_DECLVAR_CONTEXT(bgp, bgp);
2351
2352 int idx = 0;
2353 if (argv_find(argv, argc, "confed", &idx))
2354 bgp_flag_unset(bgp, BGP_FLAG_MED_CONFED);
2355 idx = 0;
2356 if (argv_find(argv, argc, "missing-as-worst", &idx))
2357 bgp_flag_unset(bgp, BGP_FLAG_MED_MISSING_AS_WORST);
2358
2359 bgp_recalculate_all_bestpaths(bgp);
2360
2361 return CMD_SUCCESS;
2362 }
2363
2364 /* "no bgp default ipv4-unicast". */
2365 DEFUN (no_bgp_default_ipv4_unicast,
2366 no_bgp_default_ipv4_unicast_cmd,
2367 "no bgp default ipv4-unicast",
2368 NO_STR
2369 "BGP specific commands\n"
2370 "Configure BGP defaults\n"
2371 "Activate ipv4-unicast for a peer by default\n")
2372 {
2373 VTY_DECLVAR_CONTEXT(bgp, bgp);
2374 bgp_flag_set(bgp, BGP_FLAG_NO_DEFAULT_IPV4);
2375 return CMD_SUCCESS;
2376 }
2377
2378 DEFUN (bgp_default_ipv4_unicast,
2379 bgp_default_ipv4_unicast_cmd,
2380 "bgp default ipv4-unicast",
2381 "BGP specific commands\n"
2382 "Configure BGP defaults\n"
2383 "Activate ipv4-unicast for a peer by default\n")
2384 {
2385 VTY_DECLVAR_CONTEXT(bgp, bgp);
2386 bgp_flag_unset(bgp, BGP_FLAG_NO_DEFAULT_IPV4);
2387 return CMD_SUCCESS;
2388 }
2389
2390 /* Display hostname in certain command outputs */
2391 DEFUN (bgp_default_show_hostname,
2392 bgp_default_show_hostname_cmd,
2393 "bgp default show-hostname",
2394 "BGP specific commands\n"
2395 "Configure BGP defaults\n"
2396 "Show hostname in certain command outputs\n")
2397 {
2398 VTY_DECLVAR_CONTEXT(bgp, bgp);
2399 bgp_flag_set(bgp, BGP_FLAG_SHOW_HOSTNAME);
2400 return CMD_SUCCESS;
2401 }
2402
2403 DEFUN (no_bgp_default_show_hostname,
2404 no_bgp_default_show_hostname_cmd,
2405 "no bgp default show-hostname",
2406 NO_STR
2407 "BGP specific commands\n"
2408 "Configure BGP defaults\n"
2409 "Show hostname in certain command outputs\n")
2410 {
2411 VTY_DECLVAR_CONTEXT(bgp, bgp);
2412 bgp_flag_unset(bgp, BGP_FLAG_SHOW_HOSTNAME);
2413 return CMD_SUCCESS;
2414 }
2415
2416 /* "bgp network import-check" configuration. */
2417 DEFUN (bgp_network_import_check,
2418 bgp_network_import_check_cmd,
2419 "bgp network import-check",
2420 "BGP specific commands\n"
2421 "BGP network command\n"
2422 "Check BGP network route exists in IGP\n")
2423 {
2424 VTY_DECLVAR_CONTEXT(bgp, bgp);
2425 if (!bgp_flag_check(bgp, BGP_FLAG_IMPORT_CHECK)) {
2426 bgp_flag_set(bgp, BGP_FLAG_IMPORT_CHECK);
2427 bgp_static_redo_import_check(bgp);
2428 }
2429
2430 return CMD_SUCCESS;
2431 }
2432
2433 ALIAS_HIDDEN(bgp_network_import_check, bgp_network_import_check_exact_cmd,
2434 "bgp network import-check exact",
2435 "BGP specific commands\n"
2436 "BGP network command\n"
2437 "Check BGP network route exists in IGP\n"
2438 "Match route precisely\n")
2439
2440 DEFUN (no_bgp_network_import_check,
2441 no_bgp_network_import_check_cmd,
2442 "no bgp network import-check",
2443 NO_STR
2444 "BGP specific commands\n"
2445 "BGP network command\n"
2446 "Check BGP network route exists in IGP\n")
2447 {
2448 VTY_DECLVAR_CONTEXT(bgp, bgp);
2449 if (bgp_flag_check(bgp, BGP_FLAG_IMPORT_CHECK)) {
2450 bgp_flag_unset(bgp, BGP_FLAG_IMPORT_CHECK);
2451 bgp_static_redo_import_check(bgp);
2452 }
2453
2454 return CMD_SUCCESS;
2455 }
2456
2457 DEFUN (bgp_default_local_preference,
2458 bgp_default_local_preference_cmd,
2459 "bgp default local-preference (0-4294967295)",
2460 "BGP specific commands\n"
2461 "Configure BGP defaults\n"
2462 "local preference (higher=more preferred)\n"
2463 "Configure default local preference value\n")
2464 {
2465 VTY_DECLVAR_CONTEXT(bgp, bgp);
2466 int idx_number = 3;
2467 uint32_t local_pref;
2468
2469 local_pref = strtoul(argv[idx_number]->arg, NULL, 10);
2470
2471 bgp_default_local_preference_set(bgp, local_pref);
2472 bgp_clear_star_soft_in(vty, bgp->name);
2473
2474 return CMD_SUCCESS;
2475 }
2476
2477 DEFUN (no_bgp_default_local_preference,
2478 no_bgp_default_local_preference_cmd,
2479 "no bgp default local-preference [(0-4294967295)]",
2480 NO_STR
2481 "BGP specific commands\n"
2482 "Configure BGP defaults\n"
2483 "local preference (higher=more preferred)\n"
2484 "Configure default local preference value\n")
2485 {
2486 VTY_DECLVAR_CONTEXT(bgp, bgp);
2487 bgp_default_local_preference_unset(bgp);
2488 bgp_clear_star_soft_in(vty, bgp->name);
2489
2490 return CMD_SUCCESS;
2491 }
2492
2493
2494 DEFUN (bgp_default_subgroup_pkt_queue_max,
2495 bgp_default_subgroup_pkt_queue_max_cmd,
2496 "bgp default subgroup-pkt-queue-max (20-100)",
2497 "BGP specific commands\n"
2498 "Configure BGP defaults\n"
2499 "subgroup-pkt-queue-max\n"
2500 "Configure subgroup packet queue max\n")
2501 {
2502 VTY_DECLVAR_CONTEXT(bgp, bgp);
2503 int idx_number = 3;
2504 uint32_t max_size;
2505
2506 max_size = strtoul(argv[idx_number]->arg, NULL, 10);
2507
2508 bgp_default_subgroup_pkt_queue_max_set(bgp, max_size);
2509
2510 return CMD_SUCCESS;
2511 }
2512
2513 DEFUN (no_bgp_default_subgroup_pkt_queue_max,
2514 no_bgp_default_subgroup_pkt_queue_max_cmd,
2515 "no bgp default subgroup-pkt-queue-max [(20-100)]",
2516 NO_STR
2517 "BGP specific commands\n"
2518 "Configure BGP defaults\n"
2519 "subgroup-pkt-queue-max\n"
2520 "Configure subgroup packet queue max\n")
2521 {
2522 VTY_DECLVAR_CONTEXT(bgp, bgp);
2523 bgp_default_subgroup_pkt_queue_max_unset(bgp);
2524 return CMD_SUCCESS;
2525 }
2526
2527
2528 DEFUN (bgp_rr_allow_outbound_policy,
2529 bgp_rr_allow_outbound_policy_cmd,
2530 "bgp route-reflector allow-outbound-policy",
2531 "BGP specific commands\n"
2532 "Allow modifications made by out route-map\n"
2533 "on ibgp neighbors\n")
2534 {
2535 VTY_DECLVAR_CONTEXT(bgp, bgp);
2536
2537 if (!bgp_flag_check(bgp, BGP_FLAG_RR_ALLOW_OUTBOUND_POLICY)) {
2538 bgp_flag_set(bgp, BGP_FLAG_RR_ALLOW_OUTBOUND_POLICY);
2539 update_group_announce_rrclients(bgp);
2540 bgp_clear_star_soft_out(vty, bgp->name);
2541 }
2542
2543 return CMD_SUCCESS;
2544 }
2545
2546 DEFUN (no_bgp_rr_allow_outbound_policy,
2547 no_bgp_rr_allow_outbound_policy_cmd,
2548 "no bgp route-reflector allow-outbound-policy",
2549 NO_STR
2550 "BGP specific commands\n"
2551 "Allow modifications made by out route-map\n"
2552 "on ibgp neighbors\n")
2553 {
2554 VTY_DECLVAR_CONTEXT(bgp, bgp);
2555
2556 if (bgp_flag_check(bgp, BGP_FLAG_RR_ALLOW_OUTBOUND_POLICY)) {
2557 bgp_flag_unset(bgp, BGP_FLAG_RR_ALLOW_OUTBOUND_POLICY);
2558 update_group_announce_rrclients(bgp);
2559 bgp_clear_star_soft_out(vty, bgp->name);
2560 }
2561
2562 return CMD_SUCCESS;
2563 }
2564
2565 DEFUN (bgp_listen_limit,
2566 bgp_listen_limit_cmd,
2567 "bgp listen limit (1-5000)",
2568 "BGP specific commands\n"
2569 "Configure BGP defaults\n"
2570 "maximum number of BGP Dynamic Neighbors that can be created\n"
2571 "Configure Dynamic Neighbors listen limit value\n")
2572 {
2573 VTY_DECLVAR_CONTEXT(bgp, bgp);
2574 int idx_number = 3;
2575 int listen_limit;
2576
2577 listen_limit = strtoul(argv[idx_number]->arg, NULL, 10);
2578
2579 bgp_listen_limit_set(bgp, listen_limit);
2580
2581 return CMD_SUCCESS;
2582 }
2583
2584 DEFUN (no_bgp_listen_limit,
2585 no_bgp_listen_limit_cmd,
2586 "no bgp listen limit [(1-5000)]",
2587 "BGP specific commands\n"
2588 "Configure BGP defaults\n"
2589 "unset maximum number of BGP Dynamic Neighbors that can be created\n"
2590 "Configure Dynamic Neighbors listen limit value to default\n"
2591 "Configure Dynamic Neighbors listen limit value\n")
2592 {
2593 VTY_DECLVAR_CONTEXT(bgp, bgp);
2594 bgp_listen_limit_unset(bgp);
2595 return CMD_SUCCESS;
2596 }
2597
2598
2599 /*
2600 * Check if this listen range is already configured. Check for exact
2601 * match or overlap based on input.
2602 */
2603 static struct peer_group *listen_range_exists(struct bgp *bgp,
2604 struct prefix *range, int exact)
2605 {
2606 struct listnode *node, *nnode;
2607 struct listnode *node1, *nnode1;
2608 struct peer_group *group;
2609 struct prefix *lr;
2610 afi_t afi;
2611 int match;
2612
2613 afi = family2afi(range->family);
2614 for (ALL_LIST_ELEMENTS(bgp->group, node, nnode, group)) {
2615 for (ALL_LIST_ELEMENTS(group->listen_range[afi], node1, nnode1,
2616 lr)) {
2617 if (exact)
2618 match = prefix_same(range, lr);
2619 else
2620 match = (prefix_match(range, lr)
2621 || prefix_match(lr, range));
2622 if (match)
2623 return group;
2624 }
2625 }
2626
2627 return NULL;
2628 }
2629
2630 DEFUN (bgp_listen_range,
2631 bgp_listen_range_cmd,
2632 "bgp listen range <A.B.C.D/M|X:X::X:X/M> peer-group WORD",
2633 "BGP specific commands\n"
2634 "Configure BGP dynamic neighbors listen range\n"
2635 "Configure BGP dynamic neighbors listen range\n"
2636 NEIGHBOR_ADDR_STR
2637 "Member of the peer-group\n"
2638 "Peer-group name\n")
2639 {
2640 VTY_DECLVAR_CONTEXT(bgp, bgp);
2641 struct prefix range;
2642 struct peer_group *group, *existing_group;
2643 afi_t afi;
2644 int ret;
2645 int idx = 0;
2646
2647 argv_find(argv, argc, "A.B.C.D/M", &idx);
2648 argv_find(argv, argc, "X:X::X:X/M", &idx);
2649 char *prefix = argv[idx]->arg;
2650 argv_find(argv, argc, "WORD", &idx);
2651 char *peergroup = argv[idx]->arg;
2652
2653 /* Convert IP prefix string to struct prefix. */
2654 ret = str2prefix(prefix, &range);
2655 if (!ret) {
2656 vty_out(vty, "%% Malformed listen range\n");
2657 return CMD_WARNING_CONFIG_FAILED;
2658 }
2659
2660 afi = family2afi(range.family);
2661
2662 if (afi == AFI_IP6 && IN6_IS_ADDR_LINKLOCAL(&range.u.prefix6)) {
2663 vty_out(vty,
2664 "%% Malformed listen range (link-local address)\n");
2665 return CMD_WARNING_CONFIG_FAILED;
2666 }
2667
2668 apply_mask(&range);
2669
2670 /* Check if same listen range is already configured. */
2671 existing_group = listen_range_exists(bgp, &range, 1);
2672 if (existing_group) {
2673 if (strcmp(existing_group->name, peergroup) == 0)
2674 return CMD_SUCCESS;
2675 else {
2676 vty_out(vty,
2677 "%% Same listen range is attached to peer-group %s\n",
2678 existing_group->name);
2679 return CMD_WARNING_CONFIG_FAILED;
2680 }
2681 }
2682
2683 /* Check if an overlapping listen range exists. */
2684 if (listen_range_exists(bgp, &range, 0)) {
2685 vty_out(vty,
2686 "%% Listen range overlaps with existing listen range\n");
2687 return CMD_WARNING_CONFIG_FAILED;
2688 }
2689
2690 group = peer_group_lookup(bgp, peergroup);
2691 if (!group) {
2692 vty_out(vty, "%% Configure the peer-group first\n");
2693 return CMD_WARNING_CONFIG_FAILED;
2694 }
2695
2696 ret = peer_group_listen_range_add(group, &range);
2697 return bgp_vty_return(vty, ret);
2698 }
2699
2700 DEFUN (no_bgp_listen_range,
2701 no_bgp_listen_range_cmd,
2702 "no bgp listen range <A.B.C.D/M|X:X::X:X/M> peer-group WORD",
2703 NO_STR
2704 "BGP specific commands\n"
2705 "Unconfigure BGP dynamic neighbors listen range\n"
2706 "Unconfigure BGP dynamic neighbors listen range\n"
2707 NEIGHBOR_ADDR_STR
2708 "Member of the peer-group\n"
2709 "Peer-group name\n")
2710 {
2711 VTY_DECLVAR_CONTEXT(bgp, bgp);
2712 struct prefix range;
2713 struct peer_group *group;
2714 afi_t afi;
2715 int ret;
2716 int idx = 0;
2717
2718 argv_find(argv, argc, "A.B.C.D/M", &idx);
2719 argv_find(argv, argc, "X:X::X:X/M", &idx);
2720 char *prefix = argv[idx]->arg;
2721 argv_find(argv, argc, "WORD", &idx);
2722 char *peergroup = argv[idx]->arg;
2723
2724 /* Convert IP prefix string to struct prefix. */
2725 ret = str2prefix(prefix, &range);
2726 if (!ret) {
2727 vty_out(vty, "%% Malformed listen range\n");
2728 return CMD_WARNING_CONFIG_FAILED;
2729 }
2730
2731 afi = family2afi(range.family);
2732
2733 if (afi == AFI_IP6 && IN6_IS_ADDR_LINKLOCAL(&range.u.prefix6)) {
2734 vty_out(vty,
2735 "%% Malformed listen range (link-local address)\n");
2736 return CMD_WARNING_CONFIG_FAILED;
2737 }
2738
2739 apply_mask(&range);
2740
2741 group = peer_group_lookup(bgp, peergroup);
2742 if (!group) {
2743 vty_out(vty, "%% Peer-group does not exist\n");
2744 return CMD_WARNING_CONFIG_FAILED;
2745 }
2746
2747 ret = peer_group_listen_range_del(group, &range);
2748 return bgp_vty_return(vty, ret);
2749 }
2750
2751 void bgp_config_write_listen(struct vty *vty, struct bgp *bgp)
2752 {
2753 struct peer_group *group;
2754 struct listnode *node, *nnode, *rnode, *nrnode;
2755 struct prefix *range;
2756 afi_t afi;
2757 char buf[PREFIX2STR_BUFFER];
2758
2759 if (bgp->dynamic_neighbors_limit != BGP_DYNAMIC_NEIGHBORS_LIMIT_DEFAULT)
2760 vty_out(vty, " bgp listen limit %d\n",
2761 bgp->dynamic_neighbors_limit);
2762
2763 for (ALL_LIST_ELEMENTS(bgp->group, node, nnode, group)) {
2764 for (afi = AFI_IP; afi < AFI_MAX; afi++) {
2765 for (ALL_LIST_ELEMENTS(group->listen_range[afi], rnode,
2766 nrnode, range)) {
2767 prefix2str(range, buf, sizeof(buf));
2768 vty_out(vty,
2769 " bgp listen range %s peer-group %s\n",
2770 buf, group->name);
2771 }
2772 }
2773 }
2774 }
2775
2776
2777 DEFUN (bgp_disable_connected_route_check,
2778 bgp_disable_connected_route_check_cmd,
2779 "bgp disable-ebgp-connected-route-check",
2780 "BGP specific commands\n"
2781 "Disable checking if nexthop is connected on ebgp sessions\n")
2782 {
2783 VTY_DECLVAR_CONTEXT(bgp, bgp);
2784 bgp_flag_set(bgp, BGP_FLAG_DISABLE_NH_CONNECTED_CHK);
2785 bgp_clear_star_soft_in(vty, bgp->name);
2786
2787 return CMD_SUCCESS;
2788 }
2789
2790 DEFUN (no_bgp_disable_connected_route_check,
2791 no_bgp_disable_connected_route_check_cmd,
2792 "no bgp disable-ebgp-connected-route-check",
2793 NO_STR
2794 "BGP specific commands\n"
2795 "Disable checking if nexthop is connected on ebgp sessions\n")
2796 {
2797 VTY_DECLVAR_CONTEXT(bgp, bgp);
2798 bgp_flag_unset(bgp, BGP_FLAG_DISABLE_NH_CONNECTED_CHK);
2799 bgp_clear_star_soft_in(vty, bgp->name);
2800
2801 return CMD_SUCCESS;
2802 }
2803
2804
2805 static int peer_remote_as_vty(struct vty *vty, const char *peer_str,
2806 const char *as_str, afi_t afi, safi_t safi)
2807 {
2808 VTY_DECLVAR_CONTEXT(bgp, bgp);
2809 int ret;
2810 as_t as;
2811 int as_type = AS_SPECIFIED;
2812 union sockunion su;
2813
2814 if (as_str[0] == 'i') {
2815 as = 0;
2816 as_type = AS_INTERNAL;
2817 } else if (as_str[0] == 'e') {
2818 as = 0;
2819 as_type = AS_EXTERNAL;
2820 } else {
2821 /* Get AS number. */
2822 as = strtoul(as_str, NULL, 10);
2823 }
2824
2825 /* If peer is peer group or interface peer, call proper function. */
2826 ret = str2sockunion(peer_str, &su);
2827 if (ret < 0) {
2828 struct peer *peer;
2829
2830 /* Check if existing interface peer */
2831 peer = peer_lookup_by_conf_if(bgp, peer_str);
2832
2833 ret = peer_remote_as(bgp, NULL, peer_str, &as, as_type, afi,
2834 safi);
2835
2836 /* if not interface peer, check peer-group settings */
2837 if (ret < 0 && !peer) {
2838 ret = peer_group_remote_as(bgp, peer_str, &as, as_type);
2839 if (ret < 0) {
2840 vty_out(vty,
2841 "%% Create the peer-group or interface first\n");
2842 return CMD_WARNING_CONFIG_FAILED;
2843 }
2844 return CMD_SUCCESS;
2845 }
2846 } else {
2847 if (peer_address_self_check(bgp, &su)) {
2848 vty_out(vty,
2849 "%% Can not configure the local system as neighbor\n");
2850 return CMD_WARNING_CONFIG_FAILED;
2851 }
2852 ret = peer_remote_as(bgp, &su, NULL, &as, as_type, afi, safi);
2853 }
2854
2855 /* This peer belongs to peer group. */
2856 switch (ret) {
2857 case BGP_ERR_PEER_GROUP_MEMBER:
2858 vty_out(vty,
2859 "%% Peer-group member cannot override remote-as of peer-group\n");
2860 return CMD_WARNING_CONFIG_FAILED;
2861 case BGP_ERR_PEER_GROUP_PEER_TYPE_DIFFERENT:
2862 vty_out(vty,
2863 "%% Peer-group members must be all internal or all external\n");
2864 return CMD_WARNING_CONFIG_FAILED;
2865 }
2866 return bgp_vty_return(vty, ret);
2867 }
2868
2869 DEFUN (bgp_default_shutdown,
2870 bgp_default_shutdown_cmd,
2871 "[no] bgp default shutdown",
2872 NO_STR
2873 BGP_STR
2874 "Configure BGP defaults\n"
2875 "Apply administrative shutdown to newly configured peers\n")
2876 {
2877 VTY_DECLVAR_CONTEXT(bgp, bgp);
2878 bgp->autoshutdown = !strmatch(argv[0]->text, "no");
2879 return CMD_SUCCESS;
2880 }
2881
2882 DEFUN (neighbor_remote_as,
2883 neighbor_remote_as_cmd,
2884 "neighbor <A.B.C.D|X:X::X:X|WORD> remote-as <(1-4294967295)|internal|external>",
2885 NEIGHBOR_STR
2886 NEIGHBOR_ADDR_STR2
2887 "Specify a BGP neighbor\n"
2888 AS_STR
2889 "Internal BGP peer\n"
2890 "External BGP peer\n")
2891 {
2892 int idx_peer = 1;
2893 int idx_remote_as = 3;
2894 return peer_remote_as_vty(vty, argv[idx_peer]->arg,
2895 argv[idx_remote_as]->arg, AFI_IP,
2896 SAFI_UNICAST);
2897 }
2898
2899 static int peer_conf_interface_get(struct vty *vty, const char *conf_if,
2900 afi_t afi, safi_t safi, int v6only,
2901 const char *peer_group_name,
2902 const char *as_str)
2903 {
2904 VTY_DECLVAR_CONTEXT(bgp, bgp);
2905 as_t as = 0;
2906 int as_type = AS_UNSPECIFIED;
2907 struct peer *peer;
2908 struct peer_group *group;
2909 int ret = 0;
2910 union sockunion su;
2911
2912 group = peer_group_lookup(bgp, conf_if);
2913
2914 if (group) {
2915 vty_out(vty, "%% Name conflict with peer-group \n");
2916 return CMD_WARNING_CONFIG_FAILED;
2917 }
2918
2919 if (as_str) {
2920 if (as_str[0] == 'i') {
2921 as_type = AS_INTERNAL;
2922 } else if (as_str[0] == 'e') {
2923 as_type = AS_EXTERNAL;
2924 } else {
2925 /* Get AS number. */
2926 as = strtoul(as_str, NULL, 10);
2927 as_type = AS_SPECIFIED;
2928 }
2929 }
2930
2931 peer = peer_lookup_by_conf_if(bgp, conf_if);
2932 if (peer) {
2933 if (as_str)
2934 ret = peer_remote_as(bgp, NULL, conf_if, &as, as_type,
2935 afi, safi);
2936 } else {
2937 if (bgp_flag_check(bgp, BGP_FLAG_NO_DEFAULT_IPV4)
2938 && afi == AFI_IP && safi == SAFI_UNICAST)
2939 peer = peer_create(NULL, conf_if, bgp, bgp->as, as,
2940 as_type, 0, 0, NULL);
2941 else
2942 peer = peer_create(NULL, conf_if, bgp, bgp->as, as,
2943 as_type, afi, safi, NULL);
2944
2945 if (!peer) {
2946 vty_out(vty, "%% BGP failed to create peer\n");
2947 return CMD_WARNING_CONFIG_FAILED;
2948 }
2949
2950 if (v6only)
2951 peer_flag_set(peer, PEER_FLAG_IFPEER_V6ONLY);
2952
2953 /* Request zebra to initiate IPv6 RAs on this interface. We do
2954 * this
2955 * any unnumbered peer in order to not worry about run-time
2956 * transitions
2957 * (e.g., peering is initially IPv4, but the IPv4 /30 or /31
2958 * address
2959 * gets deleted later etc.)
2960 */
2961 if (peer->ifp)
2962 bgp_zebra_initiate_radv(bgp, peer);
2963 }
2964
2965 if ((v6only && !CHECK_FLAG(peer->flags, PEER_FLAG_IFPEER_V6ONLY))
2966 || (!v6only && CHECK_FLAG(peer->flags, PEER_FLAG_IFPEER_V6ONLY))) {
2967 if (v6only)
2968 peer_flag_set(peer, PEER_FLAG_IFPEER_V6ONLY);
2969 else
2970 peer_flag_unset(peer, PEER_FLAG_IFPEER_V6ONLY);
2971
2972 /* v6only flag changed. Reset bgp seesion */
2973 if (BGP_IS_VALID_STATE_FOR_NOTIF(peer->status)) {
2974 peer->last_reset = PEER_DOWN_V6ONLY_CHANGE;
2975 bgp_notify_send(peer, BGP_NOTIFY_CEASE,
2976 BGP_NOTIFY_CEASE_CONFIG_CHANGE);
2977 } else
2978 bgp_session_reset(peer);
2979 }
2980
2981 if (!CHECK_FLAG(peer->flags_invert, PEER_FLAG_CAPABILITY_ENHE)) {
2982 SET_FLAG(peer->flags, PEER_FLAG_CAPABILITY_ENHE);
2983 SET_FLAG(peer->flags_invert, PEER_FLAG_CAPABILITY_ENHE);
2984 SET_FLAG(peer->flags_override, PEER_FLAG_CAPABILITY_ENHE);
2985 }
2986
2987 if (peer_group_name) {
2988 group = peer_group_lookup(bgp, peer_group_name);
2989 if (!group) {
2990 vty_out(vty, "%% Configure the peer-group first\n");
2991 return CMD_WARNING_CONFIG_FAILED;
2992 }
2993
2994 ret = peer_group_bind(bgp, &su, peer, group, &as);
2995 }
2996
2997 return bgp_vty_return(vty, ret);
2998 }
2999
3000 DEFUN (neighbor_interface_config,
3001 neighbor_interface_config_cmd,
3002 "neighbor WORD interface [peer-group WORD]",
3003 NEIGHBOR_STR
3004 "Interface name or neighbor tag\n"
3005 "Enable BGP on interface\n"
3006 "Member of the peer-group\n"
3007 "Peer-group name\n")
3008 {
3009 int idx_word = 1;
3010 int idx_peer_group_word = 4;
3011
3012 if (argc > idx_peer_group_word)
3013 return peer_conf_interface_get(
3014 vty, argv[idx_word]->arg, AFI_IP, SAFI_UNICAST, 0,
3015 argv[idx_peer_group_word]->arg, NULL);
3016 else
3017 return peer_conf_interface_get(vty, argv[idx_word]->arg, AFI_IP,
3018 SAFI_UNICAST, 0, NULL, NULL);
3019 }
3020
3021 DEFUN (neighbor_interface_config_v6only,
3022 neighbor_interface_config_v6only_cmd,
3023 "neighbor WORD interface v6only [peer-group WORD]",
3024 NEIGHBOR_STR
3025 "Interface name or neighbor tag\n"
3026 "Enable BGP on interface\n"
3027 "Enable BGP with v6 link-local only\n"
3028 "Member of the peer-group\n"
3029 "Peer-group name\n")
3030 {
3031 int idx_word = 1;
3032 int idx_peer_group_word = 5;
3033
3034 if (argc > idx_peer_group_word)
3035 return peer_conf_interface_get(
3036 vty, argv[idx_word]->arg, AFI_IP, SAFI_UNICAST, 1,
3037 argv[idx_peer_group_word]->arg, NULL);
3038
3039 return peer_conf_interface_get(vty, argv[idx_word]->arg, AFI_IP,
3040 SAFI_UNICAST, 1, NULL, NULL);
3041 }
3042
3043
3044 DEFUN (neighbor_interface_config_remote_as,
3045 neighbor_interface_config_remote_as_cmd,
3046 "neighbor WORD interface remote-as <(1-4294967295)|internal|external>",
3047 NEIGHBOR_STR
3048 "Interface name or neighbor tag\n"
3049 "Enable BGP on interface\n"
3050 "Specify a BGP neighbor\n"
3051 AS_STR
3052 "Internal BGP peer\n"
3053 "External BGP peer\n")
3054 {
3055 int idx_word = 1;
3056 int idx_remote_as = 4;
3057 return peer_conf_interface_get(vty, argv[idx_word]->arg, AFI_IP,
3058 SAFI_UNICAST, 0, NULL,
3059 argv[idx_remote_as]->arg);
3060 }
3061
3062 DEFUN (neighbor_interface_v6only_config_remote_as,
3063 neighbor_interface_v6only_config_remote_as_cmd,
3064 "neighbor WORD interface v6only remote-as <(1-4294967295)|internal|external>",
3065 NEIGHBOR_STR
3066 "Interface name or neighbor tag\n"
3067 "Enable BGP with v6 link-local only\n"
3068 "Enable BGP on interface\n"
3069 "Specify a BGP neighbor\n"
3070 AS_STR
3071 "Internal BGP peer\n"
3072 "External BGP peer\n")
3073 {
3074 int idx_word = 1;
3075 int idx_remote_as = 5;
3076 return peer_conf_interface_get(vty, argv[idx_word]->arg, AFI_IP,
3077 SAFI_UNICAST, 1, NULL,
3078 argv[idx_remote_as]->arg);
3079 }
3080
3081 DEFUN (neighbor_peer_group,
3082 neighbor_peer_group_cmd,
3083 "neighbor WORD peer-group",
3084 NEIGHBOR_STR
3085 "Interface name or neighbor tag\n"
3086 "Configure peer-group\n")
3087 {
3088 VTY_DECLVAR_CONTEXT(bgp, bgp);
3089 int idx_word = 1;
3090 struct peer *peer;
3091 struct peer_group *group;
3092
3093 peer = peer_lookup_by_conf_if(bgp, argv[idx_word]->arg);
3094 if (peer) {
3095 vty_out(vty, "%% Name conflict with interface: \n");
3096 return CMD_WARNING_CONFIG_FAILED;
3097 }
3098
3099 group = peer_group_get(bgp, argv[idx_word]->arg);
3100 if (!group) {
3101 vty_out(vty, "%% BGP failed to find or create peer-group\n");
3102 return CMD_WARNING_CONFIG_FAILED;
3103 }
3104
3105 return CMD_SUCCESS;
3106 }
3107
3108 DEFUN (no_neighbor,
3109 no_neighbor_cmd,
3110 "no neighbor <WORD|<A.B.C.D|X:X::X:X> [remote-as <(1-4294967295)|internal|external>]>",
3111 NO_STR
3112 NEIGHBOR_STR
3113 NEIGHBOR_ADDR_STR2
3114 "Specify a BGP neighbor\n"
3115 AS_STR
3116 "Internal BGP peer\n"
3117 "External BGP peer\n")
3118 {
3119 VTY_DECLVAR_CONTEXT(bgp, bgp);
3120 int idx_peer = 2;
3121 int ret;
3122 union sockunion su;
3123 struct peer_group *group;
3124 struct peer *peer;
3125 struct peer *other;
3126
3127 ret = str2sockunion(argv[idx_peer]->arg, &su);
3128 if (ret < 0) {
3129 /* look up for neighbor by interface name config. */
3130 peer = peer_lookup_by_conf_if(bgp, argv[idx_peer]->arg);
3131 if (peer) {
3132 /* Request zebra to terminate IPv6 RAs on this
3133 * interface. */
3134 if (peer->ifp)
3135 bgp_zebra_terminate_radv(peer->bgp, peer);
3136 peer_delete(peer);
3137 return CMD_SUCCESS;
3138 }
3139
3140 group = peer_group_lookup(bgp, argv[idx_peer]->arg);
3141 if (group)
3142 peer_group_delete(group);
3143 else {
3144 vty_out(vty, "%% Create the peer-group first\n");
3145 return CMD_WARNING_CONFIG_FAILED;
3146 }
3147 } else {
3148 peer = peer_lookup(bgp, &su);
3149 if (peer) {
3150 if (peer_dynamic_neighbor(peer)) {
3151 vty_out(vty,
3152 "%% Operation not allowed on a dynamic neighbor\n");
3153 return CMD_WARNING_CONFIG_FAILED;
3154 }
3155
3156 other = peer->doppelganger;
3157 peer_delete(peer);
3158 if (other && other->status != Deleted)
3159 peer_delete(other);
3160 }
3161 }
3162
3163 return CMD_SUCCESS;
3164 }
3165
3166 DEFUN (no_neighbor_interface_config,
3167 no_neighbor_interface_config_cmd,
3168 "no neighbor WORD interface [v6only] [peer-group WORD] [remote-as <(1-4294967295)|internal|external>]",
3169 NO_STR
3170 NEIGHBOR_STR
3171 "Interface name\n"
3172 "Configure BGP on interface\n"
3173 "Enable BGP with v6 link-local only\n"
3174 "Member of the peer-group\n"
3175 "Peer-group name\n"
3176 "Specify a BGP neighbor\n"
3177 AS_STR
3178 "Internal BGP peer\n"
3179 "External BGP peer\n")
3180 {
3181 VTY_DECLVAR_CONTEXT(bgp, bgp);
3182 int idx_word = 2;
3183 struct peer *peer;
3184
3185 /* look up for neighbor by interface name config. */
3186 peer = peer_lookup_by_conf_if(bgp, argv[idx_word]->arg);
3187 if (peer) {
3188 /* Request zebra to terminate IPv6 RAs on this interface. */
3189 if (peer->ifp)
3190 bgp_zebra_terminate_radv(peer->bgp, peer);
3191 peer_delete(peer);
3192 } else {
3193 vty_out(vty, "%% Create the bgp interface first\n");
3194 return CMD_WARNING_CONFIG_FAILED;
3195 }
3196 return CMD_SUCCESS;
3197 }
3198
3199 DEFUN (no_neighbor_peer_group,
3200 no_neighbor_peer_group_cmd,
3201 "no neighbor WORD peer-group",
3202 NO_STR
3203 NEIGHBOR_STR
3204 "Neighbor tag\n"
3205 "Configure peer-group\n")
3206 {
3207 VTY_DECLVAR_CONTEXT(bgp, bgp);
3208 int idx_word = 2;
3209 struct peer_group *group;
3210
3211 group = peer_group_lookup(bgp, argv[idx_word]->arg);
3212 if (group)
3213 peer_group_delete(group);
3214 else {
3215 vty_out(vty, "%% Create the peer-group first\n");
3216 return CMD_WARNING_CONFIG_FAILED;
3217 }
3218 return CMD_SUCCESS;
3219 }
3220
3221 DEFUN (no_neighbor_interface_peer_group_remote_as,
3222 no_neighbor_interface_peer_group_remote_as_cmd,
3223 "no neighbor WORD remote-as <(1-4294967295)|internal|external>",
3224 NO_STR
3225 NEIGHBOR_STR
3226 "Interface name or neighbor tag\n"
3227 "Specify a BGP neighbor\n"
3228 AS_STR
3229 "Internal BGP peer\n"
3230 "External BGP peer\n")
3231 {
3232 VTY_DECLVAR_CONTEXT(bgp, bgp);
3233 int idx_word = 2;
3234 struct peer_group *group;
3235 struct peer *peer;
3236
3237 /* look up for neighbor by interface name config. */
3238 peer = peer_lookup_by_conf_if(bgp, argv[idx_word]->arg);
3239 if (peer) {
3240 peer_as_change(peer, 0, AS_UNSPECIFIED);
3241 return CMD_SUCCESS;
3242 }
3243
3244 group = peer_group_lookup(bgp, argv[idx_word]->arg);
3245 if (group)
3246 peer_group_remote_as_delete(group);
3247 else {
3248 vty_out(vty, "%% Create the peer-group or interface first\n");
3249 return CMD_WARNING_CONFIG_FAILED;
3250 }
3251 return CMD_SUCCESS;
3252 }
3253
3254 DEFUN (neighbor_local_as,
3255 neighbor_local_as_cmd,
3256 "neighbor <A.B.C.D|X:X::X:X|WORD> local-as (1-4294967295)",
3257 NEIGHBOR_STR
3258 NEIGHBOR_ADDR_STR2
3259 "Specify a local-as number\n"
3260 "AS number used as local AS\n")
3261 {
3262 int idx_peer = 1;
3263 int idx_number = 3;
3264 struct peer *peer;
3265 int ret;
3266 as_t as;
3267
3268 peer = peer_and_group_lookup_vty(vty, argv[idx_peer]->arg);
3269 if (!peer)
3270 return CMD_WARNING_CONFIG_FAILED;
3271
3272 as = strtoul(argv[idx_number]->arg, NULL, 10);
3273 ret = peer_local_as_set(peer, as, 0, 0);
3274 return bgp_vty_return(vty, ret);
3275 }
3276
3277 DEFUN (neighbor_local_as_no_prepend,
3278 neighbor_local_as_no_prepend_cmd,
3279 "neighbor <A.B.C.D|X:X::X:X|WORD> local-as (1-4294967295) no-prepend",
3280 NEIGHBOR_STR
3281 NEIGHBOR_ADDR_STR2
3282 "Specify a local-as number\n"
3283 "AS number used as local AS\n"
3284 "Do not prepend local-as to updates from ebgp peers\n")
3285 {
3286 int idx_peer = 1;
3287 int idx_number = 3;
3288 struct peer *peer;
3289 int ret;
3290 as_t as;
3291
3292 peer = peer_and_group_lookup_vty(vty, argv[idx_peer]->arg);
3293 if (!peer)
3294 return CMD_WARNING_CONFIG_FAILED;
3295
3296 as = strtoul(argv[idx_number]->arg, NULL, 10);
3297 ret = peer_local_as_set(peer, as, 1, 0);
3298 return bgp_vty_return(vty, ret);
3299 }
3300
3301 DEFUN (neighbor_local_as_no_prepend_replace_as,
3302 neighbor_local_as_no_prepend_replace_as_cmd,
3303 "neighbor <A.B.C.D|X:X::X:X|WORD> local-as (1-4294967295) no-prepend replace-as",
3304 NEIGHBOR_STR
3305 NEIGHBOR_ADDR_STR2
3306 "Specify a local-as number\n"
3307 "AS number used as local AS\n"
3308 "Do not prepend local-as to updates from ebgp peers\n"
3309 "Do not prepend local-as to updates from ibgp peers\n")
3310 {
3311 int idx_peer = 1;
3312 int idx_number = 3;
3313 struct peer *peer;
3314 int ret;
3315 as_t as;
3316
3317 peer = peer_and_group_lookup_vty(vty, argv[idx_peer]->arg);
3318 if (!peer)
3319 return CMD_WARNING_CONFIG_FAILED;
3320
3321 as = strtoul(argv[idx_number]->arg, NULL, 10);
3322 ret = peer_local_as_set(peer, as, 1, 1);
3323 return bgp_vty_return(vty, ret);
3324 }
3325
3326 DEFUN (no_neighbor_local_as,
3327 no_neighbor_local_as_cmd,
3328 "no neighbor <A.B.C.D|X:X::X:X|WORD> local-as [(1-4294967295) [no-prepend [replace-as]]]",
3329 NO_STR
3330 NEIGHBOR_STR
3331 NEIGHBOR_ADDR_STR2
3332 "Specify a local-as number\n"
3333 "AS number used as local AS\n"
3334 "Do not prepend local-as to updates from ebgp peers\n"
3335 "Do not prepend local-as to updates from ibgp peers\n")
3336 {
3337 int idx_peer = 2;
3338 struct peer *peer;
3339 int ret;
3340
3341 peer = peer_and_group_lookup_vty(vty, argv[idx_peer]->arg);
3342 if (!peer)
3343 return CMD_WARNING_CONFIG_FAILED;
3344
3345 ret = peer_local_as_unset(peer);
3346 return bgp_vty_return(vty, ret);
3347 }
3348
3349
3350 DEFUN (neighbor_solo,
3351 neighbor_solo_cmd,
3352 "neighbor <A.B.C.D|X:X::X:X|WORD> solo",
3353 NEIGHBOR_STR
3354 NEIGHBOR_ADDR_STR2
3355 "Solo peer - part of its own update group\n")
3356 {
3357 int idx_peer = 1;
3358 struct peer *peer;
3359 int ret;
3360
3361 peer = peer_and_group_lookup_vty(vty, argv[idx_peer]->arg);
3362 if (!peer)
3363 return CMD_WARNING_CONFIG_FAILED;
3364
3365 ret = update_group_adjust_soloness(peer, 1);
3366 return bgp_vty_return(vty, ret);
3367 }
3368
3369 DEFUN (no_neighbor_solo,
3370 no_neighbor_solo_cmd,
3371 "no neighbor <A.B.C.D|X:X::X:X|WORD> solo",
3372 NO_STR
3373 NEIGHBOR_STR
3374 NEIGHBOR_ADDR_STR2
3375 "Solo peer - part of its own update group\n")
3376 {
3377 int idx_peer = 2;
3378 struct peer *peer;
3379 int ret;
3380
3381 peer = peer_and_group_lookup_vty(vty, argv[idx_peer]->arg);
3382 if (!peer)
3383 return CMD_WARNING_CONFIG_FAILED;
3384
3385 ret = update_group_adjust_soloness(peer, 0);
3386 return bgp_vty_return(vty, ret);
3387 }
3388
3389 DEFUN (neighbor_password,
3390 neighbor_password_cmd,
3391 "neighbor <A.B.C.D|X:X::X:X|WORD> password LINE",
3392 NEIGHBOR_STR
3393 NEIGHBOR_ADDR_STR2
3394 "Set a password\n"
3395 "The password\n")
3396 {
3397 int idx_peer = 1;
3398 int idx_line = 3;
3399 struct peer *peer;
3400 int ret;
3401
3402 peer = peer_and_group_lookup_vty(vty, argv[idx_peer]->arg);
3403 if (!peer)
3404 return CMD_WARNING_CONFIG_FAILED;
3405
3406 ret = peer_password_set(peer, argv[idx_line]->arg);
3407 return bgp_vty_return(vty, ret);
3408 }
3409
3410 DEFUN (no_neighbor_password,
3411 no_neighbor_password_cmd,
3412 "no neighbor <A.B.C.D|X:X::X:X|WORD> password [LINE]",
3413 NO_STR
3414 NEIGHBOR_STR
3415 NEIGHBOR_ADDR_STR2
3416 "Set a password\n"
3417 "The password\n")
3418 {
3419 int idx_peer = 2;
3420 struct peer *peer;
3421 int ret;
3422
3423 peer = peer_and_group_lookup_vty(vty, argv[idx_peer]->arg);
3424 if (!peer)
3425 return CMD_WARNING_CONFIG_FAILED;
3426
3427 ret = peer_password_unset(peer);
3428 return bgp_vty_return(vty, ret);
3429 }
3430
3431 DEFUN (neighbor_activate,
3432 neighbor_activate_cmd,
3433 "neighbor <A.B.C.D|X:X::X:X|WORD> activate",
3434 NEIGHBOR_STR
3435 NEIGHBOR_ADDR_STR2
3436 "Enable the Address Family for this Neighbor\n")
3437 {
3438 int idx_peer = 1;
3439 int ret;
3440 struct peer *peer;
3441
3442 peer = peer_and_group_lookup_vty(vty, argv[idx_peer]->arg);
3443 if (!peer)
3444 return CMD_WARNING_CONFIG_FAILED;
3445
3446 ret = peer_activate(peer, bgp_node_afi(vty), bgp_node_safi(vty));
3447 return bgp_vty_return(vty, ret);
3448 }
3449
3450 ALIAS_HIDDEN(neighbor_activate, neighbor_activate_hidden_cmd,
3451 "neighbor <A.B.C.D|X:X::X:X|WORD> activate",
3452 NEIGHBOR_STR NEIGHBOR_ADDR_STR2
3453 "Enable the Address Family for this Neighbor\n")
3454
3455 DEFUN (no_neighbor_activate,
3456 no_neighbor_activate_cmd,
3457 "no neighbor <A.B.C.D|X:X::X:X|WORD> activate",
3458 NO_STR
3459 NEIGHBOR_STR
3460 NEIGHBOR_ADDR_STR2
3461 "Enable the Address Family for this Neighbor\n")
3462 {
3463 int idx_peer = 2;
3464 int ret;
3465 struct peer *peer;
3466
3467 /* Lookup peer. */
3468 peer = peer_and_group_lookup_vty(vty, argv[idx_peer]->arg);
3469 if (!peer)
3470 return CMD_WARNING_CONFIG_FAILED;
3471
3472 ret = peer_deactivate(peer, bgp_node_afi(vty), bgp_node_safi(vty));
3473 return bgp_vty_return(vty, ret);
3474 }
3475
3476 ALIAS_HIDDEN(no_neighbor_activate, no_neighbor_activate_hidden_cmd,
3477 "no neighbor <A.B.C.D|X:X::X:X|WORD> activate",
3478 NO_STR NEIGHBOR_STR NEIGHBOR_ADDR_STR2
3479 "Enable the Address Family for this Neighbor\n")
3480
3481 DEFUN (neighbor_set_peer_group,
3482 neighbor_set_peer_group_cmd,
3483 "neighbor <A.B.C.D|X:X::X:X|WORD> peer-group WORD",
3484 NEIGHBOR_STR
3485 NEIGHBOR_ADDR_STR2
3486 "Member of the peer-group\n"
3487 "Peer-group name\n")
3488 {
3489 VTY_DECLVAR_CONTEXT(bgp, bgp);
3490 int idx_peer = 1;
3491 int idx_word = 3;
3492 int ret;
3493 as_t as;
3494 union sockunion su;
3495 struct peer *peer;
3496 struct peer_group *group;
3497
3498 ret = str2sockunion(argv[idx_peer]->arg, &su);
3499 if (ret < 0) {
3500 peer = peer_lookup_by_conf_if(bgp, argv[idx_peer]->arg);
3501 if (!peer) {
3502 vty_out(vty, "%% Malformed address or name: %s\n",
3503 argv[idx_peer]->arg);
3504 return CMD_WARNING_CONFIG_FAILED;
3505 }
3506 } else {
3507 if (peer_address_self_check(bgp, &su)) {
3508 vty_out(vty,
3509 "%% Can not configure the local system as neighbor\n");
3510 return CMD_WARNING_CONFIG_FAILED;
3511 }
3512
3513 /* Disallow for dynamic neighbor. */
3514 peer = peer_lookup(bgp, &su);
3515 if (peer && peer_dynamic_neighbor(peer)) {
3516 vty_out(vty,
3517 "%% Operation not allowed on a dynamic neighbor\n");
3518 return CMD_WARNING_CONFIG_FAILED;
3519 }
3520 }
3521
3522 group = peer_group_lookup(bgp, argv[idx_word]->arg);
3523 if (!group) {
3524 vty_out(vty, "%% Configure the peer-group first\n");
3525 return CMD_WARNING_CONFIG_FAILED;
3526 }
3527
3528 ret = peer_group_bind(bgp, &su, peer, group, &as);
3529
3530 if (ret == BGP_ERR_PEER_GROUP_PEER_TYPE_DIFFERENT) {
3531 vty_out(vty,
3532 "%% Peer with AS %u cannot be in this peer-group, members must be all internal or all external\n",
3533 as);
3534 return CMD_WARNING_CONFIG_FAILED;
3535 }
3536
3537 return bgp_vty_return(vty, ret);
3538 }
3539
3540 ALIAS_HIDDEN(neighbor_set_peer_group, neighbor_set_peer_group_hidden_cmd,
3541 "neighbor <A.B.C.D|X:X::X:X|WORD> peer-group WORD",
3542 NEIGHBOR_STR NEIGHBOR_ADDR_STR2
3543 "Member of the peer-group\n"
3544 "Peer-group name\n")
3545
3546 DEFUN (no_neighbor_set_peer_group,
3547 no_neighbor_set_peer_group_cmd,
3548 "no neighbor <A.B.C.D|X:X::X:X|WORD> peer-group WORD",
3549 NO_STR
3550 NEIGHBOR_STR
3551 NEIGHBOR_ADDR_STR2
3552 "Member of the peer-group\n"
3553 "Peer-group name\n")
3554 {
3555 VTY_DECLVAR_CONTEXT(bgp, bgp);
3556 int idx_peer = 2;
3557 int idx_word = 4;
3558 int ret;
3559 struct peer *peer;
3560 struct peer_group *group;
3561
3562 peer = peer_lookup_vty(vty, argv[idx_peer]->arg);
3563 if (!peer)
3564 return CMD_WARNING_CONFIG_FAILED;
3565
3566 group = peer_group_lookup(bgp, argv[idx_word]->arg);
3567 if (!group) {
3568 vty_out(vty, "%% Configure the peer-group first\n");
3569 return CMD_WARNING_CONFIG_FAILED;
3570 }
3571
3572 ret = peer_delete(peer);
3573
3574 return bgp_vty_return(vty, ret);
3575 }
3576
3577 ALIAS_HIDDEN(no_neighbor_set_peer_group, no_neighbor_set_peer_group_hidden_cmd,
3578 "no neighbor <A.B.C.D|X:X::X:X|WORD> peer-group WORD",
3579 NO_STR NEIGHBOR_STR NEIGHBOR_ADDR_STR2
3580 "Member of the peer-group\n"
3581 "Peer-group name\n")
3582
3583 static int peer_flag_modify_vty(struct vty *vty, const char *ip_str,
3584 uint32_t flag, int set)
3585 {
3586 int ret;
3587 struct peer *peer;
3588
3589 peer = peer_and_group_lookup_vty(vty, ip_str);
3590 if (!peer)
3591 return CMD_WARNING_CONFIG_FAILED;
3592
3593 /*
3594 * If 'neighbor <interface>', then this is for directly connected peers,
3595 * we should not accept disable-connected-check.
3596 */
3597 if (peer->conf_if && (flag == PEER_FLAG_DISABLE_CONNECTED_CHECK)) {
3598 vty_out(vty,
3599 "%s is directly connected peer, cannot accept disable-"
3600 "connected-check\n",
3601 ip_str);
3602 return CMD_WARNING_CONFIG_FAILED;
3603 }
3604
3605 if (!set && flag == PEER_FLAG_SHUTDOWN)
3606 peer_tx_shutdown_message_unset(peer);
3607
3608 if (set)
3609 ret = peer_flag_set(peer, flag);
3610 else
3611 ret = peer_flag_unset(peer, flag);
3612
3613 return bgp_vty_return(vty, ret);
3614 }
3615
3616 static int peer_flag_set_vty(struct vty *vty, const char *ip_str, uint32_t flag)
3617 {
3618 return peer_flag_modify_vty(vty, ip_str, flag, 1);
3619 }
3620
3621 static int peer_flag_unset_vty(struct vty *vty, const char *ip_str,
3622 uint32_t flag)
3623 {
3624 return peer_flag_modify_vty(vty, ip_str, flag, 0);
3625 }
3626
3627 /* neighbor passive. */
3628 DEFUN (neighbor_passive,
3629 neighbor_passive_cmd,
3630 "neighbor <A.B.C.D|X:X::X:X|WORD> passive",
3631 NEIGHBOR_STR
3632 NEIGHBOR_ADDR_STR2
3633 "Don't send open messages to this neighbor\n")
3634 {
3635 int idx_peer = 1;
3636 return peer_flag_set_vty(vty, argv[idx_peer]->arg, PEER_FLAG_PASSIVE);
3637 }
3638
3639 DEFUN (no_neighbor_passive,
3640 no_neighbor_passive_cmd,
3641 "no neighbor <A.B.C.D|X:X::X:X|WORD> passive",
3642 NO_STR
3643 NEIGHBOR_STR
3644 NEIGHBOR_ADDR_STR2
3645 "Don't send open messages to this neighbor\n")
3646 {
3647 int idx_peer = 2;
3648 return peer_flag_unset_vty(vty, argv[idx_peer]->arg, PEER_FLAG_PASSIVE);
3649 }
3650
3651 /* neighbor shutdown. */
3652 DEFUN (neighbor_shutdown_msg,
3653 neighbor_shutdown_msg_cmd,
3654 "neighbor <A.B.C.D|X:X::X:X|WORD> shutdown message MSG...",
3655 NEIGHBOR_STR
3656 NEIGHBOR_ADDR_STR2
3657 "Administratively shut down this neighbor\n"
3658 "Add a shutdown message (draft-ietf-idr-shutdown-06)\n"
3659 "Shutdown message\n")
3660 {
3661 int idx_peer = 1;
3662
3663 if (argc >= 5) {
3664 struct peer *peer =
3665 peer_and_group_lookup_vty(vty, argv[idx_peer]->arg);
3666 char *message;
3667
3668 if (!peer)
3669 return CMD_WARNING_CONFIG_FAILED;
3670 message = argv_concat(argv, argc, 4);
3671 peer_tx_shutdown_message_set(peer, message);
3672 XFREE(MTYPE_TMP, message);
3673 }
3674
3675 return peer_flag_set_vty(vty, argv[idx_peer]->arg, PEER_FLAG_SHUTDOWN);
3676 }
3677
3678 ALIAS(neighbor_shutdown_msg, neighbor_shutdown_cmd,
3679 "neighbor <A.B.C.D|X:X::X:X|WORD> shutdown",
3680 NEIGHBOR_STR NEIGHBOR_ADDR_STR2
3681 "Administratively shut down this neighbor\n")
3682
3683 DEFUN (no_neighbor_shutdown_msg,
3684 no_neighbor_shutdown_msg_cmd,
3685 "no neighbor <A.B.C.D|X:X::X:X|WORD> shutdown message MSG...",
3686 NO_STR
3687 NEIGHBOR_STR
3688 NEIGHBOR_ADDR_STR2
3689 "Administratively shut down this neighbor\n"
3690 "Remove a shutdown message (draft-ietf-idr-shutdown-06)\n"
3691 "Shutdown message\n")
3692 {
3693 int idx_peer = 2;
3694
3695 return peer_flag_unset_vty(vty, argv[idx_peer]->arg,
3696 PEER_FLAG_SHUTDOWN);
3697 }
3698
3699 ALIAS(no_neighbor_shutdown_msg, no_neighbor_shutdown_cmd,
3700 "no neighbor <A.B.C.D|X:X::X:X|WORD> shutdown",
3701 NO_STR NEIGHBOR_STR NEIGHBOR_ADDR_STR2
3702 "Administratively shut down this neighbor\n")
3703
3704 /* neighbor capability dynamic. */
3705 DEFUN (neighbor_capability_dynamic,
3706 neighbor_capability_dynamic_cmd,
3707 "neighbor <A.B.C.D|X:X::X:X|WORD> capability dynamic",
3708 NEIGHBOR_STR
3709 NEIGHBOR_ADDR_STR2
3710 "Advertise capability to the peer\n"
3711 "Advertise dynamic capability to this neighbor\n")
3712 {
3713 int idx_peer = 1;
3714 return peer_flag_set_vty(vty, argv[idx_peer]->arg,
3715 PEER_FLAG_DYNAMIC_CAPABILITY);
3716 }
3717
3718 DEFUN (no_neighbor_capability_dynamic,
3719 no_neighbor_capability_dynamic_cmd,
3720 "no neighbor <A.B.C.D|X:X::X:X|WORD> capability dynamic",
3721 NO_STR
3722 NEIGHBOR_STR
3723 NEIGHBOR_ADDR_STR2
3724 "Advertise capability to the peer\n"
3725 "Advertise dynamic capability to this neighbor\n")
3726 {
3727 int idx_peer = 2;
3728 return peer_flag_unset_vty(vty, argv[idx_peer]->arg,
3729 PEER_FLAG_DYNAMIC_CAPABILITY);
3730 }
3731
3732 /* neighbor dont-capability-negotiate */
3733 DEFUN (neighbor_dont_capability_negotiate,
3734 neighbor_dont_capability_negotiate_cmd,
3735 "neighbor <A.B.C.D|X:X::X:X|WORD> dont-capability-negotiate",
3736 NEIGHBOR_STR
3737 NEIGHBOR_ADDR_STR2
3738 "Do not perform capability negotiation\n")
3739 {
3740 int idx_peer = 1;
3741 return peer_flag_set_vty(vty, argv[idx_peer]->arg,
3742 PEER_FLAG_DONT_CAPABILITY);
3743 }
3744
3745 DEFUN (no_neighbor_dont_capability_negotiate,
3746 no_neighbor_dont_capability_negotiate_cmd,
3747 "no neighbor <A.B.C.D|X:X::X:X|WORD> dont-capability-negotiate",
3748 NO_STR
3749 NEIGHBOR_STR
3750 NEIGHBOR_ADDR_STR2
3751 "Do not perform capability negotiation\n")
3752 {
3753 int idx_peer = 2;
3754 return peer_flag_unset_vty(vty, argv[idx_peer]->arg,
3755 PEER_FLAG_DONT_CAPABILITY);
3756 }
3757
3758 /* neighbor capability extended next hop encoding */
3759 DEFUN (neighbor_capability_enhe,
3760 neighbor_capability_enhe_cmd,
3761 "neighbor <A.B.C.D|X:X::X:X|WORD> capability extended-nexthop",
3762 NEIGHBOR_STR
3763 NEIGHBOR_ADDR_STR2
3764 "Advertise capability to the peer\n"
3765 "Advertise extended next-hop capability to the peer\n")
3766 {
3767 int idx_peer = 1;
3768 return peer_flag_set_vty(vty, argv[idx_peer]->arg,
3769 PEER_FLAG_CAPABILITY_ENHE);
3770 }
3771
3772 DEFUN (no_neighbor_capability_enhe,
3773 no_neighbor_capability_enhe_cmd,
3774 "no neighbor <A.B.C.D|X:X::X:X|WORD> capability extended-nexthop",
3775 NO_STR
3776 NEIGHBOR_STR
3777 NEIGHBOR_ADDR_STR2
3778 "Advertise capability to the peer\n"
3779 "Advertise extended next-hop capability to the peer\n")
3780 {
3781 int idx_peer = 2;
3782 return peer_flag_unset_vty(vty, argv[idx_peer]->arg,
3783 PEER_FLAG_CAPABILITY_ENHE);
3784 }
3785
3786 static int peer_af_flag_modify_vty(struct vty *vty, const char *peer_str,
3787 afi_t afi, safi_t safi, uint32_t flag,
3788 int set)
3789 {
3790 int ret;
3791 struct peer *peer;
3792
3793 peer = peer_and_group_lookup_vty(vty, peer_str);
3794 if (!peer)
3795 return CMD_WARNING_CONFIG_FAILED;
3796
3797 if (set)
3798 ret = peer_af_flag_set(peer, afi, safi, flag);
3799 else
3800 ret = peer_af_flag_unset(peer, afi, safi, flag);
3801
3802 return bgp_vty_return(vty, ret);
3803 }
3804
3805 static int peer_af_flag_set_vty(struct vty *vty, const char *peer_str,
3806 afi_t afi, safi_t safi, uint32_t flag)
3807 {
3808 return peer_af_flag_modify_vty(vty, peer_str, afi, safi, flag, 1);
3809 }
3810
3811 static int peer_af_flag_unset_vty(struct vty *vty, const char *peer_str,
3812 afi_t afi, safi_t safi, uint32_t flag)
3813 {
3814 return peer_af_flag_modify_vty(vty, peer_str, afi, safi, flag, 0);
3815 }
3816
3817 /* neighbor capability orf prefix-list. */
3818 DEFUN (neighbor_capability_orf_prefix,
3819 neighbor_capability_orf_prefix_cmd,
3820 "neighbor <A.B.C.D|X:X::X:X|WORD> capability orf prefix-list <both|send|receive>",
3821 NEIGHBOR_STR
3822 NEIGHBOR_ADDR_STR2
3823 "Advertise capability to the peer\n"
3824 "Advertise ORF capability to the peer\n"
3825 "Advertise prefixlist ORF capability to this neighbor\n"
3826 "Capability to SEND and RECEIVE the ORF to/from this neighbor\n"
3827 "Capability to RECEIVE the ORF from this neighbor\n"
3828 "Capability to SEND the ORF to this neighbor\n")
3829 {
3830 int idx_peer = 1;
3831 int idx_send_recv = 5;
3832 uint16_t flag = 0;
3833
3834 if (strmatch(argv[idx_send_recv]->text, "send"))
3835 flag = PEER_FLAG_ORF_PREFIX_SM;
3836 else if (strmatch(argv[idx_send_recv]->text, "receive"))
3837 flag = PEER_FLAG_ORF_PREFIX_RM;
3838 else if (strmatch(argv[idx_send_recv]->text, "both"))
3839 flag = PEER_FLAG_ORF_PREFIX_SM | PEER_FLAG_ORF_PREFIX_RM;
3840 else {
3841 vty_out(vty, "%% BGP invalid orf prefix-list option\n");
3842 return CMD_WARNING_CONFIG_FAILED;
3843 }
3844
3845 return peer_af_flag_set_vty(vty, argv[idx_peer]->arg, bgp_node_afi(vty),
3846 bgp_node_safi(vty), flag);
3847 }
3848
3849 ALIAS_HIDDEN(
3850 neighbor_capability_orf_prefix,
3851 neighbor_capability_orf_prefix_hidden_cmd,
3852 "neighbor <A.B.C.D|X:X::X:X|WORD> capability orf prefix-list <both|send|receive>",
3853 NEIGHBOR_STR NEIGHBOR_ADDR_STR2
3854 "Advertise capability to the peer\n"
3855 "Advertise ORF capability to the peer\n"
3856 "Advertise prefixlist ORF capability to this neighbor\n"
3857 "Capability to SEND and RECEIVE the ORF to/from this neighbor\n"
3858 "Capability to RECEIVE the ORF from this neighbor\n"
3859 "Capability to SEND the ORF to this neighbor\n")
3860
3861 DEFUN (no_neighbor_capability_orf_prefix,
3862 no_neighbor_capability_orf_prefix_cmd,
3863 "no neighbor <A.B.C.D|X:X::X:X|WORD> capability orf prefix-list <both|send|receive>",
3864 NO_STR
3865 NEIGHBOR_STR
3866 NEIGHBOR_ADDR_STR2
3867 "Advertise capability to the peer\n"
3868 "Advertise ORF capability to the peer\n"
3869 "Advertise prefixlist ORF capability to this neighbor\n"
3870 "Capability to SEND and RECEIVE the ORF to/from this neighbor\n"
3871 "Capability to RECEIVE the ORF from this neighbor\n"
3872 "Capability to SEND the ORF to this neighbor\n")
3873 {
3874 int idx_peer = 2;
3875 int idx_send_recv = 6;
3876 uint16_t flag = 0;
3877
3878 if (strmatch(argv[idx_send_recv]->text, "send"))
3879 flag = PEER_FLAG_ORF_PREFIX_SM;
3880 else if (strmatch(argv[idx_send_recv]->text, "receive"))
3881 flag = PEER_FLAG_ORF_PREFIX_RM;
3882 else if (strmatch(argv[idx_send_recv]->text, "both"))
3883 flag = PEER_FLAG_ORF_PREFIX_SM | PEER_FLAG_ORF_PREFIX_RM;
3884 else {
3885 vty_out(vty, "%% BGP invalid orf prefix-list option\n");
3886 return CMD_WARNING_CONFIG_FAILED;
3887 }
3888
3889 return peer_af_flag_unset_vty(vty, argv[idx_peer]->arg,
3890 bgp_node_afi(vty), bgp_node_safi(vty),
3891 flag);
3892 }
3893
3894 ALIAS_HIDDEN(
3895 no_neighbor_capability_orf_prefix,
3896 no_neighbor_capability_orf_prefix_hidden_cmd,
3897 "no neighbor <A.B.C.D|X:X::X:X|WORD> capability orf prefix-list <both|send|receive>",
3898 NO_STR NEIGHBOR_STR NEIGHBOR_ADDR_STR2
3899 "Advertise capability to the peer\n"
3900 "Advertise ORF capability to the peer\n"
3901 "Advertise prefixlist ORF capability to this neighbor\n"
3902 "Capability to SEND and RECEIVE the ORF to/from this neighbor\n"
3903 "Capability to RECEIVE the ORF from this neighbor\n"
3904 "Capability to SEND the ORF to this neighbor\n")
3905
3906 /* neighbor next-hop-self. */
3907 DEFUN (neighbor_nexthop_self,
3908 neighbor_nexthop_self_cmd,
3909 "neighbor <A.B.C.D|X:X::X:X|WORD> next-hop-self",
3910 NEIGHBOR_STR
3911 NEIGHBOR_ADDR_STR2
3912 "Disable the next hop calculation for this neighbor\n")
3913 {
3914 int idx_peer = 1;
3915 return peer_af_flag_set_vty(vty, argv[idx_peer]->arg, bgp_node_afi(vty),
3916 bgp_node_safi(vty), PEER_FLAG_NEXTHOP_SELF);
3917 }
3918
3919 ALIAS_HIDDEN(neighbor_nexthop_self, neighbor_nexthop_self_hidden_cmd,
3920 "neighbor <A.B.C.D|X:X::X:X|WORD> next-hop-self",
3921 NEIGHBOR_STR NEIGHBOR_ADDR_STR2
3922 "Disable the next hop calculation for this neighbor\n")
3923
3924 /* neighbor next-hop-self. */
3925 DEFUN (neighbor_nexthop_self_force,
3926 neighbor_nexthop_self_force_cmd,
3927 "neighbor <A.B.C.D|X:X::X:X|WORD> next-hop-self force",
3928 NEIGHBOR_STR
3929 NEIGHBOR_ADDR_STR2
3930 "Disable the next hop calculation for this neighbor\n"
3931 "Set the next hop to self for reflected routes\n")
3932 {
3933 int idx_peer = 1;
3934 return peer_af_flag_set_vty(vty, argv[idx_peer]->arg, bgp_node_afi(vty),
3935 bgp_node_safi(vty),
3936 PEER_FLAG_FORCE_NEXTHOP_SELF);
3937 }
3938
3939 ALIAS_HIDDEN(neighbor_nexthop_self_force,
3940 neighbor_nexthop_self_force_hidden_cmd,
3941 "neighbor <A.B.C.D|X:X::X:X|WORD> next-hop-self force",
3942 NEIGHBOR_STR NEIGHBOR_ADDR_STR2
3943 "Disable the next hop calculation for this neighbor\n"
3944 "Set the next hop to self for reflected routes\n")
3945
3946 DEFUN (no_neighbor_nexthop_self,
3947 no_neighbor_nexthop_self_cmd,
3948 "no neighbor <A.B.C.D|X:X::X:X|WORD> next-hop-self",
3949 NO_STR
3950 NEIGHBOR_STR
3951 NEIGHBOR_ADDR_STR2
3952 "Disable the next hop calculation for this neighbor\n")
3953 {
3954 int idx_peer = 2;
3955 return peer_af_flag_unset_vty(vty, argv[idx_peer]->arg,
3956 bgp_node_afi(vty), bgp_node_safi(vty),
3957 PEER_FLAG_NEXTHOP_SELF);
3958 }
3959
3960 ALIAS_HIDDEN(no_neighbor_nexthop_self, no_neighbor_nexthop_self_hidden_cmd,
3961 "no neighbor <A.B.C.D|X:X::X:X|WORD> next-hop-self",
3962 NO_STR NEIGHBOR_STR NEIGHBOR_ADDR_STR2
3963 "Disable the next hop calculation for this neighbor\n")
3964
3965 DEFUN (no_neighbor_nexthop_self_force,
3966 no_neighbor_nexthop_self_force_cmd,
3967 "no neighbor <A.B.C.D|X:X::X:X|WORD> next-hop-self force",
3968 NO_STR
3969 NEIGHBOR_STR
3970 NEIGHBOR_ADDR_STR2
3971 "Disable the next hop calculation for this neighbor\n"
3972 "Set the next hop to self for reflected routes\n")
3973 {
3974 int idx_peer = 2;
3975 return peer_af_flag_unset_vty(vty, argv[idx_peer]->arg,
3976 bgp_node_afi(vty), bgp_node_safi(vty),
3977 PEER_FLAG_FORCE_NEXTHOP_SELF);
3978 }
3979
3980 ALIAS_HIDDEN(no_neighbor_nexthop_self_force,
3981 no_neighbor_nexthop_self_force_hidden_cmd,
3982 "no neighbor <A.B.C.D|X:X::X:X|WORD> next-hop-self force",
3983 NO_STR NEIGHBOR_STR NEIGHBOR_ADDR_STR2
3984 "Disable the next hop calculation for this neighbor\n"
3985 "Set the next hop to self for reflected routes\n")
3986
3987 /* neighbor as-override */
3988 DEFUN (neighbor_as_override,
3989 neighbor_as_override_cmd,
3990 "neighbor <A.B.C.D|X:X::X:X|WORD> as-override",
3991 NEIGHBOR_STR
3992 NEIGHBOR_ADDR_STR2
3993 "Override ASNs in outbound updates if aspath equals remote-as\n")
3994 {
3995 int idx_peer = 1;
3996 return peer_af_flag_set_vty(vty, argv[idx_peer]->arg, bgp_node_afi(vty),
3997 bgp_node_safi(vty), PEER_FLAG_AS_OVERRIDE);
3998 }
3999
4000 ALIAS_HIDDEN(neighbor_as_override, neighbor_as_override_hidden_cmd,
4001 "neighbor <A.B.C.D|X:X::X:X|WORD> as-override",
4002 NEIGHBOR_STR NEIGHBOR_ADDR_STR2
4003 "Override ASNs in outbound updates if aspath equals remote-as\n")
4004
4005 DEFUN (no_neighbor_as_override,
4006 no_neighbor_as_override_cmd,
4007 "no neighbor <A.B.C.D|X:X::X:X|WORD> as-override",
4008 NO_STR
4009 NEIGHBOR_STR
4010 NEIGHBOR_ADDR_STR2
4011 "Override ASNs in outbound updates if aspath equals remote-as\n")
4012 {
4013 int idx_peer = 2;
4014 return peer_af_flag_unset_vty(vty, argv[idx_peer]->arg,
4015 bgp_node_afi(vty), bgp_node_safi(vty),
4016 PEER_FLAG_AS_OVERRIDE);
4017 }
4018
4019 ALIAS_HIDDEN(no_neighbor_as_override, no_neighbor_as_override_hidden_cmd,
4020 "no neighbor <A.B.C.D|X:X::X:X|WORD> as-override",
4021 NO_STR NEIGHBOR_STR NEIGHBOR_ADDR_STR2
4022 "Override ASNs in outbound updates if aspath equals remote-as\n")
4023
4024 /* neighbor remove-private-AS. */
4025 DEFUN (neighbor_remove_private_as,
4026 neighbor_remove_private_as_cmd,
4027 "neighbor <A.B.C.D|X:X::X:X|WORD> remove-private-AS",
4028 NEIGHBOR_STR
4029 NEIGHBOR_ADDR_STR2
4030 "Remove private ASNs in outbound updates\n")
4031 {
4032 int idx_peer = 1;
4033 return peer_af_flag_set_vty(vty, argv[idx_peer]->arg, bgp_node_afi(vty),
4034 bgp_node_safi(vty),
4035 PEER_FLAG_REMOVE_PRIVATE_AS);
4036 }
4037
4038 ALIAS_HIDDEN(neighbor_remove_private_as, neighbor_remove_private_as_hidden_cmd,
4039 "neighbor <A.B.C.D|X:X::X:X|WORD> remove-private-AS",
4040 NEIGHBOR_STR NEIGHBOR_ADDR_STR2
4041 "Remove private ASNs in outbound updates\n")
4042
4043 DEFUN (neighbor_remove_private_as_all,
4044 neighbor_remove_private_as_all_cmd,
4045 "neighbor <A.B.C.D|X:X::X:X|WORD> remove-private-AS all",
4046 NEIGHBOR_STR
4047 NEIGHBOR_ADDR_STR2
4048 "Remove private ASNs in outbound updates\n"
4049 "Apply to all AS numbers\n")
4050 {
4051 int idx_peer = 1;
4052 return peer_af_flag_set_vty(vty, argv[idx_peer]->arg, bgp_node_afi(vty),
4053 bgp_node_safi(vty),
4054 PEER_FLAG_REMOVE_PRIVATE_AS_ALL);
4055 }
4056
4057 ALIAS_HIDDEN(neighbor_remove_private_as_all,
4058 neighbor_remove_private_as_all_hidden_cmd,
4059 "neighbor <A.B.C.D|X:X::X:X|WORD> remove-private-AS all",
4060 NEIGHBOR_STR NEIGHBOR_ADDR_STR2
4061 "Remove private ASNs in outbound updates\n"
4062 "Apply to all AS numbers")
4063
4064 DEFUN (neighbor_remove_private_as_replace_as,
4065 neighbor_remove_private_as_replace_as_cmd,
4066 "neighbor <A.B.C.D|X:X::X:X|WORD> remove-private-AS replace-AS",
4067 NEIGHBOR_STR
4068 NEIGHBOR_ADDR_STR2
4069 "Remove private ASNs in outbound updates\n"
4070 "Replace private ASNs with our ASN in outbound updates\n")
4071 {
4072 int idx_peer = 1;
4073 return peer_af_flag_set_vty(vty, argv[idx_peer]->arg, bgp_node_afi(vty),
4074 bgp_node_safi(vty),
4075 PEER_FLAG_REMOVE_PRIVATE_AS_REPLACE);
4076 }
4077
4078 ALIAS_HIDDEN(neighbor_remove_private_as_replace_as,
4079 neighbor_remove_private_as_replace_as_hidden_cmd,
4080 "neighbor <A.B.C.D|X:X::X:X|WORD> remove-private-AS replace-AS",
4081 NEIGHBOR_STR NEIGHBOR_ADDR_STR2
4082 "Remove private ASNs in outbound updates\n"
4083 "Replace private ASNs with our ASN in outbound updates\n")
4084
4085 DEFUN (neighbor_remove_private_as_all_replace_as,
4086 neighbor_remove_private_as_all_replace_as_cmd,
4087 "neighbor <A.B.C.D|X:X::X:X|WORD> remove-private-AS all replace-AS",
4088 NEIGHBOR_STR
4089 NEIGHBOR_ADDR_STR2
4090 "Remove private ASNs in outbound updates\n"
4091 "Apply to all AS numbers\n"
4092 "Replace private ASNs with our ASN in outbound updates\n")
4093 {
4094 int idx_peer = 1;
4095 return peer_af_flag_set_vty(vty, argv[idx_peer]->arg, bgp_node_afi(vty),
4096 bgp_node_safi(vty),
4097 PEER_FLAG_REMOVE_PRIVATE_AS_ALL_REPLACE);
4098 }
4099
4100 ALIAS_HIDDEN(
4101 neighbor_remove_private_as_all_replace_as,
4102 neighbor_remove_private_as_all_replace_as_hidden_cmd,
4103 "neighbor <A.B.C.D|X:X::X:X|WORD> remove-private-AS all replace-AS",
4104 NEIGHBOR_STR NEIGHBOR_ADDR_STR2
4105 "Remove private ASNs in outbound updates\n"
4106 "Apply to all AS numbers\n"
4107 "Replace private ASNs with our ASN in outbound updates\n")
4108
4109 DEFUN (no_neighbor_remove_private_as,
4110 no_neighbor_remove_private_as_cmd,
4111 "no neighbor <A.B.C.D|X:X::X:X|WORD> remove-private-AS",
4112 NO_STR
4113 NEIGHBOR_STR
4114 NEIGHBOR_ADDR_STR2
4115 "Remove private ASNs in outbound updates\n")
4116 {
4117 int idx_peer = 2;
4118 return peer_af_flag_unset_vty(vty, argv[idx_peer]->arg,
4119 bgp_node_afi(vty), bgp_node_safi(vty),
4120 PEER_FLAG_REMOVE_PRIVATE_AS);
4121 }
4122
4123 ALIAS_HIDDEN(no_neighbor_remove_private_as,
4124 no_neighbor_remove_private_as_hidden_cmd,
4125 "no neighbor <A.B.C.D|X:X::X:X|WORD> remove-private-AS",
4126 NO_STR NEIGHBOR_STR NEIGHBOR_ADDR_STR2
4127 "Remove private ASNs in outbound updates\n")
4128
4129 DEFUN (no_neighbor_remove_private_as_all,
4130 no_neighbor_remove_private_as_all_cmd,
4131 "no neighbor <A.B.C.D|X:X::X:X|WORD> remove-private-AS all",
4132 NO_STR
4133 NEIGHBOR_STR
4134 NEIGHBOR_ADDR_STR2
4135 "Remove private ASNs in outbound updates\n"
4136 "Apply to all AS numbers\n")
4137 {
4138 int idx_peer = 2;
4139 return peer_af_flag_unset_vty(vty, argv[idx_peer]->arg,
4140 bgp_node_afi(vty), bgp_node_safi(vty),
4141 PEER_FLAG_REMOVE_PRIVATE_AS_ALL);
4142 }
4143
4144 ALIAS_HIDDEN(no_neighbor_remove_private_as_all,
4145 no_neighbor_remove_private_as_all_hidden_cmd,
4146 "no neighbor <A.B.C.D|X:X::X:X|WORD> remove-private-AS all",
4147 NO_STR NEIGHBOR_STR NEIGHBOR_ADDR_STR2
4148 "Remove private ASNs in outbound updates\n"
4149 "Apply to all AS numbers\n")
4150
4151 DEFUN (no_neighbor_remove_private_as_replace_as,
4152 no_neighbor_remove_private_as_replace_as_cmd,
4153 "no neighbor <A.B.C.D|X:X::X:X|WORD> remove-private-AS replace-AS",
4154 NO_STR
4155 NEIGHBOR_STR
4156 NEIGHBOR_ADDR_STR2
4157 "Remove private ASNs in outbound updates\n"
4158 "Replace private ASNs with our ASN in outbound updates\n")
4159 {
4160 int idx_peer = 2;
4161 return peer_af_flag_unset_vty(vty, argv[idx_peer]->arg,
4162 bgp_node_afi(vty), bgp_node_safi(vty),
4163 PEER_FLAG_REMOVE_PRIVATE_AS_REPLACE);
4164 }
4165
4166 ALIAS_HIDDEN(no_neighbor_remove_private_as_replace_as,
4167 no_neighbor_remove_private_as_replace_as_hidden_cmd,
4168 "no neighbor <A.B.C.D|X:X::X:X|WORD> remove-private-AS replace-AS",
4169 NO_STR NEIGHBOR_STR NEIGHBOR_ADDR_STR2
4170 "Remove private ASNs in outbound updates\n"
4171 "Replace private ASNs with our ASN in outbound updates\n")
4172
4173 DEFUN (no_neighbor_remove_private_as_all_replace_as,
4174 no_neighbor_remove_private_as_all_replace_as_cmd,
4175 "no neighbor <A.B.C.D|X:X::X:X|WORD> remove-private-AS all replace-AS",
4176 NO_STR
4177 NEIGHBOR_STR
4178 NEIGHBOR_ADDR_STR2
4179 "Remove private ASNs in outbound updates\n"
4180 "Apply to all AS numbers\n"
4181 "Replace private ASNs with our ASN in outbound updates\n")
4182 {
4183 int idx_peer = 2;
4184 return peer_af_flag_unset_vty(vty, argv[idx_peer]->arg,
4185 bgp_node_afi(vty), bgp_node_safi(vty),
4186 PEER_FLAG_REMOVE_PRIVATE_AS_ALL_REPLACE);
4187 }
4188
4189 ALIAS_HIDDEN(
4190 no_neighbor_remove_private_as_all_replace_as,
4191 no_neighbor_remove_private_as_all_replace_as_hidden_cmd,
4192 "no neighbor <A.B.C.D|X:X::X:X|WORD> remove-private-AS all replace-AS",
4193 NO_STR NEIGHBOR_STR NEIGHBOR_ADDR_STR2
4194 "Remove private ASNs in outbound updates\n"
4195 "Apply to all AS numbers\n"
4196 "Replace private ASNs with our ASN in outbound updates\n")
4197
4198
4199 /* neighbor send-community. */
4200 DEFUN (neighbor_send_community,
4201 neighbor_send_community_cmd,
4202 "neighbor <A.B.C.D|X:X::X:X|WORD> send-community",
4203 NEIGHBOR_STR
4204 NEIGHBOR_ADDR_STR2
4205 "Send Community attribute to this neighbor\n")
4206 {
4207 int idx_peer = 1;
4208
4209 return peer_af_flag_set_vty(vty, argv[idx_peer]->arg, bgp_node_afi(vty),
4210 bgp_node_safi(vty),
4211 PEER_FLAG_SEND_COMMUNITY);
4212 }
4213
4214 ALIAS_HIDDEN(neighbor_send_community, neighbor_send_community_hidden_cmd,
4215 "neighbor <A.B.C.D|X:X::X:X|WORD> send-community",
4216 NEIGHBOR_STR NEIGHBOR_ADDR_STR2
4217 "Send Community attribute to this neighbor\n")
4218
4219 DEFUN (no_neighbor_send_community,
4220 no_neighbor_send_community_cmd,
4221 "no neighbor <A.B.C.D|X:X::X:X|WORD> send-community",
4222 NO_STR
4223 NEIGHBOR_STR
4224 NEIGHBOR_ADDR_STR2
4225 "Send Community attribute to this neighbor\n")
4226 {
4227 int idx_peer = 2;
4228
4229 return peer_af_flag_unset_vty(vty, argv[idx_peer]->arg,
4230 bgp_node_afi(vty), bgp_node_safi(vty),
4231 PEER_FLAG_SEND_COMMUNITY);
4232 }
4233
4234 ALIAS_HIDDEN(no_neighbor_send_community, no_neighbor_send_community_hidden_cmd,
4235 "no neighbor <A.B.C.D|X:X::X:X|WORD> send-community",
4236 NO_STR NEIGHBOR_STR NEIGHBOR_ADDR_STR2
4237 "Send Community attribute to this neighbor\n")
4238
4239 /* neighbor send-community extended. */
4240 DEFUN (neighbor_send_community_type,
4241 neighbor_send_community_type_cmd,
4242 "neighbor <A.B.C.D|X:X::X:X|WORD> send-community <both|all|extended|standard|large>",
4243 NEIGHBOR_STR
4244 NEIGHBOR_ADDR_STR2
4245 "Send Community attribute to this neighbor\n"
4246 "Send Standard and Extended Community attributes\n"
4247 "Send Standard, Large and Extended Community attributes\n"
4248 "Send Extended Community attributes\n"
4249 "Send Standard Community attributes\n"
4250 "Send Large Community attributes\n")
4251 {
4252 int idx_peer = 1;
4253 uint32_t flag = 0;
4254 const char *type = argv[argc - 1]->text;
4255
4256 if (strmatch(type, "standard")) {
4257 SET_FLAG(flag, PEER_FLAG_SEND_COMMUNITY);
4258 } else if (strmatch(type, "extended")) {
4259 SET_FLAG(flag, PEER_FLAG_SEND_EXT_COMMUNITY);
4260 } else if (strmatch(type, "large")) {
4261 SET_FLAG(flag, PEER_FLAG_SEND_LARGE_COMMUNITY);
4262 } else if (strmatch(type, "both")) {
4263 SET_FLAG(flag, PEER_FLAG_SEND_COMMUNITY);
4264 SET_FLAG(flag, PEER_FLAG_SEND_EXT_COMMUNITY);
4265 } else { /* if (strmatch(type, "all")) */
4266 SET_FLAG(flag, PEER_FLAG_SEND_COMMUNITY);
4267 SET_FLAG(flag, PEER_FLAG_SEND_EXT_COMMUNITY);
4268 SET_FLAG(flag, PEER_FLAG_SEND_LARGE_COMMUNITY);
4269 }
4270
4271 return peer_af_flag_set_vty(vty, argv[idx_peer]->arg, bgp_node_afi(vty),
4272 bgp_node_safi(vty), flag);
4273 }
4274
4275 ALIAS_HIDDEN(
4276 neighbor_send_community_type, neighbor_send_community_type_hidden_cmd,
4277 "neighbor <A.B.C.D|X:X::X:X|WORD> send-community <both|all|extended|standard|large>",
4278 NEIGHBOR_STR NEIGHBOR_ADDR_STR2
4279 "Send Community attribute to this neighbor\n"
4280 "Send Standard and Extended Community attributes\n"
4281 "Send Standard, Large and Extended Community attributes\n"
4282 "Send Extended Community attributes\n"
4283 "Send Standard Community attributes\n"
4284 "Send Large Community attributes\n")
4285
4286 DEFUN (no_neighbor_send_community_type,
4287 no_neighbor_send_community_type_cmd,
4288 "no neighbor <A.B.C.D|X:X::X:X|WORD> send-community <both|all|extended|standard|large>",
4289 NO_STR
4290 NEIGHBOR_STR
4291 NEIGHBOR_ADDR_STR2
4292 "Send Community attribute to this neighbor\n"
4293 "Send Standard and Extended Community attributes\n"
4294 "Send Standard, Large and Extended Community attributes\n"
4295 "Send Extended Community attributes\n"
4296 "Send Standard Community attributes\n"
4297 "Send Large Community attributes\n")
4298 {
4299 int idx_peer = 2;
4300 uint32_t flag = 0;
4301 const char *type = argv[argc - 1]->text;
4302
4303 if (strmatch(type, "standard")) {
4304 SET_FLAG(flag, PEER_FLAG_SEND_COMMUNITY);
4305 } else if (strmatch(type, "extended")) {
4306 SET_FLAG(flag, PEER_FLAG_SEND_EXT_COMMUNITY);
4307 } else if (strmatch(type, "large")) {
4308 SET_FLAG(flag, PEER_FLAG_SEND_LARGE_COMMUNITY);
4309 } else if (strmatch(type, "both")) {
4310 SET_FLAG(flag, PEER_FLAG_SEND_COMMUNITY);
4311 SET_FLAG(flag, PEER_FLAG_SEND_EXT_COMMUNITY);
4312 } else { /* if (strmatch(type, "all")) */
4313 SET_FLAG(flag, PEER_FLAG_SEND_COMMUNITY);
4314 SET_FLAG(flag, PEER_FLAG_SEND_EXT_COMMUNITY);
4315 SET_FLAG(flag, PEER_FLAG_SEND_LARGE_COMMUNITY);
4316 }
4317
4318 return peer_af_flag_unset_vty(vty, argv[idx_peer]->arg,
4319 bgp_node_afi(vty), bgp_node_safi(vty),
4320 flag);
4321 }
4322
4323 ALIAS_HIDDEN(
4324 no_neighbor_send_community_type,
4325 no_neighbor_send_community_type_hidden_cmd,
4326 "no neighbor <A.B.C.D|X:X::X:X|WORD> send-community <both|all|extended|standard|large>",
4327 NO_STR NEIGHBOR_STR NEIGHBOR_ADDR_STR2
4328 "Send Community attribute to this neighbor\n"
4329 "Send Standard and Extended Community attributes\n"
4330 "Send Standard, Large and Extended Community attributes\n"
4331 "Send Extended Community attributes\n"
4332 "Send Standard Community attributes\n"
4333 "Send Large Community attributes\n")
4334
4335 /* neighbor soft-reconfig. */
4336 DEFUN (neighbor_soft_reconfiguration,
4337 neighbor_soft_reconfiguration_cmd,
4338 "neighbor <A.B.C.D|X:X::X:X|WORD> soft-reconfiguration inbound",
4339 NEIGHBOR_STR
4340 NEIGHBOR_ADDR_STR2
4341 "Per neighbor soft reconfiguration\n"
4342 "Allow inbound soft reconfiguration for this neighbor\n")
4343 {
4344 int idx_peer = 1;
4345 return peer_af_flag_set_vty(vty, argv[idx_peer]->arg, bgp_node_afi(vty),
4346 bgp_node_safi(vty),
4347 PEER_FLAG_SOFT_RECONFIG);
4348 }
4349
4350 ALIAS_HIDDEN(neighbor_soft_reconfiguration,
4351 neighbor_soft_reconfiguration_hidden_cmd,
4352 "neighbor <A.B.C.D|X:X::X:X|WORD> soft-reconfiguration inbound",
4353 NEIGHBOR_STR NEIGHBOR_ADDR_STR2
4354 "Per neighbor soft reconfiguration\n"
4355 "Allow inbound soft reconfiguration for this neighbor\n")
4356
4357 DEFUN (no_neighbor_soft_reconfiguration,
4358 no_neighbor_soft_reconfiguration_cmd,
4359 "no neighbor <A.B.C.D|X:X::X:X|WORD> soft-reconfiguration inbound",
4360 NO_STR
4361 NEIGHBOR_STR
4362 NEIGHBOR_ADDR_STR2
4363 "Per neighbor soft reconfiguration\n"
4364 "Allow inbound soft reconfiguration for this neighbor\n")
4365 {
4366 int idx_peer = 2;
4367 return peer_af_flag_unset_vty(vty, argv[idx_peer]->arg,
4368 bgp_node_afi(vty), bgp_node_safi(vty),
4369 PEER_FLAG_SOFT_RECONFIG);
4370 }
4371
4372 ALIAS_HIDDEN(no_neighbor_soft_reconfiguration,
4373 no_neighbor_soft_reconfiguration_hidden_cmd,
4374 "no neighbor <A.B.C.D|X:X::X:X|WORD> soft-reconfiguration inbound",
4375 NO_STR NEIGHBOR_STR NEIGHBOR_ADDR_STR2
4376 "Per neighbor soft reconfiguration\n"
4377 "Allow inbound soft reconfiguration for this neighbor\n")
4378
4379 DEFUN (neighbor_route_reflector_client,
4380 neighbor_route_reflector_client_cmd,
4381 "neighbor <A.B.C.D|X:X::X:X|WORD> route-reflector-client",
4382 NEIGHBOR_STR
4383 NEIGHBOR_ADDR_STR2
4384 "Configure a neighbor as Route Reflector client\n")
4385 {
4386 int idx_peer = 1;
4387 struct peer *peer;
4388
4389
4390 peer = peer_and_group_lookup_vty(vty, argv[idx_peer]->arg);
4391 if (!peer)
4392 return CMD_WARNING_CONFIG_FAILED;
4393
4394 return peer_af_flag_set_vty(vty, argv[idx_peer]->arg, bgp_node_afi(vty),
4395 bgp_node_safi(vty),
4396 PEER_FLAG_REFLECTOR_CLIENT);
4397 }
4398
4399 ALIAS_HIDDEN(neighbor_route_reflector_client,
4400 neighbor_route_reflector_client_hidden_cmd,
4401 "neighbor <A.B.C.D|X:X::X:X|WORD> route-reflector-client",
4402 NEIGHBOR_STR NEIGHBOR_ADDR_STR2
4403 "Configure a neighbor as Route Reflector client\n")
4404
4405 DEFUN (no_neighbor_route_reflector_client,
4406 no_neighbor_route_reflector_client_cmd,
4407 "no neighbor <A.B.C.D|X:X::X:X|WORD> route-reflector-client",
4408 NO_STR
4409 NEIGHBOR_STR
4410 NEIGHBOR_ADDR_STR2
4411 "Configure a neighbor as Route Reflector client\n")
4412 {
4413 int idx_peer = 2;
4414 return peer_af_flag_unset_vty(vty, argv[idx_peer]->arg,
4415 bgp_node_afi(vty), bgp_node_safi(vty),
4416 PEER_FLAG_REFLECTOR_CLIENT);
4417 }
4418
4419 ALIAS_HIDDEN(no_neighbor_route_reflector_client,
4420 no_neighbor_route_reflector_client_hidden_cmd,
4421 "no neighbor <A.B.C.D|X:X::X:X|WORD> route-reflector-client",
4422 NO_STR NEIGHBOR_STR NEIGHBOR_ADDR_STR2
4423 "Configure a neighbor as Route Reflector client\n")
4424
4425 /* neighbor route-server-client. */
4426 DEFUN (neighbor_route_server_client,
4427 neighbor_route_server_client_cmd,
4428 "neighbor <A.B.C.D|X:X::X:X|WORD> route-server-client",
4429 NEIGHBOR_STR
4430 NEIGHBOR_ADDR_STR2
4431 "Configure a neighbor as Route Server client\n")
4432 {
4433 int idx_peer = 1;
4434 struct peer *peer;
4435
4436 peer = peer_and_group_lookup_vty(vty, argv[idx_peer]->arg);
4437 if (!peer)
4438 return CMD_WARNING_CONFIG_FAILED;
4439 return peer_af_flag_set_vty(vty, argv[idx_peer]->arg, bgp_node_afi(vty),
4440 bgp_node_safi(vty),
4441 PEER_FLAG_RSERVER_CLIENT);
4442 }
4443
4444 ALIAS_HIDDEN(neighbor_route_server_client,
4445 neighbor_route_server_client_hidden_cmd,
4446 "neighbor <A.B.C.D|X:X::X:X|WORD> route-server-client",
4447 NEIGHBOR_STR NEIGHBOR_ADDR_STR2
4448 "Configure a neighbor as Route Server client\n")
4449
4450 DEFUN (no_neighbor_route_server_client,
4451 no_neighbor_route_server_client_cmd,
4452 "no neighbor <A.B.C.D|X:X::X:X|WORD> route-server-client",
4453 NO_STR
4454 NEIGHBOR_STR
4455 NEIGHBOR_ADDR_STR2
4456 "Configure a neighbor as Route Server client\n")
4457 {
4458 int idx_peer = 2;
4459 return peer_af_flag_unset_vty(vty, argv[idx_peer]->arg,
4460 bgp_node_afi(vty), bgp_node_safi(vty),
4461 PEER_FLAG_RSERVER_CLIENT);
4462 }
4463
4464 ALIAS_HIDDEN(no_neighbor_route_server_client,
4465 no_neighbor_route_server_client_hidden_cmd,
4466 "no neighbor <A.B.C.D|X:X::X:X|WORD> route-server-client",
4467 NO_STR NEIGHBOR_STR NEIGHBOR_ADDR_STR2
4468 "Configure a neighbor as Route Server client\n")
4469
4470 DEFUN (neighbor_nexthop_local_unchanged,
4471 neighbor_nexthop_local_unchanged_cmd,
4472 "neighbor <A.B.C.D|X:X::X:X|WORD> nexthop-local unchanged",
4473 NEIGHBOR_STR
4474 NEIGHBOR_ADDR_STR2
4475 "Configure treatment of outgoing link-local nexthop attribute\n"
4476 "Leave link-local nexthop unchanged for this peer\n")
4477 {
4478 int idx_peer = 1;
4479 return peer_af_flag_set_vty(vty, argv[idx_peer]->arg, bgp_node_afi(vty),
4480 bgp_node_safi(vty),
4481 PEER_FLAG_NEXTHOP_LOCAL_UNCHANGED);
4482 }
4483
4484 DEFUN (no_neighbor_nexthop_local_unchanged,
4485 no_neighbor_nexthop_local_unchanged_cmd,
4486 "no neighbor <A.B.C.D|X:X::X:X|WORD> nexthop-local unchanged",
4487 NO_STR
4488 NEIGHBOR_STR
4489 NEIGHBOR_ADDR_STR2
4490 "Configure treatment of outgoing link-local-nexthop attribute\n"
4491 "Leave link-local nexthop unchanged for this peer\n")
4492 {
4493 int idx_peer = 2;
4494 return peer_af_flag_unset_vty(vty, argv[idx_peer]->arg,
4495 bgp_node_afi(vty), bgp_node_safi(vty),
4496 PEER_FLAG_NEXTHOP_LOCAL_UNCHANGED);
4497 }
4498
4499 DEFUN (neighbor_attr_unchanged,
4500 neighbor_attr_unchanged_cmd,
4501 "neighbor <A.B.C.D|X:X::X:X|WORD> attribute-unchanged [{as-path|next-hop|med}]",
4502 NEIGHBOR_STR
4503 NEIGHBOR_ADDR_STR2
4504 "BGP attribute is propagated unchanged to this neighbor\n"
4505 "As-path attribute\n"
4506 "Nexthop attribute\n"
4507 "Med attribute\n")
4508 {
4509 int idx = 0;
4510 char *peer_str = argv[1]->arg;
4511 struct peer *peer;
4512 uint16_t flags = 0;
4513 afi_t afi = bgp_node_afi(vty);
4514 safi_t safi = bgp_node_safi(vty);
4515
4516 peer = peer_and_group_lookup_vty(vty, peer_str);
4517 if (!peer)
4518 return CMD_WARNING_CONFIG_FAILED;
4519
4520 if (argv_find(argv, argc, "as-path", &idx))
4521 SET_FLAG(flags, PEER_FLAG_AS_PATH_UNCHANGED);
4522 idx = 0;
4523 if (argv_find(argv, argc, "next-hop", &idx))
4524 SET_FLAG(flags, PEER_FLAG_NEXTHOP_UNCHANGED);
4525 idx = 0;
4526 if (argv_find(argv, argc, "med", &idx))
4527 SET_FLAG(flags, PEER_FLAG_MED_UNCHANGED);
4528
4529 /* no flags means all of them! */
4530 if (!flags) {
4531 SET_FLAG(flags, PEER_FLAG_AS_PATH_UNCHANGED);
4532 SET_FLAG(flags, PEER_FLAG_NEXTHOP_UNCHANGED);
4533 SET_FLAG(flags, PEER_FLAG_MED_UNCHANGED);
4534 } else {
4535 if (!CHECK_FLAG(flags, PEER_FLAG_AS_PATH_UNCHANGED)
4536 && peer_af_flag_check(peer, afi, safi,
4537 PEER_FLAG_AS_PATH_UNCHANGED)) {
4538 peer_af_flag_unset_vty(vty, peer_str, afi, safi,
4539 PEER_FLAG_AS_PATH_UNCHANGED);
4540 }
4541
4542 if (!CHECK_FLAG(flags, PEER_FLAG_NEXTHOP_UNCHANGED)
4543 && peer_af_flag_check(peer, afi, safi,
4544 PEER_FLAG_NEXTHOP_UNCHANGED)) {
4545 peer_af_flag_unset_vty(vty, peer_str, afi, safi,
4546 PEER_FLAG_NEXTHOP_UNCHANGED);
4547 }
4548
4549 if (!CHECK_FLAG(flags, PEER_FLAG_MED_UNCHANGED)
4550 && peer_af_flag_check(peer, afi, safi,
4551 PEER_FLAG_MED_UNCHANGED)) {
4552 peer_af_flag_unset_vty(vty, peer_str, afi, safi,
4553 PEER_FLAG_MED_UNCHANGED);
4554 }
4555 }
4556
4557 return peer_af_flag_set_vty(vty, peer_str, afi, safi, flags);
4558 }
4559
4560 ALIAS_HIDDEN(
4561 neighbor_attr_unchanged, neighbor_attr_unchanged_hidden_cmd,
4562 "neighbor <A.B.C.D|X:X::X:X|WORD> attribute-unchanged [{as-path|next-hop|med}]",
4563 NEIGHBOR_STR NEIGHBOR_ADDR_STR2
4564 "BGP attribute is propagated unchanged to this neighbor\n"
4565 "As-path attribute\n"
4566 "Nexthop attribute\n"
4567 "Med attribute\n")
4568
4569 DEFUN (no_neighbor_attr_unchanged,
4570 no_neighbor_attr_unchanged_cmd,
4571 "no neighbor <A.B.C.D|X:X::X:X|WORD> attribute-unchanged [{as-path|next-hop|med}]",
4572 NO_STR
4573 NEIGHBOR_STR
4574 NEIGHBOR_ADDR_STR2
4575 "BGP attribute is propagated unchanged to this neighbor\n"
4576 "As-path attribute\n"
4577 "Nexthop attribute\n"
4578 "Med attribute\n")
4579 {
4580 int idx = 0;
4581 char *peer = argv[2]->arg;
4582 uint16_t flags = 0;
4583
4584 if (argv_find(argv, argc, "as-path", &idx))
4585 SET_FLAG(flags, PEER_FLAG_AS_PATH_UNCHANGED);
4586 idx = 0;
4587 if (argv_find(argv, argc, "next-hop", &idx))
4588 SET_FLAG(flags, PEER_FLAG_NEXTHOP_UNCHANGED);
4589 idx = 0;
4590 if (argv_find(argv, argc, "med", &idx))
4591 SET_FLAG(flags, PEER_FLAG_MED_UNCHANGED);
4592
4593 if (!flags) // no flags means all of them!
4594 {
4595 SET_FLAG(flags, PEER_FLAG_AS_PATH_UNCHANGED);
4596 SET_FLAG(flags, PEER_FLAG_NEXTHOP_UNCHANGED);
4597 SET_FLAG(flags, PEER_FLAG_MED_UNCHANGED);
4598 }
4599
4600 return peer_af_flag_unset_vty(vty, peer, bgp_node_afi(vty),
4601 bgp_node_safi(vty), flags);
4602 }
4603
4604 ALIAS_HIDDEN(
4605 no_neighbor_attr_unchanged, no_neighbor_attr_unchanged_hidden_cmd,
4606 "no neighbor <A.B.C.D|X:X::X:X|WORD> attribute-unchanged [{as-path|next-hop|med}]",
4607 NO_STR NEIGHBOR_STR NEIGHBOR_ADDR_STR2
4608 "BGP attribute is propagated unchanged to this neighbor\n"
4609 "As-path attribute\n"
4610 "Nexthop attribute\n"
4611 "Med attribute\n")
4612
4613 /* EBGP multihop configuration. */
4614 static int peer_ebgp_multihop_set_vty(struct vty *vty, const char *ip_str,
4615 const char *ttl_str)
4616 {
4617 struct peer *peer;
4618 unsigned int ttl;
4619
4620 peer = peer_and_group_lookup_vty(vty, ip_str);
4621 if (!peer)
4622 return CMD_WARNING_CONFIG_FAILED;
4623
4624 if (peer->conf_if)
4625 return bgp_vty_return(vty, BGP_ERR_INVALID_FOR_DIRECT_PEER);
4626
4627 if (!ttl_str)
4628 ttl = MAXTTL;
4629 else
4630 ttl = strtoul(ttl_str, NULL, 10);
4631
4632 return bgp_vty_return(vty, peer_ebgp_multihop_set(peer, ttl));
4633 }
4634
4635 static int peer_ebgp_multihop_unset_vty(struct vty *vty, const char *ip_str)
4636 {
4637 struct peer *peer;
4638
4639 peer = peer_and_group_lookup_vty(vty, ip_str);
4640 if (!peer)
4641 return CMD_WARNING_CONFIG_FAILED;
4642
4643 return bgp_vty_return(vty, peer_ebgp_multihop_unset(peer));
4644 }
4645
4646 /* neighbor ebgp-multihop. */
4647 DEFUN (neighbor_ebgp_multihop,
4648 neighbor_ebgp_multihop_cmd,
4649 "neighbor <A.B.C.D|X:X::X:X|WORD> ebgp-multihop",
4650 NEIGHBOR_STR
4651 NEIGHBOR_ADDR_STR2
4652 "Allow EBGP neighbors not on directly connected networks\n")
4653 {
4654 int idx_peer = 1;
4655 return peer_ebgp_multihop_set_vty(vty, argv[idx_peer]->arg, NULL);
4656 }
4657
4658 DEFUN (neighbor_ebgp_multihop_ttl,
4659 neighbor_ebgp_multihop_ttl_cmd,
4660 "neighbor <A.B.C.D|X:X::X:X|WORD> ebgp-multihop (1-255)",
4661 NEIGHBOR_STR
4662 NEIGHBOR_ADDR_STR2
4663 "Allow EBGP neighbors not on directly connected networks\n"
4664 "maximum hop count\n")
4665 {
4666 int idx_peer = 1;
4667 int idx_number = 3;
4668 return peer_ebgp_multihop_set_vty(vty, argv[idx_peer]->arg,
4669 argv[idx_number]->arg);
4670 }
4671
4672 DEFUN (no_neighbor_ebgp_multihop,
4673 no_neighbor_ebgp_multihop_cmd,
4674 "no neighbor <A.B.C.D|X:X::X:X|WORD> ebgp-multihop [(1-255)]",
4675 NO_STR
4676 NEIGHBOR_STR
4677 NEIGHBOR_ADDR_STR2
4678 "Allow EBGP neighbors not on directly connected networks\n"
4679 "maximum hop count\n")
4680 {
4681 int idx_peer = 2;
4682 return peer_ebgp_multihop_unset_vty(vty, argv[idx_peer]->arg);
4683 }
4684
4685
4686 /* disable-connected-check */
4687 DEFUN (neighbor_disable_connected_check,
4688 neighbor_disable_connected_check_cmd,
4689 "neighbor <A.B.C.D|X:X::X:X|WORD> <disable-connected-check|enforce-multihop>",
4690 NEIGHBOR_STR
4691 NEIGHBOR_ADDR_STR2
4692 "one-hop away EBGP peer using loopback address\n"
4693 "Enforce EBGP neighbors perform multihop\n")
4694 {
4695 int idx_peer = 1;
4696 return peer_flag_set_vty(vty, argv[idx_peer]->arg,
4697 PEER_FLAG_DISABLE_CONNECTED_CHECK);
4698 }
4699
4700 DEFUN (no_neighbor_disable_connected_check,
4701 no_neighbor_disable_connected_check_cmd,
4702 "no neighbor <A.B.C.D|X:X::X:X|WORD> <disable-connected-check|enforce-multihop>",
4703 NO_STR
4704 NEIGHBOR_STR
4705 NEIGHBOR_ADDR_STR2
4706 "one-hop away EBGP peer using loopback address\n"
4707 "Enforce EBGP neighbors perform multihop\n")
4708 {
4709 int idx_peer = 2;
4710 return peer_flag_unset_vty(vty, argv[idx_peer]->arg,
4711 PEER_FLAG_DISABLE_CONNECTED_CHECK);
4712 }
4713
4714
4715 /* enforce-first-as */
4716 DEFUN (neighbor_enforce_first_as,
4717 neighbor_enforce_first_as_cmd,
4718 "neighbor <A.B.C.D|X:X::X:X|WORD> enforce-first-as",
4719 NEIGHBOR_STR
4720 NEIGHBOR_ADDR_STR2
4721 "Enforce the first AS for EBGP routes\n")
4722 {
4723 int idx_peer = 1;
4724
4725 return peer_flag_set_vty(vty, argv[idx_peer]->arg,
4726 PEER_FLAG_ENFORCE_FIRST_AS);
4727 }
4728
4729 DEFUN (no_neighbor_enforce_first_as,
4730 no_neighbor_enforce_first_as_cmd,
4731 "no neighbor <A.B.C.D|X:X::X:X|WORD> enforce-first-as",
4732 NO_STR
4733 NEIGHBOR_STR
4734 NEIGHBOR_ADDR_STR2
4735 "Enforce the first AS for EBGP routes\n")
4736 {
4737 int idx_peer = 2;
4738
4739 return peer_flag_unset_vty(vty, argv[idx_peer]->arg,
4740 PEER_FLAG_ENFORCE_FIRST_AS);
4741 }
4742
4743
4744 DEFUN (neighbor_description,
4745 neighbor_description_cmd,
4746 "neighbor <A.B.C.D|X:X::X:X|WORD> description LINE...",
4747 NEIGHBOR_STR
4748 NEIGHBOR_ADDR_STR2
4749 "Neighbor specific description\n"
4750 "Up to 80 characters describing this neighbor\n")
4751 {
4752 int idx_peer = 1;
4753 int idx_line = 3;
4754 struct peer *peer;
4755 char *str;
4756
4757 peer = peer_and_group_lookup_vty(vty, argv[idx_peer]->arg);
4758 if (!peer)
4759 return CMD_WARNING_CONFIG_FAILED;
4760
4761 str = argv_concat(argv, argc, idx_line);
4762
4763 peer_description_set(peer, str);
4764
4765 XFREE(MTYPE_TMP, str);
4766
4767 return CMD_SUCCESS;
4768 }
4769
4770 DEFUN (no_neighbor_description,
4771 no_neighbor_description_cmd,
4772 "no neighbor <A.B.C.D|X:X::X:X|WORD> description",
4773 NO_STR
4774 NEIGHBOR_STR
4775 NEIGHBOR_ADDR_STR2
4776 "Neighbor specific description\n")
4777 {
4778 int idx_peer = 2;
4779 struct peer *peer;
4780
4781 peer = peer_and_group_lookup_vty(vty, argv[idx_peer]->arg);
4782 if (!peer)
4783 return CMD_WARNING_CONFIG_FAILED;
4784
4785 peer_description_unset(peer);
4786
4787 return CMD_SUCCESS;
4788 }
4789
4790 ALIAS(no_neighbor_description, no_neighbor_description_comment_cmd,
4791 "no neighbor <A.B.C.D|X:X::X:X|WORD> description LINE...",
4792 NO_STR NEIGHBOR_STR NEIGHBOR_ADDR_STR2
4793 "Neighbor specific description\n"
4794 "Up to 80 characters describing this neighbor\n")
4795
4796 /* Neighbor update-source. */
4797 static int peer_update_source_vty(struct vty *vty, const char *peer_str,
4798 const char *source_str)
4799 {
4800 struct peer *peer;
4801 struct prefix p;
4802 union sockunion su;
4803
4804 peer = peer_and_group_lookup_vty(vty, peer_str);
4805 if (!peer)
4806 return CMD_WARNING_CONFIG_FAILED;
4807
4808 if (peer->conf_if)
4809 return CMD_WARNING;
4810
4811 if (source_str) {
4812 if (str2sockunion(source_str, &su) == 0)
4813 peer_update_source_addr_set(peer, &su);
4814 else {
4815 if (str2prefix(source_str, &p)) {
4816 vty_out(vty,
4817 "%% Invalid update-source, remove prefix length \n");
4818 return CMD_WARNING_CONFIG_FAILED;
4819 } else
4820 peer_update_source_if_set(peer, source_str);
4821 }
4822 } else
4823 peer_update_source_unset(peer);
4824
4825 return CMD_SUCCESS;
4826 }
4827
4828 #define BGP_UPDATE_SOURCE_HELP_STR \
4829 "IPv4 address\n" \
4830 "IPv6 address\n" \
4831 "Interface name (requires zebra to be running)\n"
4832
4833 DEFUN (neighbor_update_source,
4834 neighbor_update_source_cmd,
4835 "neighbor <A.B.C.D|X:X::X:X|WORD> update-source <A.B.C.D|X:X::X:X|WORD>",
4836 NEIGHBOR_STR
4837 NEIGHBOR_ADDR_STR2
4838 "Source of routing updates\n"
4839 BGP_UPDATE_SOURCE_HELP_STR)
4840 {
4841 int idx_peer = 1;
4842 int idx_peer_2 = 3;
4843 return peer_update_source_vty(vty, argv[idx_peer]->arg,
4844 argv[idx_peer_2]->arg);
4845 }
4846
4847 DEFUN (no_neighbor_update_source,
4848 no_neighbor_update_source_cmd,
4849 "no neighbor <A.B.C.D|X:X::X:X|WORD> update-source [<A.B.C.D|X:X::X:X|WORD>]",
4850 NO_STR
4851 NEIGHBOR_STR
4852 NEIGHBOR_ADDR_STR2
4853 "Source of routing updates\n"
4854 BGP_UPDATE_SOURCE_HELP_STR)
4855 {
4856 int idx_peer = 2;
4857 return peer_update_source_vty(vty, argv[idx_peer]->arg, NULL);
4858 }
4859
4860 static int peer_default_originate_set_vty(struct vty *vty, const char *peer_str,
4861 afi_t afi, safi_t safi,
4862 const char *rmap, int set)
4863 {
4864 int ret;
4865 struct peer *peer;
4866 struct route_map *route_map;
4867
4868 peer = peer_and_group_lookup_vty(vty, peer_str);
4869 if (!peer)
4870 return CMD_WARNING_CONFIG_FAILED;
4871
4872 if (set) {
4873 route_map = route_map_lookup_warn_noexist(vty, rmap);
4874 ret = peer_default_originate_set(peer, afi, safi,
4875 rmap, route_map);
4876 } else
4877 ret = peer_default_originate_unset(peer, afi, safi);
4878
4879 return bgp_vty_return(vty, ret);
4880 }
4881
4882 /* neighbor default-originate. */
4883 DEFUN (neighbor_default_originate,
4884 neighbor_default_originate_cmd,
4885 "neighbor <A.B.C.D|X:X::X:X|WORD> default-originate",
4886 NEIGHBOR_STR
4887 NEIGHBOR_ADDR_STR2
4888 "Originate default route to this neighbor\n")
4889 {
4890 int idx_peer = 1;
4891 return peer_default_originate_set_vty(vty, argv[idx_peer]->arg,
4892 bgp_node_afi(vty),
4893 bgp_node_safi(vty), NULL, 1);
4894 }
4895
4896 ALIAS_HIDDEN(neighbor_default_originate, neighbor_default_originate_hidden_cmd,
4897 "neighbor <A.B.C.D|X:X::X:X|WORD> default-originate",
4898 NEIGHBOR_STR NEIGHBOR_ADDR_STR2
4899 "Originate default route to this neighbor\n")
4900
4901 DEFUN (neighbor_default_originate_rmap,
4902 neighbor_default_originate_rmap_cmd,
4903 "neighbor <A.B.C.D|X:X::X:X|WORD> default-originate route-map WORD",
4904 NEIGHBOR_STR
4905 NEIGHBOR_ADDR_STR2
4906 "Originate default route to this neighbor\n"
4907 "Route-map to specify criteria to originate default\n"
4908 "route-map name\n")
4909 {
4910 int idx_peer = 1;
4911 int idx_word = 4;
4912 return peer_default_originate_set_vty(
4913 vty, argv[idx_peer]->arg, bgp_node_afi(vty), bgp_node_safi(vty),
4914 argv[idx_word]->arg, 1);
4915 }
4916
4917 ALIAS_HIDDEN(
4918 neighbor_default_originate_rmap,
4919 neighbor_default_originate_rmap_hidden_cmd,
4920 "neighbor <A.B.C.D|X:X::X:X|WORD> default-originate route-map WORD",
4921 NEIGHBOR_STR NEIGHBOR_ADDR_STR2
4922 "Originate default route to this neighbor\n"
4923 "Route-map to specify criteria to originate default\n"
4924 "route-map name\n")
4925
4926 DEFUN (no_neighbor_default_originate,
4927 no_neighbor_default_originate_cmd,
4928 "no neighbor <A.B.C.D|X:X::X:X|WORD> default-originate [route-map WORD]",
4929 NO_STR
4930 NEIGHBOR_STR
4931 NEIGHBOR_ADDR_STR2
4932 "Originate default route to this neighbor\n"
4933 "Route-map to specify criteria to originate default\n"
4934 "route-map name\n")
4935 {
4936 int idx_peer = 2;
4937 return peer_default_originate_set_vty(vty, argv[idx_peer]->arg,
4938 bgp_node_afi(vty),
4939 bgp_node_safi(vty), NULL, 0);
4940 }
4941
4942 ALIAS_HIDDEN(
4943 no_neighbor_default_originate, no_neighbor_default_originate_hidden_cmd,
4944 "no neighbor <A.B.C.D|X:X::X:X|WORD> default-originate [route-map WORD]",
4945 NO_STR NEIGHBOR_STR NEIGHBOR_ADDR_STR2
4946 "Originate default route to this neighbor\n"
4947 "Route-map to specify criteria to originate default\n"
4948 "route-map name\n")
4949
4950
4951 /* Set neighbor's BGP port. */
4952 static int peer_port_vty(struct vty *vty, const char *ip_str, int afi,
4953 const char *port_str)
4954 {
4955 struct peer *peer;
4956 uint16_t port;
4957 struct servent *sp;
4958
4959 peer = peer_lookup_vty(vty, ip_str);
4960 if (!peer)
4961 return CMD_WARNING_CONFIG_FAILED;
4962
4963 if (!port_str) {
4964 sp = getservbyname("bgp", "tcp");
4965 port = (sp == NULL) ? BGP_PORT_DEFAULT : ntohs(sp->s_port);
4966 } else {
4967 port = strtoul(port_str, NULL, 10);
4968 }
4969
4970 peer_port_set(peer, port);
4971
4972 return CMD_SUCCESS;
4973 }
4974
4975 /* Set specified peer's BGP port. */
4976 DEFUN (neighbor_port,
4977 neighbor_port_cmd,
4978 "neighbor <A.B.C.D|X:X::X:X> port (0-65535)",
4979 NEIGHBOR_STR
4980 NEIGHBOR_ADDR_STR
4981 "Neighbor's BGP port\n"
4982 "TCP port number\n")
4983 {
4984 int idx_ip = 1;
4985 int idx_number = 3;
4986 return peer_port_vty(vty, argv[idx_ip]->arg, AFI_IP,
4987 argv[idx_number]->arg);
4988 }
4989
4990 DEFUN (no_neighbor_port,
4991 no_neighbor_port_cmd,
4992 "no neighbor <A.B.C.D|X:X::X:X> port [(0-65535)]",
4993 NO_STR
4994 NEIGHBOR_STR
4995 NEIGHBOR_ADDR_STR
4996 "Neighbor's BGP port\n"
4997 "TCP port number\n")
4998 {
4999 int idx_ip = 2;
5000 return peer_port_vty(vty, argv[idx_ip]->arg, AFI_IP, NULL);
5001 }
5002
5003
5004 /* neighbor weight. */
5005 static int peer_weight_set_vty(struct vty *vty, const char *ip_str, afi_t afi,
5006 safi_t safi, const char *weight_str)
5007 {
5008 int ret;
5009 struct peer *peer;
5010 unsigned long weight;
5011
5012 peer = peer_and_group_lookup_vty(vty, ip_str);
5013 if (!peer)
5014 return CMD_WARNING_CONFIG_FAILED;
5015
5016 weight = strtoul(weight_str, NULL, 10);
5017
5018 ret = peer_weight_set(peer, afi, safi, weight);
5019 return bgp_vty_return(vty, ret);
5020 }
5021
5022 static int peer_weight_unset_vty(struct vty *vty, const char *ip_str, afi_t afi,
5023 safi_t safi)
5024 {
5025 int ret;
5026 struct peer *peer;
5027
5028 peer = peer_and_group_lookup_vty(vty, ip_str);
5029 if (!peer)
5030 return CMD_WARNING_CONFIG_FAILED;
5031
5032 ret = peer_weight_unset(peer, afi, safi);
5033 return bgp_vty_return(vty, ret);
5034 }
5035
5036 DEFUN (neighbor_weight,
5037 neighbor_weight_cmd,
5038 "neighbor <A.B.C.D|X:X::X:X|WORD> weight (0-65535)",
5039 NEIGHBOR_STR
5040 NEIGHBOR_ADDR_STR2
5041 "Set default weight for routes from this neighbor\n"
5042 "default weight\n")
5043 {
5044 int idx_peer = 1;
5045 int idx_number = 3;
5046 return peer_weight_set_vty(vty, argv[idx_peer]->arg, bgp_node_afi(vty),
5047 bgp_node_safi(vty), argv[idx_number]->arg);
5048 }
5049
5050 ALIAS_HIDDEN(neighbor_weight, neighbor_weight_hidden_cmd,
5051 "neighbor <A.B.C.D|X:X::X:X|WORD> weight (0-65535)",
5052 NEIGHBOR_STR NEIGHBOR_ADDR_STR2
5053 "Set default weight for routes from this neighbor\n"
5054 "default weight\n")
5055
5056 DEFUN (no_neighbor_weight,
5057 no_neighbor_weight_cmd,
5058 "no neighbor <A.B.C.D|X:X::X:X|WORD> weight [(0-65535)]",
5059 NO_STR
5060 NEIGHBOR_STR
5061 NEIGHBOR_ADDR_STR2
5062 "Set default weight for routes from this neighbor\n"
5063 "default weight\n")
5064 {
5065 int idx_peer = 2;
5066 return peer_weight_unset_vty(vty, argv[idx_peer]->arg,
5067 bgp_node_afi(vty), bgp_node_safi(vty));
5068 }
5069
5070 ALIAS_HIDDEN(no_neighbor_weight, no_neighbor_weight_hidden_cmd,
5071 "no neighbor <A.B.C.D|X:X::X:X|WORD> weight [(0-65535)]",
5072 NO_STR NEIGHBOR_STR NEIGHBOR_ADDR_STR2
5073 "Set default weight for routes from this neighbor\n"
5074 "default weight\n")
5075
5076
5077 /* Override capability negotiation. */
5078 DEFUN (neighbor_override_capability,
5079 neighbor_override_capability_cmd,
5080 "neighbor <A.B.C.D|X:X::X:X|WORD> override-capability",
5081 NEIGHBOR_STR
5082 NEIGHBOR_ADDR_STR2
5083 "Override capability negotiation result\n")
5084 {
5085 int idx_peer = 1;
5086 return peer_flag_set_vty(vty, argv[idx_peer]->arg,
5087 PEER_FLAG_OVERRIDE_CAPABILITY);
5088 }
5089
5090 DEFUN (no_neighbor_override_capability,
5091 no_neighbor_override_capability_cmd,
5092 "no neighbor <A.B.C.D|X:X::X:X|WORD> override-capability",
5093 NO_STR
5094 NEIGHBOR_STR
5095 NEIGHBOR_ADDR_STR2
5096 "Override capability negotiation result\n")
5097 {
5098 int idx_peer = 2;
5099 return peer_flag_unset_vty(vty, argv[idx_peer]->arg,
5100 PEER_FLAG_OVERRIDE_CAPABILITY);
5101 }
5102
5103 DEFUN (neighbor_strict_capability,
5104 neighbor_strict_capability_cmd,
5105 "neighbor <A.B.C.D|X:X::X:X|WORD> strict-capability-match",
5106 NEIGHBOR_STR
5107 NEIGHBOR_ADDR_STR2
5108 "Strict capability negotiation match\n")
5109 {
5110 int idx_peer = 1;
5111
5112 return peer_flag_set_vty(vty, argv[idx_peer]->arg,
5113 PEER_FLAG_STRICT_CAP_MATCH);
5114 }
5115
5116 DEFUN (no_neighbor_strict_capability,
5117 no_neighbor_strict_capability_cmd,
5118 "no neighbor <A.B.C.D|X:X::X:X|WORD> strict-capability-match",
5119 NO_STR
5120 NEIGHBOR_STR
5121 NEIGHBOR_ADDR_STR2
5122 "Strict capability negotiation match\n")
5123 {
5124 int idx_peer = 2;
5125
5126 return peer_flag_unset_vty(vty, argv[idx_peer]->arg,
5127 PEER_FLAG_STRICT_CAP_MATCH);
5128 }
5129
5130 static int peer_timers_set_vty(struct vty *vty, const char *ip_str,
5131 const char *keep_str, const char *hold_str)
5132 {
5133 int ret;
5134 struct peer *peer;
5135 uint32_t keepalive;
5136 uint32_t holdtime;
5137
5138 peer = peer_and_group_lookup_vty(vty, ip_str);
5139 if (!peer)
5140 return CMD_WARNING_CONFIG_FAILED;
5141
5142 keepalive = strtoul(keep_str, NULL, 10);
5143 holdtime = strtoul(hold_str, NULL, 10);
5144
5145 ret = peer_timers_set(peer, keepalive, holdtime);
5146
5147 return bgp_vty_return(vty, ret);
5148 }
5149
5150 static int peer_timers_unset_vty(struct vty *vty, const char *ip_str)
5151 {
5152 int ret;
5153 struct peer *peer;
5154
5155 peer = peer_and_group_lookup_vty(vty, ip_str);
5156 if (!peer)
5157 return CMD_WARNING_CONFIG_FAILED;
5158
5159 ret = peer_timers_unset(peer);
5160
5161 return bgp_vty_return(vty, ret);
5162 }
5163
5164 DEFUN (neighbor_timers,
5165 neighbor_timers_cmd,
5166 "neighbor <A.B.C.D|X:X::X:X|WORD> timers (0-65535) (0-65535)",
5167 NEIGHBOR_STR
5168 NEIGHBOR_ADDR_STR2
5169 "BGP per neighbor timers\n"
5170 "Keepalive interval\n"
5171 "Holdtime\n")
5172 {
5173 int idx_peer = 1;
5174 int idx_number = 3;
5175 int idx_number_2 = 4;
5176 return peer_timers_set_vty(vty, argv[idx_peer]->arg,
5177 argv[idx_number]->arg,
5178 argv[idx_number_2]->arg);
5179 }
5180
5181 DEFUN (no_neighbor_timers,
5182 no_neighbor_timers_cmd,
5183 "no neighbor <A.B.C.D|X:X::X:X|WORD> timers [(0-65535) (0-65535)]",
5184 NO_STR
5185 NEIGHBOR_STR
5186 NEIGHBOR_ADDR_STR2
5187 "BGP per neighbor timers\n"
5188 "Keepalive interval\n"
5189 "Holdtime\n")
5190 {
5191 int idx_peer = 2;
5192 return peer_timers_unset_vty(vty, argv[idx_peer]->arg);
5193 }
5194
5195
5196 static int peer_timers_connect_set_vty(struct vty *vty, const char *ip_str,
5197 const char *time_str)
5198 {
5199 int ret;
5200 struct peer *peer;
5201 uint32_t connect;
5202
5203 peer = peer_and_group_lookup_vty(vty, ip_str);
5204 if (!peer)
5205 return CMD_WARNING_CONFIG_FAILED;
5206
5207 connect = strtoul(time_str, NULL, 10);
5208
5209 ret = peer_timers_connect_set(peer, connect);
5210
5211 return bgp_vty_return(vty, ret);
5212 }
5213
5214 static int peer_timers_connect_unset_vty(struct vty *vty, const char *ip_str)
5215 {
5216 int ret;
5217 struct peer *peer;
5218
5219 peer = peer_and_group_lookup_vty(vty, ip_str);
5220 if (!peer)
5221 return CMD_WARNING_CONFIG_FAILED;
5222
5223 ret = peer_timers_connect_unset(peer);
5224
5225 return bgp_vty_return(vty, ret);
5226 }
5227
5228 DEFUN (neighbor_timers_connect,
5229 neighbor_timers_connect_cmd,
5230 "neighbor <A.B.C.D|X:X::X:X|WORD> timers connect (1-65535)",
5231 NEIGHBOR_STR
5232 NEIGHBOR_ADDR_STR2
5233 "BGP per neighbor timers\n"
5234 "BGP connect timer\n"
5235 "Connect timer\n")
5236 {
5237 int idx_peer = 1;
5238 int idx_number = 4;
5239 return peer_timers_connect_set_vty(vty, argv[idx_peer]->arg,
5240 argv[idx_number]->arg);
5241 }
5242
5243 DEFUN (no_neighbor_timers_connect,
5244 no_neighbor_timers_connect_cmd,
5245 "no neighbor <A.B.C.D|X:X::X:X|WORD> timers connect [(1-65535)]",
5246 NO_STR
5247 NEIGHBOR_STR
5248 NEIGHBOR_ADDR_STR2
5249 "BGP per neighbor timers\n"
5250 "BGP connect timer\n"
5251 "Connect timer\n")
5252 {
5253 int idx_peer = 2;
5254 return peer_timers_connect_unset_vty(vty, argv[idx_peer]->arg);
5255 }
5256
5257
5258 static int peer_advertise_interval_vty(struct vty *vty, const char *ip_str,
5259 const char *time_str, int set)
5260 {
5261 int ret;
5262 struct peer *peer;
5263 uint32_t routeadv = 0;
5264
5265 peer = peer_and_group_lookup_vty(vty, ip_str);
5266 if (!peer)
5267 return CMD_WARNING_CONFIG_FAILED;
5268
5269 if (time_str)
5270 routeadv = strtoul(time_str, NULL, 10);
5271
5272 if (set)
5273 ret = peer_advertise_interval_set(peer, routeadv);
5274 else
5275 ret = peer_advertise_interval_unset(peer);
5276
5277 return bgp_vty_return(vty, ret);
5278 }
5279
5280 DEFUN (neighbor_advertise_interval,
5281 neighbor_advertise_interval_cmd,
5282 "neighbor <A.B.C.D|X:X::X:X|WORD> advertisement-interval (0-600)",
5283 NEIGHBOR_STR
5284 NEIGHBOR_ADDR_STR2
5285 "Minimum interval between sending BGP routing updates\n"
5286 "time in seconds\n")
5287 {
5288 int idx_peer = 1;
5289 int idx_number = 3;
5290 return peer_advertise_interval_vty(vty, argv[idx_peer]->arg,
5291 argv[idx_number]->arg, 1);
5292 }
5293
5294 DEFUN (no_neighbor_advertise_interval,
5295 no_neighbor_advertise_interval_cmd,
5296 "no neighbor <A.B.C.D|X:X::X:X|WORD> advertisement-interval [(0-600)]",
5297 NO_STR
5298 NEIGHBOR_STR
5299 NEIGHBOR_ADDR_STR2
5300 "Minimum interval between sending BGP routing updates\n"
5301 "time in seconds\n")
5302 {
5303 int idx_peer = 2;
5304 return peer_advertise_interval_vty(vty, argv[idx_peer]->arg, NULL, 0);
5305 }
5306
5307
5308 /* Time to wait before processing route-map updates */
5309 DEFUN (bgp_set_route_map_delay_timer,
5310 bgp_set_route_map_delay_timer_cmd,
5311 "bgp route-map delay-timer (0-600)",
5312 SET_STR
5313 "BGP route-map delay timer\n"
5314 "Time in secs to wait before processing route-map changes\n"
5315 "0 disables the timer, no route updates happen when route-maps change\n")
5316 {
5317 int idx_number = 3;
5318 uint32_t rmap_delay_timer;
5319
5320 if (argv[idx_number]->arg) {
5321 rmap_delay_timer = strtoul(argv[idx_number]->arg, NULL, 10);
5322 bm->rmap_update_timer = rmap_delay_timer;
5323
5324 /* if the dynamic update handling is being disabled, and a timer
5325 * is
5326 * running, stop the timer and act as if the timer has already
5327 * fired.
5328 */
5329 if (!rmap_delay_timer && bm->t_rmap_update) {
5330 BGP_TIMER_OFF(bm->t_rmap_update);
5331 thread_execute(bm->master, bgp_route_map_update_timer,
5332 NULL, 0);
5333 }
5334 return CMD_SUCCESS;
5335 } else {
5336 vty_out(vty, "%% BGP invalid route-map delay-timer\n");
5337 return CMD_WARNING_CONFIG_FAILED;
5338 }
5339 }
5340
5341 DEFUN (no_bgp_set_route_map_delay_timer,
5342 no_bgp_set_route_map_delay_timer_cmd,
5343 "no bgp route-map delay-timer [(0-600)]",
5344 NO_STR
5345 BGP_STR
5346 "Default BGP route-map delay timer\n"
5347 "Reset to default time to wait for processing route-map changes\n"
5348 "0 disables the timer, no route updates happen when route-maps change\n")
5349 {
5350
5351 bm->rmap_update_timer = RMAP_DEFAULT_UPDATE_TIMER;
5352
5353 return CMD_SUCCESS;
5354 }
5355
5356
5357 /* neighbor interface */
5358 static int peer_interface_vty(struct vty *vty, const char *ip_str,
5359 const char *str)
5360 {
5361 struct peer *peer;
5362
5363 peer = peer_lookup_vty(vty, ip_str);
5364 if (!peer || peer->conf_if) {
5365 vty_out(vty, "%% BGP invalid peer %s\n", ip_str);
5366 return CMD_WARNING_CONFIG_FAILED;
5367 }
5368
5369 if (str)
5370 peer_interface_set(peer, str);
5371 else
5372 peer_interface_unset(peer);
5373
5374 return CMD_SUCCESS;
5375 }
5376
5377 DEFUN (neighbor_interface,
5378 neighbor_interface_cmd,
5379 "neighbor <A.B.C.D|X:X::X:X> interface WORD",
5380 NEIGHBOR_STR
5381 NEIGHBOR_ADDR_STR
5382 "Interface\n"
5383 "Interface name\n")
5384 {
5385 int idx_ip = 1;
5386 int idx_word = 3;
5387 return peer_interface_vty(vty, argv[idx_ip]->arg, argv[idx_word]->arg);
5388 }
5389
5390 DEFUN (no_neighbor_interface,
5391 no_neighbor_interface_cmd,
5392 "no neighbor <A.B.C.D|X:X::X:X|WORD> interface WORD",
5393 NO_STR
5394 NEIGHBOR_STR
5395 NEIGHBOR_ADDR_STR2
5396 "Interface\n"
5397 "Interface name\n")
5398 {
5399 int idx_peer = 2;
5400 return peer_interface_vty(vty, argv[idx_peer]->arg, NULL);
5401 }
5402
5403 DEFUN (neighbor_distribute_list,
5404 neighbor_distribute_list_cmd,
5405 "neighbor <A.B.C.D|X:X::X:X|WORD> distribute-list <(1-199)|(1300-2699)|WORD> <in|out>",
5406 NEIGHBOR_STR
5407 NEIGHBOR_ADDR_STR2
5408 "Filter updates to/from this neighbor\n"
5409 "IP access-list number\n"
5410 "IP access-list number (expanded range)\n"
5411 "IP Access-list name\n"
5412 "Filter incoming updates\n"
5413 "Filter outgoing updates\n")
5414 {
5415 int idx_peer = 1;
5416 int idx_acl = 3;
5417 int direct, ret;
5418 struct peer *peer;
5419
5420 const char *pstr = argv[idx_peer]->arg;
5421 const char *acl = argv[idx_acl]->arg;
5422 const char *inout = argv[argc - 1]->text;
5423
5424 peer = peer_and_group_lookup_vty(vty, pstr);
5425 if (!peer)
5426 return CMD_WARNING_CONFIG_FAILED;
5427
5428 /* Check filter direction. */
5429 direct = strmatch(inout, "in") ? FILTER_IN : FILTER_OUT;
5430 ret = peer_distribute_set(peer, bgp_node_afi(vty), bgp_node_safi(vty),
5431 direct, acl);
5432
5433 return bgp_vty_return(vty, ret);
5434 }
5435
5436 ALIAS_HIDDEN(
5437 neighbor_distribute_list, neighbor_distribute_list_hidden_cmd,
5438 "neighbor <A.B.C.D|X:X::X:X|WORD> distribute-list <(1-199)|(1300-2699)|WORD> <in|out>",
5439 NEIGHBOR_STR NEIGHBOR_ADDR_STR2
5440 "Filter updates to/from this neighbor\n"
5441 "IP access-list number\n"
5442 "IP access-list number (expanded range)\n"
5443 "IP Access-list name\n"
5444 "Filter incoming updates\n"
5445 "Filter outgoing updates\n")
5446
5447 DEFUN (no_neighbor_distribute_list,
5448 no_neighbor_distribute_list_cmd,
5449 "no neighbor <A.B.C.D|X:X::X:X|WORD> distribute-list <(1-199)|(1300-2699)|WORD> <in|out>",
5450 NO_STR
5451 NEIGHBOR_STR
5452 NEIGHBOR_ADDR_STR2
5453 "Filter updates to/from this neighbor\n"
5454 "IP access-list number\n"
5455 "IP access-list number (expanded range)\n"
5456 "IP Access-list name\n"
5457 "Filter incoming updates\n"
5458 "Filter outgoing updates\n")
5459 {
5460 int idx_peer = 2;
5461 int direct, ret;
5462 struct peer *peer;
5463
5464 const char *pstr = argv[idx_peer]->arg;
5465 const char *inout = argv[argc - 1]->text;
5466
5467 peer = peer_and_group_lookup_vty(vty, pstr);
5468 if (!peer)
5469 return CMD_WARNING_CONFIG_FAILED;
5470
5471 /* Check filter direction. */
5472 direct = strmatch(inout, "in") ? FILTER_IN : FILTER_OUT;
5473 ret = peer_distribute_unset(peer, bgp_node_afi(vty), bgp_node_safi(vty),
5474 direct);
5475
5476 return bgp_vty_return(vty, ret);
5477 }
5478
5479 ALIAS_HIDDEN(
5480 no_neighbor_distribute_list, no_neighbor_distribute_list_hidden_cmd,
5481 "no neighbor <A.B.C.D|X:X::X:X|WORD> distribute-list <(1-199)|(1300-2699)|WORD> <in|out>",
5482 NO_STR NEIGHBOR_STR NEIGHBOR_ADDR_STR2
5483 "Filter updates to/from this neighbor\n"
5484 "IP access-list number\n"
5485 "IP access-list number (expanded range)\n"
5486 "IP Access-list name\n"
5487 "Filter incoming updates\n"
5488 "Filter outgoing updates\n")
5489
5490 /* Set prefix list to the peer. */
5491 static int peer_prefix_list_set_vty(struct vty *vty, const char *ip_str,
5492 afi_t afi, safi_t safi,
5493 const char *name_str,
5494 const char *direct_str)
5495 {
5496 int ret;
5497 int direct = FILTER_IN;
5498 struct peer *peer;
5499
5500 peer = peer_and_group_lookup_vty(vty, ip_str);
5501 if (!peer)
5502 return CMD_WARNING_CONFIG_FAILED;
5503
5504 /* Check filter direction. */
5505 if (strncmp(direct_str, "i", 1) == 0)
5506 direct = FILTER_IN;
5507 else if (strncmp(direct_str, "o", 1) == 0)
5508 direct = FILTER_OUT;
5509
5510 ret = peer_prefix_list_set(peer, afi, safi, direct, name_str);
5511
5512 return bgp_vty_return(vty, ret);
5513 }
5514
5515 static int peer_prefix_list_unset_vty(struct vty *vty, const char *ip_str,
5516 afi_t afi, safi_t safi,
5517 const char *direct_str)
5518 {
5519 int ret;
5520 struct peer *peer;
5521 int direct = FILTER_IN;
5522
5523 peer = peer_and_group_lookup_vty(vty, ip_str);
5524 if (!peer)
5525 return CMD_WARNING_CONFIG_FAILED;
5526
5527 /* Check filter direction. */
5528 if (strncmp(direct_str, "i", 1) == 0)
5529 direct = FILTER_IN;
5530 else if (strncmp(direct_str, "o", 1) == 0)
5531 direct = FILTER_OUT;
5532
5533 ret = peer_prefix_list_unset(peer, afi, safi, direct);
5534
5535 return bgp_vty_return(vty, ret);
5536 }
5537
5538 DEFUN (neighbor_prefix_list,
5539 neighbor_prefix_list_cmd,
5540 "neighbor <A.B.C.D|X:X::X:X|WORD> prefix-list WORD <in|out>",
5541 NEIGHBOR_STR
5542 NEIGHBOR_ADDR_STR2
5543 "Filter updates to/from this neighbor\n"
5544 "Name of a prefix list\n"
5545 "Filter incoming updates\n"
5546 "Filter outgoing updates\n")
5547 {
5548 int idx_peer = 1;
5549 int idx_word = 3;
5550 int idx_in_out = 4;
5551 return peer_prefix_list_set_vty(
5552 vty, argv[idx_peer]->arg, bgp_node_afi(vty), bgp_node_safi(vty),
5553 argv[idx_word]->arg, argv[idx_in_out]->arg);
5554 }
5555
5556 ALIAS_HIDDEN(neighbor_prefix_list, neighbor_prefix_list_hidden_cmd,
5557 "neighbor <A.B.C.D|X:X::X:X|WORD> prefix-list WORD <in|out>",
5558 NEIGHBOR_STR NEIGHBOR_ADDR_STR2
5559 "Filter updates to/from this neighbor\n"
5560 "Name of a prefix list\n"
5561 "Filter incoming updates\n"
5562 "Filter outgoing updates\n")
5563
5564 DEFUN (no_neighbor_prefix_list,
5565 no_neighbor_prefix_list_cmd,
5566 "no neighbor <A.B.C.D|X:X::X:X|WORD> prefix-list WORD <in|out>",
5567 NO_STR
5568 NEIGHBOR_STR
5569 NEIGHBOR_ADDR_STR2
5570 "Filter updates to/from this neighbor\n"
5571 "Name of a prefix list\n"
5572 "Filter incoming updates\n"
5573 "Filter outgoing updates\n")
5574 {
5575 int idx_peer = 2;
5576 int idx_in_out = 5;
5577 return peer_prefix_list_unset_vty(vty, argv[idx_peer]->arg,
5578 bgp_node_afi(vty), bgp_node_safi(vty),
5579 argv[idx_in_out]->arg);
5580 }
5581
5582 ALIAS_HIDDEN(no_neighbor_prefix_list, no_neighbor_prefix_list_hidden_cmd,
5583 "no neighbor <A.B.C.D|X:X::X:X|WORD> prefix-list WORD <in|out>",
5584 NO_STR NEIGHBOR_STR NEIGHBOR_ADDR_STR2
5585 "Filter updates to/from this neighbor\n"
5586 "Name of a prefix list\n"
5587 "Filter incoming updates\n"
5588 "Filter outgoing updates\n")
5589
5590 static int peer_aslist_set_vty(struct vty *vty, const char *ip_str, afi_t afi,
5591 safi_t safi, const char *name_str,
5592 const char *direct_str)
5593 {
5594 int ret;
5595 struct peer *peer;
5596 int direct = FILTER_IN;
5597
5598 peer = peer_and_group_lookup_vty(vty, ip_str);
5599 if (!peer)
5600 return CMD_WARNING_CONFIG_FAILED;
5601
5602 /* Check filter direction. */
5603 if (strncmp(direct_str, "i", 1) == 0)
5604 direct = FILTER_IN;
5605 else if (strncmp(direct_str, "o", 1) == 0)
5606 direct = FILTER_OUT;
5607
5608 ret = peer_aslist_set(peer, afi, safi, direct, name_str);
5609
5610 return bgp_vty_return(vty, ret);
5611 }
5612
5613 static int peer_aslist_unset_vty(struct vty *vty, const char *ip_str, afi_t afi,
5614 safi_t safi, const char *direct_str)
5615 {
5616 int ret;
5617 struct peer *peer;
5618 int direct = FILTER_IN;
5619
5620 peer = peer_and_group_lookup_vty(vty, ip_str);
5621 if (!peer)
5622 return CMD_WARNING_CONFIG_FAILED;
5623
5624 /* Check filter direction. */
5625 if (strncmp(direct_str, "i", 1) == 0)
5626 direct = FILTER_IN;
5627 else if (strncmp(direct_str, "o", 1) == 0)
5628 direct = FILTER_OUT;
5629
5630 ret = peer_aslist_unset(peer, afi, safi, direct);
5631
5632 return bgp_vty_return(vty, ret);
5633 }
5634
5635 DEFUN (neighbor_filter_list,
5636 neighbor_filter_list_cmd,
5637 "neighbor <A.B.C.D|X:X::X:X|WORD> filter-list WORD <in|out>",
5638 NEIGHBOR_STR
5639 NEIGHBOR_ADDR_STR2
5640 "Establish BGP filters\n"
5641 "AS path access-list name\n"
5642 "Filter incoming routes\n"
5643 "Filter outgoing routes\n")
5644 {
5645 int idx_peer = 1;
5646 int idx_word = 3;
5647 int idx_in_out = 4;
5648 return peer_aslist_set_vty(vty, argv[idx_peer]->arg, bgp_node_afi(vty),
5649 bgp_node_safi(vty), argv[idx_word]->arg,
5650 argv[idx_in_out]->arg);
5651 }
5652
5653 ALIAS_HIDDEN(neighbor_filter_list, neighbor_filter_list_hidden_cmd,
5654 "neighbor <A.B.C.D|X:X::X:X|WORD> filter-list WORD <in|out>",
5655 NEIGHBOR_STR NEIGHBOR_ADDR_STR2
5656 "Establish BGP filters\n"
5657 "AS path access-list name\n"
5658 "Filter incoming routes\n"
5659 "Filter outgoing routes\n")
5660
5661 DEFUN (no_neighbor_filter_list,
5662 no_neighbor_filter_list_cmd,
5663 "no neighbor <A.B.C.D|X:X::X:X|WORD> filter-list WORD <in|out>",
5664 NO_STR
5665 NEIGHBOR_STR
5666 NEIGHBOR_ADDR_STR2
5667 "Establish BGP filters\n"
5668 "AS path access-list name\n"
5669 "Filter incoming routes\n"
5670 "Filter outgoing routes\n")
5671 {
5672 int idx_peer = 2;
5673 int idx_in_out = 5;
5674 return peer_aslist_unset_vty(vty, argv[idx_peer]->arg,
5675 bgp_node_afi(vty), bgp_node_safi(vty),
5676 argv[idx_in_out]->arg);
5677 }
5678
5679 ALIAS_HIDDEN(no_neighbor_filter_list, no_neighbor_filter_list_hidden_cmd,
5680 "no neighbor <A.B.C.D|X:X::X:X|WORD> filter-list WORD <in|out>",
5681 NO_STR NEIGHBOR_STR NEIGHBOR_ADDR_STR2
5682 "Establish BGP filters\n"
5683 "AS path access-list name\n"
5684 "Filter incoming routes\n"
5685 "Filter outgoing routes\n")
5686
5687 /* Set route-map to the peer. */
5688 static int peer_route_map_set_vty(struct vty *vty, const char *ip_str,
5689 afi_t afi, safi_t safi, const char *name_str,
5690 const char *direct_str)
5691 {
5692 int ret;
5693 struct peer *peer;
5694 int direct = RMAP_IN;
5695 struct route_map *route_map;
5696
5697 peer = peer_and_group_lookup_vty(vty, ip_str);
5698 if (!peer)
5699 return CMD_WARNING_CONFIG_FAILED;
5700
5701 /* Check filter direction. */
5702 if (strncmp(direct_str, "in", 2) == 0)
5703 direct = RMAP_IN;
5704 else if (strncmp(direct_str, "o", 1) == 0)
5705 direct = RMAP_OUT;
5706
5707 route_map = route_map_lookup_warn_noexist(vty, name_str);
5708 ret = peer_route_map_set(peer, afi, safi, direct, name_str, route_map);
5709
5710 return bgp_vty_return(vty, ret);
5711 }
5712
5713 static int peer_route_map_unset_vty(struct vty *vty, const char *ip_str,
5714 afi_t afi, safi_t safi,
5715 const char *direct_str)
5716 {
5717 int ret;
5718 struct peer *peer;
5719 int direct = RMAP_IN;
5720
5721 peer = peer_and_group_lookup_vty(vty, ip_str);
5722 if (!peer)
5723 return CMD_WARNING_CONFIG_FAILED;
5724
5725 /* Check filter direction. */
5726 if (strncmp(direct_str, "in", 2) == 0)
5727 direct = RMAP_IN;
5728 else if (strncmp(direct_str, "o", 1) == 0)
5729 direct = RMAP_OUT;
5730
5731 ret = peer_route_map_unset(peer, afi, safi, direct);
5732
5733 return bgp_vty_return(vty, ret);
5734 }
5735
5736 DEFUN (neighbor_route_map,
5737 neighbor_route_map_cmd,
5738 "neighbor <A.B.C.D|X:X::X:X|WORD> route-map WORD <in|out>",
5739 NEIGHBOR_STR
5740 NEIGHBOR_ADDR_STR2
5741 "Apply route map to neighbor\n"
5742 "Name of route map\n"
5743 "Apply map to incoming routes\n"
5744 "Apply map to outbound routes\n")
5745 {
5746 int idx_peer = 1;
5747 int idx_word = 3;
5748 int idx_in_out = 4;
5749 return peer_route_map_set_vty(
5750 vty, argv[idx_peer]->arg, bgp_node_afi(vty), bgp_node_safi(vty),
5751 argv[idx_word]->arg, argv[idx_in_out]->arg);
5752 }
5753
5754 ALIAS_HIDDEN(neighbor_route_map, neighbor_route_map_hidden_cmd,
5755 "neighbor <A.B.C.D|X:X::X:X|WORD> route-map WORD <in|out>",
5756 NEIGHBOR_STR NEIGHBOR_ADDR_STR2
5757 "Apply route map to neighbor\n"
5758 "Name of route map\n"
5759 "Apply map to incoming routes\n"
5760 "Apply map to outbound routes\n")
5761
5762 DEFUN (no_neighbor_route_map,
5763 no_neighbor_route_map_cmd,
5764 "no neighbor <A.B.C.D|X:X::X:X|WORD> route-map WORD <in|out>",
5765 NO_STR
5766 NEIGHBOR_STR
5767 NEIGHBOR_ADDR_STR2
5768 "Apply route map to neighbor\n"
5769 "Name of route map\n"
5770 "Apply map to incoming routes\n"
5771 "Apply map to outbound routes\n")
5772 {
5773 int idx_peer = 2;
5774 int idx_in_out = 5;
5775 return peer_route_map_unset_vty(vty, argv[idx_peer]->arg,
5776 bgp_node_afi(vty), bgp_node_safi(vty),
5777 argv[idx_in_out]->arg);
5778 }
5779
5780 ALIAS_HIDDEN(no_neighbor_route_map, no_neighbor_route_map_hidden_cmd,
5781 "no neighbor <A.B.C.D|X:X::X:X|WORD> route-map WORD <in|out>",
5782 NO_STR NEIGHBOR_STR NEIGHBOR_ADDR_STR2
5783 "Apply route map to neighbor\n"
5784 "Name of route map\n"
5785 "Apply map to incoming routes\n"
5786 "Apply map to outbound routes\n")
5787
5788 /* Set unsuppress-map to the peer. */
5789 static int peer_unsuppress_map_set_vty(struct vty *vty, const char *ip_str,
5790 afi_t afi, safi_t safi,
5791 const char *name_str)
5792 {
5793 int ret;
5794 struct peer *peer;
5795 struct route_map *route_map;
5796
5797 peer = peer_and_group_lookup_vty(vty, ip_str);
5798 if (!peer)
5799 return CMD_WARNING_CONFIG_FAILED;
5800
5801 route_map = route_map_lookup_warn_noexist(vty, name_str);
5802 ret = peer_unsuppress_map_set(peer, afi, safi, name_str, route_map);
5803
5804 return bgp_vty_return(vty, ret);
5805 }
5806
5807 /* Unset route-map from the peer. */
5808 static int peer_unsuppress_map_unset_vty(struct vty *vty, const char *ip_str,
5809 afi_t afi, safi_t safi)
5810 {
5811 int ret;
5812 struct peer *peer;
5813
5814 peer = peer_and_group_lookup_vty(vty, ip_str);
5815 if (!peer)
5816 return CMD_WARNING_CONFIG_FAILED;
5817
5818 ret = peer_unsuppress_map_unset(peer, afi, safi);
5819
5820 return bgp_vty_return(vty, ret);
5821 }
5822
5823 DEFUN (neighbor_unsuppress_map,
5824 neighbor_unsuppress_map_cmd,
5825 "neighbor <A.B.C.D|X:X::X:X|WORD> unsuppress-map WORD",
5826 NEIGHBOR_STR
5827 NEIGHBOR_ADDR_STR2
5828 "Route-map to selectively unsuppress suppressed routes\n"
5829 "Name of route map\n")
5830 {
5831 int idx_peer = 1;
5832 int idx_word = 3;
5833 return peer_unsuppress_map_set_vty(
5834 vty, argv[idx_peer]->arg, bgp_node_afi(vty), bgp_node_safi(vty),
5835 argv[idx_word]->arg);
5836 }
5837
5838 ALIAS_HIDDEN(neighbor_unsuppress_map, neighbor_unsuppress_map_hidden_cmd,
5839 "neighbor <A.B.C.D|X:X::X:X|WORD> unsuppress-map WORD",
5840 NEIGHBOR_STR NEIGHBOR_ADDR_STR2
5841 "Route-map to selectively unsuppress suppressed routes\n"
5842 "Name of route map\n")
5843
5844 DEFUN (no_neighbor_unsuppress_map,
5845 no_neighbor_unsuppress_map_cmd,
5846 "no neighbor <A.B.C.D|X:X::X:X|WORD> unsuppress-map WORD",
5847 NO_STR
5848 NEIGHBOR_STR
5849 NEIGHBOR_ADDR_STR2
5850 "Route-map to selectively unsuppress suppressed routes\n"
5851 "Name of route map\n")
5852 {
5853 int idx_peer = 2;
5854 return peer_unsuppress_map_unset_vty(vty, argv[idx_peer]->arg,
5855 bgp_node_afi(vty),
5856 bgp_node_safi(vty));
5857 }
5858
5859 ALIAS_HIDDEN(no_neighbor_unsuppress_map, no_neighbor_unsuppress_map_hidden_cmd,
5860 "no neighbor <A.B.C.D|X:X::X:X|WORD> unsuppress-map WORD",
5861 NO_STR NEIGHBOR_STR NEIGHBOR_ADDR_STR2
5862 "Route-map to selectively unsuppress suppressed routes\n"
5863 "Name of route map\n")
5864
5865 static int peer_maximum_prefix_set_vty(struct vty *vty, const char *ip_str,
5866 afi_t afi, safi_t safi,
5867 const char *num_str,
5868 const char *threshold_str, int warning,
5869 const char *restart_str)
5870 {
5871 int ret;
5872 struct peer *peer;
5873 uint32_t max;
5874 uint8_t threshold;
5875 uint16_t restart;
5876
5877 peer = peer_and_group_lookup_vty(vty, ip_str);
5878 if (!peer)
5879 return CMD_WARNING_CONFIG_FAILED;
5880
5881 max = strtoul(num_str, NULL, 10);
5882 if (threshold_str)
5883 threshold = atoi(threshold_str);
5884 else
5885 threshold = MAXIMUM_PREFIX_THRESHOLD_DEFAULT;
5886
5887 if (restart_str)
5888 restart = atoi(restart_str);
5889 else
5890 restart = 0;
5891
5892 ret = peer_maximum_prefix_set(peer, afi, safi, max, threshold, warning,
5893 restart);
5894
5895 return bgp_vty_return(vty, ret);
5896 }
5897
5898 static int peer_maximum_prefix_unset_vty(struct vty *vty, const char *ip_str,
5899 afi_t afi, safi_t safi)
5900 {
5901 int ret;
5902 struct peer *peer;
5903
5904 peer = peer_and_group_lookup_vty(vty, ip_str);
5905 if (!peer)
5906 return CMD_WARNING_CONFIG_FAILED;
5907
5908 ret = peer_maximum_prefix_unset(peer, afi, safi);
5909
5910 return bgp_vty_return(vty, ret);
5911 }
5912
5913 /* Maximum number of prefix configuration. prefix count is different
5914 for each peer configuration. So this configuration can be set for
5915 each peer configuration. */
5916 DEFUN (neighbor_maximum_prefix,
5917 neighbor_maximum_prefix_cmd,
5918 "neighbor <A.B.C.D|X:X::X:X|WORD> maximum-prefix (1-4294967295)",
5919 NEIGHBOR_STR
5920 NEIGHBOR_ADDR_STR2
5921 "Maximum number of prefix accept from this peer\n"
5922 "maximum no. of prefix limit\n")
5923 {
5924 int idx_peer = 1;
5925 int idx_number = 3;
5926 return peer_maximum_prefix_set_vty(
5927 vty, argv[idx_peer]->arg, bgp_node_afi(vty), bgp_node_safi(vty),
5928 argv[idx_number]->arg, NULL, 0, NULL);
5929 }
5930
5931 ALIAS_HIDDEN(neighbor_maximum_prefix, neighbor_maximum_prefix_hidden_cmd,
5932 "neighbor <A.B.C.D|X:X::X:X|WORD> maximum-prefix (1-4294967295)",
5933 NEIGHBOR_STR NEIGHBOR_ADDR_STR2
5934 "Maximum number of prefix accept from this peer\n"
5935 "maximum no. of prefix limit\n")
5936
5937 DEFUN (neighbor_maximum_prefix_threshold,
5938 neighbor_maximum_prefix_threshold_cmd,
5939 "neighbor <A.B.C.D|X:X::X:X|WORD> maximum-prefix (1-4294967295) (1-100)",
5940 NEIGHBOR_STR
5941 NEIGHBOR_ADDR_STR2
5942 "Maximum number of prefix accept from this peer\n"
5943 "maximum no. of prefix limit\n"
5944 "Threshold value (%) at which to generate a warning msg\n")
5945 {
5946 int idx_peer = 1;
5947 int idx_number = 3;
5948 int idx_number_2 = 4;
5949 return peer_maximum_prefix_set_vty(
5950 vty, argv[idx_peer]->arg, bgp_node_afi(vty), bgp_node_safi(vty),
5951 argv[idx_number]->arg, argv[idx_number_2]->arg, 0, NULL);
5952 }
5953
5954 ALIAS_HIDDEN(
5955 neighbor_maximum_prefix_threshold,
5956 neighbor_maximum_prefix_threshold_hidden_cmd,
5957 "neighbor <A.B.C.D|X:X::X:X|WORD> maximum-prefix (1-4294967295) (1-100)",
5958 NEIGHBOR_STR NEIGHBOR_ADDR_STR2
5959 "Maximum number of prefix accept from this peer\n"
5960 "maximum no. of prefix limit\n"
5961 "Threshold value (%) at which to generate a warning msg\n")
5962
5963 DEFUN (neighbor_maximum_prefix_warning,
5964 neighbor_maximum_prefix_warning_cmd,
5965 "neighbor <A.B.C.D|X:X::X:X|WORD> maximum-prefix (1-4294967295) warning-only",
5966 NEIGHBOR_STR
5967 NEIGHBOR_ADDR_STR2
5968 "Maximum number of prefix accept from this peer\n"
5969 "maximum no. of prefix limit\n"
5970 "Only give warning message when limit is exceeded\n")
5971 {
5972 int idx_peer = 1;
5973 int idx_number = 3;
5974 return peer_maximum_prefix_set_vty(
5975 vty, argv[idx_peer]->arg, bgp_node_afi(vty), bgp_node_safi(vty),
5976 argv[idx_number]->arg, NULL, 1, NULL);
5977 }
5978
5979 ALIAS_HIDDEN(
5980 neighbor_maximum_prefix_warning,
5981 neighbor_maximum_prefix_warning_hidden_cmd,
5982 "neighbor <A.B.C.D|X:X::X:X|WORD> maximum-prefix (1-4294967295) warning-only",
5983 NEIGHBOR_STR NEIGHBOR_ADDR_STR2
5984 "Maximum number of prefix accept from this peer\n"
5985 "maximum no. of prefix limit\n"
5986 "Only give warning message when limit is exceeded\n")
5987
5988 DEFUN (neighbor_maximum_prefix_threshold_warning,
5989 neighbor_maximum_prefix_threshold_warning_cmd,
5990 "neighbor <A.B.C.D|X:X::X:X|WORD> maximum-prefix (1-4294967295) (1-100) warning-only",
5991 NEIGHBOR_STR
5992 NEIGHBOR_ADDR_STR2
5993 "Maximum number of prefix accept from this peer\n"
5994 "maximum no. of prefix limit\n"
5995 "Threshold value (%) at which to generate a warning msg\n"
5996 "Only give warning message when limit is exceeded\n")
5997 {
5998 int idx_peer = 1;
5999 int idx_number = 3;
6000 int idx_number_2 = 4;
6001 return peer_maximum_prefix_set_vty(
6002 vty, argv[idx_peer]->arg, bgp_node_afi(vty), bgp_node_safi(vty),
6003 argv[idx_number]->arg, argv[idx_number_2]->arg, 1, NULL);
6004 }
6005
6006 ALIAS_HIDDEN(
6007 neighbor_maximum_prefix_threshold_warning,
6008 neighbor_maximum_prefix_threshold_warning_hidden_cmd,
6009 "neighbor <A.B.C.D|X:X::X:X|WORD> maximum-prefix (1-4294967295) (1-100) warning-only",
6010 NEIGHBOR_STR NEIGHBOR_ADDR_STR2
6011 "Maximum number of prefix accept from this peer\n"
6012 "maximum no. of prefix limit\n"
6013 "Threshold value (%) at which to generate a warning msg\n"
6014 "Only give warning message when limit is exceeded\n")
6015
6016 DEFUN (neighbor_maximum_prefix_restart,
6017 neighbor_maximum_prefix_restart_cmd,
6018 "neighbor <A.B.C.D|X:X::X:X|WORD> maximum-prefix (1-4294967295) restart (1-65535)",
6019 NEIGHBOR_STR
6020 NEIGHBOR_ADDR_STR2
6021 "Maximum number of prefix accept from this peer\n"
6022 "maximum no. of prefix limit\n"
6023 "Restart bgp connection after limit is exceeded\n"
6024 "Restart interval in minutes\n")
6025 {
6026 int idx_peer = 1;
6027 int idx_number = 3;
6028 int idx_number_2 = 5;
6029 return peer_maximum_prefix_set_vty(
6030 vty, argv[idx_peer]->arg, bgp_node_afi(vty), bgp_node_safi(vty),
6031 argv[idx_number]->arg, NULL, 0, argv[idx_number_2]->arg);
6032 }
6033
6034 ALIAS_HIDDEN(
6035 neighbor_maximum_prefix_restart,
6036 neighbor_maximum_prefix_restart_hidden_cmd,
6037 "neighbor <A.B.C.D|X:X::X:X|WORD> maximum-prefix (1-4294967295) restart (1-65535)",
6038 NEIGHBOR_STR NEIGHBOR_ADDR_STR2
6039 "Maximum number of prefix accept from this peer\n"
6040 "maximum no. of prefix limit\n"
6041 "Restart bgp connection after limit is exceeded\n"
6042 "Restart interval in minutes\n")
6043
6044 DEFUN (neighbor_maximum_prefix_threshold_restart,
6045 neighbor_maximum_prefix_threshold_restart_cmd,
6046 "neighbor <A.B.C.D|X:X::X:X|WORD> maximum-prefix (1-4294967295) (1-100) restart (1-65535)",
6047 NEIGHBOR_STR
6048 NEIGHBOR_ADDR_STR2
6049 "Maximum number of prefixes to accept from this peer\n"
6050 "maximum no. of prefix limit\n"
6051 "Threshold value (%) at which to generate a warning msg\n"
6052 "Restart bgp connection after limit is exceeded\n"
6053 "Restart interval in minutes\n")
6054 {
6055 int idx_peer = 1;
6056 int idx_number = 3;
6057 int idx_number_2 = 4;
6058 int idx_number_3 = 6;
6059 return peer_maximum_prefix_set_vty(
6060 vty, argv[idx_peer]->arg, bgp_node_afi(vty), bgp_node_safi(vty),
6061 argv[idx_number]->arg, argv[idx_number_2]->arg, 0,
6062 argv[idx_number_3]->arg);
6063 }
6064
6065 ALIAS_HIDDEN(
6066 neighbor_maximum_prefix_threshold_restart,
6067 neighbor_maximum_prefix_threshold_restart_hidden_cmd,
6068 "neighbor <A.B.C.D|X:X::X:X|WORD> maximum-prefix (1-4294967295) (1-100) restart (1-65535)",
6069 NEIGHBOR_STR NEIGHBOR_ADDR_STR2
6070 "Maximum number of prefixes to accept from this peer\n"
6071 "maximum no. of prefix limit\n"
6072 "Threshold value (%) at which to generate a warning msg\n"
6073 "Restart bgp connection after limit is exceeded\n"
6074 "Restart interval in minutes\n")
6075
6076 DEFUN (no_neighbor_maximum_prefix,
6077 no_neighbor_maximum_prefix_cmd,
6078 "no neighbor <A.B.C.D|X:X::X:X|WORD> maximum-prefix [(1-4294967295) [(1-100)] [restart (1-65535)] [warning-only]]",
6079 NO_STR
6080 NEIGHBOR_STR
6081 NEIGHBOR_ADDR_STR2
6082 "Maximum number of prefixes to accept from this peer\n"
6083 "maximum no. of prefix limit\n"
6084 "Threshold value (%) at which to generate a warning msg\n"
6085 "Restart bgp connection after limit is exceeded\n"
6086 "Restart interval in minutes\n"
6087 "Only give warning message when limit is exceeded\n")
6088 {
6089 int idx_peer = 2;
6090 return peer_maximum_prefix_unset_vty(vty, argv[idx_peer]->arg,
6091 bgp_node_afi(vty),
6092 bgp_node_safi(vty));
6093 }
6094
6095 ALIAS_HIDDEN(
6096 no_neighbor_maximum_prefix, no_neighbor_maximum_prefix_hidden_cmd,
6097 "no neighbor <A.B.C.D|X:X::X:X|WORD> maximum-prefix [(1-4294967295) [(1-100)] [restart (1-65535)] [warning-only]]",
6098 NO_STR NEIGHBOR_STR NEIGHBOR_ADDR_STR2
6099 "Maximum number of prefixes to accept from this peer\n"
6100 "maximum no. of prefix limit\n"
6101 "Threshold value (%) at which to generate a warning msg\n"
6102 "Restart bgp connection after limit is exceeded\n"
6103 "Restart interval in minutes\n"
6104 "Only give warning message when limit is exceeded\n")
6105
6106
6107 /* "neighbor allowas-in" */
6108 DEFUN (neighbor_allowas_in,
6109 neighbor_allowas_in_cmd,
6110 "neighbor <A.B.C.D|X:X::X:X|WORD> allowas-in [<(1-10)|origin>]",
6111 NEIGHBOR_STR
6112 NEIGHBOR_ADDR_STR2
6113 "Accept as-path with my AS present in it\n"
6114 "Number of occurences of AS number\n"
6115 "Only accept my AS in the as-path if the route was originated in my AS\n")
6116 {
6117 int idx_peer = 1;
6118 int idx_number_origin = 3;
6119 int ret;
6120 int origin = 0;
6121 struct peer *peer;
6122 int allow_num = 0;
6123
6124 peer = peer_and_group_lookup_vty(vty, argv[idx_peer]->arg);
6125 if (!peer)
6126 return CMD_WARNING_CONFIG_FAILED;
6127
6128 if (argc <= idx_number_origin)
6129 allow_num = 3;
6130 else {
6131 if (argv[idx_number_origin]->type == WORD_TKN)
6132 origin = 1;
6133 else
6134 allow_num = atoi(argv[idx_number_origin]->arg);
6135 }
6136
6137 ret = peer_allowas_in_set(peer, bgp_node_afi(vty), bgp_node_safi(vty),
6138 allow_num, origin);
6139
6140 return bgp_vty_return(vty, ret);
6141 }
6142
6143 ALIAS_HIDDEN(
6144 neighbor_allowas_in, neighbor_allowas_in_hidden_cmd,
6145 "neighbor <A.B.C.D|X:X::X:X|WORD> allowas-in [<(1-10)|origin>]",
6146 NEIGHBOR_STR NEIGHBOR_ADDR_STR2
6147 "Accept as-path with my AS present in it\n"
6148 "Number of occurences of AS number\n"
6149 "Only accept my AS in the as-path if the route was originated in my AS\n")
6150
6151 DEFUN (no_neighbor_allowas_in,
6152 no_neighbor_allowas_in_cmd,
6153 "no neighbor <A.B.C.D|X:X::X:X|WORD> allowas-in [<(1-10)|origin>]",
6154 NO_STR
6155 NEIGHBOR_STR
6156 NEIGHBOR_ADDR_STR2
6157 "allow local ASN appears in aspath attribute\n"
6158 "Number of occurences of AS number\n"
6159 "Only accept my AS in the as-path if the route was originated in my AS\n")
6160 {
6161 int idx_peer = 2;
6162 int ret;
6163 struct peer *peer;
6164
6165 peer = peer_and_group_lookup_vty(vty, argv[idx_peer]->arg);
6166 if (!peer)
6167 return CMD_WARNING_CONFIG_FAILED;
6168
6169 ret = peer_allowas_in_unset(peer, bgp_node_afi(vty),
6170 bgp_node_safi(vty));
6171
6172 return bgp_vty_return(vty, ret);
6173 }
6174
6175 ALIAS_HIDDEN(
6176 no_neighbor_allowas_in, no_neighbor_allowas_in_hidden_cmd,
6177 "no neighbor <A.B.C.D|X:X::X:X|WORD> allowas-in [<(1-10)|origin>]",
6178 NO_STR NEIGHBOR_STR NEIGHBOR_ADDR_STR2
6179 "allow local ASN appears in aspath attribute\n"
6180 "Number of occurences of AS number\n"
6181 "Only accept my AS in the as-path if the route was originated in my AS\n")
6182
6183 DEFUN (neighbor_ttl_security,
6184 neighbor_ttl_security_cmd,
6185 "neighbor <A.B.C.D|X:X::X:X|WORD> ttl-security hops (1-254)",
6186 NEIGHBOR_STR
6187 NEIGHBOR_ADDR_STR2
6188 "BGP ttl-security parameters\n"
6189 "Specify the maximum number of hops to the BGP peer\n"
6190 "Number of hops to BGP peer\n")
6191 {
6192 int idx_peer = 1;
6193 int idx_number = 4;
6194 struct peer *peer;
6195 int gtsm_hops;
6196
6197 peer = peer_and_group_lookup_vty(vty, argv[idx_peer]->arg);
6198 if (!peer)
6199 return CMD_WARNING_CONFIG_FAILED;
6200
6201 gtsm_hops = strtoul(argv[idx_number]->arg, NULL, 10);
6202
6203 /*
6204 * If 'neighbor swpX', then this is for directly connected peers,
6205 * we should not accept a ttl-security hops value greater than 1.
6206 */
6207 if (peer->conf_if && (gtsm_hops > 1)) {
6208 vty_out(vty,
6209 "%s is directly connected peer, hops cannot exceed 1\n",
6210 argv[idx_peer]->arg);
6211 return CMD_WARNING_CONFIG_FAILED;
6212 }
6213
6214 return bgp_vty_return(vty, peer_ttl_security_hops_set(peer, gtsm_hops));
6215 }
6216
6217 DEFUN (no_neighbor_ttl_security,
6218 no_neighbor_ttl_security_cmd,
6219 "no neighbor <A.B.C.D|X:X::X:X|WORD> ttl-security hops (1-254)",
6220 NO_STR
6221 NEIGHBOR_STR
6222 NEIGHBOR_ADDR_STR2
6223 "BGP ttl-security parameters\n"
6224 "Specify the maximum number of hops to the BGP peer\n"
6225 "Number of hops to BGP peer\n")
6226 {
6227 int idx_peer = 2;
6228 struct peer *peer;
6229
6230 peer = peer_and_group_lookup_vty(vty, argv[idx_peer]->arg);
6231 if (!peer)
6232 return CMD_WARNING_CONFIG_FAILED;
6233
6234 return bgp_vty_return(vty, peer_ttl_security_hops_unset(peer));
6235 }
6236
6237 DEFUN (neighbor_addpath_tx_all_paths,
6238 neighbor_addpath_tx_all_paths_cmd,
6239 "neighbor <A.B.C.D|X:X::X:X|WORD> addpath-tx-all-paths",
6240 NEIGHBOR_STR
6241 NEIGHBOR_ADDR_STR2
6242 "Use addpath to advertise all paths to a neighbor\n")
6243 {
6244 int idx_peer = 1;
6245 struct peer *peer;
6246
6247 peer = peer_and_group_lookup_vty(vty, argv[idx_peer]->arg);
6248 if (!peer)
6249 return CMD_WARNING_CONFIG_FAILED;
6250
6251 bgp_addpath_set_peer_type(peer, bgp_node_afi(vty), bgp_node_safi(vty),
6252 BGP_ADDPATH_ALL);
6253 return CMD_SUCCESS;
6254 }
6255
6256 ALIAS_HIDDEN(neighbor_addpath_tx_all_paths,
6257 neighbor_addpath_tx_all_paths_hidden_cmd,
6258 "neighbor <A.B.C.D|X:X::X:X|WORD> addpath-tx-all-paths",
6259 NEIGHBOR_STR NEIGHBOR_ADDR_STR2
6260 "Use addpath to advertise all paths to a neighbor\n")
6261
6262 DEFUN (no_neighbor_addpath_tx_all_paths,
6263 no_neighbor_addpath_tx_all_paths_cmd,
6264 "no neighbor <A.B.C.D|X:X::X:X|WORD> addpath-tx-all-paths",
6265 NO_STR
6266 NEIGHBOR_STR
6267 NEIGHBOR_ADDR_STR2
6268 "Use addpath to advertise all paths to a neighbor\n")
6269 {
6270 int idx_peer = 2;
6271 struct peer *peer;
6272
6273 peer = peer_and_group_lookup_vty(vty, argv[idx_peer]->arg);
6274 if (!peer)
6275 return CMD_WARNING_CONFIG_FAILED;
6276
6277 if (peer->addpath_type[bgp_node_afi(vty)][bgp_node_safi(vty)]
6278 != BGP_ADDPATH_ALL) {
6279 vty_out(vty,
6280 "%% Peer not currently configured to transmit all paths.");
6281 return CMD_WARNING_CONFIG_FAILED;
6282 }
6283
6284 bgp_addpath_set_peer_type(peer, bgp_node_afi(vty), bgp_node_safi(vty),
6285 BGP_ADDPATH_NONE);
6286
6287 return CMD_SUCCESS;
6288 }
6289
6290 ALIAS_HIDDEN(no_neighbor_addpath_tx_all_paths,
6291 no_neighbor_addpath_tx_all_paths_hidden_cmd,
6292 "no neighbor <A.B.C.D|X:X::X:X|WORD> addpath-tx-all-paths",
6293 NO_STR NEIGHBOR_STR NEIGHBOR_ADDR_STR2
6294 "Use addpath to advertise all paths to a neighbor\n")
6295
6296 DEFUN (neighbor_addpath_tx_bestpath_per_as,
6297 neighbor_addpath_tx_bestpath_per_as_cmd,
6298 "neighbor <A.B.C.D|X:X::X:X|WORD> addpath-tx-bestpath-per-AS",
6299 NEIGHBOR_STR
6300 NEIGHBOR_ADDR_STR2
6301 "Use addpath to advertise the bestpath per each neighboring AS\n")
6302 {
6303 int idx_peer = 1;
6304 struct peer *peer;
6305
6306 peer = peer_and_group_lookup_vty(vty, argv[idx_peer]->arg);
6307 if (!peer)
6308 return CMD_WARNING_CONFIG_FAILED;
6309
6310 bgp_addpath_set_peer_type(peer, bgp_node_afi(vty), bgp_node_safi(vty),
6311 BGP_ADDPATH_BEST_PER_AS);
6312
6313 return CMD_SUCCESS;
6314 }
6315
6316 ALIAS_HIDDEN(neighbor_addpath_tx_bestpath_per_as,
6317 neighbor_addpath_tx_bestpath_per_as_hidden_cmd,
6318 "neighbor <A.B.C.D|X:X::X:X|WORD> addpath-tx-bestpath-per-AS",
6319 NEIGHBOR_STR NEIGHBOR_ADDR_STR2
6320 "Use addpath to advertise the bestpath per each neighboring AS\n")
6321
6322 DEFUN (no_neighbor_addpath_tx_bestpath_per_as,
6323 no_neighbor_addpath_tx_bestpath_per_as_cmd,
6324 "no neighbor <A.B.C.D|X:X::X:X|WORD> addpath-tx-bestpath-per-AS",
6325 NO_STR
6326 NEIGHBOR_STR
6327 NEIGHBOR_ADDR_STR2
6328 "Use addpath to advertise the bestpath per each neighboring AS\n")
6329 {
6330 int idx_peer = 2;
6331 struct peer *peer;
6332
6333 peer = peer_and_group_lookup_vty(vty, argv[idx_peer]->arg);
6334 if (!peer)
6335 return CMD_WARNING_CONFIG_FAILED;
6336
6337 if (peer->addpath_type[bgp_node_afi(vty)][bgp_node_safi(vty)]
6338 != BGP_ADDPATH_BEST_PER_AS) {
6339 vty_out(vty,
6340 "%% Peer not currently configured to transmit all best path per as.");
6341 return CMD_WARNING_CONFIG_FAILED;
6342 }
6343
6344 bgp_addpath_set_peer_type(peer, bgp_node_afi(vty), bgp_node_safi(vty),
6345 BGP_ADDPATH_NONE);
6346
6347 return CMD_SUCCESS;
6348 }
6349
6350 ALIAS_HIDDEN(no_neighbor_addpath_tx_bestpath_per_as,
6351 no_neighbor_addpath_tx_bestpath_per_as_hidden_cmd,
6352 "no neighbor <A.B.C.D|X:X::X:X|WORD> addpath-tx-bestpath-per-AS",
6353 NO_STR NEIGHBOR_STR NEIGHBOR_ADDR_STR2
6354 "Use addpath to advertise the bestpath per each neighboring AS\n")
6355
6356 static int set_ecom_list(struct vty *vty, int argc, struct cmd_token **argv,
6357 struct ecommunity **list)
6358 {
6359 struct ecommunity *ecom = NULL;
6360 struct ecommunity *ecomadd;
6361
6362 for (; argc; --argc, ++argv) {
6363
6364 ecomadd = ecommunity_str2com(argv[0]->arg,
6365 ECOMMUNITY_ROUTE_TARGET, 0);
6366 if (!ecomadd) {
6367 vty_out(vty, "Malformed community-list value\n");
6368 if (ecom)
6369 ecommunity_free(&ecom);
6370 return CMD_WARNING_CONFIG_FAILED;
6371 }
6372
6373 if (ecom) {
6374 ecommunity_merge(ecom, ecomadd);
6375 ecommunity_free(&ecomadd);
6376 } else {
6377 ecom = ecomadd;
6378 }
6379 }
6380
6381 if (*list) {
6382 ecommunity_free(&*list);
6383 }
6384 *list = ecom;
6385
6386 return CMD_SUCCESS;
6387 }
6388
6389 /*
6390 * v2vimport is true if we are handling a `import vrf ...` command
6391 */
6392 static afi_t vpn_policy_getafi(struct vty *vty, struct bgp *bgp, bool v2vimport)
6393 {
6394 afi_t afi;
6395
6396 switch (vty->node) {
6397 case BGP_IPV4_NODE:
6398 afi = AFI_IP;
6399 break;
6400 case BGP_IPV6_NODE:
6401 afi = AFI_IP6;
6402 break;
6403 default:
6404 vty_out(vty,
6405 "%% context error: valid only in address-family <ipv4|ipv6> unicast block\n");
6406 return AFI_MAX;
6407 }
6408
6409 if (!v2vimport) {
6410 if (CHECK_FLAG(bgp->af_flags[afi][SAFI_UNICAST],
6411 BGP_CONFIG_VRF_TO_VRF_IMPORT)
6412 || CHECK_FLAG(bgp->af_flags[afi][SAFI_UNICAST],
6413 BGP_CONFIG_VRF_TO_VRF_EXPORT)) {
6414 vty_out(vty,
6415 "%% error: Please unconfigure import vrf commands before using vpn commands\n");
6416 return AFI_MAX;
6417 }
6418 } else {
6419 if (CHECK_FLAG(bgp->af_flags[afi][SAFI_UNICAST],
6420 BGP_CONFIG_VRF_TO_MPLSVPN_EXPORT)
6421 || CHECK_FLAG(bgp->af_flags[afi][SAFI_UNICAST],
6422 BGP_CONFIG_MPLSVPN_TO_VRF_IMPORT)) {
6423 vty_out(vty,
6424 "%% error: Please unconfigure vpn to vrf commands before using import vrf commands\n");
6425 return AFI_MAX;
6426 }
6427 }
6428 return afi;
6429 }
6430
6431 DEFPY (af_rd_vpn_export,
6432 af_rd_vpn_export_cmd,
6433 "[no] rd vpn export ASN:NN_OR_IP-ADDRESS:NN$rd_str",
6434 NO_STR
6435 "Specify route distinguisher\n"
6436 "Between current address-family and vpn\n"
6437 "For routes leaked from current address-family to vpn\n"
6438 "Route Distinguisher (<as-number>:<number> | <ip-address>:<number>)\n")
6439 {
6440 VTY_DECLVAR_CONTEXT(bgp, bgp);
6441 struct prefix_rd prd;
6442 int ret;
6443 afi_t afi;
6444 int idx = 0;
6445 int yes = 1;
6446
6447 if (argv_find(argv, argc, "no", &idx))
6448 yes = 0;
6449
6450 if (yes) {
6451 ret = str2prefix_rd(rd_str, &prd);
6452 if (!ret) {
6453 vty_out(vty, "%% Malformed rd\n");
6454 return CMD_WARNING_CONFIG_FAILED;
6455 }
6456 }
6457
6458 afi = vpn_policy_getafi(vty, bgp, false);
6459 if (afi == AFI_MAX)
6460 return CMD_WARNING_CONFIG_FAILED;
6461
6462 /*
6463 * pre-change: un-export vpn routes (vpn->vrf routes unaffected)
6464 */
6465 vpn_leak_prechange(BGP_VPN_POLICY_DIR_TOVPN, afi,
6466 bgp_get_default(), bgp);
6467
6468 if (yes) {
6469 bgp->vpn_policy[afi].tovpn_rd = prd;
6470 SET_FLAG(bgp->vpn_policy[afi].flags,
6471 BGP_VPN_POLICY_TOVPN_RD_SET);
6472 } else {
6473 UNSET_FLAG(bgp->vpn_policy[afi].flags,
6474 BGP_VPN_POLICY_TOVPN_RD_SET);
6475 }
6476
6477 /* post-change: re-export vpn routes */
6478 vpn_leak_postchange(BGP_VPN_POLICY_DIR_TOVPN, afi,
6479 bgp_get_default(), bgp);
6480
6481 return CMD_SUCCESS;
6482 }
6483
6484 ALIAS (af_rd_vpn_export,
6485 af_no_rd_vpn_export_cmd,
6486 "no rd vpn export",
6487 NO_STR
6488 "Specify route distinguisher\n"
6489 "Between current address-family and vpn\n"
6490 "For routes leaked from current address-family to vpn\n")
6491
6492 DEFPY (af_label_vpn_export,
6493 af_label_vpn_export_cmd,
6494 "[no] label vpn export <(0-1048575)$label_val|auto$label_auto>",
6495 NO_STR
6496 "label value for VRF\n"
6497 "Between current address-family and vpn\n"
6498 "For routes leaked from current address-family to vpn\n"
6499 "Label Value <0-1048575>\n"
6500 "Automatically assign a label\n")
6501 {
6502 VTY_DECLVAR_CONTEXT(bgp, bgp);
6503 mpls_label_t label = MPLS_LABEL_NONE;
6504 afi_t afi;
6505 int idx = 0;
6506 int yes = 1;
6507
6508 if (argv_find(argv, argc, "no", &idx))
6509 yes = 0;
6510
6511 /* If "no ...", squash trailing parameter */
6512 if (!yes)
6513 label_auto = NULL;
6514
6515 if (yes) {
6516 if (!label_auto)
6517 label = label_val; /* parser should force unsigned */
6518 }
6519
6520 afi = vpn_policy_getafi(vty, bgp, false);
6521 if (afi == AFI_MAX)
6522 return CMD_WARNING_CONFIG_FAILED;
6523
6524
6525 if (label_auto && CHECK_FLAG(bgp->vpn_policy[afi].flags,
6526 BGP_VPN_POLICY_TOVPN_LABEL_AUTO))
6527 /* no change */
6528 return CMD_SUCCESS;
6529
6530 /*
6531 * pre-change: un-export vpn routes (vpn->vrf routes unaffected)
6532 */
6533 vpn_leak_prechange(BGP_VPN_POLICY_DIR_TOVPN, afi,
6534 bgp_get_default(), bgp);
6535
6536 if (!label_auto && CHECK_FLAG(bgp->vpn_policy[afi].flags,
6537 BGP_VPN_POLICY_TOVPN_LABEL_AUTO)) {
6538
6539 if (bgp->vpn_policy[afi].tovpn_label != MPLS_LABEL_NONE) {
6540
6541 /*
6542 * label has previously been automatically
6543 * assigned by labelpool: release it
6544 *
6545 * NB if tovpn_label == MPLS_LABEL_NONE it
6546 * means the automatic assignment is in flight
6547 * and therefore the labelpool callback must
6548 * detect that the auto label is not needed.
6549 */
6550
6551 bgp_lp_release(LP_TYPE_VRF,
6552 &bgp->vpn_policy[afi],
6553 bgp->vpn_policy[afi].tovpn_label);
6554 }
6555 UNSET_FLAG(bgp->vpn_policy[afi].flags,
6556 BGP_VPN_POLICY_TOVPN_LABEL_AUTO);
6557 }
6558
6559 bgp->vpn_policy[afi].tovpn_label = label;
6560 if (label_auto) {
6561 SET_FLAG(bgp->vpn_policy[afi].flags,
6562 BGP_VPN_POLICY_TOVPN_LABEL_AUTO);
6563 bgp_lp_get(LP_TYPE_VRF, &bgp->vpn_policy[afi],
6564 vpn_leak_label_callback);
6565 }
6566
6567 /* post-change: re-export vpn routes */
6568 vpn_leak_postchange(BGP_VPN_POLICY_DIR_TOVPN, afi,
6569 bgp_get_default(), bgp);
6570
6571 return CMD_SUCCESS;
6572 }
6573
6574 ALIAS (af_label_vpn_export,
6575 af_no_label_vpn_export_cmd,
6576 "no label vpn export",
6577 NO_STR
6578 "label value for VRF\n"
6579 "Between current address-family and vpn\n"
6580 "For routes leaked from current address-family to vpn\n")
6581
6582 DEFPY (af_nexthop_vpn_export,
6583 af_nexthop_vpn_export_cmd,
6584 "[no] nexthop vpn export <A.B.C.D|X:X::X:X>$nexthop_str",
6585 NO_STR
6586 "Specify next hop to use for VRF advertised prefixes\n"
6587 "Between current address-family and vpn\n"
6588 "For routes leaked from current address-family to vpn\n"
6589 "IPv4 prefix\n"
6590 "IPv6 prefix\n")
6591 {
6592 VTY_DECLVAR_CONTEXT(bgp, bgp);
6593 afi_t afi;
6594 struct prefix p;
6595 int idx = 0;
6596 int yes = 1;
6597
6598 if (argv_find(argv, argc, "no", &idx))
6599 yes = 0;
6600
6601 if (yes) {
6602 if (!sockunion2hostprefix(nexthop_str, &p))
6603 return CMD_WARNING_CONFIG_FAILED;
6604 }
6605
6606 afi = vpn_policy_getafi(vty, bgp, false);
6607 if (afi == AFI_MAX)
6608 return CMD_WARNING_CONFIG_FAILED;
6609
6610 /*
6611 * pre-change: un-export vpn routes (vpn->vrf routes unaffected)
6612 */
6613 vpn_leak_prechange(BGP_VPN_POLICY_DIR_TOVPN, afi,
6614 bgp_get_default(), bgp);
6615
6616 if (yes) {
6617 bgp->vpn_policy[afi].tovpn_nexthop = p;
6618 SET_FLAG(bgp->vpn_policy[afi].flags,
6619 BGP_VPN_POLICY_TOVPN_NEXTHOP_SET);
6620 } else {
6621 UNSET_FLAG(bgp->vpn_policy[afi].flags,
6622 BGP_VPN_POLICY_TOVPN_NEXTHOP_SET);
6623 }
6624
6625 /* post-change: re-export vpn routes */
6626 vpn_leak_postchange(BGP_VPN_POLICY_DIR_TOVPN, afi,
6627 bgp_get_default(), bgp);
6628
6629 return CMD_SUCCESS;
6630 }
6631
6632 ALIAS (af_nexthop_vpn_export,
6633 af_no_nexthop_vpn_export_cmd,
6634 "no nexthop vpn export",
6635 NO_STR
6636 "Specify next hop to use for VRF advertised prefixes\n"
6637 "Between current address-family and vpn\n"
6638 "For routes leaked from current address-family to vpn\n")
6639
6640 static int vpn_policy_getdirs(struct vty *vty, const char *dstr, int *dodir)
6641 {
6642 if (!strcmp(dstr, "import")) {
6643 dodir[BGP_VPN_POLICY_DIR_FROMVPN] = 1;
6644 } else if (!strcmp(dstr, "export")) {
6645 dodir[BGP_VPN_POLICY_DIR_TOVPN] = 1;
6646 } else if (!strcmp(dstr, "both")) {
6647 dodir[BGP_VPN_POLICY_DIR_FROMVPN] = 1;
6648 dodir[BGP_VPN_POLICY_DIR_TOVPN] = 1;
6649 } else {
6650 vty_out(vty, "%% direction parse error\n");
6651 return CMD_WARNING_CONFIG_FAILED;
6652 }
6653 return CMD_SUCCESS;
6654 }
6655
6656 DEFPY (af_rt_vpn_imexport,
6657 af_rt_vpn_imexport_cmd,
6658 "[no] <rt|route-target> vpn <import|export|both>$direction_str RTLIST...",
6659 NO_STR
6660 "Specify route target list\n"
6661 "Specify route target list\n"
6662 "Between current address-family and vpn\n"
6663 "For routes leaked from vpn to current address-family: match any\n"
6664 "For routes leaked from current address-family to vpn: set\n"
6665 "both import: match any and export: set\n"
6666 "Space separated route target list (A.B.C.D:MN|EF:OPQR|GHJK:MN)\n")
6667 {
6668 VTY_DECLVAR_CONTEXT(bgp, bgp);
6669 int ret;
6670 struct ecommunity *ecom = NULL;
6671 int dodir[BGP_VPN_POLICY_DIR_MAX] = {0};
6672 vpn_policy_direction_t dir;
6673 afi_t afi;
6674 int idx = 0;
6675 int yes = 1;
6676
6677 if (argv_find(argv, argc, "no", &idx))
6678 yes = 0;
6679
6680 afi = vpn_policy_getafi(vty, bgp, false);
6681 if (afi == AFI_MAX)
6682 return CMD_WARNING_CONFIG_FAILED;
6683
6684 ret = vpn_policy_getdirs(vty, direction_str, dodir);
6685 if (ret != CMD_SUCCESS)
6686 return ret;
6687
6688 if (yes) {
6689 if (!argv_find(argv, argc, "RTLIST", &idx)) {
6690 vty_out(vty, "%% Missing RTLIST\n");
6691 return CMD_WARNING_CONFIG_FAILED;
6692 }
6693 ret = set_ecom_list(vty, argc - idx, argv + idx, &ecom);
6694 if (ret != CMD_SUCCESS) {
6695 return ret;
6696 }
6697 }
6698
6699 for (dir = 0; dir < BGP_VPN_POLICY_DIR_MAX; ++dir) {
6700 if (!dodir[dir])
6701 continue;
6702
6703 vpn_leak_prechange(dir, afi, bgp_get_default(), bgp);
6704
6705 if (yes) {
6706 if (bgp->vpn_policy[afi].rtlist[dir])
6707 ecommunity_free(
6708 &bgp->vpn_policy[afi].rtlist[dir]);
6709 bgp->vpn_policy[afi].rtlist[dir] =
6710 ecommunity_dup(ecom);
6711 } else {
6712 if (bgp->vpn_policy[afi].rtlist[dir])
6713 ecommunity_free(
6714 &bgp->vpn_policy[afi].rtlist[dir]);
6715 bgp->vpn_policy[afi].rtlist[dir] = NULL;
6716 }
6717
6718 vpn_leak_postchange(dir, afi, bgp_get_default(), bgp);
6719 }
6720
6721 if (ecom)
6722 ecommunity_free(&ecom);
6723
6724 return CMD_SUCCESS;
6725 }
6726
6727 ALIAS (af_rt_vpn_imexport,
6728 af_no_rt_vpn_imexport_cmd,
6729 "no <rt|route-target> vpn <import|export|both>$direction_str",
6730 NO_STR
6731 "Specify route target list\n"
6732 "Specify route target list\n"
6733 "Between current address-family and vpn\n"
6734 "For routes leaked from vpn to current address-family\n"
6735 "For routes leaked from current address-family to vpn\n"
6736 "both import and export\n")
6737
6738 DEFPY (af_route_map_vpn_imexport,
6739 af_route_map_vpn_imexport_cmd,
6740 /* future: "route-map <vpn|evpn|vrf NAME> <import|export> RMAP" */
6741 "[no] route-map vpn <import|export>$direction_str RMAP$rmap_str",
6742 NO_STR
6743 "Specify route map\n"
6744 "Between current address-family and vpn\n"
6745 "For routes leaked from vpn to current address-family\n"
6746 "For routes leaked from current address-family to vpn\n"
6747 "name of route-map\n")
6748 {
6749 VTY_DECLVAR_CONTEXT(bgp, bgp);
6750 int ret;
6751 int dodir[BGP_VPN_POLICY_DIR_MAX] = {0};
6752 vpn_policy_direction_t dir;
6753 afi_t afi;
6754 int idx = 0;
6755 int yes = 1;
6756
6757 if (argv_find(argv, argc, "no", &idx))
6758 yes = 0;
6759
6760 afi = vpn_policy_getafi(vty, bgp, false);
6761 if (afi == AFI_MAX)
6762 return CMD_WARNING_CONFIG_FAILED;
6763
6764 ret = vpn_policy_getdirs(vty, direction_str, dodir);
6765 if (ret != CMD_SUCCESS)
6766 return ret;
6767
6768 for (dir = 0; dir < BGP_VPN_POLICY_DIR_MAX; ++dir) {
6769 if (!dodir[dir])
6770 continue;
6771
6772 vpn_leak_prechange(dir, afi, bgp_get_default(), bgp);
6773
6774 if (yes) {
6775 if (bgp->vpn_policy[afi].rmap_name[dir])
6776 XFREE(MTYPE_ROUTE_MAP_NAME,
6777 bgp->vpn_policy[afi].rmap_name[dir]);
6778 bgp->vpn_policy[afi].rmap_name[dir] = XSTRDUP(
6779 MTYPE_ROUTE_MAP_NAME, rmap_str);
6780 bgp->vpn_policy[afi].rmap[dir] =
6781 route_map_lookup_warn_noexist(vty, rmap_str);
6782 if (!bgp->vpn_policy[afi].rmap[dir])
6783 return CMD_SUCCESS;
6784 } else {
6785 if (bgp->vpn_policy[afi].rmap_name[dir])
6786 XFREE(MTYPE_ROUTE_MAP_NAME,
6787 bgp->vpn_policy[afi].rmap_name[dir]);
6788 bgp->vpn_policy[afi].rmap_name[dir] = NULL;
6789 bgp->vpn_policy[afi].rmap[dir] = NULL;
6790 }
6791
6792 vpn_leak_postchange(dir, afi, bgp_get_default(), bgp);
6793 }
6794
6795 return CMD_SUCCESS;
6796 }
6797
6798 ALIAS (af_route_map_vpn_imexport,
6799 af_no_route_map_vpn_imexport_cmd,
6800 "no route-map vpn <import|export>$direction_str",
6801 NO_STR
6802 "Specify route map\n"
6803 "Between current address-family and vpn\n"
6804 "For routes leaked from vpn to current address-family\n"
6805 "For routes leaked from current address-family to vpn\n")
6806
6807 DEFPY(af_import_vrf_route_map, af_import_vrf_route_map_cmd,
6808 "[no] import vrf route-map RMAP$rmap_str",
6809 NO_STR
6810 "Import routes from another VRF\n"
6811 "Vrf routes being filtered\n"
6812 "Specify route map\n"
6813 "name of route-map\n")
6814 {
6815 VTY_DECLVAR_CONTEXT(bgp, bgp);
6816 vpn_policy_direction_t dir = BGP_VPN_POLICY_DIR_FROMVPN;
6817 afi_t afi;
6818 int idx = 0;
6819 int yes = 1;
6820 struct bgp *bgp_default;
6821
6822 if (argv_find(argv, argc, "no", &idx))
6823 yes = 0;
6824
6825 afi = vpn_policy_getafi(vty, bgp, true);
6826 if (afi == AFI_MAX)
6827 return CMD_WARNING_CONFIG_FAILED;
6828
6829 bgp_default = bgp_get_default();
6830 if (!bgp_default) {
6831 int32_t ret;
6832 as_t as = bgp->as;
6833
6834 /* Auto-create assuming the same AS */
6835 ret = bgp_get(&bgp_default, &as, NULL,
6836 BGP_INSTANCE_TYPE_DEFAULT);
6837
6838 if (ret) {
6839 vty_out(vty,
6840 "VRF default is not configured as a bgp instance\n");
6841 return CMD_WARNING;
6842 }
6843 }
6844
6845 vpn_leak_prechange(dir, afi, bgp_get_default(), bgp);
6846
6847 if (yes) {
6848 if (bgp->vpn_policy[afi].rmap_name[dir])
6849 XFREE(MTYPE_ROUTE_MAP_NAME,
6850 bgp->vpn_policy[afi].rmap_name[dir]);
6851 bgp->vpn_policy[afi].rmap_name[dir] =
6852 XSTRDUP(MTYPE_ROUTE_MAP_NAME, rmap_str);
6853 bgp->vpn_policy[afi].rmap[dir] =
6854 route_map_lookup_warn_noexist(vty, rmap_str);
6855 if (!bgp->vpn_policy[afi].rmap[dir])
6856 return CMD_SUCCESS;
6857 } else {
6858 if (bgp->vpn_policy[afi].rmap_name[dir])
6859 XFREE(MTYPE_ROUTE_MAP_NAME,
6860 bgp->vpn_policy[afi].rmap_name[dir]);
6861 bgp->vpn_policy[afi].rmap_name[dir] = NULL;
6862 bgp->vpn_policy[afi].rmap[dir] = NULL;
6863 }
6864
6865 vpn_leak_postchange(dir, afi, bgp_get_default(), bgp);
6866
6867 return CMD_SUCCESS;
6868 }
6869
6870 ALIAS(af_import_vrf_route_map, af_no_import_vrf_route_map_cmd,
6871 "no import vrf route-map",
6872 NO_STR
6873 "Import routes from another VRF\n"
6874 "Vrf routes being filtered\n"
6875 "Specify route map\n")
6876
6877 DEFPY(bgp_imexport_vrf, bgp_imexport_vrf_cmd,
6878 "[no] import vrf VIEWVRFNAME$import_name",
6879 NO_STR
6880 "Import routes from another VRF\n"
6881 "VRF to import from\n"
6882 "The name of the VRF\n")
6883 {
6884 VTY_DECLVAR_CONTEXT(bgp, bgp);
6885 struct listnode *node;
6886 struct bgp *vrf_bgp, *bgp_default;
6887 int32_t ret = 0;
6888 as_t as = bgp->as;
6889 bool remove = false;
6890 int32_t idx = 0;
6891 char *vname;
6892 enum bgp_instance_type bgp_type = BGP_INSTANCE_TYPE_VRF;
6893 safi_t safi;
6894 afi_t afi;
6895
6896 if (import_name == NULL) {
6897 vty_out(vty, "%% Missing import name\n");
6898 return CMD_WARNING;
6899 }
6900
6901 if (argv_find(argv, argc, "no", &idx))
6902 remove = true;
6903
6904 afi = vpn_policy_getafi(vty, bgp, true);
6905 if (afi == AFI_MAX)
6906 return CMD_WARNING_CONFIG_FAILED;
6907
6908 safi = bgp_node_safi(vty);
6909
6910 if (((BGP_INSTANCE_TYPE_DEFAULT == bgp->inst_type)
6911 && (strcmp(import_name, VRF_DEFAULT_NAME) == 0))
6912 || (bgp->name && (strcmp(import_name, bgp->name) == 0))) {
6913 vty_out(vty, "%% Cannot %s vrf %s into itself\n",
6914 remove ? "unimport" : "import", import_name);
6915 return CMD_WARNING;
6916 }
6917
6918 bgp_default = bgp_get_default();
6919 if (!bgp_default) {
6920 /* Auto-create assuming the same AS */
6921 ret = bgp_get(&bgp_default, &as, NULL,
6922 BGP_INSTANCE_TYPE_DEFAULT);
6923
6924 if (ret) {
6925 vty_out(vty,
6926 "VRF default is not configured as a bgp instance\n");
6927 return CMD_WARNING;
6928 }
6929 }
6930
6931 vrf_bgp = bgp_lookup_by_name(import_name);
6932 if (!vrf_bgp) {
6933 if (strcmp(import_name, VRF_DEFAULT_NAME) == 0)
6934 vrf_bgp = bgp_default;
6935 else
6936 /* Auto-create assuming the same AS */
6937 ret = bgp_get(&vrf_bgp, &as, import_name, bgp_type);
6938
6939 if (ret) {
6940 vty_out(vty,
6941 "VRF %s is not configured as a bgp instance\n",
6942 import_name);
6943 return CMD_WARNING;
6944 }
6945 }
6946
6947 if (remove) {
6948 vrf_unimport_from_vrf(bgp, vrf_bgp, afi, safi);
6949 } else {
6950 /* Already importing from "import_vrf"? */
6951 for (ALL_LIST_ELEMENTS_RO(bgp->vpn_policy[afi].import_vrf, node,
6952 vname)) {
6953 if (strcmp(vname, import_name) == 0)
6954 return CMD_WARNING;
6955 }
6956
6957 vrf_import_from_vrf(bgp, vrf_bgp, afi, safi);
6958 }
6959
6960 return CMD_SUCCESS;
6961 }
6962
6963 /* This command is valid only in a bgp vrf instance or the default instance */
6964 DEFPY (bgp_imexport_vpn,
6965 bgp_imexport_vpn_cmd,
6966 "[no] <import|export>$direction_str vpn",
6967 NO_STR
6968 "Import routes to this address-family\n"
6969 "Export routes from this address-family\n"
6970 "to/from default instance VPN RIB\n")
6971 {
6972 VTY_DECLVAR_CONTEXT(bgp, bgp);
6973 int previous_state;
6974 afi_t afi;
6975 safi_t safi;
6976 int idx = 0;
6977 int yes = 1;
6978 int flag;
6979 vpn_policy_direction_t dir;
6980
6981 if (argv_find(argv, argc, "no", &idx))
6982 yes = 0;
6983
6984 if (BGP_INSTANCE_TYPE_VRF != bgp->inst_type &&
6985 BGP_INSTANCE_TYPE_DEFAULT != bgp->inst_type) {
6986
6987 vty_out(vty, "%% import|export vpn valid only for bgp vrf or default instance\n");
6988 return CMD_WARNING_CONFIG_FAILED;
6989 }
6990
6991 afi = bgp_node_afi(vty);
6992 safi = bgp_node_safi(vty);
6993 if ((SAFI_UNICAST != safi) || ((AFI_IP != afi) && (AFI_IP6 != afi))) {
6994 vty_out(vty, "%% import|export vpn valid only for unicast ipv4|ipv6\n");
6995 return CMD_WARNING_CONFIG_FAILED;
6996 }
6997
6998 if (!strcmp(direction_str, "import")) {
6999 flag = BGP_CONFIG_MPLSVPN_TO_VRF_IMPORT;
7000 dir = BGP_VPN_POLICY_DIR_FROMVPN;
7001 } else if (!strcmp(direction_str, "export")) {
7002 flag = BGP_CONFIG_VRF_TO_MPLSVPN_EXPORT;
7003 dir = BGP_VPN_POLICY_DIR_TOVPN;
7004 } else {
7005 vty_out(vty, "%% unknown direction %s\n", direction_str);
7006 return CMD_WARNING_CONFIG_FAILED;
7007 }
7008
7009 previous_state = CHECK_FLAG(bgp->af_flags[afi][safi], flag);
7010
7011 if (yes) {
7012 SET_FLAG(bgp->af_flags[afi][safi], flag);
7013 if (!previous_state) {
7014 /* trigger export current vrf */
7015 vpn_leak_postchange(dir, afi, bgp_get_default(), bgp);
7016 }
7017 } else {
7018 if (previous_state) {
7019 /* trigger un-export current vrf */
7020 vpn_leak_prechange(dir, afi, bgp_get_default(), bgp);
7021 }
7022 UNSET_FLAG(bgp->af_flags[afi][safi], flag);
7023 }
7024
7025 return CMD_SUCCESS;
7026 }
7027
7028 DEFPY (af_routetarget_import,
7029 af_routetarget_import_cmd,
7030 "[no] <rt|route-target> redirect import RTLIST...",
7031 NO_STR
7032 "Specify route target list\n"
7033 "Specify route target list\n"
7034 "Flow-spec redirect type route target\n"
7035 "Import routes to this address-family\n"
7036 "Space separated route target list (A.B.C.D:MN|EF:OPQR|GHJK:MN)\n")
7037 {
7038 VTY_DECLVAR_CONTEXT(bgp, bgp);
7039 int ret;
7040 struct ecommunity *ecom = NULL;
7041 afi_t afi;
7042 int idx = 0;
7043 int yes = 1;
7044
7045 if (argv_find(argv, argc, "no", &idx))
7046 yes = 0;
7047
7048 afi = vpn_policy_getafi(vty, bgp, false);
7049 if (afi == AFI_MAX)
7050 return CMD_WARNING_CONFIG_FAILED;
7051
7052 if (yes) {
7053 if (!argv_find(argv, argc, "RTLIST", &idx)) {
7054 vty_out(vty, "%% Missing RTLIST\n");
7055 return CMD_WARNING_CONFIG_FAILED;
7056 }
7057 ret = set_ecom_list(vty, argc - idx, argv + idx, &ecom);
7058 if (ret != CMD_SUCCESS)
7059 return ret;
7060 }
7061
7062 if (yes) {
7063 if (bgp->vpn_policy[afi].import_redirect_rtlist)
7064 ecommunity_free(&bgp->vpn_policy[afi]
7065 .import_redirect_rtlist);
7066 bgp->vpn_policy[afi].import_redirect_rtlist =
7067 ecommunity_dup(ecom);
7068 } else {
7069 if (bgp->vpn_policy[afi].import_redirect_rtlist)
7070 ecommunity_free(&bgp->vpn_policy[afi]
7071 .import_redirect_rtlist);
7072 bgp->vpn_policy[afi].import_redirect_rtlist = NULL;
7073 }
7074
7075 if (ecom)
7076 ecommunity_free(&ecom);
7077
7078 return CMD_SUCCESS;
7079 }
7080
7081 DEFUN_NOSH (address_family_ipv4_safi,
7082 address_family_ipv4_safi_cmd,
7083 "address-family ipv4 [<unicast|multicast|vpn|labeled-unicast|flowspec>]",
7084 "Enter Address Family command mode\n"
7085 "Address Family\n"
7086 BGP_SAFI_WITH_LABEL_HELP_STR)
7087 {
7088
7089 if (argc == 3) {
7090 VTY_DECLVAR_CONTEXT(bgp, bgp);
7091 safi_t safi = bgp_vty_safi_from_str(argv[2]->text);
7092 if (bgp->inst_type != BGP_INSTANCE_TYPE_DEFAULT
7093 && safi != SAFI_UNICAST && safi != SAFI_MULTICAST
7094 && safi != SAFI_EVPN) {
7095 vty_out(vty,
7096 "Only Unicast/Multicast/EVPN SAFIs supported in non-core instances.\n");
7097 return CMD_WARNING_CONFIG_FAILED;
7098 }
7099 vty->node = bgp_node_type(AFI_IP, safi);
7100 } else
7101 vty->node = BGP_IPV4_NODE;
7102
7103 return CMD_SUCCESS;
7104 }
7105
7106 DEFUN_NOSH (address_family_ipv6_safi,
7107 address_family_ipv6_safi_cmd,
7108 "address-family ipv6 [<unicast|multicast|vpn|labeled-unicast|flowspec>]",
7109 "Enter Address Family command mode\n"
7110 "Address Family\n"
7111 BGP_SAFI_WITH_LABEL_HELP_STR)
7112 {
7113 if (argc == 3) {
7114 VTY_DECLVAR_CONTEXT(bgp, bgp);
7115 safi_t safi = bgp_vty_safi_from_str(argv[2]->text);
7116 if (bgp->inst_type != BGP_INSTANCE_TYPE_DEFAULT
7117 && safi != SAFI_UNICAST && safi != SAFI_MULTICAST
7118 && safi != SAFI_EVPN) {
7119 vty_out(vty,
7120 "Only Unicast/Multicast/EVPN SAFIs supported in non-core instances.\n");
7121 return CMD_WARNING_CONFIG_FAILED;
7122 }
7123 vty->node = bgp_node_type(AFI_IP6, safi);
7124 } else
7125 vty->node = BGP_IPV6_NODE;
7126
7127 return CMD_SUCCESS;
7128 }
7129
7130 #ifdef KEEP_OLD_VPN_COMMANDS
7131 DEFUN_NOSH (address_family_vpnv4,
7132 address_family_vpnv4_cmd,
7133 "address-family vpnv4 [unicast]",
7134 "Enter Address Family command mode\n"
7135 "Address Family\n"
7136 "Address Family modifier\n")
7137 {
7138 vty->node = BGP_VPNV4_NODE;
7139 return CMD_SUCCESS;
7140 }
7141
7142 DEFUN_NOSH (address_family_vpnv6,
7143 address_family_vpnv6_cmd,
7144 "address-family vpnv6 [unicast]",
7145 "Enter Address Family command mode\n"
7146 "Address Family\n"
7147 "Address Family modifier\n")
7148 {
7149 vty->node = BGP_VPNV6_NODE;
7150 return CMD_SUCCESS;
7151 }
7152 #endif /* KEEP_OLD_VPN_COMMANDS */
7153
7154 DEFUN_NOSH (address_family_evpn,
7155 address_family_evpn_cmd,
7156 "address-family l2vpn evpn",
7157 "Enter Address Family command mode\n"
7158 "Address Family\n"
7159 "Address Family modifier\n")
7160 {
7161 VTY_DECLVAR_CONTEXT(bgp, bgp);
7162 vty->node = BGP_EVPN_NODE;
7163 return CMD_SUCCESS;
7164 }
7165
7166 DEFUN_NOSH (exit_address_family,
7167 exit_address_family_cmd,
7168 "exit-address-family",
7169 "Exit from Address Family configuration mode\n")
7170 {
7171 if (vty->node == BGP_IPV4_NODE || vty->node == BGP_IPV4M_NODE
7172 || vty->node == BGP_IPV4L_NODE || vty->node == BGP_VPNV4_NODE
7173 || vty->node == BGP_IPV6_NODE || vty->node == BGP_IPV6M_NODE
7174 || vty->node == BGP_IPV6L_NODE || vty->node == BGP_VPNV6_NODE
7175 || vty->node == BGP_EVPN_NODE
7176 || vty->node == BGP_FLOWSPECV4_NODE
7177 || vty->node == BGP_FLOWSPECV6_NODE)
7178 vty->node = BGP_NODE;
7179 return CMD_SUCCESS;
7180 }
7181
7182 /* Recalculate bestpath and re-advertise a prefix */
7183 static int bgp_clear_prefix(struct vty *vty, const char *view_name,
7184 const char *ip_str, afi_t afi, safi_t safi,
7185 struct prefix_rd *prd)
7186 {
7187 int ret;
7188 struct prefix match;
7189 struct bgp_node *rn;
7190 struct bgp_node *rm;
7191 struct bgp *bgp;
7192 struct bgp_table *table;
7193 struct bgp_table *rib;
7194
7195 /* BGP structure lookup. */
7196 if (view_name) {
7197 bgp = bgp_lookup_by_name(view_name);
7198 if (bgp == NULL) {
7199 vty_out(vty, "%% Can't find BGP instance %s\n",
7200 view_name);
7201 return CMD_WARNING;
7202 }
7203 } else {
7204 bgp = bgp_get_default();
7205 if (bgp == NULL) {
7206 vty_out(vty, "%% No BGP process is configured\n");
7207 return CMD_WARNING;
7208 }
7209 }
7210
7211 /* Check IP address argument. */
7212 ret = str2prefix(ip_str, &match);
7213 if (!ret) {
7214 vty_out(vty, "%% address is malformed\n");
7215 return CMD_WARNING;
7216 }
7217
7218 match.family = afi2family(afi);
7219 rib = bgp->rib[afi][safi];
7220
7221 if (safi == SAFI_MPLS_VPN) {
7222 for (rn = bgp_table_top(rib); rn; rn = bgp_route_next(rn)) {
7223 if (prd && memcmp(rn->p.u.val, prd->val, 8) != 0)
7224 continue;
7225
7226 table = bgp_node_get_bgp_table_info(rn);
7227 if (table != NULL) {
7228
7229 if ((rm = bgp_node_match(table, &match))
7230 != NULL) {
7231 if (rm->p.prefixlen
7232 == match.prefixlen) {
7233 SET_FLAG(rm->flags,
7234 BGP_NODE_USER_CLEAR);
7235 bgp_process(bgp, rm, afi, safi);
7236 }
7237 bgp_unlock_node(rm);
7238 }
7239 }
7240 }
7241 } else {
7242 if ((rn = bgp_node_match(rib, &match)) != NULL) {
7243 if (rn->p.prefixlen == match.prefixlen) {
7244 SET_FLAG(rn->flags, BGP_NODE_USER_CLEAR);
7245 bgp_process(bgp, rn, afi, safi);
7246 }
7247 bgp_unlock_node(rn);
7248 }
7249 }
7250
7251 return CMD_SUCCESS;
7252 }
7253
7254 /* one clear bgp command to rule them all */
7255 DEFUN (clear_ip_bgp_all,
7256 clear_ip_bgp_all_cmd,
7257 "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>]",
7258 CLEAR_STR
7259 IP_STR
7260 BGP_STR
7261 BGP_INSTANCE_HELP_STR
7262 BGP_AFI_HELP_STR
7263 "Address Family\n"
7264 BGP_SAFI_WITH_LABEL_HELP_STR
7265 "Address Family modifier\n"
7266 "Clear all peers\n"
7267 "BGP neighbor address to clear\n"
7268 "BGP IPv6 neighbor to clear\n"
7269 "BGP neighbor on interface to clear\n"
7270 "Clear peers with the AS number\n"
7271 "Clear all external peers\n"
7272 "Clear all members of peer-group\n"
7273 "BGP peer-group name\n"
7274 BGP_SOFT_STR
7275 BGP_SOFT_IN_STR
7276 BGP_SOFT_OUT_STR
7277 BGP_SOFT_IN_STR
7278 "Push out prefix-list ORF and do inbound soft reconfig\n"
7279 BGP_SOFT_OUT_STR)
7280 {
7281 char *vrf = NULL;
7282
7283 afi_t afi = AFI_IP6;
7284 safi_t safi = SAFI_UNICAST;
7285 enum clear_sort clr_sort = clear_peer;
7286 enum bgp_clear_type clr_type;
7287 char *clr_arg = NULL;
7288
7289 int idx = 0;
7290
7291 /* clear [ip] bgp */
7292 if (argv_find(argv, argc, "ip", &idx))
7293 afi = AFI_IP;
7294
7295 /* [<vrf> VIEWVRFNAME] */
7296 if (argv_find(argv, argc, "vrf", &idx)) {
7297 vrf = argv[idx + 1]->arg;
7298 idx += 2;
7299 if (vrf && strmatch(vrf, VRF_DEFAULT_NAME))
7300 vrf = NULL;
7301 } else if (argv_find(argv, argc, "view", &idx)) {
7302 /* [<view> VIEWVRFNAME] */
7303 vrf = argv[idx + 1]->arg;
7304 idx += 2;
7305 }
7306 /* ["BGP_AFI_CMD_STR" ["BGP_SAFI_CMD_STR"]] */
7307 if (argv_find_and_parse_afi(argv, argc, &idx, &afi))
7308 argv_find_and_parse_safi(argv, argc, &idx, &safi);
7309
7310 /* <*|A.B.C.D|X:X::X:X|WORD|(1-4294967295)|external|peer-group WORD> */
7311 if (argv_find(argv, argc, "*", &idx)) {
7312 clr_sort = clear_all;
7313 } else if (argv_find(argv, argc, "A.B.C.D", &idx)) {
7314 clr_sort = clear_peer;
7315 clr_arg = argv[idx]->arg;
7316 } else if (argv_find(argv, argc, "X:X::X:X", &idx)) {
7317 clr_sort = clear_peer;
7318 clr_arg = argv[idx]->arg;
7319 } else if (argv_find(argv, argc, "peer-group", &idx)) {
7320 clr_sort = clear_group;
7321 idx++;
7322 clr_arg = argv[idx]->arg;
7323 } else if (argv_find(argv, argc, "WORD", &idx)) {
7324 clr_sort = clear_peer;
7325 clr_arg = argv[idx]->arg;
7326 } else if (argv_find(argv, argc, "(1-4294967295)", &idx)) {
7327 clr_sort = clear_as;
7328 clr_arg = argv[idx]->arg;
7329 } else if (argv_find(argv, argc, "external", &idx)) {
7330 clr_sort = clear_external;
7331 }
7332
7333 /* [<soft [<in|out>]|in [prefix-filter]|out>] */
7334 if (argv_find(argv, argc, "soft", &idx)) {
7335 if (argv_find(argv, argc, "in", &idx)
7336 || argv_find(argv, argc, "out", &idx))
7337 clr_type = strmatch(argv[idx]->text, "in")
7338 ? BGP_CLEAR_SOFT_IN
7339 : BGP_CLEAR_SOFT_OUT;
7340 else
7341 clr_type = BGP_CLEAR_SOFT_BOTH;
7342 } else if (argv_find(argv, argc, "in", &idx)) {
7343 clr_type = argv_find(argv, argc, "prefix-filter", &idx)
7344 ? BGP_CLEAR_SOFT_IN_ORF_PREFIX
7345 : BGP_CLEAR_SOFT_IN;
7346 } else if (argv_find(argv, argc, "out", &idx)) {
7347 clr_type = BGP_CLEAR_SOFT_OUT;
7348 } else
7349 clr_type = BGP_CLEAR_SOFT_NONE;
7350
7351 return bgp_clear_vty(vty, vrf, afi, safi, clr_sort, clr_type, clr_arg);
7352 }
7353
7354 DEFUN (clear_ip_bgp_prefix,
7355 clear_ip_bgp_prefix_cmd,
7356 "clear [ip] bgp [<view|vrf> VIEWVRFNAME] prefix A.B.C.D/M",
7357 CLEAR_STR
7358 IP_STR
7359 BGP_STR
7360 BGP_INSTANCE_HELP_STR
7361 "Clear bestpath and re-advertise\n"
7362 "IPv4 prefix\n")
7363 {
7364 char *vrf = NULL;
7365 char *prefix = NULL;
7366
7367 int idx = 0;
7368
7369 /* [<view|vrf> VIEWVRFNAME] */
7370 if (argv_find(argv, argc, "vrf", &idx)) {
7371 vrf = argv[idx + 1]->arg;
7372 idx += 2;
7373 if (vrf && strmatch(vrf, VRF_DEFAULT_NAME))
7374 vrf = NULL;
7375 } else if (argv_find(argv, argc, "view", &idx)) {
7376 /* [<view> VIEWVRFNAME] */
7377 vrf = argv[idx + 1]->arg;
7378 idx += 2;
7379 }
7380
7381 prefix = argv[argc - 1]->arg;
7382
7383 return bgp_clear_prefix(vty, vrf, prefix, AFI_IP, SAFI_UNICAST, NULL);
7384 }
7385
7386 DEFUN (clear_bgp_ipv6_safi_prefix,
7387 clear_bgp_ipv6_safi_prefix_cmd,
7388 "clear [ip] bgp ipv6 "BGP_SAFI_CMD_STR" prefix X:X::X:X/M",
7389 CLEAR_STR
7390 IP_STR
7391 BGP_STR
7392 "Address Family\n"
7393 BGP_SAFI_HELP_STR
7394 "Clear bestpath and re-advertise\n"
7395 "IPv6 prefix\n")
7396 {
7397 int idx_safi = 0;
7398 int idx_ipv6_prefix = 0;
7399 safi_t safi = SAFI_UNICAST;
7400 char *prefix = argv_find(argv, argc, "X:X::X:X/M", &idx_ipv6_prefix) ?
7401 argv[idx_ipv6_prefix]->arg : NULL;
7402
7403 argv_find_and_parse_safi(argv, argc, &idx_safi, &safi);
7404 return bgp_clear_prefix(
7405 vty, NULL, prefix, AFI_IP6,
7406 safi, NULL);
7407 }
7408
7409 DEFUN (clear_bgp_instance_ipv6_safi_prefix,
7410 clear_bgp_instance_ipv6_safi_prefix_cmd,
7411 "clear [ip] bgp <view|vrf> VIEWVRFNAME ipv6 "BGP_SAFI_CMD_STR" prefix X:X::X:X/M",
7412 CLEAR_STR
7413 IP_STR
7414 BGP_STR
7415 BGP_INSTANCE_HELP_STR
7416 "Address Family\n"
7417 BGP_SAFI_HELP_STR
7418 "Clear bestpath and re-advertise\n"
7419 "IPv6 prefix\n")
7420 {
7421 int idx_safi = 0;
7422 int idx_vrfview = 0;
7423 int idx_ipv6_prefix = 0;
7424 safi_t safi = SAFI_UNICAST;
7425 char *prefix = argv_find(argv, argc, "X:X::X:X/M", &idx_ipv6_prefix) ?
7426 argv[idx_ipv6_prefix]->arg : NULL;
7427 char *vrfview = NULL;
7428
7429 /* [<view|vrf> VIEWVRFNAME] */
7430 if (argv_find(argv, argc, "vrf", &idx_vrfview)) {
7431 vrfview = argv[idx_vrfview + 1]->arg;
7432 if (vrfview && strmatch(vrfview, VRF_DEFAULT_NAME))
7433 vrfview = NULL;
7434 } else if (argv_find(argv, argc, "view", &idx_vrfview)) {
7435 /* [<view> VIEWVRFNAME] */
7436 vrfview = argv[idx_vrfview + 1]->arg;
7437 }
7438 argv_find_and_parse_safi(argv, argc, &idx_safi, &safi);
7439
7440 return bgp_clear_prefix(
7441 vty, vrfview, prefix,
7442 AFI_IP6, safi, NULL);
7443 }
7444
7445 DEFUN (show_bgp_views,
7446 show_bgp_views_cmd,
7447 "show [ip] bgp views",
7448 SHOW_STR
7449 IP_STR
7450 BGP_STR
7451 "Show the defined BGP views\n")
7452 {
7453 struct list *inst = bm->bgp;
7454 struct listnode *node;
7455 struct bgp *bgp;
7456
7457 if (!bgp_option_check(BGP_OPT_MULTIPLE_INSTANCE)) {
7458 vty_out(vty, "BGP Multiple Instance is not enabled\n");
7459 return CMD_WARNING;
7460 }
7461
7462 vty_out(vty, "Defined BGP views:\n");
7463 for (ALL_LIST_ELEMENTS_RO(inst, node, bgp)) {
7464 /* Skip VRFs. */
7465 if (bgp->inst_type == BGP_INSTANCE_TYPE_VRF)
7466 continue;
7467 vty_out(vty, "\t%s (AS%u)\n", bgp->name ? bgp->name : "(null)",
7468 bgp->as);
7469 }
7470
7471 return CMD_SUCCESS;
7472 }
7473
7474 DEFUN (show_bgp_vrfs,
7475 show_bgp_vrfs_cmd,
7476 "show [ip] bgp vrfs [json]",
7477 SHOW_STR
7478 IP_STR
7479 BGP_STR
7480 "Show BGP VRFs\n"
7481 JSON_STR)
7482 {
7483 char buf[ETHER_ADDR_STRLEN];
7484 struct list *inst = bm->bgp;
7485 struct listnode *node;
7486 struct bgp *bgp;
7487 bool uj = use_json(argc, argv);
7488 json_object *json = NULL;
7489 json_object *json_vrfs = NULL;
7490 int count = 0;
7491
7492 if (!bgp_option_check(BGP_OPT_MULTIPLE_INSTANCE)) {
7493 vty_out(vty, "BGP Multiple Instance is not enabled\n");
7494 return CMD_WARNING;
7495 }
7496
7497 if (uj) {
7498 json = json_object_new_object();
7499 json_vrfs = json_object_new_object();
7500 }
7501
7502 for (ALL_LIST_ELEMENTS_RO(inst, node, bgp)) {
7503 const char *name, *type;
7504 struct peer *peer;
7505 struct listnode *node2, *nnode2;
7506 int peers_cfg, peers_estb;
7507 json_object *json_vrf = NULL;
7508
7509 /* Skip Views. */
7510 if (bgp->inst_type == BGP_INSTANCE_TYPE_VIEW)
7511 continue;
7512
7513 count++;
7514 if (!uj && count == 1)
7515 vty_out(vty,
7516 "%4s %-5s %-16s %9s %10s %-37s %-10s %-15s\n",
7517 "Type", "Id", "routerId", "#PeersVfg",
7518 "#PeersEstb", "Name", "L3-VNI", "Rmac");
7519
7520 peers_cfg = peers_estb = 0;
7521 if (uj)
7522 json_vrf = json_object_new_object();
7523
7524
7525 for (ALL_LIST_ELEMENTS(bgp->peer, node2, nnode2, peer)) {
7526 if (!CHECK_FLAG(peer->flags, PEER_FLAG_CONFIG_NODE))
7527 continue;
7528 peers_cfg++;
7529 if (peer->status == Established)
7530 peers_estb++;
7531 }
7532
7533 if (bgp->inst_type == BGP_INSTANCE_TYPE_DEFAULT) {
7534 name = VRF_DEFAULT_NAME;
7535 type = "DFLT";
7536 } else {
7537 name = bgp->name;
7538 type = "VRF";
7539 }
7540
7541
7542 if (uj) {
7543 int64_t vrf_id_ui = (bgp->vrf_id == VRF_UNKNOWN)
7544 ? -1
7545 : (int64_t)bgp->vrf_id;
7546 json_object_string_add(json_vrf, "type", type);
7547 json_object_int_add(json_vrf, "vrfId", vrf_id_ui);
7548 json_object_string_add(json_vrf, "routerId",
7549 inet_ntoa(bgp->router_id));
7550 json_object_int_add(json_vrf, "numConfiguredPeers",
7551 peers_cfg);
7552 json_object_int_add(json_vrf, "numEstablishedPeers",
7553 peers_estb);
7554
7555 json_object_int_add(json_vrf, "l3vni", bgp->l3vni);
7556 json_object_string_add(
7557 json_vrf, "rmac",
7558 prefix_mac2str(&bgp->rmac, buf, sizeof(buf)));
7559 json_object_object_add(json_vrfs, name, json_vrf);
7560 } else
7561 vty_out(vty,
7562 "%4s %-5d %-16s %9u %10u %-37s %-10u %-15s\n",
7563 type,
7564 bgp->vrf_id == VRF_UNKNOWN ? -1
7565 : (int)bgp->vrf_id,
7566 inet_ntoa(bgp->router_id), peers_cfg,
7567 peers_estb, name, bgp->l3vni,
7568 prefix_mac2str(&bgp->rmac, buf, sizeof(buf)));
7569 }
7570
7571 if (uj) {
7572 json_object_object_add(json, "vrfs", json_vrfs);
7573
7574 json_object_int_add(json, "totalVrfs", count);
7575
7576 vty_out(vty, "%s\n", json_object_to_json_string_ext(
7577 json, JSON_C_TO_STRING_PRETTY));
7578 json_object_free(json);
7579 } else {
7580 if (count)
7581 vty_out(vty,
7582 "\nTotal number of VRFs (including default): %d\n",
7583 count);
7584 }
7585
7586 return CMD_SUCCESS;
7587 }
7588
7589 DEFUN (show_bgp_mac_hash,
7590 show_bgp_mac_hash_cmd,
7591 "show bgp mac hash",
7592 SHOW_STR
7593 BGP_STR
7594 "Mac Address\n"
7595 "Mac Address database\n")
7596 {
7597 bgp_mac_dump_table(vty);
7598
7599 return CMD_SUCCESS;
7600 }
7601
7602 static void show_tip_entry(struct hash_bucket *bucket, void *args)
7603 {
7604 struct vty *vty = (struct vty *)args;
7605 struct tip_addr *tip = (struct tip_addr *)bucket->data;
7606
7607 vty_out(vty, "addr: %s, count: %d\n", inet_ntoa(tip->addr),
7608 tip->refcnt);
7609 }
7610
7611 static void bgp_show_martian_nexthops(struct vty *vty, struct bgp *bgp)
7612 {
7613 vty_out(vty, "self nexthop database:\n");
7614 bgp_nexthop_show_address_hash(vty, bgp);
7615
7616 vty_out(vty, "Tunnel-ip database:\n");
7617 hash_iterate(bgp->tip_hash,
7618 (void (*)(struct hash_bucket *, void *))show_tip_entry,
7619 vty);
7620 }
7621
7622 DEFUN(show_bgp_martian_nexthop_db, show_bgp_martian_nexthop_db_cmd,
7623 "show bgp [<view|vrf> VIEWVRFNAME] martian next-hop",
7624 SHOW_STR BGP_STR BGP_INSTANCE_HELP_STR
7625 "martian next-hops\n"
7626 "martian next-hop database\n")
7627 {
7628 struct bgp *bgp = NULL;
7629 int idx = 0;
7630 char *name = NULL;
7631
7632 /* [<vrf> VIEWVRFNAME] */
7633 if (argv_find(argv, argc, "vrf", &idx)) {
7634 name = argv[idx + 1]->arg;
7635 if (name && strmatch(name, VRF_DEFAULT_NAME))
7636 name = NULL;
7637 } else if (argv_find(argv, argc, "view", &idx))
7638 /* [<view> VIEWVRFNAME] */
7639 name = argv[idx + 1]->arg;
7640 if (name)
7641 bgp = bgp_lookup_by_name(name);
7642 else
7643 bgp = bgp_get_default();
7644
7645 if (!bgp) {
7646 vty_out(vty, "%% No BGP process is configured\n");
7647 return CMD_WARNING;
7648 }
7649 bgp_show_martian_nexthops(vty, bgp);
7650
7651 return CMD_SUCCESS;
7652 }
7653
7654 DEFUN (show_bgp_memory,
7655 show_bgp_memory_cmd,
7656 "show [ip] bgp memory",
7657 SHOW_STR
7658 IP_STR
7659 BGP_STR
7660 "Global BGP memory statistics\n")
7661 {
7662 char memstrbuf[MTYPE_MEMSTR_LEN];
7663 unsigned long count;
7664
7665 /* RIB related usage stats */
7666 count = mtype_stats_alloc(MTYPE_BGP_NODE);
7667 vty_out(vty, "%ld RIB nodes, using %s of memory\n", count,
7668 mtype_memstr(memstrbuf, sizeof(memstrbuf),
7669 count * sizeof(struct bgp_node)));
7670
7671 count = mtype_stats_alloc(MTYPE_BGP_ROUTE);
7672 vty_out(vty, "%ld BGP routes, using %s of memory\n", count,
7673 mtype_memstr(memstrbuf, sizeof(memstrbuf),
7674 count * sizeof(struct bgp_path_info)));
7675 if ((count = mtype_stats_alloc(MTYPE_BGP_ROUTE_EXTRA)))
7676 vty_out(vty, "%ld BGP route ancillaries, using %s of memory\n",
7677 count,
7678 mtype_memstr(
7679 memstrbuf, sizeof(memstrbuf),
7680 count * sizeof(struct bgp_path_info_extra)));
7681
7682 if ((count = mtype_stats_alloc(MTYPE_BGP_STATIC)))
7683 vty_out(vty, "%ld Static routes, using %s of memory\n", count,
7684 mtype_memstr(memstrbuf, sizeof(memstrbuf),
7685 count * sizeof(struct bgp_static)));
7686
7687 if ((count = mtype_stats_alloc(MTYPE_BGP_PACKET)))
7688 vty_out(vty, "%ld Packets, using %s of memory\n", count,
7689 mtype_memstr(memstrbuf, sizeof(memstrbuf),
7690 count * sizeof(struct bpacket)));
7691
7692 /* Adj-In/Out */
7693 if ((count = mtype_stats_alloc(MTYPE_BGP_ADJ_IN)))
7694 vty_out(vty, "%ld Adj-In entries, using %s of memory\n", count,
7695 mtype_memstr(memstrbuf, sizeof(memstrbuf),
7696 count * sizeof(struct bgp_adj_in)));
7697 if ((count = mtype_stats_alloc(MTYPE_BGP_ADJ_OUT)))
7698 vty_out(vty, "%ld Adj-Out entries, using %s of memory\n", count,
7699 mtype_memstr(memstrbuf, sizeof(memstrbuf),
7700 count * sizeof(struct bgp_adj_out)));
7701
7702 if ((count = mtype_stats_alloc(MTYPE_BGP_NEXTHOP_CACHE)))
7703 vty_out(vty, "%ld Nexthop cache entries, using %s of memory\n",
7704 count,
7705 mtype_memstr(memstrbuf, sizeof(memstrbuf),
7706 count * sizeof(struct bgp_nexthop_cache)));
7707
7708 if ((count = mtype_stats_alloc(MTYPE_BGP_DAMP_INFO)))
7709 vty_out(vty, "%ld Dampening entries, using %s of memory\n",
7710 count,
7711 mtype_memstr(memstrbuf, sizeof(memstrbuf),
7712 count * sizeof(struct bgp_damp_info)));
7713
7714 /* Attributes */
7715 count = attr_count();
7716 vty_out(vty, "%ld BGP attributes, using %s of memory\n", count,
7717 mtype_memstr(memstrbuf, sizeof(memstrbuf),
7718 count * sizeof(struct attr)));
7719
7720 if ((count = attr_unknown_count()))
7721 vty_out(vty, "%ld unknown attributes\n", count);
7722
7723 /* AS_PATH attributes */
7724 count = aspath_count();
7725 vty_out(vty, "%ld BGP AS-PATH entries, using %s of memory\n", count,
7726 mtype_memstr(memstrbuf, sizeof(memstrbuf),
7727 count * sizeof(struct aspath)));
7728
7729 count = mtype_stats_alloc(MTYPE_AS_SEG);
7730 vty_out(vty, "%ld BGP AS-PATH segments, using %s of memory\n", count,
7731 mtype_memstr(memstrbuf, sizeof(memstrbuf),
7732 count * sizeof(struct assegment)));
7733
7734 /* Other attributes */
7735 if ((count = community_count()))
7736 vty_out(vty, "%ld BGP community entries, using %s of memory\n",
7737 count, mtype_memstr(memstrbuf, sizeof(memstrbuf),
7738 count * sizeof(struct community)));
7739 if ((count = mtype_stats_alloc(MTYPE_ECOMMUNITY)))
7740 vty_out(vty, "%ld BGP community entries, using %s of memory\n",
7741 count, mtype_memstr(memstrbuf, sizeof(memstrbuf),
7742 count * sizeof(struct ecommunity)));
7743 if ((count = mtype_stats_alloc(MTYPE_LCOMMUNITY)))
7744 vty_out(vty,
7745 "%ld BGP large-community entries, using %s of memory\n",
7746 count, mtype_memstr(memstrbuf, sizeof(memstrbuf),
7747 count * sizeof(struct lcommunity)));
7748
7749 if ((count = mtype_stats_alloc(MTYPE_CLUSTER)))
7750 vty_out(vty, "%ld Cluster lists, using %s of memory\n", count,
7751 mtype_memstr(memstrbuf, sizeof(memstrbuf),
7752 count * sizeof(struct cluster_list)));
7753
7754 /* Peer related usage */
7755 count = mtype_stats_alloc(MTYPE_BGP_PEER);
7756 vty_out(vty, "%ld peers, using %s of memory\n", count,
7757 mtype_memstr(memstrbuf, sizeof(memstrbuf),
7758 count * sizeof(struct peer)));
7759
7760 if ((count = mtype_stats_alloc(MTYPE_PEER_GROUP)))
7761 vty_out(vty, "%ld peer groups, using %s of memory\n", count,
7762 mtype_memstr(memstrbuf, sizeof(memstrbuf),
7763 count * sizeof(struct peer_group)));
7764
7765 /* Other */
7766 if ((count = mtype_stats_alloc(MTYPE_HASH)))
7767 vty_out(vty, "%ld hash tables, using %s of memory\n", count,
7768 mtype_memstr(memstrbuf, sizeof(memstrbuf),
7769 count * sizeof(struct hash)));
7770 if ((count = mtype_stats_alloc(MTYPE_HASH_BACKET)))
7771 vty_out(vty, "%ld hash buckets, using %s of memory\n", count,
7772 mtype_memstr(memstrbuf, sizeof(memstrbuf),
7773 count * sizeof(struct hash_bucket)));
7774 if ((count = mtype_stats_alloc(MTYPE_BGP_REGEXP)))
7775 vty_out(vty, "%ld compiled regexes, using %s of memory\n",
7776 count, mtype_memstr(memstrbuf, sizeof(memstrbuf),
7777 count * sizeof(regex_t)));
7778 return CMD_SUCCESS;
7779 }
7780
7781 static void bgp_show_bestpath_json(struct bgp *bgp, json_object *json)
7782 {
7783 json_object *bestpath = json_object_new_object();
7784
7785 if (bgp_flag_check(bgp, BGP_FLAG_ASPATH_IGNORE))
7786 json_object_string_add(bestpath, "asPath", "ignore");
7787
7788 if (bgp_flag_check(bgp, BGP_FLAG_ASPATH_CONFED))
7789 json_object_string_add(bestpath, "asPath", "confed");
7790
7791 if (bgp_flag_check(bgp, BGP_FLAG_ASPATH_MULTIPATH_RELAX)) {
7792 if (bgp_flag_check(bgp, BGP_FLAG_MULTIPATH_RELAX_AS_SET))
7793 json_object_string_add(bestpath, "multiPathRelax",
7794 "as-set");
7795 else
7796 json_object_string_add(bestpath, "multiPathRelax",
7797 "true");
7798 } else
7799 json_object_string_add(bestpath, "multiPathRelax", "false");
7800
7801 if (bgp_flag_check(bgp, BGP_FLAG_COMPARE_ROUTER_ID))
7802 json_object_string_add(bestpath, "compareRouterId", "true");
7803 if (bgp_flag_check(bgp, BGP_FLAG_MED_CONFED)
7804 || bgp_flag_check(bgp, BGP_FLAG_MED_MISSING_AS_WORST)) {
7805 if (bgp_flag_check(bgp, BGP_FLAG_MED_CONFED))
7806 json_object_string_add(bestpath, "med", "confed");
7807 if (bgp_flag_check(bgp, BGP_FLAG_MED_MISSING_AS_WORST))
7808 json_object_string_add(bestpath, "med",
7809 "missing-as-worst");
7810 else
7811 json_object_string_add(bestpath, "med", "true");
7812 }
7813
7814 json_object_object_add(json, "bestPath", bestpath);
7815 }
7816
7817 /* Show BGP peer's summary information. */
7818 static int bgp_show_summary(struct vty *vty, struct bgp *bgp, int afi, int safi,
7819 bool use_json, json_object *json)
7820 {
7821 struct peer *peer;
7822 struct listnode *node, *nnode;
7823 unsigned int count = 0, dn_count = 0;
7824 char timebuf[BGP_UPTIME_LEN], dn_flag[2];
7825 char neighbor_buf[VTY_BUFSIZ];
7826 int neighbor_col_default_width = 16;
7827 int len;
7828 int max_neighbor_width = 0;
7829 int pfx_rcd_safi;
7830 json_object *json_peer = NULL;
7831 json_object *json_peers = NULL;
7832 struct peer_af *paf;
7833
7834 /* labeled-unicast routes are installed in the unicast table so in order
7835 * to
7836 * display the correct PfxRcd value we must look at SAFI_UNICAST
7837 */
7838 if (safi == SAFI_LABELED_UNICAST)
7839 pfx_rcd_safi = SAFI_UNICAST;
7840 else
7841 pfx_rcd_safi = safi;
7842
7843 if (use_json) {
7844 if (json == NULL)
7845 json = json_object_new_object();
7846
7847 json_peers = json_object_new_object();
7848 } else {
7849 /* Loop over all neighbors that will be displayed to determine
7850 * how many
7851 * characters are needed for the Neighbor column
7852 */
7853 for (ALL_LIST_ELEMENTS(bgp->peer, node, nnode, peer)) {
7854 if (!CHECK_FLAG(peer->flags, PEER_FLAG_CONFIG_NODE))
7855 continue;
7856
7857 if (peer->afc[afi][safi]) {
7858 memset(dn_flag, '\0', sizeof(dn_flag));
7859 if (peer_dynamic_neighbor(peer))
7860 dn_flag[0] = '*';
7861
7862 if (peer->hostname
7863 && bgp_flag_check(bgp,
7864 BGP_FLAG_SHOW_HOSTNAME))
7865 sprintf(neighbor_buf, "%s%s(%s) ",
7866 dn_flag, peer->hostname,
7867 peer->host);
7868 else
7869 sprintf(neighbor_buf, "%s%s ", dn_flag,
7870 peer->host);
7871
7872 len = strlen(neighbor_buf);
7873
7874 if (len > max_neighbor_width)
7875 max_neighbor_width = len;
7876 }
7877 }
7878
7879 /* Originally we displayed the Neighbor column as 16
7880 * characters wide so make that the default
7881 */
7882 if (max_neighbor_width < neighbor_col_default_width)
7883 max_neighbor_width = neighbor_col_default_width;
7884 }
7885
7886 for (ALL_LIST_ELEMENTS(bgp->peer, node, nnode, peer)) {
7887 if (!CHECK_FLAG(peer->flags, PEER_FLAG_CONFIG_NODE))
7888 continue;
7889
7890 if (!peer->afc[afi][safi])
7891 continue;
7892
7893 if (!count) {
7894 unsigned long ents;
7895 char memstrbuf[MTYPE_MEMSTR_LEN];
7896 int64_t vrf_id_ui;
7897
7898 vrf_id_ui = (bgp->vrf_id == VRF_UNKNOWN)
7899 ? -1
7900 : (int64_t)bgp->vrf_id;
7901
7902 /* Usage summary and header */
7903 if (use_json) {
7904 json_object_string_add(
7905 json, "routerId",
7906 inet_ntoa(bgp->router_id));
7907 json_object_int_add(json, "as", bgp->as);
7908 json_object_int_add(json, "vrfId", vrf_id_ui);
7909 json_object_string_add(
7910 json, "vrfName",
7911 (bgp->inst_type
7912 == BGP_INSTANCE_TYPE_DEFAULT)
7913 ? VRF_DEFAULT_NAME
7914 : bgp->name);
7915 } else {
7916 vty_out(vty,
7917 "BGP router identifier %s, local AS number %u vrf-id %d",
7918 inet_ntoa(bgp->router_id), bgp->as,
7919 bgp->vrf_id == VRF_UNKNOWN
7920 ? -1
7921 : (int)bgp->vrf_id);
7922 vty_out(vty, "\n");
7923 }
7924
7925 if (bgp_update_delay_configured(bgp)) {
7926 if (use_json) {
7927 json_object_int_add(
7928 json, "updateDelayLimit",
7929 bgp->v_update_delay);
7930
7931 if (bgp->v_update_delay
7932 != bgp->v_establish_wait)
7933 json_object_int_add(
7934 json,
7935 "updateDelayEstablishWait",
7936 bgp->v_establish_wait);
7937
7938 if (bgp_update_delay_active(bgp)) {
7939 json_object_string_add(
7940 json,
7941 "updateDelayFirstNeighbor",
7942 bgp->update_delay_begin_time);
7943 json_object_boolean_true_add(
7944 json,
7945 "updateDelayInProgress");
7946 } else {
7947 if (bgp->update_delay_over) {
7948 json_object_string_add(
7949 json,
7950 "updateDelayFirstNeighbor",
7951 bgp->update_delay_begin_time);
7952 json_object_string_add(
7953 json,
7954 "updateDelayBestpathResumed",
7955 bgp->update_delay_end_time);
7956 json_object_string_add(
7957 json,
7958 "updateDelayZebraUpdateResume",
7959 bgp->update_delay_zebra_resume_time);
7960 json_object_string_add(
7961 json,
7962 "updateDelayPeerUpdateResume",
7963 bgp->update_delay_peers_resume_time);
7964 }
7965 }
7966 } else {
7967 vty_out(vty,
7968 "Read-only mode update-delay limit: %d seconds\n",
7969 bgp->v_update_delay);
7970 if (bgp->v_update_delay
7971 != bgp->v_establish_wait)
7972 vty_out(vty,
7973 " Establish wait: %d seconds\n",
7974 bgp->v_establish_wait);
7975
7976 if (bgp_update_delay_active(bgp)) {
7977 vty_out(vty,
7978 " First neighbor established: %s\n",
7979 bgp->update_delay_begin_time);
7980 vty_out(vty,
7981 " Delay in progress\n");
7982 } else {
7983 if (bgp->update_delay_over) {
7984 vty_out(vty,
7985 " First neighbor established: %s\n",
7986 bgp->update_delay_begin_time);
7987 vty_out(vty,
7988 " Best-paths resumed: %s\n",
7989 bgp->update_delay_end_time);
7990 vty_out(vty,
7991 " zebra update resumed: %s\n",
7992 bgp->update_delay_zebra_resume_time);
7993 vty_out(vty,
7994 " peers update resumed: %s\n",
7995 bgp->update_delay_peers_resume_time);
7996 }
7997 }
7998 }
7999 }
8000
8001 if (use_json) {
8002 if (bgp_maxmed_onstartup_configured(bgp)
8003 && bgp->maxmed_active)
8004 json_object_boolean_true_add(
8005 json, "maxMedOnStartup");
8006 if (bgp->v_maxmed_admin)
8007 json_object_boolean_true_add(
8008 json, "maxMedAdministrative");
8009
8010 json_object_int_add(
8011 json, "tableVersion",
8012 bgp_table_version(bgp->rib[afi][safi]));
8013
8014 ents = bgp_table_count(bgp->rib[afi][safi]);
8015 json_object_int_add(json, "ribCount", ents);
8016 json_object_int_add(
8017 json, "ribMemory",
8018 ents * sizeof(struct bgp_node));
8019
8020 ents = bgp->af_peer_count[afi][safi];
8021 json_object_int_add(json, "peerCount", ents);
8022 json_object_int_add(json, "peerMemory",
8023 ents * sizeof(struct peer));
8024
8025 if ((ents = listcount(bgp->group))) {
8026 json_object_int_add(
8027 json, "peerGroupCount", ents);
8028 json_object_int_add(
8029 json, "peerGroupMemory",
8030 ents * sizeof(struct
8031 peer_group));
8032 }
8033
8034 if (CHECK_FLAG(bgp->af_flags[afi][safi],
8035 BGP_CONFIG_DAMPENING))
8036 json_object_boolean_true_add(
8037 json, "dampeningEnabled");
8038 } else {
8039 if (bgp_maxmed_onstartup_configured(bgp)
8040 && bgp->maxmed_active)
8041 vty_out(vty,
8042 "Max-med on-startup active\n");
8043 if (bgp->v_maxmed_admin)
8044 vty_out(vty,
8045 "Max-med administrative active\n");
8046
8047 vty_out(vty, "BGP table version %" PRIu64 "\n",
8048 bgp_table_version(bgp->rib[afi][safi]));
8049
8050 ents = bgp_table_count(bgp->rib[afi][safi]);
8051 vty_out(vty,
8052 "RIB entries %ld, using %s of memory\n",
8053 ents,
8054 mtype_memstr(memstrbuf,
8055 sizeof(memstrbuf),
8056 ents * sizeof(struct
8057 bgp_node)));
8058
8059 /* Peer related usage */
8060 ents = bgp->af_peer_count[afi][safi];
8061 vty_out(vty, "Peers %ld, using %s of memory\n",
8062 ents,
8063 mtype_memstr(
8064 memstrbuf, sizeof(memstrbuf),
8065 ents * sizeof(struct peer)));
8066
8067 if ((ents = listcount(bgp->group)))
8068 vty_out(vty,
8069 "Peer groups %ld, using %s of memory\n",
8070 ents,
8071 mtype_memstr(
8072 memstrbuf,
8073 sizeof(memstrbuf),
8074 ents * sizeof(struct
8075 peer_group)));
8076
8077 if (CHECK_FLAG(bgp->af_flags[afi][safi],
8078 BGP_CONFIG_DAMPENING))
8079 vty_out(vty, "Dampening enabled.\n");
8080 vty_out(vty, "\n");
8081
8082 /* Subtract 8 here because 'Neighbor' is
8083 * 8 characters */
8084 vty_out(vty, "Neighbor");
8085 vty_out(vty, "%*s", max_neighbor_width - 8,
8086 " ");
8087 vty_out(vty,
8088 "V AS MsgRcvd MsgSent TblVer InQ OutQ Up/Down State/PfxRcd\n");
8089 }
8090 }
8091
8092 count++;
8093
8094 if (use_json) {
8095 json_peer = json_object_new_object();
8096
8097 if (peer_dynamic_neighbor(peer)) {
8098 dn_count++;
8099 json_object_boolean_true_add(json_peer,
8100 "dynamicPeer");
8101 }
8102
8103 if (peer->hostname)
8104 json_object_string_add(json_peer, "hostname",
8105 peer->hostname);
8106
8107 if (peer->domainname)
8108 json_object_string_add(json_peer, "domainname",
8109 peer->domainname);
8110
8111 json_object_int_add(json_peer, "remoteAs", peer->as);
8112 json_object_int_add(json_peer, "version", 4);
8113 json_object_int_add(json_peer, "msgRcvd",
8114 PEER_TOTAL_RX(peer));
8115 json_object_int_add(json_peer, "msgSent",
8116 PEER_TOTAL_TX(peer));
8117
8118 json_object_int_add(json_peer, "tableVersion",
8119 peer->version[afi][safi]);
8120 json_object_int_add(json_peer, "outq",
8121 peer->obuf->count);
8122 json_object_int_add(json_peer, "inq", 0);
8123 peer_uptime(peer->uptime, timebuf, BGP_UPTIME_LEN,
8124 use_json, json_peer);
8125
8126 /*
8127 * Adding "pfxRcd" field to match with the corresponding
8128 * CLI. "prefixReceivedCount" will be deprecated in
8129 * future.
8130 */
8131 json_object_int_add(json_peer, "prefixReceivedCount",
8132 peer->pcount[afi][pfx_rcd_safi]);
8133 json_object_int_add(json_peer, "pfxRcd",
8134 peer->pcount[afi][pfx_rcd_safi]);
8135
8136 paf = peer_af_find(peer, afi, pfx_rcd_safi);
8137 if (paf && PAF_SUBGRP(paf))
8138 json_object_int_add(json_peer,
8139 "pfxSnt",
8140 (PAF_SUBGRP(paf))->scount);
8141
8142 if (CHECK_FLAG(peer->flags, PEER_FLAG_SHUTDOWN))
8143 json_object_string_add(json_peer, "state",
8144 "Idle (Admin)");
8145 else if (peer->afc_recv[afi][safi])
8146 json_object_string_add(
8147 json_peer, "state",
8148 lookup_msg(bgp_status_msg, peer->status,
8149 NULL));
8150 else if (CHECK_FLAG(peer->sflags,
8151 PEER_STATUS_PREFIX_OVERFLOW))
8152 json_object_string_add(json_peer, "state",
8153 "Idle (PfxCt)");
8154 else
8155 json_object_string_add(
8156 json_peer, "state",
8157 lookup_msg(bgp_status_msg, peer->status,
8158 NULL));
8159
8160 if (peer->conf_if)
8161 json_object_string_add(json_peer, "idType",
8162 "interface");
8163 else if (peer->su.sa.sa_family == AF_INET)
8164 json_object_string_add(json_peer, "idType",
8165 "ipv4");
8166 else if (peer->su.sa.sa_family == AF_INET6)
8167 json_object_string_add(json_peer, "idType",
8168 "ipv6");
8169
8170 json_object_object_add(json_peers, peer->host,
8171 json_peer);
8172 } else {
8173 memset(dn_flag, '\0', sizeof(dn_flag));
8174 if (peer_dynamic_neighbor(peer)) {
8175 dn_count++;
8176 dn_flag[0] = '*';
8177 }
8178
8179 if (peer->hostname
8180 && bgp_flag_check(bgp, BGP_FLAG_SHOW_HOSTNAME))
8181 len = vty_out(vty, "%s%s(%s)", dn_flag,
8182 peer->hostname, peer->host);
8183 else
8184 len = vty_out(vty, "%s%s", dn_flag, peer->host);
8185
8186 /* pad the neighbor column with spaces */
8187 if (len < max_neighbor_width)
8188 vty_out(vty, "%*s", max_neighbor_width - len,
8189 " ");
8190
8191 vty_out(vty, "4 %10u %7u %7u %8" PRIu64 " %4d %4zd %8s",
8192 peer->as, PEER_TOTAL_RX(peer),
8193 PEER_TOTAL_TX(peer), peer->version[afi][safi],
8194 0, peer->obuf->count,
8195 peer_uptime(peer->uptime, timebuf,
8196 BGP_UPTIME_LEN, 0, NULL));
8197
8198 if (peer->status == Established)
8199 if (peer->afc_recv[afi][safi])
8200 vty_out(vty, " %12ld",
8201 peer->pcount[afi]
8202 [pfx_rcd_safi]);
8203 else
8204 vty_out(vty, " NoNeg");
8205 else {
8206 if (CHECK_FLAG(peer->flags, PEER_FLAG_SHUTDOWN))
8207 vty_out(vty, " Idle (Admin)");
8208 else if (CHECK_FLAG(
8209 peer->sflags,
8210 PEER_STATUS_PREFIX_OVERFLOW))
8211 vty_out(vty, " Idle (PfxCt)");
8212 else
8213 vty_out(vty, " %12s",
8214 lookup_msg(bgp_status_msg,
8215 peer->status, NULL));
8216 }
8217 vty_out(vty, "\n");
8218 }
8219 }
8220
8221 if (use_json) {
8222 json_object_object_add(json, "peers", json_peers);
8223
8224 json_object_int_add(json, "totalPeers", count);
8225 json_object_int_add(json, "dynamicPeers", dn_count);
8226
8227 bgp_show_bestpath_json(bgp, json);
8228
8229 vty_out(vty, "%s\n", json_object_to_json_string_ext(
8230 json, JSON_C_TO_STRING_PRETTY));
8231 json_object_free(json);
8232 } else {
8233 if (count)
8234 vty_out(vty, "\nTotal number of neighbors %d\n", count);
8235 else {
8236 vty_out(vty, "No %s neighbor is configured\n",
8237 afi_safi_print(afi, safi));
8238 }
8239
8240 if (dn_count) {
8241 vty_out(vty, "* - dynamic neighbor\n");
8242 vty_out(vty, "%d dynamic neighbor(s), limit %d\n",
8243 dn_count, bgp->dynamic_neighbors_limit);
8244 }
8245 }
8246
8247 return CMD_SUCCESS;
8248 }
8249
8250 static void bgp_show_summary_afi_safi(struct vty *vty, struct bgp *bgp, int afi,
8251 int safi, bool use_json,
8252 json_object *json)
8253 {
8254 int is_first = 1;
8255 int afi_wildcard = (afi == AFI_MAX);
8256 int safi_wildcard = (safi == SAFI_MAX);
8257 int is_wildcard = (afi_wildcard || safi_wildcard);
8258 bool nbr_output = false;
8259
8260 if (use_json && is_wildcard)
8261 vty_out(vty, "{\n");
8262 if (afi_wildcard)
8263 afi = 1; /* AFI_IP */
8264 while (afi < AFI_MAX) {
8265 if (safi_wildcard)
8266 safi = 1; /* SAFI_UNICAST */
8267 while (safi < SAFI_MAX) {
8268 if (bgp_afi_safi_peer_exists(bgp, afi, safi)) {
8269 nbr_output = true;
8270 if (is_wildcard) {
8271 /*
8272 * So limit output to those afi/safi
8273 * pairs that
8274 * actualy have something interesting in
8275 * them
8276 */
8277 if (use_json) {
8278 json = json_object_new_object();
8279
8280 if (!is_first)
8281 vty_out(vty, ",\n");
8282 else
8283 is_first = 0;
8284
8285 vty_out(vty, "\"%s\":",
8286 afi_safi_json(afi,
8287 safi));
8288 } else {
8289 vty_out(vty, "\n%s Summary:\n",
8290 afi_safi_print(afi,
8291 safi));
8292 }
8293 }
8294 bgp_show_summary(vty, bgp, afi, safi, use_json,
8295 json);
8296 }
8297 safi++;
8298 if (!safi_wildcard)
8299 safi = SAFI_MAX;
8300 }
8301 afi++;
8302 if (!afi_wildcard)
8303 afi = AFI_MAX;
8304 }
8305
8306 if (use_json && is_wildcard)
8307 vty_out(vty, "}\n");
8308 else if (!nbr_output) {
8309 if (use_json)
8310 vty_out(vty, "{}\n");
8311 else
8312 vty_out(vty, "%% No BGP neighbors found\n");
8313 }
8314 }
8315
8316 static void bgp_show_all_instances_summary_vty(struct vty *vty, afi_t afi,
8317 safi_t safi, bool use_json)
8318 {
8319 struct listnode *node, *nnode;
8320 struct bgp *bgp;
8321 json_object *json = NULL;
8322 int is_first = 1;
8323 bool nbr_output = false;
8324
8325 if (use_json)
8326 vty_out(vty, "{\n");
8327
8328 for (ALL_LIST_ELEMENTS(bm->bgp, node, nnode, bgp)) {
8329 nbr_output = true;
8330 if (use_json) {
8331 json = json_object_new_object();
8332
8333 if (!is_first)
8334 vty_out(vty, ",\n");
8335 else
8336 is_first = 0;
8337
8338 vty_out(vty, "\"%s\":",
8339 (bgp->inst_type == BGP_INSTANCE_TYPE_DEFAULT)
8340 ? VRF_DEFAULT_NAME
8341 : bgp->name);
8342 } else {
8343 vty_out(vty, "\nInstance %s:\n",
8344 (bgp->inst_type == BGP_INSTANCE_TYPE_DEFAULT)
8345 ? VRF_DEFAULT_NAME
8346 : bgp->name);
8347 }
8348 bgp_show_summary_afi_safi(vty, bgp, afi, safi, use_json, json);
8349 }
8350
8351 if (use_json)
8352 vty_out(vty, "}\n");
8353 else if (!nbr_output)
8354 vty_out(vty, "%% BGP instance not found\n");
8355 }
8356
8357 int bgp_show_summary_vty(struct vty *vty, const char *name, afi_t afi,
8358 safi_t safi, bool use_json)
8359 {
8360 struct bgp *bgp;
8361
8362 if (name) {
8363 if (strmatch(name, "all")) {
8364 bgp_show_all_instances_summary_vty(vty, afi, safi,
8365 use_json);
8366 return CMD_SUCCESS;
8367 } else {
8368 bgp = bgp_lookup_by_name(name);
8369
8370 if (!bgp) {
8371 if (use_json)
8372 vty_out(vty, "{}\n");
8373 else
8374 vty_out(vty,
8375 "%% BGP instance not found\n");
8376 return CMD_WARNING;
8377 }
8378
8379 bgp_show_summary_afi_safi(vty, bgp, afi, safi, use_json,
8380 NULL);
8381 return CMD_SUCCESS;
8382 }
8383 }
8384
8385 bgp = bgp_get_default();
8386
8387 if (bgp)
8388 bgp_show_summary_afi_safi(vty, bgp, afi, safi, use_json, NULL);
8389 else {
8390 if (use_json)
8391 vty_out(vty, "{}\n");
8392 else
8393 vty_out(vty, "%% BGP instance not found\n");
8394 return CMD_WARNING;
8395 }
8396
8397 return CMD_SUCCESS;
8398 }
8399
8400 /* `show [ip] bgp summary' commands. */
8401 DEFUN (show_ip_bgp_summary,
8402 show_ip_bgp_summary_cmd,
8403 "show [ip] bgp [<view|vrf> VIEWVRFNAME] ["BGP_AFI_CMD_STR" ["BGP_SAFI_WITH_LABEL_CMD_STR"]] summary [json]",
8404 SHOW_STR
8405 IP_STR
8406 BGP_STR
8407 BGP_INSTANCE_HELP_STR
8408 BGP_AFI_HELP_STR
8409 BGP_SAFI_WITH_LABEL_HELP_STR
8410 "Summary of BGP neighbor status\n"
8411 JSON_STR)
8412 {
8413 char *vrf = NULL;
8414 afi_t afi = AFI_MAX;
8415 safi_t safi = SAFI_MAX;
8416
8417 int idx = 0;
8418
8419 /* show [ip] bgp */
8420 if (argv_find(argv, argc, "ip", &idx))
8421 afi = AFI_IP;
8422 /* [<vrf> VIEWVRFNAME] */
8423 if (argv_find(argv, argc, "vrf", &idx)) {
8424 vrf = argv[idx + 1]->arg;
8425 if (vrf && strmatch(vrf, VRF_DEFAULT_NAME))
8426 vrf = NULL;
8427 } else if (argv_find(argv, argc, "view", &idx))
8428 /* [<view> VIEWVRFNAME] */
8429 vrf = argv[idx + 1]->arg;
8430 /* ["BGP_AFI_CMD_STR" ["BGP_SAFI_CMD_STR"]] */
8431 if (argv_find_and_parse_afi(argv, argc, &idx, &afi)) {
8432 argv_find_and_parse_safi(argv, argc, &idx, &safi);
8433 }
8434
8435 bool uj = use_json(argc, argv);
8436
8437 return bgp_show_summary_vty(vty, vrf, afi, safi, uj);
8438 }
8439
8440 const char *afi_safi_print(afi_t afi, safi_t safi)
8441 {
8442 if (afi == AFI_IP && safi == SAFI_UNICAST)
8443 return "IPv4 Unicast";
8444 else if (afi == AFI_IP && safi == SAFI_MULTICAST)
8445 return "IPv4 Multicast";
8446 else if (afi == AFI_IP && safi == SAFI_LABELED_UNICAST)
8447 return "IPv4 Labeled Unicast";
8448 else if (afi == AFI_IP && safi == SAFI_MPLS_VPN)
8449 return "IPv4 VPN";
8450 else if (afi == AFI_IP && safi == SAFI_ENCAP)
8451 return "IPv4 Encap";
8452 else if (afi == AFI_IP && safi == SAFI_FLOWSPEC)
8453 return "IPv4 Flowspec";
8454 else if (afi == AFI_IP6 && safi == SAFI_UNICAST)
8455 return "IPv6 Unicast";
8456 else if (afi == AFI_IP6 && safi == SAFI_MULTICAST)
8457 return "IPv6 Multicast";
8458 else if (afi == AFI_IP6 && safi == SAFI_LABELED_UNICAST)
8459 return "IPv6 Labeled Unicast";
8460 else if (afi == AFI_IP6 && safi == SAFI_MPLS_VPN)
8461 return "IPv6 VPN";
8462 else if (afi == AFI_IP6 && safi == SAFI_ENCAP)
8463 return "IPv6 Encap";
8464 else if (afi == AFI_IP6 && safi == SAFI_FLOWSPEC)
8465 return "IPv6 Flowspec";
8466 else if (afi == AFI_L2VPN && safi == SAFI_EVPN)
8467 return "L2VPN EVPN";
8468 else
8469 return "Unknown";
8470 }
8471
8472 /*
8473 * Please note that we have intentionally camelCased
8474 * the return strings here. So if you want
8475 * to use this function, please ensure you
8476 * are doing this within json output
8477 */
8478 const char *afi_safi_json(afi_t afi, safi_t safi)
8479 {
8480 if (afi == AFI_IP && safi == SAFI_UNICAST)
8481 return "ipv4Unicast";
8482 else if (afi == AFI_IP && safi == SAFI_MULTICAST)
8483 return "ipv4Multicast";
8484 else if (afi == AFI_IP && safi == SAFI_LABELED_UNICAST)
8485 return "ipv4LabeledUnicast";
8486 else if (afi == AFI_IP && safi == SAFI_MPLS_VPN)
8487 return "ipv4Vpn";
8488 else if (afi == AFI_IP && safi == SAFI_ENCAP)
8489 return "ipv4Encap";
8490 else if (afi == AFI_IP && safi == SAFI_FLOWSPEC)
8491 return "ipv4Flowspec";
8492 else if (afi == AFI_IP6 && safi == SAFI_UNICAST)
8493 return "ipv6Unicast";
8494 else if (afi == AFI_IP6 && safi == SAFI_MULTICAST)
8495 return "ipv6Multicast";
8496 else if (afi == AFI_IP6 && safi == SAFI_LABELED_UNICAST)
8497 return "ipv6LabeledUnicast";
8498 else if (afi == AFI_IP6 && safi == SAFI_MPLS_VPN)
8499 return "ipv6Vpn";
8500 else if (afi == AFI_IP6 && safi == SAFI_ENCAP)
8501 return "ipv6Encap";
8502 else if (afi == AFI_IP6 && safi == SAFI_FLOWSPEC)
8503 return "ipv6Flowspec";
8504 else if (afi == AFI_L2VPN && safi == SAFI_EVPN)
8505 return "l2VpnEvpn";
8506 else
8507 return "Unknown";
8508 }
8509
8510 /* Show BGP peer's information. */
8511 enum show_type { show_all, show_peer, show_ipv4_all, show_ipv6_all, show_ipv4_peer, show_ipv6_peer };
8512
8513 static void bgp_show_peer_afi_orf_cap(struct vty *vty, struct peer *p,
8514 afi_t afi, safi_t safi,
8515 uint16_t adv_smcap, uint16_t adv_rmcap,
8516 uint16_t rcv_smcap, uint16_t rcv_rmcap,
8517 bool use_json, json_object *json_pref)
8518 {
8519 /* Send-Mode */
8520 if (CHECK_FLAG(p->af_cap[afi][safi], adv_smcap)
8521 || CHECK_FLAG(p->af_cap[afi][safi], rcv_smcap)) {
8522 if (use_json) {
8523 if (CHECK_FLAG(p->af_cap[afi][safi], adv_smcap)
8524 && CHECK_FLAG(p->af_cap[afi][safi], rcv_smcap))
8525 json_object_string_add(json_pref, "sendMode",
8526 "advertisedAndReceived");
8527 else if (CHECK_FLAG(p->af_cap[afi][safi], adv_smcap))
8528 json_object_string_add(json_pref, "sendMode",
8529 "advertised");
8530 else if (CHECK_FLAG(p->af_cap[afi][safi], rcv_smcap))
8531 json_object_string_add(json_pref, "sendMode",
8532 "received");
8533 } else {
8534 vty_out(vty, " Send-mode: ");
8535 if (CHECK_FLAG(p->af_cap[afi][safi], adv_smcap))
8536 vty_out(vty, "advertised");
8537 if (CHECK_FLAG(p->af_cap[afi][safi], rcv_smcap))
8538 vty_out(vty, "%sreceived",
8539 CHECK_FLAG(p->af_cap[afi][safi],
8540 adv_smcap)
8541 ? ", "
8542 : "");
8543 vty_out(vty, "\n");
8544 }
8545 }
8546
8547 /* Receive-Mode */
8548 if (CHECK_FLAG(p->af_cap[afi][safi], adv_rmcap)
8549 || CHECK_FLAG(p->af_cap[afi][safi], rcv_rmcap)) {
8550 if (use_json) {
8551 if (CHECK_FLAG(p->af_cap[afi][safi], adv_rmcap)
8552 && CHECK_FLAG(p->af_cap[afi][safi], rcv_rmcap))
8553 json_object_string_add(json_pref, "recvMode",
8554 "advertisedAndReceived");
8555 else if (CHECK_FLAG(p->af_cap[afi][safi], adv_rmcap))
8556 json_object_string_add(json_pref, "recvMode",
8557 "advertised");
8558 else if (CHECK_FLAG(p->af_cap[afi][safi], rcv_rmcap))
8559 json_object_string_add(json_pref, "recvMode",
8560 "received");
8561 } else {
8562 vty_out(vty, " Receive-mode: ");
8563 if (CHECK_FLAG(p->af_cap[afi][safi], adv_rmcap))
8564 vty_out(vty, "advertised");
8565 if (CHECK_FLAG(p->af_cap[afi][safi], rcv_rmcap))
8566 vty_out(vty, "%sreceived",
8567 CHECK_FLAG(p->af_cap[afi][safi],
8568 adv_rmcap)
8569 ? ", "
8570 : "");
8571 vty_out(vty, "\n");
8572 }
8573 }
8574 }
8575
8576 static void bgp_show_peer_afi(struct vty *vty, struct peer *p, afi_t afi,
8577 safi_t safi, bool use_json,
8578 json_object *json_neigh)
8579 {
8580 struct bgp_filter *filter;
8581 struct peer_af *paf;
8582 char orf_pfx_name[BUFSIZ];
8583 int orf_pfx_count;
8584 json_object *json_af = NULL;
8585 json_object *json_prefA = NULL;
8586 json_object *json_prefB = NULL;
8587 json_object *json_addr = NULL;
8588
8589 if (use_json) {
8590 json_addr = json_object_new_object();
8591 json_af = json_object_new_object();
8592 filter = &p->filter[afi][safi];
8593
8594 if (peer_group_active(p))
8595 json_object_string_add(json_addr, "peerGroupMember",
8596 p->group->name);
8597
8598 paf = peer_af_find(p, afi, safi);
8599 if (paf && PAF_SUBGRP(paf)) {
8600 json_object_int_add(json_addr, "updateGroupId",
8601 PAF_UPDGRP(paf)->id);
8602 json_object_int_add(json_addr, "subGroupId",
8603 PAF_SUBGRP(paf)->id);
8604 json_object_int_add(json_addr, "packetQueueLength",
8605 bpacket_queue_virtual_length(paf));
8606 }
8607
8608 if (CHECK_FLAG(p->af_cap[afi][safi], PEER_CAP_ORF_PREFIX_SM_ADV)
8609 || CHECK_FLAG(p->af_cap[afi][safi],
8610 PEER_CAP_ORF_PREFIX_SM_RCV)
8611 || CHECK_FLAG(p->af_cap[afi][safi],
8612 PEER_CAP_ORF_PREFIX_RM_ADV)
8613 || CHECK_FLAG(p->af_cap[afi][safi],
8614 PEER_CAP_ORF_PREFIX_RM_RCV)) {
8615 json_object_int_add(json_af, "orfType",
8616 ORF_TYPE_PREFIX);
8617 json_prefA = json_object_new_object();
8618 bgp_show_peer_afi_orf_cap(vty, p, afi, safi,
8619 PEER_CAP_ORF_PREFIX_SM_ADV,
8620 PEER_CAP_ORF_PREFIX_RM_ADV,
8621 PEER_CAP_ORF_PREFIX_SM_RCV,
8622 PEER_CAP_ORF_PREFIX_RM_RCV,
8623 use_json, json_prefA);
8624 json_object_object_add(json_af, "orfPrefixList",
8625 json_prefA);
8626 }
8627
8628 if (CHECK_FLAG(p->af_cap[afi][safi], PEER_CAP_ORF_PREFIX_SM_ADV)
8629 || CHECK_FLAG(p->af_cap[afi][safi],
8630 PEER_CAP_ORF_PREFIX_SM_OLD_RCV)
8631 || CHECK_FLAG(p->af_cap[afi][safi],
8632 PEER_CAP_ORF_PREFIX_RM_ADV)
8633 || CHECK_FLAG(p->af_cap[afi][safi],
8634 PEER_CAP_ORF_PREFIX_RM_OLD_RCV)) {
8635 json_object_int_add(json_af, "orfOldType",
8636 ORF_TYPE_PREFIX_OLD);
8637 json_prefB = json_object_new_object();
8638 bgp_show_peer_afi_orf_cap(
8639 vty, p, afi, safi, PEER_CAP_ORF_PREFIX_SM_ADV,
8640 PEER_CAP_ORF_PREFIX_RM_ADV,
8641 PEER_CAP_ORF_PREFIX_SM_OLD_RCV,
8642 PEER_CAP_ORF_PREFIX_RM_OLD_RCV, use_json,
8643 json_prefB);
8644 json_object_object_add(json_af, "orfOldPrefixList",
8645 json_prefB);
8646 }
8647
8648 if (CHECK_FLAG(p->af_cap[afi][safi], PEER_CAP_ORF_PREFIX_SM_ADV)
8649 || CHECK_FLAG(p->af_cap[afi][safi],
8650 PEER_CAP_ORF_PREFIX_SM_RCV)
8651 || CHECK_FLAG(p->af_cap[afi][safi],
8652 PEER_CAP_ORF_PREFIX_SM_OLD_RCV)
8653 || CHECK_FLAG(p->af_cap[afi][safi],
8654 PEER_CAP_ORF_PREFIX_RM_ADV)
8655 || CHECK_FLAG(p->af_cap[afi][safi],
8656 PEER_CAP_ORF_PREFIX_RM_RCV)
8657 || CHECK_FLAG(p->af_cap[afi][safi],
8658 PEER_CAP_ORF_PREFIX_RM_OLD_RCV))
8659 json_object_object_add(json_addr, "afDependentCap",
8660 json_af);
8661 else
8662 json_object_free(json_af);
8663
8664 sprintf(orf_pfx_name, "%s.%d.%d", p->host, afi, safi);
8665 orf_pfx_count = prefix_bgp_show_prefix_list(
8666 NULL, afi, orf_pfx_name, use_json);
8667
8668 if (CHECK_FLAG(p->af_sflags[afi][safi],
8669 PEER_STATUS_ORF_PREFIX_SEND)
8670 || orf_pfx_count) {
8671 if (CHECK_FLAG(p->af_sflags[afi][safi],
8672 PEER_STATUS_ORF_PREFIX_SEND))
8673 json_object_boolean_true_add(json_neigh,
8674 "orfSent");
8675 if (orf_pfx_count)
8676 json_object_int_add(json_addr, "orfRecvCounter",
8677 orf_pfx_count);
8678 }
8679 if (CHECK_FLAG(p->af_sflags[afi][safi],
8680 PEER_STATUS_ORF_WAIT_REFRESH))
8681 json_object_string_add(
8682 json_addr, "orfFirstUpdate",
8683 "deferredUntilORFOrRouteRefreshRecvd");
8684
8685 if (CHECK_FLAG(p->af_flags[afi][safi],
8686 PEER_FLAG_REFLECTOR_CLIENT))
8687 json_object_boolean_true_add(json_addr,
8688 "routeReflectorClient");
8689 if (CHECK_FLAG(p->af_flags[afi][safi],
8690 PEER_FLAG_RSERVER_CLIENT))
8691 json_object_boolean_true_add(json_addr,
8692 "routeServerClient");
8693 if (CHECK_FLAG(p->af_flags[afi][safi], PEER_FLAG_SOFT_RECONFIG))
8694 json_object_boolean_true_add(json_addr,
8695 "inboundSoftConfigPermit");
8696
8697 if (CHECK_FLAG(p->af_flags[afi][safi],
8698 PEER_FLAG_REMOVE_PRIVATE_AS_ALL_REPLACE))
8699 json_object_boolean_true_add(
8700 json_addr,
8701 "privateAsNumsAllReplacedInUpdatesToNbr");
8702 else if (CHECK_FLAG(p->af_flags[afi][safi],
8703 PEER_FLAG_REMOVE_PRIVATE_AS_REPLACE))
8704 json_object_boolean_true_add(
8705 json_addr,
8706 "privateAsNumsReplacedInUpdatesToNbr");
8707 else if (CHECK_FLAG(p->af_flags[afi][safi],
8708 PEER_FLAG_REMOVE_PRIVATE_AS_ALL))
8709 json_object_boolean_true_add(
8710 json_addr,
8711 "privateAsNumsAllRemovedInUpdatesToNbr");
8712 else if (CHECK_FLAG(p->af_flags[afi][safi],
8713 PEER_FLAG_REMOVE_PRIVATE_AS))
8714 json_object_boolean_true_add(
8715 json_addr,
8716 "privateAsNumsRemovedInUpdatesToNbr");
8717
8718 if (p->addpath_type[afi][safi] != BGP_ADDPATH_NONE)
8719 json_object_boolean_true_add(
8720 json_addr,
8721 bgp_addpath_names(p->addpath_type[afi][safi])
8722 ->type_json_name);
8723
8724 if (CHECK_FLAG(p->af_flags[afi][safi], PEER_FLAG_AS_OVERRIDE))
8725 json_object_string_add(json_addr,
8726 "overrideASNsInOutboundUpdates",
8727 "ifAspathEqualRemoteAs");
8728
8729 if (CHECK_FLAG(p->af_flags[afi][safi], PEER_FLAG_NEXTHOP_SELF)
8730 || CHECK_FLAG(p->af_flags[afi][safi],
8731 PEER_FLAG_FORCE_NEXTHOP_SELF))
8732 json_object_boolean_true_add(json_addr,
8733 "routerAlwaysNextHop");
8734 if (CHECK_FLAG(p->af_flags[afi][safi],
8735 PEER_FLAG_AS_PATH_UNCHANGED))
8736 json_object_boolean_true_add(
8737 json_addr, "unchangedAsPathPropogatedToNbr");
8738 if (CHECK_FLAG(p->af_flags[afi][safi],
8739 PEER_FLAG_NEXTHOP_UNCHANGED))
8740 json_object_boolean_true_add(
8741 json_addr, "unchangedNextHopPropogatedToNbr");
8742 if (CHECK_FLAG(p->af_flags[afi][safi], PEER_FLAG_MED_UNCHANGED))
8743 json_object_boolean_true_add(
8744 json_addr, "unchangedMedPropogatedToNbr");
8745 if (CHECK_FLAG(p->af_flags[afi][safi], PEER_FLAG_SEND_COMMUNITY)
8746 || CHECK_FLAG(p->af_flags[afi][safi],
8747 PEER_FLAG_SEND_EXT_COMMUNITY)) {
8748 if (CHECK_FLAG(p->af_flags[afi][safi],
8749 PEER_FLAG_SEND_COMMUNITY)
8750 && CHECK_FLAG(p->af_flags[afi][safi],
8751 PEER_FLAG_SEND_EXT_COMMUNITY))
8752 json_object_string_add(json_addr,
8753 "commAttriSentToNbr",
8754 "extendedAndStandard");
8755 else if (CHECK_FLAG(p->af_flags[afi][safi],
8756 PEER_FLAG_SEND_EXT_COMMUNITY))
8757 json_object_string_add(json_addr,
8758 "commAttriSentToNbr",
8759 "extended");
8760 else
8761 json_object_string_add(json_addr,
8762 "commAttriSentToNbr",
8763 "standard");
8764 }
8765 if (CHECK_FLAG(p->af_flags[afi][safi],
8766 PEER_FLAG_DEFAULT_ORIGINATE)) {
8767 if (p->default_rmap[afi][safi].name)
8768 json_object_string_add(
8769 json_addr, "defaultRouteMap",
8770 p->default_rmap[afi][safi].name);
8771
8772 if (paf && PAF_SUBGRP(paf)
8773 && CHECK_FLAG(PAF_SUBGRP(paf)->sflags,
8774 SUBGRP_STATUS_DEFAULT_ORIGINATE))
8775 json_object_boolean_true_add(json_addr,
8776 "defaultSent");
8777 else
8778 json_object_boolean_true_add(json_addr,
8779 "defaultNotSent");
8780 }
8781
8782 if (afi == AFI_L2VPN && safi == SAFI_EVPN) {
8783 if (is_evpn_enabled())
8784 json_object_boolean_true_add(
8785 json_addr, "advertiseAllVnis");
8786 }
8787
8788 if (filter->plist[FILTER_IN].name
8789 || filter->dlist[FILTER_IN].name
8790 || filter->aslist[FILTER_IN].name
8791 || filter->map[RMAP_IN].name)
8792 json_object_boolean_true_add(json_addr,
8793 "inboundPathPolicyConfig");
8794 if (filter->plist[FILTER_OUT].name
8795 || filter->dlist[FILTER_OUT].name
8796 || filter->aslist[FILTER_OUT].name
8797 || filter->map[RMAP_OUT].name || filter->usmap.name)
8798 json_object_boolean_true_add(
8799 json_addr, "outboundPathPolicyConfig");
8800
8801 /* prefix-list */
8802 if (filter->plist[FILTER_IN].name)
8803 json_object_string_add(json_addr,
8804 "incomingUpdatePrefixFilterList",
8805 filter->plist[FILTER_IN].name);
8806 if (filter->plist[FILTER_OUT].name)
8807 json_object_string_add(json_addr,
8808 "outgoingUpdatePrefixFilterList",
8809 filter->plist[FILTER_OUT].name);
8810
8811 /* distribute-list */
8812 if (filter->dlist[FILTER_IN].name)
8813 json_object_string_add(
8814 json_addr, "incomingUpdateNetworkFilterList",
8815 filter->dlist[FILTER_IN].name);
8816 if (filter->dlist[FILTER_OUT].name)
8817 json_object_string_add(
8818 json_addr, "outgoingUpdateNetworkFilterList",
8819 filter->dlist[FILTER_OUT].name);
8820
8821 /* filter-list. */
8822 if (filter->aslist[FILTER_IN].name)
8823 json_object_string_add(json_addr,
8824 "incomingUpdateAsPathFilterList",
8825 filter->aslist[FILTER_IN].name);
8826 if (filter->aslist[FILTER_OUT].name)
8827 json_object_string_add(json_addr,
8828 "outgoingUpdateAsPathFilterList",
8829 filter->aslist[FILTER_OUT].name);
8830
8831 /* route-map. */
8832 if (filter->map[RMAP_IN].name)
8833 json_object_string_add(
8834 json_addr, "routeMapForIncomingAdvertisements",
8835 filter->map[RMAP_IN].name);
8836 if (filter->map[RMAP_OUT].name)
8837 json_object_string_add(
8838 json_addr, "routeMapForOutgoingAdvertisements",
8839 filter->map[RMAP_OUT].name);
8840
8841 /* ebgp-requires-policy (inbound) */
8842 if (p->bgp->ebgp_requires_policy == DEFAULT_EBGP_POLICY_ENABLED
8843 && !bgp_inbound_policy_exists(p, filter))
8844 json_object_string_add(
8845 json_addr, "inboundEbgpRequiresPolicy",
8846 "Inbound updates discarded due to missing policy");
8847
8848 /* ebgp-requires-policy (outbound) */
8849 if (p->bgp->ebgp_requires_policy == DEFAULT_EBGP_POLICY_ENABLED
8850 && (!bgp_outbound_policy_exists(p, filter)))
8851 json_object_string_add(
8852 json_addr, "outboundEbgpRequiresPolicy",
8853 "Outbound updates discarded due to missing policy");
8854
8855 /* unsuppress-map */
8856 if (filter->usmap.name)
8857 json_object_string_add(json_addr,
8858 "selectiveUnsuppressRouteMap",
8859 filter->usmap.name);
8860
8861 /* Receive prefix count */
8862 json_object_int_add(json_addr, "acceptedPrefixCounter",
8863 p->pcount[afi][safi]);
8864 if (paf && PAF_SUBGRP(paf))
8865 json_object_int_add(json_addr, "sentPrefixCounter",
8866 (PAF_SUBGRP(paf))->scount);
8867
8868 /* Maximum prefix */
8869 if (CHECK_FLAG(p->af_flags[afi][safi], PEER_FLAG_MAX_PREFIX)) {
8870 json_object_int_add(json_addr, "prefixAllowedMax",
8871 p->pmax[afi][safi]);
8872 if (CHECK_FLAG(p->af_flags[afi][safi],
8873 PEER_FLAG_MAX_PREFIX_WARNING))
8874 json_object_boolean_true_add(
8875 json_addr, "prefixAllowedMaxWarning");
8876 json_object_int_add(json_addr,
8877 "prefixAllowedWarningThresh",
8878 p->pmax_threshold[afi][safi]);
8879 if (p->pmax_restart[afi][safi])
8880 json_object_int_add(
8881 json_addr,
8882 "prefixAllowedRestartIntervalMsecs",
8883 p->pmax_restart[afi][safi] * 60000);
8884 }
8885 json_object_object_add(json_neigh, afi_safi_print(afi, safi),
8886 json_addr);
8887
8888 } else {
8889 filter = &p->filter[afi][safi];
8890
8891 vty_out(vty, " For address family: %s\n",
8892 afi_safi_print(afi, safi));
8893
8894 if (peer_group_active(p))
8895 vty_out(vty, " %s peer-group member\n",
8896 p->group->name);
8897
8898 paf = peer_af_find(p, afi, safi);
8899 if (paf && PAF_SUBGRP(paf)) {
8900 vty_out(vty, " Update group %" PRIu64
8901 ", subgroup %" PRIu64 "\n",
8902 PAF_UPDGRP(paf)->id, PAF_SUBGRP(paf)->id);
8903 vty_out(vty, " Packet Queue length %d\n",
8904 bpacket_queue_virtual_length(paf));
8905 } else {
8906 vty_out(vty, " Not part of any update group\n");
8907 }
8908 if (CHECK_FLAG(p->af_cap[afi][safi], PEER_CAP_ORF_PREFIX_SM_ADV)
8909 || CHECK_FLAG(p->af_cap[afi][safi],
8910 PEER_CAP_ORF_PREFIX_SM_RCV)
8911 || CHECK_FLAG(p->af_cap[afi][safi],
8912 PEER_CAP_ORF_PREFIX_SM_OLD_RCV)
8913 || CHECK_FLAG(p->af_cap[afi][safi],
8914 PEER_CAP_ORF_PREFIX_RM_ADV)
8915 || CHECK_FLAG(p->af_cap[afi][safi],
8916 PEER_CAP_ORF_PREFIX_RM_RCV)
8917 || CHECK_FLAG(p->af_cap[afi][safi],
8918 PEER_CAP_ORF_PREFIX_RM_OLD_RCV))
8919 vty_out(vty, " AF-dependant capabilities:\n");
8920
8921 if (CHECK_FLAG(p->af_cap[afi][safi], PEER_CAP_ORF_PREFIX_SM_ADV)
8922 || CHECK_FLAG(p->af_cap[afi][safi],
8923 PEER_CAP_ORF_PREFIX_SM_RCV)
8924 || CHECK_FLAG(p->af_cap[afi][safi],
8925 PEER_CAP_ORF_PREFIX_RM_ADV)
8926 || CHECK_FLAG(p->af_cap[afi][safi],
8927 PEER_CAP_ORF_PREFIX_RM_RCV)) {
8928 vty_out(vty,
8929 " Outbound Route Filter (ORF) type (%d) Prefix-list:\n",
8930 ORF_TYPE_PREFIX);
8931 bgp_show_peer_afi_orf_cap(
8932 vty, p, afi, safi, PEER_CAP_ORF_PREFIX_SM_ADV,
8933 PEER_CAP_ORF_PREFIX_RM_ADV,
8934 PEER_CAP_ORF_PREFIX_SM_RCV,
8935 PEER_CAP_ORF_PREFIX_RM_RCV, use_json, NULL);
8936 }
8937 if (CHECK_FLAG(p->af_cap[afi][safi], PEER_CAP_ORF_PREFIX_SM_ADV)
8938 || CHECK_FLAG(p->af_cap[afi][safi],
8939 PEER_CAP_ORF_PREFIX_SM_OLD_RCV)
8940 || CHECK_FLAG(p->af_cap[afi][safi],
8941 PEER_CAP_ORF_PREFIX_RM_ADV)
8942 || CHECK_FLAG(p->af_cap[afi][safi],
8943 PEER_CAP_ORF_PREFIX_RM_OLD_RCV)) {
8944 vty_out(vty,
8945 " Outbound Route Filter (ORF) type (%d) Prefix-list:\n",
8946 ORF_TYPE_PREFIX_OLD);
8947 bgp_show_peer_afi_orf_cap(
8948 vty, p, afi, safi, PEER_CAP_ORF_PREFIX_SM_ADV,
8949 PEER_CAP_ORF_PREFIX_RM_ADV,
8950 PEER_CAP_ORF_PREFIX_SM_OLD_RCV,
8951 PEER_CAP_ORF_PREFIX_RM_OLD_RCV, use_json, NULL);
8952 }
8953
8954 sprintf(orf_pfx_name, "%s.%d.%d", p->host, afi, safi);
8955 orf_pfx_count = prefix_bgp_show_prefix_list(
8956 NULL, afi, orf_pfx_name, use_json);
8957
8958 if (CHECK_FLAG(p->af_sflags[afi][safi],
8959 PEER_STATUS_ORF_PREFIX_SEND)
8960 || orf_pfx_count) {
8961 vty_out(vty, " Outbound Route Filter (ORF):");
8962 if (CHECK_FLAG(p->af_sflags[afi][safi],
8963 PEER_STATUS_ORF_PREFIX_SEND))
8964 vty_out(vty, " sent;");
8965 if (orf_pfx_count)
8966 vty_out(vty, " received (%d entries)",
8967 orf_pfx_count);
8968 vty_out(vty, "\n");
8969 }
8970 if (CHECK_FLAG(p->af_sflags[afi][safi],
8971 PEER_STATUS_ORF_WAIT_REFRESH))
8972 vty_out(vty,
8973 " First update is deferred until ORF or ROUTE-REFRESH is received\n");
8974
8975 if (CHECK_FLAG(p->af_flags[afi][safi],
8976 PEER_FLAG_REFLECTOR_CLIENT))
8977 vty_out(vty, " Route-Reflector Client\n");
8978 if (CHECK_FLAG(p->af_flags[afi][safi],
8979 PEER_FLAG_RSERVER_CLIENT))
8980 vty_out(vty, " Route-Server Client\n");
8981 if (CHECK_FLAG(p->af_flags[afi][safi], PEER_FLAG_SOFT_RECONFIG))
8982 vty_out(vty,
8983 " Inbound soft reconfiguration allowed\n");
8984
8985 if (CHECK_FLAG(p->af_flags[afi][safi],
8986 PEER_FLAG_REMOVE_PRIVATE_AS_ALL_REPLACE))
8987 vty_out(vty,
8988 " Private AS numbers (all) replaced in updates to this neighbor\n");
8989 else if (CHECK_FLAG(p->af_flags[afi][safi],
8990 PEER_FLAG_REMOVE_PRIVATE_AS_REPLACE))
8991 vty_out(vty,
8992 " Private AS numbers replaced in updates to this neighbor\n");
8993 else if (CHECK_FLAG(p->af_flags[afi][safi],
8994 PEER_FLAG_REMOVE_PRIVATE_AS_ALL))
8995 vty_out(vty,
8996 " Private AS numbers (all) removed in updates to this neighbor\n");
8997 else if (CHECK_FLAG(p->af_flags[afi][safi],
8998 PEER_FLAG_REMOVE_PRIVATE_AS))
8999 vty_out(vty,
9000 " Private AS numbers removed in updates to this neighbor\n");
9001
9002 if (p->addpath_type[afi][safi] != BGP_ADDPATH_NONE)
9003 vty_out(vty, " %s\n",
9004 bgp_addpath_names(p->addpath_type[afi][safi])
9005 ->human_description);
9006
9007 if (CHECK_FLAG(p->af_flags[afi][safi], PEER_FLAG_AS_OVERRIDE))
9008 vty_out(vty,
9009 " Override ASNs in outbound updates if aspath equals remote-as\n");
9010
9011 if (CHECK_FLAG(p->af_flags[afi][safi], PEER_FLAG_NEXTHOP_SELF)
9012 || CHECK_FLAG(p->af_flags[afi][safi],
9013 PEER_FLAG_FORCE_NEXTHOP_SELF))
9014 vty_out(vty, " NEXT_HOP is always this router\n");
9015 if (CHECK_FLAG(p->af_flags[afi][safi],
9016 PEER_FLAG_AS_PATH_UNCHANGED))
9017 vty_out(vty,
9018 " AS_PATH is propagated unchanged to this neighbor\n");
9019 if (CHECK_FLAG(p->af_flags[afi][safi],
9020 PEER_FLAG_NEXTHOP_UNCHANGED))
9021 vty_out(vty,
9022 " NEXT_HOP is propagated unchanged to this neighbor\n");
9023 if (CHECK_FLAG(p->af_flags[afi][safi], PEER_FLAG_MED_UNCHANGED))
9024 vty_out(vty,
9025 " MED is propagated unchanged to this neighbor\n");
9026 if (CHECK_FLAG(p->af_flags[afi][safi], PEER_FLAG_SEND_COMMUNITY)
9027 || CHECK_FLAG(p->af_flags[afi][safi],
9028 PEER_FLAG_SEND_EXT_COMMUNITY)
9029 || CHECK_FLAG(p->af_flags[afi][safi],
9030 PEER_FLAG_SEND_LARGE_COMMUNITY)) {
9031 vty_out(vty,
9032 " Community attribute sent to this neighbor");
9033 if (CHECK_FLAG(p->af_flags[afi][safi],
9034 PEER_FLAG_SEND_COMMUNITY)
9035 && CHECK_FLAG(p->af_flags[afi][safi],
9036 PEER_FLAG_SEND_EXT_COMMUNITY)
9037 && CHECK_FLAG(p->af_flags[afi][safi],
9038 PEER_FLAG_SEND_LARGE_COMMUNITY))
9039 vty_out(vty, "(all)\n");
9040 else if (CHECK_FLAG(p->af_flags[afi][safi],
9041 PEER_FLAG_SEND_LARGE_COMMUNITY))
9042 vty_out(vty, "(large)\n");
9043 else if (CHECK_FLAG(p->af_flags[afi][safi],
9044 PEER_FLAG_SEND_EXT_COMMUNITY))
9045 vty_out(vty, "(extended)\n");
9046 else
9047 vty_out(vty, "(standard)\n");
9048 }
9049 if (CHECK_FLAG(p->af_flags[afi][safi],
9050 PEER_FLAG_DEFAULT_ORIGINATE)) {
9051 vty_out(vty, " Default information originate,");
9052
9053 if (p->default_rmap[afi][safi].name)
9054 vty_out(vty, " default route-map %s%s,",
9055 p->default_rmap[afi][safi].map ? "*"
9056 : "",
9057 p->default_rmap[afi][safi].name);
9058 if (paf && PAF_SUBGRP(paf)
9059 && CHECK_FLAG(PAF_SUBGRP(paf)->sflags,
9060 SUBGRP_STATUS_DEFAULT_ORIGINATE))
9061 vty_out(vty, " default sent\n");
9062 else
9063 vty_out(vty, " default not sent\n");
9064 }
9065
9066 /* advertise-vni-all */
9067 if (afi == AFI_L2VPN && safi == SAFI_EVPN) {
9068 if (is_evpn_enabled())
9069 vty_out(vty, " advertise-all-vni\n");
9070 }
9071
9072 if (filter->plist[FILTER_IN].name
9073 || filter->dlist[FILTER_IN].name
9074 || filter->aslist[FILTER_IN].name
9075 || filter->map[RMAP_IN].name)
9076 vty_out(vty, " Inbound path policy configured\n");
9077 if (filter->plist[FILTER_OUT].name
9078 || filter->dlist[FILTER_OUT].name
9079 || filter->aslist[FILTER_OUT].name
9080 || filter->map[RMAP_OUT].name || filter->usmap.name)
9081 vty_out(vty, " Outbound path policy configured\n");
9082
9083 /* prefix-list */
9084 if (filter->plist[FILTER_IN].name)
9085 vty_out(vty,
9086 " Incoming update prefix filter list is %s%s\n",
9087 filter->plist[FILTER_IN].plist ? "*" : "",
9088 filter->plist[FILTER_IN].name);
9089 if (filter->plist[FILTER_OUT].name)
9090 vty_out(vty,
9091 " Outgoing update prefix filter list is %s%s\n",
9092 filter->plist[FILTER_OUT].plist ? "*" : "",
9093 filter->plist[FILTER_OUT].name);
9094
9095 /* distribute-list */
9096 if (filter->dlist[FILTER_IN].name)
9097 vty_out(vty,
9098 " Incoming update network filter list is %s%s\n",
9099 filter->dlist[FILTER_IN].alist ? "*" : "",
9100 filter->dlist[FILTER_IN].name);
9101 if (filter->dlist[FILTER_OUT].name)
9102 vty_out(vty,
9103 " Outgoing update network filter list is %s%s\n",
9104 filter->dlist[FILTER_OUT].alist ? "*" : "",
9105 filter->dlist[FILTER_OUT].name);
9106
9107 /* filter-list. */
9108 if (filter->aslist[FILTER_IN].name)
9109 vty_out(vty,
9110 " Incoming update AS path filter list is %s%s\n",
9111 filter->aslist[FILTER_IN].aslist ? "*" : "",
9112 filter->aslist[FILTER_IN].name);
9113 if (filter->aslist[FILTER_OUT].name)
9114 vty_out(vty,
9115 " Outgoing update AS path filter list is %s%s\n",
9116 filter->aslist[FILTER_OUT].aslist ? "*" : "",
9117 filter->aslist[FILTER_OUT].name);
9118
9119 /* route-map. */
9120 if (filter->map[RMAP_IN].name)
9121 vty_out(vty,
9122 " Route map for incoming advertisements is %s%s\n",
9123 filter->map[RMAP_IN].map ? "*" : "",
9124 filter->map[RMAP_IN].name);
9125 if (filter->map[RMAP_OUT].name)
9126 vty_out(vty,
9127 " Route map for outgoing advertisements is %s%s\n",
9128 filter->map[RMAP_OUT].map ? "*" : "",
9129 filter->map[RMAP_OUT].name);
9130
9131 /* ebgp-requires-policy (inbound) */
9132 if (p->bgp->ebgp_requires_policy == DEFAULT_EBGP_POLICY_ENABLED
9133 && !bgp_inbound_policy_exists(p, filter))
9134 vty_out(vty,
9135 " Inbound updates discarded due to missing policy\n");
9136
9137 /* ebgp-requires-policy (outbound) */
9138 if (p->bgp->ebgp_requires_policy == DEFAULT_EBGP_POLICY_ENABLED
9139 && !bgp_outbound_policy_exists(p, filter))
9140 vty_out(vty,
9141 " Outbound updates discarded due to missing policy\n");
9142
9143 /* unsuppress-map */
9144 if (filter->usmap.name)
9145 vty_out(vty,
9146 " Route map for selective unsuppress is %s%s\n",
9147 filter->usmap.map ? "*" : "",
9148 filter->usmap.name);
9149
9150 /* Receive prefix count */
9151 vty_out(vty, " %ld accepted prefixes\n", p->pcount[afi][safi]);
9152
9153 /* Maximum prefix */
9154 if (CHECK_FLAG(p->af_flags[afi][safi], PEER_FLAG_MAX_PREFIX)) {
9155 vty_out(vty, " Maximum prefixes allowed %ld%s\n",
9156 p->pmax[afi][safi],
9157 CHECK_FLAG(p->af_flags[afi][safi],
9158 PEER_FLAG_MAX_PREFIX_WARNING)
9159 ? " (warning-only)"
9160 : "");
9161 vty_out(vty, " Threshold for warning message %d%%",
9162 p->pmax_threshold[afi][safi]);
9163 if (p->pmax_restart[afi][safi])
9164 vty_out(vty, ", restart interval %d min",
9165 p->pmax_restart[afi][safi]);
9166 vty_out(vty, "\n");
9167 }
9168
9169 vty_out(vty, "\n");
9170 }
9171 }
9172
9173 static void bgp_show_peer(struct vty *vty, struct peer *p, bool use_json,
9174 json_object *json)
9175 {
9176 struct bgp *bgp;
9177 char buf1[PREFIX2STR_BUFFER], buf[SU_ADDRSTRLEN];
9178 char timebuf[BGP_UPTIME_LEN];
9179 char dn_flag[2];
9180 const char *subcode_str;
9181 const char *code_str;
9182 afi_t afi;
9183 safi_t safi;
9184 uint16_t i;
9185 uint8_t *msg;
9186 json_object *json_neigh = NULL;
9187 time_t epoch_tbuf;
9188
9189 bgp = p->bgp;
9190
9191 if (use_json)
9192 json_neigh = json_object_new_object();
9193
9194 memset(dn_flag, '\0', sizeof(dn_flag));
9195 if (!p->conf_if && peer_dynamic_neighbor(p))
9196 dn_flag[0] = '*';
9197
9198 if (!use_json) {
9199 if (p->conf_if) /* Configured interface name. */
9200 vty_out(vty, "BGP neighbor on %s: %s, ", p->conf_if,
9201 BGP_PEER_SU_UNSPEC(p)
9202 ? "None"
9203 : sockunion2str(&p->su, buf,
9204 SU_ADDRSTRLEN));
9205 else /* Configured IP address. */
9206 vty_out(vty, "BGP neighbor is %s%s, ", dn_flag,
9207 p->host);
9208 }
9209
9210 if (use_json) {
9211 if (p->conf_if && BGP_PEER_SU_UNSPEC(p))
9212 json_object_string_add(json_neigh, "bgpNeighborAddr",
9213 "none");
9214 else if (p->conf_if && !BGP_PEER_SU_UNSPEC(p))
9215 json_object_string_add(
9216 json_neigh, "bgpNeighborAddr",
9217 sockunion2str(&p->su, buf, SU_ADDRSTRLEN));
9218
9219 json_object_int_add(json_neigh, "remoteAs", p->as);
9220
9221 if (p->change_local_as)
9222 json_object_int_add(json_neigh, "localAs",
9223 p->change_local_as);
9224 else
9225 json_object_int_add(json_neigh, "localAs", p->local_as);
9226
9227 if (CHECK_FLAG(p->flags, PEER_FLAG_LOCAL_AS_NO_PREPEND))
9228 json_object_boolean_true_add(json_neigh,
9229 "localAsNoPrepend");
9230
9231 if (CHECK_FLAG(p->flags, PEER_FLAG_LOCAL_AS_REPLACE_AS))
9232 json_object_boolean_true_add(json_neigh,
9233 "localAsReplaceAs");
9234 } else {
9235 if ((p->as_type == AS_SPECIFIED) || (p->as_type == AS_EXTERNAL)
9236 || (p->as_type == AS_INTERNAL))
9237 vty_out(vty, "remote AS %u, ", p->as);
9238 else
9239 vty_out(vty, "remote AS Unspecified, ");
9240 vty_out(vty, "local AS %u%s%s, ",
9241 p->change_local_as ? p->change_local_as : p->local_as,
9242 CHECK_FLAG(p->flags, PEER_FLAG_LOCAL_AS_NO_PREPEND)
9243 ? " no-prepend"
9244 : "",
9245 CHECK_FLAG(p->flags, PEER_FLAG_LOCAL_AS_REPLACE_AS)
9246 ? " replace-as"
9247 : "");
9248 }
9249 /* peer type internal or confed-internal */
9250 if ((p->as == p->local_as) || (p->as_type == AS_INTERNAL)) {
9251 if (use_json) {
9252 if (CHECK_FLAG(bgp->config, BGP_CONFIG_CONFEDERATION))
9253 json_object_boolean_true_add(
9254 json_neigh, "nbrConfedInternalLink");
9255 else
9256 json_object_boolean_true_add(json_neigh,
9257 "nbrInternalLink");
9258 } else {
9259 if (CHECK_FLAG(bgp->config, BGP_CONFIG_CONFEDERATION))
9260 vty_out(vty, "confed-internal link\n");
9261 else
9262 vty_out(vty, "internal link\n");
9263 }
9264 /* peer type external or confed-external */
9265 } else if (p->as || (p->as_type == AS_EXTERNAL)) {
9266 if (use_json) {
9267 if (CHECK_FLAG(bgp->config, BGP_CONFIG_CONFEDERATION))
9268 json_object_boolean_true_add(
9269 json_neigh, "nbrConfedExternalLink");
9270 else
9271 json_object_boolean_true_add(json_neigh,
9272 "nbrExternalLink");
9273 } else {
9274 if (bgp_confederation_peers_check(bgp, p->as))
9275 vty_out(vty, "confed-external link\n");
9276 else
9277 vty_out(vty, "external link\n");
9278 }
9279 } else {
9280 if (use_json)
9281 json_object_boolean_true_add(json_neigh,
9282 "nbrUnspecifiedLink");
9283 else
9284 vty_out(vty, "unspecified link\n");
9285 }
9286
9287 /* Description. */
9288 if (p->desc) {
9289 if (use_json)
9290 json_object_string_add(json_neigh, "nbrDesc", p->desc);
9291 else
9292 vty_out(vty, " Description: %s\n", p->desc);
9293 }
9294
9295 if (p->hostname) {
9296 if (use_json) {
9297 if (p->hostname)
9298 json_object_string_add(json_neigh, "hostname",
9299 p->hostname);
9300
9301 if (p->domainname)
9302 json_object_string_add(json_neigh, "domainname",
9303 p->domainname);
9304 } else {
9305 if (p->domainname && (p->domainname[0] != '\0'))
9306 vty_out(vty, "Hostname: %s.%s\n", p->hostname,
9307 p->domainname);
9308 else
9309 vty_out(vty, "Hostname: %s\n", p->hostname);
9310 }
9311 }
9312
9313 /* Peer-group */
9314 if (p->group) {
9315 if (use_json) {
9316 json_object_string_add(json_neigh, "peerGroup",
9317 p->group->name);
9318
9319 if (dn_flag[0]) {
9320 struct prefix prefix, *range = NULL;
9321
9322 sockunion2hostprefix(&(p->su), &prefix);
9323 range = peer_group_lookup_dynamic_neighbor_range(
9324 p->group, &prefix);
9325
9326 if (range) {
9327 prefix2str(range, buf1, sizeof(buf1));
9328 json_object_string_add(
9329 json_neigh,
9330 "peerSubnetRangeGroup", buf1);
9331 }
9332 }
9333 } else {
9334 vty_out(vty,
9335 " Member of peer-group %s for session parameters\n",
9336 p->group->name);
9337
9338 if (dn_flag[0]) {
9339 struct prefix prefix, *range = NULL;
9340
9341 sockunion2hostprefix(&(p->su), &prefix);
9342 range = peer_group_lookup_dynamic_neighbor_range(
9343 p->group, &prefix);
9344
9345 if (range) {
9346 prefix2str(range, buf1, sizeof(buf1));
9347 vty_out(vty,
9348 " Belongs to the subnet range group: %s\n",
9349 buf1);
9350 }
9351 }
9352 }
9353 }
9354
9355 if (use_json) {
9356 /* Administrative shutdown. */
9357 if (CHECK_FLAG(p->flags, PEER_FLAG_SHUTDOWN))
9358 json_object_boolean_true_add(json_neigh,
9359 "adminShutDown");
9360
9361 /* BGP Version. */
9362 json_object_int_add(json_neigh, "bgpVersion", 4);
9363 json_object_string_add(
9364 json_neigh, "remoteRouterId",
9365 inet_ntop(AF_INET, &p->remote_id, buf1, sizeof(buf1)));
9366 json_object_string_add(
9367 json_neigh, "localRouterId",
9368 inet_ntop(AF_INET, &bgp->router_id, buf1,
9369 sizeof(buf1)));
9370
9371 /* Confederation */
9372 if (CHECK_FLAG(bgp->config, BGP_CONFIG_CONFEDERATION)
9373 && bgp_confederation_peers_check(bgp, p->as))
9374 json_object_boolean_true_add(json_neigh,
9375 "nbrCommonAdmin");
9376
9377 /* Status. */
9378 json_object_string_add(
9379 json_neigh, "bgpState",
9380 lookup_msg(bgp_status_msg, p->status, NULL));
9381
9382 if (p->status == Established) {
9383 time_t uptime;
9384
9385 uptime = bgp_clock();
9386 uptime -= p->uptime;
9387 epoch_tbuf = time(NULL) - uptime;
9388
9389 #if CONFDATE > 20200101
9390 CPP_NOTICE(
9391 "bgpTimerUp should be deprecated and can be removed now");
9392 #endif
9393 /*
9394 * bgpTimerUp was miliseconds that was accurate
9395 * up to 1 day, then the value returned
9396 * became garbage. So in order to provide
9397 * some level of backwards compatability,
9398 * we still provde the data, but now
9399 * we are returning the correct value
9400 * and also adding a new bgpTimerUpMsec
9401 * which will allow us to deprecate
9402 * this eventually
9403 */
9404 json_object_int_add(json_neigh, "bgpTimerUp",
9405 uptime * 1000);
9406 json_object_int_add(json_neigh, "bgpTimerUpMsec",
9407 uptime * 1000);
9408 json_object_string_add(json_neigh, "bgpTimerUpString",
9409 peer_uptime(p->uptime, timebuf,
9410 BGP_UPTIME_LEN, 0,
9411 NULL));
9412 json_object_int_add(json_neigh,
9413 "bgpTimerUpEstablishedEpoch",
9414 epoch_tbuf);
9415 }
9416
9417 else if (p->status == Active) {
9418 if (CHECK_FLAG(p->flags, PEER_FLAG_PASSIVE))
9419 json_object_string_add(json_neigh, "bgpStateIs",
9420 "passive");
9421 else if (CHECK_FLAG(p->sflags, PEER_STATUS_NSF_WAIT))
9422 json_object_string_add(json_neigh, "bgpStateIs",
9423 "passiveNSF");
9424 }
9425
9426 /* read timer */
9427 time_t uptime;
9428 struct tm *tm;
9429
9430 uptime = bgp_clock();
9431 uptime -= p->readtime;
9432 tm = gmtime(&uptime);
9433 json_object_int_add(json_neigh, "bgpTimerLastRead",
9434 (tm->tm_sec * 1000) + (tm->tm_min * 60000)
9435 + (tm->tm_hour * 3600000));
9436
9437 uptime = bgp_clock();
9438 uptime -= p->last_write;
9439 tm = gmtime(&uptime);
9440 json_object_int_add(json_neigh, "bgpTimerLastWrite",
9441 (tm->tm_sec * 1000) + (tm->tm_min * 60000)
9442 + (tm->tm_hour * 3600000));
9443
9444 uptime = bgp_clock();
9445 uptime -= p->update_time;
9446 tm = gmtime(&uptime);
9447 json_object_int_add(json_neigh, "bgpInUpdateElapsedTimeMsecs",
9448 (tm->tm_sec * 1000) + (tm->tm_min * 60000)
9449 + (tm->tm_hour * 3600000));
9450
9451 /* Configured timer values. */
9452 json_object_int_add(json_neigh, "bgpTimerHoldTimeMsecs",
9453 p->v_holdtime * 1000);
9454 json_object_int_add(json_neigh,
9455 "bgpTimerKeepAliveIntervalMsecs",
9456 p->v_keepalive * 1000);
9457 if (CHECK_FLAG(p->flags, PEER_FLAG_TIMER)) {
9458 json_object_int_add(json_neigh,
9459 "bgpTimerConfiguredHoldTimeMsecs",
9460 p->holdtime * 1000);
9461 json_object_int_add(
9462 json_neigh,
9463 "bgpTimerConfiguredKeepAliveIntervalMsecs",
9464 p->keepalive * 1000);
9465 } else if ((bgp->default_holdtime != BGP_DEFAULT_HOLDTIME)
9466 || (bgp->default_keepalive
9467 != BGP_DEFAULT_KEEPALIVE)) {
9468 json_object_int_add(json_neigh,
9469 "bgpTimerConfiguredHoldTimeMsecs",
9470 bgp->default_holdtime);
9471 json_object_int_add(
9472 json_neigh,
9473 "bgpTimerConfiguredKeepAliveIntervalMsecs",
9474 bgp->default_keepalive);
9475 }
9476 } else {
9477 /* Administrative shutdown. */
9478 if (CHECK_FLAG(p->flags, PEER_FLAG_SHUTDOWN))
9479 vty_out(vty, " Administratively shut down\n");
9480
9481 /* BGP Version. */
9482 vty_out(vty, " BGP version 4");
9483 vty_out(vty, ", remote router ID %s",
9484 inet_ntop(AF_INET, &p->remote_id, buf1, sizeof(buf1)));
9485 vty_out(vty, ", local router ID %s\n",
9486 inet_ntop(AF_INET, &bgp->router_id, buf1,
9487 sizeof(buf1)));
9488
9489 /* Confederation */
9490 if (CHECK_FLAG(bgp->config, BGP_CONFIG_CONFEDERATION)
9491 && bgp_confederation_peers_check(bgp, p->as))
9492 vty_out(vty,
9493 " Neighbor under common administration\n");
9494
9495 /* Status. */
9496 vty_out(vty, " BGP state = %s",
9497 lookup_msg(bgp_status_msg, p->status, NULL));
9498
9499 if (p->status == Established)
9500 vty_out(vty, ", up for %8s",
9501 peer_uptime(p->uptime, timebuf, BGP_UPTIME_LEN,
9502 0, NULL));
9503
9504 else if (p->status == Active) {
9505 if (CHECK_FLAG(p->flags, PEER_FLAG_PASSIVE))
9506 vty_out(vty, " (passive)");
9507 else if (CHECK_FLAG(p->sflags, PEER_STATUS_NSF_WAIT))
9508 vty_out(vty, " (NSF passive)");
9509 }
9510 vty_out(vty, "\n");
9511
9512 /* read timer */
9513 vty_out(vty, " Last read %s",
9514 peer_uptime(p->readtime, timebuf, BGP_UPTIME_LEN, 0,
9515 NULL));
9516 vty_out(vty, ", Last write %s\n",
9517 peer_uptime(p->last_write, timebuf, BGP_UPTIME_LEN, 0,
9518 NULL));
9519
9520 /* Configured timer values. */
9521 vty_out(vty,
9522 " Hold time is %d, keepalive interval is %d seconds\n",
9523 p->v_holdtime, p->v_keepalive);
9524 if (CHECK_FLAG(p->flags, PEER_FLAG_TIMER)) {
9525 vty_out(vty, " Configured hold time is %d",
9526 p->holdtime);
9527 vty_out(vty, ", keepalive interval is %d seconds\n",
9528 p->keepalive);
9529 } else if ((bgp->default_holdtime != BGP_DEFAULT_HOLDTIME)
9530 || (bgp->default_keepalive
9531 != BGP_DEFAULT_KEEPALIVE)) {
9532 vty_out(vty, " Configured hold time is %d",
9533 bgp->default_holdtime);
9534 vty_out(vty, ", keepalive interval is %d seconds\n",
9535 bgp->default_keepalive);
9536 }
9537 }
9538 /* Capability. */
9539 if (p->status == Established) {
9540 if (p->cap || p->afc_adv[AFI_IP][SAFI_UNICAST]
9541 || p->afc_recv[AFI_IP][SAFI_UNICAST]
9542 || p->afc_adv[AFI_IP][SAFI_MULTICAST]
9543 || p->afc_recv[AFI_IP][SAFI_MULTICAST]
9544 || p->afc_adv[AFI_IP6][SAFI_UNICAST]
9545 || p->afc_recv[AFI_IP6][SAFI_UNICAST]
9546 || p->afc_adv[AFI_IP6][SAFI_MULTICAST]
9547 || p->afc_recv[AFI_IP6][SAFI_MULTICAST]
9548 || p->afc_adv[AFI_IP6][SAFI_MPLS_VPN]
9549 || p->afc_recv[AFI_IP6][SAFI_MPLS_VPN]
9550 || p->afc_adv[AFI_IP6][SAFI_ENCAP]
9551 || p->afc_recv[AFI_IP6][SAFI_ENCAP]
9552 || p->afc_adv[AFI_IP6][SAFI_FLOWSPEC]
9553 || p->afc_recv[AFI_IP6][SAFI_FLOWSPEC]
9554 || p->afc_adv[AFI_IP][SAFI_ENCAP]
9555 || p->afc_recv[AFI_IP][SAFI_ENCAP]
9556 || p->afc_adv[AFI_IP][SAFI_FLOWSPEC]
9557 || p->afc_recv[AFI_IP][SAFI_FLOWSPEC]
9558 || p->afc_adv[AFI_IP][SAFI_MPLS_VPN]
9559 || p->afc_recv[AFI_IP][SAFI_MPLS_VPN]) {
9560 if (use_json) {
9561 json_object *json_cap = NULL;
9562
9563 json_cap = json_object_new_object();
9564
9565 /* AS4 */
9566 if (CHECK_FLAG(p->cap, PEER_CAP_AS4_RCV)
9567 || CHECK_FLAG(p->cap, PEER_CAP_AS4_ADV)) {
9568 if (CHECK_FLAG(p->cap, PEER_CAP_AS4_ADV)
9569 && CHECK_FLAG(p->cap,
9570 PEER_CAP_AS4_RCV))
9571 json_object_string_add(
9572 json_cap, "4byteAs",
9573 "advertisedAndReceived");
9574 else if (CHECK_FLAG(p->cap,
9575 PEER_CAP_AS4_ADV))
9576 json_object_string_add(
9577 json_cap, "4byteAs",
9578 "advertised");
9579 else if (CHECK_FLAG(p->cap,
9580 PEER_CAP_AS4_RCV))
9581 json_object_string_add(
9582 json_cap, "4byteAs",
9583 "received");
9584 }
9585
9586 /* AddPath */
9587 if (CHECK_FLAG(p->cap, PEER_CAP_ADDPATH_RCV)
9588 || CHECK_FLAG(p->cap,
9589 PEER_CAP_ADDPATH_ADV)) {
9590 json_object *json_add = NULL;
9591 const char *print_store;
9592
9593 json_add = json_object_new_object();
9594
9595 FOREACH_AFI_SAFI (afi, safi) {
9596 json_object *json_sub = NULL;
9597 json_sub =
9598 json_object_new_object();
9599 print_store = afi_safi_print(
9600 afi, safi);
9601
9602 if (CHECK_FLAG(
9603 p->af_cap[afi]
9604 [safi],
9605 PEER_CAP_ADDPATH_AF_TX_ADV)
9606 || CHECK_FLAG(
9607 p->af_cap[afi]
9608 [safi],
9609 PEER_CAP_ADDPATH_AF_TX_RCV)) {
9610 if (CHECK_FLAG(
9611 p->af_cap
9612 [afi]
9613 [safi],
9614 PEER_CAP_ADDPATH_AF_TX_ADV)
9615 && CHECK_FLAG(
9616 p->af_cap
9617 [afi]
9618 [safi],
9619 PEER_CAP_ADDPATH_AF_TX_RCV))
9620 json_object_boolean_true_add(
9621 json_sub,
9622 "txAdvertisedAndReceived");
9623 else if (
9624 CHECK_FLAG(
9625 p->af_cap
9626 [afi]
9627 [safi],
9628 PEER_CAP_ADDPATH_AF_TX_ADV))
9629 json_object_boolean_true_add(
9630 json_sub,
9631 "txAdvertised");
9632 else if (
9633 CHECK_FLAG(
9634 p->af_cap
9635 [afi]
9636 [safi],
9637 PEER_CAP_ADDPATH_AF_TX_RCV))
9638 json_object_boolean_true_add(
9639 json_sub,
9640 "txReceived");
9641 }
9642
9643 if (CHECK_FLAG(
9644 p->af_cap[afi]
9645 [safi],
9646 PEER_CAP_ADDPATH_AF_RX_ADV)
9647 || CHECK_FLAG(
9648 p->af_cap[afi]
9649 [safi],
9650 PEER_CAP_ADDPATH_AF_RX_RCV)) {
9651 if (CHECK_FLAG(
9652 p->af_cap
9653 [afi]
9654 [safi],
9655 PEER_CAP_ADDPATH_AF_RX_ADV)
9656 && CHECK_FLAG(
9657 p->af_cap
9658 [afi]
9659 [safi],
9660 PEER_CAP_ADDPATH_AF_RX_RCV))
9661 json_object_boolean_true_add(
9662 json_sub,
9663 "rxAdvertisedAndReceived");
9664 else if (
9665 CHECK_FLAG(
9666 p->af_cap
9667 [afi]
9668 [safi],
9669 PEER_CAP_ADDPATH_AF_RX_ADV))
9670 json_object_boolean_true_add(
9671 json_sub,
9672 "rxAdvertised");
9673 else if (
9674 CHECK_FLAG(
9675 p->af_cap
9676 [afi]
9677 [safi],
9678 PEER_CAP_ADDPATH_AF_RX_RCV))
9679 json_object_boolean_true_add(
9680 json_sub,
9681 "rxReceived");
9682 }
9683
9684 if (CHECK_FLAG(
9685 p->af_cap[afi]
9686 [safi],
9687 PEER_CAP_ADDPATH_AF_TX_ADV)
9688 || CHECK_FLAG(
9689 p->af_cap[afi]
9690 [safi],
9691 PEER_CAP_ADDPATH_AF_TX_RCV)
9692 || CHECK_FLAG(
9693 p->af_cap[afi]
9694 [safi],
9695 PEER_CAP_ADDPATH_AF_RX_ADV)
9696 || CHECK_FLAG(
9697 p->af_cap[afi]
9698 [safi],
9699 PEER_CAP_ADDPATH_AF_RX_RCV))
9700 json_object_object_add(
9701 json_add,
9702 print_store,
9703 json_sub);
9704 else
9705 json_object_free(
9706 json_sub);
9707 }
9708
9709 json_object_object_add(
9710 json_cap, "addPath", json_add);
9711 }
9712
9713 /* Dynamic */
9714 if (CHECK_FLAG(p->cap, PEER_CAP_DYNAMIC_RCV)
9715 || CHECK_FLAG(p->cap,
9716 PEER_CAP_DYNAMIC_ADV)) {
9717 if (CHECK_FLAG(p->cap,
9718 PEER_CAP_DYNAMIC_ADV)
9719 && CHECK_FLAG(p->cap,
9720 PEER_CAP_DYNAMIC_RCV))
9721 json_object_string_add(
9722 json_cap, "dynamic",
9723 "advertisedAndReceived");
9724 else if (CHECK_FLAG(
9725 p->cap,
9726 PEER_CAP_DYNAMIC_ADV))
9727 json_object_string_add(
9728 json_cap, "dynamic",
9729 "advertised");
9730 else if (CHECK_FLAG(
9731 p->cap,
9732 PEER_CAP_DYNAMIC_RCV))
9733 json_object_string_add(
9734 json_cap, "dynamic",
9735 "received");
9736 }
9737
9738 /* Extended nexthop */
9739 if (CHECK_FLAG(p->cap, PEER_CAP_ENHE_RCV)
9740 || CHECK_FLAG(p->cap, PEER_CAP_ENHE_ADV)) {
9741 json_object *json_nxt = NULL;
9742 const char *print_store;
9743
9744
9745 if (CHECK_FLAG(p->cap,
9746 PEER_CAP_ENHE_ADV)
9747 && CHECK_FLAG(p->cap,
9748 PEER_CAP_ENHE_RCV))
9749 json_object_string_add(
9750 json_cap,
9751 "extendedNexthop",
9752 "advertisedAndReceived");
9753 else if (CHECK_FLAG(p->cap,
9754 PEER_CAP_ENHE_ADV))
9755 json_object_string_add(
9756 json_cap,
9757 "extendedNexthop",
9758 "advertised");
9759 else if (CHECK_FLAG(p->cap,
9760 PEER_CAP_ENHE_RCV))
9761 json_object_string_add(
9762 json_cap,
9763 "extendedNexthop",
9764 "received");
9765
9766 if (CHECK_FLAG(p->cap,
9767 PEER_CAP_ENHE_RCV)) {
9768 json_nxt =
9769 json_object_new_object();
9770
9771 for (safi = SAFI_UNICAST;
9772 safi < SAFI_MAX; safi++) {
9773 if (CHECK_FLAG(
9774 p->af_cap
9775 [AFI_IP]
9776 [safi],
9777 PEER_CAP_ENHE_AF_RCV)) {
9778 print_store = afi_safi_print(
9779 AFI_IP,
9780 safi);
9781 json_object_string_add(
9782 json_nxt,
9783 print_store,
9784 "recieved"); /* misspelled for compatibility */
9785 }
9786 }
9787 json_object_object_add(
9788 json_cap,
9789 "extendedNexthopFamililesByPeer",
9790 json_nxt);
9791 }
9792 }
9793
9794 /* Route Refresh */
9795 if (CHECK_FLAG(p->cap, PEER_CAP_REFRESH_ADV)
9796 || CHECK_FLAG(p->cap,
9797 PEER_CAP_REFRESH_NEW_RCV)
9798 || CHECK_FLAG(p->cap,
9799 PEER_CAP_REFRESH_OLD_RCV)) {
9800 if (CHECK_FLAG(p->cap,
9801 PEER_CAP_REFRESH_ADV)
9802 && (CHECK_FLAG(
9803 p->cap,
9804 PEER_CAP_REFRESH_NEW_RCV)
9805 || CHECK_FLAG(
9806 p->cap,
9807 PEER_CAP_REFRESH_OLD_RCV))) {
9808 if (CHECK_FLAG(
9809 p->cap,
9810 PEER_CAP_REFRESH_OLD_RCV)
9811 && CHECK_FLAG(
9812 p->cap,
9813 PEER_CAP_REFRESH_NEW_RCV))
9814 json_object_string_add(
9815 json_cap,
9816 "routeRefresh",
9817 "advertisedAndReceivedOldNew");
9818 else {
9819 if (CHECK_FLAG(
9820 p->cap,
9821 PEER_CAP_REFRESH_OLD_RCV))
9822 json_object_string_add(
9823 json_cap,
9824 "routeRefresh",
9825 "advertisedAndReceivedOld");
9826 else
9827 json_object_string_add(
9828 json_cap,
9829 "routeRefresh",
9830 "advertisedAndReceivedNew");
9831 }
9832 } else if (
9833 CHECK_FLAG(
9834 p->cap,
9835 PEER_CAP_REFRESH_ADV))
9836 json_object_string_add(
9837 json_cap,
9838 "routeRefresh",
9839 "advertised");
9840 else if (
9841 CHECK_FLAG(
9842 p->cap,
9843 PEER_CAP_REFRESH_NEW_RCV)
9844 || CHECK_FLAG(
9845 p->cap,
9846 PEER_CAP_REFRESH_OLD_RCV))
9847 json_object_string_add(
9848 json_cap,
9849 "routeRefresh",
9850 "received");
9851 }
9852
9853 /* Multiprotocol Extensions */
9854 json_object *json_multi = NULL;
9855 json_multi = json_object_new_object();
9856
9857 FOREACH_AFI_SAFI (afi, safi) {
9858 if (p->afc_adv[afi][safi]
9859 || p->afc_recv[afi][safi]) {
9860 json_object *json_exten = NULL;
9861 json_exten =
9862 json_object_new_object();
9863
9864 if (p->afc_adv[afi][safi]
9865 && p->afc_recv[afi][safi])
9866 json_object_boolean_true_add(
9867 json_exten,
9868 "advertisedAndReceived");
9869 else if (p->afc_adv[afi][safi])
9870 json_object_boolean_true_add(
9871 json_exten,
9872 "advertised");
9873 else if (p->afc_recv[afi][safi])
9874 json_object_boolean_true_add(
9875 json_exten,
9876 "received");
9877
9878 json_object_object_add(
9879 json_multi,
9880 afi_safi_print(afi,
9881 safi),
9882 json_exten);
9883 }
9884 }
9885 json_object_object_add(
9886 json_cap, "multiprotocolExtensions",
9887 json_multi);
9888
9889 /* Hostname capabilities */
9890 json_object *json_hname = NULL;
9891
9892 json_hname = json_object_new_object();
9893
9894 if (CHECK_FLAG(p->cap, PEER_CAP_HOSTNAME_ADV)) {
9895 json_object_string_add(
9896 json_hname, "advHostName",
9897 bgp->peer_self->hostname
9898 ? bgp->peer_self
9899 ->hostname
9900 : "n/a");
9901 json_object_string_add(
9902 json_hname, "advDomainName",
9903 bgp->peer_self->domainname
9904 ? bgp->peer_self
9905 ->domainname
9906 : "n/a");
9907 }
9908
9909
9910 if (CHECK_FLAG(p->cap, PEER_CAP_HOSTNAME_RCV)) {
9911 json_object_string_add(
9912 json_hname, "rcvHostName",
9913 p->hostname ? p->hostname
9914 : "n/a");
9915 json_object_string_add(
9916 json_hname, "rcvDomainName",
9917 p->domainname ? p->domainname
9918 : "n/a");
9919 }
9920
9921 json_object_object_add(json_cap, "hostName",
9922 json_hname);
9923
9924 /* Gracefull Restart */
9925 if (CHECK_FLAG(p->cap, PEER_CAP_RESTART_RCV)
9926 || CHECK_FLAG(p->cap,
9927 PEER_CAP_RESTART_ADV)) {
9928 if (CHECK_FLAG(p->cap,
9929 PEER_CAP_RESTART_ADV)
9930 && CHECK_FLAG(p->cap,
9931 PEER_CAP_RESTART_RCV))
9932 json_object_string_add(
9933 json_cap,
9934 "gracefulRestart",
9935 "advertisedAndReceived");
9936 else if (CHECK_FLAG(
9937 p->cap,
9938 PEER_CAP_RESTART_ADV))
9939 json_object_string_add(
9940 json_cap,
9941 "gracefulRestartCapability",
9942 "advertised");
9943 else if (CHECK_FLAG(
9944 p->cap,
9945 PEER_CAP_RESTART_RCV))
9946 json_object_string_add(
9947 json_cap,
9948 "gracefulRestartCapability",
9949 "received");
9950
9951 if (CHECK_FLAG(p->cap,
9952 PEER_CAP_RESTART_RCV)) {
9953 int restart_af_count = 0;
9954 json_object *json_restart =
9955 NULL;
9956 json_restart =
9957 json_object_new_object();
9958
9959 json_object_int_add(
9960 json_cap,
9961 "gracefulRestartRemoteTimerMsecs",
9962 p->v_gr_restart * 1000);
9963
9964 FOREACH_AFI_SAFI (afi, safi) {
9965 if (CHECK_FLAG(
9966 p->af_cap
9967 [afi]
9968 [safi],
9969 PEER_CAP_RESTART_AF_RCV)) {
9970 json_object *
9971 json_sub =
9972 NULL;
9973 json_sub =
9974 json_object_new_object();
9975
9976 if (CHECK_FLAG(
9977 p->af_cap
9978 [afi]
9979 [safi],
9980 PEER_CAP_RESTART_AF_PRESERVE_RCV))
9981 json_object_boolean_true_add(
9982 json_sub,
9983 "preserved");
9984 restart_af_count++;
9985 json_object_object_add(
9986 json_restart,
9987 afi_safi_print(
9988 afi,
9989 safi),
9990 json_sub);
9991 }
9992 }
9993 if (!restart_af_count) {
9994 json_object_string_add(
9995 json_cap,
9996 "addressFamiliesByPeer",
9997 "none");
9998 json_object_free(
9999 json_restart);
10000 } else
10001 json_object_object_add(
10002 json_cap,
10003 "addressFamiliesByPeer",
10004 json_restart);
10005 }
10006 }
10007 json_object_object_add(json_neigh,
10008 "neighborCapabilities",
10009 json_cap);
10010 } else {
10011 vty_out(vty, " Neighbor capabilities:\n");
10012
10013 /* AS4 */
10014 if (CHECK_FLAG(p->cap, PEER_CAP_AS4_RCV)
10015 || CHECK_FLAG(p->cap, PEER_CAP_AS4_ADV)) {
10016 vty_out(vty, " 4 Byte AS:");
10017 if (CHECK_FLAG(p->cap,
10018 PEER_CAP_AS4_ADV))
10019 vty_out(vty, " advertised");
10020 if (CHECK_FLAG(p->cap,
10021 PEER_CAP_AS4_RCV))
10022 vty_out(vty, " %sreceived",
10023 CHECK_FLAG(
10024 p->cap,
10025 PEER_CAP_AS4_ADV)
10026 ? "and "
10027 : "");
10028 vty_out(vty, "\n");
10029 }
10030
10031 /* AddPath */
10032 if (CHECK_FLAG(p->cap, PEER_CAP_ADDPATH_RCV)
10033 || CHECK_FLAG(p->cap,
10034 PEER_CAP_ADDPATH_ADV)) {
10035 vty_out(vty, " AddPath:\n");
10036
10037 FOREACH_AFI_SAFI (afi, safi) {
10038 if (CHECK_FLAG(
10039 p->af_cap[afi]
10040 [safi],
10041 PEER_CAP_ADDPATH_AF_TX_ADV)
10042 || CHECK_FLAG(
10043 p->af_cap[afi]
10044 [safi],
10045 PEER_CAP_ADDPATH_AF_TX_RCV)) {
10046 vty_out(vty,
10047 " %s: TX ",
10048 afi_safi_print(
10049 afi,
10050 safi));
10051
10052 if (CHECK_FLAG(
10053 p->af_cap
10054 [afi]
10055 [safi],
10056 PEER_CAP_ADDPATH_AF_TX_ADV))
10057 vty_out(vty,
10058 "advertised %s",
10059 afi_safi_print(
10060 afi,
10061 safi));
10062
10063 if (CHECK_FLAG(
10064 p->af_cap
10065 [afi]
10066 [safi],
10067 PEER_CAP_ADDPATH_AF_TX_RCV))
10068 vty_out(vty,
10069 "%sreceived",
10070 CHECK_FLAG(
10071 p->af_cap
10072 [afi]
10073 [safi],
10074 PEER_CAP_ADDPATH_AF_TX_ADV)
10075 ? " and "
10076 : "");
10077
10078 vty_out(vty, "\n");
10079 }
10080
10081 if (CHECK_FLAG(
10082 p->af_cap[afi]
10083 [safi],
10084 PEER_CAP_ADDPATH_AF_RX_ADV)
10085 || CHECK_FLAG(
10086 p->af_cap[afi]
10087 [safi],
10088 PEER_CAP_ADDPATH_AF_RX_RCV)) {
10089 vty_out(vty,
10090 " %s: RX ",
10091 afi_safi_print(
10092 afi,
10093 safi));
10094
10095 if (CHECK_FLAG(
10096 p->af_cap
10097 [afi]
10098 [safi],
10099 PEER_CAP_ADDPATH_AF_RX_ADV))
10100 vty_out(vty,
10101 "advertised %s",
10102 afi_safi_print(
10103 afi,
10104 safi));
10105
10106 if (CHECK_FLAG(
10107 p->af_cap
10108 [afi]
10109 [safi],
10110 PEER_CAP_ADDPATH_AF_RX_RCV))
10111 vty_out(vty,
10112 "%sreceived",
10113 CHECK_FLAG(
10114 p->af_cap
10115 [afi]
10116 [safi],
10117 PEER_CAP_ADDPATH_AF_RX_ADV)
10118 ? " and "
10119 : "");
10120
10121 vty_out(vty, "\n");
10122 }
10123 }
10124 }
10125
10126 /* Dynamic */
10127 if (CHECK_FLAG(p->cap, PEER_CAP_DYNAMIC_RCV)
10128 || CHECK_FLAG(p->cap,
10129 PEER_CAP_DYNAMIC_ADV)) {
10130 vty_out(vty, " Dynamic:");
10131 if (CHECK_FLAG(p->cap,
10132 PEER_CAP_DYNAMIC_ADV))
10133 vty_out(vty, " advertised");
10134 if (CHECK_FLAG(p->cap,
10135 PEER_CAP_DYNAMIC_RCV))
10136 vty_out(vty, " %sreceived",
10137 CHECK_FLAG(
10138 p->cap,
10139 PEER_CAP_DYNAMIC_ADV)
10140 ? "and "
10141 : "");
10142 vty_out(vty, "\n");
10143 }
10144
10145 /* Extended nexthop */
10146 if (CHECK_FLAG(p->cap, PEER_CAP_ENHE_RCV)
10147 || CHECK_FLAG(p->cap, PEER_CAP_ENHE_ADV)) {
10148 vty_out(vty, " Extended nexthop:");
10149 if (CHECK_FLAG(p->cap,
10150 PEER_CAP_ENHE_ADV))
10151 vty_out(vty, " advertised");
10152 if (CHECK_FLAG(p->cap,
10153 PEER_CAP_ENHE_RCV))
10154 vty_out(vty, " %sreceived",
10155 CHECK_FLAG(
10156 p->cap,
10157 PEER_CAP_ENHE_ADV)
10158 ? "and "
10159 : "");
10160 vty_out(vty, "\n");
10161
10162 if (CHECK_FLAG(p->cap,
10163 PEER_CAP_ENHE_RCV)) {
10164 vty_out(vty,
10165 " Address families by peer:\n ");
10166 for (safi = SAFI_UNICAST;
10167 safi < SAFI_MAX; safi++)
10168 if (CHECK_FLAG(
10169 p->af_cap
10170 [AFI_IP]
10171 [safi],
10172 PEER_CAP_ENHE_AF_RCV))
10173 vty_out(vty,
10174 " %s\n",
10175 afi_safi_print(
10176 AFI_IP,
10177 safi));
10178 }
10179 }
10180
10181 /* Route Refresh */
10182 if (CHECK_FLAG(p->cap, PEER_CAP_REFRESH_ADV)
10183 || CHECK_FLAG(p->cap,
10184 PEER_CAP_REFRESH_NEW_RCV)
10185 || CHECK_FLAG(p->cap,
10186 PEER_CAP_REFRESH_OLD_RCV)) {
10187 vty_out(vty, " Route refresh:");
10188 if (CHECK_FLAG(p->cap,
10189 PEER_CAP_REFRESH_ADV))
10190 vty_out(vty, " advertised");
10191 if (CHECK_FLAG(p->cap,
10192 PEER_CAP_REFRESH_NEW_RCV)
10193 || CHECK_FLAG(
10194 p->cap,
10195 PEER_CAP_REFRESH_OLD_RCV))
10196 vty_out(vty, " %sreceived(%s)",
10197 CHECK_FLAG(
10198 p->cap,
10199 PEER_CAP_REFRESH_ADV)
10200 ? "and "
10201 : "",
10202 (CHECK_FLAG(
10203 p->cap,
10204 PEER_CAP_REFRESH_OLD_RCV)
10205 && CHECK_FLAG(
10206 p->cap,
10207 PEER_CAP_REFRESH_NEW_RCV))
10208 ? "old & new"
10209 : CHECK_FLAG(
10210 p->cap,
10211 PEER_CAP_REFRESH_OLD_RCV)
10212 ? "old"
10213 : "new");
10214
10215 vty_out(vty, "\n");
10216 }
10217
10218 /* Multiprotocol Extensions */
10219 FOREACH_AFI_SAFI (afi, safi)
10220 if (p->afc_adv[afi][safi]
10221 || p->afc_recv[afi][safi]) {
10222 vty_out(vty,
10223 " Address Family %s:",
10224 afi_safi_print(afi,
10225 safi));
10226 if (p->afc_adv[afi][safi])
10227 vty_out(vty,
10228 " advertised");
10229 if (p->afc_recv[afi][safi])
10230 vty_out(vty,
10231 " %sreceived",
10232 p->afc_adv[afi]
10233 [safi]
10234 ? "and "
10235 : "");
10236 vty_out(vty, "\n");
10237 }
10238
10239 /* Hostname capability */
10240 vty_out(vty, " Hostname Capability:");
10241
10242 if (CHECK_FLAG(p->cap, PEER_CAP_HOSTNAME_ADV)) {
10243 vty_out(vty,
10244 " advertised (name: %s,domain name: %s)",
10245 bgp->peer_self->hostname
10246 ? bgp->peer_self
10247 ->hostname
10248 : "n/a",
10249 bgp->peer_self->domainname
10250 ? bgp->peer_self
10251 ->domainname
10252 : "n/a");
10253 } else {
10254 vty_out(vty, " not advertised");
10255 }
10256
10257 if (CHECK_FLAG(p->cap, PEER_CAP_HOSTNAME_RCV)) {
10258 vty_out(vty,
10259 " received (name: %s,domain name: %s)",
10260 p->hostname ? p->hostname
10261 : "n/a",
10262 p->domainname ? p->domainname
10263 : "n/a");
10264 } else {
10265 vty_out(vty, " not received");
10266 }
10267
10268 vty_out(vty, "\n");
10269
10270 /* Gracefull Restart */
10271 if (CHECK_FLAG(p->cap, PEER_CAP_RESTART_RCV)
10272 || CHECK_FLAG(p->cap,
10273 PEER_CAP_RESTART_ADV)) {
10274 vty_out(vty,
10275 " Graceful Restart Capabilty:");
10276 if (CHECK_FLAG(p->cap,
10277 PEER_CAP_RESTART_ADV))
10278 vty_out(vty, " advertised");
10279 if (CHECK_FLAG(p->cap,
10280 PEER_CAP_RESTART_RCV))
10281 vty_out(vty, " %sreceived",
10282 CHECK_FLAG(
10283 p->cap,
10284 PEER_CAP_RESTART_ADV)
10285 ? "and "
10286 : "");
10287 vty_out(vty, "\n");
10288
10289 if (CHECK_FLAG(p->cap,
10290 PEER_CAP_RESTART_RCV)) {
10291 int restart_af_count = 0;
10292
10293 vty_out(vty,
10294 " Remote Restart timer is %d seconds\n",
10295 p->v_gr_restart);
10296 vty_out(vty,
10297 " Address families by peer:\n ");
10298
10299 FOREACH_AFI_SAFI (afi, safi)
10300 if (CHECK_FLAG(
10301 p->af_cap
10302 [afi]
10303 [safi],
10304 PEER_CAP_RESTART_AF_RCV)) {
10305 vty_out(vty,
10306 "%s%s(%s)",
10307 restart_af_count
10308 ? ", "
10309 : "",
10310 afi_safi_print(
10311 afi,
10312 safi),
10313 CHECK_FLAG(
10314 p->af_cap
10315 [afi]
10316 [safi],
10317 PEER_CAP_RESTART_AF_PRESERVE_RCV)
10318 ? "preserved"
10319 : "not preserved");
10320 restart_af_count++;
10321 }
10322 if (!restart_af_count)
10323 vty_out(vty, "none");
10324 vty_out(vty, "\n");
10325 }
10326 }
10327 }
10328 }
10329 }
10330
10331 /* graceful restart information */
10332 if (CHECK_FLAG(p->cap, PEER_CAP_RESTART_RCV) || p->t_gr_restart
10333 || p->t_gr_stale) {
10334 json_object *json_grace = NULL;
10335 json_object *json_grace_send = NULL;
10336 json_object *json_grace_recv = NULL;
10337 int eor_send_af_count = 0;
10338 int eor_receive_af_count = 0;
10339
10340 if (use_json) {
10341 json_grace = json_object_new_object();
10342 json_grace_send = json_object_new_object();
10343 json_grace_recv = json_object_new_object();
10344
10345 if (p->status == Established) {
10346 FOREACH_AFI_SAFI (afi, safi) {
10347 if (CHECK_FLAG(p->af_sflags[afi][safi],
10348 PEER_STATUS_EOR_SEND)) {
10349 json_object_boolean_true_add(
10350 json_grace_send,
10351 afi_safi_print(afi,
10352 safi));
10353 eor_send_af_count++;
10354 }
10355 }
10356 FOREACH_AFI_SAFI (afi, safi) {
10357 if (CHECK_FLAG(
10358 p->af_sflags[afi][safi],
10359 PEER_STATUS_EOR_RECEIVED)) {
10360 json_object_boolean_true_add(
10361 json_grace_recv,
10362 afi_safi_print(afi,
10363 safi));
10364 eor_receive_af_count++;
10365 }
10366 }
10367 }
10368
10369 json_object_object_add(json_grace, "endOfRibSend",
10370 json_grace_send);
10371 json_object_object_add(json_grace, "endOfRibRecv",
10372 json_grace_recv);
10373
10374 if (p->t_gr_restart)
10375 json_object_int_add(json_grace,
10376 "gracefulRestartTimerMsecs",
10377 thread_timer_remain_second(
10378 p->t_gr_restart)
10379 * 1000);
10380
10381 if (p->t_gr_stale)
10382 json_object_int_add(
10383 json_grace,
10384 "gracefulStalepathTimerMsecs",
10385 thread_timer_remain_second(
10386 p->t_gr_stale)
10387 * 1000);
10388
10389 json_object_object_add(
10390 json_neigh, "gracefulRestartInfo", json_grace);
10391 } else {
10392 vty_out(vty, " Graceful restart information:\n");
10393 if (p->status == Established) {
10394 vty_out(vty, " End-of-RIB send: ");
10395 FOREACH_AFI_SAFI (afi, safi) {
10396 if (CHECK_FLAG(p->af_sflags[afi][safi],
10397 PEER_STATUS_EOR_SEND)) {
10398 vty_out(vty, "%s%s",
10399 eor_send_af_count ? ", "
10400 : "",
10401 afi_safi_print(afi,
10402 safi));
10403 eor_send_af_count++;
10404 }
10405 }
10406 vty_out(vty, "\n");
10407 vty_out(vty, " End-of-RIB received: ");
10408 FOREACH_AFI_SAFI (afi, safi) {
10409 if (CHECK_FLAG(
10410 p->af_sflags[afi][safi],
10411 PEER_STATUS_EOR_RECEIVED)) {
10412 vty_out(vty, "%s%s",
10413 eor_receive_af_count
10414 ? ", "
10415 : "",
10416 afi_safi_print(afi,
10417 safi));
10418 eor_receive_af_count++;
10419 }
10420 }
10421 vty_out(vty, "\n");
10422 }
10423
10424 if (p->t_gr_restart)
10425 vty_out(vty,
10426 " The remaining time of restart timer is %ld\n",
10427 thread_timer_remain_second(
10428 p->t_gr_restart));
10429
10430 if (p->t_gr_stale)
10431 vty_out(vty,
10432 " The remaining time of stalepath timer is %ld\n",
10433 thread_timer_remain_second(
10434 p->t_gr_stale));
10435 }
10436 }
10437 if (use_json) {
10438 json_object *json_stat = NULL;
10439 json_stat = json_object_new_object();
10440 /* Packet counts. */
10441 json_object_int_add(json_stat, "depthInq", 0);
10442 json_object_int_add(json_stat, "depthOutq",
10443 (unsigned long)p->obuf->count);
10444 json_object_int_add(json_stat, "opensSent",
10445 atomic_load_explicit(&p->open_out,
10446 memory_order_relaxed));
10447 json_object_int_add(json_stat, "opensRecv",
10448 atomic_load_explicit(&p->open_in,
10449 memory_order_relaxed));
10450 json_object_int_add(json_stat, "notificationsSent",
10451 atomic_load_explicit(&p->notify_out,
10452 memory_order_relaxed));
10453 json_object_int_add(json_stat, "notificationsRecv",
10454 atomic_load_explicit(&p->notify_in,
10455 memory_order_relaxed));
10456 json_object_int_add(json_stat, "updatesSent",
10457 atomic_load_explicit(&p->update_out,
10458 memory_order_relaxed));
10459 json_object_int_add(json_stat, "updatesRecv",
10460 atomic_load_explicit(&p->update_in,
10461 memory_order_relaxed));
10462 json_object_int_add(json_stat, "keepalivesSent",
10463 atomic_load_explicit(&p->keepalive_out,
10464 memory_order_relaxed));
10465 json_object_int_add(json_stat, "keepalivesRecv",
10466 atomic_load_explicit(&p->keepalive_in,
10467 memory_order_relaxed));
10468 json_object_int_add(json_stat, "routeRefreshSent",
10469 atomic_load_explicit(&p->refresh_out,
10470 memory_order_relaxed));
10471 json_object_int_add(json_stat, "routeRefreshRecv",
10472 atomic_load_explicit(&p->refresh_in,
10473 memory_order_relaxed));
10474 json_object_int_add(json_stat, "capabilitySent",
10475 atomic_load_explicit(&p->dynamic_cap_out,
10476 memory_order_relaxed));
10477 json_object_int_add(json_stat, "capabilityRecv",
10478 atomic_load_explicit(&p->dynamic_cap_in,
10479 memory_order_relaxed));
10480 json_object_int_add(json_stat, "totalSent", PEER_TOTAL_TX(p));
10481 json_object_int_add(json_stat, "totalRecv", PEER_TOTAL_RX(p));
10482 json_object_object_add(json_neigh, "messageStats", json_stat);
10483 } else {
10484 /* Packet counts. */
10485 vty_out(vty, " Message statistics:\n");
10486 vty_out(vty, " Inq depth is 0\n");
10487 vty_out(vty, " Outq depth is %lu\n",
10488 (unsigned long)p->obuf->count);
10489 vty_out(vty, " Sent Rcvd\n");
10490 vty_out(vty, " Opens: %10d %10d\n",
10491 atomic_load_explicit(&p->open_out,
10492 memory_order_relaxed),
10493 atomic_load_explicit(&p->open_in,
10494 memory_order_relaxed));
10495 vty_out(vty, " Notifications: %10d %10d\n",
10496 atomic_load_explicit(&p->notify_out,
10497 memory_order_relaxed),
10498 atomic_load_explicit(&p->notify_in,
10499 memory_order_relaxed));
10500 vty_out(vty, " Updates: %10d %10d\n",
10501 atomic_load_explicit(&p->update_out,
10502 memory_order_relaxed),
10503 atomic_load_explicit(&p->update_in,
10504 memory_order_relaxed));
10505 vty_out(vty, " Keepalives: %10d %10d\n",
10506 atomic_load_explicit(&p->keepalive_out,
10507 memory_order_relaxed),
10508 atomic_load_explicit(&p->keepalive_in,
10509 memory_order_relaxed));
10510 vty_out(vty, " Route Refresh: %10d %10d\n",
10511 atomic_load_explicit(&p->refresh_out,
10512 memory_order_relaxed),
10513 atomic_load_explicit(&p->refresh_in,
10514 memory_order_relaxed));
10515 vty_out(vty, " Capability: %10d %10d\n",
10516 atomic_load_explicit(&p->dynamic_cap_out,
10517 memory_order_relaxed),
10518 atomic_load_explicit(&p->dynamic_cap_in,
10519 memory_order_relaxed));
10520 vty_out(vty, " Total: %10d %10d\n", PEER_TOTAL_TX(p),
10521 PEER_TOTAL_RX(p));
10522 }
10523
10524 if (use_json) {
10525 /* advertisement-interval */
10526 json_object_int_add(json_neigh,
10527 "minBtwnAdvertisementRunsTimerMsecs",
10528 p->v_routeadv * 1000);
10529
10530 /* Update-source. */
10531 if (p->update_if || p->update_source) {
10532 if (p->update_if)
10533 json_object_string_add(json_neigh,
10534 "updateSource",
10535 p->update_if);
10536 else if (p->update_source)
10537 json_object_string_add(
10538 json_neigh, "updateSource",
10539 sockunion2str(p->update_source, buf1,
10540 SU_ADDRSTRLEN));
10541 }
10542 } else {
10543 /* advertisement-interval */
10544 vty_out(vty,
10545 " Minimum time between advertisement runs is %d seconds\n",
10546 p->v_routeadv);
10547
10548 /* Update-source. */
10549 if (p->update_if || p->update_source) {
10550 vty_out(vty, " Update source is ");
10551 if (p->update_if)
10552 vty_out(vty, "%s", p->update_if);
10553 else if (p->update_source)
10554 vty_out(vty, "%s",
10555 sockunion2str(p->update_source, buf1,
10556 SU_ADDRSTRLEN));
10557 vty_out(vty, "\n");
10558 }
10559
10560 vty_out(vty, "\n");
10561 }
10562
10563 /* Address Family Information */
10564 json_object *json_hold = NULL;
10565
10566 if (use_json)
10567 json_hold = json_object_new_object();
10568
10569 FOREACH_AFI_SAFI (afi, safi)
10570 if (p->afc[afi][safi])
10571 bgp_show_peer_afi(vty, p, afi, safi, use_json,
10572 json_hold);
10573
10574 if (use_json) {
10575 json_object_object_add(json_neigh, "addressFamilyInfo",
10576 json_hold);
10577 json_object_int_add(json_neigh, "connectionsEstablished",
10578 p->established);
10579 json_object_int_add(json_neigh, "connectionsDropped",
10580 p->dropped);
10581 } else
10582 vty_out(vty, " Connections established %d; dropped %d\n",
10583 p->established, p->dropped);
10584
10585 if (!p->last_reset) {
10586 if (use_json)
10587 json_object_string_add(json_neigh, "lastReset",
10588 "never");
10589 else
10590 vty_out(vty, " Last reset never\n");
10591 } else {
10592 if (use_json) {
10593 time_t uptime;
10594 struct tm *tm;
10595
10596 uptime = bgp_clock();
10597 uptime -= p->resettime;
10598 tm = gmtime(&uptime);
10599 json_object_int_add(json_neigh, "lastResetTimerMsecs",
10600 (tm->tm_sec * 1000)
10601 + (tm->tm_min * 60000)
10602 + (tm->tm_hour * 3600000));
10603 json_object_string_add(
10604 json_neigh, "lastResetDueTo",
10605 peer_down_str[(int)p->last_reset]);
10606 if (p->last_reset == PEER_DOWN_NOTIFY_SEND
10607 || p->last_reset == PEER_DOWN_NOTIFY_RECEIVED) {
10608 char errorcodesubcode_hexstr[5];
10609 char errorcodesubcode_str[256];
10610
10611 code_str = bgp_notify_code_str(p->notify.code);
10612 subcode_str = bgp_notify_subcode_str(
10613 p->notify.code, p->notify.subcode);
10614
10615 sprintf(errorcodesubcode_hexstr, "%02X%02X",
10616 p->notify.code, p->notify.subcode);
10617 json_object_string_add(json_neigh,
10618 "lastErrorCodeSubcode",
10619 errorcodesubcode_hexstr);
10620 snprintf(errorcodesubcode_str, 255, "%s%s",
10621 code_str, subcode_str);
10622 json_object_string_add(json_neigh,
10623 "lastNotificationReason",
10624 errorcodesubcode_str);
10625 if (p->last_reset == PEER_DOWN_NOTIFY_RECEIVED
10626 && p->notify.code == BGP_NOTIFY_CEASE
10627 && (p->notify.subcode
10628 == BGP_NOTIFY_CEASE_ADMIN_SHUTDOWN
10629 || p->notify.subcode
10630 == BGP_NOTIFY_CEASE_ADMIN_RESET)
10631 && p->notify.length) {
10632 char msgbuf[1024];
10633 const char *msg_str;
10634
10635 msg_str = bgp_notify_admin_message(
10636 msgbuf, sizeof(msgbuf),
10637 (uint8_t *)p->notify.data,
10638 p->notify.length);
10639 if (msg_str)
10640 json_object_string_add(
10641 json_neigh,
10642 "lastShutdownDescription",
10643 msg_str);
10644 }
10645 }
10646 } else {
10647 vty_out(vty, " Last reset %s, ",
10648 peer_uptime(p->resettime, timebuf,
10649 BGP_UPTIME_LEN, 0, NULL));
10650
10651 if (p->last_reset == PEER_DOWN_NOTIFY_SEND
10652 || p->last_reset == PEER_DOWN_NOTIFY_RECEIVED) {
10653 code_str = bgp_notify_code_str(p->notify.code);
10654 subcode_str = bgp_notify_subcode_str(
10655 p->notify.code, p->notify.subcode);
10656 vty_out(vty, "due to NOTIFICATION %s (%s%s)\n",
10657 p->last_reset == PEER_DOWN_NOTIFY_SEND
10658 ? "sent"
10659 : "received",
10660 code_str, subcode_str);
10661 if (p->last_reset == PEER_DOWN_NOTIFY_RECEIVED
10662 && p->notify.code == BGP_NOTIFY_CEASE
10663 && (p->notify.subcode
10664 == BGP_NOTIFY_CEASE_ADMIN_SHUTDOWN
10665 || p->notify.subcode
10666 == BGP_NOTIFY_CEASE_ADMIN_RESET)
10667 && p->notify.length) {
10668 char msgbuf[1024];
10669 const char *msg_str;
10670
10671 msg_str = bgp_notify_admin_message(
10672 msgbuf, sizeof(msgbuf),
10673 (uint8_t *)p->notify.data,
10674 p->notify.length);
10675 if (msg_str)
10676 vty_out(vty,
10677 " Message: \"%s\"\n",
10678 msg_str);
10679 }
10680 } else {
10681 vty_out(vty, "due to %s\n",
10682 peer_down_str[(int)p->last_reset]);
10683 }
10684
10685 if (p->last_reset_cause_size) {
10686 msg = p->last_reset_cause;
10687 vty_out(vty,
10688 " Message received that caused BGP to send a NOTIFICATION:\n ");
10689 for (i = 1; i <= p->last_reset_cause_size;
10690 i++) {
10691 vty_out(vty, "%02X", *msg++);
10692
10693 if (i != p->last_reset_cause_size) {
10694 if (i % 16 == 0) {
10695 vty_out(vty, "\n ");
10696 } else if (i % 4 == 0) {
10697 vty_out(vty, " ");
10698 }
10699 }
10700 }
10701 vty_out(vty, "\n");
10702 }
10703 }
10704 }
10705
10706 if (CHECK_FLAG(p->sflags, PEER_STATUS_PREFIX_OVERFLOW)) {
10707 if (use_json)
10708 json_object_boolean_true_add(json_neigh,
10709 "prefixesConfigExceedMax");
10710 else
10711 vty_out(vty,
10712 " Peer had exceeded the max. no. of prefixes configured.\n");
10713
10714 if (p->t_pmax_restart) {
10715 if (use_json) {
10716 json_object_boolean_true_add(
10717 json_neigh, "reducePrefixNumFrom");
10718 json_object_int_add(json_neigh,
10719 "restartInTimerMsec",
10720 thread_timer_remain_second(
10721 p->t_pmax_restart)
10722 * 1000);
10723 } else
10724 vty_out(vty,
10725 " Reduce the no. of prefix from %s, will restart in %ld seconds\n",
10726 p->host, thread_timer_remain_second(
10727 p->t_pmax_restart));
10728 } else {
10729 if (use_json)
10730 json_object_boolean_true_add(
10731 json_neigh,
10732 "reducePrefixNumAndClearIpBgp");
10733 else
10734 vty_out(vty,
10735 " Reduce the no. of prefix and clear ip bgp %s to restore peering\n",
10736 p->host);
10737 }
10738 }
10739
10740 /* EBGP Multihop and GTSM */
10741 if (p->sort != BGP_PEER_IBGP) {
10742 if (use_json) {
10743 if (p->gtsm_hops > 0)
10744 json_object_int_add(json_neigh,
10745 "externalBgpNbrMaxHopsAway",
10746 p->gtsm_hops);
10747 else if (p->ttl > 1)
10748 json_object_int_add(json_neigh,
10749 "externalBgpNbrMaxHopsAway",
10750 p->ttl);
10751 } else {
10752 if (p->gtsm_hops > 0)
10753 vty_out(vty,
10754 " External BGP neighbor may be up to %d hops away.\n",
10755 p->gtsm_hops);
10756 else if (p->ttl > 1)
10757 vty_out(vty,
10758 " External BGP neighbor may be up to %d hops away.\n",
10759 p->ttl);
10760 }
10761 } else {
10762 if (p->gtsm_hops > 0) {
10763 if (use_json)
10764 json_object_int_add(json_neigh,
10765 "internalBgpNbrMaxHopsAway",
10766 p->gtsm_hops);
10767 else
10768 vty_out(vty,
10769 " Internal BGP neighbor may be up to %d hops away.\n",
10770 p->gtsm_hops);
10771 }
10772 }
10773
10774 /* Local address. */
10775 if (p->su_local) {
10776 if (use_json) {
10777 json_object_string_add(json_neigh, "hostLocal",
10778 sockunion2str(p->su_local, buf1,
10779 SU_ADDRSTRLEN));
10780 json_object_int_add(json_neigh, "portLocal",
10781 ntohs(p->su_local->sin.sin_port));
10782 } else
10783 vty_out(vty, "Local host: %s, Local port: %d\n",
10784 sockunion2str(p->su_local, buf1, SU_ADDRSTRLEN),
10785 ntohs(p->su_local->sin.sin_port));
10786 }
10787
10788 /* Remote address. */
10789 if (p->su_remote) {
10790 if (use_json) {
10791 json_object_string_add(json_neigh, "hostForeign",
10792 sockunion2str(p->su_remote, buf1,
10793 SU_ADDRSTRLEN));
10794 json_object_int_add(json_neigh, "portForeign",
10795 ntohs(p->su_remote->sin.sin_port));
10796 } else
10797 vty_out(vty, "Foreign host: %s, Foreign port: %d\n",
10798 sockunion2str(p->su_remote, buf1,
10799 SU_ADDRSTRLEN),
10800 ntohs(p->su_remote->sin.sin_port));
10801 }
10802
10803 /* Nexthop display. */
10804 if (p->su_local) {
10805 if (use_json) {
10806 json_object_string_add(json_neigh, "nexthop",
10807 inet_ntop(AF_INET,
10808 &p->nexthop.v4, buf1,
10809 sizeof(buf1)));
10810 json_object_string_add(json_neigh, "nexthopGlobal",
10811 inet_ntop(AF_INET6,
10812 &p->nexthop.v6_global,
10813 buf1, sizeof(buf1)));
10814 json_object_string_add(json_neigh, "nexthopLocal",
10815 inet_ntop(AF_INET6,
10816 &p->nexthop.v6_local,
10817 buf1, sizeof(buf1)));
10818 if (p->shared_network)
10819 json_object_string_add(json_neigh,
10820 "bgpConnection",
10821 "sharedNetwork");
10822 else
10823 json_object_string_add(json_neigh,
10824 "bgpConnection",
10825 "nonSharedNetwork");
10826 } else {
10827 vty_out(vty, "Nexthop: %s\n",
10828 inet_ntop(AF_INET, &p->nexthop.v4, buf1,
10829 sizeof(buf1)));
10830 vty_out(vty, "Nexthop global: %s\n",
10831 inet_ntop(AF_INET6, &p->nexthop.v6_global, buf1,
10832 sizeof(buf1)));
10833 vty_out(vty, "Nexthop local: %s\n",
10834 inet_ntop(AF_INET6, &p->nexthop.v6_local, buf1,
10835 sizeof(buf1)));
10836 vty_out(vty, "BGP connection: %s\n",
10837 p->shared_network ? "shared network"
10838 : "non shared network");
10839 }
10840 }
10841
10842 /* Timer information. */
10843 if (use_json) {
10844 json_object_int_add(json_neigh, "connectRetryTimer",
10845 p->v_connect);
10846 if (p->status == Established && p->rtt)
10847 json_object_int_add(json_neigh, "estimatedRttInMsecs",
10848 p->rtt);
10849 if (p->t_start)
10850 json_object_int_add(
10851 json_neigh, "nextStartTimerDueInMsecs",
10852 thread_timer_remain_second(p->t_start) * 1000);
10853 if (p->t_connect)
10854 json_object_int_add(
10855 json_neigh, "nextConnectTimerDueInMsecs",
10856 thread_timer_remain_second(p->t_connect)
10857 * 1000);
10858 if (p->t_routeadv) {
10859 json_object_int_add(json_neigh, "mraiInterval",
10860 p->v_routeadv);
10861 json_object_int_add(
10862 json_neigh, "mraiTimerExpireInMsecs",
10863 thread_timer_remain_second(p->t_routeadv)
10864 * 1000);
10865 }
10866 if (p->password)
10867 json_object_int_add(json_neigh, "authenticationEnabled",
10868 1);
10869
10870 if (p->t_read)
10871 json_object_string_add(json_neigh, "readThread", "on");
10872 else
10873 json_object_string_add(json_neigh, "readThread", "off");
10874
10875 if (CHECK_FLAG(p->thread_flags, PEER_THREAD_WRITES_ON))
10876 json_object_string_add(json_neigh, "writeThread", "on");
10877 else
10878 json_object_string_add(json_neigh, "writeThread",
10879 "off");
10880 } else {
10881 vty_out(vty, "BGP Connect Retry Timer in Seconds: %d\n",
10882 p->v_connect);
10883 if (p->status == Established && p->rtt)
10884 vty_out(vty, "Estimated round trip time: %d ms\n",
10885 p->rtt);
10886 if (p->t_start)
10887 vty_out(vty, "Next start timer due in %ld seconds\n",
10888 thread_timer_remain_second(p->t_start));
10889 if (p->t_connect)
10890 vty_out(vty, "Next connect timer due in %ld seconds\n",
10891 thread_timer_remain_second(p->t_connect));
10892 if (p->t_routeadv)
10893 vty_out(vty,
10894 "MRAI (interval %u) timer expires in %ld seconds\n",
10895 p->v_routeadv,
10896 thread_timer_remain_second(p->t_routeadv));
10897 if (p->password)
10898 vty_out(vty, "Peer Authentication Enabled\n");
10899
10900 vty_out(vty, "Read thread: %s Write thread: %s\n",
10901 p->t_read ? "on" : "off",
10902 CHECK_FLAG(p->thread_flags, PEER_THREAD_WRITES_ON)
10903 ? "on"
10904 : "off");
10905 }
10906
10907 if (p->notify.code == BGP_NOTIFY_OPEN_ERR
10908 && p->notify.subcode == BGP_NOTIFY_OPEN_UNSUP_CAPBL)
10909 bgp_capability_vty_out(vty, p, use_json, json_neigh);
10910
10911 if (!use_json)
10912 vty_out(vty, "\n");
10913
10914 /* BFD information. */
10915 bgp_bfd_show_info(vty, p, use_json, json_neigh);
10916
10917 if (use_json) {
10918 if (p->conf_if) /* Configured interface name. */
10919 json_object_object_add(json, p->conf_if, json_neigh);
10920 else /* Configured IP address. */
10921 json_object_object_add(json, p->host, json_neigh);
10922 }
10923 }
10924
10925 static int bgp_show_neighbor(struct vty *vty, struct bgp *bgp,
10926 enum show_type type, union sockunion *su,
10927 const char *conf_if, bool use_json,
10928 json_object *json)
10929 {
10930 struct listnode *node, *nnode;
10931 struct peer *peer;
10932 int find = 0;
10933 bool nbr_output = false;
10934 afi_t afi = AFI_MAX;
10935 safi_t safi = SAFI_MAX;
10936
10937 if (type == show_ipv4_peer || type == show_ipv4_all) {
10938 afi = AFI_IP;
10939 } else if (type == show_ipv6_peer || type == show_ipv6_all) {
10940 afi = AFI_IP6;
10941 }
10942
10943 for (ALL_LIST_ELEMENTS(bgp->peer, node, nnode, peer)) {
10944 if (!CHECK_FLAG(peer->flags, PEER_FLAG_CONFIG_NODE))
10945 continue;
10946
10947 switch (type) {
10948 case show_all:
10949 bgp_show_peer(vty, peer, use_json, json);
10950 nbr_output = true;
10951 break;
10952 case show_peer:
10953 if (conf_if) {
10954 if ((peer->conf_if
10955 && !strcmp(peer->conf_if, conf_if))
10956 || (peer->hostname
10957 && !strcmp(peer->hostname, conf_if))) {
10958 find = 1;
10959 bgp_show_peer(vty, peer, use_json,
10960 json);
10961 }
10962 } else {
10963 if (sockunion_same(&peer->su, su)) {
10964 find = 1;
10965 bgp_show_peer(vty, peer, use_json,
10966 json);
10967 }
10968 }
10969 break;
10970 case show_ipv4_peer:
10971 case show_ipv6_peer:
10972 FOREACH_SAFI (safi) {
10973 if (peer->afc[afi][safi]) {
10974 if (conf_if) {
10975 if ((peer->conf_if
10976 && !strcmp(peer->conf_if, conf_if))
10977 || (peer->hostname
10978 && !strcmp(peer->hostname, conf_if))) {
10979 find = 1;
10980 bgp_show_peer(vty, peer, use_json,
10981 json);
10982 break;
10983 }
10984 } else {
10985 if (sockunion_same(&peer->su, su)) {
10986 find = 1;
10987 bgp_show_peer(vty, peer, use_json,
10988 json);
10989 break;
10990 }
10991 }
10992 }
10993 }
10994 break;
10995 case show_ipv4_all:
10996 case show_ipv6_all:
10997 FOREACH_SAFI (safi) {
10998 if (peer->afc[afi][safi]) {
10999 bgp_show_peer(vty, peer, use_json, json);
11000 nbr_output = true;
11001 break;
11002 }
11003 }
11004 break;
11005 }
11006 }
11007
11008 if ((type == show_peer || type == show_ipv4_peer ||
11009 type == show_ipv6_peer) && !find) {
11010 if (use_json)
11011 json_object_boolean_true_add(json, "bgpNoSuchNeighbor");
11012 else
11013 vty_out(vty, "%% No such neighbor in this view/vrf\n");
11014 }
11015
11016 if (type != show_peer && type != show_ipv4_peer &&
11017 type != show_ipv6_peer && !nbr_output && !use_json)
11018 vty_out(vty, "%% No BGP neighbors found\n");
11019
11020 if (use_json) {
11021 vty_out(vty, "%s\n", json_object_to_json_string_ext(
11022 json, JSON_C_TO_STRING_PRETTY));
11023 } else {
11024 vty_out(vty, "\n");
11025 }
11026
11027 return CMD_SUCCESS;
11028 }
11029
11030 static void bgp_show_all_instances_neighbors_vty(struct vty *vty,
11031 enum show_type type,
11032 const char *ip_str,
11033 bool use_json)
11034 {
11035 struct listnode *node, *nnode;
11036 struct bgp *bgp;
11037 union sockunion su;
11038 json_object *json = NULL;
11039 int ret, is_first = 1;
11040 bool nbr_output = false;
11041
11042 if (use_json)
11043 vty_out(vty, "{\n");
11044
11045 for (ALL_LIST_ELEMENTS(bm->bgp, node, nnode, bgp)) {
11046 nbr_output = true;
11047 if (use_json) {
11048 if (!(json = json_object_new_object())) {
11049 flog_err(
11050 EC_BGP_JSON_MEM_ERROR,
11051 "Unable to allocate memory for JSON object");
11052 vty_out(vty,
11053 "{\"error\": {\"message:\": \"Unable to allocate memory for JSON object\"}}}\n");
11054 return;
11055 }
11056
11057 json_object_int_add(json, "vrfId",
11058 (bgp->vrf_id == VRF_UNKNOWN)
11059 ? -1
11060 : (int64_t)bgp->vrf_id);
11061 json_object_string_add(
11062 json, "vrfName",
11063 (bgp->inst_type == BGP_INSTANCE_TYPE_DEFAULT)
11064 ? VRF_DEFAULT_NAME
11065 : bgp->name);
11066
11067 if (!is_first)
11068 vty_out(vty, ",\n");
11069 else
11070 is_first = 0;
11071
11072 vty_out(vty, "\"%s\":",
11073 (bgp->inst_type == BGP_INSTANCE_TYPE_DEFAULT)
11074 ? VRF_DEFAULT_NAME
11075 : bgp->name);
11076 } else {
11077 vty_out(vty, "\nInstance %s:\n",
11078 (bgp->inst_type == BGP_INSTANCE_TYPE_DEFAULT)
11079 ? VRF_DEFAULT_NAME
11080 : bgp->name);
11081 }
11082
11083 if (type == show_peer || type == show_ipv4_peer ||
11084 type == show_ipv6_peer) {
11085 ret = str2sockunion(ip_str, &su);
11086 if (ret < 0)
11087 bgp_show_neighbor(vty, bgp, type, NULL, ip_str,
11088 use_json, json);
11089 else
11090 bgp_show_neighbor(vty, bgp, type, &su, NULL,
11091 use_json, json);
11092 } else {
11093 bgp_show_neighbor(vty, bgp, type, NULL, NULL,
11094 use_json, json);
11095 }
11096 json_object_free(json);
11097 }
11098
11099 if (use_json) {
11100 vty_out(vty, "}\n");
11101 json_object_free(json);
11102 }
11103 else if (!nbr_output)
11104 vty_out(vty, "%% BGP instance not found\n");
11105 }
11106
11107 static int bgp_show_neighbor_vty(struct vty *vty, const char *name,
11108 enum show_type type, const char *ip_str,
11109 bool use_json)
11110 {
11111 int ret;
11112 struct bgp *bgp;
11113 union sockunion su;
11114 json_object *json = NULL;
11115
11116 if (name) {
11117 if (strmatch(name, "all")) {
11118 bgp_show_all_instances_neighbors_vty(vty, type, ip_str,
11119 use_json);
11120 return CMD_SUCCESS;
11121 } else {
11122 bgp = bgp_lookup_by_name(name);
11123 if (!bgp) {
11124 if (use_json) {
11125 json = json_object_new_object();
11126 vty_out(vty, "%s\n",
11127 json_object_to_json_string_ext(
11128 json,
11129 JSON_C_TO_STRING_PRETTY));
11130 json_object_free(json);
11131 } else
11132 vty_out(vty,
11133 "%% BGP instance not found\n");
11134
11135 return CMD_WARNING;
11136 }
11137 }
11138 } else {
11139 bgp = bgp_get_default();
11140 }
11141
11142 if (bgp) {
11143 json = json_object_new_object();
11144 if (ip_str) {
11145 ret = str2sockunion(ip_str, &su);
11146 if (ret < 0)
11147 bgp_show_neighbor(vty, bgp, type, NULL, ip_str,
11148 use_json, json);
11149 else
11150 bgp_show_neighbor(vty, bgp, type, &su, NULL,
11151 use_json, json);
11152 } else {
11153 bgp_show_neighbor(vty, bgp, type, NULL, NULL, use_json,
11154 json);
11155 }
11156 json_object_free(json);
11157 } else {
11158 if (use_json)
11159 vty_out(vty, "{}\n");
11160 else
11161 vty_out(vty, "%% BGP instance not found\n");
11162 }
11163
11164 return CMD_SUCCESS;
11165 }
11166
11167 /* "show [ip] bgp neighbors" commands. */
11168 DEFUN (show_ip_bgp_neighbors,
11169 show_ip_bgp_neighbors_cmd,
11170 "show [ip] bgp [<view|vrf> VIEWVRFNAME] [<ipv4|ipv6>] neighbors [<A.B.C.D|X:X::X:X|WORD>] [json]",
11171 SHOW_STR
11172 IP_STR
11173 BGP_STR
11174 BGP_INSTANCE_HELP_STR
11175 "Address Family\n"
11176 "Address Family\n"
11177 "Detailed information on TCP and BGP neighbor connections\n"
11178 "Neighbor to display information about\n"
11179 "Neighbor to display information about\n"
11180 "Neighbor on BGP configured interface\n"
11181 JSON_STR)
11182 {
11183 char *vrf = NULL;
11184 char *sh_arg = NULL;
11185 enum show_type sh_type;
11186 afi_t afi = AFI_MAX;
11187
11188 bool uj = use_json(argc, argv);
11189
11190 int idx = 0;
11191
11192 /* [<vrf> VIEWVRFNAME] */
11193 if (argv_find(argv, argc, "vrf", &idx)) {
11194 vrf = argv[idx + 1]->arg;
11195 if (vrf && strmatch(vrf, VRF_DEFAULT_NAME))
11196 vrf = NULL;
11197 } else if (argv_find(argv, argc, "view", &idx))
11198 /* [<view> VIEWVRFNAME] */
11199 vrf = argv[idx + 1]->arg;
11200
11201 idx++;
11202
11203 if (argv_find(argv, argc, "ipv4", &idx)) {
11204 sh_type = show_ipv4_all;
11205 afi = AFI_IP;
11206 } else if (argv_find(argv, argc, "ipv6", &idx)) {
11207 sh_type = show_ipv6_all;
11208 afi = AFI_IP6;
11209 } else {
11210 sh_type = show_all;
11211 }
11212
11213 if (argv_find(argv, argc, "A.B.C.D", &idx)
11214 || argv_find(argv, argc, "X:X::X:X", &idx)
11215 || argv_find(argv, argc, "WORD", &idx)) {
11216 sh_type = show_peer;
11217 sh_arg = argv[idx]->arg;
11218 }
11219
11220 if (sh_type == show_peer && afi == AFI_IP) {
11221 sh_type = show_ipv4_peer;
11222 } else if (sh_type == show_peer && afi == AFI_IP6) {
11223 sh_type = show_ipv6_peer;
11224 }
11225
11226 return bgp_show_neighbor_vty(vty, vrf, sh_type, sh_arg, uj);
11227 }
11228
11229 /* Show BGP's AS paths internal data. There are both `show [ip] bgp
11230 paths' and `show ip mbgp paths'. Those functions results are the
11231 same.*/
11232 DEFUN (show_ip_bgp_paths,
11233 show_ip_bgp_paths_cmd,
11234 "show [ip] bgp ["BGP_SAFI_CMD_STR"] paths",
11235 SHOW_STR
11236 IP_STR
11237 BGP_STR
11238 BGP_SAFI_HELP_STR
11239 "Path information\n")
11240 {
11241 vty_out(vty, "Address Refcnt Path\n");
11242 aspath_print_all_vty(vty);
11243 return CMD_SUCCESS;
11244 }
11245
11246 #include "hash.h"
11247
11248 static void community_show_all_iterator(struct hash_bucket *bucket,
11249 struct vty *vty)
11250 {
11251 struct community *com;
11252
11253 com = (struct community *)bucket->data;
11254 vty_out(vty, "[%p] (%ld) %s\n", (void *)com, com->refcnt,
11255 community_str(com, false));
11256 }
11257
11258 /* Show BGP's community internal data. */
11259 DEFUN (show_ip_bgp_community_info,
11260 show_ip_bgp_community_info_cmd,
11261 "show [ip] bgp community-info",
11262 SHOW_STR
11263 IP_STR
11264 BGP_STR
11265 "List all bgp community information\n")
11266 {
11267 vty_out(vty, "Address Refcnt Community\n");
11268
11269 hash_iterate(community_hash(),
11270 (void (*)(struct hash_bucket *,
11271 void *))community_show_all_iterator,
11272 vty);
11273
11274 return CMD_SUCCESS;
11275 }
11276
11277 static void lcommunity_show_all_iterator(struct hash_bucket *bucket,
11278 struct vty *vty)
11279 {
11280 struct lcommunity *lcom;
11281
11282 lcom = (struct lcommunity *)bucket->data;
11283 vty_out(vty, "[%p] (%ld) %s\n", (void *)lcom, lcom->refcnt,
11284 lcommunity_str(lcom, false));
11285 }
11286
11287 /* Show BGP's community internal data. */
11288 DEFUN (show_ip_bgp_lcommunity_info,
11289 show_ip_bgp_lcommunity_info_cmd,
11290 "show ip bgp large-community-info",
11291 SHOW_STR
11292 IP_STR
11293 BGP_STR
11294 "List all bgp large-community information\n")
11295 {
11296 vty_out(vty, "Address Refcnt Large-community\n");
11297
11298 hash_iterate(lcommunity_hash(),
11299 (void (*)(struct hash_bucket *,
11300 void *))lcommunity_show_all_iterator,
11301 vty);
11302
11303 return CMD_SUCCESS;
11304 }
11305
11306
11307 DEFUN (show_ip_bgp_attr_info,
11308 show_ip_bgp_attr_info_cmd,
11309 "show [ip] bgp attribute-info",
11310 SHOW_STR
11311 IP_STR
11312 BGP_STR
11313 "List all bgp attribute information\n")
11314 {
11315 attr_show_all(vty);
11316 return CMD_SUCCESS;
11317 }
11318
11319 static int bgp_show_route_leak_vty(struct vty *vty, const char *name,
11320 afi_t afi, safi_t safi,
11321 bool use_json, json_object *json)
11322 {
11323 struct bgp *bgp;
11324 struct listnode *node;
11325 char *vname;
11326 char buf1[INET6_ADDRSTRLEN];
11327 char *ecom_str;
11328 vpn_policy_direction_t dir;
11329
11330 if (json) {
11331 json_object *json_import_vrfs = NULL;
11332 json_object *json_export_vrfs = NULL;
11333
11334 bgp = name ? bgp_lookup_by_name(name) : bgp_get_default();
11335
11336 if (!bgp) {
11337 vty_out(vty, "%s\n",
11338 json_object_to_json_string_ext(
11339 json,
11340 JSON_C_TO_STRING_PRETTY));
11341 json_object_free(json);
11342
11343 return CMD_WARNING;
11344 }
11345
11346 /* Provide context for the block */
11347 json_object_string_add(json, "vrf", name ? name : "default");
11348 json_object_string_add(json, "afiSafi",
11349 afi_safi_print(afi, safi));
11350
11351 if (!CHECK_FLAG(bgp->af_flags[afi][safi],
11352 BGP_CONFIG_VRF_TO_VRF_IMPORT)) {
11353 json_object_string_add(json, "importFromVrfs", "none");
11354 json_object_string_add(json, "importRts", "none");
11355 } else {
11356 json_import_vrfs = json_object_new_array();
11357
11358 for (ALL_LIST_ELEMENTS_RO(
11359 bgp->vpn_policy[afi].import_vrf,
11360 node, vname))
11361 json_object_array_add(json_import_vrfs,
11362 json_object_new_string(vname));
11363
11364 dir = BGP_VPN_POLICY_DIR_FROMVPN;
11365 ecom_str = ecommunity_ecom2str(
11366 bgp->vpn_policy[afi].rtlist[dir],
11367 ECOMMUNITY_FORMAT_ROUTE_MAP, 0);
11368 json_object_object_add(json, "importFromVrfs",
11369 json_import_vrfs);
11370 json_object_string_add(json, "importRts", ecom_str);
11371
11372 XFREE(MTYPE_ECOMMUNITY_STR, ecom_str);
11373 }
11374
11375 if (!CHECK_FLAG(bgp->af_flags[afi][safi],
11376 BGP_CONFIG_VRF_TO_VRF_EXPORT)) {
11377 json_object_string_add(json, "exportToVrfs", "none");
11378 json_object_string_add(json, "routeDistinguisher",
11379 "none");
11380 json_object_string_add(json, "exportRts", "none");
11381 } else {
11382 json_export_vrfs = json_object_new_array();
11383
11384 for (ALL_LIST_ELEMENTS_RO(
11385 bgp->vpn_policy[afi].export_vrf,
11386 node, vname))
11387 json_object_array_add(json_export_vrfs,
11388 json_object_new_string(vname));
11389 json_object_object_add(json, "exportToVrfs",
11390 json_export_vrfs);
11391 json_object_string_add(json, "routeDistinguisher",
11392 prefix_rd2str(&bgp->vpn_policy[afi].tovpn_rd,
11393 buf1, RD_ADDRSTRLEN));
11394
11395 dir = BGP_VPN_POLICY_DIR_TOVPN;
11396 ecom_str = ecommunity_ecom2str(
11397 bgp->vpn_policy[afi].rtlist[dir],
11398 ECOMMUNITY_FORMAT_ROUTE_MAP, 0);
11399 json_object_string_add(json, "exportRts", ecom_str);
11400
11401 XFREE(MTYPE_ECOMMUNITY_STR, ecom_str);
11402 }
11403
11404 if (use_json) {
11405 vty_out(vty, "%s\n",
11406 json_object_to_json_string_ext(json,
11407 JSON_C_TO_STRING_PRETTY));
11408 json_object_free(json);
11409 }
11410 } else {
11411 bgp = name ? bgp_lookup_by_name(name) : bgp_get_default();
11412
11413 if (!bgp) {
11414 vty_out(vty, "%% No such BGP instance exist\n");
11415 return CMD_WARNING;
11416 }
11417
11418 if (!CHECK_FLAG(bgp->af_flags[afi][safi],
11419 BGP_CONFIG_VRF_TO_VRF_IMPORT))
11420 vty_out(vty,
11421 "This VRF is not importing %s routes from any other VRF\n",
11422 afi_safi_print(afi, safi));
11423 else {
11424 vty_out(vty,
11425 "This VRF is importing %s routes from the following VRFs:\n",
11426 afi_safi_print(afi, safi));
11427
11428 for (ALL_LIST_ELEMENTS_RO(
11429 bgp->vpn_policy[afi].import_vrf,
11430 node, vname))
11431 vty_out(vty, " %s\n", vname);
11432
11433 dir = BGP_VPN_POLICY_DIR_FROMVPN;
11434 ecom_str = ecommunity_ecom2str(
11435 bgp->vpn_policy[afi].rtlist[dir],
11436 ECOMMUNITY_FORMAT_ROUTE_MAP, 0);
11437 vty_out(vty, "Import RT(s): %s\n", ecom_str);
11438
11439 XFREE(MTYPE_ECOMMUNITY_STR, ecom_str);
11440 }
11441
11442 if (!CHECK_FLAG(bgp->af_flags[afi][safi],
11443 BGP_CONFIG_VRF_TO_VRF_EXPORT))
11444 vty_out(vty,
11445 "This VRF is not exporting %s routes to any other VRF\n",
11446 afi_safi_print(afi, safi));
11447 else {
11448 vty_out(vty,
11449 "This VRF is exporting %s routes to the following VRFs:\n",
11450 afi_safi_print(afi, safi));
11451
11452 for (ALL_LIST_ELEMENTS_RO(
11453 bgp->vpn_policy[afi].export_vrf,
11454 node, vname))
11455 vty_out(vty, " %s\n", vname);
11456
11457 vty_out(vty, "RD: %s\n",
11458 prefix_rd2str(&bgp->vpn_policy[afi].tovpn_rd,
11459 buf1, RD_ADDRSTRLEN));
11460
11461 dir = BGP_VPN_POLICY_DIR_TOVPN;
11462 ecom_str = ecommunity_ecom2str(
11463 bgp->vpn_policy[afi].rtlist[dir],
11464 ECOMMUNITY_FORMAT_ROUTE_MAP, 0);
11465 vty_out(vty, "Export RT: %s\n", ecom_str);
11466 XFREE(MTYPE_ECOMMUNITY_STR, ecom_str);
11467 }
11468 }
11469
11470 return CMD_SUCCESS;
11471 }
11472
11473 static int bgp_show_all_instance_route_leak_vty(struct vty *vty, afi_t afi,
11474 safi_t safi, bool use_json)
11475 {
11476 struct listnode *node, *nnode;
11477 struct bgp *bgp;
11478 char *vrf_name = NULL;
11479 json_object *json = NULL;
11480 json_object *json_vrf = NULL;
11481 json_object *json_vrfs = NULL;
11482
11483 if (use_json) {
11484 json = json_object_new_object();
11485 json_vrfs = json_object_new_object();
11486 }
11487
11488 for (ALL_LIST_ELEMENTS(bm->bgp, node, nnode, bgp)) {
11489
11490 if (bgp->inst_type != BGP_INSTANCE_TYPE_DEFAULT)
11491 vrf_name = bgp->name;
11492
11493 if (use_json) {
11494 json_vrf = json_object_new_object();
11495 } else {
11496 vty_out(vty, "\nInstance %s:\n",
11497 (bgp->inst_type == BGP_INSTANCE_TYPE_DEFAULT)
11498 ? VRF_DEFAULT_NAME : bgp->name);
11499 }
11500 bgp_show_route_leak_vty(vty, vrf_name, afi, safi, 0, json_vrf);
11501 if (use_json) {
11502 if (bgp->inst_type == BGP_INSTANCE_TYPE_DEFAULT)
11503 json_object_object_add(json_vrfs,
11504 VRF_DEFAULT_NAME, json_vrf);
11505 else
11506 json_object_object_add(json_vrfs, vrf_name,
11507 json_vrf);
11508 }
11509 }
11510
11511 if (use_json) {
11512 json_object_object_add(json, "vrfs", json_vrfs);
11513 vty_out(vty, "%s\n", json_object_to_json_string_ext(json,
11514 JSON_C_TO_STRING_PRETTY));
11515 json_object_free(json);
11516 }
11517
11518 return CMD_SUCCESS;
11519 }
11520
11521 /* "show [ip] bgp route-leak" command. */
11522 DEFUN (show_ip_bgp_route_leak,
11523 show_ip_bgp_route_leak_cmd,
11524 "show [ip] bgp [<view|vrf> VIEWVRFNAME] ["BGP_AFI_CMD_STR" ["BGP_SAFI_CMD_STR"]] route-leak [json]",
11525 SHOW_STR
11526 IP_STR
11527 BGP_STR
11528 BGP_INSTANCE_HELP_STR
11529 BGP_AFI_HELP_STR
11530 BGP_SAFI_HELP_STR
11531 "Route leaking information\n"
11532 JSON_STR)
11533 {
11534 char *vrf = NULL;
11535 afi_t afi = AFI_MAX;
11536 safi_t safi = SAFI_MAX;
11537
11538 bool uj = use_json(argc, argv);
11539 int idx = 0;
11540 json_object *json = NULL;
11541
11542 /* show [ip] bgp */
11543 if (argv_find(argv, argc, "ip", &idx)) {
11544 afi = AFI_IP;
11545 safi = SAFI_UNICAST;
11546 }
11547 /* [vrf VIEWVRFNAME] */
11548 if (argv_find(argv, argc, "view", &idx)) {
11549 vty_out(vty,
11550 "%% This command is not applicable to BGP views\n");
11551 return CMD_WARNING;
11552 }
11553
11554 if (argv_find(argv, argc, "vrf", &idx)) {
11555 vrf = argv[idx + 1]->arg;
11556 if (vrf && strmatch(vrf, VRF_DEFAULT_NAME))
11557 vrf = NULL;
11558 }
11559 /* ["BGP_AFI_CMD_STR" ["BGP_SAFI_CMD_STR"]] */
11560 if (argv_find_and_parse_afi(argv, argc, &idx, &afi)) {
11561 argv_find_and_parse_safi(argv, argc, &idx, &safi);
11562 }
11563
11564 if (!((afi == AFI_IP || afi == AFI_IP6) && safi == SAFI_UNICAST)) {
11565 vty_out(vty,
11566 "%% This command is applicable only for unicast ipv4|ipv6\n");
11567 return CMD_WARNING;
11568 }
11569
11570 if (vrf && strmatch(vrf, "all"))
11571 return bgp_show_all_instance_route_leak_vty(vty, afi, safi, uj);
11572
11573 if (uj)
11574 json = json_object_new_object();
11575
11576 return bgp_show_route_leak_vty(vty, vrf, afi, safi, uj, json);
11577 }
11578
11579 static void bgp_show_all_instances_updgrps_vty(struct vty *vty, afi_t afi,
11580 safi_t safi)
11581 {
11582 struct listnode *node, *nnode;
11583 struct bgp *bgp;
11584
11585 for (ALL_LIST_ELEMENTS(bm->bgp, node, nnode, bgp)) {
11586 vty_out(vty, "\nInstance %s:\n",
11587 (bgp->inst_type == BGP_INSTANCE_TYPE_DEFAULT)
11588 ? VRF_DEFAULT_NAME
11589 : bgp->name);
11590 update_group_show(bgp, afi, safi, vty, 0);
11591 }
11592 }
11593
11594 static int bgp_show_update_groups(struct vty *vty, const char *name, int afi,
11595 int safi, uint64_t subgrp_id)
11596 {
11597 struct bgp *bgp;
11598
11599 if (name) {
11600 if (strmatch(name, "all")) {
11601 bgp_show_all_instances_updgrps_vty(vty, afi, safi);
11602 return CMD_SUCCESS;
11603 } else {
11604 bgp = bgp_lookup_by_name(name);
11605 }
11606 } else {
11607 bgp = bgp_get_default();
11608 }
11609
11610 if (bgp)
11611 update_group_show(bgp, afi, safi, vty, subgrp_id);
11612 return CMD_SUCCESS;
11613 }
11614
11615 DEFUN (show_ip_bgp_updgrps,
11616 show_ip_bgp_updgrps_cmd,
11617 "show [ip] bgp [<view|vrf> VIEWVRFNAME] ["BGP_AFI_CMD_STR" ["BGP_SAFI_WITH_LABEL_CMD_STR"]] update-groups [SUBGROUP-ID]",
11618 SHOW_STR
11619 IP_STR
11620 BGP_STR
11621 BGP_INSTANCE_HELP_STR
11622 BGP_AFI_HELP_STR
11623 BGP_SAFI_WITH_LABEL_HELP_STR
11624 "Detailed info about dynamic update groups\n"
11625 "Specific subgroup to display detailed info for\n")
11626 {
11627 char *vrf = NULL;
11628 afi_t afi = AFI_IP6;
11629 safi_t safi = SAFI_UNICAST;
11630 uint64_t subgrp_id = 0;
11631
11632 int idx = 0;
11633
11634 /* show [ip] bgp */
11635 if (argv_find(argv, argc, "ip", &idx))
11636 afi = AFI_IP;
11637 /* [<vrf> VIEWVRFNAME] */
11638 if (argv_find(argv, argc, "vrf", &idx)) {
11639 vrf = argv[idx + 1]->arg;
11640 if (vrf && strmatch(vrf, VRF_DEFAULT_NAME))
11641 vrf = NULL;
11642 } else if (argv_find(argv, argc, "view", &idx))
11643 /* [<view> VIEWVRFNAME] */
11644 vrf = argv[idx + 1]->arg;
11645 /* ["BGP_AFI_CMD_STR" ["BGP_SAFI_CMD_STR"]] */
11646 if (argv_find_and_parse_afi(argv, argc, &idx, &afi)) {
11647 argv_find_and_parse_safi(argv, argc, &idx, &safi);
11648 }
11649
11650 /* get subgroup id, if provided */
11651 idx = argc - 1;
11652 if (argv[idx]->type == VARIABLE_TKN)
11653 subgrp_id = strtoull(argv[idx]->arg, NULL, 10);
11654
11655 return (bgp_show_update_groups(vty, vrf, afi, safi, subgrp_id));
11656 }
11657
11658 DEFUN (show_bgp_instance_all_ipv6_updgrps,
11659 show_bgp_instance_all_ipv6_updgrps_cmd,
11660 "show [ip] bgp <view|vrf> all update-groups",
11661 SHOW_STR
11662 IP_STR
11663 BGP_STR
11664 BGP_INSTANCE_ALL_HELP_STR
11665 "Detailed info about dynamic update groups\n")
11666 {
11667 bgp_show_all_instances_updgrps_vty(vty, AFI_IP6, SAFI_UNICAST);
11668 return CMD_SUCCESS;
11669 }
11670
11671 DEFUN (show_bgp_l2vpn_evpn_updgrps,
11672 show_bgp_l2vpn_evpn_updgrps_cmd,
11673 "show [ip] bgp l2vpn evpn update-groups",
11674 SHOW_STR
11675 IP_STR
11676 BGP_STR
11677 "l2vpn address family\n"
11678 "evpn sub-address family\n"
11679 "Detailed info about dynamic update groups\n")
11680 {
11681 char *vrf = NULL;
11682 uint64_t subgrp_id = 0;
11683
11684 bgp_show_update_groups(vty, vrf, AFI_L2VPN, SAFI_EVPN, subgrp_id);
11685 return CMD_SUCCESS;
11686 }
11687
11688 DEFUN (show_bgp_updgrps_stats,
11689 show_bgp_updgrps_stats_cmd,
11690 "show [ip] bgp update-groups statistics",
11691 SHOW_STR
11692 IP_STR
11693 BGP_STR
11694 "Detailed info about dynamic update groups\n"
11695 "Statistics\n")
11696 {
11697 struct bgp *bgp;
11698
11699 bgp = bgp_get_default();
11700 if (bgp)
11701 update_group_show_stats(bgp, vty);
11702
11703 return CMD_SUCCESS;
11704 }
11705
11706 DEFUN (show_bgp_instance_updgrps_stats,
11707 show_bgp_instance_updgrps_stats_cmd,
11708 "show [ip] bgp <view|vrf> VIEWVRFNAME update-groups statistics",
11709 SHOW_STR
11710 IP_STR
11711 BGP_STR
11712 BGP_INSTANCE_HELP_STR
11713 "Detailed info about dynamic update groups\n"
11714 "Statistics\n")
11715 {
11716 int idx_word = 3;
11717 struct bgp *bgp;
11718
11719 bgp = bgp_lookup_by_name(argv[idx_word]->arg);
11720 if (bgp)
11721 update_group_show_stats(bgp, vty);
11722
11723 return CMD_SUCCESS;
11724 }
11725
11726 static void show_bgp_updgrps_adj_info_aux(struct vty *vty, const char *name,
11727 afi_t afi, safi_t safi,
11728 const char *what, uint64_t subgrp_id)
11729 {
11730 struct bgp *bgp;
11731
11732 if (name)
11733 bgp = bgp_lookup_by_name(name);
11734 else
11735 bgp = bgp_get_default();
11736
11737 if (bgp) {
11738 if (!strcmp(what, "advertise-queue"))
11739 update_group_show_adj_queue(bgp, afi, safi, vty,
11740 subgrp_id);
11741 else if (!strcmp(what, "advertised-routes"))
11742 update_group_show_advertised(bgp, afi, safi, vty,
11743 subgrp_id);
11744 else if (!strcmp(what, "packet-queue"))
11745 update_group_show_packet_queue(bgp, afi, safi, vty,
11746 subgrp_id);
11747 }
11748 }
11749
11750 DEFPY(show_ip_bgp_instance_updgrps_adj_s,
11751 show_ip_bgp_instance_updgrps_adj_s_cmd,
11752 "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",
11753 SHOW_STR IP_STR BGP_STR BGP_INSTANCE_HELP_STR BGP_AFI_HELP_STR
11754 BGP_SAFI_HELP_STR
11755 "Detailed info about dynamic update groups\n"
11756 "Specific subgroup to display info for\n"
11757 "Advertisement queue\n"
11758 "Announced routes\n"
11759 "Packet queue\n")
11760 {
11761 uint64_t subgrp_id = 0;
11762 afi_t afiz;
11763 safi_t safiz;
11764 if (sgid)
11765 subgrp_id = strtoull(sgid, NULL, 10);
11766
11767 if (!ip && !afi)
11768 afiz = AFI_IP6;
11769 if (!ip && afi)
11770 afiz = bgp_vty_afi_from_str(afi);
11771 if (ip && !afi)
11772 afiz = AFI_IP;
11773 if (ip && afi) {
11774 afiz = bgp_vty_afi_from_str(afi);
11775 if (afiz != AFI_IP)
11776 vty_out(vty,
11777 "%% Cannot specify both 'ip' and 'ipv6'\n");
11778 return CMD_WARNING;
11779 }
11780
11781 safiz = safi ? bgp_vty_safi_from_str(safi) : SAFI_UNICAST;
11782
11783 show_bgp_updgrps_adj_info_aux(vty, vrf, afiz, safiz, rtq, subgrp_id);
11784 return CMD_SUCCESS;
11785 }
11786
11787 static int bgp_show_one_peer_group(struct vty *vty, struct peer_group *group)
11788 {
11789 struct listnode *node, *nnode;
11790 struct prefix *range;
11791 struct peer *conf;
11792 struct peer *peer;
11793 char buf[PREFIX2STR_BUFFER];
11794 afi_t afi;
11795 safi_t safi;
11796 const char *peer_status;
11797 const char *af_str;
11798 int lr_count;
11799 int dynamic;
11800 int af_cfgd;
11801
11802 conf = group->conf;
11803
11804 if (conf->as_type == AS_SPECIFIED || conf->as_type == AS_EXTERNAL) {
11805 vty_out(vty, "\nBGP peer-group %s, remote AS %" PRIu32 "\n",
11806 group->name, conf->as);
11807 } else if (conf->as_type == AS_INTERNAL) {
11808 vty_out(vty, "\nBGP peer-group %s, remote AS %" PRIu32 "\n",
11809 group->name, group->bgp->as);
11810 } else {
11811 vty_out(vty, "\nBGP peer-group %s\n", group->name);
11812 }
11813
11814 if ((group->bgp->as == conf->as) || (conf->as_type == AS_INTERNAL))
11815 vty_out(vty, " Peer-group type is internal\n");
11816 else
11817 vty_out(vty, " Peer-group type is external\n");
11818
11819 /* Display AFs configured. */
11820 vty_out(vty, " Configured address-families:");
11821 FOREACH_AFI_SAFI (afi, safi) {
11822 if (conf->afc[afi][safi]) {
11823 af_cfgd = 1;
11824 vty_out(vty, " %s;", afi_safi_print(afi, safi));
11825 }
11826 }
11827 if (!af_cfgd)
11828 vty_out(vty, " none\n");
11829 else
11830 vty_out(vty, "\n");
11831
11832 /* Display listen ranges (for dynamic neighbors), if any */
11833 for (afi = AFI_IP; afi < AFI_MAX; afi++) {
11834 if (afi == AFI_IP)
11835 af_str = "IPv4";
11836 else if (afi == AFI_IP6)
11837 af_str = "IPv6";
11838 else
11839 af_str = "???";
11840 lr_count = listcount(group->listen_range[afi]);
11841 if (lr_count) {
11842 vty_out(vty, " %d %s listen range(s)\n", lr_count,
11843 af_str);
11844
11845
11846 for (ALL_LIST_ELEMENTS(group->listen_range[afi], node,
11847 nnode, range)) {
11848 prefix2str(range, buf, sizeof(buf));
11849 vty_out(vty, " %s\n", buf);
11850 }
11851 }
11852 }
11853
11854 /* Display group members and their status */
11855 if (listcount(group->peer)) {
11856 vty_out(vty, " Peer-group members:\n");
11857 for (ALL_LIST_ELEMENTS(group->peer, node, nnode, peer)) {
11858 if (CHECK_FLAG(peer->flags, PEER_FLAG_SHUTDOWN))
11859 peer_status = "Idle (Admin)";
11860 else if (CHECK_FLAG(peer->sflags,
11861 PEER_STATUS_PREFIX_OVERFLOW))
11862 peer_status = "Idle (PfxCt)";
11863 else
11864 peer_status = lookup_msg(bgp_status_msg,
11865 peer->status, NULL);
11866
11867 dynamic = peer_dynamic_neighbor(peer);
11868 vty_out(vty, " %s %s %s \n", peer->host,
11869 dynamic ? "(dynamic)" : "", peer_status);
11870 }
11871 }
11872
11873 return CMD_SUCCESS;
11874 }
11875
11876 static int bgp_show_peer_group_vty(struct vty *vty, const char *name,
11877 const char *group_name)
11878 {
11879 struct bgp *bgp;
11880 struct listnode *node, *nnode;
11881 struct peer_group *group;
11882 bool found = false;
11883
11884 bgp = name ? bgp_lookup_by_name(name) : bgp_get_default();
11885
11886 if (!bgp) {
11887 vty_out(vty, "%% BGP instance not found\n");
11888 return CMD_WARNING;
11889 }
11890
11891 for (ALL_LIST_ELEMENTS(bgp->group, node, nnode, group)) {
11892 if (group_name) {
11893 if (strmatch(group->name, group_name)) {
11894 bgp_show_one_peer_group(vty, group);
11895 found = true;
11896 break;
11897 }
11898 } else {
11899 bgp_show_one_peer_group(vty, group);
11900 }
11901 }
11902
11903 if (group_name && !found)
11904 vty_out(vty, "%% No such peer-group\n");
11905
11906 return CMD_SUCCESS;
11907 }
11908
11909 DEFUN (show_ip_bgp_peer_groups,
11910 show_ip_bgp_peer_groups_cmd,
11911 "show [ip] bgp [<view|vrf> VIEWVRFNAME] peer-group [PGNAME]",
11912 SHOW_STR
11913 IP_STR
11914 BGP_STR
11915 BGP_INSTANCE_HELP_STR
11916 "Detailed information on BGP peer groups\n"
11917 "Peer group name\n")
11918 {
11919 char *vrf, *pg;
11920 int idx = 0;
11921
11922 vrf = argv_find(argv, argc, "VIEWVRFNAME", &idx) ? argv[idx]->arg
11923 : NULL;
11924 pg = argv_find(argv, argc, "PGNAME", &idx) ? argv[idx]->arg : NULL;
11925
11926 return bgp_show_peer_group_vty(vty, vrf, pg);
11927 }
11928
11929
11930 /* Redistribute VTY commands. */
11931
11932 DEFUN (bgp_redistribute_ipv4,
11933 bgp_redistribute_ipv4_cmd,
11934 "redistribute " FRR_IP_REDIST_STR_BGPD,
11935 "Redistribute information from another routing protocol\n"
11936 FRR_IP_REDIST_HELP_STR_BGPD)
11937 {
11938 VTY_DECLVAR_CONTEXT(bgp, bgp);
11939 int idx_protocol = 1;
11940 int type;
11941
11942 type = proto_redistnum(AFI_IP, argv[idx_protocol]->text);
11943 if (type < 0) {
11944 vty_out(vty, "%% Invalid route type\n");
11945 return CMD_WARNING_CONFIG_FAILED;
11946 }
11947
11948 bgp_redist_add(bgp, AFI_IP, type, 0);
11949 return bgp_redistribute_set(bgp, AFI_IP, type, 0, false);
11950 }
11951
11952 ALIAS_HIDDEN(
11953 bgp_redistribute_ipv4, bgp_redistribute_ipv4_hidden_cmd,
11954 "redistribute " FRR_IP_REDIST_STR_BGPD,
11955 "Redistribute information from another routing protocol\n" FRR_IP_REDIST_HELP_STR_BGPD)
11956
11957 DEFUN (bgp_redistribute_ipv4_rmap,
11958 bgp_redistribute_ipv4_rmap_cmd,
11959 "redistribute " FRR_IP_REDIST_STR_BGPD " route-map WORD",
11960 "Redistribute information from another routing protocol\n"
11961 FRR_IP_REDIST_HELP_STR_BGPD
11962 "Route map reference\n"
11963 "Pointer to route-map entries\n")
11964 {
11965 VTY_DECLVAR_CONTEXT(bgp, bgp);
11966 int idx_protocol = 1;
11967 int idx_word = 3;
11968 int type;
11969 struct bgp_redist *red;
11970 bool changed;
11971 struct route_map *route_map = route_map_lookup_warn_noexist(
11972 vty, argv[idx_word]->arg);
11973
11974 type = proto_redistnum(AFI_IP, argv[idx_protocol]->text);
11975 if (type < 0) {
11976 vty_out(vty, "%% Invalid route type\n");
11977 return CMD_WARNING_CONFIG_FAILED;
11978 }
11979
11980 red = bgp_redist_add(bgp, AFI_IP, type, 0);
11981 changed =
11982 bgp_redistribute_rmap_set(red, argv[idx_word]->arg, route_map);
11983 return bgp_redistribute_set(bgp, AFI_IP, type, 0, changed);
11984 }
11985
11986 ALIAS_HIDDEN(
11987 bgp_redistribute_ipv4_rmap, bgp_redistribute_ipv4_rmap_hidden_cmd,
11988 "redistribute " FRR_IP_REDIST_STR_BGPD " route-map WORD",
11989 "Redistribute information from another routing protocol\n" FRR_IP_REDIST_HELP_STR_BGPD
11990 "Route map reference\n"
11991 "Pointer to route-map entries\n")
11992
11993 DEFUN (bgp_redistribute_ipv4_metric,
11994 bgp_redistribute_ipv4_metric_cmd,
11995 "redistribute " FRR_IP_REDIST_STR_BGPD " metric (0-4294967295)",
11996 "Redistribute information from another routing protocol\n"
11997 FRR_IP_REDIST_HELP_STR_BGPD
11998 "Metric for redistributed routes\n"
11999 "Default metric\n")
12000 {
12001 VTY_DECLVAR_CONTEXT(bgp, bgp);
12002 int idx_protocol = 1;
12003 int idx_number = 3;
12004 int type;
12005 uint32_t metric;
12006 struct bgp_redist *red;
12007 bool changed;
12008
12009 type = proto_redistnum(AFI_IP, argv[idx_protocol]->text);
12010 if (type < 0) {
12011 vty_out(vty, "%% Invalid route type\n");
12012 return CMD_WARNING_CONFIG_FAILED;
12013 }
12014 metric = strtoul(argv[idx_number]->arg, NULL, 10);
12015
12016 red = bgp_redist_add(bgp, AFI_IP, type, 0);
12017 changed = bgp_redistribute_metric_set(bgp, red, AFI_IP, type, metric);
12018 return bgp_redistribute_set(bgp, AFI_IP, type, 0, changed);
12019 }
12020
12021 ALIAS_HIDDEN(
12022 bgp_redistribute_ipv4_metric, bgp_redistribute_ipv4_metric_hidden_cmd,
12023 "redistribute " FRR_IP_REDIST_STR_BGPD " metric (0-4294967295)",
12024 "Redistribute information from another routing protocol\n" FRR_IP_REDIST_HELP_STR_BGPD
12025 "Metric for redistributed routes\n"
12026 "Default metric\n")
12027
12028 DEFUN (bgp_redistribute_ipv4_rmap_metric,
12029 bgp_redistribute_ipv4_rmap_metric_cmd,
12030 "redistribute " FRR_IP_REDIST_STR_BGPD " route-map WORD metric (0-4294967295)",
12031 "Redistribute information from another routing protocol\n"
12032 FRR_IP_REDIST_HELP_STR_BGPD
12033 "Route map reference\n"
12034 "Pointer to route-map entries\n"
12035 "Metric for redistributed routes\n"
12036 "Default metric\n")
12037 {
12038 VTY_DECLVAR_CONTEXT(bgp, bgp);
12039 int idx_protocol = 1;
12040 int idx_word = 3;
12041 int idx_number = 5;
12042 int type;
12043 uint32_t metric;
12044 struct bgp_redist *red;
12045 bool changed;
12046 struct route_map *route_map =
12047 route_map_lookup_warn_noexist(vty, argv[idx_word]->arg);
12048
12049 type = proto_redistnum(AFI_IP, argv[idx_protocol]->text);
12050 if (type < 0) {
12051 vty_out(vty, "%% Invalid route type\n");
12052 return CMD_WARNING_CONFIG_FAILED;
12053 }
12054 metric = strtoul(argv[idx_number]->arg, NULL, 10);
12055
12056 red = bgp_redist_add(bgp, AFI_IP, type, 0);
12057 changed =
12058 bgp_redistribute_rmap_set(red, argv[idx_word]->arg, route_map);
12059 changed |= bgp_redistribute_metric_set(bgp, red, AFI_IP, type, metric);
12060 return bgp_redistribute_set(bgp, AFI_IP, type, 0, changed);
12061 }
12062
12063 ALIAS_HIDDEN(
12064 bgp_redistribute_ipv4_rmap_metric,
12065 bgp_redistribute_ipv4_rmap_metric_hidden_cmd,
12066 "redistribute " FRR_IP_REDIST_STR_BGPD
12067 " route-map WORD metric (0-4294967295)",
12068 "Redistribute information from another routing protocol\n" FRR_IP_REDIST_HELP_STR_BGPD
12069 "Route map reference\n"
12070 "Pointer to route-map entries\n"
12071 "Metric for redistributed routes\n"
12072 "Default metric\n")
12073
12074 DEFUN (bgp_redistribute_ipv4_metric_rmap,
12075 bgp_redistribute_ipv4_metric_rmap_cmd,
12076 "redistribute " FRR_IP_REDIST_STR_BGPD " metric (0-4294967295) route-map WORD",
12077 "Redistribute information from another routing protocol\n"
12078 FRR_IP_REDIST_HELP_STR_BGPD
12079 "Metric for redistributed routes\n"
12080 "Default metric\n"
12081 "Route map reference\n"
12082 "Pointer to route-map entries\n")
12083 {
12084 VTY_DECLVAR_CONTEXT(bgp, bgp);
12085 int idx_protocol = 1;
12086 int idx_number = 3;
12087 int idx_word = 5;
12088 int type;
12089 uint32_t metric;
12090 struct bgp_redist *red;
12091 bool changed;
12092 struct route_map *route_map =
12093 route_map_lookup_warn_noexist(vty, argv[idx_word]->arg);
12094
12095 type = proto_redistnum(AFI_IP, argv[idx_protocol]->text);
12096 if (type < 0) {
12097 vty_out(vty, "%% Invalid route type\n");
12098 return CMD_WARNING_CONFIG_FAILED;
12099 }
12100 metric = strtoul(argv[idx_number]->arg, NULL, 10);
12101
12102 red = bgp_redist_add(bgp, AFI_IP, type, 0);
12103 changed = bgp_redistribute_metric_set(bgp, red, AFI_IP, type, metric);
12104 changed |=
12105 bgp_redistribute_rmap_set(red, argv[idx_word]->arg, route_map);
12106 return bgp_redistribute_set(bgp, AFI_IP, type, 0, changed);
12107 }
12108
12109 ALIAS_HIDDEN(
12110 bgp_redistribute_ipv4_metric_rmap,
12111 bgp_redistribute_ipv4_metric_rmap_hidden_cmd,
12112 "redistribute " FRR_IP_REDIST_STR_BGPD
12113 " metric (0-4294967295) route-map WORD",
12114 "Redistribute information from another routing protocol\n" FRR_IP_REDIST_HELP_STR_BGPD
12115 "Metric for redistributed routes\n"
12116 "Default metric\n"
12117 "Route map reference\n"
12118 "Pointer to route-map entries\n")
12119
12120 DEFUN (bgp_redistribute_ipv4_ospf,
12121 bgp_redistribute_ipv4_ospf_cmd,
12122 "redistribute <ospf|table> (1-65535)",
12123 "Redistribute information from another routing protocol\n"
12124 "Open Shortest Path First (OSPFv2)\n"
12125 "Non-main Kernel Routing Table\n"
12126 "Instance ID/Table ID\n")
12127 {
12128 VTY_DECLVAR_CONTEXT(bgp, bgp);
12129 int idx_ospf_table = 1;
12130 int idx_number = 2;
12131 unsigned short instance;
12132 unsigned short protocol;
12133
12134 instance = strtoul(argv[idx_number]->arg, NULL, 10);
12135
12136 if (strncmp(argv[idx_ospf_table]->arg, "o", 1) == 0)
12137 protocol = ZEBRA_ROUTE_OSPF;
12138 else
12139 protocol = ZEBRA_ROUTE_TABLE;
12140
12141 bgp_redist_add(bgp, AFI_IP, protocol, instance);
12142 return bgp_redistribute_set(bgp, AFI_IP, protocol, instance, false);
12143 }
12144
12145 ALIAS_HIDDEN(bgp_redistribute_ipv4_ospf, bgp_redistribute_ipv4_ospf_hidden_cmd,
12146 "redistribute <ospf|table> (1-65535)",
12147 "Redistribute information from another routing protocol\n"
12148 "Open Shortest Path First (OSPFv2)\n"
12149 "Non-main Kernel Routing Table\n"
12150 "Instance ID/Table ID\n")
12151
12152 DEFUN (bgp_redistribute_ipv4_ospf_rmap,
12153 bgp_redistribute_ipv4_ospf_rmap_cmd,
12154 "redistribute <ospf|table> (1-65535) route-map WORD",
12155 "Redistribute information from another routing protocol\n"
12156 "Open Shortest Path First (OSPFv2)\n"
12157 "Non-main Kernel Routing Table\n"
12158 "Instance ID/Table ID\n"
12159 "Route map reference\n"
12160 "Pointer to route-map entries\n")
12161 {
12162 VTY_DECLVAR_CONTEXT(bgp, bgp);
12163 int idx_ospf_table = 1;
12164 int idx_number = 2;
12165 int idx_word = 4;
12166 struct bgp_redist *red;
12167 unsigned short instance;
12168 int protocol;
12169 bool changed;
12170 struct route_map *route_map =
12171 route_map_lookup_warn_noexist(vty, argv[idx_word]->arg);
12172
12173 if (strncmp(argv[idx_ospf_table]->arg, "o", 1) == 0)
12174 protocol = ZEBRA_ROUTE_OSPF;
12175 else
12176 protocol = ZEBRA_ROUTE_TABLE;
12177
12178 instance = strtoul(argv[idx_number]->arg, NULL, 10);
12179 red = bgp_redist_add(bgp, AFI_IP, protocol, instance);
12180 changed =
12181 bgp_redistribute_rmap_set(red, argv[idx_word]->arg, route_map);
12182 return bgp_redistribute_set(bgp, AFI_IP, protocol, instance, changed);
12183 }
12184
12185 ALIAS_HIDDEN(bgp_redistribute_ipv4_ospf_rmap,
12186 bgp_redistribute_ipv4_ospf_rmap_hidden_cmd,
12187 "redistribute <ospf|table> (1-65535) route-map WORD",
12188 "Redistribute information from another routing protocol\n"
12189 "Open Shortest Path First (OSPFv2)\n"
12190 "Non-main Kernel Routing Table\n"
12191 "Instance ID/Table ID\n"
12192 "Route map reference\n"
12193 "Pointer to route-map entries\n")
12194
12195 DEFUN (bgp_redistribute_ipv4_ospf_metric,
12196 bgp_redistribute_ipv4_ospf_metric_cmd,
12197 "redistribute <ospf|table> (1-65535) metric (0-4294967295)",
12198 "Redistribute information from another routing protocol\n"
12199 "Open Shortest Path First (OSPFv2)\n"
12200 "Non-main Kernel Routing Table\n"
12201 "Instance ID/Table ID\n"
12202 "Metric for redistributed routes\n"
12203 "Default metric\n")
12204 {
12205 VTY_DECLVAR_CONTEXT(bgp, bgp);
12206 int idx_ospf_table = 1;
12207 int idx_number = 2;
12208 int idx_number_2 = 4;
12209 uint32_t metric;
12210 struct bgp_redist *red;
12211 unsigned short instance;
12212 int protocol;
12213 bool changed;
12214
12215 if (strncmp(argv[idx_ospf_table]->arg, "o", 1) == 0)
12216 protocol = ZEBRA_ROUTE_OSPF;
12217 else
12218 protocol = ZEBRA_ROUTE_TABLE;
12219
12220 instance = strtoul(argv[idx_number]->arg, NULL, 10);
12221 metric = strtoul(argv[idx_number_2]->arg, NULL, 10);
12222
12223 red = bgp_redist_add(bgp, AFI_IP, protocol, instance);
12224 changed = bgp_redistribute_metric_set(bgp, red, AFI_IP, protocol,
12225 metric);
12226 return bgp_redistribute_set(bgp, AFI_IP, protocol, instance, changed);
12227 }
12228
12229 ALIAS_HIDDEN(bgp_redistribute_ipv4_ospf_metric,
12230 bgp_redistribute_ipv4_ospf_metric_hidden_cmd,
12231 "redistribute <ospf|table> (1-65535) metric (0-4294967295)",
12232 "Redistribute information from another routing protocol\n"
12233 "Open Shortest Path First (OSPFv2)\n"
12234 "Non-main Kernel Routing Table\n"
12235 "Instance ID/Table ID\n"
12236 "Metric for redistributed routes\n"
12237 "Default metric\n")
12238
12239 DEFUN (bgp_redistribute_ipv4_ospf_rmap_metric,
12240 bgp_redistribute_ipv4_ospf_rmap_metric_cmd,
12241 "redistribute <ospf|table> (1-65535) route-map WORD metric (0-4294967295)",
12242 "Redistribute information from another routing protocol\n"
12243 "Open Shortest Path First (OSPFv2)\n"
12244 "Non-main Kernel Routing Table\n"
12245 "Instance ID/Table ID\n"
12246 "Route map reference\n"
12247 "Pointer to route-map entries\n"
12248 "Metric for redistributed routes\n"
12249 "Default metric\n")
12250 {
12251 VTY_DECLVAR_CONTEXT(bgp, bgp);
12252 int idx_ospf_table = 1;
12253 int idx_number = 2;
12254 int idx_word = 4;
12255 int idx_number_2 = 6;
12256 uint32_t metric;
12257 struct bgp_redist *red;
12258 unsigned short instance;
12259 int protocol;
12260 bool changed;
12261 struct route_map *route_map =
12262 route_map_lookup_warn_noexist(vty, argv[idx_word]->arg);
12263
12264 if (strncmp(argv[idx_ospf_table]->arg, "o", 1) == 0)
12265 protocol = ZEBRA_ROUTE_OSPF;
12266 else
12267 protocol = ZEBRA_ROUTE_TABLE;
12268
12269 instance = strtoul(argv[idx_number]->arg, NULL, 10);
12270 metric = strtoul(argv[idx_number_2]->arg, NULL, 10);
12271
12272 red = bgp_redist_add(bgp, AFI_IP, protocol, instance);
12273 changed =
12274 bgp_redistribute_rmap_set(red, argv[idx_word]->arg, route_map);
12275 changed |= bgp_redistribute_metric_set(bgp, red, AFI_IP, protocol,
12276 metric);
12277 return bgp_redistribute_set(bgp, AFI_IP, protocol, instance, changed);
12278 }
12279
12280 ALIAS_HIDDEN(
12281 bgp_redistribute_ipv4_ospf_rmap_metric,
12282 bgp_redistribute_ipv4_ospf_rmap_metric_hidden_cmd,
12283 "redistribute <ospf|table> (1-65535) route-map WORD metric (0-4294967295)",
12284 "Redistribute information from another routing protocol\n"
12285 "Open Shortest Path First (OSPFv2)\n"
12286 "Non-main Kernel Routing Table\n"
12287 "Instance ID/Table ID\n"
12288 "Route map reference\n"
12289 "Pointer to route-map entries\n"
12290 "Metric for redistributed routes\n"
12291 "Default metric\n")
12292
12293 DEFUN (bgp_redistribute_ipv4_ospf_metric_rmap,
12294 bgp_redistribute_ipv4_ospf_metric_rmap_cmd,
12295 "redistribute <ospf|table> (1-65535) metric (0-4294967295) route-map WORD",
12296 "Redistribute information from another routing protocol\n"
12297 "Open Shortest Path First (OSPFv2)\n"
12298 "Non-main Kernel Routing Table\n"
12299 "Instance ID/Table ID\n"
12300 "Metric for redistributed routes\n"
12301 "Default metric\n"
12302 "Route map reference\n"
12303 "Pointer to route-map entries\n")
12304 {
12305 VTY_DECLVAR_CONTEXT(bgp, bgp);
12306 int idx_ospf_table = 1;
12307 int idx_number = 2;
12308 int idx_number_2 = 4;
12309 int idx_word = 6;
12310 uint32_t metric;
12311 struct bgp_redist *red;
12312 unsigned short instance;
12313 int protocol;
12314 bool changed;
12315 struct route_map *route_map =
12316 route_map_lookup_warn_noexist(vty, argv[idx_word]->arg);
12317
12318 if (strncmp(argv[idx_ospf_table]->arg, "o", 1) == 0)
12319 protocol = ZEBRA_ROUTE_OSPF;
12320 else
12321 protocol = ZEBRA_ROUTE_TABLE;
12322
12323 instance = strtoul(argv[idx_number]->arg, NULL, 10);
12324 metric = strtoul(argv[idx_number_2]->arg, NULL, 10);
12325
12326 red = bgp_redist_add(bgp, AFI_IP, protocol, instance);
12327 changed = bgp_redistribute_metric_set(bgp, red, AFI_IP, protocol,
12328 metric);
12329 changed |=
12330 bgp_redistribute_rmap_set(red, argv[idx_word]->arg, route_map);
12331 return bgp_redistribute_set(bgp, AFI_IP, protocol, instance, changed);
12332 }
12333
12334 ALIAS_HIDDEN(
12335 bgp_redistribute_ipv4_ospf_metric_rmap,
12336 bgp_redistribute_ipv4_ospf_metric_rmap_hidden_cmd,
12337 "redistribute <ospf|table> (1-65535) metric (0-4294967295) route-map WORD",
12338 "Redistribute information from another routing protocol\n"
12339 "Open Shortest Path First (OSPFv2)\n"
12340 "Non-main Kernel Routing Table\n"
12341 "Instance ID/Table ID\n"
12342 "Metric for redistributed routes\n"
12343 "Default metric\n"
12344 "Route map reference\n"
12345 "Pointer to route-map entries\n")
12346
12347 DEFUN (no_bgp_redistribute_ipv4_ospf,
12348 no_bgp_redistribute_ipv4_ospf_cmd,
12349 "no redistribute <ospf|table> (1-65535) [metric (0-4294967295)] [route-map WORD]",
12350 NO_STR
12351 "Redistribute information from another routing protocol\n"
12352 "Open Shortest Path First (OSPFv2)\n"
12353 "Non-main Kernel Routing Table\n"
12354 "Instance ID/Table ID\n"
12355 "Metric for redistributed routes\n"
12356 "Default metric\n"
12357 "Route map reference\n"
12358 "Pointer to route-map entries\n")
12359 {
12360 VTY_DECLVAR_CONTEXT(bgp, bgp);
12361 int idx_ospf_table = 2;
12362 int idx_number = 3;
12363 unsigned short instance;
12364 int protocol;
12365
12366 if (strncmp(argv[idx_ospf_table]->arg, "o", 1) == 0)
12367 protocol = ZEBRA_ROUTE_OSPF;
12368 else
12369 protocol = ZEBRA_ROUTE_TABLE;
12370
12371 instance = strtoul(argv[idx_number]->arg, NULL, 10);
12372 return bgp_redistribute_unset(bgp, AFI_IP, protocol, instance);
12373 }
12374
12375 ALIAS_HIDDEN(
12376 no_bgp_redistribute_ipv4_ospf, no_bgp_redistribute_ipv4_ospf_hidden_cmd,
12377 "no redistribute <ospf|table> (1-65535) [metric (0-4294967295)] [route-map WORD]",
12378 NO_STR
12379 "Redistribute information from another routing protocol\n"
12380 "Open Shortest Path First (OSPFv2)\n"
12381 "Non-main Kernel Routing Table\n"
12382 "Instance ID/Table ID\n"
12383 "Metric for redistributed routes\n"
12384 "Default metric\n"
12385 "Route map reference\n"
12386 "Pointer to route-map entries\n")
12387
12388 DEFUN (no_bgp_redistribute_ipv4,
12389 no_bgp_redistribute_ipv4_cmd,
12390 "no redistribute " FRR_IP_REDIST_STR_BGPD " [metric (0-4294967295)] [route-map WORD]",
12391 NO_STR
12392 "Redistribute information from another routing protocol\n"
12393 FRR_IP_REDIST_HELP_STR_BGPD
12394 "Metric for redistributed routes\n"
12395 "Default metric\n"
12396 "Route map reference\n"
12397 "Pointer to route-map entries\n")
12398 {
12399 VTY_DECLVAR_CONTEXT(bgp, bgp);
12400 int idx_protocol = 2;
12401 int type;
12402
12403 type = proto_redistnum(AFI_IP, argv[idx_protocol]->text);
12404 if (type < 0) {
12405 vty_out(vty, "%% Invalid route type\n");
12406 return CMD_WARNING_CONFIG_FAILED;
12407 }
12408 return bgp_redistribute_unset(bgp, AFI_IP, type, 0);
12409 }
12410
12411 ALIAS_HIDDEN(
12412 no_bgp_redistribute_ipv4, no_bgp_redistribute_ipv4_hidden_cmd,
12413 "no redistribute " FRR_IP_REDIST_STR_BGPD
12414 " [metric (0-4294967295)] [route-map WORD]",
12415 NO_STR
12416 "Redistribute information from another routing protocol\n" FRR_IP_REDIST_HELP_STR_BGPD
12417 "Metric for redistributed routes\n"
12418 "Default metric\n"
12419 "Route map reference\n"
12420 "Pointer to route-map entries\n")
12421
12422 DEFUN (bgp_redistribute_ipv6,
12423 bgp_redistribute_ipv6_cmd,
12424 "redistribute " FRR_IP6_REDIST_STR_BGPD,
12425 "Redistribute information from another routing protocol\n"
12426 FRR_IP6_REDIST_HELP_STR_BGPD)
12427 {
12428 VTY_DECLVAR_CONTEXT(bgp, bgp);
12429 int idx_protocol = 1;
12430 int type;
12431
12432 type = proto_redistnum(AFI_IP6, argv[idx_protocol]->text);
12433 if (type < 0) {
12434 vty_out(vty, "%% Invalid route type\n");
12435 return CMD_WARNING_CONFIG_FAILED;
12436 }
12437
12438 bgp_redist_add(bgp, AFI_IP6, type, 0);
12439 return bgp_redistribute_set(bgp, AFI_IP6, type, 0, false);
12440 }
12441
12442 DEFUN (bgp_redistribute_ipv6_rmap,
12443 bgp_redistribute_ipv6_rmap_cmd,
12444 "redistribute " FRR_IP6_REDIST_STR_BGPD " route-map WORD",
12445 "Redistribute information from another routing protocol\n"
12446 FRR_IP6_REDIST_HELP_STR_BGPD
12447 "Route map reference\n"
12448 "Pointer to route-map entries\n")
12449 {
12450 VTY_DECLVAR_CONTEXT(bgp, bgp);
12451 int idx_protocol = 1;
12452 int idx_word = 3;
12453 int type;
12454 struct bgp_redist *red;
12455 bool changed;
12456 struct route_map *route_map =
12457 route_map_lookup_warn_noexist(vty, argv[idx_word]->arg);
12458
12459 type = proto_redistnum(AFI_IP6, argv[idx_protocol]->text);
12460 if (type < 0) {
12461 vty_out(vty, "%% Invalid route type\n");
12462 return CMD_WARNING_CONFIG_FAILED;
12463 }
12464
12465 red = bgp_redist_add(bgp, AFI_IP6, type, 0);
12466 changed =
12467 bgp_redistribute_rmap_set(red, argv[idx_word]->arg, route_map);
12468 return bgp_redistribute_set(bgp, AFI_IP6, type, 0, changed);
12469 }
12470
12471 DEFUN (bgp_redistribute_ipv6_metric,
12472 bgp_redistribute_ipv6_metric_cmd,
12473 "redistribute " FRR_IP6_REDIST_STR_BGPD " metric (0-4294967295)",
12474 "Redistribute information from another routing protocol\n"
12475 FRR_IP6_REDIST_HELP_STR_BGPD
12476 "Metric for redistributed routes\n"
12477 "Default metric\n")
12478 {
12479 VTY_DECLVAR_CONTEXT(bgp, bgp);
12480 int idx_protocol = 1;
12481 int idx_number = 3;
12482 int type;
12483 uint32_t metric;
12484 struct bgp_redist *red;
12485 bool changed;
12486
12487 type = proto_redistnum(AFI_IP6, argv[idx_protocol]->text);
12488 if (type < 0) {
12489 vty_out(vty, "%% Invalid route type\n");
12490 return CMD_WARNING_CONFIG_FAILED;
12491 }
12492 metric = strtoul(argv[idx_number]->arg, NULL, 10);
12493
12494 red = bgp_redist_add(bgp, AFI_IP6, type, 0);
12495 changed = bgp_redistribute_metric_set(bgp, red, AFI_IP6, type, metric);
12496 return bgp_redistribute_set(bgp, AFI_IP6, type, 0, changed);
12497 }
12498
12499 DEFUN (bgp_redistribute_ipv6_rmap_metric,
12500 bgp_redistribute_ipv6_rmap_metric_cmd,
12501 "redistribute " FRR_IP6_REDIST_STR_BGPD " route-map WORD metric (0-4294967295)",
12502 "Redistribute information from another routing protocol\n"
12503 FRR_IP6_REDIST_HELP_STR_BGPD
12504 "Route map reference\n"
12505 "Pointer to route-map entries\n"
12506 "Metric for redistributed routes\n"
12507 "Default metric\n")
12508 {
12509 VTY_DECLVAR_CONTEXT(bgp, bgp);
12510 int idx_protocol = 1;
12511 int idx_word = 3;
12512 int idx_number = 5;
12513 int type;
12514 uint32_t metric;
12515 struct bgp_redist *red;
12516 bool changed;
12517 struct route_map *route_map =
12518 route_map_lookup_warn_noexist(vty, argv[idx_word]->arg);
12519
12520 type = proto_redistnum(AFI_IP6, argv[idx_protocol]->text);
12521 if (type < 0) {
12522 vty_out(vty, "%% Invalid route type\n");
12523 return CMD_WARNING_CONFIG_FAILED;
12524 }
12525 metric = strtoul(argv[idx_number]->arg, NULL, 10);
12526
12527 red = bgp_redist_add(bgp, AFI_IP6, type, 0);
12528 changed =
12529 bgp_redistribute_rmap_set(red, argv[idx_word]->arg, route_map);
12530 changed |= bgp_redistribute_metric_set(bgp, red, AFI_IP6, type,
12531 metric);
12532 return bgp_redistribute_set(bgp, AFI_IP6, type, 0, changed);
12533 }
12534
12535 DEFUN (bgp_redistribute_ipv6_metric_rmap,
12536 bgp_redistribute_ipv6_metric_rmap_cmd,
12537 "redistribute " FRR_IP6_REDIST_STR_BGPD " metric (0-4294967295) route-map WORD",
12538 "Redistribute information from another routing protocol\n"
12539 FRR_IP6_REDIST_HELP_STR_BGPD
12540 "Metric for redistributed routes\n"
12541 "Default metric\n"
12542 "Route map reference\n"
12543 "Pointer to route-map entries\n")
12544 {
12545 VTY_DECLVAR_CONTEXT(bgp, bgp);
12546 int idx_protocol = 1;
12547 int idx_number = 3;
12548 int idx_word = 5;
12549 int type;
12550 uint32_t metric;
12551 struct bgp_redist *red;
12552 bool changed;
12553 struct route_map *route_map =
12554 route_map_lookup_warn_noexist(vty, argv[idx_word]->arg);
12555
12556 type = proto_redistnum(AFI_IP6, argv[idx_protocol]->text);
12557 if (type < 0) {
12558 vty_out(vty, "%% Invalid route type\n");
12559 return CMD_WARNING_CONFIG_FAILED;
12560 }
12561 metric = strtoul(argv[idx_number]->arg, NULL, 10);
12562
12563 red = bgp_redist_add(bgp, AFI_IP6, type, 0);
12564 changed = bgp_redistribute_metric_set(bgp, red, AFI_IP6, SAFI_UNICAST,
12565 metric);
12566 changed |=
12567 bgp_redistribute_rmap_set(red, argv[idx_word]->arg, route_map);
12568 return bgp_redistribute_set(bgp, AFI_IP6, type, 0, changed);
12569 }
12570
12571 DEFUN (no_bgp_redistribute_ipv6,
12572 no_bgp_redistribute_ipv6_cmd,
12573 "no redistribute " FRR_IP6_REDIST_STR_BGPD " [metric (0-4294967295)] [route-map WORD]",
12574 NO_STR
12575 "Redistribute information from another routing protocol\n"
12576 FRR_IP6_REDIST_HELP_STR_BGPD
12577 "Metric for redistributed routes\n"
12578 "Default metric\n"
12579 "Route map reference\n"
12580 "Pointer to route-map entries\n")
12581 {
12582 VTY_DECLVAR_CONTEXT(bgp, bgp);
12583 int idx_protocol = 2;
12584 int type;
12585
12586 type = proto_redistnum(AFI_IP6, argv[idx_protocol]->text);
12587 if (type < 0) {
12588 vty_out(vty, "%% Invalid route type\n");
12589 return CMD_WARNING_CONFIG_FAILED;
12590 }
12591
12592 return bgp_redistribute_unset(bgp, AFI_IP6, type, 0);
12593 }
12594
12595 void bgp_config_write_redistribute(struct vty *vty, struct bgp *bgp, afi_t afi,
12596 safi_t safi)
12597 {
12598 int i;
12599
12600 /* Unicast redistribution only. */
12601 if (safi != SAFI_UNICAST)
12602 return;
12603
12604 for (i = 0; i < ZEBRA_ROUTE_MAX; i++) {
12605 /* Redistribute BGP does not make sense. */
12606 if (i != ZEBRA_ROUTE_BGP) {
12607 struct list *red_list;
12608 struct listnode *node;
12609 struct bgp_redist *red;
12610
12611 red_list = bgp->redist[afi][i];
12612 if (!red_list)
12613 continue;
12614
12615 for (ALL_LIST_ELEMENTS_RO(red_list, node, red)) {
12616 /* "redistribute" configuration. */
12617 vty_out(vty, " redistribute %s",
12618 zebra_route_string(i));
12619 if (red->instance)
12620 vty_out(vty, " %d", red->instance);
12621 if (red->redist_metric_flag)
12622 vty_out(vty, " metric %u",
12623 red->redist_metric);
12624 if (red->rmap.name)
12625 vty_out(vty, " route-map %s",
12626 red->rmap.name);
12627 vty_out(vty, "\n");
12628 }
12629 }
12630 }
12631 }
12632
12633 /* This is part of the address-family block (unicast only) */
12634 void bgp_vpn_policy_config_write_afi(struct vty *vty, struct bgp *bgp,
12635 afi_t afi)
12636 {
12637 int indent = 2;
12638
12639 if (bgp->vpn_policy[afi].rmap_name[BGP_VPN_POLICY_DIR_FROMVPN]) {
12640 if (listcount(bgp->vpn_policy[afi].import_vrf))
12641 vty_out(vty, "%*simport vrf route-map %s\n", indent, "",
12642 bgp->vpn_policy[afi]
12643 .rmap_name[BGP_VPN_POLICY_DIR_FROMVPN]);
12644 else
12645 vty_out(vty, "%*sroute-map vpn import %s\n", indent, "",
12646 bgp->vpn_policy[afi]
12647 .rmap_name[BGP_VPN_POLICY_DIR_FROMVPN]);
12648 }
12649 if (CHECK_FLAG(bgp->af_flags[afi][SAFI_UNICAST],
12650 BGP_CONFIG_VRF_TO_VRF_IMPORT)
12651 || CHECK_FLAG(bgp->af_flags[afi][SAFI_UNICAST],
12652 BGP_CONFIG_VRF_TO_VRF_EXPORT))
12653 return;
12654
12655 if (CHECK_FLAG(bgp->vpn_policy[afi].flags,
12656 BGP_VPN_POLICY_TOVPN_LABEL_AUTO)) {
12657
12658 vty_out(vty, "%*slabel vpn export %s\n", indent, "", "auto");
12659
12660 } else {
12661 if (bgp->vpn_policy[afi].tovpn_label != MPLS_LABEL_NONE) {
12662 vty_out(vty, "%*slabel vpn export %u\n", indent, "",
12663 bgp->vpn_policy[afi].tovpn_label);
12664 }
12665 }
12666 if (CHECK_FLAG(bgp->vpn_policy[afi].flags,
12667 BGP_VPN_POLICY_TOVPN_RD_SET)) {
12668 char buf[RD_ADDRSTRLEN];
12669 vty_out(vty, "%*srd vpn export %s\n", indent, "",
12670 prefix_rd2str(&bgp->vpn_policy[afi].tovpn_rd, buf,
12671 sizeof(buf)));
12672 }
12673 if (CHECK_FLAG(bgp->vpn_policy[afi].flags,
12674 BGP_VPN_POLICY_TOVPN_NEXTHOP_SET)) {
12675
12676 char buf[PREFIX_STRLEN];
12677 if (inet_ntop(bgp->vpn_policy[afi].tovpn_nexthop.family,
12678 &bgp->vpn_policy[afi].tovpn_nexthop.u.prefix, buf,
12679 sizeof(buf))) {
12680
12681 vty_out(vty, "%*snexthop vpn export %s\n",
12682 indent, "", buf);
12683 }
12684 }
12685 if (bgp->vpn_policy[afi].rtlist[BGP_VPN_POLICY_DIR_FROMVPN]
12686 && bgp->vpn_policy[afi].rtlist[BGP_VPN_POLICY_DIR_TOVPN]
12687 && ecommunity_cmp(
12688 bgp->vpn_policy[afi].rtlist[BGP_VPN_POLICY_DIR_FROMVPN],
12689 bgp->vpn_policy[afi].rtlist[BGP_VPN_POLICY_DIR_TOVPN])) {
12690
12691 char *b = ecommunity_ecom2str(
12692 bgp->vpn_policy[afi].rtlist[BGP_VPN_POLICY_DIR_TOVPN],
12693 ECOMMUNITY_FORMAT_ROUTE_MAP, ECOMMUNITY_ROUTE_TARGET);
12694 vty_out(vty, "%*srt vpn both %s\n", indent, "", b);
12695 XFREE(MTYPE_ECOMMUNITY_STR, b);
12696 } else {
12697 if (bgp->vpn_policy[afi].rtlist[BGP_VPN_POLICY_DIR_FROMVPN]) {
12698 char *b = ecommunity_ecom2str(
12699 bgp->vpn_policy[afi]
12700 .rtlist[BGP_VPN_POLICY_DIR_FROMVPN],
12701 ECOMMUNITY_FORMAT_ROUTE_MAP,
12702 ECOMMUNITY_ROUTE_TARGET);
12703 vty_out(vty, "%*srt vpn import %s\n", indent, "", b);
12704 XFREE(MTYPE_ECOMMUNITY_STR, b);
12705 }
12706 if (bgp->vpn_policy[afi].rtlist[BGP_VPN_POLICY_DIR_TOVPN]) {
12707 char *b = ecommunity_ecom2str(
12708 bgp->vpn_policy[afi]
12709 .rtlist[BGP_VPN_POLICY_DIR_TOVPN],
12710 ECOMMUNITY_FORMAT_ROUTE_MAP,
12711 ECOMMUNITY_ROUTE_TARGET);
12712 vty_out(vty, "%*srt vpn export %s\n", indent, "", b);
12713 XFREE(MTYPE_ECOMMUNITY_STR, b);
12714 }
12715 }
12716
12717 if (bgp->vpn_policy[afi].rmap_name[BGP_VPN_POLICY_DIR_TOVPN])
12718 vty_out(vty, "%*sroute-map vpn export %s\n", indent, "",
12719 bgp->vpn_policy[afi]
12720 .rmap_name[BGP_VPN_POLICY_DIR_TOVPN]);
12721
12722 if (bgp->vpn_policy[afi].import_redirect_rtlist) {
12723 char *b = ecommunity_ecom2str(
12724 bgp->vpn_policy[afi]
12725 .import_redirect_rtlist,
12726 ECOMMUNITY_FORMAT_ROUTE_MAP,
12727 ECOMMUNITY_ROUTE_TARGET);
12728
12729 vty_out(vty, "%*srt redirect import %s\n", indent, "", b);
12730 XFREE(MTYPE_ECOMMUNITY_STR, b);
12731 }
12732 }
12733
12734
12735 /* BGP node structure. */
12736 static struct cmd_node bgp_node = {
12737 BGP_NODE, "%s(config-router)# ", 1,
12738 };
12739
12740 static struct cmd_node bgp_ipv4_unicast_node = {
12741 BGP_IPV4_NODE, "%s(config-router-af)# ", 1,
12742 };
12743
12744 static struct cmd_node bgp_ipv4_multicast_node = {
12745 BGP_IPV4M_NODE, "%s(config-router-af)# ", 1,
12746 };
12747
12748 static struct cmd_node bgp_ipv4_labeled_unicast_node = {
12749 BGP_IPV4L_NODE, "%s(config-router-af)# ", 1,
12750 };
12751
12752 static struct cmd_node bgp_ipv6_unicast_node = {
12753 BGP_IPV6_NODE, "%s(config-router-af)# ", 1,
12754 };
12755
12756 static struct cmd_node bgp_ipv6_multicast_node = {
12757 BGP_IPV6M_NODE, "%s(config-router-af)# ", 1,
12758 };
12759
12760 static struct cmd_node bgp_ipv6_labeled_unicast_node = {
12761 BGP_IPV6L_NODE, "%s(config-router-af)# ", 1,
12762 };
12763
12764 static struct cmd_node bgp_vpnv4_node = {BGP_VPNV4_NODE,
12765 "%s(config-router-af)# ", 1};
12766
12767 static struct cmd_node bgp_vpnv6_node = {BGP_VPNV6_NODE,
12768 "%s(config-router-af-vpnv6)# ", 1};
12769
12770 static struct cmd_node bgp_evpn_node = {BGP_EVPN_NODE,
12771 "%s(config-router-evpn)# ", 1};
12772
12773 static struct cmd_node bgp_evpn_vni_node = {BGP_EVPN_VNI_NODE,
12774 "%s(config-router-af-vni)# ", 1};
12775
12776 static struct cmd_node bgp_flowspecv4_node = {BGP_FLOWSPECV4_NODE,
12777 "%s(config-router-af)# ", 1};
12778
12779 static struct cmd_node bgp_flowspecv6_node = {BGP_FLOWSPECV6_NODE,
12780 "%s(config-router-af-vpnv6)# ", 1};
12781
12782 static void community_list_vty(void);
12783
12784 static void bgp_ac_neighbor(vector comps, struct cmd_token *token)
12785 {
12786 struct bgp *bgp;
12787 struct peer *peer;
12788 struct listnode *lnbgp, *lnpeer;
12789
12790 for (ALL_LIST_ELEMENTS_RO(bm->bgp, lnbgp, bgp)) {
12791 for (ALL_LIST_ELEMENTS_RO(bgp->peer, lnpeer, peer)) {
12792 /* only provide suggestions on the appropriate input
12793 * token type,
12794 * they'll otherwise show up multiple times */
12795 enum cmd_token_type match_type;
12796 char *name = peer->host;
12797
12798 if (peer->conf_if) {
12799 match_type = VARIABLE_TKN;
12800 name = peer->conf_if;
12801 } else if (strchr(peer->host, ':'))
12802 match_type = IPV6_TKN;
12803 else
12804 match_type = IPV4_TKN;
12805
12806 if (token->type != match_type)
12807 continue;
12808
12809 vector_set(comps, XSTRDUP(MTYPE_COMPLETION, name));
12810 }
12811 }
12812 }
12813
12814 static const struct cmd_variable_handler bgp_var_neighbor[] = {
12815 {.varname = "neighbor", .completions = bgp_ac_neighbor},
12816 {.varname = "neighbors", .completions = bgp_ac_neighbor},
12817 {.varname = "peer", .completions = bgp_ac_neighbor},
12818 {.completions = NULL}};
12819
12820 static void bgp_ac_peergroup(vector comps, struct cmd_token *token)
12821 {
12822 struct bgp *bgp;
12823 struct peer_group *group;
12824 struct listnode *lnbgp, *lnpeer;
12825
12826 for (ALL_LIST_ELEMENTS_RO(bm->bgp, lnbgp, bgp)) {
12827 for (ALL_LIST_ELEMENTS_RO(bgp->group, lnpeer, group))
12828 vector_set(comps, XSTRDUP(MTYPE_COMPLETION,
12829 group->name));
12830 }
12831 }
12832
12833 static const struct cmd_variable_handler bgp_var_peergroup[] = {
12834 {.tokenname = "PGNAME", .completions = bgp_ac_peergroup},
12835 {.completions = NULL} };
12836
12837 void bgp_vty_init(void)
12838 {
12839 cmd_variable_handler_register(bgp_var_neighbor);
12840 cmd_variable_handler_register(bgp_var_peergroup);
12841
12842 /* Install bgp top node. */
12843 install_node(&bgp_node, bgp_config_write);
12844 install_node(&bgp_ipv4_unicast_node, NULL);
12845 install_node(&bgp_ipv4_multicast_node, NULL);
12846 install_node(&bgp_ipv4_labeled_unicast_node, NULL);
12847 install_node(&bgp_ipv6_unicast_node, NULL);
12848 install_node(&bgp_ipv6_multicast_node, NULL);
12849 install_node(&bgp_ipv6_labeled_unicast_node, NULL);
12850 install_node(&bgp_vpnv4_node, NULL);
12851 install_node(&bgp_vpnv6_node, NULL);
12852 install_node(&bgp_evpn_node, NULL);
12853 install_node(&bgp_evpn_vni_node, NULL);
12854 install_node(&bgp_flowspecv4_node, NULL);
12855 install_node(&bgp_flowspecv6_node, NULL);
12856
12857 /* Install default VTY commands to new nodes. */
12858 install_default(BGP_NODE);
12859 install_default(BGP_IPV4_NODE);
12860 install_default(BGP_IPV4M_NODE);
12861 install_default(BGP_IPV4L_NODE);
12862 install_default(BGP_IPV6_NODE);
12863 install_default(BGP_IPV6M_NODE);
12864 install_default(BGP_IPV6L_NODE);
12865 install_default(BGP_VPNV4_NODE);
12866 install_default(BGP_VPNV6_NODE);
12867 install_default(BGP_FLOWSPECV4_NODE);
12868 install_default(BGP_FLOWSPECV6_NODE);
12869 install_default(BGP_EVPN_NODE);
12870 install_default(BGP_EVPN_VNI_NODE);
12871
12872 /* "bgp multiple-instance" commands. */
12873 install_element(CONFIG_NODE, &bgp_multiple_instance_cmd);
12874 install_element(CONFIG_NODE, &no_bgp_multiple_instance_cmd);
12875
12876 /* "bgp config-type" commands. */
12877 install_element(CONFIG_NODE, &bgp_config_type_cmd);
12878 install_element(CONFIG_NODE, &no_bgp_config_type_cmd);
12879
12880 /* "bgp local-mac" hidden commands. */
12881 install_element(CONFIG_NODE, &bgp_local_mac_cmd);
12882 install_element(CONFIG_NODE, &no_bgp_local_mac_cmd);
12883
12884 /* bgp route-map delay-timer commands. */
12885 install_element(CONFIG_NODE, &bgp_set_route_map_delay_timer_cmd);
12886 install_element(CONFIG_NODE, &no_bgp_set_route_map_delay_timer_cmd);
12887
12888 /* Dummy commands (Currently not supported) */
12889 install_element(BGP_NODE, &no_synchronization_cmd);
12890 install_element(BGP_NODE, &no_auto_summary_cmd);
12891
12892 /* "router bgp" commands. */
12893 install_element(CONFIG_NODE, &router_bgp_cmd);
12894
12895 /* "no router bgp" commands. */
12896 install_element(CONFIG_NODE, &no_router_bgp_cmd);
12897
12898 /* "bgp router-id" commands. */
12899 install_element(BGP_NODE, &bgp_router_id_cmd);
12900 install_element(BGP_NODE, &no_bgp_router_id_cmd);
12901
12902 /* "bgp cluster-id" commands. */
12903 install_element(BGP_NODE, &bgp_cluster_id_cmd);
12904 install_element(BGP_NODE, &no_bgp_cluster_id_cmd);
12905
12906 /* "bgp confederation" commands. */
12907 install_element(BGP_NODE, &bgp_confederation_identifier_cmd);
12908 install_element(BGP_NODE, &no_bgp_confederation_identifier_cmd);
12909
12910 /* "bgp confederation peers" commands. */
12911 install_element(BGP_NODE, &bgp_confederation_peers_cmd);
12912 install_element(BGP_NODE, &no_bgp_confederation_peers_cmd);
12913
12914 /* bgp max-med command */
12915 install_element(BGP_NODE, &bgp_maxmed_admin_cmd);
12916 install_element(BGP_NODE, &no_bgp_maxmed_admin_cmd);
12917 install_element(BGP_NODE, &bgp_maxmed_admin_medv_cmd);
12918 install_element(BGP_NODE, &bgp_maxmed_onstartup_cmd);
12919 install_element(BGP_NODE, &no_bgp_maxmed_onstartup_cmd);
12920
12921 /* bgp disable-ebgp-connected-nh-check */
12922 install_element(BGP_NODE, &bgp_disable_connected_route_check_cmd);
12923 install_element(BGP_NODE, &no_bgp_disable_connected_route_check_cmd);
12924
12925 /* bgp update-delay command */
12926 install_element(BGP_NODE, &bgp_update_delay_cmd);
12927 install_element(BGP_NODE, &no_bgp_update_delay_cmd);
12928 install_element(BGP_NODE, &bgp_update_delay_establish_wait_cmd);
12929
12930 install_element(BGP_NODE, &bgp_wpkt_quanta_cmd);
12931 install_element(BGP_NODE, &no_bgp_wpkt_quanta_cmd);
12932 install_element(BGP_NODE, &bgp_rpkt_quanta_cmd);
12933 install_element(BGP_NODE, &no_bgp_rpkt_quanta_cmd);
12934
12935 install_element(BGP_NODE, &bgp_coalesce_time_cmd);
12936 install_element(BGP_NODE, &no_bgp_coalesce_time_cmd);
12937
12938 /* "maximum-paths" commands. */
12939 install_element(BGP_NODE, &bgp_maxpaths_hidden_cmd);
12940 install_element(BGP_NODE, &no_bgp_maxpaths_hidden_cmd);
12941 install_element(BGP_IPV4_NODE, &bgp_maxpaths_cmd);
12942 install_element(BGP_IPV4_NODE, &no_bgp_maxpaths_cmd);
12943 install_element(BGP_IPV6_NODE, &bgp_maxpaths_cmd);
12944 install_element(BGP_IPV6_NODE, &no_bgp_maxpaths_cmd);
12945 install_element(BGP_NODE, &bgp_maxpaths_ibgp_hidden_cmd);
12946 install_element(BGP_NODE, &bgp_maxpaths_ibgp_cluster_hidden_cmd);
12947 install_element(BGP_NODE, &no_bgp_maxpaths_ibgp_hidden_cmd);
12948 install_element(BGP_IPV4_NODE, &bgp_maxpaths_ibgp_cmd);
12949 install_element(BGP_IPV4_NODE, &bgp_maxpaths_ibgp_cluster_cmd);
12950 install_element(BGP_IPV4_NODE, &no_bgp_maxpaths_ibgp_cmd);
12951 install_element(BGP_IPV6_NODE, &bgp_maxpaths_ibgp_cmd);
12952 install_element(BGP_IPV6_NODE, &bgp_maxpaths_ibgp_cluster_cmd);
12953 install_element(BGP_IPV6_NODE, &no_bgp_maxpaths_ibgp_cmd);
12954
12955 install_element(BGP_IPV6L_NODE, &bgp_maxpaths_cmd);
12956 install_element(BGP_IPV6L_NODE, &no_bgp_maxpaths_cmd);
12957 install_element(BGP_IPV6L_NODE, &bgp_maxpaths_ibgp_cmd);
12958 install_element(BGP_IPV6L_NODE, &bgp_maxpaths_ibgp_cluster_cmd);
12959 install_element(BGP_IPV6L_NODE, &no_bgp_maxpaths_ibgp_cmd);
12960
12961 /* "timers bgp" commands. */
12962 install_element(BGP_NODE, &bgp_timers_cmd);
12963 install_element(BGP_NODE, &no_bgp_timers_cmd);
12964
12965 /* route-map delay-timer commands - per instance for backwards compat.
12966 */
12967 install_element(BGP_NODE, &bgp_set_route_map_delay_timer_cmd);
12968 install_element(BGP_NODE, &no_bgp_set_route_map_delay_timer_cmd);
12969
12970 /* "bgp client-to-client reflection" commands */
12971 install_element(BGP_NODE, &no_bgp_client_to_client_reflection_cmd);
12972 install_element(BGP_NODE, &bgp_client_to_client_reflection_cmd);
12973
12974 /* "bgp always-compare-med" commands */
12975 install_element(BGP_NODE, &bgp_always_compare_med_cmd);
12976 install_element(BGP_NODE, &no_bgp_always_compare_med_cmd);
12977
12978 /* bgp ebgp-requires-policy */
12979 install_element(BGP_NODE, &bgp_ebgp_requires_policy_cmd);
12980 install_element(BGP_NODE, &no_bgp_ebgp_requires_policy_cmd);
12981
12982 /* "bgp deterministic-med" commands */
12983 install_element(BGP_NODE, &bgp_deterministic_med_cmd);
12984 install_element(BGP_NODE, &no_bgp_deterministic_med_cmd);
12985
12986 /* "bgp graceful-restart" commands */
12987 install_element(BGP_NODE, &bgp_graceful_restart_cmd);
12988 install_element(BGP_NODE, &no_bgp_graceful_restart_cmd);
12989 install_element(BGP_NODE, &bgp_graceful_restart_stalepath_time_cmd);
12990 install_element(BGP_NODE, &no_bgp_graceful_restart_stalepath_time_cmd);
12991 install_element(BGP_NODE, &bgp_graceful_restart_restart_time_cmd);
12992 install_element(BGP_NODE, &no_bgp_graceful_restart_restart_time_cmd);
12993
12994 install_element(BGP_NODE, &bgp_graceful_restart_preserve_fw_cmd);
12995 install_element(BGP_NODE, &no_bgp_graceful_restart_preserve_fw_cmd);
12996
12997 /* "bgp graceful-shutdown" commands */
12998 install_element(BGP_NODE, &bgp_graceful_shutdown_cmd);
12999 install_element(BGP_NODE, &no_bgp_graceful_shutdown_cmd);
13000
13001 /* "bgp fast-external-failover" commands */
13002 install_element(BGP_NODE, &bgp_fast_external_failover_cmd);
13003 install_element(BGP_NODE, &no_bgp_fast_external_failover_cmd);
13004
13005 /* "bgp enforce-first-as" commands */
13006 install_element(BGP_NODE, &bgp_enforce_first_as_cmd);
13007
13008 /* "bgp bestpath compare-routerid" commands */
13009 install_element(BGP_NODE, &bgp_bestpath_compare_router_id_cmd);
13010 install_element(BGP_NODE, &no_bgp_bestpath_compare_router_id_cmd);
13011
13012 /* "bgp bestpath as-path ignore" commands */
13013 install_element(BGP_NODE, &bgp_bestpath_aspath_ignore_cmd);
13014 install_element(BGP_NODE, &no_bgp_bestpath_aspath_ignore_cmd);
13015
13016 /* "bgp bestpath as-path confed" commands */
13017 install_element(BGP_NODE, &bgp_bestpath_aspath_confed_cmd);
13018 install_element(BGP_NODE, &no_bgp_bestpath_aspath_confed_cmd);
13019
13020 /* "bgp bestpath as-path multipath-relax" commands */
13021 install_element(BGP_NODE, &bgp_bestpath_aspath_multipath_relax_cmd);
13022 install_element(BGP_NODE, &no_bgp_bestpath_aspath_multipath_relax_cmd);
13023
13024 /* "bgp log-neighbor-changes" commands */
13025 install_element(BGP_NODE, &bgp_log_neighbor_changes_cmd);
13026 install_element(BGP_NODE, &no_bgp_log_neighbor_changes_cmd);
13027
13028 /* "bgp bestpath med" commands */
13029 install_element(BGP_NODE, &bgp_bestpath_med_cmd);
13030 install_element(BGP_NODE, &no_bgp_bestpath_med_cmd);
13031
13032 /* "no bgp default ipv4-unicast" commands. */
13033 install_element(BGP_NODE, &no_bgp_default_ipv4_unicast_cmd);
13034 install_element(BGP_NODE, &bgp_default_ipv4_unicast_cmd);
13035
13036 /* "bgp network import-check" commands. */
13037 install_element(BGP_NODE, &bgp_network_import_check_cmd);
13038 install_element(BGP_NODE, &bgp_network_import_check_exact_cmd);
13039 install_element(BGP_NODE, &no_bgp_network_import_check_cmd);
13040
13041 /* "bgp default local-preference" commands. */
13042 install_element(BGP_NODE, &bgp_default_local_preference_cmd);
13043 install_element(BGP_NODE, &no_bgp_default_local_preference_cmd);
13044
13045 /* bgp default show-hostname */
13046 install_element(BGP_NODE, &bgp_default_show_hostname_cmd);
13047 install_element(BGP_NODE, &no_bgp_default_show_hostname_cmd);
13048
13049 /* "bgp default subgroup-pkt-queue-max" commands. */
13050 install_element(BGP_NODE, &bgp_default_subgroup_pkt_queue_max_cmd);
13051 install_element(BGP_NODE, &no_bgp_default_subgroup_pkt_queue_max_cmd);
13052
13053 /* bgp ibgp-allow-policy-mods command */
13054 install_element(BGP_NODE, &bgp_rr_allow_outbound_policy_cmd);
13055 install_element(BGP_NODE, &no_bgp_rr_allow_outbound_policy_cmd);
13056
13057 /* "bgp listen limit" commands. */
13058 install_element(BGP_NODE, &bgp_listen_limit_cmd);
13059 install_element(BGP_NODE, &no_bgp_listen_limit_cmd);
13060
13061 /* "bgp listen range" commands. */
13062 install_element(BGP_NODE, &bgp_listen_range_cmd);
13063 install_element(BGP_NODE, &no_bgp_listen_range_cmd);
13064
13065 /* "bgp default shutdown" command */
13066 install_element(BGP_NODE, &bgp_default_shutdown_cmd);
13067
13068 /* "neighbor remote-as" commands. */
13069 install_element(BGP_NODE, &neighbor_remote_as_cmd);
13070 install_element(BGP_NODE, &neighbor_interface_config_cmd);
13071 install_element(BGP_NODE, &neighbor_interface_config_v6only_cmd);
13072 install_element(BGP_NODE, &neighbor_interface_config_remote_as_cmd);
13073 install_element(BGP_NODE,
13074 &neighbor_interface_v6only_config_remote_as_cmd);
13075 install_element(BGP_NODE, &no_neighbor_cmd);
13076 install_element(BGP_NODE, &no_neighbor_interface_config_cmd);
13077
13078 /* "neighbor peer-group" commands. */
13079 install_element(BGP_NODE, &neighbor_peer_group_cmd);
13080 install_element(BGP_NODE, &no_neighbor_peer_group_cmd);
13081 install_element(BGP_NODE,
13082 &no_neighbor_interface_peer_group_remote_as_cmd);
13083
13084 /* "neighbor local-as" commands. */
13085 install_element(BGP_NODE, &neighbor_local_as_cmd);
13086 install_element(BGP_NODE, &neighbor_local_as_no_prepend_cmd);
13087 install_element(BGP_NODE, &neighbor_local_as_no_prepend_replace_as_cmd);
13088 install_element(BGP_NODE, &no_neighbor_local_as_cmd);
13089
13090 /* "neighbor solo" commands. */
13091 install_element(BGP_NODE, &neighbor_solo_cmd);
13092 install_element(BGP_NODE, &no_neighbor_solo_cmd);
13093
13094 /* "neighbor password" commands. */
13095 install_element(BGP_NODE, &neighbor_password_cmd);
13096 install_element(BGP_NODE, &no_neighbor_password_cmd);
13097
13098 /* "neighbor activate" commands. */
13099 install_element(BGP_NODE, &neighbor_activate_hidden_cmd);
13100 install_element(BGP_IPV4_NODE, &neighbor_activate_cmd);
13101 install_element(BGP_IPV4M_NODE, &neighbor_activate_cmd);
13102 install_element(BGP_IPV4L_NODE, &neighbor_activate_cmd);
13103 install_element(BGP_IPV6_NODE, &neighbor_activate_cmd);
13104 install_element(BGP_IPV6M_NODE, &neighbor_activate_cmd);
13105 install_element(BGP_IPV6L_NODE, &neighbor_activate_cmd);
13106 install_element(BGP_VPNV4_NODE, &neighbor_activate_cmd);
13107 install_element(BGP_VPNV6_NODE, &neighbor_activate_cmd);
13108 install_element(BGP_FLOWSPECV4_NODE, &neighbor_activate_cmd);
13109 install_element(BGP_FLOWSPECV6_NODE, &neighbor_activate_cmd);
13110 install_element(BGP_EVPN_NODE, &neighbor_activate_cmd);
13111
13112 /* "no neighbor activate" commands. */
13113 install_element(BGP_NODE, &no_neighbor_activate_hidden_cmd);
13114 install_element(BGP_IPV4_NODE, &no_neighbor_activate_cmd);
13115 install_element(BGP_IPV4M_NODE, &no_neighbor_activate_cmd);
13116 install_element(BGP_IPV4L_NODE, &no_neighbor_activate_cmd);
13117 install_element(BGP_IPV6_NODE, &no_neighbor_activate_cmd);
13118 install_element(BGP_IPV6M_NODE, &no_neighbor_activate_cmd);
13119 install_element(BGP_IPV6L_NODE, &no_neighbor_activate_cmd);
13120 install_element(BGP_VPNV4_NODE, &no_neighbor_activate_cmd);
13121 install_element(BGP_VPNV6_NODE, &no_neighbor_activate_cmd);
13122 install_element(BGP_FLOWSPECV4_NODE, &no_neighbor_activate_cmd);
13123 install_element(BGP_FLOWSPECV6_NODE, &no_neighbor_activate_cmd);
13124 install_element(BGP_EVPN_NODE, &no_neighbor_activate_cmd);
13125
13126 /* "neighbor peer-group" set commands. */
13127 install_element(BGP_NODE, &neighbor_set_peer_group_cmd);
13128 install_element(BGP_IPV4_NODE, &neighbor_set_peer_group_hidden_cmd);
13129 install_element(BGP_IPV4M_NODE, &neighbor_set_peer_group_hidden_cmd);
13130 install_element(BGP_IPV6_NODE, &neighbor_set_peer_group_hidden_cmd);
13131 install_element(BGP_IPV6M_NODE, &neighbor_set_peer_group_hidden_cmd);
13132 install_element(BGP_IPV6L_NODE, &neighbor_set_peer_group_hidden_cmd);
13133 install_element(BGP_VPNV4_NODE, &neighbor_set_peer_group_hidden_cmd);
13134 install_element(BGP_VPNV6_NODE, &neighbor_set_peer_group_hidden_cmd);
13135 install_element(BGP_FLOWSPECV4_NODE,
13136 &neighbor_set_peer_group_hidden_cmd);
13137 install_element(BGP_FLOWSPECV6_NODE,
13138 &neighbor_set_peer_group_hidden_cmd);
13139
13140 /* "no neighbor peer-group unset" commands. */
13141 install_element(BGP_NODE, &no_neighbor_set_peer_group_cmd);
13142 install_element(BGP_IPV4_NODE, &no_neighbor_set_peer_group_hidden_cmd);
13143 install_element(BGP_IPV4M_NODE, &no_neighbor_set_peer_group_hidden_cmd);
13144 install_element(BGP_IPV6_NODE, &no_neighbor_set_peer_group_hidden_cmd);
13145 install_element(BGP_IPV6M_NODE, &no_neighbor_set_peer_group_hidden_cmd);
13146 install_element(BGP_IPV6L_NODE, &no_neighbor_set_peer_group_hidden_cmd);
13147 install_element(BGP_VPNV4_NODE, &no_neighbor_set_peer_group_hidden_cmd);
13148 install_element(BGP_VPNV6_NODE, &no_neighbor_set_peer_group_hidden_cmd);
13149 install_element(BGP_FLOWSPECV4_NODE,
13150 &no_neighbor_set_peer_group_hidden_cmd);
13151 install_element(BGP_FLOWSPECV6_NODE,
13152 &no_neighbor_set_peer_group_hidden_cmd);
13153
13154 /* "neighbor softreconfiguration inbound" commands.*/
13155 install_element(BGP_NODE, &neighbor_soft_reconfiguration_hidden_cmd);
13156 install_element(BGP_NODE, &no_neighbor_soft_reconfiguration_hidden_cmd);
13157 install_element(BGP_IPV4_NODE, &neighbor_soft_reconfiguration_cmd);
13158 install_element(BGP_IPV4_NODE, &no_neighbor_soft_reconfiguration_cmd);
13159 install_element(BGP_IPV4L_NODE, &neighbor_soft_reconfiguration_cmd);
13160 install_element(BGP_IPV4L_NODE, &no_neighbor_soft_reconfiguration_cmd);
13161 install_element(BGP_IPV4M_NODE, &neighbor_soft_reconfiguration_cmd);
13162 install_element(BGP_IPV4M_NODE, &no_neighbor_soft_reconfiguration_cmd);
13163 install_element(BGP_IPV6_NODE, &neighbor_soft_reconfiguration_cmd);
13164 install_element(BGP_IPV6_NODE, &no_neighbor_soft_reconfiguration_cmd);
13165 install_element(BGP_IPV6M_NODE, &neighbor_soft_reconfiguration_cmd);
13166 install_element(BGP_IPV6M_NODE, &no_neighbor_soft_reconfiguration_cmd);
13167 install_element(BGP_IPV6L_NODE, &neighbor_soft_reconfiguration_cmd);
13168 install_element(BGP_IPV6L_NODE, &no_neighbor_soft_reconfiguration_cmd);
13169 install_element(BGP_VPNV4_NODE, &neighbor_soft_reconfiguration_cmd);
13170 install_element(BGP_VPNV4_NODE, &no_neighbor_soft_reconfiguration_cmd);
13171 install_element(BGP_VPNV6_NODE, &neighbor_soft_reconfiguration_cmd);
13172 install_element(BGP_VPNV6_NODE, &no_neighbor_soft_reconfiguration_cmd);
13173 install_element(BGP_FLOWSPECV4_NODE,
13174 &neighbor_soft_reconfiguration_cmd);
13175 install_element(BGP_FLOWSPECV4_NODE,
13176 &no_neighbor_soft_reconfiguration_cmd);
13177 install_element(BGP_FLOWSPECV6_NODE,
13178 &neighbor_soft_reconfiguration_cmd);
13179 install_element(BGP_FLOWSPECV6_NODE,
13180 &no_neighbor_soft_reconfiguration_cmd);
13181 install_element(BGP_EVPN_NODE, &neighbor_soft_reconfiguration_cmd);
13182 install_element(BGP_EVPN_NODE, &no_neighbor_soft_reconfiguration_cmd);
13183
13184 /* "neighbor attribute-unchanged" commands. */
13185 install_element(BGP_NODE, &neighbor_attr_unchanged_hidden_cmd);
13186 install_element(BGP_NODE, &no_neighbor_attr_unchanged_hidden_cmd);
13187 install_element(BGP_IPV4_NODE, &neighbor_attr_unchanged_cmd);
13188 install_element(BGP_IPV4_NODE, &no_neighbor_attr_unchanged_cmd);
13189 install_element(BGP_IPV4M_NODE, &neighbor_attr_unchanged_cmd);
13190 install_element(BGP_IPV4M_NODE, &no_neighbor_attr_unchanged_cmd);
13191 install_element(BGP_IPV4L_NODE, &neighbor_attr_unchanged_cmd);
13192 install_element(BGP_IPV4L_NODE, &no_neighbor_attr_unchanged_cmd);
13193 install_element(BGP_IPV6_NODE, &neighbor_attr_unchanged_cmd);
13194 install_element(BGP_IPV6_NODE, &no_neighbor_attr_unchanged_cmd);
13195 install_element(BGP_IPV6M_NODE, &neighbor_attr_unchanged_cmd);
13196 install_element(BGP_IPV6M_NODE, &no_neighbor_attr_unchanged_cmd);
13197 install_element(BGP_IPV6L_NODE, &neighbor_attr_unchanged_cmd);
13198 install_element(BGP_IPV6L_NODE, &no_neighbor_attr_unchanged_cmd);
13199 install_element(BGP_VPNV4_NODE, &neighbor_attr_unchanged_cmd);
13200 install_element(BGP_VPNV4_NODE, &no_neighbor_attr_unchanged_cmd);
13201 install_element(BGP_VPNV6_NODE, &neighbor_attr_unchanged_cmd);
13202 install_element(BGP_VPNV6_NODE, &no_neighbor_attr_unchanged_cmd);
13203
13204 install_element(BGP_EVPN_NODE, &neighbor_attr_unchanged_cmd);
13205 install_element(BGP_EVPN_NODE, &no_neighbor_attr_unchanged_cmd);
13206
13207 /* "nexthop-local unchanged" commands */
13208 install_element(BGP_IPV6_NODE, &neighbor_nexthop_local_unchanged_cmd);
13209 install_element(BGP_IPV6_NODE,
13210 &no_neighbor_nexthop_local_unchanged_cmd);
13211
13212 /* "neighbor next-hop-self" commands. */
13213 install_element(BGP_NODE, &neighbor_nexthop_self_hidden_cmd);
13214 install_element(BGP_NODE, &no_neighbor_nexthop_self_hidden_cmd);
13215 install_element(BGP_IPV4_NODE, &neighbor_nexthop_self_cmd);
13216 install_element(BGP_IPV4_NODE, &no_neighbor_nexthop_self_cmd);
13217 install_element(BGP_IPV4M_NODE, &neighbor_nexthop_self_cmd);
13218 install_element(BGP_IPV4M_NODE, &no_neighbor_nexthop_self_cmd);
13219 install_element(BGP_IPV4L_NODE, &neighbor_nexthop_self_cmd);
13220 install_element(BGP_IPV4L_NODE, &no_neighbor_nexthop_self_cmd);
13221 install_element(BGP_IPV6_NODE, &neighbor_nexthop_self_cmd);
13222 install_element(BGP_IPV6_NODE, &no_neighbor_nexthop_self_cmd);
13223 install_element(BGP_IPV6M_NODE, &neighbor_nexthop_self_cmd);
13224 install_element(BGP_IPV6M_NODE, &no_neighbor_nexthop_self_cmd);
13225 install_element(BGP_IPV6L_NODE, &neighbor_nexthop_self_cmd);
13226 install_element(BGP_IPV6L_NODE, &no_neighbor_nexthop_self_cmd);
13227 install_element(BGP_VPNV4_NODE, &neighbor_nexthop_self_cmd);
13228 install_element(BGP_VPNV4_NODE, &no_neighbor_nexthop_self_cmd);
13229 install_element(BGP_VPNV6_NODE, &neighbor_nexthop_self_cmd);
13230 install_element(BGP_VPNV6_NODE, &no_neighbor_nexthop_self_cmd);
13231 install_element(BGP_EVPN_NODE, &neighbor_nexthop_self_cmd);
13232 install_element(BGP_EVPN_NODE, &no_neighbor_nexthop_self_cmd);
13233
13234 /* "neighbor next-hop-self force" commands. */
13235 install_element(BGP_NODE, &neighbor_nexthop_self_force_hidden_cmd);
13236 install_element(BGP_NODE, &no_neighbor_nexthop_self_force_hidden_cmd);
13237 install_element(BGP_IPV4_NODE, &neighbor_nexthop_self_force_cmd);
13238 install_element(BGP_IPV4_NODE, &no_neighbor_nexthop_self_force_cmd);
13239 install_element(BGP_IPV4M_NODE, &neighbor_nexthop_self_force_cmd);
13240 install_element(BGP_IPV4M_NODE, &no_neighbor_nexthop_self_force_cmd);
13241 install_element(BGP_IPV4L_NODE, &neighbor_nexthop_self_force_cmd);
13242 install_element(BGP_IPV4L_NODE, &no_neighbor_nexthop_self_force_cmd);
13243 install_element(BGP_IPV6_NODE, &neighbor_nexthop_self_force_cmd);
13244 install_element(BGP_IPV6_NODE, &no_neighbor_nexthop_self_force_cmd);
13245 install_element(BGP_IPV6M_NODE, &neighbor_nexthop_self_force_cmd);
13246 install_element(BGP_IPV6M_NODE, &no_neighbor_nexthop_self_force_cmd);
13247 install_element(BGP_IPV6L_NODE, &neighbor_nexthop_self_force_cmd);
13248 install_element(BGP_IPV6L_NODE, &no_neighbor_nexthop_self_force_cmd);
13249 install_element(BGP_VPNV4_NODE, &neighbor_nexthop_self_force_cmd);
13250 install_element(BGP_VPNV4_NODE, &no_neighbor_nexthop_self_force_cmd);
13251 install_element(BGP_VPNV6_NODE, &neighbor_nexthop_self_force_cmd);
13252 install_element(BGP_VPNV6_NODE, &no_neighbor_nexthop_self_force_cmd);
13253
13254 /* "neighbor as-override" commands. */
13255 install_element(BGP_NODE, &neighbor_as_override_hidden_cmd);
13256 install_element(BGP_NODE, &no_neighbor_as_override_hidden_cmd);
13257 install_element(BGP_IPV4_NODE, &neighbor_as_override_cmd);
13258 install_element(BGP_IPV4_NODE, &no_neighbor_as_override_cmd);
13259 install_element(BGP_IPV4M_NODE, &neighbor_as_override_cmd);
13260 install_element(BGP_IPV4M_NODE, &no_neighbor_as_override_cmd);
13261 install_element(BGP_IPV4L_NODE, &neighbor_as_override_cmd);
13262 install_element(BGP_IPV4L_NODE, &no_neighbor_as_override_cmd);
13263 install_element(BGP_IPV6_NODE, &neighbor_as_override_cmd);
13264 install_element(BGP_IPV6_NODE, &no_neighbor_as_override_cmd);
13265 install_element(BGP_IPV6M_NODE, &neighbor_as_override_cmd);
13266 install_element(BGP_IPV6M_NODE, &no_neighbor_as_override_cmd);
13267 install_element(BGP_IPV6L_NODE, &neighbor_as_override_cmd);
13268 install_element(BGP_IPV6L_NODE, &no_neighbor_as_override_cmd);
13269 install_element(BGP_VPNV4_NODE, &neighbor_as_override_cmd);
13270 install_element(BGP_VPNV4_NODE, &no_neighbor_as_override_cmd);
13271 install_element(BGP_VPNV6_NODE, &neighbor_as_override_cmd);
13272 install_element(BGP_VPNV6_NODE, &no_neighbor_as_override_cmd);
13273
13274 /* "neighbor remove-private-AS" commands. */
13275 install_element(BGP_NODE, &neighbor_remove_private_as_hidden_cmd);
13276 install_element(BGP_NODE, &no_neighbor_remove_private_as_hidden_cmd);
13277 install_element(BGP_NODE, &neighbor_remove_private_as_all_hidden_cmd);
13278 install_element(BGP_NODE,
13279 &no_neighbor_remove_private_as_all_hidden_cmd);
13280 install_element(BGP_NODE,
13281 &neighbor_remove_private_as_replace_as_hidden_cmd);
13282 install_element(BGP_NODE,
13283 &no_neighbor_remove_private_as_replace_as_hidden_cmd);
13284 install_element(BGP_NODE,
13285 &neighbor_remove_private_as_all_replace_as_hidden_cmd);
13286 install_element(
13287 BGP_NODE,
13288 &no_neighbor_remove_private_as_all_replace_as_hidden_cmd);
13289 install_element(BGP_IPV4_NODE, &neighbor_remove_private_as_cmd);
13290 install_element(BGP_IPV4_NODE, &no_neighbor_remove_private_as_cmd);
13291 install_element(BGP_IPV4_NODE, &neighbor_remove_private_as_all_cmd);
13292 install_element(BGP_IPV4_NODE, &no_neighbor_remove_private_as_all_cmd);
13293 install_element(BGP_IPV4_NODE,
13294 &neighbor_remove_private_as_replace_as_cmd);
13295 install_element(BGP_IPV4_NODE,
13296 &no_neighbor_remove_private_as_replace_as_cmd);
13297 install_element(BGP_IPV4_NODE,
13298 &neighbor_remove_private_as_all_replace_as_cmd);
13299 install_element(BGP_IPV4_NODE,
13300 &no_neighbor_remove_private_as_all_replace_as_cmd);
13301 install_element(BGP_IPV4M_NODE, &neighbor_remove_private_as_cmd);
13302 install_element(BGP_IPV4M_NODE, &no_neighbor_remove_private_as_cmd);
13303 install_element(BGP_IPV4M_NODE, &neighbor_remove_private_as_all_cmd);
13304 install_element(BGP_IPV4M_NODE, &no_neighbor_remove_private_as_all_cmd);
13305 install_element(BGP_IPV4M_NODE,
13306 &neighbor_remove_private_as_replace_as_cmd);
13307 install_element(BGP_IPV4M_NODE,
13308 &no_neighbor_remove_private_as_replace_as_cmd);
13309 install_element(BGP_IPV4M_NODE,
13310 &neighbor_remove_private_as_all_replace_as_cmd);
13311 install_element(BGP_IPV4M_NODE,
13312 &no_neighbor_remove_private_as_all_replace_as_cmd);
13313 install_element(BGP_IPV4L_NODE, &neighbor_remove_private_as_cmd);
13314 install_element(BGP_IPV4L_NODE, &no_neighbor_remove_private_as_cmd);
13315 install_element(BGP_IPV4L_NODE, &neighbor_remove_private_as_all_cmd);
13316 install_element(BGP_IPV4L_NODE, &no_neighbor_remove_private_as_all_cmd);
13317 install_element(BGP_IPV4L_NODE,
13318 &neighbor_remove_private_as_replace_as_cmd);
13319 install_element(BGP_IPV4L_NODE,
13320 &no_neighbor_remove_private_as_replace_as_cmd);
13321 install_element(BGP_IPV4L_NODE,
13322 &neighbor_remove_private_as_all_replace_as_cmd);
13323 install_element(BGP_IPV4L_NODE,
13324 &no_neighbor_remove_private_as_all_replace_as_cmd);
13325 install_element(BGP_IPV6_NODE, &neighbor_remove_private_as_cmd);
13326 install_element(BGP_IPV6_NODE, &no_neighbor_remove_private_as_cmd);
13327 install_element(BGP_IPV6_NODE, &neighbor_remove_private_as_all_cmd);
13328 install_element(BGP_IPV6_NODE, &no_neighbor_remove_private_as_all_cmd);
13329 install_element(BGP_IPV6_NODE,
13330 &neighbor_remove_private_as_replace_as_cmd);
13331 install_element(BGP_IPV6_NODE,
13332 &no_neighbor_remove_private_as_replace_as_cmd);
13333 install_element(BGP_IPV6_NODE,
13334 &neighbor_remove_private_as_all_replace_as_cmd);
13335 install_element(BGP_IPV6_NODE,
13336 &no_neighbor_remove_private_as_all_replace_as_cmd);
13337 install_element(BGP_IPV6M_NODE, &neighbor_remove_private_as_cmd);
13338 install_element(BGP_IPV6M_NODE, &no_neighbor_remove_private_as_cmd);
13339 install_element(BGP_IPV6M_NODE, &neighbor_remove_private_as_all_cmd);
13340 install_element(BGP_IPV6M_NODE, &no_neighbor_remove_private_as_all_cmd);
13341 install_element(BGP_IPV6M_NODE,
13342 &neighbor_remove_private_as_replace_as_cmd);
13343 install_element(BGP_IPV6M_NODE,
13344 &no_neighbor_remove_private_as_replace_as_cmd);
13345 install_element(BGP_IPV6M_NODE,
13346 &neighbor_remove_private_as_all_replace_as_cmd);
13347 install_element(BGP_IPV6M_NODE,
13348 &no_neighbor_remove_private_as_all_replace_as_cmd);
13349 install_element(BGP_IPV6L_NODE, &neighbor_remove_private_as_cmd);
13350 install_element(BGP_IPV6L_NODE, &no_neighbor_remove_private_as_cmd);
13351 install_element(BGP_IPV6L_NODE, &neighbor_remove_private_as_all_cmd);
13352 install_element(BGP_IPV6L_NODE, &no_neighbor_remove_private_as_all_cmd);
13353 install_element(BGP_IPV6L_NODE,
13354 &neighbor_remove_private_as_replace_as_cmd);
13355 install_element(BGP_IPV6L_NODE,
13356 &no_neighbor_remove_private_as_replace_as_cmd);
13357 install_element(BGP_IPV6L_NODE,
13358 &neighbor_remove_private_as_all_replace_as_cmd);
13359 install_element(BGP_IPV6L_NODE,
13360 &no_neighbor_remove_private_as_all_replace_as_cmd);
13361 install_element(BGP_VPNV4_NODE, &neighbor_remove_private_as_cmd);
13362 install_element(BGP_VPNV4_NODE, &no_neighbor_remove_private_as_cmd);
13363 install_element(BGP_VPNV4_NODE, &neighbor_remove_private_as_all_cmd);
13364 install_element(BGP_VPNV4_NODE, &no_neighbor_remove_private_as_all_cmd);
13365 install_element(BGP_VPNV4_NODE,
13366 &neighbor_remove_private_as_replace_as_cmd);
13367 install_element(BGP_VPNV4_NODE,
13368 &no_neighbor_remove_private_as_replace_as_cmd);
13369 install_element(BGP_VPNV4_NODE,
13370 &neighbor_remove_private_as_all_replace_as_cmd);
13371 install_element(BGP_VPNV4_NODE,
13372 &no_neighbor_remove_private_as_all_replace_as_cmd);
13373 install_element(BGP_VPNV6_NODE, &neighbor_remove_private_as_cmd);
13374 install_element(BGP_VPNV6_NODE, &no_neighbor_remove_private_as_cmd);
13375 install_element(BGP_VPNV6_NODE, &neighbor_remove_private_as_all_cmd);
13376 install_element(BGP_VPNV6_NODE, &no_neighbor_remove_private_as_all_cmd);
13377 install_element(BGP_VPNV6_NODE,
13378 &neighbor_remove_private_as_replace_as_cmd);
13379 install_element(BGP_VPNV6_NODE,
13380 &no_neighbor_remove_private_as_replace_as_cmd);
13381 install_element(BGP_VPNV6_NODE,
13382 &neighbor_remove_private_as_all_replace_as_cmd);
13383 install_element(BGP_VPNV6_NODE,
13384 &no_neighbor_remove_private_as_all_replace_as_cmd);
13385
13386 /* "neighbor send-community" commands.*/
13387 install_element(BGP_NODE, &neighbor_send_community_hidden_cmd);
13388 install_element(BGP_NODE, &neighbor_send_community_type_hidden_cmd);
13389 install_element(BGP_NODE, &no_neighbor_send_community_hidden_cmd);
13390 install_element(BGP_NODE, &no_neighbor_send_community_type_hidden_cmd);
13391 install_element(BGP_IPV4_NODE, &neighbor_send_community_cmd);
13392 install_element(BGP_IPV4_NODE, &neighbor_send_community_type_cmd);
13393 install_element(BGP_IPV4_NODE, &no_neighbor_send_community_cmd);
13394 install_element(BGP_IPV4_NODE, &no_neighbor_send_community_type_cmd);
13395 install_element(BGP_IPV4M_NODE, &neighbor_send_community_cmd);
13396 install_element(BGP_IPV4M_NODE, &neighbor_send_community_type_cmd);
13397 install_element(BGP_IPV4M_NODE, &no_neighbor_send_community_cmd);
13398 install_element(BGP_IPV4M_NODE, &no_neighbor_send_community_type_cmd);
13399 install_element(BGP_IPV4L_NODE, &neighbor_send_community_cmd);
13400 install_element(BGP_IPV4L_NODE, &neighbor_send_community_type_cmd);
13401 install_element(BGP_IPV4L_NODE, &no_neighbor_send_community_cmd);
13402 install_element(BGP_IPV4L_NODE, &no_neighbor_send_community_type_cmd);
13403 install_element(BGP_IPV6_NODE, &neighbor_send_community_cmd);
13404 install_element(BGP_IPV6_NODE, &neighbor_send_community_type_cmd);
13405 install_element(BGP_IPV6_NODE, &no_neighbor_send_community_cmd);
13406 install_element(BGP_IPV6_NODE, &no_neighbor_send_community_type_cmd);
13407 install_element(BGP_IPV6M_NODE, &neighbor_send_community_cmd);
13408 install_element(BGP_IPV6M_NODE, &neighbor_send_community_type_cmd);
13409 install_element(BGP_IPV6M_NODE, &no_neighbor_send_community_cmd);
13410 install_element(BGP_IPV6M_NODE, &no_neighbor_send_community_type_cmd);
13411 install_element(BGP_IPV6L_NODE, &neighbor_send_community_cmd);
13412 install_element(BGP_IPV6L_NODE, &neighbor_send_community_type_cmd);
13413 install_element(BGP_IPV6L_NODE, &no_neighbor_send_community_cmd);
13414 install_element(BGP_IPV6L_NODE, &no_neighbor_send_community_type_cmd);
13415 install_element(BGP_VPNV4_NODE, &neighbor_send_community_cmd);
13416 install_element(BGP_VPNV4_NODE, &neighbor_send_community_type_cmd);
13417 install_element(BGP_VPNV4_NODE, &no_neighbor_send_community_cmd);
13418 install_element(BGP_VPNV4_NODE, &no_neighbor_send_community_type_cmd);
13419 install_element(BGP_VPNV6_NODE, &neighbor_send_community_cmd);
13420 install_element(BGP_VPNV6_NODE, &neighbor_send_community_type_cmd);
13421 install_element(BGP_VPNV6_NODE, &no_neighbor_send_community_cmd);
13422 install_element(BGP_VPNV6_NODE, &no_neighbor_send_community_type_cmd);
13423
13424 /* "neighbor route-reflector" commands.*/
13425 install_element(BGP_NODE, &neighbor_route_reflector_client_hidden_cmd);
13426 install_element(BGP_NODE,
13427 &no_neighbor_route_reflector_client_hidden_cmd);
13428 install_element(BGP_IPV4_NODE, &neighbor_route_reflector_client_cmd);
13429 install_element(BGP_IPV4_NODE, &no_neighbor_route_reflector_client_cmd);
13430 install_element(BGP_IPV4M_NODE, &neighbor_route_reflector_client_cmd);
13431 install_element(BGP_IPV4M_NODE,
13432 &no_neighbor_route_reflector_client_cmd);
13433 install_element(BGP_IPV4L_NODE, &neighbor_route_reflector_client_cmd);
13434 install_element(BGP_IPV4L_NODE,
13435 &no_neighbor_route_reflector_client_cmd);
13436 install_element(BGP_IPV6_NODE, &neighbor_route_reflector_client_cmd);
13437 install_element(BGP_IPV6_NODE, &no_neighbor_route_reflector_client_cmd);
13438 install_element(BGP_IPV6M_NODE, &neighbor_route_reflector_client_cmd);
13439 install_element(BGP_IPV6M_NODE,
13440 &no_neighbor_route_reflector_client_cmd);
13441 install_element(BGP_IPV6L_NODE, &neighbor_route_reflector_client_cmd);
13442 install_element(BGP_IPV6L_NODE,
13443 &no_neighbor_route_reflector_client_cmd);
13444 install_element(BGP_VPNV4_NODE, &neighbor_route_reflector_client_cmd);
13445 install_element(BGP_VPNV4_NODE,
13446 &no_neighbor_route_reflector_client_cmd);
13447 install_element(BGP_VPNV6_NODE, &neighbor_route_reflector_client_cmd);
13448 install_element(BGP_VPNV6_NODE,
13449 &no_neighbor_route_reflector_client_cmd);
13450 install_element(BGP_FLOWSPECV4_NODE,
13451 &neighbor_route_reflector_client_cmd);
13452 install_element(BGP_FLOWSPECV4_NODE,
13453 &no_neighbor_route_reflector_client_cmd);
13454 install_element(BGP_FLOWSPECV6_NODE,
13455 &neighbor_route_reflector_client_cmd);
13456 install_element(BGP_FLOWSPECV6_NODE,
13457 &no_neighbor_route_reflector_client_cmd);
13458 install_element(BGP_EVPN_NODE, &neighbor_route_reflector_client_cmd);
13459 install_element(BGP_EVPN_NODE, &no_neighbor_route_reflector_client_cmd);
13460
13461 /* "neighbor route-server" commands.*/
13462 install_element(BGP_NODE, &neighbor_route_server_client_hidden_cmd);
13463 install_element(BGP_NODE, &no_neighbor_route_server_client_hidden_cmd);
13464 install_element(BGP_IPV4_NODE, &neighbor_route_server_client_cmd);
13465 install_element(BGP_IPV4_NODE, &no_neighbor_route_server_client_cmd);
13466 install_element(BGP_IPV4M_NODE, &neighbor_route_server_client_cmd);
13467 install_element(BGP_IPV4M_NODE, &no_neighbor_route_server_client_cmd);
13468 install_element(BGP_IPV4L_NODE, &neighbor_route_server_client_cmd);
13469 install_element(BGP_IPV4L_NODE, &no_neighbor_route_server_client_cmd);
13470 install_element(BGP_IPV6_NODE, &neighbor_route_server_client_cmd);
13471 install_element(BGP_IPV6_NODE, &no_neighbor_route_server_client_cmd);
13472 install_element(BGP_IPV6M_NODE, &neighbor_route_server_client_cmd);
13473 install_element(BGP_IPV6M_NODE, &no_neighbor_route_server_client_cmd);
13474 install_element(BGP_IPV6L_NODE, &neighbor_route_server_client_cmd);
13475 install_element(BGP_IPV6L_NODE, &no_neighbor_route_server_client_cmd);
13476 install_element(BGP_VPNV4_NODE, &neighbor_route_server_client_cmd);
13477 install_element(BGP_VPNV4_NODE, &no_neighbor_route_server_client_cmd);
13478 install_element(BGP_VPNV6_NODE, &neighbor_route_server_client_cmd);
13479 install_element(BGP_VPNV6_NODE, &no_neighbor_route_server_client_cmd);
13480 install_element(BGP_EVPN_NODE, &neighbor_route_server_client_cmd);
13481 install_element(BGP_EVPN_NODE, &no_neighbor_route_server_client_cmd);
13482 install_element(BGP_FLOWSPECV4_NODE, &neighbor_route_server_client_cmd);
13483 install_element(BGP_FLOWSPECV4_NODE,
13484 &no_neighbor_route_server_client_cmd);
13485 install_element(BGP_FLOWSPECV6_NODE, &neighbor_route_server_client_cmd);
13486 install_element(BGP_FLOWSPECV6_NODE,
13487 &no_neighbor_route_server_client_cmd);
13488
13489 /* "neighbor addpath-tx-all-paths" commands.*/
13490 install_element(BGP_NODE, &neighbor_addpath_tx_all_paths_hidden_cmd);
13491 install_element(BGP_NODE, &no_neighbor_addpath_tx_all_paths_hidden_cmd);
13492 install_element(BGP_IPV4_NODE, &neighbor_addpath_tx_all_paths_cmd);
13493 install_element(BGP_IPV4_NODE, &no_neighbor_addpath_tx_all_paths_cmd);
13494 install_element(BGP_IPV4M_NODE, &neighbor_addpath_tx_all_paths_cmd);
13495 install_element(BGP_IPV4M_NODE, &no_neighbor_addpath_tx_all_paths_cmd);
13496 install_element(BGP_IPV4L_NODE, &neighbor_addpath_tx_all_paths_cmd);
13497 install_element(BGP_IPV4L_NODE, &no_neighbor_addpath_tx_all_paths_cmd);
13498 install_element(BGP_IPV6_NODE, &neighbor_addpath_tx_all_paths_cmd);
13499 install_element(BGP_IPV6_NODE, &no_neighbor_addpath_tx_all_paths_cmd);
13500 install_element(BGP_IPV6M_NODE, &neighbor_addpath_tx_all_paths_cmd);
13501 install_element(BGP_IPV6M_NODE, &no_neighbor_addpath_tx_all_paths_cmd);
13502 install_element(BGP_IPV6L_NODE, &neighbor_addpath_tx_all_paths_cmd);
13503 install_element(BGP_IPV6L_NODE, &no_neighbor_addpath_tx_all_paths_cmd);
13504 install_element(BGP_VPNV4_NODE, &neighbor_addpath_tx_all_paths_cmd);
13505 install_element(BGP_VPNV4_NODE, &no_neighbor_addpath_tx_all_paths_cmd);
13506 install_element(BGP_VPNV6_NODE, &neighbor_addpath_tx_all_paths_cmd);
13507 install_element(BGP_VPNV6_NODE, &no_neighbor_addpath_tx_all_paths_cmd);
13508
13509 /* "neighbor addpath-tx-bestpath-per-AS" commands.*/
13510 install_element(BGP_NODE,
13511 &neighbor_addpath_tx_bestpath_per_as_hidden_cmd);
13512 install_element(BGP_NODE,
13513 &no_neighbor_addpath_tx_bestpath_per_as_hidden_cmd);
13514 install_element(BGP_IPV4_NODE,
13515 &neighbor_addpath_tx_bestpath_per_as_cmd);
13516 install_element(BGP_IPV4_NODE,
13517 &no_neighbor_addpath_tx_bestpath_per_as_cmd);
13518 install_element(BGP_IPV4M_NODE,
13519 &neighbor_addpath_tx_bestpath_per_as_cmd);
13520 install_element(BGP_IPV4M_NODE,
13521 &no_neighbor_addpath_tx_bestpath_per_as_cmd);
13522 install_element(BGP_IPV4L_NODE,
13523 &neighbor_addpath_tx_bestpath_per_as_cmd);
13524 install_element(BGP_IPV4L_NODE,
13525 &no_neighbor_addpath_tx_bestpath_per_as_cmd);
13526 install_element(BGP_IPV6_NODE,
13527 &neighbor_addpath_tx_bestpath_per_as_cmd);
13528 install_element(BGP_IPV6_NODE,
13529 &no_neighbor_addpath_tx_bestpath_per_as_cmd);
13530 install_element(BGP_IPV6M_NODE,
13531 &neighbor_addpath_tx_bestpath_per_as_cmd);
13532 install_element(BGP_IPV6M_NODE,
13533 &no_neighbor_addpath_tx_bestpath_per_as_cmd);
13534 install_element(BGP_IPV6L_NODE,
13535 &neighbor_addpath_tx_bestpath_per_as_cmd);
13536 install_element(BGP_IPV6L_NODE,
13537 &no_neighbor_addpath_tx_bestpath_per_as_cmd);
13538 install_element(BGP_VPNV4_NODE,
13539 &neighbor_addpath_tx_bestpath_per_as_cmd);
13540 install_element(BGP_VPNV4_NODE,
13541 &no_neighbor_addpath_tx_bestpath_per_as_cmd);
13542 install_element(BGP_VPNV6_NODE,
13543 &neighbor_addpath_tx_bestpath_per_as_cmd);
13544 install_element(BGP_VPNV6_NODE,
13545 &no_neighbor_addpath_tx_bestpath_per_as_cmd);
13546
13547 /* "neighbor passive" commands. */
13548 install_element(BGP_NODE, &neighbor_passive_cmd);
13549 install_element(BGP_NODE, &no_neighbor_passive_cmd);
13550
13551
13552 /* "neighbor shutdown" commands. */
13553 install_element(BGP_NODE, &neighbor_shutdown_cmd);
13554 install_element(BGP_NODE, &no_neighbor_shutdown_cmd);
13555 install_element(BGP_NODE, &neighbor_shutdown_msg_cmd);
13556 install_element(BGP_NODE, &no_neighbor_shutdown_msg_cmd);
13557
13558 /* "neighbor capability extended-nexthop" commands.*/
13559 install_element(BGP_NODE, &neighbor_capability_enhe_cmd);
13560 install_element(BGP_NODE, &no_neighbor_capability_enhe_cmd);
13561
13562 /* "neighbor capability orf prefix-list" commands.*/
13563 install_element(BGP_NODE, &neighbor_capability_orf_prefix_hidden_cmd);
13564 install_element(BGP_NODE,
13565 &no_neighbor_capability_orf_prefix_hidden_cmd);
13566 install_element(BGP_IPV4_NODE, &neighbor_capability_orf_prefix_cmd);
13567 install_element(BGP_IPV4_NODE, &no_neighbor_capability_orf_prefix_cmd);
13568 install_element(BGP_IPV4M_NODE, &neighbor_capability_orf_prefix_cmd);
13569 install_element(BGP_IPV4M_NODE, &no_neighbor_capability_orf_prefix_cmd);
13570 install_element(BGP_IPV4L_NODE, &neighbor_capability_orf_prefix_cmd);
13571 install_element(BGP_IPV4L_NODE, &no_neighbor_capability_orf_prefix_cmd);
13572 install_element(BGP_IPV6_NODE, &neighbor_capability_orf_prefix_cmd);
13573 install_element(BGP_IPV6_NODE, &no_neighbor_capability_orf_prefix_cmd);
13574 install_element(BGP_IPV6M_NODE, &neighbor_capability_orf_prefix_cmd);
13575 install_element(BGP_IPV6M_NODE, &no_neighbor_capability_orf_prefix_cmd);
13576 install_element(BGP_IPV6L_NODE, &neighbor_capability_orf_prefix_cmd);
13577 install_element(BGP_IPV6L_NODE, &no_neighbor_capability_orf_prefix_cmd);
13578
13579 /* "neighbor capability dynamic" commands.*/
13580 install_element(BGP_NODE, &neighbor_capability_dynamic_cmd);
13581 install_element(BGP_NODE, &no_neighbor_capability_dynamic_cmd);
13582
13583 /* "neighbor dont-capability-negotiate" commands. */
13584 install_element(BGP_NODE, &neighbor_dont_capability_negotiate_cmd);
13585 install_element(BGP_NODE, &no_neighbor_dont_capability_negotiate_cmd);
13586
13587 /* "neighbor ebgp-multihop" commands. */
13588 install_element(BGP_NODE, &neighbor_ebgp_multihop_cmd);
13589 install_element(BGP_NODE, &neighbor_ebgp_multihop_ttl_cmd);
13590 install_element(BGP_NODE, &no_neighbor_ebgp_multihop_cmd);
13591
13592 /* "neighbor disable-connected-check" commands. */
13593 install_element(BGP_NODE, &neighbor_disable_connected_check_cmd);
13594 install_element(BGP_NODE, &no_neighbor_disable_connected_check_cmd);
13595
13596 /* "neighbor enforce-first-as" commands. */
13597 install_element(BGP_NODE, &neighbor_enforce_first_as_cmd);
13598 install_element(BGP_NODE, &no_neighbor_enforce_first_as_cmd);
13599
13600 /* "neighbor description" commands. */
13601 install_element(BGP_NODE, &neighbor_description_cmd);
13602 install_element(BGP_NODE, &no_neighbor_description_cmd);
13603 install_element(BGP_NODE, &no_neighbor_description_comment_cmd);
13604
13605 /* "neighbor update-source" commands. "*/
13606 install_element(BGP_NODE, &neighbor_update_source_cmd);
13607 install_element(BGP_NODE, &no_neighbor_update_source_cmd);
13608
13609 /* "neighbor default-originate" commands. */
13610 install_element(BGP_NODE, &neighbor_default_originate_hidden_cmd);
13611 install_element(BGP_NODE, &neighbor_default_originate_rmap_hidden_cmd);
13612 install_element(BGP_NODE, &no_neighbor_default_originate_hidden_cmd);
13613 install_element(BGP_IPV4_NODE, &neighbor_default_originate_cmd);
13614 install_element(BGP_IPV4_NODE, &neighbor_default_originate_rmap_cmd);
13615 install_element(BGP_IPV4_NODE, &no_neighbor_default_originate_cmd);
13616 install_element(BGP_IPV4M_NODE, &neighbor_default_originate_cmd);
13617 install_element(BGP_IPV4M_NODE, &neighbor_default_originate_rmap_cmd);
13618 install_element(BGP_IPV4M_NODE, &no_neighbor_default_originate_cmd);
13619 install_element(BGP_IPV4L_NODE, &neighbor_default_originate_cmd);
13620 install_element(BGP_IPV4L_NODE, &neighbor_default_originate_rmap_cmd);
13621 install_element(BGP_IPV4L_NODE, &no_neighbor_default_originate_cmd);
13622 install_element(BGP_IPV6_NODE, &neighbor_default_originate_cmd);
13623 install_element(BGP_IPV6_NODE, &neighbor_default_originate_rmap_cmd);
13624 install_element(BGP_IPV6_NODE, &no_neighbor_default_originate_cmd);
13625 install_element(BGP_IPV6M_NODE, &neighbor_default_originate_cmd);
13626 install_element(BGP_IPV6M_NODE, &neighbor_default_originate_rmap_cmd);
13627 install_element(BGP_IPV6M_NODE, &no_neighbor_default_originate_cmd);
13628 install_element(BGP_IPV6L_NODE, &neighbor_default_originate_cmd);
13629 install_element(BGP_IPV6L_NODE, &neighbor_default_originate_rmap_cmd);
13630 install_element(BGP_IPV6L_NODE, &no_neighbor_default_originate_cmd);
13631
13632 /* "neighbor port" commands. */
13633 install_element(BGP_NODE, &neighbor_port_cmd);
13634 install_element(BGP_NODE, &no_neighbor_port_cmd);
13635
13636 /* "neighbor weight" commands. */
13637 install_element(BGP_NODE, &neighbor_weight_hidden_cmd);
13638 install_element(BGP_NODE, &no_neighbor_weight_hidden_cmd);
13639
13640 install_element(BGP_IPV4_NODE, &neighbor_weight_cmd);
13641 install_element(BGP_IPV4_NODE, &no_neighbor_weight_cmd);
13642 install_element(BGP_IPV4M_NODE, &neighbor_weight_cmd);
13643 install_element(BGP_IPV4M_NODE, &no_neighbor_weight_cmd);
13644 install_element(BGP_IPV4L_NODE, &neighbor_weight_cmd);
13645 install_element(BGP_IPV4L_NODE, &no_neighbor_weight_cmd);
13646 install_element(BGP_IPV6_NODE, &neighbor_weight_cmd);
13647 install_element(BGP_IPV6_NODE, &no_neighbor_weight_cmd);
13648 install_element(BGP_IPV6M_NODE, &neighbor_weight_cmd);
13649 install_element(BGP_IPV6M_NODE, &no_neighbor_weight_cmd);
13650 install_element(BGP_IPV6L_NODE, &neighbor_weight_cmd);
13651 install_element(BGP_IPV6L_NODE, &no_neighbor_weight_cmd);
13652 install_element(BGP_VPNV4_NODE, &neighbor_weight_cmd);
13653 install_element(BGP_VPNV4_NODE, &no_neighbor_weight_cmd);
13654 install_element(BGP_VPNV6_NODE, &neighbor_weight_cmd);
13655 install_element(BGP_VPNV6_NODE, &no_neighbor_weight_cmd);
13656
13657 /* "neighbor override-capability" commands. */
13658 install_element(BGP_NODE, &neighbor_override_capability_cmd);
13659 install_element(BGP_NODE, &no_neighbor_override_capability_cmd);
13660
13661 /* "neighbor strict-capability-match" commands. */
13662 install_element(BGP_NODE, &neighbor_strict_capability_cmd);
13663 install_element(BGP_NODE, &no_neighbor_strict_capability_cmd);
13664
13665 /* "neighbor timers" commands. */
13666 install_element(BGP_NODE, &neighbor_timers_cmd);
13667 install_element(BGP_NODE, &no_neighbor_timers_cmd);
13668
13669 /* "neighbor timers connect" commands. */
13670 install_element(BGP_NODE, &neighbor_timers_connect_cmd);
13671 install_element(BGP_NODE, &no_neighbor_timers_connect_cmd);
13672
13673 /* "neighbor advertisement-interval" commands. */
13674 install_element(BGP_NODE, &neighbor_advertise_interval_cmd);
13675 install_element(BGP_NODE, &no_neighbor_advertise_interval_cmd);
13676
13677 /* "neighbor interface" commands. */
13678 install_element(BGP_NODE, &neighbor_interface_cmd);
13679 install_element(BGP_NODE, &no_neighbor_interface_cmd);
13680
13681 /* "neighbor distribute" commands. */
13682 install_element(BGP_NODE, &neighbor_distribute_list_hidden_cmd);
13683 install_element(BGP_NODE, &no_neighbor_distribute_list_hidden_cmd);
13684 install_element(BGP_IPV4_NODE, &neighbor_distribute_list_cmd);
13685 install_element(BGP_IPV4_NODE, &no_neighbor_distribute_list_cmd);
13686 install_element(BGP_IPV4M_NODE, &neighbor_distribute_list_cmd);
13687 install_element(BGP_IPV4M_NODE, &no_neighbor_distribute_list_cmd);
13688 install_element(BGP_IPV4L_NODE, &neighbor_distribute_list_cmd);
13689 install_element(BGP_IPV4L_NODE, &no_neighbor_distribute_list_cmd);
13690 install_element(BGP_IPV6_NODE, &neighbor_distribute_list_cmd);
13691 install_element(BGP_IPV6_NODE, &no_neighbor_distribute_list_cmd);
13692 install_element(BGP_IPV6M_NODE, &neighbor_distribute_list_cmd);
13693 install_element(BGP_IPV6M_NODE, &no_neighbor_distribute_list_cmd);
13694 install_element(BGP_IPV6L_NODE, &neighbor_distribute_list_cmd);
13695 install_element(BGP_IPV6L_NODE, &no_neighbor_distribute_list_cmd);
13696 install_element(BGP_VPNV4_NODE, &neighbor_distribute_list_cmd);
13697 install_element(BGP_VPNV4_NODE, &no_neighbor_distribute_list_cmd);
13698 install_element(BGP_VPNV6_NODE, &neighbor_distribute_list_cmd);
13699 install_element(BGP_VPNV6_NODE, &no_neighbor_distribute_list_cmd);
13700
13701 /* "neighbor prefix-list" commands. */
13702 install_element(BGP_NODE, &neighbor_prefix_list_hidden_cmd);
13703 install_element(BGP_NODE, &no_neighbor_prefix_list_hidden_cmd);
13704 install_element(BGP_IPV4_NODE, &neighbor_prefix_list_cmd);
13705 install_element(BGP_IPV4_NODE, &no_neighbor_prefix_list_cmd);
13706 install_element(BGP_IPV4M_NODE, &neighbor_prefix_list_cmd);
13707 install_element(BGP_IPV4M_NODE, &no_neighbor_prefix_list_cmd);
13708 install_element(BGP_IPV4L_NODE, &neighbor_prefix_list_cmd);
13709 install_element(BGP_IPV4L_NODE, &no_neighbor_prefix_list_cmd);
13710 install_element(BGP_IPV6_NODE, &neighbor_prefix_list_cmd);
13711 install_element(BGP_IPV6_NODE, &no_neighbor_prefix_list_cmd);
13712 install_element(BGP_IPV6M_NODE, &neighbor_prefix_list_cmd);
13713 install_element(BGP_IPV6M_NODE, &no_neighbor_prefix_list_cmd);
13714 install_element(BGP_IPV6L_NODE, &neighbor_prefix_list_cmd);
13715 install_element(BGP_IPV6L_NODE, &no_neighbor_prefix_list_cmd);
13716 install_element(BGP_VPNV4_NODE, &neighbor_prefix_list_cmd);
13717 install_element(BGP_VPNV4_NODE, &no_neighbor_prefix_list_cmd);
13718 install_element(BGP_VPNV6_NODE, &neighbor_prefix_list_cmd);
13719 install_element(BGP_VPNV6_NODE, &no_neighbor_prefix_list_cmd);
13720 install_element(BGP_FLOWSPECV4_NODE, &neighbor_prefix_list_cmd);
13721 install_element(BGP_FLOWSPECV4_NODE, &no_neighbor_prefix_list_cmd);
13722 install_element(BGP_FLOWSPECV6_NODE, &neighbor_prefix_list_cmd);
13723 install_element(BGP_FLOWSPECV6_NODE, &no_neighbor_prefix_list_cmd);
13724
13725 /* "neighbor filter-list" commands. */
13726 install_element(BGP_NODE, &neighbor_filter_list_hidden_cmd);
13727 install_element(BGP_NODE, &no_neighbor_filter_list_hidden_cmd);
13728 install_element(BGP_IPV4_NODE, &neighbor_filter_list_cmd);
13729 install_element(BGP_IPV4_NODE, &no_neighbor_filter_list_cmd);
13730 install_element(BGP_IPV4M_NODE, &neighbor_filter_list_cmd);
13731 install_element(BGP_IPV4M_NODE, &no_neighbor_filter_list_cmd);
13732 install_element(BGP_IPV4L_NODE, &neighbor_filter_list_cmd);
13733 install_element(BGP_IPV4L_NODE, &no_neighbor_filter_list_cmd);
13734 install_element(BGP_IPV6_NODE, &neighbor_filter_list_cmd);
13735 install_element(BGP_IPV6_NODE, &no_neighbor_filter_list_cmd);
13736 install_element(BGP_IPV6M_NODE, &neighbor_filter_list_cmd);
13737 install_element(BGP_IPV6M_NODE, &no_neighbor_filter_list_cmd);
13738 install_element(BGP_IPV6L_NODE, &neighbor_filter_list_cmd);
13739 install_element(BGP_IPV6L_NODE, &no_neighbor_filter_list_cmd);
13740 install_element(BGP_VPNV4_NODE, &neighbor_filter_list_cmd);
13741 install_element(BGP_VPNV4_NODE, &no_neighbor_filter_list_cmd);
13742 install_element(BGP_VPNV6_NODE, &neighbor_filter_list_cmd);
13743 install_element(BGP_VPNV6_NODE, &no_neighbor_filter_list_cmd);
13744 install_element(BGP_FLOWSPECV4_NODE, &neighbor_filter_list_cmd);
13745 install_element(BGP_FLOWSPECV4_NODE, &no_neighbor_filter_list_cmd);
13746 install_element(BGP_FLOWSPECV6_NODE, &neighbor_filter_list_cmd);
13747 install_element(BGP_FLOWSPECV6_NODE, &no_neighbor_filter_list_cmd);
13748
13749 /* "neighbor route-map" commands. */
13750 install_element(BGP_NODE, &neighbor_route_map_hidden_cmd);
13751 install_element(BGP_NODE, &no_neighbor_route_map_hidden_cmd);
13752 install_element(BGP_IPV4_NODE, &neighbor_route_map_cmd);
13753 install_element(BGP_IPV4_NODE, &no_neighbor_route_map_cmd);
13754 install_element(BGP_IPV4M_NODE, &neighbor_route_map_cmd);
13755 install_element(BGP_IPV4M_NODE, &no_neighbor_route_map_cmd);
13756 install_element(BGP_IPV4L_NODE, &neighbor_route_map_cmd);
13757 install_element(BGP_IPV4L_NODE, &no_neighbor_route_map_cmd);
13758 install_element(BGP_IPV6_NODE, &neighbor_route_map_cmd);
13759 install_element(BGP_IPV6_NODE, &no_neighbor_route_map_cmd);
13760 install_element(BGP_IPV6M_NODE, &neighbor_route_map_cmd);
13761 install_element(BGP_IPV6M_NODE, &no_neighbor_route_map_cmd);
13762 install_element(BGP_IPV6L_NODE, &neighbor_route_map_cmd);
13763 install_element(BGP_IPV6L_NODE, &no_neighbor_route_map_cmd);
13764 install_element(BGP_VPNV4_NODE, &neighbor_route_map_cmd);
13765 install_element(BGP_VPNV4_NODE, &no_neighbor_route_map_cmd);
13766 install_element(BGP_VPNV6_NODE, &neighbor_route_map_cmd);
13767 install_element(BGP_VPNV6_NODE, &no_neighbor_route_map_cmd);
13768 install_element(BGP_FLOWSPECV4_NODE, &neighbor_route_map_cmd);
13769 install_element(BGP_FLOWSPECV4_NODE, &no_neighbor_route_map_cmd);
13770 install_element(BGP_FLOWSPECV6_NODE, &neighbor_route_map_cmd);
13771 install_element(BGP_FLOWSPECV6_NODE, &no_neighbor_route_map_cmd);
13772 install_element(BGP_EVPN_NODE, &neighbor_route_map_cmd);
13773 install_element(BGP_EVPN_NODE, &no_neighbor_route_map_cmd);
13774
13775 /* "neighbor unsuppress-map" commands. */
13776 install_element(BGP_NODE, &neighbor_unsuppress_map_hidden_cmd);
13777 install_element(BGP_NODE, &no_neighbor_unsuppress_map_hidden_cmd);
13778 install_element(BGP_IPV4_NODE, &neighbor_unsuppress_map_cmd);
13779 install_element(BGP_IPV4_NODE, &no_neighbor_unsuppress_map_cmd);
13780 install_element(BGP_IPV4M_NODE, &neighbor_unsuppress_map_cmd);
13781 install_element(BGP_IPV4M_NODE, &no_neighbor_unsuppress_map_cmd);
13782 install_element(BGP_IPV4L_NODE, &neighbor_unsuppress_map_cmd);
13783 install_element(BGP_IPV4L_NODE, &no_neighbor_unsuppress_map_cmd);
13784 install_element(BGP_IPV6_NODE, &neighbor_unsuppress_map_cmd);
13785 install_element(BGP_IPV6_NODE, &no_neighbor_unsuppress_map_cmd);
13786 install_element(BGP_IPV6M_NODE, &neighbor_unsuppress_map_cmd);
13787 install_element(BGP_IPV6M_NODE, &no_neighbor_unsuppress_map_cmd);
13788 install_element(BGP_IPV6L_NODE, &neighbor_unsuppress_map_cmd);
13789 install_element(BGP_IPV6L_NODE, &no_neighbor_unsuppress_map_cmd);
13790 install_element(BGP_VPNV4_NODE, &neighbor_unsuppress_map_cmd);
13791 install_element(BGP_VPNV4_NODE, &no_neighbor_unsuppress_map_cmd);
13792 install_element(BGP_VPNV6_NODE, &neighbor_unsuppress_map_cmd);
13793 install_element(BGP_VPNV6_NODE, &no_neighbor_unsuppress_map_cmd);
13794
13795 /* "neighbor maximum-prefix" commands. */
13796 install_element(BGP_NODE, &neighbor_maximum_prefix_hidden_cmd);
13797 install_element(BGP_NODE,
13798 &neighbor_maximum_prefix_threshold_hidden_cmd);
13799 install_element(BGP_NODE, &neighbor_maximum_prefix_warning_hidden_cmd);
13800 install_element(BGP_NODE,
13801 &neighbor_maximum_prefix_threshold_warning_hidden_cmd);
13802 install_element(BGP_NODE, &neighbor_maximum_prefix_restart_hidden_cmd);
13803 install_element(BGP_NODE,
13804 &neighbor_maximum_prefix_threshold_restart_hidden_cmd);
13805 install_element(BGP_NODE, &no_neighbor_maximum_prefix_hidden_cmd);
13806 install_element(BGP_IPV4_NODE, &neighbor_maximum_prefix_cmd);
13807 install_element(BGP_IPV4_NODE, &neighbor_maximum_prefix_threshold_cmd);
13808 install_element(BGP_IPV4_NODE, &neighbor_maximum_prefix_warning_cmd);
13809 install_element(BGP_IPV4_NODE,
13810 &neighbor_maximum_prefix_threshold_warning_cmd);
13811 install_element(BGP_IPV4_NODE, &neighbor_maximum_prefix_restart_cmd);
13812 install_element(BGP_IPV4_NODE,
13813 &neighbor_maximum_prefix_threshold_restart_cmd);
13814 install_element(BGP_IPV4_NODE, &no_neighbor_maximum_prefix_cmd);
13815 install_element(BGP_IPV4M_NODE, &neighbor_maximum_prefix_cmd);
13816 install_element(BGP_IPV4M_NODE, &neighbor_maximum_prefix_threshold_cmd);
13817 install_element(BGP_IPV4M_NODE, &neighbor_maximum_prefix_warning_cmd);
13818 install_element(BGP_IPV4M_NODE,
13819 &neighbor_maximum_prefix_threshold_warning_cmd);
13820 install_element(BGP_IPV4M_NODE, &neighbor_maximum_prefix_restart_cmd);
13821 install_element(BGP_IPV4M_NODE,
13822 &neighbor_maximum_prefix_threshold_restart_cmd);
13823 install_element(BGP_IPV4M_NODE, &no_neighbor_maximum_prefix_cmd);
13824 install_element(BGP_IPV4L_NODE, &neighbor_maximum_prefix_cmd);
13825 install_element(BGP_IPV4L_NODE, &neighbor_maximum_prefix_threshold_cmd);
13826 install_element(BGP_IPV4L_NODE, &neighbor_maximum_prefix_warning_cmd);
13827 install_element(BGP_IPV4L_NODE,
13828 &neighbor_maximum_prefix_threshold_warning_cmd);
13829 install_element(BGP_IPV4L_NODE, &neighbor_maximum_prefix_restart_cmd);
13830 install_element(BGP_IPV4L_NODE,
13831 &neighbor_maximum_prefix_threshold_restart_cmd);
13832 install_element(BGP_IPV4L_NODE, &no_neighbor_maximum_prefix_cmd);
13833 install_element(BGP_IPV6_NODE, &neighbor_maximum_prefix_cmd);
13834 install_element(BGP_IPV6_NODE, &neighbor_maximum_prefix_threshold_cmd);
13835 install_element(BGP_IPV6_NODE, &neighbor_maximum_prefix_warning_cmd);
13836 install_element(BGP_IPV6_NODE,
13837 &neighbor_maximum_prefix_threshold_warning_cmd);
13838 install_element(BGP_IPV6_NODE, &neighbor_maximum_prefix_restart_cmd);
13839 install_element(BGP_IPV6_NODE,
13840 &neighbor_maximum_prefix_threshold_restart_cmd);
13841 install_element(BGP_IPV6_NODE, &no_neighbor_maximum_prefix_cmd);
13842 install_element(BGP_IPV6M_NODE, &neighbor_maximum_prefix_cmd);
13843 install_element(BGP_IPV6M_NODE, &neighbor_maximum_prefix_threshold_cmd);
13844 install_element(BGP_IPV6M_NODE, &neighbor_maximum_prefix_warning_cmd);
13845 install_element(BGP_IPV6M_NODE,
13846 &neighbor_maximum_prefix_threshold_warning_cmd);
13847 install_element(BGP_IPV6M_NODE, &neighbor_maximum_prefix_restart_cmd);
13848 install_element(BGP_IPV6M_NODE,
13849 &neighbor_maximum_prefix_threshold_restart_cmd);
13850 install_element(BGP_IPV6M_NODE, &no_neighbor_maximum_prefix_cmd);
13851 install_element(BGP_IPV6L_NODE, &neighbor_maximum_prefix_cmd);
13852 install_element(BGP_IPV6L_NODE, &neighbor_maximum_prefix_threshold_cmd);
13853 install_element(BGP_IPV6L_NODE, &neighbor_maximum_prefix_warning_cmd);
13854 install_element(BGP_IPV6L_NODE,
13855 &neighbor_maximum_prefix_threshold_warning_cmd);
13856 install_element(BGP_IPV6L_NODE, &neighbor_maximum_prefix_restart_cmd);
13857 install_element(BGP_IPV6L_NODE,
13858 &neighbor_maximum_prefix_threshold_restart_cmd);
13859 install_element(BGP_IPV6L_NODE, &no_neighbor_maximum_prefix_cmd);
13860 install_element(BGP_VPNV4_NODE, &neighbor_maximum_prefix_cmd);
13861 install_element(BGP_VPNV4_NODE, &neighbor_maximum_prefix_threshold_cmd);
13862 install_element(BGP_VPNV4_NODE, &neighbor_maximum_prefix_warning_cmd);
13863 install_element(BGP_VPNV4_NODE,
13864 &neighbor_maximum_prefix_threshold_warning_cmd);
13865 install_element(BGP_VPNV4_NODE, &neighbor_maximum_prefix_restart_cmd);
13866 install_element(BGP_VPNV4_NODE,
13867 &neighbor_maximum_prefix_threshold_restart_cmd);
13868 install_element(BGP_VPNV4_NODE, &no_neighbor_maximum_prefix_cmd);
13869 install_element(BGP_VPNV6_NODE, &neighbor_maximum_prefix_cmd);
13870 install_element(BGP_VPNV6_NODE, &neighbor_maximum_prefix_threshold_cmd);
13871 install_element(BGP_VPNV6_NODE, &neighbor_maximum_prefix_warning_cmd);
13872 install_element(BGP_VPNV6_NODE,
13873 &neighbor_maximum_prefix_threshold_warning_cmd);
13874 install_element(BGP_VPNV6_NODE, &neighbor_maximum_prefix_restart_cmd);
13875 install_element(BGP_VPNV6_NODE,
13876 &neighbor_maximum_prefix_threshold_restart_cmd);
13877 install_element(BGP_VPNV6_NODE, &no_neighbor_maximum_prefix_cmd);
13878
13879 /* "neighbor allowas-in" */
13880 install_element(BGP_NODE, &neighbor_allowas_in_hidden_cmd);
13881 install_element(BGP_NODE, &no_neighbor_allowas_in_hidden_cmd);
13882 install_element(BGP_IPV4_NODE, &neighbor_allowas_in_cmd);
13883 install_element(BGP_IPV4_NODE, &no_neighbor_allowas_in_cmd);
13884 install_element(BGP_IPV4M_NODE, &neighbor_allowas_in_cmd);
13885 install_element(BGP_IPV4M_NODE, &no_neighbor_allowas_in_cmd);
13886 install_element(BGP_IPV4L_NODE, &neighbor_allowas_in_cmd);
13887 install_element(BGP_IPV4L_NODE, &no_neighbor_allowas_in_cmd);
13888 install_element(BGP_IPV6_NODE, &neighbor_allowas_in_cmd);
13889 install_element(BGP_IPV6_NODE, &no_neighbor_allowas_in_cmd);
13890 install_element(BGP_IPV6M_NODE, &neighbor_allowas_in_cmd);
13891 install_element(BGP_IPV6M_NODE, &no_neighbor_allowas_in_cmd);
13892 install_element(BGP_IPV6L_NODE, &neighbor_allowas_in_cmd);
13893 install_element(BGP_IPV6L_NODE, &no_neighbor_allowas_in_cmd);
13894 install_element(BGP_VPNV4_NODE, &neighbor_allowas_in_cmd);
13895 install_element(BGP_VPNV4_NODE, &no_neighbor_allowas_in_cmd);
13896 install_element(BGP_VPNV6_NODE, &neighbor_allowas_in_cmd);
13897 install_element(BGP_VPNV6_NODE, &no_neighbor_allowas_in_cmd);
13898 install_element(BGP_EVPN_NODE, &neighbor_allowas_in_cmd);
13899 install_element(BGP_EVPN_NODE, &no_neighbor_allowas_in_cmd);
13900
13901 /* address-family commands. */
13902 install_element(BGP_NODE, &address_family_ipv4_safi_cmd);
13903 install_element(BGP_NODE, &address_family_ipv6_safi_cmd);
13904 #ifdef KEEP_OLD_VPN_COMMANDS
13905 install_element(BGP_NODE, &address_family_vpnv4_cmd);
13906 install_element(BGP_NODE, &address_family_vpnv6_cmd);
13907 #endif /* KEEP_OLD_VPN_COMMANDS */
13908
13909 install_element(BGP_NODE, &address_family_evpn_cmd);
13910
13911 /* "exit-address-family" command. */
13912 install_element(BGP_IPV4_NODE, &exit_address_family_cmd);
13913 install_element(BGP_IPV4M_NODE, &exit_address_family_cmd);
13914 install_element(BGP_IPV4L_NODE, &exit_address_family_cmd);
13915 install_element(BGP_IPV6_NODE, &exit_address_family_cmd);
13916 install_element(BGP_IPV6M_NODE, &exit_address_family_cmd);
13917 install_element(BGP_IPV6L_NODE, &exit_address_family_cmd);
13918 install_element(BGP_VPNV4_NODE, &exit_address_family_cmd);
13919 install_element(BGP_VPNV6_NODE, &exit_address_family_cmd);
13920 install_element(BGP_FLOWSPECV4_NODE, &exit_address_family_cmd);
13921 install_element(BGP_FLOWSPECV6_NODE, &exit_address_family_cmd);
13922 install_element(BGP_EVPN_NODE, &exit_address_family_cmd);
13923
13924 /* "clear ip bgp commands" */
13925 install_element(ENABLE_NODE, &clear_ip_bgp_all_cmd);
13926
13927 /* clear ip bgp prefix */
13928 install_element(ENABLE_NODE, &clear_ip_bgp_prefix_cmd);
13929 install_element(ENABLE_NODE, &clear_bgp_ipv6_safi_prefix_cmd);
13930 install_element(ENABLE_NODE, &clear_bgp_instance_ipv6_safi_prefix_cmd);
13931
13932 /* "show [ip] bgp summary" commands. */
13933 install_element(VIEW_NODE, &show_bgp_instance_all_ipv6_updgrps_cmd);
13934 install_element(VIEW_NODE, &show_bgp_l2vpn_evpn_updgrps_cmd);
13935 install_element(VIEW_NODE, &show_bgp_instance_updgrps_stats_cmd);
13936 install_element(VIEW_NODE, &show_bgp_updgrps_stats_cmd);
13937 install_element(VIEW_NODE, &show_ip_bgp_instance_updgrps_adj_s_cmd);
13938 install_element(VIEW_NODE, &show_ip_bgp_summary_cmd);
13939 install_element(VIEW_NODE, &show_ip_bgp_updgrps_cmd);
13940
13941 /* "show [ip] bgp neighbors" commands. */
13942 install_element(VIEW_NODE, &show_ip_bgp_neighbors_cmd);
13943
13944 /* "show [ip] bgp peer-group" commands. */
13945 install_element(VIEW_NODE, &show_ip_bgp_peer_groups_cmd);
13946
13947 /* "show [ip] bgp paths" commands. */
13948 install_element(VIEW_NODE, &show_ip_bgp_paths_cmd);
13949
13950 /* "show [ip] bgp community" commands. */
13951 install_element(VIEW_NODE, &show_ip_bgp_community_info_cmd);
13952
13953 /* "show ip bgp large-community" commands. */
13954 install_element(VIEW_NODE, &show_ip_bgp_lcommunity_info_cmd);
13955 /* "show [ip] bgp attribute-info" commands. */
13956 install_element(VIEW_NODE, &show_ip_bgp_attr_info_cmd);
13957 /* "show [ip] bgp route-leak" command */
13958 install_element(VIEW_NODE, &show_ip_bgp_route_leak_cmd);
13959
13960 /* "redistribute" commands. */
13961 install_element(BGP_NODE, &bgp_redistribute_ipv4_hidden_cmd);
13962 install_element(BGP_NODE, &no_bgp_redistribute_ipv4_hidden_cmd);
13963 install_element(BGP_NODE, &bgp_redistribute_ipv4_rmap_hidden_cmd);
13964 install_element(BGP_NODE, &bgp_redistribute_ipv4_metric_hidden_cmd);
13965 install_element(BGP_NODE,
13966 &bgp_redistribute_ipv4_rmap_metric_hidden_cmd);
13967 install_element(BGP_NODE,
13968 &bgp_redistribute_ipv4_metric_rmap_hidden_cmd);
13969 install_element(BGP_NODE, &bgp_redistribute_ipv4_ospf_hidden_cmd);
13970 install_element(BGP_NODE, &no_bgp_redistribute_ipv4_ospf_hidden_cmd);
13971 install_element(BGP_NODE, &bgp_redistribute_ipv4_ospf_rmap_hidden_cmd);
13972 install_element(BGP_NODE,
13973 &bgp_redistribute_ipv4_ospf_metric_hidden_cmd);
13974 install_element(BGP_NODE,
13975 &bgp_redistribute_ipv4_ospf_rmap_metric_hidden_cmd);
13976 install_element(BGP_NODE,
13977 &bgp_redistribute_ipv4_ospf_metric_rmap_hidden_cmd);
13978 install_element(BGP_IPV4_NODE, &bgp_redistribute_ipv4_cmd);
13979 install_element(BGP_IPV4_NODE, &no_bgp_redistribute_ipv4_cmd);
13980 install_element(BGP_IPV4_NODE, &bgp_redistribute_ipv4_rmap_cmd);
13981 install_element(BGP_IPV4_NODE, &bgp_redistribute_ipv4_metric_cmd);
13982 install_element(BGP_IPV4_NODE, &bgp_redistribute_ipv4_rmap_metric_cmd);
13983 install_element(BGP_IPV4_NODE, &bgp_redistribute_ipv4_metric_rmap_cmd);
13984 install_element(BGP_IPV4_NODE, &bgp_redistribute_ipv4_ospf_cmd);
13985 install_element(BGP_IPV4_NODE, &no_bgp_redistribute_ipv4_ospf_cmd);
13986 install_element(BGP_IPV4_NODE, &bgp_redistribute_ipv4_ospf_rmap_cmd);
13987 install_element(BGP_IPV4_NODE, &bgp_redistribute_ipv4_ospf_metric_cmd);
13988 install_element(BGP_IPV4_NODE,
13989 &bgp_redistribute_ipv4_ospf_rmap_metric_cmd);
13990 install_element(BGP_IPV4_NODE,
13991 &bgp_redistribute_ipv4_ospf_metric_rmap_cmd);
13992 install_element(BGP_IPV6_NODE, &bgp_redistribute_ipv6_cmd);
13993 install_element(BGP_IPV6_NODE, &no_bgp_redistribute_ipv6_cmd);
13994 install_element(BGP_IPV6_NODE, &bgp_redistribute_ipv6_rmap_cmd);
13995 install_element(BGP_IPV6_NODE, &bgp_redistribute_ipv6_metric_cmd);
13996 install_element(BGP_IPV6_NODE, &bgp_redistribute_ipv6_rmap_metric_cmd);
13997 install_element(BGP_IPV6_NODE, &bgp_redistribute_ipv6_metric_rmap_cmd);
13998
13999 /* import|export vpn [route-map WORD] */
14000 install_element(BGP_IPV4_NODE, &bgp_imexport_vpn_cmd);
14001 install_element(BGP_IPV6_NODE, &bgp_imexport_vpn_cmd);
14002
14003 install_element(BGP_IPV4_NODE, &bgp_imexport_vrf_cmd);
14004 install_element(BGP_IPV6_NODE, &bgp_imexport_vrf_cmd);
14005
14006 /* ttl_security commands */
14007 install_element(BGP_NODE, &neighbor_ttl_security_cmd);
14008 install_element(BGP_NODE, &no_neighbor_ttl_security_cmd);
14009
14010 /* "show [ip] bgp memory" commands. */
14011 install_element(VIEW_NODE, &show_bgp_memory_cmd);
14012
14013 /* "show bgp martian next-hop" */
14014 install_element(VIEW_NODE, &show_bgp_martian_nexthop_db_cmd);
14015
14016 install_element(VIEW_NODE, &show_bgp_mac_hash_cmd);
14017
14018 /* "show [ip] bgp views" commands. */
14019 install_element(VIEW_NODE, &show_bgp_views_cmd);
14020
14021 /* "show [ip] bgp vrfs" commands. */
14022 install_element(VIEW_NODE, &show_bgp_vrfs_cmd);
14023
14024 /* Community-list. */
14025 community_list_vty();
14026
14027 /* vpn-policy commands */
14028 install_element(BGP_IPV4_NODE, &af_rd_vpn_export_cmd);
14029 install_element(BGP_IPV6_NODE, &af_rd_vpn_export_cmd);
14030 install_element(BGP_IPV4_NODE, &af_label_vpn_export_cmd);
14031 install_element(BGP_IPV6_NODE, &af_label_vpn_export_cmd);
14032 install_element(BGP_IPV4_NODE, &af_nexthop_vpn_export_cmd);
14033 install_element(BGP_IPV6_NODE, &af_nexthop_vpn_export_cmd);
14034 install_element(BGP_IPV4_NODE, &af_rt_vpn_imexport_cmd);
14035 install_element(BGP_IPV6_NODE, &af_rt_vpn_imexport_cmd);
14036 install_element(BGP_IPV4_NODE, &af_route_map_vpn_imexport_cmd);
14037 install_element(BGP_IPV6_NODE, &af_route_map_vpn_imexport_cmd);
14038 install_element(BGP_IPV4_NODE, &af_import_vrf_route_map_cmd);
14039 install_element(BGP_IPV6_NODE, &af_import_vrf_route_map_cmd);
14040
14041 install_element(BGP_IPV4_NODE, &af_routetarget_import_cmd);
14042 install_element(BGP_IPV6_NODE, &af_routetarget_import_cmd);
14043
14044 install_element(BGP_IPV4_NODE, &af_no_rd_vpn_export_cmd);
14045 install_element(BGP_IPV6_NODE, &af_no_rd_vpn_export_cmd);
14046 install_element(BGP_IPV4_NODE, &af_no_label_vpn_export_cmd);
14047 install_element(BGP_IPV6_NODE, &af_no_label_vpn_export_cmd);
14048 install_element(BGP_IPV4_NODE, &af_no_nexthop_vpn_export_cmd);
14049 install_element(BGP_IPV6_NODE, &af_no_nexthop_vpn_export_cmd);
14050 install_element(BGP_IPV4_NODE, &af_no_rt_vpn_imexport_cmd);
14051 install_element(BGP_IPV6_NODE, &af_no_rt_vpn_imexport_cmd);
14052 install_element(BGP_IPV4_NODE, &af_no_route_map_vpn_imexport_cmd);
14053 install_element(BGP_IPV6_NODE, &af_no_route_map_vpn_imexport_cmd);
14054 install_element(BGP_IPV4_NODE, &af_no_import_vrf_route_map_cmd);
14055 install_element(BGP_IPV6_NODE, &af_no_import_vrf_route_map_cmd);
14056 }
14057
14058 #include "memory.h"
14059 #include "bgp_regex.h"
14060 #include "bgp_clist.h"
14061 #include "bgp_ecommunity.h"
14062
14063 /* VTY functions. */
14064
14065 /* Direction value to string conversion. */
14066 static const char *community_direct_str(int direct)
14067 {
14068 switch (direct) {
14069 case COMMUNITY_DENY:
14070 return "deny";
14071 case COMMUNITY_PERMIT:
14072 return "permit";
14073 default:
14074 return "unknown";
14075 }
14076 }
14077
14078 /* Display error string. */
14079 static void community_list_perror(struct vty *vty, int ret)
14080 {
14081 switch (ret) {
14082 case COMMUNITY_LIST_ERR_CANT_FIND_LIST:
14083 vty_out(vty, "%% Can't find community-list\n");
14084 break;
14085 case COMMUNITY_LIST_ERR_MALFORMED_VAL:
14086 vty_out(vty, "%% Malformed community-list value\n");
14087 break;
14088 case COMMUNITY_LIST_ERR_STANDARD_CONFLICT:
14089 vty_out(vty,
14090 "%% Community name conflict, previously defined as standard community\n");
14091 break;
14092 case COMMUNITY_LIST_ERR_EXPANDED_CONFLICT:
14093 vty_out(vty,
14094 "%% Community name conflict, previously defined as expanded community\n");
14095 break;
14096 }
14097 }
14098
14099 /* "community-list" keyword help string. */
14100 #define COMMUNITY_LIST_STR "Add a community list entry\n"
14101
14102 /*community-list standard */
14103 DEFUN (community_list_standard,
14104 bgp_community_list_standard_cmd,
14105 "bgp community-list <(1-99)|standard WORD> <deny|permit> AA:NN...",
14106 BGP_STR
14107 COMMUNITY_LIST_STR
14108 "Community list number (standard)\n"
14109 "Add an standard community-list entry\n"
14110 "Community list name\n"
14111 "Specify community to reject\n"
14112 "Specify community to accept\n"
14113 COMMUNITY_VAL_STR)
14114 {
14115 char *cl_name_or_number = NULL;
14116 int direct = 0;
14117 int style = COMMUNITY_LIST_STANDARD;
14118
14119 int idx = 0;
14120
14121 if (argv_find(argv, argc, "ip", &idx)) {
14122 vty_out(vty, "This config option is deprecated, and is scheduled for removal.\n");
14123 vty_out(vty, "if you are using this please migrate to the below command.\n");
14124 vty_out(vty, "'bgp community-list <(1-99)|(100-500)|standard|expanded> <deny|permit> AA:NN'\n");
14125 zlog_warn("Deprecated option: 'ip community-list <(1-99)|(100-500)|standard|expanded> <deny|permit> AA:NN' being used");
14126 }
14127
14128 argv_find(argv, argc, "(1-99)", &idx);
14129 argv_find(argv, argc, "WORD", &idx);
14130 cl_name_or_number = argv[idx]->arg;
14131 direct = argv_find(argv, argc, "permit", &idx) ? COMMUNITY_PERMIT
14132 : COMMUNITY_DENY;
14133 argv_find(argv, argc, "AA:NN", &idx);
14134 char *str = argv_concat(argv, argc, idx);
14135
14136 int ret = community_list_set(bgp_clist, cl_name_or_number, str, direct,
14137 style);
14138
14139 XFREE(MTYPE_TMP, str);
14140
14141 if (ret < 0) {
14142 /* Display error string. */
14143 community_list_perror(vty, ret);
14144 return CMD_WARNING_CONFIG_FAILED;
14145 }
14146
14147 return CMD_SUCCESS;
14148 }
14149
14150 #if CONFDATE > 20191005
14151 CPP_NOTICE("bgpd: remove deprecated 'ip community-list <(1-99)|(100-500)|standard|expanded> <deny|permit> AA:NN' command")
14152 #endif
14153 ALIAS (community_list_standard,
14154 ip_community_list_standard_cmd,
14155 "ip community-list <(1-99)|standard WORD> <deny|permit> AA:NN...",
14156 IP_STR
14157 COMMUNITY_LIST_STR
14158 "Community list number (standard)\n"
14159 "Add an standard community-list entry\n"
14160 "Community list name\n"
14161 "Specify community to reject\n"
14162 "Specify community to accept\n"
14163 COMMUNITY_VAL_STR)
14164
14165 DEFUN (no_community_list_standard_all,
14166 no_bgp_community_list_standard_all_cmd,
14167 "no bgp community-list <(1-99)|standard WORD> <deny|permit> AA:NN...",
14168 NO_STR
14169 BGP_STR
14170 COMMUNITY_LIST_STR
14171 "Community list number (standard)\n"
14172 "Add an standard community-list entry\n"
14173 "Community list name\n"
14174 "Specify community to reject\n"
14175 "Specify community to accept\n"
14176 COMMUNITY_VAL_STR)
14177 {
14178 char *cl_name_or_number = NULL;
14179 char *str = NULL;
14180 int direct = 0;
14181 int style = COMMUNITY_LIST_STANDARD;
14182
14183 int idx = 0;
14184
14185 if (argv_find(argv, argc, "ip", &idx)) {
14186 vty_out(vty, "This config option is deprecated, and is scheduled for removal\n");
14187 vty_out(vty, "if you are using this please migrate to the below command.\n");
14188 vty_out(vty, "'no bgp community-list <(1-99)|(100-500)|standard|expanded> <deny|permit> AA:NN'\n");
14189 zlog_warn("Deprecated option: 'no ip community-list <(1-99)|(100-500)|standard|expanded> <deny|permit> |AA:NN' being used");
14190 }
14191
14192 argv_find(argv, argc, "permit", &idx);
14193 argv_find(argv, argc, "deny", &idx);
14194
14195 if (idx) {
14196 direct = argv_find(argv, argc, "permit", &idx)
14197 ? COMMUNITY_PERMIT
14198 : COMMUNITY_DENY;
14199
14200 idx = 0;
14201 argv_find(argv, argc, "AA:NN", &idx);
14202 str = argv_concat(argv, argc, idx);
14203 }
14204
14205 idx = 0;
14206 argv_find(argv, argc, "(1-99)", &idx);
14207 argv_find(argv, argc, "WORD", &idx);
14208 cl_name_or_number = argv[idx]->arg;
14209
14210 int ret = community_list_unset(bgp_clist, cl_name_or_number, str,
14211 direct, style);
14212
14213 XFREE(MTYPE_TMP, str);
14214
14215 if (ret < 0) {
14216 community_list_perror(vty, ret);
14217 return CMD_WARNING_CONFIG_FAILED;
14218 }
14219
14220 return CMD_SUCCESS;
14221 }
14222 ALIAS (no_community_list_standard_all,
14223 no_ip_community_list_standard_all_cmd,
14224 "no ip community-list <(1-99)|standard WORD> <deny|permit> AA:NN...",
14225 NO_STR
14226 IP_STR
14227 COMMUNITY_LIST_STR
14228 "Community list number (standard)\n"
14229 "Add an standard community-list entry\n"
14230 "Community list name\n"
14231 "Specify community to reject\n"
14232 "Specify community to accept\n"
14233 COMMUNITY_VAL_STR)
14234
14235 ALIAS(no_community_list_standard_all, no_bgp_community_list_standard_all_list_cmd,
14236 "no bgp community-list <(1-99)|standard WORD>",
14237 NO_STR BGP_STR COMMUNITY_LIST_STR
14238 "Community list number (standard)\n"
14239 "Add an standard community-list entry\n"
14240 "Community list name\n")
14241
14242 ALIAS(no_community_list_standard_all, no_ip_community_list_standard_all_list_cmd,
14243 "no ip community-list <(1-99)|standard WORD>",
14244 NO_STR BGP_STR COMMUNITY_LIST_STR
14245 "Community list number (standard)\n"
14246 "Add an standard community-list entry\n"
14247 "Community list name\n")
14248
14249 /*community-list expanded */
14250 DEFUN (community_list_expanded_all,
14251 bgp_community_list_expanded_all_cmd,
14252 "bgp community-list <(100-500)|expanded WORD> <deny|permit> AA:NN...",
14253 BGP_STR
14254 COMMUNITY_LIST_STR
14255 "Community list number (expanded)\n"
14256 "Add an expanded community-list entry\n"
14257 "Community list name\n"
14258 "Specify community to reject\n"
14259 "Specify community to accept\n"
14260 COMMUNITY_VAL_STR)
14261 {
14262 char *cl_name_or_number = NULL;
14263 int direct = 0;
14264 int style = COMMUNITY_LIST_EXPANDED;
14265
14266 int idx = 0;
14267 if (argv_find(argv, argc, "ip", &idx)) {
14268 vty_out(vty, "This config option is deprecated, and is scheduled for removal.\n");
14269 vty_out(vty, "if you are using this please migrate to the below command.\n");
14270 vty_out(vty, "'bgp community-list <(1-99)|(100-500)|standard|expanded> <deny|permit> AA:NN'\n");
14271 zlog_warn("Deprecated option: 'ip community-list <(1-99)|(100-500)|standard|expanded> <deny|permit> AA:NN' being used");
14272 }
14273 argv_find(argv, argc, "(100-500)", &idx);
14274 argv_find(argv, argc, "WORD", &idx);
14275 cl_name_or_number = argv[idx]->arg;
14276 direct = argv_find(argv, argc, "permit", &idx) ? COMMUNITY_PERMIT
14277 : COMMUNITY_DENY;
14278 argv_find(argv, argc, "AA:NN", &idx);
14279 char *str = argv_concat(argv, argc, idx);
14280
14281 int ret = community_list_set(bgp_clist, cl_name_or_number, str, direct,
14282 style);
14283
14284 XFREE(MTYPE_TMP, str);
14285
14286 if (ret < 0) {
14287 /* Display error string. */
14288 community_list_perror(vty, ret);
14289 return CMD_WARNING_CONFIG_FAILED;
14290 }
14291
14292 return CMD_SUCCESS;
14293 }
14294
14295 ALIAS (community_list_expanded_all,
14296 ip_community_list_expanded_all_cmd,
14297 "ip community-list <(100-500)|expanded WORD> <deny|permit> AA:NN...",
14298 IP_STR
14299 COMMUNITY_LIST_STR
14300 "Community list number (expanded)\n"
14301 "Add an expanded community-list entry\n"
14302 "Community list name\n"
14303 "Specify community to reject\n"
14304 "Specify community to accept\n"
14305 COMMUNITY_VAL_STR)
14306
14307 DEFUN (no_community_list_expanded_all,
14308 no_bgp_community_list_expanded_all_cmd,
14309 "no bgp community-list <(100-500)|expanded WORD> <deny|permit> AA:NN...",
14310 NO_STR
14311 BGP_STR
14312 COMMUNITY_LIST_STR
14313 "Community list number (expanded)\n"
14314 "Add an expanded community-list entry\n"
14315 "Community list name\n"
14316 "Specify community to reject\n"
14317 "Specify community to accept\n"
14318 COMMUNITY_VAL_STR)
14319 {
14320 char *cl_name_or_number = NULL;
14321 char *str = NULL;
14322 int direct = 0;
14323 int style = COMMUNITY_LIST_EXPANDED;
14324
14325 int idx = 0;
14326 if (argv_find(argv, argc, "ip", &idx)) {
14327 vty_out(vty, "This config option is deprecated, and is scheduled for removal.\n");
14328 vty_out(vty, "if you are using this please migrate to the below command.\n");
14329 vty_out(vty, "'no bgp community-list <(1-99)|(100-500)|standard|expanded> <deny|permit> AA:NN'\n");
14330 zlog_warn("Deprecated option: 'no ip community-list <(1-99)|(100-500)|standard|expanded> <deny|permit> AA:NN' being used");
14331 }
14332
14333 idx = 0;
14334 argv_find(argv, argc, "permit", &idx);
14335 argv_find(argv, argc, "deny", &idx);
14336
14337 if (idx) {
14338 direct = argv_find(argv, argc, "permit", &idx)
14339 ? COMMUNITY_PERMIT
14340 : COMMUNITY_DENY;
14341
14342 idx = 0;
14343 argv_find(argv, argc, "AA:NN", &idx);
14344 str = argv_concat(argv, argc, idx);
14345 }
14346
14347 idx = 0;
14348 argv_find(argv, argc, "(100-500)", &idx);
14349 argv_find(argv, argc, "WORD", &idx);
14350 cl_name_or_number = argv[idx]->arg;
14351
14352 int ret = community_list_unset(bgp_clist, cl_name_or_number, str,
14353 direct, style);
14354
14355 XFREE(MTYPE_TMP, str);
14356
14357 if (ret < 0) {
14358 community_list_perror(vty, ret);
14359 return CMD_WARNING_CONFIG_FAILED;
14360 }
14361
14362 return CMD_SUCCESS;
14363 }
14364
14365 ALIAS (no_community_list_expanded_all,
14366 no_ip_community_list_expanded_all_cmd,
14367 "no ip community-list <(100-500)|expanded WORD> <deny|permit> AA:NN...",
14368 NO_STR
14369 IP_STR
14370 COMMUNITY_LIST_STR
14371 "Community list number (expanded)\n"
14372 "Add an expanded community-list entry\n"
14373 "Community list name\n"
14374 "Specify community to reject\n"
14375 "Specify community to accept\n"
14376 COMMUNITY_VAL_STR)
14377
14378 ALIAS(no_community_list_expanded_all, no_bgp_community_list_expanded_all_list_cmd,
14379 "no bgp community-list <(100-500)|expanded WORD>",
14380 NO_STR IP_STR COMMUNITY_LIST_STR
14381 "Community list number (expanded)\n"
14382 "Add an expanded community-list entry\n"
14383 "Community list name\n")
14384
14385 ALIAS(no_community_list_expanded_all, no_ip_community_list_expanded_all_list_cmd,
14386 "no ip community-list <(100-500)|expanded WORD>",
14387 NO_STR IP_STR COMMUNITY_LIST_STR
14388 "Community list number (expanded)\n"
14389 "Add an expanded community-list entry\n"
14390 "Community list name\n")
14391
14392 /* Return configuration string of community-list entry. */
14393 static const char *community_list_config_str(struct community_entry *entry)
14394 {
14395 const char *str;
14396
14397 if (entry->any)
14398 str = "";
14399 else {
14400 if (entry->style == COMMUNITY_LIST_STANDARD)
14401 str = community_str(entry->u.com, false);
14402 else if (entry->style == LARGE_COMMUNITY_LIST_STANDARD)
14403 str = lcommunity_str(entry->u.lcom, false);
14404 else
14405 str = entry->config;
14406 }
14407 return str;
14408 }
14409
14410 static void community_list_show(struct vty *vty, struct community_list *list)
14411 {
14412 struct community_entry *entry;
14413
14414 for (entry = list->head; entry; entry = entry->next) {
14415 if (entry == list->head) {
14416 if (all_digit(list->name))
14417 vty_out(vty, "Community %s list %s\n",
14418 entry->style == COMMUNITY_LIST_STANDARD
14419 ? "standard"
14420 : "(expanded) access",
14421 list->name);
14422 else
14423 vty_out(vty, "Named Community %s list %s\n",
14424 entry->style == COMMUNITY_LIST_STANDARD
14425 ? "standard"
14426 : "expanded",
14427 list->name);
14428 }
14429 if (entry->any)
14430 vty_out(vty, " %s\n",
14431 community_direct_str(entry->direct));
14432 else
14433 vty_out(vty, " %s %s\n",
14434 community_direct_str(entry->direct),
14435 community_list_config_str(entry));
14436 }
14437 }
14438
14439 DEFUN (show_community_list,
14440 show_bgp_community_list_cmd,
14441 "show bgp community-list",
14442 SHOW_STR
14443 BGP_STR
14444 "List community-list\n")
14445 {
14446 struct community_list *list;
14447 struct community_list_master *cm;
14448
14449 int idx = 0;
14450 if (argv_find(argv, argc, "ip", &idx)) {
14451 vty_out(vty, "This config option is deprecated, and is scheduled for removal.\n");
14452 vty_out(vty, "if you are using this please migrate to the below command.\n");
14453 vty_out(vty, "'show bgp community-list <(1-500)|WORD>'\n");
14454 zlog_warn("Deprecated option: 'ip show community-list <(1-500)|WORD>' being used");
14455 }
14456 cm = community_list_master_lookup(bgp_clist, COMMUNITY_LIST_MASTER);
14457 if (!cm)
14458 return CMD_SUCCESS;
14459
14460 for (list = cm->num.head; list; list = list->next)
14461 community_list_show(vty, list);
14462
14463 for (list = cm->str.head; list; list = list->next)
14464 community_list_show(vty, list);
14465
14466 return CMD_SUCCESS;
14467 }
14468
14469 ALIAS (show_community_list,
14470 show_ip_community_list_cmd,
14471 "show ip community-list",
14472 SHOW_STR
14473 IP_STR
14474 "List community-list\n")
14475
14476 DEFUN (show_community_list_arg,
14477 show_bgp_community_list_arg_cmd,
14478 "show bgp community-list <(1-500)|WORD>",
14479 SHOW_STR
14480 BGP_STR
14481 "List community-list\n"
14482 "Community-list number\n"
14483 "Community-list name\n")
14484 {
14485 int idx_comm_list = 3;
14486 struct community_list *list;
14487
14488 int idx = 0;
14489 if (argv_find(argv, argc, "ip", &idx)) {
14490 vty_out(vty, "This config option is deprecated, and is scheduled for removal.\n");
14491 vty_out(vty, "if you are using this please migrate to the below command.\n");
14492 vty_out(vty, "'show bgp community-list <(1-500)|WORD>'\n");
14493 zlog_warn("Deprecated option: 'ip show community-list <(1-500)|WORD>' being used");
14494 }
14495 list = community_list_lookup(bgp_clist, argv[idx_comm_list]->arg, 0,
14496 COMMUNITY_LIST_MASTER);
14497 if (!list) {
14498 vty_out(vty, "%% Can't find community-list\n");
14499 return CMD_WARNING;
14500 }
14501
14502 community_list_show(vty, list);
14503
14504 return CMD_SUCCESS;
14505 }
14506
14507 ALIAS (show_community_list_arg,
14508 show_ip_community_list_arg_cmd,
14509 "show ip community-list <(1-500)|WORD>",
14510 SHOW_STR
14511 IP_STR
14512 "List community-list\n"
14513 "Community-list number\n"
14514 "Community-list name\n")
14515
14516 /*
14517 * Large Community code.
14518 */
14519 static int lcommunity_list_set_vty(struct vty *vty, int argc,
14520 struct cmd_token **argv, int style,
14521 int reject_all_digit_name)
14522 {
14523 int ret;
14524 int direct;
14525 char *str;
14526 int idx = 0;
14527 char *cl_name;
14528
14529 if (argv_find(argv, argc, "ip", &idx)) {
14530 vty_out(vty, "This config option is deprecated, and is scheduled for removal.\n");
14531 vty_out(vty, "if you are using this please migrate to the below command.\n");
14532 vty_out(vty, "'bgp large-community-list <(1-99)|(100-500)|standard|expanded> <deny|permit> <LINE|AA:BB:CC>'\n");
14533 zlog_warn("Deprecated option: 'large-community-list <(1-99)|(100-500)|standard|expanded> <deny|permit> <LINE|AA:BB:CC>' being used");
14534 }
14535 direct = argv_find(argv, argc, "permit", &idx) ? COMMUNITY_PERMIT
14536 : COMMUNITY_DENY;
14537
14538 /* All digit name check. */
14539 idx = 0;
14540 argv_find(argv, argc, "WORD", &idx);
14541 argv_find(argv, argc, "(1-99)", &idx);
14542 argv_find(argv, argc, "(100-500)", &idx);
14543 cl_name = argv[idx]->arg;
14544 if (reject_all_digit_name && all_digit(cl_name)) {
14545 vty_out(vty, "%% Community name cannot have all digits\n");
14546 return CMD_WARNING_CONFIG_FAILED;
14547 }
14548
14549 idx = 0;
14550 argv_find(argv, argc, "AA:BB:CC", &idx);
14551 argv_find(argv, argc, "LINE", &idx);
14552 /* Concat community string argument. */
14553 if (idx)
14554 str = argv_concat(argv, argc, idx);
14555 else
14556 str = NULL;
14557
14558 ret = lcommunity_list_set(bgp_clist, cl_name, str, direct, style);
14559
14560 /* Free temporary community list string allocated by
14561 argv_concat(). */
14562 XFREE(MTYPE_TMP, str);
14563
14564 if (ret < 0) {
14565 community_list_perror(vty, ret);
14566 return CMD_WARNING_CONFIG_FAILED;
14567 }
14568 return CMD_SUCCESS;
14569 }
14570
14571 static int lcommunity_list_unset_vty(struct vty *vty, int argc,
14572 struct cmd_token **argv, int style)
14573 {
14574 int ret;
14575 int direct = 0;
14576 char *str = NULL;
14577 int idx = 0;
14578
14579 if (argv_find(argv, argc, "ip", &idx)) {
14580 vty_out(vty, "This config option is deprecated, and is scheduled for removal.\n");
14581 vty_out(vty, "if you are using this please migrate to the below command.\n");
14582 vty_out(vty, "'no bgp large-community-list <(1-99)|(100-500)|standard|expanded> <deny|permit> <LINE|AA:BB:CC>'\n");
14583 zlog_warn("Deprecated option: 'no ip large-community-list <(1-99)|(100-500)|standard|expanded> <deny|permit> <LINE|AA:BB:CC>' being used");
14584 }
14585 argv_find(argv, argc, "permit", &idx);
14586 argv_find(argv, argc, "deny", &idx);
14587
14588 if (idx) {
14589 /* Check the list direct. */
14590 if (strncmp(argv[idx]->arg, "p", 1) == 0)
14591 direct = COMMUNITY_PERMIT;
14592 else
14593 direct = COMMUNITY_DENY;
14594
14595 idx = 0;
14596 argv_find(argv, argc, "LINE", &idx);
14597 argv_find(argv, argc, "AA:AA:NN", &idx);
14598 /* Concat community string argument. */
14599 str = argv_concat(argv, argc, idx);
14600 }
14601
14602 idx = 0;
14603 argv_find(argv, argc, "(1-99)", &idx);
14604 argv_find(argv, argc, "(100-500)", &idx);
14605 argv_find(argv, argc, "WORD", &idx);
14606
14607 /* Unset community list. */
14608 ret = lcommunity_list_unset(bgp_clist, argv[idx]->arg, str, direct,
14609 style);
14610
14611 /* Free temporary community list string allocated by
14612 argv_concat(). */
14613 XFREE(MTYPE_TMP, str);
14614
14615 if (ret < 0) {
14616 community_list_perror(vty, ret);
14617 return CMD_WARNING_CONFIG_FAILED;
14618 }
14619
14620 return CMD_SUCCESS;
14621 }
14622
14623 /* "large-community-list" keyword help string. */
14624 #define LCOMMUNITY_LIST_STR "Add a large community list entry\n"
14625 #define LCOMMUNITY_VAL_STR "large community in 'aa:bb:cc' format\n"
14626
14627 #if CONFDATE > 20191005
14628 CPP_NOTICE("bgpd: remove deprecated 'ip large-community-list <(1-99)|(100-500)|standard|expanded> <deny|permit> <LINE|AA:BB:CC>' command")
14629 #endif
14630 DEFUN (lcommunity_list_standard,
14631 bgp_lcommunity_list_standard_cmd,
14632 "bgp large-community-list (1-99) <deny|permit>",
14633 BGP_STR
14634 LCOMMUNITY_LIST_STR
14635 "Large Community list number (standard)\n"
14636 "Specify large community to reject\n"
14637 "Specify large community to accept\n")
14638 {
14639 return lcommunity_list_set_vty(vty, argc, argv,
14640 LARGE_COMMUNITY_LIST_STANDARD, 0);
14641 }
14642
14643 ALIAS (lcommunity_list_standard,
14644 ip_lcommunity_list_standard_cmd,
14645 "ip large-community-list (1-99) <deny|permit>",
14646 IP_STR
14647 LCOMMUNITY_LIST_STR
14648 "Large Community list number (standard)\n"
14649 "Specify large community to reject\n"
14650 "Specify large community to accept\n")
14651
14652 DEFUN (lcommunity_list_standard1,
14653 bgp_lcommunity_list_standard1_cmd,
14654 "bgp large-community-list (1-99) <deny|permit> AA:BB:CC...",
14655 BGP_STR
14656 LCOMMUNITY_LIST_STR
14657 "Large Community list number (standard)\n"
14658 "Specify large community to reject\n"
14659 "Specify large community to accept\n"
14660 LCOMMUNITY_VAL_STR)
14661 {
14662 return lcommunity_list_set_vty(vty, argc, argv,
14663 LARGE_COMMUNITY_LIST_STANDARD, 0);
14664 }
14665
14666 ALIAS (lcommunity_list_standard1,
14667 ip_lcommunity_list_standard1_cmd,
14668 "ip large-community-list (1-99) <deny|permit> AA:BB:CC...",
14669 IP_STR
14670 LCOMMUNITY_LIST_STR
14671 "Large Community list number (standard)\n"
14672 "Specify large community to reject\n"
14673 "Specify large community to accept\n"
14674 LCOMMUNITY_VAL_STR)
14675
14676 DEFUN (lcommunity_list_expanded,
14677 bgp_lcommunity_list_expanded_cmd,
14678 "bgp large-community-list (100-500) <deny|permit> LINE...",
14679 BGP_STR
14680 LCOMMUNITY_LIST_STR
14681 "Large Community list number (expanded)\n"
14682 "Specify large community to reject\n"
14683 "Specify large community to accept\n"
14684 "An ordered list as a regular-expression\n")
14685 {
14686 return lcommunity_list_set_vty(vty, argc, argv,
14687 LARGE_COMMUNITY_LIST_EXPANDED, 0);
14688 }
14689
14690 ALIAS (lcommunity_list_expanded,
14691 ip_lcommunity_list_expanded_cmd,
14692 "ip large-community-list (100-500) <deny|permit> LINE...",
14693 IP_STR
14694 LCOMMUNITY_LIST_STR
14695 "Large Community list number (expanded)\n"
14696 "Specify large community to reject\n"
14697 "Specify large community to accept\n"
14698 "An ordered list as a regular-expression\n")
14699
14700 DEFUN (lcommunity_list_name_standard,
14701 bgp_lcommunity_list_name_standard_cmd,
14702 "bgp large-community-list standard WORD <deny|permit>",
14703 BGP_STR
14704 LCOMMUNITY_LIST_STR
14705 "Specify standard large-community-list\n"
14706 "Large Community list name\n"
14707 "Specify large community to reject\n"
14708 "Specify large community to accept\n")
14709 {
14710 return lcommunity_list_set_vty(vty, argc, argv,
14711 LARGE_COMMUNITY_LIST_STANDARD, 1);
14712 }
14713
14714 ALIAS (lcommunity_list_name_standard,
14715 ip_lcommunity_list_name_standard_cmd,
14716 "ip large-community-list standard WORD <deny|permit>",
14717 IP_STR
14718 LCOMMUNITY_LIST_STR
14719 "Specify standard large-community-list\n"
14720 "Large Community list name\n"
14721 "Specify large community to reject\n"
14722 "Specify large community to accept\n")
14723
14724 DEFUN (lcommunity_list_name_standard1,
14725 bgp_lcommunity_list_name_standard1_cmd,
14726 "bgp large-community-list standard WORD <deny|permit> AA:BB:CC...",
14727 BGP_STR
14728 LCOMMUNITY_LIST_STR
14729 "Specify standard large-community-list\n"
14730 "Large Community list name\n"
14731 "Specify large community to reject\n"
14732 "Specify large community to accept\n"
14733 LCOMMUNITY_VAL_STR)
14734 {
14735 return lcommunity_list_set_vty(vty, argc, argv,
14736 LARGE_COMMUNITY_LIST_STANDARD, 1);
14737 }
14738
14739 ALIAS (lcommunity_list_name_standard1,
14740 ip_lcommunity_list_name_standard1_cmd,
14741 "ip large-community-list standard WORD <deny|permit> AA:BB:CC...",
14742 IP_STR
14743 LCOMMUNITY_LIST_STR
14744 "Specify standard large-community-list\n"
14745 "Large Community list name\n"
14746 "Specify large community to reject\n"
14747 "Specify large community to accept\n"
14748 LCOMMUNITY_VAL_STR)
14749
14750 DEFUN (lcommunity_list_name_expanded,
14751 bgp_lcommunity_list_name_expanded_cmd,
14752 "bgp large-community-list expanded WORD <deny|permit> LINE...",
14753 BGP_STR
14754 LCOMMUNITY_LIST_STR
14755 "Specify expanded large-community-list\n"
14756 "Large Community list name\n"
14757 "Specify large community to reject\n"
14758 "Specify large community to accept\n"
14759 "An ordered list as a regular-expression\n")
14760 {
14761 return lcommunity_list_set_vty(vty, argc, argv,
14762 LARGE_COMMUNITY_LIST_EXPANDED, 1);
14763 }
14764
14765 ALIAS (lcommunity_list_name_expanded,
14766 ip_lcommunity_list_name_expanded_cmd,
14767 "ip large-community-list expanded WORD <deny|permit> LINE...",
14768 IP_STR
14769 LCOMMUNITY_LIST_STR
14770 "Specify expanded large-community-list\n"
14771 "Large Community list name\n"
14772 "Specify large community to reject\n"
14773 "Specify large community to accept\n"
14774 "An ordered list as a regular-expression\n")
14775
14776 DEFUN (no_lcommunity_list_standard_all,
14777 no_bgp_lcommunity_list_standard_all_cmd,
14778 "no bgp large-community-list <(1-99)|(100-500)|WORD>",
14779 NO_STR
14780 BGP_STR
14781 LCOMMUNITY_LIST_STR
14782 "Large Community list number (standard)\n"
14783 "Large Community list number (expanded)\n"
14784 "Large Community list name\n")
14785 {
14786 return lcommunity_list_unset_vty(vty, argc, argv,
14787 LARGE_COMMUNITY_LIST_STANDARD);
14788 }
14789
14790 ALIAS (no_lcommunity_list_standard_all,
14791 no_ip_lcommunity_list_standard_all_cmd,
14792 "no ip large-community-list <(1-99)|(100-500)|WORD>",
14793 NO_STR
14794 IP_STR
14795 LCOMMUNITY_LIST_STR
14796 "Large Community list number (standard)\n"
14797 "Large Community list number (expanded)\n"
14798 "Large Community list name\n")
14799
14800 DEFUN (no_lcommunity_list_name_expanded_all,
14801 no_bgp_lcommunity_list_name_expanded_all_cmd,
14802 "no bgp large-community-list expanded WORD",
14803 NO_STR
14804 BGP_STR
14805 LCOMMUNITY_LIST_STR
14806 "Specify expanded large-community-list\n"
14807 "Large Community list name\n")
14808 {
14809 return lcommunity_list_unset_vty(vty, argc, argv,
14810 LARGE_COMMUNITY_LIST_EXPANDED);
14811 }
14812
14813 ALIAS (no_lcommunity_list_name_expanded_all,
14814 no_ip_lcommunity_list_name_expanded_all_cmd,
14815 "no ip large-community-list expanded WORD",
14816 NO_STR
14817 IP_STR
14818 LCOMMUNITY_LIST_STR
14819 "Specify expanded large-community-list\n"
14820 "Large Community list name\n")
14821
14822 DEFUN (no_lcommunity_list_standard,
14823 no_bgp_lcommunity_list_standard_cmd,
14824 "no bgp large-community-list (1-99) <deny|permit> AA:AA:NN...",
14825 NO_STR
14826 BGP_STR
14827 LCOMMUNITY_LIST_STR
14828 "Large Community list number (standard)\n"
14829 "Specify large community to reject\n"
14830 "Specify large community to accept\n"
14831 LCOMMUNITY_VAL_STR)
14832 {
14833 return lcommunity_list_unset_vty(vty, argc, argv,
14834 LARGE_COMMUNITY_LIST_STANDARD);
14835 }
14836
14837 ALIAS (no_lcommunity_list_standard,
14838 no_ip_lcommunity_list_standard_cmd,
14839 "no ip large-community-list (1-99) <deny|permit> AA:AA:NN...",
14840 NO_STR
14841 IP_STR
14842 LCOMMUNITY_LIST_STR
14843 "Large Community list number (standard)\n"
14844 "Specify large community to reject\n"
14845 "Specify large community to accept\n"
14846 LCOMMUNITY_VAL_STR)
14847
14848 DEFUN (no_lcommunity_list_expanded,
14849 no_bgp_lcommunity_list_expanded_cmd,
14850 "no bgp large-community-list (100-500) <deny|permit> LINE...",
14851 NO_STR
14852 BGP_STR
14853 LCOMMUNITY_LIST_STR
14854 "Large Community list number (expanded)\n"
14855 "Specify large community to reject\n"
14856 "Specify large community to accept\n"
14857 "An ordered list as a regular-expression\n")
14858 {
14859 return lcommunity_list_unset_vty(vty, argc, argv,
14860 LARGE_COMMUNITY_LIST_EXPANDED);
14861 }
14862
14863 ALIAS (no_lcommunity_list_expanded,
14864 no_ip_lcommunity_list_expanded_cmd,
14865 "no ip large-community-list (100-500) <deny|permit> LINE...",
14866 NO_STR
14867 IP_STR
14868 LCOMMUNITY_LIST_STR
14869 "Large Community list number (expanded)\n"
14870 "Specify large community to reject\n"
14871 "Specify large community to accept\n"
14872 "An ordered list as a regular-expression\n")
14873
14874 DEFUN (no_lcommunity_list_name_standard,
14875 no_bgp_lcommunity_list_name_standard_cmd,
14876 "no bgp large-community-list standard WORD <deny|permit> AA:AA:NN...",
14877 NO_STR
14878 BGP_STR
14879 LCOMMUNITY_LIST_STR
14880 "Specify standard large-community-list\n"
14881 "Large Community list name\n"
14882 "Specify large community to reject\n"
14883 "Specify large community to accept\n"
14884 LCOMMUNITY_VAL_STR)
14885 {
14886 return lcommunity_list_unset_vty(vty, argc, argv,
14887 LARGE_COMMUNITY_LIST_STANDARD);
14888 }
14889
14890 ALIAS (no_lcommunity_list_name_standard,
14891 no_ip_lcommunity_list_name_standard_cmd,
14892 "no ip large-community-list standard WORD <deny|permit> AA:AA:NN...",
14893 NO_STR
14894 IP_STR
14895 LCOMMUNITY_LIST_STR
14896 "Specify standard large-community-list\n"
14897 "Large Community list name\n"
14898 "Specify large community to reject\n"
14899 "Specify large community to accept\n"
14900 LCOMMUNITY_VAL_STR)
14901
14902 DEFUN (no_lcommunity_list_name_expanded,
14903 no_bgp_lcommunity_list_name_expanded_cmd,
14904 "no bgp large-community-list expanded WORD <deny|permit> LINE...",
14905 NO_STR
14906 BGP_STR
14907 LCOMMUNITY_LIST_STR
14908 "Specify expanded large-community-list\n"
14909 "Large community list name\n"
14910 "Specify large community to reject\n"
14911 "Specify large community to accept\n"
14912 "An ordered list as a regular-expression\n")
14913 {
14914 return lcommunity_list_unset_vty(vty, argc, argv,
14915 LARGE_COMMUNITY_LIST_EXPANDED);
14916 }
14917
14918 ALIAS (no_lcommunity_list_name_expanded,
14919 no_ip_lcommunity_list_name_expanded_cmd,
14920 "no ip large-community-list expanded WORD <deny|permit> LINE...",
14921 NO_STR
14922 IP_STR
14923 LCOMMUNITY_LIST_STR
14924 "Specify expanded large-community-list\n"
14925 "Large community list name\n"
14926 "Specify large community to reject\n"
14927 "Specify large community to accept\n"
14928 "An ordered list as a regular-expression\n")
14929
14930 static void lcommunity_list_show(struct vty *vty, struct community_list *list)
14931 {
14932 struct community_entry *entry;
14933
14934 for (entry = list->head; entry; entry = entry->next) {
14935 if (entry == list->head) {
14936 if (all_digit(list->name))
14937 vty_out(vty, "Large community %s list %s\n",
14938 entry->style == EXTCOMMUNITY_LIST_STANDARD
14939 ? "standard"
14940 : "(expanded) access",
14941 list->name);
14942 else
14943 vty_out(vty,
14944 "Named large community %s list %s\n",
14945 entry->style == EXTCOMMUNITY_LIST_STANDARD
14946 ? "standard"
14947 : "expanded",
14948 list->name);
14949 }
14950 if (entry->any)
14951 vty_out(vty, " %s\n",
14952 community_direct_str(entry->direct));
14953 else
14954 vty_out(vty, " %s %s\n",
14955 community_direct_str(entry->direct),
14956 community_list_config_str(entry));
14957 }
14958 }
14959
14960 DEFUN (show_lcommunity_list,
14961 show_bgp_lcommunity_list_cmd,
14962 "show bgp large-community-list",
14963 SHOW_STR
14964 BGP_STR
14965 "List large-community list\n")
14966 {
14967 struct community_list *list;
14968 struct community_list_master *cm;
14969 int idx = 0;
14970
14971 if (argv_find(argv, argc, "ip", &idx)) {
14972 vty_out(vty, "This config option is deprecated, and is scheduled for removal.\n");
14973 vty_out(vty, "if you are using this please migrate to the below command.\n");
14974 vty_out(vty, "'show bgp large-community-list <(1-500)|WORD>'\n");
14975 zlog_warn("Deprecated option: 'ip show large-community-list <(1-500)|WORD>' being used");
14976 }
14977
14978 cm = community_list_master_lookup(bgp_clist,
14979 LARGE_COMMUNITY_LIST_MASTER);
14980 if (!cm)
14981 return CMD_SUCCESS;
14982
14983 for (list = cm->num.head; list; list = list->next)
14984 lcommunity_list_show(vty, list);
14985
14986 for (list = cm->str.head; list; list = list->next)
14987 lcommunity_list_show(vty, list);
14988
14989 return CMD_SUCCESS;
14990 }
14991
14992 ALIAS (show_lcommunity_list,
14993 show_ip_lcommunity_list_cmd,
14994 "show ip large-community-list",
14995 SHOW_STR
14996 IP_STR
14997 "List large-community list\n")
14998
14999 DEFUN (show_lcommunity_list_arg,
15000 show_bgp_lcommunity_list_arg_cmd,
15001 "show bgp large-community-list <(1-500)|WORD>",
15002 SHOW_STR
15003 BGP_STR
15004 "List large-community list\n"
15005 "large-community-list number\n"
15006 "large-community-list name\n")
15007 {
15008 struct community_list *list;
15009 int idx = 0;
15010
15011 if (argv_find(argv, argc, "ip", &idx)) {
15012 vty_out(vty, "This config option is deprecated, and is scheduled for removal.\n");
15013 vty_out(vty, "if you are using this please migrate to the below command.\n");
15014 vty_out(vty, "'show bgp large-community-list <(1-500)|WORD>'\n");
15015 zlog_warn("Deprecated option: 'ip show large-community-list <(1-500)|WORD>' being used");
15016 }
15017
15018 list = community_list_lookup(bgp_clist, argv[3]->arg, 0,
15019 LARGE_COMMUNITY_LIST_MASTER);
15020 if (!list) {
15021 vty_out(vty, "%% Can't find extcommunity-list\n");
15022 return CMD_WARNING;
15023 }
15024
15025 lcommunity_list_show(vty, list);
15026
15027 return CMD_SUCCESS;
15028 }
15029
15030 ALIAS (show_lcommunity_list_arg,
15031 show_ip_lcommunity_list_arg_cmd,
15032 "show ip large-community-list <(1-500)|WORD>",
15033 SHOW_STR
15034 IP_STR
15035 "List large-community list\n"
15036 "large-community-list number\n"
15037 "large-community-list name\n")
15038
15039 /* "extcommunity-list" keyword help string. */
15040 #define EXTCOMMUNITY_LIST_STR "Add a extended community list entry\n"
15041 #define EXTCOMMUNITY_VAL_STR "Extended community attribute in 'rt aa:nn_or_IPaddr:nn' OR 'soo aa:nn_or_IPaddr:nn' format\n"
15042
15043 DEFUN (extcommunity_list_standard,
15044 bgp_extcommunity_list_standard_cmd,
15045 "bgp extcommunity-list <(1-99)|standard WORD> <deny|permit> AA:NN...",
15046 BGP_STR
15047 EXTCOMMUNITY_LIST_STR
15048 "Extended Community list number (standard)\n"
15049 "Specify standard extcommunity-list\n"
15050 "Community list name\n"
15051 "Specify community to reject\n"
15052 "Specify community to accept\n"
15053 EXTCOMMUNITY_VAL_STR)
15054 {
15055 int style = EXTCOMMUNITY_LIST_STANDARD;
15056 int direct = 0;
15057 char *cl_number_or_name = NULL;
15058
15059 int idx = 0;
15060 if (argv_find(argv, argc, "ip", &idx)) {
15061 vty_out(vty, "This config option is deprecated, and is scheduled for removal.\n");
15062 vty_out(vty, "if you are using this please migrate to the below command.\n");
15063 vty_out(vty, "'bgp extcommunity-list <(1-99)|(100-500)|standard|expanded> <deny|permit> <LINE|AA:NN>'\n");
15064 zlog_warn("Deprecated option: 'ip extcommunity-list <(1-99)|(100-500)|standard|expanded> <deny|permit> <LINE|AA:NN>' being used");
15065 }
15066 argv_find(argv, argc, "(1-99)", &idx);
15067 argv_find(argv, argc, "WORD", &idx);
15068 cl_number_or_name = argv[idx]->arg;
15069 direct = argv_find(argv, argc, "permit", &idx) ? COMMUNITY_PERMIT
15070 : COMMUNITY_DENY;
15071 argv_find(argv, argc, "AA:NN", &idx);
15072 char *str = argv_concat(argv, argc, idx);
15073
15074 int ret = extcommunity_list_set(bgp_clist, cl_number_or_name, str,
15075 direct, style);
15076
15077 XFREE(MTYPE_TMP, str);
15078
15079 if (ret < 0) {
15080 community_list_perror(vty, ret);
15081 return CMD_WARNING_CONFIG_FAILED;
15082 }
15083
15084 return CMD_SUCCESS;
15085 }
15086
15087 #if CONFDATE > 20191005
15088 CPP_NOTICE("bgpd: remove deprecated 'ip extcommunity-list <(1-99)|(100-500)|standard|expanded> <deny|permit> <LINE|AA:NN>' command")
15089 #endif
15090 ALIAS (extcommunity_list_standard,
15091 ip_extcommunity_list_standard_cmd,
15092 "ip extcommunity-list <(1-99)|standard WORD> <deny|permit> AA:NN...",
15093 IP_STR
15094 EXTCOMMUNITY_LIST_STR
15095 "Extended Community list number (standard)\n"
15096 "Specify standard extcommunity-list\n"
15097 "Community list name\n"
15098 "Specify community to reject\n"
15099 "Specify community to accept\n"
15100 EXTCOMMUNITY_VAL_STR)
15101
15102 DEFUN (extcommunity_list_name_expanded,
15103 bgp_extcommunity_list_name_expanded_cmd,
15104 "bgp extcommunity-list <(100-500)|expanded WORD> <deny|permit> LINE...",
15105 BGP_STR
15106 EXTCOMMUNITY_LIST_STR
15107 "Extended Community list number (expanded)\n"
15108 "Specify expanded extcommunity-list\n"
15109 "Extended Community list name\n"
15110 "Specify community to reject\n"
15111 "Specify community to accept\n"
15112 "An ordered list as a regular-expression\n")
15113 {
15114 int style = EXTCOMMUNITY_LIST_EXPANDED;
15115 int direct = 0;
15116 char *cl_number_or_name = NULL;
15117
15118 int idx = 0;
15119 if (argv_find(argv, argc, "ip", &idx)) {
15120 vty_out(vty, "This config option is deprecated, and is scheduled for removal.\n");
15121 vty_out(vty, "if you are using this please migrate to the below command.\n");
15122 vty_out(vty, "'extcommunity-list <(1-99)|(100-500)|standard|expanded> <deny|permit> <LINE|AA:NN>'\n");
15123 zlog_warn("Deprecated option: ‘ip extcommunity-list <(1-99)|(100-500)|standard|expanded> <deny|permit> <LINE|AA:NN>' being used");
15124 }
15125
15126 argv_find(argv, argc, "(100-500)", &idx);
15127 argv_find(argv, argc, "WORD", &idx);
15128 cl_number_or_name = argv[idx]->arg;
15129 direct = argv_find(argv, argc, "permit", &idx) ? COMMUNITY_PERMIT
15130 : COMMUNITY_DENY;
15131 argv_find(argv, argc, "LINE", &idx);
15132 char *str = argv_concat(argv, argc, idx);
15133
15134 int ret = extcommunity_list_set(bgp_clist, cl_number_or_name, str,
15135 direct, style);
15136
15137 XFREE(MTYPE_TMP, str);
15138
15139 if (ret < 0) {
15140 community_list_perror(vty, ret);
15141 return CMD_WARNING_CONFIG_FAILED;
15142 }
15143
15144 return CMD_SUCCESS;
15145 }
15146
15147 ALIAS (extcommunity_list_name_expanded,
15148 ip_extcommunity_list_name_expanded_cmd,
15149 "ip extcommunity-list <(100-500)|expanded WORD> <deny|permit> LINE...",
15150 IP_STR
15151 EXTCOMMUNITY_LIST_STR
15152 "Extended Community list number (expanded)\n"
15153 "Specify expanded extcommunity-list\n"
15154 "Extended Community list name\n"
15155 "Specify community to reject\n"
15156 "Specify community to accept\n"
15157 "An ordered list as a regular-expression\n")
15158
15159 DEFUN (no_extcommunity_list_standard_all,
15160 no_bgp_extcommunity_list_standard_all_cmd,
15161 "no bgp extcommunity-list <(1-99)|standard WORD> <deny|permit> AA:NN...",
15162 NO_STR
15163 BGP_STR
15164 EXTCOMMUNITY_LIST_STR
15165 "Extended Community list number (standard)\n"
15166 "Specify standard extcommunity-list\n"
15167 "Community list name\n"
15168 "Specify community to reject\n"
15169 "Specify community to accept\n"
15170 EXTCOMMUNITY_VAL_STR)
15171 {
15172 int style = EXTCOMMUNITY_LIST_STANDARD;
15173 int direct = 0;
15174 char *cl_number_or_name = NULL;
15175 char *str = NULL;
15176
15177 int idx = 0;
15178 if (argv_find(argv, argc, "ip", &idx)) {
15179 vty_out(vty, "This config option is deprecated, and is scheduled for removal\n");
15180 vty_out(vty, "if you are using this please migrate to the below command.\n");
15181 vty_out(vty, "'no bgp extcommunity-list <(1-99)|(100-500)|standard|expanded> <deny|permit> <LINE|AA:NN>'\n");
15182 zlog_warn("Deprecated option: ‘no ip extcommunity-list <(1-99)|(100-500)|standard|expanded> <deny|permit> <LINE|AA:NN>' being used");
15183 }
15184
15185 idx = 0;
15186 argv_find(argv, argc, "permit", &idx);
15187 argv_find(argv, argc, "deny", &idx);
15188
15189 if (idx) {
15190 direct = argv_find(argv, argc, "permit", &idx)
15191 ? COMMUNITY_PERMIT
15192 : COMMUNITY_DENY;
15193
15194 idx = 0;
15195 argv_find(argv, argc, "AA:NN", &idx);
15196 str = argv_concat(argv, argc, idx);
15197 }
15198
15199 idx = 0;
15200 argv_find(argv, argc, "(1-99)", &idx);
15201 argv_find(argv, argc, "WORD", &idx);
15202 cl_number_or_name = argv[idx]->arg;
15203
15204 int ret = extcommunity_list_unset(bgp_clist, cl_number_or_name, str,
15205 direct, style);
15206
15207 XFREE(MTYPE_TMP, str);
15208
15209 if (ret < 0) {
15210 community_list_perror(vty, ret);
15211 return CMD_WARNING_CONFIG_FAILED;
15212 }
15213
15214 return CMD_SUCCESS;
15215 }
15216
15217 ALIAS (no_extcommunity_list_standard_all,
15218 no_ip_extcommunity_list_standard_all_cmd,
15219 "no ip extcommunity-list <(1-99)|standard WORD> <deny|permit> AA:NN...",
15220 NO_STR
15221 IP_STR
15222 EXTCOMMUNITY_LIST_STR
15223 "Extended Community list number (standard)\n"
15224 "Specify standard extcommunity-list\n"
15225 "Community list name\n"
15226 "Specify community to reject\n"
15227 "Specify community to accept\n"
15228 EXTCOMMUNITY_VAL_STR)
15229
15230 ALIAS(no_extcommunity_list_standard_all,
15231 no_bgp_extcommunity_list_standard_all_list_cmd,
15232 "no bgp extcommunity-list <(1-99)|standard WORD>",
15233 NO_STR IP_STR EXTCOMMUNITY_LIST_STR
15234 "Extended Community list number (standard)\n"
15235 "Specify standard extcommunity-list\n"
15236 "Community list name\n")
15237
15238 ALIAS(no_extcommunity_list_standard_all,
15239 no_ip_extcommunity_list_standard_all_list_cmd,
15240 "no ip extcommunity-list <(1-99)|standard WORD>",
15241 NO_STR IP_STR EXTCOMMUNITY_LIST_STR
15242 "Extended Community list number (standard)\n"
15243 "Specify standard extcommunity-list\n"
15244 "Community list name\n")
15245
15246 DEFUN (no_extcommunity_list_expanded_all,
15247 no_bgp_extcommunity_list_expanded_all_cmd,
15248 "no bgp extcommunity-list <(100-500)|expanded WORD> <deny|permit> LINE...",
15249 NO_STR
15250 BGP_STR
15251 EXTCOMMUNITY_LIST_STR
15252 "Extended Community list number (expanded)\n"
15253 "Specify expanded extcommunity-list\n"
15254 "Extended Community list name\n"
15255 "Specify community to reject\n"
15256 "Specify community to accept\n"
15257 "An ordered list as a regular-expression\n")
15258 {
15259 int style = EXTCOMMUNITY_LIST_EXPANDED;
15260 int direct = 0;
15261 char *cl_number_or_name = NULL;
15262 char *str = NULL;
15263
15264 int idx = 0;
15265 if (argv_find(argv, argc, "ip", &idx)) {
15266 vty_out(vty, "This config option is deprecated, and is scheduled for removal.\n");
15267 vty_out(vty, "if you are using this please migrate to the below command.\n");
15268 vty_out(vty, "'no bgp extcommunity-list <(1-99)|(100-500)|standard|expanded> <deny|permit> <LINE|AA:NN>'\n");
15269 zlog_warn("Deprecated option: ‘no ip extcommunity-list <(1-99)|(100-500)|standard|expanded> <deny|permit> <LINE|AA:NN>' being used");
15270 }
15271
15272 idx = 0;
15273 argv_find(argv, argc, "permit", &idx);
15274 argv_find(argv, argc, "deny", &idx);
15275
15276 if (idx) {
15277 direct = argv_find(argv, argc, "permit", &idx)
15278 ? COMMUNITY_PERMIT
15279 : COMMUNITY_DENY;
15280
15281 idx = 0;
15282 argv_find(argv, argc, "LINE", &idx);
15283 str = argv_concat(argv, argc, idx);
15284 }
15285
15286 idx = 0;
15287 argv_find(argv, argc, "(100-500)", &idx);
15288 argv_find(argv, argc, "WORD", &idx);
15289 cl_number_or_name = argv[idx]->arg;
15290
15291 int ret = extcommunity_list_unset(bgp_clist, cl_number_or_name, str,
15292 direct, style);
15293
15294 XFREE(MTYPE_TMP, str);
15295
15296 if (ret < 0) {
15297 community_list_perror(vty, ret);
15298 return CMD_WARNING_CONFIG_FAILED;
15299 }
15300
15301 return CMD_SUCCESS;
15302 }
15303
15304 ALIAS (no_extcommunity_list_expanded_all,
15305 no_ip_extcommunity_list_expanded_all_cmd,
15306 "no ip extcommunity-list <(100-500)|expanded WORD> <deny|permit> LINE...",
15307 NO_STR
15308 IP_STR
15309 EXTCOMMUNITY_LIST_STR
15310 "Extended Community list number (expanded)\n"
15311 "Specify expanded extcommunity-list\n"
15312 "Extended Community list name\n"
15313 "Specify community to reject\n"
15314 "Specify community to accept\n"
15315 "An ordered list as a regular-expression\n")
15316
15317 ALIAS(no_extcommunity_list_expanded_all,
15318 no_ip_extcommunity_list_expanded_all_list_cmd,
15319 "no ip extcommunity-list <(100-500)|expanded WORD>",
15320 NO_STR IP_STR EXTCOMMUNITY_LIST_STR
15321 "Extended Community list number (expanded)\n"
15322 "Specify expanded extcommunity-list\n"
15323 "Extended Community list name\n")
15324
15325 ALIAS(no_extcommunity_list_expanded_all,
15326 no_bgp_extcommunity_list_expanded_all_list_cmd,
15327 "no bgp extcommunity-list <(100-500)|expanded WORD>",
15328 NO_STR IP_STR EXTCOMMUNITY_LIST_STR
15329 "Extended Community list number (expanded)\n"
15330 "Specify expanded extcommunity-list\n"
15331 "Extended Community list name\n")
15332
15333 static void extcommunity_list_show(struct vty *vty, struct community_list *list)
15334 {
15335 struct community_entry *entry;
15336
15337 for (entry = list->head; entry; entry = entry->next) {
15338 if (entry == list->head) {
15339 if (all_digit(list->name))
15340 vty_out(vty, "Extended community %s list %s\n",
15341 entry->style == EXTCOMMUNITY_LIST_STANDARD
15342 ? "standard"
15343 : "(expanded) access",
15344 list->name);
15345 else
15346 vty_out(vty,
15347 "Named extended community %s list %s\n",
15348 entry->style == EXTCOMMUNITY_LIST_STANDARD
15349 ? "standard"
15350 : "expanded",
15351 list->name);
15352 }
15353 if (entry->any)
15354 vty_out(vty, " %s\n",
15355 community_direct_str(entry->direct));
15356 else
15357 vty_out(vty, " %s %s\n",
15358 community_direct_str(entry->direct),
15359 community_list_config_str(entry));
15360 }
15361 }
15362
15363 DEFUN (show_extcommunity_list,
15364 show_bgp_extcommunity_list_cmd,
15365 "show bgp extcommunity-list",
15366 SHOW_STR
15367 BGP_STR
15368 "List extended-community list\n")
15369 {
15370 struct community_list *list;
15371 struct community_list_master *cm;
15372 int idx = 0;
15373
15374 if (argv_find(argv, argc, "ip", &idx)) {
15375 vty_out(vty, "This config option is deprecated, and is scheduled for removal\n");
15376 vty_out(vty, "if you are using this please migrate to the below command.\n");
15377 vty_out(vty, "'show bgp extcommunity-list <(1-500)|WORD>'\n");
15378 zlog_warn("Deprecated option: 'ip show extcommunity-list <(1-500)|WORD>' being used");
15379 }
15380 cm = community_list_master_lookup(bgp_clist, EXTCOMMUNITY_LIST_MASTER);
15381 if (!cm)
15382 return CMD_SUCCESS;
15383
15384 for (list = cm->num.head; list; list = list->next)
15385 extcommunity_list_show(vty, list);
15386
15387 for (list = cm->str.head; list; list = list->next)
15388 extcommunity_list_show(vty, list);
15389
15390 return CMD_SUCCESS;
15391 }
15392
15393 ALIAS (show_extcommunity_list,
15394 show_ip_extcommunity_list_cmd,
15395 "show ip extcommunity-list",
15396 SHOW_STR
15397 IP_STR
15398 "List extended-community list\n")
15399
15400 DEFUN (show_extcommunity_list_arg,
15401 show_bgp_extcommunity_list_arg_cmd,
15402 "show bgp extcommunity-list <(1-500)|WORD>",
15403 SHOW_STR
15404 BGP_STR
15405 "List extended-community list\n"
15406 "Extcommunity-list number\n"
15407 "Extcommunity-list name\n")
15408 {
15409 int idx_comm_list = 3;
15410 struct community_list *list;
15411 int idx = 0;
15412
15413 if (argv_find(argv, argc, "ip", &idx)) {
15414 vty_out(vty, "This config option is deprecated, and is scheduled for removal.\n");
15415 vty_out(vty, "if you are using this please migrate to the below command.\n");
15416 vty_out(vty, "'show bgp extcommunity-list <(1-500)|WORD>'\n");
15417 zlog_warn("Deprecated option: 'ip show extcommunity-list <(1-500)|WORD>' being used");
15418 }
15419 list = community_list_lookup(bgp_clist, argv[idx_comm_list]->arg, 0,
15420 EXTCOMMUNITY_LIST_MASTER);
15421 if (!list) {
15422 vty_out(vty, "%% Can't find extcommunity-list\n");
15423 return CMD_WARNING;
15424 }
15425
15426 extcommunity_list_show(vty, list);
15427
15428 return CMD_SUCCESS;
15429 }
15430
15431 ALIAS (show_extcommunity_list_arg,
15432 show_ip_extcommunity_list_arg_cmd,
15433 "show ip extcommunity-list <(1-500)|WORD>",
15434 SHOW_STR
15435 IP_STR
15436 "List extended-community list\n"
15437 "Extcommunity-list number\n"
15438 "Extcommunity-list name\n")
15439
15440 /* Display community-list and extcommunity-list configuration. */
15441 static int community_list_config_write(struct vty *vty)
15442 {
15443 struct community_list *list;
15444 struct community_entry *entry;
15445 struct community_list_master *cm;
15446 int write = 0;
15447
15448 /* Community-list. */
15449 cm = community_list_master_lookup(bgp_clist, COMMUNITY_LIST_MASTER);
15450
15451 for (list = cm->num.head; list; list = list->next)
15452 for (entry = list->head; entry; entry = entry->next) {
15453 vty_out(vty, "bgp community-list %s %s %s\n", list->name,
15454 community_direct_str(entry->direct),
15455 community_list_config_str(entry));
15456 write++;
15457 }
15458 for (list = cm->str.head; list; list = list->next)
15459 for (entry = list->head; entry; entry = entry->next) {
15460 vty_out(vty, "bgp community-list %s %s %s %s\n",
15461 entry->style == COMMUNITY_LIST_STANDARD
15462 ? "standard"
15463 : "expanded",
15464 list->name, community_direct_str(entry->direct),
15465 community_list_config_str(entry));
15466 write++;
15467 }
15468
15469 /* Extcommunity-list. */
15470 cm = community_list_master_lookup(bgp_clist, EXTCOMMUNITY_LIST_MASTER);
15471
15472 for (list = cm->num.head; list; list = list->next)
15473 for (entry = list->head; entry; entry = entry->next) {
15474 vty_out(vty, "bgp extcommunity-list %s %s %s\n",
15475 list->name, community_direct_str(entry->direct),
15476 community_list_config_str(entry));
15477 write++;
15478 }
15479 for (list = cm->str.head; list; list = list->next)
15480 for (entry = list->head; entry; entry = entry->next) {
15481 vty_out(vty, "bgp extcommunity-list %s %s %s %s\n",
15482 entry->style == EXTCOMMUNITY_LIST_STANDARD
15483 ? "standard"
15484 : "expanded",
15485 list->name, community_direct_str(entry->direct),
15486 community_list_config_str(entry));
15487 write++;
15488 }
15489
15490
15491 /* lcommunity-list. */
15492 cm = community_list_master_lookup(bgp_clist,
15493 LARGE_COMMUNITY_LIST_MASTER);
15494
15495 for (list = cm->num.head; list; list = list->next)
15496 for (entry = list->head; entry; entry = entry->next) {
15497 vty_out(vty, "bgp large-community-list %s %s %s\n",
15498 list->name, community_direct_str(entry->direct),
15499 community_list_config_str(entry));
15500 write++;
15501 }
15502 for (list = cm->str.head; list; list = list->next)
15503 for (entry = list->head; entry; entry = entry->next) {
15504 vty_out(vty, "bgp large-community-list %s %s %s %s\n",
15505 entry->style == LARGE_COMMUNITY_LIST_STANDARD
15506 ? "standard"
15507 : "expanded",
15508 list->name, community_direct_str(entry->direct),
15509 community_list_config_str(entry));
15510 write++;
15511 }
15512
15513 return write;
15514 }
15515
15516 static struct cmd_node community_list_node = {
15517 COMMUNITY_LIST_NODE, "", 1 /* Export to vtysh. */
15518 };
15519
15520 static void community_list_vty(void)
15521 {
15522 install_node(&community_list_node, community_list_config_write);
15523
15524 /* Community-list. */
15525 install_element(CONFIG_NODE, &bgp_community_list_standard_cmd);
15526 install_element(CONFIG_NODE, &bgp_community_list_expanded_all_cmd);
15527 install_element(CONFIG_NODE, &no_bgp_community_list_standard_all_cmd);
15528 install_element(CONFIG_NODE, &no_bgp_community_list_standard_all_list_cmd);
15529 install_element(CONFIG_NODE, &no_bgp_community_list_expanded_all_cmd);
15530 install_element(CONFIG_NODE, &no_bgp_community_list_expanded_all_list_cmd);
15531 install_element(VIEW_NODE, &show_bgp_community_list_cmd);
15532 install_element(VIEW_NODE, &show_bgp_community_list_arg_cmd);
15533 install_element(CONFIG_NODE, &ip_community_list_standard_cmd);
15534 install_element(CONFIG_NODE, &ip_community_list_expanded_all_cmd);
15535 install_element(CONFIG_NODE, &no_ip_community_list_standard_all_cmd);
15536 install_element(CONFIG_NODE, &no_ip_community_list_standard_all_list_cmd);
15537 install_element(CONFIG_NODE, &no_ip_community_list_expanded_all_cmd);
15538 install_element(CONFIG_NODE, &no_ip_community_list_expanded_all_list_cmd);
15539 install_element(VIEW_NODE, &show_ip_community_list_cmd);
15540 install_element(VIEW_NODE, &show_ip_community_list_arg_cmd);
15541
15542 /* Extcommunity-list. */
15543 install_element(CONFIG_NODE, &bgp_extcommunity_list_standard_cmd);
15544 install_element(CONFIG_NODE, &bgp_extcommunity_list_name_expanded_cmd);
15545 install_element(CONFIG_NODE, &no_bgp_extcommunity_list_standard_all_cmd);
15546 install_element(CONFIG_NODE,
15547 &no_bgp_extcommunity_list_standard_all_list_cmd);
15548 install_element(CONFIG_NODE, &no_bgp_extcommunity_list_expanded_all_cmd);
15549 install_element(CONFIG_NODE,
15550 &no_bgp_extcommunity_list_expanded_all_list_cmd);
15551 install_element(VIEW_NODE, &show_bgp_extcommunity_list_cmd);
15552 install_element(VIEW_NODE, &show_bgp_extcommunity_list_arg_cmd);
15553 install_element(CONFIG_NODE, &ip_extcommunity_list_standard_cmd);
15554 install_element(CONFIG_NODE, &ip_extcommunity_list_name_expanded_cmd);
15555 install_element(CONFIG_NODE, &no_ip_extcommunity_list_standard_all_cmd);
15556 install_element(CONFIG_NODE, &no_ip_extcommunity_list_standard_all_list_cmd);
15557 install_element(CONFIG_NODE, &no_ip_extcommunity_list_expanded_all_cmd);
15558 install_element(CONFIG_NODE, &no_ip_extcommunity_list_expanded_all_list_cmd);
15559 install_element(VIEW_NODE, &show_ip_extcommunity_list_cmd);
15560 install_element(VIEW_NODE, &show_ip_extcommunity_list_arg_cmd);
15561
15562 /* Large Community List */
15563 install_element(CONFIG_NODE, &bgp_lcommunity_list_standard_cmd);
15564 install_element(CONFIG_NODE, &bgp_lcommunity_list_standard1_cmd);
15565 install_element(CONFIG_NODE, &bgp_lcommunity_list_expanded_cmd);
15566 install_element(CONFIG_NODE, &bgp_lcommunity_list_name_standard_cmd);
15567 install_element(CONFIG_NODE, &bgp_lcommunity_list_name_standard1_cmd);
15568 install_element(CONFIG_NODE, &bgp_lcommunity_list_name_expanded_cmd);
15569 install_element(CONFIG_NODE, &no_bgp_lcommunity_list_standard_all_cmd);
15570 install_element(CONFIG_NODE,
15571 &no_bgp_lcommunity_list_name_expanded_all_cmd);
15572 install_element(CONFIG_NODE, &no_bgp_lcommunity_list_standard_cmd);
15573 install_element(CONFIG_NODE, &no_bgp_lcommunity_list_expanded_cmd);
15574 install_element(CONFIG_NODE, &no_bgp_lcommunity_list_name_standard_cmd);
15575 install_element(CONFIG_NODE, &no_bgp_lcommunity_list_name_expanded_cmd);
15576 install_element(VIEW_NODE, &show_bgp_lcommunity_list_cmd);
15577 install_element(VIEW_NODE, &show_bgp_lcommunity_list_arg_cmd);
15578 install_element(CONFIG_NODE, &ip_lcommunity_list_standard_cmd);
15579 install_element(CONFIG_NODE, &ip_lcommunity_list_standard1_cmd);
15580 install_element(CONFIG_NODE, &ip_lcommunity_list_expanded_cmd);
15581 install_element(CONFIG_NODE, &ip_lcommunity_list_name_standard_cmd);
15582 install_element(CONFIG_NODE, &ip_lcommunity_list_name_standard1_cmd);
15583 install_element(CONFIG_NODE, &ip_lcommunity_list_name_expanded_cmd);
15584 install_element(CONFIG_NODE, &no_ip_lcommunity_list_standard_all_cmd);
15585 install_element(CONFIG_NODE,
15586 &no_ip_lcommunity_list_name_expanded_all_cmd);
15587 install_element(CONFIG_NODE, &no_ip_lcommunity_list_standard_cmd);
15588 install_element(CONFIG_NODE, &no_ip_lcommunity_list_expanded_cmd);
15589 install_element(CONFIG_NODE, &no_ip_lcommunity_list_name_standard_cmd);
15590 install_element(CONFIG_NODE, &no_ip_lcommunity_list_name_expanded_cmd);
15591 install_element(VIEW_NODE, &show_ip_lcommunity_list_cmd);
15592 install_element(VIEW_NODE, &show_ip_lcommunity_list_arg_cmd);
15593 }