]> git.proxmox.com Git - mirror_frr.git/blob - bgpd/bgp_vty.c
27042017dd7ff343562e9ff46216e6aef692905d
[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_UNSPEC:
123 case AFI_MAX:
124 // We should never be here but to clarify the switch statement..
125 return BGP_IPV4_NODE;
126 break;
127 }
128
129 // Impossible to happen
130 return BGP_IPV4_NODE;
131 }
132
133 /* Utility function to get address family from current node. */
134 afi_t bgp_node_afi(struct vty *vty)
135 {
136 afi_t afi;
137 switch (vty->node) {
138 case BGP_IPV6_NODE:
139 case BGP_IPV6M_NODE:
140 case BGP_IPV6L_NODE:
141 case BGP_VPNV6_NODE:
142 case BGP_FLOWSPECV6_NODE:
143 afi = AFI_IP6;
144 break;
145 case BGP_EVPN_NODE:
146 afi = AFI_L2VPN;
147 break;
148 default:
149 afi = AFI_IP;
150 break;
151 }
152 return afi;
153 }
154
155 /* Utility function to get subsequent address family from current
156 node. */
157 safi_t bgp_node_safi(struct vty *vty)
158 {
159 safi_t safi;
160 switch (vty->node) {
161 case BGP_VPNV4_NODE:
162 case BGP_VPNV6_NODE:
163 safi = SAFI_MPLS_VPN;
164 break;
165 case BGP_IPV4M_NODE:
166 case BGP_IPV6M_NODE:
167 safi = SAFI_MULTICAST;
168 break;
169 case BGP_EVPN_NODE:
170 safi = SAFI_EVPN;
171 break;
172 case BGP_IPV4L_NODE:
173 case BGP_IPV6L_NODE:
174 safi = SAFI_LABELED_UNICAST;
175 break;
176 case BGP_FLOWSPECV4_NODE:
177 case BGP_FLOWSPECV6_NODE:
178 safi = SAFI_FLOWSPEC;
179 break;
180 default:
181 safi = SAFI_UNICAST;
182 break;
183 }
184 return safi;
185 }
186
187 /**
188 * Converts an AFI in string form to afi_t
189 *
190 * @param afi string, one of
191 * - "ipv4"
192 * - "ipv6"
193 * - "l2vpn"
194 * @return the corresponding afi_t
195 */
196 afi_t bgp_vty_afi_from_str(const char *afi_str)
197 {
198 afi_t afi = AFI_MAX; /* unknown */
199 if (strmatch(afi_str, "ipv4"))
200 afi = AFI_IP;
201 else if (strmatch(afi_str, "ipv6"))
202 afi = AFI_IP6;
203 else if (strmatch(afi_str, "l2vpn"))
204 afi = AFI_L2VPN;
205 return afi;
206 }
207
208 int argv_find_and_parse_afi(struct cmd_token **argv, int argc, int *index,
209 afi_t *afi)
210 {
211 int ret = 0;
212 if (argv_find(argv, argc, "ipv4", index)) {
213 ret = 1;
214 if (afi)
215 *afi = AFI_IP;
216 } else if (argv_find(argv, argc, "ipv6", index)) {
217 ret = 1;
218 if (afi)
219 *afi = AFI_IP6;
220 } else if (argv_find(argv, argc, "l2vpn", index)) {
221 ret = 1;
222 if (afi)
223 *afi = AFI_L2VPN;
224 }
225 return ret;
226 }
227
228 /* supports <unicast|multicast|vpn|labeled-unicast> */
229 safi_t bgp_vty_safi_from_str(const char *safi_str)
230 {
231 safi_t safi = SAFI_MAX; /* unknown */
232 if (strmatch(safi_str, "multicast"))
233 safi = SAFI_MULTICAST;
234 else if (strmatch(safi_str, "unicast"))
235 safi = SAFI_UNICAST;
236 else if (strmatch(safi_str, "vpn"))
237 safi = SAFI_MPLS_VPN;
238 else if (strmatch(safi_str, "evpn"))
239 safi = SAFI_EVPN;
240 else if (strmatch(safi_str, "labeled-unicast"))
241 safi = SAFI_LABELED_UNICAST;
242 else if (strmatch(safi_str, "flowspec"))
243 safi = SAFI_FLOWSPEC;
244 return safi;
245 }
246
247 int argv_find_and_parse_safi(struct cmd_token **argv, int argc, int *index,
248 safi_t *safi)
249 {
250 int ret = 0;
251 if (argv_find(argv, argc, "unicast", index)) {
252 ret = 1;
253 if (safi)
254 *safi = SAFI_UNICAST;
255 } else if (argv_find(argv, argc, "multicast", index)) {
256 ret = 1;
257 if (safi)
258 *safi = SAFI_MULTICAST;
259 } else if (argv_find(argv, argc, "labeled-unicast", index)) {
260 ret = 1;
261 if (safi)
262 *safi = SAFI_LABELED_UNICAST;
263 } else if (argv_find(argv, argc, "vpn", index)) {
264 ret = 1;
265 if (safi)
266 *safi = SAFI_MPLS_VPN;
267 } else if (argv_find(argv, argc, "evpn", index)) {
268 ret = 1;
269 if (safi)
270 *safi = SAFI_EVPN;
271 } else if (argv_find(argv, argc, "flowspec", index)) {
272 ret = 1;
273 if (safi)
274 *safi = SAFI_FLOWSPEC;
275 }
276 return ret;
277 }
278
279 /*
280 * bgp_vty_find_and_parse_afi_safi_bgp
281 *
282 * For a given 'show ...' command, correctly parse the afi/safi/bgp out from it
283 * This function *assumes* that the calling function pre-sets the afi/safi/bgp
284 * to appropriate values for the calling function. This is to allow the
285 * calling function to make decisions appropriate for the show command
286 * that is being parsed.
287 *
288 * The show commands are generally of the form:
289 * "show [ip] bgp [<view|vrf> VIEWVRFNAME] [<ipv4|ipv6>
290 * [<unicast|multicast|vpn|labeled-unicast>]] ..."
291 *
292 * Since we use argv_find if the show command in particular doesn't have:
293 * [ip]
294 * [<view|vrf> VIEWVRFNAME]
295 * [<ipv4|ipv6> [<unicast|multicast|vpn|labeled-unicast>]]
296 * The command parsing should still be ok.
297 *
298 * vty -> The vty for the command so we can output some useful data in
299 * the event of a parse error in the vrf.
300 * argv -> The command tokens
301 * argc -> How many command tokens we have
302 * idx -> The current place in the command, generally should be 0 for this
303 * function
304 * afi -> The parsed afi if it was included in the show command, returned here
305 * safi -> The parsed safi if it was included in the show command, returned here
306 * bgp -> Pointer to the bgp data structure we need to fill in.
307 * use_json -> json is configured or not
308 *
309 * The function returns the correct location in the parse tree for the
310 * last token found.
311 *
312 * Returns 0 for failure to parse correctly, else the idx position of where
313 * it found the last token.
314 */
315 int bgp_vty_find_and_parse_afi_safi_bgp(struct vty *vty,
316 struct cmd_token **argv, int argc,
317 int *idx, afi_t *afi, safi_t *safi,
318 struct bgp **bgp, bool use_json)
319 {
320 char *vrf_name = NULL;
321
322 assert(afi);
323 assert(safi);
324 assert(bgp);
325
326 if (argv_find(argv, argc, "ip", idx))
327 *afi = AFI_IP;
328
329 if (argv_find(argv, argc, "view", idx))
330 vrf_name = argv[*idx + 1]->arg;
331 else if (argv_find(argv, argc, "vrf", idx)) {
332 vrf_name = argv[*idx + 1]->arg;
333 if (strmatch(vrf_name, VRF_DEFAULT_NAME))
334 vrf_name = NULL;
335 }
336 if (vrf_name) {
337 if (strmatch(vrf_name, "all"))
338 *bgp = NULL;
339 else {
340 *bgp = bgp_lookup_by_name(vrf_name);
341 if (!*bgp) {
342 if (use_json) {
343 json_object *json = NULL;
344 json = json_object_new_object();
345 json_object_string_add(
346 json, "warning",
347 "View/Vrf is unknown");
348 vty_out(vty, "%s\n",
349 json_object_to_json_string_ext(json,
350 JSON_C_TO_STRING_PRETTY));
351 json_object_free(json);
352 }
353 else
354 vty_out(vty, "View/Vrf %s is unknown\n",
355 vrf_name);
356 *idx = 0;
357 return 0;
358 }
359 }
360 } else {
361 *bgp = bgp_get_default();
362 if (!*bgp) {
363 if (use_json) {
364 json_object *json = NULL;
365 json = json_object_new_object();
366 json_object_string_add(
367 json, "warning",
368 "Default BGP instance not found");
369 vty_out(vty, "%s\n",
370 json_object_to_json_string_ext(json,
371 JSON_C_TO_STRING_PRETTY));
372 json_object_free(json);
373 }
374 else
375 vty_out(vty,
376 "Default BGP instance not found\n");
377 *idx = 0;
378 return 0;
379 }
380 }
381
382 if (argv_find_and_parse_afi(argv, argc, idx, afi))
383 argv_find_and_parse_safi(argv, argc, idx, safi);
384
385 *idx += 1;
386 return *idx;
387 }
388
389 static int peer_address_self_check(struct bgp *bgp, union sockunion *su)
390 {
391 struct interface *ifp = NULL;
392
393 if (su->sa.sa_family == AF_INET)
394 ifp = if_lookup_by_ipv4_exact(&su->sin.sin_addr, bgp->vrf_id);
395 else if (su->sa.sa_family == AF_INET6)
396 ifp = if_lookup_by_ipv6_exact(&su->sin6.sin6_addr,
397 su->sin6.sin6_scope_id,
398 bgp->vrf_id);
399
400 if (ifp)
401 return 1;
402
403 return 0;
404 }
405
406 /* Utility function for looking up peer from VTY. */
407 /* This is used only for configuration, so disallow if attempted on
408 * a dynamic neighbor.
409 */
410 static struct peer *peer_lookup_vty(struct vty *vty, const char *ip_str)
411 {
412 struct bgp *bgp = VTY_GET_CONTEXT(bgp);
413 int ret;
414 union sockunion su;
415 struct peer *peer;
416
417 if (!bgp) {
418 return NULL;
419 }
420
421 ret = str2sockunion(ip_str, &su);
422 if (ret < 0) {
423 peer = peer_lookup_by_conf_if(bgp, ip_str);
424 if (!peer) {
425 if ((peer = peer_lookup_by_hostname(bgp, ip_str))
426 == NULL) {
427 vty_out(vty,
428 "%% Malformed address or name: %s\n",
429 ip_str);
430 return NULL;
431 }
432 }
433 } else {
434 peer = peer_lookup(bgp, &su);
435 if (!peer) {
436 vty_out(vty,
437 "%% Specify remote-as or peer-group commands first\n");
438 return NULL;
439 }
440 if (peer_dynamic_neighbor(peer)) {
441 vty_out(vty,
442 "%% Operation not allowed on a dynamic neighbor\n");
443 return NULL;
444 }
445 }
446 return peer;
447 }
448
449 /* Utility function for looking up peer or peer group. */
450 /* This is used only for configuration, so disallow if attempted on
451 * a dynamic neighbor.
452 */
453 struct peer *peer_and_group_lookup_vty(struct vty *vty, const char *peer_str)
454 {
455 struct bgp *bgp = VTY_GET_CONTEXT(bgp);
456 int ret;
457 union sockunion su;
458 struct peer *peer = NULL;
459 struct peer_group *group = NULL;
460
461 if (!bgp) {
462 return NULL;
463 }
464
465 ret = str2sockunion(peer_str, &su);
466 if (ret == 0) {
467 /* IP address, locate peer. */
468 peer = peer_lookup(bgp, &su);
469 } else {
470 /* Not IP, could match either peer configured on interface or a
471 * group. */
472 peer = peer_lookup_by_conf_if(bgp, peer_str);
473 if (!peer)
474 group = peer_group_lookup(bgp, peer_str);
475 }
476
477 if (peer) {
478 if (peer_dynamic_neighbor(peer)) {
479 vty_out(vty,
480 "%% Operation not allowed on a dynamic neighbor\n");
481 return NULL;
482 }
483
484 return peer;
485 }
486
487 if (group)
488 return group->conf;
489
490 vty_out(vty, "%% Specify remote-as or peer-group commands first\n");
491
492 return NULL;
493 }
494
495 int bgp_vty_return(struct vty *vty, int ret)
496 {
497 const char *str = NULL;
498
499 switch (ret) {
500 case BGP_ERR_INVALID_VALUE:
501 str = "Invalid value";
502 break;
503 case BGP_ERR_INVALID_FLAG:
504 str = "Invalid flag";
505 break;
506 case BGP_ERR_PEER_GROUP_SHUTDOWN:
507 str = "Peer-group has been shutdown. Activate the peer-group first";
508 break;
509 case BGP_ERR_PEER_FLAG_CONFLICT:
510 str = "Can't set override-capability and strict-capability-match at the same time";
511 break;
512 case BGP_ERR_PEER_GROUP_NO_REMOTE_AS:
513 str = "Specify remote-as or peer-group remote AS first";
514 break;
515 case BGP_ERR_PEER_GROUP_CANT_CHANGE:
516 str = "Cannot change the peer-group. Deconfigure first";
517 break;
518 case BGP_ERR_PEER_GROUP_MISMATCH:
519 str = "Peer is not a member of this peer-group";
520 break;
521 case BGP_ERR_PEER_FILTER_CONFLICT:
522 str = "Prefix/distribute list can not co-exist";
523 break;
524 case BGP_ERR_NOT_INTERNAL_PEER:
525 str = "Invalid command. Not an internal neighbor";
526 break;
527 case BGP_ERR_REMOVE_PRIVATE_AS:
528 str = "remove-private-AS cannot be configured for IBGP peers";
529 break;
530 case BGP_ERR_LOCAL_AS_ALLOWED_ONLY_FOR_EBGP:
531 str = "Local-AS allowed only for EBGP peers";
532 break;
533 case BGP_ERR_CANNOT_HAVE_LOCAL_AS_SAME_AS:
534 str = "Cannot have local-as same as BGP AS number";
535 break;
536 case BGP_ERR_TCPSIG_FAILED:
537 str = "Error while applying TCP-Sig to session(s)";
538 break;
539 case BGP_ERR_NO_EBGP_MULTIHOP_WITH_TTLHACK:
540 str = "ebgp-multihop and ttl-security cannot be configured together";
541 break;
542 case BGP_ERR_NO_IBGP_WITH_TTLHACK:
543 str = "ttl-security only allowed for EBGP peers";
544 break;
545 case BGP_ERR_AS_OVERRIDE:
546 str = "as-override cannot be configured for IBGP peers";
547 break;
548 case BGP_ERR_INVALID_DYNAMIC_NEIGHBORS_LIMIT:
549 str = "Invalid limit for number of dynamic neighbors";
550 break;
551 case BGP_ERR_DYNAMIC_NEIGHBORS_RANGE_EXISTS:
552 str = "Dynamic neighbor listen range already exists";
553 break;
554 case BGP_ERR_INVALID_FOR_DYNAMIC_PEER:
555 str = "Operation not allowed on a dynamic neighbor";
556 break;
557 case BGP_ERR_INVALID_FOR_DIRECT_PEER:
558 str = "Operation not allowed on a directly connected neighbor";
559 break;
560 case BGP_ERR_PEER_SAFI_CONFLICT:
561 str = "Cannot activate peer for both 'ipv4 unicast' and 'ipv4 labeled-unicast'";
562 break;
563 }
564 if (str) {
565 vty_out(vty, "%% %s\n", str);
566 return CMD_WARNING_CONFIG_FAILED;
567 }
568 return CMD_SUCCESS;
569 }
570
571 /* BGP clear sort. */
572 enum clear_sort {
573 clear_all,
574 clear_peer,
575 clear_group,
576 clear_external,
577 clear_as
578 };
579
580 static void bgp_clear_vty_error(struct vty *vty, struct peer *peer, afi_t afi,
581 safi_t safi, int error)
582 {
583 switch (error) {
584 case BGP_ERR_AF_UNCONFIGURED:
585 vty_out(vty,
586 "%%BGP: Enable %s address family for the neighbor %s\n",
587 afi_safi_print(afi, safi), peer->host);
588 break;
589 case BGP_ERR_SOFT_RECONFIG_UNCONFIGURED:
590 vty_out(vty,
591 "%%BGP: Inbound soft reconfig for %s not possible as it\n has neither refresh capability, nor inbound soft reconfig\n",
592 peer->host);
593 break;
594 default:
595 break;
596 }
597 }
598
599 /* `clear ip bgp' functions. */
600 static int bgp_clear(struct vty *vty, struct bgp *bgp, afi_t afi, safi_t safi,
601 enum clear_sort sort, enum bgp_clear_type stype,
602 const char *arg)
603 {
604 int ret;
605 bool found = false;
606 struct peer *peer;
607 struct listnode *node, *nnode;
608
609 /* Clear all neighbors. */
610 /*
611 * Pass along pointer to next node to peer_clear() when walking all
612 * nodes on the BGP instance as that may get freed if it is a
613 * doppelganger
614 */
615 if (sort == clear_all) {
616 for (ALL_LIST_ELEMENTS(bgp->peer, node, nnode, peer)) {
617 if (!peer->afc[afi][safi])
618 continue;
619
620 if (stype == BGP_CLEAR_SOFT_NONE)
621 ret = peer_clear(peer, &nnode);
622 else
623 ret = peer_clear_soft(peer, afi, safi, stype);
624
625 if (ret < 0)
626 bgp_clear_vty_error(vty, peer, afi, safi, ret);
627 }
628
629 /* This is to apply read-only mode on this clear. */
630 if (stype == BGP_CLEAR_SOFT_NONE)
631 bgp->update_delay_over = 0;
632
633 return CMD_SUCCESS;
634 }
635
636 /* Clear specified neighbor. */
637 if (sort == clear_peer) {
638 union sockunion su;
639
640 /* Make sockunion for lookup. */
641 ret = str2sockunion(arg, &su);
642 if (ret < 0) {
643 peer = peer_lookup_by_conf_if(bgp, arg);
644 if (!peer) {
645 peer = peer_lookup_by_hostname(bgp, arg);
646 if (!peer) {
647 vty_out(vty,
648 "Malformed address or name: %s\n",
649 arg);
650 return CMD_WARNING;
651 }
652 }
653 } else {
654 peer = peer_lookup(bgp, &su);
655 if (!peer) {
656 vty_out(vty,
657 "%%BGP: Unknown neighbor - \"%s\"\n",
658 arg);
659 return CMD_WARNING;
660 }
661 }
662
663 if (!peer->afc[afi][safi])
664 ret = BGP_ERR_AF_UNCONFIGURED;
665 else if (stype == BGP_CLEAR_SOFT_NONE)
666 ret = peer_clear(peer, NULL);
667 else
668 ret = peer_clear_soft(peer, afi, safi, stype);
669
670 if (ret < 0)
671 bgp_clear_vty_error(vty, peer, afi, safi, ret);
672
673 return CMD_SUCCESS;
674 }
675
676 /* Clear all neighbors belonging to a specific peer-group. */
677 if (sort == clear_group) {
678 struct peer_group *group;
679
680 group = peer_group_lookup(bgp, arg);
681 if (!group) {
682 vty_out(vty, "%%BGP: No such peer-group %s\n", arg);
683 return CMD_WARNING;
684 }
685
686 for (ALL_LIST_ELEMENTS(group->peer, node, nnode, peer)) {
687 if (!peer->afc[afi][safi])
688 continue;
689
690 if (stype == BGP_CLEAR_SOFT_NONE)
691 ret = peer_clear(peer, NULL);
692 else
693 ret = peer_clear_soft(peer, afi, safi, stype);
694
695 if (ret < 0)
696 bgp_clear_vty_error(vty, peer, afi, safi, ret);
697 else
698 found = true;
699 }
700
701 if (!found)
702 vty_out(vty,
703 "%%BGP: No %s peer belonging to peer-group %s is configured\n",
704 afi_safi_print(afi, safi), arg);
705
706 return CMD_SUCCESS;
707 }
708
709 /* Clear all external (eBGP) neighbors. */
710 if (sort == clear_external) {
711 for (ALL_LIST_ELEMENTS(bgp->peer, node, nnode, peer)) {
712 if (peer->sort == BGP_PEER_IBGP)
713 continue;
714
715 if (!peer->afc[afi][safi])
716 continue;
717
718 if (stype == BGP_CLEAR_SOFT_NONE)
719 ret = peer_clear(peer, &nnode);
720 else
721 ret = peer_clear_soft(peer, afi, safi, stype);
722
723 if (ret < 0)
724 bgp_clear_vty_error(vty, peer, afi, safi, ret);
725 else
726 found = true;
727 }
728
729 if (!found)
730 vty_out(vty,
731 "%%BGP: No external %s peer is configured\n",
732 afi_safi_print(afi, safi));
733
734 return CMD_SUCCESS;
735 }
736
737 /* Clear all neighbors belonging to a specific AS. */
738 if (sort == clear_as) {
739 as_t as = strtoul(arg, NULL, 10);
740
741 for (ALL_LIST_ELEMENTS(bgp->peer, node, nnode, peer)) {
742 if (peer->as != as)
743 continue;
744
745 if (!peer->afc[afi][safi])
746 ret = BGP_ERR_AF_UNCONFIGURED;
747 else if (stype == BGP_CLEAR_SOFT_NONE)
748 ret = peer_clear(peer, &nnode);
749 else
750 ret = peer_clear_soft(peer, afi, safi, stype);
751
752 if (ret < 0)
753 bgp_clear_vty_error(vty, peer, afi, safi, ret);
754 else
755 found = true;
756 }
757
758 if (!found)
759 vty_out(vty,
760 "%%BGP: No %s peer is configured with AS %s\n",
761 afi_safi_print(afi, safi), arg);
762
763 return CMD_SUCCESS;
764 }
765
766 return CMD_SUCCESS;
767 }
768
769 static int bgp_clear_vty(struct vty *vty, const char *name, afi_t afi,
770 safi_t safi, enum clear_sort sort,
771 enum bgp_clear_type stype, const char *arg)
772 {
773 struct bgp *bgp;
774
775 /* BGP structure lookup. */
776 if (name) {
777 bgp = bgp_lookup_by_name(name);
778 if (bgp == NULL) {
779 vty_out(vty, "Can't find BGP instance %s\n", name);
780 return CMD_WARNING;
781 }
782 } else {
783 bgp = bgp_get_default();
784 if (bgp == NULL) {
785 vty_out(vty, "No BGP process is configured\n");
786 return CMD_WARNING;
787 }
788 }
789
790 return bgp_clear(vty, bgp, afi, safi, sort, stype, arg);
791 }
792
793 /* clear soft inbound */
794 static void bgp_clear_star_soft_in(struct vty *vty, const char *name)
795 {
796 afi_t afi;
797 safi_t safi;
798
799 FOREACH_AFI_SAFI (afi, safi)
800 bgp_clear_vty(vty, name, afi, safi, clear_all,
801 BGP_CLEAR_SOFT_IN, NULL);
802 }
803
804 /* clear soft outbound */
805 static void bgp_clear_star_soft_out(struct vty *vty, const char *name)
806 {
807 afi_t afi;
808 safi_t safi;
809
810 FOREACH_AFI_SAFI (afi, safi)
811 bgp_clear_vty(vty, name, afi, safi, clear_all,
812 BGP_CLEAR_SOFT_OUT, NULL);
813 }
814
815
816 #ifndef VTYSH_EXTRACT_PL
817 #include "bgpd/bgp_vty_clippy.c"
818 #endif
819
820 DEFUN_HIDDEN (bgp_local_mac,
821 bgp_local_mac_cmd,
822 "bgp local-mac vni " CMD_VNI_RANGE " mac WORD seq (0-4294967295)",
823 BGP_STR
824 "Local MAC config\n"
825 "VxLAN Network Identifier\n"
826 "VNI number\n"
827 "local mac\n"
828 "mac address\n"
829 "mac-mobility sequence\n"
830 "seq number\n")
831 {
832 int rv;
833 vni_t vni;
834 struct ethaddr mac;
835 struct ipaddr ip;
836 uint32_t seq;
837 struct bgp *bgp;
838
839 vni = strtoul(argv[3]->arg, NULL, 10);
840 if (!prefix_str2mac(argv[5]->arg, &mac)) {
841 vty_out(vty, "%% Malformed MAC address\n");
842 return CMD_WARNING;
843 }
844 memset(&ip, 0, sizeof(ip));
845 seq = strtoul(argv[7]->arg, NULL, 10);
846
847 bgp = bgp_get_default();
848 if (!bgp) {
849 vty_out(vty, "Default BGP instance is not there\n");
850 return CMD_WARNING;
851 }
852
853 rv = bgp_evpn_local_macip_add(bgp, vni, &mac, &ip, 0 /* flags */, seq);
854 if (rv < 0) {
855 vty_out(vty, "Internal error\n");
856 return CMD_WARNING;
857 }
858
859 return CMD_SUCCESS;
860 }
861
862 DEFUN_HIDDEN (no_bgp_local_mac,
863 no_bgp_local_mac_cmd,
864 "no bgp local-mac vni " CMD_VNI_RANGE " mac WORD",
865 NO_STR
866 BGP_STR
867 "Local MAC config\n"
868 "VxLAN Network Identifier\n"
869 "VNI number\n"
870 "local mac\n"
871 "mac address\n")
872 {
873 int rv;
874 vni_t vni;
875 struct ethaddr mac;
876 struct ipaddr ip;
877 struct bgp *bgp;
878
879 vni = strtoul(argv[4]->arg, NULL, 10);
880 if (!prefix_str2mac(argv[6]->arg, &mac)) {
881 vty_out(vty, "%% Malformed MAC address\n");
882 return CMD_WARNING;
883 }
884 memset(&ip, 0, sizeof(ip));
885
886 bgp = bgp_get_default();
887 if (!bgp) {
888 vty_out(vty, "Default BGP instance is not there\n");
889 return CMD_WARNING;
890 }
891
892 rv = bgp_evpn_local_macip_del(bgp, vni, &mac, &ip, ZEBRA_NEIGH_ACTIVE);
893 if (rv < 0) {
894 vty_out(vty, "Internal error\n");
895 return CMD_WARNING;
896 }
897
898 return CMD_SUCCESS;
899 }
900
901 DEFUN (no_synchronization,
902 no_synchronization_cmd,
903 "no synchronization",
904 NO_STR
905 "Perform IGP synchronization\n")
906 {
907 return CMD_SUCCESS;
908 }
909
910 DEFUN (no_auto_summary,
911 no_auto_summary_cmd,
912 "no auto-summary",
913 NO_STR
914 "Enable automatic network number summarization\n")
915 {
916 return CMD_SUCCESS;
917 }
918
919 /* "router bgp" commands. */
920 DEFUN_NOSH (router_bgp,
921 router_bgp_cmd,
922 "router bgp [(1-4294967295)$instasn [<view|vrf> VIEWVRFNAME]]",
923 ROUTER_STR
924 BGP_STR
925 AS_STR
926 BGP_INSTANCE_HELP_STR)
927 {
928 int idx_asn = 2;
929 int idx_view_vrf = 3;
930 int idx_vrf = 4;
931 int is_new_bgp = 0;
932 int ret;
933 as_t as;
934 struct bgp *bgp;
935 const char *name = NULL;
936 enum bgp_instance_type inst_type;
937
938 // "router bgp" without an ASN
939 if (argc == 2) {
940 // Pending: Make VRF option available for ASN less config
941 bgp = bgp_get_default();
942
943 if (bgp == NULL) {
944 vty_out(vty, "%% No BGP process is configured\n");
945 return CMD_WARNING_CONFIG_FAILED;
946 }
947
948 if (listcount(bm->bgp) > 1) {
949 vty_out(vty, "%% Please specify ASN and VRF\n");
950 return CMD_WARNING_CONFIG_FAILED;
951 }
952 }
953
954 // "router bgp X"
955 else {
956 as = strtoul(argv[idx_asn]->arg, NULL, 10);
957
958 inst_type = BGP_INSTANCE_TYPE_DEFAULT;
959 if (argc > 3) {
960 name = argv[idx_vrf]->arg;
961
962 if (!strcmp(argv[idx_view_vrf]->text, "vrf")) {
963 if (strmatch(name, VRF_DEFAULT_NAME))
964 name = NULL;
965 else
966 inst_type = BGP_INSTANCE_TYPE_VRF;
967 } else if (!strcmp(argv[idx_view_vrf]->text, "view"))
968 inst_type = BGP_INSTANCE_TYPE_VIEW;
969 }
970
971 if (inst_type == BGP_INSTANCE_TYPE_DEFAULT)
972 is_new_bgp = (bgp_lookup(as, name) == NULL);
973
974 ret = bgp_get(&bgp, &as, name, inst_type);
975 switch (ret) {
976 case BGP_ERR_AS_MISMATCH:
977 vty_out(vty, "BGP is already running; AS is %u\n", as);
978 return CMD_WARNING_CONFIG_FAILED;
979 case BGP_ERR_INSTANCE_MISMATCH:
980 vty_out(vty,
981 "BGP instance name and AS number mismatch\n");
982 vty_out(vty,
983 "BGP instance is already running; AS is %u\n",
984 as);
985 return CMD_WARNING_CONFIG_FAILED;
986 }
987
988 /*
989 * If we just instantiated the default instance, complete
990 * any pending VRF-VPN leaking that was configured via
991 * earlier "router bgp X vrf FOO" blocks.
992 */
993 if (is_new_bgp && inst_type == BGP_INSTANCE_TYPE_DEFAULT)
994 vpn_leak_postchange_all();
995
996 if (inst_type == BGP_INSTANCE_TYPE_VRF)
997 bgp_vpn_leak_export(bgp);
998 /* Pending: handle when user tries to change a view to vrf n vv.
999 */
1000 }
1001
1002 /* unset the auto created flag as the user config is now present */
1003 UNSET_FLAG(bgp->vrf_flags, BGP_VRF_AUTO);
1004 VTY_PUSH_CONTEXT(BGP_NODE, bgp);
1005
1006 return CMD_SUCCESS;
1007 }
1008
1009 /* "no router bgp" commands. */
1010 DEFUN (no_router_bgp,
1011 no_router_bgp_cmd,
1012 "no router bgp [(1-4294967295)$instasn [<view|vrf> VIEWVRFNAME]]",
1013 NO_STR
1014 ROUTER_STR
1015 BGP_STR
1016 AS_STR
1017 BGP_INSTANCE_HELP_STR)
1018 {
1019 int idx_asn = 3;
1020 int idx_vrf = 5;
1021 as_t as;
1022 struct bgp *bgp;
1023 const char *name = NULL;
1024
1025 // "no router bgp" without an ASN
1026 if (argc == 3) {
1027 // Pending: Make VRF option available for ASN less config
1028 bgp = bgp_get_default();
1029
1030 if (bgp == NULL) {
1031 vty_out(vty, "%% No BGP process is configured\n");
1032 return CMD_WARNING_CONFIG_FAILED;
1033 }
1034
1035 if (listcount(bm->bgp) > 1) {
1036 vty_out(vty, "%% Please specify ASN and VRF\n");
1037 return CMD_WARNING_CONFIG_FAILED;
1038 }
1039
1040 if (bgp->l3vni) {
1041 vty_out(vty, "%% Please unconfigure l3vni %u",
1042 bgp->l3vni);
1043 return CMD_WARNING_CONFIG_FAILED;
1044 }
1045 } else {
1046 as = strtoul(argv[idx_asn]->arg, NULL, 10);
1047
1048 if (argc > 4)
1049 name = argv[idx_vrf]->arg;
1050
1051 /* Lookup bgp structure. */
1052 bgp = bgp_lookup(as, name);
1053 if (!bgp) {
1054 vty_out(vty, "%% Can't find BGP instance\n");
1055 return CMD_WARNING_CONFIG_FAILED;
1056 }
1057
1058 if (bgp->l3vni) {
1059 vty_out(vty, "%% Please unconfigure l3vni %u\n",
1060 bgp->l3vni);
1061 return CMD_WARNING_CONFIG_FAILED;
1062 }
1063
1064 /* Cannot delete default instance if vrf instances exist */
1065 if (bgp->inst_type == BGP_INSTANCE_TYPE_DEFAULT) {
1066 struct listnode *node;
1067 struct bgp *tmp_bgp;
1068
1069 for (ALL_LIST_ELEMENTS_RO(bm->bgp, node, tmp_bgp)) {
1070 if (tmp_bgp->inst_type
1071 == BGP_INSTANCE_TYPE_VRF) {
1072 vty_out(vty,
1073 "%% Cannot delete default BGP instance. Dependent VRF instances exist\n");
1074 return CMD_WARNING_CONFIG_FAILED;
1075 }
1076 }
1077 }
1078 }
1079
1080 if (bgp_vpn_leak_unimport(bgp, vty))
1081 return CMD_WARNING_CONFIG_FAILED;
1082
1083 bgp_delete(bgp);
1084
1085 return CMD_SUCCESS;
1086 }
1087
1088
1089 /* BGP router-id. */
1090
1091 DEFPY (bgp_router_id,
1092 bgp_router_id_cmd,
1093 "bgp router-id A.B.C.D",
1094 BGP_STR
1095 "Override configured router identifier\n"
1096 "Manually configured router identifier\n")
1097 {
1098 VTY_DECLVAR_CONTEXT(bgp, bgp);
1099 bgp_router_id_static_set(bgp, router_id);
1100 return CMD_SUCCESS;
1101 }
1102
1103 DEFPY (no_bgp_router_id,
1104 no_bgp_router_id_cmd,
1105 "no bgp router-id [A.B.C.D]",
1106 NO_STR
1107 BGP_STR
1108 "Override configured router identifier\n"
1109 "Manually configured router identifier\n")
1110 {
1111 VTY_DECLVAR_CONTEXT(bgp, bgp);
1112
1113 if (router_id_str) {
1114 if (!IPV4_ADDR_SAME(&bgp->router_id_static, &router_id)) {
1115 vty_out(vty, "%% BGP router-id doesn't match\n");
1116 return CMD_WARNING_CONFIG_FAILED;
1117 }
1118 }
1119
1120 router_id.s_addr = 0;
1121 bgp_router_id_static_set(bgp, router_id);
1122
1123 return CMD_SUCCESS;
1124 }
1125
1126
1127 /* BGP Cluster ID. */
1128 DEFUN (bgp_cluster_id,
1129 bgp_cluster_id_cmd,
1130 "bgp cluster-id <A.B.C.D|(1-4294967295)>",
1131 BGP_STR
1132 "Configure Route-Reflector Cluster-id\n"
1133 "Route-Reflector Cluster-id in IP address format\n"
1134 "Route-Reflector Cluster-id as 32 bit quantity\n")
1135 {
1136 VTY_DECLVAR_CONTEXT(bgp, bgp);
1137 int idx_ipv4 = 2;
1138 int ret;
1139 struct in_addr cluster;
1140
1141 ret = inet_aton(argv[idx_ipv4]->arg, &cluster);
1142 if (!ret) {
1143 vty_out(vty, "%% Malformed bgp cluster identifier\n");
1144 return CMD_WARNING_CONFIG_FAILED;
1145 }
1146
1147 bgp_cluster_id_set(bgp, &cluster);
1148 bgp_clear_star_soft_out(vty, bgp->name);
1149
1150 return CMD_SUCCESS;
1151 }
1152
1153 DEFUN (no_bgp_cluster_id,
1154 no_bgp_cluster_id_cmd,
1155 "no bgp cluster-id [<A.B.C.D|(1-4294967295)>]",
1156 NO_STR
1157 BGP_STR
1158 "Configure Route-Reflector Cluster-id\n"
1159 "Route-Reflector Cluster-id in IP address format\n"
1160 "Route-Reflector Cluster-id as 32 bit quantity\n")
1161 {
1162 VTY_DECLVAR_CONTEXT(bgp, bgp);
1163 bgp_cluster_id_unset(bgp);
1164 bgp_clear_star_soft_out(vty, bgp->name);
1165
1166 return CMD_SUCCESS;
1167 }
1168
1169 DEFUN (bgp_confederation_identifier,
1170 bgp_confederation_identifier_cmd,
1171 "bgp confederation identifier (1-4294967295)",
1172 "BGP specific commands\n"
1173 "AS confederation parameters\n"
1174 "AS number\n"
1175 "Set routing domain confederation AS\n")
1176 {
1177 VTY_DECLVAR_CONTEXT(bgp, bgp);
1178 int idx_number = 3;
1179 as_t as;
1180
1181 as = strtoul(argv[idx_number]->arg, NULL, 10);
1182
1183 bgp_confederation_id_set(bgp, as);
1184
1185 return CMD_SUCCESS;
1186 }
1187
1188 DEFUN (no_bgp_confederation_identifier,
1189 no_bgp_confederation_identifier_cmd,
1190 "no bgp confederation identifier [(1-4294967295)]",
1191 NO_STR
1192 "BGP specific commands\n"
1193 "AS confederation parameters\n"
1194 "AS number\n"
1195 "Set routing domain confederation AS\n")
1196 {
1197 VTY_DECLVAR_CONTEXT(bgp, bgp);
1198 bgp_confederation_id_unset(bgp);
1199
1200 return CMD_SUCCESS;
1201 }
1202
1203 DEFUN (bgp_confederation_peers,
1204 bgp_confederation_peers_cmd,
1205 "bgp confederation peers (1-4294967295)...",
1206 "BGP specific commands\n"
1207 "AS confederation parameters\n"
1208 "Peer ASs in BGP confederation\n"
1209 AS_STR)
1210 {
1211 VTY_DECLVAR_CONTEXT(bgp, bgp);
1212 int idx_asn = 3;
1213 as_t as;
1214 int i;
1215
1216 for (i = idx_asn; i < argc; i++) {
1217 as = strtoul(argv[i]->arg, NULL, 10);
1218
1219 if (bgp->as == as) {
1220 vty_out(vty,
1221 "%% Local member-AS not allowed in confed peer list\n");
1222 continue;
1223 }
1224
1225 bgp_confederation_peers_add(bgp, as);
1226 }
1227 return CMD_SUCCESS;
1228 }
1229
1230 DEFUN (no_bgp_confederation_peers,
1231 no_bgp_confederation_peers_cmd,
1232 "no bgp confederation peers (1-4294967295)...",
1233 NO_STR
1234 "BGP specific commands\n"
1235 "AS confederation parameters\n"
1236 "Peer ASs in BGP confederation\n"
1237 AS_STR)
1238 {
1239 VTY_DECLVAR_CONTEXT(bgp, bgp);
1240 int idx_asn = 4;
1241 as_t as;
1242 int i;
1243
1244 for (i = idx_asn; i < argc; i++) {
1245 as = strtoul(argv[i]->arg, NULL, 10);
1246
1247 bgp_confederation_peers_remove(bgp, as);
1248 }
1249 return CMD_SUCCESS;
1250 }
1251
1252 /**
1253 * Central routine for maximum-paths configuration.
1254 * @peer_type: BGP_PEER_EBGP or BGP_PEER_IBGP
1255 * @set: 1 for setting values, 0 for removing the max-paths config.
1256 */
1257 static int bgp_maxpaths_config_vty(struct vty *vty, int peer_type,
1258 const char *mpaths, uint16_t options,
1259 int set)
1260 {
1261 VTY_DECLVAR_CONTEXT(bgp, bgp);
1262 uint16_t maxpaths = 0;
1263 int ret;
1264 afi_t afi;
1265 safi_t safi;
1266
1267 afi = bgp_node_afi(vty);
1268 safi = bgp_node_safi(vty);
1269
1270 if (set) {
1271 maxpaths = strtol(mpaths, NULL, 10);
1272 if (maxpaths > multipath_num) {
1273 vty_out(vty,
1274 "%% Maxpaths Specified: %d is > than multipath num specified on bgp command line %d",
1275 maxpaths, multipath_num);
1276 return CMD_WARNING_CONFIG_FAILED;
1277 }
1278 ret = bgp_maximum_paths_set(bgp, afi, safi, peer_type, maxpaths,
1279 options);
1280 } else
1281 ret = bgp_maximum_paths_unset(bgp, afi, safi, peer_type);
1282
1283 if (ret < 0) {
1284 vty_out(vty,
1285 "%% Failed to %sset maximum-paths %s %u for afi %u, safi %u\n",
1286 (set == 1) ? "" : "un",
1287 (peer_type == BGP_PEER_EBGP) ? "ebgp" : "ibgp",
1288 maxpaths, afi, safi);
1289 return CMD_WARNING_CONFIG_FAILED;
1290 }
1291
1292 bgp_recalculate_all_bestpaths(bgp);
1293
1294 return CMD_SUCCESS;
1295 }
1296
1297 DEFUN (bgp_maxmed_admin,
1298 bgp_maxmed_admin_cmd,
1299 "bgp max-med administrative ",
1300 BGP_STR
1301 "Advertise routes with max-med\n"
1302 "Administratively applied, for an indefinite period\n")
1303 {
1304 VTY_DECLVAR_CONTEXT(bgp, bgp);
1305
1306 bgp->v_maxmed_admin = 1;
1307 bgp->maxmed_admin_value = BGP_MAXMED_VALUE_DEFAULT;
1308
1309 bgp_maxmed_update(bgp);
1310
1311 return CMD_SUCCESS;
1312 }
1313
1314 DEFUN (bgp_maxmed_admin_medv,
1315 bgp_maxmed_admin_medv_cmd,
1316 "bgp max-med administrative (0-4294967295)",
1317 BGP_STR
1318 "Advertise routes with max-med\n"
1319 "Administratively applied, for an indefinite period\n"
1320 "Max MED value to be used\n")
1321 {
1322 VTY_DECLVAR_CONTEXT(bgp, bgp);
1323 int idx_number = 3;
1324
1325 bgp->v_maxmed_admin = 1;
1326 bgp->maxmed_admin_value = strtoul(argv[idx_number]->arg, NULL, 10);
1327
1328 bgp_maxmed_update(bgp);
1329
1330 return CMD_SUCCESS;
1331 }
1332
1333 DEFUN (no_bgp_maxmed_admin,
1334 no_bgp_maxmed_admin_cmd,
1335 "no bgp max-med administrative [(0-4294967295)]",
1336 NO_STR
1337 BGP_STR
1338 "Advertise routes with max-med\n"
1339 "Administratively applied, for an indefinite period\n"
1340 "Max MED value to be used\n")
1341 {
1342 VTY_DECLVAR_CONTEXT(bgp, bgp);
1343 bgp->v_maxmed_admin = BGP_MAXMED_ADMIN_UNCONFIGURED;
1344 bgp->maxmed_admin_value = BGP_MAXMED_VALUE_DEFAULT;
1345 bgp_maxmed_update(bgp);
1346
1347 return CMD_SUCCESS;
1348 }
1349
1350 DEFUN (bgp_maxmed_onstartup,
1351 bgp_maxmed_onstartup_cmd,
1352 "bgp max-med on-startup (5-86400) [(0-4294967295)]",
1353 BGP_STR
1354 "Advertise routes with max-med\n"
1355 "Effective on a startup\n"
1356 "Time (seconds) period for max-med\n"
1357 "Max MED value to be used\n")
1358 {
1359 VTY_DECLVAR_CONTEXT(bgp, bgp);
1360 int idx = 0;
1361
1362 argv_find(argv, argc, "(5-86400)", &idx);
1363 bgp->v_maxmed_onstartup = strtoul(argv[idx]->arg, NULL, 10);
1364 if (argv_find(argv, argc, "(0-4294967295)", &idx))
1365 bgp->maxmed_onstartup_value = strtoul(argv[idx]->arg, NULL, 10);
1366 else
1367 bgp->maxmed_onstartup_value = BGP_MAXMED_VALUE_DEFAULT;
1368
1369 bgp_maxmed_update(bgp);
1370
1371 return CMD_SUCCESS;
1372 }
1373
1374 DEFUN (no_bgp_maxmed_onstartup,
1375 no_bgp_maxmed_onstartup_cmd,
1376 "no bgp max-med on-startup [(5-86400) [(0-4294967295)]]",
1377 NO_STR
1378 BGP_STR
1379 "Advertise routes with max-med\n"
1380 "Effective on a startup\n"
1381 "Time (seconds) period for max-med\n"
1382 "Max MED value to be used\n")
1383 {
1384 VTY_DECLVAR_CONTEXT(bgp, bgp);
1385
1386 /* Cancel max-med onstartup if its on */
1387 if (bgp->t_maxmed_onstartup) {
1388 THREAD_TIMER_OFF(bgp->t_maxmed_onstartup);
1389 bgp->maxmed_onstartup_over = 1;
1390 }
1391
1392 bgp->v_maxmed_onstartup = BGP_MAXMED_ONSTARTUP_UNCONFIGURED;
1393 bgp->maxmed_onstartup_value = BGP_MAXMED_VALUE_DEFAULT;
1394
1395 bgp_maxmed_update(bgp);
1396
1397 return CMD_SUCCESS;
1398 }
1399
1400 static int bgp_update_delay_config_vty(struct vty *vty, const char *delay,
1401 const char *wait)
1402 {
1403 VTY_DECLVAR_CONTEXT(bgp, bgp);
1404 uint16_t update_delay;
1405 uint16_t establish_wait;
1406
1407 update_delay = strtoul(delay, NULL, 10);
1408
1409 if (!wait) /* update-delay <delay> */
1410 {
1411 bgp->v_update_delay = update_delay;
1412 bgp->v_establish_wait = bgp->v_update_delay;
1413 return CMD_SUCCESS;
1414 }
1415
1416 /* update-delay <delay> <establish-wait> */
1417 establish_wait = atoi(wait);
1418 if (update_delay < establish_wait) {
1419 vty_out(vty,
1420 "%%Failed: update-delay less than the establish-wait!\n");
1421 return CMD_WARNING_CONFIG_FAILED;
1422 }
1423
1424 bgp->v_update_delay = update_delay;
1425 bgp->v_establish_wait = establish_wait;
1426
1427 return CMD_SUCCESS;
1428 }
1429
1430 static int bgp_update_delay_deconfig_vty(struct vty *vty)
1431 {
1432 VTY_DECLVAR_CONTEXT(bgp, bgp);
1433
1434 bgp->v_update_delay = BGP_UPDATE_DELAY_DEF;
1435 bgp->v_establish_wait = bgp->v_update_delay;
1436
1437 return CMD_SUCCESS;
1438 }
1439
1440 void bgp_config_write_update_delay(struct vty *vty, struct bgp *bgp)
1441 {
1442 if (bgp->v_update_delay != BGP_UPDATE_DELAY_DEF) {
1443 vty_out(vty, " update-delay %d", bgp->v_update_delay);
1444 if (bgp->v_update_delay != bgp->v_establish_wait)
1445 vty_out(vty, " %d", bgp->v_establish_wait);
1446 vty_out(vty, "\n");
1447 }
1448 }
1449
1450
1451 /* Update-delay configuration */
1452 DEFUN (bgp_update_delay,
1453 bgp_update_delay_cmd,
1454 "update-delay (0-3600)",
1455 "Force initial delay for best-path and updates\n"
1456 "Seconds\n")
1457 {
1458 int idx_number = 1;
1459 return bgp_update_delay_config_vty(vty, argv[idx_number]->arg, NULL);
1460 }
1461
1462 DEFUN (bgp_update_delay_establish_wait,
1463 bgp_update_delay_establish_wait_cmd,
1464 "update-delay (0-3600) (1-3600)",
1465 "Force initial delay for best-path and updates\n"
1466 "Seconds\n"
1467 "Seconds\n")
1468 {
1469 int idx_number = 1;
1470 int idx_number_2 = 2;
1471 return bgp_update_delay_config_vty(vty, argv[idx_number]->arg,
1472 argv[idx_number_2]->arg);
1473 }
1474
1475 /* Update-delay deconfiguration */
1476 DEFUN (no_bgp_update_delay,
1477 no_bgp_update_delay_cmd,
1478 "no update-delay [(0-3600) [(1-3600)]]",
1479 NO_STR
1480 "Force initial delay for best-path and updates\n"
1481 "Seconds\n"
1482 "Seconds\n")
1483 {
1484 return bgp_update_delay_deconfig_vty(vty);
1485 }
1486
1487
1488 static int bgp_wpkt_quanta_config_vty(struct vty *vty, const char *num,
1489 char set)
1490 {
1491 VTY_DECLVAR_CONTEXT(bgp, bgp);
1492
1493 if (set) {
1494 uint32_t quanta = strtoul(num, NULL, 10);
1495 atomic_store_explicit(&bgp->wpkt_quanta, quanta,
1496 memory_order_relaxed);
1497 } else {
1498 atomic_store_explicit(&bgp->wpkt_quanta, BGP_WRITE_PACKET_MAX,
1499 memory_order_relaxed);
1500 }
1501
1502 return CMD_SUCCESS;
1503 }
1504
1505 static int bgp_rpkt_quanta_config_vty(struct vty *vty, const char *num,
1506 char set)
1507 {
1508 VTY_DECLVAR_CONTEXT(bgp, bgp);
1509
1510 if (set) {
1511 uint32_t quanta = strtoul(num, NULL, 10);
1512 atomic_store_explicit(&bgp->rpkt_quanta, quanta,
1513 memory_order_relaxed);
1514 } else {
1515 atomic_store_explicit(&bgp->rpkt_quanta, BGP_READ_PACKET_MAX,
1516 memory_order_relaxed);
1517 }
1518
1519 return CMD_SUCCESS;
1520 }
1521
1522 void bgp_config_write_wpkt_quanta(struct vty *vty, struct bgp *bgp)
1523 {
1524 uint32_t quanta =
1525 atomic_load_explicit(&bgp->wpkt_quanta, memory_order_relaxed);
1526 if (quanta != BGP_WRITE_PACKET_MAX)
1527 vty_out(vty, " write-quanta %d\n", quanta);
1528 }
1529
1530 void bgp_config_write_rpkt_quanta(struct vty *vty, struct bgp *bgp)
1531 {
1532 uint32_t quanta =
1533 atomic_load_explicit(&bgp->rpkt_quanta, memory_order_relaxed);
1534 if (quanta != BGP_READ_PACKET_MAX)
1535 vty_out(vty, " read-quanta %d\n", quanta);
1536 }
1537
1538 /* Packet quanta configuration */
1539 DEFUN (bgp_wpkt_quanta,
1540 bgp_wpkt_quanta_cmd,
1541 "write-quanta (1-10)",
1542 "How many packets to write to peer socket per run\n"
1543 "Number of packets\n")
1544 {
1545 int idx_number = 1;
1546 return bgp_wpkt_quanta_config_vty(vty, argv[idx_number]->arg, 1);
1547 }
1548
1549 DEFUN (no_bgp_wpkt_quanta,
1550 no_bgp_wpkt_quanta_cmd,
1551 "no write-quanta (1-10)",
1552 NO_STR
1553 "How many packets to write to peer socket per I/O cycle\n"
1554 "Number of packets\n")
1555 {
1556 int idx_number = 2;
1557 return bgp_wpkt_quanta_config_vty(vty, argv[idx_number]->arg, 0);
1558 }
1559
1560 DEFUN (bgp_rpkt_quanta,
1561 bgp_rpkt_quanta_cmd,
1562 "read-quanta (1-10)",
1563 "How many packets to read from peer socket per I/O cycle\n"
1564 "Number of packets\n")
1565 {
1566 int idx_number = 1;
1567 return bgp_rpkt_quanta_config_vty(vty, argv[idx_number]->arg, 1);
1568 }
1569
1570 DEFUN (no_bgp_rpkt_quanta,
1571 no_bgp_rpkt_quanta_cmd,
1572 "no read-quanta (1-10)",
1573 NO_STR
1574 "How many packets to read from peer socket per I/O cycle\n"
1575 "Number of packets\n")
1576 {
1577 int idx_number = 2;
1578 return bgp_rpkt_quanta_config_vty(vty, argv[idx_number]->arg, 0);
1579 }
1580
1581 void bgp_config_write_coalesce_time(struct vty *vty, struct bgp *bgp)
1582 {
1583 if (!bgp->heuristic_coalesce)
1584 vty_out(vty, " coalesce-time %u\n", bgp->coalesce_time);
1585 }
1586
1587
1588 DEFUN (bgp_coalesce_time,
1589 bgp_coalesce_time_cmd,
1590 "coalesce-time (0-4294967295)",
1591 "Subgroup coalesce timer\n"
1592 "Subgroup coalesce timer value (in ms)\n")
1593 {
1594 VTY_DECLVAR_CONTEXT(bgp, bgp);
1595
1596 int idx = 0;
1597 argv_find(argv, argc, "(0-4294967295)", &idx);
1598 bgp->heuristic_coalesce = false;
1599 bgp->coalesce_time = strtoul(argv[idx]->arg, NULL, 10);
1600 return CMD_SUCCESS;
1601 }
1602
1603 DEFUN (no_bgp_coalesce_time,
1604 no_bgp_coalesce_time_cmd,
1605 "no coalesce-time (0-4294967295)",
1606 NO_STR
1607 "Subgroup coalesce timer\n"
1608 "Subgroup coalesce timer value (in ms)\n")
1609 {
1610 VTY_DECLVAR_CONTEXT(bgp, bgp);
1611
1612 bgp->heuristic_coalesce = true;
1613 bgp->coalesce_time = BGP_DEFAULT_SUBGROUP_COALESCE_TIME;
1614 return CMD_SUCCESS;
1615 }
1616
1617 /* Maximum-paths configuration */
1618 DEFUN (bgp_maxpaths,
1619 bgp_maxpaths_cmd,
1620 "maximum-paths " CMD_RANGE_STR(1, MULTIPATH_NUM),
1621 "Forward packets over multiple paths\n"
1622 "Number of paths\n")
1623 {
1624 int idx_number = 1;
1625 return bgp_maxpaths_config_vty(vty, BGP_PEER_EBGP,
1626 argv[idx_number]->arg, 0, 1);
1627 }
1628
1629 ALIAS_HIDDEN(bgp_maxpaths, bgp_maxpaths_hidden_cmd,
1630 "maximum-paths " CMD_RANGE_STR(1, MULTIPATH_NUM),
1631 "Forward packets over multiple paths\n"
1632 "Number of paths\n")
1633
1634 DEFUN (bgp_maxpaths_ibgp,
1635 bgp_maxpaths_ibgp_cmd,
1636 "maximum-paths ibgp " CMD_RANGE_STR(1, MULTIPATH_NUM),
1637 "Forward packets over multiple paths\n"
1638 "iBGP-multipath\n"
1639 "Number of paths\n")
1640 {
1641 int idx_number = 2;
1642 return bgp_maxpaths_config_vty(vty, BGP_PEER_IBGP,
1643 argv[idx_number]->arg, 0, 1);
1644 }
1645
1646 ALIAS_HIDDEN(bgp_maxpaths_ibgp, bgp_maxpaths_ibgp_hidden_cmd,
1647 "maximum-paths ibgp " CMD_RANGE_STR(1, MULTIPATH_NUM),
1648 "Forward packets over multiple paths\n"
1649 "iBGP-multipath\n"
1650 "Number of paths\n")
1651
1652 DEFUN (bgp_maxpaths_ibgp_cluster,
1653 bgp_maxpaths_ibgp_cluster_cmd,
1654 "maximum-paths ibgp " CMD_RANGE_STR(1, MULTIPATH_NUM) " equal-cluster-length",
1655 "Forward packets over multiple paths\n"
1656 "iBGP-multipath\n"
1657 "Number of paths\n"
1658 "Match the cluster length\n")
1659 {
1660 int idx_number = 2;
1661 return bgp_maxpaths_config_vty(
1662 vty, BGP_PEER_IBGP, argv[idx_number]->arg,
1663 BGP_FLAG_IBGP_MULTIPATH_SAME_CLUSTERLEN, 1);
1664 }
1665
1666 ALIAS_HIDDEN(bgp_maxpaths_ibgp_cluster, bgp_maxpaths_ibgp_cluster_hidden_cmd,
1667 "maximum-paths ibgp " CMD_RANGE_STR(
1668 1, MULTIPATH_NUM) " equal-cluster-length",
1669 "Forward packets over multiple paths\n"
1670 "iBGP-multipath\n"
1671 "Number of paths\n"
1672 "Match the cluster length\n")
1673
1674 DEFUN (no_bgp_maxpaths,
1675 no_bgp_maxpaths_cmd,
1676 "no maximum-paths [" CMD_RANGE_STR(1, MULTIPATH_NUM) "]",
1677 NO_STR
1678 "Forward packets over multiple paths\n"
1679 "Number of paths\n")
1680 {
1681 return bgp_maxpaths_config_vty(vty, BGP_PEER_EBGP, NULL, 0, 0);
1682 }
1683
1684 ALIAS_HIDDEN(no_bgp_maxpaths, no_bgp_maxpaths_hidden_cmd,
1685 "no maximum-paths [" CMD_RANGE_STR(1, MULTIPATH_NUM) "]", NO_STR
1686 "Forward packets over multiple paths\n"
1687 "Number of paths\n")
1688
1689 DEFUN (no_bgp_maxpaths_ibgp,
1690 no_bgp_maxpaths_ibgp_cmd,
1691 "no maximum-paths ibgp [" CMD_RANGE_STR(1, MULTIPATH_NUM) " [equal-cluster-length]]",
1692 NO_STR
1693 "Forward packets over multiple paths\n"
1694 "iBGP-multipath\n"
1695 "Number of paths\n"
1696 "Match the cluster length\n")
1697 {
1698 return bgp_maxpaths_config_vty(vty, BGP_PEER_IBGP, NULL, 0, 0);
1699 }
1700
1701 ALIAS_HIDDEN(no_bgp_maxpaths_ibgp, no_bgp_maxpaths_ibgp_hidden_cmd,
1702 "no maximum-paths ibgp [" CMD_RANGE_STR(
1703 1, MULTIPATH_NUM) " [equal-cluster-length]]",
1704 NO_STR
1705 "Forward packets over multiple paths\n"
1706 "iBGP-multipath\n"
1707 "Number of paths\n"
1708 "Match the cluster length\n")
1709
1710 void bgp_config_write_maxpaths(struct vty *vty, struct bgp *bgp, afi_t afi,
1711 safi_t safi)
1712 {
1713 if (bgp->maxpaths[afi][safi].maxpaths_ebgp != MULTIPATH_NUM) {
1714 vty_out(vty, " maximum-paths %d\n",
1715 bgp->maxpaths[afi][safi].maxpaths_ebgp);
1716 }
1717
1718 if (bgp->maxpaths[afi][safi].maxpaths_ibgp != MULTIPATH_NUM) {
1719 vty_out(vty, " maximum-paths ibgp %d",
1720 bgp->maxpaths[afi][safi].maxpaths_ibgp);
1721 if (CHECK_FLAG(bgp->maxpaths[afi][safi].ibgp_flags,
1722 BGP_FLAG_IBGP_MULTIPATH_SAME_CLUSTERLEN))
1723 vty_out(vty, " equal-cluster-length");
1724 vty_out(vty, "\n");
1725 }
1726 }
1727
1728 /* BGP timers. */
1729
1730 DEFUN (bgp_timers,
1731 bgp_timers_cmd,
1732 "timers bgp (0-65535) (0-65535)",
1733 "Adjust routing timers\n"
1734 "BGP timers\n"
1735 "Keepalive interval\n"
1736 "Holdtime\n")
1737 {
1738 VTY_DECLVAR_CONTEXT(bgp, bgp);
1739 int idx_number = 2;
1740 int idx_number_2 = 3;
1741 unsigned long keepalive = 0;
1742 unsigned long holdtime = 0;
1743
1744 keepalive = strtoul(argv[idx_number]->arg, NULL, 10);
1745 holdtime = strtoul(argv[idx_number_2]->arg, NULL, 10);
1746
1747 /* Holdtime value check. */
1748 if (holdtime < 3 && holdtime != 0) {
1749 vty_out(vty,
1750 "%% hold time value must be either 0 or greater than 3\n");
1751 return CMD_WARNING_CONFIG_FAILED;
1752 }
1753
1754 bgp_timers_set(bgp, keepalive, holdtime);
1755
1756 return CMD_SUCCESS;
1757 }
1758
1759 DEFUN (no_bgp_timers,
1760 no_bgp_timers_cmd,
1761 "no timers bgp [(0-65535) (0-65535)]",
1762 NO_STR
1763 "Adjust routing timers\n"
1764 "BGP timers\n"
1765 "Keepalive interval\n"
1766 "Holdtime\n")
1767 {
1768 VTY_DECLVAR_CONTEXT(bgp, bgp);
1769 bgp_timers_unset(bgp);
1770
1771 return CMD_SUCCESS;
1772 }
1773
1774
1775 DEFUN (bgp_client_to_client_reflection,
1776 bgp_client_to_client_reflection_cmd,
1777 "bgp client-to-client reflection",
1778 "BGP specific commands\n"
1779 "Configure client to client route reflection\n"
1780 "reflection of routes allowed\n")
1781 {
1782 VTY_DECLVAR_CONTEXT(bgp, bgp);
1783 bgp_flag_unset(bgp, BGP_FLAG_NO_CLIENT_TO_CLIENT);
1784 bgp_clear_star_soft_out(vty, bgp->name);
1785
1786 return CMD_SUCCESS;
1787 }
1788
1789 DEFUN (no_bgp_client_to_client_reflection,
1790 no_bgp_client_to_client_reflection_cmd,
1791 "no bgp client-to-client reflection",
1792 NO_STR
1793 "BGP specific commands\n"
1794 "Configure client to client route reflection\n"
1795 "reflection of routes allowed\n")
1796 {
1797 VTY_DECLVAR_CONTEXT(bgp, bgp);
1798 bgp_flag_set(bgp, BGP_FLAG_NO_CLIENT_TO_CLIENT);
1799 bgp_clear_star_soft_out(vty, bgp->name);
1800
1801 return CMD_SUCCESS;
1802 }
1803
1804 /* "bgp always-compare-med" configuration. */
1805 DEFUN (bgp_always_compare_med,
1806 bgp_always_compare_med_cmd,
1807 "bgp always-compare-med",
1808 "BGP specific commands\n"
1809 "Allow comparing MED from different neighbors\n")
1810 {
1811 VTY_DECLVAR_CONTEXT(bgp, bgp);
1812 bgp_flag_set(bgp, BGP_FLAG_ALWAYS_COMPARE_MED);
1813 bgp_recalculate_all_bestpaths(bgp);
1814
1815 return CMD_SUCCESS;
1816 }
1817
1818 DEFUN (no_bgp_always_compare_med,
1819 no_bgp_always_compare_med_cmd,
1820 "no bgp always-compare-med",
1821 NO_STR
1822 "BGP specific commands\n"
1823 "Allow comparing MED from different neighbors\n")
1824 {
1825 VTY_DECLVAR_CONTEXT(bgp, bgp);
1826 bgp_flag_unset(bgp, BGP_FLAG_ALWAYS_COMPARE_MED);
1827 bgp_recalculate_all_bestpaths(bgp);
1828
1829 return CMD_SUCCESS;
1830 }
1831
1832
1833 DEFUN(bgp_ebgp_requires_policy, bgp_ebgp_requires_policy_cmd,
1834 "bgp ebgp-requires-policy",
1835 "BGP specific commands\n"
1836 "Require in and out policy for eBGP peers (RFC8212)\n")
1837 {
1838 VTY_DECLVAR_CONTEXT(bgp, bgp);
1839 bgp->ebgp_requires_policy = DEFAULT_EBGP_POLICY_ENABLED;
1840 return CMD_SUCCESS;
1841 }
1842
1843 DEFUN(no_bgp_ebgp_requires_policy, no_bgp_ebgp_requires_policy_cmd,
1844 "no bgp ebgp-requires-policy",
1845 NO_STR
1846 "BGP specific commands\n"
1847 "Require in and out policy for eBGP peers (RFC8212)\n")
1848 {
1849 VTY_DECLVAR_CONTEXT(bgp, bgp);
1850 bgp->ebgp_requires_policy = DEFAULT_EBGP_POLICY_DISABLED;
1851 return CMD_SUCCESS;
1852 }
1853
1854
1855 /* "bgp deterministic-med" configuration. */
1856 DEFUN (bgp_deterministic_med,
1857 bgp_deterministic_med_cmd,
1858 "bgp deterministic-med",
1859 "BGP specific commands\n"
1860 "Pick the best-MED path among paths advertised from the neighboring AS\n")
1861 {
1862 VTY_DECLVAR_CONTEXT(bgp, bgp);
1863
1864 if (!bgp_flag_check(bgp, BGP_FLAG_DETERMINISTIC_MED)) {
1865 bgp_flag_set(bgp, BGP_FLAG_DETERMINISTIC_MED);
1866 bgp_recalculate_all_bestpaths(bgp);
1867 }
1868
1869 return CMD_SUCCESS;
1870 }
1871
1872 DEFUN (no_bgp_deterministic_med,
1873 no_bgp_deterministic_med_cmd,
1874 "no bgp deterministic-med",
1875 NO_STR
1876 "BGP specific commands\n"
1877 "Pick the best-MED path among paths advertised from the neighboring AS\n")
1878 {
1879 VTY_DECLVAR_CONTEXT(bgp, bgp);
1880 int bestpath_per_as_used;
1881 afi_t afi;
1882 safi_t safi;
1883 struct peer *peer;
1884 struct listnode *node, *nnode;
1885
1886 if (bgp_flag_check(bgp, BGP_FLAG_DETERMINISTIC_MED)) {
1887 bestpath_per_as_used = 0;
1888
1889 for (ALL_LIST_ELEMENTS(bgp->peer, node, nnode, peer)) {
1890 FOREACH_AFI_SAFI (afi, safi)
1891 if (bgp_addpath_dmed_required(
1892 peer->addpath_type[afi][safi])) {
1893 bestpath_per_as_used = 1;
1894 break;
1895 }
1896
1897 if (bestpath_per_as_used)
1898 break;
1899 }
1900
1901 if (bestpath_per_as_used) {
1902 vty_out(vty,
1903 "bgp deterministic-med cannot be disabled while addpath-tx-bestpath-per-AS is in use\n");
1904 return CMD_WARNING_CONFIG_FAILED;
1905 } else {
1906 bgp_flag_unset(bgp, BGP_FLAG_DETERMINISTIC_MED);
1907 bgp_recalculate_all_bestpaths(bgp);
1908 }
1909 }
1910
1911 return CMD_SUCCESS;
1912 }
1913
1914 /* "bgp graceful-restart" configuration. */
1915 DEFUN (bgp_graceful_restart,
1916 bgp_graceful_restart_cmd,
1917 "bgp graceful-restart",
1918 "BGP specific commands\n"
1919 "Graceful restart capability parameters\n")
1920 {
1921 VTY_DECLVAR_CONTEXT(bgp, bgp);
1922 bgp_flag_set(bgp, BGP_FLAG_GRACEFUL_RESTART);
1923 return CMD_SUCCESS;
1924 }
1925
1926 DEFUN (no_bgp_graceful_restart,
1927 no_bgp_graceful_restart_cmd,
1928 "no bgp graceful-restart",
1929 NO_STR
1930 "BGP specific commands\n"
1931 "Graceful restart capability parameters\n")
1932 {
1933 VTY_DECLVAR_CONTEXT(bgp, bgp);
1934 bgp_flag_unset(bgp, BGP_FLAG_GRACEFUL_RESTART);
1935 return CMD_SUCCESS;
1936 }
1937
1938 DEFUN (bgp_graceful_restart_stalepath_time,
1939 bgp_graceful_restart_stalepath_time_cmd,
1940 "bgp graceful-restart stalepath-time (1-4095)",
1941 "BGP specific commands\n"
1942 "Graceful restart capability parameters\n"
1943 "Set the max time to hold onto restarting peer's stale paths\n"
1944 "Delay value (seconds)\n")
1945 {
1946 VTY_DECLVAR_CONTEXT(bgp, bgp);
1947 int idx_number = 3;
1948 uint32_t stalepath;
1949
1950 stalepath = strtoul(argv[idx_number]->arg, NULL, 10);
1951 bgp->stalepath_time = stalepath;
1952 return CMD_SUCCESS;
1953 }
1954
1955 DEFUN (bgp_graceful_restart_restart_time,
1956 bgp_graceful_restart_restart_time_cmd,
1957 "bgp graceful-restart restart-time (1-4095)",
1958 "BGP specific commands\n"
1959 "Graceful restart capability parameters\n"
1960 "Set the time to wait to delete stale routes before a BGP open message is received\n"
1961 "Delay value (seconds)\n")
1962 {
1963 VTY_DECLVAR_CONTEXT(bgp, bgp);
1964 int idx_number = 3;
1965 uint32_t restart;
1966
1967 restart = strtoul(argv[idx_number]->arg, NULL, 10);
1968 bgp->restart_time = restart;
1969 return CMD_SUCCESS;
1970 }
1971
1972 DEFUN (no_bgp_graceful_restart_stalepath_time,
1973 no_bgp_graceful_restart_stalepath_time_cmd,
1974 "no bgp graceful-restart stalepath-time [(1-4095)]",
1975 NO_STR
1976 "BGP specific commands\n"
1977 "Graceful restart capability parameters\n"
1978 "Set the max time to hold onto restarting peer's stale paths\n"
1979 "Delay value (seconds)\n")
1980 {
1981 VTY_DECLVAR_CONTEXT(bgp, bgp);
1982
1983 bgp->stalepath_time = BGP_DEFAULT_STALEPATH_TIME;
1984 return CMD_SUCCESS;
1985 }
1986
1987 DEFUN (no_bgp_graceful_restart_restart_time,
1988 no_bgp_graceful_restart_restart_time_cmd,
1989 "no bgp graceful-restart restart-time [(1-4095)]",
1990 NO_STR
1991 "BGP specific commands\n"
1992 "Graceful restart capability parameters\n"
1993 "Set the time to wait to delete stale routes before a BGP open message is received\n"
1994 "Delay value (seconds)\n")
1995 {
1996 VTY_DECLVAR_CONTEXT(bgp, bgp);
1997
1998 bgp->restart_time = BGP_DEFAULT_RESTART_TIME;
1999 return CMD_SUCCESS;
2000 }
2001
2002 DEFUN (bgp_graceful_restart_preserve_fw,
2003 bgp_graceful_restart_preserve_fw_cmd,
2004 "bgp graceful-restart preserve-fw-state",
2005 "BGP specific commands\n"
2006 "Graceful restart capability parameters\n"
2007 "Sets F-bit indication that fib is preserved while doing Graceful Restart\n")
2008 {
2009 VTY_DECLVAR_CONTEXT(bgp, bgp);
2010 bgp_flag_set(bgp, BGP_FLAG_GR_PRESERVE_FWD);
2011 return CMD_SUCCESS;
2012 }
2013
2014 DEFUN (no_bgp_graceful_restart_preserve_fw,
2015 no_bgp_graceful_restart_preserve_fw_cmd,
2016 "no bgp graceful-restart preserve-fw-state",
2017 NO_STR
2018 "BGP specific commands\n"
2019 "Graceful restart capability parameters\n"
2020 "Unsets F-bit indication that fib is preserved while doing Graceful Restart\n")
2021 {
2022 VTY_DECLVAR_CONTEXT(bgp, bgp);
2023 bgp_flag_unset(bgp, BGP_FLAG_GR_PRESERVE_FWD);
2024 return CMD_SUCCESS;
2025 }
2026
2027 /* "bgp graceful-shutdown" configuration */
2028 DEFUN (bgp_graceful_shutdown,
2029 bgp_graceful_shutdown_cmd,
2030 "bgp graceful-shutdown",
2031 BGP_STR
2032 "Graceful shutdown parameters\n")
2033 {
2034 VTY_DECLVAR_CONTEXT(bgp, bgp);
2035
2036 if (!bgp_flag_check(bgp, BGP_FLAG_GRACEFUL_SHUTDOWN)) {
2037 bgp_flag_set(bgp, BGP_FLAG_GRACEFUL_SHUTDOWN);
2038 bgp_static_redo_import_check(bgp);
2039 bgp_redistribute_redo(bgp);
2040 bgp_clear_star_soft_out(vty, bgp->name);
2041 bgp_clear_star_soft_in(vty, bgp->name);
2042 }
2043
2044 return CMD_SUCCESS;
2045 }
2046
2047 DEFUN (no_bgp_graceful_shutdown,
2048 no_bgp_graceful_shutdown_cmd,
2049 "no bgp graceful-shutdown",
2050 NO_STR
2051 BGP_STR
2052 "Graceful shutdown parameters\n")
2053 {
2054 VTY_DECLVAR_CONTEXT(bgp, bgp);
2055
2056 if (bgp_flag_check(bgp, BGP_FLAG_GRACEFUL_SHUTDOWN)) {
2057 bgp_flag_unset(bgp, BGP_FLAG_GRACEFUL_SHUTDOWN);
2058 bgp_static_redo_import_check(bgp);
2059 bgp_redistribute_redo(bgp);
2060 bgp_clear_star_soft_out(vty, bgp->name);
2061 bgp_clear_star_soft_in(vty, bgp->name);
2062 }
2063
2064 return CMD_SUCCESS;
2065 }
2066
2067 /* "bgp fast-external-failover" configuration. */
2068 DEFUN (bgp_fast_external_failover,
2069 bgp_fast_external_failover_cmd,
2070 "bgp fast-external-failover",
2071 BGP_STR
2072 "Immediately reset session if a link to a directly connected external peer goes down\n")
2073 {
2074 VTY_DECLVAR_CONTEXT(bgp, bgp);
2075 bgp_flag_unset(bgp, BGP_FLAG_NO_FAST_EXT_FAILOVER);
2076 return CMD_SUCCESS;
2077 }
2078
2079 DEFUN (no_bgp_fast_external_failover,
2080 no_bgp_fast_external_failover_cmd,
2081 "no bgp fast-external-failover",
2082 NO_STR
2083 BGP_STR
2084 "Immediately reset session if a link to a directly connected external peer goes down\n")
2085 {
2086 VTY_DECLVAR_CONTEXT(bgp, bgp);
2087 bgp_flag_set(bgp, BGP_FLAG_NO_FAST_EXT_FAILOVER);
2088 return CMD_SUCCESS;
2089 }
2090
2091 /* "bgp bestpath compare-routerid" configuration. */
2092 DEFUN (bgp_bestpath_compare_router_id,
2093 bgp_bestpath_compare_router_id_cmd,
2094 "bgp bestpath compare-routerid",
2095 "BGP specific commands\n"
2096 "Change the default bestpath selection\n"
2097 "Compare router-id for identical EBGP paths\n")
2098 {
2099 VTY_DECLVAR_CONTEXT(bgp, bgp);
2100 bgp_flag_set(bgp, BGP_FLAG_COMPARE_ROUTER_ID);
2101 bgp_recalculate_all_bestpaths(bgp);
2102
2103 return CMD_SUCCESS;
2104 }
2105
2106 DEFUN (no_bgp_bestpath_compare_router_id,
2107 no_bgp_bestpath_compare_router_id_cmd,
2108 "no bgp bestpath compare-routerid",
2109 NO_STR
2110 "BGP specific commands\n"
2111 "Change the default bestpath selection\n"
2112 "Compare router-id for identical EBGP paths\n")
2113 {
2114 VTY_DECLVAR_CONTEXT(bgp, bgp);
2115 bgp_flag_unset(bgp, BGP_FLAG_COMPARE_ROUTER_ID);
2116 bgp_recalculate_all_bestpaths(bgp);
2117
2118 return CMD_SUCCESS;
2119 }
2120
2121 /* "bgp bestpath as-path ignore" configuration. */
2122 DEFUN (bgp_bestpath_aspath_ignore,
2123 bgp_bestpath_aspath_ignore_cmd,
2124 "bgp bestpath as-path ignore",
2125 "BGP specific commands\n"
2126 "Change the default bestpath selection\n"
2127 "AS-path attribute\n"
2128 "Ignore as-path length in selecting a route\n")
2129 {
2130 VTY_DECLVAR_CONTEXT(bgp, bgp);
2131 bgp_flag_set(bgp, BGP_FLAG_ASPATH_IGNORE);
2132 bgp_recalculate_all_bestpaths(bgp);
2133
2134 return CMD_SUCCESS;
2135 }
2136
2137 DEFUN (no_bgp_bestpath_aspath_ignore,
2138 no_bgp_bestpath_aspath_ignore_cmd,
2139 "no bgp bestpath as-path ignore",
2140 NO_STR
2141 "BGP specific commands\n"
2142 "Change the default bestpath selection\n"
2143 "AS-path attribute\n"
2144 "Ignore as-path length in selecting a route\n")
2145 {
2146 VTY_DECLVAR_CONTEXT(bgp, bgp);
2147 bgp_flag_unset(bgp, BGP_FLAG_ASPATH_IGNORE);
2148 bgp_recalculate_all_bestpaths(bgp);
2149
2150 return CMD_SUCCESS;
2151 }
2152
2153 /* "bgp bestpath as-path confed" configuration. */
2154 DEFUN (bgp_bestpath_aspath_confed,
2155 bgp_bestpath_aspath_confed_cmd,
2156 "bgp bestpath as-path confed",
2157 "BGP specific commands\n"
2158 "Change the default bestpath selection\n"
2159 "AS-path attribute\n"
2160 "Compare path lengths including confederation sets & sequences in selecting a route\n")
2161 {
2162 VTY_DECLVAR_CONTEXT(bgp, bgp);
2163 bgp_flag_set(bgp, BGP_FLAG_ASPATH_CONFED);
2164 bgp_recalculate_all_bestpaths(bgp);
2165
2166 return CMD_SUCCESS;
2167 }
2168
2169 DEFUN (no_bgp_bestpath_aspath_confed,
2170 no_bgp_bestpath_aspath_confed_cmd,
2171 "no bgp bestpath as-path confed",
2172 NO_STR
2173 "BGP specific commands\n"
2174 "Change the default bestpath selection\n"
2175 "AS-path attribute\n"
2176 "Compare path lengths including confederation sets & sequences in selecting a route\n")
2177 {
2178 VTY_DECLVAR_CONTEXT(bgp, bgp);
2179 bgp_flag_unset(bgp, BGP_FLAG_ASPATH_CONFED);
2180 bgp_recalculate_all_bestpaths(bgp);
2181
2182 return CMD_SUCCESS;
2183 }
2184
2185 /* "bgp bestpath as-path multipath-relax" configuration. */
2186 DEFUN (bgp_bestpath_aspath_multipath_relax,
2187 bgp_bestpath_aspath_multipath_relax_cmd,
2188 "bgp bestpath as-path multipath-relax [<as-set|no-as-set>]",
2189 "BGP specific commands\n"
2190 "Change the default bestpath selection\n"
2191 "AS-path attribute\n"
2192 "Allow load sharing across routes that have different AS paths (but same length)\n"
2193 "Generate an AS_SET\n"
2194 "Do not generate an AS_SET\n")
2195 {
2196 VTY_DECLVAR_CONTEXT(bgp, bgp);
2197 int idx = 0;
2198 bgp_flag_set(bgp, BGP_FLAG_ASPATH_MULTIPATH_RELAX);
2199
2200 /* no-as-set is now the default behavior so we can silently
2201 * ignore it */
2202 if (argv_find(argv, argc, "as-set", &idx))
2203 bgp_flag_set(bgp, BGP_FLAG_MULTIPATH_RELAX_AS_SET);
2204 else
2205 bgp_flag_unset(bgp, BGP_FLAG_MULTIPATH_RELAX_AS_SET);
2206
2207 bgp_recalculate_all_bestpaths(bgp);
2208
2209 return CMD_SUCCESS;
2210 }
2211
2212 DEFUN (no_bgp_bestpath_aspath_multipath_relax,
2213 no_bgp_bestpath_aspath_multipath_relax_cmd,
2214 "no bgp bestpath as-path multipath-relax [<as-set|no-as-set>]",
2215 NO_STR
2216 "BGP specific commands\n"
2217 "Change the default bestpath selection\n"
2218 "AS-path attribute\n"
2219 "Allow load sharing across routes that have different AS paths (but same length)\n"
2220 "Generate an AS_SET\n"
2221 "Do not generate an AS_SET\n")
2222 {
2223 VTY_DECLVAR_CONTEXT(bgp, bgp);
2224 bgp_flag_unset(bgp, BGP_FLAG_ASPATH_MULTIPATH_RELAX);
2225 bgp_flag_unset(bgp, BGP_FLAG_MULTIPATH_RELAX_AS_SET);
2226 bgp_recalculate_all_bestpaths(bgp);
2227
2228 return CMD_SUCCESS;
2229 }
2230
2231 /* "bgp log-neighbor-changes" configuration. */
2232 DEFUN (bgp_log_neighbor_changes,
2233 bgp_log_neighbor_changes_cmd,
2234 "bgp log-neighbor-changes",
2235 "BGP specific commands\n"
2236 "Log neighbor up/down and reset reason\n")
2237 {
2238 VTY_DECLVAR_CONTEXT(bgp, bgp);
2239 bgp_flag_set(bgp, BGP_FLAG_LOG_NEIGHBOR_CHANGES);
2240 return CMD_SUCCESS;
2241 }
2242
2243 DEFUN (no_bgp_log_neighbor_changes,
2244 no_bgp_log_neighbor_changes_cmd,
2245 "no bgp log-neighbor-changes",
2246 NO_STR
2247 "BGP specific commands\n"
2248 "Log neighbor up/down and reset reason\n")
2249 {
2250 VTY_DECLVAR_CONTEXT(bgp, bgp);
2251 bgp_flag_unset(bgp, BGP_FLAG_LOG_NEIGHBOR_CHANGES);
2252 return CMD_SUCCESS;
2253 }
2254
2255 /* "bgp bestpath med" configuration. */
2256 DEFUN (bgp_bestpath_med,
2257 bgp_bestpath_med_cmd,
2258 "bgp bestpath med <confed [missing-as-worst]|missing-as-worst [confed]>",
2259 "BGP specific commands\n"
2260 "Change the default bestpath selection\n"
2261 "MED attribute\n"
2262 "Compare MED among confederation paths\n"
2263 "Treat missing MED as the least preferred one\n"
2264 "Treat missing MED as the least preferred one\n"
2265 "Compare MED among confederation paths\n")
2266 {
2267 VTY_DECLVAR_CONTEXT(bgp, bgp);
2268
2269 int idx = 0;
2270 if (argv_find(argv, argc, "confed", &idx))
2271 bgp_flag_set(bgp, BGP_FLAG_MED_CONFED);
2272 idx = 0;
2273 if (argv_find(argv, argc, "missing-as-worst", &idx))
2274 bgp_flag_set(bgp, BGP_FLAG_MED_MISSING_AS_WORST);
2275
2276 bgp_recalculate_all_bestpaths(bgp);
2277
2278 return CMD_SUCCESS;
2279 }
2280
2281 DEFUN (no_bgp_bestpath_med,
2282 no_bgp_bestpath_med_cmd,
2283 "no bgp bestpath med <confed [missing-as-worst]|missing-as-worst [confed]>",
2284 NO_STR
2285 "BGP specific commands\n"
2286 "Change the default bestpath selection\n"
2287 "MED attribute\n"
2288 "Compare MED among confederation paths\n"
2289 "Treat missing MED as the least preferred one\n"
2290 "Treat missing MED as the least preferred one\n"
2291 "Compare MED among confederation paths\n")
2292 {
2293 VTY_DECLVAR_CONTEXT(bgp, bgp);
2294
2295 int idx = 0;
2296 if (argv_find(argv, argc, "confed", &idx))
2297 bgp_flag_unset(bgp, BGP_FLAG_MED_CONFED);
2298 idx = 0;
2299 if (argv_find(argv, argc, "missing-as-worst", &idx))
2300 bgp_flag_unset(bgp, BGP_FLAG_MED_MISSING_AS_WORST);
2301
2302 bgp_recalculate_all_bestpaths(bgp);
2303
2304 return CMD_SUCCESS;
2305 }
2306
2307 /* "no bgp default ipv4-unicast". */
2308 DEFUN (no_bgp_default_ipv4_unicast,
2309 no_bgp_default_ipv4_unicast_cmd,
2310 "no bgp default ipv4-unicast",
2311 NO_STR
2312 "BGP specific commands\n"
2313 "Configure BGP defaults\n"
2314 "Activate ipv4-unicast for a peer by default\n")
2315 {
2316 VTY_DECLVAR_CONTEXT(bgp, bgp);
2317 bgp_flag_set(bgp, BGP_FLAG_NO_DEFAULT_IPV4);
2318 return CMD_SUCCESS;
2319 }
2320
2321 DEFUN (bgp_default_ipv4_unicast,
2322 bgp_default_ipv4_unicast_cmd,
2323 "bgp default ipv4-unicast",
2324 "BGP specific commands\n"
2325 "Configure BGP defaults\n"
2326 "Activate ipv4-unicast for a peer by default\n")
2327 {
2328 VTY_DECLVAR_CONTEXT(bgp, bgp);
2329 bgp_flag_unset(bgp, BGP_FLAG_NO_DEFAULT_IPV4);
2330 return CMD_SUCCESS;
2331 }
2332
2333 /* Display hostname in certain command outputs */
2334 DEFUN (bgp_default_show_hostname,
2335 bgp_default_show_hostname_cmd,
2336 "bgp default show-hostname",
2337 "BGP specific commands\n"
2338 "Configure BGP defaults\n"
2339 "Show hostname in certain command outputs\n")
2340 {
2341 VTY_DECLVAR_CONTEXT(bgp, bgp);
2342 bgp_flag_set(bgp, BGP_FLAG_SHOW_HOSTNAME);
2343 return CMD_SUCCESS;
2344 }
2345
2346 DEFUN (no_bgp_default_show_hostname,
2347 no_bgp_default_show_hostname_cmd,
2348 "no bgp default show-hostname",
2349 NO_STR
2350 "BGP specific commands\n"
2351 "Configure BGP defaults\n"
2352 "Show hostname in certain command outputs\n")
2353 {
2354 VTY_DECLVAR_CONTEXT(bgp, bgp);
2355 bgp_flag_unset(bgp, BGP_FLAG_SHOW_HOSTNAME);
2356 return CMD_SUCCESS;
2357 }
2358
2359 /* "bgp network import-check" configuration. */
2360 DEFUN (bgp_network_import_check,
2361 bgp_network_import_check_cmd,
2362 "bgp network import-check",
2363 "BGP specific commands\n"
2364 "BGP network command\n"
2365 "Check BGP network route exists in IGP\n")
2366 {
2367 VTY_DECLVAR_CONTEXT(bgp, bgp);
2368 if (!bgp_flag_check(bgp, BGP_FLAG_IMPORT_CHECK)) {
2369 bgp_flag_set(bgp, BGP_FLAG_IMPORT_CHECK);
2370 bgp_static_redo_import_check(bgp);
2371 }
2372
2373 return CMD_SUCCESS;
2374 }
2375
2376 ALIAS_HIDDEN(bgp_network_import_check, bgp_network_import_check_exact_cmd,
2377 "bgp network import-check exact",
2378 "BGP specific commands\n"
2379 "BGP network command\n"
2380 "Check BGP network route exists in IGP\n"
2381 "Match route precisely\n")
2382
2383 DEFUN (no_bgp_network_import_check,
2384 no_bgp_network_import_check_cmd,
2385 "no bgp network import-check",
2386 NO_STR
2387 "BGP specific commands\n"
2388 "BGP network command\n"
2389 "Check BGP network route exists in IGP\n")
2390 {
2391 VTY_DECLVAR_CONTEXT(bgp, bgp);
2392 if (bgp_flag_check(bgp, BGP_FLAG_IMPORT_CHECK)) {
2393 bgp_flag_unset(bgp, BGP_FLAG_IMPORT_CHECK);
2394 bgp_static_redo_import_check(bgp);
2395 }
2396
2397 return CMD_SUCCESS;
2398 }
2399
2400 DEFUN (bgp_default_local_preference,
2401 bgp_default_local_preference_cmd,
2402 "bgp default local-preference (0-4294967295)",
2403 "BGP specific commands\n"
2404 "Configure BGP defaults\n"
2405 "local preference (higher=more preferred)\n"
2406 "Configure default local preference value\n")
2407 {
2408 VTY_DECLVAR_CONTEXT(bgp, bgp);
2409 int idx_number = 3;
2410 uint32_t local_pref;
2411
2412 local_pref = strtoul(argv[idx_number]->arg, NULL, 10);
2413
2414 bgp_default_local_preference_set(bgp, local_pref);
2415 bgp_clear_star_soft_in(vty, bgp->name);
2416
2417 return CMD_SUCCESS;
2418 }
2419
2420 DEFUN (no_bgp_default_local_preference,
2421 no_bgp_default_local_preference_cmd,
2422 "no bgp default local-preference [(0-4294967295)]",
2423 NO_STR
2424 "BGP specific commands\n"
2425 "Configure BGP defaults\n"
2426 "local preference (higher=more preferred)\n"
2427 "Configure default local preference value\n")
2428 {
2429 VTY_DECLVAR_CONTEXT(bgp, bgp);
2430 bgp_default_local_preference_unset(bgp);
2431 bgp_clear_star_soft_in(vty, bgp->name);
2432
2433 return CMD_SUCCESS;
2434 }
2435
2436
2437 DEFUN (bgp_default_subgroup_pkt_queue_max,
2438 bgp_default_subgroup_pkt_queue_max_cmd,
2439 "bgp default subgroup-pkt-queue-max (20-100)",
2440 "BGP specific commands\n"
2441 "Configure BGP defaults\n"
2442 "subgroup-pkt-queue-max\n"
2443 "Configure subgroup packet queue max\n")
2444 {
2445 VTY_DECLVAR_CONTEXT(bgp, bgp);
2446 int idx_number = 3;
2447 uint32_t max_size;
2448
2449 max_size = strtoul(argv[idx_number]->arg, NULL, 10);
2450
2451 bgp_default_subgroup_pkt_queue_max_set(bgp, max_size);
2452
2453 return CMD_SUCCESS;
2454 }
2455
2456 DEFUN (no_bgp_default_subgroup_pkt_queue_max,
2457 no_bgp_default_subgroup_pkt_queue_max_cmd,
2458 "no bgp default subgroup-pkt-queue-max [(20-100)]",
2459 NO_STR
2460 "BGP specific commands\n"
2461 "Configure BGP defaults\n"
2462 "subgroup-pkt-queue-max\n"
2463 "Configure subgroup packet queue max\n")
2464 {
2465 VTY_DECLVAR_CONTEXT(bgp, bgp);
2466 bgp_default_subgroup_pkt_queue_max_unset(bgp);
2467 return CMD_SUCCESS;
2468 }
2469
2470
2471 DEFUN (bgp_rr_allow_outbound_policy,
2472 bgp_rr_allow_outbound_policy_cmd,
2473 "bgp route-reflector allow-outbound-policy",
2474 "BGP specific commands\n"
2475 "Allow modifications made by out route-map\n"
2476 "on ibgp neighbors\n")
2477 {
2478 VTY_DECLVAR_CONTEXT(bgp, bgp);
2479
2480 if (!bgp_flag_check(bgp, BGP_FLAG_RR_ALLOW_OUTBOUND_POLICY)) {
2481 bgp_flag_set(bgp, BGP_FLAG_RR_ALLOW_OUTBOUND_POLICY);
2482 update_group_announce_rrclients(bgp);
2483 bgp_clear_star_soft_out(vty, bgp->name);
2484 }
2485
2486 return CMD_SUCCESS;
2487 }
2488
2489 DEFUN (no_bgp_rr_allow_outbound_policy,
2490 no_bgp_rr_allow_outbound_policy_cmd,
2491 "no bgp route-reflector allow-outbound-policy",
2492 NO_STR
2493 "BGP specific commands\n"
2494 "Allow modifications made by out route-map\n"
2495 "on ibgp neighbors\n")
2496 {
2497 VTY_DECLVAR_CONTEXT(bgp, bgp);
2498
2499 if (bgp_flag_check(bgp, BGP_FLAG_RR_ALLOW_OUTBOUND_POLICY)) {
2500 bgp_flag_unset(bgp, BGP_FLAG_RR_ALLOW_OUTBOUND_POLICY);
2501 update_group_announce_rrclients(bgp);
2502 bgp_clear_star_soft_out(vty, bgp->name);
2503 }
2504
2505 return CMD_SUCCESS;
2506 }
2507
2508 DEFUN (bgp_listen_limit,
2509 bgp_listen_limit_cmd,
2510 "bgp listen limit (1-5000)",
2511 "BGP specific commands\n"
2512 "Configure BGP defaults\n"
2513 "maximum number of BGP Dynamic Neighbors that can be created\n"
2514 "Configure Dynamic Neighbors listen limit value\n")
2515 {
2516 VTY_DECLVAR_CONTEXT(bgp, bgp);
2517 int idx_number = 3;
2518 int listen_limit;
2519
2520 listen_limit = strtoul(argv[idx_number]->arg, NULL, 10);
2521
2522 bgp_listen_limit_set(bgp, listen_limit);
2523
2524 return CMD_SUCCESS;
2525 }
2526
2527 DEFUN (no_bgp_listen_limit,
2528 no_bgp_listen_limit_cmd,
2529 "no bgp listen limit [(1-5000)]",
2530 "BGP specific commands\n"
2531 "Configure BGP defaults\n"
2532 "unset maximum number of BGP Dynamic Neighbors that can be created\n"
2533 "Configure Dynamic Neighbors listen limit value to default\n"
2534 "Configure Dynamic Neighbors listen limit value\n")
2535 {
2536 VTY_DECLVAR_CONTEXT(bgp, bgp);
2537 bgp_listen_limit_unset(bgp);
2538 return CMD_SUCCESS;
2539 }
2540
2541
2542 /*
2543 * Check if this listen range is already configured. Check for exact
2544 * match or overlap based on input.
2545 */
2546 static struct peer_group *listen_range_exists(struct bgp *bgp,
2547 struct prefix *range, int exact)
2548 {
2549 struct listnode *node, *nnode;
2550 struct listnode *node1, *nnode1;
2551 struct peer_group *group;
2552 struct prefix *lr;
2553 afi_t afi;
2554 int match;
2555
2556 afi = family2afi(range->family);
2557 for (ALL_LIST_ELEMENTS(bgp->group, node, nnode, group)) {
2558 for (ALL_LIST_ELEMENTS(group->listen_range[afi], node1, nnode1,
2559 lr)) {
2560 if (exact)
2561 match = prefix_same(range, lr);
2562 else
2563 match = (prefix_match(range, lr)
2564 || prefix_match(lr, range));
2565 if (match)
2566 return group;
2567 }
2568 }
2569
2570 return NULL;
2571 }
2572
2573 DEFUN (bgp_listen_range,
2574 bgp_listen_range_cmd,
2575 "bgp listen range <A.B.C.D/M|X:X::X:X/M> peer-group PGNAME",
2576 "BGP specific commands\n"
2577 "Configure BGP dynamic neighbors listen range\n"
2578 "Configure BGP dynamic neighbors listen range\n"
2579 NEIGHBOR_ADDR_STR
2580 "Member of the peer-group\n"
2581 "Peer-group name\n")
2582 {
2583 VTY_DECLVAR_CONTEXT(bgp, bgp);
2584 struct prefix range;
2585 struct peer_group *group, *existing_group;
2586 afi_t afi;
2587 int ret;
2588 int idx = 0;
2589
2590 argv_find(argv, argc, "A.B.C.D/M", &idx);
2591 argv_find(argv, argc, "X:X::X:X/M", &idx);
2592 char *prefix = argv[idx]->arg;
2593 argv_find(argv, argc, "PGNAME", &idx);
2594 char *peergroup = argv[idx]->arg;
2595
2596 /* Convert IP prefix string to struct prefix. */
2597 ret = str2prefix(prefix, &range);
2598 if (!ret) {
2599 vty_out(vty, "%% Malformed listen range\n");
2600 return CMD_WARNING_CONFIG_FAILED;
2601 }
2602
2603 afi = family2afi(range.family);
2604
2605 if (afi == AFI_IP6 && IN6_IS_ADDR_LINKLOCAL(&range.u.prefix6)) {
2606 vty_out(vty,
2607 "%% Malformed listen range (link-local address)\n");
2608 return CMD_WARNING_CONFIG_FAILED;
2609 }
2610
2611 apply_mask(&range);
2612
2613 /* Check if same listen range is already configured. */
2614 existing_group = listen_range_exists(bgp, &range, 1);
2615 if (existing_group) {
2616 if (strcmp(existing_group->name, peergroup) == 0)
2617 return CMD_SUCCESS;
2618 else {
2619 vty_out(vty,
2620 "%% Same listen range is attached to peer-group %s\n",
2621 existing_group->name);
2622 return CMD_WARNING_CONFIG_FAILED;
2623 }
2624 }
2625
2626 /* Check if an overlapping listen range exists. */
2627 if (listen_range_exists(bgp, &range, 0)) {
2628 vty_out(vty,
2629 "%% Listen range overlaps with existing listen range\n");
2630 return CMD_WARNING_CONFIG_FAILED;
2631 }
2632
2633 group = peer_group_lookup(bgp, peergroup);
2634 if (!group) {
2635 vty_out(vty, "%% Configure the peer-group first\n");
2636 return CMD_WARNING_CONFIG_FAILED;
2637 }
2638
2639 ret = peer_group_listen_range_add(group, &range);
2640 return bgp_vty_return(vty, ret);
2641 }
2642
2643 DEFUN (no_bgp_listen_range,
2644 no_bgp_listen_range_cmd,
2645 "no bgp listen range <A.B.C.D/M|X:X::X:X/M> peer-group PGNAME",
2646 NO_STR
2647 "BGP specific commands\n"
2648 "Unconfigure BGP dynamic neighbors listen range\n"
2649 "Unconfigure BGP dynamic neighbors listen range\n"
2650 NEIGHBOR_ADDR_STR
2651 "Member of the peer-group\n"
2652 "Peer-group name\n")
2653 {
2654 VTY_DECLVAR_CONTEXT(bgp, bgp);
2655 struct prefix range;
2656 struct peer_group *group;
2657 afi_t afi;
2658 int ret;
2659 int idx = 0;
2660
2661 argv_find(argv, argc, "A.B.C.D/M", &idx);
2662 argv_find(argv, argc, "X:X::X:X/M", &idx);
2663 char *prefix = argv[idx]->arg;
2664 argv_find(argv, argc, "WORD", &idx);
2665 char *peergroup = argv[idx]->arg;
2666
2667 /* Convert IP prefix string to struct prefix. */
2668 ret = str2prefix(prefix, &range);
2669 if (!ret) {
2670 vty_out(vty, "%% Malformed listen range\n");
2671 return CMD_WARNING_CONFIG_FAILED;
2672 }
2673
2674 afi = family2afi(range.family);
2675
2676 if (afi == AFI_IP6 && IN6_IS_ADDR_LINKLOCAL(&range.u.prefix6)) {
2677 vty_out(vty,
2678 "%% Malformed listen range (link-local address)\n");
2679 return CMD_WARNING_CONFIG_FAILED;
2680 }
2681
2682 apply_mask(&range);
2683
2684 group = peer_group_lookup(bgp, peergroup);
2685 if (!group) {
2686 vty_out(vty, "%% Peer-group does not exist\n");
2687 return CMD_WARNING_CONFIG_FAILED;
2688 }
2689
2690 ret = peer_group_listen_range_del(group, &range);
2691 return bgp_vty_return(vty, ret);
2692 }
2693
2694 void bgp_config_write_listen(struct vty *vty, struct bgp *bgp)
2695 {
2696 struct peer_group *group;
2697 struct listnode *node, *nnode, *rnode, *nrnode;
2698 struct prefix *range;
2699 afi_t afi;
2700 char buf[PREFIX2STR_BUFFER];
2701
2702 if (bgp->dynamic_neighbors_limit != BGP_DYNAMIC_NEIGHBORS_LIMIT_DEFAULT)
2703 vty_out(vty, " bgp listen limit %d\n",
2704 bgp->dynamic_neighbors_limit);
2705
2706 for (ALL_LIST_ELEMENTS(bgp->group, node, nnode, group)) {
2707 for (afi = AFI_IP; afi < AFI_MAX; afi++) {
2708 for (ALL_LIST_ELEMENTS(group->listen_range[afi], rnode,
2709 nrnode, range)) {
2710 prefix2str(range, buf, sizeof(buf));
2711 vty_out(vty,
2712 " bgp listen range %s peer-group %s\n",
2713 buf, group->name);
2714 }
2715 }
2716 }
2717 }
2718
2719
2720 DEFUN (bgp_disable_connected_route_check,
2721 bgp_disable_connected_route_check_cmd,
2722 "bgp disable-ebgp-connected-route-check",
2723 "BGP specific commands\n"
2724 "Disable checking if nexthop is connected on ebgp sessions\n")
2725 {
2726 VTY_DECLVAR_CONTEXT(bgp, bgp);
2727 bgp_flag_set(bgp, BGP_FLAG_DISABLE_NH_CONNECTED_CHK);
2728 bgp_clear_star_soft_in(vty, bgp->name);
2729
2730 return CMD_SUCCESS;
2731 }
2732
2733 DEFUN (no_bgp_disable_connected_route_check,
2734 no_bgp_disable_connected_route_check_cmd,
2735 "no bgp disable-ebgp-connected-route-check",
2736 NO_STR
2737 "BGP specific commands\n"
2738 "Disable checking if nexthop is connected on ebgp sessions\n")
2739 {
2740 VTY_DECLVAR_CONTEXT(bgp, bgp);
2741 bgp_flag_unset(bgp, BGP_FLAG_DISABLE_NH_CONNECTED_CHK);
2742 bgp_clear_star_soft_in(vty, bgp->name);
2743
2744 return CMD_SUCCESS;
2745 }
2746
2747
2748 static int peer_remote_as_vty(struct vty *vty, const char *peer_str,
2749 const char *as_str, afi_t afi, safi_t safi)
2750 {
2751 VTY_DECLVAR_CONTEXT(bgp, bgp);
2752 int ret;
2753 as_t as;
2754 int as_type = AS_SPECIFIED;
2755 union sockunion su;
2756
2757 if (as_str[0] == 'i') {
2758 as = 0;
2759 as_type = AS_INTERNAL;
2760 } else if (as_str[0] == 'e') {
2761 as = 0;
2762 as_type = AS_EXTERNAL;
2763 } else {
2764 /* Get AS number. */
2765 as = strtoul(as_str, NULL, 10);
2766 }
2767
2768 /* If peer is peer group or interface peer, call proper function. */
2769 ret = str2sockunion(peer_str, &su);
2770 if (ret < 0) {
2771 struct peer *peer;
2772
2773 /* Check if existing interface peer */
2774 peer = peer_lookup_by_conf_if(bgp, peer_str);
2775
2776 ret = peer_remote_as(bgp, NULL, peer_str, &as, as_type, afi,
2777 safi);
2778
2779 /* if not interface peer, check peer-group settings */
2780 if (ret < 0 && !peer) {
2781 ret = peer_group_remote_as(bgp, peer_str, &as, as_type);
2782 if (ret < 0) {
2783 vty_out(vty,
2784 "%% Create the peer-group or interface first\n");
2785 return CMD_WARNING_CONFIG_FAILED;
2786 }
2787 return CMD_SUCCESS;
2788 }
2789 } else {
2790 if (peer_address_self_check(bgp, &su)) {
2791 vty_out(vty,
2792 "%% Can not configure the local system as neighbor\n");
2793 return CMD_WARNING_CONFIG_FAILED;
2794 }
2795 ret = peer_remote_as(bgp, &su, NULL, &as, as_type, afi, safi);
2796 }
2797
2798 /* This peer belongs to peer group. */
2799 switch (ret) {
2800 case BGP_ERR_PEER_GROUP_MEMBER:
2801 vty_out(vty,
2802 "%% Peer-group member cannot override remote-as of peer-group\n");
2803 return CMD_WARNING_CONFIG_FAILED;
2804 case BGP_ERR_PEER_GROUP_PEER_TYPE_DIFFERENT:
2805 vty_out(vty,
2806 "%% Peer-group members must be all internal or all external\n");
2807 return CMD_WARNING_CONFIG_FAILED;
2808 }
2809 return bgp_vty_return(vty, ret);
2810 }
2811
2812 DEFUN (bgp_default_shutdown,
2813 bgp_default_shutdown_cmd,
2814 "[no] bgp default shutdown",
2815 NO_STR
2816 BGP_STR
2817 "Configure BGP defaults\n"
2818 "Apply administrative shutdown to newly configured peers\n")
2819 {
2820 VTY_DECLVAR_CONTEXT(bgp, bgp);
2821 bgp->autoshutdown = !strmatch(argv[0]->text, "no");
2822 return CMD_SUCCESS;
2823 }
2824
2825 DEFUN (neighbor_remote_as,
2826 neighbor_remote_as_cmd,
2827 "neighbor <A.B.C.D|X:X::X:X|WORD> remote-as <(1-4294967295)|internal|external>",
2828 NEIGHBOR_STR
2829 NEIGHBOR_ADDR_STR2
2830 "Specify a BGP neighbor\n"
2831 AS_STR
2832 "Internal BGP peer\n"
2833 "External BGP peer\n")
2834 {
2835 int idx_peer = 1;
2836 int idx_remote_as = 3;
2837 return peer_remote_as_vty(vty, argv[idx_peer]->arg,
2838 argv[idx_remote_as]->arg, AFI_IP,
2839 SAFI_UNICAST);
2840 }
2841
2842 static int peer_conf_interface_get(struct vty *vty, const char *conf_if,
2843 afi_t afi, safi_t safi, int v6only,
2844 const char *peer_group_name,
2845 const char *as_str)
2846 {
2847 VTY_DECLVAR_CONTEXT(bgp, bgp);
2848 as_t as = 0;
2849 int as_type = AS_UNSPECIFIED;
2850 struct peer *peer;
2851 struct peer_group *group;
2852 int ret = 0;
2853 union sockunion su;
2854
2855 group = peer_group_lookup(bgp, conf_if);
2856
2857 if (group) {
2858 vty_out(vty, "%% Name conflict with peer-group \n");
2859 return CMD_WARNING_CONFIG_FAILED;
2860 }
2861
2862 if (as_str) {
2863 if (as_str[0] == 'i') {
2864 as_type = AS_INTERNAL;
2865 } else if (as_str[0] == 'e') {
2866 as_type = AS_EXTERNAL;
2867 } else {
2868 /* Get AS number. */
2869 as = strtoul(as_str, NULL, 10);
2870 as_type = AS_SPECIFIED;
2871 }
2872 }
2873
2874 peer = peer_lookup_by_conf_if(bgp, conf_if);
2875 if (peer) {
2876 if (as_str)
2877 ret = peer_remote_as(bgp, NULL, conf_if, &as, as_type,
2878 afi, safi);
2879 } else {
2880 if (bgp_flag_check(bgp, BGP_FLAG_NO_DEFAULT_IPV4)
2881 && afi == AFI_IP && safi == SAFI_UNICAST)
2882 peer = peer_create(NULL, conf_if, bgp, bgp->as, as,
2883 as_type, 0, 0, NULL);
2884 else
2885 peer = peer_create(NULL, conf_if, bgp, bgp->as, as,
2886 as_type, afi, safi, NULL);
2887
2888 if (!peer) {
2889 vty_out(vty, "%% BGP failed to create peer\n");
2890 return CMD_WARNING_CONFIG_FAILED;
2891 }
2892
2893 if (v6only)
2894 peer_flag_set(peer, PEER_FLAG_IFPEER_V6ONLY);
2895
2896 /* Request zebra to initiate IPv6 RAs on this interface. We do
2897 * this
2898 * any unnumbered peer in order to not worry about run-time
2899 * transitions
2900 * (e.g., peering is initially IPv4, but the IPv4 /30 or /31
2901 * address
2902 * gets deleted later etc.)
2903 */
2904 if (peer->ifp)
2905 bgp_zebra_initiate_radv(bgp, peer);
2906 }
2907
2908 if ((v6only && !CHECK_FLAG(peer->flags, PEER_FLAG_IFPEER_V6ONLY))
2909 || (!v6only && CHECK_FLAG(peer->flags, PEER_FLAG_IFPEER_V6ONLY))) {
2910 if (v6only)
2911 peer_flag_set(peer, PEER_FLAG_IFPEER_V6ONLY);
2912 else
2913 peer_flag_unset(peer, PEER_FLAG_IFPEER_V6ONLY);
2914
2915 /* v6only flag changed. Reset bgp seesion */
2916 if (BGP_IS_VALID_STATE_FOR_NOTIF(peer->status)) {
2917 peer->last_reset = PEER_DOWN_V6ONLY_CHANGE;
2918 bgp_notify_send(peer, BGP_NOTIFY_CEASE,
2919 BGP_NOTIFY_CEASE_CONFIG_CHANGE);
2920 } else
2921 bgp_session_reset(peer);
2922 }
2923
2924 if (!CHECK_FLAG(peer->flags_invert, PEER_FLAG_CAPABILITY_ENHE)) {
2925 SET_FLAG(peer->flags, PEER_FLAG_CAPABILITY_ENHE);
2926 SET_FLAG(peer->flags_invert, PEER_FLAG_CAPABILITY_ENHE);
2927 SET_FLAG(peer->flags_override, PEER_FLAG_CAPABILITY_ENHE);
2928 }
2929
2930 if (peer_group_name) {
2931 group = peer_group_lookup(bgp, peer_group_name);
2932 if (!group) {
2933 vty_out(vty, "%% Configure the peer-group first\n");
2934 return CMD_WARNING_CONFIG_FAILED;
2935 }
2936
2937 ret = peer_group_bind(bgp, &su, peer, group, &as);
2938 }
2939
2940 return bgp_vty_return(vty, ret);
2941 }
2942
2943 DEFUN (neighbor_interface_config,
2944 neighbor_interface_config_cmd,
2945 "neighbor WORD interface [peer-group PGNAME]",
2946 NEIGHBOR_STR
2947 "Interface name or neighbor tag\n"
2948 "Enable BGP on interface\n"
2949 "Member of the peer-group\n"
2950 "Peer-group name\n")
2951 {
2952 int idx_word = 1;
2953 int idx_peer_group_word = 4;
2954
2955 if (argc > idx_peer_group_word)
2956 return peer_conf_interface_get(
2957 vty, argv[idx_word]->arg, AFI_IP, SAFI_UNICAST, 0,
2958 argv[idx_peer_group_word]->arg, NULL);
2959 else
2960 return peer_conf_interface_get(vty, argv[idx_word]->arg, AFI_IP,
2961 SAFI_UNICAST, 0, NULL, NULL);
2962 }
2963
2964 DEFUN (neighbor_interface_config_v6only,
2965 neighbor_interface_config_v6only_cmd,
2966 "neighbor WORD interface v6only [peer-group PGNAME]",
2967 NEIGHBOR_STR
2968 "Interface name or neighbor tag\n"
2969 "Enable BGP on interface\n"
2970 "Enable BGP with v6 link-local only\n"
2971 "Member of the peer-group\n"
2972 "Peer-group name\n")
2973 {
2974 int idx_word = 1;
2975 int idx_peer_group_word = 5;
2976
2977 if (argc > idx_peer_group_word)
2978 return peer_conf_interface_get(
2979 vty, argv[idx_word]->arg, AFI_IP, SAFI_UNICAST, 1,
2980 argv[idx_peer_group_word]->arg, NULL);
2981
2982 return peer_conf_interface_get(vty, argv[idx_word]->arg, AFI_IP,
2983 SAFI_UNICAST, 1, NULL, NULL);
2984 }
2985
2986
2987 DEFUN (neighbor_interface_config_remote_as,
2988 neighbor_interface_config_remote_as_cmd,
2989 "neighbor WORD interface remote-as <(1-4294967295)|internal|external>",
2990 NEIGHBOR_STR
2991 "Interface name or neighbor tag\n"
2992 "Enable BGP on interface\n"
2993 "Specify a BGP neighbor\n"
2994 AS_STR
2995 "Internal BGP peer\n"
2996 "External BGP peer\n")
2997 {
2998 int idx_word = 1;
2999 int idx_remote_as = 4;
3000 return peer_conf_interface_get(vty, argv[idx_word]->arg, AFI_IP,
3001 SAFI_UNICAST, 0, NULL,
3002 argv[idx_remote_as]->arg);
3003 }
3004
3005 DEFUN (neighbor_interface_v6only_config_remote_as,
3006 neighbor_interface_v6only_config_remote_as_cmd,
3007 "neighbor WORD interface v6only remote-as <(1-4294967295)|internal|external>",
3008 NEIGHBOR_STR
3009 "Interface name or neighbor tag\n"
3010 "Enable BGP with v6 link-local only\n"
3011 "Enable BGP on interface\n"
3012 "Specify a BGP neighbor\n"
3013 AS_STR
3014 "Internal BGP peer\n"
3015 "External BGP peer\n")
3016 {
3017 int idx_word = 1;
3018 int idx_remote_as = 5;
3019 return peer_conf_interface_get(vty, argv[idx_word]->arg, AFI_IP,
3020 SAFI_UNICAST, 1, NULL,
3021 argv[idx_remote_as]->arg);
3022 }
3023
3024 DEFUN (neighbor_peer_group,
3025 neighbor_peer_group_cmd,
3026 "neighbor WORD peer-group",
3027 NEIGHBOR_STR
3028 "Interface name or neighbor tag\n"
3029 "Configure peer-group\n")
3030 {
3031 VTY_DECLVAR_CONTEXT(bgp, bgp);
3032 int idx_word = 1;
3033 struct peer *peer;
3034 struct peer_group *group;
3035
3036 peer = peer_lookup_by_conf_if(bgp, argv[idx_word]->arg);
3037 if (peer) {
3038 vty_out(vty, "%% Name conflict with interface: \n");
3039 return CMD_WARNING_CONFIG_FAILED;
3040 }
3041
3042 group = peer_group_get(bgp, argv[idx_word]->arg);
3043 if (!group) {
3044 vty_out(vty, "%% BGP failed to find or create peer-group\n");
3045 return CMD_WARNING_CONFIG_FAILED;
3046 }
3047
3048 return CMD_SUCCESS;
3049 }
3050
3051 DEFUN (no_neighbor,
3052 no_neighbor_cmd,
3053 "no neighbor <WORD|<A.B.C.D|X:X::X:X> [remote-as <(1-4294967295)|internal|external>]>",
3054 NO_STR
3055 NEIGHBOR_STR
3056 NEIGHBOR_ADDR_STR2
3057 "Specify a BGP neighbor\n"
3058 AS_STR
3059 "Internal BGP peer\n"
3060 "External BGP peer\n")
3061 {
3062 VTY_DECLVAR_CONTEXT(bgp, bgp);
3063 int idx_peer = 2;
3064 int ret;
3065 union sockunion su;
3066 struct peer_group *group;
3067 struct peer *peer;
3068 struct peer *other;
3069
3070 ret = str2sockunion(argv[idx_peer]->arg, &su);
3071 if (ret < 0) {
3072 /* look up for neighbor by interface name config. */
3073 peer = peer_lookup_by_conf_if(bgp, argv[idx_peer]->arg);
3074 if (peer) {
3075 /* Request zebra to terminate IPv6 RAs on this
3076 * interface. */
3077 if (peer->ifp)
3078 bgp_zebra_terminate_radv(peer->bgp, peer);
3079 peer_delete(peer);
3080 return CMD_SUCCESS;
3081 }
3082
3083 group = peer_group_lookup(bgp, argv[idx_peer]->arg);
3084 if (group)
3085 peer_group_delete(group);
3086 else {
3087 vty_out(vty, "%% Create the peer-group first\n");
3088 return CMD_WARNING_CONFIG_FAILED;
3089 }
3090 } else {
3091 peer = peer_lookup(bgp, &su);
3092 if (peer) {
3093 if (peer_dynamic_neighbor(peer)) {
3094 vty_out(vty,
3095 "%% Operation not allowed on a dynamic neighbor\n");
3096 return CMD_WARNING_CONFIG_FAILED;
3097 }
3098
3099 other = peer->doppelganger;
3100 peer_delete(peer);
3101 if (other && other->status != Deleted)
3102 peer_delete(other);
3103 }
3104 }
3105
3106 return CMD_SUCCESS;
3107 }
3108
3109 DEFUN (no_neighbor_interface_config,
3110 no_neighbor_interface_config_cmd,
3111 "no neighbor WORD interface [v6only] [peer-group PGNAME] [remote-as <(1-4294967295)|internal|external>]",
3112 NO_STR
3113 NEIGHBOR_STR
3114 "Interface name\n"
3115 "Configure BGP on interface\n"
3116 "Enable BGP with v6 link-local only\n"
3117 "Member of the peer-group\n"
3118 "Peer-group name\n"
3119 "Specify a BGP neighbor\n"
3120 AS_STR
3121 "Internal BGP peer\n"
3122 "External BGP peer\n")
3123 {
3124 VTY_DECLVAR_CONTEXT(bgp, bgp);
3125 int idx_word = 2;
3126 struct peer *peer;
3127
3128 /* look up for neighbor by interface name config. */
3129 peer = peer_lookup_by_conf_if(bgp, argv[idx_word]->arg);
3130 if (peer) {
3131 /* Request zebra to terminate IPv6 RAs on this interface. */
3132 if (peer->ifp)
3133 bgp_zebra_terminate_radv(peer->bgp, peer);
3134 peer_delete(peer);
3135 } else {
3136 vty_out(vty, "%% Create the bgp interface first\n");
3137 return CMD_WARNING_CONFIG_FAILED;
3138 }
3139 return CMD_SUCCESS;
3140 }
3141
3142 DEFUN (no_neighbor_peer_group,
3143 no_neighbor_peer_group_cmd,
3144 "no neighbor WORD peer-group",
3145 NO_STR
3146 NEIGHBOR_STR
3147 "Neighbor tag\n"
3148 "Configure peer-group\n")
3149 {
3150 VTY_DECLVAR_CONTEXT(bgp, bgp);
3151 int idx_word = 2;
3152 struct peer_group *group;
3153
3154 group = peer_group_lookup(bgp, argv[idx_word]->arg);
3155 if (group)
3156 peer_group_delete(group);
3157 else {
3158 vty_out(vty, "%% Create the peer-group first\n");
3159 return CMD_WARNING_CONFIG_FAILED;
3160 }
3161 return CMD_SUCCESS;
3162 }
3163
3164 DEFUN (no_neighbor_interface_peer_group_remote_as,
3165 no_neighbor_interface_peer_group_remote_as_cmd,
3166 "no neighbor WORD remote-as <(1-4294967295)|internal|external>",
3167 NO_STR
3168 NEIGHBOR_STR
3169 "Interface name or neighbor tag\n"
3170 "Specify a BGP neighbor\n"
3171 AS_STR
3172 "Internal BGP peer\n"
3173 "External BGP peer\n")
3174 {
3175 VTY_DECLVAR_CONTEXT(bgp, bgp);
3176 int idx_word = 2;
3177 struct peer_group *group;
3178 struct peer *peer;
3179
3180 /* look up for neighbor by interface name config. */
3181 peer = peer_lookup_by_conf_if(bgp, argv[idx_word]->arg);
3182 if (peer) {
3183 peer_as_change(peer, 0, AS_UNSPECIFIED);
3184 return CMD_SUCCESS;
3185 }
3186
3187 group = peer_group_lookup(bgp, argv[idx_word]->arg);
3188 if (group)
3189 peer_group_remote_as_delete(group);
3190 else {
3191 vty_out(vty, "%% Create the peer-group or interface first\n");
3192 return CMD_WARNING_CONFIG_FAILED;
3193 }
3194 return CMD_SUCCESS;
3195 }
3196
3197 DEFUN (neighbor_local_as,
3198 neighbor_local_as_cmd,
3199 "neighbor <A.B.C.D|X:X::X:X|WORD> local-as (1-4294967295)",
3200 NEIGHBOR_STR
3201 NEIGHBOR_ADDR_STR2
3202 "Specify a local-as number\n"
3203 "AS number used as local AS\n")
3204 {
3205 int idx_peer = 1;
3206 int idx_number = 3;
3207 struct peer *peer;
3208 int ret;
3209 as_t as;
3210
3211 peer = peer_and_group_lookup_vty(vty, argv[idx_peer]->arg);
3212 if (!peer)
3213 return CMD_WARNING_CONFIG_FAILED;
3214
3215 as = strtoul(argv[idx_number]->arg, NULL, 10);
3216 ret = peer_local_as_set(peer, as, 0, 0);
3217 return bgp_vty_return(vty, ret);
3218 }
3219
3220 DEFUN (neighbor_local_as_no_prepend,
3221 neighbor_local_as_no_prepend_cmd,
3222 "neighbor <A.B.C.D|X:X::X:X|WORD> local-as (1-4294967295) no-prepend",
3223 NEIGHBOR_STR
3224 NEIGHBOR_ADDR_STR2
3225 "Specify a local-as number\n"
3226 "AS number used as local AS\n"
3227 "Do not prepend local-as to updates from ebgp peers\n")
3228 {
3229 int idx_peer = 1;
3230 int idx_number = 3;
3231 struct peer *peer;
3232 int ret;
3233 as_t as;
3234
3235 peer = peer_and_group_lookup_vty(vty, argv[idx_peer]->arg);
3236 if (!peer)
3237 return CMD_WARNING_CONFIG_FAILED;
3238
3239 as = strtoul(argv[idx_number]->arg, NULL, 10);
3240 ret = peer_local_as_set(peer, as, 1, 0);
3241 return bgp_vty_return(vty, ret);
3242 }
3243
3244 DEFUN (neighbor_local_as_no_prepend_replace_as,
3245 neighbor_local_as_no_prepend_replace_as_cmd,
3246 "neighbor <A.B.C.D|X:X::X:X|WORD> local-as (1-4294967295) no-prepend replace-as",
3247 NEIGHBOR_STR
3248 NEIGHBOR_ADDR_STR2
3249 "Specify a local-as number\n"
3250 "AS number used as local AS\n"
3251 "Do not prepend local-as to updates from ebgp peers\n"
3252 "Do not prepend local-as to updates from ibgp peers\n")
3253 {
3254 int idx_peer = 1;
3255 int idx_number = 3;
3256 struct peer *peer;
3257 int ret;
3258 as_t as;
3259
3260 peer = peer_and_group_lookup_vty(vty, argv[idx_peer]->arg);
3261 if (!peer)
3262 return CMD_WARNING_CONFIG_FAILED;
3263
3264 as = strtoul(argv[idx_number]->arg, NULL, 10);
3265 ret = peer_local_as_set(peer, as, 1, 1);
3266 return bgp_vty_return(vty, ret);
3267 }
3268
3269 DEFUN (no_neighbor_local_as,
3270 no_neighbor_local_as_cmd,
3271 "no neighbor <A.B.C.D|X:X::X:X|WORD> local-as [(1-4294967295) [no-prepend [replace-as]]]",
3272 NO_STR
3273 NEIGHBOR_STR
3274 NEIGHBOR_ADDR_STR2
3275 "Specify a local-as number\n"
3276 "AS number used as local AS\n"
3277 "Do not prepend local-as to updates from ebgp peers\n"
3278 "Do not prepend local-as to updates from ibgp peers\n")
3279 {
3280 int idx_peer = 2;
3281 struct peer *peer;
3282 int ret;
3283
3284 peer = peer_and_group_lookup_vty(vty, argv[idx_peer]->arg);
3285 if (!peer)
3286 return CMD_WARNING_CONFIG_FAILED;
3287
3288 ret = peer_local_as_unset(peer);
3289 return bgp_vty_return(vty, ret);
3290 }
3291
3292
3293 DEFUN (neighbor_solo,
3294 neighbor_solo_cmd,
3295 "neighbor <A.B.C.D|X:X::X:X|WORD> solo",
3296 NEIGHBOR_STR
3297 NEIGHBOR_ADDR_STR2
3298 "Solo peer - part of its own update group\n")
3299 {
3300 int idx_peer = 1;
3301 struct peer *peer;
3302 int ret;
3303
3304 peer = peer_and_group_lookup_vty(vty, argv[idx_peer]->arg);
3305 if (!peer)
3306 return CMD_WARNING_CONFIG_FAILED;
3307
3308 ret = update_group_adjust_soloness(peer, 1);
3309 return bgp_vty_return(vty, ret);
3310 }
3311
3312 DEFUN (no_neighbor_solo,
3313 no_neighbor_solo_cmd,
3314 "no neighbor <A.B.C.D|X:X::X:X|WORD> solo",
3315 NO_STR
3316 NEIGHBOR_STR
3317 NEIGHBOR_ADDR_STR2
3318 "Solo peer - part of its own update group\n")
3319 {
3320 int idx_peer = 2;
3321 struct peer *peer;
3322 int ret;
3323
3324 peer = peer_and_group_lookup_vty(vty, argv[idx_peer]->arg);
3325 if (!peer)
3326 return CMD_WARNING_CONFIG_FAILED;
3327
3328 ret = update_group_adjust_soloness(peer, 0);
3329 return bgp_vty_return(vty, ret);
3330 }
3331
3332 DEFUN (neighbor_password,
3333 neighbor_password_cmd,
3334 "neighbor <A.B.C.D|X:X::X:X|WORD> password LINE",
3335 NEIGHBOR_STR
3336 NEIGHBOR_ADDR_STR2
3337 "Set a password\n"
3338 "The password\n")
3339 {
3340 int idx_peer = 1;
3341 int idx_line = 3;
3342 struct peer *peer;
3343 int ret;
3344
3345 peer = peer_and_group_lookup_vty(vty, argv[idx_peer]->arg);
3346 if (!peer)
3347 return CMD_WARNING_CONFIG_FAILED;
3348
3349 ret = peer_password_set(peer, argv[idx_line]->arg);
3350 return bgp_vty_return(vty, ret);
3351 }
3352
3353 DEFUN (no_neighbor_password,
3354 no_neighbor_password_cmd,
3355 "no neighbor <A.B.C.D|X:X::X:X|WORD> password [LINE]",
3356 NO_STR
3357 NEIGHBOR_STR
3358 NEIGHBOR_ADDR_STR2
3359 "Set a password\n"
3360 "The password\n")
3361 {
3362 int idx_peer = 2;
3363 struct peer *peer;
3364 int ret;
3365
3366 peer = peer_and_group_lookup_vty(vty, argv[idx_peer]->arg);
3367 if (!peer)
3368 return CMD_WARNING_CONFIG_FAILED;
3369
3370 ret = peer_password_unset(peer);
3371 return bgp_vty_return(vty, ret);
3372 }
3373
3374 DEFUN (neighbor_activate,
3375 neighbor_activate_cmd,
3376 "neighbor <A.B.C.D|X:X::X:X|WORD> activate",
3377 NEIGHBOR_STR
3378 NEIGHBOR_ADDR_STR2
3379 "Enable the Address Family for this Neighbor\n")
3380 {
3381 int idx_peer = 1;
3382 int ret;
3383 struct peer *peer;
3384
3385 peer = peer_and_group_lookup_vty(vty, argv[idx_peer]->arg);
3386 if (!peer)
3387 return CMD_WARNING_CONFIG_FAILED;
3388
3389 ret = peer_activate(peer, bgp_node_afi(vty), bgp_node_safi(vty));
3390 return bgp_vty_return(vty, ret);
3391 }
3392
3393 ALIAS_HIDDEN(neighbor_activate, neighbor_activate_hidden_cmd,
3394 "neighbor <A.B.C.D|X:X::X:X|WORD> activate",
3395 NEIGHBOR_STR NEIGHBOR_ADDR_STR2
3396 "Enable the Address Family for this Neighbor\n")
3397
3398 DEFUN (no_neighbor_activate,
3399 no_neighbor_activate_cmd,
3400 "no neighbor <A.B.C.D|X:X::X:X|WORD> activate",
3401 NO_STR
3402 NEIGHBOR_STR
3403 NEIGHBOR_ADDR_STR2
3404 "Enable the Address Family for this Neighbor\n")
3405 {
3406 int idx_peer = 2;
3407 int ret;
3408 struct peer *peer;
3409
3410 /* Lookup peer. */
3411 peer = peer_and_group_lookup_vty(vty, argv[idx_peer]->arg);
3412 if (!peer)
3413 return CMD_WARNING_CONFIG_FAILED;
3414
3415 ret = peer_deactivate(peer, bgp_node_afi(vty), bgp_node_safi(vty));
3416 return bgp_vty_return(vty, ret);
3417 }
3418
3419 ALIAS_HIDDEN(no_neighbor_activate, no_neighbor_activate_hidden_cmd,
3420 "no neighbor <A.B.C.D|X:X::X:X|WORD> activate",
3421 NO_STR NEIGHBOR_STR NEIGHBOR_ADDR_STR2
3422 "Enable the Address Family for this Neighbor\n")
3423
3424 DEFUN (neighbor_set_peer_group,
3425 neighbor_set_peer_group_cmd,
3426 "neighbor <A.B.C.D|X:X::X:X|WORD> peer-group PGNAME",
3427 NEIGHBOR_STR
3428 NEIGHBOR_ADDR_STR2
3429 "Member of the peer-group\n"
3430 "Peer-group name\n")
3431 {
3432 VTY_DECLVAR_CONTEXT(bgp, bgp);
3433 int idx_peer = 1;
3434 int idx_word = 3;
3435 int ret;
3436 as_t as;
3437 union sockunion su;
3438 struct peer *peer;
3439 struct peer_group *group;
3440
3441 ret = str2sockunion(argv[idx_peer]->arg, &su);
3442 if (ret < 0) {
3443 peer = peer_lookup_by_conf_if(bgp, argv[idx_peer]->arg);
3444 if (!peer) {
3445 vty_out(vty, "%% Malformed address or name: %s\n",
3446 argv[idx_peer]->arg);
3447 return CMD_WARNING_CONFIG_FAILED;
3448 }
3449 } else {
3450 if (peer_address_self_check(bgp, &su)) {
3451 vty_out(vty,
3452 "%% Can not configure the local system as neighbor\n");
3453 return CMD_WARNING_CONFIG_FAILED;
3454 }
3455
3456 /* Disallow for dynamic neighbor. */
3457 peer = peer_lookup(bgp, &su);
3458 if (peer && peer_dynamic_neighbor(peer)) {
3459 vty_out(vty,
3460 "%% Operation not allowed on a dynamic neighbor\n");
3461 return CMD_WARNING_CONFIG_FAILED;
3462 }
3463 }
3464
3465 group = peer_group_lookup(bgp, argv[idx_word]->arg);
3466 if (!group) {
3467 vty_out(vty, "%% Configure the peer-group first\n");
3468 return CMD_WARNING_CONFIG_FAILED;
3469 }
3470
3471 ret = peer_group_bind(bgp, &su, peer, group, &as);
3472
3473 if (ret == BGP_ERR_PEER_GROUP_PEER_TYPE_DIFFERENT) {
3474 vty_out(vty,
3475 "%% Peer with AS %u cannot be in this peer-group, members must be all internal or all external\n",
3476 as);
3477 return CMD_WARNING_CONFIG_FAILED;
3478 }
3479
3480 return bgp_vty_return(vty, ret);
3481 }
3482
3483 ALIAS_HIDDEN(neighbor_set_peer_group, neighbor_set_peer_group_hidden_cmd,
3484 "neighbor <A.B.C.D|X:X::X:X|WORD> peer-group PGNAME",
3485 NEIGHBOR_STR NEIGHBOR_ADDR_STR2
3486 "Member of the peer-group\n"
3487 "Peer-group name\n")
3488
3489 DEFUN (no_neighbor_set_peer_group,
3490 no_neighbor_set_peer_group_cmd,
3491 "no neighbor <A.B.C.D|X:X::X:X|WORD> peer-group PGNAME",
3492 NO_STR
3493 NEIGHBOR_STR
3494 NEIGHBOR_ADDR_STR2
3495 "Member of the peer-group\n"
3496 "Peer-group name\n")
3497 {
3498 VTY_DECLVAR_CONTEXT(bgp, bgp);
3499 int idx_peer = 2;
3500 int idx_word = 4;
3501 int ret;
3502 struct peer *peer;
3503 struct peer_group *group;
3504
3505 peer = peer_lookup_vty(vty, argv[idx_peer]->arg);
3506 if (!peer)
3507 return CMD_WARNING_CONFIG_FAILED;
3508
3509 group = peer_group_lookup(bgp, argv[idx_word]->arg);
3510 if (!group) {
3511 vty_out(vty, "%% Configure the peer-group first\n");
3512 return CMD_WARNING_CONFIG_FAILED;
3513 }
3514
3515 ret = peer_delete(peer);
3516
3517 return bgp_vty_return(vty, ret);
3518 }
3519
3520 ALIAS_HIDDEN(no_neighbor_set_peer_group, no_neighbor_set_peer_group_hidden_cmd,
3521 "no neighbor <A.B.C.D|X:X::X:X|WORD> peer-group PGNAME",
3522 NO_STR NEIGHBOR_STR NEIGHBOR_ADDR_STR2
3523 "Member of the peer-group\n"
3524 "Peer-group name\n")
3525
3526 static int peer_flag_modify_vty(struct vty *vty, const char *ip_str,
3527 uint32_t flag, int set)
3528 {
3529 int ret;
3530 struct peer *peer;
3531
3532 peer = peer_and_group_lookup_vty(vty, ip_str);
3533 if (!peer)
3534 return CMD_WARNING_CONFIG_FAILED;
3535
3536 /*
3537 * If 'neighbor <interface>', then this is for directly connected peers,
3538 * we should not accept disable-connected-check.
3539 */
3540 if (peer->conf_if && (flag == PEER_FLAG_DISABLE_CONNECTED_CHECK)) {
3541 vty_out(vty,
3542 "%s is directly connected peer, cannot accept disable-"
3543 "connected-check\n",
3544 ip_str);
3545 return CMD_WARNING_CONFIG_FAILED;
3546 }
3547
3548 if (!set && flag == PEER_FLAG_SHUTDOWN)
3549 peer_tx_shutdown_message_unset(peer);
3550
3551 if (set)
3552 ret = peer_flag_set(peer, flag);
3553 else
3554 ret = peer_flag_unset(peer, flag);
3555
3556 return bgp_vty_return(vty, ret);
3557 }
3558
3559 static int peer_flag_set_vty(struct vty *vty, const char *ip_str, uint32_t flag)
3560 {
3561 return peer_flag_modify_vty(vty, ip_str, flag, 1);
3562 }
3563
3564 static int peer_flag_unset_vty(struct vty *vty, const char *ip_str,
3565 uint32_t flag)
3566 {
3567 return peer_flag_modify_vty(vty, ip_str, flag, 0);
3568 }
3569
3570 /* neighbor passive. */
3571 DEFUN (neighbor_passive,
3572 neighbor_passive_cmd,
3573 "neighbor <A.B.C.D|X:X::X:X|WORD> passive",
3574 NEIGHBOR_STR
3575 NEIGHBOR_ADDR_STR2
3576 "Don't send open messages to this neighbor\n")
3577 {
3578 int idx_peer = 1;
3579 return peer_flag_set_vty(vty, argv[idx_peer]->arg, PEER_FLAG_PASSIVE);
3580 }
3581
3582 DEFUN (no_neighbor_passive,
3583 no_neighbor_passive_cmd,
3584 "no neighbor <A.B.C.D|X:X::X:X|WORD> passive",
3585 NO_STR
3586 NEIGHBOR_STR
3587 NEIGHBOR_ADDR_STR2
3588 "Don't send open messages to this neighbor\n")
3589 {
3590 int idx_peer = 2;
3591 return peer_flag_unset_vty(vty, argv[idx_peer]->arg, PEER_FLAG_PASSIVE);
3592 }
3593
3594 /* neighbor shutdown. */
3595 DEFUN (neighbor_shutdown_msg,
3596 neighbor_shutdown_msg_cmd,
3597 "neighbor <A.B.C.D|X:X::X:X|WORD> shutdown message MSG...",
3598 NEIGHBOR_STR
3599 NEIGHBOR_ADDR_STR2
3600 "Administratively shut down this neighbor\n"
3601 "Add a shutdown message (draft-ietf-idr-shutdown-06)\n"
3602 "Shutdown message\n")
3603 {
3604 int idx_peer = 1;
3605
3606 if (argc >= 5) {
3607 struct peer *peer =
3608 peer_and_group_lookup_vty(vty, argv[idx_peer]->arg);
3609 char *message;
3610
3611 if (!peer)
3612 return CMD_WARNING_CONFIG_FAILED;
3613 message = argv_concat(argv, argc, 4);
3614 peer_tx_shutdown_message_set(peer, message);
3615 XFREE(MTYPE_TMP, message);
3616 }
3617
3618 return peer_flag_set_vty(vty, argv[idx_peer]->arg, PEER_FLAG_SHUTDOWN);
3619 }
3620
3621 ALIAS(neighbor_shutdown_msg, neighbor_shutdown_cmd,
3622 "neighbor <A.B.C.D|X:X::X:X|WORD> shutdown",
3623 NEIGHBOR_STR NEIGHBOR_ADDR_STR2
3624 "Administratively shut down this neighbor\n")
3625
3626 DEFUN (no_neighbor_shutdown_msg,
3627 no_neighbor_shutdown_msg_cmd,
3628 "no neighbor <A.B.C.D|X:X::X:X|WORD> shutdown message MSG...",
3629 NO_STR
3630 NEIGHBOR_STR
3631 NEIGHBOR_ADDR_STR2
3632 "Administratively shut down this neighbor\n"
3633 "Remove a shutdown message (draft-ietf-idr-shutdown-06)\n"
3634 "Shutdown message\n")
3635 {
3636 int idx_peer = 2;
3637
3638 return peer_flag_unset_vty(vty, argv[idx_peer]->arg,
3639 PEER_FLAG_SHUTDOWN);
3640 }
3641
3642 ALIAS(no_neighbor_shutdown_msg, no_neighbor_shutdown_cmd,
3643 "no neighbor <A.B.C.D|X:X::X:X|WORD> shutdown",
3644 NO_STR NEIGHBOR_STR NEIGHBOR_ADDR_STR2
3645 "Administratively shut down this neighbor\n")
3646
3647 /* neighbor capability dynamic. */
3648 DEFUN (neighbor_capability_dynamic,
3649 neighbor_capability_dynamic_cmd,
3650 "neighbor <A.B.C.D|X:X::X:X|WORD> capability dynamic",
3651 NEIGHBOR_STR
3652 NEIGHBOR_ADDR_STR2
3653 "Advertise capability to the peer\n"
3654 "Advertise dynamic capability to this neighbor\n")
3655 {
3656 int idx_peer = 1;
3657 return peer_flag_set_vty(vty, argv[idx_peer]->arg,
3658 PEER_FLAG_DYNAMIC_CAPABILITY);
3659 }
3660
3661 DEFUN (no_neighbor_capability_dynamic,
3662 no_neighbor_capability_dynamic_cmd,
3663 "no neighbor <A.B.C.D|X:X::X:X|WORD> capability dynamic",
3664 NO_STR
3665 NEIGHBOR_STR
3666 NEIGHBOR_ADDR_STR2
3667 "Advertise capability to the peer\n"
3668 "Advertise dynamic capability to this neighbor\n")
3669 {
3670 int idx_peer = 2;
3671 return peer_flag_unset_vty(vty, argv[idx_peer]->arg,
3672 PEER_FLAG_DYNAMIC_CAPABILITY);
3673 }
3674
3675 /* neighbor dont-capability-negotiate */
3676 DEFUN (neighbor_dont_capability_negotiate,
3677 neighbor_dont_capability_negotiate_cmd,
3678 "neighbor <A.B.C.D|X:X::X:X|WORD> dont-capability-negotiate",
3679 NEIGHBOR_STR
3680 NEIGHBOR_ADDR_STR2
3681 "Do not perform capability negotiation\n")
3682 {
3683 int idx_peer = 1;
3684 return peer_flag_set_vty(vty, argv[idx_peer]->arg,
3685 PEER_FLAG_DONT_CAPABILITY);
3686 }
3687
3688 DEFUN (no_neighbor_dont_capability_negotiate,
3689 no_neighbor_dont_capability_negotiate_cmd,
3690 "no neighbor <A.B.C.D|X:X::X:X|WORD> dont-capability-negotiate",
3691 NO_STR
3692 NEIGHBOR_STR
3693 NEIGHBOR_ADDR_STR2
3694 "Do not perform capability negotiation\n")
3695 {
3696 int idx_peer = 2;
3697 return peer_flag_unset_vty(vty, argv[idx_peer]->arg,
3698 PEER_FLAG_DONT_CAPABILITY);
3699 }
3700
3701 /* neighbor capability extended next hop encoding */
3702 DEFUN (neighbor_capability_enhe,
3703 neighbor_capability_enhe_cmd,
3704 "neighbor <A.B.C.D|X:X::X:X|WORD> capability extended-nexthop",
3705 NEIGHBOR_STR
3706 NEIGHBOR_ADDR_STR2
3707 "Advertise capability to the peer\n"
3708 "Advertise extended next-hop capability to the peer\n")
3709 {
3710 int idx_peer = 1;
3711 return peer_flag_set_vty(vty, argv[idx_peer]->arg,
3712 PEER_FLAG_CAPABILITY_ENHE);
3713 }
3714
3715 DEFUN (no_neighbor_capability_enhe,
3716 no_neighbor_capability_enhe_cmd,
3717 "no neighbor <A.B.C.D|X:X::X:X|WORD> capability extended-nexthop",
3718 NO_STR
3719 NEIGHBOR_STR
3720 NEIGHBOR_ADDR_STR2
3721 "Advertise capability to the peer\n"
3722 "Advertise extended next-hop capability to the peer\n")
3723 {
3724 int idx_peer = 2;
3725 return peer_flag_unset_vty(vty, argv[idx_peer]->arg,
3726 PEER_FLAG_CAPABILITY_ENHE);
3727 }
3728
3729 static int peer_af_flag_modify_vty(struct vty *vty, const char *peer_str,
3730 afi_t afi, safi_t safi, uint32_t flag,
3731 int set)
3732 {
3733 int ret;
3734 struct peer *peer;
3735
3736 peer = peer_and_group_lookup_vty(vty, peer_str);
3737 if (!peer)
3738 return CMD_WARNING_CONFIG_FAILED;
3739
3740 if (set)
3741 ret = peer_af_flag_set(peer, afi, safi, flag);
3742 else
3743 ret = peer_af_flag_unset(peer, afi, safi, flag);
3744
3745 return bgp_vty_return(vty, ret);
3746 }
3747
3748 static int peer_af_flag_set_vty(struct vty *vty, const char *peer_str,
3749 afi_t afi, safi_t safi, uint32_t flag)
3750 {
3751 return peer_af_flag_modify_vty(vty, peer_str, afi, safi, flag, 1);
3752 }
3753
3754 static int peer_af_flag_unset_vty(struct vty *vty, const char *peer_str,
3755 afi_t afi, safi_t safi, uint32_t flag)
3756 {
3757 return peer_af_flag_modify_vty(vty, peer_str, afi, safi, flag, 0);
3758 }
3759
3760 /* neighbor capability orf prefix-list. */
3761 DEFUN (neighbor_capability_orf_prefix,
3762 neighbor_capability_orf_prefix_cmd,
3763 "neighbor <A.B.C.D|X:X::X:X|WORD> capability orf prefix-list <both|send|receive>",
3764 NEIGHBOR_STR
3765 NEIGHBOR_ADDR_STR2
3766 "Advertise capability to the peer\n"
3767 "Advertise ORF capability to the peer\n"
3768 "Advertise prefixlist ORF capability to this neighbor\n"
3769 "Capability to SEND and RECEIVE the ORF to/from this neighbor\n"
3770 "Capability to RECEIVE the ORF from this neighbor\n"
3771 "Capability to SEND the ORF to this neighbor\n")
3772 {
3773 int idx_peer = 1;
3774 int idx_send_recv = 5;
3775 uint16_t flag = 0;
3776
3777 if (strmatch(argv[idx_send_recv]->text, "send"))
3778 flag = PEER_FLAG_ORF_PREFIX_SM;
3779 else if (strmatch(argv[idx_send_recv]->text, "receive"))
3780 flag = PEER_FLAG_ORF_PREFIX_RM;
3781 else if (strmatch(argv[idx_send_recv]->text, "both"))
3782 flag = PEER_FLAG_ORF_PREFIX_SM | PEER_FLAG_ORF_PREFIX_RM;
3783 else {
3784 vty_out(vty, "%% BGP invalid orf prefix-list option\n");
3785 return CMD_WARNING_CONFIG_FAILED;
3786 }
3787
3788 return peer_af_flag_set_vty(vty, argv[idx_peer]->arg, bgp_node_afi(vty),
3789 bgp_node_safi(vty), flag);
3790 }
3791
3792 ALIAS_HIDDEN(
3793 neighbor_capability_orf_prefix,
3794 neighbor_capability_orf_prefix_hidden_cmd,
3795 "neighbor <A.B.C.D|X:X::X:X|WORD> capability orf prefix-list <both|send|receive>",
3796 NEIGHBOR_STR NEIGHBOR_ADDR_STR2
3797 "Advertise capability to the peer\n"
3798 "Advertise ORF capability to the peer\n"
3799 "Advertise prefixlist ORF capability to this neighbor\n"
3800 "Capability to SEND and RECEIVE the ORF to/from this neighbor\n"
3801 "Capability to RECEIVE the ORF from this neighbor\n"
3802 "Capability to SEND the ORF to this neighbor\n")
3803
3804 DEFUN (no_neighbor_capability_orf_prefix,
3805 no_neighbor_capability_orf_prefix_cmd,
3806 "no neighbor <A.B.C.D|X:X::X:X|WORD> capability orf prefix-list <both|send|receive>",
3807 NO_STR
3808 NEIGHBOR_STR
3809 NEIGHBOR_ADDR_STR2
3810 "Advertise capability to the peer\n"
3811 "Advertise ORF capability to the peer\n"
3812 "Advertise prefixlist ORF capability to this neighbor\n"
3813 "Capability to SEND and RECEIVE the ORF to/from this neighbor\n"
3814 "Capability to RECEIVE the ORF from this neighbor\n"
3815 "Capability to SEND the ORF to this neighbor\n")
3816 {
3817 int idx_peer = 2;
3818 int idx_send_recv = 6;
3819 uint16_t flag = 0;
3820
3821 if (strmatch(argv[idx_send_recv]->text, "send"))
3822 flag = PEER_FLAG_ORF_PREFIX_SM;
3823 else if (strmatch(argv[idx_send_recv]->text, "receive"))
3824 flag = PEER_FLAG_ORF_PREFIX_RM;
3825 else if (strmatch(argv[idx_send_recv]->text, "both"))
3826 flag = PEER_FLAG_ORF_PREFIX_SM | PEER_FLAG_ORF_PREFIX_RM;
3827 else {
3828 vty_out(vty, "%% BGP invalid orf prefix-list option\n");
3829 return CMD_WARNING_CONFIG_FAILED;
3830 }
3831
3832 return peer_af_flag_unset_vty(vty, argv[idx_peer]->arg,
3833 bgp_node_afi(vty), bgp_node_safi(vty),
3834 flag);
3835 }
3836
3837 ALIAS_HIDDEN(
3838 no_neighbor_capability_orf_prefix,
3839 no_neighbor_capability_orf_prefix_hidden_cmd,
3840 "no neighbor <A.B.C.D|X:X::X:X|WORD> capability orf prefix-list <both|send|receive>",
3841 NO_STR NEIGHBOR_STR 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 /* neighbor next-hop-self. */
3850 DEFUN (neighbor_nexthop_self,
3851 neighbor_nexthop_self_cmd,
3852 "neighbor <A.B.C.D|X:X::X:X|WORD> next-hop-self",
3853 NEIGHBOR_STR
3854 NEIGHBOR_ADDR_STR2
3855 "Disable the next hop calculation for this neighbor\n")
3856 {
3857 int idx_peer = 1;
3858 return peer_af_flag_set_vty(vty, argv[idx_peer]->arg, bgp_node_afi(vty),
3859 bgp_node_safi(vty), PEER_FLAG_NEXTHOP_SELF);
3860 }
3861
3862 ALIAS_HIDDEN(neighbor_nexthop_self, neighbor_nexthop_self_hidden_cmd,
3863 "neighbor <A.B.C.D|X:X::X:X|WORD> next-hop-self",
3864 NEIGHBOR_STR NEIGHBOR_ADDR_STR2
3865 "Disable the next hop calculation for this neighbor\n")
3866
3867 /* neighbor next-hop-self. */
3868 DEFUN (neighbor_nexthop_self_force,
3869 neighbor_nexthop_self_force_cmd,
3870 "neighbor <A.B.C.D|X:X::X:X|WORD> next-hop-self force",
3871 NEIGHBOR_STR
3872 NEIGHBOR_ADDR_STR2
3873 "Disable the next hop calculation for this neighbor\n"
3874 "Set the next hop to self for reflected routes\n")
3875 {
3876 int idx_peer = 1;
3877 return peer_af_flag_set_vty(vty, argv[idx_peer]->arg, bgp_node_afi(vty),
3878 bgp_node_safi(vty),
3879 PEER_FLAG_FORCE_NEXTHOP_SELF);
3880 }
3881
3882 ALIAS_HIDDEN(neighbor_nexthop_self_force,
3883 neighbor_nexthop_self_force_hidden_cmd,
3884 "neighbor <A.B.C.D|X:X::X:X|WORD> next-hop-self force",
3885 NEIGHBOR_STR NEIGHBOR_ADDR_STR2
3886 "Disable the next hop calculation for this neighbor\n"
3887 "Set the next hop to self for reflected routes\n")
3888
3889 ALIAS_HIDDEN(neighbor_nexthop_self_force,
3890 neighbor_nexthop_self_all_hidden_cmd,
3891 "neighbor <A.B.C.D|X:X::X:X|WORD> next-hop-self all",
3892 NEIGHBOR_STR NEIGHBOR_ADDR_STR2
3893 "Disable the next hop calculation for this neighbor\n"
3894 "Set the next hop to self for reflected routes\n")
3895
3896 DEFUN (no_neighbor_nexthop_self,
3897 no_neighbor_nexthop_self_cmd,
3898 "no neighbor <A.B.C.D|X:X::X:X|WORD> next-hop-self",
3899 NO_STR
3900 NEIGHBOR_STR
3901 NEIGHBOR_ADDR_STR2
3902 "Disable the next hop calculation for this neighbor\n")
3903 {
3904 int idx_peer = 2;
3905 return peer_af_flag_unset_vty(vty, argv[idx_peer]->arg,
3906 bgp_node_afi(vty), bgp_node_safi(vty),
3907 PEER_FLAG_NEXTHOP_SELF);
3908 }
3909
3910 ALIAS_HIDDEN(no_neighbor_nexthop_self, no_neighbor_nexthop_self_hidden_cmd,
3911 "no neighbor <A.B.C.D|X:X::X:X|WORD> next-hop-self",
3912 NO_STR NEIGHBOR_STR NEIGHBOR_ADDR_STR2
3913 "Disable the next hop calculation for this neighbor\n")
3914
3915 DEFUN (no_neighbor_nexthop_self_force,
3916 no_neighbor_nexthop_self_force_cmd,
3917 "no neighbor <A.B.C.D|X:X::X:X|WORD> next-hop-self force",
3918 NO_STR
3919 NEIGHBOR_STR
3920 NEIGHBOR_ADDR_STR2
3921 "Disable the next hop calculation for this neighbor\n"
3922 "Set the next hop to self for reflected routes\n")
3923 {
3924 int idx_peer = 2;
3925 return peer_af_flag_unset_vty(vty, argv[idx_peer]->arg,
3926 bgp_node_afi(vty), bgp_node_safi(vty),
3927 PEER_FLAG_FORCE_NEXTHOP_SELF);
3928 }
3929
3930 ALIAS_HIDDEN(no_neighbor_nexthop_self_force,
3931 no_neighbor_nexthop_self_force_hidden_cmd,
3932 "no neighbor <A.B.C.D|X:X::X:X|WORD> next-hop-self force",
3933 NO_STR NEIGHBOR_STR NEIGHBOR_ADDR_STR2
3934 "Disable the next hop calculation for this neighbor\n"
3935 "Set the next hop to self for reflected routes\n")
3936
3937 ALIAS_HIDDEN(no_neighbor_nexthop_self_force,
3938 no_neighbor_nexthop_self_all_hidden_cmd,
3939 "no neighbor <A.B.C.D|X:X::X:X|WORD> next-hop-self all",
3940 NO_STR NEIGHBOR_STR NEIGHBOR_ADDR_STR2
3941 "Disable the next hop calculation for this neighbor\n"
3942 "Set the next hop to self for reflected routes\n")
3943
3944 /* neighbor as-override */
3945 DEFUN (neighbor_as_override,
3946 neighbor_as_override_cmd,
3947 "neighbor <A.B.C.D|X:X::X:X|WORD> as-override",
3948 NEIGHBOR_STR
3949 NEIGHBOR_ADDR_STR2
3950 "Override ASNs in outbound updates if aspath equals remote-as\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), PEER_FLAG_AS_OVERRIDE);
3955 }
3956
3957 ALIAS_HIDDEN(neighbor_as_override, neighbor_as_override_hidden_cmd,
3958 "neighbor <A.B.C.D|X:X::X:X|WORD> as-override",
3959 NEIGHBOR_STR NEIGHBOR_ADDR_STR2
3960 "Override ASNs in outbound updates if aspath equals remote-as\n")
3961
3962 DEFUN (no_neighbor_as_override,
3963 no_neighbor_as_override_cmd,
3964 "no neighbor <A.B.C.D|X:X::X:X|WORD> as-override",
3965 NO_STR
3966 NEIGHBOR_STR
3967 NEIGHBOR_ADDR_STR2
3968 "Override ASNs in outbound updates if aspath equals remote-as\n")
3969 {
3970 int idx_peer = 2;
3971 return peer_af_flag_unset_vty(vty, argv[idx_peer]->arg,
3972 bgp_node_afi(vty), bgp_node_safi(vty),
3973 PEER_FLAG_AS_OVERRIDE);
3974 }
3975
3976 ALIAS_HIDDEN(no_neighbor_as_override, no_neighbor_as_override_hidden_cmd,
3977 "no neighbor <A.B.C.D|X:X::X:X|WORD> as-override",
3978 NO_STR NEIGHBOR_STR NEIGHBOR_ADDR_STR2
3979 "Override ASNs in outbound updates if aspath equals remote-as\n")
3980
3981 /* neighbor remove-private-AS. */
3982 DEFUN (neighbor_remove_private_as,
3983 neighbor_remove_private_as_cmd,
3984 "neighbor <A.B.C.D|X:X::X:X|WORD> remove-private-AS",
3985 NEIGHBOR_STR
3986 NEIGHBOR_ADDR_STR2
3987 "Remove private ASNs in outbound updates\n")
3988 {
3989 int idx_peer = 1;
3990 return peer_af_flag_set_vty(vty, argv[idx_peer]->arg, bgp_node_afi(vty),
3991 bgp_node_safi(vty),
3992 PEER_FLAG_REMOVE_PRIVATE_AS);
3993 }
3994
3995 ALIAS_HIDDEN(neighbor_remove_private_as, neighbor_remove_private_as_hidden_cmd,
3996 "neighbor <A.B.C.D|X:X::X:X|WORD> remove-private-AS",
3997 NEIGHBOR_STR NEIGHBOR_ADDR_STR2
3998 "Remove private ASNs in outbound updates\n")
3999
4000 DEFUN (neighbor_remove_private_as_all,
4001 neighbor_remove_private_as_all_cmd,
4002 "neighbor <A.B.C.D|X:X::X:X|WORD> remove-private-AS all",
4003 NEIGHBOR_STR
4004 NEIGHBOR_ADDR_STR2
4005 "Remove private ASNs in outbound updates\n"
4006 "Apply to all AS numbers\n")
4007 {
4008 int idx_peer = 1;
4009 return peer_af_flag_set_vty(vty, argv[idx_peer]->arg, bgp_node_afi(vty),
4010 bgp_node_safi(vty),
4011 PEER_FLAG_REMOVE_PRIVATE_AS_ALL);
4012 }
4013
4014 ALIAS_HIDDEN(neighbor_remove_private_as_all,
4015 neighbor_remove_private_as_all_hidden_cmd,
4016 "neighbor <A.B.C.D|X:X::X:X|WORD> remove-private-AS all",
4017 NEIGHBOR_STR NEIGHBOR_ADDR_STR2
4018 "Remove private ASNs in outbound updates\n"
4019 "Apply to all AS numbers")
4020
4021 DEFUN (neighbor_remove_private_as_replace_as,
4022 neighbor_remove_private_as_replace_as_cmd,
4023 "neighbor <A.B.C.D|X:X::X:X|WORD> remove-private-AS replace-AS",
4024 NEIGHBOR_STR
4025 NEIGHBOR_ADDR_STR2
4026 "Remove private ASNs in outbound updates\n"
4027 "Replace private ASNs with our ASN in outbound updates\n")
4028 {
4029 int idx_peer = 1;
4030 return peer_af_flag_set_vty(vty, argv[idx_peer]->arg, bgp_node_afi(vty),
4031 bgp_node_safi(vty),
4032 PEER_FLAG_REMOVE_PRIVATE_AS_REPLACE);
4033 }
4034
4035 ALIAS_HIDDEN(neighbor_remove_private_as_replace_as,
4036 neighbor_remove_private_as_replace_as_hidden_cmd,
4037 "neighbor <A.B.C.D|X:X::X:X|WORD> remove-private-AS replace-AS",
4038 NEIGHBOR_STR NEIGHBOR_ADDR_STR2
4039 "Remove private ASNs in outbound updates\n"
4040 "Replace private ASNs with our ASN in outbound updates\n")
4041
4042 DEFUN (neighbor_remove_private_as_all_replace_as,
4043 neighbor_remove_private_as_all_replace_as_cmd,
4044 "neighbor <A.B.C.D|X:X::X:X|WORD> remove-private-AS all replace-AS",
4045 NEIGHBOR_STR
4046 NEIGHBOR_ADDR_STR2
4047 "Remove private ASNs in outbound updates\n"
4048 "Apply to all AS numbers\n"
4049 "Replace private ASNs with our ASN in outbound updates\n")
4050 {
4051 int idx_peer = 1;
4052 return peer_af_flag_set_vty(vty, argv[idx_peer]->arg, bgp_node_afi(vty),
4053 bgp_node_safi(vty),
4054 PEER_FLAG_REMOVE_PRIVATE_AS_ALL_REPLACE);
4055 }
4056
4057 ALIAS_HIDDEN(
4058 neighbor_remove_private_as_all_replace_as,
4059 neighbor_remove_private_as_all_replace_as_hidden_cmd,
4060 "neighbor <A.B.C.D|X:X::X:X|WORD> remove-private-AS all replace-AS",
4061 NEIGHBOR_STR NEIGHBOR_ADDR_STR2
4062 "Remove private ASNs in outbound updates\n"
4063 "Apply to all AS numbers\n"
4064 "Replace private ASNs with our ASN in outbound updates\n")
4065
4066 DEFUN (no_neighbor_remove_private_as,
4067 no_neighbor_remove_private_as_cmd,
4068 "no neighbor <A.B.C.D|X:X::X:X|WORD> remove-private-AS",
4069 NO_STR
4070 NEIGHBOR_STR
4071 NEIGHBOR_ADDR_STR2
4072 "Remove private ASNs in outbound updates\n")
4073 {
4074 int idx_peer = 2;
4075 return peer_af_flag_unset_vty(vty, argv[idx_peer]->arg,
4076 bgp_node_afi(vty), bgp_node_safi(vty),
4077 PEER_FLAG_REMOVE_PRIVATE_AS);
4078 }
4079
4080 ALIAS_HIDDEN(no_neighbor_remove_private_as,
4081 no_neighbor_remove_private_as_hidden_cmd,
4082 "no neighbor <A.B.C.D|X:X::X:X|WORD> remove-private-AS",
4083 NO_STR NEIGHBOR_STR NEIGHBOR_ADDR_STR2
4084 "Remove private ASNs in outbound updates\n")
4085
4086 DEFUN (no_neighbor_remove_private_as_all,
4087 no_neighbor_remove_private_as_all_cmd,
4088 "no neighbor <A.B.C.D|X:X::X:X|WORD> remove-private-AS all",
4089 NO_STR
4090 NEIGHBOR_STR
4091 NEIGHBOR_ADDR_STR2
4092 "Remove private ASNs in outbound updates\n"
4093 "Apply to all AS numbers\n")
4094 {
4095 int idx_peer = 2;
4096 return peer_af_flag_unset_vty(vty, argv[idx_peer]->arg,
4097 bgp_node_afi(vty), bgp_node_safi(vty),
4098 PEER_FLAG_REMOVE_PRIVATE_AS_ALL);
4099 }
4100
4101 ALIAS_HIDDEN(no_neighbor_remove_private_as_all,
4102 no_neighbor_remove_private_as_all_hidden_cmd,
4103 "no neighbor <A.B.C.D|X:X::X:X|WORD> remove-private-AS all",
4104 NO_STR NEIGHBOR_STR NEIGHBOR_ADDR_STR2
4105 "Remove private ASNs in outbound updates\n"
4106 "Apply to all AS numbers\n")
4107
4108 DEFUN (no_neighbor_remove_private_as_replace_as,
4109 no_neighbor_remove_private_as_replace_as_cmd,
4110 "no neighbor <A.B.C.D|X:X::X:X|WORD> remove-private-AS replace-AS",
4111 NO_STR
4112 NEIGHBOR_STR
4113 NEIGHBOR_ADDR_STR2
4114 "Remove private ASNs in outbound updates\n"
4115 "Replace private ASNs with our ASN in outbound updates\n")
4116 {
4117 int idx_peer = 2;
4118 return peer_af_flag_unset_vty(vty, argv[idx_peer]->arg,
4119 bgp_node_afi(vty), bgp_node_safi(vty),
4120 PEER_FLAG_REMOVE_PRIVATE_AS_REPLACE);
4121 }
4122
4123 ALIAS_HIDDEN(no_neighbor_remove_private_as_replace_as,
4124 no_neighbor_remove_private_as_replace_as_hidden_cmd,
4125 "no neighbor <A.B.C.D|X:X::X:X|WORD> remove-private-AS replace-AS",
4126 NO_STR NEIGHBOR_STR NEIGHBOR_ADDR_STR2
4127 "Remove private ASNs in outbound updates\n"
4128 "Replace private ASNs with our ASN in outbound updates\n")
4129
4130 DEFUN (no_neighbor_remove_private_as_all_replace_as,
4131 no_neighbor_remove_private_as_all_replace_as_cmd,
4132 "no neighbor <A.B.C.D|X:X::X:X|WORD> remove-private-AS all replace-AS",
4133 NO_STR
4134 NEIGHBOR_STR
4135 NEIGHBOR_ADDR_STR2
4136 "Remove private ASNs in outbound updates\n"
4137 "Apply to all AS numbers\n"
4138 "Replace private ASNs with our ASN in outbound updates\n")
4139 {
4140 int idx_peer = 2;
4141 return peer_af_flag_unset_vty(vty, argv[idx_peer]->arg,
4142 bgp_node_afi(vty), bgp_node_safi(vty),
4143 PEER_FLAG_REMOVE_PRIVATE_AS_ALL_REPLACE);
4144 }
4145
4146 ALIAS_HIDDEN(
4147 no_neighbor_remove_private_as_all_replace_as,
4148 no_neighbor_remove_private_as_all_replace_as_hidden_cmd,
4149 "no neighbor <A.B.C.D|X:X::X:X|WORD> remove-private-AS all replace-AS",
4150 NO_STR NEIGHBOR_STR NEIGHBOR_ADDR_STR2
4151 "Remove private ASNs in outbound updates\n"
4152 "Apply to all AS numbers\n"
4153 "Replace private ASNs with our ASN in outbound updates\n")
4154
4155
4156 /* neighbor send-community. */
4157 DEFUN (neighbor_send_community,
4158 neighbor_send_community_cmd,
4159 "neighbor <A.B.C.D|X:X::X:X|WORD> send-community",
4160 NEIGHBOR_STR
4161 NEIGHBOR_ADDR_STR2
4162 "Send Community attribute to this neighbor\n")
4163 {
4164 int idx_peer = 1;
4165
4166 return peer_af_flag_set_vty(vty, argv[idx_peer]->arg, bgp_node_afi(vty),
4167 bgp_node_safi(vty),
4168 PEER_FLAG_SEND_COMMUNITY);
4169 }
4170
4171 ALIAS_HIDDEN(neighbor_send_community, neighbor_send_community_hidden_cmd,
4172 "neighbor <A.B.C.D|X:X::X:X|WORD> send-community",
4173 NEIGHBOR_STR NEIGHBOR_ADDR_STR2
4174 "Send Community attribute to this neighbor\n")
4175
4176 DEFUN (no_neighbor_send_community,
4177 no_neighbor_send_community_cmd,
4178 "no neighbor <A.B.C.D|X:X::X:X|WORD> send-community",
4179 NO_STR
4180 NEIGHBOR_STR
4181 NEIGHBOR_ADDR_STR2
4182 "Send Community attribute to this neighbor\n")
4183 {
4184 int idx_peer = 2;
4185
4186 return peer_af_flag_unset_vty(vty, argv[idx_peer]->arg,
4187 bgp_node_afi(vty), bgp_node_safi(vty),
4188 PEER_FLAG_SEND_COMMUNITY);
4189 }
4190
4191 ALIAS_HIDDEN(no_neighbor_send_community, no_neighbor_send_community_hidden_cmd,
4192 "no neighbor <A.B.C.D|X:X::X:X|WORD> send-community",
4193 NO_STR NEIGHBOR_STR NEIGHBOR_ADDR_STR2
4194 "Send Community attribute to this neighbor\n")
4195
4196 /* neighbor send-community extended. */
4197 DEFUN (neighbor_send_community_type,
4198 neighbor_send_community_type_cmd,
4199 "neighbor <A.B.C.D|X:X::X:X|WORD> send-community <both|all|extended|standard|large>",
4200 NEIGHBOR_STR
4201 NEIGHBOR_ADDR_STR2
4202 "Send Community attribute to this neighbor\n"
4203 "Send Standard and Extended Community attributes\n"
4204 "Send Standard, Large and Extended Community attributes\n"
4205 "Send Extended Community attributes\n"
4206 "Send Standard Community attributes\n"
4207 "Send Large Community attributes\n")
4208 {
4209 int idx_peer = 1;
4210 uint32_t flag = 0;
4211 const char *type = argv[argc - 1]->text;
4212
4213 if (strmatch(type, "standard")) {
4214 SET_FLAG(flag, PEER_FLAG_SEND_COMMUNITY);
4215 } else if (strmatch(type, "extended")) {
4216 SET_FLAG(flag, PEER_FLAG_SEND_EXT_COMMUNITY);
4217 } else if (strmatch(type, "large")) {
4218 SET_FLAG(flag, PEER_FLAG_SEND_LARGE_COMMUNITY);
4219 } else if (strmatch(type, "both")) {
4220 SET_FLAG(flag, PEER_FLAG_SEND_COMMUNITY);
4221 SET_FLAG(flag, PEER_FLAG_SEND_EXT_COMMUNITY);
4222 } else { /* if (strmatch(type, "all")) */
4223 SET_FLAG(flag, PEER_FLAG_SEND_COMMUNITY);
4224 SET_FLAG(flag, PEER_FLAG_SEND_EXT_COMMUNITY);
4225 SET_FLAG(flag, PEER_FLAG_SEND_LARGE_COMMUNITY);
4226 }
4227
4228 return peer_af_flag_set_vty(vty, argv[idx_peer]->arg, bgp_node_afi(vty),
4229 bgp_node_safi(vty), flag);
4230 }
4231
4232 ALIAS_HIDDEN(
4233 neighbor_send_community_type, neighbor_send_community_type_hidden_cmd,
4234 "neighbor <A.B.C.D|X:X::X:X|WORD> send-community <both|all|extended|standard|large>",
4235 NEIGHBOR_STR NEIGHBOR_ADDR_STR2
4236 "Send Community attribute to this neighbor\n"
4237 "Send Standard and Extended Community attributes\n"
4238 "Send Standard, Large and Extended Community attributes\n"
4239 "Send Extended Community attributes\n"
4240 "Send Standard Community attributes\n"
4241 "Send Large Community attributes\n")
4242
4243 DEFUN (no_neighbor_send_community_type,
4244 no_neighbor_send_community_type_cmd,
4245 "no neighbor <A.B.C.D|X:X::X:X|WORD> send-community <both|all|extended|standard|large>",
4246 NO_STR
4247 NEIGHBOR_STR
4248 NEIGHBOR_ADDR_STR2
4249 "Send Community attribute to this neighbor\n"
4250 "Send Standard and Extended Community attributes\n"
4251 "Send Standard, Large and Extended Community attributes\n"
4252 "Send Extended Community attributes\n"
4253 "Send Standard Community attributes\n"
4254 "Send Large Community attributes\n")
4255 {
4256 int idx_peer = 2;
4257 uint32_t flag = 0;
4258 const char *type = argv[argc - 1]->text;
4259
4260 if (strmatch(type, "standard")) {
4261 SET_FLAG(flag, PEER_FLAG_SEND_COMMUNITY);
4262 } else if (strmatch(type, "extended")) {
4263 SET_FLAG(flag, PEER_FLAG_SEND_EXT_COMMUNITY);
4264 } else if (strmatch(type, "large")) {
4265 SET_FLAG(flag, PEER_FLAG_SEND_LARGE_COMMUNITY);
4266 } else if (strmatch(type, "both")) {
4267 SET_FLAG(flag, PEER_FLAG_SEND_COMMUNITY);
4268 SET_FLAG(flag, PEER_FLAG_SEND_EXT_COMMUNITY);
4269 } else { /* if (strmatch(type, "all")) */
4270 SET_FLAG(flag, PEER_FLAG_SEND_COMMUNITY);
4271 SET_FLAG(flag, PEER_FLAG_SEND_EXT_COMMUNITY);
4272 SET_FLAG(flag, PEER_FLAG_SEND_LARGE_COMMUNITY);
4273 }
4274
4275 return peer_af_flag_unset_vty(vty, argv[idx_peer]->arg,
4276 bgp_node_afi(vty), bgp_node_safi(vty),
4277 flag);
4278 }
4279
4280 ALIAS_HIDDEN(
4281 no_neighbor_send_community_type,
4282 no_neighbor_send_community_type_hidden_cmd,
4283 "no neighbor <A.B.C.D|X:X::X:X|WORD> send-community <both|all|extended|standard|large>",
4284 NO_STR NEIGHBOR_STR NEIGHBOR_ADDR_STR2
4285 "Send Community attribute to this neighbor\n"
4286 "Send Standard and Extended Community attributes\n"
4287 "Send Standard, Large and Extended Community attributes\n"
4288 "Send Extended Community attributes\n"
4289 "Send Standard Community attributes\n"
4290 "Send Large Community attributes\n")
4291
4292 /* neighbor soft-reconfig. */
4293 DEFUN (neighbor_soft_reconfiguration,
4294 neighbor_soft_reconfiguration_cmd,
4295 "neighbor <A.B.C.D|X:X::X:X|WORD> soft-reconfiguration inbound",
4296 NEIGHBOR_STR
4297 NEIGHBOR_ADDR_STR2
4298 "Per neighbor soft reconfiguration\n"
4299 "Allow inbound soft reconfiguration for this neighbor\n")
4300 {
4301 int idx_peer = 1;
4302 return peer_af_flag_set_vty(vty, argv[idx_peer]->arg, bgp_node_afi(vty),
4303 bgp_node_safi(vty),
4304 PEER_FLAG_SOFT_RECONFIG);
4305 }
4306
4307 ALIAS_HIDDEN(neighbor_soft_reconfiguration,
4308 neighbor_soft_reconfiguration_hidden_cmd,
4309 "neighbor <A.B.C.D|X:X::X:X|WORD> soft-reconfiguration inbound",
4310 NEIGHBOR_STR NEIGHBOR_ADDR_STR2
4311 "Per neighbor soft reconfiguration\n"
4312 "Allow inbound soft reconfiguration for this neighbor\n")
4313
4314 DEFUN (no_neighbor_soft_reconfiguration,
4315 no_neighbor_soft_reconfiguration_cmd,
4316 "no neighbor <A.B.C.D|X:X::X:X|WORD> soft-reconfiguration inbound",
4317 NO_STR
4318 NEIGHBOR_STR
4319 NEIGHBOR_ADDR_STR2
4320 "Per neighbor soft reconfiguration\n"
4321 "Allow inbound soft reconfiguration for this neighbor\n")
4322 {
4323 int idx_peer = 2;
4324 return peer_af_flag_unset_vty(vty, argv[idx_peer]->arg,
4325 bgp_node_afi(vty), bgp_node_safi(vty),
4326 PEER_FLAG_SOFT_RECONFIG);
4327 }
4328
4329 ALIAS_HIDDEN(no_neighbor_soft_reconfiguration,
4330 no_neighbor_soft_reconfiguration_hidden_cmd,
4331 "no neighbor <A.B.C.D|X:X::X:X|WORD> soft-reconfiguration inbound",
4332 NO_STR NEIGHBOR_STR NEIGHBOR_ADDR_STR2
4333 "Per neighbor soft reconfiguration\n"
4334 "Allow inbound soft reconfiguration for this neighbor\n")
4335
4336 DEFUN (neighbor_route_reflector_client,
4337 neighbor_route_reflector_client_cmd,
4338 "neighbor <A.B.C.D|X:X::X:X|WORD> route-reflector-client",
4339 NEIGHBOR_STR
4340 NEIGHBOR_ADDR_STR2
4341 "Configure a neighbor as Route Reflector client\n")
4342 {
4343 int idx_peer = 1;
4344 struct peer *peer;
4345
4346
4347 peer = peer_and_group_lookup_vty(vty, argv[idx_peer]->arg);
4348 if (!peer)
4349 return CMD_WARNING_CONFIG_FAILED;
4350
4351 return peer_af_flag_set_vty(vty, argv[idx_peer]->arg, bgp_node_afi(vty),
4352 bgp_node_safi(vty),
4353 PEER_FLAG_REFLECTOR_CLIENT);
4354 }
4355
4356 ALIAS_HIDDEN(neighbor_route_reflector_client,
4357 neighbor_route_reflector_client_hidden_cmd,
4358 "neighbor <A.B.C.D|X:X::X:X|WORD> route-reflector-client",
4359 NEIGHBOR_STR NEIGHBOR_ADDR_STR2
4360 "Configure a neighbor as Route Reflector client\n")
4361
4362 DEFUN (no_neighbor_route_reflector_client,
4363 no_neighbor_route_reflector_client_cmd,
4364 "no neighbor <A.B.C.D|X:X::X:X|WORD> route-reflector-client",
4365 NO_STR
4366 NEIGHBOR_STR
4367 NEIGHBOR_ADDR_STR2
4368 "Configure a neighbor as Route Reflector client\n")
4369 {
4370 int idx_peer = 2;
4371 return peer_af_flag_unset_vty(vty, argv[idx_peer]->arg,
4372 bgp_node_afi(vty), bgp_node_safi(vty),
4373 PEER_FLAG_REFLECTOR_CLIENT);
4374 }
4375
4376 ALIAS_HIDDEN(no_neighbor_route_reflector_client,
4377 no_neighbor_route_reflector_client_hidden_cmd,
4378 "no neighbor <A.B.C.D|X:X::X:X|WORD> route-reflector-client",
4379 NO_STR NEIGHBOR_STR NEIGHBOR_ADDR_STR2
4380 "Configure a neighbor as Route Reflector client\n")
4381
4382 /* neighbor route-server-client. */
4383 DEFUN (neighbor_route_server_client,
4384 neighbor_route_server_client_cmd,
4385 "neighbor <A.B.C.D|X:X::X:X|WORD> route-server-client",
4386 NEIGHBOR_STR
4387 NEIGHBOR_ADDR_STR2
4388 "Configure a neighbor as Route Server client\n")
4389 {
4390 int idx_peer = 1;
4391 struct peer *peer;
4392
4393 peer = peer_and_group_lookup_vty(vty, argv[idx_peer]->arg);
4394 if (!peer)
4395 return CMD_WARNING_CONFIG_FAILED;
4396 return peer_af_flag_set_vty(vty, argv[idx_peer]->arg, bgp_node_afi(vty),
4397 bgp_node_safi(vty),
4398 PEER_FLAG_RSERVER_CLIENT);
4399 }
4400
4401 ALIAS_HIDDEN(neighbor_route_server_client,
4402 neighbor_route_server_client_hidden_cmd,
4403 "neighbor <A.B.C.D|X:X::X:X|WORD> route-server-client",
4404 NEIGHBOR_STR NEIGHBOR_ADDR_STR2
4405 "Configure a neighbor as Route Server client\n")
4406
4407 DEFUN (no_neighbor_route_server_client,
4408 no_neighbor_route_server_client_cmd,
4409 "no neighbor <A.B.C.D|X:X::X:X|WORD> route-server-client",
4410 NO_STR
4411 NEIGHBOR_STR
4412 NEIGHBOR_ADDR_STR2
4413 "Configure a neighbor as Route Server client\n")
4414 {
4415 int idx_peer = 2;
4416 return peer_af_flag_unset_vty(vty, argv[idx_peer]->arg,
4417 bgp_node_afi(vty), bgp_node_safi(vty),
4418 PEER_FLAG_RSERVER_CLIENT);
4419 }
4420
4421 ALIAS_HIDDEN(no_neighbor_route_server_client,
4422 no_neighbor_route_server_client_hidden_cmd,
4423 "no neighbor <A.B.C.D|X:X::X:X|WORD> route-server-client",
4424 NO_STR NEIGHBOR_STR NEIGHBOR_ADDR_STR2
4425 "Configure a neighbor as Route Server client\n")
4426
4427 DEFUN (neighbor_nexthop_local_unchanged,
4428 neighbor_nexthop_local_unchanged_cmd,
4429 "neighbor <A.B.C.D|X:X::X:X|WORD> nexthop-local unchanged",
4430 NEIGHBOR_STR
4431 NEIGHBOR_ADDR_STR2
4432 "Configure treatment of outgoing link-local nexthop attribute\n"
4433 "Leave link-local nexthop unchanged for this peer\n")
4434 {
4435 int idx_peer = 1;
4436 return peer_af_flag_set_vty(vty, argv[idx_peer]->arg, bgp_node_afi(vty),
4437 bgp_node_safi(vty),
4438 PEER_FLAG_NEXTHOP_LOCAL_UNCHANGED);
4439 }
4440
4441 DEFUN (no_neighbor_nexthop_local_unchanged,
4442 no_neighbor_nexthop_local_unchanged_cmd,
4443 "no neighbor <A.B.C.D|X:X::X:X|WORD> nexthop-local unchanged",
4444 NO_STR
4445 NEIGHBOR_STR
4446 NEIGHBOR_ADDR_STR2
4447 "Configure treatment of outgoing link-local-nexthop attribute\n"
4448 "Leave link-local nexthop unchanged for this peer\n")
4449 {
4450 int idx_peer = 2;
4451 return peer_af_flag_unset_vty(vty, argv[idx_peer]->arg,
4452 bgp_node_afi(vty), bgp_node_safi(vty),
4453 PEER_FLAG_NEXTHOP_LOCAL_UNCHANGED);
4454 }
4455
4456 DEFUN (neighbor_attr_unchanged,
4457 neighbor_attr_unchanged_cmd,
4458 "neighbor <A.B.C.D|X:X::X:X|WORD> attribute-unchanged [{as-path|next-hop|med}]",
4459 NEIGHBOR_STR
4460 NEIGHBOR_ADDR_STR2
4461 "BGP attribute is propagated unchanged to this neighbor\n"
4462 "As-path attribute\n"
4463 "Nexthop attribute\n"
4464 "Med attribute\n")
4465 {
4466 int idx = 0;
4467 char *peer_str = argv[1]->arg;
4468 struct peer *peer;
4469 uint16_t flags = 0;
4470 afi_t afi = bgp_node_afi(vty);
4471 safi_t safi = bgp_node_safi(vty);
4472
4473 peer = peer_and_group_lookup_vty(vty, peer_str);
4474 if (!peer)
4475 return CMD_WARNING_CONFIG_FAILED;
4476
4477 if (argv_find(argv, argc, "as-path", &idx))
4478 SET_FLAG(flags, PEER_FLAG_AS_PATH_UNCHANGED);
4479 idx = 0;
4480 if (argv_find(argv, argc, "next-hop", &idx))
4481 SET_FLAG(flags, PEER_FLAG_NEXTHOP_UNCHANGED);
4482 idx = 0;
4483 if (argv_find(argv, argc, "med", &idx))
4484 SET_FLAG(flags, PEER_FLAG_MED_UNCHANGED);
4485
4486 /* no flags means all of them! */
4487 if (!flags) {
4488 SET_FLAG(flags, PEER_FLAG_AS_PATH_UNCHANGED);
4489 SET_FLAG(flags, PEER_FLAG_NEXTHOP_UNCHANGED);
4490 SET_FLAG(flags, PEER_FLAG_MED_UNCHANGED);
4491 } else {
4492 if (!CHECK_FLAG(flags, PEER_FLAG_AS_PATH_UNCHANGED)
4493 && peer_af_flag_check(peer, afi, safi,
4494 PEER_FLAG_AS_PATH_UNCHANGED)) {
4495 peer_af_flag_unset_vty(vty, peer_str, afi, safi,
4496 PEER_FLAG_AS_PATH_UNCHANGED);
4497 }
4498
4499 if (!CHECK_FLAG(flags, PEER_FLAG_NEXTHOP_UNCHANGED)
4500 && peer_af_flag_check(peer, afi, safi,
4501 PEER_FLAG_NEXTHOP_UNCHANGED)) {
4502 peer_af_flag_unset_vty(vty, peer_str, afi, safi,
4503 PEER_FLAG_NEXTHOP_UNCHANGED);
4504 }
4505
4506 if (!CHECK_FLAG(flags, PEER_FLAG_MED_UNCHANGED)
4507 && peer_af_flag_check(peer, afi, safi,
4508 PEER_FLAG_MED_UNCHANGED)) {
4509 peer_af_flag_unset_vty(vty, peer_str, afi, safi,
4510 PEER_FLAG_MED_UNCHANGED);
4511 }
4512 }
4513
4514 return peer_af_flag_set_vty(vty, peer_str, afi, safi, flags);
4515 }
4516
4517 ALIAS_HIDDEN(
4518 neighbor_attr_unchanged, neighbor_attr_unchanged_hidden_cmd,
4519 "neighbor <A.B.C.D|X:X::X:X|WORD> attribute-unchanged [{as-path|next-hop|med}]",
4520 NEIGHBOR_STR NEIGHBOR_ADDR_STR2
4521 "BGP attribute is propagated unchanged to this neighbor\n"
4522 "As-path attribute\n"
4523 "Nexthop attribute\n"
4524 "Med attribute\n")
4525
4526 DEFUN (no_neighbor_attr_unchanged,
4527 no_neighbor_attr_unchanged_cmd,
4528 "no neighbor <A.B.C.D|X:X::X:X|WORD> attribute-unchanged [{as-path|next-hop|med}]",
4529 NO_STR
4530 NEIGHBOR_STR
4531 NEIGHBOR_ADDR_STR2
4532 "BGP attribute is propagated unchanged to this neighbor\n"
4533 "As-path attribute\n"
4534 "Nexthop attribute\n"
4535 "Med attribute\n")
4536 {
4537 int idx = 0;
4538 char *peer = argv[2]->arg;
4539 uint16_t flags = 0;
4540
4541 if (argv_find(argv, argc, "as-path", &idx))
4542 SET_FLAG(flags, PEER_FLAG_AS_PATH_UNCHANGED);
4543 idx = 0;
4544 if (argv_find(argv, argc, "next-hop", &idx))
4545 SET_FLAG(flags, PEER_FLAG_NEXTHOP_UNCHANGED);
4546 idx = 0;
4547 if (argv_find(argv, argc, "med", &idx))
4548 SET_FLAG(flags, PEER_FLAG_MED_UNCHANGED);
4549
4550 if (!flags) // no flags means all of them!
4551 {
4552 SET_FLAG(flags, PEER_FLAG_AS_PATH_UNCHANGED);
4553 SET_FLAG(flags, PEER_FLAG_NEXTHOP_UNCHANGED);
4554 SET_FLAG(flags, PEER_FLAG_MED_UNCHANGED);
4555 }
4556
4557 return peer_af_flag_unset_vty(vty, peer, bgp_node_afi(vty),
4558 bgp_node_safi(vty), flags);
4559 }
4560
4561 ALIAS_HIDDEN(
4562 no_neighbor_attr_unchanged, no_neighbor_attr_unchanged_hidden_cmd,
4563 "no neighbor <A.B.C.D|X:X::X:X|WORD> attribute-unchanged [{as-path|next-hop|med}]",
4564 NO_STR NEIGHBOR_STR NEIGHBOR_ADDR_STR2
4565 "BGP attribute is propagated unchanged to this neighbor\n"
4566 "As-path attribute\n"
4567 "Nexthop attribute\n"
4568 "Med attribute\n")
4569
4570 /* EBGP multihop configuration. */
4571 static int peer_ebgp_multihop_set_vty(struct vty *vty, const char *ip_str,
4572 const char *ttl_str)
4573 {
4574 struct peer *peer;
4575 unsigned int ttl;
4576
4577 peer = peer_and_group_lookup_vty(vty, ip_str);
4578 if (!peer)
4579 return CMD_WARNING_CONFIG_FAILED;
4580
4581 if (peer->conf_if)
4582 return bgp_vty_return(vty, BGP_ERR_INVALID_FOR_DIRECT_PEER);
4583
4584 if (!ttl_str)
4585 ttl = MAXTTL;
4586 else
4587 ttl = strtoul(ttl_str, NULL, 10);
4588
4589 return bgp_vty_return(vty, peer_ebgp_multihop_set(peer, ttl));
4590 }
4591
4592 static int peer_ebgp_multihop_unset_vty(struct vty *vty, const char *ip_str)
4593 {
4594 struct peer *peer;
4595
4596 peer = peer_and_group_lookup_vty(vty, ip_str);
4597 if (!peer)
4598 return CMD_WARNING_CONFIG_FAILED;
4599
4600 return bgp_vty_return(vty, peer_ebgp_multihop_unset(peer));
4601 }
4602
4603 /* neighbor ebgp-multihop. */
4604 DEFUN (neighbor_ebgp_multihop,
4605 neighbor_ebgp_multihop_cmd,
4606 "neighbor <A.B.C.D|X:X::X:X|WORD> ebgp-multihop",
4607 NEIGHBOR_STR
4608 NEIGHBOR_ADDR_STR2
4609 "Allow EBGP neighbors not on directly connected networks\n")
4610 {
4611 int idx_peer = 1;
4612 return peer_ebgp_multihop_set_vty(vty, argv[idx_peer]->arg, NULL);
4613 }
4614
4615 DEFUN (neighbor_ebgp_multihop_ttl,
4616 neighbor_ebgp_multihop_ttl_cmd,
4617 "neighbor <A.B.C.D|X:X::X:X|WORD> ebgp-multihop (1-255)",
4618 NEIGHBOR_STR
4619 NEIGHBOR_ADDR_STR2
4620 "Allow EBGP neighbors not on directly connected networks\n"
4621 "maximum hop count\n")
4622 {
4623 int idx_peer = 1;
4624 int idx_number = 3;
4625 return peer_ebgp_multihop_set_vty(vty, argv[idx_peer]->arg,
4626 argv[idx_number]->arg);
4627 }
4628
4629 DEFUN (no_neighbor_ebgp_multihop,
4630 no_neighbor_ebgp_multihop_cmd,
4631 "no neighbor <A.B.C.D|X:X::X:X|WORD> ebgp-multihop [(1-255)]",
4632 NO_STR
4633 NEIGHBOR_STR
4634 NEIGHBOR_ADDR_STR2
4635 "Allow EBGP neighbors not on directly connected networks\n"
4636 "maximum hop count\n")
4637 {
4638 int idx_peer = 2;
4639 return peer_ebgp_multihop_unset_vty(vty, argv[idx_peer]->arg);
4640 }
4641
4642
4643 /* disable-connected-check */
4644 DEFUN (neighbor_disable_connected_check,
4645 neighbor_disable_connected_check_cmd,
4646 "neighbor <A.B.C.D|X:X::X:X|WORD> <disable-connected-check|enforce-multihop>",
4647 NEIGHBOR_STR
4648 NEIGHBOR_ADDR_STR2
4649 "one-hop away EBGP peer using loopback address\n"
4650 "Enforce EBGP neighbors perform multihop\n")
4651 {
4652 int idx_peer = 1;
4653 return peer_flag_set_vty(vty, argv[idx_peer]->arg,
4654 PEER_FLAG_DISABLE_CONNECTED_CHECK);
4655 }
4656
4657 DEFUN (no_neighbor_disable_connected_check,
4658 no_neighbor_disable_connected_check_cmd,
4659 "no neighbor <A.B.C.D|X:X::X:X|WORD> <disable-connected-check|enforce-multihop>",
4660 NO_STR
4661 NEIGHBOR_STR
4662 NEIGHBOR_ADDR_STR2
4663 "one-hop away EBGP peer using loopback address\n"
4664 "Enforce EBGP neighbors perform multihop\n")
4665 {
4666 int idx_peer = 2;
4667 return peer_flag_unset_vty(vty, argv[idx_peer]->arg,
4668 PEER_FLAG_DISABLE_CONNECTED_CHECK);
4669 }
4670
4671
4672 /* enforce-first-as */
4673 DEFUN (neighbor_enforce_first_as,
4674 neighbor_enforce_first_as_cmd,
4675 "neighbor <A.B.C.D|X:X::X:X|WORD> enforce-first-as",
4676 NEIGHBOR_STR
4677 NEIGHBOR_ADDR_STR2
4678 "Enforce the first AS for EBGP routes\n")
4679 {
4680 int idx_peer = 1;
4681
4682 return peer_flag_set_vty(vty, argv[idx_peer]->arg,
4683 PEER_FLAG_ENFORCE_FIRST_AS);
4684 }
4685
4686 DEFUN (no_neighbor_enforce_first_as,
4687 no_neighbor_enforce_first_as_cmd,
4688 "no neighbor <A.B.C.D|X:X::X:X|WORD> enforce-first-as",
4689 NO_STR
4690 NEIGHBOR_STR
4691 NEIGHBOR_ADDR_STR2
4692 "Enforce the first AS for EBGP routes\n")
4693 {
4694 int idx_peer = 2;
4695
4696 return peer_flag_unset_vty(vty, argv[idx_peer]->arg,
4697 PEER_FLAG_ENFORCE_FIRST_AS);
4698 }
4699
4700
4701 DEFUN (neighbor_description,
4702 neighbor_description_cmd,
4703 "neighbor <A.B.C.D|X:X::X:X|WORD> description LINE...",
4704 NEIGHBOR_STR
4705 NEIGHBOR_ADDR_STR2
4706 "Neighbor specific description\n"
4707 "Up to 80 characters describing this neighbor\n")
4708 {
4709 int idx_peer = 1;
4710 int idx_line = 3;
4711 struct peer *peer;
4712 char *str;
4713
4714 peer = peer_and_group_lookup_vty(vty, argv[idx_peer]->arg);
4715 if (!peer)
4716 return CMD_WARNING_CONFIG_FAILED;
4717
4718 str = argv_concat(argv, argc, idx_line);
4719
4720 peer_description_set(peer, str);
4721
4722 XFREE(MTYPE_TMP, str);
4723
4724 return CMD_SUCCESS;
4725 }
4726
4727 DEFUN (no_neighbor_description,
4728 no_neighbor_description_cmd,
4729 "no neighbor <A.B.C.D|X:X::X:X|WORD> description",
4730 NO_STR
4731 NEIGHBOR_STR
4732 NEIGHBOR_ADDR_STR2
4733 "Neighbor specific description\n")
4734 {
4735 int idx_peer = 2;
4736 struct peer *peer;
4737
4738 peer = peer_and_group_lookup_vty(vty, argv[idx_peer]->arg);
4739 if (!peer)
4740 return CMD_WARNING_CONFIG_FAILED;
4741
4742 peer_description_unset(peer);
4743
4744 return CMD_SUCCESS;
4745 }
4746
4747 ALIAS(no_neighbor_description, no_neighbor_description_comment_cmd,
4748 "no neighbor <A.B.C.D|X:X::X:X|WORD> description LINE...",
4749 NO_STR NEIGHBOR_STR NEIGHBOR_ADDR_STR2
4750 "Neighbor specific description\n"
4751 "Up to 80 characters describing this neighbor\n")
4752
4753 /* Neighbor update-source. */
4754 static int peer_update_source_vty(struct vty *vty, const char *peer_str,
4755 const char *source_str)
4756 {
4757 struct peer *peer;
4758 struct prefix p;
4759 union sockunion su;
4760
4761 peer = peer_and_group_lookup_vty(vty, peer_str);
4762 if (!peer)
4763 return CMD_WARNING_CONFIG_FAILED;
4764
4765 if (peer->conf_if)
4766 return CMD_WARNING;
4767
4768 if (source_str) {
4769 if (str2sockunion(source_str, &su) == 0)
4770 peer_update_source_addr_set(peer, &su);
4771 else {
4772 if (str2prefix(source_str, &p)) {
4773 vty_out(vty,
4774 "%% Invalid update-source, remove prefix length \n");
4775 return CMD_WARNING_CONFIG_FAILED;
4776 } else
4777 peer_update_source_if_set(peer, source_str);
4778 }
4779 } else
4780 peer_update_source_unset(peer);
4781
4782 return CMD_SUCCESS;
4783 }
4784
4785 #define BGP_UPDATE_SOURCE_HELP_STR \
4786 "IPv4 address\n" \
4787 "IPv6 address\n" \
4788 "Interface name (requires zebra to be running)\n"
4789
4790 DEFUN (neighbor_update_source,
4791 neighbor_update_source_cmd,
4792 "neighbor <A.B.C.D|X:X::X:X|WORD> update-source <A.B.C.D|X:X::X:X|WORD>",
4793 NEIGHBOR_STR
4794 NEIGHBOR_ADDR_STR2
4795 "Source of routing updates\n"
4796 BGP_UPDATE_SOURCE_HELP_STR)
4797 {
4798 int idx_peer = 1;
4799 int idx_peer_2 = 3;
4800 return peer_update_source_vty(vty, argv[idx_peer]->arg,
4801 argv[idx_peer_2]->arg);
4802 }
4803
4804 DEFUN (no_neighbor_update_source,
4805 no_neighbor_update_source_cmd,
4806 "no neighbor <A.B.C.D|X:X::X:X|WORD> update-source [<A.B.C.D|X:X::X:X|WORD>]",
4807 NO_STR
4808 NEIGHBOR_STR
4809 NEIGHBOR_ADDR_STR2
4810 "Source of routing updates\n"
4811 BGP_UPDATE_SOURCE_HELP_STR)
4812 {
4813 int idx_peer = 2;
4814 return peer_update_source_vty(vty, argv[idx_peer]->arg, NULL);
4815 }
4816
4817 static int peer_default_originate_set_vty(struct vty *vty, const char *peer_str,
4818 afi_t afi, safi_t safi,
4819 const char *rmap, int set)
4820 {
4821 int ret;
4822 struct peer *peer;
4823 struct route_map *route_map = NULL;
4824
4825 peer = peer_and_group_lookup_vty(vty, peer_str);
4826 if (!peer)
4827 return CMD_WARNING_CONFIG_FAILED;
4828
4829 if (set) {
4830 if (rmap)
4831 route_map = route_map_lookup_warn_noexist(vty, rmap);
4832 ret = peer_default_originate_set(peer, afi, safi,
4833 rmap, route_map);
4834 } else
4835 ret = peer_default_originate_unset(peer, afi, safi);
4836
4837 return bgp_vty_return(vty, ret);
4838 }
4839
4840 /* neighbor default-originate. */
4841 DEFUN (neighbor_default_originate,
4842 neighbor_default_originate_cmd,
4843 "neighbor <A.B.C.D|X:X::X:X|WORD> default-originate",
4844 NEIGHBOR_STR
4845 NEIGHBOR_ADDR_STR2
4846 "Originate default route to this neighbor\n")
4847 {
4848 int idx_peer = 1;
4849 return peer_default_originate_set_vty(vty, argv[idx_peer]->arg,
4850 bgp_node_afi(vty),
4851 bgp_node_safi(vty), NULL, 1);
4852 }
4853
4854 ALIAS_HIDDEN(neighbor_default_originate, neighbor_default_originate_hidden_cmd,
4855 "neighbor <A.B.C.D|X:X::X:X|WORD> default-originate",
4856 NEIGHBOR_STR NEIGHBOR_ADDR_STR2
4857 "Originate default route to this neighbor\n")
4858
4859 DEFUN (neighbor_default_originate_rmap,
4860 neighbor_default_originate_rmap_cmd,
4861 "neighbor <A.B.C.D|X:X::X:X|WORD> default-originate route-map WORD",
4862 NEIGHBOR_STR
4863 NEIGHBOR_ADDR_STR2
4864 "Originate default route to this neighbor\n"
4865 "Route-map to specify criteria to originate default\n"
4866 "route-map name\n")
4867 {
4868 int idx_peer = 1;
4869 int idx_word = 4;
4870 return peer_default_originate_set_vty(
4871 vty, argv[idx_peer]->arg, bgp_node_afi(vty), bgp_node_safi(vty),
4872 argv[idx_word]->arg, 1);
4873 }
4874
4875 ALIAS_HIDDEN(
4876 neighbor_default_originate_rmap,
4877 neighbor_default_originate_rmap_hidden_cmd,
4878 "neighbor <A.B.C.D|X:X::X:X|WORD> default-originate route-map WORD",
4879 NEIGHBOR_STR NEIGHBOR_ADDR_STR2
4880 "Originate default route to this neighbor\n"
4881 "Route-map to specify criteria to originate default\n"
4882 "route-map name\n")
4883
4884 DEFUN (no_neighbor_default_originate,
4885 no_neighbor_default_originate_cmd,
4886 "no neighbor <A.B.C.D|X:X::X:X|WORD> default-originate [route-map WORD]",
4887 NO_STR
4888 NEIGHBOR_STR
4889 NEIGHBOR_ADDR_STR2
4890 "Originate default route to this neighbor\n"
4891 "Route-map to specify criteria to originate default\n"
4892 "route-map name\n")
4893 {
4894 int idx_peer = 2;
4895 return peer_default_originate_set_vty(vty, argv[idx_peer]->arg,
4896 bgp_node_afi(vty),
4897 bgp_node_safi(vty), NULL, 0);
4898 }
4899
4900 ALIAS_HIDDEN(
4901 no_neighbor_default_originate, no_neighbor_default_originate_hidden_cmd,
4902 "no neighbor <A.B.C.D|X:X::X:X|WORD> default-originate [route-map WORD]",
4903 NO_STR NEIGHBOR_STR NEIGHBOR_ADDR_STR2
4904 "Originate default route to this neighbor\n"
4905 "Route-map to specify criteria to originate default\n"
4906 "route-map name\n")
4907
4908
4909 /* Set neighbor's BGP port. */
4910 static int peer_port_vty(struct vty *vty, const char *ip_str, int afi,
4911 const char *port_str)
4912 {
4913 struct peer *peer;
4914 uint16_t port;
4915 struct servent *sp;
4916
4917 peer = peer_lookup_vty(vty, ip_str);
4918 if (!peer)
4919 return CMD_WARNING_CONFIG_FAILED;
4920
4921 if (!port_str) {
4922 sp = getservbyname("bgp", "tcp");
4923 port = (sp == NULL) ? BGP_PORT_DEFAULT : ntohs(sp->s_port);
4924 } else {
4925 port = strtoul(port_str, NULL, 10);
4926 }
4927
4928 peer_port_set(peer, port);
4929
4930 return CMD_SUCCESS;
4931 }
4932
4933 /* Set specified peer's BGP port. */
4934 DEFUN (neighbor_port,
4935 neighbor_port_cmd,
4936 "neighbor <A.B.C.D|X:X::X:X> port (0-65535)",
4937 NEIGHBOR_STR
4938 NEIGHBOR_ADDR_STR
4939 "Neighbor's BGP port\n"
4940 "TCP port number\n")
4941 {
4942 int idx_ip = 1;
4943 int idx_number = 3;
4944 return peer_port_vty(vty, argv[idx_ip]->arg, AFI_IP,
4945 argv[idx_number]->arg);
4946 }
4947
4948 DEFUN (no_neighbor_port,
4949 no_neighbor_port_cmd,
4950 "no neighbor <A.B.C.D|X:X::X:X> port [(0-65535)]",
4951 NO_STR
4952 NEIGHBOR_STR
4953 NEIGHBOR_ADDR_STR
4954 "Neighbor's BGP port\n"
4955 "TCP port number\n")
4956 {
4957 int idx_ip = 2;
4958 return peer_port_vty(vty, argv[idx_ip]->arg, AFI_IP, NULL);
4959 }
4960
4961
4962 /* neighbor weight. */
4963 static int peer_weight_set_vty(struct vty *vty, const char *ip_str, afi_t afi,
4964 safi_t safi, const char *weight_str)
4965 {
4966 int ret;
4967 struct peer *peer;
4968 unsigned long weight;
4969
4970 peer = peer_and_group_lookup_vty(vty, ip_str);
4971 if (!peer)
4972 return CMD_WARNING_CONFIG_FAILED;
4973
4974 weight = strtoul(weight_str, NULL, 10);
4975
4976 ret = peer_weight_set(peer, afi, safi, weight);
4977 return bgp_vty_return(vty, ret);
4978 }
4979
4980 static int peer_weight_unset_vty(struct vty *vty, const char *ip_str, afi_t afi,
4981 safi_t safi)
4982 {
4983 int ret;
4984 struct peer *peer;
4985
4986 peer = peer_and_group_lookup_vty(vty, ip_str);
4987 if (!peer)
4988 return CMD_WARNING_CONFIG_FAILED;
4989
4990 ret = peer_weight_unset(peer, afi, safi);
4991 return bgp_vty_return(vty, ret);
4992 }
4993
4994 DEFUN (neighbor_weight,
4995 neighbor_weight_cmd,
4996 "neighbor <A.B.C.D|X:X::X:X|WORD> weight (0-65535)",
4997 NEIGHBOR_STR
4998 NEIGHBOR_ADDR_STR2
4999 "Set default weight for routes from this neighbor\n"
5000 "default weight\n")
5001 {
5002 int idx_peer = 1;
5003 int idx_number = 3;
5004 return peer_weight_set_vty(vty, argv[idx_peer]->arg, bgp_node_afi(vty),
5005 bgp_node_safi(vty), argv[idx_number]->arg);
5006 }
5007
5008 ALIAS_HIDDEN(neighbor_weight, neighbor_weight_hidden_cmd,
5009 "neighbor <A.B.C.D|X:X::X:X|WORD> weight (0-65535)",
5010 NEIGHBOR_STR NEIGHBOR_ADDR_STR2
5011 "Set default weight for routes from this neighbor\n"
5012 "default weight\n")
5013
5014 DEFUN (no_neighbor_weight,
5015 no_neighbor_weight_cmd,
5016 "no neighbor <A.B.C.D|X:X::X:X|WORD> weight [(0-65535)]",
5017 NO_STR
5018 NEIGHBOR_STR
5019 NEIGHBOR_ADDR_STR2
5020 "Set default weight for routes from this neighbor\n"
5021 "default weight\n")
5022 {
5023 int idx_peer = 2;
5024 return peer_weight_unset_vty(vty, argv[idx_peer]->arg,
5025 bgp_node_afi(vty), bgp_node_safi(vty));
5026 }
5027
5028 ALIAS_HIDDEN(no_neighbor_weight, no_neighbor_weight_hidden_cmd,
5029 "no neighbor <A.B.C.D|X:X::X:X|WORD> weight [(0-65535)]",
5030 NO_STR NEIGHBOR_STR NEIGHBOR_ADDR_STR2
5031 "Set default weight for routes from this neighbor\n"
5032 "default weight\n")
5033
5034
5035 /* Override capability negotiation. */
5036 DEFUN (neighbor_override_capability,
5037 neighbor_override_capability_cmd,
5038 "neighbor <A.B.C.D|X:X::X:X|WORD> override-capability",
5039 NEIGHBOR_STR
5040 NEIGHBOR_ADDR_STR2
5041 "Override capability negotiation result\n")
5042 {
5043 int idx_peer = 1;
5044 return peer_flag_set_vty(vty, argv[idx_peer]->arg,
5045 PEER_FLAG_OVERRIDE_CAPABILITY);
5046 }
5047
5048 DEFUN (no_neighbor_override_capability,
5049 no_neighbor_override_capability_cmd,
5050 "no neighbor <A.B.C.D|X:X::X:X|WORD> override-capability",
5051 NO_STR
5052 NEIGHBOR_STR
5053 NEIGHBOR_ADDR_STR2
5054 "Override capability negotiation result\n")
5055 {
5056 int idx_peer = 2;
5057 return peer_flag_unset_vty(vty, argv[idx_peer]->arg,
5058 PEER_FLAG_OVERRIDE_CAPABILITY);
5059 }
5060
5061 DEFUN (neighbor_strict_capability,
5062 neighbor_strict_capability_cmd,
5063 "neighbor <A.B.C.D|X:X::X:X|WORD> strict-capability-match",
5064 NEIGHBOR_STR
5065 NEIGHBOR_ADDR_STR2
5066 "Strict capability negotiation match\n")
5067 {
5068 int idx_peer = 1;
5069
5070 return peer_flag_set_vty(vty, argv[idx_peer]->arg,
5071 PEER_FLAG_STRICT_CAP_MATCH);
5072 }
5073
5074 DEFUN (no_neighbor_strict_capability,
5075 no_neighbor_strict_capability_cmd,
5076 "no neighbor <A.B.C.D|X:X::X:X|WORD> strict-capability-match",
5077 NO_STR
5078 NEIGHBOR_STR
5079 NEIGHBOR_ADDR_STR2
5080 "Strict capability negotiation match\n")
5081 {
5082 int idx_peer = 2;
5083
5084 return peer_flag_unset_vty(vty, argv[idx_peer]->arg,
5085 PEER_FLAG_STRICT_CAP_MATCH);
5086 }
5087
5088 static int peer_timers_set_vty(struct vty *vty, const char *ip_str,
5089 const char *keep_str, const char *hold_str)
5090 {
5091 int ret;
5092 struct peer *peer;
5093 uint32_t keepalive;
5094 uint32_t holdtime;
5095
5096 peer = peer_and_group_lookup_vty(vty, ip_str);
5097 if (!peer)
5098 return CMD_WARNING_CONFIG_FAILED;
5099
5100 keepalive = strtoul(keep_str, NULL, 10);
5101 holdtime = strtoul(hold_str, NULL, 10);
5102
5103 ret = peer_timers_set(peer, keepalive, holdtime);
5104
5105 return bgp_vty_return(vty, ret);
5106 }
5107
5108 static int peer_timers_unset_vty(struct vty *vty, const char *ip_str)
5109 {
5110 int ret;
5111 struct peer *peer;
5112
5113 peer = peer_and_group_lookup_vty(vty, ip_str);
5114 if (!peer)
5115 return CMD_WARNING_CONFIG_FAILED;
5116
5117 ret = peer_timers_unset(peer);
5118
5119 return bgp_vty_return(vty, ret);
5120 }
5121
5122 DEFUN (neighbor_timers,
5123 neighbor_timers_cmd,
5124 "neighbor <A.B.C.D|X:X::X:X|WORD> timers (0-65535) (0-65535)",
5125 NEIGHBOR_STR
5126 NEIGHBOR_ADDR_STR2
5127 "BGP per neighbor timers\n"
5128 "Keepalive interval\n"
5129 "Holdtime\n")
5130 {
5131 int idx_peer = 1;
5132 int idx_number = 3;
5133 int idx_number_2 = 4;
5134 return peer_timers_set_vty(vty, argv[idx_peer]->arg,
5135 argv[idx_number]->arg,
5136 argv[idx_number_2]->arg);
5137 }
5138
5139 DEFUN (no_neighbor_timers,
5140 no_neighbor_timers_cmd,
5141 "no neighbor <A.B.C.D|X:X::X:X|WORD> timers [(0-65535) (0-65535)]",
5142 NO_STR
5143 NEIGHBOR_STR
5144 NEIGHBOR_ADDR_STR2
5145 "BGP per neighbor timers\n"
5146 "Keepalive interval\n"
5147 "Holdtime\n")
5148 {
5149 int idx_peer = 2;
5150 return peer_timers_unset_vty(vty, argv[idx_peer]->arg);
5151 }
5152
5153
5154 static int peer_timers_connect_set_vty(struct vty *vty, const char *ip_str,
5155 const char *time_str)
5156 {
5157 int ret;
5158 struct peer *peer;
5159 uint32_t connect;
5160
5161 peer = peer_and_group_lookup_vty(vty, ip_str);
5162 if (!peer)
5163 return CMD_WARNING_CONFIG_FAILED;
5164
5165 connect = strtoul(time_str, NULL, 10);
5166
5167 ret = peer_timers_connect_set(peer, connect);
5168
5169 return bgp_vty_return(vty, ret);
5170 }
5171
5172 static int peer_timers_connect_unset_vty(struct vty *vty, const char *ip_str)
5173 {
5174 int ret;
5175 struct peer *peer;
5176
5177 peer = peer_and_group_lookup_vty(vty, ip_str);
5178 if (!peer)
5179 return CMD_WARNING_CONFIG_FAILED;
5180
5181 ret = peer_timers_connect_unset(peer);
5182
5183 return bgp_vty_return(vty, ret);
5184 }
5185
5186 DEFUN (neighbor_timers_connect,
5187 neighbor_timers_connect_cmd,
5188 "neighbor <A.B.C.D|X:X::X:X|WORD> timers connect (1-65535)",
5189 NEIGHBOR_STR
5190 NEIGHBOR_ADDR_STR2
5191 "BGP per neighbor timers\n"
5192 "BGP connect timer\n"
5193 "Connect timer\n")
5194 {
5195 int idx_peer = 1;
5196 int idx_number = 4;
5197 return peer_timers_connect_set_vty(vty, argv[idx_peer]->arg,
5198 argv[idx_number]->arg);
5199 }
5200
5201 DEFUN (no_neighbor_timers_connect,
5202 no_neighbor_timers_connect_cmd,
5203 "no neighbor <A.B.C.D|X:X::X:X|WORD> timers connect [(1-65535)]",
5204 NO_STR
5205 NEIGHBOR_STR
5206 NEIGHBOR_ADDR_STR2
5207 "BGP per neighbor timers\n"
5208 "BGP connect timer\n"
5209 "Connect timer\n")
5210 {
5211 int idx_peer = 2;
5212 return peer_timers_connect_unset_vty(vty, argv[idx_peer]->arg);
5213 }
5214
5215
5216 static int peer_advertise_interval_vty(struct vty *vty, const char *ip_str,
5217 const char *time_str, int set)
5218 {
5219 int ret;
5220 struct peer *peer;
5221 uint32_t routeadv = 0;
5222
5223 peer = peer_and_group_lookup_vty(vty, ip_str);
5224 if (!peer)
5225 return CMD_WARNING_CONFIG_FAILED;
5226
5227 if (time_str)
5228 routeadv = strtoul(time_str, NULL, 10);
5229
5230 if (set)
5231 ret = peer_advertise_interval_set(peer, routeadv);
5232 else
5233 ret = peer_advertise_interval_unset(peer);
5234
5235 return bgp_vty_return(vty, ret);
5236 }
5237
5238 DEFUN (neighbor_advertise_interval,
5239 neighbor_advertise_interval_cmd,
5240 "neighbor <A.B.C.D|X:X::X:X|WORD> advertisement-interval (0-600)",
5241 NEIGHBOR_STR
5242 NEIGHBOR_ADDR_STR2
5243 "Minimum interval between sending BGP routing updates\n"
5244 "time in seconds\n")
5245 {
5246 int idx_peer = 1;
5247 int idx_number = 3;
5248 return peer_advertise_interval_vty(vty, argv[idx_peer]->arg,
5249 argv[idx_number]->arg, 1);
5250 }
5251
5252 DEFUN (no_neighbor_advertise_interval,
5253 no_neighbor_advertise_interval_cmd,
5254 "no neighbor <A.B.C.D|X:X::X:X|WORD> advertisement-interval [(0-600)]",
5255 NO_STR
5256 NEIGHBOR_STR
5257 NEIGHBOR_ADDR_STR2
5258 "Minimum interval between sending BGP routing updates\n"
5259 "time in seconds\n")
5260 {
5261 int idx_peer = 2;
5262 return peer_advertise_interval_vty(vty, argv[idx_peer]->arg, NULL, 0);
5263 }
5264
5265
5266 /* Time to wait before processing route-map updates */
5267 DEFUN (bgp_set_route_map_delay_timer,
5268 bgp_set_route_map_delay_timer_cmd,
5269 "bgp route-map delay-timer (0-600)",
5270 SET_STR
5271 "BGP route-map delay timer\n"
5272 "Time in secs to wait before processing route-map changes\n"
5273 "0 disables the timer, no route updates happen when route-maps change\n")
5274 {
5275 int idx_number = 3;
5276 uint32_t rmap_delay_timer;
5277
5278 if (argv[idx_number]->arg) {
5279 rmap_delay_timer = strtoul(argv[idx_number]->arg, NULL, 10);
5280 bm->rmap_update_timer = rmap_delay_timer;
5281
5282 /* if the dynamic update handling is being disabled, and a timer
5283 * is
5284 * running, stop the timer and act as if the timer has already
5285 * fired.
5286 */
5287 if (!rmap_delay_timer && bm->t_rmap_update) {
5288 BGP_TIMER_OFF(bm->t_rmap_update);
5289 thread_execute(bm->master, bgp_route_map_update_timer,
5290 NULL, 0);
5291 }
5292 return CMD_SUCCESS;
5293 } else {
5294 vty_out(vty, "%% BGP invalid route-map delay-timer\n");
5295 return CMD_WARNING_CONFIG_FAILED;
5296 }
5297 }
5298
5299 DEFUN (no_bgp_set_route_map_delay_timer,
5300 no_bgp_set_route_map_delay_timer_cmd,
5301 "no bgp route-map delay-timer [(0-600)]",
5302 NO_STR
5303 BGP_STR
5304 "Default BGP route-map delay timer\n"
5305 "Reset to default time to wait for processing route-map changes\n"
5306 "0 disables the timer, no route updates happen when route-maps change\n")
5307 {
5308
5309 bm->rmap_update_timer = RMAP_DEFAULT_UPDATE_TIMER;
5310
5311 return CMD_SUCCESS;
5312 }
5313
5314
5315 /* neighbor interface */
5316 static int peer_interface_vty(struct vty *vty, const char *ip_str,
5317 const char *str)
5318 {
5319 struct peer *peer;
5320
5321 peer = peer_lookup_vty(vty, ip_str);
5322 if (!peer || peer->conf_if) {
5323 vty_out(vty, "%% BGP invalid peer %s\n", ip_str);
5324 return CMD_WARNING_CONFIG_FAILED;
5325 }
5326
5327 if (str)
5328 peer_interface_set(peer, str);
5329 else
5330 peer_interface_unset(peer);
5331
5332 return CMD_SUCCESS;
5333 }
5334
5335 DEFUN (neighbor_interface,
5336 neighbor_interface_cmd,
5337 "neighbor <A.B.C.D|X:X::X:X> interface WORD",
5338 NEIGHBOR_STR
5339 NEIGHBOR_ADDR_STR
5340 "Interface\n"
5341 "Interface name\n")
5342 {
5343 int idx_ip = 1;
5344 int idx_word = 3;
5345 return peer_interface_vty(vty, argv[idx_ip]->arg, argv[idx_word]->arg);
5346 }
5347
5348 DEFUN (no_neighbor_interface,
5349 no_neighbor_interface_cmd,
5350 "no neighbor <A.B.C.D|X:X::X:X|WORD> interface WORD",
5351 NO_STR
5352 NEIGHBOR_STR
5353 NEIGHBOR_ADDR_STR2
5354 "Interface\n"
5355 "Interface name\n")
5356 {
5357 int idx_peer = 2;
5358 return peer_interface_vty(vty, argv[idx_peer]->arg, NULL);
5359 }
5360
5361 DEFUN (neighbor_distribute_list,
5362 neighbor_distribute_list_cmd,
5363 "neighbor <A.B.C.D|X:X::X:X|WORD> distribute-list <(1-199)|(1300-2699)|WORD> <in|out>",
5364 NEIGHBOR_STR
5365 NEIGHBOR_ADDR_STR2
5366 "Filter updates to/from this neighbor\n"
5367 "IP access-list number\n"
5368 "IP access-list number (expanded range)\n"
5369 "IP Access-list name\n"
5370 "Filter incoming updates\n"
5371 "Filter outgoing updates\n")
5372 {
5373 int idx_peer = 1;
5374 int idx_acl = 3;
5375 int direct, ret;
5376 struct peer *peer;
5377
5378 const char *pstr = argv[idx_peer]->arg;
5379 const char *acl = argv[idx_acl]->arg;
5380 const char *inout = argv[argc - 1]->text;
5381
5382 peer = peer_and_group_lookup_vty(vty, pstr);
5383 if (!peer)
5384 return CMD_WARNING_CONFIG_FAILED;
5385
5386 /* Check filter direction. */
5387 direct = strmatch(inout, "in") ? FILTER_IN : FILTER_OUT;
5388 ret = peer_distribute_set(peer, bgp_node_afi(vty), bgp_node_safi(vty),
5389 direct, acl);
5390
5391 return bgp_vty_return(vty, ret);
5392 }
5393
5394 ALIAS_HIDDEN(
5395 neighbor_distribute_list, neighbor_distribute_list_hidden_cmd,
5396 "neighbor <A.B.C.D|X:X::X:X|WORD> distribute-list <(1-199)|(1300-2699)|WORD> <in|out>",
5397 NEIGHBOR_STR NEIGHBOR_ADDR_STR2
5398 "Filter updates to/from this neighbor\n"
5399 "IP access-list number\n"
5400 "IP access-list number (expanded range)\n"
5401 "IP Access-list name\n"
5402 "Filter incoming updates\n"
5403 "Filter outgoing updates\n")
5404
5405 DEFUN (no_neighbor_distribute_list,
5406 no_neighbor_distribute_list_cmd,
5407 "no neighbor <A.B.C.D|X:X::X:X|WORD> distribute-list <(1-199)|(1300-2699)|WORD> <in|out>",
5408 NO_STR
5409 NEIGHBOR_STR
5410 NEIGHBOR_ADDR_STR2
5411 "Filter updates to/from this neighbor\n"
5412 "IP access-list number\n"
5413 "IP access-list number (expanded range)\n"
5414 "IP Access-list name\n"
5415 "Filter incoming updates\n"
5416 "Filter outgoing updates\n")
5417 {
5418 int idx_peer = 2;
5419 int direct, ret;
5420 struct peer *peer;
5421
5422 const char *pstr = argv[idx_peer]->arg;
5423 const char *inout = argv[argc - 1]->text;
5424
5425 peer = peer_and_group_lookup_vty(vty, pstr);
5426 if (!peer)
5427 return CMD_WARNING_CONFIG_FAILED;
5428
5429 /* Check filter direction. */
5430 direct = strmatch(inout, "in") ? FILTER_IN : FILTER_OUT;
5431 ret = peer_distribute_unset(peer, bgp_node_afi(vty), bgp_node_safi(vty),
5432 direct);
5433
5434 return bgp_vty_return(vty, ret);
5435 }
5436
5437 ALIAS_HIDDEN(
5438 no_neighbor_distribute_list, no_neighbor_distribute_list_hidden_cmd,
5439 "no neighbor <A.B.C.D|X:X::X:X|WORD> distribute-list <(1-199)|(1300-2699)|WORD> <in|out>",
5440 NO_STR NEIGHBOR_STR NEIGHBOR_ADDR_STR2
5441 "Filter updates to/from this neighbor\n"
5442 "IP access-list number\n"
5443 "IP access-list number (expanded range)\n"
5444 "IP Access-list name\n"
5445 "Filter incoming updates\n"
5446 "Filter outgoing updates\n")
5447
5448 /* Set prefix list to the peer. */
5449 static int peer_prefix_list_set_vty(struct vty *vty, const char *ip_str,
5450 afi_t afi, safi_t safi,
5451 const char *name_str,
5452 const char *direct_str)
5453 {
5454 int ret;
5455 int direct = FILTER_IN;
5456 struct peer *peer;
5457
5458 peer = peer_and_group_lookup_vty(vty, ip_str);
5459 if (!peer)
5460 return CMD_WARNING_CONFIG_FAILED;
5461
5462 /* Check filter direction. */
5463 if (strncmp(direct_str, "i", 1) == 0)
5464 direct = FILTER_IN;
5465 else if (strncmp(direct_str, "o", 1) == 0)
5466 direct = FILTER_OUT;
5467
5468 ret = peer_prefix_list_set(peer, afi, safi, direct, name_str);
5469
5470 return bgp_vty_return(vty, ret);
5471 }
5472
5473 static int peer_prefix_list_unset_vty(struct vty *vty, const char *ip_str,
5474 afi_t afi, safi_t safi,
5475 const char *direct_str)
5476 {
5477 int ret;
5478 struct peer *peer;
5479 int direct = FILTER_IN;
5480
5481 peer = peer_and_group_lookup_vty(vty, ip_str);
5482 if (!peer)
5483 return CMD_WARNING_CONFIG_FAILED;
5484
5485 /* Check filter direction. */
5486 if (strncmp(direct_str, "i", 1) == 0)
5487 direct = FILTER_IN;
5488 else if (strncmp(direct_str, "o", 1) == 0)
5489 direct = FILTER_OUT;
5490
5491 ret = peer_prefix_list_unset(peer, afi, safi, direct);
5492
5493 return bgp_vty_return(vty, ret);
5494 }
5495
5496 DEFUN (neighbor_prefix_list,
5497 neighbor_prefix_list_cmd,
5498 "neighbor <A.B.C.D|X:X::X:X|WORD> prefix-list WORD <in|out>",
5499 NEIGHBOR_STR
5500 NEIGHBOR_ADDR_STR2
5501 "Filter updates to/from this neighbor\n"
5502 "Name of a prefix list\n"
5503 "Filter incoming updates\n"
5504 "Filter outgoing updates\n")
5505 {
5506 int idx_peer = 1;
5507 int idx_word = 3;
5508 int idx_in_out = 4;
5509 return peer_prefix_list_set_vty(
5510 vty, argv[idx_peer]->arg, bgp_node_afi(vty), bgp_node_safi(vty),
5511 argv[idx_word]->arg, argv[idx_in_out]->arg);
5512 }
5513
5514 ALIAS_HIDDEN(neighbor_prefix_list, neighbor_prefix_list_hidden_cmd,
5515 "neighbor <A.B.C.D|X:X::X:X|WORD> prefix-list WORD <in|out>",
5516 NEIGHBOR_STR NEIGHBOR_ADDR_STR2
5517 "Filter updates to/from this neighbor\n"
5518 "Name of a prefix list\n"
5519 "Filter incoming updates\n"
5520 "Filter outgoing updates\n")
5521
5522 DEFUN (no_neighbor_prefix_list,
5523 no_neighbor_prefix_list_cmd,
5524 "no neighbor <A.B.C.D|X:X::X:X|WORD> prefix-list WORD <in|out>",
5525 NO_STR
5526 NEIGHBOR_STR
5527 NEIGHBOR_ADDR_STR2
5528 "Filter updates to/from this neighbor\n"
5529 "Name of a prefix list\n"
5530 "Filter incoming updates\n"
5531 "Filter outgoing updates\n")
5532 {
5533 int idx_peer = 2;
5534 int idx_in_out = 5;
5535 return peer_prefix_list_unset_vty(vty, argv[idx_peer]->arg,
5536 bgp_node_afi(vty), bgp_node_safi(vty),
5537 argv[idx_in_out]->arg);
5538 }
5539
5540 ALIAS_HIDDEN(no_neighbor_prefix_list, no_neighbor_prefix_list_hidden_cmd,
5541 "no neighbor <A.B.C.D|X:X::X:X|WORD> prefix-list WORD <in|out>",
5542 NO_STR NEIGHBOR_STR NEIGHBOR_ADDR_STR2
5543 "Filter updates to/from this neighbor\n"
5544 "Name of a prefix list\n"
5545 "Filter incoming updates\n"
5546 "Filter outgoing updates\n")
5547
5548 static int peer_aslist_set_vty(struct vty *vty, const char *ip_str, afi_t afi,
5549 safi_t safi, const char *name_str,
5550 const char *direct_str)
5551 {
5552 int ret;
5553 struct peer *peer;
5554 int direct = FILTER_IN;
5555
5556 peer = peer_and_group_lookup_vty(vty, ip_str);
5557 if (!peer)
5558 return CMD_WARNING_CONFIG_FAILED;
5559
5560 /* Check filter direction. */
5561 if (strncmp(direct_str, "i", 1) == 0)
5562 direct = FILTER_IN;
5563 else if (strncmp(direct_str, "o", 1) == 0)
5564 direct = FILTER_OUT;
5565
5566 ret = peer_aslist_set(peer, afi, safi, direct, name_str);
5567
5568 return bgp_vty_return(vty, ret);
5569 }
5570
5571 static int peer_aslist_unset_vty(struct vty *vty, const char *ip_str, afi_t afi,
5572 safi_t safi, const char *direct_str)
5573 {
5574 int ret;
5575 struct peer *peer;
5576 int direct = FILTER_IN;
5577
5578 peer = peer_and_group_lookup_vty(vty, ip_str);
5579 if (!peer)
5580 return CMD_WARNING_CONFIG_FAILED;
5581
5582 /* Check filter direction. */
5583 if (strncmp(direct_str, "i", 1) == 0)
5584 direct = FILTER_IN;
5585 else if (strncmp(direct_str, "o", 1) == 0)
5586 direct = FILTER_OUT;
5587
5588 ret = peer_aslist_unset(peer, afi, safi, direct);
5589
5590 return bgp_vty_return(vty, ret);
5591 }
5592
5593 DEFUN (neighbor_filter_list,
5594 neighbor_filter_list_cmd,
5595 "neighbor <A.B.C.D|X:X::X:X|WORD> filter-list WORD <in|out>",
5596 NEIGHBOR_STR
5597 NEIGHBOR_ADDR_STR2
5598 "Establish BGP filters\n"
5599 "AS path access-list name\n"
5600 "Filter incoming routes\n"
5601 "Filter outgoing routes\n")
5602 {
5603 int idx_peer = 1;
5604 int idx_word = 3;
5605 int idx_in_out = 4;
5606 return peer_aslist_set_vty(vty, argv[idx_peer]->arg, bgp_node_afi(vty),
5607 bgp_node_safi(vty), argv[idx_word]->arg,
5608 argv[idx_in_out]->arg);
5609 }
5610
5611 ALIAS_HIDDEN(neighbor_filter_list, neighbor_filter_list_hidden_cmd,
5612 "neighbor <A.B.C.D|X:X::X:X|WORD> filter-list WORD <in|out>",
5613 NEIGHBOR_STR NEIGHBOR_ADDR_STR2
5614 "Establish BGP filters\n"
5615 "AS path access-list name\n"
5616 "Filter incoming routes\n"
5617 "Filter outgoing routes\n")
5618
5619 DEFUN (no_neighbor_filter_list,
5620 no_neighbor_filter_list_cmd,
5621 "no neighbor <A.B.C.D|X:X::X:X|WORD> filter-list WORD <in|out>",
5622 NO_STR
5623 NEIGHBOR_STR
5624 NEIGHBOR_ADDR_STR2
5625 "Establish BGP filters\n"
5626 "AS path access-list name\n"
5627 "Filter incoming routes\n"
5628 "Filter outgoing routes\n")
5629 {
5630 int idx_peer = 2;
5631 int idx_in_out = 5;
5632 return peer_aslist_unset_vty(vty, argv[idx_peer]->arg,
5633 bgp_node_afi(vty), bgp_node_safi(vty),
5634 argv[idx_in_out]->arg);
5635 }
5636
5637 ALIAS_HIDDEN(no_neighbor_filter_list, no_neighbor_filter_list_hidden_cmd,
5638 "no neighbor <A.B.C.D|X:X::X:X|WORD> filter-list WORD <in|out>",
5639 NO_STR NEIGHBOR_STR NEIGHBOR_ADDR_STR2
5640 "Establish BGP filters\n"
5641 "AS path access-list name\n"
5642 "Filter incoming routes\n"
5643 "Filter outgoing routes\n")
5644
5645 /* Set route-map to the peer. */
5646 static int peer_route_map_set_vty(struct vty *vty, const char *ip_str,
5647 afi_t afi, safi_t safi, const char *name_str,
5648 const char *direct_str)
5649 {
5650 int ret;
5651 struct peer *peer;
5652 int direct = RMAP_IN;
5653 struct route_map *route_map;
5654
5655 peer = peer_and_group_lookup_vty(vty, ip_str);
5656 if (!peer)
5657 return CMD_WARNING_CONFIG_FAILED;
5658
5659 /* Check filter direction. */
5660 if (strncmp(direct_str, "in", 2) == 0)
5661 direct = RMAP_IN;
5662 else if (strncmp(direct_str, "o", 1) == 0)
5663 direct = RMAP_OUT;
5664
5665 route_map = route_map_lookup_warn_noexist(vty, name_str);
5666 ret = peer_route_map_set(peer, afi, safi, direct, name_str, route_map);
5667
5668 return bgp_vty_return(vty, ret);
5669 }
5670
5671 static int peer_route_map_unset_vty(struct vty *vty, const char *ip_str,
5672 afi_t afi, safi_t safi,
5673 const char *direct_str)
5674 {
5675 int ret;
5676 struct peer *peer;
5677 int direct = RMAP_IN;
5678
5679 peer = peer_and_group_lookup_vty(vty, ip_str);
5680 if (!peer)
5681 return CMD_WARNING_CONFIG_FAILED;
5682
5683 /* Check filter direction. */
5684 if (strncmp(direct_str, "in", 2) == 0)
5685 direct = RMAP_IN;
5686 else if (strncmp(direct_str, "o", 1) == 0)
5687 direct = RMAP_OUT;
5688
5689 ret = peer_route_map_unset(peer, afi, safi, direct);
5690
5691 return bgp_vty_return(vty, ret);
5692 }
5693
5694 DEFUN (neighbor_route_map,
5695 neighbor_route_map_cmd,
5696 "neighbor <A.B.C.D|X:X::X:X|WORD> route-map WORD <in|out>",
5697 NEIGHBOR_STR
5698 NEIGHBOR_ADDR_STR2
5699 "Apply route map to neighbor\n"
5700 "Name of route map\n"
5701 "Apply map to incoming routes\n"
5702 "Apply map to outbound routes\n")
5703 {
5704 int idx_peer = 1;
5705 int idx_word = 3;
5706 int idx_in_out = 4;
5707 return peer_route_map_set_vty(
5708 vty, argv[idx_peer]->arg, bgp_node_afi(vty), bgp_node_safi(vty),
5709 argv[idx_word]->arg, argv[idx_in_out]->arg);
5710 }
5711
5712 ALIAS_HIDDEN(neighbor_route_map, neighbor_route_map_hidden_cmd,
5713 "neighbor <A.B.C.D|X:X::X:X|WORD> route-map WORD <in|out>",
5714 NEIGHBOR_STR NEIGHBOR_ADDR_STR2
5715 "Apply route map to neighbor\n"
5716 "Name of route map\n"
5717 "Apply map to incoming routes\n"
5718 "Apply map to outbound routes\n")
5719
5720 DEFUN (no_neighbor_route_map,
5721 no_neighbor_route_map_cmd,
5722 "no neighbor <A.B.C.D|X:X::X:X|WORD> route-map WORD <in|out>",
5723 NO_STR
5724 NEIGHBOR_STR
5725 NEIGHBOR_ADDR_STR2
5726 "Apply route map to neighbor\n"
5727 "Name of route map\n"
5728 "Apply map to incoming routes\n"
5729 "Apply map to outbound routes\n")
5730 {
5731 int idx_peer = 2;
5732 int idx_in_out = 5;
5733 return peer_route_map_unset_vty(vty, argv[idx_peer]->arg,
5734 bgp_node_afi(vty), bgp_node_safi(vty),
5735 argv[idx_in_out]->arg);
5736 }
5737
5738 ALIAS_HIDDEN(no_neighbor_route_map, no_neighbor_route_map_hidden_cmd,
5739 "no neighbor <A.B.C.D|X:X::X:X|WORD> route-map WORD <in|out>",
5740 NO_STR NEIGHBOR_STR NEIGHBOR_ADDR_STR2
5741 "Apply route map to neighbor\n"
5742 "Name of route map\n"
5743 "Apply map to incoming routes\n"
5744 "Apply map to outbound routes\n")
5745
5746 /* Set unsuppress-map to the peer. */
5747 static int peer_unsuppress_map_set_vty(struct vty *vty, const char *ip_str,
5748 afi_t afi, safi_t safi,
5749 const char *name_str)
5750 {
5751 int ret;
5752 struct peer *peer;
5753 struct route_map *route_map;
5754
5755 peer = peer_and_group_lookup_vty(vty, ip_str);
5756 if (!peer)
5757 return CMD_WARNING_CONFIG_FAILED;
5758
5759 route_map = route_map_lookup_warn_noexist(vty, name_str);
5760 ret = peer_unsuppress_map_set(peer, afi, safi, name_str, route_map);
5761
5762 return bgp_vty_return(vty, ret);
5763 }
5764
5765 /* Unset route-map from the peer. */
5766 static int peer_unsuppress_map_unset_vty(struct vty *vty, const char *ip_str,
5767 afi_t afi, safi_t safi)
5768 {
5769 int ret;
5770 struct peer *peer;
5771
5772 peer = peer_and_group_lookup_vty(vty, ip_str);
5773 if (!peer)
5774 return CMD_WARNING_CONFIG_FAILED;
5775
5776 ret = peer_unsuppress_map_unset(peer, afi, safi);
5777
5778 return bgp_vty_return(vty, ret);
5779 }
5780
5781 DEFUN (neighbor_unsuppress_map,
5782 neighbor_unsuppress_map_cmd,
5783 "neighbor <A.B.C.D|X:X::X:X|WORD> unsuppress-map WORD",
5784 NEIGHBOR_STR
5785 NEIGHBOR_ADDR_STR2
5786 "Route-map to selectively unsuppress suppressed routes\n"
5787 "Name of route map\n")
5788 {
5789 int idx_peer = 1;
5790 int idx_word = 3;
5791 return peer_unsuppress_map_set_vty(
5792 vty, argv[idx_peer]->arg, bgp_node_afi(vty), bgp_node_safi(vty),
5793 argv[idx_word]->arg);
5794 }
5795
5796 ALIAS_HIDDEN(neighbor_unsuppress_map, neighbor_unsuppress_map_hidden_cmd,
5797 "neighbor <A.B.C.D|X:X::X:X|WORD> unsuppress-map WORD",
5798 NEIGHBOR_STR NEIGHBOR_ADDR_STR2
5799 "Route-map to selectively unsuppress suppressed routes\n"
5800 "Name of route map\n")
5801
5802 DEFUN (no_neighbor_unsuppress_map,
5803 no_neighbor_unsuppress_map_cmd,
5804 "no neighbor <A.B.C.D|X:X::X:X|WORD> unsuppress-map WORD",
5805 NO_STR
5806 NEIGHBOR_STR
5807 NEIGHBOR_ADDR_STR2
5808 "Route-map to selectively unsuppress suppressed routes\n"
5809 "Name of route map\n")
5810 {
5811 int idx_peer = 2;
5812 return peer_unsuppress_map_unset_vty(vty, argv[idx_peer]->arg,
5813 bgp_node_afi(vty),
5814 bgp_node_safi(vty));
5815 }
5816
5817 ALIAS_HIDDEN(no_neighbor_unsuppress_map, no_neighbor_unsuppress_map_hidden_cmd,
5818 "no neighbor <A.B.C.D|X:X::X:X|WORD> unsuppress-map WORD",
5819 NO_STR NEIGHBOR_STR NEIGHBOR_ADDR_STR2
5820 "Route-map to selectively unsuppress suppressed routes\n"
5821 "Name of route map\n")
5822
5823 static int peer_maximum_prefix_set_vty(struct vty *vty, const char *ip_str,
5824 afi_t afi, safi_t safi,
5825 const char *num_str,
5826 const char *threshold_str, int warning,
5827 const char *restart_str)
5828 {
5829 int ret;
5830 struct peer *peer;
5831 uint32_t max;
5832 uint8_t threshold;
5833 uint16_t restart;
5834
5835 peer = peer_and_group_lookup_vty(vty, ip_str);
5836 if (!peer)
5837 return CMD_WARNING_CONFIG_FAILED;
5838
5839 max = strtoul(num_str, NULL, 10);
5840 if (threshold_str)
5841 threshold = atoi(threshold_str);
5842 else
5843 threshold = MAXIMUM_PREFIX_THRESHOLD_DEFAULT;
5844
5845 if (restart_str)
5846 restart = atoi(restart_str);
5847 else
5848 restart = 0;
5849
5850 ret = peer_maximum_prefix_set(peer, afi, safi, max, threshold, warning,
5851 restart);
5852
5853 return bgp_vty_return(vty, ret);
5854 }
5855
5856 static int peer_maximum_prefix_unset_vty(struct vty *vty, const char *ip_str,
5857 afi_t afi, safi_t safi)
5858 {
5859 int ret;
5860 struct peer *peer;
5861
5862 peer = peer_and_group_lookup_vty(vty, ip_str);
5863 if (!peer)
5864 return CMD_WARNING_CONFIG_FAILED;
5865
5866 ret = peer_maximum_prefix_unset(peer, afi, safi);
5867
5868 return bgp_vty_return(vty, ret);
5869 }
5870
5871 /* Maximum number of prefix configuration. prefix count is different
5872 for each peer configuration. So this configuration can be set for
5873 each peer configuration. */
5874 DEFUN (neighbor_maximum_prefix,
5875 neighbor_maximum_prefix_cmd,
5876 "neighbor <A.B.C.D|X:X::X:X|WORD> maximum-prefix (1-4294967295)",
5877 NEIGHBOR_STR
5878 NEIGHBOR_ADDR_STR2
5879 "Maximum number of prefix accept from this peer\n"
5880 "maximum no. of prefix limit\n")
5881 {
5882 int idx_peer = 1;
5883 int idx_number = 3;
5884 return peer_maximum_prefix_set_vty(
5885 vty, argv[idx_peer]->arg, bgp_node_afi(vty), bgp_node_safi(vty),
5886 argv[idx_number]->arg, NULL, 0, NULL);
5887 }
5888
5889 ALIAS_HIDDEN(neighbor_maximum_prefix, neighbor_maximum_prefix_hidden_cmd,
5890 "neighbor <A.B.C.D|X:X::X:X|WORD> maximum-prefix (1-4294967295)",
5891 NEIGHBOR_STR NEIGHBOR_ADDR_STR2
5892 "Maximum number of prefix accept from this peer\n"
5893 "maximum no. of prefix limit\n")
5894
5895 DEFUN (neighbor_maximum_prefix_threshold,
5896 neighbor_maximum_prefix_threshold_cmd,
5897 "neighbor <A.B.C.D|X:X::X:X|WORD> maximum-prefix (1-4294967295) (1-100)",
5898 NEIGHBOR_STR
5899 NEIGHBOR_ADDR_STR2
5900 "Maximum number of prefix accept from this peer\n"
5901 "maximum no. of prefix limit\n"
5902 "Threshold value (%) at which to generate a warning msg\n")
5903 {
5904 int idx_peer = 1;
5905 int idx_number = 3;
5906 int idx_number_2 = 4;
5907 return peer_maximum_prefix_set_vty(
5908 vty, argv[idx_peer]->arg, bgp_node_afi(vty), bgp_node_safi(vty),
5909 argv[idx_number]->arg, argv[idx_number_2]->arg, 0, NULL);
5910 }
5911
5912 ALIAS_HIDDEN(
5913 neighbor_maximum_prefix_threshold,
5914 neighbor_maximum_prefix_threshold_hidden_cmd,
5915 "neighbor <A.B.C.D|X:X::X:X|WORD> maximum-prefix (1-4294967295) (1-100)",
5916 NEIGHBOR_STR NEIGHBOR_ADDR_STR2
5917 "Maximum number of prefix accept from this peer\n"
5918 "maximum no. of prefix limit\n"
5919 "Threshold value (%) at which to generate a warning msg\n")
5920
5921 DEFUN (neighbor_maximum_prefix_warning,
5922 neighbor_maximum_prefix_warning_cmd,
5923 "neighbor <A.B.C.D|X:X::X:X|WORD> maximum-prefix (1-4294967295) warning-only",
5924 NEIGHBOR_STR
5925 NEIGHBOR_ADDR_STR2
5926 "Maximum number of prefix accept from this peer\n"
5927 "maximum no. of prefix limit\n"
5928 "Only give warning message when limit is exceeded\n")
5929 {
5930 int idx_peer = 1;
5931 int idx_number = 3;
5932 return peer_maximum_prefix_set_vty(
5933 vty, argv[idx_peer]->arg, bgp_node_afi(vty), bgp_node_safi(vty),
5934 argv[idx_number]->arg, NULL, 1, NULL);
5935 }
5936
5937 ALIAS_HIDDEN(
5938 neighbor_maximum_prefix_warning,
5939 neighbor_maximum_prefix_warning_hidden_cmd,
5940 "neighbor <A.B.C.D|X:X::X:X|WORD> maximum-prefix (1-4294967295) warning-only",
5941 NEIGHBOR_STR NEIGHBOR_ADDR_STR2
5942 "Maximum number of prefix accept from this peer\n"
5943 "maximum no. of prefix limit\n"
5944 "Only give warning message when limit is exceeded\n")
5945
5946 DEFUN (neighbor_maximum_prefix_threshold_warning,
5947 neighbor_maximum_prefix_threshold_warning_cmd,
5948 "neighbor <A.B.C.D|X:X::X:X|WORD> maximum-prefix (1-4294967295) (1-100) warning-only",
5949 NEIGHBOR_STR
5950 NEIGHBOR_ADDR_STR2
5951 "Maximum number of prefix accept from this peer\n"
5952 "maximum no. of prefix limit\n"
5953 "Threshold value (%) at which to generate a warning msg\n"
5954 "Only give warning message when limit is exceeded\n")
5955 {
5956 int idx_peer = 1;
5957 int idx_number = 3;
5958 int idx_number_2 = 4;
5959 return peer_maximum_prefix_set_vty(
5960 vty, argv[idx_peer]->arg, bgp_node_afi(vty), bgp_node_safi(vty),
5961 argv[idx_number]->arg, argv[idx_number_2]->arg, 1, NULL);
5962 }
5963
5964 ALIAS_HIDDEN(
5965 neighbor_maximum_prefix_threshold_warning,
5966 neighbor_maximum_prefix_threshold_warning_hidden_cmd,
5967 "neighbor <A.B.C.D|X:X::X:X|WORD> maximum-prefix (1-4294967295) (1-100) warning-only",
5968 NEIGHBOR_STR NEIGHBOR_ADDR_STR2
5969 "Maximum number of prefix accept from this peer\n"
5970 "maximum no. of prefix limit\n"
5971 "Threshold value (%) at which to generate a warning msg\n"
5972 "Only give warning message when limit is exceeded\n")
5973
5974 DEFUN (neighbor_maximum_prefix_restart,
5975 neighbor_maximum_prefix_restart_cmd,
5976 "neighbor <A.B.C.D|X:X::X:X|WORD> maximum-prefix (1-4294967295) restart (1-65535)",
5977 NEIGHBOR_STR
5978 NEIGHBOR_ADDR_STR2
5979 "Maximum number of prefix accept from this peer\n"
5980 "maximum no. of prefix limit\n"
5981 "Restart bgp connection after limit is exceeded\n"
5982 "Restart interval in minutes\n")
5983 {
5984 int idx_peer = 1;
5985 int idx_number = 3;
5986 int idx_number_2 = 5;
5987 return peer_maximum_prefix_set_vty(
5988 vty, argv[idx_peer]->arg, bgp_node_afi(vty), bgp_node_safi(vty),
5989 argv[idx_number]->arg, NULL, 0, argv[idx_number_2]->arg);
5990 }
5991
5992 ALIAS_HIDDEN(
5993 neighbor_maximum_prefix_restart,
5994 neighbor_maximum_prefix_restart_hidden_cmd,
5995 "neighbor <A.B.C.D|X:X::X:X|WORD> maximum-prefix (1-4294967295) restart (1-65535)",
5996 NEIGHBOR_STR NEIGHBOR_ADDR_STR2
5997 "Maximum number of prefix accept from this peer\n"
5998 "maximum no. of prefix limit\n"
5999 "Restart bgp connection after limit is exceeded\n"
6000 "Restart interval in minutes\n")
6001
6002 DEFUN (neighbor_maximum_prefix_threshold_restart,
6003 neighbor_maximum_prefix_threshold_restart_cmd,
6004 "neighbor <A.B.C.D|X:X::X:X|WORD> maximum-prefix (1-4294967295) (1-100) restart (1-65535)",
6005 NEIGHBOR_STR
6006 NEIGHBOR_ADDR_STR2
6007 "Maximum number of prefixes to accept from this peer\n"
6008 "maximum no. of prefix limit\n"
6009 "Threshold value (%) at which to generate a warning msg\n"
6010 "Restart bgp connection after limit is exceeded\n"
6011 "Restart interval in minutes\n")
6012 {
6013 int idx_peer = 1;
6014 int idx_number = 3;
6015 int idx_number_2 = 4;
6016 int idx_number_3 = 6;
6017 return peer_maximum_prefix_set_vty(
6018 vty, argv[idx_peer]->arg, bgp_node_afi(vty), bgp_node_safi(vty),
6019 argv[idx_number]->arg, argv[idx_number_2]->arg, 0,
6020 argv[idx_number_3]->arg);
6021 }
6022
6023 ALIAS_HIDDEN(
6024 neighbor_maximum_prefix_threshold_restart,
6025 neighbor_maximum_prefix_threshold_restart_hidden_cmd,
6026 "neighbor <A.B.C.D|X:X::X:X|WORD> maximum-prefix (1-4294967295) (1-100) restart (1-65535)",
6027 NEIGHBOR_STR NEIGHBOR_ADDR_STR2
6028 "Maximum number of prefixes to accept from this peer\n"
6029 "maximum no. of prefix limit\n"
6030 "Threshold value (%) at which to generate a warning msg\n"
6031 "Restart bgp connection after limit is exceeded\n"
6032 "Restart interval in minutes\n")
6033
6034 DEFUN (no_neighbor_maximum_prefix,
6035 no_neighbor_maximum_prefix_cmd,
6036 "no neighbor <A.B.C.D|X:X::X:X|WORD> maximum-prefix [(1-4294967295) [(1-100)] [restart (1-65535)] [warning-only]]",
6037 NO_STR
6038 NEIGHBOR_STR
6039 NEIGHBOR_ADDR_STR2
6040 "Maximum number of prefixes to accept from this peer\n"
6041 "maximum no. of prefix limit\n"
6042 "Threshold value (%) at which to generate a warning msg\n"
6043 "Restart bgp connection after limit is exceeded\n"
6044 "Restart interval in minutes\n"
6045 "Only give warning message when limit is exceeded\n")
6046 {
6047 int idx_peer = 2;
6048 return peer_maximum_prefix_unset_vty(vty, argv[idx_peer]->arg,
6049 bgp_node_afi(vty),
6050 bgp_node_safi(vty));
6051 }
6052
6053 ALIAS_HIDDEN(
6054 no_neighbor_maximum_prefix, no_neighbor_maximum_prefix_hidden_cmd,
6055 "no neighbor <A.B.C.D|X:X::X:X|WORD> maximum-prefix [(1-4294967295) [(1-100)] [restart (1-65535)] [warning-only]]",
6056 NO_STR NEIGHBOR_STR NEIGHBOR_ADDR_STR2
6057 "Maximum number of prefixes to accept from this peer\n"
6058 "maximum no. of prefix limit\n"
6059 "Threshold value (%) at which to generate a warning msg\n"
6060 "Restart bgp connection after limit is exceeded\n"
6061 "Restart interval in minutes\n"
6062 "Only give warning message when limit is exceeded\n")
6063
6064
6065 /* "neighbor allowas-in" */
6066 DEFUN (neighbor_allowas_in,
6067 neighbor_allowas_in_cmd,
6068 "neighbor <A.B.C.D|X:X::X:X|WORD> allowas-in [<(1-10)|origin>]",
6069 NEIGHBOR_STR
6070 NEIGHBOR_ADDR_STR2
6071 "Accept as-path with my AS present in it\n"
6072 "Number of occurences of AS number\n"
6073 "Only accept my AS in the as-path if the route was originated in my AS\n")
6074 {
6075 int idx_peer = 1;
6076 int idx_number_origin = 3;
6077 int ret;
6078 int origin = 0;
6079 struct peer *peer;
6080 int allow_num = 0;
6081
6082 peer = peer_and_group_lookup_vty(vty, argv[idx_peer]->arg);
6083 if (!peer)
6084 return CMD_WARNING_CONFIG_FAILED;
6085
6086 if (argc <= idx_number_origin)
6087 allow_num = 3;
6088 else {
6089 if (argv[idx_number_origin]->type == WORD_TKN)
6090 origin = 1;
6091 else
6092 allow_num = atoi(argv[idx_number_origin]->arg);
6093 }
6094
6095 ret = peer_allowas_in_set(peer, bgp_node_afi(vty), bgp_node_safi(vty),
6096 allow_num, origin);
6097
6098 return bgp_vty_return(vty, ret);
6099 }
6100
6101 ALIAS_HIDDEN(
6102 neighbor_allowas_in, neighbor_allowas_in_hidden_cmd,
6103 "neighbor <A.B.C.D|X:X::X:X|WORD> allowas-in [<(1-10)|origin>]",
6104 NEIGHBOR_STR NEIGHBOR_ADDR_STR2
6105 "Accept as-path with my AS present in it\n"
6106 "Number of occurences of AS number\n"
6107 "Only accept my AS in the as-path if the route was originated in my AS\n")
6108
6109 DEFUN (no_neighbor_allowas_in,
6110 no_neighbor_allowas_in_cmd,
6111 "no neighbor <A.B.C.D|X:X::X:X|WORD> allowas-in [<(1-10)|origin>]",
6112 NO_STR
6113 NEIGHBOR_STR
6114 NEIGHBOR_ADDR_STR2
6115 "allow local ASN appears in aspath attribute\n"
6116 "Number of occurences of AS number\n"
6117 "Only accept my AS in the as-path if the route was originated in my AS\n")
6118 {
6119 int idx_peer = 2;
6120 int ret;
6121 struct peer *peer;
6122
6123 peer = peer_and_group_lookup_vty(vty, argv[idx_peer]->arg);
6124 if (!peer)
6125 return CMD_WARNING_CONFIG_FAILED;
6126
6127 ret = peer_allowas_in_unset(peer, bgp_node_afi(vty),
6128 bgp_node_safi(vty));
6129
6130 return bgp_vty_return(vty, ret);
6131 }
6132
6133 ALIAS_HIDDEN(
6134 no_neighbor_allowas_in, no_neighbor_allowas_in_hidden_cmd,
6135 "no neighbor <A.B.C.D|X:X::X:X|WORD> allowas-in [<(1-10)|origin>]",
6136 NO_STR NEIGHBOR_STR NEIGHBOR_ADDR_STR2
6137 "allow local ASN appears in aspath attribute\n"
6138 "Number of occurences of AS number\n"
6139 "Only accept my AS in the as-path if the route was originated in my AS\n")
6140
6141 DEFUN (neighbor_ttl_security,
6142 neighbor_ttl_security_cmd,
6143 "neighbor <A.B.C.D|X:X::X:X|WORD> ttl-security hops (1-254)",
6144 NEIGHBOR_STR
6145 NEIGHBOR_ADDR_STR2
6146 "BGP ttl-security parameters\n"
6147 "Specify the maximum number of hops to the BGP peer\n"
6148 "Number of hops to BGP peer\n")
6149 {
6150 int idx_peer = 1;
6151 int idx_number = 4;
6152 struct peer *peer;
6153 int gtsm_hops;
6154
6155 peer = peer_and_group_lookup_vty(vty, argv[idx_peer]->arg);
6156 if (!peer)
6157 return CMD_WARNING_CONFIG_FAILED;
6158
6159 gtsm_hops = strtoul(argv[idx_number]->arg, NULL, 10);
6160
6161 /*
6162 * If 'neighbor swpX', then this is for directly connected peers,
6163 * we should not accept a ttl-security hops value greater than 1.
6164 */
6165 if (peer->conf_if && (gtsm_hops > 1)) {
6166 vty_out(vty,
6167 "%s is directly connected peer, hops cannot exceed 1\n",
6168 argv[idx_peer]->arg);
6169 return CMD_WARNING_CONFIG_FAILED;
6170 }
6171
6172 return bgp_vty_return(vty, peer_ttl_security_hops_set(peer, gtsm_hops));
6173 }
6174
6175 DEFUN (no_neighbor_ttl_security,
6176 no_neighbor_ttl_security_cmd,
6177 "no neighbor <A.B.C.D|X:X::X:X|WORD> ttl-security hops (1-254)",
6178 NO_STR
6179 NEIGHBOR_STR
6180 NEIGHBOR_ADDR_STR2
6181 "BGP ttl-security parameters\n"
6182 "Specify the maximum number of hops to the BGP peer\n"
6183 "Number of hops to BGP peer\n")
6184 {
6185 int idx_peer = 2;
6186 struct peer *peer;
6187
6188 peer = peer_and_group_lookup_vty(vty, argv[idx_peer]->arg);
6189 if (!peer)
6190 return CMD_WARNING_CONFIG_FAILED;
6191
6192 return bgp_vty_return(vty, peer_ttl_security_hops_unset(peer));
6193 }
6194
6195 DEFUN (neighbor_addpath_tx_all_paths,
6196 neighbor_addpath_tx_all_paths_cmd,
6197 "neighbor <A.B.C.D|X:X::X:X|WORD> addpath-tx-all-paths",
6198 NEIGHBOR_STR
6199 NEIGHBOR_ADDR_STR2
6200 "Use addpath to advertise all paths to a neighbor\n")
6201 {
6202 int idx_peer = 1;
6203 struct peer *peer;
6204
6205 peer = peer_and_group_lookup_vty(vty, argv[idx_peer]->arg);
6206 if (!peer)
6207 return CMD_WARNING_CONFIG_FAILED;
6208
6209 bgp_addpath_set_peer_type(peer, bgp_node_afi(vty), bgp_node_safi(vty),
6210 BGP_ADDPATH_ALL);
6211 return CMD_SUCCESS;
6212 }
6213
6214 ALIAS_HIDDEN(neighbor_addpath_tx_all_paths,
6215 neighbor_addpath_tx_all_paths_hidden_cmd,
6216 "neighbor <A.B.C.D|X:X::X:X|WORD> addpath-tx-all-paths",
6217 NEIGHBOR_STR NEIGHBOR_ADDR_STR2
6218 "Use addpath to advertise all paths to a neighbor\n")
6219
6220 DEFUN (no_neighbor_addpath_tx_all_paths,
6221 no_neighbor_addpath_tx_all_paths_cmd,
6222 "no neighbor <A.B.C.D|X:X::X:X|WORD> addpath-tx-all-paths",
6223 NO_STR
6224 NEIGHBOR_STR
6225 NEIGHBOR_ADDR_STR2
6226 "Use addpath to advertise all paths to a neighbor\n")
6227 {
6228 int idx_peer = 2;
6229 struct peer *peer;
6230
6231 peer = peer_and_group_lookup_vty(vty, argv[idx_peer]->arg);
6232 if (!peer)
6233 return CMD_WARNING_CONFIG_FAILED;
6234
6235 if (peer->addpath_type[bgp_node_afi(vty)][bgp_node_safi(vty)]
6236 != BGP_ADDPATH_ALL) {
6237 vty_out(vty,
6238 "%% Peer not currently configured to transmit all paths.");
6239 return CMD_WARNING_CONFIG_FAILED;
6240 }
6241
6242 bgp_addpath_set_peer_type(peer, bgp_node_afi(vty), bgp_node_safi(vty),
6243 BGP_ADDPATH_NONE);
6244
6245 return CMD_SUCCESS;
6246 }
6247
6248 ALIAS_HIDDEN(no_neighbor_addpath_tx_all_paths,
6249 no_neighbor_addpath_tx_all_paths_hidden_cmd,
6250 "no neighbor <A.B.C.D|X:X::X:X|WORD> addpath-tx-all-paths",
6251 NO_STR NEIGHBOR_STR NEIGHBOR_ADDR_STR2
6252 "Use addpath to advertise all paths to a neighbor\n")
6253
6254 DEFUN (neighbor_addpath_tx_bestpath_per_as,
6255 neighbor_addpath_tx_bestpath_per_as_cmd,
6256 "neighbor <A.B.C.D|X:X::X:X|WORD> addpath-tx-bestpath-per-AS",
6257 NEIGHBOR_STR
6258 NEIGHBOR_ADDR_STR2
6259 "Use addpath to advertise the bestpath per each neighboring AS\n")
6260 {
6261 int idx_peer = 1;
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 bgp_addpath_set_peer_type(peer, bgp_node_afi(vty), bgp_node_safi(vty),
6269 BGP_ADDPATH_BEST_PER_AS);
6270
6271 return CMD_SUCCESS;
6272 }
6273
6274 ALIAS_HIDDEN(neighbor_addpath_tx_bestpath_per_as,
6275 neighbor_addpath_tx_bestpath_per_as_hidden_cmd,
6276 "neighbor <A.B.C.D|X:X::X:X|WORD> addpath-tx-bestpath-per-AS",
6277 NEIGHBOR_STR NEIGHBOR_ADDR_STR2
6278 "Use addpath to advertise the bestpath per each neighboring AS\n")
6279
6280 DEFUN (no_neighbor_addpath_tx_bestpath_per_as,
6281 no_neighbor_addpath_tx_bestpath_per_as_cmd,
6282 "no neighbor <A.B.C.D|X:X::X:X|WORD> addpath-tx-bestpath-per-AS",
6283 NO_STR
6284 NEIGHBOR_STR
6285 NEIGHBOR_ADDR_STR2
6286 "Use addpath to advertise the bestpath per each neighboring AS\n")
6287 {
6288 int idx_peer = 2;
6289 struct peer *peer;
6290
6291 peer = peer_and_group_lookup_vty(vty, argv[idx_peer]->arg);
6292 if (!peer)
6293 return CMD_WARNING_CONFIG_FAILED;
6294
6295 if (peer->addpath_type[bgp_node_afi(vty)][bgp_node_safi(vty)]
6296 != BGP_ADDPATH_BEST_PER_AS) {
6297 vty_out(vty,
6298 "%% Peer not currently configured to transmit all best path per as.");
6299 return CMD_WARNING_CONFIG_FAILED;
6300 }
6301
6302 bgp_addpath_set_peer_type(peer, bgp_node_afi(vty), bgp_node_safi(vty),
6303 BGP_ADDPATH_NONE);
6304
6305 return CMD_SUCCESS;
6306 }
6307
6308 ALIAS_HIDDEN(no_neighbor_addpath_tx_bestpath_per_as,
6309 no_neighbor_addpath_tx_bestpath_per_as_hidden_cmd,
6310 "no neighbor <A.B.C.D|X:X::X:X|WORD> addpath-tx-bestpath-per-AS",
6311 NO_STR NEIGHBOR_STR NEIGHBOR_ADDR_STR2
6312 "Use addpath to advertise the bestpath per each neighboring AS\n")
6313
6314 static int set_ecom_list(struct vty *vty, int argc, struct cmd_token **argv,
6315 struct ecommunity **list)
6316 {
6317 struct ecommunity *ecom = NULL;
6318 struct ecommunity *ecomadd;
6319
6320 for (; argc; --argc, ++argv) {
6321
6322 ecomadd = ecommunity_str2com(argv[0]->arg,
6323 ECOMMUNITY_ROUTE_TARGET, 0);
6324 if (!ecomadd) {
6325 vty_out(vty, "Malformed community-list value\n");
6326 if (ecom)
6327 ecommunity_free(&ecom);
6328 return CMD_WARNING_CONFIG_FAILED;
6329 }
6330
6331 if (ecom) {
6332 ecommunity_merge(ecom, ecomadd);
6333 ecommunity_free(&ecomadd);
6334 } else {
6335 ecom = ecomadd;
6336 }
6337 }
6338
6339 if (*list) {
6340 ecommunity_free(&*list);
6341 }
6342 *list = ecom;
6343
6344 return CMD_SUCCESS;
6345 }
6346
6347 /*
6348 * v2vimport is true if we are handling a `import vrf ...` command
6349 */
6350 static afi_t vpn_policy_getafi(struct vty *vty, struct bgp *bgp, bool v2vimport)
6351 {
6352 afi_t afi;
6353
6354 switch (vty->node) {
6355 case BGP_IPV4_NODE:
6356 afi = AFI_IP;
6357 break;
6358 case BGP_IPV6_NODE:
6359 afi = AFI_IP6;
6360 break;
6361 default:
6362 vty_out(vty,
6363 "%% context error: valid only in address-family <ipv4|ipv6> unicast block\n");
6364 return AFI_MAX;
6365 }
6366
6367 if (!v2vimport) {
6368 if (CHECK_FLAG(bgp->af_flags[afi][SAFI_UNICAST],
6369 BGP_CONFIG_VRF_TO_VRF_IMPORT)
6370 || CHECK_FLAG(bgp->af_flags[afi][SAFI_UNICAST],
6371 BGP_CONFIG_VRF_TO_VRF_EXPORT)) {
6372 vty_out(vty,
6373 "%% error: Please unconfigure import vrf commands before using vpn commands\n");
6374 return AFI_MAX;
6375 }
6376 } else {
6377 if (CHECK_FLAG(bgp->af_flags[afi][SAFI_UNICAST],
6378 BGP_CONFIG_VRF_TO_MPLSVPN_EXPORT)
6379 || CHECK_FLAG(bgp->af_flags[afi][SAFI_UNICAST],
6380 BGP_CONFIG_MPLSVPN_TO_VRF_IMPORT)) {
6381 vty_out(vty,
6382 "%% error: Please unconfigure vpn to vrf commands before using import vrf commands\n");
6383 return AFI_MAX;
6384 }
6385 }
6386 return afi;
6387 }
6388
6389 DEFPY (af_rd_vpn_export,
6390 af_rd_vpn_export_cmd,
6391 "[no] rd vpn export ASN:NN_OR_IP-ADDRESS:NN$rd_str",
6392 NO_STR
6393 "Specify route distinguisher\n"
6394 "Between current address-family and vpn\n"
6395 "For routes leaked from current address-family to vpn\n"
6396 "Route Distinguisher (<as-number>:<number> | <ip-address>:<number>)\n")
6397 {
6398 VTY_DECLVAR_CONTEXT(bgp, bgp);
6399 struct prefix_rd prd;
6400 int ret;
6401 afi_t afi;
6402 int idx = 0;
6403 int yes = 1;
6404
6405 if (argv_find(argv, argc, "no", &idx))
6406 yes = 0;
6407
6408 if (yes) {
6409 ret = str2prefix_rd(rd_str, &prd);
6410 if (!ret) {
6411 vty_out(vty, "%% Malformed rd\n");
6412 return CMD_WARNING_CONFIG_FAILED;
6413 }
6414 }
6415
6416 afi = vpn_policy_getafi(vty, bgp, false);
6417 if (afi == AFI_MAX)
6418 return CMD_WARNING_CONFIG_FAILED;
6419
6420 /*
6421 * pre-change: un-export vpn routes (vpn->vrf routes unaffected)
6422 */
6423 vpn_leak_prechange(BGP_VPN_POLICY_DIR_TOVPN, afi,
6424 bgp_get_default(), bgp);
6425
6426 if (yes) {
6427 bgp->vpn_policy[afi].tovpn_rd = prd;
6428 SET_FLAG(bgp->vpn_policy[afi].flags,
6429 BGP_VPN_POLICY_TOVPN_RD_SET);
6430 } else {
6431 UNSET_FLAG(bgp->vpn_policy[afi].flags,
6432 BGP_VPN_POLICY_TOVPN_RD_SET);
6433 }
6434
6435 /* post-change: re-export vpn routes */
6436 vpn_leak_postchange(BGP_VPN_POLICY_DIR_TOVPN, afi,
6437 bgp_get_default(), bgp);
6438
6439 return CMD_SUCCESS;
6440 }
6441
6442 ALIAS (af_rd_vpn_export,
6443 af_no_rd_vpn_export_cmd,
6444 "no rd vpn export",
6445 NO_STR
6446 "Specify route distinguisher\n"
6447 "Between current address-family and vpn\n"
6448 "For routes leaked from current address-family to vpn\n")
6449
6450 DEFPY (af_label_vpn_export,
6451 af_label_vpn_export_cmd,
6452 "[no] label vpn export <(0-1048575)$label_val|auto$label_auto>",
6453 NO_STR
6454 "label value for VRF\n"
6455 "Between current address-family and vpn\n"
6456 "For routes leaked from current address-family to vpn\n"
6457 "Label Value <0-1048575>\n"
6458 "Automatically assign a label\n")
6459 {
6460 VTY_DECLVAR_CONTEXT(bgp, bgp);
6461 mpls_label_t label = MPLS_LABEL_NONE;
6462 afi_t afi;
6463 int idx = 0;
6464 int yes = 1;
6465
6466 if (argv_find(argv, argc, "no", &idx))
6467 yes = 0;
6468
6469 /* If "no ...", squash trailing parameter */
6470 if (!yes)
6471 label_auto = NULL;
6472
6473 if (yes) {
6474 if (!label_auto)
6475 label = label_val; /* parser should force unsigned */
6476 }
6477
6478 afi = vpn_policy_getafi(vty, bgp, false);
6479 if (afi == AFI_MAX)
6480 return CMD_WARNING_CONFIG_FAILED;
6481
6482
6483 if (label_auto && CHECK_FLAG(bgp->vpn_policy[afi].flags,
6484 BGP_VPN_POLICY_TOVPN_LABEL_AUTO))
6485 /* no change */
6486 return CMD_SUCCESS;
6487
6488 /*
6489 * pre-change: un-export vpn routes (vpn->vrf routes unaffected)
6490 */
6491 vpn_leak_prechange(BGP_VPN_POLICY_DIR_TOVPN, afi,
6492 bgp_get_default(), bgp);
6493
6494 if (!label_auto && CHECK_FLAG(bgp->vpn_policy[afi].flags,
6495 BGP_VPN_POLICY_TOVPN_LABEL_AUTO)) {
6496
6497 if (bgp->vpn_policy[afi].tovpn_label != MPLS_LABEL_NONE) {
6498
6499 /*
6500 * label has previously been automatically
6501 * assigned by labelpool: release it
6502 *
6503 * NB if tovpn_label == MPLS_LABEL_NONE it
6504 * means the automatic assignment is in flight
6505 * and therefore the labelpool callback must
6506 * detect that the auto label is not needed.
6507 */
6508
6509 bgp_lp_release(LP_TYPE_VRF,
6510 &bgp->vpn_policy[afi],
6511 bgp->vpn_policy[afi].tovpn_label);
6512 }
6513 UNSET_FLAG(bgp->vpn_policy[afi].flags,
6514 BGP_VPN_POLICY_TOVPN_LABEL_AUTO);
6515 }
6516
6517 bgp->vpn_policy[afi].tovpn_label = label;
6518 if (label_auto) {
6519 SET_FLAG(bgp->vpn_policy[afi].flags,
6520 BGP_VPN_POLICY_TOVPN_LABEL_AUTO);
6521 bgp_lp_get(LP_TYPE_VRF, &bgp->vpn_policy[afi],
6522 vpn_leak_label_callback);
6523 }
6524
6525 /* post-change: re-export vpn routes */
6526 vpn_leak_postchange(BGP_VPN_POLICY_DIR_TOVPN, afi,
6527 bgp_get_default(), bgp);
6528
6529 return CMD_SUCCESS;
6530 }
6531
6532 ALIAS (af_label_vpn_export,
6533 af_no_label_vpn_export_cmd,
6534 "no label vpn export",
6535 NO_STR
6536 "label value for VRF\n"
6537 "Between current address-family and vpn\n"
6538 "For routes leaked from current address-family to vpn\n")
6539
6540 DEFPY (af_nexthop_vpn_export,
6541 af_nexthop_vpn_export_cmd,
6542 "[no] nexthop vpn export <A.B.C.D|X:X::X:X>$nexthop_str",
6543 NO_STR
6544 "Specify next hop to use for VRF advertised prefixes\n"
6545 "Between current address-family and vpn\n"
6546 "For routes leaked from current address-family to vpn\n"
6547 "IPv4 prefix\n"
6548 "IPv6 prefix\n")
6549 {
6550 VTY_DECLVAR_CONTEXT(bgp, bgp);
6551 afi_t afi;
6552 struct prefix p;
6553 int idx = 0;
6554 int yes = 1;
6555
6556 if (argv_find(argv, argc, "no", &idx))
6557 yes = 0;
6558
6559 if (yes) {
6560 if (!sockunion2hostprefix(nexthop_str, &p))
6561 return CMD_WARNING_CONFIG_FAILED;
6562 }
6563
6564 afi = vpn_policy_getafi(vty, bgp, false);
6565 if (afi == AFI_MAX)
6566 return CMD_WARNING_CONFIG_FAILED;
6567
6568 /*
6569 * pre-change: un-export vpn routes (vpn->vrf routes unaffected)
6570 */
6571 vpn_leak_prechange(BGP_VPN_POLICY_DIR_TOVPN, afi,
6572 bgp_get_default(), bgp);
6573
6574 if (yes) {
6575 bgp->vpn_policy[afi].tovpn_nexthop = p;
6576 SET_FLAG(bgp->vpn_policy[afi].flags,
6577 BGP_VPN_POLICY_TOVPN_NEXTHOP_SET);
6578 } else {
6579 UNSET_FLAG(bgp->vpn_policy[afi].flags,
6580 BGP_VPN_POLICY_TOVPN_NEXTHOP_SET);
6581 }
6582
6583 /* post-change: re-export vpn routes */
6584 vpn_leak_postchange(BGP_VPN_POLICY_DIR_TOVPN, afi,
6585 bgp_get_default(), bgp);
6586
6587 return CMD_SUCCESS;
6588 }
6589
6590 ALIAS (af_nexthop_vpn_export,
6591 af_no_nexthop_vpn_export_cmd,
6592 "no nexthop vpn export",
6593 NO_STR
6594 "Specify next hop to use for VRF advertised prefixes\n"
6595 "Between current address-family and vpn\n"
6596 "For routes leaked from current address-family to vpn\n")
6597
6598 static int vpn_policy_getdirs(struct vty *vty, const char *dstr, int *dodir)
6599 {
6600 if (!strcmp(dstr, "import")) {
6601 dodir[BGP_VPN_POLICY_DIR_FROMVPN] = 1;
6602 } else if (!strcmp(dstr, "export")) {
6603 dodir[BGP_VPN_POLICY_DIR_TOVPN] = 1;
6604 } else if (!strcmp(dstr, "both")) {
6605 dodir[BGP_VPN_POLICY_DIR_FROMVPN] = 1;
6606 dodir[BGP_VPN_POLICY_DIR_TOVPN] = 1;
6607 } else {
6608 vty_out(vty, "%% direction parse error\n");
6609 return CMD_WARNING_CONFIG_FAILED;
6610 }
6611 return CMD_SUCCESS;
6612 }
6613
6614 DEFPY (af_rt_vpn_imexport,
6615 af_rt_vpn_imexport_cmd,
6616 "[no] <rt|route-target> vpn <import|export|both>$direction_str RTLIST...",
6617 NO_STR
6618 "Specify route target list\n"
6619 "Specify route target list\n"
6620 "Between current address-family and vpn\n"
6621 "For routes leaked from vpn to current address-family: match any\n"
6622 "For routes leaked from current address-family to vpn: set\n"
6623 "both import: match any and export: set\n"
6624 "Space separated route target list (A.B.C.D:MN|EF:OPQR|GHJK:MN)\n")
6625 {
6626 VTY_DECLVAR_CONTEXT(bgp, bgp);
6627 int ret;
6628 struct ecommunity *ecom = NULL;
6629 int dodir[BGP_VPN_POLICY_DIR_MAX] = {0};
6630 vpn_policy_direction_t dir;
6631 afi_t afi;
6632 int idx = 0;
6633 int yes = 1;
6634
6635 if (argv_find(argv, argc, "no", &idx))
6636 yes = 0;
6637
6638 afi = vpn_policy_getafi(vty, bgp, false);
6639 if (afi == AFI_MAX)
6640 return CMD_WARNING_CONFIG_FAILED;
6641
6642 ret = vpn_policy_getdirs(vty, direction_str, dodir);
6643 if (ret != CMD_SUCCESS)
6644 return ret;
6645
6646 if (yes) {
6647 if (!argv_find(argv, argc, "RTLIST", &idx)) {
6648 vty_out(vty, "%% Missing RTLIST\n");
6649 return CMD_WARNING_CONFIG_FAILED;
6650 }
6651 ret = set_ecom_list(vty, argc - idx, argv + idx, &ecom);
6652 if (ret != CMD_SUCCESS) {
6653 return ret;
6654 }
6655 }
6656
6657 for (dir = 0; dir < BGP_VPN_POLICY_DIR_MAX; ++dir) {
6658 if (!dodir[dir])
6659 continue;
6660
6661 vpn_leak_prechange(dir, afi, bgp_get_default(), bgp);
6662
6663 if (yes) {
6664 if (bgp->vpn_policy[afi].rtlist[dir])
6665 ecommunity_free(
6666 &bgp->vpn_policy[afi].rtlist[dir]);
6667 bgp->vpn_policy[afi].rtlist[dir] =
6668 ecommunity_dup(ecom);
6669 } else {
6670 if (bgp->vpn_policy[afi].rtlist[dir])
6671 ecommunity_free(
6672 &bgp->vpn_policy[afi].rtlist[dir]);
6673 bgp->vpn_policy[afi].rtlist[dir] = NULL;
6674 }
6675
6676 vpn_leak_postchange(dir, afi, bgp_get_default(), bgp);
6677 }
6678
6679 if (ecom)
6680 ecommunity_free(&ecom);
6681
6682 return CMD_SUCCESS;
6683 }
6684
6685 ALIAS (af_rt_vpn_imexport,
6686 af_no_rt_vpn_imexport_cmd,
6687 "no <rt|route-target> vpn <import|export|both>$direction_str",
6688 NO_STR
6689 "Specify route target list\n"
6690 "Specify route target list\n"
6691 "Between current address-family and vpn\n"
6692 "For routes leaked from vpn to current address-family\n"
6693 "For routes leaked from current address-family to vpn\n"
6694 "both import and export\n")
6695
6696 DEFPY (af_route_map_vpn_imexport,
6697 af_route_map_vpn_imexport_cmd,
6698 /* future: "route-map <vpn|evpn|vrf NAME> <import|export> RMAP" */
6699 "[no] route-map vpn <import|export>$direction_str RMAP$rmap_str",
6700 NO_STR
6701 "Specify route map\n"
6702 "Between current address-family and vpn\n"
6703 "For routes leaked from vpn to current address-family\n"
6704 "For routes leaked from current address-family to vpn\n"
6705 "name of route-map\n")
6706 {
6707 VTY_DECLVAR_CONTEXT(bgp, bgp);
6708 int ret;
6709 int dodir[BGP_VPN_POLICY_DIR_MAX] = {0};
6710 vpn_policy_direction_t dir;
6711 afi_t afi;
6712 int idx = 0;
6713 int yes = 1;
6714
6715 if (argv_find(argv, argc, "no", &idx))
6716 yes = 0;
6717
6718 afi = vpn_policy_getafi(vty, bgp, false);
6719 if (afi == AFI_MAX)
6720 return CMD_WARNING_CONFIG_FAILED;
6721
6722 ret = vpn_policy_getdirs(vty, direction_str, dodir);
6723 if (ret != CMD_SUCCESS)
6724 return ret;
6725
6726 for (dir = 0; dir < BGP_VPN_POLICY_DIR_MAX; ++dir) {
6727 if (!dodir[dir])
6728 continue;
6729
6730 vpn_leak_prechange(dir, afi, bgp_get_default(), bgp);
6731
6732 if (yes) {
6733 if (bgp->vpn_policy[afi].rmap_name[dir])
6734 XFREE(MTYPE_ROUTE_MAP_NAME,
6735 bgp->vpn_policy[afi].rmap_name[dir]);
6736 bgp->vpn_policy[afi].rmap_name[dir] = XSTRDUP(
6737 MTYPE_ROUTE_MAP_NAME, rmap_str);
6738 bgp->vpn_policy[afi].rmap[dir] =
6739 route_map_lookup_warn_noexist(vty, rmap_str);
6740 if (!bgp->vpn_policy[afi].rmap[dir])
6741 return CMD_SUCCESS;
6742 } else {
6743 if (bgp->vpn_policy[afi].rmap_name[dir])
6744 XFREE(MTYPE_ROUTE_MAP_NAME,
6745 bgp->vpn_policy[afi].rmap_name[dir]);
6746 bgp->vpn_policy[afi].rmap_name[dir] = NULL;
6747 bgp->vpn_policy[afi].rmap[dir] = NULL;
6748 }
6749
6750 vpn_leak_postchange(dir, afi, bgp_get_default(), bgp);
6751 }
6752
6753 return CMD_SUCCESS;
6754 }
6755
6756 ALIAS (af_route_map_vpn_imexport,
6757 af_no_route_map_vpn_imexport_cmd,
6758 "no route-map vpn <import|export>$direction_str",
6759 NO_STR
6760 "Specify route map\n"
6761 "Between current address-family and vpn\n"
6762 "For routes leaked from vpn to current address-family\n"
6763 "For routes leaked from current address-family to vpn\n")
6764
6765 DEFPY(af_import_vrf_route_map, af_import_vrf_route_map_cmd,
6766 "[no] import vrf route-map RMAP$rmap_str",
6767 NO_STR
6768 "Import routes from another VRF\n"
6769 "Vrf routes being filtered\n"
6770 "Specify route map\n"
6771 "name of route-map\n")
6772 {
6773 VTY_DECLVAR_CONTEXT(bgp, bgp);
6774 vpn_policy_direction_t dir = BGP_VPN_POLICY_DIR_FROMVPN;
6775 afi_t afi;
6776 int idx = 0;
6777 int yes = 1;
6778 struct bgp *bgp_default;
6779
6780 if (argv_find(argv, argc, "no", &idx))
6781 yes = 0;
6782
6783 afi = vpn_policy_getafi(vty, bgp, true);
6784 if (afi == AFI_MAX)
6785 return CMD_WARNING_CONFIG_FAILED;
6786
6787 bgp_default = bgp_get_default();
6788 if (!bgp_default) {
6789 int32_t ret;
6790 as_t as = bgp->as;
6791
6792 /* Auto-create assuming the same AS */
6793 ret = bgp_get(&bgp_default, &as, NULL,
6794 BGP_INSTANCE_TYPE_DEFAULT);
6795
6796 if (ret) {
6797 vty_out(vty,
6798 "VRF default is not configured as a bgp instance\n");
6799 return CMD_WARNING;
6800 }
6801 }
6802
6803 vpn_leak_prechange(dir, afi, bgp_get_default(), bgp);
6804
6805 if (yes) {
6806 if (bgp->vpn_policy[afi].rmap_name[dir])
6807 XFREE(MTYPE_ROUTE_MAP_NAME,
6808 bgp->vpn_policy[afi].rmap_name[dir]);
6809 bgp->vpn_policy[afi].rmap_name[dir] =
6810 XSTRDUP(MTYPE_ROUTE_MAP_NAME, rmap_str);
6811 bgp->vpn_policy[afi].rmap[dir] =
6812 route_map_lookup_warn_noexist(vty, rmap_str);
6813 if (!bgp->vpn_policy[afi].rmap[dir])
6814 return CMD_SUCCESS;
6815 } else {
6816 if (bgp->vpn_policy[afi].rmap_name[dir])
6817 XFREE(MTYPE_ROUTE_MAP_NAME,
6818 bgp->vpn_policy[afi].rmap_name[dir]);
6819 bgp->vpn_policy[afi].rmap_name[dir] = NULL;
6820 bgp->vpn_policy[afi].rmap[dir] = NULL;
6821 }
6822
6823 vpn_leak_postchange(dir, afi, bgp_get_default(), bgp);
6824
6825 return CMD_SUCCESS;
6826 }
6827
6828 ALIAS(af_import_vrf_route_map, af_no_import_vrf_route_map_cmd,
6829 "no import vrf route-map",
6830 NO_STR
6831 "Import routes from another VRF\n"
6832 "Vrf routes being filtered\n"
6833 "Specify route map\n")
6834
6835 DEFPY(bgp_imexport_vrf, bgp_imexport_vrf_cmd,
6836 "[no] import vrf VIEWVRFNAME$import_name",
6837 NO_STR
6838 "Import routes from another VRF\n"
6839 "VRF to import from\n"
6840 "The name of the VRF\n")
6841 {
6842 VTY_DECLVAR_CONTEXT(bgp, bgp);
6843 struct listnode *node;
6844 struct bgp *vrf_bgp, *bgp_default;
6845 int32_t ret = 0;
6846 as_t as = bgp->as;
6847 bool remove = false;
6848 int32_t idx = 0;
6849 char *vname;
6850 enum bgp_instance_type bgp_type = BGP_INSTANCE_TYPE_VRF;
6851 safi_t safi;
6852 afi_t afi;
6853
6854 if (import_name == NULL) {
6855 vty_out(vty, "%% Missing import name\n");
6856 return CMD_WARNING;
6857 }
6858
6859 if (argv_find(argv, argc, "no", &idx))
6860 remove = true;
6861
6862 afi = vpn_policy_getafi(vty, bgp, true);
6863 if (afi == AFI_MAX)
6864 return CMD_WARNING_CONFIG_FAILED;
6865
6866 safi = bgp_node_safi(vty);
6867
6868 if (((BGP_INSTANCE_TYPE_DEFAULT == bgp->inst_type)
6869 && (strcmp(import_name, VRF_DEFAULT_NAME) == 0))
6870 || (bgp->name && (strcmp(import_name, bgp->name) == 0))) {
6871 vty_out(vty, "%% Cannot %s vrf %s into itself\n",
6872 remove ? "unimport" : "import", import_name);
6873 return CMD_WARNING;
6874 }
6875
6876 bgp_default = bgp_get_default();
6877 if (!bgp_default) {
6878 /* Auto-create assuming the same AS */
6879 ret = bgp_get(&bgp_default, &as, NULL,
6880 BGP_INSTANCE_TYPE_DEFAULT);
6881
6882 if (ret) {
6883 vty_out(vty,
6884 "VRF default is not configured as a bgp instance\n");
6885 return CMD_WARNING;
6886 }
6887 }
6888
6889 vrf_bgp = bgp_lookup_by_name(import_name);
6890 if (!vrf_bgp) {
6891 if (strcmp(import_name, VRF_DEFAULT_NAME) == 0)
6892 vrf_bgp = bgp_default;
6893 else
6894 /* Auto-create assuming the same AS */
6895 ret = bgp_get(&vrf_bgp, &as, import_name, bgp_type);
6896
6897 if (ret) {
6898 vty_out(vty,
6899 "VRF %s is not configured as a bgp instance\n",
6900 import_name);
6901 return CMD_WARNING;
6902 }
6903 }
6904
6905 if (remove) {
6906 vrf_unimport_from_vrf(bgp, vrf_bgp, afi, safi);
6907 } else {
6908 /* Already importing from "import_vrf"? */
6909 for (ALL_LIST_ELEMENTS_RO(bgp->vpn_policy[afi].import_vrf, node,
6910 vname)) {
6911 if (strcmp(vname, import_name) == 0)
6912 return CMD_WARNING;
6913 }
6914
6915 vrf_import_from_vrf(bgp, vrf_bgp, afi, safi);
6916 }
6917
6918 return CMD_SUCCESS;
6919 }
6920
6921 /* This command is valid only in a bgp vrf instance or the default instance */
6922 DEFPY (bgp_imexport_vpn,
6923 bgp_imexport_vpn_cmd,
6924 "[no] <import|export>$direction_str vpn",
6925 NO_STR
6926 "Import routes to this address-family\n"
6927 "Export routes from this address-family\n"
6928 "to/from default instance VPN RIB\n")
6929 {
6930 VTY_DECLVAR_CONTEXT(bgp, bgp);
6931 int previous_state;
6932 afi_t afi;
6933 safi_t safi;
6934 int idx = 0;
6935 int yes = 1;
6936 int flag;
6937 vpn_policy_direction_t dir;
6938
6939 if (argv_find(argv, argc, "no", &idx))
6940 yes = 0;
6941
6942 if (BGP_INSTANCE_TYPE_VRF != bgp->inst_type &&
6943 BGP_INSTANCE_TYPE_DEFAULT != bgp->inst_type) {
6944
6945 vty_out(vty, "%% import|export vpn valid only for bgp vrf or default instance\n");
6946 return CMD_WARNING_CONFIG_FAILED;
6947 }
6948
6949 afi = bgp_node_afi(vty);
6950 safi = bgp_node_safi(vty);
6951 if ((SAFI_UNICAST != safi) || ((AFI_IP != afi) && (AFI_IP6 != afi))) {
6952 vty_out(vty, "%% import|export vpn valid only for unicast ipv4|ipv6\n");
6953 return CMD_WARNING_CONFIG_FAILED;
6954 }
6955
6956 if (!strcmp(direction_str, "import")) {
6957 flag = BGP_CONFIG_MPLSVPN_TO_VRF_IMPORT;
6958 dir = BGP_VPN_POLICY_DIR_FROMVPN;
6959 } else if (!strcmp(direction_str, "export")) {
6960 flag = BGP_CONFIG_VRF_TO_MPLSVPN_EXPORT;
6961 dir = BGP_VPN_POLICY_DIR_TOVPN;
6962 } else {
6963 vty_out(vty, "%% unknown direction %s\n", direction_str);
6964 return CMD_WARNING_CONFIG_FAILED;
6965 }
6966
6967 previous_state = CHECK_FLAG(bgp->af_flags[afi][safi], flag);
6968
6969 if (yes) {
6970 SET_FLAG(bgp->af_flags[afi][safi], flag);
6971 if (!previous_state) {
6972 /* trigger export current vrf */
6973 vpn_leak_postchange(dir, afi, bgp_get_default(), bgp);
6974 }
6975 } else {
6976 if (previous_state) {
6977 /* trigger un-export current vrf */
6978 vpn_leak_prechange(dir, afi, bgp_get_default(), bgp);
6979 }
6980 UNSET_FLAG(bgp->af_flags[afi][safi], flag);
6981 }
6982
6983 return CMD_SUCCESS;
6984 }
6985
6986 DEFPY (af_routetarget_import,
6987 af_routetarget_import_cmd,
6988 "[no] <rt|route-target> redirect import RTLIST...",
6989 NO_STR
6990 "Specify route target list\n"
6991 "Specify route target list\n"
6992 "Flow-spec redirect type route target\n"
6993 "Import routes to this address-family\n"
6994 "Space separated route target list (A.B.C.D:MN|EF:OPQR|GHJK:MN)\n")
6995 {
6996 VTY_DECLVAR_CONTEXT(bgp, bgp);
6997 int ret;
6998 struct ecommunity *ecom = NULL;
6999 afi_t afi;
7000 int idx = 0;
7001 int yes = 1;
7002
7003 if (argv_find(argv, argc, "no", &idx))
7004 yes = 0;
7005
7006 afi = vpn_policy_getafi(vty, bgp, false);
7007 if (afi == AFI_MAX)
7008 return CMD_WARNING_CONFIG_FAILED;
7009
7010 if (yes) {
7011 if (!argv_find(argv, argc, "RTLIST", &idx)) {
7012 vty_out(vty, "%% Missing RTLIST\n");
7013 return CMD_WARNING_CONFIG_FAILED;
7014 }
7015 ret = set_ecom_list(vty, argc - idx, argv + idx, &ecom);
7016 if (ret != CMD_SUCCESS)
7017 return ret;
7018 }
7019
7020 if (yes) {
7021 if (bgp->vpn_policy[afi].import_redirect_rtlist)
7022 ecommunity_free(&bgp->vpn_policy[afi]
7023 .import_redirect_rtlist);
7024 bgp->vpn_policy[afi].import_redirect_rtlist =
7025 ecommunity_dup(ecom);
7026 } else {
7027 if (bgp->vpn_policy[afi].import_redirect_rtlist)
7028 ecommunity_free(&bgp->vpn_policy[afi]
7029 .import_redirect_rtlist);
7030 bgp->vpn_policy[afi].import_redirect_rtlist = NULL;
7031 }
7032
7033 if (ecom)
7034 ecommunity_free(&ecom);
7035
7036 return CMD_SUCCESS;
7037 }
7038
7039 DEFUN_NOSH (address_family_ipv4_safi,
7040 address_family_ipv4_safi_cmd,
7041 "address-family ipv4 [<unicast|multicast|vpn|labeled-unicast|flowspec>]",
7042 "Enter Address Family command mode\n"
7043 "Address Family\n"
7044 BGP_SAFI_WITH_LABEL_HELP_STR)
7045 {
7046
7047 if (argc == 3) {
7048 VTY_DECLVAR_CONTEXT(bgp, bgp);
7049 safi_t safi = bgp_vty_safi_from_str(argv[2]->text);
7050 if (bgp->inst_type != BGP_INSTANCE_TYPE_DEFAULT
7051 && safi != SAFI_UNICAST && safi != SAFI_MULTICAST
7052 && safi != SAFI_EVPN) {
7053 vty_out(vty,
7054 "Only Unicast/Multicast/EVPN SAFIs supported in non-core instances.\n");
7055 return CMD_WARNING_CONFIG_FAILED;
7056 }
7057 vty->node = bgp_node_type(AFI_IP, safi);
7058 } else
7059 vty->node = BGP_IPV4_NODE;
7060
7061 return CMD_SUCCESS;
7062 }
7063
7064 DEFUN_NOSH (address_family_ipv6_safi,
7065 address_family_ipv6_safi_cmd,
7066 "address-family ipv6 [<unicast|multicast|vpn|labeled-unicast|flowspec>]",
7067 "Enter Address Family command mode\n"
7068 "Address Family\n"
7069 BGP_SAFI_WITH_LABEL_HELP_STR)
7070 {
7071 if (argc == 3) {
7072 VTY_DECLVAR_CONTEXT(bgp, bgp);
7073 safi_t safi = bgp_vty_safi_from_str(argv[2]->text);
7074 if (bgp->inst_type != BGP_INSTANCE_TYPE_DEFAULT
7075 && safi != SAFI_UNICAST && safi != SAFI_MULTICAST
7076 && safi != SAFI_EVPN) {
7077 vty_out(vty,
7078 "Only Unicast/Multicast/EVPN SAFIs supported in non-core instances.\n");
7079 return CMD_WARNING_CONFIG_FAILED;
7080 }
7081 vty->node = bgp_node_type(AFI_IP6, safi);
7082 } else
7083 vty->node = BGP_IPV6_NODE;
7084
7085 return CMD_SUCCESS;
7086 }
7087
7088 #ifdef KEEP_OLD_VPN_COMMANDS
7089 DEFUN_NOSH (address_family_vpnv4,
7090 address_family_vpnv4_cmd,
7091 "address-family vpnv4 [unicast]",
7092 "Enter Address Family command mode\n"
7093 "Address Family\n"
7094 "Address Family modifier\n")
7095 {
7096 vty->node = BGP_VPNV4_NODE;
7097 return CMD_SUCCESS;
7098 }
7099
7100 DEFUN_NOSH (address_family_vpnv6,
7101 address_family_vpnv6_cmd,
7102 "address-family vpnv6 [unicast]",
7103 "Enter Address Family command mode\n"
7104 "Address Family\n"
7105 "Address Family modifier\n")
7106 {
7107 vty->node = BGP_VPNV6_NODE;
7108 return CMD_SUCCESS;
7109 }
7110 #endif /* KEEP_OLD_VPN_COMMANDS */
7111
7112 DEFUN_NOSH (address_family_evpn,
7113 address_family_evpn_cmd,
7114 "address-family l2vpn evpn",
7115 "Enter Address Family command mode\n"
7116 "Address Family\n"
7117 "Address Family modifier\n")
7118 {
7119 VTY_DECLVAR_CONTEXT(bgp, bgp);
7120 vty->node = BGP_EVPN_NODE;
7121 return CMD_SUCCESS;
7122 }
7123
7124 DEFUN_NOSH (exit_address_family,
7125 exit_address_family_cmd,
7126 "exit-address-family",
7127 "Exit from Address Family configuration mode\n")
7128 {
7129 if (vty->node == BGP_IPV4_NODE || vty->node == BGP_IPV4M_NODE
7130 || vty->node == BGP_IPV4L_NODE || vty->node == BGP_VPNV4_NODE
7131 || vty->node == BGP_IPV6_NODE || vty->node == BGP_IPV6M_NODE
7132 || vty->node == BGP_IPV6L_NODE || vty->node == BGP_VPNV6_NODE
7133 || vty->node == BGP_EVPN_NODE
7134 || vty->node == BGP_FLOWSPECV4_NODE
7135 || vty->node == BGP_FLOWSPECV6_NODE)
7136 vty->node = BGP_NODE;
7137 return CMD_SUCCESS;
7138 }
7139
7140 /* Recalculate bestpath and re-advertise a prefix */
7141 static int bgp_clear_prefix(struct vty *vty, const char *view_name,
7142 const char *ip_str, afi_t afi, safi_t safi,
7143 struct prefix_rd *prd)
7144 {
7145 int ret;
7146 struct prefix match;
7147 struct bgp_node *rn;
7148 struct bgp_node *rm;
7149 struct bgp *bgp;
7150 struct bgp_table *table;
7151 struct bgp_table *rib;
7152
7153 /* BGP structure lookup. */
7154 if (view_name) {
7155 bgp = bgp_lookup_by_name(view_name);
7156 if (bgp == NULL) {
7157 vty_out(vty, "%% Can't find BGP instance %s\n",
7158 view_name);
7159 return CMD_WARNING;
7160 }
7161 } else {
7162 bgp = bgp_get_default();
7163 if (bgp == NULL) {
7164 vty_out(vty, "%% No BGP process is configured\n");
7165 return CMD_WARNING;
7166 }
7167 }
7168
7169 /* Check IP address argument. */
7170 ret = str2prefix(ip_str, &match);
7171 if (!ret) {
7172 vty_out(vty, "%% address is malformed\n");
7173 return CMD_WARNING;
7174 }
7175
7176 match.family = afi2family(afi);
7177 rib = bgp->rib[afi][safi];
7178
7179 if (safi == SAFI_MPLS_VPN) {
7180 for (rn = bgp_table_top(rib); rn; rn = bgp_route_next(rn)) {
7181 if (prd && memcmp(rn->p.u.val, prd->val, 8) != 0)
7182 continue;
7183
7184 table = bgp_node_get_bgp_table_info(rn);
7185 if (table != NULL) {
7186
7187 if ((rm = bgp_node_match(table, &match))
7188 != NULL) {
7189 if (rm->p.prefixlen
7190 == match.prefixlen) {
7191 SET_FLAG(rm->flags,
7192 BGP_NODE_USER_CLEAR);
7193 bgp_process(bgp, rm, afi, safi);
7194 }
7195 bgp_unlock_node(rm);
7196 }
7197 }
7198 }
7199 } else {
7200 if ((rn = bgp_node_match(rib, &match)) != NULL) {
7201 if (rn->p.prefixlen == match.prefixlen) {
7202 SET_FLAG(rn->flags, BGP_NODE_USER_CLEAR);
7203 bgp_process(bgp, rn, afi, safi);
7204 }
7205 bgp_unlock_node(rn);
7206 }
7207 }
7208
7209 return CMD_SUCCESS;
7210 }
7211
7212 /* one clear bgp command to rule them all */
7213 DEFUN (clear_ip_bgp_all,
7214 clear_ip_bgp_all_cmd,
7215 "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>]",
7216 CLEAR_STR
7217 IP_STR
7218 BGP_STR
7219 BGP_INSTANCE_HELP_STR
7220 BGP_AFI_HELP_STR
7221 "Address Family\n"
7222 BGP_SAFI_WITH_LABEL_HELP_STR
7223 "Address Family modifier\n"
7224 "Clear all peers\n"
7225 "BGP neighbor address to clear\n"
7226 "BGP IPv6 neighbor to clear\n"
7227 "BGP neighbor on interface to clear\n"
7228 "Clear peers with the AS number\n"
7229 "Clear all external peers\n"
7230 "Clear all members of peer-group\n"
7231 "BGP peer-group name\n"
7232 BGP_SOFT_STR
7233 BGP_SOFT_IN_STR
7234 BGP_SOFT_OUT_STR
7235 BGP_SOFT_IN_STR
7236 "Push out prefix-list ORF and do inbound soft reconfig\n"
7237 BGP_SOFT_OUT_STR)
7238 {
7239 char *vrf = NULL;
7240
7241 afi_t afi = AFI_IP6;
7242 safi_t safi = SAFI_UNICAST;
7243 enum clear_sort clr_sort = clear_peer;
7244 enum bgp_clear_type clr_type;
7245 char *clr_arg = NULL;
7246
7247 int idx = 0;
7248
7249 /* clear [ip] bgp */
7250 if (argv_find(argv, argc, "ip", &idx))
7251 afi = AFI_IP;
7252
7253 /* [<vrf> VIEWVRFNAME] */
7254 if (argv_find(argv, argc, "vrf", &idx)) {
7255 vrf = argv[idx + 1]->arg;
7256 idx += 2;
7257 if (vrf && strmatch(vrf, VRF_DEFAULT_NAME))
7258 vrf = NULL;
7259 } else if (argv_find(argv, argc, "view", &idx)) {
7260 /* [<view> VIEWVRFNAME] */
7261 vrf = argv[idx + 1]->arg;
7262 idx += 2;
7263 }
7264 /* ["BGP_AFI_CMD_STR" ["BGP_SAFI_CMD_STR"]] */
7265 if (argv_find_and_parse_afi(argv, argc, &idx, &afi))
7266 argv_find_and_parse_safi(argv, argc, &idx, &safi);
7267
7268 /* <*|A.B.C.D|X:X::X:X|WORD|(1-4294967295)|external|peer-group PGNAME> */
7269 if (argv_find(argv, argc, "*", &idx)) {
7270 clr_sort = clear_all;
7271 } else if (argv_find(argv, argc, "A.B.C.D", &idx)) {
7272 clr_sort = clear_peer;
7273 clr_arg = argv[idx]->arg;
7274 } else if (argv_find(argv, argc, "X:X::X:X", &idx)) {
7275 clr_sort = clear_peer;
7276 clr_arg = argv[idx]->arg;
7277 } else if (argv_find(argv, argc, "peer-group", &idx)) {
7278 clr_sort = clear_group;
7279 idx++;
7280 clr_arg = argv[idx]->arg;
7281 } else if (argv_find(argv, argc, "PGNAME", &idx)) {
7282 clr_sort = clear_peer;
7283 clr_arg = argv[idx]->arg;
7284 } else if (argv_find(argv, argc, "WORD", &idx)) {
7285 clr_sort = clear_peer;
7286 clr_arg = argv[idx]->arg;
7287 } else if (argv_find(argv, argc, "(1-4294967295)", &idx)) {
7288 clr_sort = clear_as;
7289 clr_arg = argv[idx]->arg;
7290 } else if (argv_find(argv, argc, "external", &idx)) {
7291 clr_sort = clear_external;
7292 }
7293
7294 /* [<soft [<in|out>]|in [prefix-filter]|out>] */
7295 if (argv_find(argv, argc, "soft", &idx)) {
7296 if (argv_find(argv, argc, "in", &idx)
7297 || argv_find(argv, argc, "out", &idx))
7298 clr_type = strmatch(argv[idx]->text, "in")
7299 ? BGP_CLEAR_SOFT_IN
7300 : BGP_CLEAR_SOFT_OUT;
7301 else
7302 clr_type = BGP_CLEAR_SOFT_BOTH;
7303 } else if (argv_find(argv, argc, "in", &idx)) {
7304 clr_type = argv_find(argv, argc, "prefix-filter", &idx)
7305 ? BGP_CLEAR_SOFT_IN_ORF_PREFIX
7306 : BGP_CLEAR_SOFT_IN;
7307 } else if (argv_find(argv, argc, "out", &idx)) {
7308 clr_type = BGP_CLEAR_SOFT_OUT;
7309 } else
7310 clr_type = BGP_CLEAR_SOFT_NONE;
7311
7312 return bgp_clear_vty(vty, vrf, afi, safi, clr_sort, clr_type, clr_arg);
7313 }
7314
7315 DEFUN (clear_ip_bgp_prefix,
7316 clear_ip_bgp_prefix_cmd,
7317 "clear [ip] bgp [<view|vrf> VIEWVRFNAME] prefix A.B.C.D/M",
7318 CLEAR_STR
7319 IP_STR
7320 BGP_STR
7321 BGP_INSTANCE_HELP_STR
7322 "Clear bestpath and re-advertise\n"
7323 "IPv4 prefix\n")
7324 {
7325 char *vrf = NULL;
7326 char *prefix = NULL;
7327
7328 int idx = 0;
7329
7330 /* [<view|vrf> VIEWVRFNAME] */
7331 if (argv_find(argv, argc, "vrf", &idx)) {
7332 vrf = argv[idx + 1]->arg;
7333 idx += 2;
7334 if (vrf && strmatch(vrf, VRF_DEFAULT_NAME))
7335 vrf = NULL;
7336 } else if (argv_find(argv, argc, "view", &idx)) {
7337 /* [<view> VIEWVRFNAME] */
7338 vrf = argv[idx + 1]->arg;
7339 idx += 2;
7340 }
7341
7342 prefix = argv[argc - 1]->arg;
7343
7344 return bgp_clear_prefix(vty, vrf, prefix, AFI_IP, SAFI_UNICAST, NULL);
7345 }
7346
7347 DEFUN (clear_bgp_ipv6_safi_prefix,
7348 clear_bgp_ipv6_safi_prefix_cmd,
7349 "clear [ip] bgp ipv6 "BGP_SAFI_CMD_STR" prefix X:X::X:X/M",
7350 CLEAR_STR
7351 IP_STR
7352 BGP_STR
7353 "Address Family\n"
7354 BGP_SAFI_HELP_STR
7355 "Clear bestpath and re-advertise\n"
7356 "IPv6 prefix\n")
7357 {
7358 int idx_safi = 0;
7359 int idx_ipv6_prefix = 0;
7360 safi_t safi = SAFI_UNICAST;
7361 char *prefix = argv_find(argv, argc, "X:X::X:X/M", &idx_ipv6_prefix) ?
7362 argv[idx_ipv6_prefix]->arg : NULL;
7363
7364 argv_find_and_parse_safi(argv, argc, &idx_safi, &safi);
7365 return bgp_clear_prefix(
7366 vty, NULL, prefix, AFI_IP6,
7367 safi, NULL);
7368 }
7369
7370 DEFUN (clear_bgp_instance_ipv6_safi_prefix,
7371 clear_bgp_instance_ipv6_safi_prefix_cmd,
7372 "clear [ip] bgp <view|vrf> VIEWVRFNAME ipv6 "BGP_SAFI_CMD_STR" prefix X:X::X:X/M",
7373 CLEAR_STR
7374 IP_STR
7375 BGP_STR
7376 BGP_INSTANCE_HELP_STR
7377 "Address Family\n"
7378 BGP_SAFI_HELP_STR
7379 "Clear bestpath and re-advertise\n"
7380 "IPv6 prefix\n")
7381 {
7382 int idx_safi = 0;
7383 int idx_vrfview = 0;
7384 int idx_ipv6_prefix = 0;
7385 safi_t safi = SAFI_UNICAST;
7386 char *prefix = argv_find(argv, argc, "X:X::X:X/M", &idx_ipv6_prefix) ?
7387 argv[idx_ipv6_prefix]->arg : NULL;
7388 char *vrfview = NULL;
7389
7390 /* [<view|vrf> VIEWVRFNAME] */
7391 if (argv_find(argv, argc, "vrf", &idx_vrfview)) {
7392 vrfview = argv[idx_vrfview + 1]->arg;
7393 if (vrfview && strmatch(vrfview, VRF_DEFAULT_NAME))
7394 vrfview = NULL;
7395 } else if (argv_find(argv, argc, "view", &idx_vrfview)) {
7396 /* [<view> VIEWVRFNAME] */
7397 vrfview = argv[idx_vrfview + 1]->arg;
7398 }
7399 argv_find_and_parse_safi(argv, argc, &idx_safi, &safi);
7400
7401 return bgp_clear_prefix(
7402 vty, vrfview, prefix,
7403 AFI_IP6, safi, NULL);
7404 }
7405
7406 DEFUN (show_bgp_views,
7407 show_bgp_views_cmd,
7408 "show [ip] bgp views",
7409 SHOW_STR
7410 IP_STR
7411 BGP_STR
7412 "Show the defined BGP views\n")
7413 {
7414 struct list *inst = bm->bgp;
7415 struct listnode *node;
7416 struct bgp *bgp;
7417
7418 vty_out(vty, "Defined BGP views:\n");
7419 for (ALL_LIST_ELEMENTS_RO(inst, node, bgp)) {
7420 /* Skip VRFs. */
7421 if (bgp->inst_type == BGP_INSTANCE_TYPE_VRF)
7422 continue;
7423 vty_out(vty, "\t%s (AS%u)\n", bgp->name ? bgp->name : "(null)",
7424 bgp->as);
7425 }
7426
7427 return CMD_SUCCESS;
7428 }
7429
7430 DEFUN (show_bgp_vrfs,
7431 show_bgp_vrfs_cmd,
7432 "show [ip] bgp vrfs [json]",
7433 SHOW_STR
7434 IP_STR
7435 BGP_STR
7436 "Show BGP VRFs\n"
7437 JSON_STR)
7438 {
7439 char buf[ETHER_ADDR_STRLEN];
7440 struct list *inst = bm->bgp;
7441 struct listnode *node;
7442 struct bgp *bgp;
7443 bool uj = use_json(argc, argv);
7444 json_object *json = NULL;
7445 json_object *json_vrfs = NULL;
7446 int count = 0;
7447
7448 if (uj) {
7449 json = json_object_new_object();
7450 json_vrfs = json_object_new_object();
7451 }
7452
7453 for (ALL_LIST_ELEMENTS_RO(inst, node, bgp)) {
7454 const char *name, *type;
7455 struct peer *peer;
7456 struct listnode *node2, *nnode2;
7457 int peers_cfg, peers_estb;
7458 json_object *json_vrf = NULL;
7459
7460 /* Skip Views. */
7461 if (bgp->inst_type == BGP_INSTANCE_TYPE_VIEW)
7462 continue;
7463
7464 count++;
7465 if (!uj && count == 1) {
7466 vty_out(vty,
7467 "%4s %-5s %-16s %9s %10s %-37s\n",
7468 "Type", "Id", "routerId", "#PeersVfg",
7469 "#PeersEstb", "Name");
7470 vty_out(vty, "%11s %-16s %-21s %-6s\n", " ",
7471 "L3-VNI", "RouterMAC", "Interface");
7472 }
7473
7474 peers_cfg = peers_estb = 0;
7475 if (uj)
7476 json_vrf = json_object_new_object();
7477
7478
7479 for (ALL_LIST_ELEMENTS(bgp->peer, node2, nnode2, peer)) {
7480 if (!CHECK_FLAG(peer->flags, PEER_FLAG_CONFIG_NODE))
7481 continue;
7482 peers_cfg++;
7483 if (peer->status == Established)
7484 peers_estb++;
7485 }
7486
7487 if (bgp->inst_type == BGP_INSTANCE_TYPE_DEFAULT) {
7488 name = VRF_DEFAULT_NAME;
7489 type = "DFLT";
7490 } else {
7491 name = bgp->name;
7492 type = "VRF";
7493 }
7494
7495
7496 if (uj) {
7497 int64_t vrf_id_ui = (bgp->vrf_id == VRF_UNKNOWN)
7498 ? -1
7499 : (int64_t)bgp->vrf_id;
7500 json_object_string_add(json_vrf, "type", type);
7501 json_object_int_add(json_vrf, "vrfId", vrf_id_ui);
7502 json_object_string_add(json_vrf, "routerId",
7503 inet_ntoa(bgp->router_id));
7504 json_object_int_add(json_vrf, "numConfiguredPeers",
7505 peers_cfg);
7506 json_object_int_add(json_vrf, "numEstablishedPeers",
7507 peers_estb);
7508
7509 json_object_int_add(json_vrf, "l3vni", bgp->l3vni);
7510 json_object_string_add(
7511 json_vrf, "rmac",
7512 prefix_mac2str(&bgp->rmac, buf, sizeof(buf)));
7513 json_object_string_add(json_vrf, "interface",
7514 ifindex2ifname(bgp->l3vni_svi_ifindex,
7515 bgp->vrf_id));
7516 json_object_object_add(json_vrfs, name, json_vrf);
7517 } else {
7518 vty_out(vty,
7519 "%4s %-5d %-16s %-9u %-10u %-37s\n",
7520 type,
7521 bgp->vrf_id == VRF_UNKNOWN ? -1
7522 : (int)bgp->vrf_id,
7523 inet_ntoa(bgp->router_id), peers_cfg,
7524 peers_estb, name);
7525 vty_out(vty,"%11s %-16u %-21s %-20s\n", " ",
7526 bgp->l3vni,
7527 prefix_mac2str(&bgp->rmac, buf, sizeof(buf)),
7528 ifindex2ifname(bgp->l3vni_svi_ifindex,
7529 bgp->vrf_id));
7530 }
7531 }
7532
7533 if (uj) {
7534 json_object_object_add(json, "vrfs", json_vrfs);
7535
7536 json_object_int_add(json, "totalVrfs", count);
7537
7538 vty_out(vty, "%s\n", json_object_to_json_string_ext(
7539 json, JSON_C_TO_STRING_PRETTY));
7540 json_object_free(json);
7541 } else {
7542 if (count)
7543 vty_out(vty,
7544 "\nTotal number of VRFs (including default): %d\n",
7545 count);
7546 }
7547
7548 return CMD_SUCCESS;
7549 }
7550
7551 DEFUN (show_bgp_mac_hash,
7552 show_bgp_mac_hash_cmd,
7553 "show bgp mac hash",
7554 SHOW_STR
7555 BGP_STR
7556 "Mac Address\n"
7557 "Mac Address database\n")
7558 {
7559 bgp_mac_dump_table(vty);
7560
7561 return CMD_SUCCESS;
7562 }
7563
7564 static void show_tip_entry(struct hash_bucket *bucket, void *args)
7565 {
7566 struct vty *vty = (struct vty *)args;
7567 struct tip_addr *tip = (struct tip_addr *)bucket->data;
7568
7569 vty_out(vty, "addr: %s, count: %d\n", inet_ntoa(tip->addr),
7570 tip->refcnt);
7571 }
7572
7573 static void bgp_show_martian_nexthops(struct vty *vty, struct bgp *bgp)
7574 {
7575 vty_out(vty, "self nexthop database:\n");
7576 bgp_nexthop_show_address_hash(vty, bgp);
7577
7578 vty_out(vty, "Tunnel-ip database:\n");
7579 hash_iterate(bgp->tip_hash,
7580 (void (*)(struct hash_bucket *, void *))show_tip_entry,
7581 vty);
7582 }
7583
7584 DEFUN(show_bgp_martian_nexthop_db, show_bgp_martian_nexthop_db_cmd,
7585 "show bgp [<view|vrf> VIEWVRFNAME] martian next-hop",
7586 SHOW_STR BGP_STR BGP_INSTANCE_HELP_STR
7587 "martian next-hops\n"
7588 "martian next-hop database\n")
7589 {
7590 struct bgp *bgp = NULL;
7591 int idx = 0;
7592 char *name = NULL;
7593
7594 /* [<vrf> VIEWVRFNAME] */
7595 if (argv_find(argv, argc, "vrf", &idx)) {
7596 name = argv[idx + 1]->arg;
7597 if (name && strmatch(name, VRF_DEFAULT_NAME))
7598 name = NULL;
7599 } else if (argv_find(argv, argc, "view", &idx))
7600 /* [<view> VIEWVRFNAME] */
7601 name = argv[idx + 1]->arg;
7602 if (name)
7603 bgp = bgp_lookup_by_name(name);
7604 else
7605 bgp = bgp_get_default();
7606
7607 if (!bgp) {
7608 vty_out(vty, "%% No BGP process is configured\n");
7609 return CMD_WARNING;
7610 }
7611 bgp_show_martian_nexthops(vty, bgp);
7612
7613 return CMD_SUCCESS;
7614 }
7615
7616 DEFUN (show_bgp_memory,
7617 show_bgp_memory_cmd,
7618 "show [ip] bgp memory",
7619 SHOW_STR
7620 IP_STR
7621 BGP_STR
7622 "Global BGP memory statistics\n")
7623 {
7624 char memstrbuf[MTYPE_MEMSTR_LEN];
7625 unsigned long count;
7626
7627 /* RIB related usage stats */
7628 count = mtype_stats_alloc(MTYPE_BGP_NODE);
7629 vty_out(vty, "%ld RIB nodes, using %s of memory\n", count,
7630 mtype_memstr(memstrbuf, sizeof(memstrbuf),
7631 count * sizeof(struct bgp_node)));
7632
7633 count = mtype_stats_alloc(MTYPE_BGP_ROUTE);
7634 vty_out(vty, "%ld BGP routes, using %s of memory\n", count,
7635 mtype_memstr(memstrbuf, sizeof(memstrbuf),
7636 count * sizeof(struct bgp_path_info)));
7637 if ((count = mtype_stats_alloc(MTYPE_BGP_ROUTE_EXTRA)))
7638 vty_out(vty, "%ld BGP route ancillaries, using %s of memory\n",
7639 count,
7640 mtype_memstr(
7641 memstrbuf, sizeof(memstrbuf),
7642 count * sizeof(struct bgp_path_info_extra)));
7643
7644 if ((count = mtype_stats_alloc(MTYPE_BGP_STATIC)))
7645 vty_out(vty, "%ld Static routes, using %s of memory\n", count,
7646 mtype_memstr(memstrbuf, sizeof(memstrbuf),
7647 count * sizeof(struct bgp_static)));
7648
7649 if ((count = mtype_stats_alloc(MTYPE_BGP_PACKET)))
7650 vty_out(vty, "%ld Packets, using %s of memory\n", count,
7651 mtype_memstr(memstrbuf, sizeof(memstrbuf),
7652 count * sizeof(struct bpacket)));
7653
7654 /* Adj-In/Out */
7655 if ((count = mtype_stats_alloc(MTYPE_BGP_ADJ_IN)))
7656 vty_out(vty, "%ld Adj-In entries, using %s of memory\n", count,
7657 mtype_memstr(memstrbuf, sizeof(memstrbuf),
7658 count * sizeof(struct bgp_adj_in)));
7659 if ((count = mtype_stats_alloc(MTYPE_BGP_ADJ_OUT)))
7660 vty_out(vty, "%ld Adj-Out entries, using %s of memory\n", count,
7661 mtype_memstr(memstrbuf, sizeof(memstrbuf),
7662 count * sizeof(struct bgp_adj_out)));
7663
7664 if ((count = mtype_stats_alloc(MTYPE_BGP_NEXTHOP_CACHE)))
7665 vty_out(vty, "%ld Nexthop cache entries, using %s of memory\n",
7666 count,
7667 mtype_memstr(memstrbuf, sizeof(memstrbuf),
7668 count * sizeof(struct bgp_nexthop_cache)));
7669
7670 if ((count = mtype_stats_alloc(MTYPE_BGP_DAMP_INFO)))
7671 vty_out(vty, "%ld Dampening entries, using %s of memory\n",
7672 count,
7673 mtype_memstr(memstrbuf, sizeof(memstrbuf),
7674 count * sizeof(struct bgp_damp_info)));
7675
7676 /* Attributes */
7677 count = attr_count();
7678 vty_out(vty, "%ld BGP attributes, using %s of memory\n", count,
7679 mtype_memstr(memstrbuf, sizeof(memstrbuf),
7680 count * sizeof(struct attr)));
7681
7682 if ((count = attr_unknown_count()))
7683 vty_out(vty, "%ld unknown attributes\n", count);
7684
7685 /* AS_PATH attributes */
7686 count = aspath_count();
7687 vty_out(vty, "%ld BGP AS-PATH entries, using %s of memory\n", count,
7688 mtype_memstr(memstrbuf, sizeof(memstrbuf),
7689 count * sizeof(struct aspath)));
7690
7691 count = mtype_stats_alloc(MTYPE_AS_SEG);
7692 vty_out(vty, "%ld BGP AS-PATH segments, using %s of memory\n", count,
7693 mtype_memstr(memstrbuf, sizeof(memstrbuf),
7694 count * sizeof(struct assegment)));
7695
7696 /* Other attributes */
7697 if ((count = community_count()))
7698 vty_out(vty, "%ld BGP community entries, using %s of memory\n",
7699 count, mtype_memstr(memstrbuf, sizeof(memstrbuf),
7700 count * sizeof(struct community)));
7701 if ((count = mtype_stats_alloc(MTYPE_ECOMMUNITY)))
7702 vty_out(vty, "%ld BGP community entries, using %s of memory\n",
7703 count, mtype_memstr(memstrbuf, sizeof(memstrbuf),
7704 count * sizeof(struct ecommunity)));
7705 if ((count = mtype_stats_alloc(MTYPE_LCOMMUNITY)))
7706 vty_out(vty,
7707 "%ld BGP large-community entries, using %s of memory\n",
7708 count, mtype_memstr(memstrbuf, sizeof(memstrbuf),
7709 count * sizeof(struct lcommunity)));
7710
7711 if ((count = mtype_stats_alloc(MTYPE_CLUSTER)))
7712 vty_out(vty, "%ld Cluster lists, using %s of memory\n", count,
7713 mtype_memstr(memstrbuf, sizeof(memstrbuf),
7714 count * sizeof(struct cluster_list)));
7715
7716 /* Peer related usage */
7717 count = mtype_stats_alloc(MTYPE_BGP_PEER);
7718 vty_out(vty, "%ld peers, using %s of memory\n", count,
7719 mtype_memstr(memstrbuf, sizeof(memstrbuf),
7720 count * sizeof(struct peer)));
7721
7722 if ((count = mtype_stats_alloc(MTYPE_PEER_GROUP)))
7723 vty_out(vty, "%ld peer groups, using %s of memory\n", count,
7724 mtype_memstr(memstrbuf, sizeof(memstrbuf),
7725 count * sizeof(struct peer_group)));
7726
7727 /* Other */
7728 if ((count = mtype_stats_alloc(MTYPE_BGP_REGEXP)))
7729 vty_out(vty, "%ld compiled regexes, using %s of memory\n",
7730 count, mtype_memstr(memstrbuf, sizeof(memstrbuf),
7731 count * sizeof(regex_t)));
7732 return CMD_SUCCESS;
7733 }
7734
7735 static void bgp_show_bestpath_json(struct bgp *bgp, json_object *json)
7736 {
7737 json_object *bestpath = json_object_new_object();
7738
7739 if (bgp_flag_check(bgp, BGP_FLAG_ASPATH_IGNORE))
7740 json_object_string_add(bestpath, "asPath", "ignore");
7741
7742 if (bgp_flag_check(bgp, BGP_FLAG_ASPATH_CONFED))
7743 json_object_string_add(bestpath, "asPath", "confed");
7744
7745 if (bgp_flag_check(bgp, BGP_FLAG_ASPATH_MULTIPATH_RELAX)) {
7746 if (bgp_flag_check(bgp, BGP_FLAG_MULTIPATH_RELAX_AS_SET))
7747 json_object_string_add(bestpath, "multiPathRelax",
7748 "as-set");
7749 else
7750 json_object_string_add(bestpath, "multiPathRelax",
7751 "true");
7752 } else
7753 json_object_string_add(bestpath, "multiPathRelax", "false");
7754
7755 if (bgp_flag_check(bgp, BGP_FLAG_COMPARE_ROUTER_ID))
7756 json_object_string_add(bestpath, "compareRouterId", "true");
7757 if (bgp_flag_check(bgp, BGP_FLAG_MED_CONFED)
7758 || bgp_flag_check(bgp, BGP_FLAG_MED_MISSING_AS_WORST)) {
7759 if (bgp_flag_check(bgp, BGP_FLAG_MED_CONFED))
7760 json_object_string_add(bestpath, "med", "confed");
7761 if (bgp_flag_check(bgp, BGP_FLAG_MED_MISSING_AS_WORST))
7762 json_object_string_add(bestpath, "med",
7763 "missing-as-worst");
7764 else
7765 json_object_string_add(bestpath, "med", "true");
7766 }
7767
7768 json_object_object_add(json, "bestPath", bestpath);
7769 }
7770
7771 /* Show BGP peer's summary information. */
7772 static int bgp_show_summary(struct vty *vty, struct bgp *bgp, int afi, int safi,
7773 bool use_json, json_object *json)
7774 {
7775 struct peer *peer;
7776 struct listnode *node, *nnode;
7777 unsigned int count = 0, dn_count = 0;
7778 char timebuf[BGP_UPTIME_LEN], dn_flag[2];
7779 char neighbor_buf[VTY_BUFSIZ];
7780 int neighbor_col_default_width = 16;
7781 int len;
7782 int max_neighbor_width = 0;
7783 int pfx_rcd_safi;
7784 json_object *json_peer = NULL;
7785 json_object *json_peers = NULL;
7786 struct peer_af *paf;
7787
7788 /* labeled-unicast routes are installed in the unicast table so in order
7789 * to
7790 * display the correct PfxRcd value we must look at SAFI_UNICAST
7791 */
7792 if (safi == SAFI_LABELED_UNICAST)
7793 pfx_rcd_safi = SAFI_UNICAST;
7794 else
7795 pfx_rcd_safi = safi;
7796
7797 if (use_json) {
7798 if (json == NULL)
7799 json = json_object_new_object();
7800
7801 json_peers = json_object_new_object();
7802 } else {
7803 /* Loop over all neighbors that will be displayed to determine
7804 * how many
7805 * characters are needed for the Neighbor column
7806 */
7807 for (ALL_LIST_ELEMENTS(bgp->peer, node, nnode, peer)) {
7808 if (!CHECK_FLAG(peer->flags, PEER_FLAG_CONFIG_NODE))
7809 continue;
7810
7811 if (peer->afc[afi][safi]) {
7812 memset(dn_flag, '\0', sizeof(dn_flag));
7813 if (peer_dynamic_neighbor(peer))
7814 dn_flag[0] = '*';
7815
7816 if (peer->hostname
7817 && bgp_flag_check(bgp,
7818 BGP_FLAG_SHOW_HOSTNAME))
7819 sprintf(neighbor_buf, "%s%s(%s) ",
7820 dn_flag, peer->hostname,
7821 peer->host);
7822 else
7823 sprintf(neighbor_buf, "%s%s ", dn_flag,
7824 peer->host);
7825
7826 len = strlen(neighbor_buf);
7827
7828 if (len > max_neighbor_width)
7829 max_neighbor_width = len;
7830 }
7831 }
7832
7833 /* Originally we displayed the Neighbor column as 16
7834 * characters wide so make that the default
7835 */
7836 if (max_neighbor_width < neighbor_col_default_width)
7837 max_neighbor_width = neighbor_col_default_width;
7838 }
7839
7840 for (ALL_LIST_ELEMENTS(bgp->peer, node, nnode, peer)) {
7841 if (!CHECK_FLAG(peer->flags, PEER_FLAG_CONFIG_NODE))
7842 continue;
7843
7844 if (!peer->afc[afi][safi])
7845 continue;
7846
7847 if (!count) {
7848 unsigned long ents;
7849 char memstrbuf[MTYPE_MEMSTR_LEN];
7850 int64_t vrf_id_ui;
7851
7852 vrf_id_ui = (bgp->vrf_id == VRF_UNKNOWN)
7853 ? -1
7854 : (int64_t)bgp->vrf_id;
7855
7856 /* Usage summary and header */
7857 if (use_json) {
7858 json_object_string_add(
7859 json, "routerId",
7860 inet_ntoa(bgp->router_id));
7861 json_object_int_add(json, "as", bgp->as);
7862 json_object_int_add(json, "vrfId", vrf_id_ui);
7863 json_object_string_add(
7864 json, "vrfName",
7865 (bgp->inst_type
7866 == BGP_INSTANCE_TYPE_DEFAULT)
7867 ? VRF_DEFAULT_NAME
7868 : bgp->name);
7869 } else {
7870 vty_out(vty,
7871 "BGP router identifier %s, local AS number %u vrf-id %d",
7872 inet_ntoa(bgp->router_id), bgp->as,
7873 bgp->vrf_id == VRF_UNKNOWN
7874 ? -1
7875 : (int)bgp->vrf_id);
7876 vty_out(vty, "\n");
7877 }
7878
7879 if (bgp_update_delay_configured(bgp)) {
7880 if (use_json) {
7881 json_object_int_add(
7882 json, "updateDelayLimit",
7883 bgp->v_update_delay);
7884
7885 if (bgp->v_update_delay
7886 != bgp->v_establish_wait)
7887 json_object_int_add(
7888 json,
7889 "updateDelayEstablishWait",
7890 bgp->v_establish_wait);
7891
7892 if (bgp_update_delay_active(bgp)) {
7893 json_object_string_add(
7894 json,
7895 "updateDelayFirstNeighbor",
7896 bgp->update_delay_begin_time);
7897 json_object_boolean_true_add(
7898 json,
7899 "updateDelayInProgress");
7900 } else {
7901 if (bgp->update_delay_over) {
7902 json_object_string_add(
7903 json,
7904 "updateDelayFirstNeighbor",
7905 bgp->update_delay_begin_time);
7906 json_object_string_add(
7907 json,
7908 "updateDelayBestpathResumed",
7909 bgp->update_delay_end_time);
7910 json_object_string_add(
7911 json,
7912 "updateDelayZebraUpdateResume",
7913 bgp->update_delay_zebra_resume_time);
7914 json_object_string_add(
7915 json,
7916 "updateDelayPeerUpdateResume",
7917 bgp->update_delay_peers_resume_time);
7918 }
7919 }
7920 } else {
7921 vty_out(vty,
7922 "Read-only mode update-delay limit: %d seconds\n",
7923 bgp->v_update_delay);
7924 if (bgp->v_update_delay
7925 != bgp->v_establish_wait)
7926 vty_out(vty,
7927 " Establish wait: %d seconds\n",
7928 bgp->v_establish_wait);
7929
7930 if (bgp_update_delay_active(bgp)) {
7931 vty_out(vty,
7932 " First neighbor established: %s\n",
7933 bgp->update_delay_begin_time);
7934 vty_out(vty,
7935 " Delay in progress\n");
7936 } else {
7937 if (bgp->update_delay_over) {
7938 vty_out(vty,
7939 " First neighbor established: %s\n",
7940 bgp->update_delay_begin_time);
7941 vty_out(vty,
7942 " Best-paths resumed: %s\n",
7943 bgp->update_delay_end_time);
7944 vty_out(vty,
7945 " zebra update resumed: %s\n",
7946 bgp->update_delay_zebra_resume_time);
7947 vty_out(vty,
7948 " peers update resumed: %s\n",
7949 bgp->update_delay_peers_resume_time);
7950 }
7951 }
7952 }
7953 }
7954
7955 if (use_json) {
7956 if (bgp_maxmed_onstartup_configured(bgp)
7957 && bgp->maxmed_active)
7958 json_object_boolean_true_add(
7959 json, "maxMedOnStartup");
7960 if (bgp->v_maxmed_admin)
7961 json_object_boolean_true_add(
7962 json, "maxMedAdministrative");
7963
7964 json_object_int_add(
7965 json, "tableVersion",
7966 bgp_table_version(bgp->rib[afi][safi]));
7967
7968 ents = bgp_table_count(bgp->rib[afi][safi]);
7969 json_object_int_add(json, "ribCount", ents);
7970 json_object_int_add(
7971 json, "ribMemory",
7972 ents * sizeof(struct bgp_node));
7973
7974 ents = bgp->af_peer_count[afi][safi];
7975 json_object_int_add(json, "peerCount", ents);
7976 json_object_int_add(json, "peerMemory",
7977 ents * sizeof(struct peer));
7978
7979 if ((ents = listcount(bgp->group))) {
7980 json_object_int_add(
7981 json, "peerGroupCount", ents);
7982 json_object_int_add(
7983 json, "peerGroupMemory",
7984 ents * sizeof(struct
7985 peer_group));
7986 }
7987
7988 if (CHECK_FLAG(bgp->af_flags[afi][safi],
7989 BGP_CONFIG_DAMPENING))
7990 json_object_boolean_true_add(
7991 json, "dampeningEnabled");
7992 } else {
7993 if (bgp_maxmed_onstartup_configured(bgp)
7994 && bgp->maxmed_active)
7995 vty_out(vty,
7996 "Max-med on-startup active\n");
7997 if (bgp->v_maxmed_admin)
7998 vty_out(vty,
7999 "Max-med administrative active\n");
8000
8001 vty_out(vty, "BGP table version %" PRIu64 "\n",
8002 bgp_table_version(bgp->rib[afi][safi]));
8003
8004 ents = bgp_table_count(bgp->rib[afi][safi]);
8005 vty_out(vty,
8006 "RIB entries %ld, using %s of memory\n",
8007 ents,
8008 mtype_memstr(memstrbuf,
8009 sizeof(memstrbuf),
8010 ents * sizeof(struct
8011 bgp_node)));
8012
8013 /* Peer related usage */
8014 ents = bgp->af_peer_count[afi][safi];
8015 vty_out(vty, "Peers %ld, using %s of memory\n",
8016 ents,
8017 mtype_memstr(
8018 memstrbuf, sizeof(memstrbuf),
8019 ents * sizeof(struct peer)));
8020
8021 if ((ents = listcount(bgp->group)))
8022 vty_out(vty,
8023 "Peer groups %ld, using %s of memory\n",
8024 ents,
8025 mtype_memstr(
8026 memstrbuf,
8027 sizeof(memstrbuf),
8028 ents * sizeof(struct
8029 peer_group)));
8030
8031 if (CHECK_FLAG(bgp->af_flags[afi][safi],
8032 BGP_CONFIG_DAMPENING))
8033 vty_out(vty, "Dampening enabled.\n");
8034 vty_out(vty, "\n");
8035
8036 /* Subtract 8 here because 'Neighbor' is
8037 * 8 characters */
8038 vty_out(vty, "Neighbor");
8039 vty_out(vty, "%*s", max_neighbor_width - 8,
8040 " ");
8041 vty_out(vty,
8042 "V AS MsgRcvd MsgSent TblVer InQ OutQ Up/Down State/PfxRcd\n");
8043 }
8044 }
8045
8046 count++;
8047
8048 if (use_json) {
8049 json_peer = json_object_new_object();
8050
8051 if (peer_dynamic_neighbor(peer)) {
8052 dn_count++;
8053 json_object_boolean_true_add(json_peer,
8054 "dynamicPeer");
8055 }
8056
8057 if (peer->hostname)
8058 json_object_string_add(json_peer, "hostname",
8059 peer->hostname);
8060
8061 if (peer->domainname)
8062 json_object_string_add(json_peer, "domainname",
8063 peer->domainname);
8064
8065 json_object_int_add(json_peer, "remoteAs", peer->as);
8066 json_object_int_add(json_peer, "version", 4);
8067 json_object_int_add(json_peer, "msgRcvd",
8068 PEER_TOTAL_RX(peer));
8069 json_object_int_add(json_peer, "msgSent",
8070 PEER_TOTAL_TX(peer));
8071
8072 json_object_int_add(json_peer, "tableVersion",
8073 peer->version[afi][safi]);
8074 json_object_int_add(json_peer, "outq",
8075 peer->obuf->count);
8076 json_object_int_add(json_peer, "inq", 0);
8077 peer_uptime(peer->uptime, timebuf, BGP_UPTIME_LEN,
8078 use_json, json_peer);
8079
8080 /*
8081 * Adding "pfxRcd" field to match with the corresponding
8082 * CLI. "prefixReceivedCount" will be deprecated in
8083 * future.
8084 */
8085 json_object_int_add(json_peer, "prefixReceivedCount",
8086 peer->pcount[afi][pfx_rcd_safi]);
8087 json_object_int_add(json_peer, "pfxRcd",
8088 peer->pcount[afi][pfx_rcd_safi]);
8089
8090 paf = peer_af_find(peer, afi, pfx_rcd_safi);
8091 if (paf && PAF_SUBGRP(paf))
8092 json_object_int_add(json_peer,
8093 "pfxSnt",
8094 (PAF_SUBGRP(paf))->scount);
8095
8096 if (CHECK_FLAG(peer->flags, PEER_FLAG_SHUTDOWN))
8097 json_object_string_add(json_peer, "state",
8098 "Idle (Admin)");
8099 else if (peer->afc_recv[afi][safi])
8100 json_object_string_add(
8101 json_peer, "state",
8102 lookup_msg(bgp_status_msg, peer->status,
8103 NULL));
8104 else if (CHECK_FLAG(peer->sflags,
8105 PEER_STATUS_PREFIX_OVERFLOW))
8106 json_object_string_add(json_peer, "state",
8107 "Idle (PfxCt)");
8108 else
8109 json_object_string_add(
8110 json_peer, "state",
8111 lookup_msg(bgp_status_msg, peer->status,
8112 NULL));
8113
8114 if (peer->conf_if)
8115 json_object_string_add(json_peer, "idType",
8116 "interface");
8117 else if (peer->su.sa.sa_family == AF_INET)
8118 json_object_string_add(json_peer, "idType",
8119 "ipv4");
8120 else if (peer->su.sa.sa_family == AF_INET6)
8121 json_object_string_add(json_peer, "idType",
8122 "ipv6");
8123
8124 json_object_object_add(json_peers, peer->host,
8125 json_peer);
8126 } else {
8127 memset(dn_flag, '\0', sizeof(dn_flag));
8128 if (peer_dynamic_neighbor(peer)) {
8129 dn_count++;
8130 dn_flag[0] = '*';
8131 }
8132
8133 if (peer->hostname
8134 && bgp_flag_check(bgp, BGP_FLAG_SHOW_HOSTNAME))
8135 len = vty_out(vty, "%s%s(%s)", dn_flag,
8136 peer->hostname, peer->host);
8137 else
8138 len = vty_out(vty, "%s%s", dn_flag, peer->host);
8139
8140 /* pad the neighbor column with spaces */
8141 if (len < max_neighbor_width)
8142 vty_out(vty, "%*s", max_neighbor_width - len,
8143 " ");
8144
8145 vty_out(vty, "4 %10u %7u %7u %8" PRIu64 " %4d %4zd %8s",
8146 peer->as, PEER_TOTAL_RX(peer),
8147 PEER_TOTAL_TX(peer), peer->version[afi][safi],
8148 0, peer->obuf->count,
8149 peer_uptime(peer->uptime, timebuf,
8150 BGP_UPTIME_LEN, 0, NULL));
8151
8152 if (peer->status == Established)
8153 if (peer->afc_recv[afi][safi])
8154 vty_out(vty, " %12ld",
8155 peer->pcount[afi]
8156 [pfx_rcd_safi]);
8157 else
8158 vty_out(vty, " NoNeg");
8159 else {
8160 if (CHECK_FLAG(peer->flags, PEER_FLAG_SHUTDOWN))
8161 vty_out(vty, " Idle (Admin)");
8162 else if (CHECK_FLAG(
8163 peer->sflags,
8164 PEER_STATUS_PREFIX_OVERFLOW))
8165 vty_out(vty, " Idle (PfxCt)");
8166 else
8167 vty_out(vty, " %12s",
8168 lookup_msg(bgp_status_msg,
8169 peer->status, NULL));
8170 }
8171 vty_out(vty, "\n");
8172 }
8173 }
8174
8175 if (use_json) {
8176 json_object_object_add(json, "peers", json_peers);
8177
8178 json_object_int_add(json, "totalPeers", count);
8179 json_object_int_add(json, "dynamicPeers", dn_count);
8180
8181 bgp_show_bestpath_json(bgp, json);
8182
8183 vty_out(vty, "%s\n", json_object_to_json_string_ext(
8184 json, JSON_C_TO_STRING_PRETTY));
8185 json_object_free(json);
8186 } else {
8187 if (count)
8188 vty_out(vty, "\nTotal number of neighbors %d\n", count);
8189 else {
8190 vty_out(vty, "No %s neighbor is configured\n",
8191 afi_safi_print(afi, safi));
8192 }
8193
8194 if (dn_count) {
8195 vty_out(vty, "* - dynamic neighbor\n");
8196 vty_out(vty, "%d dynamic neighbor(s), limit %d\n",
8197 dn_count, bgp->dynamic_neighbors_limit);
8198 }
8199 }
8200
8201 return CMD_SUCCESS;
8202 }
8203
8204 static void bgp_show_summary_afi_safi(struct vty *vty, struct bgp *bgp, int afi,
8205 int safi, bool use_json,
8206 json_object *json)
8207 {
8208 int is_first = 1;
8209 int afi_wildcard = (afi == AFI_MAX);
8210 int safi_wildcard = (safi == SAFI_MAX);
8211 int is_wildcard = (afi_wildcard || safi_wildcard);
8212 bool nbr_output = false;
8213
8214 if (use_json && is_wildcard)
8215 vty_out(vty, "{\n");
8216 if (afi_wildcard)
8217 afi = 1; /* AFI_IP */
8218 while (afi < AFI_MAX) {
8219 if (safi_wildcard)
8220 safi = 1; /* SAFI_UNICAST */
8221 while (safi < SAFI_MAX) {
8222 if (bgp_afi_safi_peer_exists(bgp, afi, safi)) {
8223 nbr_output = true;
8224 if (is_wildcard) {
8225 /*
8226 * So limit output to those afi/safi
8227 * pairs that
8228 * actualy have something interesting in
8229 * them
8230 */
8231 if (use_json) {
8232 json = json_object_new_object();
8233
8234 if (!is_first)
8235 vty_out(vty, ",\n");
8236 else
8237 is_first = 0;
8238
8239 vty_out(vty, "\"%s\":",
8240 afi_safi_json(afi,
8241 safi));
8242 } else {
8243 vty_out(vty, "\n%s Summary:\n",
8244 afi_safi_print(afi,
8245 safi));
8246 }
8247 }
8248 bgp_show_summary(vty, bgp, afi, safi, use_json,
8249 json);
8250 }
8251 safi++;
8252 if (!safi_wildcard)
8253 safi = SAFI_MAX;
8254 }
8255 afi++;
8256 if (!afi_wildcard)
8257 afi = AFI_MAX;
8258 }
8259
8260 if (use_json && is_wildcard)
8261 vty_out(vty, "}\n");
8262 else if (!nbr_output) {
8263 if (use_json)
8264 vty_out(vty, "{}\n");
8265 else
8266 vty_out(vty, "%% No BGP neighbors found\n");
8267 }
8268 }
8269
8270 static void bgp_show_all_instances_summary_vty(struct vty *vty, afi_t afi,
8271 safi_t safi, bool use_json)
8272 {
8273 struct listnode *node, *nnode;
8274 struct bgp *bgp;
8275 json_object *json = NULL;
8276 int is_first = 1;
8277 bool nbr_output = false;
8278
8279 if (use_json)
8280 vty_out(vty, "{\n");
8281
8282 for (ALL_LIST_ELEMENTS(bm->bgp, node, nnode, bgp)) {
8283 nbr_output = true;
8284 if (use_json) {
8285 json = json_object_new_object();
8286
8287 if (!is_first)
8288 vty_out(vty, ",\n");
8289 else
8290 is_first = 0;
8291
8292 vty_out(vty, "\"%s\":",
8293 (bgp->inst_type == BGP_INSTANCE_TYPE_DEFAULT)
8294 ? VRF_DEFAULT_NAME
8295 : bgp->name);
8296 } else {
8297 vty_out(vty, "\nInstance %s:\n",
8298 (bgp->inst_type == BGP_INSTANCE_TYPE_DEFAULT)
8299 ? VRF_DEFAULT_NAME
8300 : bgp->name);
8301 }
8302 bgp_show_summary_afi_safi(vty, bgp, afi, safi, use_json, json);
8303 }
8304
8305 if (use_json)
8306 vty_out(vty, "}\n");
8307 else if (!nbr_output)
8308 vty_out(vty, "%% BGP instance not found\n");
8309 }
8310
8311 int bgp_show_summary_vty(struct vty *vty, const char *name, afi_t afi,
8312 safi_t safi, bool use_json)
8313 {
8314 struct bgp *bgp;
8315
8316 if (name) {
8317 if (strmatch(name, "all")) {
8318 bgp_show_all_instances_summary_vty(vty, afi, safi,
8319 use_json);
8320 return CMD_SUCCESS;
8321 } else {
8322 bgp = bgp_lookup_by_name(name);
8323
8324 if (!bgp) {
8325 if (use_json)
8326 vty_out(vty, "{}\n");
8327 else
8328 vty_out(vty,
8329 "%% BGP instance not found\n");
8330 return CMD_WARNING;
8331 }
8332
8333 bgp_show_summary_afi_safi(vty, bgp, afi, safi, use_json,
8334 NULL);
8335 return CMD_SUCCESS;
8336 }
8337 }
8338
8339 bgp = bgp_get_default();
8340
8341 if (bgp)
8342 bgp_show_summary_afi_safi(vty, bgp, afi, safi, use_json, NULL);
8343 else {
8344 if (use_json)
8345 vty_out(vty, "{}\n");
8346 else
8347 vty_out(vty, "%% BGP instance not found\n");
8348 return CMD_WARNING;
8349 }
8350
8351 return CMD_SUCCESS;
8352 }
8353
8354 /* `show [ip] bgp summary' commands. */
8355 DEFUN (show_ip_bgp_summary,
8356 show_ip_bgp_summary_cmd,
8357 "show [ip] bgp [<view|vrf> VIEWVRFNAME] ["BGP_AFI_CMD_STR" ["BGP_SAFI_WITH_LABEL_CMD_STR"]] summary [json]",
8358 SHOW_STR
8359 IP_STR
8360 BGP_STR
8361 BGP_INSTANCE_HELP_STR
8362 BGP_AFI_HELP_STR
8363 BGP_SAFI_WITH_LABEL_HELP_STR
8364 "Summary of BGP neighbor status\n"
8365 JSON_STR)
8366 {
8367 char *vrf = NULL;
8368 afi_t afi = AFI_MAX;
8369 safi_t safi = SAFI_MAX;
8370
8371 int idx = 0;
8372
8373 /* show [ip] bgp */
8374 if (argv_find(argv, argc, "ip", &idx))
8375 afi = AFI_IP;
8376 /* [<vrf> VIEWVRFNAME] */
8377 if (argv_find(argv, argc, "vrf", &idx)) {
8378 vrf = argv[idx + 1]->arg;
8379 if (vrf && strmatch(vrf, VRF_DEFAULT_NAME))
8380 vrf = NULL;
8381 } else if (argv_find(argv, argc, "view", &idx))
8382 /* [<view> VIEWVRFNAME] */
8383 vrf = argv[idx + 1]->arg;
8384 /* ["BGP_AFI_CMD_STR" ["BGP_SAFI_CMD_STR"]] */
8385 if (argv_find_and_parse_afi(argv, argc, &idx, &afi)) {
8386 argv_find_and_parse_safi(argv, argc, &idx, &safi);
8387 }
8388
8389 bool uj = use_json(argc, argv);
8390
8391 return bgp_show_summary_vty(vty, vrf, afi, safi, uj);
8392 }
8393
8394 const char *afi_safi_print(afi_t afi, safi_t safi)
8395 {
8396 if (afi == AFI_IP && safi == SAFI_UNICAST)
8397 return "IPv4 Unicast";
8398 else if (afi == AFI_IP && safi == SAFI_MULTICAST)
8399 return "IPv4 Multicast";
8400 else if (afi == AFI_IP && safi == SAFI_LABELED_UNICAST)
8401 return "IPv4 Labeled Unicast";
8402 else if (afi == AFI_IP && safi == SAFI_MPLS_VPN)
8403 return "IPv4 VPN";
8404 else if (afi == AFI_IP && safi == SAFI_ENCAP)
8405 return "IPv4 Encap";
8406 else if (afi == AFI_IP && safi == SAFI_FLOWSPEC)
8407 return "IPv4 Flowspec";
8408 else if (afi == AFI_IP6 && safi == SAFI_UNICAST)
8409 return "IPv6 Unicast";
8410 else if (afi == AFI_IP6 && safi == SAFI_MULTICAST)
8411 return "IPv6 Multicast";
8412 else if (afi == AFI_IP6 && safi == SAFI_LABELED_UNICAST)
8413 return "IPv6 Labeled Unicast";
8414 else if (afi == AFI_IP6 && safi == SAFI_MPLS_VPN)
8415 return "IPv6 VPN";
8416 else if (afi == AFI_IP6 && safi == SAFI_ENCAP)
8417 return "IPv6 Encap";
8418 else if (afi == AFI_IP6 && safi == SAFI_FLOWSPEC)
8419 return "IPv6 Flowspec";
8420 else if (afi == AFI_L2VPN && safi == SAFI_EVPN)
8421 return "L2VPN EVPN";
8422 else
8423 return "Unknown";
8424 }
8425
8426 /*
8427 * Please note that we have intentionally camelCased
8428 * the return strings here. So if you want
8429 * to use this function, please ensure you
8430 * are doing this within json output
8431 */
8432 const char *afi_safi_json(afi_t afi, safi_t safi)
8433 {
8434 if (afi == AFI_IP && safi == SAFI_UNICAST)
8435 return "ipv4Unicast";
8436 else if (afi == AFI_IP && safi == SAFI_MULTICAST)
8437 return "ipv4Multicast";
8438 else if (afi == AFI_IP && safi == SAFI_LABELED_UNICAST)
8439 return "ipv4LabeledUnicast";
8440 else if (afi == AFI_IP && safi == SAFI_MPLS_VPN)
8441 return "ipv4Vpn";
8442 else if (afi == AFI_IP && safi == SAFI_ENCAP)
8443 return "ipv4Encap";
8444 else if (afi == AFI_IP && safi == SAFI_FLOWSPEC)
8445 return "ipv4Flowspec";
8446 else if (afi == AFI_IP6 && safi == SAFI_UNICAST)
8447 return "ipv6Unicast";
8448 else if (afi == AFI_IP6 && safi == SAFI_MULTICAST)
8449 return "ipv6Multicast";
8450 else if (afi == AFI_IP6 && safi == SAFI_LABELED_UNICAST)
8451 return "ipv6LabeledUnicast";
8452 else if (afi == AFI_IP6 && safi == SAFI_MPLS_VPN)
8453 return "ipv6Vpn";
8454 else if (afi == AFI_IP6 && safi == SAFI_ENCAP)
8455 return "ipv6Encap";
8456 else if (afi == AFI_IP6 && safi == SAFI_FLOWSPEC)
8457 return "ipv6Flowspec";
8458 else if (afi == AFI_L2VPN && safi == SAFI_EVPN)
8459 return "l2VpnEvpn";
8460 else
8461 return "Unknown";
8462 }
8463
8464 /* Show BGP peer's information. */
8465 enum show_type { show_all, show_peer, show_ipv4_all, show_ipv6_all, show_ipv4_peer, show_ipv6_peer };
8466
8467 static void bgp_show_peer_afi_orf_cap(struct vty *vty, struct peer *p,
8468 afi_t afi, safi_t safi,
8469 uint16_t adv_smcap, uint16_t adv_rmcap,
8470 uint16_t rcv_smcap, uint16_t rcv_rmcap,
8471 bool use_json, json_object *json_pref)
8472 {
8473 /* Send-Mode */
8474 if (CHECK_FLAG(p->af_cap[afi][safi], adv_smcap)
8475 || CHECK_FLAG(p->af_cap[afi][safi], rcv_smcap)) {
8476 if (use_json) {
8477 if (CHECK_FLAG(p->af_cap[afi][safi], adv_smcap)
8478 && CHECK_FLAG(p->af_cap[afi][safi], rcv_smcap))
8479 json_object_string_add(json_pref, "sendMode",
8480 "advertisedAndReceived");
8481 else if (CHECK_FLAG(p->af_cap[afi][safi], adv_smcap))
8482 json_object_string_add(json_pref, "sendMode",
8483 "advertised");
8484 else if (CHECK_FLAG(p->af_cap[afi][safi], rcv_smcap))
8485 json_object_string_add(json_pref, "sendMode",
8486 "received");
8487 } else {
8488 vty_out(vty, " Send-mode: ");
8489 if (CHECK_FLAG(p->af_cap[afi][safi], adv_smcap))
8490 vty_out(vty, "advertised");
8491 if (CHECK_FLAG(p->af_cap[afi][safi], rcv_smcap))
8492 vty_out(vty, "%sreceived",
8493 CHECK_FLAG(p->af_cap[afi][safi],
8494 adv_smcap)
8495 ? ", "
8496 : "");
8497 vty_out(vty, "\n");
8498 }
8499 }
8500
8501 /* Receive-Mode */
8502 if (CHECK_FLAG(p->af_cap[afi][safi], adv_rmcap)
8503 || CHECK_FLAG(p->af_cap[afi][safi], rcv_rmcap)) {
8504 if (use_json) {
8505 if (CHECK_FLAG(p->af_cap[afi][safi], adv_rmcap)
8506 && CHECK_FLAG(p->af_cap[afi][safi], rcv_rmcap))
8507 json_object_string_add(json_pref, "recvMode",
8508 "advertisedAndReceived");
8509 else if (CHECK_FLAG(p->af_cap[afi][safi], adv_rmcap))
8510 json_object_string_add(json_pref, "recvMode",
8511 "advertised");
8512 else if (CHECK_FLAG(p->af_cap[afi][safi], rcv_rmcap))
8513 json_object_string_add(json_pref, "recvMode",
8514 "received");
8515 } else {
8516 vty_out(vty, " Receive-mode: ");
8517 if (CHECK_FLAG(p->af_cap[afi][safi], adv_rmcap))
8518 vty_out(vty, "advertised");
8519 if (CHECK_FLAG(p->af_cap[afi][safi], rcv_rmcap))
8520 vty_out(vty, "%sreceived",
8521 CHECK_FLAG(p->af_cap[afi][safi],
8522 adv_rmcap)
8523 ? ", "
8524 : "");
8525 vty_out(vty, "\n");
8526 }
8527 }
8528 }
8529
8530 static void bgp_show_peer_afi(struct vty *vty, struct peer *p, afi_t afi,
8531 safi_t safi, bool use_json,
8532 json_object *json_neigh)
8533 {
8534 struct bgp_filter *filter;
8535 struct peer_af *paf;
8536 char orf_pfx_name[BUFSIZ];
8537 int orf_pfx_count;
8538 json_object *json_af = NULL;
8539 json_object *json_prefA = NULL;
8540 json_object *json_prefB = NULL;
8541 json_object *json_addr = NULL;
8542
8543 if (use_json) {
8544 json_addr = json_object_new_object();
8545 json_af = json_object_new_object();
8546 filter = &p->filter[afi][safi];
8547
8548 if (peer_group_active(p))
8549 json_object_string_add(json_addr, "peerGroupMember",
8550 p->group->name);
8551
8552 paf = peer_af_find(p, afi, safi);
8553 if (paf && PAF_SUBGRP(paf)) {
8554 json_object_int_add(json_addr, "updateGroupId",
8555 PAF_UPDGRP(paf)->id);
8556 json_object_int_add(json_addr, "subGroupId",
8557 PAF_SUBGRP(paf)->id);
8558 json_object_int_add(json_addr, "packetQueueLength",
8559 bpacket_queue_virtual_length(paf));
8560 }
8561
8562 if (CHECK_FLAG(p->af_cap[afi][safi], PEER_CAP_ORF_PREFIX_SM_ADV)
8563 || CHECK_FLAG(p->af_cap[afi][safi],
8564 PEER_CAP_ORF_PREFIX_SM_RCV)
8565 || CHECK_FLAG(p->af_cap[afi][safi],
8566 PEER_CAP_ORF_PREFIX_RM_ADV)
8567 || CHECK_FLAG(p->af_cap[afi][safi],
8568 PEER_CAP_ORF_PREFIX_RM_RCV)) {
8569 json_object_int_add(json_af, "orfType",
8570 ORF_TYPE_PREFIX);
8571 json_prefA = json_object_new_object();
8572 bgp_show_peer_afi_orf_cap(vty, p, afi, safi,
8573 PEER_CAP_ORF_PREFIX_SM_ADV,
8574 PEER_CAP_ORF_PREFIX_RM_ADV,
8575 PEER_CAP_ORF_PREFIX_SM_RCV,
8576 PEER_CAP_ORF_PREFIX_RM_RCV,
8577 use_json, json_prefA);
8578 json_object_object_add(json_af, "orfPrefixList",
8579 json_prefA);
8580 }
8581
8582 if (CHECK_FLAG(p->af_cap[afi][safi], PEER_CAP_ORF_PREFIX_SM_ADV)
8583 || CHECK_FLAG(p->af_cap[afi][safi],
8584 PEER_CAP_ORF_PREFIX_SM_OLD_RCV)
8585 || CHECK_FLAG(p->af_cap[afi][safi],
8586 PEER_CAP_ORF_PREFIX_RM_ADV)
8587 || CHECK_FLAG(p->af_cap[afi][safi],
8588 PEER_CAP_ORF_PREFIX_RM_OLD_RCV)) {
8589 json_object_int_add(json_af, "orfOldType",
8590 ORF_TYPE_PREFIX_OLD);
8591 json_prefB = json_object_new_object();
8592 bgp_show_peer_afi_orf_cap(
8593 vty, p, afi, safi, PEER_CAP_ORF_PREFIX_SM_ADV,
8594 PEER_CAP_ORF_PREFIX_RM_ADV,
8595 PEER_CAP_ORF_PREFIX_SM_OLD_RCV,
8596 PEER_CAP_ORF_PREFIX_RM_OLD_RCV, use_json,
8597 json_prefB);
8598 json_object_object_add(json_af, "orfOldPrefixList",
8599 json_prefB);
8600 }
8601
8602 if (CHECK_FLAG(p->af_cap[afi][safi], PEER_CAP_ORF_PREFIX_SM_ADV)
8603 || CHECK_FLAG(p->af_cap[afi][safi],
8604 PEER_CAP_ORF_PREFIX_SM_RCV)
8605 || CHECK_FLAG(p->af_cap[afi][safi],
8606 PEER_CAP_ORF_PREFIX_SM_OLD_RCV)
8607 || CHECK_FLAG(p->af_cap[afi][safi],
8608 PEER_CAP_ORF_PREFIX_RM_ADV)
8609 || CHECK_FLAG(p->af_cap[afi][safi],
8610 PEER_CAP_ORF_PREFIX_RM_RCV)
8611 || CHECK_FLAG(p->af_cap[afi][safi],
8612 PEER_CAP_ORF_PREFIX_RM_OLD_RCV))
8613 json_object_object_add(json_addr, "afDependentCap",
8614 json_af);
8615 else
8616 json_object_free(json_af);
8617
8618 sprintf(orf_pfx_name, "%s.%d.%d", p->host, afi, safi);
8619 orf_pfx_count = prefix_bgp_show_prefix_list(
8620 NULL, afi, orf_pfx_name, use_json);
8621
8622 if (CHECK_FLAG(p->af_sflags[afi][safi],
8623 PEER_STATUS_ORF_PREFIX_SEND)
8624 || orf_pfx_count) {
8625 if (CHECK_FLAG(p->af_sflags[afi][safi],
8626 PEER_STATUS_ORF_PREFIX_SEND))
8627 json_object_boolean_true_add(json_neigh,
8628 "orfSent");
8629 if (orf_pfx_count)
8630 json_object_int_add(json_addr, "orfRecvCounter",
8631 orf_pfx_count);
8632 }
8633 if (CHECK_FLAG(p->af_sflags[afi][safi],
8634 PEER_STATUS_ORF_WAIT_REFRESH))
8635 json_object_string_add(
8636 json_addr, "orfFirstUpdate",
8637 "deferredUntilORFOrRouteRefreshRecvd");
8638
8639 if (CHECK_FLAG(p->af_flags[afi][safi],
8640 PEER_FLAG_REFLECTOR_CLIENT))
8641 json_object_boolean_true_add(json_addr,
8642 "routeReflectorClient");
8643 if (CHECK_FLAG(p->af_flags[afi][safi],
8644 PEER_FLAG_RSERVER_CLIENT))
8645 json_object_boolean_true_add(json_addr,
8646 "routeServerClient");
8647 if (CHECK_FLAG(p->af_flags[afi][safi], PEER_FLAG_SOFT_RECONFIG))
8648 json_object_boolean_true_add(json_addr,
8649 "inboundSoftConfigPermit");
8650
8651 if (CHECK_FLAG(p->af_flags[afi][safi],
8652 PEER_FLAG_REMOVE_PRIVATE_AS_ALL_REPLACE))
8653 json_object_boolean_true_add(
8654 json_addr,
8655 "privateAsNumsAllReplacedInUpdatesToNbr");
8656 else if (CHECK_FLAG(p->af_flags[afi][safi],
8657 PEER_FLAG_REMOVE_PRIVATE_AS_REPLACE))
8658 json_object_boolean_true_add(
8659 json_addr,
8660 "privateAsNumsReplacedInUpdatesToNbr");
8661 else if (CHECK_FLAG(p->af_flags[afi][safi],
8662 PEER_FLAG_REMOVE_PRIVATE_AS_ALL))
8663 json_object_boolean_true_add(
8664 json_addr,
8665 "privateAsNumsAllRemovedInUpdatesToNbr");
8666 else if (CHECK_FLAG(p->af_flags[afi][safi],
8667 PEER_FLAG_REMOVE_PRIVATE_AS))
8668 json_object_boolean_true_add(
8669 json_addr,
8670 "privateAsNumsRemovedInUpdatesToNbr");
8671
8672 if (p->addpath_type[afi][safi] != BGP_ADDPATH_NONE)
8673 json_object_boolean_true_add(
8674 json_addr,
8675 bgp_addpath_names(p->addpath_type[afi][safi])
8676 ->type_json_name);
8677
8678 if (CHECK_FLAG(p->af_flags[afi][safi], PEER_FLAG_AS_OVERRIDE))
8679 json_object_string_add(json_addr,
8680 "overrideASNsInOutboundUpdates",
8681 "ifAspathEqualRemoteAs");
8682
8683 if (CHECK_FLAG(p->af_flags[afi][safi], PEER_FLAG_NEXTHOP_SELF)
8684 || CHECK_FLAG(p->af_flags[afi][safi],
8685 PEER_FLAG_FORCE_NEXTHOP_SELF))
8686 json_object_boolean_true_add(json_addr,
8687 "routerAlwaysNextHop");
8688 if (CHECK_FLAG(p->af_flags[afi][safi],
8689 PEER_FLAG_AS_PATH_UNCHANGED))
8690 json_object_boolean_true_add(
8691 json_addr, "unchangedAsPathPropogatedToNbr");
8692 if (CHECK_FLAG(p->af_flags[afi][safi],
8693 PEER_FLAG_NEXTHOP_UNCHANGED))
8694 json_object_boolean_true_add(
8695 json_addr, "unchangedNextHopPropogatedToNbr");
8696 if (CHECK_FLAG(p->af_flags[afi][safi], PEER_FLAG_MED_UNCHANGED))
8697 json_object_boolean_true_add(
8698 json_addr, "unchangedMedPropogatedToNbr");
8699 if (CHECK_FLAG(p->af_flags[afi][safi], PEER_FLAG_SEND_COMMUNITY)
8700 || CHECK_FLAG(p->af_flags[afi][safi],
8701 PEER_FLAG_SEND_EXT_COMMUNITY)) {
8702 if (CHECK_FLAG(p->af_flags[afi][safi],
8703 PEER_FLAG_SEND_COMMUNITY)
8704 && CHECK_FLAG(p->af_flags[afi][safi],
8705 PEER_FLAG_SEND_EXT_COMMUNITY))
8706 json_object_string_add(json_addr,
8707 "commAttriSentToNbr",
8708 "extendedAndStandard");
8709 else if (CHECK_FLAG(p->af_flags[afi][safi],
8710 PEER_FLAG_SEND_EXT_COMMUNITY))
8711 json_object_string_add(json_addr,
8712 "commAttriSentToNbr",
8713 "extended");
8714 else
8715 json_object_string_add(json_addr,
8716 "commAttriSentToNbr",
8717 "standard");
8718 }
8719 if (CHECK_FLAG(p->af_flags[afi][safi],
8720 PEER_FLAG_DEFAULT_ORIGINATE)) {
8721 if (p->default_rmap[afi][safi].name)
8722 json_object_string_add(
8723 json_addr, "defaultRouteMap",
8724 p->default_rmap[afi][safi].name);
8725
8726 if (paf && PAF_SUBGRP(paf)
8727 && CHECK_FLAG(PAF_SUBGRP(paf)->sflags,
8728 SUBGRP_STATUS_DEFAULT_ORIGINATE))
8729 json_object_boolean_true_add(json_addr,
8730 "defaultSent");
8731 else
8732 json_object_boolean_true_add(json_addr,
8733 "defaultNotSent");
8734 }
8735
8736 if (afi == AFI_L2VPN && safi == SAFI_EVPN) {
8737 if (is_evpn_enabled())
8738 json_object_boolean_true_add(
8739 json_addr, "advertiseAllVnis");
8740 }
8741
8742 if (filter->plist[FILTER_IN].name
8743 || filter->dlist[FILTER_IN].name
8744 || filter->aslist[FILTER_IN].name
8745 || filter->map[RMAP_IN].name)
8746 json_object_boolean_true_add(json_addr,
8747 "inboundPathPolicyConfig");
8748 if (filter->plist[FILTER_OUT].name
8749 || filter->dlist[FILTER_OUT].name
8750 || filter->aslist[FILTER_OUT].name
8751 || filter->map[RMAP_OUT].name || filter->usmap.name)
8752 json_object_boolean_true_add(
8753 json_addr, "outboundPathPolicyConfig");
8754
8755 /* prefix-list */
8756 if (filter->plist[FILTER_IN].name)
8757 json_object_string_add(json_addr,
8758 "incomingUpdatePrefixFilterList",
8759 filter->plist[FILTER_IN].name);
8760 if (filter->plist[FILTER_OUT].name)
8761 json_object_string_add(json_addr,
8762 "outgoingUpdatePrefixFilterList",
8763 filter->plist[FILTER_OUT].name);
8764
8765 /* distribute-list */
8766 if (filter->dlist[FILTER_IN].name)
8767 json_object_string_add(
8768 json_addr, "incomingUpdateNetworkFilterList",
8769 filter->dlist[FILTER_IN].name);
8770 if (filter->dlist[FILTER_OUT].name)
8771 json_object_string_add(
8772 json_addr, "outgoingUpdateNetworkFilterList",
8773 filter->dlist[FILTER_OUT].name);
8774
8775 /* filter-list. */
8776 if (filter->aslist[FILTER_IN].name)
8777 json_object_string_add(json_addr,
8778 "incomingUpdateAsPathFilterList",
8779 filter->aslist[FILTER_IN].name);
8780 if (filter->aslist[FILTER_OUT].name)
8781 json_object_string_add(json_addr,
8782 "outgoingUpdateAsPathFilterList",
8783 filter->aslist[FILTER_OUT].name);
8784
8785 /* route-map. */
8786 if (filter->map[RMAP_IN].name)
8787 json_object_string_add(
8788 json_addr, "routeMapForIncomingAdvertisements",
8789 filter->map[RMAP_IN].name);
8790 if (filter->map[RMAP_OUT].name)
8791 json_object_string_add(
8792 json_addr, "routeMapForOutgoingAdvertisements",
8793 filter->map[RMAP_OUT].name);
8794
8795 /* ebgp-requires-policy (inbound) */
8796 if (p->bgp->ebgp_requires_policy == DEFAULT_EBGP_POLICY_ENABLED
8797 && !bgp_inbound_policy_exists(p, filter))
8798 json_object_string_add(
8799 json_addr, "inboundEbgpRequiresPolicy",
8800 "Inbound updates discarded due to missing policy");
8801
8802 /* ebgp-requires-policy (outbound) */
8803 if (p->bgp->ebgp_requires_policy == DEFAULT_EBGP_POLICY_ENABLED
8804 && (!bgp_outbound_policy_exists(p, filter)))
8805 json_object_string_add(
8806 json_addr, "outboundEbgpRequiresPolicy",
8807 "Outbound updates discarded due to missing policy");
8808
8809 /* unsuppress-map */
8810 if (filter->usmap.name)
8811 json_object_string_add(json_addr,
8812 "selectiveUnsuppressRouteMap",
8813 filter->usmap.name);
8814
8815 /* Receive prefix count */
8816 json_object_int_add(json_addr, "acceptedPrefixCounter",
8817 p->pcount[afi][safi]);
8818 if (paf && PAF_SUBGRP(paf))
8819 json_object_int_add(json_addr, "sentPrefixCounter",
8820 (PAF_SUBGRP(paf))->scount);
8821
8822 /* Maximum prefix */
8823 if (CHECK_FLAG(p->af_flags[afi][safi], PEER_FLAG_MAX_PREFIX)) {
8824 json_object_int_add(json_addr, "prefixAllowedMax",
8825 p->pmax[afi][safi]);
8826 if (CHECK_FLAG(p->af_flags[afi][safi],
8827 PEER_FLAG_MAX_PREFIX_WARNING))
8828 json_object_boolean_true_add(
8829 json_addr, "prefixAllowedMaxWarning");
8830 json_object_int_add(json_addr,
8831 "prefixAllowedWarningThresh",
8832 p->pmax_threshold[afi][safi]);
8833 if (p->pmax_restart[afi][safi])
8834 json_object_int_add(
8835 json_addr,
8836 "prefixAllowedRestartIntervalMsecs",
8837 p->pmax_restart[afi][safi] * 60000);
8838 }
8839 json_object_object_add(json_neigh, afi_safi_print(afi, safi),
8840 json_addr);
8841
8842 } else {
8843 filter = &p->filter[afi][safi];
8844
8845 vty_out(vty, " For address family: %s\n",
8846 afi_safi_print(afi, safi));
8847
8848 if (peer_group_active(p))
8849 vty_out(vty, " %s peer-group member\n",
8850 p->group->name);
8851
8852 paf = peer_af_find(p, afi, safi);
8853 if (paf && PAF_SUBGRP(paf)) {
8854 vty_out(vty, " Update group %" PRIu64
8855 ", subgroup %" PRIu64 "\n",
8856 PAF_UPDGRP(paf)->id, PAF_SUBGRP(paf)->id);
8857 vty_out(vty, " Packet Queue length %d\n",
8858 bpacket_queue_virtual_length(paf));
8859 } else {
8860 vty_out(vty, " Not part of any update group\n");
8861 }
8862 if (CHECK_FLAG(p->af_cap[afi][safi], PEER_CAP_ORF_PREFIX_SM_ADV)
8863 || CHECK_FLAG(p->af_cap[afi][safi],
8864 PEER_CAP_ORF_PREFIX_SM_RCV)
8865 || CHECK_FLAG(p->af_cap[afi][safi],
8866 PEER_CAP_ORF_PREFIX_SM_OLD_RCV)
8867 || CHECK_FLAG(p->af_cap[afi][safi],
8868 PEER_CAP_ORF_PREFIX_RM_ADV)
8869 || CHECK_FLAG(p->af_cap[afi][safi],
8870 PEER_CAP_ORF_PREFIX_RM_RCV)
8871 || CHECK_FLAG(p->af_cap[afi][safi],
8872 PEER_CAP_ORF_PREFIX_RM_OLD_RCV))
8873 vty_out(vty, " AF-dependant capabilities:\n");
8874
8875 if (CHECK_FLAG(p->af_cap[afi][safi], PEER_CAP_ORF_PREFIX_SM_ADV)
8876 || CHECK_FLAG(p->af_cap[afi][safi],
8877 PEER_CAP_ORF_PREFIX_SM_RCV)
8878 || CHECK_FLAG(p->af_cap[afi][safi],
8879 PEER_CAP_ORF_PREFIX_RM_ADV)
8880 || CHECK_FLAG(p->af_cap[afi][safi],
8881 PEER_CAP_ORF_PREFIX_RM_RCV)) {
8882 vty_out(vty,
8883 " Outbound Route Filter (ORF) type (%d) Prefix-list:\n",
8884 ORF_TYPE_PREFIX);
8885 bgp_show_peer_afi_orf_cap(
8886 vty, p, afi, safi, PEER_CAP_ORF_PREFIX_SM_ADV,
8887 PEER_CAP_ORF_PREFIX_RM_ADV,
8888 PEER_CAP_ORF_PREFIX_SM_RCV,
8889 PEER_CAP_ORF_PREFIX_RM_RCV, use_json, NULL);
8890 }
8891 if (CHECK_FLAG(p->af_cap[afi][safi], PEER_CAP_ORF_PREFIX_SM_ADV)
8892 || CHECK_FLAG(p->af_cap[afi][safi],
8893 PEER_CAP_ORF_PREFIX_SM_OLD_RCV)
8894 || CHECK_FLAG(p->af_cap[afi][safi],
8895 PEER_CAP_ORF_PREFIX_RM_ADV)
8896 || CHECK_FLAG(p->af_cap[afi][safi],
8897 PEER_CAP_ORF_PREFIX_RM_OLD_RCV)) {
8898 vty_out(vty,
8899 " Outbound Route Filter (ORF) type (%d) Prefix-list:\n",
8900 ORF_TYPE_PREFIX_OLD);
8901 bgp_show_peer_afi_orf_cap(
8902 vty, p, afi, safi, PEER_CAP_ORF_PREFIX_SM_ADV,
8903 PEER_CAP_ORF_PREFIX_RM_ADV,
8904 PEER_CAP_ORF_PREFIX_SM_OLD_RCV,
8905 PEER_CAP_ORF_PREFIX_RM_OLD_RCV, use_json, NULL);
8906 }
8907
8908 sprintf(orf_pfx_name, "%s.%d.%d", p->host, afi, safi);
8909 orf_pfx_count = prefix_bgp_show_prefix_list(
8910 NULL, afi, orf_pfx_name, use_json);
8911
8912 if (CHECK_FLAG(p->af_sflags[afi][safi],
8913 PEER_STATUS_ORF_PREFIX_SEND)
8914 || orf_pfx_count) {
8915 vty_out(vty, " Outbound Route Filter (ORF):");
8916 if (CHECK_FLAG(p->af_sflags[afi][safi],
8917 PEER_STATUS_ORF_PREFIX_SEND))
8918 vty_out(vty, " sent;");
8919 if (orf_pfx_count)
8920 vty_out(vty, " received (%d entries)",
8921 orf_pfx_count);
8922 vty_out(vty, "\n");
8923 }
8924 if (CHECK_FLAG(p->af_sflags[afi][safi],
8925 PEER_STATUS_ORF_WAIT_REFRESH))
8926 vty_out(vty,
8927 " First update is deferred until ORF or ROUTE-REFRESH is received\n");
8928
8929 if (CHECK_FLAG(p->af_flags[afi][safi],
8930 PEER_FLAG_REFLECTOR_CLIENT))
8931 vty_out(vty, " Route-Reflector Client\n");
8932 if (CHECK_FLAG(p->af_flags[afi][safi],
8933 PEER_FLAG_RSERVER_CLIENT))
8934 vty_out(vty, " Route-Server Client\n");
8935 if (CHECK_FLAG(p->af_flags[afi][safi], PEER_FLAG_SOFT_RECONFIG))
8936 vty_out(vty,
8937 " Inbound soft reconfiguration allowed\n");
8938
8939 if (CHECK_FLAG(p->af_flags[afi][safi],
8940 PEER_FLAG_REMOVE_PRIVATE_AS_ALL_REPLACE))
8941 vty_out(vty,
8942 " Private AS numbers (all) replaced in updates to this neighbor\n");
8943 else if (CHECK_FLAG(p->af_flags[afi][safi],
8944 PEER_FLAG_REMOVE_PRIVATE_AS_REPLACE))
8945 vty_out(vty,
8946 " Private AS numbers replaced in updates to this neighbor\n");
8947 else if (CHECK_FLAG(p->af_flags[afi][safi],
8948 PEER_FLAG_REMOVE_PRIVATE_AS_ALL))
8949 vty_out(vty,
8950 " Private AS numbers (all) removed in updates to this neighbor\n");
8951 else if (CHECK_FLAG(p->af_flags[afi][safi],
8952 PEER_FLAG_REMOVE_PRIVATE_AS))
8953 vty_out(vty,
8954 " Private AS numbers removed in updates to this neighbor\n");
8955
8956 if (p->addpath_type[afi][safi] != BGP_ADDPATH_NONE)
8957 vty_out(vty, " %s\n",
8958 bgp_addpath_names(p->addpath_type[afi][safi])
8959 ->human_description);
8960
8961 if (CHECK_FLAG(p->af_flags[afi][safi], PEER_FLAG_AS_OVERRIDE))
8962 vty_out(vty,
8963 " Override ASNs in outbound updates if aspath equals remote-as\n");
8964
8965 if (CHECK_FLAG(p->af_flags[afi][safi], PEER_FLAG_NEXTHOP_SELF)
8966 || CHECK_FLAG(p->af_flags[afi][safi],
8967 PEER_FLAG_FORCE_NEXTHOP_SELF))
8968 vty_out(vty, " NEXT_HOP is always this router\n");
8969 if (CHECK_FLAG(p->af_flags[afi][safi],
8970 PEER_FLAG_AS_PATH_UNCHANGED))
8971 vty_out(vty,
8972 " AS_PATH is propagated unchanged to this neighbor\n");
8973 if (CHECK_FLAG(p->af_flags[afi][safi],
8974 PEER_FLAG_NEXTHOP_UNCHANGED))
8975 vty_out(vty,
8976 " NEXT_HOP is propagated unchanged to this neighbor\n");
8977 if (CHECK_FLAG(p->af_flags[afi][safi], PEER_FLAG_MED_UNCHANGED))
8978 vty_out(vty,
8979 " MED is propagated unchanged to this neighbor\n");
8980 if (CHECK_FLAG(p->af_flags[afi][safi], PEER_FLAG_SEND_COMMUNITY)
8981 || CHECK_FLAG(p->af_flags[afi][safi],
8982 PEER_FLAG_SEND_EXT_COMMUNITY)
8983 || CHECK_FLAG(p->af_flags[afi][safi],
8984 PEER_FLAG_SEND_LARGE_COMMUNITY)) {
8985 vty_out(vty,
8986 " Community attribute sent to this neighbor");
8987 if (CHECK_FLAG(p->af_flags[afi][safi],
8988 PEER_FLAG_SEND_COMMUNITY)
8989 && CHECK_FLAG(p->af_flags[afi][safi],
8990 PEER_FLAG_SEND_EXT_COMMUNITY)
8991 && CHECK_FLAG(p->af_flags[afi][safi],
8992 PEER_FLAG_SEND_LARGE_COMMUNITY))
8993 vty_out(vty, "(all)\n");
8994 else if (CHECK_FLAG(p->af_flags[afi][safi],
8995 PEER_FLAG_SEND_LARGE_COMMUNITY))
8996 vty_out(vty, "(large)\n");
8997 else if (CHECK_FLAG(p->af_flags[afi][safi],
8998 PEER_FLAG_SEND_EXT_COMMUNITY))
8999 vty_out(vty, "(extended)\n");
9000 else
9001 vty_out(vty, "(standard)\n");
9002 }
9003 if (CHECK_FLAG(p->af_flags[afi][safi],
9004 PEER_FLAG_DEFAULT_ORIGINATE)) {
9005 vty_out(vty, " Default information originate,");
9006
9007 if (p->default_rmap[afi][safi].name)
9008 vty_out(vty, " default route-map %s%s,",
9009 p->default_rmap[afi][safi].map ? "*"
9010 : "",
9011 p->default_rmap[afi][safi].name);
9012 if (paf && PAF_SUBGRP(paf)
9013 && CHECK_FLAG(PAF_SUBGRP(paf)->sflags,
9014 SUBGRP_STATUS_DEFAULT_ORIGINATE))
9015 vty_out(vty, " default sent\n");
9016 else
9017 vty_out(vty, " default not sent\n");
9018 }
9019
9020 /* advertise-vni-all */
9021 if (afi == AFI_L2VPN && safi == SAFI_EVPN) {
9022 if (is_evpn_enabled())
9023 vty_out(vty, " advertise-all-vni\n");
9024 }
9025
9026 if (filter->plist[FILTER_IN].name
9027 || filter->dlist[FILTER_IN].name
9028 || filter->aslist[FILTER_IN].name
9029 || filter->map[RMAP_IN].name)
9030 vty_out(vty, " Inbound path policy configured\n");
9031 if (filter->plist[FILTER_OUT].name
9032 || filter->dlist[FILTER_OUT].name
9033 || filter->aslist[FILTER_OUT].name
9034 || filter->map[RMAP_OUT].name || filter->usmap.name)
9035 vty_out(vty, " Outbound path policy configured\n");
9036
9037 /* prefix-list */
9038 if (filter->plist[FILTER_IN].name)
9039 vty_out(vty,
9040 " Incoming update prefix filter list is %s%s\n",
9041 filter->plist[FILTER_IN].plist ? "*" : "",
9042 filter->plist[FILTER_IN].name);
9043 if (filter->plist[FILTER_OUT].name)
9044 vty_out(vty,
9045 " Outgoing update prefix filter list is %s%s\n",
9046 filter->plist[FILTER_OUT].plist ? "*" : "",
9047 filter->plist[FILTER_OUT].name);
9048
9049 /* distribute-list */
9050 if (filter->dlist[FILTER_IN].name)
9051 vty_out(vty,
9052 " Incoming update network filter list is %s%s\n",
9053 filter->dlist[FILTER_IN].alist ? "*" : "",
9054 filter->dlist[FILTER_IN].name);
9055 if (filter->dlist[FILTER_OUT].name)
9056 vty_out(vty,
9057 " Outgoing update network filter list is %s%s\n",
9058 filter->dlist[FILTER_OUT].alist ? "*" : "",
9059 filter->dlist[FILTER_OUT].name);
9060
9061 /* filter-list. */
9062 if (filter->aslist[FILTER_IN].name)
9063 vty_out(vty,
9064 " Incoming update AS path filter list is %s%s\n",
9065 filter->aslist[FILTER_IN].aslist ? "*" : "",
9066 filter->aslist[FILTER_IN].name);
9067 if (filter->aslist[FILTER_OUT].name)
9068 vty_out(vty,
9069 " Outgoing update AS path filter list is %s%s\n",
9070 filter->aslist[FILTER_OUT].aslist ? "*" : "",
9071 filter->aslist[FILTER_OUT].name);
9072
9073 /* route-map. */
9074 if (filter->map[RMAP_IN].name)
9075 vty_out(vty,
9076 " Route map for incoming advertisements is %s%s\n",
9077 filter->map[RMAP_IN].map ? "*" : "",
9078 filter->map[RMAP_IN].name);
9079 if (filter->map[RMAP_OUT].name)
9080 vty_out(vty,
9081 " Route map for outgoing advertisements is %s%s\n",
9082 filter->map[RMAP_OUT].map ? "*" : "",
9083 filter->map[RMAP_OUT].name);
9084
9085 /* ebgp-requires-policy (inbound) */
9086 if (p->bgp->ebgp_requires_policy == DEFAULT_EBGP_POLICY_ENABLED
9087 && !bgp_inbound_policy_exists(p, filter))
9088 vty_out(vty,
9089 " Inbound updates discarded due to missing policy\n");
9090
9091 /* ebgp-requires-policy (outbound) */
9092 if (p->bgp->ebgp_requires_policy == DEFAULT_EBGP_POLICY_ENABLED
9093 && !bgp_outbound_policy_exists(p, filter))
9094 vty_out(vty,
9095 " Outbound updates discarded due to missing policy\n");
9096
9097 /* unsuppress-map */
9098 if (filter->usmap.name)
9099 vty_out(vty,
9100 " Route map for selective unsuppress is %s%s\n",
9101 filter->usmap.map ? "*" : "",
9102 filter->usmap.name);
9103
9104 /* Receive prefix count */
9105 vty_out(vty, " %ld accepted prefixes\n", p->pcount[afi][safi]);
9106
9107 /* Maximum prefix */
9108 if (CHECK_FLAG(p->af_flags[afi][safi], PEER_FLAG_MAX_PREFIX)) {
9109 vty_out(vty, " Maximum prefixes allowed %ld%s\n",
9110 p->pmax[afi][safi],
9111 CHECK_FLAG(p->af_flags[afi][safi],
9112 PEER_FLAG_MAX_PREFIX_WARNING)
9113 ? " (warning-only)"
9114 : "");
9115 vty_out(vty, " Threshold for warning message %d%%",
9116 p->pmax_threshold[afi][safi]);
9117 if (p->pmax_restart[afi][safi])
9118 vty_out(vty, ", restart interval %d min",
9119 p->pmax_restart[afi][safi]);
9120 vty_out(vty, "\n");
9121 }
9122
9123 vty_out(vty, "\n");
9124 }
9125 }
9126
9127 static void bgp_show_peer(struct vty *vty, struct peer *p, bool use_json,
9128 json_object *json)
9129 {
9130 struct bgp *bgp;
9131 char buf1[PREFIX2STR_BUFFER], buf[SU_ADDRSTRLEN];
9132 char timebuf[BGP_UPTIME_LEN];
9133 char dn_flag[2];
9134 const char *subcode_str;
9135 const char *code_str;
9136 afi_t afi;
9137 safi_t safi;
9138 uint16_t i;
9139 uint8_t *msg;
9140 json_object *json_neigh = NULL;
9141 time_t epoch_tbuf;
9142
9143 bgp = p->bgp;
9144
9145 if (use_json)
9146 json_neigh = json_object_new_object();
9147
9148 memset(dn_flag, '\0', sizeof(dn_flag));
9149 if (!p->conf_if && peer_dynamic_neighbor(p))
9150 dn_flag[0] = '*';
9151
9152 if (!use_json) {
9153 if (p->conf_if) /* Configured interface name. */
9154 vty_out(vty, "BGP neighbor on %s: %s, ", p->conf_if,
9155 BGP_PEER_SU_UNSPEC(p)
9156 ? "None"
9157 : sockunion2str(&p->su, buf,
9158 SU_ADDRSTRLEN));
9159 else /* Configured IP address. */
9160 vty_out(vty, "BGP neighbor is %s%s, ", dn_flag,
9161 p->host);
9162 }
9163
9164 if (use_json) {
9165 if (p->conf_if && BGP_PEER_SU_UNSPEC(p))
9166 json_object_string_add(json_neigh, "bgpNeighborAddr",
9167 "none");
9168 else if (p->conf_if && !BGP_PEER_SU_UNSPEC(p))
9169 json_object_string_add(
9170 json_neigh, "bgpNeighborAddr",
9171 sockunion2str(&p->su, buf, SU_ADDRSTRLEN));
9172
9173 json_object_int_add(json_neigh, "remoteAs", p->as);
9174
9175 if (p->change_local_as)
9176 json_object_int_add(json_neigh, "localAs",
9177 p->change_local_as);
9178 else
9179 json_object_int_add(json_neigh, "localAs", p->local_as);
9180
9181 if (CHECK_FLAG(p->flags, PEER_FLAG_LOCAL_AS_NO_PREPEND))
9182 json_object_boolean_true_add(json_neigh,
9183 "localAsNoPrepend");
9184
9185 if (CHECK_FLAG(p->flags, PEER_FLAG_LOCAL_AS_REPLACE_AS))
9186 json_object_boolean_true_add(json_neigh,
9187 "localAsReplaceAs");
9188 } else {
9189 if ((p->as_type == AS_SPECIFIED) || (p->as_type == AS_EXTERNAL)
9190 || (p->as_type == AS_INTERNAL))
9191 vty_out(vty, "remote AS %u, ", p->as);
9192 else
9193 vty_out(vty, "remote AS Unspecified, ");
9194 vty_out(vty, "local AS %u%s%s, ",
9195 p->change_local_as ? p->change_local_as : p->local_as,
9196 CHECK_FLAG(p->flags, PEER_FLAG_LOCAL_AS_NO_PREPEND)
9197 ? " no-prepend"
9198 : "",
9199 CHECK_FLAG(p->flags, PEER_FLAG_LOCAL_AS_REPLACE_AS)
9200 ? " replace-as"
9201 : "");
9202 }
9203 /* peer type internal or confed-internal */
9204 if ((p->as == p->local_as) || (p->as_type == AS_INTERNAL)) {
9205 if (use_json) {
9206 if (CHECK_FLAG(bgp->config, BGP_CONFIG_CONFEDERATION))
9207 json_object_boolean_true_add(
9208 json_neigh, "nbrConfedInternalLink");
9209 else
9210 json_object_boolean_true_add(json_neigh,
9211 "nbrInternalLink");
9212 } else {
9213 if (CHECK_FLAG(bgp->config, BGP_CONFIG_CONFEDERATION))
9214 vty_out(vty, "confed-internal link\n");
9215 else
9216 vty_out(vty, "internal link\n");
9217 }
9218 /* peer type external or confed-external */
9219 } else if (p->as || (p->as_type == AS_EXTERNAL)) {
9220 if (use_json) {
9221 if (CHECK_FLAG(bgp->config, BGP_CONFIG_CONFEDERATION))
9222 json_object_boolean_true_add(
9223 json_neigh, "nbrConfedExternalLink");
9224 else
9225 json_object_boolean_true_add(json_neigh,
9226 "nbrExternalLink");
9227 } else {
9228 if (bgp_confederation_peers_check(bgp, p->as))
9229 vty_out(vty, "confed-external link\n");
9230 else
9231 vty_out(vty, "external link\n");
9232 }
9233 } else {
9234 if (use_json)
9235 json_object_boolean_true_add(json_neigh,
9236 "nbrUnspecifiedLink");
9237 else
9238 vty_out(vty, "unspecified link\n");
9239 }
9240
9241 /* Description. */
9242 if (p->desc) {
9243 if (use_json)
9244 json_object_string_add(json_neigh, "nbrDesc", p->desc);
9245 else
9246 vty_out(vty, " Description: %s\n", p->desc);
9247 }
9248
9249 if (p->hostname) {
9250 if (use_json) {
9251 if (p->hostname)
9252 json_object_string_add(json_neigh, "hostname",
9253 p->hostname);
9254
9255 if (p->domainname)
9256 json_object_string_add(json_neigh, "domainname",
9257 p->domainname);
9258 } else {
9259 if (p->domainname && (p->domainname[0] != '\0'))
9260 vty_out(vty, "Hostname: %s.%s\n", p->hostname,
9261 p->domainname);
9262 else
9263 vty_out(vty, "Hostname: %s\n", p->hostname);
9264 }
9265 }
9266
9267 /* Peer-group */
9268 if (p->group) {
9269 if (use_json) {
9270 json_object_string_add(json_neigh, "peerGroup",
9271 p->group->name);
9272
9273 if (dn_flag[0]) {
9274 struct prefix prefix, *range = NULL;
9275
9276 sockunion2hostprefix(&(p->su), &prefix);
9277 range = peer_group_lookup_dynamic_neighbor_range(
9278 p->group, &prefix);
9279
9280 if (range) {
9281 prefix2str(range, buf1, sizeof(buf1));
9282 json_object_string_add(
9283 json_neigh,
9284 "peerSubnetRangeGroup", buf1);
9285 }
9286 }
9287 } else {
9288 vty_out(vty,
9289 " Member of peer-group %s for session parameters\n",
9290 p->group->name);
9291
9292 if (dn_flag[0]) {
9293 struct prefix prefix, *range = NULL;
9294
9295 sockunion2hostprefix(&(p->su), &prefix);
9296 range = peer_group_lookup_dynamic_neighbor_range(
9297 p->group, &prefix);
9298
9299 if (range) {
9300 prefix2str(range, buf1, sizeof(buf1));
9301 vty_out(vty,
9302 " Belongs to the subnet range group: %s\n",
9303 buf1);
9304 }
9305 }
9306 }
9307 }
9308
9309 if (use_json) {
9310 /* Administrative shutdown. */
9311 if (CHECK_FLAG(p->flags, PEER_FLAG_SHUTDOWN))
9312 json_object_boolean_true_add(json_neigh,
9313 "adminShutDown");
9314
9315 /* BGP Version. */
9316 json_object_int_add(json_neigh, "bgpVersion", 4);
9317 json_object_string_add(
9318 json_neigh, "remoteRouterId",
9319 inet_ntop(AF_INET, &p->remote_id, buf1, sizeof(buf1)));
9320 json_object_string_add(
9321 json_neigh, "localRouterId",
9322 inet_ntop(AF_INET, &bgp->router_id, buf1,
9323 sizeof(buf1)));
9324
9325 /* Confederation */
9326 if (CHECK_FLAG(bgp->config, BGP_CONFIG_CONFEDERATION)
9327 && bgp_confederation_peers_check(bgp, p->as))
9328 json_object_boolean_true_add(json_neigh,
9329 "nbrCommonAdmin");
9330
9331 /* Status. */
9332 json_object_string_add(
9333 json_neigh, "bgpState",
9334 lookup_msg(bgp_status_msg, p->status, NULL));
9335
9336 if (p->status == Established) {
9337 time_t uptime;
9338
9339 uptime = bgp_clock();
9340 uptime -= p->uptime;
9341 epoch_tbuf = time(NULL) - uptime;
9342
9343 #if CONFDATE > 20200101
9344 CPP_NOTICE(
9345 "bgpTimerUp should be deprecated and can be removed now");
9346 #endif
9347 /*
9348 * bgpTimerUp was miliseconds that was accurate
9349 * up to 1 day, then the value returned
9350 * became garbage. So in order to provide
9351 * some level of backwards compatability,
9352 * we still provde the data, but now
9353 * we are returning the correct value
9354 * and also adding a new bgpTimerUpMsec
9355 * which will allow us to deprecate
9356 * this eventually
9357 */
9358 json_object_int_add(json_neigh, "bgpTimerUp",
9359 uptime * 1000);
9360 json_object_int_add(json_neigh, "bgpTimerUpMsec",
9361 uptime * 1000);
9362 json_object_string_add(json_neigh, "bgpTimerUpString",
9363 peer_uptime(p->uptime, timebuf,
9364 BGP_UPTIME_LEN, 0,
9365 NULL));
9366 json_object_int_add(json_neigh,
9367 "bgpTimerUpEstablishedEpoch",
9368 epoch_tbuf);
9369 }
9370
9371 else if (p->status == Active) {
9372 if (CHECK_FLAG(p->flags, PEER_FLAG_PASSIVE))
9373 json_object_string_add(json_neigh, "bgpStateIs",
9374 "passive");
9375 else if (CHECK_FLAG(p->sflags, PEER_STATUS_NSF_WAIT))
9376 json_object_string_add(json_neigh, "bgpStateIs",
9377 "passiveNSF");
9378 }
9379
9380 /* read timer */
9381 time_t uptime;
9382 struct tm *tm;
9383
9384 uptime = bgp_clock();
9385 uptime -= p->readtime;
9386 tm = gmtime(&uptime);
9387 json_object_int_add(json_neigh, "bgpTimerLastRead",
9388 (tm->tm_sec * 1000) + (tm->tm_min * 60000)
9389 + (tm->tm_hour * 3600000));
9390
9391 uptime = bgp_clock();
9392 uptime -= p->last_write;
9393 tm = gmtime(&uptime);
9394 json_object_int_add(json_neigh, "bgpTimerLastWrite",
9395 (tm->tm_sec * 1000) + (tm->tm_min * 60000)
9396 + (tm->tm_hour * 3600000));
9397
9398 uptime = bgp_clock();
9399 uptime -= p->update_time;
9400 tm = gmtime(&uptime);
9401 json_object_int_add(json_neigh, "bgpInUpdateElapsedTimeMsecs",
9402 (tm->tm_sec * 1000) + (tm->tm_min * 60000)
9403 + (tm->tm_hour * 3600000));
9404
9405 /* Configured timer values. */
9406 json_object_int_add(json_neigh, "bgpTimerHoldTimeMsecs",
9407 p->v_holdtime * 1000);
9408 json_object_int_add(json_neigh,
9409 "bgpTimerKeepAliveIntervalMsecs",
9410 p->v_keepalive * 1000);
9411 if (CHECK_FLAG(p->flags, PEER_FLAG_TIMER)) {
9412 json_object_int_add(json_neigh,
9413 "bgpTimerConfiguredHoldTimeMsecs",
9414 p->holdtime * 1000);
9415 json_object_int_add(
9416 json_neigh,
9417 "bgpTimerConfiguredKeepAliveIntervalMsecs",
9418 p->keepalive * 1000);
9419 } else if ((bgp->default_holdtime != BGP_DEFAULT_HOLDTIME)
9420 || (bgp->default_keepalive
9421 != BGP_DEFAULT_KEEPALIVE)) {
9422 json_object_int_add(json_neigh,
9423 "bgpTimerConfiguredHoldTimeMsecs",
9424 bgp->default_holdtime);
9425 json_object_int_add(
9426 json_neigh,
9427 "bgpTimerConfiguredKeepAliveIntervalMsecs",
9428 bgp->default_keepalive);
9429 }
9430 } else {
9431 /* Administrative shutdown. */
9432 if (CHECK_FLAG(p->flags, PEER_FLAG_SHUTDOWN))
9433 vty_out(vty, " Administratively shut down\n");
9434
9435 /* BGP Version. */
9436 vty_out(vty, " BGP version 4");
9437 vty_out(vty, ", remote router ID %s",
9438 inet_ntop(AF_INET, &p->remote_id, buf1, sizeof(buf1)));
9439 vty_out(vty, ", local router ID %s\n",
9440 inet_ntop(AF_INET, &bgp->router_id, buf1,
9441 sizeof(buf1)));
9442
9443 /* Confederation */
9444 if (CHECK_FLAG(bgp->config, BGP_CONFIG_CONFEDERATION)
9445 && bgp_confederation_peers_check(bgp, p->as))
9446 vty_out(vty,
9447 " Neighbor under common administration\n");
9448
9449 /* Status. */
9450 vty_out(vty, " BGP state = %s",
9451 lookup_msg(bgp_status_msg, p->status, NULL));
9452
9453 if (p->status == Established)
9454 vty_out(vty, ", up for %8s",
9455 peer_uptime(p->uptime, timebuf, BGP_UPTIME_LEN,
9456 0, NULL));
9457
9458 else if (p->status == Active) {
9459 if (CHECK_FLAG(p->flags, PEER_FLAG_PASSIVE))
9460 vty_out(vty, " (passive)");
9461 else if (CHECK_FLAG(p->sflags, PEER_STATUS_NSF_WAIT))
9462 vty_out(vty, " (NSF passive)");
9463 }
9464 vty_out(vty, "\n");
9465
9466 /* read timer */
9467 vty_out(vty, " Last read %s",
9468 peer_uptime(p->readtime, timebuf, BGP_UPTIME_LEN, 0,
9469 NULL));
9470 vty_out(vty, ", Last write %s\n",
9471 peer_uptime(p->last_write, timebuf, BGP_UPTIME_LEN, 0,
9472 NULL));
9473
9474 /* Configured timer values. */
9475 vty_out(vty,
9476 " Hold time is %d, keepalive interval is %d seconds\n",
9477 p->v_holdtime, p->v_keepalive);
9478 if (CHECK_FLAG(p->flags, PEER_FLAG_TIMER)) {
9479 vty_out(vty, " Configured hold time is %d",
9480 p->holdtime);
9481 vty_out(vty, ", keepalive interval is %d seconds\n",
9482 p->keepalive);
9483 } else if ((bgp->default_holdtime != BGP_DEFAULT_HOLDTIME)
9484 || (bgp->default_keepalive
9485 != BGP_DEFAULT_KEEPALIVE)) {
9486 vty_out(vty, " Configured hold time is %d",
9487 bgp->default_holdtime);
9488 vty_out(vty, ", keepalive interval is %d seconds\n",
9489 bgp->default_keepalive);
9490 }
9491 }
9492 /* Capability. */
9493 if (p->status == Established) {
9494 if (p->cap || p->afc_adv[AFI_IP][SAFI_UNICAST]
9495 || p->afc_recv[AFI_IP][SAFI_UNICAST]
9496 || p->afc_adv[AFI_IP][SAFI_MULTICAST]
9497 || p->afc_recv[AFI_IP][SAFI_MULTICAST]
9498 || p->afc_adv[AFI_IP6][SAFI_UNICAST]
9499 || p->afc_recv[AFI_IP6][SAFI_UNICAST]
9500 || p->afc_adv[AFI_IP6][SAFI_MULTICAST]
9501 || p->afc_recv[AFI_IP6][SAFI_MULTICAST]
9502 || p->afc_adv[AFI_IP6][SAFI_MPLS_VPN]
9503 || p->afc_recv[AFI_IP6][SAFI_MPLS_VPN]
9504 || p->afc_adv[AFI_IP6][SAFI_ENCAP]
9505 || p->afc_recv[AFI_IP6][SAFI_ENCAP]
9506 || p->afc_adv[AFI_IP6][SAFI_FLOWSPEC]
9507 || p->afc_recv[AFI_IP6][SAFI_FLOWSPEC]
9508 || p->afc_adv[AFI_IP][SAFI_ENCAP]
9509 || p->afc_recv[AFI_IP][SAFI_ENCAP]
9510 || p->afc_adv[AFI_IP][SAFI_FLOWSPEC]
9511 || p->afc_recv[AFI_IP][SAFI_FLOWSPEC]
9512 || p->afc_adv[AFI_IP][SAFI_MPLS_VPN]
9513 || p->afc_recv[AFI_IP][SAFI_MPLS_VPN]) {
9514 if (use_json) {
9515 json_object *json_cap = NULL;
9516
9517 json_cap = json_object_new_object();
9518
9519 /* AS4 */
9520 if (CHECK_FLAG(p->cap, PEER_CAP_AS4_RCV)
9521 || CHECK_FLAG(p->cap, PEER_CAP_AS4_ADV)) {
9522 if (CHECK_FLAG(p->cap, PEER_CAP_AS4_ADV)
9523 && CHECK_FLAG(p->cap,
9524 PEER_CAP_AS4_RCV))
9525 json_object_string_add(
9526 json_cap, "4byteAs",
9527 "advertisedAndReceived");
9528 else if (CHECK_FLAG(p->cap,
9529 PEER_CAP_AS4_ADV))
9530 json_object_string_add(
9531 json_cap, "4byteAs",
9532 "advertised");
9533 else if (CHECK_FLAG(p->cap,
9534 PEER_CAP_AS4_RCV))
9535 json_object_string_add(
9536 json_cap, "4byteAs",
9537 "received");
9538 }
9539
9540 /* AddPath */
9541 if (CHECK_FLAG(p->cap, PEER_CAP_ADDPATH_RCV)
9542 || CHECK_FLAG(p->cap,
9543 PEER_CAP_ADDPATH_ADV)) {
9544 json_object *json_add = NULL;
9545 const char *print_store;
9546
9547 json_add = json_object_new_object();
9548
9549 FOREACH_AFI_SAFI (afi, safi) {
9550 json_object *json_sub = NULL;
9551 json_sub =
9552 json_object_new_object();
9553 print_store = afi_safi_print(
9554 afi, safi);
9555
9556 if (CHECK_FLAG(
9557 p->af_cap[afi]
9558 [safi],
9559 PEER_CAP_ADDPATH_AF_TX_ADV)
9560 || CHECK_FLAG(
9561 p->af_cap[afi]
9562 [safi],
9563 PEER_CAP_ADDPATH_AF_TX_RCV)) {
9564 if (CHECK_FLAG(
9565 p->af_cap
9566 [afi]
9567 [safi],
9568 PEER_CAP_ADDPATH_AF_TX_ADV)
9569 && CHECK_FLAG(
9570 p->af_cap
9571 [afi]
9572 [safi],
9573 PEER_CAP_ADDPATH_AF_TX_RCV))
9574 json_object_boolean_true_add(
9575 json_sub,
9576 "txAdvertisedAndReceived");
9577 else if (
9578 CHECK_FLAG(
9579 p->af_cap
9580 [afi]
9581 [safi],
9582 PEER_CAP_ADDPATH_AF_TX_ADV))
9583 json_object_boolean_true_add(
9584 json_sub,
9585 "txAdvertised");
9586 else if (
9587 CHECK_FLAG(
9588 p->af_cap
9589 [afi]
9590 [safi],
9591 PEER_CAP_ADDPATH_AF_TX_RCV))
9592 json_object_boolean_true_add(
9593 json_sub,
9594 "txReceived");
9595 }
9596
9597 if (CHECK_FLAG(
9598 p->af_cap[afi]
9599 [safi],
9600 PEER_CAP_ADDPATH_AF_RX_ADV)
9601 || CHECK_FLAG(
9602 p->af_cap[afi]
9603 [safi],
9604 PEER_CAP_ADDPATH_AF_RX_RCV)) {
9605 if (CHECK_FLAG(
9606 p->af_cap
9607 [afi]
9608 [safi],
9609 PEER_CAP_ADDPATH_AF_RX_ADV)
9610 && CHECK_FLAG(
9611 p->af_cap
9612 [afi]
9613 [safi],
9614 PEER_CAP_ADDPATH_AF_RX_RCV))
9615 json_object_boolean_true_add(
9616 json_sub,
9617 "rxAdvertisedAndReceived");
9618 else if (
9619 CHECK_FLAG(
9620 p->af_cap
9621 [afi]
9622 [safi],
9623 PEER_CAP_ADDPATH_AF_RX_ADV))
9624 json_object_boolean_true_add(
9625 json_sub,
9626 "rxAdvertised");
9627 else if (
9628 CHECK_FLAG(
9629 p->af_cap
9630 [afi]
9631 [safi],
9632 PEER_CAP_ADDPATH_AF_RX_RCV))
9633 json_object_boolean_true_add(
9634 json_sub,
9635 "rxReceived");
9636 }
9637
9638 if (CHECK_FLAG(
9639 p->af_cap[afi]
9640 [safi],
9641 PEER_CAP_ADDPATH_AF_TX_ADV)
9642 || CHECK_FLAG(
9643 p->af_cap[afi]
9644 [safi],
9645 PEER_CAP_ADDPATH_AF_TX_RCV)
9646 || CHECK_FLAG(
9647 p->af_cap[afi]
9648 [safi],
9649 PEER_CAP_ADDPATH_AF_RX_ADV)
9650 || CHECK_FLAG(
9651 p->af_cap[afi]
9652 [safi],
9653 PEER_CAP_ADDPATH_AF_RX_RCV))
9654 json_object_object_add(
9655 json_add,
9656 print_store,
9657 json_sub);
9658 else
9659 json_object_free(
9660 json_sub);
9661 }
9662
9663 json_object_object_add(
9664 json_cap, "addPath", json_add);
9665 }
9666
9667 /* Dynamic */
9668 if (CHECK_FLAG(p->cap, PEER_CAP_DYNAMIC_RCV)
9669 || CHECK_FLAG(p->cap,
9670 PEER_CAP_DYNAMIC_ADV)) {
9671 if (CHECK_FLAG(p->cap,
9672 PEER_CAP_DYNAMIC_ADV)
9673 && CHECK_FLAG(p->cap,
9674 PEER_CAP_DYNAMIC_RCV))
9675 json_object_string_add(
9676 json_cap, "dynamic",
9677 "advertisedAndReceived");
9678 else if (CHECK_FLAG(
9679 p->cap,
9680 PEER_CAP_DYNAMIC_ADV))
9681 json_object_string_add(
9682 json_cap, "dynamic",
9683 "advertised");
9684 else if (CHECK_FLAG(
9685 p->cap,
9686 PEER_CAP_DYNAMIC_RCV))
9687 json_object_string_add(
9688 json_cap, "dynamic",
9689 "received");
9690 }
9691
9692 /* Extended nexthop */
9693 if (CHECK_FLAG(p->cap, PEER_CAP_ENHE_RCV)
9694 || CHECK_FLAG(p->cap, PEER_CAP_ENHE_ADV)) {
9695 json_object *json_nxt = NULL;
9696 const char *print_store;
9697
9698
9699 if (CHECK_FLAG(p->cap,
9700 PEER_CAP_ENHE_ADV)
9701 && CHECK_FLAG(p->cap,
9702 PEER_CAP_ENHE_RCV))
9703 json_object_string_add(
9704 json_cap,
9705 "extendedNexthop",
9706 "advertisedAndReceived");
9707 else if (CHECK_FLAG(p->cap,
9708 PEER_CAP_ENHE_ADV))
9709 json_object_string_add(
9710 json_cap,
9711 "extendedNexthop",
9712 "advertised");
9713 else if (CHECK_FLAG(p->cap,
9714 PEER_CAP_ENHE_RCV))
9715 json_object_string_add(
9716 json_cap,
9717 "extendedNexthop",
9718 "received");
9719
9720 if (CHECK_FLAG(p->cap,
9721 PEER_CAP_ENHE_RCV)) {
9722 json_nxt =
9723 json_object_new_object();
9724
9725 for (safi = SAFI_UNICAST;
9726 safi < SAFI_MAX; safi++) {
9727 if (CHECK_FLAG(
9728 p->af_cap
9729 [AFI_IP]
9730 [safi],
9731 PEER_CAP_ENHE_AF_RCV)) {
9732 print_store = afi_safi_print(
9733 AFI_IP,
9734 safi);
9735 json_object_string_add(
9736 json_nxt,
9737 print_store,
9738 "recieved"); /* misspelled for compatibility */
9739 }
9740 }
9741 json_object_object_add(
9742 json_cap,
9743 "extendedNexthopFamililesByPeer",
9744 json_nxt);
9745 }
9746 }
9747
9748 /* Route Refresh */
9749 if (CHECK_FLAG(p->cap, PEER_CAP_REFRESH_ADV)
9750 || CHECK_FLAG(p->cap,
9751 PEER_CAP_REFRESH_NEW_RCV)
9752 || CHECK_FLAG(p->cap,
9753 PEER_CAP_REFRESH_OLD_RCV)) {
9754 if (CHECK_FLAG(p->cap,
9755 PEER_CAP_REFRESH_ADV)
9756 && (CHECK_FLAG(
9757 p->cap,
9758 PEER_CAP_REFRESH_NEW_RCV)
9759 || CHECK_FLAG(
9760 p->cap,
9761 PEER_CAP_REFRESH_OLD_RCV))) {
9762 if (CHECK_FLAG(
9763 p->cap,
9764 PEER_CAP_REFRESH_OLD_RCV)
9765 && CHECK_FLAG(
9766 p->cap,
9767 PEER_CAP_REFRESH_NEW_RCV))
9768 json_object_string_add(
9769 json_cap,
9770 "routeRefresh",
9771 "advertisedAndReceivedOldNew");
9772 else {
9773 if (CHECK_FLAG(
9774 p->cap,
9775 PEER_CAP_REFRESH_OLD_RCV))
9776 json_object_string_add(
9777 json_cap,
9778 "routeRefresh",
9779 "advertisedAndReceivedOld");
9780 else
9781 json_object_string_add(
9782 json_cap,
9783 "routeRefresh",
9784 "advertisedAndReceivedNew");
9785 }
9786 } else if (
9787 CHECK_FLAG(
9788 p->cap,
9789 PEER_CAP_REFRESH_ADV))
9790 json_object_string_add(
9791 json_cap,
9792 "routeRefresh",
9793 "advertised");
9794 else if (
9795 CHECK_FLAG(
9796 p->cap,
9797 PEER_CAP_REFRESH_NEW_RCV)
9798 || CHECK_FLAG(
9799 p->cap,
9800 PEER_CAP_REFRESH_OLD_RCV))
9801 json_object_string_add(
9802 json_cap,
9803 "routeRefresh",
9804 "received");
9805 }
9806
9807 /* Multiprotocol Extensions */
9808 json_object *json_multi = NULL;
9809 json_multi = json_object_new_object();
9810
9811 FOREACH_AFI_SAFI (afi, safi) {
9812 if (p->afc_adv[afi][safi]
9813 || p->afc_recv[afi][safi]) {
9814 json_object *json_exten = NULL;
9815 json_exten =
9816 json_object_new_object();
9817
9818 if (p->afc_adv[afi][safi]
9819 && p->afc_recv[afi][safi])
9820 json_object_boolean_true_add(
9821 json_exten,
9822 "advertisedAndReceived");
9823 else if (p->afc_adv[afi][safi])
9824 json_object_boolean_true_add(
9825 json_exten,
9826 "advertised");
9827 else if (p->afc_recv[afi][safi])
9828 json_object_boolean_true_add(
9829 json_exten,
9830 "received");
9831
9832 json_object_object_add(
9833 json_multi,
9834 afi_safi_print(afi,
9835 safi),
9836 json_exten);
9837 }
9838 }
9839 json_object_object_add(
9840 json_cap, "multiprotocolExtensions",
9841 json_multi);
9842
9843 /* Hostname capabilities */
9844 json_object *json_hname = NULL;
9845
9846 json_hname = json_object_new_object();
9847
9848 if (CHECK_FLAG(p->cap, PEER_CAP_HOSTNAME_ADV)) {
9849 json_object_string_add(
9850 json_hname, "advHostName",
9851 bgp->peer_self->hostname
9852 ? bgp->peer_self
9853 ->hostname
9854 : "n/a");
9855 json_object_string_add(
9856 json_hname, "advDomainName",
9857 bgp->peer_self->domainname
9858 ? bgp->peer_self
9859 ->domainname
9860 : "n/a");
9861 }
9862
9863
9864 if (CHECK_FLAG(p->cap, PEER_CAP_HOSTNAME_RCV)) {
9865 json_object_string_add(
9866 json_hname, "rcvHostName",
9867 p->hostname ? p->hostname
9868 : "n/a");
9869 json_object_string_add(
9870 json_hname, "rcvDomainName",
9871 p->domainname ? p->domainname
9872 : "n/a");
9873 }
9874
9875 json_object_object_add(json_cap, "hostName",
9876 json_hname);
9877
9878 /* Gracefull Restart */
9879 if (CHECK_FLAG(p->cap, PEER_CAP_RESTART_RCV)
9880 || CHECK_FLAG(p->cap,
9881 PEER_CAP_RESTART_ADV)) {
9882 if (CHECK_FLAG(p->cap,
9883 PEER_CAP_RESTART_ADV)
9884 && CHECK_FLAG(p->cap,
9885 PEER_CAP_RESTART_RCV))
9886 json_object_string_add(
9887 json_cap,
9888 "gracefulRestart",
9889 "advertisedAndReceived");
9890 else if (CHECK_FLAG(
9891 p->cap,
9892 PEER_CAP_RESTART_ADV))
9893 json_object_string_add(
9894 json_cap,
9895 "gracefulRestartCapability",
9896 "advertised");
9897 else if (CHECK_FLAG(
9898 p->cap,
9899 PEER_CAP_RESTART_RCV))
9900 json_object_string_add(
9901 json_cap,
9902 "gracefulRestartCapability",
9903 "received");
9904
9905 if (CHECK_FLAG(p->cap,
9906 PEER_CAP_RESTART_RCV)) {
9907 int restart_af_count = 0;
9908 json_object *json_restart =
9909 NULL;
9910 json_restart =
9911 json_object_new_object();
9912
9913 json_object_int_add(
9914 json_cap,
9915 "gracefulRestartRemoteTimerMsecs",
9916 p->v_gr_restart * 1000);
9917
9918 FOREACH_AFI_SAFI (afi, safi) {
9919 if (CHECK_FLAG(
9920 p->af_cap
9921 [afi]
9922 [safi],
9923 PEER_CAP_RESTART_AF_RCV)) {
9924 json_object *
9925 json_sub =
9926 NULL;
9927 json_sub =
9928 json_object_new_object();
9929
9930 if (CHECK_FLAG(
9931 p->af_cap
9932 [afi]
9933 [safi],
9934 PEER_CAP_RESTART_AF_PRESERVE_RCV))
9935 json_object_boolean_true_add(
9936 json_sub,
9937 "preserved");
9938 restart_af_count++;
9939 json_object_object_add(
9940 json_restart,
9941 afi_safi_print(
9942 afi,
9943 safi),
9944 json_sub);
9945 }
9946 }
9947 if (!restart_af_count) {
9948 json_object_string_add(
9949 json_cap,
9950 "addressFamiliesByPeer",
9951 "none");
9952 json_object_free(
9953 json_restart);
9954 } else
9955 json_object_object_add(
9956 json_cap,
9957 "addressFamiliesByPeer",
9958 json_restart);
9959 }
9960 }
9961 json_object_object_add(json_neigh,
9962 "neighborCapabilities",
9963 json_cap);
9964 } else {
9965 vty_out(vty, " Neighbor capabilities:\n");
9966
9967 /* AS4 */
9968 if (CHECK_FLAG(p->cap, PEER_CAP_AS4_RCV)
9969 || CHECK_FLAG(p->cap, PEER_CAP_AS4_ADV)) {
9970 vty_out(vty, " 4 Byte AS:");
9971 if (CHECK_FLAG(p->cap,
9972 PEER_CAP_AS4_ADV))
9973 vty_out(vty, " advertised");
9974 if (CHECK_FLAG(p->cap,
9975 PEER_CAP_AS4_RCV))
9976 vty_out(vty, " %sreceived",
9977 CHECK_FLAG(
9978 p->cap,
9979 PEER_CAP_AS4_ADV)
9980 ? "and "
9981 : "");
9982 vty_out(vty, "\n");
9983 }
9984
9985 /* AddPath */
9986 if (CHECK_FLAG(p->cap, PEER_CAP_ADDPATH_RCV)
9987 || CHECK_FLAG(p->cap,
9988 PEER_CAP_ADDPATH_ADV)) {
9989 vty_out(vty, " AddPath:\n");
9990
9991 FOREACH_AFI_SAFI (afi, safi) {
9992 if (CHECK_FLAG(
9993 p->af_cap[afi]
9994 [safi],
9995 PEER_CAP_ADDPATH_AF_TX_ADV)
9996 || CHECK_FLAG(
9997 p->af_cap[afi]
9998 [safi],
9999 PEER_CAP_ADDPATH_AF_TX_RCV)) {
10000 vty_out(vty,
10001 " %s: TX ",
10002 afi_safi_print(
10003 afi,
10004 safi));
10005
10006 if (CHECK_FLAG(
10007 p->af_cap
10008 [afi]
10009 [safi],
10010 PEER_CAP_ADDPATH_AF_TX_ADV))
10011 vty_out(vty,
10012 "advertised %s",
10013 afi_safi_print(
10014 afi,
10015 safi));
10016
10017 if (CHECK_FLAG(
10018 p->af_cap
10019 [afi]
10020 [safi],
10021 PEER_CAP_ADDPATH_AF_TX_RCV))
10022 vty_out(vty,
10023 "%sreceived",
10024 CHECK_FLAG(
10025 p->af_cap
10026 [afi]
10027 [safi],
10028 PEER_CAP_ADDPATH_AF_TX_ADV)
10029 ? " and "
10030 : "");
10031
10032 vty_out(vty, "\n");
10033 }
10034
10035 if (CHECK_FLAG(
10036 p->af_cap[afi]
10037 [safi],
10038 PEER_CAP_ADDPATH_AF_RX_ADV)
10039 || CHECK_FLAG(
10040 p->af_cap[afi]
10041 [safi],
10042 PEER_CAP_ADDPATH_AF_RX_RCV)) {
10043 vty_out(vty,
10044 " %s: RX ",
10045 afi_safi_print(
10046 afi,
10047 safi));
10048
10049 if (CHECK_FLAG(
10050 p->af_cap
10051 [afi]
10052 [safi],
10053 PEER_CAP_ADDPATH_AF_RX_ADV))
10054 vty_out(vty,
10055 "advertised %s",
10056 afi_safi_print(
10057 afi,
10058 safi));
10059
10060 if (CHECK_FLAG(
10061 p->af_cap
10062 [afi]
10063 [safi],
10064 PEER_CAP_ADDPATH_AF_RX_RCV))
10065 vty_out(vty,
10066 "%sreceived",
10067 CHECK_FLAG(
10068 p->af_cap
10069 [afi]
10070 [safi],
10071 PEER_CAP_ADDPATH_AF_RX_ADV)
10072 ? " and "
10073 : "");
10074
10075 vty_out(vty, "\n");
10076 }
10077 }
10078 }
10079
10080 /* Dynamic */
10081 if (CHECK_FLAG(p->cap, PEER_CAP_DYNAMIC_RCV)
10082 || CHECK_FLAG(p->cap,
10083 PEER_CAP_DYNAMIC_ADV)) {
10084 vty_out(vty, " Dynamic:");
10085 if (CHECK_FLAG(p->cap,
10086 PEER_CAP_DYNAMIC_ADV))
10087 vty_out(vty, " advertised");
10088 if (CHECK_FLAG(p->cap,
10089 PEER_CAP_DYNAMIC_RCV))
10090 vty_out(vty, " %sreceived",
10091 CHECK_FLAG(
10092 p->cap,
10093 PEER_CAP_DYNAMIC_ADV)
10094 ? "and "
10095 : "");
10096 vty_out(vty, "\n");
10097 }
10098
10099 /* Extended nexthop */
10100 if (CHECK_FLAG(p->cap, PEER_CAP_ENHE_RCV)
10101 || CHECK_FLAG(p->cap, PEER_CAP_ENHE_ADV)) {
10102 vty_out(vty, " Extended nexthop:");
10103 if (CHECK_FLAG(p->cap,
10104 PEER_CAP_ENHE_ADV))
10105 vty_out(vty, " advertised");
10106 if (CHECK_FLAG(p->cap,
10107 PEER_CAP_ENHE_RCV))
10108 vty_out(vty, " %sreceived",
10109 CHECK_FLAG(
10110 p->cap,
10111 PEER_CAP_ENHE_ADV)
10112 ? "and "
10113 : "");
10114 vty_out(vty, "\n");
10115
10116 if (CHECK_FLAG(p->cap,
10117 PEER_CAP_ENHE_RCV)) {
10118 vty_out(vty,
10119 " Address families by peer:\n ");
10120 for (safi = SAFI_UNICAST;
10121 safi < SAFI_MAX; safi++)
10122 if (CHECK_FLAG(
10123 p->af_cap
10124 [AFI_IP]
10125 [safi],
10126 PEER_CAP_ENHE_AF_RCV))
10127 vty_out(vty,
10128 " %s\n",
10129 afi_safi_print(
10130 AFI_IP,
10131 safi));
10132 }
10133 }
10134
10135 /* Route Refresh */
10136 if (CHECK_FLAG(p->cap, PEER_CAP_REFRESH_ADV)
10137 || CHECK_FLAG(p->cap,
10138 PEER_CAP_REFRESH_NEW_RCV)
10139 || CHECK_FLAG(p->cap,
10140 PEER_CAP_REFRESH_OLD_RCV)) {
10141 vty_out(vty, " Route refresh:");
10142 if (CHECK_FLAG(p->cap,
10143 PEER_CAP_REFRESH_ADV))
10144 vty_out(vty, " advertised");
10145 if (CHECK_FLAG(p->cap,
10146 PEER_CAP_REFRESH_NEW_RCV)
10147 || CHECK_FLAG(
10148 p->cap,
10149 PEER_CAP_REFRESH_OLD_RCV))
10150 vty_out(vty, " %sreceived(%s)",
10151 CHECK_FLAG(
10152 p->cap,
10153 PEER_CAP_REFRESH_ADV)
10154 ? "and "
10155 : "",
10156 (CHECK_FLAG(
10157 p->cap,
10158 PEER_CAP_REFRESH_OLD_RCV)
10159 && CHECK_FLAG(
10160 p->cap,
10161 PEER_CAP_REFRESH_NEW_RCV))
10162 ? "old & new"
10163 : CHECK_FLAG(
10164 p->cap,
10165 PEER_CAP_REFRESH_OLD_RCV)
10166 ? "old"
10167 : "new");
10168
10169 vty_out(vty, "\n");
10170 }
10171
10172 /* Multiprotocol Extensions */
10173 FOREACH_AFI_SAFI (afi, safi)
10174 if (p->afc_adv[afi][safi]
10175 || p->afc_recv[afi][safi]) {
10176 vty_out(vty,
10177 " Address Family %s:",
10178 afi_safi_print(afi,
10179 safi));
10180 if (p->afc_adv[afi][safi])
10181 vty_out(vty,
10182 " advertised");
10183 if (p->afc_recv[afi][safi])
10184 vty_out(vty,
10185 " %sreceived",
10186 p->afc_adv[afi]
10187 [safi]
10188 ? "and "
10189 : "");
10190 vty_out(vty, "\n");
10191 }
10192
10193 /* Hostname capability */
10194 vty_out(vty, " Hostname Capability:");
10195
10196 if (CHECK_FLAG(p->cap, PEER_CAP_HOSTNAME_ADV)) {
10197 vty_out(vty,
10198 " advertised (name: %s,domain name: %s)",
10199 bgp->peer_self->hostname
10200 ? bgp->peer_self
10201 ->hostname
10202 : "n/a",
10203 bgp->peer_self->domainname
10204 ? bgp->peer_self
10205 ->domainname
10206 : "n/a");
10207 } else {
10208 vty_out(vty, " not advertised");
10209 }
10210
10211 if (CHECK_FLAG(p->cap, PEER_CAP_HOSTNAME_RCV)) {
10212 vty_out(vty,
10213 " received (name: %s,domain name: %s)",
10214 p->hostname ? p->hostname
10215 : "n/a",
10216 p->domainname ? p->domainname
10217 : "n/a");
10218 } else {
10219 vty_out(vty, " not received");
10220 }
10221
10222 vty_out(vty, "\n");
10223
10224 /* Gracefull Restart */
10225 if (CHECK_FLAG(p->cap, PEER_CAP_RESTART_RCV)
10226 || CHECK_FLAG(p->cap,
10227 PEER_CAP_RESTART_ADV)) {
10228 vty_out(vty,
10229 " Graceful Restart Capabilty:");
10230 if (CHECK_FLAG(p->cap,
10231 PEER_CAP_RESTART_ADV))
10232 vty_out(vty, " advertised");
10233 if (CHECK_FLAG(p->cap,
10234 PEER_CAP_RESTART_RCV))
10235 vty_out(vty, " %sreceived",
10236 CHECK_FLAG(
10237 p->cap,
10238 PEER_CAP_RESTART_ADV)
10239 ? "and "
10240 : "");
10241 vty_out(vty, "\n");
10242
10243 if (CHECK_FLAG(p->cap,
10244 PEER_CAP_RESTART_RCV)) {
10245 int restart_af_count = 0;
10246
10247 vty_out(vty,
10248 " Remote Restart timer is %d seconds\n",
10249 p->v_gr_restart);
10250 vty_out(vty,
10251 " Address families by peer:\n ");
10252
10253 FOREACH_AFI_SAFI (afi, safi)
10254 if (CHECK_FLAG(
10255 p->af_cap
10256 [afi]
10257 [safi],
10258 PEER_CAP_RESTART_AF_RCV)) {
10259 vty_out(vty,
10260 "%s%s(%s)",
10261 restart_af_count
10262 ? ", "
10263 : "",
10264 afi_safi_print(
10265 afi,
10266 safi),
10267 CHECK_FLAG(
10268 p->af_cap
10269 [afi]
10270 [safi],
10271 PEER_CAP_RESTART_AF_PRESERVE_RCV)
10272 ? "preserved"
10273 : "not preserved");
10274 restart_af_count++;
10275 }
10276 if (!restart_af_count)
10277 vty_out(vty, "none");
10278 vty_out(vty, "\n");
10279 }
10280 }
10281 }
10282 }
10283 }
10284
10285 /* graceful restart information */
10286 if (CHECK_FLAG(p->cap, PEER_CAP_RESTART_RCV) || p->t_gr_restart
10287 || p->t_gr_stale) {
10288 json_object *json_grace = NULL;
10289 json_object *json_grace_send = NULL;
10290 json_object *json_grace_recv = NULL;
10291 int eor_send_af_count = 0;
10292 int eor_receive_af_count = 0;
10293
10294 if (use_json) {
10295 json_grace = json_object_new_object();
10296 json_grace_send = json_object_new_object();
10297 json_grace_recv = json_object_new_object();
10298
10299 if (p->status == Established) {
10300 FOREACH_AFI_SAFI (afi, safi) {
10301 if (CHECK_FLAG(p->af_sflags[afi][safi],
10302 PEER_STATUS_EOR_SEND)) {
10303 json_object_boolean_true_add(
10304 json_grace_send,
10305 afi_safi_print(afi,
10306 safi));
10307 eor_send_af_count++;
10308 }
10309 }
10310 FOREACH_AFI_SAFI (afi, safi) {
10311 if (CHECK_FLAG(
10312 p->af_sflags[afi][safi],
10313 PEER_STATUS_EOR_RECEIVED)) {
10314 json_object_boolean_true_add(
10315 json_grace_recv,
10316 afi_safi_print(afi,
10317 safi));
10318 eor_receive_af_count++;
10319 }
10320 }
10321 }
10322
10323 json_object_object_add(json_grace, "endOfRibSend",
10324 json_grace_send);
10325 json_object_object_add(json_grace, "endOfRibRecv",
10326 json_grace_recv);
10327
10328 if (p->t_gr_restart)
10329 json_object_int_add(json_grace,
10330 "gracefulRestartTimerMsecs",
10331 thread_timer_remain_second(
10332 p->t_gr_restart)
10333 * 1000);
10334
10335 if (p->t_gr_stale)
10336 json_object_int_add(
10337 json_grace,
10338 "gracefulStalepathTimerMsecs",
10339 thread_timer_remain_second(
10340 p->t_gr_stale)
10341 * 1000);
10342
10343 json_object_object_add(
10344 json_neigh, "gracefulRestartInfo", json_grace);
10345 } else {
10346 vty_out(vty, " Graceful restart information:\n");
10347 if (p->status == Established) {
10348 vty_out(vty, " End-of-RIB send: ");
10349 FOREACH_AFI_SAFI (afi, safi) {
10350 if (CHECK_FLAG(p->af_sflags[afi][safi],
10351 PEER_STATUS_EOR_SEND)) {
10352 vty_out(vty, "%s%s",
10353 eor_send_af_count ? ", "
10354 : "",
10355 afi_safi_print(afi,
10356 safi));
10357 eor_send_af_count++;
10358 }
10359 }
10360 vty_out(vty, "\n");
10361 vty_out(vty, " End-of-RIB received: ");
10362 FOREACH_AFI_SAFI (afi, safi) {
10363 if (CHECK_FLAG(
10364 p->af_sflags[afi][safi],
10365 PEER_STATUS_EOR_RECEIVED)) {
10366 vty_out(vty, "%s%s",
10367 eor_receive_af_count
10368 ? ", "
10369 : "",
10370 afi_safi_print(afi,
10371 safi));
10372 eor_receive_af_count++;
10373 }
10374 }
10375 vty_out(vty, "\n");
10376 }
10377
10378 if (p->t_gr_restart)
10379 vty_out(vty,
10380 " The remaining time of restart timer is %ld\n",
10381 thread_timer_remain_second(
10382 p->t_gr_restart));
10383
10384 if (p->t_gr_stale)
10385 vty_out(vty,
10386 " The remaining time of stalepath timer is %ld\n",
10387 thread_timer_remain_second(
10388 p->t_gr_stale));
10389 }
10390 }
10391 if (use_json) {
10392 json_object *json_stat = NULL;
10393 json_stat = json_object_new_object();
10394 /* Packet counts. */
10395 json_object_int_add(json_stat, "depthInq", 0);
10396 json_object_int_add(json_stat, "depthOutq",
10397 (unsigned long)p->obuf->count);
10398 json_object_int_add(json_stat, "opensSent",
10399 atomic_load_explicit(&p->open_out,
10400 memory_order_relaxed));
10401 json_object_int_add(json_stat, "opensRecv",
10402 atomic_load_explicit(&p->open_in,
10403 memory_order_relaxed));
10404 json_object_int_add(json_stat, "notificationsSent",
10405 atomic_load_explicit(&p->notify_out,
10406 memory_order_relaxed));
10407 json_object_int_add(json_stat, "notificationsRecv",
10408 atomic_load_explicit(&p->notify_in,
10409 memory_order_relaxed));
10410 json_object_int_add(json_stat, "updatesSent",
10411 atomic_load_explicit(&p->update_out,
10412 memory_order_relaxed));
10413 json_object_int_add(json_stat, "updatesRecv",
10414 atomic_load_explicit(&p->update_in,
10415 memory_order_relaxed));
10416 json_object_int_add(json_stat, "keepalivesSent",
10417 atomic_load_explicit(&p->keepalive_out,
10418 memory_order_relaxed));
10419 json_object_int_add(json_stat, "keepalivesRecv",
10420 atomic_load_explicit(&p->keepalive_in,
10421 memory_order_relaxed));
10422 json_object_int_add(json_stat, "routeRefreshSent",
10423 atomic_load_explicit(&p->refresh_out,
10424 memory_order_relaxed));
10425 json_object_int_add(json_stat, "routeRefreshRecv",
10426 atomic_load_explicit(&p->refresh_in,
10427 memory_order_relaxed));
10428 json_object_int_add(json_stat, "capabilitySent",
10429 atomic_load_explicit(&p->dynamic_cap_out,
10430 memory_order_relaxed));
10431 json_object_int_add(json_stat, "capabilityRecv",
10432 atomic_load_explicit(&p->dynamic_cap_in,
10433 memory_order_relaxed));
10434 json_object_int_add(json_stat, "totalSent", PEER_TOTAL_TX(p));
10435 json_object_int_add(json_stat, "totalRecv", PEER_TOTAL_RX(p));
10436 json_object_object_add(json_neigh, "messageStats", json_stat);
10437 } else {
10438 /* Packet counts. */
10439 vty_out(vty, " Message statistics:\n");
10440 vty_out(vty, " Inq depth is 0\n");
10441 vty_out(vty, " Outq depth is %lu\n",
10442 (unsigned long)p->obuf->count);
10443 vty_out(vty, " Sent Rcvd\n");
10444 vty_out(vty, " Opens: %10d %10d\n",
10445 atomic_load_explicit(&p->open_out,
10446 memory_order_relaxed),
10447 atomic_load_explicit(&p->open_in,
10448 memory_order_relaxed));
10449 vty_out(vty, " Notifications: %10d %10d\n",
10450 atomic_load_explicit(&p->notify_out,
10451 memory_order_relaxed),
10452 atomic_load_explicit(&p->notify_in,
10453 memory_order_relaxed));
10454 vty_out(vty, " Updates: %10d %10d\n",
10455 atomic_load_explicit(&p->update_out,
10456 memory_order_relaxed),
10457 atomic_load_explicit(&p->update_in,
10458 memory_order_relaxed));
10459 vty_out(vty, " Keepalives: %10d %10d\n",
10460 atomic_load_explicit(&p->keepalive_out,
10461 memory_order_relaxed),
10462 atomic_load_explicit(&p->keepalive_in,
10463 memory_order_relaxed));
10464 vty_out(vty, " Route Refresh: %10d %10d\n",
10465 atomic_load_explicit(&p->refresh_out,
10466 memory_order_relaxed),
10467 atomic_load_explicit(&p->refresh_in,
10468 memory_order_relaxed));
10469 vty_out(vty, " Capability: %10d %10d\n",
10470 atomic_load_explicit(&p->dynamic_cap_out,
10471 memory_order_relaxed),
10472 atomic_load_explicit(&p->dynamic_cap_in,
10473 memory_order_relaxed));
10474 vty_out(vty, " Total: %10d %10d\n", PEER_TOTAL_TX(p),
10475 PEER_TOTAL_RX(p));
10476 }
10477
10478 if (use_json) {
10479 /* advertisement-interval */
10480 json_object_int_add(json_neigh,
10481 "minBtwnAdvertisementRunsTimerMsecs",
10482 p->v_routeadv * 1000);
10483
10484 /* Update-source. */
10485 if (p->update_if || p->update_source) {
10486 if (p->update_if)
10487 json_object_string_add(json_neigh,
10488 "updateSource",
10489 p->update_if);
10490 else if (p->update_source)
10491 json_object_string_add(
10492 json_neigh, "updateSource",
10493 sockunion2str(p->update_source, buf1,
10494 SU_ADDRSTRLEN));
10495 }
10496 } else {
10497 /* advertisement-interval */
10498 vty_out(vty,
10499 " Minimum time between advertisement runs is %d seconds\n",
10500 p->v_routeadv);
10501
10502 /* Update-source. */
10503 if (p->update_if || p->update_source) {
10504 vty_out(vty, " Update source is ");
10505 if (p->update_if)
10506 vty_out(vty, "%s", p->update_if);
10507 else if (p->update_source)
10508 vty_out(vty, "%s",
10509 sockunion2str(p->update_source, buf1,
10510 SU_ADDRSTRLEN));
10511 vty_out(vty, "\n");
10512 }
10513
10514 vty_out(vty, "\n");
10515 }
10516
10517 /* Address Family Information */
10518 json_object *json_hold = NULL;
10519
10520 if (use_json)
10521 json_hold = json_object_new_object();
10522
10523 FOREACH_AFI_SAFI (afi, safi)
10524 if (p->afc[afi][safi])
10525 bgp_show_peer_afi(vty, p, afi, safi, use_json,
10526 json_hold);
10527
10528 if (use_json) {
10529 json_object_object_add(json_neigh, "addressFamilyInfo",
10530 json_hold);
10531 json_object_int_add(json_neigh, "connectionsEstablished",
10532 p->established);
10533 json_object_int_add(json_neigh, "connectionsDropped",
10534 p->dropped);
10535 } else
10536 vty_out(vty, " Connections established %d; dropped %d\n",
10537 p->established, p->dropped);
10538
10539 if (!p->last_reset) {
10540 if (use_json)
10541 json_object_string_add(json_neigh, "lastReset",
10542 "never");
10543 else
10544 vty_out(vty, " Last reset never\n");
10545 } else {
10546 if (use_json) {
10547 time_t uptime;
10548 struct tm *tm;
10549
10550 uptime = bgp_clock();
10551 uptime -= p->resettime;
10552 tm = gmtime(&uptime);
10553 json_object_int_add(json_neigh, "lastResetTimerMsecs",
10554 (tm->tm_sec * 1000)
10555 + (tm->tm_min * 60000)
10556 + (tm->tm_hour * 3600000));
10557 json_object_string_add(
10558 json_neigh, "lastResetDueTo",
10559 peer_down_str[(int)p->last_reset]);
10560 if (p->last_reset == PEER_DOWN_NOTIFY_SEND
10561 || p->last_reset == PEER_DOWN_NOTIFY_RECEIVED) {
10562 char errorcodesubcode_hexstr[5];
10563 char errorcodesubcode_str[256];
10564
10565 code_str = bgp_notify_code_str(p->notify.code);
10566 subcode_str = bgp_notify_subcode_str(
10567 p->notify.code, p->notify.subcode);
10568
10569 sprintf(errorcodesubcode_hexstr, "%02X%02X",
10570 p->notify.code, p->notify.subcode);
10571 json_object_string_add(json_neigh,
10572 "lastErrorCodeSubcode",
10573 errorcodesubcode_hexstr);
10574 snprintf(errorcodesubcode_str, 255, "%s%s",
10575 code_str, subcode_str);
10576 json_object_string_add(json_neigh,
10577 "lastNotificationReason",
10578 errorcodesubcode_str);
10579 if (p->last_reset == PEER_DOWN_NOTIFY_RECEIVED
10580 && p->notify.code == BGP_NOTIFY_CEASE
10581 && (p->notify.subcode
10582 == BGP_NOTIFY_CEASE_ADMIN_SHUTDOWN
10583 || p->notify.subcode
10584 == BGP_NOTIFY_CEASE_ADMIN_RESET)
10585 && p->notify.length) {
10586 char msgbuf[1024];
10587 const char *msg_str;
10588
10589 msg_str = bgp_notify_admin_message(
10590 msgbuf, sizeof(msgbuf),
10591 (uint8_t *)p->notify.data,
10592 p->notify.length);
10593 if (msg_str)
10594 json_object_string_add(
10595 json_neigh,
10596 "lastShutdownDescription",
10597 msg_str);
10598 }
10599 }
10600 } else {
10601 vty_out(vty, " Last reset %s, ",
10602 peer_uptime(p->resettime, timebuf,
10603 BGP_UPTIME_LEN, 0, NULL));
10604
10605 if (p->last_reset == PEER_DOWN_NOTIFY_SEND
10606 || p->last_reset == PEER_DOWN_NOTIFY_RECEIVED) {
10607 code_str = bgp_notify_code_str(p->notify.code);
10608 subcode_str = bgp_notify_subcode_str(
10609 p->notify.code, p->notify.subcode);
10610 vty_out(vty, "due to NOTIFICATION %s (%s%s)\n",
10611 p->last_reset == PEER_DOWN_NOTIFY_SEND
10612 ? "sent"
10613 : "received",
10614 code_str, subcode_str);
10615 if (p->last_reset == PEER_DOWN_NOTIFY_RECEIVED
10616 && p->notify.code == BGP_NOTIFY_CEASE
10617 && (p->notify.subcode
10618 == BGP_NOTIFY_CEASE_ADMIN_SHUTDOWN
10619 || p->notify.subcode
10620 == BGP_NOTIFY_CEASE_ADMIN_RESET)
10621 && p->notify.length) {
10622 char msgbuf[1024];
10623 const char *msg_str;
10624
10625 msg_str = bgp_notify_admin_message(
10626 msgbuf, sizeof(msgbuf),
10627 (uint8_t *)p->notify.data,
10628 p->notify.length);
10629 if (msg_str)
10630 vty_out(vty,
10631 " Message: \"%s\"\n",
10632 msg_str);
10633 }
10634 } else {
10635 vty_out(vty, "due to %s\n",
10636 peer_down_str[(int)p->last_reset]);
10637 }
10638
10639 if (p->last_reset_cause_size) {
10640 msg = p->last_reset_cause;
10641 vty_out(vty,
10642 " Message received that caused BGP to send a NOTIFICATION:\n ");
10643 for (i = 1; i <= p->last_reset_cause_size;
10644 i++) {
10645 vty_out(vty, "%02X", *msg++);
10646
10647 if (i != p->last_reset_cause_size) {
10648 if (i % 16 == 0) {
10649 vty_out(vty, "\n ");
10650 } else if (i % 4 == 0) {
10651 vty_out(vty, " ");
10652 }
10653 }
10654 }
10655 vty_out(vty, "\n");
10656 }
10657 }
10658 }
10659
10660 if (CHECK_FLAG(p->sflags, PEER_STATUS_PREFIX_OVERFLOW)) {
10661 if (use_json)
10662 json_object_boolean_true_add(json_neigh,
10663 "prefixesConfigExceedMax");
10664 else
10665 vty_out(vty,
10666 " Peer had exceeded the max. no. of prefixes configured.\n");
10667
10668 if (p->t_pmax_restart) {
10669 if (use_json) {
10670 json_object_boolean_true_add(
10671 json_neigh, "reducePrefixNumFrom");
10672 json_object_int_add(json_neigh,
10673 "restartInTimerMsec",
10674 thread_timer_remain_second(
10675 p->t_pmax_restart)
10676 * 1000);
10677 } else
10678 vty_out(vty,
10679 " Reduce the no. of prefix from %s, will restart in %ld seconds\n",
10680 p->host, thread_timer_remain_second(
10681 p->t_pmax_restart));
10682 } else {
10683 if (use_json)
10684 json_object_boolean_true_add(
10685 json_neigh,
10686 "reducePrefixNumAndClearIpBgp");
10687 else
10688 vty_out(vty,
10689 " Reduce the no. of prefix and clear ip bgp %s to restore peering\n",
10690 p->host);
10691 }
10692 }
10693
10694 /* EBGP Multihop and GTSM */
10695 if (p->sort != BGP_PEER_IBGP) {
10696 if (use_json) {
10697 if (p->gtsm_hops > 0)
10698 json_object_int_add(json_neigh,
10699 "externalBgpNbrMaxHopsAway",
10700 p->gtsm_hops);
10701 else if (p->ttl > 1)
10702 json_object_int_add(json_neigh,
10703 "externalBgpNbrMaxHopsAway",
10704 p->ttl);
10705 } else {
10706 if (p->gtsm_hops > 0)
10707 vty_out(vty,
10708 " External BGP neighbor may be up to %d hops away.\n",
10709 p->gtsm_hops);
10710 else if (p->ttl > 1)
10711 vty_out(vty,
10712 " External BGP neighbor may be up to %d hops away.\n",
10713 p->ttl);
10714 }
10715 } else {
10716 if (p->gtsm_hops > 0) {
10717 if (use_json)
10718 json_object_int_add(json_neigh,
10719 "internalBgpNbrMaxHopsAway",
10720 p->gtsm_hops);
10721 else
10722 vty_out(vty,
10723 " Internal BGP neighbor may be up to %d hops away.\n",
10724 p->gtsm_hops);
10725 }
10726 }
10727
10728 /* Local address. */
10729 if (p->su_local) {
10730 if (use_json) {
10731 json_object_string_add(json_neigh, "hostLocal",
10732 sockunion2str(p->su_local, buf1,
10733 SU_ADDRSTRLEN));
10734 json_object_int_add(json_neigh, "portLocal",
10735 ntohs(p->su_local->sin.sin_port));
10736 } else
10737 vty_out(vty, "Local host: %s, Local port: %d\n",
10738 sockunion2str(p->su_local, buf1, SU_ADDRSTRLEN),
10739 ntohs(p->su_local->sin.sin_port));
10740 }
10741
10742 /* Remote address. */
10743 if (p->su_remote) {
10744 if (use_json) {
10745 json_object_string_add(json_neigh, "hostForeign",
10746 sockunion2str(p->su_remote, buf1,
10747 SU_ADDRSTRLEN));
10748 json_object_int_add(json_neigh, "portForeign",
10749 ntohs(p->su_remote->sin.sin_port));
10750 } else
10751 vty_out(vty, "Foreign host: %s, Foreign port: %d\n",
10752 sockunion2str(p->su_remote, buf1,
10753 SU_ADDRSTRLEN),
10754 ntohs(p->su_remote->sin.sin_port));
10755 }
10756
10757 /* Nexthop display. */
10758 if (p->su_local) {
10759 if (use_json) {
10760 json_object_string_add(json_neigh, "nexthop",
10761 inet_ntop(AF_INET,
10762 &p->nexthop.v4, buf1,
10763 sizeof(buf1)));
10764 json_object_string_add(json_neigh, "nexthopGlobal",
10765 inet_ntop(AF_INET6,
10766 &p->nexthop.v6_global,
10767 buf1, sizeof(buf1)));
10768 json_object_string_add(json_neigh, "nexthopLocal",
10769 inet_ntop(AF_INET6,
10770 &p->nexthop.v6_local,
10771 buf1, sizeof(buf1)));
10772 if (p->shared_network)
10773 json_object_string_add(json_neigh,
10774 "bgpConnection",
10775 "sharedNetwork");
10776 else
10777 json_object_string_add(json_neigh,
10778 "bgpConnection",
10779 "nonSharedNetwork");
10780 } else {
10781 vty_out(vty, "Nexthop: %s\n",
10782 inet_ntop(AF_INET, &p->nexthop.v4, buf1,
10783 sizeof(buf1)));
10784 vty_out(vty, "Nexthop global: %s\n",
10785 inet_ntop(AF_INET6, &p->nexthop.v6_global, buf1,
10786 sizeof(buf1)));
10787 vty_out(vty, "Nexthop local: %s\n",
10788 inet_ntop(AF_INET6, &p->nexthop.v6_local, buf1,
10789 sizeof(buf1)));
10790 vty_out(vty, "BGP connection: %s\n",
10791 p->shared_network ? "shared network"
10792 : "non shared network");
10793 }
10794 }
10795
10796 /* Timer information. */
10797 if (use_json) {
10798 json_object_int_add(json_neigh, "connectRetryTimer",
10799 p->v_connect);
10800 if (p->status == Established && p->rtt)
10801 json_object_int_add(json_neigh, "estimatedRttInMsecs",
10802 p->rtt);
10803 if (p->t_start)
10804 json_object_int_add(
10805 json_neigh, "nextStartTimerDueInMsecs",
10806 thread_timer_remain_second(p->t_start) * 1000);
10807 if (p->t_connect)
10808 json_object_int_add(
10809 json_neigh, "nextConnectTimerDueInMsecs",
10810 thread_timer_remain_second(p->t_connect)
10811 * 1000);
10812 if (p->t_routeadv) {
10813 json_object_int_add(json_neigh, "mraiInterval",
10814 p->v_routeadv);
10815 json_object_int_add(
10816 json_neigh, "mraiTimerExpireInMsecs",
10817 thread_timer_remain_second(p->t_routeadv)
10818 * 1000);
10819 }
10820 if (p->password)
10821 json_object_int_add(json_neigh, "authenticationEnabled",
10822 1);
10823
10824 if (p->t_read)
10825 json_object_string_add(json_neigh, "readThread", "on");
10826 else
10827 json_object_string_add(json_neigh, "readThread", "off");
10828
10829 if (CHECK_FLAG(p->thread_flags, PEER_THREAD_WRITES_ON))
10830 json_object_string_add(json_neigh, "writeThread", "on");
10831 else
10832 json_object_string_add(json_neigh, "writeThread",
10833 "off");
10834 } else {
10835 vty_out(vty, "BGP Connect Retry Timer in Seconds: %d\n",
10836 p->v_connect);
10837 if (p->status == Established && p->rtt)
10838 vty_out(vty, "Estimated round trip time: %d ms\n",
10839 p->rtt);
10840 if (p->t_start)
10841 vty_out(vty, "Next start timer due in %ld seconds\n",
10842 thread_timer_remain_second(p->t_start));
10843 if (p->t_connect)
10844 vty_out(vty, "Next connect timer due in %ld seconds\n",
10845 thread_timer_remain_second(p->t_connect));
10846 if (p->t_routeadv)
10847 vty_out(vty,
10848 "MRAI (interval %u) timer expires in %ld seconds\n",
10849 p->v_routeadv,
10850 thread_timer_remain_second(p->t_routeadv));
10851 if (p->password)
10852 vty_out(vty, "Peer Authentication Enabled\n");
10853
10854 vty_out(vty, "Read thread: %s Write thread: %s FD used: %d\n",
10855 p->t_read ? "on" : "off",
10856 CHECK_FLAG(p->thread_flags, PEER_THREAD_WRITES_ON)
10857 ? "on"
10858 : "off", p->fd);
10859 }
10860
10861 if (p->notify.code == BGP_NOTIFY_OPEN_ERR
10862 && p->notify.subcode == BGP_NOTIFY_OPEN_UNSUP_CAPBL)
10863 bgp_capability_vty_out(vty, p, use_json, json_neigh);
10864
10865 if (!use_json)
10866 vty_out(vty, "\n");
10867
10868 /* BFD information. */
10869 bgp_bfd_show_info(vty, p, use_json, json_neigh);
10870
10871 if (use_json) {
10872 if (p->conf_if) /* Configured interface name. */
10873 json_object_object_add(json, p->conf_if, json_neigh);
10874 else /* Configured IP address. */
10875 json_object_object_add(json, p->host, json_neigh);
10876 }
10877 }
10878
10879 static int bgp_show_neighbor(struct vty *vty, struct bgp *bgp,
10880 enum show_type type, union sockunion *su,
10881 const char *conf_if, bool use_json,
10882 json_object *json)
10883 {
10884 struct listnode *node, *nnode;
10885 struct peer *peer;
10886 int find = 0;
10887 bool nbr_output = false;
10888 afi_t afi = AFI_MAX;
10889 safi_t safi = SAFI_MAX;
10890
10891 if (type == show_ipv4_peer || type == show_ipv4_all) {
10892 afi = AFI_IP;
10893 } else if (type == show_ipv6_peer || type == show_ipv6_all) {
10894 afi = AFI_IP6;
10895 }
10896
10897 for (ALL_LIST_ELEMENTS(bgp->peer, node, nnode, peer)) {
10898 if (!CHECK_FLAG(peer->flags, PEER_FLAG_CONFIG_NODE))
10899 continue;
10900
10901 switch (type) {
10902 case show_all:
10903 bgp_show_peer(vty, peer, use_json, json);
10904 nbr_output = true;
10905 break;
10906 case show_peer:
10907 if (conf_if) {
10908 if ((peer->conf_if
10909 && !strcmp(peer->conf_if, conf_if))
10910 || (peer->hostname
10911 && !strcmp(peer->hostname, conf_if))) {
10912 find = 1;
10913 bgp_show_peer(vty, peer, use_json,
10914 json);
10915 }
10916 } else {
10917 if (sockunion_same(&peer->su, su)) {
10918 find = 1;
10919 bgp_show_peer(vty, peer, use_json,
10920 json);
10921 }
10922 }
10923 break;
10924 case show_ipv4_peer:
10925 case show_ipv6_peer:
10926 FOREACH_SAFI (safi) {
10927 if (peer->afc[afi][safi]) {
10928 if (conf_if) {
10929 if ((peer->conf_if
10930 && !strcmp(peer->conf_if, conf_if))
10931 || (peer->hostname
10932 && !strcmp(peer->hostname, conf_if))) {
10933 find = 1;
10934 bgp_show_peer(vty, peer, use_json,
10935 json);
10936 break;
10937 }
10938 } else {
10939 if (sockunion_same(&peer->su, su)) {
10940 find = 1;
10941 bgp_show_peer(vty, peer, use_json,
10942 json);
10943 break;
10944 }
10945 }
10946 }
10947 }
10948 break;
10949 case show_ipv4_all:
10950 case show_ipv6_all:
10951 FOREACH_SAFI (safi) {
10952 if (peer->afc[afi][safi]) {
10953 bgp_show_peer(vty, peer, use_json, json);
10954 nbr_output = true;
10955 break;
10956 }
10957 }
10958 break;
10959 }
10960 }
10961
10962 if ((type == show_peer || type == show_ipv4_peer ||
10963 type == show_ipv6_peer) && !find) {
10964 if (use_json)
10965 json_object_boolean_true_add(json, "bgpNoSuchNeighbor");
10966 else
10967 vty_out(vty, "%% No such neighbor in this view/vrf\n");
10968 }
10969
10970 if (type != show_peer && type != show_ipv4_peer &&
10971 type != show_ipv6_peer && !nbr_output && !use_json)
10972 vty_out(vty, "%% No BGP neighbors found\n");
10973
10974 if (use_json) {
10975 vty_out(vty, "%s\n", json_object_to_json_string_ext(
10976 json, JSON_C_TO_STRING_PRETTY));
10977 } else {
10978 vty_out(vty, "\n");
10979 }
10980
10981 return CMD_SUCCESS;
10982 }
10983
10984 static void bgp_show_all_instances_neighbors_vty(struct vty *vty,
10985 enum show_type type,
10986 const char *ip_str,
10987 bool use_json)
10988 {
10989 struct listnode *node, *nnode;
10990 struct bgp *bgp;
10991 union sockunion su;
10992 json_object *json = NULL;
10993 int ret, is_first = 1;
10994 bool nbr_output = false;
10995
10996 if (use_json)
10997 vty_out(vty, "{\n");
10998
10999 for (ALL_LIST_ELEMENTS(bm->bgp, node, nnode, bgp)) {
11000 nbr_output = true;
11001 if (use_json) {
11002 if (!(json = json_object_new_object())) {
11003 flog_err(
11004 EC_BGP_JSON_MEM_ERROR,
11005 "Unable to allocate memory for JSON object");
11006 vty_out(vty,
11007 "{\"error\": {\"message:\": \"Unable to allocate memory for JSON object\"}}}\n");
11008 return;
11009 }
11010
11011 json_object_int_add(json, "vrfId",
11012 (bgp->vrf_id == VRF_UNKNOWN)
11013 ? -1
11014 : (int64_t)bgp->vrf_id);
11015 json_object_string_add(
11016 json, "vrfName",
11017 (bgp->inst_type == BGP_INSTANCE_TYPE_DEFAULT)
11018 ? VRF_DEFAULT_NAME
11019 : bgp->name);
11020
11021 if (!is_first)
11022 vty_out(vty, ",\n");
11023 else
11024 is_first = 0;
11025
11026 vty_out(vty, "\"%s\":",
11027 (bgp->inst_type == BGP_INSTANCE_TYPE_DEFAULT)
11028 ? VRF_DEFAULT_NAME
11029 : bgp->name);
11030 } else {
11031 vty_out(vty, "\nInstance %s:\n",
11032 (bgp->inst_type == BGP_INSTANCE_TYPE_DEFAULT)
11033 ? VRF_DEFAULT_NAME
11034 : bgp->name);
11035 }
11036
11037 if (type == show_peer || type == show_ipv4_peer ||
11038 type == show_ipv6_peer) {
11039 ret = str2sockunion(ip_str, &su);
11040 if (ret < 0)
11041 bgp_show_neighbor(vty, bgp, type, NULL, ip_str,
11042 use_json, json);
11043 else
11044 bgp_show_neighbor(vty, bgp, type, &su, NULL,
11045 use_json, json);
11046 } else {
11047 bgp_show_neighbor(vty, bgp, type, NULL, NULL,
11048 use_json, json);
11049 }
11050 json_object_free(json);
11051 }
11052
11053 if (use_json) {
11054 vty_out(vty, "}\n");
11055 json_object_free(json);
11056 }
11057 else if (!nbr_output)
11058 vty_out(vty, "%% BGP instance not found\n");
11059 }
11060
11061 static int bgp_show_neighbor_vty(struct vty *vty, const char *name,
11062 enum show_type type, const char *ip_str,
11063 bool use_json)
11064 {
11065 int ret;
11066 struct bgp *bgp;
11067 union sockunion su;
11068 json_object *json = NULL;
11069
11070 if (name) {
11071 if (strmatch(name, "all")) {
11072 bgp_show_all_instances_neighbors_vty(vty, type, ip_str,
11073 use_json);
11074 return CMD_SUCCESS;
11075 } else {
11076 bgp = bgp_lookup_by_name(name);
11077 if (!bgp) {
11078 if (use_json) {
11079 json = json_object_new_object();
11080 vty_out(vty, "%s\n",
11081 json_object_to_json_string_ext(
11082 json,
11083 JSON_C_TO_STRING_PRETTY));
11084 json_object_free(json);
11085 } else
11086 vty_out(vty,
11087 "%% BGP instance not found\n");
11088
11089 return CMD_WARNING;
11090 }
11091 }
11092 } else {
11093 bgp = bgp_get_default();
11094 }
11095
11096 if (bgp) {
11097 json = json_object_new_object();
11098 if (ip_str) {
11099 ret = str2sockunion(ip_str, &su);
11100 if (ret < 0)
11101 bgp_show_neighbor(vty, bgp, type, NULL, ip_str,
11102 use_json, json);
11103 else
11104 bgp_show_neighbor(vty, bgp, type, &su, NULL,
11105 use_json, json);
11106 } else {
11107 bgp_show_neighbor(vty, bgp, type, NULL, NULL, use_json,
11108 json);
11109 }
11110 json_object_free(json);
11111 } else {
11112 if (use_json)
11113 vty_out(vty, "{}\n");
11114 else
11115 vty_out(vty, "%% BGP instance not found\n");
11116 }
11117
11118 return CMD_SUCCESS;
11119 }
11120
11121 /* "show [ip] bgp neighbors" commands. */
11122 DEFUN (show_ip_bgp_neighbors,
11123 show_ip_bgp_neighbors_cmd,
11124 "show [ip] bgp [<view|vrf> VIEWVRFNAME] [<ipv4|ipv6>] neighbors [<A.B.C.D|X:X::X:X|WORD>] [json]",
11125 SHOW_STR
11126 IP_STR
11127 BGP_STR
11128 BGP_INSTANCE_HELP_STR
11129 "Address Family\n"
11130 "Address Family\n"
11131 "Detailed information on TCP and BGP neighbor connections\n"
11132 "Neighbor to display information about\n"
11133 "Neighbor to display information about\n"
11134 "Neighbor on BGP configured interface\n"
11135 JSON_STR)
11136 {
11137 char *vrf = NULL;
11138 char *sh_arg = NULL;
11139 enum show_type sh_type;
11140 afi_t afi = AFI_MAX;
11141
11142 bool uj = use_json(argc, argv);
11143
11144 int idx = 0;
11145
11146 /* [<vrf> VIEWVRFNAME] */
11147 if (argv_find(argv, argc, "vrf", &idx)) {
11148 vrf = argv[idx + 1]->arg;
11149 if (vrf && strmatch(vrf, VRF_DEFAULT_NAME))
11150 vrf = NULL;
11151 } else if (argv_find(argv, argc, "view", &idx))
11152 /* [<view> VIEWVRFNAME] */
11153 vrf = argv[idx + 1]->arg;
11154
11155 idx++;
11156
11157 if (argv_find(argv, argc, "ipv4", &idx)) {
11158 sh_type = show_ipv4_all;
11159 afi = AFI_IP;
11160 } else if (argv_find(argv, argc, "ipv6", &idx)) {
11161 sh_type = show_ipv6_all;
11162 afi = AFI_IP6;
11163 } else {
11164 sh_type = show_all;
11165 }
11166
11167 if (argv_find(argv, argc, "A.B.C.D", &idx)
11168 || argv_find(argv, argc, "X:X::X:X", &idx)
11169 || argv_find(argv, argc, "WORD", &idx)) {
11170 sh_type = show_peer;
11171 sh_arg = argv[idx]->arg;
11172 }
11173
11174 if (sh_type == show_peer && afi == AFI_IP) {
11175 sh_type = show_ipv4_peer;
11176 } else if (sh_type == show_peer && afi == AFI_IP6) {
11177 sh_type = show_ipv6_peer;
11178 }
11179
11180 return bgp_show_neighbor_vty(vty, vrf, sh_type, sh_arg, uj);
11181 }
11182
11183 /* Show BGP's AS paths internal data. There are both `show [ip] bgp
11184 paths' and `show ip mbgp paths'. Those functions results are the
11185 same.*/
11186 DEFUN (show_ip_bgp_paths,
11187 show_ip_bgp_paths_cmd,
11188 "show [ip] bgp ["BGP_SAFI_CMD_STR"] paths",
11189 SHOW_STR
11190 IP_STR
11191 BGP_STR
11192 BGP_SAFI_HELP_STR
11193 "Path information\n")
11194 {
11195 vty_out(vty, "Address Refcnt Path\n");
11196 aspath_print_all_vty(vty);
11197 return CMD_SUCCESS;
11198 }
11199
11200 #include "hash.h"
11201
11202 static void community_show_all_iterator(struct hash_bucket *bucket,
11203 struct vty *vty)
11204 {
11205 struct community *com;
11206
11207 com = (struct community *)bucket->data;
11208 vty_out(vty, "[%p] (%ld) %s\n", (void *)com, com->refcnt,
11209 community_str(com, false));
11210 }
11211
11212 /* Show BGP's community internal data. */
11213 DEFUN (show_ip_bgp_community_info,
11214 show_ip_bgp_community_info_cmd,
11215 "show [ip] bgp community-info",
11216 SHOW_STR
11217 IP_STR
11218 BGP_STR
11219 "List all bgp community information\n")
11220 {
11221 vty_out(vty, "Address Refcnt Community\n");
11222
11223 hash_iterate(community_hash(),
11224 (void (*)(struct hash_bucket *,
11225 void *))community_show_all_iterator,
11226 vty);
11227
11228 return CMD_SUCCESS;
11229 }
11230
11231 static void lcommunity_show_all_iterator(struct hash_bucket *bucket,
11232 struct vty *vty)
11233 {
11234 struct lcommunity *lcom;
11235
11236 lcom = (struct lcommunity *)bucket->data;
11237 vty_out(vty, "[%p] (%ld) %s\n", (void *)lcom, lcom->refcnt,
11238 lcommunity_str(lcom, false));
11239 }
11240
11241 /* Show BGP's community internal data. */
11242 DEFUN (show_ip_bgp_lcommunity_info,
11243 show_ip_bgp_lcommunity_info_cmd,
11244 "show ip bgp large-community-info",
11245 SHOW_STR
11246 IP_STR
11247 BGP_STR
11248 "List all bgp large-community information\n")
11249 {
11250 vty_out(vty, "Address Refcnt Large-community\n");
11251
11252 hash_iterate(lcommunity_hash(),
11253 (void (*)(struct hash_bucket *,
11254 void *))lcommunity_show_all_iterator,
11255 vty);
11256
11257 return CMD_SUCCESS;
11258 }
11259
11260
11261 DEFUN (show_ip_bgp_attr_info,
11262 show_ip_bgp_attr_info_cmd,
11263 "show [ip] bgp attribute-info",
11264 SHOW_STR
11265 IP_STR
11266 BGP_STR
11267 "List all bgp attribute information\n")
11268 {
11269 attr_show_all(vty);
11270 return CMD_SUCCESS;
11271 }
11272
11273 static int bgp_show_route_leak_vty(struct vty *vty, const char *name,
11274 afi_t afi, safi_t safi,
11275 bool use_json, json_object *json)
11276 {
11277 struct bgp *bgp;
11278 struct listnode *node;
11279 char *vname;
11280 char buf1[INET6_ADDRSTRLEN];
11281 char *ecom_str;
11282 vpn_policy_direction_t dir;
11283
11284 if (json) {
11285 json_object *json_import_vrfs = NULL;
11286 json_object *json_export_vrfs = NULL;
11287
11288 bgp = name ? bgp_lookup_by_name(name) : bgp_get_default();
11289
11290 if (!bgp) {
11291 vty_out(vty, "%s\n",
11292 json_object_to_json_string_ext(
11293 json,
11294 JSON_C_TO_STRING_PRETTY));
11295 json_object_free(json);
11296
11297 return CMD_WARNING;
11298 }
11299
11300 /* Provide context for the block */
11301 json_object_string_add(json, "vrf", name ? name : "default");
11302 json_object_string_add(json, "afiSafi",
11303 afi_safi_print(afi, safi));
11304
11305 if (!CHECK_FLAG(bgp->af_flags[afi][safi],
11306 BGP_CONFIG_VRF_TO_VRF_IMPORT)) {
11307 json_object_string_add(json, "importFromVrfs", "none");
11308 json_object_string_add(json, "importRts", "none");
11309 } else {
11310 json_import_vrfs = json_object_new_array();
11311
11312 for (ALL_LIST_ELEMENTS_RO(
11313 bgp->vpn_policy[afi].import_vrf,
11314 node, vname))
11315 json_object_array_add(json_import_vrfs,
11316 json_object_new_string(vname));
11317
11318 json_object_object_add(json, "importFromVrfs",
11319 json_import_vrfs);
11320 dir = BGP_VPN_POLICY_DIR_FROMVPN;
11321 if (bgp->vpn_policy[afi].rtlist[dir]) {
11322 ecom_str = ecommunity_ecom2str(
11323 bgp->vpn_policy[afi].rtlist[dir],
11324 ECOMMUNITY_FORMAT_ROUTE_MAP, 0);
11325 json_object_string_add(json, "importRts",
11326 ecom_str);
11327 XFREE(MTYPE_ECOMMUNITY_STR, ecom_str);
11328 } else
11329 json_object_string_add(json, "importRts",
11330 "none");
11331 }
11332
11333 if (!CHECK_FLAG(bgp->af_flags[afi][safi],
11334 BGP_CONFIG_VRF_TO_VRF_EXPORT)) {
11335 json_object_string_add(json, "exportToVrfs", "none");
11336 json_object_string_add(json, "routeDistinguisher",
11337 "none");
11338 json_object_string_add(json, "exportRts", "none");
11339 } else {
11340 json_export_vrfs = json_object_new_array();
11341
11342 for (ALL_LIST_ELEMENTS_RO(
11343 bgp->vpn_policy[afi].export_vrf,
11344 node, vname))
11345 json_object_array_add(json_export_vrfs,
11346 json_object_new_string(vname));
11347 json_object_object_add(json, "exportToVrfs",
11348 json_export_vrfs);
11349 json_object_string_add(json, "routeDistinguisher",
11350 prefix_rd2str(&bgp->vpn_policy[afi].tovpn_rd,
11351 buf1, RD_ADDRSTRLEN));
11352
11353 dir = BGP_VPN_POLICY_DIR_TOVPN;
11354 if (bgp->vpn_policy[afi].rtlist[dir]) {
11355 ecom_str = ecommunity_ecom2str(
11356 bgp->vpn_policy[afi].rtlist[dir],
11357 ECOMMUNITY_FORMAT_ROUTE_MAP, 0);
11358 json_object_string_add(json, "exportRts",
11359 ecom_str);
11360 XFREE(MTYPE_ECOMMUNITY_STR, ecom_str);
11361 } else
11362 json_object_string_add(json, "exportRts",
11363 "none");
11364 }
11365
11366 if (use_json) {
11367 vty_out(vty, "%s\n",
11368 json_object_to_json_string_ext(json,
11369 JSON_C_TO_STRING_PRETTY));
11370 json_object_free(json);
11371 }
11372 } else {
11373 bgp = name ? bgp_lookup_by_name(name) : bgp_get_default();
11374
11375 if (!bgp) {
11376 vty_out(vty, "%% No such BGP instance exist\n");
11377 return CMD_WARNING;
11378 }
11379
11380 if (!CHECK_FLAG(bgp->af_flags[afi][safi],
11381 BGP_CONFIG_VRF_TO_VRF_IMPORT))
11382 vty_out(vty,
11383 "This VRF is not importing %s routes from any other VRF\n",
11384 afi_safi_print(afi, safi));
11385 else {
11386 vty_out(vty,
11387 "This VRF is importing %s routes from the following VRFs:\n",
11388 afi_safi_print(afi, safi));
11389
11390 for (ALL_LIST_ELEMENTS_RO(
11391 bgp->vpn_policy[afi].import_vrf,
11392 node, vname))
11393 vty_out(vty, " %s\n", vname);
11394
11395 dir = BGP_VPN_POLICY_DIR_FROMVPN;
11396 ecom_str = NULL;
11397 if (bgp->vpn_policy[afi].rtlist[dir]) {
11398 ecom_str = ecommunity_ecom2str(
11399 bgp->vpn_policy[afi].rtlist[dir],
11400 ECOMMUNITY_FORMAT_ROUTE_MAP, 0);
11401 vty_out(vty, "Import RT(s): %s\n", ecom_str);
11402
11403 XFREE(MTYPE_ECOMMUNITY_STR, ecom_str);
11404 } else
11405 vty_out(vty, "Import RT(s):\n");
11406 }
11407
11408 if (!CHECK_FLAG(bgp->af_flags[afi][safi],
11409 BGP_CONFIG_VRF_TO_VRF_EXPORT))
11410 vty_out(vty,
11411 "This VRF is not exporting %s routes to any other VRF\n",
11412 afi_safi_print(afi, safi));
11413 else {
11414 vty_out(vty,
11415 "This VRF is exporting %s routes to the following VRFs:\n",
11416 afi_safi_print(afi, safi));
11417
11418 for (ALL_LIST_ELEMENTS_RO(
11419 bgp->vpn_policy[afi].export_vrf,
11420 node, vname))
11421 vty_out(vty, " %s\n", vname);
11422
11423 vty_out(vty, "RD: %s\n",
11424 prefix_rd2str(&bgp->vpn_policy[afi].tovpn_rd,
11425 buf1, RD_ADDRSTRLEN));
11426
11427 dir = BGP_VPN_POLICY_DIR_TOVPN;
11428 if (bgp->vpn_policy[afi].rtlist[dir]) {
11429 ecom_str = ecommunity_ecom2str(
11430 bgp->vpn_policy[afi].rtlist[dir],
11431 ECOMMUNITY_FORMAT_ROUTE_MAP, 0);
11432 vty_out(vty, "Export RT: %s\n", ecom_str);
11433 XFREE(MTYPE_ECOMMUNITY_STR, ecom_str);
11434 } else
11435 vty_out(vty, "Import RT(s):\n");
11436 }
11437 }
11438
11439 return CMD_SUCCESS;
11440 }
11441
11442 static int bgp_show_all_instance_route_leak_vty(struct vty *vty, afi_t afi,
11443 safi_t safi, bool use_json)
11444 {
11445 struct listnode *node, *nnode;
11446 struct bgp *bgp;
11447 char *vrf_name = NULL;
11448 json_object *json = NULL;
11449 json_object *json_vrf = NULL;
11450 json_object *json_vrfs = NULL;
11451
11452 if (use_json) {
11453 json = json_object_new_object();
11454 json_vrfs = json_object_new_object();
11455 }
11456
11457 for (ALL_LIST_ELEMENTS(bm->bgp, node, nnode, bgp)) {
11458
11459 if (bgp->inst_type != BGP_INSTANCE_TYPE_DEFAULT)
11460 vrf_name = bgp->name;
11461
11462 if (use_json) {
11463 json_vrf = json_object_new_object();
11464 } else {
11465 vty_out(vty, "\nInstance %s:\n",
11466 (bgp->inst_type == BGP_INSTANCE_TYPE_DEFAULT)
11467 ? VRF_DEFAULT_NAME : bgp->name);
11468 }
11469 bgp_show_route_leak_vty(vty, vrf_name, afi, safi, 0, json_vrf);
11470 if (use_json) {
11471 if (bgp->inst_type == BGP_INSTANCE_TYPE_DEFAULT)
11472 json_object_object_add(json_vrfs,
11473 VRF_DEFAULT_NAME, json_vrf);
11474 else
11475 json_object_object_add(json_vrfs, vrf_name,
11476 json_vrf);
11477 }
11478 }
11479
11480 if (use_json) {
11481 json_object_object_add(json, "vrfs", json_vrfs);
11482 vty_out(vty, "%s\n", json_object_to_json_string_ext(json,
11483 JSON_C_TO_STRING_PRETTY));
11484 json_object_free(json);
11485 }
11486
11487 return CMD_SUCCESS;
11488 }
11489
11490 /* "show [ip] bgp route-leak" command. */
11491 DEFUN (show_ip_bgp_route_leak,
11492 show_ip_bgp_route_leak_cmd,
11493 "show [ip] bgp [<view|vrf> VIEWVRFNAME] ["BGP_AFI_CMD_STR" ["BGP_SAFI_CMD_STR"]] route-leak [json]",
11494 SHOW_STR
11495 IP_STR
11496 BGP_STR
11497 BGP_INSTANCE_HELP_STR
11498 BGP_AFI_HELP_STR
11499 BGP_SAFI_HELP_STR
11500 "Route leaking information\n"
11501 JSON_STR)
11502 {
11503 char *vrf = NULL;
11504 afi_t afi = AFI_MAX;
11505 safi_t safi = SAFI_MAX;
11506
11507 bool uj = use_json(argc, argv);
11508 int idx = 0;
11509 json_object *json = NULL;
11510
11511 /* show [ip] bgp */
11512 if (argv_find(argv, argc, "ip", &idx)) {
11513 afi = AFI_IP;
11514 safi = SAFI_UNICAST;
11515 }
11516 /* [vrf VIEWVRFNAME] */
11517 if (argv_find(argv, argc, "view", &idx)) {
11518 vty_out(vty,
11519 "%% This command is not applicable to BGP views\n");
11520 return CMD_WARNING;
11521 }
11522
11523 if (argv_find(argv, argc, "vrf", &idx)) {
11524 vrf = argv[idx + 1]->arg;
11525 if (vrf && strmatch(vrf, VRF_DEFAULT_NAME))
11526 vrf = NULL;
11527 }
11528 /* ["BGP_AFI_CMD_STR" ["BGP_SAFI_CMD_STR"]] */
11529 if (argv_find_and_parse_afi(argv, argc, &idx, &afi)) {
11530 argv_find_and_parse_safi(argv, argc, &idx, &safi);
11531 }
11532
11533 if (!((afi == AFI_IP || afi == AFI_IP6) && safi == SAFI_UNICAST)) {
11534 vty_out(vty,
11535 "%% This command is applicable only for unicast ipv4|ipv6\n");
11536 return CMD_WARNING;
11537 }
11538
11539 if (vrf && strmatch(vrf, "all"))
11540 return bgp_show_all_instance_route_leak_vty(vty, afi, safi, uj);
11541
11542 if (uj)
11543 json = json_object_new_object();
11544
11545 return bgp_show_route_leak_vty(vty, vrf, afi, safi, uj, json);
11546 }
11547
11548 static void bgp_show_all_instances_updgrps_vty(struct vty *vty, afi_t afi,
11549 safi_t safi)
11550 {
11551 struct listnode *node, *nnode;
11552 struct bgp *bgp;
11553
11554 for (ALL_LIST_ELEMENTS(bm->bgp, node, nnode, bgp)) {
11555 vty_out(vty, "\nInstance %s:\n",
11556 (bgp->inst_type == BGP_INSTANCE_TYPE_DEFAULT)
11557 ? VRF_DEFAULT_NAME
11558 : bgp->name);
11559 update_group_show(bgp, afi, safi, vty, 0);
11560 }
11561 }
11562
11563 static int bgp_show_update_groups(struct vty *vty, const char *name, int afi,
11564 int safi, uint64_t subgrp_id)
11565 {
11566 struct bgp *bgp;
11567
11568 if (name) {
11569 if (strmatch(name, "all")) {
11570 bgp_show_all_instances_updgrps_vty(vty, afi, safi);
11571 return CMD_SUCCESS;
11572 } else {
11573 bgp = bgp_lookup_by_name(name);
11574 }
11575 } else {
11576 bgp = bgp_get_default();
11577 }
11578
11579 if (bgp)
11580 update_group_show(bgp, afi, safi, vty, subgrp_id);
11581 return CMD_SUCCESS;
11582 }
11583
11584 DEFUN (show_ip_bgp_updgrps,
11585 show_ip_bgp_updgrps_cmd,
11586 "show [ip] bgp [<view|vrf> VIEWVRFNAME] ["BGP_AFI_CMD_STR" ["BGP_SAFI_WITH_LABEL_CMD_STR"]] update-groups [SUBGROUP-ID]",
11587 SHOW_STR
11588 IP_STR
11589 BGP_STR
11590 BGP_INSTANCE_HELP_STR
11591 BGP_AFI_HELP_STR
11592 BGP_SAFI_WITH_LABEL_HELP_STR
11593 "Detailed info about dynamic update groups\n"
11594 "Specific subgroup to display detailed info for\n")
11595 {
11596 char *vrf = NULL;
11597 afi_t afi = AFI_IP6;
11598 safi_t safi = SAFI_UNICAST;
11599 uint64_t subgrp_id = 0;
11600
11601 int idx = 0;
11602
11603 /* show [ip] bgp */
11604 if (argv_find(argv, argc, "ip", &idx))
11605 afi = AFI_IP;
11606 /* [<vrf> VIEWVRFNAME] */
11607 if (argv_find(argv, argc, "vrf", &idx)) {
11608 vrf = argv[idx + 1]->arg;
11609 if (vrf && strmatch(vrf, VRF_DEFAULT_NAME))
11610 vrf = NULL;
11611 } else if (argv_find(argv, argc, "view", &idx))
11612 /* [<view> VIEWVRFNAME] */
11613 vrf = argv[idx + 1]->arg;
11614 /* ["BGP_AFI_CMD_STR" ["BGP_SAFI_CMD_STR"]] */
11615 if (argv_find_and_parse_afi(argv, argc, &idx, &afi)) {
11616 argv_find_and_parse_safi(argv, argc, &idx, &safi);
11617 }
11618
11619 /* get subgroup id, if provided */
11620 idx = argc - 1;
11621 if (argv[idx]->type == VARIABLE_TKN)
11622 subgrp_id = strtoull(argv[idx]->arg, NULL, 10);
11623
11624 return (bgp_show_update_groups(vty, vrf, afi, safi, subgrp_id));
11625 }
11626
11627 DEFUN (show_bgp_instance_all_ipv6_updgrps,
11628 show_bgp_instance_all_ipv6_updgrps_cmd,
11629 "show [ip] bgp <view|vrf> all update-groups",
11630 SHOW_STR
11631 IP_STR
11632 BGP_STR
11633 BGP_INSTANCE_ALL_HELP_STR
11634 "Detailed info about dynamic update groups\n")
11635 {
11636 bgp_show_all_instances_updgrps_vty(vty, AFI_IP6, SAFI_UNICAST);
11637 return CMD_SUCCESS;
11638 }
11639
11640 DEFUN (show_bgp_l2vpn_evpn_updgrps,
11641 show_bgp_l2vpn_evpn_updgrps_cmd,
11642 "show [ip] bgp l2vpn evpn update-groups",
11643 SHOW_STR
11644 IP_STR
11645 BGP_STR
11646 "l2vpn address family\n"
11647 "evpn sub-address family\n"
11648 "Detailed info about dynamic update groups\n")
11649 {
11650 char *vrf = NULL;
11651 uint64_t subgrp_id = 0;
11652
11653 bgp_show_update_groups(vty, vrf, AFI_L2VPN, SAFI_EVPN, subgrp_id);
11654 return CMD_SUCCESS;
11655 }
11656
11657 DEFUN (show_bgp_updgrps_stats,
11658 show_bgp_updgrps_stats_cmd,
11659 "show [ip] bgp update-groups statistics",
11660 SHOW_STR
11661 IP_STR
11662 BGP_STR
11663 "Detailed info about dynamic update groups\n"
11664 "Statistics\n")
11665 {
11666 struct bgp *bgp;
11667
11668 bgp = bgp_get_default();
11669 if (bgp)
11670 update_group_show_stats(bgp, vty);
11671
11672 return CMD_SUCCESS;
11673 }
11674
11675 DEFUN (show_bgp_instance_updgrps_stats,
11676 show_bgp_instance_updgrps_stats_cmd,
11677 "show [ip] bgp <view|vrf> VIEWVRFNAME update-groups statistics",
11678 SHOW_STR
11679 IP_STR
11680 BGP_STR
11681 BGP_INSTANCE_HELP_STR
11682 "Detailed info about dynamic update groups\n"
11683 "Statistics\n")
11684 {
11685 int idx_word = 3;
11686 struct bgp *bgp;
11687
11688 bgp = bgp_lookup_by_name(argv[idx_word]->arg);
11689 if (bgp)
11690 update_group_show_stats(bgp, vty);
11691
11692 return CMD_SUCCESS;
11693 }
11694
11695 static void show_bgp_updgrps_adj_info_aux(struct vty *vty, const char *name,
11696 afi_t afi, safi_t safi,
11697 const char *what, uint64_t subgrp_id)
11698 {
11699 struct bgp *bgp;
11700
11701 if (name)
11702 bgp = bgp_lookup_by_name(name);
11703 else
11704 bgp = bgp_get_default();
11705
11706 if (bgp) {
11707 if (!strcmp(what, "advertise-queue"))
11708 update_group_show_adj_queue(bgp, afi, safi, vty,
11709 subgrp_id);
11710 else if (!strcmp(what, "advertised-routes"))
11711 update_group_show_advertised(bgp, afi, safi, vty,
11712 subgrp_id);
11713 else if (!strcmp(what, "packet-queue"))
11714 update_group_show_packet_queue(bgp, afi, safi, vty,
11715 subgrp_id);
11716 }
11717 }
11718
11719 DEFPY(show_ip_bgp_instance_updgrps_adj_s,
11720 show_ip_bgp_instance_updgrps_adj_s_cmd,
11721 "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",
11722 SHOW_STR IP_STR BGP_STR BGP_INSTANCE_HELP_STR BGP_AFI_HELP_STR
11723 BGP_SAFI_HELP_STR
11724 "Detailed info about dynamic update groups\n"
11725 "Specific subgroup to display info for\n"
11726 "Advertisement queue\n"
11727 "Announced routes\n"
11728 "Packet queue\n")
11729 {
11730 uint64_t subgrp_id = 0;
11731 afi_t afiz;
11732 safi_t safiz;
11733 if (sgid)
11734 subgrp_id = strtoull(sgid, NULL, 10);
11735
11736 if (!ip && !afi)
11737 afiz = AFI_IP6;
11738 if (!ip && afi)
11739 afiz = bgp_vty_afi_from_str(afi);
11740 if (ip && !afi)
11741 afiz = AFI_IP;
11742 if (ip && afi) {
11743 afiz = bgp_vty_afi_from_str(afi);
11744 if (afiz != AFI_IP)
11745 vty_out(vty,
11746 "%% Cannot specify both 'ip' and 'ipv6'\n");
11747 return CMD_WARNING;
11748 }
11749
11750 safiz = safi ? bgp_vty_safi_from_str(safi) : SAFI_UNICAST;
11751
11752 show_bgp_updgrps_adj_info_aux(vty, vrf, afiz, safiz, rtq, subgrp_id);
11753 return CMD_SUCCESS;
11754 }
11755
11756 static int bgp_show_one_peer_group(struct vty *vty, struct peer_group *group)
11757 {
11758 struct listnode *node, *nnode;
11759 struct prefix *range;
11760 struct peer *conf;
11761 struct peer *peer;
11762 char buf[PREFIX2STR_BUFFER];
11763 afi_t afi;
11764 safi_t safi;
11765 const char *peer_status;
11766 const char *af_str;
11767 int lr_count;
11768 int dynamic;
11769 int af_cfgd;
11770
11771 conf = group->conf;
11772
11773 if (conf->as_type == AS_SPECIFIED || conf->as_type == AS_EXTERNAL) {
11774 vty_out(vty, "\nBGP peer-group %s, remote AS %" PRIu32 "\n",
11775 group->name, conf->as);
11776 } else if (conf->as_type == AS_INTERNAL) {
11777 vty_out(vty, "\nBGP peer-group %s, remote AS %" PRIu32 "\n",
11778 group->name, group->bgp->as);
11779 } else {
11780 vty_out(vty, "\nBGP peer-group %s\n", group->name);
11781 }
11782
11783 if ((group->bgp->as == conf->as) || (conf->as_type == AS_INTERNAL))
11784 vty_out(vty, " Peer-group type is internal\n");
11785 else
11786 vty_out(vty, " Peer-group type is external\n");
11787
11788 /* Display AFs configured. */
11789 vty_out(vty, " Configured address-families:");
11790 FOREACH_AFI_SAFI (afi, safi) {
11791 if (conf->afc[afi][safi]) {
11792 af_cfgd = 1;
11793 vty_out(vty, " %s;", afi_safi_print(afi, safi));
11794 }
11795 }
11796 if (!af_cfgd)
11797 vty_out(vty, " none\n");
11798 else
11799 vty_out(vty, "\n");
11800
11801 /* Display listen ranges (for dynamic neighbors), if any */
11802 for (afi = AFI_IP; afi < AFI_MAX; afi++) {
11803 if (afi == AFI_IP)
11804 af_str = "IPv4";
11805 else if (afi == AFI_IP6)
11806 af_str = "IPv6";
11807 else
11808 af_str = "???";
11809 lr_count = listcount(group->listen_range[afi]);
11810 if (lr_count) {
11811 vty_out(vty, " %d %s listen range(s)\n", lr_count,
11812 af_str);
11813
11814
11815 for (ALL_LIST_ELEMENTS(group->listen_range[afi], node,
11816 nnode, range)) {
11817 prefix2str(range, buf, sizeof(buf));
11818 vty_out(vty, " %s\n", buf);
11819 }
11820 }
11821 }
11822
11823 /* Display group members and their status */
11824 if (listcount(group->peer)) {
11825 vty_out(vty, " Peer-group members:\n");
11826 for (ALL_LIST_ELEMENTS(group->peer, node, nnode, peer)) {
11827 if (CHECK_FLAG(peer->flags, PEER_FLAG_SHUTDOWN))
11828 peer_status = "Idle (Admin)";
11829 else if (CHECK_FLAG(peer->sflags,
11830 PEER_STATUS_PREFIX_OVERFLOW))
11831 peer_status = "Idle (PfxCt)";
11832 else
11833 peer_status = lookup_msg(bgp_status_msg,
11834 peer->status, NULL);
11835
11836 dynamic = peer_dynamic_neighbor(peer);
11837 vty_out(vty, " %s %s %s \n", peer->host,
11838 dynamic ? "(dynamic)" : "", peer_status);
11839 }
11840 }
11841
11842 return CMD_SUCCESS;
11843 }
11844
11845 static int bgp_show_peer_group_vty(struct vty *vty, const char *name,
11846 const char *group_name)
11847 {
11848 struct bgp *bgp;
11849 struct listnode *node, *nnode;
11850 struct peer_group *group;
11851 bool found = false;
11852
11853 bgp = name ? bgp_lookup_by_name(name) : bgp_get_default();
11854
11855 if (!bgp) {
11856 vty_out(vty, "%% BGP instance not found\n");
11857 return CMD_WARNING;
11858 }
11859
11860 for (ALL_LIST_ELEMENTS(bgp->group, node, nnode, group)) {
11861 if (group_name) {
11862 if (strmatch(group->name, group_name)) {
11863 bgp_show_one_peer_group(vty, group);
11864 found = true;
11865 break;
11866 }
11867 } else {
11868 bgp_show_one_peer_group(vty, group);
11869 }
11870 }
11871
11872 if (group_name && !found)
11873 vty_out(vty, "%% No such peer-group\n");
11874
11875 return CMD_SUCCESS;
11876 }
11877
11878 DEFUN (show_ip_bgp_peer_groups,
11879 show_ip_bgp_peer_groups_cmd,
11880 "show [ip] bgp [<view|vrf> VIEWVRFNAME] peer-group [PGNAME]",
11881 SHOW_STR
11882 IP_STR
11883 BGP_STR
11884 BGP_INSTANCE_HELP_STR
11885 "Detailed information on BGP peer groups\n"
11886 "Peer group name\n")
11887 {
11888 char *vrf, *pg;
11889 int idx = 0;
11890
11891 vrf = argv_find(argv, argc, "VIEWVRFNAME", &idx) ? argv[idx]->arg
11892 : NULL;
11893 pg = argv_find(argv, argc, "PGNAME", &idx) ? argv[idx]->arg : NULL;
11894
11895 return bgp_show_peer_group_vty(vty, vrf, pg);
11896 }
11897
11898
11899 /* Redistribute VTY commands. */
11900
11901 DEFUN (bgp_redistribute_ipv4,
11902 bgp_redistribute_ipv4_cmd,
11903 "redistribute " FRR_IP_REDIST_STR_BGPD,
11904 "Redistribute information from another routing protocol\n"
11905 FRR_IP_REDIST_HELP_STR_BGPD)
11906 {
11907 VTY_DECLVAR_CONTEXT(bgp, bgp);
11908 int idx_protocol = 1;
11909 int type;
11910
11911 type = proto_redistnum(AFI_IP, argv[idx_protocol]->text);
11912 if (type < 0) {
11913 vty_out(vty, "%% Invalid route type\n");
11914 return CMD_WARNING_CONFIG_FAILED;
11915 }
11916
11917 bgp_redist_add(bgp, AFI_IP, type, 0);
11918 return bgp_redistribute_set(bgp, AFI_IP, type, 0, false);
11919 }
11920
11921 ALIAS_HIDDEN(
11922 bgp_redistribute_ipv4, bgp_redistribute_ipv4_hidden_cmd,
11923 "redistribute " FRR_IP_REDIST_STR_BGPD,
11924 "Redistribute information from another routing protocol\n" FRR_IP_REDIST_HELP_STR_BGPD)
11925
11926 DEFUN (bgp_redistribute_ipv4_rmap,
11927 bgp_redistribute_ipv4_rmap_cmd,
11928 "redistribute " FRR_IP_REDIST_STR_BGPD " route-map WORD",
11929 "Redistribute information from another routing protocol\n"
11930 FRR_IP_REDIST_HELP_STR_BGPD
11931 "Route map reference\n"
11932 "Pointer to route-map entries\n")
11933 {
11934 VTY_DECLVAR_CONTEXT(bgp, bgp);
11935 int idx_protocol = 1;
11936 int idx_word = 3;
11937 int type;
11938 struct bgp_redist *red;
11939 bool changed;
11940 struct route_map *route_map = route_map_lookup_warn_noexist(
11941 vty, argv[idx_word]->arg);
11942
11943 type = proto_redistnum(AFI_IP, argv[idx_protocol]->text);
11944 if (type < 0) {
11945 vty_out(vty, "%% Invalid route type\n");
11946 return CMD_WARNING_CONFIG_FAILED;
11947 }
11948
11949 red = bgp_redist_add(bgp, AFI_IP, type, 0);
11950 changed =
11951 bgp_redistribute_rmap_set(red, argv[idx_word]->arg, route_map);
11952 return bgp_redistribute_set(bgp, AFI_IP, type, 0, changed);
11953 }
11954
11955 ALIAS_HIDDEN(
11956 bgp_redistribute_ipv4_rmap, bgp_redistribute_ipv4_rmap_hidden_cmd,
11957 "redistribute " FRR_IP_REDIST_STR_BGPD " route-map WORD",
11958 "Redistribute information from another routing protocol\n" FRR_IP_REDIST_HELP_STR_BGPD
11959 "Route map reference\n"
11960 "Pointer to route-map entries\n")
11961
11962 DEFUN (bgp_redistribute_ipv4_metric,
11963 bgp_redistribute_ipv4_metric_cmd,
11964 "redistribute " FRR_IP_REDIST_STR_BGPD " metric (0-4294967295)",
11965 "Redistribute information from another routing protocol\n"
11966 FRR_IP_REDIST_HELP_STR_BGPD
11967 "Metric for redistributed routes\n"
11968 "Default metric\n")
11969 {
11970 VTY_DECLVAR_CONTEXT(bgp, bgp);
11971 int idx_protocol = 1;
11972 int idx_number = 3;
11973 int type;
11974 uint32_t metric;
11975 struct bgp_redist *red;
11976 bool changed;
11977
11978 type = proto_redistnum(AFI_IP, argv[idx_protocol]->text);
11979 if (type < 0) {
11980 vty_out(vty, "%% Invalid route type\n");
11981 return CMD_WARNING_CONFIG_FAILED;
11982 }
11983 metric = strtoul(argv[idx_number]->arg, NULL, 10);
11984
11985 red = bgp_redist_add(bgp, AFI_IP, type, 0);
11986 changed = bgp_redistribute_metric_set(bgp, red, AFI_IP, type, metric);
11987 return bgp_redistribute_set(bgp, AFI_IP, type, 0, changed);
11988 }
11989
11990 ALIAS_HIDDEN(
11991 bgp_redistribute_ipv4_metric, bgp_redistribute_ipv4_metric_hidden_cmd,
11992 "redistribute " FRR_IP_REDIST_STR_BGPD " metric (0-4294967295)",
11993 "Redistribute information from another routing protocol\n" FRR_IP_REDIST_HELP_STR_BGPD
11994 "Metric for redistributed routes\n"
11995 "Default metric\n")
11996
11997 DEFUN (bgp_redistribute_ipv4_rmap_metric,
11998 bgp_redistribute_ipv4_rmap_metric_cmd,
11999 "redistribute " FRR_IP_REDIST_STR_BGPD " route-map WORD metric (0-4294967295)",
12000 "Redistribute information from another routing protocol\n"
12001 FRR_IP_REDIST_HELP_STR_BGPD
12002 "Route map reference\n"
12003 "Pointer to route-map entries\n"
12004 "Metric for redistributed routes\n"
12005 "Default metric\n")
12006 {
12007 VTY_DECLVAR_CONTEXT(bgp, bgp);
12008 int idx_protocol = 1;
12009 int idx_word = 3;
12010 int idx_number = 5;
12011 int type;
12012 uint32_t metric;
12013 struct bgp_redist *red;
12014 bool changed;
12015 struct route_map *route_map =
12016 route_map_lookup_warn_noexist(vty, argv[idx_word]->arg);
12017
12018 type = proto_redistnum(AFI_IP, argv[idx_protocol]->text);
12019 if (type < 0) {
12020 vty_out(vty, "%% Invalid route type\n");
12021 return CMD_WARNING_CONFIG_FAILED;
12022 }
12023 metric = strtoul(argv[idx_number]->arg, NULL, 10);
12024
12025 red = bgp_redist_add(bgp, AFI_IP, type, 0);
12026 changed =
12027 bgp_redistribute_rmap_set(red, argv[idx_word]->arg, route_map);
12028 changed |= bgp_redistribute_metric_set(bgp, red, AFI_IP, type, metric);
12029 return bgp_redistribute_set(bgp, AFI_IP, type, 0, changed);
12030 }
12031
12032 ALIAS_HIDDEN(
12033 bgp_redistribute_ipv4_rmap_metric,
12034 bgp_redistribute_ipv4_rmap_metric_hidden_cmd,
12035 "redistribute " FRR_IP_REDIST_STR_BGPD
12036 " route-map WORD metric (0-4294967295)",
12037 "Redistribute information from another routing protocol\n" FRR_IP_REDIST_HELP_STR_BGPD
12038 "Route map reference\n"
12039 "Pointer to route-map entries\n"
12040 "Metric for redistributed routes\n"
12041 "Default metric\n")
12042
12043 DEFUN (bgp_redistribute_ipv4_metric_rmap,
12044 bgp_redistribute_ipv4_metric_rmap_cmd,
12045 "redistribute " FRR_IP_REDIST_STR_BGPD " metric (0-4294967295) route-map WORD",
12046 "Redistribute information from another routing protocol\n"
12047 FRR_IP_REDIST_HELP_STR_BGPD
12048 "Metric for redistributed routes\n"
12049 "Default metric\n"
12050 "Route map reference\n"
12051 "Pointer to route-map entries\n")
12052 {
12053 VTY_DECLVAR_CONTEXT(bgp, bgp);
12054 int idx_protocol = 1;
12055 int idx_number = 3;
12056 int idx_word = 5;
12057 int type;
12058 uint32_t metric;
12059 struct bgp_redist *red;
12060 bool changed;
12061 struct route_map *route_map =
12062 route_map_lookup_warn_noexist(vty, argv[idx_word]->arg);
12063
12064 type = proto_redistnum(AFI_IP, argv[idx_protocol]->text);
12065 if (type < 0) {
12066 vty_out(vty, "%% Invalid route type\n");
12067 return CMD_WARNING_CONFIG_FAILED;
12068 }
12069 metric = strtoul(argv[idx_number]->arg, NULL, 10);
12070
12071 red = bgp_redist_add(bgp, AFI_IP, type, 0);
12072 changed = bgp_redistribute_metric_set(bgp, red, AFI_IP, type, metric);
12073 changed |=
12074 bgp_redistribute_rmap_set(red, argv[idx_word]->arg, route_map);
12075 return bgp_redistribute_set(bgp, AFI_IP, type, 0, changed);
12076 }
12077
12078 ALIAS_HIDDEN(
12079 bgp_redistribute_ipv4_metric_rmap,
12080 bgp_redistribute_ipv4_metric_rmap_hidden_cmd,
12081 "redistribute " FRR_IP_REDIST_STR_BGPD
12082 " metric (0-4294967295) route-map WORD",
12083 "Redistribute information from another routing protocol\n" FRR_IP_REDIST_HELP_STR_BGPD
12084 "Metric for redistributed routes\n"
12085 "Default metric\n"
12086 "Route map reference\n"
12087 "Pointer to route-map entries\n")
12088
12089 DEFUN (bgp_redistribute_ipv4_ospf,
12090 bgp_redistribute_ipv4_ospf_cmd,
12091 "redistribute <ospf|table> (1-65535)",
12092 "Redistribute information from another routing protocol\n"
12093 "Open Shortest Path First (OSPFv2)\n"
12094 "Non-main Kernel Routing Table\n"
12095 "Instance ID/Table ID\n")
12096 {
12097 VTY_DECLVAR_CONTEXT(bgp, bgp);
12098 int idx_ospf_table = 1;
12099 int idx_number = 2;
12100 unsigned short instance;
12101 unsigned short protocol;
12102
12103 instance = strtoul(argv[idx_number]->arg, NULL, 10);
12104
12105 if (strncmp(argv[idx_ospf_table]->arg, "o", 1) == 0)
12106 protocol = ZEBRA_ROUTE_OSPF;
12107 else
12108 protocol = ZEBRA_ROUTE_TABLE;
12109
12110 bgp_redist_add(bgp, AFI_IP, protocol, instance);
12111 return bgp_redistribute_set(bgp, AFI_IP, protocol, instance, false);
12112 }
12113
12114 ALIAS_HIDDEN(bgp_redistribute_ipv4_ospf, bgp_redistribute_ipv4_ospf_hidden_cmd,
12115 "redistribute <ospf|table> (1-65535)",
12116 "Redistribute information from another routing protocol\n"
12117 "Open Shortest Path First (OSPFv2)\n"
12118 "Non-main Kernel Routing Table\n"
12119 "Instance ID/Table ID\n")
12120
12121 DEFUN (bgp_redistribute_ipv4_ospf_rmap,
12122 bgp_redistribute_ipv4_ospf_rmap_cmd,
12123 "redistribute <ospf|table> (1-65535) route-map WORD",
12124 "Redistribute information from another routing protocol\n"
12125 "Open Shortest Path First (OSPFv2)\n"
12126 "Non-main Kernel Routing Table\n"
12127 "Instance ID/Table ID\n"
12128 "Route map reference\n"
12129 "Pointer to route-map entries\n")
12130 {
12131 VTY_DECLVAR_CONTEXT(bgp, bgp);
12132 int idx_ospf_table = 1;
12133 int idx_number = 2;
12134 int idx_word = 4;
12135 struct bgp_redist *red;
12136 unsigned short instance;
12137 int protocol;
12138 bool changed;
12139 struct route_map *route_map =
12140 route_map_lookup_warn_noexist(vty, argv[idx_word]->arg);
12141
12142 if (strncmp(argv[idx_ospf_table]->arg, "o", 1) == 0)
12143 protocol = ZEBRA_ROUTE_OSPF;
12144 else
12145 protocol = ZEBRA_ROUTE_TABLE;
12146
12147 instance = strtoul(argv[idx_number]->arg, NULL, 10);
12148 red = bgp_redist_add(bgp, AFI_IP, protocol, instance);
12149 changed =
12150 bgp_redistribute_rmap_set(red, argv[idx_word]->arg, route_map);
12151 return bgp_redistribute_set(bgp, AFI_IP, protocol, instance, changed);
12152 }
12153
12154 ALIAS_HIDDEN(bgp_redistribute_ipv4_ospf_rmap,
12155 bgp_redistribute_ipv4_ospf_rmap_hidden_cmd,
12156 "redistribute <ospf|table> (1-65535) route-map WORD",
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 "Route map reference\n"
12162 "Pointer to route-map entries\n")
12163
12164 DEFUN (bgp_redistribute_ipv4_ospf_metric,
12165 bgp_redistribute_ipv4_ospf_metric_cmd,
12166 "redistribute <ospf|table> (1-65535) metric (0-4294967295)",
12167 "Redistribute information from another routing protocol\n"
12168 "Open Shortest Path First (OSPFv2)\n"
12169 "Non-main Kernel Routing Table\n"
12170 "Instance ID/Table ID\n"
12171 "Metric for redistributed routes\n"
12172 "Default metric\n")
12173 {
12174 VTY_DECLVAR_CONTEXT(bgp, bgp);
12175 int idx_ospf_table = 1;
12176 int idx_number = 2;
12177 int idx_number_2 = 4;
12178 uint32_t metric;
12179 struct bgp_redist *red;
12180 unsigned short instance;
12181 int protocol;
12182 bool changed;
12183
12184 if (strncmp(argv[idx_ospf_table]->arg, "o", 1) == 0)
12185 protocol = ZEBRA_ROUTE_OSPF;
12186 else
12187 protocol = ZEBRA_ROUTE_TABLE;
12188
12189 instance = strtoul(argv[idx_number]->arg, NULL, 10);
12190 metric = strtoul(argv[idx_number_2]->arg, NULL, 10);
12191
12192 red = bgp_redist_add(bgp, AFI_IP, protocol, instance);
12193 changed = bgp_redistribute_metric_set(bgp, red, AFI_IP, protocol,
12194 metric);
12195 return bgp_redistribute_set(bgp, AFI_IP, protocol, instance, changed);
12196 }
12197
12198 ALIAS_HIDDEN(bgp_redistribute_ipv4_ospf_metric,
12199 bgp_redistribute_ipv4_ospf_metric_hidden_cmd,
12200 "redistribute <ospf|table> (1-65535) metric (0-4294967295)",
12201 "Redistribute information from another routing protocol\n"
12202 "Open Shortest Path First (OSPFv2)\n"
12203 "Non-main Kernel Routing Table\n"
12204 "Instance ID/Table ID\n"
12205 "Metric for redistributed routes\n"
12206 "Default metric\n")
12207
12208 DEFUN (bgp_redistribute_ipv4_ospf_rmap_metric,
12209 bgp_redistribute_ipv4_ospf_rmap_metric_cmd,
12210 "redistribute <ospf|table> (1-65535) route-map WORD metric (0-4294967295)",
12211 "Redistribute information from another routing protocol\n"
12212 "Open Shortest Path First (OSPFv2)\n"
12213 "Non-main Kernel Routing Table\n"
12214 "Instance ID/Table ID\n"
12215 "Route map reference\n"
12216 "Pointer to route-map entries\n"
12217 "Metric for redistributed routes\n"
12218 "Default metric\n")
12219 {
12220 VTY_DECLVAR_CONTEXT(bgp, bgp);
12221 int idx_ospf_table = 1;
12222 int idx_number = 2;
12223 int idx_word = 4;
12224 int idx_number_2 = 6;
12225 uint32_t metric;
12226 struct bgp_redist *red;
12227 unsigned short instance;
12228 int protocol;
12229 bool changed;
12230 struct route_map *route_map =
12231 route_map_lookup_warn_noexist(vty, argv[idx_word]->arg);
12232
12233 if (strncmp(argv[idx_ospf_table]->arg, "o", 1) == 0)
12234 protocol = ZEBRA_ROUTE_OSPF;
12235 else
12236 protocol = ZEBRA_ROUTE_TABLE;
12237
12238 instance = strtoul(argv[idx_number]->arg, NULL, 10);
12239 metric = strtoul(argv[idx_number_2]->arg, NULL, 10);
12240
12241 red = bgp_redist_add(bgp, AFI_IP, protocol, instance);
12242 changed =
12243 bgp_redistribute_rmap_set(red, argv[idx_word]->arg, route_map);
12244 changed |= bgp_redistribute_metric_set(bgp, red, AFI_IP, protocol,
12245 metric);
12246 return bgp_redistribute_set(bgp, AFI_IP, protocol, instance, changed);
12247 }
12248
12249 ALIAS_HIDDEN(
12250 bgp_redistribute_ipv4_ospf_rmap_metric,
12251 bgp_redistribute_ipv4_ospf_rmap_metric_hidden_cmd,
12252 "redistribute <ospf|table> (1-65535) route-map WORD metric (0-4294967295)",
12253 "Redistribute information from another routing protocol\n"
12254 "Open Shortest Path First (OSPFv2)\n"
12255 "Non-main Kernel Routing Table\n"
12256 "Instance ID/Table ID\n"
12257 "Route map reference\n"
12258 "Pointer to route-map entries\n"
12259 "Metric for redistributed routes\n"
12260 "Default metric\n")
12261
12262 DEFUN (bgp_redistribute_ipv4_ospf_metric_rmap,
12263 bgp_redistribute_ipv4_ospf_metric_rmap_cmd,
12264 "redistribute <ospf|table> (1-65535) metric (0-4294967295) route-map WORD",
12265 "Redistribute information from another routing protocol\n"
12266 "Open Shortest Path First (OSPFv2)\n"
12267 "Non-main Kernel Routing Table\n"
12268 "Instance ID/Table ID\n"
12269 "Metric for redistributed routes\n"
12270 "Default metric\n"
12271 "Route map reference\n"
12272 "Pointer to route-map entries\n")
12273 {
12274 VTY_DECLVAR_CONTEXT(bgp, bgp);
12275 int idx_ospf_table = 1;
12276 int idx_number = 2;
12277 int idx_number_2 = 4;
12278 int idx_word = 6;
12279 uint32_t metric;
12280 struct bgp_redist *red;
12281 unsigned short instance;
12282 int protocol;
12283 bool changed;
12284 struct route_map *route_map =
12285 route_map_lookup_warn_noexist(vty, argv[idx_word]->arg);
12286
12287 if (strncmp(argv[idx_ospf_table]->arg, "o", 1) == 0)
12288 protocol = ZEBRA_ROUTE_OSPF;
12289 else
12290 protocol = ZEBRA_ROUTE_TABLE;
12291
12292 instance = strtoul(argv[idx_number]->arg, NULL, 10);
12293 metric = strtoul(argv[idx_number_2]->arg, NULL, 10);
12294
12295 red = bgp_redist_add(bgp, AFI_IP, protocol, instance);
12296 changed = bgp_redistribute_metric_set(bgp, red, AFI_IP, protocol,
12297 metric);
12298 changed |=
12299 bgp_redistribute_rmap_set(red, argv[idx_word]->arg, route_map);
12300 return bgp_redistribute_set(bgp, AFI_IP, protocol, instance, changed);
12301 }
12302
12303 ALIAS_HIDDEN(
12304 bgp_redistribute_ipv4_ospf_metric_rmap,
12305 bgp_redistribute_ipv4_ospf_metric_rmap_hidden_cmd,
12306 "redistribute <ospf|table> (1-65535) metric (0-4294967295) route-map WORD",
12307 "Redistribute information from another routing protocol\n"
12308 "Open Shortest Path First (OSPFv2)\n"
12309 "Non-main Kernel Routing Table\n"
12310 "Instance ID/Table ID\n"
12311 "Metric for redistributed routes\n"
12312 "Default metric\n"
12313 "Route map reference\n"
12314 "Pointer to route-map entries\n")
12315
12316 DEFUN (no_bgp_redistribute_ipv4_ospf,
12317 no_bgp_redistribute_ipv4_ospf_cmd,
12318 "no redistribute <ospf|table> (1-65535) [{metric (0-4294967295)|route-map WORD}]",
12319 NO_STR
12320 "Redistribute information from another routing protocol\n"
12321 "Open Shortest Path First (OSPFv2)\n"
12322 "Non-main Kernel Routing Table\n"
12323 "Instance ID/Table ID\n"
12324 "Metric for redistributed routes\n"
12325 "Default metric\n"
12326 "Route map reference\n"
12327 "Pointer to route-map entries\n")
12328 {
12329 VTY_DECLVAR_CONTEXT(bgp, bgp);
12330 int idx_ospf_table = 2;
12331 int idx_number = 3;
12332 unsigned short instance;
12333 int protocol;
12334
12335 if (strncmp(argv[idx_ospf_table]->arg, "o", 1) == 0)
12336 protocol = ZEBRA_ROUTE_OSPF;
12337 else
12338 protocol = ZEBRA_ROUTE_TABLE;
12339
12340 instance = strtoul(argv[idx_number]->arg, NULL, 10);
12341 return bgp_redistribute_unset(bgp, AFI_IP, protocol, instance);
12342 }
12343
12344 ALIAS_HIDDEN(
12345 no_bgp_redistribute_ipv4_ospf, no_bgp_redistribute_ipv4_ospf_hidden_cmd,
12346 "no redistribute <ospf|table> (1-65535) [{metric (0-4294967295)|route-map WORD}]",
12347 NO_STR
12348 "Redistribute information from another routing protocol\n"
12349 "Open Shortest Path First (OSPFv2)\n"
12350 "Non-main Kernel Routing Table\n"
12351 "Instance ID/Table ID\n"
12352 "Metric for redistributed routes\n"
12353 "Default metric\n"
12354 "Route map reference\n"
12355 "Pointer to route-map entries\n")
12356
12357 DEFUN (no_bgp_redistribute_ipv4,
12358 no_bgp_redistribute_ipv4_cmd,
12359 "no redistribute " FRR_IP_REDIST_STR_BGPD " [{metric (0-4294967295)|route-map WORD}]",
12360 NO_STR
12361 "Redistribute information from another routing protocol\n"
12362 FRR_IP_REDIST_HELP_STR_BGPD
12363 "Metric for redistributed routes\n"
12364 "Default metric\n"
12365 "Route map reference\n"
12366 "Pointer to route-map entries\n")
12367 {
12368 VTY_DECLVAR_CONTEXT(bgp, bgp);
12369 int idx_protocol = 2;
12370 int type;
12371
12372 type = proto_redistnum(AFI_IP, argv[idx_protocol]->text);
12373 if (type < 0) {
12374 vty_out(vty, "%% Invalid route type\n");
12375 return CMD_WARNING_CONFIG_FAILED;
12376 }
12377 return bgp_redistribute_unset(bgp, AFI_IP, type, 0);
12378 }
12379
12380 ALIAS_HIDDEN(
12381 no_bgp_redistribute_ipv4, no_bgp_redistribute_ipv4_hidden_cmd,
12382 "no redistribute " FRR_IP_REDIST_STR_BGPD
12383 " [{metric (0-4294967295)|route-map WORD}]",
12384 NO_STR
12385 "Redistribute information from another routing protocol\n" FRR_IP_REDIST_HELP_STR_BGPD
12386 "Metric for redistributed routes\n"
12387 "Default metric\n"
12388 "Route map reference\n"
12389 "Pointer to route-map entries\n")
12390
12391 DEFUN (bgp_redistribute_ipv6,
12392 bgp_redistribute_ipv6_cmd,
12393 "redistribute " FRR_IP6_REDIST_STR_BGPD,
12394 "Redistribute information from another routing protocol\n"
12395 FRR_IP6_REDIST_HELP_STR_BGPD)
12396 {
12397 VTY_DECLVAR_CONTEXT(bgp, bgp);
12398 int idx_protocol = 1;
12399 int type;
12400
12401 type = proto_redistnum(AFI_IP6, argv[idx_protocol]->text);
12402 if (type < 0) {
12403 vty_out(vty, "%% Invalid route type\n");
12404 return CMD_WARNING_CONFIG_FAILED;
12405 }
12406
12407 bgp_redist_add(bgp, AFI_IP6, type, 0);
12408 return bgp_redistribute_set(bgp, AFI_IP6, type, 0, false);
12409 }
12410
12411 DEFUN (bgp_redistribute_ipv6_rmap,
12412 bgp_redistribute_ipv6_rmap_cmd,
12413 "redistribute " FRR_IP6_REDIST_STR_BGPD " route-map WORD",
12414 "Redistribute information from another routing protocol\n"
12415 FRR_IP6_REDIST_HELP_STR_BGPD
12416 "Route map reference\n"
12417 "Pointer to route-map entries\n")
12418 {
12419 VTY_DECLVAR_CONTEXT(bgp, bgp);
12420 int idx_protocol = 1;
12421 int idx_word = 3;
12422 int type;
12423 struct bgp_redist *red;
12424 bool changed;
12425 struct route_map *route_map =
12426 route_map_lookup_warn_noexist(vty, argv[idx_word]->arg);
12427
12428 type = proto_redistnum(AFI_IP6, argv[idx_protocol]->text);
12429 if (type < 0) {
12430 vty_out(vty, "%% Invalid route type\n");
12431 return CMD_WARNING_CONFIG_FAILED;
12432 }
12433
12434 red = bgp_redist_add(bgp, AFI_IP6, type, 0);
12435 changed =
12436 bgp_redistribute_rmap_set(red, argv[idx_word]->arg, route_map);
12437 return bgp_redistribute_set(bgp, AFI_IP6, type, 0, changed);
12438 }
12439
12440 DEFUN (bgp_redistribute_ipv6_metric,
12441 bgp_redistribute_ipv6_metric_cmd,
12442 "redistribute " FRR_IP6_REDIST_STR_BGPD " metric (0-4294967295)",
12443 "Redistribute information from another routing protocol\n"
12444 FRR_IP6_REDIST_HELP_STR_BGPD
12445 "Metric for redistributed routes\n"
12446 "Default metric\n")
12447 {
12448 VTY_DECLVAR_CONTEXT(bgp, bgp);
12449 int idx_protocol = 1;
12450 int idx_number = 3;
12451 int type;
12452 uint32_t metric;
12453 struct bgp_redist *red;
12454 bool changed;
12455
12456 type = proto_redistnum(AFI_IP6, argv[idx_protocol]->text);
12457 if (type < 0) {
12458 vty_out(vty, "%% Invalid route type\n");
12459 return CMD_WARNING_CONFIG_FAILED;
12460 }
12461 metric = strtoul(argv[idx_number]->arg, NULL, 10);
12462
12463 red = bgp_redist_add(bgp, AFI_IP6, type, 0);
12464 changed = bgp_redistribute_metric_set(bgp, red, AFI_IP6, type, metric);
12465 return bgp_redistribute_set(bgp, AFI_IP6, type, 0, changed);
12466 }
12467
12468 DEFUN (bgp_redistribute_ipv6_rmap_metric,
12469 bgp_redistribute_ipv6_rmap_metric_cmd,
12470 "redistribute " FRR_IP6_REDIST_STR_BGPD " route-map WORD metric (0-4294967295)",
12471 "Redistribute information from another routing protocol\n"
12472 FRR_IP6_REDIST_HELP_STR_BGPD
12473 "Route map reference\n"
12474 "Pointer to route-map entries\n"
12475 "Metric for redistributed routes\n"
12476 "Default metric\n")
12477 {
12478 VTY_DECLVAR_CONTEXT(bgp, bgp);
12479 int idx_protocol = 1;
12480 int idx_word = 3;
12481 int idx_number = 5;
12482 int type;
12483 uint32_t metric;
12484 struct bgp_redist *red;
12485 bool changed;
12486 struct route_map *route_map =
12487 route_map_lookup_warn_noexist(vty, argv[idx_word]->arg);
12488
12489 type = proto_redistnum(AFI_IP6, argv[idx_protocol]->text);
12490 if (type < 0) {
12491 vty_out(vty, "%% Invalid route type\n");
12492 return CMD_WARNING_CONFIG_FAILED;
12493 }
12494 metric = strtoul(argv[idx_number]->arg, NULL, 10);
12495
12496 red = bgp_redist_add(bgp, AFI_IP6, type, 0);
12497 changed =
12498 bgp_redistribute_rmap_set(red, argv[idx_word]->arg, route_map);
12499 changed |= bgp_redistribute_metric_set(bgp, red, AFI_IP6, type,
12500 metric);
12501 return bgp_redistribute_set(bgp, AFI_IP6, type, 0, changed);
12502 }
12503
12504 DEFUN (bgp_redistribute_ipv6_metric_rmap,
12505 bgp_redistribute_ipv6_metric_rmap_cmd,
12506 "redistribute " FRR_IP6_REDIST_STR_BGPD " metric (0-4294967295) route-map WORD",
12507 "Redistribute information from another routing protocol\n"
12508 FRR_IP6_REDIST_HELP_STR_BGPD
12509 "Metric for redistributed routes\n"
12510 "Default metric\n"
12511 "Route map reference\n"
12512 "Pointer to route-map entries\n")
12513 {
12514 VTY_DECLVAR_CONTEXT(bgp, bgp);
12515 int idx_protocol = 1;
12516 int idx_number = 3;
12517 int idx_word = 5;
12518 int type;
12519 uint32_t metric;
12520 struct bgp_redist *red;
12521 bool changed;
12522 struct route_map *route_map =
12523 route_map_lookup_warn_noexist(vty, argv[idx_word]->arg);
12524
12525 type = proto_redistnum(AFI_IP6, argv[idx_protocol]->text);
12526 if (type < 0) {
12527 vty_out(vty, "%% Invalid route type\n");
12528 return CMD_WARNING_CONFIG_FAILED;
12529 }
12530 metric = strtoul(argv[idx_number]->arg, NULL, 10);
12531
12532 red = bgp_redist_add(bgp, AFI_IP6, type, 0);
12533 changed = bgp_redistribute_metric_set(bgp, red, AFI_IP6, SAFI_UNICAST,
12534 metric);
12535 changed |=
12536 bgp_redistribute_rmap_set(red, argv[idx_word]->arg, route_map);
12537 return bgp_redistribute_set(bgp, AFI_IP6, type, 0, changed);
12538 }
12539
12540 DEFUN (no_bgp_redistribute_ipv6,
12541 no_bgp_redistribute_ipv6_cmd,
12542 "no redistribute " FRR_IP6_REDIST_STR_BGPD " [{metric (0-4294967295)|route-map WORD}]",
12543 NO_STR
12544 "Redistribute information from another routing protocol\n"
12545 FRR_IP6_REDIST_HELP_STR_BGPD
12546 "Metric for redistributed routes\n"
12547 "Default metric\n"
12548 "Route map reference\n"
12549 "Pointer to route-map entries\n")
12550 {
12551 VTY_DECLVAR_CONTEXT(bgp, bgp);
12552 int idx_protocol = 2;
12553 int type;
12554
12555 type = proto_redistnum(AFI_IP6, argv[idx_protocol]->text);
12556 if (type < 0) {
12557 vty_out(vty, "%% Invalid route type\n");
12558 return CMD_WARNING_CONFIG_FAILED;
12559 }
12560
12561 return bgp_redistribute_unset(bgp, AFI_IP6, type, 0);
12562 }
12563
12564 void bgp_config_write_redistribute(struct vty *vty, struct bgp *bgp, afi_t afi,
12565 safi_t safi)
12566 {
12567 int i;
12568
12569 /* Unicast redistribution only. */
12570 if (safi != SAFI_UNICAST)
12571 return;
12572
12573 for (i = 0; i < ZEBRA_ROUTE_MAX; i++) {
12574 /* Redistribute BGP does not make sense. */
12575 if (i != ZEBRA_ROUTE_BGP) {
12576 struct list *red_list;
12577 struct listnode *node;
12578 struct bgp_redist *red;
12579
12580 red_list = bgp->redist[afi][i];
12581 if (!red_list)
12582 continue;
12583
12584 for (ALL_LIST_ELEMENTS_RO(red_list, node, red)) {
12585 /* "redistribute" configuration. */
12586 vty_out(vty, " redistribute %s",
12587 zebra_route_string(i));
12588 if (red->instance)
12589 vty_out(vty, " %d", red->instance);
12590 if (red->redist_metric_flag)
12591 vty_out(vty, " metric %u",
12592 red->redist_metric);
12593 if (red->rmap.name)
12594 vty_out(vty, " route-map %s",
12595 red->rmap.name);
12596 vty_out(vty, "\n");
12597 }
12598 }
12599 }
12600 }
12601
12602 /* This is part of the address-family block (unicast only) */
12603 void bgp_vpn_policy_config_write_afi(struct vty *vty, struct bgp *bgp,
12604 afi_t afi)
12605 {
12606 int indent = 2;
12607
12608 if (bgp->vpn_policy[afi].rmap_name[BGP_VPN_POLICY_DIR_FROMVPN]) {
12609 if (listcount(bgp->vpn_policy[afi].import_vrf))
12610 vty_out(vty, "%*simport vrf route-map %s\n", indent, "",
12611 bgp->vpn_policy[afi]
12612 .rmap_name[BGP_VPN_POLICY_DIR_FROMVPN]);
12613 else
12614 vty_out(vty, "%*sroute-map vpn import %s\n", indent, "",
12615 bgp->vpn_policy[afi]
12616 .rmap_name[BGP_VPN_POLICY_DIR_FROMVPN]);
12617 }
12618 if (CHECK_FLAG(bgp->af_flags[afi][SAFI_UNICAST],
12619 BGP_CONFIG_VRF_TO_VRF_IMPORT)
12620 || CHECK_FLAG(bgp->af_flags[afi][SAFI_UNICAST],
12621 BGP_CONFIG_VRF_TO_VRF_EXPORT))
12622 return;
12623
12624 if (CHECK_FLAG(bgp->vpn_policy[afi].flags,
12625 BGP_VPN_POLICY_TOVPN_LABEL_AUTO)) {
12626
12627 vty_out(vty, "%*slabel vpn export %s\n", indent, "", "auto");
12628
12629 } else {
12630 if (bgp->vpn_policy[afi].tovpn_label != MPLS_LABEL_NONE) {
12631 vty_out(vty, "%*slabel vpn export %u\n", indent, "",
12632 bgp->vpn_policy[afi].tovpn_label);
12633 }
12634 }
12635 if (CHECK_FLAG(bgp->vpn_policy[afi].flags,
12636 BGP_VPN_POLICY_TOVPN_RD_SET)) {
12637 char buf[RD_ADDRSTRLEN];
12638 vty_out(vty, "%*srd vpn export %s\n", indent, "",
12639 prefix_rd2str(&bgp->vpn_policy[afi].tovpn_rd, buf,
12640 sizeof(buf)));
12641 }
12642 if (CHECK_FLAG(bgp->vpn_policy[afi].flags,
12643 BGP_VPN_POLICY_TOVPN_NEXTHOP_SET)) {
12644
12645 char buf[PREFIX_STRLEN];
12646 if (inet_ntop(bgp->vpn_policy[afi].tovpn_nexthop.family,
12647 &bgp->vpn_policy[afi].tovpn_nexthop.u.prefix, buf,
12648 sizeof(buf))) {
12649
12650 vty_out(vty, "%*snexthop vpn export %s\n",
12651 indent, "", buf);
12652 }
12653 }
12654 if (bgp->vpn_policy[afi].rtlist[BGP_VPN_POLICY_DIR_FROMVPN]
12655 && bgp->vpn_policy[afi].rtlist[BGP_VPN_POLICY_DIR_TOVPN]
12656 && ecommunity_cmp(
12657 bgp->vpn_policy[afi].rtlist[BGP_VPN_POLICY_DIR_FROMVPN],
12658 bgp->vpn_policy[afi].rtlist[BGP_VPN_POLICY_DIR_TOVPN])) {
12659
12660 char *b = ecommunity_ecom2str(
12661 bgp->vpn_policy[afi].rtlist[BGP_VPN_POLICY_DIR_TOVPN],
12662 ECOMMUNITY_FORMAT_ROUTE_MAP, ECOMMUNITY_ROUTE_TARGET);
12663 vty_out(vty, "%*srt vpn both %s\n", indent, "", b);
12664 XFREE(MTYPE_ECOMMUNITY_STR, b);
12665 } else {
12666 if (bgp->vpn_policy[afi].rtlist[BGP_VPN_POLICY_DIR_FROMVPN]) {
12667 char *b = ecommunity_ecom2str(
12668 bgp->vpn_policy[afi]
12669 .rtlist[BGP_VPN_POLICY_DIR_FROMVPN],
12670 ECOMMUNITY_FORMAT_ROUTE_MAP,
12671 ECOMMUNITY_ROUTE_TARGET);
12672 vty_out(vty, "%*srt vpn import %s\n", indent, "", b);
12673 XFREE(MTYPE_ECOMMUNITY_STR, b);
12674 }
12675 if (bgp->vpn_policy[afi].rtlist[BGP_VPN_POLICY_DIR_TOVPN]) {
12676 char *b = ecommunity_ecom2str(
12677 bgp->vpn_policy[afi]
12678 .rtlist[BGP_VPN_POLICY_DIR_TOVPN],
12679 ECOMMUNITY_FORMAT_ROUTE_MAP,
12680 ECOMMUNITY_ROUTE_TARGET);
12681 vty_out(vty, "%*srt vpn export %s\n", indent, "", b);
12682 XFREE(MTYPE_ECOMMUNITY_STR, b);
12683 }
12684 }
12685
12686 if (bgp->vpn_policy[afi].rmap_name[BGP_VPN_POLICY_DIR_TOVPN])
12687 vty_out(vty, "%*sroute-map vpn export %s\n", indent, "",
12688 bgp->vpn_policy[afi]
12689 .rmap_name[BGP_VPN_POLICY_DIR_TOVPN]);
12690
12691 if (bgp->vpn_policy[afi].import_redirect_rtlist) {
12692 char *b = ecommunity_ecom2str(
12693 bgp->vpn_policy[afi]
12694 .import_redirect_rtlist,
12695 ECOMMUNITY_FORMAT_ROUTE_MAP,
12696 ECOMMUNITY_ROUTE_TARGET);
12697
12698 vty_out(vty, "%*srt redirect import %s\n", indent, "", b);
12699 XFREE(MTYPE_ECOMMUNITY_STR, b);
12700 }
12701 }
12702
12703
12704 /* BGP node structure. */
12705 static struct cmd_node bgp_node = {
12706 BGP_NODE, "%s(config-router)# ", 1,
12707 };
12708
12709 static struct cmd_node bgp_ipv4_unicast_node = {
12710 BGP_IPV4_NODE, "%s(config-router-af)# ", 1,
12711 };
12712
12713 static struct cmd_node bgp_ipv4_multicast_node = {
12714 BGP_IPV4M_NODE, "%s(config-router-af)# ", 1,
12715 };
12716
12717 static struct cmd_node bgp_ipv4_labeled_unicast_node = {
12718 BGP_IPV4L_NODE, "%s(config-router-af)# ", 1,
12719 };
12720
12721 static struct cmd_node bgp_ipv6_unicast_node = {
12722 BGP_IPV6_NODE, "%s(config-router-af)# ", 1,
12723 };
12724
12725 static struct cmd_node bgp_ipv6_multicast_node = {
12726 BGP_IPV6M_NODE, "%s(config-router-af)# ", 1,
12727 };
12728
12729 static struct cmd_node bgp_ipv6_labeled_unicast_node = {
12730 BGP_IPV6L_NODE, "%s(config-router-af)# ", 1,
12731 };
12732
12733 static struct cmd_node bgp_vpnv4_node = {BGP_VPNV4_NODE,
12734 "%s(config-router-af)# ", 1};
12735
12736 static struct cmd_node bgp_vpnv6_node = {BGP_VPNV6_NODE,
12737 "%s(config-router-af-vpnv6)# ", 1};
12738
12739 static struct cmd_node bgp_evpn_node = {BGP_EVPN_NODE,
12740 "%s(config-router-evpn)# ", 1};
12741
12742 static struct cmd_node bgp_evpn_vni_node = {BGP_EVPN_VNI_NODE,
12743 "%s(config-router-af-vni)# ", 1};
12744
12745 static struct cmd_node bgp_flowspecv4_node = {BGP_FLOWSPECV4_NODE,
12746 "%s(config-router-af)# ", 1};
12747
12748 static struct cmd_node bgp_flowspecv6_node = {BGP_FLOWSPECV6_NODE,
12749 "%s(config-router-af-vpnv6)# ", 1};
12750
12751 static void community_list_vty(void);
12752
12753 static void bgp_ac_neighbor(vector comps, struct cmd_token *token)
12754 {
12755 struct bgp *bgp;
12756 struct peer *peer;
12757 struct listnode *lnbgp, *lnpeer;
12758
12759 for (ALL_LIST_ELEMENTS_RO(bm->bgp, lnbgp, bgp)) {
12760 for (ALL_LIST_ELEMENTS_RO(bgp->peer, lnpeer, peer)) {
12761 /* only provide suggestions on the appropriate input
12762 * token type,
12763 * they'll otherwise show up multiple times */
12764 enum cmd_token_type match_type;
12765 char *name = peer->host;
12766
12767 if (peer->conf_if) {
12768 match_type = VARIABLE_TKN;
12769 name = peer->conf_if;
12770 } else if (strchr(peer->host, ':'))
12771 match_type = IPV6_TKN;
12772 else
12773 match_type = IPV4_TKN;
12774
12775 if (token->type != match_type)
12776 continue;
12777
12778 vector_set(comps, XSTRDUP(MTYPE_COMPLETION, name));
12779 }
12780 }
12781 }
12782
12783 static const struct cmd_variable_handler bgp_var_neighbor[] = {
12784 {.varname = "neighbor", .completions = bgp_ac_neighbor},
12785 {.varname = "neighbors", .completions = bgp_ac_neighbor},
12786 {.varname = "peer", .completions = bgp_ac_neighbor},
12787 {.completions = NULL}};
12788
12789 static void bgp_ac_peergroup(vector comps, struct cmd_token *token)
12790 {
12791 struct bgp *bgp;
12792 struct peer_group *group;
12793 struct listnode *lnbgp, *lnpeer;
12794
12795 for (ALL_LIST_ELEMENTS_RO(bm->bgp, lnbgp, bgp)) {
12796 for (ALL_LIST_ELEMENTS_RO(bgp->group, lnpeer, group))
12797 vector_set(comps, XSTRDUP(MTYPE_COMPLETION,
12798 group->name));
12799 }
12800 }
12801
12802 static const struct cmd_variable_handler bgp_var_peergroup[] = {
12803 {.tokenname = "PGNAME", .completions = bgp_ac_peergroup},
12804 {.completions = NULL} };
12805
12806 void bgp_vty_init(void)
12807 {
12808 cmd_variable_handler_register(bgp_var_neighbor);
12809 cmd_variable_handler_register(bgp_var_peergroup);
12810
12811 /* Install bgp top node. */
12812 install_node(&bgp_node, bgp_config_write);
12813 install_node(&bgp_ipv4_unicast_node, NULL);
12814 install_node(&bgp_ipv4_multicast_node, NULL);
12815 install_node(&bgp_ipv4_labeled_unicast_node, NULL);
12816 install_node(&bgp_ipv6_unicast_node, NULL);
12817 install_node(&bgp_ipv6_multicast_node, NULL);
12818 install_node(&bgp_ipv6_labeled_unicast_node, NULL);
12819 install_node(&bgp_vpnv4_node, NULL);
12820 install_node(&bgp_vpnv6_node, NULL);
12821 install_node(&bgp_evpn_node, NULL);
12822 install_node(&bgp_evpn_vni_node, NULL);
12823 install_node(&bgp_flowspecv4_node, NULL);
12824 install_node(&bgp_flowspecv6_node, NULL);
12825
12826 /* Install default VTY commands to new nodes. */
12827 install_default(BGP_NODE);
12828 install_default(BGP_IPV4_NODE);
12829 install_default(BGP_IPV4M_NODE);
12830 install_default(BGP_IPV4L_NODE);
12831 install_default(BGP_IPV6_NODE);
12832 install_default(BGP_IPV6M_NODE);
12833 install_default(BGP_IPV6L_NODE);
12834 install_default(BGP_VPNV4_NODE);
12835 install_default(BGP_VPNV6_NODE);
12836 install_default(BGP_FLOWSPECV4_NODE);
12837 install_default(BGP_FLOWSPECV6_NODE);
12838 install_default(BGP_EVPN_NODE);
12839 install_default(BGP_EVPN_VNI_NODE);
12840
12841 /* "bgp local-mac" hidden commands. */
12842 install_element(CONFIG_NODE, &bgp_local_mac_cmd);
12843 install_element(CONFIG_NODE, &no_bgp_local_mac_cmd);
12844
12845 /* bgp route-map delay-timer commands. */
12846 install_element(CONFIG_NODE, &bgp_set_route_map_delay_timer_cmd);
12847 install_element(CONFIG_NODE, &no_bgp_set_route_map_delay_timer_cmd);
12848
12849 /* Dummy commands (Currently not supported) */
12850 install_element(BGP_NODE, &no_synchronization_cmd);
12851 install_element(BGP_NODE, &no_auto_summary_cmd);
12852
12853 /* "router bgp" commands. */
12854 install_element(CONFIG_NODE, &router_bgp_cmd);
12855
12856 /* "no router bgp" commands. */
12857 install_element(CONFIG_NODE, &no_router_bgp_cmd);
12858
12859 /* "bgp router-id" commands. */
12860 install_element(BGP_NODE, &bgp_router_id_cmd);
12861 install_element(BGP_NODE, &no_bgp_router_id_cmd);
12862
12863 /* "bgp cluster-id" commands. */
12864 install_element(BGP_NODE, &bgp_cluster_id_cmd);
12865 install_element(BGP_NODE, &no_bgp_cluster_id_cmd);
12866
12867 /* "bgp confederation" commands. */
12868 install_element(BGP_NODE, &bgp_confederation_identifier_cmd);
12869 install_element(BGP_NODE, &no_bgp_confederation_identifier_cmd);
12870
12871 /* "bgp confederation peers" commands. */
12872 install_element(BGP_NODE, &bgp_confederation_peers_cmd);
12873 install_element(BGP_NODE, &no_bgp_confederation_peers_cmd);
12874
12875 /* bgp max-med command */
12876 install_element(BGP_NODE, &bgp_maxmed_admin_cmd);
12877 install_element(BGP_NODE, &no_bgp_maxmed_admin_cmd);
12878 install_element(BGP_NODE, &bgp_maxmed_admin_medv_cmd);
12879 install_element(BGP_NODE, &bgp_maxmed_onstartup_cmd);
12880 install_element(BGP_NODE, &no_bgp_maxmed_onstartup_cmd);
12881
12882 /* bgp disable-ebgp-connected-nh-check */
12883 install_element(BGP_NODE, &bgp_disable_connected_route_check_cmd);
12884 install_element(BGP_NODE, &no_bgp_disable_connected_route_check_cmd);
12885
12886 /* bgp update-delay command */
12887 install_element(BGP_NODE, &bgp_update_delay_cmd);
12888 install_element(BGP_NODE, &no_bgp_update_delay_cmd);
12889 install_element(BGP_NODE, &bgp_update_delay_establish_wait_cmd);
12890
12891 install_element(BGP_NODE, &bgp_wpkt_quanta_cmd);
12892 install_element(BGP_NODE, &no_bgp_wpkt_quanta_cmd);
12893 install_element(BGP_NODE, &bgp_rpkt_quanta_cmd);
12894 install_element(BGP_NODE, &no_bgp_rpkt_quanta_cmd);
12895
12896 install_element(BGP_NODE, &bgp_coalesce_time_cmd);
12897 install_element(BGP_NODE, &no_bgp_coalesce_time_cmd);
12898
12899 /* "maximum-paths" commands. */
12900 install_element(BGP_NODE, &bgp_maxpaths_hidden_cmd);
12901 install_element(BGP_NODE, &no_bgp_maxpaths_hidden_cmd);
12902 install_element(BGP_IPV4_NODE, &bgp_maxpaths_cmd);
12903 install_element(BGP_IPV4_NODE, &no_bgp_maxpaths_cmd);
12904 install_element(BGP_IPV6_NODE, &bgp_maxpaths_cmd);
12905 install_element(BGP_IPV6_NODE, &no_bgp_maxpaths_cmd);
12906 install_element(BGP_NODE, &bgp_maxpaths_ibgp_hidden_cmd);
12907 install_element(BGP_NODE, &bgp_maxpaths_ibgp_cluster_hidden_cmd);
12908 install_element(BGP_NODE, &no_bgp_maxpaths_ibgp_hidden_cmd);
12909 install_element(BGP_IPV4_NODE, &bgp_maxpaths_ibgp_cmd);
12910 install_element(BGP_IPV4_NODE, &bgp_maxpaths_ibgp_cluster_cmd);
12911 install_element(BGP_IPV4_NODE, &no_bgp_maxpaths_ibgp_cmd);
12912 install_element(BGP_IPV6_NODE, &bgp_maxpaths_ibgp_cmd);
12913 install_element(BGP_IPV6_NODE, &bgp_maxpaths_ibgp_cluster_cmd);
12914 install_element(BGP_IPV6_NODE, &no_bgp_maxpaths_ibgp_cmd);
12915
12916 install_element(BGP_IPV6L_NODE, &bgp_maxpaths_cmd);
12917 install_element(BGP_IPV6L_NODE, &no_bgp_maxpaths_cmd);
12918 install_element(BGP_IPV6L_NODE, &bgp_maxpaths_ibgp_cmd);
12919 install_element(BGP_IPV6L_NODE, &bgp_maxpaths_ibgp_cluster_cmd);
12920 install_element(BGP_IPV6L_NODE, &no_bgp_maxpaths_ibgp_cmd);
12921
12922 /* "timers bgp" commands. */
12923 install_element(BGP_NODE, &bgp_timers_cmd);
12924 install_element(BGP_NODE, &no_bgp_timers_cmd);
12925
12926 /* route-map delay-timer commands - per instance for backwards compat.
12927 */
12928 install_element(BGP_NODE, &bgp_set_route_map_delay_timer_cmd);
12929 install_element(BGP_NODE, &no_bgp_set_route_map_delay_timer_cmd);
12930
12931 /* "bgp client-to-client reflection" commands */
12932 install_element(BGP_NODE, &no_bgp_client_to_client_reflection_cmd);
12933 install_element(BGP_NODE, &bgp_client_to_client_reflection_cmd);
12934
12935 /* "bgp always-compare-med" commands */
12936 install_element(BGP_NODE, &bgp_always_compare_med_cmd);
12937 install_element(BGP_NODE, &no_bgp_always_compare_med_cmd);
12938
12939 /* bgp ebgp-requires-policy */
12940 install_element(BGP_NODE, &bgp_ebgp_requires_policy_cmd);
12941 install_element(BGP_NODE, &no_bgp_ebgp_requires_policy_cmd);
12942
12943 /* "bgp deterministic-med" commands */
12944 install_element(BGP_NODE, &bgp_deterministic_med_cmd);
12945 install_element(BGP_NODE, &no_bgp_deterministic_med_cmd);
12946
12947 /* "bgp graceful-restart" commands */
12948 install_element(BGP_NODE, &bgp_graceful_restart_cmd);
12949 install_element(BGP_NODE, &no_bgp_graceful_restart_cmd);
12950 install_element(BGP_NODE, &bgp_graceful_restart_stalepath_time_cmd);
12951 install_element(BGP_NODE, &no_bgp_graceful_restart_stalepath_time_cmd);
12952 install_element(BGP_NODE, &bgp_graceful_restart_restart_time_cmd);
12953 install_element(BGP_NODE, &no_bgp_graceful_restart_restart_time_cmd);
12954
12955 install_element(BGP_NODE, &bgp_graceful_restart_preserve_fw_cmd);
12956 install_element(BGP_NODE, &no_bgp_graceful_restart_preserve_fw_cmd);
12957
12958 /* "bgp graceful-shutdown" commands */
12959 install_element(BGP_NODE, &bgp_graceful_shutdown_cmd);
12960 install_element(BGP_NODE, &no_bgp_graceful_shutdown_cmd);
12961
12962 /* "bgp fast-external-failover" commands */
12963 install_element(BGP_NODE, &bgp_fast_external_failover_cmd);
12964 install_element(BGP_NODE, &no_bgp_fast_external_failover_cmd);
12965
12966 /* "bgp bestpath compare-routerid" commands */
12967 install_element(BGP_NODE, &bgp_bestpath_compare_router_id_cmd);
12968 install_element(BGP_NODE, &no_bgp_bestpath_compare_router_id_cmd);
12969
12970 /* "bgp bestpath as-path ignore" commands */
12971 install_element(BGP_NODE, &bgp_bestpath_aspath_ignore_cmd);
12972 install_element(BGP_NODE, &no_bgp_bestpath_aspath_ignore_cmd);
12973
12974 /* "bgp bestpath as-path confed" commands */
12975 install_element(BGP_NODE, &bgp_bestpath_aspath_confed_cmd);
12976 install_element(BGP_NODE, &no_bgp_bestpath_aspath_confed_cmd);
12977
12978 /* "bgp bestpath as-path multipath-relax" commands */
12979 install_element(BGP_NODE, &bgp_bestpath_aspath_multipath_relax_cmd);
12980 install_element(BGP_NODE, &no_bgp_bestpath_aspath_multipath_relax_cmd);
12981
12982 /* "bgp log-neighbor-changes" commands */
12983 install_element(BGP_NODE, &bgp_log_neighbor_changes_cmd);
12984 install_element(BGP_NODE, &no_bgp_log_neighbor_changes_cmd);
12985
12986 /* "bgp bestpath med" commands */
12987 install_element(BGP_NODE, &bgp_bestpath_med_cmd);
12988 install_element(BGP_NODE, &no_bgp_bestpath_med_cmd);
12989
12990 /* "no bgp default ipv4-unicast" commands. */
12991 install_element(BGP_NODE, &no_bgp_default_ipv4_unicast_cmd);
12992 install_element(BGP_NODE, &bgp_default_ipv4_unicast_cmd);
12993
12994 /* "bgp network import-check" commands. */
12995 install_element(BGP_NODE, &bgp_network_import_check_cmd);
12996 install_element(BGP_NODE, &bgp_network_import_check_exact_cmd);
12997 install_element(BGP_NODE, &no_bgp_network_import_check_cmd);
12998
12999 /* "bgp default local-preference" commands. */
13000 install_element(BGP_NODE, &bgp_default_local_preference_cmd);
13001 install_element(BGP_NODE, &no_bgp_default_local_preference_cmd);
13002
13003 /* bgp default show-hostname */
13004 install_element(BGP_NODE, &bgp_default_show_hostname_cmd);
13005 install_element(BGP_NODE, &no_bgp_default_show_hostname_cmd);
13006
13007 /* "bgp default subgroup-pkt-queue-max" commands. */
13008 install_element(BGP_NODE, &bgp_default_subgroup_pkt_queue_max_cmd);
13009 install_element(BGP_NODE, &no_bgp_default_subgroup_pkt_queue_max_cmd);
13010
13011 /* bgp ibgp-allow-policy-mods command */
13012 install_element(BGP_NODE, &bgp_rr_allow_outbound_policy_cmd);
13013 install_element(BGP_NODE, &no_bgp_rr_allow_outbound_policy_cmd);
13014
13015 /* "bgp listen limit" commands. */
13016 install_element(BGP_NODE, &bgp_listen_limit_cmd);
13017 install_element(BGP_NODE, &no_bgp_listen_limit_cmd);
13018
13019 /* "bgp listen range" commands. */
13020 install_element(BGP_NODE, &bgp_listen_range_cmd);
13021 install_element(BGP_NODE, &no_bgp_listen_range_cmd);
13022
13023 /* "bgp default shutdown" command */
13024 install_element(BGP_NODE, &bgp_default_shutdown_cmd);
13025
13026 /* "neighbor remote-as" commands. */
13027 install_element(BGP_NODE, &neighbor_remote_as_cmd);
13028 install_element(BGP_NODE, &neighbor_interface_config_cmd);
13029 install_element(BGP_NODE, &neighbor_interface_config_v6only_cmd);
13030 install_element(BGP_NODE, &neighbor_interface_config_remote_as_cmd);
13031 install_element(BGP_NODE,
13032 &neighbor_interface_v6only_config_remote_as_cmd);
13033 install_element(BGP_NODE, &no_neighbor_cmd);
13034 install_element(BGP_NODE, &no_neighbor_interface_config_cmd);
13035
13036 /* "neighbor peer-group" commands. */
13037 install_element(BGP_NODE, &neighbor_peer_group_cmd);
13038 install_element(BGP_NODE, &no_neighbor_peer_group_cmd);
13039 install_element(BGP_NODE,
13040 &no_neighbor_interface_peer_group_remote_as_cmd);
13041
13042 /* "neighbor local-as" commands. */
13043 install_element(BGP_NODE, &neighbor_local_as_cmd);
13044 install_element(BGP_NODE, &neighbor_local_as_no_prepend_cmd);
13045 install_element(BGP_NODE, &neighbor_local_as_no_prepend_replace_as_cmd);
13046 install_element(BGP_NODE, &no_neighbor_local_as_cmd);
13047
13048 /* "neighbor solo" commands. */
13049 install_element(BGP_NODE, &neighbor_solo_cmd);
13050 install_element(BGP_NODE, &no_neighbor_solo_cmd);
13051
13052 /* "neighbor password" commands. */
13053 install_element(BGP_NODE, &neighbor_password_cmd);
13054 install_element(BGP_NODE, &no_neighbor_password_cmd);
13055
13056 /* "neighbor activate" commands. */
13057 install_element(BGP_NODE, &neighbor_activate_hidden_cmd);
13058 install_element(BGP_IPV4_NODE, &neighbor_activate_cmd);
13059 install_element(BGP_IPV4M_NODE, &neighbor_activate_cmd);
13060 install_element(BGP_IPV4L_NODE, &neighbor_activate_cmd);
13061 install_element(BGP_IPV6_NODE, &neighbor_activate_cmd);
13062 install_element(BGP_IPV6M_NODE, &neighbor_activate_cmd);
13063 install_element(BGP_IPV6L_NODE, &neighbor_activate_cmd);
13064 install_element(BGP_VPNV4_NODE, &neighbor_activate_cmd);
13065 install_element(BGP_VPNV6_NODE, &neighbor_activate_cmd);
13066 install_element(BGP_FLOWSPECV4_NODE, &neighbor_activate_cmd);
13067 install_element(BGP_FLOWSPECV6_NODE, &neighbor_activate_cmd);
13068 install_element(BGP_EVPN_NODE, &neighbor_activate_cmd);
13069
13070 /* "no neighbor activate" commands. */
13071 install_element(BGP_NODE, &no_neighbor_activate_hidden_cmd);
13072 install_element(BGP_IPV4_NODE, &no_neighbor_activate_cmd);
13073 install_element(BGP_IPV4M_NODE, &no_neighbor_activate_cmd);
13074 install_element(BGP_IPV4L_NODE, &no_neighbor_activate_cmd);
13075 install_element(BGP_IPV6_NODE, &no_neighbor_activate_cmd);
13076 install_element(BGP_IPV6M_NODE, &no_neighbor_activate_cmd);
13077 install_element(BGP_IPV6L_NODE, &no_neighbor_activate_cmd);
13078 install_element(BGP_VPNV4_NODE, &no_neighbor_activate_cmd);
13079 install_element(BGP_VPNV6_NODE, &no_neighbor_activate_cmd);
13080 install_element(BGP_FLOWSPECV4_NODE, &no_neighbor_activate_cmd);
13081 install_element(BGP_FLOWSPECV6_NODE, &no_neighbor_activate_cmd);
13082 install_element(BGP_EVPN_NODE, &no_neighbor_activate_cmd);
13083
13084 /* "neighbor peer-group" set commands. */
13085 install_element(BGP_NODE, &neighbor_set_peer_group_cmd);
13086 install_element(BGP_IPV4_NODE, &neighbor_set_peer_group_hidden_cmd);
13087 install_element(BGP_IPV4M_NODE, &neighbor_set_peer_group_hidden_cmd);
13088 install_element(BGP_IPV6_NODE, &neighbor_set_peer_group_hidden_cmd);
13089 install_element(BGP_IPV6M_NODE, &neighbor_set_peer_group_hidden_cmd);
13090 install_element(BGP_IPV6L_NODE, &neighbor_set_peer_group_hidden_cmd);
13091 install_element(BGP_VPNV4_NODE, &neighbor_set_peer_group_hidden_cmd);
13092 install_element(BGP_VPNV6_NODE, &neighbor_set_peer_group_hidden_cmd);
13093 install_element(BGP_FLOWSPECV4_NODE,
13094 &neighbor_set_peer_group_hidden_cmd);
13095 install_element(BGP_FLOWSPECV6_NODE,
13096 &neighbor_set_peer_group_hidden_cmd);
13097
13098 /* "no neighbor peer-group unset" commands. */
13099 install_element(BGP_NODE, &no_neighbor_set_peer_group_cmd);
13100 install_element(BGP_IPV4_NODE, &no_neighbor_set_peer_group_hidden_cmd);
13101 install_element(BGP_IPV4M_NODE, &no_neighbor_set_peer_group_hidden_cmd);
13102 install_element(BGP_IPV6_NODE, &no_neighbor_set_peer_group_hidden_cmd);
13103 install_element(BGP_IPV6M_NODE, &no_neighbor_set_peer_group_hidden_cmd);
13104 install_element(BGP_IPV6L_NODE, &no_neighbor_set_peer_group_hidden_cmd);
13105 install_element(BGP_VPNV4_NODE, &no_neighbor_set_peer_group_hidden_cmd);
13106 install_element(BGP_VPNV6_NODE, &no_neighbor_set_peer_group_hidden_cmd);
13107 install_element(BGP_FLOWSPECV4_NODE,
13108 &no_neighbor_set_peer_group_hidden_cmd);
13109 install_element(BGP_FLOWSPECV6_NODE,
13110 &no_neighbor_set_peer_group_hidden_cmd);
13111
13112 /* "neighbor softreconfiguration inbound" commands.*/
13113 install_element(BGP_NODE, &neighbor_soft_reconfiguration_hidden_cmd);
13114 install_element(BGP_NODE, &no_neighbor_soft_reconfiguration_hidden_cmd);
13115 install_element(BGP_IPV4_NODE, &neighbor_soft_reconfiguration_cmd);
13116 install_element(BGP_IPV4_NODE, &no_neighbor_soft_reconfiguration_cmd);
13117 install_element(BGP_IPV4L_NODE, &neighbor_soft_reconfiguration_cmd);
13118 install_element(BGP_IPV4L_NODE, &no_neighbor_soft_reconfiguration_cmd);
13119 install_element(BGP_IPV4M_NODE, &neighbor_soft_reconfiguration_cmd);
13120 install_element(BGP_IPV4M_NODE, &no_neighbor_soft_reconfiguration_cmd);
13121 install_element(BGP_IPV6_NODE, &neighbor_soft_reconfiguration_cmd);
13122 install_element(BGP_IPV6_NODE, &no_neighbor_soft_reconfiguration_cmd);
13123 install_element(BGP_IPV6M_NODE, &neighbor_soft_reconfiguration_cmd);
13124 install_element(BGP_IPV6M_NODE, &no_neighbor_soft_reconfiguration_cmd);
13125 install_element(BGP_IPV6L_NODE, &neighbor_soft_reconfiguration_cmd);
13126 install_element(BGP_IPV6L_NODE, &no_neighbor_soft_reconfiguration_cmd);
13127 install_element(BGP_VPNV4_NODE, &neighbor_soft_reconfiguration_cmd);
13128 install_element(BGP_VPNV4_NODE, &no_neighbor_soft_reconfiguration_cmd);
13129 install_element(BGP_VPNV6_NODE, &neighbor_soft_reconfiguration_cmd);
13130 install_element(BGP_VPNV6_NODE, &no_neighbor_soft_reconfiguration_cmd);
13131 install_element(BGP_FLOWSPECV4_NODE,
13132 &neighbor_soft_reconfiguration_cmd);
13133 install_element(BGP_FLOWSPECV4_NODE,
13134 &no_neighbor_soft_reconfiguration_cmd);
13135 install_element(BGP_FLOWSPECV6_NODE,
13136 &neighbor_soft_reconfiguration_cmd);
13137 install_element(BGP_FLOWSPECV6_NODE,
13138 &no_neighbor_soft_reconfiguration_cmd);
13139 install_element(BGP_EVPN_NODE, &neighbor_soft_reconfiguration_cmd);
13140 install_element(BGP_EVPN_NODE, &no_neighbor_soft_reconfiguration_cmd);
13141
13142 /* "neighbor attribute-unchanged" commands. */
13143 install_element(BGP_NODE, &neighbor_attr_unchanged_hidden_cmd);
13144 install_element(BGP_NODE, &no_neighbor_attr_unchanged_hidden_cmd);
13145 install_element(BGP_IPV4_NODE, &neighbor_attr_unchanged_cmd);
13146 install_element(BGP_IPV4_NODE, &no_neighbor_attr_unchanged_cmd);
13147 install_element(BGP_IPV4M_NODE, &neighbor_attr_unchanged_cmd);
13148 install_element(BGP_IPV4M_NODE, &no_neighbor_attr_unchanged_cmd);
13149 install_element(BGP_IPV4L_NODE, &neighbor_attr_unchanged_cmd);
13150 install_element(BGP_IPV4L_NODE, &no_neighbor_attr_unchanged_cmd);
13151 install_element(BGP_IPV6_NODE, &neighbor_attr_unchanged_cmd);
13152 install_element(BGP_IPV6_NODE, &no_neighbor_attr_unchanged_cmd);
13153 install_element(BGP_IPV6M_NODE, &neighbor_attr_unchanged_cmd);
13154 install_element(BGP_IPV6M_NODE, &no_neighbor_attr_unchanged_cmd);
13155 install_element(BGP_IPV6L_NODE, &neighbor_attr_unchanged_cmd);
13156 install_element(BGP_IPV6L_NODE, &no_neighbor_attr_unchanged_cmd);
13157 install_element(BGP_VPNV4_NODE, &neighbor_attr_unchanged_cmd);
13158 install_element(BGP_VPNV4_NODE, &no_neighbor_attr_unchanged_cmd);
13159 install_element(BGP_VPNV6_NODE, &neighbor_attr_unchanged_cmd);
13160 install_element(BGP_VPNV6_NODE, &no_neighbor_attr_unchanged_cmd);
13161
13162 install_element(BGP_EVPN_NODE, &neighbor_attr_unchanged_cmd);
13163 install_element(BGP_EVPN_NODE, &no_neighbor_attr_unchanged_cmd);
13164
13165 /* "nexthop-local unchanged" commands */
13166 install_element(BGP_IPV6_NODE, &neighbor_nexthop_local_unchanged_cmd);
13167 install_element(BGP_IPV6_NODE,
13168 &no_neighbor_nexthop_local_unchanged_cmd);
13169
13170 /* "neighbor next-hop-self" commands. */
13171 install_element(BGP_NODE, &neighbor_nexthop_self_hidden_cmd);
13172 install_element(BGP_NODE, &no_neighbor_nexthop_self_hidden_cmd);
13173 install_element(BGP_IPV4_NODE, &neighbor_nexthop_self_cmd);
13174 install_element(BGP_IPV4_NODE, &no_neighbor_nexthop_self_cmd);
13175 install_element(BGP_IPV4M_NODE, &neighbor_nexthop_self_cmd);
13176 install_element(BGP_IPV4M_NODE, &no_neighbor_nexthop_self_cmd);
13177 install_element(BGP_IPV4L_NODE, &neighbor_nexthop_self_cmd);
13178 install_element(BGP_IPV4L_NODE, &no_neighbor_nexthop_self_cmd);
13179 install_element(BGP_IPV6_NODE, &neighbor_nexthop_self_cmd);
13180 install_element(BGP_IPV6_NODE, &no_neighbor_nexthop_self_cmd);
13181 install_element(BGP_IPV6M_NODE, &neighbor_nexthop_self_cmd);
13182 install_element(BGP_IPV6M_NODE, &no_neighbor_nexthop_self_cmd);
13183 install_element(BGP_IPV6L_NODE, &neighbor_nexthop_self_cmd);
13184 install_element(BGP_IPV6L_NODE, &no_neighbor_nexthop_self_cmd);
13185 install_element(BGP_VPNV4_NODE, &neighbor_nexthop_self_cmd);
13186 install_element(BGP_VPNV4_NODE, &no_neighbor_nexthop_self_cmd);
13187 install_element(BGP_VPNV6_NODE, &neighbor_nexthop_self_cmd);
13188 install_element(BGP_VPNV6_NODE, &no_neighbor_nexthop_self_cmd);
13189 install_element(BGP_EVPN_NODE, &neighbor_nexthop_self_cmd);
13190 install_element(BGP_EVPN_NODE, &no_neighbor_nexthop_self_cmd);
13191
13192 /* "neighbor next-hop-self force" commands. */
13193 install_element(BGP_NODE, &neighbor_nexthop_self_force_hidden_cmd);
13194 install_element(BGP_NODE, &no_neighbor_nexthop_self_force_hidden_cmd);
13195 install_element(BGP_NODE, &neighbor_nexthop_self_all_hidden_cmd);
13196 install_element(BGP_NODE, &no_neighbor_nexthop_self_all_hidden_cmd);
13197 install_element(BGP_IPV4_NODE, &neighbor_nexthop_self_force_cmd);
13198 install_element(BGP_IPV4_NODE, &no_neighbor_nexthop_self_force_cmd);
13199 install_element(BGP_IPV4_NODE, &neighbor_nexthop_self_all_hidden_cmd);
13200 install_element(BGP_IPV4_NODE,
13201 &no_neighbor_nexthop_self_all_hidden_cmd);
13202 install_element(BGP_IPV4M_NODE, &neighbor_nexthop_self_force_cmd);
13203 install_element(BGP_IPV4M_NODE, &no_neighbor_nexthop_self_force_cmd);
13204 install_element(BGP_IPV4M_NODE, &neighbor_nexthop_self_all_hidden_cmd);
13205 install_element(BGP_IPV4M_NODE,
13206 &no_neighbor_nexthop_self_all_hidden_cmd);
13207 install_element(BGP_IPV4L_NODE, &neighbor_nexthop_self_force_cmd);
13208 install_element(BGP_IPV4L_NODE, &no_neighbor_nexthop_self_force_cmd);
13209 install_element(BGP_IPV4L_NODE, &neighbor_nexthop_self_all_hidden_cmd);
13210 install_element(BGP_IPV4L_NODE,
13211 &no_neighbor_nexthop_self_all_hidden_cmd);
13212 install_element(BGP_IPV6_NODE, &neighbor_nexthop_self_force_cmd);
13213 install_element(BGP_IPV6_NODE, &no_neighbor_nexthop_self_force_cmd);
13214 install_element(BGP_IPV6_NODE, &neighbor_nexthop_self_all_hidden_cmd);
13215 install_element(BGP_IPV6_NODE,
13216 &no_neighbor_nexthop_self_all_hidden_cmd);
13217 install_element(BGP_IPV6M_NODE, &neighbor_nexthop_self_force_cmd);
13218 install_element(BGP_IPV6M_NODE, &no_neighbor_nexthop_self_force_cmd);
13219 install_element(BGP_IPV6M_NODE, &neighbor_nexthop_self_all_hidden_cmd);
13220 install_element(BGP_IPV6M_NODE,
13221 &no_neighbor_nexthop_self_all_hidden_cmd);
13222 install_element(BGP_IPV6L_NODE, &neighbor_nexthop_self_force_cmd);
13223 install_element(BGP_IPV6L_NODE, &no_neighbor_nexthop_self_force_cmd);
13224 install_element(BGP_IPV6L_NODE, &neighbor_nexthop_self_all_hidden_cmd);
13225 install_element(BGP_IPV6L_NODE,
13226 &no_neighbor_nexthop_self_all_hidden_cmd);
13227 install_element(BGP_VPNV4_NODE, &neighbor_nexthop_self_force_cmd);
13228 install_element(BGP_VPNV4_NODE, &no_neighbor_nexthop_self_force_cmd);
13229 install_element(BGP_VPNV4_NODE, &neighbor_nexthop_self_all_hidden_cmd);
13230 install_element(BGP_VPNV4_NODE,
13231 &no_neighbor_nexthop_self_all_hidden_cmd);
13232 install_element(BGP_VPNV6_NODE, &neighbor_nexthop_self_force_cmd);
13233 install_element(BGP_VPNV6_NODE, &no_neighbor_nexthop_self_force_cmd);
13234 install_element(BGP_VPNV6_NODE, &neighbor_nexthop_self_all_hidden_cmd);
13235 install_element(BGP_VPNV6_NODE,
13236 &no_neighbor_nexthop_self_all_hidden_cmd);
13237
13238 /* "neighbor as-override" commands. */
13239 install_element(BGP_NODE, &neighbor_as_override_hidden_cmd);
13240 install_element(BGP_NODE, &no_neighbor_as_override_hidden_cmd);
13241 install_element(BGP_IPV4_NODE, &neighbor_as_override_cmd);
13242 install_element(BGP_IPV4_NODE, &no_neighbor_as_override_cmd);
13243 install_element(BGP_IPV4M_NODE, &neighbor_as_override_cmd);
13244 install_element(BGP_IPV4M_NODE, &no_neighbor_as_override_cmd);
13245 install_element(BGP_IPV4L_NODE, &neighbor_as_override_cmd);
13246 install_element(BGP_IPV4L_NODE, &no_neighbor_as_override_cmd);
13247 install_element(BGP_IPV6_NODE, &neighbor_as_override_cmd);
13248 install_element(BGP_IPV6_NODE, &no_neighbor_as_override_cmd);
13249 install_element(BGP_IPV6M_NODE, &neighbor_as_override_cmd);
13250 install_element(BGP_IPV6M_NODE, &no_neighbor_as_override_cmd);
13251 install_element(BGP_IPV6L_NODE, &neighbor_as_override_cmd);
13252 install_element(BGP_IPV6L_NODE, &no_neighbor_as_override_cmd);
13253 install_element(BGP_VPNV4_NODE, &neighbor_as_override_cmd);
13254 install_element(BGP_VPNV4_NODE, &no_neighbor_as_override_cmd);
13255 install_element(BGP_VPNV6_NODE, &neighbor_as_override_cmd);
13256 install_element(BGP_VPNV6_NODE, &no_neighbor_as_override_cmd);
13257
13258 /* "neighbor remove-private-AS" commands. */
13259 install_element(BGP_NODE, &neighbor_remove_private_as_hidden_cmd);
13260 install_element(BGP_NODE, &no_neighbor_remove_private_as_hidden_cmd);
13261 install_element(BGP_NODE, &neighbor_remove_private_as_all_hidden_cmd);
13262 install_element(BGP_NODE,
13263 &no_neighbor_remove_private_as_all_hidden_cmd);
13264 install_element(BGP_NODE,
13265 &neighbor_remove_private_as_replace_as_hidden_cmd);
13266 install_element(BGP_NODE,
13267 &no_neighbor_remove_private_as_replace_as_hidden_cmd);
13268 install_element(BGP_NODE,
13269 &neighbor_remove_private_as_all_replace_as_hidden_cmd);
13270 install_element(
13271 BGP_NODE,
13272 &no_neighbor_remove_private_as_all_replace_as_hidden_cmd);
13273 install_element(BGP_IPV4_NODE, &neighbor_remove_private_as_cmd);
13274 install_element(BGP_IPV4_NODE, &no_neighbor_remove_private_as_cmd);
13275 install_element(BGP_IPV4_NODE, &neighbor_remove_private_as_all_cmd);
13276 install_element(BGP_IPV4_NODE, &no_neighbor_remove_private_as_all_cmd);
13277 install_element(BGP_IPV4_NODE,
13278 &neighbor_remove_private_as_replace_as_cmd);
13279 install_element(BGP_IPV4_NODE,
13280 &no_neighbor_remove_private_as_replace_as_cmd);
13281 install_element(BGP_IPV4_NODE,
13282 &neighbor_remove_private_as_all_replace_as_cmd);
13283 install_element(BGP_IPV4_NODE,
13284 &no_neighbor_remove_private_as_all_replace_as_cmd);
13285 install_element(BGP_IPV4M_NODE, &neighbor_remove_private_as_cmd);
13286 install_element(BGP_IPV4M_NODE, &no_neighbor_remove_private_as_cmd);
13287 install_element(BGP_IPV4M_NODE, &neighbor_remove_private_as_all_cmd);
13288 install_element(BGP_IPV4M_NODE, &no_neighbor_remove_private_as_all_cmd);
13289 install_element(BGP_IPV4M_NODE,
13290 &neighbor_remove_private_as_replace_as_cmd);
13291 install_element(BGP_IPV4M_NODE,
13292 &no_neighbor_remove_private_as_replace_as_cmd);
13293 install_element(BGP_IPV4M_NODE,
13294 &neighbor_remove_private_as_all_replace_as_cmd);
13295 install_element(BGP_IPV4M_NODE,
13296 &no_neighbor_remove_private_as_all_replace_as_cmd);
13297 install_element(BGP_IPV4L_NODE, &neighbor_remove_private_as_cmd);
13298 install_element(BGP_IPV4L_NODE, &no_neighbor_remove_private_as_cmd);
13299 install_element(BGP_IPV4L_NODE, &neighbor_remove_private_as_all_cmd);
13300 install_element(BGP_IPV4L_NODE, &no_neighbor_remove_private_as_all_cmd);
13301 install_element(BGP_IPV4L_NODE,
13302 &neighbor_remove_private_as_replace_as_cmd);
13303 install_element(BGP_IPV4L_NODE,
13304 &no_neighbor_remove_private_as_replace_as_cmd);
13305 install_element(BGP_IPV4L_NODE,
13306 &neighbor_remove_private_as_all_replace_as_cmd);
13307 install_element(BGP_IPV4L_NODE,
13308 &no_neighbor_remove_private_as_all_replace_as_cmd);
13309 install_element(BGP_IPV6_NODE, &neighbor_remove_private_as_cmd);
13310 install_element(BGP_IPV6_NODE, &no_neighbor_remove_private_as_cmd);
13311 install_element(BGP_IPV6_NODE, &neighbor_remove_private_as_all_cmd);
13312 install_element(BGP_IPV6_NODE, &no_neighbor_remove_private_as_all_cmd);
13313 install_element(BGP_IPV6_NODE,
13314 &neighbor_remove_private_as_replace_as_cmd);
13315 install_element(BGP_IPV6_NODE,
13316 &no_neighbor_remove_private_as_replace_as_cmd);
13317 install_element(BGP_IPV6_NODE,
13318 &neighbor_remove_private_as_all_replace_as_cmd);
13319 install_element(BGP_IPV6_NODE,
13320 &no_neighbor_remove_private_as_all_replace_as_cmd);
13321 install_element(BGP_IPV6M_NODE, &neighbor_remove_private_as_cmd);
13322 install_element(BGP_IPV6M_NODE, &no_neighbor_remove_private_as_cmd);
13323 install_element(BGP_IPV6M_NODE, &neighbor_remove_private_as_all_cmd);
13324 install_element(BGP_IPV6M_NODE, &no_neighbor_remove_private_as_all_cmd);
13325 install_element(BGP_IPV6M_NODE,
13326 &neighbor_remove_private_as_replace_as_cmd);
13327 install_element(BGP_IPV6M_NODE,
13328 &no_neighbor_remove_private_as_replace_as_cmd);
13329 install_element(BGP_IPV6M_NODE,
13330 &neighbor_remove_private_as_all_replace_as_cmd);
13331 install_element(BGP_IPV6M_NODE,
13332 &no_neighbor_remove_private_as_all_replace_as_cmd);
13333 install_element(BGP_IPV6L_NODE, &neighbor_remove_private_as_cmd);
13334 install_element(BGP_IPV6L_NODE, &no_neighbor_remove_private_as_cmd);
13335 install_element(BGP_IPV6L_NODE, &neighbor_remove_private_as_all_cmd);
13336 install_element(BGP_IPV6L_NODE, &no_neighbor_remove_private_as_all_cmd);
13337 install_element(BGP_IPV6L_NODE,
13338 &neighbor_remove_private_as_replace_as_cmd);
13339 install_element(BGP_IPV6L_NODE,
13340 &no_neighbor_remove_private_as_replace_as_cmd);
13341 install_element(BGP_IPV6L_NODE,
13342 &neighbor_remove_private_as_all_replace_as_cmd);
13343 install_element(BGP_IPV6L_NODE,
13344 &no_neighbor_remove_private_as_all_replace_as_cmd);
13345 install_element(BGP_VPNV4_NODE, &neighbor_remove_private_as_cmd);
13346 install_element(BGP_VPNV4_NODE, &no_neighbor_remove_private_as_cmd);
13347 install_element(BGP_VPNV4_NODE, &neighbor_remove_private_as_all_cmd);
13348 install_element(BGP_VPNV4_NODE, &no_neighbor_remove_private_as_all_cmd);
13349 install_element(BGP_VPNV4_NODE,
13350 &neighbor_remove_private_as_replace_as_cmd);
13351 install_element(BGP_VPNV4_NODE,
13352 &no_neighbor_remove_private_as_replace_as_cmd);
13353 install_element(BGP_VPNV4_NODE,
13354 &neighbor_remove_private_as_all_replace_as_cmd);
13355 install_element(BGP_VPNV4_NODE,
13356 &no_neighbor_remove_private_as_all_replace_as_cmd);
13357 install_element(BGP_VPNV6_NODE, &neighbor_remove_private_as_cmd);
13358 install_element(BGP_VPNV6_NODE, &no_neighbor_remove_private_as_cmd);
13359 install_element(BGP_VPNV6_NODE, &neighbor_remove_private_as_all_cmd);
13360 install_element(BGP_VPNV6_NODE, &no_neighbor_remove_private_as_all_cmd);
13361 install_element(BGP_VPNV6_NODE,
13362 &neighbor_remove_private_as_replace_as_cmd);
13363 install_element(BGP_VPNV6_NODE,
13364 &no_neighbor_remove_private_as_replace_as_cmd);
13365 install_element(BGP_VPNV6_NODE,
13366 &neighbor_remove_private_as_all_replace_as_cmd);
13367 install_element(BGP_VPNV6_NODE,
13368 &no_neighbor_remove_private_as_all_replace_as_cmd);
13369
13370 /* "neighbor send-community" commands.*/
13371 install_element(BGP_NODE, &neighbor_send_community_hidden_cmd);
13372 install_element(BGP_NODE, &neighbor_send_community_type_hidden_cmd);
13373 install_element(BGP_NODE, &no_neighbor_send_community_hidden_cmd);
13374 install_element(BGP_NODE, &no_neighbor_send_community_type_hidden_cmd);
13375 install_element(BGP_IPV4_NODE, &neighbor_send_community_cmd);
13376 install_element(BGP_IPV4_NODE, &neighbor_send_community_type_cmd);
13377 install_element(BGP_IPV4_NODE, &no_neighbor_send_community_cmd);
13378 install_element(BGP_IPV4_NODE, &no_neighbor_send_community_type_cmd);
13379 install_element(BGP_IPV4M_NODE, &neighbor_send_community_cmd);
13380 install_element(BGP_IPV4M_NODE, &neighbor_send_community_type_cmd);
13381 install_element(BGP_IPV4M_NODE, &no_neighbor_send_community_cmd);
13382 install_element(BGP_IPV4M_NODE, &no_neighbor_send_community_type_cmd);
13383 install_element(BGP_IPV4L_NODE, &neighbor_send_community_cmd);
13384 install_element(BGP_IPV4L_NODE, &neighbor_send_community_type_cmd);
13385 install_element(BGP_IPV4L_NODE, &no_neighbor_send_community_cmd);
13386 install_element(BGP_IPV4L_NODE, &no_neighbor_send_community_type_cmd);
13387 install_element(BGP_IPV6_NODE, &neighbor_send_community_cmd);
13388 install_element(BGP_IPV6_NODE, &neighbor_send_community_type_cmd);
13389 install_element(BGP_IPV6_NODE, &no_neighbor_send_community_cmd);
13390 install_element(BGP_IPV6_NODE, &no_neighbor_send_community_type_cmd);
13391 install_element(BGP_IPV6M_NODE, &neighbor_send_community_cmd);
13392 install_element(BGP_IPV6M_NODE, &neighbor_send_community_type_cmd);
13393 install_element(BGP_IPV6M_NODE, &no_neighbor_send_community_cmd);
13394 install_element(BGP_IPV6M_NODE, &no_neighbor_send_community_type_cmd);
13395 install_element(BGP_IPV6L_NODE, &neighbor_send_community_cmd);
13396 install_element(BGP_IPV6L_NODE, &neighbor_send_community_type_cmd);
13397 install_element(BGP_IPV6L_NODE, &no_neighbor_send_community_cmd);
13398 install_element(BGP_IPV6L_NODE, &no_neighbor_send_community_type_cmd);
13399 install_element(BGP_VPNV4_NODE, &neighbor_send_community_cmd);
13400 install_element(BGP_VPNV4_NODE, &neighbor_send_community_type_cmd);
13401 install_element(BGP_VPNV4_NODE, &no_neighbor_send_community_cmd);
13402 install_element(BGP_VPNV4_NODE, &no_neighbor_send_community_type_cmd);
13403 install_element(BGP_VPNV6_NODE, &neighbor_send_community_cmd);
13404 install_element(BGP_VPNV6_NODE, &neighbor_send_community_type_cmd);
13405 install_element(BGP_VPNV6_NODE, &no_neighbor_send_community_cmd);
13406 install_element(BGP_VPNV6_NODE, &no_neighbor_send_community_type_cmd);
13407
13408 /* "neighbor route-reflector" commands.*/
13409 install_element(BGP_NODE, &neighbor_route_reflector_client_hidden_cmd);
13410 install_element(BGP_NODE,
13411 &no_neighbor_route_reflector_client_hidden_cmd);
13412 install_element(BGP_IPV4_NODE, &neighbor_route_reflector_client_cmd);
13413 install_element(BGP_IPV4_NODE, &no_neighbor_route_reflector_client_cmd);
13414 install_element(BGP_IPV4M_NODE, &neighbor_route_reflector_client_cmd);
13415 install_element(BGP_IPV4M_NODE,
13416 &no_neighbor_route_reflector_client_cmd);
13417 install_element(BGP_IPV4L_NODE, &neighbor_route_reflector_client_cmd);
13418 install_element(BGP_IPV4L_NODE,
13419 &no_neighbor_route_reflector_client_cmd);
13420 install_element(BGP_IPV6_NODE, &neighbor_route_reflector_client_cmd);
13421 install_element(BGP_IPV6_NODE, &no_neighbor_route_reflector_client_cmd);
13422 install_element(BGP_IPV6M_NODE, &neighbor_route_reflector_client_cmd);
13423 install_element(BGP_IPV6M_NODE,
13424 &no_neighbor_route_reflector_client_cmd);
13425 install_element(BGP_IPV6L_NODE, &neighbor_route_reflector_client_cmd);
13426 install_element(BGP_IPV6L_NODE,
13427 &no_neighbor_route_reflector_client_cmd);
13428 install_element(BGP_VPNV4_NODE, &neighbor_route_reflector_client_cmd);
13429 install_element(BGP_VPNV4_NODE,
13430 &no_neighbor_route_reflector_client_cmd);
13431 install_element(BGP_VPNV6_NODE, &neighbor_route_reflector_client_cmd);
13432 install_element(BGP_VPNV6_NODE,
13433 &no_neighbor_route_reflector_client_cmd);
13434 install_element(BGP_FLOWSPECV4_NODE,
13435 &neighbor_route_reflector_client_cmd);
13436 install_element(BGP_FLOWSPECV4_NODE,
13437 &no_neighbor_route_reflector_client_cmd);
13438 install_element(BGP_FLOWSPECV6_NODE,
13439 &neighbor_route_reflector_client_cmd);
13440 install_element(BGP_FLOWSPECV6_NODE,
13441 &no_neighbor_route_reflector_client_cmd);
13442 install_element(BGP_EVPN_NODE, &neighbor_route_reflector_client_cmd);
13443 install_element(BGP_EVPN_NODE, &no_neighbor_route_reflector_client_cmd);
13444
13445 /* "neighbor route-server" commands.*/
13446 install_element(BGP_NODE, &neighbor_route_server_client_hidden_cmd);
13447 install_element(BGP_NODE, &no_neighbor_route_server_client_hidden_cmd);
13448 install_element(BGP_IPV4_NODE, &neighbor_route_server_client_cmd);
13449 install_element(BGP_IPV4_NODE, &no_neighbor_route_server_client_cmd);
13450 install_element(BGP_IPV4M_NODE, &neighbor_route_server_client_cmd);
13451 install_element(BGP_IPV4M_NODE, &no_neighbor_route_server_client_cmd);
13452 install_element(BGP_IPV4L_NODE, &neighbor_route_server_client_cmd);
13453 install_element(BGP_IPV4L_NODE, &no_neighbor_route_server_client_cmd);
13454 install_element(BGP_IPV6_NODE, &neighbor_route_server_client_cmd);
13455 install_element(BGP_IPV6_NODE, &no_neighbor_route_server_client_cmd);
13456 install_element(BGP_IPV6M_NODE, &neighbor_route_server_client_cmd);
13457 install_element(BGP_IPV6M_NODE, &no_neighbor_route_server_client_cmd);
13458 install_element(BGP_IPV6L_NODE, &neighbor_route_server_client_cmd);
13459 install_element(BGP_IPV6L_NODE, &no_neighbor_route_server_client_cmd);
13460 install_element(BGP_VPNV4_NODE, &neighbor_route_server_client_cmd);
13461 install_element(BGP_VPNV4_NODE, &no_neighbor_route_server_client_cmd);
13462 install_element(BGP_VPNV6_NODE, &neighbor_route_server_client_cmd);
13463 install_element(BGP_VPNV6_NODE, &no_neighbor_route_server_client_cmd);
13464 install_element(BGP_EVPN_NODE, &neighbor_route_server_client_cmd);
13465 install_element(BGP_EVPN_NODE, &no_neighbor_route_server_client_cmd);
13466 install_element(BGP_FLOWSPECV4_NODE, &neighbor_route_server_client_cmd);
13467 install_element(BGP_FLOWSPECV4_NODE,
13468 &no_neighbor_route_server_client_cmd);
13469 install_element(BGP_FLOWSPECV6_NODE, &neighbor_route_server_client_cmd);
13470 install_element(BGP_FLOWSPECV6_NODE,
13471 &no_neighbor_route_server_client_cmd);
13472
13473 /* "neighbor addpath-tx-all-paths" commands.*/
13474 install_element(BGP_NODE, &neighbor_addpath_tx_all_paths_hidden_cmd);
13475 install_element(BGP_NODE, &no_neighbor_addpath_tx_all_paths_hidden_cmd);
13476 install_element(BGP_IPV4_NODE, &neighbor_addpath_tx_all_paths_cmd);
13477 install_element(BGP_IPV4_NODE, &no_neighbor_addpath_tx_all_paths_cmd);
13478 install_element(BGP_IPV4M_NODE, &neighbor_addpath_tx_all_paths_cmd);
13479 install_element(BGP_IPV4M_NODE, &no_neighbor_addpath_tx_all_paths_cmd);
13480 install_element(BGP_IPV4L_NODE, &neighbor_addpath_tx_all_paths_cmd);
13481 install_element(BGP_IPV4L_NODE, &no_neighbor_addpath_tx_all_paths_cmd);
13482 install_element(BGP_IPV6_NODE, &neighbor_addpath_tx_all_paths_cmd);
13483 install_element(BGP_IPV6_NODE, &no_neighbor_addpath_tx_all_paths_cmd);
13484 install_element(BGP_IPV6M_NODE, &neighbor_addpath_tx_all_paths_cmd);
13485 install_element(BGP_IPV6M_NODE, &no_neighbor_addpath_tx_all_paths_cmd);
13486 install_element(BGP_IPV6L_NODE, &neighbor_addpath_tx_all_paths_cmd);
13487 install_element(BGP_IPV6L_NODE, &no_neighbor_addpath_tx_all_paths_cmd);
13488 install_element(BGP_VPNV4_NODE, &neighbor_addpath_tx_all_paths_cmd);
13489 install_element(BGP_VPNV4_NODE, &no_neighbor_addpath_tx_all_paths_cmd);
13490 install_element(BGP_VPNV6_NODE, &neighbor_addpath_tx_all_paths_cmd);
13491 install_element(BGP_VPNV6_NODE, &no_neighbor_addpath_tx_all_paths_cmd);
13492
13493 /* "neighbor addpath-tx-bestpath-per-AS" commands.*/
13494 install_element(BGP_NODE,
13495 &neighbor_addpath_tx_bestpath_per_as_hidden_cmd);
13496 install_element(BGP_NODE,
13497 &no_neighbor_addpath_tx_bestpath_per_as_hidden_cmd);
13498 install_element(BGP_IPV4_NODE,
13499 &neighbor_addpath_tx_bestpath_per_as_cmd);
13500 install_element(BGP_IPV4_NODE,
13501 &no_neighbor_addpath_tx_bestpath_per_as_cmd);
13502 install_element(BGP_IPV4M_NODE,
13503 &neighbor_addpath_tx_bestpath_per_as_cmd);
13504 install_element(BGP_IPV4M_NODE,
13505 &no_neighbor_addpath_tx_bestpath_per_as_cmd);
13506 install_element(BGP_IPV4L_NODE,
13507 &neighbor_addpath_tx_bestpath_per_as_cmd);
13508 install_element(BGP_IPV4L_NODE,
13509 &no_neighbor_addpath_tx_bestpath_per_as_cmd);
13510 install_element(BGP_IPV6_NODE,
13511 &neighbor_addpath_tx_bestpath_per_as_cmd);
13512 install_element(BGP_IPV6_NODE,
13513 &no_neighbor_addpath_tx_bestpath_per_as_cmd);
13514 install_element(BGP_IPV6M_NODE,
13515 &neighbor_addpath_tx_bestpath_per_as_cmd);
13516 install_element(BGP_IPV6M_NODE,
13517 &no_neighbor_addpath_tx_bestpath_per_as_cmd);
13518 install_element(BGP_IPV6L_NODE,
13519 &neighbor_addpath_tx_bestpath_per_as_cmd);
13520 install_element(BGP_IPV6L_NODE,
13521 &no_neighbor_addpath_tx_bestpath_per_as_cmd);
13522 install_element(BGP_VPNV4_NODE,
13523 &neighbor_addpath_tx_bestpath_per_as_cmd);
13524 install_element(BGP_VPNV4_NODE,
13525 &no_neighbor_addpath_tx_bestpath_per_as_cmd);
13526 install_element(BGP_VPNV6_NODE,
13527 &neighbor_addpath_tx_bestpath_per_as_cmd);
13528 install_element(BGP_VPNV6_NODE,
13529 &no_neighbor_addpath_tx_bestpath_per_as_cmd);
13530
13531 /* "neighbor passive" commands. */
13532 install_element(BGP_NODE, &neighbor_passive_cmd);
13533 install_element(BGP_NODE, &no_neighbor_passive_cmd);
13534
13535
13536 /* "neighbor shutdown" commands. */
13537 install_element(BGP_NODE, &neighbor_shutdown_cmd);
13538 install_element(BGP_NODE, &no_neighbor_shutdown_cmd);
13539 install_element(BGP_NODE, &neighbor_shutdown_msg_cmd);
13540 install_element(BGP_NODE, &no_neighbor_shutdown_msg_cmd);
13541
13542 /* "neighbor capability extended-nexthop" commands.*/
13543 install_element(BGP_NODE, &neighbor_capability_enhe_cmd);
13544 install_element(BGP_NODE, &no_neighbor_capability_enhe_cmd);
13545
13546 /* "neighbor capability orf prefix-list" commands.*/
13547 install_element(BGP_NODE, &neighbor_capability_orf_prefix_hidden_cmd);
13548 install_element(BGP_NODE,
13549 &no_neighbor_capability_orf_prefix_hidden_cmd);
13550 install_element(BGP_IPV4_NODE, &neighbor_capability_orf_prefix_cmd);
13551 install_element(BGP_IPV4_NODE, &no_neighbor_capability_orf_prefix_cmd);
13552 install_element(BGP_IPV4M_NODE, &neighbor_capability_orf_prefix_cmd);
13553 install_element(BGP_IPV4M_NODE, &no_neighbor_capability_orf_prefix_cmd);
13554 install_element(BGP_IPV4L_NODE, &neighbor_capability_orf_prefix_cmd);
13555 install_element(BGP_IPV4L_NODE, &no_neighbor_capability_orf_prefix_cmd);
13556 install_element(BGP_IPV6_NODE, &neighbor_capability_orf_prefix_cmd);
13557 install_element(BGP_IPV6_NODE, &no_neighbor_capability_orf_prefix_cmd);
13558 install_element(BGP_IPV6M_NODE, &neighbor_capability_orf_prefix_cmd);
13559 install_element(BGP_IPV6M_NODE, &no_neighbor_capability_orf_prefix_cmd);
13560 install_element(BGP_IPV6L_NODE, &neighbor_capability_orf_prefix_cmd);
13561 install_element(BGP_IPV6L_NODE, &no_neighbor_capability_orf_prefix_cmd);
13562
13563 /* "neighbor capability dynamic" commands.*/
13564 install_element(BGP_NODE, &neighbor_capability_dynamic_cmd);
13565 install_element(BGP_NODE, &no_neighbor_capability_dynamic_cmd);
13566
13567 /* "neighbor dont-capability-negotiate" commands. */
13568 install_element(BGP_NODE, &neighbor_dont_capability_negotiate_cmd);
13569 install_element(BGP_NODE, &no_neighbor_dont_capability_negotiate_cmd);
13570
13571 /* "neighbor ebgp-multihop" commands. */
13572 install_element(BGP_NODE, &neighbor_ebgp_multihop_cmd);
13573 install_element(BGP_NODE, &neighbor_ebgp_multihop_ttl_cmd);
13574 install_element(BGP_NODE, &no_neighbor_ebgp_multihop_cmd);
13575
13576 /* "neighbor disable-connected-check" commands. */
13577 install_element(BGP_NODE, &neighbor_disable_connected_check_cmd);
13578 install_element(BGP_NODE, &no_neighbor_disable_connected_check_cmd);
13579
13580 /* "neighbor enforce-first-as" commands. */
13581 install_element(BGP_NODE, &neighbor_enforce_first_as_cmd);
13582 install_element(BGP_NODE, &no_neighbor_enforce_first_as_cmd);
13583
13584 /* "neighbor description" commands. */
13585 install_element(BGP_NODE, &neighbor_description_cmd);
13586 install_element(BGP_NODE, &no_neighbor_description_cmd);
13587 install_element(BGP_NODE, &no_neighbor_description_comment_cmd);
13588
13589 /* "neighbor update-source" commands. "*/
13590 install_element(BGP_NODE, &neighbor_update_source_cmd);
13591 install_element(BGP_NODE, &no_neighbor_update_source_cmd);
13592
13593 /* "neighbor default-originate" commands. */
13594 install_element(BGP_NODE, &neighbor_default_originate_hidden_cmd);
13595 install_element(BGP_NODE, &neighbor_default_originate_rmap_hidden_cmd);
13596 install_element(BGP_NODE, &no_neighbor_default_originate_hidden_cmd);
13597 install_element(BGP_IPV4_NODE, &neighbor_default_originate_cmd);
13598 install_element(BGP_IPV4_NODE, &neighbor_default_originate_rmap_cmd);
13599 install_element(BGP_IPV4_NODE, &no_neighbor_default_originate_cmd);
13600 install_element(BGP_IPV4M_NODE, &neighbor_default_originate_cmd);
13601 install_element(BGP_IPV4M_NODE, &neighbor_default_originate_rmap_cmd);
13602 install_element(BGP_IPV4M_NODE, &no_neighbor_default_originate_cmd);
13603 install_element(BGP_IPV4L_NODE, &neighbor_default_originate_cmd);
13604 install_element(BGP_IPV4L_NODE, &neighbor_default_originate_rmap_cmd);
13605 install_element(BGP_IPV4L_NODE, &no_neighbor_default_originate_cmd);
13606 install_element(BGP_IPV6_NODE, &neighbor_default_originate_cmd);
13607 install_element(BGP_IPV6_NODE, &neighbor_default_originate_rmap_cmd);
13608 install_element(BGP_IPV6_NODE, &no_neighbor_default_originate_cmd);
13609 install_element(BGP_IPV6M_NODE, &neighbor_default_originate_cmd);
13610 install_element(BGP_IPV6M_NODE, &neighbor_default_originate_rmap_cmd);
13611 install_element(BGP_IPV6M_NODE, &no_neighbor_default_originate_cmd);
13612 install_element(BGP_IPV6L_NODE, &neighbor_default_originate_cmd);
13613 install_element(BGP_IPV6L_NODE, &neighbor_default_originate_rmap_cmd);
13614 install_element(BGP_IPV6L_NODE, &no_neighbor_default_originate_cmd);
13615
13616 /* "neighbor port" commands. */
13617 install_element(BGP_NODE, &neighbor_port_cmd);
13618 install_element(BGP_NODE, &no_neighbor_port_cmd);
13619
13620 /* "neighbor weight" commands. */
13621 install_element(BGP_NODE, &neighbor_weight_hidden_cmd);
13622 install_element(BGP_NODE, &no_neighbor_weight_hidden_cmd);
13623
13624 install_element(BGP_IPV4_NODE, &neighbor_weight_cmd);
13625 install_element(BGP_IPV4_NODE, &no_neighbor_weight_cmd);
13626 install_element(BGP_IPV4M_NODE, &neighbor_weight_cmd);
13627 install_element(BGP_IPV4M_NODE, &no_neighbor_weight_cmd);
13628 install_element(BGP_IPV4L_NODE, &neighbor_weight_cmd);
13629 install_element(BGP_IPV4L_NODE, &no_neighbor_weight_cmd);
13630 install_element(BGP_IPV6_NODE, &neighbor_weight_cmd);
13631 install_element(BGP_IPV6_NODE, &no_neighbor_weight_cmd);
13632 install_element(BGP_IPV6M_NODE, &neighbor_weight_cmd);
13633 install_element(BGP_IPV6M_NODE, &no_neighbor_weight_cmd);
13634 install_element(BGP_IPV6L_NODE, &neighbor_weight_cmd);
13635 install_element(BGP_IPV6L_NODE, &no_neighbor_weight_cmd);
13636 install_element(BGP_VPNV4_NODE, &neighbor_weight_cmd);
13637 install_element(BGP_VPNV4_NODE, &no_neighbor_weight_cmd);
13638 install_element(BGP_VPNV6_NODE, &neighbor_weight_cmd);
13639 install_element(BGP_VPNV6_NODE, &no_neighbor_weight_cmd);
13640
13641 /* "neighbor override-capability" commands. */
13642 install_element(BGP_NODE, &neighbor_override_capability_cmd);
13643 install_element(BGP_NODE, &no_neighbor_override_capability_cmd);
13644
13645 /* "neighbor strict-capability-match" commands. */
13646 install_element(BGP_NODE, &neighbor_strict_capability_cmd);
13647 install_element(BGP_NODE, &no_neighbor_strict_capability_cmd);
13648
13649 /* "neighbor timers" commands. */
13650 install_element(BGP_NODE, &neighbor_timers_cmd);
13651 install_element(BGP_NODE, &no_neighbor_timers_cmd);
13652
13653 /* "neighbor timers connect" commands. */
13654 install_element(BGP_NODE, &neighbor_timers_connect_cmd);
13655 install_element(BGP_NODE, &no_neighbor_timers_connect_cmd);
13656
13657 /* "neighbor advertisement-interval" commands. */
13658 install_element(BGP_NODE, &neighbor_advertise_interval_cmd);
13659 install_element(BGP_NODE, &no_neighbor_advertise_interval_cmd);
13660
13661 /* "neighbor interface" commands. */
13662 install_element(BGP_NODE, &neighbor_interface_cmd);
13663 install_element(BGP_NODE, &no_neighbor_interface_cmd);
13664
13665 /* "neighbor distribute" commands. */
13666 install_element(BGP_NODE, &neighbor_distribute_list_hidden_cmd);
13667 install_element(BGP_NODE, &no_neighbor_distribute_list_hidden_cmd);
13668 install_element(BGP_IPV4_NODE, &neighbor_distribute_list_cmd);
13669 install_element(BGP_IPV4_NODE, &no_neighbor_distribute_list_cmd);
13670 install_element(BGP_IPV4M_NODE, &neighbor_distribute_list_cmd);
13671 install_element(BGP_IPV4M_NODE, &no_neighbor_distribute_list_cmd);
13672 install_element(BGP_IPV4L_NODE, &neighbor_distribute_list_cmd);
13673 install_element(BGP_IPV4L_NODE, &no_neighbor_distribute_list_cmd);
13674 install_element(BGP_IPV6_NODE, &neighbor_distribute_list_cmd);
13675 install_element(BGP_IPV6_NODE, &no_neighbor_distribute_list_cmd);
13676 install_element(BGP_IPV6M_NODE, &neighbor_distribute_list_cmd);
13677 install_element(BGP_IPV6M_NODE, &no_neighbor_distribute_list_cmd);
13678 install_element(BGP_IPV6L_NODE, &neighbor_distribute_list_cmd);
13679 install_element(BGP_IPV6L_NODE, &no_neighbor_distribute_list_cmd);
13680 install_element(BGP_VPNV4_NODE, &neighbor_distribute_list_cmd);
13681 install_element(BGP_VPNV4_NODE, &no_neighbor_distribute_list_cmd);
13682 install_element(BGP_VPNV6_NODE, &neighbor_distribute_list_cmd);
13683 install_element(BGP_VPNV6_NODE, &no_neighbor_distribute_list_cmd);
13684
13685 /* "neighbor prefix-list" commands. */
13686 install_element(BGP_NODE, &neighbor_prefix_list_hidden_cmd);
13687 install_element(BGP_NODE, &no_neighbor_prefix_list_hidden_cmd);
13688 install_element(BGP_IPV4_NODE, &neighbor_prefix_list_cmd);
13689 install_element(BGP_IPV4_NODE, &no_neighbor_prefix_list_cmd);
13690 install_element(BGP_IPV4M_NODE, &neighbor_prefix_list_cmd);
13691 install_element(BGP_IPV4M_NODE, &no_neighbor_prefix_list_cmd);
13692 install_element(BGP_IPV4L_NODE, &neighbor_prefix_list_cmd);
13693 install_element(BGP_IPV4L_NODE, &no_neighbor_prefix_list_cmd);
13694 install_element(BGP_IPV6_NODE, &neighbor_prefix_list_cmd);
13695 install_element(BGP_IPV6_NODE, &no_neighbor_prefix_list_cmd);
13696 install_element(BGP_IPV6M_NODE, &neighbor_prefix_list_cmd);
13697 install_element(BGP_IPV6M_NODE, &no_neighbor_prefix_list_cmd);
13698 install_element(BGP_IPV6L_NODE, &neighbor_prefix_list_cmd);
13699 install_element(BGP_IPV6L_NODE, &no_neighbor_prefix_list_cmd);
13700 install_element(BGP_VPNV4_NODE, &neighbor_prefix_list_cmd);
13701 install_element(BGP_VPNV4_NODE, &no_neighbor_prefix_list_cmd);
13702 install_element(BGP_VPNV6_NODE, &neighbor_prefix_list_cmd);
13703 install_element(BGP_VPNV6_NODE, &no_neighbor_prefix_list_cmd);
13704 install_element(BGP_FLOWSPECV4_NODE, &neighbor_prefix_list_cmd);
13705 install_element(BGP_FLOWSPECV4_NODE, &no_neighbor_prefix_list_cmd);
13706 install_element(BGP_FLOWSPECV6_NODE, &neighbor_prefix_list_cmd);
13707 install_element(BGP_FLOWSPECV6_NODE, &no_neighbor_prefix_list_cmd);
13708
13709 /* "neighbor filter-list" commands. */
13710 install_element(BGP_NODE, &neighbor_filter_list_hidden_cmd);
13711 install_element(BGP_NODE, &no_neighbor_filter_list_hidden_cmd);
13712 install_element(BGP_IPV4_NODE, &neighbor_filter_list_cmd);
13713 install_element(BGP_IPV4_NODE, &no_neighbor_filter_list_cmd);
13714 install_element(BGP_IPV4M_NODE, &neighbor_filter_list_cmd);
13715 install_element(BGP_IPV4M_NODE, &no_neighbor_filter_list_cmd);
13716 install_element(BGP_IPV4L_NODE, &neighbor_filter_list_cmd);
13717 install_element(BGP_IPV4L_NODE, &no_neighbor_filter_list_cmd);
13718 install_element(BGP_IPV6_NODE, &neighbor_filter_list_cmd);
13719 install_element(BGP_IPV6_NODE, &no_neighbor_filter_list_cmd);
13720 install_element(BGP_IPV6M_NODE, &neighbor_filter_list_cmd);
13721 install_element(BGP_IPV6M_NODE, &no_neighbor_filter_list_cmd);
13722 install_element(BGP_IPV6L_NODE, &neighbor_filter_list_cmd);
13723 install_element(BGP_IPV6L_NODE, &no_neighbor_filter_list_cmd);
13724 install_element(BGP_VPNV4_NODE, &neighbor_filter_list_cmd);
13725 install_element(BGP_VPNV4_NODE, &no_neighbor_filter_list_cmd);
13726 install_element(BGP_VPNV6_NODE, &neighbor_filter_list_cmd);
13727 install_element(BGP_VPNV6_NODE, &no_neighbor_filter_list_cmd);
13728 install_element(BGP_FLOWSPECV4_NODE, &neighbor_filter_list_cmd);
13729 install_element(BGP_FLOWSPECV4_NODE, &no_neighbor_filter_list_cmd);
13730 install_element(BGP_FLOWSPECV6_NODE, &neighbor_filter_list_cmd);
13731 install_element(BGP_FLOWSPECV6_NODE, &no_neighbor_filter_list_cmd);
13732
13733 /* "neighbor route-map" commands. */
13734 install_element(BGP_NODE, &neighbor_route_map_hidden_cmd);
13735 install_element(BGP_NODE, &no_neighbor_route_map_hidden_cmd);
13736 install_element(BGP_IPV4_NODE, &neighbor_route_map_cmd);
13737 install_element(BGP_IPV4_NODE, &no_neighbor_route_map_cmd);
13738 install_element(BGP_IPV4M_NODE, &neighbor_route_map_cmd);
13739 install_element(BGP_IPV4M_NODE, &no_neighbor_route_map_cmd);
13740 install_element(BGP_IPV4L_NODE, &neighbor_route_map_cmd);
13741 install_element(BGP_IPV4L_NODE, &no_neighbor_route_map_cmd);
13742 install_element(BGP_IPV6_NODE, &neighbor_route_map_cmd);
13743 install_element(BGP_IPV6_NODE, &no_neighbor_route_map_cmd);
13744 install_element(BGP_IPV6M_NODE, &neighbor_route_map_cmd);
13745 install_element(BGP_IPV6M_NODE, &no_neighbor_route_map_cmd);
13746 install_element(BGP_IPV6L_NODE, &neighbor_route_map_cmd);
13747 install_element(BGP_IPV6L_NODE, &no_neighbor_route_map_cmd);
13748 install_element(BGP_VPNV4_NODE, &neighbor_route_map_cmd);
13749 install_element(BGP_VPNV4_NODE, &no_neighbor_route_map_cmd);
13750 install_element(BGP_VPNV6_NODE, &neighbor_route_map_cmd);
13751 install_element(BGP_VPNV6_NODE, &no_neighbor_route_map_cmd);
13752 install_element(BGP_FLOWSPECV4_NODE, &neighbor_route_map_cmd);
13753 install_element(BGP_FLOWSPECV4_NODE, &no_neighbor_route_map_cmd);
13754 install_element(BGP_FLOWSPECV6_NODE, &neighbor_route_map_cmd);
13755 install_element(BGP_FLOWSPECV6_NODE, &no_neighbor_route_map_cmd);
13756 install_element(BGP_EVPN_NODE, &neighbor_route_map_cmd);
13757 install_element(BGP_EVPN_NODE, &no_neighbor_route_map_cmd);
13758
13759 /* "neighbor unsuppress-map" commands. */
13760 install_element(BGP_NODE, &neighbor_unsuppress_map_hidden_cmd);
13761 install_element(BGP_NODE, &no_neighbor_unsuppress_map_hidden_cmd);
13762 install_element(BGP_IPV4_NODE, &neighbor_unsuppress_map_cmd);
13763 install_element(BGP_IPV4_NODE, &no_neighbor_unsuppress_map_cmd);
13764 install_element(BGP_IPV4M_NODE, &neighbor_unsuppress_map_cmd);
13765 install_element(BGP_IPV4M_NODE, &no_neighbor_unsuppress_map_cmd);
13766 install_element(BGP_IPV4L_NODE, &neighbor_unsuppress_map_cmd);
13767 install_element(BGP_IPV4L_NODE, &no_neighbor_unsuppress_map_cmd);
13768 install_element(BGP_IPV6_NODE, &neighbor_unsuppress_map_cmd);
13769 install_element(BGP_IPV6_NODE, &no_neighbor_unsuppress_map_cmd);
13770 install_element(BGP_IPV6M_NODE, &neighbor_unsuppress_map_cmd);
13771 install_element(BGP_IPV6M_NODE, &no_neighbor_unsuppress_map_cmd);
13772 install_element(BGP_IPV6L_NODE, &neighbor_unsuppress_map_cmd);
13773 install_element(BGP_IPV6L_NODE, &no_neighbor_unsuppress_map_cmd);
13774 install_element(BGP_VPNV4_NODE, &neighbor_unsuppress_map_cmd);
13775 install_element(BGP_VPNV4_NODE, &no_neighbor_unsuppress_map_cmd);
13776 install_element(BGP_VPNV6_NODE, &neighbor_unsuppress_map_cmd);
13777 install_element(BGP_VPNV6_NODE, &no_neighbor_unsuppress_map_cmd);
13778
13779 /* "neighbor maximum-prefix" commands. */
13780 install_element(BGP_NODE, &neighbor_maximum_prefix_hidden_cmd);
13781 install_element(BGP_NODE,
13782 &neighbor_maximum_prefix_threshold_hidden_cmd);
13783 install_element(BGP_NODE, &neighbor_maximum_prefix_warning_hidden_cmd);
13784 install_element(BGP_NODE,
13785 &neighbor_maximum_prefix_threshold_warning_hidden_cmd);
13786 install_element(BGP_NODE, &neighbor_maximum_prefix_restart_hidden_cmd);
13787 install_element(BGP_NODE,
13788 &neighbor_maximum_prefix_threshold_restart_hidden_cmd);
13789 install_element(BGP_NODE, &no_neighbor_maximum_prefix_hidden_cmd);
13790 install_element(BGP_IPV4_NODE, &neighbor_maximum_prefix_cmd);
13791 install_element(BGP_IPV4_NODE, &neighbor_maximum_prefix_threshold_cmd);
13792 install_element(BGP_IPV4_NODE, &neighbor_maximum_prefix_warning_cmd);
13793 install_element(BGP_IPV4_NODE,
13794 &neighbor_maximum_prefix_threshold_warning_cmd);
13795 install_element(BGP_IPV4_NODE, &neighbor_maximum_prefix_restart_cmd);
13796 install_element(BGP_IPV4_NODE,
13797 &neighbor_maximum_prefix_threshold_restart_cmd);
13798 install_element(BGP_IPV4_NODE, &no_neighbor_maximum_prefix_cmd);
13799 install_element(BGP_IPV4M_NODE, &neighbor_maximum_prefix_cmd);
13800 install_element(BGP_IPV4M_NODE, &neighbor_maximum_prefix_threshold_cmd);
13801 install_element(BGP_IPV4M_NODE, &neighbor_maximum_prefix_warning_cmd);
13802 install_element(BGP_IPV4M_NODE,
13803 &neighbor_maximum_prefix_threshold_warning_cmd);
13804 install_element(BGP_IPV4M_NODE, &neighbor_maximum_prefix_restart_cmd);
13805 install_element(BGP_IPV4M_NODE,
13806 &neighbor_maximum_prefix_threshold_restart_cmd);
13807 install_element(BGP_IPV4M_NODE, &no_neighbor_maximum_prefix_cmd);
13808 install_element(BGP_IPV4L_NODE, &neighbor_maximum_prefix_cmd);
13809 install_element(BGP_IPV4L_NODE, &neighbor_maximum_prefix_threshold_cmd);
13810 install_element(BGP_IPV4L_NODE, &neighbor_maximum_prefix_warning_cmd);
13811 install_element(BGP_IPV4L_NODE,
13812 &neighbor_maximum_prefix_threshold_warning_cmd);
13813 install_element(BGP_IPV4L_NODE, &neighbor_maximum_prefix_restart_cmd);
13814 install_element(BGP_IPV4L_NODE,
13815 &neighbor_maximum_prefix_threshold_restart_cmd);
13816 install_element(BGP_IPV4L_NODE, &no_neighbor_maximum_prefix_cmd);
13817 install_element(BGP_IPV6_NODE, &neighbor_maximum_prefix_cmd);
13818 install_element(BGP_IPV6_NODE, &neighbor_maximum_prefix_threshold_cmd);
13819 install_element(BGP_IPV6_NODE, &neighbor_maximum_prefix_warning_cmd);
13820 install_element(BGP_IPV6_NODE,
13821 &neighbor_maximum_prefix_threshold_warning_cmd);
13822 install_element(BGP_IPV6_NODE, &neighbor_maximum_prefix_restart_cmd);
13823 install_element(BGP_IPV6_NODE,
13824 &neighbor_maximum_prefix_threshold_restart_cmd);
13825 install_element(BGP_IPV6_NODE, &no_neighbor_maximum_prefix_cmd);
13826 install_element(BGP_IPV6M_NODE, &neighbor_maximum_prefix_cmd);
13827 install_element(BGP_IPV6M_NODE, &neighbor_maximum_prefix_threshold_cmd);
13828 install_element(BGP_IPV6M_NODE, &neighbor_maximum_prefix_warning_cmd);
13829 install_element(BGP_IPV6M_NODE,
13830 &neighbor_maximum_prefix_threshold_warning_cmd);
13831 install_element(BGP_IPV6M_NODE, &neighbor_maximum_prefix_restart_cmd);
13832 install_element(BGP_IPV6M_NODE,
13833 &neighbor_maximum_prefix_threshold_restart_cmd);
13834 install_element(BGP_IPV6M_NODE, &no_neighbor_maximum_prefix_cmd);
13835 install_element(BGP_IPV6L_NODE, &neighbor_maximum_prefix_cmd);
13836 install_element(BGP_IPV6L_NODE, &neighbor_maximum_prefix_threshold_cmd);
13837 install_element(BGP_IPV6L_NODE, &neighbor_maximum_prefix_warning_cmd);
13838 install_element(BGP_IPV6L_NODE,
13839 &neighbor_maximum_prefix_threshold_warning_cmd);
13840 install_element(BGP_IPV6L_NODE, &neighbor_maximum_prefix_restart_cmd);
13841 install_element(BGP_IPV6L_NODE,
13842 &neighbor_maximum_prefix_threshold_restart_cmd);
13843 install_element(BGP_IPV6L_NODE, &no_neighbor_maximum_prefix_cmd);
13844 install_element(BGP_VPNV4_NODE, &neighbor_maximum_prefix_cmd);
13845 install_element(BGP_VPNV4_NODE, &neighbor_maximum_prefix_threshold_cmd);
13846 install_element(BGP_VPNV4_NODE, &neighbor_maximum_prefix_warning_cmd);
13847 install_element(BGP_VPNV4_NODE,
13848 &neighbor_maximum_prefix_threshold_warning_cmd);
13849 install_element(BGP_VPNV4_NODE, &neighbor_maximum_prefix_restart_cmd);
13850 install_element(BGP_VPNV4_NODE,
13851 &neighbor_maximum_prefix_threshold_restart_cmd);
13852 install_element(BGP_VPNV4_NODE, &no_neighbor_maximum_prefix_cmd);
13853 install_element(BGP_VPNV6_NODE, &neighbor_maximum_prefix_cmd);
13854 install_element(BGP_VPNV6_NODE, &neighbor_maximum_prefix_threshold_cmd);
13855 install_element(BGP_VPNV6_NODE, &neighbor_maximum_prefix_warning_cmd);
13856 install_element(BGP_VPNV6_NODE,
13857 &neighbor_maximum_prefix_threshold_warning_cmd);
13858 install_element(BGP_VPNV6_NODE, &neighbor_maximum_prefix_restart_cmd);
13859 install_element(BGP_VPNV6_NODE,
13860 &neighbor_maximum_prefix_threshold_restart_cmd);
13861 install_element(BGP_VPNV6_NODE, &no_neighbor_maximum_prefix_cmd);
13862
13863 /* "neighbor allowas-in" */
13864 install_element(BGP_NODE, &neighbor_allowas_in_hidden_cmd);
13865 install_element(BGP_NODE, &no_neighbor_allowas_in_hidden_cmd);
13866 install_element(BGP_IPV4_NODE, &neighbor_allowas_in_cmd);
13867 install_element(BGP_IPV4_NODE, &no_neighbor_allowas_in_cmd);
13868 install_element(BGP_IPV4M_NODE, &neighbor_allowas_in_cmd);
13869 install_element(BGP_IPV4M_NODE, &no_neighbor_allowas_in_cmd);
13870 install_element(BGP_IPV4L_NODE, &neighbor_allowas_in_cmd);
13871 install_element(BGP_IPV4L_NODE, &no_neighbor_allowas_in_cmd);
13872 install_element(BGP_IPV6_NODE, &neighbor_allowas_in_cmd);
13873 install_element(BGP_IPV6_NODE, &no_neighbor_allowas_in_cmd);
13874 install_element(BGP_IPV6M_NODE, &neighbor_allowas_in_cmd);
13875 install_element(BGP_IPV6M_NODE, &no_neighbor_allowas_in_cmd);
13876 install_element(BGP_IPV6L_NODE, &neighbor_allowas_in_cmd);
13877 install_element(BGP_IPV6L_NODE, &no_neighbor_allowas_in_cmd);
13878 install_element(BGP_VPNV4_NODE, &neighbor_allowas_in_cmd);
13879 install_element(BGP_VPNV4_NODE, &no_neighbor_allowas_in_cmd);
13880 install_element(BGP_VPNV6_NODE, &neighbor_allowas_in_cmd);
13881 install_element(BGP_VPNV6_NODE, &no_neighbor_allowas_in_cmd);
13882 install_element(BGP_EVPN_NODE, &neighbor_allowas_in_cmd);
13883 install_element(BGP_EVPN_NODE, &no_neighbor_allowas_in_cmd);
13884
13885 /* address-family commands. */
13886 install_element(BGP_NODE, &address_family_ipv4_safi_cmd);
13887 install_element(BGP_NODE, &address_family_ipv6_safi_cmd);
13888 #ifdef KEEP_OLD_VPN_COMMANDS
13889 install_element(BGP_NODE, &address_family_vpnv4_cmd);
13890 install_element(BGP_NODE, &address_family_vpnv6_cmd);
13891 #endif /* KEEP_OLD_VPN_COMMANDS */
13892
13893 install_element(BGP_NODE, &address_family_evpn_cmd);
13894
13895 /* "exit-address-family" command. */
13896 install_element(BGP_IPV4_NODE, &exit_address_family_cmd);
13897 install_element(BGP_IPV4M_NODE, &exit_address_family_cmd);
13898 install_element(BGP_IPV4L_NODE, &exit_address_family_cmd);
13899 install_element(BGP_IPV6_NODE, &exit_address_family_cmd);
13900 install_element(BGP_IPV6M_NODE, &exit_address_family_cmd);
13901 install_element(BGP_IPV6L_NODE, &exit_address_family_cmd);
13902 install_element(BGP_VPNV4_NODE, &exit_address_family_cmd);
13903 install_element(BGP_VPNV6_NODE, &exit_address_family_cmd);
13904 install_element(BGP_FLOWSPECV4_NODE, &exit_address_family_cmd);
13905 install_element(BGP_FLOWSPECV6_NODE, &exit_address_family_cmd);
13906 install_element(BGP_EVPN_NODE, &exit_address_family_cmd);
13907
13908 /* "clear ip bgp commands" */
13909 install_element(ENABLE_NODE, &clear_ip_bgp_all_cmd);
13910
13911 /* clear ip bgp prefix */
13912 install_element(ENABLE_NODE, &clear_ip_bgp_prefix_cmd);
13913 install_element(ENABLE_NODE, &clear_bgp_ipv6_safi_prefix_cmd);
13914 install_element(ENABLE_NODE, &clear_bgp_instance_ipv6_safi_prefix_cmd);
13915
13916 /* "show [ip] bgp summary" commands. */
13917 install_element(VIEW_NODE, &show_bgp_instance_all_ipv6_updgrps_cmd);
13918 install_element(VIEW_NODE, &show_bgp_l2vpn_evpn_updgrps_cmd);
13919 install_element(VIEW_NODE, &show_bgp_instance_updgrps_stats_cmd);
13920 install_element(VIEW_NODE, &show_bgp_updgrps_stats_cmd);
13921 install_element(VIEW_NODE, &show_ip_bgp_instance_updgrps_adj_s_cmd);
13922 install_element(VIEW_NODE, &show_ip_bgp_summary_cmd);
13923 install_element(VIEW_NODE, &show_ip_bgp_updgrps_cmd);
13924
13925 /* "show [ip] bgp neighbors" commands. */
13926 install_element(VIEW_NODE, &show_ip_bgp_neighbors_cmd);
13927
13928 /* "show [ip] bgp peer-group" commands. */
13929 install_element(VIEW_NODE, &show_ip_bgp_peer_groups_cmd);
13930
13931 /* "show [ip] bgp paths" commands. */
13932 install_element(VIEW_NODE, &show_ip_bgp_paths_cmd);
13933
13934 /* "show [ip] bgp community" commands. */
13935 install_element(VIEW_NODE, &show_ip_bgp_community_info_cmd);
13936
13937 /* "show ip bgp large-community" commands. */
13938 install_element(VIEW_NODE, &show_ip_bgp_lcommunity_info_cmd);
13939 /* "show [ip] bgp attribute-info" commands. */
13940 install_element(VIEW_NODE, &show_ip_bgp_attr_info_cmd);
13941 /* "show [ip] bgp route-leak" command */
13942 install_element(VIEW_NODE, &show_ip_bgp_route_leak_cmd);
13943
13944 /* "redistribute" commands. */
13945 install_element(BGP_NODE, &bgp_redistribute_ipv4_hidden_cmd);
13946 install_element(BGP_NODE, &no_bgp_redistribute_ipv4_hidden_cmd);
13947 install_element(BGP_NODE, &bgp_redistribute_ipv4_rmap_hidden_cmd);
13948 install_element(BGP_NODE, &bgp_redistribute_ipv4_metric_hidden_cmd);
13949 install_element(BGP_NODE,
13950 &bgp_redistribute_ipv4_rmap_metric_hidden_cmd);
13951 install_element(BGP_NODE,
13952 &bgp_redistribute_ipv4_metric_rmap_hidden_cmd);
13953 install_element(BGP_NODE, &bgp_redistribute_ipv4_ospf_hidden_cmd);
13954 install_element(BGP_NODE, &no_bgp_redistribute_ipv4_ospf_hidden_cmd);
13955 install_element(BGP_NODE, &bgp_redistribute_ipv4_ospf_rmap_hidden_cmd);
13956 install_element(BGP_NODE,
13957 &bgp_redistribute_ipv4_ospf_metric_hidden_cmd);
13958 install_element(BGP_NODE,
13959 &bgp_redistribute_ipv4_ospf_rmap_metric_hidden_cmd);
13960 install_element(BGP_NODE,
13961 &bgp_redistribute_ipv4_ospf_metric_rmap_hidden_cmd);
13962 install_element(BGP_IPV4_NODE, &bgp_redistribute_ipv4_cmd);
13963 install_element(BGP_IPV4_NODE, &no_bgp_redistribute_ipv4_cmd);
13964 install_element(BGP_IPV4_NODE, &bgp_redistribute_ipv4_rmap_cmd);
13965 install_element(BGP_IPV4_NODE, &bgp_redistribute_ipv4_metric_cmd);
13966 install_element(BGP_IPV4_NODE, &bgp_redistribute_ipv4_rmap_metric_cmd);
13967 install_element(BGP_IPV4_NODE, &bgp_redistribute_ipv4_metric_rmap_cmd);
13968 install_element(BGP_IPV4_NODE, &bgp_redistribute_ipv4_ospf_cmd);
13969 install_element(BGP_IPV4_NODE, &no_bgp_redistribute_ipv4_ospf_cmd);
13970 install_element(BGP_IPV4_NODE, &bgp_redistribute_ipv4_ospf_rmap_cmd);
13971 install_element(BGP_IPV4_NODE, &bgp_redistribute_ipv4_ospf_metric_cmd);
13972 install_element(BGP_IPV4_NODE,
13973 &bgp_redistribute_ipv4_ospf_rmap_metric_cmd);
13974 install_element(BGP_IPV4_NODE,
13975 &bgp_redistribute_ipv4_ospf_metric_rmap_cmd);
13976 install_element(BGP_IPV6_NODE, &bgp_redistribute_ipv6_cmd);
13977 install_element(BGP_IPV6_NODE, &no_bgp_redistribute_ipv6_cmd);
13978 install_element(BGP_IPV6_NODE, &bgp_redistribute_ipv6_rmap_cmd);
13979 install_element(BGP_IPV6_NODE, &bgp_redistribute_ipv6_metric_cmd);
13980 install_element(BGP_IPV6_NODE, &bgp_redistribute_ipv6_rmap_metric_cmd);
13981 install_element(BGP_IPV6_NODE, &bgp_redistribute_ipv6_metric_rmap_cmd);
13982
13983 /* import|export vpn [route-map WORD] */
13984 install_element(BGP_IPV4_NODE, &bgp_imexport_vpn_cmd);
13985 install_element(BGP_IPV6_NODE, &bgp_imexport_vpn_cmd);
13986
13987 install_element(BGP_IPV4_NODE, &bgp_imexport_vrf_cmd);
13988 install_element(BGP_IPV6_NODE, &bgp_imexport_vrf_cmd);
13989
13990 /* ttl_security commands */
13991 install_element(BGP_NODE, &neighbor_ttl_security_cmd);
13992 install_element(BGP_NODE, &no_neighbor_ttl_security_cmd);
13993
13994 /* "show [ip] bgp memory" commands. */
13995 install_element(VIEW_NODE, &show_bgp_memory_cmd);
13996
13997 /* "show bgp martian next-hop" */
13998 install_element(VIEW_NODE, &show_bgp_martian_nexthop_db_cmd);
13999
14000 install_element(VIEW_NODE, &show_bgp_mac_hash_cmd);
14001
14002 /* "show [ip] bgp views" commands. */
14003 install_element(VIEW_NODE, &show_bgp_views_cmd);
14004
14005 /* "show [ip] bgp vrfs" commands. */
14006 install_element(VIEW_NODE, &show_bgp_vrfs_cmd);
14007
14008 /* Community-list. */
14009 community_list_vty();
14010
14011 /* vpn-policy commands */
14012 install_element(BGP_IPV4_NODE, &af_rd_vpn_export_cmd);
14013 install_element(BGP_IPV6_NODE, &af_rd_vpn_export_cmd);
14014 install_element(BGP_IPV4_NODE, &af_label_vpn_export_cmd);
14015 install_element(BGP_IPV6_NODE, &af_label_vpn_export_cmd);
14016 install_element(BGP_IPV4_NODE, &af_nexthop_vpn_export_cmd);
14017 install_element(BGP_IPV6_NODE, &af_nexthop_vpn_export_cmd);
14018 install_element(BGP_IPV4_NODE, &af_rt_vpn_imexport_cmd);
14019 install_element(BGP_IPV6_NODE, &af_rt_vpn_imexport_cmd);
14020 install_element(BGP_IPV4_NODE, &af_route_map_vpn_imexport_cmd);
14021 install_element(BGP_IPV6_NODE, &af_route_map_vpn_imexport_cmd);
14022 install_element(BGP_IPV4_NODE, &af_import_vrf_route_map_cmd);
14023 install_element(BGP_IPV6_NODE, &af_import_vrf_route_map_cmd);
14024
14025 install_element(BGP_IPV4_NODE, &af_routetarget_import_cmd);
14026 install_element(BGP_IPV6_NODE, &af_routetarget_import_cmd);
14027
14028 install_element(BGP_IPV4_NODE, &af_no_rd_vpn_export_cmd);
14029 install_element(BGP_IPV6_NODE, &af_no_rd_vpn_export_cmd);
14030 install_element(BGP_IPV4_NODE, &af_no_label_vpn_export_cmd);
14031 install_element(BGP_IPV6_NODE, &af_no_label_vpn_export_cmd);
14032 install_element(BGP_IPV4_NODE, &af_no_nexthop_vpn_export_cmd);
14033 install_element(BGP_IPV6_NODE, &af_no_nexthop_vpn_export_cmd);
14034 install_element(BGP_IPV4_NODE, &af_no_rt_vpn_imexport_cmd);
14035 install_element(BGP_IPV6_NODE, &af_no_rt_vpn_imexport_cmd);
14036 install_element(BGP_IPV4_NODE, &af_no_route_map_vpn_imexport_cmd);
14037 install_element(BGP_IPV6_NODE, &af_no_route_map_vpn_imexport_cmd);
14038 install_element(BGP_IPV4_NODE, &af_no_import_vrf_route_map_cmd);
14039 install_element(BGP_IPV6_NODE, &af_no_import_vrf_route_map_cmd);
14040 }
14041
14042 #include "memory.h"
14043 #include "bgp_regex.h"
14044 #include "bgp_clist.h"
14045 #include "bgp_ecommunity.h"
14046
14047 /* VTY functions. */
14048
14049 /* Direction value to string conversion. */
14050 static const char *community_direct_str(int direct)
14051 {
14052 switch (direct) {
14053 case COMMUNITY_DENY:
14054 return "deny";
14055 case COMMUNITY_PERMIT:
14056 return "permit";
14057 default:
14058 return "unknown";
14059 }
14060 }
14061
14062 /* Display error string. */
14063 static void community_list_perror(struct vty *vty, int ret)
14064 {
14065 switch (ret) {
14066 case COMMUNITY_LIST_ERR_CANT_FIND_LIST:
14067 vty_out(vty, "%% Can't find community-list\n");
14068 break;
14069 case COMMUNITY_LIST_ERR_MALFORMED_VAL:
14070 vty_out(vty, "%% Malformed community-list value\n");
14071 break;
14072 case COMMUNITY_LIST_ERR_STANDARD_CONFLICT:
14073 vty_out(vty,
14074 "%% Community name conflict, previously defined as standard community\n");
14075 break;
14076 case COMMUNITY_LIST_ERR_EXPANDED_CONFLICT:
14077 vty_out(vty,
14078 "%% Community name conflict, previously defined as expanded community\n");
14079 break;
14080 }
14081 }
14082
14083 /* "community-list" keyword help string. */
14084 #define COMMUNITY_LIST_STR "Add a community list entry\n"
14085
14086 /*community-list standard */
14087 DEFUN (community_list_standard,
14088 bgp_community_list_standard_cmd,
14089 "bgp community-list <(1-99)|standard WORD> <deny|permit> AA:NN...",
14090 BGP_STR
14091 COMMUNITY_LIST_STR
14092 "Community list number (standard)\n"
14093 "Add an standard community-list entry\n"
14094 "Community list name\n"
14095 "Specify community to reject\n"
14096 "Specify community to accept\n"
14097 COMMUNITY_VAL_STR)
14098 {
14099 char *cl_name_or_number = NULL;
14100 int direct = 0;
14101 int style = COMMUNITY_LIST_STANDARD;
14102
14103 int idx = 0;
14104
14105 if (argv_find(argv, argc, "ip", &idx)) {
14106 vty_out(vty, "This config option is deprecated, and is scheduled for removal.\n");
14107 vty_out(vty, "if you are using this please migrate to the below command.\n");
14108 vty_out(vty, "'bgp community-list <(1-99)|(100-500)|standard|expanded> <deny|permit> AA:NN'\n");
14109 zlog_warn("Deprecated option: 'ip community-list <(1-99)|(100-500)|standard|expanded> <deny|permit> AA:NN' being used");
14110 }
14111
14112 argv_find(argv, argc, "(1-99)", &idx);
14113 argv_find(argv, argc, "WORD", &idx);
14114 cl_name_or_number = argv[idx]->arg;
14115 direct = argv_find(argv, argc, "permit", &idx) ? COMMUNITY_PERMIT
14116 : COMMUNITY_DENY;
14117 argv_find(argv, argc, "AA:NN", &idx);
14118 char *str = argv_concat(argv, argc, idx);
14119
14120 int ret = community_list_set(bgp_clist, cl_name_or_number, str, direct,
14121 style);
14122
14123 XFREE(MTYPE_TMP, str);
14124
14125 if (ret < 0) {
14126 /* Display error string. */
14127 community_list_perror(vty, ret);
14128 return CMD_WARNING_CONFIG_FAILED;
14129 }
14130
14131 return CMD_SUCCESS;
14132 }
14133
14134 #if CONFDATE > 20191005
14135 CPP_NOTICE("bgpd: remove deprecated 'ip community-list <(1-99)|(100-500)|standard|expanded> <deny|permit> AA:NN' command")
14136 #endif
14137 ALIAS (community_list_standard,
14138 ip_community_list_standard_cmd,
14139 "ip community-list <(1-99)|standard WORD> <deny|permit> AA:NN...",
14140 IP_STR
14141 COMMUNITY_LIST_STR
14142 "Community list number (standard)\n"
14143 "Add an standard community-list entry\n"
14144 "Community list name\n"
14145 "Specify community to reject\n"
14146 "Specify community to accept\n"
14147 COMMUNITY_VAL_STR)
14148
14149 DEFUN (no_community_list_standard_all,
14150 no_bgp_community_list_standard_all_cmd,
14151 "no bgp community-list <(1-99)|standard WORD> <deny|permit> AA:NN...",
14152 NO_STR
14153 BGP_STR
14154 COMMUNITY_LIST_STR
14155 "Community list number (standard)\n"
14156 "Add an standard community-list entry\n"
14157 "Community list name\n"
14158 "Specify community to reject\n"
14159 "Specify community to accept\n"
14160 COMMUNITY_VAL_STR)
14161 {
14162 char *cl_name_or_number = NULL;
14163 char *str = NULL;
14164 int direct = 0;
14165 int style = COMMUNITY_LIST_STANDARD;
14166
14167 int idx = 0;
14168
14169 if (argv_find(argv, argc, "ip", &idx)) {
14170 vty_out(vty, "This config option is deprecated, and is scheduled for removal\n");
14171 vty_out(vty, "if you are using this please migrate to the below command.\n");
14172 vty_out(vty, "'no bgp community-list <(1-99)|(100-500)|standard|expanded> <deny|permit> AA:NN'\n");
14173 zlog_warn("Deprecated option: 'no ip community-list <(1-99)|(100-500)|standard|expanded> <deny|permit> |AA:NN' being used");
14174 }
14175
14176 argv_find(argv, argc, "permit", &idx);
14177 argv_find(argv, argc, "deny", &idx);
14178
14179 if (idx) {
14180 direct = argv_find(argv, argc, "permit", &idx)
14181 ? COMMUNITY_PERMIT
14182 : COMMUNITY_DENY;
14183
14184 idx = 0;
14185 argv_find(argv, argc, "AA:NN", &idx);
14186 str = argv_concat(argv, argc, idx);
14187 }
14188
14189 idx = 0;
14190 argv_find(argv, argc, "(1-99)", &idx);
14191 argv_find(argv, argc, "WORD", &idx);
14192 cl_name_or_number = argv[idx]->arg;
14193
14194 int ret = community_list_unset(bgp_clist, cl_name_or_number, str,
14195 direct, style);
14196
14197 XFREE(MTYPE_TMP, str);
14198
14199 if (ret < 0) {
14200 community_list_perror(vty, ret);
14201 return CMD_WARNING_CONFIG_FAILED;
14202 }
14203
14204 return CMD_SUCCESS;
14205 }
14206 ALIAS (no_community_list_standard_all,
14207 no_ip_community_list_standard_all_cmd,
14208 "no ip community-list <(1-99)|standard WORD> <deny|permit> AA:NN...",
14209 NO_STR
14210 IP_STR
14211 COMMUNITY_LIST_STR
14212 "Community list number (standard)\n"
14213 "Add an standard community-list entry\n"
14214 "Community list name\n"
14215 "Specify community to reject\n"
14216 "Specify community to accept\n"
14217 COMMUNITY_VAL_STR)
14218
14219 ALIAS(no_community_list_standard_all, no_bgp_community_list_standard_all_list_cmd,
14220 "no bgp community-list <(1-99)|standard WORD>",
14221 NO_STR BGP_STR COMMUNITY_LIST_STR
14222 "Community list number (standard)\n"
14223 "Add an standard community-list entry\n"
14224 "Community list name\n")
14225
14226 ALIAS(no_community_list_standard_all, no_ip_community_list_standard_all_list_cmd,
14227 "no ip community-list <(1-99)|standard WORD>",
14228 NO_STR BGP_STR COMMUNITY_LIST_STR
14229 "Community list number (standard)\n"
14230 "Add an standard community-list entry\n"
14231 "Community list name\n")
14232
14233 /*community-list expanded */
14234 DEFUN (community_list_expanded_all,
14235 bgp_community_list_expanded_all_cmd,
14236 "bgp community-list <(100-500)|expanded WORD> <deny|permit> AA:NN...",
14237 BGP_STR
14238 COMMUNITY_LIST_STR
14239 "Community list number (expanded)\n"
14240 "Add an expanded community-list entry\n"
14241 "Community list name\n"
14242 "Specify community to reject\n"
14243 "Specify community to accept\n"
14244 COMMUNITY_VAL_STR)
14245 {
14246 char *cl_name_or_number = NULL;
14247 int direct = 0;
14248 int style = COMMUNITY_LIST_EXPANDED;
14249
14250 int idx = 0;
14251 if (argv_find(argv, argc, "ip", &idx)) {
14252 vty_out(vty, "This config option is deprecated, and is scheduled for removal.\n");
14253 vty_out(vty, "if you are using this please migrate to the below command.\n");
14254 vty_out(vty, "'bgp community-list <(1-99)|(100-500)|standard|expanded> <deny|permit> AA:NN'\n");
14255 zlog_warn("Deprecated option: 'ip community-list <(1-99)|(100-500)|standard|expanded> <deny|permit> AA:NN' being used");
14256 }
14257 argv_find(argv, argc, "(100-500)", &idx);
14258 argv_find(argv, argc, "WORD", &idx);
14259 cl_name_or_number = argv[idx]->arg;
14260 direct = argv_find(argv, argc, "permit", &idx) ? COMMUNITY_PERMIT
14261 : COMMUNITY_DENY;
14262 argv_find(argv, argc, "AA:NN", &idx);
14263 char *str = argv_concat(argv, argc, idx);
14264
14265 int ret = community_list_set(bgp_clist, cl_name_or_number, str, direct,
14266 style);
14267
14268 XFREE(MTYPE_TMP, str);
14269
14270 if (ret < 0) {
14271 /* Display error string. */
14272 community_list_perror(vty, ret);
14273 return CMD_WARNING_CONFIG_FAILED;
14274 }
14275
14276 return CMD_SUCCESS;
14277 }
14278
14279 ALIAS (community_list_expanded_all,
14280 ip_community_list_expanded_all_cmd,
14281 "ip community-list <(100-500)|expanded WORD> <deny|permit> AA:NN...",
14282 IP_STR
14283 COMMUNITY_LIST_STR
14284 "Community list number (expanded)\n"
14285 "Add an expanded community-list entry\n"
14286 "Community list name\n"
14287 "Specify community to reject\n"
14288 "Specify community to accept\n"
14289 COMMUNITY_VAL_STR)
14290
14291 DEFUN (no_community_list_expanded_all,
14292 no_bgp_community_list_expanded_all_cmd,
14293 "no bgp community-list <(100-500)|expanded WORD> <deny|permit> AA:NN...",
14294 NO_STR
14295 BGP_STR
14296 COMMUNITY_LIST_STR
14297 "Community list number (expanded)\n"
14298 "Add an expanded community-list entry\n"
14299 "Community list name\n"
14300 "Specify community to reject\n"
14301 "Specify community to accept\n"
14302 COMMUNITY_VAL_STR)
14303 {
14304 char *cl_name_or_number = NULL;
14305 char *str = NULL;
14306 int direct = 0;
14307 int style = COMMUNITY_LIST_EXPANDED;
14308
14309 int idx = 0;
14310 if (argv_find(argv, argc, "ip", &idx)) {
14311 vty_out(vty, "This config option is deprecated, and is scheduled for removal.\n");
14312 vty_out(vty, "if you are using this please migrate to the below command.\n");
14313 vty_out(vty, "'no bgp community-list <(1-99)|(100-500)|standard|expanded> <deny|permit> AA:NN'\n");
14314 zlog_warn("Deprecated option: 'no ip community-list <(1-99)|(100-500)|standard|expanded> <deny|permit> AA:NN' being used");
14315 }
14316
14317 idx = 0;
14318 argv_find(argv, argc, "permit", &idx);
14319 argv_find(argv, argc, "deny", &idx);
14320
14321 if (idx) {
14322 direct = argv_find(argv, argc, "permit", &idx)
14323 ? COMMUNITY_PERMIT
14324 : COMMUNITY_DENY;
14325
14326 idx = 0;
14327 argv_find(argv, argc, "AA:NN", &idx);
14328 str = argv_concat(argv, argc, idx);
14329 }
14330
14331 idx = 0;
14332 argv_find(argv, argc, "(100-500)", &idx);
14333 argv_find(argv, argc, "WORD", &idx);
14334 cl_name_or_number = argv[idx]->arg;
14335
14336 int ret = community_list_unset(bgp_clist, cl_name_or_number, str,
14337 direct, style);
14338
14339 XFREE(MTYPE_TMP, str);
14340
14341 if (ret < 0) {
14342 community_list_perror(vty, ret);
14343 return CMD_WARNING_CONFIG_FAILED;
14344 }
14345
14346 return CMD_SUCCESS;
14347 }
14348
14349 ALIAS (no_community_list_expanded_all,
14350 no_ip_community_list_expanded_all_cmd,
14351 "no ip community-list <(100-500)|expanded WORD> <deny|permit> AA:NN...",
14352 NO_STR
14353 IP_STR
14354 COMMUNITY_LIST_STR
14355 "Community list number (expanded)\n"
14356 "Add an expanded community-list entry\n"
14357 "Community list name\n"
14358 "Specify community to reject\n"
14359 "Specify community to accept\n"
14360 COMMUNITY_VAL_STR)
14361
14362 ALIAS(no_community_list_expanded_all, no_bgp_community_list_expanded_all_list_cmd,
14363 "no bgp community-list <(100-500)|expanded WORD>",
14364 NO_STR IP_STR COMMUNITY_LIST_STR
14365 "Community list number (expanded)\n"
14366 "Add an expanded community-list entry\n"
14367 "Community list name\n")
14368
14369 ALIAS(no_community_list_expanded_all, no_ip_community_list_expanded_all_list_cmd,
14370 "no ip community-list <(100-500)|expanded WORD>",
14371 NO_STR IP_STR COMMUNITY_LIST_STR
14372 "Community list number (expanded)\n"
14373 "Add an expanded community-list entry\n"
14374 "Community list name\n")
14375
14376 /* Return configuration string of community-list entry. */
14377 static const char *community_list_config_str(struct community_entry *entry)
14378 {
14379 const char *str;
14380
14381 if (entry->any)
14382 str = "";
14383 else {
14384 if (entry->style == COMMUNITY_LIST_STANDARD)
14385 str = community_str(entry->u.com, false);
14386 else if (entry->style == LARGE_COMMUNITY_LIST_STANDARD)
14387 str = lcommunity_str(entry->u.lcom, false);
14388 else
14389 str = entry->config;
14390 }
14391 return str;
14392 }
14393
14394 static void community_list_show(struct vty *vty, struct community_list *list)
14395 {
14396 struct community_entry *entry;
14397
14398 for (entry = list->head; entry; entry = entry->next) {
14399 if (entry == list->head) {
14400 if (all_digit(list->name))
14401 vty_out(vty, "Community %s list %s\n",
14402 entry->style == COMMUNITY_LIST_STANDARD
14403 ? "standard"
14404 : "(expanded) access",
14405 list->name);
14406 else
14407 vty_out(vty, "Named Community %s list %s\n",
14408 entry->style == COMMUNITY_LIST_STANDARD
14409 ? "standard"
14410 : "expanded",
14411 list->name);
14412 }
14413 if (entry->any)
14414 vty_out(vty, " %s\n",
14415 community_direct_str(entry->direct));
14416 else
14417 vty_out(vty, " %s %s\n",
14418 community_direct_str(entry->direct),
14419 community_list_config_str(entry));
14420 }
14421 }
14422
14423 DEFUN (show_community_list,
14424 show_bgp_community_list_cmd,
14425 "show bgp community-list",
14426 SHOW_STR
14427 BGP_STR
14428 "List community-list\n")
14429 {
14430 struct community_list *list;
14431 struct community_list_master *cm;
14432
14433 int idx = 0;
14434 if (argv_find(argv, argc, "ip", &idx)) {
14435 vty_out(vty, "This config option is deprecated, and is scheduled for removal.\n");
14436 vty_out(vty, "if you are using this please migrate to the below command.\n");
14437 vty_out(vty, "'show bgp community-list <(1-500)|WORD>'\n");
14438 zlog_warn("Deprecated option: 'ip show community-list <(1-500)|WORD>' being used");
14439 }
14440 cm = community_list_master_lookup(bgp_clist, COMMUNITY_LIST_MASTER);
14441 if (!cm)
14442 return CMD_SUCCESS;
14443
14444 for (list = cm->num.head; list; list = list->next)
14445 community_list_show(vty, list);
14446
14447 for (list = cm->str.head; list; list = list->next)
14448 community_list_show(vty, list);
14449
14450 return CMD_SUCCESS;
14451 }
14452
14453 ALIAS (show_community_list,
14454 show_ip_community_list_cmd,
14455 "show ip community-list",
14456 SHOW_STR
14457 IP_STR
14458 "List community-list\n")
14459
14460 DEFUN (show_community_list_arg,
14461 show_bgp_community_list_arg_cmd,
14462 "show bgp community-list <(1-500)|WORD>",
14463 SHOW_STR
14464 BGP_STR
14465 "List community-list\n"
14466 "Community-list number\n"
14467 "Community-list name\n")
14468 {
14469 int idx_comm_list = 3;
14470 struct community_list *list;
14471
14472 int idx = 0;
14473 if (argv_find(argv, argc, "ip", &idx)) {
14474 vty_out(vty, "This config option is deprecated, and is scheduled for removal.\n");
14475 vty_out(vty, "if you are using this please migrate to the below command.\n");
14476 vty_out(vty, "'show bgp community-list <(1-500)|WORD>'\n");
14477 zlog_warn("Deprecated option: 'ip show community-list <(1-500)|WORD>' being used");
14478 }
14479 list = community_list_lookup(bgp_clist, argv[idx_comm_list]->arg, 0,
14480 COMMUNITY_LIST_MASTER);
14481 if (!list) {
14482 vty_out(vty, "%% Can't find community-list\n");
14483 return CMD_WARNING;
14484 }
14485
14486 community_list_show(vty, list);
14487
14488 return CMD_SUCCESS;
14489 }
14490
14491 ALIAS (show_community_list_arg,
14492 show_ip_community_list_arg_cmd,
14493 "show ip community-list <(1-500)|WORD>",
14494 SHOW_STR
14495 IP_STR
14496 "List community-list\n"
14497 "Community-list number\n"
14498 "Community-list name\n")
14499
14500 /*
14501 * Large Community code.
14502 */
14503 static int lcommunity_list_set_vty(struct vty *vty, int argc,
14504 struct cmd_token **argv, int style,
14505 int reject_all_digit_name)
14506 {
14507 int ret;
14508 int direct;
14509 char *str;
14510 int idx = 0;
14511 char *cl_name;
14512
14513 if (argv_find(argv, argc, "ip", &idx)) {
14514 vty_out(vty, "This config option is deprecated, and is scheduled for removal.\n");
14515 vty_out(vty, "if you are using this please migrate to the below command.\n");
14516 vty_out(vty, "'bgp large-community-list <(1-99)|(100-500)|standard|expanded> <deny|permit> <LINE|AA:BB:CC>'\n");
14517 zlog_warn("Deprecated option: 'large-community-list <(1-99)|(100-500)|standard|expanded> <deny|permit> <LINE|AA:BB:CC>' being used");
14518 }
14519 direct = argv_find(argv, argc, "permit", &idx) ? COMMUNITY_PERMIT
14520 : COMMUNITY_DENY;
14521
14522 /* All digit name check. */
14523 idx = 0;
14524 argv_find(argv, argc, "WORD", &idx);
14525 argv_find(argv, argc, "(1-99)", &idx);
14526 argv_find(argv, argc, "(100-500)", &idx);
14527 cl_name = argv[idx]->arg;
14528 if (reject_all_digit_name && all_digit(cl_name)) {
14529 vty_out(vty, "%% Community name cannot have all digits\n");
14530 return CMD_WARNING_CONFIG_FAILED;
14531 }
14532
14533 idx = 0;
14534 argv_find(argv, argc, "AA:BB:CC", &idx);
14535 argv_find(argv, argc, "LINE", &idx);
14536 /* Concat community string argument. */
14537 if (idx)
14538 str = argv_concat(argv, argc, idx);
14539 else
14540 str = NULL;
14541
14542 ret = lcommunity_list_set(bgp_clist, cl_name, str, direct, style);
14543
14544 /* Free temporary community list string allocated by
14545 argv_concat(). */
14546 XFREE(MTYPE_TMP, str);
14547
14548 if (ret < 0) {
14549 community_list_perror(vty, ret);
14550 return CMD_WARNING_CONFIG_FAILED;
14551 }
14552 return CMD_SUCCESS;
14553 }
14554
14555 static int lcommunity_list_unset_vty(struct vty *vty, int argc,
14556 struct cmd_token **argv, int style)
14557 {
14558 int ret;
14559 int direct = 0;
14560 char *str = NULL;
14561 int idx = 0;
14562
14563 if (argv_find(argv, argc, "ip", &idx)) {
14564 vty_out(vty, "This config option is deprecated, and is scheduled for removal.\n");
14565 vty_out(vty, "if you are using this please migrate to the below command.\n");
14566 vty_out(vty, "'no bgp large-community-list <(1-99)|(100-500)|standard|expanded> <deny|permit> <LINE|AA:BB:CC>'\n");
14567 zlog_warn("Deprecated option: 'no ip large-community-list <(1-99)|(100-500)|standard|expanded> <deny|permit> <LINE|AA:BB:CC>' being used");
14568 }
14569 argv_find(argv, argc, "permit", &idx);
14570 argv_find(argv, argc, "deny", &idx);
14571
14572 if (idx) {
14573 /* Check the list direct. */
14574 if (strncmp(argv[idx]->arg, "p", 1) == 0)
14575 direct = COMMUNITY_PERMIT;
14576 else
14577 direct = COMMUNITY_DENY;
14578
14579 idx = 0;
14580 argv_find(argv, argc, "LINE", &idx);
14581 argv_find(argv, argc, "AA:AA:NN", &idx);
14582 /* Concat community string argument. */
14583 str = argv_concat(argv, argc, idx);
14584 }
14585
14586 idx = 0;
14587 argv_find(argv, argc, "(1-99)", &idx);
14588 argv_find(argv, argc, "(100-500)", &idx);
14589 argv_find(argv, argc, "WORD", &idx);
14590
14591 /* Unset community list. */
14592 ret = lcommunity_list_unset(bgp_clist, argv[idx]->arg, str, direct,
14593 style);
14594
14595 /* Free temporary community list string allocated by
14596 argv_concat(). */
14597 XFREE(MTYPE_TMP, str);
14598
14599 if (ret < 0) {
14600 community_list_perror(vty, ret);
14601 return CMD_WARNING_CONFIG_FAILED;
14602 }
14603
14604 return CMD_SUCCESS;
14605 }
14606
14607 /* "large-community-list" keyword help string. */
14608 #define LCOMMUNITY_LIST_STR "Add a large community list entry\n"
14609 #define LCOMMUNITY_VAL_STR "large community in 'aa:bb:cc' format\n"
14610
14611 #if CONFDATE > 20191005
14612 CPP_NOTICE("bgpd: remove deprecated 'ip large-community-list <(1-99)|(100-500)|standard|expanded> <deny|permit> <LINE|AA:BB:CC>' command")
14613 #endif
14614 DEFUN (lcommunity_list_standard,
14615 bgp_lcommunity_list_standard_cmd,
14616 "bgp large-community-list (1-99) <deny|permit>",
14617 BGP_STR
14618 LCOMMUNITY_LIST_STR
14619 "Large Community list number (standard)\n"
14620 "Specify large community to reject\n"
14621 "Specify large community to accept\n")
14622 {
14623 return lcommunity_list_set_vty(vty, argc, argv,
14624 LARGE_COMMUNITY_LIST_STANDARD, 0);
14625 }
14626
14627 ALIAS (lcommunity_list_standard,
14628 ip_lcommunity_list_standard_cmd,
14629 "ip large-community-list (1-99) <deny|permit>",
14630 IP_STR
14631 LCOMMUNITY_LIST_STR
14632 "Large Community list number (standard)\n"
14633 "Specify large community to reject\n"
14634 "Specify large community to accept\n")
14635
14636 DEFUN (lcommunity_list_standard1,
14637 bgp_lcommunity_list_standard1_cmd,
14638 "bgp large-community-list (1-99) <deny|permit> AA:BB:CC...",
14639 BGP_STR
14640 LCOMMUNITY_LIST_STR
14641 "Large Community list number (standard)\n"
14642 "Specify large community to reject\n"
14643 "Specify large community to accept\n"
14644 LCOMMUNITY_VAL_STR)
14645 {
14646 return lcommunity_list_set_vty(vty, argc, argv,
14647 LARGE_COMMUNITY_LIST_STANDARD, 0);
14648 }
14649
14650 ALIAS (lcommunity_list_standard1,
14651 ip_lcommunity_list_standard1_cmd,
14652 "ip large-community-list (1-99) <deny|permit> AA:BB:CC...",
14653 IP_STR
14654 LCOMMUNITY_LIST_STR
14655 "Large Community list number (standard)\n"
14656 "Specify large community to reject\n"
14657 "Specify large community to accept\n"
14658 LCOMMUNITY_VAL_STR)
14659
14660 DEFUN (lcommunity_list_expanded,
14661 bgp_lcommunity_list_expanded_cmd,
14662 "bgp large-community-list (100-500) <deny|permit> LINE...",
14663 BGP_STR
14664 LCOMMUNITY_LIST_STR
14665 "Large Community list number (expanded)\n"
14666 "Specify large community to reject\n"
14667 "Specify large community to accept\n"
14668 "An ordered list as a regular-expression\n")
14669 {
14670 return lcommunity_list_set_vty(vty, argc, argv,
14671 LARGE_COMMUNITY_LIST_EXPANDED, 0);
14672 }
14673
14674 ALIAS (lcommunity_list_expanded,
14675 ip_lcommunity_list_expanded_cmd,
14676 "ip large-community-list (100-500) <deny|permit> LINE...",
14677 IP_STR
14678 LCOMMUNITY_LIST_STR
14679 "Large Community list number (expanded)\n"
14680 "Specify large community to reject\n"
14681 "Specify large community to accept\n"
14682 "An ordered list as a regular-expression\n")
14683
14684 DEFUN (lcommunity_list_name_standard,
14685 bgp_lcommunity_list_name_standard_cmd,
14686 "bgp large-community-list standard WORD <deny|permit>",
14687 BGP_STR
14688 LCOMMUNITY_LIST_STR
14689 "Specify standard large-community-list\n"
14690 "Large Community list name\n"
14691 "Specify large community to reject\n"
14692 "Specify large community to accept\n")
14693 {
14694 return lcommunity_list_set_vty(vty, argc, argv,
14695 LARGE_COMMUNITY_LIST_STANDARD, 1);
14696 }
14697
14698 ALIAS (lcommunity_list_name_standard,
14699 ip_lcommunity_list_name_standard_cmd,
14700 "ip large-community-list standard WORD <deny|permit>",
14701 IP_STR
14702 LCOMMUNITY_LIST_STR
14703 "Specify standard large-community-list\n"
14704 "Large Community list name\n"
14705 "Specify large community to reject\n"
14706 "Specify large community to accept\n")
14707
14708 DEFUN (lcommunity_list_name_standard1,
14709 bgp_lcommunity_list_name_standard1_cmd,
14710 "bgp large-community-list standard WORD <deny|permit> AA:BB:CC...",
14711 BGP_STR
14712 LCOMMUNITY_LIST_STR
14713 "Specify standard large-community-list\n"
14714 "Large Community list name\n"
14715 "Specify large community to reject\n"
14716 "Specify large community to accept\n"
14717 LCOMMUNITY_VAL_STR)
14718 {
14719 return lcommunity_list_set_vty(vty, argc, argv,
14720 LARGE_COMMUNITY_LIST_STANDARD, 1);
14721 }
14722
14723 ALIAS (lcommunity_list_name_standard1,
14724 ip_lcommunity_list_name_standard1_cmd,
14725 "ip large-community-list standard WORD <deny|permit> AA:BB:CC...",
14726 IP_STR
14727 LCOMMUNITY_LIST_STR
14728 "Specify standard large-community-list\n"
14729 "Large Community list name\n"
14730 "Specify large community to reject\n"
14731 "Specify large community to accept\n"
14732 LCOMMUNITY_VAL_STR)
14733
14734 DEFUN (lcommunity_list_name_expanded,
14735 bgp_lcommunity_list_name_expanded_cmd,
14736 "bgp large-community-list expanded WORD <deny|permit> LINE...",
14737 BGP_STR
14738 LCOMMUNITY_LIST_STR
14739 "Specify expanded large-community-list\n"
14740 "Large Community list name\n"
14741 "Specify large community to reject\n"
14742 "Specify large community to accept\n"
14743 "An ordered list as a regular-expression\n")
14744 {
14745 return lcommunity_list_set_vty(vty, argc, argv,
14746 LARGE_COMMUNITY_LIST_EXPANDED, 1);
14747 }
14748
14749 ALIAS (lcommunity_list_name_expanded,
14750 ip_lcommunity_list_name_expanded_cmd,
14751 "ip large-community-list expanded WORD <deny|permit> LINE...",
14752 IP_STR
14753 LCOMMUNITY_LIST_STR
14754 "Specify expanded large-community-list\n"
14755 "Large Community list name\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 (no_lcommunity_list_standard_all,
14761 no_bgp_lcommunity_list_standard_all_cmd,
14762 "no bgp large-community-list <(1-99)|(100-500)|WORD>",
14763 NO_STR
14764 BGP_STR
14765 LCOMMUNITY_LIST_STR
14766 "Large Community list number (standard)\n"
14767 "Large Community list number (expanded)\n"
14768 "Large Community list name\n")
14769 {
14770 return lcommunity_list_unset_vty(vty, argc, argv,
14771 LARGE_COMMUNITY_LIST_STANDARD);
14772 }
14773
14774 ALIAS (no_lcommunity_list_standard_all,
14775 no_ip_lcommunity_list_standard_all_cmd,
14776 "no ip large-community-list <(1-99)|(100-500)|WORD>",
14777 NO_STR
14778 IP_STR
14779 LCOMMUNITY_LIST_STR
14780 "Large Community list number (standard)\n"
14781 "Large Community list number (expanded)\n"
14782 "Large Community list name\n")
14783
14784 DEFUN (no_lcommunity_list_name_expanded_all,
14785 no_bgp_lcommunity_list_name_expanded_all_cmd,
14786 "no bgp large-community-list expanded WORD",
14787 NO_STR
14788 BGP_STR
14789 LCOMMUNITY_LIST_STR
14790 "Specify expanded large-community-list\n"
14791 "Large Community list name\n")
14792 {
14793 return lcommunity_list_unset_vty(vty, argc, argv,
14794 LARGE_COMMUNITY_LIST_EXPANDED);
14795 }
14796
14797 ALIAS (no_lcommunity_list_name_expanded_all,
14798 no_ip_lcommunity_list_name_expanded_all_cmd,
14799 "no ip large-community-list expanded WORD",
14800 NO_STR
14801 IP_STR
14802 LCOMMUNITY_LIST_STR
14803 "Specify expanded large-community-list\n"
14804 "Large Community list name\n")
14805
14806 DEFUN (no_lcommunity_list_standard,
14807 no_bgp_lcommunity_list_standard_cmd,
14808 "no bgp large-community-list (1-99) <deny|permit> AA:AA:NN...",
14809 NO_STR
14810 BGP_STR
14811 LCOMMUNITY_LIST_STR
14812 "Large Community list number (standard)\n"
14813 "Specify large community to reject\n"
14814 "Specify large community to accept\n"
14815 LCOMMUNITY_VAL_STR)
14816 {
14817 return lcommunity_list_unset_vty(vty, argc, argv,
14818 LARGE_COMMUNITY_LIST_STANDARD);
14819 }
14820
14821 ALIAS (no_lcommunity_list_standard,
14822 no_ip_lcommunity_list_standard_cmd,
14823 "no ip large-community-list (1-99) <deny|permit> AA:AA:NN...",
14824 NO_STR
14825 IP_STR
14826 LCOMMUNITY_LIST_STR
14827 "Large Community list number (standard)\n"
14828 "Specify large community to reject\n"
14829 "Specify large community to accept\n"
14830 LCOMMUNITY_VAL_STR)
14831
14832 DEFUN (no_lcommunity_list_expanded,
14833 no_bgp_lcommunity_list_expanded_cmd,
14834 "no bgp large-community-list (100-500) <deny|permit> LINE...",
14835 NO_STR
14836 BGP_STR
14837 LCOMMUNITY_LIST_STR
14838 "Large Community list number (expanded)\n"
14839 "Specify large community to reject\n"
14840 "Specify large community to accept\n"
14841 "An ordered list as a regular-expression\n")
14842 {
14843 return lcommunity_list_unset_vty(vty, argc, argv,
14844 LARGE_COMMUNITY_LIST_EXPANDED);
14845 }
14846
14847 ALIAS (no_lcommunity_list_expanded,
14848 no_ip_lcommunity_list_expanded_cmd,
14849 "no ip large-community-list (100-500) <deny|permit> LINE...",
14850 NO_STR
14851 IP_STR
14852 LCOMMUNITY_LIST_STR
14853 "Large Community list number (expanded)\n"
14854 "Specify large community to reject\n"
14855 "Specify large community to accept\n"
14856 "An ordered list as a regular-expression\n")
14857
14858 DEFUN (no_lcommunity_list_name_standard,
14859 no_bgp_lcommunity_list_name_standard_cmd,
14860 "no bgp large-community-list standard WORD <deny|permit> AA:AA:NN...",
14861 NO_STR
14862 BGP_STR
14863 LCOMMUNITY_LIST_STR
14864 "Specify standard large-community-list\n"
14865 "Large Community list name\n"
14866 "Specify large community to reject\n"
14867 "Specify large community to accept\n"
14868 LCOMMUNITY_VAL_STR)
14869 {
14870 return lcommunity_list_unset_vty(vty, argc, argv,
14871 LARGE_COMMUNITY_LIST_STANDARD);
14872 }
14873
14874 ALIAS (no_lcommunity_list_name_standard,
14875 no_ip_lcommunity_list_name_standard_cmd,
14876 "no ip large-community-list standard WORD <deny|permit> AA:AA:NN...",
14877 NO_STR
14878 IP_STR
14879 LCOMMUNITY_LIST_STR
14880 "Specify standard large-community-list\n"
14881 "Large Community list name\n"
14882 "Specify large community to reject\n"
14883 "Specify large community to accept\n"
14884 LCOMMUNITY_VAL_STR)
14885
14886 DEFUN (no_lcommunity_list_name_expanded,
14887 no_bgp_lcommunity_list_name_expanded_cmd,
14888 "no bgp large-community-list expanded WORD <deny|permit> LINE...",
14889 NO_STR
14890 BGP_STR
14891 LCOMMUNITY_LIST_STR
14892 "Specify expanded large-community-list\n"
14893 "Large community list name\n"
14894 "Specify large community to reject\n"
14895 "Specify large community to accept\n"
14896 "An ordered list as a regular-expression\n")
14897 {
14898 return lcommunity_list_unset_vty(vty, argc, argv,
14899 LARGE_COMMUNITY_LIST_EXPANDED);
14900 }
14901
14902 ALIAS (no_lcommunity_list_name_expanded,
14903 no_ip_lcommunity_list_name_expanded_cmd,
14904 "no ip large-community-list expanded WORD <deny|permit> LINE...",
14905 NO_STR
14906 IP_STR
14907 LCOMMUNITY_LIST_STR
14908 "Specify expanded large-community-list\n"
14909 "Large community list name\n"
14910 "Specify large community to reject\n"
14911 "Specify large community to accept\n"
14912 "An ordered list as a regular-expression\n")
14913
14914 static void lcommunity_list_show(struct vty *vty, struct community_list *list)
14915 {
14916 struct community_entry *entry;
14917
14918 for (entry = list->head; entry; entry = entry->next) {
14919 if (entry == list->head) {
14920 if (all_digit(list->name))
14921 vty_out(vty, "Large community %s list %s\n",
14922 entry->style ==
14923 LARGE_COMMUNITY_LIST_STANDARD
14924 ? "standard"
14925 : "(expanded) access",
14926 list->name);
14927 else
14928 vty_out(vty,
14929 "Named large community %s list %s\n",
14930 entry->style ==
14931 LARGE_COMMUNITY_LIST_STANDARD
14932 ? "standard"
14933 : "expanded",
14934 list->name);
14935 }
14936 if (entry->any)
14937 vty_out(vty, " %s\n",
14938 community_direct_str(entry->direct));
14939 else
14940 vty_out(vty, " %s %s\n",
14941 community_direct_str(entry->direct),
14942 community_list_config_str(entry));
14943 }
14944 }
14945
14946 DEFUN (show_lcommunity_list,
14947 show_bgp_lcommunity_list_cmd,
14948 "show bgp large-community-list",
14949 SHOW_STR
14950 BGP_STR
14951 "List large-community list\n")
14952 {
14953 struct community_list *list;
14954 struct community_list_master *cm;
14955 int idx = 0;
14956
14957 if (argv_find(argv, argc, "ip", &idx)) {
14958 vty_out(vty, "This config option is deprecated, and is scheduled for removal.\n");
14959 vty_out(vty, "if you are using this please migrate to the below command.\n");
14960 vty_out(vty, "'show bgp large-community-list <(1-500)|WORD>'\n");
14961 zlog_warn("Deprecated option: 'ip show large-community-list <(1-500)|WORD>' being used");
14962 }
14963
14964 cm = community_list_master_lookup(bgp_clist,
14965 LARGE_COMMUNITY_LIST_MASTER);
14966 if (!cm)
14967 return CMD_SUCCESS;
14968
14969 for (list = cm->num.head; list; list = list->next)
14970 lcommunity_list_show(vty, list);
14971
14972 for (list = cm->str.head; list; list = list->next)
14973 lcommunity_list_show(vty, list);
14974
14975 return CMD_SUCCESS;
14976 }
14977
14978 ALIAS (show_lcommunity_list,
14979 show_ip_lcommunity_list_cmd,
14980 "show ip large-community-list",
14981 SHOW_STR
14982 IP_STR
14983 "List large-community list\n")
14984
14985 DEFUN (show_lcommunity_list_arg,
14986 show_bgp_lcommunity_list_arg_cmd,
14987 "show bgp large-community-list <(1-500)|WORD>",
14988 SHOW_STR
14989 BGP_STR
14990 "List large-community list\n"
14991 "large-community-list number\n"
14992 "large-community-list name\n")
14993 {
14994 struct community_list *list;
14995 int idx = 0;
14996
14997 if (argv_find(argv, argc, "ip", &idx)) {
14998 vty_out(vty, "This config option is deprecated, and is scheduled for removal.\n");
14999 vty_out(vty, "if you are using this please migrate to the below command.\n");
15000 vty_out(vty, "'show bgp large-community-list <(1-500)|WORD>'\n");
15001 zlog_warn("Deprecated option: 'ip show large-community-list <(1-500)|WORD>' being used");
15002 }
15003
15004 list = community_list_lookup(bgp_clist, argv[3]->arg, 0,
15005 LARGE_COMMUNITY_LIST_MASTER);
15006 if (!list) {
15007 vty_out(vty, "%% Can't find extcommunity-list\n");
15008 return CMD_WARNING;
15009 }
15010
15011 lcommunity_list_show(vty, list);
15012
15013 return CMD_SUCCESS;
15014 }
15015
15016 ALIAS (show_lcommunity_list_arg,
15017 show_ip_lcommunity_list_arg_cmd,
15018 "show ip large-community-list <(1-500)|WORD>",
15019 SHOW_STR
15020 IP_STR
15021 "List large-community list\n"
15022 "large-community-list number\n"
15023 "large-community-list name\n")
15024
15025 /* "extcommunity-list" keyword help string. */
15026 #define EXTCOMMUNITY_LIST_STR "Add a extended community list entry\n"
15027 #define EXTCOMMUNITY_VAL_STR "Extended community attribute in 'rt aa:nn_or_IPaddr:nn' OR 'soo aa:nn_or_IPaddr:nn' format\n"
15028
15029 DEFUN (extcommunity_list_standard,
15030 bgp_extcommunity_list_standard_cmd,
15031 "bgp extcommunity-list <(1-99)|standard WORD> <deny|permit> AA:NN...",
15032 BGP_STR
15033 EXTCOMMUNITY_LIST_STR
15034 "Extended Community list number (standard)\n"
15035 "Specify standard extcommunity-list\n"
15036 "Community list name\n"
15037 "Specify community to reject\n"
15038 "Specify community to accept\n"
15039 EXTCOMMUNITY_VAL_STR)
15040 {
15041 int style = EXTCOMMUNITY_LIST_STANDARD;
15042 int direct = 0;
15043 char *cl_number_or_name = NULL;
15044
15045 int idx = 0;
15046 if (argv_find(argv, argc, "ip", &idx)) {
15047 vty_out(vty, "This config option is deprecated, and is scheduled for removal.\n");
15048 vty_out(vty, "if you are using this please migrate to the below command.\n");
15049 vty_out(vty, "'bgp extcommunity-list <(1-99)|(100-500)|standard|expanded> <deny|permit> <LINE|AA:NN>'\n");
15050 zlog_warn("Deprecated option: 'ip extcommunity-list <(1-99)|(100-500)|standard|expanded> <deny|permit> <LINE|AA:NN>' being used");
15051 }
15052 argv_find(argv, argc, "(1-99)", &idx);
15053 argv_find(argv, argc, "WORD", &idx);
15054 cl_number_or_name = argv[idx]->arg;
15055 direct = argv_find(argv, argc, "permit", &idx) ? COMMUNITY_PERMIT
15056 : COMMUNITY_DENY;
15057 argv_find(argv, argc, "AA:NN", &idx);
15058 char *str = argv_concat(argv, argc, idx);
15059
15060 int ret = extcommunity_list_set(bgp_clist, cl_number_or_name, str,
15061 direct, style);
15062
15063 XFREE(MTYPE_TMP, str);
15064
15065 if (ret < 0) {
15066 community_list_perror(vty, ret);
15067 return CMD_WARNING_CONFIG_FAILED;
15068 }
15069
15070 return CMD_SUCCESS;
15071 }
15072
15073 #if CONFDATE > 20191005
15074 CPP_NOTICE("bgpd: remove deprecated 'ip extcommunity-list <(1-99)|(100-500)|standard|expanded> <deny|permit> <LINE|AA:NN>' command")
15075 #endif
15076 ALIAS (extcommunity_list_standard,
15077 ip_extcommunity_list_standard_cmd,
15078 "ip extcommunity-list <(1-99)|standard WORD> <deny|permit> AA:NN...",
15079 IP_STR
15080 EXTCOMMUNITY_LIST_STR
15081 "Extended Community list number (standard)\n"
15082 "Specify standard extcommunity-list\n"
15083 "Community list name\n"
15084 "Specify community to reject\n"
15085 "Specify community to accept\n"
15086 EXTCOMMUNITY_VAL_STR)
15087
15088 DEFUN (extcommunity_list_name_expanded,
15089 bgp_extcommunity_list_name_expanded_cmd,
15090 "bgp extcommunity-list <(100-500)|expanded WORD> <deny|permit> LINE...",
15091 BGP_STR
15092 EXTCOMMUNITY_LIST_STR
15093 "Extended Community list number (expanded)\n"
15094 "Specify expanded extcommunity-list\n"
15095 "Extended Community list name\n"
15096 "Specify community to reject\n"
15097 "Specify community to accept\n"
15098 "An ordered list as a regular-expression\n")
15099 {
15100 int style = EXTCOMMUNITY_LIST_EXPANDED;
15101 int direct = 0;
15102 char *cl_number_or_name = NULL;
15103
15104 int idx = 0;
15105 if (argv_find(argv, argc, "ip", &idx)) {
15106 vty_out(vty, "This config option is deprecated, and is scheduled for removal.\n");
15107 vty_out(vty, "if you are using this please migrate to the below command.\n");
15108 vty_out(vty, "'extcommunity-list <(1-99)|(100-500)|standard|expanded> <deny|permit> <LINE|AA:NN>'\n");
15109 zlog_warn("Deprecated option: ‘ip extcommunity-list <(1-99)|(100-500)|standard|expanded> <deny|permit> <LINE|AA:NN>' being used");
15110 }
15111
15112 argv_find(argv, argc, "(100-500)", &idx);
15113 argv_find(argv, argc, "WORD", &idx);
15114 cl_number_or_name = argv[idx]->arg;
15115 direct = argv_find(argv, argc, "permit", &idx) ? COMMUNITY_PERMIT
15116 : COMMUNITY_DENY;
15117 argv_find(argv, argc, "LINE", &idx);
15118 char *str = argv_concat(argv, argc, idx);
15119
15120 int ret = extcommunity_list_set(bgp_clist, cl_number_or_name, str,
15121 direct, style);
15122
15123 XFREE(MTYPE_TMP, str);
15124
15125 if (ret < 0) {
15126 community_list_perror(vty, ret);
15127 return CMD_WARNING_CONFIG_FAILED;
15128 }
15129
15130 return CMD_SUCCESS;
15131 }
15132
15133 ALIAS (extcommunity_list_name_expanded,
15134 ip_extcommunity_list_name_expanded_cmd,
15135 "ip extcommunity-list <(100-500)|expanded WORD> <deny|permit> LINE...",
15136 IP_STR
15137 EXTCOMMUNITY_LIST_STR
15138 "Extended Community list number (expanded)\n"
15139 "Specify expanded extcommunity-list\n"
15140 "Extended Community list name\n"
15141 "Specify community to reject\n"
15142 "Specify community to accept\n"
15143 "An ordered list as a regular-expression\n")
15144
15145 DEFUN (no_extcommunity_list_standard_all,
15146 no_bgp_extcommunity_list_standard_all_cmd,
15147 "no bgp extcommunity-list <(1-99)|standard WORD> <deny|permit> AA:NN...",
15148 NO_STR
15149 BGP_STR
15150 EXTCOMMUNITY_LIST_STR
15151 "Extended Community list number (standard)\n"
15152 "Specify standard extcommunity-list\n"
15153 "Community list name\n"
15154 "Specify community to reject\n"
15155 "Specify community to accept\n"
15156 EXTCOMMUNITY_VAL_STR)
15157 {
15158 int style = EXTCOMMUNITY_LIST_STANDARD;
15159 int direct = 0;
15160 char *cl_number_or_name = NULL;
15161 char *str = NULL;
15162
15163 int idx = 0;
15164 if (argv_find(argv, argc, "ip", &idx)) {
15165 vty_out(vty, "This config option is deprecated, and is scheduled for removal\n");
15166 vty_out(vty, "if you are using this please migrate to the below command.\n");
15167 vty_out(vty, "'no bgp extcommunity-list <(1-99)|(100-500)|standard|expanded> <deny|permit> <LINE|AA:NN>'\n");
15168 zlog_warn("Deprecated option: ‘no ip extcommunity-list <(1-99)|(100-500)|standard|expanded> <deny|permit> <LINE|AA:NN>' being used");
15169 }
15170
15171 idx = 0;
15172 argv_find(argv, argc, "permit", &idx);
15173 argv_find(argv, argc, "deny", &idx);
15174
15175 if (idx) {
15176 direct = argv_find(argv, argc, "permit", &idx)
15177 ? COMMUNITY_PERMIT
15178 : COMMUNITY_DENY;
15179
15180 idx = 0;
15181 argv_find(argv, argc, "AA:NN", &idx);
15182 str = argv_concat(argv, argc, idx);
15183 }
15184
15185 idx = 0;
15186 argv_find(argv, argc, "(1-99)", &idx);
15187 argv_find(argv, argc, "WORD", &idx);
15188 cl_number_or_name = argv[idx]->arg;
15189
15190 int ret = extcommunity_list_unset(bgp_clist, cl_number_or_name, str,
15191 direct, style);
15192
15193 XFREE(MTYPE_TMP, str);
15194
15195 if (ret < 0) {
15196 community_list_perror(vty, ret);
15197 return CMD_WARNING_CONFIG_FAILED;
15198 }
15199
15200 return CMD_SUCCESS;
15201 }
15202
15203 ALIAS (no_extcommunity_list_standard_all,
15204 no_ip_extcommunity_list_standard_all_cmd,
15205 "no ip extcommunity-list <(1-99)|standard WORD> <deny|permit> AA:NN...",
15206 NO_STR
15207 IP_STR
15208 EXTCOMMUNITY_LIST_STR
15209 "Extended Community list number (standard)\n"
15210 "Specify standard extcommunity-list\n"
15211 "Community list name\n"
15212 "Specify community to reject\n"
15213 "Specify community to accept\n"
15214 EXTCOMMUNITY_VAL_STR)
15215
15216 ALIAS(no_extcommunity_list_standard_all,
15217 no_bgp_extcommunity_list_standard_all_list_cmd,
15218 "no bgp extcommunity-list <(1-99)|standard WORD>",
15219 NO_STR IP_STR EXTCOMMUNITY_LIST_STR
15220 "Extended Community list number (standard)\n"
15221 "Specify standard extcommunity-list\n"
15222 "Community list name\n")
15223
15224 ALIAS(no_extcommunity_list_standard_all,
15225 no_ip_extcommunity_list_standard_all_list_cmd,
15226 "no ip extcommunity-list <(1-99)|standard WORD>",
15227 NO_STR IP_STR EXTCOMMUNITY_LIST_STR
15228 "Extended Community list number (standard)\n"
15229 "Specify standard extcommunity-list\n"
15230 "Community list name\n")
15231
15232 DEFUN (no_extcommunity_list_expanded_all,
15233 no_bgp_extcommunity_list_expanded_all_cmd,
15234 "no bgp extcommunity-list <(100-500)|expanded WORD> <deny|permit> LINE...",
15235 NO_STR
15236 BGP_STR
15237 EXTCOMMUNITY_LIST_STR
15238 "Extended Community list number (expanded)\n"
15239 "Specify expanded extcommunity-list\n"
15240 "Extended Community list name\n"
15241 "Specify community to reject\n"
15242 "Specify community to accept\n"
15243 "An ordered list as a regular-expression\n")
15244 {
15245 int style = EXTCOMMUNITY_LIST_EXPANDED;
15246 int direct = 0;
15247 char *cl_number_or_name = NULL;
15248 char *str = NULL;
15249
15250 int idx = 0;
15251 if (argv_find(argv, argc, "ip", &idx)) {
15252 vty_out(vty, "This config option is deprecated, and is scheduled for removal.\n");
15253 vty_out(vty, "if you are using this please migrate to the below command.\n");
15254 vty_out(vty, "'no bgp extcommunity-list <(1-99)|(100-500)|standard|expanded> <deny|permit> <LINE|AA:NN>'\n");
15255 zlog_warn("Deprecated option: ‘no ip extcommunity-list <(1-99)|(100-500)|standard|expanded> <deny|permit> <LINE|AA:NN>' being used");
15256 }
15257
15258 idx = 0;
15259 argv_find(argv, argc, "permit", &idx);
15260 argv_find(argv, argc, "deny", &idx);
15261
15262 if (idx) {
15263 direct = argv_find(argv, argc, "permit", &idx)
15264 ? COMMUNITY_PERMIT
15265 : COMMUNITY_DENY;
15266
15267 idx = 0;
15268 argv_find(argv, argc, "LINE", &idx);
15269 str = argv_concat(argv, argc, idx);
15270 }
15271
15272 idx = 0;
15273 argv_find(argv, argc, "(100-500)", &idx);
15274 argv_find(argv, argc, "WORD", &idx);
15275 cl_number_or_name = argv[idx]->arg;
15276
15277 int ret = extcommunity_list_unset(bgp_clist, cl_number_or_name, str,
15278 direct, style);
15279
15280 XFREE(MTYPE_TMP, str);
15281
15282 if (ret < 0) {
15283 community_list_perror(vty, ret);
15284 return CMD_WARNING_CONFIG_FAILED;
15285 }
15286
15287 return CMD_SUCCESS;
15288 }
15289
15290 ALIAS (no_extcommunity_list_expanded_all,
15291 no_ip_extcommunity_list_expanded_all_cmd,
15292 "no ip extcommunity-list <(100-500)|expanded WORD> <deny|permit> LINE...",
15293 NO_STR
15294 IP_STR
15295 EXTCOMMUNITY_LIST_STR
15296 "Extended Community list number (expanded)\n"
15297 "Specify expanded extcommunity-list\n"
15298 "Extended Community list name\n"
15299 "Specify community to reject\n"
15300 "Specify community to accept\n"
15301 "An ordered list as a regular-expression\n")
15302
15303 ALIAS(no_extcommunity_list_expanded_all,
15304 no_ip_extcommunity_list_expanded_all_list_cmd,
15305 "no ip extcommunity-list <(100-500)|expanded WORD>",
15306 NO_STR IP_STR EXTCOMMUNITY_LIST_STR
15307 "Extended Community list number (expanded)\n"
15308 "Specify expanded extcommunity-list\n"
15309 "Extended Community list name\n")
15310
15311 ALIAS(no_extcommunity_list_expanded_all,
15312 no_bgp_extcommunity_list_expanded_all_list_cmd,
15313 "no bgp extcommunity-list <(100-500)|expanded WORD>",
15314 NO_STR IP_STR EXTCOMMUNITY_LIST_STR
15315 "Extended Community list number (expanded)\n"
15316 "Specify expanded extcommunity-list\n"
15317 "Extended Community list name\n")
15318
15319 static void extcommunity_list_show(struct vty *vty, struct community_list *list)
15320 {
15321 struct community_entry *entry;
15322
15323 for (entry = list->head; entry; entry = entry->next) {
15324 if (entry == list->head) {
15325 if (all_digit(list->name))
15326 vty_out(vty, "Extended community %s list %s\n",
15327 entry->style == EXTCOMMUNITY_LIST_STANDARD
15328 ? "standard"
15329 : "(expanded) access",
15330 list->name);
15331 else
15332 vty_out(vty,
15333 "Named extended community %s list %s\n",
15334 entry->style == EXTCOMMUNITY_LIST_STANDARD
15335 ? "standard"
15336 : "expanded",
15337 list->name);
15338 }
15339 if (entry->any)
15340 vty_out(vty, " %s\n",
15341 community_direct_str(entry->direct));
15342 else
15343 vty_out(vty, " %s %s\n",
15344 community_direct_str(entry->direct),
15345 community_list_config_str(entry));
15346 }
15347 }
15348
15349 DEFUN (show_extcommunity_list,
15350 show_bgp_extcommunity_list_cmd,
15351 "show bgp extcommunity-list",
15352 SHOW_STR
15353 BGP_STR
15354 "List extended-community list\n")
15355 {
15356 struct community_list *list;
15357 struct community_list_master *cm;
15358 int idx = 0;
15359
15360 if (argv_find(argv, argc, "ip", &idx)) {
15361 vty_out(vty, "This config option is deprecated, and is scheduled for removal\n");
15362 vty_out(vty, "if you are using this please migrate to the below command.\n");
15363 vty_out(vty, "'show bgp extcommunity-list <(1-500)|WORD>'\n");
15364 zlog_warn("Deprecated option: 'ip show extcommunity-list <(1-500)|WORD>' being used");
15365 }
15366 cm = community_list_master_lookup(bgp_clist, EXTCOMMUNITY_LIST_MASTER);
15367 if (!cm)
15368 return CMD_SUCCESS;
15369
15370 for (list = cm->num.head; list; list = list->next)
15371 extcommunity_list_show(vty, list);
15372
15373 for (list = cm->str.head; list; list = list->next)
15374 extcommunity_list_show(vty, list);
15375
15376 return CMD_SUCCESS;
15377 }
15378
15379 ALIAS (show_extcommunity_list,
15380 show_ip_extcommunity_list_cmd,
15381 "show ip extcommunity-list",
15382 SHOW_STR
15383 IP_STR
15384 "List extended-community list\n")
15385
15386 DEFUN (show_extcommunity_list_arg,
15387 show_bgp_extcommunity_list_arg_cmd,
15388 "show bgp extcommunity-list <(1-500)|WORD>",
15389 SHOW_STR
15390 BGP_STR
15391 "List extended-community list\n"
15392 "Extcommunity-list number\n"
15393 "Extcommunity-list name\n")
15394 {
15395 int idx_comm_list = 3;
15396 struct community_list *list;
15397 int idx = 0;
15398
15399 if (argv_find(argv, argc, "ip", &idx)) {
15400 vty_out(vty, "This config option is deprecated, and is scheduled for removal.\n");
15401 vty_out(vty, "if you are using this please migrate to the below command.\n");
15402 vty_out(vty, "'show bgp extcommunity-list <(1-500)|WORD>'\n");
15403 zlog_warn("Deprecated option: 'ip show extcommunity-list <(1-500)|WORD>' being used");
15404 }
15405 list = community_list_lookup(bgp_clist, argv[idx_comm_list]->arg, 0,
15406 EXTCOMMUNITY_LIST_MASTER);
15407 if (!list) {
15408 vty_out(vty, "%% Can't find extcommunity-list\n");
15409 return CMD_WARNING;
15410 }
15411
15412 extcommunity_list_show(vty, list);
15413
15414 return CMD_SUCCESS;
15415 }
15416
15417 ALIAS (show_extcommunity_list_arg,
15418 show_ip_extcommunity_list_arg_cmd,
15419 "show ip extcommunity-list <(1-500)|WORD>",
15420 SHOW_STR
15421 IP_STR
15422 "List extended-community list\n"
15423 "Extcommunity-list number\n"
15424 "Extcommunity-list name\n")
15425
15426 /* Display community-list and extcommunity-list configuration. */
15427 static int community_list_config_write(struct vty *vty)
15428 {
15429 struct community_list *list;
15430 struct community_entry *entry;
15431 struct community_list_master *cm;
15432 int write = 0;
15433
15434 /* Community-list. */
15435 cm = community_list_master_lookup(bgp_clist, COMMUNITY_LIST_MASTER);
15436
15437 for (list = cm->num.head; list; list = list->next)
15438 for (entry = list->head; entry; entry = entry->next) {
15439 vty_out(vty, "bgp community-list %s %s %s\n", list->name,
15440 community_direct_str(entry->direct),
15441 community_list_config_str(entry));
15442 write++;
15443 }
15444 for (list = cm->str.head; list; list = list->next)
15445 for (entry = list->head; entry; entry = entry->next) {
15446 vty_out(vty, "bgp community-list %s %s %s %s\n",
15447 entry->style == COMMUNITY_LIST_STANDARD
15448 ? "standard"
15449 : "expanded",
15450 list->name, community_direct_str(entry->direct),
15451 community_list_config_str(entry));
15452 write++;
15453 }
15454
15455 /* Extcommunity-list. */
15456 cm = community_list_master_lookup(bgp_clist, EXTCOMMUNITY_LIST_MASTER);
15457
15458 for (list = cm->num.head; list; list = list->next)
15459 for (entry = list->head; entry; entry = entry->next) {
15460 vty_out(vty, "bgp extcommunity-list %s %s %s\n",
15461 list->name, community_direct_str(entry->direct),
15462 community_list_config_str(entry));
15463 write++;
15464 }
15465 for (list = cm->str.head; list; list = list->next)
15466 for (entry = list->head; entry; entry = entry->next) {
15467 vty_out(vty, "bgp extcommunity-list %s %s %s %s\n",
15468 entry->style == EXTCOMMUNITY_LIST_STANDARD
15469 ? "standard"
15470 : "expanded",
15471 list->name, community_direct_str(entry->direct),
15472 community_list_config_str(entry));
15473 write++;
15474 }
15475
15476
15477 /* lcommunity-list. */
15478 cm = community_list_master_lookup(bgp_clist,
15479 LARGE_COMMUNITY_LIST_MASTER);
15480
15481 for (list = cm->num.head; list; list = list->next)
15482 for (entry = list->head; entry; entry = entry->next) {
15483 vty_out(vty, "bgp large-community-list %s %s %s\n",
15484 list->name, community_direct_str(entry->direct),
15485 community_list_config_str(entry));
15486 write++;
15487 }
15488 for (list = cm->str.head; list; list = list->next)
15489 for (entry = list->head; entry; entry = entry->next) {
15490 vty_out(vty, "bgp large-community-list %s %s %s %s\n",
15491 entry->style == LARGE_COMMUNITY_LIST_STANDARD
15492 ? "standard"
15493 : "expanded",
15494 list->name, community_direct_str(entry->direct),
15495 community_list_config_str(entry));
15496 write++;
15497 }
15498
15499 return write;
15500 }
15501
15502 static struct cmd_node community_list_node = {
15503 COMMUNITY_LIST_NODE, "", 1 /* Export to vtysh. */
15504 };
15505
15506 static void community_list_vty(void)
15507 {
15508 install_node(&community_list_node, community_list_config_write);
15509
15510 /* Community-list. */
15511 install_element(CONFIG_NODE, &bgp_community_list_standard_cmd);
15512 install_element(CONFIG_NODE, &bgp_community_list_expanded_all_cmd);
15513 install_element(CONFIG_NODE, &no_bgp_community_list_standard_all_cmd);
15514 install_element(CONFIG_NODE, &no_bgp_community_list_standard_all_list_cmd);
15515 install_element(CONFIG_NODE, &no_bgp_community_list_expanded_all_cmd);
15516 install_element(CONFIG_NODE, &no_bgp_community_list_expanded_all_list_cmd);
15517 install_element(VIEW_NODE, &show_bgp_community_list_cmd);
15518 install_element(VIEW_NODE, &show_bgp_community_list_arg_cmd);
15519 install_element(CONFIG_NODE, &ip_community_list_standard_cmd);
15520 install_element(CONFIG_NODE, &ip_community_list_expanded_all_cmd);
15521 install_element(CONFIG_NODE, &no_ip_community_list_standard_all_cmd);
15522 install_element(CONFIG_NODE, &no_ip_community_list_standard_all_list_cmd);
15523 install_element(CONFIG_NODE, &no_ip_community_list_expanded_all_cmd);
15524 install_element(CONFIG_NODE, &no_ip_community_list_expanded_all_list_cmd);
15525 install_element(VIEW_NODE, &show_ip_community_list_cmd);
15526 install_element(VIEW_NODE, &show_ip_community_list_arg_cmd);
15527
15528 /* Extcommunity-list. */
15529 install_element(CONFIG_NODE, &bgp_extcommunity_list_standard_cmd);
15530 install_element(CONFIG_NODE, &bgp_extcommunity_list_name_expanded_cmd);
15531 install_element(CONFIG_NODE, &no_bgp_extcommunity_list_standard_all_cmd);
15532 install_element(CONFIG_NODE,
15533 &no_bgp_extcommunity_list_standard_all_list_cmd);
15534 install_element(CONFIG_NODE, &no_bgp_extcommunity_list_expanded_all_cmd);
15535 install_element(CONFIG_NODE,
15536 &no_bgp_extcommunity_list_expanded_all_list_cmd);
15537 install_element(VIEW_NODE, &show_bgp_extcommunity_list_cmd);
15538 install_element(VIEW_NODE, &show_bgp_extcommunity_list_arg_cmd);
15539 install_element(CONFIG_NODE, &ip_extcommunity_list_standard_cmd);
15540 install_element(CONFIG_NODE, &ip_extcommunity_list_name_expanded_cmd);
15541 install_element(CONFIG_NODE, &no_ip_extcommunity_list_standard_all_cmd);
15542 install_element(CONFIG_NODE, &no_ip_extcommunity_list_standard_all_list_cmd);
15543 install_element(CONFIG_NODE, &no_ip_extcommunity_list_expanded_all_cmd);
15544 install_element(CONFIG_NODE, &no_ip_extcommunity_list_expanded_all_list_cmd);
15545 install_element(VIEW_NODE, &show_ip_extcommunity_list_cmd);
15546 install_element(VIEW_NODE, &show_ip_extcommunity_list_arg_cmd);
15547
15548 /* Large Community List */
15549 install_element(CONFIG_NODE, &bgp_lcommunity_list_standard_cmd);
15550 install_element(CONFIG_NODE, &bgp_lcommunity_list_standard1_cmd);
15551 install_element(CONFIG_NODE, &bgp_lcommunity_list_expanded_cmd);
15552 install_element(CONFIG_NODE, &bgp_lcommunity_list_name_standard_cmd);
15553 install_element(CONFIG_NODE, &bgp_lcommunity_list_name_standard1_cmd);
15554 install_element(CONFIG_NODE, &bgp_lcommunity_list_name_expanded_cmd);
15555 install_element(CONFIG_NODE, &no_bgp_lcommunity_list_standard_all_cmd);
15556 install_element(CONFIG_NODE,
15557 &no_bgp_lcommunity_list_name_expanded_all_cmd);
15558 install_element(CONFIG_NODE, &no_bgp_lcommunity_list_standard_cmd);
15559 install_element(CONFIG_NODE, &no_bgp_lcommunity_list_expanded_cmd);
15560 install_element(CONFIG_NODE, &no_bgp_lcommunity_list_name_standard_cmd);
15561 install_element(CONFIG_NODE, &no_bgp_lcommunity_list_name_expanded_cmd);
15562 install_element(VIEW_NODE, &show_bgp_lcommunity_list_cmd);
15563 install_element(VIEW_NODE, &show_bgp_lcommunity_list_arg_cmd);
15564 install_element(CONFIG_NODE, &ip_lcommunity_list_standard_cmd);
15565 install_element(CONFIG_NODE, &ip_lcommunity_list_standard1_cmd);
15566 install_element(CONFIG_NODE, &ip_lcommunity_list_expanded_cmd);
15567 install_element(CONFIG_NODE, &ip_lcommunity_list_name_standard_cmd);
15568 install_element(CONFIG_NODE, &ip_lcommunity_list_name_standard1_cmd);
15569 install_element(CONFIG_NODE, &ip_lcommunity_list_name_expanded_cmd);
15570 install_element(CONFIG_NODE, &no_ip_lcommunity_list_standard_all_cmd);
15571 install_element(CONFIG_NODE,
15572 &no_ip_lcommunity_list_name_expanded_all_cmd);
15573 install_element(CONFIG_NODE, &no_ip_lcommunity_list_standard_cmd);
15574 install_element(CONFIG_NODE, &no_ip_lcommunity_list_expanded_cmd);
15575 install_element(CONFIG_NODE, &no_ip_lcommunity_list_name_standard_cmd);
15576 install_element(CONFIG_NODE, &no_ip_lcommunity_list_name_expanded_cmd);
15577 install_element(VIEW_NODE, &show_ip_lcommunity_list_cmd);
15578 install_element(VIEW_NODE, &show_ip_lcommunity_list_arg_cmd);
15579 }