]> git.proxmox.com Git - mirror_frr.git/blob - bgpd/bgp_vty.c
e9be8a494fe433eb10954ad3ddbf7898044fc318
[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 * use_json -> json is configured or not
299 *
300 * The function returns the correct location in the parse tree for the
301 * last token found.
302 *
303 * Returns 0 for failure to parse correctly, else the idx position of where
304 * it found the last token.
305 */
306 int bgp_vty_find_and_parse_afi_safi_bgp(struct vty *vty,
307 struct cmd_token **argv, int argc,
308 int *idx, afi_t *afi, safi_t *safi,
309 struct bgp **bgp, bool use_json)
310 {
311 char *vrf_name = NULL;
312
313 assert(afi);
314 assert(safi);
315 assert(bgp);
316
317 if (argv_find(argv, argc, "ip", idx))
318 *afi = AFI_IP;
319
320 if (argv_find(argv, argc, "view", idx))
321 vrf_name = argv[*idx + 1]->arg;
322 else if (argv_find(argv, argc, "vrf", idx)) {
323 vrf_name = argv[*idx + 1]->arg;
324 if (strmatch(vrf_name, VRF_DEFAULT_NAME))
325 vrf_name = NULL;
326 }
327 if (vrf_name) {
328 if (strmatch(vrf_name, "all"))
329 *bgp = NULL;
330 else {
331 *bgp = bgp_lookup_by_name(vrf_name);
332 if (!*bgp) {
333 if (use_json) {
334 json_object *json = NULL;
335 json = json_object_new_object();
336 json_object_string_add(
337 json, "warning",
338 "View/Vrf is unknown");
339 vty_out(vty, "%s\n",
340 json_object_to_json_string_ext(json,
341 JSON_C_TO_STRING_PRETTY));
342 json_object_free(json);
343 }
344 else
345 vty_out(vty, "View/Vrf %s is unknown\n",
346 vrf_name);
347 *idx = 0;
348 return 0;
349 }
350 }
351 } else {
352 *bgp = bgp_get_default();
353 if (!*bgp) {
354 if (use_json) {
355 json_object *json = NULL;
356 json = json_object_new_object();
357 json_object_string_add(
358 json, "warning",
359 "Default BGP instance not found");
360 vty_out(vty, "%s\n",
361 json_object_to_json_string_ext(json,
362 JSON_C_TO_STRING_PRETTY));
363 json_object_free(json);
364 }
365 else
366 vty_out(vty,
367 "Default BGP instance not found\n");
368 *idx = 0;
369 return 0;
370 }
371 }
372
373 if (argv_find_and_parse_afi(argv, argc, idx, afi))
374 argv_find_and_parse_safi(argv, argc, idx, safi);
375
376 *idx += 1;
377 return *idx;
378 }
379
380 static int peer_address_self_check(struct bgp *bgp, union sockunion *su)
381 {
382 struct interface *ifp = NULL;
383
384 if (su->sa.sa_family == AF_INET)
385 ifp = if_lookup_by_ipv4_exact(&su->sin.sin_addr, bgp->vrf_id);
386 else if (su->sa.sa_family == AF_INET6)
387 ifp = if_lookup_by_ipv6_exact(&su->sin6.sin6_addr,
388 su->sin6.sin6_scope_id,
389 bgp->vrf_id);
390
391 if (ifp)
392 return 1;
393
394 return 0;
395 }
396
397 /* Utility function for looking up peer from VTY. */
398 /* This is used only for configuration, so disallow if attempted on
399 * a dynamic neighbor.
400 */
401 static struct peer *peer_lookup_vty(struct vty *vty, const char *ip_str)
402 {
403 struct bgp *bgp = VTY_GET_CONTEXT(bgp);
404 int ret;
405 union sockunion su;
406 struct peer *peer;
407
408 if (!bgp) {
409 return NULL;
410 }
411
412 ret = str2sockunion(ip_str, &su);
413 if (ret < 0) {
414 peer = peer_lookup_by_conf_if(bgp, ip_str);
415 if (!peer) {
416 if ((peer = peer_lookup_by_hostname(bgp, ip_str))
417 == NULL) {
418 vty_out(vty,
419 "%% Malformed address or name: %s\n",
420 ip_str);
421 return NULL;
422 }
423 }
424 } else {
425 peer = peer_lookup(bgp, &su);
426 if (!peer) {
427 vty_out(vty,
428 "%% Specify remote-as or peer-group commands first\n");
429 return NULL;
430 }
431 if (peer_dynamic_neighbor(peer)) {
432 vty_out(vty,
433 "%% Operation not allowed on a dynamic neighbor\n");
434 return NULL;
435 }
436 }
437 return peer;
438 }
439
440 /* Utility function for looking up peer or peer group. */
441 /* This is used only for configuration, so disallow if attempted on
442 * a dynamic neighbor.
443 */
444 struct peer *peer_and_group_lookup_vty(struct vty *vty, const char *peer_str)
445 {
446 struct bgp *bgp = VTY_GET_CONTEXT(bgp);
447 int ret;
448 union sockunion su;
449 struct peer *peer = NULL;
450 struct peer_group *group = NULL;
451
452 if (!bgp) {
453 return NULL;
454 }
455
456 ret = str2sockunion(peer_str, &su);
457 if (ret == 0) {
458 /* IP address, locate peer. */
459 peer = peer_lookup(bgp, &su);
460 } else {
461 /* Not IP, could match either peer configured on interface or a
462 * group. */
463 peer = peer_lookup_by_conf_if(bgp, peer_str);
464 if (!peer)
465 group = peer_group_lookup(bgp, peer_str);
466 }
467
468 if (peer) {
469 if (peer_dynamic_neighbor(peer)) {
470 vty_out(vty,
471 "%% Operation not allowed on a dynamic neighbor\n");
472 return NULL;
473 }
474
475 return peer;
476 }
477
478 if (group)
479 return group->conf;
480
481 vty_out(vty, "%% Specify remote-as or peer-group commands first\n");
482
483 return NULL;
484 }
485
486 int bgp_vty_return(struct vty *vty, int ret)
487 {
488 const char *str = NULL;
489
490 switch (ret) {
491 case BGP_ERR_INVALID_VALUE:
492 str = "Invalid value";
493 break;
494 case BGP_ERR_INVALID_FLAG:
495 str = "Invalid flag";
496 break;
497 case BGP_ERR_PEER_GROUP_SHUTDOWN:
498 str = "Peer-group has been shutdown. Activate the peer-group first";
499 break;
500 case BGP_ERR_PEER_FLAG_CONFLICT:
501 str = "Can't set override-capability and strict-capability-match at the same time";
502 break;
503 case BGP_ERR_PEER_GROUP_NO_REMOTE_AS:
504 str = "Specify remote-as or peer-group remote AS first";
505 break;
506 case BGP_ERR_PEER_GROUP_CANT_CHANGE:
507 str = "Cannot change the peer-group. Deconfigure first";
508 break;
509 case BGP_ERR_PEER_GROUP_MISMATCH:
510 str = "Peer is not a member of this peer-group";
511 break;
512 case BGP_ERR_PEER_FILTER_CONFLICT:
513 str = "Prefix/distribute list can not co-exist";
514 break;
515 case BGP_ERR_NOT_INTERNAL_PEER:
516 str = "Invalid command. Not an internal neighbor";
517 break;
518 case BGP_ERR_REMOVE_PRIVATE_AS:
519 str = "remove-private-AS cannot be configured for IBGP peers";
520 break;
521 case BGP_ERR_LOCAL_AS_ALLOWED_ONLY_FOR_EBGP:
522 str = "Local-AS allowed only for EBGP peers";
523 break;
524 case BGP_ERR_CANNOT_HAVE_LOCAL_AS_SAME_AS:
525 str = "Cannot have local-as same as BGP AS number";
526 break;
527 case BGP_ERR_TCPSIG_FAILED:
528 str = "Error while applying TCP-Sig to session(s)";
529 break;
530 case BGP_ERR_NO_EBGP_MULTIHOP_WITH_TTLHACK:
531 str = "ebgp-multihop and ttl-security cannot be configured together";
532 break;
533 case BGP_ERR_NO_IBGP_WITH_TTLHACK:
534 str = "ttl-security only allowed for EBGP peers";
535 break;
536 case BGP_ERR_AS_OVERRIDE:
537 str = "as-override cannot be configured for IBGP peers";
538 break;
539 case BGP_ERR_INVALID_DYNAMIC_NEIGHBORS_LIMIT:
540 str = "Invalid limit for number of dynamic neighbors";
541 break;
542 case BGP_ERR_DYNAMIC_NEIGHBORS_RANGE_EXISTS:
543 str = "Dynamic neighbor listen range already exists";
544 break;
545 case BGP_ERR_INVALID_FOR_DYNAMIC_PEER:
546 str = "Operation not allowed on a dynamic neighbor";
547 break;
548 case BGP_ERR_INVALID_FOR_DIRECT_PEER:
549 str = "Operation not allowed on a directly connected neighbor";
550 break;
551 case BGP_ERR_PEER_SAFI_CONFLICT:
552 str = "Cannot activate peer for both 'ipv4 unicast' and 'ipv4 labeled-unicast'";
553 break;
554 }
555 if (str) {
556 vty_out(vty, "%% %s\n", str);
557 return CMD_WARNING_CONFIG_FAILED;
558 }
559 return CMD_SUCCESS;
560 }
561
562 /* BGP clear sort. */
563 enum clear_sort {
564 clear_all,
565 clear_peer,
566 clear_group,
567 clear_external,
568 clear_as
569 };
570
571 static void bgp_clear_vty_error(struct vty *vty, struct peer *peer, afi_t afi,
572 safi_t safi, int error)
573 {
574 switch (error) {
575 case BGP_ERR_AF_UNCONFIGURED:
576 vty_out(vty,
577 "%%BGP: Enable %s address family for the neighbor %s\n",
578 afi_safi_print(afi, safi), peer->host);
579 break;
580 case BGP_ERR_SOFT_RECONFIG_UNCONFIGURED:
581 vty_out(vty,
582 "%%BGP: Inbound soft reconfig for %s not possible as it\n has neither refresh capability, nor inbound soft reconfig\n",
583 peer->host);
584 break;
585 default:
586 break;
587 }
588 }
589
590 /* `clear ip bgp' functions. */
591 static int bgp_clear(struct vty *vty, struct bgp *bgp, afi_t afi, safi_t safi,
592 enum clear_sort sort, enum bgp_clear_type stype,
593 const char *arg)
594 {
595 int ret;
596 bool found = false;
597 struct peer *peer;
598 struct listnode *node, *nnode;
599
600 /* Clear all neighbors. */
601 /*
602 * Pass along pointer to next node to peer_clear() when walking all
603 * nodes on the BGP instance as that may get freed if it is a
604 * doppelganger
605 */
606 if (sort == clear_all) {
607 for (ALL_LIST_ELEMENTS(bgp->peer, node, nnode, peer)) {
608 if (!peer->afc[afi][safi])
609 continue;
610
611 if (stype == BGP_CLEAR_SOFT_NONE)
612 ret = peer_clear(peer, &nnode);
613 else
614 ret = peer_clear_soft(peer, afi, safi, stype);
615
616 if (ret < 0)
617 bgp_clear_vty_error(vty, peer, afi, safi, ret);
618 else
619 found = true;
620 }
621
622 /* This is to apply read-only mode on this clear. */
623 if (stype == BGP_CLEAR_SOFT_NONE)
624 bgp->update_delay_over = 0;
625
626 if (!found)
627 vty_out(vty, "%%BGP: No %s peer configured\n",
628 afi_safi_print(afi, safi));
629
630 return CMD_SUCCESS;
631 }
632
633 /* Clear specified neighbor. */
634 if (sort == clear_peer) {
635 union sockunion su;
636
637 /* Make sockunion for lookup. */
638 ret = str2sockunion(arg, &su);
639 if (ret < 0) {
640 peer = peer_lookup_by_conf_if(bgp, arg);
641 if (!peer) {
642 peer = peer_lookup_by_hostname(bgp, arg);
643 if (!peer) {
644 vty_out(vty,
645 "Malformed address or name: %s\n",
646 arg);
647 return CMD_WARNING;
648 }
649 }
650 } else {
651 peer = peer_lookup(bgp, &su);
652 if (!peer) {
653 vty_out(vty,
654 "%%BGP: Unknown neighbor - \"%s\"\n",
655 arg);
656 return CMD_WARNING;
657 }
658 }
659
660 if (!peer->afc[afi][safi])
661 ret = BGP_ERR_AF_UNCONFIGURED;
662 else if (stype == BGP_CLEAR_SOFT_NONE)
663 ret = peer_clear(peer, NULL);
664 else
665 ret = peer_clear_soft(peer, afi, safi, stype);
666
667 if (ret < 0)
668 bgp_clear_vty_error(vty, peer, afi, safi, ret);
669
670 return CMD_SUCCESS;
671 }
672
673 /* Clear all neighbors belonging to a specific peer-group. */
674 if (sort == clear_group) {
675 struct peer_group *group;
676
677 group = peer_group_lookup(bgp, arg);
678 if (!group) {
679 vty_out(vty, "%%BGP: No such peer-group %s\n", arg);
680 return CMD_WARNING;
681 }
682
683 for (ALL_LIST_ELEMENTS(group->peer, node, nnode, peer)) {
684 if (!peer->afc[afi][safi])
685 continue;
686
687 if (stype == BGP_CLEAR_SOFT_NONE)
688 ret = peer_clear(peer, NULL);
689 else
690 ret = peer_clear_soft(peer, afi, safi, stype);
691
692 if (ret < 0)
693 bgp_clear_vty_error(vty, peer, afi, safi, ret);
694 else
695 found = true;
696 }
697
698 if (!found)
699 vty_out(vty,
700 "%%BGP: No %s peer belonging to peer-group %s is configured\n",
701 afi_safi_print(afi, safi), arg);
702
703 return CMD_SUCCESS;
704 }
705
706 /* Clear all external (eBGP) neighbors. */
707 if (sort == clear_external) {
708 for (ALL_LIST_ELEMENTS(bgp->peer, node, nnode, peer)) {
709 if (peer->sort == BGP_PEER_IBGP)
710 continue;
711
712 if (!peer->afc[afi][safi])
713 continue;
714
715 if (stype == BGP_CLEAR_SOFT_NONE)
716 ret = peer_clear(peer, &nnode);
717 else
718 ret = peer_clear_soft(peer, afi, safi, stype);
719
720 if (ret < 0)
721 bgp_clear_vty_error(vty, peer, afi, safi, ret);
722 else
723 found = true;
724 }
725
726 if (!found)
727 vty_out(vty,
728 "%%BGP: No external %s peer is configured\n",
729 afi_safi_print(afi, safi));
730
731 return CMD_SUCCESS;
732 }
733
734 /* Clear all neighbors belonging to a specific AS. */
735 if (sort == clear_as) {
736 as_t as = strtoul(arg, NULL, 10);
737
738 for (ALL_LIST_ELEMENTS(bgp->peer, node, nnode, peer)) {
739 if (peer->as != as)
740 continue;
741
742 if (!peer->afc[afi][safi])
743 ret = BGP_ERR_AF_UNCONFIGURED;
744 else if (stype == BGP_CLEAR_SOFT_NONE)
745 ret = peer_clear(peer, &nnode);
746 else
747 ret = peer_clear_soft(peer, afi, safi, stype);
748
749 if (ret < 0)
750 bgp_clear_vty_error(vty, peer, afi, safi, ret);
751 else
752 found = true;
753 }
754
755 if (!found)
756 vty_out(vty,
757 "%%BGP: No %s peer is configured with AS %s\n",
758 afi_safi_print(afi, safi), arg);
759
760 return CMD_SUCCESS;
761 }
762
763 return CMD_SUCCESS;
764 }
765
766 static int bgp_clear_vty(struct vty *vty, const char *name, afi_t afi,
767 safi_t safi, enum clear_sort sort,
768 enum bgp_clear_type stype, const char *arg)
769 {
770 struct bgp *bgp;
771
772 /* BGP structure lookup. */
773 if (name) {
774 bgp = bgp_lookup_by_name(name);
775 if (bgp == NULL) {
776 vty_out(vty, "Can't find BGP instance %s\n", name);
777 return CMD_WARNING;
778 }
779 } else {
780 bgp = bgp_get_default();
781 if (bgp == NULL) {
782 vty_out(vty, "No BGP process is configured\n");
783 return CMD_WARNING;
784 }
785 }
786
787 return bgp_clear(vty, bgp, afi, safi, sort, stype, arg);
788 }
789
790 /* clear soft inbound */
791 static void bgp_clear_star_soft_in(struct vty *vty, const char *name)
792 {
793 afi_t afi;
794 safi_t safi;
795
796 FOREACH_AFI_SAFI (afi, safi)
797 bgp_clear_vty(vty, name, afi, safi, clear_all,
798 BGP_CLEAR_SOFT_IN, NULL);
799 }
800
801 /* clear soft outbound */
802 static void bgp_clear_star_soft_out(struct vty *vty, const char *name)
803 {
804 afi_t afi;
805 safi_t safi;
806
807 FOREACH_AFI_SAFI (afi, safi)
808 bgp_clear_vty(vty, name, afi, safi, clear_all,
809 BGP_CLEAR_SOFT_OUT, NULL);
810 }
811
812
813 #ifndef VTYSH_EXTRACT_PL
814 #include "bgpd/bgp_vty_clippy.c"
815 #endif
816
817 /* BGP global configuration. */
818 #if (CONFDATE > 20190601)
819 CPP_NOTICE("bgpd: time to remove deprecated bgp multiple-instance")
820 CPP_NOTICE("This includes BGP_OPT_MULTIPLE_INSTANCE")
821 #endif
822 DEFUN_HIDDEN (bgp_multiple_instance_func,
823 bgp_multiple_instance_cmd,
824 "bgp multiple-instance",
825 BGP_STR
826 "Enable bgp multiple instance\n")
827 {
828 bgp_option_set(BGP_OPT_MULTIPLE_INSTANCE);
829 return CMD_SUCCESS;
830 }
831
832 DEFUN_HIDDEN (no_bgp_multiple_instance,
833 no_bgp_multiple_instance_cmd,
834 "no bgp multiple-instance",
835 NO_STR
836 BGP_STR
837 "BGP multiple instance\n")
838 {
839 int ret;
840
841 vty_out(vty, "This config option is deprecated, and is scheduled for removal.\n");
842 vty_out(vty, "if you are using this please let the developers know\n");
843 zlog_info("Deprecated option: `bgp multiple-instance` being used");
844 ret = bgp_option_unset(BGP_OPT_MULTIPLE_INSTANCE);
845 if (ret < 0) {
846 vty_out(vty, "%% There are more than two BGP instances\n");
847 return CMD_WARNING_CONFIG_FAILED;
848 }
849 return CMD_SUCCESS;
850 }
851
852 DEFUN_HIDDEN (bgp_local_mac,
853 bgp_local_mac_cmd,
854 "bgp local-mac vni " CMD_VNI_RANGE " mac WORD seq (0-4294967295)",
855 BGP_STR
856 "Local MAC config\n"
857 "VxLAN Network Identifier\n"
858 "VNI number\n"
859 "local mac\n"
860 "mac address\n"
861 "mac-mobility sequence\n"
862 "seq number\n")
863 {
864 int rv;
865 vni_t vni;
866 struct ethaddr mac;
867 struct ipaddr ip;
868 uint32_t seq;
869 struct bgp *bgp;
870
871 vni = strtoul(argv[3]->arg, NULL, 10);
872 if (!prefix_str2mac(argv[5]->arg, &mac)) {
873 vty_out(vty, "%% Malformed MAC address\n");
874 return CMD_WARNING;
875 }
876 memset(&ip, 0, sizeof(ip));
877 seq = strtoul(argv[7]->arg, NULL, 10);
878
879 bgp = bgp_get_default();
880 if (!bgp) {
881 vty_out(vty, "Default BGP instance is not there\n");
882 return CMD_WARNING;
883 }
884
885 rv = bgp_evpn_local_macip_add(bgp, vni, &mac, &ip, 0 /* flags */, seq);
886 if (rv < 0) {
887 vty_out(vty, "Internal error\n");
888 return CMD_WARNING;
889 }
890
891 return CMD_SUCCESS;
892 }
893
894 DEFUN_HIDDEN (no_bgp_local_mac,
895 no_bgp_local_mac_cmd,
896 "no bgp local-mac vni " CMD_VNI_RANGE " mac WORD",
897 NO_STR
898 BGP_STR
899 "Local MAC config\n"
900 "VxLAN Network Identifier\n"
901 "VNI number\n"
902 "local mac\n"
903 "mac address\n")
904 {
905 int rv;
906 vni_t vni;
907 struct ethaddr mac;
908 struct ipaddr ip;
909 struct bgp *bgp;
910
911 vni = strtoul(argv[4]->arg, NULL, 10);
912 if (!prefix_str2mac(argv[6]->arg, &mac)) {
913 vty_out(vty, "%% Malformed MAC address\n");
914 return CMD_WARNING;
915 }
916 memset(&ip, 0, sizeof(ip));
917
918 bgp = bgp_get_default();
919 if (!bgp) {
920 vty_out(vty, "Default BGP instance is not there\n");
921 return CMD_WARNING;
922 }
923
924 rv = bgp_evpn_local_macip_del(bgp, vni, &mac, &ip, ZEBRA_NEIGH_ACTIVE);
925 if (rv < 0) {
926 vty_out(vty, "Internal error\n");
927 return CMD_WARNING;
928 }
929
930 return CMD_SUCCESS;
931 }
932
933 #if (CONFDATE > 20190601)
934 CPP_NOTICE("bgpd: time to remove deprecated cli bgp config-type cisco")
935 CPP_NOTICE("This includes BGP_OPT_CISCO_CONFIG")
936 #endif
937 DEFUN_HIDDEN (bgp_config_type,
938 bgp_config_type_cmd,
939 "bgp config-type <cisco|zebra>",
940 BGP_STR
941 "Configuration type\n"
942 "cisco\n"
943 "zebra\n")
944 {
945 int idx = 0;
946 if (argv_find(argv, argc, "cisco", &idx)) {
947 vty_out(vty, "This config option is deprecated, and is scheduled for removal.\n");
948 vty_out(vty, "if you are using this please let the developers know!\n");
949 zlog_info("Deprecated option: `bgp config-type cisco` being used");
950 bgp_option_set(BGP_OPT_CONFIG_CISCO);
951 } else
952 bgp_option_unset(BGP_OPT_CONFIG_CISCO);
953
954 return CMD_SUCCESS;
955 }
956
957 DEFUN_HIDDEN (no_bgp_config_type,
958 no_bgp_config_type_cmd,
959 "no bgp config-type [<cisco|zebra>]",
960 NO_STR
961 BGP_STR
962 "Display configuration type\n"
963 "cisco\n"
964 "zebra\n")
965 {
966 bgp_option_unset(BGP_OPT_CONFIG_CISCO);
967 return CMD_SUCCESS;
968 }
969
970
971 DEFUN (no_synchronization,
972 no_synchronization_cmd,
973 "no synchronization",
974 NO_STR
975 "Perform IGP synchronization\n")
976 {
977 return CMD_SUCCESS;
978 }
979
980 DEFUN (no_auto_summary,
981 no_auto_summary_cmd,
982 "no auto-summary",
983 NO_STR
984 "Enable automatic network number summarization\n")
985 {
986 return CMD_SUCCESS;
987 }
988
989 /* "router bgp" commands. */
990 DEFUN_NOSH (router_bgp,
991 router_bgp_cmd,
992 "router bgp [(1-4294967295) [<view|vrf> VIEWVRFNAME]]",
993 ROUTER_STR
994 BGP_STR
995 AS_STR
996 BGP_INSTANCE_HELP_STR)
997 {
998 int idx_asn = 2;
999 int idx_view_vrf = 3;
1000 int idx_vrf = 4;
1001 int is_new_bgp = 0;
1002 int ret;
1003 as_t as;
1004 struct bgp *bgp;
1005 const char *name = NULL;
1006 enum bgp_instance_type inst_type;
1007
1008 // "router bgp" without an ASN
1009 if (argc == 2) {
1010 // Pending: Make VRF option available for ASN less config
1011 bgp = bgp_get_default();
1012
1013 if (bgp == NULL) {
1014 vty_out(vty, "%% No BGP process is configured\n");
1015 return CMD_WARNING_CONFIG_FAILED;
1016 }
1017
1018 if (listcount(bm->bgp) > 1) {
1019 vty_out(vty, "%% Please specify ASN and VRF\n");
1020 return CMD_WARNING_CONFIG_FAILED;
1021 }
1022 }
1023
1024 // "router bgp X"
1025 else {
1026 as = strtoul(argv[idx_asn]->arg, NULL, 10);
1027
1028 inst_type = BGP_INSTANCE_TYPE_DEFAULT;
1029 if (argc > 3) {
1030 name = argv[idx_vrf]->arg;
1031
1032 if (!strcmp(argv[idx_view_vrf]->text, "vrf")) {
1033 if (strmatch(name, VRF_DEFAULT_NAME))
1034 name = NULL;
1035 else
1036 inst_type = BGP_INSTANCE_TYPE_VRF;
1037 } else if (!strcmp(argv[idx_view_vrf]->text, "view"))
1038 inst_type = BGP_INSTANCE_TYPE_VIEW;
1039 }
1040
1041 if (inst_type == BGP_INSTANCE_TYPE_DEFAULT)
1042 is_new_bgp = (bgp_lookup(as, name) == NULL);
1043
1044 ret = bgp_get(&bgp, &as, name, inst_type);
1045 switch (ret) {
1046 case BGP_ERR_MULTIPLE_INSTANCE_NOT_SET:
1047 vty_out(vty,
1048 "Please specify 'bgp multiple-instance' first\n");
1049 return CMD_WARNING_CONFIG_FAILED;
1050 case BGP_ERR_AS_MISMATCH:
1051 vty_out(vty, "BGP is already running; AS is %u\n", as);
1052 return CMD_WARNING_CONFIG_FAILED;
1053 case BGP_ERR_INSTANCE_MISMATCH:
1054 vty_out(vty,
1055 "BGP instance name and AS number mismatch\n");
1056 vty_out(vty,
1057 "BGP instance is already running; AS is %u\n",
1058 as);
1059 return CMD_WARNING_CONFIG_FAILED;
1060 }
1061
1062 /*
1063 * If we just instantiated the default instance, complete
1064 * any pending VRF-VPN leaking that was configured via
1065 * earlier "router bgp X vrf FOO" blocks.
1066 */
1067 if (is_new_bgp && inst_type == BGP_INSTANCE_TYPE_DEFAULT)
1068 vpn_leak_postchange_all();
1069
1070 /* Pending: handle when user tries to change a view to vrf n vv.
1071 */
1072 }
1073
1074 /* unset the auto created flag as the user config is now present */
1075 UNSET_FLAG(bgp->vrf_flags, BGP_VRF_AUTO);
1076 VTY_PUSH_CONTEXT(BGP_NODE, bgp);
1077
1078 return CMD_SUCCESS;
1079 }
1080
1081 /* "no router bgp" commands. */
1082 DEFUN (no_router_bgp,
1083 no_router_bgp_cmd,
1084 "no router bgp [(1-4294967295) [<view|vrf> VIEWVRFNAME]]",
1085 NO_STR
1086 ROUTER_STR
1087 BGP_STR
1088 AS_STR
1089 BGP_INSTANCE_HELP_STR)
1090 {
1091 int idx_asn = 3;
1092 int idx_vrf = 5;
1093 as_t as;
1094 struct bgp *bgp;
1095 const char *name = NULL;
1096
1097 // "no router bgp" without an ASN
1098 if (argc == 3) {
1099 // Pending: Make VRF option available for ASN less config
1100 bgp = bgp_get_default();
1101
1102 if (bgp == NULL) {
1103 vty_out(vty, "%% No BGP process is configured\n");
1104 return CMD_WARNING_CONFIG_FAILED;
1105 }
1106
1107 if (listcount(bm->bgp) > 1) {
1108 vty_out(vty, "%% Please specify ASN and VRF\n");
1109 return CMD_WARNING_CONFIG_FAILED;
1110 }
1111
1112 if (bgp->l3vni) {
1113 vty_out(vty, "%% Please unconfigure l3vni %u",
1114 bgp->l3vni);
1115 return CMD_WARNING_CONFIG_FAILED;
1116 }
1117 } else {
1118 as = strtoul(argv[idx_asn]->arg, NULL, 10);
1119
1120 if (argc > 4)
1121 name = argv[idx_vrf]->arg;
1122
1123 /* Lookup bgp structure. */
1124 bgp = bgp_lookup(as, name);
1125 if (!bgp) {
1126 vty_out(vty, "%% Can't find BGP instance\n");
1127 return CMD_WARNING_CONFIG_FAILED;
1128 }
1129
1130 if (bgp->l3vni) {
1131 vty_out(vty, "%% Please unconfigure l3vni %u",
1132 bgp->l3vni);
1133 return CMD_WARNING_CONFIG_FAILED;
1134 }
1135 }
1136
1137 bgp_delete(bgp);
1138
1139 return CMD_SUCCESS;
1140 }
1141
1142
1143 /* BGP router-id. */
1144
1145 DEFPY (bgp_router_id,
1146 bgp_router_id_cmd,
1147 "bgp router-id A.B.C.D",
1148 BGP_STR
1149 "Override configured router identifier\n"
1150 "Manually configured router identifier\n")
1151 {
1152 VTY_DECLVAR_CONTEXT(bgp, bgp);
1153 bgp_router_id_static_set(bgp, router_id);
1154 return CMD_SUCCESS;
1155 }
1156
1157 DEFPY (no_bgp_router_id,
1158 no_bgp_router_id_cmd,
1159 "no bgp router-id [A.B.C.D]",
1160 NO_STR
1161 BGP_STR
1162 "Override configured router identifier\n"
1163 "Manually configured router identifier\n")
1164 {
1165 VTY_DECLVAR_CONTEXT(bgp, bgp);
1166
1167 if (router_id_str) {
1168 if (!IPV4_ADDR_SAME(&bgp->router_id_static, &router_id)) {
1169 vty_out(vty, "%% BGP router-id doesn't match\n");
1170 return CMD_WARNING_CONFIG_FAILED;
1171 }
1172 }
1173
1174 router_id.s_addr = 0;
1175 bgp_router_id_static_set(bgp, router_id);
1176
1177 return CMD_SUCCESS;
1178 }
1179
1180
1181 /* BGP Cluster ID. */
1182 DEFUN (bgp_cluster_id,
1183 bgp_cluster_id_cmd,
1184 "bgp cluster-id <A.B.C.D|(1-4294967295)>",
1185 BGP_STR
1186 "Configure Route-Reflector Cluster-id\n"
1187 "Route-Reflector Cluster-id in IP address format\n"
1188 "Route-Reflector Cluster-id as 32 bit quantity\n")
1189 {
1190 VTY_DECLVAR_CONTEXT(bgp, bgp);
1191 int idx_ipv4 = 2;
1192 int ret;
1193 struct in_addr cluster;
1194
1195 ret = inet_aton(argv[idx_ipv4]->arg, &cluster);
1196 if (!ret) {
1197 vty_out(vty, "%% Malformed bgp cluster identifier\n");
1198 return CMD_WARNING_CONFIG_FAILED;
1199 }
1200
1201 bgp_cluster_id_set(bgp, &cluster);
1202 bgp_clear_star_soft_out(vty, bgp->name);
1203
1204 return CMD_SUCCESS;
1205 }
1206
1207 DEFUN (no_bgp_cluster_id,
1208 no_bgp_cluster_id_cmd,
1209 "no bgp cluster-id [<A.B.C.D|(1-4294967295)>]",
1210 NO_STR
1211 BGP_STR
1212 "Configure Route-Reflector Cluster-id\n"
1213 "Route-Reflector Cluster-id in IP address format\n"
1214 "Route-Reflector Cluster-id as 32 bit quantity\n")
1215 {
1216 VTY_DECLVAR_CONTEXT(bgp, bgp);
1217 bgp_cluster_id_unset(bgp);
1218 bgp_clear_star_soft_out(vty, bgp->name);
1219
1220 return CMD_SUCCESS;
1221 }
1222
1223 DEFUN (bgp_confederation_identifier,
1224 bgp_confederation_identifier_cmd,
1225 "bgp confederation identifier (1-4294967295)",
1226 "BGP specific commands\n"
1227 "AS confederation parameters\n"
1228 "AS number\n"
1229 "Set routing domain confederation AS\n")
1230 {
1231 VTY_DECLVAR_CONTEXT(bgp, bgp);
1232 int idx_number = 3;
1233 as_t as;
1234
1235 as = strtoul(argv[idx_number]->arg, NULL, 10);
1236
1237 bgp_confederation_id_set(bgp, as);
1238
1239 return CMD_SUCCESS;
1240 }
1241
1242 DEFUN (no_bgp_confederation_identifier,
1243 no_bgp_confederation_identifier_cmd,
1244 "no bgp confederation identifier [(1-4294967295)]",
1245 NO_STR
1246 "BGP specific commands\n"
1247 "AS confederation parameters\n"
1248 "AS number\n"
1249 "Set routing domain confederation AS\n")
1250 {
1251 VTY_DECLVAR_CONTEXT(bgp, bgp);
1252 bgp_confederation_id_unset(bgp);
1253
1254 return CMD_SUCCESS;
1255 }
1256
1257 DEFUN (bgp_confederation_peers,
1258 bgp_confederation_peers_cmd,
1259 "bgp confederation peers (1-4294967295)...",
1260 "BGP specific commands\n"
1261 "AS confederation parameters\n"
1262 "Peer ASs in BGP confederation\n"
1263 AS_STR)
1264 {
1265 VTY_DECLVAR_CONTEXT(bgp, bgp);
1266 int idx_asn = 3;
1267 as_t as;
1268 int i;
1269
1270 for (i = idx_asn; i < argc; i++) {
1271 as = strtoul(argv[i]->arg, NULL, 10);
1272
1273 if (bgp->as == as) {
1274 vty_out(vty,
1275 "%% Local member-AS not allowed in confed peer list\n");
1276 continue;
1277 }
1278
1279 bgp_confederation_peers_add(bgp, as);
1280 }
1281 return CMD_SUCCESS;
1282 }
1283
1284 DEFUN (no_bgp_confederation_peers,
1285 no_bgp_confederation_peers_cmd,
1286 "no bgp confederation peers (1-4294967295)...",
1287 NO_STR
1288 "BGP specific commands\n"
1289 "AS confederation parameters\n"
1290 "Peer ASs in BGP confederation\n"
1291 AS_STR)
1292 {
1293 VTY_DECLVAR_CONTEXT(bgp, bgp);
1294 int idx_asn = 4;
1295 as_t as;
1296 int i;
1297
1298 for (i = idx_asn; i < argc; i++) {
1299 as = strtoul(argv[i]->arg, NULL, 10);
1300
1301 bgp_confederation_peers_remove(bgp, as);
1302 }
1303 return CMD_SUCCESS;
1304 }
1305
1306 /**
1307 * Central routine for maximum-paths configuration.
1308 * @peer_type: BGP_PEER_EBGP or BGP_PEER_IBGP
1309 * @set: 1 for setting values, 0 for removing the max-paths config.
1310 */
1311 static int bgp_maxpaths_config_vty(struct vty *vty, int peer_type,
1312 const char *mpaths, uint16_t options,
1313 int set)
1314 {
1315 VTY_DECLVAR_CONTEXT(bgp, bgp);
1316 uint16_t maxpaths = 0;
1317 int ret;
1318 afi_t afi;
1319 safi_t safi;
1320
1321 afi = bgp_node_afi(vty);
1322 safi = bgp_node_safi(vty);
1323
1324 if (set) {
1325 maxpaths = strtol(mpaths, NULL, 10);
1326 if (maxpaths > multipath_num) {
1327 vty_out(vty,
1328 "%% Maxpaths Specified: %d is > than multipath num specified on bgp command line %d",
1329 maxpaths, multipath_num);
1330 return CMD_WARNING_CONFIG_FAILED;
1331 }
1332 ret = bgp_maximum_paths_set(bgp, afi, safi, peer_type, maxpaths,
1333 options);
1334 } else
1335 ret = bgp_maximum_paths_unset(bgp, afi, safi, peer_type);
1336
1337 if (ret < 0) {
1338 vty_out(vty,
1339 "%% Failed to %sset maximum-paths %s %u for afi %u, safi %u\n",
1340 (set == 1) ? "" : "un",
1341 (peer_type == BGP_PEER_EBGP) ? "ebgp" : "ibgp",
1342 maxpaths, afi, safi);
1343 return CMD_WARNING_CONFIG_FAILED;
1344 }
1345
1346 bgp_recalculate_all_bestpaths(bgp);
1347
1348 return CMD_SUCCESS;
1349 }
1350
1351 DEFUN (bgp_maxmed_admin,
1352 bgp_maxmed_admin_cmd,
1353 "bgp max-med administrative ",
1354 BGP_STR
1355 "Advertise routes with max-med\n"
1356 "Administratively applied, for an indefinite period\n")
1357 {
1358 VTY_DECLVAR_CONTEXT(bgp, bgp);
1359
1360 bgp->v_maxmed_admin = 1;
1361 bgp->maxmed_admin_value = BGP_MAXMED_VALUE_DEFAULT;
1362
1363 bgp_maxmed_update(bgp);
1364
1365 return CMD_SUCCESS;
1366 }
1367
1368 DEFUN (bgp_maxmed_admin_medv,
1369 bgp_maxmed_admin_medv_cmd,
1370 "bgp max-med administrative (0-4294967295)",
1371 BGP_STR
1372 "Advertise routes with max-med\n"
1373 "Administratively applied, for an indefinite period\n"
1374 "Max MED value to be used\n")
1375 {
1376 VTY_DECLVAR_CONTEXT(bgp, bgp);
1377 int idx_number = 3;
1378
1379 bgp->v_maxmed_admin = 1;
1380 bgp->maxmed_admin_value = strtoul(argv[idx_number]->arg, NULL, 10);
1381
1382 bgp_maxmed_update(bgp);
1383
1384 return CMD_SUCCESS;
1385 }
1386
1387 DEFUN (no_bgp_maxmed_admin,
1388 no_bgp_maxmed_admin_cmd,
1389 "no bgp max-med administrative [(0-4294967295)]",
1390 NO_STR
1391 BGP_STR
1392 "Advertise routes with max-med\n"
1393 "Administratively applied, for an indefinite period\n"
1394 "Max MED value to be used\n")
1395 {
1396 VTY_DECLVAR_CONTEXT(bgp, bgp);
1397 bgp->v_maxmed_admin = BGP_MAXMED_ADMIN_UNCONFIGURED;
1398 bgp->maxmed_admin_value = BGP_MAXMED_VALUE_DEFAULT;
1399 bgp_maxmed_update(bgp);
1400
1401 return CMD_SUCCESS;
1402 }
1403
1404 DEFUN (bgp_maxmed_onstartup,
1405 bgp_maxmed_onstartup_cmd,
1406 "bgp max-med on-startup (5-86400) [(0-4294967295)]",
1407 BGP_STR
1408 "Advertise routes with max-med\n"
1409 "Effective on a startup\n"
1410 "Time (seconds) period for max-med\n"
1411 "Max MED value to be used\n")
1412 {
1413 VTY_DECLVAR_CONTEXT(bgp, bgp);
1414 int idx = 0;
1415
1416 argv_find(argv, argc, "(5-86400)", &idx);
1417 bgp->v_maxmed_onstartup = strtoul(argv[idx]->arg, NULL, 10);
1418 if (argv_find(argv, argc, "(0-4294967295)", &idx))
1419 bgp->maxmed_onstartup_value = strtoul(argv[idx]->arg, NULL, 10);
1420 else
1421 bgp->maxmed_onstartup_value = BGP_MAXMED_VALUE_DEFAULT;
1422
1423 bgp_maxmed_update(bgp);
1424
1425 return CMD_SUCCESS;
1426 }
1427
1428 DEFUN (no_bgp_maxmed_onstartup,
1429 no_bgp_maxmed_onstartup_cmd,
1430 "no bgp max-med on-startup [(5-86400) [(0-4294967295)]]",
1431 NO_STR
1432 BGP_STR
1433 "Advertise routes with max-med\n"
1434 "Effective on a startup\n"
1435 "Time (seconds) period for max-med\n"
1436 "Max MED value to be used\n")
1437 {
1438 VTY_DECLVAR_CONTEXT(bgp, bgp);
1439
1440 /* Cancel max-med onstartup if its on */
1441 if (bgp->t_maxmed_onstartup) {
1442 THREAD_TIMER_OFF(bgp->t_maxmed_onstartup);
1443 bgp->maxmed_onstartup_over = 1;
1444 }
1445
1446 bgp->v_maxmed_onstartup = BGP_MAXMED_ONSTARTUP_UNCONFIGURED;
1447 bgp->maxmed_onstartup_value = BGP_MAXMED_VALUE_DEFAULT;
1448
1449 bgp_maxmed_update(bgp);
1450
1451 return CMD_SUCCESS;
1452 }
1453
1454 static int bgp_update_delay_config_vty(struct vty *vty, const char *delay,
1455 const char *wait)
1456 {
1457 VTY_DECLVAR_CONTEXT(bgp, bgp);
1458 uint16_t update_delay;
1459 uint16_t establish_wait;
1460
1461 update_delay = strtoul(delay, NULL, 10);
1462
1463 if (!wait) /* update-delay <delay> */
1464 {
1465 bgp->v_update_delay = update_delay;
1466 bgp->v_establish_wait = bgp->v_update_delay;
1467 return CMD_SUCCESS;
1468 }
1469
1470 /* update-delay <delay> <establish-wait> */
1471 establish_wait = atoi(wait);
1472 if (update_delay < establish_wait) {
1473 vty_out(vty,
1474 "%%Failed: update-delay less than the establish-wait!\n");
1475 return CMD_WARNING_CONFIG_FAILED;
1476 }
1477
1478 bgp->v_update_delay = update_delay;
1479 bgp->v_establish_wait = establish_wait;
1480
1481 return CMD_SUCCESS;
1482 }
1483
1484 static int bgp_update_delay_deconfig_vty(struct vty *vty)
1485 {
1486 VTY_DECLVAR_CONTEXT(bgp, bgp);
1487
1488 bgp->v_update_delay = BGP_UPDATE_DELAY_DEF;
1489 bgp->v_establish_wait = bgp->v_update_delay;
1490
1491 return CMD_SUCCESS;
1492 }
1493
1494 void bgp_config_write_update_delay(struct vty *vty, struct bgp *bgp)
1495 {
1496 if (bgp->v_update_delay != BGP_UPDATE_DELAY_DEF) {
1497 vty_out(vty, " update-delay %d", bgp->v_update_delay);
1498 if (bgp->v_update_delay != bgp->v_establish_wait)
1499 vty_out(vty, " %d", bgp->v_establish_wait);
1500 vty_out(vty, "\n");
1501 }
1502 }
1503
1504
1505 /* Update-delay configuration */
1506 DEFUN (bgp_update_delay,
1507 bgp_update_delay_cmd,
1508 "update-delay (0-3600)",
1509 "Force initial delay for best-path and updates\n"
1510 "Seconds\n")
1511 {
1512 int idx_number = 1;
1513 return bgp_update_delay_config_vty(vty, argv[idx_number]->arg, NULL);
1514 }
1515
1516 DEFUN (bgp_update_delay_establish_wait,
1517 bgp_update_delay_establish_wait_cmd,
1518 "update-delay (0-3600) (1-3600)",
1519 "Force initial delay for best-path and updates\n"
1520 "Seconds\n"
1521 "Seconds\n")
1522 {
1523 int idx_number = 1;
1524 int idx_number_2 = 2;
1525 return bgp_update_delay_config_vty(vty, argv[idx_number]->arg,
1526 argv[idx_number_2]->arg);
1527 }
1528
1529 /* Update-delay deconfiguration */
1530 DEFUN (no_bgp_update_delay,
1531 no_bgp_update_delay_cmd,
1532 "no update-delay [(0-3600) [(1-3600)]]",
1533 NO_STR
1534 "Force initial delay for best-path and updates\n"
1535 "Seconds\n"
1536 "Seconds\n")
1537 {
1538 return bgp_update_delay_deconfig_vty(vty);
1539 }
1540
1541
1542 static int bgp_wpkt_quanta_config_vty(struct vty *vty, const char *num,
1543 char set)
1544 {
1545 VTY_DECLVAR_CONTEXT(bgp, bgp);
1546
1547 if (set) {
1548 uint32_t quanta = strtoul(num, NULL, 10);
1549 atomic_store_explicit(&bgp->wpkt_quanta, quanta,
1550 memory_order_relaxed);
1551 } else {
1552 atomic_store_explicit(&bgp->wpkt_quanta, BGP_WRITE_PACKET_MAX,
1553 memory_order_relaxed);
1554 }
1555
1556 return CMD_SUCCESS;
1557 }
1558
1559 static int bgp_rpkt_quanta_config_vty(struct vty *vty, const char *num,
1560 char set)
1561 {
1562 VTY_DECLVAR_CONTEXT(bgp, bgp);
1563
1564 if (set) {
1565 uint32_t quanta = strtoul(num, NULL, 10);
1566 atomic_store_explicit(&bgp->rpkt_quanta, quanta,
1567 memory_order_relaxed);
1568 } else {
1569 atomic_store_explicit(&bgp->rpkt_quanta, BGP_READ_PACKET_MAX,
1570 memory_order_relaxed);
1571 }
1572
1573 return CMD_SUCCESS;
1574 }
1575
1576 void bgp_config_write_wpkt_quanta(struct vty *vty, struct bgp *bgp)
1577 {
1578 uint32_t quanta =
1579 atomic_load_explicit(&bgp->wpkt_quanta, memory_order_relaxed);
1580 if (quanta != BGP_WRITE_PACKET_MAX)
1581 vty_out(vty, " write-quanta %d\n", quanta);
1582 }
1583
1584 void bgp_config_write_rpkt_quanta(struct vty *vty, struct bgp *bgp)
1585 {
1586 uint32_t quanta =
1587 atomic_load_explicit(&bgp->rpkt_quanta, memory_order_relaxed);
1588 if (quanta != BGP_READ_PACKET_MAX)
1589 vty_out(vty, " read-quanta %d\n", quanta);
1590 }
1591
1592 /* Packet quanta configuration */
1593 DEFUN (bgp_wpkt_quanta,
1594 bgp_wpkt_quanta_cmd,
1595 "write-quanta (1-10)",
1596 "How many packets to write to peer socket per run\n"
1597 "Number of packets\n")
1598 {
1599 int idx_number = 1;
1600 return bgp_wpkt_quanta_config_vty(vty, argv[idx_number]->arg, 1);
1601 }
1602
1603 DEFUN (no_bgp_wpkt_quanta,
1604 no_bgp_wpkt_quanta_cmd,
1605 "no write-quanta (1-10)",
1606 NO_STR
1607 "How many packets to write to peer socket per I/O cycle\n"
1608 "Number of packets\n")
1609 {
1610 int idx_number = 2;
1611 return bgp_wpkt_quanta_config_vty(vty, argv[idx_number]->arg, 0);
1612 }
1613
1614 DEFUN (bgp_rpkt_quanta,
1615 bgp_rpkt_quanta_cmd,
1616 "read-quanta (1-10)",
1617 "How many packets to read from peer socket per I/O cycle\n"
1618 "Number of packets\n")
1619 {
1620 int idx_number = 1;
1621 return bgp_rpkt_quanta_config_vty(vty, argv[idx_number]->arg, 1);
1622 }
1623
1624 DEFUN (no_bgp_rpkt_quanta,
1625 no_bgp_rpkt_quanta_cmd,
1626 "no read-quanta (1-10)",
1627 NO_STR
1628 "How many packets to read from peer socket per I/O cycle\n"
1629 "Number of packets\n")
1630 {
1631 int idx_number = 2;
1632 return bgp_rpkt_quanta_config_vty(vty, argv[idx_number]->arg, 0);
1633 }
1634
1635 void bgp_config_write_coalesce_time(struct vty *vty, struct bgp *bgp)
1636 {
1637 if (!bgp->heuristic_coalesce)
1638 vty_out(vty, " coalesce-time %u\n", bgp->coalesce_time);
1639 }
1640
1641
1642 DEFUN (bgp_coalesce_time,
1643 bgp_coalesce_time_cmd,
1644 "coalesce-time (0-4294967295)",
1645 "Subgroup coalesce timer\n"
1646 "Subgroup coalesce timer value (in ms)\n")
1647 {
1648 VTY_DECLVAR_CONTEXT(bgp, bgp);
1649
1650 int idx = 0;
1651 argv_find(argv, argc, "(0-4294967295)", &idx);
1652 bgp->heuristic_coalesce = false;
1653 bgp->coalesce_time = strtoul(argv[idx]->arg, NULL, 10);
1654 return CMD_SUCCESS;
1655 }
1656
1657 DEFUN (no_bgp_coalesce_time,
1658 no_bgp_coalesce_time_cmd,
1659 "no coalesce-time (0-4294967295)",
1660 NO_STR
1661 "Subgroup coalesce timer\n"
1662 "Subgroup coalesce timer value (in ms)\n")
1663 {
1664 VTY_DECLVAR_CONTEXT(bgp, bgp);
1665
1666 bgp->heuristic_coalesce = true;
1667 bgp->coalesce_time = BGP_DEFAULT_SUBGROUP_COALESCE_TIME;
1668 return CMD_SUCCESS;
1669 }
1670
1671 /* Maximum-paths configuration */
1672 DEFUN (bgp_maxpaths,
1673 bgp_maxpaths_cmd,
1674 "maximum-paths " CMD_RANGE_STR(1, MULTIPATH_NUM),
1675 "Forward packets over multiple paths\n"
1676 "Number of paths\n")
1677 {
1678 int idx_number = 1;
1679 return bgp_maxpaths_config_vty(vty, BGP_PEER_EBGP,
1680 argv[idx_number]->arg, 0, 1);
1681 }
1682
1683 ALIAS_HIDDEN(bgp_maxpaths, bgp_maxpaths_hidden_cmd,
1684 "maximum-paths " CMD_RANGE_STR(1, MULTIPATH_NUM),
1685 "Forward packets over multiple paths\n"
1686 "Number of paths\n")
1687
1688 DEFUN (bgp_maxpaths_ibgp,
1689 bgp_maxpaths_ibgp_cmd,
1690 "maximum-paths ibgp " CMD_RANGE_STR(1, MULTIPATH_NUM),
1691 "Forward packets over multiple paths\n"
1692 "iBGP-multipath\n"
1693 "Number of paths\n")
1694 {
1695 int idx_number = 2;
1696 return bgp_maxpaths_config_vty(vty, BGP_PEER_IBGP,
1697 argv[idx_number]->arg, 0, 1);
1698 }
1699
1700 ALIAS_HIDDEN(bgp_maxpaths_ibgp, bgp_maxpaths_ibgp_hidden_cmd,
1701 "maximum-paths ibgp " CMD_RANGE_STR(1, MULTIPATH_NUM),
1702 "Forward packets over multiple paths\n"
1703 "iBGP-multipath\n"
1704 "Number of paths\n")
1705
1706 DEFUN (bgp_maxpaths_ibgp_cluster,
1707 bgp_maxpaths_ibgp_cluster_cmd,
1708 "maximum-paths ibgp " CMD_RANGE_STR(1, MULTIPATH_NUM) " equal-cluster-length",
1709 "Forward packets over multiple paths\n"
1710 "iBGP-multipath\n"
1711 "Number of paths\n"
1712 "Match the cluster length\n")
1713 {
1714 int idx_number = 2;
1715 return bgp_maxpaths_config_vty(
1716 vty, BGP_PEER_IBGP, argv[idx_number]->arg,
1717 BGP_FLAG_IBGP_MULTIPATH_SAME_CLUSTERLEN, 1);
1718 }
1719
1720 ALIAS_HIDDEN(bgp_maxpaths_ibgp_cluster, bgp_maxpaths_ibgp_cluster_hidden_cmd,
1721 "maximum-paths ibgp " CMD_RANGE_STR(
1722 1, MULTIPATH_NUM) " equal-cluster-length",
1723 "Forward packets over multiple paths\n"
1724 "iBGP-multipath\n"
1725 "Number of paths\n"
1726 "Match the cluster length\n")
1727
1728 DEFUN (no_bgp_maxpaths,
1729 no_bgp_maxpaths_cmd,
1730 "no maximum-paths [" CMD_RANGE_STR(1, MULTIPATH_NUM) "]",
1731 NO_STR
1732 "Forward packets over multiple paths\n"
1733 "Number of paths\n")
1734 {
1735 return bgp_maxpaths_config_vty(vty, BGP_PEER_EBGP, NULL, 0, 0);
1736 }
1737
1738 ALIAS_HIDDEN(no_bgp_maxpaths, no_bgp_maxpaths_hidden_cmd,
1739 "no maximum-paths [" CMD_RANGE_STR(1, MULTIPATH_NUM) "]", NO_STR
1740 "Forward packets over multiple paths\n"
1741 "Number of paths\n")
1742
1743 DEFUN (no_bgp_maxpaths_ibgp,
1744 no_bgp_maxpaths_ibgp_cmd,
1745 "no maximum-paths ibgp [" CMD_RANGE_STR(1, MULTIPATH_NUM) " [equal-cluster-length]]",
1746 NO_STR
1747 "Forward packets over multiple paths\n"
1748 "iBGP-multipath\n"
1749 "Number of paths\n"
1750 "Match the cluster length\n")
1751 {
1752 return bgp_maxpaths_config_vty(vty, BGP_PEER_IBGP, NULL, 0, 0);
1753 }
1754
1755 ALIAS_HIDDEN(no_bgp_maxpaths_ibgp, no_bgp_maxpaths_ibgp_hidden_cmd,
1756 "no maximum-paths ibgp [" CMD_RANGE_STR(
1757 1, MULTIPATH_NUM) " [equal-cluster-length]]",
1758 NO_STR
1759 "Forward packets over multiple paths\n"
1760 "iBGP-multipath\n"
1761 "Number of paths\n"
1762 "Match the cluster length\n")
1763
1764 void bgp_config_write_maxpaths(struct vty *vty, struct bgp *bgp, afi_t afi,
1765 safi_t safi)
1766 {
1767 if (bgp->maxpaths[afi][safi].maxpaths_ebgp != MULTIPATH_NUM) {
1768 vty_out(vty, " maximum-paths %d\n",
1769 bgp->maxpaths[afi][safi].maxpaths_ebgp);
1770 }
1771
1772 if (bgp->maxpaths[afi][safi].maxpaths_ibgp != MULTIPATH_NUM) {
1773 vty_out(vty, " maximum-paths ibgp %d",
1774 bgp->maxpaths[afi][safi].maxpaths_ibgp);
1775 if (CHECK_FLAG(bgp->maxpaths[afi][safi].ibgp_flags,
1776 BGP_FLAG_IBGP_MULTIPATH_SAME_CLUSTERLEN))
1777 vty_out(vty, " equal-cluster-length");
1778 vty_out(vty, "\n");
1779 }
1780 }
1781
1782 /* BGP timers. */
1783
1784 DEFUN (bgp_timers,
1785 bgp_timers_cmd,
1786 "timers bgp (0-65535) (0-65535)",
1787 "Adjust routing timers\n"
1788 "BGP timers\n"
1789 "Keepalive interval\n"
1790 "Holdtime\n")
1791 {
1792 VTY_DECLVAR_CONTEXT(bgp, bgp);
1793 int idx_number = 2;
1794 int idx_number_2 = 3;
1795 unsigned long keepalive = 0;
1796 unsigned long holdtime = 0;
1797
1798 keepalive = strtoul(argv[idx_number]->arg, NULL, 10);
1799 holdtime = strtoul(argv[idx_number_2]->arg, NULL, 10);
1800
1801 /* Holdtime value check. */
1802 if (holdtime < 3 && holdtime != 0) {
1803 vty_out(vty,
1804 "%% hold time value must be either 0 or greater than 3\n");
1805 return CMD_WARNING_CONFIG_FAILED;
1806 }
1807
1808 bgp_timers_set(bgp, keepalive, holdtime);
1809
1810 return CMD_SUCCESS;
1811 }
1812
1813 DEFUN (no_bgp_timers,
1814 no_bgp_timers_cmd,
1815 "no timers bgp [(0-65535) (0-65535)]",
1816 NO_STR
1817 "Adjust routing timers\n"
1818 "BGP timers\n"
1819 "Keepalive interval\n"
1820 "Holdtime\n")
1821 {
1822 VTY_DECLVAR_CONTEXT(bgp, bgp);
1823 bgp_timers_unset(bgp);
1824
1825 return CMD_SUCCESS;
1826 }
1827
1828
1829 DEFUN (bgp_client_to_client_reflection,
1830 bgp_client_to_client_reflection_cmd,
1831 "bgp client-to-client reflection",
1832 "BGP specific commands\n"
1833 "Configure client to client route reflection\n"
1834 "reflection of routes allowed\n")
1835 {
1836 VTY_DECLVAR_CONTEXT(bgp, bgp);
1837 bgp_flag_unset(bgp, BGP_FLAG_NO_CLIENT_TO_CLIENT);
1838 bgp_clear_star_soft_out(vty, bgp->name);
1839
1840 return CMD_SUCCESS;
1841 }
1842
1843 DEFUN (no_bgp_client_to_client_reflection,
1844 no_bgp_client_to_client_reflection_cmd,
1845 "no bgp client-to-client reflection",
1846 NO_STR
1847 "BGP specific commands\n"
1848 "Configure client to client route reflection\n"
1849 "reflection of routes allowed\n")
1850 {
1851 VTY_DECLVAR_CONTEXT(bgp, bgp);
1852 bgp_flag_set(bgp, BGP_FLAG_NO_CLIENT_TO_CLIENT);
1853 bgp_clear_star_soft_out(vty, bgp->name);
1854
1855 return CMD_SUCCESS;
1856 }
1857
1858 /* "bgp always-compare-med" configuration. */
1859 DEFUN (bgp_always_compare_med,
1860 bgp_always_compare_med_cmd,
1861 "bgp always-compare-med",
1862 "BGP specific commands\n"
1863 "Allow comparing MED from different neighbors\n")
1864 {
1865 VTY_DECLVAR_CONTEXT(bgp, bgp);
1866 bgp_flag_set(bgp, BGP_FLAG_ALWAYS_COMPARE_MED);
1867 bgp_recalculate_all_bestpaths(bgp);
1868
1869 return CMD_SUCCESS;
1870 }
1871
1872 DEFUN (no_bgp_always_compare_med,
1873 no_bgp_always_compare_med_cmd,
1874 "no bgp always-compare-med",
1875 NO_STR
1876 "BGP specific commands\n"
1877 "Allow comparing MED from different neighbors\n")
1878 {
1879 VTY_DECLVAR_CONTEXT(bgp, bgp);
1880 bgp_flag_unset(bgp, BGP_FLAG_ALWAYS_COMPARE_MED);
1881 bgp_recalculate_all_bestpaths(bgp);
1882
1883 return CMD_SUCCESS;
1884 }
1885
1886
1887 DEFUN(bgp_ebgp_requires_policy, bgp_ebgp_requires_policy_cmd,
1888 "bgp ebgp-requires-policy",
1889 "BGP specific commands\n"
1890 "Require in and out policy for eBGP peers (RFC8212)\n")
1891 {
1892 VTY_DECLVAR_CONTEXT(bgp, bgp);
1893 bgp->ebgp_requires_policy = DEFAULT_EBGP_POLICY_ENABLED;
1894 return CMD_SUCCESS;
1895 }
1896
1897 DEFUN(no_bgp_ebgp_requires_policy, no_bgp_ebgp_requires_policy_cmd,
1898 "no bgp ebgp-requires-policy",
1899 NO_STR
1900 "BGP specific commands\n"
1901 "Require in and out policy for eBGP peers (RFC8212)\n")
1902 {
1903 VTY_DECLVAR_CONTEXT(bgp, bgp);
1904 bgp->ebgp_requires_policy = DEFAULT_EBGP_POLICY_DISABLED;
1905 return CMD_SUCCESS;
1906 }
1907
1908
1909 /* "bgp deterministic-med" configuration. */
1910 DEFUN (bgp_deterministic_med,
1911 bgp_deterministic_med_cmd,
1912 "bgp deterministic-med",
1913 "BGP specific commands\n"
1914 "Pick the best-MED path among paths advertised from the neighboring AS\n")
1915 {
1916 VTY_DECLVAR_CONTEXT(bgp, bgp);
1917
1918 if (!bgp_flag_check(bgp, BGP_FLAG_DETERMINISTIC_MED)) {
1919 bgp_flag_set(bgp, BGP_FLAG_DETERMINISTIC_MED);
1920 bgp_recalculate_all_bestpaths(bgp);
1921 }
1922
1923 return CMD_SUCCESS;
1924 }
1925
1926 DEFUN (no_bgp_deterministic_med,
1927 no_bgp_deterministic_med_cmd,
1928 "no bgp deterministic-med",
1929 NO_STR
1930 "BGP specific commands\n"
1931 "Pick the best-MED path among paths advertised from the neighboring AS\n")
1932 {
1933 VTY_DECLVAR_CONTEXT(bgp, bgp);
1934 int bestpath_per_as_used;
1935 afi_t afi;
1936 safi_t safi;
1937 struct peer *peer;
1938 struct listnode *node, *nnode;
1939
1940 if (bgp_flag_check(bgp, BGP_FLAG_DETERMINISTIC_MED)) {
1941 bestpath_per_as_used = 0;
1942
1943 for (ALL_LIST_ELEMENTS(bgp->peer, node, nnode, peer)) {
1944 FOREACH_AFI_SAFI (afi, safi)
1945 if (bgp_addpath_dmed_required(
1946 peer->addpath_type[afi][safi])) {
1947 bestpath_per_as_used = 1;
1948 break;
1949 }
1950
1951 if (bestpath_per_as_used)
1952 break;
1953 }
1954
1955 if (bestpath_per_as_used) {
1956 vty_out(vty,
1957 "bgp deterministic-med cannot be disabled while addpath-tx-bestpath-per-AS is in use\n");
1958 return CMD_WARNING_CONFIG_FAILED;
1959 } else {
1960 bgp_flag_unset(bgp, BGP_FLAG_DETERMINISTIC_MED);
1961 bgp_recalculate_all_bestpaths(bgp);
1962 }
1963 }
1964
1965 return CMD_SUCCESS;
1966 }
1967
1968 /* "bgp graceful-restart" configuration. */
1969 DEFUN (bgp_graceful_restart,
1970 bgp_graceful_restart_cmd,
1971 "bgp graceful-restart",
1972 "BGP specific commands\n"
1973 "Graceful restart capability parameters\n")
1974 {
1975 VTY_DECLVAR_CONTEXT(bgp, bgp);
1976 bgp_flag_set(bgp, BGP_FLAG_GRACEFUL_RESTART);
1977 return CMD_SUCCESS;
1978 }
1979
1980 DEFUN (no_bgp_graceful_restart,
1981 no_bgp_graceful_restart_cmd,
1982 "no bgp graceful-restart",
1983 NO_STR
1984 "BGP specific commands\n"
1985 "Graceful restart capability parameters\n")
1986 {
1987 VTY_DECLVAR_CONTEXT(bgp, bgp);
1988 bgp_flag_unset(bgp, BGP_FLAG_GRACEFUL_RESTART);
1989 return CMD_SUCCESS;
1990 }
1991
1992 DEFUN (bgp_graceful_restart_stalepath_time,
1993 bgp_graceful_restart_stalepath_time_cmd,
1994 "bgp graceful-restart stalepath-time (1-4095)",
1995 "BGP specific commands\n"
1996 "Graceful restart capability parameters\n"
1997 "Set the max time to hold onto restarting peer's stale paths\n"
1998 "Delay value (seconds)\n")
1999 {
2000 VTY_DECLVAR_CONTEXT(bgp, bgp);
2001 int idx_number = 3;
2002 uint32_t stalepath;
2003
2004 stalepath = strtoul(argv[idx_number]->arg, NULL, 10);
2005 bgp->stalepath_time = stalepath;
2006 return CMD_SUCCESS;
2007 }
2008
2009 DEFUN (bgp_graceful_restart_restart_time,
2010 bgp_graceful_restart_restart_time_cmd,
2011 "bgp graceful-restart restart-time (1-4095)",
2012 "BGP specific commands\n"
2013 "Graceful restart capability parameters\n"
2014 "Set the time to wait to delete stale routes before a BGP open message is received\n"
2015 "Delay value (seconds)\n")
2016 {
2017 VTY_DECLVAR_CONTEXT(bgp, bgp);
2018 int idx_number = 3;
2019 uint32_t restart;
2020
2021 restart = strtoul(argv[idx_number]->arg, NULL, 10);
2022 bgp->restart_time = restart;
2023 return CMD_SUCCESS;
2024 }
2025
2026 DEFUN (no_bgp_graceful_restart_stalepath_time,
2027 no_bgp_graceful_restart_stalepath_time_cmd,
2028 "no bgp graceful-restart stalepath-time [(1-4095)]",
2029 NO_STR
2030 "BGP specific commands\n"
2031 "Graceful restart capability parameters\n"
2032 "Set the max time to hold onto restarting peer's stale paths\n"
2033 "Delay value (seconds)\n")
2034 {
2035 VTY_DECLVAR_CONTEXT(bgp, bgp);
2036
2037 bgp->stalepath_time = BGP_DEFAULT_STALEPATH_TIME;
2038 return CMD_SUCCESS;
2039 }
2040
2041 DEFUN (no_bgp_graceful_restart_restart_time,
2042 no_bgp_graceful_restart_restart_time_cmd,
2043 "no bgp graceful-restart restart-time [(1-4095)]",
2044 NO_STR
2045 "BGP specific commands\n"
2046 "Graceful restart capability parameters\n"
2047 "Set the time to wait to delete stale routes before a BGP open message is received\n"
2048 "Delay value (seconds)\n")
2049 {
2050 VTY_DECLVAR_CONTEXT(bgp, bgp);
2051
2052 bgp->restart_time = BGP_DEFAULT_RESTART_TIME;
2053 return CMD_SUCCESS;
2054 }
2055
2056 DEFUN (bgp_graceful_restart_preserve_fw,
2057 bgp_graceful_restart_preserve_fw_cmd,
2058 "bgp graceful-restart preserve-fw-state",
2059 "BGP specific commands\n"
2060 "Graceful restart capability parameters\n"
2061 "Sets F-bit indication that fib is preserved while doing Graceful Restart\n")
2062 {
2063 VTY_DECLVAR_CONTEXT(bgp, bgp);
2064 bgp_flag_set(bgp, BGP_FLAG_GR_PRESERVE_FWD);
2065 return CMD_SUCCESS;
2066 }
2067
2068 DEFUN (no_bgp_graceful_restart_preserve_fw,
2069 no_bgp_graceful_restart_preserve_fw_cmd,
2070 "no bgp graceful-restart preserve-fw-state",
2071 NO_STR
2072 "BGP specific commands\n"
2073 "Graceful restart capability parameters\n"
2074 "Unsets F-bit indication that fib is preserved while doing Graceful Restart\n")
2075 {
2076 VTY_DECLVAR_CONTEXT(bgp, bgp);
2077 bgp_flag_unset(bgp, BGP_FLAG_GR_PRESERVE_FWD);
2078 return CMD_SUCCESS;
2079 }
2080
2081 /* "bgp graceful-shutdown" configuration */
2082 DEFUN (bgp_graceful_shutdown,
2083 bgp_graceful_shutdown_cmd,
2084 "bgp graceful-shutdown",
2085 BGP_STR
2086 "Graceful shutdown parameters\n")
2087 {
2088 VTY_DECLVAR_CONTEXT(bgp, bgp);
2089
2090 if (!bgp_flag_check(bgp, BGP_FLAG_GRACEFUL_SHUTDOWN)) {
2091 bgp_flag_set(bgp, BGP_FLAG_GRACEFUL_SHUTDOWN);
2092 bgp_static_redo_import_check(bgp);
2093 bgp_redistribute_redo(bgp);
2094 bgp_clear_star_soft_out(vty, bgp->name);
2095 bgp_clear_star_soft_in(vty, bgp->name);
2096 }
2097
2098 return CMD_SUCCESS;
2099 }
2100
2101 DEFUN (no_bgp_graceful_shutdown,
2102 no_bgp_graceful_shutdown_cmd,
2103 "no bgp graceful-shutdown",
2104 NO_STR
2105 BGP_STR
2106 "Graceful shutdown parameters\n")
2107 {
2108 VTY_DECLVAR_CONTEXT(bgp, bgp);
2109
2110 if (bgp_flag_check(bgp, BGP_FLAG_GRACEFUL_SHUTDOWN)) {
2111 bgp_flag_unset(bgp, BGP_FLAG_GRACEFUL_SHUTDOWN);
2112 bgp_static_redo_import_check(bgp);
2113 bgp_redistribute_redo(bgp);
2114 bgp_clear_star_soft_out(vty, bgp->name);
2115 bgp_clear_star_soft_in(vty, bgp->name);
2116 }
2117
2118 return CMD_SUCCESS;
2119 }
2120
2121 /* "bgp fast-external-failover" configuration. */
2122 DEFUN (bgp_fast_external_failover,
2123 bgp_fast_external_failover_cmd,
2124 "bgp fast-external-failover",
2125 BGP_STR
2126 "Immediately reset session if a link to a directly connected external peer goes down\n")
2127 {
2128 VTY_DECLVAR_CONTEXT(bgp, bgp);
2129 bgp_flag_unset(bgp, BGP_FLAG_NO_FAST_EXT_FAILOVER);
2130 return CMD_SUCCESS;
2131 }
2132
2133 DEFUN (no_bgp_fast_external_failover,
2134 no_bgp_fast_external_failover_cmd,
2135 "no bgp fast-external-failover",
2136 NO_STR
2137 BGP_STR
2138 "Immediately reset session if a link to a directly connected external peer goes down\n")
2139 {
2140 VTY_DECLVAR_CONTEXT(bgp, bgp);
2141 bgp_flag_set(bgp, BGP_FLAG_NO_FAST_EXT_FAILOVER);
2142 return CMD_SUCCESS;
2143 }
2144
2145 /* "bgp enforce-first-as" configuration. */
2146 #if CONFDATE > 20190517
2147 CPP_NOTICE("bgpd: remove deprecated '[no] bgp enforce-first-as' commands")
2148 #endif
2149
2150 DEFUN_HIDDEN (bgp_enforce_first_as,
2151 bgp_enforce_first_as_cmd,
2152 "[no] bgp enforce-first-as",
2153 NO_STR
2154 BGP_STR
2155 "Enforce the first AS for EBGP routes\n")
2156 {
2157 VTY_DECLVAR_CONTEXT(bgp, bgp);
2158
2159 if (strmatch(argv[0]->text, "no"))
2160 bgp_flag_unset(bgp, BGP_FLAG_ENFORCE_FIRST_AS);
2161 else
2162 bgp_flag_set(bgp, BGP_FLAG_ENFORCE_FIRST_AS);
2163
2164 return CMD_SUCCESS;
2165 }
2166
2167 /* "bgp bestpath compare-routerid" configuration. */
2168 DEFUN (bgp_bestpath_compare_router_id,
2169 bgp_bestpath_compare_router_id_cmd,
2170 "bgp bestpath compare-routerid",
2171 "BGP specific commands\n"
2172 "Change the default bestpath selection\n"
2173 "Compare router-id for identical EBGP paths\n")
2174 {
2175 VTY_DECLVAR_CONTEXT(bgp, bgp);
2176 bgp_flag_set(bgp, BGP_FLAG_COMPARE_ROUTER_ID);
2177 bgp_recalculate_all_bestpaths(bgp);
2178
2179 return CMD_SUCCESS;
2180 }
2181
2182 DEFUN (no_bgp_bestpath_compare_router_id,
2183 no_bgp_bestpath_compare_router_id_cmd,
2184 "no bgp bestpath compare-routerid",
2185 NO_STR
2186 "BGP specific commands\n"
2187 "Change the default bestpath selection\n"
2188 "Compare router-id for identical EBGP paths\n")
2189 {
2190 VTY_DECLVAR_CONTEXT(bgp, bgp);
2191 bgp_flag_unset(bgp, BGP_FLAG_COMPARE_ROUTER_ID);
2192 bgp_recalculate_all_bestpaths(bgp);
2193
2194 return CMD_SUCCESS;
2195 }
2196
2197 /* "bgp bestpath as-path ignore" configuration. */
2198 DEFUN (bgp_bestpath_aspath_ignore,
2199 bgp_bestpath_aspath_ignore_cmd,
2200 "bgp bestpath as-path ignore",
2201 "BGP specific commands\n"
2202 "Change the default bestpath selection\n"
2203 "AS-path attribute\n"
2204 "Ignore as-path length in selecting a route\n")
2205 {
2206 VTY_DECLVAR_CONTEXT(bgp, bgp);
2207 bgp_flag_set(bgp, BGP_FLAG_ASPATH_IGNORE);
2208 bgp_recalculate_all_bestpaths(bgp);
2209
2210 return CMD_SUCCESS;
2211 }
2212
2213 DEFUN (no_bgp_bestpath_aspath_ignore,
2214 no_bgp_bestpath_aspath_ignore_cmd,
2215 "no bgp bestpath as-path ignore",
2216 NO_STR
2217 "BGP specific commands\n"
2218 "Change the default bestpath selection\n"
2219 "AS-path attribute\n"
2220 "Ignore as-path length in selecting a route\n")
2221 {
2222 VTY_DECLVAR_CONTEXT(bgp, bgp);
2223 bgp_flag_unset(bgp, BGP_FLAG_ASPATH_IGNORE);
2224 bgp_recalculate_all_bestpaths(bgp);
2225
2226 return CMD_SUCCESS;
2227 }
2228
2229 /* "bgp bestpath as-path confed" configuration. */
2230 DEFUN (bgp_bestpath_aspath_confed,
2231 bgp_bestpath_aspath_confed_cmd,
2232 "bgp bestpath as-path confed",
2233 "BGP specific commands\n"
2234 "Change the default bestpath selection\n"
2235 "AS-path attribute\n"
2236 "Compare path lengths including confederation sets & sequences in selecting a route\n")
2237 {
2238 VTY_DECLVAR_CONTEXT(bgp, bgp);
2239 bgp_flag_set(bgp, BGP_FLAG_ASPATH_CONFED);
2240 bgp_recalculate_all_bestpaths(bgp);
2241
2242 return CMD_SUCCESS;
2243 }
2244
2245 DEFUN (no_bgp_bestpath_aspath_confed,
2246 no_bgp_bestpath_aspath_confed_cmd,
2247 "no bgp bestpath as-path confed",
2248 NO_STR
2249 "BGP specific commands\n"
2250 "Change the default bestpath selection\n"
2251 "AS-path attribute\n"
2252 "Compare path lengths including confederation sets & sequences in selecting a route\n")
2253 {
2254 VTY_DECLVAR_CONTEXT(bgp, bgp);
2255 bgp_flag_unset(bgp, BGP_FLAG_ASPATH_CONFED);
2256 bgp_recalculate_all_bestpaths(bgp);
2257
2258 return CMD_SUCCESS;
2259 }
2260
2261 /* "bgp bestpath as-path multipath-relax" configuration. */
2262 DEFUN (bgp_bestpath_aspath_multipath_relax,
2263 bgp_bestpath_aspath_multipath_relax_cmd,
2264 "bgp bestpath as-path multipath-relax [<as-set|no-as-set>]",
2265 "BGP specific commands\n"
2266 "Change the default bestpath selection\n"
2267 "AS-path attribute\n"
2268 "Allow load sharing across routes that have different AS paths (but same length)\n"
2269 "Generate an AS_SET\n"
2270 "Do not generate an AS_SET\n")
2271 {
2272 VTY_DECLVAR_CONTEXT(bgp, bgp);
2273 int idx = 0;
2274 bgp_flag_set(bgp, BGP_FLAG_ASPATH_MULTIPATH_RELAX);
2275
2276 /* no-as-set is now the default behavior so we can silently
2277 * ignore it */
2278 if (argv_find(argv, argc, "as-set", &idx))
2279 bgp_flag_set(bgp, BGP_FLAG_MULTIPATH_RELAX_AS_SET);
2280 else
2281 bgp_flag_unset(bgp, BGP_FLAG_MULTIPATH_RELAX_AS_SET);
2282
2283 bgp_recalculate_all_bestpaths(bgp);
2284
2285 return CMD_SUCCESS;
2286 }
2287
2288 DEFUN (no_bgp_bestpath_aspath_multipath_relax,
2289 no_bgp_bestpath_aspath_multipath_relax_cmd,
2290 "no bgp bestpath as-path multipath-relax [<as-set|no-as-set>]",
2291 NO_STR
2292 "BGP specific commands\n"
2293 "Change the default bestpath selection\n"
2294 "AS-path attribute\n"
2295 "Allow load sharing across routes that have different AS paths (but same length)\n"
2296 "Generate an AS_SET\n"
2297 "Do not generate an AS_SET\n")
2298 {
2299 VTY_DECLVAR_CONTEXT(bgp, bgp);
2300 bgp_flag_unset(bgp, BGP_FLAG_ASPATH_MULTIPATH_RELAX);
2301 bgp_flag_unset(bgp, BGP_FLAG_MULTIPATH_RELAX_AS_SET);
2302 bgp_recalculate_all_bestpaths(bgp);
2303
2304 return CMD_SUCCESS;
2305 }
2306
2307 /* "bgp log-neighbor-changes" configuration. */
2308 DEFUN (bgp_log_neighbor_changes,
2309 bgp_log_neighbor_changes_cmd,
2310 "bgp log-neighbor-changes",
2311 "BGP specific commands\n"
2312 "Log neighbor up/down and reset reason\n")
2313 {
2314 VTY_DECLVAR_CONTEXT(bgp, bgp);
2315 bgp_flag_set(bgp, BGP_FLAG_LOG_NEIGHBOR_CHANGES);
2316 return CMD_SUCCESS;
2317 }
2318
2319 DEFUN (no_bgp_log_neighbor_changes,
2320 no_bgp_log_neighbor_changes_cmd,
2321 "no bgp log-neighbor-changes",
2322 NO_STR
2323 "BGP specific commands\n"
2324 "Log neighbor up/down and reset reason\n")
2325 {
2326 VTY_DECLVAR_CONTEXT(bgp, bgp);
2327 bgp_flag_unset(bgp, BGP_FLAG_LOG_NEIGHBOR_CHANGES);
2328 return CMD_SUCCESS;
2329 }
2330
2331 /* "bgp bestpath med" configuration. */
2332 DEFUN (bgp_bestpath_med,
2333 bgp_bestpath_med_cmd,
2334 "bgp bestpath med <confed [missing-as-worst]|missing-as-worst [confed]>",
2335 "BGP specific commands\n"
2336 "Change the default bestpath selection\n"
2337 "MED attribute\n"
2338 "Compare MED among confederation paths\n"
2339 "Treat missing MED as the least preferred one\n"
2340 "Treat missing MED as the least preferred one\n"
2341 "Compare MED among confederation paths\n")
2342 {
2343 VTY_DECLVAR_CONTEXT(bgp, bgp);
2344
2345 int idx = 0;
2346 if (argv_find(argv, argc, "confed", &idx))
2347 bgp_flag_set(bgp, BGP_FLAG_MED_CONFED);
2348 idx = 0;
2349 if (argv_find(argv, argc, "missing-as-worst", &idx))
2350 bgp_flag_set(bgp, BGP_FLAG_MED_MISSING_AS_WORST);
2351
2352 bgp_recalculate_all_bestpaths(bgp);
2353
2354 return CMD_SUCCESS;
2355 }
2356
2357 DEFUN (no_bgp_bestpath_med,
2358 no_bgp_bestpath_med_cmd,
2359 "no bgp bestpath med <confed [missing-as-worst]|missing-as-worst [confed]>",
2360 NO_STR
2361 "BGP specific commands\n"
2362 "Change the default bestpath selection\n"
2363 "MED attribute\n"
2364 "Compare MED among confederation paths\n"
2365 "Treat missing MED as the least preferred one\n"
2366 "Treat missing MED as the least preferred one\n"
2367 "Compare MED among confederation paths\n")
2368 {
2369 VTY_DECLVAR_CONTEXT(bgp, bgp);
2370
2371 int idx = 0;
2372 if (argv_find(argv, argc, "confed", &idx))
2373 bgp_flag_unset(bgp, BGP_FLAG_MED_CONFED);
2374 idx = 0;
2375 if (argv_find(argv, argc, "missing-as-worst", &idx))
2376 bgp_flag_unset(bgp, BGP_FLAG_MED_MISSING_AS_WORST);
2377
2378 bgp_recalculate_all_bestpaths(bgp);
2379
2380 return CMD_SUCCESS;
2381 }
2382
2383 /* "no bgp default ipv4-unicast". */
2384 DEFUN (no_bgp_default_ipv4_unicast,
2385 no_bgp_default_ipv4_unicast_cmd,
2386 "no bgp default ipv4-unicast",
2387 NO_STR
2388 "BGP specific commands\n"
2389 "Configure BGP defaults\n"
2390 "Activate ipv4-unicast for a peer by default\n")
2391 {
2392 VTY_DECLVAR_CONTEXT(bgp, bgp);
2393 bgp_flag_set(bgp, BGP_FLAG_NO_DEFAULT_IPV4);
2394 return CMD_SUCCESS;
2395 }
2396
2397 DEFUN (bgp_default_ipv4_unicast,
2398 bgp_default_ipv4_unicast_cmd,
2399 "bgp default ipv4-unicast",
2400 "BGP specific commands\n"
2401 "Configure BGP defaults\n"
2402 "Activate ipv4-unicast for a peer by default\n")
2403 {
2404 VTY_DECLVAR_CONTEXT(bgp, bgp);
2405 bgp_flag_unset(bgp, BGP_FLAG_NO_DEFAULT_IPV4);
2406 return CMD_SUCCESS;
2407 }
2408
2409 /* Display hostname in certain command outputs */
2410 DEFUN (bgp_default_show_hostname,
2411 bgp_default_show_hostname_cmd,
2412 "bgp default show-hostname",
2413 "BGP specific commands\n"
2414 "Configure BGP defaults\n"
2415 "Show hostname in certain command outputs\n")
2416 {
2417 VTY_DECLVAR_CONTEXT(bgp, bgp);
2418 bgp_flag_set(bgp, BGP_FLAG_SHOW_HOSTNAME);
2419 return CMD_SUCCESS;
2420 }
2421
2422 DEFUN (no_bgp_default_show_hostname,
2423 no_bgp_default_show_hostname_cmd,
2424 "no bgp default show-hostname",
2425 NO_STR
2426 "BGP specific commands\n"
2427 "Configure BGP defaults\n"
2428 "Show hostname in certain command outputs\n")
2429 {
2430 VTY_DECLVAR_CONTEXT(bgp, bgp);
2431 bgp_flag_unset(bgp, BGP_FLAG_SHOW_HOSTNAME);
2432 return CMD_SUCCESS;
2433 }
2434
2435 /* "bgp network import-check" configuration. */
2436 DEFUN (bgp_network_import_check,
2437 bgp_network_import_check_cmd,
2438 "bgp network import-check",
2439 "BGP specific commands\n"
2440 "BGP network command\n"
2441 "Check BGP network route exists in IGP\n")
2442 {
2443 VTY_DECLVAR_CONTEXT(bgp, bgp);
2444 if (!bgp_flag_check(bgp, BGP_FLAG_IMPORT_CHECK)) {
2445 bgp_flag_set(bgp, BGP_FLAG_IMPORT_CHECK);
2446 bgp_static_redo_import_check(bgp);
2447 }
2448
2449 return CMD_SUCCESS;
2450 }
2451
2452 ALIAS_HIDDEN(bgp_network_import_check, bgp_network_import_check_exact_cmd,
2453 "bgp network import-check exact",
2454 "BGP specific commands\n"
2455 "BGP network command\n"
2456 "Check BGP network route exists in IGP\n"
2457 "Match route precisely\n")
2458
2459 DEFUN (no_bgp_network_import_check,
2460 no_bgp_network_import_check_cmd,
2461 "no bgp network import-check",
2462 NO_STR
2463 "BGP specific commands\n"
2464 "BGP network command\n"
2465 "Check BGP network route exists in IGP\n")
2466 {
2467 VTY_DECLVAR_CONTEXT(bgp, bgp);
2468 if (bgp_flag_check(bgp, BGP_FLAG_IMPORT_CHECK)) {
2469 bgp_flag_unset(bgp, BGP_FLAG_IMPORT_CHECK);
2470 bgp_static_redo_import_check(bgp);
2471 }
2472
2473 return CMD_SUCCESS;
2474 }
2475
2476 DEFUN (bgp_default_local_preference,
2477 bgp_default_local_preference_cmd,
2478 "bgp default local-preference (0-4294967295)",
2479 "BGP specific commands\n"
2480 "Configure BGP defaults\n"
2481 "local preference (higher=more preferred)\n"
2482 "Configure default local preference value\n")
2483 {
2484 VTY_DECLVAR_CONTEXT(bgp, bgp);
2485 int idx_number = 3;
2486 uint32_t local_pref;
2487
2488 local_pref = strtoul(argv[idx_number]->arg, NULL, 10);
2489
2490 bgp_default_local_preference_set(bgp, local_pref);
2491 bgp_clear_star_soft_in(vty, bgp->name);
2492
2493 return CMD_SUCCESS;
2494 }
2495
2496 DEFUN (no_bgp_default_local_preference,
2497 no_bgp_default_local_preference_cmd,
2498 "no bgp default local-preference [(0-4294967295)]",
2499 NO_STR
2500 "BGP specific commands\n"
2501 "Configure BGP defaults\n"
2502 "local preference (higher=more preferred)\n"
2503 "Configure default local preference value\n")
2504 {
2505 VTY_DECLVAR_CONTEXT(bgp, bgp);
2506 bgp_default_local_preference_unset(bgp);
2507 bgp_clear_star_soft_in(vty, bgp->name);
2508
2509 return CMD_SUCCESS;
2510 }
2511
2512
2513 DEFUN (bgp_default_subgroup_pkt_queue_max,
2514 bgp_default_subgroup_pkt_queue_max_cmd,
2515 "bgp default subgroup-pkt-queue-max (20-100)",
2516 "BGP specific commands\n"
2517 "Configure BGP defaults\n"
2518 "subgroup-pkt-queue-max\n"
2519 "Configure subgroup packet queue max\n")
2520 {
2521 VTY_DECLVAR_CONTEXT(bgp, bgp);
2522 int idx_number = 3;
2523 uint32_t max_size;
2524
2525 max_size = strtoul(argv[idx_number]->arg, NULL, 10);
2526
2527 bgp_default_subgroup_pkt_queue_max_set(bgp, max_size);
2528
2529 return CMD_SUCCESS;
2530 }
2531
2532 DEFUN (no_bgp_default_subgroup_pkt_queue_max,
2533 no_bgp_default_subgroup_pkt_queue_max_cmd,
2534 "no bgp default subgroup-pkt-queue-max [(20-100)]",
2535 NO_STR
2536 "BGP specific commands\n"
2537 "Configure BGP defaults\n"
2538 "subgroup-pkt-queue-max\n"
2539 "Configure subgroup packet queue max\n")
2540 {
2541 VTY_DECLVAR_CONTEXT(bgp, bgp);
2542 bgp_default_subgroup_pkt_queue_max_unset(bgp);
2543 return CMD_SUCCESS;
2544 }
2545
2546
2547 DEFUN (bgp_rr_allow_outbound_policy,
2548 bgp_rr_allow_outbound_policy_cmd,
2549 "bgp route-reflector allow-outbound-policy",
2550 "BGP specific commands\n"
2551 "Allow modifications made by out route-map\n"
2552 "on ibgp neighbors\n")
2553 {
2554 VTY_DECLVAR_CONTEXT(bgp, bgp);
2555
2556 if (!bgp_flag_check(bgp, BGP_FLAG_RR_ALLOW_OUTBOUND_POLICY)) {
2557 bgp_flag_set(bgp, BGP_FLAG_RR_ALLOW_OUTBOUND_POLICY);
2558 update_group_announce_rrclients(bgp);
2559 bgp_clear_star_soft_out(vty, bgp->name);
2560 }
2561
2562 return CMD_SUCCESS;
2563 }
2564
2565 DEFUN (no_bgp_rr_allow_outbound_policy,
2566 no_bgp_rr_allow_outbound_policy_cmd,
2567 "no bgp route-reflector allow-outbound-policy",
2568 NO_STR
2569 "BGP specific commands\n"
2570 "Allow modifications made by out route-map\n"
2571 "on ibgp neighbors\n")
2572 {
2573 VTY_DECLVAR_CONTEXT(bgp, bgp);
2574
2575 if (bgp_flag_check(bgp, BGP_FLAG_RR_ALLOW_OUTBOUND_POLICY)) {
2576 bgp_flag_unset(bgp, BGP_FLAG_RR_ALLOW_OUTBOUND_POLICY);
2577 update_group_announce_rrclients(bgp);
2578 bgp_clear_star_soft_out(vty, bgp->name);
2579 }
2580
2581 return CMD_SUCCESS;
2582 }
2583
2584 DEFUN (bgp_listen_limit,
2585 bgp_listen_limit_cmd,
2586 "bgp listen limit (1-5000)",
2587 "BGP specific commands\n"
2588 "Configure BGP defaults\n"
2589 "maximum number of BGP Dynamic Neighbors that can be created\n"
2590 "Configure Dynamic Neighbors listen limit value\n")
2591 {
2592 VTY_DECLVAR_CONTEXT(bgp, bgp);
2593 int idx_number = 3;
2594 int listen_limit;
2595
2596 listen_limit = strtoul(argv[idx_number]->arg, NULL, 10);
2597
2598 bgp_listen_limit_set(bgp, listen_limit);
2599
2600 return CMD_SUCCESS;
2601 }
2602
2603 DEFUN (no_bgp_listen_limit,
2604 no_bgp_listen_limit_cmd,
2605 "no bgp listen limit [(1-5000)]",
2606 "BGP specific commands\n"
2607 "Configure BGP defaults\n"
2608 "unset maximum number of BGP Dynamic Neighbors that can be created\n"
2609 "Configure Dynamic Neighbors listen limit value to default\n"
2610 "Configure Dynamic Neighbors listen limit value\n")
2611 {
2612 VTY_DECLVAR_CONTEXT(bgp, bgp);
2613 bgp_listen_limit_unset(bgp);
2614 return CMD_SUCCESS;
2615 }
2616
2617
2618 /*
2619 * Check if this listen range is already configured. Check for exact
2620 * match or overlap based on input.
2621 */
2622 static struct peer_group *listen_range_exists(struct bgp *bgp,
2623 struct prefix *range, int exact)
2624 {
2625 struct listnode *node, *nnode;
2626 struct listnode *node1, *nnode1;
2627 struct peer_group *group;
2628 struct prefix *lr;
2629 afi_t afi;
2630 int match;
2631
2632 afi = family2afi(range->family);
2633 for (ALL_LIST_ELEMENTS(bgp->group, node, nnode, group)) {
2634 for (ALL_LIST_ELEMENTS(group->listen_range[afi], node1, nnode1,
2635 lr)) {
2636 if (exact)
2637 match = prefix_same(range, lr);
2638 else
2639 match = (prefix_match(range, lr)
2640 || prefix_match(lr, range));
2641 if (match)
2642 return group;
2643 }
2644 }
2645
2646 return NULL;
2647 }
2648
2649 DEFUN (bgp_listen_range,
2650 bgp_listen_range_cmd,
2651 "bgp listen range <A.B.C.D/M|X:X::X:X/M> peer-group PGNAME",
2652 "BGP specific commands\n"
2653 "Configure BGP dynamic neighbors listen range\n"
2654 "Configure BGP dynamic neighbors listen range\n"
2655 NEIGHBOR_ADDR_STR
2656 "Member of the peer-group\n"
2657 "Peer-group name\n")
2658 {
2659 VTY_DECLVAR_CONTEXT(bgp, bgp);
2660 struct prefix range;
2661 struct peer_group *group, *existing_group;
2662 afi_t afi;
2663 int ret;
2664 int idx = 0;
2665
2666 argv_find(argv, argc, "A.B.C.D/M", &idx);
2667 argv_find(argv, argc, "X:X::X:X/M", &idx);
2668 char *prefix = argv[idx]->arg;
2669 argv_find(argv, argc, "PGNAME", &idx);
2670 char *peergroup = argv[idx]->arg;
2671
2672 /* Convert IP prefix string to struct prefix. */
2673 ret = str2prefix(prefix, &range);
2674 if (!ret) {
2675 vty_out(vty, "%% Malformed listen range\n");
2676 return CMD_WARNING_CONFIG_FAILED;
2677 }
2678
2679 afi = family2afi(range.family);
2680
2681 if (afi == AFI_IP6 && IN6_IS_ADDR_LINKLOCAL(&range.u.prefix6)) {
2682 vty_out(vty,
2683 "%% Malformed listen range (link-local address)\n");
2684 return CMD_WARNING_CONFIG_FAILED;
2685 }
2686
2687 apply_mask(&range);
2688
2689 /* Check if same listen range is already configured. */
2690 existing_group = listen_range_exists(bgp, &range, 1);
2691 if (existing_group) {
2692 if (strcmp(existing_group->name, peergroup) == 0)
2693 return CMD_SUCCESS;
2694 else {
2695 vty_out(vty,
2696 "%% Same listen range is attached to peer-group %s\n",
2697 existing_group->name);
2698 return CMD_WARNING_CONFIG_FAILED;
2699 }
2700 }
2701
2702 /* Check if an overlapping listen range exists. */
2703 if (listen_range_exists(bgp, &range, 0)) {
2704 vty_out(vty,
2705 "%% Listen range overlaps with existing listen range\n");
2706 return CMD_WARNING_CONFIG_FAILED;
2707 }
2708
2709 group = peer_group_lookup(bgp, peergroup);
2710 if (!group) {
2711 vty_out(vty, "%% Configure the peer-group first\n");
2712 return CMD_WARNING_CONFIG_FAILED;
2713 }
2714
2715 ret = peer_group_listen_range_add(group, &range);
2716 return bgp_vty_return(vty, ret);
2717 }
2718
2719 DEFUN (no_bgp_listen_range,
2720 no_bgp_listen_range_cmd,
2721 "no bgp listen range <A.B.C.D/M|X:X::X:X/M> peer-group PGNAME",
2722 NO_STR
2723 "BGP specific commands\n"
2724 "Unconfigure BGP dynamic neighbors listen range\n"
2725 "Unconfigure BGP dynamic neighbors listen range\n"
2726 NEIGHBOR_ADDR_STR
2727 "Member of the peer-group\n"
2728 "Peer-group name\n")
2729 {
2730 VTY_DECLVAR_CONTEXT(bgp, bgp);
2731 struct prefix range;
2732 struct peer_group *group;
2733 afi_t afi;
2734 int ret;
2735 int idx = 0;
2736
2737 argv_find(argv, argc, "A.B.C.D/M", &idx);
2738 argv_find(argv, argc, "X:X::X:X/M", &idx);
2739 char *prefix = argv[idx]->arg;
2740 argv_find(argv, argc, "WORD", &idx);
2741 char *peergroup = argv[idx]->arg;
2742
2743 /* Convert IP prefix string to struct prefix. */
2744 ret = str2prefix(prefix, &range);
2745 if (!ret) {
2746 vty_out(vty, "%% Malformed listen range\n");
2747 return CMD_WARNING_CONFIG_FAILED;
2748 }
2749
2750 afi = family2afi(range.family);
2751
2752 if (afi == AFI_IP6 && IN6_IS_ADDR_LINKLOCAL(&range.u.prefix6)) {
2753 vty_out(vty,
2754 "%% Malformed listen range (link-local address)\n");
2755 return CMD_WARNING_CONFIG_FAILED;
2756 }
2757
2758 apply_mask(&range);
2759
2760 group = peer_group_lookup(bgp, peergroup);
2761 if (!group) {
2762 vty_out(vty, "%% Peer-group does not exist\n");
2763 return CMD_WARNING_CONFIG_FAILED;
2764 }
2765
2766 ret = peer_group_listen_range_del(group, &range);
2767 return bgp_vty_return(vty, ret);
2768 }
2769
2770 void bgp_config_write_listen(struct vty *vty, struct bgp *bgp)
2771 {
2772 struct peer_group *group;
2773 struct listnode *node, *nnode, *rnode, *nrnode;
2774 struct prefix *range;
2775 afi_t afi;
2776 char buf[PREFIX2STR_BUFFER];
2777
2778 if (bgp->dynamic_neighbors_limit != BGP_DYNAMIC_NEIGHBORS_LIMIT_DEFAULT)
2779 vty_out(vty, " bgp listen limit %d\n",
2780 bgp->dynamic_neighbors_limit);
2781
2782 for (ALL_LIST_ELEMENTS(bgp->group, node, nnode, group)) {
2783 for (afi = AFI_IP; afi < AFI_MAX; afi++) {
2784 for (ALL_LIST_ELEMENTS(group->listen_range[afi], rnode,
2785 nrnode, range)) {
2786 prefix2str(range, buf, sizeof(buf));
2787 vty_out(vty,
2788 " bgp listen range %s peer-group %s\n",
2789 buf, group->name);
2790 }
2791 }
2792 }
2793 }
2794
2795
2796 DEFUN (bgp_disable_connected_route_check,
2797 bgp_disable_connected_route_check_cmd,
2798 "bgp disable-ebgp-connected-route-check",
2799 "BGP specific commands\n"
2800 "Disable checking if nexthop is connected on ebgp sessions\n")
2801 {
2802 VTY_DECLVAR_CONTEXT(bgp, bgp);
2803 bgp_flag_set(bgp, BGP_FLAG_DISABLE_NH_CONNECTED_CHK);
2804 bgp_clear_star_soft_in(vty, bgp->name);
2805
2806 return CMD_SUCCESS;
2807 }
2808
2809 DEFUN (no_bgp_disable_connected_route_check,
2810 no_bgp_disable_connected_route_check_cmd,
2811 "no bgp disable-ebgp-connected-route-check",
2812 NO_STR
2813 "BGP specific commands\n"
2814 "Disable checking if nexthop is connected on ebgp sessions\n")
2815 {
2816 VTY_DECLVAR_CONTEXT(bgp, bgp);
2817 bgp_flag_unset(bgp, BGP_FLAG_DISABLE_NH_CONNECTED_CHK);
2818 bgp_clear_star_soft_in(vty, bgp->name);
2819
2820 return CMD_SUCCESS;
2821 }
2822
2823
2824 static int peer_remote_as_vty(struct vty *vty, const char *peer_str,
2825 const char *as_str, afi_t afi, safi_t safi)
2826 {
2827 VTY_DECLVAR_CONTEXT(bgp, bgp);
2828 int ret;
2829 as_t as;
2830 int as_type = AS_SPECIFIED;
2831 union sockunion su;
2832
2833 if (as_str[0] == 'i') {
2834 as = 0;
2835 as_type = AS_INTERNAL;
2836 } else if (as_str[0] == 'e') {
2837 as = 0;
2838 as_type = AS_EXTERNAL;
2839 } else {
2840 /* Get AS number. */
2841 as = strtoul(as_str, NULL, 10);
2842 }
2843
2844 /* If peer is peer group or interface peer, call proper function. */
2845 ret = str2sockunion(peer_str, &su);
2846 if (ret < 0) {
2847 struct peer *peer;
2848
2849 /* Check if existing interface peer */
2850 peer = peer_lookup_by_conf_if(bgp, peer_str);
2851
2852 ret = peer_remote_as(bgp, NULL, peer_str, &as, as_type, afi,
2853 safi);
2854
2855 /* if not interface peer, check peer-group settings */
2856 if (ret < 0 && !peer) {
2857 ret = peer_group_remote_as(bgp, peer_str, &as, as_type);
2858 if (ret < 0) {
2859 vty_out(vty,
2860 "%% Create the peer-group or interface first\n");
2861 return CMD_WARNING_CONFIG_FAILED;
2862 }
2863 return CMD_SUCCESS;
2864 }
2865 } else {
2866 if (peer_address_self_check(bgp, &su)) {
2867 vty_out(vty,
2868 "%% Can not configure the local system as neighbor\n");
2869 return CMD_WARNING_CONFIG_FAILED;
2870 }
2871 ret = peer_remote_as(bgp, &su, NULL, &as, as_type, afi, safi);
2872 }
2873
2874 /* This peer belongs to peer group. */
2875 switch (ret) {
2876 case BGP_ERR_PEER_GROUP_MEMBER:
2877 vty_out(vty,
2878 "%% Peer-group member cannot override remote-as of peer-group\n");
2879 return CMD_WARNING_CONFIG_FAILED;
2880 case BGP_ERR_PEER_GROUP_PEER_TYPE_DIFFERENT:
2881 vty_out(vty,
2882 "%% Peer-group members must be all internal or all external\n");
2883 return CMD_WARNING_CONFIG_FAILED;
2884 }
2885 return bgp_vty_return(vty, ret);
2886 }
2887
2888 DEFUN (bgp_default_shutdown,
2889 bgp_default_shutdown_cmd,
2890 "[no] bgp default shutdown",
2891 NO_STR
2892 BGP_STR
2893 "Configure BGP defaults\n"
2894 "Apply administrative shutdown to newly configured peers\n")
2895 {
2896 VTY_DECLVAR_CONTEXT(bgp, bgp);
2897 bgp->autoshutdown = !strmatch(argv[0]->text, "no");
2898 return CMD_SUCCESS;
2899 }
2900
2901 DEFUN (neighbor_remote_as,
2902 neighbor_remote_as_cmd,
2903 "neighbor <A.B.C.D|X:X::X:X|WORD> remote-as <(1-4294967295)|internal|external>",
2904 NEIGHBOR_STR
2905 NEIGHBOR_ADDR_STR2
2906 "Specify a BGP neighbor\n"
2907 AS_STR
2908 "Internal BGP peer\n"
2909 "External BGP peer\n")
2910 {
2911 int idx_peer = 1;
2912 int idx_remote_as = 3;
2913 return peer_remote_as_vty(vty, argv[idx_peer]->arg,
2914 argv[idx_remote_as]->arg, AFI_IP,
2915 SAFI_UNICAST);
2916 }
2917
2918 static int peer_conf_interface_get(struct vty *vty, const char *conf_if,
2919 afi_t afi, safi_t safi, int v6only,
2920 const char *peer_group_name,
2921 const char *as_str)
2922 {
2923 VTY_DECLVAR_CONTEXT(bgp, bgp);
2924 as_t as = 0;
2925 int as_type = AS_UNSPECIFIED;
2926 struct peer *peer;
2927 struct peer_group *group;
2928 int ret = 0;
2929 union sockunion su;
2930
2931 group = peer_group_lookup(bgp, conf_if);
2932
2933 if (group) {
2934 vty_out(vty, "%% Name conflict with peer-group \n");
2935 return CMD_WARNING_CONFIG_FAILED;
2936 }
2937
2938 if (as_str) {
2939 if (as_str[0] == 'i') {
2940 as_type = AS_INTERNAL;
2941 } else if (as_str[0] == 'e') {
2942 as_type = AS_EXTERNAL;
2943 } else {
2944 /* Get AS number. */
2945 as = strtoul(as_str, NULL, 10);
2946 as_type = AS_SPECIFIED;
2947 }
2948 }
2949
2950 peer = peer_lookup_by_conf_if(bgp, conf_if);
2951 if (peer) {
2952 if (as_str)
2953 ret = peer_remote_as(bgp, NULL, conf_if, &as, as_type,
2954 afi, safi);
2955 } else {
2956 if (bgp_flag_check(bgp, BGP_FLAG_NO_DEFAULT_IPV4)
2957 && afi == AFI_IP && safi == SAFI_UNICAST)
2958 peer = peer_create(NULL, conf_if, bgp, bgp->as, as,
2959 as_type, 0, 0, NULL);
2960 else
2961 peer = peer_create(NULL, conf_if, bgp, bgp->as, as,
2962 as_type, afi, safi, NULL);
2963
2964 if (!peer) {
2965 vty_out(vty, "%% BGP failed to create peer\n");
2966 return CMD_WARNING_CONFIG_FAILED;
2967 }
2968
2969 if (v6only)
2970 peer_flag_set(peer, PEER_FLAG_IFPEER_V6ONLY);
2971
2972 /* Request zebra to initiate IPv6 RAs on this interface. We do
2973 * this
2974 * any unnumbered peer in order to not worry about run-time
2975 * transitions
2976 * (e.g., peering is initially IPv4, but the IPv4 /30 or /31
2977 * address
2978 * gets deleted later etc.)
2979 */
2980 if (peer->ifp)
2981 bgp_zebra_initiate_radv(bgp, peer);
2982 }
2983
2984 if ((v6only && !CHECK_FLAG(peer->flags, PEER_FLAG_IFPEER_V6ONLY))
2985 || (!v6only && CHECK_FLAG(peer->flags, PEER_FLAG_IFPEER_V6ONLY))) {
2986 if (v6only)
2987 peer_flag_set(peer, PEER_FLAG_IFPEER_V6ONLY);
2988 else
2989 peer_flag_unset(peer, PEER_FLAG_IFPEER_V6ONLY);
2990
2991 /* v6only flag changed. Reset bgp seesion */
2992 if (BGP_IS_VALID_STATE_FOR_NOTIF(peer->status)) {
2993 peer->last_reset = PEER_DOWN_V6ONLY_CHANGE;
2994 bgp_notify_send(peer, BGP_NOTIFY_CEASE,
2995 BGP_NOTIFY_CEASE_CONFIG_CHANGE);
2996 } else
2997 bgp_session_reset(peer);
2998 }
2999
3000 if (!CHECK_FLAG(peer->flags_invert, PEER_FLAG_CAPABILITY_ENHE)) {
3001 SET_FLAG(peer->flags, PEER_FLAG_CAPABILITY_ENHE);
3002 SET_FLAG(peer->flags_invert, PEER_FLAG_CAPABILITY_ENHE);
3003 SET_FLAG(peer->flags_override, PEER_FLAG_CAPABILITY_ENHE);
3004 }
3005
3006 if (peer_group_name) {
3007 group = peer_group_lookup(bgp, peer_group_name);
3008 if (!group) {
3009 vty_out(vty, "%% Configure the peer-group first\n");
3010 return CMD_WARNING_CONFIG_FAILED;
3011 }
3012
3013 ret = peer_group_bind(bgp, &su, peer, group, &as);
3014 }
3015
3016 return bgp_vty_return(vty, ret);
3017 }
3018
3019 DEFUN (neighbor_interface_config,
3020 neighbor_interface_config_cmd,
3021 "neighbor WORD interface [peer-group PGNAME]",
3022 NEIGHBOR_STR
3023 "Interface name or neighbor tag\n"
3024 "Enable BGP on interface\n"
3025 "Member of the peer-group\n"
3026 "Peer-group name\n")
3027 {
3028 int idx_word = 1;
3029 int idx_peer_group_word = 4;
3030
3031 if (argc > idx_peer_group_word)
3032 return peer_conf_interface_get(
3033 vty, argv[idx_word]->arg, AFI_IP, SAFI_UNICAST, 0,
3034 argv[idx_peer_group_word]->arg, NULL);
3035 else
3036 return peer_conf_interface_get(vty, argv[idx_word]->arg, AFI_IP,
3037 SAFI_UNICAST, 0, NULL, NULL);
3038 }
3039
3040 DEFUN (neighbor_interface_config_v6only,
3041 neighbor_interface_config_v6only_cmd,
3042 "neighbor WORD interface v6only [peer-group PGNAME]",
3043 NEIGHBOR_STR
3044 "Interface name or neighbor tag\n"
3045 "Enable BGP on interface\n"
3046 "Enable BGP with v6 link-local only\n"
3047 "Member of the peer-group\n"
3048 "Peer-group name\n")
3049 {
3050 int idx_word = 1;
3051 int idx_peer_group_word = 5;
3052
3053 if (argc > idx_peer_group_word)
3054 return peer_conf_interface_get(
3055 vty, argv[idx_word]->arg, AFI_IP, SAFI_UNICAST, 1,
3056 argv[idx_peer_group_word]->arg, NULL);
3057
3058 return peer_conf_interface_get(vty, argv[idx_word]->arg, AFI_IP,
3059 SAFI_UNICAST, 1, NULL, NULL);
3060 }
3061
3062
3063 DEFUN (neighbor_interface_config_remote_as,
3064 neighbor_interface_config_remote_as_cmd,
3065 "neighbor WORD interface remote-as <(1-4294967295)|internal|external>",
3066 NEIGHBOR_STR
3067 "Interface name or neighbor tag\n"
3068 "Enable BGP on interface\n"
3069 "Specify a BGP neighbor\n"
3070 AS_STR
3071 "Internal BGP peer\n"
3072 "External BGP peer\n")
3073 {
3074 int idx_word = 1;
3075 int idx_remote_as = 4;
3076 return peer_conf_interface_get(vty, argv[idx_word]->arg, AFI_IP,
3077 SAFI_UNICAST, 0, NULL,
3078 argv[idx_remote_as]->arg);
3079 }
3080
3081 DEFUN (neighbor_interface_v6only_config_remote_as,
3082 neighbor_interface_v6only_config_remote_as_cmd,
3083 "neighbor WORD interface v6only remote-as <(1-4294967295)|internal|external>",
3084 NEIGHBOR_STR
3085 "Interface name or neighbor tag\n"
3086 "Enable BGP with v6 link-local only\n"
3087 "Enable BGP on interface\n"
3088 "Specify a BGP neighbor\n"
3089 AS_STR
3090 "Internal BGP peer\n"
3091 "External BGP peer\n")
3092 {
3093 int idx_word = 1;
3094 int idx_remote_as = 5;
3095 return peer_conf_interface_get(vty, argv[idx_word]->arg, AFI_IP,
3096 SAFI_UNICAST, 1, NULL,
3097 argv[idx_remote_as]->arg);
3098 }
3099
3100 DEFUN (neighbor_peer_group,
3101 neighbor_peer_group_cmd,
3102 "neighbor WORD peer-group",
3103 NEIGHBOR_STR
3104 "Interface name or neighbor tag\n"
3105 "Configure peer-group\n")
3106 {
3107 VTY_DECLVAR_CONTEXT(bgp, bgp);
3108 int idx_word = 1;
3109 struct peer *peer;
3110 struct peer_group *group;
3111
3112 peer = peer_lookup_by_conf_if(bgp, argv[idx_word]->arg);
3113 if (peer) {
3114 vty_out(vty, "%% Name conflict with interface: \n");
3115 return CMD_WARNING_CONFIG_FAILED;
3116 }
3117
3118 group = peer_group_get(bgp, argv[idx_word]->arg);
3119 if (!group) {
3120 vty_out(vty, "%% BGP failed to find or create peer-group\n");
3121 return CMD_WARNING_CONFIG_FAILED;
3122 }
3123
3124 return CMD_SUCCESS;
3125 }
3126
3127 DEFUN (no_neighbor,
3128 no_neighbor_cmd,
3129 "no neighbor <WORD|<A.B.C.D|X:X::X:X> [remote-as <(1-4294967295)|internal|external>]>",
3130 NO_STR
3131 NEIGHBOR_STR
3132 NEIGHBOR_ADDR_STR2
3133 "Specify a BGP neighbor\n"
3134 AS_STR
3135 "Internal BGP peer\n"
3136 "External BGP peer\n")
3137 {
3138 VTY_DECLVAR_CONTEXT(bgp, bgp);
3139 int idx_peer = 2;
3140 int ret;
3141 union sockunion su;
3142 struct peer_group *group;
3143 struct peer *peer;
3144 struct peer *other;
3145
3146 ret = str2sockunion(argv[idx_peer]->arg, &su);
3147 if (ret < 0) {
3148 /* look up for neighbor by interface name config. */
3149 peer = peer_lookup_by_conf_if(bgp, argv[idx_peer]->arg);
3150 if (peer) {
3151 /* Request zebra to terminate IPv6 RAs on this
3152 * interface. */
3153 if (peer->ifp)
3154 bgp_zebra_terminate_radv(peer->bgp, peer);
3155 peer_delete(peer);
3156 return CMD_SUCCESS;
3157 }
3158
3159 group = peer_group_lookup(bgp, argv[idx_peer]->arg);
3160 if (group)
3161 peer_group_delete(group);
3162 else {
3163 vty_out(vty, "%% Create the peer-group first\n");
3164 return CMD_WARNING_CONFIG_FAILED;
3165 }
3166 } else {
3167 peer = peer_lookup(bgp, &su);
3168 if (peer) {
3169 if (peer_dynamic_neighbor(peer)) {
3170 vty_out(vty,
3171 "%% Operation not allowed on a dynamic neighbor\n");
3172 return CMD_WARNING_CONFIG_FAILED;
3173 }
3174
3175 other = peer->doppelganger;
3176 peer_delete(peer);
3177 if (other && other->status != Deleted)
3178 peer_delete(other);
3179 }
3180 }
3181
3182 return CMD_SUCCESS;
3183 }
3184
3185 DEFUN (no_neighbor_interface_config,
3186 no_neighbor_interface_config_cmd,
3187 "no neighbor WORD interface [v6only] [peer-group PGNAME] [remote-as <(1-4294967295)|internal|external>]",
3188 NO_STR
3189 NEIGHBOR_STR
3190 "Interface name\n"
3191 "Configure BGP on interface\n"
3192 "Enable BGP with v6 link-local only\n"
3193 "Member of the peer-group\n"
3194 "Peer-group name\n"
3195 "Specify a BGP neighbor\n"
3196 AS_STR
3197 "Internal BGP peer\n"
3198 "External BGP peer\n")
3199 {
3200 VTY_DECLVAR_CONTEXT(bgp, bgp);
3201 int idx_word = 2;
3202 struct peer *peer;
3203
3204 /* look up for neighbor by interface name config. */
3205 peer = peer_lookup_by_conf_if(bgp, argv[idx_word]->arg);
3206 if (peer) {
3207 /* Request zebra to terminate IPv6 RAs on this interface. */
3208 if (peer->ifp)
3209 bgp_zebra_terminate_radv(peer->bgp, peer);
3210 peer_delete(peer);
3211 } else {
3212 vty_out(vty, "%% Create the bgp interface first\n");
3213 return CMD_WARNING_CONFIG_FAILED;
3214 }
3215 return CMD_SUCCESS;
3216 }
3217
3218 DEFUN (no_neighbor_peer_group,
3219 no_neighbor_peer_group_cmd,
3220 "no neighbor WORD peer-group",
3221 NO_STR
3222 NEIGHBOR_STR
3223 "Neighbor tag\n"
3224 "Configure peer-group\n")
3225 {
3226 VTY_DECLVAR_CONTEXT(bgp, bgp);
3227 int idx_word = 2;
3228 struct peer_group *group;
3229
3230 group = peer_group_lookup(bgp, argv[idx_word]->arg);
3231 if (group)
3232 peer_group_delete(group);
3233 else {
3234 vty_out(vty, "%% Create the peer-group first\n");
3235 return CMD_WARNING_CONFIG_FAILED;
3236 }
3237 return CMD_SUCCESS;
3238 }
3239
3240 DEFUN (no_neighbor_interface_peer_group_remote_as,
3241 no_neighbor_interface_peer_group_remote_as_cmd,
3242 "no neighbor WORD remote-as <(1-4294967295)|internal|external>",
3243 NO_STR
3244 NEIGHBOR_STR
3245 "Interface name or neighbor tag\n"
3246 "Specify a BGP neighbor\n"
3247 AS_STR
3248 "Internal BGP peer\n"
3249 "External BGP peer\n")
3250 {
3251 VTY_DECLVAR_CONTEXT(bgp, bgp);
3252 int idx_word = 2;
3253 struct peer_group *group;
3254 struct peer *peer;
3255
3256 /* look up for neighbor by interface name config. */
3257 peer = peer_lookup_by_conf_if(bgp, argv[idx_word]->arg);
3258 if (peer) {
3259 peer_as_change(peer, 0, AS_UNSPECIFIED);
3260 return CMD_SUCCESS;
3261 }
3262
3263 group = peer_group_lookup(bgp, argv[idx_word]->arg);
3264 if (group)
3265 peer_group_remote_as_delete(group);
3266 else {
3267 vty_out(vty, "%% Create the peer-group or interface first\n");
3268 return CMD_WARNING_CONFIG_FAILED;
3269 }
3270 return CMD_SUCCESS;
3271 }
3272
3273 DEFUN (neighbor_local_as,
3274 neighbor_local_as_cmd,
3275 "neighbor <A.B.C.D|X:X::X:X|WORD> local-as (1-4294967295)",
3276 NEIGHBOR_STR
3277 NEIGHBOR_ADDR_STR2
3278 "Specify a local-as number\n"
3279 "AS number used as local AS\n")
3280 {
3281 int idx_peer = 1;
3282 int idx_number = 3;
3283 struct peer *peer;
3284 int ret;
3285 as_t as;
3286
3287 peer = peer_and_group_lookup_vty(vty, argv[idx_peer]->arg);
3288 if (!peer)
3289 return CMD_WARNING_CONFIG_FAILED;
3290
3291 as = strtoul(argv[idx_number]->arg, NULL, 10);
3292 ret = peer_local_as_set(peer, as, 0, 0);
3293 return bgp_vty_return(vty, ret);
3294 }
3295
3296 DEFUN (neighbor_local_as_no_prepend,
3297 neighbor_local_as_no_prepend_cmd,
3298 "neighbor <A.B.C.D|X:X::X:X|WORD> local-as (1-4294967295) no-prepend",
3299 NEIGHBOR_STR
3300 NEIGHBOR_ADDR_STR2
3301 "Specify a local-as number\n"
3302 "AS number used as local AS\n"
3303 "Do not prepend local-as to updates from ebgp peers\n")
3304 {
3305 int idx_peer = 1;
3306 int idx_number = 3;
3307 struct peer *peer;
3308 int ret;
3309 as_t as;
3310
3311 peer = peer_and_group_lookup_vty(vty, argv[idx_peer]->arg);
3312 if (!peer)
3313 return CMD_WARNING_CONFIG_FAILED;
3314
3315 as = strtoul(argv[idx_number]->arg, NULL, 10);
3316 ret = peer_local_as_set(peer, as, 1, 0);
3317 return bgp_vty_return(vty, ret);
3318 }
3319
3320 DEFUN (neighbor_local_as_no_prepend_replace_as,
3321 neighbor_local_as_no_prepend_replace_as_cmd,
3322 "neighbor <A.B.C.D|X:X::X:X|WORD> local-as (1-4294967295) no-prepend replace-as",
3323 NEIGHBOR_STR
3324 NEIGHBOR_ADDR_STR2
3325 "Specify a local-as number\n"
3326 "AS number used as local AS\n"
3327 "Do not prepend local-as to updates from ebgp peers\n"
3328 "Do not prepend local-as to updates from ibgp peers\n")
3329 {
3330 int idx_peer = 1;
3331 int idx_number = 3;
3332 struct peer *peer;
3333 int ret;
3334 as_t as;
3335
3336 peer = peer_and_group_lookup_vty(vty, argv[idx_peer]->arg);
3337 if (!peer)
3338 return CMD_WARNING_CONFIG_FAILED;
3339
3340 as = strtoul(argv[idx_number]->arg, NULL, 10);
3341 ret = peer_local_as_set(peer, as, 1, 1);
3342 return bgp_vty_return(vty, ret);
3343 }
3344
3345 DEFUN (no_neighbor_local_as,
3346 no_neighbor_local_as_cmd,
3347 "no neighbor <A.B.C.D|X:X::X:X|WORD> local-as [(1-4294967295) [no-prepend [replace-as]]]",
3348 NO_STR
3349 NEIGHBOR_STR
3350 NEIGHBOR_ADDR_STR2
3351 "Specify a local-as number\n"
3352 "AS number used as local AS\n"
3353 "Do not prepend local-as to updates from ebgp peers\n"
3354 "Do not prepend local-as to updates from ibgp peers\n")
3355 {
3356 int idx_peer = 2;
3357 struct peer *peer;
3358 int ret;
3359
3360 peer = peer_and_group_lookup_vty(vty, argv[idx_peer]->arg);
3361 if (!peer)
3362 return CMD_WARNING_CONFIG_FAILED;
3363
3364 ret = peer_local_as_unset(peer);
3365 return bgp_vty_return(vty, ret);
3366 }
3367
3368
3369 DEFUN (neighbor_solo,
3370 neighbor_solo_cmd,
3371 "neighbor <A.B.C.D|X:X::X:X|WORD> solo",
3372 NEIGHBOR_STR
3373 NEIGHBOR_ADDR_STR2
3374 "Solo peer - part of its own update group\n")
3375 {
3376 int idx_peer = 1;
3377 struct peer *peer;
3378 int ret;
3379
3380 peer = peer_and_group_lookup_vty(vty, argv[idx_peer]->arg);
3381 if (!peer)
3382 return CMD_WARNING_CONFIG_FAILED;
3383
3384 ret = update_group_adjust_soloness(peer, 1);
3385 return bgp_vty_return(vty, ret);
3386 }
3387
3388 DEFUN (no_neighbor_solo,
3389 no_neighbor_solo_cmd,
3390 "no neighbor <A.B.C.D|X:X::X:X|WORD> solo",
3391 NO_STR
3392 NEIGHBOR_STR
3393 NEIGHBOR_ADDR_STR2
3394 "Solo peer - part of its own update group\n")
3395 {
3396 int idx_peer = 2;
3397 struct peer *peer;
3398 int ret;
3399
3400 peer = peer_and_group_lookup_vty(vty, argv[idx_peer]->arg);
3401 if (!peer)
3402 return CMD_WARNING_CONFIG_FAILED;
3403
3404 ret = update_group_adjust_soloness(peer, 0);
3405 return bgp_vty_return(vty, ret);
3406 }
3407
3408 DEFUN (neighbor_password,
3409 neighbor_password_cmd,
3410 "neighbor <A.B.C.D|X:X::X:X|WORD> password LINE",
3411 NEIGHBOR_STR
3412 NEIGHBOR_ADDR_STR2
3413 "Set a password\n"
3414 "The password\n")
3415 {
3416 int idx_peer = 1;
3417 int idx_line = 3;
3418 struct peer *peer;
3419 int ret;
3420
3421 peer = peer_and_group_lookup_vty(vty, argv[idx_peer]->arg);
3422 if (!peer)
3423 return CMD_WARNING_CONFIG_FAILED;
3424
3425 ret = peer_password_set(peer, argv[idx_line]->arg);
3426 return bgp_vty_return(vty, ret);
3427 }
3428
3429 DEFUN (no_neighbor_password,
3430 no_neighbor_password_cmd,
3431 "no neighbor <A.B.C.D|X:X::X:X|WORD> password [LINE]",
3432 NO_STR
3433 NEIGHBOR_STR
3434 NEIGHBOR_ADDR_STR2
3435 "Set a password\n"
3436 "The password\n")
3437 {
3438 int idx_peer = 2;
3439 struct peer *peer;
3440 int ret;
3441
3442 peer = peer_and_group_lookup_vty(vty, argv[idx_peer]->arg);
3443 if (!peer)
3444 return CMD_WARNING_CONFIG_FAILED;
3445
3446 ret = peer_password_unset(peer);
3447 return bgp_vty_return(vty, ret);
3448 }
3449
3450 DEFUN (neighbor_activate,
3451 neighbor_activate_cmd,
3452 "neighbor <A.B.C.D|X:X::X:X|WORD> activate",
3453 NEIGHBOR_STR
3454 NEIGHBOR_ADDR_STR2
3455 "Enable the Address Family for this Neighbor\n")
3456 {
3457 int idx_peer = 1;
3458 int ret;
3459 struct peer *peer;
3460
3461 peer = peer_and_group_lookup_vty(vty, argv[idx_peer]->arg);
3462 if (!peer)
3463 return CMD_WARNING_CONFIG_FAILED;
3464
3465 ret = peer_activate(peer, bgp_node_afi(vty), bgp_node_safi(vty));
3466 return bgp_vty_return(vty, ret);
3467 }
3468
3469 ALIAS_HIDDEN(neighbor_activate, neighbor_activate_hidden_cmd,
3470 "neighbor <A.B.C.D|X:X::X:X|WORD> activate",
3471 NEIGHBOR_STR NEIGHBOR_ADDR_STR2
3472 "Enable the Address Family for this Neighbor\n")
3473
3474 DEFUN (no_neighbor_activate,
3475 no_neighbor_activate_cmd,
3476 "no neighbor <A.B.C.D|X:X::X:X|WORD> activate",
3477 NO_STR
3478 NEIGHBOR_STR
3479 NEIGHBOR_ADDR_STR2
3480 "Enable the Address Family for this Neighbor\n")
3481 {
3482 int idx_peer = 2;
3483 int ret;
3484 struct peer *peer;
3485
3486 /* Lookup peer. */
3487 peer = peer_and_group_lookup_vty(vty, argv[idx_peer]->arg);
3488 if (!peer)
3489 return CMD_WARNING_CONFIG_FAILED;
3490
3491 ret = peer_deactivate(peer, bgp_node_afi(vty), bgp_node_safi(vty));
3492 return bgp_vty_return(vty, ret);
3493 }
3494
3495 ALIAS_HIDDEN(no_neighbor_activate, no_neighbor_activate_hidden_cmd,
3496 "no neighbor <A.B.C.D|X:X::X:X|WORD> activate",
3497 NO_STR NEIGHBOR_STR NEIGHBOR_ADDR_STR2
3498 "Enable the Address Family for this Neighbor\n")
3499
3500 DEFUN (neighbor_set_peer_group,
3501 neighbor_set_peer_group_cmd,
3502 "neighbor <A.B.C.D|X:X::X:X|WORD> peer-group PGNAME",
3503 NEIGHBOR_STR
3504 NEIGHBOR_ADDR_STR2
3505 "Member of the peer-group\n"
3506 "Peer-group name\n")
3507 {
3508 VTY_DECLVAR_CONTEXT(bgp, bgp);
3509 int idx_peer = 1;
3510 int idx_word = 3;
3511 int ret;
3512 as_t as;
3513 union sockunion su;
3514 struct peer *peer;
3515 struct peer_group *group;
3516
3517 ret = str2sockunion(argv[idx_peer]->arg, &su);
3518 if (ret < 0) {
3519 peer = peer_lookup_by_conf_if(bgp, argv[idx_peer]->arg);
3520 if (!peer) {
3521 vty_out(vty, "%% Malformed address or name: %s\n",
3522 argv[idx_peer]->arg);
3523 return CMD_WARNING_CONFIG_FAILED;
3524 }
3525 } else {
3526 if (peer_address_self_check(bgp, &su)) {
3527 vty_out(vty,
3528 "%% Can not configure the local system as neighbor\n");
3529 return CMD_WARNING_CONFIG_FAILED;
3530 }
3531
3532 /* Disallow for dynamic neighbor. */
3533 peer = peer_lookup(bgp, &su);
3534 if (peer && peer_dynamic_neighbor(peer)) {
3535 vty_out(vty,
3536 "%% Operation not allowed on a dynamic neighbor\n");
3537 return CMD_WARNING_CONFIG_FAILED;
3538 }
3539 }
3540
3541 group = peer_group_lookup(bgp, argv[idx_word]->arg);
3542 if (!group) {
3543 vty_out(vty, "%% Configure the peer-group first\n");
3544 return CMD_WARNING_CONFIG_FAILED;
3545 }
3546
3547 ret = peer_group_bind(bgp, &su, peer, group, &as);
3548
3549 if (ret == BGP_ERR_PEER_GROUP_PEER_TYPE_DIFFERENT) {
3550 vty_out(vty,
3551 "%% Peer with AS %u cannot be in this peer-group, members must be all internal or all external\n",
3552 as);
3553 return CMD_WARNING_CONFIG_FAILED;
3554 }
3555
3556 return bgp_vty_return(vty, ret);
3557 }
3558
3559 ALIAS_HIDDEN(neighbor_set_peer_group, neighbor_set_peer_group_hidden_cmd,
3560 "neighbor <A.B.C.D|X:X::X:X|WORD> peer-group PGNAME",
3561 NEIGHBOR_STR NEIGHBOR_ADDR_STR2
3562 "Member of the peer-group\n"
3563 "Peer-group name\n")
3564
3565 DEFUN (no_neighbor_set_peer_group,
3566 no_neighbor_set_peer_group_cmd,
3567 "no neighbor <A.B.C.D|X:X::X:X|WORD> peer-group PGNAME",
3568 NO_STR
3569 NEIGHBOR_STR
3570 NEIGHBOR_ADDR_STR2
3571 "Member of the peer-group\n"
3572 "Peer-group name\n")
3573 {
3574 VTY_DECLVAR_CONTEXT(bgp, bgp);
3575 int idx_peer = 2;
3576 int idx_word = 4;
3577 int ret;
3578 struct peer *peer;
3579 struct peer_group *group;
3580
3581 peer = peer_lookup_vty(vty, argv[idx_peer]->arg);
3582 if (!peer)
3583 return CMD_WARNING_CONFIG_FAILED;
3584
3585 group = peer_group_lookup(bgp, argv[idx_word]->arg);
3586 if (!group) {
3587 vty_out(vty, "%% Configure the peer-group first\n");
3588 return CMD_WARNING_CONFIG_FAILED;
3589 }
3590
3591 ret = peer_delete(peer);
3592
3593 return bgp_vty_return(vty, ret);
3594 }
3595
3596 ALIAS_HIDDEN(no_neighbor_set_peer_group, no_neighbor_set_peer_group_hidden_cmd,
3597 "no neighbor <A.B.C.D|X:X::X:X|WORD> peer-group PGNAME",
3598 NO_STR NEIGHBOR_STR NEIGHBOR_ADDR_STR2
3599 "Member of the peer-group\n"
3600 "Peer-group name\n")
3601
3602 static int peer_flag_modify_vty(struct vty *vty, const char *ip_str,
3603 uint32_t flag, int set)
3604 {
3605 int ret;
3606 struct peer *peer;
3607
3608 peer = peer_and_group_lookup_vty(vty, ip_str);
3609 if (!peer)
3610 return CMD_WARNING_CONFIG_FAILED;
3611
3612 /*
3613 * If 'neighbor <interface>', then this is for directly connected peers,
3614 * we should not accept disable-connected-check.
3615 */
3616 if (peer->conf_if && (flag == PEER_FLAG_DISABLE_CONNECTED_CHECK)) {
3617 vty_out(vty,
3618 "%s is directly connected peer, cannot accept disable-"
3619 "connected-check\n",
3620 ip_str);
3621 return CMD_WARNING_CONFIG_FAILED;
3622 }
3623
3624 if (!set && flag == PEER_FLAG_SHUTDOWN)
3625 peer_tx_shutdown_message_unset(peer);
3626
3627 if (set)
3628 ret = peer_flag_set(peer, flag);
3629 else
3630 ret = peer_flag_unset(peer, flag);
3631
3632 return bgp_vty_return(vty, ret);
3633 }
3634
3635 static int peer_flag_set_vty(struct vty *vty, const char *ip_str, uint32_t flag)
3636 {
3637 return peer_flag_modify_vty(vty, ip_str, flag, 1);
3638 }
3639
3640 static int peer_flag_unset_vty(struct vty *vty, const char *ip_str,
3641 uint32_t flag)
3642 {
3643 return peer_flag_modify_vty(vty, ip_str, flag, 0);
3644 }
3645
3646 /* neighbor passive. */
3647 DEFUN (neighbor_passive,
3648 neighbor_passive_cmd,
3649 "neighbor <A.B.C.D|X:X::X:X|WORD> passive",
3650 NEIGHBOR_STR
3651 NEIGHBOR_ADDR_STR2
3652 "Don't send open messages to this neighbor\n")
3653 {
3654 int idx_peer = 1;
3655 return peer_flag_set_vty(vty, argv[idx_peer]->arg, PEER_FLAG_PASSIVE);
3656 }
3657
3658 DEFUN (no_neighbor_passive,
3659 no_neighbor_passive_cmd,
3660 "no neighbor <A.B.C.D|X:X::X:X|WORD> passive",
3661 NO_STR
3662 NEIGHBOR_STR
3663 NEIGHBOR_ADDR_STR2
3664 "Don't send open messages to this neighbor\n")
3665 {
3666 int idx_peer = 2;
3667 return peer_flag_unset_vty(vty, argv[idx_peer]->arg, PEER_FLAG_PASSIVE);
3668 }
3669
3670 /* neighbor shutdown. */
3671 DEFUN (neighbor_shutdown_msg,
3672 neighbor_shutdown_msg_cmd,
3673 "neighbor <A.B.C.D|X:X::X:X|WORD> shutdown message MSG...",
3674 NEIGHBOR_STR
3675 NEIGHBOR_ADDR_STR2
3676 "Administratively shut down this neighbor\n"
3677 "Add a shutdown message (draft-ietf-idr-shutdown-06)\n"
3678 "Shutdown message\n")
3679 {
3680 int idx_peer = 1;
3681
3682 if (argc >= 5) {
3683 struct peer *peer =
3684 peer_and_group_lookup_vty(vty, argv[idx_peer]->arg);
3685 char *message;
3686
3687 if (!peer)
3688 return CMD_WARNING_CONFIG_FAILED;
3689 message = argv_concat(argv, argc, 4);
3690 peer_tx_shutdown_message_set(peer, message);
3691 XFREE(MTYPE_TMP, message);
3692 }
3693
3694 return peer_flag_set_vty(vty, argv[idx_peer]->arg, PEER_FLAG_SHUTDOWN);
3695 }
3696
3697 ALIAS(neighbor_shutdown_msg, neighbor_shutdown_cmd,
3698 "neighbor <A.B.C.D|X:X::X:X|WORD> shutdown",
3699 NEIGHBOR_STR NEIGHBOR_ADDR_STR2
3700 "Administratively shut down this neighbor\n")
3701
3702 DEFUN (no_neighbor_shutdown_msg,
3703 no_neighbor_shutdown_msg_cmd,
3704 "no neighbor <A.B.C.D|X:X::X:X|WORD> shutdown message MSG...",
3705 NO_STR
3706 NEIGHBOR_STR
3707 NEIGHBOR_ADDR_STR2
3708 "Administratively shut down this neighbor\n"
3709 "Remove a shutdown message (draft-ietf-idr-shutdown-06)\n"
3710 "Shutdown message\n")
3711 {
3712 int idx_peer = 2;
3713
3714 return peer_flag_unset_vty(vty, argv[idx_peer]->arg,
3715 PEER_FLAG_SHUTDOWN);
3716 }
3717
3718 ALIAS(no_neighbor_shutdown_msg, no_neighbor_shutdown_cmd,
3719 "no neighbor <A.B.C.D|X:X::X:X|WORD> shutdown",
3720 NO_STR NEIGHBOR_STR NEIGHBOR_ADDR_STR2
3721 "Administratively shut down this neighbor\n")
3722
3723 /* neighbor capability dynamic. */
3724 DEFUN (neighbor_capability_dynamic,
3725 neighbor_capability_dynamic_cmd,
3726 "neighbor <A.B.C.D|X:X::X:X|WORD> capability dynamic",
3727 NEIGHBOR_STR
3728 NEIGHBOR_ADDR_STR2
3729 "Advertise capability to the peer\n"
3730 "Advertise dynamic capability to this neighbor\n")
3731 {
3732 int idx_peer = 1;
3733 return peer_flag_set_vty(vty, argv[idx_peer]->arg,
3734 PEER_FLAG_DYNAMIC_CAPABILITY);
3735 }
3736
3737 DEFUN (no_neighbor_capability_dynamic,
3738 no_neighbor_capability_dynamic_cmd,
3739 "no neighbor <A.B.C.D|X:X::X:X|WORD> capability dynamic",
3740 NO_STR
3741 NEIGHBOR_STR
3742 NEIGHBOR_ADDR_STR2
3743 "Advertise capability to the peer\n"
3744 "Advertise dynamic capability to this neighbor\n")
3745 {
3746 int idx_peer = 2;
3747 return peer_flag_unset_vty(vty, argv[idx_peer]->arg,
3748 PEER_FLAG_DYNAMIC_CAPABILITY);
3749 }
3750
3751 /* neighbor dont-capability-negotiate */
3752 DEFUN (neighbor_dont_capability_negotiate,
3753 neighbor_dont_capability_negotiate_cmd,
3754 "neighbor <A.B.C.D|X:X::X:X|WORD> dont-capability-negotiate",
3755 NEIGHBOR_STR
3756 NEIGHBOR_ADDR_STR2
3757 "Do not perform capability negotiation\n")
3758 {
3759 int idx_peer = 1;
3760 return peer_flag_set_vty(vty, argv[idx_peer]->arg,
3761 PEER_FLAG_DONT_CAPABILITY);
3762 }
3763
3764 DEFUN (no_neighbor_dont_capability_negotiate,
3765 no_neighbor_dont_capability_negotiate_cmd,
3766 "no neighbor <A.B.C.D|X:X::X:X|WORD> dont-capability-negotiate",
3767 NO_STR
3768 NEIGHBOR_STR
3769 NEIGHBOR_ADDR_STR2
3770 "Do not perform capability negotiation\n")
3771 {
3772 int idx_peer = 2;
3773 return peer_flag_unset_vty(vty, argv[idx_peer]->arg,
3774 PEER_FLAG_DONT_CAPABILITY);
3775 }
3776
3777 /* neighbor capability extended next hop encoding */
3778 DEFUN (neighbor_capability_enhe,
3779 neighbor_capability_enhe_cmd,
3780 "neighbor <A.B.C.D|X:X::X:X|WORD> capability extended-nexthop",
3781 NEIGHBOR_STR
3782 NEIGHBOR_ADDR_STR2
3783 "Advertise capability to the peer\n"
3784 "Advertise extended next-hop capability to the peer\n")
3785 {
3786 int idx_peer = 1;
3787 return peer_flag_set_vty(vty, argv[idx_peer]->arg,
3788 PEER_FLAG_CAPABILITY_ENHE);
3789 }
3790
3791 DEFUN (no_neighbor_capability_enhe,
3792 no_neighbor_capability_enhe_cmd,
3793 "no neighbor <A.B.C.D|X:X::X:X|WORD> capability extended-nexthop",
3794 NO_STR
3795 NEIGHBOR_STR
3796 NEIGHBOR_ADDR_STR2
3797 "Advertise capability to the peer\n"
3798 "Advertise extended next-hop capability to the peer\n")
3799 {
3800 int idx_peer = 2;
3801 return peer_flag_unset_vty(vty, argv[idx_peer]->arg,
3802 PEER_FLAG_CAPABILITY_ENHE);
3803 }
3804
3805 static int peer_af_flag_modify_vty(struct vty *vty, const char *peer_str,
3806 afi_t afi, safi_t safi, uint32_t flag,
3807 int set)
3808 {
3809 int ret;
3810 struct peer *peer;
3811
3812 peer = peer_and_group_lookup_vty(vty, peer_str);
3813 if (!peer)
3814 return CMD_WARNING_CONFIG_FAILED;
3815
3816 if (set)
3817 ret = peer_af_flag_set(peer, afi, safi, flag);
3818 else
3819 ret = peer_af_flag_unset(peer, afi, safi, flag);
3820
3821 return bgp_vty_return(vty, ret);
3822 }
3823
3824 static int peer_af_flag_set_vty(struct vty *vty, const char *peer_str,
3825 afi_t afi, safi_t safi, uint32_t flag)
3826 {
3827 return peer_af_flag_modify_vty(vty, peer_str, afi, safi, flag, 1);
3828 }
3829
3830 static int peer_af_flag_unset_vty(struct vty *vty, const char *peer_str,
3831 afi_t afi, safi_t safi, uint32_t flag)
3832 {
3833 return peer_af_flag_modify_vty(vty, peer_str, afi, safi, flag, 0);
3834 }
3835
3836 /* neighbor capability orf prefix-list. */
3837 DEFUN (neighbor_capability_orf_prefix,
3838 neighbor_capability_orf_prefix_cmd,
3839 "neighbor <A.B.C.D|X:X::X:X|WORD> capability orf prefix-list <both|send|receive>",
3840 NEIGHBOR_STR
3841 NEIGHBOR_ADDR_STR2
3842 "Advertise capability to the peer\n"
3843 "Advertise ORF capability to the peer\n"
3844 "Advertise prefixlist ORF capability to this neighbor\n"
3845 "Capability to SEND and RECEIVE the ORF to/from this neighbor\n"
3846 "Capability to RECEIVE the ORF from this neighbor\n"
3847 "Capability to SEND the ORF to this neighbor\n")
3848 {
3849 int idx_peer = 1;
3850 int idx_send_recv = 5;
3851 uint16_t flag = 0;
3852
3853 if (strmatch(argv[idx_send_recv]->text, "send"))
3854 flag = PEER_FLAG_ORF_PREFIX_SM;
3855 else if (strmatch(argv[idx_send_recv]->text, "receive"))
3856 flag = PEER_FLAG_ORF_PREFIX_RM;
3857 else if (strmatch(argv[idx_send_recv]->text, "both"))
3858 flag = PEER_FLAG_ORF_PREFIX_SM | PEER_FLAG_ORF_PREFIX_RM;
3859 else {
3860 vty_out(vty, "%% BGP invalid orf prefix-list option\n");
3861 return CMD_WARNING_CONFIG_FAILED;
3862 }
3863
3864 return peer_af_flag_set_vty(vty, argv[idx_peer]->arg, bgp_node_afi(vty),
3865 bgp_node_safi(vty), flag);
3866 }
3867
3868 ALIAS_HIDDEN(
3869 neighbor_capability_orf_prefix,
3870 neighbor_capability_orf_prefix_hidden_cmd,
3871 "neighbor <A.B.C.D|X:X::X:X|WORD> capability orf prefix-list <both|send|receive>",
3872 NEIGHBOR_STR NEIGHBOR_ADDR_STR2
3873 "Advertise capability to the peer\n"
3874 "Advertise ORF capability to the peer\n"
3875 "Advertise prefixlist ORF capability to this neighbor\n"
3876 "Capability to SEND and RECEIVE the ORF to/from this neighbor\n"
3877 "Capability to RECEIVE the ORF from this neighbor\n"
3878 "Capability to SEND the ORF to this neighbor\n")
3879
3880 DEFUN (no_neighbor_capability_orf_prefix,
3881 no_neighbor_capability_orf_prefix_cmd,
3882 "no neighbor <A.B.C.D|X:X::X:X|WORD> capability orf prefix-list <both|send|receive>",
3883 NO_STR
3884 NEIGHBOR_STR
3885 NEIGHBOR_ADDR_STR2
3886 "Advertise capability to the peer\n"
3887 "Advertise ORF capability to the peer\n"
3888 "Advertise prefixlist ORF capability to this neighbor\n"
3889 "Capability to SEND and RECEIVE the ORF to/from this neighbor\n"
3890 "Capability to RECEIVE the ORF from this neighbor\n"
3891 "Capability to SEND the ORF to this neighbor\n")
3892 {
3893 int idx_peer = 2;
3894 int idx_send_recv = 6;
3895 uint16_t flag = 0;
3896
3897 if (strmatch(argv[idx_send_recv]->text, "send"))
3898 flag = PEER_FLAG_ORF_PREFIX_SM;
3899 else if (strmatch(argv[idx_send_recv]->text, "receive"))
3900 flag = PEER_FLAG_ORF_PREFIX_RM;
3901 else if (strmatch(argv[idx_send_recv]->text, "both"))
3902 flag = PEER_FLAG_ORF_PREFIX_SM | PEER_FLAG_ORF_PREFIX_RM;
3903 else {
3904 vty_out(vty, "%% BGP invalid orf prefix-list option\n");
3905 return CMD_WARNING_CONFIG_FAILED;
3906 }
3907
3908 return peer_af_flag_unset_vty(vty, argv[idx_peer]->arg,
3909 bgp_node_afi(vty), bgp_node_safi(vty),
3910 flag);
3911 }
3912
3913 ALIAS_HIDDEN(
3914 no_neighbor_capability_orf_prefix,
3915 no_neighbor_capability_orf_prefix_hidden_cmd,
3916 "no neighbor <A.B.C.D|X:X::X:X|WORD> capability orf prefix-list <both|send|receive>",
3917 NO_STR NEIGHBOR_STR NEIGHBOR_ADDR_STR2
3918 "Advertise capability to the peer\n"
3919 "Advertise ORF capability to the peer\n"
3920 "Advertise prefixlist ORF capability to this neighbor\n"
3921 "Capability to SEND and RECEIVE the ORF to/from this neighbor\n"
3922 "Capability to RECEIVE the ORF from this neighbor\n"
3923 "Capability to SEND the ORF to this neighbor\n")
3924
3925 /* neighbor next-hop-self. */
3926 DEFUN (neighbor_nexthop_self,
3927 neighbor_nexthop_self_cmd,
3928 "neighbor <A.B.C.D|X:X::X:X|WORD> next-hop-self",
3929 NEIGHBOR_STR
3930 NEIGHBOR_ADDR_STR2
3931 "Disable the next hop calculation for this neighbor\n")
3932 {
3933 int idx_peer = 1;
3934 return peer_af_flag_set_vty(vty, argv[idx_peer]->arg, bgp_node_afi(vty),
3935 bgp_node_safi(vty), PEER_FLAG_NEXTHOP_SELF);
3936 }
3937
3938 ALIAS_HIDDEN(neighbor_nexthop_self, neighbor_nexthop_self_hidden_cmd,
3939 "neighbor <A.B.C.D|X:X::X:X|WORD> next-hop-self",
3940 NEIGHBOR_STR NEIGHBOR_ADDR_STR2
3941 "Disable the next hop calculation for this neighbor\n")
3942
3943 /* neighbor next-hop-self. */
3944 DEFUN (neighbor_nexthop_self_force,
3945 neighbor_nexthop_self_force_cmd,
3946 "neighbor <A.B.C.D|X:X::X:X|WORD> next-hop-self force",
3947 NEIGHBOR_STR
3948 NEIGHBOR_ADDR_STR2
3949 "Disable the next hop calculation for this neighbor\n"
3950 "Set the next hop to self for reflected routes\n")
3951 {
3952 int idx_peer = 1;
3953 return peer_af_flag_set_vty(vty, argv[idx_peer]->arg, bgp_node_afi(vty),
3954 bgp_node_safi(vty),
3955 PEER_FLAG_FORCE_NEXTHOP_SELF);
3956 }
3957
3958 ALIAS_HIDDEN(neighbor_nexthop_self_force,
3959 neighbor_nexthop_self_force_hidden_cmd,
3960 "neighbor <A.B.C.D|X:X::X:X|WORD> next-hop-self force",
3961 NEIGHBOR_STR NEIGHBOR_ADDR_STR2
3962 "Disable the next hop calculation for this neighbor\n"
3963 "Set the next hop to self for reflected routes\n")
3964
3965 ALIAS_HIDDEN(neighbor_nexthop_self_force,
3966 neighbor_nexthop_self_all_hidden_cmd,
3967 "neighbor <A.B.C.D|X:X::X:X|WORD> next-hop-self all",
3968 NEIGHBOR_STR NEIGHBOR_ADDR_STR2
3969 "Disable the next hop calculation for this neighbor\n"
3970 "Set the next hop to self for reflected routes\n")
3971
3972 DEFUN (no_neighbor_nexthop_self,
3973 no_neighbor_nexthop_self_cmd,
3974 "no neighbor <A.B.C.D|X:X::X:X|WORD> next-hop-self",
3975 NO_STR
3976 NEIGHBOR_STR
3977 NEIGHBOR_ADDR_STR2
3978 "Disable the next hop calculation for this neighbor\n")
3979 {
3980 int idx_peer = 2;
3981 return peer_af_flag_unset_vty(vty, argv[idx_peer]->arg,
3982 bgp_node_afi(vty), bgp_node_safi(vty),
3983 PEER_FLAG_NEXTHOP_SELF);
3984 }
3985
3986 ALIAS_HIDDEN(no_neighbor_nexthop_self, no_neighbor_nexthop_self_hidden_cmd,
3987 "no neighbor <A.B.C.D|X:X::X:X|WORD> next-hop-self",
3988 NO_STR NEIGHBOR_STR NEIGHBOR_ADDR_STR2
3989 "Disable the next hop calculation for this neighbor\n")
3990
3991 DEFUN (no_neighbor_nexthop_self_force,
3992 no_neighbor_nexthop_self_force_cmd,
3993 "no neighbor <A.B.C.D|X:X::X:X|WORD> next-hop-self force",
3994 NO_STR
3995 NEIGHBOR_STR
3996 NEIGHBOR_ADDR_STR2
3997 "Disable the next hop calculation for this neighbor\n"
3998 "Set the next hop to self for reflected routes\n")
3999 {
4000 int idx_peer = 2;
4001 return peer_af_flag_unset_vty(vty, argv[idx_peer]->arg,
4002 bgp_node_afi(vty), bgp_node_safi(vty),
4003 PEER_FLAG_FORCE_NEXTHOP_SELF);
4004 }
4005
4006 ALIAS_HIDDEN(no_neighbor_nexthop_self_force,
4007 no_neighbor_nexthop_self_force_hidden_cmd,
4008 "no neighbor <A.B.C.D|X:X::X:X|WORD> next-hop-self force",
4009 NO_STR NEIGHBOR_STR NEIGHBOR_ADDR_STR2
4010 "Disable the next hop calculation for this neighbor\n"
4011 "Set the next hop to self for reflected routes\n")
4012
4013 ALIAS_HIDDEN(no_neighbor_nexthop_self_force,
4014 no_neighbor_nexthop_self_all_hidden_cmd,
4015 "no neighbor <A.B.C.D|X:X::X:X|WORD> next-hop-self all",
4016 NO_STR NEIGHBOR_STR NEIGHBOR_ADDR_STR2
4017 "Disable the next hop calculation for this neighbor\n"
4018 "Set the next hop to self for reflected routes\n")
4019
4020 /* neighbor as-override */
4021 DEFUN (neighbor_as_override,
4022 neighbor_as_override_cmd,
4023 "neighbor <A.B.C.D|X:X::X:X|WORD> as-override",
4024 NEIGHBOR_STR
4025 NEIGHBOR_ADDR_STR2
4026 "Override ASNs in outbound updates if aspath equals remote-as\n")
4027 {
4028 int idx_peer = 1;
4029 return peer_af_flag_set_vty(vty, argv[idx_peer]->arg, bgp_node_afi(vty),
4030 bgp_node_safi(vty), PEER_FLAG_AS_OVERRIDE);
4031 }
4032
4033 ALIAS_HIDDEN(neighbor_as_override, neighbor_as_override_hidden_cmd,
4034 "neighbor <A.B.C.D|X:X::X:X|WORD> as-override",
4035 NEIGHBOR_STR NEIGHBOR_ADDR_STR2
4036 "Override ASNs in outbound updates if aspath equals remote-as\n")
4037
4038 DEFUN (no_neighbor_as_override,
4039 no_neighbor_as_override_cmd,
4040 "no neighbor <A.B.C.D|X:X::X:X|WORD> as-override",
4041 NO_STR
4042 NEIGHBOR_STR
4043 NEIGHBOR_ADDR_STR2
4044 "Override ASNs in outbound updates if aspath equals remote-as\n")
4045 {
4046 int idx_peer = 2;
4047 return peer_af_flag_unset_vty(vty, argv[idx_peer]->arg,
4048 bgp_node_afi(vty), bgp_node_safi(vty),
4049 PEER_FLAG_AS_OVERRIDE);
4050 }
4051
4052 ALIAS_HIDDEN(no_neighbor_as_override, no_neighbor_as_override_hidden_cmd,
4053 "no neighbor <A.B.C.D|X:X::X:X|WORD> as-override",
4054 NO_STR NEIGHBOR_STR NEIGHBOR_ADDR_STR2
4055 "Override ASNs in outbound updates if aspath equals remote-as\n")
4056
4057 /* neighbor remove-private-AS. */
4058 DEFUN (neighbor_remove_private_as,
4059 neighbor_remove_private_as_cmd,
4060 "neighbor <A.B.C.D|X:X::X:X|WORD> remove-private-AS",
4061 NEIGHBOR_STR
4062 NEIGHBOR_ADDR_STR2
4063 "Remove private ASNs in outbound updates\n")
4064 {
4065 int idx_peer = 1;
4066 return peer_af_flag_set_vty(vty, argv[idx_peer]->arg, bgp_node_afi(vty),
4067 bgp_node_safi(vty),
4068 PEER_FLAG_REMOVE_PRIVATE_AS);
4069 }
4070
4071 ALIAS_HIDDEN(neighbor_remove_private_as, neighbor_remove_private_as_hidden_cmd,
4072 "neighbor <A.B.C.D|X:X::X:X|WORD> remove-private-AS",
4073 NEIGHBOR_STR NEIGHBOR_ADDR_STR2
4074 "Remove private ASNs in outbound updates\n")
4075
4076 DEFUN (neighbor_remove_private_as_all,
4077 neighbor_remove_private_as_all_cmd,
4078 "neighbor <A.B.C.D|X:X::X:X|WORD> remove-private-AS all",
4079 NEIGHBOR_STR
4080 NEIGHBOR_ADDR_STR2
4081 "Remove private ASNs in outbound updates\n"
4082 "Apply to all AS numbers\n")
4083 {
4084 int idx_peer = 1;
4085 return peer_af_flag_set_vty(vty, argv[idx_peer]->arg, bgp_node_afi(vty),
4086 bgp_node_safi(vty),
4087 PEER_FLAG_REMOVE_PRIVATE_AS_ALL);
4088 }
4089
4090 ALIAS_HIDDEN(neighbor_remove_private_as_all,
4091 neighbor_remove_private_as_all_hidden_cmd,
4092 "neighbor <A.B.C.D|X:X::X:X|WORD> remove-private-AS all",
4093 NEIGHBOR_STR NEIGHBOR_ADDR_STR2
4094 "Remove private ASNs in outbound updates\n"
4095 "Apply to all AS numbers")
4096
4097 DEFUN (neighbor_remove_private_as_replace_as,
4098 neighbor_remove_private_as_replace_as_cmd,
4099 "neighbor <A.B.C.D|X:X::X:X|WORD> remove-private-AS replace-AS",
4100 NEIGHBOR_STR
4101 NEIGHBOR_ADDR_STR2
4102 "Remove private ASNs in outbound updates\n"
4103 "Replace private ASNs with our ASN in outbound updates\n")
4104 {
4105 int idx_peer = 1;
4106 return peer_af_flag_set_vty(vty, argv[idx_peer]->arg, bgp_node_afi(vty),
4107 bgp_node_safi(vty),
4108 PEER_FLAG_REMOVE_PRIVATE_AS_REPLACE);
4109 }
4110
4111 ALIAS_HIDDEN(neighbor_remove_private_as_replace_as,
4112 neighbor_remove_private_as_replace_as_hidden_cmd,
4113 "neighbor <A.B.C.D|X:X::X:X|WORD> remove-private-AS replace-AS",
4114 NEIGHBOR_STR NEIGHBOR_ADDR_STR2
4115 "Remove private ASNs in outbound updates\n"
4116 "Replace private ASNs with our ASN in outbound updates\n")
4117
4118 DEFUN (neighbor_remove_private_as_all_replace_as,
4119 neighbor_remove_private_as_all_replace_as_cmd,
4120 "neighbor <A.B.C.D|X:X::X:X|WORD> remove-private-AS all replace-AS",
4121 NEIGHBOR_STR
4122 NEIGHBOR_ADDR_STR2
4123 "Remove private ASNs in outbound updates\n"
4124 "Apply to all AS numbers\n"
4125 "Replace private ASNs with our ASN in outbound updates\n")
4126 {
4127 int idx_peer = 1;
4128 return peer_af_flag_set_vty(vty, argv[idx_peer]->arg, bgp_node_afi(vty),
4129 bgp_node_safi(vty),
4130 PEER_FLAG_REMOVE_PRIVATE_AS_ALL_REPLACE);
4131 }
4132
4133 ALIAS_HIDDEN(
4134 neighbor_remove_private_as_all_replace_as,
4135 neighbor_remove_private_as_all_replace_as_hidden_cmd,
4136 "neighbor <A.B.C.D|X:X::X:X|WORD> remove-private-AS all replace-AS",
4137 NEIGHBOR_STR NEIGHBOR_ADDR_STR2
4138 "Remove private ASNs in outbound updates\n"
4139 "Apply to all AS numbers\n"
4140 "Replace private ASNs with our ASN in outbound updates\n")
4141
4142 DEFUN (no_neighbor_remove_private_as,
4143 no_neighbor_remove_private_as_cmd,
4144 "no neighbor <A.B.C.D|X:X::X:X|WORD> remove-private-AS",
4145 NO_STR
4146 NEIGHBOR_STR
4147 NEIGHBOR_ADDR_STR2
4148 "Remove private ASNs in outbound updates\n")
4149 {
4150 int idx_peer = 2;
4151 return peer_af_flag_unset_vty(vty, argv[idx_peer]->arg,
4152 bgp_node_afi(vty), bgp_node_safi(vty),
4153 PEER_FLAG_REMOVE_PRIVATE_AS);
4154 }
4155
4156 ALIAS_HIDDEN(no_neighbor_remove_private_as,
4157 no_neighbor_remove_private_as_hidden_cmd,
4158 "no neighbor <A.B.C.D|X:X::X:X|WORD> remove-private-AS",
4159 NO_STR NEIGHBOR_STR NEIGHBOR_ADDR_STR2
4160 "Remove private ASNs in outbound updates\n")
4161
4162 DEFUN (no_neighbor_remove_private_as_all,
4163 no_neighbor_remove_private_as_all_cmd,
4164 "no neighbor <A.B.C.D|X:X::X:X|WORD> remove-private-AS all",
4165 NO_STR
4166 NEIGHBOR_STR
4167 NEIGHBOR_ADDR_STR2
4168 "Remove private ASNs in outbound updates\n"
4169 "Apply to all AS numbers\n")
4170 {
4171 int idx_peer = 2;
4172 return peer_af_flag_unset_vty(vty, argv[idx_peer]->arg,
4173 bgp_node_afi(vty), bgp_node_safi(vty),
4174 PEER_FLAG_REMOVE_PRIVATE_AS_ALL);
4175 }
4176
4177 ALIAS_HIDDEN(no_neighbor_remove_private_as_all,
4178 no_neighbor_remove_private_as_all_hidden_cmd,
4179 "no neighbor <A.B.C.D|X:X::X:X|WORD> remove-private-AS all",
4180 NO_STR NEIGHBOR_STR NEIGHBOR_ADDR_STR2
4181 "Remove private ASNs in outbound updates\n"
4182 "Apply to all AS numbers\n")
4183
4184 DEFUN (no_neighbor_remove_private_as_replace_as,
4185 no_neighbor_remove_private_as_replace_as_cmd,
4186 "no neighbor <A.B.C.D|X:X::X:X|WORD> remove-private-AS replace-AS",
4187 NO_STR
4188 NEIGHBOR_STR
4189 NEIGHBOR_ADDR_STR2
4190 "Remove private ASNs in outbound updates\n"
4191 "Replace private ASNs with our ASN in outbound updates\n")
4192 {
4193 int idx_peer = 2;
4194 return peer_af_flag_unset_vty(vty, argv[idx_peer]->arg,
4195 bgp_node_afi(vty), bgp_node_safi(vty),
4196 PEER_FLAG_REMOVE_PRIVATE_AS_REPLACE);
4197 }
4198
4199 ALIAS_HIDDEN(no_neighbor_remove_private_as_replace_as,
4200 no_neighbor_remove_private_as_replace_as_hidden_cmd,
4201 "no neighbor <A.B.C.D|X:X::X:X|WORD> remove-private-AS replace-AS",
4202 NO_STR NEIGHBOR_STR NEIGHBOR_ADDR_STR2
4203 "Remove private ASNs in outbound updates\n"
4204 "Replace private ASNs with our ASN in outbound updates\n")
4205
4206 DEFUN (no_neighbor_remove_private_as_all_replace_as,
4207 no_neighbor_remove_private_as_all_replace_as_cmd,
4208 "no neighbor <A.B.C.D|X:X::X:X|WORD> remove-private-AS all replace-AS",
4209 NO_STR
4210 NEIGHBOR_STR
4211 NEIGHBOR_ADDR_STR2
4212 "Remove private ASNs in outbound updates\n"
4213 "Apply to all AS numbers\n"
4214 "Replace private ASNs with our ASN in outbound updates\n")
4215 {
4216 int idx_peer = 2;
4217 return peer_af_flag_unset_vty(vty, argv[idx_peer]->arg,
4218 bgp_node_afi(vty), bgp_node_safi(vty),
4219 PEER_FLAG_REMOVE_PRIVATE_AS_ALL_REPLACE);
4220 }
4221
4222 ALIAS_HIDDEN(
4223 no_neighbor_remove_private_as_all_replace_as,
4224 no_neighbor_remove_private_as_all_replace_as_hidden_cmd,
4225 "no neighbor <A.B.C.D|X:X::X:X|WORD> remove-private-AS all replace-AS",
4226 NO_STR NEIGHBOR_STR NEIGHBOR_ADDR_STR2
4227 "Remove private ASNs in outbound updates\n"
4228 "Apply to all AS numbers\n"
4229 "Replace private ASNs with our ASN in outbound updates\n")
4230
4231
4232 /* neighbor send-community. */
4233 DEFUN (neighbor_send_community,
4234 neighbor_send_community_cmd,
4235 "neighbor <A.B.C.D|X:X::X:X|WORD> send-community",
4236 NEIGHBOR_STR
4237 NEIGHBOR_ADDR_STR2
4238 "Send Community attribute to this neighbor\n")
4239 {
4240 int idx_peer = 1;
4241
4242 return peer_af_flag_set_vty(vty, argv[idx_peer]->arg, bgp_node_afi(vty),
4243 bgp_node_safi(vty),
4244 PEER_FLAG_SEND_COMMUNITY);
4245 }
4246
4247 ALIAS_HIDDEN(neighbor_send_community, neighbor_send_community_hidden_cmd,
4248 "neighbor <A.B.C.D|X:X::X:X|WORD> send-community",
4249 NEIGHBOR_STR NEIGHBOR_ADDR_STR2
4250 "Send Community attribute to this neighbor\n")
4251
4252 DEFUN (no_neighbor_send_community,
4253 no_neighbor_send_community_cmd,
4254 "no neighbor <A.B.C.D|X:X::X:X|WORD> send-community",
4255 NO_STR
4256 NEIGHBOR_STR
4257 NEIGHBOR_ADDR_STR2
4258 "Send Community attribute to this neighbor\n")
4259 {
4260 int idx_peer = 2;
4261
4262 return peer_af_flag_unset_vty(vty, argv[idx_peer]->arg,
4263 bgp_node_afi(vty), bgp_node_safi(vty),
4264 PEER_FLAG_SEND_COMMUNITY);
4265 }
4266
4267 ALIAS_HIDDEN(no_neighbor_send_community, no_neighbor_send_community_hidden_cmd,
4268 "no neighbor <A.B.C.D|X:X::X:X|WORD> send-community",
4269 NO_STR NEIGHBOR_STR NEIGHBOR_ADDR_STR2
4270 "Send Community attribute to this neighbor\n")
4271
4272 /* neighbor send-community extended. */
4273 DEFUN (neighbor_send_community_type,
4274 neighbor_send_community_type_cmd,
4275 "neighbor <A.B.C.D|X:X::X:X|WORD> send-community <both|all|extended|standard|large>",
4276 NEIGHBOR_STR
4277 NEIGHBOR_ADDR_STR2
4278 "Send Community attribute to this neighbor\n"
4279 "Send Standard and Extended Community attributes\n"
4280 "Send Standard, Large and Extended Community attributes\n"
4281 "Send Extended Community attributes\n"
4282 "Send Standard Community attributes\n"
4283 "Send Large Community attributes\n")
4284 {
4285 int idx_peer = 1;
4286 uint32_t flag = 0;
4287 const char *type = argv[argc - 1]->text;
4288
4289 if (strmatch(type, "standard")) {
4290 SET_FLAG(flag, PEER_FLAG_SEND_COMMUNITY);
4291 } else if (strmatch(type, "extended")) {
4292 SET_FLAG(flag, PEER_FLAG_SEND_EXT_COMMUNITY);
4293 } else if (strmatch(type, "large")) {
4294 SET_FLAG(flag, PEER_FLAG_SEND_LARGE_COMMUNITY);
4295 } else if (strmatch(type, "both")) {
4296 SET_FLAG(flag, PEER_FLAG_SEND_COMMUNITY);
4297 SET_FLAG(flag, PEER_FLAG_SEND_EXT_COMMUNITY);
4298 } else { /* if (strmatch(type, "all")) */
4299 SET_FLAG(flag, PEER_FLAG_SEND_COMMUNITY);
4300 SET_FLAG(flag, PEER_FLAG_SEND_EXT_COMMUNITY);
4301 SET_FLAG(flag, PEER_FLAG_SEND_LARGE_COMMUNITY);
4302 }
4303
4304 return peer_af_flag_set_vty(vty, argv[idx_peer]->arg, bgp_node_afi(vty),
4305 bgp_node_safi(vty), flag);
4306 }
4307
4308 ALIAS_HIDDEN(
4309 neighbor_send_community_type, neighbor_send_community_type_hidden_cmd,
4310 "neighbor <A.B.C.D|X:X::X:X|WORD> send-community <both|all|extended|standard|large>",
4311 NEIGHBOR_STR NEIGHBOR_ADDR_STR2
4312 "Send Community attribute to this neighbor\n"
4313 "Send Standard and Extended Community attributes\n"
4314 "Send Standard, Large and Extended Community attributes\n"
4315 "Send Extended Community attributes\n"
4316 "Send Standard Community attributes\n"
4317 "Send Large Community attributes\n")
4318
4319 DEFUN (no_neighbor_send_community_type,
4320 no_neighbor_send_community_type_cmd,
4321 "no neighbor <A.B.C.D|X:X::X:X|WORD> send-community <both|all|extended|standard|large>",
4322 NO_STR
4323 NEIGHBOR_STR
4324 NEIGHBOR_ADDR_STR2
4325 "Send Community attribute to this neighbor\n"
4326 "Send Standard and Extended Community attributes\n"
4327 "Send Standard, Large and Extended Community attributes\n"
4328 "Send Extended Community attributes\n"
4329 "Send Standard Community attributes\n"
4330 "Send Large Community attributes\n")
4331 {
4332 int idx_peer = 2;
4333 uint32_t flag = 0;
4334 const char *type = argv[argc - 1]->text;
4335
4336 if (strmatch(type, "standard")) {
4337 SET_FLAG(flag, PEER_FLAG_SEND_COMMUNITY);
4338 } else if (strmatch(type, "extended")) {
4339 SET_FLAG(flag, PEER_FLAG_SEND_EXT_COMMUNITY);
4340 } else if (strmatch(type, "large")) {
4341 SET_FLAG(flag, PEER_FLAG_SEND_LARGE_COMMUNITY);
4342 } else if (strmatch(type, "both")) {
4343 SET_FLAG(flag, PEER_FLAG_SEND_COMMUNITY);
4344 SET_FLAG(flag, PEER_FLAG_SEND_EXT_COMMUNITY);
4345 } else { /* if (strmatch(type, "all")) */
4346 SET_FLAG(flag, PEER_FLAG_SEND_COMMUNITY);
4347 SET_FLAG(flag, PEER_FLAG_SEND_EXT_COMMUNITY);
4348 SET_FLAG(flag, PEER_FLAG_SEND_LARGE_COMMUNITY);
4349 }
4350
4351 return peer_af_flag_unset_vty(vty, argv[idx_peer]->arg,
4352 bgp_node_afi(vty), bgp_node_safi(vty),
4353 flag);
4354 }
4355
4356 ALIAS_HIDDEN(
4357 no_neighbor_send_community_type,
4358 no_neighbor_send_community_type_hidden_cmd,
4359 "no neighbor <A.B.C.D|X:X::X:X|WORD> send-community <both|all|extended|standard|large>",
4360 NO_STR NEIGHBOR_STR NEIGHBOR_ADDR_STR2
4361 "Send Community attribute to this neighbor\n"
4362 "Send Standard and Extended Community attributes\n"
4363 "Send Standard, Large and Extended Community attributes\n"
4364 "Send Extended Community attributes\n"
4365 "Send Standard Community attributes\n"
4366 "Send Large Community attributes\n")
4367
4368 /* neighbor soft-reconfig. */
4369 DEFUN (neighbor_soft_reconfiguration,
4370 neighbor_soft_reconfiguration_cmd,
4371 "neighbor <A.B.C.D|X:X::X:X|WORD> soft-reconfiguration inbound",
4372 NEIGHBOR_STR
4373 NEIGHBOR_ADDR_STR2
4374 "Per neighbor soft reconfiguration\n"
4375 "Allow inbound soft reconfiguration for this neighbor\n")
4376 {
4377 int idx_peer = 1;
4378 return peer_af_flag_set_vty(vty, argv[idx_peer]->arg, bgp_node_afi(vty),
4379 bgp_node_safi(vty),
4380 PEER_FLAG_SOFT_RECONFIG);
4381 }
4382
4383 ALIAS_HIDDEN(neighbor_soft_reconfiguration,
4384 neighbor_soft_reconfiguration_hidden_cmd,
4385 "neighbor <A.B.C.D|X:X::X:X|WORD> soft-reconfiguration inbound",
4386 NEIGHBOR_STR NEIGHBOR_ADDR_STR2
4387 "Per neighbor soft reconfiguration\n"
4388 "Allow inbound soft reconfiguration for this neighbor\n")
4389
4390 DEFUN (no_neighbor_soft_reconfiguration,
4391 no_neighbor_soft_reconfiguration_cmd,
4392 "no neighbor <A.B.C.D|X:X::X:X|WORD> soft-reconfiguration inbound",
4393 NO_STR
4394 NEIGHBOR_STR
4395 NEIGHBOR_ADDR_STR2
4396 "Per neighbor soft reconfiguration\n"
4397 "Allow inbound soft reconfiguration for this neighbor\n")
4398 {
4399 int idx_peer = 2;
4400 return peer_af_flag_unset_vty(vty, argv[idx_peer]->arg,
4401 bgp_node_afi(vty), bgp_node_safi(vty),
4402 PEER_FLAG_SOFT_RECONFIG);
4403 }
4404
4405 ALIAS_HIDDEN(no_neighbor_soft_reconfiguration,
4406 no_neighbor_soft_reconfiguration_hidden_cmd,
4407 "no neighbor <A.B.C.D|X:X::X:X|WORD> soft-reconfiguration inbound",
4408 NO_STR NEIGHBOR_STR NEIGHBOR_ADDR_STR2
4409 "Per neighbor soft reconfiguration\n"
4410 "Allow inbound soft reconfiguration for this neighbor\n")
4411
4412 DEFUN (neighbor_route_reflector_client,
4413 neighbor_route_reflector_client_cmd,
4414 "neighbor <A.B.C.D|X:X::X:X|WORD> route-reflector-client",
4415 NEIGHBOR_STR
4416 NEIGHBOR_ADDR_STR2
4417 "Configure a neighbor as Route Reflector client\n")
4418 {
4419 int idx_peer = 1;
4420 struct peer *peer;
4421
4422
4423 peer = peer_and_group_lookup_vty(vty, argv[idx_peer]->arg);
4424 if (!peer)
4425 return CMD_WARNING_CONFIG_FAILED;
4426
4427 return peer_af_flag_set_vty(vty, argv[idx_peer]->arg, bgp_node_afi(vty),
4428 bgp_node_safi(vty),
4429 PEER_FLAG_REFLECTOR_CLIENT);
4430 }
4431
4432 ALIAS_HIDDEN(neighbor_route_reflector_client,
4433 neighbor_route_reflector_client_hidden_cmd,
4434 "neighbor <A.B.C.D|X:X::X:X|WORD> route-reflector-client",
4435 NEIGHBOR_STR NEIGHBOR_ADDR_STR2
4436 "Configure a neighbor as Route Reflector client\n")
4437
4438 DEFUN (no_neighbor_route_reflector_client,
4439 no_neighbor_route_reflector_client_cmd,
4440 "no neighbor <A.B.C.D|X:X::X:X|WORD> route-reflector-client",
4441 NO_STR
4442 NEIGHBOR_STR
4443 NEIGHBOR_ADDR_STR2
4444 "Configure a neighbor as Route Reflector client\n")
4445 {
4446 int idx_peer = 2;
4447 return peer_af_flag_unset_vty(vty, argv[idx_peer]->arg,
4448 bgp_node_afi(vty), bgp_node_safi(vty),
4449 PEER_FLAG_REFLECTOR_CLIENT);
4450 }
4451
4452 ALIAS_HIDDEN(no_neighbor_route_reflector_client,
4453 no_neighbor_route_reflector_client_hidden_cmd,
4454 "no neighbor <A.B.C.D|X:X::X:X|WORD> route-reflector-client",
4455 NO_STR NEIGHBOR_STR NEIGHBOR_ADDR_STR2
4456 "Configure a neighbor as Route Reflector client\n")
4457
4458 /* neighbor route-server-client. */
4459 DEFUN (neighbor_route_server_client,
4460 neighbor_route_server_client_cmd,
4461 "neighbor <A.B.C.D|X:X::X:X|WORD> route-server-client",
4462 NEIGHBOR_STR
4463 NEIGHBOR_ADDR_STR2
4464 "Configure a neighbor as Route Server client\n")
4465 {
4466 int idx_peer = 1;
4467 struct peer *peer;
4468
4469 peer = peer_and_group_lookup_vty(vty, argv[idx_peer]->arg);
4470 if (!peer)
4471 return CMD_WARNING_CONFIG_FAILED;
4472 return peer_af_flag_set_vty(vty, argv[idx_peer]->arg, bgp_node_afi(vty),
4473 bgp_node_safi(vty),
4474 PEER_FLAG_RSERVER_CLIENT);
4475 }
4476
4477 ALIAS_HIDDEN(neighbor_route_server_client,
4478 neighbor_route_server_client_hidden_cmd,
4479 "neighbor <A.B.C.D|X:X::X:X|WORD> route-server-client",
4480 NEIGHBOR_STR NEIGHBOR_ADDR_STR2
4481 "Configure a neighbor as Route Server client\n")
4482
4483 DEFUN (no_neighbor_route_server_client,
4484 no_neighbor_route_server_client_cmd,
4485 "no neighbor <A.B.C.D|X:X::X:X|WORD> route-server-client",
4486 NO_STR
4487 NEIGHBOR_STR
4488 NEIGHBOR_ADDR_STR2
4489 "Configure a neighbor as Route Server client\n")
4490 {
4491 int idx_peer = 2;
4492 return peer_af_flag_unset_vty(vty, argv[idx_peer]->arg,
4493 bgp_node_afi(vty), bgp_node_safi(vty),
4494 PEER_FLAG_RSERVER_CLIENT);
4495 }
4496
4497 ALIAS_HIDDEN(no_neighbor_route_server_client,
4498 no_neighbor_route_server_client_hidden_cmd,
4499 "no neighbor <A.B.C.D|X:X::X:X|WORD> route-server-client",
4500 NO_STR NEIGHBOR_STR NEIGHBOR_ADDR_STR2
4501 "Configure a neighbor as Route Server client\n")
4502
4503 DEFUN (neighbor_nexthop_local_unchanged,
4504 neighbor_nexthop_local_unchanged_cmd,
4505 "neighbor <A.B.C.D|X:X::X:X|WORD> nexthop-local unchanged",
4506 NEIGHBOR_STR
4507 NEIGHBOR_ADDR_STR2
4508 "Configure treatment of outgoing link-local nexthop attribute\n"
4509 "Leave link-local nexthop unchanged for this peer\n")
4510 {
4511 int idx_peer = 1;
4512 return peer_af_flag_set_vty(vty, argv[idx_peer]->arg, bgp_node_afi(vty),
4513 bgp_node_safi(vty),
4514 PEER_FLAG_NEXTHOP_LOCAL_UNCHANGED);
4515 }
4516
4517 DEFUN (no_neighbor_nexthop_local_unchanged,
4518 no_neighbor_nexthop_local_unchanged_cmd,
4519 "no neighbor <A.B.C.D|X:X::X:X|WORD> nexthop-local unchanged",
4520 NO_STR
4521 NEIGHBOR_STR
4522 NEIGHBOR_ADDR_STR2
4523 "Configure treatment of outgoing link-local-nexthop attribute\n"
4524 "Leave link-local nexthop unchanged for this peer\n")
4525 {
4526 int idx_peer = 2;
4527 return peer_af_flag_unset_vty(vty, argv[idx_peer]->arg,
4528 bgp_node_afi(vty), bgp_node_safi(vty),
4529 PEER_FLAG_NEXTHOP_LOCAL_UNCHANGED);
4530 }
4531
4532 DEFUN (neighbor_attr_unchanged,
4533 neighbor_attr_unchanged_cmd,
4534 "neighbor <A.B.C.D|X:X::X:X|WORD> attribute-unchanged [{as-path|next-hop|med}]",
4535 NEIGHBOR_STR
4536 NEIGHBOR_ADDR_STR2
4537 "BGP attribute is propagated unchanged to this neighbor\n"
4538 "As-path attribute\n"
4539 "Nexthop attribute\n"
4540 "Med attribute\n")
4541 {
4542 int idx = 0;
4543 char *peer_str = argv[1]->arg;
4544 struct peer *peer;
4545 uint16_t flags = 0;
4546 afi_t afi = bgp_node_afi(vty);
4547 safi_t safi = bgp_node_safi(vty);
4548
4549 peer = peer_and_group_lookup_vty(vty, peer_str);
4550 if (!peer)
4551 return CMD_WARNING_CONFIG_FAILED;
4552
4553 if (argv_find(argv, argc, "as-path", &idx))
4554 SET_FLAG(flags, PEER_FLAG_AS_PATH_UNCHANGED);
4555 idx = 0;
4556 if (argv_find(argv, argc, "next-hop", &idx))
4557 SET_FLAG(flags, PEER_FLAG_NEXTHOP_UNCHANGED);
4558 idx = 0;
4559 if (argv_find(argv, argc, "med", &idx))
4560 SET_FLAG(flags, PEER_FLAG_MED_UNCHANGED);
4561
4562 /* no flags means all of them! */
4563 if (!flags) {
4564 SET_FLAG(flags, PEER_FLAG_AS_PATH_UNCHANGED);
4565 SET_FLAG(flags, PEER_FLAG_NEXTHOP_UNCHANGED);
4566 SET_FLAG(flags, PEER_FLAG_MED_UNCHANGED);
4567 } else {
4568 if (!CHECK_FLAG(flags, PEER_FLAG_AS_PATH_UNCHANGED)
4569 && peer_af_flag_check(peer, afi, safi,
4570 PEER_FLAG_AS_PATH_UNCHANGED)) {
4571 peer_af_flag_unset_vty(vty, peer_str, afi, safi,
4572 PEER_FLAG_AS_PATH_UNCHANGED);
4573 }
4574
4575 if (!CHECK_FLAG(flags, PEER_FLAG_NEXTHOP_UNCHANGED)
4576 && peer_af_flag_check(peer, afi, safi,
4577 PEER_FLAG_NEXTHOP_UNCHANGED)) {
4578 peer_af_flag_unset_vty(vty, peer_str, afi, safi,
4579 PEER_FLAG_NEXTHOP_UNCHANGED);
4580 }
4581
4582 if (!CHECK_FLAG(flags, PEER_FLAG_MED_UNCHANGED)
4583 && peer_af_flag_check(peer, afi, safi,
4584 PEER_FLAG_MED_UNCHANGED)) {
4585 peer_af_flag_unset_vty(vty, peer_str, afi, safi,
4586 PEER_FLAG_MED_UNCHANGED);
4587 }
4588 }
4589
4590 return peer_af_flag_set_vty(vty, peer_str, afi, safi, flags);
4591 }
4592
4593 ALIAS_HIDDEN(
4594 neighbor_attr_unchanged, neighbor_attr_unchanged_hidden_cmd,
4595 "neighbor <A.B.C.D|X:X::X:X|WORD> attribute-unchanged [{as-path|next-hop|med}]",
4596 NEIGHBOR_STR NEIGHBOR_ADDR_STR2
4597 "BGP attribute is propagated unchanged to this neighbor\n"
4598 "As-path attribute\n"
4599 "Nexthop attribute\n"
4600 "Med attribute\n")
4601
4602 DEFUN (no_neighbor_attr_unchanged,
4603 no_neighbor_attr_unchanged_cmd,
4604 "no neighbor <A.B.C.D|X:X::X:X|WORD> attribute-unchanged [{as-path|next-hop|med}]",
4605 NO_STR
4606 NEIGHBOR_STR
4607 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 int idx = 0;
4614 char *peer = argv[2]->arg;
4615 uint16_t flags = 0;
4616
4617 if (argv_find(argv, argc, "as-path", &idx))
4618 SET_FLAG(flags, PEER_FLAG_AS_PATH_UNCHANGED);
4619 idx = 0;
4620 if (argv_find(argv, argc, "next-hop", &idx))
4621 SET_FLAG(flags, PEER_FLAG_NEXTHOP_UNCHANGED);
4622 idx = 0;
4623 if (argv_find(argv, argc, "med", &idx))
4624 SET_FLAG(flags, PEER_FLAG_MED_UNCHANGED);
4625
4626 if (!flags) // no flags means all of them!
4627 {
4628 SET_FLAG(flags, PEER_FLAG_AS_PATH_UNCHANGED);
4629 SET_FLAG(flags, PEER_FLAG_NEXTHOP_UNCHANGED);
4630 SET_FLAG(flags, PEER_FLAG_MED_UNCHANGED);
4631 }
4632
4633 return peer_af_flag_unset_vty(vty, peer, bgp_node_afi(vty),
4634 bgp_node_safi(vty), flags);
4635 }
4636
4637 ALIAS_HIDDEN(
4638 no_neighbor_attr_unchanged, no_neighbor_attr_unchanged_hidden_cmd,
4639 "no neighbor <A.B.C.D|X:X::X:X|WORD> attribute-unchanged [{as-path|next-hop|med}]",
4640 NO_STR NEIGHBOR_STR NEIGHBOR_ADDR_STR2
4641 "BGP attribute is propagated unchanged to this neighbor\n"
4642 "As-path attribute\n"
4643 "Nexthop attribute\n"
4644 "Med attribute\n")
4645
4646 /* EBGP multihop configuration. */
4647 static int peer_ebgp_multihop_set_vty(struct vty *vty, const char *ip_str,
4648 const char *ttl_str)
4649 {
4650 struct peer *peer;
4651 unsigned int ttl;
4652
4653 peer = peer_and_group_lookup_vty(vty, ip_str);
4654 if (!peer)
4655 return CMD_WARNING_CONFIG_FAILED;
4656
4657 if (peer->conf_if)
4658 return bgp_vty_return(vty, BGP_ERR_INVALID_FOR_DIRECT_PEER);
4659
4660 if (!ttl_str)
4661 ttl = MAXTTL;
4662 else
4663 ttl = strtoul(ttl_str, NULL, 10);
4664
4665 return bgp_vty_return(vty, peer_ebgp_multihop_set(peer, ttl));
4666 }
4667
4668 static int peer_ebgp_multihop_unset_vty(struct vty *vty, const char *ip_str)
4669 {
4670 struct peer *peer;
4671
4672 peer = peer_and_group_lookup_vty(vty, ip_str);
4673 if (!peer)
4674 return CMD_WARNING_CONFIG_FAILED;
4675
4676 return bgp_vty_return(vty, peer_ebgp_multihop_unset(peer));
4677 }
4678
4679 /* neighbor ebgp-multihop. */
4680 DEFUN (neighbor_ebgp_multihop,
4681 neighbor_ebgp_multihop_cmd,
4682 "neighbor <A.B.C.D|X:X::X:X|WORD> ebgp-multihop",
4683 NEIGHBOR_STR
4684 NEIGHBOR_ADDR_STR2
4685 "Allow EBGP neighbors not on directly connected networks\n")
4686 {
4687 int idx_peer = 1;
4688 return peer_ebgp_multihop_set_vty(vty, argv[idx_peer]->arg, NULL);
4689 }
4690
4691 DEFUN (neighbor_ebgp_multihop_ttl,
4692 neighbor_ebgp_multihop_ttl_cmd,
4693 "neighbor <A.B.C.D|X:X::X:X|WORD> ebgp-multihop (1-255)",
4694 NEIGHBOR_STR
4695 NEIGHBOR_ADDR_STR2
4696 "Allow EBGP neighbors not on directly connected networks\n"
4697 "maximum hop count\n")
4698 {
4699 int idx_peer = 1;
4700 int idx_number = 3;
4701 return peer_ebgp_multihop_set_vty(vty, argv[idx_peer]->arg,
4702 argv[idx_number]->arg);
4703 }
4704
4705 DEFUN (no_neighbor_ebgp_multihop,
4706 no_neighbor_ebgp_multihop_cmd,
4707 "no neighbor <A.B.C.D|X:X::X:X|WORD> ebgp-multihop [(1-255)]",
4708 NO_STR
4709 NEIGHBOR_STR
4710 NEIGHBOR_ADDR_STR2
4711 "Allow EBGP neighbors not on directly connected networks\n"
4712 "maximum hop count\n")
4713 {
4714 int idx_peer = 2;
4715 return peer_ebgp_multihop_unset_vty(vty, argv[idx_peer]->arg);
4716 }
4717
4718
4719 /* disable-connected-check */
4720 DEFUN (neighbor_disable_connected_check,
4721 neighbor_disable_connected_check_cmd,
4722 "neighbor <A.B.C.D|X:X::X:X|WORD> <disable-connected-check|enforce-multihop>",
4723 NEIGHBOR_STR
4724 NEIGHBOR_ADDR_STR2
4725 "one-hop away EBGP peer using loopback address\n"
4726 "Enforce EBGP neighbors perform multihop\n")
4727 {
4728 int idx_peer = 1;
4729 return peer_flag_set_vty(vty, argv[idx_peer]->arg,
4730 PEER_FLAG_DISABLE_CONNECTED_CHECK);
4731 }
4732
4733 DEFUN (no_neighbor_disable_connected_check,
4734 no_neighbor_disable_connected_check_cmd,
4735 "no neighbor <A.B.C.D|X:X::X:X|WORD> <disable-connected-check|enforce-multihop>",
4736 NO_STR
4737 NEIGHBOR_STR
4738 NEIGHBOR_ADDR_STR2
4739 "one-hop away EBGP peer using loopback address\n"
4740 "Enforce EBGP neighbors perform multihop\n")
4741 {
4742 int idx_peer = 2;
4743 return peer_flag_unset_vty(vty, argv[idx_peer]->arg,
4744 PEER_FLAG_DISABLE_CONNECTED_CHECK);
4745 }
4746
4747
4748 /* enforce-first-as */
4749 DEFUN (neighbor_enforce_first_as,
4750 neighbor_enforce_first_as_cmd,
4751 "neighbor <A.B.C.D|X:X::X:X|WORD> enforce-first-as",
4752 NEIGHBOR_STR
4753 NEIGHBOR_ADDR_STR2
4754 "Enforce the first AS for EBGP routes\n")
4755 {
4756 int idx_peer = 1;
4757
4758 return peer_flag_set_vty(vty, argv[idx_peer]->arg,
4759 PEER_FLAG_ENFORCE_FIRST_AS);
4760 }
4761
4762 DEFUN (no_neighbor_enforce_first_as,
4763 no_neighbor_enforce_first_as_cmd,
4764 "no neighbor <A.B.C.D|X:X::X:X|WORD> enforce-first-as",
4765 NO_STR
4766 NEIGHBOR_STR
4767 NEIGHBOR_ADDR_STR2
4768 "Enforce the first AS for EBGP routes\n")
4769 {
4770 int idx_peer = 2;
4771
4772 return peer_flag_unset_vty(vty, argv[idx_peer]->arg,
4773 PEER_FLAG_ENFORCE_FIRST_AS);
4774 }
4775
4776
4777 DEFUN (neighbor_description,
4778 neighbor_description_cmd,
4779 "neighbor <A.B.C.D|X:X::X:X|WORD> description LINE...",
4780 NEIGHBOR_STR
4781 NEIGHBOR_ADDR_STR2
4782 "Neighbor specific description\n"
4783 "Up to 80 characters describing this neighbor\n")
4784 {
4785 int idx_peer = 1;
4786 int idx_line = 3;
4787 struct peer *peer;
4788 char *str;
4789
4790 peer = peer_and_group_lookup_vty(vty, argv[idx_peer]->arg);
4791 if (!peer)
4792 return CMD_WARNING_CONFIG_FAILED;
4793
4794 str = argv_concat(argv, argc, idx_line);
4795
4796 peer_description_set(peer, str);
4797
4798 XFREE(MTYPE_TMP, str);
4799
4800 return CMD_SUCCESS;
4801 }
4802
4803 DEFUN (no_neighbor_description,
4804 no_neighbor_description_cmd,
4805 "no neighbor <A.B.C.D|X:X::X:X|WORD> description",
4806 NO_STR
4807 NEIGHBOR_STR
4808 NEIGHBOR_ADDR_STR2
4809 "Neighbor specific description\n")
4810 {
4811 int idx_peer = 2;
4812 struct peer *peer;
4813
4814 peer = peer_and_group_lookup_vty(vty, argv[idx_peer]->arg);
4815 if (!peer)
4816 return CMD_WARNING_CONFIG_FAILED;
4817
4818 peer_description_unset(peer);
4819
4820 return CMD_SUCCESS;
4821 }
4822
4823 ALIAS(no_neighbor_description, no_neighbor_description_comment_cmd,
4824 "no neighbor <A.B.C.D|X:X::X:X|WORD> description LINE...",
4825 NO_STR NEIGHBOR_STR NEIGHBOR_ADDR_STR2
4826 "Neighbor specific description\n"
4827 "Up to 80 characters describing this neighbor\n")
4828
4829 /* Neighbor update-source. */
4830 static int peer_update_source_vty(struct vty *vty, const char *peer_str,
4831 const char *source_str)
4832 {
4833 struct peer *peer;
4834 struct prefix p;
4835 union sockunion su;
4836
4837 peer = peer_and_group_lookup_vty(vty, peer_str);
4838 if (!peer)
4839 return CMD_WARNING_CONFIG_FAILED;
4840
4841 if (peer->conf_if)
4842 return CMD_WARNING;
4843
4844 if (source_str) {
4845 if (str2sockunion(source_str, &su) == 0)
4846 peer_update_source_addr_set(peer, &su);
4847 else {
4848 if (str2prefix(source_str, &p)) {
4849 vty_out(vty,
4850 "%% Invalid update-source, remove prefix length \n");
4851 return CMD_WARNING_CONFIG_FAILED;
4852 } else
4853 peer_update_source_if_set(peer, source_str);
4854 }
4855 } else
4856 peer_update_source_unset(peer);
4857
4858 return CMD_SUCCESS;
4859 }
4860
4861 #define BGP_UPDATE_SOURCE_HELP_STR \
4862 "IPv4 address\n" \
4863 "IPv6 address\n" \
4864 "Interface name (requires zebra to be running)\n"
4865
4866 DEFUN (neighbor_update_source,
4867 neighbor_update_source_cmd,
4868 "neighbor <A.B.C.D|X:X::X:X|WORD> update-source <A.B.C.D|X:X::X:X|WORD>",
4869 NEIGHBOR_STR
4870 NEIGHBOR_ADDR_STR2
4871 "Source of routing updates\n"
4872 BGP_UPDATE_SOURCE_HELP_STR)
4873 {
4874 int idx_peer = 1;
4875 int idx_peer_2 = 3;
4876 return peer_update_source_vty(vty, argv[idx_peer]->arg,
4877 argv[idx_peer_2]->arg);
4878 }
4879
4880 DEFUN (no_neighbor_update_source,
4881 no_neighbor_update_source_cmd,
4882 "no neighbor <A.B.C.D|X:X::X:X|WORD> update-source [<A.B.C.D|X:X::X:X|WORD>]",
4883 NO_STR
4884 NEIGHBOR_STR
4885 NEIGHBOR_ADDR_STR2
4886 "Source of routing updates\n"
4887 BGP_UPDATE_SOURCE_HELP_STR)
4888 {
4889 int idx_peer = 2;
4890 return peer_update_source_vty(vty, argv[idx_peer]->arg, NULL);
4891 }
4892
4893 static int peer_default_originate_set_vty(struct vty *vty, const char *peer_str,
4894 afi_t afi, safi_t safi,
4895 const char *rmap, int set)
4896 {
4897 int ret;
4898 struct peer *peer;
4899 struct route_map *route_map;
4900
4901 peer = peer_and_group_lookup_vty(vty, peer_str);
4902 if (!peer)
4903 return CMD_WARNING_CONFIG_FAILED;
4904
4905 if (set) {
4906 route_map = route_map_lookup_warn_noexist(vty, rmap);
4907 ret = peer_default_originate_set(peer, afi, safi,
4908 rmap, route_map);
4909 } else
4910 ret = peer_default_originate_unset(peer, afi, safi);
4911
4912 return bgp_vty_return(vty, ret);
4913 }
4914
4915 /* neighbor default-originate. */
4916 DEFUN (neighbor_default_originate,
4917 neighbor_default_originate_cmd,
4918 "neighbor <A.B.C.D|X:X::X:X|WORD> default-originate",
4919 NEIGHBOR_STR
4920 NEIGHBOR_ADDR_STR2
4921 "Originate default route to this neighbor\n")
4922 {
4923 int idx_peer = 1;
4924 return peer_default_originate_set_vty(vty, argv[idx_peer]->arg,
4925 bgp_node_afi(vty),
4926 bgp_node_safi(vty), NULL, 1);
4927 }
4928
4929 ALIAS_HIDDEN(neighbor_default_originate, neighbor_default_originate_hidden_cmd,
4930 "neighbor <A.B.C.D|X:X::X:X|WORD> default-originate",
4931 NEIGHBOR_STR NEIGHBOR_ADDR_STR2
4932 "Originate default route to this neighbor\n")
4933
4934 DEFUN (neighbor_default_originate_rmap,
4935 neighbor_default_originate_rmap_cmd,
4936 "neighbor <A.B.C.D|X:X::X:X|WORD> default-originate route-map WORD",
4937 NEIGHBOR_STR
4938 NEIGHBOR_ADDR_STR2
4939 "Originate default route to this neighbor\n"
4940 "Route-map to specify criteria to originate default\n"
4941 "route-map name\n")
4942 {
4943 int idx_peer = 1;
4944 int idx_word = 4;
4945 return peer_default_originate_set_vty(
4946 vty, argv[idx_peer]->arg, bgp_node_afi(vty), bgp_node_safi(vty),
4947 argv[idx_word]->arg, 1);
4948 }
4949
4950 ALIAS_HIDDEN(
4951 neighbor_default_originate_rmap,
4952 neighbor_default_originate_rmap_hidden_cmd,
4953 "neighbor <A.B.C.D|X:X::X:X|WORD> default-originate route-map WORD",
4954 NEIGHBOR_STR NEIGHBOR_ADDR_STR2
4955 "Originate default route to this neighbor\n"
4956 "Route-map to specify criteria to originate default\n"
4957 "route-map name\n")
4958
4959 DEFUN (no_neighbor_default_originate,
4960 no_neighbor_default_originate_cmd,
4961 "no neighbor <A.B.C.D|X:X::X:X|WORD> default-originate [route-map WORD]",
4962 NO_STR
4963 NEIGHBOR_STR
4964 NEIGHBOR_ADDR_STR2
4965 "Originate default route to this neighbor\n"
4966 "Route-map to specify criteria to originate default\n"
4967 "route-map name\n")
4968 {
4969 int idx_peer = 2;
4970 return peer_default_originate_set_vty(vty, argv[idx_peer]->arg,
4971 bgp_node_afi(vty),
4972 bgp_node_safi(vty), NULL, 0);
4973 }
4974
4975 ALIAS_HIDDEN(
4976 no_neighbor_default_originate, no_neighbor_default_originate_hidden_cmd,
4977 "no neighbor <A.B.C.D|X:X::X:X|WORD> default-originate [route-map WORD]",
4978 NO_STR NEIGHBOR_STR NEIGHBOR_ADDR_STR2
4979 "Originate default route to this neighbor\n"
4980 "Route-map to specify criteria to originate default\n"
4981 "route-map name\n")
4982
4983
4984 /* Set neighbor's BGP port. */
4985 static int peer_port_vty(struct vty *vty, const char *ip_str, int afi,
4986 const char *port_str)
4987 {
4988 struct peer *peer;
4989 uint16_t port;
4990 struct servent *sp;
4991
4992 peer = peer_lookup_vty(vty, ip_str);
4993 if (!peer)
4994 return CMD_WARNING_CONFIG_FAILED;
4995
4996 if (!port_str) {
4997 sp = getservbyname("bgp", "tcp");
4998 port = (sp == NULL) ? BGP_PORT_DEFAULT : ntohs(sp->s_port);
4999 } else {
5000 port = strtoul(port_str, NULL, 10);
5001 }
5002
5003 peer_port_set(peer, port);
5004
5005 return CMD_SUCCESS;
5006 }
5007
5008 /* Set specified peer's BGP port. */
5009 DEFUN (neighbor_port,
5010 neighbor_port_cmd,
5011 "neighbor <A.B.C.D|X:X::X:X> port (0-65535)",
5012 NEIGHBOR_STR
5013 NEIGHBOR_ADDR_STR
5014 "Neighbor's BGP port\n"
5015 "TCP port number\n")
5016 {
5017 int idx_ip = 1;
5018 int idx_number = 3;
5019 return peer_port_vty(vty, argv[idx_ip]->arg, AFI_IP,
5020 argv[idx_number]->arg);
5021 }
5022
5023 DEFUN (no_neighbor_port,
5024 no_neighbor_port_cmd,
5025 "no neighbor <A.B.C.D|X:X::X:X> port [(0-65535)]",
5026 NO_STR
5027 NEIGHBOR_STR
5028 NEIGHBOR_ADDR_STR
5029 "Neighbor's BGP port\n"
5030 "TCP port number\n")
5031 {
5032 int idx_ip = 2;
5033 return peer_port_vty(vty, argv[idx_ip]->arg, AFI_IP, NULL);
5034 }
5035
5036
5037 /* neighbor weight. */
5038 static int peer_weight_set_vty(struct vty *vty, const char *ip_str, afi_t afi,
5039 safi_t safi, const char *weight_str)
5040 {
5041 int ret;
5042 struct peer *peer;
5043 unsigned long weight;
5044
5045 peer = peer_and_group_lookup_vty(vty, ip_str);
5046 if (!peer)
5047 return CMD_WARNING_CONFIG_FAILED;
5048
5049 weight = strtoul(weight_str, NULL, 10);
5050
5051 ret = peer_weight_set(peer, afi, safi, weight);
5052 return bgp_vty_return(vty, ret);
5053 }
5054
5055 static int peer_weight_unset_vty(struct vty *vty, const char *ip_str, afi_t afi,
5056 safi_t safi)
5057 {
5058 int ret;
5059 struct peer *peer;
5060
5061 peer = peer_and_group_lookup_vty(vty, ip_str);
5062 if (!peer)
5063 return CMD_WARNING_CONFIG_FAILED;
5064
5065 ret = peer_weight_unset(peer, afi, safi);
5066 return bgp_vty_return(vty, ret);
5067 }
5068
5069 DEFUN (neighbor_weight,
5070 neighbor_weight_cmd,
5071 "neighbor <A.B.C.D|X:X::X:X|WORD> weight (0-65535)",
5072 NEIGHBOR_STR
5073 NEIGHBOR_ADDR_STR2
5074 "Set default weight for routes from this neighbor\n"
5075 "default weight\n")
5076 {
5077 int idx_peer = 1;
5078 int idx_number = 3;
5079 return peer_weight_set_vty(vty, argv[idx_peer]->arg, bgp_node_afi(vty),
5080 bgp_node_safi(vty), argv[idx_number]->arg);
5081 }
5082
5083 ALIAS_HIDDEN(neighbor_weight, neighbor_weight_hidden_cmd,
5084 "neighbor <A.B.C.D|X:X::X:X|WORD> weight (0-65535)",
5085 NEIGHBOR_STR NEIGHBOR_ADDR_STR2
5086 "Set default weight for routes from this neighbor\n"
5087 "default weight\n")
5088
5089 DEFUN (no_neighbor_weight,
5090 no_neighbor_weight_cmd,
5091 "no neighbor <A.B.C.D|X:X::X:X|WORD> weight [(0-65535)]",
5092 NO_STR
5093 NEIGHBOR_STR
5094 NEIGHBOR_ADDR_STR2
5095 "Set default weight for routes from this neighbor\n"
5096 "default weight\n")
5097 {
5098 int idx_peer = 2;
5099 return peer_weight_unset_vty(vty, argv[idx_peer]->arg,
5100 bgp_node_afi(vty), bgp_node_safi(vty));
5101 }
5102
5103 ALIAS_HIDDEN(no_neighbor_weight, no_neighbor_weight_hidden_cmd,
5104 "no neighbor <A.B.C.D|X:X::X:X|WORD> weight [(0-65535)]",
5105 NO_STR NEIGHBOR_STR NEIGHBOR_ADDR_STR2
5106 "Set default weight for routes from this neighbor\n"
5107 "default weight\n")
5108
5109
5110 /* Override capability negotiation. */
5111 DEFUN (neighbor_override_capability,
5112 neighbor_override_capability_cmd,
5113 "neighbor <A.B.C.D|X:X::X:X|WORD> override-capability",
5114 NEIGHBOR_STR
5115 NEIGHBOR_ADDR_STR2
5116 "Override capability negotiation result\n")
5117 {
5118 int idx_peer = 1;
5119 return peer_flag_set_vty(vty, argv[idx_peer]->arg,
5120 PEER_FLAG_OVERRIDE_CAPABILITY);
5121 }
5122
5123 DEFUN (no_neighbor_override_capability,
5124 no_neighbor_override_capability_cmd,
5125 "no neighbor <A.B.C.D|X:X::X:X|WORD> override-capability",
5126 NO_STR
5127 NEIGHBOR_STR
5128 NEIGHBOR_ADDR_STR2
5129 "Override capability negotiation result\n")
5130 {
5131 int idx_peer = 2;
5132 return peer_flag_unset_vty(vty, argv[idx_peer]->arg,
5133 PEER_FLAG_OVERRIDE_CAPABILITY);
5134 }
5135
5136 DEFUN (neighbor_strict_capability,
5137 neighbor_strict_capability_cmd,
5138 "neighbor <A.B.C.D|X:X::X:X|WORD> strict-capability-match",
5139 NEIGHBOR_STR
5140 NEIGHBOR_ADDR_STR2
5141 "Strict capability negotiation match\n")
5142 {
5143 int idx_peer = 1;
5144
5145 return peer_flag_set_vty(vty, argv[idx_peer]->arg,
5146 PEER_FLAG_STRICT_CAP_MATCH);
5147 }
5148
5149 DEFUN (no_neighbor_strict_capability,
5150 no_neighbor_strict_capability_cmd,
5151 "no neighbor <A.B.C.D|X:X::X:X|WORD> strict-capability-match",
5152 NO_STR
5153 NEIGHBOR_STR
5154 NEIGHBOR_ADDR_STR2
5155 "Strict capability negotiation match\n")
5156 {
5157 int idx_peer = 2;
5158
5159 return peer_flag_unset_vty(vty, argv[idx_peer]->arg,
5160 PEER_FLAG_STRICT_CAP_MATCH);
5161 }
5162
5163 static int peer_timers_set_vty(struct vty *vty, const char *ip_str,
5164 const char *keep_str, const char *hold_str)
5165 {
5166 int ret;
5167 struct peer *peer;
5168 uint32_t keepalive;
5169 uint32_t holdtime;
5170
5171 peer = peer_and_group_lookup_vty(vty, ip_str);
5172 if (!peer)
5173 return CMD_WARNING_CONFIG_FAILED;
5174
5175 keepalive = strtoul(keep_str, NULL, 10);
5176 holdtime = strtoul(hold_str, NULL, 10);
5177
5178 ret = peer_timers_set(peer, keepalive, holdtime);
5179
5180 return bgp_vty_return(vty, ret);
5181 }
5182
5183 static int peer_timers_unset_vty(struct vty *vty, const char *ip_str)
5184 {
5185 int ret;
5186 struct peer *peer;
5187
5188 peer = peer_and_group_lookup_vty(vty, ip_str);
5189 if (!peer)
5190 return CMD_WARNING_CONFIG_FAILED;
5191
5192 ret = peer_timers_unset(peer);
5193
5194 return bgp_vty_return(vty, ret);
5195 }
5196
5197 DEFUN (neighbor_timers,
5198 neighbor_timers_cmd,
5199 "neighbor <A.B.C.D|X:X::X:X|WORD> timers (0-65535) (0-65535)",
5200 NEIGHBOR_STR
5201 NEIGHBOR_ADDR_STR2
5202 "BGP per neighbor timers\n"
5203 "Keepalive interval\n"
5204 "Holdtime\n")
5205 {
5206 int idx_peer = 1;
5207 int idx_number = 3;
5208 int idx_number_2 = 4;
5209 return peer_timers_set_vty(vty, argv[idx_peer]->arg,
5210 argv[idx_number]->arg,
5211 argv[idx_number_2]->arg);
5212 }
5213
5214 DEFUN (no_neighbor_timers,
5215 no_neighbor_timers_cmd,
5216 "no neighbor <A.B.C.D|X:X::X:X|WORD> timers [(0-65535) (0-65535)]",
5217 NO_STR
5218 NEIGHBOR_STR
5219 NEIGHBOR_ADDR_STR2
5220 "BGP per neighbor timers\n"
5221 "Keepalive interval\n"
5222 "Holdtime\n")
5223 {
5224 int idx_peer = 2;
5225 return peer_timers_unset_vty(vty, argv[idx_peer]->arg);
5226 }
5227
5228
5229 static int peer_timers_connect_set_vty(struct vty *vty, const char *ip_str,
5230 const char *time_str)
5231 {
5232 int ret;
5233 struct peer *peer;
5234 uint32_t connect;
5235
5236 peer = peer_and_group_lookup_vty(vty, ip_str);
5237 if (!peer)
5238 return CMD_WARNING_CONFIG_FAILED;
5239
5240 connect = strtoul(time_str, NULL, 10);
5241
5242 ret = peer_timers_connect_set(peer, connect);
5243
5244 return bgp_vty_return(vty, ret);
5245 }
5246
5247 static int peer_timers_connect_unset_vty(struct vty *vty, const char *ip_str)
5248 {
5249 int ret;
5250 struct peer *peer;
5251
5252 peer = peer_and_group_lookup_vty(vty, ip_str);
5253 if (!peer)
5254 return CMD_WARNING_CONFIG_FAILED;
5255
5256 ret = peer_timers_connect_unset(peer);
5257
5258 return bgp_vty_return(vty, ret);
5259 }
5260
5261 DEFUN (neighbor_timers_connect,
5262 neighbor_timers_connect_cmd,
5263 "neighbor <A.B.C.D|X:X::X:X|WORD> timers connect (1-65535)",
5264 NEIGHBOR_STR
5265 NEIGHBOR_ADDR_STR2
5266 "BGP per neighbor timers\n"
5267 "BGP connect timer\n"
5268 "Connect timer\n")
5269 {
5270 int idx_peer = 1;
5271 int idx_number = 4;
5272 return peer_timers_connect_set_vty(vty, argv[idx_peer]->arg,
5273 argv[idx_number]->arg);
5274 }
5275
5276 DEFUN (no_neighbor_timers_connect,
5277 no_neighbor_timers_connect_cmd,
5278 "no neighbor <A.B.C.D|X:X::X:X|WORD> timers connect [(1-65535)]",
5279 NO_STR
5280 NEIGHBOR_STR
5281 NEIGHBOR_ADDR_STR2
5282 "BGP per neighbor timers\n"
5283 "BGP connect timer\n"
5284 "Connect timer\n")
5285 {
5286 int idx_peer = 2;
5287 return peer_timers_connect_unset_vty(vty, argv[idx_peer]->arg);
5288 }
5289
5290
5291 static int peer_advertise_interval_vty(struct vty *vty, const char *ip_str,
5292 const char *time_str, int set)
5293 {
5294 int ret;
5295 struct peer *peer;
5296 uint32_t routeadv = 0;
5297
5298 peer = peer_and_group_lookup_vty(vty, ip_str);
5299 if (!peer)
5300 return CMD_WARNING_CONFIG_FAILED;
5301
5302 if (time_str)
5303 routeadv = strtoul(time_str, NULL, 10);
5304
5305 if (set)
5306 ret = peer_advertise_interval_set(peer, routeadv);
5307 else
5308 ret = peer_advertise_interval_unset(peer);
5309
5310 return bgp_vty_return(vty, ret);
5311 }
5312
5313 DEFUN (neighbor_advertise_interval,
5314 neighbor_advertise_interval_cmd,
5315 "neighbor <A.B.C.D|X:X::X:X|WORD> advertisement-interval (0-600)",
5316 NEIGHBOR_STR
5317 NEIGHBOR_ADDR_STR2
5318 "Minimum interval between sending BGP routing updates\n"
5319 "time in seconds\n")
5320 {
5321 int idx_peer = 1;
5322 int idx_number = 3;
5323 return peer_advertise_interval_vty(vty, argv[idx_peer]->arg,
5324 argv[idx_number]->arg, 1);
5325 }
5326
5327 DEFUN (no_neighbor_advertise_interval,
5328 no_neighbor_advertise_interval_cmd,
5329 "no neighbor <A.B.C.D|X:X::X:X|WORD> advertisement-interval [(0-600)]",
5330 NO_STR
5331 NEIGHBOR_STR
5332 NEIGHBOR_ADDR_STR2
5333 "Minimum interval between sending BGP routing updates\n"
5334 "time in seconds\n")
5335 {
5336 int idx_peer = 2;
5337 return peer_advertise_interval_vty(vty, argv[idx_peer]->arg, NULL, 0);
5338 }
5339
5340
5341 /* Time to wait before processing route-map updates */
5342 DEFUN (bgp_set_route_map_delay_timer,
5343 bgp_set_route_map_delay_timer_cmd,
5344 "bgp route-map delay-timer (0-600)",
5345 SET_STR
5346 "BGP route-map delay timer\n"
5347 "Time in secs to wait before processing route-map changes\n"
5348 "0 disables the timer, no route updates happen when route-maps change\n")
5349 {
5350 int idx_number = 3;
5351 uint32_t rmap_delay_timer;
5352
5353 if (argv[idx_number]->arg) {
5354 rmap_delay_timer = strtoul(argv[idx_number]->arg, NULL, 10);
5355 bm->rmap_update_timer = rmap_delay_timer;
5356
5357 /* if the dynamic update handling is being disabled, and a timer
5358 * is
5359 * running, stop the timer and act as if the timer has already
5360 * fired.
5361 */
5362 if (!rmap_delay_timer && bm->t_rmap_update) {
5363 BGP_TIMER_OFF(bm->t_rmap_update);
5364 thread_execute(bm->master, bgp_route_map_update_timer,
5365 NULL, 0);
5366 }
5367 return CMD_SUCCESS;
5368 } else {
5369 vty_out(vty, "%% BGP invalid route-map delay-timer\n");
5370 return CMD_WARNING_CONFIG_FAILED;
5371 }
5372 }
5373
5374 DEFUN (no_bgp_set_route_map_delay_timer,
5375 no_bgp_set_route_map_delay_timer_cmd,
5376 "no bgp route-map delay-timer [(0-600)]",
5377 NO_STR
5378 BGP_STR
5379 "Default BGP route-map delay timer\n"
5380 "Reset to default time to wait for processing route-map changes\n"
5381 "0 disables the timer, no route updates happen when route-maps change\n")
5382 {
5383
5384 bm->rmap_update_timer = RMAP_DEFAULT_UPDATE_TIMER;
5385
5386 return CMD_SUCCESS;
5387 }
5388
5389
5390 /* neighbor interface */
5391 static int peer_interface_vty(struct vty *vty, const char *ip_str,
5392 const char *str)
5393 {
5394 struct peer *peer;
5395
5396 peer = peer_lookup_vty(vty, ip_str);
5397 if (!peer || peer->conf_if) {
5398 vty_out(vty, "%% BGP invalid peer %s\n", ip_str);
5399 return CMD_WARNING_CONFIG_FAILED;
5400 }
5401
5402 if (str)
5403 peer_interface_set(peer, str);
5404 else
5405 peer_interface_unset(peer);
5406
5407 return CMD_SUCCESS;
5408 }
5409
5410 DEFUN (neighbor_interface,
5411 neighbor_interface_cmd,
5412 "neighbor <A.B.C.D|X:X::X:X> interface WORD",
5413 NEIGHBOR_STR
5414 NEIGHBOR_ADDR_STR
5415 "Interface\n"
5416 "Interface name\n")
5417 {
5418 int idx_ip = 1;
5419 int idx_word = 3;
5420 return peer_interface_vty(vty, argv[idx_ip]->arg, argv[idx_word]->arg);
5421 }
5422
5423 DEFUN (no_neighbor_interface,
5424 no_neighbor_interface_cmd,
5425 "no neighbor <A.B.C.D|X:X::X:X|WORD> interface WORD",
5426 NO_STR
5427 NEIGHBOR_STR
5428 NEIGHBOR_ADDR_STR2
5429 "Interface\n"
5430 "Interface name\n")
5431 {
5432 int idx_peer = 2;
5433 return peer_interface_vty(vty, argv[idx_peer]->arg, NULL);
5434 }
5435
5436 DEFUN (neighbor_distribute_list,
5437 neighbor_distribute_list_cmd,
5438 "neighbor <A.B.C.D|X:X::X:X|WORD> distribute-list <(1-199)|(1300-2699)|WORD> <in|out>",
5439 NEIGHBOR_STR
5440 NEIGHBOR_ADDR_STR2
5441 "Filter updates to/from this neighbor\n"
5442 "IP access-list number\n"
5443 "IP access-list number (expanded range)\n"
5444 "IP Access-list name\n"
5445 "Filter incoming updates\n"
5446 "Filter outgoing updates\n")
5447 {
5448 int idx_peer = 1;
5449 int idx_acl = 3;
5450 int direct, ret;
5451 struct peer *peer;
5452
5453 const char *pstr = argv[idx_peer]->arg;
5454 const char *acl = argv[idx_acl]->arg;
5455 const char *inout = argv[argc - 1]->text;
5456
5457 peer = peer_and_group_lookup_vty(vty, pstr);
5458 if (!peer)
5459 return CMD_WARNING_CONFIG_FAILED;
5460
5461 /* Check filter direction. */
5462 direct = strmatch(inout, "in") ? FILTER_IN : FILTER_OUT;
5463 ret = peer_distribute_set(peer, bgp_node_afi(vty), bgp_node_safi(vty),
5464 direct, acl);
5465
5466 return bgp_vty_return(vty, ret);
5467 }
5468
5469 ALIAS_HIDDEN(
5470 neighbor_distribute_list, neighbor_distribute_list_hidden_cmd,
5471 "neighbor <A.B.C.D|X:X::X:X|WORD> distribute-list <(1-199)|(1300-2699)|WORD> <in|out>",
5472 NEIGHBOR_STR NEIGHBOR_ADDR_STR2
5473 "Filter updates to/from this neighbor\n"
5474 "IP access-list number\n"
5475 "IP access-list number (expanded range)\n"
5476 "IP Access-list name\n"
5477 "Filter incoming updates\n"
5478 "Filter outgoing updates\n")
5479
5480 DEFUN (no_neighbor_distribute_list,
5481 no_neighbor_distribute_list_cmd,
5482 "no neighbor <A.B.C.D|X:X::X:X|WORD> distribute-list <(1-199)|(1300-2699)|WORD> <in|out>",
5483 NO_STR
5484 NEIGHBOR_STR
5485 NEIGHBOR_ADDR_STR2
5486 "Filter updates to/from this neighbor\n"
5487 "IP access-list number\n"
5488 "IP access-list number (expanded range)\n"
5489 "IP Access-list name\n"
5490 "Filter incoming updates\n"
5491 "Filter outgoing updates\n")
5492 {
5493 int idx_peer = 2;
5494 int direct, ret;
5495 struct peer *peer;
5496
5497 const char *pstr = argv[idx_peer]->arg;
5498 const char *inout = argv[argc - 1]->text;
5499
5500 peer = peer_and_group_lookup_vty(vty, pstr);
5501 if (!peer)
5502 return CMD_WARNING_CONFIG_FAILED;
5503
5504 /* Check filter direction. */
5505 direct = strmatch(inout, "in") ? FILTER_IN : FILTER_OUT;
5506 ret = peer_distribute_unset(peer, bgp_node_afi(vty), bgp_node_safi(vty),
5507 direct);
5508
5509 return bgp_vty_return(vty, ret);
5510 }
5511
5512 ALIAS_HIDDEN(
5513 no_neighbor_distribute_list, no_neighbor_distribute_list_hidden_cmd,
5514 "no neighbor <A.B.C.D|X:X::X:X|WORD> distribute-list <(1-199)|(1300-2699)|WORD> <in|out>",
5515 NO_STR NEIGHBOR_STR NEIGHBOR_ADDR_STR2
5516 "Filter updates to/from this neighbor\n"
5517 "IP access-list number\n"
5518 "IP access-list number (expanded range)\n"
5519 "IP Access-list name\n"
5520 "Filter incoming updates\n"
5521 "Filter outgoing updates\n")
5522
5523 /* Set prefix list to the peer. */
5524 static int peer_prefix_list_set_vty(struct vty *vty, const char *ip_str,
5525 afi_t afi, safi_t safi,
5526 const char *name_str,
5527 const char *direct_str)
5528 {
5529 int ret;
5530 int direct = FILTER_IN;
5531 struct peer *peer;
5532
5533 peer = peer_and_group_lookup_vty(vty, ip_str);
5534 if (!peer)
5535 return CMD_WARNING_CONFIG_FAILED;
5536
5537 /* Check filter direction. */
5538 if (strncmp(direct_str, "i", 1) == 0)
5539 direct = FILTER_IN;
5540 else if (strncmp(direct_str, "o", 1) == 0)
5541 direct = FILTER_OUT;
5542
5543 ret = peer_prefix_list_set(peer, afi, safi, direct, name_str);
5544
5545 return bgp_vty_return(vty, ret);
5546 }
5547
5548 static int peer_prefix_list_unset_vty(struct vty *vty, const char *ip_str,
5549 afi_t afi, safi_t safi,
5550 const char *direct_str)
5551 {
5552 int ret;
5553 struct peer *peer;
5554 int direct = FILTER_IN;
5555
5556 peer = peer_and_group_lookup_vty(vty, ip_str);
5557 if (!peer)
5558 return CMD_WARNING_CONFIG_FAILED;
5559
5560 /* Check filter direction. */
5561 if (strncmp(direct_str, "i", 1) == 0)
5562 direct = FILTER_IN;
5563 else if (strncmp(direct_str, "o", 1) == 0)
5564 direct = FILTER_OUT;
5565
5566 ret = peer_prefix_list_unset(peer, afi, safi, direct);
5567
5568 return bgp_vty_return(vty, ret);
5569 }
5570
5571 DEFUN (neighbor_prefix_list,
5572 neighbor_prefix_list_cmd,
5573 "neighbor <A.B.C.D|X:X::X:X|WORD> prefix-list WORD <in|out>",
5574 NEIGHBOR_STR
5575 NEIGHBOR_ADDR_STR2
5576 "Filter updates to/from this neighbor\n"
5577 "Name of a prefix list\n"
5578 "Filter incoming updates\n"
5579 "Filter outgoing updates\n")
5580 {
5581 int idx_peer = 1;
5582 int idx_word = 3;
5583 int idx_in_out = 4;
5584 return peer_prefix_list_set_vty(
5585 vty, argv[idx_peer]->arg, bgp_node_afi(vty), bgp_node_safi(vty),
5586 argv[idx_word]->arg, argv[idx_in_out]->arg);
5587 }
5588
5589 ALIAS_HIDDEN(neighbor_prefix_list, neighbor_prefix_list_hidden_cmd,
5590 "neighbor <A.B.C.D|X:X::X:X|WORD> prefix-list WORD <in|out>",
5591 NEIGHBOR_STR NEIGHBOR_ADDR_STR2
5592 "Filter updates to/from this neighbor\n"
5593 "Name of a prefix list\n"
5594 "Filter incoming updates\n"
5595 "Filter outgoing updates\n")
5596
5597 DEFUN (no_neighbor_prefix_list,
5598 no_neighbor_prefix_list_cmd,
5599 "no neighbor <A.B.C.D|X:X::X:X|WORD> prefix-list WORD <in|out>",
5600 NO_STR
5601 NEIGHBOR_STR
5602 NEIGHBOR_ADDR_STR2
5603 "Filter updates to/from this neighbor\n"
5604 "Name of a prefix list\n"
5605 "Filter incoming updates\n"
5606 "Filter outgoing updates\n")
5607 {
5608 int idx_peer = 2;
5609 int idx_in_out = 5;
5610 return peer_prefix_list_unset_vty(vty, argv[idx_peer]->arg,
5611 bgp_node_afi(vty), bgp_node_safi(vty),
5612 argv[idx_in_out]->arg);
5613 }
5614
5615 ALIAS_HIDDEN(no_neighbor_prefix_list, no_neighbor_prefix_list_hidden_cmd,
5616 "no neighbor <A.B.C.D|X:X::X:X|WORD> prefix-list WORD <in|out>",
5617 NO_STR NEIGHBOR_STR NEIGHBOR_ADDR_STR2
5618 "Filter updates to/from this neighbor\n"
5619 "Name of a prefix list\n"
5620 "Filter incoming updates\n"
5621 "Filter outgoing updates\n")
5622
5623 static int peer_aslist_set_vty(struct vty *vty, const char *ip_str, afi_t afi,
5624 safi_t safi, const char *name_str,
5625 const char *direct_str)
5626 {
5627 int ret;
5628 struct peer *peer;
5629 int direct = FILTER_IN;
5630
5631 peer = peer_and_group_lookup_vty(vty, ip_str);
5632 if (!peer)
5633 return CMD_WARNING_CONFIG_FAILED;
5634
5635 /* Check filter direction. */
5636 if (strncmp(direct_str, "i", 1) == 0)
5637 direct = FILTER_IN;
5638 else if (strncmp(direct_str, "o", 1) == 0)
5639 direct = FILTER_OUT;
5640
5641 ret = peer_aslist_set(peer, afi, safi, direct, name_str);
5642
5643 return bgp_vty_return(vty, ret);
5644 }
5645
5646 static int peer_aslist_unset_vty(struct vty *vty, const char *ip_str, afi_t afi,
5647 safi_t safi, const char *direct_str)
5648 {
5649 int ret;
5650 struct peer *peer;
5651 int direct = FILTER_IN;
5652
5653 peer = peer_and_group_lookup_vty(vty, ip_str);
5654 if (!peer)
5655 return CMD_WARNING_CONFIG_FAILED;
5656
5657 /* Check filter direction. */
5658 if (strncmp(direct_str, "i", 1) == 0)
5659 direct = FILTER_IN;
5660 else if (strncmp(direct_str, "o", 1) == 0)
5661 direct = FILTER_OUT;
5662
5663 ret = peer_aslist_unset(peer, afi, safi, direct);
5664
5665 return bgp_vty_return(vty, ret);
5666 }
5667
5668 DEFUN (neighbor_filter_list,
5669 neighbor_filter_list_cmd,
5670 "neighbor <A.B.C.D|X:X::X:X|WORD> filter-list WORD <in|out>",
5671 NEIGHBOR_STR
5672 NEIGHBOR_ADDR_STR2
5673 "Establish BGP filters\n"
5674 "AS path access-list name\n"
5675 "Filter incoming routes\n"
5676 "Filter outgoing routes\n")
5677 {
5678 int idx_peer = 1;
5679 int idx_word = 3;
5680 int idx_in_out = 4;
5681 return peer_aslist_set_vty(vty, argv[idx_peer]->arg, bgp_node_afi(vty),
5682 bgp_node_safi(vty), argv[idx_word]->arg,
5683 argv[idx_in_out]->arg);
5684 }
5685
5686 ALIAS_HIDDEN(neighbor_filter_list, neighbor_filter_list_hidden_cmd,
5687 "neighbor <A.B.C.D|X:X::X:X|WORD> filter-list WORD <in|out>",
5688 NEIGHBOR_STR NEIGHBOR_ADDR_STR2
5689 "Establish BGP filters\n"
5690 "AS path access-list name\n"
5691 "Filter incoming routes\n"
5692 "Filter outgoing routes\n")
5693
5694 DEFUN (no_neighbor_filter_list,
5695 no_neighbor_filter_list_cmd,
5696 "no neighbor <A.B.C.D|X:X::X:X|WORD> filter-list WORD <in|out>",
5697 NO_STR
5698 NEIGHBOR_STR
5699 NEIGHBOR_ADDR_STR2
5700 "Establish BGP filters\n"
5701 "AS path access-list name\n"
5702 "Filter incoming routes\n"
5703 "Filter outgoing routes\n")
5704 {
5705 int idx_peer = 2;
5706 int idx_in_out = 5;
5707 return peer_aslist_unset_vty(vty, argv[idx_peer]->arg,
5708 bgp_node_afi(vty), bgp_node_safi(vty),
5709 argv[idx_in_out]->arg);
5710 }
5711
5712 ALIAS_HIDDEN(no_neighbor_filter_list, no_neighbor_filter_list_hidden_cmd,
5713 "no neighbor <A.B.C.D|X:X::X:X|WORD> filter-list WORD <in|out>",
5714 NO_STR NEIGHBOR_STR NEIGHBOR_ADDR_STR2
5715 "Establish BGP filters\n"
5716 "AS path access-list name\n"
5717 "Filter incoming routes\n"
5718 "Filter outgoing routes\n")
5719
5720 /* Set route-map to the peer. */
5721 static int peer_route_map_set_vty(struct vty *vty, const char *ip_str,
5722 afi_t afi, safi_t safi, const char *name_str,
5723 const char *direct_str)
5724 {
5725 int ret;
5726 struct peer *peer;
5727 int direct = RMAP_IN;
5728 struct route_map *route_map;
5729
5730 peer = peer_and_group_lookup_vty(vty, ip_str);
5731 if (!peer)
5732 return CMD_WARNING_CONFIG_FAILED;
5733
5734 /* Check filter direction. */
5735 if (strncmp(direct_str, "in", 2) == 0)
5736 direct = RMAP_IN;
5737 else if (strncmp(direct_str, "o", 1) == 0)
5738 direct = RMAP_OUT;
5739
5740 route_map = route_map_lookup_warn_noexist(vty, name_str);
5741 ret = peer_route_map_set(peer, afi, safi, direct, name_str, route_map);
5742
5743 return bgp_vty_return(vty, ret);
5744 }
5745
5746 static int peer_route_map_unset_vty(struct vty *vty, const char *ip_str,
5747 afi_t afi, safi_t safi,
5748 const char *direct_str)
5749 {
5750 int ret;
5751 struct peer *peer;
5752 int direct = RMAP_IN;
5753
5754 peer = peer_and_group_lookup_vty(vty, ip_str);
5755 if (!peer)
5756 return CMD_WARNING_CONFIG_FAILED;
5757
5758 /* Check filter direction. */
5759 if (strncmp(direct_str, "in", 2) == 0)
5760 direct = RMAP_IN;
5761 else if (strncmp(direct_str, "o", 1) == 0)
5762 direct = RMAP_OUT;
5763
5764 ret = peer_route_map_unset(peer, afi, safi, direct);
5765
5766 return bgp_vty_return(vty, ret);
5767 }
5768
5769 DEFUN (neighbor_route_map,
5770 neighbor_route_map_cmd,
5771 "neighbor <A.B.C.D|X:X::X:X|WORD> route-map WORD <in|out>",
5772 NEIGHBOR_STR
5773 NEIGHBOR_ADDR_STR2
5774 "Apply route map to neighbor\n"
5775 "Name of route map\n"
5776 "Apply map to incoming routes\n"
5777 "Apply map to outbound routes\n")
5778 {
5779 int idx_peer = 1;
5780 int idx_word = 3;
5781 int idx_in_out = 4;
5782 return peer_route_map_set_vty(
5783 vty, argv[idx_peer]->arg, bgp_node_afi(vty), bgp_node_safi(vty),
5784 argv[idx_word]->arg, argv[idx_in_out]->arg);
5785 }
5786
5787 ALIAS_HIDDEN(neighbor_route_map, neighbor_route_map_hidden_cmd,
5788 "neighbor <A.B.C.D|X:X::X:X|WORD> route-map WORD <in|out>",
5789 NEIGHBOR_STR NEIGHBOR_ADDR_STR2
5790 "Apply route map to neighbor\n"
5791 "Name of route map\n"
5792 "Apply map to incoming routes\n"
5793 "Apply map to outbound routes\n")
5794
5795 DEFUN (no_neighbor_route_map,
5796 no_neighbor_route_map_cmd,
5797 "no neighbor <A.B.C.D|X:X::X:X|WORD> route-map WORD <in|out>",
5798 NO_STR
5799 NEIGHBOR_STR
5800 NEIGHBOR_ADDR_STR2
5801 "Apply route map to neighbor\n"
5802 "Name of route map\n"
5803 "Apply map to incoming routes\n"
5804 "Apply map to outbound routes\n")
5805 {
5806 int idx_peer = 2;
5807 int idx_in_out = 5;
5808 return peer_route_map_unset_vty(vty, argv[idx_peer]->arg,
5809 bgp_node_afi(vty), bgp_node_safi(vty),
5810 argv[idx_in_out]->arg);
5811 }
5812
5813 ALIAS_HIDDEN(no_neighbor_route_map, no_neighbor_route_map_hidden_cmd,
5814 "no neighbor <A.B.C.D|X:X::X:X|WORD> route-map WORD <in|out>",
5815 NO_STR NEIGHBOR_STR NEIGHBOR_ADDR_STR2
5816 "Apply route map to neighbor\n"
5817 "Name of route map\n"
5818 "Apply map to incoming routes\n"
5819 "Apply map to outbound routes\n")
5820
5821 /* Set unsuppress-map to the peer. */
5822 static int peer_unsuppress_map_set_vty(struct vty *vty, const char *ip_str,
5823 afi_t afi, safi_t safi,
5824 const char *name_str)
5825 {
5826 int ret;
5827 struct peer *peer;
5828 struct route_map *route_map;
5829
5830 peer = peer_and_group_lookup_vty(vty, ip_str);
5831 if (!peer)
5832 return CMD_WARNING_CONFIG_FAILED;
5833
5834 route_map = route_map_lookup_warn_noexist(vty, name_str);
5835 ret = peer_unsuppress_map_set(peer, afi, safi, name_str, route_map);
5836
5837 return bgp_vty_return(vty, ret);
5838 }
5839
5840 /* Unset route-map from the peer. */
5841 static int peer_unsuppress_map_unset_vty(struct vty *vty, const char *ip_str,
5842 afi_t afi, safi_t safi)
5843 {
5844 int ret;
5845 struct peer *peer;
5846
5847 peer = peer_and_group_lookup_vty(vty, ip_str);
5848 if (!peer)
5849 return CMD_WARNING_CONFIG_FAILED;
5850
5851 ret = peer_unsuppress_map_unset(peer, afi, safi);
5852
5853 return bgp_vty_return(vty, ret);
5854 }
5855
5856 DEFUN (neighbor_unsuppress_map,
5857 neighbor_unsuppress_map_cmd,
5858 "neighbor <A.B.C.D|X:X::X:X|WORD> unsuppress-map WORD",
5859 NEIGHBOR_STR
5860 NEIGHBOR_ADDR_STR2
5861 "Route-map to selectively unsuppress suppressed routes\n"
5862 "Name of route map\n")
5863 {
5864 int idx_peer = 1;
5865 int idx_word = 3;
5866 return peer_unsuppress_map_set_vty(
5867 vty, argv[idx_peer]->arg, bgp_node_afi(vty), bgp_node_safi(vty),
5868 argv[idx_word]->arg);
5869 }
5870
5871 ALIAS_HIDDEN(neighbor_unsuppress_map, neighbor_unsuppress_map_hidden_cmd,
5872 "neighbor <A.B.C.D|X:X::X:X|WORD> unsuppress-map WORD",
5873 NEIGHBOR_STR NEIGHBOR_ADDR_STR2
5874 "Route-map to selectively unsuppress suppressed routes\n"
5875 "Name of route map\n")
5876
5877 DEFUN (no_neighbor_unsuppress_map,
5878 no_neighbor_unsuppress_map_cmd,
5879 "no neighbor <A.B.C.D|X:X::X:X|WORD> unsuppress-map WORD",
5880 NO_STR
5881 NEIGHBOR_STR
5882 NEIGHBOR_ADDR_STR2
5883 "Route-map to selectively unsuppress suppressed routes\n"
5884 "Name of route map\n")
5885 {
5886 int idx_peer = 2;
5887 return peer_unsuppress_map_unset_vty(vty, argv[idx_peer]->arg,
5888 bgp_node_afi(vty),
5889 bgp_node_safi(vty));
5890 }
5891
5892 ALIAS_HIDDEN(no_neighbor_unsuppress_map, no_neighbor_unsuppress_map_hidden_cmd,
5893 "no neighbor <A.B.C.D|X:X::X:X|WORD> unsuppress-map WORD",
5894 NO_STR NEIGHBOR_STR NEIGHBOR_ADDR_STR2
5895 "Route-map to selectively unsuppress suppressed routes\n"
5896 "Name of route map\n")
5897
5898 static int peer_maximum_prefix_set_vty(struct vty *vty, const char *ip_str,
5899 afi_t afi, safi_t safi,
5900 const char *num_str,
5901 const char *threshold_str, int warning,
5902 const char *restart_str)
5903 {
5904 int ret;
5905 struct peer *peer;
5906 uint32_t max;
5907 uint8_t threshold;
5908 uint16_t restart;
5909
5910 peer = peer_and_group_lookup_vty(vty, ip_str);
5911 if (!peer)
5912 return CMD_WARNING_CONFIG_FAILED;
5913
5914 max = strtoul(num_str, NULL, 10);
5915 if (threshold_str)
5916 threshold = atoi(threshold_str);
5917 else
5918 threshold = MAXIMUM_PREFIX_THRESHOLD_DEFAULT;
5919
5920 if (restart_str)
5921 restart = atoi(restart_str);
5922 else
5923 restart = 0;
5924
5925 ret = peer_maximum_prefix_set(peer, afi, safi, max, threshold, warning,
5926 restart);
5927
5928 return bgp_vty_return(vty, ret);
5929 }
5930
5931 static int peer_maximum_prefix_unset_vty(struct vty *vty, const char *ip_str,
5932 afi_t afi, safi_t safi)
5933 {
5934 int ret;
5935 struct peer *peer;
5936
5937 peer = peer_and_group_lookup_vty(vty, ip_str);
5938 if (!peer)
5939 return CMD_WARNING_CONFIG_FAILED;
5940
5941 ret = peer_maximum_prefix_unset(peer, afi, safi);
5942
5943 return bgp_vty_return(vty, ret);
5944 }
5945
5946 /* Maximum number of prefix configuration. prefix count is different
5947 for each peer configuration. So this configuration can be set for
5948 each peer configuration. */
5949 DEFUN (neighbor_maximum_prefix,
5950 neighbor_maximum_prefix_cmd,
5951 "neighbor <A.B.C.D|X:X::X:X|WORD> maximum-prefix (1-4294967295)",
5952 NEIGHBOR_STR
5953 NEIGHBOR_ADDR_STR2
5954 "Maximum number of prefix accept from this peer\n"
5955 "maximum no. of prefix limit\n")
5956 {
5957 int idx_peer = 1;
5958 int idx_number = 3;
5959 return peer_maximum_prefix_set_vty(
5960 vty, argv[idx_peer]->arg, bgp_node_afi(vty), bgp_node_safi(vty),
5961 argv[idx_number]->arg, NULL, 0, NULL);
5962 }
5963
5964 ALIAS_HIDDEN(neighbor_maximum_prefix, neighbor_maximum_prefix_hidden_cmd,
5965 "neighbor <A.B.C.D|X:X::X:X|WORD> maximum-prefix (1-4294967295)",
5966 NEIGHBOR_STR NEIGHBOR_ADDR_STR2
5967 "Maximum number of prefix accept from this peer\n"
5968 "maximum no. of prefix limit\n")
5969
5970 DEFUN (neighbor_maximum_prefix_threshold,
5971 neighbor_maximum_prefix_threshold_cmd,
5972 "neighbor <A.B.C.D|X:X::X:X|WORD> maximum-prefix (1-4294967295) (1-100)",
5973 NEIGHBOR_STR
5974 NEIGHBOR_ADDR_STR2
5975 "Maximum number of prefix accept from this peer\n"
5976 "maximum no. of prefix limit\n"
5977 "Threshold value (%) at which to generate a warning msg\n")
5978 {
5979 int idx_peer = 1;
5980 int idx_number = 3;
5981 int idx_number_2 = 4;
5982 return peer_maximum_prefix_set_vty(
5983 vty, argv[idx_peer]->arg, bgp_node_afi(vty), bgp_node_safi(vty),
5984 argv[idx_number]->arg, argv[idx_number_2]->arg, 0, NULL);
5985 }
5986
5987 ALIAS_HIDDEN(
5988 neighbor_maximum_prefix_threshold,
5989 neighbor_maximum_prefix_threshold_hidden_cmd,
5990 "neighbor <A.B.C.D|X:X::X:X|WORD> maximum-prefix (1-4294967295) (1-100)",
5991 NEIGHBOR_STR NEIGHBOR_ADDR_STR2
5992 "Maximum number of prefix accept from this peer\n"
5993 "maximum no. of prefix limit\n"
5994 "Threshold value (%) at which to generate a warning msg\n")
5995
5996 DEFUN (neighbor_maximum_prefix_warning,
5997 neighbor_maximum_prefix_warning_cmd,
5998 "neighbor <A.B.C.D|X:X::X:X|WORD> maximum-prefix (1-4294967295) warning-only",
5999 NEIGHBOR_STR
6000 NEIGHBOR_ADDR_STR2
6001 "Maximum number of prefix accept from this peer\n"
6002 "maximum no. of prefix limit\n"
6003 "Only give warning message when limit is exceeded\n")
6004 {
6005 int idx_peer = 1;
6006 int idx_number = 3;
6007 return peer_maximum_prefix_set_vty(
6008 vty, argv[idx_peer]->arg, bgp_node_afi(vty), bgp_node_safi(vty),
6009 argv[idx_number]->arg, NULL, 1, NULL);
6010 }
6011
6012 ALIAS_HIDDEN(
6013 neighbor_maximum_prefix_warning,
6014 neighbor_maximum_prefix_warning_hidden_cmd,
6015 "neighbor <A.B.C.D|X:X::X:X|WORD> maximum-prefix (1-4294967295) warning-only",
6016 NEIGHBOR_STR NEIGHBOR_ADDR_STR2
6017 "Maximum number of prefix accept from this peer\n"
6018 "maximum no. of prefix limit\n"
6019 "Only give warning message when limit is exceeded\n")
6020
6021 DEFUN (neighbor_maximum_prefix_threshold_warning,
6022 neighbor_maximum_prefix_threshold_warning_cmd,
6023 "neighbor <A.B.C.D|X:X::X:X|WORD> maximum-prefix (1-4294967295) (1-100) warning-only",
6024 NEIGHBOR_STR
6025 NEIGHBOR_ADDR_STR2
6026 "Maximum number of prefix accept from this peer\n"
6027 "maximum no. of prefix limit\n"
6028 "Threshold value (%) at which to generate a warning msg\n"
6029 "Only give warning message when limit is exceeded\n")
6030 {
6031 int idx_peer = 1;
6032 int idx_number = 3;
6033 int idx_number_2 = 4;
6034 return peer_maximum_prefix_set_vty(
6035 vty, argv[idx_peer]->arg, bgp_node_afi(vty), bgp_node_safi(vty),
6036 argv[idx_number]->arg, argv[idx_number_2]->arg, 1, NULL);
6037 }
6038
6039 ALIAS_HIDDEN(
6040 neighbor_maximum_prefix_threshold_warning,
6041 neighbor_maximum_prefix_threshold_warning_hidden_cmd,
6042 "neighbor <A.B.C.D|X:X::X:X|WORD> maximum-prefix (1-4294967295) (1-100) warning-only",
6043 NEIGHBOR_STR NEIGHBOR_ADDR_STR2
6044 "Maximum number of prefix accept from this peer\n"
6045 "maximum no. of prefix limit\n"
6046 "Threshold value (%) at which to generate a warning msg\n"
6047 "Only give warning message when limit is exceeded\n")
6048
6049 DEFUN (neighbor_maximum_prefix_restart,
6050 neighbor_maximum_prefix_restart_cmd,
6051 "neighbor <A.B.C.D|X:X::X:X|WORD> maximum-prefix (1-4294967295) restart (1-65535)",
6052 NEIGHBOR_STR
6053 NEIGHBOR_ADDR_STR2
6054 "Maximum number of prefix accept from this peer\n"
6055 "maximum no. of prefix limit\n"
6056 "Restart bgp connection after limit is exceeded\n"
6057 "Restart interval in minutes\n")
6058 {
6059 int idx_peer = 1;
6060 int idx_number = 3;
6061 int idx_number_2 = 5;
6062 return peer_maximum_prefix_set_vty(
6063 vty, argv[idx_peer]->arg, bgp_node_afi(vty), bgp_node_safi(vty),
6064 argv[idx_number]->arg, NULL, 0, argv[idx_number_2]->arg);
6065 }
6066
6067 ALIAS_HIDDEN(
6068 neighbor_maximum_prefix_restart,
6069 neighbor_maximum_prefix_restart_hidden_cmd,
6070 "neighbor <A.B.C.D|X:X::X:X|WORD> maximum-prefix (1-4294967295) restart (1-65535)",
6071 NEIGHBOR_STR NEIGHBOR_ADDR_STR2
6072 "Maximum number of prefix accept from this peer\n"
6073 "maximum no. of prefix limit\n"
6074 "Restart bgp connection after limit is exceeded\n"
6075 "Restart interval in minutes\n")
6076
6077 DEFUN (neighbor_maximum_prefix_threshold_restart,
6078 neighbor_maximum_prefix_threshold_restart_cmd,
6079 "neighbor <A.B.C.D|X:X::X:X|WORD> maximum-prefix (1-4294967295) (1-100) restart (1-65535)",
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 {
6088 int idx_peer = 1;
6089 int idx_number = 3;
6090 int idx_number_2 = 4;
6091 int idx_number_3 = 6;
6092 return peer_maximum_prefix_set_vty(
6093 vty, argv[idx_peer]->arg, bgp_node_afi(vty), bgp_node_safi(vty),
6094 argv[idx_number]->arg, argv[idx_number_2]->arg, 0,
6095 argv[idx_number_3]->arg);
6096 }
6097
6098 ALIAS_HIDDEN(
6099 neighbor_maximum_prefix_threshold_restart,
6100 neighbor_maximum_prefix_threshold_restart_hidden_cmd,
6101 "neighbor <A.B.C.D|X:X::X:X|WORD> maximum-prefix (1-4294967295) (1-100) restart (1-65535)",
6102 NEIGHBOR_STR NEIGHBOR_ADDR_STR2
6103 "Maximum number of prefixes to accept from this peer\n"
6104 "maximum no. of prefix limit\n"
6105 "Threshold value (%) at which to generate a warning msg\n"
6106 "Restart bgp connection after limit is exceeded\n"
6107 "Restart interval in minutes\n")
6108
6109 DEFUN (no_neighbor_maximum_prefix,
6110 no_neighbor_maximum_prefix_cmd,
6111 "no neighbor <A.B.C.D|X:X::X:X|WORD> maximum-prefix [(1-4294967295) [(1-100)] [restart (1-65535)] [warning-only]]",
6112 NO_STR
6113 NEIGHBOR_STR
6114 NEIGHBOR_ADDR_STR2
6115 "Maximum number of prefixes to accept from this peer\n"
6116 "maximum no. of prefix limit\n"
6117 "Threshold value (%) at which to generate a warning msg\n"
6118 "Restart bgp connection after limit is exceeded\n"
6119 "Restart interval in minutes\n"
6120 "Only give warning message when limit is exceeded\n")
6121 {
6122 int idx_peer = 2;
6123 return peer_maximum_prefix_unset_vty(vty, argv[idx_peer]->arg,
6124 bgp_node_afi(vty),
6125 bgp_node_safi(vty));
6126 }
6127
6128 ALIAS_HIDDEN(
6129 no_neighbor_maximum_prefix, no_neighbor_maximum_prefix_hidden_cmd,
6130 "no neighbor <A.B.C.D|X:X::X:X|WORD> maximum-prefix [(1-4294967295) [(1-100)] [restart (1-65535)] [warning-only]]",
6131 NO_STR NEIGHBOR_STR NEIGHBOR_ADDR_STR2
6132 "Maximum number of prefixes to accept from this peer\n"
6133 "maximum no. of prefix limit\n"
6134 "Threshold value (%) at which to generate a warning msg\n"
6135 "Restart bgp connection after limit is exceeded\n"
6136 "Restart interval in minutes\n"
6137 "Only give warning message when limit is exceeded\n")
6138
6139
6140 /* "neighbor allowas-in" */
6141 DEFUN (neighbor_allowas_in,
6142 neighbor_allowas_in_cmd,
6143 "neighbor <A.B.C.D|X:X::X:X|WORD> allowas-in [<(1-10)|origin>]",
6144 NEIGHBOR_STR
6145 NEIGHBOR_ADDR_STR2
6146 "Accept as-path with my AS present in it\n"
6147 "Number of occurences of AS number\n"
6148 "Only accept my AS in the as-path if the route was originated in my AS\n")
6149 {
6150 int idx_peer = 1;
6151 int idx_number_origin = 3;
6152 int ret;
6153 int origin = 0;
6154 struct peer *peer;
6155 int allow_num = 0;
6156
6157 peer = peer_and_group_lookup_vty(vty, argv[idx_peer]->arg);
6158 if (!peer)
6159 return CMD_WARNING_CONFIG_FAILED;
6160
6161 if (argc <= idx_number_origin)
6162 allow_num = 3;
6163 else {
6164 if (argv[idx_number_origin]->type == WORD_TKN)
6165 origin = 1;
6166 else
6167 allow_num = atoi(argv[idx_number_origin]->arg);
6168 }
6169
6170 ret = peer_allowas_in_set(peer, bgp_node_afi(vty), bgp_node_safi(vty),
6171 allow_num, origin);
6172
6173 return bgp_vty_return(vty, ret);
6174 }
6175
6176 ALIAS_HIDDEN(
6177 neighbor_allowas_in, neighbor_allowas_in_hidden_cmd,
6178 "neighbor <A.B.C.D|X:X::X:X|WORD> allowas-in [<(1-10)|origin>]",
6179 NEIGHBOR_STR NEIGHBOR_ADDR_STR2
6180 "Accept as-path with my AS present in it\n"
6181 "Number of occurences of AS number\n"
6182 "Only accept my AS in the as-path if the route was originated in my AS\n")
6183
6184 DEFUN (no_neighbor_allowas_in,
6185 no_neighbor_allowas_in_cmd,
6186 "no neighbor <A.B.C.D|X:X::X:X|WORD> allowas-in [<(1-10)|origin>]",
6187 NO_STR
6188 NEIGHBOR_STR
6189 NEIGHBOR_ADDR_STR2
6190 "allow local ASN appears in aspath attribute\n"
6191 "Number of occurences of AS number\n"
6192 "Only accept my AS in the as-path if the route was originated in my AS\n")
6193 {
6194 int idx_peer = 2;
6195 int ret;
6196 struct peer *peer;
6197
6198 peer = peer_and_group_lookup_vty(vty, argv[idx_peer]->arg);
6199 if (!peer)
6200 return CMD_WARNING_CONFIG_FAILED;
6201
6202 ret = peer_allowas_in_unset(peer, bgp_node_afi(vty),
6203 bgp_node_safi(vty));
6204
6205 return bgp_vty_return(vty, ret);
6206 }
6207
6208 ALIAS_HIDDEN(
6209 no_neighbor_allowas_in, no_neighbor_allowas_in_hidden_cmd,
6210 "no neighbor <A.B.C.D|X:X::X:X|WORD> allowas-in [<(1-10)|origin>]",
6211 NO_STR NEIGHBOR_STR NEIGHBOR_ADDR_STR2
6212 "allow local ASN appears in aspath attribute\n"
6213 "Number of occurences of AS number\n"
6214 "Only accept my AS in the as-path if the route was originated in my AS\n")
6215
6216 DEFUN (neighbor_ttl_security,
6217 neighbor_ttl_security_cmd,
6218 "neighbor <A.B.C.D|X:X::X:X|WORD> ttl-security hops (1-254)",
6219 NEIGHBOR_STR
6220 NEIGHBOR_ADDR_STR2
6221 "BGP ttl-security parameters\n"
6222 "Specify the maximum number of hops to the BGP peer\n"
6223 "Number of hops to BGP peer\n")
6224 {
6225 int idx_peer = 1;
6226 int idx_number = 4;
6227 struct peer *peer;
6228 int gtsm_hops;
6229
6230 peer = peer_and_group_lookup_vty(vty, argv[idx_peer]->arg);
6231 if (!peer)
6232 return CMD_WARNING_CONFIG_FAILED;
6233
6234 gtsm_hops = strtoul(argv[idx_number]->arg, NULL, 10);
6235
6236 /*
6237 * If 'neighbor swpX', then this is for directly connected peers,
6238 * we should not accept a ttl-security hops value greater than 1.
6239 */
6240 if (peer->conf_if && (gtsm_hops > 1)) {
6241 vty_out(vty,
6242 "%s is directly connected peer, hops cannot exceed 1\n",
6243 argv[idx_peer]->arg);
6244 return CMD_WARNING_CONFIG_FAILED;
6245 }
6246
6247 return bgp_vty_return(vty, peer_ttl_security_hops_set(peer, gtsm_hops));
6248 }
6249
6250 DEFUN (no_neighbor_ttl_security,
6251 no_neighbor_ttl_security_cmd,
6252 "no neighbor <A.B.C.D|X:X::X:X|WORD> ttl-security hops (1-254)",
6253 NO_STR
6254 NEIGHBOR_STR
6255 NEIGHBOR_ADDR_STR2
6256 "BGP ttl-security parameters\n"
6257 "Specify the maximum number of hops to the BGP peer\n"
6258 "Number of hops to BGP peer\n")
6259 {
6260 int idx_peer = 2;
6261 struct peer *peer;
6262
6263 peer = peer_and_group_lookup_vty(vty, argv[idx_peer]->arg);
6264 if (!peer)
6265 return CMD_WARNING_CONFIG_FAILED;
6266
6267 return bgp_vty_return(vty, peer_ttl_security_hops_unset(peer));
6268 }
6269
6270 DEFUN (neighbor_addpath_tx_all_paths,
6271 neighbor_addpath_tx_all_paths_cmd,
6272 "neighbor <A.B.C.D|X:X::X:X|WORD> addpath-tx-all-paths",
6273 NEIGHBOR_STR
6274 NEIGHBOR_ADDR_STR2
6275 "Use addpath to advertise all paths to a neighbor\n")
6276 {
6277 int idx_peer = 1;
6278 struct peer *peer;
6279
6280 peer = peer_and_group_lookup_vty(vty, argv[idx_peer]->arg);
6281 if (!peer)
6282 return CMD_WARNING_CONFIG_FAILED;
6283
6284 bgp_addpath_set_peer_type(peer, bgp_node_afi(vty), bgp_node_safi(vty),
6285 BGP_ADDPATH_ALL);
6286 return CMD_SUCCESS;
6287 }
6288
6289 ALIAS_HIDDEN(neighbor_addpath_tx_all_paths,
6290 neighbor_addpath_tx_all_paths_hidden_cmd,
6291 "neighbor <A.B.C.D|X:X::X:X|WORD> addpath-tx-all-paths",
6292 NEIGHBOR_STR NEIGHBOR_ADDR_STR2
6293 "Use addpath to advertise all paths to a neighbor\n")
6294
6295 DEFUN (no_neighbor_addpath_tx_all_paths,
6296 no_neighbor_addpath_tx_all_paths_cmd,
6297 "no neighbor <A.B.C.D|X:X::X:X|WORD> addpath-tx-all-paths",
6298 NO_STR
6299 NEIGHBOR_STR
6300 NEIGHBOR_ADDR_STR2
6301 "Use addpath to advertise all paths to a neighbor\n")
6302 {
6303 int idx_peer = 2;
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 if (peer->addpath_type[bgp_node_afi(vty)][bgp_node_safi(vty)]
6311 != BGP_ADDPATH_ALL) {
6312 vty_out(vty,
6313 "%% Peer not currently configured to transmit all paths.");
6314 return CMD_WARNING_CONFIG_FAILED;
6315 }
6316
6317 bgp_addpath_set_peer_type(peer, bgp_node_afi(vty), bgp_node_safi(vty),
6318 BGP_ADDPATH_NONE);
6319
6320 return CMD_SUCCESS;
6321 }
6322
6323 ALIAS_HIDDEN(no_neighbor_addpath_tx_all_paths,
6324 no_neighbor_addpath_tx_all_paths_hidden_cmd,
6325 "no neighbor <A.B.C.D|X:X::X:X|WORD> addpath-tx-all-paths",
6326 NO_STR NEIGHBOR_STR NEIGHBOR_ADDR_STR2
6327 "Use addpath to advertise all paths to a neighbor\n")
6328
6329 DEFUN (neighbor_addpath_tx_bestpath_per_as,
6330 neighbor_addpath_tx_bestpath_per_as_cmd,
6331 "neighbor <A.B.C.D|X:X::X:X|WORD> addpath-tx-bestpath-per-AS",
6332 NEIGHBOR_STR
6333 NEIGHBOR_ADDR_STR2
6334 "Use addpath to advertise the bestpath per each neighboring AS\n")
6335 {
6336 int idx_peer = 1;
6337 struct peer *peer;
6338
6339 peer = peer_and_group_lookup_vty(vty, argv[idx_peer]->arg);
6340 if (!peer)
6341 return CMD_WARNING_CONFIG_FAILED;
6342
6343 bgp_addpath_set_peer_type(peer, bgp_node_afi(vty), bgp_node_safi(vty),
6344 BGP_ADDPATH_BEST_PER_AS);
6345
6346 return CMD_SUCCESS;
6347 }
6348
6349 ALIAS_HIDDEN(neighbor_addpath_tx_bestpath_per_as,
6350 neighbor_addpath_tx_bestpath_per_as_hidden_cmd,
6351 "neighbor <A.B.C.D|X:X::X:X|WORD> addpath-tx-bestpath-per-AS",
6352 NEIGHBOR_STR NEIGHBOR_ADDR_STR2
6353 "Use addpath to advertise the bestpath per each neighboring AS\n")
6354
6355 DEFUN (no_neighbor_addpath_tx_bestpath_per_as,
6356 no_neighbor_addpath_tx_bestpath_per_as_cmd,
6357 "no neighbor <A.B.C.D|X:X::X:X|WORD> addpath-tx-bestpath-per-AS",
6358 NO_STR
6359 NEIGHBOR_STR
6360 NEIGHBOR_ADDR_STR2
6361 "Use addpath to advertise the bestpath per each neighboring AS\n")
6362 {
6363 int idx_peer = 2;
6364 struct peer *peer;
6365
6366 peer = peer_and_group_lookup_vty(vty, argv[idx_peer]->arg);
6367 if (!peer)
6368 return CMD_WARNING_CONFIG_FAILED;
6369
6370 if (peer->addpath_type[bgp_node_afi(vty)][bgp_node_safi(vty)]
6371 != BGP_ADDPATH_BEST_PER_AS) {
6372 vty_out(vty,
6373 "%% Peer not currently configured to transmit all best path per as.");
6374 return CMD_WARNING_CONFIG_FAILED;
6375 }
6376
6377 bgp_addpath_set_peer_type(peer, bgp_node_afi(vty), bgp_node_safi(vty),
6378 BGP_ADDPATH_NONE);
6379
6380 return CMD_SUCCESS;
6381 }
6382
6383 ALIAS_HIDDEN(no_neighbor_addpath_tx_bestpath_per_as,
6384 no_neighbor_addpath_tx_bestpath_per_as_hidden_cmd,
6385 "no neighbor <A.B.C.D|X:X::X:X|WORD> addpath-tx-bestpath-per-AS",
6386 NO_STR NEIGHBOR_STR NEIGHBOR_ADDR_STR2
6387 "Use addpath to advertise the bestpath per each neighboring AS\n")
6388
6389 static int set_ecom_list(struct vty *vty, int argc, struct cmd_token **argv,
6390 struct ecommunity **list)
6391 {
6392 struct ecommunity *ecom = NULL;
6393 struct ecommunity *ecomadd;
6394
6395 for (; argc; --argc, ++argv) {
6396
6397 ecomadd = ecommunity_str2com(argv[0]->arg,
6398 ECOMMUNITY_ROUTE_TARGET, 0);
6399 if (!ecomadd) {
6400 vty_out(vty, "Malformed community-list value\n");
6401 if (ecom)
6402 ecommunity_free(&ecom);
6403 return CMD_WARNING_CONFIG_FAILED;
6404 }
6405
6406 if (ecom) {
6407 ecommunity_merge(ecom, ecomadd);
6408 ecommunity_free(&ecomadd);
6409 } else {
6410 ecom = ecomadd;
6411 }
6412 }
6413
6414 if (*list) {
6415 ecommunity_free(&*list);
6416 }
6417 *list = ecom;
6418
6419 return CMD_SUCCESS;
6420 }
6421
6422 /*
6423 * v2vimport is true if we are handling a `import vrf ...` command
6424 */
6425 static afi_t vpn_policy_getafi(struct vty *vty, struct bgp *bgp, bool v2vimport)
6426 {
6427 afi_t afi;
6428
6429 switch (vty->node) {
6430 case BGP_IPV4_NODE:
6431 afi = AFI_IP;
6432 break;
6433 case BGP_IPV6_NODE:
6434 afi = AFI_IP6;
6435 break;
6436 default:
6437 vty_out(vty,
6438 "%% context error: valid only in address-family <ipv4|ipv6> unicast block\n");
6439 return AFI_MAX;
6440 }
6441
6442 if (!v2vimport) {
6443 if (CHECK_FLAG(bgp->af_flags[afi][SAFI_UNICAST],
6444 BGP_CONFIG_VRF_TO_VRF_IMPORT)
6445 || CHECK_FLAG(bgp->af_flags[afi][SAFI_UNICAST],
6446 BGP_CONFIG_VRF_TO_VRF_EXPORT)) {
6447 vty_out(vty,
6448 "%% error: Please unconfigure import vrf commands before using vpn commands\n");
6449 return AFI_MAX;
6450 }
6451 } else {
6452 if (CHECK_FLAG(bgp->af_flags[afi][SAFI_UNICAST],
6453 BGP_CONFIG_VRF_TO_MPLSVPN_EXPORT)
6454 || CHECK_FLAG(bgp->af_flags[afi][SAFI_UNICAST],
6455 BGP_CONFIG_MPLSVPN_TO_VRF_IMPORT)) {
6456 vty_out(vty,
6457 "%% error: Please unconfigure vpn to vrf commands before using import vrf commands\n");
6458 return AFI_MAX;
6459 }
6460 }
6461 return afi;
6462 }
6463
6464 DEFPY (af_rd_vpn_export,
6465 af_rd_vpn_export_cmd,
6466 "[no] rd vpn export ASN:NN_OR_IP-ADDRESS:NN$rd_str",
6467 NO_STR
6468 "Specify route distinguisher\n"
6469 "Between current address-family and vpn\n"
6470 "For routes leaked from current address-family to vpn\n"
6471 "Route Distinguisher (<as-number>:<number> | <ip-address>:<number>)\n")
6472 {
6473 VTY_DECLVAR_CONTEXT(bgp, bgp);
6474 struct prefix_rd prd;
6475 int ret;
6476 afi_t afi;
6477 int idx = 0;
6478 int yes = 1;
6479
6480 if (argv_find(argv, argc, "no", &idx))
6481 yes = 0;
6482
6483 if (yes) {
6484 ret = str2prefix_rd(rd_str, &prd);
6485 if (!ret) {
6486 vty_out(vty, "%% Malformed rd\n");
6487 return CMD_WARNING_CONFIG_FAILED;
6488 }
6489 }
6490
6491 afi = vpn_policy_getafi(vty, bgp, false);
6492 if (afi == AFI_MAX)
6493 return CMD_WARNING_CONFIG_FAILED;
6494
6495 /*
6496 * pre-change: un-export vpn routes (vpn->vrf routes unaffected)
6497 */
6498 vpn_leak_prechange(BGP_VPN_POLICY_DIR_TOVPN, afi,
6499 bgp_get_default(), bgp);
6500
6501 if (yes) {
6502 bgp->vpn_policy[afi].tovpn_rd = prd;
6503 SET_FLAG(bgp->vpn_policy[afi].flags,
6504 BGP_VPN_POLICY_TOVPN_RD_SET);
6505 } else {
6506 UNSET_FLAG(bgp->vpn_policy[afi].flags,
6507 BGP_VPN_POLICY_TOVPN_RD_SET);
6508 }
6509
6510 /* post-change: re-export vpn routes */
6511 vpn_leak_postchange(BGP_VPN_POLICY_DIR_TOVPN, afi,
6512 bgp_get_default(), bgp);
6513
6514 return CMD_SUCCESS;
6515 }
6516
6517 ALIAS (af_rd_vpn_export,
6518 af_no_rd_vpn_export_cmd,
6519 "no rd vpn export",
6520 NO_STR
6521 "Specify route distinguisher\n"
6522 "Between current address-family and vpn\n"
6523 "For routes leaked from current address-family to vpn\n")
6524
6525 DEFPY (af_label_vpn_export,
6526 af_label_vpn_export_cmd,
6527 "[no] label vpn export <(0-1048575)$label_val|auto$label_auto>",
6528 NO_STR
6529 "label value for VRF\n"
6530 "Between current address-family and vpn\n"
6531 "For routes leaked from current address-family to vpn\n"
6532 "Label Value <0-1048575>\n"
6533 "Automatically assign a label\n")
6534 {
6535 VTY_DECLVAR_CONTEXT(bgp, bgp);
6536 mpls_label_t label = MPLS_LABEL_NONE;
6537 afi_t afi;
6538 int idx = 0;
6539 int yes = 1;
6540
6541 if (argv_find(argv, argc, "no", &idx))
6542 yes = 0;
6543
6544 /* If "no ...", squash trailing parameter */
6545 if (!yes)
6546 label_auto = NULL;
6547
6548 if (yes) {
6549 if (!label_auto)
6550 label = label_val; /* parser should force unsigned */
6551 }
6552
6553 afi = vpn_policy_getafi(vty, bgp, false);
6554 if (afi == AFI_MAX)
6555 return CMD_WARNING_CONFIG_FAILED;
6556
6557
6558 if (label_auto && CHECK_FLAG(bgp->vpn_policy[afi].flags,
6559 BGP_VPN_POLICY_TOVPN_LABEL_AUTO))
6560 /* no change */
6561 return CMD_SUCCESS;
6562
6563 /*
6564 * pre-change: un-export vpn routes (vpn->vrf routes unaffected)
6565 */
6566 vpn_leak_prechange(BGP_VPN_POLICY_DIR_TOVPN, afi,
6567 bgp_get_default(), bgp);
6568
6569 if (!label_auto && CHECK_FLAG(bgp->vpn_policy[afi].flags,
6570 BGP_VPN_POLICY_TOVPN_LABEL_AUTO)) {
6571
6572 if (bgp->vpn_policy[afi].tovpn_label != MPLS_LABEL_NONE) {
6573
6574 /*
6575 * label has previously been automatically
6576 * assigned by labelpool: release it
6577 *
6578 * NB if tovpn_label == MPLS_LABEL_NONE it
6579 * means the automatic assignment is in flight
6580 * and therefore the labelpool callback must
6581 * detect that the auto label is not needed.
6582 */
6583
6584 bgp_lp_release(LP_TYPE_VRF,
6585 &bgp->vpn_policy[afi],
6586 bgp->vpn_policy[afi].tovpn_label);
6587 }
6588 UNSET_FLAG(bgp->vpn_policy[afi].flags,
6589 BGP_VPN_POLICY_TOVPN_LABEL_AUTO);
6590 }
6591
6592 bgp->vpn_policy[afi].tovpn_label = label;
6593 if (label_auto) {
6594 SET_FLAG(bgp->vpn_policy[afi].flags,
6595 BGP_VPN_POLICY_TOVPN_LABEL_AUTO);
6596 bgp_lp_get(LP_TYPE_VRF, &bgp->vpn_policy[afi],
6597 vpn_leak_label_callback);
6598 }
6599
6600 /* post-change: re-export vpn routes */
6601 vpn_leak_postchange(BGP_VPN_POLICY_DIR_TOVPN, afi,
6602 bgp_get_default(), bgp);
6603
6604 return CMD_SUCCESS;
6605 }
6606
6607 ALIAS (af_label_vpn_export,
6608 af_no_label_vpn_export_cmd,
6609 "no label vpn export",
6610 NO_STR
6611 "label value for VRF\n"
6612 "Between current address-family and vpn\n"
6613 "For routes leaked from current address-family to vpn\n")
6614
6615 DEFPY (af_nexthop_vpn_export,
6616 af_nexthop_vpn_export_cmd,
6617 "[no] nexthop vpn export <A.B.C.D|X:X::X:X>$nexthop_str",
6618 NO_STR
6619 "Specify next hop to use for VRF advertised prefixes\n"
6620 "Between current address-family and vpn\n"
6621 "For routes leaked from current address-family to vpn\n"
6622 "IPv4 prefix\n"
6623 "IPv6 prefix\n")
6624 {
6625 VTY_DECLVAR_CONTEXT(bgp, bgp);
6626 afi_t afi;
6627 struct prefix p;
6628 int idx = 0;
6629 int yes = 1;
6630
6631 if (argv_find(argv, argc, "no", &idx))
6632 yes = 0;
6633
6634 if (yes) {
6635 if (!sockunion2hostprefix(nexthop_str, &p))
6636 return CMD_WARNING_CONFIG_FAILED;
6637 }
6638
6639 afi = vpn_policy_getafi(vty, bgp, false);
6640 if (afi == AFI_MAX)
6641 return CMD_WARNING_CONFIG_FAILED;
6642
6643 /*
6644 * pre-change: un-export vpn routes (vpn->vrf routes unaffected)
6645 */
6646 vpn_leak_prechange(BGP_VPN_POLICY_DIR_TOVPN, afi,
6647 bgp_get_default(), bgp);
6648
6649 if (yes) {
6650 bgp->vpn_policy[afi].tovpn_nexthop = p;
6651 SET_FLAG(bgp->vpn_policy[afi].flags,
6652 BGP_VPN_POLICY_TOVPN_NEXTHOP_SET);
6653 } else {
6654 UNSET_FLAG(bgp->vpn_policy[afi].flags,
6655 BGP_VPN_POLICY_TOVPN_NEXTHOP_SET);
6656 }
6657
6658 /* post-change: re-export vpn routes */
6659 vpn_leak_postchange(BGP_VPN_POLICY_DIR_TOVPN, afi,
6660 bgp_get_default(), bgp);
6661
6662 return CMD_SUCCESS;
6663 }
6664
6665 ALIAS (af_nexthop_vpn_export,
6666 af_no_nexthop_vpn_export_cmd,
6667 "no nexthop vpn export",
6668 NO_STR
6669 "Specify next hop to use for VRF advertised prefixes\n"
6670 "Between current address-family and vpn\n"
6671 "For routes leaked from current address-family to vpn\n")
6672
6673 static int vpn_policy_getdirs(struct vty *vty, const char *dstr, int *dodir)
6674 {
6675 if (!strcmp(dstr, "import")) {
6676 dodir[BGP_VPN_POLICY_DIR_FROMVPN] = 1;
6677 } else if (!strcmp(dstr, "export")) {
6678 dodir[BGP_VPN_POLICY_DIR_TOVPN] = 1;
6679 } else if (!strcmp(dstr, "both")) {
6680 dodir[BGP_VPN_POLICY_DIR_FROMVPN] = 1;
6681 dodir[BGP_VPN_POLICY_DIR_TOVPN] = 1;
6682 } else {
6683 vty_out(vty, "%% direction parse error\n");
6684 return CMD_WARNING_CONFIG_FAILED;
6685 }
6686 return CMD_SUCCESS;
6687 }
6688
6689 DEFPY (af_rt_vpn_imexport,
6690 af_rt_vpn_imexport_cmd,
6691 "[no] <rt|route-target> vpn <import|export|both>$direction_str RTLIST...",
6692 NO_STR
6693 "Specify route target list\n"
6694 "Specify route target list\n"
6695 "Between current address-family and vpn\n"
6696 "For routes leaked from vpn to current address-family: match any\n"
6697 "For routes leaked from current address-family to vpn: set\n"
6698 "both import: match any and export: set\n"
6699 "Space separated route target list (A.B.C.D:MN|EF:OPQR|GHJK:MN)\n")
6700 {
6701 VTY_DECLVAR_CONTEXT(bgp, bgp);
6702 int ret;
6703 struct ecommunity *ecom = NULL;
6704 int dodir[BGP_VPN_POLICY_DIR_MAX] = {0};
6705 vpn_policy_direction_t dir;
6706 afi_t afi;
6707 int idx = 0;
6708 int yes = 1;
6709
6710 if (argv_find(argv, argc, "no", &idx))
6711 yes = 0;
6712
6713 afi = vpn_policy_getafi(vty, bgp, false);
6714 if (afi == AFI_MAX)
6715 return CMD_WARNING_CONFIG_FAILED;
6716
6717 ret = vpn_policy_getdirs(vty, direction_str, dodir);
6718 if (ret != CMD_SUCCESS)
6719 return ret;
6720
6721 if (yes) {
6722 if (!argv_find(argv, argc, "RTLIST", &idx)) {
6723 vty_out(vty, "%% Missing RTLIST\n");
6724 return CMD_WARNING_CONFIG_FAILED;
6725 }
6726 ret = set_ecom_list(vty, argc - idx, argv + idx, &ecom);
6727 if (ret != CMD_SUCCESS) {
6728 return ret;
6729 }
6730 }
6731
6732 for (dir = 0; dir < BGP_VPN_POLICY_DIR_MAX; ++dir) {
6733 if (!dodir[dir])
6734 continue;
6735
6736 vpn_leak_prechange(dir, afi, bgp_get_default(), bgp);
6737
6738 if (yes) {
6739 if (bgp->vpn_policy[afi].rtlist[dir])
6740 ecommunity_free(
6741 &bgp->vpn_policy[afi].rtlist[dir]);
6742 bgp->vpn_policy[afi].rtlist[dir] =
6743 ecommunity_dup(ecom);
6744 } else {
6745 if (bgp->vpn_policy[afi].rtlist[dir])
6746 ecommunity_free(
6747 &bgp->vpn_policy[afi].rtlist[dir]);
6748 bgp->vpn_policy[afi].rtlist[dir] = NULL;
6749 }
6750
6751 vpn_leak_postchange(dir, afi, bgp_get_default(), bgp);
6752 }
6753
6754 if (ecom)
6755 ecommunity_free(&ecom);
6756
6757 return CMD_SUCCESS;
6758 }
6759
6760 ALIAS (af_rt_vpn_imexport,
6761 af_no_rt_vpn_imexport_cmd,
6762 "no <rt|route-target> vpn <import|export|both>$direction_str",
6763 NO_STR
6764 "Specify route target list\n"
6765 "Specify route target list\n"
6766 "Between current address-family and vpn\n"
6767 "For routes leaked from vpn to current address-family\n"
6768 "For routes leaked from current address-family to vpn\n"
6769 "both import and export\n")
6770
6771 DEFPY (af_route_map_vpn_imexport,
6772 af_route_map_vpn_imexport_cmd,
6773 /* future: "route-map <vpn|evpn|vrf NAME> <import|export> RMAP" */
6774 "[no] route-map vpn <import|export>$direction_str RMAP$rmap_str",
6775 NO_STR
6776 "Specify route map\n"
6777 "Between current address-family and vpn\n"
6778 "For routes leaked from vpn to current address-family\n"
6779 "For routes leaked from current address-family to vpn\n"
6780 "name of route-map\n")
6781 {
6782 VTY_DECLVAR_CONTEXT(bgp, bgp);
6783 int ret;
6784 int dodir[BGP_VPN_POLICY_DIR_MAX] = {0};
6785 vpn_policy_direction_t dir;
6786 afi_t afi;
6787 int idx = 0;
6788 int yes = 1;
6789
6790 if (argv_find(argv, argc, "no", &idx))
6791 yes = 0;
6792
6793 afi = vpn_policy_getafi(vty, bgp, false);
6794 if (afi == AFI_MAX)
6795 return CMD_WARNING_CONFIG_FAILED;
6796
6797 ret = vpn_policy_getdirs(vty, direction_str, dodir);
6798 if (ret != CMD_SUCCESS)
6799 return ret;
6800
6801 for (dir = 0; dir < BGP_VPN_POLICY_DIR_MAX; ++dir) {
6802 if (!dodir[dir])
6803 continue;
6804
6805 vpn_leak_prechange(dir, afi, bgp_get_default(), bgp);
6806
6807 if (yes) {
6808 if (bgp->vpn_policy[afi].rmap_name[dir])
6809 XFREE(MTYPE_ROUTE_MAP_NAME,
6810 bgp->vpn_policy[afi].rmap_name[dir]);
6811 bgp->vpn_policy[afi].rmap_name[dir] = XSTRDUP(
6812 MTYPE_ROUTE_MAP_NAME, rmap_str);
6813 bgp->vpn_policy[afi].rmap[dir] =
6814 route_map_lookup_warn_noexist(vty, rmap_str);
6815 if (!bgp->vpn_policy[afi].rmap[dir])
6816 return CMD_SUCCESS;
6817 } else {
6818 if (bgp->vpn_policy[afi].rmap_name[dir])
6819 XFREE(MTYPE_ROUTE_MAP_NAME,
6820 bgp->vpn_policy[afi].rmap_name[dir]);
6821 bgp->vpn_policy[afi].rmap_name[dir] = NULL;
6822 bgp->vpn_policy[afi].rmap[dir] = NULL;
6823 }
6824
6825 vpn_leak_postchange(dir, afi, bgp_get_default(), bgp);
6826 }
6827
6828 return CMD_SUCCESS;
6829 }
6830
6831 ALIAS (af_route_map_vpn_imexport,
6832 af_no_route_map_vpn_imexport_cmd,
6833 "no route-map vpn <import|export>$direction_str",
6834 NO_STR
6835 "Specify route map\n"
6836 "Between current address-family and vpn\n"
6837 "For routes leaked from vpn to current address-family\n"
6838 "For routes leaked from current address-family to vpn\n")
6839
6840 DEFPY(af_import_vrf_route_map, af_import_vrf_route_map_cmd,
6841 "[no] import vrf route-map RMAP$rmap_str",
6842 NO_STR
6843 "Import routes from another VRF\n"
6844 "Vrf routes being filtered\n"
6845 "Specify route map\n"
6846 "name of route-map\n")
6847 {
6848 VTY_DECLVAR_CONTEXT(bgp, bgp);
6849 vpn_policy_direction_t dir = BGP_VPN_POLICY_DIR_FROMVPN;
6850 afi_t afi;
6851 int idx = 0;
6852 int yes = 1;
6853 struct bgp *bgp_default;
6854
6855 if (argv_find(argv, argc, "no", &idx))
6856 yes = 0;
6857
6858 afi = vpn_policy_getafi(vty, bgp, true);
6859 if (afi == AFI_MAX)
6860 return CMD_WARNING_CONFIG_FAILED;
6861
6862 bgp_default = bgp_get_default();
6863 if (!bgp_default) {
6864 int32_t ret;
6865 as_t as = bgp->as;
6866
6867 /* Auto-create assuming the same AS */
6868 ret = bgp_get(&bgp_default, &as, NULL,
6869 BGP_INSTANCE_TYPE_DEFAULT);
6870
6871 if (ret) {
6872 vty_out(vty,
6873 "VRF default is not configured as a bgp instance\n");
6874 return CMD_WARNING;
6875 }
6876 }
6877
6878 vpn_leak_prechange(dir, afi, bgp_get_default(), bgp);
6879
6880 if (yes) {
6881 if (bgp->vpn_policy[afi].rmap_name[dir])
6882 XFREE(MTYPE_ROUTE_MAP_NAME,
6883 bgp->vpn_policy[afi].rmap_name[dir]);
6884 bgp->vpn_policy[afi].rmap_name[dir] =
6885 XSTRDUP(MTYPE_ROUTE_MAP_NAME, rmap_str);
6886 bgp->vpn_policy[afi].rmap[dir] =
6887 route_map_lookup_warn_noexist(vty, rmap_str);
6888 if (!bgp->vpn_policy[afi].rmap[dir])
6889 return CMD_SUCCESS;
6890 } else {
6891 if (bgp->vpn_policy[afi].rmap_name[dir])
6892 XFREE(MTYPE_ROUTE_MAP_NAME,
6893 bgp->vpn_policy[afi].rmap_name[dir]);
6894 bgp->vpn_policy[afi].rmap_name[dir] = NULL;
6895 bgp->vpn_policy[afi].rmap[dir] = NULL;
6896 }
6897
6898 vpn_leak_postchange(dir, afi, bgp_get_default(), bgp);
6899
6900 return CMD_SUCCESS;
6901 }
6902
6903 ALIAS(af_import_vrf_route_map, af_no_import_vrf_route_map_cmd,
6904 "no import vrf route-map",
6905 NO_STR
6906 "Import routes from another VRF\n"
6907 "Vrf routes being filtered\n"
6908 "Specify route map\n")
6909
6910 DEFPY(bgp_imexport_vrf, bgp_imexport_vrf_cmd,
6911 "[no] import vrf VIEWVRFNAME$import_name",
6912 NO_STR
6913 "Import routes from another VRF\n"
6914 "VRF to import from\n"
6915 "The name of the VRF\n")
6916 {
6917 VTY_DECLVAR_CONTEXT(bgp, bgp);
6918 struct listnode *node;
6919 struct bgp *vrf_bgp, *bgp_default;
6920 int32_t ret = 0;
6921 as_t as = bgp->as;
6922 bool remove = false;
6923 int32_t idx = 0;
6924 char *vname;
6925 enum bgp_instance_type bgp_type = BGP_INSTANCE_TYPE_VRF;
6926 safi_t safi;
6927 afi_t afi;
6928
6929 if (import_name == NULL) {
6930 vty_out(vty, "%% Missing import name\n");
6931 return CMD_WARNING;
6932 }
6933
6934 if (argv_find(argv, argc, "no", &idx))
6935 remove = true;
6936
6937 afi = vpn_policy_getafi(vty, bgp, true);
6938 if (afi == AFI_MAX)
6939 return CMD_WARNING_CONFIG_FAILED;
6940
6941 safi = bgp_node_safi(vty);
6942
6943 if (((BGP_INSTANCE_TYPE_DEFAULT == bgp->inst_type)
6944 && (strcmp(import_name, VRF_DEFAULT_NAME) == 0))
6945 || (bgp->name && (strcmp(import_name, bgp->name) == 0))) {
6946 vty_out(vty, "%% Cannot %s vrf %s into itself\n",
6947 remove ? "unimport" : "import", import_name);
6948 return CMD_WARNING;
6949 }
6950
6951 bgp_default = bgp_get_default();
6952 if (!bgp_default) {
6953 /* Auto-create assuming the same AS */
6954 ret = bgp_get(&bgp_default, &as, NULL,
6955 BGP_INSTANCE_TYPE_DEFAULT);
6956
6957 if (ret) {
6958 vty_out(vty,
6959 "VRF default is not configured as a bgp instance\n");
6960 return CMD_WARNING;
6961 }
6962 }
6963
6964 vrf_bgp = bgp_lookup_by_name(import_name);
6965 if (!vrf_bgp) {
6966 if (strcmp(import_name, VRF_DEFAULT_NAME) == 0)
6967 vrf_bgp = bgp_default;
6968 else
6969 /* Auto-create assuming the same AS */
6970 ret = bgp_get(&vrf_bgp, &as, import_name, bgp_type);
6971
6972 if (ret) {
6973 vty_out(vty,
6974 "VRF %s is not configured as a bgp instance\n",
6975 import_name);
6976 return CMD_WARNING;
6977 }
6978 }
6979
6980 if (remove) {
6981 vrf_unimport_from_vrf(bgp, vrf_bgp, afi, safi);
6982 } else {
6983 /* Already importing from "import_vrf"? */
6984 for (ALL_LIST_ELEMENTS_RO(bgp->vpn_policy[afi].import_vrf, node,
6985 vname)) {
6986 if (strcmp(vname, import_name) == 0)
6987 return CMD_WARNING;
6988 }
6989
6990 vrf_import_from_vrf(bgp, vrf_bgp, afi, safi);
6991 }
6992
6993 return CMD_SUCCESS;
6994 }
6995
6996 /* This command is valid only in a bgp vrf instance or the default instance */
6997 DEFPY (bgp_imexport_vpn,
6998 bgp_imexport_vpn_cmd,
6999 "[no] <import|export>$direction_str vpn",
7000 NO_STR
7001 "Import routes to this address-family\n"
7002 "Export routes from this address-family\n"
7003 "to/from default instance VPN RIB\n")
7004 {
7005 VTY_DECLVAR_CONTEXT(bgp, bgp);
7006 int previous_state;
7007 afi_t afi;
7008 safi_t safi;
7009 int idx = 0;
7010 int yes = 1;
7011 int flag;
7012 vpn_policy_direction_t dir;
7013
7014 if (argv_find(argv, argc, "no", &idx))
7015 yes = 0;
7016
7017 if (BGP_INSTANCE_TYPE_VRF != bgp->inst_type &&
7018 BGP_INSTANCE_TYPE_DEFAULT != bgp->inst_type) {
7019
7020 vty_out(vty, "%% import|export vpn valid only for bgp vrf or default instance\n");
7021 return CMD_WARNING_CONFIG_FAILED;
7022 }
7023
7024 afi = bgp_node_afi(vty);
7025 safi = bgp_node_safi(vty);
7026 if ((SAFI_UNICAST != safi) || ((AFI_IP != afi) && (AFI_IP6 != afi))) {
7027 vty_out(vty, "%% import|export vpn valid only for unicast ipv4|ipv6\n");
7028 return CMD_WARNING_CONFIG_FAILED;
7029 }
7030
7031 if (!strcmp(direction_str, "import")) {
7032 flag = BGP_CONFIG_MPLSVPN_TO_VRF_IMPORT;
7033 dir = BGP_VPN_POLICY_DIR_FROMVPN;
7034 } else if (!strcmp(direction_str, "export")) {
7035 flag = BGP_CONFIG_VRF_TO_MPLSVPN_EXPORT;
7036 dir = BGP_VPN_POLICY_DIR_TOVPN;
7037 } else {
7038 vty_out(vty, "%% unknown direction %s\n", direction_str);
7039 return CMD_WARNING_CONFIG_FAILED;
7040 }
7041
7042 previous_state = CHECK_FLAG(bgp->af_flags[afi][safi], flag);
7043
7044 if (yes) {
7045 SET_FLAG(bgp->af_flags[afi][safi], flag);
7046 if (!previous_state) {
7047 /* trigger export current vrf */
7048 vpn_leak_postchange(dir, afi, bgp_get_default(), bgp);
7049 }
7050 } else {
7051 if (previous_state) {
7052 /* trigger un-export current vrf */
7053 vpn_leak_prechange(dir, afi, bgp_get_default(), bgp);
7054 }
7055 UNSET_FLAG(bgp->af_flags[afi][safi], flag);
7056 }
7057
7058 return CMD_SUCCESS;
7059 }
7060
7061 DEFPY (af_routetarget_import,
7062 af_routetarget_import_cmd,
7063 "[no] <rt|route-target> redirect import RTLIST...",
7064 NO_STR
7065 "Specify route target list\n"
7066 "Specify route target list\n"
7067 "Flow-spec redirect type route target\n"
7068 "Import routes to this address-family\n"
7069 "Space separated route target list (A.B.C.D:MN|EF:OPQR|GHJK:MN)\n")
7070 {
7071 VTY_DECLVAR_CONTEXT(bgp, bgp);
7072 int ret;
7073 struct ecommunity *ecom = NULL;
7074 afi_t afi;
7075 int idx = 0;
7076 int yes = 1;
7077
7078 if (argv_find(argv, argc, "no", &idx))
7079 yes = 0;
7080
7081 afi = vpn_policy_getafi(vty, bgp, false);
7082 if (afi == AFI_MAX)
7083 return CMD_WARNING_CONFIG_FAILED;
7084
7085 if (yes) {
7086 if (!argv_find(argv, argc, "RTLIST", &idx)) {
7087 vty_out(vty, "%% Missing RTLIST\n");
7088 return CMD_WARNING_CONFIG_FAILED;
7089 }
7090 ret = set_ecom_list(vty, argc - idx, argv + idx, &ecom);
7091 if (ret != CMD_SUCCESS)
7092 return ret;
7093 }
7094
7095 if (yes) {
7096 if (bgp->vpn_policy[afi].import_redirect_rtlist)
7097 ecommunity_free(&bgp->vpn_policy[afi]
7098 .import_redirect_rtlist);
7099 bgp->vpn_policy[afi].import_redirect_rtlist =
7100 ecommunity_dup(ecom);
7101 } else {
7102 if (bgp->vpn_policy[afi].import_redirect_rtlist)
7103 ecommunity_free(&bgp->vpn_policy[afi]
7104 .import_redirect_rtlist);
7105 bgp->vpn_policy[afi].import_redirect_rtlist = NULL;
7106 }
7107
7108 if (ecom)
7109 ecommunity_free(&ecom);
7110
7111 return CMD_SUCCESS;
7112 }
7113
7114 DEFUN_NOSH (address_family_ipv4_safi,
7115 address_family_ipv4_safi_cmd,
7116 "address-family ipv4 [<unicast|multicast|vpn|labeled-unicast|flowspec>]",
7117 "Enter Address Family command mode\n"
7118 "Address Family\n"
7119 BGP_SAFI_WITH_LABEL_HELP_STR)
7120 {
7121
7122 if (argc == 3) {
7123 VTY_DECLVAR_CONTEXT(bgp, bgp);
7124 safi_t safi = bgp_vty_safi_from_str(argv[2]->text);
7125 if (bgp->inst_type != BGP_INSTANCE_TYPE_DEFAULT
7126 && safi != SAFI_UNICAST && safi != SAFI_MULTICAST
7127 && safi != SAFI_EVPN) {
7128 vty_out(vty,
7129 "Only Unicast/Multicast/EVPN SAFIs supported in non-core instances.\n");
7130 return CMD_WARNING_CONFIG_FAILED;
7131 }
7132 vty->node = bgp_node_type(AFI_IP, safi);
7133 } else
7134 vty->node = BGP_IPV4_NODE;
7135
7136 return CMD_SUCCESS;
7137 }
7138
7139 DEFUN_NOSH (address_family_ipv6_safi,
7140 address_family_ipv6_safi_cmd,
7141 "address-family ipv6 [<unicast|multicast|vpn|labeled-unicast|flowspec>]",
7142 "Enter Address Family command mode\n"
7143 "Address Family\n"
7144 BGP_SAFI_WITH_LABEL_HELP_STR)
7145 {
7146 if (argc == 3) {
7147 VTY_DECLVAR_CONTEXT(bgp, bgp);
7148 safi_t safi = bgp_vty_safi_from_str(argv[2]->text);
7149 if (bgp->inst_type != BGP_INSTANCE_TYPE_DEFAULT
7150 && safi != SAFI_UNICAST && safi != SAFI_MULTICAST
7151 && safi != SAFI_EVPN) {
7152 vty_out(vty,
7153 "Only Unicast/Multicast/EVPN SAFIs supported in non-core instances.\n");
7154 return CMD_WARNING_CONFIG_FAILED;
7155 }
7156 vty->node = bgp_node_type(AFI_IP6, safi);
7157 } else
7158 vty->node = BGP_IPV6_NODE;
7159
7160 return CMD_SUCCESS;
7161 }
7162
7163 #ifdef KEEP_OLD_VPN_COMMANDS
7164 DEFUN_NOSH (address_family_vpnv4,
7165 address_family_vpnv4_cmd,
7166 "address-family vpnv4 [unicast]",
7167 "Enter Address Family command mode\n"
7168 "Address Family\n"
7169 "Address Family modifier\n")
7170 {
7171 vty->node = BGP_VPNV4_NODE;
7172 return CMD_SUCCESS;
7173 }
7174
7175 DEFUN_NOSH (address_family_vpnv6,
7176 address_family_vpnv6_cmd,
7177 "address-family vpnv6 [unicast]",
7178 "Enter Address Family command mode\n"
7179 "Address Family\n"
7180 "Address Family modifier\n")
7181 {
7182 vty->node = BGP_VPNV6_NODE;
7183 return CMD_SUCCESS;
7184 }
7185 #endif /* KEEP_OLD_VPN_COMMANDS */
7186
7187 DEFUN_NOSH (address_family_evpn,
7188 address_family_evpn_cmd,
7189 "address-family l2vpn evpn",
7190 "Enter Address Family command mode\n"
7191 "Address Family\n"
7192 "Address Family modifier\n")
7193 {
7194 VTY_DECLVAR_CONTEXT(bgp, bgp);
7195 vty->node = BGP_EVPN_NODE;
7196 return CMD_SUCCESS;
7197 }
7198
7199 DEFUN_NOSH (exit_address_family,
7200 exit_address_family_cmd,
7201 "exit-address-family",
7202 "Exit from Address Family configuration mode\n")
7203 {
7204 if (vty->node == BGP_IPV4_NODE || vty->node == BGP_IPV4M_NODE
7205 || vty->node == BGP_IPV4L_NODE || vty->node == BGP_VPNV4_NODE
7206 || vty->node == BGP_IPV6_NODE || vty->node == BGP_IPV6M_NODE
7207 || vty->node == BGP_IPV6L_NODE || vty->node == BGP_VPNV6_NODE
7208 || vty->node == BGP_EVPN_NODE
7209 || vty->node == BGP_FLOWSPECV4_NODE
7210 || vty->node == BGP_FLOWSPECV6_NODE)
7211 vty->node = BGP_NODE;
7212 return CMD_SUCCESS;
7213 }
7214
7215 /* Recalculate bestpath and re-advertise a prefix */
7216 static int bgp_clear_prefix(struct vty *vty, const char *view_name,
7217 const char *ip_str, afi_t afi, safi_t safi,
7218 struct prefix_rd *prd)
7219 {
7220 int ret;
7221 struct prefix match;
7222 struct bgp_node *rn;
7223 struct bgp_node *rm;
7224 struct bgp *bgp;
7225 struct bgp_table *table;
7226 struct bgp_table *rib;
7227
7228 /* BGP structure lookup. */
7229 if (view_name) {
7230 bgp = bgp_lookup_by_name(view_name);
7231 if (bgp == NULL) {
7232 vty_out(vty, "%% Can't find BGP instance %s\n",
7233 view_name);
7234 return CMD_WARNING;
7235 }
7236 } else {
7237 bgp = bgp_get_default();
7238 if (bgp == NULL) {
7239 vty_out(vty, "%% No BGP process is configured\n");
7240 return CMD_WARNING;
7241 }
7242 }
7243
7244 /* Check IP address argument. */
7245 ret = str2prefix(ip_str, &match);
7246 if (!ret) {
7247 vty_out(vty, "%% address is malformed\n");
7248 return CMD_WARNING;
7249 }
7250
7251 match.family = afi2family(afi);
7252 rib = bgp->rib[afi][safi];
7253
7254 if (safi == SAFI_MPLS_VPN) {
7255 for (rn = bgp_table_top(rib); rn; rn = bgp_route_next(rn)) {
7256 if (prd && memcmp(rn->p.u.val, prd->val, 8) != 0)
7257 continue;
7258
7259 table = bgp_node_get_bgp_table_info(rn);
7260 if (table != NULL) {
7261
7262 if ((rm = bgp_node_match(table, &match))
7263 != NULL) {
7264 if (rm->p.prefixlen
7265 == match.prefixlen) {
7266 SET_FLAG(rm->flags,
7267 BGP_NODE_USER_CLEAR);
7268 bgp_process(bgp, rm, afi, safi);
7269 }
7270 bgp_unlock_node(rm);
7271 }
7272 }
7273 }
7274 } else {
7275 if ((rn = bgp_node_match(rib, &match)) != NULL) {
7276 if (rn->p.prefixlen == match.prefixlen) {
7277 SET_FLAG(rn->flags, BGP_NODE_USER_CLEAR);
7278 bgp_process(bgp, rn, afi, safi);
7279 }
7280 bgp_unlock_node(rn);
7281 }
7282 }
7283
7284 return CMD_SUCCESS;
7285 }
7286
7287 /* one clear bgp command to rule them all */
7288 DEFUN (clear_ip_bgp_all,
7289 clear_ip_bgp_all_cmd,
7290 "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 PGNAME> [<soft [<in|out>]|in [prefix-filter]|out>]",
7291 CLEAR_STR
7292 IP_STR
7293 BGP_STR
7294 BGP_INSTANCE_HELP_STR
7295 BGP_AFI_HELP_STR
7296 "Address Family\n"
7297 BGP_SAFI_WITH_LABEL_HELP_STR
7298 "Address Family modifier\n"
7299 "Clear all peers\n"
7300 "BGP neighbor address to clear\n"
7301 "BGP IPv6 neighbor to clear\n"
7302 "BGP neighbor on interface to clear\n"
7303 "Clear peers with the AS number\n"
7304 "Clear all external peers\n"
7305 "Clear all members of peer-group\n"
7306 "BGP peer-group name\n"
7307 BGP_SOFT_STR
7308 BGP_SOFT_IN_STR
7309 BGP_SOFT_OUT_STR
7310 BGP_SOFT_IN_STR
7311 "Push out prefix-list ORF and do inbound soft reconfig\n"
7312 BGP_SOFT_OUT_STR)
7313 {
7314 char *vrf = NULL;
7315
7316 afi_t afi = AFI_IP6;
7317 safi_t safi = SAFI_UNICAST;
7318 enum clear_sort clr_sort = clear_peer;
7319 enum bgp_clear_type clr_type;
7320 char *clr_arg = NULL;
7321
7322 int idx = 0;
7323
7324 /* clear [ip] bgp */
7325 if (argv_find(argv, argc, "ip", &idx))
7326 afi = AFI_IP;
7327
7328 /* [<vrf> VIEWVRFNAME] */
7329 if (argv_find(argv, argc, "vrf", &idx)) {
7330 vrf = argv[idx + 1]->arg;
7331 idx += 2;
7332 if (vrf && strmatch(vrf, VRF_DEFAULT_NAME))
7333 vrf = NULL;
7334 } else if (argv_find(argv, argc, "view", &idx)) {
7335 /* [<view> VIEWVRFNAME] */
7336 vrf = argv[idx + 1]->arg;
7337 idx += 2;
7338 }
7339 /* ["BGP_AFI_CMD_STR" ["BGP_SAFI_CMD_STR"]] */
7340 if (argv_find_and_parse_afi(argv, argc, &idx, &afi))
7341 argv_find_and_parse_safi(argv, argc, &idx, &safi);
7342
7343 /* <*|A.B.C.D|X:X::X:X|WORD|(1-4294967295)|external|peer-group PGNAME> */
7344 if (argv_find(argv, argc, "*", &idx)) {
7345 clr_sort = clear_all;
7346 } else if (argv_find(argv, argc, "A.B.C.D", &idx)) {
7347 clr_sort = clear_peer;
7348 clr_arg = argv[idx]->arg;
7349 } else if (argv_find(argv, argc, "X:X::X:X", &idx)) {
7350 clr_sort = clear_peer;
7351 clr_arg = argv[idx]->arg;
7352 } else if (argv_find(argv, argc, "peer-group", &idx)) {
7353 clr_sort = clear_group;
7354 idx++;
7355 clr_arg = argv[idx]->arg;
7356 } else if (argv_find(argv, argc, "PGNAME", &idx)) {
7357 clr_sort = clear_peer;
7358 clr_arg = argv[idx]->arg;
7359 } else if (argv_find(argv, argc, "(1-4294967295)", &idx)) {
7360 clr_sort = clear_as;
7361 clr_arg = argv[idx]->arg;
7362 } else if (argv_find(argv, argc, "external", &idx)) {
7363 clr_sort = clear_external;
7364 }
7365
7366 /* [<soft [<in|out>]|in [prefix-filter]|out>] */
7367 if (argv_find(argv, argc, "soft", &idx)) {
7368 if (argv_find(argv, argc, "in", &idx)
7369 || argv_find(argv, argc, "out", &idx))
7370 clr_type = strmatch(argv[idx]->text, "in")
7371 ? BGP_CLEAR_SOFT_IN
7372 : BGP_CLEAR_SOFT_OUT;
7373 else
7374 clr_type = BGP_CLEAR_SOFT_BOTH;
7375 } else if (argv_find(argv, argc, "in", &idx)) {
7376 clr_type = argv_find(argv, argc, "prefix-filter", &idx)
7377 ? BGP_CLEAR_SOFT_IN_ORF_PREFIX
7378 : BGP_CLEAR_SOFT_IN;
7379 } else if (argv_find(argv, argc, "out", &idx)) {
7380 clr_type = BGP_CLEAR_SOFT_OUT;
7381 } else
7382 clr_type = BGP_CLEAR_SOFT_NONE;
7383
7384 return bgp_clear_vty(vty, vrf, afi, safi, clr_sort, clr_type, clr_arg);
7385 }
7386
7387 DEFUN (clear_ip_bgp_prefix,
7388 clear_ip_bgp_prefix_cmd,
7389 "clear [ip] bgp [<view|vrf> VIEWVRFNAME] prefix A.B.C.D/M",
7390 CLEAR_STR
7391 IP_STR
7392 BGP_STR
7393 BGP_INSTANCE_HELP_STR
7394 "Clear bestpath and re-advertise\n"
7395 "IPv4 prefix\n")
7396 {
7397 char *vrf = NULL;
7398 char *prefix = NULL;
7399
7400 int idx = 0;
7401
7402 /* [<view|vrf> VIEWVRFNAME] */
7403 if (argv_find(argv, argc, "vrf", &idx)) {
7404 vrf = argv[idx + 1]->arg;
7405 idx += 2;
7406 if (vrf && strmatch(vrf, VRF_DEFAULT_NAME))
7407 vrf = NULL;
7408 } else if (argv_find(argv, argc, "view", &idx)) {
7409 /* [<view> VIEWVRFNAME] */
7410 vrf = argv[idx + 1]->arg;
7411 idx += 2;
7412 }
7413
7414 prefix = argv[argc - 1]->arg;
7415
7416 return bgp_clear_prefix(vty, vrf, prefix, AFI_IP, SAFI_UNICAST, NULL);
7417 }
7418
7419 DEFUN (clear_bgp_ipv6_safi_prefix,
7420 clear_bgp_ipv6_safi_prefix_cmd,
7421 "clear [ip] bgp ipv6 "BGP_SAFI_CMD_STR" prefix X:X::X:X/M",
7422 CLEAR_STR
7423 IP_STR
7424 BGP_STR
7425 "Address Family\n"
7426 BGP_SAFI_HELP_STR
7427 "Clear bestpath and re-advertise\n"
7428 "IPv6 prefix\n")
7429 {
7430 int idx_safi = 0;
7431 int idx_ipv6_prefix = 0;
7432 safi_t safi = SAFI_UNICAST;
7433 char *prefix = argv_find(argv, argc, "X:X::X:X/M", &idx_ipv6_prefix) ?
7434 argv[idx_ipv6_prefix]->arg : NULL;
7435
7436 argv_find_and_parse_safi(argv, argc, &idx_safi, &safi);
7437 return bgp_clear_prefix(
7438 vty, NULL, prefix, AFI_IP6,
7439 safi, NULL);
7440 }
7441
7442 DEFUN (clear_bgp_instance_ipv6_safi_prefix,
7443 clear_bgp_instance_ipv6_safi_prefix_cmd,
7444 "clear [ip] bgp <view|vrf> VIEWVRFNAME ipv6 "BGP_SAFI_CMD_STR" prefix X:X::X:X/M",
7445 CLEAR_STR
7446 IP_STR
7447 BGP_STR
7448 BGP_INSTANCE_HELP_STR
7449 "Address Family\n"
7450 BGP_SAFI_HELP_STR
7451 "Clear bestpath and re-advertise\n"
7452 "IPv6 prefix\n")
7453 {
7454 int idx_safi = 0;
7455 int idx_vrfview = 0;
7456 int idx_ipv6_prefix = 0;
7457 safi_t safi = SAFI_UNICAST;
7458 char *prefix = argv_find(argv, argc, "X:X::X:X/M", &idx_ipv6_prefix) ?
7459 argv[idx_ipv6_prefix]->arg : NULL;
7460 char *vrfview = NULL;
7461
7462 /* [<view|vrf> VIEWVRFNAME] */
7463 if (argv_find(argv, argc, "vrf", &idx_vrfview)) {
7464 vrfview = argv[idx_vrfview + 1]->arg;
7465 if (vrfview && strmatch(vrfview, VRF_DEFAULT_NAME))
7466 vrfview = NULL;
7467 } else if (argv_find(argv, argc, "view", &idx_vrfview)) {
7468 /* [<view> VIEWVRFNAME] */
7469 vrfview = argv[idx_vrfview + 1]->arg;
7470 }
7471 argv_find_and_parse_safi(argv, argc, &idx_safi, &safi);
7472
7473 return bgp_clear_prefix(
7474 vty, vrfview, prefix,
7475 AFI_IP6, safi, NULL);
7476 }
7477
7478 DEFUN (show_bgp_views,
7479 show_bgp_views_cmd,
7480 "show [ip] bgp views",
7481 SHOW_STR
7482 IP_STR
7483 BGP_STR
7484 "Show the defined BGP views\n")
7485 {
7486 struct list *inst = bm->bgp;
7487 struct listnode *node;
7488 struct bgp *bgp;
7489
7490 if (!bgp_option_check(BGP_OPT_MULTIPLE_INSTANCE)) {
7491 vty_out(vty, "BGP Multiple Instance is not enabled\n");
7492 return CMD_WARNING;
7493 }
7494
7495 vty_out(vty, "Defined BGP views:\n");
7496 for (ALL_LIST_ELEMENTS_RO(inst, node, bgp)) {
7497 /* Skip VRFs. */
7498 if (bgp->inst_type == BGP_INSTANCE_TYPE_VRF)
7499 continue;
7500 vty_out(vty, "\t%s (AS%u)\n", bgp->name ? bgp->name : "(null)",
7501 bgp->as);
7502 }
7503
7504 return CMD_SUCCESS;
7505 }
7506
7507 DEFUN (show_bgp_vrfs,
7508 show_bgp_vrfs_cmd,
7509 "show [ip] bgp vrfs [json]",
7510 SHOW_STR
7511 IP_STR
7512 BGP_STR
7513 "Show BGP VRFs\n"
7514 JSON_STR)
7515 {
7516 char buf[ETHER_ADDR_STRLEN];
7517 struct list *inst = bm->bgp;
7518 struct listnode *node;
7519 struct bgp *bgp;
7520 bool uj = use_json(argc, argv);
7521 json_object *json = NULL;
7522 json_object *json_vrfs = NULL;
7523 int count = 0;
7524
7525 if (!bgp_option_check(BGP_OPT_MULTIPLE_INSTANCE)) {
7526 vty_out(vty, "BGP Multiple Instance is not enabled\n");
7527 return CMD_WARNING;
7528 }
7529
7530 if (uj) {
7531 json = json_object_new_object();
7532 json_vrfs = json_object_new_object();
7533 }
7534
7535 for (ALL_LIST_ELEMENTS_RO(inst, node, bgp)) {
7536 const char *name, *type;
7537 struct peer *peer;
7538 struct listnode *node2, *nnode2;
7539 int peers_cfg, peers_estb;
7540 json_object *json_vrf = NULL;
7541
7542 /* Skip Views. */
7543 if (bgp->inst_type == BGP_INSTANCE_TYPE_VIEW)
7544 continue;
7545
7546 count++;
7547 if (!uj && count == 1)
7548 vty_out(vty,
7549 "%4s %-5s %-16s %9s %10s %-37s %-10s %-15s\n",
7550 "Type", "Id", "routerId", "#PeersVfg",
7551 "#PeersEstb", "Name", "L3-VNI", "Rmac");
7552
7553 peers_cfg = peers_estb = 0;
7554 if (uj)
7555 json_vrf = json_object_new_object();
7556
7557
7558 for (ALL_LIST_ELEMENTS(bgp->peer, node2, nnode2, peer)) {
7559 if (!CHECK_FLAG(peer->flags, PEER_FLAG_CONFIG_NODE))
7560 continue;
7561 peers_cfg++;
7562 if (peer->status == Established)
7563 peers_estb++;
7564 }
7565
7566 if (bgp->inst_type == BGP_INSTANCE_TYPE_DEFAULT) {
7567 name = VRF_DEFAULT_NAME;
7568 type = "DFLT";
7569 } else {
7570 name = bgp->name;
7571 type = "VRF";
7572 }
7573
7574
7575 if (uj) {
7576 int64_t vrf_id_ui = (bgp->vrf_id == VRF_UNKNOWN)
7577 ? -1
7578 : (int64_t)bgp->vrf_id;
7579 json_object_string_add(json_vrf, "type", type);
7580 json_object_int_add(json_vrf, "vrfId", vrf_id_ui);
7581 json_object_string_add(json_vrf, "routerId",
7582 inet_ntoa(bgp->router_id));
7583 json_object_int_add(json_vrf, "numConfiguredPeers",
7584 peers_cfg);
7585 json_object_int_add(json_vrf, "numEstablishedPeers",
7586 peers_estb);
7587
7588 json_object_int_add(json_vrf, "l3vni", bgp->l3vni);
7589 json_object_string_add(
7590 json_vrf, "rmac",
7591 prefix_mac2str(&bgp->rmac, buf, sizeof(buf)));
7592 json_object_object_add(json_vrfs, name, json_vrf);
7593 } else
7594 vty_out(vty,
7595 "%4s %-5d %-16s %9u %10u %-37s %-10u %-15s\n",
7596 type,
7597 bgp->vrf_id == VRF_UNKNOWN ? -1
7598 : (int)bgp->vrf_id,
7599 inet_ntoa(bgp->router_id), peers_cfg,
7600 peers_estb, name, bgp->l3vni,
7601 prefix_mac2str(&bgp->rmac, buf, sizeof(buf)));
7602 }
7603
7604 if (uj) {
7605 json_object_object_add(json, "vrfs", json_vrfs);
7606
7607 json_object_int_add(json, "totalVrfs", count);
7608
7609 vty_out(vty, "%s\n", json_object_to_json_string_ext(
7610 json, JSON_C_TO_STRING_PRETTY));
7611 json_object_free(json);
7612 } else {
7613 if (count)
7614 vty_out(vty,
7615 "\nTotal number of VRFs (including default): %d\n",
7616 count);
7617 }
7618
7619 return CMD_SUCCESS;
7620 }
7621
7622 DEFUN (show_bgp_mac_hash,
7623 show_bgp_mac_hash_cmd,
7624 "show bgp mac hash",
7625 SHOW_STR
7626 BGP_STR
7627 "Mac Address\n"
7628 "Mac Address database\n")
7629 {
7630 bgp_mac_dump_table(vty);
7631
7632 return CMD_SUCCESS;
7633 }
7634
7635 static void show_tip_entry(struct hash_bucket *bucket, void *args)
7636 {
7637 struct vty *vty = (struct vty *)args;
7638 struct tip_addr *tip = (struct tip_addr *)bucket->data;
7639
7640 vty_out(vty, "addr: %s, count: %d\n", inet_ntoa(tip->addr),
7641 tip->refcnt);
7642 }
7643
7644 static void bgp_show_martian_nexthops(struct vty *vty, struct bgp *bgp)
7645 {
7646 vty_out(vty, "self nexthop database:\n");
7647 bgp_nexthop_show_address_hash(vty, bgp);
7648
7649 vty_out(vty, "Tunnel-ip database:\n");
7650 hash_iterate(bgp->tip_hash,
7651 (void (*)(struct hash_bucket *, void *))show_tip_entry,
7652 vty);
7653 }
7654
7655 DEFUN(show_bgp_martian_nexthop_db, show_bgp_martian_nexthop_db_cmd,
7656 "show bgp [<view|vrf> VIEWVRFNAME] martian next-hop",
7657 SHOW_STR BGP_STR BGP_INSTANCE_HELP_STR
7658 "martian next-hops\n"
7659 "martian next-hop database\n")
7660 {
7661 struct bgp *bgp = NULL;
7662 int idx = 0;
7663 char *name = NULL;
7664
7665 /* [<vrf> VIEWVRFNAME] */
7666 if (argv_find(argv, argc, "vrf", &idx)) {
7667 name = argv[idx + 1]->arg;
7668 if (name && strmatch(name, VRF_DEFAULT_NAME))
7669 name = NULL;
7670 } else if (argv_find(argv, argc, "view", &idx))
7671 /* [<view> VIEWVRFNAME] */
7672 name = argv[idx + 1]->arg;
7673 if (name)
7674 bgp = bgp_lookup_by_name(name);
7675 else
7676 bgp = bgp_get_default();
7677
7678 if (!bgp) {
7679 vty_out(vty, "%% No BGP process is configured\n");
7680 return CMD_WARNING;
7681 }
7682 bgp_show_martian_nexthops(vty, bgp);
7683
7684 return CMD_SUCCESS;
7685 }
7686
7687 DEFUN (show_bgp_memory,
7688 show_bgp_memory_cmd,
7689 "show [ip] bgp memory",
7690 SHOW_STR
7691 IP_STR
7692 BGP_STR
7693 "Global BGP memory statistics\n")
7694 {
7695 char memstrbuf[MTYPE_MEMSTR_LEN];
7696 unsigned long count;
7697
7698 /* RIB related usage stats */
7699 count = mtype_stats_alloc(MTYPE_BGP_NODE);
7700 vty_out(vty, "%ld RIB nodes, using %s of memory\n", count,
7701 mtype_memstr(memstrbuf, sizeof(memstrbuf),
7702 count * sizeof(struct bgp_node)));
7703
7704 count = mtype_stats_alloc(MTYPE_BGP_ROUTE);
7705 vty_out(vty, "%ld BGP routes, using %s of memory\n", count,
7706 mtype_memstr(memstrbuf, sizeof(memstrbuf),
7707 count * sizeof(struct bgp_path_info)));
7708 if ((count = mtype_stats_alloc(MTYPE_BGP_ROUTE_EXTRA)))
7709 vty_out(vty, "%ld BGP route ancillaries, using %s of memory\n",
7710 count,
7711 mtype_memstr(
7712 memstrbuf, sizeof(memstrbuf),
7713 count * sizeof(struct bgp_path_info_extra)));
7714
7715 if ((count = mtype_stats_alloc(MTYPE_BGP_STATIC)))
7716 vty_out(vty, "%ld Static routes, using %s of memory\n", count,
7717 mtype_memstr(memstrbuf, sizeof(memstrbuf),
7718 count * sizeof(struct bgp_static)));
7719
7720 if ((count = mtype_stats_alloc(MTYPE_BGP_PACKET)))
7721 vty_out(vty, "%ld Packets, using %s of memory\n", count,
7722 mtype_memstr(memstrbuf, sizeof(memstrbuf),
7723 count * sizeof(struct bpacket)));
7724
7725 /* Adj-In/Out */
7726 if ((count = mtype_stats_alloc(MTYPE_BGP_ADJ_IN)))
7727 vty_out(vty, "%ld Adj-In entries, using %s of memory\n", count,
7728 mtype_memstr(memstrbuf, sizeof(memstrbuf),
7729 count * sizeof(struct bgp_adj_in)));
7730 if ((count = mtype_stats_alloc(MTYPE_BGP_ADJ_OUT)))
7731 vty_out(vty, "%ld Adj-Out entries, using %s of memory\n", count,
7732 mtype_memstr(memstrbuf, sizeof(memstrbuf),
7733 count * sizeof(struct bgp_adj_out)));
7734
7735 if ((count = mtype_stats_alloc(MTYPE_BGP_NEXTHOP_CACHE)))
7736 vty_out(vty, "%ld Nexthop cache entries, using %s of memory\n",
7737 count,
7738 mtype_memstr(memstrbuf, sizeof(memstrbuf),
7739 count * sizeof(struct bgp_nexthop_cache)));
7740
7741 if ((count = mtype_stats_alloc(MTYPE_BGP_DAMP_INFO)))
7742 vty_out(vty, "%ld Dampening entries, using %s of memory\n",
7743 count,
7744 mtype_memstr(memstrbuf, sizeof(memstrbuf),
7745 count * sizeof(struct bgp_damp_info)));
7746
7747 /* Attributes */
7748 count = attr_count();
7749 vty_out(vty, "%ld BGP attributes, using %s of memory\n", count,
7750 mtype_memstr(memstrbuf, sizeof(memstrbuf),
7751 count * sizeof(struct attr)));
7752
7753 if ((count = attr_unknown_count()))
7754 vty_out(vty, "%ld unknown attributes\n", count);
7755
7756 /* AS_PATH attributes */
7757 count = aspath_count();
7758 vty_out(vty, "%ld BGP AS-PATH entries, using %s of memory\n", count,
7759 mtype_memstr(memstrbuf, sizeof(memstrbuf),
7760 count * sizeof(struct aspath)));
7761
7762 count = mtype_stats_alloc(MTYPE_AS_SEG);
7763 vty_out(vty, "%ld BGP AS-PATH segments, using %s of memory\n", count,
7764 mtype_memstr(memstrbuf, sizeof(memstrbuf),
7765 count * sizeof(struct assegment)));
7766
7767 /* Other attributes */
7768 if ((count = community_count()))
7769 vty_out(vty, "%ld BGP community entries, using %s of memory\n",
7770 count, mtype_memstr(memstrbuf, sizeof(memstrbuf),
7771 count * sizeof(struct community)));
7772 if ((count = mtype_stats_alloc(MTYPE_ECOMMUNITY)))
7773 vty_out(vty, "%ld BGP community entries, using %s of memory\n",
7774 count, mtype_memstr(memstrbuf, sizeof(memstrbuf),
7775 count * sizeof(struct ecommunity)));
7776 if ((count = mtype_stats_alloc(MTYPE_LCOMMUNITY)))
7777 vty_out(vty,
7778 "%ld BGP large-community entries, using %s of memory\n",
7779 count, mtype_memstr(memstrbuf, sizeof(memstrbuf),
7780 count * sizeof(struct lcommunity)));
7781
7782 if ((count = mtype_stats_alloc(MTYPE_CLUSTER)))
7783 vty_out(vty, "%ld Cluster lists, using %s of memory\n", count,
7784 mtype_memstr(memstrbuf, sizeof(memstrbuf),
7785 count * sizeof(struct cluster_list)));
7786
7787 /* Peer related usage */
7788 count = mtype_stats_alloc(MTYPE_BGP_PEER);
7789 vty_out(vty, "%ld peers, using %s of memory\n", count,
7790 mtype_memstr(memstrbuf, sizeof(memstrbuf),
7791 count * sizeof(struct peer)));
7792
7793 if ((count = mtype_stats_alloc(MTYPE_PEER_GROUP)))
7794 vty_out(vty, "%ld peer groups, using %s of memory\n", count,
7795 mtype_memstr(memstrbuf, sizeof(memstrbuf),
7796 count * sizeof(struct peer_group)));
7797
7798 /* Other */
7799 if ((count = mtype_stats_alloc(MTYPE_HASH)))
7800 vty_out(vty, "%ld hash tables, using %s of memory\n", count,
7801 mtype_memstr(memstrbuf, sizeof(memstrbuf),
7802 count * sizeof(struct hash)));
7803 if ((count = mtype_stats_alloc(MTYPE_HASH_BACKET)))
7804 vty_out(vty, "%ld hash buckets, using %s of memory\n", count,
7805 mtype_memstr(memstrbuf, sizeof(memstrbuf),
7806 count * sizeof(struct hash_bucket)));
7807 if ((count = mtype_stats_alloc(MTYPE_BGP_REGEXP)))
7808 vty_out(vty, "%ld compiled regexes, using %s of memory\n",
7809 count, mtype_memstr(memstrbuf, sizeof(memstrbuf),
7810 count * sizeof(regex_t)));
7811 return CMD_SUCCESS;
7812 }
7813
7814 static void bgp_show_bestpath_json(struct bgp *bgp, json_object *json)
7815 {
7816 json_object *bestpath = json_object_new_object();
7817
7818 if (bgp_flag_check(bgp, BGP_FLAG_ASPATH_IGNORE))
7819 json_object_string_add(bestpath, "asPath", "ignore");
7820
7821 if (bgp_flag_check(bgp, BGP_FLAG_ASPATH_CONFED))
7822 json_object_string_add(bestpath, "asPath", "confed");
7823
7824 if (bgp_flag_check(bgp, BGP_FLAG_ASPATH_MULTIPATH_RELAX)) {
7825 if (bgp_flag_check(bgp, BGP_FLAG_MULTIPATH_RELAX_AS_SET))
7826 json_object_string_add(bestpath, "multiPathRelax",
7827 "as-set");
7828 else
7829 json_object_string_add(bestpath, "multiPathRelax",
7830 "true");
7831 } else
7832 json_object_string_add(bestpath, "multiPathRelax", "false");
7833
7834 if (bgp_flag_check(bgp, BGP_FLAG_COMPARE_ROUTER_ID))
7835 json_object_string_add(bestpath, "compareRouterId", "true");
7836 if (bgp_flag_check(bgp, BGP_FLAG_MED_CONFED)
7837 || bgp_flag_check(bgp, BGP_FLAG_MED_MISSING_AS_WORST)) {
7838 if (bgp_flag_check(bgp, BGP_FLAG_MED_CONFED))
7839 json_object_string_add(bestpath, "med", "confed");
7840 if (bgp_flag_check(bgp, BGP_FLAG_MED_MISSING_AS_WORST))
7841 json_object_string_add(bestpath, "med",
7842 "missing-as-worst");
7843 else
7844 json_object_string_add(bestpath, "med", "true");
7845 }
7846
7847 json_object_object_add(json, "bestPath", bestpath);
7848 }
7849
7850 /* Show BGP peer's summary information. */
7851 static int bgp_show_summary(struct vty *vty, struct bgp *bgp, int afi, int safi,
7852 bool use_json, json_object *json)
7853 {
7854 struct peer *peer;
7855 struct listnode *node, *nnode;
7856 unsigned int count = 0, dn_count = 0;
7857 char timebuf[BGP_UPTIME_LEN], dn_flag[2];
7858 char neighbor_buf[VTY_BUFSIZ];
7859 int neighbor_col_default_width = 16;
7860 int len;
7861 int max_neighbor_width = 0;
7862 int pfx_rcd_safi;
7863 json_object *json_peer = NULL;
7864 json_object *json_peers = NULL;
7865 struct peer_af *paf;
7866
7867 /* labeled-unicast routes are installed in the unicast table so in order
7868 * to
7869 * display the correct PfxRcd value we must look at SAFI_UNICAST
7870 */
7871 if (safi == SAFI_LABELED_UNICAST)
7872 pfx_rcd_safi = SAFI_UNICAST;
7873 else
7874 pfx_rcd_safi = safi;
7875
7876 if (use_json) {
7877 if (json == NULL)
7878 json = json_object_new_object();
7879
7880 json_peers = json_object_new_object();
7881 } else {
7882 /* Loop over all neighbors that will be displayed to determine
7883 * how many
7884 * characters are needed for the Neighbor column
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 memset(dn_flag, '\0', sizeof(dn_flag));
7892 if (peer_dynamic_neighbor(peer))
7893 dn_flag[0] = '*';
7894
7895 if (peer->hostname
7896 && bgp_flag_check(bgp,
7897 BGP_FLAG_SHOW_HOSTNAME))
7898 sprintf(neighbor_buf, "%s%s(%s) ",
7899 dn_flag, peer->hostname,
7900 peer->host);
7901 else
7902 sprintf(neighbor_buf, "%s%s ", dn_flag,
7903 peer->host);
7904
7905 len = strlen(neighbor_buf);
7906
7907 if (len > max_neighbor_width)
7908 max_neighbor_width = len;
7909 }
7910 }
7911
7912 /* Originally we displayed the Neighbor column as 16
7913 * characters wide so make that the default
7914 */
7915 if (max_neighbor_width < neighbor_col_default_width)
7916 max_neighbor_width = neighbor_col_default_width;
7917 }
7918
7919 for (ALL_LIST_ELEMENTS(bgp->peer, node, nnode, peer)) {
7920 if (!CHECK_FLAG(peer->flags, PEER_FLAG_CONFIG_NODE))
7921 continue;
7922
7923 if (!peer->afc[afi][safi])
7924 continue;
7925
7926 if (!count) {
7927 unsigned long ents;
7928 char memstrbuf[MTYPE_MEMSTR_LEN];
7929 int64_t vrf_id_ui;
7930
7931 vrf_id_ui = (bgp->vrf_id == VRF_UNKNOWN)
7932 ? -1
7933 : (int64_t)bgp->vrf_id;
7934
7935 /* Usage summary and header */
7936 if (use_json) {
7937 json_object_string_add(
7938 json, "routerId",
7939 inet_ntoa(bgp->router_id));
7940 json_object_int_add(json, "as", bgp->as);
7941 json_object_int_add(json, "vrfId", vrf_id_ui);
7942 json_object_string_add(
7943 json, "vrfName",
7944 (bgp->inst_type
7945 == BGP_INSTANCE_TYPE_DEFAULT)
7946 ? VRF_DEFAULT_NAME
7947 : bgp->name);
7948 } else {
7949 vty_out(vty,
7950 "BGP router identifier %s, local AS number %u vrf-id %d",
7951 inet_ntoa(bgp->router_id), bgp->as,
7952 bgp->vrf_id == VRF_UNKNOWN
7953 ? -1
7954 : (int)bgp->vrf_id);
7955 vty_out(vty, "\n");
7956 }
7957
7958 if (bgp_update_delay_configured(bgp)) {
7959 if (use_json) {
7960 json_object_int_add(
7961 json, "updateDelayLimit",
7962 bgp->v_update_delay);
7963
7964 if (bgp->v_update_delay
7965 != bgp->v_establish_wait)
7966 json_object_int_add(
7967 json,
7968 "updateDelayEstablishWait",
7969 bgp->v_establish_wait);
7970
7971 if (bgp_update_delay_active(bgp)) {
7972 json_object_string_add(
7973 json,
7974 "updateDelayFirstNeighbor",
7975 bgp->update_delay_begin_time);
7976 json_object_boolean_true_add(
7977 json,
7978 "updateDelayInProgress");
7979 } else {
7980 if (bgp->update_delay_over) {
7981 json_object_string_add(
7982 json,
7983 "updateDelayFirstNeighbor",
7984 bgp->update_delay_begin_time);
7985 json_object_string_add(
7986 json,
7987 "updateDelayBestpathResumed",
7988 bgp->update_delay_end_time);
7989 json_object_string_add(
7990 json,
7991 "updateDelayZebraUpdateResume",
7992 bgp->update_delay_zebra_resume_time);
7993 json_object_string_add(
7994 json,
7995 "updateDelayPeerUpdateResume",
7996 bgp->update_delay_peers_resume_time);
7997 }
7998 }
7999 } else {
8000 vty_out(vty,
8001 "Read-only mode update-delay limit: %d seconds\n",
8002 bgp->v_update_delay);
8003 if (bgp->v_update_delay
8004 != bgp->v_establish_wait)
8005 vty_out(vty,
8006 " Establish wait: %d seconds\n",
8007 bgp->v_establish_wait);
8008
8009 if (bgp_update_delay_active(bgp)) {
8010 vty_out(vty,
8011 " First neighbor established: %s\n",
8012 bgp->update_delay_begin_time);
8013 vty_out(vty,
8014 " Delay in progress\n");
8015 } else {
8016 if (bgp->update_delay_over) {
8017 vty_out(vty,
8018 " First neighbor established: %s\n",
8019 bgp->update_delay_begin_time);
8020 vty_out(vty,
8021 " Best-paths resumed: %s\n",
8022 bgp->update_delay_end_time);
8023 vty_out(vty,
8024 " zebra update resumed: %s\n",
8025 bgp->update_delay_zebra_resume_time);
8026 vty_out(vty,
8027 " peers update resumed: %s\n",
8028 bgp->update_delay_peers_resume_time);
8029 }
8030 }
8031 }
8032 }
8033
8034 if (use_json) {
8035 if (bgp_maxmed_onstartup_configured(bgp)
8036 && bgp->maxmed_active)
8037 json_object_boolean_true_add(
8038 json, "maxMedOnStartup");
8039 if (bgp->v_maxmed_admin)
8040 json_object_boolean_true_add(
8041 json, "maxMedAdministrative");
8042
8043 json_object_int_add(
8044 json, "tableVersion",
8045 bgp_table_version(bgp->rib[afi][safi]));
8046
8047 ents = bgp_table_count(bgp->rib[afi][safi]);
8048 json_object_int_add(json, "ribCount", ents);
8049 json_object_int_add(
8050 json, "ribMemory",
8051 ents * sizeof(struct bgp_node));
8052
8053 ents = bgp->af_peer_count[afi][safi];
8054 json_object_int_add(json, "peerCount", ents);
8055 json_object_int_add(json, "peerMemory",
8056 ents * sizeof(struct peer));
8057
8058 if ((ents = listcount(bgp->group))) {
8059 json_object_int_add(
8060 json, "peerGroupCount", ents);
8061 json_object_int_add(
8062 json, "peerGroupMemory",
8063 ents * sizeof(struct
8064 peer_group));
8065 }
8066
8067 if (CHECK_FLAG(bgp->af_flags[afi][safi],
8068 BGP_CONFIG_DAMPENING))
8069 json_object_boolean_true_add(
8070 json, "dampeningEnabled");
8071 } else {
8072 if (bgp_maxmed_onstartup_configured(bgp)
8073 && bgp->maxmed_active)
8074 vty_out(vty,
8075 "Max-med on-startup active\n");
8076 if (bgp->v_maxmed_admin)
8077 vty_out(vty,
8078 "Max-med administrative active\n");
8079
8080 vty_out(vty, "BGP table version %" PRIu64 "\n",
8081 bgp_table_version(bgp->rib[afi][safi]));
8082
8083 ents = bgp_table_count(bgp->rib[afi][safi]);
8084 vty_out(vty,
8085 "RIB entries %ld, using %s of memory\n",
8086 ents,
8087 mtype_memstr(memstrbuf,
8088 sizeof(memstrbuf),
8089 ents * sizeof(struct
8090 bgp_node)));
8091
8092 /* Peer related usage */
8093 ents = bgp->af_peer_count[afi][safi];
8094 vty_out(vty, "Peers %ld, using %s of memory\n",
8095 ents,
8096 mtype_memstr(
8097 memstrbuf, sizeof(memstrbuf),
8098 ents * sizeof(struct peer)));
8099
8100 if ((ents = listcount(bgp->group)))
8101 vty_out(vty,
8102 "Peer groups %ld, using %s of memory\n",
8103 ents,
8104 mtype_memstr(
8105 memstrbuf,
8106 sizeof(memstrbuf),
8107 ents * sizeof(struct
8108 peer_group)));
8109
8110 if (CHECK_FLAG(bgp->af_flags[afi][safi],
8111 BGP_CONFIG_DAMPENING))
8112 vty_out(vty, "Dampening enabled.\n");
8113 vty_out(vty, "\n");
8114
8115 /* Subtract 8 here because 'Neighbor' is
8116 * 8 characters */
8117 vty_out(vty, "Neighbor");
8118 vty_out(vty, "%*s", max_neighbor_width - 8,
8119 " ");
8120 vty_out(vty,
8121 "V AS MsgRcvd MsgSent TblVer InQ OutQ Up/Down State/PfxRcd\n");
8122 }
8123 }
8124
8125 count++;
8126
8127 if (use_json) {
8128 json_peer = json_object_new_object();
8129
8130 if (peer_dynamic_neighbor(peer)) {
8131 dn_count++;
8132 json_object_boolean_true_add(json_peer,
8133 "dynamicPeer");
8134 }
8135
8136 if (peer->hostname)
8137 json_object_string_add(json_peer, "hostname",
8138 peer->hostname);
8139
8140 if (peer->domainname)
8141 json_object_string_add(json_peer, "domainname",
8142 peer->domainname);
8143
8144 json_object_int_add(json_peer, "remoteAs", peer->as);
8145 json_object_int_add(json_peer, "version", 4);
8146 json_object_int_add(json_peer, "msgRcvd",
8147 PEER_TOTAL_RX(peer));
8148 json_object_int_add(json_peer, "msgSent",
8149 PEER_TOTAL_TX(peer));
8150
8151 json_object_int_add(json_peer, "tableVersion",
8152 peer->version[afi][safi]);
8153 json_object_int_add(json_peer, "outq",
8154 peer->obuf->count);
8155 json_object_int_add(json_peer, "inq", 0);
8156 peer_uptime(peer->uptime, timebuf, BGP_UPTIME_LEN,
8157 use_json, json_peer);
8158
8159 /*
8160 * Adding "pfxRcd" field to match with the corresponding
8161 * CLI. "prefixReceivedCount" will be deprecated in
8162 * future.
8163 */
8164 json_object_int_add(json_peer, "prefixReceivedCount",
8165 peer->pcount[afi][pfx_rcd_safi]);
8166 json_object_int_add(json_peer, "pfxRcd",
8167 peer->pcount[afi][pfx_rcd_safi]);
8168
8169 paf = peer_af_find(peer, afi, pfx_rcd_safi);
8170 if (paf && PAF_SUBGRP(paf))
8171 json_object_int_add(json_peer,
8172 "pfxSnt",
8173 (PAF_SUBGRP(paf))->scount);
8174
8175 if (CHECK_FLAG(peer->flags, PEER_FLAG_SHUTDOWN))
8176 json_object_string_add(json_peer, "state",
8177 "Idle (Admin)");
8178 else if (peer->afc_recv[afi][safi])
8179 json_object_string_add(
8180 json_peer, "state",
8181 lookup_msg(bgp_status_msg, peer->status,
8182 NULL));
8183 else if (CHECK_FLAG(peer->sflags,
8184 PEER_STATUS_PREFIX_OVERFLOW))
8185 json_object_string_add(json_peer, "state",
8186 "Idle (PfxCt)");
8187 else
8188 json_object_string_add(
8189 json_peer, "state",
8190 lookup_msg(bgp_status_msg, peer->status,
8191 NULL));
8192
8193 if (peer->conf_if)
8194 json_object_string_add(json_peer, "idType",
8195 "interface");
8196 else if (peer->su.sa.sa_family == AF_INET)
8197 json_object_string_add(json_peer, "idType",
8198 "ipv4");
8199 else if (peer->su.sa.sa_family == AF_INET6)
8200 json_object_string_add(json_peer, "idType",
8201 "ipv6");
8202
8203 json_object_object_add(json_peers, peer->host,
8204 json_peer);
8205 } else {
8206 memset(dn_flag, '\0', sizeof(dn_flag));
8207 if (peer_dynamic_neighbor(peer)) {
8208 dn_count++;
8209 dn_flag[0] = '*';
8210 }
8211
8212 if (peer->hostname
8213 && bgp_flag_check(bgp, BGP_FLAG_SHOW_HOSTNAME))
8214 len = vty_out(vty, "%s%s(%s)", dn_flag,
8215 peer->hostname, peer->host);
8216 else
8217 len = vty_out(vty, "%s%s", dn_flag, peer->host);
8218
8219 /* pad the neighbor column with spaces */
8220 if (len < max_neighbor_width)
8221 vty_out(vty, "%*s", max_neighbor_width - len,
8222 " ");
8223
8224 vty_out(vty, "4 %10u %7u %7u %8" PRIu64 " %4d %4zd %8s",
8225 peer->as, PEER_TOTAL_RX(peer),
8226 PEER_TOTAL_TX(peer), peer->version[afi][safi],
8227 0, peer->obuf->count,
8228 peer_uptime(peer->uptime, timebuf,
8229 BGP_UPTIME_LEN, 0, NULL));
8230
8231 if (peer->status == Established)
8232 if (peer->afc_recv[afi][safi])
8233 vty_out(vty, " %12ld",
8234 peer->pcount[afi]
8235 [pfx_rcd_safi]);
8236 else
8237 vty_out(vty, " NoNeg");
8238 else {
8239 if (CHECK_FLAG(peer->flags, PEER_FLAG_SHUTDOWN))
8240 vty_out(vty, " Idle (Admin)");
8241 else if (CHECK_FLAG(
8242 peer->sflags,
8243 PEER_STATUS_PREFIX_OVERFLOW))
8244 vty_out(vty, " Idle (PfxCt)");
8245 else
8246 vty_out(vty, " %12s",
8247 lookup_msg(bgp_status_msg,
8248 peer->status, NULL));
8249 }
8250 vty_out(vty, "\n");
8251 }
8252 }
8253
8254 if (use_json) {
8255 json_object_object_add(json, "peers", json_peers);
8256
8257 json_object_int_add(json, "totalPeers", count);
8258 json_object_int_add(json, "dynamicPeers", dn_count);
8259
8260 bgp_show_bestpath_json(bgp, json);
8261
8262 vty_out(vty, "%s\n", json_object_to_json_string_ext(
8263 json, JSON_C_TO_STRING_PRETTY));
8264 json_object_free(json);
8265 } else {
8266 if (count)
8267 vty_out(vty, "\nTotal number of neighbors %d\n", count);
8268 else {
8269 vty_out(vty, "No %s neighbor is configured\n",
8270 afi_safi_print(afi, safi));
8271 }
8272
8273 if (dn_count) {
8274 vty_out(vty, "* - dynamic neighbor\n");
8275 vty_out(vty, "%d dynamic neighbor(s), limit %d\n",
8276 dn_count, bgp->dynamic_neighbors_limit);
8277 }
8278 }
8279
8280 return CMD_SUCCESS;
8281 }
8282
8283 static void bgp_show_summary_afi_safi(struct vty *vty, struct bgp *bgp, int afi,
8284 int safi, bool use_json,
8285 json_object *json)
8286 {
8287 int is_first = 1;
8288 int afi_wildcard = (afi == AFI_MAX);
8289 int safi_wildcard = (safi == SAFI_MAX);
8290 int is_wildcard = (afi_wildcard || safi_wildcard);
8291 bool nbr_output = false;
8292
8293 if (use_json && is_wildcard)
8294 vty_out(vty, "{\n");
8295 if (afi_wildcard)
8296 afi = 1; /* AFI_IP */
8297 while (afi < AFI_MAX) {
8298 if (safi_wildcard)
8299 safi = 1; /* SAFI_UNICAST */
8300 while (safi < SAFI_MAX) {
8301 if (bgp_afi_safi_peer_exists(bgp, afi, safi)) {
8302 nbr_output = true;
8303 if (is_wildcard) {
8304 /*
8305 * So limit output to those afi/safi
8306 * pairs that
8307 * actualy have something interesting in
8308 * them
8309 */
8310 if (use_json) {
8311 json = json_object_new_object();
8312
8313 if (!is_first)
8314 vty_out(vty, ",\n");
8315 else
8316 is_first = 0;
8317
8318 vty_out(vty, "\"%s\":",
8319 afi_safi_json(afi,
8320 safi));
8321 } else {
8322 vty_out(vty, "\n%s Summary:\n",
8323 afi_safi_print(afi,
8324 safi));
8325 }
8326 }
8327 bgp_show_summary(vty, bgp, afi, safi, use_json,
8328 json);
8329 }
8330 safi++;
8331 if (!safi_wildcard)
8332 safi = SAFI_MAX;
8333 }
8334 afi++;
8335 if (!afi_wildcard)
8336 afi = AFI_MAX;
8337 }
8338
8339 if (use_json && is_wildcard)
8340 vty_out(vty, "}\n");
8341 else if (!nbr_output) {
8342 if (use_json)
8343 vty_out(vty, "{}\n");
8344 else
8345 vty_out(vty, "%% No BGP neighbors found\n");
8346 }
8347 }
8348
8349 static void bgp_show_all_instances_summary_vty(struct vty *vty, afi_t afi,
8350 safi_t safi, bool use_json)
8351 {
8352 struct listnode *node, *nnode;
8353 struct bgp *bgp;
8354 json_object *json = NULL;
8355 int is_first = 1;
8356 bool nbr_output = false;
8357
8358 if (use_json)
8359 vty_out(vty, "{\n");
8360
8361 for (ALL_LIST_ELEMENTS(bm->bgp, node, nnode, bgp)) {
8362 nbr_output = true;
8363 if (use_json) {
8364 json = json_object_new_object();
8365
8366 if (!is_first)
8367 vty_out(vty, ",\n");
8368 else
8369 is_first = 0;
8370
8371 vty_out(vty, "\"%s\":",
8372 (bgp->inst_type == BGP_INSTANCE_TYPE_DEFAULT)
8373 ? VRF_DEFAULT_NAME
8374 : bgp->name);
8375 } else {
8376 vty_out(vty, "\nInstance %s:\n",
8377 (bgp->inst_type == BGP_INSTANCE_TYPE_DEFAULT)
8378 ? VRF_DEFAULT_NAME
8379 : bgp->name);
8380 }
8381 bgp_show_summary_afi_safi(vty, bgp, afi, safi, use_json, json);
8382 }
8383
8384 if (use_json)
8385 vty_out(vty, "}\n");
8386 else if (!nbr_output)
8387 vty_out(vty, "%% BGP instance not found\n");
8388 }
8389
8390 int bgp_show_summary_vty(struct vty *vty, const char *name, afi_t afi,
8391 safi_t safi, bool use_json)
8392 {
8393 struct bgp *bgp;
8394
8395 if (name) {
8396 if (strmatch(name, "all")) {
8397 bgp_show_all_instances_summary_vty(vty, afi, safi,
8398 use_json);
8399 return CMD_SUCCESS;
8400 } else {
8401 bgp = bgp_lookup_by_name(name);
8402
8403 if (!bgp) {
8404 if (use_json)
8405 vty_out(vty, "{}\n");
8406 else
8407 vty_out(vty,
8408 "%% BGP instance not found\n");
8409 return CMD_WARNING;
8410 }
8411
8412 bgp_show_summary_afi_safi(vty, bgp, afi, safi, use_json,
8413 NULL);
8414 return CMD_SUCCESS;
8415 }
8416 }
8417
8418 bgp = bgp_get_default();
8419
8420 if (bgp)
8421 bgp_show_summary_afi_safi(vty, bgp, afi, safi, use_json, NULL);
8422 else {
8423 if (use_json)
8424 vty_out(vty, "{}\n");
8425 else
8426 vty_out(vty, "%% BGP instance not found\n");
8427 return CMD_WARNING;
8428 }
8429
8430 return CMD_SUCCESS;
8431 }
8432
8433 /* `show [ip] bgp summary' commands. */
8434 DEFUN (show_ip_bgp_summary,
8435 show_ip_bgp_summary_cmd,
8436 "show [ip] bgp [<view|vrf> VIEWVRFNAME] ["BGP_AFI_CMD_STR" ["BGP_SAFI_WITH_LABEL_CMD_STR"]] summary [json]",
8437 SHOW_STR
8438 IP_STR
8439 BGP_STR
8440 BGP_INSTANCE_HELP_STR
8441 BGP_AFI_HELP_STR
8442 BGP_SAFI_WITH_LABEL_HELP_STR
8443 "Summary of BGP neighbor status\n"
8444 JSON_STR)
8445 {
8446 char *vrf = NULL;
8447 afi_t afi = AFI_MAX;
8448 safi_t safi = SAFI_MAX;
8449
8450 int idx = 0;
8451
8452 /* show [ip] bgp */
8453 if (argv_find(argv, argc, "ip", &idx))
8454 afi = AFI_IP;
8455 /* [<vrf> VIEWVRFNAME] */
8456 if (argv_find(argv, argc, "vrf", &idx)) {
8457 vrf = argv[idx + 1]->arg;
8458 if (vrf && strmatch(vrf, VRF_DEFAULT_NAME))
8459 vrf = NULL;
8460 } else if (argv_find(argv, argc, "view", &idx))
8461 /* [<view> VIEWVRFNAME] */
8462 vrf = argv[idx + 1]->arg;
8463 /* ["BGP_AFI_CMD_STR" ["BGP_SAFI_CMD_STR"]] */
8464 if (argv_find_and_parse_afi(argv, argc, &idx, &afi)) {
8465 argv_find_and_parse_safi(argv, argc, &idx, &safi);
8466 }
8467
8468 bool uj = use_json(argc, argv);
8469
8470 return bgp_show_summary_vty(vty, vrf, afi, safi, uj);
8471 }
8472
8473 const char *afi_safi_print(afi_t afi, safi_t safi)
8474 {
8475 if (afi == AFI_IP && safi == SAFI_UNICAST)
8476 return "IPv4 Unicast";
8477 else if (afi == AFI_IP && safi == SAFI_MULTICAST)
8478 return "IPv4 Multicast";
8479 else if (afi == AFI_IP && safi == SAFI_LABELED_UNICAST)
8480 return "IPv4 Labeled Unicast";
8481 else if (afi == AFI_IP && safi == SAFI_MPLS_VPN)
8482 return "IPv4 VPN";
8483 else if (afi == AFI_IP && safi == SAFI_ENCAP)
8484 return "IPv4 Encap";
8485 else if (afi == AFI_IP && safi == SAFI_FLOWSPEC)
8486 return "IPv4 Flowspec";
8487 else if (afi == AFI_IP6 && safi == SAFI_UNICAST)
8488 return "IPv6 Unicast";
8489 else if (afi == AFI_IP6 && safi == SAFI_MULTICAST)
8490 return "IPv6 Multicast";
8491 else if (afi == AFI_IP6 && safi == SAFI_LABELED_UNICAST)
8492 return "IPv6 Labeled Unicast";
8493 else if (afi == AFI_IP6 && safi == SAFI_MPLS_VPN)
8494 return "IPv6 VPN";
8495 else if (afi == AFI_IP6 && safi == SAFI_ENCAP)
8496 return "IPv6 Encap";
8497 else if (afi == AFI_IP6 && safi == SAFI_FLOWSPEC)
8498 return "IPv6 Flowspec";
8499 else if (afi == AFI_L2VPN && safi == SAFI_EVPN)
8500 return "L2VPN EVPN";
8501 else
8502 return "Unknown";
8503 }
8504
8505 /*
8506 * Please note that we have intentionally camelCased
8507 * the return strings here. So if you want
8508 * to use this function, please ensure you
8509 * are doing this within json output
8510 */
8511 const char *afi_safi_json(afi_t afi, safi_t safi)
8512 {
8513 if (afi == AFI_IP && safi == SAFI_UNICAST)
8514 return "ipv4Unicast";
8515 else if (afi == AFI_IP && safi == SAFI_MULTICAST)
8516 return "ipv4Multicast";
8517 else if (afi == AFI_IP && safi == SAFI_LABELED_UNICAST)
8518 return "ipv4LabeledUnicast";
8519 else if (afi == AFI_IP && safi == SAFI_MPLS_VPN)
8520 return "ipv4Vpn";
8521 else if (afi == AFI_IP && safi == SAFI_ENCAP)
8522 return "ipv4Encap";
8523 else if (afi == AFI_IP && safi == SAFI_FLOWSPEC)
8524 return "ipv4Flowspec";
8525 else if (afi == AFI_IP6 && safi == SAFI_UNICAST)
8526 return "ipv6Unicast";
8527 else if (afi == AFI_IP6 && safi == SAFI_MULTICAST)
8528 return "ipv6Multicast";
8529 else if (afi == AFI_IP6 && safi == SAFI_LABELED_UNICAST)
8530 return "ipv6LabeledUnicast";
8531 else if (afi == AFI_IP6 && safi == SAFI_MPLS_VPN)
8532 return "ipv6Vpn";
8533 else if (afi == AFI_IP6 && safi == SAFI_ENCAP)
8534 return "ipv6Encap";
8535 else if (afi == AFI_IP6 && safi == SAFI_FLOWSPEC)
8536 return "ipv6Flowspec";
8537 else if (afi == AFI_L2VPN && safi == SAFI_EVPN)
8538 return "l2VpnEvpn";
8539 else
8540 return "Unknown";
8541 }
8542
8543 /* Show BGP peer's information. */
8544 enum show_type { show_all, show_peer, show_ipv4_all, show_ipv6_all, show_ipv4_peer, show_ipv6_peer };
8545
8546 static void bgp_show_peer_afi_orf_cap(struct vty *vty, struct peer *p,
8547 afi_t afi, safi_t safi,
8548 uint16_t adv_smcap, uint16_t adv_rmcap,
8549 uint16_t rcv_smcap, uint16_t rcv_rmcap,
8550 bool use_json, json_object *json_pref)
8551 {
8552 /* Send-Mode */
8553 if (CHECK_FLAG(p->af_cap[afi][safi], adv_smcap)
8554 || CHECK_FLAG(p->af_cap[afi][safi], rcv_smcap)) {
8555 if (use_json) {
8556 if (CHECK_FLAG(p->af_cap[afi][safi], adv_smcap)
8557 && CHECK_FLAG(p->af_cap[afi][safi], rcv_smcap))
8558 json_object_string_add(json_pref, "sendMode",
8559 "advertisedAndReceived");
8560 else if (CHECK_FLAG(p->af_cap[afi][safi], adv_smcap))
8561 json_object_string_add(json_pref, "sendMode",
8562 "advertised");
8563 else if (CHECK_FLAG(p->af_cap[afi][safi], rcv_smcap))
8564 json_object_string_add(json_pref, "sendMode",
8565 "received");
8566 } else {
8567 vty_out(vty, " Send-mode: ");
8568 if (CHECK_FLAG(p->af_cap[afi][safi], adv_smcap))
8569 vty_out(vty, "advertised");
8570 if (CHECK_FLAG(p->af_cap[afi][safi], rcv_smcap))
8571 vty_out(vty, "%sreceived",
8572 CHECK_FLAG(p->af_cap[afi][safi],
8573 adv_smcap)
8574 ? ", "
8575 : "");
8576 vty_out(vty, "\n");
8577 }
8578 }
8579
8580 /* Receive-Mode */
8581 if (CHECK_FLAG(p->af_cap[afi][safi], adv_rmcap)
8582 || CHECK_FLAG(p->af_cap[afi][safi], rcv_rmcap)) {
8583 if (use_json) {
8584 if (CHECK_FLAG(p->af_cap[afi][safi], adv_rmcap)
8585 && CHECK_FLAG(p->af_cap[afi][safi], rcv_rmcap))
8586 json_object_string_add(json_pref, "recvMode",
8587 "advertisedAndReceived");
8588 else if (CHECK_FLAG(p->af_cap[afi][safi], adv_rmcap))
8589 json_object_string_add(json_pref, "recvMode",
8590 "advertised");
8591 else if (CHECK_FLAG(p->af_cap[afi][safi], rcv_rmcap))
8592 json_object_string_add(json_pref, "recvMode",
8593 "received");
8594 } else {
8595 vty_out(vty, " Receive-mode: ");
8596 if (CHECK_FLAG(p->af_cap[afi][safi], adv_rmcap))
8597 vty_out(vty, "advertised");
8598 if (CHECK_FLAG(p->af_cap[afi][safi], rcv_rmcap))
8599 vty_out(vty, "%sreceived",
8600 CHECK_FLAG(p->af_cap[afi][safi],
8601 adv_rmcap)
8602 ? ", "
8603 : "");
8604 vty_out(vty, "\n");
8605 }
8606 }
8607 }
8608
8609 static void bgp_show_peer_afi(struct vty *vty, struct peer *p, afi_t afi,
8610 safi_t safi, bool use_json,
8611 json_object *json_neigh)
8612 {
8613 struct bgp_filter *filter;
8614 struct peer_af *paf;
8615 char orf_pfx_name[BUFSIZ];
8616 int orf_pfx_count;
8617 json_object *json_af = NULL;
8618 json_object *json_prefA = NULL;
8619 json_object *json_prefB = NULL;
8620 json_object *json_addr = NULL;
8621
8622 if (use_json) {
8623 json_addr = json_object_new_object();
8624 json_af = json_object_new_object();
8625 filter = &p->filter[afi][safi];
8626
8627 if (peer_group_active(p))
8628 json_object_string_add(json_addr, "peerGroupMember",
8629 p->group->name);
8630
8631 paf = peer_af_find(p, afi, safi);
8632 if (paf && PAF_SUBGRP(paf)) {
8633 json_object_int_add(json_addr, "updateGroupId",
8634 PAF_UPDGRP(paf)->id);
8635 json_object_int_add(json_addr, "subGroupId",
8636 PAF_SUBGRP(paf)->id);
8637 json_object_int_add(json_addr, "packetQueueLength",
8638 bpacket_queue_virtual_length(paf));
8639 }
8640
8641 if (CHECK_FLAG(p->af_cap[afi][safi], PEER_CAP_ORF_PREFIX_SM_ADV)
8642 || CHECK_FLAG(p->af_cap[afi][safi],
8643 PEER_CAP_ORF_PREFIX_SM_RCV)
8644 || CHECK_FLAG(p->af_cap[afi][safi],
8645 PEER_CAP_ORF_PREFIX_RM_ADV)
8646 || CHECK_FLAG(p->af_cap[afi][safi],
8647 PEER_CAP_ORF_PREFIX_RM_RCV)) {
8648 json_object_int_add(json_af, "orfType",
8649 ORF_TYPE_PREFIX);
8650 json_prefA = json_object_new_object();
8651 bgp_show_peer_afi_orf_cap(vty, p, afi, safi,
8652 PEER_CAP_ORF_PREFIX_SM_ADV,
8653 PEER_CAP_ORF_PREFIX_RM_ADV,
8654 PEER_CAP_ORF_PREFIX_SM_RCV,
8655 PEER_CAP_ORF_PREFIX_RM_RCV,
8656 use_json, json_prefA);
8657 json_object_object_add(json_af, "orfPrefixList",
8658 json_prefA);
8659 }
8660
8661 if (CHECK_FLAG(p->af_cap[afi][safi], PEER_CAP_ORF_PREFIX_SM_ADV)
8662 || CHECK_FLAG(p->af_cap[afi][safi],
8663 PEER_CAP_ORF_PREFIX_SM_OLD_RCV)
8664 || CHECK_FLAG(p->af_cap[afi][safi],
8665 PEER_CAP_ORF_PREFIX_RM_ADV)
8666 || CHECK_FLAG(p->af_cap[afi][safi],
8667 PEER_CAP_ORF_PREFIX_RM_OLD_RCV)) {
8668 json_object_int_add(json_af, "orfOldType",
8669 ORF_TYPE_PREFIX_OLD);
8670 json_prefB = json_object_new_object();
8671 bgp_show_peer_afi_orf_cap(
8672 vty, p, afi, safi, PEER_CAP_ORF_PREFIX_SM_ADV,
8673 PEER_CAP_ORF_PREFIX_RM_ADV,
8674 PEER_CAP_ORF_PREFIX_SM_OLD_RCV,
8675 PEER_CAP_ORF_PREFIX_RM_OLD_RCV, use_json,
8676 json_prefB);
8677 json_object_object_add(json_af, "orfOldPrefixList",
8678 json_prefB);
8679 }
8680
8681 if (CHECK_FLAG(p->af_cap[afi][safi], PEER_CAP_ORF_PREFIX_SM_ADV)
8682 || CHECK_FLAG(p->af_cap[afi][safi],
8683 PEER_CAP_ORF_PREFIX_SM_RCV)
8684 || CHECK_FLAG(p->af_cap[afi][safi],
8685 PEER_CAP_ORF_PREFIX_SM_OLD_RCV)
8686 || CHECK_FLAG(p->af_cap[afi][safi],
8687 PEER_CAP_ORF_PREFIX_RM_ADV)
8688 || CHECK_FLAG(p->af_cap[afi][safi],
8689 PEER_CAP_ORF_PREFIX_RM_RCV)
8690 || CHECK_FLAG(p->af_cap[afi][safi],
8691 PEER_CAP_ORF_PREFIX_RM_OLD_RCV))
8692 json_object_object_add(json_addr, "afDependentCap",
8693 json_af);
8694 else
8695 json_object_free(json_af);
8696
8697 sprintf(orf_pfx_name, "%s.%d.%d", p->host, afi, safi);
8698 orf_pfx_count = prefix_bgp_show_prefix_list(
8699 NULL, afi, orf_pfx_name, use_json);
8700
8701 if (CHECK_FLAG(p->af_sflags[afi][safi],
8702 PEER_STATUS_ORF_PREFIX_SEND)
8703 || orf_pfx_count) {
8704 if (CHECK_FLAG(p->af_sflags[afi][safi],
8705 PEER_STATUS_ORF_PREFIX_SEND))
8706 json_object_boolean_true_add(json_neigh,
8707 "orfSent");
8708 if (orf_pfx_count)
8709 json_object_int_add(json_addr, "orfRecvCounter",
8710 orf_pfx_count);
8711 }
8712 if (CHECK_FLAG(p->af_sflags[afi][safi],
8713 PEER_STATUS_ORF_WAIT_REFRESH))
8714 json_object_string_add(
8715 json_addr, "orfFirstUpdate",
8716 "deferredUntilORFOrRouteRefreshRecvd");
8717
8718 if (CHECK_FLAG(p->af_flags[afi][safi],
8719 PEER_FLAG_REFLECTOR_CLIENT))
8720 json_object_boolean_true_add(json_addr,
8721 "routeReflectorClient");
8722 if (CHECK_FLAG(p->af_flags[afi][safi],
8723 PEER_FLAG_RSERVER_CLIENT))
8724 json_object_boolean_true_add(json_addr,
8725 "routeServerClient");
8726 if (CHECK_FLAG(p->af_flags[afi][safi], PEER_FLAG_SOFT_RECONFIG))
8727 json_object_boolean_true_add(json_addr,
8728 "inboundSoftConfigPermit");
8729
8730 if (CHECK_FLAG(p->af_flags[afi][safi],
8731 PEER_FLAG_REMOVE_PRIVATE_AS_ALL_REPLACE))
8732 json_object_boolean_true_add(
8733 json_addr,
8734 "privateAsNumsAllReplacedInUpdatesToNbr");
8735 else if (CHECK_FLAG(p->af_flags[afi][safi],
8736 PEER_FLAG_REMOVE_PRIVATE_AS_REPLACE))
8737 json_object_boolean_true_add(
8738 json_addr,
8739 "privateAsNumsReplacedInUpdatesToNbr");
8740 else if (CHECK_FLAG(p->af_flags[afi][safi],
8741 PEER_FLAG_REMOVE_PRIVATE_AS_ALL))
8742 json_object_boolean_true_add(
8743 json_addr,
8744 "privateAsNumsAllRemovedInUpdatesToNbr");
8745 else if (CHECK_FLAG(p->af_flags[afi][safi],
8746 PEER_FLAG_REMOVE_PRIVATE_AS))
8747 json_object_boolean_true_add(
8748 json_addr,
8749 "privateAsNumsRemovedInUpdatesToNbr");
8750
8751 if (p->addpath_type[afi][safi] != BGP_ADDPATH_NONE)
8752 json_object_boolean_true_add(
8753 json_addr,
8754 bgp_addpath_names(p->addpath_type[afi][safi])
8755 ->type_json_name);
8756
8757 if (CHECK_FLAG(p->af_flags[afi][safi], PEER_FLAG_AS_OVERRIDE))
8758 json_object_string_add(json_addr,
8759 "overrideASNsInOutboundUpdates",
8760 "ifAspathEqualRemoteAs");
8761
8762 if (CHECK_FLAG(p->af_flags[afi][safi], PEER_FLAG_NEXTHOP_SELF)
8763 || CHECK_FLAG(p->af_flags[afi][safi],
8764 PEER_FLAG_FORCE_NEXTHOP_SELF))
8765 json_object_boolean_true_add(json_addr,
8766 "routerAlwaysNextHop");
8767 if (CHECK_FLAG(p->af_flags[afi][safi],
8768 PEER_FLAG_AS_PATH_UNCHANGED))
8769 json_object_boolean_true_add(
8770 json_addr, "unchangedAsPathPropogatedToNbr");
8771 if (CHECK_FLAG(p->af_flags[afi][safi],
8772 PEER_FLAG_NEXTHOP_UNCHANGED))
8773 json_object_boolean_true_add(
8774 json_addr, "unchangedNextHopPropogatedToNbr");
8775 if (CHECK_FLAG(p->af_flags[afi][safi], PEER_FLAG_MED_UNCHANGED))
8776 json_object_boolean_true_add(
8777 json_addr, "unchangedMedPropogatedToNbr");
8778 if (CHECK_FLAG(p->af_flags[afi][safi], PEER_FLAG_SEND_COMMUNITY)
8779 || CHECK_FLAG(p->af_flags[afi][safi],
8780 PEER_FLAG_SEND_EXT_COMMUNITY)) {
8781 if (CHECK_FLAG(p->af_flags[afi][safi],
8782 PEER_FLAG_SEND_COMMUNITY)
8783 && CHECK_FLAG(p->af_flags[afi][safi],
8784 PEER_FLAG_SEND_EXT_COMMUNITY))
8785 json_object_string_add(json_addr,
8786 "commAttriSentToNbr",
8787 "extendedAndStandard");
8788 else if (CHECK_FLAG(p->af_flags[afi][safi],
8789 PEER_FLAG_SEND_EXT_COMMUNITY))
8790 json_object_string_add(json_addr,
8791 "commAttriSentToNbr",
8792 "extended");
8793 else
8794 json_object_string_add(json_addr,
8795 "commAttriSentToNbr",
8796 "standard");
8797 }
8798 if (CHECK_FLAG(p->af_flags[afi][safi],
8799 PEER_FLAG_DEFAULT_ORIGINATE)) {
8800 if (p->default_rmap[afi][safi].name)
8801 json_object_string_add(
8802 json_addr, "defaultRouteMap",
8803 p->default_rmap[afi][safi].name);
8804
8805 if (paf && PAF_SUBGRP(paf)
8806 && CHECK_FLAG(PAF_SUBGRP(paf)->sflags,
8807 SUBGRP_STATUS_DEFAULT_ORIGINATE))
8808 json_object_boolean_true_add(json_addr,
8809 "defaultSent");
8810 else
8811 json_object_boolean_true_add(json_addr,
8812 "defaultNotSent");
8813 }
8814
8815 if (afi == AFI_L2VPN && safi == SAFI_EVPN) {
8816 if (is_evpn_enabled())
8817 json_object_boolean_true_add(
8818 json_addr, "advertiseAllVnis");
8819 }
8820
8821 if (filter->plist[FILTER_IN].name
8822 || filter->dlist[FILTER_IN].name
8823 || filter->aslist[FILTER_IN].name
8824 || filter->map[RMAP_IN].name)
8825 json_object_boolean_true_add(json_addr,
8826 "inboundPathPolicyConfig");
8827 if (filter->plist[FILTER_OUT].name
8828 || filter->dlist[FILTER_OUT].name
8829 || filter->aslist[FILTER_OUT].name
8830 || filter->map[RMAP_OUT].name || filter->usmap.name)
8831 json_object_boolean_true_add(
8832 json_addr, "outboundPathPolicyConfig");
8833
8834 /* prefix-list */
8835 if (filter->plist[FILTER_IN].name)
8836 json_object_string_add(json_addr,
8837 "incomingUpdatePrefixFilterList",
8838 filter->plist[FILTER_IN].name);
8839 if (filter->plist[FILTER_OUT].name)
8840 json_object_string_add(json_addr,
8841 "outgoingUpdatePrefixFilterList",
8842 filter->plist[FILTER_OUT].name);
8843
8844 /* distribute-list */
8845 if (filter->dlist[FILTER_IN].name)
8846 json_object_string_add(
8847 json_addr, "incomingUpdateNetworkFilterList",
8848 filter->dlist[FILTER_IN].name);
8849 if (filter->dlist[FILTER_OUT].name)
8850 json_object_string_add(
8851 json_addr, "outgoingUpdateNetworkFilterList",
8852 filter->dlist[FILTER_OUT].name);
8853
8854 /* filter-list. */
8855 if (filter->aslist[FILTER_IN].name)
8856 json_object_string_add(json_addr,
8857 "incomingUpdateAsPathFilterList",
8858 filter->aslist[FILTER_IN].name);
8859 if (filter->aslist[FILTER_OUT].name)
8860 json_object_string_add(json_addr,
8861 "outgoingUpdateAsPathFilterList",
8862 filter->aslist[FILTER_OUT].name);
8863
8864 /* route-map. */
8865 if (filter->map[RMAP_IN].name)
8866 json_object_string_add(
8867 json_addr, "routeMapForIncomingAdvertisements",
8868 filter->map[RMAP_IN].name);
8869 if (filter->map[RMAP_OUT].name)
8870 json_object_string_add(
8871 json_addr, "routeMapForOutgoingAdvertisements",
8872 filter->map[RMAP_OUT].name);
8873
8874 /* ebgp-requires-policy (inbound) */
8875 if (p->bgp->ebgp_requires_policy == DEFAULT_EBGP_POLICY_ENABLED
8876 && !bgp_inbound_policy_exists(p, filter))
8877 json_object_string_add(
8878 json_addr, "inboundEbgpRequiresPolicy",
8879 "Inbound updates discarded due to missing policy");
8880
8881 /* ebgp-requires-policy (outbound) */
8882 if (p->bgp->ebgp_requires_policy == DEFAULT_EBGP_POLICY_ENABLED
8883 && (!bgp_outbound_policy_exists(p, filter)))
8884 json_object_string_add(
8885 json_addr, "outboundEbgpRequiresPolicy",
8886 "Outbound updates discarded due to missing policy");
8887
8888 /* unsuppress-map */
8889 if (filter->usmap.name)
8890 json_object_string_add(json_addr,
8891 "selectiveUnsuppressRouteMap",
8892 filter->usmap.name);
8893
8894 /* Receive prefix count */
8895 json_object_int_add(json_addr, "acceptedPrefixCounter",
8896 p->pcount[afi][safi]);
8897 if (paf && PAF_SUBGRP(paf))
8898 json_object_int_add(json_addr, "sentPrefixCounter",
8899 (PAF_SUBGRP(paf))->scount);
8900
8901 /* Maximum prefix */
8902 if (CHECK_FLAG(p->af_flags[afi][safi], PEER_FLAG_MAX_PREFIX)) {
8903 json_object_int_add(json_addr, "prefixAllowedMax",
8904 p->pmax[afi][safi]);
8905 if (CHECK_FLAG(p->af_flags[afi][safi],
8906 PEER_FLAG_MAX_PREFIX_WARNING))
8907 json_object_boolean_true_add(
8908 json_addr, "prefixAllowedMaxWarning");
8909 json_object_int_add(json_addr,
8910 "prefixAllowedWarningThresh",
8911 p->pmax_threshold[afi][safi]);
8912 if (p->pmax_restart[afi][safi])
8913 json_object_int_add(
8914 json_addr,
8915 "prefixAllowedRestartIntervalMsecs",
8916 p->pmax_restart[afi][safi] * 60000);
8917 }
8918 json_object_object_add(json_neigh, afi_safi_print(afi, safi),
8919 json_addr);
8920
8921 } else {
8922 filter = &p->filter[afi][safi];
8923
8924 vty_out(vty, " For address family: %s\n",
8925 afi_safi_print(afi, safi));
8926
8927 if (peer_group_active(p))
8928 vty_out(vty, " %s peer-group member\n",
8929 p->group->name);
8930
8931 paf = peer_af_find(p, afi, safi);
8932 if (paf && PAF_SUBGRP(paf)) {
8933 vty_out(vty, " Update group %" PRIu64
8934 ", subgroup %" PRIu64 "\n",
8935 PAF_UPDGRP(paf)->id, PAF_SUBGRP(paf)->id);
8936 vty_out(vty, " Packet Queue length %d\n",
8937 bpacket_queue_virtual_length(paf));
8938 } else {
8939 vty_out(vty, " Not part of any update group\n");
8940 }
8941 if (CHECK_FLAG(p->af_cap[afi][safi], PEER_CAP_ORF_PREFIX_SM_ADV)
8942 || CHECK_FLAG(p->af_cap[afi][safi],
8943 PEER_CAP_ORF_PREFIX_SM_RCV)
8944 || CHECK_FLAG(p->af_cap[afi][safi],
8945 PEER_CAP_ORF_PREFIX_SM_OLD_RCV)
8946 || CHECK_FLAG(p->af_cap[afi][safi],
8947 PEER_CAP_ORF_PREFIX_RM_ADV)
8948 || CHECK_FLAG(p->af_cap[afi][safi],
8949 PEER_CAP_ORF_PREFIX_RM_RCV)
8950 || CHECK_FLAG(p->af_cap[afi][safi],
8951 PEER_CAP_ORF_PREFIX_RM_OLD_RCV))
8952 vty_out(vty, " AF-dependant capabilities:\n");
8953
8954 if (CHECK_FLAG(p->af_cap[afi][safi], PEER_CAP_ORF_PREFIX_SM_ADV)
8955 || CHECK_FLAG(p->af_cap[afi][safi],
8956 PEER_CAP_ORF_PREFIX_SM_RCV)
8957 || CHECK_FLAG(p->af_cap[afi][safi],
8958 PEER_CAP_ORF_PREFIX_RM_ADV)
8959 || CHECK_FLAG(p->af_cap[afi][safi],
8960 PEER_CAP_ORF_PREFIX_RM_RCV)) {
8961 vty_out(vty,
8962 " Outbound Route Filter (ORF) type (%d) Prefix-list:\n",
8963 ORF_TYPE_PREFIX);
8964 bgp_show_peer_afi_orf_cap(
8965 vty, p, afi, safi, PEER_CAP_ORF_PREFIX_SM_ADV,
8966 PEER_CAP_ORF_PREFIX_RM_ADV,
8967 PEER_CAP_ORF_PREFIX_SM_RCV,
8968 PEER_CAP_ORF_PREFIX_RM_RCV, use_json, NULL);
8969 }
8970 if (CHECK_FLAG(p->af_cap[afi][safi], PEER_CAP_ORF_PREFIX_SM_ADV)
8971 || CHECK_FLAG(p->af_cap[afi][safi],
8972 PEER_CAP_ORF_PREFIX_SM_OLD_RCV)
8973 || CHECK_FLAG(p->af_cap[afi][safi],
8974 PEER_CAP_ORF_PREFIX_RM_ADV)
8975 || CHECK_FLAG(p->af_cap[afi][safi],
8976 PEER_CAP_ORF_PREFIX_RM_OLD_RCV)) {
8977 vty_out(vty,
8978 " Outbound Route Filter (ORF) type (%d) Prefix-list:\n",
8979 ORF_TYPE_PREFIX_OLD);
8980 bgp_show_peer_afi_orf_cap(
8981 vty, p, afi, safi, PEER_CAP_ORF_PREFIX_SM_ADV,
8982 PEER_CAP_ORF_PREFIX_RM_ADV,
8983 PEER_CAP_ORF_PREFIX_SM_OLD_RCV,
8984 PEER_CAP_ORF_PREFIX_RM_OLD_RCV, use_json, NULL);
8985 }
8986
8987 sprintf(orf_pfx_name, "%s.%d.%d", p->host, afi, safi);
8988 orf_pfx_count = prefix_bgp_show_prefix_list(
8989 NULL, afi, orf_pfx_name, use_json);
8990
8991 if (CHECK_FLAG(p->af_sflags[afi][safi],
8992 PEER_STATUS_ORF_PREFIX_SEND)
8993 || orf_pfx_count) {
8994 vty_out(vty, " Outbound Route Filter (ORF):");
8995 if (CHECK_FLAG(p->af_sflags[afi][safi],
8996 PEER_STATUS_ORF_PREFIX_SEND))
8997 vty_out(vty, " sent;");
8998 if (orf_pfx_count)
8999 vty_out(vty, " received (%d entries)",
9000 orf_pfx_count);
9001 vty_out(vty, "\n");
9002 }
9003 if (CHECK_FLAG(p->af_sflags[afi][safi],
9004 PEER_STATUS_ORF_WAIT_REFRESH))
9005 vty_out(vty,
9006 " First update is deferred until ORF or ROUTE-REFRESH is received\n");
9007
9008 if (CHECK_FLAG(p->af_flags[afi][safi],
9009 PEER_FLAG_REFLECTOR_CLIENT))
9010 vty_out(vty, " Route-Reflector Client\n");
9011 if (CHECK_FLAG(p->af_flags[afi][safi],
9012 PEER_FLAG_RSERVER_CLIENT))
9013 vty_out(vty, " Route-Server Client\n");
9014 if (CHECK_FLAG(p->af_flags[afi][safi], PEER_FLAG_SOFT_RECONFIG))
9015 vty_out(vty,
9016 " Inbound soft reconfiguration allowed\n");
9017
9018 if (CHECK_FLAG(p->af_flags[afi][safi],
9019 PEER_FLAG_REMOVE_PRIVATE_AS_ALL_REPLACE))
9020 vty_out(vty,
9021 " Private AS numbers (all) replaced in updates to this neighbor\n");
9022 else if (CHECK_FLAG(p->af_flags[afi][safi],
9023 PEER_FLAG_REMOVE_PRIVATE_AS_REPLACE))
9024 vty_out(vty,
9025 " Private AS numbers replaced in updates to this neighbor\n");
9026 else if (CHECK_FLAG(p->af_flags[afi][safi],
9027 PEER_FLAG_REMOVE_PRIVATE_AS_ALL))
9028 vty_out(vty,
9029 " Private AS numbers (all) removed in updates to this neighbor\n");
9030 else if (CHECK_FLAG(p->af_flags[afi][safi],
9031 PEER_FLAG_REMOVE_PRIVATE_AS))
9032 vty_out(vty,
9033 " Private AS numbers removed in updates to this neighbor\n");
9034
9035 if (p->addpath_type[afi][safi] != BGP_ADDPATH_NONE)
9036 vty_out(vty, " %s\n",
9037 bgp_addpath_names(p->addpath_type[afi][safi])
9038 ->human_description);
9039
9040 if (CHECK_FLAG(p->af_flags[afi][safi], PEER_FLAG_AS_OVERRIDE))
9041 vty_out(vty,
9042 " Override ASNs in outbound updates if aspath equals remote-as\n");
9043
9044 if (CHECK_FLAG(p->af_flags[afi][safi], PEER_FLAG_NEXTHOP_SELF)
9045 || CHECK_FLAG(p->af_flags[afi][safi],
9046 PEER_FLAG_FORCE_NEXTHOP_SELF))
9047 vty_out(vty, " NEXT_HOP is always this router\n");
9048 if (CHECK_FLAG(p->af_flags[afi][safi],
9049 PEER_FLAG_AS_PATH_UNCHANGED))
9050 vty_out(vty,
9051 " AS_PATH is propagated unchanged to this neighbor\n");
9052 if (CHECK_FLAG(p->af_flags[afi][safi],
9053 PEER_FLAG_NEXTHOP_UNCHANGED))
9054 vty_out(vty,
9055 " NEXT_HOP is propagated unchanged to this neighbor\n");
9056 if (CHECK_FLAG(p->af_flags[afi][safi], PEER_FLAG_MED_UNCHANGED))
9057 vty_out(vty,
9058 " MED is propagated unchanged to this neighbor\n");
9059 if (CHECK_FLAG(p->af_flags[afi][safi], PEER_FLAG_SEND_COMMUNITY)
9060 || CHECK_FLAG(p->af_flags[afi][safi],
9061 PEER_FLAG_SEND_EXT_COMMUNITY)
9062 || CHECK_FLAG(p->af_flags[afi][safi],
9063 PEER_FLAG_SEND_LARGE_COMMUNITY)) {
9064 vty_out(vty,
9065 " Community attribute sent to this neighbor");
9066 if (CHECK_FLAG(p->af_flags[afi][safi],
9067 PEER_FLAG_SEND_COMMUNITY)
9068 && CHECK_FLAG(p->af_flags[afi][safi],
9069 PEER_FLAG_SEND_EXT_COMMUNITY)
9070 && CHECK_FLAG(p->af_flags[afi][safi],
9071 PEER_FLAG_SEND_LARGE_COMMUNITY))
9072 vty_out(vty, "(all)\n");
9073 else if (CHECK_FLAG(p->af_flags[afi][safi],
9074 PEER_FLAG_SEND_LARGE_COMMUNITY))
9075 vty_out(vty, "(large)\n");
9076 else if (CHECK_FLAG(p->af_flags[afi][safi],
9077 PEER_FLAG_SEND_EXT_COMMUNITY))
9078 vty_out(vty, "(extended)\n");
9079 else
9080 vty_out(vty, "(standard)\n");
9081 }
9082 if (CHECK_FLAG(p->af_flags[afi][safi],
9083 PEER_FLAG_DEFAULT_ORIGINATE)) {
9084 vty_out(vty, " Default information originate,");
9085
9086 if (p->default_rmap[afi][safi].name)
9087 vty_out(vty, " default route-map %s%s,",
9088 p->default_rmap[afi][safi].map ? "*"
9089 : "",
9090 p->default_rmap[afi][safi].name);
9091 if (paf && PAF_SUBGRP(paf)
9092 && CHECK_FLAG(PAF_SUBGRP(paf)->sflags,
9093 SUBGRP_STATUS_DEFAULT_ORIGINATE))
9094 vty_out(vty, " default sent\n");
9095 else
9096 vty_out(vty, " default not sent\n");
9097 }
9098
9099 /* advertise-vni-all */
9100 if (afi == AFI_L2VPN && safi == SAFI_EVPN) {
9101 if (is_evpn_enabled())
9102 vty_out(vty, " advertise-all-vni\n");
9103 }
9104
9105 if (filter->plist[FILTER_IN].name
9106 || filter->dlist[FILTER_IN].name
9107 || filter->aslist[FILTER_IN].name
9108 || filter->map[RMAP_IN].name)
9109 vty_out(vty, " Inbound path policy configured\n");
9110 if (filter->plist[FILTER_OUT].name
9111 || filter->dlist[FILTER_OUT].name
9112 || filter->aslist[FILTER_OUT].name
9113 || filter->map[RMAP_OUT].name || filter->usmap.name)
9114 vty_out(vty, " Outbound path policy configured\n");
9115
9116 /* prefix-list */
9117 if (filter->plist[FILTER_IN].name)
9118 vty_out(vty,
9119 " Incoming update prefix filter list is %s%s\n",
9120 filter->plist[FILTER_IN].plist ? "*" : "",
9121 filter->plist[FILTER_IN].name);
9122 if (filter->plist[FILTER_OUT].name)
9123 vty_out(vty,
9124 " Outgoing update prefix filter list is %s%s\n",
9125 filter->plist[FILTER_OUT].plist ? "*" : "",
9126 filter->plist[FILTER_OUT].name);
9127
9128 /* distribute-list */
9129 if (filter->dlist[FILTER_IN].name)
9130 vty_out(vty,
9131 " Incoming update network filter list is %s%s\n",
9132 filter->dlist[FILTER_IN].alist ? "*" : "",
9133 filter->dlist[FILTER_IN].name);
9134 if (filter->dlist[FILTER_OUT].name)
9135 vty_out(vty,
9136 " Outgoing update network filter list is %s%s\n",
9137 filter->dlist[FILTER_OUT].alist ? "*" : "",
9138 filter->dlist[FILTER_OUT].name);
9139
9140 /* filter-list. */
9141 if (filter->aslist[FILTER_IN].name)
9142 vty_out(vty,
9143 " Incoming update AS path filter list is %s%s\n",
9144 filter->aslist[FILTER_IN].aslist ? "*" : "",
9145 filter->aslist[FILTER_IN].name);
9146 if (filter->aslist[FILTER_OUT].name)
9147 vty_out(vty,
9148 " Outgoing update AS path filter list is %s%s\n",
9149 filter->aslist[FILTER_OUT].aslist ? "*" : "",
9150 filter->aslist[FILTER_OUT].name);
9151
9152 /* route-map. */
9153 if (filter->map[RMAP_IN].name)
9154 vty_out(vty,
9155 " Route map for incoming advertisements is %s%s\n",
9156 filter->map[RMAP_IN].map ? "*" : "",
9157 filter->map[RMAP_IN].name);
9158 if (filter->map[RMAP_OUT].name)
9159 vty_out(vty,
9160 " Route map for outgoing advertisements is %s%s\n",
9161 filter->map[RMAP_OUT].map ? "*" : "",
9162 filter->map[RMAP_OUT].name);
9163
9164 /* ebgp-requires-policy (inbound) */
9165 if (p->bgp->ebgp_requires_policy == DEFAULT_EBGP_POLICY_ENABLED
9166 && !bgp_inbound_policy_exists(p, filter))
9167 vty_out(vty,
9168 " Inbound updates discarded due to missing policy\n");
9169
9170 /* ebgp-requires-policy (outbound) */
9171 if (p->bgp->ebgp_requires_policy == DEFAULT_EBGP_POLICY_ENABLED
9172 && !bgp_outbound_policy_exists(p, filter))
9173 vty_out(vty,
9174 " Outbound updates discarded due to missing policy\n");
9175
9176 /* unsuppress-map */
9177 if (filter->usmap.name)
9178 vty_out(vty,
9179 " Route map for selective unsuppress is %s%s\n",
9180 filter->usmap.map ? "*" : "",
9181 filter->usmap.name);
9182
9183 /* Receive prefix count */
9184 vty_out(vty, " %ld accepted prefixes\n", p->pcount[afi][safi]);
9185
9186 /* Maximum prefix */
9187 if (CHECK_FLAG(p->af_flags[afi][safi], PEER_FLAG_MAX_PREFIX)) {
9188 vty_out(vty, " Maximum prefixes allowed %ld%s\n",
9189 p->pmax[afi][safi],
9190 CHECK_FLAG(p->af_flags[afi][safi],
9191 PEER_FLAG_MAX_PREFIX_WARNING)
9192 ? " (warning-only)"
9193 : "");
9194 vty_out(vty, " Threshold for warning message %d%%",
9195 p->pmax_threshold[afi][safi]);
9196 if (p->pmax_restart[afi][safi])
9197 vty_out(vty, ", restart interval %d min",
9198 p->pmax_restart[afi][safi]);
9199 vty_out(vty, "\n");
9200 }
9201
9202 vty_out(vty, "\n");
9203 }
9204 }
9205
9206 static void bgp_show_peer(struct vty *vty, struct peer *p, bool use_json,
9207 json_object *json)
9208 {
9209 struct bgp *bgp;
9210 char buf1[PREFIX2STR_BUFFER], buf[SU_ADDRSTRLEN];
9211 char timebuf[BGP_UPTIME_LEN];
9212 char dn_flag[2];
9213 const char *subcode_str;
9214 const char *code_str;
9215 afi_t afi;
9216 safi_t safi;
9217 uint16_t i;
9218 uint8_t *msg;
9219 json_object *json_neigh = NULL;
9220 time_t epoch_tbuf;
9221
9222 bgp = p->bgp;
9223
9224 if (use_json)
9225 json_neigh = json_object_new_object();
9226
9227 memset(dn_flag, '\0', sizeof(dn_flag));
9228 if (!p->conf_if && peer_dynamic_neighbor(p))
9229 dn_flag[0] = '*';
9230
9231 if (!use_json) {
9232 if (p->conf_if) /* Configured interface name. */
9233 vty_out(vty, "BGP neighbor on %s: %s, ", p->conf_if,
9234 BGP_PEER_SU_UNSPEC(p)
9235 ? "None"
9236 : sockunion2str(&p->su, buf,
9237 SU_ADDRSTRLEN));
9238 else /* Configured IP address. */
9239 vty_out(vty, "BGP neighbor is %s%s, ", dn_flag,
9240 p->host);
9241 }
9242
9243 if (use_json) {
9244 if (p->conf_if && BGP_PEER_SU_UNSPEC(p))
9245 json_object_string_add(json_neigh, "bgpNeighborAddr",
9246 "none");
9247 else if (p->conf_if && !BGP_PEER_SU_UNSPEC(p))
9248 json_object_string_add(
9249 json_neigh, "bgpNeighborAddr",
9250 sockunion2str(&p->su, buf, SU_ADDRSTRLEN));
9251
9252 json_object_int_add(json_neigh, "remoteAs", p->as);
9253
9254 if (p->change_local_as)
9255 json_object_int_add(json_neigh, "localAs",
9256 p->change_local_as);
9257 else
9258 json_object_int_add(json_neigh, "localAs", p->local_as);
9259
9260 if (CHECK_FLAG(p->flags, PEER_FLAG_LOCAL_AS_NO_PREPEND))
9261 json_object_boolean_true_add(json_neigh,
9262 "localAsNoPrepend");
9263
9264 if (CHECK_FLAG(p->flags, PEER_FLAG_LOCAL_AS_REPLACE_AS))
9265 json_object_boolean_true_add(json_neigh,
9266 "localAsReplaceAs");
9267 } else {
9268 if ((p->as_type == AS_SPECIFIED) || (p->as_type == AS_EXTERNAL)
9269 || (p->as_type == AS_INTERNAL))
9270 vty_out(vty, "remote AS %u, ", p->as);
9271 else
9272 vty_out(vty, "remote AS Unspecified, ");
9273 vty_out(vty, "local AS %u%s%s, ",
9274 p->change_local_as ? p->change_local_as : p->local_as,
9275 CHECK_FLAG(p->flags, PEER_FLAG_LOCAL_AS_NO_PREPEND)
9276 ? " no-prepend"
9277 : "",
9278 CHECK_FLAG(p->flags, PEER_FLAG_LOCAL_AS_REPLACE_AS)
9279 ? " replace-as"
9280 : "");
9281 }
9282 /* peer type internal or confed-internal */
9283 if ((p->as == p->local_as) || (p->as_type == AS_INTERNAL)) {
9284 if (use_json) {
9285 if (CHECK_FLAG(bgp->config, BGP_CONFIG_CONFEDERATION))
9286 json_object_boolean_true_add(
9287 json_neigh, "nbrConfedInternalLink");
9288 else
9289 json_object_boolean_true_add(json_neigh,
9290 "nbrInternalLink");
9291 } else {
9292 if (CHECK_FLAG(bgp->config, BGP_CONFIG_CONFEDERATION))
9293 vty_out(vty, "confed-internal link\n");
9294 else
9295 vty_out(vty, "internal link\n");
9296 }
9297 /* peer type external or confed-external */
9298 } else if (p->as || (p->as_type == AS_EXTERNAL)) {
9299 if (use_json) {
9300 if (CHECK_FLAG(bgp->config, BGP_CONFIG_CONFEDERATION))
9301 json_object_boolean_true_add(
9302 json_neigh, "nbrConfedExternalLink");
9303 else
9304 json_object_boolean_true_add(json_neigh,
9305 "nbrExternalLink");
9306 } else {
9307 if (bgp_confederation_peers_check(bgp, p->as))
9308 vty_out(vty, "confed-external link\n");
9309 else
9310 vty_out(vty, "external link\n");
9311 }
9312 } else {
9313 if (use_json)
9314 json_object_boolean_true_add(json_neigh,
9315 "nbrUnspecifiedLink");
9316 else
9317 vty_out(vty, "unspecified link\n");
9318 }
9319
9320 /* Description. */
9321 if (p->desc) {
9322 if (use_json)
9323 json_object_string_add(json_neigh, "nbrDesc", p->desc);
9324 else
9325 vty_out(vty, " Description: %s\n", p->desc);
9326 }
9327
9328 if (p->hostname) {
9329 if (use_json) {
9330 if (p->hostname)
9331 json_object_string_add(json_neigh, "hostname",
9332 p->hostname);
9333
9334 if (p->domainname)
9335 json_object_string_add(json_neigh, "domainname",
9336 p->domainname);
9337 } else {
9338 if (p->domainname && (p->domainname[0] != '\0'))
9339 vty_out(vty, "Hostname: %s.%s\n", p->hostname,
9340 p->domainname);
9341 else
9342 vty_out(vty, "Hostname: %s\n", p->hostname);
9343 }
9344 }
9345
9346 /* Peer-group */
9347 if (p->group) {
9348 if (use_json) {
9349 json_object_string_add(json_neigh, "peerGroup",
9350 p->group->name);
9351
9352 if (dn_flag[0]) {
9353 struct prefix prefix, *range = NULL;
9354
9355 sockunion2hostprefix(&(p->su), &prefix);
9356 range = peer_group_lookup_dynamic_neighbor_range(
9357 p->group, &prefix);
9358
9359 if (range) {
9360 prefix2str(range, buf1, sizeof(buf1));
9361 json_object_string_add(
9362 json_neigh,
9363 "peerSubnetRangeGroup", buf1);
9364 }
9365 }
9366 } else {
9367 vty_out(vty,
9368 " Member of peer-group %s for session parameters\n",
9369 p->group->name);
9370
9371 if (dn_flag[0]) {
9372 struct prefix prefix, *range = NULL;
9373
9374 sockunion2hostprefix(&(p->su), &prefix);
9375 range = peer_group_lookup_dynamic_neighbor_range(
9376 p->group, &prefix);
9377
9378 if (range) {
9379 prefix2str(range, buf1, sizeof(buf1));
9380 vty_out(vty,
9381 " Belongs to the subnet range group: %s\n",
9382 buf1);
9383 }
9384 }
9385 }
9386 }
9387
9388 if (use_json) {
9389 /* Administrative shutdown. */
9390 if (CHECK_FLAG(p->flags, PEER_FLAG_SHUTDOWN))
9391 json_object_boolean_true_add(json_neigh,
9392 "adminShutDown");
9393
9394 /* BGP Version. */
9395 json_object_int_add(json_neigh, "bgpVersion", 4);
9396 json_object_string_add(
9397 json_neigh, "remoteRouterId",
9398 inet_ntop(AF_INET, &p->remote_id, buf1, sizeof(buf1)));
9399 json_object_string_add(
9400 json_neigh, "localRouterId",
9401 inet_ntop(AF_INET, &bgp->router_id, buf1,
9402 sizeof(buf1)));
9403
9404 /* Confederation */
9405 if (CHECK_FLAG(bgp->config, BGP_CONFIG_CONFEDERATION)
9406 && bgp_confederation_peers_check(bgp, p->as))
9407 json_object_boolean_true_add(json_neigh,
9408 "nbrCommonAdmin");
9409
9410 /* Status. */
9411 json_object_string_add(
9412 json_neigh, "bgpState",
9413 lookup_msg(bgp_status_msg, p->status, NULL));
9414
9415 if (p->status == Established) {
9416 time_t uptime;
9417
9418 uptime = bgp_clock();
9419 uptime -= p->uptime;
9420 epoch_tbuf = time(NULL) - uptime;
9421
9422 #if CONFDATE > 20200101
9423 CPP_NOTICE(
9424 "bgpTimerUp should be deprecated and can be removed now");
9425 #endif
9426 /*
9427 * bgpTimerUp was miliseconds that was accurate
9428 * up to 1 day, then the value returned
9429 * became garbage. So in order to provide
9430 * some level of backwards compatability,
9431 * we still provde the data, but now
9432 * we are returning the correct value
9433 * and also adding a new bgpTimerUpMsec
9434 * which will allow us to deprecate
9435 * this eventually
9436 */
9437 json_object_int_add(json_neigh, "bgpTimerUp",
9438 uptime * 1000);
9439 json_object_int_add(json_neigh, "bgpTimerUpMsec",
9440 uptime * 1000);
9441 json_object_string_add(json_neigh, "bgpTimerUpString",
9442 peer_uptime(p->uptime, timebuf,
9443 BGP_UPTIME_LEN, 0,
9444 NULL));
9445 json_object_int_add(json_neigh,
9446 "bgpTimerUpEstablishedEpoch",
9447 epoch_tbuf);
9448 }
9449
9450 else if (p->status == Active) {
9451 if (CHECK_FLAG(p->flags, PEER_FLAG_PASSIVE))
9452 json_object_string_add(json_neigh, "bgpStateIs",
9453 "passive");
9454 else if (CHECK_FLAG(p->sflags, PEER_STATUS_NSF_WAIT))
9455 json_object_string_add(json_neigh, "bgpStateIs",
9456 "passiveNSF");
9457 }
9458
9459 /* read timer */
9460 time_t uptime;
9461 struct tm *tm;
9462
9463 uptime = bgp_clock();
9464 uptime -= p->readtime;
9465 tm = gmtime(&uptime);
9466 json_object_int_add(json_neigh, "bgpTimerLastRead",
9467 (tm->tm_sec * 1000) + (tm->tm_min * 60000)
9468 + (tm->tm_hour * 3600000));
9469
9470 uptime = bgp_clock();
9471 uptime -= p->last_write;
9472 tm = gmtime(&uptime);
9473 json_object_int_add(json_neigh, "bgpTimerLastWrite",
9474 (tm->tm_sec * 1000) + (tm->tm_min * 60000)
9475 + (tm->tm_hour * 3600000));
9476
9477 uptime = bgp_clock();
9478 uptime -= p->update_time;
9479 tm = gmtime(&uptime);
9480 json_object_int_add(json_neigh, "bgpInUpdateElapsedTimeMsecs",
9481 (tm->tm_sec * 1000) + (tm->tm_min * 60000)
9482 + (tm->tm_hour * 3600000));
9483
9484 /* Configured timer values. */
9485 json_object_int_add(json_neigh, "bgpTimerHoldTimeMsecs",
9486 p->v_holdtime * 1000);
9487 json_object_int_add(json_neigh,
9488 "bgpTimerKeepAliveIntervalMsecs",
9489 p->v_keepalive * 1000);
9490 if (CHECK_FLAG(p->flags, PEER_FLAG_TIMER)) {
9491 json_object_int_add(json_neigh,
9492 "bgpTimerConfiguredHoldTimeMsecs",
9493 p->holdtime * 1000);
9494 json_object_int_add(
9495 json_neigh,
9496 "bgpTimerConfiguredKeepAliveIntervalMsecs",
9497 p->keepalive * 1000);
9498 } else if ((bgp->default_holdtime != BGP_DEFAULT_HOLDTIME)
9499 || (bgp->default_keepalive
9500 != BGP_DEFAULT_KEEPALIVE)) {
9501 json_object_int_add(json_neigh,
9502 "bgpTimerConfiguredHoldTimeMsecs",
9503 bgp->default_holdtime);
9504 json_object_int_add(
9505 json_neigh,
9506 "bgpTimerConfiguredKeepAliveIntervalMsecs",
9507 bgp->default_keepalive);
9508 }
9509 } else {
9510 /* Administrative shutdown. */
9511 if (CHECK_FLAG(p->flags, PEER_FLAG_SHUTDOWN))
9512 vty_out(vty, " Administratively shut down\n");
9513
9514 /* BGP Version. */
9515 vty_out(vty, " BGP version 4");
9516 vty_out(vty, ", remote router ID %s",
9517 inet_ntop(AF_INET, &p->remote_id, buf1, sizeof(buf1)));
9518 vty_out(vty, ", local router ID %s\n",
9519 inet_ntop(AF_INET, &bgp->router_id, buf1,
9520 sizeof(buf1)));
9521
9522 /* Confederation */
9523 if (CHECK_FLAG(bgp->config, BGP_CONFIG_CONFEDERATION)
9524 && bgp_confederation_peers_check(bgp, p->as))
9525 vty_out(vty,
9526 " Neighbor under common administration\n");
9527
9528 /* Status. */
9529 vty_out(vty, " BGP state = %s",
9530 lookup_msg(bgp_status_msg, p->status, NULL));
9531
9532 if (p->status == Established)
9533 vty_out(vty, ", up for %8s",
9534 peer_uptime(p->uptime, timebuf, BGP_UPTIME_LEN,
9535 0, NULL));
9536
9537 else if (p->status == Active) {
9538 if (CHECK_FLAG(p->flags, PEER_FLAG_PASSIVE))
9539 vty_out(vty, " (passive)");
9540 else if (CHECK_FLAG(p->sflags, PEER_STATUS_NSF_WAIT))
9541 vty_out(vty, " (NSF passive)");
9542 }
9543 vty_out(vty, "\n");
9544
9545 /* read timer */
9546 vty_out(vty, " Last read %s",
9547 peer_uptime(p->readtime, timebuf, BGP_UPTIME_LEN, 0,
9548 NULL));
9549 vty_out(vty, ", Last write %s\n",
9550 peer_uptime(p->last_write, timebuf, BGP_UPTIME_LEN, 0,
9551 NULL));
9552
9553 /* Configured timer values. */
9554 vty_out(vty,
9555 " Hold time is %d, keepalive interval is %d seconds\n",
9556 p->v_holdtime, p->v_keepalive);
9557 if (CHECK_FLAG(p->flags, PEER_FLAG_TIMER)) {
9558 vty_out(vty, " Configured hold time is %d",
9559 p->holdtime);
9560 vty_out(vty, ", keepalive interval is %d seconds\n",
9561 p->keepalive);
9562 } else if ((bgp->default_holdtime != BGP_DEFAULT_HOLDTIME)
9563 || (bgp->default_keepalive
9564 != BGP_DEFAULT_KEEPALIVE)) {
9565 vty_out(vty, " Configured hold time is %d",
9566 bgp->default_holdtime);
9567 vty_out(vty, ", keepalive interval is %d seconds\n",
9568 bgp->default_keepalive);
9569 }
9570 }
9571 /* Capability. */
9572 if (p->status == Established) {
9573 if (p->cap || p->afc_adv[AFI_IP][SAFI_UNICAST]
9574 || p->afc_recv[AFI_IP][SAFI_UNICAST]
9575 || p->afc_adv[AFI_IP][SAFI_MULTICAST]
9576 || p->afc_recv[AFI_IP][SAFI_MULTICAST]
9577 || p->afc_adv[AFI_IP6][SAFI_UNICAST]
9578 || p->afc_recv[AFI_IP6][SAFI_UNICAST]
9579 || p->afc_adv[AFI_IP6][SAFI_MULTICAST]
9580 || p->afc_recv[AFI_IP6][SAFI_MULTICAST]
9581 || p->afc_adv[AFI_IP6][SAFI_MPLS_VPN]
9582 || p->afc_recv[AFI_IP6][SAFI_MPLS_VPN]
9583 || p->afc_adv[AFI_IP6][SAFI_ENCAP]
9584 || p->afc_recv[AFI_IP6][SAFI_ENCAP]
9585 || p->afc_adv[AFI_IP6][SAFI_FLOWSPEC]
9586 || p->afc_recv[AFI_IP6][SAFI_FLOWSPEC]
9587 || p->afc_adv[AFI_IP][SAFI_ENCAP]
9588 || p->afc_recv[AFI_IP][SAFI_ENCAP]
9589 || p->afc_adv[AFI_IP][SAFI_FLOWSPEC]
9590 || p->afc_recv[AFI_IP][SAFI_FLOWSPEC]
9591 || p->afc_adv[AFI_IP][SAFI_MPLS_VPN]
9592 || p->afc_recv[AFI_IP][SAFI_MPLS_VPN]) {
9593 if (use_json) {
9594 json_object *json_cap = NULL;
9595
9596 json_cap = json_object_new_object();
9597
9598 /* AS4 */
9599 if (CHECK_FLAG(p->cap, PEER_CAP_AS4_RCV)
9600 || CHECK_FLAG(p->cap, PEER_CAP_AS4_ADV)) {
9601 if (CHECK_FLAG(p->cap, PEER_CAP_AS4_ADV)
9602 && CHECK_FLAG(p->cap,
9603 PEER_CAP_AS4_RCV))
9604 json_object_string_add(
9605 json_cap, "4byteAs",
9606 "advertisedAndReceived");
9607 else if (CHECK_FLAG(p->cap,
9608 PEER_CAP_AS4_ADV))
9609 json_object_string_add(
9610 json_cap, "4byteAs",
9611 "advertised");
9612 else if (CHECK_FLAG(p->cap,
9613 PEER_CAP_AS4_RCV))
9614 json_object_string_add(
9615 json_cap, "4byteAs",
9616 "received");
9617 }
9618
9619 /* AddPath */
9620 if (CHECK_FLAG(p->cap, PEER_CAP_ADDPATH_RCV)
9621 || CHECK_FLAG(p->cap,
9622 PEER_CAP_ADDPATH_ADV)) {
9623 json_object *json_add = NULL;
9624 const char *print_store;
9625
9626 json_add = json_object_new_object();
9627
9628 FOREACH_AFI_SAFI (afi, safi) {
9629 json_object *json_sub = NULL;
9630 json_sub =
9631 json_object_new_object();
9632 print_store = afi_safi_print(
9633 afi, safi);
9634
9635 if (CHECK_FLAG(
9636 p->af_cap[afi]
9637 [safi],
9638 PEER_CAP_ADDPATH_AF_TX_ADV)
9639 || CHECK_FLAG(
9640 p->af_cap[afi]
9641 [safi],
9642 PEER_CAP_ADDPATH_AF_TX_RCV)) {
9643 if (CHECK_FLAG(
9644 p->af_cap
9645 [afi]
9646 [safi],
9647 PEER_CAP_ADDPATH_AF_TX_ADV)
9648 && CHECK_FLAG(
9649 p->af_cap
9650 [afi]
9651 [safi],
9652 PEER_CAP_ADDPATH_AF_TX_RCV))
9653 json_object_boolean_true_add(
9654 json_sub,
9655 "txAdvertisedAndReceived");
9656 else if (
9657 CHECK_FLAG(
9658 p->af_cap
9659 [afi]
9660 [safi],
9661 PEER_CAP_ADDPATH_AF_TX_ADV))
9662 json_object_boolean_true_add(
9663 json_sub,
9664 "txAdvertised");
9665 else if (
9666 CHECK_FLAG(
9667 p->af_cap
9668 [afi]
9669 [safi],
9670 PEER_CAP_ADDPATH_AF_TX_RCV))
9671 json_object_boolean_true_add(
9672 json_sub,
9673 "txReceived");
9674 }
9675
9676 if (CHECK_FLAG(
9677 p->af_cap[afi]
9678 [safi],
9679 PEER_CAP_ADDPATH_AF_RX_ADV)
9680 || CHECK_FLAG(
9681 p->af_cap[afi]
9682 [safi],
9683 PEER_CAP_ADDPATH_AF_RX_RCV)) {
9684 if (CHECK_FLAG(
9685 p->af_cap
9686 [afi]
9687 [safi],
9688 PEER_CAP_ADDPATH_AF_RX_ADV)
9689 && CHECK_FLAG(
9690 p->af_cap
9691 [afi]
9692 [safi],
9693 PEER_CAP_ADDPATH_AF_RX_RCV))
9694 json_object_boolean_true_add(
9695 json_sub,
9696 "rxAdvertisedAndReceived");
9697 else if (
9698 CHECK_FLAG(
9699 p->af_cap
9700 [afi]
9701 [safi],
9702 PEER_CAP_ADDPATH_AF_RX_ADV))
9703 json_object_boolean_true_add(
9704 json_sub,
9705 "rxAdvertised");
9706 else if (
9707 CHECK_FLAG(
9708 p->af_cap
9709 [afi]
9710 [safi],
9711 PEER_CAP_ADDPATH_AF_RX_RCV))
9712 json_object_boolean_true_add(
9713 json_sub,
9714 "rxReceived");
9715 }
9716
9717 if (CHECK_FLAG(
9718 p->af_cap[afi]
9719 [safi],
9720 PEER_CAP_ADDPATH_AF_TX_ADV)
9721 || CHECK_FLAG(
9722 p->af_cap[afi]
9723 [safi],
9724 PEER_CAP_ADDPATH_AF_TX_RCV)
9725 || CHECK_FLAG(
9726 p->af_cap[afi]
9727 [safi],
9728 PEER_CAP_ADDPATH_AF_RX_ADV)
9729 || CHECK_FLAG(
9730 p->af_cap[afi]
9731 [safi],
9732 PEER_CAP_ADDPATH_AF_RX_RCV))
9733 json_object_object_add(
9734 json_add,
9735 print_store,
9736 json_sub);
9737 else
9738 json_object_free(
9739 json_sub);
9740 }
9741
9742 json_object_object_add(
9743 json_cap, "addPath", json_add);
9744 }
9745
9746 /* Dynamic */
9747 if (CHECK_FLAG(p->cap, PEER_CAP_DYNAMIC_RCV)
9748 || CHECK_FLAG(p->cap,
9749 PEER_CAP_DYNAMIC_ADV)) {
9750 if (CHECK_FLAG(p->cap,
9751 PEER_CAP_DYNAMIC_ADV)
9752 && CHECK_FLAG(p->cap,
9753 PEER_CAP_DYNAMIC_RCV))
9754 json_object_string_add(
9755 json_cap, "dynamic",
9756 "advertisedAndReceived");
9757 else if (CHECK_FLAG(
9758 p->cap,
9759 PEER_CAP_DYNAMIC_ADV))
9760 json_object_string_add(
9761 json_cap, "dynamic",
9762 "advertised");
9763 else if (CHECK_FLAG(
9764 p->cap,
9765 PEER_CAP_DYNAMIC_RCV))
9766 json_object_string_add(
9767 json_cap, "dynamic",
9768 "received");
9769 }
9770
9771 /* Extended nexthop */
9772 if (CHECK_FLAG(p->cap, PEER_CAP_ENHE_RCV)
9773 || CHECK_FLAG(p->cap, PEER_CAP_ENHE_ADV)) {
9774 json_object *json_nxt = NULL;
9775 const char *print_store;
9776
9777
9778 if (CHECK_FLAG(p->cap,
9779 PEER_CAP_ENHE_ADV)
9780 && CHECK_FLAG(p->cap,
9781 PEER_CAP_ENHE_RCV))
9782 json_object_string_add(
9783 json_cap,
9784 "extendedNexthop",
9785 "advertisedAndReceived");
9786 else if (CHECK_FLAG(p->cap,
9787 PEER_CAP_ENHE_ADV))
9788 json_object_string_add(
9789 json_cap,
9790 "extendedNexthop",
9791 "advertised");
9792 else if (CHECK_FLAG(p->cap,
9793 PEER_CAP_ENHE_RCV))
9794 json_object_string_add(
9795 json_cap,
9796 "extendedNexthop",
9797 "received");
9798
9799 if (CHECK_FLAG(p->cap,
9800 PEER_CAP_ENHE_RCV)) {
9801 json_nxt =
9802 json_object_new_object();
9803
9804 for (safi = SAFI_UNICAST;
9805 safi < SAFI_MAX; safi++) {
9806 if (CHECK_FLAG(
9807 p->af_cap
9808 [AFI_IP]
9809 [safi],
9810 PEER_CAP_ENHE_AF_RCV)) {
9811 print_store = afi_safi_print(
9812 AFI_IP,
9813 safi);
9814 json_object_string_add(
9815 json_nxt,
9816 print_store,
9817 "recieved"); /* misspelled for compatibility */
9818 }
9819 }
9820 json_object_object_add(
9821 json_cap,
9822 "extendedNexthopFamililesByPeer",
9823 json_nxt);
9824 }
9825 }
9826
9827 /* Route Refresh */
9828 if (CHECK_FLAG(p->cap, PEER_CAP_REFRESH_ADV)
9829 || CHECK_FLAG(p->cap,
9830 PEER_CAP_REFRESH_NEW_RCV)
9831 || CHECK_FLAG(p->cap,
9832 PEER_CAP_REFRESH_OLD_RCV)) {
9833 if (CHECK_FLAG(p->cap,
9834 PEER_CAP_REFRESH_ADV)
9835 && (CHECK_FLAG(
9836 p->cap,
9837 PEER_CAP_REFRESH_NEW_RCV)
9838 || CHECK_FLAG(
9839 p->cap,
9840 PEER_CAP_REFRESH_OLD_RCV))) {
9841 if (CHECK_FLAG(
9842 p->cap,
9843 PEER_CAP_REFRESH_OLD_RCV)
9844 && CHECK_FLAG(
9845 p->cap,
9846 PEER_CAP_REFRESH_NEW_RCV))
9847 json_object_string_add(
9848 json_cap,
9849 "routeRefresh",
9850 "advertisedAndReceivedOldNew");
9851 else {
9852 if (CHECK_FLAG(
9853 p->cap,
9854 PEER_CAP_REFRESH_OLD_RCV))
9855 json_object_string_add(
9856 json_cap,
9857 "routeRefresh",
9858 "advertisedAndReceivedOld");
9859 else
9860 json_object_string_add(
9861 json_cap,
9862 "routeRefresh",
9863 "advertisedAndReceivedNew");
9864 }
9865 } else if (
9866 CHECK_FLAG(
9867 p->cap,
9868 PEER_CAP_REFRESH_ADV))
9869 json_object_string_add(
9870 json_cap,
9871 "routeRefresh",
9872 "advertised");
9873 else if (
9874 CHECK_FLAG(
9875 p->cap,
9876 PEER_CAP_REFRESH_NEW_RCV)
9877 || CHECK_FLAG(
9878 p->cap,
9879 PEER_CAP_REFRESH_OLD_RCV))
9880 json_object_string_add(
9881 json_cap,
9882 "routeRefresh",
9883 "received");
9884 }
9885
9886 /* Multiprotocol Extensions */
9887 json_object *json_multi = NULL;
9888 json_multi = json_object_new_object();
9889
9890 FOREACH_AFI_SAFI (afi, safi) {
9891 if (p->afc_adv[afi][safi]
9892 || p->afc_recv[afi][safi]) {
9893 json_object *json_exten = NULL;
9894 json_exten =
9895 json_object_new_object();
9896
9897 if (p->afc_adv[afi][safi]
9898 && p->afc_recv[afi][safi])
9899 json_object_boolean_true_add(
9900 json_exten,
9901 "advertisedAndReceived");
9902 else if (p->afc_adv[afi][safi])
9903 json_object_boolean_true_add(
9904 json_exten,
9905 "advertised");
9906 else if (p->afc_recv[afi][safi])
9907 json_object_boolean_true_add(
9908 json_exten,
9909 "received");
9910
9911 json_object_object_add(
9912 json_multi,
9913 afi_safi_print(afi,
9914 safi),
9915 json_exten);
9916 }
9917 }
9918 json_object_object_add(
9919 json_cap, "multiprotocolExtensions",
9920 json_multi);
9921
9922 /* Hostname capabilities */
9923 json_object *json_hname = NULL;
9924
9925 json_hname = json_object_new_object();
9926
9927 if (CHECK_FLAG(p->cap, PEER_CAP_HOSTNAME_ADV)) {
9928 json_object_string_add(
9929 json_hname, "advHostName",
9930 bgp->peer_self->hostname
9931 ? bgp->peer_self
9932 ->hostname
9933 : "n/a");
9934 json_object_string_add(
9935 json_hname, "advDomainName",
9936 bgp->peer_self->domainname
9937 ? bgp->peer_self
9938 ->domainname
9939 : "n/a");
9940 }
9941
9942
9943 if (CHECK_FLAG(p->cap, PEER_CAP_HOSTNAME_RCV)) {
9944 json_object_string_add(
9945 json_hname, "rcvHostName",
9946 p->hostname ? p->hostname
9947 : "n/a");
9948 json_object_string_add(
9949 json_hname, "rcvDomainName",
9950 p->domainname ? p->domainname
9951 : "n/a");
9952 }
9953
9954 json_object_object_add(json_cap, "hostName",
9955 json_hname);
9956
9957 /* Gracefull Restart */
9958 if (CHECK_FLAG(p->cap, PEER_CAP_RESTART_RCV)
9959 || CHECK_FLAG(p->cap,
9960 PEER_CAP_RESTART_ADV)) {
9961 if (CHECK_FLAG(p->cap,
9962 PEER_CAP_RESTART_ADV)
9963 && CHECK_FLAG(p->cap,
9964 PEER_CAP_RESTART_RCV))
9965 json_object_string_add(
9966 json_cap,
9967 "gracefulRestart",
9968 "advertisedAndReceived");
9969 else if (CHECK_FLAG(
9970 p->cap,
9971 PEER_CAP_RESTART_ADV))
9972 json_object_string_add(
9973 json_cap,
9974 "gracefulRestartCapability",
9975 "advertised");
9976 else if (CHECK_FLAG(
9977 p->cap,
9978 PEER_CAP_RESTART_RCV))
9979 json_object_string_add(
9980 json_cap,
9981 "gracefulRestartCapability",
9982 "received");
9983
9984 if (CHECK_FLAG(p->cap,
9985 PEER_CAP_RESTART_RCV)) {
9986 int restart_af_count = 0;
9987 json_object *json_restart =
9988 NULL;
9989 json_restart =
9990 json_object_new_object();
9991
9992 json_object_int_add(
9993 json_cap,
9994 "gracefulRestartRemoteTimerMsecs",
9995 p->v_gr_restart * 1000);
9996
9997 FOREACH_AFI_SAFI (afi, safi) {
9998 if (CHECK_FLAG(
9999 p->af_cap
10000 [afi]
10001 [safi],
10002 PEER_CAP_RESTART_AF_RCV)) {
10003 json_object *
10004 json_sub =
10005 NULL;
10006 json_sub =
10007 json_object_new_object();
10008
10009 if (CHECK_FLAG(
10010 p->af_cap
10011 [afi]
10012 [safi],
10013 PEER_CAP_RESTART_AF_PRESERVE_RCV))
10014 json_object_boolean_true_add(
10015 json_sub,
10016 "preserved");
10017 restart_af_count++;
10018 json_object_object_add(
10019 json_restart,
10020 afi_safi_print(
10021 afi,
10022 safi),
10023 json_sub);
10024 }
10025 }
10026 if (!restart_af_count) {
10027 json_object_string_add(
10028 json_cap,
10029 "addressFamiliesByPeer",
10030 "none");
10031 json_object_free(
10032 json_restart);
10033 } else
10034 json_object_object_add(
10035 json_cap,
10036 "addressFamiliesByPeer",
10037 json_restart);
10038 }
10039 }
10040 json_object_object_add(json_neigh,
10041 "neighborCapabilities",
10042 json_cap);
10043 } else {
10044 vty_out(vty, " Neighbor capabilities:\n");
10045
10046 /* AS4 */
10047 if (CHECK_FLAG(p->cap, PEER_CAP_AS4_RCV)
10048 || CHECK_FLAG(p->cap, PEER_CAP_AS4_ADV)) {
10049 vty_out(vty, " 4 Byte AS:");
10050 if (CHECK_FLAG(p->cap,
10051 PEER_CAP_AS4_ADV))
10052 vty_out(vty, " advertised");
10053 if (CHECK_FLAG(p->cap,
10054 PEER_CAP_AS4_RCV))
10055 vty_out(vty, " %sreceived",
10056 CHECK_FLAG(
10057 p->cap,
10058 PEER_CAP_AS4_ADV)
10059 ? "and "
10060 : "");
10061 vty_out(vty, "\n");
10062 }
10063
10064 /* AddPath */
10065 if (CHECK_FLAG(p->cap, PEER_CAP_ADDPATH_RCV)
10066 || CHECK_FLAG(p->cap,
10067 PEER_CAP_ADDPATH_ADV)) {
10068 vty_out(vty, " AddPath:\n");
10069
10070 FOREACH_AFI_SAFI (afi, safi) {
10071 if (CHECK_FLAG(
10072 p->af_cap[afi]
10073 [safi],
10074 PEER_CAP_ADDPATH_AF_TX_ADV)
10075 || CHECK_FLAG(
10076 p->af_cap[afi]
10077 [safi],
10078 PEER_CAP_ADDPATH_AF_TX_RCV)) {
10079 vty_out(vty,
10080 " %s: TX ",
10081 afi_safi_print(
10082 afi,
10083 safi));
10084
10085 if (CHECK_FLAG(
10086 p->af_cap
10087 [afi]
10088 [safi],
10089 PEER_CAP_ADDPATH_AF_TX_ADV))
10090 vty_out(vty,
10091 "advertised %s",
10092 afi_safi_print(
10093 afi,
10094 safi));
10095
10096 if (CHECK_FLAG(
10097 p->af_cap
10098 [afi]
10099 [safi],
10100 PEER_CAP_ADDPATH_AF_TX_RCV))
10101 vty_out(vty,
10102 "%sreceived",
10103 CHECK_FLAG(
10104 p->af_cap
10105 [afi]
10106 [safi],
10107 PEER_CAP_ADDPATH_AF_TX_ADV)
10108 ? " and "
10109 : "");
10110
10111 vty_out(vty, "\n");
10112 }
10113
10114 if (CHECK_FLAG(
10115 p->af_cap[afi]
10116 [safi],
10117 PEER_CAP_ADDPATH_AF_RX_ADV)
10118 || CHECK_FLAG(
10119 p->af_cap[afi]
10120 [safi],
10121 PEER_CAP_ADDPATH_AF_RX_RCV)) {
10122 vty_out(vty,
10123 " %s: RX ",
10124 afi_safi_print(
10125 afi,
10126 safi));
10127
10128 if (CHECK_FLAG(
10129 p->af_cap
10130 [afi]
10131 [safi],
10132 PEER_CAP_ADDPATH_AF_RX_ADV))
10133 vty_out(vty,
10134 "advertised %s",
10135 afi_safi_print(
10136 afi,
10137 safi));
10138
10139 if (CHECK_FLAG(
10140 p->af_cap
10141 [afi]
10142 [safi],
10143 PEER_CAP_ADDPATH_AF_RX_RCV))
10144 vty_out(vty,
10145 "%sreceived",
10146 CHECK_FLAG(
10147 p->af_cap
10148 [afi]
10149 [safi],
10150 PEER_CAP_ADDPATH_AF_RX_ADV)
10151 ? " and "
10152 : "");
10153
10154 vty_out(vty, "\n");
10155 }
10156 }
10157 }
10158
10159 /* Dynamic */
10160 if (CHECK_FLAG(p->cap, PEER_CAP_DYNAMIC_RCV)
10161 || CHECK_FLAG(p->cap,
10162 PEER_CAP_DYNAMIC_ADV)) {
10163 vty_out(vty, " Dynamic:");
10164 if (CHECK_FLAG(p->cap,
10165 PEER_CAP_DYNAMIC_ADV))
10166 vty_out(vty, " advertised");
10167 if (CHECK_FLAG(p->cap,
10168 PEER_CAP_DYNAMIC_RCV))
10169 vty_out(vty, " %sreceived",
10170 CHECK_FLAG(
10171 p->cap,
10172 PEER_CAP_DYNAMIC_ADV)
10173 ? "and "
10174 : "");
10175 vty_out(vty, "\n");
10176 }
10177
10178 /* Extended nexthop */
10179 if (CHECK_FLAG(p->cap, PEER_CAP_ENHE_RCV)
10180 || CHECK_FLAG(p->cap, PEER_CAP_ENHE_ADV)) {
10181 vty_out(vty, " Extended nexthop:");
10182 if (CHECK_FLAG(p->cap,
10183 PEER_CAP_ENHE_ADV))
10184 vty_out(vty, " advertised");
10185 if (CHECK_FLAG(p->cap,
10186 PEER_CAP_ENHE_RCV))
10187 vty_out(vty, " %sreceived",
10188 CHECK_FLAG(
10189 p->cap,
10190 PEER_CAP_ENHE_ADV)
10191 ? "and "
10192 : "");
10193 vty_out(vty, "\n");
10194
10195 if (CHECK_FLAG(p->cap,
10196 PEER_CAP_ENHE_RCV)) {
10197 vty_out(vty,
10198 " Address families by peer:\n ");
10199 for (safi = SAFI_UNICAST;
10200 safi < SAFI_MAX; safi++)
10201 if (CHECK_FLAG(
10202 p->af_cap
10203 [AFI_IP]
10204 [safi],
10205 PEER_CAP_ENHE_AF_RCV))
10206 vty_out(vty,
10207 " %s\n",
10208 afi_safi_print(
10209 AFI_IP,
10210 safi));
10211 }
10212 }
10213
10214 /* Route Refresh */
10215 if (CHECK_FLAG(p->cap, PEER_CAP_REFRESH_ADV)
10216 || CHECK_FLAG(p->cap,
10217 PEER_CAP_REFRESH_NEW_RCV)
10218 || CHECK_FLAG(p->cap,
10219 PEER_CAP_REFRESH_OLD_RCV)) {
10220 vty_out(vty, " Route refresh:");
10221 if (CHECK_FLAG(p->cap,
10222 PEER_CAP_REFRESH_ADV))
10223 vty_out(vty, " advertised");
10224 if (CHECK_FLAG(p->cap,
10225 PEER_CAP_REFRESH_NEW_RCV)
10226 || CHECK_FLAG(
10227 p->cap,
10228 PEER_CAP_REFRESH_OLD_RCV))
10229 vty_out(vty, " %sreceived(%s)",
10230 CHECK_FLAG(
10231 p->cap,
10232 PEER_CAP_REFRESH_ADV)
10233 ? "and "
10234 : "",
10235 (CHECK_FLAG(
10236 p->cap,
10237 PEER_CAP_REFRESH_OLD_RCV)
10238 && CHECK_FLAG(
10239 p->cap,
10240 PEER_CAP_REFRESH_NEW_RCV))
10241 ? "old & new"
10242 : CHECK_FLAG(
10243 p->cap,
10244 PEER_CAP_REFRESH_OLD_RCV)
10245 ? "old"
10246 : "new");
10247
10248 vty_out(vty, "\n");
10249 }
10250
10251 /* Multiprotocol Extensions */
10252 FOREACH_AFI_SAFI (afi, safi)
10253 if (p->afc_adv[afi][safi]
10254 || p->afc_recv[afi][safi]) {
10255 vty_out(vty,
10256 " Address Family %s:",
10257 afi_safi_print(afi,
10258 safi));
10259 if (p->afc_adv[afi][safi])
10260 vty_out(vty,
10261 " advertised");
10262 if (p->afc_recv[afi][safi])
10263 vty_out(vty,
10264 " %sreceived",
10265 p->afc_adv[afi]
10266 [safi]
10267 ? "and "
10268 : "");
10269 vty_out(vty, "\n");
10270 }
10271
10272 /* Hostname capability */
10273 vty_out(vty, " Hostname Capability:");
10274
10275 if (CHECK_FLAG(p->cap, PEER_CAP_HOSTNAME_ADV)) {
10276 vty_out(vty,
10277 " advertised (name: %s,domain name: %s)",
10278 bgp->peer_self->hostname
10279 ? bgp->peer_self
10280 ->hostname
10281 : "n/a",
10282 bgp->peer_self->domainname
10283 ? bgp->peer_self
10284 ->domainname
10285 : "n/a");
10286 } else {
10287 vty_out(vty, " not advertised");
10288 }
10289
10290 if (CHECK_FLAG(p->cap, PEER_CAP_HOSTNAME_RCV)) {
10291 vty_out(vty,
10292 " received (name: %s,domain name: %s)",
10293 p->hostname ? p->hostname
10294 : "n/a",
10295 p->domainname ? p->domainname
10296 : "n/a");
10297 } else {
10298 vty_out(vty, " not received");
10299 }
10300
10301 vty_out(vty, "\n");
10302
10303 /* Gracefull Restart */
10304 if (CHECK_FLAG(p->cap, PEER_CAP_RESTART_RCV)
10305 || CHECK_FLAG(p->cap,
10306 PEER_CAP_RESTART_ADV)) {
10307 vty_out(vty,
10308 " Graceful Restart Capabilty:");
10309 if (CHECK_FLAG(p->cap,
10310 PEER_CAP_RESTART_ADV))
10311 vty_out(vty, " advertised");
10312 if (CHECK_FLAG(p->cap,
10313 PEER_CAP_RESTART_RCV))
10314 vty_out(vty, " %sreceived",
10315 CHECK_FLAG(
10316 p->cap,
10317 PEER_CAP_RESTART_ADV)
10318 ? "and "
10319 : "");
10320 vty_out(vty, "\n");
10321
10322 if (CHECK_FLAG(p->cap,
10323 PEER_CAP_RESTART_RCV)) {
10324 int restart_af_count = 0;
10325
10326 vty_out(vty,
10327 " Remote Restart timer is %d seconds\n",
10328 p->v_gr_restart);
10329 vty_out(vty,
10330 " Address families by peer:\n ");
10331
10332 FOREACH_AFI_SAFI (afi, safi)
10333 if (CHECK_FLAG(
10334 p->af_cap
10335 [afi]
10336 [safi],
10337 PEER_CAP_RESTART_AF_RCV)) {
10338 vty_out(vty,
10339 "%s%s(%s)",
10340 restart_af_count
10341 ? ", "
10342 : "",
10343 afi_safi_print(
10344 afi,
10345 safi),
10346 CHECK_FLAG(
10347 p->af_cap
10348 [afi]
10349 [safi],
10350 PEER_CAP_RESTART_AF_PRESERVE_RCV)
10351 ? "preserved"
10352 : "not preserved");
10353 restart_af_count++;
10354 }
10355 if (!restart_af_count)
10356 vty_out(vty, "none");
10357 vty_out(vty, "\n");
10358 }
10359 }
10360 }
10361 }
10362 }
10363
10364 /* graceful restart information */
10365 if (CHECK_FLAG(p->cap, PEER_CAP_RESTART_RCV) || p->t_gr_restart
10366 || p->t_gr_stale) {
10367 json_object *json_grace = NULL;
10368 json_object *json_grace_send = NULL;
10369 json_object *json_grace_recv = NULL;
10370 int eor_send_af_count = 0;
10371 int eor_receive_af_count = 0;
10372
10373 if (use_json) {
10374 json_grace = json_object_new_object();
10375 json_grace_send = json_object_new_object();
10376 json_grace_recv = json_object_new_object();
10377
10378 if (p->status == Established) {
10379 FOREACH_AFI_SAFI (afi, safi) {
10380 if (CHECK_FLAG(p->af_sflags[afi][safi],
10381 PEER_STATUS_EOR_SEND)) {
10382 json_object_boolean_true_add(
10383 json_grace_send,
10384 afi_safi_print(afi,
10385 safi));
10386 eor_send_af_count++;
10387 }
10388 }
10389 FOREACH_AFI_SAFI (afi, safi) {
10390 if (CHECK_FLAG(
10391 p->af_sflags[afi][safi],
10392 PEER_STATUS_EOR_RECEIVED)) {
10393 json_object_boolean_true_add(
10394 json_grace_recv,
10395 afi_safi_print(afi,
10396 safi));
10397 eor_receive_af_count++;
10398 }
10399 }
10400 }
10401
10402 json_object_object_add(json_grace, "endOfRibSend",
10403 json_grace_send);
10404 json_object_object_add(json_grace, "endOfRibRecv",
10405 json_grace_recv);
10406
10407 if (p->t_gr_restart)
10408 json_object_int_add(json_grace,
10409 "gracefulRestartTimerMsecs",
10410 thread_timer_remain_second(
10411 p->t_gr_restart)
10412 * 1000);
10413
10414 if (p->t_gr_stale)
10415 json_object_int_add(
10416 json_grace,
10417 "gracefulStalepathTimerMsecs",
10418 thread_timer_remain_second(
10419 p->t_gr_stale)
10420 * 1000);
10421
10422 json_object_object_add(
10423 json_neigh, "gracefulRestartInfo", json_grace);
10424 } else {
10425 vty_out(vty, " Graceful restart information:\n");
10426 if (p->status == Established) {
10427 vty_out(vty, " End-of-RIB send: ");
10428 FOREACH_AFI_SAFI (afi, safi) {
10429 if (CHECK_FLAG(p->af_sflags[afi][safi],
10430 PEER_STATUS_EOR_SEND)) {
10431 vty_out(vty, "%s%s",
10432 eor_send_af_count ? ", "
10433 : "",
10434 afi_safi_print(afi,
10435 safi));
10436 eor_send_af_count++;
10437 }
10438 }
10439 vty_out(vty, "\n");
10440 vty_out(vty, " End-of-RIB received: ");
10441 FOREACH_AFI_SAFI (afi, safi) {
10442 if (CHECK_FLAG(
10443 p->af_sflags[afi][safi],
10444 PEER_STATUS_EOR_RECEIVED)) {
10445 vty_out(vty, "%s%s",
10446 eor_receive_af_count
10447 ? ", "
10448 : "",
10449 afi_safi_print(afi,
10450 safi));
10451 eor_receive_af_count++;
10452 }
10453 }
10454 vty_out(vty, "\n");
10455 }
10456
10457 if (p->t_gr_restart)
10458 vty_out(vty,
10459 " The remaining time of restart timer is %ld\n",
10460 thread_timer_remain_second(
10461 p->t_gr_restart));
10462
10463 if (p->t_gr_stale)
10464 vty_out(vty,
10465 " The remaining time of stalepath timer is %ld\n",
10466 thread_timer_remain_second(
10467 p->t_gr_stale));
10468 }
10469 }
10470 if (use_json) {
10471 json_object *json_stat = NULL;
10472 json_stat = json_object_new_object();
10473 /* Packet counts. */
10474 json_object_int_add(json_stat, "depthInq", 0);
10475 json_object_int_add(json_stat, "depthOutq",
10476 (unsigned long)p->obuf->count);
10477 json_object_int_add(json_stat, "opensSent",
10478 atomic_load_explicit(&p->open_out,
10479 memory_order_relaxed));
10480 json_object_int_add(json_stat, "opensRecv",
10481 atomic_load_explicit(&p->open_in,
10482 memory_order_relaxed));
10483 json_object_int_add(json_stat, "notificationsSent",
10484 atomic_load_explicit(&p->notify_out,
10485 memory_order_relaxed));
10486 json_object_int_add(json_stat, "notificationsRecv",
10487 atomic_load_explicit(&p->notify_in,
10488 memory_order_relaxed));
10489 json_object_int_add(json_stat, "updatesSent",
10490 atomic_load_explicit(&p->update_out,
10491 memory_order_relaxed));
10492 json_object_int_add(json_stat, "updatesRecv",
10493 atomic_load_explicit(&p->update_in,
10494 memory_order_relaxed));
10495 json_object_int_add(json_stat, "keepalivesSent",
10496 atomic_load_explicit(&p->keepalive_out,
10497 memory_order_relaxed));
10498 json_object_int_add(json_stat, "keepalivesRecv",
10499 atomic_load_explicit(&p->keepalive_in,
10500 memory_order_relaxed));
10501 json_object_int_add(json_stat, "routeRefreshSent",
10502 atomic_load_explicit(&p->refresh_out,
10503 memory_order_relaxed));
10504 json_object_int_add(json_stat, "routeRefreshRecv",
10505 atomic_load_explicit(&p->refresh_in,
10506 memory_order_relaxed));
10507 json_object_int_add(json_stat, "capabilitySent",
10508 atomic_load_explicit(&p->dynamic_cap_out,
10509 memory_order_relaxed));
10510 json_object_int_add(json_stat, "capabilityRecv",
10511 atomic_load_explicit(&p->dynamic_cap_in,
10512 memory_order_relaxed));
10513 json_object_int_add(json_stat, "totalSent", PEER_TOTAL_TX(p));
10514 json_object_int_add(json_stat, "totalRecv", PEER_TOTAL_RX(p));
10515 json_object_object_add(json_neigh, "messageStats", json_stat);
10516 } else {
10517 /* Packet counts. */
10518 vty_out(vty, " Message statistics:\n");
10519 vty_out(vty, " Inq depth is 0\n");
10520 vty_out(vty, " Outq depth is %lu\n",
10521 (unsigned long)p->obuf->count);
10522 vty_out(vty, " Sent Rcvd\n");
10523 vty_out(vty, " Opens: %10d %10d\n",
10524 atomic_load_explicit(&p->open_out,
10525 memory_order_relaxed),
10526 atomic_load_explicit(&p->open_in,
10527 memory_order_relaxed));
10528 vty_out(vty, " Notifications: %10d %10d\n",
10529 atomic_load_explicit(&p->notify_out,
10530 memory_order_relaxed),
10531 atomic_load_explicit(&p->notify_in,
10532 memory_order_relaxed));
10533 vty_out(vty, " Updates: %10d %10d\n",
10534 atomic_load_explicit(&p->update_out,
10535 memory_order_relaxed),
10536 atomic_load_explicit(&p->update_in,
10537 memory_order_relaxed));
10538 vty_out(vty, " Keepalives: %10d %10d\n",
10539 atomic_load_explicit(&p->keepalive_out,
10540 memory_order_relaxed),
10541 atomic_load_explicit(&p->keepalive_in,
10542 memory_order_relaxed));
10543 vty_out(vty, " Route Refresh: %10d %10d\n",
10544 atomic_load_explicit(&p->refresh_out,
10545 memory_order_relaxed),
10546 atomic_load_explicit(&p->refresh_in,
10547 memory_order_relaxed));
10548 vty_out(vty, " Capability: %10d %10d\n",
10549 atomic_load_explicit(&p->dynamic_cap_out,
10550 memory_order_relaxed),
10551 atomic_load_explicit(&p->dynamic_cap_in,
10552 memory_order_relaxed));
10553 vty_out(vty, " Total: %10d %10d\n", PEER_TOTAL_TX(p),
10554 PEER_TOTAL_RX(p));
10555 }
10556
10557 if (use_json) {
10558 /* advertisement-interval */
10559 json_object_int_add(json_neigh,
10560 "minBtwnAdvertisementRunsTimerMsecs",
10561 p->v_routeadv * 1000);
10562
10563 /* Update-source. */
10564 if (p->update_if || p->update_source) {
10565 if (p->update_if)
10566 json_object_string_add(json_neigh,
10567 "updateSource",
10568 p->update_if);
10569 else if (p->update_source)
10570 json_object_string_add(
10571 json_neigh, "updateSource",
10572 sockunion2str(p->update_source, buf1,
10573 SU_ADDRSTRLEN));
10574 }
10575 } else {
10576 /* advertisement-interval */
10577 vty_out(vty,
10578 " Minimum time between advertisement runs is %d seconds\n",
10579 p->v_routeadv);
10580
10581 /* Update-source. */
10582 if (p->update_if || p->update_source) {
10583 vty_out(vty, " Update source is ");
10584 if (p->update_if)
10585 vty_out(vty, "%s", p->update_if);
10586 else if (p->update_source)
10587 vty_out(vty, "%s",
10588 sockunion2str(p->update_source, buf1,
10589 SU_ADDRSTRLEN));
10590 vty_out(vty, "\n");
10591 }
10592
10593 vty_out(vty, "\n");
10594 }
10595
10596 /* Address Family Information */
10597 json_object *json_hold = NULL;
10598
10599 if (use_json)
10600 json_hold = json_object_new_object();
10601
10602 FOREACH_AFI_SAFI (afi, safi)
10603 if (p->afc[afi][safi])
10604 bgp_show_peer_afi(vty, p, afi, safi, use_json,
10605 json_hold);
10606
10607 if (use_json) {
10608 json_object_object_add(json_neigh, "addressFamilyInfo",
10609 json_hold);
10610 json_object_int_add(json_neigh, "connectionsEstablished",
10611 p->established);
10612 json_object_int_add(json_neigh, "connectionsDropped",
10613 p->dropped);
10614 } else
10615 vty_out(vty, " Connections established %d; dropped %d\n",
10616 p->established, p->dropped);
10617
10618 if (!p->last_reset) {
10619 if (use_json)
10620 json_object_string_add(json_neigh, "lastReset",
10621 "never");
10622 else
10623 vty_out(vty, " Last reset never\n");
10624 } else {
10625 if (use_json) {
10626 time_t uptime;
10627 struct tm *tm;
10628
10629 uptime = bgp_clock();
10630 uptime -= p->resettime;
10631 tm = gmtime(&uptime);
10632 json_object_int_add(json_neigh, "lastResetTimerMsecs",
10633 (tm->tm_sec * 1000)
10634 + (tm->tm_min * 60000)
10635 + (tm->tm_hour * 3600000));
10636 json_object_string_add(
10637 json_neigh, "lastResetDueTo",
10638 peer_down_str[(int)p->last_reset]);
10639 if (p->last_reset == PEER_DOWN_NOTIFY_SEND
10640 || p->last_reset == PEER_DOWN_NOTIFY_RECEIVED) {
10641 char errorcodesubcode_hexstr[5];
10642 char errorcodesubcode_str[256];
10643
10644 code_str = bgp_notify_code_str(p->notify.code);
10645 subcode_str = bgp_notify_subcode_str(
10646 p->notify.code, p->notify.subcode);
10647
10648 sprintf(errorcodesubcode_hexstr, "%02X%02X",
10649 p->notify.code, p->notify.subcode);
10650 json_object_string_add(json_neigh,
10651 "lastErrorCodeSubcode",
10652 errorcodesubcode_hexstr);
10653 snprintf(errorcodesubcode_str, 255, "%s%s",
10654 code_str, subcode_str);
10655 json_object_string_add(json_neigh,
10656 "lastNotificationReason",
10657 errorcodesubcode_str);
10658 if (p->last_reset == PEER_DOWN_NOTIFY_RECEIVED
10659 && p->notify.code == BGP_NOTIFY_CEASE
10660 && (p->notify.subcode
10661 == BGP_NOTIFY_CEASE_ADMIN_SHUTDOWN
10662 || p->notify.subcode
10663 == BGP_NOTIFY_CEASE_ADMIN_RESET)
10664 && p->notify.length) {
10665 char msgbuf[1024];
10666 const char *msg_str;
10667
10668 msg_str = bgp_notify_admin_message(
10669 msgbuf, sizeof(msgbuf),
10670 (uint8_t *)p->notify.data,
10671 p->notify.length);
10672 if (msg_str)
10673 json_object_string_add(
10674 json_neigh,
10675 "lastShutdownDescription",
10676 msg_str);
10677 }
10678 }
10679 } else {
10680 vty_out(vty, " Last reset %s, ",
10681 peer_uptime(p->resettime, timebuf,
10682 BGP_UPTIME_LEN, 0, NULL));
10683
10684 if (p->last_reset == PEER_DOWN_NOTIFY_SEND
10685 || p->last_reset == PEER_DOWN_NOTIFY_RECEIVED) {
10686 code_str = bgp_notify_code_str(p->notify.code);
10687 subcode_str = bgp_notify_subcode_str(
10688 p->notify.code, p->notify.subcode);
10689 vty_out(vty, "due to NOTIFICATION %s (%s%s)\n",
10690 p->last_reset == PEER_DOWN_NOTIFY_SEND
10691 ? "sent"
10692 : "received",
10693 code_str, subcode_str);
10694 if (p->last_reset == PEER_DOWN_NOTIFY_RECEIVED
10695 && p->notify.code == BGP_NOTIFY_CEASE
10696 && (p->notify.subcode
10697 == BGP_NOTIFY_CEASE_ADMIN_SHUTDOWN
10698 || p->notify.subcode
10699 == BGP_NOTIFY_CEASE_ADMIN_RESET)
10700 && p->notify.length) {
10701 char msgbuf[1024];
10702 const char *msg_str;
10703
10704 msg_str = bgp_notify_admin_message(
10705 msgbuf, sizeof(msgbuf),
10706 (uint8_t *)p->notify.data,
10707 p->notify.length);
10708 if (msg_str)
10709 vty_out(vty,
10710 " Message: \"%s\"\n",
10711 msg_str);
10712 }
10713 } else {
10714 vty_out(vty, "due to %s\n",
10715 peer_down_str[(int)p->last_reset]);
10716 }
10717
10718 if (p->last_reset_cause_size) {
10719 msg = p->last_reset_cause;
10720 vty_out(vty,
10721 " Message received that caused BGP to send a NOTIFICATION:\n ");
10722 for (i = 1; i <= p->last_reset_cause_size;
10723 i++) {
10724 vty_out(vty, "%02X", *msg++);
10725
10726 if (i != p->last_reset_cause_size) {
10727 if (i % 16 == 0) {
10728 vty_out(vty, "\n ");
10729 } else if (i % 4 == 0) {
10730 vty_out(vty, " ");
10731 }
10732 }
10733 }
10734 vty_out(vty, "\n");
10735 }
10736 }
10737 }
10738
10739 if (CHECK_FLAG(p->sflags, PEER_STATUS_PREFIX_OVERFLOW)) {
10740 if (use_json)
10741 json_object_boolean_true_add(json_neigh,
10742 "prefixesConfigExceedMax");
10743 else
10744 vty_out(vty,
10745 " Peer had exceeded the max. no. of prefixes configured.\n");
10746
10747 if (p->t_pmax_restart) {
10748 if (use_json) {
10749 json_object_boolean_true_add(
10750 json_neigh, "reducePrefixNumFrom");
10751 json_object_int_add(json_neigh,
10752 "restartInTimerMsec",
10753 thread_timer_remain_second(
10754 p->t_pmax_restart)
10755 * 1000);
10756 } else
10757 vty_out(vty,
10758 " Reduce the no. of prefix from %s, will restart in %ld seconds\n",
10759 p->host, thread_timer_remain_second(
10760 p->t_pmax_restart));
10761 } else {
10762 if (use_json)
10763 json_object_boolean_true_add(
10764 json_neigh,
10765 "reducePrefixNumAndClearIpBgp");
10766 else
10767 vty_out(vty,
10768 " Reduce the no. of prefix and clear ip bgp %s to restore peering\n",
10769 p->host);
10770 }
10771 }
10772
10773 /* EBGP Multihop and GTSM */
10774 if (p->sort != BGP_PEER_IBGP) {
10775 if (use_json) {
10776 if (p->gtsm_hops > 0)
10777 json_object_int_add(json_neigh,
10778 "externalBgpNbrMaxHopsAway",
10779 p->gtsm_hops);
10780 else if (p->ttl > 1)
10781 json_object_int_add(json_neigh,
10782 "externalBgpNbrMaxHopsAway",
10783 p->ttl);
10784 } else {
10785 if (p->gtsm_hops > 0)
10786 vty_out(vty,
10787 " External BGP neighbor may be up to %d hops away.\n",
10788 p->gtsm_hops);
10789 else if (p->ttl > 1)
10790 vty_out(vty,
10791 " External BGP neighbor may be up to %d hops away.\n",
10792 p->ttl);
10793 }
10794 } else {
10795 if (p->gtsm_hops > 0) {
10796 if (use_json)
10797 json_object_int_add(json_neigh,
10798 "internalBgpNbrMaxHopsAway",
10799 p->gtsm_hops);
10800 else
10801 vty_out(vty,
10802 " Internal BGP neighbor may be up to %d hops away.\n",
10803 p->gtsm_hops);
10804 }
10805 }
10806
10807 /* Local address. */
10808 if (p->su_local) {
10809 if (use_json) {
10810 json_object_string_add(json_neigh, "hostLocal",
10811 sockunion2str(p->su_local, buf1,
10812 SU_ADDRSTRLEN));
10813 json_object_int_add(json_neigh, "portLocal",
10814 ntohs(p->su_local->sin.sin_port));
10815 } else
10816 vty_out(vty, "Local host: %s, Local port: %d\n",
10817 sockunion2str(p->su_local, buf1, SU_ADDRSTRLEN),
10818 ntohs(p->su_local->sin.sin_port));
10819 }
10820
10821 /* Remote address. */
10822 if (p->su_remote) {
10823 if (use_json) {
10824 json_object_string_add(json_neigh, "hostForeign",
10825 sockunion2str(p->su_remote, buf1,
10826 SU_ADDRSTRLEN));
10827 json_object_int_add(json_neigh, "portForeign",
10828 ntohs(p->su_remote->sin.sin_port));
10829 } else
10830 vty_out(vty, "Foreign host: %s, Foreign port: %d\n",
10831 sockunion2str(p->su_remote, buf1,
10832 SU_ADDRSTRLEN),
10833 ntohs(p->su_remote->sin.sin_port));
10834 }
10835
10836 /* Nexthop display. */
10837 if (p->su_local) {
10838 if (use_json) {
10839 json_object_string_add(json_neigh, "nexthop",
10840 inet_ntop(AF_INET,
10841 &p->nexthop.v4, buf1,
10842 sizeof(buf1)));
10843 json_object_string_add(json_neigh, "nexthopGlobal",
10844 inet_ntop(AF_INET6,
10845 &p->nexthop.v6_global,
10846 buf1, sizeof(buf1)));
10847 json_object_string_add(json_neigh, "nexthopLocal",
10848 inet_ntop(AF_INET6,
10849 &p->nexthop.v6_local,
10850 buf1, sizeof(buf1)));
10851 if (p->shared_network)
10852 json_object_string_add(json_neigh,
10853 "bgpConnection",
10854 "sharedNetwork");
10855 else
10856 json_object_string_add(json_neigh,
10857 "bgpConnection",
10858 "nonSharedNetwork");
10859 } else {
10860 vty_out(vty, "Nexthop: %s\n",
10861 inet_ntop(AF_INET, &p->nexthop.v4, buf1,
10862 sizeof(buf1)));
10863 vty_out(vty, "Nexthop global: %s\n",
10864 inet_ntop(AF_INET6, &p->nexthop.v6_global, buf1,
10865 sizeof(buf1)));
10866 vty_out(vty, "Nexthop local: %s\n",
10867 inet_ntop(AF_INET6, &p->nexthop.v6_local, buf1,
10868 sizeof(buf1)));
10869 vty_out(vty, "BGP connection: %s\n",
10870 p->shared_network ? "shared network"
10871 : "non shared network");
10872 }
10873 }
10874
10875 /* Timer information. */
10876 if (use_json) {
10877 json_object_int_add(json_neigh, "connectRetryTimer",
10878 p->v_connect);
10879 if (p->status == Established && p->rtt)
10880 json_object_int_add(json_neigh, "estimatedRttInMsecs",
10881 p->rtt);
10882 if (p->t_start)
10883 json_object_int_add(
10884 json_neigh, "nextStartTimerDueInMsecs",
10885 thread_timer_remain_second(p->t_start) * 1000);
10886 if (p->t_connect)
10887 json_object_int_add(
10888 json_neigh, "nextConnectTimerDueInMsecs",
10889 thread_timer_remain_second(p->t_connect)
10890 * 1000);
10891 if (p->t_routeadv) {
10892 json_object_int_add(json_neigh, "mraiInterval",
10893 p->v_routeadv);
10894 json_object_int_add(
10895 json_neigh, "mraiTimerExpireInMsecs",
10896 thread_timer_remain_second(p->t_routeadv)
10897 * 1000);
10898 }
10899 if (p->password)
10900 json_object_int_add(json_neigh, "authenticationEnabled",
10901 1);
10902
10903 if (p->t_read)
10904 json_object_string_add(json_neigh, "readThread", "on");
10905 else
10906 json_object_string_add(json_neigh, "readThread", "off");
10907
10908 if (CHECK_FLAG(p->thread_flags, PEER_THREAD_WRITES_ON))
10909 json_object_string_add(json_neigh, "writeThread", "on");
10910 else
10911 json_object_string_add(json_neigh, "writeThread",
10912 "off");
10913 } else {
10914 vty_out(vty, "BGP Connect Retry Timer in Seconds: %d\n",
10915 p->v_connect);
10916 if (p->status == Established && p->rtt)
10917 vty_out(vty, "Estimated round trip time: %d ms\n",
10918 p->rtt);
10919 if (p->t_start)
10920 vty_out(vty, "Next start timer due in %ld seconds\n",
10921 thread_timer_remain_second(p->t_start));
10922 if (p->t_connect)
10923 vty_out(vty, "Next connect timer due in %ld seconds\n",
10924 thread_timer_remain_second(p->t_connect));
10925 if (p->t_routeadv)
10926 vty_out(vty,
10927 "MRAI (interval %u) timer expires in %ld seconds\n",
10928 p->v_routeadv,
10929 thread_timer_remain_second(p->t_routeadv));
10930 if (p->password)
10931 vty_out(vty, "Peer Authentication Enabled\n");
10932
10933 vty_out(vty, "Read thread: %s Write thread: %s\n",
10934 p->t_read ? "on" : "off",
10935 CHECK_FLAG(p->thread_flags, PEER_THREAD_WRITES_ON)
10936 ? "on"
10937 : "off");
10938 }
10939
10940 if (p->notify.code == BGP_NOTIFY_OPEN_ERR
10941 && p->notify.subcode == BGP_NOTIFY_OPEN_UNSUP_CAPBL)
10942 bgp_capability_vty_out(vty, p, use_json, json_neigh);
10943
10944 if (!use_json)
10945 vty_out(vty, "\n");
10946
10947 /* BFD information. */
10948 bgp_bfd_show_info(vty, p, use_json, json_neigh);
10949
10950 if (use_json) {
10951 if (p->conf_if) /* Configured interface name. */
10952 json_object_object_add(json, p->conf_if, json_neigh);
10953 else /* Configured IP address. */
10954 json_object_object_add(json, p->host, json_neigh);
10955 }
10956 }
10957
10958 static int bgp_show_neighbor(struct vty *vty, struct bgp *bgp,
10959 enum show_type type, union sockunion *su,
10960 const char *conf_if, bool use_json,
10961 json_object *json)
10962 {
10963 struct listnode *node, *nnode;
10964 struct peer *peer;
10965 int find = 0;
10966 bool nbr_output = false;
10967 afi_t afi = AFI_MAX;
10968 safi_t safi = SAFI_MAX;
10969
10970 if (type == show_ipv4_peer || type == show_ipv4_all) {
10971 afi = AFI_IP;
10972 } else if (type == show_ipv6_peer || type == show_ipv6_all) {
10973 afi = AFI_IP6;
10974 }
10975
10976 for (ALL_LIST_ELEMENTS(bgp->peer, node, nnode, peer)) {
10977 if (!CHECK_FLAG(peer->flags, PEER_FLAG_CONFIG_NODE))
10978 continue;
10979
10980 switch (type) {
10981 case show_all:
10982 bgp_show_peer(vty, peer, use_json, json);
10983 nbr_output = true;
10984 break;
10985 case show_peer:
10986 if (conf_if) {
10987 if ((peer->conf_if
10988 && !strcmp(peer->conf_if, conf_if))
10989 || (peer->hostname
10990 && !strcmp(peer->hostname, conf_if))) {
10991 find = 1;
10992 bgp_show_peer(vty, peer, use_json,
10993 json);
10994 }
10995 } else {
10996 if (sockunion_same(&peer->su, su)) {
10997 find = 1;
10998 bgp_show_peer(vty, peer, use_json,
10999 json);
11000 }
11001 }
11002 break;
11003 case show_ipv4_peer:
11004 case show_ipv6_peer:
11005 FOREACH_SAFI (safi) {
11006 if (peer->afc[afi][safi]) {
11007 if (conf_if) {
11008 if ((peer->conf_if
11009 && !strcmp(peer->conf_if, conf_if))
11010 || (peer->hostname
11011 && !strcmp(peer->hostname, conf_if))) {
11012 find = 1;
11013 bgp_show_peer(vty, peer, use_json,
11014 json);
11015 break;
11016 }
11017 } else {
11018 if (sockunion_same(&peer->su, su)) {
11019 find = 1;
11020 bgp_show_peer(vty, peer, use_json,
11021 json);
11022 break;
11023 }
11024 }
11025 }
11026 }
11027 break;
11028 case show_ipv4_all:
11029 case show_ipv6_all:
11030 FOREACH_SAFI (safi) {
11031 if (peer->afc[afi][safi]) {
11032 bgp_show_peer(vty, peer, use_json, json);
11033 nbr_output = true;
11034 break;
11035 }
11036 }
11037 break;
11038 }
11039 }
11040
11041 if ((type == show_peer || type == show_ipv4_peer ||
11042 type == show_ipv6_peer) && !find) {
11043 if (use_json)
11044 json_object_boolean_true_add(json, "bgpNoSuchNeighbor");
11045 else
11046 vty_out(vty, "%% No such neighbor in this view/vrf\n");
11047 }
11048
11049 if (type != show_peer && type != show_ipv4_peer &&
11050 type != show_ipv6_peer && !nbr_output && !use_json)
11051 vty_out(vty, "%% No BGP neighbors found\n");
11052
11053 if (use_json) {
11054 vty_out(vty, "%s\n", json_object_to_json_string_ext(
11055 json, JSON_C_TO_STRING_PRETTY));
11056 } else {
11057 vty_out(vty, "\n");
11058 }
11059
11060 return CMD_SUCCESS;
11061 }
11062
11063 static void bgp_show_all_instances_neighbors_vty(struct vty *vty,
11064 enum show_type type,
11065 const char *ip_str,
11066 bool use_json)
11067 {
11068 struct listnode *node, *nnode;
11069 struct bgp *bgp;
11070 union sockunion su;
11071 json_object *json = NULL;
11072 int ret, is_first = 1;
11073 bool nbr_output = false;
11074
11075 if (use_json)
11076 vty_out(vty, "{\n");
11077
11078 for (ALL_LIST_ELEMENTS(bm->bgp, node, nnode, bgp)) {
11079 nbr_output = true;
11080 if (use_json) {
11081 if (!(json = json_object_new_object())) {
11082 flog_err(
11083 EC_BGP_JSON_MEM_ERROR,
11084 "Unable to allocate memory for JSON object");
11085 vty_out(vty,
11086 "{\"error\": {\"message:\": \"Unable to allocate memory for JSON object\"}}}\n");
11087 return;
11088 }
11089
11090 json_object_int_add(json, "vrfId",
11091 (bgp->vrf_id == VRF_UNKNOWN)
11092 ? -1
11093 : (int64_t)bgp->vrf_id);
11094 json_object_string_add(
11095 json, "vrfName",
11096 (bgp->inst_type == BGP_INSTANCE_TYPE_DEFAULT)
11097 ? VRF_DEFAULT_NAME
11098 : bgp->name);
11099
11100 if (!is_first)
11101 vty_out(vty, ",\n");
11102 else
11103 is_first = 0;
11104
11105 vty_out(vty, "\"%s\":",
11106 (bgp->inst_type == BGP_INSTANCE_TYPE_DEFAULT)
11107 ? VRF_DEFAULT_NAME
11108 : bgp->name);
11109 } else {
11110 vty_out(vty, "\nInstance %s:\n",
11111 (bgp->inst_type == BGP_INSTANCE_TYPE_DEFAULT)
11112 ? VRF_DEFAULT_NAME
11113 : bgp->name);
11114 }
11115
11116 if (type == show_peer || type == show_ipv4_peer ||
11117 type == show_ipv6_peer) {
11118 ret = str2sockunion(ip_str, &su);
11119 if (ret < 0)
11120 bgp_show_neighbor(vty, bgp, type, NULL, ip_str,
11121 use_json, json);
11122 else
11123 bgp_show_neighbor(vty, bgp, type, &su, NULL,
11124 use_json, json);
11125 } else {
11126 bgp_show_neighbor(vty, bgp, type, NULL, NULL,
11127 use_json, json);
11128 }
11129 json_object_free(json);
11130 }
11131
11132 if (use_json) {
11133 vty_out(vty, "}\n");
11134 json_object_free(json);
11135 }
11136 else if (!nbr_output)
11137 vty_out(vty, "%% BGP instance not found\n");
11138 }
11139
11140 static int bgp_show_neighbor_vty(struct vty *vty, const char *name,
11141 enum show_type type, const char *ip_str,
11142 bool use_json)
11143 {
11144 int ret;
11145 struct bgp *bgp;
11146 union sockunion su;
11147 json_object *json = NULL;
11148
11149 if (name) {
11150 if (strmatch(name, "all")) {
11151 bgp_show_all_instances_neighbors_vty(vty, type, ip_str,
11152 use_json);
11153 return CMD_SUCCESS;
11154 } else {
11155 bgp = bgp_lookup_by_name(name);
11156 if (!bgp) {
11157 if (use_json) {
11158 json = json_object_new_object();
11159 vty_out(vty, "%s\n",
11160 json_object_to_json_string_ext(
11161 json,
11162 JSON_C_TO_STRING_PRETTY));
11163 json_object_free(json);
11164 } else
11165 vty_out(vty,
11166 "%% BGP instance not found\n");
11167
11168 return CMD_WARNING;
11169 }
11170 }
11171 } else {
11172 bgp = bgp_get_default();
11173 }
11174
11175 if (bgp) {
11176 json = json_object_new_object();
11177 if (ip_str) {
11178 ret = str2sockunion(ip_str, &su);
11179 if (ret < 0)
11180 bgp_show_neighbor(vty, bgp, type, NULL, ip_str,
11181 use_json, json);
11182 else
11183 bgp_show_neighbor(vty, bgp, type, &su, NULL,
11184 use_json, json);
11185 } else {
11186 bgp_show_neighbor(vty, bgp, type, NULL, NULL, use_json,
11187 json);
11188 }
11189 json_object_free(json);
11190 } else {
11191 if (use_json)
11192 vty_out(vty, "{}\n");
11193 else
11194 vty_out(vty, "%% BGP instance not found\n");
11195 }
11196
11197 return CMD_SUCCESS;
11198 }
11199
11200 /* "show [ip] bgp neighbors" commands. */
11201 DEFUN (show_ip_bgp_neighbors,
11202 show_ip_bgp_neighbors_cmd,
11203 "show [ip] bgp [<view|vrf> VIEWVRFNAME] [<ipv4|ipv6>] neighbors [<A.B.C.D|X:X::X:X|WORD>] [json]",
11204 SHOW_STR
11205 IP_STR
11206 BGP_STR
11207 BGP_INSTANCE_HELP_STR
11208 "Address Family\n"
11209 "Address Family\n"
11210 "Detailed information on TCP and BGP neighbor connections\n"
11211 "Neighbor to display information about\n"
11212 "Neighbor to display information about\n"
11213 "Neighbor on BGP configured interface\n"
11214 JSON_STR)
11215 {
11216 char *vrf = NULL;
11217 char *sh_arg = NULL;
11218 enum show_type sh_type;
11219 afi_t afi = AFI_MAX;
11220
11221 bool uj = use_json(argc, argv);
11222
11223 int idx = 0;
11224
11225 /* [<vrf> VIEWVRFNAME] */
11226 if (argv_find(argv, argc, "vrf", &idx)) {
11227 vrf = argv[idx + 1]->arg;
11228 if (vrf && strmatch(vrf, VRF_DEFAULT_NAME))
11229 vrf = NULL;
11230 } else if (argv_find(argv, argc, "view", &idx))
11231 /* [<view> VIEWVRFNAME] */
11232 vrf = argv[idx + 1]->arg;
11233
11234 idx++;
11235
11236 if (argv_find(argv, argc, "ipv4", &idx)) {
11237 sh_type = show_ipv4_all;
11238 afi = AFI_IP;
11239 } else if (argv_find(argv, argc, "ipv6", &idx)) {
11240 sh_type = show_ipv6_all;
11241 afi = AFI_IP6;
11242 } else {
11243 sh_type = show_all;
11244 }
11245
11246 if (argv_find(argv, argc, "A.B.C.D", &idx)
11247 || argv_find(argv, argc, "X:X::X:X", &idx)
11248 || argv_find(argv, argc, "WORD", &idx)) {
11249 sh_type = show_peer;
11250 sh_arg = argv[idx]->arg;
11251 }
11252
11253 if (sh_type == show_peer && afi == AFI_IP) {
11254 sh_type = show_ipv4_peer;
11255 } else if (sh_type == show_peer && afi == AFI_IP6) {
11256 sh_type = show_ipv6_peer;
11257 }
11258
11259 return bgp_show_neighbor_vty(vty, vrf, sh_type, sh_arg, uj);
11260 }
11261
11262 /* Show BGP's AS paths internal data. There are both `show [ip] bgp
11263 paths' and `show ip mbgp paths'. Those functions results are the
11264 same.*/
11265 DEFUN (show_ip_bgp_paths,
11266 show_ip_bgp_paths_cmd,
11267 "show [ip] bgp ["BGP_SAFI_CMD_STR"] paths",
11268 SHOW_STR
11269 IP_STR
11270 BGP_STR
11271 BGP_SAFI_HELP_STR
11272 "Path information\n")
11273 {
11274 vty_out(vty, "Address Refcnt Path\n");
11275 aspath_print_all_vty(vty);
11276 return CMD_SUCCESS;
11277 }
11278
11279 #include "hash.h"
11280
11281 static void community_show_all_iterator(struct hash_bucket *bucket,
11282 struct vty *vty)
11283 {
11284 struct community *com;
11285
11286 com = (struct community *)bucket->data;
11287 vty_out(vty, "[%p] (%ld) %s\n", (void *)com, com->refcnt,
11288 community_str(com, false));
11289 }
11290
11291 /* Show BGP's community internal data. */
11292 DEFUN (show_ip_bgp_community_info,
11293 show_ip_bgp_community_info_cmd,
11294 "show [ip] bgp community-info",
11295 SHOW_STR
11296 IP_STR
11297 BGP_STR
11298 "List all bgp community information\n")
11299 {
11300 vty_out(vty, "Address Refcnt Community\n");
11301
11302 hash_iterate(community_hash(),
11303 (void (*)(struct hash_bucket *,
11304 void *))community_show_all_iterator,
11305 vty);
11306
11307 return CMD_SUCCESS;
11308 }
11309
11310 static void lcommunity_show_all_iterator(struct hash_bucket *bucket,
11311 struct vty *vty)
11312 {
11313 struct lcommunity *lcom;
11314
11315 lcom = (struct lcommunity *)bucket->data;
11316 vty_out(vty, "[%p] (%ld) %s\n", (void *)lcom, lcom->refcnt,
11317 lcommunity_str(lcom, false));
11318 }
11319
11320 /* Show BGP's community internal data. */
11321 DEFUN (show_ip_bgp_lcommunity_info,
11322 show_ip_bgp_lcommunity_info_cmd,
11323 "show ip bgp large-community-info",
11324 SHOW_STR
11325 IP_STR
11326 BGP_STR
11327 "List all bgp large-community information\n")
11328 {
11329 vty_out(vty, "Address Refcnt Large-community\n");
11330
11331 hash_iterate(lcommunity_hash(),
11332 (void (*)(struct hash_bucket *,
11333 void *))lcommunity_show_all_iterator,
11334 vty);
11335
11336 return CMD_SUCCESS;
11337 }
11338
11339
11340 DEFUN (show_ip_bgp_attr_info,
11341 show_ip_bgp_attr_info_cmd,
11342 "show [ip] bgp attribute-info",
11343 SHOW_STR
11344 IP_STR
11345 BGP_STR
11346 "List all bgp attribute information\n")
11347 {
11348 attr_show_all(vty);
11349 return CMD_SUCCESS;
11350 }
11351
11352 static int bgp_show_route_leak_vty(struct vty *vty, const char *name,
11353 afi_t afi, safi_t safi,
11354 bool use_json, json_object *json)
11355 {
11356 struct bgp *bgp;
11357 struct listnode *node;
11358 char *vname;
11359 char buf1[INET6_ADDRSTRLEN];
11360 char *ecom_str;
11361 vpn_policy_direction_t dir;
11362
11363 if (json) {
11364 json_object *json_import_vrfs = NULL;
11365 json_object *json_export_vrfs = NULL;
11366
11367 bgp = name ? bgp_lookup_by_name(name) : bgp_get_default();
11368
11369 if (!bgp) {
11370 vty_out(vty, "%s\n",
11371 json_object_to_json_string_ext(
11372 json,
11373 JSON_C_TO_STRING_PRETTY));
11374 json_object_free(json);
11375
11376 return CMD_WARNING;
11377 }
11378
11379 /* Provide context for the block */
11380 json_object_string_add(json, "vrf", name ? name : "default");
11381 json_object_string_add(json, "afiSafi",
11382 afi_safi_print(afi, safi));
11383
11384 if (!CHECK_FLAG(bgp->af_flags[afi][safi],
11385 BGP_CONFIG_VRF_TO_VRF_IMPORT)) {
11386 json_object_string_add(json, "importFromVrfs", "none");
11387 json_object_string_add(json, "importRts", "none");
11388 } else {
11389 json_import_vrfs = json_object_new_array();
11390
11391 for (ALL_LIST_ELEMENTS_RO(
11392 bgp->vpn_policy[afi].import_vrf,
11393 node, vname))
11394 json_object_array_add(json_import_vrfs,
11395 json_object_new_string(vname));
11396
11397 dir = BGP_VPN_POLICY_DIR_FROMVPN;
11398 ecom_str = ecommunity_ecom2str(
11399 bgp->vpn_policy[afi].rtlist[dir],
11400 ECOMMUNITY_FORMAT_ROUTE_MAP, 0);
11401 json_object_object_add(json, "importFromVrfs",
11402 json_import_vrfs);
11403 json_object_string_add(json, "importRts", ecom_str);
11404
11405 XFREE(MTYPE_ECOMMUNITY_STR, ecom_str);
11406 }
11407
11408 if (!CHECK_FLAG(bgp->af_flags[afi][safi],
11409 BGP_CONFIG_VRF_TO_VRF_EXPORT)) {
11410 json_object_string_add(json, "exportToVrfs", "none");
11411 json_object_string_add(json, "routeDistinguisher",
11412 "none");
11413 json_object_string_add(json, "exportRts", "none");
11414 } else {
11415 json_export_vrfs = json_object_new_array();
11416
11417 for (ALL_LIST_ELEMENTS_RO(
11418 bgp->vpn_policy[afi].export_vrf,
11419 node, vname))
11420 json_object_array_add(json_export_vrfs,
11421 json_object_new_string(vname));
11422 json_object_object_add(json, "exportToVrfs",
11423 json_export_vrfs);
11424 json_object_string_add(json, "routeDistinguisher",
11425 prefix_rd2str(&bgp->vpn_policy[afi].tovpn_rd,
11426 buf1, RD_ADDRSTRLEN));
11427
11428 dir = BGP_VPN_POLICY_DIR_TOVPN;
11429 ecom_str = ecommunity_ecom2str(
11430 bgp->vpn_policy[afi].rtlist[dir],
11431 ECOMMUNITY_FORMAT_ROUTE_MAP, 0);
11432 json_object_string_add(json, "exportRts", ecom_str);
11433
11434 XFREE(MTYPE_ECOMMUNITY_STR, ecom_str);
11435 }
11436
11437 if (use_json) {
11438 vty_out(vty, "%s\n",
11439 json_object_to_json_string_ext(json,
11440 JSON_C_TO_STRING_PRETTY));
11441 json_object_free(json);
11442 }
11443 } else {
11444 bgp = name ? bgp_lookup_by_name(name) : bgp_get_default();
11445
11446 if (!bgp) {
11447 vty_out(vty, "%% No such BGP instance exist\n");
11448 return CMD_WARNING;
11449 }
11450
11451 if (!CHECK_FLAG(bgp->af_flags[afi][safi],
11452 BGP_CONFIG_VRF_TO_VRF_IMPORT))
11453 vty_out(vty,
11454 "This VRF is not importing %s routes from any other VRF\n",
11455 afi_safi_print(afi, safi));
11456 else {
11457 vty_out(vty,
11458 "This VRF is importing %s routes from the following VRFs:\n",
11459 afi_safi_print(afi, safi));
11460
11461 for (ALL_LIST_ELEMENTS_RO(
11462 bgp->vpn_policy[afi].import_vrf,
11463 node, vname))
11464 vty_out(vty, " %s\n", vname);
11465
11466 dir = BGP_VPN_POLICY_DIR_FROMVPN;
11467 ecom_str = ecommunity_ecom2str(
11468 bgp->vpn_policy[afi].rtlist[dir],
11469 ECOMMUNITY_FORMAT_ROUTE_MAP, 0);
11470 vty_out(vty, "Import RT(s): %s\n", ecom_str);
11471
11472 XFREE(MTYPE_ECOMMUNITY_STR, ecom_str);
11473 }
11474
11475 if (!CHECK_FLAG(bgp->af_flags[afi][safi],
11476 BGP_CONFIG_VRF_TO_VRF_EXPORT))
11477 vty_out(vty,
11478 "This VRF is not exporting %s routes to any other VRF\n",
11479 afi_safi_print(afi, safi));
11480 else {
11481 vty_out(vty,
11482 "This VRF is exporting %s routes to the following VRFs:\n",
11483 afi_safi_print(afi, safi));
11484
11485 for (ALL_LIST_ELEMENTS_RO(
11486 bgp->vpn_policy[afi].export_vrf,
11487 node, vname))
11488 vty_out(vty, " %s\n", vname);
11489
11490 vty_out(vty, "RD: %s\n",
11491 prefix_rd2str(&bgp->vpn_policy[afi].tovpn_rd,
11492 buf1, RD_ADDRSTRLEN));
11493
11494 dir = BGP_VPN_POLICY_DIR_TOVPN;
11495 ecom_str = ecommunity_ecom2str(
11496 bgp->vpn_policy[afi].rtlist[dir],
11497 ECOMMUNITY_FORMAT_ROUTE_MAP, 0);
11498 vty_out(vty, "Export RT: %s\n", ecom_str);
11499 XFREE(MTYPE_ECOMMUNITY_STR, ecom_str);
11500 }
11501 }
11502
11503 return CMD_SUCCESS;
11504 }
11505
11506 static int bgp_show_all_instance_route_leak_vty(struct vty *vty, afi_t afi,
11507 safi_t safi, bool use_json)
11508 {
11509 struct listnode *node, *nnode;
11510 struct bgp *bgp;
11511 char *vrf_name = NULL;
11512 json_object *json = NULL;
11513 json_object *json_vrf = NULL;
11514 json_object *json_vrfs = NULL;
11515
11516 if (use_json) {
11517 json = json_object_new_object();
11518 json_vrfs = json_object_new_object();
11519 }
11520
11521 for (ALL_LIST_ELEMENTS(bm->bgp, node, nnode, bgp)) {
11522
11523 if (bgp->inst_type != BGP_INSTANCE_TYPE_DEFAULT)
11524 vrf_name = bgp->name;
11525
11526 if (use_json) {
11527 json_vrf = json_object_new_object();
11528 } else {
11529 vty_out(vty, "\nInstance %s:\n",
11530 (bgp->inst_type == BGP_INSTANCE_TYPE_DEFAULT)
11531 ? VRF_DEFAULT_NAME : bgp->name);
11532 }
11533 bgp_show_route_leak_vty(vty, vrf_name, afi, safi, 0, json_vrf);
11534 if (use_json) {
11535 if (bgp->inst_type == BGP_INSTANCE_TYPE_DEFAULT)
11536 json_object_object_add(json_vrfs,
11537 VRF_DEFAULT_NAME, json_vrf);
11538 else
11539 json_object_object_add(json_vrfs, vrf_name,
11540 json_vrf);
11541 }
11542 }
11543
11544 if (use_json) {
11545 json_object_object_add(json, "vrfs", json_vrfs);
11546 vty_out(vty, "%s\n", json_object_to_json_string_ext(json,
11547 JSON_C_TO_STRING_PRETTY));
11548 json_object_free(json);
11549 }
11550
11551 return CMD_SUCCESS;
11552 }
11553
11554 /* "show [ip] bgp route-leak" command. */
11555 DEFUN (show_ip_bgp_route_leak,
11556 show_ip_bgp_route_leak_cmd,
11557 "show [ip] bgp [<view|vrf> VIEWVRFNAME] ["BGP_AFI_CMD_STR" ["BGP_SAFI_CMD_STR"]] route-leak [json]",
11558 SHOW_STR
11559 IP_STR
11560 BGP_STR
11561 BGP_INSTANCE_HELP_STR
11562 BGP_AFI_HELP_STR
11563 BGP_SAFI_HELP_STR
11564 "Route leaking information\n"
11565 JSON_STR)
11566 {
11567 char *vrf = NULL;
11568 afi_t afi = AFI_MAX;
11569 safi_t safi = SAFI_MAX;
11570
11571 bool uj = use_json(argc, argv);
11572 int idx = 0;
11573 json_object *json = NULL;
11574
11575 /* show [ip] bgp */
11576 if (argv_find(argv, argc, "ip", &idx)) {
11577 afi = AFI_IP;
11578 safi = SAFI_UNICAST;
11579 }
11580 /* [vrf VIEWVRFNAME] */
11581 if (argv_find(argv, argc, "view", &idx)) {
11582 vty_out(vty,
11583 "%% This command is not applicable to BGP views\n");
11584 return CMD_WARNING;
11585 }
11586
11587 if (argv_find(argv, argc, "vrf", &idx)) {
11588 vrf = argv[idx + 1]->arg;
11589 if (vrf && strmatch(vrf, VRF_DEFAULT_NAME))
11590 vrf = NULL;
11591 }
11592 /* ["BGP_AFI_CMD_STR" ["BGP_SAFI_CMD_STR"]] */
11593 if (argv_find_and_parse_afi(argv, argc, &idx, &afi)) {
11594 argv_find_and_parse_safi(argv, argc, &idx, &safi);
11595 }
11596
11597 if (!((afi == AFI_IP || afi == AFI_IP6) && safi == SAFI_UNICAST)) {
11598 vty_out(vty,
11599 "%% This command is applicable only for unicast ipv4|ipv6\n");
11600 return CMD_WARNING;
11601 }
11602
11603 if (vrf && strmatch(vrf, "all"))
11604 return bgp_show_all_instance_route_leak_vty(vty, afi, safi, uj);
11605
11606 if (uj)
11607 json = json_object_new_object();
11608
11609 return bgp_show_route_leak_vty(vty, vrf, afi, safi, uj, json);
11610 }
11611
11612 static void bgp_show_all_instances_updgrps_vty(struct vty *vty, afi_t afi,
11613 safi_t safi)
11614 {
11615 struct listnode *node, *nnode;
11616 struct bgp *bgp;
11617
11618 for (ALL_LIST_ELEMENTS(bm->bgp, node, nnode, bgp)) {
11619 vty_out(vty, "\nInstance %s:\n",
11620 (bgp->inst_type == BGP_INSTANCE_TYPE_DEFAULT)
11621 ? VRF_DEFAULT_NAME
11622 : bgp->name);
11623 update_group_show(bgp, afi, safi, vty, 0);
11624 }
11625 }
11626
11627 static int bgp_show_update_groups(struct vty *vty, const char *name, int afi,
11628 int safi, uint64_t subgrp_id)
11629 {
11630 struct bgp *bgp;
11631
11632 if (name) {
11633 if (strmatch(name, "all")) {
11634 bgp_show_all_instances_updgrps_vty(vty, afi, safi);
11635 return CMD_SUCCESS;
11636 } else {
11637 bgp = bgp_lookup_by_name(name);
11638 }
11639 } else {
11640 bgp = bgp_get_default();
11641 }
11642
11643 if (bgp)
11644 update_group_show(bgp, afi, safi, vty, subgrp_id);
11645 return CMD_SUCCESS;
11646 }
11647
11648 DEFUN (show_ip_bgp_updgrps,
11649 show_ip_bgp_updgrps_cmd,
11650 "show [ip] bgp [<view|vrf> VIEWVRFNAME] ["BGP_AFI_CMD_STR" ["BGP_SAFI_WITH_LABEL_CMD_STR"]] update-groups [SUBGROUP-ID]",
11651 SHOW_STR
11652 IP_STR
11653 BGP_STR
11654 BGP_INSTANCE_HELP_STR
11655 BGP_AFI_HELP_STR
11656 BGP_SAFI_WITH_LABEL_HELP_STR
11657 "Detailed info about dynamic update groups\n"
11658 "Specific subgroup to display detailed info for\n")
11659 {
11660 char *vrf = NULL;
11661 afi_t afi = AFI_IP6;
11662 safi_t safi = SAFI_UNICAST;
11663 uint64_t subgrp_id = 0;
11664
11665 int idx = 0;
11666
11667 /* show [ip] bgp */
11668 if (argv_find(argv, argc, "ip", &idx))
11669 afi = AFI_IP;
11670 /* [<vrf> VIEWVRFNAME] */
11671 if (argv_find(argv, argc, "vrf", &idx)) {
11672 vrf = argv[idx + 1]->arg;
11673 if (vrf && strmatch(vrf, VRF_DEFAULT_NAME))
11674 vrf = NULL;
11675 } else if (argv_find(argv, argc, "view", &idx))
11676 /* [<view> VIEWVRFNAME] */
11677 vrf = argv[idx + 1]->arg;
11678 /* ["BGP_AFI_CMD_STR" ["BGP_SAFI_CMD_STR"]] */
11679 if (argv_find_and_parse_afi(argv, argc, &idx, &afi)) {
11680 argv_find_and_parse_safi(argv, argc, &idx, &safi);
11681 }
11682
11683 /* get subgroup id, if provided */
11684 idx = argc - 1;
11685 if (argv[idx]->type == VARIABLE_TKN)
11686 subgrp_id = strtoull(argv[idx]->arg, NULL, 10);
11687
11688 return (bgp_show_update_groups(vty, vrf, afi, safi, subgrp_id));
11689 }
11690
11691 DEFUN (show_bgp_instance_all_ipv6_updgrps,
11692 show_bgp_instance_all_ipv6_updgrps_cmd,
11693 "show [ip] bgp <view|vrf> all update-groups",
11694 SHOW_STR
11695 IP_STR
11696 BGP_STR
11697 BGP_INSTANCE_ALL_HELP_STR
11698 "Detailed info about dynamic update groups\n")
11699 {
11700 bgp_show_all_instances_updgrps_vty(vty, AFI_IP6, SAFI_UNICAST);
11701 return CMD_SUCCESS;
11702 }
11703
11704 DEFUN (show_bgp_l2vpn_evpn_updgrps,
11705 show_bgp_l2vpn_evpn_updgrps_cmd,
11706 "show [ip] bgp l2vpn evpn update-groups",
11707 SHOW_STR
11708 IP_STR
11709 BGP_STR
11710 "l2vpn address family\n"
11711 "evpn sub-address family\n"
11712 "Detailed info about dynamic update groups\n")
11713 {
11714 char *vrf = NULL;
11715 uint64_t subgrp_id = 0;
11716
11717 bgp_show_update_groups(vty, vrf, AFI_L2VPN, SAFI_EVPN, subgrp_id);
11718 return CMD_SUCCESS;
11719 }
11720
11721 DEFUN (show_bgp_updgrps_stats,
11722 show_bgp_updgrps_stats_cmd,
11723 "show [ip] bgp update-groups statistics",
11724 SHOW_STR
11725 IP_STR
11726 BGP_STR
11727 "Detailed info about dynamic update groups\n"
11728 "Statistics\n")
11729 {
11730 struct bgp *bgp;
11731
11732 bgp = bgp_get_default();
11733 if (bgp)
11734 update_group_show_stats(bgp, vty);
11735
11736 return CMD_SUCCESS;
11737 }
11738
11739 DEFUN (show_bgp_instance_updgrps_stats,
11740 show_bgp_instance_updgrps_stats_cmd,
11741 "show [ip] bgp <view|vrf> VIEWVRFNAME update-groups statistics",
11742 SHOW_STR
11743 IP_STR
11744 BGP_STR
11745 BGP_INSTANCE_HELP_STR
11746 "Detailed info about dynamic update groups\n"
11747 "Statistics\n")
11748 {
11749 int idx_word = 3;
11750 struct bgp *bgp;
11751
11752 bgp = bgp_lookup_by_name(argv[idx_word]->arg);
11753 if (bgp)
11754 update_group_show_stats(bgp, vty);
11755
11756 return CMD_SUCCESS;
11757 }
11758
11759 static void show_bgp_updgrps_adj_info_aux(struct vty *vty, const char *name,
11760 afi_t afi, safi_t safi,
11761 const char *what, uint64_t subgrp_id)
11762 {
11763 struct bgp *bgp;
11764
11765 if (name)
11766 bgp = bgp_lookup_by_name(name);
11767 else
11768 bgp = bgp_get_default();
11769
11770 if (bgp) {
11771 if (!strcmp(what, "advertise-queue"))
11772 update_group_show_adj_queue(bgp, afi, safi, vty,
11773 subgrp_id);
11774 else if (!strcmp(what, "advertised-routes"))
11775 update_group_show_advertised(bgp, afi, safi, vty,
11776 subgrp_id);
11777 else if (!strcmp(what, "packet-queue"))
11778 update_group_show_packet_queue(bgp, afi, safi, vty,
11779 subgrp_id);
11780 }
11781 }
11782
11783 DEFPY(show_ip_bgp_instance_updgrps_adj_s,
11784 show_ip_bgp_instance_updgrps_adj_s_cmd,
11785 "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",
11786 SHOW_STR IP_STR BGP_STR BGP_INSTANCE_HELP_STR BGP_AFI_HELP_STR
11787 BGP_SAFI_HELP_STR
11788 "Detailed info about dynamic update groups\n"
11789 "Specific subgroup to display info for\n"
11790 "Advertisement queue\n"
11791 "Announced routes\n"
11792 "Packet queue\n")
11793 {
11794 uint64_t subgrp_id = 0;
11795 afi_t afiz;
11796 safi_t safiz;
11797 if (sgid)
11798 subgrp_id = strtoull(sgid, NULL, 10);
11799
11800 if (!ip && !afi)
11801 afiz = AFI_IP6;
11802 if (!ip && afi)
11803 afiz = bgp_vty_afi_from_str(afi);
11804 if (ip && !afi)
11805 afiz = AFI_IP;
11806 if (ip && afi) {
11807 afiz = bgp_vty_afi_from_str(afi);
11808 if (afiz != AFI_IP)
11809 vty_out(vty,
11810 "%% Cannot specify both 'ip' and 'ipv6'\n");
11811 return CMD_WARNING;
11812 }
11813
11814 safiz = safi ? bgp_vty_safi_from_str(safi) : SAFI_UNICAST;
11815
11816 show_bgp_updgrps_adj_info_aux(vty, vrf, afiz, safiz, rtq, subgrp_id);
11817 return CMD_SUCCESS;
11818 }
11819
11820 static int bgp_show_one_peer_group(struct vty *vty, struct peer_group *group)
11821 {
11822 struct listnode *node, *nnode;
11823 struct prefix *range;
11824 struct peer *conf;
11825 struct peer *peer;
11826 char buf[PREFIX2STR_BUFFER];
11827 afi_t afi;
11828 safi_t safi;
11829 const char *peer_status;
11830 const char *af_str;
11831 int lr_count;
11832 int dynamic;
11833 int af_cfgd;
11834
11835 conf = group->conf;
11836
11837 if (conf->as_type == AS_SPECIFIED || conf->as_type == AS_EXTERNAL) {
11838 vty_out(vty, "\nBGP peer-group %s, remote AS %" PRIu32 "\n",
11839 group->name, conf->as);
11840 } else if (conf->as_type == AS_INTERNAL) {
11841 vty_out(vty, "\nBGP peer-group %s, remote AS %" PRIu32 "\n",
11842 group->name, group->bgp->as);
11843 } else {
11844 vty_out(vty, "\nBGP peer-group %s\n", group->name);
11845 }
11846
11847 if ((group->bgp->as == conf->as) || (conf->as_type == AS_INTERNAL))
11848 vty_out(vty, " Peer-group type is internal\n");
11849 else
11850 vty_out(vty, " Peer-group type is external\n");
11851
11852 /* Display AFs configured. */
11853 vty_out(vty, " Configured address-families:");
11854 FOREACH_AFI_SAFI (afi, safi) {
11855 if (conf->afc[afi][safi]) {
11856 af_cfgd = 1;
11857 vty_out(vty, " %s;", afi_safi_print(afi, safi));
11858 }
11859 }
11860 if (!af_cfgd)
11861 vty_out(vty, " none\n");
11862 else
11863 vty_out(vty, "\n");
11864
11865 /* Display listen ranges (for dynamic neighbors), if any */
11866 for (afi = AFI_IP; afi < AFI_MAX; afi++) {
11867 if (afi == AFI_IP)
11868 af_str = "IPv4";
11869 else if (afi == AFI_IP6)
11870 af_str = "IPv6";
11871 else
11872 af_str = "???";
11873 lr_count = listcount(group->listen_range[afi]);
11874 if (lr_count) {
11875 vty_out(vty, " %d %s listen range(s)\n", lr_count,
11876 af_str);
11877
11878
11879 for (ALL_LIST_ELEMENTS(group->listen_range[afi], node,
11880 nnode, range)) {
11881 prefix2str(range, buf, sizeof(buf));
11882 vty_out(vty, " %s\n", buf);
11883 }
11884 }
11885 }
11886
11887 /* Display group members and their status */
11888 if (listcount(group->peer)) {
11889 vty_out(vty, " Peer-group members:\n");
11890 for (ALL_LIST_ELEMENTS(group->peer, node, nnode, peer)) {
11891 if (CHECK_FLAG(peer->flags, PEER_FLAG_SHUTDOWN))
11892 peer_status = "Idle (Admin)";
11893 else if (CHECK_FLAG(peer->sflags,
11894 PEER_STATUS_PREFIX_OVERFLOW))
11895 peer_status = "Idle (PfxCt)";
11896 else
11897 peer_status = lookup_msg(bgp_status_msg,
11898 peer->status, NULL);
11899
11900 dynamic = peer_dynamic_neighbor(peer);
11901 vty_out(vty, " %s %s %s \n", peer->host,
11902 dynamic ? "(dynamic)" : "", peer_status);
11903 }
11904 }
11905
11906 return CMD_SUCCESS;
11907 }
11908
11909 static int bgp_show_peer_group_vty(struct vty *vty, const char *name,
11910 const char *group_name)
11911 {
11912 struct bgp *bgp;
11913 struct listnode *node, *nnode;
11914 struct peer_group *group;
11915 bool found = false;
11916
11917 bgp = name ? bgp_lookup_by_name(name) : bgp_get_default();
11918
11919 if (!bgp) {
11920 vty_out(vty, "%% BGP instance not found\n");
11921 return CMD_WARNING;
11922 }
11923
11924 for (ALL_LIST_ELEMENTS(bgp->group, node, nnode, group)) {
11925 if (group_name) {
11926 if (strmatch(group->name, group_name)) {
11927 bgp_show_one_peer_group(vty, group);
11928 found = true;
11929 break;
11930 }
11931 } else {
11932 bgp_show_one_peer_group(vty, group);
11933 }
11934 }
11935
11936 if (group_name && !found)
11937 vty_out(vty, "%% No such peer-group\n");
11938
11939 return CMD_SUCCESS;
11940 }
11941
11942 DEFUN (show_ip_bgp_peer_groups,
11943 show_ip_bgp_peer_groups_cmd,
11944 "show [ip] bgp [<view|vrf> VIEWVRFNAME] peer-group [PGNAME]",
11945 SHOW_STR
11946 IP_STR
11947 BGP_STR
11948 BGP_INSTANCE_HELP_STR
11949 "Detailed information on BGP peer groups\n"
11950 "Peer group name\n")
11951 {
11952 char *vrf, *pg;
11953 int idx = 0;
11954
11955 vrf = argv_find(argv, argc, "VIEWVRFNAME", &idx) ? argv[idx]->arg
11956 : NULL;
11957 pg = argv_find(argv, argc, "PGNAME", &idx) ? argv[idx]->arg : NULL;
11958
11959 return bgp_show_peer_group_vty(vty, vrf, pg);
11960 }
11961
11962
11963 /* Redistribute VTY commands. */
11964
11965 DEFUN (bgp_redistribute_ipv4,
11966 bgp_redistribute_ipv4_cmd,
11967 "redistribute " FRR_IP_REDIST_STR_BGPD,
11968 "Redistribute information from another routing protocol\n"
11969 FRR_IP_REDIST_HELP_STR_BGPD)
11970 {
11971 VTY_DECLVAR_CONTEXT(bgp, bgp);
11972 int idx_protocol = 1;
11973 int type;
11974
11975 type = proto_redistnum(AFI_IP, argv[idx_protocol]->text);
11976 if (type < 0) {
11977 vty_out(vty, "%% Invalid route type\n");
11978 return CMD_WARNING_CONFIG_FAILED;
11979 }
11980
11981 bgp_redist_add(bgp, AFI_IP, type, 0);
11982 return bgp_redistribute_set(bgp, AFI_IP, type, 0, false);
11983 }
11984
11985 ALIAS_HIDDEN(
11986 bgp_redistribute_ipv4, bgp_redistribute_ipv4_hidden_cmd,
11987 "redistribute " FRR_IP_REDIST_STR_BGPD,
11988 "Redistribute information from another routing protocol\n" FRR_IP_REDIST_HELP_STR_BGPD)
11989
11990 DEFUN (bgp_redistribute_ipv4_rmap,
11991 bgp_redistribute_ipv4_rmap_cmd,
11992 "redistribute " FRR_IP_REDIST_STR_BGPD " route-map WORD",
11993 "Redistribute information from another routing protocol\n"
11994 FRR_IP_REDIST_HELP_STR_BGPD
11995 "Route map reference\n"
11996 "Pointer to route-map entries\n")
11997 {
11998 VTY_DECLVAR_CONTEXT(bgp, bgp);
11999 int idx_protocol = 1;
12000 int idx_word = 3;
12001 int type;
12002 struct bgp_redist *red;
12003 bool changed;
12004 struct route_map *route_map = route_map_lookup_warn_noexist(
12005 vty, argv[idx_word]->arg);
12006
12007 type = proto_redistnum(AFI_IP, argv[idx_protocol]->text);
12008 if (type < 0) {
12009 vty_out(vty, "%% Invalid route type\n");
12010 return CMD_WARNING_CONFIG_FAILED;
12011 }
12012
12013 red = bgp_redist_add(bgp, AFI_IP, type, 0);
12014 changed =
12015 bgp_redistribute_rmap_set(red, argv[idx_word]->arg, route_map);
12016 return bgp_redistribute_set(bgp, AFI_IP, type, 0, changed);
12017 }
12018
12019 ALIAS_HIDDEN(
12020 bgp_redistribute_ipv4_rmap, bgp_redistribute_ipv4_rmap_hidden_cmd,
12021 "redistribute " FRR_IP_REDIST_STR_BGPD " route-map WORD",
12022 "Redistribute information from another routing protocol\n" FRR_IP_REDIST_HELP_STR_BGPD
12023 "Route map reference\n"
12024 "Pointer to route-map entries\n")
12025
12026 DEFUN (bgp_redistribute_ipv4_metric,
12027 bgp_redistribute_ipv4_metric_cmd,
12028 "redistribute " FRR_IP_REDIST_STR_BGPD " metric (0-4294967295)",
12029 "Redistribute information from another routing protocol\n"
12030 FRR_IP_REDIST_HELP_STR_BGPD
12031 "Metric for redistributed routes\n"
12032 "Default metric\n")
12033 {
12034 VTY_DECLVAR_CONTEXT(bgp, bgp);
12035 int idx_protocol = 1;
12036 int idx_number = 3;
12037 int type;
12038 uint32_t metric;
12039 struct bgp_redist *red;
12040 bool changed;
12041
12042 type = proto_redistnum(AFI_IP, argv[idx_protocol]->text);
12043 if (type < 0) {
12044 vty_out(vty, "%% Invalid route type\n");
12045 return CMD_WARNING_CONFIG_FAILED;
12046 }
12047 metric = strtoul(argv[idx_number]->arg, NULL, 10);
12048
12049 red = bgp_redist_add(bgp, AFI_IP, type, 0);
12050 changed = bgp_redistribute_metric_set(bgp, red, AFI_IP, type, metric);
12051 return bgp_redistribute_set(bgp, AFI_IP, type, 0, changed);
12052 }
12053
12054 ALIAS_HIDDEN(
12055 bgp_redistribute_ipv4_metric, bgp_redistribute_ipv4_metric_hidden_cmd,
12056 "redistribute " FRR_IP_REDIST_STR_BGPD " metric (0-4294967295)",
12057 "Redistribute information from another routing protocol\n" FRR_IP_REDIST_HELP_STR_BGPD
12058 "Metric for redistributed routes\n"
12059 "Default metric\n")
12060
12061 DEFUN (bgp_redistribute_ipv4_rmap_metric,
12062 bgp_redistribute_ipv4_rmap_metric_cmd,
12063 "redistribute " FRR_IP_REDIST_STR_BGPD " route-map WORD metric (0-4294967295)",
12064 "Redistribute information from another routing protocol\n"
12065 FRR_IP_REDIST_HELP_STR_BGPD
12066 "Route map reference\n"
12067 "Pointer to route-map entries\n"
12068 "Metric for redistributed routes\n"
12069 "Default metric\n")
12070 {
12071 VTY_DECLVAR_CONTEXT(bgp, bgp);
12072 int idx_protocol = 1;
12073 int idx_word = 3;
12074 int idx_number = 5;
12075 int type;
12076 uint32_t metric;
12077 struct bgp_redist *red;
12078 bool changed;
12079 struct route_map *route_map =
12080 route_map_lookup_warn_noexist(vty, argv[idx_word]->arg);
12081
12082 type = proto_redistnum(AFI_IP, argv[idx_protocol]->text);
12083 if (type < 0) {
12084 vty_out(vty, "%% Invalid route type\n");
12085 return CMD_WARNING_CONFIG_FAILED;
12086 }
12087 metric = strtoul(argv[idx_number]->arg, NULL, 10);
12088
12089 red = bgp_redist_add(bgp, AFI_IP, type, 0);
12090 changed =
12091 bgp_redistribute_rmap_set(red, argv[idx_word]->arg, route_map);
12092 changed |= bgp_redistribute_metric_set(bgp, red, AFI_IP, type, metric);
12093 return bgp_redistribute_set(bgp, AFI_IP, type, 0, changed);
12094 }
12095
12096 ALIAS_HIDDEN(
12097 bgp_redistribute_ipv4_rmap_metric,
12098 bgp_redistribute_ipv4_rmap_metric_hidden_cmd,
12099 "redistribute " FRR_IP_REDIST_STR_BGPD
12100 " route-map WORD metric (0-4294967295)",
12101 "Redistribute information from another routing protocol\n" FRR_IP_REDIST_HELP_STR_BGPD
12102 "Route map reference\n"
12103 "Pointer to route-map entries\n"
12104 "Metric for redistributed routes\n"
12105 "Default metric\n")
12106
12107 DEFUN (bgp_redistribute_ipv4_metric_rmap,
12108 bgp_redistribute_ipv4_metric_rmap_cmd,
12109 "redistribute " FRR_IP_REDIST_STR_BGPD " metric (0-4294967295) route-map WORD",
12110 "Redistribute information from another routing protocol\n"
12111 FRR_IP_REDIST_HELP_STR_BGPD
12112 "Metric for redistributed routes\n"
12113 "Default metric\n"
12114 "Route map reference\n"
12115 "Pointer to route-map entries\n")
12116 {
12117 VTY_DECLVAR_CONTEXT(bgp, bgp);
12118 int idx_protocol = 1;
12119 int idx_number = 3;
12120 int idx_word = 5;
12121 int type;
12122 uint32_t metric;
12123 struct bgp_redist *red;
12124 bool changed;
12125 struct route_map *route_map =
12126 route_map_lookup_warn_noexist(vty, argv[idx_word]->arg);
12127
12128 type = proto_redistnum(AFI_IP, argv[idx_protocol]->text);
12129 if (type < 0) {
12130 vty_out(vty, "%% Invalid route type\n");
12131 return CMD_WARNING_CONFIG_FAILED;
12132 }
12133 metric = strtoul(argv[idx_number]->arg, NULL, 10);
12134
12135 red = bgp_redist_add(bgp, AFI_IP, type, 0);
12136 changed = bgp_redistribute_metric_set(bgp, red, AFI_IP, type, metric);
12137 changed |=
12138 bgp_redistribute_rmap_set(red, argv[idx_word]->arg, route_map);
12139 return bgp_redistribute_set(bgp, AFI_IP, type, 0, changed);
12140 }
12141
12142 ALIAS_HIDDEN(
12143 bgp_redistribute_ipv4_metric_rmap,
12144 bgp_redistribute_ipv4_metric_rmap_hidden_cmd,
12145 "redistribute " FRR_IP_REDIST_STR_BGPD
12146 " metric (0-4294967295) route-map WORD",
12147 "Redistribute information from another routing protocol\n" FRR_IP_REDIST_HELP_STR_BGPD
12148 "Metric for redistributed routes\n"
12149 "Default metric\n"
12150 "Route map reference\n"
12151 "Pointer to route-map entries\n")
12152
12153 DEFUN (bgp_redistribute_ipv4_ospf,
12154 bgp_redistribute_ipv4_ospf_cmd,
12155 "redistribute <ospf|table> (1-65535)",
12156 "Redistribute information from another routing protocol\n"
12157 "Open Shortest Path First (OSPFv2)\n"
12158 "Non-main Kernel Routing Table\n"
12159 "Instance ID/Table ID\n")
12160 {
12161 VTY_DECLVAR_CONTEXT(bgp, bgp);
12162 int idx_ospf_table = 1;
12163 int idx_number = 2;
12164 unsigned short instance;
12165 unsigned short protocol;
12166
12167 instance = strtoul(argv[idx_number]->arg, NULL, 10);
12168
12169 if (strncmp(argv[idx_ospf_table]->arg, "o", 1) == 0)
12170 protocol = ZEBRA_ROUTE_OSPF;
12171 else
12172 protocol = ZEBRA_ROUTE_TABLE;
12173
12174 bgp_redist_add(bgp, AFI_IP, protocol, instance);
12175 return bgp_redistribute_set(bgp, AFI_IP, protocol, instance, false);
12176 }
12177
12178 ALIAS_HIDDEN(bgp_redistribute_ipv4_ospf, bgp_redistribute_ipv4_ospf_hidden_cmd,
12179 "redistribute <ospf|table> (1-65535)",
12180 "Redistribute information from another routing protocol\n"
12181 "Open Shortest Path First (OSPFv2)\n"
12182 "Non-main Kernel Routing Table\n"
12183 "Instance ID/Table ID\n")
12184
12185 DEFUN (bgp_redistribute_ipv4_ospf_rmap,
12186 bgp_redistribute_ipv4_ospf_rmap_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 VTY_DECLVAR_CONTEXT(bgp, bgp);
12196 int idx_ospf_table = 1;
12197 int idx_number = 2;
12198 int idx_word = 4;
12199 struct bgp_redist *red;
12200 unsigned short instance;
12201 int protocol;
12202 bool changed;
12203 struct route_map *route_map =
12204 route_map_lookup_warn_noexist(vty, argv[idx_word]->arg);
12205
12206 if (strncmp(argv[idx_ospf_table]->arg, "o", 1) == 0)
12207 protocol = ZEBRA_ROUTE_OSPF;
12208 else
12209 protocol = ZEBRA_ROUTE_TABLE;
12210
12211 instance = strtoul(argv[idx_number]->arg, NULL, 10);
12212 red = bgp_redist_add(bgp, AFI_IP, protocol, instance);
12213 changed =
12214 bgp_redistribute_rmap_set(red, argv[idx_word]->arg, route_map);
12215 return bgp_redistribute_set(bgp, AFI_IP, protocol, instance, changed);
12216 }
12217
12218 ALIAS_HIDDEN(bgp_redistribute_ipv4_ospf_rmap,
12219 bgp_redistribute_ipv4_ospf_rmap_hidden_cmd,
12220 "redistribute <ospf|table> (1-65535) route-map WORD",
12221 "Redistribute information from another routing protocol\n"
12222 "Open Shortest Path First (OSPFv2)\n"
12223 "Non-main Kernel Routing Table\n"
12224 "Instance ID/Table ID\n"
12225 "Route map reference\n"
12226 "Pointer to route-map entries\n")
12227
12228 DEFUN (bgp_redistribute_ipv4_ospf_metric,
12229 bgp_redistribute_ipv4_ospf_metric_cmd,
12230 "redistribute <ospf|table> (1-65535) metric (0-4294967295)",
12231 "Redistribute information from another routing protocol\n"
12232 "Open Shortest Path First (OSPFv2)\n"
12233 "Non-main Kernel Routing Table\n"
12234 "Instance ID/Table ID\n"
12235 "Metric for redistributed routes\n"
12236 "Default metric\n")
12237 {
12238 VTY_DECLVAR_CONTEXT(bgp, bgp);
12239 int idx_ospf_table = 1;
12240 int idx_number = 2;
12241 int idx_number_2 = 4;
12242 uint32_t metric;
12243 struct bgp_redist *red;
12244 unsigned short instance;
12245 int protocol;
12246 bool changed;
12247
12248 if (strncmp(argv[idx_ospf_table]->arg, "o", 1) == 0)
12249 protocol = ZEBRA_ROUTE_OSPF;
12250 else
12251 protocol = ZEBRA_ROUTE_TABLE;
12252
12253 instance = strtoul(argv[idx_number]->arg, NULL, 10);
12254 metric = strtoul(argv[idx_number_2]->arg, NULL, 10);
12255
12256 red = bgp_redist_add(bgp, AFI_IP, protocol, instance);
12257 changed = bgp_redistribute_metric_set(bgp, red, AFI_IP, protocol,
12258 metric);
12259 return bgp_redistribute_set(bgp, AFI_IP, protocol, instance, changed);
12260 }
12261
12262 ALIAS_HIDDEN(bgp_redistribute_ipv4_ospf_metric,
12263 bgp_redistribute_ipv4_ospf_metric_hidden_cmd,
12264 "redistribute <ospf|table> (1-65535) metric (0-4294967295)",
12265 "Redistribute information from another routing protocol\n"
12266 "Open Shortest Path First (OSPFv2)\n"
12267 "Non-main Kernel Routing Table\n"
12268 "Instance ID/Table ID\n"
12269 "Metric for redistributed routes\n"
12270 "Default metric\n")
12271
12272 DEFUN (bgp_redistribute_ipv4_ospf_rmap_metric,
12273 bgp_redistribute_ipv4_ospf_rmap_metric_cmd,
12274 "redistribute <ospf|table> (1-65535) route-map WORD metric (0-4294967295)",
12275 "Redistribute information from another routing protocol\n"
12276 "Open Shortest Path First (OSPFv2)\n"
12277 "Non-main Kernel Routing Table\n"
12278 "Instance ID/Table ID\n"
12279 "Route map reference\n"
12280 "Pointer to route-map entries\n"
12281 "Metric for redistributed routes\n"
12282 "Default metric\n")
12283 {
12284 VTY_DECLVAR_CONTEXT(bgp, bgp);
12285 int idx_ospf_table = 1;
12286 int idx_number = 2;
12287 int idx_word = 4;
12288 int idx_number_2 = 6;
12289 uint32_t metric;
12290 struct bgp_redist *red;
12291 unsigned short instance;
12292 int protocol;
12293 bool changed;
12294 struct route_map *route_map =
12295 route_map_lookup_warn_noexist(vty, argv[idx_word]->arg);
12296
12297 if (strncmp(argv[idx_ospf_table]->arg, "o", 1) == 0)
12298 protocol = ZEBRA_ROUTE_OSPF;
12299 else
12300 protocol = ZEBRA_ROUTE_TABLE;
12301
12302 instance = strtoul(argv[idx_number]->arg, NULL, 10);
12303 metric = strtoul(argv[idx_number_2]->arg, NULL, 10);
12304
12305 red = bgp_redist_add(bgp, AFI_IP, protocol, instance);
12306 changed =
12307 bgp_redistribute_rmap_set(red, argv[idx_word]->arg, route_map);
12308 changed |= bgp_redistribute_metric_set(bgp, red, AFI_IP, protocol,
12309 metric);
12310 return bgp_redistribute_set(bgp, AFI_IP, protocol, instance, changed);
12311 }
12312
12313 ALIAS_HIDDEN(
12314 bgp_redistribute_ipv4_ospf_rmap_metric,
12315 bgp_redistribute_ipv4_ospf_rmap_metric_hidden_cmd,
12316 "redistribute <ospf|table> (1-65535) route-map WORD metric (0-4294967295)",
12317 "Redistribute information from another routing protocol\n"
12318 "Open Shortest Path First (OSPFv2)\n"
12319 "Non-main Kernel Routing Table\n"
12320 "Instance ID/Table ID\n"
12321 "Route map reference\n"
12322 "Pointer to route-map entries\n"
12323 "Metric for redistributed routes\n"
12324 "Default metric\n")
12325
12326 DEFUN (bgp_redistribute_ipv4_ospf_metric_rmap,
12327 bgp_redistribute_ipv4_ospf_metric_rmap_cmd,
12328 "redistribute <ospf|table> (1-65535) metric (0-4294967295) route-map WORD",
12329 "Redistribute information from another routing protocol\n"
12330 "Open Shortest Path First (OSPFv2)\n"
12331 "Non-main Kernel Routing Table\n"
12332 "Instance ID/Table ID\n"
12333 "Metric for redistributed routes\n"
12334 "Default metric\n"
12335 "Route map reference\n"
12336 "Pointer to route-map entries\n")
12337 {
12338 VTY_DECLVAR_CONTEXT(bgp, bgp);
12339 int idx_ospf_table = 1;
12340 int idx_number = 2;
12341 int idx_number_2 = 4;
12342 int idx_word = 6;
12343 uint32_t metric;
12344 struct bgp_redist *red;
12345 unsigned short instance;
12346 int protocol;
12347 bool changed;
12348 struct route_map *route_map =
12349 route_map_lookup_warn_noexist(vty, argv[idx_word]->arg);
12350
12351 if (strncmp(argv[idx_ospf_table]->arg, "o", 1) == 0)
12352 protocol = ZEBRA_ROUTE_OSPF;
12353 else
12354 protocol = ZEBRA_ROUTE_TABLE;
12355
12356 instance = strtoul(argv[idx_number]->arg, NULL, 10);
12357 metric = strtoul(argv[idx_number_2]->arg, NULL, 10);
12358
12359 red = bgp_redist_add(bgp, AFI_IP, protocol, instance);
12360 changed = bgp_redistribute_metric_set(bgp, red, AFI_IP, protocol,
12361 metric);
12362 changed |=
12363 bgp_redistribute_rmap_set(red, argv[idx_word]->arg, route_map);
12364 return bgp_redistribute_set(bgp, AFI_IP, protocol, instance, changed);
12365 }
12366
12367 ALIAS_HIDDEN(
12368 bgp_redistribute_ipv4_ospf_metric_rmap,
12369 bgp_redistribute_ipv4_ospf_metric_rmap_hidden_cmd,
12370 "redistribute <ospf|table> (1-65535) metric (0-4294967295) route-map WORD",
12371 "Redistribute information from another routing protocol\n"
12372 "Open Shortest Path First (OSPFv2)\n"
12373 "Non-main Kernel Routing Table\n"
12374 "Instance ID/Table ID\n"
12375 "Metric for redistributed routes\n"
12376 "Default metric\n"
12377 "Route map reference\n"
12378 "Pointer to route-map entries\n")
12379
12380 DEFUN (no_bgp_redistribute_ipv4_ospf,
12381 no_bgp_redistribute_ipv4_ospf_cmd,
12382 "no redistribute <ospf|table> (1-65535) [metric (0-4294967295)] [route-map WORD]",
12383 NO_STR
12384 "Redistribute information from another routing protocol\n"
12385 "Open Shortest Path First (OSPFv2)\n"
12386 "Non-main Kernel Routing Table\n"
12387 "Instance ID/Table ID\n"
12388 "Metric for redistributed routes\n"
12389 "Default metric\n"
12390 "Route map reference\n"
12391 "Pointer to route-map entries\n")
12392 {
12393 VTY_DECLVAR_CONTEXT(bgp, bgp);
12394 int idx_ospf_table = 2;
12395 int idx_number = 3;
12396 unsigned short instance;
12397 int protocol;
12398
12399 if (strncmp(argv[idx_ospf_table]->arg, "o", 1) == 0)
12400 protocol = ZEBRA_ROUTE_OSPF;
12401 else
12402 protocol = ZEBRA_ROUTE_TABLE;
12403
12404 instance = strtoul(argv[idx_number]->arg, NULL, 10);
12405 return bgp_redistribute_unset(bgp, AFI_IP, protocol, instance);
12406 }
12407
12408 ALIAS_HIDDEN(
12409 no_bgp_redistribute_ipv4_ospf, no_bgp_redistribute_ipv4_ospf_hidden_cmd,
12410 "no redistribute <ospf|table> (1-65535) [metric (0-4294967295)] [route-map WORD]",
12411 NO_STR
12412 "Redistribute information from another routing protocol\n"
12413 "Open Shortest Path First (OSPFv2)\n"
12414 "Non-main Kernel Routing Table\n"
12415 "Instance ID/Table ID\n"
12416 "Metric for redistributed routes\n"
12417 "Default metric\n"
12418 "Route map reference\n"
12419 "Pointer to route-map entries\n")
12420
12421 DEFUN (no_bgp_redistribute_ipv4,
12422 no_bgp_redistribute_ipv4_cmd,
12423 "no redistribute " FRR_IP_REDIST_STR_BGPD " [metric (0-4294967295)] [route-map WORD]",
12424 NO_STR
12425 "Redistribute information from another routing protocol\n"
12426 FRR_IP_REDIST_HELP_STR_BGPD
12427 "Metric for redistributed routes\n"
12428 "Default metric\n"
12429 "Route map reference\n"
12430 "Pointer to route-map entries\n")
12431 {
12432 VTY_DECLVAR_CONTEXT(bgp, bgp);
12433 int idx_protocol = 2;
12434 int type;
12435
12436 type = proto_redistnum(AFI_IP, argv[idx_protocol]->text);
12437 if (type < 0) {
12438 vty_out(vty, "%% Invalid route type\n");
12439 return CMD_WARNING_CONFIG_FAILED;
12440 }
12441 return bgp_redistribute_unset(bgp, AFI_IP, type, 0);
12442 }
12443
12444 ALIAS_HIDDEN(
12445 no_bgp_redistribute_ipv4, no_bgp_redistribute_ipv4_hidden_cmd,
12446 "no redistribute " FRR_IP_REDIST_STR_BGPD
12447 " [metric (0-4294967295)] [route-map WORD]",
12448 NO_STR
12449 "Redistribute information from another routing protocol\n" FRR_IP_REDIST_HELP_STR_BGPD
12450 "Metric for redistributed routes\n"
12451 "Default metric\n"
12452 "Route map reference\n"
12453 "Pointer to route-map entries\n")
12454
12455 DEFUN (bgp_redistribute_ipv6,
12456 bgp_redistribute_ipv6_cmd,
12457 "redistribute " FRR_IP6_REDIST_STR_BGPD,
12458 "Redistribute information from another routing protocol\n"
12459 FRR_IP6_REDIST_HELP_STR_BGPD)
12460 {
12461 VTY_DECLVAR_CONTEXT(bgp, bgp);
12462 int idx_protocol = 1;
12463 int type;
12464
12465 type = proto_redistnum(AFI_IP6, argv[idx_protocol]->text);
12466 if (type < 0) {
12467 vty_out(vty, "%% Invalid route type\n");
12468 return CMD_WARNING_CONFIG_FAILED;
12469 }
12470
12471 bgp_redist_add(bgp, AFI_IP6, type, 0);
12472 return bgp_redistribute_set(bgp, AFI_IP6, type, 0, false);
12473 }
12474
12475 DEFUN (bgp_redistribute_ipv6_rmap,
12476 bgp_redistribute_ipv6_rmap_cmd,
12477 "redistribute " FRR_IP6_REDIST_STR_BGPD " route-map WORD",
12478 "Redistribute information from another routing protocol\n"
12479 FRR_IP6_REDIST_HELP_STR_BGPD
12480 "Route map reference\n"
12481 "Pointer to route-map entries\n")
12482 {
12483 VTY_DECLVAR_CONTEXT(bgp, bgp);
12484 int idx_protocol = 1;
12485 int idx_word = 3;
12486 int type;
12487 struct bgp_redist *red;
12488 bool changed;
12489 struct route_map *route_map =
12490 route_map_lookup_warn_noexist(vty, argv[idx_word]->arg);
12491
12492 type = proto_redistnum(AFI_IP6, argv[idx_protocol]->text);
12493 if (type < 0) {
12494 vty_out(vty, "%% Invalid route type\n");
12495 return CMD_WARNING_CONFIG_FAILED;
12496 }
12497
12498 red = bgp_redist_add(bgp, AFI_IP6, type, 0);
12499 changed =
12500 bgp_redistribute_rmap_set(red, argv[idx_word]->arg, route_map);
12501 return bgp_redistribute_set(bgp, AFI_IP6, type, 0, changed);
12502 }
12503
12504 DEFUN (bgp_redistribute_ipv6_metric,
12505 bgp_redistribute_ipv6_metric_cmd,
12506 "redistribute " FRR_IP6_REDIST_STR_BGPD " metric (0-4294967295)",
12507 "Redistribute information from another routing protocol\n"
12508 FRR_IP6_REDIST_HELP_STR_BGPD
12509 "Metric for redistributed routes\n"
12510 "Default metric\n")
12511 {
12512 VTY_DECLVAR_CONTEXT(bgp, bgp);
12513 int idx_protocol = 1;
12514 int idx_number = 3;
12515 int type;
12516 uint32_t metric;
12517 struct bgp_redist *red;
12518 bool changed;
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 = bgp_redistribute_metric_set(bgp, red, AFI_IP6, type, metric);
12529 return bgp_redistribute_set(bgp, AFI_IP6, type, 0, changed);
12530 }
12531
12532 DEFUN (bgp_redistribute_ipv6_rmap_metric,
12533 bgp_redistribute_ipv6_rmap_metric_cmd,
12534 "redistribute " FRR_IP6_REDIST_STR_BGPD " route-map WORD metric (0-4294967295)",
12535 "Redistribute information from another routing protocol\n"
12536 FRR_IP6_REDIST_HELP_STR_BGPD
12537 "Route map reference\n"
12538 "Pointer to route-map entries\n"
12539 "Metric for redistributed routes\n"
12540 "Default metric\n")
12541 {
12542 VTY_DECLVAR_CONTEXT(bgp, bgp);
12543 int idx_protocol = 1;
12544 int idx_word = 3;
12545 int idx_number = 5;
12546 int type;
12547 uint32_t metric;
12548 struct bgp_redist *red;
12549 bool changed;
12550 struct route_map *route_map =
12551 route_map_lookup_warn_noexist(vty, argv[idx_word]->arg);
12552
12553 type = proto_redistnum(AFI_IP6, argv[idx_protocol]->text);
12554 if (type < 0) {
12555 vty_out(vty, "%% Invalid route type\n");
12556 return CMD_WARNING_CONFIG_FAILED;
12557 }
12558 metric = strtoul(argv[idx_number]->arg, NULL, 10);
12559
12560 red = bgp_redist_add(bgp, AFI_IP6, type, 0);
12561 changed =
12562 bgp_redistribute_rmap_set(red, argv[idx_word]->arg, route_map);
12563 changed |= bgp_redistribute_metric_set(bgp, red, AFI_IP6, type,
12564 metric);
12565 return bgp_redistribute_set(bgp, AFI_IP6, type, 0, changed);
12566 }
12567
12568 DEFUN (bgp_redistribute_ipv6_metric_rmap,
12569 bgp_redistribute_ipv6_metric_rmap_cmd,
12570 "redistribute " FRR_IP6_REDIST_STR_BGPD " metric (0-4294967295) route-map WORD",
12571 "Redistribute information from another routing protocol\n"
12572 FRR_IP6_REDIST_HELP_STR_BGPD
12573 "Metric for redistributed routes\n"
12574 "Default metric\n"
12575 "Route map reference\n"
12576 "Pointer to route-map entries\n")
12577 {
12578 VTY_DECLVAR_CONTEXT(bgp, bgp);
12579 int idx_protocol = 1;
12580 int idx_number = 3;
12581 int idx_word = 5;
12582 int type;
12583 uint32_t metric;
12584 struct bgp_redist *red;
12585 bool changed;
12586 struct route_map *route_map =
12587 route_map_lookup_warn_noexist(vty, argv[idx_word]->arg);
12588
12589 type = proto_redistnum(AFI_IP6, argv[idx_protocol]->text);
12590 if (type < 0) {
12591 vty_out(vty, "%% Invalid route type\n");
12592 return CMD_WARNING_CONFIG_FAILED;
12593 }
12594 metric = strtoul(argv[idx_number]->arg, NULL, 10);
12595
12596 red = bgp_redist_add(bgp, AFI_IP6, type, 0);
12597 changed = bgp_redistribute_metric_set(bgp, red, AFI_IP6, SAFI_UNICAST,
12598 metric);
12599 changed |=
12600 bgp_redistribute_rmap_set(red, argv[idx_word]->arg, route_map);
12601 return bgp_redistribute_set(bgp, AFI_IP6, type, 0, changed);
12602 }
12603
12604 DEFUN (no_bgp_redistribute_ipv6,
12605 no_bgp_redistribute_ipv6_cmd,
12606 "no redistribute " FRR_IP6_REDIST_STR_BGPD " [metric (0-4294967295)] [route-map WORD]",
12607 NO_STR
12608 "Redistribute information from another routing protocol\n"
12609 FRR_IP6_REDIST_HELP_STR_BGPD
12610 "Metric for redistributed routes\n"
12611 "Default metric\n"
12612 "Route map reference\n"
12613 "Pointer to route-map entries\n")
12614 {
12615 VTY_DECLVAR_CONTEXT(bgp, bgp);
12616 int idx_protocol = 2;
12617 int type;
12618
12619 type = proto_redistnum(AFI_IP6, argv[idx_protocol]->text);
12620 if (type < 0) {
12621 vty_out(vty, "%% Invalid route type\n");
12622 return CMD_WARNING_CONFIG_FAILED;
12623 }
12624
12625 return bgp_redistribute_unset(bgp, AFI_IP6, type, 0);
12626 }
12627
12628 void bgp_config_write_redistribute(struct vty *vty, struct bgp *bgp, afi_t afi,
12629 safi_t safi)
12630 {
12631 int i;
12632
12633 /* Unicast redistribution only. */
12634 if (safi != SAFI_UNICAST)
12635 return;
12636
12637 for (i = 0; i < ZEBRA_ROUTE_MAX; i++) {
12638 /* Redistribute BGP does not make sense. */
12639 if (i != ZEBRA_ROUTE_BGP) {
12640 struct list *red_list;
12641 struct listnode *node;
12642 struct bgp_redist *red;
12643
12644 red_list = bgp->redist[afi][i];
12645 if (!red_list)
12646 continue;
12647
12648 for (ALL_LIST_ELEMENTS_RO(red_list, node, red)) {
12649 /* "redistribute" configuration. */
12650 vty_out(vty, " redistribute %s",
12651 zebra_route_string(i));
12652 if (red->instance)
12653 vty_out(vty, " %d", red->instance);
12654 if (red->redist_metric_flag)
12655 vty_out(vty, " metric %u",
12656 red->redist_metric);
12657 if (red->rmap.name)
12658 vty_out(vty, " route-map %s",
12659 red->rmap.name);
12660 vty_out(vty, "\n");
12661 }
12662 }
12663 }
12664 }
12665
12666 /* This is part of the address-family block (unicast only) */
12667 void bgp_vpn_policy_config_write_afi(struct vty *vty, struct bgp *bgp,
12668 afi_t afi)
12669 {
12670 int indent = 2;
12671
12672 if (bgp->vpn_policy[afi].rmap_name[BGP_VPN_POLICY_DIR_FROMVPN]) {
12673 if (listcount(bgp->vpn_policy[afi].import_vrf))
12674 vty_out(vty, "%*simport vrf route-map %s\n", indent, "",
12675 bgp->vpn_policy[afi]
12676 .rmap_name[BGP_VPN_POLICY_DIR_FROMVPN]);
12677 else
12678 vty_out(vty, "%*sroute-map vpn import %s\n", indent, "",
12679 bgp->vpn_policy[afi]
12680 .rmap_name[BGP_VPN_POLICY_DIR_FROMVPN]);
12681 }
12682 if (CHECK_FLAG(bgp->af_flags[afi][SAFI_UNICAST],
12683 BGP_CONFIG_VRF_TO_VRF_IMPORT)
12684 || CHECK_FLAG(bgp->af_flags[afi][SAFI_UNICAST],
12685 BGP_CONFIG_VRF_TO_VRF_EXPORT))
12686 return;
12687
12688 if (CHECK_FLAG(bgp->vpn_policy[afi].flags,
12689 BGP_VPN_POLICY_TOVPN_LABEL_AUTO)) {
12690
12691 vty_out(vty, "%*slabel vpn export %s\n", indent, "", "auto");
12692
12693 } else {
12694 if (bgp->vpn_policy[afi].tovpn_label != MPLS_LABEL_NONE) {
12695 vty_out(vty, "%*slabel vpn export %u\n", indent, "",
12696 bgp->vpn_policy[afi].tovpn_label);
12697 }
12698 }
12699 if (CHECK_FLAG(bgp->vpn_policy[afi].flags,
12700 BGP_VPN_POLICY_TOVPN_RD_SET)) {
12701 char buf[RD_ADDRSTRLEN];
12702 vty_out(vty, "%*srd vpn export %s\n", indent, "",
12703 prefix_rd2str(&bgp->vpn_policy[afi].tovpn_rd, buf,
12704 sizeof(buf)));
12705 }
12706 if (CHECK_FLAG(bgp->vpn_policy[afi].flags,
12707 BGP_VPN_POLICY_TOVPN_NEXTHOP_SET)) {
12708
12709 char buf[PREFIX_STRLEN];
12710 if (inet_ntop(bgp->vpn_policy[afi].tovpn_nexthop.family,
12711 &bgp->vpn_policy[afi].tovpn_nexthop.u.prefix, buf,
12712 sizeof(buf))) {
12713
12714 vty_out(vty, "%*snexthop vpn export %s\n",
12715 indent, "", buf);
12716 }
12717 }
12718 if (bgp->vpn_policy[afi].rtlist[BGP_VPN_POLICY_DIR_FROMVPN]
12719 && bgp->vpn_policy[afi].rtlist[BGP_VPN_POLICY_DIR_TOVPN]
12720 && ecommunity_cmp(
12721 bgp->vpn_policy[afi].rtlist[BGP_VPN_POLICY_DIR_FROMVPN],
12722 bgp->vpn_policy[afi].rtlist[BGP_VPN_POLICY_DIR_TOVPN])) {
12723
12724 char *b = ecommunity_ecom2str(
12725 bgp->vpn_policy[afi].rtlist[BGP_VPN_POLICY_DIR_TOVPN],
12726 ECOMMUNITY_FORMAT_ROUTE_MAP, ECOMMUNITY_ROUTE_TARGET);
12727 vty_out(vty, "%*srt vpn both %s\n", indent, "", b);
12728 XFREE(MTYPE_ECOMMUNITY_STR, b);
12729 } else {
12730 if (bgp->vpn_policy[afi].rtlist[BGP_VPN_POLICY_DIR_FROMVPN]) {
12731 char *b = ecommunity_ecom2str(
12732 bgp->vpn_policy[afi]
12733 .rtlist[BGP_VPN_POLICY_DIR_FROMVPN],
12734 ECOMMUNITY_FORMAT_ROUTE_MAP,
12735 ECOMMUNITY_ROUTE_TARGET);
12736 vty_out(vty, "%*srt vpn import %s\n", indent, "", b);
12737 XFREE(MTYPE_ECOMMUNITY_STR, b);
12738 }
12739 if (bgp->vpn_policy[afi].rtlist[BGP_VPN_POLICY_DIR_TOVPN]) {
12740 char *b = ecommunity_ecom2str(
12741 bgp->vpn_policy[afi]
12742 .rtlist[BGP_VPN_POLICY_DIR_TOVPN],
12743 ECOMMUNITY_FORMAT_ROUTE_MAP,
12744 ECOMMUNITY_ROUTE_TARGET);
12745 vty_out(vty, "%*srt vpn export %s\n", indent, "", b);
12746 XFREE(MTYPE_ECOMMUNITY_STR, b);
12747 }
12748 }
12749
12750 if (bgp->vpn_policy[afi].rmap_name[BGP_VPN_POLICY_DIR_TOVPN])
12751 vty_out(vty, "%*sroute-map vpn export %s\n", indent, "",
12752 bgp->vpn_policy[afi]
12753 .rmap_name[BGP_VPN_POLICY_DIR_TOVPN]);
12754
12755 if (bgp->vpn_policy[afi].import_redirect_rtlist) {
12756 char *b = ecommunity_ecom2str(
12757 bgp->vpn_policy[afi]
12758 .import_redirect_rtlist,
12759 ECOMMUNITY_FORMAT_ROUTE_MAP,
12760 ECOMMUNITY_ROUTE_TARGET);
12761
12762 vty_out(vty, "%*srt redirect import %s\n", indent, "", b);
12763 XFREE(MTYPE_ECOMMUNITY_STR, b);
12764 }
12765 }
12766
12767
12768 /* BGP node structure. */
12769 static struct cmd_node bgp_node = {
12770 BGP_NODE, "%s(config-router)# ", 1,
12771 };
12772
12773 static struct cmd_node bgp_ipv4_unicast_node = {
12774 BGP_IPV4_NODE, "%s(config-router-af)# ", 1,
12775 };
12776
12777 static struct cmd_node bgp_ipv4_multicast_node = {
12778 BGP_IPV4M_NODE, "%s(config-router-af)# ", 1,
12779 };
12780
12781 static struct cmd_node bgp_ipv4_labeled_unicast_node = {
12782 BGP_IPV4L_NODE, "%s(config-router-af)# ", 1,
12783 };
12784
12785 static struct cmd_node bgp_ipv6_unicast_node = {
12786 BGP_IPV6_NODE, "%s(config-router-af)# ", 1,
12787 };
12788
12789 static struct cmd_node bgp_ipv6_multicast_node = {
12790 BGP_IPV6M_NODE, "%s(config-router-af)# ", 1,
12791 };
12792
12793 static struct cmd_node bgp_ipv6_labeled_unicast_node = {
12794 BGP_IPV6L_NODE, "%s(config-router-af)# ", 1,
12795 };
12796
12797 static struct cmd_node bgp_vpnv4_node = {BGP_VPNV4_NODE,
12798 "%s(config-router-af)# ", 1};
12799
12800 static struct cmd_node bgp_vpnv6_node = {BGP_VPNV6_NODE,
12801 "%s(config-router-af-vpnv6)# ", 1};
12802
12803 static struct cmd_node bgp_evpn_node = {BGP_EVPN_NODE,
12804 "%s(config-router-evpn)# ", 1};
12805
12806 static struct cmd_node bgp_evpn_vni_node = {BGP_EVPN_VNI_NODE,
12807 "%s(config-router-af-vni)# ", 1};
12808
12809 static struct cmd_node bgp_flowspecv4_node = {BGP_FLOWSPECV4_NODE,
12810 "%s(config-router-af)# ", 1};
12811
12812 static struct cmd_node bgp_flowspecv6_node = {BGP_FLOWSPECV6_NODE,
12813 "%s(config-router-af-vpnv6)# ", 1};
12814
12815 static void community_list_vty(void);
12816
12817 static void bgp_ac_neighbor(vector comps, struct cmd_token *token)
12818 {
12819 struct bgp *bgp;
12820 struct peer *peer;
12821 struct listnode *lnbgp, *lnpeer;
12822
12823 for (ALL_LIST_ELEMENTS_RO(bm->bgp, lnbgp, bgp)) {
12824 for (ALL_LIST_ELEMENTS_RO(bgp->peer, lnpeer, peer)) {
12825 /* only provide suggestions on the appropriate input
12826 * token type,
12827 * they'll otherwise show up multiple times */
12828 enum cmd_token_type match_type;
12829 char *name = peer->host;
12830
12831 if (peer->conf_if) {
12832 match_type = VARIABLE_TKN;
12833 name = peer->conf_if;
12834 } else if (strchr(peer->host, ':'))
12835 match_type = IPV6_TKN;
12836 else
12837 match_type = IPV4_TKN;
12838
12839 if (token->type != match_type)
12840 continue;
12841
12842 vector_set(comps, XSTRDUP(MTYPE_COMPLETION, name));
12843 }
12844 }
12845 }
12846
12847 static const struct cmd_variable_handler bgp_var_neighbor[] = {
12848 {.varname = "neighbor", .completions = bgp_ac_neighbor},
12849 {.varname = "neighbors", .completions = bgp_ac_neighbor},
12850 {.varname = "peer", .completions = bgp_ac_neighbor},
12851 {.completions = NULL}};
12852
12853 static void bgp_ac_peergroup(vector comps, struct cmd_token *token)
12854 {
12855 struct bgp *bgp;
12856 struct peer_group *group;
12857 struct listnode *lnbgp, *lnpeer;
12858
12859 for (ALL_LIST_ELEMENTS_RO(bm->bgp, lnbgp, bgp)) {
12860 for (ALL_LIST_ELEMENTS_RO(bgp->group, lnpeer, group))
12861 vector_set(comps, XSTRDUP(MTYPE_COMPLETION,
12862 group->name));
12863 }
12864 }
12865
12866 static const struct cmd_variable_handler bgp_var_peergroup[] = {
12867 {.tokenname = "PGNAME", .completions = bgp_ac_peergroup},
12868 {.completions = NULL} };
12869
12870 void bgp_vty_init(void)
12871 {
12872 cmd_variable_handler_register(bgp_var_neighbor);
12873 cmd_variable_handler_register(bgp_var_peergroup);
12874
12875 /* Install bgp top node. */
12876 install_node(&bgp_node, bgp_config_write);
12877 install_node(&bgp_ipv4_unicast_node, NULL);
12878 install_node(&bgp_ipv4_multicast_node, NULL);
12879 install_node(&bgp_ipv4_labeled_unicast_node, NULL);
12880 install_node(&bgp_ipv6_unicast_node, NULL);
12881 install_node(&bgp_ipv6_multicast_node, NULL);
12882 install_node(&bgp_ipv6_labeled_unicast_node, NULL);
12883 install_node(&bgp_vpnv4_node, NULL);
12884 install_node(&bgp_vpnv6_node, NULL);
12885 install_node(&bgp_evpn_node, NULL);
12886 install_node(&bgp_evpn_vni_node, NULL);
12887 install_node(&bgp_flowspecv4_node, NULL);
12888 install_node(&bgp_flowspecv6_node, NULL);
12889
12890 /* Install default VTY commands to new nodes. */
12891 install_default(BGP_NODE);
12892 install_default(BGP_IPV4_NODE);
12893 install_default(BGP_IPV4M_NODE);
12894 install_default(BGP_IPV4L_NODE);
12895 install_default(BGP_IPV6_NODE);
12896 install_default(BGP_IPV6M_NODE);
12897 install_default(BGP_IPV6L_NODE);
12898 install_default(BGP_VPNV4_NODE);
12899 install_default(BGP_VPNV6_NODE);
12900 install_default(BGP_FLOWSPECV4_NODE);
12901 install_default(BGP_FLOWSPECV6_NODE);
12902 install_default(BGP_EVPN_NODE);
12903 install_default(BGP_EVPN_VNI_NODE);
12904
12905 /* "bgp multiple-instance" commands. */
12906 install_element(CONFIG_NODE, &bgp_multiple_instance_cmd);
12907 install_element(CONFIG_NODE, &no_bgp_multiple_instance_cmd);
12908
12909 /* "bgp config-type" commands. */
12910 install_element(CONFIG_NODE, &bgp_config_type_cmd);
12911 install_element(CONFIG_NODE, &no_bgp_config_type_cmd);
12912
12913 /* "bgp local-mac" hidden commands. */
12914 install_element(CONFIG_NODE, &bgp_local_mac_cmd);
12915 install_element(CONFIG_NODE, &no_bgp_local_mac_cmd);
12916
12917 /* bgp route-map delay-timer commands. */
12918 install_element(CONFIG_NODE, &bgp_set_route_map_delay_timer_cmd);
12919 install_element(CONFIG_NODE, &no_bgp_set_route_map_delay_timer_cmd);
12920
12921 /* Dummy commands (Currently not supported) */
12922 install_element(BGP_NODE, &no_synchronization_cmd);
12923 install_element(BGP_NODE, &no_auto_summary_cmd);
12924
12925 /* "router bgp" commands. */
12926 install_element(CONFIG_NODE, &router_bgp_cmd);
12927
12928 /* "no router bgp" commands. */
12929 install_element(CONFIG_NODE, &no_router_bgp_cmd);
12930
12931 /* "bgp router-id" commands. */
12932 install_element(BGP_NODE, &bgp_router_id_cmd);
12933 install_element(BGP_NODE, &no_bgp_router_id_cmd);
12934
12935 /* "bgp cluster-id" commands. */
12936 install_element(BGP_NODE, &bgp_cluster_id_cmd);
12937 install_element(BGP_NODE, &no_bgp_cluster_id_cmd);
12938
12939 /* "bgp confederation" commands. */
12940 install_element(BGP_NODE, &bgp_confederation_identifier_cmd);
12941 install_element(BGP_NODE, &no_bgp_confederation_identifier_cmd);
12942
12943 /* "bgp confederation peers" commands. */
12944 install_element(BGP_NODE, &bgp_confederation_peers_cmd);
12945 install_element(BGP_NODE, &no_bgp_confederation_peers_cmd);
12946
12947 /* bgp max-med command */
12948 install_element(BGP_NODE, &bgp_maxmed_admin_cmd);
12949 install_element(BGP_NODE, &no_bgp_maxmed_admin_cmd);
12950 install_element(BGP_NODE, &bgp_maxmed_admin_medv_cmd);
12951 install_element(BGP_NODE, &bgp_maxmed_onstartup_cmd);
12952 install_element(BGP_NODE, &no_bgp_maxmed_onstartup_cmd);
12953
12954 /* bgp disable-ebgp-connected-nh-check */
12955 install_element(BGP_NODE, &bgp_disable_connected_route_check_cmd);
12956 install_element(BGP_NODE, &no_bgp_disable_connected_route_check_cmd);
12957
12958 /* bgp update-delay command */
12959 install_element(BGP_NODE, &bgp_update_delay_cmd);
12960 install_element(BGP_NODE, &no_bgp_update_delay_cmd);
12961 install_element(BGP_NODE, &bgp_update_delay_establish_wait_cmd);
12962
12963 install_element(BGP_NODE, &bgp_wpkt_quanta_cmd);
12964 install_element(BGP_NODE, &no_bgp_wpkt_quanta_cmd);
12965 install_element(BGP_NODE, &bgp_rpkt_quanta_cmd);
12966 install_element(BGP_NODE, &no_bgp_rpkt_quanta_cmd);
12967
12968 install_element(BGP_NODE, &bgp_coalesce_time_cmd);
12969 install_element(BGP_NODE, &no_bgp_coalesce_time_cmd);
12970
12971 /* "maximum-paths" commands. */
12972 install_element(BGP_NODE, &bgp_maxpaths_hidden_cmd);
12973 install_element(BGP_NODE, &no_bgp_maxpaths_hidden_cmd);
12974 install_element(BGP_IPV4_NODE, &bgp_maxpaths_cmd);
12975 install_element(BGP_IPV4_NODE, &no_bgp_maxpaths_cmd);
12976 install_element(BGP_IPV6_NODE, &bgp_maxpaths_cmd);
12977 install_element(BGP_IPV6_NODE, &no_bgp_maxpaths_cmd);
12978 install_element(BGP_NODE, &bgp_maxpaths_ibgp_hidden_cmd);
12979 install_element(BGP_NODE, &bgp_maxpaths_ibgp_cluster_hidden_cmd);
12980 install_element(BGP_NODE, &no_bgp_maxpaths_ibgp_hidden_cmd);
12981 install_element(BGP_IPV4_NODE, &bgp_maxpaths_ibgp_cmd);
12982 install_element(BGP_IPV4_NODE, &bgp_maxpaths_ibgp_cluster_cmd);
12983 install_element(BGP_IPV4_NODE, &no_bgp_maxpaths_ibgp_cmd);
12984 install_element(BGP_IPV6_NODE, &bgp_maxpaths_ibgp_cmd);
12985 install_element(BGP_IPV6_NODE, &bgp_maxpaths_ibgp_cluster_cmd);
12986 install_element(BGP_IPV6_NODE, &no_bgp_maxpaths_ibgp_cmd);
12987
12988 install_element(BGP_IPV6L_NODE, &bgp_maxpaths_cmd);
12989 install_element(BGP_IPV6L_NODE, &no_bgp_maxpaths_cmd);
12990 install_element(BGP_IPV6L_NODE, &bgp_maxpaths_ibgp_cmd);
12991 install_element(BGP_IPV6L_NODE, &bgp_maxpaths_ibgp_cluster_cmd);
12992 install_element(BGP_IPV6L_NODE, &no_bgp_maxpaths_ibgp_cmd);
12993
12994 /* "timers bgp" commands. */
12995 install_element(BGP_NODE, &bgp_timers_cmd);
12996 install_element(BGP_NODE, &no_bgp_timers_cmd);
12997
12998 /* route-map delay-timer commands - per instance for backwards compat.
12999 */
13000 install_element(BGP_NODE, &bgp_set_route_map_delay_timer_cmd);
13001 install_element(BGP_NODE, &no_bgp_set_route_map_delay_timer_cmd);
13002
13003 /* "bgp client-to-client reflection" commands */
13004 install_element(BGP_NODE, &no_bgp_client_to_client_reflection_cmd);
13005 install_element(BGP_NODE, &bgp_client_to_client_reflection_cmd);
13006
13007 /* "bgp always-compare-med" commands */
13008 install_element(BGP_NODE, &bgp_always_compare_med_cmd);
13009 install_element(BGP_NODE, &no_bgp_always_compare_med_cmd);
13010
13011 /* bgp ebgp-requires-policy */
13012 install_element(BGP_NODE, &bgp_ebgp_requires_policy_cmd);
13013 install_element(BGP_NODE, &no_bgp_ebgp_requires_policy_cmd);
13014
13015 /* "bgp deterministic-med" commands */
13016 install_element(BGP_NODE, &bgp_deterministic_med_cmd);
13017 install_element(BGP_NODE, &no_bgp_deterministic_med_cmd);
13018
13019 /* "bgp graceful-restart" commands */
13020 install_element(BGP_NODE, &bgp_graceful_restart_cmd);
13021 install_element(BGP_NODE, &no_bgp_graceful_restart_cmd);
13022 install_element(BGP_NODE, &bgp_graceful_restart_stalepath_time_cmd);
13023 install_element(BGP_NODE, &no_bgp_graceful_restart_stalepath_time_cmd);
13024 install_element(BGP_NODE, &bgp_graceful_restart_restart_time_cmd);
13025 install_element(BGP_NODE, &no_bgp_graceful_restart_restart_time_cmd);
13026
13027 install_element(BGP_NODE, &bgp_graceful_restart_preserve_fw_cmd);
13028 install_element(BGP_NODE, &no_bgp_graceful_restart_preserve_fw_cmd);
13029
13030 /* "bgp graceful-shutdown" commands */
13031 install_element(BGP_NODE, &bgp_graceful_shutdown_cmd);
13032 install_element(BGP_NODE, &no_bgp_graceful_shutdown_cmd);
13033
13034 /* "bgp fast-external-failover" commands */
13035 install_element(BGP_NODE, &bgp_fast_external_failover_cmd);
13036 install_element(BGP_NODE, &no_bgp_fast_external_failover_cmd);
13037
13038 /* "bgp enforce-first-as" commands */
13039 install_element(BGP_NODE, &bgp_enforce_first_as_cmd);
13040
13041 /* "bgp bestpath compare-routerid" commands */
13042 install_element(BGP_NODE, &bgp_bestpath_compare_router_id_cmd);
13043 install_element(BGP_NODE, &no_bgp_bestpath_compare_router_id_cmd);
13044
13045 /* "bgp bestpath as-path ignore" commands */
13046 install_element(BGP_NODE, &bgp_bestpath_aspath_ignore_cmd);
13047 install_element(BGP_NODE, &no_bgp_bestpath_aspath_ignore_cmd);
13048
13049 /* "bgp bestpath as-path confed" commands */
13050 install_element(BGP_NODE, &bgp_bestpath_aspath_confed_cmd);
13051 install_element(BGP_NODE, &no_bgp_bestpath_aspath_confed_cmd);
13052
13053 /* "bgp bestpath as-path multipath-relax" commands */
13054 install_element(BGP_NODE, &bgp_bestpath_aspath_multipath_relax_cmd);
13055 install_element(BGP_NODE, &no_bgp_bestpath_aspath_multipath_relax_cmd);
13056
13057 /* "bgp log-neighbor-changes" commands */
13058 install_element(BGP_NODE, &bgp_log_neighbor_changes_cmd);
13059 install_element(BGP_NODE, &no_bgp_log_neighbor_changes_cmd);
13060
13061 /* "bgp bestpath med" commands */
13062 install_element(BGP_NODE, &bgp_bestpath_med_cmd);
13063 install_element(BGP_NODE, &no_bgp_bestpath_med_cmd);
13064
13065 /* "no bgp default ipv4-unicast" commands. */
13066 install_element(BGP_NODE, &no_bgp_default_ipv4_unicast_cmd);
13067 install_element(BGP_NODE, &bgp_default_ipv4_unicast_cmd);
13068
13069 /* "bgp network import-check" commands. */
13070 install_element(BGP_NODE, &bgp_network_import_check_cmd);
13071 install_element(BGP_NODE, &bgp_network_import_check_exact_cmd);
13072 install_element(BGP_NODE, &no_bgp_network_import_check_cmd);
13073
13074 /* "bgp default local-preference" commands. */
13075 install_element(BGP_NODE, &bgp_default_local_preference_cmd);
13076 install_element(BGP_NODE, &no_bgp_default_local_preference_cmd);
13077
13078 /* bgp default show-hostname */
13079 install_element(BGP_NODE, &bgp_default_show_hostname_cmd);
13080 install_element(BGP_NODE, &no_bgp_default_show_hostname_cmd);
13081
13082 /* "bgp default subgroup-pkt-queue-max" commands. */
13083 install_element(BGP_NODE, &bgp_default_subgroup_pkt_queue_max_cmd);
13084 install_element(BGP_NODE, &no_bgp_default_subgroup_pkt_queue_max_cmd);
13085
13086 /* bgp ibgp-allow-policy-mods command */
13087 install_element(BGP_NODE, &bgp_rr_allow_outbound_policy_cmd);
13088 install_element(BGP_NODE, &no_bgp_rr_allow_outbound_policy_cmd);
13089
13090 /* "bgp listen limit" commands. */
13091 install_element(BGP_NODE, &bgp_listen_limit_cmd);
13092 install_element(BGP_NODE, &no_bgp_listen_limit_cmd);
13093
13094 /* "bgp listen range" commands. */
13095 install_element(BGP_NODE, &bgp_listen_range_cmd);
13096 install_element(BGP_NODE, &no_bgp_listen_range_cmd);
13097
13098 /* "bgp default shutdown" command */
13099 install_element(BGP_NODE, &bgp_default_shutdown_cmd);
13100
13101 /* "neighbor remote-as" commands. */
13102 install_element(BGP_NODE, &neighbor_remote_as_cmd);
13103 install_element(BGP_NODE, &neighbor_interface_config_cmd);
13104 install_element(BGP_NODE, &neighbor_interface_config_v6only_cmd);
13105 install_element(BGP_NODE, &neighbor_interface_config_remote_as_cmd);
13106 install_element(BGP_NODE,
13107 &neighbor_interface_v6only_config_remote_as_cmd);
13108 install_element(BGP_NODE, &no_neighbor_cmd);
13109 install_element(BGP_NODE, &no_neighbor_interface_config_cmd);
13110
13111 /* "neighbor peer-group" commands. */
13112 install_element(BGP_NODE, &neighbor_peer_group_cmd);
13113 install_element(BGP_NODE, &no_neighbor_peer_group_cmd);
13114 install_element(BGP_NODE,
13115 &no_neighbor_interface_peer_group_remote_as_cmd);
13116
13117 /* "neighbor local-as" commands. */
13118 install_element(BGP_NODE, &neighbor_local_as_cmd);
13119 install_element(BGP_NODE, &neighbor_local_as_no_prepend_cmd);
13120 install_element(BGP_NODE, &neighbor_local_as_no_prepend_replace_as_cmd);
13121 install_element(BGP_NODE, &no_neighbor_local_as_cmd);
13122
13123 /* "neighbor solo" commands. */
13124 install_element(BGP_NODE, &neighbor_solo_cmd);
13125 install_element(BGP_NODE, &no_neighbor_solo_cmd);
13126
13127 /* "neighbor password" commands. */
13128 install_element(BGP_NODE, &neighbor_password_cmd);
13129 install_element(BGP_NODE, &no_neighbor_password_cmd);
13130
13131 /* "neighbor activate" commands. */
13132 install_element(BGP_NODE, &neighbor_activate_hidden_cmd);
13133 install_element(BGP_IPV4_NODE, &neighbor_activate_cmd);
13134 install_element(BGP_IPV4M_NODE, &neighbor_activate_cmd);
13135 install_element(BGP_IPV4L_NODE, &neighbor_activate_cmd);
13136 install_element(BGP_IPV6_NODE, &neighbor_activate_cmd);
13137 install_element(BGP_IPV6M_NODE, &neighbor_activate_cmd);
13138 install_element(BGP_IPV6L_NODE, &neighbor_activate_cmd);
13139 install_element(BGP_VPNV4_NODE, &neighbor_activate_cmd);
13140 install_element(BGP_VPNV6_NODE, &neighbor_activate_cmd);
13141 install_element(BGP_FLOWSPECV4_NODE, &neighbor_activate_cmd);
13142 install_element(BGP_FLOWSPECV6_NODE, &neighbor_activate_cmd);
13143 install_element(BGP_EVPN_NODE, &neighbor_activate_cmd);
13144
13145 /* "no neighbor activate" commands. */
13146 install_element(BGP_NODE, &no_neighbor_activate_hidden_cmd);
13147 install_element(BGP_IPV4_NODE, &no_neighbor_activate_cmd);
13148 install_element(BGP_IPV4M_NODE, &no_neighbor_activate_cmd);
13149 install_element(BGP_IPV4L_NODE, &no_neighbor_activate_cmd);
13150 install_element(BGP_IPV6_NODE, &no_neighbor_activate_cmd);
13151 install_element(BGP_IPV6M_NODE, &no_neighbor_activate_cmd);
13152 install_element(BGP_IPV6L_NODE, &no_neighbor_activate_cmd);
13153 install_element(BGP_VPNV4_NODE, &no_neighbor_activate_cmd);
13154 install_element(BGP_VPNV6_NODE, &no_neighbor_activate_cmd);
13155 install_element(BGP_FLOWSPECV4_NODE, &no_neighbor_activate_cmd);
13156 install_element(BGP_FLOWSPECV6_NODE, &no_neighbor_activate_cmd);
13157 install_element(BGP_EVPN_NODE, &no_neighbor_activate_cmd);
13158
13159 /* "neighbor peer-group" set commands. */
13160 install_element(BGP_NODE, &neighbor_set_peer_group_cmd);
13161 install_element(BGP_IPV4_NODE, &neighbor_set_peer_group_hidden_cmd);
13162 install_element(BGP_IPV4M_NODE, &neighbor_set_peer_group_hidden_cmd);
13163 install_element(BGP_IPV6_NODE, &neighbor_set_peer_group_hidden_cmd);
13164 install_element(BGP_IPV6M_NODE, &neighbor_set_peer_group_hidden_cmd);
13165 install_element(BGP_IPV6L_NODE, &neighbor_set_peer_group_hidden_cmd);
13166 install_element(BGP_VPNV4_NODE, &neighbor_set_peer_group_hidden_cmd);
13167 install_element(BGP_VPNV6_NODE, &neighbor_set_peer_group_hidden_cmd);
13168 install_element(BGP_FLOWSPECV4_NODE,
13169 &neighbor_set_peer_group_hidden_cmd);
13170 install_element(BGP_FLOWSPECV6_NODE,
13171 &neighbor_set_peer_group_hidden_cmd);
13172
13173 /* "no neighbor peer-group unset" commands. */
13174 install_element(BGP_NODE, &no_neighbor_set_peer_group_cmd);
13175 install_element(BGP_IPV4_NODE, &no_neighbor_set_peer_group_hidden_cmd);
13176 install_element(BGP_IPV4M_NODE, &no_neighbor_set_peer_group_hidden_cmd);
13177 install_element(BGP_IPV6_NODE, &no_neighbor_set_peer_group_hidden_cmd);
13178 install_element(BGP_IPV6M_NODE, &no_neighbor_set_peer_group_hidden_cmd);
13179 install_element(BGP_IPV6L_NODE, &no_neighbor_set_peer_group_hidden_cmd);
13180 install_element(BGP_VPNV4_NODE, &no_neighbor_set_peer_group_hidden_cmd);
13181 install_element(BGP_VPNV6_NODE, &no_neighbor_set_peer_group_hidden_cmd);
13182 install_element(BGP_FLOWSPECV4_NODE,
13183 &no_neighbor_set_peer_group_hidden_cmd);
13184 install_element(BGP_FLOWSPECV6_NODE,
13185 &no_neighbor_set_peer_group_hidden_cmd);
13186
13187 /* "neighbor softreconfiguration inbound" commands.*/
13188 install_element(BGP_NODE, &neighbor_soft_reconfiguration_hidden_cmd);
13189 install_element(BGP_NODE, &no_neighbor_soft_reconfiguration_hidden_cmd);
13190 install_element(BGP_IPV4_NODE, &neighbor_soft_reconfiguration_cmd);
13191 install_element(BGP_IPV4_NODE, &no_neighbor_soft_reconfiguration_cmd);
13192 install_element(BGP_IPV4L_NODE, &neighbor_soft_reconfiguration_cmd);
13193 install_element(BGP_IPV4L_NODE, &no_neighbor_soft_reconfiguration_cmd);
13194 install_element(BGP_IPV4M_NODE, &neighbor_soft_reconfiguration_cmd);
13195 install_element(BGP_IPV4M_NODE, &no_neighbor_soft_reconfiguration_cmd);
13196 install_element(BGP_IPV6_NODE, &neighbor_soft_reconfiguration_cmd);
13197 install_element(BGP_IPV6_NODE, &no_neighbor_soft_reconfiguration_cmd);
13198 install_element(BGP_IPV6M_NODE, &neighbor_soft_reconfiguration_cmd);
13199 install_element(BGP_IPV6M_NODE, &no_neighbor_soft_reconfiguration_cmd);
13200 install_element(BGP_IPV6L_NODE, &neighbor_soft_reconfiguration_cmd);
13201 install_element(BGP_IPV6L_NODE, &no_neighbor_soft_reconfiguration_cmd);
13202 install_element(BGP_VPNV4_NODE, &neighbor_soft_reconfiguration_cmd);
13203 install_element(BGP_VPNV4_NODE, &no_neighbor_soft_reconfiguration_cmd);
13204 install_element(BGP_VPNV6_NODE, &neighbor_soft_reconfiguration_cmd);
13205 install_element(BGP_VPNV6_NODE, &no_neighbor_soft_reconfiguration_cmd);
13206 install_element(BGP_FLOWSPECV4_NODE,
13207 &neighbor_soft_reconfiguration_cmd);
13208 install_element(BGP_FLOWSPECV4_NODE,
13209 &no_neighbor_soft_reconfiguration_cmd);
13210 install_element(BGP_FLOWSPECV6_NODE,
13211 &neighbor_soft_reconfiguration_cmd);
13212 install_element(BGP_FLOWSPECV6_NODE,
13213 &no_neighbor_soft_reconfiguration_cmd);
13214 install_element(BGP_EVPN_NODE, &neighbor_soft_reconfiguration_cmd);
13215 install_element(BGP_EVPN_NODE, &no_neighbor_soft_reconfiguration_cmd);
13216
13217 /* "neighbor attribute-unchanged" commands. */
13218 install_element(BGP_NODE, &neighbor_attr_unchanged_hidden_cmd);
13219 install_element(BGP_NODE, &no_neighbor_attr_unchanged_hidden_cmd);
13220 install_element(BGP_IPV4_NODE, &neighbor_attr_unchanged_cmd);
13221 install_element(BGP_IPV4_NODE, &no_neighbor_attr_unchanged_cmd);
13222 install_element(BGP_IPV4M_NODE, &neighbor_attr_unchanged_cmd);
13223 install_element(BGP_IPV4M_NODE, &no_neighbor_attr_unchanged_cmd);
13224 install_element(BGP_IPV4L_NODE, &neighbor_attr_unchanged_cmd);
13225 install_element(BGP_IPV4L_NODE, &no_neighbor_attr_unchanged_cmd);
13226 install_element(BGP_IPV6_NODE, &neighbor_attr_unchanged_cmd);
13227 install_element(BGP_IPV6_NODE, &no_neighbor_attr_unchanged_cmd);
13228 install_element(BGP_IPV6M_NODE, &neighbor_attr_unchanged_cmd);
13229 install_element(BGP_IPV6M_NODE, &no_neighbor_attr_unchanged_cmd);
13230 install_element(BGP_IPV6L_NODE, &neighbor_attr_unchanged_cmd);
13231 install_element(BGP_IPV6L_NODE, &no_neighbor_attr_unchanged_cmd);
13232 install_element(BGP_VPNV4_NODE, &neighbor_attr_unchanged_cmd);
13233 install_element(BGP_VPNV4_NODE, &no_neighbor_attr_unchanged_cmd);
13234 install_element(BGP_VPNV6_NODE, &neighbor_attr_unchanged_cmd);
13235 install_element(BGP_VPNV6_NODE, &no_neighbor_attr_unchanged_cmd);
13236
13237 install_element(BGP_EVPN_NODE, &neighbor_attr_unchanged_cmd);
13238 install_element(BGP_EVPN_NODE, &no_neighbor_attr_unchanged_cmd);
13239
13240 /* "nexthop-local unchanged" commands */
13241 install_element(BGP_IPV6_NODE, &neighbor_nexthop_local_unchanged_cmd);
13242 install_element(BGP_IPV6_NODE,
13243 &no_neighbor_nexthop_local_unchanged_cmd);
13244
13245 /* "neighbor next-hop-self" commands. */
13246 install_element(BGP_NODE, &neighbor_nexthop_self_hidden_cmd);
13247 install_element(BGP_NODE, &no_neighbor_nexthop_self_hidden_cmd);
13248 install_element(BGP_IPV4_NODE, &neighbor_nexthop_self_cmd);
13249 install_element(BGP_IPV4_NODE, &no_neighbor_nexthop_self_cmd);
13250 install_element(BGP_IPV4M_NODE, &neighbor_nexthop_self_cmd);
13251 install_element(BGP_IPV4M_NODE, &no_neighbor_nexthop_self_cmd);
13252 install_element(BGP_IPV4L_NODE, &neighbor_nexthop_self_cmd);
13253 install_element(BGP_IPV4L_NODE, &no_neighbor_nexthop_self_cmd);
13254 install_element(BGP_IPV6_NODE, &neighbor_nexthop_self_cmd);
13255 install_element(BGP_IPV6_NODE, &no_neighbor_nexthop_self_cmd);
13256 install_element(BGP_IPV6M_NODE, &neighbor_nexthop_self_cmd);
13257 install_element(BGP_IPV6M_NODE, &no_neighbor_nexthop_self_cmd);
13258 install_element(BGP_IPV6L_NODE, &neighbor_nexthop_self_cmd);
13259 install_element(BGP_IPV6L_NODE, &no_neighbor_nexthop_self_cmd);
13260 install_element(BGP_VPNV4_NODE, &neighbor_nexthop_self_cmd);
13261 install_element(BGP_VPNV4_NODE, &no_neighbor_nexthop_self_cmd);
13262 install_element(BGP_VPNV6_NODE, &neighbor_nexthop_self_cmd);
13263 install_element(BGP_VPNV6_NODE, &no_neighbor_nexthop_self_cmd);
13264 install_element(BGP_EVPN_NODE, &neighbor_nexthop_self_cmd);
13265 install_element(BGP_EVPN_NODE, &no_neighbor_nexthop_self_cmd);
13266
13267 /* "neighbor next-hop-self force" commands. */
13268 install_element(BGP_NODE, &neighbor_nexthop_self_force_hidden_cmd);
13269 install_element(BGP_NODE, &no_neighbor_nexthop_self_force_hidden_cmd);
13270 install_element(BGP_NODE, &neighbor_nexthop_self_all_hidden_cmd);
13271 install_element(BGP_NODE, &no_neighbor_nexthop_self_all_hidden_cmd);
13272 install_element(BGP_IPV4_NODE, &neighbor_nexthop_self_force_cmd);
13273 install_element(BGP_IPV4_NODE, &no_neighbor_nexthop_self_force_cmd);
13274 install_element(BGP_IPV4_NODE, &neighbor_nexthop_self_all_hidden_cmd);
13275 install_element(BGP_IPV4_NODE,
13276 &no_neighbor_nexthop_self_all_hidden_cmd);
13277 install_element(BGP_IPV4M_NODE, &neighbor_nexthop_self_force_cmd);
13278 install_element(BGP_IPV4M_NODE, &no_neighbor_nexthop_self_force_cmd);
13279 install_element(BGP_IPV4M_NODE, &neighbor_nexthop_self_all_hidden_cmd);
13280 install_element(BGP_IPV4M_NODE,
13281 &no_neighbor_nexthop_self_all_hidden_cmd);
13282 install_element(BGP_IPV4L_NODE, &neighbor_nexthop_self_force_cmd);
13283 install_element(BGP_IPV4L_NODE, &no_neighbor_nexthop_self_force_cmd);
13284 install_element(BGP_IPV4L_NODE, &neighbor_nexthop_self_all_hidden_cmd);
13285 install_element(BGP_IPV4L_NODE,
13286 &no_neighbor_nexthop_self_all_hidden_cmd);
13287 install_element(BGP_IPV6_NODE, &neighbor_nexthop_self_force_cmd);
13288 install_element(BGP_IPV6_NODE, &no_neighbor_nexthop_self_force_cmd);
13289 install_element(BGP_IPV6_NODE, &neighbor_nexthop_self_all_hidden_cmd);
13290 install_element(BGP_IPV6_NODE,
13291 &no_neighbor_nexthop_self_all_hidden_cmd);
13292 install_element(BGP_IPV6M_NODE, &neighbor_nexthop_self_force_cmd);
13293 install_element(BGP_IPV6M_NODE, &no_neighbor_nexthop_self_force_cmd);
13294 install_element(BGP_IPV6M_NODE, &neighbor_nexthop_self_all_hidden_cmd);
13295 install_element(BGP_IPV6M_NODE,
13296 &no_neighbor_nexthop_self_all_hidden_cmd);
13297 install_element(BGP_IPV6L_NODE, &neighbor_nexthop_self_force_cmd);
13298 install_element(BGP_IPV6L_NODE, &no_neighbor_nexthop_self_force_cmd);
13299 install_element(BGP_IPV6L_NODE, &neighbor_nexthop_self_all_hidden_cmd);
13300 install_element(BGP_IPV6L_NODE,
13301 &no_neighbor_nexthop_self_all_hidden_cmd);
13302 install_element(BGP_VPNV4_NODE, &neighbor_nexthop_self_force_cmd);
13303 install_element(BGP_VPNV4_NODE, &no_neighbor_nexthop_self_force_cmd);
13304 install_element(BGP_VPNV4_NODE, &neighbor_nexthop_self_all_hidden_cmd);
13305 install_element(BGP_VPNV4_NODE,
13306 &no_neighbor_nexthop_self_all_hidden_cmd);
13307 install_element(BGP_VPNV6_NODE, &neighbor_nexthop_self_force_cmd);
13308 install_element(BGP_VPNV6_NODE, &no_neighbor_nexthop_self_force_cmd);
13309 install_element(BGP_VPNV6_NODE, &neighbor_nexthop_self_all_hidden_cmd);
13310 install_element(BGP_VPNV6_NODE,
13311 &no_neighbor_nexthop_self_all_hidden_cmd);
13312
13313 /* "neighbor as-override" commands. */
13314 install_element(BGP_NODE, &neighbor_as_override_hidden_cmd);
13315 install_element(BGP_NODE, &no_neighbor_as_override_hidden_cmd);
13316 install_element(BGP_IPV4_NODE, &neighbor_as_override_cmd);
13317 install_element(BGP_IPV4_NODE, &no_neighbor_as_override_cmd);
13318 install_element(BGP_IPV4M_NODE, &neighbor_as_override_cmd);
13319 install_element(BGP_IPV4M_NODE, &no_neighbor_as_override_cmd);
13320 install_element(BGP_IPV4L_NODE, &neighbor_as_override_cmd);
13321 install_element(BGP_IPV4L_NODE, &no_neighbor_as_override_cmd);
13322 install_element(BGP_IPV6_NODE, &neighbor_as_override_cmd);
13323 install_element(BGP_IPV6_NODE, &no_neighbor_as_override_cmd);
13324 install_element(BGP_IPV6M_NODE, &neighbor_as_override_cmd);
13325 install_element(BGP_IPV6M_NODE, &no_neighbor_as_override_cmd);
13326 install_element(BGP_IPV6L_NODE, &neighbor_as_override_cmd);
13327 install_element(BGP_IPV6L_NODE, &no_neighbor_as_override_cmd);
13328 install_element(BGP_VPNV4_NODE, &neighbor_as_override_cmd);
13329 install_element(BGP_VPNV4_NODE, &no_neighbor_as_override_cmd);
13330 install_element(BGP_VPNV6_NODE, &neighbor_as_override_cmd);
13331 install_element(BGP_VPNV6_NODE, &no_neighbor_as_override_cmd);
13332
13333 /* "neighbor remove-private-AS" commands. */
13334 install_element(BGP_NODE, &neighbor_remove_private_as_hidden_cmd);
13335 install_element(BGP_NODE, &no_neighbor_remove_private_as_hidden_cmd);
13336 install_element(BGP_NODE, &neighbor_remove_private_as_all_hidden_cmd);
13337 install_element(BGP_NODE,
13338 &no_neighbor_remove_private_as_all_hidden_cmd);
13339 install_element(BGP_NODE,
13340 &neighbor_remove_private_as_replace_as_hidden_cmd);
13341 install_element(BGP_NODE,
13342 &no_neighbor_remove_private_as_replace_as_hidden_cmd);
13343 install_element(BGP_NODE,
13344 &neighbor_remove_private_as_all_replace_as_hidden_cmd);
13345 install_element(
13346 BGP_NODE,
13347 &no_neighbor_remove_private_as_all_replace_as_hidden_cmd);
13348 install_element(BGP_IPV4_NODE, &neighbor_remove_private_as_cmd);
13349 install_element(BGP_IPV4_NODE, &no_neighbor_remove_private_as_cmd);
13350 install_element(BGP_IPV4_NODE, &neighbor_remove_private_as_all_cmd);
13351 install_element(BGP_IPV4_NODE, &no_neighbor_remove_private_as_all_cmd);
13352 install_element(BGP_IPV4_NODE,
13353 &neighbor_remove_private_as_replace_as_cmd);
13354 install_element(BGP_IPV4_NODE,
13355 &no_neighbor_remove_private_as_replace_as_cmd);
13356 install_element(BGP_IPV4_NODE,
13357 &neighbor_remove_private_as_all_replace_as_cmd);
13358 install_element(BGP_IPV4_NODE,
13359 &no_neighbor_remove_private_as_all_replace_as_cmd);
13360 install_element(BGP_IPV4M_NODE, &neighbor_remove_private_as_cmd);
13361 install_element(BGP_IPV4M_NODE, &no_neighbor_remove_private_as_cmd);
13362 install_element(BGP_IPV4M_NODE, &neighbor_remove_private_as_all_cmd);
13363 install_element(BGP_IPV4M_NODE, &no_neighbor_remove_private_as_all_cmd);
13364 install_element(BGP_IPV4M_NODE,
13365 &neighbor_remove_private_as_replace_as_cmd);
13366 install_element(BGP_IPV4M_NODE,
13367 &no_neighbor_remove_private_as_replace_as_cmd);
13368 install_element(BGP_IPV4M_NODE,
13369 &neighbor_remove_private_as_all_replace_as_cmd);
13370 install_element(BGP_IPV4M_NODE,
13371 &no_neighbor_remove_private_as_all_replace_as_cmd);
13372 install_element(BGP_IPV4L_NODE, &neighbor_remove_private_as_cmd);
13373 install_element(BGP_IPV4L_NODE, &no_neighbor_remove_private_as_cmd);
13374 install_element(BGP_IPV4L_NODE, &neighbor_remove_private_as_all_cmd);
13375 install_element(BGP_IPV4L_NODE, &no_neighbor_remove_private_as_all_cmd);
13376 install_element(BGP_IPV4L_NODE,
13377 &neighbor_remove_private_as_replace_as_cmd);
13378 install_element(BGP_IPV4L_NODE,
13379 &no_neighbor_remove_private_as_replace_as_cmd);
13380 install_element(BGP_IPV4L_NODE,
13381 &neighbor_remove_private_as_all_replace_as_cmd);
13382 install_element(BGP_IPV4L_NODE,
13383 &no_neighbor_remove_private_as_all_replace_as_cmd);
13384 install_element(BGP_IPV6_NODE, &neighbor_remove_private_as_cmd);
13385 install_element(BGP_IPV6_NODE, &no_neighbor_remove_private_as_cmd);
13386 install_element(BGP_IPV6_NODE, &neighbor_remove_private_as_all_cmd);
13387 install_element(BGP_IPV6_NODE, &no_neighbor_remove_private_as_all_cmd);
13388 install_element(BGP_IPV6_NODE,
13389 &neighbor_remove_private_as_replace_as_cmd);
13390 install_element(BGP_IPV6_NODE,
13391 &no_neighbor_remove_private_as_replace_as_cmd);
13392 install_element(BGP_IPV6_NODE,
13393 &neighbor_remove_private_as_all_replace_as_cmd);
13394 install_element(BGP_IPV6_NODE,
13395 &no_neighbor_remove_private_as_all_replace_as_cmd);
13396 install_element(BGP_IPV6M_NODE, &neighbor_remove_private_as_cmd);
13397 install_element(BGP_IPV6M_NODE, &no_neighbor_remove_private_as_cmd);
13398 install_element(BGP_IPV6M_NODE, &neighbor_remove_private_as_all_cmd);
13399 install_element(BGP_IPV6M_NODE, &no_neighbor_remove_private_as_all_cmd);
13400 install_element(BGP_IPV6M_NODE,
13401 &neighbor_remove_private_as_replace_as_cmd);
13402 install_element(BGP_IPV6M_NODE,
13403 &no_neighbor_remove_private_as_replace_as_cmd);
13404 install_element(BGP_IPV6M_NODE,
13405 &neighbor_remove_private_as_all_replace_as_cmd);
13406 install_element(BGP_IPV6M_NODE,
13407 &no_neighbor_remove_private_as_all_replace_as_cmd);
13408 install_element(BGP_IPV6L_NODE, &neighbor_remove_private_as_cmd);
13409 install_element(BGP_IPV6L_NODE, &no_neighbor_remove_private_as_cmd);
13410 install_element(BGP_IPV6L_NODE, &neighbor_remove_private_as_all_cmd);
13411 install_element(BGP_IPV6L_NODE, &no_neighbor_remove_private_as_all_cmd);
13412 install_element(BGP_IPV6L_NODE,
13413 &neighbor_remove_private_as_replace_as_cmd);
13414 install_element(BGP_IPV6L_NODE,
13415 &no_neighbor_remove_private_as_replace_as_cmd);
13416 install_element(BGP_IPV6L_NODE,
13417 &neighbor_remove_private_as_all_replace_as_cmd);
13418 install_element(BGP_IPV6L_NODE,
13419 &no_neighbor_remove_private_as_all_replace_as_cmd);
13420 install_element(BGP_VPNV4_NODE, &neighbor_remove_private_as_cmd);
13421 install_element(BGP_VPNV4_NODE, &no_neighbor_remove_private_as_cmd);
13422 install_element(BGP_VPNV4_NODE, &neighbor_remove_private_as_all_cmd);
13423 install_element(BGP_VPNV4_NODE, &no_neighbor_remove_private_as_all_cmd);
13424 install_element(BGP_VPNV4_NODE,
13425 &neighbor_remove_private_as_replace_as_cmd);
13426 install_element(BGP_VPNV4_NODE,
13427 &no_neighbor_remove_private_as_replace_as_cmd);
13428 install_element(BGP_VPNV4_NODE,
13429 &neighbor_remove_private_as_all_replace_as_cmd);
13430 install_element(BGP_VPNV4_NODE,
13431 &no_neighbor_remove_private_as_all_replace_as_cmd);
13432 install_element(BGP_VPNV6_NODE, &neighbor_remove_private_as_cmd);
13433 install_element(BGP_VPNV6_NODE, &no_neighbor_remove_private_as_cmd);
13434 install_element(BGP_VPNV6_NODE, &neighbor_remove_private_as_all_cmd);
13435 install_element(BGP_VPNV6_NODE, &no_neighbor_remove_private_as_all_cmd);
13436 install_element(BGP_VPNV6_NODE,
13437 &neighbor_remove_private_as_replace_as_cmd);
13438 install_element(BGP_VPNV6_NODE,
13439 &no_neighbor_remove_private_as_replace_as_cmd);
13440 install_element(BGP_VPNV6_NODE,
13441 &neighbor_remove_private_as_all_replace_as_cmd);
13442 install_element(BGP_VPNV6_NODE,
13443 &no_neighbor_remove_private_as_all_replace_as_cmd);
13444
13445 /* "neighbor send-community" commands.*/
13446 install_element(BGP_NODE, &neighbor_send_community_hidden_cmd);
13447 install_element(BGP_NODE, &neighbor_send_community_type_hidden_cmd);
13448 install_element(BGP_NODE, &no_neighbor_send_community_hidden_cmd);
13449 install_element(BGP_NODE, &no_neighbor_send_community_type_hidden_cmd);
13450 install_element(BGP_IPV4_NODE, &neighbor_send_community_cmd);
13451 install_element(BGP_IPV4_NODE, &neighbor_send_community_type_cmd);
13452 install_element(BGP_IPV4_NODE, &no_neighbor_send_community_cmd);
13453 install_element(BGP_IPV4_NODE, &no_neighbor_send_community_type_cmd);
13454 install_element(BGP_IPV4M_NODE, &neighbor_send_community_cmd);
13455 install_element(BGP_IPV4M_NODE, &neighbor_send_community_type_cmd);
13456 install_element(BGP_IPV4M_NODE, &no_neighbor_send_community_cmd);
13457 install_element(BGP_IPV4M_NODE, &no_neighbor_send_community_type_cmd);
13458 install_element(BGP_IPV4L_NODE, &neighbor_send_community_cmd);
13459 install_element(BGP_IPV4L_NODE, &neighbor_send_community_type_cmd);
13460 install_element(BGP_IPV4L_NODE, &no_neighbor_send_community_cmd);
13461 install_element(BGP_IPV4L_NODE, &no_neighbor_send_community_type_cmd);
13462 install_element(BGP_IPV6_NODE, &neighbor_send_community_cmd);
13463 install_element(BGP_IPV6_NODE, &neighbor_send_community_type_cmd);
13464 install_element(BGP_IPV6_NODE, &no_neighbor_send_community_cmd);
13465 install_element(BGP_IPV6_NODE, &no_neighbor_send_community_type_cmd);
13466 install_element(BGP_IPV6M_NODE, &neighbor_send_community_cmd);
13467 install_element(BGP_IPV6M_NODE, &neighbor_send_community_type_cmd);
13468 install_element(BGP_IPV6M_NODE, &no_neighbor_send_community_cmd);
13469 install_element(BGP_IPV6M_NODE, &no_neighbor_send_community_type_cmd);
13470 install_element(BGP_IPV6L_NODE, &neighbor_send_community_cmd);
13471 install_element(BGP_IPV6L_NODE, &neighbor_send_community_type_cmd);
13472 install_element(BGP_IPV6L_NODE, &no_neighbor_send_community_cmd);
13473 install_element(BGP_IPV6L_NODE, &no_neighbor_send_community_type_cmd);
13474 install_element(BGP_VPNV4_NODE, &neighbor_send_community_cmd);
13475 install_element(BGP_VPNV4_NODE, &neighbor_send_community_type_cmd);
13476 install_element(BGP_VPNV4_NODE, &no_neighbor_send_community_cmd);
13477 install_element(BGP_VPNV4_NODE, &no_neighbor_send_community_type_cmd);
13478 install_element(BGP_VPNV6_NODE, &neighbor_send_community_cmd);
13479 install_element(BGP_VPNV6_NODE, &neighbor_send_community_type_cmd);
13480 install_element(BGP_VPNV6_NODE, &no_neighbor_send_community_cmd);
13481 install_element(BGP_VPNV6_NODE, &no_neighbor_send_community_type_cmd);
13482
13483 /* "neighbor route-reflector" commands.*/
13484 install_element(BGP_NODE, &neighbor_route_reflector_client_hidden_cmd);
13485 install_element(BGP_NODE,
13486 &no_neighbor_route_reflector_client_hidden_cmd);
13487 install_element(BGP_IPV4_NODE, &neighbor_route_reflector_client_cmd);
13488 install_element(BGP_IPV4_NODE, &no_neighbor_route_reflector_client_cmd);
13489 install_element(BGP_IPV4M_NODE, &neighbor_route_reflector_client_cmd);
13490 install_element(BGP_IPV4M_NODE,
13491 &no_neighbor_route_reflector_client_cmd);
13492 install_element(BGP_IPV4L_NODE, &neighbor_route_reflector_client_cmd);
13493 install_element(BGP_IPV4L_NODE,
13494 &no_neighbor_route_reflector_client_cmd);
13495 install_element(BGP_IPV6_NODE, &neighbor_route_reflector_client_cmd);
13496 install_element(BGP_IPV6_NODE, &no_neighbor_route_reflector_client_cmd);
13497 install_element(BGP_IPV6M_NODE, &neighbor_route_reflector_client_cmd);
13498 install_element(BGP_IPV6M_NODE,
13499 &no_neighbor_route_reflector_client_cmd);
13500 install_element(BGP_IPV6L_NODE, &neighbor_route_reflector_client_cmd);
13501 install_element(BGP_IPV6L_NODE,
13502 &no_neighbor_route_reflector_client_cmd);
13503 install_element(BGP_VPNV4_NODE, &neighbor_route_reflector_client_cmd);
13504 install_element(BGP_VPNV4_NODE,
13505 &no_neighbor_route_reflector_client_cmd);
13506 install_element(BGP_VPNV6_NODE, &neighbor_route_reflector_client_cmd);
13507 install_element(BGP_VPNV6_NODE,
13508 &no_neighbor_route_reflector_client_cmd);
13509 install_element(BGP_FLOWSPECV4_NODE,
13510 &neighbor_route_reflector_client_cmd);
13511 install_element(BGP_FLOWSPECV4_NODE,
13512 &no_neighbor_route_reflector_client_cmd);
13513 install_element(BGP_FLOWSPECV6_NODE,
13514 &neighbor_route_reflector_client_cmd);
13515 install_element(BGP_FLOWSPECV6_NODE,
13516 &no_neighbor_route_reflector_client_cmd);
13517 install_element(BGP_EVPN_NODE, &neighbor_route_reflector_client_cmd);
13518 install_element(BGP_EVPN_NODE, &no_neighbor_route_reflector_client_cmd);
13519
13520 /* "neighbor route-server" commands.*/
13521 install_element(BGP_NODE, &neighbor_route_server_client_hidden_cmd);
13522 install_element(BGP_NODE, &no_neighbor_route_server_client_hidden_cmd);
13523 install_element(BGP_IPV4_NODE, &neighbor_route_server_client_cmd);
13524 install_element(BGP_IPV4_NODE, &no_neighbor_route_server_client_cmd);
13525 install_element(BGP_IPV4M_NODE, &neighbor_route_server_client_cmd);
13526 install_element(BGP_IPV4M_NODE, &no_neighbor_route_server_client_cmd);
13527 install_element(BGP_IPV4L_NODE, &neighbor_route_server_client_cmd);
13528 install_element(BGP_IPV4L_NODE, &no_neighbor_route_server_client_cmd);
13529 install_element(BGP_IPV6_NODE, &neighbor_route_server_client_cmd);
13530 install_element(BGP_IPV6_NODE, &no_neighbor_route_server_client_cmd);
13531 install_element(BGP_IPV6M_NODE, &neighbor_route_server_client_cmd);
13532 install_element(BGP_IPV6M_NODE, &no_neighbor_route_server_client_cmd);
13533 install_element(BGP_IPV6L_NODE, &neighbor_route_server_client_cmd);
13534 install_element(BGP_IPV6L_NODE, &no_neighbor_route_server_client_cmd);
13535 install_element(BGP_VPNV4_NODE, &neighbor_route_server_client_cmd);
13536 install_element(BGP_VPNV4_NODE, &no_neighbor_route_server_client_cmd);
13537 install_element(BGP_VPNV6_NODE, &neighbor_route_server_client_cmd);
13538 install_element(BGP_VPNV6_NODE, &no_neighbor_route_server_client_cmd);
13539 install_element(BGP_EVPN_NODE, &neighbor_route_server_client_cmd);
13540 install_element(BGP_EVPN_NODE, &no_neighbor_route_server_client_cmd);
13541 install_element(BGP_FLOWSPECV4_NODE, &neighbor_route_server_client_cmd);
13542 install_element(BGP_FLOWSPECV4_NODE,
13543 &no_neighbor_route_server_client_cmd);
13544 install_element(BGP_FLOWSPECV6_NODE, &neighbor_route_server_client_cmd);
13545 install_element(BGP_FLOWSPECV6_NODE,
13546 &no_neighbor_route_server_client_cmd);
13547
13548 /* "neighbor addpath-tx-all-paths" commands.*/
13549 install_element(BGP_NODE, &neighbor_addpath_tx_all_paths_hidden_cmd);
13550 install_element(BGP_NODE, &no_neighbor_addpath_tx_all_paths_hidden_cmd);
13551 install_element(BGP_IPV4_NODE, &neighbor_addpath_tx_all_paths_cmd);
13552 install_element(BGP_IPV4_NODE, &no_neighbor_addpath_tx_all_paths_cmd);
13553 install_element(BGP_IPV4M_NODE, &neighbor_addpath_tx_all_paths_cmd);
13554 install_element(BGP_IPV4M_NODE, &no_neighbor_addpath_tx_all_paths_cmd);
13555 install_element(BGP_IPV4L_NODE, &neighbor_addpath_tx_all_paths_cmd);
13556 install_element(BGP_IPV4L_NODE, &no_neighbor_addpath_tx_all_paths_cmd);
13557 install_element(BGP_IPV6_NODE, &neighbor_addpath_tx_all_paths_cmd);
13558 install_element(BGP_IPV6_NODE, &no_neighbor_addpath_tx_all_paths_cmd);
13559 install_element(BGP_IPV6M_NODE, &neighbor_addpath_tx_all_paths_cmd);
13560 install_element(BGP_IPV6M_NODE, &no_neighbor_addpath_tx_all_paths_cmd);
13561 install_element(BGP_IPV6L_NODE, &neighbor_addpath_tx_all_paths_cmd);
13562 install_element(BGP_IPV6L_NODE, &no_neighbor_addpath_tx_all_paths_cmd);
13563 install_element(BGP_VPNV4_NODE, &neighbor_addpath_tx_all_paths_cmd);
13564 install_element(BGP_VPNV4_NODE, &no_neighbor_addpath_tx_all_paths_cmd);
13565 install_element(BGP_VPNV6_NODE, &neighbor_addpath_tx_all_paths_cmd);
13566 install_element(BGP_VPNV6_NODE, &no_neighbor_addpath_tx_all_paths_cmd);
13567
13568 /* "neighbor addpath-tx-bestpath-per-AS" commands.*/
13569 install_element(BGP_NODE,
13570 &neighbor_addpath_tx_bestpath_per_as_hidden_cmd);
13571 install_element(BGP_NODE,
13572 &no_neighbor_addpath_tx_bestpath_per_as_hidden_cmd);
13573 install_element(BGP_IPV4_NODE,
13574 &neighbor_addpath_tx_bestpath_per_as_cmd);
13575 install_element(BGP_IPV4_NODE,
13576 &no_neighbor_addpath_tx_bestpath_per_as_cmd);
13577 install_element(BGP_IPV4M_NODE,
13578 &neighbor_addpath_tx_bestpath_per_as_cmd);
13579 install_element(BGP_IPV4M_NODE,
13580 &no_neighbor_addpath_tx_bestpath_per_as_cmd);
13581 install_element(BGP_IPV4L_NODE,
13582 &neighbor_addpath_tx_bestpath_per_as_cmd);
13583 install_element(BGP_IPV4L_NODE,
13584 &no_neighbor_addpath_tx_bestpath_per_as_cmd);
13585 install_element(BGP_IPV6_NODE,
13586 &neighbor_addpath_tx_bestpath_per_as_cmd);
13587 install_element(BGP_IPV6_NODE,
13588 &no_neighbor_addpath_tx_bestpath_per_as_cmd);
13589 install_element(BGP_IPV6M_NODE,
13590 &neighbor_addpath_tx_bestpath_per_as_cmd);
13591 install_element(BGP_IPV6M_NODE,
13592 &no_neighbor_addpath_tx_bestpath_per_as_cmd);
13593 install_element(BGP_IPV6L_NODE,
13594 &neighbor_addpath_tx_bestpath_per_as_cmd);
13595 install_element(BGP_IPV6L_NODE,
13596 &no_neighbor_addpath_tx_bestpath_per_as_cmd);
13597 install_element(BGP_VPNV4_NODE,
13598 &neighbor_addpath_tx_bestpath_per_as_cmd);
13599 install_element(BGP_VPNV4_NODE,
13600 &no_neighbor_addpath_tx_bestpath_per_as_cmd);
13601 install_element(BGP_VPNV6_NODE,
13602 &neighbor_addpath_tx_bestpath_per_as_cmd);
13603 install_element(BGP_VPNV6_NODE,
13604 &no_neighbor_addpath_tx_bestpath_per_as_cmd);
13605
13606 /* "neighbor passive" commands. */
13607 install_element(BGP_NODE, &neighbor_passive_cmd);
13608 install_element(BGP_NODE, &no_neighbor_passive_cmd);
13609
13610
13611 /* "neighbor shutdown" commands. */
13612 install_element(BGP_NODE, &neighbor_shutdown_cmd);
13613 install_element(BGP_NODE, &no_neighbor_shutdown_cmd);
13614 install_element(BGP_NODE, &neighbor_shutdown_msg_cmd);
13615 install_element(BGP_NODE, &no_neighbor_shutdown_msg_cmd);
13616
13617 /* "neighbor capability extended-nexthop" commands.*/
13618 install_element(BGP_NODE, &neighbor_capability_enhe_cmd);
13619 install_element(BGP_NODE, &no_neighbor_capability_enhe_cmd);
13620
13621 /* "neighbor capability orf prefix-list" commands.*/
13622 install_element(BGP_NODE, &neighbor_capability_orf_prefix_hidden_cmd);
13623 install_element(BGP_NODE,
13624 &no_neighbor_capability_orf_prefix_hidden_cmd);
13625 install_element(BGP_IPV4_NODE, &neighbor_capability_orf_prefix_cmd);
13626 install_element(BGP_IPV4_NODE, &no_neighbor_capability_orf_prefix_cmd);
13627 install_element(BGP_IPV4M_NODE, &neighbor_capability_orf_prefix_cmd);
13628 install_element(BGP_IPV4M_NODE, &no_neighbor_capability_orf_prefix_cmd);
13629 install_element(BGP_IPV4L_NODE, &neighbor_capability_orf_prefix_cmd);
13630 install_element(BGP_IPV4L_NODE, &no_neighbor_capability_orf_prefix_cmd);
13631 install_element(BGP_IPV6_NODE, &neighbor_capability_orf_prefix_cmd);
13632 install_element(BGP_IPV6_NODE, &no_neighbor_capability_orf_prefix_cmd);
13633 install_element(BGP_IPV6M_NODE, &neighbor_capability_orf_prefix_cmd);
13634 install_element(BGP_IPV6M_NODE, &no_neighbor_capability_orf_prefix_cmd);
13635 install_element(BGP_IPV6L_NODE, &neighbor_capability_orf_prefix_cmd);
13636 install_element(BGP_IPV6L_NODE, &no_neighbor_capability_orf_prefix_cmd);
13637
13638 /* "neighbor capability dynamic" commands.*/
13639 install_element(BGP_NODE, &neighbor_capability_dynamic_cmd);
13640 install_element(BGP_NODE, &no_neighbor_capability_dynamic_cmd);
13641
13642 /* "neighbor dont-capability-negotiate" commands. */
13643 install_element(BGP_NODE, &neighbor_dont_capability_negotiate_cmd);
13644 install_element(BGP_NODE, &no_neighbor_dont_capability_negotiate_cmd);
13645
13646 /* "neighbor ebgp-multihop" commands. */
13647 install_element(BGP_NODE, &neighbor_ebgp_multihop_cmd);
13648 install_element(BGP_NODE, &neighbor_ebgp_multihop_ttl_cmd);
13649 install_element(BGP_NODE, &no_neighbor_ebgp_multihop_cmd);
13650
13651 /* "neighbor disable-connected-check" commands. */
13652 install_element(BGP_NODE, &neighbor_disable_connected_check_cmd);
13653 install_element(BGP_NODE, &no_neighbor_disable_connected_check_cmd);
13654
13655 /* "neighbor enforce-first-as" commands. */
13656 install_element(BGP_NODE, &neighbor_enforce_first_as_cmd);
13657 install_element(BGP_NODE, &no_neighbor_enforce_first_as_cmd);
13658
13659 /* "neighbor description" commands. */
13660 install_element(BGP_NODE, &neighbor_description_cmd);
13661 install_element(BGP_NODE, &no_neighbor_description_cmd);
13662 install_element(BGP_NODE, &no_neighbor_description_comment_cmd);
13663
13664 /* "neighbor update-source" commands. "*/
13665 install_element(BGP_NODE, &neighbor_update_source_cmd);
13666 install_element(BGP_NODE, &no_neighbor_update_source_cmd);
13667
13668 /* "neighbor default-originate" commands. */
13669 install_element(BGP_NODE, &neighbor_default_originate_hidden_cmd);
13670 install_element(BGP_NODE, &neighbor_default_originate_rmap_hidden_cmd);
13671 install_element(BGP_NODE, &no_neighbor_default_originate_hidden_cmd);
13672 install_element(BGP_IPV4_NODE, &neighbor_default_originate_cmd);
13673 install_element(BGP_IPV4_NODE, &neighbor_default_originate_rmap_cmd);
13674 install_element(BGP_IPV4_NODE, &no_neighbor_default_originate_cmd);
13675 install_element(BGP_IPV4M_NODE, &neighbor_default_originate_cmd);
13676 install_element(BGP_IPV4M_NODE, &neighbor_default_originate_rmap_cmd);
13677 install_element(BGP_IPV4M_NODE, &no_neighbor_default_originate_cmd);
13678 install_element(BGP_IPV4L_NODE, &neighbor_default_originate_cmd);
13679 install_element(BGP_IPV4L_NODE, &neighbor_default_originate_rmap_cmd);
13680 install_element(BGP_IPV4L_NODE, &no_neighbor_default_originate_cmd);
13681 install_element(BGP_IPV6_NODE, &neighbor_default_originate_cmd);
13682 install_element(BGP_IPV6_NODE, &neighbor_default_originate_rmap_cmd);
13683 install_element(BGP_IPV6_NODE, &no_neighbor_default_originate_cmd);
13684 install_element(BGP_IPV6M_NODE, &neighbor_default_originate_cmd);
13685 install_element(BGP_IPV6M_NODE, &neighbor_default_originate_rmap_cmd);
13686 install_element(BGP_IPV6M_NODE, &no_neighbor_default_originate_cmd);
13687 install_element(BGP_IPV6L_NODE, &neighbor_default_originate_cmd);
13688 install_element(BGP_IPV6L_NODE, &neighbor_default_originate_rmap_cmd);
13689 install_element(BGP_IPV6L_NODE, &no_neighbor_default_originate_cmd);
13690
13691 /* "neighbor port" commands. */
13692 install_element(BGP_NODE, &neighbor_port_cmd);
13693 install_element(BGP_NODE, &no_neighbor_port_cmd);
13694
13695 /* "neighbor weight" commands. */
13696 install_element(BGP_NODE, &neighbor_weight_hidden_cmd);
13697 install_element(BGP_NODE, &no_neighbor_weight_hidden_cmd);
13698
13699 install_element(BGP_IPV4_NODE, &neighbor_weight_cmd);
13700 install_element(BGP_IPV4_NODE, &no_neighbor_weight_cmd);
13701 install_element(BGP_IPV4M_NODE, &neighbor_weight_cmd);
13702 install_element(BGP_IPV4M_NODE, &no_neighbor_weight_cmd);
13703 install_element(BGP_IPV4L_NODE, &neighbor_weight_cmd);
13704 install_element(BGP_IPV4L_NODE, &no_neighbor_weight_cmd);
13705 install_element(BGP_IPV6_NODE, &neighbor_weight_cmd);
13706 install_element(BGP_IPV6_NODE, &no_neighbor_weight_cmd);
13707 install_element(BGP_IPV6M_NODE, &neighbor_weight_cmd);
13708 install_element(BGP_IPV6M_NODE, &no_neighbor_weight_cmd);
13709 install_element(BGP_IPV6L_NODE, &neighbor_weight_cmd);
13710 install_element(BGP_IPV6L_NODE, &no_neighbor_weight_cmd);
13711 install_element(BGP_VPNV4_NODE, &neighbor_weight_cmd);
13712 install_element(BGP_VPNV4_NODE, &no_neighbor_weight_cmd);
13713 install_element(BGP_VPNV6_NODE, &neighbor_weight_cmd);
13714 install_element(BGP_VPNV6_NODE, &no_neighbor_weight_cmd);
13715
13716 /* "neighbor override-capability" commands. */
13717 install_element(BGP_NODE, &neighbor_override_capability_cmd);
13718 install_element(BGP_NODE, &no_neighbor_override_capability_cmd);
13719
13720 /* "neighbor strict-capability-match" commands. */
13721 install_element(BGP_NODE, &neighbor_strict_capability_cmd);
13722 install_element(BGP_NODE, &no_neighbor_strict_capability_cmd);
13723
13724 /* "neighbor timers" commands. */
13725 install_element(BGP_NODE, &neighbor_timers_cmd);
13726 install_element(BGP_NODE, &no_neighbor_timers_cmd);
13727
13728 /* "neighbor timers connect" commands. */
13729 install_element(BGP_NODE, &neighbor_timers_connect_cmd);
13730 install_element(BGP_NODE, &no_neighbor_timers_connect_cmd);
13731
13732 /* "neighbor advertisement-interval" commands. */
13733 install_element(BGP_NODE, &neighbor_advertise_interval_cmd);
13734 install_element(BGP_NODE, &no_neighbor_advertise_interval_cmd);
13735
13736 /* "neighbor interface" commands. */
13737 install_element(BGP_NODE, &neighbor_interface_cmd);
13738 install_element(BGP_NODE, &no_neighbor_interface_cmd);
13739
13740 /* "neighbor distribute" commands. */
13741 install_element(BGP_NODE, &neighbor_distribute_list_hidden_cmd);
13742 install_element(BGP_NODE, &no_neighbor_distribute_list_hidden_cmd);
13743 install_element(BGP_IPV4_NODE, &neighbor_distribute_list_cmd);
13744 install_element(BGP_IPV4_NODE, &no_neighbor_distribute_list_cmd);
13745 install_element(BGP_IPV4M_NODE, &neighbor_distribute_list_cmd);
13746 install_element(BGP_IPV4M_NODE, &no_neighbor_distribute_list_cmd);
13747 install_element(BGP_IPV4L_NODE, &neighbor_distribute_list_cmd);
13748 install_element(BGP_IPV4L_NODE, &no_neighbor_distribute_list_cmd);
13749 install_element(BGP_IPV6_NODE, &neighbor_distribute_list_cmd);
13750 install_element(BGP_IPV6_NODE, &no_neighbor_distribute_list_cmd);
13751 install_element(BGP_IPV6M_NODE, &neighbor_distribute_list_cmd);
13752 install_element(BGP_IPV6M_NODE, &no_neighbor_distribute_list_cmd);
13753 install_element(BGP_IPV6L_NODE, &neighbor_distribute_list_cmd);
13754 install_element(BGP_IPV6L_NODE, &no_neighbor_distribute_list_cmd);
13755 install_element(BGP_VPNV4_NODE, &neighbor_distribute_list_cmd);
13756 install_element(BGP_VPNV4_NODE, &no_neighbor_distribute_list_cmd);
13757 install_element(BGP_VPNV6_NODE, &neighbor_distribute_list_cmd);
13758 install_element(BGP_VPNV6_NODE, &no_neighbor_distribute_list_cmd);
13759
13760 /* "neighbor prefix-list" commands. */
13761 install_element(BGP_NODE, &neighbor_prefix_list_hidden_cmd);
13762 install_element(BGP_NODE, &no_neighbor_prefix_list_hidden_cmd);
13763 install_element(BGP_IPV4_NODE, &neighbor_prefix_list_cmd);
13764 install_element(BGP_IPV4_NODE, &no_neighbor_prefix_list_cmd);
13765 install_element(BGP_IPV4M_NODE, &neighbor_prefix_list_cmd);
13766 install_element(BGP_IPV4M_NODE, &no_neighbor_prefix_list_cmd);
13767 install_element(BGP_IPV4L_NODE, &neighbor_prefix_list_cmd);
13768 install_element(BGP_IPV4L_NODE, &no_neighbor_prefix_list_cmd);
13769 install_element(BGP_IPV6_NODE, &neighbor_prefix_list_cmd);
13770 install_element(BGP_IPV6_NODE, &no_neighbor_prefix_list_cmd);
13771 install_element(BGP_IPV6M_NODE, &neighbor_prefix_list_cmd);
13772 install_element(BGP_IPV6M_NODE, &no_neighbor_prefix_list_cmd);
13773 install_element(BGP_IPV6L_NODE, &neighbor_prefix_list_cmd);
13774 install_element(BGP_IPV6L_NODE, &no_neighbor_prefix_list_cmd);
13775 install_element(BGP_VPNV4_NODE, &neighbor_prefix_list_cmd);
13776 install_element(BGP_VPNV4_NODE, &no_neighbor_prefix_list_cmd);
13777 install_element(BGP_VPNV6_NODE, &neighbor_prefix_list_cmd);
13778 install_element(BGP_VPNV6_NODE, &no_neighbor_prefix_list_cmd);
13779 install_element(BGP_FLOWSPECV4_NODE, &neighbor_prefix_list_cmd);
13780 install_element(BGP_FLOWSPECV4_NODE, &no_neighbor_prefix_list_cmd);
13781 install_element(BGP_FLOWSPECV6_NODE, &neighbor_prefix_list_cmd);
13782 install_element(BGP_FLOWSPECV6_NODE, &no_neighbor_prefix_list_cmd);
13783
13784 /* "neighbor filter-list" commands. */
13785 install_element(BGP_NODE, &neighbor_filter_list_hidden_cmd);
13786 install_element(BGP_NODE, &no_neighbor_filter_list_hidden_cmd);
13787 install_element(BGP_IPV4_NODE, &neighbor_filter_list_cmd);
13788 install_element(BGP_IPV4_NODE, &no_neighbor_filter_list_cmd);
13789 install_element(BGP_IPV4M_NODE, &neighbor_filter_list_cmd);
13790 install_element(BGP_IPV4M_NODE, &no_neighbor_filter_list_cmd);
13791 install_element(BGP_IPV4L_NODE, &neighbor_filter_list_cmd);
13792 install_element(BGP_IPV4L_NODE, &no_neighbor_filter_list_cmd);
13793 install_element(BGP_IPV6_NODE, &neighbor_filter_list_cmd);
13794 install_element(BGP_IPV6_NODE, &no_neighbor_filter_list_cmd);
13795 install_element(BGP_IPV6M_NODE, &neighbor_filter_list_cmd);
13796 install_element(BGP_IPV6M_NODE, &no_neighbor_filter_list_cmd);
13797 install_element(BGP_IPV6L_NODE, &neighbor_filter_list_cmd);
13798 install_element(BGP_IPV6L_NODE, &no_neighbor_filter_list_cmd);
13799 install_element(BGP_VPNV4_NODE, &neighbor_filter_list_cmd);
13800 install_element(BGP_VPNV4_NODE, &no_neighbor_filter_list_cmd);
13801 install_element(BGP_VPNV6_NODE, &neighbor_filter_list_cmd);
13802 install_element(BGP_VPNV6_NODE, &no_neighbor_filter_list_cmd);
13803 install_element(BGP_FLOWSPECV4_NODE, &neighbor_filter_list_cmd);
13804 install_element(BGP_FLOWSPECV4_NODE, &no_neighbor_filter_list_cmd);
13805 install_element(BGP_FLOWSPECV6_NODE, &neighbor_filter_list_cmd);
13806 install_element(BGP_FLOWSPECV6_NODE, &no_neighbor_filter_list_cmd);
13807
13808 /* "neighbor route-map" commands. */
13809 install_element(BGP_NODE, &neighbor_route_map_hidden_cmd);
13810 install_element(BGP_NODE, &no_neighbor_route_map_hidden_cmd);
13811 install_element(BGP_IPV4_NODE, &neighbor_route_map_cmd);
13812 install_element(BGP_IPV4_NODE, &no_neighbor_route_map_cmd);
13813 install_element(BGP_IPV4M_NODE, &neighbor_route_map_cmd);
13814 install_element(BGP_IPV4M_NODE, &no_neighbor_route_map_cmd);
13815 install_element(BGP_IPV4L_NODE, &neighbor_route_map_cmd);
13816 install_element(BGP_IPV4L_NODE, &no_neighbor_route_map_cmd);
13817 install_element(BGP_IPV6_NODE, &neighbor_route_map_cmd);
13818 install_element(BGP_IPV6_NODE, &no_neighbor_route_map_cmd);
13819 install_element(BGP_IPV6M_NODE, &neighbor_route_map_cmd);
13820 install_element(BGP_IPV6M_NODE, &no_neighbor_route_map_cmd);
13821 install_element(BGP_IPV6L_NODE, &neighbor_route_map_cmd);
13822 install_element(BGP_IPV6L_NODE, &no_neighbor_route_map_cmd);
13823 install_element(BGP_VPNV4_NODE, &neighbor_route_map_cmd);
13824 install_element(BGP_VPNV4_NODE, &no_neighbor_route_map_cmd);
13825 install_element(BGP_VPNV6_NODE, &neighbor_route_map_cmd);
13826 install_element(BGP_VPNV6_NODE, &no_neighbor_route_map_cmd);
13827 install_element(BGP_FLOWSPECV4_NODE, &neighbor_route_map_cmd);
13828 install_element(BGP_FLOWSPECV4_NODE, &no_neighbor_route_map_cmd);
13829 install_element(BGP_FLOWSPECV6_NODE, &neighbor_route_map_cmd);
13830 install_element(BGP_FLOWSPECV6_NODE, &no_neighbor_route_map_cmd);
13831 install_element(BGP_EVPN_NODE, &neighbor_route_map_cmd);
13832 install_element(BGP_EVPN_NODE, &no_neighbor_route_map_cmd);
13833
13834 /* "neighbor unsuppress-map" commands. */
13835 install_element(BGP_NODE, &neighbor_unsuppress_map_hidden_cmd);
13836 install_element(BGP_NODE, &no_neighbor_unsuppress_map_hidden_cmd);
13837 install_element(BGP_IPV4_NODE, &neighbor_unsuppress_map_cmd);
13838 install_element(BGP_IPV4_NODE, &no_neighbor_unsuppress_map_cmd);
13839 install_element(BGP_IPV4M_NODE, &neighbor_unsuppress_map_cmd);
13840 install_element(BGP_IPV4M_NODE, &no_neighbor_unsuppress_map_cmd);
13841 install_element(BGP_IPV4L_NODE, &neighbor_unsuppress_map_cmd);
13842 install_element(BGP_IPV4L_NODE, &no_neighbor_unsuppress_map_cmd);
13843 install_element(BGP_IPV6_NODE, &neighbor_unsuppress_map_cmd);
13844 install_element(BGP_IPV6_NODE, &no_neighbor_unsuppress_map_cmd);
13845 install_element(BGP_IPV6M_NODE, &neighbor_unsuppress_map_cmd);
13846 install_element(BGP_IPV6M_NODE, &no_neighbor_unsuppress_map_cmd);
13847 install_element(BGP_IPV6L_NODE, &neighbor_unsuppress_map_cmd);
13848 install_element(BGP_IPV6L_NODE, &no_neighbor_unsuppress_map_cmd);
13849 install_element(BGP_VPNV4_NODE, &neighbor_unsuppress_map_cmd);
13850 install_element(BGP_VPNV4_NODE, &no_neighbor_unsuppress_map_cmd);
13851 install_element(BGP_VPNV6_NODE, &neighbor_unsuppress_map_cmd);
13852 install_element(BGP_VPNV6_NODE, &no_neighbor_unsuppress_map_cmd);
13853
13854 /* "neighbor maximum-prefix" commands. */
13855 install_element(BGP_NODE, &neighbor_maximum_prefix_hidden_cmd);
13856 install_element(BGP_NODE,
13857 &neighbor_maximum_prefix_threshold_hidden_cmd);
13858 install_element(BGP_NODE, &neighbor_maximum_prefix_warning_hidden_cmd);
13859 install_element(BGP_NODE,
13860 &neighbor_maximum_prefix_threshold_warning_hidden_cmd);
13861 install_element(BGP_NODE, &neighbor_maximum_prefix_restart_hidden_cmd);
13862 install_element(BGP_NODE,
13863 &neighbor_maximum_prefix_threshold_restart_hidden_cmd);
13864 install_element(BGP_NODE, &no_neighbor_maximum_prefix_hidden_cmd);
13865 install_element(BGP_IPV4_NODE, &neighbor_maximum_prefix_cmd);
13866 install_element(BGP_IPV4_NODE, &neighbor_maximum_prefix_threshold_cmd);
13867 install_element(BGP_IPV4_NODE, &neighbor_maximum_prefix_warning_cmd);
13868 install_element(BGP_IPV4_NODE,
13869 &neighbor_maximum_prefix_threshold_warning_cmd);
13870 install_element(BGP_IPV4_NODE, &neighbor_maximum_prefix_restart_cmd);
13871 install_element(BGP_IPV4_NODE,
13872 &neighbor_maximum_prefix_threshold_restart_cmd);
13873 install_element(BGP_IPV4_NODE, &no_neighbor_maximum_prefix_cmd);
13874 install_element(BGP_IPV4M_NODE, &neighbor_maximum_prefix_cmd);
13875 install_element(BGP_IPV4M_NODE, &neighbor_maximum_prefix_threshold_cmd);
13876 install_element(BGP_IPV4M_NODE, &neighbor_maximum_prefix_warning_cmd);
13877 install_element(BGP_IPV4M_NODE,
13878 &neighbor_maximum_prefix_threshold_warning_cmd);
13879 install_element(BGP_IPV4M_NODE, &neighbor_maximum_prefix_restart_cmd);
13880 install_element(BGP_IPV4M_NODE,
13881 &neighbor_maximum_prefix_threshold_restart_cmd);
13882 install_element(BGP_IPV4M_NODE, &no_neighbor_maximum_prefix_cmd);
13883 install_element(BGP_IPV4L_NODE, &neighbor_maximum_prefix_cmd);
13884 install_element(BGP_IPV4L_NODE, &neighbor_maximum_prefix_threshold_cmd);
13885 install_element(BGP_IPV4L_NODE, &neighbor_maximum_prefix_warning_cmd);
13886 install_element(BGP_IPV4L_NODE,
13887 &neighbor_maximum_prefix_threshold_warning_cmd);
13888 install_element(BGP_IPV4L_NODE, &neighbor_maximum_prefix_restart_cmd);
13889 install_element(BGP_IPV4L_NODE,
13890 &neighbor_maximum_prefix_threshold_restart_cmd);
13891 install_element(BGP_IPV4L_NODE, &no_neighbor_maximum_prefix_cmd);
13892 install_element(BGP_IPV6_NODE, &neighbor_maximum_prefix_cmd);
13893 install_element(BGP_IPV6_NODE, &neighbor_maximum_prefix_threshold_cmd);
13894 install_element(BGP_IPV6_NODE, &neighbor_maximum_prefix_warning_cmd);
13895 install_element(BGP_IPV6_NODE,
13896 &neighbor_maximum_prefix_threshold_warning_cmd);
13897 install_element(BGP_IPV6_NODE, &neighbor_maximum_prefix_restart_cmd);
13898 install_element(BGP_IPV6_NODE,
13899 &neighbor_maximum_prefix_threshold_restart_cmd);
13900 install_element(BGP_IPV6_NODE, &no_neighbor_maximum_prefix_cmd);
13901 install_element(BGP_IPV6M_NODE, &neighbor_maximum_prefix_cmd);
13902 install_element(BGP_IPV6M_NODE, &neighbor_maximum_prefix_threshold_cmd);
13903 install_element(BGP_IPV6M_NODE, &neighbor_maximum_prefix_warning_cmd);
13904 install_element(BGP_IPV6M_NODE,
13905 &neighbor_maximum_prefix_threshold_warning_cmd);
13906 install_element(BGP_IPV6M_NODE, &neighbor_maximum_prefix_restart_cmd);
13907 install_element(BGP_IPV6M_NODE,
13908 &neighbor_maximum_prefix_threshold_restart_cmd);
13909 install_element(BGP_IPV6M_NODE, &no_neighbor_maximum_prefix_cmd);
13910 install_element(BGP_IPV6L_NODE, &neighbor_maximum_prefix_cmd);
13911 install_element(BGP_IPV6L_NODE, &neighbor_maximum_prefix_threshold_cmd);
13912 install_element(BGP_IPV6L_NODE, &neighbor_maximum_prefix_warning_cmd);
13913 install_element(BGP_IPV6L_NODE,
13914 &neighbor_maximum_prefix_threshold_warning_cmd);
13915 install_element(BGP_IPV6L_NODE, &neighbor_maximum_prefix_restart_cmd);
13916 install_element(BGP_IPV6L_NODE,
13917 &neighbor_maximum_prefix_threshold_restart_cmd);
13918 install_element(BGP_IPV6L_NODE, &no_neighbor_maximum_prefix_cmd);
13919 install_element(BGP_VPNV4_NODE, &neighbor_maximum_prefix_cmd);
13920 install_element(BGP_VPNV4_NODE, &neighbor_maximum_prefix_threshold_cmd);
13921 install_element(BGP_VPNV4_NODE, &neighbor_maximum_prefix_warning_cmd);
13922 install_element(BGP_VPNV4_NODE,
13923 &neighbor_maximum_prefix_threshold_warning_cmd);
13924 install_element(BGP_VPNV4_NODE, &neighbor_maximum_prefix_restart_cmd);
13925 install_element(BGP_VPNV4_NODE,
13926 &neighbor_maximum_prefix_threshold_restart_cmd);
13927 install_element(BGP_VPNV4_NODE, &no_neighbor_maximum_prefix_cmd);
13928 install_element(BGP_VPNV6_NODE, &neighbor_maximum_prefix_cmd);
13929 install_element(BGP_VPNV6_NODE, &neighbor_maximum_prefix_threshold_cmd);
13930 install_element(BGP_VPNV6_NODE, &neighbor_maximum_prefix_warning_cmd);
13931 install_element(BGP_VPNV6_NODE,
13932 &neighbor_maximum_prefix_threshold_warning_cmd);
13933 install_element(BGP_VPNV6_NODE, &neighbor_maximum_prefix_restart_cmd);
13934 install_element(BGP_VPNV6_NODE,
13935 &neighbor_maximum_prefix_threshold_restart_cmd);
13936 install_element(BGP_VPNV6_NODE, &no_neighbor_maximum_prefix_cmd);
13937
13938 /* "neighbor allowas-in" */
13939 install_element(BGP_NODE, &neighbor_allowas_in_hidden_cmd);
13940 install_element(BGP_NODE, &no_neighbor_allowas_in_hidden_cmd);
13941 install_element(BGP_IPV4_NODE, &neighbor_allowas_in_cmd);
13942 install_element(BGP_IPV4_NODE, &no_neighbor_allowas_in_cmd);
13943 install_element(BGP_IPV4M_NODE, &neighbor_allowas_in_cmd);
13944 install_element(BGP_IPV4M_NODE, &no_neighbor_allowas_in_cmd);
13945 install_element(BGP_IPV4L_NODE, &neighbor_allowas_in_cmd);
13946 install_element(BGP_IPV4L_NODE, &no_neighbor_allowas_in_cmd);
13947 install_element(BGP_IPV6_NODE, &neighbor_allowas_in_cmd);
13948 install_element(BGP_IPV6_NODE, &no_neighbor_allowas_in_cmd);
13949 install_element(BGP_IPV6M_NODE, &neighbor_allowas_in_cmd);
13950 install_element(BGP_IPV6M_NODE, &no_neighbor_allowas_in_cmd);
13951 install_element(BGP_IPV6L_NODE, &neighbor_allowas_in_cmd);
13952 install_element(BGP_IPV6L_NODE, &no_neighbor_allowas_in_cmd);
13953 install_element(BGP_VPNV4_NODE, &neighbor_allowas_in_cmd);
13954 install_element(BGP_VPNV4_NODE, &no_neighbor_allowas_in_cmd);
13955 install_element(BGP_VPNV6_NODE, &neighbor_allowas_in_cmd);
13956 install_element(BGP_VPNV6_NODE, &no_neighbor_allowas_in_cmd);
13957 install_element(BGP_EVPN_NODE, &neighbor_allowas_in_cmd);
13958 install_element(BGP_EVPN_NODE, &no_neighbor_allowas_in_cmd);
13959
13960 /* address-family commands. */
13961 install_element(BGP_NODE, &address_family_ipv4_safi_cmd);
13962 install_element(BGP_NODE, &address_family_ipv6_safi_cmd);
13963 #ifdef KEEP_OLD_VPN_COMMANDS
13964 install_element(BGP_NODE, &address_family_vpnv4_cmd);
13965 install_element(BGP_NODE, &address_family_vpnv6_cmd);
13966 #endif /* KEEP_OLD_VPN_COMMANDS */
13967
13968 install_element(BGP_NODE, &address_family_evpn_cmd);
13969
13970 /* "exit-address-family" command. */
13971 install_element(BGP_IPV4_NODE, &exit_address_family_cmd);
13972 install_element(BGP_IPV4M_NODE, &exit_address_family_cmd);
13973 install_element(BGP_IPV4L_NODE, &exit_address_family_cmd);
13974 install_element(BGP_IPV6_NODE, &exit_address_family_cmd);
13975 install_element(BGP_IPV6M_NODE, &exit_address_family_cmd);
13976 install_element(BGP_IPV6L_NODE, &exit_address_family_cmd);
13977 install_element(BGP_VPNV4_NODE, &exit_address_family_cmd);
13978 install_element(BGP_VPNV6_NODE, &exit_address_family_cmd);
13979 install_element(BGP_FLOWSPECV4_NODE, &exit_address_family_cmd);
13980 install_element(BGP_FLOWSPECV6_NODE, &exit_address_family_cmd);
13981 install_element(BGP_EVPN_NODE, &exit_address_family_cmd);
13982
13983 /* "clear ip bgp commands" */
13984 install_element(ENABLE_NODE, &clear_ip_bgp_all_cmd);
13985
13986 /* clear ip bgp prefix */
13987 install_element(ENABLE_NODE, &clear_ip_bgp_prefix_cmd);
13988 install_element(ENABLE_NODE, &clear_bgp_ipv6_safi_prefix_cmd);
13989 install_element(ENABLE_NODE, &clear_bgp_instance_ipv6_safi_prefix_cmd);
13990
13991 /* "show [ip] bgp summary" commands. */
13992 install_element(VIEW_NODE, &show_bgp_instance_all_ipv6_updgrps_cmd);
13993 install_element(VIEW_NODE, &show_bgp_l2vpn_evpn_updgrps_cmd);
13994 install_element(VIEW_NODE, &show_bgp_instance_updgrps_stats_cmd);
13995 install_element(VIEW_NODE, &show_bgp_updgrps_stats_cmd);
13996 install_element(VIEW_NODE, &show_ip_bgp_instance_updgrps_adj_s_cmd);
13997 install_element(VIEW_NODE, &show_ip_bgp_summary_cmd);
13998 install_element(VIEW_NODE, &show_ip_bgp_updgrps_cmd);
13999
14000 /* "show [ip] bgp neighbors" commands. */
14001 install_element(VIEW_NODE, &show_ip_bgp_neighbors_cmd);
14002
14003 /* "show [ip] bgp peer-group" commands. */
14004 install_element(VIEW_NODE, &show_ip_bgp_peer_groups_cmd);
14005
14006 /* "show [ip] bgp paths" commands. */
14007 install_element(VIEW_NODE, &show_ip_bgp_paths_cmd);
14008
14009 /* "show [ip] bgp community" commands. */
14010 install_element(VIEW_NODE, &show_ip_bgp_community_info_cmd);
14011
14012 /* "show ip bgp large-community" commands. */
14013 install_element(VIEW_NODE, &show_ip_bgp_lcommunity_info_cmd);
14014 /* "show [ip] bgp attribute-info" commands. */
14015 install_element(VIEW_NODE, &show_ip_bgp_attr_info_cmd);
14016 /* "show [ip] bgp route-leak" command */
14017 install_element(VIEW_NODE, &show_ip_bgp_route_leak_cmd);
14018
14019 /* "redistribute" commands. */
14020 install_element(BGP_NODE, &bgp_redistribute_ipv4_hidden_cmd);
14021 install_element(BGP_NODE, &no_bgp_redistribute_ipv4_hidden_cmd);
14022 install_element(BGP_NODE, &bgp_redistribute_ipv4_rmap_hidden_cmd);
14023 install_element(BGP_NODE, &bgp_redistribute_ipv4_metric_hidden_cmd);
14024 install_element(BGP_NODE,
14025 &bgp_redistribute_ipv4_rmap_metric_hidden_cmd);
14026 install_element(BGP_NODE,
14027 &bgp_redistribute_ipv4_metric_rmap_hidden_cmd);
14028 install_element(BGP_NODE, &bgp_redistribute_ipv4_ospf_hidden_cmd);
14029 install_element(BGP_NODE, &no_bgp_redistribute_ipv4_ospf_hidden_cmd);
14030 install_element(BGP_NODE, &bgp_redistribute_ipv4_ospf_rmap_hidden_cmd);
14031 install_element(BGP_NODE,
14032 &bgp_redistribute_ipv4_ospf_metric_hidden_cmd);
14033 install_element(BGP_NODE,
14034 &bgp_redistribute_ipv4_ospf_rmap_metric_hidden_cmd);
14035 install_element(BGP_NODE,
14036 &bgp_redistribute_ipv4_ospf_metric_rmap_hidden_cmd);
14037 install_element(BGP_IPV4_NODE, &bgp_redistribute_ipv4_cmd);
14038 install_element(BGP_IPV4_NODE, &no_bgp_redistribute_ipv4_cmd);
14039 install_element(BGP_IPV4_NODE, &bgp_redistribute_ipv4_rmap_cmd);
14040 install_element(BGP_IPV4_NODE, &bgp_redistribute_ipv4_metric_cmd);
14041 install_element(BGP_IPV4_NODE, &bgp_redistribute_ipv4_rmap_metric_cmd);
14042 install_element(BGP_IPV4_NODE, &bgp_redistribute_ipv4_metric_rmap_cmd);
14043 install_element(BGP_IPV4_NODE, &bgp_redistribute_ipv4_ospf_cmd);
14044 install_element(BGP_IPV4_NODE, &no_bgp_redistribute_ipv4_ospf_cmd);
14045 install_element(BGP_IPV4_NODE, &bgp_redistribute_ipv4_ospf_rmap_cmd);
14046 install_element(BGP_IPV4_NODE, &bgp_redistribute_ipv4_ospf_metric_cmd);
14047 install_element(BGP_IPV4_NODE,
14048 &bgp_redistribute_ipv4_ospf_rmap_metric_cmd);
14049 install_element(BGP_IPV4_NODE,
14050 &bgp_redistribute_ipv4_ospf_metric_rmap_cmd);
14051 install_element(BGP_IPV6_NODE, &bgp_redistribute_ipv6_cmd);
14052 install_element(BGP_IPV6_NODE, &no_bgp_redistribute_ipv6_cmd);
14053 install_element(BGP_IPV6_NODE, &bgp_redistribute_ipv6_rmap_cmd);
14054 install_element(BGP_IPV6_NODE, &bgp_redistribute_ipv6_metric_cmd);
14055 install_element(BGP_IPV6_NODE, &bgp_redistribute_ipv6_rmap_metric_cmd);
14056 install_element(BGP_IPV6_NODE, &bgp_redistribute_ipv6_metric_rmap_cmd);
14057
14058 /* import|export vpn [route-map WORD] */
14059 install_element(BGP_IPV4_NODE, &bgp_imexport_vpn_cmd);
14060 install_element(BGP_IPV6_NODE, &bgp_imexport_vpn_cmd);
14061
14062 install_element(BGP_IPV4_NODE, &bgp_imexport_vrf_cmd);
14063 install_element(BGP_IPV6_NODE, &bgp_imexport_vrf_cmd);
14064
14065 /* ttl_security commands */
14066 install_element(BGP_NODE, &neighbor_ttl_security_cmd);
14067 install_element(BGP_NODE, &no_neighbor_ttl_security_cmd);
14068
14069 /* "show [ip] bgp memory" commands. */
14070 install_element(VIEW_NODE, &show_bgp_memory_cmd);
14071
14072 /* "show bgp martian next-hop" */
14073 install_element(VIEW_NODE, &show_bgp_martian_nexthop_db_cmd);
14074
14075 install_element(VIEW_NODE, &show_bgp_mac_hash_cmd);
14076
14077 /* "show [ip] bgp views" commands. */
14078 install_element(VIEW_NODE, &show_bgp_views_cmd);
14079
14080 /* "show [ip] bgp vrfs" commands. */
14081 install_element(VIEW_NODE, &show_bgp_vrfs_cmd);
14082
14083 /* Community-list. */
14084 community_list_vty();
14085
14086 /* vpn-policy commands */
14087 install_element(BGP_IPV4_NODE, &af_rd_vpn_export_cmd);
14088 install_element(BGP_IPV6_NODE, &af_rd_vpn_export_cmd);
14089 install_element(BGP_IPV4_NODE, &af_label_vpn_export_cmd);
14090 install_element(BGP_IPV6_NODE, &af_label_vpn_export_cmd);
14091 install_element(BGP_IPV4_NODE, &af_nexthop_vpn_export_cmd);
14092 install_element(BGP_IPV6_NODE, &af_nexthop_vpn_export_cmd);
14093 install_element(BGP_IPV4_NODE, &af_rt_vpn_imexport_cmd);
14094 install_element(BGP_IPV6_NODE, &af_rt_vpn_imexport_cmd);
14095 install_element(BGP_IPV4_NODE, &af_route_map_vpn_imexport_cmd);
14096 install_element(BGP_IPV6_NODE, &af_route_map_vpn_imexport_cmd);
14097 install_element(BGP_IPV4_NODE, &af_import_vrf_route_map_cmd);
14098 install_element(BGP_IPV6_NODE, &af_import_vrf_route_map_cmd);
14099
14100 install_element(BGP_IPV4_NODE, &af_routetarget_import_cmd);
14101 install_element(BGP_IPV6_NODE, &af_routetarget_import_cmd);
14102
14103 install_element(BGP_IPV4_NODE, &af_no_rd_vpn_export_cmd);
14104 install_element(BGP_IPV6_NODE, &af_no_rd_vpn_export_cmd);
14105 install_element(BGP_IPV4_NODE, &af_no_label_vpn_export_cmd);
14106 install_element(BGP_IPV6_NODE, &af_no_label_vpn_export_cmd);
14107 install_element(BGP_IPV4_NODE, &af_no_nexthop_vpn_export_cmd);
14108 install_element(BGP_IPV6_NODE, &af_no_nexthop_vpn_export_cmd);
14109 install_element(BGP_IPV4_NODE, &af_no_rt_vpn_imexport_cmd);
14110 install_element(BGP_IPV6_NODE, &af_no_rt_vpn_imexport_cmd);
14111 install_element(BGP_IPV4_NODE, &af_no_route_map_vpn_imexport_cmd);
14112 install_element(BGP_IPV6_NODE, &af_no_route_map_vpn_imexport_cmd);
14113 install_element(BGP_IPV4_NODE, &af_no_import_vrf_route_map_cmd);
14114 install_element(BGP_IPV6_NODE, &af_no_import_vrf_route_map_cmd);
14115 }
14116
14117 #include "memory.h"
14118 #include "bgp_regex.h"
14119 #include "bgp_clist.h"
14120 #include "bgp_ecommunity.h"
14121
14122 /* VTY functions. */
14123
14124 /* Direction value to string conversion. */
14125 static const char *community_direct_str(int direct)
14126 {
14127 switch (direct) {
14128 case COMMUNITY_DENY:
14129 return "deny";
14130 case COMMUNITY_PERMIT:
14131 return "permit";
14132 default:
14133 return "unknown";
14134 }
14135 }
14136
14137 /* Display error string. */
14138 static void community_list_perror(struct vty *vty, int ret)
14139 {
14140 switch (ret) {
14141 case COMMUNITY_LIST_ERR_CANT_FIND_LIST:
14142 vty_out(vty, "%% Can't find community-list\n");
14143 break;
14144 case COMMUNITY_LIST_ERR_MALFORMED_VAL:
14145 vty_out(vty, "%% Malformed community-list value\n");
14146 break;
14147 case COMMUNITY_LIST_ERR_STANDARD_CONFLICT:
14148 vty_out(vty,
14149 "%% Community name conflict, previously defined as standard community\n");
14150 break;
14151 case COMMUNITY_LIST_ERR_EXPANDED_CONFLICT:
14152 vty_out(vty,
14153 "%% Community name conflict, previously defined as expanded community\n");
14154 break;
14155 }
14156 }
14157
14158 /* "community-list" keyword help string. */
14159 #define COMMUNITY_LIST_STR "Add a community list entry\n"
14160
14161 /*community-list standard */
14162 DEFUN (community_list_standard,
14163 bgp_community_list_standard_cmd,
14164 "bgp community-list <(1-99)|standard WORD> <deny|permit> AA:NN...",
14165 BGP_STR
14166 COMMUNITY_LIST_STR
14167 "Community list number (standard)\n"
14168 "Add an standard community-list entry\n"
14169 "Community list name\n"
14170 "Specify community to reject\n"
14171 "Specify community to accept\n"
14172 COMMUNITY_VAL_STR)
14173 {
14174 char *cl_name_or_number = NULL;
14175 int direct = 0;
14176 int style = COMMUNITY_LIST_STANDARD;
14177
14178 int idx = 0;
14179
14180 if (argv_find(argv, argc, "ip", &idx)) {
14181 vty_out(vty, "This config option is deprecated, and is scheduled for removal.\n");
14182 vty_out(vty, "if you are using this please migrate to the below command.\n");
14183 vty_out(vty, "'bgp community-list <(1-99)|(100-500)|standard|expanded> <deny|permit> AA:NN'\n");
14184 zlog_warn("Deprecated option: 'ip community-list <(1-99)|(100-500)|standard|expanded> <deny|permit> AA:NN' being used");
14185 }
14186
14187 argv_find(argv, argc, "(1-99)", &idx);
14188 argv_find(argv, argc, "WORD", &idx);
14189 cl_name_or_number = argv[idx]->arg;
14190 direct = argv_find(argv, argc, "permit", &idx) ? COMMUNITY_PERMIT
14191 : COMMUNITY_DENY;
14192 argv_find(argv, argc, "AA:NN", &idx);
14193 char *str = argv_concat(argv, argc, idx);
14194
14195 int ret = community_list_set(bgp_clist, cl_name_or_number, str, direct,
14196 style);
14197
14198 XFREE(MTYPE_TMP, str);
14199
14200 if (ret < 0) {
14201 /* Display error string. */
14202 community_list_perror(vty, ret);
14203 return CMD_WARNING_CONFIG_FAILED;
14204 }
14205
14206 return CMD_SUCCESS;
14207 }
14208
14209 #if CONFDATE > 20191005
14210 CPP_NOTICE("bgpd: remove deprecated 'ip community-list <(1-99)|(100-500)|standard|expanded> <deny|permit> AA:NN' command")
14211 #endif
14212 ALIAS (community_list_standard,
14213 ip_community_list_standard_cmd,
14214 "ip community-list <(1-99)|standard WORD> <deny|permit> AA:NN...",
14215 IP_STR
14216 COMMUNITY_LIST_STR
14217 "Community list number (standard)\n"
14218 "Add an standard community-list entry\n"
14219 "Community list name\n"
14220 "Specify community to reject\n"
14221 "Specify community to accept\n"
14222 COMMUNITY_VAL_STR)
14223
14224 DEFUN (no_community_list_standard_all,
14225 no_bgp_community_list_standard_all_cmd,
14226 "no bgp community-list <(1-99)|standard WORD> <deny|permit> AA:NN...",
14227 NO_STR
14228 BGP_STR
14229 COMMUNITY_LIST_STR
14230 "Community list number (standard)\n"
14231 "Add an standard community-list entry\n"
14232 "Community list name\n"
14233 "Specify community to reject\n"
14234 "Specify community to accept\n"
14235 COMMUNITY_VAL_STR)
14236 {
14237 char *cl_name_or_number = NULL;
14238 char *str = NULL;
14239 int direct = 0;
14240 int style = COMMUNITY_LIST_STANDARD;
14241
14242 int idx = 0;
14243
14244 if (argv_find(argv, argc, "ip", &idx)) {
14245 vty_out(vty, "This config option is deprecated, and is scheduled for removal\n");
14246 vty_out(vty, "if you are using this please migrate to the below command.\n");
14247 vty_out(vty, "'no bgp community-list <(1-99)|(100-500)|standard|expanded> <deny|permit> AA:NN'\n");
14248 zlog_warn("Deprecated option: 'no ip community-list <(1-99)|(100-500)|standard|expanded> <deny|permit> |AA:NN' being used");
14249 }
14250
14251 argv_find(argv, argc, "permit", &idx);
14252 argv_find(argv, argc, "deny", &idx);
14253
14254 if (idx) {
14255 direct = argv_find(argv, argc, "permit", &idx)
14256 ? COMMUNITY_PERMIT
14257 : COMMUNITY_DENY;
14258
14259 idx = 0;
14260 argv_find(argv, argc, "AA:NN", &idx);
14261 str = argv_concat(argv, argc, idx);
14262 }
14263
14264 idx = 0;
14265 argv_find(argv, argc, "(1-99)", &idx);
14266 argv_find(argv, argc, "WORD", &idx);
14267 cl_name_or_number = argv[idx]->arg;
14268
14269 int ret = community_list_unset(bgp_clist, cl_name_or_number, str,
14270 direct, style);
14271
14272 XFREE(MTYPE_TMP, str);
14273
14274 if (ret < 0) {
14275 community_list_perror(vty, ret);
14276 return CMD_WARNING_CONFIG_FAILED;
14277 }
14278
14279 return CMD_SUCCESS;
14280 }
14281 ALIAS (no_community_list_standard_all,
14282 no_ip_community_list_standard_all_cmd,
14283 "no ip community-list <(1-99)|standard WORD> <deny|permit> AA:NN...",
14284 NO_STR
14285 IP_STR
14286 COMMUNITY_LIST_STR
14287 "Community list number (standard)\n"
14288 "Add an standard community-list entry\n"
14289 "Community list name\n"
14290 "Specify community to reject\n"
14291 "Specify community to accept\n"
14292 COMMUNITY_VAL_STR)
14293
14294 ALIAS(no_community_list_standard_all, no_bgp_community_list_standard_all_list_cmd,
14295 "no bgp community-list <(1-99)|standard WORD>",
14296 NO_STR BGP_STR COMMUNITY_LIST_STR
14297 "Community list number (standard)\n"
14298 "Add an standard community-list entry\n"
14299 "Community list name\n")
14300
14301 ALIAS(no_community_list_standard_all, no_ip_community_list_standard_all_list_cmd,
14302 "no ip community-list <(1-99)|standard WORD>",
14303 NO_STR BGP_STR COMMUNITY_LIST_STR
14304 "Community list number (standard)\n"
14305 "Add an standard community-list entry\n"
14306 "Community list name\n")
14307
14308 /*community-list expanded */
14309 DEFUN (community_list_expanded_all,
14310 bgp_community_list_expanded_all_cmd,
14311 "bgp community-list <(100-500)|expanded WORD> <deny|permit> AA:NN...",
14312 BGP_STR
14313 COMMUNITY_LIST_STR
14314 "Community list number (expanded)\n"
14315 "Add an expanded community-list entry\n"
14316 "Community list name\n"
14317 "Specify community to reject\n"
14318 "Specify community to accept\n"
14319 COMMUNITY_VAL_STR)
14320 {
14321 char *cl_name_or_number = 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, "'bgp community-list <(1-99)|(100-500)|standard|expanded> <deny|permit> AA:NN'\n");
14330 zlog_warn("Deprecated option: 'ip community-list <(1-99)|(100-500)|standard|expanded> <deny|permit> AA:NN' being used");
14331 }
14332 argv_find(argv, argc, "(100-500)", &idx);
14333 argv_find(argv, argc, "WORD", &idx);
14334 cl_name_or_number = argv[idx]->arg;
14335 direct = argv_find(argv, argc, "permit", &idx) ? COMMUNITY_PERMIT
14336 : COMMUNITY_DENY;
14337 argv_find(argv, argc, "AA:NN", &idx);
14338 char *str = argv_concat(argv, argc, idx);
14339
14340 int ret = community_list_set(bgp_clist, cl_name_or_number, str, direct,
14341 style);
14342
14343 XFREE(MTYPE_TMP, str);
14344
14345 if (ret < 0) {
14346 /* Display error string. */
14347 community_list_perror(vty, ret);
14348 return CMD_WARNING_CONFIG_FAILED;
14349 }
14350
14351 return CMD_SUCCESS;
14352 }
14353
14354 ALIAS (community_list_expanded_all,
14355 ip_community_list_expanded_all_cmd,
14356 "ip community-list <(100-500)|expanded WORD> <deny|permit> AA:NN...",
14357 IP_STR
14358 COMMUNITY_LIST_STR
14359 "Community list number (expanded)\n"
14360 "Add an expanded community-list entry\n"
14361 "Community list name\n"
14362 "Specify community to reject\n"
14363 "Specify community to accept\n"
14364 COMMUNITY_VAL_STR)
14365
14366 DEFUN (no_community_list_expanded_all,
14367 no_bgp_community_list_expanded_all_cmd,
14368 "no bgp community-list <(100-500)|expanded WORD> <deny|permit> AA:NN...",
14369 NO_STR
14370 BGP_STR
14371 COMMUNITY_LIST_STR
14372 "Community list number (expanded)\n"
14373 "Add an expanded community-list entry\n"
14374 "Community list name\n"
14375 "Specify community to reject\n"
14376 "Specify community to accept\n"
14377 COMMUNITY_VAL_STR)
14378 {
14379 char *cl_name_or_number = NULL;
14380 char *str = NULL;
14381 int direct = 0;
14382 int style = COMMUNITY_LIST_EXPANDED;
14383
14384 int idx = 0;
14385 if (argv_find(argv, argc, "ip", &idx)) {
14386 vty_out(vty, "This config option is deprecated, and is scheduled for removal.\n");
14387 vty_out(vty, "if you are using this please migrate to the below command.\n");
14388 vty_out(vty, "'no bgp community-list <(1-99)|(100-500)|standard|expanded> <deny|permit> AA:NN'\n");
14389 zlog_warn("Deprecated option: 'no ip community-list <(1-99)|(100-500)|standard|expanded> <deny|permit> AA:NN' being used");
14390 }
14391
14392 idx = 0;
14393 argv_find(argv, argc, "permit", &idx);
14394 argv_find(argv, argc, "deny", &idx);
14395
14396 if (idx) {
14397 direct = argv_find(argv, argc, "permit", &idx)
14398 ? COMMUNITY_PERMIT
14399 : COMMUNITY_DENY;
14400
14401 idx = 0;
14402 argv_find(argv, argc, "AA:NN", &idx);
14403 str = argv_concat(argv, argc, idx);
14404 }
14405
14406 idx = 0;
14407 argv_find(argv, argc, "(100-500)", &idx);
14408 argv_find(argv, argc, "WORD", &idx);
14409 cl_name_or_number = argv[idx]->arg;
14410
14411 int ret = community_list_unset(bgp_clist, cl_name_or_number, str,
14412 direct, style);
14413
14414 XFREE(MTYPE_TMP, str);
14415
14416 if (ret < 0) {
14417 community_list_perror(vty, ret);
14418 return CMD_WARNING_CONFIG_FAILED;
14419 }
14420
14421 return CMD_SUCCESS;
14422 }
14423
14424 ALIAS (no_community_list_expanded_all,
14425 no_ip_community_list_expanded_all_cmd,
14426 "no ip community-list <(100-500)|expanded WORD> <deny|permit> AA:NN...",
14427 NO_STR
14428 IP_STR
14429 COMMUNITY_LIST_STR
14430 "Community list number (expanded)\n"
14431 "Add an expanded community-list entry\n"
14432 "Community list name\n"
14433 "Specify community to reject\n"
14434 "Specify community to accept\n"
14435 COMMUNITY_VAL_STR)
14436
14437 ALIAS(no_community_list_expanded_all, no_bgp_community_list_expanded_all_list_cmd,
14438 "no bgp community-list <(100-500)|expanded WORD>",
14439 NO_STR IP_STR COMMUNITY_LIST_STR
14440 "Community list number (expanded)\n"
14441 "Add an expanded community-list entry\n"
14442 "Community list name\n")
14443
14444 ALIAS(no_community_list_expanded_all, no_ip_community_list_expanded_all_list_cmd,
14445 "no ip community-list <(100-500)|expanded WORD>",
14446 NO_STR IP_STR COMMUNITY_LIST_STR
14447 "Community list number (expanded)\n"
14448 "Add an expanded community-list entry\n"
14449 "Community list name\n")
14450
14451 /* Return configuration string of community-list entry. */
14452 static const char *community_list_config_str(struct community_entry *entry)
14453 {
14454 const char *str;
14455
14456 if (entry->any)
14457 str = "";
14458 else {
14459 if (entry->style == COMMUNITY_LIST_STANDARD)
14460 str = community_str(entry->u.com, false);
14461 else if (entry->style == LARGE_COMMUNITY_LIST_STANDARD)
14462 str = lcommunity_str(entry->u.lcom, false);
14463 else
14464 str = entry->config;
14465 }
14466 return str;
14467 }
14468
14469 static void community_list_show(struct vty *vty, struct community_list *list)
14470 {
14471 struct community_entry *entry;
14472
14473 for (entry = list->head; entry; entry = entry->next) {
14474 if (entry == list->head) {
14475 if (all_digit(list->name))
14476 vty_out(vty, "Community %s list %s\n",
14477 entry->style == COMMUNITY_LIST_STANDARD
14478 ? "standard"
14479 : "(expanded) access",
14480 list->name);
14481 else
14482 vty_out(vty, "Named Community %s list %s\n",
14483 entry->style == COMMUNITY_LIST_STANDARD
14484 ? "standard"
14485 : "expanded",
14486 list->name);
14487 }
14488 if (entry->any)
14489 vty_out(vty, " %s\n",
14490 community_direct_str(entry->direct));
14491 else
14492 vty_out(vty, " %s %s\n",
14493 community_direct_str(entry->direct),
14494 community_list_config_str(entry));
14495 }
14496 }
14497
14498 DEFUN (show_community_list,
14499 show_bgp_community_list_cmd,
14500 "show bgp community-list",
14501 SHOW_STR
14502 BGP_STR
14503 "List community-list\n")
14504 {
14505 struct community_list *list;
14506 struct community_list_master *cm;
14507
14508 int idx = 0;
14509 if (argv_find(argv, argc, "ip", &idx)) {
14510 vty_out(vty, "This config option is deprecated, and is scheduled for removal.\n");
14511 vty_out(vty, "if you are using this please migrate to the below command.\n");
14512 vty_out(vty, "'show bgp community-list <(1-500)|WORD>'\n");
14513 zlog_warn("Deprecated option: 'ip show community-list <(1-500)|WORD>' being used");
14514 }
14515 cm = community_list_master_lookup(bgp_clist, COMMUNITY_LIST_MASTER);
14516 if (!cm)
14517 return CMD_SUCCESS;
14518
14519 for (list = cm->num.head; list; list = list->next)
14520 community_list_show(vty, list);
14521
14522 for (list = cm->str.head; list; list = list->next)
14523 community_list_show(vty, list);
14524
14525 return CMD_SUCCESS;
14526 }
14527
14528 ALIAS (show_community_list,
14529 show_ip_community_list_cmd,
14530 "show ip community-list",
14531 SHOW_STR
14532 IP_STR
14533 "List community-list\n")
14534
14535 DEFUN (show_community_list_arg,
14536 show_bgp_community_list_arg_cmd,
14537 "show bgp community-list <(1-500)|WORD>",
14538 SHOW_STR
14539 BGP_STR
14540 "List community-list\n"
14541 "Community-list number\n"
14542 "Community-list name\n")
14543 {
14544 int idx_comm_list = 3;
14545 struct community_list *list;
14546
14547 int idx = 0;
14548 if (argv_find(argv, argc, "ip", &idx)) {
14549 vty_out(vty, "This config option is deprecated, and is scheduled for removal.\n");
14550 vty_out(vty, "if you are using this please migrate to the below command.\n");
14551 vty_out(vty, "'show bgp community-list <(1-500)|WORD>'\n");
14552 zlog_warn("Deprecated option: 'ip show community-list <(1-500)|WORD>' being used");
14553 }
14554 list = community_list_lookup(bgp_clist, argv[idx_comm_list]->arg, 0,
14555 COMMUNITY_LIST_MASTER);
14556 if (!list) {
14557 vty_out(vty, "%% Can't find community-list\n");
14558 return CMD_WARNING;
14559 }
14560
14561 community_list_show(vty, list);
14562
14563 return CMD_SUCCESS;
14564 }
14565
14566 ALIAS (show_community_list_arg,
14567 show_ip_community_list_arg_cmd,
14568 "show ip community-list <(1-500)|WORD>",
14569 SHOW_STR
14570 IP_STR
14571 "List community-list\n"
14572 "Community-list number\n"
14573 "Community-list name\n")
14574
14575 /*
14576 * Large Community code.
14577 */
14578 static int lcommunity_list_set_vty(struct vty *vty, int argc,
14579 struct cmd_token **argv, int style,
14580 int reject_all_digit_name)
14581 {
14582 int ret;
14583 int direct;
14584 char *str;
14585 int idx = 0;
14586 char *cl_name;
14587
14588 if (argv_find(argv, argc, "ip", &idx)) {
14589 vty_out(vty, "This config option is deprecated, and is scheduled for removal.\n");
14590 vty_out(vty, "if you are using this please migrate to the below command.\n");
14591 vty_out(vty, "'bgp large-community-list <(1-99)|(100-500)|standard|expanded> <deny|permit> <LINE|AA:BB:CC>'\n");
14592 zlog_warn("Deprecated option: 'large-community-list <(1-99)|(100-500)|standard|expanded> <deny|permit> <LINE|AA:BB:CC>' being used");
14593 }
14594 direct = argv_find(argv, argc, "permit", &idx) ? COMMUNITY_PERMIT
14595 : COMMUNITY_DENY;
14596
14597 /* All digit name check. */
14598 idx = 0;
14599 argv_find(argv, argc, "WORD", &idx);
14600 argv_find(argv, argc, "(1-99)", &idx);
14601 argv_find(argv, argc, "(100-500)", &idx);
14602 cl_name = argv[idx]->arg;
14603 if (reject_all_digit_name && all_digit(cl_name)) {
14604 vty_out(vty, "%% Community name cannot have all digits\n");
14605 return CMD_WARNING_CONFIG_FAILED;
14606 }
14607
14608 idx = 0;
14609 argv_find(argv, argc, "AA:BB:CC", &idx);
14610 argv_find(argv, argc, "LINE", &idx);
14611 /* Concat community string argument. */
14612 if (idx)
14613 str = argv_concat(argv, argc, idx);
14614 else
14615 str = NULL;
14616
14617 ret = lcommunity_list_set(bgp_clist, cl_name, str, direct, style);
14618
14619 /* Free temporary community list string allocated by
14620 argv_concat(). */
14621 XFREE(MTYPE_TMP, str);
14622
14623 if (ret < 0) {
14624 community_list_perror(vty, ret);
14625 return CMD_WARNING_CONFIG_FAILED;
14626 }
14627 return CMD_SUCCESS;
14628 }
14629
14630 static int lcommunity_list_unset_vty(struct vty *vty, int argc,
14631 struct cmd_token **argv, int style)
14632 {
14633 int ret;
14634 int direct = 0;
14635 char *str = NULL;
14636 int idx = 0;
14637
14638 if (argv_find(argv, argc, "ip", &idx)) {
14639 vty_out(vty, "This config option is deprecated, and is scheduled for removal.\n");
14640 vty_out(vty, "if you are using this please migrate to the below command.\n");
14641 vty_out(vty, "'no bgp large-community-list <(1-99)|(100-500)|standard|expanded> <deny|permit> <LINE|AA:BB:CC>'\n");
14642 zlog_warn("Deprecated option: 'no ip large-community-list <(1-99)|(100-500)|standard|expanded> <deny|permit> <LINE|AA:BB:CC>' being used");
14643 }
14644 argv_find(argv, argc, "permit", &idx);
14645 argv_find(argv, argc, "deny", &idx);
14646
14647 if (idx) {
14648 /* Check the list direct. */
14649 if (strncmp(argv[idx]->arg, "p", 1) == 0)
14650 direct = COMMUNITY_PERMIT;
14651 else
14652 direct = COMMUNITY_DENY;
14653
14654 idx = 0;
14655 argv_find(argv, argc, "LINE", &idx);
14656 argv_find(argv, argc, "AA:AA:NN", &idx);
14657 /* Concat community string argument. */
14658 str = argv_concat(argv, argc, idx);
14659 }
14660
14661 idx = 0;
14662 argv_find(argv, argc, "(1-99)", &idx);
14663 argv_find(argv, argc, "(100-500)", &idx);
14664 argv_find(argv, argc, "WORD", &idx);
14665
14666 /* Unset community list. */
14667 ret = lcommunity_list_unset(bgp_clist, argv[idx]->arg, str, direct,
14668 style);
14669
14670 /* Free temporary community list string allocated by
14671 argv_concat(). */
14672 XFREE(MTYPE_TMP, str);
14673
14674 if (ret < 0) {
14675 community_list_perror(vty, ret);
14676 return CMD_WARNING_CONFIG_FAILED;
14677 }
14678
14679 return CMD_SUCCESS;
14680 }
14681
14682 /* "large-community-list" keyword help string. */
14683 #define LCOMMUNITY_LIST_STR "Add a large community list entry\n"
14684 #define LCOMMUNITY_VAL_STR "large community in 'aa:bb:cc' format\n"
14685
14686 #if CONFDATE > 20191005
14687 CPP_NOTICE("bgpd: remove deprecated 'ip large-community-list <(1-99)|(100-500)|standard|expanded> <deny|permit> <LINE|AA:BB:CC>' command")
14688 #endif
14689 DEFUN (lcommunity_list_standard,
14690 bgp_lcommunity_list_standard_cmd,
14691 "bgp large-community-list (1-99) <deny|permit>",
14692 BGP_STR
14693 LCOMMUNITY_LIST_STR
14694 "Large Community list number (standard)\n"
14695 "Specify large community to reject\n"
14696 "Specify large community to accept\n")
14697 {
14698 return lcommunity_list_set_vty(vty, argc, argv,
14699 LARGE_COMMUNITY_LIST_STANDARD, 0);
14700 }
14701
14702 ALIAS (lcommunity_list_standard,
14703 ip_lcommunity_list_standard_cmd,
14704 "ip large-community-list (1-99) <deny|permit>",
14705 IP_STR
14706 LCOMMUNITY_LIST_STR
14707 "Large Community list number (standard)\n"
14708 "Specify large community to reject\n"
14709 "Specify large community to accept\n")
14710
14711 DEFUN (lcommunity_list_standard1,
14712 bgp_lcommunity_list_standard1_cmd,
14713 "bgp large-community-list (1-99) <deny|permit> AA:BB:CC...",
14714 BGP_STR
14715 LCOMMUNITY_LIST_STR
14716 "Large Community list number (standard)\n"
14717 "Specify large community to reject\n"
14718 "Specify large community to accept\n"
14719 LCOMMUNITY_VAL_STR)
14720 {
14721 return lcommunity_list_set_vty(vty, argc, argv,
14722 LARGE_COMMUNITY_LIST_STANDARD, 0);
14723 }
14724
14725 ALIAS (lcommunity_list_standard1,
14726 ip_lcommunity_list_standard1_cmd,
14727 "ip large-community-list (1-99) <deny|permit> AA:BB:CC...",
14728 IP_STR
14729 LCOMMUNITY_LIST_STR
14730 "Large Community list number (standard)\n"
14731 "Specify large community to reject\n"
14732 "Specify large community to accept\n"
14733 LCOMMUNITY_VAL_STR)
14734
14735 DEFUN (lcommunity_list_expanded,
14736 bgp_lcommunity_list_expanded_cmd,
14737 "bgp large-community-list (100-500) <deny|permit> LINE...",
14738 BGP_STR
14739 LCOMMUNITY_LIST_STR
14740 "Large Community list number (expanded)\n"
14741 "Specify large community to reject\n"
14742 "Specify large community to accept\n"
14743 "An ordered list as a regular-expression\n")
14744 {
14745 return lcommunity_list_set_vty(vty, argc, argv,
14746 LARGE_COMMUNITY_LIST_EXPANDED, 0);
14747 }
14748
14749 ALIAS (lcommunity_list_expanded,
14750 ip_lcommunity_list_expanded_cmd,
14751 "ip large-community-list (100-500) <deny|permit> LINE...",
14752 IP_STR
14753 LCOMMUNITY_LIST_STR
14754 "Large Community list number (expanded)\n"
14755 "Specify large community to reject\n"
14756 "Specify large community to accept\n"
14757 "An ordered list as a regular-expression\n")
14758
14759 DEFUN (lcommunity_list_name_standard,
14760 bgp_lcommunity_list_name_standard_cmd,
14761 "bgp large-community-list standard WORD <deny|permit>",
14762 BGP_STR
14763 LCOMMUNITY_LIST_STR
14764 "Specify standard large-community-list\n"
14765 "Large Community list name\n"
14766 "Specify large community to reject\n"
14767 "Specify large community to accept\n")
14768 {
14769 return lcommunity_list_set_vty(vty, argc, argv,
14770 LARGE_COMMUNITY_LIST_STANDARD, 1);
14771 }
14772
14773 ALIAS (lcommunity_list_name_standard,
14774 ip_lcommunity_list_name_standard_cmd,
14775 "ip large-community-list standard WORD <deny|permit>",
14776 IP_STR
14777 LCOMMUNITY_LIST_STR
14778 "Specify standard large-community-list\n"
14779 "Large Community list name\n"
14780 "Specify large community to reject\n"
14781 "Specify large community to accept\n")
14782
14783 DEFUN (lcommunity_list_name_standard1,
14784 bgp_lcommunity_list_name_standard1_cmd,
14785 "bgp large-community-list standard WORD <deny|permit> AA:BB:CC...",
14786 BGP_STR
14787 LCOMMUNITY_LIST_STR
14788 "Specify standard large-community-list\n"
14789 "Large Community list name\n"
14790 "Specify large community to reject\n"
14791 "Specify large community to accept\n"
14792 LCOMMUNITY_VAL_STR)
14793 {
14794 return lcommunity_list_set_vty(vty, argc, argv,
14795 LARGE_COMMUNITY_LIST_STANDARD, 1);
14796 }
14797
14798 ALIAS (lcommunity_list_name_standard1,
14799 ip_lcommunity_list_name_standard1_cmd,
14800 "ip large-community-list standard WORD <deny|permit> AA:BB:CC...",
14801 IP_STR
14802 LCOMMUNITY_LIST_STR
14803 "Specify standard large-community-list\n"
14804 "Large Community list name\n"
14805 "Specify large community to reject\n"
14806 "Specify large community to accept\n"
14807 LCOMMUNITY_VAL_STR)
14808
14809 DEFUN (lcommunity_list_name_expanded,
14810 bgp_lcommunity_list_name_expanded_cmd,
14811 "bgp large-community-list expanded WORD <deny|permit> LINE...",
14812 BGP_STR
14813 LCOMMUNITY_LIST_STR
14814 "Specify expanded large-community-list\n"
14815 "Large Community list name\n"
14816 "Specify large community to reject\n"
14817 "Specify large community to accept\n"
14818 "An ordered list as a regular-expression\n")
14819 {
14820 return lcommunity_list_set_vty(vty, argc, argv,
14821 LARGE_COMMUNITY_LIST_EXPANDED, 1);
14822 }
14823
14824 ALIAS (lcommunity_list_name_expanded,
14825 ip_lcommunity_list_name_expanded_cmd,
14826 "ip large-community-list expanded WORD <deny|permit> LINE...",
14827 IP_STR
14828 LCOMMUNITY_LIST_STR
14829 "Specify expanded large-community-list\n"
14830 "Large Community list name\n"
14831 "Specify large community to reject\n"
14832 "Specify large community to accept\n"
14833 "An ordered list as a regular-expression\n")
14834
14835 DEFUN (no_lcommunity_list_standard_all,
14836 no_bgp_lcommunity_list_standard_all_cmd,
14837 "no bgp large-community-list <(1-99)|(100-500)|WORD>",
14838 NO_STR
14839 BGP_STR
14840 LCOMMUNITY_LIST_STR
14841 "Large Community list number (standard)\n"
14842 "Large Community list number (expanded)\n"
14843 "Large Community list name\n")
14844 {
14845 return lcommunity_list_unset_vty(vty, argc, argv,
14846 LARGE_COMMUNITY_LIST_STANDARD);
14847 }
14848
14849 ALIAS (no_lcommunity_list_standard_all,
14850 no_ip_lcommunity_list_standard_all_cmd,
14851 "no ip large-community-list <(1-99)|(100-500)|WORD>",
14852 NO_STR
14853 IP_STR
14854 LCOMMUNITY_LIST_STR
14855 "Large Community list number (standard)\n"
14856 "Large Community list number (expanded)\n"
14857 "Large Community list name\n")
14858
14859 DEFUN (no_lcommunity_list_name_expanded_all,
14860 no_bgp_lcommunity_list_name_expanded_all_cmd,
14861 "no bgp large-community-list expanded WORD",
14862 NO_STR
14863 BGP_STR
14864 LCOMMUNITY_LIST_STR
14865 "Specify expanded large-community-list\n"
14866 "Large Community list name\n")
14867 {
14868 return lcommunity_list_unset_vty(vty, argc, argv,
14869 LARGE_COMMUNITY_LIST_EXPANDED);
14870 }
14871
14872 ALIAS (no_lcommunity_list_name_expanded_all,
14873 no_ip_lcommunity_list_name_expanded_all_cmd,
14874 "no ip large-community-list expanded WORD",
14875 NO_STR
14876 IP_STR
14877 LCOMMUNITY_LIST_STR
14878 "Specify expanded large-community-list\n"
14879 "Large Community list name\n")
14880
14881 DEFUN (no_lcommunity_list_standard,
14882 no_bgp_lcommunity_list_standard_cmd,
14883 "no bgp large-community-list (1-99) <deny|permit> AA:AA:NN...",
14884 NO_STR
14885 BGP_STR
14886 LCOMMUNITY_LIST_STR
14887 "Large Community list number (standard)\n"
14888 "Specify large community to reject\n"
14889 "Specify large community to accept\n"
14890 LCOMMUNITY_VAL_STR)
14891 {
14892 return lcommunity_list_unset_vty(vty, argc, argv,
14893 LARGE_COMMUNITY_LIST_STANDARD);
14894 }
14895
14896 ALIAS (no_lcommunity_list_standard,
14897 no_ip_lcommunity_list_standard_cmd,
14898 "no ip large-community-list (1-99) <deny|permit> AA:AA:NN...",
14899 NO_STR
14900 IP_STR
14901 LCOMMUNITY_LIST_STR
14902 "Large Community list number (standard)\n"
14903 "Specify large community to reject\n"
14904 "Specify large community to accept\n"
14905 LCOMMUNITY_VAL_STR)
14906
14907 DEFUN (no_lcommunity_list_expanded,
14908 no_bgp_lcommunity_list_expanded_cmd,
14909 "no bgp large-community-list (100-500) <deny|permit> LINE...",
14910 NO_STR
14911 BGP_STR
14912 LCOMMUNITY_LIST_STR
14913 "Large Community list number (expanded)\n"
14914 "Specify large community to reject\n"
14915 "Specify large community to accept\n"
14916 "An ordered list as a regular-expression\n")
14917 {
14918 return lcommunity_list_unset_vty(vty, argc, argv,
14919 LARGE_COMMUNITY_LIST_EXPANDED);
14920 }
14921
14922 ALIAS (no_lcommunity_list_expanded,
14923 no_ip_lcommunity_list_expanded_cmd,
14924 "no ip large-community-list (100-500) <deny|permit> LINE...",
14925 NO_STR
14926 IP_STR
14927 LCOMMUNITY_LIST_STR
14928 "Large Community list number (expanded)\n"
14929 "Specify large community to reject\n"
14930 "Specify large community to accept\n"
14931 "An ordered list as a regular-expression\n")
14932
14933 DEFUN (no_lcommunity_list_name_standard,
14934 no_bgp_lcommunity_list_name_standard_cmd,
14935 "no bgp large-community-list standard WORD <deny|permit> AA:AA:NN...",
14936 NO_STR
14937 BGP_STR
14938 LCOMMUNITY_LIST_STR
14939 "Specify standard large-community-list\n"
14940 "Large Community list name\n"
14941 "Specify large community to reject\n"
14942 "Specify large community to accept\n"
14943 LCOMMUNITY_VAL_STR)
14944 {
14945 return lcommunity_list_unset_vty(vty, argc, argv,
14946 LARGE_COMMUNITY_LIST_STANDARD);
14947 }
14948
14949 ALIAS (no_lcommunity_list_name_standard,
14950 no_ip_lcommunity_list_name_standard_cmd,
14951 "no ip large-community-list standard WORD <deny|permit> AA:AA:NN...",
14952 NO_STR
14953 IP_STR
14954 LCOMMUNITY_LIST_STR
14955 "Specify standard large-community-list\n"
14956 "Large Community list name\n"
14957 "Specify large community to reject\n"
14958 "Specify large community to accept\n"
14959 LCOMMUNITY_VAL_STR)
14960
14961 DEFUN (no_lcommunity_list_name_expanded,
14962 no_bgp_lcommunity_list_name_expanded_cmd,
14963 "no bgp large-community-list expanded WORD <deny|permit> LINE...",
14964 NO_STR
14965 BGP_STR
14966 LCOMMUNITY_LIST_STR
14967 "Specify expanded large-community-list\n"
14968 "Large community list name\n"
14969 "Specify large community to reject\n"
14970 "Specify large community to accept\n"
14971 "An ordered list as a regular-expression\n")
14972 {
14973 return lcommunity_list_unset_vty(vty, argc, argv,
14974 LARGE_COMMUNITY_LIST_EXPANDED);
14975 }
14976
14977 ALIAS (no_lcommunity_list_name_expanded,
14978 no_ip_lcommunity_list_name_expanded_cmd,
14979 "no ip large-community-list expanded WORD <deny|permit> LINE...",
14980 NO_STR
14981 IP_STR
14982 LCOMMUNITY_LIST_STR
14983 "Specify expanded large-community-list\n"
14984 "Large community list name\n"
14985 "Specify large community to reject\n"
14986 "Specify large community to accept\n"
14987 "An ordered list as a regular-expression\n")
14988
14989 static void lcommunity_list_show(struct vty *vty, struct community_list *list)
14990 {
14991 struct community_entry *entry;
14992
14993 for (entry = list->head; entry; entry = entry->next) {
14994 if (entry == list->head) {
14995 if (all_digit(list->name))
14996 vty_out(vty, "Large community %s list %s\n",
14997 entry->style ==
14998 LARGE_COMMUNITY_LIST_STANDARD
14999 ? "standard"
15000 : "(expanded) access",
15001 list->name);
15002 else
15003 vty_out(vty,
15004 "Named large community %s list %s\n",
15005 entry->style ==
15006 LARGE_COMMUNITY_LIST_STANDARD
15007 ? "standard"
15008 : "expanded",
15009 list->name);
15010 }
15011 if (entry->any)
15012 vty_out(vty, " %s\n",
15013 community_direct_str(entry->direct));
15014 else
15015 vty_out(vty, " %s %s\n",
15016 community_direct_str(entry->direct),
15017 community_list_config_str(entry));
15018 }
15019 }
15020
15021 DEFUN (show_lcommunity_list,
15022 show_bgp_lcommunity_list_cmd,
15023 "show bgp large-community-list",
15024 SHOW_STR
15025 BGP_STR
15026 "List large-community list\n")
15027 {
15028 struct community_list *list;
15029 struct community_list_master *cm;
15030 int idx = 0;
15031
15032 if (argv_find(argv, argc, "ip", &idx)) {
15033 vty_out(vty, "This config option is deprecated, and is scheduled for removal.\n");
15034 vty_out(vty, "if you are using this please migrate to the below command.\n");
15035 vty_out(vty, "'show bgp large-community-list <(1-500)|WORD>'\n");
15036 zlog_warn("Deprecated option: 'ip show large-community-list <(1-500)|WORD>' being used");
15037 }
15038
15039 cm = community_list_master_lookup(bgp_clist,
15040 LARGE_COMMUNITY_LIST_MASTER);
15041 if (!cm)
15042 return CMD_SUCCESS;
15043
15044 for (list = cm->num.head; list; list = list->next)
15045 lcommunity_list_show(vty, list);
15046
15047 for (list = cm->str.head; list; list = list->next)
15048 lcommunity_list_show(vty, list);
15049
15050 return CMD_SUCCESS;
15051 }
15052
15053 ALIAS (show_lcommunity_list,
15054 show_ip_lcommunity_list_cmd,
15055 "show ip large-community-list",
15056 SHOW_STR
15057 IP_STR
15058 "List large-community list\n")
15059
15060 DEFUN (show_lcommunity_list_arg,
15061 show_bgp_lcommunity_list_arg_cmd,
15062 "show bgp large-community-list <(1-500)|WORD>",
15063 SHOW_STR
15064 BGP_STR
15065 "List large-community list\n"
15066 "large-community-list number\n"
15067 "large-community-list name\n")
15068 {
15069 struct community_list *list;
15070 int idx = 0;
15071
15072 if (argv_find(argv, argc, "ip", &idx)) {
15073 vty_out(vty, "This config option is deprecated, and is scheduled for removal.\n");
15074 vty_out(vty, "if you are using this please migrate to the below command.\n");
15075 vty_out(vty, "'show bgp large-community-list <(1-500)|WORD>'\n");
15076 zlog_warn("Deprecated option: 'ip show large-community-list <(1-500)|WORD>' being used");
15077 }
15078
15079 list = community_list_lookup(bgp_clist, argv[3]->arg, 0,
15080 LARGE_COMMUNITY_LIST_MASTER);
15081 if (!list) {
15082 vty_out(vty, "%% Can't find extcommunity-list\n");
15083 return CMD_WARNING;
15084 }
15085
15086 lcommunity_list_show(vty, list);
15087
15088 return CMD_SUCCESS;
15089 }
15090
15091 ALIAS (show_lcommunity_list_arg,
15092 show_ip_lcommunity_list_arg_cmd,
15093 "show ip large-community-list <(1-500)|WORD>",
15094 SHOW_STR
15095 IP_STR
15096 "List large-community list\n"
15097 "large-community-list number\n"
15098 "large-community-list name\n")
15099
15100 /* "extcommunity-list" keyword help string. */
15101 #define EXTCOMMUNITY_LIST_STR "Add a extended community list entry\n"
15102 #define EXTCOMMUNITY_VAL_STR "Extended community attribute in 'rt aa:nn_or_IPaddr:nn' OR 'soo aa:nn_or_IPaddr:nn' format\n"
15103
15104 DEFUN (extcommunity_list_standard,
15105 bgp_extcommunity_list_standard_cmd,
15106 "bgp extcommunity-list <(1-99)|standard WORD> <deny|permit> AA:NN...",
15107 BGP_STR
15108 EXTCOMMUNITY_LIST_STR
15109 "Extended Community list number (standard)\n"
15110 "Specify standard extcommunity-list\n"
15111 "Community list name\n"
15112 "Specify community to reject\n"
15113 "Specify community to accept\n"
15114 EXTCOMMUNITY_VAL_STR)
15115 {
15116 int style = EXTCOMMUNITY_LIST_STANDARD;
15117 int direct = 0;
15118 char *cl_number_or_name = NULL;
15119
15120 int idx = 0;
15121 if (argv_find(argv, argc, "ip", &idx)) {
15122 vty_out(vty, "This config option is deprecated, and is scheduled for removal.\n");
15123 vty_out(vty, "if you are using this please migrate to the below command.\n");
15124 vty_out(vty, "'bgp extcommunity-list <(1-99)|(100-500)|standard|expanded> <deny|permit> <LINE|AA:NN>'\n");
15125 zlog_warn("Deprecated option: 'ip extcommunity-list <(1-99)|(100-500)|standard|expanded> <deny|permit> <LINE|AA:NN>' being used");
15126 }
15127 argv_find(argv, argc, "(1-99)", &idx);
15128 argv_find(argv, argc, "WORD", &idx);
15129 cl_number_or_name = argv[idx]->arg;
15130 direct = argv_find(argv, argc, "permit", &idx) ? COMMUNITY_PERMIT
15131 : COMMUNITY_DENY;
15132 argv_find(argv, argc, "AA:NN", &idx);
15133 char *str = argv_concat(argv, argc, idx);
15134
15135 int ret = extcommunity_list_set(bgp_clist, cl_number_or_name, str,
15136 direct, style);
15137
15138 XFREE(MTYPE_TMP, str);
15139
15140 if (ret < 0) {
15141 community_list_perror(vty, ret);
15142 return CMD_WARNING_CONFIG_FAILED;
15143 }
15144
15145 return CMD_SUCCESS;
15146 }
15147
15148 #if CONFDATE > 20191005
15149 CPP_NOTICE("bgpd: remove deprecated 'ip extcommunity-list <(1-99)|(100-500)|standard|expanded> <deny|permit> <LINE|AA:NN>' command")
15150 #endif
15151 ALIAS (extcommunity_list_standard,
15152 ip_extcommunity_list_standard_cmd,
15153 "ip extcommunity-list <(1-99)|standard WORD> <deny|permit> AA:NN...",
15154 IP_STR
15155 EXTCOMMUNITY_LIST_STR
15156 "Extended Community list number (standard)\n"
15157 "Specify standard extcommunity-list\n"
15158 "Community list name\n"
15159 "Specify community to reject\n"
15160 "Specify community to accept\n"
15161 EXTCOMMUNITY_VAL_STR)
15162
15163 DEFUN (extcommunity_list_name_expanded,
15164 bgp_extcommunity_list_name_expanded_cmd,
15165 "bgp extcommunity-list <(100-500)|expanded WORD> <deny|permit> LINE...",
15166 BGP_STR
15167 EXTCOMMUNITY_LIST_STR
15168 "Extended Community list number (expanded)\n"
15169 "Specify expanded extcommunity-list\n"
15170 "Extended Community list name\n"
15171 "Specify community to reject\n"
15172 "Specify community to accept\n"
15173 "An ordered list as a regular-expression\n")
15174 {
15175 int style = EXTCOMMUNITY_LIST_EXPANDED;
15176 int direct = 0;
15177 char *cl_number_or_name = NULL;
15178
15179 int idx = 0;
15180 if (argv_find(argv, argc, "ip", &idx)) {
15181 vty_out(vty, "This config option is deprecated, and is scheduled for removal.\n");
15182 vty_out(vty, "if you are using this please migrate to the below command.\n");
15183 vty_out(vty, "'extcommunity-list <(1-99)|(100-500)|standard|expanded> <deny|permit> <LINE|AA:NN>'\n");
15184 zlog_warn("Deprecated option: ‘ip extcommunity-list <(1-99)|(100-500)|standard|expanded> <deny|permit> <LINE|AA:NN>' being used");
15185 }
15186
15187 argv_find(argv, argc, "(100-500)", &idx);
15188 argv_find(argv, argc, "WORD", &idx);
15189 cl_number_or_name = argv[idx]->arg;
15190 direct = argv_find(argv, argc, "permit", &idx) ? COMMUNITY_PERMIT
15191 : COMMUNITY_DENY;
15192 argv_find(argv, argc, "LINE", &idx);
15193 char *str = argv_concat(argv, argc, idx);
15194
15195 int ret = extcommunity_list_set(bgp_clist, cl_number_or_name, str,
15196 direct, style);
15197
15198 XFREE(MTYPE_TMP, str);
15199
15200 if (ret < 0) {
15201 community_list_perror(vty, ret);
15202 return CMD_WARNING_CONFIG_FAILED;
15203 }
15204
15205 return CMD_SUCCESS;
15206 }
15207
15208 ALIAS (extcommunity_list_name_expanded,
15209 ip_extcommunity_list_name_expanded_cmd,
15210 "ip extcommunity-list <(100-500)|expanded WORD> <deny|permit> LINE...",
15211 IP_STR
15212 EXTCOMMUNITY_LIST_STR
15213 "Extended Community list number (expanded)\n"
15214 "Specify expanded extcommunity-list\n"
15215 "Extended Community list name\n"
15216 "Specify community to reject\n"
15217 "Specify community to accept\n"
15218 "An ordered list as a regular-expression\n")
15219
15220 DEFUN (no_extcommunity_list_standard_all,
15221 no_bgp_extcommunity_list_standard_all_cmd,
15222 "no bgp extcommunity-list <(1-99)|standard WORD> <deny|permit> AA:NN...",
15223 NO_STR
15224 BGP_STR
15225 EXTCOMMUNITY_LIST_STR
15226 "Extended Community list number (standard)\n"
15227 "Specify standard extcommunity-list\n"
15228 "Community list name\n"
15229 "Specify community to reject\n"
15230 "Specify community to accept\n"
15231 EXTCOMMUNITY_VAL_STR)
15232 {
15233 int style = EXTCOMMUNITY_LIST_STANDARD;
15234 int direct = 0;
15235 char *cl_number_or_name = NULL;
15236 char *str = NULL;
15237
15238 int idx = 0;
15239 if (argv_find(argv, argc, "ip", &idx)) {
15240 vty_out(vty, "This config option is deprecated, and is scheduled for removal\n");
15241 vty_out(vty, "if you are using this please migrate to the below command.\n");
15242 vty_out(vty, "'no bgp extcommunity-list <(1-99)|(100-500)|standard|expanded> <deny|permit> <LINE|AA:NN>'\n");
15243 zlog_warn("Deprecated option: ‘no ip extcommunity-list <(1-99)|(100-500)|standard|expanded> <deny|permit> <LINE|AA:NN>' being used");
15244 }
15245
15246 idx = 0;
15247 argv_find(argv, argc, "permit", &idx);
15248 argv_find(argv, argc, "deny", &idx);
15249
15250 if (idx) {
15251 direct = argv_find(argv, argc, "permit", &idx)
15252 ? COMMUNITY_PERMIT
15253 : COMMUNITY_DENY;
15254
15255 idx = 0;
15256 argv_find(argv, argc, "AA:NN", &idx);
15257 str = argv_concat(argv, argc, idx);
15258 }
15259
15260 idx = 0;
15261 argv_find(argv, argc, "(1-99)", &idx);
15262 argv_find(argv, argc, "WORD", &idx);
15263 cl_number_or_name = argv[idx]->arg;
15264
15265 int ret = extcommunity_list_unset(bgp_clist, cl_number_or_name, str,
15266 direct, style);
15267
15268 XFREE(MTYPE_TMP, str);
15269
15270 if (ret < 0) {
15271 community_list_perror(vty, ret);
15272 return CMD_WARNING_CONFIG_FAILED;
15273 }
15274
15275 return CMD_SUCCESS;
15276 }
15277
15278 ALIAS (no_extcommunity_list_standard_all,
15279 no_ip_extcommunity_list_standard_all_cmd,
15280 "no ip extcommunity-list <(1-99)|standard WORD> <deny|permit> AA:NN...",
15281 NO_STR
15282 IP_STR
15283 EXTCOMMUNITY_LIST_STR
15284 "Extended Community list number (standard)\n"
15285 "Specify standard extcommunity-list\n"
15286 "Community list name\n"
15287 "Specify community to reject\n"
15288 "Specify community to accept\n"
15289 EXTCOMMUNITY_VAL_STR)
15290
15291 ALIAS(no_extcommunity_list_standard_all,
15292 no_bgp_extcommunity_list_standard_all_list_cmd,
15293 "no bgp extcommunity-list <(1-99)|standard WORD>",
15294 NO_STR IP_STR EXTCOMMUNITY_LIST_STR
15295 "Extended Community list number (standard)\n"
15296 "Specify standard extcommunity-list\n"
15297 "Community list name\n")
15298
15299 ALIAS(no_extcommunity_list_standard_all,
15300 no_ip_extcommunity_list_standard_all_list_cmd,
15301 "no ip extcommunity-list <(1-99)|standard WORD>",
15302 NO_STR IP_STR EXTCOMMUNITY_LIST_STR
15303 "Extended Community list number (standard)\n"
15304 "Specify standard extcommunity-list\n"
15305 "Community list name\n")
15306
15307 DEFUN (no_extcommunity_list_expanded_all,
15308 no_bgp_extcommunity_list_expanded_all_cmd,
15309 "no bgp extcommunity-list <(100-500)|expanded WORD> <deny|permit> LINE...",
15310 NO_STR
15311 BGP_STR
15312 EXTCOMMUNITY_LIST_STR
15313 "Extended Community list number (expanded)\n"
15314 "Specify expanded extcommunity-list\n"
15315 "Extended Community list name\n"
15316 "Specify community to reject\n"
15317 "Specify community to accept\n"
15318 "An ordered list as a regular-expression\n")
15319 {
15320 int style = EXTCOMMUNITY_LIST_EXPANDED;
15321 int direct = 0;
15322 char *cl_number_or_name = NULL;
15323 char *str = NULL;
15324
15325 int idx = 0;
15326 if (argv_find(argv, argc, "ip", &idx)) {
15327 vty_out(vty, "This config option is deprecated, and is scheduled for removal.\n");
15328 vty_out(vty, "if you are using this please migrate to the below command.\n");
15329 vty_out(vty, "'no bgp extcommunity-list <(1-99)|(100-500)|standard|expanded> <deny|permit> <LINE|AA:NN>'\n");
15330 zlog_warn("Deprecated option: ‘no ip extcommunity-list <(1-99)|(100-500)|standard|expanded> <deny|permit> <LINE|AA:NN>' being used");
15331 }
15332
15333 idx = 0;
15334 argv_find(argv, argc, "permit", &idx);
15335 argv_find(argv, argc, "deny", &idx);
15336
15337 if (idx) {
15338 direct = argv_find(argv, argc, "permit", &idx)
15339 ? COMMUNITY_PERMIT
15340 : COMMUNITY_DENY;
15341
15342 idx = 0;
15343 argv_find(argv, argc, "LINE", &idx);
15344 str = argv_concat(argv, argc, idx);
15345 }
15346
15347 idx = 0;
15348 argv_find(argv, argc, "(100-500)", &idx);
15349 argv_find(argv, argc, "WORD", &idx);
15350 cl_number_or_name = argv[idx]->arg;
15351
15352 int ret = extcommunity_list_unset(bgp_clist, cl_number_or_name, str,
15353 direct, style);
15354
15355 XFREE(MTYPE_TMP, str);
15356
15357 if (ret < 0) {
15358 community_list_perror(vty, ret);
15359 return CMD_WARNING_CONFIG_FAILED;
15360 }
15361
15362 return CMD_SUCCESS;
15363 }
15364
15365 ALIAS (no_extcommunity_list_expanded_all,
15366 no_ip_extcommunity_list_expanded_all_cmd,
15367 "no ip extcommunity-list <(100-500)|expanded WORD> <deny|permit> LINE...",
15368 NO_STR
15369 IP_STR
15370 EXTCOMMUNITY_LIST_STR
15371 "Extended Community list number (expanded)\n"
15372 "Specify expanded extcommunity-list\n"
15373 "Extended Community list name\n"
15374 "Specify community to reject\n"
15375 "Specify community to accept\n"
15376 "An ordered list as a regular-expression\n")
15377
15378 ALIAS(no_extcommunity_list_expanded_all,
15379 no_ip_extcommunity_list_expanded_all_list_cmd,
15380 "no ip extcommunity-list <(100-500)|expanded WORD>",
15381 NO_STR IP_STR EXTCOMMUNITY_LIST_STR
15382 "Extended Community list number (expanded)\n"
15383 "Specify expanded extcommunity-list\n"
15384 "Extended Community list name\n")
15385
15386 ALIAS(no_extcommunity_list_expanded_all,
15387 no_bgp_extcommunity_list_expanded_all_list_cmd,
15388 "no bgp extcommunity-list <(100-500)|expanded WORD>",
15389 NO_STR IP_STR EXTCOMMUNITY_LIST_STR
15390 "Extended Community list number (expanded)\n"
15391 "Specify expanded extcommunity-list\n"
15392 "Extended Community list name\n")
15393
15394 static void extcommunity_list_show(struct vty *vty, struct community_list *list)
15395 {
15396 struct community_entry *entry;
15397
15398 for (entry = list->head; entry; entry = entry->next) {
15399 if (entry == list->head) {
15400 if (all_digit(list->name))
15401 vty_out(vty, "Extended community %s list %s\n",
15402 entry->style == EXTCOMMUNITY_LIST_STANDARD
15403 ? "standard"
15404 : "(expanded) access",
15405 list->name);
15406 else
15407 vty_out(vty,
15408 "Named extended community %s list %s\n",
15409 entry->style == EXTCOMMUNITY_LIST_STANDARD
15410 ? "standard"
15411 : "expanded",
15412 list->name);
15413 }
15414 if (entry->any)
15415 vty_out(vty, " %s\n",
15416 community_direct_str(entry->direct));
15417 else
15418 vty_out(vty, " %s %s\n",
15419 community_direct_str(entry->direct),
15420 community_list_config_str(entry));
15421 }
15422 }
15423
15424 DEFUN (show_extcommunity_list,
15425 show_bgp_extcommunity_list_cmd,
15426 "show bgp extcommunity-list",
15427 SHOW_STR
15428 BGP_STR
15429 "List extended-community list\n")
15430 {
15431 struct community_list *list;
15432 struct community_list_master *cm;
15433 int idx = 0;
15434
15435 if (argv_find(argv, argc, "ip", &idx)) {
15436 vty_out(vty, "This config option is deprecated, and is scheduled for removal\n");
15437 vty_out(vty, "if you are using this please migrate to the below command.\n");
15438 vty_out(vty, "'show bgp extcommunity-list <(1-500)|WORD>'\n");
15439 zlog_warn("Deprecated option: 'ip show extcommunity-list <(1-500)|WORD>' being used");
15440 }
15441 cm = community_list_master_lookup(bgp_clist, EXTCOMMUNITY_LIST_MASTER);
15442 if (!cm)
15443 return CMD_SUCCESS;
15444
15445 for (list = cm->num.head; list; list = list->next)
15446 extcommunity_list_show(vty, list);
15447
15448 for (list = cm->str.head; list; list = list->next)
15449 extcommunity_list_show(vty, list);
15450
15451 return CMD_SUCCESS;
15452 }
15453
15454 ALIAS (show_extcommunity_list,
15455 show_ip_extcommunity_list_cmd,
15456 "show ip extcommunity-list",
15457 SHOW_STR
15458 IP_STR
15459 "List extended-community list\n")
15460
15461 DEFUN (show_extcommunity_list_arg,
15462 show_bgp_extcommunity_list_arg_cmd,
15463 "show bgp extcommunity-list <(1-500)|WORD>",
15464 SHOW_STR
15465 BGP_STR
15466 "List extended-community list\n"
15467 "Extcommunity-list number\n"
15468 "Extcommunity-list name\n")
15469 {
15470 int idx_comm_list = 3;
15471 struct community_list *list;
15472 int idx = 0;
15473
15474 if (argv_find(argv, argc, "ip", &idx)) {
15475 vty_out(vty, "This config option is deprecated, and is scheduled for removal.\n");
15476 vty_out(vty, "if you are using this please migrate to the below command.\n");
15477 vty_out(vty, "'show bgp extcommunity-list <(1-500)|WORD>'\n");
15478 zlog_warn("Deprecated option: 'ip show extcommunity-list <(1-500)|WORD>' being used");
15479 }
15480 list = community_list_lookup(bgp_clist, argv[idx_comm_list]->arg, 0,
15481 EXTCOMMUNITY_LIST_MASTER);
15482 if (!list) {
15483 vty_out(vty, "%% Can't find extcommunity-list\n");
15484 return CMD_WARNING;
15485 }
15486
15487 extcommunity_list_show(vty, list);
15488
15489 return CMD_SUCCESS;
15490 }
15491
15492 ALIAS (show_extcommunity_list_arg,
15493 show_ip_extcommunity_list_arg_cmd,
15494 "show ip extcommunity-list <(1-500)|WORD>",
15495 SHOW_STR
15496 IP_STR
15497 "List extended-community list\n"
15498 "Extcommunity-list number\n"
15499 "Extcommunity-list name\n")
15500
15501 /* Display community-list and extcommunity-list configuration. */
15502 static int community_list_config_write(struct vty *vty)
15503 {
15504 struct community_list *list;
15505 struct community_entry *entry;
15506 struct community_list_master *cm;
15507 int write = 0;
15508
15509 /* Community-list. */
15510 cm = community_list_master_lookup(bgp_clist, COMMUNITY_LIST_MASTER);
15511
15512 for (list = cm->num.head; list; list = list->next)
15513 for (entry = list->head; entry; entry = entry->next) {
15514 vty_out(vty, "bgp community-list %s %s %s\n", list->name,
15515 community_direct_str(entry->direct),
15516 community_list_config_str(entry));
15517 write++;
15518 }
15519 for (list = cm->str.head; list; list = list->next)
15520 for (entry = list->head; entry; entry = entry->next) {
15521 vty_out(vty, "bgp community-list %s %s %s %s\n",
15522 entry->style == COMMUNITY_LIST_STANDARD
15523 ? "standard"
15524 : "expanded",
15525 list->name, community_direct_str(entry->direct),
15526 community_list_config_str(entry));
15527 write++;
15528 }
15529
15530 /* Extcommunity-list. */
15531 cm = community_list_master_lookup(bgp_clist, EXTCOMMUNITY_LIST_MASTER);
15532
15533 for (list = cm->num.head; list; list = list->next)
15534 for (entry = list->head; entry; entry = entry->next) {
15535 vty_out(vty, "bgp extcommunity-list %s %s %s\n",
15536 list->name, community_direct_str(entry->direct),
15537 community_list_config_str(entry));
15538 write++;
15539 }
15540 for (list = cm->str.head; list; list = list->next)
15541 for (entry = list->head; entry; entry = entry->next) {
15542 vty_out(vty, "bgp extcommunity-list %s %s %s %s\n",
15543 entry->style == EXTCOMMUNITY_LIST_STANDARD
15544 ? "standard"
15545 : "expanded",
15546 list->name, community_direct_str(entry->direct),
15547 community_list_config_str(entry));
15548 write++;
15549 }
15550
15551
15552 /* lcommunity-list. */
15553 cm = community_list_master_lookup(bgp_clist,
15554 LARGE_COMMUNITY_LIST_MASTER);
15555
15556 for (list = cm->num.head; list; list = list->next)
15557 for (entry = list->head; entry; entry = entry->next) {
15558 vty_out(vty, "bgp large-community-list %s %s %s\n",
15559 list->name, community_direct_str(entry->direct),
15560 community_list_config_str(entry));
15561 write++;
15562 }
15563 for (list = cm->str.head; list; list = list->next)
15564 for (entry = list->head; entry; entry = entry->next) {
15565 vty_out(vty, "bgp large-community-list %s %s %s %s\n",
15566 entry->style == LARGE_COMMUNITY_LIST_STANDARD
15567 ? "standard"
15568 : "expanded",
15569 list->name, community_direct_str(entry->direct),
15570 community_list_config_str(entry));
15571 write++;
15572 }
15573
15574 return write;
15575 }
15576
15577 static struct cmd_node community_list_node = {
15578 COMMUNITY_LIST_NODE, "", 1 /* Export to vtysh. */
15579 };
15580
15581 static void community_list_vty(void)
15582 {
15583 install_node(&community_list_node, community_list_config_write);
15584
15585 /* Community-list. */
15586 install_element(CONFIG_NODE, &bgp_community_list_standard_cmd);
15587 install_element(CONFIG_NODE, &bgp_community_list_expanded_all_cmd);
15588 install_element(CONFIG_NODE, &no_bgp_community_list_standard_all_cmd);
15589 install_element(CONFIG_NODE, &no_bgp_community_list_standard_all_list_cmd);
15590 install_element(CONFIG_NODE, &no_bgp_community_list_expanded_all_cmd);
15591 install_element(CONFIG_NODE, &no_bgp_community_list_expanded_all_list_cmd);
15592 install_element(VIEW_NODE, &show_bgp_community_list_cmd);
15593 install_element(VIEW_NODE, &show_bgp_community_list_arg_cmd);
15594 install_element(CONFIG_NODE, &ip_community_list_standard_cmd);
15595 install_element(CONFIG_NODE, &ip_community_list_expanded_all_cmd);
15596 install_element(CONFIG_NODE, &no_ip_community_list_standard_all_cmd);
15597 install_element(CONFIG_NODE, &no_ip_community_list_standard_all_list_cmd);
15598 install_element(CONFIG_NODE, &no_ip_community_list_expanded_all_cmd);
15599 install_element(CONFIG_NODE, &no_ip_community_list_expanded_all_list_cmd);
15600 install_element(VIEW_NODE, &show_ip_community_list_cmd);
15601 install_element(VIEW_NODE, &show_ip_community_list_arg_cmd);
15602
15603 /* Extcommunity-list. */
15604 install_element(CONFIG_NODE, &bgp_extcommunity_list_standard_cmd);
15605 install_element(CONFIG_NODE, &bgp_extcommunity_list_name_expanded_cmd);
15606 install_element(CONFIG_NODE, &no_bgp_extcommunity_list_standard_all_cmd);
15607 install_element(CONFIG_NODE,
15608 &no_bgp_extcommunity_list_standard_all_list_cmd);
15609 install_element(CONFIG_NODE, &no_bgp_extcommunity_list_expanded_all_cmd);
15610 install_element(CONFIG_NODE,
15611 &no_bgp_extcommunity_list_expanded_all_list_cmd);
15612 install_element(VIEW_NODE, &show_bgp_extcommunity_list_cmd);
15613 install_element(VIEW_NODE, &show_bgp_extcommunity_list_arg_cmd);
15614 install_element(CONFIG_NODE, &ip_extcommunity_list_standard_cmd);
15615 install_element(CONFIG_NODE, &ip_extcommunity_list_name_expanded_cmd);
15616 install_element(CONFIG_NODE, &no_ip_extcommunity_list_standard_all_cmd);
15617 install_element(CONFIG_NODE, &no_ip_extcommunity_list_standard_all_list_cmd);
15618 install_element(CONFIG_NODE, &no_ip_extcommunity_list_expanded_all_cmd);
15619 install_element(CONFIG_NODE, &no_ip_extcommunity_list_expanded_all_list_cmd);
15620 install_element(VIEW_NODE, &show_ip_extcommunity_list_cmd);
15621 install_element(VIEW_NODE, &show_ip_extcommunity_list_arg_cmd);
15622
15623 /* Large Community List */
15624 install_element(CONFIG_NODE, &bgp_lcommunity_list_standard_cmd);
15625 install_element(CONFIG_NODE, &bgp_lcommunity_list_standard1_cmd);
15626 install_element(CONFIG_NODE, &bgp_lcommunity_list_expanded_cmd);
15627 install_element(CONFIG_NODE, &bgp_lcommunity_list_name_standard_cmd);
15628 install_element(CONFIG_NODE, &bgp_lcommunity_list_name_standard1_cmd);
15629 install_element(CONFIG_NODE, &bgp_lcommunity_list_name_expanded_cmd);
15630 install_element(CONFIG_NODE, &no_bgp_lcommunity_list_standard_all_cmd);
15631 install_element(CONFIG_NODE,
15632 &no_bgp_lcommunity_list_name_expanded_all_cmd);
15633 install_element(CONFIG_NODE, &no_bgp_lcommunity_list_standard_cmd);
15634 install_element(CONFIG_NODE, &no_bgp_lcommunity_list_expanded_cmd);
15635 install_element(CONFIG_NODE, &no_bgp_lcommunity_list_name_standard_cmd);
15636 install_element(CONFIG_NODE, &no_bgp_lcommunity_list_name_expanded_cmd);
15637 install_element(VIEW_NODE, &show_bgp_lcommunity_list_cmd);
15638 install_element(VIEW_NODE, &show_bgp_lcommunity_list_arg_cmd);
15639 install_element(CONFIG_NODE, &ip_lcommunity_list_standard_cmd);
15640 install_element(CONFIG_NODE, &ip_lcommunity_list_standard1_cmd);
15641 install_element(CONFIG_NODE, &ip_lcommunity_list_expanded_cmd);
15642 install_element(CONFIG_NODE, &ip_lcommunity_list_name_standard_cmd);
15643 install_element(CONFIG_NODE, &ip_lcommunity_list_name_standard1_cmd);
15644 install_element(CONFIG_NODE, &ip_lcommunity_list_name_expanded_cmd);
15645 install_element(CONFIG_NODE, &no_ip_lcommunity_list_standard_all_cmd);
15646 install_element(CONFIG_NODE,
15647 &no_ip_lcommunity_list_name_expanded_all_cmd);
15648 install_element(CONFIG_NODE, &no_ip_lcommunity_list_standard_cmd);
15649 install_element(CONFIG_NODE, &no_ip_lcommunity_list_expanded_cmd);
15650 install_element(CONFIG_NODE, &no_ip_lcommunity_list_name_standard_cmd);
15651 install_element(CONFIG_NODE, &no_ip_lcommunity_list_name_expanded_cmd);
15652 install_element(VIEW_NODE, &show_ip_lcommunity_list_cmd);
15653 install_element(VIEW_NODE, &show_ip_lcommunity_list_arg_cmd);
15654 }