]> git.proxmox.com Git - mirror_frr.git/blob - bgpd/bgp_vty.c
Merge pull request #5092 from sworleys/Fix-Vrf_ID-Decode_7.1
[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 = NULL;
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 if (rmap)
4907 route_map = route_map_lookup_warn_noexist(vty, rmap);
4908 ret = peer_default_originate_set(peer, afi, safi,
4909 rmap, route_map);
4910 } else
4911 ret = peer_default_originate_unset(peer, afi, safi);
4912
4913 return bgp_vty_return(vty, ret);
4914 }
4915
4916 /* neighbor default-originate. */
4917 DEFUN (neighbor_default_originate,
4918 neighbor_default_originate_cmd,
4919 "neighbor <A.B.C.D|X:X::X:X|WORD> default-originate",
4920 NEIGHBOR_STR
4921 NEIGHBOR_ADDR_STR2
4922 "Originate default route to this neighbor\n")
4923 {
4924 int idx_peer = 1;
4925 return peer_default_originate_set_vty(vty, argv[idx_peer]->arg,
4926 bgp_node_afi(vty),
4927 bgp_node_safi(vty), NULL, 1);
4928 }
4929
4930 ALIAS_HIDDEN(neighbor_default_originate, neighbor_default_originate_hidden_cmd,
4931 "neighbor <A.B.C.D|X:X::X:X|WORD> default-originate",
4932 NEIGHBOR_STR NEIGHBOR_ADDR_STR2
4933 "Originate default route to this neighbor\n")
4934
4935 DEFUN (neighbor_default_originate_rmap,
4936 neighbor_default_originate_rmap_cmd,
4937 "neighbor <A.B.C.D|X:X::X:X|WORD> default-originate route-map WORD",
4938 NEIGHBOR_STR
4939 NEIGHBOR_ADDR_STR2
4940 "Originate default route to this neighbor\n"
4941 "Route-map to specify criteria to originate default\n"
4942 "route-map name\n")
4943 {
4944 int idx_peer = 1;
4945 int idx_word = 4;
4946 return peer_default_originate_set_vty(
4947 vty, argv[idx_peer]->arg, bgp_node_afi(vty), bgp_node_safi(vty),
4948 argv[idx_word]->arg, 1);
4949 }
4950
4951 ALIAS_HIDDEN(
4952 neighbor_default_originate_rmap,
4953 neighbor_default_originate_rmap_hidden_cmd,
4954 "neighbor <A.B.C.D|X:X::X:X|WORD> default-originate route-map WORD",
4955 NEIGHBOR_STR NEIGHBOR_ADDR_STR2
4956 "Originate default route to this neighbor\n"
4957 "Route-map to specify criteria to originate default\n"
4958 "route-map name\n")
4959
4960 DEFUN (no_neighbor_default_originate,
4961 no_neighbor_default_originate_cmd,
4962 "no neighbor <A.B.C.D|X:X::X:X|WORD> default-originate [route-map WORD]",
4963 NO_STR
4964 NEIGHBOR_STR
4965 NEIGHBOR_ADDR_STR2
4966 "Originate default route to this neighbor\n"
4967 "Route-map to specify criteria to originate default\n"
4968 "route-map name\n")
4969 {
4970 int idx_peer = 2;
4971 return peer_default_originate_set_vty(vty, argv[idx_peer]->arg,
4972 bgp_node_afi(vty),
4973 bgp_node_safi(vty), NULL, 0);
4974 }
4975
4976 ALIAS_HIDDEN(
4977 no_neighbor_default_originate, no_neighbor_default_originate_hidden_cmd,
4978 "no neighbor <A.B.C.D|X:X::X:X|WORD> default-originate [route-map WORD]",
4979 NO_STR NEIGHBOR_STR NEIGHBOR_ADDR_STR2
4980 "Originate default route to this neighbor\n"
4981 "Route-map to specify criteria to originate default\n"
4982 "route-map name\n")
4983
4984
4985 /* Set neighbor's BGP port. */
4986 static int peer_port_vty(struct vty *vty, const char *ip_str, int afi,
4987 const char *port_str)
4988 {
4989 struct peer *peer;
4990 uint16_t port;
4991 struct servent *sp;
4992
4993 peer = peer_lookup_vty(vty, ip_str);
4994 if (!peer)
4995 return CMD_WARNING_CONFIG_FAILED;
4996
4997 if (!port_str) {
4998 sp = getservbyname("bgp", "tcp");
4999 port = (sp == NULL) ? BGP_PORT_DEFAULT : ntohs(sp->s_port);
5000 } else {
5001 port = strtoul(port_str, NULL, 10);
5002 }
5003
5004 peer_port_set(peer, port);
5005
5006 return CMD_SUCCESS;
5007 }
5008
5009 /* Set specified peer's BGP port. */
5010 DEFUN (neighbor_port,
5011 neighbor_port_cmd,
5012 "neighbor <A.B.C.D|X:X::X:X> port (0-65535)",
5013 NEIGHBOR_STR
5014 NEIGHBOR_ADDR_STR
5015 "Neighbor's BGP port\n"
5016 "TCP port number\n")
5017 {
5018 int idx_ip = 1;
5019 int idx_number = 3;
5020 return peer_port_vty(vty, argv[idx_ip]->arg, AFI_IP,
5021 argv[idx_number]->arg);
5022 }
5023
5024 DEFUN (no_neighbor_port,
5025 no_neighbor_port_cmd,
5026 "no neighbor <A.B.C.D|X:X::X:X> port [(0-65535)]",
5027 NO_STR
5028 NEIGHBOR_STR
5029 NEIGHBOR_ADDR_STR
5030 "Neighbor's BGP port\n"
5031 "TCP port number\n")
5032 {
5033 int idx_ip = 2;
5034 return peer_port_vty(vty, argv[idx_ip]->arg, AFI_IP, NULL);
5035 }
5036
5037
5038 /* neighbor weight. */
5039 static int peer_weight_set_vty(struct vty *vty, const char *ip_str, afi_t afi,
5040 safi_t safi, const char *weight_str)
5041 {
5042 int ret;
5043 struct peer *peer;
5044 unsigned long weight;
5045
5046 peer = peer_and_group_lookup_vty(vty, ip_str);
5047 if (!peer)
5048 return CMD_WARNING_CONFIG_FAILED;
5049
5050 weight = strtoul(weight_str, NULL, 10);
5051
5052 ret = peer_weight_set(peer, afi, safi, weight);
5053 return bgp_vty_return(vty, ret);
5054 }
5055
5056 static int peer_weight_unset_vty(struct vty *vty, const char *ip_str, afi_t afi,
5057 safi_t safi)
5058 {
5059 int ret;
5060 struct peer *peer;
5061
5062 peer = peer_and_group_lookup_vty(vty, ip_str);
5063 if (!peer)
5064 return CMD_WARNING_CONFIG_FAILED;
5065
5066 ret = peer_weight_unset(peer, afi, safi);
5067 return bgp_vty_return(vty, ret);
5068 }
5069
5070 DEFUN (neighbor_weight,
5071 neighbor_weight_cmd,
5072 "neighbor <A.B.C.D|X:X::X:X|WORD> weight (0-65535)",
5073 NEIGHBOR_STR
5074 NEIGHBOR_ADDR_STR2
5075 "Set default weight for routes from this neighbor\n"
5076 "default weight\n")
5077 {
5078 int idx_peer = 1;
5079 int idx_number = 3;
5080 return peer_weight_set_vty(vty, argv[idx_peer]->arg, bgp_node_afi(vty),
5081 bgp_node_safi(vty), argv[idx_number]->arg);
5082 }
5083
5084 ALIAS_HIDDEN(neighbor_weight, neighbor_weight_hidden_cmd,
5085 "neighbor <A.B.C.D|X:X::X:X|WORD> weight (0-65535)",
5086 NEIGHBOR_STR NEIGHBOR_ADDR_STR2
5087 "Set default weight for routes from this neighbor\n"
5088 "default weight\n")
5089
5090 DEFUN (no_neighbor_weight,
5091 no_neighbor_weight_cmd,
5092 "no neighbor <A.B.C.D|X:X::X:X|WORD> weight [(0-65535)]",
5093 NO_STR
5094 NEIGHBOR_STR
5095 NEIGHBOR_ADDR_STR2
5096 "Set default weight for routes from this neighbor\n"
5097 "default weight\n")
5098 {
5099 int idx_peer = 2;
5100 return peer_weight_unset_vty(vty, argv[idx_peer]->arg,
5101 bgp_node_afi(vty), bgp_node_safi(vty));
5102 }
5103
5104 ALIAS_HIDDEN(no_neighbor_weight, no_neighbor_weight_hidden_cmd,
5105 "no neighbor <A.B.C.D|X:X::X:X|WORD> weight [(0-65535)]",
5106 NO_STR NEIGHBOR_STR NEIGHBOR_ADDR_STR2
5107 "Set default weight for routes from this neighbor\n"
5108 "default weight\n")
5109
5110
5111 /* Override capability negotiation. */
5112 DEFUN (neighbor_override_capability,
5113 neighbor_override_capability_cmd,
5114 "neighbor <A.B.C.D|X:X::X:X|WORD> override-capability",
5115 NEIGHBOR_STR
5116 NEIGHBOR_ADDR_STR2
5117 "Override capability negotiation result\n")
5118 {
5119 int idx_peer = 1;
5120 return peer_flag_set_vty(vty, argv[idx_peer]->arg,
5121 PEER_FLAG_OVERRIDE_CAPABILITY);
5122 }
5123
5124 DEFUN (no_neighbor_override_capability,
5125 no_neighbor_override_capability_cmd,
5126 "no neighbor <A.B.C.D|X:X::X:X|WORD> override-capability",
5127 NO_STR
5128 NEIGHBOR_STR
5129 NEIGHBOR_ADDR_STR2
5130 "Override capability negotiation result\n")
5131 {
5132 int idx_peer = 2;
5133 return peer_flag_unset_vty(vty, argv[idx_peer]->arg,
5134 PEER_FLAG_OVERRIDE_CAPABILITY);
5135 }
5136
5137 DEFUN (neighbor_strict_capability,
5138 neighbor_strict_capability_cmd,
5139 "neighbor <A.B.C.D|X:X::X:X|WORD> strict-capability-match",
5140 NEIGHBOR_STR
5141 NEIGHBOR_ADDR_STR2
5142 "Strict capability negotiation match\n")
5143 {
5144 int idx_peer = 1;
5145
5146 return peer_flag_set_vty(vty, argv[idx_peer]->arg,
5147 PEER_FLAG_STRICT_CAP_MATCH);
5148 }
5149
5150 DEFUN (no_neighbor_strict_capability,
5151 no_neighbor_strict_capability_cmd,
5152 "no neighbor <A.B.C.D|X:X::X:X|WORD> strict-capability-match",
5153 NO_STR
5154 NEIGHBOR_STR
5155 NEIGHBOR_ADDR_STR2
5156 "Strict capability negotiation match\n")
5157 {
5158 int idx_peer = 2;
5159
5160 return peer_flag_unset_vty(vty, argv[idx_peer]->arg,
5161 PEER_FLAG_STRICT_CAP_MATCH);
5162 }
5163
5164 static int peer_timers_set_vty(struct vty *vty, const char *ip_str,
5165 const char *keep_str, const char *hold_str)
5166 {
5167 int ret;
5168 struct peer *peer;
5169 uint32_t keepalive;
5170 uint32_t holdtime;
5171
5172 peer = peer_and_group_lookup_vty(vty, ip_str);
5173 if (!peer)
5174 return CMD_WARNING_CONFIG_FAILED;
5175
5176 keepalive = strtoul(keep_str, NULL, 10);
5177 holdtime = strtoul(hold_str, NULL, 10);
5178
5179 ret = peer_timers_set(peer, keepalive, holdtime);
5180
5181 return bgp_vty_return(vty, ret);
5182 }
5183
5184 static int peer_timers_unset_vty(struct vty *vty, const char *ip_str)
5185 {
5186 int ret;
5187 struct peer *peer;
5188
5189 peer = peer_and_group_lookup_vty(vty, ip_str);
5190 if (!peer)
5191 return CMD_WARNING_CONFIG_FAILED;
5192
5193 ret = peer_timers_unset(peer);
5194
5195 return bgp_vty_return(vty, ret);
5196 }
5197
5198 DEFUN (neighbor_timers,
5199 neighbor_timers_cmd,
5200 "neighbor <A.B.C.D|X:X::X:X|WORD> timers (0-65535) (0-65535)",
5201 NEIGHBOR_STR
5202 NEIGHBOR_ADDR_STR2
5203 "BGP per neighbor timers\n"
5204 "Keepalive interval\n"
5205 "Holdtime\n")
5206 {
5207 int idx_peer = 1;
5208 int idx_number = 3;
5209 int idx_number_2 = 4;
5210 return peer_timers_set_vty(vty, argv[idx_peer]->arg,
5211 argv[idx_number]->arg,
5212 argv[idx_number_2]->arg);
5213 }
5214
5215 DEFUN (no_neighbor_timers,
5216 no_neighbor_timers_cmd,
5217 "no neighbor <A.B.C.D|X:X::X:X|WORD> timers [(0-65535) (0-65535)]",
5218 NO_STR
5219 NEIGHBOR_STR
5220 NEIGHBOR_ADDR_STR2
5221 "BGP per neighbor timers\n"
5222 "Keepalive interval\n"
5223 "Holdtime\n")
5224 {
5225 int idx_peer = 2;
5226 return peer_timers_unset_vty(vty, argv[idx_peer]->arg);
5227 }
5228
5229
5230 static int peer_timers_connect_set_vty(struct vty *vty, const char *ip_str,
5231 const char *time_str)
5232 {
5233 int ret;
5234 struct peer *peer;
5235 uint32_t connect;
5236
5237 peer = peer_and_group_lookup_vty(vty, ip_str);
5238 if (!peer)
5239 return CMD_WARNING_CONFIG_FAILED;
5240
5241 connect = strtoul(time_str, NULL, 10);
5242
5243 ret = peer_timers_connect_set(peer, connect);
5244
5245 return bgp_vty_return(vty, ret);
5246 }
5247
5248 static int peer_timers_connect_unset_vty(struct vty *vty, const char *ip_str)
5249 {
5250 int ret;
5251 struct peer *peer;
5252
5253 peer = peer_and_group_lookup_vty(vty, ip_str);
5254 if (!peer)
5255 return CMD_WARNING_CONFIG_FAILED;
5256
5257 ret = peer_timers_connect_unset(peer);
5258
5259 return bgp_vty_return(vty, ret);
5260 }
5261
5262 DEFUN (neighbor_timers_connect,
5263 neighbor_timers_connect_cmd,
5264 "neighbor <A.B.C.D|X:X::X:X|WORD> timers connect (1-65535)",
5265 NEIGHBOR_STR
5266 NEIGHBOR_ADDR_STR2
5267 "BGP per neighbor timers\n"
5268 "BGP connect timer\n"
5269 "Connect timer\n")
5270 {
5271 int idx_peer = 1;
5272 int idx_number = 4;
5273 return peer_timers_connect_set_vty(vty, argv[idx_peer]->arg,
5274 argv[idx_number]->arg);
5275 }
5276
5277 DEFUN (no_neighbor_timers_connect,
5278 no_neighbor_timers_connect_cmd,
5279 "no neighbor <A.B.C.D|X:X::X:X|WORD> timers connect [(1-65535)]",
5280 NO_STR
5281 NEIGHBOR_STR
5282 NEIGHBOR_ADDR_STR2
5283 "BGP per neighbor timers\n"
5284 "BGP connect timer\n"
5285 "Connect timer\n")
5286 {
5287 int idx_peer = 2;
5288 return peer_timers_connect_unset_vty(vty, argv[idx_peer]->arg);
5289 }
5290
5291
5292 static int peer_advertise_interval_vty(struct vty *vty, const char *ip_str,
5293 const char *time_str, int set)
5294 {
5295 int ret;
5296 struct peer *peer;
5297 uint32_t routeadv = 0;
5298
5299 peer = peer_and_group_lookup_vty(vty, ip_str);
5300 if (!peer)
5301 return CMD_WARNING_CONFIG_FAILED;
5302
5303 if (time_str)
5304 routeadv = strtoul(time_str, NULL, 10);
5305
5306 if (set)
5307 ret = peer_advertise_interval_set(peer, routeadv);
5308 else
5309 ret = peer_advertise_interval_unset(peer);
5310
5311 return bgp_vty_return(vty, ret);
5312 }
5313
5314 DEFUN (neighbor_advertise_interval,
5315 neighbor_advertise_interval_cmd,
5316 "neighbor <A.B.C.D|X:X::X:X|WORD> advertisement-interval (0-600)",
5317 NEIGHBOR_STR
5318 NEIGHBOR_ADDR_STR2
5319 "Minimum interval between sending BGP routing updates\n"
5320 "time in seconds\n")
5321 {
5322 int idx_peer = 1;
5323 int idx_number = 3;
5324 return peer_advertise_interval_vty(vty, argv[idx_peer]->arg,
5325 argv[idx_number]->arg, 1);
5326 }
5327
5328 DEFUN (no_neighbor_advertise_interval,
5329 no_neighbor_advertise_interval_cmd,
5330 "no neighbor <A.B.C.D|X:X::X:X|WORD> advertisement-interval [(0-600)]",
5331 NO_STR
5332 NEIGHBOR_STR
5333 NEIGHBOR_ADDR_STR2
5334 "Minimum interval between sending BGP routing updates\n"
5335 "time in seconds\n")
5336 {
5337 int idx_peer = 2;
5338 return peer_advertise_interval_vty(vty, argv[idx_peer]->arg, NULL, 0);
5339 }
5340
5341
5342 /* Time to wait before processing route-map updates */
5343 DEFUN (bgp_set_route_map_delay_timer,
5344 bgp_set_route_map_delay_timer_cmd,
5345 "bgp route-map delay-timer (0-600)",
5346 SET_STR
5347 "BGP route-map delay timer\n"
5348 "Time in secs to wait before processing route-map changes\n"
5349 "0 disables the timer, no route updates happen when route-maps change\n")
5350 {
5351 int idx_number = 3;
5352 uint32_t rmap_delay_timer;
5353
5354 if (argv[idx_number]->arg) {
5355 rmap_delay_timer = strtoul(argv[idx_number]->arg, NULL, 10);
5356 bm->rmap_update_timer = rmap_delay_timer;
5357
5358 /* if the dynamic update handling is being disabled, and a timer
5359 * is
5360 * running, stop the timer and act as if the timer has already
5361 * fired.
5362 */
5363 if (!rmap_delay_timer && bm->t_rmap_update) {
5364 BGP_TIMER_OFF(bm->t_rmap_update);
5365 thread_execute(bm->master, bgp_route_map_update_timer,
5366 NULL, 0);
5367 }
5368 return CMD_SUCCESS;
5369 } else {
5370 vty_out(vty, "%% BGP invalid route-map delay-timer\n");
5371 return CMD_WARNING_CONFIG_FAILED;
5372 }
5373 }
5374
5375 DEFUN (no_bgp_set_route_map_delay_timer,
5376 no_bgp_set_route_map_delay_timer_cmd,
5377 "no bgp route-map delay-timer [(0-600)]",
5378 NO_STR
5379 BGP_STR
5380 "Default BGP route-map delay timer\n"
5381 "Reset to default time to wait for processing route-map changes\n"
5382 "0 disables the timer, no route updates happen when route-maps change\n")
5383 {
5384
5385 bm->rmap_update_timer = RMAP_DEFAULT_UPDATE_TIMER;
5386
5387 return CMD_SUCCESS;
5388 }
5389
5390
5391 /* neighbor interface */
5392 static int peer_interface_vty(struct vty *vty, const char *ip_str,
5393 const char *str)
5394 {
5395 struct peer *peer;
5396
5397 peer = peer_lookup_vty(vty, ip_str);
5398 if (!peer || peer->conf_if) {
5399 vty_out(vty, "%% BGP invalid peer %s\n", ip_str);
5400 return CMD_WARNING_CONFIG_FAILED;
5401 }
5402
5403 if (str)
5404 peer_interface_set(peer, str);
5405 else
5406 peer_interface_unset(peer);
5407
5408 return CMD_SUCCESS;
5409 }
5410
5411 DEFUN (neighbor_interface,
5412 neighbor_interface_cmd,
5413 "neighbor <A.B.C.D|X:X::X:X> interface WORD",
5414 NEIGHBOR_STR
5415 NEIGHBOR_ADDR_STR
5416 "Interface\n"
5417 "Interface name\n")
5418 {
5419 int idx_ip = 1;
5420 int idx_word = 3;
5421 return peer_interface_vty(vty, argv[idx_ip]->arg, argv[idx_word]->arg);
5422 }
5423
5424 DEFUN (no_neighbor_interface,
5425 no_neighbor_interface_cmd,
5426 "no neighbor <A.B.C.D|X:X::X:X|WORD> interface WORD",
5427 NO_STR
5428 NEIGHBOR_STR
5429 NEIGHBOR_ADDR_STR2
5430 "Interface\n"
5431 "Interface name\n")
5432 {
5433 int idx_peer = 2;
5434 return peer_interface_vty(vty, argv[idx_peer]->arg, NULL);
5435 }
5436
5437 DEFUN (neighbor_distribute_list,
5438 neighbor_distribute_list_cmd,
5439 "neighbor <A.B.C.D|X:X::X:X|WORD> distribute-list <(1-199)|(1300-2699)|WORD> <in|out>",
5440 NEIGHBOR_STR
5441 NEIGHBOR_ADDR_STR2
5442 "Filter updates to/from this neighbor\n"
5443 "IP access-list number\n"
5444 "IP access-list number (expanded range)\n"
5445 "IP Access-list name\n"
5446 "Filter incoming updates\n"
5447 "Filter outgoing updates\n")
5448 {
5449 int idx_peer = 1;
5450 int idx_acl = 3;
5451 int direct, ret;
5452 struct peer *peer;
5453
5454 const char *pstr = argv[idx_peer]->arg;
5455 const char *acl = argv[idx_acl]->arg;
5456 const char *inout = argv[argc - 1]->text;
5457
5458 peer = peer_and_group_lookup_vty(vty, pstr);
5459 if (!peer)
5460 return CMD_WARNING_CONFIG_FAILED;
5461
5462 /* Check filter direction. */
5463 direct = strmatch(inout, "in") ? FILTER_IN : FILTER_OUT;
5464 ret = peer_distribute_set(peer, bgp_node_afi(vty), bgp_node_safi(vty),
5465 direct, acl);
5466
5467 return bgp_vty_return(vty, ret);
5468 }
5469
5470 ALIAS_HIDDEN(
5471 neighbor_distribute_list, neighbor_distribute_list_hidden_cmd,
5472 "neighbor <A.B.C.D|X:X::X:X|WORD> distribute-list <(1-199)|(1300-2699)|WORD> <in|out>",
5473 NEIGHBOR_STR NEIGHBOR_ADDR_STR2
5474 "Filter updates to/from this neighbor\n"
5475 "IP access-list number\n"
5476 "IP access-list number (expanded range)\n"
5477 "IP Access-list name\n"
5478 "Filter incoming updates\n"
5479 "Filter outgoing updates\n")
5480
5481 DEFUN (no_neighbor_distribute_list,
5482 no_neighbor_distribute_list_cmd,
5483 "no neighbor <A.B.C.D|X:X::X:X|WORD> distribute-list <(1-199)|(1300-2699)|WORD> <in|out>",
5484 NO_STR
5485 NEIGHBOR_STR
5486 NEIGHBOR_ADDR_STR2
5487 "Filter updates to/from this neighbor\n"
5488 "IP access-list number\n"
5489 "IP access-list number (expanded range)\n"
5490 "IP Access-list name\n"
5491 "Filter incoming updates\n"
5492 "Filter outgoing updates\n")
5493 {
5494 int idx_peer = 2;
5495 int direct, ret;
5496 struct peer *peer;
5497
5498 const char *pstr = argv[idx_peer]->arg;
5499 const char *inout = argv[argc - 1]->text;
5500
5501 peer = peer_and_group_lookup_vty(vty, pstr);
5502 if (!peer)
5503 return CMD_WARNING_CONFIG_FAILED;
5504
5505 /* Check filter direction. */
5506 direct = strmatch(inout, "in") ? FILTER_IN : FILTER_OUT;
5507 ret = peer_distribute_unset(peer, bgp_node_afi(vty), bgp_node_safi(vty),
5508 direct);
5509
5510 return bgp_vty_return(vty, ret);
5511 }
5512
5513 ALIAS_HIDDEN(
5514 no_neighbor_distribute_list, no_neighbor_distribute_list_hidden_cmd,
5515 "no neighbor <A.B.C.D|X:X::X:X|WORD> distribute-list <(1-199)|(1300-2699)|WORD> <in|out>",
5516 NO_STR NEIGHBOR_STR NEIGHBOR_ADDR_STR2
5517 "Filter updates to/from this neighbor\n"
5518 "IP access-list number\n"
5519 "IP access-list number (expanded range)\n"
5520 "IP Access-list name\n"
5521 "Filter incoming updates\n"
5522 "Filter outgoing updates\n")
5523
5524 /* Set prefix list to the peer. */
5525 static int peer_prefix_list_set_vty(struct vty *vty, const char *ip_str,
5526 afi_t afi, safi_t safi,
5527 const char *name_str,
5528 const char *direct_str)
5529 {
5530 int ret;
5531 int direct = FILTER_IN;
5532 struct peer *peer;
5533
5534 peer = peer_and_group_lookup_vty(vty, ip_str);
5535 if (!peer)
5536 return CMD_WARNING_CONFIG_FAILED;
5537
5538 /* Check filter direction. */
5539 if (strncmp(direct_str, "i", 1) == 0)
5540 direct = FILTER_IN;
5541 else if (strncmp(direct_str, "o", 1) == 0)
5542 direct = FILTER_OUT;
5543
5544 ret = peer_prefix_list_set(peer, afi, safi, direct, name_str);
5545
5546 return bgp_vty_return(vty, ret);
5547 }
5548
5549 static int peer_prefix_list_unset_vty(struct vty *vty, const char *ip_str,
5550 afi_t afi, safi_t safi,
5551 const char *direct_str)
5552 {
5553 int ret;
5554 struct peer *peer;
5555 int direct = FILTER_IN;
5556
5557 peer = peer_and_group_lookup_vty(vty, ip_str);
5558 if (!peer)
5559 return CMD_WARNING_CONFIG_FAILED;
5560
5561 /* Check filter direction. */
5562 if (strncmp(direct_str, "i", 1) == 0)
5563 direct = FILTER_IN;
5564 else if (strncmp(direct_str, "o", 1) == 0)
5565 direct = FILTER_OUT;
5566
5567 ret = peer_prefix_list_unset(peer, afi, safi, direct);
5568
5569 return bgp_vty_return(vty, ret);
5570 }
5571
5572 DEFUN (neighbor_prefix_list,
5573 neighbor_prefix_list_cmd,
5574 "neighbor <A.B.C.D|X:X::X:X|WORD> prefix-list WORD <in|out>",
5575 NEIGHBOR_STR
5576 NEIGHBOR_ADDR_STR2
5577 "Filter updates to/from this neighbor\n"
5578 "Name of a prefix list\n"
5579 "Filter incoming updates\n"
5580 "Filter outgoing updates\n")
5581 {
5582 int idx_peer = 1;
5583 int idx_word = 3;
5584 int idx_in_out = 4;
5585 return peer_prefix_list_set_vty(
5586 vty, argv[idx_peer]->arg, bgp_node_afi(vty), bgp_node_safi(vty),
5587 argv[idx_word]->arg, argv[idx_in_out]->arg);
5588 }
5589
5590 ALIAS_HIDDEN(neighbor_prefix_list, neighbor_prefix_list_hidden_cmd,
5591 "neighbor <A.B.C.D|X:X::X:X|WORD> prefix-list WORD <in|out>",
5592 NEIGHBOR_STR NEIGHBOR_ADDR_STR2
5593 "Filter updates to/from this neighbor\n"
5594 "Name of a prefix list\n"
5595 "Filter incoming updates\n"
5596 "Filter outgoing updates\n")
5597
5598 DEFUN (no_neighbor_prefix_list,
5599 no_neighbor_prefix_list_cmd,
5600 "no neighbor <A.B.C.D|X:X::X:X|WORD> prefix-list WORD <in|out>",
5601 NO_STR
5602 NEIGHBOR_STR
5603 NEIGHBOR_ADDR_STR2
5604 "Filter updates to/from this neighbor\n"
5605 "Name of a prefix list\n"
5606 "Filter incoming updates\n"
5607 "Filter outgoing updates\n")
5608 {
5609 int idx_peer = 2;
5610 int idx_in_out = 5;
5611 return peer_prefix_list_unset_vty(vty, argv[idx_peer]->arg,
5612 bgp_node_afi(vty), bgp_node_safi(vty),
5613 argv[idx_in_out]->arg);
5614 }
5615
5616 ALIAS_HIDDEN(no_neighbor_prefix_list, no_neighbor_prefix_list_hidden_cmd,
5617 "no neighbor <A.B.C.D|X:X::X:X|WORD> prefix-list WORD <in|out>",
5618 NO_STR NEIGHBOR_STR NEIGHBOR_ADDR_STR2
5619 "Filter updates to/from this neighbor\n"
5620 "Name of a prefix list\n"
5621 "Filter incoming updates\n"
5622 "Filter outgoing updates\n")
5623
5624 static int peer_aslist_set_vty(struct vty *vty, const char *ip_str, afi_t afi,
5625 safi_t safi, const char *name_str,
5626 const char *direct_str)
5627 {
5628 int ret;
5629 struct peer *peer;
5630 int direct = FILTER_IN;
5631
5632 peer = peer_and_group_lookup_vty(vty, ip_str);
5633 if (!peer)
5634 return CMD_WARNING_CONFIG_FAILED;
5635
5636 /* Check filter direction. */
5637 if (strncmp(direct_str, "i", 1) == 0)
5638 direct = FILTER_IN;
5639 else if (strncmp(direct_str, "o", 1) == 0)
5640 direct = FILTER_OUT;
5641
5642 ret = peer_aslist_set(peer, afi, safi, direct, name_str);
5643
5644 return bgp_vty_return(vty, ret);
5645 }
5646
5647 static int peer_aslist_unset_vty(struct vty *vty, const char *ip_str, afi_t afi,
5648 safi_t safi, const char *direct_str)
5649 {
5650 int ret;
5651 struct peer *peer;
5652 int direct = FILTER_IN;
5653
5654 peer = peer_and_group_lookup_vty(vty, ip_str);
5655 if (!peer)
5656 return CMD_WARNING_CONFIG_FAILED;
5657
5658 /* Check filter direction. */
5659 if (strncmp(direct_str, "i", 1) == 0)
5660 direct = FILTER_IN;
5661 else if (strncmp(direct_str, "o", 1) == 0)
5662 direct = FILTER_OUT;
5663
5664 ret = peer_aslist_unset(peer, afi, safi, direct);
5665
5666 return bgp_vty_return(vty, ret);
5667 }
5668
5669 DEFUN (neighbor_filter_list,
5670 neighbor_filter_list_cmd,
5671 "neighbor <A.B.C.D|X:X::X:X|WORD> filter-list WORD <in|out>",
5672 NEIGHBOR_STR
5673 NEIGHBOR_ADDR_STR2
5674 "Establish BGP filters\n"
5675 "AS path access-list name\n"
5676 "Filter incoming routes\n"
5677 "Filter outgoing routes\n")
5678 {
5679 int idx_peer = 1;
5680 int idx_word = 3;
5681 int idx_in_out = 4;
5682 return peer_aslist_set_vty(vty, argv[idx_peer]->arg, bgp_node_afi(vty),
5683 bgp_node_safi(vty), argv[idx_word]->arg,
5684 argv[idx_in_out]->arg);
5685 }
5686
5687 ALIAS_HIDDEN(neighbor_filter_list, neighbor_filter_list_hidden_cmd,
5688 "neighbor <A.B.C.D|X:X::X:X|WORD> filter-list WORD <in|out>",
5689 NEIGHBOR_STR NEIGHBOR_ADDR_STR2
5690 "Establish BGP filters\n"
5691 "AS path access-list name\n"
5692 "Filter incoming routes\n"
5693 "Filter outgoing routes\n")
5694
5695 DEFUN (no_neighbor_filter_list,
5696 no_neighbor_filter_list_cmd,
5697 "no neighbor <A.B.C.D|X:X::X:X|WORD> filter-list WORD <in|out>",
5698 NO_STR
5699 NEIGHBOR_STR
5700 NEIGHBOR_ADDR_STR2
5701 "Establish BGP filters\n"
5702 "AS path access-list name\n"
5703 "Filter incoming routes\n"
5704 "Filter outgoing routes\n")
5705 {
5706 int idx_peer = 2;
5707 int idx_in_out = 5;
5708 return peer_aslist_unset_vty(vty, argv[idx_peer]->arg,
5709 bgp_node_afi(vty), bgp_node_safi(vty),
5710 argv[idx_in_out]->arg);
5711 }
5712
5713 ALIAS_HIDDEN(no_neighbor_filter_list, no_neighbor_filter_list_hidden_cmd,
5714 "no neighbor <A.B.C.D|X:X::X:X|WORD> filter-list WORD <in|out>",
5715 NO_STR NEIGHBOR_STR NEIGHBOR_ADDR_STR2
5716 "Establish BGP filters\n"
5717 "AS path access-list name\n"
5718 "Filter incoming routes\n"
5719 "Filter outgoing routes\n")
5720
5721 /* Set route-map to the peer. */
5722 static int peer_route_map_set_vty(struct vty *vty, const char *ip_str,
5723 afi_t afi, safi_t safi, const char *name_str,
5724 const char *direct_str)
5725 {
5726 int ret;
5727 struct peer *peer;
5728 int direct = RMAP_IN;
5729 struct route_map *route_map;
5730
5731 peer = peer_and_group_lookup_vty(vty, ip_str);
5732 if (!peer)
5733 return CMD_WARNING_CONFIG_FAILED;
5734
5735 /* Check filter direction. */
5736 if (strncmp(direct_str, "in", 2) == 0)
5737 direct = RMAP_IN;
5738 else if (strncmp(direct_str, "o", 1) == 0)
5739 direct = RMAP_OUT;
5740
5741 route_map = route_map_lookup_warn_noexist(vty, name_str);
5742 ret = peer_route_map_set(peer, afi, safi, direct, name_str, route_map);
5743
5744 return bgp_vty_return(vty, ret);
5745 }
5746
5747 static int peer_route_map_unset_vty(struct vty *vty, const char *ip_str,
5748 afi_t afi, safi_t safi,
5749 const char *direct_str)
5750 {
5751 int ret;
5752 struct peer *peer;
5753 int direct = RMAP_IN;
5754
5755 peer = peer_and_group_lookup_vty(vty, ip_str);
5756 if (!peer)
5757 return CMD_WARNING_CONFIG_FAILED;
5758
5759 /* Check filter direction. */
5760 if (strncmp(direct_str, "in", 2) == 0)
5761 direct = RMAP_IN;
5762 else if (strncmp(direct_str, "o", 1) == 0)
5763 direct = RMAP_OUT;
5764
5765 ret = peer_route_map_unset(peer, afi, safi, direct);
5766
5767 return bgp_vty_return(vty, ret);
5768 }
5769
5770 DEFUN (neighbor_route_map,
5771 neighbor_route_map_cmd,
5772 "neighbor <A.B.C.D|X:X::X:X|WORD> route-map WORD <in|out>",
5773 NEIGHBOR_STR
5774 NEIGHBOR_ADDR_STR2
5775 "Apply route map to neighbor\n"
5776 "Name of route map\n"
5777 "Apply map to incoming routes\n"
5778 "Apply map to outbound routes\n")
5779 {
5780 int idx_peer = 1;
5781 int idx_word = 3;
5782 int idx_in_out = 4;
5783 return peer_route_map_set_vty(
5784 vty, argv[idx_peer]->arg, bgp_node_afi(vty), bgp_node_safi(vty),
5785 argv[idx_word]->arg, argv[idx_in_out]->arg);
5786 }
5787
5788 ALIAS_HIDDEN(neighbor_route_map, neighbor_route_map_hidden_cmd,
5789 "neighbor <A.B.C.D|X:X::X:X|WORD> route-map WORD <in|out>",
5790 NEIGHBOR_STR NEIGHBOR_ADDR_STR2
5791 "Apply route map to neighbor\n"
5792 "Name of route map\n"
5793 "Apply map to incoming routes\n"
5794 "Apply map to outbound routes\n")
5795
5796 DEFUN (no_neighbor_route_map,
5797 no_neighbor_route_map_cmd,
5798 "no neighbor <A.B.C.D|X:X::X:X|WORD> route-map WORD <in|out>",
5799 NO_STR
5800 NEIGHBOR_STR
5801 NEIGHBOR_ADDR_STR2
5802 "Apply route map to neighbor\n"
5803 "Name of route map\n"
5804 "Apply map to incoming routes\n"
5805 "Apply map to outbound routes\n")
5806 {
5807 int idx_peer = 2;
5808 int idx_in_out = 5;
5809 return peer_route_map_unset_vty(vty, argv[idx_peer]->arg,
5810 bgp_node_afi(vty), bgp_node_safi(vty),
5811 argv[idx_in_out]->arg);
5812 }
5813
5814 ALIAS_HIDDEN(no_neighbor_route_map, no_neighbor_route_map_hidden_cmd,
5815 "no neighbor <A.B.C.D|X:X::X:X|WORD> route-map WORD <in|out>",
5816 NO_STR NEIGHBOR_STR NEIGHBOR_ADDR_STR2
5817 "Apply route map to neighbor\n"
5818 "Name of route map\n"
5819 "Apply map to incoming routes\n"
5820 "Apply map to outbound routes\n")
5821
5822 /* Set unsuppress-map to the peer. */
5823 static int peer_unsuppress_map_set_vty(struct vty *vty, const char *ip_str,
5824 afi_t afi, safi_t safi,
5825 const char *name_str)
5826 {
5827 int ret;
5828 struct peer *peer;
5829 struct route_map *route_map;
5830
5831 peer = peer_and_group_lookup_vty(vty, ip_str);
5832 if (!peer)
5833 return CMD_WARNING_CONFIG_FAILED;
5834
5835 route_map = route_map_lookup_warn_noexist(vty, name_str);
5836 ret = peer_unsuppress_map_set(peer, afi, safi, name_str, route_map);
5837
5838 return bgp_vty_return(vty, ret);
5839 }
5840
5841 /* Unset route-map from the peer. */
5842 static int peer_unsuppress_map_unset_vty(struct vty *vty, const char *ip_str,
5843 afi_t afi, safi_t safi)
5844 {
5845 int ret;
5846 struct peer *peer;
5847
5848 peer = peer_and_group_lookup_vty(vty, ip_str);
5849 if (!peer)
5850 return CMD_WARNING_CONFIG_FAILED;
5851
5852 ret = peer_unsuppress_map_unset(peer, afi, safi);
5853
5854 return bgp_vty_return(vty, ret);
5855 }
5856
5857 DEFUN (neighbor_unsuppress_map,
5858 neighbor_unsuppress_map_cmd,
5859 "neighbor <A.B.C.D|X:X::X:X|WORD> unsuppress-map WORD",
5860 NEIGHBOR_STR
5861 NEIGHBOR_ADDR_STR2
5862 "Route-map to selectively unsuppress suppressed routes\n"
5863 "Name of route map\n")
5864 {
5865 int idx_peer = 1;
5866 int idx_word = 3;
5867 return peer_unsuppress_map_set_vty(
5868 vty, argv[idx_peer]->arg, bgp_node_afi(vty), bgp_node_safi(vty),
5869 argv[idx_word]->arg);
5870 }
5871
5872 ALIAS_HIDDEN(neighbor_unsuppress_map, neighbor_unsuppress_map_hidden_cmd,
5873 "neighbor <A.B.C.D|X:X::X:X|WORD> unsuppress-map WORD",
5874 NEIGHBOR_STR NEIGHBOR_ADDR_STR2
5875 "Route-map to selectively unsuppress suppressed routes\n"
5876 "Name of route map\n")
5877
5878 DEFUN (no_neighbor_unsuppress_map,
5879 no_neighbor_unsuppress_map_cmd,
5880 "no neighbor <A.B.C.D|X:X::X:X|WORD> unsuppress-map WORD",
5881 NO_STR
5882 NEIGHBOR_STR
5883 NEIGHBOR_ADDR_STR2
5884 "Route-map to selectively unsuppress suppressed routes\n"
5885 "Name of route map\n")
5886 {
5887 int idx_peer = 2;
5888 return peer_unsuppress_map_unset_vty(vty, argv[idx_peer]->arg,
5889 bgp_node_afi(vty),
5890 bgp_node_safi(vty));
5891 }
5892
5893 ALIAS_HIDDEN(no_neighbor_unsuppress_map, no_neighbor_unsuppress_map_hidden_cmd,
5894 "no neighbor <A.B.C.D|X:X::X:X|WORD> unsuppress-map WORD",
5895 NO_STR NEIGHBOR_STR NEIGHBOR_ADDR_STR2
5896 "Route-map to selectively unsuppress suppressed routes\n"
5897 "Name of route map\n")
5898
5899 static int peer_maximum_prefix_set_vty(struct vty *vty, const char *ip_str,
5900 afi_t afi, safi_t safi,
5901 const char *num_str,
5902 const char *threshold_str, int warning,
5903 const char *restart_str)
5904 {
5905 int ret;
5906 struct peer *peer;
5907 uint32_t max;
5908 uint8_t threshold;
5909 uint16_t restart;
5910
5911 peer = peer_and_group_lookup_vty(vty, ip_str);
5912 if (!peer)
5913 return CMD_WARNING_CONFIG_FAILED;
5914
5915 max = strtoul(num_str, NULL, 10);
5916 if (threshold_str)
5917 threshold = atoi(threshold_str);
5918 else
5919 threshold = MAXIMUM_PREFIX_THRESHOLD_DEFAULT;
5920
5921 if (restart_str)
5922 restart = atoi(restart_str);
5923 else
5924 restart = 0;
5925
5926 ret = peer_maximum_prefix_set(peer, afi, safi, max, threshold, warning,
5927 restart);
5928
5929 return bgp_vty_return(vty, ret);
5930 }
5931
5932 static int peer_maximum_prefix_unset_vty(struct vty *vty, const char *ip_str,
5933 afi_t afi, safi_t safi)
5934 {
5935 int ret;
5936 struct peer *peer;
5937
5938 peer = peer_and_group_lookup_vty(vty, ip_str);
5939 if (!peer)
5940 return CMD_WARNING_CONFIG_FAILED;
5941
5942 ret = peer_maximum_prefix_unset(peer, afi, safi);
5943
5944 return bgp_vty_return(vty, ret);
5945 }
5946
5947 /* Maximum number of prefix configuration. prefix count is different
5948 for each peer configuration. So this configuration can be set for
5949 each peer configuration. */
5950 DEFUN (neighbor_maximum_prefix,
5951 neighbor_maximum_prefix_cmd,
5952 "neighbor <A.B.C.D|X:X::X:X|WORD> maximum-prefix (1-4294967295)",
5953 NEIGHBOR_STR
5954 NEIGHBOR_ADDR_STR2
5955 "Maximum number of prefix accept from this peer\n"
5956 "maximum no. of prefix limit\n")
5957 {
5958 int idx_peer = 1;
5959 int idx_number = 3;
5960 return peer_maximum_prefix_set_vty(
5961 vty, argv[idx_peer]->arg, bgp_node_afi(vty), bgp_node_safi(vty),
5962 argv[idx_number]->arg, NULL, 0, NULL);
5963 }
5964
5965 ALIAS_HIDDEN(neighbor_maximum_prefix, neighbor_maximum_prefix_hidden_cmd,
5966 "neighbor <A.B.C.D|X:X::X:X|WORD> maximum-prefix (1-4294967295)",
5967 NEIGHBOR_STR NEIGHBOR_ADDR_STR2
5968 "Maximum number of prefix accept from this peer\n"
5969 "maximum no. of prefix limit\n")
5970
5971 DEFUN (neighbor_maximum_prefix_threshold,
5972 neighbor_maximum_prefix_threshold_cmd,
5973 "neighbor <A.B.C.D|X:X::X:X|WORD> maximum-prefix (1-4294967295) (1-100)",
5974 NEIGHBOR_STR
5975 NEIGHBOR_ADDR_STR2
5976 "Maximum number of prefix accept from this peer\n"
5977 "maximum no. of prefix limit\n"
5978 "Threshold value (%) at which to generate a warning msg\n")
5979 {
5980 int idx_peer = 1;
5981 int idx_number = 3;
5982 int idx_number_2 = 4;
5983 return peer_maximum_prefix_set_vty(
5984 vty, argv[idx_peer]->arg, bgp_node_afi(vty), bgp_node_safi(vty),
5985 argv[idx_number]->arg, argv[idx_number_2]->arg, 0, NULL);
5986 }
5987
5988 ALIAS_HIDDEN(
5989 neighbor_maximum_prefix_threshold,
5990 neighbor_maximum_prefix_threshold_hidden_cmd,
5991 "neighbor <A.B.C.D|X:X::X:X|WORD> maximum-prefix (1-4294967295) (1-100)",
5992 NEIGHBOR_STR NEIGHBOR_ADDR_STR2
5993 "Maximum number of prefix accept from this peer\n"
5994 "maximum no. of prefix limit\n"
5995 "Threshold value (%) at which to generate a warning msg\n")
5996
5997 DEFUN (neighbor_maximum_prefix_warning,
5998 neighbor_maximum_prefix_warning_cmd,
5999 "neighbor <A.B.C.D|X:X::X:X|WORD> maximum-prefix (1-4294967295) warning-only",
6000 NEIGHBOR_STR
6001 NEIGHBOR_ADDR_STR2
6002 "Maximum number of prefix accept from this peer\n"
6003 "maximum no. of prefix limit\n"
6004 "Only give warning message when limit is exceeded\n")
6005 {
6006 int idx_peer = 1;
6007 int idx_number = 3;
6008 return peer_maximum_prefix_set_vty(
6009 vty, argv[idx_peer]->arg, bgp_node_afi(vty), bgp_node_safi(vty),
6010 argv[idx_number]->arg, NULL, 1, NULL);
6011 }
6012
6013 ALIAS_HIDDEN(
6014 neighbor_maximum_prefix_warning,
6015 neighbor_maximum_prefix_warning_hidden_cmd,
6016 "neighbor <A.B.C.D|X:X::X:X|WORD> maximum-prefix (1-4294967295) warning-only",
6017 NEIGHBOR_STR NEIGHBOR_ADDR_STR2
6018 "Maximum number of prefix accept from this peer\n"
6019 "maximum no. of prefix limit\n"
6020 "Only give warning message when limit is exceeded\n")
6021
6022 DEFUN (neighbor_maximum_prefix_threshold_warning,
6023 neighbor_maximum_prefix_threshold_warning_cmd,
6024 "neighbor <A.B.C.D|X:X::X:X|WORD> maximum-prefix (1-4294967295) (1-100) warning-only",
6025 NEIGHBOR_STR
6026 NEIGHBOR_ADDR_STR2
6027 "Maximum number of prefix accept from this peer\n"
6028 "maximum no. of prefix limit\n"
6029 "Threshold value (%) at which to generate a warning msg\n"
6030 "Only give warning message when limit is exceeded\n")
6031 {
6032 int idx_peer = 1;
6033 int idx_number = 3;
6034 int idx_number_2 = 4;
6035 return peer_maximum_prefix_set_vty(
6036 vty, argv[idx_peer]->arg, bgp_node_afi(vty), bgp_node_safi(vty),
6037 argv[idx_number]->arg, argv[idx_number_2]->arg, 1, NULL);
6038 }
6039
6040 ALIAS_HIDDEN(
6041 neighbor_maximum_prefix_threshold_warning,
6042 neighbor_maximum_prefix_threshold_warning_hidden_cmd,
6043 "neighbor <A.B.C.D|X:X::X:X|WORD> maximum-prefix (1-4294967295) (1-100) warning-only",
6044 NEIGHBOR_STR NEIGHBOR_ADDR_STR2
6045 "Maximum number of prefix accept from this peer\n"
6046 "maximum no. of prefix limit\n"
6047 "Threshold value (%) at which to generate a warning msg\n"
6048 "Only give warning message when limit is exceeded\n")
6049
6050 DEFUN (neighbor_maximum_prefix_restart,
6051 neighbor_maximum_prefix_restart_cmd,
6052 "neighbor <A.B.C.D|X:X::X:X|WORD> maximum-prefix (1-4294967295) restart (1-65535)",
6053 NEIGHBOR_STR
6054 NEIGHBOR_ADDR_STR2
6055 "Maximum number of prefix accept from this peer\n"
6056 "maximum no. of prefix limit\n"
6057 "Restart bgp connection after limit is exceeded\n"
6058 "Restart interval in minutes\n")
6059 {
6060 int idx_peer = 1;
6061 int idx_number = 3;
6062 int idx_number_2 = 5;
6063 return peer_maximum_prefix_set_vty(
6064 vty, argv[idx_peer]->arg, bgp_node_afi(vty), bgp_node_safi(vty),
6065 argv[idx_number]->arg, NULL, 0, argv[idx_number_2]->arg);
6066 }
6067
6068 ALIAS_HIDDEN(
6069 neighbor_maximum_prefix_restart,
6070 neighbor_maximum_prefix_restart_hidden_cmd,
6071 "neighbor <A.B.C.D|X:X::X:X|WORD> maximum-prefix (1-4294967295) restart (1-65535)",
6072 NEIGHBOR_STR NEIGHBOR_ADDR_STR2
6073 "Maximum number of prefix accept from this peer\n"
6074 "maximum no. of prefix limit\n"
6075 "Restart bgp connection after limit is exceeded\n"
6076 "Restart interval in minutes\n")
6077
6078 DEFUN (neighbor_maximum_prefix_threshold_restart,
6079 neighbor_maximum_prefix_threshold_restart_cmd,
6080 "neighbor <A.B.C.D|X:X::X:X|WORD> maximum-prefix (1-4294967295) (1-100) restart (1-65535)",
6081 NEIGHBOR_STR
6082 NEIGHBOR_ADDR_STR2
6083 "Maximum number of prefixes to accept from this peer\n"
6084 "maximum no. of prefix limit\n"
6085 "Threshold value (%) at which to generate a warning msg\n"
6086 "Restart bgp connection after limit is exceeded\n"
6087 "Restart interval in minutes\n")
6088 {
6089 int idx_peer = 1;
6090 int idx_number = 3;
6091 int idx_number_2 = 4;
6092 int idx_number_3 = 6;
6093 return peer_maximum_prefix_set_vty(
6094 vty, argv[idx_peer]->arg, bgp_node_afi(vty), bgp_node_safi(vty),
6095 argv[idx_number]->arg, argv[idx_number_2]->arg, 0,
6096 argv[idx_number_3]->arg);
6097 }
6098
6099 ALIAS_HIDDEN(
6100 neighbor_maximum_prefix_threshold_restart,
6101 neighbor_maximum_prefix_threshold_restart_hidden_cmd,
6102 "neighbor <A.B.C.D|X:X::X:X|WORD> maximum-prefix (1-4294967295) (1-100) restart (1-65535)",
6103 NEIGHBOR_STR NEIGHBOR_ADDR_STR2
6104 "Maximum number of prefixes to accept from this peer\n"
6105 "maximum no. of prefix limit\n"
6106 "Threshold value (%) at which to generate a warning msg\n"
6107 "Restart bgp connection after limit is exceeded\n"
6108 "Restart interval in minutes\n")
6109
6110 DEFUN (no_neighbor_maximum_prefix,
6111 no_neighbor_maximum_prefix_cmd,
6112 "no neighbor <A.B.C.D|X:X::X:X|WORD> maximum-prefix [(1-4294967295) [(1-100)] [restart (1-65535)] [warning-only]]",
6113 NO_STR
6114 NEIGHBOR_STR
6115 NEIGHBOR_ADDR_STR2
6116 "Maximum number of prefixes to accept from this peer\n"
6117 "maximum no. of prefix limit\n"
6118 "Threshold value (%) at which to generate a warning msg\n"
6119 "Restart bgp connection after limit is exceeded\n"
6120 "Restart interval in minutes\n"
6121 "Only give warning message when limit is exceeded\n")
6122 {
6123 int idx_peer = 2;
6124 return peer_maximum_prefix_unset_vty(vty, argv[idx_peer]->arg,
6125 bgp_node_afi(vty),
6126 bgp_node_safi(vty));
6127 }
6128
6129 ALIAS_HIDDEN(
6130 no_neighbor_maximum_prefix, no_neighbor_maximum_prefix_hidden_cmd,
6131 "no neighbor <A.B.C.D|X:X::X:X|WORD> maximum-prefix [(1-4294967295) [(1-100)] [restart (1-65535)] [warning-only]]",
6132 NO_STR NEIGHBOR_STR NEIGHBOR_ADDR_STR2
6133 "Maximum number of prefixes to accept from this peer\n"
6134 "maximum no. of prefix limit\n"
6135 "Threshold value (%) at which to generate a warning msg\n"
6136 "Restart bgp connection after limit is exceeded\n"
6137 "Restart interval in minutes\n"
6138 "Only give warning message when limit is exceeded\n")
6139
6140
6141 /* "neighbor allowas-in" */
6142 DEFUN (neighbor_allowas_in,
6143 neighbor_allowas_in_cmd,
6144 "neighbor <A.B.C.D|X:X::X:X|WORD> allowas-in [<(1-10)|origin>]",
6145 NEIGHBOR_STR
6146 NEIGHBOR_ADDR_STR2
6147 "Accept as-path with my AS present in it\n"
6148 "Number of occurences of AS number\n"
6149 "Only accept my AS in the as-path if the route was originated in my AS\n")
6150 {
6151 int idx_peer = 1;
6152 int idx_number_origin = 3;
6153 int ret;
6154 int origin = 0;
6155 struct peer *peer;
6156 int allow_num = 0;
6157
6158 peer = peer_and_group_lookup_vty(vty, argv[idx_peer]->arg);
6159 if (!peer)
6160 return CMD_WARNING_CONFIG_FAILED;
6161
6162 if (argc <= idx_number_origin)
6163 allow_num = 3;
6164 else {
6165 if (argv[idx_number_origin]->type == WORD_TKN)
6166 origin = 1;
6167 else
6168 allow_num = atoi(argv[idx_number_origin]->arg);
6169 }
6170
6171 ret = peer_allowas_in_set(peer, bgp_node_afi(vty), bgp_node_safi(vty),
6172 allow_num, origin);
6173
6174 return bgp_vty_return(vty, ret);
6175 }
6176
6177 ALIAS_HIDDEN(
6178 neighbor_allowas_in, neighbor_allowas_in_hidden_cmd,
6179 "neighbor <A.B.C.D|X:X::X:X|WORD> allowas-in [<(1-10)|origin>]",
6180 NEIGHBOR_STR NEIGHBOR_ADDR_STR2
6181 "Accept as-path with my AS present in it\n"
6182 "Number of occurences of AS number\n"
6183 "Only accept my AS in the as-path if the route was originated in my AS\n")
6184
6185 DEFUN (no_neighbor_allowas_in,
6186 no_neighbor_allowas_in_cmd,
6187 "no neighbor <A.B.C.D|X:X::X:X|WORD> allowas-in [<(1-10)|origin>]",
6188 NO_STR
6189 NEIGHBOR_STR
6190 NEIGHBOR_ADDR_STR2
6191 "allow local ASN appears in aspath attribute\n"
6192 "Number of occurences of AS number\n"
6193 "Only accept my AS in the as-path if the route was originated in my AS\n")
6194 {
6195 int idx_peer = 2;
6196 int ret;
6197 struct peer *peer;
6198
6199 peer = peer_and_group_lookup_vty(vty, argv[idx_peer]->arg);
6200 if (!peer)
6201 return CMD_WARNING_CONFIG_FAILED;
6202
6203 ret = peer_allowas_in_unset(peer, bgp_node_afi(vty),
6204 bgp_node_safi(vty));
6205
6206 return bgp_vty_return(vty, ret);
6207 }
6208
6209 ALIAS_HIDDEN(
6210 no_neighbor_allowas_in, no_neighbor_allowas_in_hidden_cmd,
6211 "no neighbor <A.B.C.D|X:X::X:X|WORD> allowas-in [<(1-10)|origin>]",
6212 NO_STR NEIGHBOR_STR NEIGHBOR_ADDR_STR2
6213 "allow local ASN appears in aspath attribute\n"
6214 "Number of occurences of AS number\n"
6215 "Only accept my AS in the as-path if the route was originated in my AS\n")
6216
6217 DEFUN (neighbor_ttl_security,
6218 neighbor_ttl_security_cmd,
6219 "neighbor <A.B.C.D|X:X::X:X|WORD> ttl-security hops (1-254)",
6220 NEIGHBOR_STR
6221 NEIGHBOR_ADDR_STR2
6222 "BGP ttl-security parameters\n"
6223 "Specify the maximum number of hops to the BGP peer\n"
6224 "Number of hops to BGP peer\n")
6225 {
6226 int idx_peer = 1;
6227 int idx_number = 4;
6228 struct peer *peer;
6229 int gtsm_hops;
6230
6231 peer = peer_and_group_lookup_vty(vty, argv[idx_peer]->arg);
6232 if (!peer)
6233 return CMD_WARNING_CONFIG_FAILED;
6234
6235 gtsm_hops = strtoul(argv[idx_number]->arg, NULL, 10);
6236
6237 /*
6238 * If 'neighbor swpX', then this is for directly connected peers,
6239 * we should not accept a ttl-security hops value greater than 1.
6240 */
6241 if (peer->conf_if && (gtsm_hops > 1)) {
6242 vty_out(vty,
6243 "%s is directly connected peer, hops cannot exceed 1\n",
6244 argv[idx_peer]->arg);
6245 return CMD_WARNING_CONFIG_FAILED;
6246 }
6247
6248 return bgp_vty_return(vty, peer_ttl_security_hops_set(peer, gtsm_hops));
6249 }
6250
6251 DEFUN (no_neighbor_ttl_security,
6252 no_neighbor_ttl_security_cmd,
6253 "no neighbor <A.B.C.D|X:X::X:X|WORD> ttl-security hops (1-254)",
6254 NO_STR
6255 NEIGHBOR_STR
6256 NEIGHBOR_ADDR_STR2
6257 "BGP ttl-security parameters\n"
6258 "Specify the maximum number of hops to the BGP peer\n"
6259 "Number of hops to BGP peer\n")
6260 {
6261 int idx_peer = 2;
6262 struct peer *peer;
6263
6264 peer = peer_and_group_lookup_vty(vty, argv[idx_peer]->arg);
6265 if (!peer)
6266 return CMD_WARNING_CONFIG_FAILED;
6267
6268 return bgp_vty_return(vty, peer_ttl_security_hops_unset(peer));
6269 }
6270
6271 DEFUN (neighbor_addpath_tx_all_paths,
6272 neighbor_addpath_tx_all_paths_cmd,
6273 "neighbor <A.B.C.D|X:X::X:X|WORD> addpath-tx-all-paths",
6274 NEIGHBOR_STR
6275 NEIGHBOR_ADDR_STR2
6276 "Use addpath to advertise all paths to a neighbor\n")
6277 {
6278 int idx_peer = 1;
6279 struct peer *peer;
6280
6281 peer = peer_and_group_lookup_vty(vty, argv[idx_peer]->arg);
6282 if (!peer)
6283 return CMD_WARNING_CONFIG_FAILED;
6284
6285 bgp_addpath_set_peer_type(peer, bgp_node_afi(vty), bgp_node_safi(vty),
6286 BGP_ADDPATH_ALL);
6287 return CMD_SUCCESS;
6288 }
6289
6290 ALIAS_HIDDEN(neighbor_addpath_tx_all_paths,
6291 neighbor_addpath_tx_all_paths_hidden_cmd,
6292 "neighbor <A.B.C.D|X:X::X:X|WORD> addpath-tx-all-paths",
6293 NEIGHBOR_STR NEIGHBOR_ADDR_STR2
6294 "Use addpath to advertise all paths to a neighbor\n")
6295
6296 DEFUN (no_neighbor_addpath_tx_all_paths,
6297 no_neighbor_addpath_tx_all_paths_cmd,
6298 "no neighbor <A.B.C.D|X:X::X:X|WORD> addpath-tx-all-paths",
6299 NO_STR
6300 NEIGHBOR_STR
6301 NEIGHBOR_ADDR_STR2
6302 "Use addpath to advertise all paths to a neighbor\n")
6303 {
6304 int idx_peer = 2;
6305 struct peer *peer;
6306
6307 peer = peer_and_group_lookup_vty(vty, argv[idx_peer]->arg);
6308 if (!peer)
6309 return CMD_WARNING_CONFIG_FAILED;
6310
6311 if (peer->addpath_type[bgp_node_afi(vty)][bgp_node_safi(vty)]
6312 != BGP_ADDPATH_ALL) {
6313 vty_out(vty,
6314 "%% Peer not currently configured to transmit all paths.");
6315 return CMD_WARNING_CONFIG_FAILED;
6316 }
6317
6318 bgp_addpath_set_peer_type(peer, bgp_node_afi(vty), bgp_node_safi(vty),
6319 BGP_ADDPATH_NONE);
6320
6321 return CMD_SUCCESS;
6322 }
6323
6324 ALIAS_HIDDEN(no_neighbor_addpath_tx_all_paths,
6325 no_neighbor_addpath_tx_all_paths_hidden_cmd,
6326 "no neighbor <A.B.C.D|X:X::X:X|WORD> addpath-tx-all-paths",
6327 NO_STR NEIGHBOR_STR NEIGHBOR_ADDR_STR2
6328 "Use addpath to advertise all paths to a neighbor\n")
6329
6330 DEFUN (neighbor_addpath_tx_bestpath_per_as,
6331 neighbor_addpath_tx_bestpath_per_as_cmd,
6332 "neighbor <A.B.C.D|X:X::X:X|WORD> addpath-tx-bestpath-per-AS",
6333 NEIGHBOR_STR
6334 NEIGHBOR_ADDR_STR2
6335 "Use addpath to advertise the bestpath per each neighboring AS\n")
6336 {
6337 int idx_peer = 1;
6338 struct peer *peer;
6339
6340 peer = peer_and_group_lookup_vty(vty, argv[idx_peer]->arg);
6341 if (!peer)
6342 return CMD_WARNING_CONFIG_FAILED;
6343
6344 bgp_addpath_set_peer_type(peer, bgp_node_afi(vty), bgp_node_safi(vty),
6345 BGP_ADDPATH_BEST_PER_AS);
6346
6347 return CMD_SUCCESS;
6348 }
6349
6350 ALIAS_HIDDEN(neighbor_addpath_tx_bestpath_per_as,
6351 neighbor_addpath_tx_bestpath_per_as_hidden_cmd,
6352 "neighbor <A.B.C.D|X:X::X:X|WORD> addpath-tx-bestpath-per-AS",
6353 NEIGHBOR_STR NEIGHBOR_ADDR_STR2
6354 "Use addpath to advertise the bestpath per each neighboring AS\n")
6355
6356 DEFUN (no_neighbor_addpath_tx_bestpath_per_as,
6357 no_neighbor_addpath_tx_bestpath_per_as_cmd,
6358 "no neighbor <A.B.C.D|X:X::X:X|WORD> addpath-tx-bestpath-per-AS",
6359 NO_STR
6360 NEIGHBOR_STR
6361 NEIGHBOR_ADDR_STR2
6362 "Use addpath to advertise the bestpath per each neighboring AS\n")
6363 {
6364 int idx_peer = 2;
6365 struct peer *peer;
6366
6367 peer = peer_and_group_lookup_vty(vty, argv[idx_peer]->arg);
6368 if (!peer)
6369 return CMD_WARNING_CONFIG_FAILED;
6370
6371 if (peer->addpath_type[bgp_node_afi(vty)][bgp_node_safi(vty)]
6372 != BGP_ADDPATH_BEST_PER_AS) {
6373 vty_out(vty,
6374 "%% Peer not currently configured to transmit all best path per as.");
6375 return CMD_WARNING_CONFIG_FAILED;
6376 }
6377
6378 bgp_addpath_set_peer_type(peer, bgp_node_afi(vty), bgp_node_safi(vty),
6379 BGP_ADDPATH_NONE);
6380
6381 return CMD_SUCCESS;
6382 }
6383
6384 ALIAS_HIDDEN(no_neighbor_addpath_tx_bestpath_per_as,
6385 no_neighbor_addpath_tx_bestpath_per_as_hidden_cmd,
6386 "no neighbor <A.B.C.D|X:X::X:X|WORD> addpath-tx-bestpath-per-AS",
6387 NO_STR NEIGHBOR_STR NEIGHBOR_ADDR_STR2
6388 "Use addpath to advertise the bestpath per each neighboring AS\n")
6389
6390 static int set_ecom_list(struct vty *vty, int argc, struct cmd_token **argv,
6391 struct ecommunity **list)
6392 {
6393 struct ecommunity *ecom = NULL;
6394 struct ecommunity *ecomadd;
6395
6396 for (; argc; --argc, ++argv) {
6397
6398 ecomadd = ecommunity_str2com(argv[0]->arg,
6399 ECOMMUNITY_ROUTE_TARGET, 0);
6400 if (!ecomadd) {
6401 vty_out(vty, "Malformed community-list value\n");
6402 if (ecom)
6403 ecommunity_free(&ecom);
6404 return CMD_WARNING_CONFIG_FAILED;
6405 }
6406
6407 if (ecom) {
6408 ecommunity_merge(ecom, ecomadd);
6409 ecommunity_free(&ecomadd);
6410 } else {
6411 ecom = ecomadd;
6412 }
6413 }
6414
6415 if (*list) {
6416 ecommunity_free(&*list);
6417 }
6418 *list = ecom;
6419
6420 return CMD_SUCCESS;
6421 }
6422
6423 /*
6424 * v2vimport is true if we are handling a `import vrf ...` command
6425 */
6426 static afi_t vpn_policy_getafi(struct vty *vty, struct bgp *bgp, bool v2vimport)
6427 {
6428 afi_t afi;
6429
6430 switch (vty->node) {
6431 case BGP_IPV4_NODE:
6432 afi = AFI_IP;
6433 break;
6434 case BGP_IPV6_NODE:
6435 afi = AFI_IP6;
6436 break;
6437 default:
6438 vty_out(vty,
6439 "%% context error: valid only in address-family <ipv4|ipv6> unicast block\n");
6440 return AFI_MAX;
6441 }
6442
6443 if (!v2vimport) {
6444 if (CHECK_FLAG(bgp->af_flags[afi][SAFI_UNICAST],
6445 BGP_CONFIG_VRF_TO_VRF_IMPORT)
6446 || CHECK_FLAG(bgp->af_flags[afi][SAFI_UNICAST],
6447 BGP_CONFIG_VRF_TO_VRF_EXPORT)) {
6448 vty_out(vty,
6449 "%% error: Please unconfigure import vrf commands before using vpn commands\n");
6450 return AFI_MAX;
6451 }
6452 } else {
6453 if (CHECK_FLAG(bgp->af_flags[afi][SAFI_UNICAST],
6454 BGP_CONFIG_VRF_TO_MPLSVPN_EXPORT)
6455 || CHECK_FLAG(bgp->af_flags[afi][SAFI_UNICAST],
6456 BGP_CONFIG_MPLSVPN_TO_VRF_IMPORT)) {
6457 vty_out(vty,
6458 "%% error: Please unconfigure vpn to vrf commands before using import vrf commands\n");
6459 return AFI_MAX;
6460 }
6461 }
6462 return afi;
6463 }
6464
6465 DEFPY (af_rd_vpn_export,
6466 af_rd_vpn_export_cmd,
6467 "[no] rd vpn export ASN:NN_OR_IP-ADDRESS:NN$rd_str",
6468 NO_STR
6469 "Specify route distinguisher\n"
6470 "Between current address-family and vpn\n"
6471 "For routes leaked from current address-family to vpn\n"
6472 "Route Distinguisher (<as-number>:<number> | <ip-address>:<number>)\n")
6473 {
6474 VTY_DECLVAR_CONTEXT(bgp, bgp);
6475 struct prefix_rd prd;
6476 int ret;
6477 afi_t afi;
6478 int idx = 0;
6479 int yes = 1;
6480
6481 if (argv_find(argv, argc, "no", &idx))
6482 yes = 0;
6483
6484 if (yes) {
6485 ret = str2prefix_rd(rd_str, &prd);
6486 if (!ret) {
6487 vty_out(vty, "%% Malformed rd\n");
6488 return CMD_WARNING_CONFIG_FAILED;
6489 }
6490 }
6491
6492 afi = vpn_policy_getafi(vty, bgp, false);
6493 if (afi == AFI_MAX)
6494 return CMD_WARNING_CONFIG_FAILED;
6495
6496 /*
6497 * pre-change: un-export vpn routes (vpn->vrf routes unaffected)
6498 */
6499 vpn_leak_prechange(BGP_VPN_POLICY_DIR_TOVPN, afi,
6500 bgp_get_default(), bgp);
6501
6502 if (yes) {
6503 bgp->vpn_policy[afi].tovpn_rd = prd;
6504 SET_FLAG(bgp->vpn_policy[afi].flags,
6505 BGP_VPN_POLICY_TOVPN_RD_SET);
6506 } else {
6507 UNSET_FLAG(bgp->vpn_policy[afi].flags,
6508 BGP_VPN_POLICY_TOVPN_RD_SET);
6509 }
6510
6511 /* post-change: re-export vpn routes */
6512 vpn_leak_postchange(BGP_VPN_POLICY_DIR_TOVPN, afi,
6513 bgp_get_default(), bgp);
6514
6515 return CMD_SUCCESS;
6516 }
6517
6518 ALIAS (af_rd_vpn_export,
6519 af_no_rd_vpn_export_cmd,
6520 "no rd vpn export",
6521 NO_STR
6522 "Specify route distinguisher\n"
6523 "Between current address-family and vpn\n"
6524 "For routes leaked from current address-family to vpn\n")
6525
6526 DEFPY (af_label_vpn_export,
6527 af_label_vpn_export_cmd,
6528 "[no] label vpn export <(0-1048575)$label_val|auto$label_auto>",
6529 NO_STR
6530 "label value for VRF\n"
6531 "Between current address-family and vpn\n"
6532 "For routes leaked from current address-family to vpn\n"
6533 "Label Value <0-1048575>\n"
6534 "Automatically assign a label\n")
6535 {
6536 VTY_DECLVAR_CONTEXT(bgp, bgp);
6537 mpls_label_t label = MPLS_LABEL_NONE;
6538 afi_t afi;
6539 int idx = 0;
6540 int yes = 1;
6541
6542 if (argv_find(argv, argc, "no", &idx))
6543 yes = 0;
6544
6545 /* If "no ...", squash trailing parameter */
6546 if (!yes)
6547 label_auto = NULL;
6548
6549 if (yes) {
6550 if (!label_auto)
6551 label = label_val; /* parser should force unsigned */
6552 }
6553
6554 afi = vpn_policy_getafi(vty, bgp, false);
6555 if (afi == AFI_MAX)
6556 return CMD_WARNING_CONFIG_FAILED;
6557
6558
6559 if (label_auto && CHECK_FLAG(bgp->vpn_policy[afi].flags,
6560 BGP_VPN_POLICY_TOVPN_LABEL_AUTO))
6561 /* no change */
6562 return CMD_SUCCESS;
6563
6564 /*
6565 * pre-change: un-export vpn routes (vpn->vrf routes unaffected)
6566 */
6567 vpn_leak_prechange(BGP_VPN_POLICY_DIR_TOVPN, afi,
6568 bgp_get_default(), bgp);
6569
6570 if (!label_auto && CHECK_FLAG(bgp->vpn_policy[afi].flags,
6571 BGP_VPN_POLICY_TOVPN_LABEL_AUTO)) {
6572
6573 if (bgp->vpn_policy[afi].tovpn_label != MPLS_LABEL_NONE) {
6574
6575 /*
6576 * label has previously been automatically
6577 * assigned by labelpool: release it
6578 *
6579 * NB if tovpn_label == MPLS_LABEL_NONE it
6580 * means the automatic assignment is in flight
6581 * and therefore the labelpool callback must
6582 * detect that the auto label is not needed.
6583 */
6584
6585 bgp_lp_release(LP_TYPE_VRF,
6586 &bgp->vpn_policy[afi],
6587 bgp->vpn_policy[afi].tovpn_label);
6588 }
6589 UNSET_FLAG(bgp->vpn_policy[afi].flags,
6590 BGP_VPN_POLICY_TOVPN_LABEL_AUTO);
6591 }
6592
6593 bgp->vpn_policy[afi].tovpn_label = label;
6594 if (label_auto) {
6595 SET_FLAG(bgp->vpn_policy[afi].flags,
6596 BGP_VPN_POLICY_TOVPN_LABEL_AUTO);
6597 bgp_lp_get(LP_TYPE_VRF, &bgp->vpn_policy[afi],
6598 vpn_leak_label_callback);
6599 }
6600
6601 /* post-change: re-export vpn routes */
6602 vpn_leak_postchange(BGP_VPN_POLICY_DIR_TOVPN, afi,
6603 bgp_get_default(), bgp);
6604
6605 return CMD_SUCCESS;
6606 }
6607
6608 ALIAS (af_label_vpn_export,
6609 af_no_label_vpn_export_cmd,
6610 "no label vpn export",
6611 NO_STR
6612 "label value for VRF\n"
6613 "Between current address-family and vpn\n"
6614 "For routes leaked from current address-family to vpn\n")
6615
6616 DEFPY (af_nexthop_vpn_export,
6617 af_nexthop_vpn_export_cmd,
6618 "[no] nexthop vpn export <A.B.C.D|X:X::X:X>$nexthop_str",
6619 NO_STR
6620 "Specify next hop to use for VRF advertised prefixes\n"
6621 "Between current address-family and vpn\n"
6622 "For routes leaked from current address-family to vpn\n"
6623 "IPv4 prefix\n"
6624 "IPv6 prefix\n")
6625 {
6626 VTY_DECLVAR_CONTEXT(bgp, bgp);
6627 afi_t afi;
6628 struct prefix p;
6629 int idx = 0;
6630 int yes = 1;
6631
6632 if (argv_find(argv, argc, "no", &idx))
6633 yes = 0;
6634
6635 if (yes) {
6636 if (!sockunion2hostprefix(nexthop_str, &p))
6637 return CMD_WARNING_CONFIG_FAILED;
6638 }
6639
6640 afi = vpn_policy_getafi(vty, bgp, false);
6641 if (afi == AFI_MAX)
6642 return CMD_WARNING_CONFIG_FAILED;
6643
6644 /*
6645 * pre-change: un-export vpn routes (vpn->vrf routes unaffected)
6646 */
6647 vpn_leak_prechange(BGP_VPN_POLICY_DIR_TOVPN, afi,
6648 bgp_get_default(), bgp);
6649
6650 if (yes) {
6651 bgp->vpn_policy[afi].tovpn_nexthop = p;
6652 SET_FLAG(bgp->vpn_policy[afi].flags,
6653 BGP_VPN_POLICY_TOVPN_NEXTHOP_SET);
6654 } else {
6655 UNSET_FLAG(bgp->vpn_policy[afi].flags,
6656 BGP_VPN_POLICY_TOVPN_NEXTHOP_SET);
6657 }
6658
6659 /* post-change: re-export vpn routes */
6660 vpn_leak_postchange(BGP_VPN_POLICY_DIR_TOVPN, afi,
6661 bgp_get_default(), bgp);
6662
6663 return CMD_SUCCESS;
6664 }
6665
6666 ALIAS (af_nexthop_vpn_export,
6667 af_no_nexthop_vpn_export_cmd,
6668 "no nexthop vpn export",
6669 NO_STR
6670 "Specify next hop to use for VRF advertised prefixes\n"
6671 "Between current address-family and vpn\n"
6672 "For routes leaked from current address-family to vpn\n")
6673
6674 static int vpn_policy_getdirs(struct vty *vty, const char *dstr, int *dodir)
6675 {
6676 if (!strcmp(dstr, "import")) {
6677 dodir[BGP_VPN_POLICY_DIR_FROMVPN] = 1;
6678 } else if (!strcmp(dstr, "export")) {
6679 dodir[BGP_VPN_POLICY_DIR_TOVPN] = 1;
6680 } else if (!strcmp(dstr, "both")) {
6681 dodir[BGP_VPN_POLICY_DIR_FROMVPN] = 1;
6682 dodir[BGP_VPN_POLICY_DIR_TOVPN] = 1;
6683 } else {
6684 vty_out(vty, "%% direction parse error\n");
6685 return CMD_WARNING_CONFIG_FAILED;
6686 }
6687 return CMD_SUCCESS;
6688 }
6689
6690 DEFPY (af_rt_vpn_imexport,
6691 af_rt_vpn_imexport_cmd,
6692 "[no] <rt|route-target> vpn <import|export|both>$direction_str RTLIST...",
6693 NO_STR
6694 "Specify route target list\n"
6695 "Specify route target list\n"
6696 "Between current address-family and vpn\n"
6697 "For routes leaked from vpn to current address-family: match any\n"
6698 "For routes leaked from current address-family to vpn: set\n"
6699 "both import: match any and export: set\n"
6700 "Space separated route target list (A.B.C.D:MN|EF:OPQR|GHJK:MN)\n")
6701 {
6702 VTY_DECLVAR_CONTEXT(bgp, bgp);
6703 int ret;
6704 struct ecommunity *ecom = NULL;
6705 int dodir[BGP_VPN_POLICY_DIR_MAX] = {0};
6706 vpn_policy_direction_t dir;
6707 afi_t afi;
6708 int idx = 0;
6709 int yes = 1;
6710
6711 if (argv_find(argv, argc, "no", &idx))
6712 yes = 0;
6713
6714 afi = vpn_policy_getafi(vty, bgp, false);
6715 if (afi == AFI_MAX)
6716 return CMD_WARNING_CONFIG_FAILED;
6717
6718 ret = vpn_policy_getdirs(vty, direction_str, dodir);
6719 if (ret != CMD_SUCCESS)
6720 return ret;
6721
6722 if (yes) {
6723 if (!argv_find(argv, argc, "RTLIST", &idx)) {
6724 vty_out(vty, "%% Missing RTLIST\n");
6725 return CMD_WARNING_CONFIG_FAILED;
6726 }
6727 ret = set_ecom_list(vty, argc - idx, argv + idx, &ecom);
6728 if (ret != CMD_SUCCESS) {
6729 return ret;
6730 }
6731 }
6732
6733 for (dir = 0; dir < BGP_VPN_POLICY_DIR_MAX; ++dir) {
6734 if (!dodir[dir])
6735 continue;
6736
6737 vpn_leak_prechange(dir, afi, bgp_get_default(), bgp);
6738
6739 if (yes) {
6740 if (bgp->vpn_policy[afi].rtlist[dir])
6741 ecommunity_free(
6742 &bgp->vpn_policy[afi].rtlist[dir]);
6743 bgp->vpn_policy[afi].rtlist[dir] =
6744 ecommunity_dup(ecom);
6745 } else {
6746 if (bgp->vpn_policy[afi].rtlist[dir])
6747 ecommunity_free(
6748 &bgp->vpn_policy[afi].rtlist[dir]);
6749 bgp->vpn_policy[afi].rtlist[dir] = NULL;
6750 }
6751
6752 vpn_leak_postchange(dir, afi, bgp_get_default(), bgp);
6753 }
6754
6755 if (ecom)
6756 ecommunity_free(&ecom);
6757
6758 return CMD_SUCCESS;
6759 }
6760
6761 ALIAS (af_rt_vpn_imexport,
6762 af_no_rt_vpn_imexport_cmd,
6763 "no <rt|route-target> vpn <import|export|both>$direction_str",
6764 NO_STR
6765 "Specify route target list\n"
6766 "Specify route target list\n"
6767 "Between current address-family and vpn\n"
6768 "For routes leaked from vpn to current address-family\n"
6769 "For routes leaked from current address-family to vpn\n"
6770 "both import and export\n")
6771
6772 DEFPY (af_route_map_vpn_imexport,
6773 af_route_map_vpn_imexport_cmd,
6774 /* future: "route-map <vpn|evpn|vrf NAME> <import|export> RMAP" */
6775 "[no] route-map vpn <import|export>$direction_str RMAP$rmap_str",
6776 NO_STR
6777 "Specify route map\n"
6778 "Between current address-family and vpn\n"
6779 "For routes leaked from vpn to current address-family\n"
6780 "For routes leaked from current address-family to vpn\n"
6781 "name of route-map\n")
6782 {
6783 VTY_DECLVAR_CONTEXT(bgp, bgp);
6784 int ret;
6785 int dodir[BGP_VPN_POLICY_DIR_MAX] = {0};
6786 vpn_policy_direction_t dir;
6787 afi_t afi;
6788 int idx = 0;
6789 int yes = 1;
6790
6791 if (argv_find(argv, argc, "no", &idx))
6792 yes = 0;
6793
6794 afi = vpn_policy_getafi(vty, bgp, false);
6795 if (afi == AFI_MAX)
6796 return CMD_WARNING_CONFIG_FAILED;
6797
6798 ret = vpn_policy_getdirs(vty, direction_str, dodir);
6799 if (ret != CMD_SUCCESS)
6800 return ret;
6801
6802 for (dir = 0; dir < BGP_VPN_POLICY_DIR_MAX; ++dir) {
6803 if (!dodir[dir])
6804 continue;
6805
6806 vpn_leak_prechange(dir, afi, bgp_get_default(), bgp);
6807
6808 if (yes) {
6809 if (bgp->vpn_policy[afi].rmap_name[dir])
6810 XFREE(MTYPE_ROUTE_MAP_NAME,
6811 bgp->vpn_policy[afi].rmap_name[dir]);
6812 bgp->vpn_policy[afi].rmap_name[dir] = XSTRDUP(
6813 MTYPE_ROUTE_MAP_NAME, rmap_str);
6814 bgp->vpn_policy[afi].rmap[dir] =
6815 route_map_lookup_warn_noexist(vty, rmap_str);
6816 if (!bgp->vpn_policy[afi].rmap[dir])
6817 return CMD_SUCCESS;
6818 } else {
6819 if (bgp->vpn_policy[afi].rmap_name[dir])
6820 XFREE(MTYPE_ROUTE_MAP_NAME,
6821 bgp->vpn_policy[afi].rmap_name[dir]);
6822 bgp->vpn_policy[afi].rmap_name[dir] = NULL;
6823 bgp->vpn_policy[afi].rmap[dir] = NULL;
6824 }
6825
6826 vpn_leak_postchange(dir, afi, bgp_get_default(), bgp);
6827 }
6828
6829 return CMD_SUCCESS;
6830 }
6831
6832 ALIAS (af_route_map_vpn_imexport,
6833 af_no_route_map_vpn_imexport_cmd,
6834 "no route-map vpn <import|export>$direction_str",
6835 NO_STR
6836 "Specify route map\n"
6837 "Between current address-family and vpn\n"
6838 "For routes leaked from vpn to current address-family\n"
6839 "For routes leaked from current address-family to vpn\n")
6840
6841 DEFPY(af_import_vrf_route_map, af_import_vrf_route_map_cmd,
6842 "[no] import vrf route-map RMAP$rmap_str",
6843 NO_STR
6844 "Import routes from another VRF\n"
6845 "Vrf routes being filtered\n"
6846 "Specify route map\n"
6847 "name of route-map\n")
6848 {
6849 VTY_DECLVAR_CONTEXT(bgp, bgp);
6850 vpn_policy_direction_t dir = BGP_VPN_POLICY_DIR_FROMVPN;
6851 afi_t afi;
6852 int idx = 0;
6853 int yes = 1;
6854 struct bgp *bgp_default;
6855
6856 if (argv_find(argv, argc, "no", &idx))
6857 yes = 0;
6858
6859 afi = vpn_policy_getafi(vty, bgp, true);
6860 if (afi == AFI_MAX)
6861 return CMD_WARNING_CONFIG_FAILED;
6862
6863 bgp_default = bgp_get_default();
6864 if (!bgp_default) {
6865 int32_t ret;
6866 as_t as = bgp->as;
6867
6868 /* Auto-create assuming the same AS */
6869 ret = bgp_get(&bgp_default, &as, NULL,
6870 BGP_INSTANCE_TYPE_DEFAULT);
6871
6872 if (ret) {
6873 vty_out(vty,
6874 "VRF default is not configured as a bgp instance\n");
6875 return CMD_WARNING;
6876 }
6877 }
6878
6879 vpn_leak_prechange(dir, afi, bgp_get_default(), bgp);
6880
6881 if (yes) {
6882 if (bgp->vpn_policy[afi].rmap_name[dir])
6883 XFREE(MTYPE_ROUTE_MAP_NAME,
6884 bgp->vpn_policy[afi].rmap_name[dir]);
6885 bgp->vpn_policy[afi].rmap_name[dir] =
6886 XSTRDUP(MTYPE_ROUTE_MAP_NAME, rmap_str);
6887 bgp->vpn_policy[afi].rmap[dir] =
6888 route_map_lookup_warn_noexist(vty, rmap_str);
6889 if (!bgp->vpn_policy[afi].rmap[dir])
6890 return CMD_SUCCESS;
6891 } else {
6892 if (bgp->vpn_policy[afi].rmap_name[dir])
6893 XFREE(MTYPE_ROUTE_MAP_NAME,
6894 bgp->vpn_policy[afi].rmap_name[dir]);
6895 bgp->vpn_policy[afi].rmap_name[dir] = NULL;
6896 bgp->vpn_policy[afi].rmap[dir] = NULL;
6897 }
6898
6899 vpn_leak_postchange(dir, afi, bgp_get_default(), bgp);
6900
6901 return CMD_SUCCESS;
6902 }
6903
6904 ALIAS(af_import_vrf_route_map, af_no_import_vrf_route_map_cmd,
6905 "no import vrf route-map",
6906 NO_STR
6907 "Import routes from another VRF\n"
6908 "Vrf routes being filtered\n"
6909 "Specify route map\n")
6910
6911 DEFPY(bgp_imexport_vrf, bgp_imexport_vrf_cmd,
6912 "[no] import vrf VIEWVRFNAME$import_name",
6913 NO_STR
6914 "Import routes from another VRF\n"
6915 "VRF to import from\n"
6916 "The name of the VRF\n")
6917 {
6918 VTY_DECLVAR_CONTEXT(bgp, bgp);
6919 struct listnode *node;
6920 struct bgp *vrf_bgp, *bgp_default;
6921 int32_t ret = 0;
6922 as_t as = bgp->as;
6923 bool remove = false;
6924 int32_t idx = 0;
6925 char *vname;
6926 enum bgp_instance_type bgp_type = BGP_INSTANCE_TYPE_VRF;
6927 safi_t safi;
6928 afi_t afi;
6929
6930 if (import_name == NULL) {
6931 vty_out(vty, "%% Missing import name\n");
6932 return CMD_WARNING;
6933 }
6934
6935 if (argv_find(argv, argc, "no", &idx))
6936 remove = true;
6937
6938 afi = vpn_policy_getafi(vty, bgp, true);
6939 if (afi == AFI_MAX)
6940 return CMD_WARNING_CONFIG_FAILED;
6941
6942 safi = bgp_node_safi(vty);
6943
6944 if (((BGP_INSTANCE_TYPE_DEFAULT == bgp->inst_type)
6945 && (strcmp(import_name, VRF_DEFAULT_NAME) == 0))
6946 || (bgp->name && (strcmp(import_name, bgp->name) == 0))) {
6947 vty_out(vty, "%% Cannot %s vrf %s into itself\n",
6948 remove ? "unimport" : "import", import_name);
6949 return CMD_WARNING;
6950 }
6951
6952 bgp_default = bgp_get_default();
6953 if (!bgp_default) {
6954 /* Auto-create assuming the same AS */
6955 ret = bgp_get(&bgp_default, &as, NULL,
6956 BGP_INSTANCE_TYPE_DEFAULT);
6957
6958 if (ret) {
6959 vty_out(vty,
6960 "VRF default is not configured as a bgp instance\n");
6961 return CMD_WARNING;
6962 }
6963 }
6964
6965 vrf_bgp = bgp_lookup_by_name(import_name);
6966 if (!vrf_bgp) {
6967 if (strcmp(import_name, VRF_DEFAULT_NAME) == 0)
6968 vrf_bgp = bgp_default;
6969 else
6970 /* Auto-create assuming the same AS */
6971 ret = bgp_get(&vrf_bgp, &as, import_name, bgp_type);
6972
6973 if (ret) {
6974 vty_out(vty,
6975 "VRF %s is not configured as a bgp instance\n",
6976 import_name);
6977 return CMD_WARNING;
6978 }
6979 }
6980
6981 if (remove) {
6982 vrf_unimport_from_vrf(bgp, vrf_bgp, afi, safi);
6983 } else {
6984 /* Already importing from "import_vrf"? */
6985 for (ALL_LIST_ELEMENTS_RO(bgp->vpn_policy[afi].import_vrf, node,
6986 vname)) {
6987 if (strcmp(vname, import_name) == 0)
6988 return CMD_WARNING;
6989 }
6990
6991 vrf_import_from_vrf(bgp, vrf_bgp, afi, safi);
6992 }
6993
6994 return CMD_SUCCESS;
6995 }
6996
6997 /* This command is valid only in a bgp vrf instance or the default instance */
6998 DEFPY (bgp_imexport_vpn,
6999 bgp_imexport_vpn_cmd,
7000 "[no] <import|export>$direction_str vpn",
7001 NO_STR
7002 "Import routes to this address-family\n"
7003 "Export routes from this address-family\n"
7004 "to/from default instance VPN RIB\n")
7005 {
7006 VTY_DECLVAR_CONTEXT(bgp, bgp);
7007 int previous_state;
7008 afi_t afi;
7009 safi_t safi;
7010 int idx = 0;
7011 int yes = 1;
7012 int flag;
7013 vpn_policy_direction_t dir;
7014
7015 if (argv_find(argv, argc, "no", &idx))
7016 yes = 0;
7017
7018 if (BGP_INSTANCE_TYPE_VRF != bgp->inst_type &&
7019 BGP_INSTANCE_TYPE_DEFAULT != bgp->inst_type) {
7020
7021 vty_out(vty, "%% import|export vpn valid only for bgp vrf or default instance\n");
7022 return CMD_WARNING_CONFIG_FAILED;
7023 }
7024
7025 afi = bgp_node_afi(vty);
7026 safi = bgp_node_safi(vty);
7027 if ((SAFI_UNICAST != safi) || ((AFI_IP != afi) && (AFI_IP6 != afi))) {
7028 vty_out(vty, "%% import|export vpn valid only for unicast ipv4|ipv6\n");
7029 return CMD_WARNING_CONFIG_FAILED;
7030 }
7031
7032 if (!strcmp(direction_str, "import")) {
7033 flag = BGP_CONFIG_MPLSVPN_TO_VRF_IMPORT;
7034 dir = BGP_VPN_POLICY_DIR_FROMVPN;
7035 } else if (!strcmp(direction_str, "export")) {
7036 flag = BGP_CONFIG_VRF_TO_MPLSVPN_EXPORT;
7037 dir = BGP_VPN_POLICY_DIR_TOVPN;
7038 } else {
7039 vty_out(vty, "%% unknown direction %s\n", direction_str);
7040 return CMD_WARNING_CONFIG_FAILED;
7041 }
7042
7043 previous_state = CHECK_FLAG(bgp->af_flags[afi][safi], flag);
7044
7045 if (yes) {
7046 SET_FLAG(bgp->af_flags[afi][safi], flag);
7047 if (!previous_state) {
7048 /* trigger export current vrf */
7049 vpn_leak_postchange(dir, afi, bgp_get_default(), bgp);
7050 }
7051 } else {
7052 if (previous_state) {
7053 /* trigger un-export current vrf */
7054 vpn_leak_prechange(dir, afi, bgp_get_default(), bgp);
7055 }
7056 UNSET_FLAG(bgp->af_flags[afi][safi], flag);
7057 }
7058
7059 return CMD_SUCCESS;
7060 }
7061
7062 DEFPY (af_routetarget_import,
7063 af_routetarget_import_cmd,
7064 "[no] <rt|route-target> redirect import RTLIST...",
7065 NO_STR
7066 "Specify route target list\n"
7067 "Specify route target list\n"
7068 "Flow-spec redirect type route target\n"
7069 "Import routes to this address-family\n"
7070 "Space separated route target list (A.B.C.D:MN|EF:OPQR|GHJK:MN)\n")
7071 {
7072 VTY_DECLVAR_CONTEXT(bgp, bgp);
7073 int ret;
7074 struct ecommunity *ecom = NULL;
7075 afi_t afi;
7076 int idx = 0;
7077 int yes = 1;
7078
7079 if (argv_find(argv, argc, "no", &idx))
7080 yes = 0;
7081
7082 afi = vpn_policy_getafi(vty, bgp, false);
7083 if (afi == AFI_MAX)
7084 return CMD_WARNING_CONFIG_FAILED;
7085
7086 if (yes) {
7087 if (!argv_find(argv, argc, "RTLIST", &idx)) {
7088 vty_out(vty, "%% Missing RTLIST\n");
7089 return CMD_WARNING_CONFIG_FAILED;
7090 }
7091 ret = set_ecom_list(vty, argc - idx, argv + idx, &ecom);
7092 if (ret != CMD_SUCCESS)
7093 return ret;
7094 }
7095
7096 if (yes) {
7097 if (bgp->vpn_policy[afi].import_redirect_rtlist)
7098 ecommunity_free(&bgp->vpn_policy[afi]
7099 .import_redirect_rtlist);
7100 bgp->vpn_policy[afi].import_redirect_rtlist =
7101 ecommunity_dup(ecom);
7102 } else {
7103 if (bgp->vpn_policy[afi].import_redirect_rtlist)
7104 ecommunity_free(&bgp->vpn_policy[afi]
7105 .import_redirect_rtlist);
7106 bgp->vpn_policy[afi].import_redirect_rtlist = NULL;
7107 }
7108
7109 if (ecom)
7110 ecommunity_free(&ecom);
7111
7112 return CMD_SUCCESS;
7113 }
7114
7115 DEFUN_NOSH (address_family_ipv4_safi,
7116 address_family_ipv4_safi_cmd,
7117 "address-family ipv4 [<unicast|multicast|vpn|labeled-unicast|flowspec>]",
7118 "Enter Address Family command mode\n"
7119 "Address Family\n"
7120 BGP_SAFI_WITH_LABEL_HELP_STR)
7121 {
7122
7123 if (argc == 3) {
7124 VTY_DECLVAR_CONTEXT(bgp, bgp);
7125 safi_t safi = bgp_vty_safi_from_str(argv[2]->text);
7126 if (bgp->inst_type != BGP_INSTANCE_TYPE_DEFAULT
7127 && safi != SAFI_UNICAST && safi != SAFI_MULTICAST
7128 && safi != SAFI_EVPN) {
7129 vty_out(vty,
7130 "Only Unicast/Multicast/EVPN SAFIs supported in non-core instances.\n");
7131 return CMD_WARNING_CONFIG_FAILED;
7132 }
7133 vty->node = bgp_node_type(AFI_IP, safi);
7134 } else
7135 vty->node = BGP_IPV4_NODE;
7136
7137 return CMD_SUCCESS;
7138 }
7139
7140 DEFUN_NOSH (address_family_ipv6_safi,
7141 address_family_ipv6_safi_cmd,
7142 "address-family ipv6 [<unicast|multicast|vpn|labeled-unicast|flowspec>]",
7143 "Enter Address Family command mode\n"
7144 "Address Family\n"
7145 BGP_SAFI_WITH_LABEL_HELP_STR)
7146 {
7147 if (argc == 3) {
7148 VTY_DECLVAR_CONTEXT(bgp, bgp);
7149 safi_t safi = bgp_vty_safi_from_str(argv[2]->text);
7150 if (bgp->inst_type != BGP_INSTANCE_TYPE_DEFAULT
7151 && safi != SAFI_UNICAST && safi != SAFI_MULTICAST
7152 && safi != SAFI_EVPN) {
7153 vty_out(vty,
7154 "Only Unicast/Multicast/EVPN SAFIs supported in non-core instances.\n");
7155 return CMD_WARNING_CONFIG_FAILED;
7156 }
7157 vty->node = bgp_node_type(AFI_IP6, safi);
7158 } else
7159 vty->node = BGP_IPV6_NODE;
7160
7161 return CMD_SUCCESS;
7162 }
7163
7164 #ifdef KEEP_OLD_VPN_COMMANDS
7165 DEFUN_NOSH (address_family_vpnv4,
7166 address_family_vpnv4_cmd,
7167 "address-family vpnv4 [unicast]",
7168 "Enter Address Family command mode\n"
7169 "Address Family\n"
7170 "Address Family modifier\n")
7171 {
7172 vty->node = BGP_VPNV4_NODE;
7173 return CMD_SUCCESS;
7174 }
7175
7176 DEFUN_NOSH (address_family_vpnv6,
7177 address_family_vpnv6_cmd,
7178 "address-family vpnv6 [unicast]",
7179 "Enter Address Family command mode\n"
7180 "Address Family\n"
7181 "Address Family modifier\n")
7182 {
7183 vty->node = BGP_VPNV6_NODE;
7184 return CMD_SUCCESS;
7185 }
7186 #endif /* KEEP_OLD_VPN_COMMANDS */
7187
7188 DEFUN_NOSH (address_family_evpn,
7189 address_family_evpn_cmd,
7190 "address-family l2vpn evpn",
7191 "Enter Address Family command mode\n"
7192 "Address Family\n"
7193 "Address Family modifier\n")
7194 {
7195 VTY_DECLVAR_CONTEXT(bgp, bgp);
7196 vty->node = BGP_EVPN_NODE;
7197 return CMD_SUCCESS;
7198 }
7199
7200 DEFUN_NOSH (exit_address_family,
7201 exit_address_family_cmd,
7202 "exit-address-family",
7203 "Exit from Address Family configuration mode\n")
7204 {
7205 if (vty->node == BGP_IPV4_NODE || vty->node == BGP_IPV4M_NODE
7206 || vty->node == BGP_IPV4L_NODE || vty->node == BGP_VPNV4_NODE
7207 || vty->node == BGP_IPV6_NODE || vty->node == BGP_IPV6M_NODE
7208 || vty->node == BGP_IPV6L_NODE || vty->node == BGP_VPNV6_NODE
7209 || vty->node == BGP_EVPN_NODE
7210 || vty->node == BGP_FLOWSPECV4_NODE
7211 || vty->node == BGP_FLOWSPECV6_NODE)
7212 vty->node = BGP_NODE;
7213 return CMD_SUCCESS;
7214 }
7215
7216 /* Recalculate bestpath and re-advertise a prefix */
7217 static int bgp_clear_prefix(struct vty *vty, const char *view_name,
7218 const char *ip_str, afi_t afi, safi_t safi,
7219 struct prefix_rd *prd)
7220 {
7221 int ret;
7222 struct prefix match;
7223 struct bgp_node *rn;
7224 struct bgp_node *rm;
7225 struct bgp *bgp;
7226 struct bgp_table *table;
7227 struct bgp_table *rib;
7228
7229 /* BGP structure lookup. */
7230 if (view_name) {
7231 bgp = bgp_lookup_by_name(view_name);
7232 if (bgp == NULL) {
7233 vty_out(vty, "%% Can't find BGP instance %s\n",
7234 view_name);
7235 return CMD_WARNING;
7236 }
7237 } else {
7238 bgp = bgp_get_default();
7239 if (bgp == NULL) {
7240 vty_out(vty, "%% No BGP process is configured\n");
7241 return CMD_WARNING;
7242 }
7243 }
7244
7245 /* Check IP address argument. */
7246 ret = str2prefix(ip_str, &match);
7247 if (!ret) {
7248 vty_out(vty, "%% address is malformed\n");
7249 return CMD_WARNING;
7250 }
7251
7252 match.family = afi2family(afi);
7253 rib = bgp->rib[afi][safi];
7254
7255 if (safi == SAFI_MPLS_VPN) {
7256 for (rn = bgp_table_top(rib); rn; rn = bgp_route_next(rn)) {
7257 if (prd && memcmp(rn->p.u.val, prd->val, 8) != 0)
7258 continue;
7259
7260 table = bgp_node_get_bgp_table_info(rn);
7261 if (table != NULL) {
7262
7263 if ((rm = bgp_node_match(table, &match))
7264 != NULL) {
7265 if (rm->p.prefixlen
7266 == match.prefixlen) {
7267 SET_FLAG(rm->flags,
7268 BGP_NODE_USER_CLEAR);
7269 bgp_process(bgp, rm, afi, safi);
7270 }
7271 bgp_unlock_node(rm);
7272 }
7273 }
7274 }
7275 } else {
7276 if ((rn = bgp_node_match(rib, &match)) != NULL) {
7277 if (rn->p.prefixlen == match.prefixlen) {
7278 SET_FLAG(rn->flags, BGP_NODE_USER_CLEAR);
7279 bgp_process(bgp, rn, afi, safi);
7280 }
7281 bgp_unlock_node(rn);
7282 }
7283 }
7284
7285 return CMD_SUCCESS;
7286 }
7287
7288 /* one clear bgp command to rule them all */
7289 DEFUN (clear_ip_bgp_all,
7290 clear_ip_bgp_all_cmd,
7291 "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>]",
7292 CLEAR_STR
7293 IP_STR
7294 BGP_STR
7295 BGP_INSTANCE_HELP_STR
7296 BGP_AFI_HELP_STR
7297 "Address Family\n"
7298 BGP_SAFI_WITH_LABEL_HELP_STR
7299 "Address Family modifier\n"
7300 "Clear all peers\n"
7301 "BGP neighbor address to clear\n"
7302 "BGP IPv6 neighbor to clear\n"
7303 "BGP neighbor on interface to clear\n"
7304 "Clear peers with the AS number\n"
7305 "Clear all external peers\n"
7306 "Clear all members of peer-group\n"
7307 "BGP peer-group name\n"
7308 BGP_SOFT_STR
7309 BGP_SOFT_IN_STR
7310 BGP_SOFT_OUT_STR
7311 BGP_SOFT_IN_STR
7312 "Push out prefix-list ORF and do inbound soft reconfig\n"
7313 BGP_SOFT_OUT_STR)
7314 {
7315 char *vrf = NULL;
7316
7317 afi_t afi = AFI_IP6;
7318 safi_t safi = SAFI_UNICAST;
7319 enum clear_sort clr_sort = clear_peer;
7320 enum bgp_clear_type clr_type;
7321 char *clr_arg = NULL;
7322
7323 int idx = 0;
7324
7325 /* clear [ip] bgp */
7326 if (argv_find(argv, argc, "ip", &idx))
7327 afi = AFI_IP;
7328
7329 /* [<vrf> VIEWVRFNAME] */
7330 if (argv_find(argv, argc, "vrf", &idx)) {
7331 vrf = argv[idx + 1]->arg;
7332 idx += 2;
7333 if (vrf && strmatch(vrf, VRF_DEFAULT_NAME))
7334 vrf = NULL;
7335 } else if (argv_find(argv, argc, "view", &idx)) {
7336 /* [<view> VIEWVRFNAME] */
7337 vrf = argv[idx + 1]->arg;
7338 idx += 2;
7339 }
7340 /* ["BGP_AFI_CMD_STR" ["BGP_SAFI_CMD_STR"]] */
7341 if (argv_find_and_parse_afi(argv, argc, &idx, &afi))
7342 argv_find_and_parse_safi(argv, argc, &idx, &safi);
7343
7344 /* <*|A.B.C.D|X:X::X:X|WORD|(1-4294967295)|external|peer-group PGNAME> */
7345 if (argv_find(argv, argc, "*", &idx)) {
7346 clr_sort = clear_all;
7347 } else if (argv_find(argv, argc, "A.B.C.D", &idx)) {
7348 clr_sort = clear_peer;
7349 clr_arg = argv[idx]->arg;
7350 } else if (argv_find(argv, argc, "X:X::X:X", &idx)) {
7351 clr_sort = clear_peer;
7352 clr_arg = argv[idx]->arg;
7353 } else if (argv_find(argv, argc, "peer-group", &idx)) {
7354 clr_sort = clear_group;
7355 idx++;
7356 clr_arg = argv[idx]->arg;
7357 } else if (argv_find(argv, argc, "PGNAME", &idx)) {
7358 clr_sort = clear_peer;
7359 clr_arg = argv[idx]->arg;
7360 } else if (argv_find(argv, argc, "(1-4294967295)", &idx)) {
7361 clr_sort = clear_as;
7362 clr_arg = argv[idx]->arg;
7363 } else if (argv_find(argv, argc, "external", &idx)) {
7364 clr_sort = clear_external;
7365 }
7366
7367 /* [<soft [<in|out>]|in [prefix-filter]|out>] */
7368 if (argv_find(argv, argc, "soft", &idx)) {
7369 if (argv_find(argv, argc, "in", &idx)
7370 || argv_find(argv, argc, "out", &idx))
7371 clr_type = strmatch(argv[idx]->text, "in")
7372 ? BGP_CLEAR_SOFT_IN
7373 : BGP_CLEAR_SOFT_OUT;
7374 else
7375 clr_type = BGP_CLEAR_SOFT_BOTH;
7376 } else if (argv_find(argv, argc, "in", &idx)) {
7377 clr_type = argv_find(argv, argc, "prefix-filter", &idx)
7378 ? BGP_CLEAR_SOFT_IN_ORF_PREFIX
7379 : BGP_CLEAR_SOFT_IN;
7380 } else if (argv_find(argv, argc, "out", &idx)) {
7381 clr_type = BGP_CLEAR_SOFT_OUT;
7382 } else
7383 clr_type = BGP_CLEAR_SOFT_NONE;
7384
7385 return bgp_clear_vty(vty, vrf, afi, safi, clr_sort, clr_type, clr_arg);
7386 }
7387
7388 DEFUN (clear_ip_bgp_prefix,
7389 clear_ip_bgp_prefix_cmd,
7390 "clear [ip] bgp [<view|vrf> VIEWVRFNAME] prefix A.B.C.D/M",
7391 CLEAR_STR
7392 IP_STR
7393 BGP_STR
7394 BGP_INSTANCE_HELP_STR
7395 "Clear bestpath and re-advertise\n"
7396 "IPv4 prefix\n")
7397 {
7398 char *vrf = NULL;
7399 char *prefix = NULL;
7400
7401 int idx = 0;
7402
7403 /* [<view|vrf> VIEWVRFNAME] */
7404 if (argv_find(argv, argc, "vrf", &idx)) {
7405 vrf = argv[idx + 1]->arg;
7406 idx += 2;
7407 if (vrf && strmatch(vrf, VRF_DEFAULT_NAME))
7408 vrf = NULL;
7409 } else if (argv_find(argv, argc, "view", &idx)) {
7410 /* [<view> VIEWVRFNAME] */
7411 vrf = argv[idx + 1]->arg;
7412 idx += 2;
7413 }
7414
7415 prefix = argv[argc - 1]->arg;
7416
7417 return bgp_clear_prefix(vty, vrf, prefix, AFI_IP, SAFI_UNICAST, NULL);
7418 }
7419
7420 DEFUN (clear_bgp_ipv6_safi_prefix,
7421 clear_bgp_ipv6_safi_prefix_cmd,
7422 "clear [ip] bgp ipv6 "BGP_SAFI_CMD_STR" prefix X:X::X:X/M",
7423 CLEAR_STR
7424 IP_STR
7425 BGP_STR
7426 "Address Family\n"
7427 BGP_SAFI_HELP_STR
7428 "Clear bestpath and re-advertise\n"
7429 "IPv6 prefix\n")
7430 {
7431 int idx_safi = 0;
7432 int idx_ipv6_prefix = 0;
7433 safi_t safi = SAFI_UNICAST;
7434 char *prefix = argv_find(argv, argc, "X:X::X:X/M", &idx_ipv6_prefix) ?
7435 argv[idx_ipv6_prefix]->arg : NULL;
7436
7437 argv_find_and_parse_safi(argv, argc, &idx_safi, &safi);
7438 return bgp_clear_prefix(
7439 vty, NULL, prefix, AFI_IP6,
7440 safi, NULL);
7441 }
7442
7443 DEFUN (clear_bgp_instance_ipv6_safi_prefix,
7444 clear_bgp_instance_ipv6_safi_prefix_cmd,
7445 "clear [ip] bgp <view|vrf> VIEWVRFNAME ipv6 "BGP_SAFI_CMD_STR" prefix X:X::X:X/M",
7446 CLEAR_STR
7447 IP_STR
7448 BGP_STR
7449 BGP_INSTANCE_HELP_STR
7450 "Address Family\n"
7451 BGP_SAFI_HELP_STR
7452 "Clear bestpath and re-advertise\n"
7453 "IPv6 prefix\n")
7454 {
7455 int idx_safi = 0;
7456 int idx_vrfview = 0;
7457 int idx_ipv6_prefix = 0;
7458 safi_t safi = SAFI_UNICAST;
7459 char *prefix = argv_find(argv, argc, "X:X::X:X/M", &idx_ipv6_prefix) ?
7460 argv[idx_ipv6_prefix]->arg : NULL;
7461 char *vrfview = NULL;
7462
7463 /* [<view|vrf> VIEWVRFNAME] */
7464 if (argv_find(argv, argc, "vrf", &idx_vrfview)) {
7465 vrfview = argv[idx_vrfview + 1]->arg;
7466 if (vrfview && strmatch(vrfview, VRF_DEFAULT_NAME))
7467 vrfview = NULL;
7468 } else if (argv_find(argv, argc, "view", &idx_vrfview)) {
7469 /* [<view> VIEWVRFNAME] */
7470 vrfview = argv[idx_vrfview + 1]->arg;
7471 }
7472 argv_find_and_parse_safi(argv, argc, &idx_safi, &safi);
7473
7474 return bgp_clear_prefix(
7475 vty, vrfview, prefix,
7476 AFI_IP6, safi, NULL);
7477 }
7478
7479 DEFUN (show_bgp_views,
7480 show_bgp_views_cmd,
7481 "show [ip] bgp views",
7482 SHOW_STR
7483 IP_STR
7484 BGP_STR
7485 "Show the defined BGP views\n")
7486 {
7487 struct list *inst = bm->bgp;
7488 struct listnode *node;
7489 struct bgp *bgp;
7490
7491 if (!bgp_option_check(BGP_OPT_MULTIPLE_INSTANCE)) {
7492 vty_out(vty, "BGP Multiple Instance is not enabled\n");
7493 return CMD_WARNING;
7494 }
7495
7496 vty_out(vty, "Defined BGP views:\n");
7497 for (ALL_LIST_ELEMENTS_RO(inst, node, bgp)) {
7498 /* Skip VRFs. */
7499 if (bgp->inst_type == BGP_INSTANCE_TYPE_VRF)
7500 continue;
7501 vty_out(vty, "\t%s (AS%u)\n", bgp->name ? bgp->name : "(null)",
7502 bgp->as);
7503 }
7504
7505 return CMD_SUCCESS;
7506 }
7507
7508 DEFUN (show_bgp_vrfs,
7509 show_bgp_vrfs_cmd,
7510 "show [ip] bgp vrfs [json]",
7511 SHOW_STR
7512 IP_STR
7513 BGP_STR
7514 "Show BGP VRFs\n"
7515 JSON_STR)
7516 {
7517 char buf[ETHER_ADDR_STRLEN];
7518 struct list *inst = bm->bgp;
7519 struct listnode *node;
7520 struct bgp *bgp;
7521 bool uj = use_json(argc, argv);
7522 json_object *json = NULL;
7523 json_object *json_vrfs = NULL;
7524 int count = 0;
7525
7526 if (!bgp_option_check(BGP_OPT_MULTIPLE_INSTANCE)) {
7527 vty_out(vty, "BGP Multiple Instance is not enabled\n");
7528 return CMD_WARNING;
7529 }
7530
7531 if (uj) {
7532 json = json_object_new_object();
7533 json_vrfs = json_object_new_object();
7534 }
7535
7536 for (ALL_LIST_ELEMENTS_RO(inst, node, bgp)) {
7537 const char *name, *type;
7538 struct peer *peer;
7539 struct listnode *node2, *nnode2;
7540 int peers_cfg, peers_estb;
7541 json_object *json_vrf = NULL;
7542
7543 /* Skip Views. */
7544 if (bgp->inst_type == BGP_INSTANCE_TYPE_VIEW)
7545 continue;
7546
7547 count++;
7548 if (!uj && count == 1)
7549 vty_out(vty,
7550 "%4s %-5s %-16s %9s %10s %-37s %-10s %-15s\n",
7551 "Type", "Id", "routerId", "#PeersVfg",
7552 "#PeersEstb", "Name", "L3-VNI", "Rmac");
7553
7554 peers_cfg = peers_estb = 0;
7555 if (uj)
7556 json_vrf = json_object_new_object();
7557
7558
7559 for (ALL_LIST_ELEMENTS(bgp->peer, node2, nnode2, peer)) {
7560 if (!CHECK_FLAG(peer->flags, PEER_FLAG_CONFIG_NODE))
7561 continue;
7562 peers_cfg++;
7563 if (peer->status == Established)
7564 peers_estb++;
7565 }
7566
7567 if (bgp->inst_type == BGP_INSTANCE_TYPE_DEFAULT) {
7568 name = VRF_DEFAULT_NAME;
7569 type = "DFLT";
7570 } else {
7571 name = bgp->name;
7572 type = "VRF";
7573 }
7574
7575
7576 if (uj) {
7577 int64_t vrf_id_ui = (bgp->vrf_id == VRF_UNKNOWN)
7578 ? -1
7579 : (int64_t)bgp->vrf_id;
7580 json_object_string_add(json_vrf, "type", type);
7581 json_object_int_add(json_vrf, "vrfId", vrf_id_ui);
7582 json_object_string_add(json_vrf, "routerId",
7583 inet_ntoa(bgp->router_id));
7584 json_object_int_add(json_vrf, "numConfiguredPeers",
7585 peers_cfg);
7586 json_object_int_add(json_vrf, "numEstablishedPeers",
7587 peers_estb);
7588
7589 json_object_int_add(json_vrf, "l3vni", bgp->l3vni);
7590 json_object_string_add(
7591 json_vrf, "rmac",
7592 prefix_mac2str(&bgp->rmac, buf, sizeof(buf)));
7593 json_object_object_add(json_vrfs, name, json_vrf);
7594 } else
7595 vty_out(vty,
7596 "%4s %-5d %-16s %9u %10u %-37s %-10u %-15s\n",
7597 type,
7598 bgp->vrf_id == VRF_UNKNOWN ? -1
7599 : (int)bgp->vrf_id,
7600 inet_ntoa(bgp->router_id), peers_cfg,
7601 peers_estb, name, bgp->l3vni,
7602 prefix_mac2str(&bgp->rmac, buf, sizeof(buf)));
7603 }
7604
7605 if (uj) {
7606 json_object_object_add(json, "vrfs", json_vrfs);
7607
7608 json_object_int_add(json, "totalVrfs", count);
7609
7610 vty_out(vty, "%s\n", json_object_to_json_string_ext(
7611 json, JSON_C_TO_STRING_PRETTY));
7612 json_object_free(json);
7613 } else {
7614 if (count)
7615 vty_out(vty,
7616 "\nTotal number of VRFs (including default): %d\n",
7617 count);
7618 }
7619
7620 return CMD_SUCCESS;
7621 }
7622
7623 DEFUN (show_bgp_mac_hash,
7624 show_bgp_mac_hash_cmd,
7625 "show bgp mac hash",
7626 SHOW_STR
7627 BGP_STR
7628 "Mac Address\n"
7629 "Mac Address database\n")
7630 {
7631 bgp_mac_dump_table(vty);
7632
7633 return CMD_SUCCESS;
7634 }
7635
7636 static void show_tip_entry(struct hash_bucket *bucket, void *args)
7637 {
7638 struct vty *vty = (struct vty *)args;
7639 struct tip_addr *tip = (struct tip_addr *)bucket->data;
7640
7641 vty_out(vty, "addr: %s, count: %d\n", inet_ntoa(tip->addr),
7642 tip->refcnt);
7643 }
7644
7645 static void bgp_show_martian_nexthops(struct vty *vty, struct bgp *bgp)
7646 {
7647 vty_out(vty, "self nexthop database:\n");
7648 bgp_nexthop_show_address_hash(vty, bgp);
7649
7650 vty_out(vty, "Tunnel-ip database:\n");
7651 hash_iterate(bgp->tip_hash,
7652 (void (*)(struct hash_bucket *, void *))show_tip_entry,
7653 vty);
7654 }
7655
7656 DEFUN(show_bgp_martian_nexthop_db, show_bgp_martian_nexthop_db_cmd,
7657 "show bgp [<view|vrf> VIEWVRFNAME] martian next-hop",
7658 SHOW_STR BGP_STR BGP_INSTANCE_HELP_STR
7659 "martian next-hops\n"
7660 "martian next-hop database\n")
7661 {
7662 struct bgp *bgp = NULL;
7663 int idx = 0;
7664 char *name = NULL;
7665
7666 /* [<vrf> VIEWVRFNAME] */
7667 if (argv_find(argv, argc, "vrf", &idx)) {
7668 name = argv[idx + 1]->arg;
7669 if (name && strmatch(name, VRF_DEFAULT_NAME))
7670 name = NULL;
7671 } else if (argv_find(argv, argc, "view", &idx))
7672 /* [<view> VIEWVRFNAME] */
7673 name = argv[idx + 1]->arg;
7674 if (name)
7675 bgp = bgp_lookup_by_name(name);
7676 else
7677 bgp = bgp_get_default();
7678
7679 if (!bgp) {
7680 vty_out(vty, "%% No BGP process is configured\n");
7681 return CMD_WARNING;
7682 }
7683 bgp_show_martian_nexthops(vty, bgp);
7684
7685 return CMD_SUCCESS;
7686 }
7687
7688 DEFUN (show_bgp_memory,
7689 show_bgp_memory_cmd,
7690 "show [ip] bgp memory",
7691 SHOW_STR
7692 IP_STR
7693 BGP_STR
7694 "Global BGP memory statistics\n")
7695 {
7696 char memstrbuf[MTYPE_MEMSTR_LEN];
7697 unsigned long count;
7698
7699 /* RIB related usage stats */
7700 count = mtype_stats_alloc(MTYPE_BGP_NODE);
7701 vty_out(vty, "%ld RIB nodes, using %s of memory\n", count,
7702 mtype_memstr(memstrbuf, sizeof(memstrbuf),
7703 count * sizeof(struct bgp_node)));
7704
7705 count = mtype_stats_alloc(MTYPE_BGP_ROUTE);
7706 vty_out(vty, "%ld BGP routes, using %s of memory\n", count,
7707 mtype_memstr(memstrbuf, sizeof(memstrbuf),
7708 count * sizeof(struct bgp_path_info)));
7709 if ((count = mtype_stats_alloc(MTYPE_BGP_ROUTE_EXTRA)))
7710 vty_out(vty, "%ld BGP route ancillaries, using %s of memory\n",
7711 count,
7712 mtype_memstr(
7713 memstrbuf, sizeof(memstrbuf),
7714 count * sizeof(struct bgp_path_info_extra)));
7715
7716 if ((count = mtype_stats_alloc(MTYPE_BGP_STATIC)))
7717 vty_out(vty, "%ld Static routes, using %s of memory\n", count,
7718 mtype_memstr(memstrbuf, sizeof(memstrbuf),
7719 count * sizeof(struct bgp_static)));
7720
7721 if ((count = mtype_stats_alloc(MTYPE_BGP_PACKET)))
7722 vty_out(vty, "%ld Packets, using %s of memory\n", count,
7723 mtype_memstr(memstrbuf, sizeof(memstrbuf),
7724 count * sizeof(struct bpacket)));
7725
7726 /* Adj-In/Out */
7727 if ((count = mtype_stats_alloc(MTYPE_BGP_ADJ_IN)))
7728 vty_out(vty, "%ld Adj-In entries, using %s of memory\n", count,
7729 mtype_memstr(memstrbuf, sizeof(memstrbuf),
7730 count * sizeof(struct bgp_adj_in)));
7731 if ((count = mtype_stats_alloc(MTYPE_BGP_ADJ_OUT)))
7732 vty_out(vty, "%ld Adj-Out entries, using %s of memory\n", count,
7733 mtype_memstr(memstrbuf, sizeof(memstrbuf),
7734 count * sizeof(struct bgp_adj_out)));
7735
7736 if ((count = mtype_stats_alloc(MTYPE_BGP_NEXTHOP_CACHE)))
7737 vty_out(vty, "%ld Nexthop cache entries, using %s of memory\n",
7738 count,
7739 mtype_memstr(memstrbuf, sizeof(memstrbuf),
7740 count * sizeof(struct bgp_nexthop_cache)));
7741
7742 if ((count = mtype_stats_alloc(MTYPE_BGP_DAMP_INFO)))
7743 vty_out(vty, "%ld Dampening entries, using %s of memory\n",
7744 count,
7745 mtype_memstr(memstrbuf, sizeof(memstrbuf),
7746 count * sizeof(struct bgp_damp_info)));
7747
7748 /* Attributes */
7749 count = attr_count();
7750 vty_out(vty, "%ld BGP attributes, using %s of memory\n", count,
7751 mtype_memstr(memstrbuf, sizeof(memstrbuf),
7752 count * sizeof(struct attr)));
7753
7754 if ((count = attr_unknown_count()))
7755 vty_out(vty, "%ld unknown attributes\n", count);
7756
7757 /* AS_PATH attributes */
7758 count = aspath_count();
7759 vty_out(vty, "%ld BGP AS-PATH entries, using %s of memory\n", count,
7760 mtype_memstr(memstrbuf, sizeof(memstrbuf),
7761 count * sizeof(struct aspath)));
7762
7763 count = mtype_stats_alloc(MTYPE_AS_SEG);
7764 vty_out(vty, "%ld BGP AS-PATH segments, using %s of memory\n", count,
7765 mtype_memstr(memstrbuf, sizeof(memstrbuf),
7766 count * sizeof(struct assegment)));
7767
7768 /* Other attributes */
7769 if ((count = community_count()))
7770 vty_out(vty, "%ld BGP community entries, using %s of memory\n",
7771 count, mtype_memstr(memstrbuf, sizeof(memstrbuf),
7772 count * sizeof(struct community)));
7773 if ((count = mtype_stats_alloc(MTYPE_ECOMMUNITY)))
7774 vty_out(vty, "%ld BGP community entries, using %s of memory\n",
7775 count, mtype_memstr(memstrbuf, sizeof(memstrbuf),
7776 count * sizeof(struct ecommunity)));
7777 if ((count = mtype_stats_alloc(MTYPE_LCOMMUNITY)))
7778 vty_out(vty,
7779 "%ld BGP large-community entries, using %s of memory\n",
7780 count, mtype_memstr(memstrbuf, sizeof(memstrbuf),
7781 count * sizeof(struct lcommunity)));
7782
7783 if ((count = mtype_stats_alloc(MTYPE_CLUSTER)))
7784 vty_out(vty, "%ld Cluster lists, using %s of memory\n", count,
7785 mtype_memstr(memstrbuf, sizeof(memstrbuf),
7786 count * sizeof(struct cluster_list)));
7787
7788 /* Peer related usage */
7789 count = mtype_stats_alloc(MTYPE_BGP_PEER);
7790 vty_out(vty, "%ld peers, using %s of memory\n", count,
7791 mtype_memstr(memstrbuf, sizeof(memstrbuf),
7792 count * sizeof(struct peer)));
7793
7794 if ((count = mtype_stats_alloc(MTYPE_PEER_GROUP)))
7795 vty_out(vty, "%ld peer groups, using %s of memory\n", count,
7796 mtype_memstr(memstrbuf, sizeof(memstrbuf),
7797 count * sizeof(struct peer_group)));
7798
7799 /* Other */
7800 if ((count = mtype_stats_alloc(MTYPE_HASH)))
7801 vty_out(vty, "%ld hash tables, using %s of memory\n", count,
7802 mtype_memstr(memstrbuf, sizeof(memstrbuf),
7803 count * sizeof(struct hash)));
7804 if ((count = mtype_stats_alloc(MTYPE_HASH_BACKET)))
7805 vty_out(vty, "%ld hash buckets, using %s of memory\n", count,
7806 mtype_memstr(memstrbuf, sizeof(memstrbuf),
7807 count * sizeof(struct hash_bucket)));
7808 if ((count = mtype_stats_alloc(MTYPE_BGP_REGEXP)))
7809 vty_out(vty, "%ld compiled regexes, using %s of memory\n",
7810 count, mtype_memstr(memstrbuf, sizeof(memstrbuf),
7811 count * sizeof(regex_t)));
7812 return CMD_SUCCESS;
7813 }
7814
7815 static void bgp_show_bestpath_json(struct bgp *bgp, json_object *json)
7816 {
7817 json_object *bestpath = json_object_new_object();
7818
7819 if (bgp_flag_check(bgp, BGP_FLAG_ASPATH_IGNORE))
7820 json_object_string_add(bestpath, "asPath", "ignore");
7821
7822 if (bgp_flag_check(bgp, BGP_FLAG_ASPATH_CONFED))
7823 json_object_string_add(bestpath, "asPath", "confed");
7824
7825 if (bgp_flag_check(bgp, BGP_FLAG_ASPATH_MULTIPATH_RELAX)) {
7826 if (bgp_flag_check(bgp, BGP_FLAG_MULTIPATH_RELAX_AS_SET))
7827 json_object_string_add(bestpath, "multiPathRelax",
7828 "as-set");
7829 else
7830 json_object_string_add(bestpath, "multiPathRelax",
7831 "true");
7832 } else
7833 json_object_string_add(bestpath, "multiPathRelax", "false");
7834
7835 if (bgp_flag_check(bgp, BGP_FLAG_COMPARE_ROUTER_ID))
7836 json_object_string_add(bestpath, "compareRouterId", "true");
7837 if (bgp_flag_check(bgp, BGP_FLAG_MED_CONFED)
7838 || bgp_flag_check(bgp, BGP_FLAG_MED_MISSING_AS_WORST)) {
7839 if (bgp_flag_check(bgp, BGP_FLAG_MED_CONFED))
7840 json_object_string_add(bestpath, "med", "confed");
7841 if (bgp_flag_check(bgp, BGP_FLAG_MED_MISSING_AS_WORST))
7842 json_object_string_add(bestpath, "med",
7843 "missing-as-worst");
7844 else
7845 json_object_string_add(bestpath, "med", "true");
7846 }
7847
7848 json_object_object_add(json, "bestPath", bestpath);
7849 }
7850
7851 /* Show BGP peer's summary information. */
7852 static int bgp_show_summary(struct vty *vty, struct bgp *bgp, int afi, int safi,
7853 bool use_json, json_object *json)
7854 {
7855 struct peer *peer;
7856 struct listnode *node, *nnode;
7857 unsigned int count = 0, dn_count = 0;
7858 char timebuf[BGP_UPTIME_LEN], dn_flag[2];
7859 char neighbor_buf[VTY_BUFSIZ];
7860 int neighbor_col_default_width = 16;
7861 int len;
7862 int max_neighbor_width = 0;
7863 int pfx_rcd_safi;
7864 json_object *json_peer = NULL;
7865 json_object *json_peers = NULL;
7866 struct peer_af *paf;
7867
7868 /* labeled-unicast routes are installed in the unicast table so in order
7869 * to
7870 * display the correct PfxRcd value we must look at SAFI_UNICAST
7871 */
7872 if (safi == SAFI_LABELED_UNICAST)
7873 pfx_rcd_safi = SAFI_UNICAST;
7874 else
7875 pfx_rcd_safi = safi;
7876
7877 if (use_json) {
7878 if (json == NULL)
7879 json = json_object_new_object();
7880
7881 json_peers = json_object_new_object();
7882 } else {
7883 /* Loop over all neighbors that will be displayed to determine
7884 * how many
7885 * characters are needed for the Neighbor column
7886 */
7887 for (ALL_LIST_ELEMENTS(bgp->peer, node, nnode, peer)) {
7888 if (!CHECK_FLAG(peer->flags, PEER_FLAG_CONFIG_NODE))
7889 continue;
7890
7891 if (peer->afc[afi][safi]) {
7892 memset(dn_flag, '\0', sizeof(dn_flag));
7893 if (peer_dynamic_neighbor(peer))
7894 dn_flag[0] = '*';
7895
7896 if (peer->hostname
7897 && bgp_flag_check(bgp,
7898 BGP_FLAG_SHOW_HOSTNAME))
7899 sprintf(neighbor_buf, "%s%s(%s) ",
7900 dn_flag, peer->hostname,
7901 peer->host);
7902 else
7903 sprintf(neighbor_buf, "%s%s ", dn_flag,
7904 peer->host);
7905
7906 len = strlen(neighbor_buf);
7907
7908 if (len > max_neighbor_width)
7909 max_neighbor_width = len;
7910 }
7911 }
7912
7913 /* Originally we displayed the Neighbor column as 16
7914 * characters wide so make that the default
7915 */
7916 if (max_neighbor_width < neighbor_col_default_width)
7917 max_neighbor_width = neighbor_col_default_width;
7918 }
7919
7920 for (ALL_LIST_ELEMENTS(bgp->peer, node, nnode, peer)) {
7921 if (!CHECK_FLAG(peer->flags, PEER_FLAG_CONFIG_NODE))
7922 continue;
7923
7924 if (!peer->afc[afi][safi])
7925 continue;
7926
7927 if (!count) {
7928 unsigned long ents;
7929 char memstrbuf[MTYPE_MEMSTR_LEN];
7930 int64_t vrf_id_ui;
7931
7932 vrf_id_ui = (bgp->vrf_id == VRF_UNKNOWN)
7933 ? -1
7934 : (int64_t)bgp->vrf_id;
7935
7936 /* Usage summary and header */
7937 if (use_json) {
7938 json_object_string_add(
7939 json, "routerId",
7940 inet_ntoa(bgp->router_id));
7941 json_object_int_add(json, "as", bgp->as);
7942 json_object_int_add(json, "vrfId", vrf_id_ui);
7943 json_object_string_add(
7944 json, "vrfName",
7945 (bgp->inst_type
7946 == BGP_INSTANCE_TYPE_DEFAULT)
7947 ? VRF_DEFAULT_NAME
7948 : bgp->name);
7949 } else {
7950 vty_out(vty,
7951 "BGP router identifier %s, local AS number %u vrf-id %d",
7952 inet_ntoa(bgp->router_id), bgp->as,
7953 bgp->vrf_id == VRF_UNKNOWN
7954 ? -1
7955 : (int)bgp->vrf_id);
7956 vty_out(vty, "\n");
7957 }
7958
7959 if (bgp_update_delay_configured(bgp)) {
7960 if (use_json) {
7961 json_object_int_add(
7962 json, "updateDelayLimit",
7963 bgp->v_update_delay);
7964
7965 if (bgp->v_update_delay
7966 != bgp->v_establish_wait)
7967 json_object_int_add(
7968 json,
7969 "updateDelayEstablishWait",
7970 bgp->v_establish_wait);
7971
7972 if (bgp_update_delay_active(bgp)) {
7973 json_object_string_add(
7974 json,
7975 "updateDelayFirstNeighbor",
7976 bgp->update_delay_begin_time);
7977 json_object_boolean_true_add(
7978 json,
7979 "updateDelayInProgress");
7980 } else {
7981 if (bgp->update_delay_over) {
7982 json_object_string_add(
7983 json,
7984 "updateDelayFirstNeighbor",
7985 bgp->update_delay_begin_time);
7986 json_object_string_add(
7987 json,
7988 "updateDelayBestpathResumed",
7989 bgp->update_delay_end_time);
7990 json_object_string_add(
7991 json,
7992 "updateDelayZebraUpdateResume",
7993 bgp->update_delay_zebra_resume_time);
7994 json_object_string_add(
7995 json,
7996 "updateDelayPeerUpdateResume",
7997 bgp->update_delay_peers_resume_time);
7998 }
7999 }
8000 } else {
8001 vty_out(vty,
8002 "Read-only mode update-delay limit: %d seconds\n",
8003 bgp->v_update_delay);
8004 if (bgp->v_update_delay
8005 != bgp->v_establish_wait)
8006 vty_out(vty,
8007 " Establish wait: %d seconds\n",
8008 bgp->v_establish_wait);
8009
8010 if (bgp_update_delay_active(bgp)) {
8011 vty_out(vty,
8012 " First neighbor established: %s\n",
8013 bgp->update_delay_begin_time);
8014 vty_out(vty,
8015 " Delay in progress\n");
8016 } else {
8017 if (bgp->update_delay_over) {
8018 vty_out(vty,
8019 " First neighbor established: %s\n",
8020 bgp->update_delay_begin_time);
8021 vty_out(vty,
8022 " Best-paths resumed: %s\n",
8023 bgp->update_delay_end_time);
8024 vty_out(vty,
8025 " zebra update resumed: %s\n",
8026 bgp->update_delay_zebra_resume_time);
8027 vty_out(vty,
8028 " peers update resumed: %s\n",
8029 bgp->update_delay_peers_resume_time);
8030 }
8031 }
8032 }
8033 }
8034
8035 if (use_json) {
8036 if (bgp_maxmed_onstartup_configured(bgp)
8037 && bgp->maxmed_active)
8038 json_object_boolean_true_add(
8039 json, "maxMedOnStartup");
8040 if (bgp->v_maxmed_admin)
8041 json_object_boolean_true_add(
8042 json, "maxMedAdministrative");
8043
8044 json_object_int_add(
8045 json, "tableVersion",
8046 bgp_table_version(bgp->rib[afi][safi]));
8047
8048 ents = bgp_table_count(bgp->rib[afi][safi]);
8049 json_object_int_add(json, "ribCount", ents);
8050 json_object_int_add(
8051 json, "ribMemory",
8052 ents * sizeof(struct bgp_node));
8053
8054 ents = bgp->af_peer_count[afi][safi];
8055 json_object_int_add(json, "peerCount", ents);
8056 json_object_int_add(json, "peerMemory",
8057 ents * sizeof(struct peer));
8058
8059 if ((ents = listcount(bgp->group))) {
8060 json_object_int_add(
8061 json, "peerGroupCount", ents);
8062 json_object_int_add(
8063 json, "peerGroupMemory",
8064 ents * sizeof(struct
8065 peer_group));
8066 }
8067
8068 if (CHECK_FLAG(bgp->af_flags[afi][safi],
8069 BGP_CONFIG_DAMPENING))
8070 json_object_boolean_true_add(
8071 json, "dampeningEnabled");
8072 } else {
8073 if (bgp_maxmed_onstartup_configured(bgp)
8074 && bgp->maxmed_active)
8075 vty_out(vty,
8076 "Max-med on-startup active\n");
8077 if (bgp->v_maxmed_admin)
8078 vty_out(vty,
8079 "Max-med administrative active\n");
8080
8081 vty_out(vty, "BGP table version %" PRIu64 "\n",
8082 bgp_table_version(bgp->rib[afi][safi]));
8083
8084 ents = bgp_table_count(bgp->rib[afi][safi]);
8085 vty_out(vty,
8086 "RIB entries %ld, using %s of memory\n",
8087 ents,
8088 mtype_memstr(memstrbuf,
8089 sizeof(memstrbuf),
8090 ents * sizeof(struct
8091 bgp_node)));
8092
8093 /* Peer related usage */
8094 ents = bgp->af_peer_count[afi][safi];
8095 vty_out(vty, "Peers %ld, using %s of memory\n",
8096 ents,
8097 mtype_memstr(
8098 memstrbuf, sizeof(memstrbuf),
8099 ents * sizeof(struct peer)));
8100
8101 if ((ents = listcount(bgp->group)))
8102 vty_out(vty,
8103 "Peer groups %ld, using %s of memory\n",
8104 ents,
8105 mtype_memstr(
8106 memstrbuf,
8107 sizeof(memstrbuf),
8108 ents * sizeof(struct
8109 peer_group)));
8110
8111 if (CHECK_FLAG(bgp->af_flags[afi][safi],
8112 BGP_CONFIG_DAMPENING))
8113 vty_out(vty, "Dampening enabled.\n");
8114 vty_out(vty, "\n");
8115
8116 /* Subtract 8 here because 'Neighbor' is
8117 * 8 characters */
8118 vty_out(vty, "Neighbor");
8119 vty_out(vty, "%*s", max_neighbor_width - 8,
8120 " ");
8121 vty_out(vty,
8122 "V AS MsgRcvd MsgSent TblVer InQ OutQ Up/Down State/PfxRcd\n");
8123 }
8124 }
8125
8126 count++;
8127
8128 if (use_json) {
8129 json_peer = json_object_new_object();
8130
8131 if (peer_dynamic_neighbor(peer)) {
8132 dn_count++;
8133 json_object_boolean_true_add(json_peer,
8134 "dynamicPeer");
8135 }
8136
8137 if (peer->hostname)
8138 json_object_string_add(json_peer, "hostname",
8139 peer->hostname);
8140
8141 if (peer->domainname)
8142 json_object_string_add(json_peer, "domainname",
8143 peer->domainname);
8144
8145 json_object_int_add(json_peer, "remoteAs", peer->as);
8146 json_object_int_add(json_peer, "version", 4);
8147 json_object_int_add(json_peer, "msgRcvd",
8148 PEER_TOTAL_RX(peer));
8149 json_object_int_add(json_peer, "msgSent",
8150 PEER_TOTAL_TX(peer));
8151
8152 json_object_int_add(json_peer, "tableVersion",
8153 peer->version[afi][safi]);
8154 json_object_int_add(json_peer, "outq",
8155 peer->obuf->count);
8156 json_object_int_add(json_peer, "inq", 0);
8157 peer_uptime(peer->uptime, timebuf, BGP_UPTIME_LEN,
8158 use_json, json_peer);
8159
8160 /*
8161 * Adding "pfxRcd" field to match with the corresponding
8162 * CLI. "prefixReceivedCount" will be deprecated in
8163 * future.
8164 */
8165 json_object_int_add(json_peer, "prefixReceivedCount",
8166 peer->pcount[afi][pfx_rcd_safi]);
8167 json_object_int_add(json_peer, "pfxRcd",
8168 peer->pcount[afi][pfx_rcd_safi]);
8169
8170 paf = peer_af_find(peer, afi, pfx_rcd_safi);
8171 if (paf && PAF_SUBGRP(paf))
8172 json_object_int_add(json_peer,
8173 "pfxSnt",
8174 (PAF_SUBGRP(paf))->scount);
8175
8176 if (CHECK_FLAG(peer->flags, PEER_FLAG_SHUTDOWN))
8177 json_object_string_add(json_peer, "state",
8178 "Idle (Admin)");
8179 else if (peer->afc_recv[afi][safi])
8180 json_object_string_add(
8181 json_peer, "state",
8182 lookup_msg(bgp_status_msg, peer->status,
8183 NULL));
8184 else if (CHECK_FLAG(peer->sflags,
8185 PEER_STATUS_PREFIX_OVERFLOW))
8186 json_object_string_add(json_peer, "state",
8187 "Idle (PfxCt)");
8188 else
8189 json_object_string_add(
8190 json_peer, "state",
8191 lookup_msg(bgp_status_msg, peer->status,
8192 NULL));
8193
8194 if (peer->conf_if)
8195 json_object_string_add(json_peer, "idType",
8196 "interface");
8197 else if (peer->su.sa.sa_family == AF_INET)
8198 json_object_string_add(json_peer, "idType",
8199 "ipv4");
8200 else if (peer->su.sa.sa_family == AF_INET6)
8201 json_object_string_add(json_peer, "idType",
8202 "ipv6");
8203
8204 json_object_object_add(json_peers, peer->host,
8205 json_peer);
8206 } else {
8207 memset(dn_flag, '\0', sizeof(dn_flag));
8208 if (peer_dynamic_neighbor(peer)) {
8209 dn_count++;
8210 dn_flag[0] = '*';
8211 }
8212
8213 if (peer->hostname
8214 && bgp_flag_check(bgp, BGP_FLAG_SHOW_HOSTNAME))
8215 len = vty_out(vty, "%s%s(%s)", dn_flag,
8216 peer->hostname, peer->host);
8217 else
8218 len = vty_out(vty, "%s%s", dn_flag, peer->host);
8219
8220 /* pad the neighbor column with spaces */
8221 if (len < max_neighbor_width)
8222 vty_out(vty, "%*s", max_neighbor_width - len,
8223 " ");
8224
8225 vty_out(vty, "4 %10u %7u %7u %8" PRIu64 " %4d %4zd %8s",
8226 peer->as, PEER_TOTAL_RX(peer),
8227 PEER_TOTAL_TX(peer), peer->version[afi][safi],
8228 0, peer->obuf->count,
8229 peer_uptime(peer->uptime, timebuf,
8230 BGP_UPTIME_LEN, 0, NULL));
8231
8232 if (peer->status == Established)
8233 if (peer->afc_recv[afi][safi])
8234 vty_out(vty, " %12ld",
8235 peer->pcount[afi]
8236 [pfx_rcd_safi]);
8237 else
8238 vty_out(vty, " NoNeg");
8239 else {
8240 if (CHECK_FLAG(peer->flags, PEER_FLAG_SHUTDOWN))
8241 vty_out(vty, " Idle (Admin)");
8242 else if (CHECK_FLAG(
8243 peer->sflags,
8244 PEER_STATUS_PREFIX_OVERFLOW))
8245 vty_out(vty, " Idle (PfxCt)");
8246 else
8247 vty_out(vty, " %12s",
8248 lookup_msg(bgp_status_msg,
8249 peer->status, NULL));
8250 }
8251 vty_out(vty, "\n");
8252 }
8253 }
8254
8255 if (use_json) {
8256 json_object_object_add(json, "peers", json_peers);
8257
8258 json_object_int_add(json, "totalPeers", count);
8259 json_object_int_add(json, "dynamicPeers", dn_count);
8260
8261 bgp_show_bestpath_json(bgp, json);
8262
8263 vty_out(vty, "%s\n", json_object_to_json_string_ext(
8264 json, JSON_C_TO_STRING_PRETTY));
8265 json_object_free(json);
8266 } else {
8267 if (count)
8268 vty_out(vty, "\nTotal number of neighbors %d\n", count);
8269 else {
8270 vty_out(vty, "No %s neighbor is configured\n",
8271 afi_safi_print(afi, safi));
8272 }
8273
8274 if (dn_count) {
8275 vty_out(vty, "* - dynamic neighbor\n");
8276 vty_out(vty, "%d dynamic neighbor(s), limit %d\n",
8277 dn_count, bgp->dynamic_neighbors_limit);
8278 }
8279 }
8280
8281 return CMD_SUCCESS;
8282 }
8283
8284 static void bgp_show_summary_afi_safi(struct vty *vty, struct bgp *bgp, int afi,
8285 int safi, bool use_json,
8286 json_object *json)
8287 {
8288 int is_first = 1;
8289 int afi_wildcard = (afi == AFI_MAX);
8290 int safi_wildcard = (safi == SAFI_MAX);
8291 int is_wildcard = (afi_wildcard || safi_wildcard);
8292 bool nbr_output = false;
8293
8294 if (use_json && is_wildcard)
8295 vty_out(vty, "{\n");
8296 if (afi_wildcard)
8297 afi = 1; /* AFI_IP */
8298 while (afi < AFI_MAX) {
8299 if (safi_wildcard)
8300 safi = 1; /* SAFI_UNICAST */
8301 while (safi < SAFI_MAX) {
8302 if (bgp_afi_safi_peer_exists(bgp, afi, safi)) {
8303 nbr_output = true;
8304 if (is_wildcard) {
8305 /*
8306 * So limit output to those afi/safi
8307 * pairs that
8308 * actualy have something interesting in
8309 * them
8310 */
8311 if (use_json) {
8312 json = json_object_new_object();
8313
8314 if (!is_first)
8315 vty_out(vty, ",\n");
8316 else
8317 is_first = 0;
8318
8319 vty_out(vty, "\"%s\":",
8320 afi_safi_json(afi,
8321 safi));
8322 } else {
8323 vty_out(vty, "\n%s Summary:\n",
8324 afi_safi_print(afi,
8325 safi));
8326 }
8327 }
8328 bgp_show_summary(vty, bgp, afi, safi, use_json,
8329 json);
8330 }
8331 safi++;
8332 if (!safi_wildcard)
8333 safi = SAFI_MAX;
8334 }
8335 afi++;
8336 if (!afi_wildcard)
8337 afi = AFI_MAX;
8338 }
8339
8340 if (use_json && is_wildcard)
8341 vty_out(vty, "}\n");
8342 else if (!nbr_output) {
8343 if (use_json)
8344 vty_out(vty, "{}\n");
8345 else
8346 vty_out(vty, "%% No BGP neighbors found\n");
8347 }
8348 }
8349
8350 static void bgp_show_all_instances_summary_vty(struct vty *vty, afi_t afi,
8351 safi_t safi, bool use_json)
8352 {
8353 struct listnode *node, *nnode;
8354 struct bgp *bgp;
8355 json_object *json = NULL;
8356 int is_first = 1;
8357 bool nbr_output = false;
8358
8359 if (use_json)
8360 vty_out(vty, "{\n");
8361
8362 for (ALL_LIST_ELEMENTS(bm->bgp, node, nnode, bgp)) {
8363 nbr_output = true;
8364 if (use_json) {
8365 json = json_object_new_object();
8366
8367 if (!is_first)
8368 vty_out(vty, ",\n");
8369 else
8370 is_first = 0;
8371
8372 vty_out(vty, "\"%s\":",
8373 (bgp->inst_type == BGP_INSTANCE_TYPE_DEFAULT)
8374 ? VRF_DEFAULT_NAME
8375 : bgp->name);
8376 } else {
8377 vty_out(vty, "\nInstance %s:\n",
8378 (bgp->inst_type == BGP_INSTANCE_TYPE_DEFAULT)
8379 ? VRF_DEFAULT_NAME
8380 : bgp->name);
8381 }
8382 bgp_show_summary_afi_safi(vty, bgp, afi, safi, use_json, json);
8383 }
8384
8385 if (use_json)
8386 vty_out(vty, "}\n");
8387 else if (!nbr_output)
8388 vty_out(vty, "%% BGP instance not found\n");
8389 }
8390
8391 int bgp_show_summary_vty(struct vty *vty, const char *name, afi_t afi,
8392 safi_t safi, bool use_json)
8393 {
8394 struct bgp *bgp;
8395
8396 if (name) {
8397 if (strmatch(name, "all")) {
8398 bgp_show_all_instances_summary_vty(vty, afi, safi,
8399 use_json);
8400 return CMD_SUCCESS;
8401 } else {
8402 bgp = bgp_lookup_by_name(name);
8403
8404 if (!bgp) {
8405 if (use_json)
8406 vty_out(vty, "{}\n");
8407 else
8408 vty_out(vty,
8409 "%% BGP instance not found\n");
8410 return CMD_WARNING;
8411 }
8412
8413 bgp_show_summary_afi_safi(vty, bgp, afi, safi, use_json,
8414 NULL);
8415 return CMD_SUCCESS;
8416 }
8417 }
8418
8419 bgp = bgp_get_default();
8420
8421 if (bgp)
8422 bgp_show_summary_afi_safi(vty, bgp, afi, safi, use_json, NULL);
8423 else {
8424 if (use_json)
8425 vty_out(vty, "{}\n");
8426 else
8427 vty_out(vty, "%% BGP instance not found\n");
8428 return CMD_WARNING;
8429 }
8430
8431 return CMD_SUCCESS;
8432 }
8433
8434 /* `show [ip] bgp summary' commands. */
8435 DEFUN (show_ip_bgp_summary,
8436 show_ip_bgp_summary_cmd,
8437 "show [ip] bgp [<view|vrf> VIEWVRFNAME] ["BGP_AFI_CMD_STR" ["BGP_SAFI_WITH_LABEL_CMD_STR"]] summary [json]",
8438 SHOW_STR
8439 IP_STR
8440 BGP_STR
8441 BGP_INSTANCE_HELP_STR
8442 BGP_AFI_HELP_STR
8443 BGP_SAFI_WITH_LABEL_HELP_STR
8444 "Summary of BGP neighbor status\n"
8445 JSON_STR)
8446 {
8447 char *vrf = NULL;
8448 afi_t afi = AFI_MAX;
8449 safi_t safi = SAFI_MAX;
8450
8451 int idx = 0;
8452
8453 /* show [ip] bgp */
8454 if (argv_find(argv, argc, "ip", &idx))
8455 afi = AFI_IP;
8456 /* [<vrf> VIEWVRFNAME] */
8457 if (argv_find(argv, argc, "vrf", &idx)) {
8458 vrf = argv[idx + 1]->arg;
8459 if (vrf && strmatch(vrf, VRF_DEFAULT_NAME))
8460 vrf = NULL;
8461 } else if (argv_find(argv, argc, "view", &idx))
8462 /* [<view> VIEWVRFNAME] */
8463 vrf = argv[idx + 1]->arg;
8464 /* ["BGP_AFI_CMD_STR" ["BGP_SAFI_CMD_STR"]] */
8465 if (argv_find_and_parse_afi(argv, argc, &idx, &afi)) {
8466 argv_find_and_parse_safi(argv, argc, &idx, &safi);
8467 }
8468
8469 bool uj = use_json(argc, argv);
8470
8471 return bgp_show_summary_vty(vty, vrf, afi, safi, uj);
8472 }
8473
8474 const char *afi_safi_print(afi_t afi, safi_t safi)
8475 {
8476 if (afi == AFI_IP && safi == SAFI_UNICAST)
8477 return "IPv4 Unicast";
8478 else if (afi == AFI_IP && safi == SAFI_MULTICAST)
8479 return "IPv4 Multicast";
8480 else if (afi == AFI_IP && safi == SAFI_LABELED_UNICAST)
8481 return "IPv4 Labeled Unicast";
8482 else if (afi == AFI_IP && safi == SAFI_MPLS_VPN)
8483 return "IPv4 VPN";
8484 else if (afi == AFI_IP && safi == SAFI_ENCAP)
8485 return "IPv4 Encap";
8486 else if (afi == AFI_IP && safi == SAFI_FLOWSPEC)
8487 return "IPv4 Flowspec";
8488 else if (afi == AFI_IP6 && safi == SAFI_UNICAST)
8489 return "IPv6 Unicast";
8490 else if (afi == AFI_IP6 && safi == SAFI_MULTICAST)
8491 return "IPv6 Multicast";
8492 else if (afi == AFI_IP6 && safi == SAFI_LABELED_UNICAST)
8493 return "IPv6 Labeled Unicast";
8494 else if (afi == AFI_IP6 && safi == SAFI_MPLS_VPN)
8495 return "IPv6 VPN";
8496 else if (afi == AFI_IP6 && safi == SAFI_ENCAP)
8497 return "IPv6 Encap";
8498 else if (afi == AFI_IP6 && safi == SAFI_FLOWSPEC)
8499 return "IPv6 Flowspec";
8500 else if (afi == AFI_L2VPN && safi == SAFI_EVPN)
8501 return "L2VPN EVPN";
8502 else
8503 return "Unknown";
8504 }
8505
8506 /*
8507 * Please note that we have intentionally camelCased
8508 * the return strings here. So if you want
8509 * to use this function, please ensure you
8510 * are doing this within json output
8511 */
8512 const char *afi_safi_json(afi_t afi, safi_t safi)
8513 {
8514 if (afi == AFI_IP && safi == SAFI_UNICAST)
8515 return "ipv4Unicast";
8516 else if (afi == AFI_IP && safi == SAFI_MULTICAST)
8517 return "ipv4Multicast";
8518 else if (afi == AFI_IP && safi == SAFI_LABELED_UNICAST)
8519 return "ipv4LabeledUnicast";
8520 else if (afi == AFI_IP && safi == SAFI_MPLS_VPN)
8521 return "ipv4Vpn";
8522 else if (afi == AFI_IP && safi == SAFI_ENCAP)
8523 return "ipv4Encap";
8524 else if (afi == AFI_IP && safi == SAFI_FLOWSPEC)
8525 return "ipv4Flowspec";
8526 else if (afi == AFI_IP6 && safi == SAFI_UNICAST)
8527 return "ipv6Unicast";
8528 else if (afi == AFI_IP6 && safi == SAFI_MULTICAST)
8529 return "ipv6Multicast";
8530 else if (afi == AFI_IP6 && safi == SAFI_LABELED_UNICAST)
8531 return "ipv6LabeledUnicast";
8532 else if (afi == AFI_IP6 && safi == SAFI_MPLS_VPN)
8533 return "ipv6Vpn";
8534 else if (afi == AFI_IP6 && safi == SAFI_ENCAP)
8535 return "ipv6Encap";
8536 else if (afi == AFI_IP6 && safi == SAFI_FLOWSPEC)
8537 return "ipv6Flowspec";
8538 else if (afi == AFI_L2VPN && safi == SAFI_EVPN)
8539 return "l2VpnEvpn";
8540 else
8541 return "Unknown";
8542 }
8543
8544 /* Show BGP peer's information. */
8545 enum show_type { show_all, show_peer, show_ipv4_all, show_ipv6_all, show_ipv4_peer, show_ipv6_peer };
8546
8547 static void bgp_show_peer_afi_orf_cap(struct vty *vty, struct peer *p,
8548 afi_t afi, safi_t safi,
8549 uint16_t adv_smcap, uint16_t adv_rmcap,
8550 uint16_t rcv_smcap, uint16_t rcv_rmcap,
8551 bool use_json, json_object *json_pref)
8552 {
8553 /* Send-Mode */
8554 if (CHECK_FLAG(p->af_cap[afi][safi], adv_smcap)
8555 || CHECK_FLAG(p->af_cap[afi][safi], rcv_smcap)) {
8556 if (use_json) {
8557 if (CHECK_FLAG(p->af_cap[afi][safi], adv_smcap)
8558 && CHECK_FLAG(p->af_cap[afi][safi], rcv_smcap))
8559 json_object_string_add(json_pref, "sendMode",
8560 "advertisedAndReceived");
8561 else if (CHECK_FLAG(p->af_cap[afi][safi], adv_smcap))
8562 json_object_string_add(json_pref, "sendMode",
8563 "advertised");
8564 else if (CHECK_FLAG(p->af_cap[afi][safi], rcv_smcap))
8565 json_object_string_add(json_pref, "sendMode",
8566 "received");
8567 } else {
8568 vty_out(vty, " Send-mode: ");
8569 if (CHECK_FLAG(p->af_cap[afi][safi], adv_smcap))
8570 vty_out(vty, "advertised");
8571 if (CHECK_FLAG(p->af_cap[afi][safi], rcv_smcap))
8572 vty_out(vty, "%sreceived",
8573 CHECK_FLAG(p->af_cap[afi][safi],
8574 adv_smcap)
8575 ? ", "
8576 : "");
8577 vty_out(vty, "\n");
8578 }
8579 }
8580
8581 /* Receive-Mode */
8582 if (CHECK_FLAG(p->af_cap[afi][safi], adv_rmcap)
8583 || CHECK_FLAG(p->af_cap[afi][safi], rcv_rmcap)) {
8584 if (use_json) {
8585 if (CHECK_FLAG(p->af_cap[afi][safi], adv_rmcap)
8586 && CHECK_FLAG(p->af_cap[afi][safi], rcv_rmcap))
8587 json_object_string_add(json_pref, "recvMode",
8588 "advertisedAndReceived");
8589 else if (CHECK_FLAG(p->af_cap[afi][safi], adv_rmcap))
8590 json_object_string_add(json_pref, "recvMode",
8591 "advertised");
8592 else if (CHECK_FLAG(p->af_cap[afi][safi], rcv_rmcap))
8593 json_object_string_add(json_pref, "recvMode",
8594 "received");
8595 } else {
8596 vty_out(vty, " Receive-mode: ");
8597 if (CHECK_FLAG(p->af_cap[afi][safi], adv_rmcap))
8598 vty_out(vty, "advertised");
8599 if (CHECK_FLAG(p->af_cap[afi][safi], rcv_rmcap))
8600 vty_out(vty, "%sreceived",
8601 CHECK_FLAG(p->af_cap[afi][safi],
8602 adv_rmcap)
8603 ? ", "
8604 : "");
8605 vty_out(vty, "\n");
8606 }
8607 }
8608 }
8609
8610 static void bgp_show_peer_afi(struct vty *vty, struct peer *p, afi_t afi,
8611 safi_t safi, bool use_json,
8612 json_object *json_neigh)
8613 {
8614 struct bgp_filter *filter;
8615 struct peer_af *paf;
8616 char orf_pfx_name[BUFSIZ];
8617 int orf_pfx_count;
8618 json_object *json_af = NULL;
8619 json_object *json_prefA = NULL;
8620 json_object *json_prefB = NULL;
8621 json_object *json_addr = NULL;
8622
8623 if (use_json) {
8624 json_addr = json_object_new_object();
8625 json_af = json_object_new_object();
8626 filter = &p->filter[afi][safi];
8627
8628 if (peer_group_active(p))
8629 json_object_string_add(json_addr, "peerGroupMember",
8630 p->group->name);
8631
8632 paf = peer_af_find(p, afi, safi);
8633 if (paf && PAF_SUBGRP(paf)) {
8634 json_object_int_add(json_addr, "updateGroupId",
8635 PAF_UPDGRP(paf)->id);
8636 json_object_int_add(json_addr, "subGroupId",
8637 PAF_SUBGRP(paf)->id);
8638 json_object_int_add(json_addr, "packetQueueLength",
8639 bpacket_queue_virtual_length(paf));
8640 }
8641
8642 if (CHECK_FLAG(p->af_cap[afi][safi], PEER_CAP_ORF_PREFIX_SM_ADV)
8643 || CHECK_FLAG(p->af_cap[afi][safi],
8644 PEER_CAP_ORF_PREFIX_SM_RCV)
8645 || CHECK_FLAG(p->af_cap[afi][safi],
8646 PEER_CAP_ORF_PREFIX_RM_ADV)
8647 || CHECK_FLAG(p->af_cap[afi][safi],
8648 PEER_CAP_ORF_PREFIX_RM_RCV)) {
8649 json_object_int_add(json_af, "orfType",
8650 ORF_TYPE_PREFIX);
8651 json_prefA = json_object_new_object();
8652 bgp_show_peer_afi_orf_cap(vty, p, afi, safi,
8653 PEER_CAP_ORF_PREFIX_SM_ADV,
8654 PEER_CAP_ORF_PREFIX_RM_ADV,
8655 PEER_CAP_ORF_PREFIX_SM_RCV,
8656 PEER_CAP_ORF_PREFIX_RM_RCV,
8657 use_json, json_prefA);
8658 json_object_object_add(json_af, "orfPrefixList",
8659 json_prefA);
8660 }
8661
8662 if (CHECK_FLAG(p->af_cap[afi][safi], PEER_CAP_ORF_PREFIX_SM_ADV)
8663 || CHECK_FLAG(p->af_cap[afi][safi],
8664 PEER_CAP_ORF_PREFIX_SM_OLD_RCV)
8665 || CHECK_FLAG(p->af_cap[afi][safi],
8666 PEER_CAP_ORF_PREFIX_RM_ADV)
8667 || CHECK_FLAG(p->af_cap[afi][safi],
8668 PEER_CAP_ORF_PREFIX_RM_OLD_RCV)) {
8669 json_object_int_add(json_af, "orfOldType",
8670 ORF_TYPE_PREFIX_OLD);
8671 json_prefB = json_object_new_object();
8672 bgp_show_peer_afi_orf_cap(
8673 vty, p, afi, safi, PEER_CAP_ORF_PREFIX_SM_ADV,
8674 PEER_CAP_ORF_PREFIX_RM_ADV,
8675 PEER_CAP_ORF_PREFIX_SM_OLD_RCV,
8676 PEER_CAP_ORF_PREFIX_RM_OLD_RCV, use_json,
8677 json_prefB);
8678 json_object_object_add(json_af, "orfOldPrefixList",
8679 json_prefB);
8680 }
8681
8682 if (CHECK_FLAG(p->af_cap[afi][safi], PEER_CAP_ORF_PREFIX_SM_ADV)
8683 || CHECK_FLAG(p->af_cap[afi][safi],
8684 PEER_CAP_ORF_PREFIX_SM_RCV)
8685 || CHECK_FLAG(p->af_cap[afi][safi],
8686 PEER_CAP_ORF_PREFIX_SM_OLD_RCV)
8687 || CHECK_FLAG(p->af_cap[afi][safi],
8688 PEER_CAP_ORF_PREFIX_RM_ADV)
8689 || CHECK_FLAG(p->af_cap[afi][safi],
8690 PEER_CAP_ORF_PREFIX_RM_RCV)
8691 || CHECK_FLAG(p->af_cap[afi][safi],
8692 PEER_CAP_ORF_PREFIX_RM_OLD_RCV))
8693 json_object_object_add(json_addr, "afDependentCap",
8694 json_af);
8695 else
8696 json_object_free(json_af);
8697
8698 sprintf(orf_pfx_name, "%s.%d.%d", p->host, afi, safi);
8699 orf_pfx_count = prefix_bgp_show_prefix_list(
8700 NULL, afi, orf_pfx_name, use_json);
8701
8702 if (CHECK_FLAG(p->af_sflags[afi][safi],
8703 PEER_STATUS_ORF_PREFIX_SEND)
8704 || orf_pfx_count) {
8705 if (CHECK_FLAG(p->af_sflags[afi][safi],
8706 PEER_STATUS_ORF_PREFIX_SEND))
8707 json_object_boolean_true_add(json_neigh,
8708 "orfSent");
8709 if (orf_pfx_count)
8710 json_object_int_add(json_addr, "orfRecvCounter",
8711 orf_pfx_count);
8712 }
8713 if (CHECK_FLAG(p->af_sflags[afi][safi],
8714 PEER_STATUS_ORF_WAIT_REFRESH))
8715 json_object_string_add(
8716 json_addr, "orfFirstUpdate",
8717 "deferredUntilORFOrRouteRefreshRecvd");
8718
8719 if (CHECK_FLAG(p->af_flags[afi][safi],
8720 PEER_FLAG_REFLECTOR_CLIENT))
8721 json_object_boolean_true_add(json_addr,
8722 "routeReflectorClient");
8723 if (CHECK_FLAG(p->af_flags[afi][safi],
8724 PEER_FLAG_RSERVER_CLIENT))
8725 json_object_boolean_true_add(json_addr,
8726 "routeServerClient");
8727 if (CHECK_FLAG(p->af_flags[afi][safi], PEER_FLAG_SOFT_RECONFIG))
8728 json_object_boolean_true_add(json_addr,
8729 "inboundSoftConfigPermit");
8730
8731 if (CHECK_FLAG(p->af_flags[afi][safi],
8732 PEER_FLAG_REMOVE_PRIVATE_AS_ALL_REPLACE))
8733 json_object_boolean_true_add(
8734 json_addr,
8735 "privateAsNumsAllReplacedInUpdatesToNbr");
8736 else if (CHECK_FLAG(p->af_flags[afi][safi],
8737 PEER_FLAG_REMOVE_PRIVATE_AS_REPLACE))
8738 json_object_boolean_true_add(
8739 json_addr,
8740 "privateAsNumsReplacedInUpdatesToNbr");
8741 else if (CHECK_FLAG(p->af_flags[afi][safi],
8742 PEER_FLAG_REMOVE_PRIVATE_AS_ALL))
8743 json_object_boolean_true_add(
8744 json_addr,
8745 "privateAsNumsAllRemovedInUpdatesToNbr");
8746 else if (CHECK_FLAG(p->af_flags[afi][safi],
8747 PEER_FLAG_REMOVE_PRIVATE_AS))
8748 json_object_boolean_true_add(
8749 json_addr,
8750 "privateAsNumsRemovedInUpdatesToNbr");
8751
8752 if (p->addpath_type[afi][safi] != BGP_ADDPATH_NONE)
8753 json_object_boolean_true_add(
8754 json_addr,
8755 bgp_addpath_names(p->addpath_type[afi][safi])
8756 ->type_json_name);
8757
8758 if (CHECK_FLAG(p->af_flags[afi][safi], PEER_FLAG_AS_OVERRIDE))
8759 json_object_string_add(json_addr,
8760 "overrideASNsInOutboundUpdates",
8761 "ifAspathEqualRemoteAs");
8762
8763 if (CHECK_FLAG(p->af_flags[afi][safi], PEER_FLAG_NEXTHOP_SELF)
8764 || CHECK_FLAG(p->af_flags[afi][safi],
8765 PEER_FLAG_FORCE_NEXTHOP_SELF))
8766 json_object_boolean_true_add(json_addr,
8767 "routerAlwaysNextHop");
8768 if (CHECK_FLAG(p->af_flags[afi][safi],
8769 PEER_FLAG_AS_PATH_UNCHANGED))
8770 json_object_boolean_true_add(
8771 json_addr, "unchangedAsPathPropogatedToNbr");
8772 if (CHECK_FLAG(p->af_flags[afi][safi],
8773 PEER_FLAG_NEXTHOP_UNCHANGED))
8774 json_object_boolean_true_add(
8775 json_addr, "unchangedNextHopPropogatedToNbr");
8776 if (CHECK_FLAG(p->af_flags[afi][safi], PEER_FLAG_MED_UNCHANGED))
8777 json_object_boolean_true_add(
8778 json_addr, "unchangedMedPropogatedToNbr");
8779 if (CHECK_FLAG(p->af_flags[afi][safi], PEER_FLAG_SEND_COMMUNITY)
8780 || CHECK_FLAG(p->af_flags[afi][safi],
8781 PEER_FLAG_SEND_EXT_COMMUNITY)) {
8782 if (CHECK_FLAG(p->af_flags[afi][safi],
8783 PEER_FLAG_SEND_COMMUNITY)
8784 && CHECK_FLAG(p->af_flags[afi][safi],
8785 PEER_FLAG_SEND_EXT_COMMUNITY))
8786 json_object_string_add(json_addr,
8787 "commAttriSentToNbr",
8788 "extendedAndStandard");
8789 else if (CHECK_FLAG(p->af_flags[afi][safi],
8790 PEER_FLAG_SEND_EXT_COMMUNITY))
8791 json_object_string_add(json_addr,
8792 "commAttriSentToNbr",
8793 "extended");
8794 else
8795 json_object_string_add(json_addr,
8796 "commAttriSentToNbr",
8797 "standard");
8798 }
8799 if (CHECK_FLAG(p->af_flags[afi][safi],
8800 PEER_FLAG_DEFAULT_ORIGINATE)) {
8801 if (p->default_rmap[afi][safi].name)
8802 json_object_string_add(
8803 json_addr, "defaultRouteMap",
8804 p->default_rmap[afi][safi].name);
8805
8806 if (paf && PAF_SUBGRP(paf)
8807 && CHECK_FLAG(PAF_SUBGRP(paf)->sflags,
8808 SUBGRP_STATUS_DEFAULT_ORIGINATE))
8809 json_object_boolean_true_add(json_addr,
8810 "defaultSent");
8811 else
8812 json_object_boolean_true_add(json_addr,
8813 "defaultNotSent");
8814 }
8815
8816 if (afi == AFI_L2VPN && safi == SAFI_EVPN) {
8817 if (is_evpn_enabled())
8818 json_object_boolean_true_add(
8819 json_addr, "advertiseAllVnis");
8820 }
8821
8822 if (filter->plist[FILTER_IN].name
8823 || filter->dlist[FILTER_IN].name
8824 || filter->aslist[FILTER_IN].name
8825 || filter->map[RMAP_IN].name)
8826 json_object_boolean_true_add(json_addr,
8827 "inboundPathPolicyConfig");
8828 if (filter->plist[FILTER_OUT].name
8829 || filter->dlist[FILTER_OUT].name
8830 || filter->aslist[FILTER_OUT].name
8831 || filter->map[RMAP_OUT].name || filter->usmap.name)
8832 json_object_boolean_true_add(
8833 json_addr, "outboundPathPolicyConfig");
8834
8835 /* prefix-list */
8836 if (filter->plist[FILTER_IN].name)
8837 json_object_string_add(json_addr,
8838 "incomingUpdatePrefixFilterList",
8839 filter->plist[FILTER_IN].name);
8840 if (filter->plist[FILTER_OUT].name)
8841 json_object_string_add(json_addr,
8842 "outgoingUpdatePrefixFilterList",
8843 filter->plist[FILTER_OUT].name);
8844
8845 /* distribute-list */
8846 if (filter->dlist[FILTER_IN].name)
8847 json_object_string_add(
8848 json_addr, "incomingUpdateNetworkFilterList",
8849 filter->dlist[FILTER_IN].name);
8850 if (filter->dlist[FILTER_OUT].name)
8851 json_object_string_add(
8852 json_addr, "outgoingUpdateNetworkFilterList",
8853 filter->dlist[FILTER_OUT].name);
8854
8855 /* filter-list. */
8856 if (filter->aslist[FILTER_IN].name)
8857 json_object_string_add(json_addr,
8858 "incomingUpdateAsPathFilterList",
8859 filter->aslist[FILTER_IN].name);
8860 if (filter->aslist[FILTER_OUT].name)
8861 json_object_string_add(json_addr,
8862 "outgoingUpdateAsPathFilterList",
8863 filter->aslist[FILTER_OUT].name);
8864
8865 /* route-map. */
8866 if (filter->map[RMAP_IN].name)
8867 json_object_string_add(
8868 json_addr, "routeMapForIncomingAdvertisements",
8869 filter->map[RMAP_IN].name);
8870 if (filter->map[RMAP_OUT].name)
8871 json_object_string_add(
8872 json_addr, "routeMapForOutgoingAdvertisements",
8873 filter->map[RMAP_OUT].name);
8874
8875 /* ebgp-requires-policy (inbound) */
8876 if (p->bgp->ebgp_requires_policy == DEFAULT_EBGP_POLICY_ENABLED
8877 && !bgp_inbound_policy_exists(p, filter))
8878 json_object_string_add(
8879 json_addr, "inboundEbgpRequiresPolicy",
8880 "Inbound updates discarded due to missing policy");
8881
8882 /* ebgp-requires-policy (outbound) */
8883 if (p->bgp->ebgp_requires_policy == DEFAULT_EBGP_POLICY_ENABLED
8884 && (!bgp_outbound_policy_exists(p, filter)))
8885 json_object_string_add(
8886 json_addr, "outboundEbgpRequiresPolicy",
8887 "Outbound updates discarded due to missing policy");
8888
8889 /* unsuppress-map */
8890 if (filter->usmap.name)
8891 json_object_string_add(json_addr,
8892 "selectiveUnsuppressRouteMap",
8893 filter->usmap.name);
8894
8895 /* Receive prefix count */
8896 json_object_int_add(json_addr, "acceptedPrefixCounter",
8897 p->pcount[afi][safi]);
8898 if (paf && PAF_SUBGRP(paf))
8899 json_object_int_add(json_addr, "sentPrefixCounter",
8900 (PAF_SUBGRP(paf))->scount);
8901
8902 /* Maximum prefix */
8903 if (CHECK_FLAG(p->af_flags[afi][safi], PEER_FLAG_MAX_PREFIX)) {
8904 json_object_int_add(json_addr, "prefixAllowedMax",
8905 p->pmax[afi][safi]);
8906 if (CHECK_FLAG(p->af_flags[afi][safi],
8907 PEER_FLAG_MAX_PREFIX_WARNING))
8908 json_object_boolean_true_add(
8909 json_addr, "prefixAllowedMaxWarning");
8910 json_object_int_add(json_addr,
8911 "prefixAllowedWarningThresh",
8912 p->pmax_threshold[afi][safi]);
8913 if (p->pmax_restart[afi][safi])
8914 json_object_int_add(
8915 json_addr,
8916 "prefixAllowedRestartIntervalMsecs",
8917 p->pmax_restart[afi][safi] * 60000);
8918 }
8919 json_object_object_add(json_neigh, afi_safi_print(afi, safi),
8920 json_addr);
8921
8922 } else {
8923 filter = &p->filter[afi][safi];
8924
8925 vty_out(vty, " For address family: %s\n",
8926 afi_safi_print(afi, safi));
8927
8928 if (peer_group_active(p))
8929 vty_out(vty, " %s peer-group member\n",
8930 p->group->name);
8931
8932 paf = peer_af_find(p, afi, safi);
8933 if (paf && PAF_SUBGRP(paf)) {
8934 vty_out(vty, " Update group %" PRIu64
8935 ", subgroup %" PRIu64 "\n",
8936 PAF_UPDGRP(paf)->id, PAF_SUBGRP(paf)->id);
8937 vty_out(vty, " Packet Queue length %d\n",
8938 bpacket_queue_virtual_length(paf));
8939 } else {
8940 vty_out(vty, " Not part of any update group\n");
8941 }
8942 if (CHECK_FLAG(p->af_cap[afi][safi], PEER_CAP_ORF_PREFIX_SM_ADV)
8943 || CHECK_FLAG(p->af_cap[afi][safi],
8944 PEER_CAP_ORF_PREFIX_SM_RCV)
8945 || CHECK_FLAG(p->af_cap[afi][safi],
8946 PEER_CAP_ORF_PREFIX_SM_OLD_RCV)
8947 || CHECK_FLAG(p->af_cap[afi][safi],
8948 PEER_CAP_ORF_PREFIX_RM_ADV)
8949 || CHECK_FLAG(p->af_cap[afi][safi],
8950 PEER_CAP_ORF_PREFIX_RM_RCV)
8951 || CHECK_FLAG(p->af_cap[afi][safi],
8952 PEER_CAP_ORF_PREFIX_RM_OLD_RCV))
8953 vty_out(vty, " AF-dependant capabilities:\n");
8954
8955 if (CHECK_FLAG(p->af_cap[afi][safi], PEER_CAP_ORF_PREFIX_SM_ADV)
8956 || CHECK_FLAG(p->af_cap[afi][safi],
8957 PEER_CAP_ORF_PREFIX_SM_RCV)
8958 || CHECK_FLAG(p->af_cap[afi][safi],
8959 PEER_CAP_ORF_PREFIX_RM_ADV)
8960 || CHECK_FLAG(p->af_cap[afi][safi],
8961 PEER_CAP_ORF_PREFIX_RM_RCV)) {
8962 vty_out(vty,
8963 " Outbound Route Filter (ORF) type (%d) Prefix-list:\n",
8964 ORF_TYPE_PREFIX);
8965 bgp_show_peer_afi_orf_cap(
8966 vty, p, afi, safi, PEER_CAP_ORF_PREFIX_SM_ADV,
8967 PEER_CAP_ORF_PREFIX_RM_ADV,
8968 PEER_CAP_ORF_PREFIX_SM_RCV,
8969 PEER_CAP_ORF_PREFIX_RM_RCV, use_json, NULL);
8970 }
8971 if (CHECK_FLAG(p->af_cap[afi][safi], PEER_CAP_ORF_PREFIX_SM_ADV)
8972 || CHECK_FLAG(p->af_cap[afi][safi],
8973 PEER_CAP_ORF_PREFIX_SM_OLD_RCV)
8974 || CHECK_FLAG(p->af_cap[afi][safi],
8975 PEER_CAP_ORF_PREFIX_RM_ADV)
8976 || CHECK_FLAG(p->af_cap[afi][safi],
8977 PEER_CAP_ORF_PREFIX_RM_OLD_RCV)) {
8978 vty_out(vty,
8979 " Outbound Route Filter (ORF) type (%d) Prefix-list:\n",
8980 ORF_TYPE_PREFIX_OLD);
8981 bgp_show_peer_afi_orf_cap(
8982 vty, p, afi, safi, PEER_CAP_ORF_PREFIX_SM_ADV,
8983 PEER_CAP_ORF_PREFIX_RM_ADV,
8984 PEER_CAP_ORF_PREFIX_SM_OLD_RCV,
8985 PEER_CAP_ORF_PREFIX_RM_OLD_RCV, use_json, NULL);
8986 }
8987
8988 sprintf(orf_pfx_name, "%s.%d.%d", p->host, afi, safi);
8989 orf_pfx_count = prefix_bgp_show_prefix_list(
8990 NULL, afi, orf_pfx_name, use_json);
8991
8992 if (CHECK_FLAG(p->af_sflags[afi][safi],
8993 PEER_STATUS_ORF_PREFIX_SEND)
8994 || orf_pfx_count) {
8995 vty_out(vty, " Outbound Route Filter (ORF):");
8996 if (CHECK_FLAG(p->af_sflags[afi][safi],
8997 PEER_STATUS_ORF_PREFIX_SEND))
8998 vty_out(vty, " sent;");
8999 if (orf_pfx_count)
9000 vty_out(vty, " received (%d entries)",
9001 orf_pfx_count);
9002 vty_out(vty, "\n");
9003 }
9004 if (CHECK_FLAG(p->af_sflags[afi][safi],
9005 PEER_STATUS_ORF_WAIT_REFRESH))
9006 vty_out(vty,
9007 " First update is deferred until ORF or ROUTE-REFRESH is received\n");
9008
9009 if (CHECK_FLAG(p->af_flags[afi][safi],
9010 PEER_FLAG_REFLECTOR_CLIENT))
9011 vty_out(vty, " Route-Reflector Client\n");
9012 if (CHECK_FLAG(p->af_flags[afi][safi],
9013 PEER_FLAG_RSERVER_CLIENT))
9014 vty_out(vty, " Route-Server Client\n");
9015 if (CHECK_FLAG(p->af_flags[afi][safi], PEER_FLAG_SOFT_RECONFIG))
9016 vty_out(vty,
9017 " Inbound soft reconfiguration allowed\n");
9018
9019 if (CHECK_FLAG(p->af_flags[afi][safi],
9020 PEER_FLAG_REMOVE_PRIVATE_AS_ALL_REPLACE))
9021 vty_out(vty,
9022 " Private AS numbers (all) replaced in updates to this neighbor\n");
9023 else if (CHECK_FLAG(p->af_flags[afi][safi],
9024 PEER_FLAG_REMOVE_PRIVATE_AS_REPLACE))
9025 vty_out(vty,
9026 " Private AS numbers replaced in updates to this neighbor\n");
9027 else if (CHECK_FLAG(p->af_flags[afi][safi],
9028 PEER_FLAG_REMOVE_PRIVATE_AS_ALL))
9029 vty_out(vty,
9030 " Private AS numbers (all) removed in updates to this neighbor\n");
9031 else if (CHECK_FLAG(p->af_flags[afi][safi],
9032 PEER_FLAG_REMOVE_PRIVATE_AS))
9033 vty_out(vty,
9034 " Private AS numbers removed in updates to this neighbor\n");
9035
9036 if (p->addpath_type[afi][safi] != BGP_ADDPATH_NONE)
9037 vty_out(vty, " %s\n",
9038 bgp_addpath_names(p->addpath_type[afi][safi])
9039 ->human_description);
9040
9041 if (CHECK_FLAG(p->af_flags[afi][safi], PEER_FLAG_AS_OVERRIDE))
9042 vty_out(vty,
9043 " Override ASNs in outbound updates if aspath equals remote-as\n");
9044
9045 if (CHECK_FLAG(p->af_flags[afi][safi], PEER_FLAG_NEXTHOP_SELF)
9046 || CHECK_FLAG(p->af_flags[afi][safi],
9047 PEER_FLAG_FORCE_NEXTHOP_SELF))
9048 vty_out(vty, " NEXT_HOP is always this router\n");
9049 if (CHECK_FLAG(p->af_flags[afi][safi],
9050 PEER_FLAG_AS_PATH_UNCHANGED))
9051 vty_out(vty,
9052 " AS_PATH is propagated unchanged to this neighbor\n");
9053 if (CHECK_FLAG(p->af_flags[afi][safi],
9054 PEER_FLAG_NEXTHOP_UNCHANGED))
9055 vty_out(vty,
9056 " NEXT_HOP is propagated unchanged to this neighbor\n");
9057 if (CHECK_FLAG(p->af_flags[afi][safi], PEER_FLAG_MED_UNCHANGED))
9058 vty_out(vty,
9059 " MED is propagated unchanged to this neighbor\n");
9060 if (CHECK_FLAG(p->af_flags[afi][safi], PEER_FLAG_SEND_COMMUNITY)
9061 || CHECK_FLAG(p->af_flags[afi][safi],
9062 PEER_FLAG_SEND_EXT_COMMUNITY)
9063 || CHECK_FLAG(p->af_flags[afi][safi],
9064 PEER_FLAG_SEND_LARGE_COMMUNITY)) {
9065 vty_out(vty,
9066 " Community attribute sent to this neighbor");
9067 if (CHECK_FLAG(p->af_flags[afi][safi],
9068 PEER_FLAG_SEND_COMMUNITY)
9069 && CHECK_FLAG(p->af_flags[afi][safi],
9070 PEER_FLAG_SEND_EXT_COMMUNITY)
9071 && CHECK_FLAG(p->af_flags[afi][safi],
9072 PEER_FLAG_SEND_LARGE_COMMUNITY))
9073 vty_out(vty, "(all)\n");
9074 else if (CHECK_FLAG(p->af_flags[afi][safi],
9075 PEER_FLAG_SEND_LARGE_COMMUNITY))
9076 vty_out(vty, "(large)\n");
9077 else if (CHECK_FLAG(p->af_flags[afi][safi],
9078 PEER_FLAG_SEND_EXT_COMMUNITY))
9079 vty_out(vty, "(extended)\n");
9080 else
9081 vty_out(vty, "(standard)\n");
9082 }
9083 if (CHECK_FLAG(p->af_flags[afi][safi],
9084 PEER_FLAG_DEFAULT_ORIGINATE)) {
9085 vty_out(vty, " Default information originate,");
9086
9087 if (p->default_rmap[afi][safi].name)
9088 vty_out(vty, " default route-map %s%s,",
9089 p->default_rmap[afi][safi].map ? "*"
9090 : "",
9091 p->default_rmap[afi][safi].name);
9092 if (paf && PAF_SUBGRP(paf)
9093 && CHECK_FLAG(PAF_SUBGRP(paf)->sflags,
9094 SUBGRP_STATUS_DEFAULT_ORIGINATE))
9095 vty_out(vty, " default sent\n");
9096 else
9097 vty_out(vty, " default not sent\n");
9098 }
9099
9100 /* advertise-vni-all */
9101 if (afi == AFI_L2VPN && safi == SAFI_EVPN) {
9102 if (is_evpn_enabled())
9103 vty_out(vty, " advertise-all-vni\n");
9104 }
9105
9106 if (filter->plist[FILTER_IN].name
9107 || filter->dlist[FILTER_IN].name
9108 || filter->aslist[FILTER_IN].name
9109 || filter->map[RMAP_IN].name)
9110 vty_out(vty, " Inbound path policy configured\n");
9111 if (filter->plist[FILTER_OUT].name
9112 || filter->dlist[FILTER_OUT].name
9113 || filter->aslist[FILTER_OUT].name
9114 || filter->map[RMAP_OUT].name || filter->usmap.name)
9115 vty_out(vty, " Outbound path policy configured\n");
9116
9117 /* prefix-list */
9118 if (filter->plist[FILTER_IN].name)
9119 vty_out(vty,
9120 " Incoming update prefix filter list is %s%s\n",
9121 filter->plist[FILTER_IN].plist ? "*" : "",
9122 filter->plist[FILTER_IN].name);
9123 if (filter->plist[FILTER_OUT].name)
9124 vty_out(vty,
9125 " Outgoing update prefix filter list is %s%s\n",
9126 filter->plist[FILTER_OUT].plist ? "*" : "",
9127 filter->plist[FILTER_OUT].name);
9128
9129 /* distribute-list */
9130 if (filter->dlist[FILTER_IN].name)
9131 vty_out(vty,
9132 " Incoming update network filter list is %s%s\n",
9133 filter->dlist[FILTER_IN].alist ? "*" : "",
9134 filter->dlist[FILTER_IN].name);
9135 if (filter->dlist[FILTER_OUT].name)
9136 vty_out(vty,
9137 " Outgoing update network filter list is %s%s\n",
9138 filter->dlist[FILTER_OUT].alist ? "*" : "",
9139 filter->dlist[FILTER_OUT].name);
9140
9141 /* filter-list. */
9142 if (filter->aslist[FILTER_IN].name)
9143 vty_out(vty,
9144 " Incoming update AS path filter list is %s%s\n",
9145 filter->aslist[FILTER_IN].aslist ? "*" : "",
9146 filter->aslist[FILTER_IN].name);
9147 if (filter->aslist[FILTER_OUT].name)
9148 vty_out(vty,
9149 " Outgoing update AS path filter list is %s%s\n",
9150 filter->aslist[FILTER_OUT].aslist ? "*" : "",
9151 filter->aslist[FILTER_OUT].name);
9152
9153 /* route-map. */
9154 if (filter->map[RMAP_IN].name)
9155 vty_out(vty,
9156 " Route map for incoming advertisements is %s%s\n",
9157 filter->map[RMAP_IN].map ? "*" : "",
9158 filter->map[RMAP_IN].name);
9159 if (filter->map[RMAP_OUT].name)
9160 vty_out(vty,
9161 " Route map for outgoing advertisements is %s%s\n",
9162 filter->map[RMAP_OUT].map ? "*" : "",
9163 filter->map[RMAP_OUT].name);
9164
9165 /* ebgp-requires-policy (inbound) */
9166 if (p->bgp->ebgp_requires_policy == DEFAULT_EBGP_POLICY_ENABLED
9167 && !bgp_inbound_policy_exists(p, filter))
9168 vty_out(vty,
9169 " Inbound updates discarded due to missing policy\n");
9170
9171 /* ebgp-requires-policy (outbound) */
9172 if (p->bgp->ebgp_requires_policy == DEFAULT_EBGP_POLICY_ENABLED
9173 && !bgp_outbound_policy_exists(p, filter))
9174 vty_out(vty,
9175 " Outbound updates discarded due to missing policy\n");
9176
9177 /* unsuppress-map */
9178 if (filter->usmap.name)
9179 vty_out(vty,
9180 " Route map for selective unsuppress is %s%s\n",
9181 filter->usmap.map ? "*" : "",
9182 filter->usmap.name);
9183
9184 /* Receive prefix count */
9185 vty_out(vty, " %ld accepted prefixes\n", p->pcount[afi][safi]);
9186
9187 /* Maximum prefix */
9188 if (CHECK_FLAG(p->af_flags[afi][safi], PEER_FLAG_MAX_PREFIX)) {
9189 vty_out(vty, " Maximum prefixes allowed %ld%s\n",
9190 p->pmax[afi][safi],
9191 CHECK_FLAG(p->af_flags[afi][safi],
9192 PEER_FLAG_MAX_PREFIX_WARNING)
9193 ? " (warning-only)"
9194 : "");
9195 vty_out(vty, " Threshold for warning message %d%%",
9196 p->pmax_threshold[afi][safi]);
9197 if (p->pmax_restart[afi][safi])
9198 vty_out(vty, ", restart interval %d min",
9199 p->pmax_restart[afi][safi]);
9200 vty_out(vty, "\n");
9201 }
9202
9203 vty_out(vty, "\n");
9204 }
9205 }
9206
9207 static void bgp_show_peer(struct vty *vty, struct peer *p, bool use_json,
9208 json_object *json)
9209 {
9210 struct bgp *bgp;
9211 char buf1[PREFIX2STR_BUFFER], buf[SU_ADDRSTRLEN];
9212 char timebuf[BGP_UPTIME_LEN];
9213 char dn_flag[2];
9214 const char *subcode_str;
9215 const char *code_str;
9216 afi_t afi;
9217 safi_t safi;
9218 uint16_t i;
9219 uint8_t *msg;
9220 json_object *json_neigh = NULL;
9221 time_t epoch_tbuf;
9222
9223 bgp = p->bgp;
9224
9225 if (use_json)
9226 json_neigh = json_object_new_object();
9227
9228 memset(dn_flag, '\0', sizeof(dn_flag));
9229 if (!p->conf_if && peer_dynamic_neighbor(p))
9230 dn_flag[0] = '*';
9231
9232 if (!use_json) {
9233 if (p->conf_if) /* Configured interface name. */
9234 vty_out(vty, "BGP neighbor on %s: %s, ", p->conf_if,
9235 BGP_PEER_SU_UNSPEC(p)
9236 ? "None"
9237 : sockunion2str(&p->su, buf,
9238 SU_ADDRSTRLEN));
9239 else /* Configured IP address. */
9240 vty_out(vty, "BGP neighbor is %s%s, ", dn_flag,
9241 p->host);
9242 }
9243
9244 if (use_json) {
9245 if (p->conf_if && BGP_PEER_SU_UNSPEC(p))
9246 json_object_string_add(json_neigh, "bgpNeighborAddr",
9247 "none");
9248 else if (p->conf_if && !BGP_PEER_SU_UNSPEC(p))
9249 json_object_string_add(
9250 json_neigh, "bgpNeighborAddr",
9251 sockunion2str(&p->su, buf, SU_ADDRSTRLEN));
9252
9253 json_object_int_add(json_neigh, "remoteAs", p->as);
9254
9255 if (p->change_local_as)
9256 json_object_int_add(json_neigh, "localAs",
9257 p->change_local_as);
9258 else
9259 json_object_int_add(json_neigh, "localAs", p->local_as);
9260
9261 if (CHECK_FLAG(p->flags, PEER_FLAG_LOCAL_AS_NO_PREPEND))
9262 json_object_boolean_true_add(json_neigh,
9263 "localAsNoPrepend");
9264
9265 if (CHECK_FLAG(p->flags, PEER_FLAG_LOCAL_AS_REPLACE_AS))
9266 json_object_boolean_true_add(json_neigh,
9267 "localAsReplaceAs");
9268 } else {
9269 if ((p->as_type == AS_SPECIFIED) || (p->as_type == AS_EXTERNAL)
9270 || (p->as_type == AS_INTERNAL))
9271 vty_out(vty, "remote AS %u, ", p->as);
9272 else
9273 vty_out(vty, "remote AS Unspecified, ");
9274 vty_out(vty, "local AS %u%s%s, ",
9275 p->change_local_as ? p->change_local_as : p->local_as,
9276 CHECK_FLAG(p->flags, PEER_FLAG_LOCAL_AS_NO_PREPEND)
9277 ? " no-prepend"
9278 : "",
9279 CHECK_FLAG(p->flags, PEER_FLAG_LOCAL_AS_REPLACE_AS)
9280 ? " replace-as"
9281 : "");
9282 }
9283 /* peer type internal or confed-internal */
9284 if ((p->as == p->local_as) || (p->as_type == AS_INTERNAL)) {
9285 if (use_json) {
9286 if (CHECK_FLAG(bgp->config, BGP_CONFIG_CONFEDERATION))
9287 json_object_boolean_true_add(
9288 json_neigh, "nbrConfedInternalLink");
9289 else
9290 json_object_boolean_true_add(json_neigh,
9291 "nbrInternalLink");
9292 } else {
9293 if (CHECK_FLAG(bgp->config, BGP_CONFIG_CONFEDERATION))
9294 vty_out(vty, "confed-internal link\n");
9295 else
9296 vty_out(vty, "internal link\n");
9297 }
9298 /* peer type external or confed-external */
9299 } else if (p->as || (p->as_type == AS_EXTERNAL)) {
9300 if (use_json) {
9301 if (CHECK_FLAG(bgp->config, BGP_CONFIG_CONFEDERATION))
9302 json_object_boolean_true_add(
9303 json_neigh, "nbrConfedExternalLink");
9304 else
9305 json_object_boolean_true_add(json_neigh,
9306 "nbrExternalLink");
9307 } else {
9308 if (bgp_confederation_peers_check(bgp, p->as))
9309 vty_out(vty, "confed-external link\n");
9310 else
9311 vty_out(vty, "external link\n");
9312 }
9313 } else {
9314 if (use_json)
9315 json_object_boolean_true_add(json_neigh,
9316 "nbrUnspecifiedLink");
9317 else
9318 vty_out(vty, "unspecified link\n");
9319 }
9320
9321 /* Description. */
9322 if (p->desc) {
9323 if (use_json)
9324 json_object_string_add(json_neigh, "nbrDesc", p->desc);
9325 else
9326 vty_out(vty, " Description: %s\n", p->desc);
9327 }
9328
9329 if (p->hostname) {
9330 if (use_json) {
9331 if (p->hostname)
9332 json_object_string_add(json_neigh, "hostname",
9333 p->hostname);
9334
9335 if (p->domainname)
9336 json_object_string_add(json_neigh, "domainname",
9337 p->domainname);
9338 } else {
9339 if (p->domainname && (p->domainname[0] != '\0'))
9340 vty_out(vty, "Hostname: %s.%s\n", p->hostname,
9341 p->domainname);
9342 else
9343 vty_out(vty, "Hostname: %s\n", p->hostname);
9344 }
9345 }
9346
9347 /* Peer-group */
9348 if (p->group) {
9349 if (use_json) {
9350 json_object_string_add(json_neigh, "peerGroup",
9351 p->group->name);
9352
9353 if (dn_flag[0]) {
9354 struct prefix prefix, *range = NULL;
9355
9356 sockunion2hostprefix(&(p->su), &prefix);
9357 range = peer_group_lookup_dynamic_neighbor_range(
9358 p->group, &prefix);
9359
9360 if (range) {
9361 prefix2str(range, buf1, sizeof(buf1));
9362 json_object_string_add(
9363 json_neigh,
9364 "peerSubnetRangeGroup", buf1);
9365 }
9366 }
9367 } else {
9368 vty_out(vty,
9369 " Member of peer-group %s for session parameters\n",
9370 p->group->name);
9371
9372 if (dn_flag[0]) {
9373 struct prefix prefix, *range = NULL;
9374
9375 sockunion2hostprefix(&(p->su), &prefix);
9376 range = peer_group_lookup_dynamic_neighbor_range(
9377 p->group, &prefix);
9378
9379 if (range) {
9380 prefix2str(range, buf1, sizeof(buf1));
9381 vty_out(vty,
9382 " Belongs to the subnet range group: %s\n",
9383 buf1);
9384 }
9385 }
9386 }
9387 }
9388
9389 if (use_json) {
9390 /* Administrative shutdown. */
9391 if (CHECK_FLAG(p->flags, PEER_FLAG_SHUTDOWN))
9392 json_object_boolean_true_add(json_neigh,
9393 "adminShutDown");
9394
9395 /* BGP Version. */
9396 json_object_int_add(json_neigh, "bgpVersion", 4);
9397 json_object_string_add(
9398 json_neigh, "remoteRouterId",
9399 inet_ntop(AF_INET, &p->remote_id, buf1, sizeof(buf1)));
9400 json_object_string_add(
9401 json_neigh, "localRouterId",
9402 inet_ntop(AF_INET, &bgp->router_id, buf1,
9403 sizeof(buf1)));
9404
9405 /* Confederation */
9406 if (CHECK_FLAG(bgp->config, BGP_CONFIG_CONFEDERATION)
9407 && bgp_confederation_peers_check(bgp, p->as))
9408 json_object_boolean_true_add(json_neigh,
9409 "nbrCommonAdmin");
9410
9411 /* Status. */
9412 json_object_string_add(
9413 json_neigh, "bgpState",
9414 lookup_msg(bgp_status_msg, p->status, NULL));
9415
9416 if (p->status == Established) {
9417 time_t uptime;
9418
9419 uptime = bgp_clock();
9420 uptime -= p->uptime;
9421 epoch_tbuf = time(NULL) - uptime;
9422
9423 #if CONFDATE > 20200101
9424 CPP_NOTICE(
9425 "bgpTimerUp should be deprecated and can be removed now");
9426 #endif
9427 /*
9428 * bgpTimerUp was miliseconds that was accurate
9429 * up to 1 day, then the value returned
9430 * became garbage. So in order to provide
9431 * some level of backwards compatability,
9432 * we still provde the data, but now
9433 * we are returning the correct value
9434 * and also adding a new bgpTimerUpMsec
9435 * which will allow us to deprecate
9436 * this eventually
9437 */
9438 json_object_int_add(json_neigh, "bgpTimerUp",
9439 uptime * 1000);
9440 json_object_int_add(json_neigh, "bgpTimerUpMsec",
9441 uptime * 1000);
9442 json_object_string_add(json_neigh, "bgpTimerUpString",
9443 peer_uptime(p->uptime, timebuf,
9444 BGP_UPTIME_LEN, 0,
9445 NULL));
9446 json_object_int_add(json_neigh,
9447 "bgpTimerUpEstablishedEpoch",
9448 epoch_tbuf);
9449 }
9450
9451 else if (p->status == Active) {
9452 if (CHECK_FLAG(p->flags, PEER_FLAG_PASSIVE))
9453 json_object_string_add(json_neigh, "bgpStateIs",
9454 "passive");
9455 else if (CHECK_FLAG(p->sflags, PEER_STATUS_NSF_WAIT))
9456 json_object_string_add(json_neigh, "bgpStateIs",
9457 "passiveNSF");
9458 }
9459
9460 /* read timer */
9461 time_t uptime;
9462 struct tm *tm;
9463
9464 uptime = bgp_clock();
9465 uptime -= p->readtime;
9466 tm = gmtime(&uptime);
9467 json_object_int_add(json_neigh, "bgpTimerLastRead",
9468 (tm->tm_sec * 1000) + (tm->tm_min * 60000)
9469 + (tm->tm_hour * 3600000));
9470
9471 uptime = bgp_clock();
9472 uptime -= p->last_write;
9473 tm = gmtime(&uptime);
9474 json_object_int_add(json_neigh, "bgpTimerLastWrite",
9475 (tm->tm_sec * 1000) + (tm->tm_min * 60000)
9476 + (tm->tm_hour * 3600000));
9477
9478 uptime = bgp_clock();
9479 uptime -= p->update_time;
9480 tm = gmtime(&uptime);
9481 json_object_int_add(json_neigh, "bgpInUpdateElapsedTimeMsecs",
9482 (tm->tm_sec * 1000) + (tm->tm_min * 60000)
9483 + (tm->tm_hour * 3600000));
9484
9485 /* Configured timer values. */
9486 json_object_int_add(json_neigh, "bgpTimerHoldTimeMsecs",
9487 p->v_holdtime * 1000);
9488 json_object_int_add(json_neigh,
9489 "bgpTimerKeepAliveIntervalMsecs",
9490 p->v_keepalive * 1000);
9491 if (CHECK_FLAG(p->flags, PEER_FLAG_TIMER)) {
9492 json_object_int_add(json_neigh,
9493 "bgpTimerConfiguredHoldTimeMsecs",
9494 p->holdtime * 1000);
9495 json_object_int_add(
9496 json_neigh,
9497 "bgpTimerConfiguredKeepAliveIntervalMsecs",
9498 p->keepalive * 1000);
9499 } else if ((bgp->default_holdtime != BGP_DEFAULT_HOLDTIME)
9500 || (bgp->default_keepalive
9501 != BGP_DEFAULT_KEEPALIVE)) {
9502 json_object_int_add(json_neigh,
9503 "bgpTimerConfiguredHoldTimeMsecs",
9504 bgp->default_holdtime);
9505 json_object_int_add(
9506 json_neigh,
9507 "bgpTimerConfiguredKeepAliveIntervalMsecs",
9508 bgp->default_keepalive);
9509 }
9510 } else {
9511 /* Administrative shutdown. */
9512 if (CHECK_FLAG(p->flags, PEER_FLAG_SHUTDOWN))
9513 vty_out(vty, " Administratively shut down\n");
9514
9515 /* BGP Version. */
9516 vty_out(vty, " BGP version 4");
9517 vty_out(vty, ", remote router ID %s",
9518 inet_ntop(AF_INET, &p->remote_id, buf1, sizeof(buf1)));
9519 vty_out(vty, ", local router ID %s\n",
9520 inet_ntop(AF_INET, &bgp->router_id, buf1,
9521 sizeof(buf1)));
9522
9523 /* Confederation */
9524 if (CHECK_FLAG(bgp->config, BGP_CONFIG_CONFEDERATION)
9525 && bgp_confederation_peers_check(bgp, p->as))
9526 vty_out(vty,
9527 " Neighbor under common administration\n");
9528
9529 /* Status. */
9530 vty_out(vty, " BGP state = %s",
9531 lookup_msg(bgp_status_msg, p->status, NULL));
9532
9533 if (p->status == Established)
9534 vty_out(vty, ", up for %8s",
9535 peer_uptime(p->uptime, timebuf, BGP_UPTIME_LEN,
9536 0, NULL));
9537
9538 else if (p->status == Active) {
9539 if (CHECK_FLAG(p->flags, PEER_FLAG_PASSIVE))
9540 vty_out(vty, " (passive)");
9541 else if (CHECK_FLAG(p->sflags, PEER_STATUS_NSF_WAIT))
9542 vty_out(vty, " (NSF passive)");
9543 }
9544 vty_out(vty, "\n");
9545
9546 /* read timer */
9547 vty_out(vty, " Last read %s",
9548 peer_uptime(p->readtime, timebuf, BGP_UPTIME_LEN, 0,
9549 NULL));
9550 vty_out(vty, ", Last write %s\n",
9551 peer_uptime(p->last_write, timebuf, BGP_UPTIME_LEN, 0,
9552 NULL));
9553
9554 /* Configured timer values. */
9555 vty_out(vty,
9556 " Hold time is %d, keepalive interval is %d seconds\n",
9557 p->v_holdtime, p->v_keepalive);
9558 if (CHECK_FLAG(p->flags, PEER_FLAG_TIMER)) {
9559 vty_out(vty, " Configured hold time is %d",
9560 p->holdtime);
9561 vty_out(vty, ", keepalive interval is %d seconds\n",
9562 p->keepalive);
9563 } else if ((bgp->default_holdtime != BGP_DEFAULT_HOLDTIME)
9564 || (bgp->default_keepalive
9565 != BGP_DEFAULT_KEEPALIVE)) {
9566 vty_out(vty, " Configured hold time is %d",
9567 bgp->default_holdtime);
9568 vty_out(vty, ", keepalive interval is %d seconds\n",
9569 bgp->default_keepalive);
9570 }
9571 }
9572 /* Capability. */
9573 if (p->status == Established) {
9574 if (p->cap || p->afc_adv[AFI_IP][SAFI_UNICAST]
9575 || p->afc_recv[AFI_IP][SAFI_UNICAST]
9576 || p->afc_adv[AFI_IP][SAFI_MULTICAST]
9577 || p->afc_recv[AFI_IP][SAFI_MULTICAST]
9578 || p->afc_adv[AFI_IP6][SAFI_UNICAST]
9579 || p->afc_recv[AFI_IP6][SAFI_UNICAST]
9580 || p->afc_adv[AFI_IP6][SAFI_MULTICAST]
9581 || p->afc_recv[AFI_IP6][SAFI_MULTICAST]
9582 || p->afc_adv[AFI_IP6][SAFI_MPLS_VPN]
9583 || p->afc_recv[AFI_IP6][SAFI_MPLS_VPN]
9584 || p->afc_adv[AFI_IP6][SAFI_ENCAP]
9585 || p->afc_recv[AFI_IP6][SAFI_ENCAP]
9586 || p->afc_adv[AFI_IP6][SAFI_FLOWSPEC]
9587 || p->afc_recv[AFI_IP6][SAFI_FLOWSPEC]
9588 || p->afc_adv[AFI_IP][SAFI_ENCAP]
9589 || p->afc_recv[AFI_IP][SAFI_ENCAP]
9590 || p->afc_adv[AFI_IP][SAFI_FLOWSPEC]
9591 || p->afc_recv[AFI_IP][SAFI_FLOWSPEC]
9592 || p->afc_adv[AFI_IP][SAFI_MPLS_VPN]
9593 || p->afc_recv[AFI_IP][SAFI_MPLS_VPN]) {
9594 if (use_json) {
9595 json_object *json_cap = NULL;
9596
9597 json_cap = json_object_new_object();
9598
9599 /* AS4 */
9600 if (CHECK_FLAG(p->cap, PEER_CAP_AS4_RCV)
9601 || CHECK_FLAG(p->cap, PEER_CAP_AS4_ADV)) {
9602 if (CHECK_FLAG(p->cap, PEER_CAP_AS4_ADV)
9603 && CHECK_FLAG(p->cap,
9604 PEER_CAP_AS4_RCV))
9605 json_object_string_add(
9606 json_cap, "4byteAs",
9607 "advertisedAndReceived");
9608 else if (CHECK_FLAG(p->cap,
9609 PEER_CAP_AS4_ADV))
9610 json_object_string_add(
9611 json_cap, "4byteAs",
9612 "advertised");
9613 else if (CHECK_FLAG(p->cap,
9614 PEER_CAP_AS4_RCV))
9615 json_object_string_add(
9616 json_cap, "4byteAs",
9617 "received");
9618 }
9619
9620 /* AddPath */
9621 if (CHECK_FLAG(p->cap, PEER_CAP_ADDPATH_RCV)
9622 || CHECK_FLAG(p->cap,
9623 PEER_CAP_ADDPATH_ADV)) {
9624 json_object *json_add = NULL;
9625 const char *print_store;
9626
9627 json_add = json_object_new_object();
9628
9629 FOREACH_AFI_SAFI (afi, safi) {
9630 json_object *json_sub = NULL;
9631 json_sub =
9632 json_object_new_object();
9633 print_store = afi_safi_print(
9634 afi, safi);
9635
9636 if (CHECK_FLAG(
9637 p->af_cap[afi]
9638 [safi],
9639 PEER_CAP_ADDPATH_AF_TX_ADV)
9640 || CHECK_FLAG(
9641 p->af_cap[afi]
9642 [safi],
9643 PEER_CAP_ADDPATH_AF_TX_RCV)) {
9644 if (CHECK_FLAG(
9645 p->af_cap
9646 [afi]
9647 [safi],
9648 PEER_CAP_ADDPATH_AF_TX_ADV)
9649 && CHECK_FLAG(
9650 p->af_cap
9651 [afi]
9652 [safi],
9653 PEER_CAP_ADDPATH_AF_TX_RCV))
9654 json_object_boolean_true_add(
9655 json_sub,
9656 "txAdvertisedAndReceived");
9657 else if (
9658 CHECK_FLAG(
9659 p->af_cap
9660 [afi]
9661 [safi],
9662 PEER_CAP_ADDPATH_AF_TX_ADV))
9663 json_object_boolean_true_add(
9664 json_sub,
9665 "txAdvertised");
9666 else if (
9667 CHECK_FLAG(
9668 p->af_cap
9669 [afi]
9670 [safi],
9671 PEER_CAP_ADDPATH_AF_TX_RCV))
9672 json_object_boolean_true_add(
9673 json_sub,
9674 "txReceived");
9675 }
9676
9677 if (CHECK_FLAG(
9678 p->af_cap[afi]
9679 [safi],
9680 PEER_CAP_ADDPATH_AF_RX_ADV)
9681 || CHECK_FLAG(
9682 p->af_cap[afi]
9683 [safi],
9684 PEER_CAP_ADDPATH_AF_RX_RCV)) {
9685 if (CHECK_FLAG(
9686 p->af_cap
9687 [afi]
9688 [safi],
9689 PEER_CAP_ADDPATH_AF_RX_ADV)
9690 && CHECK_FLAG(
9691 p->af_cap
9692 [afi]
9693 [safi],
9694 PEER_CAP_ADDPATH_AF_RX_RCV))
9695 json_object_boolean_true_add(
9696 json_sub,
9697 "rxAdvertisedAndReceived");
9698 else if (
9699 CHECK_FLAG(
9700 p->af_cap
9701 [afi]
9702 [safi],
9703 PEER_CAP_ADDPATH_AF_RX_ADV))
9704 json_object_boolean_true_add(
9705 json_sub,
9706 "rxAdvertised");
9707 else if (
9708 CHECK_FLAG(
9709 p->af_cap
9710 [afi]
9711 [safi],
9712 PEER_CAP_ADDPATH_AF_RX_RCV))
9713 json_object_boolean_true_add(
9714 json_sub,
9715 "rxReceived");
9716 }
9717
9718 if (CHECK_FLAG(
9719 p->af_cap[afi]
9720 [safi],
9721 PEER_CAP_ADDPATH_AF_TX_ADV)
9722 || CHECK_FLAG(
9723 p->af_cap[afi]
9724 [safi],
9725 PEER_CAP_ADDPATH_AF_TX_RCV)
9726 || CHECK_FLAG(
9727 p->af_cap[afi]
9728 [safi],
9729 PEER_CAP_ADDPATH_AF_RX_ADV)
9730 || CHECK_FLAG(
9731 p->af_cap[afi]
9732 [safi],
9733 PEER_CAP_ADDPATH_AF_RX_RCV))
9734 json_object_object_add(
9735 json_add,
9736 print_store,
9737 json_sub);
9738 else
9739 json_object_free(
9740 json_sub);
9741 }
9742
9743 json_object_object_add(
9744 json_cap, "addPath", json_add);
9745 }
9746
9747 /* Dynamic */
9748 if (CHECK_FLAG(p->cap, PEER_CAP_DYNAMIC_RCV)
9749 || CHECK_FLAG(p->cap,
9750 PEER_CAP_DYNAMIC_ADV)) {
9751 if (CHECK_FLAG(p->cap,
9752 PEER_CAP_DYNAMIC_ADV)
9753 && CHECK_FLAG(p->cap,
9754 PEER_CAP_DYNAMIC_RCV))
9755 json_object_string_add(
9756 json_cap, "dynamic",
9757 "advertisedAndReceived");
9758 else if (CHECK_FLAG(
9759 p->cap,
9760 PEER_CAP_DYNAMIC_ADV))
9761 json_object_string_add(
9762 json_cap, "dynamic",
9763 "advertised");
9764 else if (CHECK_FLAG(
9765 p->cap,
9766 PEER_CAP_DYNAMIC_RCV))
9767 json_object_string_add(
9768 json_cap, "dynamic",
9769 "received");
9770 }
9771
9772 /* Extended nexthop */
9773 if (CHECK_FLAG(p->cap, PEER_CAP_ENHE_RCV)
9774 || CHECK_FLAG(p->cap, PEER_CAP_ENHE_ADV)) {
9775 json_object *json_nxt = NULL;
9776 const char *print_store;
9777
9778
9779 if (CHECK_FLAG(p->cap,
9780 PEER_CAP_ENHE_ADV)
9781 && CHECK_FLAG(p->cap,
9782 PEER_CAP_ENHE_RCV))
9783 json_object_string_add(
9784 json_cap,
9785 "extendedNexthop",
9786 "advertisedAndReceived");
9787 else if (CHECK_FLAG(p->cap,
9788 PEER_CAP_ENHE_ADV))
9789 json_object_string_add(
9790 json_cap,
9791 "extendedNexthop",
9792 "advertised");
9793 else if (CHECK_FLAG(p->cap,
9794 PEER_CAP_ENHE_RCV))
9795 json_object_string_add(
9796 json_cap,
9797 "extendedNexthop",
9798 "received");
9799
9800 if (CHECK_FLAG(p->cap,
9801 PEER_CAP_ENHE_RCV)) {
9802 json_nxt =
9803 json_object_new_object();
9804
9805 for (safi = SAFI_UNICAST;
9806 safi < SAFI_MAX; safi++) {
9807 if (CHECK_FLAG(
9808 p->af_cap
9809 [AFI_IP]
9810 [safi],
9811 PEER_CAP_ENHE_AF_RCV)) {
9812 print_store = afi_safi_print(
9813 AFI_IP,
9814 safi);
9815 json_object_string_add(
9816 json_nxt,
9817 print_store,
9818 "recieved"); /* misspelled for compatibility */
9819 }
9820 }
9821 json_object_object_add(
9822 json_cap,
9823 "extendedNexthopFamililesByPeer",
9824 json_nxt);
9825 }
9826 }
9827
9828 /* Route Refresh */
9829 if (CHECK_FLAG(p->cap, PEER_CAP_REFRESH_ADV)
9830 || CHECK_FLAG(p->cap,
9831 PEER_CAP_REFRESH_NEW_RCV)
9832 || CHECK_FLAG(p->cap,
9833 PEER_CAP_REFRESH_OLD_RCV)) {
9834 if (CHECK_FLAG(p->cap,
9835 PEER_CAP_REFRESH_ADV)
9836 && (CHECK_FLAG(
9837 p->cap,
9838 PEER_CAP_REFRESH_NEW_RCV)
9839 || CHECK_FLAG(
9840 p->cap,
9841 PEER_CAP_REFRESH_OLD_RCV))) {
9842 if (CHECK_FLAG(
9843 p->cap,
9844 PEER_CAP_REFRESH_OLD_RCV)
9845 && CHECK_FLAG(
9846 p->cap,
9847 PEER_CAP_REFRESH_NEW_RCV))
9848 json_object_string_add(
9849 json_cap,
9850 "routeRefresh",
9851 "advertisedAndReceivedOldNew");
9852 else {
9853 if (CHECK_FLAG(
9854 p->cap,
9855 PEER_CAP_REFRESH_OLD_RCV))
9856 json_object_string_add(
9857 json_cap,
9858 "routeRefresh",
9859 "advertisedAndReceivedOld");
9860 else
9861 json_object_string_add(
9862 json_cap,
9863 "routeRefresh",
9864 "advertisedAndReceivedNew");
9865 }
9866 } else if (
9867 CHECK_FLAG(
9868 p->cap,
9869 PEER_CAP_REFRESH_ADV))
9870 json_object_string_add(
9871 json_cap,
9872 "routeRefresh",
9873 "advertised");
9874 else if (
9875 CHECK_FLAG(
9876 p->cap,
9877 PEER_CAP_REFRESH_NEW_RCV)
9878 || CHECK_FLAG(
9879 p->cap,
9880 PEER_CAP_REFRESH_OLD_RCV))
9881 json_object_string_add(
9882 json_cap,
9883 "routeRefresh",
9884 "received");
9885 }
9886
9887 /* Multiprotocol Extensions */
9888 json_object *json_multi = NULL;
9889 json_multi = json_object_new_object();
9890
9891 FOREACH_AFI_SAFI (afi, safi) {
9892 if (p->afc_adv[afi][safi]
9893 || p->afc_recv[afi][safi]) {
9894 json_object *json_exten = NULL;
9895 json_exten =
9896 json_object_new_object();
9897
9898 if (p->afc_adv[afi][safi]
9899 && p->afc_recv[afi][safi])
9900 json_object_boolean_true_add(
9901 json_exten,
9902 "advertisedAndReceived");
9903 else if (p->afc_adv[afi][safi])
9904 json_object_boolean_true_add(
9905 json_exten,
9906 "advertised");
9907 else if (p->afc_recv[afi][safi])
9908 json_object_boolean_true_add(
9909 json_exten,
9910 "received");
9911
9912 json_object_object_add(
9913 json_multi,
9914 afi_safi_print(afi,
9915 safi),
9916 json_exten);
9917 }
9918 }
9919 json_object_object_add(
9920 json_cap, "multiprotocolExtensions",
9921 json_multi);
9922
9923 /* Hostname capabilities */
9924 json_object *json_hname = NULL;
9925
9926 json_hname = json_object_new_object();
9927
9928 if (CHECK_FLAG(p->cap, PEER_CAP_HOSTNAME_ADV)) {
9929 json_object_string_add(
9930 json_hname, "advHostName",
9931 bgp->peer_self->hostname
9932 ? bgp->peer_self
9933 ->hostname
9934 : "n/a");
9935 json_object_string_add(
9936 json_hname, "advDomainName",
9937 bgp->peer_self->domainname
9938 ? bgp->peer_self
9939 ->domainname
9940 : "n/a");
9941 }
9942
9943
9944 if (CHECK_FLAG(p->cap, PEER_CAP_HOSTNAME_RCV)) {
9945 json_object_string_add(
9946 json_hname, "rcvHostName",
9947 p->hostname ? p->hostname
9948 : "n/a");
9949 json_object_string_add(
9950 json_hname, "rcvDomainName",
9951 p->domainname ? p->domainname
9952 : "n/a");
9953 }
9954
9955 json_object_object_add(json_cap, "hostName",
9956 json_hname);
9957
9958 /* Gracefull Restart */
9959 if (CHECK_FLAG(p->cap, PEER_CAP_RESTART_RCV)
9960 || CHECK_FLAG(p->cap,
9961 PEER_CAP_RESTART_ADV)) {
9962 if (CHECK_FLAG(p->cap,
9963 PEER_CAP_RESTART_ADV)
9964 && CHECK_FLAG(p->cap,
9965 PEER_CAP_RESTART_RCV))
9966 json_object_string_add(
9967 json_cap,
9968 "gracefulRestart",
9969 "advertisedAndReceived");
9970 else if (CHECK_FLAG(
9971 p->cap,
9972 PEER_CAP_RESTART_ADV))
9973 json_object_string_add(
9974 json_cap,
9975 "gracefulRestartCapability",
9976 "advertised");
9977 else if (CHECK_FLAG(
9978 p->cap,
9979 PEER_CAP_RESTART_RCV))
9980 json_object_string_add(
9981 json_cap,
9982 "gracefulRestartCapability",
9983 "received");
9984
9985 if (CHECK_FLAG(p->cap,
9986 PEER_CAP_RESTART_RCV)) {
9987 int restart_af_count = 0;
9988 json_object *json_restart =
9989 NULL;
9990 json_restart =
9991 json_object_new_object();
9992
9993 json_object_int_add(
9994 json_cap,
9995 "gracefulRestartRemoteTimerMsecs",
9996 p->v_gr_restart * 1000);
9997
9998 FOREACH_AFI_SAFI (afi, safi) {
9999 if (CHECK_FLAG(
10000 p->af_cap
10001 [afi]
10002 [safi],
10003 PEER_CAP_RESTART_AF_RCV)) {
10004 json_object *
10005 json_sub =
10006 NULL;
10007 json_sub =
10008 json_object_new_object();
10009
10010 if (CHECK_FLAG(
10011 p->af_cap
10012 [afi]
10013 [safi],
10014 PEER_CAP_RESTART_AF_PRESERVE_RCV))
10015 json_object_boolean_true_add(
10016 json_sub,
10017 "preserved");
10018 restart_af_count++;
10019 json_object_object_add(
10020 json_restart,
10021 afi_safi_print(
10022 afi,
10023 safi),
10024 json_sub);
10025 }
10026 }
10027 if (!restart_af_count) {
10028 json_object_string_add(
10029 json_cap,
10030 "addressFamiliesByPeer",
10031 "none");
10032 json_object_free(
10033 json_restart);
10034 } else
10035 json_object_object_add(
10036 json_cap,
10037 "addressFamiliesByPeer",
10038 json_restart);
10039 }
10040 }
10041 json_object_object_add(json_neigh,
10042 "neighborCapabilities",
10043 json_cap);
10044 } else {
10045 vty_out(vty, " Neighbor capabilities:\n");
10046
10047 /* AS4 */
10048 if (CHECK_FLAG(p->cap, PEER_CAP_AS4_RCV)
10049 || CHECK_FLAG(p->cap, PEER_CAP_AS4_ADV)) {
10050 vty_out(vty, " 4 Byte AS:");
10051 if (CHECK_FLAG(p->cap,
10052 PEER_CAP_AS4_ADV))
10053 vty_out(vty, " advertised");
10054 if (CHECK_FLAG(p->cap,
10055 PEER_CAP_AS4_RCV))
10056 vty_out(vty, " %sreceived",
10057 CHECK_FLAG(
10058 p->cap,
10059 PEER_CAP_AS4_ADV)
10060 ? "and "
10061 : "");
10062 vty_out(vty, "\n");
10063 }
10064
10065 /* AddPath */
10066 if (CHECK_FLAG(p->cap, PEER_CAP_ADDPATH_RCV)
10067 || CHECK_FLAG(p->cap,
10068 PEER_CAP_ADDPATH_ADV)) {
10069 vty_out(vty, " AddPath:\n");
10070
10071 FOREACH_AFI_SAFI (afi, safi) {
10072 if (CHECK_FLAG(
10073 p->af_cap[afi]
10074 [safi],
10075 PEER_CAP_ADDPATH_AF_TX_ADV)
10076 || CHECK_FLAG(
10077 p->af_cap[afi]
10078 [safi],
10079 PEER_CAP_ADDPATH_AF_TX_RCV)) {
10080 vty_out(vty,
10081 " %s: TX ",
10082 afi_safi_print(
10083 afi,
10084 safi));
10085
10086 if (CHECK_FLAG(
10087 p->af_cap
10088 [afi]
10089 [safi],
10090 PEER_CAP_ADDPATH_AF_TX_ADV))
10091 vty_out(vty,
10092 "advertised %s",
10093 afi_safi_print(
10094 afi,
10095 safi));
10096
10097 if (CHECK_FLAG(
10098 p->af_cap
10099 [afi]
10100 [safi],
10101 PEER_CAP_ADDPATH_AF_TX_RCV))
10102 vty_out(vty,
10103 "%sreceived",
10104 CHECK_FLAG(
10105 p->af_cap
10106 [afi]
10107 [safi],
10108 PEER_CAP_ADDPATH_AF_TX_ADV)
10109 ? " and "
10110 : "");
10111
10112 vty_out(vty, "\n");
10113 }
10114
10115 if (CHECK_FLAG(
10116 p->af_cap[afi]
10117 [safi],
10118 PEER_CAP_ADDPATH_AF_RX_ADV)
10119 || CHECK_FLAG(
10120 p->af_cap[afi]
10121 [safi],
10122 PEER_CAP_ADDPATH_AF_RX_RCV)) {
10123 vty_out(vty,
10124 " %s: RX ",
10125 afi_safi_print(
10126 afi,
10127 safi));
10128
10129 if (CHECK_FLAG(
10130 p->af_cap
10131 [afi]
10132 [safi],
10133 PEER_CAP_ADDPATH_AF_RX_ADV))
10134 vty_out(vty,
10135 "advertised %s",
10136 afi_safi_print(
10137 afi,
10138 safi));
10139
10140 if (CHECK_FLAG(
10141 p->af_cap
10142 [afi]
10143 [safi],
10144 PEER_CAP_ADDPATH_AF_RX_RCV))
10145 vty_out(vty,
10146 "%sreceived",
10147 CHECK_FLAG(
10148 p->af_cap
10149 [afi]
10150 [safi],
10151 PEER_CAP_ADDPATH_AF_RX_ADV)
10152 ? " and "
10153 : "");
10154
10155 vty_out(vty, "\n");
10156 }
10157 }
10158 }
10159
10160 /* Dynamic */
10161 if (CHECK_FLAG(p->cap, PEER_CAP_DYNAMIC_RCV)
10162 || CHECK_FLAG(p->cap,
10163 PEER_CAP_DYNAMIC_ADV)) {
10164 vty_out(vty, " Dynamic:");
10165 if (CHECK_FLAG(p->cap,
10166 PEER_CAP_DYNAMIC_ADV))
10167 vty_out(vty, " advertised");
10168 if (CHECK_FLAG(p->cap,
10169 PEER_CAP_DYNAMIC_RCV))
10170 vty_out(vty, " %sreceived",
10171 CHECK_FLAG(
10172 p->cap,
10173 PEER_CAP_DYNAMIC_ADV)
10174 ? "and "
10175 : "");
10176 vty_out(vty, "\n");
10177 }
10178
10179 /* Extended nexthop */
10180 if (CHECK_FLAG(p->cap, PEER_CAP_ENHE_RCV)
10181 || CHECK_FLAG(p->cap, PEER_CAP_ENHE_ADV)) {
10182 vty_out(vty, " Extended nexthop:");
10183 if (CHECK_FLAG(p->cap,
10184 PEER_CAP_ENHE_ADV))
10185 vty_out(vty, " advertised");
10186 if (CHECK_FLAG(p->cap,
10187 PEER_CAP_ENHE_RCV))
10188 vty_out(vty, " %sreceived",
10189 CHECK_FLAG(
10190 p->cap,
10191 PEER_CAP_ENHE_ADV)
10192 ? "and "
10193 : "");
10194 vty_out(vty, "\n");
10195
10196 if (CHECK_FLAG(p->cap,
10197 PEER_CAP_ENHE_RCV)) {
10198 vty_out(vty,
10199 " Address families by peer:\n ");
10200 for (safi = SAFI_UNICAST;
10201 safi < SAFI_MAX; safi++)
10202 if (CHECK_FLAG(
10203 p->af_cap
10204 [AFI_IP]
10205 [safi],
10206 PEER_CAP_ENHE_AF_RCV))
10207 vty_out(vty,
10208 " %s\n",
10209 afi_safi_print(
10210 AFI_IP,
10211 safi));
10212 }
10213 }
10214
10215 /* Route Refresh */
10216 if (CHECK_FLAG(p->cap, PEER_CAP_REFRESH_ADV)
10217 || CHECK_FLAG(p->cap,
10218 PEER_CAP_REFRESH_NEW_RCV)
10219 || CHECK_FLAG(p->cap,
10220 PEER_CAP_REFRESH_OLD_RCV)) {
10221 vty_out(vty, " Route refresh:");
10222 if (CHECK_FLAG(p->cap,
10223 PEER_CAP_REFRESH_ADV))
10224 vty_out(vty, " advertised");
10225 if (CHECK_FLAG(p->cap,
10226 PEER_CAP_REFRESH_NEW_RCV)
10227 || CHECK_FLAG(
10228 p->cap,
10229 PEER_CAP_REFRESH_OLD_RCV))
10230 vty_out(vty, " %sreceived(%s)",
10231 CHECK_FLAG(
10232 p->cap,
10233 PEER_CAP_REFRESH_ADV)
10234 ? "and "
10235 : "",
10236 (CHECK_FLAG(
10237 p->cap,
10238 PEER_CAP_REFRESH_OLD_RCV)
10239 && CHECK_FLAG(
10240 p->cap,
10241 PEER_CAP_REFRESH_NEW_RCV))
10242 ? "old & new"
10243 : CHECK_FLAG(
10244 p->cap,
10245 PEER_CAP_REFRESH_OLD_RCV)
10246 ? "old"
10247 : "new");
10248
10249 vty_out(vty, "\n");
10250 }
10251
10252 /* Multiprotocol Extensions */
10253 FOREACH_AFI_SAFI (afi, safi)
10254 if (p->afc_adv[afi][safi]
10255 || p->afc_recv[afi][safi]) {
10256 vty_out(vty,
10257 " Address Family %s:",
10258 afi_safi_print(afi,
10259 safi));
10260 if (p->afc_adv[afi][safi])
10261 vty_out(vty,
10262 " advertised");
10263 if (p->afc_recv[afi][safi])
10264 vty_out(vty,
10265 " %sreceived",
10266 p->afc_adv[afi]
10267 [safi]
10268 ? "and "
10269 : "");
10270 vty_out(vty, "\n");
10271 }
10272
10273 /* Hostname capability */
10274 vty_out(vty, " Hostname Capability:");
10275
10276 if (CHECK_FLAG(p->cap, PEER_CAP_HOSTNAME_ADV)) {
10277 vty_out(vty,
10278 " advertised (name: %s,domain name: %s)",
10279 bgp->peer_self->hostname
10280 ? bgp->peer_self
10281 ->hostname
10282 : "n/a",
10283 bgp->peer_self->domainname
10284 ? bgp->peer_self
10285 ->domainname
10286 : "n/a");
10287 } else {
10288 vty_out(vty, " not advertised");
10289 }
10290
10291 if (CHECK_FLAG(p->cap, PEER_CAP_HOSTNAME_RCV)) {
10292 vty_out(vty,
10293 " received (name: %s,domain name: %s)",
10294 p->hostname ? p->hostname
10295 : "n/a",
10296 p->domainname ? p->domainname
10297 : "n/a");
10298 } else {
10299 vty_out(vty, " not received");
10300 }
10301
10302 vty_out(vty, "\n");
10303
10304 /* Gracefull Restart */
10305 if (CHECK_FLAG(p->cap, PEER_CAP_RESTART_RCV)
10306 || CHECK_FLAG(p->cap,
10307 PEER_CAP_RESTART_ADV)) {
10308 vty_out(vty,
10309 " Graceful Restart Capabilty:");
10310 if (CHECK_FLAG(p->cap,
10311 PEER_CAP_RESTART_ADV))
10312 vty_out(vty, " advertised");
10313 if (CHECK_FLAG(p->cap,
10314 PEER_CAP_RESTART_RCV))
10315 vty_out(vty, " %sreceived",
10316 CHECK_FLAG(
10317 p->cap,
10318 PEER_CAP_RESTART_ADV)
10319 ? "and "
10320 : "");
10321 vty_out(vty, "\n");
10322
10323 if (CHECK_FLAG(p->cap,
10324 PEER_CAP_RESTART_RCV)) {
10325 int restart_af_count = 0;
10326
10327 vty_out(vty,
10328 " Remote Restart timer is %d seconds\n",
10329 p->v_gr_restart);
10330 vty_out(vty,
10331 " Address families by peer:\n ");
10332
10333 FOREACH_AFI_SAFI (afi, safi)
10334 if (CHECK_FLAG(
10335 p->af_cap
10336 [afi]
10337 [safi],
10338 PEER_CAP_RESTART_AF_RCV)) {
10339 vty_out(vty,
10340 "%s%s(%s)",
10341 restart_af_count
10342 ? ", "
10343 : "",
10344 afi_safi_print(
10345 afi,
10346 safi),
10347 CHECK_FLAG(
10348 p->af_cap
10349 [afi]
10350 [safi],
10351 PEER_CAP_RESTART_AF_PRESERVE_RCV)
10352 ? "preserved"
10353 : "not preserved");
10354 restart_af_count++;
10355 }
10356 if (!restart_af_count)
10357 vty_out(vty, "none");
10358 vty_out(vty, "\n");
10359 }
10360 }
10361 }
10362 }
10363 }
10364
10365 /* graceful restart information */
10366 if (CHECK_FLAG(p->cap, PEER_CAP_RESTART_RCV) || p->t_gr_restart
10367 || p->t_gr_stale) {
10368 json_object *json_grace = NULL;
10369 json_object *json_grace_send = NULL;
10370 json_object *json_grace_recv = NULL;
10371 int eor_send_af_count = 0;
10372 int eor_receive_af_count = 0;
10373
10374 if (use_json) {
10375 json_grace = json_object_new_object();
10376 json_grace_send = json_object_new_object();
10377 json_grace_recv = json_object_new_object();
10378
10379 if (p->status == Established) {
10380 FOREACH_AFI_SAFI (afi, safi) {
10381 if (CHECK_FLAG(p->af_sflags[afi][safi],
10382 PEER_STATUS_EOR_SEND)) {
10383 json_object_boolean_true_add(
10384 json_grace_send,
10385 afi_safi_print(afi,
10386 safi));
10387 eor_send_af_count++;
10388 }
10389 }
10390 FOREACH_AFI_SAFI (afi, safi) {
10391 if (CHECK_FLAG(
10392 p->af_sflags[afi][safi],
10393 PEER_STATUS_EOR_RECEIVED)) {
10394 json_object_boolean_true_add(
10395 json_grace_recv,
10396 afi_safi_print(afi,
10397 safi));
10398 eor_receive_af_count++;
10399 }
10400 }
10401 }
10402
10403 json_object_object_add(json_grace, "endOfRibSend",
10404 json_grace_send);
10405 json_object_object_add(json_grace, "endOfRibRecv",
10406 json_grace_recv);
10407
10408 if (p->t_gr_restart)
10409 json_object_int_add(json_grace,
10410 "gracefulRestartTimerMsecs",
10411 thread_timer_remain_second(
10412 p->t_gr_restart)
10413 * 1000);
10414
10415 if (p->t_gr_stale)
10416 json_object_int_add(
10417 json_grace,
10418 "gracefulStalepathTimerMsecs",
10419 thread_timer_remain_second(
10420 p->t_gr_stale)
10421 * 1000);
10422
10423 json_object_object_add(
10424 json_neigh, "gracefulRestartInfo", json_grace);
10425 } else {
10426 vty_out(vty, " Graceful restart information:\n");
10427 if (p->status == Established) {
10428 vty_out(vty, " End-of-RIB send: ");
10429 FOREACH_AFI_SAFI (afi, safi) {
10430 if (CHECK_FLAG(p->af_sflags[afi][safi],
10431 PEER_STATUS_EOR_SEND)) {
10432 vty_out(vty, "%s%s",
10433 eor_send_af_count ? ", "
10434 : "",
10435 afi_safi_print(afi,
10436 safi));
10437 eor_send_af_count++;
10438 }
10439 }
10440 vty_out(vty, "\n");
10441 vty_out(vty, " End-of-RIB received: ");
10442 FOREACH_AFI_SAFI (afi, safi) {
10443 if (CHECK_FLAG(
10444 p->af_sflags[afi][safi],
10445 PEER_STATUS_EOR_RECEIVED)) {
10446 vty_out(vty, "%s%s",
10447 eor_receive_af_count
10448 ? ", "
10449 : "",
10450 afi_safi_print(afi,
10451 safi));
10452 eor_receive_af_count++;
10453 }
10454 }
10455 vty_out(vty, "\n");
10456 }
10457
10458 if (p->t_gr_restart)
10459 vty_out(vty,
10460 " The remaining time of restart timer is %ld\n",
10461 thread_timer_remain_second(
10462 p->t_gr_restart));
10463
10464 if (p->t_gr_stale)
10465 vty_out(vty,
10466 " The remaining time of stalepath timer is %ld\n",
10467 thread_timer_remain_second(
10468 p->t_gr_stale));
10469 }
10470 }
10471 if (use_json) {
10472 json_object *json_stat = NULL;
10473 json_stat = json_object_new_object();
10474 /* Packet counts. */
10475 json_object_int_add(json_stat, "depthInq", 0);
10476 json_object_int_add(json_stat, "depthOutq",
10477 (unsigned long)p->obuf->count);
10478 json_object_int_add(json_stat, "opensSent",
10479 atomic_load_explicit(&p->open_out,
10480 memory_order_relaxed));
10481 json_object_int_add(json_stat, "opensRecv",
10482 atomic_load_explicit(&p->open_in,
10483 memory_order_relaxed));
10484 json_object_int_add(json_stat, "notificationsSent",
10485 atomic_load_explicit(&p->notify_out,
10486 memory_order_relaxed));
10487 json_object_int_add(json_stat, "notificationsRecv",
10488 atomic_load_explicit(&p->notify_in,
10489 memory_order_relaxed));
10490 json_object_int_add(json_stat, "updatesSent",
10491 atomic_load_explicit(&p->update_out,
10492 memory_order_relaxed));
10493 json_object_int_add(json_stat, "updatesRecv",
10494 atomic_load_explicit(&p->update_in,
10495 memory_order_relaxed));
10496 json_object_int_add(json_stat, "keepalivesSent",
10497 atomic_load_explicit(&p->keepalive_out,
10498 memory_order_relaxed));
10499 json_object_int_add(json_stat, "keepalivesRecv",
10500 atomic_load_explicit(&p->keepalive_in,
10501 memory_order_relaxed));
10502 json_object_int_add(json_stat, "routeRefreshSent",
10503 atomic_load_explicit(&p->refresh_out,
10504 memory_order_relaxed));
10505 json_object_int_add(json_stat, "routeRefreshRecv",
10506 atomic_load_explicit(&p->refresh_in,
10507 memory_order_relaxed));
10508 json_object_int_add(json_stat, "capabilitySent",
10509 atomic_load_explicit(&p->dynamic_cap_out,
10510 memory_order_relaxed));
10511 json_object_int_add(json_stat, "capabilityRecv",
10512 atomic_load_explicit(&p->dynamic_cap_in,
10513 memory_order_relaxed));
10514 json_object_int_add(json_stat, "totalSent", PEER_TOTAL_TX(p));
10515 json_object_int_add(json_stat, "totalRecv", PEER_TOTAL_RX(p));
10516 json_object_object_add(json_neigh, "messageStats", json_stat);
10517 } else {
10518 /* Packet counts. */
10519 vty_out(vty, " Message statistics:\n");
10520 vty_out(vty, " Inq depth is 0\n");
10521 vty_out(vty, " Outq depth is %lu\n",
10522 (unsigned long)p->obuf->count);
10523 vty_out(vty, " Sent Rcvd\n");
10524 vty_out(vty, " Opens: %10d %10d\n",
10525 atomic_load_explicit(&p->open_out,
10526 memory_order_relaxed),
10527 atomic_load_explicit(&p->open_in,
10528 memory_order_relaxed));
10529 vty_out(vty, " Notifications: %10d %10d\n",
10530 atomic_load_explicit(&p->notify_out,
10531 memory_order_relaxed),
10532 atomic_load_explicit(&p->notify_in,
10533 memory_order_relaxed));
10534 vty_out(vty, " Updates: %10d %10d\n",
10535 atomic_load_explicit(&p->update_out,
10536 memory_order_relaxed),
10537 atomic_load_explicit(&p->update_in,
10538 memory_order_relaxed));
10539 vty_out(vty, " Keepalives: %10d %10d\n",
10540 atomic_load_explicit(&p->keepalive_out,
10541 memory_order_relaxed),
10542 atomic_load_explicit(&p->keepalive_in,
10543 memory_order_relaxed));
10544 vty_out(vty, " Route Refresh: %10d %10d\n",
10545 atomic_load_explicit(&p->refresh_out,
10546 memory_order_relaxed),
10547 atomic_load_explicit(&p->refresh_in,
10548 memory_order_relaxed));
10549 vty_out(vty, " Capability: %10d %10d\n",
10550 atomic_load_explicit(&p->dynamic_cap_out,
10551 memory_order_relaxed),
10552 atomic_load_explicit(&p->dynamic_cap_in,
10553 memory_order_relaxed));
10554 vty_out(vty, " Total: %10d %10d\n", PEER_TOTAL_TX(p),
10555 PEER_TOTAL_RX(p));
10556 }
10557
10558 if (use_json) {
10559 /* advertisement-interval */
10560 json_object_int_add(json_neigh,
10561 "minBtwnAdvertisementRunsTimerMsecs",
10562 p->v_routeadv * 1000);
10563
10564 /* Update-source. */
10565 if (p->update_if || p->update_source) {
10566 if (p->update_if)
10567 json_object_string_add(json_neigh,
10568 "updateSource",
10569 p->update_if);
10570 else if (p->update_source)
10571 json_object_string_add(
10572 json_neigh, "updateSource",
10573 sockunion2str(p->update_source, buf1,
10574 SU_ADDRSTRLEN));
10575 }
10576 } else {
10577 /* advertisement-interval */
10578 vty_out(vty,
10579 " Minimum time between advertisement runs is %d seconds\n",
10580 p->v_routeadv);
10581
10582 /* Update-source. */
10583 if (p->update_if || p->update_source) {
10584 vty_out(vty, " Update source is ");
10585 if (p->update_if)
10586 vty_out(vty, "%s", p->update_if);
10587 else if (p->update_source)
10588 vty_out(vty, "%s",
10589 sockunion2str(p->update_source, buf1,
10590 SU_ADDRSTRLEN));
10591 vty_out(vty, "\n");
10592 }
10593
10594 vty_out(vty, "\n");
10595 }
10596
10597 /* Address Family Information */
10598 json_object *json_hold = NULL;
10599
10600 if (use_json)
10601 json_hold = json_object_new_object();
10602
10603 FOREACH_AFI_SAFI (afi, safi)
10604 if (p->afc[afi][safi])
10605 bgp_show_peer_afi(vty, p, afi, safi, use_json,
10606 json_hold);
10607
10608 if (use_json) {
10609 json_object_object_add(json_neigh, "addressFamilyInfo",
10610 json_hold);
10611 json_object_int_add(json_neigh, "connectionsEstablished",
10612 p->established);
10613 json_object_int_add(json_neigh, "connectionsDropped",
10614 p->dropped);
10615 } else
10616 vty_out(vty, " Connections established %d; dropped %d\n",
10617 p->established, p->dropped);
10618
10619 if (!p->last_reset) {
10620 if (use_json)
10621 json_object_string_add(json_neigh, "lastReset",
10622 "never");
10623 else
10624 vty_out(vty, " Last reset never\n");
10625 } else {
10626 if (use_json) {
10627 time_t uptime;
10628 struct tm *tm;
10629
10630 uptime = bgp_clock();
10631 uptime -= p->resettime;
10632 tm = gmtime(&uptime);
10633 json_object_int_add(json_neigh, "lastResetTimerMsecs",
10634 (tm->tm_sec * 1000)
10635 + (tm->tm_min * 60000)
10636 + (tm->tm_hour * 3600000));
10637 json_object_string_add(
10638 json_neigh, "lastResetDueTo",
10639 peer_down_str[(int)p->last_reset]);
10640 if (p->last_reset == PEER_DOWN_NOTIFY_SEND
10641 || p->last_reset == PEER_DOWN_NOTIFY_RECEIVED) {
10642 char errorcodesubcode_hexstr[5];
10643 char errorcodesubcode_str[256];
10644
10645 code_str = bgp_notify_code_str(p->notify.code);
10646 subcode_str = bgp_notify_subcode_str(
10647 p->notify.code, p->notify.subcode);
10648
10649 sprintf(errorcodesubcode_hexstr, "%02X%02X",
10650 p->notify.code, p->notify.subcode);
10651 json_object_string_add(json_neigh,
10652 "lastErrorCodeSubcode",
10653 errorcodesubcode_hexstr);
10654 snprintf(errorcodesubcode_str, 255, "%s%s",
10655 code_str, subcode_str);
10656 json_object_string_add(json_neigh,
10657 "lastNotificationReason",
10658 errorcodesubcode_str);
10659 if (p->last_reset == PEER_DOWN_NOTIFY_RECEIVED
10660 && p->notify.code == BGP_NOTIFY_CEASE
10661 && (p->notify.subcode
10662 == BGP_NOTIFY_CEASE_ADMIN_SHUTDOWN
10663 || p->notify.subcode
10664 == BGP_NOTIFY_CEASE_ADMIN_RESET)
10665 && p->notify.length) {
10666 char msgbuf[1024];
10667 const char *msg_str;
10668
10669 msg_str = bgp_notify_admin_message(
10670 msgbuf, sizeof(msgbuf),
10671 (uint8_t *)p->notify.data,
10672 p->notify.length);
10673 if (msg_str)
10674 json_object_string_add(
10675 json_neigh,
10676 "lastShutdownDescription",
10677 msg_str);
10678 }
10679 }
10680 } else {
10681 vty_out(vty, " Last reset %s, ",
10682 peer_uptime(p->resettime, timebuf,
10683 BGP_UPTIME_LEN, 0, NULL));
10684
10685 if (p->last_reset == PEER_DOWN_NOTIFY_SEND
10686 || p->last_reset == PEER_DOWN_NOTIFY_RECEIVED) {
10687 code_str = bgp_notify_code_str(p->notify.code);
10688 subcode_str = bgp_notify_subcode_str(
10689 p->notify.code, p->notify.subcode);
10690 vty_out(vty, "due to NOTIFICATION %s (%s%s)\n",
10691 p->last_reset == PEER_DOWN_NOTIFY_SEND
10692 ? "sent"
10693 : "received",
10694 code_str, subcode_str);
10695 if (p->last_reset == PEER_DOWN_NOTIFY_RECEIVED
10696 && p->notify.code == BGP_NOTIFY_CEASE
10697 && (p->notify.subcode
10698 == BGP_NOTIFY_CEASE_ADMIN_SHUTDOWN
10699 || p->notify.subcode
10700 == BGP_NOTIFY_CEASE_ADMIN_RESET)
10701 && p->notify.length) {
10702 char msgbuf[1024];
10703 const char *msg_str;
10704
10705 msg_str = bgp_notify_admin_message(
10706 msgbuf, sizeof(msgbuf),
10707 (uint8_t *)p->notify.data,
10708 p->notify.length);
10709 if (msg_str)
10710 vty_out(vty,
10711 " Message: \"%s\"\n",
10712 msg_str);
10713 }
10714 } else {
10715 vty_out(vty, "due to %s\n",
10716 peer_down_str[(int)p->last_reset]);
10717 }
10718
10719 if (p->last_reset_cause_size) {
10720 msg = p->last_reset_cause;
10721 vty_out(vty,
10722 " Message received that caused BGP to send a NOTIFICATION:\n ");
10723 for (i = 1; i <= p->last_reset_cause_size;
10724 i++) {
10725 vty_out(vty, "%02X", *msg++);
10726
10727 if (i != p->last_reset_cause_size) {
10728 if (i % 16 == 0) {
10729 vty_out(vty, "\n ");
10730 } else if (i % 4 == 0) {
10731 vty_out(vty, " ");
10732 }
10733 }
10734 }
10735 vty_out(vty, "\n");
10736 }
10737 }
10738 }
10739
10740 if (CHECK_FLAG(p->sflags, PEER_STATUS_PREFIX_OVERFLOW)) {
10741 if (use_json)
10742 json_object_boolean_true_add(json_neigh,
10743 "prefixesConfigExceedMax");
10744 else
10745 vty_out(vty,
10746 " Peer had exceeded the max. no. of prefixes configured.\n");
10747
10748 if (p->t_pmax_restart) {
10749 if (use_json) {
10750 json_object_boolean_true_add(
10751 json_neigh, "reducePrefixNumFrom");
10752 json_object_int_add(json_neigh,
10753 "restartInTimerMsec",
10754 thread_timer_remain_second(
10755 p->t_pmax_restart)
10756 * 1000);
10757 } else
10758 vty_out(vty,
10759 " Reduce the no. of prefix from %s, will restart in %ld seconds\n",
10760 p->host, thread_timer_remain_second(
10761 p->t_pmax_restart));
10762 } else {
10763 if (use_json)
10764 json_object_boolean_true_add(
10765 json_neigh,
10766 "reducePrefixNumAndClearIpBgp");
10767 else
10768 vty_out(vty,
10769 " Reduce the no. of prefix and clear ip bgp %s to restore peering\n",
10770 p->host);
10771 }
10772 }
10773
10774 /* EBGP Multihop and GTSM */
10775 if (p->sort != BGP_PEER_IBGP) {
10776 if (use_json) {
10777 if (p->gtsm_hops > 0)
10778 json_object_int_add(json_neigh,
10779 "externalBgpNbrMaxHopsAway",
10780 p->gtsm_hops);
10781 else if (p->ttl > 1)
10782 json_object_int_add(json_neigh,
10783 "externalBgpNbrMaxHopsAway",
10784 p->ttl);
10785 } else {
10786 if (p->gtsm_hops > 0)
10787 vty_out(vty,
10788 " External BGP neighbor may be up to %d hops away.\n",
10789 p->gtsm_hops);
10790 else if (p->ttl > 1)
10791 vty_out(vty,
10792 " External BGP neighbor may be up to %d hops away.\n",
10793 p->ttl);
10794 }
10795 } else {
10796 if (p->gtsm_hops > 0) {
10797 if (use_json)
10798 json_object_int_add(json_neigh,
10799 "internalBgpNbrMaxHopsAway",
10800 p->gtsm_hops);
10801 else
10802 vty_out(vty,
10803 " Internal BGP neighbor may be up to %d hops away.\n",
10804 p->gtsm_hops);
10805 }
10806 }
10807
10808 /* Local address. */
10809 if (p->su_local) {
10810 if (use_json) {
10811 json_object_string_add(json_neigh, "hostLocal",
10812 sockunion2str(p->su_local, buf1,
10813 SU_ADDRSTRLEN));
10814 json_object_int_add(json_neigh, "portLocal",
10815 ntohs(p->su_local->sin.sin_port));
10816 } else
10817 vty_out(vty, "Local host: %s, Local port: %d\n",
10818 sockunion2str(p->su_local, buf1, SU_ADDRSTRLEN),
10819 ntohs(p->su_local->sin.sin_port));
10820 }
10821
10822 /* Remote address. */
10823 if (p->su_remote) {
10824 if (use_json) {
10825 json_object_string_add(json_neigh, "hostForeign",
10826 sockunion2str(p->su_remote, buf1,
10827 SU_ADDRSTRLEN));
10828 json_object_int_add(json_neigh, "portForeign",
10829 ntohs(p->su_remote->sin.sin_port));
10830 } else
10831 vty_out(vty, "Foreign host: %s, Foreign port: %d\n",
10832 sockunion2str(p->su_remote, buf1,
10833 SU_ADDRSTRLEN),
10834 ntohs(p->su_remote->sin.sin_port));
10835 }
10836
10837 /* Nexthop display. */
10838 if (p->su_local) {
10839 if (use_json) {
10840 json_object_string_add(json_neigh, "nexthop",
10841 inet_ntop(AF_INET,
10842 &p->nexthop.v4, buf1,
10843 sizeof(buf1)));
10844 json_object_string_add(json_neigh, "nexthopGlobal",
10845 inet_ntop(AF_INET6,
10846 &p->nexthop.v6_global,
10847 buf1, sizeof(buf1)));
10848 json_object_string_add(json_neigh, "nexthopLocal",
10849 inet_ntop(AF_INET6,
10850 &p->nexthop.v6_local,
10851 buf1, sizeof(buf1)));
10852 if (p->shared_network)
10853 json_object_string_add(json_neigh,
10854 "bgpConnection",
10855 "sharedNetwork");
10856 else
10857 json_object_string_add(json_neigh,
10858 "bgpConnection",
10859 "nonSharedNetwork");
10860 } else {
10861 vty_out(vty, "Nexthop: %s\n",
10862 inet_ntop(AF_INET, &p->nexthop.v4, buf1,
10863 sizeof(buf1)));
10864 vty_out(vty, "Nexthop global: %s\n",
10865 inet_ntop(AF_INET6, &p->nexthop.v6_global, buf1,
10866 sizeof(buf1)));
10867 vty_out(vty, "Nexthop local: %s\n",
10868 inet_ntop(AF_INET6, &p->nexthop.v6_local, buf1,
10869 sizeof(buf1)));
10870 vty_out(vty, "BGP connection: %s\n",
10871 p->shared_network ? "shared network"
10872 : "non shared network");
10873 }
10874 }
10875
10876 /* Timer information. */
10877 if (use_json) {
10878 json_object_int_add(json_neigh, "connectRetryTimer",
10879 p->v_connect);
10880 if (p->status == Established && p->rtt)
10881 json_object_int_add(json_neigh, "estimatedRttInMsecs",
10882 p->rtt);
10883 if (p->t_start)
10884 json_object_int_add(
10885 json_neigh, "nextStartTimerDueInMsecs",
10886 thread_timer_remain_second(p->t_start) * 1000);
10887 if (p->t_connect)
10888 json_object_int_add(
10889 json_neigh, "nextConnectTimerDueInMsecs",
10890 thread_timer_remain_second(p->t_connect)
10891 * 1000);
10892 if (p->t_routeadv) {
10893 json_object_int_add(json_neigh, "mraiInterval",
10894 p->v_routeadv);
10895 json_object_int_add(
10896 json_neigh, "mraiTimerExpireInMsecs",
10897 thread_timer_remain_second(p->t_routeadv)
10898 * 1000);
10899 }
10900 if (p->password)
10901 json_object_int_add(json_neigh, "authenticationEnabled",
10902 1);
10903
10904 if (p->t_read)
10905 json_object_string_add(json_neigh, "readThread", "on");
10906 else
10907 json_object_string_add(json_neigh, "readThread", "off");
10908
10909 if (CHECK_FLAG(p->thread_flags, PEER_THREAD_WRITES_ON))
10910 json_object_string_add(json_neigh, "writeThread", "on");
10911 else
10912 json_object_string_add(json_neigh, "writeThread",
10913 "off");
10914 } else {
10915 vty_out(vty, "BGP Connect Retry Timer in Seconds: %d\n",
10916 p->v_connect);
10917 if (p->status == Established && p->rtt)
10918 vty_out(vty, "Estimated round trip time: %d ms\n",
10919 p->rtt);
10920 if (p->t_start)
10921 vty_out(vty, "Next start timer due in %ld seconds\n",
10922 thread_timer_remain_second(p->t_start));
10923 if (p->t_connect)
10924 vty_out(vty, "Next connect timer due in %ld seconds\n",
10925 thread_timer_remain_second(p->t_connect));
10926 if (p->t_routeadv)
10927 vty_out(vty,
10928 "MRAI (interval %u) timer expires in %ld seconds\n",
10929 p->v_routeadv,
10930 thread_timer_remain_second(p->t_routeadv));
10931 if (p->password)
10932 vty_out(vty, "Peer Authentication Enabled\n");
10933
10934 vty_out(vty, "Read thread: %s Write thread: %s\n",
10935 p->t_read ? "on" : "off",
10936 CHECK_FLAG(p->thread_flags, PEER_THREAD_WRITES_ON)
10937 ? "on"
10938 : "off");
10939 }
10940
10941 if (p->notify.code == BGP_NOTIFY_OPEN_ERR
10942 && p->notify.subcode == BGP_NOTIFY_OPEN_UNSUP_CAPBL)
10943 bgp_capability_vty_out(vty, p, use_json, json_neigh);
10944
10945 if (!use_json)
10946 vty_out(vty, "\n");
10947
10948 /* BFD information. */
10949 bgp_bfd_show_info(vty, p, use_json, json_neigh);
10950
10951 if (use_json) {
10952 if (p->conf_if) /* Configured interface name. */
10953 json_object_object_add(json, p->conf_if, json_neigh);
10954 else /* Configured IP address. */
10955 json_object_object_add(json, p->host, json_neigh);
10956 }
10957 }
10958
10959 static int bgp_show_neighbor(struct vty *vty, struct bgp *bgp,
10960 enum show_type type, union sockunion *su,
10961 const char *conf_if, bool use_json,
10962 json_object *json)
10963 {
10964 struct listnode *node, *nnode;
10965 struct peer *peer;
10966 int find = 0;
10967 bool nbr_output = false;
10968 afi_t afi = AFI_MAX;
10969 safi_t safi = SAFI_MAX;
10970
10971 if (type == show_ipv4_peer || type == show_ipv4_all) {
10972 afi = AFI_IP;
10973 } else if (type == show_ipv6_peer || type == show_ipv6_all) {
10974 afi = AFI_IP6;
10975 }
10976
10977 for (ALL_LIST_ELEMENTS(bgp->peer, node, nnode, peer)) {
10978 if (!CHECK_FLAG(peer->flags, PEER_FLAG_CONFIG_NODE))
10979 continue;
10980
10981 switch (type) {
10982 case show_all:
10983 bgp_show_peer(vty, peer, use_json, json);
10984 nbr_output = true;
10985 break;
10986 case show_peer:
10987 if (conf_if) {
10988 if ((peer->conf_if
10989 && !strcmp(peer->conf_if, conf_if))
10990 || (peer->hostname
10991 && !strcmp(peer->hostname, conf_if))) {
10992 find = 1;
10993 bgp_show_peer(vty, peer, use_json,
10994 json);
10995 }
10996 } else {
10997 if (sockunion_same(&peer->su, su)) {
10998 find = 1;
10999 bgp_show_peer(vty, peer, use_json,
11000 json);
11001 }
11002 }
11003 break;
11004 case show_ipv4_peer:
11005 case show_ipv6_peer:
11006 FOREACH_SAFI (safi) {
11007 if (peer->afc[afi][safi]) {
11008 if (conf_if) {
11009 if ((peer->conf_if
11010 && !strcmp(peer->conf_if, conf_if))
11011 || (peer->hostname
11012 && !strcmp(peer->hostname, conf_if))) {
11013 find = 1;
11014 bgp_show_peer(vty, peer, use_json,
11015 json);
11016 break;
11017 }
11018 } else {
11019 if (sockunion_same(&peer->su, su)) {
11020 find = 1;
11021 bgp_show_peer(vty, peer, use_json,
11022 json);
11023 break;
11024 }
11025 }
11026 }
11027 }
11028 break;
11029 case show_ipv4_all:
11030 case show_ipv6_all:
11031 FOREACH_SAFI (safi) {
11032 if (peer->afc[afi][safi]) {
11033 bgp_show_peer(vty, peer, use_json, json);
11034 nbr_output = true;
11035 break;
11036 }
11037 }
11038 break;
11039 }
11040 }
11041
11042 if ((type == show_peer || type == show_ipv4_peer ||
11043 type == show_ipv6_peer) && !find) {
11044 if (use_json)
11045 json_object_boolean_true_add(json, "bgpNoSuchNeighbor");
11046 else
11047 vty_out(vty, "%% No such neighbor in this view/vrf\n");
11048 }
11049
11050 if (type != show_peer && type != show_ipv4_peer &&
11051 type != show_ipv6_peer && !nbr_output && !use_json)
11052 vty_out(vty, "%% No BGP neighbors found\n");
11053
11054 if (use_json) {
11055 vty_out(vty, "%s\n", json_object_to_json_string_ext(
11056 json, JSON_C_TO_STRING_PRETTY));
11057 } else {
11058 vty_out(vty, "\n");
11059 }
11060
11061 return CMD_SUCCESS;
11062 }
11063
11064 static void bgp_show_all_instances_neighbors_vty(struct vty *vty,
11065 enum show_type type,
11066 const char *ip_str,
11067 bool use_json)
11068 {
11069 struct listnode *node, *nnode;
11070 struct bgp *bgp;
11071 union sockunion su;
11072 json_object *json = NULL;
11073 int ret, is_first = 1;
11074 bool nbr_output = false;
11075
11076 if (use_json)
11077 vty_out(vty, "{\n");
11078
11079 for (ALL_LIST_ELEMENTS(bm->bgp, node, nnode, bgp)) {
11080 nbr_output = true;
11081 if (use_json) {
11082 if (!(json = json_object_new_object())) {
11083 flog_err(
11084 EC_BGP_JSON_MEM_ERROR,
11085 "Unable to allocate memory for JSON object");
11086 vty_out(vty,
11087 "{\"error\": {\"message:\": \"Unable to allocate memory for JSON object\"}}}\n");
11088 return;
11089 }
11090
11091 json_object_int_add(json, "vrfId",
11092 (bgp->vrf_id == VRF_UNKNOWN)
11093 ? -1
11094 : (int64_t)bgp->vrf_id);
11095 json_object_string_add(
11096 json, "vrfName",
11097 (bgp->inst_type == BGP_INSTANCE_TYPE_DEFAULT)
11098 ? VRF_DEFAULT_NAME
11099 : bgp->name);
11100
11101 if (!is_first)
11102 vty_out(vty, ",\n");
11103 else
11104 is_first = 0;
11105
11106 vty_out(vty, "\"%s\":",
11107 (bgp->inst_type == BGP_INSTANCE_TYPE_DEFAULT)
11108 ? VRF_DEFAULT_NAME
11109 : bgp->name);
11110 } else {
11111 vty_out(vty, "\nInstance %s:\n",
11112 (bgp->inst_type == BGP_INSTANCE_TYPE_DEFAULT)
11113 ? VRF_DEFAULT_NAME
11114 : bgp->name);
11115 }
11116
11117 if (type == show_peer || type == show_ipv4_peer ||
11118 type == show_ipv6_peer) {
11119 ret = str2sockunion(ip_str, &su);
11120 if (ret < 0)
11121 bgp_show_neighbor(vty, bgp, type, NULL, ip_str,
11122 use_json, json);
11123 else
11124 bgp_show_neighbor(vty, bgp, type, &su, NULL,
11125 use_json, json);
11126 } else {
11127 bgp_show_neighbor(vty, bgp, type, NULL, NULL,
11128 use_json, json);
11129 }
11130 json_object_free(json);
11131 }
11132
11133 if (use_json) {
11134 vty_out(vty, "}\n");
11135 json_object_free(json);
11136 }
11137 else if (!nbr_output)
11138 vty_out(vty, "%% BGP instance not found\n");
11139 }
11140
11141 static int bgp_show_neighbor_vty(struct vty *vty, const char *name,
11142 enum show_type type, const char *ip_str,
11143 bool use_json)
11144 {
11145 int ret;
11146 struct bgp *bgp;
11147 union sockunion su;
11148 json_object *json = NULL;
11149
11150 if (name) {
11151 if (strmatch(name, "all")) {
11152 bgp_show_all_instances_neighbors_vty(vty, type, ip_str,
11153 use_json);
11154 return CMD_SUCCESS;
11155 } else {
11156 bgp = bgp_lookup_by_name(name);
11157 if (!bgp) {
11158 if (use_json) {
11159 json = json_object_new_object();
11160 vty_out(vty, "%s\n",
11161 json_object_to_json_string_ext(
11162 json,
11163 JSON_C_TO_STRING_PRETTY));
11164 json_object_free(json);
11165 } else
11166 vty_out(vty,
11167 "%% BGP instance not found\n");
11168
11169 return CMD_WARNING;
11170 }
11171 }
11172 } else {
11173 bgp = bgp_get_default();
11174 }
11175
11176 if (bgp) {
11177 json = json_object_new_object();
11178 if (ip_str) {
11179 ret = str2sockunion(ip_str, &su);
11180 if (ret < 0)
11181 bgp_show_neighbor(vty, bgp, type, NULL, ip_str,
11182 use_json, json);
11183 else
11184 bgp_show_neighbor(vty, bgp, type, &su, NULL,
11185 use_json, json);
11186 } else {
11187 bgp_show_neighbor(vty, bgp, type, NULL, NULL, use_json,
11188 json);
11189 }
11190 json_object_free(json);
11191 } else {
11192 if (use_json)
11193 vty_out(vty, "{}\n");
11194 else
11195 vty_out(vty, "%% BGP instance not found\n");
11196 }
11197
11198 return CMD_SUCCESS;
11199 }
11200
11201 /* "show [ip] bgp neighbors" commands. */
11202 DEFUN (show_ip_bgp_neighbors,
11203 show_ip_bgp_neighbors_cmd,
11204 "show [ip] bgp [<view|vrf> VIEWVRFNAME] [<ipv4|ipv6>] neighbors [<A.B.C.D|X:X::X:X|WORD>] [json]",
11205 SHOW_STR
11206 IP_STR
11207 BGP_STR
11208 BGP_INSTANCE_HELP_STR
11209 "Address Family\n"
11210 "Address Family\n"
11211 "Detailed information on TCP and BGP neighbor connections\n"
11212 "Neighbor to display information about\n"
11213 "Neighbor to display information about\n"
11214 "Neighbor on BGP configured interface\n"
11215 JSON_STR)
11216 {
11217 char *vrf = NULL;
11218 char *sh_arg = NULL;
11219 enum show_type sh_type;
11220 afi_t afi = AFI_MAX;
11221
11222 bool uj = use_json(argc, argv);
11223
11224 int idx = 0;
11225
11226 /* [<vrf> VIEWVRFNAME] */
11227 if (argv_find(argv, argc, "vrf", &idx)) {
11228 vrf = argv[idx + 1]->arg;
11229 if (vrf && strmatch(vrf, VRF_DEFAULT_NAME))
11230 vrf = NULL;
11231 } else if (argv_find(argv, argc, "view", &idx))
11232 /* [<view> VIEWVRFNAME] */
11233 vrf = argv[idx + 1]->arg;
11234
11235 idx++;
11236
11237 if (argv_find(argv, argc, "ipv4", &idx)) {
11238 sh_type = show_ipv4_all;
11239 afi = AFI_IP;
11240 } else if (argv_find(argv, argc, "ipv6", &idx)) {
11241 sh_type = show_ipv6_all;
11242 afi = AFI_IP6;
11243 } else {
11244 sh_type = show_all;
11245 }
11246
11247 if (argv_find(argv, argc, "A.B.C.D", &idx)
11248 || argv_find(argv, argc, "X:X::X:X", &idx)
11249 || argv_find(argv, argc, "WORD", &idx)) {
11250 sh_type = show_peer;
11251 sh_arg = argv[idx]->arg;
11252 }
11253
11254 if (sh_type == show_peer && afi == AFI_IP) {
11255 sh_type = show_ipv4_peer;
11256 } else if (sh_type == show_peer && afi == AFI_IP6) {
11257 sh_type = show_ipv6_peer;
11258 }
11259
11260 return bgp_show_neighbor_vty(vty, vrf, sh_type, sh_arg, uj);
11261 }
11262
11263 /* Show BGP's AS paths internal data. There are both `show [ip] bgp
11264 paths' and `show ip mbgp paths'. Those functions results are the
11265 same.*/
11266 DEFUN (show_ip_bgp_paths,
11267 show_ip_bgp_paths_cmd,
11268 "show [ip] bgp ["BGP_SAFI_CMD_STR"] paths",
11269 SHOW_STR
11270 IP_STR
11271 BGP_STR
11272 BGP_SAFI_HELP_STR
11273 "Path information\n")
11274 {
11275 vty_out(vty, "Address Refcnt Path\n");
11276 aspath_print_all_vty(vty);
11277 return CMD_SUCCESS;
11278 }
11279
11280 #include "hash.h"
11281
11282 static void community_show_all_iterator(struct hash_bucket *bucket,
11283 struct vty *vty)
11284 {
11285 struct community *com;
11286
11287 com = (struct community *)bucket->data;
11288 vty_out(vty, "[%p] (%ld) %s\n", (void *)com, com->refcnt,
11289 community_str(com, false));
11290 }
11291
11292 /* Show BGP's community internal data. */
11293 DEFUN (show_ip_bgp_community_info,
11294 show_ip_bgp_community_info_cmd,
11295 "show [ip] bgp community-info",
11296 SHOW_STR
11297 IP_STR
11298 BGP_STR
11299 "List all bgp community information\n")
11300 {
11301 vty_out(vty, "Address Refcnt Community\n");
11302
11303 hash_iterate(community_hash(),
11304 (void (*)(struct hash_bucket *,
11305 void *))community_show_all_iterator,
11306 vty);
11307
11308 return CMD_SUCCESS;
11309 }
11310
11311 static void lcommunity_show_all_iterator(struct hash_bucket *bucket,
11312 struct vty *vty)
11313 {
11314 struct lcommunity *lcom;
11315
11316 lcom = (struct lcommunity *)bucket->data;
11317 vty_out(vty, "[%p] (%ld) %s\n", (void *)lcom, lcom->refcnt,
11318 lcommunity_str(lcom, false));
11319 }
11320
11321 /* Show BGP's community internal data. */
11322 DEFUN (show_ip_bgp_lcommunity_info,
11323 show_ip_bgp_lcommunity_info_cmd,
11324 "show ip bgp large-community-info",
11325 SHOW_STR
11326 IP_STR
11327 BGP_STR
11328 "List all bgp large-community information\n")
11329 {
11330 vty_out(vty, "Address Refcnt Large-community\n");
11331
11332 hash_iterate(lcommunity_hash(),
11333 (void (*)(struct hash_bucket *,
11334 void *))lcommunity_show_all_iterator,
11335 vty);
11336
11337 return CMD_SUCCESS;
11338 }
11339
11340
11341 DEFUN (show_ip_bgp_attr_info,
11342 show_ip_bgp_attr_info_cmd,
11343 "show [ip] bgp attribute-info",
11344 SHOW_STR
11345 IP_STR
11346 BGP_STR
11347 "List all bgp attribute information\n")
11348 {
11349 attr_show_all(vty);
11350 return CMD_SUCCESS;
11351 }
11352
11353 static int bgp_show_route_leak_vty(struct vty *vty, const char *name,
11354 afi_t afi, safi_t safi,
11355 bool use_json, json_object *json)
11356 {
11357 struct bgp *bgp;
11358 struct listnode *node;
11359 char *vname;
11360 char buf1[INET6_ADDRSTRLEN];
11361 char *ecom_str;
11362 vpn_policy_direction_t dir;
11363
11364 if (json) {
11365 json_object *json_import_vrfs = NULL;
11366 json_object *json_export_vrfs = NULL;
11367
11368 bgp = name ? bgp_lookup_by_name(name) : bgp_get_default();
11369
11370 if (!bgp) {
11371 vty_out(vty, "%s\n",
11372 json_object_to_json_string_ext(
11373 json,
11374 JSON_C_TO_STRING_PRETTY));
11375 json_object_free(json);
11376
11377 return CMD_WARNING;
11378 }
11379
11380 /* Provide context for the block */
11381 json_object_string_add(json, "vrf", name ? name : "default");
11382 json_object_string_add(json, "afiSafi",
11383 afi_safi_print(afi, safi));
11384
11385 if (!CHECK_FLAG(bgp->af_flags[afi][safi],
11386 BGP_CONFIG_VRF_TO_VRF_IMPORT)) {
11387 json_object_string_add(json, "importFromVrfs", "none");
11388 json_object_string_add(json, "importRts", "none");
11389 } else {
11390 json_import_vrfs = json_object_new_array();
11391
11392 for (ALL_LIST_ELEMENTS_RO(
11393 bgp->vpn_policy[afi].import_vrf,
11394 node, vname))
11395 json_object_array_add(json_import_vrfs,
11396 json_object_new_string(vname));
11397
11398 dir = BGP_VPN_POLICY_DIR_FROMVPN;
11399 ecom_str = ecommunity_ecom2str(
11400 bgp->vpn_policy[afi].rtlist[dir],
11401 ECOMMUNITY_FORMAT_ROUTE_MAP, 0);
11402 json_object_object_add(json, "importFromVrfs",
11403 json_import_vrfs);
11404 json_object_string_add(json, "importRts", ecom_str);
11405
11406 XFREE(MTYPE_ECOMMUNITY_STR, ecom_str);
11407 }
11408
11409 if (!CHECK_FLAG(bgp->af_flags[afi][safi],
11410 BGP_CONFIG_VRF_TO_VRF_EXPORT)) {
11411 json_object_string_add(json, "exportToVrfs", "none");
11412 json_object_string_add(json, "routeDistinguisher",
11413 "none");
11414 json_object_string_add(json, "exportRts", "none");
11415 } else {
11416 json_export_vrfs = json_object_new_array();
11417
11418 for (ALL_LIST_ELEMENTS_RO(
11419 bgp->vpn_policy[afi].export_vrf,
11420 node, vname))
11421 json_object_array_add(json_export_vrfs,
11422 json_object_new_string(vname));
11423 json_object_object_add(json, "exportToVrfs",
11424 json_export_vrfs);
11425 json_object_string_add(json, "routeDistinguisher",
11426 prefix_rd2str(&bgp->vpn_policy[afi].tovpn_rd,
11427 buf1, RD_ADDRSTRLEN));
11428
11429 dir = BGP_VPN_POLICY_DIR_TOVPN;
11430 ecom_str = ecommunity_ecom2str(
11431 bgp->vpn_policy[afi].rtlist[dir],
11432 ECOMMUNITY_FORMAT_ROUTE_MAP, 0);
11433 json_object_string_add(json, "exportRts", ecom_str);
11434
11435 XFREE(MTYPE_ECOMMUNITY_STR, ecom_str);
11436 }
11437
11438 if (use_json) {
11439 vty_out(vty, "%s\n",
11440 json_object_to_json_string_ext(json,
11441 JSON_C_TO_STRING_PRETTY));
11442 json_object_free(json);
11443 }
11444 } else {
11445 bgp = name ? bgp_lookup_by_name(name) : bgp_get_default();
11446
11447 if (!bgp) {
11448 vty_out(vty, "%% No such BGP instance exist\n");
11449 return CMD_WARNING;
11450 }
11451
11452 if (!CHECK_FLAG(bgp->af_flags[afi][safi],
11453 BGP_CONFIG_VRF_TO_VRF_IMPORT))
11454 vty_out(vty,
11455 "This VRF is not importing %s routes from any other VRF\n",
11456 afi_safi_print(afi, safi));
11457 else {
11458 vty_out(vty,
11459 "This VRF is importing %s routes from the following VRFs:\n",
11460 afi_safi_print(afi, safi));
11461
11462 for (ALL_LIST_ELEMENTS_RO(
11463 bgp->vpn_policy[afi].import_vrf,
11464 node, vname))
11465 vty_out(vty, " %s\n", vname);
11466
11467 dir = BGP_VPN_POLICY_DIR_FROMVPN;
11468 ecom_str = ecommunity_ecom2str(
11469 bgp->vpn_policy[afi].rtlist[dir],
11470 ECOMMUNITY_FORMAT_ROUTE_MAP, 0);
11471 vty_out(vty, "Import RT(s): %s\n", ecom_str);
11472
11473 XFREE(MTYPE_ECOMMUNITY_STR, ecom_str);
11474 }
11475
11476 if (!CHECK_FLAG(bgp->af_flags[afi][safi],
11477 BGP_CONFIG_VRF_TO_VRF_EXPORT))
11478 vty_out(vty,
11479 "This VRF is not exporting %s routes to any other VRF\n",
11480 afi_safi_print(afi, safi));
11481 else {
11482 vty_out(vty,
11483 "This VRF is exporting %s routes to the following VRFs:\n",
11484 afi_safi_print(afi, safi));
11485
11486 for (ALL_LIST_ELEMENTS_RO(
11487 bgp->vpn_policy[afi].export_vrf,
11488 node, vname))
11489 vty_out(vty, " %s\n", vname);
11490
11491 vty_out(vty, "RD: %s\n",
11492 prefix_rd2str(&bgp->vpn_policy[afi].tovpn_rd,
11493 buf1, RD_ADDRSTRLEN));
11494
11495 dir = BGP_VPN_POLICY_DIR_TOVPN;
11496 ecom_str = ecommunity_ecom2str(
11497 bgp->vpn_policy[afi].rtlist[dir],
11498 ECOMMUNITY_FORMAT_ROUTE_MAP, 0);
11499 vty_out(vty, "Export RT: %s\n", ecom_str);
11500 XFREE(MTYPE_ECOMMUNITY_STR, ecom_str);
11501 }
11502 }
11503
11504 return CMD_SUCCESS;
11505 }
11506
11507 static int bgp_show_all_instance_route_leak_vty(struct vty *vty, afi_t afi,
11508 safi_t safi, bool use_json)
11509 {
11510 struct listnode *node, *nnode;
11511 struct bgp *bgp;
11512 char *vrf_name = NULL;
11513 json_object *json = NULL;
11514 json_object *json_vrf = NULL;
11515 json_object *json_vrfs = NULL;
11516
11517 if (use_json) {
11518 json = json_object_new_object();
11519 json_vrfs = json_object_new_object();
11520 }
11521
11522 for (ALL_LIST_ELEMENTS(bm->bgp, node, nnode, bgp)) {
11523
11524 if (bgp->inst_type != BGP_INSTANCE_TYPE_DEFAULT)
11525 vrf_name = bgp->name;
11526
11527 if (use_json) {
11528 json_vrf = json_object_new_object();
11529 } else {
11530 vty_out(vty, "\nInstance %s:\n",
11531 (bgp->inst_type == BGP_INSTANCE_TYPE_DEFAULT)
11532 ? VRF_DEFAULT_NAME : bgp->name);
11533 }
11534 bgp_show_route_leak_vty(vty, vrf_name, afi, safi, 0, json_vrf);
11535 if (use_json) {
11536 if (bgp->inst_type == BGP_INSTANCE_TYPE_DEFAULT)
11537 json_object_object_add(json_vrfs,
11538 VRF_DEFAULT_NAME, json_vrf);
11539 else
11540 json_object_object_add(json_vrfs, vrf_name,
11541 json_vrf);
11542 }
11543 }
11544
11545 if (use_json) {
11546 json_object_object_add(json, "vrfs", json_vrfs);
11547 vty_out(vty, "%s\n", json_object_to_json_string_ext(json,
11548 JSON_C_TO_STRING_PRETTY));
11549 json_object_free(json);
11550 }
11551
11552 return CMD_SUCCESS;
11553 }
11554
11555 /* "show [ip] bgp route-leak" command. */
11556 DEFUN (show_ip_bgp_route_leak,
11557 show_ip_bgp_route_leak_cmd,
11558 "show [ip] bgp [<view|vrf> VIEWVRFNAME] ["BGP_AFI_CMD_STR" ["BGP_SAFI_CMD_STR"]] route-leak [json]",
11559 SHOW_STR
11560 IP_STR
11561 BGP_STR
11562 BGP_INSTANCE_HELP_STR
11563 BGP_AFI_HELP_STR
11564 BGP_SAFI_HELP_STR
11565 "Route leaking information\n"
11566 JSON_STR)
11567 {
11568 char *vrf = NULL;
11569 afi_t afi = AFI_MAX;
11570 safi_t safi = SAFI_MAX;
11571
11572 bool uj = use_json(argc, argv);
11573 int idx = 0;
11574 json_object *json = NULL;
11575
11576 /* show [ip] bgp */
11577 if (argv_find(argv, argc, "ip", &idx)) {
11578 afi = AFI_IP;
11579 safi = SAFI_UNICAST;
11580 }
11581 /* [vrf VIEWVRFNAME] */
11582 if (argv_find(argv, argc, "view", &idx)) {
11583 vty_out(vty,
11584 "%% This command is not applicable to BGP views\n");
11585 return CMD_WARNING;
11586 }
11587
11588 if (argv_find(argv, argc, "vrf", &idx)) {
11589 vrf = argv[idx + 1]->arg;
11590 if (vrf && strmatch(vrf, VRF_DEFAULT_NAME))
11591 vrf = NULL;
11592 }
11593 /* ["BGP_AFI_CMD_STR" ["BGP_SAFI_CMD_STR"]] */
11594 if (argv_find_and_parse_afi(argv, argc, &idx, &afi)) {
11595 argv_find_and_parse_safi(argv, argc, &idx, &safi);
11596 }
11597
11598 if (!((afi == AFI_IP || afi == AFI_IP6) && safi == SAFI_UNICAST)) {
11599 vty_out(vty,
11600 "%% This command is applicable only for unicast ipv4|ipv6\n");
11601 return CMD_WARNING;
11602 }
11603
11604 if (vrf && strmatch(vrf, "all"))
11605 return bgp_show_all_instance_route_leak_vty(vty, afi, safi, uj);
11606
11607 if (uj)
11608 json = json_object_new_object();
11609
11610 return bgp_show_route_leak_vty(vty, vrf, afi, safi, uj, json);
11611 }
11612
11613 static void bgp_show_all_instances_updgrps_vty(struct vty *vty, afi_t afi,
11614 safi_t safi)
11615 {
11616 struct listnode *node, *nnode;
11617 struct bgp *bgp;
11618
11619 for (ALL_LIST_ELEMENTS(bm->bgp, node, nnode, bgp)) {
11620 vty_out(vty, "\nInstance %s:\n",
11621 (bgp->inst_type == BGP_INSTANCE_TYPE_DEFAULT)
11622 ? VRF_DEFAULT_NAME
11623 : bgp->name);
11624 update_group_show(bgp, afi, safi, vty, 0);
11625 }
11626 }
11627
11628 static int bgp_show_update_groups(struct vty *vty, const char *name, int afi,
11629 int safi, uint64_t subgrp_id)
11630 {
11631 struct bgp *bgp;
11632
11633 if (name) {
11634 if (strmatch(name, "all")) {
11635 bgp_show_all_instances_updgrps_vty(vty, afi, safi);
11636 return CMD_SUCCESS;
11637 } else {
11638 bgp = bgp_lookup_by_name(name);
11639 }
11640 } else {
11641 bgp = bgp_get_default();
11642 }
11643
11644 if (bgp)
11645 update_group_show(bgp, afi, safi, vty, subgrp_id);
11646 return CMD_SUCCESS;
11647 }
11648
11649 DEFUN (show_ip_bgp_updgrps,
11650 show_ip_bgp_updgrps_cmd,
11651 "show [ip] bgp [<view|vrf> VIEWVRFNAME] ["BGP_AFI_CMD_STR" ["BGP_SAFI_WITH_LABEL_CMD_STR"]] update-groups [SUBGROUP-ID]",
11652 SHOW_STR
11653 IP_STR
11654 BGP_STR
11655 BGP_INSTANCE_HELP_STR
11656 BGP_AFI_HELP_STR
11657 BGP_SAFI_WITH_LABEL_HELP_STR
11658 "Detailed info about dynamic update groups\n"
11659 "Specific subgroup to display detailed info for\n")
11660 {
11661 char *vrf = NULL;
11662 afi_t afi = AFI_IP6;
11663 safi_t safi = SAFI_UNICAST;
11664 uint64_t subgrp_id = 0;
11665
11666 int idx = 0;
11667
11668 /* show [ip] bgp */
11669 if (argv_find(argv, argc, "ip", &idx))
11670 afi = AFI_IP;
11671 /* [<vrf> VIEWVRFNAME] */
11672 if (argv_find(argv, argc, "vrf", &idx)) {
11673 vrf = argv[idx + 1]->arg;
11674 if (vrf && strmatch(vrf, VRF_DEFAULT_NAME))
11675 vrf = NULL;
11676 } else if (argv_find(argv, argc, "view", &idx))
11677 /* [<view> VIEWVRFNAME] */
11678 vrf = argv[idx + 1]->arg;
11679 /* ["BGP_AFI_CMD_STR" ["BGP_SAFI_CMD_STR"]] */
11680 if (argv_find_and_parse_afi(argv, argc, &idx, &afi)) {
11681 argv_find_and_parse_safi(argv, argc, &idx, &safi);
11682 }
11683
11684 /* get subgroup id, if provided */
11685 idx = argc - 1;
11686 if (argv[idx]->type == VARIABLE_TKN)
11687 subgrp_id = strtoull(argv[idx]->arg, NULL, 10);
11688
11689 return (bgp_show_update_groups(vty, vrf, afi, safi, subgrp_id));
11690 }
11691
11692 DEFUN (show_bgp_instance_all_ipv6_updgrps,
11693 show_bgp_instance_all_ipv6_updgrps_cmd,
11694 "show [ip] bgp <view|vrf> all update-groups",
11695 SHOW_STR
11696 IP_STR
11697 BGP_STR
11698 BGP_INSTANCE_ALL_HELP_STR
11699 "Detailed info about dynamic update groups\n")
11700 {
11701 bgp_show_all_instances_updgrps_vty(vty, AFI_IP6, SAFI_UNICAST);
11702 return CMD_SUCCESS;
11703 }
11704
11705 DEFUN (show_bgp_l2vpn_evpn_updgrps,
11706 show_bgp_l2vpn_evpn_updgrps_cmd,
11707 "show [ip] bgp l2vpn evpn update-groups",
11708 SHOW_STR
11709 IP_STR
11710 BGP_STR
11711 "l2vpn address family\n"
11712 "evpn sub-address family\n"
11713 "Detailed info about dynamic update groups\n")
11714 {
11715 char *vrf = NULL;
11716 uint64_t subgrp_id = 0;
11717
11718 bgp_show_update_groups(vty, vrf, AFI_L2VPN, SAFI_EVPN, subgrp_id);
11719 return CMD_SUCCESS;
11720 }
11721
11722 DEFUN (show_bgp_updgrps_stats,
11723 show_bgp_updgrps_stats_cmd,
11724 "show [ip] bgp update-groups statistics",
11725 SHOW_STR
11726 IP_STR
11727 BGP_STR
11728 "Detailed info about dynamic update groups\n"
11729 "Statistics\n")
11730 {
11731 struct bgp *bgp;
11732
11733 bgp = bgp_get_default();
11734 if (bgp)
11735 update_group_show_stats(bgp, vty);
11736
11737 return CMD_SUCCESS;
11738 }
11739
11740 DEFUN (show_bgp_instance_updgrps_stats,
11741 show_bgp_instance_updgrps_stats_cmd,
11742 "show [ip] bgp <view|vrf> VIEWVRFNAME update-groups statistics",
11743 SHOW_STR
11744 IP_STR
11745 BGP_STR
11746 BGP_INSTANCE_HELP_STR
11747 "Detailed info about dynamic update groups\n"
11748 "Statistics\n")
11749 {
11750 int idx_word = 3;
11751 struct bgp *bgp;
11752
11753 bgp = bgp_lookup_by_name(argv[idx_word]->arg);
11754 if (bgp)
11755 update_group_show_stats(bgp, vty);
11756
11757 return CMD_SUCCESS;
11758 }
11759
11760 static void show_bgp_updgrps_adj_info_aux(struct vty *vty, const char *name,
11761 afi_t afi, safi_t safi,
11762 const char *what, uint64_t subgrp_id)
11763 {
11764 struct bgp *bgp;
11765
11766 if (name)
11767 bgp = bgp_lookup_by_name(name);
11768 else
11769 bgp = bgp_get_default();
11770
11771 if (bgp) {
11772 if (!strcmp(what, "advertise-queue"))
11773 update_group_show_adj_queue(bgp, afi, safi, vty,
11774 subgrp_id);
11775 else if (!strcmp(what, "advertised-routes"))
11776 update_group_show_advertised(bgp, afi, safi, vty,
11777 subgrp_id);
11778 else if (!strcmp(what, "packet-queue"))
11779 update_group_show_packet_queue(bgp, afi, safi, vty,
11780 subgrp_id);
11781 }
11782 }
11783
11784 DEFPY(show_ip_bgp_instance_updgrps_adj_s,
11785 show_ip_bgp_instance_updgrps_adj_s_cmd,
11786 "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",
11787 SHOW_STR IP_STR BGP_STR BGP_INSTANCE_HELP_STR BGP_AFI_HELP_STR
11788 BGP_SAFI_HELP_STR
11789 "Detailed info about dynamic update groups\n"
11790 "Specific subgroup to display info for\n"
11791 "Advertisement queue\n"
11792 "Announced routes\n"
11793 "Packet queue\n")
11794 {
11795 uint64_t subgrp_id = 0;
11796 afi_t afiz;
11797 safi_t safiz;
11798 if (sgid)
11799 subgrp_id = strtoull(sgid, NULL, 10);
11800
11801 if (!ip && !afi)
11802 afiz = AFI_IP6;
11803 if (!ip && afi)
11804 afiz = bgp_vty_afi_from_str(afi);
11805 if (ip && !afi)
11806 afiz = AFI_IP;
11807 if (ip && afi) {
11808 afiz = bgp_vty_afi_from_str(afi);
11809 if (afiz != AFI_IP)
11810 vty_out(vty,
11811 "%% Cannot specify both 'ip' and 'ipv6'\n");
11812 return CMD_WARNING;
11813 }
11814
11815 safiz = safi ? bgp_vty_safi_from_str(safi) : SAFI_UNICAST;
11816
11817 show_bgp_updgrps_adj_info_aux(vty, vrf, afiz, safiz, rtq, subgrp_id);
11818 return CMD_SUCCESS;
11819 }
11820
11821 static int bgp_show_one_peer_group(struct vty *vty, struct peer_group *group)
11822 {
11823 struct listnode *node, *nnode;
11824 struct prefix *range;
11825 struct peer *conf;
11826 struct peer *peer;
11827 char buf[PREFIX2STR_BUFFER];
11828 afi_t afi;
11829 safi_t safi;
11830 const char *peer_status;
11831 const char *af_str;
11832 int lr_count;
11833 int dynamic;
11834 int af_cfgd;
11835
11836 conf = group->conf;
11837
11838 if (conf->as_type == AS_SPECIFIED || conf->as_type == AS_EXTERNAL) {
11839 vty_out(vty, "\nBGP peer-group %s, remote AS %" PRIu32 "\n",
11840 group->name, conf->as);
11841 } else if (conf->as_type == AS_INTERNAL) {
11842 vty_out(vty, "\nBGP peer-group %s, remote AS %" PRIu32 "\n",
11843 group->name, group->bgp->as);
11844 } else {
11845 vty_out(vty, "\nBGP peer-group %s\n", group->name);
11846 }
11847
11848 if ((group->bgp->as == conf->as) || (conf->as_type == AS_INTERNAL))
11849 vty_out(vty, " Peer-group type is internal\n");
11850 else
11851 vty_out(vty, " Peer-group type is external\n");
11852
11853 /* Display AFs configured. */
11854 vty_out(vty, " Configured address-families:");
11855 FOREACH_AFI_SAFI (afi, safi) {
11856 if (conf->afc[afi][safi]) {
11857 af_cfgd = 1;
11858 vty_out(vty, " %s;", afi_safi_print(afi, safi));
11859 }
11860 }
11861 if (!af_cfgd)
11862 vty_out(vty, " none\n");
11863 else
11864 vty_out(vty, "\n");
11865
11866 /* Display listen ranges (for dynamic neighbors), if any */
11867 for (afi = AFI_IP; afi < AFI_MAX; afi++) {
11868 if (afi == AFI_IP)
11869 af_str = "IPv4";
11870 else if (afi == AFI_IP6)
11871 af_str = "IPv6";
11872 else
11873 af_str = "???";
11874 lr_count = listcount(group->listen_range[afi]);
11875 if (lr_count) {
11876 vty_out(vty, " %d %s listen range(s)\n", lr_count,
11877 af_str);
11878
11879
11880 for (ALL_LIST_ELEMENTS(group->listen_range[afi], node,
11881 nnode, range)) {
11882 prefix2str(range, buf, sizeof(buf));
11883 vty_out(vty, " %s\n", buf);
11884 }
11885 }
11886 }
11887
11888 /* Display group members and their status */
11889 if (listcount(group->peer)) {
11890 vty_out(vty, " Peer-group members:\n");
11891 for (ALL_LIST_ELEMENTS(group->peer, node, nnode, peer)) {
11892 if (CHECK_FLAG(peer->flags, PEER_FLAG_SHUTDOWN))
11893 peer_status = "Idle (Admin)";
11894 else if (CHECK_FLAG(peer->sflags,
11895 PEER_STATUS_PREFIX_OVERFLOW))
11896 peer_status = "Idle (PfxCt)";
11897 else
11898 peer_status = lookup_msg(bgp_status_msg,
11899 peer->status, NULL);
11900
11901 dynamic = peer_dynamic_neighbor(peer);
11902 vty_out(vty, " %s %s %s \n", peer->host,
11903 dynamic ? "(dynamic)" : "", peer_status);
11904 }
11905 }
11906
11907 return CMD_SUCCESS;
11908 }
11909
11910 static int bgp_show_peer_group_vty(struct vty *vty, const char *name,
11911 const char *group_name)
11912 {
11913 struct bgp *bgp;
11914 struct listnode *node, *nnode;
11915 struct peer_group *group;
11916 bool found = false;
11917
11918 bgp = name ? bgp_lookup_by_name(name) : bgp_get_default();
11919
11920 if (!bgp) {
11921 vty_out(vty, "%% BGP instance not found\n");
11922 return CMD_WARNING;
11923 }
11924
11925 for (ALL_LIST_ELEMENTS(bgp->group, node, nnode, group)) {
11926 if (group_name) {
11927 if (strmatch(group->name, group_name)) {
11928 bgp_show_one_peer_group(vty, group);
11929 found = true;
11930 break;
11931 }
11932 } else {
11933 bgp_show_one_peer_group(vty, group);
11934 }
11935 }
11936
11937 if (group_name && !found)
11938 vty_out(vty, "%% No such peer-group\n");
11939
11940 return CMD_SUCCESS;
11941 }
11942
11943 DEFUN (show_ip_bgp_peer_groups,
11944 show_ip_bgp_peer_groups_cmd,
11945 "show [ip] bgp [<view|vrf> VIEWVRFNAME] peer-group [PGNAME]",
11946 SHOW_STR
11947 IP_STR
11948 BGP_STR
11949 BGP_INSTANCE_HELP_STR
11950 "Detailed information on BGP peer groups\n"
11951 "Peer group name\n")
11952 {
11953 char *vrf, *pg;
11954 int idx = 0;
11955
11956 vrf = argv_find(argv, argc, "VIEWVRFNAME", &idx) ? argv[idx]->arg
11957 : NULL;
11958 pg = argv_find(argv, argc, "PGNAME", &idx) ? argv[idx]->arg : NULL;
11959
11960 return bgp_show_peer_group_vty(vty, vrf, pg);
11961 }
11962
11963
11964 /* Redistribute VTY commands. */
11965
11966 DEFUN (bgp_redistribute_ipv4,
11967 bgp_redistribute_ipv4_cmd,
11968 "redistribute " FRR_IP_REDIST_STR_BGPD,
11969 "Redistribute information from another routing protocol\n"
11970 FRR_IP_REDIST_HELP_STR_BGPD)
11971 {
11972 VTY_DECLVAR_CONTEXT(bgp, bgp);
11973 int idx_protocol = 1;
11974 int type;
11975
11976 type = proto_redistnum(AFI_IP, argv[idx_protocol]->text);
11977 if (type < 0) {
11978 vty_out(vty, "%% Invalid route type\n");
11979 return CMD_WARNING_CONFIG_FAILED;
11980 }
11981
11982 bgp_redist_add(bgp, AFI_IP, type, 0);
11983 return bgp_redistribute_set(bgp, AFI_IP, type, 0, false);
11984 }
11985
11986 ALIAS_HIDDEN(
11987 bgp_redistribute_ipv4, bgp_redistribute_ipv4_hidden_cmd,
11988 "redistribute " FRR_IP_REDIST_STR_BGPD,
11989 "Redistribute information from another routing protocol\n" FRR_IP_REDIST_HELP_STR_BGPD)
11990
11991 DEFUN (bgp_redistribute_ipv4_rmap,
11992 bgp_redistribute_ipv4_rmap_cmd,
11993 "redistribute " FRR_IP_REDIST_STR_BGPD " route-map WORD",
11994 "Redistribute information from another routing protocol\n"
11995 FRR_IP_REDIST_HELP_STR_BGPD
11996 "Route map reference\n"
11997 "Pointer to route-map entries\n")
11998 {
11999 VTY_DECLVAR_CONTEXT(bgp, bgp);
12000 int idx_protocol = 1;
12001 int idx_word = 3;
12002 int type;
12003 struct bgp_redist *red;
12004 bool changed;
12005 struct route_map *route_map = route_map_lookup_warn_noexist(
12006 vty, argv[idx_word]->arg);
12007
12008 type = proto_redistnum(AFI_IP, argv[idx_protocol]->text);
12009 if (type < 0) {
12010 vty_out(vty, "%% Invalid route type\n");
12011 return CMD_WARNING_CONFIG_FAILED;
12012 }
12013
12014 red = bgp_redist_add(bgp, AFI_IP, type, 0);
12015 changed =
12016 bgp_redistribute_rmap_set(red, argv[idx_word]->arg, route_map);
12017 return bgp_redistribute_set(bgp, AFI_IP, type, 0, changed);
12018 }
12019
12020 ALIAS_HIDDEN(
12021 bgp_redistribute_ipv4_rmap, bgp_redistribute_ipv4_rmap_hidden_cmd,
12022 "redistribute " FRR_IP_REDIST_STR_BGPD " route-map WORD",
12023 "Redistribute information from another routing protocol\n" FRR_IP_REDIST_HELP_STR_BGPD
12024 "Route map reference\n"
12025 "Pointer to route-map entries\n")
12026
12027 DEFUN (bgp_redistribute_ipv4_metric,
12028 bgp_redistribute_ipv4_metric_cmd,
12029 "redistribute " FRR_IP_REDIST_STR_BGPD " metric (0-4294967295)",
12030 "Redistribute information from another routing protocol\n"
12031 FRR_IP_REDIST_HELP_STR_BGPD
12032 "Metric for redistributed routes\n"
12033 "Default metric\n")
12034 {
12035 VTY_DECLVAR_CONTEXT(bgp, bgp);
12036 int idx_protocol = 1;
12037 int idx_number = 3;
12038 int type;
12039 uint32_t metric;
12040 struct bgp_redist *red;
12041 bool changed;
12042
12043 type = proto_redistnum(AFI_IP, argv[idx_protocol]->text);
12044 if (type < 0) {
12045 vty_out(vty, "%% Invalid route type\n");
12046 return CMD_WARNING_CONFIG_FAILED;
12047 }
12048 metric = strtoul(argv[idx_number]->arg, NULL, 10);
12049
12050 red = bgp_redist_add(bgp, AFI_IP, type, 0);
12051 changed = bgp_redistribute_metric_set(bgp, red, AFI_IP, type, metric);
12052 return bgp_redistribute_set(bgp, AFI_IP, type, 0, changed);
12053 }
12054
12055 ALIAS_HIDDEN(
12056 bgp_redistribute_ipv4_metric, bgp_redistribute_ipv4_metric_hidden_cmd,
12057 "redistribute " FRR_IP_REDIST_STR_BGPD " metric (0-4294967295)",
12058 "Redistribute information from another routing protocol\n" FRR_IP_REDIST_HELP_STR_BGPD
12059 "Metric for redistributed routes\n"
12060 "Default metric\n")
12061
12062 DEFUN (bgp_redistribute_ipv4_rmap_metric,
12063 bgp_redistribute_ipv4_rmap_metric_cmd,
12064 "redistribute " FRR_IP_REDIST_STR_BGPD " route-map WORD metric (0-4294967295)",
12065 "Redistribute information from another routing protocol\n"
12066 FRR_IP_REDIST_HELP_STR_BGPD
12067 "Route map reference\n"
12068 "Pointer to route-map entries\n"
12069 "Metric for redistributed routes\n"
12070 "Default metric\n")
12071 {
12072 VTY_DECLVAR_CONTEXT(bgp, bgp);
12073 int idx_protocol = 1;
12074 int idx_word = 3;
12075 int idx_number = 5;
12076 int type;
12077 uint32_t metric;
12078 struct bgp_redist *red;
12079 bool changed;
12080 struct route_map *route_map =
12081 route_map_lookup_warn_noexist(vty, argv[idx_word]->arg);
12082
12083 type = proto_redistnum(AFI_IP, argv[idx_protocol]->text);
12084 if (type < 0) {
12085 vty_out(vty, "%% Invalid route type\n");
12086 return CMD_WARNING_CONFIG_FAILED;
12087 }
12088 metric = strtoul(argv[idx_number]->arg, NULL, 10);
12089
12090 red = bgp_redist_add(bgp, AFI_IP, type, 0);
12091 changed =
12092 bgp_redistribute_rmap_set(red, argv[idx_word]->arg, route_map);
12093 changed |= bgp_redistribute_metric_set(bgp, red, AFI_IP, type, metric);
12094 return bgp_redistribute_set(bgp, AFI_IP, type, 0, changed);
12095 }
12096
12097 ALIAS_HIDDEN(
12098 bgp_redistribute_ipv4_rmap_metric,
12099 bgp_redistribute_ipv4_rmap_metric_hidden_cmd,
12100 "redistribute " FRR_IP_REDIST_STR_BGPD
12101 " route-map WORD metric (0-4294967295)",
12102 "Redistribute information from another routing protocol\n" FRR_IP_REDIST_HELP_STR_BGPD
12103 "Route map reference\n"
12104 "Pointer to route-map entries\n"
12105 "Metric for redistributed routes\n"
12106 "Default metric\n")
12107
12108 DEFUN (bgp_redistribute_ipv4_metric_rmap,
12109 bgp_redistribute_ipv4_metric_rmap_cmd,
12110 "redistribute " FRR_IP_REDIST_STR_BGPD " metric (0-4294967295) route-map WORD",
12111 "Redistribute information from another routing protocol\n"
12112 FRR_IP_REDIST_HELP_STR_BGPD
12113 "Metric for redistributed routes\n"
12114 "Default metric\n"
12115 "Route map reference\n"
12116 "Pointer to route-map entries\n")
12117 {
12118 VTY_DECLVAR_CONTEXT(bgp, bgp);
12119 int idx_protocol = 1;
12120 int idx_number = 3;
12121 int idx_word = 5;
12122 int type;
12123 uint32_t metric;
12124 struct bgp_redist *red;
12125 bool changed;
12126 struct route_map *route_map =
12127 route_map_lookup_warn_noexist(vty, argv[idx_word]->arg);
12128
12129 type = proto_redistnum(AFI_IP, argv[idx_protocol]->text);
12130 if (type < 0) {
12131 vty_out(vty, "%% Invalid route type\n");
12132 return CMD_WARNING_CONFIG_FAILED;
12133 }
12134 metric = strtoul(argv[idx_number]->arg, NULL, 10);
12135
12136 red = bgp_redist_add(bgp, AFI_IP, type, 0);
12137 changed = bgp_redistribute_metric_set(bgp, red, AFI_IP, type, metric);
12138 changed |=
12139 bgp_redistribute_rmap_set(red, argv[idx_word]->arg, route_map);
12140 return bgp_redistribute_set(bgp, AFI_IP, type, 0, changed);
12141 }
12142
12143 ALIAS_HIDDEN(
12144 bgp_redistribute_ipv4_metric_rmap,
12145 bgp_redistribute_ipv4_metric_rmap_hidden_cmd,
12146 "redistribute " FRR_IP_REDIST_STR_BGPD
12147 " metric (0-4294967295) route-map WORD",
12148 "Redistribute information from another routing protocol\n" FRR_IP_REDIST_HELP_STR_BGPD
12149 "Metric for redistributed routes\n"
12150 "Default metric\n"
12151 "Route map reference\n"
12152 "Pointer to route-map entries\n")
12153
12154 DEFUN (bgp_redistribute_ipv4_ospf,
12155 bgp_redistribute_ipv4_ospf_cmd,
12156 "redistribute <ospf|table> (1-65535)",
12157 "Redistribute information from another routing protocol\n"
12158 "Open Shortest Path First (OSPFv2)\n"
12159 "Non-main Kernel Routing Table\n"
12160 "Instance ID/Table ID\n")
12161 {
12162 VTY_DECLVAR_CONTEXT(bgp, bgp);
12163 int idx_ospf_table = 1;
12164 int idx_number = 2;
12165 unsigned short instance;
12166 unsigned short protocol;
12167
12168 instance = strtoul(argv[idx_number]->arg, NULL, 10);
12169
12170 if (strncmp(argv[idx_ospf_table]->arg, "o", 1) == 0)
12171 protocol = ZEBRA_ROUTE_OSPF;
12172 else
12173 protocol = ZEBRA_ROUTE_TABLE;
12174
12175 bgp_redist_add(bgp, AFI_IP, protocol, instance);
12176 return bgp_redistribute_set(bgp, AFI_IP, protocol, instance, false);
12177 }
12178
12179 ALIAS_HIDDEN(bgp_redistribute_ipv4_ospf, bgp_redistribute_ipv4_ospf_hidden_cmd,
12180 "redistribute <ospf|table> (1-65535)",
12181 "Redistribute information from another routing protocol\n"
12182 "Open Shortest Path First (OSPFv2)\n"
12183 "Non-main Kernel Routing Table\n"
12184 "Instance ID/Table ID\n")
12185
12186 DEFUN (bgp_redistribute_ipv4_ospf_rmap,
12187 bgp_redistribute_ipv4_ospf_rmap_cmd,
12188 "redistribute <ospf|table> (1-65535) route-map WORD",
12189 "Redistribute information from another routing protocol\n"
12190 "Open Shortest Path First (OSPFv2)\n"
12191 "Non-main Kernel Routing Table\n"
12192 "Instance ID/Table ID\n"
12193 "Route map reference\n"
12194 "Pointer to route-map entries\n")
12195 {
12196 VTY_DECLVAR_CONTEXT(bgp, bgp);
12197 int idx_ospf_table = 1;
12198 int idx_number = 2;
12199 int idx_word = 4;
12200 struct bgp_redist *red;
12201 unsigned short instance;
12202 int protocol;
12203 bool changed;
12204 struct route_map *route_map =
12205 route_map_lookup_warn_noexist(vty, argv[idx_word]->arg);
12206
12207 if (strncmp(argv[idx_ospf_table]->arg, "o", 1) == 0)
12208 protocol = ZEBRA_ROUTE_OSPF;
12209 else
12210 protocol = ZEBRA_ROUTE_TABLE;
12211
12212 instance = strtoul(argv[idx_number]->arg, NULL, 10);
12213 red = bgp_redist_add(bgp, AFI_IP, protocol, instance);
12214 changed =
12215 bgp_redistribute_rmap_set(red, argv[idx_word]->arg, route_map);
12216 return bgp_redistribute_set(bgp, AFI_IP, protocol, instance, changed);
12217 }
12218
12219 ALIAS_HIDDEN(bgp_redistribute_ipv4_ospf_rmap,
12220 bgp_redistribute_ipv4_ospf_rmap_hidden_cmd,
12221 "redistribute <ospf|table> (1-65535) route-map WORD",
12222 "Redistribute information from another routing protocol\n"
12223 "Open Shortest Path First (OSPFv2)\n"
12224 "Non-main Kernel Routing Table\n"
12225 "Instance ID/Table ID\n"
12226 "Route map reference\n"
12227 "Pointer to route-map entries\n")
12228
12229 DEFUN (bgp_redistribute_ipv4_ospf_metric,
12230 bgp_redistribute_ipv4_ospf_metric_cmd,
12231 "redistribute <ospf|table> (1-65535) metric (0-4294967295)",
12232 "Redistribute information from another routing protocol\n"
12233 "Open Shortest Path First (OSPFv2)\n"
12234 "Non-main Kernel Routing Table\n"
12235 "Instance ID/Table ID\n"
12236 "Metric for redistributed routes\n"
12237 "Default metric\n")
12238 {
12239 VTY_DECLVAR_CONTEXT(bgp, bgp);
12240 int idx_ospf_table = 1;
12241 int idx_number = 2;
12242 int idx_number_2 = 4;
12243 uint32_t metric;
12244 struct bgp_redist *red;
12245 unsigned short instance;
12246 int protocol;
12247 bool changed;
12248
12249 if (strncmp(argv[idx_ospf_table]->arg, "o", 1) == 0)
12250 protocol = ZEBRA_ROUTE_OSPF;
12251 else
12252 protocol = ZEBRA_ROUTE_TABLE;
12253
12254 instance = strtoul(argv[idx_number]->arg, NULL, 10);
12255 metric = strtoul(argv[idx_number_2]->arg, NULL, 10);
12256
12257 red = bgp_redist_add(bgp, AFI_IP, protocol, instance);
12258 changed = bgp_redistribute_metric_set(bgp, red, AFI_IP, protocol,
12259 metric);
12260 return bgp_redistribute_set(bgp, AFI_IP, protocol, instance, changed);
12261 }
12262
12263 ALIAS_HIDDEN(bgp_redistribute_ipv4_ospf_metric,
12264 bgp_redistribute_ipv4_ospf_metric_hidden_cmd,
12265 "redistribute <ospf|table> (1-65535) metric (0-4294967295)",
12266 "Redistribute information from another routing protocol\n"
12267 "Open Shortest Path First (OSPFv2)\n"
12268 "Non-main Kernel Routing Table\n"
12269 "Instance ID/Table ID\n"
12270 "Metric for redistributed routes\n"
12271 "Default metric\n")
12272
12273 DEFUN (bgp_redistribute_ipv4_ospf_rmap_metric,
12274 bgp_redistribute_ipv4_ospf_rmap_metric_cmd,
12275 "redistribute <ospf|table> (1-65535) route-map WORD metric (0-4294967295)",
12276 "Redistribute information from another routing protocol\n"
12277 "Open Shortest Path First (OSPFv2)\n"
12278 "Non-main Kernel Routing Table\n"
12279 "Instance ID/Table ID\n"
12280 "Route map reference\n"
12281 "Pointer to route-map entries\n"
12282 "Metric for redistributed routes\n"
12283 "Default metric\n")
12284 {
12285 VTY_DECLVAR_CONTEXT(bgp, bgp);
12286 int idx_ospf_table = 1;
12287 int idx_number = 2;
12288 int idx_word = 4;
12289 int idx_number_2 = 6;
12290 uint32_t metric;
12291 struct bgp_redist *red;
12292 unsigned short instance;
12293 int protocol;
12294 bool changed;
12295 struct route_map *route_map =
12296 route_map_lookup_warn_noexist(vty, argv[idx_word]->arg);
12297
12298 if (strncmp(argv[idx_ospf_table]->arg, "o", 1) == 0)
12299 protocol = ZEBRA_ROUTE_OSPF;
12300 else
12301 protocol = ZEBRA_ROUTE_TABLE;
12302
12303 instance = strtoul(argv[idx_number]->arg, NULL, 10);
12304 metric = strtoul(argv[idx_number_2]->arg, NULL, 10);
12305
12306 red = bgp_redist_add(bgp, AFI_IP, protocol, instance);
12307 changed =
12308 bgp_redistribute_rmap_set(red, argv[idx_word]->arg, route_map);
12309 changed |= bgp_redistribute_metric_set(bgp, red, AFI_IP, protocol,
12310 metric);
12311 return bgp_redistribute_set(bgp, AFI_IP, protocol, instance, changed);
12312 }
12313
12314 ALIAS_HIDDEN(
12315 bgp_redistribute_ipv4_ospf_rmap_metric,
12316 bgp_redistribute_ipv4_ospf_rmap_metric_hidden_cmd,
12317 "redistribute <ospf|table> (1-65535) route-map WORD metric (0-4294967295)",
12318 "Redistribute information from another routing protocol\n"
12319 "Open Shortest Path First (OSPFv2)\n"
12320 "Non-main Kernel Routing Table\n"
12321 "Instance ID/Table ID\n"
12322 "Route map reference\n"
12323 "Pointer to route-map entries\n"
12324 "Metric for redistributed routes\n"
12325 "Default metric\n")
12326
12327 DEFUN (bgp_redistribute_ipv4_ospf_metric_rmap,
12328 bgp_redistribute_ipv4_ospf_metric_rmap_cmd,
12329 "redistribute <ospf|table> (1-65535) metric (0-4294967295) route-map WORD",
12330 "Redistribute information from another routing protocol\n"
12331 "Open Shortest Path First (OSPFv2)\n"
12332 "Non-main Kernel Routing Table\n"
12333 "Instance ID/Table ID\n"
12334 "Metric for redistributed routes\n"
12335 "Default metric\n"
12336 "Route map reference\n"
12337 "Pointer to route-map entries\n")
12338 {
12339 VTY_DECLVAR_CONTEXT(bgp, bgp);
12340 int idx_ospf_table = 1;
12341 int idx_number = 2;
12342 int idx_number_2 = 4;
12343 int idx_word = 6;
12344 uint32_t metric;
12345 struct bgp_redist *red;
12346 unsigned short instance;
12347 int protocol;
12348 bool changed;
12349 struct route_map *route_map =
12350 route_map_lookup_warn_noexist(vty, argv[idx_word]->arg);
12351
12352 if (strncmp(argv[idx_ospf_table]->arg, "o", 1) == 0)
12353 protocol = ZEBRA_ROUTE_OSPF;
12354 else
12355 protocol = ZEBRA_ROUTE_TABLE;
12356
12357 instance = strtoul(argv[idx_number]->arg, NULL, 10);
12358 metric = strtoul(argv[idx_number_2]->arg, NULL, 10);
12359
12360 red = bgp_redist_add(bgp, AFI_IP, protocol, instance);
12361 changed = bgp_redistribute_metric_set(bgp, red, AFI_IP, protocol,
12362 metric);
12363 changed |=
12364 bgp_redistribute_rmap_set(red, argv[idx_word]->arg, route_map);
12365 return bgp_redistribute_set(bgp, AFI_IP, protocol, instance, changed);
12366 }
12367
12368 ALIAS_HIDDEN(
12369 bgp_redistribute_ipv4_ospf_metric_rmap,
12370 bgp_redistribute_ipv4_ospf_metric_rmap_hidden_cmd,
12371 "redistribute <ospf|table> (1-65535) metric (0-4294967295) route-map WORD",
12372 "Redistribute information from another routing protocol\n"
12373 "Open Shortest Path First (OSPFv2)\n"
12374 "Non-main Kernel Routing Table\n"
12375 "Instance ID/Table ID\n"
12376 "Metric for redistributed routes\n"
12377 "Default metric\n"
12378 "Route map reference\n"
12379 "Pointer to route-map entries\n")
12380
12381 DEFUN (no_bgp_redistribute_ipv4_ospf,
12382 no_bgp_redistribute_ipv4_ospf_cmd,
12383 "no redistribute <ospf|table> (1-65535) [metric (0-4294967295)] [route-map WORD]",
12384 NO_STR
12385 "Redistribute information from another routing protocol\n"
12386 "Open Shortest Path First (OSPFv2)\n"
12387 "Non-main Kernel Routing Table\n"
12388 "Instance ID/Table ID\n"
12389 "Metric for redistributed routes\n"
12390 "Default metric\n"
12391 "Route map reference\n"
12392 "Pointer to route-map entries\n")
12393 {
12394 VTY_DECLVAR_CONTEXT(bgp, bgp);
12395 int idx_ospf_table = 2;
12396 int idx_number = 3;
12397 unsigned short instance;
12398 int protocol;
12399
12400 if (strncmp(argv[idx_ospf_table]->arg, "o", 1) == 0)
12401 protocol = ZEBRA_ROUTE_OSPF;
12402 else
12403 protocol = ZEBRA_ROUTE_TABLE;
12404
12405 instance = strtoul(argv[idx_number]->arg, NULL, 10);
12406 return bgp_redistribute_unset(bgp, AFI_IP, protocol, instance);
12407 }
12408
12409 ALIAS_HIDDEN(
12410 no_bgp_redistribute_ipv4_ospf, no_bgp_redistribute_ipv4_ospf_hidden_cmd,
12411 "no redistribute <ospf|table> (1-65535) [metric (0-4294967295)] [route-map WORD]",
12412 NO_STR
12413 "Redistribute information from another routing protocol\n"
12414 "Open Shortest Path First (OSPFv2)\n"
12415 "Non-main Kernel Routing Table\n"
12416 "Instance ID/Table ID\n"
12417 "Metric for redistributed routes\n"
12418 "Default metric\n"
12419 "Route map reference\n"
12420 "Pointer to route-map entries\n")
12421
12422 DEFUN (no_bgp_redistribute_ipv4,
12423 no_bgp_redistribute_ipv4_cmd,
12424 "no redistribute " FRR_IP_REDIST_STR_BGPD " [metric (0-4294967295)] [route-map WORD]",
12425 NO_STR
12426 "Redistribute information from another routing protocol\n"
12427 FRR_IP_REDIST_HELP_STR_BGPD
12428 "Metric for redistributed routes\n"
12429 "Default metric\n"
12430 "Route map reference\n"
12431 "Pointer to route-map entries\n")
12432 {
12433 VTY_DECLVAR_CONTEXT(bgp, bgp);
12434 int idx_protocol = 2;
12435 int type;
12436
12437 type = proto_redistnum(AFI_IP, argv[idx_protocol]->text);
12438 if (type < 0) {
12439 vty_out(vty, "%% Invalid route type\n");
12440 return CMD_WARNING_CONFIG_FAILED;
12441 }
12442 return bgp_redistribute_unset(bgp, AFI_IP, type, 0);
12443 }
12444
12445 ALIAS_HIDDEN(
12446 no_bgp_redistribute_ipv4, no_bgp_redistribute_ipv4_hidden_cmd,
12447 "no redistribute " FRR_IP_REDIST_STR_BGPD
12448 " [metric (0-4294967295)] [route-map WORD]",
12449 NO_STR
12450 "Redistribute information from another routing protocol\n" FRR_IP_REDIST_HELP_STR_BGPD
12451 "Metric for redistributed routes\n"
12452 "Default metric\n"
12453 "Route map reference\n"
12454 "Pointer to route-map entries\n")
12455
12456 DEFUN (bgp_redistribute_ipv6,
12457 bgp_redistribute_ipv6_cmd,
12458 "redistribute " FRR_IP6_REDIST_STR_BGPD,
12459 "Redistribute information from another routing protocol\n"
12460 FRR_IP6_REDIST_HELP_STR_BGPD)
12461 {
12462 VTY_DECLVAR_CONTEXT(bgp, bgp);
12463 int idx_protocol = 1;
12464 int type;
12465
12466 type = proto_redistnum(AFI_IP6, argv[idx_protocol]->text);
12467 if (type < 0) {
12468 vty_out(vty, "%% Invalid route type\n");
12469 return CMD_WARNING_CONFIG_FAILED;
12470 }
12471
12472 bgp_redist_add(bgp, AFI_IP6, type, 0);
12473 return bgp_redistribute_set(bgp, AFI_IP6, type, 0, false);
12474 }
12475
12476 DEFUN (bgp_redistribute_ipv6_rmap,
12477 bgp_redistribute_ipv6_rmap_cmd,
12478 "redistribute " FRR_IP6_REDIST_STR_BGPD " route-map WORD",
12479 "Redistribute information from another routing protocol\n"
12480 FRR_IP6_REDIST_HELP_STR_BGPD
12481 "Route map reference\n"
12482 "Pointer to route-map entries\n")
12483 {
12484 VTY_DECLVAR_CONTEXT(bgp, bgp);
12485 int idx_protocol = 1;
12486 int idx_word = 3;
12487 int type;
12488 struct bgp_redist *red;
12489 bool changed;
12490 struct route_map *route_map =
12491 route_map_lookup_warn_noexist(vty, argv[idx_word]->arg);
12492
12493 type = proto_redistnum(AFI_IP6, argv[idx_protocol]->text);
12494 if (type < 0) {
12495 vty_out(vty, "%% Invalid route type\n");
12496 return CMD_WARNING_CONFIG_FAILED;
12497 }
12498
12499 red = bgp_redist_add(bgp, AFI_IP6, type, 0);
12500 changed =
12501 bgp_redistribute_rmap_set(red, argv[idx_word]->arg, route_map);
12502 return bgp_redistribute_set(bgp, AFI_IP6, type, 0, changed);
12503 }
12504
12505 DEFUN (bgp_redistribute_ipv6_metric,
12506 bgp_redistribute_ipv6_metric_cmd,
12507 "redistribute " FRR_IP6_REDIST_STR_BGPD " metric (0-4294967295)",
12508 "Redistribute information from another routing protocol\n"
12509 FRR_IP6_REDIST_HELP_STR_BGPD
12510 "Metric for redistributed routes\n"
12511 "Default metric\n")
12512 {
12513 VTY_DECLVAR_CONTEXT(bgp, bgp);
12514 int idx_protocol = 1;
12515 int idx_number = 3;
12516 int type;
12517 uint32_t metric;
12518 struct bgp_redist *red;
12519 bool changed;
12520
12521 type = proto_redistnum(AFI_IP6, argv[idx_protocol]->text);
12522 if (type < 0) {
12523 vty_out(vty, "%% Invalid route type\n");
12524 return CMD_WARNING_CONFIG_FAILED;
12525 }
12526 metric = strtoul(argv[idx_number]->arg, NULL, 10);
12527
12528 red = bgp_redist_add(bgp, AFI_IP6, type, 0);
12529 changed = bgp_redistribute_metric_set(bgp, red, AFI_IP6, type, metric);
12530 return bgp_redistribute_set(bgp, AFI_IP6, type, 0, changed);
12531 }
12532
12533 DEFUN (bgp_redistribute_ipv6_rmap_metric,
12534 bgp_redistribute_ipv6_rmap_metric_cmd,
12535 "redistribute " FRR_IP6_REDIST_STR_BGPD " route-map WORD metric (0-4294967295)",
12536 "Redistribute information from another routing protocol\n"
12537 FRR_IP6_REDIST_HELP_STR_BGPD
12538 "Route map reference\n"
12539 "Pointer to route-map entries\n"
12540 "Metric for redistributed routes\n"
12541 "Default metric\n")
12542 {
12543 VTY_DECLVAR_CONTEXT(bgp, bgp);
12544 int idx_protocol = 1;
12545 int idx_word = 3;
12546 int idx_number = 5;
12547 int type;
12548 uint32_t metric;
12549 struct bgp_redist *red;
12550 bool changed;
12551 struct route_map *route_map =
12552 route_map_lookup_warn_noexist(vty, argv[idx_word]->arg);
12553
12554 type = proto_redistnum(AFI_IP6, argv[idx_protocol]->text);
12555 if (type < 0) {
12556 vty_out(vty, "%% Invalid route type\n");
12557 return CMD_WARNING_CONFIG_FAILED;
12558 }
12559 metric = strtoul(argv[idx_number]->arg, NULL, 10);
12560
12561 red = bgp_redist_add(bgp, AFI_IP6, type, 0);
12562 changed =
12563 bgp_redistribute_rmap_set(red, argv[idx_word]->arg, route_map);
12564 changed |= bgp_redistribute_metric_set(bgp, red, AFI_IP6, type,
12565 metric);
12566 return bgp_redistribute_set(bgp, AFI_IP6, type, 0, changed);
12567 }
12568
12569 DEFUN (bgp_redistribute_ipv6_metric_rmap,
12570 bgp_redistribute_ipv6_metric_rmap_cmd,
12571 "redistribute " FRR_IP6_REDIST_STR_BGPD " metric (0-4294967295) route-map WORD",
12572 "Redistribute information from another routing protocol\n"
12573 FRR_IP6_REDIST_HELP_STR_BGPD
12574 "Metric for redistributed routes\n"
12575 "Default metric\n"
12576 "Route map reference\n"
12577 "Pointer to route-map entries\n")
12578 {
12579 VTY_DECLVAR_CONTEXT(bgp, bgp);
12580 int idx_protocol = 1;
12581 int idx_number = 3;
12582 int idx_word = 5;
12583 int type;
12584 uint32_t metric;
12585 struct bgp_redist *red;
12586 bool changed;
12587 struct route_map *route_map =
12588 route_map_lookup_warn_noexist(vty, argv[idx_word]->arg);
12589
12590 type = proto_redistnum(AFI_IP6, argv[idx_protocol]->text);
12591 if (type < 0) {
12592 vty_out(vty, "%% Invalid route type\n");
12593 return CMD_WARNING_CONFIG_FAILED;
12594 }
12595 metric = strtoul(argv[idx_number]->arg, NULL, 10);
12596
12597 red = bgp_redist_add(bgp, AFI_IP6, type, 0);
12598 changed = bgp_redistribute_metric_set(bgp, red, AFI_IP6, SAFI_UNICAST,
12599 metric);
12600 changed |=
12601 bgp_redistribute_rmap_set(red, argv[idx_word]->arg, route_map);
12602 return bgp_redistribute_set(bgp, AFI_IP6, type, 0, changed);
12603 }
12604
12605 DEFUN (no_bgp_redistribute_ipv6,
12606 no_bgp_redistribute_ipv6_cmd,
12607 "no redistribute " FRR_IP6_REDIST_STR_BGPD " [metric (0-4294967295)] [route-map WORD]",
12608 NO_STR
12609 "Redistribute information from another routing protocol\n"
12610 FRR_IP6_REDIST_HELP_STR_BGPD
12611 "Metric for redistributed routes\n"
12612 "Default metric\n"
12613 "Route map reference\n"
12614 "Pointer to route-map entries\n")
12615 {
12616 VTY_DECLVAR_CONTEXT(bgp, bgp);
12617 int idx_protocol = 2;
12618 int type;
12619
12620 type = proto_redistnum(AFI_IP6, argv[idx_protocol]->text);
12621 if (type < 0) {
12622 vty_out(vty, "%% Invalid route type\n");
12623 return CMD_WARNING_CONFIG_FAILED;
12624 }
12625
12626 return bgp_redistribute_unset(bgp, AFI_IP6, type, 0);
12627 }
12628
12629 void bgp_config_write_redistribute(struct vty *vty, struct bgp *bgp, afi_t afi,
12630 safi_t safi)
12631 {
12632 int i;
12633
12634 /* Unicast redistribution only. */
12635 if (safi != SAFI_UNICAST)
12636 return;
12637
12638 for (i = 0; i < ZEBRA_ROUTE_MAX; i++) {
12639 /* Redistribute BGP does not make sense. */
12640 if (i != ZEBRA_ROUTE_BGP) {
12641 struct list *red_list;
12642 struct listnode *node;
12643 struct bgp_redist *red;
12644
12645 red_list = bgp->redist[afi][i];
12646 if (!red_list)
12647 continue;
12648
12649 for (ALL_LIST_ELEMENTS_RO(red_list, node, red)) {
12650 /* "redistribute" configuration. */
12651 vty_out(vty, " redistribute %s",
12652 zebra_route_string(i));
12653 if (red->instance)
12654 vty_out(vty, " %d", red->instance);
12655 if (red->redist_metric_flag)
12656 vty_out(vty, " metric %u",
12657 red->redist_metric);
12658 if (red->rmap.name)
12659 vty_out(vty, " route-map %s",
12660 red->rmap.name);
12661 vty_out(vty, "\n");
12662 }
12663 }
12664 }
12665 }
12666
12667 /* This is part of the address-family block (unicast only) */
12668 void bgp_vpn_policy_config_write_afi(struct vty *vty, struct bgp *bgp,
12669 afi_t afi)
12670 {
12671 int indent = 2;
12672
12673 if (bgp->vpn_policy[afi].rmap_name[BGP_VPN_POLICY_DIR_FROMVPN]) {
12674 if (listcount(bgp->vpn_policy[afi].import_vrf))
12675 vty_out(vty, "%*simport vrf route-map %s\n", indent, "",
12676 bgp->vpn_policy[afi]
12677 .rmap_name[BGP_VPN_POLICY_DIR_FROMVPN]);
12678 else
12679 vty_out(vty, "%*sroute-map vpn import %s\n", indent, "",
12680 bgp->vpn_policy[afi]
12681 .rmap_name[BGP_VPN_POLICY_DIR_FROMVPN]);
12682 }
12683 if (CHECK_FLAG(bgp->af_flags[afi][SAFI_UNICAST],
12684 BGP_CONFIG_VRF_TO_VRF_IMPORT)
12685 || CHECK_FLAG(bgp->af_flags[afi][SAFI_UNICAST],
12686 BGP_CONFIG_VRF_TO_VRF_EXPORT))
12687 return;
12688
12689 if (CHECK_FLAG(bgp->vpn_policy[afi].flags,
12690 BGP_VPN_POLICY_TOVPN_LABEL_AUTO)) {
12691
12692 vty_out(vty, "%*slabel vpn export %s\n", indent, "", "auto");
12693
12694 } else {
12695 if (bgp->vpn_policy[afi].tovpn_label != MPLS_LABEL_NONE) {
12696 vty_out(vty, "%*slabel vpn export %u\n", indent, "",
12697 bgp->vpn_policy[afi].tovpn_label);
12698 }
12699 }
12700 if (CHECK_FLAG(bgp->vpn_policy[afi].flags,
12701 BGP_VPN_POLICY_TOVPN_RD_SET)) {
12702 char buf[RD_ADDRSTRLEN];
12703 vty_out(vty, "%*srd vpn export %s\n", indent, "",
12704 prefix_rd2str(&bgp->vpn_policy[afi].tovpn_rd, buf,
12705 sizeof(buf)));
12706 }
12707 if (CHECK_FLAG(bgp->vpn_policy[afi].flags,
12708 BGP_VPN_POLICY_TOVPN_NEXTHOP_SET)) {
12709
12710 char buf[PREFIX_STRLEN];
12711 if (inet_ntop(bgp->vpn_policy[afi].tovpn_nexthop.family,
12712 &bgp->vpn_policy[afi].tovpn_nexthop.u.prefix, buf,
12713 sizeof(buf))) {
12714
12715 vty_out(vty, "%*snexthop vpn export %s\n",
12716 indent, "", buf);
12717 }
12718 }
12719 if (bgp->vpn_policy[afi].rtlist[BGP_VPN_POLICY_DIR_FROMVPN]
12720 && bgp->vpn_policy[afi].rtlist[BGP_VPN_POLICY_DIR_TOVPN]
12721 && ecommunity_cmp(
12722 bgp->vpn_policy[afi].rtlist[BGP_VPN_POLICY_DIR_FROMVPN],
12723 bgp->vpn_policy[afi].rtlist[BGP_VPN_POLICY_DIR_TOVPN])) {
12724
12725 char *b = ecommunity_ecom2str(
12726 bgp->vpn_policy[afi].rtlist[BGP_VPN_POLICY_DIR_TOVPN],
12727 ECOMMUNITY_FORMAT_ROUTE_MAP, ECOMMUNITY_ROUTE_TARGET);
12728 vty_out(vty, "%*srt vpn both %s\n", indent, "", b);
12729 XFREE(MTYPE_ECOMMUNITY_STR, b);
12730 } else {
12731 if (bgp->vpn_policy[afi].rtlist[BGP_VPN_POLICY_DIR_FROMVPN]) {
12732 char *b = ecommunity_ecom2str(
12733 bgp->vpn_policy[afi]
12734 .rtlist[BGP_VPN_POLICY_DIR_FROMVPN],
12735 ECOMMUNITY_FORMAT_ROUTE_MAP,
12736 ECOMMUNITY_ROUTE_TARGET);
12737 vty_out(vty, "%*srt vpn import %s\n", indent, "", b);
12738 XFREE(MTYPE_ECOMMUNITY_STR, b);
12739 }
12740 if (bgp->vpn_policy[afi].rtlist[BGP_VPN_POLICY_DIR_TOVPN]) {
12741 char *b = ecommunity_ecom2str(
12742 bgp->vpn_policy[afi]
12743 .rtlist[BGP_VPN_POLICY_DIR_TOVPN],
12744 ECOMMUNITY_FORMAT_ROUTE_MAP,
12745 ECOMMUNITY_ROUTE_TARGET);
12746 vty_out(vty, "%*srt vpn export %s\n", indent, "", b);
12747 XFREE(MTYPE_ECOMMUNITY_STR, b);
12748 }
12749 }
12750
12751 if (bgp->vpn_policy[afi].rmap_name[BGP_VPN_POLICY_DIR_TOVPN])
12752 vty_out(vty, "%*sroute-map vpn export %s\n", indent, "",
12753 bgp->vpn_policy[afi]
12754 .rmap_name[BGP_VPN_POLICY_DIR_TOVPN]);
12755
12756 if (bgp->vpn_policy[afi].import_redirect_rtlist) {
12757 char *b = ecommunity_ecom2str(
12758 bgp->vpn_policy[afi]
12759 .import_redirect_rtlist,
12760 ECOMMUNITY_FORMAT_ROUTE_MAP,
12761 ECOMMUNITY_ROUTE_TARGET);
12762
12763 vty_out(vty, "%*srt redirect import %s\n", indent, "", b);
12764 XFREE(MTYPE_ECOMMUNITY_STR, b);
12765 }
12766 }
12767
12768
12769 /* BGP node structure. */
12770 static struct cmd_node bgp_node = {
12771 BGP_NODE, "%s(config-router)# ", 1,
12772 };
12773
12774 static struct cmd_node bgp_ipv4_unicast_node = {
12775 BGP_IPV4_NODE, "%s(config-router-af)# ", 1,
12776 };
12777
12778 static struct cmd_node bgp_ipv4_multicast_node = {
12779 BGP_IPV4M_NODE, "%s(config-router-af)# ", 1,
12780 };
12781
12782 static struct cmd_node bgp_ipv4_labeled_unicast_node = {
12783 BGP_IPV4L_NODE, "%s(config-router-af)# ", 1,
12784 };
12785
12786 static struct cmd_node bgp_ipv6_unicast_node = {
12787 BGP_IPV6_NODE, "%s(config-router-af)# ", 1,
12788 };
12789
12790 static struct cmd_node bgp_ipv6_multicast_node = {
12791 BGP_IPV6M_NODE, "%s(config-router-af)# ", 1,
12792 };
12793
12794 static struct cmd_node bgp_ipv6_labeled_unicast_node = {
12795 BGP_IPV6L_NODE, "%s(config-router-af)# ", 1,
12796 };
12797
12798 static struct cmd_node bgp_vpnv4_node = {BGP_VPNV4_NODE,
12799 "%s(config-router-af)# ", 1};
12800
12801 static struct cmd_node bgp_vpnv6_node = {BGP_VPNV6_NODE,
12802 "%s(config-router-af-vpnv6)# ", 1};
12803
12804 static struct cmd_node bgp_evpn_node = {BGP_EVPN_NODE,
12805 "%s(config-router-evpn)# ", 1};
12806
12807 static struct cmd_node bgp_evpn_vni_node = {BGP_EVPN_VNI_NODE,
12808 "%s(config-router-af-vni)# ", 1};
12809
12810 static struct cmd_node bgp_flowspecv4_node = {BGP_FLOWSPECV4_NODE,
12811 "%s(config-router-af)# ", 1};
12812
12813 static struct cmd_node bgp_flowspecv6_node = {BGP_FLOWSPECV6_NODE,
12814 "%s(config-router-af-vpnv6)# ", 1};
12815
12816 static void community_list_vty(void);
12817
12818 static void bgp_ac_neighbor(vector comps, struct cmd_token *token)
12819 {
12820 struct bgp *bgp;
12821 struct peer *peer;
12822 struct listnode *lnbgp, *lnpeer;
12823
12824 for (ALL_LIST_ELEMENTS_RO(bm->bgp, lnbgp, bgp)) {
12825 for (ALL_LIST_ELEMENTS_RO(bgp->peer, lnpeer, peer)) {
12826 /* only provide suggestions on the appropriate input
12827 * token type,
12828 * they'll otherwise show up multiple times */
12829 enum cmd_token_type match_type;
12830 char *name = peer->host;
12831
12832 if (peer->conf_if) {
12833 match_type = VARIABLE_TKN;
12834 name = peer->conf_if;
12835 } else if (strchr(peer->host, ':'))
12836 match_type = IPV6_TKN;
12837 else
12838 match_type = IPV4_TKN;
12839
12840 if (token->type != match_type)
12841 continue;
12842
12843 vector_set(comps, XSTRDUP(MTYPE_COMPLETION, name));
12844 }
12845 }
12846 }
12847
12848 static const struct cmd_variable_handler bgp_var_neighbor[] = {
12849 {.varname = "neighbor", .completions = bgp_ac_neighbor},
12850 {.varname = "neighbors", .completions = bgp_ac_neighbor},
12851 {.varname = "peer", .completions = bgp_ac_neighbor},
12852 {.completions = NULL}};
12853
12854 static void bgp_ac_peergroup(vector comps, struct cmd_token *token)
12855 {
12856 struct bgp *bgp;
12857 struct peer_group *group;
12858 struct listnode *lnbgp, *lnpeer;
12859
12860 for (ALL_LIST_ELEMENTS_RO(bm->bgp, lnbgp, bgp)) {
12861 for (ALL_LIST_ELEMENTS_RO(bgp->group, lnpeer, group))
12862 vector_set(comps, XSTRDUP(MTYPE_COMPLETION,
12863 group->name));
12864 }
12865 }
12866
12867 static const struct cmd_variable_handler bgp_var_peergroup[] = {
12868 {.tokenname = "PGNAME", .completions = bgp_ac_peergroup},
12869 {.completions = NULL} };
12870
12871 void bgp_vty_init(void)
12872 {
12873 cmd_variable_handler_register(bgp_var_neighbor);
12874 cmd_variable_handler_register(bgp_var_peergroup);
12875
12876 /* Install bgp top node. */
12877 install_node(&bgp_node, bgp_config_write);
12878 install_node(&bgp_ipv4_unicast_node, NULL);
12879 install_node(&bgp_ipv4_multicast_node, NULL);
12880 install_node(&bgp_ipv4_labeled_unicast_node, NULL);
12881 install_node(&bgp_ipv6_unicast_node, NULL);
12882 install_node(&bgp_ipv6_multicast_node, NULL);
12883 install_node(&bgp_ipv6_labeled_unicast_node, NULL);
12884 install_node(&bgp_vpnv4_node, NULL);
12885 install_node(&bgp_vpnv6_node, NULL);
12886 install_node(&bgp_evpn_node, NULL);
12887 install_node(&bgp_evpn_vni_node, NULL);
12888 install_node(&bgp_flowspecv4_node, NULL);
12889 install_node(&bgp_flowspecv6_node, NULL);
12890
12891 /* Install default VTY commands to new nodes. */
12892 install_default(BGP_NODE);
12893 install_default(BGP_IPV4_NODE);
12894 install_default(BGP_IPV4M_NODE);
12895 install_default(BGP_IPV4L_NODE);
12896 install_default(BGP_IPV6_NODE);
12897 install_default(BGP_IPV6M_NODE);
12898 install_default(BGP_IPV6L_NODE);
12899 install_default(BGP_VPNV4_NODE);
12900 install_default(BGP_VPNV6_NODE);
12901 install_default(BGP_FLOWSPECV4_NODE);
12902 install_default(BGP_FLOWSPECV6_NODE);
12903 install_default(BGP_EVPN_NODE);
12904 install_default(BGP_EVPN_VNI_NODE);
12905
12906 /* "bgp multiple-instance" commands. */
12907 install_element(CONFIG_NODE, &bgp_multiple_instance_cmd);
12908 install_element(CONFIG_NODE, &no_bgp_multiple_instance_cmd);
12909
12910 /* "bgp config-type" commands. */
12911 install_element(CONFIG_NODE, &bgp_config_type_cmd);
12912 install_element(CONFIG_NODE, &no_bgp_config_type_cmd);
12913
12914 /* "bgp local-mac" hidden commands. */
12915 install_element(CONFIG_NODE, &bgp_local_mac_cmd);
12916 install_element(CONFIG_NODE, &no_bgp_local_mac_cmd);
12917
12918 /* bgp route-map delay-timer commands. */
12919 install_element(CONFIG_NODE, &bgp_set_route_map_delay_timer_cmd);
12920 install_element(CONFIG_NODE, &no_bgp_set_route_map_delay_timer_cmd);
12921
12922 /* Dummy commands (Currently not supported) */
12923 install_element(BGP_NODE, &no_synchronization_cmd);
12924 install_element(BGP_NODE, &no_auto_summary_cmd);
12925
12926 /* "router bgp" commands. */
12927 install_element(CONFIG_NODE, &router_bgp_cmd);
12928
12929 /* "no router bgp" commands. */
12930 install_element(CONFIG_NODE, &no_router_bgp_cmd);
12931
12932 /* "bgp router-id" commands. */
12933 install_element(BGP_NODE, &bgp_router_id_cmd);
12934 install_element(BGP_NODE, &no_bgp_router_id_cmd);
12935
12936 /* "bgp cluster-id" commands. */
12937 install_element(BGP_NODE, &bgp_cluster_id_cmd);
12938 install_element(BGP_NODE, &no_bgp_cluster_id_cmd);
12939
12940 /* "bgp confederation" commands. */
12941 install_element(BGP_NODE, &bgp_confederation_identifier_cmd);
12942 install_element(BGP_NODE, &no_bgp_confederation_identifier_cmd);
12943
12944 /* "bgp confederation peers" commands. */
12945 install_element(BGP_NODE, &bgp_confederation_peers_cmd);
12946 install_element(BGP_NODE, &no_bgp_confederation_peers_cmd);
12947
12948 /* bgp max-med command */
12949 install_element(BGP_NODE, &bgp_maxmed_admin_cmd);
12950 install_element(BGP_NODE, &no_bgp_maxmed_admin_cmd);
12951 install_element(BGP_NODE, &bgp_maxmed_admin_medv_cmd);
12952 install_element(BGP_NODE, &bgp_maxmed_onstartup_cmd);
12953 install_element(BGP_NODE, &no_bgp_maxmed_onstartup_cmd);
12954
12955 /* bgp disable-ebgp-connected-nh-check */
12956 install_element(BGP_NODE, &bgp_disable_connected_route_check_cmd);
12957 install_element(BGP_NODE, &no_bgp_disable_connected_route_check_cmd);
12958
12959 /* bgp update-delay command */
12960 install_element(BGP_NODE, &bgp_update_delay_cmd);
12961 install_element(BGP_NODE, &no_bgp_update_delay_cmd);
12962 install_element(BGP_NODE, &bgp_update_delay_establish_wait_cmd);
12963
12964 install_element(BGP_NODE, &bgp_wpkt_quanta_cmd);
12965 install_element(BGP_NODE, &no_bgp_wpkt_quanta_cmd);
12966 install_element(BGP_NODE, &bgp_rpkt_quanta_cmd);
12967 install_element(BGP_NODE, &no_bgp_rpkt_quanta_cmd);
12968
12969 install_element(BGP_NODE, &bgp_coalesce_time_cmd);
12970 install_element(BGP_NODE, &no_bgp_coalesce_time_cmd);
12971
12972 /* "maximum-paths" commands. */
12973 install_element(BGP_NODE, &bgp_maxpaths_hidden_cmd);
12974 install_element(BGP_NODE, &no_bgp_maxpaths_hidden_cmd);
12975 install_element(BGP_IPV4_NODE, &bgp_maxpaths_cmd);
12976 install_element(BGP_IPV4_NODE, &no_bgp_maxpaths_cmd);
12977 install_element(BGP_IPV6_NODE, &bgp_maxpaths_cmd);
12978 install_element(BGP_IPV6_NODE, &no_bgp_maxpaths_cmd);
12979 install_element(BGP_NODE, &bgp_maxpaths_ibgp_hidden_cmd);
12980 install_element(BGP_NODE, &bgp_maxpaths_ibgp_cluster_hidden_cmd);
12981 install_element(BGP_NODE, &no_bgp_maxpaths_ibgp_hidden_cmd);
12982 install_element(BGP_IPV4_NODE, &bgp_maxpaths_ibgp_cmd);
12983 install_element(BGP_IPV4_NODE, &bgp_maxpaths_ibgp_cluster_cmd);
12984 install_element(BGP_IPV4_NODE, &no_bgp_maxpaths_ibgp_cmd);
12985 install_element(BGP_IPV6_NODE, &bgp_maxpaths_ibgp_cmd);
12986 install_element(BGP_IPV6_NODE, &bgp_maxpaths_ibgp_cluster_cmd);
12987 install_element(BGP_IPV6_NODE, &no_bgp_maxpaths_ibgp_cmd);
12988
12989 install_element(BGP_IPV6L_NODE, &bgp_maxpaths_cmd);
12990 install_element(BGP_IPV6L_NODE, &no_bgp_maxpaths_cmd);
12991 install_element(BGP_IPV6L_NODE, &bgp_maxpaths_ibgp_cmd);
12992 install_element(BGP_IPV6L_NODE, &bgp_maxpaths_ibgp_cluster_cmd);
12993 install_element(BGP_IPV6L_NODE, &no_bgp_maxpaths_ibgp_cmd);
12994
12995 /* "timers bgp" commands. */
12996 install_element(BGP_NODE, &bgp_timers_cmd);
12997 install_element(BGP_NODE, &no_bgp_timers_cmd);
12998
12999 /* route-map delay-timer commands - per instance for backwards compat.
13000 */
13001 install_element(BGP_NODE, &bgp_set_route_map_delay_timer_cmd);
13002 install_element(BGP_NODE, &no_bgp_set_route_map_delay_timer_cmd);
13003
13004 /* "bgp client-to-client reflection" commands */
13005 install_element(BGP_NODE, &no_bgp_client_to_client_reflection_cmd);
13006 install_element(BGP_NODE, &bgp_client_to_client_reflection_cmd);
13007
13008 /* "bgp always-compare-med" commands */
13009 install_element(BGP_NODE, &bgp_always_compare_med_cmd);
13010 install_element(BGP_NODE, &no_bgp_always_compare_med_cmd);
13011
13012 /* bgp ebgp-requires-policy */
13013 install_element(BGP_NODE, &bgp_ebgp_requires_policy_cmd);
13014 install_element(BGP_NODE, &no_bgp_ebgp_requires_policy_cmd);
13015
13016 /* "bgp deterministic-med" commands */
13017 install_element(BGP_NODE, &bgp_deterministic_med_cmd);
13018 install_element(BGP_NODE, &no_bgp_deterministic_med_cmd);
13019
13020 /* "bgp graceful-restart" commands */
13021 install_element(BGP_NODE, &bgp_graceful_restart_cmd);
13022 install_element(BGP_NODE, &no_bgp_graceful_restart_cmd);
13023 install_element(BGP_NODE, &bgp_graceful_restart_stalepath_time_cmd);
13024 install_element(BGP_NODE, &no_bgp_graceful_restart_stalepath_time_cmd);
13025 install_element(BGP_NODE, &bgp_graceful_restart_restart_time_cmd);
13026 install_element(BGP_NODE, &no_bgp_graceful_restart_restart_time_cmd);
13027
13028 install_element(BGP_NODE, &bgp_graceful_restart_preserve_fw_cmd);
13029 install_element(BGP_NODE, &no_bgp_graceful_restart_preserve_fw_cmd);
13030
13031 /* "bgp graceful-shutdown" commands */
13032 install_element(BGP_NODE, &bgp_graceful_shutdown_cmd);
13033 install_element(BGP_NODE, &no_bgp_graceful_shutdown_cmd);
13034
13035 /* "bgp fast-external-failover" commands */
13036 install_element(BGP_NODE, &bgp_fast_external_failover_cmd);
13037 install_element(BGP_NODE, &no_bgp_fast_external_failover_cmd);
13038
13039 /* "bgp enforce-first-as" commands */
13040 install_element(BGP_NODE, &bgp_enforce_first_as_cmd);
13041
13042 /* "bgp bestpath compare-routerid" commands */
13043 install_element(BGP_NODE, &bgp_bestpath_compare_router_id_cmd);
13044 install_element(BGP_NODE, &no_bgp_bestpath_compare_router_id_cmd);
13045
13046 /* "bgp bestpath as-path ignore" commands */
13047 install_element(BGP_NODE, &bgp_bestpath_aspath_ignore_cmd);
13048 install_element(BGP_NODE, &no_bgp_bestpath_aspath_ignore_cmd);
13049
13050 /* "bgp bestpath as-path confed" commands */
13051 install_element(BGP_NODE, &bgp_bestpath_aspath_confed_cmd);
13052 install_element(BGP_NODE, &no_bgp_bestpath_aspath_confed_cmd);
13053
13054 /* "bgp bestpath as-path multipath-relax" commands */
13055 install_element(BGP_NODE, &bgp_bestpath_aspath_multipath_relax_cmd);
13056 install_element(BGP_NODE, &no_bgp_bestpath_aspath_multipath_relax_cmd);
13057
13058 /* "bgp log-neighbor-changes" commands */
13059 install_element(BGP_NODE, &bgp_log_neighbor_changes_cmd);
13060 install_element(BGP_NODE, &no_bgp_log_neighbor_changes_cmd);
13061
13062 /* "bgp bestpath med" commands */
13063 install_element(BGP_NODE, &bgp_bestpath_med_cmd);
13064 install_element(BGP_NODE, &no_bgp_bestpath_med_cmd);
13065
13066 /* "no bgp default ipv4-unicast" commands. */
13067 install_element(BGP_NODE, &no_bgp_default_ipv4_unicast_cmd);
13068 install_element(BGP_NODE, &bgp_default_ipv4_unicast_cmd);
13069
13070 /* "bgp network import-check" commands. */
13071 install_element(BGP_NODE, &bgp_network_import_check_cmd);
13072 install_element(BGP_NODE, &bgp_network_import_check_exact_cmd);
13073 install_element(BGP_NODE, &no_bgp_network_import_check_cmd);
13074
13075 /* "bgp default local-preference" commands. */
13076 install_element(BGP_NODE, &bgp_default_local_preference_cmd);
13077 install_element(BGP_NODE, &no_bgp_default_local_preference_cmd);
13078
13079 /* bgp default show-hostname */
13080 install_element(BGP_NODE, &bgp_default_show_hostname_cmd);
13081 install_element(BGP_NODE, &no_bgp_default_show_hostname_cmd);
13082
13083 /* "bgp default subgroup-pkt-queue-max" commands. */
13084 install_element(BGP_NODE, &bgp_default_subgroup_pkt_queue_max_cmd);
13085 install_element(BGP_NODE, &no_bgp_default_subgroup_pkt_queue_max_cmd);
13086
13087 /* bgp ibgp-allow-policy-mods command */
13088 install_element(BGP_NODE, &bgp_rr_allow_outbound_policy_cmd);
13089 install_element(BGP_NODE, &no_bgp_rr_allow_outbound_policy_cmd);
13090
13091 /* "bgp listen limit" commands. */
13092 install_element(BGP_NODE, &bgp_listen_limit_cmd);
13093 install_element(BGP_NODE, &no_bgp_listen_limit_cmd);
13094
13095 /* "bgp listen range" commands. */
13096 install_element(BGP_NODE, &bgp_listen_range_cmd);
13097 install_element(BGP_NODE, &no_bgp_listen_range_cmd);
13098
13099 /* "bgp default shutdown" command */
13100 install_element(BGP_NODE, &bgp_default_shutdown_cmd);
13101
13102 /* "neighbor remote-as" commands. */
13103 install_element(BGP_NODE, &neighbor_remote_as_cmd);
13104 install_element(BGP_NODE, &neighbor_interface_config_cmd);
13105 install_element(BGP_NODE, &neighbor_interface_config_v6only_cmd);
13106 install_element(BGP_NODE, &neighbor_interface_config_remote_as_cmd);
13107 install_element(BGP_NODE,
13108 &neighbor_interface_v6only_config_remote_as_cmd);
13109 install_element(BGP_NODE, &no_neighbor_cmd);
13110 install_element(BGP_NODE, &no_neighbor_interface_config_cmd);
13111
13112 /* "neighbor peer-group" commands. */
13113 install_element(BGP_NODE, &neighbor_peer_group_cmd);
13114 install_element(BGP_NODE, &no_neighbor_peer_group_cmd);
13115 install_element(BGP_NODE,
13116 &no_neighbor_interface_peer_group_remote_as_cmd);
13117
13118 /* "neighbor local-as" commands. */
13119 install_element(BGP_NODE, &neighbor_local_as_cmd);
13120 install_element(BGP_NODE, &neighbor_local_as_no_prepend_cmd);
13121 install_element(BGP_NODE, &neighbor_local_as_no_prepend_replace_as_cmd);
13122 install_element(BGP_NODE, &no_neighbor_local_as_cmd);
13123
13124 /* "neighbor solo" commands. */
13125 install_element(BGP_NODE, &neighbor_solo_cmd);
13126 install_element(BGP_NODE, &no_neighbor_solo_cmd);
13127
13128 /* "neighbor password" commands. */
13129 install_element(BGP_NODE, &neighbor_password_cmd);
13130 install_element(BGP_NODE, &no_neighbor_password_cmd);
13131
13132 /* "neighbor activate" commands. */
13133 install_element(BGP_NODE, &neighbor_activate_hidden_cmd);
13134 install_element(BGP_IPV4_NODE, &neighbor_activate_cmd);
13135 install_element(BGP_IPV4M_NODE, &neighbor_activate_cmd);
13136 install_element(BGP_IPV4L_NODE, &neighbor_activate_cmd);
13137 install_element(BGP_IPV6_NODE, &neighbor_activate_cmd);
13138 install_element(BGP_IPV6M_NODE, &neighbor_activate_cmd);
13139 install_element(BGP_IPV6L_NODE, &neighbor_activate_cmd);
13140 install_element(BGP_VPNV4_NODE, &neighbor_activate_cmd);
13141 install_element(BGP_VPNV6_NODE, &neighbor_activate_cmd);
13142 install_element(BGP_FLOWSPECV4_NODE, &neighbor_activate_cmd);
13143 install_element(BGP_FLOWSPECV6_NODE, &neighbor_activate_cmd);
13144 install_element(BGP_EVPN_NODE, &neighbor_activate_cmd);
13145
13146 /* "no neighbor activate" commands. */
13147 install_element(BGP_NODE, &no_neighbor_activate_hidden_cmd);
13148 install_element(BGP_IPV4_NODE, &no_neighbor_activate_cmd);
13149 install_element(BGP_IPV4M_NODE, &no_neighbor_activate_cmd);
13150 install_element(BGP_IPV4L_NODE, &no_neighbor_activate_cmd);
13151 install_element(BGP_IPV6_NODE, &no_neighbor_activate_cmd);
13152 install_element(BGP_IPV6M_NODE, &no_neighbor_activate_cmd);
13153 install_element(BGP_IPV6L_NODE, &no_neighbor_activate_cmd);
13154 install_element(BGP_VPNV4_NODE, &no_neighbor_activate_cmd);
13155 install_element(BGP_VPNV6_NODE, &no_neighbor_activate_cmd);
13156 install_element(BGP_FLOWSPECV4_NODE, &no_neighbor_activate_cmd);
13157 install_element(BGP_FLOWSPECV6_NODE, &no_neighbor_activate_cmd);
13158 install_element(BGP_EVPN_NODE, &no_neighbor_activate_cmd);
13159
13160 /* "neighbor peer-group" set commands. */
13161 install_element(BGP_NODE, &neighbor_set_peer_group_cmd);
13162 install_element(BGP_IPV4_NODE, &neighbor_set_peer_group_hidden_cmd);
13163 install_element(BGP_IPV4M_NODE, &neighbor_set_peer_group_hidden_cmd);
13164 install_element(BGP_IPV6_NODE, &neighbor_set_peer_group_hidden_cmd);
13165 install_element(BGP_IPV6M_NODE, &neighbor_set_peer_group_hidden_cmd);
13166 install_element(BGP_IPV6L_NODE, &neighbor_set_peer_group_hidden_cmd);
13167 install_element(BGP_VPNV4_NODE, &neighbor_set_peer_group_hidden_cmd);
13168 install_element(BGP_VPNV6_NODE, &neighbor_set_peer_group_hidden_cmd);
13169 install_element(BGP_FLOWSPECV4_NODE,
13170 &neighbor_set_peer_group_hidden_cmd);
13171 install_element(BGP_FLOWSPECV6_NODE,
13172 &neighbor_set_peer_group_hidden_cmd);
13173
13174 /* "no neighbor peer-group unset" commands. */
13175 install_element(BGP_NODE, &no_neighbor_set_peer_group_cmd);
13176 install_element(BGP_IPV4_NODE, &no_neighbor_set_peer_group_hidden_cmd);
13177 install_element(BGP_IPV4M_NODE, &no_neighbor_set_peer_group_hidden_cmd);
13178 install_element(BGP_IPV6_NODE, &no_neighbor_set_peer_group_hidden_cmd);
13179 install_element(BGP_IPV6M_NODE, &no_neighbor_set_peer_group_hidden_cmd);
13180 install_element(BGP_IPV6L_NODE, &no_neighbor_set_peer_group_hidden_cmd);
13181 install_element(BGP_VPNV4_NODE, &no_neighbor_set_peer_group_hidden_cmd);
13182 install_element(BGP_VPNV6_NODE, &no_neighbor_set_peer_group_hidden_cmd);
13183 install_element(BGP_FLOWSPECV4_NODE,
13184 &no_neighbor_set_peer_group_hidden_cmd);
13185 install_element(BGP_FLOWSPECV6_NODE,
13186 &no_neighbor_set_peer_group_hidden_cmd);
13187
13188 /* "neighbor softreconfiguration inbound" commands.*/
13189 install_element(BGP_NODE, &neighbor_soft_reconfiguration_hidden_cmd);
13190 install_element(BGP_NODE, &no_neighbor_soft_reconfiguration_hidden_cmd);
13191 install_element(BGP_IPV4_NODE, &neighbor_soft_reconfiguration_cmd);
13192 install_element(BGP_IPV4_NODE, &no_neighbor_soft_reconfiguration_cmd);
13193 install_element(BGP_IPV4L_NODE, &neighbor_soft_reconfiguration_cmd);
13194 install_element(BGP_IPV4L_NODE, &no_neighbor_soft_reconfiguration_cmd);
13195 install_element(BGP_IPV4M_NODE, &neighbor_soft_reconfiguration_cmd);
13196 install_element(BGP_IPV4M_NODE, &no_neighbor_soft_reconfiguration_cmd);
13197 install_element(BGP_IPV6_NODE, &neighbor_soft_reconfiguration_cmd);
13198 install_element(BGP_IPV6_NODE, &no_neighbor_soft_reconfiguration_cmd);
13199 install_element(BGP_IPV6M_NODE, &neighbor_soft_reconfiguration_cmd);
13200 install_element(BGP_IPV6M_NODE, &no_neighbor_soft_reconfiguration_cmd);
13201 install_element(BGP_IPV6L_NODE, &neighbor_soft_reconfiguration_cmd);
13202 install_element(BGP_IPV6L_NODE, &no_neighbor_soft_reconfiguration_cmd);
13203 install_element(BGP_VPNV4_NODE, &neighbor_soft_reconfiguration_cmd);
13204 install_element(BGP_VPNV4_NODE, &no_neighbor_soft_reconfiguration_cmd);
13205 install_element(BGP_VPNV6_NODE, &neighbor_soft_reconfiguration_cmd);
13206 install_element(BGP_VPNV6_NODE, &no_neighbor_soft_reconfiguration_cmd);
13207 install_element(BGP_FLOWSPECV4_NODE,
13208 &neighbor_soft_reconfiguration_cmd);
13209 install_element(BGP_FLOWSPECV4_NODE,
13210 &no_neighbor_soft_reconfiguration_cmd);
13211 install_element(BGP_FLOWSPECV6_NODE,
13212 &neighbor_soft_reconfiguration_cmd);
13213 install_element(BGP_FLOWSPECV6_NODE,
13214 &no_neighbor_soft_reconfiguration_cmd);
13215 install_element(BGP_EVPN_NODE, &neighbor_soft_reconfiguration_cmd);
13216 install_element(BGP_EVPN_NODE, &no_neighbor_soft_reconfiguration_cmd);
13217
13218 /* "neighbor attribute-unchanged" commands. */
13219 install_element(BGP_NODE, &neighbor_attr_unchanged_hidden_cmd);
13220 install_element(BGP_NODE, &no_neighbor_attr_unchanged_hidden_cmd);
13221 install_element(BGP_IPV4_NODE, &neighbor_attr_unchanged_cmd);
13222 install_element(BGP_IPV4_NODE, &no_neighbor_attr_unchanged_cmd);
13223 install_element(BGP_IPV4M_NODE, &neighbor_attr_unchanged_cmd);
13224 install_element(BGP_IPV4M_NODE, &no_neighbor_attr_unchanged_cmd);
13225 install_element(BGP_IPV4L_NODE, &neighbor_attr_unchanged_cmd);
13226 install_element(BGP_IPV4L_NODE, &no_neighbor_attr_unchanged_cmd);
13227 install_element(BGP_IPV6_NODE, &neighbor_attr_unchanged_cmd);
13228 install_element(BGP_IPV6_NODE, &no_neighbor_attr_unchanged_cmd);
13229 install_element(BGP_IPV6M_NODE, &neighbor_attr_unchanged_cmd);
13230 install_element(BGP_IPV6M_NODE, &no_neighbor_attr_unchanged_cmd);
13231 install_element(BGP_IPV6L_NODE, &neighbor_attr_unchanged_cmd);
13232 install_element(BGP_IPV6L_NODE, &no_neighbor_attr_unchanged_cmd);
13233 install_element(BGP_VPNV4_NODE, &neighbor_attr_unchanged_cmd);
13234 install_element(BGP_VPNV4_NODE, &no_neighbor_attr_unchanged_cmd);
13235 install_element(BGP_VPNV6_NODE, &neighbor_attr_unchanged_cmd);
13236 install_element(BGP_VPNV6_NODE, &no_neighbor_attr_unchanged_cmd);
13237
13238 install_element(BGP_EVPN_NODE, &neighbor_attr_unchanged_cmd);
13239 install_element(BGP_EVPN_NODE, &no_neighbor_attr_unchanged_cmd);
13240
13241 /* "nexthop-local unchanged" commands */
13242 install_element(BGP_IPV6_NODE, &neighbor_nexthop_local_unchanged_cmd);
13243 install_element(BGP_IPV6_NODE,
13244 &no_neighbor_nexthop_local_unchanged_cmd);
13245
13246 /* "neighbor next-hop-self" commands. */
13247 install_element(BGP_NODE, &neighbor_nexthop_self_hidden_cmd);
13248 install_element(BGP_NODE, &no_neighbor_nexthop_self_hidden_cmd);
13249 install_element(BGP_IPV4_NODE, &neighbor_nexthop_self_cmd);
13250 install_element(BGP_IPV4_NODE, &no_neighbor_nexthop_self_cmd);
13251 install_element(BGP_IPV4M_NODE, &neighbor_nexthop_self_cmd);
13252 install_element(BGP_IPV4M_NODE, &no_neighbor_nexthop_self_cmd);
13253 install_element(BGP_IPV4L_NODE, &neighbor_nexthop_self_cmd);
13254 install_element(BGP_IPV4L_NODE, &no_neighbor_nexthop_self_cmd);
13255 install_element(BGP_IPV6_NODE, &neighbor_nexthop_self_cmd);
13256 install_element(BGP_IPV6_NODE, &no_neighbor_nexthop_self_cmd);
13257 install_element(BGP_IPV6M_NODE, &neighbor_nexthop_self_cmd);
13258 install_element(BGP_IPV6M_NODE, &no_neighbor_nexthop_self_cmd);
13259 install_element(BGP_IPV6L_NODE, &neighbor_nexthop_self_cmd);
13260 install_element(BGP_IPV6L_NODE, &no_neighbor_nexthop_self_cmd);
13261 install_element(BGP_VPNV4_NODE, &neighbor_nexthop_self_cmd);
13262 install_element(BGP_VPNV4_NODE, &no_neighbor_nexthop_self_cmd);
13263 install_element(BGP_VPNV6_NODE, &neighbor_nexthop_self_cmd);
13264 install_element(BGP_VPNV6_NODE, &no_neighbor_nexthop_self_cmd);
13265 install_element(BGP_EVPN_NODE, &neighbor_nexthop_self_cmd);
13266 install_element(BGP_EVPN_NODE, &no_neighbor_nexthop_self_cmd);
13267
13268 /* "neighbor next-hop-self force" commands. */
13269 install_element(BGP_NODE, &neighbor_nexthop_self_force_hidden_cmd);
13270 install_element(BGP_NODE, &no_neighbor_nexthop_self_force_hidden_cmd);
13271 install_element(BGP_NODE, &neighbor_nexthop_self_all_hidden_cmd);
13272 install_element(BGP_NODE, &no_neighbor_nexthop_self_all_hidden_cmd);
13273 install_element(BGP_IPV4_NODE, &neighbor_nexthop_self_force_cmd);
13274 install_element(BGP_IPV4_NODE, &no_neighbor_nexthop_self_force_cmd);
13275 install_element(BGP_IPV4_NODE, &neighbor_nexthop_self_all_hidden_cmd);
13276 install_element(BGP_IPV4_NODE,
13277 &no_neighbor_nexthop_self_all_hidden_cmd);
13278 install_element(BGP_IPV4M_NODE, &neighbor_nexthop_self_force_cmd);
13279 install_element(BGP_IPV4M_NODE, &no_neighbor_nexthop_self_force_cmd);
13280 install_element(BGP_IPV4M_NODE, &neighbor_nexthop_self_all_hidden_cmd);
13281 install_element(BGP_IPV4M_NODE,
13282 &no_neighbor_nexthop_self_all_hidden_cmd);
13283 install_element(BGP_IPV4L_NODE, &neighbor_nexthop_self_force_cmd);
13284 install_element(BGP_IPV4L_NODE, &no_neighbor_nexthop_self_force_cmd);
13285 install_element(BGP_IPV4L_NODE, &neighbor_nexthop_self_all_hidden_cmd);
13286 install_element(BGP_IPV4L_NODE,
13287 &no_neighbor_nexthop_self_all_hidden_cmd);
13288 install_element(BGP_IPV6_NODE, &neighbor_nexthop_self_force_cmd);
13289 install_element(BGP_IPV6_NODE, &no_neighbor_nexthop_self_force_cmd);
13290 install_element(BGP_IPV6_NODE, &neighbor_nexthop_self_all_hidden_cmd);
13291 install_element(BGP_IPV6_NODE,
13292 &no_neighbor_nexthop_self_all_hidden_cmd);
13293 install_element(BGP_IPV6M_NODE, &neighbor_nexthop_self_force_cmd);
13294 install_element(BGP_IPV6M_NODE, &no_neighbor_nexthop_self_force_cmd);
13295 install_element(BGP_IPV6M_NODE, &neighbor_nexthop_self_all_hidden_cmd);
13296 install_element(BGP_IPV6M_NODE,
13297 &no_neighbor_nexthop_self_all_hidden_cmd);
13298 install_element(BGP_IPV6L_NODE, &neighbor_nexthop_self_force_cmd);
13299 install_element(BGP_IPV6L_NODE, &no_neighbor_nexthop_self_force_cmd);
13300 install_element(BGP_IPV6L_NODE, &neighbor_nexthop_self_all_hidden_cmd);
13301 install_element(BGP_IPV6L_NODE,
13302 &no_neighbor_nexthop_self_all_hidden_cmd);
13303 install_element(BGP_VPNV4_NODE, &neighbor_nexthop_self_force_cmd);
13304 install_element(BGP_VPNV4_NODE, &no_neighbor_nexthop_self_force_cmd);
13305 install_element(BGP_VPNV4_NODE, &neighbor_nexthop_self_all_hidden_cmd);
13306 install_element(BGP_VPNV4_NODE,
13307 &no_neighbor_nexthop_self_all_hidden_cmd);
13308 install_element(BGP_VPNV6_NODE, &neighbor_nexthop_self_force_cmd);
13309 install_element(BGP_VPNV6_NODE, &no_neighbor_nexthop_self_force_cmd);
13310 install_element(BGP_VPNV6_NODE, &neighbor_nexthop_self_all_hidden_cmd);
13311 install_element(BGP_VPNV6_NODE,
13312 &no_neighbor_nexthop_self_all_hidden_cmd);
13313
13314 /* "neighbor as-override" commands. */
13315 install_element(BGP_NODE, &neighbor_as_override_hidden_cmd);
13316 install_element(BGP_NODE, &no_neighbor_as_override_hidden_cmd);
13317 install_element(BGP_IPV4_NODE, &neighbor_as_override_cmd);
13318 install_element(BGP_IPV4_NODE, &no_neighbor_as_override_cmd);
13319 install_element(BGP_IPV4M_NODE, &neighbor_as_override_cmd);
13320 install_element(BGP_IPV4M_NODE, &no_neighbor_as_override_cmd);
13321 install_element(BGP_IPV4L_NODE, &neighbor_as_override_cmd);
13322 install_element(BGP_IPV4L_NODE, &no_neighbor_as_override_cmd);
13323 install_element(BGP_IPV6_NODE, &neighbor_as_override_cmd);
13324 install_element(BGP_IPV6_NODE, &no_neighbor_as_override_cmd);
13325 install_element(BGP_IPV6M_NODE, &neighbor_as_override_cmd);
13326 install_element(BGP_IPV6M_NODE, &no_neighbor_as_override_cmd);
13327 install_element(BGP_IPV6L_NODE, &neighbor_as_override_cmd);
13328 install_element(BGP_IPV6L_NODE, &no_neighbor_as_override_cmd);
13329 install_element(BGP_VPNV4_NODE, &neighbor_as_override_cmd);
13330 install_element(BGP_VPNV4_NODE, &no_neighbor_as_override_cmd);
13331 install_element(BGP_VPNV6_NODE, &neighbor_as_override_cmd);
13332 install_element(BGP_VPNV6_NODE, &no_neighbor_as_override_cmd);
13333
13334 /* "neighbor remove-private-AS" commands. */
13335 install_element(BGP_NODE, &neighbor_remove_private_as_hidden_cmd);
13336 install_element(BGP_NODE, &no_neighbor_remove_private_as_hidden_cmd);
13337 install_element(BGP_NODE, &neighbor_remove_private_as_all_hidden_cmd);
13338 install_element(BGP_NODE,
13339 &no_neighbor_remove_private_as_all_hidden_cmd);
13340 install_element(BGP_NODE,
13341 &neighbor_remove_private_as_replace_as_hidden_cmd);
13342 install_element(BGP_NODE,
13343 &no_neighbor_remove_private_as_replace_as_hidden_cmd);
13344 install_element(BGP_NODE,
13345 &neighbor_remove_private_as_all_replace_as_hidden_cmd);
13346 install_element(
13347 BGP_NODE,
13348 &no_neighbor_remove_private_as_all_replace_as_hidden_cmd);
13349 install_element(BGP_IPV4_NODE, &neighbor_remove_private_as_cmd);
13350 install_element(BGP_IPV4_NODE, &no_neighbor_remove_private_as_cmd);
13351 install_element(BGP_IPV4_NODE, &neighbor_remove_private_as_all_cmd);
13352 install_element(BGP_IPV4_NODE, &no_neighbor_remove_private_as_all_cmd);
13353 install_element(BGP_IPV4_NODE,
13354 &neighbor_remove_private_as_replace_as_cmd);
13355 install_element(BGP_IPV4_NODE,
13356 &no_neighbor_remove_private_as_replace_as_cmd);
13357 install_element(BGP_IPV4_NODE,
13358 &neighbor_remove_private_as_all_replace_as_cmd);
13359 install_element(BGP_IPV4_NODE,
13360 &no_neighbor_remove_private_as_all_replace_as_cmd);
13361 install_element(BGP_IPV4M_NODE, &neighbor_remove_private_as_cmd);
13362 install_element(BGP_IPV4M_NODE, &no_neighbor_remove_private_as_cmd);
13363 install_element(BGP_IPV4M_NODE, &neighbor_remove_private_as_all_cmd);
13364 install_element(BGP_IPV4M_NODE, &no_neighbor_remove_private_as_all_cmd);
13365 install_element(BGP_IPV4M_NODE,
13366 &neighbor_remove_private_as_replace_as_cmd);
13367 install_element(BGP_IPV4M_NODE,
13368 &no_neighbor_remove_private_as_replace_as_cmd);
13369 install_element(BGP_IPV4M_NODE,
13370 &neighbor_remove_private_as_all_replace_as_cmd);
13371 install_element(BGP_IPV4M_NODE,
13372 &no_neighbor_remove_private_as_all_replace_as_cmd);
13373 install_element(BGP_IPV4L_NODE, &neighbor_remove_private_as_cmd);
13374 install_element(BGP_IPV4L_NODE, &no_neighbor_remove_private_as_cmd);
13375 install_element(BGP_IPV4L_NODE, &neighbor_remove_private_as_all_cmd);
13376 install_element(BGP_IPV4L_NODE, &no_neighbor_remove_private_as_all_cmd);
13377 install_element(BGP_IPV4L_NODE,
13378 &neighbor_remove_private_as_replace_as_cmd);
13379 install_element(BGP_IPV4L_NODE,
13380 &no_neighbor_remove_private_as_replace_as_cmd);
13381 install_element(BGP_IPV4L_NODE,
13382 &neighbor_remove_private_as_all_replace_as_cmd);
13383 install_element(BGP_IPV4L_NODE,
13384 &no_neighbor_remove_private_as_all_replace_as_cmd);
13385 install_element(BGP_IPV6_NODE, &neighbor_remove_private_as_cmd);
13386 install_element(BGP_IPV6_NODE, &no_neighbor_remove_private_as_cmd);
13387 install_element(BGP_IPV6_NODE, &neighbor_remove_private_as_all_cmd);
13388 install_element(BGP_IPV6_NODE, &no_neighbor_remove_private_as_all_cmd);
13389 install_element(BGP_IPV6_NODE,
13390 &neighbor_remove_private_as_replace_as_cmd);
13391 install_element(BGP_IPV6_NODE,
13392 &no_neighbor_remove_private_as_replace_as_cmd);
13393 install_element(BGP_IPV6_NODE,
13394 &neighbor_remove_private_as_all_replace_as_cmd);
13395 install_element(BGP_IPV6_NODE,
13396 &no_neighbor_remove_private_as_all_replace_as_cmd);
13397 install_element(BGP_IPV6M_NODE, &neighbor_remove_private_as_cmd);
13398 install_element(BGP_IPV6M_NODE, &no_neighbor_remove_private_as_cmd);
13399 install_element(BGP_IPV6M_NODE, &neighbor_remove_private_as_all_cmd);
13400 install_element(BGP_IPV6M_NODE, &no_neighbor_remove_private_as_all_cmd);
13401 install_element(BGP_IPV6M_NODE,
13402 &neighbor_remove_private_as_replace_as_cmd);
13403 install_element(BGP_IPV6M_NODE,
13404 &no_neighbor_remove_private_as_replace_as_cmd);
13405 install_element(BGP_IPV6M_NODE,
13406 &neighbor_remove_private_as_all_replace_as_cmd);
13407 install_element(BGP_IPV6M_NODE,
13408 &no_neighbor_remove_private_as_all_replace_as_cmd);
13409 install_element(BGP_IPV6L_NODE, &neighbor_remove_private_as_cmd);
13410 install_element(BGP_IPV6L_NODE, &no_neighbor_remove_private_as_cmd);
13411 install_element(BGP_IPV6L_NODE, &neighbor_remove_private_as_all_cmd);
13412 install_element(BGP_IPV6L_NODE, &no_neighbor_remove_private_as_all_cmd);
13413 install_element(BGP_IPV6L_NODE,
13414 &neighbor_remove_private_as_replace_as_cmd);
13415 install_element(BGP_IPV6L_NODE,
13416 &no_neighbor_remove_private_as_replace_as_cmd);
13417 install_element(BGP_IPV6L_NODE,
13418 &neighbor_remove_private_as_all_replace_as_cmd);
13419 install_element(BGP_IPV6L_NODE,
13420 &no_neighbor_remove_private_as_all_replace_as_cmd);
13421 install_element(BGP_VPNV4_NODE, &neighbor_remove_private_as_cmd);
13422 install_element(BGP_VPNV4_NODE, &no_neighbor_remove_private_as_cmd);
13423 install_element(BGP_VPNV4_NODE, &neighbor_remove_private_as_all_cmd);
13424 install_element(BGP_VPNV4_NODE, &no_neighbor_remove_private_as_all_cmd);
13425 install_element(BGP_VPNV4_NODE,
13426 &neighbor_remove_private_as_replace_as_cmd);
13427 install_element(BGP_VPNV4_NODE,
13428 &no_neighbor_remove_private_as_replace_as_cmd);
13429 install_element(BGP_VPNV4_NODE,
13430 &neighbor_remove_private_as_all_replace_as_cmd);
13431 install_element(BGP_VPNV4_NODE,
13432 &no_neighbor_remove_private_as_all_replace_as_cmd);
13433 install_element(BGP_VPNV6_NODE, &neighbor_remove_private_as_cmd);
13434 install_element(BGP_VPNV6_NODE, &no_neighbor_remove_private_as_cmd);
13435 install_element(BGP_VPNV6_NODE, &neighbor_remove_private_as_all_cmd);
13436 install_element(BGP_VPNV6_NODE, &no_neighbor_remove_private_as_all_cmd);
13437 install_element(BGP_VPNV6_NODE,
13438 &neighbor_remove_private_as_replace_as_cmd);
13439 install_element(BGP_VPNV6_NODE,
13440 &no_neighbor_remove_private_as_replace_as_cmd);
13441 install_element(BGP_VPNV6_NODE,
13442 &neighbor_remove_private_as_all_replace_as_cmd);
13443 install_element(BGP_VPNV6_NODE,
13444 &no_neighbor_remove_private_as_all_replace_as_cmd);
13445
13446 /* "neighbor send-community" commands.*/
13447 install_element(BGP_NODE, &neighbor_send_community_hidden_cmd);
13448 install_element(BGP_NODE, &neighbor_send_community_type_hidden_cmd);
13449 install_element(BGP_NODE, &no_neighbor_send_community_hidden_cmd);
13450 install_element(BGP_NODE, &no_neighbor_send_community_type_hidden_cmd);
13451 install_element(BGP_IPV4_NODE, &neighbor_send_community_cmd);
13452 install_element(BGP_IPV4_NODE, &neighbor_send_community_type_cmd);
13453 install_element(BGP_IPV4_NODE, &no_neighbor_send_community_cmd);
13454 install_element(BGP_IPV4_NODE, &no_neighbor_send_community_type_cmd);
13455 install_element(BGP_IPV4M_NODE, &neighbor_send_community_cmd);
13456 install_element(BGP_IPV4M_NODE, &neighbor_send_community_type_cmd);
13457 install_element(BGP_IPV4M_NODE, &no_neighbor_send_community_cmd);
13458 install_element(BGP_IPV4M_NODE, &no_neighbor_send_community_type_cmd);
13459 install_element(BGP_IPV4L_NODE, &neighbor_send_community_cmd);
13460 install_element(BGP_IPV4L_NODE, &neighbor_send_community_type_cmd);
13461 install_element(BGP_IPV4L_NODE, &no_neighbor_send_community_cmd);
13462 install_element(BGP_IPV4L_NODE, &no_neighbor_send_community_type_cmd);
13463 install_element(BGP_IPV6_NODE, &neighbor_send_community_cmd);
13464 install_element(BGP_IPV6_NODE, &neighbor_send_community_type_cmd);
13465 install_element(BGP_IPV6_NODE, &no_neighbor_send_community_cmd);
13466 install_element(BGP_IPV6_NODE, &no_neighbor_send_community_type_cmd);
13467 install_element(BGP_IPV6M_NODE, &neighbor_send_community_cmd);
13468 install_element(BGP_IPV6M_NODE, &neighbor_send_community_type_cmd);
13469 install_element(BGP_IPV6M_NODE, &no_neighbor_send_community_cmd);
13470 install_element(BGP_IPV6M_NODE, &no_neighbor_send_community_type_cmd);
13471 install_element(BGP_IPV6L_NODE, &neighbor_send_community_cmd);
13472 install_element(BGP_IPV6L_NODE, &neighbor_send_community_type_cmd);
13473 install_element(BGP_IPV6L_NODE, &no_neighbor_send_community_cmd);
13474 install_element(BGP_IPV6L_NODE, &no_neighbor_send_community_type_cmd);
13475 install_element(BGP_VPNV4_NODE, &neighbor_send_community_cmd);
13476 install_element(BGP_VPNV4_NODE, &neighbor_send_community_type_cmd);
13477 install_element(BGP_VPNV4_NODE, &no_neighbor_send_community_cmd);
13478 install_element(BGP_VPNV4_NODE, &no_neighbor_send_community_type_cmd);
13479 install_element(BGP_VPNV6_NODE, &neighbor_send_community_cmd);
13480 install_element(BGP_VPNV6_NODE, &neighbor_send_community_type_cmd);
13481 install_element(BGP_VPNV6_NODE, &no_neighbor_send_community_cmd);
13482 install_element(BGP_VPNV6_NODE, &no_neighbor_send_community_type_cmd);
13483
13484 /* "neighbor route-reflector" commands.*/
13485 install_element(BGP_NODE, &neighbor_route_reflector_client_hidden_cmd);
13486 install_element(BGP_NODE,
13487 &no_neighbor_route_reflector_client_hidden_cmd);
13488 install_element(BGP_IPV4_NODE, &neighbor_route_reflector_client_cmd);
13489 install_element(BGP_IPV4_NODE, &no_neighbor_route_reflector_client_cmd);
13490 install_element(BGP_IPV4M_NODE, &neighbor_route_reflector_client_cmd);
13491 install_element(BGP_IPV4M_NODE,
13492 &no_neighbor_route_reflector_client_cmd);
13493 install_element(BGP_IPV4L_NODE, &neighbor_route_reflector_client_cmd);
13494 install_element(BGP_IPV4L_NODE,
13495 &no_neighbor_route_reflector_client_cmd);
13496 install_element(BGP_IPV6_NODE, &neighbor_route_reflector_client_cmd);
13497 install_element(BGP_IPV6_NODE, &no_neighbor_route_reflector_client_cmd);
13498 install_element(BGP_IPV6M_NODE, &neighbor_route_reflector_client_cmd);
13499 install_element(BGP_IPV6M_NODE,
13500 &no_neighbor_route_reflector_client_cmd);
13501 install_element(BGP_IPV6L_NODE, &neighbor_route_reflector_client_cmd);
13502 install_element(BGP_IPV6L_NODE,
13503 &no_neighbor_route_reflector_client_cmd);
13504 install_element(BGP_VPNV4_NODE, &neighbor_route_reflector_client_cmd);
13505 install_element(BGP_VPNV4_NODE,
13506 &no_neighbor_route_reflector_client_cmd);
13507 install_element(BGP_VPNV6_NODE, &neighbor_route_reflector_client_cmd);
13508 install_element(BGP_VPNV6_NODE,
13509 &no_neighbor_route_reflector_client_cmd);
13510 install_element(BGP_FLOWSPECV4_NODE,
13511 &neighbor_route_reflector_client_cmd);
13512 install_element(BGP_FLOWSPECV4_NODE,
13513 &no_neighbor_route_reflector_client_cmd);
13514 install_element(BGP_FLOWSPECV6_NODE,
13515 &neighbor_route_reflector_client_cmd);
13516 install_element(BGP_FLOWSPECV6_NODE,
13517 &no_neighbor_route_reflector_client_cmd);
13518 install_element(BGP_EVPN_NODE, &neighbor_route_reflector_client_cmd);
13519 install_element(BGP_EVPN_NODE, &no_neighbor_route_reflector_client_cmd);
13520
13521 /* "neighbor route-server" commands.*/
13522 install_element(BGP_NODE, &neighbor_route_server_client_hidden_cmd);
13523 install_element(BGP_NODE, &no_neighbor_route_server_client_hidden_cmd);
13524 install_element(BGP_IPV4_NODE, &neighbor_route_server_client_cmd);
13525 install_element(BGP_IPV4_NODE, &no_neighbor_route_server_client_cmd);
13526 install_element(BGP_IPV4M_NODE, &neighbor_route_server_client_cmd);
13527 install_element(BGP_IPV4M_NODE, &no_neighbor_route_server_client_cmd);
13528 install_element(BGP_IPV4L_NODE, &neighbor_route_server_client_cmd);
13529 install_element(BGP_IPV4L_NODE, &no_neighbor_route_server_client_cmd);
13530 install_element(BGP_IPV6_NODE, &neighbor_route_server_client_cmd);
13531 install_element(BGP_IPV6_NODE, &no_neighbor_route_server_client_cmd);
13532 install_element(BGP_IPV6M_NODE, &neighbor_route_server_client_cmd);
13533 install_element(BGP_IPV6M_NODE, &no_neighbor_route_server_client_cmd);
13534 install_element(BGP_IPV6L_NODE, &neighbor_route_server_client_cmd);
13535 install_element(BGP_IPV6L_NODE, &no_neighbor_route_server_client_cmd);
13536 install_element(BGP_VPNV4_NODE, &neighbor_route_server_client_cmd);
13537 install_element(BGP_VPNV4_NODE, &no_neighbor_route_server_client_cmd);
13538 install_element(BGP_VPNV6_NODE, &neighbor_route_server_client_cmd);
13539 install_element(BGP_VPNV6_NODE, &no_neighbor_route_server_client_cmd);
13540 install_element(BGP_EVPN_NODE, &neighbor_route_server_client_cmd);
13541 install_element(BGP_EVPN_NODE, &no_neighbor_route_server_client_cmd);
13542 install_element(BGP_FLOWSPECV4_NODE, &neighbor_route_server_client_cmd);
13543 install_element(BGP_FLOWSPECV4_NODE,
13544 &no_neighbor_route_server_client_cmd);
13545 install_element(BGP_FLOWSPECV6_NODE, &neighbor_route_server_client_cmd);
13546 install_element(BGP_FLOWSPECV6_NODE,
13547 &no_neighbor_route_server_client_cmd);
13548
13549 /* "neighbor addpath-tx-all-paths" commands.*/
13550 install_element(BGP_NODE, &neighbor_addpath_tx_all_paths_hidden_cmd);
13551 install_element(BGP_NODE, &no_neighbor_addpath_tx_all_paths_hidden_cmd);
13552 install_element(BGP_IPV4_NODE, &neighbor_addpath_tx_all_paths_cmd);
13553 install_element(BGP_IPV4_NODE, &no_neighbor_addpath_tx_all_paths_cmd);
13554 install_element(BGP_IPV4M_NODE, &neighbor_addpath_tx_all_paths_cmd);
13555 install_element(BGP_IPV4M_NODE, &no_neighbor_addpath_tx_all_paths_cmd);
13556 install_element(BGP_IPV4L_NODE, &neighbor_addpath_tx_all_paths_cmd);
13557 install_element(BGP_IPV4L_NODE, &no_neighbor_addpath_tx_all_paths_cmd);
13558 install_element(BGP_IPV6_NODE, &neighbor_addpath_tx_all_paths_cmd);
13559 install_element(BGP_IPV6_NODE, &no_neighbor_addpath_tx_all_paths_cmd);
13560 install_element(BGP_IPV6M_NODE, &neighbor_addpath_tx_all_paths_cmd);
13561 install_element(BGP_IPV6M_NODE, &no_neighbor_addpath_tx_all_paths_cmd);
13562 install_element(BGP_IPV6L_NODE, &neighbor_addpath_tx_all_paths_cmd);
13563 install_element(BGP_IPV6L_NODE, &no_neighbor_addpath_tx_all_paths_cmd);
13564 install_element(BGP_VPNV4_NODE, &neighbor_addpath_tx_all_paths_cmd);
13565 install_element(BGP_VPNV4_NODE, &no_neighbor_addpath_tx_all_paths_cmd);
13566 install_element(BGP_VPNV6_NODE, &neighbor_addpath_tx_all_paths_cmd);
13567 install_element(BGP_VPNV6_NODE, &no_neighbor_addpath_tx_all_paths_cmd);
13568
13569 /* "neighbor addpath-tx-bestpath-per-AS" commands.*/
13570 install_element(BGP_NODE,
13571 &neighbor_addpath_tx_bestpath_per_as_hidden_cmd);
13572 install_element(BGP_NODE,
13573 &no_neighbor_addpath_tx_bestpath_per_as_hidden_cmd);
13574 install_element(BGP_IPV4_NODE,
13575 &neighbor_addpath_tx_bestpath_per_as_cmd);
13576 install_element(BGP_IPV4_NODE,
13577 &no_neighbor_addpath_tx_bestpath_per_as_cmd);
13578 install_element(BGP_IPV4M_NODE,
13579 &neighbor_addpath_tx_bestpath_per_as_cmd);
13580 install_element(BGP_IPV4M_NODE,
13581 &no_neighbor_addpath_tx_bestpath_per_as_cmd);
13582 install_element(BGP_IPV4L_NODE,
13583 &neighbor_addpath_tx_bestpath_per_as_cmd);
13584 install_element(BGP_IPV4L_NODE,
13585 &no_neighbor_addpath_tx_bestpath_per_as_cmd);
13586 install_element(BGP_IPV6_NODE,
13587 &neighbor_addpath_tx_bestpath_per_as_cmd);
13588 install_element(BGP_IPV6_NODE,
13589 &no_neighbor_addpath_tx_bestpath_per_as_cmd);
13590 install_element(BGP_IPV6M_NODE,
13591 &neighbor_addpath_tx_bestpath_per_as_cmd);
13592 install_element(BGP_IPV6M_NODE,
13593 &no_neighbor_addpath_tx_bestpath_per_as_cmd);
13594 install_element(BGP_IPV6L_NODE,
13595 &neighbor_addpath_tx_bestpath_per_as_cmd);
13596 install_element(BGP_IPV6L_NODE,
13597 &no_neighbor_addpath_tx_bestpath_per_as_cmd);
13598 install_element(BGP_VPNV4_NODE,
13599 &neighbor_addpath_tx_bestpath_per_as_cmd);
13600 install_element(BGP_VPNV4_NODE,
13601 &no_neighbor_addpath_tx_bestpath_per_as_cmd);
13602 install_element(BGP_VPNV6_NODE,
13603 &neighbor_addpath_tx_bestpath_per_as_cmd);
13604 install_element(BGP_VPNV6_NODE,
13605 &no_neighbor_addpath_tx_bestpath_per_as_cmd);
13606
13607 /* "neighbor passive" commands. */
13608 install_element(BGP_NODE, &neighbor_passive_cmd);
13609 install_element(BGP_NODE, &no_neighbor_passive_cmd);
13610
13611
13612 /* "neighbor shutdown" commands. */
13613 install_element(BGP_NODE, &neighbor_shutdown_cmd);
13614 install_element(BGP_NODE, &no_neighbor_shutdown_cmd);
13615 install_element(BGP_NODE, &neighbor_shutdown_msg_cmd);
13616 install_element(BGP_NODE, &no_neighbor_shutdown_msg_cmd);
13617
13618 /* "neighbor capability extended-nexthop" commands.*/
13619 install_element(BGP_NODE, &neighbor_capability_enhe_cmd);
13620 install_element(BGP_NODE, &no_neighbor_capability_enhe_cmd);
13621
13622 /* "neighbor capability orf prefix-list" commands.*/
13623 install_element(BGP_NODE, &neighbor_capability_orf_prefix_hidden_cmd);
13624 install_element(BGP_NODE,
13625 &no_neighbor_capability_orf_prefix_hidden_cmd);
13626 install_element(BGP_IPV4_NODE, &neighbor_capability_orf_prefix_cmd);
13627 install_element(BGP_IPV4_NODE, &no_neighbor_capability_orf_prefix_cmd);
13628 install_element(BGP_IPV4M_NODE, &neighbor_capability_orf_prefix_cmd);
13629 install_element(BGP_IPV4M_NODE, &no_neighbor_capability_orf_prefix_cmd);
13630 install_element(BGP_IPV4L_NODE, &neighbor_capability_orf_prefix_cmd);
13631 install_element(BGP_IPV4L_NODE, &no_neighbor_capability_orf_prefix_cmd);
13632 install_element(BGP_IPV6_NODE, &neighbor_capability_orf_prefix_cmd);
13633 install_element(BGP_IPV6_NODE, &no_neighbor_capability_orf_prefix_cmd);
13634 install_element(BGP_IPV6M_NODE, &neighbor_capability_orf_prefix_cmd);
13635 install_element(BGP_IPV6M_NODE, &no_neighbor_capability_orf_prefix_cmd);
13636 install_element(BGP_IPV6L_NODE, &neighbor_capability_orf_prefix_cmd);
13637 install_element(BGP_IPV6L_NODE, &no_neighbor_capability_orf_prefix_cmd);
13638
13639 /* "neighbor capability dynamic" commands.*/
13640 install_element(BGP_NODE, &neighbor_capability_dynamic_cmd);
13641 install_element(BGP_NODE, &no_neighbor_capability_dynamic_cmd);
13642
13643 /* "neighbor dont-capability-negotiate" commands. */
13644 install_element(BGP_NODE, &neighbor_dont_capability_negotiate_cmd);
13645 install_element(BGP_NODE, &no_neighbor_dont_capability_negotiate_cmd);
13646
13647 /* "neighbor ebgp-multihop" commands. */
13648 install_element(BGP_NODE, &neighbor_ebgp_multihop_cmd);
13649 install_element(BGP_NODE, &neighbor_ebgp_multihop_ttl_cmd);
13650 install_element(BGP_NODE, &no_neighbor_ebgp_multihop_cmd);
13651
13652 /* "neighbor disable-connected-check" commands. */
13653 install_element(BGP_NODE, &neighbor_disable_connected_check_cmd);
13654 install_element(BGP_NODE, &no_neighbor_disable_connected_check_cmd);
13655
13656 /* "neighbor enforce-first-as" commands. */
13657 install_element(BGP_NODE, &neighbor_enforce_first_as_cmd);
13658 install_element(BGP_NODE, &no_neighbor_enforce_first_as_cmd);
13659
13660 /* "neighbor description" commands. */
13661 install_element(BGP_NODE, &neighbor_description_cmd);
13662 install_element(BGP_NODE, &no_neighbor_description_cmd);
13663 install_element(BGP_NODE, &no_neighbor_description_comment_cmd);
13664
13665 /* "neighbor update-source" commands. "*/
13666 install_element(BGP_NODE, &neighbor_update_source_cmd);
13667 install_element(BGP_NODE, &no_neighbor_update_source_cmd);
13668
13669 /* "neighbor default-originate" commands. */
13670 install_element(BGP_NODE, &neighbor_default_originate_hidden_cmd);
13671 install_element(BGP_NODE, &neighbor_default_originate_rmap_hidden_cmd);
13672 install_element(BGP_NODE, &no_neighbor_default_originate_hidden_cmd);
13673 install_element(BGP_IPV4_NODE, &neighbor_default_originate_cmd);
13674 install_element(BGP_IPV4_NODE, &neighbor_default_originate_rmap_cmd);
13675 install_element(BGP_IPV4_NODE, &no_neighbor_default_originate_cmd);
13676 install_element(BGP_IPV4M_NODE, &neighbor_default_originate_cmd);
13677 install_element(BGP_IPV4M_NODE, &neighbor_default_originate_rmap_cmd);
13678 install_element(BGP_IPV4M_NODE, &no_neighbor_default_originate_cmd);
13679 install_element(BGP_IPV4L_NODE, &neighbor_default_originate_cmd);
13680 install_element(BGP_IPV4L_NODE, &neighbor_default_originate_rmap_cmd);
13681 install_element(BGP_IPV4L_NODE, &no_neighbor_default_originate_cmd);
13682 install_element(BGP_IPV6_NODE, &neighbor_default_originate_cmd);
13683 install_element(BGP_IPV6_NODE, &neighbor_default_originate_rmap_cmd);
13684 install_element(BGP_IPV6_NODE, &no_neighbor_default_originate_cmd);
13685 install_element(BGP_IPV6M_NODE, &neighbor_default_originate_cmd);
13686 install_element(BGP_IPV6M_NODE, &neighbor_default_originate_rmap_cmd);
13687 install_element(BGP_IPV6M_NODE, &no_neighbor_default_originate_cmd);
13688 install_element(BGP_IPV6L_NODE, &neighbor_default_originate_cmd);
13689 install_element(BGP_IPV6L_NODE, &neighbor_default_originate_rmap_cmd);
13690 install_element(BGP_IPV6L_NODE, &no_neighbor_default_originate_cmd);
13691
13692 /* "neighbor port" commands. */
13693 install_element(BGP_NODE, &neighbor_port_cmd);
13694 install_element(BGP_NODE, &no_neighbor_port_cmd);
13695
13696 /* "neighbor weight" commands. */
13697 install_element(BGP_NODE, &neighbor_weight_hidden_cmd);
13698 install_element(BGP_NODE, &no_neighbor_weight_hidden_cmd);
13699
13700 install_element(BGP_IPV4_NODE, &neighbor_weight_cmd);
13701 install_element(BGP_IPV4_NODE, &no_neighbor_weight_cmd);
13702 install_element(BGP_IPV4M_NODE, &neighbor_weight_cmd);
13703 install_element(BGP_IPV4M_NODE, &no_neighbor_weight_cmd);
13704 install_element(BGP_IPV4L_NODE, &neighbor_weight_cmd);
13705 install_element(BGP_IPV4L_NODE, &no_neighbor_weight_cmd);
13706 install_element(BGP_IPV6_NODE, &neighbor_weight_cmd);
13707 install_element(BGP_IPV6_NODE, &no_neighbor_weight_cmd);
13708 install_element(BGP_IPV6M_NODE, &neighbor_weight_cmd);
13709 install_element(BGP_IPV6M_NODE, &no_neighbor_weight_cmd);
13710 install_element(BGP_IPV6L_NODE, &neighbor_weight_cmd);
13711 install_element(BGP_IPV6L_NODE, &no_neighbor_weight_cmd);
13712 install_element(BGP_VPNV4_NODE, &neighbor_weight_cmd);
13713 install_element(BGP_VPNV4_NODE, &no_neighbor_weight_cmd);
13714 install_element(BGP_VPNV6_NODE, &neighbor_weight_cmd);
13715 install_element(BGP_VPNV6_NODE, &no_neighbor_weight_cmd);
13716
13717 /* "neighbor override-capability" commands. */
13718 install_element(BGP_NODE, &neighbor_override_capability_cmd);
13719 install_element(BGP_NODE, &no_neighbor_override_capability_cmd);
13720
13721 /* "neighbor strict-capability-match" commands. */
13722 install_element(BGP_NODE, &neighbor_strict_capability_cmd);
13723 install_element(BGP_NODE, &no_neighbor_strict_capability_cmd);
13724
13725 /* "neighbor timers" commands. */
13726 install_element(BGP_NODE, &neighbor_timers_cmd);
13727 install_element(BGP_NODE, &no_neighbor_timers_cmd);
13728
13729 /* "neighbor timers connect" commands. */
13730 install_element(BGP_NODE, &neighbor_timers_connect_cmd);
13731 install_element(BGP_NODE, &no_neighbor_timers_connect_cmd);
13732
13733 /* "neighbor advertisement-interval" commands. */
13734 install_element(BGP_NODE, &neighbor_advertise_interval_cmd);
13735 install_element(BGP_NODE, &no_neighbor_advertise_interval_cmd);
13736
13737 /* "neighbor interface" commands. */
13738 install_element(BGP_NODE, &neighbor_interface_cmd);
13739 install_element(BGP_NODE, &no_neighbor_interface_cmd);
13740
13741 /* "neighbor distribute" commands. */
13742 install_element(BGP_NODE, &neighbor_distribute_list_hidden_cmd);
13743 install_element(BGP_NODE, &no_neighbor_distribute_list_hidden_cmd);
13744 install_element(BGP_IPV4_NODE, &neighbor_distribute_list_cmd);
13745 install_element(BGP_IPV4_NODE, &no_neighbor_distribute_list_cmd);
13746 install_element(BGP_IPV4M_NODE, &neighbor_distribute_list_cmd);
13747 install_element(BGP_IPV4M_NODE, &no_neighbor_distribute_list_cmd);
13748 install_element(BGP_IPV4L_NODE, &neighbor_distribute_list_cmd);
13749 install_element(BGP_IPV4L_NODE, &no_neighbor_distribute_list_cmd);
13750 install_element(BGP_IPV6_NODE, &neighbor_distribute_list_cmd);
13751 install_element(BGP_IPV6_NODE, &no_neighbor_distribute_list_cmd);
13752 install_element(BGP_IPV6M_NODE, &neighbor_distribute_list_cmd);
13753 install_element(BGP_IPV6M_NODE, &no_neighbor_distribute_list_cmd);
13754 install_element(BGP_IPV6L_NODE, &neighbor_distribute_list_cmd);
13755 install_element(BGP_IPV6L_NODE, &no_neighbor_distribute_list_cmd);
13756 install_element(BGP_VPNV4_NODE, &neighbor_distribute_list_cmd);
13757 install_element(BGP_VPNV4_NODE, &no_neighbor_distribute_list_cmd);
13758 install_element(BGP_VPNV6_NODE, &neighbor_distribute_list_cmd);
13759 install_element(BGP_VPNV6_NODE, &no_neighbor_distribute_list_cmd);
13760
13761 /* "neighbor prefix-list" commands. */
13762 install_element(BGP_NODE, &neighbor_prefix_list_hidden_cmd);
13763 install_element(BGP_NODE, &no_neighbor_prefix_list_hidden_cmd);
13764 install_element(BGP_IPV4_NODE, &neighbor_prefix_list_cmd);
13765 install_element(BGP_IPV4_NODE, &no_neighbor_prefix_list_cmd);
13766 install_element(BGP_IPV4M_NODE, &neighbor_prefix_list_cmd);
13767 install_element(BGP_IPV4M_NODE, &no_neighbor_prefix_list_cmd);
13768 install_element(BGP_IPV4L_NODE, &neighbor_prefix_list_cmd);
13769 install_element(BGP_IPV4L_NODE, &no_neighbor_prefix_list_cmd);
13770 install_element(BGP_IPV6_NODE, &neighbor_prefix_list_cmd);
13771 install_element(BGP_IPV6_NODE, &no_neighbor_prefix_list_cmd);
13772 install_element(BGP_IPV6M_NODE, &neighbor_prefix_list_cmd);
13773 install_element(BGP_IPV6M_NODE, &no_neighbor_prefix_list_cmd);
13774 install_element(BGP_IPV6L_NODE, &neighbor_prefix_list_cmd);
13775 install_element(BGP_IPV6L_NODE, &no_neighbor_prefix_list_cmd);
13776 install_element(BGP_VPNV4_NODE, &neighbor_prefix_list_cmd);
13777 install_element(BGP_VPNV4_NODE, &no_neighbor_prefix_list_cmd);
13778 install_element(BGP_VPNV6_NODE, &neighbor_prefix_list_cmd);
13779 install_element(BGP_VPNV6_NODE, &no_neighbor_prefix_list_cmd);
13780 install_element(BGP_FLOWSPECV4_NODE, &neighbor_prefix_list_cmd);
13781 install_element(BGP_FLOWSPECV4_NODE, &no_neighbor_prefix_list_cmd);
13782 install_element(BGP_FLOWSPECV6_NODE, &neighbor_prefix_list_cmd);
13783 install_element(BGP_FLOWSPECV6_NODE, &no_neighbor_prefix_list_cmd);
13784
13785 /* "neighbor filter-list" commands. */
13786 install_element(BGP_NODE, &neighbor_filter_list_hidden_cmd);
13787 install_element(BGP_NODE, &no_neighbor_filter_list_hidden_cmd);
13788 install_element(BGP_IPV4_NODE, &neighbor_filter_list_cmd);
13789 install_element(BGP_IPV4_NODE, &no_neighbor_filter_list_cmd);
13790 install_element(BGP_IPV4M_NODE, &neighbor_filter_list_cmd);
13791 install_element(BGP_IPV4M_NODE, &no_neighbor_filter_list_cmd);
13792 install_element(BGP_IPV4L_NODE, &neighbor_filter_list_cmd);
13793 install_element(BGP_IPV4L_NODE, &no_neighbor_filter_list_cmd);
13794 install_element(BGP_IPV6_NODE, &neighbor_filter_list_cmd);
13795 install_element(BGP_IPV6_NODE, &no_neighbor_filter_list_cmd);
13796 install_element(BGP_IPV6M_NODE, &neighbor_filter_list_cmd);
13797 install_element(BGP_IPV6M_NODE, &no_neighbor_filter_list_cmd);
13798 install_element(BGP_IPV6L_NODE, &neighbor_filter_list_cmd);
13799 install_element(BGP_IPV6L_NODE, &no_neighbor_filter_list_cmd);
13800 install_element(BGP_VPNV4_NODE, &neighbor_filter_list_cmd);
13801 install_element(BGP_VPNV4_NODE, &no_neighbor_filter_list_cmd);
13802 install_element(BGP_VPNV6_NODE, &neighbor_filter_list_cmd);
13803 install_element(BGP_VPNV6_NODE, &no_neighbor_filter_list_cmd);
13804 install_element(BGP_FLOWSPECV4_NODE, &neighbor_filter_list_cmd);
13805 install_element(BGP_FLOWSPECV4_NODE, &no_neighbor_filter_list_cmd);
13806 install_element(BGP_FLOWSPECV6_NODE, &neighbor_filter_list_cmd);
13807 install_element(BGP_FLOWSPECV6_NODE, &no_neighbor_filter_list_cmd);
13808
13809 /* "neighbor route-map" commands. */
13810 install_element(BGP_NODE, &neighbor_route_map_hidden_cmd);
13811 install_element(BGP_NODE, &no_neighbor_route_map_hidden_cmd);
13812 install_element(BGP_IPV4_NODE, &neighbor_route_map_cmd);
13813 install_element(BGP_IPV4_NODE, &no_neighbor_route_map_cmd);
13814 install_element(BGP_IPV4M_NODE, &neighbor_route_map_cmd);
13815 install_element(BGP_IPV4M_NODE, &no_neighbor_route_map_cmd);
13816 install_element(BGP_IPV4L_NODE, &neighbor_route_map_cmd);
13817 install_element(BGP_IPV4L_NODE, &no_neighbor_route_map_cmd);
13818 install_element(BGP_IPV6_NODE, &neighbor_route_map_cmd);
13819 install_element(BGP_IPV6_NODE, &no_neighbor_route_map_cmd);
13820 install_element(BGP_IPV6M_NODE, &neighbor_route_map_cmd);
13821 install_element(BGP_IPV6M_NODE, &no_neighbor_route_map_cmd);
13822 install_element(BGP_IPV6L_NODE, &neighbor_route_map_cmd);
13823 install_element(BGP_IPV6L_NODE, &no_neighbor_route_map_cmd);
13824 install_element(BGP_VPNV4_NODE, &neighbor_route_map_cmd);
13825 install_element(BGP_VPNV4_NODE, &no_neighbor_route_map_cmd);
13826 install_element(BGP_VPNV6_NODE, &neighbor_route_map_cmd);
13827 install_element(BGP_VPNV6_NODE, &no_neighbor_route_map_cmd);
13828 install_element(BGP_FLOWSPECV4_NODE, &neighbor_route_map_cmd);
13829 install_element(BGP_FLOWSPECV4_NODE, &no_neighbor_route_map_cmd);
13830 install_element(BGP_FLOWSPECV6_NODE, &neighbor_route_map_cmd);
13831 install_element(BGP_FLOWSPECV6_NODE, &no_neighbor_route_map_cmd);
13832 install_element(BGP_EVPN_NODE, &neighbor_route_map_cmd);
13833 install_element(BGP_EVPN_NODE, &no_neighbor_route_map_cmd);
13834
13835 /* "neighbor unsuppress-map" commands. */
13836 install_element(BGP_NODE, &neighbor_unsuppress_map_hidden_cmd);
13837 install_element(BGP_NODE, &no_neighbor_unsuppress_map_hidden_cmd);
13838 install_element(BGP_IPV4_NODE, &neighbor_unsuppress_map_cmd);
13839 install_element(BGP_IPV4_NODE, &no_neighbor_unsuppress_map_cmd);
13840 install_element(BGP_IPV4M_NODE, &neighbor_unsuppress_map_cmd);
13841 install_element(BGP_IPV4M_NODE, &no_neighbor_unsuppress_map_cmd);
13842 install_element(BGP_IPV4L_NODE, &neighbor_unsuppress_map_cmd);
13843 install_element(BGP_IPV4L_NODE, &no_neighbor_unsuppress_map_cmd);
13844 install_element(BGP_IPV6_NODE, &neighbor_unsuppress_map_cmd);
13845 install_element(BGP_IPV6_NODE, &no_neighbor_unsuppress_map_cmd);
13846 install_element(BGP_IPV6M_NODE, &neighbor_unsuppress_map_cmd);
13847 install_element(BGP_IPV6M_NODE, &no_neighbor_unsuppress_map_cmd);
13848 install_element(BGP_IPV6L_NODE, &neighbor_unsuppress_map_cmd);
13849 install_element(BGP_IPV6L_NODE, &no_neighbor_unsuppress_map_cmd);
13850 install_element(BGP_VPNV4_NODE, &neighbor_unsuppress_map_cmd);
13851 install_element(BGP_VPNV4_NODE, &no_neighbor_unsuppress_map_cmd);
13852 install_element(BGP_VPNV6_NODE, &neighbor_unsuppress_map_cmd);
13853 install_element(BGP_VPNV6_NODE, &no_neighbor_unsuppress_map_cmd);
13854
13855 /* "neighbor maximum-prefix" commands. */
13856 install_element(BGP_NODE, &neighbor_maximum_prefix_hidden_cmd);
13857 install_element(BGP_NODE,
13858 &neighbor_maximum_prefix_threshold_hidden_cmd);
13859 install_element(BGP_NODE, &neighbor_maximum_prefix_warning_hidden_cmd);
13860 install_element(BGP_NODE,
13861 &neighbor_maximum_prefix_threshold_warning_hidden_cmd);
13862 install_element(BGP_NODE, &neighbor_maximum_prefix_restart_hidden_cmd);
13863 install_element(BGP_NODE,
13864 &neighbor_maximum_prefix_threshold_restart_hidden_cmd);
13865 install_element(BGP_NODE, &no_neighbor_maximum_prefix_hidden_cmd);
13866 install_element(BGP_IPV4_NODE, &neighbor_maximum_prefix_cmd);
13867 install_element(BGP_IPV4_NODE, &neighbor_maximum_prefix_threshold_cmd);
13868 install_element(BGP_IPV4_NODE, &neighbor_maximum_prefix_warning_cmd);
13869 install_element(BGP_IPV4_NODE,
13870 &neighbor_maximum_prefix_threshold_warning_cmd);
13871 install_element(BGP_IPV4_NODE, &neighbor_maximum_prefix_restart_cmd);
13872 install_element(BGP_IPV4_NODE,
13873 &neighbor_maximum_prefix_threshold_restart_cmd);
13874 install_element(BGP_IPV4_NODE, &no_neighbor_maximum_prefix_cmd);
13875 install_element(BGP_IPV4M_NODE, &neighbor_maximum_prefix_cmd);
13876 install_element(BGP_IPV4M_NODE, &neighbor_maximum_prefix_threshold_cmd);
13877 install_element(BGP_IPV4M_NODE, &neighbor_maximum_prefix_warning_cmd);
13878 install_element(BGP_IPV4M_NODE,
13879 &neighbor_maximum_prefix_threshold_warning_cmd);
13880 install_element(BGP_IPV4M_NODE, &neighbor_maximum_prefix_restart_cmd);
13881 install_element(BGP_IPV4M_NODE,
13882 &neighbor_maximum_prefix_threshold_restart_cmd);
13883 install_element(BGP_IPV4M_NODE, &no_neighbor_maximum_prefix_cmd);
13884 install_element(BGP_IPV4L_NODE, &neighbor_maximum_prefix_cmd);
13885 install_element(BGP_IPV4L_NODE, &neighbor_maximum_prefix_threshold_cmd);
13886 install_element(BGP_IPV4L_NODE, &neighbor_maximum_prefix_warning_cmd);
13887 install_element(BGP_IPV4L_NODE,
13888 &neighbor_maximum_prefix_threshold_warning_cmd);
13889 install_element(BGP_IPV4L_NODE, &neighbor_maximum_prefix_restart_cmd);
13890 install_element(BGP_IPV4L_NODE,
13891 &neighbor_maximum_prefix_threshold_restart_cmd);
13892 install_element(BGP_IPV4L_NODE, &no_neighbor_maximum_prefix_cmd);
13893 install_element(BGP_IPV6_NODE, &neighbor_maximum_prefix_cmd);
13894 install_element(BGP_IPV6_NODE, &neighbor_maximum_prefix_threshold_cmd);
13895 install_element(BGP_IPV6_NODE, &neighbor_maximum_prefix_warning_cmd);
13896 install_element(BGP_IPV6_NODE,
13897 &neighbor_maximum_prefix_threshold_warning_cmd);
13898 install_element(BGP_IPV6_NODE, &neighbor_maximum_prefix_restart_cmd);
13899 install_element(BGP_IPV6_NODE,
13900 &neighbor_maximum_prefix_threshold_restart_cmd);
13901 install_element(BGP_IPV6_NODE, &no_neighbor_maximum_prefix_cmd);
13902 install_element(BGP_IPV6M_NODE, &neighbor_maximum_prefix_cmd);
13903 install_element(BGP_IPV6M_NODE, &neighbor_maximum_prefix_threshold_cmd);
13904 install_element(BGP_IPV6M_NODE, &neighbor_maximum_prefix_warning_cmd);
13905 install_element(BGP_IPV6M_NODE,
13906 &neighbor_maximum_prefix_threshold_warning_cmd);
13907 install_element(BGP_IPV6M_NODE, &neighbor_maximum_prefix_restart_cmd);
13908 install_element(BGP_IPV6M_NODE,
13909 &neighbor_maximum_prefix_threshold_restart_cmd);
13910 install_element(BGP_IPV6M_NODE, &no_neighbor_maximum_prefix_cmd);
13911 install_element(BGP_IPV6L_NODE, &neighbor_maximum_prefix_cmd);
13912 install_element(BGP_IPV6L_NODE, &neighbor_maximum_prefix_threshold_cmd);
13913 install_element(BGP_IPV6L_NODE, &neighbor_maximum_prefix_warning_cmd);
13914 install_element(BGP_IPV6L_NODE,
13915 &neighbor_maximum_prefix_threshold_warning_cmd);
13916 install_element(BGP_IPV6L_NODE, &neighbor_maximum_prefix_restart_cmd);
13917 install_element(BGP_IPV6L_NODE,
13918 &neighbor_maximum_prefix_threshold_restart_cmd);
13919 install_element(BGP_IPV6L_NODE, &no_neighbor_maximum_prefix_cmd);
13920 install_element(BGP_VPNV4_NODE, &neighbor_maximum_prefix_cmd);
13921 install_element(BGP_VPNV4_NODE, &neighbor_maximum_prefix_threshold_cmd);
13922 install_element(BGP_VPNV4_NODE, &neighbor_maximum_prefix_warning_cmd);
13923 install_element(BGP_VPNV4_NODE,
13924 &neighbor_maximum_prefix_threshold_warning_cmd);
13925 install_element(BGP_VPNV4_NODE, &neighbor_maximum_prefix_restart_cmd);
13926 install_element(BGP_VPNV4_NODE,
13927 &neighbor_maximum_prefix_threshold_restart_cmd);
13928 install_element(BGP_VPNV4_NODE, &no_neighbor_maximum_prefix_cmd);
13929 install_element(BGP_VPNV6_NODE, &neighbor_maximum_prefix_cmd);
13930 install_element(BGP_VPNV6_NODE, &neighbor_maximum_prefix_threshold_cmd);
13931 install_element(BGP_VPNV6_NODE, &neighbor_maximum_prefix_warning_cmd);
13932 install_element(BGP_VPNV6_NODE,
13933 &neighbor_maximum_prefix_threshold_warning_cmd);
13934 install_element(BGP_VPNV6_NODE, &neighbor_maximum_prefix_restart_cmd);
13935 install_element(BGP_VPNV6_NODE,
13936 &neighbor_maximum_prefix_threshold_restart_cmd);
13937 install_element(BGP_VPNV6_NODE, &no_neighbor_maximum_prefix_cmd);
13938
13939 /* "neighbor allowas-in" */
13940 install_element(BGP_NODE, &neighbor_allowas_in_hidden_cmd);
13941 install_element(BGP_NODE, &no_neighbor_allowas_in_hidden_cmd);
13942 install_element(BGP_IPV4_NODE, &neighbor_allowas_in_cmd);
13943 install_element(BGP_IPV4_NODE, &no_neighbor_allowas_in_cmd);
13944 install_element(BGP_IPV4M_NODE, &neighbor_allowas_in_cmd);
13945 install_element(BGP_IPV4M_NODE, &no_neighbor_allowas_in_cmd);
13946 install_element(BGP_IPV4L_NODE, &neighbor_allowas_in_cmd);
13947 install_element(BGP_IPV4L_NODE, &no_neighbor_allowas_in_cmd);
13948 install_element(BGP_IPV6_NODE, &neighbor_allowas_in_cmd);
13949 install_element(BGP_IPV6_NODE, &no_neighbor_allowas_in_cmd);
13950 install_element(BGP_IPV6M_NODE, &neighbor_allowas_in_cmd);
13951 install_element(BGP_IPV6M_NODE, &no_neighbor_allowas_in_cmd);
13952 install_element(BGP_IPV6L_NODE, &neighbor_allowas_in_cmd);
13953 install_element(BGP_IPV6L_NODE, &no_neighbor_allowas_in_cmd);
13954 install_element(BGP_VPNV4_NODE, &neighbor_allowas_in_cmd);
13955 install_element(BGP_VPNV4_NODE, &no_neighbor_allowas_in_cmd);
13956 install_element(BGP_VPNV6_NODE, &neighbor_allowas_in_cmd);
13957 install_element(BGP_VPNV6_NODE, &no_neighbor_allowas_in_cmd);
13958 install_element(BGP_EVPN_NODE, &neighbor_allowas_in_cmd);
13959 install_element(BGP_EVPN_NODE, &no_neighbor_allowas_in_cmd);
13960
13961 /* address-family commands. */
13962 install_element(BGP_NODE, &address_family_ipv4_safi_cmd);
13963 install_element(BGP_NODE, &address_family_ipv6_safi_cmd);
13964 #ifdef KEEP_OLD_VPN_COMMANDS
13965 install_element(BGP_NODE, &address_family_vpnv4_cmd);
13966 install_element(BGP_NODE, &address_family_vpnv6_cmd);
13967 #endif /* KEEP_OLD_VPN_COMMANDS */
13968
13969 install_element(BGP_NODE, &address_family_evpn_cmd);
13970
13971 /* "exit-address-family" command. */
13972 install_element(BGP_IPV4_NODE, &exit_address_family_cmd);
13973 install_element(BGP_IPV4M_NODE, &exit_address_family_cmd);
13974 install_element(BGP_IPV4L_NODE, &exit_address_family_cmd);
13975 install_element(BGP_IPV6_NODE, &exit_address_family_cmd);
13976 install_element(BGP_IPV6M_NODE, &exit_address_family_cmd);
13977 install_element(BGP_IPV6L_NODE, &exit_address_family_cmd);
13978 install_element(BGP_VPNV4_NODE, &exit_address_family_cmd);
13979 install_element(BGP_VPNV6_NODE, &exit_address_family_cmd);
13980 install_element(BGP_FLOWSPECV4_NODE, &exit_address_family_cmd);
13981 install_element(BGP_FLOWSPECV6_NODE, &exit_address_family_cmd);
13982 install_element(BGP_EVPN_NODE, &exit_address_family_cmd);
13983
13984 /* "clear ip bgp commands" */
13985 install_element(ENABLE_NODE, &clear_ip_bgp_all_cmd);
13986
13987 /* clear ip bgp prefix */
13988 install_element(ENABLE_NODE, &clear_ip_bgp_prefix_cmd);
13989 install_element(ENABLE_NODE, &clear_bgp_ipv6_safi_prefix_cmd);
13990 install_element(ENABLE_NODE, &clear_bgp_instance_ipv6_safi_prefix_cmd);
13991
13992 /* "show [ip] bgp summary" commands. */
13993 install_element(VIEW_NODE, &show_bgp_instance_all_ipv6_updgrps_cmd);
13994 install_element(VIEW_NODE, &show_bgp_l2vpn_evpn_updgrps_cmd);
13995 install_element(VIEW_NODE, &show_bgp_instance_updgrps_stats_cmd);
13996 install_element(VIEW_NODE, &show_bgp_updgrps_stats_cmd);
13997 install_element(VIEW_NODE, &show_ip_bgp_instance_updgrps_adj_s_cmd);
13998 install_element(VIEW_NODE, &show_ip_bgp_summary_cmd);
13999 install_element(VIEW_NODE, &show_ip_bgp_updgrps_cmd);
14000
14001 /* "show [ip] bgp neighbors" commands. */
14002 install_element(VIEW_NODE, &show_ip_bgp_neighbors_cmd);
14003
14004 /* "show [ip] bgp peer-group" commands. */
14005 install_element(VIEW_NODE, &show_ip_bgp_peer_groups_cmd);
14006
14007 /* "show [ip] bgp paths" commands. */
14008 install_element(VIEW_NODE, &show_ip_bgp_paths_cmd);
14009
14010 /* "show [ip] bgp community" commands. */
14011 install_element(VIEW_NODE, &show_ip_bgp_community_info_cmd);
14012
14013 /* "show ip bgp large-community" commands. */
14014 install_element(VIEW_NODE, &show_ip_bgp_lcommunity_info_cmd);
14015 /* "show [ip] bgp attribute-info" commands. */
14016 install_element(VIEW_NODE, &show_ip_bgp_attr_info_cmd);
14017 /* "show [ip] bgp route-leak" command */
14018 install_element(VIEW_NODE, &show_ip_bgp_route_leak_cmd);
14019
14020 /* "redistribute" commands. */
14021 install_element(BGP_NODE, &bgp_redistribute_ipv4_hidden_cmd);
14022 install_element(BGP_NODE, &no_bgp_redistribute_ipv4_hidden_cmd);
14023 install_element(BGP_NODE, &bgp_redistribute_ipv4_rmap_hidden_cmd);
14024 install_element(BGP_NODE, &bgp_redistribute_ipv4_metric_hidden_cmd);
14025 install_element(BGP_NODE,
14026 &bgp_redistribute_ipv4_rmap_metric_hidden_cmd);
14027 install_element(BGP_NODE,
14028 &bgp_redistribute_ipv4_metric_rmap_hidden_cmd);
14029 install_element(BGP_NODE, &bgp_redistribute_ipv4_ospf_hidden_cmd);
14030 install_element(BGP_NODE, &no_bgp_redistribute_ipv4_ospf_hidden_cmd);
14031 install_element(BGP_NODE, &bgp_redistribute_ipv4_ospf_rmap_hidden_cmd);
14032 install_element(BGP_NODE,
14033 &bgp_redistribute_ipv4_ospf_metric_hidden_cmd);
14034 install_element(BGP_NODE,
14035 &bgp_redistribute_ipv4_ospf_rmap_metric_hidden_cmd);
14036 install_element(BGP_NODE,
14037 &bgp_redistribute_ipv4_ospf_metric_rmap_hidden_cmd);
14038 install_element(BGP_IPV4_NODE, &bgp_redistribute_ipv4_cmd);
14039 install_element(BGP_IPV4_NODE, &no_bgp_redistribute_ipv4_cmd);
14040 install_element(BGP_IPV4_NODE, &bgp_redistribute_ipv4_rmap_cmd);
14041 install_element(BGP_IPV4_NODE, &bgp_redistribute_ipv4_metric_cmd);
14042 install_element(BGP_IPV4_NODE, &bgp_redistribute_ipv4_rmap_metric_cmd);
14043 install_element(BGP_IPV4_NODE, &bgp_redistribute_ipv4_metric_rmap_cmd);
14044 install_element(BGP_IPV4_NODE, &bgp_redistribute_ipv4_ospf_cmd);
14045 install_element(BGP_IPV4_NODE, &no_bgp_redistribute_ipv4_ospf_cmd);
14046 install_element(BGP_IPV4_NODE, &bgp_redistribute_ipv4_ospf_rmap_cmd);
14047 install_element(BGP_IPV4_NODE, &bgp_redistribute_ipv4_ospf_metric_cmd);
14048 install_element(BGP_IPV4_NODE,
14049 &bgp_redistribute_ipv4_ospf_rmap_metric_cmd);
14050 install_element(BGP_IPV4_NODE,
14051 &bgp_redistribute_ipv4_ospf_metric_rmap_cmd);
14052 install_element(BGP_IPV6_NODE, &bgp_redistribute_ipv6_cmd);
14053 install_element(BGP_IPV6_NODE, &no_bgp_redistribute_ipv6_cmd);
14054 install_element(BGP_IPV6_NODE, &bgp_redistribute_ipv6_rmap_cmd);
14055 install_element(BGP_IPV6_NODE, &bgp_redistribute_ipv6_metric_cmd);
14056 install_element(BGP_IPV6_NODE, &bgp_redistribute_ipv6_rmap_metric_cmd);
14057 install_element(BGP_IPV6_NODE, &bgp_redistribute_ipv6_metric_rmap_cmd);
14058
14059 /* import|export vpn [route-map WORD] */
14060 install_element(BGP_IPV4_NODE, &bgp_imexport_vpn_cmd);
14061 install_element(BGP_IPV6_NODE, &bgp_imexport_vpn_cmd);
14062
14063 install_element(BGP_IPV4_NODE, &bgp_imexport_vrf_cmd);
14064 install_element(BGP_IPV6_NODE, &bgp_imexport_vrf_cmd);
14065
14066 /* ttl_security commands */
14067 install_element(BGP_NODE, &neighbor_ttl_security_cmd);
14068 install_element(BGP_NODE, &no_neighbor_ttl_security_cmd);
14069
14070 /* "show [ip] bgp memory" commands. */
14071 install_element(VIEW_NODE, &show_bgp_memory_cmd);
14072
14073 /* "show bgp martian next-hop" */
14074 install_element(VIEW_NODE, &show_bgp_martian_nexthop_db_cmd);
14075
14076 install_element(VIEW_NODE, &show_bgp_mac_hash_cmd);
14077
14078 /* "show [ip] bgp views" commands. */
14079 install_element(VIEW_NODE, &show_bgp_views_cmd);
14080
14081 /* "show [ip] bgp vrfs" commands. */
14082 install_element(VIEW_NODE, &show_bgp_vrfs_cmd);
14083
14084 /* Community-list. */
14085 community_list_vty();
14086
14087 /* vpn-policy commands */
14088 install_element(BGP_IPV4_NODE, &af_rd_vpn_export_cmd);
14089 install_element(BGP_IPV6_NODE, &af_rd_vpn_export_cmd);
14090 install_element(BGP_IPV4_NODE, &af_label_vpn_export_cmd);
14091 install_element(BGP_IPV6_NODE, &af_label_vpn_export_cmd);
14092 install_element(BGP_IPV4_NODE, &af_nexthop_vpn_export_cmd);
14093 install_element(BGP_IPV6_NODE, &af_nexthop_vpn_export_cmd);
14094 install_element(BGP_IPV4_NODE, &af_rt_vpn_imexport_cmd);
14095 install_element(BGP_IPV6_NODE, &af_rt_vpn_imexport_cmd);
14096 install_element(BGP_IPV4_NODE, &af_route_map_vpn_imexport_cmd);
14097 install_element(BGP_IPV6_NODE, &af_route_map_vpn_imexport_cmd);
14098 install_element(BGP_IPV4_NODE, &af_import_vrf_route_map_cmd);
14099 install_element(BGP_IPV6_NODE, &af_import_vrf_route_map_cmd);
14100
14101 install_element(BGP_IPV4_NODE, &af_routetarget_import_cmd);
14102 install_element(BGP_IPV6_NODE, &af_routetarget_import_cmd);
14103
14104 install_element(BGP_IPV4_NODE, &af_no_rd_vpn_export_cmd);
14105 install_element(BGP_IPV6_NODE, &af_no_rd_vpn_export_cmd);
14106 install_element(BGP_IPV4_NODE, &af_no_label_vpn_export_cmd);
14107 install_element(BGP_IPV6_NODE, &af_no_label_vpn_export_cmd);
14108 install_element(BGP_IPV4_NODE, &af_no_nexthop_vpn_export_cmd);
14109 install_element(BGP_IPV6_NODE, &af_no_nexthop_vpn_export_cmd);
14110 install_element(BGP_IPV4_NODE, &af_no_rt_vpn_imexport_cmd);
14111 install_element(BGP_IPV6_NODE, &af_no_rt_vpn_imexport_cmd);
14112 install_element(BGP_IPV4_NODE, &af_no_route_map_vpn_imexport_cmd);
14113 install_element(BGP_IPV6_NODE, &af_no_route_map_vpn_imexport_cmd);
14114 install_element(BGP_IPV4_NODE, &af_no_import_vrf_route_map_cmd);
14115 install_element(BGP_IPV6_NODE, &af_no_import_vrf_route_map_cmd);
14116 }
14117
14118 #include "memory.h"
14119 #include "bgp_regex.h"
14120 #include "bgp_clist.h"
14121 #include "bgp_ecommunity.h"
14122
14123 /* VTY functions. */
14124
14125 /* Direction value to string conversion. */
14126 static const char *community_direct_str(int direct)
14127 {
14128 switch (direct) {
14129 case COMMUNITY_DENY:
14130 return "deny";
14131 case COMMUNITY_PERMIT:
14132 return "permit";
14133 default:
14134 return "unknown";
14135 }
14136 }
14137
14138 /* Display error string. */
14139 static void community_list_perror(struct vty *vty, int ret)
14140 {
14141 switch (ret) {
14142 case COMMUNITY_LIST_ERR_CANT_FIND_LIST:
14143 vty_out(vty, "%% Can't find community-list\n");
14144 break;
14145 case COMMUNITY_LIST_ERR_MALFORMED_VAL:
14146 vty_out(vty, "%% Malformed community-list value\n");
14147 break;
14148 case COMMUNITY_LIST_ERR_STANDARD_CONFLICT:
14149 vty_out(vty,
14150 "%% Community name conflict, previously defined as standard community\n");
14151 break;
14152 case COMMUNITY_LIST_ERR_EXPANDED_CONFLICT:
14153 vty_out(vty,
14154 "%% Community name conflict, previously defined as expanded community\n");
14155 break;
14156 }
14157 }
14158
14159 /* "community-list" keyword help string. */
14160 #define COMMUNITY_LIST_STR "Add a community list entry\n"
14161
14162 /*community-list standard */
14163 DEFUN (community_list_standard,
14164 bgp_community_list_standard_cmd,
14165 "bgp community-list <(1-99)|standard WORD> <deny|permit> AA:NN...",
14166 BGP_STR
14167 COMMUNITY_LIST_STR
14168 "Community list number (standard)\n"
14169 "Add an standard community-list entry\n"
14170 "Community list name\n"
14171 "Specify community to reject\n"
14172 "Specify community to accept\n"
14173 COMMUNITY_VAL_STR)
14174 {
14175 char *cl_name_or_number = NULL;
14176 int direct = 0;
14177 int style = COMMUNITY_LIST_STANDARD;
14178
14179 int idx = 0;
14180
14181 if (argv_find(argv, argc, "ip", &idx)) {
14182 vty_out(vty, "This config option is deprecated, and is scheduled for removal.\n");
14183 vty_out(vty, "if you are using this please migrate to the below command.\n");
14184 vty_out(vty, "'bgp community-list <(1-99)|(100-500)|standard|expanded> <deny|permit> AA:NN'\n");
14185 zlog_warn("Deprecated option: 'ip community-list <(1-99)|(100-500)|standard|expanded> <deny|permit> AA:NN' being used");
14186 }
14187
14188 argv_find(argv, argc, "(1-99)", &idx);
14189 argv_find(argv, argc, "WORD", &idx);
14190 cl_name_or_number = argv[idx]->arg;
14191 direct = argv_find(argv, argc, "permit", &idx) ? COMMUNITY_PERMIT
14192 : COMMUNITY_DENY;
14193 argv_find(argv, argc, "AA:NN", &idx);
14194 char *str = argv_concat(argv, argc, idx);
14195
14196 int ret = community_list_set(bgp_clist, cl_name_or_number, str, direct,
14197 style);
14198
14199 XFREE(MTYPE_TMP, str);
14200
14201 if (ret < 0) {
14202 /* Display error string. */
14203 community_list_perror(vty, ret);
14204 return CMD_WARNING_CONFIG_FAILED;
14205 }
14206
14207 return CMD_SUCCESS;
14208 }
14209
14210 #if CONFDATE > 20191005
14211 CPP_NOTICE("bgpd: remove deprecated 'ip community-list <(1-99)|(100-500)|standard|expanded> <deny|permit> AA:NN' command")
14212 #endif
14213 ALIAS (community_list_standard,
14214 ip_community_list_standard_cmd,
14215 "ip community-list <(1-99)|standard WORD> <deny|permit> AA:NN...",
14216 IP_STR
14217 COMMUNITY_LIST_STR
14218 "Community list number (standard)\n"
14219 "Add an standard community-list entry\n"
14220 "Community list name\n"
14221 "Specify community to reject\n"
14222 "Specify community to accept\n"
14223 COMMUNITY_VAL_STR)
14224
14225 DEFUN (no_community_list_standard_all,
14226 no_bgp_community_list_standard_all_cmd,
14227 "no bgp community-list <(1-99)|standard WORD> <deny|permit> AA:NN...",
14228 NO_STR
14229 BGP_STR
14230 COMMUNITY_LIST_STR
14231 "Community list number (standard)\n"
14232 "Add an standard community-list entry\n"
14233 "Community list name\n"
14234 "Specify community to reject\n"
14235 "Specify community to accept\n"
14236 COMMUNITY_VAL_STR)
14237 {
14238 char *cl_name_or_number = NULL;
14239 char *str = NULL;
14240 int direct = 0;
14241 int style = COMMUNITY_LIST_STANDARD;
14242
14243 int idx = 0;
14244
14245 if (argv_find(argv, argc, "ip", &idx)) {
14246 vty_out(vty, "This config option is deprecated, and is scheduled for removal\n");
14247 vty_out(vty, "if you are using this please migrate to the below command.\n");
14248 vty_out(vty, "'no bgp community-list <(1-99)|(100-500)|standard|expanded> <deny|permit> AA:NN'\n");
14249 zlog_warn("Deprecated option: 'no ip community-list <(1-99)|(100-500)|standard|expanded> <deny|permit> |AA:NN' being used");
14250 }
14251
14252 argv_find(argv, argc, "permit", &idx);
14253 argv_find(argv, argc, "deny", &idx);
14254
14255 if (idx) {
14256 direct = argv_find(argv, argc, "permit", &idx)
14257 ? COMMUNITY_PERMIT
14258 : COMMUNITY_DENY;
14259
14260 idx = 0;
14261 argv_find(argv, argc, "AA:NN", &idx);
14262 str = argv_concat(argv, argc, idx);
14263 }
14264
14265 idx = 0;
14266 argv_find(argv, argc, "(1-99)", &idx);
14267 argv_find(argv, argc, "WORD", &idx);
14268 cl_name_or_number = argv[idx]->arg;
14269
14270 int ret = community_list_unset(bgp_clist, cl_name_or_number, str,
14271 direct, style);
14272
14273 XFREE(MTYPE_TMP, str);
14274
14275 if (ret < 0) {
14276 community_list_perror(vty, ret);
14277 return CMD_WARNING_CONFIG_FAILED;
14278 }
14279
14280 return CMD_SUCCESS;
14281 }
14282 ALIAS (no_community_list_standard_all,
14283 no_ip_community_list_standard_all_cmd,
14284 "no ip community-list <(1-99)|standard WORD> <deny|permit> AA:NN...",
14285 NO_STR
14286 IP_STR
14287 COMMUNITY_LIST_STR
14288 "Community list number (standard)\n"
14289 "Add an standard community-list entry\n"
14290 "Community list name\n"
14291 "Specify community to reject\n"
14292 "Specify community to accept\n"
14293 COMMUNITY_VAL_STR)
14294
14295 ALIAS(no_community_list_standard_all, no_bgp_community_list_standard_all_list_cmd,
14296 "no bgp community-list <(1-99)|standard WORD>",
14297 NO_STR BGP_STR COMMUNITY_LIST_STR
14298 "Community list number (standard)\n"
14299 "Add an standard community-list entry\n"
14300 "Community list name\n")
14301
14302 ALIAS(no_community_list_standard_all, no_ip_community_list_standard_all_list_cmd,
14303 "no ip community-list <(1-99)|standard WORD>",
14304 NO_STR BGP_STR COMMUNITY_LIST_STR
14305 "Community list number (standard)\n"
14306 "Add an standard community-list entry\n"
14307 "Community list name\n")
14308
14309 /*community-list expanded */
14310 DEFUN (community_list_expanded_all,
14311 bgp_community_list_expanded_all_cmd,
14312 "bgp community-list <(100-500)|expanded WORD> <deny|permit> AA:NN...",
14313 BGP_STR
14314 COMMUNITY_LIST_STR
14315 "Community list number (expanded)\n"
14316 "Add an expanded community-list entry\n"
14317 "Community list name\n"
14318 "Specify community to reject\n"
14319 "Specify community to accept\n"
14320 COMMUNITY_VAL_STR)
14321 {
14322 char *cl_name_or_number = NULL;
14323 int direct = 0;
14324 int style = COMMUNITY_LIST_EXPANDED;
14325
14326 int idx = 0;
14327 if (argv_find(argv, argc, "ip", &idx)) {
14328 vty_out(vty, "This config option is deprecated, and is scheduled for removal.\n");
14329 vty_out(vty, "if you are using this please migrate to the below command.\n");
14330 vty_out(vty, "'bgp community-list <(1-99)|(100-500)|standard|expanded> <deny|permit> AA:NN'\n");
14331 zlog_warn("Deprecated option: 'ip community-list <(1-99)|(100-500)|standard|expanded> <deny|permit> AA:NN' being used");
14332 }
14333 argv_find(argv, argc, "(100-500)", &idx);
14334 argv_find(argv, argc, "WORD", &idx);
14335 cl_name_or_number = argv[idx]->arg;
14336 direct = argv_find(argv, argc, "permit", &idx) ? COMMUNITY_PERMIT
14337 : COMMUNITY_DENY;
14338 argv_find(argv, argc, "AA:NN", &idx);
14339 char *str = argv_concat(argv, argc, idx);
14340
14341 int ret = community_list_set(bgp_clist, cl_name_or_number, str, direct,
14342 style);
14343
14344 XFREE(MTYPE_TMP, str);
14345
14346 if (ret < 0) {
14347 /* Display error string. */
14348 community_list_perror(vty, ret);
14349 return CMD_WARNING_CONFIG_FAILED;
14350 }
14351
14352 return CMD_SUCCESS;
14353 }
14354
14355 ALIAS (community_list_expanded_all,
14356 ip_community_list_expanded_all_cmd,
14357 "ip community-list <(100-500)|expanded WORD> <deny|permit> AA:NN...",
14358 IP_STR
14359 COMMUNITY_LIST_STR
14360 "Community list number (expanded)\n"
14361 "Add an expanded community-list entry\n"
14362 "Community list name\n"
14363 "Specify community to reject\n"
14364 "Specify community to accept\n"
14365 COMMUNITY_VAL_STR)
14366
14367 DEFUN (no_community_list_expanded_all,
14368 no_bgp_community_list_expanded_all_cmd,
14369 "no bgp community-list <(100-500)|expanded WORD> <deny|permit> AA:NN...",
14370 NO_STR
14371 BGP_STR
14372 COMMUNITY_LIST_STR
14373 "Community list number (expanded)\n"
14374 "Add an expanded community-list entry\n"
14375 "Community list name\n"
14376 "Specify community to reject\n"
14377 "Specify community to accept\n"
14378 COMMUNITY_VAL_STR)
14379 {
14380 char *cl_name_or_number = NULL;
14381 char *str = NULL;
14382 int direct = 0;
14383 int style = COMMUNITY_LIST_EXPANDED;
14384
14385 int idx = 0;
14386 if (argv_find(argv, argc, "ip", &idx)) {
14387 vty_out(vty, "This config option is deprecated, and is scheduled for removal.\n");
14388 vty_out(vty, "if you are using this please migrate to the below command.\n");
14389 vty_out(vty, "'no bgp community-list <(1-99)|(100-500)|standard|expanded> <deny|permit> AA:NN'\n");
14390 zlog_warn("Deprecated option: 'no ip community-list <(1-99)|(100-500)|standard|expanded> <deny|permit> AA:NN' being used");
14391 }
14392
14393 idx = 0;
14394 argv_find(argv, argc, "permit", &idx);
14395 argv_find(argv, argc, "deny", &idx);
14396
14397 if (idx) {
14398 direct = argv_find(argv, argc, "permit", &idx)
14399 ? COMMUNITY_PERMIT
14400 : COMMUNITY_DENY;
14401
14402 idx = 0;
14403 argv_find(argv, argc, "AA:NN", &idx);
14404 str = argv_concat(argv, argc, idx);
14405 }
14406
14407 idx = 0;
14408 argv_find(argv, argc, "(100-500)", &idx);
14409 argv_find(argv, argc, "WORD", &idx);
14410 cl_name_or_number = argv[idx]->arg;
14411
14412 int ret = community_list_unset(bgp_clist, cl_name_or_number, str,
14413 direct, style);
14414
14415 XFREE(MTYPE_TMP, str);
14416
14417 if (ret < 0) {
14418 community_list_perror(vty, ret);
14419 return CMD_WARNING_CONFIG_FAILED;
14420 }
14421
14422 return CMD_SUCCESS;
14423 }
14424
14425 ALIAS (no_community_list_expanded_all,
14426 no_ip_community_list_expanded_all_cmd,
14427 "no ip community-list <(100-500)|expanded WORD> <deny|permit> AA:NN...",
14428 NO_STR
14429 IP_STR
14430 COMMUNITY_LIST_STR
14431 "Community list number (expanded)\n"
14432 "Add an expanded community-list entry\n"
14433 "Community list name\n"
14434 "Specify community to reject\n"
14435 "Specify community to accept\n"
14436 COMMUNITY_VAL_STR)
14437
14438 ALIAS(no_community_list_expanded_all, no_bgp_community_list_expanded_all_list_cmd,
14439 "no bgp community-list <(100-500)|expanded WORD>",
14440 NO_STR IP_STR COMMUNITY_LIST_STR
14441 "Community list number (expanded)\n"
14442 "Add an expanded community-list entry\n"
14443 "Community list name\n")
14444
14445 ALIAS(no_community_list_expanded_all, no_ip_community_list_expanded_all_list_cmd,
14446 "no ip community-list <(100-500)|expanded WORD>",
14447 NO_STR IP_STR COMMUNITY_LIST_STR
14448 "Community list number (expanded)\n"
14449 "Add an expanded community-list entry\n"
14450 "Community list name\n")
14451
14452 /* Return configuration string of community-list entry. */
14453 static const char *community_list_config_str(struct community_entry *entry)
14454 {
14455 const char *str;
14456
14457 if (entry->any)
14458 str = "";
14459 else {
14460 if (entry->style == COMMUNITY_LIST_STANDARD)
14461 str = community_str(entry->u.com, false);
14462 else if (entry->style == LARGE_COMMUNITY_LIST_STANDARD)
14463 str = lcommunity_str(entry->u.lcom, false);
14464 else
14465 str = entry->config;
14466 }
14467 return str;
14468 }
14469
14470 static void community_list_show(struct vty *vty, struct community_list *list)
14471 {
14472 struct community_entry *entry;
14473
14474 for (entry = list->head; entry; entry = entry->next) {
14475 if (entry == list->head) {
14476 if (all_digit(list->name))
14477 vty_out(vty, "Community %s list %s\n",
14478 entry->style == COMMUNITY_LIST_STANDARD
14479 ? "standard"
14480 : "(expanded) access",
14481 list->name);
14482 else
14483 vty_out(vty, "Named Community %s list %s\n",
14484 entry->style == COMMUNITY_LIST_STANDARD
14485 ? "standard"
14486 : "expanded",
14487 list->name);
14488 }
14489 if (entry->any)
14490 vty_out(vty, " %s\n",
14491 community_direct_str(entry->direct));
14492 else
14493 vty_out(vty, " %s %s\n",
14494 community_direct_str(entry->direct),
14495 community_list_config_str(entry));
14496 }
14497 }
14498
14499 DEFUN (show_community_list,
14500 show_bgp_community_list_cmd,
14501 "show bgp community-list",
14502 SHOW_STR
14503 BGP_STR
14504 "List community-list\n")
14505 {
14506 struct community_list *list;
14507 struct community_list_master *cm;
14508
14509 int idx = 0;
14510 if (argv_find(argv, argc, "ip", &idx)) {
14511 vty_out(vty, "This config option is deprecated, and is scheduled for removal.\n");
14512 vty_out(vty, "if you are using this please migrate to the below command.\n");
14513 vty_out(vty, "'show bgp community-list <(1-500)|WORD>'\n");
14514 zlog_warn("Deprecated option: 'ip show community-list <(1-500)|WORD>' being used");
14515 }
14516 cm = community_list_master_lookup(bgp_clist, COMMUNITY_LIST_MASTER);
14517 if (!cm)
14518 return CMD_SUCCESS;
14519
14520 for (list = cm->num.head; list; list = list->next)
14521 community_list_show(vty, list);
14522
14523 for (list = cm->str.head; list; list = list->next)
14524 community_list_show(vty, list);
14525
14526 return CMD_SUCCESS;
14527 }
14528
14529 ALIAS (show_community_list,
14530 show_ip_community_list_cmd,
14531 "show ip community-list",
14532 SHOW_STR
14533 IP_STR
14534 "List community-list\n")
14535
14536 DEFUN (show_community_list_arg,
14537 show_bgp_community_list_arg_cmd,
14538 "show bgp community-list <(1-500)|WORD>",
14539 SHOW_STR
14540 BGP_STR
14541 "List community-list\n"
14542 "Community-list number\n"
14543 "Community-list name\n")
14544 {
14545 int idx_comm_list = 3;
14546 struct community_list *list;
14547
14548 int idx = 0;
14549 if (argv_find(argv, argc, "ip", &idx)) {
14550 vty_out(vty, "This config option is deprecated, and is scheduled for removal.\n");
14551 vty_out(vty, "if you are using this please migrate to the below command.\n");
14552 vty_out(vty, "'show bgp community-list <(1-500)|WORD>'\n");
14553 zlog_warn("Deprecated option: 'ip show community-list <(1-500)|WORD>' being used");
14554 }
14555 list = community_list_lookup(bgp_clist, argv[idx_comm_list]->arg, 0,
14556 COMMUNITY_LIST_MASTER);
14557 if (!list) {
14558 vty_out(vty, "%% Can't find community-list\n");
14559 return CMD_WARNING;
14560 }
14561
14562 community_list_show(vty, list);
14563
14564 return CMD_SUCCESS;
14565 }
14566
14567 ALIAS (show_community_list_arg,
14568 show_ip_community_list_arg_cmd,
14569 "show ip community-list <(1-500)|WORD>",
14570 SHOW_STR
14571 IP_STR
14572 "List community-list\n"
14573 "Community-list number\n"
14574 "Community-list name\n")
14575
14576 /*
14577 * Large Community code.
14578 */
14579 static int lcommunity_list_set_vty(struct vty *vty, int argc,
14580 struct cmd_token **argv, int style,
14581 int reject_all_digit_name)
14582 {
14583 int ret;
14584 int direct;
14585 char *str;
14586 int idx = 0;
14587 char *cl_name;
14588
14589 if (argv_find(argv, argc, "ip", &idx)) {
14590 vty_out(vty, "This config option is deprecated, and is scheduled for removal.\n");
14591 vty_out(vty, "if you are using this please migrate to the below command.\n");
14592 vty_out(vty, "'bgp large-community-list <(1-99)|(100-500)|standard|expanded> <deny|permit> <LINE|AA:BB:CC>'\n");
14593 zlog_warn("Deprecated option: 'large-community-list <(1-99)|(100-500)|standard|expanded> <deny|permit> <LINE|AA:BB:CC>' being used");
14594 }
14595 direct = argv_find(argv, argc, "permit", &idx) ? COMMUNITY_PERMIT
14596 : COMMUNITY_DENY;
14597
14598 /* All digit name check. */
14599 idx = 0;
14600 argv_find(argv, argc, "WORD", &idx);
14601 argv_find(argv, argc, "(1-99)", &idx);
14602 argv_find(argv, argc, "(100-500)", &idx);
14603 cl_name = argv[idx]->arg;
14604 if (reject_all_digit_name && all_digit(cl_name)) {
14605 vty_out(vty, "%% Community name cannot have all digits\n");
14606 return CMD_WARNING_CONFIG_FAILED;
14607 }
14608
14609 idx = 0;
14610 argv_find(argv, argc, "AA:BB:CC", &idx);
14611 argv_find(argv, argc, "LINE", &idx);
14612 /* Concat community string argument. */
14613 if (idx)
14614 str = argv_concat(argv, argc, idx);
14615 else
14616 str = NULL;
14617
14618 ret = lcommunity_list_set(bgp_clist, cl_name, str, direct, style);
14619
14620 /* Free temporary community list string allocated by
14621 argv_concat(). */
14622 XFREE(MTYPE_TMP, str);
14623
14624 if (ret < 0) {
14625 community_list_perror(vty, ret);
14626 return CMD_WARNING_CONFIG_FAILED;
14627 }
14628 return CMD_SUCCESS;
14629 }
14630
14631 static int lcommunity_list_unset_vty(struct vty *vty, int argc,
14632 struct cmd_token **argv, int style)
14633 {
14634 int ret;
14635 int direct = 0;
14636 char *str = NULL;
14637 int idx = 0;
14638
14639 if (argv_find(argv, argc, "ip", &idx)) {
14640 vty_out(vty, "This config option is deprecated, and is scheduled for removal.\n");
14641 vty_out(vty, "if you are using this please migrate to the below command.\n");
14642 vty_out(vty, "'no bgp large-community-list <(1-99)|(100-500)|standard|expanded> <deny|permit> <LINE|AA:BB:CC>'\n");
14643 zlog_warn("Deprecated option: 'no ip large-community-list <(1-99)|(100-500)|standard|expanded> <deny|permit> <LINE|AA:BB:CC>' being used");
14644 }
14645 argv_find(argv, argc, "permit", &idx);
14646 argv_find(argv, argc, "deny", &idx);
14647
14648 if (idx) {
14649 /* Check the list direct. */
14650 if (strncmp(argv[idx]->arg, "p", 1) == 0)
14651 direct = COMMUNITY_PERMIT;
14652 else
14653 direct = COMMUNITY_DENY;
14654
14655 idx = 0;
14656 argv_find(argv, argc, "LINE", &idx);
14657 argv_find(argv, argc, "AA:AA:NN", &idx);
14658 /* Concat community string argument. */
14659 str = argv_concat(argv, argc, idx);
14660 }
14661
14662 idx = 0;
14663 argv_find(argv, argc, "(1-99)", &idx);
14664 argv_find(argv, argc, "(100-500)", &idx);
14665 argv_find(argv, argc, "WORD", &idx);
14666
14667 /* Unset community list. */
14668 ret = lcommunity_list_unset(bgp_clist, argv[idx]->arg, str, direct,
14669 style);
14670
14671 /* Free temporary community list string allocated by
14672 argv_concat(). */
14673 XFREE(MTYPE_TMP, str);
14674
14675 if (ret < 0) {
14676 community_list_perror(vty, ret);
14677 return CMD_WARNING_CONFIG_FAILED;
14678 }
14679
14680 return CMD_SUCCESS;
14681 }
14682
14683 /* "large-community-list" keyword help string. */
14684 #define LCOMMUNITY_LIST_STR "Add a large community list entry\n"
14685 #define LCOMMUNITY_VAL_STR "large community in 'aa:bb:cc' format\n"
14686
14687 #if CONFDATE > 20191005
14688 CPP_NOTICE("bgpd: remove deprecated 'ip large-community-list <(1-99)|(100-500)|standard|expanded> <deny|permit> <LINE|AA:BB:CC>' command")
14689 #endif
14690 DEFUN (lcommunity_list_standard,
14691 bgp_lcommunity_list_standard_cmd,
14692 "bgp large-community-list (1-99) <deny|permit>",
14693 BGP_STR
14694 LCOMMUNITY_LIST_STR
14695 "Large Community list number (standard)\n"
14696 "Specify large community to reject\n"
14697 "Specify large community to accept\n")
14698 {
14699 return lcommunity_list_set_vty(vty, argc, argv,
14700 LARGE_COMMUNITY_LIST_STANDARD, 0);
14701 }
14702
14703 ALIAS (lcommunity_list_standard,
14704 ip_lcommunity_list_standard_cmd,
14705 "ip large-community-list (1-99) <deny|permit>",
14706 IP_STR
14707 LCOMMUNITY_LIST_STR
14708 "Large Community list number (standard)\n"
14709 "Specify large community to reject\n"
14710 "Specify large community to accept\n")
14711
14712 DEFUN (lcommunity_list_standard1,
14713 bgp_lcommunity_list_standard1_cmd,
14714 "bgp large-community-list (1-99) <deny|permit> AA:BB:CC...",
14715 BGP_STR
14716 LCOMMUNITY_LIST_STR
14717 "Large Community list number (standard)\n"
14718 "Specify large community to reject\n"
14719 "Specify large community to accept\n"
14720 LCOMMUNITY_VAL_STR)
14721 {
14722 return lcommunity_list_set_vty(vty, argc, argv,
14723 LARGE_COMMUNITY_LIST_STANDARD, 0);
14724 }
14725
14726 ALIAS (lcommunity_list_standard1,
14727 ip_lcommunity_list_standard1_cmd,
14728 "ip large-community-list (1-99) <deny|permit> AA:BB:CC...",
14729 IP_STR
14730 LCOMMUNITY_LIST_STR
14731 "Large Community list number (standard)\n"
14732 "Specify large community to reject\n"
14733 "Specify large community to accept\n"
14734 LCOMMUNITY_VAL_STR)
14735
14736 DEFUN (lcommunity_list_expanded,
14737 bgp_lcommunity_list_expanded_cmd,
14738 "bgp large-community-list (100-500) <deny|permit> LINE...",
14739 BGP_STR
14740 LCOMMUNITY_LIST_STR
14741 "Large Community list number (expanded)\n"
14742 "Specify large community to reject\n"
14743 "Specify large community to accept\n"
14744 "An ordered list as a regular-expression\n")
14745 {
14746 return lcommunity_list_set_vty(vty, argc, argv,
14747 LARGE_COMMUNITY_LIST_EXPANDED, 0);
14748 }
14749
14750 ALIAS (lcommunity_list_expanded,
14751 ip_lcommunity_list_expanded_cmd,
14752 "ip large-community-list (100-500) <deny|permit> LINE...",
14753 IP_STR
14754 LCOMMUNITY_LIST_STR
14755 "Large Community list number (expanded)\n"
14756 "Specify large community to reject\n"
14757 "Specify large community to accept\n"
14758 "An ordered list as a regular-expression\n")
14759
14760 DEFUN (lcommunity_list_name_standard,
14761 bgp_lcommunity_list_name_standard_cmd,
14762 "bgp large-community-list standard WORD <deny|permit>",
14763 BGP_STR
14764 LCOMMUNITY_LIST_STR
14765 "Specify standard large-community-list\n"
14766 "Large Community list name\n"
14767 "Specify large community to reject\n"
14768 "Specify large community to accept\n")
14769 {
14770 return lcommunity_list_set_vty(vty, argc, argv,
14771 LARGE_COMMUNITY_LIST_STANDARD, 1);
14772 }
14773
14774 ALIAS (lcommunity_list_name_standard,
14775 ip_lcommunity_list_name_standard_cmd,
14776 "ip large-community-list standard WORD <deny|permit>",
14777 IP_STR
14778 LCOMMUNITY_LIST_STR
14779 "Specify standard large-community-list\n"
14780 "Large Community list name\n"
14781 "Specify large community to reject\n"
14782 "Specify large community to accept\n")
14783
14784 DEFUN (lcommunity_list_name_standard1,
14785 bgp_lcommunity_list_name_standard1_cmd,
14786 "bgp large-community-list standard WORD <deny|permit> AA:BB:CC...",
14787 BGP_STR
14788 LCOMMUNITY_LIST_STR
14789 "Specify standard large-community-list\n"
14790 "Large Community list name\n"
14791 "Specify large community to reject\n"
14792 "Specify large community to accept\n"
14793 LCOMMUNITY_VAL_STR)
14794 {
14795 return lcommunity_list_set_vty(vty, argc, argv,
14796 LARGE_COMMUNITY_LIST_STANDARD, 1);
14797 }
14798
14799 ALIAS (lcommunity_list_name_standard1,
14800 ip_lcommunity_list_name_standard1_cmd,
14801 "ip large-community-list standard WORD <deny|permit> AA:BB:CC...",
14802 IP_STR
14803 LCOMMUNITY_LIST_STR
14804 "Specify standard large-community-list\n"
14805 "Large Community list name\n"
14806 "Specify large community to reject\n"
14807 "Specify large community to accept\n"
14808 LCOMMUNITY_VAL_STR)
14809
14810 DEFUN (lcommunity_list_name_expanded,
14811 bgp_lcommunity_list_name_expanded_cmd,
14812 "bgp large-community-list expanded WORD <deny|permit> LINE...",
14813 BGP_STR
14814 LCOMMUNITY_LIST_STR
14815 "Specify expanded large-community-list\n"
14816 "Large Community list name\n"
14817 "Specify large community to reject\n"
14818 "Specify large community to accept\n"
14819 "An ordered list as a regular-expression\n")
14820 {
14821 return lcommunity_list_set_vty(vty, argc, argv,
14822 LARGE_COMMUNITY_LIST_EXPANDED, 1);
14823 }
14824
14825 ALIAS (lcommunity_list_name_expanded,
14826 ip_lcommunity_list_name_expanded_cmd,
14827 "ip large-community-list expanded WORD <deny|permit> LINE...",
14828 IP_STR
14829 LCOMMUNITY_LIST_STR
14830 "Specify expanded large-community-list\n"
14831 "Large Community list name\n"
14832 "Specify large community to reject\n"
14833 "Specify large community to accept\n"
14834 "An ordered list as a regular-expression\n")
14835
14836 DEFUN (no_lcommunity_list_standard_all,
14837 no_bgp_lcommunity_list_standard_all_cmd,
14838 "no bgp large-community-list <(1-99)|(100-500)|WORD>",
14839 NO_STR
14840 BGP_STR
14841 LCOMMUNITY_LIST_STR
14842 "Large Community list number (standard)\n"
14843 "Large Community list number (expanded)\n"
14844 "Large Community list name\n")
14845 {
14846 return lcommunity_list_unset_vty(vty, argc, argv,
14847 LARGE_COMMUNITY_LIST_STANDARD);
14848 }
14849
14850 ALIAS (no_lcommunity_list_standard_all,
14851 no_ip_lcommunity_list_standard_all_cmd,
14852 "no ip large-community-list <(1-99)|(100-500)|WORD>",
14853 NO_STR
14854 IP_STR
14855 LCOMMUNITY_LIST_STR
14856 "Large Community list number (standard)\n"
14857 "Large Community list number (expanded)\n"
14858 "Large Community list name\n")
14859
14860 DEFUN (no_lcommunity_list_name_expanded_all,
14861 no_bgp_lcommunity_list_name_expanded_all_cmd,
14862 "no bgp large-community-list expanded WORD",
14863 NO_STR
14864 BGP_STR
14865 LCOMMUNITY_LIST_STR
14866 "Specify expanded large-community-list\n"
14867 "Large Community list name\n")
14868 {
14869 return lcommunity_list_unset_vty(vty, argc, argv,
14870 LARGE_COMMUNITY_LIST_EXPANDED);
14871 }
14872
14873 ALIAS (no_lcommunity_list_name_expanded_all,
14874 no_ip_lcommunity_list_name_expanded_all_cmd,
14875 "no ip large-community-list expanded WORD",
14876 NO_STR
14877 IP_STR
14878 LCOMMUNITY_LIST_STR
14879 "Specify expanded large-community-list\n"
14880 "Large Community list name\n")
14881
14882 DEFUN (no_lcommunity_list_standard,
14883 no_bgp_lcommunity_list_standard_cmd,
14884 "no bgp large-community-list (1-99) <deny|permit> AA:AA:NN...",
14885 NO_STR
14886 BGP_STR
14887 LCOMMUNITY_LIST_STR
14888 "Large Community list number (standard)\n"
14889 "Specify large community to reject\n"
14890 "Specify large community to accept\n"
14891 LCOMMUNITY_VAL_STR)
14892 {
14893 return lcommunity_list_unset_vty(vty, argc, argv,
14894 LARGE_COMMUNITY_LIST_STANDARD);
14895 }
14896
14897 ALIAS (no_lcommunity_list_standard,
14898 no_ip_lcommunity_list_standard_cmd,
14899 "no ip large-community-list (1-99) <deny|permit> AA:AA:NN...",
14900 NO_STR
14901 IP_STR
14902 LCOMMUNITY_LIST_STR
14903 "Large Community list number (standard)\n"
14904 "Specify large community to reject\n"
14905 "Specify large community to accept\n"
14906 LCOMMUNITY_VAL_STR)
14907
14908 DEFUN (no_lcommunity_list_expanded,
14909 no_bgp_lcommunity_list_expanded_cmd,
14910 "no bgp large-community-list (100-500) <deny|permit> LINE...",
14911 NO_STR
14912 BGP_STR
14913 LCOMMUNITY_LIST_STR
14914 "Large Community list number (expanded)\n"
14915 "Specify large community to reject\n"
14916 "Specify large community to accept\n"
14917 "An ordered list as a regular-expression\n")
14918 {
14919 return lcommunity_list_unset_vty(vty, argc, argv,
14920 LARGE_COMMUNITY_LIST_EXPANDED);
14921 }
14922
14923 ALIAS (no_lcommunity_list_expanded,
14924 no_ip_lcommunity_list_expanded_cmd,
14925 "no ip large-community-list (100-500) <deny|permit> LINE...",
14926 NO_STR
14927 IP_STR
14928 LCOMMUNITY_LIST_STR
14929 "Large Community list number (expanded)\n"
14930 "Specify large community to reject\n"
14931 "Specify large community to accept\n"
14932 "An ordered list as a regular-expression\n")
14933
14934 DEFUN (no_lcommunity_list_name_standard,
14935 no_bgp_lcommunity_list_name_standard_cmd,
14936 "no bgp large-community-list standard WORD <deny|permit> AA:AA:NN...",
14937 NO_STR
14938 BGP_STR
14939 LCOMMUNITY_LIST_STR
14940 "Specify standard large-community-list\n"
14941 "Large Community list name\n"
14942 "Specify large community to reject\n"
14943 "Specify large community to accept\n"
14944 LCOMMUNITY_VAL_STR)
14945 {
14946 return lcommunity_list_unset_vty(vty, argc, argv,
14947 LARGE_COMMUNITY_LIST_STANDARD);
14948 }
14949
14950 ALIAS (no_lcommunity_list_name_standard,
14951 no_ip_lcommunity_list_name_standard_cmd,
14952 "no ip large-community-list standard WORD <deny|permit> AA:AA:NN...",
14953 NO_STR
14954 IP_STR
14955 LCOMMUNITY_LIST_STR
14956 "Specify standard large-community-list\n"
14957 "Large Community list name\n"
14958 "Specify large community to reject\n"
14959 "Specify large community to accept\n"
14960 LCOMMUNITY_VAL_STR)
14961
14962 DEFUN (no_lcommunity_list_name_expanded,
14963 no_bgp_lcommunity_list_name_expanded_cmd,
14964 "no bgp large-community-list expanded WORD <deny|permit> LINE...",
14965 NO_STR
14966 BGP_STR
14967 LCOMMUNITY_LIST_STR
14968 "Specify expanded large-community-list\n"
14969 "Large community list name\n"
14970 "Specify large community to reject\n"
14971 "Specify large community to accept\n"
14972 "An ordered list as a regular-expression\n")
14973 {
14974 return lcommunity_list_unset_vty(vty, argc, argv,
14975 LARGE_COMMUNITY_LIST_EXPANDED);
14976 }
14977
14978 ALIAS (no_lcommunity_list_name_expanded,
14979 no_ip_lcommunity_list_name_expanded_cmd,
14980 "no ip large-community-list expanded WORD <deny|permit> LINE...",
14981 NO_STR
14982 IP_STR
14983 LCOMMUNITY_LIST_STR
14984 "Specify expanded large-community-list\n"
14985 "Large community list name\n"
14986 "Specify large community to reject\n"
14987 "Specify large community to accept\n"
14988 "An ordered list as a regular-expression\n")
14989
14990 static void lcommunity_list_show(struct vty *vty, struct community_list *list)
14991 {
14992 struct community_entry *entry;
14993
14994 for (entry = list->head; entry; entry = entry->next) {
14995 if (entry == list->head) {
14996 if (all_digit(list->name))
14997 vty_out(vty, "Large community %s list %s\n",
14998 entry->style ==
14999 LARGE_COMMUNITY_LIST_STANDARD
15000 ? "standard"
15001 : "(expanded) access",
15002 list->name);
15003 else
15004 vty_out(vty,
15005 "Named large community %s list %s\n",
15006 entry->style ==
15007 LARGE_COMMUNITY_LIST_STANDARD
15008 ? "standard"
15009 : "expanded",
15010 list->name);
15011 }
15012 if (entry->any)
15013 vty_out(vty, " %s\n",
15014 community_direct_str(entry->direct));
15015 else
15016 vty_out(vty, " %s %s\n",
15017 community_direct_str(entry->direct),
15018 community_list_config_str(entry));
15019 }
15020 }
15021
15022 DEFUN (show_lcommunity_list,
15023 show_bgp_lcommunity_list_cmd,
15024 "show bgp large-community-list",
15025 SHOW_STR
15026 BGP_STR
15027 "List large-community list\n")
15028 {
15029 struct community_list *list;
15030 struct community_list_master *cm;
15031 int idx = 0;
15032
15033 if (argv_find(argv, argc, "ip", &idx)) {
15034 vty_out(vty, "This config option is deprecated, and is scheduled for removal.\n");
15035 vty_out(vty, "if you are using this please migrate to the below command.\n");
15036 vty_out(vty, "'show bgp large-community-list <(1-500)|WORD>'\n");
15037 zlog_warn("Deprecated option: 'ip show large-community-list <(1-500)|WORD>' being used");
15038 }
15039
15040 cm = community_list_master_lookup(bgp_clist,
15041 LARGE_COMMUNITY_LIST_MASTER);
15042 if (!cm)
15043 return CMD_SUCCESS;
15044
15045 for (list = cm->num.head; list; list = list->next)
15046 lcommunity_list_show(vty, list);
15047
15048 for (list = cm->str.head; list; list = list->next)
15049 lcommunity_list_show(vty, list);
15050
15051 return CMD_SUCCESS;
15052 }
15053
15054 ALIAS (show_lcommunity_list,
15055 show_ip_lcommunity_list_cmd,
15056 "show ip large-community-list",
15057 SHOW_STR
15058 IP_STR
15059 "List large-community list\n")
15060
15061 DEFUN (show_lcommunity_list_arg,
15062 show_bgp_lcommunity_list_arg_cmd,
15063 "show bgp large-community-list <(1-500)|WORD>",
15064 SHOW_STR
15065 BGP_STR
15066 "List large-community list\n"
15067 "large-community-list number\n"
15068 "large-community-list name\n")
15069 {
15070 struct community_list *list;
15071 int idx = 0;
15072
15073 if (argv_find(argv, argc, "ip", &idx)) {
15074 vty_out(vty, "This config option is deprecated, and is scheduled for removal.\n");
15075 vty_out(vty, "if you are using this please migrate to the below command.\n");
15076 vty_out(vty, "'show bgp large-community-list <(1-500)|WORD>'\n");
15077 zlog_warn("Deprecated option: 'ip show large-community-list <(1-500)|WORD>' being used");
15078 }
15079
15080 list = community_list_lookup(bgp_clist, argv[3]->arg, 0,
15081 LARGE_COMMUNITY_LIST_MASTER);
15082 if (!list) {
15083 vty_out(vty, "%% Can't find extcommunity-list\n");
15084 return CMD_WARNING;
15085 }
15086
15087 lcommunity_list_show(vty, list);
15088
15089 return CMD_SUCCESS;
15090 }
15091
15092 ALIAS (show_lcommunity_list_arg,
15093 show_ip_lcommunity_list_arg_cmd,
15094 "show ip large-community-list <(1-500)|WORD>",
15095 SHOW_STR
15096 IP_STR
15097 "List large-community list\n"
15098 "large-community-list number\n"
15099 "large-community-list name\n")
15100
15101 /* "extcommunity-list" keyword help string. */
15102 #define EXTCOMMUNITY_LIST_STR "Add a extended community list entry\n"
15103 #define EXTCOMMUNITY_VAL_STR "Extended community attribute in 'rt aa:nn_or_IPaddr:nn' OR 'soo aa:nn_or_IPaddr:nn' format\n"
15104
15105 DEFUN (extcommunity_list_standard,
15106 bgp_extcommunity_list_standard_cmd,
15107 "bgp extcommunity-list <(1-99)|standard WORD> <deny|permit> AA:NN...",
15108 BGP_STR
15109 EXTCOMMUNITY_LIST_STR
15110 "Extended Community list number (standard)\n"
15111 "Specify standard extcommunity-list\n"
15112 "Community list name\n"
15113 "Specify community to reject\n"
15114 "Specify community to accept\n"
15115 EXTCOMMUNITY_VAL_STR)
15116 {
15117 int style = EXTCOMMUNITY_LIST_STANDARD;
15118 int direct = 0;
15119 char *cl_number_or_name = NULL;
15120
15121 int idx = 0;
15122 if (argv_find(argv, argc, "ip", &idx)) {
15123 vty_out(vty, "This config option is deprecated, and is scheduled for removal.\n");
15124 vty_out(vty, "if you are using this please migrate to the below command.\n");
15125 vty_out(vty, "'bgp extcommunity-list <(1-99)|(100-500)|standard|expanded> <deny|permit> <LINE|AA:NN>'\n");
15126 zlog_warn("Deprecated option: 'ip extcommunity-list <(1-99)|(100-500)|standard|expanded> <deny|permit> <LINE|AA:NN>' being used");
15127 }
15128 argv_find(argv, argc, "(1-99)", &idx);
15129 argv_find(argv, argc, "WORD", &idx);
15130 cl_number_or_name = argv[idx]->arg;
15131 direct = argv_find(argv, argc, "permit", &idx) ? COMMUNITY_PERMIT
15132 : COMMUNITY_DENY;
15133 argv_find(argv, argc, "AA:NN", &idx);
15134 char *str = argv_concat(argv, argc, idx);
15135
15136 int ret = extcommunity_list_set(bgp_clist, cl_number_or_name, str,
15137 direct, style);
15138
15139 XFREE(MTYPE_TMP, str);
15140
15141 if (ret < 0) {
15142 community_list_perror(vty, ret);
15143 return CMD_WARNING_CONFIG_FAILED;
15144 }
15145
15146 return CMD_SUCCESS;
15147 }
15148
15149 #if CONFDATE > 20191005
15150 CPP_NOTICE("bgpd: remove deprecated 'ip extcommunity-list <(1-99)|(100-500)|standard|expanded> <deny|permit> <LINE|AA:NN>' command")
15151 #endif
15152 ALIAS (extcommunity_list_standard,
15153 ip_extcommunity_list_standard_cmd,
15154 "ip extcommunity-list <(1-99)|standard WORD> <deny|permit> AA:NN...",
15155 IP_STR
15156 EXTCOMMUNITY_LIST_STR
15157 "Extended Community list number (standard)\n"
15158 "Specify standard extcommunity-list\n"
15159 "Community list name\n"
15160 "Specify community to reject\n"
15161 "Specify community to accept\n"
15162 EXTCOMMUNITY_VAL_STR)
15163
15164 DEFUN (extcommunity_list_name_expanded,
15165 bgp_extcommunity_list_name_expanded_cmd,
15166 "bgp extcommunity-list <(100-500)|expanded WORD> <deny|permit> LINE...",
15167 BGP_STR
15168 EXTCOMMUNITY_LIST_STR
15169 "Extended Community list number (expanded)\n"
15170 "Specify expanded extcommunity-list\n"
15171 "Extended Community list name\n"
15172 "Specify community to reject\n"
15173 "Specify community to accept\n"
15174 "An ordered list as a regular-expression\n")
15175 {
15176 int style = EXTCOMMUNITY_LIST_EXPANDED;
15177 int direct = 0;
15178 char *cl_number_or_name = NULL;
15179
15180 int idx = 0;
15181 if (argv_find(argv, argc, "ip", &idx)) {
15182 vty_out(vty, "This config option is deprecated, and is scheduled for removal.\n");
15183 vty_out(vty, "if you are using this please migrate to the below command.\n");
15184 vty_out(vty, "'extcommunity-list <(1-99)|(100-500)|standard|expanded> <deny|permit> <LINE|AA:NN>'\n");
15185 zlog_warn("Deprecated option: ‘ip extcommunity-list <(1-99)|(100-500)|standard|expanded> <deny|permit> <LINE|AA:NN>' being used");
15186 }
15187
15188 argv_find(argv, argc, "(100-500)", &idx);
15189 argv_find(argv, argc, "WORD", &idx);
15190 cl_number_or_name = argv[idx]->arg;
15191 direct = argv_find(argv, argc, "permit", &idx) ? COMMUNITY_PERMIT
15192 : COMMUNITY_DENY;
15193 argv_find(argv, argc, "LINE", &idx);
15194 char *str = argv_concat(argv, argc, idx);
15195
15196 int ret = extcommunity_list_set(bgp_clist, cl_number_or_name, str,
15197 direct, style);
15198
15199 XFREE(MTYPE_TMP, str);
15200
15201 if (ret < 0) {
15202 community_list_perror(vty, ret);
15203 return CMD_WARNING_CONFIG_FAILED;
15204 }
15205
15206 return CMD_SUCCESS;
15207 }
15208
15209 ALIAS (extcommunity_list_name_expanded,
15210 ip_extcommunity_list_name_expanded_cmd,
15211 "ip extcommunity-list <(100-500)|expanded WORD> <deny|permit> LINE...",
15212 IP_STR
15213 EXTCOMMUNITY_LIST_STR
15214 "Extended Community list number (expanded)\n"
15215 "Specify expanded extcommunity-list\n"
15216 "Extended Community list name\n"
15217 "Specify community to reject\n"
15218 "Specify community to accept\n"
15219 "An ordered list as a regular-expression\n")
15220
15221 DEFUN (no_extcommunity_list_standard_all,
15222 no_bgp_extcommunity_list_standard_all_cmd,
15223 "no bgp extcommunity-list <(1-99)|standard WORD> <deny|permit> AA:NN...",
15224 NO_STR
15225 BGP_STR
15226 EXTCOMMUNITY_LIST_STR
15227 "Extended Community list number (standard)\n"
15228 "Specify standard extcommunity-list\n"
15229 "Community list name\n"
15230 "Specify community to reject\n"
15231 "Specify community to accept\n"
15232 EXTCOMMUNITY_VAL_STR)
15233 {
15234 int style = EXTCOMMUNITY_LIST_STANDARD;
15235 int direct = 0;
15236 char *cl_number_or_name = NULL;
15237 char *str = NULL;
15238
15239 int idx = 0;
15240 if (argv_find(argv, argc, "ip", &idx)) {
15241 vty_out(vty, "This config option is deprecated, and is scheduled for removal\n");
15242 vty_out(vty, "if you are using this please migrate to the below command.\n");
15243 vty_out(vty, "'no bgp extcommunity-list <(1-99)|(100-500)|standard|expanded> <deny|permit> <LINE|AA:NN>'\n");
15244 zlog_warn("Deprecated option: ‘no ip extcommunity-list <(1-99)|(100-500)|standard|expanded> <deny|permit> <LINE|AA:NN>' being used");
15245 }
15246
15247 idx = 0;
15248 argv_find(argv, argc, "permit", &idx);
15249 argv_find(argv, argc, "deny", &idx);
15250
15251 if (idx) {
15252 direct = argv_find(argv, argc, "permit", &idx)
15253 ? COMMUNITY_PERMIT
15254 : COMMUNITY_DENY;
15255
15256 idx = 0;
15257 argv_find(argv, argc, "AA:NN", &idx);
15258 str = argv_concat(argv, argc, idx);
15259 }
15260
15261 idx = 0;
15262 argv_find(argv, argc, "(1-99)", &idx);
15263 argv_find(argv, argc, "WORD", &idx);
15264 cl_number_or_name = argv[idx]->arg;
15265
15266 int ret = extcommunity_list_unset(bgp_clist, cl_number_or_name, str,
15267 direct, style);
15268
15269 XFREE(MTYPE_TMP, str);
15270
15271 if (ret < 0) {
15272 community_list_perror(vty, ret);
15273 return CMD_WARNING_CONFIG_FAILED;
15274 }
15275
15276 return CMD_SUCCESS;
15277 }
15278
15279 ALIAS (no_extcommunity_list_standard_all,
15280 no_ip_extcommunity_list_standard_all_cmd,
15281 "no ip extcommunity-list <(1-99)|standard WORD> <deny|permit> AA:NN...",
15282 NO_STR
15283 IP_STR
15284 EXTCOMMUNITY_LIST_STR
15285 "Extended Community list number (standard)\n"
15286 "Specify standard extcommunity-list\n"
15287 "Community list name\n"
15288 "Specify community to reject\n"
15289 "Specify community to accept\n"
15290 EXTCOMMUNITY_VAL_STR)
15291
15292 ALIAS(no_extcommunity_list_standard_all,
15293 no_bgp_extcommunity_list_standard_all_list_cmd,
15294 "no bgp extcommunity-list <(1-99)|standard WORD>",
15295 NO_STR IP_STR EXTCOMMUNITY_LIST_STR
15296 "Extended Community list number (standard)\n"
15297 "Specify standard extcommunity-list\n"
15298 "Community list name\n")
15299
15300 ALIAS(no_extcommunity_list_standard_all,
15301 no_ip_extcommunity_list_standard_all_list_cmd,
15302 "no ip extcommunity-list <(1-99)|standard WORD>",
15303 NO_STR IP_STR EXTCOMMUNITY_LIST_STR
15304 "Extended Community list number (standard)\n"
15305 "Specify standard extcommunity-list\n"
15306 "Community list name\n")
15307
15308 DEFUN (no_extcommunity_list_expanded_all,
15309 no_bgp_extcommunity_list_expanded_all_cmd,
15310 "no bgp extcommunity-list <(100-500)|expanded WORD> <deny|permit> LINE...",
15311 NO_STR
15312 BGP_STR
15313 EXTCOMMUNITY_LIST_STR
15314 "Extended Community list number (expanded)\n"
15315 "Specify expanded extcommunity-list\n"
15316 "Extended Community list name\n"
15317 "Specify community to reject\n"
15318 "Specify community to accept\n"
15319 "An ordered list as a regular-expression\n")
15320 {
15321 int style = EXTCOMMUNITY_LIST_EXPANDED;
15322 int direct = 0;
15323 char *cl_number_or_name = NULL;
15324 char *str = NULL;
15325
15326 int idx = 0;
15327 if (argv_find(argv, argc, "ip", &idx)) {
15328 vty_out(vty, "This config option is deprecated, and is scheduled for removal.\n");
15329 vty_out(vty, "if you are using this please migrate to the below command.\n");
15330 vty_out(vty, "'no bgp extcommunity-list <(1-99)|(100-500)|standard|expanded> <deny|permit> <LINE|AA:NN>'\n");
15331 zlog_warn("Deprecated option: ‘no ip extcommunity-list <(1-99)|(100-500)|standard|expanded> <deny|permit> <LINE|AA:NN>' being used");
15332 }
15333
15334 idx = 0;
15335 argv_find(argv, argc, "permit", &idx);
15336 argv_find(argv, argc, "deny", &idx);
15337
15338 if (idx) {
15339 direct = argv_find(argv, argc, "permit", &idx)
15340 ? COMMUNITY_PERMIT
15341 : COMMUNITY_DENY;
15342
15343 idx = 0;
15344 argv_find(argv, argc, "LINE", &idx);
15345 str = argv_concat(argv, argc, idx);
15346 }
15347
15348 idx = 0;
15349 argv_find(argv, argc, "(100-500)", &idx);
15350 argv_find(argv, argc, "WORD", &idx);
15351 cl_number_or_name = argv[idx]->arg;
15352
15353 int ret = extcommunity_list_unset(bgp_clist, cl_number_or_name, str,
15354 direct, style);
15355
15356 XFREE(MTYPE_TMP, str);
15357
15358 if (ret < 0) {
15359 community_list_perror(vty, ret);
15360 return CMD_WARNING_CONFIG_FAILED;
15361 }
15362
15363 return CMD_SUCCESS;
15364 }
15365
15366 ALIAS (no_extcommunity_list_expanded_all,
15367 no_ip_extcommunity_list_expanded_all_cmd,
15368 "no ip extcommunity-list <(100-500)|expanded WORD> <deny|permit> LINE...",
15369 NO_STR
15370 IP_STR
15371 EXTCOMMUNITY_LIST_STR
15372 "Extended Community list number (expanded)\n"
15373 "Specify expanded extcommunity-list\n"
15374 "Extended Community list name\n"
15375 "Specify community to reject\n"
15376 "Specify community to accept\n"
15377 "An ordered list as a regular-expression\n")
15378
15379 ALIAS(no_extcommunity_list_expanded_all,
15380 no_ip_extcommunity_list_expanded_all_list_cmd,
15381 "no ip extcommunity-list <(100-500)|expanded WORD>",
15382 NO_STR IP_STR EXTCOMMUNITY_LIST_STR
15383 "Extended Community list number (expanded)\n"
15384 "Specify expanded extcommunity-list\n"
15385 "Extended Community list name\n")
15386
15387 ALIAS(no_extcommunity_list_expanded_all,
15388 no_bgp_extcommunity_list_expanded_all_list_cmd,
15389 "no bgp extcommunity-list <(100-500)|expanded WORD>",
15390 NO_STR IP_STR EXTCOMMUNITY_LIST_STR
15391 "Extended Community list number (expanded)\n"
15392 "Specify expanded extcommunity-list\n"
15393 "Extended Community list name\n")
15394
15395 static void extcommunity_list_show(struct vty *vty, struct community_list *list)
15396 {
15397 struct community_entry *entry;
15398
15399 for (entry = list->head; entry; entry = entry->next) {
15400 if (entry == list->head) {
15401 if (all_digit(list->name))
15402 vty_out(vty, "Extended community %s list %s\n",
15403 entry->style == EXTCOMMUNITY_LIST_STANDARD
15404 ? "standard"
15405 : "(expanded) access",
15406 list->name);
15407 else
15408 vty_out(vty,
15409 "Named extended community %s list %s\n",
15410 entry->style == EXTCOMMUNITY_LIST_STANDARD
15411 ? "standard"
15412 : "expanded",
15413 list->name);
15414 }
15415 if (entry->any)
15416 vty_out(vty, " %s\n",
15417 community_direct_str(entry->direct));
15418 else
15419 vty_out(vty, " %s %s\n",
15420 community_direct_str(entry->direct),
15421 community_list_config_str(entry));
15422 }
15423 }
15424
15425 DEFUN (show_extcommunity_list,
15426 show_bgp_extcommunity_list_cmd,
15427 "show bgp extcommunity-list",
15428 SHOW_STR
15429 BGP_STR
15430 "List extended-community list\n")
15431 {
15432 struct community_list *list;
15433 struct community_list_master *cm;
15434 int idx = 0;
15435
15436 if (argv_find(argv, argc, "ip", &idx)) {
15437 vty_out(vty, "This config option is deprecated, and is scheduled for removal\n");
15438 vty_out(vty, "if you are using this please migrate to the below command.\n");
15439 vty_out(vty, "'show bgp extcommunity-list <(1-500)|WORD>'\n");
15440 zlog_warn("Deprecated option: 'ip show extcommunity-list <(1-500)|WORD>' being used");
15441 }
15442 cm = community_list_master_lookup(bgp_clist, EXTCOMMUNITY_LIST_MASTER);
15443 if (!cm)
15444 return CMD_SUCCESS;
15445
15446 for (list = cm->num.head; list; list = list->next)
15447 extcommunity_list_show(vty, list);
15448
15449 for (list = cm->str.head; list; list = list->next)
15450 extcommunity_list_show(vty, list);
15451
15452 return CMD_SUCCESS;
15453 }
15454
15455 ALIAS (show_extcommunity_list,
15456 show_ip_extcommunity_list_cmd,
15457 "show ip extcommunity-list",
15458 SHOW_STR
15459 IP_STR
15460 "List extended-community list\n")
15461
15462 DEFUN (show_extcommunity_list_arg,
15463 show_bgp_extcommunity_list_arg_cmd,
15464 "show bgp extcommunity-list <(1-500)|WORD>",
15465 SHOW_STR
15466 BGP_STR
15467 "List extended-community list\n"
15468 "Extcommunity-list number\n"
15469 "Extcommunity-list name\n")
15470 {
15471 int idx_comm_list = 3;
15472 struct community_list *list;
15473 int idx = 0;
15474
15475 if (argv_find(argv, argc, "ip", &idx)) {
15476 vty_out(vty, "This config option is deprecated, and is scheduled for removal.\n");
15477 vty_out(vty, "if you are using this please migrate to the below command.\n");
15478 vty_out(vty, "'show bgp extcommunity-list <(1-500)|WORD>'\n");
15479 zlog_warn("Deprecated option: 'ip show extcommunity-list <(1-500)|WORD>' being used");
15480 }
15481 list = community_list_lookup(bgp_clist, argv[idx_comm_list]->arg, 0,
15482 EXTCOMMUNITY_LIST_MASTER);
15483 if (!list) {
15484 vty_out(vty, "%% Can't find extcommunity-list\n");
15485 return CMD_WARNING;
15486 }
15487
15488 extcommunity_list_show(vty, list);
15489
15490 return CMD_SUCCESS;
15491 }
15492
15493 ALIAS (show_extcommunity_list_arg,
15494 show_ip_extcommunity_list_arg_cmd,
15495 "show ip extcommunity-list <(1-500)|WORD>",
15496 SHOW_STR
15497 IP_STR
15498 "List extended-community list\n"
15499 "Extcommunity-list number\n"
15500 "Extcommunity-list name\n")
15501
15502 /* Display community-list and extcommunity-list configuration. */
15503 static int community_list_config_write(struct vty *vty)
15504 {
15505 struct community_list *list;
15506 struct community_entry *entry;
15507 struct community_list_master *cm;
15508 int write = 0;
15509
15510 /* Community-list. */
15511 cm = community_list_master_lookup(bgp_clist, COMMUNITY_LIST_MASTER);
15512
15513 for (list = cm->num.head; list; list = list->next)
15514 for (entry = list->head; entry; entry = entry->next) {
15515 vty_out(vty, "bgp community-list %s %s %s\n", list->name,
15516 community_direct_str(entry->direct),
15517 community_list_config_str(entry));
15518 write++;
15519 }
15520 for (list = cm->str.head; list; list = list->next)
15521 for (entry = list->head; entry; entry = entry->next) {
15522 vty_out(vty, "bgp community-list %s %s %s %s\n",
15523 entry->style == COMMUNITY_LIST_STANDARD
15524 ? "standard"
15525 : "expanded",
15526 list->name, community_direct_str(entry->direct),
15527 community_list_config_str(entry));
15528 write++;
15529 }
15530
15531 /* Extcommunity-list. */
15532 cm = community_list_master_lookup(bgp_clist, EXTCOMMUNITY_LIST_MASTER);
15533
15534 for (list = cm->num.head; list; list = list->next)
15535 for (entry = list->head; entry; entry = entry->next) {
15536 vty_out(vty, "bgp extcommunity-list %s %s %s\n",
15537 list->name, community_direct_str(entry->direct),
15538 community_list_config_str(entry));
15539 write++;
15540 }
15541 for (list = cm->str.head; list; list = list->next)
15542 for (entry = list->head; entry; entry = entry->next) {
15543 vty_out(vty, "bgp extcommunity-list %s %s %s %s\n",
15544 entry->style == EXTCOMMUNITY_LIST_STANDARD
15545 ? "standard"
15546 : "expanded",
15547 list->name, community_direct_str(entry->direct),
15548 community_list_config_str(entry));
15549 write++;
15550 }
15551
15552
15553 /* lcommunity-list. */
15554 cm = community_list_master_lookup(bgp_clist,
15555 LARGE_COMMUNITY_LIST_MASTER);
15556
15557 for (list = cm->num.head; list; list = list->next)
15558 for (entry = list->head; entry; entry = entry->next) {
15559 vty_out(vty, "bgp large-community-list %s %s %s\n",
15560 list->name, community_direct_str(entry->direct),
15561 community_list_config_str(entry));
15562 write++;
15563 }
15564 for (list = cm->str.head; list; list = list->next)
15565 for (entry = list->head; entry; entry = entry->next) {
15566 vty_out(vty, "bgp large-community-list %s %s %s %s\n",
15567 entry->style == LARGE_COMMUNITY_LIST_STANDARD
15568 ? "standard"
15569 : "expanded",
15570 list->name, community_direct_str(entry->direct),
15571 community_list_config_str(entry));
15572 write++;
15573 }
15574
15575 return write;
15576 }
15577
15578 static struct cmd_node community_list_node = {
15579 COMMUNITY_LIST_NODE, "", 1 /* Export to vtysh. */
15580 };
15581
15582 static void community_list_vty(void)
15583 {
15584 install_node(&community_list_node, community_list_config_write);
15585
15586 /* Community-list. */
15587 install_element(CONFIG_NODE, &bgp_community_list_standard_cmd);
15588 install_element(CONFIG_NODE, &bgp_community_list_expanded_all_cmd);
15589 install_element(CONFIG_NODE, &no_bgp_community_list_standard_all_cmd);
15590 install_element(CONFIG_NODE, &no_bgp_community_list_standard_all_list_cmd);
15591 install_element(CONFIG_NODE, &no_bgp_community_list_expanded_all_cmd);
15592 install_element(CONFIG_NODE, &no_bgp_community_list_expanded_all_list_cmd);
15593 install_element(VIEW_NODE, &show_bgp_community_list_cmd);
15594 install_element(VIEW_NODE, &show_bgp_community_list_arg_cmd);
15595 install_element(CONFIG_NODE, &ip_community_list_standard_cmd);
15596 install_element(CONFIG_NODE, &ip_community_list_expanded_all_cmd);
15597 install_element(CONFIG_NODE, &no_ip_community_list_standard_all_cmd);
15598 install_element(CONFIG_NODE, &no_ip_community_list_standard_all_list_cmd);
15599 install_element(CONFIG_NODE, &no_ip_community_list_expanded_all_cmd);
15600 install_element(CONFIG_NODE, &no_ip_community_list_expanded_all_list_cmd);
15601 install_element(VIEW_NODE, &show_ip_community_list_cmd);
15602 install_element(VIEW_NODE, &show_ip_community_list_arg_cmd);
15603
15604 /* Extcommunity-list. */
15605 install_element(CONFIG_NODE, &bgp_extcommunity_list_standard_cmd);
15606 install_element(CONFIG_NODE, &bgp_extcommunity_list_name_expanded_cmd);
15607 install_element(CONFIG_NODE, &no_bgp_extcommunity_list_standard_all_cmd);
15608 install_element(CONFIG_NODE,
15609 &no_bgp_extcommunity_list_standard_all_list_cmd);
15610 install_element(CONFIG_NODE, &no_bgp_extcommunity_list_expanded_all_cmd);
15611 install_element(CONFIG_NODE,
15612 &no_bgp_extcommunity_list_expanded_all_list_cmd);
15613 install_element(VIEW_NODE, &show_bgp_extcommunity_list_cmd);
15614 install_element(VIEW_NODE, &show_bgp_extcommunity_list_arg_cmd);
15615 install_element(CONFIG_NODE, &ip_extcommunity_list_standard_cmd);
15616 install_element(CONFIG_NODE, &ip_extcommunity_list_name_expanded_cmd);
15617 install_element(CONFIG_NODE, &no_ip_extcommunity_list_standard_all_cmd);
15618 install_element(CONFIG_NODE, &no_ip_extcommunity_list_standard_all_list_cmd);
15619 install_element(CONFIG_NODE, &no_ip_extcommunity_list_expanded_all_cmd);
15620 install_element(CONFIG_NODE, &no_ip_extcommunity_list_expanded_all_list_cmd);
15621 install_element(VIEW_NODE, &show_ip_extcommunity_list_cmd);
15622 install_element(VIEW_NODE, &show_ip_extcommunity_list_arg_cmd);
15623
15624 /* Large Community List */
15625 install_element(CONFIG_NODE, &bgp_lcommunity_list_standard_cmd);
15626 install_element(CONFIG_NODE, &bgp_lcommunity_list_standard1_cmd);
15627 install_element(CONFIG_NODE, &bgp_lcommunity_list_expanded_cmd);
15628 install_element(CONFIG_NODE, &bgp_lcommunity_list_name_standard_cmd);
15629 install_element(CONFIG_NODE, &bgp_lcommunity_list_name_standard1_cmd);
15630 install_element(CONFIG_NODE, &bgp_lcommunity_list_name_expanded_cmd);
15631 install_element(CONFIG_NODE, &no_bgp_lcommunity_list_standard_all_cmd);
15632 install_element(CONFIG_NODE,
15633 &no_bgp_lcommunity_list_name_expanded_all_cmd);
15634 install_element(CONFIG_NODE, &no_bgp_lcommunity_list_standard_cmd);
15635 install_element(CONFIG_NODE, &no_bgp_lcommunity_list_expanded_cmd);
15636 install_element(CONFIG_NODE, &no_bgp_lcommunity_list_name_standard_cmd);
15637 install_element(CONFIG_NODE, &no_bgp_lcommunity_list_name_expanded_cmd);
15638 install_element(VIEW_NODE, &show_bgp_lcommunity_list_cmd);
15639 install_element(VIEW_NODE, &show_bgp_lcommunity_list_arg_cmd);
15640 install_element(CONFIG_NODE, &ip_lcommunity_list_standard_cmd);
15641 install_element(CONFIG_NODE, &ip_lcommunity_list_standard1_cmd);
15642 install_element(CONFIG_NODE, &ip_lcommunity_list_expanded_cmd);
15643 install_element(CONFIG_NODE, &ip_lcommunity_list_name_standard_cmd);
15644 install_element(CONFIG_NODE, &ip_lcommunity_list_name_standard1_cmd);
15645 install_element(CONFIG_NODE, &ip_lcommunity_list_name_expanded_cmd);
15646 install_element(CONFIG_NODE, &no_ip_lcommunity_list_standard_all_cmd);
15647 install_element(CONFIG_NODE,
15648 &no_ip_lcommunity_list_name_expanded_all_cmd);
15649 install_element(CONFIG_NODE, &no_ip_lcommunity_list_standard_cmd);
15650 install_element(CONFIG_NODE, &no_ip_lcommunity_list_expanded_cmd);
15651 install_element(CONFIG_NODE, &no_ip_lcommunity_list_name_standard_cmd);
15652 install_element(CONFIG_NODE, &no_ip_lcommunity_list_name_expanded_cmd);
15653 install_element(VIEW_NODE, &show_ip_lcommunity_list_cmd);
15654 install_element(VIEW_NODE, &show_ip_lcommunity_list_arg_cmd);
15655 }