]> git.proxmox.com Git - mirror_frr.git/blob - bgpd/bgp_vty.c
bgpd: BGP_ERR_MULTIPLE_INSTANCE_NOT_SET is an impossible condition
[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 else
628 found = true;
629 }
630
631 /* This is to apply read-only mode on this clear. */
632 if (stype == BGP_CLEAR_SOFT_NONE)
633 bgp->update_delay_over = 0;
634
635 if (!found)
636 vty_out(vty, "%%BGP: No %s peer configured\n",
637 afi_safi_print(afi, safi));
638
639 return CMD_SUCCESS;
640 }
641
642 /* Clear specified neighbor. */
643 if (sort == clear_peer) {
644 union sockunion su;
645
646 /* Make sockunion for lookup. */
647 ret = str2sockunion(arg, &su);
648 if (ret < 0) {
649 peer = peer_lookup_by_conf_if(bgp, arg);
650 if (!peer) {
651 peer = peer_lookup_by_hostname(bgp, arg);
652 if (!peer) {
653 vty_out(vty,
654 "Malformed address or name: %s\n",
655 arg);
656 return CMD_WARNING;
657 }
658 }
659 } else {
660 peer = peer_lookup(bgp, &su);
661 if (!peer) {
662 vty_out(vty,
663 "%%BGP: Unknown neighbor - \"%s\"\n",
664 arg);
665 return CMD_WARNING;
666 }
667 }
668
669 if (!peer->afc[afi][safi])
670 ret = BGP_ERR_AF_UNCONFIGURED;
671 else if (stype == BGP_CLEAR_SOFT_NONE)
672 ret = peer_clear(peer, NULL);
673 else
674 ret = peer_clear_soft(peer, afi, safi, stype);
675
676 if (ret < 0)
677 bgp_clear_vty_error(vty, peer, afi, safi, ret);
678
679 return CMD_SUCCESS;
680 }
681
682 /* Clear all neighbors belonging to a specific peer-group. */
683 if (sort == clear_group) {
684 struct peer_group *group;
685
686 group = peer_group_lookup(bgp, arg);
687 if (!group) {
688 vty_out(vty, "%%BGP: No such peer-group %s\n", arg);
689 return CMD_WARNING;
690 }
691
692 for (ALL_LIST_ELEMENTS(group->peer, node, nnode, peer)) {
693 if (!peer->afc[afi][safi])
694 continue;
695
696 if (stype == BGP_CLEAR_SOFT_NONE)
697 ret = peer_clear(peer, NULL);
698 else
699 ret = peer_clear_soft(peer, afi, safi, stype);
700
701 if (ret < 0)
702 bgp_clear_vty_error(vty, peer, afi, safi, ret);
703 else
704 found = true;
705 }
706
707 if (!found)
708 vty_out(vty,
709 "%%BGP: No %s peer belonging to peer-group %s is configured\n",
710 afi_safi_print(afi, safi), arg);
711
712 return CMD_SUCCESS;
713 }
714
715 /* Clear all external (eBGP) neighbors. */
716 if (sort == clear_external) {
717 for (ALL_LIST_ELEMENTS(bgp->peer, node, nnode, peer)) {
718 if (peer->sort == BGP_PEER_IBGP)
719 continue;
720
721 if (!peer->afc[afi][safi])
722 continue;
723
724 if (stype == BGP_CLEAR_SOFT_NONE)
725 ret = peer_clear(peer, &nnode);
726 else
727 ret = peer_clear_soft(peer, afi, safi, stype);
728
729 if (ret < 0)
730 bgp_clear_vty_error(vty, peer, afi, safi, ret);
731 else
732 found = true;
733 }
734
735 if (!found)
736 vty_out(vty,
737 "%%BGP: No external %s peer is configured\n",
738 afi_safi_print(afi, safi));
739
740 return CMD_SUCCESS;
741 }
742
743 /* Clear all neighbors belonging to a specific AS. */
744 if (sort == clear_as) {
745 as_t as = strtoul(arg, NULL, 10);
746
747 for (ALL_LIST_ELEMENTS(bgp->peer, node, nnode, peer)) {
748 if (peer->as != as)
749 continue;
750
751 if (!peer->afc[afi][safi])
752 ret = BGP_ERR_AF_UNCONFIGURED;
753 else if (stype == BGP_CLEAR_SOFT_NONE)
754 ret = peer_clear(peer, &nnode);
755 else
756 ret = peer_clear_soft(peer, afi, safi, stype);
757
758 if (ret < 0)
759 bgp_clear_vty_error(vty, peer, afi, safi, ret);
760 else
761 found = true;
762 }
763
764 if (!found)
765 vty_out(vty,
766 "%%BGP: No %s peer is configured with AS %s\n",
767 afi_safi_print(afi, safi), arg);
768
769 return CMD_SUCCESS;
770 }
771
772 return CMD_SUCCESS;
773 }
774
775 static int bgp_clear_vty(struct vty *vty, const char *name, afi_t afi,
776 safi_t safi, enum clear_sort sort,
777 enum bgp_clear_type stype, const char *arg)
778 {
779 struct bgp *bgp;
780
781 /* BGP structure lookup. */
782 if (name) {
783 bgp = bgp_lookup_by_name(name);
784 if (bgp == NULL) {
785 vty_out(vty, "Can't find BGP instance %s\n", name);
786 return CMD_WARNING;
787 }
788 } else {
789 bgp = bgp_get_default();
790 if (bgp == NULL) {
791 vty_out(vty, "No BGP process is configured\n");
792 return CMD_WARNING;
793 }
794 }
795
796 return bgp_clear(vty, bgp, afi, safi, sort, stype, arg);
797 }
798
799 /* clear soft inbound */
800 static void bgp_clear_star_soft_in(struct vty *vty, const char *name)
801 {
802 afi_t afi;
803 safi_t safi;
804
805 FOREACH_AFI_SAFI (afi, safi)
806 bgp_clear_vty(vty, name, afi, safi, clear_all,
807 BGP_CLEAR_SOFT_IN, NULL);
808 }
809
810 /* clear soft outbound */
811 static void bgp_clear_star_soft_out(struct vty *vty, const char *name)
812 {
813 afi_t afi;
814 safi_t safi;
815
816 FOREACH_AFI_SAFI (afi, safi)
817 bgp_clear_vty(vty, name, afi, safi, clear_all,
818 BGP_CLEAR_SOFT_OUT, NULL);
819 }
820
821
822 #ifndef VTYSH_EXTRACT_PL
823 #include "bgpd/bgp_vty_clippy.c"
824 #endif
825
826 DEFUN_HIDDEN (bgp_local_mac,
827 bgp_local_mac_cmd,
828 "bgp local-mac vni " CMD_VNI_RANGE " mac WORD seq (0-4294967295)",
829 BGP_STR
830 "Local MAC config\n"
831 "VxLAN Network Identifier\n"
832 "VNI number\n"
833 "local mac\n"
834 "mac address\n"
835 "mac-mobility sequence\n"
836 "seq number\n")
837 {
838 int rv;
839 vni_t vni;
840 struct ethaddr mac;
841 struct ipaddr ip;
842 uint32_t seq;
843 struct bgp *bgp;
844
845 vni = strtoul(argv[3]->arg, NULL, 10);
846 if (!prefix_str2mac(argv[5]->arg, &mac)) {
847 vty_out(vty, "%% Malformed MAC address\n");
848 return CMD_WARNING;
849 }
850 memset(&ip, 0, sizeof(ip));
851 seq = strtoul(argv[7]->arg, NULL, 10);
852
853 bgp = bgp_get_default();
854 if (!bgp) {
855 vty_out(vty, "Default BGP instance is not there\n");
856 return CMD_WARNING;
857 }
858
859 rv = bgp_evpn_local_macip_add(bgp, vni, &mac, &ip, 0 /* flags */, seq);
860 if (rv < 0) {
861 vty_out(vty, "Internal error\n");
862 return CMD_WARNING;
863 }
864
865 return CMD_SUCCESS;
866 }
867
868 DEFUN_HIDDEN (no_bgp_local_mac,
869 no_bgp_local_mac_cmd,
870 "no bgp local-mac vni " CMD_VNI_RANGE " mac WORD",
871 NO_STR
872 BGP_STR
873 "Local MAC config\n"
874 "VxLAN Network Identifier\n"
875 "VNI number\n"
876 "local mac\n"
877 "mac address\n")
878 {
879 int rv;
880 vni_t vni;
881 struct ethaddr mac;
882 struct ipaddr ip;
883 struct bgp *bgp;
884
885 vni = strtoul(argv[4]->arg, NULL, 10);
886 if (!prefix_str2mac(argv[6]->arg, &mac)) {
887 vty_out(vty, "%% Malformed MAC address\n");
888 return CMD_WARNING;
889 }
890 memset(&ip, 0, sizeof(ip));
891
892 bgp = bgp_get_default();
893 if (!bgp) {
894 vty_out(vty, "Default BGP instance is not there\n");
895 return CMD_WARNING;
896 }
897
898 rv = bgp_evpn_local_macip_del(bgp, vni, &mac, &ip, ZEBRA_NEIGH_ACTIVE);
899 if (rv < 0) {
900 vty_out(vty, "Internal error\n");
901 return CMD_WARNING;
902 }
903
904 return CMD_SUCCESS;
905 }
906
907 DEFUN (no_synchronization,
908 no_synchronization_cmd,
909 "no synchronization",
910 NO_STR
911 "Perform IGP synchronization\n")
912 {
913 return CMD_SUCCESS;
914 }
915
916 DEFUN (no_auto_summary,
917 no_auto_summary_cmd,
918 "no auto-summary",
919 NO_STR
920 "Enable automatic network number summarization\n")
921 {
922 return CMD_SUCCESS;
923 }
924
925 /* "router bgp" commands. */
926 DEFUN_NOSH (router_bgp,
927 router_bgp_cmd,
928 "router bgp [(1-4294967295) [<view|vrf> VIEWVRFNAME]]",
929 ROUTER_STR
930 BGP_STR
931 AS_STR
932 BGP_INSTANCE_HELP_STR)
933 {
934 int idx_asn = 2;
935 int idx_view_vrf = 3;
936 int idx_vrf = 4;
937 int is_new_bgp = 0;
938 int ret;
939 as_t as;
940 struct bgp *bgp;
941 const char *name = NULL;
942 enum bgp_instance_type inst_type;
943
944 // "router bgp" without an ASN
945 if (argc == 2) {
946 // Pending: Make VRF option available for ASN less config
947 bgp = bgp_get_default();
948
949 if (bgp == NULL) {
950 vty_out(vty, "%% No BGP process is configured\n");
951 return CMD_WARNING_CONFIG_FAILED;
952 }
953
954 if (listcount(bm->bgp) > 1) {
955 vty_out(vty, "%% Please specify ASN and VRF\n");
956 return CMD_WARNING_CONFIG_FAILED;
957 }
958 }
959
960 // "router bgp X"
961 else {
962 as = strtoul(argv[idx_asn]->arg, NULL, 10);
963
964 inst_type = BGP_INSTANCE_TYPE_DEFAULT;
965 if (argc > 3) {
966 name = argv[idx_vrf]->arg;
967
968 if (!strcmp(argv[idx_view_vrf]->text, "vrf")) {
969 if (strmatch(name, VRF_DEFAULT_NAME))
970 name = NULL;
971 else
972 inst_type = BGP_INSTANCE_TYPE_VRF;
973 } else if (!strcmp(argv[idx_view_vrf]->text, "view"))
974 inst_type = BGP_INSTANCE_TYPE_VIEW;
975 }
976
977 if (inst_type == BGP_INSTANCE_TYPE_DEFAULT)
978 is_new_bgp = (bgp_lookup(as, name) == NULL);
979
980 ret = bgp_get(&bgp, &as, name, inst_type);
981 switch (ret) {
982 case BGP_ERR_AS_MISMATCH:
983 vty_out(vty, "BGP is already running; AS is %u\n", as);
984 return CMD_WARNING_CONFIG_FAILED;
985 case BGP_ERR_INSTANCE_MISMATCH:
986 vty_out(vty,
987 "BGP instance name and AS number mismatch\n");
988 vty_out(vty,
989 "BGP instance is already running; AS is %u\n",
990 as);
991 return CMD_WARNING_CONFIG_FAILED;
992 }
993
994 /*
995 * If we just instantiated the default instance, complete
996 * any pending VRF-VPN leaking that was configured via
997 * earlier "router bgp X vrf FOO" blocks.
998 */
999 if (is_new_bgp && inst_type == BGP_INSTANCE_TYPE_DEFAULT)
1000 vpn_leak_postchange_all();
1001
1002 /* Pending: handle when user tries to change a view to vrf n vv.
1003 */
1004 }
1005
1006 /* unset the auto created flag as the user config is now present */
1007 UNSET_FLAG(bgp->vrf_flags, BGP_VRF_AUTO);
1008 VTY_PUSH_CONTEXT(BGP_NODE, bgp);
1009
1010 return CMD_SUCCESS;
1011 }
1012
1013 /* "no router bgp" commands. */
1014 DEFUN (no_router_bgp,
1015 no_router_bgp_cmd,
1016 "no router bgp [(1-4294967295) [<view|vrf> VIEWVRFNAME]]",
1017 NO_STR
1018 ROUTER_STR
1019 BGP_STR
1020 AS_STR
1021 BGP_INSTANCE_HELP_STR)
1022 {
1023 int idx_asn = 3;
1024 int idx_vrf = 5;
1025 as_t as;
1026 struct bgp *bgp;
1027 const char *name = NULL;
1028
1029 // "no router bgp" without an ASN
1030 if (argc == 3) {
1031 // Pending: Make VRF option available for ASN less config
1032 bgp = bgp_get_default();
1033
1034 if (bgp == NULL) {
1035 vty_out(vty, "%% No BGP process is configured\n");
1036 return CMD_WARNING_CONFIG_FAILED;
1037 }
1038
1039 if (listcount(bm->bgp) > 1) {
1040 vty_out(vty, "%% Please specify ASN and VRF\n");
1041 return CMD_WARNING_CONFIG_FAILED;
1042 }
1043
1044 if (bgp->l3vni) {
1045 vty_out(vty, "%% Please unconfigure l3vni %u",
1046 bgp->l3vni);
1047 return CMD_WARNING_CONFIG_FAILED;
1048 }
1049 } else {
1050 as = strtoul(argv[idx_asn]->arg, NULL, 10);
1051
1052 if (argc > 4)
1053 name = argv[idx_vrf]->arg;
1054
1055 /* Lookup bgp structure. */
1056 bgp = bgp_lookup(as, name);
1057 if (!bgp) {
1058 vty_out(vty, "%% Can't find BGP instance\n");
1059 return CMD_WARNING_CONFIG_FAILED;
1060 }
1061
1062 if (bgp->l3vni) {
1063 vty_out(vty, "%% Please unconfigure l3vni %u\n",
1064 bgp->l3vni);
1065 return CMD_WARNING_CONFIG_FAILED;
1066 }
1067
1068 /* Cannot delete default instance if vrf instances exist */
1069 if (bgp->inst_type == BGP_INSTANCE_TYPE_DEFAULT) {
1070 struct listnode *node;
1071 struct bgp *tmp_bgp;
1072
1073 for (ALL_LIST_ELEMENTS_RO(bm->bgp, node, tmp_bgp)) {
1074 if (tmp_bgp->inst_type
1075 == BGP_INSTANCE_TYPE_VRF) {
1076 vty_out(vty,
1077 "%% Cannot delete default BGP instance. Dependent VRF instances exist\n");
1078 return CMD_WARNING_CONFIG_FAILED;
1079 }
1080 }
1081 }
1082 }
1083
1084 bgp_delete(bgp);
1085
1086 return CMD_SUCCESS;
1087 }
1088
1089
1090 /* BGP router-id. */
1091
1092 DEFPY (bgp_router_id,
1093 bgp_router_id_cmd,
1094 "bgp router-id A.B.C.D",
1095 BGP_STR
1096 "Override configured router identifier\n"
1097 "Manually configured router identifier\n")
1098 {
1099 VTY_DECLVAR_CONTEXT(bgp, bgp);
1100 bgp_router_id_static_set(bgp, router_id);
1101 return CMD_SUCCESS;
1102 }
1103
1104 DEFPY (no_bgp_router_id,
1105 no_bgp_router_id_cmd,
1106 "no bgp router-id [A.B.C.D]",
1107 NO_STR
1108 BGP_STR
1109 "Override configured router identifier\n"
1110 "Manually configured router identifier\n")
1111 {
1112 VTY_DECLVAR_CONTEXT(bgp, bgp);
1113
1114 if (router_id_str) {
1115 if (!IPV4_ADDR_SAME(&bgp->router_id_static, &router_id)) {
1116 vty_out(vty, "%% BGP router-id doesn't match\n");
1117 return CMD_WARNING_CONFIG_FAILED;
1118 }
1119 }
1120
1121 router_id.s_addr = 0;
1122 bgp_router_id_static_set(bgp, router_id);
1123
1124 return CMD_SUCCESS;
1125 }
1126
1127
1128 /* BGP Cluster ID. */
1129 DEFUN (bgp_cluster_id,
1130 bgp_cluster_id_cmd,
1131 "bgp cluster-id <A.B.C.D|(1-4294967295)>",
1132 BGP_STR
1133 "Configure Route-Reflector Cluster-id\n"
1134 "Route-Reflector Cluster-id in IP address format\n"
1135 "Route-Reflector Cluster-id as 32 bit quantity\n")
1136 {
1137 VTY_DECLVAR_CONTEXT(bgp, bgp);
1138 int idx_ipv4 = 2;
1139 int ret;
1140 struct in_addr cluster;
1141
1142 ret = inet_aton(argv[idx_ipv4]->arg, &cluster);
1143 if (!ret) {
1144 vty_out(vty, "%% Malformed bgp cluster identifier\n");
1145 return CMD_WARNING_CONFIG_FAILED;
1146 }
1147
1148 bgp_cluster_id_set(bgp, &cluster);
1149 bgp_clear_star_soft_out(vty, bgp->name);
1150
1151 return CMD_SUCCESS;
1152 }
1153
1154 DEFUN (no_bgp_cluster_id,
1155 no_bgp_cluster_id_cmd,
1156 "no bgp cluster-id [<A.B.C.D|(1-4294967295)>]",
1157 NO_STR
1158 BGP_STR
1159 "Configure Route-Reflector Cluster-id\n"
1160 "Route-Reflector Cluster-id in IP address format\n"
1161 "Route-Reflector Cluster-id as 32 bit quantity\n")
1162 {
1163 VTY_DECLVAR_CONTEXT(bgp, bgp);
1164 bgp_cluster_id_unset(bgp);
1165 bgp_clear_star_soft_out(vty, bgp->name);
1166
1167 return CMD_SUCCESS;
1168 }
1169
1170 DEFUN (bgp_confederation_identifier,
1171 bgp_confederation_identifier_cmd,
1172 "bgp confederation identifier (1-4294967295)",
1173 "BGP specific commands\n"
1174 "AS confederation parameters\n"
1175 "AS number\n"
1176 "Set routing domain confederation AS\n")
1177 {
1178 VTY_DECLVAR_CONTEXT(bgp, bgp);
1179 int idx_number = 3;
1180 as_t as;
1181
1182 as = strtoul(argv[idx_number]->arg, NULL, 10);
1183
1184 bgp_confederation_id_set(bgp, as);
1185
1186 return CMD_SUCCESS;
1187 }
1188
1189 DEFUN (no_bgp_confederation_identifier,
1190 no_bgp_confederation_identifier_cmd,
1191 "no bgp confederation identifier [(1-4294967295)]",
1192 NO_STR
1193 "BGP specific commands\n"
1194 "AS confederation parameters\n"
1195 "AS number\n"
1196 "Set routing domain confederation AS\n")
1197 {
1198 VTY_DECLVAR_CONTEXT(bgp, bgp);
1199 bgp_confederation_id_unset(bgp);
1200
1201 return CMD_SUCCESS;
1202 }
1203
1204 DEFUN (bgp_confederation_peers,
1205 bgp_confederation_peers_cmd,
1206 "bgp confederation peers (1-4294967295)...",
1207 "BGP specific commands\n"
1208 "AS confederation parameters\n"
1209 "Peer ASs in BGP confederation\n"
1210 AS_STR)
1211 {
1212 VTY_DECLVAR_CONTEXT(bgp, bgp);
1213 int idx_asn = 3;
1214 as_t as;
1215 int i;
1216
1217 for (i = idx_asn; i < argc; i++) {
1218 as = strtoul(argv[i]->arg, NULL, 10);
1219
1220 if (bgp->as == as) {
1221 vty_out(vty,
1222 "%% Local member-AS not allowed in confed peer list\n");
1223 continue;
1224 }
1225
1226 bgp_confederation_peers_add(bgp, as);
1227 }
1228 return CMD_SUCCESS;
1229 }
1230
1231 DEFUN (no_bgp_confederation_peers,
1232 no_bgp_confederation_peers_cmd,
1233 "no bgp confederation peers (1-4294967295)...",
1234 NO_STR
1235 "BGP specific commands\n"
1236 "AS confederation parameters\n"
1237 "Peer ASs in BGP confederation\n"
1238 AS_STR)
1239 {
1240 VTY_DECLVAR_CONTEXT(bgp, bgp);
1241 int idx_asn = 4;
1242 as_t as;
1243 int i;
1244
1245 for (i = idx_asn; i < argc; i++) {
1246 as = strtoul(argv[i]->arg, NULL, 10);
1247
1248 bgp_confederation_peers_remove(bgp, as);
1249 }
1250 return CMD_SUCCESS;
1251 }
1252
1253 /**
1254 * Central routine for maximum-paths configuration.
1255 * @peer_type: BGP_PEER_EBGP or BGP_PEER_IBGP
1256 * @set: 1 for setting values, 0 for removing the max-paths config.
1257 */
1258 static int bgp_maxpaths_config_vty(struct vty *vty, int peer_type,
1259 const char *mpaths, uint16_t options,
1260 int set)
1261 {
1262 VTY_DECLVAR_CONTEXT(bgp, bgp);
1263 uint16_t maxpaths = 0;
1264 int ret;
1265 afi_t afi;
1266 safi_t safi;
1267
1268 afi = bgp_node_afi(vty);
1269 safi = bgp_node_safi(vty);
1270
1271 if (set) {
1272 maxpaths = strtol(mpaths, NULL, 10);
1273 if (maxpaths > multipath_num) {
1274 vty_out(vty,
1275 "%% Maxpaths Specified: %d is > than multipath num specified on bgp command line %d",
1276 maxpaths, multipath_num);
1277 return CMD_WARNING_CONFIG_FAILED;
1278 }
1279 ret = bgp_maximum_paths_set(bgp, afi, safi, peer_type, maxpaths,
1280 options);
1281 } else
1282 ret = bgp_maximum_paths_unset(bgp, afi, safi, peer_type);
1283
1284 if (ret < 0) {
1285 vty_out(vty,
1286 "%% Failed to %sset maximum-paths %s %u for afi %u, safi %u\n",
1287 (set == 1) ? "" : "un",
1288 (peer_type == BGP_PEER_EBGP) ? "ebgp" : "ibgp",
1289 maxpaths, afi, safi);
1290 return CMD_WARNING_CONFIG_FAILED;
1291 }
1292
1293 bgp_recalculate_all_bestpaths(bgp);
1294
1295 return CMD_SUCCESS;
1296 }
1297
1298 DEFUN (bgp_maxmed_admin,
1299 bgp_maxmed_admin_cmd,
1300 "bgp max-med administrative ",
1301 BGP_STR
1302 "Advertise routes with max-med\n"
1303 "Administratively applied, for an indefinite period\n")
1304 {
1305 VTY_DECLVAR_CONTEXT(bgp, bgp);
1306
1307 bgp->v_maxmed_admin = 1;
1308 bgp->maxmed_admin_value = BGP_MAXMED_VALUE_DEFAULT;
1309
1310 bgp_maxmed_update(bgp);
1311
1312 return CMD_SUCCESS;
1313 }
1314
1315 DEFUN (bgp_maxmed_admin_medv,
1316 bgp_maxmed_admin_medv_cmd,
1317 "bgp max-med administrative (0-4294967295)",
1318 BGP_STR
1319 "Advertise routes with max-med\n"
1320 "Administratively applied, for an indefinite period\n"
1321 "Max MED value to be used\n")
1322 {
1323 VTY_DECLVAR_CONTEXT(bgp, bgp);
1324 int idx_number = 3;
1325
1326 bgp->v_maxmed_admin = 1;
1327 bgp->maxmed_admin_value = strtoul(argv[idx_number]->arg, NULL, 10);
1328
1329 bgp_maxmed_update(bgp);
1330
1331 return CMD_SUCCESS;
1332 }
1333
1334 DEFUN (no_bgp_maxmed_admin,
1335 no_bgp_maxmed_admin_cmd,
1336 "no bgp max-med administrative [(0-4294967295)]",
1337 NO_STR
1338 BGP_STR
1339 "Advertise routes with max-med\n"
1340 "Administratively applied, for an indefinite period\n"
1341 "Max MED value to be used\n")
1342 {
1343 VTY_DECLVAR_CONTEXT(bgp, bgp);
1344 bgp->v_maxmed_admin = BGP_MAXMED_ADMIN_UNCONFIGURED;
1345 bgp->maxmed_admin_value = BGP_MAXMED_VALUE_DEFAULT;
1346 bgp_maxmed_update(bgp);
1347
1348 return CMD_SUCCESS;
1349 }
1350
1351 DEFUN (bgp_maxmed_onstartup,
1352 bgp_maxmed_onstartup_cmd,
1353 "bgp max-med on-startup (5-86400) [(0-4294967295)]",
1354 BGP_STR
1355 "Advertise routes with max-med\n"
1356 "Effective on a startup\n"
1357 "Time (seconds) period for max-med\n"
1358 "Max MED value to be used\n")
1359 {
1360 VTY_DECLVAR_CONTEXT(bgp, bgp);
1361 int idx = 0;
1362
1363 argv_find(argv, argc, "(5-86400)", &idx);
1364 bgp->v_maxmed_onstartup = strtoul(argv[idx]->arg, NULL, 10);
1365 if (argv_find(argv, argc, "(0-4294967295)", &idx))
1366 bgp->maxmed_onstartup_value = strtoul(argv[idx]->arg, NULL, 10);
1367 else
1368 bgp->maxmed_onstartup_value = BGP_MAXMED_VALUE_DEFAULT;
1369
1370 bgp_maxmed_update(bgp);
1371
1372 return CMD_SUCCESS;
1373 }
1374
1375 DEFUN (no_bgp_maxmed_onstartup,
1376 no_bgp_maxmed_onstartup_cmd,
1377 "no bgp max-med on-startup [(5-86400) [(0-4294967295)]]",
1378 NO_STR
1379 BGP_STR
1380 "Advertise routes with max-med\n"
1381 "Effective on a startup\n"
1382 "Time (seconds) period for max-med\n"
1383 "Max MED value to be used\n")
1384 {
1385 VTY_DECLVAR_CONTEXT(bgp, bgp);
1386
1387 /* Cancel max-med onstartup if its on */
1388 if (bgp->t_maxmed_onstartup) {
1389 THREAD_TIMER_OFF(bgp->t_maxmed_onstartup);
1390 bgp->maxmed_onstartup_over = 1;
1391 }
1392
1393 bgp->v_maxmed_onstartup = BGP_MAXMED_ONSTARTUP_UNCONFIGURED;
1394 bgp->maxmed_onstartup_value = BGP_MAXMED_VALUE_DEFAULT;
1395
1396 bgp_maxmed_update(bgp);
1397
1398 return CMD_SUCCESS;
1399 }
1400
1401 static int bgp_update_delay_config_vty(struct vty *vty, const char *delay,
1402 const char *wait)
1403 {
1404 VTY_DECLVAR_CONTEXT(bgp, bgp);
1405 uint16_t update_delay;
1406 uint16_t establish_wait;
1407
1408 update_delay = strtoul(delay, NULL, 10);
1409
1410 if (!wait) /* update-delay <delay> */
1411 {
1412 bgp->v_update_delay = update_delay;
1413 bgp->v_establish_wait = bgp->v_update_delay;
1414 return CMD_SUCCESS;
1415 }
1416
1417 /* update-delay <delay> <establish-wait> */
1418 establish_wait = atoi(wait);
1419 if (update_delay < establish_wait) {
1420 vty_out(vty,
1421 "%%Failed: update-delay less than the establish-wait!\n");
1422 return CMD_WARNING_CONFIG_FAILED;
1423 }
1424
1425 bgp->v_update_delay = update_delay;
1426 bgp->v_establish_wait = establish_wait;
1427
1428 return CMD_SUCCESS;
1429 }
1430
1431 static int bgp_update_delay_deconfig_vty(struct vty *vty)
1432 {
1433 VTY_DECLVAR_CONTEXT(bgp, bgp);
1434
1435 bgp->v_update_delay = BGP_UPDATE_DELAY_DEF;
1436 bgp->v_establish_wait = bgp->v_update_delay;
1437
1438 return CMD_SUCCESS;
1439 }
1440
1441 void bgp_config_write_update_delay(struct vty *vty, struct bgp *bgp)
1442 {
1443 if (bgp->v_update_delay != BGP_UPDATE_DELAY_DEF) {
1444 vty_out(vty, " update-delay %d", bgp->v_update_delay);
1445 if (bgp->v_update_delay != bgp->v_establish_wait)
1446 vty_out(vty, " %d", bgp->v_establish_wait);
1447 vty_out(vty, "\n");
1448 }
1449 }
1450
1451
1452 /* Update-delay configuration */
1453 DEFUN (bgp_update_delay,
1454 bgp_update_delay_cmd,
1455 "update-delay (0-3600)",
1456 "Force initial delay for best-path and updates\n"
1457 "Seconds\n")
1458 {
1459 int idx_number = 1;
1460 return bgp_update_delay_config_vty(vty, argv[idx_number]->arg, NULL);
1461 }
1462
1463 DEFUN (bgp_update_delay_establish_wait,
1464 bgp_update_delay_establish_wait_cmd,
1465 "update-delay (0-3600) (1-3600)",
1466 "Force initial delay for best-path and updates\n"
1467 "Seconds\n"
1468 "Seconds\n")
1469 {
1470 int idx_number = 1;
1471 int idx_number_2 = 2;
1472 return bgp_update_delay_config_vty(vty, argv[idx_number]->arg,
1473 argv[idx_number_2]->arg);
1474 }
1475
1476 /* Update-delay deconfiguration */
1477 DEFUN (no_bgp_update_delay,
1478 no_bgp_update_delay_cmd,
1479 "no update-delay [(0-3600) [(1-3600)]]",
1480 NO_STR
1481 "Force initial delay for best-path and updates\n"
1482 "Seconds\n"
1483 "Seconds\n")
1484 {
1485 return bgp_update_delay_deconfig_vty(vty);
1486 }
1487
1488
1489 static int bgp_wpkt_quanta_config_vty(struct vty *vty, const char *num,
1490 char set)
1491 {
1492 VTY_DECLVAR_CONTEXT(bgp, bgp);
1493
1494 if (set) {
1495 uint32_t quanta = strtoul(num, NULL, 10);
1496 atomic_store_explicit(&bgp->wpkt_quanta, quanta,
1497 memory_order_relaxed);
1498 } else {
1499 atomic_store_explicit(&bgp->wpkt_quanta, BGP_WRITE_PACKET_MAX,
1500 memory_order_relaxed);
1501 }
1502
1503 return CMD_SUCCESS;
1504 }
1505
1506 static int bgp_rpkt_quanta_config_vty(struct vty *vty, const char *num,
1507 char set)
1508 {
1509 VTY_DECLVAR_CONTEXT(bgp, bgp);
1510
1511 if (set) {
1512 uint32_t quanta = strtoul(num, NULL, 10);
1513 atomic_store_explicit(&bgp->rpkt_quanta, quanta,
1514 memory_order_relaxed);
1515 } else {
1516 atomic_store_explicit(&bgp->rpkt_quanta, BGP_READ_PACKET_MAX,
1517 memory_order_relaxed);
1518 }
1519
1520 return CMD_SUCCESS;
1521 }
1522
1523 void bgp_config_write_wpkt_quanta(struct vty *vty, struct bgp *bgp)
1524 {
1525 uint32_t quanta =
1526 atomic_load_explicit(&bgp->wpkt_quanta, memory_order_relaxed);
1527 if (quanta != BGP_WRITE_PACKET_MAX)
1528 vty_out(vty, " write-quanta %d\n", quanta);
1529 }
1530
1531 void bgp_config_write_rpkt_quanta(struct vty *vty, struct bgp *bgp)
1532 {
1533 uint32_t quanta =
1534 atomic_load_explicit(&bgp->rpkt_quanta, memory_order_relaxed);
1535 if (quanta != BGP_READ_PACKET_MAX)
1536 vty_out(vty, " read-quanta %d\n", quanta);
1537 }
1538
1539 /* Packet quanta configuration */
1540 DEFUN (bgp_wpkt_quanta,
1541 bgp_wpkt_quanta_cmd,
1542 "write-quanta (1-10)",
1543 "How many packets to write to peer socket per run\n"
1544 "Number of packets\n")
1545 {
1546 int idx_number = 1;
1547 return bgp_wpkt_quanta_config_vty(vty, argv[idx_number]->arg, 1);
1548 }
1549
1550 DEFUN (no_bgp_wpkt_quanta,
1551 no_bgp_wpkt_quanta_cmd,
1552 "no write-quanta (1-10)",
1553 NO_STR
1554 "How many packets to write to peer socket per I/O cycle\n"
1555 "Number of packets\n")
1556 {
1557 int idx_number = 2;
1558 return bgp_wpkt_quanta_config_vty(vty, argv[idx_number]->arg, 0);
1559 }
1560
1561 DEFUN (bgp_rpkt_quanta,
1562 bgp_rpkt_quanta_cmd,
1563 "read-quanta (1-10)",
1564 "How many packets to read from peer socket per I/O cycle\n"
1565 "Number of packets\n")
1566 {
1567 int idx_number = 1;
1568 return bgp_rpkt_quanta_config_vty(vty, argv[idx_number]->arg, 1);
1569 }
1570
1571 DEFUN (no_bgp_rpkt_quanta,
1572 no_bgp_rpkt_quanta_cmd,
1573 "no read-quanta (1-10)",
1574 NO_STR
1575 "How many packets to read from peer socket per I/O cycle\n"
1576 "Number of packets\n")
1577 {
1578 int idx_number = 2;
1579 return bgp_rpkt_quanta_config_vty(vty, argv[idx_number]->arg, 0);
1580 }
1581
1582 void bgp_config_write_coalesce_time(struct vty *vty, struct bgp *bgp)
1583 {
1584 if (!bgp->heuristic_coalesce)
1585 vty_out(vty, " coalesce-time %u\n", bgp->coalesce_time);
1586 }
1587
1588
1589 DEFUN (bgp_coalesce_time,
1590 bgp_coalesce_time_cmd,
1591 "coalesce-time (0-4294967295)",
1592 "Subgroup coalesce timer\n"
1593 "Subgroup coalesce timer value (in ms)\n")
1594 {
1595 VTY_DECLVAR_CONTEXT(bgp, bgp);
1596
1597 int idx = 0;
1598 argv_find(argv, argc, "(0-4294967295)", &idx);
1599 bgp->heuristic_coalesce = false;
1600 bgp->coalesce_time = strtoul(argv[idx]->arg, NULL, 10);
1601 return CMD_SUCCESS;
1602 }
1603
1604 DEFUN (no_bgp_coalesce_time,
1605 no_bgp_coalesce_time_cmd,
1606 "no coalesce-time (0-4294967295)",
1607 NO_STR
1608 "Subgroup coalesce timer\n"
1609 "Subgroup coalesce timer value (in ms)\n")
1610 {
1611 VTY_DECLVAR_CONTEXT(bgp, bgp);
1612
1613 bgp->heuristic_coalesce = true;
1614 bgp->coalesce_time = BGP_DEFAULT_SUBGROUP_COALESCE_TIME;
1615 return CMD_SUCCESS;
1616 }
1617
1618 /* Maximum-paths configuration */
1619 DEFUN (bgp_maxpaths,
1620 bgp_maxpaths_cmd,
1621 "maximum-paths " CMD_RANGE_STR(1, MULTIPATH_NUM),
1622 "Forward packets over multiple paths\n"
1623 "Number of paths\n")
1624 {
1625 int idx_number = 1;
1626 return bgp_maxpaths_config_vty(vty, BGP_PEER_EBGP,
1627 argv[idx_number]->arg, 0, 1);
1628 }
1629
1630 ALIAS_HIDDEN(bgp_maxpaths, bgp_maxpaths_hidden_cmd,
1631 "maximum-paths " CMD_RANGE_STR(1, MULTIPATH_NUM),
1632 "Forward packets over multiple paths\n"
1633 "Number of paths\n")
1634
1635 DEFUN (bgp_maxpaths_ibgp,
1636 bgp_maxpaths_ibgp_cmd,
1637 "maximum-paths ibgp " CMD_RANGE_STR(1, MULTIPATH_NUM),
1638 "Forward packets over multiple paths\n"
1639 "iBGP-multipath\n"
1640 "Number of paths\n")
1641 {
1642 int idx_number = 2;
1643 return bgp_maxpaths_config_vty(vty, BGP_PEER_IBGP,
1644 argv[idx_number]->arg, 0, 1);
1645 }
1646
1647 ALIAS_HIDDEN(bgp_maxpaths_ibgp, bgp_maxpaths_ibgp_hidden_cmd,
1648 "maximum-paths ibgp " CMD_RANGE_STR(1, MULTIPATH_NUM),
1649 "Forward packets over multiple paths\n"
1650 "iBGP-multipath\n"
1651 "Number of paths\n")
1652
1653 DEFUN (bgp_maxpaths_ibgp_cluster,
1654 bgp_maxpaths_ibgp_cluster_cmd,
1655 "maximum-paths ibgp " CMD_RANGE_STR(1, MULTIPATH_NUM) " equal-cluster-length",
1656 "Forward packets over multiple paths\n"
1657 "iBGP-multipath\n"
1658 "Number of paths\n"
1659 "Match the cluster length\n")
1660 {
1661 int idx_number = 2;
1662 return bgp_maxpaths_config_vty(
1663 vty, BGP_PEER_IBGP, argv[idx_number]->arg,
1664 BGP_FLAG_IBGP_MULTIPATH_SAME_CLUSTERLEN, 1);
1665 }
1666
1667 ALIAS_HIDDEN(bgp_maxpaths_ibgp_cluster, bgp_maxpaths_ibgp_cluster_hidden_cmd,
1668 "maximum-paths ibgp " CMD_RANGE_STR(
1669 1, MULTIPATH_NUM) " equal-cluster-length",
1670 "Forward packets over multiple paths\n"
1671 "iBGP-multipath\n"
1672 "Number of paths\n"
1673 "Match the cluster length\n")
1674
1675 DEFUN (no_bgp_maxpaths,
1676 no_bgp_maxpaths_cmd,
1677 "no maximum-paths [" CMD_RANGE_STR(1, MULTIPATH_NUM) "]",
1678 NO_STR
1679 "Forward packets over multiple paths\n"
1680 "Number of paths\n")
1681 {
1682 return bgp_maxpaths_config_vty(vty, BGP_PEER_EBGP, NULL, 0, 0);
1683 }
1684
1685 ALIAS_HIDDEN(no_bgp_maxpaths, no_bgp_maxpaths_hidden_cmd,
1686 "no maximum-paths [" CMD_RANGE_STR(1, MULTIPATH_NUM) "]", NO_STR
1687 "Forward packets over multiple paths\n"
1688 "Number of paths\n")
1689
1690 DEFUN (no_bgp_maxpaths_ibgp,
1691 no_bgp_maxpaths_ibgp_cmd,
1692 "no maximum-paths ibgp [" CMD_RANGE_STR(1, MULTIPATH_NUM) " [equal-cluster-length]]",
1693 NO_STR
1694 "Forward packets over multiple paths\n"
1695 "iBGP-multipath\n"
1696 "Number of paths\n"
1697 "Match the cluster length\n")
1698 {
1699 return bgp_maxpaths_config_vty(vty, BGP_PEER_IBGP, NULL, 0, 0);
1700 }
1701
1702 ALIAS_HIDDEN(no_bgp_maxpaths_ibgp, no_bgp_maxpaths_ibgp_hidden_cmd,
1703 "no maximum-paths ibgp [" CMD_RANGE_STR(
1704 1, MULTIPATH_NUM) " [equal-cluster-length]]",
1705 NO_STR
1706 "Forward packets over multiple paths\n"
1707 "iBGP-multipath\n"
1708 "Number of paths\n"
1709 "Match the cluster length\n")
1710
1711 void bgp_config_write_maxpaths(struct vty *vty, struct bgp *bgp, afi_t afi,
1712 safi_t safi)
1713 {
1714 if (bgp->maxpaths[afi][safi].maxpaths_ebgp != MULTIPATH_NUM) {
1715 vty_out(vty, " maximum-paths %d\n",
1716 bgp->maxpaths[afi][safi].maxpaths_ebgp);
1717 }
1718
1719 if (bgp->maxpaths[afi][safi].maxpaths_ibgp != MULTIPATH_NUM) {
1720 vty_out(vty, " maximum-paths ibgp %d",
1721 bgp->maxpaths[afi][safi].maxpaths_ibgp);
1722 if (CHECK_FLAG(bgp->maxpaths[afi][safi].ibgp_flags,
1723 BGP_FLAG_IBGP_MULTIPATH_SAME_CLUSTERLEN))
1724 vty_out(vty, " equal-cluster-length");
1725 vty_out(vty, "\n");
1726 }
1727 }
1728
1729 /* BGP timers. */
1730
1731 DEFUN (bgp_timers,
1732 bgp_timers_cmd,
1733 "timers bgp (0-65535) (0-65535)",
1734 "Adjust routing timers\n"
1735 "BGP timers\n"
1736 "Keepalive interval\n"
1737 "Holdtime\n")
1738 {
1739 VTY_DECLVAR_CONTEXT(bgp, bgp);
1740 int idx_number = 2;
1741 int idx_number_2 = 3;
1742 unsigned long keepalive = 0;
1743 unsigned long holdtime = 0;
1744
1745 keepalive = strtoul(argv[idx_number]->arg, NULL, 10);
1746 holdtime = strtoul(argv[idx_number_2]->arg, NULL, 10);
1747
1748 /* Holdtime value check. */
1749 if (holdtime < 3 && holdtime != 0) {
1750 vty_out(vty,
1751 "%% hold time value must be either 0 or greater than 3\n");
1752 return CMD_WARNING_CONFIG_FAILED;
1753 }
1754
1755 bgp_timers_set(bgp, keepalive, holdtime);
1756
1757 return CMD_SUCCESS;
1758 }
1759
1760 DEFUN (no_bgp_timers,
1761 no_bgp_timers_cmd,
1762 "no timers bgp [(0-65535) (0-65535)]",
1763 NO_STR
1764 "Adjust routing timers\n"
1765 "BGP timers\n"
1766 "Keepalive interval\n"
1767 "Holdtime\n")
1768 {
1769 VTY_DECLVAR_CONTEXT(bgp, bgp);
1770 bgp_timers_unset(bgp);
1771
1772 return CMD_SUCCESS;
1773 }
1774
1775
1776 DEFUN (bgp_client_to_client_reflection,
1777 bgp_client_to_client_reflection_cmd,
1778 "bgp client-to-client reflection",
1779 "BGP specific commands\n"
1780 "Configure client to client route reflection\n"
1781 "reflection of routes allowed\n")
1782 {
1783 VTY_DECLVAR_CONTEXT(bgp, bgp);
1784 bgp_flag_unset(bgp, BGP_FLAG_NO_CLIENT_TO_CLIENT);
1785 bgp_clear_star_soft_out(vty, bgp->name);
1786
1787 return CMD_SUCCESS;
1788 }
1789
1790 DEFUN (no_bgp_client_to_client_reflection,
1791 no_bgp_client_to_client_reflection_cmd,
1792 "no bgp client-to-client reflection",
1793 NO_STR
1794 "BGP specific commands\n"
1795 "Configure client to client route reflection\n"
1796 "reflection of routes allowed\n")
1797 {
1798 VTY_DECLVAR_CONTEXT(bgp, bgp);
1799 bgp_flag_set(bgp, BGP_FLAG_NO_CLIENT_TO_CLIENT);
1800 bgp_clear_star_soft_out(vty, bgp->name);
1801
1802 return CMD_SUCCESS;
1803 }
1804
1805 /* "bgp always-compare-med" configuration. */
1806 DEFUN (bgp_always_compare_med,
1807 bgp_always_compare_med_cmd,
1808 "bgp always-compare-med",
1809 "BGP specific commands\n"
1810 "Allow comparing MED from different neighbors\n")
1811 {
1812 VTY_DECLVAR_CONTEXT(bgp, bgp);
1813 bgp_flag_set(bgp, BGP_FLAG_ALWAYS_COMPARE_MED);
1814 bgp_recalculate_all_bestpaths(bgp);
1815
1816 return CMD_SUCCESS;
1817 }
1818
1819 DEFUN (no_bgp_always_compare_med,
1820 no_bgp_always_compare_med_cmd,
1821 "no bgp always-compare-med",
1822 NO_STR
1823 "BGP specific commands\n"
1824 "Allow comparing MED from different neighbors\n")
1825 {
1826 VTY_DECLVAR_CONTEXT(bgp, bgp);
1827 bgp_flag_unset(bgp, BGP_FLAG_ALWAYS_COMPARE_MED);
1828 bgp_recalculate_all_bestpaths(bgp);
1829
1830 return CMD_SUCCESS;
1831 }
1832
1833
1834 DEFUN(bgp_ebgp_requires_policy, bgp_ebgp_requires_policy_cmd,
1835 "bgp ebgp-requires-policy",
1836 "BGP specific commands\n"
1837 "Require in and out policy for eBGP peers (RFC8212)\n")
1838 {
1839 VTY_DECLVAR_CONTEXT(bgp, bgp);
1840 bgp->ebgp_requires_policy = DEFAULT_EBGP_POLICY_ENABLED;
1841 return CMD_SUCCESS;
1842 }
1843
1844 DEFUN(no_bgp_ebgp_requires_policy, no_bgp_ebgp_requires_policy_cmd,
1845 "no bgp ebgp-requires-policy",
1846 NO_STR
1847 "BGP specific commands\n"
1848 "Require in and out policy for eBGP peers (RFC8212)\n")
1849 {
1850 VTY_DECLVAR_CONTEXT(bgp, bgp);
1851 bgp->ebgp_requires_policy = DEFAULT_EBGP_POLICY_DISABLED;
1852 return CMD_SUCCESS;
1853 }
1854
1855
1856 /* "bgp deterministic-med" configuration. */
1857 DEFUN (bgp_deterministic_med,
1858 bgp_deterministic_med_cmd,
1859 "bgp deterministic-med",
1860 "BGP specific commands\n"
1861 "Pick the best-MED path among paths advertised from the neighboring AS\n")
1862 {
1863 VTY_DECLVAR_CONTEXT(bgp, bgp);
1864
1865 if (!bgp_flag_check(bgp, BGP_FLAG_DETERMINISTIC_MED)) {
1866 bgp_flag_set(bgp, BGP_FLAG_DETERMINISTIC_MED);
1867 bgp_recalculate_all_bestpaths(bgp);
1868 }
1869
1870 return CMD_SUCCESS;
1871 }
1872
1873 DEFUN (no_bgp_deterministic_med,
1874 no_bgp_deterministic_med_cmd,
1875 "no bgp deterministic-med",
1876 NO_STR
1877 "BGP specific commands\n"
1878 "Pick the best-MED path among paths advertised from the neighboring AS\n")
1879 {
1880 VTY_DECLVAR_CONTEXT(bgp, bgp);
1881 int bestpath_per_as_used;
1882 afi_t afi;
1883 safi_t safi;
1884 struct peer *peer;
1885 struct listnode *node, *nnode;
1886
1887 if (bgp_flag_check(bgp, BGP_FLAG_DETERMINISTIC_MED)) {
1888 bestpath_per_as_used = 0;
1889
1890 for (ALL_LIST_ELEMENTS(bgp->peer, node, nnode, peer)) {
1891 FOREACH_AFI_SAFI (afi, safi)
1892 if (bgp_addpath_dmed_required(
1893 peer->addpath_type[afi][safi])) {
1894 bestpath_per_as_used = 1;
1895 break;
1896 }
1897
1898 if (bestpath_per_as_used)
1899 break;
1900 }
1901
1902 if (bestpath_per_as_used) {
1903 vty_out(vty,
1904 "bgp deterministic-med cannot be disabled while addpath-tx-bestpath-per-AS is in use\n");
1905 return CMD_WARNING_CONFIG_FAILED;
1906 } else {
1907 bgp_flag_unset(bgp, BGP_FLAG_DETERMINISTIC_MED);
1908 bgp_recalculate_all_bestpaths(bgp);
1909 }
1910 }
1911
1912 return CMD_SUCCESS;
1913 }
1914
1915 /* "bgp graceful-restart" configuration. */
1916 DEFUN (bgp_graceful_restart,
1917 bgp_graceful_restart_cmd,
1918 "bgp graceful-restart",
1919 "BGP specific commands\n"
1920 "Graceful restart capability parameters\n")
1921 {
1922 VTY_DECLVAR_CONTEXT(bgp, bgp);
1923 bgp_flag_set(bgp, BGP_FLAG_GRACEFUL_RESTART);
1924 return CMD_SUCCESS;
1925 }
1926
1927 DEFUN (no_bgp_graceful_restart,
1928 no_bgp_graceful_restart_cmd,
1929 "no bgp graceful-restart",
1930 NO_STR
1931 "BGP specific commands\n"
1932 "Graceful restart capability parameters\n")
1933 {
1934 VTY_DECLVAR_CONTEXT(bgp, bgp);
1935 bgp_flag_unset(bgp, BGP_FLAG_GRACEFUL_RESTART);
1936 return CMD_SUCCESS;
1937 }
1938
1939 DEFUN (bgp_graceful_restart_stalepath_time,
1940 bgp_graceful_restart_stalepath_time_cmd,
1941 "bgp graceful-restart stalepath-time (1-4095)",
1942 "BGP specific commands\n"
1943 "Graceful restart capability parameters\n"
1944 "Set the max time to hold onto restarting peer's stale paths\n"
1945 "Delay value (seconds)\n")
1946 {
1947 VTY_DECLVAR_CONTEXT(bgp, bgp);
1948 int idx_number = 3;
1949 uint32_t stalepath;
1950
1951 stalepath = strtoul(argv[idx_number]->arg, NULL, 10);
1952 bgp->stalepath_time = stalepath;
1953 return CMD_SUCCESS;
1954 }
1955
1956 DEFUN (bgp_graceful_restart_restart_time,
1957 bgp_graceful_restart_restart_time_cmd,
1958 "bgp graceful-restart restart-time (1-4095)",
1959 "BGP specific commands\n"
1960 "Graceful restart capability parameters\n"
1961 "Set the time to wait to delete stale routes before a BGP open message is received\n"
1962 "Delay value (seconds)\n")
1963 {
1964 VTY_DECLVAR_CONTEXT(bgp, bgp);
1965 int idx_number = 3;
1966 uint32_t restart;
1967
1968 restart = strtoul(argv[idx_number]->arg, NULL, 10);
1969 bgp->restart_time = restart;
1970 return CMD_SUCCESS;
1971 }
1972
1973 DEFUN (no_bgp_graceful_restart_stalepath_time,
1974 no_bgp_graceful_restart_stalepath_time_cmd,
1975 "no bgp graceful-restart stalepath-time [(1-4095)]",
1976 NO_STR
1977 "BGP specific commands\n"
1978 "Graceful restart capability parameters\n"
1979 "Set the max time to hold onto restarting peer's stale paths\n"
1980 "Delay value (seconds)\n")
1981 {
1982 VTY_DECLVAR_CONTEXT(bgp, bgp);
1983
1984 bgp->stalepath_time = BGP_DEFAULT_STALEPATH_TIME;
1985 return CMD_SUCCESS;
1986 }
1987
1988 DEFUN (no_bgp_graceful_restart_restart_time,
1989 no_bgp_graceful_restart_restart_time_cmd,
1990 "no bgp graceful-restart restart-time [(1-4095)]",
1991 NO_STR
1992 "BGP specific commands\n"
1993 "Graceful restart capability parameters\n"
1994 "Set the time to wait to delete stale routes before a BGP open message is received\n"
1995 "Delay value (seconds)\n")
1996 {
1997 VTY_DECLVAR_CONTEXT(bgp, bgp);
1998
1999 bgp->restart_time = BGP_DEFAULT_RESTART_TIME;
2000 return CMD_SUCCESS;
2001 }
2002
2003 DEFUN (bgp_graceful_restart_preserve_fw,
2004 bgp_graceful_restart_preserve_fw_cmd,
2005 "bgp graceful-restart preserve-fw-state",
2006 "BGP specific commands\n"
2007 "Graceful restart capability parameters\n"
2008 "Sets F-bit indication that fib is preserved while doing Graceful Restart\n")
2009 {
2010 VTY_DECLVAR_CONTEXT(bgp, bgp);
2011 bgp_flag_set(bgp, BGP_FLAG_GR_PRESERVE_FWD);
2012 return CMD_SUCCESS;
2013 }
2014
2015 DEFUN (no_bgp_graceful_restart_preserve_fw,
2016 no_bgp_graceful_restart_preserve_fw_cmd,
2017 "no bgp graceful-restart preserve-fw-state",
2018 NO_STR
2019 "BGP specific commands\n"
2020 "Graceful restart capability parameters\n"
2021 "Unsets F-bit indication that fib is preserved while doing Graceful Restart\n")
2022 {
2023 VTY_DECLVAR_CONTEXT(bgp, bgp);
2024 bgp_flag_unset(bgp, BGP_FLAG_GR_PRESERVE_FWD);
2025 return CMD_SUCCESS;
2026 }
2027
2028 /* "bgp graceful-shutdown" configuration */
2029 DEFUN (bgp_graceful_shutdown,
2030 bgp_graceful_shutdown_cmd,
2031 "bgp graceful-shutdown",
2032 BGP_STR
2033 "Graceful shutdown parameters\n")
2034 {
2035 VTY_DECLVAR_CONTEXT(bgp, bgp);
2036
2037 if (!bgp_flag_check(bgp, BGP_FLAG_GRACEFUL_SHUTDOWN)) {
2038 bgp_flag_set(bgp, BGP_FLAG_GRACEFUL_SHUTDOWN);
2039 bgp_static_redo_import_check(bgp);
2040 bgp_redistribute_redo(bgp);
2041 bgp_clear_star_soft_out(vty, bgp->name);
2042 bgp_clear_star_soft_in(vty, bgp->name);
2043 }
2044
2045 return CMD_SUCCESS;
2046 }
2047
2048 DEFUN (no_bgp_graceful_shutdown,
2049 no_bgp_graceful_shutdown_cmd,
2050 "no bgp graceful-shutdown",
2051 NO_STR
2052 BGP_STR
2053 "Graceful shutdown parameters\n")
2054 {
2055 VTY_DECLVAR_CONTEXT(bgp, bgp);
2056
2057 if (bgp_flag_check(bgp, BGP_FLAG_GRACEFUL_SHUTDOWN)) {
2058 bgp_flag_unset(bgp, BGP_FLAG_GRACEFUL_SHUTDOWN);
2059 bgp_static_redo_import_check(bgp);
2060 bgp_redistribute_redo(bgp);
2061 bgp_clear_star_soft_out(vty, bgp->name);
2062 bgp_clear_star_soft_in(vty, bgp->name);
2063 }
2064
2065 return CMD_SUCCESS;
2066 }
2067
2068 /* "bgp fast-external-failover" configuration. */
2069 DEFUN (bgp_fast_external_failover,
2070 bgp_fast_external_failover_cmd,
2071 "bgp fast-external-failover",
2072 BGP_STR
2073 "Immediately reset session if a link to a directly connected external peer goes down\n")
2074 {
2075 VTY_DECLVAR_CONTEXT(bgp, bgp);
2076 bgp_flag_unset(bgp, BGP_FLAG_NO_FAST_EXT_FAILOVER);
2077 return CMD_SUCCESS;
2078 }
2079
2080 DEFUN (no_bgp_fast_external_failover,
2081 no_bgp_fast_external_failover_cmd,
2082 "no bgp fast-external-failover",
2083 NO_STR
2084 BGP_STR
2085 "Immediately reset session if a link to a directly connected external peer goes down\n")
2086 {
2087 VTY_DECLVAR_CONTEXT(bgp, bgp);
2088 bgp_flag_set(bgp, BGP_FLAG_NO_FAST_EXT_FAILOVER);
2089 return CMD_SUCCESS;
2090 }
2091
2092 /* "bgp bestpath compare-routerid" configuration. */
2093 DEFUN (bgp_bestpath_compare_router_id,
2094 bgp_bestpath_compare_router_id_cmd,
2095 "bgp bestpath compare-routerid",
2096 "BGP specific commands\n"
2097 "Change the default bestpath selection\n"
2098 "Compare router-id for identical EBGP paths\n")
2099 {
2100 VTY_DECLVAR_CONTEXT(bgp, bgp);
2101 bgp_flag_set(bgp, BGP_FLAG_COMPARE_ROUTER_ID);
2102 bgp_recalculate_all_bestpaths(bgp);
2103
2104 return CMD_SUCCESS;
2105 }
2106
2107 DEFUN (no_bgp_bestpath_compare_router_id,
2108 no_bgp_bestpath_compare_router_id_cmd,
2109 "no bgp bestpath compare-routerid",
2110 NO_STR
2111 "BGP specific commands\n"
2112 "Change the default bestpath selection\n"
2113 "Compare router-id for identical EBGP paths\n")
2114 {
2115 VTY_DECLVAR_CONTEXT(bgp, bgp);
2116 bgp_flag_unset(bgp, BGP_FLAG_COMPARE_ROUTER_ID);
2117 bgp_recalculate_all_bestpaths(bgp);
2118
2119 return CMD_SUCCESS;
2120 }
2121
2122 /* "bgp bestpath as-path ignore" configuration. */
2123 DEFUN (bgp_bestpath_aspath_ignore,
2124 bgp_bestpath_aspath_ignore_cmd,
2125 "bgp bestpath as-path ignore",
2126 "BGP specific commands\n"
2127 "Change the default bestpath selection\n"
2128 "AS-path attribute\n"
2129 "Ignore as-path length in selecting a route\n")
2130 {
2131 VTY_DECLVAR_CONTEXT(bgp, bgp);
2132 bgp_flag_set(bgp, BGP_FLAG_ASPATH_IGNORE);
2133 bgp_recalculate_all_bestpaths(bgp);
2134
2135 return CMD_SUCCESS;
2136 }
2137
2138 DEFUN (no_bgp_bestpath_aspath_ignore,
2139 no_bgp_bestpath_aspath_ignore_cmd,
2140 "no bgp bestpath as-path ignore",
2141 NO_STR
2142 "BGP specific commands\n"
2143 "Change the default bestpath selection\n"
2144 "AS-path attribute\n"
2145 "Ignore as-path length in selecting a route\n")
2146 {
2147 VTY_DECLVAR_CONTEXT(bgp, bgp);
2148 bgp_flag_unset(bgp, BGP_FLAG_ASPATH_IGNORE);
2149 bgp_recalculate_all_bestpaths(bgp);
2150
2151 return CMD_SUCCESS;
2152 }
2153
2154 /* "bgp bestpath as-path confed" configuration. */
2155 DEFUN (bgp_bestpath_aspath_confed,
2156 bgp_bestpath_aspath_confed_cmd,
2157 "bgp bestpath as-path confed",
2158 "BGP specific commands\n"
2159 "Change the default bestpath selection\n"
2160 "AS-path attribute\n"
2161 "Compare path lengths including confederation sets & sequences in selecting a route\n")
2162 {
2163 VTY_DECLVAR_CONTEXT(bgp, bgp);
2164 bgp_flag_set(bgp, BGP_FLAG_ASPATH_CONFED);
2165 bgp_recalculate_all_bestpaths(bgp);
2166
2167 return CMD_SUCCESS;
2168 }
2169
2170 DEFUN (no_bgp_bestpath_aspath_confed,
2171 no_bgp_bestpath_aspath_confed_cmd,
2172 "no bgp bestpath as-path confed",
2173 NO_STR
2174 "BGP specific commands\n"
2175 "Change the default bestpath selection\n"
2176 "AS-path attribute\n"
2177 "Compare path lengths including confederation sets & sequences in selecting a route\n")
2178 {
2179 VTY_DECLVAR_CONTEXT(bgp, bgp);
2180 bgp_flag_unset(bgp, BGP_FLAG_ASPATH_CONFED);
2181 bgp_recalculate_all_bestpaths(bgp);
2182
2183 return CMD_SUCCESS;
2184 }
2185
2186 /* "bgp bestpath as-path multipath-relax" configuration. */
2187 DEFUN (bgp_bestpath_aspath_multipath_relax,
2188 bgp_bestpath_aspath_multipath_relax_cmd,
2189 "bgp bestpath as-path multipath-relax [<as-set|no-as-set>]",
2190 "BGP specific commands\n"
2191 "Change the default bestpath selection\n"
2192 "AS-path attribute\n"
2193 "Allow load sharing across routes that have different AS paths (but same length)\n"
2194 "Generate an AS_SET\n"
2195 "Do not generate an AS_SET\n")
2196 {
2197 VTY_DECLVAR_CONTEXT(bgp, bgp);
2198 int idx = 0;
2199 bgp_flag_set(bgp, BGP_FLAG_ASPATH_MULTIPATH_RELAX);
2200
2201 /* no-as-set is now the default behavior so we can silently
2202 * ignore it */
2203 if (argv_find(argv, argc, "as-set", &idx))
2204 bgp_flag_set(bgp, BGP_FLAG_MULTIPATH_RELAX_AS_SET);
2205 else
2206 bgp_flag_unset(bgp, BGP_FLAG_MULTIPATH_RELAX_AS_SET);
2207
2208 bgp_recalculate_all_bestpaths(bgp);
2209
2210 return CMD_SUCCESS;
2211 }
2212
2213 DEFUN (no_bgp_bestpath_aspath_multipath_relax,
2214 no_bgp_bestpath_aspath_multipath_relax_cmd,
2215 "no bgp bestpath as-path multipath-relax [<as-set|no-as-set>]",
2216 NO_STR
2217 "BGP specific commands\n"
2218 "Change the default bestpath selection\n"
2219 "AS-path attribute\n"
2220 "Allow load sharing across routes that have different AS paths (but same length)\n"
2221 "Generate an AS_SET\n"
2222 "Do not generate an AS_SET\n")
2223 {
2224 VTY_DECLVAR_CONTEXT(bgp, bgp);
2225 bgp_flag_unset(bgp, BGP_FLAG_ASPATH_MULTIPATH_RELAX);
2226 bgp_flag_unset(bgp, BGP_FLAG_MULTIPATH_RELAX_AS_SET);
2227 bgp_recalculate_all_bestpaths(bgp);
2228
2229 return CMD_SUCCESS;
2230 }
2231
2232 /* "bgp log-neighbor-changes" configuration. */
2233 DEFUN (bgp_log_neighbor_changes,
2234 bgp_log_neighbor_changes_cmd,
2235 "bgp log-neighbor-changes",
2236 "BGP specific commands\n"
2237 "Log neighbor up/down and reset reason\n")
2238 {
2239 VTY_DECLVAR_CONTEXT(bgp, bgp);
2240 bgp_flag_set(bgp, BGP_FLAG_LOG_NEIGHBOR_CHANGES);
2241 return CMD_SUCCESS;
2242 }
2243
2244 DEFUN (no_bgp_log_neighbor_changes,
2245 no_bgp_log_neighbor_changes_cmd,
2246 "no bgp log-neighbor-changes",
2247 NO_STR
2248 "BGP specific commands\n"
2249 "Log neighbor up/down and reset reason\n")
2250 {
2251 VTY_DECLVAR_CONTEXT(bgp, bgp);
2252 bgp_flag_unset(bgp, BGP_FLAG_LOG_NEIGHBOR_CHANGES);
2253 return CMD_SUCCESS;
2254 }
2255
2256 /* "bgp bestpath med" configuration. */
2257 DEFUN (bgp_bestpath_med,
2258 bgp_bestpath_med_cmd,
2259 "bgp bestpath med <confed [missing-as-worst]|missing-as-worst [confed]>",
2260 "BGP specific commands\n"
2261 "Change the default bestpath selection\n"
2262 "MED attribute\n"
2263 "Compare MED among confederation paths\n"
2264 "Treat missing MED as the least preferred one\n"
2265 "Treat missing MED as the least preferred one\n"
2266 "Compare MED among confederation paths\n")
2267 {
2268 VTY_DECLVAR_CONTEXT(bgp, bgp);
2269
2270 int idx = 0;
2271 if (argv_find(argv, argc, "confed", &idx))
2272 bgp_flag_set(bgp, BGP_FLAG_MED_CONFED);
2273 idx = 0;
2274 if (argv_find(argv, argc, "missing-as-worst", &idx))
2275 bgp_flag_set(bgp, BGP_FLAG_MED_MISSING_AS_WORST);
2276
2277 bgp_recalculate_all_bestpaths(bgp);
2278
2279 return CMD_SUCCESS;
2280 }
2281
2282 DEFUN (no_bgp_bestpath_med,
2283 no_bgp_bestpath_med_cmd,
2284 "no bgp bestpath med <confed [missing-as-worst]|missing-as-worst [confed]>",
2285 NO_STR
2286 "BGP specific commands\n"
2287 "Change the default bestpath selection\n"
2288 "MED attribute\n"
2289 "Compare MED among confederation paths\n"
2290 "Treat missing MED as the least preferred one\n"
2291 "Treat missing MED as the least preferred one\n"
2292 "Compare MED among confederation paths\n")
2293 {
2294 VTY_DECLVAR_CONTEXT(bgp, bgp);
2295
2296 int idx = 0;
2297 if (argv_find(argv, argc, "confed", &idx))
2298 bgp_flag_unset(bgp, BGP_FLAG_MED_CONFED);
2299 idx = 0;
2300 if (argv_find(argv, argc, "missing-as-worst", &idx))
2301 bgp_flag_unset(bgp, BGP_FLAG_MED_MISSING_AS_WORST);
2302
2303 bgp_recalculate_all_bestpaths(bgp);
2304
2305 return CMD_SUCCESS;
2306 }
2307
2308 /* "no bgp default ipv4-unicast". */
2309 DEFUN (no_bgp_default_ipv4_unicast,
2310 no_bgp_default_ipv4_unicast_cmd,
2311 "no bgp default ipv4-unicast",
2312 NO_STR
2313 "BGP specific commands\n"
2314 "Configure BGP defaults\n"
2315 "Activate ipv4-unicast for a peer by default\n")
2316 {
2317 VTY_DECLVAR_CONTEXT(bgp, bgp);
2318 bgp_flag_set(bgp, BGP_FLAG_NO_DEFAULT_IPV4);
2319 return CMD_SUCCESS;
2320 }
2321
2322 DEFUN (bgp_default_ipv4_unicast,
2323 bgp_default_ipv4_unicast_cmd,
2324 "bgp default ipv4-unicast",
2325 "BGP specific commands\n"
2326 "Configure BGP defaults\n"
2327 "Activate ipv4-unicast for a peer by default\n")
2328 {
2329 VTY_DECLVAR_CONTEXT(bgp, bgp);
2330 bgp_flag_unset(bgp, BGP_FLAG_NO_DEFAULT_IPV4);
2331 return CMD_SUCCESS;
2332 }
2333
2334 /* Display hostname in certain command outputs */
2335 DEFUN (bgp_default_show_hostname,
2336 bgp_default_show_hostname_cmd,
2337 "bgp default show-hostname",
2338 "BGP specific commands\n"
2339 "Configure BGP defaults\n"
2340 "Show hostname in certain command outputs\n")
2341 {
2342 VTY_DECLVAR_CONTEXT(bgp, bgp);
2343 bgp_flag_set(bgp, BGP_FLAG_SHOW_HOSTNAME);
2344 return CMD_SUCCESS;
2345 }
2346
2347 DEFUN (no_bgp_default_show_hostname,
2348 no_bgp_default_show_hostname_cmd,
2349 "no bgp default show-hostname",
2350 NO_STR
2351 "BGP specific commands\n"
2352 "Configure BGP defaults\n"
2353 "Show hostname in certain command outputs\n")
2354 {
2355 VTY_DECLVAR_CONTEXT(bgp, bgp);
2356 bgp_flag_unset(bgp, BGP_FLAG_SHOW_HOSTNAME);
2357 return CMD_SUCCESS;
2358 }
2359
2360 /* "bgp network import-check" configuration. */
2361 DEFUN (bgp_network_import_check,
2362 bgp_network_import_check_cmd,
2363 "bgp network import-check",
2364 "BGP specific commands\n"
2365 "BGP network command\n"
2366 "Check BGP network route exists in IGP\n")
2367 {
2368 VTY_DECLVAR_CONTEXT(bgp, bgp);
2369 if (!bgp_flag_check(bgp, BGP_FLAG_IMPORT_CHECK)) {
2370 bgp_flag_set(bgp, BGP_FLAG_IMPORT_CHECK);
2371 bgp_static_redo_import_check(bgp);
2372 }
2373
2374 return CMD_SUCCESS;
2375 }
2376
2377 ALIAS_HIDDEN(bgp_network_import_check, bgp_network_import_check_exact_cmd,
2378 "bgp network import-check exact",
2379 "BGP specific commands\n"
2380 "BGP network command\n"
2381 "Check BGP network route exists in IGP\n"
2382 "Match route precisely\n")
2383
2384 DEFUN (no_bgp_network_import_check,
2385 no_bgp_network_import_check_cmd,
2386 "no bgp network import-check",
2387 NO_STR
2388 "BGP specific commands\n"
2389 "BGP network command\n"
2390 "Check BGP network route exists in IGP\n")
2391 {
2392 VTY_DECLVAR_CONTEXT(bgp, bgp);
2393 if (bgp_flag_check(bgp, BGP_FLAG_IMPORT_CHECK)) {
2394 bgp_flag_unset(bgp, BGP_FLAG_IMPORT_CHECK);
2395 bgp_static_redo_import_check(bgp);
2396 }
2397
2398 return CMD_SUCCESS;
2399 }
2400
2401 DEFUN (bgp_default_local_preference,
2402 bgp_default_local_preference_cmd,
2403 "bgp default local-preference (0-4294967295)",
2404 "BGP specific commands\n"
2405 "Configure BGP defaults\n"
2406 "local preference (higher=more preferred)\n"
2407 "Configure default local preference value\n")
2408 {
2409 VTY_DECLVAR_CONTEXT(bgp, bgp);
2410 int idx_number = 3;
2411 uint32_t local_pref;
2412
2413 local_pref = strtoul(argv[idx_number]->arg, NULL, 10);
2414
2415 bgp_default_local_preference_set(bgp, local_pref);
2416 bgp_clear_star_soft_in(vty, bgp->name);
2417
2418 return CMD_SUCCESS;
2419 }
2420
2421 DEFUN (no_bgp_default_local_preference,
2422 no_bgp_default_local_preference_cmd,
2423 "no bgp default local-preference [(0-4294967295)]",
2424 NO_STR
2425 "BGP specific commands\n"
2426 "Configure BGP defaults\n"
2427 "local preference (higher=more preferred)\n"
2428 "Configure default local preference value\n")
2429 {
2430 VTY_DECLVAR_CONTEXT(bgp, bgp);
2431 bgp_default_local_preference_unset(bgp);
2432 bgp_clear_star_soft_in(vty, bgp->name);
2433
2434 return CMD_SUCCESS;
2435 }
2436
2437
2438 DEFUN (bgp_default_subgroup_pkt_queue_max,
2439 bgp_default_subgroup_pkt_queue_max_cmd,
2440 "bgp default subgroup-pkt-queue-max (20-100)",
2441 "BGP specific commands\n"
2442 "Configure BGP defaults\n"
2443 "subgroup-pkt-queue-max\n"
2444 "Configure subgroup packet queue max\n")
2445 {
2446 VTY_DECLVAR_CONTEXT(bgp, bgp);
2447 int idx_number = 3;
2448 uint32_t max_size;
2449
2450 max_size = strtoul(argv[idx_number]->arg, NULL, 10);
2451
2452 bgp_default_subgroup_pkt_queue_max_set(bgp, max_size);
2453
2454 return CMD_SUCCESS;
2455 }
2456
2457 DEFUN (no_bgp_default_subgroup_pkt_queue_max,
2458 no_bgp_default_subgroup_pkt_queue_max_cmd,
2459 "no bgp default subgroup-pkt-queue-max [(20-100)]",
2460 NO_STR
2461 "BGP specific commands\n"
2462 "Configure BGP defaults\n"
2463 "subgroup-pkt-queue-max\n"
2464 "Configure subgroup packet queue max\n")
2465 {
2466 VTY_DECLVAR_CONTEXT(bgp, bgp);
2467 bgp_default_subgroup_pkt_queue_max_unset(bgp);
2468 return CMD_SUCCESS;
2469 }
2470
2471
2472 DEFUN (bgp_rr_allow_outbound_policy,
2473 bgp_rr_allow_outbound_policy_cmd,
2474 "bgp route-reflector allow-outbound-policy",
2475 "BGP specific commands\n"
2476 "Allow modifications made by out route-map\n"
2477 "on ibgp neighbors\n")
2478 {
2479 VTY_DECLVAR_CONTEXT(bgp, bgp);
2480
2481 if (!bgp_flag_check(bgp, BGP_FLAG_RR_ALLOW_OUTBOUND_POLICY)) {
2482 bgp_flag_set(bgp, BGP_FLAG_RR_ALLOW_OUTBOUND_POLICY);
2483 update_group_announce_rrclients(bgp);
2484 bgp_clear_star_soft_out(vty, bgp->name);
2485 }
2486
2487 return CMD_SUCCESS;
2488 }
2489
2490 DEFUN (no_bgp_rr_allow_outbound_policy,
2491 no_bgp_rr_allow_outbound_policy_cmd,
2492 "no bgp route-reflector allow-outbound-policy",
2493 NO_STR
2494 "BGP specific commands\n"
2495 "Allow modifications made by out route-map\n"
2496 "on ibgp neighbors\n")
2497 {
2498 VTY_DECLVAR_CONTEXT(bgp, bgp);
2499
2500 if (bgp_flag_check(bgp, BGP_FLAG_RR_ALLOW_OUTBOUND_POLICY)) {
2501 bgp_flag_unset(bgp, BGP_FLAG_RR_ALLOW_OUTBOUND_POLICY);
2502 update_group_announce_rrclients(bgp);
2503 bgp_clear_star_soft_out(vty, bgp->name);
2504 }
2505
2506 return CMD_SUCCESS;
2507 }
2508
2509 DEFUN (bgp_listen_limit,
2510 bgp_listen_limit_cmd,
2511 "bgp listen limit (1-5000)",
2512 "BGP specific commands\n"
2513 "Configure BGP defaults\n"
2514 "maximum number of BGP Dynamic Neighbors that can be created\n"
2515 "Configure Dynamic Neighbors listen limit value\n")
2516 {
2517 VTY_DECLVAR_CONTEXT(bgp, bgp);
2518 int idx_number = 3;
2519 int listen_limit;
2520
2521 listen_limit = strtoul(argv[idx_number]->arg, NULL, 10);
2522
2523 bgp_listen_limit_set(bgp, listen_limit);
2524
2525 return CMD_SUCCESS;
2526 }
2527
2528 DEFUN (no_bgp_listen_limit,
2529 no_bgp_listen_limit_cmd,
2530 "no bgp listen limit [(1-5000)]",
2531 "BGP specific commands\n"
2532 "Configure BGP defaults\n"
2533 "unset maximum number of BGP Dynamic Neighbors that can be created\n"
2534 "Configure Dynamic Neighbors listen limit value to default\n"
2535 "Configure Dynamic Neighbors listen limit value\n")
2536 {
2537 VTY_DECLVAR_CONTEXT(bgp, bgp);
2538 bgp_listen_limit_unset(bgp);
2539 return CMD_SUCCESS;
2540 }
2541
2542
2543 /*
2544 * Check if this listen range is already configured. Check for exact
2545 * match or overlap based on input.
2546 */
2547 static struct peer_group *listen_range_exists(struct bgp *bgp,
2548 struct prefix *range, int exact)
2549 {
2550 struct listnode *node, *nnode;
2551 struct listnode *node1, *nnode1;
2552 struct peer_group *group;
2553 struct prefix *lr;
2554 afi_t afi;
2555 int match;
2556
2557 afi = family2afi(range->family);
2558 for (ALL_LIST_ELEMENTS(bgp->group, node, nnode, group)) {
2559 for (ALL_LIST_ELEMENTS(group->listen_range[afi], node1, nnode1,
2560 lr)) {
2561 if (exact)
2562 match = prefix_same(range, lr);
2563 else
2564 match = (prefix_match(range, lr)
2565 || prefix_match(lr, range));
2566 if (match)
2567 return group;
2568 }
2569 }
2570
2571 return NULL;
2572 }
2573
2574 DEFUN (bgp_listen_range,
2575 bgp_listen_range_cmd,
2576 "bgp listen range <A.B.C.D/M|X:X::X:X/M> peer-group PGNAME",
2577 "BGP specific commands\n"
2578 "Configure BGP dynamic neighbors listen range\n"
2579 "Configure BGP dynamic neighbors listen range\n"
2580 NEIGHBOR_ADDR_STR
2581 "Member of the peer-group\n"
2582 "Peer-group name\n")
2583 {
2584 VTY_DECLVAR_CONTEXT(bgp, bgp);
2585 struct prefix range;
2586 struct peer_group *group, *existing_group;
2587 afi_t afi;
2588 int ret;
2589 int idx = 0;
2590
2591 argv_find(argv, argc, "A.B.C.D/M", &idx);
2592 argv_find(argv, argc, "X:X::X:X/M", &idx);
2593 char *prefix = argv[idx]->arg;
2594 argv_find(argv, argc, "PGNAME", &idx);
2595 char *peergroup = argv[idx]->arg;
2596
2597 /* Convert IP prefix string to struct prefix. */
2598 ret = str2prefix(prefix, &range);
2599 if (!ret) {
2600 vty_out(vty, "%% Malformed listen range\n");
2601 return CMD_WARNING_CONFIG_FAILED;
2602 }
2603
2604 afi = family2afi(range.family);
2605
2606 if (afi == AFI_IP6 && IN6_IS_ADDR_LINKLOCAL(&range.u.prefix6)) {
2607 vty_out(vty,
2608 "%% Malformed listen range (link-local address)\n");
2609 return CMD_WARNING_CONFIG_FAILED;
2610 }
2611
2612 apply_mask(&range);
2613
2614 /* Check if same listen range is already configured. */
2615 existing_group = listen_range_exists(bgp, &range, 1);
2616 if (existing_group) {
2617 if (strcmp(existing_group->name, peergroup) == 0)
2618 return CMD_SUCCESS;
2619 else {
2620 vty_out(vty,
2621 "%% Same listen range is attached to peer-group %s\n",
2622 existing_group->name);
2623 return CMD_WARNING_CONFIG_FAILED;
2624 }
2625 }
2626
2627 /* Check if an overlapping listen range exists. */
2628 if (listen_range_exists(bgp, &range, 0)) {
2629 vty_out(vty,
2630 "%% Listen range overlaps with existing listen range\n");
2631 return CMD_WARNING_CONFIG_FAILED;
2632 }
2633
2634 group = peer_group_lookup(bgp, peergroup);
2635 if (!group) {
2636 vty_out(vty, "%% Configure the peer-group first\n");
2637 return CMD_WARNING_CONFIG_FAILED;
2638 }
2639
2640 ret = peer_group_listen_range_add(group, &range);
2641 return bgp_vty_return(vty, ret);
2642 }
2643
2644 DEFUN (no_bgp_listen_range,
2645 no_bgp_listen_range_cmd,
2646 "no bgp listen range <A.B.C.D/M|X:X::X:X/M> peer-group PGNAME",
2647 NO_STR
2648 "BGP specific commands\n"
2649 "Unconfigure BGP dynamic neighbors listen range\n"
2650 "Unconfigure BGP dynamic neighbors listen range\n"
2651 NEIGHBOR_ADDR_STR
2652 "Member of the peer-group\n"
2653 "Peer-group name\n")
2654 {
2655 VTY_DECLVAR_CONTEXT(bgp, bgp);
2656 struct prefix range;
2657 struct peer_group *group;
2658 afi_t afi;
2659 int ret;
2660 int idx = 0;
2661
2662 argv_find(argv, argc, "A.B.C.D/M", &idx);
2663 argv_find(argv, argc, "X:X::X:X/M", &idx);
2664 char *prefix = argv[idx]->arg;
2665 argv_find(argv, argc, "WORD", &idx);
2666 char *peergroup = argv[idx]->arg;
2667
2668 /* Convert IP prefix string to struct prefix. */
2669 ret = str2prefix(prefix, &range);
2670 if (!ret) {
2671 vty_out(vty, "%% Malformed listen range\n");
2672 return CMD_WARNING_CONFIG_FAILED;
2673 }
2674
2675 afi = family2afi(range.family);
2676
2677 if (afi == AFI_IP6 && IN6_IS_ADDR_LINKLOCAL(&range.u.prefix6)) {
2678 vty_out(vty,
2679 "%% Malformed listen range (link-local address)\n");
2680 return CMD_WARNING_CONFIG_FAILED;
2681 }
2682
2683 apply_mask(&range);
2684
2685 group = peer_group_lookup(bgp, peergroup);
2686 if (!group) {
2687 vty_out(vty, "%% Peer-group does not exist\n");
2688 return CMD_WARNING_CONFIG_FAILED;
2689 }
2690
2691 ret = peer_group_listen_range_del(group, &range);
2692 return bgp_vty_return(vty, ret);
2693 }
2694
2695 void bgp_config_write_listen(struct vty *vty, struct bgp *bgp)
2696 {
2697 struct peer_group *group;
2698 struct listnode *node, *nnode, *rnode, *nrnode;
2699 struct prefix *range;
2700 afi_t afi;
2701 char buf[PREFIX2STR_BUFFER];
2702
2703 if (bgp->dynamic_neighbors_limit != BGP_DYNAMIC_NEIGHBORS_LIMIT_DEFAULT)
2704 vty_out(vty, " bgp listen limit %d\n",
2705 bgp->dynamic_neighbors_limit);
2706
2707 for (ALL_LIST_ELEMENTS(bgp->group, node, nnode, group)) {
2708 for (afi = AFI_IP; afi < AFI_MAX; afi++) {
2709 for (ALL_LIST_ELEMENTS(group->listen_range[afi], rnode,
2710 nrnode, range)) {
2711 prefix2str(range, buf, sizeof(buf));
2712 vty_out(vty,
2713 " bgp listen range %s peer-group %s\n",
2714 buf, group->name);
2715 }
2716 }
2717 }
2718 }
2719
2720
2721 DEFUN (bgp_disable_connected_route_check,
2722 bgp_disable_connected_route_check_cmd,
2723 "bgp disable-ebgp-connected-route-check",
2724 "BGP specific commands\n"
2725 "Disable checking if nexthop is connected on ebgp sessions\n")
2726 {
2727 VTY_DECLVAR_CONTEXT(bgp, bgp);
2728 bgp_flag_set(bgp, BGP_FLAG_DISABLE_NH_CONNECTED_CHK);
2729 bgp_clear_star_soft_in(vty, bgp->name);
2730
2731 return CMD_SUCCESS;
2732 }
2733
2734 DEFUN (no_bgp_disable_connected_route_check,
2735 no_bgp_disable_connected_route_check_cmd,
2736 "no bgp disable-ebgp-connected-route-check",
2737 NO_STR
2738 "BGP specific commands\n"
2739 "Disable checking if nexthop is connected on ebgp sessions\n")
2740 {
2741 VTY_DECLVAR_CONTEXT(bgp, bgp);
2742 bgp_flag_unset(bgp, BGP_FLAG_DISABLE_NH_CONNECTED_CHK);
2743 bgp_clear_star_soft_in(vty, bgp->name);
2744
2745 return CMD_SUCCESS;
2746 }
2747
2748
2749 static int peer_remote_as_vty(struct vty *vty, const char *peer_str,
2750 const char *as_str, afi_t afi, safi_t safi)
2751 {
2752 VTY_DECLVAR_CONTEXT(bgp, bgp);
2753 int ret;
2754 as_t as;
2755 int as_type = AS_SPECIFIED;
2756 union sockunion su;
2757
2758 if (as_str[0] == 'i') {
2759 as = 0;
2760 as_type = AS_INTERNAL;
2761 } else if (as_str[0] == 'e') {
2762 as = 0;
2763 as_type = AS_EXTERNAL;
2764 } else {
2765 /* Get AS number. */
2766 as = strtoul(as_str, NULL, 10);
2767 }
2768
2769 /* If peer is peer group or interface peer, call proper function. */
2770 ret = str2sockunion(peer_str, &su);
2771 if (ret < 0) {
2772 struct peer *peer;
2773
2774 /* Check if existing interface peer */
2775 peer = peer_lookup_by_conf_if(bgp, peer_str);
2776
2777 ret = peer_remote_as(bgp, NULL, peer_str, &as, as_type, afi,
2778 safi);
2779
2780 /* if not interface peer, check peer-group settings */
2781 if (ret < 0 && !peer) {
2782 ret = peer_group_remote_as(bgp, peer_str, &as, as_type);
2783 if (ret < 0) {
2784 vty_out(vty,
2785 "%% Create the peer-group or interface first\n");
2786 return CMD_WARNING_CONFIG_FAILED;
2787 }
2788 return CMD_SUCCESS;
2789 }
2790 } else {
2791 if (peer_address_self_check(bgp, &su)) {
2792 vty_out(vty,
2793 "%% Can not configure the local system as neighbor\n");
2794 return CMD_WARNING_CONFIG_FAILED;
2795 }
2796 ret = peer_remote_as(bgp, &su, NULL, &as, as_type, afi, safi);
2797 }
2798
2799 /* This peer belongs to peer group. */
2800 switch (ret) {
2801 case BGP_ERR_PEER_GROUP_MEMBER:
2802 vty_out(vty,
2803 "%% Peer-group member cannot override remote-as of peer-group\n");
2804 return CMD_WARNING_CONFIG_FAILED;
2805 case BGP_ERR_PEER_GROUP_PEER_TYPE_DIFFERENT:
2806 vty_out(vty,
2807 "%% Peer-group members must be all internal or all external\n");
2808 return CMD_WARNING_CONFIG_FAILED;
2809 }
2810 return bgp_vty_return(vty, ret);
2811 }
2812
2813 DEFUN (bgp_default_shutdown,
2814 bgp_default_shutdown_cmd,
2815 "[no] bgp default shutdown",
2816 NO_STR
2817 BGP_STR
2818 "Configure BGP defaults\n"
2819 "Apply administrative shutdown to newly configured peers\n")
2820 {
2821 VTY_DECLVAR_CONTEXT(bgp, bgp);
2822 bgp->autoshutdown = !strmatch(argv[0]->text, "no");
2823 return CMD_SUCCESS;
2824 }
2825
2826 DEFUN (neighbor_remote_as,
2827 neighbor_remote_as_cmd,
2828 "neighbor <A.B.C.D|X:X::X:X|WORD> remote-as <(1-4294967295)|internal|external>",
2829 NEIGHBOR_STR
2830 NEIGHBOR_ADDR_STR2
2831 "Specify a BGP neighbor\n"
2832 AS_STR
2833 "Internal BGP peer\n"
2834 "External BGP peer\n")
2835 {
2836 int idx_peer = 1;
2837 int idx_remote_as = 3;
2838 return peer_remote_as_vty(vty, argv[idx_peer]->arg,
2839 argv[idx_remote_as]->arg, AFI_IP,
2840 SAFI_UNICAST);
2841 }
2842
2843 static int peer_conf_interface_get(struct vty *vty, const char *conf_if,
2844 afi_t afi, safi_t safi, int v6only,
2845 const char *peer_group_name,
2846 const char *as_str)
2847 {
2848 VTY_DECLVAR_CONTEXT(bgp, bgp);
2849 as_t as = 0;
2850 int as_type = AS_UNSPECIFIED;
2851 struct peer *peer;
2852 struct peer_group *group;
2853 int ret = 0;
2854 union sockunion su;
2855
2856 group = peer_group_lookup(bgp, conf_if);
2857
2858 if (group) {
2859 vty_out(vty, "%% Name conflict with peer-group \n");
2860 return CMD_WARNING_CONFIG_FAILED;
2861 }
2862
2863 if (as_str) {
2864 if (as_str[0] == 'i') {
2865 as_type = AS_INTERNAL;
2866 } else if (as_str[0] == 'e') {
2867 as_type = AS_EXTERNAL;
2868 } else {
2869 /* Get AS number. */
2870 as = strtoul(as_str, NULL, 10);
2871 as_type = AS_SPECIFIED;
2872 }
2873 }
2874
2875 peer = peer_lookup_by_conf_if(bgp, conf_if);
2876 if (peer) {
2877 if (as_str)
2878 ret = peer_remote_as(bgp, NULL, conf_if, &as, as_type,
2879 afi, safi);
2880 } else {
2881 if (bgp_flag_check(bgp, BGP_FLAG_NO_DEFAULT_IPV4)
2882 && afi == AFI_IP && safi == SAFI_UNICAST)
2883 peer = peer_create(NULL, conf_if, bgp, bgp->as, as,
2884 as_type, 0, 0, NULL);
2885 else
2886 peer = peer_create(NULL, conf_if, bgp, bgp->as, as,
2887 as_type, afi, safi, NULL);
2888
2889 if (!peer) {
2890 vty_out(vty, "%% BGP failed to create peer\n");
2891 return CMD_WARNING_CONFIG_FAILED;
2892 }
2893
2894 if (v6only)
2895 peer_flag_set(peer, PEER_FLAG_IFPEER_V6ONLY);
2896
2897 /* Request zebra to initiate IPv6 RAs on this interface. We do
2898 * this
2899 * any unnumbered peer in order to not worry about run-time
2900 * transitions
2901 * (e.g., peering is initially IPv4, but the IPv4 /30 or /31
2902 * address
2903 * gets deleted later etc.)
2904 */
2905 if (peer->ifp)
2906 bgp_zebra_initiate_radv(bgp, peer);
2907 }
2908
2909 if ((v6only && !CHECK_FLAG(peer->flags, PEER_FLAG_IFPEER_V6ONLY))
2910 || (!v6only && CHECK_FLAG(peer->flags, PEER_FLAG_IFPEER_V6ONLY))) {
2911 if (v6only)
2912 peer_flag_set(peer, PEER_FLAG_IFPEER_V6ONLY);
2913 else
2914 peer_flag_unset(peer, PEER_FLAG_IFPEER_V6ONLY);
2915
2916 /* v6only flag changed. Reset bgp seesion */
2917 if (BGP_IS_VALID_STATE_FOR_NOTIF(peer->status)) {
2918 peer->last_reset = PEER_DOWN_V6ONLY_CHANGE;
2919 bgp_notify_send(peer, BGP_NOTIFY_CEASE,
2920 BGP_NOTIFY_CEASE_CONFIG_CHANGE);
2921 } else
2922 bgp_session_reset(peer);
2923 }
2924
2925 if (!CHECK_FLAG(peer->flags_invert, PEER_FLAG_CAPABILITY_ENHE)) {
2926 SET_FLAG(peer->flags, PEER_FLAG_CAPABILITY_ENHE);
2927 SET_FLAG(peer->flags_invert, PEER_FLAG_CAPABILITY_ENHE);
2928 SET_FLAG(peer->flags_override, PEER_FLAG_CAPABILITY_ENHE);
2929 }
2930
2931 if (peer_group_name) {
2932 group = peer_group_lookup(bgp, peer_group_name);
2933 if (!group) {
2934 vty_out(vty, "%% Configure the peer-group first\n");
2935 return CMD_WARNING_CONFIG_FAILED;
2936 }
2937
2938 ret = peer_group_bind(bgp, &su, peer, group, &as);
2939 }
2940
2941 return bgp_vty_return(vty, ret);
2942 }
2943
2944 DEFUN (neighbor_interface_config,
2945 neighbor_interface_config_cmd,
2946 "neighbor WORD interface [peer-group PGNAME]",
2947 NEIGHBOR_STR
2948 "Interface name or neighbor tag\n"
2949 "Enable BGP on interface\n"
2950 "Member of the peer-group\n"
2951 "Peer-group name\n")
2952 {
2953 int idx_word = 1;
2954 int idx_peer_group_word = 4;
2955
2956 if (argc > idx_peer_group_word)
2957 return peer_conf_interface_get(
2958 vty, argv[idx_word]->arg, AFI_IP, SAFI_UNICAST, 0,
2959 argv[idx_peer_group_word]->arg, NULL);
2960 else
2961 return peer_conf_interface_get(vty, argv[idx_word]->arg, AFI_IP,
2962 SAFI_UNICAST, 0, NULL, NULL);
2963 }
2964
2965 DEFUN (neighbor_interface_config_v6only,
2966 neighbor_interface_config_v6only_cmd,
2967 "neighbor WORD interface v6only [peer-group PGNAME]",
2968 NEIGHBOR_STR
2969 "Interface name or neighbor tag\n"
2970 "Enable BGP on interface\n"
2971 "Enable BGP with v6 link-local only\n"
2972 "Member of the peer-group\n"
2973 "Peer-group name\n")
2974 {
2975 int idx_word = 1;
2976 int idx_peer_group_word = 5;
2977
2978 if (argc > idx_peer_group_word)
2979 return peer_conf_interface_get(
2980 vty, argv[idx_word]->arg, AFI_IP, SAFI_UNICAST, 1,
2981 argv[idx_peer_group_word]->arg, NULL);
2982
2983 return peer_conf_interface_get(vty, argv[idx_word]->arg, AFI_IP,
2984 SAFI_UNICAST, 1, NULL, NULL);
2985 }
2986
2987
2988 DEFUN (neighbor_interface_config_remote_as,
2989 neighbor_interface_config_remote_as_cmd,
2990 "neighbor WORD interface remote-as <(1-4294967295)|internal|external>",
2991 NEIGHBOR_STR
2992 "Interface name or neighbor tag\n"
2993 "Enable BGP on interface\n"
2994 "Specify a BGP neighbor\n"
2995 AS_STR
2996 "Internal BGP peer\n"
2997 "External BGP peer\n")
2998 {
2999 int idx_word = 1;
3000 int idx_remote_as = 4;
3001 return peer_conf_interface_get(vty, argv[idx_word]->arg, AFI_IP,
3002 SAFI_UNICAST, 0, NULL,
3003 argv[idx_remote_as]->arg);
3004 }
3005
3006 DEFUN (neighbor_interface_v6only_config_remote_as,
3007 neighbor_interface_v6only_config_remote_as_cmd,
3008 "neighbor WORD interface v6only remote-as <(1-4294967295)|internal|external>",
3009 NEIGHBOR_STR
3010 "Interface name or neighbor tag\n"
3011 "Enable BGP with v6 link-local only\n"
3012 "Enable BGP on interface\n"
3013 "Specify a BGP neighbor\n"
3014 AS_STR
3015 "Internal BGP peer\n"
3016 "External BGP peer\n")
3017 {
3018 int idx_word = 1;
3019 int idx_remote_as = 5;
3020 return peer_conf_interface_get(vty, argv[idx_word]->arg, AFI_IP,
3021 SAFI_UNICAST, 1, NULL,
3022 argv[idx_remote_as]->arg);
3023 }
3024
3025 DEFUN (neighbor_peer_group,
3026 neighbor_peer_group_cmd,
3027 "neighbor WORD peer-group",
3028 NEIGHBOR_STR
3029 "Interface name or neighbor tag\n"
3030 "Configure peer-group\n")
3031 {
3032 VTY_DECLVAR_CONTEXT(bgp, bgp);
3033 int idx_word = 1;
3034 struct peer *peer;
3035 struct peer_group *group;
3036
3037 peer = peer_lookup_by_conf_if(bgp, argv[idx_word]->arg);
3038 if (peer) {
3039 vty_out(vty, "%% Name conflict with interface: \n");
3040 return CMD_WARNING_CONFIG_FAILED;
3041 }
3042
3043 group = peer_group_get(bgp, argv[idx_word]->arg);
3044 if (!group) {
3045 vty_out(vty, "%% BGP failed to find or create peer-group\n");
3046 return CMD_WARNING_CONFIG_FAILED;
3047 }
3048
3049 return CMD_SUCCESS;
3050 }
3051
3052 DEFUN (no_neighbor,
3053 no_neighbor_cmd,
3054 "no neighbor <WORD|<A.B.C.D|X:X::X:X> [remote-as <(1-4294967295)|internal|external>]>",
3055 NO_STR
3056 NEIGHBOR_STR
3057 NEIGHBOR_ADDR_STR2
3058 "Specify a BGP neighbor\n"
3059 AS_STR
3060 "Internal BGP peer\n"
3061 "External BGP peer\n")
3062 {
3063 VTY_DECLVAR_CONTEXT(bgp, bgp);
3064 int idx_peer = 2;
3065 int ret;
3066 union sockunion su;
3067 struct peer_group *group;
3068 struct peer *peer;
3069 struct peer *other;
3070
3071 ret = str2sockunion(argv[idx_peer]->arg, &su);
3072 if (ret < 0) {
3073 /* look up for neighbor by interface name config. */
3074 peer = peer_lookup_by_conf_if(bgp, argv[idx_peer]->arg);
3075 if (peer) {
3076 /* Request zebra to terminate IPv6 RAs on this
3077 * interface. */
3078 if (peer->ifp)
3079 bgp_zebra_terminate_radv(peer->bgp, peer);
3080 peer_delete(peer);
3081 return CMD_SUCCESS;
3082 }
3083
3084 group = peer_group_lookup(bgp, argv[idx_peer]->arg);
3085 if (group)
3086 peer_group_delete(group);
3087 else {
3088 vty_out(vty, "%% Create the peer-group first\n");
3089 return CMD_WARNING_CONFIG_FAILED;
3090 }
3091 } else {
3092 peer = peer_lookup(bgp, &su);
3093 if (peer) {
3094 if (peer_dynamic_neighbor(peer)) {
3095 vty_out(vty,
3096 "%% Operation not allowed on a dynamic neighbor\n");
3097 return CMD_WARNING_CONFIG_FAILED;
3098 }
3099
3100 other = peer->doppelganger;
3101 peer_delete(peer);
3102 if (other && other->status != Deleted)
3103 peer_delete(other);
3104 }
3105 }
3106
3107 return CMD_SUCCESS;
3108 }
3109
3110 DEFUN (no_neighbor_interface_config,
3111 no_neighbor_interface_config_cmd,
3112 "no neighbor WORD interface [v6only] [peer-group PGNAME] [remote-as <(1-4294967295)|internal|external>]",
3113 NO_STR
3114 NEIGHBOR_STR
3115 "Interface name\n"
3116 "Configure BGP on interface\n"
3117 "Enable BGP with v6 link-local only\n"
3118 "Member of the peer-group\n"
3119 "Peer-group name\n"
3120 "Specify a BGP neighbor\n"
3121 AS_STR
3122 "Internal BGP peer\n"
3123 "External BGP peer\n")
3124 {
3125 VTY_DECLVAR_CONTEXT(bgp, bgp);
3126 int idx_word = 2;
3127 struct peer *peer;
3128
3129 /* look up for neighbor by interface name config. */
3130 peer = peer_lookup_by_conf_if(bgp, argv[idx_word]->arg);
3131 if (peer) {
3132 /* Request zebra to terminate IPv6 RAs on this interface. */
3133 if (peer->ifp)
3134 bgp_zebra_terminate_radv(peer->bgp, peer);
3135 peer_delete(peer);
3136 } else {
3137 vty_out(vty, "%% Create the bgp interface first\n");
3138 return CMD_WARNING_CONFIG_FAILED;
3139 }
3140 return CMD_SUCCESS;
3141 }
3142
3143 DEFUN (no_neighbor_peer_group,
3144 no_neighbor_peer_group_cmd,
3145 "no neighbor WORD peer-group",
3146 NO_STR
3147 NEIGHBOR_STR
3148 "Neighbor tag\n"
3149 "Configure peer-group\n")
3150 {
3151 VTY_DECLVAR_CONTEXT(bgp, bgp);
3152 int idx_word = 2;
3153 struct peer_group *group;
3154
3155 group = peer_group_lookup(bgp, argv[idx_word]->arg);
3156 if (group)
3157 peer_group_delete(group);
3158 else {
3159 vty_out(vty, "%% Create the peer-group first\n");
3160 return CMD_WARNING_CONFIG_FAILED;
3161 }
3162 return CMD_SUCCESS;
3163 }
3164
3165 DEFUN (no_neighbor_interface_peer_group_remote_as,
3166 no_neighbor_interface_peer_group_remote_as_cmd,
3167 "no neighbor WORD remote-as <(1-4294967295)|internal|external>",
3168 NO_STR
3169 NEIGHBOR_STR
3170 "Interface name or neighbor tag\n"
3171 "Specify a BGP neighbor\n"
3172 AS_STR
3173 "Internal BGP peer\n"
3174 "External BGP peer\n")
3175 {
3176 VTY_DECLVAR_CONTEXT(bgp, bgp);
3177 int idx_word = 2;
3178 struct peer_group *group;
3179 struct peer *peer;
3180
3181 /* look up for neighbor by interface name config. */
3182 peer = peer_lookup_by_conf_if(bgp, argv[idx_word]->arg);
3183 if (peer) {
3184 peer_as_change(peer, 0, AS_UNSPECIFIED);
3185 return CMD_SUCCESS;
3186 }
3187
3188 group = peer_group_lookup(bgp, argv[idx_word]->arg);
3189 if (group)
3190 peer_group_remote_as_delete(group);
3191 else {
3192 vty_out(vty, "%% Create the peer-group or interface first\n");
3193 return CMD_WARNING_CONFIG_FAILED;
3194 }
3195 return CMD_SUCCESS;
3196 }
3197
3198 DEFUN (neighbor_local_as,
3199 neighbor_local_as_cmd,
3200 "neighbor <A.B.C.D|X:X::X:X|WORD> local-as (1-4294967295)",
3201 NEIGHBOR_STR
3202 NEIGHBOR_ADDR_STR2
3203 "Specify a local-as number\n"
3204 "AS number used as local AS\n")
3205 {
3206 int idx_peer = 1;
3207 int idx_number = 3;
3208 struct peer *peer;
3209 int ret;
3210 as_t as;
3211
3212 peer = peer_and_group_lookup_vty(vty, argv[idx_peer]->arg);
3213 if (!peer)
3214 return CMD_WARNING_CONFIG_FAILED;
3215
3216 as = strtoul(argv[idx_number]->arg, NULL, 10);
3217 ret = peer_local_as_set(peer, as, 0, 0);
3218 return bgp_vty_return(vty, ret);
3219 }
3220
3221 DEFUN (neighbor_local_as_no_prepend,
3222 neighbor_local_as_no_prepend_cmd,
3223 "neighbor <A.B.C.D|X:X::X:X|WORD> local-as (1-4294967295) no-prepend",
3224 NEIGHBOR_STR
3225 NEIGHBOR_ADDR_STR2
3226 "Specify a local-as number\n"
3227 "AS number used as local AS\n"
3228 "Do not prepend local-as to updates from ebgp peers\n")
3229 {
3230 int idx_peer = 1;
3231 int idx_number = 3;
3232 struct peer *peer;
3233 int ret;
3234 as_t as;
3235
3236 peer = peer_and_group_lookup_vty(vty, argv[idx_peer]->arg);
3237 if (!peer)
3238 return CMD_WARNING_CONFIG_FAILED;
3239
3240 as = strtoul(argv[idx_number]->arg, NULL, 10);
3241 ret = peer_local_as_set(peer, as, 1, 0);
3242 return bgp_vty_return(vty, ret);
3243 }
3244
3245 DEFUN (neighbor_local_as_no_prepend_replace_as,
3246 neighbor_local_as_no_prepend_replace_as_cmd,
3247 "neighbor <A.B.C.D|X:X::X:X|WORD> local-as (1-4294967295) no-prepend replace-as",
3248 NEIGHBOR_STR
3249 NEIGHBOR_ADDR_STR2
3250 "Specify a local-as number\n"
3251 "AS number used as local AS\n"
3252 "Do not prepend local-as to updates from ebgp peers\n"
3253 "Do not prepend local-as to updates from ibgp peers\n")
3254 {
3255 int idx_peer = 1;
3256 int idx_number = 3;
3257 struct peer *peer;
3258 int ret;
3259 as_t as;
3260
3261 peer = peer_and_group_lookup_vty(vty, argv[idx_peer]->arg);
3262 if (!peer)
3263 return CMD_WARNING_CONFIG_FAILED;
3264
3265 as = strtoul(argv[idx_number]->arg, NULL, 10);
3266 ret = peer_local_as_set(peer, as, 1, 1);
3267 return bgp_vty_return(vty, ret);
3268 }
3269
3270 DEFUN (no_neighbor_local_as,
3271 no_neighbor_local_as_cmd,
3272 "no neighbor <A.B.C.D|X:X::X:X|WORD> local-as [(1-4294967295) [no-prepend [replace-as]]]",
3273 NO_STR
3274 NEIGHBOR_STR
3275 NEIGHBOR_ADDR_STR2
3276 "Specify a local-as number\n"
3277 "AS number used as local AS\n"
3278 "Do not prepend local-as to updates from ebgp peers\n"
3279 "Do not prepend local-as to updates from ibgp peers\n")
3280 {
3281 int idx_peer = 2;
3282 struct peer *peer;
3283 int ret;
3284
3285 peer = peer_and_group_lookup_vty(vty, argv[idx_peer]->arg);
3286 if (!peer)
3287 return CMD_WARNING_CONFIG_FAILED;
3288
3289 ret = peer_local_as_unset(peer);
3290 return bgp_vty_return(vty, ret);
3291 }
3292
3293
3294 DEFUN (neighbor_solo,
3295 neighbor_solo_cmd,
3296 "neighbor <A.B.C.D|X:X::X:X|WORD> solo",
3297 NEIGHBOR_STR
3298 NEIGHBOR_ADDR_STR2
3299 "Solo peer - part of its own update group\n")
3300 {
3301 int idx_peer = 1;
3302 struct peer *peer;
3303 int ret;
3304
3305 peer = peer_and_group_lookup_vty(vty, argv[idx_peer]->arg);
3306 if (!peer)
3307 return CMD_WARNING_CONFIG_FAILED;
3308
3309 ret = update_group_adjust_soloness(peer, 1);
3310 return bgp_vty_return(vty, ret);
3311 }
3312
3313 DEFUN (no_neighbor_solo,
3314 no_neighbor_solo_cmd,
3315 "no neighbor <A.B.C.D|X:X::X:X|WORD> solo",
3316 NO_STR
3317 NEIGHBOR_STR
3318 NEIGHBOR_ADDR_STR2
3319 "Solo peer - part of its own update group\n")
3320 {
3321 int idx_peer = 2;
3322 struct peer *peer;
3323 int ret;
3324
3325 peer = peer_and_group_lookup_vty(vty, argv[idx_peer]->arg);
3326 if (!peer)
3327 return CMD_WARNING_CONFIG_FAILED;
3328
3329 ret = update_group_adjust_soloness(peer, 0);
3330 return bgp_vty_return(vty, ret);
3331 }
3332
3333 DEFUN (neighbor_password,
3334 neighbor_password_cmd,
3335 "neighbor <A.B.C.D|X:X::X:X|WORD> password LINE",
3336 NEIGHBOR_STR
3337 NEIGHBOR_ADDR_STR2
3338 "Set a password\n"
3339 "The password\n")
3340 {
3341 int idx_peer = 1;
3342 int idx_line = 3;
3343 struct peer *peer;
3344 int ret;
3345
3346 peer = peer_and_group_lookup_vty(vty, argv[idx_peer]->arg);
3347 if (!peer)
3348 return CMD_WARNING_CONFIG_FAILED;
3349
3350 ret = peer_password_set(peer, argv[idx_line]->arg);
3351 return bgp_vty_return(vty, ret);
3352 }
3353
3354 DEFUN (no_neighbor_password,
3355 no_neighbor_password_cmd,
3356 "no neighbor <A.B.C.D|X:X::X:X|WORD> password [LINE]",
3357 NO_STR
3358 NEIGHBOR_STR
3359 NEIGHBOR_ADDR_STR2
3360 "Set a password\n"
3361 "The password\n")
3362 {
3363 int idx_peer = 2;
3364 struct peer *peer;
3365 int ret;
3366
3367 peer = peer_and_group_lookup_vty(vty, argv[idx_peer]->arg);
3368 if (!peer)
3369 return CMD_WARNING_CONFIG_FAILED;
3370
3371 ret = peer_password_unset(peer);
3372 return bgp_vty_return(vty, ret);
3373 }
3374
3375 DEFUN (neighbor_activate,
3376 neighbor_activate_cmd,
3377 "neighbor <A.B.C.D|X:X::X:X|WORD> activate",
3378 NEIGHBOR_STR
3379 NEIGHBOR_ADDR_STR2
3380 "Enable the Address Family for this Neighbor\n")
3381 {
3382 int idx_peer = 1;
3383 int ret;
3384 struct peer *peer;
3385
3386 peer = peer_and_group_lookup_vty(vty, argv[idx_peer]->arg);
3387 if (!peer)
3388 return CMD_WARNING_CONFIG_FAILED;
3389
3390 ret = peer_activate(peer, bgp_node_afi(vty), bgp_node_safi(vty));
3391 return bgp_vty_return(vty, ret);
3392 }
3393
3394 ALIAS_HIDDEN(neighbor_activate, neighbor_activate_hidden_cmd,
3395 "neighbor <A.B.C.D|X:X::X:X|WORD> activate",
3396 NEIGHBOR_STR NEIGHBOR_ADDR_STR2
3397 "Enable the Address Family for this Neighbor\n")
3398
3399 DEFUN (no_neighbor_activate,
3400 no_neighbor_activate_cmd,
3401 "no neighbor <A.B.C.D|X:X::X:X|WORD> activate",
3402 NO_STR
3403 NEIGHBOR_STR
3404 NEIGHBOR_ADDR_STR2
3405 "Enable the Address Family for this Neighbor\n")
3406 {
3407 int idx_peer = 2;
3408 int ret;
3409 struct peer *peer;
3410
3411 /* Lookup peer. */
3412 peer = peer_and_group_lookup_vty(vty, argv[idx_peer]->arg);
3413 if (!peer)
3414 return CMD_WARNING_CONFIG_FAILED;
3415
3416 ret = peer_deactivate(peer, bgp_node_afi(vty), bgp_node_safi(vty));
3417 return bgp_vty_return(vty, ret);
3418 }
3419
3420 ALIAS_HIDDEN(no_neighbor_activate, no_neighbor_activate_hidden_cmd,
3421 "no neighbor <A.B.C.D|X:X::X:X|WORD> activate",
3422 NO_STR NEIGHBOR_STR NEIGHBOR_ADDR_STR2
3423 "Enable the Address Family for this Neighbor\n")
3424
3425 DEFUN (neighbor_set_peer_group,
3426 neighbor_set_peer_group_cmd,
3427 "neighbor <A.B.C.D|X:X::X:X|WORD> peer-group PGNAME",
3428 NEIGHBOR_STR
3429 NEIGHBOR_ADDR_STR2
3430 "Member of the peer-group\n"
3431 "Peer-group name\n")
3432 {
3433 VTY_DECLVAR_CONTEXT(bgp, bgp);
3434 int idx_peer = 1;
3435 int idx_word = 3;
3436 int ret;
3437 as_t as;
3438 union sockunion su;
3439 struct peer *peer;
3440 struct peer_group *group;
3441
3442 ret = str2sockunion(argv[idx_peer]->arg, &su);
3443 if (ret < 0) {
3444 peer = peer_lookup_by_conf_if(bgp, argv[idx_peer]->arg);
3445 if (!peer) {
3446 vty_out(vty, "%% Malformed address or name: %s\n",
3447 argv[idx_peer]->arg);
3448 return CMD_WARNING_CONFIG_FAILED;
3449 }
3450 } else {
3451 if (peer_address_self_check(bgp, &su)) {
3452 vty_out(vty,
3453 "%% Can not configure the local system as neighbor\n");
3454 return CMD_WARNING_CONFIG_FAILED;
3455 }
3456
3457 /* Disallow for dynamic neighbor. */
3458 peer = peer_lookup(bgp, &su);
3459 if (peer && peer_dynamic_neighbor(peer)) {
3460 vty_out(vty,
3461 "%% Operation not allowed on a dynamic neighbor\n");
3462 return CMD_WARNING_CONFIG_FAILED;
3463 }
3464 }
3465
3466 group = peer_group_lookup(bgp, argv[idx_word]->arg);
3467 if (!group) {
3468 vty_out(vty, "%% Configure the peer-group first\n");
3469 return CMD_WARNING_CONFIG_FAILED;
3470 }
3471
3472 ret = peer_group_bind(bgp, &su, peer, group, &as);
3473
3474 if (ret == BGP_ERR_PEER_GROUP_PEER_TYPE_DIFFERENT) {
3475 vty_out(vty,
3476 "%% Peer with AS %u cannot be in this peer-group, members must be all internal or all external\n",
3477 as);
3478 return CMD_WARNING_CONFIG_FAILED;
3479 }
3480
3481 return bgp_vty_return(vty, ret);
3482 }
3483
3484 ALIAS_HIDDEN(neighbor_set_peer_group, neighbor_set_peer_group_hidden_cmd,
3485 "neighbor <A.B.C.D|X:X::X:X|WORD> peer-group PGNAME",
3486 NEIGHBOR_STR NEIGHBOR_ADDR_STR2
3487 "Member of the peer-group\n"
3488 "Peer-group name\n")
3489
3490 DEFUN (no_neighbor_set_peer_group,
3491 no_neighbor_set_peer_group_cmd,
3492 "no neighbor <A.B.C.D|X:X::X:X|WORD> peer-group PGNAME",
3493 NO_STR
3494 NEIGHBOR_STR
3495 NEIGHBOR_ADDR_STR2
3496 "Member of the peer-group\n"
3497 "Peer-group name\n")
3498 {
3499 VTY_DECLVAR_CONTEXT(bgp, bgp);
3500 int idx_peer = 2;
3501 int idx_word = 4;
3502 int ret;
3503 struct peer *peer;
3504 struct peer_group *group;
3505
3506 peer = peer_lookup_vty(vty, argv[idx_peer]->arg);
3507 if (!peer)
3508 return CMD_WARNING_CONFIG_FAILED;
3509
3510 group = peer_group_lookup(bgp, argv[idx_word]->arg);
3511 if (!group) {
3512 vty_out(vty, "%% Configure the peer-group first\n");
3513 return CMD_WARNING_CONFIG_FAILED;
3514 }
3515
3516 ret = peer_delete(peer);
3517
3518 return bgp_vty_return(vty, ret);
3519 }
3520
3521 ALIAS_HIDDEN(no_neighbor_set_peer_group, no_neighbor_set_peer_group_hidden_cmd,
3522 "no neighbor <A.B.C.D|X:X::X:X|WORD> peer-group PGNAME",
3523 NO_STR NEIGHBOR_STR NEIGHBOR_ADDR_STR2
3524 "Member of the peer-group\n"
3525 "Peer-group name\n")
3526
3527 static int peer_flag_modify_vty(struct vty *vty, const char *ip_str,
3528 uint32_t flag, int set)
3529 {
3530 int ret;
3531 struct peer *peer;
3532
3533 peer = peer_and_group_lookup_vty(vty, ip_str);
3534 if (!peer)
3535 return CMD_WARNING_CONFIG_FAILED;
3536
3537 /*
3538 * If 'neighbor <interface>', then this is for directly connected peers,
3539 * we should not accept disable-connected-check.
3540 */
3541 if (peer->conf_if && (flag == PEER_FLAG_DISABLE_CONNECTED_CHECK)) {
3542 vty_out(vty,
3543 "%s is directly connected peer, cannot accept disable-"
3544 "connected-check\n",
3545 ip_str);
3546 return CMD_WARNING_CONFIG_FAILED;
3547 }
3548
3549 if (!set && flag == PEER_FLAG_SHUTDOWN)
3550 peer_tx_shutdown_message_unset(peer);
3551
3552 if (set)
3553 ret = peer_flag_set(peer, flag);
3554 else
3555 ret = peer_flag_unset(peer, flag);
3556
3557 return bgp_vty_return(vty, ret);
3558 }
3559
3560 static int peer_flag_set_vty(struct vty *vty, const char *ip_str, uint32_t flag)
3561 {
3562 return peer_flag_modify_vty(vty, ip_str, flag, 1);
3563 }
3564
3565 static int peer_flag_unset_vty(struct vty *vty, const char *ip_str,
3566 uint32_t flag)
3567 {
3568 return peer_flag_modify_vty(vty, ip_str, flag, 0);
3569 }
3570
3571 /* neighbor passive. */
3572 DEFUN (neighbor_passive,
3573 neighbor_passive_cmd,
3574 "neighbor <A.B.C.D|X:X::X:X|WORD> passive",
3575 NEIGHBOR_STR
3576 NEIGHBOR_ADDR_STR2
3577 "Don't send open messages to this neighbor\n")
3578 {
3579 int idx_peer = 1;
3580 return peer_flag_set_vty(vty, argv[idx_peer]->arg, PEER_FLAG_PASSIVE);
3581 }
3582
3583 DEFUN (no_neighbor_passive,
3584 no_neighbor_passive_cmd,
3585 "no neighbor <A.B.C.D|X:X::X:X|WORD> passive",
3586 NO_STR
3587 NEIGHBOR_STR
3588 NEIGHBOR_ADDR_STR2
3589 "Don't send open messages to this neighbor\n")
3590 {
3591 int idx_peer = 2;
3592 return peer_flag_unset_vty(vty, argv[idx_peer]->arg, PEER_FLAG_PASSIVE);
3593 }
3594
3595 /* neighbor shutdown. */
3596 DEFUN (neighbor_shutdown_msg,
3597 neighbor_shutdown_msg_cmd,
3598 "neighbor <A.B.C.D|X:X::X:X|WORD> shutdown message MSG...",
3599 NEIGHBOR_STR
3600 NEIGHBOR_ADDR_STR2
3601 "Administratively shut down this neighbor\n"
3602 "Add a shutdown message (draft-ietf-idr-shutdown-06)\n"
3603 "Shutdown message\n")
3604 {
3605 int idx_peer = 1;
3606
3607 if (argc >= 5) {
3608 struct peer *peer =
3609 peer_and_group_lookup_vty(vty, argv[idx_peer]->arg);
3610 char *message;
3611
3612 if (!peer)
3613 return CMD_WARNING_CONFIG_FAILED;
3614 message = argv_concat(argv, argc, 4);
3615 peer_tx_shutdown_message_set(peer, message);
3616 XFREE(MTYPE_TMP, message);
3617 }
3618
3619 return peer_flag_set_vty(vty, argv[idx_peer]->arg, PEER_FLAG_SHUTDOWN);
3620 }
3621
3622 ALIAS(neighbor_shutdown_msg, neighbor_shutdown_cmd,
3623 "neighbor <A.B.C.D|X:X::X:X|WORD> shutdown",
3624 NEIGHBOR_STR NEIGHBOR_ADDR_STR2
3625 "Administratively shut down this neighbor\n")
3626
3627 DEFUN (no_neighbor_shutdown_msg,
3628 no_neighbor_shutdown_msg_cmd,
3629 "no neighbor <A.B.C.D|X:X::X:X|WORD> shutdown message MSG...",
3630 NO_STR
3631 NEIGHBOR_STR
3632 NEIGHBOR_ADDR_STR2
3633 "Administratively shut down this neighbor\n"
3634 "Remove a shutdown message (draft-ietf-idr-shutdown-06)\n"
3635 "Shutdown message\n")
3636 {
3637 int idx_peer = 2;
3638
3639 return peer_flag_unset_vty(vty, argv[idx_peer]->arg,
3640 PEER_FLAG_SHUTDOWN);
3641 }
3642
3643 ALIAS(no_neighbor_shutdown_msg, no_neighbor_shutdown_cmd,
3644 "no neighbor <A.B.C.D|X:X::X:X|WORD> shutdown",
3645 NO_STR NEIGHBOR_STR NEIGHBOR_ADDR_STR2
3646 "Administratively shut down this neighbor\n")
3647
3648 /* neighbor capability dynamic. */
3649 DEFUN (neighbor_capability_dynamic,
3650 neighbor_capability_dynamic_cmd,
3651 "neighbor <A.B.C.D|X:X::X:X|WORD> capability dynamic",
3652 NEIGHBOR_STR
3653 NEIGHBOR_ADDR_STR2
3654 "Advertise capability to the peer\n"
3655 "Advertise dynamic capability to this neighbor\n")
3656 {
3657 int idx_peer = 1;
3658 return peer_flag_set_vty(vty, argv[idx_peer]->arg,
3659 PEER_FLAG_DYNAMIC_CAPABILITY);
3660 }
3661
3662 DEFUN (no_neighbor_capability_dynamic,
3663 no_neighbor_capability_dynamic_cmd,
3664 "no neighbor <A.B.C.D|X:X::X:X|WORD> capability dynamic",
3665 NO_STR
3666 NEIGHBOR_STR
3667 NEIGHBOR_ADDR_STR2
3668 "Advertise capability to the peer\n"
3669 "Advertise dynamic capability to this neighbor\n")
3670 {
3671 int idx_peer = 2;
3672 return peer_flag_unset_vty(vty, argv[idx_peer]->arg,
3673 PEER_FLAG_DYNAMIC_CAPABILITY);
3674 }
3675
3676 /* neighbor dont-capability-negotiate */
3677 DEFUN (neighbor_dont_capability_negotiate,
3678 neighbor_dont_capability_negotiate_cmd,
3679 "neighbor <A.B.C.D|X:X::X:X|WORD> dont-capability-negotiate",
3680 NEIGHBOR_STR
3681 NEIGHBOR_ADDR_STR2
3682 "Do not perform capability negotiation\n")
3683 {
3684 int idx_peer = 1;
3685 return peer_flag_set_vty(vty, argv[idx_peer]->arg,
3686 PEER_FLAG_DONT_CAPABILITY);
3687 }
3688
3689 DEFUN (no_neighbor_dont_capability_negotiate,
3690 no_neighbor_dont_capability_negotiate_cmd,
3691 "no neighbor <A.B.C.D|X:X::X:X|WORD> dont-capability-negotiate",
3692 NO_STR
3693 NEIGHBOR_STR
3694 NEIGHBOR_ADDR_STR2
3695 "Do not perform capability negotiation\n")
3696 {
3697 int idx_peer = 2;
3698 return peer_flag_unset_vty(vty, argv[idx_peer]->arg,
3699 PEER_FLAG_DONT_CAPABILITY);
3700 }
3701
3702 /* neighbor capability extended next hop encoding */
3703 DEFUN (neighbor_capability_enhe,
3704 neighbor_capability_enhe_cmd,
3705 "neighbor <A.B.C.D|X:X::X:X|WORD> capability extended-nexthop",
3706 NEIGHBOR_STR
3707 NEIGHBOR_ADDR_STR2
3708 "Advertise capability to the peer\n"
3709 "Advertise extended next-hop capability to the peer\n")
3710 {
3711 int idx_peer = 1;
3712 return peer_flag_set_vty(vty, argv[idx_peer]->arg,
3713 PEER_FLAG_CAPABILITY_ENHE);
3714 }
3715
3716 DEFUN (no_neighbor_capability_enhe,
3717 no_neighbor_capability_enhe_cmd,
3718 "no neighbor <A.B.C.D|X:X::X:X|WORD> capability extended-nexthop",
3719 NO_STR
3720 NEIGHBOR_STR
3721 NEIGHBOR_ADDR_STR2
3722 "Advertise capability to the peer\n"
3723 "Advertise extended next-hop capability to the peer\n")
3724 {
3725 int idx_peer = 2;
3726 return peer_flag_unset_vty(vty, argv[idx_peer]->arg,
3727 PEER_FLAG_CAPABILITY_ENHE);
3728 }
3729
3730 static int peer_af_flag_modify_vty(struct vty *vty, const char *peer_str,
3731 afi_t afi, safi_t safi, uint32_t flag,
3732 int set)
3733 {
3734 int ret;
3735 struct peer *peer;
3736
3737 peer = peer_and_group_lookup_vty(vty, peer_str);
3738 if (!peer)
3739 return CMD_WARNING_CONFIG_FAILED;
3740
3741 if (set)
3742 ret = peer_af_flag_set(peer, afi, safi, flag);
3743 else
3744 ret = peer_af_flag_unset(peer, afi, safi, flag);
3745
3746 return bgp_vty_return(vty, ret);
3747 }
3748
3749 static int peer_af_flag_set_vty(struct vty *vty, const char *peer_str,
3750 afi_t afi, safi_t safi, uint32_t flag)
3751 {
3752 return peer_af_flag_modify_vty(vty, peer_str, afi, safi, flag, 1);
3753 }
3754
3755 static int peer_af_flag_unset_vty(struct vty *vty, const char *peer_str,
3756 afi_t afi, safi_t safi, uint32_t flag)
3757 {
3758 return peer_af_flag_modify_vty(vty, peer_str, afi, safi, flag, 0);
3759 }
3760
3761 /* neighbor capability orf prefix-list. */
3762 DEFUN (neighbor_capability_orf_prefix,
3763 neighbor_capability_orf_prefix_cmd,
3764 "neighbor <A.B.C.D|X:X::X:X|WORD> capability orf prefix-list <both|send|receive>",
3765 NEIGHBOR_STR
3766 NEIGHBOR_ADDR_STR2
3767 "Advertise capability to the peer\n"
3768 "Advertise ORF capability to the peer\n"
3769 "Advertise prefixlist ORF capability to this neighbor\n"
3770 "Capability to SEND and RECEIVE the ORF to/from this neighbor\n"
3771 "Capability to RECEIVE the ORF from this neighbor\n"
3772 "Capability to SEND the ORF to this neighbor\n")
3773 {
3774 int idx_peer = 1;
3775 int idx_send_recv = 5;
3776 uint16_t flag = 0;
3777
3778 if (strmatch(argv[idx_send_recv]->text, "send"))
3779 flag = PEER_FLAG_ORF_PREFIX_SM;
3780 else if (strmatch(argv[idx_send_recv]->text, "receive"))
3781 flag = PEER_FLAG_ORF_PREFIX_RM;
3782 else if (strmatch(argv[idx_send_recv]->text, "both"))
3783 flag = PEER_FLAG_ORF_PREFIX_SM | PEER_FLAG_ORF_PREFIX_RM;
3784 else {
3785 vty_out(vty, "%% BGP invalid orf prefix-list option\n");
3786 return CMD_WARNING_CONFIG_FAILED;
3787 }
3788
3789 return peer_af_flag_set_vty(vty, argv[idx_peer]->arg, bgp_node_afi(vty),
3790 bgp_node_safi(vty), flag);
3791 }
3792
3793 ALIAS_HIDDEN(
3794 neighbor_capability_orf_prefix,
3795 neighbor_capability_orf_prefix_hidden_cmd,
3796 "neighbor <A.B.C.D|X:X::X:X|WORD> capability orf prefix-list <both|send|receive>",
3797 NEIGHBOR_STR NEIGHBOR_ADDR_STR2
3798 "Advertise capability to the peer\n"
3799 "Advertise ORF capability to the peer\n"
3800 "Advertise prefixlist ORF capability to this neighbor\n"
3801 "Capability to SEND and RECEIVE the ORF to/from this neighbor\n"
3802 "Capability to RECEIVE the ORF from this neighbor\n"
3803 "Capability to SEND the ORF to this neighbor\n")
3804
3805 DEFUN (no_neighbor_capability_orf_prefix,
3806 no_neighbor_capability_orf_prefix_cmd,
3807 "no neighbor <A.B.C.D|X:X::X:X|WORD> capability orf prefix-list <both|send|receive>",
3808 NO_STR
3809 NEIGHBOR_STR
3810 NEIGHBOR_ADDR_STR2
3811 "Advertise capability to the peer\n"
3812 "Advertise ORF capability to the peer\n"
3813 "Advertise prefixlist ORF capability to this neighbor\n"
3814 "Capability to SEND and RECEIVE the ORF to/from this neighbor\n"
3815 "Capability to RECEIVE the ORF from this neighbor\n"
3816 "Capability to SEND the ORF to this neighbor\n")
3817 {
3818 int idx_peer = 2;
3819 int idx_send_recv = 6;
3820 uint16_t flag = 0;
3821
3822 if (strmatch(argv[idx_send_recv]->text, "send"))
3823 flag = PEER_FLAG_ORF_PREFIX_SM;
3824 else if (strmatch(argv[idx_send_recv]->text, "receive"))
3825 flag = PEER_FLAG_ORF_PREFIX_RM;
3826 else if (strmatch(argv[idx_send_recv]->text, "both"))
3827 flag = PEER_FLAG_ORF_PREFIX_SM | PEER_FLAG_ORF_PREFIX_RM;
3828 else {
3829 vty_out(vty, "%% BGP invalid orf prefix-list option\n");
3830 return CMD_WARNING_CONFIG_FAILED;
3831 }
3832
3833 return peer_af_flag_unset_vty(vty, argv[idx_peer]->arg,
3834 bgp_node_afi(vty), bgp_node_safi(vty),
3835 flag);
3836 }
3837
3838 ALIAS_HIDDEN(
3839 no_neighbor_capability_orf_prefix,
3840 no_neighbor_capability_orf_prefix_hidden_cmd,
3841 "no neighbor <A.B.C.D|X:X::X:X|WORD> capability orf prefix-list <both|send|receive>",
3842 NO_STR NEIGHBOR_STR NEIGHBOR_ADDR_STR2
3843 "Advertise capability to the peer\n"
3844 "Advertise ORF capability to the peer\n"
3845 "Advertise prefixlist ORF capability to this neighbor\n"
3846 "Capability to SEND and RECEIVE the ORF to/from this neighbor\n"
3847 "Capability to RECEIVE the ORF from this neighbor\n"
3848 "Capability to SEND the ORF to this neighbor\n")
3849
3850 /* neighbor next-hop-self. */
3851 DEFUN (neighbor_nexthop_self,
3852 neighbor_nexthop_self_cmd,
3853 "neighbor <A.B.C.D|X:X::X:X|WORD> next-hop-self",
3854 NEIGHBOR_STR
3855 NEIGHBOR_ADDR_STR2
3856 "Disable the next hop calculation for this neighbor\n")
3857 {
3858 int idx_peer = 1;
3859 return peer_af_flag_set_vty(vty, argv[idx_peer]->arg, bgp_node_afi(vty),
3860 bgp_node_safi(vty), PEER_FLAG_NEXTHOP_SELF);
3861 }
3862
3863 ALIAS_HIDDEN(neighbor_nexthop_self, neighbor_nexthop_self_hidden_cmd,
3864 "neighbor <A.B.C.D|X:X::X:X|WORD> next-hop-self",
3865 NEIGHBOR_STR NEIGHBOR_ADDR_STR2
3866 "Disable the next hop calculation for this neighbor\n")
3867
3868 /* neighbor next-hop-self. */
3869 DEFUN (neighbor_nexthop_self_force,
3870 neighbor_nexthop_self_force_cmd,
3871 "neighbor <A.B.C.D|X:X::X:X|WORD> next-hop-self force",
3872 NEIGHBOR_STR
3873 NEIGHBOR_ADDR_STR2
3874 "Disable the next hop calculation for this neighbor\n"
3875 "Set the next hop to self for reflected routes\n")
3876 {
3877 int idx_peer = 1;
3878 return peer_af_flag_set_vty(vty, argv[idx_peer]->arg, bgp_node_afi(vty),
3879 bgp_node_safi(vty),
3880 PEER_FLAG_FORCE_NEXTHOP_SELF);
3881 }
3882
3883 ALIAS_HIDDEN(neighbor_nexthop_self_force,
3884 neighbor_nexthop_self_force_hidden_cmd,
3885 "neighbor <A.B.C.D|X:X::X:X|WORD> next-hop-self force",
3886 NEIGHBOR_STR NEIGHBOR_ADDR_STR2
3887 "Disable the next hop calculation for this neighbor\n"
3888 "Set the next hop to self for reflected routes\n")
3889
3890 ALIAS_HIDDEN(neighbor_nexthop_self_force,
3891 neighbor_nexthop_self_all_hidden_cmd,
3892 "neighbor <A.B.C.D|X:X::X:X|WORD> next-hop-self all",
3893 NEIGHBOR_STR NEIGHBOR_ADDR_STR2
3894 "Disable the next hop calculation for this neighbor\n"
3895 "Set the next hop to self for reflected routes\n")
3896
3897 DEFUN (no_neighbor_nexthop_self,
3898 no_neighbor_nexthop_self_cmd,
3899 "no neighbor <A.B.C.D|X:X::X:X|WORD> next-hop-self",
3900 NO_STR
3901 NEIGHBOR_STR
3902 NEIGHBOR_ADDR_STR2
3903 "Disable the next hop calculation for this neighbor\n")
3904 {
3905 int idx_peer = 2;
3906 return peer_af_flag_unset_vty(vty, argv[idx_peer]->arg,
3907 bgp_node_afi(vty), bgp_node_safi(vty),
3908 PEER_FLAG_NEXTHOP_SELF);
3909 }
3910
3911 ALIAS_HIDDEN(no_neighbor_nexthop_self, no_neighbor_nexthop_self_hidden_cmd,
3912 "no neighbor <A.B.C.D|X:X::X:X|WORD> next-hop-self",
3913 NO_STR NEIGHBOR_STR NEIGHBOR_ADDR_STR2
3914 "Disable the next hop calculation for this neighbor\n")
3915
3916 DEFUN (no_neighbor_nexthop_self_force,
3917 no_neighbor_nexthop_self_force_cmd,
3918 "no neighbor <A.B.C.D|X:X::X:X|WORD> next-hop-self force",
3919 NO_STR
3920 NEIGHBOR_STR
3921 NEIGHBOR_ADDR_STR2
3922 "Disable the next hop calculation for this neighbor\n"
3923 "Set the next hop to self for reflected routes\n")
3924 {
3925 int idx_peer = 2;
3926 return peer_af_flag_unset_vty(vty, argv[idx_peer]->arg,
3927 bgp_node_afi(vty), bgp_node_safi(vty),
3928 PEER_FLAG_FORCE_NEXTHOP_SELF);
3929 }
3930
3931 ALIAS_HIDDEN(no_neighbor_nexthop_self_force,
3932 no_neighbor_nexthop_self_force_hidden_cmd,
3933 "no neighbor <A.B.C.D|X:X::X:X|WORD> next-hop-self force",
3934 NO_STR NEIGHBOR_STR NEIGHBOR_ADDR_STR2
3935 "Disable the next hop calculation for this neighbor\n"
3936 "Set the next hop to self for reflected routes\n")
3937
3938 ALIAS_HIDDEN(no_neighbor_nexthop_self_force,
3939 no_neighbor_nexthop_self_all_hidden_cmd,
3940 "no neighbor <A.B.C.D|X:X::X:X|WORD> next-hop-self all",
3941 NO_STR NEIGHBOR_STR NEIGHBOR_ADDR_STR2
3942 "Disable the next hop calculation for this neighbor\n"
3943 "Set the next hop to self for reflected routes\n")
3944
3945 /* neighbor as-override */
3946 DEFUN (neighbor_as_override,
3947 neighbor_as_override_cmd,
3948 "neighbor <A.B.C.D|X:X::X:X|WORD> as-override",
3949 NEIGHBOR_STR
3950 NEIGHBOR_ADDR_STR2
3951 "Override ASNs in outbound updates if aspath equals remote-as\n")
3952 {
3953 int idx_peer = 1;
3954 return peer_af_flag_set_vty(vty, argv[idx_peer]->arg, bgp_node_afi(vty),
3955 bgp_node_safi(vty), PEER_FLAG_AS_OVERRIDE);
3956 }
3957
3958 ALIAS_HIDDEN(neighbor_as_override, neighbor_as_override_hidden_cmd,
3959 "neighbor <A.B.C.D|X:X::X:X|WORD> as-override",
3960 NEIGHBOR_STR NEIGHBOR_ADDR_STR2
3961 "Override ASNs in outbound updates if aspath equals remote-as\n")
3962
3963 DEFUN (no_neighbor_as_override,
3964 no_neighbor_as_override_cmd,
3965 "no neighbor <A.B.C.D|X:X::X:X|WORD> as-override",
3966 NO_STR
3967 NEIGHBOR_STR
3968 NEIGHBOR_ADDR_STR2
3969 "Override ASNs in outbound updates if aspath equals remote-as\n")
3970 {
3971 int idx_peer = 2;
3972 return peer_af_flag_unset_vty(vty, argv[idx_peer]->arg,
3973 bgp_node_afi(vty), bgp_node_safi(vty),
3974 PEER_FLAG_AS_OVERRIDE);
3975 }
3976
3977 ALIAS_HIDDEN(no_neighbor_as_override, no_neighbor_as_override_hidden_cmd,
3978 "no neighbor <A.B.C.D|X:X::X:X|WORD> as-override",
3979 NO_STR NEIGHBOR_STR NEIGHBOR_ADDR_STR2
3980 "Override ASNs in outbound updates if aspath equals remote-as\n")
3981
3982 /* neighbor remove-private-AS. */
3983 DEFUN (neighbor_remove_private_as,
3984 neighbor_remove_private_as_cmd,
3985 "neighbor <A.B.C.D|X:X::X:X|WORD> remove-private-AS",
3986 NEIGHBOR_STR
3987 NEIGHBOR_ADDR_STR2
3988 "Remove private ASNs in outbound updates\n")
3989 {
3990 int idx_peer = 1;
3991 return peer_af_flag_set_vty(vty, argv[idx_peer]->arg, bgp_node_afi(vty),
3992 bgp_node_safi(vty),
3993 PEER_FLAG_REMOVE_PRIVATE_AS);
3994 }
3995
3996 ALIAS_HIDDEN(neighbor_remove_private_as, neighbor_remove_private_as_hidden_cmd,
3997 "neighbor <A.B.C.D|X:X::X:X|WORD> remove-private-AS",
3998 NEIGHBOR_STR NEIGHBOR_ADDR_STR2
3999 "Remove private ASNs in outbound updates\n")
4000
4001 DEFUN (neighbor_remove_private_as_all,
4002 neighbor_remove_private_as_all_cmd,
4003 "neighbor <A.B.C.D|X:X::X:X|WORD> remove-private-AS all",
4004 NEIGHBOR_STR
4005 NEIGHBOR_ADDR_STR2
4006 "Remove private ASNs in outbound updates\n"
4007 "Apply to all AS numbers\n")
4008 {
4009 int idx_peer = 1;
4010 return peer_af_flag_set_vty(vty, argv[idx_peer]->arg, bgp_node_afi(vty),
4011 bgp_node_safi(vty),
4012 PEER_FLAG_REMOVE_PRIVATE_AS_ALL);
4013 }
4014
4015 ALIAS_HIDDEN(neighbor_remove_private_as_all,
4016 neighbor_remove_private_as_all_hidden_cmd,
4017 "neighbor <A.B.C.D|X:X::X:X|WORD> remove-private-AS all",
4018 NEIGHBOR_STR NEIGHBOR_ADDR_STR2
4019 "Remove private ASNs in outbound updates\n"
4020 "Apply to all AS numbers")
4021
4022 DEFUN (neighbor_remove_private_as_replace_as,
4023 neighbor_remove_private_as_replace_as_cmd,
4024 "neighbor <A.B.C.D|X:X::X:X|WORD> remove-private-AS replace-AS",
4025 NEIGHBOR_STR
4026 NEIGHBOR_ADDR_STR2
4027 "Remove private ASNs in outbound updates\n"
4028 "Replace private ASNs with our ASN in outbound updates\n")
4029 {
4030 int idx_peer = 1;
4031 return peer_af_flag_set_vty(vty, argv[idx_peer]->arg, bgp_node_afi(vty),
4032 bgp_node_safi(vty),
4033 PEER_FLAG_REMOVE_PRIVATE_AS_REPLACE);
4034 }
4035
4036 ALIAS_HIDDEN(neighbor_remove_private_as_replace_as,
4037 neighbor_remove_private_as_replace_as_hidden_cmd,
4038 "neighbor <A.B.C.D|X:X::X:X|WORD> remove-private-AS replace-AS",
4039 NEIGHBOR_STR NEIGHBOR_ADDR_STR2
4040 "Remove private ASNs in outbound updates\n"
4041 "Replace private ASNs with our ASN in outbound updates\n")
4042
4043 DEFUN (neighbor_remove_private_as_all_replace_as,
4044 neighbor_remove_private_as_all_replace_as_cmd,
4045 "neighbor <A.B.C.D|X:X::X:X|WORD> remove-private-AS all replace-AS",
4046 NEIGHBOR_STR
4047 NEIGHBOR_ADDR_STR2
4048 "Remove private ASNs in outbound updates\n"
4049 "Apply to all AS numbers\n"
4050 "Replace private ASNs with our ASN in outbound updates\n")
4051 {
4052 int idx_peer = 1;
4053 return peer_af_flag_set_vty(vty, argv[idx_peer]->arg, bgp_node_afi(vty),
4054 bgp_node_safi(vty),
4055 PEER_FLAG_REMOVE_PRIVATE_AS_ALL_REPLACE);
4056 }
4057
4058 ALIAS_HIDDEN(
4059 neighbor_remove_private_as_all_replace_as,
4060 neighbor_remove_private_as_all_replace_as_hidden_cmd,
4061 "neighbor <A.B.C.D|X:X::X:X|WORD> remove-private-AS all replace-AS",
4062 NEIGHBOR_STR NEIGHBOR_ADDR_STR2
4063 "Remove private ASNs in outbound updates\n"
4064 "Apply to all AS numbers\n"
4065 "Replace private ASNs with our ASN in outbound updates\n")
4066
4067 DEFUN (no_neighbor_remove_private_as,
4068 no_neighbor_remove_private_as_cmd,
4069 "no neighbor <A.B.C.D|X:X::X:X|WORD> remove-private-AS",
4070 NO_STR
4071 NEIGHBOR_STR
4072 NEIGHBOR_ADDR_STR2
4073 "Remove private ASNs in outbound updates\n")
4074 {
4075 int idx_peer = 2;
4076 return peer_af_flag_unset_vty(vty, argv[idx_peer]->arg,
4077 bgp_node_afi(vty), bgp_node_safi(vty),
4078 PEER_FLAG_REMOVE_PRIVATE_AS);
4079 }
4080
4081 ALIAS_HIDDEN(no_neighbor_remove_private_as,
4082 no_neighbor_remove_private_as_hidden_cmd,
4083 "no neighbor <A.B.C.D|X:X::X:X|WORD> remove-private-AS",
4084 NO_STR NEIGHBOR_STR NEIGHBOR_ADDR_STR2
4085 "Remove private ASNs in outbound updates\n")
4086
4087 DEFUN (no_neighbor_remove_private_as_all,
4088 no_neighbor_remove_private_as_all_cmd,
4089 "no neighbor <A.B.C.D|X:X::X:X|WORD> remove-private-AS all",
4090 NO_STR
4091 NEIGHBOR_STR
4092 NEIGHBOR_ADDR_STR2
4093 "Remove private ASNs in outbound updates\n"
4094 "Apply to all AS numbers\n")
4095 {
4096 int idx_peer = 2;
4097 return peer_af_flag_unset_vty(vty, argv[idx_peer]->arg,
4098 bgp_node_afi(vty), bgp_node_safi(vty),
4099 PEER_FLAG_REMOVE_PRIVATE_AS_ALL);
4100 }
4101
4102 ALIAS_HIDDEN(no_neighbor_remove_private_as_all,
4103 no_neighbor_remove_private_as_all_hidden_cmd,
4104 "no neighbor <A.B.C.D|X:X::X:X|WORD> remove-private-AS all",
4105 NO_STR NEIGHBOR_STR NEIGHBOR_ADDR_STR2
4106 "Remove private ASNs in outbound updates\n"
4107 "Apply to all AS numbers\n")
4108
4109 DEFUN (no_neighbor_remove_private_as_replace_as,
4110 no_neighbor_remove_private_as_replace_as_cmd,
4111 "no neighbor <A.B.C.D|X:X::X:X|WORD> remove-private-AS replace-AS",
4112 NO_STR
4113 NEIGHBOR_STR
4114 NEIGHBOR_ADDR_STR2
4115 "Remove private ASNs in outbound updates\n"
4116 "Replace private ASNs with our ASN in outbound updates\n")
4117 {
4118 int idx_peer = 2;
4119 return peer_af_flag_unset_vty(vty, argv[idx_peer]->arg,
4120 bgp_node_afi(vty), bgp_node_safi(vty),
4121 PEER_FLAG_REMOVE_PRIVATE_AS_REPLACE);
4122 }
4123
4124 ALIAS_HIDDEN(no_neighbor_remove_private_as_replace_as,
4125 no_neighbor_remove_private_as_replace_as_hidden_cmd,
4126 "no neighbor <A.B.C.D|X:X::X:X|WORD> remove-private-AS replace-AS",
4127 NO_STR NEIGHBOR_STR NEIGHBOR_ADDR_STR2
4128 "Remove private ASNs in outbound updates\n"
4129 "Replace private ASNs with our ASN in outbound updates\n")
4130
4131 DEFUN (no_neighbor_remove_private_as_all_replace_as,
4132 no_neighbor_remove_private_as_all_replace_as_cmd,
4133 "no neighbor <A.B.C.D|X:X::X:X|WORD> remove-private-AS all replace-AS",
4134 NO_STR
4135 NEIGHBOR_STR
4136 NEIGHBOR_ADDR_STR2
4137 "Remove private ASNs in outbound updates\n"
4138 "Apply to all AS numbers\n"
4139 "Replace private ASNs with our ASN in outbound updates\n")
4140 {
4141 int idx_peer = 2;
4142 return peer_af_flag_unset_vty(vty, argv[idx_peer]->arg,
4143 bgp_node_afi(vty), bgp_node_safi(vty),
4144 PEER_FLAG_REMOVE_PRIVATE_AS_ALL_REPLACE);
4145 }
4146
4147 ALIAS_HIDDEN(
4148 no_neighbor_remove_private_as_all_replace_as,
4149 no_neighbor_remove_private_as_all_replace_as_hidden_cmd,
4150 "no neighbor <A.B.C.D|X:X::X:X|WORD> remove-private-AS all replace-AS",
4151 NO_STR NEIGHBOR_STR NEIGHBOR_ADDR_STR2
4152 "Remove private ASNs in outbound updates\n"
4153 "Apply to all AS numbers\n"
4154 "Replace private ASNs with our ASN in outbound updates\n")
4155
4156
4157 /* neighbor send-community. */
4158 DEFUN (neighbor_send_community,
4159 neighbor_send_community_cmd,
4160 "neighbor <A.B.C.D|X:X::X:X|WORD> send-community",
4161 NEIGHBOR_STR
4162 NEIGHBOR_ADDR_STR2
4163 "Send Community attribute to this neighbor\n")
4164 {
4165 int idx_peer = 1;
4166
4167 return peer_af_flag_set_vty(vty, argv[idx_peer]->arg, bgp_node_afi(vty),
4168 bgp_node_safi(vty),
4169 PEER_FLAG_SEND_COMMUNITY);
4170 }
4171
4172 ALIAS_HIDDEN(neighbor_send_community, neighbor_send_community_hidden_cmd,
4173 "neighbor <A.B.C.D|X:X::X:X|WORD> send-community",
4174 NEIGHBOR_STR NEIGHBOR_ADDR_STR2
4175 "Send Community attribute to this neighbor\n")
4176
4177 DEFUN (no_neighbor_send_community,
4178 no_neighbor_send_community_cmd,
4179 "no neighbor <A.B.C.D|X:X::X:X|WORD> send-community",
4180 NO_STR
4181 NEIGHBOR_STR
4182 NEIGHBOR_ADDR_STR2
4183 "Send Community attribute to this neighbor\n")
4184 {
4185 int idx_peer = 2;
4186
4187 return peer_af_flag_unset_vty(vty, argv[idx_peer]->arg,
4188 bgp_node_afi(vty), bgp_node_safi(vty),
4189 PEER_FLAG_SEND_COMMUNITY);
4190 }
4191
4192 ALIAS_HIDDEN(no_neighbor_send_community, no_neighbor_send_community_hidden_cmd,
4193 "no neighbor <A.B.C.D|X:X::X:X|WORD> send-community",
4194 NO_STR NEIGHBOR_STR NEIGHBOR_ADDR_STR2
4195 "Send Community attribute to this neighbor\n")
4196
4197 /* neighbor send-community extended. */
4198 DEFUN (neighbor_send_community_type,
4199 neighbor_send_community_type_cmd,
4200 "neighbor <A.B.C.D|X:X::X:X|WORD> send-community <both|all|extended|standard|large>",
4201 NEIGHBOR_STR
4202 NEIGHBOR_ADDR_STR2
4203 "Send Community attribute to this neighbor\n"
4204 "Send Standard and Extended Community attributes\n"
4205 "Send Standard, Large and Extended Community attributes\n"
4206 "Send Extended Community attributes\n"
4207 "Send Standard Community attributes\n"
4208 "Send Large Community attributes\n")
4209 {
4210 int idx_peer = 1;
4211 uint32_t flag = 0;
4212 const char *type = argv[argc - 1]->text;
4213
4214 if (strmatch(type, "standard")) {
4215 SET_FLAG(flag, PEER_FLAG_SEND_COMMUNITY);
4216 } else if (strmatch(type, "extended")) {
4217 SET_FLAG(flag, PEER_FLAG_SEND_EXT_COMMUNITY);
4218 } else if (strmatch(type, "large")) {
4219 SET_FLAG(flag, PEER_FLAG_SEND_LARGE_COMMUNITY);
4220 } else if (strmatch(type, "both")) {
4221 SET_FLAG(flag, PEER_FLAG_SEND_COMMUNITY);
4222 SET_FLAG(flag, PEER_FLAG_SEND_EXT_COMMUNITY);
4223 } else { /* if (strmatch(type, "all")) */
4224 SET_FLAG(flag, PEER_FLAG_SEND_COMMUNITY);
4225 SET_FLAG(flag, PEER_FLAG_SEND_EXT_COMMUNITY);
4226 SET_FLAG(flag, PEER_FLAG_SEND_LARGE_COMMUNITY);
4227 }
4228
4229 return peer_af_flag_set_vty(vty, argv[idx_peer]->arg, bgp_node_afi(vty),
4230 bgp_node_safi(vty), flag);
4231 }
4232
4233 ALIAS_HIDDEN(
4234 neighbor_send_community_type, neighbor_send_community_type_hidden_cmd,
4235 "neighbor <A.B.C.D|X:X::X:X|WORD> send-community <both|all|extended|standard|large>",
4236 NEIGHBOR_STR NEIGHBOR_ADDR_STR2
4237 "Send Community attribute to this neighbor\n"
4238 "Send Standard and Extended Community attributes\n"
4239 "Send Standard, Large and Extended Community attributes\n"
4240 "Send Extended Community attributes\n"
4241 "Send Standard Community attributes\n"
4242 "Send Large Community attributes\n")
4243
4244 DEFUN (no_neighbor_send_community_type,
4245 no_neighbor_send_community_type_cmd,
4246 "no neighbor <A.B.C.D|X:X::X:X|WORD> send-community <both|all|extended|standard|large>",
4247 NO_STR
4248 NEIGHBOR_STR
4249 NEIGHBOR_ADDR_STR2
4250 "Send Community attribute to this neighbor\n"
4251 "Send Standard and Extended Community attributes\n"
4252 "Send Standard, Large and Extended Community attributes\n"
4253 "Send Extended Community attributes\n"
4254 "Send Standard Community attributes\n"
4255 "Send Large Community attributes\n")
4256 {
4257 int idx_peer = 2;
4258 uint32_t flag = 0;
4259 const char *type = argv[argc - 1]->text;
4260
4261 if (strmatch(type, "standard")) {
4262 SET_FLAG(flag, PEER_FLAG_SEND_COMMUNITY);
4263 } else if (strmatch(type, "extended")) {
4264 SET_FLAG(flag, PEER_FLAG_SEND_EXT_COMMUNITY);
4265 } else if (strmatch(type, "large")) {
4266 SET_FLAG(flag, PEER_FLAG_SEND_LARGE_COMMUNITY);
4267 } else if (strmatch(type, "both")) {
4268 SET_FLAG(flag, PEER_FLAG_SEND_COMMUNITY);
4269 SET_FLAG(flag, PEER_FLAG_SEND_EXT_COMMUNITY);
4270 } else { /* if (strmatch(type, "all")) */
4271 SET_FLAG(flag, PEER_FLAG_SEND_COMMUNITY);
4272 SET_FLAG(flag, PEER_FLAG_SEND_EXT_COMMUNITY);
4273 SET_FLAG(flag, PEER_FLAG_SEND_LARGE_COMMUNITY);
4274 }
4275
4276 return peer_af_flag_unset_vty(vty, argv[idx_peer]->arg,
4277 bgp_node_afi(vty), bgp_node_safi(vty),
4278 flag);
4279 }
4280
4281 ALIAS_HIDDEN(
4282 no_neighbor_send_community_type,
4283 no_neighbor_send_community_type_hidden_cmd,
4284 "no neighbor <A.B.C.D|X:X::X:X|WORD> send-community <both|all|extended|standard|large>",
4285 NO_STR NEIGHBOR_STR NEIGHBOR_ADDR_STR2
4286 "Send Community attribute to this neighbor\n"
4287 "Send Standard and Extended Community attributes\n"
4288 "Send Standard, Large and Extended Community attributes\n"
4289 "Send Extended Community attributes\n"
4290 "Send Standard Community attributes\n"
4291 "Send Large Community attributes\n")
4292
4293 /* neighbor soft-reconfig. */
4294 DEFUN (neighbor_soft_reconfiguration,
4295 neighbor_soft_reconfiguration_cmd,
4296 "neighbor <A.B.C.D|X:X::X:X|WORD> soft-reconfiguration inbound",
4297 NEIGHBOR_STR
4298 NEIGHBOR_ADDR_STR2
4299 "Per neighbor soft reconfiguration\n"
4300 "Allow inbound soft reconfiguration for this neighbor\n")
4301 {
4302 int idx_peer = 1;
4303 return peer_af_flag_set_vty(vty, argv[idx_peer]->arg, bgp_node_afi(vty),
4304 bgp_node_safi(vty),
4305 PEER_FLAG_SOFT_RECONFIG);
4306 }
4307
4308 ALIAS_HIDDEN(neighbor_soft_reconfiguration,
4309 neighbor_soft_reconfiguration_hidden_cmd,
4310 "neighbor <A.B.C.D|X:X::X:X|WORD> soft-reconfiguration inbound",
4311 NEIGHBOR_STR NEIGHBOR_ADDR_STR2
4312 "Per neighbor soft reconfiguration\n"
4313 "Allow inbound soft reconfiguration for this neighbor\n")
4314
4315 DEFUN (no_neighbor_soft_reconfiguration,
4316 no_neighbor_soft_reconfiguration_cmd,
4317 "no neighbor <A.B.C.D|X:X::X:X|WORD> soft-reconfiguration inbound",
4318 NO_STR
4319 NEIGHBOR_STR
4320 NEIGHBOR_ADDR_STR2
4321 "Per neighbor soft reconfiguration\n"
4322 "Allow inbound soft reconfiguration for this neighbor\n")
4323 {
4324 int idx_peer = 2;
4325 return peer_af_flag_unset_vty(vty, argv[idx_peer]->arg,
4326 bgp_node_afi(vty), bgp_node_safi(vty),
4327 PEER_FLAG_SOFT_RECONFIG);
4328 }
4329
4330 ALIAS_HIDDEN(no_neighbor_soft_reconfiguration,
4331 no_neighbor_soft_reconfiguration_hidden_cmd,
4332 "no neighbor <A.B.C.D|X:X::X:X|WORD> soft-reconfiguration inbound",
4333 NO_STR NEIGHBOR_STR NEIGHBOR_ADDR_STR2
4334 "Per neighbor soft reconfiguration\n"
4335 "Allow inbound soft reconfiguration for this neighbor\n")
4336
4337 DEFUN (neighbor_route_reflector_client,
4338 neighbor_route_reflector_client_cmd,
4339 "neighbor <A.B.C.D|X:X::X:X|WORD> route-reflector-client",
4340 NEIGHBOR_STR
4341 NEIGHBOR_ADDR_STR2
4342 "Configure a neighbor as Route Reflector client\n")
4343 {
4344 int idx_peer = 1;
4345 struct peer *peer;
4346
4347
4348 peer = peer_and_group_lookup_vty(vty, argv[idx_peer]->arg);
4349 if (!peer)
4350 return CMD_WARNING_CONFIG_FAILED;
4351
4352 return peer_af_flag_set_vty(vty, argv[idx_peer]->arg, bgp_node_afi(vty),
4353 bgp_node_safi(vty),
4354 PEER_FLAG_REFLECTOR_CLIENT);
4355 }
4356
4357 ALIAS_HIDDEN(neighbor_route_reflector_client,
4358 neighbor_route_reflector_client_hidden_cmd,
4359 "neighbor <A.B.C.D|X:X::X:X|WORD> route-reflector-client",
4360 NEIGHBOR_STR NEIGHBOR_ADDR_STR2
4361 "Configure a neighbor as Route Reflector client\n")
4362
4363 DEFUN (no_neighbor_route_reflector_client,
4364 no_neighbor_route_reflector_client_cmd,
4365 "no neighbor <A.B.C.D|X:X::X:X|WORD> route-reflector-client",
4366 NO_STR
4367 NEIGHBOR_STR
4368 NEIGHBOR_ADDR_STR2
4369 "Configure a neighbor as Route Reflector client\n")
4370 {
4371 int idx_peer = 2;
4372 return peer_af_flag_unset_vty(vty, argv[idx_peer]->arg,
4373 bgp_node_afi(vty), bgp_node_safi(vty),
4374 PEER_FLAG_REFLECTOR_CLIENT);
4375 }
4376
4377 ALIAS_HIDDEN(no_neighbor_route_reflector_client,
4378 no_neighbor_route_reflector_client_hidden_cmd,
4379 "no neighbor <A.B.C.D|X:X::X:X|WORD> route-reflector-client",
4380 NO_STR NEIGHBOR_STR NEIGHBOR_ADDR_STR2
4381 "Configure a neighbor as Route Reflector client\n")
4382
4383 /* neighbor route-server-client. */
4384 DEFUN (neighbor_route_server_client,
4385 neighbor_route_server_client_cmd,
4386 "neighbor <A.B.C.D|X:X::X:X|WORD> route-server-client",
4387 NEIGHBOR_STR
4388 NEIGHBOR_ADDR_STR2
4389 "Configure a neighbor as Route Server client\n")
4390 {
4391 int idx_peer = 1;
4392 struct peer *peer;
4393
4394 peer = peer_and_group_lookup_vty(vty, argv[idx_peer]->arg);
4395 if (!peer)
4396 return CMD_WARNING_CONFIG_FAILED;
4397 return peer_af_flag_set_vty(vty, argv[idx_peer]->arg, bgp_node_afi(vty),
4398 bgp_node_safi(vty),
4399 PEER_FLAG_RSERVER_CLIENT);
4400 }
4401
4402 ALIAS_HIDDEN(neighbor_route_server_client,
4403 neighbor_route_server_client_hidden_cmd,
4404 "neighbor <A.B.C.D|X:X::X:X|WORD> route-server-client",
4405 NEIGHBOR_STR NEIGHBOR_ADDR_STR2
4406 "Configure a neighbor as Route Server client\n")
4407
4408 DEFUN (no_neighbor_route_server_client,
4409 no_neighbor_route_server_client_cmd,
4410 "no neighbor <A.B.C.D|X:X::X:X|WORD> route-server-client",
4411 NO_STR
4412 NEIGHBOR_STR
4413 NEIGHBOR_ADDR_STR2
4414 "Configure a neighbor as Route Server client\n")
4415 {
4416 int idx_peer = 2;
4417 return peer_af_flag_unset_vty(vty, argv[idx_peer]->arg,
4418 bgp_node_afi(vty), bgp_node_safi(vty),
4419 PEER_FLAG_RSERVER_CLIENT);
4420 }
4421
4422 ALIAS_HIDDEN(no_neighbor_route_server_client,
4423 no_neighbor_route_server_client_hidden_cmd,
4424 "no neighbor <A.B.C.D|X:X::X:X|WORD> route-server-client",
4425 NO_STR NEIGHBOR_STR NEIGHBOR_ADDR_STR2
4426 "Configure a neighbor as Route Server client\n")
4427
4428 DEFUN (neighbor_nexthop_local_unchanged,
4429 neighbor_nexthop_local_unchanged_cmd,
4430 "neighbor <A.B.C.D|X:X::X:X|WORD> nexthop-local unchanged",
4431 NEIGHBOR_STR
4432 NEIGHBOR_ADDR_STR2
4433 "Configure treatment of outgoing link-local nexthop attribute\n"
4434 "Leave link-local nexthop unchanged for this peer\n")
4435 {
4436 int idx_peer = 1;
4437 return peer_af_flag_set_vty(vty, argv[idx_peer]->arg, bgp_node_afi(vty),
4438 bgp_node_safi(vty),
4439 PEER_FLAG_NEXTHOP_LOCAL_UNCHANGED);
4440 }
4441
4442 DEFUN (no_neighbor_nexthop_local_unchanged,
4443 no_neighbor_nexthop_local_unchanged_cmd,
4444 "no neighbor <A.B.C.D|X:X::X:X|WORD> nexthop-local unchanged",
4445 NO_STR
4446 NEIGHBOR_STR
4447 NEIGHBOR_ADDR_STR2
4448 "Configure treatment of outgoing link-local-nexthop attribute\n"
4449 "Leave link-local nexthop unchanged for this peer\n")
4450 {
4451 int idx_peer = 2;
4452 return peer_af_flag_unset_vty(vty, argv[idx_peer]->arg,
4453 bgp_node_afi(vty), bgp_node_safi(vty),
4454 PEER_FLAG_NEXTHOP_LOCAL_UNCHANGED);
4455 }
4456
4457 DEFUN (neighbor_attr_unchanged,
4458 neighbor_attr_unchanged_cmd,
4459 "neighbor <A.B.C.D|X:X::X:X|WORD> attribute-unchanged [{as-path|next-hop|med}]",
4460 NEIGHBOR_STR
4461 NEIGHBOR_ADDR_STR2
4462 "BGP attribute is propagated unchanged to this neighbor\n"
4463 "As-path attribute\n"
4464 "Nexthop attribute\n"
4465 "Med attribute\n")
4466 {
4467 int idx = 0;
4468 char *peer_str = argv[1]->arg;
4469 struct peer *peer;
4470 uint16_t flags = 0;
4471 afi_t afi = bgp_node_afi(vty);
4472 safi_t safi = bgp_node_safi(vty);
4473
4474 peer = peer_and_group_lookup_vty(vty, peer_str);
4475 if (!peer)
4476 return CMD_WARNING_CONFIG_FAILED;
4477
4478 if (argv_find(argv, argc, "as-path", &idx))
4479 SET_FLAG(flags, PEER_FLAG_AS_PATH_UNCHANGED);
4480 idx = 0;
4481 if (argv_find(argv, argc, "next-hop", &idx))
4482 SET_FLAG(flags, PEER_FLAG_NEXTHOP_UNCHANGED);
4483 idx = 0;
4484 if (argv_find(argv, argc, "med", &idx))
4485 SET_FLAG(flags, PEER_FLAG_MED_UNCHANGED);
4486
4487 /* no flags means all of them! */
4488 if (!flags) {
4489 SET_FLAG(flags, PEER_FLAG_AS_PATH_UNCHANGED);
4490 SET_FLAG(flags, PEER_FLAG_NEXTHOP_UNCHANGED);
4491 SET_FLAG(flags, PEER_FLAG_MED_UNCHANGED);
4492 } else {
4493 if (!CHECK_FLAG(flags, PEER_FLAG_AS_PATH_UNCHANGED)
4494 && peer_af_flag_check(peer, afi, safi,
4495 PEER_FLAG_AS_PATH_UNCHANGED)) {
4496 peer_af_flag_unset_vty(vty, peer_str, afi, safi,
4497 PEER_FLAG_AS_PATH_UNCHANGED);
4498 }
4499
4500 if (!CHECK_FLAG(flags, PEER_FLAG_NEXTHOP_UNCHANGED)
4501 && peer_af_flag_check(peer, afi, safi,
4502 PEER_FLAG_NEXTHOP_UNCHANGED)) {
4503 peer_af_flag_unset_vty(vty, peer_str, afi, safi,
4504 PEER_FLAG_NEXTHOP_UNCHANGED);
4505 }
4506
4507 if (!CHECK_FLAG(flags, PEER_FLAG_MED_UNCHANGED)
4508 && peer_af_flag_check(peer, afi, safi,
4509 PEER_FLAG_MED_UNCHANGED)) {
4510 peer_af_flag_unset_vty(vty, peer_str, afi, safi,
4511 PEER_FLAG_MED_UNCHANGED);
4512 }
4513 }
4514
4515 return peer_af_flag_set_vty(vty, peer_str, afi, safi, flags);
4516 }
4517
4518 ALIAS_HIDDEN(
4519 neighbor_attr_unchanged, neighbor_attr_unchanged_hidden_cmd,
4520 "neighbor <A.B.C.D|X:X::X:X|WORD> attribute-unchanged [{as-path|next-hop|med}]",
4521 NEIGHBOR_STR NEIGHBOR_ADDR_STR2
4522 "BGP attribute is propagated unchanged to this neighbor\n"
4523 "As-path attribute\n"
4524 "Nexthop attribute\n"
4525 "Med attribute\n")
4526
4527 DEFUN (no_neighbor_attr_unchanged,
4528 no_neighbor_attr_unchanged_cmd,
4529 "no neighbor <A.B.C.D|X:X::X:X|WORD> attribute-unchanged [{as-path|next-hop|med}]",
4530 NO_STR
4531 NEIGHBOR_STR
4532 NEIGHBOR_ADDR_STR2
4533 "BGP attribute is propagated unchanged to this neighbor\n"
4534 "As-path attribute\n"
4535 "Nexthop attribute\n"
4536 "Med attribute\n")
4537 {
4538 int idx = 0;
4539 char *peer = argv[2]->arg;
4540 uint16_t flags = 0;
4541
4542 if (argv_find(argv, argc, "as-path", &idx))
4543 SET_FLAG(flags, PEER_FLAG_AS_PATH_UNCHANGED);
4544 idx = 0;
4545 if (argv_find(argv, argc, "next-hop", &idx))
4546 SET_FLAG(flags, PEER_FLAG_NEXTHOP_UNCHANGED);
4547 idx = 0;
4548 if (argv_find(argv, argc, "med", &idx))
4549 SET_FLAG(flags, PEER_FLAG_MED_UNCHANGED);
4550
4551 if (!flags) // no flags means all of them!
4552 {
4553 SET_FLAG(flags, PEER_FLAG_AS_PATH_UNCHANGED);
4554 SET_FLAG(flags, PEER_FLAG_NEXTHOP_UNCHANGED);
4555 SET_FLAG(flags, PEER_FLAG_MED_UNCHANGED);
4556 }
4557
4558 return peer_af_flag_unset_vty(vty, peer, bgp_node_afi(vty),
4559 bgp_node_safi(vty), flags);
4560 }
4561
4562 ALIAS_HIDDEN(
4563 no_neighbor_attr_unchanged, no_neighbor_attr_unchanged_hidden_cmd,
4564 "no neighbor <A.B.C.D|X:X::X:X|WORD> attribute-unchanged [{as-path|next-hop|med}]",
4565 NO_STR NEIGHBOR_STR NEIGHBOR_ADDR_STR2
4566 "BGP attribute is propagated unchanged to this neighbor\n"
4567 "As-path attribute\n"
4568 "Nexthop attribute\n"
4569 "Med attribute\n")
4570
4571 /* EBGP multihop configuration. */
4572 static int peer_ebgp_multihop_set_vty(struct vty *vty, const char *ip_str,
4573 const char *ttl_str)
4574 {
4575 struct peer *peer;
4576 unsigned int ttl;
4577
4578 peer = peer_and_group_lookup_vty(vty, ip_str);
4579 if (!peer)
4580 return CMD_WARNING_CONFIG_FAILED;
4581
4582 if (peer->conf_if)
4583 return bgp_vty_return(vty, BGP_ERR_INVALID_FOR_DIRECT_PEER);
4584
4585 if (!ttl_str)
4586 ttl = MAXTTL;
4587 else
4588 ttl = strtoul(ttl_str, NULL, 10);
4589
4590 return bgp_vty_return(vty, peer_ebgp_multihop_set(peer, ttl));
4591 }
4592
4593 static int peer_ebgp_multihop_unset_vty(struct vty *vty, const char *ip_str)
4594 {
4595 struct peer *peer;
4596
4597 peer = peer_and_group_lookup_vty(vty, ip_str);
4598 if (!peer)
4599 return CMD_WARNING_CONFIG_FAILED;
4600
4601 return bgp_vty_return(vty, peer_ebgp_multihop_unset(peer));
4602 }
4603
4604 /* neighbor ebgp-multihop. */
4605 DEFUN (neighbor_ebgp_multihop,
4606 neighbor_ebgp_multihop_cmd,
4607 "neighbor <A.B.C.D|X:X::X:X|WORD> ebgp-multihop",
4608 NEIGHBOR_STR
4609 NEIGHBOR_ADDR_STR2
4610 "Allow EBGP neighbors not on directly connected networks\n")
4611 {
4612 int idx_peer = 1;
4613 return peer_ebgp_multihop_set_vty(vty, argv[idx_peer]->arg, NULL);
4614 }
4615
4616 DEFUN (neighbor_ebgp_multihop_ttl,
4617 neighbor_ebgp_multihop_ttl_cmd,
4618 "neighbor <A.B.C.D|X:X::X:X|WORD> ebgp-multihop (1-255)",
4619 NEIGHBOR_STR
4620 NEIGHBOR_ADDR_STR2
4621 "Allow EBGP neighbors not on directly connected networks\n"
4622 "maximum hop count\n")
4623 {
4624 int idx_peer = 1;
4625 int idx_number = 3;
4626 return peer_ebgp_multihop_set_vty(vty, argv[idx_peer]->arg,
4627 argv[idx_number]->arg);
4628 }
4629
4630 DEFUN (no_neighbor_ebgp_multihop,
4631 no_neighbor_ebgp_multihop_cmd,
4632 "no neighbor <A.B.C.D|X:X::X:X|WORD> ebgp-multihop [(1-255)]",
4633 NO_STR
4634 NEIGHBOR_STR
4635 NEIGHBOR_ADDR_STR2
4636 "Allow EBGP neighbors not on directly connected networks\n"
4637 "maximum hop count\n")
4638 {
4639 int idx_peer = 2;
4640 return peer_ebgp_multihop_unset_vty(vty, argv[idx_peer]->arg);
4641 }
4642
4643
4644 /* disable-connected-check */
4645 DEFUN (neighbor_disable_connected_check,
4646 neighbor_disable_connected_check_cmd,
4647 "neighbor <A.B.C.D|X:X::X:X|WORD> <disable-connected-check|enforce-multihop>",
4648 NEIGHBOR_STR
4649 NEIGHBOR_ADDR_STR2
4650 "one-hop away EBGP peer using loopback address\n"
4651 "Enforce EBGP neighbors perform multihop\n")
4652 {
4653 int idx_peer = 1;
4654 return peer_flag_set_vty(vty, argv[idx_peer]->arg,
4655 PEER_FLAG_DISABLE_CONNECTED_CHECK);
4656 }
4657
4658 DEFUN (no_neighbor_disable_connected_check,
4659 no_neighbor_disable_connected_check_cmd,
4660 "no neighbor <A.B.C.D|X:X::X:X|WORD> <disable-connected-check|enforce-multihop>",
4661 NO_STR
4662 NEIGHBOR_STR
4663 NEIGHBOR_ADDR_STR2
4664 "one-hop away EBGP peer using loopback address\n"
4665 "Enforce EBGP neighbors perform multihop\n")
4666 {
4667 int idx_peer = 2;
4668 return peer_flag_unset_vty(vty, argv[idx_peer]->arg,
4669 PEER_FLAG_DISABLE_CONNECTED_CHECK);
4670 }
4671
4672
4673 /* enforce-first-as */
4674 DEFUN (neighbor_enforce_first_as,
4675 neighbor_enforce_first_as_cmd,
4676 "neighbor <A.B.C.D|X:X::X:X|WORD> enforce-first-as",
4677 NEIGHBOR_STR
4678 NEIGHBOR_ADDR_STR2
4679 "Enforce the first AS for EBGP routes\n")
4680 {
4681 int idx_peer = 1;
4682
4683 return peer_flag_set_vty(vty, argv[idx_peer]->arg,
4684 PEER_FLAG_ENFORCE_FIRST_AS);
4685 }
4686
4687 DEFUN (no_neighbor_enforce_first_as,
4688 no_neighbor_enforce_first_as_cmd,
4689 "no neighbor <A.B.C.D|X:X::X:X|WORD> enforce-first-as",
4690 NO_STR
4691 NEIGHBOR_STR
4692 NEIGHBOR_ADDR_STR2
4693 "Enforce the first AS for EBGP routes\n")
4694 {
4695 int idx_peer = 2;
4696
4697 return peer_flag_unset_vty(vty, argv[idx_peer]->arg,
4698 PEER_FLAG_ENFORCE_FIRST_AS);
4699 }
4700
4701
4702 DEFUN (neighbor_description,
4703 neighbor_description_cmd,
4704 "neighbor <A.B.C.D|X:X::X:X|WORD> description LINE...",
4705 NEIGHBOR_STR
4706 NEIGHBOR_ADDR_STR2
4707 "Neighbor specific description\n"
4708 "Up to 80 characters describing this neighbor\n")
4709 {
4710 int idx_peer = 1;
4711 int idx_line = 3;
4712 struct peer *peer;
4713 char *str;
4714
4715 peer = peer_and_group_lookup_vty(vty, argv[idx_peer]->arg);
4716 if (!peer)
4717 return CMD_WARNING_CONFIG_FAILED;
4718
4719 str = argv_concat(argv, argc, idx_line);
4720
4721 peer_description_set(peer, str);
4722
4723 XFREE(MTYPE_TMP, str);
4724
4725 return CMD_SUCCESS;
4726 }
4727
4728 DEFUN (no_neighbor_description,
4729 no_neighbor_description_cmd,
4730 "no neighbor <A.B.C.D|X:X::X:X|WORD> description",
4731 NO_STR
4732 NEIGHBOR_STR
4733 NEIGHBOR_ADDR_STR2
4734 "Neighbor specific description\n")
4735 {
4736 int idx_peer = 2;
4737 struct peer *peer;
4738
4739 peer = peer_and_group_lookup_vty(vty, argv[idx_peer]->arg);
4740 if (!peer)
4741 return CMD_WARNING_CONFIG_FAILED;
4742
4743 peer_description_unset(peer);
4744
4745 return CMD_SUCCESS;
4746 }
4747
4748 ALIAS(no_neighbor_description, no_neighbor_description_comment_cmd,
4749 "no neighbor <A.B.C.D|X:X::X:X|WORD> description LINE...",
4750 NO_STR NEIGHBOR_STR NEIGHBOR_ADDR_STR2
4751 "Neighbor specific description\n"
4752 "Up to 80 characters describing this neighbor\n")
4753
4754 /* Neighbor update-source. */
4755 static int peer_update_source_vty(struct vty *vty, const char *peer_str,
4756 const char *source_str)
4757 {
4758 struct peer *peer;
4759 struct prefix p;
4760 union sockunion su;
4761
4762 peer = peer_and_group_lookup_vty(vty, peer_str);
4763 if (!peer)
4764 return CMD_WARNING_CONFIG_FAILED;
4765
4766 if (peer->conf_if)
4767 return CMD_WARNING;
4768
4769 if (source_str) {
4770 if (str2sockunion(source_str, &su) == 0)
4771 peer_update_source_addr_set(peer, &su);
4772 else {
4773 if (str2prefix(source_str, &p)) {
4774 vty_out(vty,
4775 "%% Invalid update-source, remove prefix length \n");
4776 return CMD_WARNING_CONFIG_FAILED;
4777 } else
4778 peer_update_source_if_set(peer, source_str);
4779 }
4780 } else
4781 peer_update_source_unset(peer);
4782
4783 return CMD_SUCCESS;
4784 }
4785
4786 #define BGP_UPDATE_SOURCE_HELP_STR \
4787 "IPv4 address\n" \
4788 "IPv6 address\n" \
4789 "Interface name (requires zebra to be running)\n"
4790
4791 DEFUN (neighbor_update_source,
4792 neighbor_update_source_cmd,
4793 "neighbor <A.B.C.D|X:X::X:X|WORD> update-source <A.B.C.D|X:X::X:X|WORD>",
4794 NEIGHBOR_STR
4795 NEIGHBOR_ADDR_STR2
4796 "Source of routing updates\n"
4797 BGP_UPDATE_SOURCE_HELP_STR)
4798 {
4799 int idx_peer = 1;
4800 int idx_peer_2 = 3;
4801 return peer_update_source_vty(vty, argv[idx_peer]->arg,
4802 argv[idx_peer_2]->arg);
4803 }
4804
4805 DEFUN (no_neighbor_update_source,
4806 no_neighbor_update_source_cmd,
4807 "no neighbor <A.B.C.D|X:X::X:X|WORD> update-source [<A.B.C.D|X:X::X:X|WORD>]",
4808 NO_STR
4809 NEIGHBOR_STR
4810 NEIGHBOR_ADDR_STR2
4811 "Source of routing updates\n"
4812 BGP_UPDATE_SOURCE_HELP_STR)
4813 {
4814 int idx_peer = 2;
4815 return peer_update_source_vty(vty, argv[idx_peer]->arg, NULL);
4816 }
4817
4818 static int peer_default_originate_set_vty(struct vty *vty, const char *peer_str,
4819 afi_t afi, safi_t safi,
4820 const char *rmap, int set)
4821 {
4822 int ret;
4823 struct peer *peer;
4824 struct route_map *route_map;
4825
4826 peer = peer_and_group_lookup_vty(vty, peer_str);
4827 if (!peer)
4828 return CMD_WARNING_CONFIG_FAILED;
4829
4830 if (set) {
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, "(1-4294967295)", &idx)) {
7285 clr_sort = clear_as;
7286 clr_arg = argv[idx]->arg;
7287 } else if (argv_find(argv, argc, "external", &idx)) {
7288 clr_sort = clear_external;
7289 }
7290
7291 /* [<soft [<in|out>]|in [prefix-filter]|out>] */
7292 if (argv_find(argv, argc, "soft", &idx)) {
7293 if (argv_find(argv, argc, "in", &idx)
7294 || argv_find(argv, argc, "out", &idx))
7295 clr_type = strmatch(argv[idx]->text, "in")
7296 ? BGP_CLEAR_SOFT_IN
7297 : BGP_CLEAR_SOFT_OUT;
7298 else
7299 clr_type = BGP_CLEAR_SOFT_BOTH;
7300 } else if (argv_find(argv, argc, "in", &idx)) {
7301 clr_type = argv_find(argv, argc, "prefix-filter", &idx)
7302 ? BGP_CLEAR_SOFT_IN_ORF_PREFIX
7303 : BGP_CLEAR_SOFT_IN;
7304 } else if (argv_find(argv, argc, "out", &idx)) {
7305 clr_type = BGP_CLEAR_SOFT_OUT;
7306 } else
7307 clr_type = BGP_CLEAR_SOFT_NONE;
7308
7309 return bgp_clear_vty(vty, vrf, afi, safi, clr_sort, clr_type, clr_arg);
7310 }
7311
7312 DEFUN (clear_ip_bgp_prefix,
7313 clear_ip_bgp_prefix_cmd,
7314 "clear [ip] bgp [<view|vrf> VIEWVRFNAME] prefix A.B.C.D/M",
7315 CLEAR_STR
7316 IP_STR
7317 BGP_STR
7318 BGP_INSTANCE_HELP_STR
7319 "Clear bestpath and re-advertise\n"
7320 "IPv4 prefix\n")
7321 {
7322 char *vrf = NULL;
7323 char *prefix = NULL;
7324
7325 int idx = 0;
7326
7327 /* [<view|vrf> VIEWVRFNAME] */
7328 if (argv_find(argv, argc, "vrf", &idx)) {
7329 vrf = argv[idx + 1]->arg;
7330 idx += 2;
7331 if (vrf && strmatch(vrf, VRF_DEFAULT_NAME))
7332 vrf = NULL;
7333 } else if (argv_find(argv, argc, "view", &idx)) {
7334 /* [<view> VIEWVRFNAME] */
7335 vrf = argv[idx + 1]->arg;
7336 idx += 2;
7337 }
7338
7339 prefix = argv[argc - 1]->arg;
7340
7341 return bgp_clear_prefix(vty, vrf, prefix, AFI_IP, SAFI_UNICAST, NULL);
7342 }
7343
7344 DEFUN (clear_bgp_ipv6_safi_prefix,
7345 clear_bgp_ipv6_safi_prefix_cmd,
7346 "clear [ip] bgp ipv6 "BGP_SAFI_CMD_STR" prefix X:X::X:X/M",
7347 CLEAR_STR
7348 IP_STR
7349 BGP_STR
7350 "Address Family\n"
7351 BGP_SAFI_HELP_STR
7352 "Clear bestpath and re-advertise\n"
7353 "IPv6 prefix\n")
7354 {
7355 int idx_safi = 0;
7356 int idx_ipv6_prefix = 0;
7357 safi_t safi = SAFI_UNICAST;
7358 char *prefix = argv_find(argv, argc, "X:X::X:X/M", &idx_ipv6_prefix) ?
7359 argv[idx_ipv6_prefix]->arg : NULL;
7360
7361 argv_find_and_parse_safi(argv, argc, &idx_safi, &safi);
7362 return bgp_clear_prefix(
7363 vty, NULL, prefix, AFI_IP6,
7364 safi, NULL);
7365 }
7366
7367 DEFUN (clear_bgp_instance_ipv6_safi_prefix,
7368 clear_bgp_instance_ipv6_safi_prefix_cmd,
7369 "clear [ip] bgp <view|vrf> VIEWVRFNAME ipv6 "BGP_SAFI_CMD_STR" prefix X:X::X:X/M",
7370 CLEAR_STR
7371 IP_STR
7372 BGP_STR
7373 BGP_INSTANCE_HELP_STR
7374 "Address Family\n"
7375 BGP_SAFI_HELP_STR
7376 "Clear bestpath and re-advertise\n"
7377 "IPv6 prefix\n")
7378 {
7379 int idx_safi = 0;
7380 int idx_vrfview = 0;
7381 int idx_ipv6_prefix = 0;
7382 safi_t safi = SAFI_UNICAST;
7383 char *prefix = argv_find(argv, argc, "X:X::X:X/M", &idx_ipv6_prefix) ?
7384 argv[idx_ipv6_prefix]->arg : NULL;
7385 char *vrfview = NULL;
7386
7387 /* [<view|vrf> VIEWVRFNAME] */
7388 if (argv_find(argv, argc, "vrf", &idx_vrfview)) {
7389 vrfview = argv[idx_vrfview + 1]->arg;
7390 if (vrfview && strmatch(vrfview, VRF_DEFAULT_NAME))
7391 vrfview = NULL;
7392 } else if (argv_find(argv, argc, "view", &idx_vrfview)) {
7393 /* [<view> VIEWVRFNAME] */
7394 vrfview = argv[idx_vrfview + 1]->arg;
7395 }
7396 argv_find_and_parse_safi(argv, argc, &idx_safi, &safi);
7397
7398 return bgp_clear_prefix(
7399 vty, vrfview, prefix,
7400 AFI_IP6, safi, NULL);
7401 }
7402
7403 DEFUN (show_bgp_views,
7404 show_bgp_views_cmd,
7405 "show [ip] bgp views",
7406 SHOW_STR
7407 IP_STR
7408 BGP_STR
7409 "Show the defined BGP views\n")
7410 {
7411 struct list *inst = bm->bgp;
7412 struct listnode *node;
7413 struct bgp *bgp;
7414
7415 vty_out(vty, "Defined BGP views:\n");
7416 for (ALL_LIST_ELEMENTS_RO(inst, node, bgp)) {
7417 /* Skip VRFs. */
7418 if (bgp->inst_type == BGP_INSTANCE_TYPE_VRF)
7419 continue;
7420 vty_out(vty, "\t%s (AS%u)\n", bgp->name ? bgp->name : "(null)",
7421 bgp->as);
7422 }
7423
7424 return CMD_SUCCESS;
7425 }
7426
7427 DEFUN (show_bgp_vrfs,
7428 show_bgp_vrfs_cmd,
7429 "show [ip] bgp vrfs [json]",
7430 SHOW_STR
7431 IP_STR
7432 BGP_STR
7433 "Show BGP VRFs\n"
7434 JSON_STR)
7435 {
7436 char buf[ETHER_ADDR_STRLEN];
7437 struct list *inst = bm->bgp;
7438 struct listnode *node;
7439 struct bgp *bgp;
7440 bool uj = use_json(argc, argv);
7441 json_object *json = NULL;
7442 json_object *json_vrfs = NULL;
7443 int count = 0;
7444
7445 if (uj) {
7446 json = json_object_new_object();
7447 json_vrfs = json_object_new_object();
7448 }
7449
7450 for (ALL_LIST_ELEMENTS_RO(inst, node, bgp)) {
7451 const char *name, *type;
7452 struct peer *peer;
7453 struct listnode *node2, *nnode2;
7454 int peers_cfg, peers_estb;
7455 json_object *json_vrf = NULL;
7456
7457 /* Skip Views. */
7458 if (bgp->inst_type == BGP_INSTANCE_TYPE_VIEW)
7459 continue;
7460
7461 count++;
7462 if (!uj && count == 1) {
7463 vty_out(vty,
7464 "%4s %-5s %-16s %9s %10s %-37s\n",
7465 "Type", "Id", "routerId", "#PeersVfg",
7466 "#PeersEstb", "Name");
7467 vty_out(vty, "%11s %-16s %-21s %-6s\n", " ",
7468 "L3-VNI", "RouterMAC", "Interface");
7469 }
7470
7471 peers_cfg = peers_estb = 0;
7472 if (uj)
7473 json_vrf = json_object_new_object();
7474
7475
7476 for (ALL_LIST_ELEMENTS(bgp->peer, node2, nnode2, peer)) {
7477 if (!CHECK_FLAG(peer->flags, PEER_FLAG_CONFIG_NODE))
7478 continue;
7479 peers_cfg++;
7480 if (peer->status == Established)
7481 peers_estb++;
7482 }
7483
7484 if (bgp->inst_type == BGP_INSTANCE_TYPE_DEFAULT) {
7485 name = VRF_DEFAULT_NAME;
7486 type = "DFLT";
7487 } else {
7488 name = bgp->name;
7489 type = "VRF";
7490 }
7491
7492
7493 if (uj) {
7494 int64_t vrf_id_ui = (bgp->vrf_id == VRF_UNKNOWN)
7495 ? -1
7496 : (int64_t)bgp->vrf_id;
7497 json_object_string_add(json_vrf, "type", type);
7498 json_object_int_add(json_vrf, "vrfId", vrf_id_ui);
7499 json_object_string_add(json_vrf, "routerId",
7500 inet_ntoa(bgp->router_id));
7501 json_object_int_add(json_vrf, "numConfiguredPeers",
7502 peers_cfg);
7503 json_object_int_add(json_vrf, "numEstablishedPeers",
7504 peers_estb);
7505
7506 json_object_int_add(json_vrf, "l3vni", bgp->l3vni);
7507 json_object_string_add(
7508 json_vrf, "rmac",
7509 prefix_mac2str(&bgp->rmac, buf, sizeof(buf)));
7510 json_object_string_add(json_vrf, "interface",
7511 ifindex2ifname(bgp->l3vni_svi_ifindex,
7512 bgp->vrf_id));
7513 json_object_object_add(json_vrfs, name, json_vrf);
7514 } else {
7515 vty_out(vty,
7516 "%4s %-5d %-16s %-9u %-10u %-37s\n",
7517 type,
7518 bgp->vrf_id == VRF_UNKNOWN ? -1
7519 : (int)bgp->vrf_id,
7520 inet_ntoa(bgp->router_id), peers_cfg,
7521 peers_estb, name);
7522 vty_out(vty,"%11s %-16u %-21s %-20s\n", " ",
7523 bgp->l3vni,
7524 prefix_mac2str(&bgp->rmac, buf, sizeof(buf)),
7525 ifindex2ifname(bgp->l3vni_svi_ifindex,
7526 bgp->vrf_id));
7527 }
7528 }
7529
7530 if (uj) {
7531 json_object_object_add(json, "vrfs", json_vrfs);
7532
7533 json_object_int_add(json, "totalVrfs", count);
7534
7535 vty_out(vty, "%s\n", json_object_to_json_string_ext(
7536 json, JSON_C_TO_STRING_PRETTY));
7537 json_object_free(json);
7538 } else {
7539 if (count)
7540 vty_out(vty,
7541 "\nTotal number of VRFs (including default): %d\n",
7542 count);
7543 }
7544
7545 return CMD_SUCCESS;
7546 }
7547
7548 DEFUN (show_bgp_mac_hash,
7549 show_bgp_mac_hash_cmd,
7550 "show bgp mac hash",
7551 SHOW_STR
7552 BGP_STR
7553 "Mac Address\n"
7554 "Mac Address database\n")
7555 {
7556 bgp_mac_dump_table(vty);
7557
7558 return CMD_SUCCESS;
7559 }
7560
7561 static void show_tip_entry(struct hash_bucket *bucket, void *args)
7562 {
7563 struct vty *vty = (struct vty *)args;
7564 struct tip_addr *tip = (struct tip_addr *)bucket->data;
7565
7566 vty_out(vty, "addr: %s, count: %d\n", inet_ntoa(tip->addr),
7567 tip->refcnt);
7568 }
7569
7570 static void bgp_show_martian_nexthops(struct vty *vty, struct bgp *bgp)
7571 {
7572 vty_out(vty, "self nexthop database:\n");
7573 bgp_nexthop_show_address_hash(vty, bgp);
7574
7575 vty_out(vty, "Tunnel-ip database:\n");
7576 hash_iterate(bgp->tip_hash,
7577 (void (*)(struct hash_bucket *, void *))show_tip_entry,
7578 vty);
7579 }
7580
7581 DEFUN(show_bgp_martian_nexthop_db, show_bgp_martian_nexthop_db_cmd,
7582 "show bgp [<view|vrf> VIEWVRFNAME] martian next-hop",
7583 SHOW_STR BGP_STR BGP_INSTANCE_HELP_STR
7584 "martian next-hops\n"
7585 "martian next-hop database\n")
7586 {
7587 struct bgp *bgp = NULL;
7588 int idx = 0;
7589 char *name = NULL;
7590
7591 /* [<vrf> VIEWVRFNAME] */
7592 if (argv_find(argv, argc, "vrf", &idx)) {
7593 name = argv[idx + 1]->arg;
7594 if (name && strmatch(name, VRF_DEFAULT_NAME))
7595 name = NULL;
7596 } else if (argv_find(argv, argc, "view", &idx))
7597 /* [<view> VIEWVRFNAME] */
7598 name = argv[idx + 1]->arg;
7599 if (name)
7600 bgp = bgp_lookup_by_name(name);
7601 else
7602 bgp = bgp_get_default();
7603
7604 if (!bgp) {
7605 vty_out(vty, "%% No BGP process is configured\n");
7606 return CMD_WARNING;
7607 }
7608 bgp_show_martian_nexthops(vty, bgp);
7609
7610 return CMD_SUCCESS;
7611 }
7612
7613 DEFUN (show_bgp_memory,
7614 show_bgp_memory_cmd,
7615 "show [ip] bgp memory",
7616 SHOW_STR
7617 IP_STR
7618 BGP_STR
7619 "Global BGP memory statistics\n")
7620 {
7621 char memstrbuf[MTYPE_MEMSTR_LEN];
7622 unsigned long count;
7623
7624 /* RIB related usage stats */
7625 count = mtype_stats_alloc(MTYPE_BGP_NODE);
7626 vty_out(vty, "%ld RIB nodes, using %s of memory\n", count,
7627 mtype_memstr(memstrbuf, sizeof(memstrbuf),
7628 count * sizeof(struct bgp_node)));
7629
7630 count = mtype_stats_alloc(MTYPE_BGP_ROUTE);
7631 vty_out(vty, "%ld BGP routes, using %s of memory\n", count,
7632 mtype_memstr(memstrbuf, sizeof(memstrbuf),
7633 count * sizeof(struct bgp_path_info)));
7634 if ((count = mtype_stats_alloc(MTYPE_BGP_ROUTE_EXTRA)))
7635 vty_out(vty, "%ld BGP route ancillaries, using %s of memory\n",
7636 count,
7637 mtype_memstr(
7638 memstrbuf, sizeof(memstrbuf),
7639 count * sizeof(struct bgp_path_info_extra)));
7640
7641 if ((count = mtype_stats_alloc(MTYPE_BGP_STATIC)))
7642 vty_out(vty, "%ld Static routes, using %s of memory\n", count,
7643 mtype_memstr(memstrbuf, sizeof(memstrbuf),
7644 count * sizeof(struct bgp_static)));
7645
7646 if ((count = mtype_stats_alloc(MTYPE_BGP_PACKET)))
7647 vty_out(vty, "%ld Packets, using %s of memory\n", count,
7648 mtype_memstr(memstrbuf, sizeof(memstrbuf),
7649 count * sizeof(struct bpacket)));
7650
7651 /* Adj-In/Out */
7652 if ((count = mtype_stats_alloc(MTYPE_BGP_ADJ_IN)))
7653 vty_out(vty, "%ld Adj-In entries, using %s of memory\n", count,
7654 mtype_memstr(memstrbuf, sizeof(memstrbuf),
7655 count * sizeof(struct bgp_adj_in)));
7656 if ((count = mtype_stats_alloc(MTYPE_BGP_ADJ_OUT)))
7657 vty_out(vty, "%ld Adj-Out entries, using %s of memory\n", count,
7658 mtype_memstr(memstrbuf, sizeof(memstrbuf),
7659 count * sizeof(struct bgp_adj_out)));
7660
7661 if ((count = mtype_stats_alloc(MTYPE_BGP_NEXTHOP_CACHE)))
7662 vty_out(vty, "%ld Nexthop cache entries, using %s of memory\n",
7663 count,
7664 mtype_memstr(memstrbuf, sizeof(memstrbuf),
7665 count * sizeof(struct bgp_nexthop_cache)));
7666
7667 if ((count = mtype_stats_alloc(MTYPE_BGP_DAMP_INFO)))
7668 vty_out(vty, "%ld Dampening entries, using %s of memory\n",
7669 count,
7670 mtype_memstr(memstrbuf, sizeof(memstrbuf),
7671 count * sizeof(struct bgp_damp_info)));
7672
7673 /* Attributes */
7674 count = attr_count();
7675 vty_out(vty, "%ld BGP attributes, using %s of memory\n", count,
7676 mtype_memstr(memstrbuf, sizeof(memstrbuf),
7677 count * sizeof(struct attr)));
7678
7679 if ((count = attr_unknown_count()))
7680 vty_out(vty, "%ld unknown attributes\n", count);
7681
7682 /* AS_PATH attributes */
7683 count = aspath_count();
7684 vty_out(vty, "%ld BGP AS-PATH entries, using %s of memory\n", count,
7685 mtype_memstr(memstrbuf, sizeof(memstrbuf),
7686 count * sizeof(struct aspath)));
7687
7688 count = mtype_stats_alloc(MTYPE_AS_SEG);
7689 vty_out(vty, "%ld BGP AS-PATH segments, using %s of memory\n", count,
7690 mtype_memstr(memstrbuf, sizeof(memstrbuf),
7691 count * sizeof(struct assegment)));
7692
7693 /* Other attributes */
7694 if ((count = community_count()))
7695 vty_out(vty, "%ld BGP community entries, using %s of memory\n",
7696 count, mtype_memstr(memstrbuf, sizeof(memstrbuf),
7697 count * sizeof(struct community)));
7698 if ((count = mtype_stats_alloc(MTYPE_ECOMMUNITY)))
7699 vty_out(vty, "%ld BGP community entries, using %s of memory\n",
7700 count, mtype_memstr(memstrbuf, sizeof(memstrbuf),
7701 count * sizeof(struct ecommunity)));
7702 if ((count = mtype_stats_alloc(MTYPE_LCOMMUNITY)))
7703 vty_out(vty,
7704 "%ld BGP large-community entries, using %s of memory\n",
7705 count, mtype_memstr(memstrbuf, sizeof(memstrbuf),
7706 count * sizeof(struct lcommunity)));
7707
7708 if ((count = mtype_stats_alloc(MTYPE_CLUSTER)))
7709 vty_out(vty, "%ld Cluster lists, using %s of memory\n", count,
7710 mtype_memstr(memstrbuf, sizeof(memstrbuf),
7711 count * sizeof(struct cluster_list)));
7712
7713 /* Peer related usage */
7714 count = mtype_stats_alloc(MTYPE_BGP_PEER);
7715 vty_out(vty, "%ld peers, using %s of memory\n", count,
7716 mtype_memstr(memstrbuf, sizeof(memstrbuf),
7717 count * sizeof(struct peer)));
7718
7719 if ((count = mtype_stats_alloc(MTYPE_PEER_GROUP)))
7720 vty_out(vty, "%ld peer groups, using %s of memory\n", count,
7721 mtype_memstr(memstrbuf, sizeof(memstrbuf),
7722 count * sizeof(struct peer_group)));
7723
7724 /* Other */
7725 if ((count = mtype_stats_alloc(MTYPE_HASH)))
7726 vty_out(vty, "%ld hash tables, using %s of memory\n", count,
7727 mtype_memstr(memstrbuf, sizeof(memstrbuf),
7728 count * sizeof(struct hash)));
7729 if ((count = mtype_stats_alloc(MTYPE_HASH_BACKET)))
7730 vty_out(vty, "%ld hash buckets, using %s of memory\n", count,
7731 mtype_memstr(memstrbuf, sizeof(memstrbuf),
7732 count * sizeof(struct hash_bucket)));
7733 if ((count = mtype_stats_alloc(MTYPE_BGP_REGEXP)))
7734 vty_out(vty, "%ld compiled regexes, using %s of memory\n",
7735 count, mtype_memstr(memstrbuf, sizeof(memstrbuf),
7736 count * sizeof(regex_t)));
7737 return CMD_SUCCESS;
7738 }
7739
7740 static void bgp_show_bestpath_json(struct bgp *bgp, json_object *json)
7741 {
7742 json_object *bestpath = json_object_new_object();
7743
7744 if (bgp_flag_check(bgp, BGP_FLAG_ASPATH_IGNORE))
7745 json_object_string_add(bestpath, "asPath", "ignore");
7746
7747 if (bgp_flag_check(bgp, BGP_FLAG_ASPATH_CONFED))
7748 json_object_string_add(bestpath, "asPath", "confed");
7749
7750 if (bgp_flag_check(bgp, BGP_FLAG_ASPATH_MULTIPATH_RELAX)) {
7751 if (bgp_flag_check(bgp, BGP_FLAG_MULTIPATH_RELAX_AS_SET))
7752 json_object_string_add(bestpath, "multiPathRelax",
7753 "as-set");
7754 else
7755 json_object_string_add(bestpath, "multiPathRelax",
7756 "true");
7757 } else
7758 json_object_string_add(bestpath, "multiPathRelax", "false");
7759
7760 if (bgp_flag_check(bgp, BGP_FLAG_COMPARE_ROUTER_ID))
7761 json_object_string_add(bestpath, "compareRouterId", "true");
7762 if (bgp_flag_check(bgp, BGP_FLAG_MED_CONFED)
7763 || bgp_flag_check(bgp, BGP_FLAG_MED_MISSING_AS_WORST)) {
7764 if (bgp_flag_check(bgp, BGP_FLAG_MED_CONFED))
7765 json_object_string_add(bestpath, "med", "confed");
7766 if (bgp_flag_check(bgp, BGP_FLAG_MED_MISSING_AS_WORST))
7767 json_object_string_add(bestpath, "med",
7768 "missing-as-worst");
7769 else
7770 json_object_string_add(bestpath, "med", "true");
7771 }
7772
7773 json_object_object_add(json, "bestPath", bestpath);
7774 }
7775
7776 /* Show BGP peer's summary information. */
7777 static int bgp_show_summary(struct vty *vty, struct bgp *bgp, int afi, int safi,
7778 bool use_json, json_object *json)
7779 {
7780 struct peer *peer;
7781 struct listnode *node, *nnode;
7782 unsigned int count = 0, dn_count = 0;
7783 char timebuf[BGP_UPTIME_LEN], dn_flag[2];
7784 char neighbor_buf[VTY_BUFSIZ];
7785 int neighbor_col_default_width = 16;
7786 int len;
7787 int max_neighbor_width = 0;
7788 int pfx_rcd_safi;
7789 json_object *json_peer = NULL;
7790 json_object *json_peers = NULL;
7791 struct peer_af *paf;
7792
7793 /* labeled-unicast routes are installed in the unicast table so in order
7794 * to
7795 * display the correct PfxRcd value we must look at SAFI_UNICAST
7796 */
7797 if (safi == SAFI_LABELED_UNICAST)
7798 pfx_rcd_safi = SAFI_UNICAST;
7799 else
7800 pfx_rcd_safi = safi;
7801
7802 if (use_json) {
7803 if (json == NULL)
7804 json = json_object_new_object();
7805
7806 json_peers = json_object_new_object();
7807 } else {
7808 /* Loop over all neighbors that will be displayed to determine
7809 * how many
7810 * characters are needed for the Neighbor column
7811 */
7812 for (ALL_LIST_ELEMENTS(bgp->peer, node, nnode, peer)) {
7813 if (!CHECK_FLAG(peer->flags, PEER_FLAG_CONFIG_NODE))
7814 continue;
7815
7816 if (peer->afc[afi][safi]) {
7817 memset(dn_flag, '\0', sizeof(dn_flag));
7818 if (peer_dynamic_neighbor(peer))
7819 dn_flag[0] = '*';
7820
7821 if (peer->hostname
7822 && bgp_flag_check(bgp,
7823 BGP_FLAG_SHOW_HOSTNAME))
7824 sprintf(neighbor_buf, "%s%s(%s) ",
7825 dn_flag, peer->hostname,
7826 peer->host);
7827 else
7828 sprintf(neighbor_buf, "%s%s ", dn_flag,
7829 peer->host);
7830
7831 len = strlen(neighbor_buf);
7832
7833 if (len > max_neighbor_width)
7834 max_neighbor_width = len;
7835 }
7836 }
7837
7838 /* Originally we displayed the Neighbor column as 16
7839 * characters wide so make that the default
7840 */
7841 if (max_neighbor_width < neighbor_col_default_width)
7842 max_neighbor_width = neighbor_col_default_width;
7843 }
7844
7845 for (ALL_LIST_ELEMENTS(bgp->peer, node, nnode, peer)) {
7846 if (!CHECK_FLAG(peer->flags, PEER_FLAG_CONFIG_NODE))
7847 continue;
7848
7849 if (!peer->afc[afi][safi])
7850 continue;
7851
7852 if (!count) {
7853 unsigned long ents;
7854 char memstrbuf[MTYPE_MEMSTR_LEN];
7855 int64_t vrf_id_ui;
7856
7857 vrf_id_ui = (bgp->vrf_id == VRF_UNKNOWN)
7858 ? -1
7859 : (int64_t)bgp->vrf_id;
7860
7861 /* Usage summary and header */
7862 if (use_json) {
7863 json_object_string_add(
7864 json, "routerId",
7865 inet_ntoa(bgp->router_id));
7866 json_object_int_add(json, "as", bgp->as);
7867 json_object_int_add(json, "vrfId", vrf_id_ui);
7868 json_object_string_add(
7869 json, "vrfName",
7870 (bgp->inst_type
7871 == BGP_INSTANCE_TYPE_DEFAULT)
7872 ? VRF_DEFAULT_NAME
7873 : bgp->name);
7874 } else {
7875 vty_out(vty,
7876 "BGP router identifier %s, local AS number %u vrf-id %d",
7877 inet_ntoa(bgp->router_id), bgp->as,
7878 bgp->vrf_id == VRF_UNKNOWN
7879 ? -1
7880 : (int)bgp->vrf_id);
7881 vty_out(vty, "\n");
7882 }
7883
7884 if (bgp_update_delay_configured(bgp)) {
7885 if (use_json) {
7886 json_object_int_add(
7887 json, "updateDelayLimit",
7888 bgp->v_update_delay);
7889
7890 if (bgp->v_update_delay
7891 != bgp->v_establish_wait)
7892 json_object_int_add(
7893 json,
7894 "updateDelayEstablishWait",
7895 bgp->v_establish_wait);
7896
7897 if (bgp_update_delay_active(bgp)) {
7898 json_object_string_add(
7899 json,
7900 "updateDelayFirstNeighbor",
7901 bgp->update_delay_begin_time);
7902 json_object_boolean_true_add(
7903 json,
7904 "updateDelayInProgress");
7905 } else {
7906 if (bgp->update_delay_over) {
7907 json_object_string_add(
7908 json,
7909 "updateDelayFirstNeighbor",
7910 bgp->update_delay_begin_time);
7911 json_object_string_add(
7912 json,
7913 "updateDelayBestpathResumed",
7914 bgp->update_delay_end_time);
7915 json_object_string_add(
7916 json,
7917 "updateDelayZebraUpdateResume",
7918 bgp->update_delay_zebra_resume_time);
7919 json_object_string_add(
7920 json,
7921 "updateDelayPeerUpdateResume",
7922 bgp->update_delay_peers_resume_time);
7923 }
7924 }
7925 } else {
7926 vty_out(vty,
7927 "Read-only mode update-delay limit: %d seconds\n",
7928 bgp->v_update_delay);
7929 if (bgp->v_update_delay
7930 != bgp->v_establish_wait)
7931 vty_out(vty,
7932 " Establish wait: %d seconds\n",
7933 bgp->v_establish_wait);
7934
7935 if (bgp_update_delay_active(bgp)) {
7936 vty_out(vty,
7937 " First neighbor established: %s\n",
7938 bgp->update_delay_begin_time);
7939 vty_out(vty,
7940 " Delay in progress\n");
7941 } else {
7942 if (bgp->update_delay_over) {
7943 vty_out(vty,
7944 " First neighbor established: %s\n",
7945 bgp->update_delay_begin_time);
7946 vty_out(vty,
7947 " Best-paths resumed: %s\n",
7948 bgp->update_delay_end_time);
7949 vty_out(vty,
7950 " zebra update resumed: %s\n",
7951 bgp->update_delay_zebra_resume_time);
7952 vty_out(vty,
7953 " peers update resumed: %s\n",
7954 bgp->update_delay_peers_resume_time);
7955 }
7956 }
7957 }
7958 }
7959
7960 if (use_json) {
7961 if (bgp_maxmed_onstartup_configured(bgp)
7962 && bgp->maxmed_active)
7963 json_object_boolean_true_add(
7964 json, "maxMedOnStartup");
7965 if (bgp->v_maxmed_admin)
7966 json_object_boolean_true_add(
7967 json, "maxMedAdministrative");
7968
7969 json_object_int_add(
7970 json, "tableVersion",
7971 bgp_table_version(bgp->rib[afi][safi]));
7972
7973 ents = bgp_table_count(bgp->rib[afi][safi]);
7974 json_object_int_add(json, "ribCount", ents);
7975 json_object_int_add(
7976 json, "ribMemory",
7977 ents * sizeof(struct bgp_node));
7978
7979 ents = bgp->af_peer_count[afi][safi];
7980 json_object_int_add(json, "peerCount", ents);
7981 json_object_int_add(json, "peerMemory",
7982 ents * sizeof(struct peer));
7983
7984 if ((ents = listcount(bgp->group))) {
7985 json_object_int_add(
7986 json, "peerGroupCount", ents);
7987 json_object_int_add(
7988 json, "peerGroupMemory",
7989 ents * sizeof(struct
7990 peer_group));
7991 }
7992
7993 if (CHECK_FLAG(bgp->af_flags[afi][safi],
7994 BGP_CONFIG_DAMPENING))
7995 json_object_boolean_true_add(
7996 json, "dampeningEnabled");
7997 } else {
7998 if (bgp_maxmed_onstartup_configured(bgp)
7999 && bgp->maxmed_active)
8000 vty_out(vty,
8001 "Max-med on-startup active\n");
8002 if (bgp->v_maxmed_admin)
8003 vty_out(vty,
8004 "Max-med administrative active\n");
8005
8006 vty_out(vty, "BGP table version %" PRIu64 "\n",
8007 bgp_table_version(bgp->rib[afi][safi]));
8008
8009 ents = bgp_table_count(bgp->rib[afi][safi]);
8010 vty_out(vty,
8011 "RIB entries %ld, using %s of memory\n",
8012 ents,
8013 mtype_memstr(memstrbuf,
8014 sizeof(memstrbuf),
8015 ents * sizeof(struct
8016 bgp_node)));
8017
8018 /* Peer related usage */
8019 ents = bgp->af_peer_count[afi][safi];
8020 vty_out(vty, "Peers %ld, using %s of memory\n",
8021 ents,
8022 mtype_memstr(
8023 memstrbuf, sizeof(memstrbuf),
8024 ents * sizeof(struct peer)));
8025
8026 if ((ents = listcount(bgp->group)))
8027 vty_out(vty,
8028 "Peer groups %ld, using %s of memory\n",
8029 ents,
8030 mtype_memstr(
8031 memstrbuf,
8032 sizeof(memstrbuf),
8033 ents * sizeof(struct
8034 peer_group)));
8035
8036 if (CHECK_FLAG(bgp->af_flags[afi][safi],
8037 BGP_CONFIG_DAMPENING))
8038 vty_out(vty, "Dampening enabled.\n");
8039 vty_out(vty, "\n");
8040
8041 /* Subtract 8 here because 'Neighbor' is
8042 * 8 characters */
8043 vty_out(vty, "Neighbor");
8044 vty_out(vty, "%*s", max_neighbor_width - 8,
8045 " ");
8046 vty_out(vty,
8047 "V AS MsgRcvd MsgSent TblVer InQ OutQ Up/Down State/PfxRcd\n");
8048 }
8049 }
8050
8051 count++;
8052
8053 if (use_json) {
8054 json_peer = json_object_new_object();
8055
8056 if (peer_dynamic_neighbor(peer)) {
8057 dn_count++;
8058 json_object_boolean_true_add(json_peer,
8059 "dynamicPeer");
8060 }
8061
8062 if (peer->hostname)
8063 json_object_string_add(json_peer, "hostname",
8064 peer->hostname);
8065
8066 if (peer->domainname)
8067 json_object_string_add(json_peer, "domainname",
8068 peer->domainname);
8069
8070 json_object_int_add(json_peer, "remoteAs", peer->as);
8071 json_object_int_add(json_peer, "version", 4);
8072 json_object_int_add(json_peer, "msgRcvd",
8073 PEER_TOTAL_RX(peer));
8074 json_object_int_add(json_peer, "msgSent",
8075 PEER_TOTAL_TX(peer));
8076
8077 json_object_int_add(json_peer, "tableVersion",
8078 peer->version[afi][safi]);
8079 json_object_int_add(json_peer, "outq",
8080 peer->obuf->count);
8081 json_object_int_add(json_peer, "inq", 0);
8082 peer_uptime(peer->uptime, timebuf, BGP_UPTIME_LEN,
8083 use_json, json_peer);
8084
8085 /*
8086 * Adding "pfxRcd" field to match with the corresponding
8087 * CLI. "prefixReceivedCount" will be deprecated in
8088 * future.
8089 */
8090 json_object_int_add(json_peer, "prefixReceivedCount",
8091 peer->pcount[afi][pfx_rcd_safi]);
8092 json_object_int_add(json_peer, "pfxRcd",
8093 peer->pcount[afi][pfx_rcd_safi]);
8094
8095 paf = peer_af_find(peer, afi, pfx_rcd_safi);
8096 if (paf && PAF_SUBGRP(paf))
8097 json_object_int_add(json_peer,
8098 "pfxSnt",
8099 (PAF_SUBGRP(paf))->scount);
8100
8101 if (CHECK_FLAG(peer->flags, PEER_FLAG_SHUTDOWN))
8102 json_object_string_add(json_peer, "state",
8103 "Idle (Admin)");
8104 else if (peer->afc_recv[afi][safi])
8105 json_object_string_add(
8106 json_peer, "state",
8107 lookup_msg(bgp_status_msg, peer->status,
8108 NULL));
8109 else if (CHECK_FLAG(peer->sflags,
8110 PEER_STATUS_PREFIX_OVERFLOW))
8111 json_object_string_add(json_peer, "state",
8112 "Idle (PfxCt)");
8113 else
8114 json_object_string_add(
8115 json_peer, "state",
8116 lookup_msg(bgp_status_msg, peer->status,
8117 NULL));
8118
8119 if (peer->conf_if)
8120 json_object_string_add(json_peer, "idType",
8121 "interface");
8122 else if (peer->su.sa.sa_family == AF_INET)
8123 json_object_string_add(json_peer, "idType",
8124 "ipv4");
8125 else if (peer->su.sa.sa_family == AF_INET6)
8126 json_object_string_add(json_peer, "idType",
8127 "ipv6");
8128
8129 json_object_object_add(json_peers, peer->host,
8130 json_peer);
8131 } else {
8132 memset(dn_flag, '\0', sizeof(dn_flag));
8133 if (peer_dynamic_neighbor(peer)) {
8134 dn_count++;
8135 dn_flag[0] = '*';
8136 }
8137
8138 if (peer->hostname
8139 && bgp_flag_check(bgp, BGP_FLAG_SHOW_HOSTNAME))
8140 len = vty_out(vty, "%s%s(%s)", dn_flag,
8141 peer->hostname, peer->host);
8142 else
8143 len = vty_out(vty, "%s%s", dn_flag, peer->host);
8144
8145 /* pad the neighbor column with spaces */
8146 if (len < max_neighbor_width)
8147 vty_out(vty, "%*s", max_neighbor_width - len,
8148 " ");
8149
8150 vty_out(vty, "4 %10u %7u %7u %8" PRIu64 " %4d %4zd %8s",
8151 peer->as, PEER_TOTAL_RX(peer),
8152 PEER_TOTAL_TX(peer), peer->version[afi][safi],
8153 0, peer->obuf->count,
8154 peer_uptime(peer->uptime, timebuf,
8155 BGP_UPTIME_LEN, 0, NULL));
8156
8157 if (peer->status == Established)
8158 if (peer->afc_recv[afi][safi])
8159 vty_out(vty, " %12ld",
8160 peer->pcount[afi]
8161 [pfx_rcd_safi]);
8162 else
8163 vty_out(vty, " NoNeg");
8164 else {
8165 if (CHECK_FLAG(peer->flags, PEER_FLAG_SHUTDOWN))
8166 vty_out(vty, " Idle (Admin)");
8167 else if (CHECK_FLAG(
8168 peer->sflags,
8169 PEER_STATUS_PREFIX_OVERFLOW))
8170 vty_out(vty, " Idle (PfxCt)");
8171 else
8172 vty_out(vty, " %12s",
8173 lookup_msg(bgp_status_msg,
8174 peer->status, NULL));
8175 }
8176 vty_out(vty, "\n");
8177 }
8178 }
8179
8180 if (use_json) {
8181 json_object_object_add(json, "peers", json_peers);
8182
8183 json_object_int_add(json, "totalPeers", count);
8184 json_object_int_add(json, "dynamicPeers", dn_count);
8185
8186 bgp_show_bestpath_json(bgp, json);
8187
8188 vty_out(vty, "%s\n", json_object_to_json_string_ext(
8189 json, JSON_C_TO_STRING_PRETTY));
8190 json_object_free(json);
8191 } else {
8192 if (count)
8193 vty_out(vty, "\nTotal number of neighbors %d\n", count);
8194 else {
8195 vty_out(vty, "No %s neighbor is configured\n",
8196 afi_safi_print(afi, safi));
8197 }
8198
8199 if (dn_count) {
8200 vty_out(vty, "* - dynamic neighbor\n");
8201 vty_out(vty, "%d dynamic neighbor(s), limit %d\n",
8202 dn_count, bgp->dynamic_neighbors_limit);
8203 }
8204 }
8205
8206 return CMD_SUCCESS;
8207 }
8208
8209 static void bgp_show_summary_afi_safi(struct vty *vty, struct bgp *bgp, int afi,
8210 int safi, bool use_json,
8211 json_object *json)
8212 {
8213 int is_first = 1;
8214 int afi_wildcard = (afi == AFI_MAX);
8215 int safi_wildcard = (safi == SAFI_MAX);
8216 int is_wildcard = (afi_wildcard || safi_wildcard);
8217 bool nbr_output = false;
8218
8219 if (use_json && is_wildcard)
8220 vty_out(vty, "{\n");
8221 if (afi_wildcard)
8222 afi = 1; /* AFI_IP */
8223 while (afi < AFI_MAX) {
8224 if (safi_wildcard)
8225 safi = 1; /* SAFI_UNICAST */
8226 while (safi < SAFI_MAX) {
8227 if (bgp_afi_safi_peer_exists(bgp, afi, safi)) {
8228 nbr_output = true;
8229 if (is_wildcard) {
8230 /*
8231 * So limit output to those afi/safi
8232 * pairs that
8233 * actualy have something interesting in
8234 * them
8235 */
8236 if (use_json) {
8237 json = json_object_new_object();
8238
8239 if (!is_first)
8240 vty_out(vty, ",\n");
8241 else
8242 is_first = 0;
8243
8244 vty_out(vty, "\"%s\":",
8245 afi_safi_json(afi,
8246 safi));
8247 } else {
8248 vty_out(vty, "\n%s Summary:\n",
8249 afi_safi_print(afi,
8250 safi));
8251 }
8252 }
8253 bgp_show_summary(vty, bgp, afi, safi, use_json,
8254 json);
8255 }
8256 safi++;
8257 if (!safi_wildcard)
8258 safi = SAFI_MAX;
8259 }
8260 afi++;
8261 if (!afi_wildcard)
8262 afi = AFI_MAX;
8263 }
8264
8265 if (use_json && is_wildcard)
8266 vty_out(vty, "}\n");
8267 else if (!nbr_output) {
8268 if (use_json)
8269 vty_out(vty, "{}\n");
8270 else
8271 vty_out(vty, "%% No BGP neighbors found\n");
8272 }
8273 }
8274
8275 static void bgp_show_all_instances_summary_vty(struct vty *vty, afi_t afi,
8276 safi_t safi, bool use_json)
8277 {
8278 struct listnode *node, *nnode;
8279 struct bgp *bgp;
8280 json_object *json = NULL;
8281 int is_first = 1;
8282 bool nbr_output = false;
8283
8284 if (use_json)
8285 vty_out(vty, "{\n");
8286
8287 for (ALL_LIST_ELEMENTS(bm->bgp, node, nnode, bgp)) {
8288 nbr_output = true;
8289 if (use_json) {
8290 json = json_object_new_object();
8291
8292 if (!is_first)
8293 vty_out(vty, ",\n");
8294 else
8295 is_first = 0;
8296
8297 vty_out(vty, "\"%s\":",
8298 (bgp->inst_type == BGP_INSTANCE_TYPE_DEFAULT)
8299 ? VRF_DEFAULT_NAME
8300 : bgp->name);
8301 } else {
8302 vty_out(vty, "\nInstance %s:\n",
8303 (bgp->inst_type == BGP_INSTANCE_TYPE_DEFAULT)
8304 ? VRF_DEFAULT_NAME
8305 : bgp->name);
8306 }
8307 bgp_show_summary_afi_safi(vty, bgp, afi, safi, use_json, json);
8308 }
8309
8310 if (use_json)
8311 vty_out(vty, "}\n");
8312 else if (!nbr_output)
8313 vty_out(vty, "%% BGP instance not found\n");
8314 }
8315
8316 int bgp_show_summary_vty(struct vty *vty, const char *name, afi_t afi,
8317 safi_t safi, bool use_json)
8318 {
8319 struct bgp *bgp;
8320
8321 if (name) {
8322 if (strmatch(name, "all")) {
8323 bgp_show_all_instances_summary_vty(vty, afi, safi,
8324 use_json);
8325 return CMD_SUCCESS;
8326 } else {
8327 bgp = bgp_lookup_by_name(name);
8328
8329 if (!bgp) {
8330 if (use_json)
8331 vty_out(vty, "{}\n");
8332 else
8333 vty_out(vty,
8334 "%% BGP instance not found\n");
8335 return CMD_WARNING;
8336 }
8337
8338 bgp_show_summary_afi_safi(vty, bgp, afi, safi, use_json,
8339 NULL);
8340 return CMD_SUCCESS;
8341 }
8342 }
8343
8344 bgp = bgp_get_default();
8345
8346 if (bgp)
8347 bgp_show_summary_afi_safi(vty, bgp, afi, safi, use_json, NULL);
8348 else {
8349 if (use_json)
8350 vty_out(vty, "{}\n");
8351 else
8352 vty_out(vty, "%% BGP instance not found\n");
8353 return CMD_WARNING;
8354 }
8355
8356 return CMD_SUCCESS;
8357 }
8358
8359 /* `show [ip] bgp summary' commands. */
8360 DEFUN (show_ip_bgp_summary,
8361 show_ip_bgp_summary_cmd,
8362 "show [ip] bgp [<view|vrf> VIEWVRFNAME] ["BGP_AFI_CMD_STR" ["BGP_SAFI_WITH_LABEL_CMD_STR"]] summary [json]",
8363 SHOW_STR
8364 IP_STR
8365 BGP_STR
8366 BGP_INSTANCE_HELP_STR
8367 BGP_AFI_HELP_STR
8368 BGP_SAFI_WITH_LABEL_HELP_STR
8369 "Summary of BGP neighbor status\n"
8370 JSON_STR)
8371 {
8372 char *vrf = NULL;
8373 afi_t afi = AFI_MAX;
8374 safi_t safi = SAFI_MAX;
8375
8376 int idx = 0;
8377
8378 /* show [ip] bgp */
8379 if (argv_find(argv, argc, "ip", &idx))
8380 afi = AFI_IP;
8381 /* [<vrf> VIEWVRFNAME] */
8382 if (argv_find(argv, argc, "vrf", &idx)) {
8383 vrf = argv[idx + 1]->arg;
8384 if (vrf && strmatch(vrf, VRF_DEFAULT_NAME))
8385 vrf = NULL;
8386 } else if (argv_find(argv, argc, "view", &idx))
8387 /* [<view> VIEWVRFNAME] */
8388 vrf = argv[idx + 1]->arg;
8389 /* ["BGP_AFI_CMD_STR" ["BGP_SAFI_CMD_STR"]] */
8390 if (argv_find_and_parse_afi(argv, argc, &idx, &afi)) {
8391 argv_find_and_parse_safi(argv, argc, &idx, &safi);
8392 }
8393
8394 bool uj = use_json(argc, argv);
8395
8396 return bgp_show_summary_vty(vty, vrf, afi, safi, uj);
8397 }
8398
8399 const char *afi_safi_print(afi_t afi, safi_t safi)
8400 {
8401 if (afi == AFI_IP && safi == SAFI_UNICAST)
8402 return "IPv4 Unicast";
8403 else if (afi == AFI_IP && safi == SAFI_MULTICAST)
8404 return "IPv4 Multicast";
8405 else if (afi == AFI_IP && safi == SAFI_LABELED_UNICAST)
8406 return "IPv4 Labeled Unicast";
8407 else if (afi == AFI_IP && safi == SAFI_MPLS_VPN)
8408 return "IPv4 VPN";
8409 else if (afi == AFI_IP && safi == SAFI_ENCAP)
8410 return "IPv4 Encap";
8411 else if (afi == AFI_IP && safi == SAFI_FLOWSPEC)
8412 return "IPv4 Flowspec";
8413 else if (afi == AFI_IP6 && safi == SAFI_UNICAST)
8414 return "IPv6 Unicast";
8415 else if (afi == AFI_IP6 && safi == SAFI_MULTICAST)
8416 return "IPv6 Multicast";
8417 else if (afi == AFI_IP6 && safi == SAFI_LABELED_UNICAST)
8418 return "IPv6 Labeled Unicast";
8419 else if (afi == AFI_IP6 && safi == SAFI_MPLS_VPN)
8420 return "IPv6 VPN";
8421 else if (afi == AFI_IP6 && safi == SAFI_ENCAP)
8422 return "IPv6 Encap";
8423 else if (afi == AFI_IP6 && safi == SAFI_FLOWSPEC)
8424 return "IPv6 Flowspec";
8425 else if (afi == AFI_L2VPN && safi == SAFI_EVPN)
8426 return "L2VPN EVPN";
8427 else
8428 return "Unknown";
8429 }
8430
8431 /*
8432 * Please note that we have intentionally camelCased
8433 * the return strings here. So if you want
8434 * to use this function, please ensure you
8435 * are doing this within json output
8436 */
8437 const char *afi_safi_json(afi_t afi, safi_t safi)
8438 {
8439 if (afi == AFI_IP && safi == SAFI_UNICAST)
8440 return "ipv4Unicast";
8441 else if (afi == AFI_IP && safi == SAFI_MULTICAST)
8442 return "ipv4Multicast";
8443 else if (afi == AFI_IP && safi == SAFI_LABELED_UNICAST)
8444 return "ipv4LabeledUnicast";
8445 else if (afi == AFI_IP && safi == SAFI_MPLS_VPN)
8446 return "ipv4Vpn";
8447 else if (afi == AFI_IP && safi == SAFI_ENCAP)
8448 return "ipv4Encap";
8449 else if (afi == AFI_IP && safi == SAFI_FLOWSPEC)
8450 return "ipv4Flowspec";
8451 else if (afi == AFI_IP6 && safi == SAFI_UNICAST)
8452 return "ipv6Unicast";
8453 else if (afi == AFI_IP6 && safi == SAFI_MULTICAST)
8454 return "ipv6Multicast";
8455 else if (afi == AFI_IP6 && safi == SAFI_LABELED_UNICAST)
8456 return "ipv6LabeledUnicast";
8457 else if (afi == AFI_IP6 && safi == SAFI_MPLS_VPN)
8458 return "ipv6Vpn";
8459 else if (afi == AFI_IP6 && safi == SAFI_ENCAP)
8460 return "ipv6Encap";
8461 else if (afi == AFI_IP6 && safi == SAFI_FLOWSPEC)
8462 return "ipv6Flowspec";
8463 else if (afi == AFI_L2VPN && safi == SAFI_EVPN)
8464 return "l2VpnEvpn";
8465 else
8466 return "Unknown";
8467 }
8468
8469 /* Show BGP peer's information. */
8470 enum show_type { show_all, show_peer, show_ipv4_all, show_ipv6_all, show_ipv4_peer, show_ipv6_peer };
8471
8472 static void bgp_show_peer_afi_orf_cap(struct vty *vty, struct peer *p,
8473 afi_t afi, safi_t safi,
8474 uint16_t adv_smcap, uint16_t adv_rmcap,
8475 uint16_t rcv_smcap, uint16_t rcv_rmcap,
8476 bool use_json, json_object *json_pref)
8477 {
8478 /* Send-Mode */
8479 if (CHECK_FLAG(p->af_cap[afi][safi], adv_smcap)
8480 || CHECK_FLAG(p->af_cap[afi][safi], rcv_smcap)) {
8481 if (use_json) {
8482 if (CHECK_FLAG(p->af_cap[afi][safi], adv_smcap)
8483 && CHECK_FLAG(p->af_cap[afi][safi], rcv_smcap))
8484 json_object_string_add(json_pref, "sendMode",
8485 "advertisedAndReceived");
8486 else if (CHECK_FLAG(p->af_cap[afi][safi], adv_smcap))
8487 json_object_string_add(json_pref, "sendMode",
8488 "advertised");
8489 else if (CHECK_FLAG(p->af_cap[afi][safi], rcv_smcap))
8490 json_object_string_add(json_pref, "sendMode",
8491 "received");
8492 } else {
8493 vty_out(vty, " Send-mode: ");
8494 if (CHECK_FLAG(p->af_cap[afi][safi], adv_smcap))
8495 vty_out(vty, "advertised");
8496 if (CHECK_FLAG(p->af_cap[afi][safi], rcv_smcap))
8497 vty_out(vty, "%sreceived",
8498 CHECK_FLAG(p->af_cap[afi][safi],
8499 adv_smcap)
8500 ? ", "
8501 : "");
8502 vty_out(vty, "\n");
8503 }
8504 }
8505
8506 /* Receive-Mode */
8507 if (CHECK_FLAG(p->af_cap[afi][safi], adv_rmcap)
8508 || CHECK_FLAG(p->af_cap[afi][safi], rcv_rmcap)) {
8509 if (use_json) {
8510 if (CHECK_FLAG(p->af_cap[afi][safi], adv_rmcap)
8511 && CHECK_FLAG(p->af_cap[afi][safi], rcv_rmcap))
8512 json_object_string_add(json_pref, "recvMode",
8513 "advertisedAndReceived");
8514 else if (CHECK_FLAG(p->af_cap[afi][safi], adv_rmcap))
8515 json_object_string_add(json_pref, "recvMode",
8516 "advertised");
8517 else if (CHECK_FLAG(p->af_cap[afi][safi], rcv_rmcap))
8518 json_object_string_add(json_pref, "recvMode",
8519 "received");
8520 } else {
8521 vty_out(vty, " Receive-mode: ");
8522 if (CHECK_FLAG(p->af_cap[afi][safi], adv_rmcap))
8523 vty_out(vty, "advertised");
8524 if (CHECK_FLAG(p->af_cap[afi][safi], rcv_rmcap))
8525 vty_out(vty, "%sreceived",
8526 CHECK_FLAG(p->af_cap[afi][safi],
8527 adv_rmcap)
8528 ? ", "
8529 : "");
8530 vty_out(vty, "\n");
8531 }
8532 }
8533 }
8534
8535 static void bgp_show_peer_afi(struct vty *vty, struct peer *p, afi_t afi,
8536 safi_t safi, bool use_json,
8537 json_object *json_neigh)
8538 {
8539 struct bgp_filter *filter;
8540 struct peer_af *paf;
8541 char orf_pfx_name[BUFSIZ];
8542 int orf_pfx_count;
8543 json_object *json_af = NULL;
8544 json_object *json_prefA = NULL;
8545 json_object *json_prefB = NULL;
8546 json_object *json_addr = NULL;
8547
8548 if (use_json) {
8549 json_addr = json_object_new_object();
8550 json_af = json_object_new_object();
8551 filter = &p->filter[afi][safi];
8552
8553 if (peer_group_active(p))
8554 json_object_string_add(json_addr, "peerGroupMember",
8555 p->group->name);
8556
8557 paf = peer_af_find(p, afi, safi);
8558 if (paf && PAF_SUBGRP(paf)) {
8559 json_object_int_add(json_addr, "updateGroupId",
8560 PAF_UPDGRP(paf)->id);
8561 json_object_int_add(json_addr, "subGroupId",
8562 PAF_SUBGRP(paf)->id);
8563 json_object_int_add(json_addr, "packetQueueLength",
8564 bpacket_queue_virtual_length(paf));
8565 }
8566
8567 if (CHECK_FLAG(p->af_cap[afi][safi], PEER_CAP_ORF_PREFIX_SM_ADV)
8568 || CHECK_FLAG(p->af_cap[afi][safi],
8569 PEER_CAP_ORF_PREFIX_SM_RCV)
8570 || CHECK_FLAG(p->af_cap[afi][safi],
8571 PEER_CAP_ORF_PREFIX_RM_ADV)
8572 || CHECK_FLAG(p->af_cap[afi][safi],
8573 PEER_CAP_ORF_PREFIX_RM_RCV)) {
8574 json_object_int_add(json_af, "orfType",
8575 ORF_TYPE_PREFIX);
8576 json_prefA = json_object_new_object();
8577 bgp_show_peer_afi_orf_cap(vty, p, afi, safi,
8578 PEER_CAP_ORF_PREFIX_SM_ADV,
8579 PEER_CAP_ORF_PREFIX_RM_ADV,
8580 PEER_CAP_ORF_PREFIX_SM_RCV,
8581 PEER_CAP_ORF_PREFIX_RM_RCV,
8582 use_json, json_prefA);
8583 json_object_object_add(json_af, "orfPrefixList",
8584 json_prefA);
8585 }
8586
8587 if (CHECK_FLAG(p->af_cap[afi][safi], PEER_CAP_ORF_PREFIX_SM_ADV)
8588 || CHECK_FLAG(p->af_cap[afi][safi],
8589 PEER_CAP_ORF_PREFIX_SM_OLD_RCV)
8590 || CHECK_FLAG(p->af_cap[afi][safi],
8591 PEER_CAP_ORF_PREFIX_RM_ADV)
8592 || CHECK_FLAG(p->af_cap[afi][safi],
8593 PEER_CAP_ORF_PREFIX_RM_OLD_RCV)) {
8594 json_object_int_add(json_af, "orfOldType",
8595 ORF_TYPE_PREFIX_OLD);
8596 json_prefB = json_object_new_object();
8597 bgp_show_peer_afi_orf_cap(
8598 vty, p, afi, safi, PEER_CAP_ORF_PREFIX_SM_ADV,
8599 PEER_CAP_ORF_PREFIX_RM_ADV,
8600 PEER_CAP_ORF_PREFIX_SM_OLD_RCV,
8601 PEER_CAP_ORF_PREFIX_RM_OLD_RCV, use_json,
8602 json_prefB);
8603 json_object_object_add(json_af, "orfOldPrefixList",
8604 json_prefB);
8605 }
8606
8607 if (CHECK_FLAG(p->af_cap[afi][safi], PEER_CAP_ORF_PREFIX_SM_ADV)
8608 || CHECK_FLAG(p->af_cap[afi][safi],
8609 PEER_CAP_ORF_PREFIX_SM_RCV)
8610 || CHECK_FLAG(p->af_cap[afi][safi],
8611 PEER_CAP_ORF_PREFIX_SM_OLD_RCV)
8612 || CHECK_FLAG(p->af_cap[afi][safi],
8613 PEER_CAP_ORF_PREFIX_RM_ADV)
8614 || CHECK_FLAG(p->af_cap[afi][safi],
8615 PEER_CAP_ORF_PREFIX_RM_RCV)
8616 || CHECK_FLAG(p->af_cap[afi][safi],
8617 PEER_CAP_ORF_PREFIX_RM_OLD_RCV))
8618 json_object_object_add(json_addr, "afDependentCap",
8619 json_af);
8620 else
8621 json_object_free(json_af);
8622
8623 sprintf(orf_pfx_name, "%s.%d.%d", p->host, afi, safi);
8624 orf_pfx_count = prefix_bgp_show_prefix_list(
8625 NULL, afi, orf_pfx_name, use_json);
8626
8627 if (CHECK_FLAG(p->af_sflags[afi][safi],
8628 PEER_STATUS_ORF_PREFIX_SEND)
8629 || orf_pfx_count) {
8630 if (CHECK_FLAG(p->af_sflags[afi][safi],
8631 PEER_STATUS_ORF_PREFIX_SEND))
8632 json_object_boolean_true_add(json_neigh,
8633 "orfSent");
8634 if (orf_pfx_count)
8635 json_object_int_add(json_addr, "orfRecvCounter",
8636 orf_pfx_count);
8637 }
8638 if (CHECK_FLAG(p->af_sflags[afi][safi],
8639 PEER_STATUS_ORF_WAIT_REFRESH))
8640 json_object_string_add(
8641 json_addr, "orfFirstUpdate",
8642 "deferredUntilORFOrRouteRefreshRecvd");
8643
8644 if (CHECK_FLAG(p->af_flags[afi][safi],
8645 PEER_FLAG_REFLECTOR_CLIENT))
8646 json_object_boolean_true_add(json_addr,
8647 "routeReflectorClient");
8648 if (CHECK_FLAG(p->af_flags[afi][safi],
8649 PEER_FLAG_RSERVER_CLIENT))
8650 json_object_boolean_true_add(json_addr,
8651 "routeServerClient");
8652 if (CHECK_FLAG(p->af_flags[afi][safi], PEER_FLAG_SOFT_RECONFIG))
8653 json_object_boolean_true_add(json_addr,
8654 "inboundSoftConfigPermit");
8655
8656 if (CHECK_FLAG(p->af_flags[afi][safi],
8657 PEER_FLAG_REMOVE_PRIVATE_AS_ALL_REPLACE))
8658 json_object_boolean_true_add(
8659 json_addr,
8660 "privateAsNumsAllReplacedInUpdatesToNbr");
8661 else if (CHECK_FLAG(p->af_flags[afi][safi],
8662 PEER_FLAG_REMOVE_PRIVATE_AS_REPLACE))
8663 json_object_boolean_true_add(
8664 json_addr,
8665 "privateAsNumsReplacedInUpdatesToNbr");
8666 else if (CHECK_FLAG(p->af_flags[afi][safi],
8667 PEER_FLAG_REMOVE_PRIVATE_AS_ALL))
8668 json_object_boolean_true_add(
8669 json_addr,
8670 "privateAsNumsAllRemovedInUpdatesToNbr");
8671 else if (CHECK_FLAG(p->af_flags[afi][safi],
8672 PEER_FLAG_REMOVE_PRIVATE_AS))
8673 json_object_boolean_true_add(
8674 json_addr,
8675 "privateAsNumsRemovedInUpdatesToNbr");
8676
8677 if (p->addpath_type[afi][safi] != BGP_ADDPATH_NONE)
8678 json_object_boolean_true_add(
8679 json_addr,
8680 bgp_addpath_names(p->addpath_type[afi][safi])
8681 ->type_json_name);
8682
8683 if (CHECK_FLAG(p->af_flags[afi][safi], PEER_FLAG_AS_OVERRIDE))
8684 json_object_string_add(json_addr,
8685 "overrideASNsInOutboundUpdates",
8686 "ifAspathEqualRemoteAs");
8687
8688 if (CHECK_FLAG(p->af_flags[afi][safi], PEER_FLAG_NEXTHOP_SELF)
8689 || CHECK_FLAG(p->af_flags[afi][safi],
8690 PEER_FLAG_FORCE_NEXTHOP_SELF))
8691 json_object_boolean_true_add(json_addr,
8692 "routerAlwaysNextHop");
8693 if (CHECK_FLAG(p->af_flags[afi][safi],
8694 PEER_FLAG_AS_PATH_UNCHANGED))
8695 json_object_boolean_true_add(
8696 json_addr, "unchangedAsPathPropogatedToNbr");
8697 if (CHECK_FLAG(p->af_flags[afi][safi],
8698 PEER_FLAG_NEXTHOP_UNCHANGED))
8699 json_object_boolean_true_add(
8700 json_addr, "unchangedNextHopPropogatedToNbr");
8701 if (CHECK_FLAG(p->af_flags[afi][safi], PEER_FLAG_MED_UNCHANGED))
8702 json_object_boolean_true_add(
8703 json_addr, "unchangedMedPropogatedToNbr");
8704 if (CHECK_FLAG(p->af_flags[afi][safi], PEER_FLAG_SEND_COMMUNITY)
8705 || CHECK_FLAG(p->af_flags[afi][safi],
8706 PEER_FLAG_SEND_EXT_COMMUNITY)) {
8707 if (CHECK_FLAG(p->af_flags[afi][safi],
8708 PEER_FLAG_SEND_COMMUNITY)
8709 && CHECK_FLAG(p->af_flags[afi][safi],
8710 PEER_FLAG_SEND_EXT_COMMUNITY))
8711 json_object_string_add(json_addr,
8712 "commAttriSentToNbr",
8713 "extendedAndStandard");
8714 else if (CHECK_FLAG(p->af_flags[afi][safi],
8715 PEER_FLAG_SEND_EXT_COMMUNITY))
8716 json_object_string_add(json_addr,
8717 "commAttriSentToNbr",
8718 "extended");
8719 else
8720 json_object_string_add(json_addr,
8721 "commAttriSentToNbr",
8722 "standard");
8723 }
8724 if (CHECK_FLAG(p->af_flags[afi][safi],
8725 PEER_FLAG_DEFAULT_ORIGINATE)) {
8726 if (p->default_rmap[afi][safi].name)
8727 json_object_string_add(
8728 json_addr, "defaultRouteMap",
8729 p->default_rmap[afi][safi].name);
8730
8731 if (paf && PAF_SUBGRP(paf)
8732 && CHECK_FLAG(PAF_SUBGRP(paf)->sflags,
8733 SUBGRP_STATUS_DEFAULT_ORIGINATE))
8734 json_object_boolean_true_add(json_addr,
8735 "defaultSent");
8736 else
8737 json_object_boolean_true_add(json_addr,
8738 "defaultNotSent");
8739 }
8740
8741 if (afi == AFI_L2VPN && safi == SAFI_EVPN) {
8742 if (is_evpn_enabled())
8743 json_object_boolean_true_add(
8744 json_addr, "advertiseAllVnis");
8745 }
8746
8747 if (filter->plist[FILTER_IN].name
8748 || filter->dlist[FILTER_IN].name
8749 || filter->aslist[FILTER_IN].name
8750 || filter->map[RMAP_IN].name)
8751 json_object_boolean_true_add(json_addr,
8752 "inboundPathPolicyConfig");
8753 if (filter->plist[FILTER_OUT].name
8754 || filter->dlist[FILTER_OUT].name
8755 || filter->aslist[FILTER_OUT].name
8756 || filter->map[RMAP_OUT].name || filter->usmap.name)
8757 json_object_boolean_true_add(
8758 json_addr, "outboundPathPolicyConfig");
8759
8760 /* prefix-list */
8761 if (filter->plist[FILTER_IN].name)
8762 json_object_string_add(json_addr,
8763 "incomingUpdatePrefixFilterList",
8764 filter->plist[FILTER_IN].name);
8765 if (filter->plist[FILTER_OUT].name)
8766 json_object_string_add(json_addr,
8767 "outgoingUpdatePrefixFilterList",
8768 filter->plist[FILTER_OUT].name);
8769
8770 /* distribute-list */
8771 if (filter->dlist[FILTER_IN].name)
8772 json_object_string_add(
8773 json_addr, "incomingUpdateNetworkFilterList",
8774 filter->dlist[FILTER_IN].name);
8775 if (filter->dlist[FILTER_OUT].name)
8776 json_object_string_add(
8777 json_addr, "outgoingUpdateNetworkFilterList",
8778 filter->dlist[FILTER_OUT].name);
8779
8780 /* filter-list. */
8781 if (filter->aslist[FILTER_IN].name)
8782 json_object_string_add(json_addr,
8783 "incomingUpdateAsPathFilterList",
8784 filter->aslist[FILTER_IN].name);
8785 if (filter->aslist[FILTER_OUT].name)
8786 json_object_string_add(json_addr,
8787 "outgoingUpdateAsPathFilterList",
8788 filter->aslist[FILTER_OUT].name);
8789
8790 /* route-map. */
8791 if (filter->map[RMAP_IN].name)
8792 json_object_string_add(
8793 json_addr, "routeMapForIncomingAdvertisements",
8794 filter->map[RMAP_IN].name);
8795 if (filter->map[RMAP_OUT].name)
8796 json_object_string_add(
8797 json_addr, "routeMapForOutgoingAdvertisements",
8798 filter->map[RMAP_OUT].name);
8799
8800 /* ebgp-requires-policy (inbound) */
8801 if (p->bgp->ebgp_requires_policy == DEFAULT_EBGP_POLICY_ENABLED
8802 && !bgp_inbound_policy_exists(p, filter))
8803 json_object_string_add(
8804 json_addr, "inboundEbgpRequiresPolicy",
8805 "Inbound updates discarded due to missing policy");
8806
8807 /* ebgp-requires-policy (outbound) */
8808 if (p->bgp->ebgp_requires_policy == DEFAULT_EBGP_POLICY_ENABLED
8809 && (!bgp_outbound_policy_exists(p, filter)))
8810 json_object_string_add(
8811 json_addr, "outboundEbgpRequiresPolicy",
8812 "Outbound updates discarded due to missing policy");
8813
8814 /* unsuppress-map */
8815 if (filter->usmap.name)
8816 json_object_string_add(json_addr,
8817 "selectiveUnsuppressRouteMap",
8818 filter->usmap.name);
8819
8820 /* Receive prefix count */
8821 json_object_int_add(json_addr, "acceptedPrefixCounter",
8822 p->pcount[afi][safi]);
8823 if (paf && PAF_SUBGRP(paf))
8824 json_object_int_add(json_addr, "sentPrefixCounter",
8825 (PAF_SUBGRP(paf))->scount);
8826
8827 /* Maximum prefix */
8828 if (CHECK_FLAG(p->af_flags[afi][safi], PEER_FLAG_MAX_PREFIX)) {
8829 json_object_int_add(json_addr, "prefixAllowedMax",
8830 p->pmax[afi][safi]);
8831 if (CHECK_FLAG(p->af_flags[afi][safi],
8832 PEER_FLAG_MAX_PREFIX_WARNING))
8833 json_object_boolean_true_add(
8834 json_addr, "prefixAllowedMaxWarning");
8835 json_object_int_add(json_addr,
8836 "prefixAllowedWarningThresh",
8837 p->pmax_threshold[afi][safi]);
8838 if (p->pmax_restart[afi][safi])
8839 json_object_int_add(
8840 json_addr,
8841 "prefixAllowedRestartIntervalMsecs",
8842 p->pmax_restart[afi][safi] * 60000);
8843 }
8844 json_object_object_add(json_neigh, afi_safi_print(afi, safi),
8845 json_addr);
8846
8847 } else {
8848 filter = &p->filter[afi][safi];
8849
8850 vty_out(vty, " For address family: %s\n",
8851 afi_safi_print(afi, safi));
8852
8853 if (peer_group_active(p))
8854 vty_out(vty, " %s peer-group member\n",
8855 p->group->name);
8856
8857 paf = peer_af_find(p, afi, safi);
8858 if (paf && PAF_SUBGRP(paf)) {
8859 vty_out(vty, " Update group %" PRIu64
8860 ", subgroup %" PRIu64 "\n",
8861 PAF_UPDGRP(paf)->id, PAF_SUBGRP(paf)->id);
8862 vty_out(vty, " Packet Queue length %d\n",
8863 bpacket_queue_virtual_length(paf));
8864 } else {
8865 vty_out(vty, " Not part of any update group\n");
8866 }
8867 if (CHECK_FLAG(p->af_cap[afi][safi], PEER_CAP_ORF_PREFIX_SM_ADV)
8868 || CHECK_FLAG(p->af_cap[afi][safi],
8869 PEER_CAP_ORF_PREFIX_SM_RCV)
8870 || CHECK_FLAG(p->af_cap[afi][safi],
8871 PEER_CAP_ORF_PREFIX_SM_OLD_RCV)
8872 || CHECK_FLAG(p->af_cap[afi][safi],
8873 PEER_CAP_ORF_PREFIX_RM_ADV)
8874 || CHECK_FLAG(p->af_cap[afi][safi],
8875 PEER_CAP_ORF_PREFIX_RM_RCV)
8876 || CHECK_FLAG(p->af_cap[afi][safi],
8877 PEER_CAP_ORF_PREFIX_RM_OLD_RCV))
8878 vty_out(vty, " AF-dependant capabilities:\n");
8879
8880 if (CHECK_FLAG(p->af_cap[afi][safi], PEER_CAP_ORF_PREFIX_SM_ADV)
8881 || CHECK_FLAG(p->af_cap[afi][safi],
8882 PEER_CAP_ORF_PREFIX_SM_RCV)
8883 || CHECK_FLAG(p->af_cap[afi][safi],
8884 PEER_CAP_ORF_PREFIX_RM_ADV)
8885 || CHECK_FLAG(p->af_cap[afi][safi],
8886 PEER_CAP_ORF_PREFIX_RM_RCV)) {
8887 vty_out(vty,
8888 " Outbound Route Filter (ORF) type (%d) Prefix-list:\n",
8889 ORF_TYPE_PREFIX);
8890 bgp_show_peer_afi_orf_cap(
8891 vty, p, afi, safi, PEER_CAP_ORF_PREFIX_SM_ADV,
8892 PEER_CAP_ORF_PREFIX_RM_ADV,
8893 PEER_CAP_ORF_PREFIX_SM_RCV,
8894 PEER_CAP_ORF_PREFIX_RM_RCV, use_json, NULL);
8895 }
8896 if (CHECK_FLAG(p->af_cap[afi][safi], PEER_CAP_ORF_PREFIX_SM_ADV)
8897 || CHECK_FLAG(p->af_cap[afi][safi],
8898 PEER_CAP_ORF_PREFIX_SM_OLD_RCV)
8899 || CHECK_FLAG(p->af_cap[afi][safi],
8900 PEER_CAP_ORF_PREFIX_RM_ADV)
8901 || CHECK_FLAG(p->af_cap[afi][safi],
8902 PEER_CAP_ORF_PREFIX_RM_OLD_RCV)) {
8903 vty_out(vty,
8904 " Outbound Route Filter (ORF) type (%d) Prefix-list:\n",
8905 ORF_TYPE_PREFIX_OLD);
8906 bgp_show_peer_afi_orf_cap(
8907 vty, p, afi, safi, PEER_CAP_ORF_PREFIX_SM_ADV,
8908 PEER_CAP_ORF_PREFIX_RM_ADV,
8909 PEER_CAP_ORF_PREFIX_SM_OLD_RCV,
8910 PEER_CAP_ORF_PREFIX_RM_OLD_RCV, use_json, NULL);
8911 }
8912
8913 sprintf(orf_pfx_name, "%s.%d.%d", p->host, afi, safi);
8914 orf_pfx_count = prefix_bgp_show_prefix_list(
8915 NULL, afi, orf_pfx_name, use_json);
8916
8917 if (CHECK_FLAG(p->af_sflags[afi][safi],
8918 PEER_STATUS_ORF_PREFIX_SEND)
8919 || orf_pfx_count) {
8920 vty_out(vty, " Outbound Route Filter (ORF):");
8921 if (CHECK_FLAG(p->af_sflags[afi][safi],
8922 PEER_STATUS_ORF_PREFIX_SEND))
8923 vty_out(vty, " sent;");
8924 if (orf_pfx_count)
8925 vty_out(vty, " received (%d entries)",
8926 orf_pfx_count);
8927 vty_out(vty, "\n");
8928 }
8929 if (CHECK_FLAG(p->af_sflags[afi][safi],
8930 PEER_STATUS_ORF_WAIT_REFRESH))
8931 vty_out(vty,
8932 " First update is deferred until ORF or ROUTE-REFRESH is received\n");
8933
8934 if (CHECK_FLAG(p->af_flags[afi][safi],
8935 PEER_FLAG_REFLECTOR_CLIENT))
8936 vty_out(vty, " Route-Reflector Client\n");
8937 if (CHECK_FLAG(p->af_flags[afi][safi],
8938 PEER_FLAG_RSERVER_CLIENT))
8939 vty_out(vty, " Route-Server Client\n");
8940 if (CHECK_FLAG(p->af_flags[afi][safi], PEER_FLAG_SOFT_RECONFIG))
8941 vty_out(vty,
8942 " Inbound soft reconfiguration allowed\n");
8943
8944 if (CHECK_FLAG(p->af_flags[afi][safi],
8945 PEER_FLAG_REMOVE_PRIVATE_AS_ALL_REPLACE))
8946 vty_out(vty,
8947 " Private AS numbers (all) replaced in updates to this neighbor\n");
8948 else if (CHECK_FLAG(p->af_flags[afi][safi],
8949 PEER_FLAG_REMOVE_PRIVATE_AS_REPLACE))
8950 vty_out(vty,
8951 " Private AS numbers replaced in updates to this neighbor\n");
8952 else if (CHECK_FLAG(p->af_flags[afi][safi],
8953 PEER_FLAG_REMOVE_PRIVATE_AS_ALL))
8954 vty_out(vty,
8955 " Private AS numbers (all) removed in updates to this neighbor\n");
8956 else if (CHECK_FLAG(p->af_flags[afi][safi],
8957 PEER_FLAG_REMOVE_PRIVATE_AS))
8958 vty_out(vty,
8959 " Private AS numbers removed in updates to this neighbor\n");
8960
8961 if (p->addpath_type[afi][safi] != BGP_ADDPATH_NONE)
8962 vty_out(vty, " %s\n",
8963 bgp_addpath_names(p->addpath_type[afi][safi])
8964 ->human_description);
8965
8966 if (CHECK_FLAG(p->af_flags[afi][safi], PEER_FLAG_AS_OVERRIDE))
8967 vty_out(vty,
8968 " Override ASNs in outbound updates if aspath equals remote-as\n");
8969
8970 if (CHECK_FLAG(p->af_flags[afi][safi], PEER_FLAG_NEXTHOP_SELF)
8971 || CHECK_FLAG(p->af_flags[afi][safi],
8972 PEER_FLAG_FORCE_NEXTHOP_SELF))
8973 vty_out(vty, " NEXT_HOP is always this router\n");
8974 if (CHECK_FLAG(p->af_flags[afi][safi],
8975 PEER_FLAG_AS_PATH_UNCHANGED))
8976 vty_out(vty,
8977 " AS_PATH is propagated unchanged to this neighbor\n");
8978 if (CHECK_FLAG(p->af_flags[afi][safi],
8979 PEER_FLAG_NEXTHOP_UNCHANGED))
8980 vty_out(vty,
8981 " NEXT_HOP is propagated unchanged to this neighbor\n");
8982 if (CHECK_FLAG(p->af_flags[afi][safi], PEER_FLAG_MED_UNCHANGED))
8983 vty_out(vty,
8984 " MED is propagated unchanged to this neighbor\n");
8985 if (CHECK_FLAG(p->af_flags[afi][safi], PEER_FLAG_SEND_COMMUNITY)
8986 || CHECK_FLAG(p->af_flags[afi][safi],
8987 PEER_FLAG_SEND_EXT_COMMUNITY)
8988 || CHECK_FLAG(p->af_flags[afi][safi],
8989 PEER_FLAG_SEND_LARGE_COMMUNITY)) {
8990 vty_out(vty,
8991 " Community attribute sent to this neighbor");
8992 if (CHECK_FLAG(p->af_flags[afi][safi],
8993 PEER_FLAG_SEND_COMMUNITY)
8994 && CHECK_FLAG(p->af_flags[afi][safi],
8995 PEER_FLAG_SEND_EXT_COMMUNITY)
8996 && CHECK_FLAG(p->af_flags[afi][safi],
8997 PEER_FLAG_SEND_LARGE_COMMUNITY))
8998 vty_out(vty, "(all)\n");
8999 else if (CHECK_FLAG(p->af_flags[afi][safi],
9000 PEER_FLAG_SEND_LARGE_COMMUNITY))
9001 vty_out(vty, "(large)\n");
9002 else if (CHECK_FLAG(p->af_flags[afi][safi],
9003 PEER_FLAG_SEND_EXT_COMMUNITY))
9004 vty_out(vty, "(extended)\n");
9005 else
9006 vty_out(vty, "(standard)\n");
9007 }
9008 if (CHECK_FLAG(p->af_flags[afi][safi],
9009 PEER_FLAG_DEFAULT_ORIGINATE)) {
9010 vty_out(vty, " Default information originate,");
9011
9012 if (p->default_rmap[afi][safi].name)
9013 vty_out(vty, " default route-map %s%s,",
9014 p->default_rmap[afi][safi].map ? "*"
9015 : "",
9016 p->default_rmap[afi][safi].name);
9017 if (paf && PAF_SUBGRP(paf)
9018 && CHECK_FLAG(PAF_SUBGRP(paf)->sflags,
9019 SUBGRP_STATUS_DEFAULT_ORIGINATE))
9020 vty_out(vty, " default sent\n");
9021 else
9022 vty_out(vty, " default not sent\n");
9023 }
9024
9025 /* advertise-vni-all */
9026 if (afi == AFI_L2VPN && safi == SAFI_EVPN) {
9027 if (is_evpn_enabled())
9028 vty_out(vty, " advertise-all-vni\n");
9029 }
9030
9031 if (filter->plist[FILTER_IN].name
9032 || filter->dlist[FILTER_IN].name
9033 || filter->aslist[FILTER_IN].name
9034 || filter->map[RMAP_IN].name)
9035 vty_out(vty, " Inbound path policy configured\n");
9036 if (filter->plist[FILTER_OUT].name
9037 || filter->dlist[FILTER_OUT].name
9038 || filter->aslist[FILTER_OUT].name
9039 || filter->map[RMAP_OUT].name || filter->usmap.name)
9040 vty_out(vty, " Outbound path policy configured\n");
9041
9042 /* prefix-list */
9043 if (filter->plist[FILTER_IN].name)
9044 vty_out(vty,
9045 " Incoming update prefix filter list is %s%s\n",
9046 filter->plist[FILTER_IN].plist ? "*" : "",
9047 filter->plist[FILTER_IN].name);
9048 if (filter->plist[FILTER_OUT].name)
9049 vty_out(vty,
9050 " Outgoing update prefix filter list is %s%s\n",
9051 filter->plist[FILTER_OUT].plist ? "*" : "",
9052 filter->plist[FILTER_OUT].name);
9053
9054 /* distribute-list */
9055 if (filter->dlist[FILTER_IN].name)
9056 vty_out(vty,
9057 " Incoming update network filter list is %s%s\n",
9058 filter->dlist[FILTER_IN].alist ? "*" : "",
9059 filter->dlist[FILTER_IN].name);
9060 if (filter->dlist[FILTER_OUT].name)
9061 vty_out(vty,
9062 " Outgoing update network filter list is %s%s\n",
9063 filter->dlist[FILTER_OUT].alist ? "*" : "",
9064 filter->dlist[FILTER_OUT].name);
9065
9066 /* filter-list. */
9067 if (filter->aslist[FILTER_IN].name)
9068 vty_out(vty,
9069 " Incoming update AS path filter list is %s%s\n",
9070 filter->aslist[FILTER_IN].aslist ? "*" : "",
9071 filter->aslist[FILTER_IN].name);
9072 if (filter->aslist[FILTER_OUT].name)
9073 vty_out(vty,
9074 " Outgoing update AS path filter list is %s%s\n",
9075 filter->aslist[FILTER_OUT].aslist ? "*" : "",
9076 filter->aslist[FILTER_OUT].name);
9077
9078 /* route-map. */
9079 if (filter->map[RMAP_IN].name)
9080 vty_out(vty,
9081 " Route map for incoming advertisements is %s%s\n",
9082 filter->map[RMAP_IN].map ? "*" : "",
9083 filter->map[RMAP_IN].name);
9084 if (filter->map[RMAP_OUT].name)
9085 vty_out(vty,
9086 " Route map for outgoing advertisements is %s%s\n",
9087 filter->map[RMAP_OUT].map ? "*" : "",
9088 filter->map[RMAP_OUT].name);
9089
9090 /* ebgp-requires-policy (inbound) */
9091 if (p->bgp->ebgp_requires_policy == DEFAULT_EBGP_POLICY_ENABLED
9092 && !bgp_inbound_policy_exists(p, filter))
9093 vty_out(vty,
9094 " Inbound updates discarded due to missing policy\n");
9095
9096 /* ebgp-requires-policy (outbound) */
9097 if (p->bgp->ebgp_requires_policy == DEFAULT_EBGP_POLICY_ENABLED
9098 && !bgp_outbound_policy_exists(p, filter))
9099 vty_out(vty,
9100 " Outbound updates discarded due to missing policy\n");
9101
9102 /* unsuppress-map */
9103 if (filter->usmap.name)
9104 vty_out(vty,
9105 " Route map for selective unsuppress is %s%s\n",
9106 filter->usmap.map ? "*" : "",
9107 filter->usmap.name);
9108
9109 /* Receive prefix count */
9110 vty_out(vty, " %ld accepted prefixes\n", p->pcount[afi][safi]);
9111
9112 /* Maximum prefix */
9113 if (CHECK_FLAG(p->af_flags[afi][safi], PEER_FLAG_MAX_PREFIX)) {
9114 vty_out(vty, " Maximum prefixes allowed %ld%s\n",
9115 p->pmax[afi][safi],
9116 CHECK_FLAG(p->af_flags[afi][safi],
9117 PEER_FLAG_MAX_PREFIX_WARNING)
9118 ? " (warning-only)"
9119 : "");
9120 vty_out(vty, " Threshold for warning message %d%%",
9121 p->pmax_threshold[afi][safi]);
9122 if (p->pmax_restart[afi][safi])
9123 vty_out(vty, ", restart interval %d min",
9124 p->pmax_restart[afi][safi]);
9125 vty_out(vty, "\n");
9126 }
9127
9128 vty_out(vty, "\n");
9129 }
9130 }
9131
9132 static void bgp_show_peer(struct vty *vty, struct peer *p, bool use_json,
9133 json_object *json)
9134 {
9135 struct bgp *bgp;
9136 char buf1[PREFIX2STR_BUFFER], buf[SU_ADDRSTRLEN];
9137 char timebuf[BGP_UPTIME_LEN];
9138 char dn_flag[2];
9139 const char *subcode_str;
9140 const char *code_str;
9141 afi_t afi;
9142 safi_t safi;
9143 uint16_t i;
9144 uint8_t *msg;
9145 json_object *json_neigh = NULL;
9146 time_t epoch_tbuf;
9147
9148 bgp = p->bgp;
9149
9150 if (use_json)
9151 json_neigh = json_object_new_object();
9152
9153 memset(dn_flag, '\0', sizeof(dn_flag));
9154 if (!p->conf_if && peer_dynamic_neighbor(p))
9155 dn_flag[0] = '*';
9156
9157 if (!use_json) {
9158 if (p->conf_if) /* Configured interface name. */
9159 vty_out(vty, "BGP neighbor on %s: %s, ", p->conf_if,
9160 BGP_PEER_SU_UNSPEC(p)
9161 ? "None"
9162 : sockunion2str(&p->su, buf,
9163 SU_ADDRSTRLEN));
9164 else /* Configured IP address. */
9165 vty_out(vty, "BGP neighbor is %s%s, ", dn_flag,
9166 p->host);
9167 }
9168
9169 if (use_json) {
9170 if (p->conf_if && BGP_PEER_SU_UNSPEC(p))
9171 json_object_string_add(json_neigh, "bgpNeighborAddr",
9172 "none");
9173 else if (p->conf_if && !BGP_PEER_SU_UNSPEC(p))
9174 json_object_string_add(
9175 json_neigh, "bgpNeighborAddr",
9176 sockunion2str(&p->su, buf, SU_ADDRSTRLEN));
9177
9178 json_object_int_add(json_neigh, "remoteAs", p->as);
9179
9180 if (p->change_local_as)
9181 json_object_int_add(json_neigh, "localAs",
9182 p->change_local_as);
9183 else
9184 json_object_int_add(json_neigh, "localAs", p->local_as);
9185
9186 if (CHECK_FLAG(p->flags, PEER_FLAG_LOCAL_AS_NO_PREPEND))
9187 json_object_boolean_true_add(json_neigh,
9188 "localAsNoPrepend");
9189
9190 if (CHECK_FLAG(p->flags, PEER_FLAG_LOCAL_AS_REPLACE_AS))
9191 json_object_boolean_true_add(json_neigh,
9192 "localAsReplaceAs");
9193 } else {
9194 if ((p->as_type == AS_SPECIFIED) || (p->as_type == AS_EXTERNAL)
9195 || (p->as_type == AS_INTERNAL))
9196 vty_out(vty, "remote AS %u, ", p->as);
9197 else
9198 vty_out(vty, "remote AS Unspecified, ");
9199 vty_out(vty, "local AS %u%s%s, ",
9200 p->change_local_as ? p->change_local_as : p->local_as,
9201 CHECK_FLAG(p->flags, PEER_FLAG_LOCAL_AS_NO_PREPEND)
9202 ? " no-prepend"
9203 : "",
9204 CHECK_FLAG(p->flags, PEER_FLAG_LOCAL_AS_REPLACE_AS)
9205 ? " replace-as"
9206 : "");
9207 }
9208 /* peer type internal or confed-internal */
9209 if ((p->as == p->local_as) || (p->as_type == AS_INTERNAL)) {
9210 if (use_json) {
9211 if (CHECK_FLAG(bgp->config, BGP_CONFIG_CONFEDERATION))
9212 json_object_boolean_true_add(
9213 json_neigh, "nbrConfedInternalLink");
9214 else
9215 json_object_boolean_true_add(json_neigh,
9216 "nbrInternalLink");
9217 } else {
9218 if (CHECK_FLAG(bgp->config, BGP_CONFIG_CONFEDERATION))
9219 vty_out(vty, "confed-internal link\n");
9220 else
9221 vty_out(vty, "internal link\n");
9222 }
9223 /* peer type external or confed-external */
9224 } else if (p->as || (p->as_type == AS_EXTERNAL)) {
9225 if (use_json) {
9226 if (CHECK_FLAG(bgp->config, BGP_CONFIG_CONFEDERATION))
9227 json_object_boolean_true_add(
9228 json_neigh, "nbrConfedExternalLink");
9229 else
9230 json_object_boolean_true_add(json_neigh,
9231 "nbrExternalLink");
9232 } else {
9233 if (bgp_confederation_peers_check(bgp, p->as))
9234 vty_out(vty, "confed-external link\n");
9235 else
9236 vty_out(vty, "external link\n");
9237 }
9238 } else {
9239 if (use_json)
9240 json_object_boolean_true_add(json_neigh,
9241 "nbrUnspecifiedLink");
9242 else
9243 vty_out(vty, "unspecified link\n");
9244 }
9245
9246 /* Description. */
9247 if (p->desc) {
9248 if (use_json)
9249 json_object_string_add(json_neigh, "nbrDesc", p->desc);
9250 else
9251 vty_out(vty, " Description: %s\n", p->desc);
9252 }
9253
9254 if (p->hostname) {
9255 if (use_json) {
9256 if (p->hostname)
9257 json_object_string_add(json_neigh, "hostname",
9258 p->hostname);
9259
9260 if (p->domainname)
9261 json_object_string_add(json_neigh, "domainname",
9262 p->domainname);
9263 } else {
9264 if (p->domainname && (p->domainname[0] != '\0'))
9265 vty_out(vty, "Hostname: %s.%s\n", p->hostname,
9266 p->domainname);
9267 else
9268 vty_out(vty, "Hostname: %s\n", p->hostname);
9269 }
9270 }
9271
9272 /* Peer-group */
9273 if (p->group) {
9274 if (use_json) {
9275 json_object_string_add(json_neigh, "peerGroup",
9276 p->group->name);
9277
9278 if (dn_flag[0]) {
9279 struct prefix prefix, *range = NULL;
9280
9281 sockunion2hostprefix(&(p->su), &prefix);
9282 range = peer_group_lookup_dynamic_neighbor_range(
9283 p->group, &prefix);
9284
9285 if (range) {
9286 prefix2str(range, buf1, sizeof(buf1));
9287 json_object_string_add(
9288 json_neigh,
9289 "peerSubnetRangeGroup", buf1);
9290 }
9291 }
9292 } else {
9293 vty_out(vty,
9294 " Member of peer-group %s for session parameters\n",
9295 p->group->name);
9296
9297 if (dn_flag[0]) {
9298 struct prefix prefix, *range = NULL;
9299
9300 sockunion2hostprefix(&(p->su), &prefix);
9301 range = peer_group_lookup_dynamic_neighbor_range(
9302 p->group, &prefix);
9303
9304 if (range) {
9305 prefix2str(range, buf1, sizeof(buf1));
9306 vty_out(vty,
9307 " Belongs to the subnet range group: %s\n",
9308 buf1);
9309 }
9310 }
9311 }
9312 }
9313
9314 if (use_json) {
9315 /* Administrative shutdown. */
9316 if (CHECK_FLAG(p->flags, PEER_FLAG_SHUTDOWN))
9317 json_object_boolean_true_add(json_neigh,
9318 "adminShutDown");
9319
9320 /* BGP Version. */
9321 json_object_int_add(json_neigh, "bgpVersion", 4);
9322 json_object_string_add(
9323 json_neigh, "remoteRouterId",
9324 inet_ntop(AF_INET, &p->remote_id, buf1, sizeof(buf1)));
9325 json_object_string_add(
9326 json_neigh, "localRouterId",
9327 inet_ntop(AF_INET, &bgp->router_id, buf1,
9328 sizeof(buf1)));
9329
9330 /* Confederation */
9331 if (CHECK_FLAG(bgp->config, BGP_CONFIG_CONFEDERATION)
9332 && bgp_confederation_peers_check(bgp, p->as))
9333 json_object_boolean_true_add(json_neigh,
9334 "nbrCommonAdmin");
9335
9336 /* Status. */
9337 json_object_string_add(
9338 json_neigh, "bgpState",
9339 lookup_msg(bgp_status_msg, p->status, NULL));
9340
9341 if (p->status == Established) {
9342 time_t uptime;
9343
9344 uptime = bgp_clock();
9345 uptime -= p->uptime;
9346 epoch_tbuf = time(NULL) - uptime;
9347
9348 #if CONFDATE > 20200101
9349 CPP_NOTICE(
9350 "bgpTimerUp should be deprecated and can be removed now");
9351 #endif
9352 /*
9353 * bgpTimerUp was miliseconds that was accurate
9354 * up to 1 day, then the value returned
9355 * became garbage. So in order to provide
9356 * some level of backwards compatability,
9357 * we still provde the data, but now
9358 * we are returning the correct value
9359 * and also adding a new bgpTimerUpMsec
9360 * which will allow us to deprecate
9361 * this eventually
9362 */
9363 json_object_int_add(json_neigh, "bgpTimerUp",
9364 uptime * 1000);
9365 json_object_int_add(json_neigh, "bgpTimerUpMsec",
9366 uptime * 1000);
9367 json_object_string_add(json_neigh, "bgpTimerUpString",
9368 peer_uptime(p->uptime, timebuf,
9369 BGP_UPTIME_LEN, 0,
9370 NULL));
9371 json_object_int_add(json_neigh,
9372 "bgpTimerUpEstablishedEpoch",
9373 epoch_tbuf);
9374 }
9375
9376 else if (p->status == Active) {
9377 if (CHECK_FLAG(p->flags, PEER_FLAG_PASSIVE))
9378 json_object_string_add(json_neigh, "bgpStateIs",
9379 "passive");
9380 else if (CHECK_FLAG(p->sflags, PEER_STATUS_NSF_WAIT))
9381 json_object_string_add(json_neigh, "bgpStateIs",
9382 "passiveNSF");
9383 }
9384
9385 /* read timer */
9386 time_t uptime;
9387 struct tm *tm;
9388
9389 uptime = bgp_clock();
9390 uptime -= p->readtime;
9391 tm = gmtime(&uptime);
9392 json_object_int_add(json_neigh, "bgpTimerLastRead",
9393 (tm->tm_sec * 1000) + (tm->tm_min * 60000)
9394 + (tm->tm_hour * 3600000));
9395
9396 uptime = bgp_clock();
9397 uptime -= p->last_write;
9398 tm = gmtime(&uptime);
9399 json_object_int_add(json_neigh, "bgpTimerLastWrite",
9400 (tm->tm_sec * 1000) + (tm->tm_min * 60000)
9401 + (tm->tm_hour * 3600000));
9402
9403 uptime = bgp_clock();
9404 uptime -= p->update_time;
9405 tm = gmtime(&uptime);
9406 json_object_int_add(json_neigh, "bgpInUpdateElapsedTimeMsecs",
9407 (tm->tm_sec * 1000) + (tm->tm_min * 60000)
9408 + (tm->tm_hour * 3600000));
9409
9410 /* Configured timer values. */
9411 json_object_int_add(json_neigh, "bgpTimerHoldTimeMsecs",
9412 p->v_holdtime * 1000);
9413 json_object_int_add(json_neigh,
9414 "bgpTimerKeepAliveIntervalMsecs",
9415 p->v_keepalive * 1000);
9416 if (CHECK_FLAG(p->flags, PEER_FLAG_TIMER)) {
9417 json_object_int_add(json_neigh,
9418 "bgpTimerConfiguredHoldTimeMsecs",
9419 p->holdtime * 1000);
9420 json_object_int_add(
9421 json_neigh,
9422 "bgpTimerConfiguredKeepAliveIntervalMsecs",
9423 p->keepalive * 1000);
9424 } else if ((bgp->default_holdtime != BGP_DEFAULT_HOLDTIME)
9425 || (bgp->default_keepalive
9426 != BGP_DEFAULT_KEEPALIVE)) {
9427 json_object_int_add(json_neigh,
9428 "bgpTimerConfiguredHoldTimeMsecs",
9429 bgp->default_holdtime);
9430 json_object_int_add(
9431 json_neigh,
9432 "bgpTimerConfiguredKeepAliveIntervalMsecs",
9433 bgp->default_keepalive);
9434 }
9435 } else {
9436 /* Administrative shutdown. */
9437 if (CHECK_FLAG(p->flags, PEER_FLAG_SHUTDOWN))
9438 vty_out(vty, " Administratively shut down\n");
9439
9440 /* BGP Version. */
9441 vty_out(vty, " BGP version 4");
9442 vty_out(vty, ", remote router ID %s",
9443 inet_ntop(AF_INET, &p->remote_id, buf1, sizeof(buf1)));
9444 vty_out(vty, ", local router ID %s\n",
9445 inet_ntop(AF_INET, &bgp->router_id, buf1,
9446 sizeof(buf1)));
9447
9448 /* Confederation */
9449 if (CHECK_FLAG(bgp->config, BGP_CONFIG_CONFEDERATION)
9450 && bgp_confederation_peers_check(bgp, p->as))
9451 vty_out(vty,
9452 " Neighbor under common administration\n");
9453
9454 /* Status. */
9455 vty_out(vty, " BGP state = %s",
9456 lookup_msg(bgp_status_msg, p->status, NULL));
9457
9458 if (p->status == Established)
9459 vty_out(vty, ", up for %8s",
9460 peer_uptime(p->uptime, timebuf, BGP_UPTIME_LEN,
9461 0, NULL));
9462
9463 else if (p->status == Active) {
9464 if (CHECK_FLAG(p->flags, PEER_FLAG_PASSIVE))
9465 vty_out(vty, " (passive)");
9466 else if (CHECK_FLAG(p->sflags, PEER_STATUS_NSF_WAIT))
9467 vty_out(vty, " (NSF passive)");
9468 }
9469 vty_out(vty, "\n");
9470
9471 /* read timer */
9472 vty_out(vty, " Last read %s",
9473 peer_uptime(p->readtime, timebuf, BGP_UPTIME_LEN, 0,
9474 NULL));
9475 vty_out(vty, ", Last write %s\n",
9476 peer_uptime(p->last_write, timebuf, BGP_UPTIME_LEN, 0,
9477 NULL));
9478
9479 /* Configured timer values. */
9480 vty_out(vty,
9481 " Hold time is %d, keepalive interval is %d seconds\n",
9482 p->v_holdtime, p->v_keepalive);
9483 if (CHECK_FLAG(p->flags, PEER_FLAG_TIMER)) {
9484 vty_out(vty, " Configured hold time is %d",
9485 p->holdtime);
9486 vty_out(vty, ", keepalive interval is %d seconds\n",
9487 p->keepalive);
9488 } else if ((bgp->default_holdtime != BGP_DEFAULT_HOLDTIME)
9489 || (bgp->default_keepalive
9490 != BGP_DEFAULT_KEEPALIVE)) {
9491 vty_out(vty, " Configured hold time is %d",
9492 bgp->default_holdtime);
9493 vty_out(vty, ", keepalive interval is %d seconds\n",
9494 bgp->default_keepalive);
9495 }
9496 }
9497 /* Capability. */
9498 if (p->status == Established) {
9499 if (p->cap || p->afc_adv[AFI_IP][SAFI_UNICAST]
9500 || p->afc_recv[AFI_IP][SAFI_UNICAST]
9501 || p->afc_adv[AFI_IP][SAFI_MULTICAST]
9502 || p->afc_recv[AFI_IP][SAFI_MULTICAST]
9503 || p->afc_adv[AFI_IP6][SAFI_UNICAST]
9504 || p->afc_recv[AFI_IP6][SAFI_UNICAST]
9505 || p->afc_adv[AFI_IP6][SAFI_MULTICAST]
9506 || p->afc_recv[AFI_IP6][SAFI_MULTICAST]
9507 || p->afc_adv[AFI_IP6][SAFI_MPLS_VPN]
9508 || p->afc_recv[AFI_IP6][SAFI_MPLS_VPN]
9509 || p->afc_adv[AFI_IP6][SAFI_ENCAP]
9510 || p->afc_recv[AFI_IP6][SAFI_ENCAP]
9511 || p->afc_adv[AFI_IP6][SAFI_FLOWSPEC]
9512 || p->afc_recv[AFI_IP6][SAFI_FLOWSPEC]
9513 || p->afc_adv[AFI_IP][SAFI_ENCAP]
9514 || p->afc_recv[AFI_IP][SAFI_ENCAP]
9515 || p->afc_adv[AFI_IP][SAFI_FLOWSPEC]
9516 || p->afc_recv[AFI_IP][SAFI_FLOWSPEC]
9517 || p->afc_adv[AFI_IP][SAFI_MPLS_VPN]
9518 || p->afc_recv[AFI_IP][SAFI_MPLS_VPN]) {
9519 if (use_json) {
9520 json_object *json_cap = NULL;
9521
9522 json_cap = json_object_new_object();
9523
9524 /* AS4 */
9525 if (CHECK_FLAG(p->cap, PEER_CAP_AS4_RCV)
9526 || CHECK_FLAG(p->cap, PEER_CAP_AS4_ADV)) {
9527 if (CHECK_FLAG(p->cap, PEER_CAP_AS4_ADV)
9528 && CHECK_FLAG(p->cap,
9529 PEER_CAP_AS4_RCV))
9530 json_object_string_add(
9531 json_cap, "4byteAs",
9532 "advertisedAndReceived");
9533 else if (CHECK_FLAG(p->cap,
9534 PEER_CAP_AS4_ADV))
9535 json_object_string_add(
9536 json_cap, "4byteAs",
9537 "advertised");
9538 else if (CHECK_FLAG(p->cap,
9539 PEER_CAP_AS4_RCV))
9540 json_object_string_add(
9541 json_cap, "4byteAs",
9542 "received");
9543 }
9544
9545 /* AddPath */
9546 if (CHECK_FLAG(p->cap, PEER_CAP_ADDPATH_RCV)
9547 || CHECK_FLAG(p->cap,
9548 PEER_CAP_ADDPATH_ADV)) {
9549 json_object *json_add = NULL;
9550 const char *print_store;
9551
9552 json_add = json_object_new_object();
9553
9554 FOREACH_AFI_SAFI (afi, safi) {
9555 json_object *json_sub = NULL;
9556 json_sub =
9557 json_object_new_object();
9558 print_store = afi_safi_print(
9559 afi, safi);
9560
9561 if (CHECK_FLAG(
9562 p->af_cap[afi]
9563 [safi],
9564 PEER_CAP_ADDPATH_AF_TX_ADV)
9565 || CHECK_FLAG(
9566 p->af_cap[afi]
9567 [safi],
9568 PEER_CAP_ADDPATH_AF_TX_RCV)) {
9569 if (CHECK_FLAG(
9570 p->af_cap
9571 [afi]
9572 [safi],
9573 PEER_CAP_ADDPATH_AF_TX_ADV)
9574 && CHECK_FLAG(
9575 p->af_cap
9576 [afi]
9577 [safi],
9578 PEER_CAP_ADDPATH_AF_TX_RCV))
9579 json_object_boolean_true_add(
9580 json_sub,
9581 "txAdvertisedAndReceived");
9582 else if (
9583 CHECK_FLAG(
9584 p->af_cap
9585 [afi]
9586 [safi],
9587 PEER_CAP_ADDPATH_AF_TX_ADV))
9588 json_object_boolean_true_add(
9589 json_sub,
9590 "txAdvertised");
9591 else if (
9592 CHECK_FLAG(
9593 p->af_cap
9594 [afi]
9595 [safi],
9596 PEER_CAP_ADDPATH_AF_TX_RCV))
9597 json_object_boolean_true_add(
9598 json_sub,
9599 "txReceived");
9600 }
9601
9602 if (CHECK_FLAG(
9603 p->af_cap[afi]
9604 [safi],
9605 PEER_CAP_ADDPATH_AF_RX_ADV)
9606 || CHECK_FLAG(
9607 p->af_cap[afi]
9608 [safi],
9609 PEER_CAP_ADDPATH_AF_RX_RCV)) {
9610 if (CHECK_FLAG(
9611 p->af_cap
9612 [afi]
9613 [safi],
9614 PEER_CAP_ADDPATH_AF_RX_ADV)
9615 && CHECK_FLAG(
9616 p->af_cap
9617 [afi]
9618 [safi],
9619 PEER_CAP_ADDPATH_AF_RX_RCV))
9620 json_object_boolean_true_add(
9621 json_sub,
9622 "rxAdvertisedAndReceived");
9623 else if (
9624 CHECK_FLAG(
9625 p->af_cap
9626 [afi]
9627 [safi],
9628 PEER_CAP_ADDPATH_AF_RX_ADV))
9629 json_object_boolean_true_add(
9630 json_sub,
9631 "rxAdvertised");
9632 else if (
9633 CHECK_FLAG(
9634 p->af_cap
9635 [afi]
9636 [safi],
9637 PEER_CAP_ADDPATH_AF_RX_RCV))
9638 json_object_boolean_true_add(
9639 json_sub,
9640 "rxReceived");
9641 }
9642
9643 if (CHECK_FLAG(
9644 p->af_cap[afi]
9645 [safi],
9646 PEER_CAP_ADDPATH_AF_TX_ADV)
9647 || CHECK_FLAG(
9648 p->af_cap[afi]
9649 [safi],
9650 PEER_CAP_ADDPATH_AF_TX_RCV)
9651 || CHECK_FLAG(
9652 p->af_cap[afi]
9653 [safi],
9654 PEER_CAP_ADDPATH_AF_RX_ADV)
9655 || CHECK_FLAG(
9656 p->af_cap[afi]
9657 [safi],
9658 PEER_CAP_ADDPATH_AF_RX_RCV))
9659 json_object_object_add(
9660 json_add,
9661 print_store,
9662 json_sub);
9663 else
9664 json_object_free(
9665 json_sub);
9666 }
9667
9668 json_object_object_add(
9669 json_cap, "addPath", json_add);
9670 }
9671
9672 /* Dynamic */
9673 if (CHECK_FLAG(p->cap, PEER_CAP_DYNAMIC_RCV)
9674 || CHECK_FLAG(p->cap,
9675 PEER_CAP_DYNAMIC_ADV)) {
9676 if (CHECK_FLAG(p->cap,
9677 PEER_CAP_DYNAMIC_ADV)
9678 && CHECK_FLAG(p->cap,
9679 PEER_CAP_DYNAMIC_RCV))
9680 json_object_string_add(
9681 json_cap, "dynamic",
9682 "advertisedAndReceived");
9683 else if (CHECK_FLAG(
9684 p->cap,
9685 PEER_CAP_DYNAMIC_ADV))
9686 json_object_string_add(
9687 json_cap, "dynamic",
9688 "advertised");
9689 else if (CHECK_FLAG(
9690 p->cap,
9691 PEER_CAP_DYNAMIC_RCV))
9692 json_object_string_add(
9693 json_cap, "dynamic",
9694 "received");
9695 }
9696
9697 /* Extended nexthop */
9698 if (CHECK_FLAG(p->cap, PEER_CAP_ENHE_RCV)
9699 || CHECK_FLAG(p->cap, PEER_CAP_ENHE_ADV)) {
9700 json_object *json_nxt = NULL;
9701 const char *print_store;
9702
9703
9704 if (CHECK_FLAG(p->cap,
9705 PEER_CAP_ENHE_ADV)
9706 && CHECK_FLAG(p->cap,
9707 PEER_CAP_ENHE_RCV))
9708 json_object_string_add(
9709 json_cap,
9710 "extendedNexthop",
9711 "advertisedAndReceived");
9712 else if (CHECK_FLAG(p->cap,
9713 PEER_CAP_ENHE_ADV))
9714 json_object_string_add(
9715 json_cap,
9716 "extendedNexthop",
9717 "advertised");
9718 else if (CHECK_FLAG(p->cap,
9719 PEER_CAP_ENHE_RCV))
9720 json_object_string_add(
9721 json_cap,
9722 "extendedNexthop",
9723 "received");
9724
9725 if (CHECK_FLAG(p->cap,
9726 PEER_CAP_ENHE_RCV)) {
9727 json_nxt =
9728 json_object_new_object();
9729
9730 for (safi = SAFI_UNICAST;
9731 safi < SAFI_MAX; safi++) {
9732 if (CHECK_FLAG(
9733 p->af_cap
9734 [AFI_IP]
9735 [safi],
9736 PEER_CAP_ENHE_AF_RCV)) {
9737 print_store = afi_safi_print(
9738 AFI_IP,
9739 safi);
9740 json_object_string_add(
9741 json_nxt,
9742 print_store,
9743 "recieved"); /* misspelled for compatibility */
9744 }
9745 }
9746 json_object_object_add(
9747 json_cap,
9748 "extendedNexthopFamililesByPeer",
9749 json_nxt);
9750 }
9751 }
9752
9753 /* Route Refresh */
9754 if (CHECK_FLAG(p->cap, PEER_CAP_REFRESH_ADV)
9755 || CHECK_FLAG(p->cap,
9756 PEER_CAP_REFRESH_NEW_RCV)
9757 || CHECK_FLAG(p->cap,
9758 PEER_CAP_REFRESH_OLD_RCV)) {
9759 if (CHECK_FLAG(p->cap,
9760 PEER_CAP_REFRESH_ADV)
9761 && (CHECK_FLAG(
9762 p->cap,
9763 PEER_CAP_REFRESH_NEW_RCV)
9764 || CHECK_FLAG(
9765 p->cap,
9766 PEER_CAP_REFRESH_OLD_RCV))) {
9767 if (CHECK_FLAG(
9768 p->cap,
9769 PEER_CAP_REFRESH_OLD_RCV)
9770 && CHECK_FLAG(
9771 p->cap,
9772 PEER_CAP_REFRESH_NEW_RCV))
9773 json_object_string_add(
9774 json_cap,
9775 "routeRefresh",
9776 "advertisedAndReceivedOldNew");
9777 else {
9778 if (CHECK_FLAG(
9779 p->cap,
9780 PEER_CAP_REFRESH_OLD_RCV))
9781 json_object_string_add(
9782 json_cap,
9783 "routeRefresh",
9784 "advertisedAndReceivedOld");
9785 else
9786 json_object_string_add(
9787 json_cap,
9788 "routeRefresh",
9789 "advertisedAndReceivedNew");
9790 }
9791 } else if (
9792 CHECK_FLAG(
9793 p->cap,
9794 PEER_CAP_REFRESH_ADV))
9795 json_object_string_add(
9796 json_cap,
9797 "routeRefresh",
9798 "advertised");
9799 else if (
9800 CHECK_FLAG(
9801 p->cap,
9802 PEER_CAP_REFRESH_NEW_RCV)
9803 || CHECK_FLAG(
9804 p->cap,
9805 PEER_CAP_REFRESH_OLD_RCV))
9806 json_object_string_add(
9807 json_cap,
9808 "routeRefresh",
9809 "received");
9810 }
9811
9812 /* Multiprotocol Extensions */
9813 json_object *json_multi = NULL;
9814 json_multi = json_object_new_object();
9815
9816 FOREACH_AFI_SAFI (afi, safi) {
9817 if (p->afc_adv[afi][safi]
9818 || p->afc_recv[afi][safi]) {
9819 json_object *json_exten = NULL;
9820 json_exten =
9821 json_object_new_object();
9822
9823 if (p->afc_adv[afi][safi]
9824 && p->afc_recv[afi][safi])
9825 json_object_boolean_true_add(
9826 json_exten,
9827 "advertisedAndReceived");
9828 else if (p->afc_adv[afi][safi])
9829 json_object_boolean_true_add(
9830 json_exten,
9831 "advertised");
9832 else if (p->afc_recv[afi][safi])
9833 json_object_boolean_true_add(
9834 json_exten,
9835 "received");
9836
9837 json_object_object_add(
9838 json_multi,
9839 afi_safi_print(afi,
9840 safi),
9841 json_exten);
9842 }
9843 }
9844 json_object_object_add(
9845 json_cap, "multiprotocolExtensions",
9846 json_multi);
9847
9848 /* Hostname capabilities */
9849 json_object *json_hname = NULL;
9850
9851 json_hname = json_object_new_object();
9852
9853 if (CHECK_FLAG(p->cap, PEER_CAP_HOSTNAME_ADV)) {
9854 json_object_string_add(
9855 json_hname, "advHostName",
9856 bgp->peer_self->hostname
9857 ? bgp->peer_self
9858 ->hostname
9859 : "n/a");
9860 json_object_string_add(
9861 json_hname, "advDomainName",
9862 bgp->peer_self->domainname
9863 ? bgp->peer_self
9864 ->domainname
9865 : "n/a");
9866 }
9867
9868
9869 if (CHECK_FLAG(p->cap, PEER_CAP_HOSTNAME_RCV)) {
9870 json_object_string_add(
9871 json_hname, "rcvHostName",
9872 p->hostname ? p->hostname
9873 : "n/a");
9874 json_object_string_add(
9875 json_hname, "rcvDomainName",
9876 p->domainname ? p->domainname
9877 : "n/a");
9878 }
9879
9880 json_object_object_add(json_cap, "hostName",
9881 json_hname);
9882
9883 /* Gracefull Restart */
9884 if (CHECK_FLAG(p->cap, PEER_CAP_RESTART_RCV)
9885 || CHECK_FLAG(p->cap,
9886 PEER_CAP_RESTART_ADV)) {
9887 if (CHECK_FLAG(p->cap,
9888 PEER_CAP_RESTART_ADV)
9889 && CHECK_FLAG(p->cap,
9890 PEER_CAP_RESTART_RCV))
9891 json_object_string_add(
9892 json_cap,
9893 "gracefulRestart",
9894 "advertisedAndReceived");
9895 else if (CHECK_FLAG(
9896 p->cap,
9897 PEER_CAP_RESTART_ADV))
9898 json_object_string_add(
9899 json_cap,
9900 "gracefulRestartCapability",
9901 "advertised");
9902 else if (CHECK_FLAG(
9903 p->cap,
9904 PEER_CAP_RESTART_RCV))
9905 json_object_string_add(
9906 json_cap,
9907 "gracefulRestartCapability",
9908 "received");
9909
9910 if (CHECK_FLAG(p->cap,
9911 PEER_CAP_RESTART_RCV)) {
9912 int restart_af_count = 0;
9913 json_object *json_restart =
9914 NULL;
9915 json_restart =
9916 json_object_new_object();
9917
9918 json_object_int_add(
9919 json_cap,
9920 "gracefulRestartRemoteTimerMsecs",
9921 p->v_gr_restart * 1000);
9922
9923 FOREACH_AFI_SAFI (afi, safi) {
9924 if (CHECK_FLAG(
9925 p->af_cap
9926 [afi]
9927 [safi],
9928 PEER_CAP_RESTART_AF_RCV)) {
9929 json_object *
9930 json_sub =
9931 NULL;
9932 json_sub =
9933 json_object_new_object();
9934
9935 if (CHECK_FLAG(
9936 p->af_cap
9937 [afi]
9938 [safi],
9939 PEER_CAP_RESTART_AF_PRESERVE_RCV))
9940 json_object_boolean_true_add(
9941 json_sub,
9942 "preserved");
9943 restart_af_count++;
9944 json_object_object_add(
9945 json_restart,
9946 afi_safi_print(
9947 afi,
9948 safi),
9949 json_sub);
9950 }
9951 }
9952 if (!restart_af_count) {
9953 json_object_string_add(
9954 json_cap,
9955 "addressFamiliesByPeer",
9956 "none");
9957 json_object_free(
9958 json_restart);
9959 } else
9960 json_object_object_add(
9961 json_cap,
9962 "addressFamiliesByPeer",
9963 json_restart);
9964 }
9965 }
9966 json_object_object_add(json_neigh,
9967 "neighborCapabilities",
9968 json_cap);
9969 } else {
9970 vty_out(vty, " Neighbor capabilities:\n");
9971
9972 /* AS4 */
9973 if (CHECK_FLAG(p->cap, PEER_CAP_AS4_RCV)
9974 || CHECK_FLAG(p->cap, PEER_CAP_AS4_ADV)) {
9975 vty_out(vty, " 4 Byte AS:");
9976 if (CHECK_FLAG(p->cap,
9977 PEER_CAP_AS4_ADV))
9978 vty_out(vty, " advertised");
9979 if (CHECK_FLAG(p->cap,
9980 PEER_CAP_AS4_RCV))
9981 vty_out(vty, " %sreceived",
9982 CHECK_FLAG(
9983 p->cap,
9984 PEER_CAP_AS4_ADV)
9985 ? "and "
9986 : "");
9987 vty_out(vty, "\n");
9988 }
9989
9990 /* AddPath */
9991 if (CHECK_FLAG(p->cap, PEER_CAP_ADDPATH_RCV)
9992 || CHECK_FLAG(p->cap,
9993 PEER_CAP_ADDPATH_ADV)) {
9994 vty_out(vty, " AddPath:\n");
9995
9996 FOREACH_AFI_SAFI (afi, safi) {
9997 if (CHECK_FLAG(
9998 p->af_cap[afi]
9999 [safi],
10000 PEER_CAP_ADDPATH_AF_TX_ADV)
10001 || CHECK_FLAG(
10002 p->af_cap[afi]
10003 [safi],
10004 PEER_CAP_ADDPATH_AF_TX_RCV)) {
10005 vty_out(vty,
10006 " %s: TX ",
10007 afi_safi_print(
10008 afi,
10009 safi));
10010
10011 if (CHECK_FLAG(
10012 p->af_cap
10013 [afi]
10014 [safi],
10015 PEER_CAP_ADDPATH_AF_TX_ADV))
10016 vty_out(vty,
10017 "advertised %s",
10018 afi_safi_print(
10019 afi,
10020 safi));
10021
10022 if (CHECK_FLAG(
10023 p->af_cap
10024 [afi]
10025 [safi],
10026 PEER_CAP_ADDPATH_AF_TX_RCV))
10027 vty_out(vty,
10028 "%sreceived",
10029 CHECK_FLAG(
10030 p->af_cap
10031 [afi]
10032 [safi],
10033 PEER_CAP_ADDPATH_AF_TX_ADV)
10034 ? " and "
10035 : "");
10036
10037 vty_out(vty, "\n");
10038 }
10039
10040 if (CHECK_FLAG(
10041 p->af_cap[afi]
10042 [safi],
10043 PEER_CAP_ADDPATH_AF_RX_ADV)
10044 || CHECK_FLAG(
10045 p->af_cap[afi]
10046 [safi],
10047 PEER_CAP_ADDPATH_AF_RX_RCV)) {
10048 vty_out(vty,
10049 " %s: RX ",
10050 afi_safi_print(
10051 afi,
10052 safi));
10053
10054 if (CHECK_FLAG(
10055 p->af_cap
10056 [afi]
10057 [safi],
10058 PEER_CAP_ADDPATH_AF_RX_ADV))
10059 vty_out(vty,
10060 "advertised %s",
10061 afi_safi_print(
10062 afi,
10063 safi));
10064
10065 if (CHECK_FLAG(
10066 p->af_cap
10067 [afi]
10068 [safi],
10069 PEER_CAP_ADDPATH_AF_RX_RCV))
10070 vty_out(vty,
10071 "%sreceived",
10072 CHECK_FLAG(
10073 p->af_cap
10074 [afi]
10075 [safi],
10076 PEER_CAP_ADDPATH_AF_RX_ADV)
10077 ? " and "
10078 : "");
10079
10080 vty_out(vty, "\n");
10081 }
10082 }
10083 }
10084
10085 /* Dynamic */
10086 if (CHECK_FLAG(p->cap, PEER_CAP_DYNAMIC_RCV)
10087 || CHECK_FLAG(p->cap,
10088 PEER_CAP_DYNAMIC_ADV)) {
10089 vty_out(vty, " Dynamic:");
10090 if (CHECK_FLAG(p->cap,
10091 PEER_CAP_DYNAMIC_ADV))
10092 vty_out(vty, " advertised");
10093 if (CHECK_FLAG(p->cap,
10094 PEER_CAP_DYNAMIC_RCV))
10095 vty_out(vty, " %sreceived",
10096 CHECK_FLAG(
10097 p->cap,
10098 PEER_CAP_DYNAMIC_ADV)
10099 ? "and "
10100 : "");
10101 vty_out(vty, "\n");
10102 }
10103
10104 /* Extended nexthop */
10105 if (CHECK_FLAG(p->cap, PEER_CAP_ENHE_RCV)
10106 || CHECK_FLAG(p->cap, PEER_CAP_ENHE_ADV)) {
10107 vty_out(vty, " Extended nexthop:");
10108 if (CHECK_FLAG(p->cap,
10109 PEER_CAP_ENHE_ADV))
10110 vty_out(vty, " advertised");
10111 if (CHECK_FLAG(p->cap,
10112 PEER_CAP_ENHE_RCV))
10113 vty_out(vty, " %sreceived",
10114 CHECK_FLAG(
10115 p->cap,
10116 PEER_CAP_ENHE_ADV)
10117 ? "and "
10118 : "");
10119 vty_out(vty, "\n");
10120
10121 if (CHECK_FLAG(p->cap,
10122 PEER_CAP_ENHE_RCV)) {
10123 vty_out(vty,
10124 " Address families by peer:\n ");
10125 for (safi = SAFI_UNICAST;
10126 safi < SAFI_MAX; safi++)
10127 if (CHECK_FLAG(
10128 p->af_cap
10129 [AFI_IP]
10130 [safi],
10131 PEER_CAP_ENHE_AF_RCV))
10132 vty_out(vty,
10133 " %s\n",
10134 afi_safi_print(
10135 AFI_IP,
10136 safi));
10137 }
10138 }
10139
10140 /* Route Refresh */
10141 if (CHECK_FLAG(p->cap, PEER_CAP_REFRESH_ADV)
10142 || CHECK_FLAG(p->cap,
10143 PEER_CAP_REFRESH_NEW_RCV)
10144 || CHECK_FLAG(p->cap,
10145 PEER_CAP_REFRESH_OLD_RCV)) {
10146 vty_out(vty, " Route refresh:");
10147 if (CHECK_FLAG(p->cap,
10148 PEER_CAP_REFRESH_ADV))
10149 vty_out(vty, " advertised");
10150 if (CHECK_FLAG(p->cap,
10151 PEER_CAP_REFRESH_NEW_RCV)
10152 || CHECK_FLAG(
10153 p->cap,
10154 PEER_CAP_REFRESH_OLD_RCV))
10155 vty_out(vty, " %sreceived(%s)",
10156 CHECK_FLAG(
10157 p->cap,
10158 PEER_CAP_REFRESH_ADV)
10159 ? "and "
10160 : "",
10161 (CHECK_FLAG(
10162 p->cap,
10163 PEER_CAP_REFRESH_OLD_RCV)
10164 && CHECK_FLAG(
10165 p->cap,
10166 PEER_CAP_REFRESH_NEW_RCV))
10167 ? "old & new"
10168 : CHECK_FLAG(
10169 p->cap,
10170 PEER_CAP_REFRESH_OLD_RCV)
10171 ? "old"
10172 : "new");
10173
10174 vty_out(vty, "\n");
10175 }
10176
10177 /* Multiprotocol Extensions */
10178 FOREACH_AFI_SAFI (afi, safi)
10179 if (p->afc_adv[afi][safi]
10180 || p->afc_recv[afi][safi]) {
10181 vty_out(vty,
10182 " Address Family %s:",
10183 afi_safi_print(afi,
10184 safi));
10185 if (p->afc_adv[afi][safi])
10186 vty_out(vty,
10187 " advertised");
10188 if (p->afc_recv[afi][safi])
10189 vty_out(vty,
10190 " %sreceived",
10191 p->afc_adv[afi]
10192 [safi]
10193 ? "and "
10194 : "");
10195 vty_out(vty, "\n");
10196 }
10197
10198 /* Hostname capability */
10199 vty_out(vty, " Hostname Capability:");
10200
10201 if (CHECK_FLAG(p->cap, PEER_CAP_HOSTNAME_ADV)) {
10202 vty_out(vty,
10203 " advertised (name: %s,domain name: %s)",
10204 bgp->peer_self->hostname
10205 ? bgp->peer_self
10206 ->hostname
10207 : "n/a",
10208 bgp->peer_self->domainname
10209 ? bgp->peer_self
10210 ->domainname
10211 : "n/a");
10212 } else {
10213 vty_out(vty, " not advertised");
10214 }
10215
10216 if (CHECK_FLAG(p->cap, PEER_CAP_HOSTNAME_RCV)) {
10217 vty_out(vty,
10218 " received (name: %s,domain name: %s)",
10219 p->hostname ? p->hostname
10220 : "n/a",
10221 p->domainname ? p->domainname
10222 : "n/a");
10223 } else {
10224 vty_out(vty, " not received");
10225 }
10226
10227 vty_out(vty, "\n");
10228
10229 /* Gracefull Restart */
10230 if (CHECK_FLAG(p->cap, PEER_CAP_RESTART_RCV)
10231 || CHECK_FLAG(p->cap,
10232 PEER_CAP_RESTART_ADV)) {
10233 vty_out(vty,
10234 " Graceful Restart Capabilty:");
10235 if (CHECK_FLAG(p->cap,
10236 PEER_CAP_RESTART_ADV))
10237 vty_out(vty, " advertised");
10238 if (CHECK_FLAG(p->cap,
10239 PEER_CAP_RESTART_RCV))
10240 vty_out(vty, " %sreceived",
10241 CHECK_FLAG(
10242 p->cap,
10243 PEER_CAP_RESTART_ADV)
10244 ? "and "
10245 : "");
10246 vty_out(vty, "\n");
10247
10248 if (CHECK_FLAG(p->cap,
10249 PEER_CAP_RESTART_RCV)) {
10250 int restart_af_count = 0;
10251
10252 vty_out(vty,
10253 " Remote Restart timer is %d seconds\n",
10254 p->v_gr_restart);
10255 vty_out(vty,
10256 " Address families by peer:\n ");
10257
10258 FOREACH_AFI_SAFI (afi, safi)
10259 if (CHECK_FLAG(
10260 p->af_cap
10261 [afi]
10262 [safi],
10263 PEER_CAP_RESTART_AF_RCV)) {
10264 vty_out(vty,
10265 "%s%s(%s)",
10266 restart_af_count
10267 ? ", "
10268 : "",
10269 afi_safi_print(
10270 afi,
10271 safi),
10272 CHECK_FLAG(
10273 p->af_cap
10274 [afi]
10275 [safi],
10276 PEER_CAP_RESTART_AF_PRESERVE_RCV)
10277 ? "preserved"
10278 : "not preserved");
10279 restart_af_count++;
10280 }
10281 if (!restart_af_count)
10282 vty_out(vty, "none");
10283 vty_out(vty, "\n");
10284 }
10285 }
10286 }
10287 }
10288 }
10289
10290 /* graceful restart information */
10291 if (CHECK_FLAG(p->cap, PEER_CAP_RESTART_RCV) || p->t_gr_restart
10292 || p->t_gr_stale) {
10293 json_object *json_grace = NULL;
10294 json_object *json_grace_send = NULL;
10295 json_object *json_grace_recv = NULL;
10296 int eor_send_af_count = 0;
10297 int eor_receive_af_count = 0;
10298
10299 if (use_json) {
10300 json_grace = json_object_new_object();
10301 json_grace_send = json_object_new_object();
10302 json_grace_recv = json_object_new_object();
10303
10304 if (p->status == Established) {
10305 FOREACH_AFI_SAFI (afi, safi) {
10306 if (CHECK_FLAG(p->af_sflags[afi][safi],
10307 PEER_STATUS_EOR_SEND)) {
10308 json_object_boolean_true_add(
10309 json_grace_send,
10310 afi_safi_print(afi,
10311 safi));
10312 eor_send_af_count++;
10313 }
10314 }
10315 FOREACH_AFI_SAFI (afi, safi) {
10316 if (CHECK_FLAG(
10317 p->af_sflags[afi][safi],
10318 PEER_STATUS_EOR_RECEIVED)) {
10319 json_object_boolean_true_add(
10320 json_grace_recv,
10321 afi_safi_print(afi,
10322 safi));
10323 eor_receive_af_count++;
10324 }
10325 }
10326 }
10327
10328 json_object_object_add(json_grace, "endOfRibSend",
10329 json_grace_send);
10330 json_object_object_add(json_grace, "endOfRibRecv",
10331 json_grace_recv);
10332
10333 if (p->t_gr_restart)
10334 json_object_int_add(json_grace,
10335 "gracefulRestartTimerMsecs",
10336 thread_timer_remain_second(
10337 p->t_gr_restart)
10338 * 1000);
10339
10340 if (p->t_gr_stale)
10341 json_object_int_add(
10342 json_grace,
10343 "gracefulStalepathTimerMsecs",
10344 thread_timer_remain_second(
10345 p->t_gr_stale)
10346 * 1000);
10347
10348 json_object_object_add(
10349 json_neigh, "gracefulRestartInfo", json_grace);
10350 } else {
10351 vty_out(vty, " Graceful restart information:\n");
10352 if (p->status == Established) {
10353 vty_out(vty, " End-of-RIB send: ");
10354 FOREACH_AFI_SAFI (afi, safi) {
10355 if (CHECK_FLAG(p->af_sflags[afi][safi],
10356 PEER_STATUS_EOR_SEND)) {
10357 vty_out(vty, "%s%s",
10358 eor_send_af_count ? ", "
10359 : "",
10360 afi_safi_print(afi,
10361 safi));
10362 eor_send_af_count++;
10363 }
10364 }
10365 vty_out(vty, "\n");
10366 vty_out(vty, " End-of-RIB received: ");
10367 FOREACH_AFI_SAFI (afi, safi) {
10368 if (CHECK_FLAG(
10369 p->af_sflags[afi][safi],
10370 PEER_STATUS_EOR_RECEIVED)) {
10371 vty_out(vty, "%s%s",
10372 eor_receive_af_count
10373 ? ", "
10374 : "",
10375 afi_safi_print(afi,
10376 safi));
10377 eor_receive_af_count++;
10378 }
10379 }
10380 vty_out(vty, "\n");
10381 }
10382
10383 if (p->t_gr_restart)
10384 vty_out(vty,
10385 " The remaining time of restart timer is %ld\n",
10386 thread_timer_remain_second(
10387 p->t_gr_restart));
10388
10389 if (p->t_gr_stale)
10390 vty_out(vty,
10391 " The remaining time of stalepath timer is %ld\n",
10392 thread_timer_remain_second(
10393 p->t_gr_stale));
10394 }
10395 }
10396 if (use_json) {
10397 json_object *json_stat = NULL;
10398 json_stat = json_object_new_object();
10399 /* Packet counts. */
10400 json_object_int_add(json_stat, "depthInq", 0);
10401 json_object_int_add(json_stat, "depthOutq",
10402 (unsigned long)p->obuf->count);
10403 json_object_int_add(json_stat, "opensSent",
10404 atomic_load_explicit(&p->open_out,
10405 memory_order_relaxed));
10406 json_object_int_add(json_stat, "opensRecv",
10407 atomic_load_explicit(&p->open_in,
10408 memory_order_relaxed));
10409 json_object_int_add(json_stat, "notificationsSent",
10410 atomic_load_explicit(&p->notify_out,
10411 memory_order_relaxed));
10412 json_object_int_add(json_stat, "notificationsRecv",
10413 atomic_load_explicit(&p->notify_in,
10414 memory_order_relaxed));
10415 json_object_int_add(json_stat, "updatesSent",
10416 atomic_load_explicit(&p->update_out,
10417 memory_order_relaxed));
10418 json_object_int_add(json_stat, "updatesRecv",
10419 atomic_load_explicit(&p->update_in,
10420 memory_order_relaxed));
10421 json_object_int_add(json_stat, "keepalivesSent",
10422 atomic_load_explicit(&p->keepalive_out,
10423 memory_order_relaxed));
10424 json_object_int_add(json_stat, "keepalivesRecv",
10425 atomic_load_explicit(&p->keepalive_in,
10426 memory_order_relaxed));
10427 json_object_int_add(json_stat, "routeRefreshSent",
10428 atomic_load_explicit(&p->refresh_out,
10429 memory_order_relaxed));
10430 json_object_int_add(json_stat, "routeRefreshRecv",
10431 atomic_load_explicit(&p->refresh_in,
10432 memory_order_relaxed));
10433 json_object_int_add(json_stat, "capabilitySent",
10434 atomic_load_explicit(&p->dynamic_cap_out,
10435 memory_order_relaxed));
10436 json_object_int_add(json_stat, "capabilityRecv",
10437 atomic_load_explicit(&p->dynamic_cap_in,
10438 memory_order_relaxed));
10439 json_object_int_add(json_stat, "totalSent", PEER_TOTAL_TX(p));
10440 json_object_int_add(json_stat, "totalRecv", PEER_TOTAL_RX(p));
10441 json_object_object_add(json_neigh, "messageStats", json_stat);
10442 } else {
10443 /* Packet counts. */
10444 vty_out(vty, " Message statistics:\n");
10445 vty_out(vty, " Inq depth is 0\n");
10446 vty_out(vty, " Outq depth is %lu\n",
10447 (unsigned long)p->obuf->count);
10448 vty_out(vty, " Sent Rcvd\n");
10449 vty_out(vty, " Opens: %10d %10d\n",
10450 atomic_load_explicit(&p->open_out,
10451 memory_order_relaxed),
10452 atomic_load_explicit(&p->open_in,
10453 memory_order_relaxed));
10454 vty_out(vty, " Notifications: %10d %10d\n",
10455 atomic_load_explicit(&p->notify_out,
10456 memory_order_relaxed),
10457 atomic_load_explicit(&p->notify_in,
10458 memory_order_relaxed));
10459 vty_out(vty, " Updates: %10d %10d\n",
10460 atomic_load_explicit(&p->update_out,
10461 memory_order_relaxed),
10462 atomic_load_explicit(&p->update_in,
10463 memory_order_relaxed));
10464 vty_out(vty, " Keepalives: %10d %10d\n",
10465 atomic_load_explicit(&p->keepalive_out,
10466 memory_order_relaxed),
10467 atomic_load_explicit(&p->keepalive_in,
10468 memory_order_relaxed));
10469 vty_out(vty, " Route Refresh: %10d %10d\n",
10470 atomic_load_explicit(&p->refresh_out,
10471 memory_order_relaxed),
10472 atomic_load_explicit(&p->refresh_in,
10473 memory_order_relaxed));
10474 vty_out(vty, " Capability: %10d %10d\n",
10475 atomic_load_explicit(&p->dynamic_cap_out,
10476 memory_order_relaxed),
10477 atomic_load_explicit(&p->dynamic_cap_in,
10478 memory_order_relaxed));
10479 vty_out(vty, " Total: %10d %10d\n", PEER_TOTAL_TX(p),
10480 PEER_TOTAL_RX(p));
10481 }
10482
10483 if (use_json) {
10484 /* advertisement-interval */
10485 json_object_int_add(json_neigh,
10486 "minBtwnAdvertisementRunsTimerMsecs",
10487 p->v_routeadv * 1000);
10488
10489 /* Update-source. */
10490 if (p->update_if || p->update_source) {
10491 if (p->update_if)
10492 json_object_string_add(json_neigh,
10493 "updateSource",
10494 p->update_if);
10495 else if (p->update_source)
10496 json_object_string_add(
10497 json_neigh, "updateSource",
10498 sockunion2str(p->update_source, buf1,
10499 SU_ADDRSTRLEN));
10500 }
10501 } else {
10502 /* advertisement-interval */
10503 vty_out(vty,
10504 " Minimum time between advertisement runs is %d seconds\n",
10505 p->v_routeadv);
10506
10507 /* Update-source. */
10508 if (p->update_if || p->update_source) {
10509 vty_out(vty, " Update source is ");
10510 if (p->update_if)
10511 vty_out(vty, "%s", p->update_if);
10512 else if (p->update_source)
10513 vty_out(vty, "%s",
10514 sockunion2str(p->update_source, buf1,
10515 SU_ADDRSTRLEN));
10516 vty_out(vty, "\n");
10517 }
10518
10519 vty_out(vty, "\n");
10520 }
10521
10522 /* Address Family Information */
10523 json_object *json_hold = NULL;
10524
10525 if (use_json)
10526 json_hold = json_object_new_object();
10527
10528 FOREACH_AFI_SAFI (afi, safi)
10529 if (p->afc[afi][safi])
10530 bgp_show_peer_afi(vty, p, afi, safi, use_json,
10531 json_hold);
10532
10533 if (use_json) {
10534 json_object_object_add(json_neigh, "addressFamilyInfo",
10535 json_hold);
10536 json_object_int_add(json_neigh, "connectionsEstablished",
10537 p->established);
10538 json_object_int_add(json_neigh, "connectionsDropped",
10539 p->dropped);
10540 } else
10541 vty_out(vty, " Connections established %d; dropped %d\n",
10542 p->established, p->dropped);
10543
10544 if (!p->last_reset) {
10545 if (use_json)
10546 json_object_string_add(json_neigh, "lastReset",
10547 "never");
10548 else
10549 vty_out(vty, " Last reset never\n");
10550 } else {
10551 if (use_json) {
10552 time_t uptime;
10553 struct tm *tm;
10554
10555 uptime = bgp_clock();
10556 uptime -= p->resettime;
10557 tm = gmtime(&uptime);
10558 json_object_int_add(json_neigh, "lastResetTimerMsecs",
10559 (tm->tm_sec * 1000)
10560 + (tm->tm_min * 60000)
10561 + (tm->tm_hour * 3600000));
10562 json_object_string_add(
10563 json_neigh, "lastResetDueTo",
10564 peer_down_str[(int)p->last_reset]);
10565 if (p->last_reset == PEER_DOWN_NOTIFY_SEND
10566 || p->last_reset == PEER_DOWN_NOTIFY_RECEIVED) {
10567 char errorcodesubcode_hexstr[5];
10568 char errorcodesubcode_str[256];
10569
10570 code_str = bgp_notify_code_str(p->notify.code);
10571 subcode_str = bgp_notify_subcode_str(
10572 p->notify.code, p->notify.subcode);
10573
10574 sprintf(errorcodesubcode_hexstr, "%02X%02X",
10575 p->notify.code, p->notify.subcode);
10576 json_object_string_add(json_neigh,
10577 "lastErrorCodeSubcode",
10578 errorcodesubcode_hexstr);
10579 snprintf(errorcodesubcode_str, 255, "%s%s",
10580 code_str, subcode_str);
10581 json_object_string_add(json_neigh,
10582 "lastNotificationReason",
10583 errorcodesubcode_str);
10584 if (p->last_reset == PEER_DOWN_NOTIFY_RECEIVED
10585 && p->notify.code == BGP_NOTIFY_CEASE
10586 && (p->notify.subcode
10587 == BGP_NOTIFY_CEASE_ADMIN_SHUTDOWN
10588 || p->notify.subcode
10589 == BGP_NOTIFY_CEASE_ADMIN_RESET)
10590 && p->notify.length) {
10591 char msgbuf[1024];
10592 const char *msg_str;
10593
10594 msg_str = bgp_notify_admin_message(
10595 msgbuf, sizeof(msgbuf),
10596 (uint8_t *)p->notify.data,
10597 p->notify.length);
10598 if (msg_str)
10599 json_object_string_add(
10600 json_neigh,
10601 "lastShutdownDescription",
10602 msg_str);
10603 }
10604 }
10605 } else {
10606 vty_out(vty, " Last reset %s, ",
10607 peer_uptime(p->resettime, timebuf,
10608 BGP_UPTIME_LEN, 0, NULL));
10609
10610 if (p->last_reset == PEER_DOWN_NOTIFY_SEND
10611 || p->last_reset == PEER_DOWN_NOTIFY_RECEIVED) {
10612 code_str = bgp_notify_code_str(p->notify.code);
10613 subcode_str = bgp_notify_subcode_str(
10614 p->notify.code, p->notify.subcode);
10615 vty_out(vty, "due to NOTIFICATION %s (%s%s)\n",
10616 p->last_reset == PEER_DOWN_NOTIFY_SEND
10617 ? "sent"
10618 : "received",
10619 code_str, subcode_str);
10620 if (p->last_reset == PEER_DOWN_NOTIFY_RECEIVED
10621 && p->notify.code == BGP_NOTIFY_CEASE
10622 && (p->notify.subcode
10623 == BGP_NOTIFY_CEASE_ADMIN_SHUTDOWN
10624 || p->notify.subcode
10625 == BGP_NOTIFY_CEASE_ADMIN_RESET)
10626 && p->notify.length) {
10627 char msgbuf[1024];
10628 const char *msg_str;
10629
10630 msg_str = bgp_notify_admin_message(
10631 msgbuf, sizeof(msgbuf),
10632 (uint8_t *)p->notify.data,
10633 p->notify.length);
10634 if (msg_str)
10635 vty_out(vty,
10636 " Message: \"%s\"\n",
10637 msg_str);
10638 }
10639 } else {
10640 vty_out(vty, "due to %s\n",
10641 peer_down_str[(int)p->last_reset]);
10642 }
10643
10644 if (p->last_reset_cause_size) {
10645 msg = p->last_reset_cause;
10646 vty_out(vty,
10647 " Message received that caused BGP to send a NOTIFICATION:\n ");
10648 for (i = 1; i <= p->last_reset_cause_size;
10649 i++) {
10650 vty_out(vty, "%02X", *msg++);
10651
10652 if (i != p->last_reset_cause_size) {
10653 if (i % 16 == 0) {
10654 vty_out(vty, "\n ");
10655 } else if (i % 4 == 0) {
10656 vty_out(vty, " ");
10657 }
10658 }
10659 }
10660 vty_out(vty, "\n");
10661 }
10662 }
10663 }
10664
10665 if (CHECK_FLAG(p->sflags, PEER_STATUS_PREFIX_OVERFLOW)) {
10666 if (use_json)
10667 json_object_boolean_true_add(json_neigh,
10668 "prefixesConfigExceedMax");
10669 else
10670 vty_out(vty,
10671 " Peer had exceeded the max. no. of prefixes configured.\n");
10672
10673 if (p->t_pmax_restart) {
10674 if (use_json) {
10675 json_object_boolean_true_add(
10676 json_neigh, "reducePrefixNumFrom");
10677 json_object_int_add(json_neigh,
10678 "restartInTimerMsec",
10679 thread_timer_remain_second(
10680 p->t_pmax_restart)
10681 * 1000);
10682 } else
10683 vty_out(vty,
10684 " Reduce the no. of prefix from %s, will restart in %ld seconds\n",
10685 p->host, thread_timer_remain_second(
10686 p->t_pmax_restart));
10687 } else {
10688 if (use_json)
10689 json_object_boolean_true_add(
10690 json_neigh,
10691 "reducePrefixNumAndClearIpBgp");
10692 else
10693 vty_out(vty,
10694 " Reduce the no. of prefix and clear ip bgp %s to restore peering\n",
10695 p->host);
10696 }
10697 }
10698
10699 /* EBGP Multihop and GTSM */
10700 if (p->sort != BGP_PEER_IBGP) {
10701 if (use_json) {
10702 if (p->gtsm_hops > 0)
10703 json_object_int_add(json_neigh,
10704 "externalBgpNbrMaxHopsAway",
10705 p->gtsm_hops);
10706 else if (p->ttl > 1)
10707 json_object_int_add(json_neigh,
10708 "externalBgpNbrMaxHopsAway",
10709 p->ttl);
10710 } else {
10711 if (p->gtsm_hops > 0)
10712 vty_out(vty,
10713 " External BGP neighbor may be up to %d hops away.\n",
10714 p->gtsm_hops);
10715 else if (p->ttl > 1)
10716 vty_out(vty,
10717 " External BGP neighbor may be up to %d hops away.\n",
10718 p->ttl);
10719 }
10720 } else {
10721 if (p->gtsm_hops > 0) {
10722 if (use_json)
10723 json_object_int_add(json_neigh,
10724 "internalBgpNbrMaxHopsAway",
10725 p->gtsm_hops);
10726 else
10727 vty_out(vty,
10728 " Internal BGP neighbor may be up to %d hops away.\n",
10729 p->gtsm_hops);
10730 }
10731 }
10732
10733 /* Local address. */
10734 if (p->su_local) {
10735 if (use_json) {
10736 json_object_string_add(json_neigh, "hostLocal",
10737 sockunion2str(p->su_local, buf1,
10738 SU_ADDRSTRLEN));
10739 json_object_int_add(json_neigh, "portLocal",
10740 ntohs(p->su_local->sin.sin_port));
10741 } else
10742 vty_out(vty, "Local host: %s, Local port: %d\n",
10743 sockunion2str(p->su_local, buf1, SU_ADDRSTRLEN),
10744 ntohs(p->su_local->sin.sin_port));
10745 }
10746
10747 /* Remote address. */
10748 if (p->su_remote) {
10749 if (use_json) {
10750 json_object_string_add(json_neigh, "hostForeign",
10751 sockunion2str(p->su_remote, buf1,
10752 SU_ADDRSTRLEN));
10753 json_object_int_add(json_neigh, "portForeign",
10754 ntohs(p->su_remote->sin.sin_port));
10755 } else
10756 vty_out(vty, "Foreign host: %s, Foreign port: %d\n",
10757 sockunion2str(p->su_remote, buf1,
10758 SU_ADDRSTRLEN),
10759 ntohs(p->su_remote->sin.sin_port));
10760 }
10761
10762 /* Nexthop display. */
10763 if (p->su_local) {
10764 if (use_json) {
10765 json_object_string_add(json_neigh, "nexthop",
10766 inet_ntop(AF_INET,
10767 &p->nexthop.v4, buf1,
10768 sizeof(buf1)));
10769 json_object_string_add(json_neigh, "nexthopGlobal",
10770 inet_ntop(AF_INET6,
10771 &p->nexthop.v6_global,
10772 buf1, sizeof(buf1)));
10773 json_object_string_add(json_neigh, "nexthopLocal",
10774 inet_ntop(AF_INET6,
10775 &p->nexthop.v6_local,
10776 buf1, sizeof(buf1)));
10777 if (p->shared_network)
10778 json_object_string_add(json_neigh,
10779 "bgpConnection",
10780 "sharedNetwork");
10781 else
10782 json_object_string_add(json_neigh,
10783 "bgpConnection",
10784 "nonSharedNetwork");
10785 } else {
10786 vty_out(vty, "Nexthop: %s\n",
10787 inet_ntop(AF_INET, &p->nexthop.v4, buf1,
10788 sizeof(buf1)));
10789 vty_out(vty, "Nexthop global: %s\n",
10790 inet_ntop(AF_INET6, &p->nexthop.v6_global, buf1,
10791 sizeof(buf1)));
10792 vty_out(vty, "Nexthop local: %s\n",
10793 inet_ntop(AF_INET6, &p->nexthop.v6_local, buf1,
10794 sizeof(buf1)));
10795 vty_out(vty, "BGP connection: %s\n",
10796 p->shared_network ? "shared network"
10797 : "non shared network");
10798 }
10799 }
10800
10801 /* Timer information. */
10802 if (use_json) {
10803 json_object_int_add(json_neigh, "connectRetryTimer",
10804 p->v_connect);
10805 if (p->status == Established && p->rtt)
10806 json_object_int_add(json_neigh, "estimatedRttInMsecs",
10807 p->rtt);
10808 if (p->t_start)
10809 json_object_int_add(
10810 json_neigh, "nextStartTimerDueInMsecs",
10811 thread_timer_remain_second(p->t_start) * 1000);
10812 if (p->t_connect)
10813 json_object_int_add(
10814 json_neigh, "nextConnectTimerDueInMsecs",
10815 thread_timer_remain_second(p->t_connect)
10816 * 1000);
10817 if (p->t_routeadv) {
10818 json_object_int_add(json_neigh, "mraiInterval",
10819 p->v_routeadv);
10820 json_object_int_add(
10821 json_neigh, "mraiTimerExpireInMsecs",
10822 thread_timer_remain_second(p->t_routeadv)
10823 * 1000);
10824 }
10825 if (p->password)
10826 json_object_int_add(json_neigh, "authenticationEnabled",
10827 1);
10828
10829 if (p->t_read)
10830 json_object_string_add(json_neigh, "readThread", "on");
10831 else
10832 json_object_string_add(json_neigh, "readThread", "off");
10833
10834 if (CHECK_FLAG(p->thread_flags, PEER_THREAD_WRITES_ON))
10835 json_object_string_add(json_neigh, "writeThread", "on");
10836 else
10837 json_object_string_add(json_neigh, "writeThread",
10838 "off");
10839 } else {
10840 vty_out(vty, "BGP Connect Retry Timer in Seconds: %d\n",
10841 p->v_connect);
10842 if (p->status == Established && p->rtt)
10843 vty_out(vty, "Estimated round trip time: %d ms\n",
10844 p->rtt);
10845 if (p->t_start)
10846 vty_out(vty, "Next start timer due in %ld seconds\n",
10847 thread_timer_remain_second(p->t_start));
10848 if (p->t_connect)
10849 vty_out(vty, "Next connect timer due in %ld seconds\n",
10850 thread_timer_remain_second(p->t_connect));
10851 if (p->t_routeadv)
10852 vty_out(vty,
10853 "MRAI (interval %u) timer expires in %ld seconds\n",
10854 p->v_routeadv,
10855 thread_timer_remain_second(p->t_routeadv));
10856 if (p->password)
10857 vty_out(vty, "Peer Authentication Enabled\n");
10858
10859 vty_out(vty, "Read thread: %s Write thread: %s FD used: %d\n",
10860 p->t_read ? "on" : "off",
10861 CHECK_FLAG(p->thread_flags, PEER_THREAD_WRITES_ON)
10862 ? "on"
10863 : "off", p->fd);
10864 }
10865
10866 if (p->notify.code == BGP_NOTIFY_OPEN_ERR
10867 && p->notify.subcode == BGP_NOTIFY_OPEN_UNSUP_CAPBL)
10868 bgp_capability_vty_out(vty, p, use_json, json_neigh);
10869
10870 if (!use_json)
10871 vty_out(vty, "\n");
10872
10873 /* BFD information. */
10874 bgp_bfd_show_info(vty, p, use_json, json_neigh);
10875
10876 if (use_json) {
10877 if (p->conf_if) /* Configured interface name. */
10878 json_object_object_add(json, p->conf_if, json_neigh);
10879 else /* Configured IP address. */
10880 json_object_object_add(json, p->host, json_neigh);
10881 }
10882 }
10883
10884 static int bgp_show_neighbor(struct vty *vty, struct bgp *bgp,
10885 enum show_type type, union sockunion *su,
10886 const char *conf_if, bool use_json,
10887 json_object *json)
10888 {
10889 struct listnode *node, *nnode;
10890 struct peer *peer;
10891 int find = 0;
10892 bool nbr_output = false;
10893 afi_t afi = AFI_MAX;
10894 safi_t safi = SAFI_MAX;
10895
10896 if (type == show_ipv4_peer || type == show_ipv4_all) {
10897 afi = AFI_IP;
10898 } else if (type == show_ipv6_peer || type == show_ipv6_all) {
10899 afi = AFI_IP6;
10900 }
10901
10902 for (ALL_LIST_ELEMENTS(bgp->peer, node, nnode, peer)) {
10903 if (!CHECK_FLAG(peer->flags, PEER_FLAG_CONFIG_NODE))
10904 continue;
10905
10906 switch (type) {
10907 case show_all:
10908 bgp_show_peer(vty, peer, use_json, json);
10909 nbr_output = true;
10910 break;
10911 case show_peer:
10912 if (conf_if) {
10913 if ((peer->conf_if
10914 && !strcmp(peer->conf_if, conf_if))
10915 || (peer->hostname
10916 && !strcmp(peer->hostname, conf_if))) {
10917 find = 1;
10918 bgp_show_peer(vty, peer, use_json,
10919 json);
10920 }
10921 } else {
10922 if (sockunion_same(&peer->su, su)) {
10923 find = 1;
10924 bgp_show_peer(vty, peer, use_json,
10925 json);
10926 }
10927 }
10928 break;
10929 case show_ipv4_peer:
10930 case show_ipv6_peer:
10931 FOREACH_SAFI (safi) {
10932 if (peer->afc[afi][safi]) {
10933 if (conf_if) {
10934 if ((peer->conf_if
10935 && !strcmp(peer->conf_if, conf_if))
10936 || (peer->hostname
10937 && !strcmp(peer->hostname, conf_if))) {
10938 find = 1;
10939 bgp_show_peer(vty, peer, use_json,
10940 json);
10941 break;
10942 }
10943 } else {
10944 if (sockunion_same(&peer->su, su)) {
10945 find = 1;
10946 bgp_show_peer(vty, peer, use_json,
10947 json);
10948 break;
10949 }
10950 }
10951 }
10952 }
10953 break;
10954 case show_ipv4_all:
10955 case show_ipv6_all:
10956 FOREACH_SAFI (safi) {
10957 if (peer->afc[afi][safi]) {
10958 bgp_show_peer(vty, peer, use_json, json);
10959 nbr_output = true;
10960 break;
10961 }
10962 }
10963 break;
10964 }
10965 }
10966
10967 if ((type == show_peer || type == show_ipv4_peer ||
10968 type == show_ipv6_peer) && !find) {
10969 if (use_json)
10970 json_object_boolean_true_add(json, "bgpNoSuchNeighbor");
10971 else
10972 vty_out(vty, "%% No such neighbor in this view/vrf\n");
10973 }
10974
10975 if (type != show_peer && type != show_ipv4_peer &&
10976 type != show_ipv6_peer && !nbr_output && !use_json)
10977 vty_out(vty, "%% No BGP neighbors found\n");
10978
10979 if (use_json) {
10980 vty_out(vty, "%s\n", json_object_to_json_string_ext(
10981 json, JSON_C_TO_STRING_PRETTY));
10982 } else {
10983 vty_out(vty, "\n");
10984 }
10985
10986 return CMD_SUCCESS;
10987 }
10988
10989 static void bgp_show_all_instances_neighbors_vty(struct vty *vty,
10990 enum show_type type,
10991 const char *ip_str,
10992 bool use_json)
10993 {
10994 struct listnode *node, *nnode;
10995 struct bgp *bgp;
10996 union sockunion su;
10997 json_object *json = NULL;
10998 int ret, is_first = 1;
10999 bool nbr_output = false;
11000
11001 if (use_json)
11002 vty_out(vty, "{\n");
11003
11004 for (ALL_LIST_ELEMENTS(bm->bgp, node, nnode, bgp)) {
11005 nbr_output = true;
11006 if (use_json) {
11007 if (!(json = json_object_new_object())) {
11008 flog_err(
11009 EC_BGP_JSON_MEM_ERROR,
11010 "Unable to allocate memory for JSON object");
11011 vty_out(vty,
11012 "{\"error\": {\"message:\": \"Unable to allocate memory for JSON object\"}}}\n");
11013 return;
11014 }
11015
11016 json_object_int_add(json, "vrfId",
11017 (bgp->vrf_id == VRF_UNKNOWN)
11018 ? -1
11019 : (int64_t)bgp->vrf_id);
11020 json_object_string_add(
11021 json, "vrfName",
11022 (bgp->inst_type == BGP_INSTANCE_TYPE_DEFAULT)
11023 ? VRF_DEFAULT_NAME
11024 : bgp->name);
11025
11026 if (!is_first)
11027 vty_out(vty, ",\n");
11028 else
11029 is_first = 0;
11030
11031 vty_out(vty, "\"%s\":",
11032 (bgp->inst_type == BGP_INSTANCE_TYPE_DEFAULT)
11033 ? VRF_DEFAULT_NAME
11034 : bgp->name);
11035 } else {
11036 vty_out(vty, "\nInstance %s:\n",
11037 (bgp->inst_type == BGP_INSTANCE_TYPE_DEFAULT)
11038 ? VRF_DEFAULT_NAME
11039 : bgp->name);
11040 }
11041
11042 if (type == show_peer || type == show_ipv4_peer ||
11043 type == show_ipv6_peer) {
11044 ret = str2sockunion(ip_str, &su);
11045 if (ret < 0)
11046 bgp_show_neighbor(vty, bgp, type, NULL, ip_str,
11047 use_json, json);
11048 else
11049 bgp_show_neighbor(vty, bgp, type, &su, NULL,
11050 use_json, json);
11051 } else {
11052 bgp_show_neighbor(vty, bgp, type, NULL, NULL,
11053 use_json, json);
11054 }
11055 json_object_free(json);
11056 }
11057
11058 if (use_json) {
11059 vty_out(vty, "}\n");
11060 json_object_free(json);
11061 }
11062 else if (!nbr_output)
11063 vty_out(vty, "%% BGP instance not found\n");
11064 }
11065
11066 static int bgp_show_neighbor_vty(struct vty *vty, const char *name,
11067 enum show_type type, const char *ip_str,
11068 bool use_json)
11069 {
11070 int ret;
11071 struct bgp *bgp;
11072 union sockunion su;
11073 json_object *json = NULL;
11074
11075 if (name) {
11076 if (strmatch(name, "all")) {
11077 bgp_show_all_instances_neighbors_vty(vty, type, ip_str,
11078 use_json);
11079 return CMD_SUCCESS;
11080 } else {
11081 bgp = bgp_lookup_by_name(name);
11082 if (!bgp) {
11083 if (use_json) {
11084 json = json_object_new_object();
11085 vty_out(vty, "%s\n",
11086 json_object_to_json_string_ext(
11087 json,
11088 JSON_C_TO_STRING_PRETTY));
11089 json_object_free(json);
11090 } else
11091 vty_out(vty,
11092 "%% BGP instance not found\n");
11093
11094 return CMD_WARNING;
11095 }
11096 }
11097 } else {
11098 bgp = bgp_get_default();
11099 }
11100
11101 if (bgp) {
11102 json = json_object_new_object();
11103 if (ip_str) {
11104 ret = str2sockunion(ip_str, &su);
11105 if (ret < 0)
11106 bgp_show_neighbor(vty, bgp, type, NULL, ip_str,
11107 use_json, json);
11108 else
11109 bgp_show_neighbor(vty, bgp, type, &su, NULL,
11110 use_json, json);
11111 } else {
11112 bgp_show_neighbor(vty, bgp, type, NULL, NULL, use_json,
11113 json);
11114 }
11115 json_object_free(json);
11116 } else {
11117 if (use_json)
11118 vty_out(vty, "{}\n");
11119 else
11120 vty_out(vty, "%% BGP instance not found\n");
11121 }
11122
11123 return CMD_SUCCESS;
11124 }
11125
11126 /* "show [ip] bgp neighbors" commands. */
11127 DEFUN (show_ip_bgp_neighbors,
11128 show_ip_bgp_neighbors_cmd,
11129 "show [ip] bgp [<view|vrf> VIEWVRFNAME] [<ipv4|ipv6>] neighbors [<A.B.C.D|X:X::X:X|WORD>] [json]",
11130 SHOW_STR
11131 IP_STR
11132 BGP_STR
11133 BGP_INSTANCE_HELP_STR
11134 "Address Family\n"
11135 "Address Family\n"
11136 "Detailed information on TCP and BGP neighbor connections\n"
11137 "Neighbor to display information about\n"
11138 "Neighbor to display information about\n"
11139 "Neighbor on BGP configured interface\n"
11140 JSON_STR)
11141 {
11142 char *vrf = NULL;
11143 char *sh_arg = NULL;
11144 enum show_type sh_type;
11145 afi_t afi = AFI_MAX;
11146
11147 bool uj = use_json(argc, argv);
11148
11149 int idx = 0;
11150
11151 /* [<vrf> VIEWVRFNAME] */
11152 if (argv_find(argv, argc, "vrf", &idx)) {
11153 vrf = argv[idx + 1]->arg;
11154 if (vrf && strmatch(vrf, VRF_DEFAULT_NAME))
11155 vrf = NULL;
11156 } else if (argv_find(argv, argc, "view", &idx))
11157 /* [<view> VIEWVRFNAME] */
11158 vrf = argv[idx + 1]->arg;
11159
11160 idx++;
11161
11162 if (argv_find(argv, argc, "ipv4", &idx)) {
11163 sh_type = show_ipv4_all;
11164 afi = AFI_IP;
11165 } else if (argv_find(argv, argc, "ipv6", &idx)) {
11166 sh_type = show_ipv6_all;
11167 afi = AFI_IP6;
11168 } else {
11169 sh_type = show_all;
11170 }
11171
11172 if (argv_find(argv, argc, "A.B.C.D", &idx)
11173 || argv_find(argv, argc, "X:X::X:X", &idx)
11174 || argv_find(argv, argc, "WORD", &idx)) {
11175 sh_type = show_peer;
11176 sh_arg = argv[idx]->arg;
11177 }
11178
11179 if (sh_type == show_peer && afi == AFI_IP) {
11180 sh_type = show_ipv4_peer;
11181 } else if (sh_type == show_peer && afi == AFI_IP6) {
11182 sh_type = show_ipv6_peer;
11183 }
11184
11185 return bgp_show_neighbor_vty(vty, vrf, sh_type, sh_arg, uj);
11186 }
11187
11188 /* Show BGP's AS paths internal data. There are both `show [ip] bgp
11189 paths' and `show ip mbgp paths'. Those functions results are the
11190 same.*/
11191 DEFUN (show_ip_bgp_paths,
11192 show_ip_bgp_paths_cmd,
11193 "show [ip] bgp ["BGP_SAFI_CMD_STR"] paths",
11194 SHOW_STR
11195 IP_STR
11196 BGP_STR
11197 BGP_SAFI_HELP_STR
11198 "Path information\n")
11199 {
11200 vty_out(vty, "Address Refcnt Path\n");
11201 aspath_print_all_vty(vty);
11202 return CMD_SUCCESS;
11203 }
11204
11205 #include "hash.h"
11206
11207 static void community_show_all_iterator(struct hash_bucket *bucket,
11208 struct vty *vty)
11209 {
11210 struct community *com;
11211
11212 com = (struct community *)bucket->data;
11213 vty_out(vty, "[%p] (%ld) %s\n", (void *)com, com->refcnt,
11214 community_str(com, false));
11215 }
11216
11217 /* Show BGP's community internal data. */
11218 DEFUN (show_ip_bgp_community_info,
11219 show_ip_bgp_community_info_cmd,
11220 "show [ip] bgp community-info",
11221 SHOW_STR
11222 IP_STR
11223 BGP_STR
11224 "List all bgp community information\n")
11225 {
11226 vty_out(vty, "Address Refcnt Community\n");
11227
11228 hash_iterate(community_hash(),
11229 (void (*)(struct hash_bucket *,
11230 void *))community_show_all_iterator,
11231 vty);
11232
11233 return CMD_SUCCESS;
11234 }
11235
11236 static void lcommunity_show_all_iterator(struct hash_bucket *bucket,
11237 struct vty *vty)
11238 {
11239 struct lcommunity *lcom;
11240
11241 lcom = (struct lcommunity *)bucket->data;
11242 vty_out(vty, "[%p] (%ld) %s\n", (void *)lcom, lcom->refcnt,
11243 lcommunity_str(lcom, false));
11244 }
11245
11246 /* Show BGP's community internal data. */
11247 DEFUN (show_ip_bgp_lcommunity_info,
11248 show_ip_bgp_lcommunity_info_cmd,
11249 "show ip bgp large-community-info",
11250 SHOW_STR
11251 IP_STR
11252 BGP_STR
11253 "List all bgp large-community information\n")
11254 {
11255 vty_out(vty, "Address Refcnt Large-community\n");
11256
11257 hash_iterate(lcommunity_hash(),
11258 (void (*)(struct hash_bucket *,
11259 void *))lcommunity_show_all_iterator,
11260 vty);
11261
11262 return CMD_SUCCESS;
11263 }
11264
11265
11266 DEFUN (show_ip_bgp_attr_info,
11267 show_ip_bgp_attr_info_cmd,
11268 "show [ip] bgp attribute-info",
11269 SHOW_STR
11270 IP_STR
11271 BGP_STR
11272 "List all bgp attribute information\n")
11273 {
11274 attr_show_all(vty);
11275 return CMD_SUCCESS;
11276 }
11277
11278 static int bgp_show_route_leak_vty(struct vty *vty, const char *name,
11279 afi_t afi, safi_t safi,
11280 bool use_json, json_object *json)
11281 {
11282 struct bgp *bgp;
11283 struct listnode *node;
11284 char *vname;
11285 char buf1[INET6_ADDRSTRLEN];
11286 char *ecom_str;
11287 vpn_policy_direction_t dir;
11288
11289 if (json) {
11290 json_object *json_import_vrfs = NULL;
11291 json_object *json_export_vrfs = NULL;
11292
11293 bgp = name ? bgp_lookup_by_name(name) : bgp_get_default();
11294
11295 if (!bgp) {
11296 vty_out(vty, "%s\n",
11297 json_object_to_json_string_ext(
11298 json,
11299 JSON_C_TO_STRING_PRETTY));
11300 json_object_free(json);
11301
11302 return CMD_WARNING;
11303 }
11304
11305 /* Provide context for the block */
11306 json_object_string_add(json, "vrf", name ? name : "default");
11307 json_object_string_add(json, "afiSafi",
11308 afi_safi_print(afi, safi));
11309
11310 if (!CHECK_FLAG(bgp->af_flags[afi][safi],
11311 BGP_CONFIG_VRF_TO_VRF_IMPORT)) {
11312 json_object_string_add(json, "importFromVrfs", "none");
11313 json_object_string_add(json, "importRts", "none");
11314 } else {
11315 json_import_vrfs = json_object_new_array();
11316
11317 for (ALL_LIST_ELEMENTS_RO(
11318 bgp->vpn_policy[afi].import_vrf,
11319 node, vname))
11320 json_object_array_add(json_import_vrfs,
11321 json_object_new_string(vname));
11322
11323 dir = BGP_VPN_POLICY_DIR_FROMVPN;
11324 ecom_str = ecommunity_ecom2str(
11325 bgp->vpn_policy[afi].rtlist[dir],
11326 ECOMMUNITY_FORMAT_ROUTE_MAP, 0);
11327 json_object_object_add(json, "importFromVrfs",
11328 json_import_vrfs);
11329 json_object_string_add(json, "importRts", ecom_str);
11330
11331 XFREE(MTYPE_ECOMMUNITY_STR, ecom_str);
11332 }
11333
11334 if (!CHECK_FLAG(bgp->af_flags[afi][safi],
11335 BGP_CONFIG_VRF_TO_VRF_EXPORT)) {
11336 json_object_string_add(json, "exportToVrfs", "none");
11337 json_object_string_add(json, "routeDistinguisher",
11338 "none");
11339 json_object_string_add(json, "exportRts", "none");
11340 } else {
11341 json_export_vrfs = json_object_new_array();
11342
11343 for (ALL_LIST_ELEMENTS_RO(
11344 bgp->vpn_policy[afi].export_vrf,
11345 node, vname))
11346 json_object_array_add(json_export_vrfs,
11347 json_object_new_string(vname));
11348 json_object_object_add(json, "exportToVrfs",
11349 json_export_vrfs);
11350 json_object_string_add(json, "routeDistinguisher",
11351 prefix_rd2str(&bgp->vpn_policy[afi].tovpn_rd,
11352 buf1, RD_ADDRSTRLEN));
11353
11354 dir = BGP_VPN_POLICY_DIR_TOVPN;
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", ecom_str);
11359
11360 XFREE(MTYPE_ECOMMUNITY_STR, ecom_str);
11361 }
11362
11363 if (use_json) {
11364 vty_out(vty, "%s\n",
11365 json_object_to_json_string_ext(json,
11366 JSON_C_TO_STRING_PRETTY));
11367 json_object_free(json);
11368 }
11369 } else {
11370 bgp = name ? bgp_lookup_by_name(name) : bgp_get_default();
11371
11372 if (!bgp) {
11373 vty_out(vty, "%% No such BGP instance exist\n");
11374 return CMD_WARNING;
11375 }
11376
11377 if (!CHECK_FLAG(bgp->af_flags[afi][safi],
11378 BGP_CONFIG_VRF_TO_VRF_IMPORT))
11379 vty_out(vty,
11380 "This VRF is not importing %s routes from any other VRF\n",
11381 afi_safi_print(afi, safi));
11382 else {
11383 vty_out(vty,
11384 "This VRF is importing %s routes from the following VRFs:\n",
11385 afi_safi_print(afi, safi));
11386
11387 for (ALL_LIST_ELEMENTS_RO(
11388 bgp->vpn_policy[afi].import_vrf,
11389 node, vname))
11390 vty_out(vty, " %s\n", vname);
11391
11392 dir = BGP_VPN_POLICY_DIR_FROMVPN;
11393 ecom_str = ecommunity_ecom2str(
11394 bgp->vpn_policy[afi].rtlist[dir],
11395 ECOMMUNITY_FORMAT_ROUTE_MAP, 0);
11396 vty_out(vty, "Import RT(s): %s\n", ecom_str);
11397
11398 XFREE(MTYPE_ECOMMUNITY_STR, ecom_str);
11399 }
11400
11401 if (!CHECK_FLAG(bgp->af_flags[afi][safi],
11402 BGP_CONFIG_VRF_TO_VRF_EXPORT))
11403 vty_out(vty,
11404 "This VRF is not exporting %s routes to any other VRF\n",
11405 afi_safi_print(afi, safi));
11406 else {
11407 vty_out(vty,
11408 "This VRF is exporting %s routes to the following VRFs:\n",
11409 afi_safi_print(afi, safi));
11410
11411 for (ALL_LIST_ELEMENTS_RO(
11412 bgp->vpn_policy[afi].export_vrf,
11413 node, vname))
11414 vty_out(vty, " %s\n", vname);
11415
11416 vty_out(vty, "RD: %s\n",
11417 prefix_rd2str(&bgp->vpn_policy[afi].tovpn_rd,
11418 buf1, RD_ADDRSTRLEN));
11419
11420 dir = BGP_VPN_POLICY_DIR_TOVPN;
11421 ecom_str = ecommunity_ecom2str(
11422 bgp->vpn_policy[afi].rtlist[dir],
11423 ECOMMUNITY_FORMAT_ROUTE_MAP, 0);
11424 vty_out(vty, "Export RT: %s\n", ecom_str);
11425 XFREE(MTYPE_ECOMMUNITY_STR, ecom_str);
11426 }
11427 }
11428
11429 return CMD_SUCCESS;
11430 }
11431
11432 static int bgp_show_all_instance_route_leak_vty(struct vty *vty, afi_t afi,
11433 safi_t safi, bool use_json)
11434 {
11435 struct listnode *node, *nnode;
11436 struct bgp *bgp;
11437 char *vrf_name = NULL;
11438 json_object *json = NULL;
11439 json_object *json_vrf = NULL;
11440 json_object *json_vrfs = NULL;
11441
11442 if (use_json) {
11443 json = json_object_new_object();
11444 json_vrfs = json_object_new_object();
11445 }
11446
11447 for (ALL_LIST_ELEMENTS(bm->bgp, node, nnode, bgp)) {
11448
11449 if (bgp->inst_type != BGP_INSTANCE_TYPE_DEFAULT)
11450 vrf_name = bgp->name;
11451
11452 if (use_json) {
11453 json_vrf = json_object_new_object();
11454 } else {
11455 vty_out(vty, "\nInstance %s:\n",
11456 (bgp->inst_type == BGP_INSTANCE_TYPE_DEFAULT)
11457 ? VRF_DEFAULT_NAME : bgp->name);
11458 }
11459 bgp_show_route_leak_vty(vty, vrf_name, afi, safi, 0, json_vrf);
11460 if (use_json) {
11461 if (bgp->inst_type == BGP_INSTANCE_TYPE_DEFAULT)
11462 json_object_object_add(json_vrfs,
11463 VRF_DEFAULT_NAME, json_vrf);
11464 else
11465 json_object_object_add(json_vrfs, vrf_name,
11466 json_vrf);
11467 }
11468 }
11469
11470 if (use_json) {
11471 json_object_object_add(json, "vrfs", json_vrfs);
11472 vty_out(vty, "%s\n", json_object_to_json_string_ext(json,
11473 JSON_C_TO_STRING_PRETTY));
11474 json_object_free(json);
11475 }
11476
11477 return CMD_SUCCESS;
11478 }
11479
11480 /* "show [ip] bgp route-leak" command. */
11481 DEFUN (show_ip_bgp_route_leak,
11482 show_ip_bgp_route_leak_cmd,
11483 "show [ip] bgp [<view|vrf> VIEWVRFNAME] ["BGP_AFI_CMD_STR" ["BGP_SAFI_CMD_STR"]] route-leak [json]",
11484 SHOW_STR
11485 IP_STR
11486 BGP_STR
11487 BGP_INSTANCE_HELP_STR
11488 BGP_AFI_HELP_STR
11489 BGP_SAFI_HELP_STR
11490 "Route leaking information\n"
11491 JSON_STR)
11492 {
11493 char *vrf = NULL;
11494 afi_t afi = AFI_MAX;
11495 safi_t safi = SAFI_MAX;
11496
11497 bool uj = use_json(argc, argv);
11498 int idx = 0;
11499 json_object *json = NULL;
11500
11501 /* show [ip] bgp */
11502 if (argv_find(argv, argc, "ip", &idx)) {
11503 afi = AFI_IP;
11504 safi = SAFI_UNICAST;
11505 }
11506 /* [vrf VIEWVRFNAME] */
11507 if (argv_find(argv, argc, "view", &idx)) {
11508 vty_out(vty,
11509 "%% This command is not applicable to BGP views\n");
11510 return CMD_WARNING;
11511 }
11512
11513 if (argv_find(argv, argc, "vrf", &idx)) {
11514 vrf = argv[idx + 1]->arg;
11515 if (vrf && strmatch(vrf, VRF_DEFAULT_NAME))
11516 vrf = NULL;
11517 }
11518 /* ["BGP_AFI_CMD_STR" ["BGP_SAFI_CMD_STR"]] */
11519 if (argv_find_and_parse_afi(argv, argc, &idx, &afi)) {
11520 argv_find_and_parse_safi(argv, argc, &idx, &safi);
11521 }
11522
11523 if (!((afi == AFI_IP || afi == AFI_IP6) && safi == SAFI_UNICAST)) {
11524 vty_out(vty,
11525 "%% This command is applicable only for unicast ipv4|ipv6\n");
11526 return CMD_WARNING;
11527 }
11528
11529 if (vrf && strmatch(vrf, "all"))
11530 return bgp_show_all_instance_route_leak_vty(vty, afi, safi, uj);
11531
11532 if (uj)
11533 json = json_object_new_object();
11534
11535 return bgp_show_route_leak_vty(vty, vrf, afi, safi, uj, json);
11536 }
11537
11538 static void bgp_show_all_instances_updgrps_vty(struct vty *vty, afi_t afi,
11539 safi_t safi)
11540 {
11541 struct listnode *node, *nnode;
11542 struct bgp *bgp;
11543
11544 for (ALL_LIST_ELEMENTS(bm->bgp, node, nnode, bgp)) {
11545 vty_out(vty, "\nInstance %s:\n",
11546 (bgp->inst_type == BGP_INSTANCE_TYPE_DEFAULT)
11547 ? VRF_DEFAULT_NAME
11548 : bgp->name);
11549 update_group_show(bgp, afi, safi, vty, 0);
11550 }
11551 }
11552
11553 static int bgp_show_update_groups(struct vty *vty, const char *name, int afi,
11554 int safi, uint64_t subgrp_id)
11555 {
11556 struct bgp *bgp;
11557
11558 if (name) {
11559 if (strmatch(name, "all")) {
11560 bgp_show_all_instances_updgrps_vty(vty, afi, safi);
11561 return CMD_SUCCESS;
11562 } else {
11563 bgp = bgp_lookup_by_name(name);
11564 }
11565 } else {
11566 bgp = bgp_get_default();
11567 }
11568
11569 if (bgp)
11570 update_group_show(bgp, afi, safi, vty, subgrp_id);
11571 return CMD_SUCCESS;
11572 }
11573
11574 DEFUN (show_ip_bgp_updgrps,
11575 show_ip_bgp_updgrps_cmd,
11576 "show [ip] bgp [<view|vrf> VIEWVRFNAME] ["BGP_AFI_CMD_STR" ["BGP_SAFI_WITH_LABEL_CMD_STR"]] update-groups [SUBGROUP-ID]",
11577 SHOW_STR
11578 IP_STR
11579 BGP_STR
11580 BGP_INSTANCE_HELP_STR
11581 BGP_AFI_HELP_STR
11582 BGP_SAFI_WITH_LABEL_HELP_STR
11583 "Detailed info about dynamic update groups\n"
11584 "Specific subgroup to display detailed info for\n")
11585 {
11586 char *vrf = NULL;
11587 afi_t afi = AFI_IP6;
11588 safi_t safi = SAFI_UNICAST;
11589 uint64_t subgrp_id = 0;
11590
11591 int idx = 0;
11592
11593 /* show [ip] bgp */
11594 if (argv_find(argv, argc, "ip", &idx))
11595 afi = AFI_IP;
11596 /* [<vrf> VIEWVRFNAME] */
11597 if (argv_find(argv, argc, "vrf", &idx)) {
11598 vrf = argv[idx + 1]->arg;
11599 if (vrf && strmatch(vrf, VRF_DEFAULT_NAME))
11600 vrf = NULL;
11601 } else if (argv_find(argv, argc, "view", &idx))
11602 /* [<view> VIEWVRFNAME] */
11603 vrf = argv[idx + 1]->arg;
11604 /* ["BGP_AFI_CMD_STR" ["BGP_SAFI_CMD_STR"]] */
11605 if (argv_find_and_parse_afi(argv, argc, &idx, &afi)) {
11606 argv_find_and_parse_safi(argv, argc, &idx, &safi);
11607 }
11608
11609 /* get subgroup id, if provided */
11610 idx = argc - 1;
11611 if (argv[idx]->type == VARIABLE_TKN)
11612 subgrp_id = strtoull(argv[idx]->arg, NULL, 10);
11613
11614 return (bgp_show_update_groups(vty, vrf, afi, safi, subgrp_id));
11615 }
11616
11617 DEFUN (show_bgp_instance_all_ipv6_updgrps,
11618 show_bgp_instance_all_ipv6_updgrps_cmd,
11619 "show [ip] bgp <view|vrf> all update-groups",
11620 SHOW_STR
11621 IP_STR
11622 BGP_STR
11623 BGP_INSTANCE_ALL_HELP_STR
11624 "Detailed info about dynamic update groups\n")
11625 {
11626 bgp_show_all_instances_updgrps_vty(vty, AFI_IP6, SAFI_UNICAST);
11627 return CMD_SUCCESS;
11628 }
11629
11630 DEFUN (show_bgp_l2vpn_evpn_updgrps,
11631 show_bgp_l2vpn_evpn_updgrps_cmd,
11632 "show [ip] bgp l2vpn evpn update-groups",
11633 SHOW_STR
11634 IP_STR
11635 BGP_STR
11636 "l2vpn address family\n"
11637 "evpn sub-address family\n"
11638 "Detailed info about dynamic update groups\n")
11639 {
11640 char *vrf = NULL;
11641 uint64_t subgrp_id = 0;
11642
11643 bgp_show_update_groups(vty, vrf, AFI_L2VPN, SAFI_EVPN, subgrp_id);
11644 return CMD_SUCCESS;
11645 }
11646
11647 DEFUN (show_bgp_updgrps_stats,
11648 show_bgp_updgrps_stats_cmd,
11649 "show [ip] bgp update-groups statistics",
11650 SHOW_STR
11651 IP_STR
11652 BGP_STR
11653 "Detailed info about dynamic update groups\n"
11654 "Statistics\n")
11655 {
11656 struct bgp *bgp;
11657
11658 bgp = bgp_get_default();
11659 if (bgp)
11660 update_group_show_stats(bgp, vty);
11661
11662 return CMD_SUCCESS;
11663 }
11664
11665 DEFUN (show_bgp_instance_updgrps_stats,
11666 show_bgp_instance_updgrps_stats_cmd,
11667 "show [ip] bgp <view|vrf> VIEWVRFNAME update-groups statistics",
11668 SHOW_STR
11669 IP_STR
11670 BGP_STR
11671 BGP_INSTANCE_HELP_STR
11672 "Detailed info about dynamic update groups\n"
11673 "Statistics\n")
11674 {
11675 int idx_word = 3;
11676 struct bgp *bgp;
11677
11678 bgp = bgp_lookup_by_name(argv[idx_word]->arg);
11679 if (bgp)
11680 update_group_show_stats(bgp, vty);
11681
11682 return CMD_SUCCESS;
11683 }
11684
11685 static void show_bgp_updgrps_adj_info_aux(struct vty *vty, const char *name,
11686 afi_t afi, safi_t safi,
11687 const char *what, uint64_t subgrp_id)
11688 {
11689 struct bgp *bgp;
11690
11691 if (name)
11692 bgp = bgp_lookup_by_name(name);
11693 else
11694 bgp = bgp_get_default();
11695
11696 if (bgp) {
11697 if (!strcmp(what, "advertise-queue"))
11698 update_group_show_adj_queue(bgp, afi, safi, vty,
11699 subgrp_id);
11700 else if (!strcmp(what, "advertised-routes"))
11701 update_group_show_advertised(bgp, afi, safi, vty,
11702 subgrp_id);
11703 else if (!strcmp(what, "packet-queue"))
11704 update_group_show_packet_queue(bgp, afi, safi, vty,
11705 subgrp_id);
11706 }
11707 }
11708
11709 DEFPY(show_ip_bgp_instance_updgrps_adj_s,
11710 show_ip_bgp_instance_updgrps_adj_s_cmd,
11711 "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",
11712 SHOW_STR IP_STR BGP_STR BGP_INSTANCE_HELP_STR BGP_AFI_HELP_STR
11713 BGP_SAFI_HELP_STR
11714 "Detailed info about dynamic update groups\n"
11715 "Specific subgroup to display info for\n"
11716 "Advertisement queue\n"
11717 "Announced routes\n"
11718 "Packet queue\n")
11719 {
11720 uint64_t subgrp_id = 0;
11721 afi_t afiz;
11722 safi_t safiz;
11723 if (sgid)
11724 subgrp_id = strtoull(sgid, NULL, 10);
11725
11726 if (!ip && !afi)
11727 afiz = AFI_IP6;
11728 if (!ip && afi)
11729 afiz = bgp_vty_afi_from_str(afi);
11730 if (ip && !afi)
11731 afiz = AFI_IP;
11732 if (ip && afi) {
11733 afiz = bgp_vty_afi_from_str(afi);
11734 if (afiz != AFI_IP)
11735 vty_out(vty,
11736 "%% Cannot specify both 'ip' and 'ipv6'\n");
11737 return CMD_WARNING;
11738 }
11739
11740 safiz = safi ? bgp_vty_safi_from_str(safi) : SAFI_UNICAST;
11741
11742 show_bgp_updgrps_adj_info_aux(vty, vrf, afiz, safiz, rtq, subgrp_id);
11743 return CMD_SUCCESS;
11744 }
11745
11746 static int bgp_show_one_peer_group(struct vty *vty, struct peer_group *group)
11747 {
11748 struct listnode *node, *nnode;
11749 struct prefix *range;
11750 struct peer *conf;
11751 struct peer *peer;
11752 char buf[PREFIX2STR_BUFFER];
11753 afi_t afi;
11754 safi_t safi;
11755 const char *peer_status;
11756 const char *af_str;
11757 int lr_count;
11758 int dynamic;
11759 int af_cfgd;
11760
11761 conf = group->conf;
11762
11763 if (conf->as_type == AS_SPECIFIED || conf->as_type == AS_EXTERNAL) {
11764 vty_out(vty, "\nBGP peer-group %s, remote AS %" PRIu32 "\n",
11765 group->name, conf->as);
11766 } else if (conf->as_type == AS_INTERNAL) {
11767 vty_out(vty, "\nBGP peer-group %s, remote AS %" PRIu32 "\n",
11768 group->name, group->bgp->as);
11769 } else {
11770 vty_out(vty, "\nBGP peer-group %s\n", group->name);
11771 }
11772
11773 if ((group->bgp->as == conf->as) || (conf->as_type == AS_INTERNAL))
11774 vty_out(vty, " Peer-group type is internal\n");
11775 else
11776 vty_out(vty, " Peer-group type is external\n");
11777
11778 /* Display AFs configured. */
11779 vty_out(vty, " Configured address-families:");
11780 FOREACH_AFI_SAFI (afi, safi) {
11781 if (conf->afc[afi][safi]) {
11782 af_cfgd = 1;
11783 vty_out(vty, " %s;", afi_safi_print(afi, safi));
11784 }
11785 }
11786 if (!af_cfgd)
11787 vty_out(vty, " none\n");
11788 else
11789 vty_out(vty, "\n");
11790
11791 /* Display listen ranges (for dynamic neighbors), if any */
11792 for (afi = AFI_IP; afi < AFI_MAX; afi++) {
11793 if (afi == AFI_IP)
11794 af_str = "IPv4";
11795 else if (afi == AFI_IP6)
11796 af_str = "IPv6";
11797 else
11798 af_str = "???";
11799 lr_count = listcount(group->listen_range[afi]);
11800 if (lr_count) {
11801 vty_out(vty, " %d %s listen range(s)\n", lr_count,
11802 af_str);
11803
11804
11805 for (ALL_LIST_ELEMENTS(group->listen_range[afi], node,
11806 nnode, range)) {
11807 prefix2str(range, buf, sizeof(buf));
11808 vty_out(vty, " %s\n", buf);
11809 }
11810 }
11811 }
11812
11813 /* Display group members and their status */
11814 if (listcount(group->peer)) {
11815 vty_out(vty, " Peer-group members:\n");
11816 for (ALL_LIST_ELEMENTS(group->peer, node, nnode, peer)) {
11817 if (CHECK_FLAG(peer->flags, PEER_FLAG_SHUTDOWN))
11818 peer_status = "Idle (Admin)";
11819 else if (CHECK_FLAG(peer->sflags,
11820 PEER_STATUS_PREFIX_OVERFLOW))
11821 peer_status = "Idle (PfxCt)";
11822 else
11823 peer_status = lookup_msg(bgp_status_msg,
11824 peer->status, NULL);
11825
11826 dynamic = peer_dynamic_neighbor(peer);
11827 vty_out(vty, " %s %s %s \n", peer->host,
11828 dynamic ? "(dynamic)" : "", peer_status);
11829 }
11830 }
11831
11832 return CMD_SUCCESS;
11833 }
11834
11835 static int bgp_show_peer_group_vty(struct vty *vty, const char *name,
11836 const char *group_name)
11837 {
11838 struct bgp *bgp;
11839 struct listnode *node, *nnode;
11840 struct peer_group *group;
11841 bool found = false;
11842
11843 bgp = name ? bgp_lookup_by_name(name) : bgp_get_default();
11844
11845 if (!bgp) {
11846 vty_out(vty, "%% BGP instance not found\n");
11847 return CMD_WARNING;
11848 }
11849
11850 for (ALL_LIST_ELEMENTS(bgp->group, node, nnode, group)) {
11851 if (group_name) {
11852 if (strmatch(group->name, group_name)) {
11853 bgp_show_one_peer_group(vty, group);
11854 found = true;
11855 break;
11856 }
11857 } else {
11858 bgp_show_one_peer_group(vty, group);
11859 }
11860 }
11861
11862 if (group_name && !found)
11863 vty_out(vty, "%% No such peer-group\n");
11864
11865 return CMD_SUCCESS;
11866 }
11867
11868 DEFUN (show_ip_bgp_peer_groups,
11869 show_ip_bgp_peer_groups_cmd,
11870 "show [ip] bgp [<view|vrf> VIEWVRFNAME] peer-group [PGNAME]",
11871 SHOW_STR
11872 IP_STR
11873 BGP_STR
11874 BGP_INSTANCE_HELP_STR
11875 "Detailed information on BGP peer groups\n"
11876 "Peer group name\n")
11877 {
11878 char *vrf, *pg;
11879 int idx = 0;
11880
11881 vrf = argv_find(argv, argc, "VIEWVRFNAME", &idx) ? argv[idx]->arg
11882 : NULL;
11883 pg = argv_find(argv, argc, "PGNAME", &idx) ? argv[idx]->arg : NULL;
11884
11885 return bgp_show_peer_group_vty(vty, vrf, pg);
11886 }
11887
11888
11889 /* Redistribute VTY commands. */
11890
11891 DEFUN (bgp_redistribute_ipv4,
11892 bgp_redistribute_ipv4_cmd,
11893 "redistribute " FRR_IP_REDIST_STR_BGPD,
11894 "Redistribute information from another routing protocol\n"
11895 FRR_IP_REDIST_HELP_STR_BGPD)
11896 {
11897 VTY_DECLVAR_CONTEXT(bgp, bgp);
11898 int idx_protocol = 1;
11899 int type;
11900
11901 type = proto_redistnum(AFI_IP, argv[idx_protocol]->text);
11902 if (type < 0) {
11903 vty_out(vty, "%% Invalid route type\n");
11904 return CMD_WARNING_CONFIG_FAILED;
11905 }
11906
11907 bgp_redist_add(bgp, AFI_IP, type, 0);
11908 return bgp_redistribute_set(bgp, AFI_IP, type, 0, false);
11909 }
11910
11911 ALIAS_HIDDEN(
11912 bgp_redistribute_ipv4, bgp_redistribute_ipv4_hidden_cmd,
11913 "redistribute " FRR_IP_REDIST_STR_BGPD,
11914 "Redistribute information from another routing protocol\n" FRR_IP_REDIST_HELP_STR_BGPD)
11915
11916 DEFUN (bgp_redistribute_ipv4_rmap,
11917 bgp_redistribute_ipv4_rmap_cmd,
11918 "redistribute " FRR_IP_REDIST_STR_BGPD " route-map WORD",
11919 "Redistribute information from another routing protocol\n"
11920 FRR_IP_REDIST_HELP_STR_BGPD
11921 "Route map reference\n"
11922 "Pointer to route-map entries\n")
11923 {
11924 VTY_DECLVAR_CONTEXT(bgp, bgp);
11925 int idx_protocol = 1;
11926 int idx_word = 3;
11927 int type;
11928 struct bgp_redist *red;
11929 bool changed;
11930 struct route_map *route_map = route_map_lookup_warn_noexist(
11931 vty, argv[idx_word]->arg);
11932
11933 type = proto_redistnum(AFI_IP, argv[idx_protocol]->text);
11934 if (type < 0) {
11935 vty_out(vty, "%% Invalid route type\n");
11936 return CMD_WARNING_CONFIG_FAILED;
11937 }
11938
11939 red = bgp_redist_add(bgp, AFI_IP, type, 0);
11940 changed =
11941 bgp_redistribute_rmap_set(red, argv[idx_word]->arg, route_map);
11942 return bgp_redistribute_set(bgp, AFI_IP, type, 0, changed);
11943 }
11944
11945 ALIAS_HIDDEN(
11946 bgp_redistribute_ipv4_rmap, bgp_redistribute_ipv4_rmap_hidden_cmd,
11947 "redistribute " FRR_IP_REDIST_STR_BGPD " route-map WORD",
11948 "Redistribute information from another routing protocol\n" FRR_IP_REDIST_HELP_STR_BGPD
11949 "Route map reference\n"
11950 "Pointer to route-map entries\n")
11951
11952 DEFUN (bgp_redistribute_ipv4_metric,
11953 bgp_redistribute_ipv4_metric_cmd,
11954 "redistribute " FRR_IP_REDIST_STR_BGPD " metric (0-4294967295)",
11955 "Redistribute information from another routing protocol\n"
11956 FRR_IP_REDIST_HELP_STR_BGPD
11957 "Metric for redistributed routes\n"
11958 "Default metric\n")
11959 {
11960 VTY_DECLVAR_CONTEXT(bgp, bgp);
11961 int idx_protocol = 1;
11962 int idx_number = 3;
11963 int type;
11964 uint32_t metric;
11965 struct bgp_redist *red;
11966 bool changed;
11967
11968 type = proto_redistnum(AFI_IP, argv[idx_protocol]->text);
11969 if (type < 0) {
11970 vty_out(vty, "%% Invalid route type\n");
11971 return CMD_WARNING_CONFIG_FAILED;
11972 }
11973 metric = strtoul(argv[idx_number]->arg, NULL, 10);
11974
11975 red = bgp_redist_add(bgp, AFI_IP, type, 0);
11976 changed = bgp_redistribute_metric_set(bgp, red, AFI_IP, type, metric);
11977 return bgp_redistribute_set(bgp, AFI_IP, type, 0, changed);
11978 }
11979
11980 ALIAS_HIDDEN(
11981 bgp_redistribute_ipv4_metric, bgp_redistribute_ipv4_metric_hidden_cmd,
11982 "redistribute " FRR_IP_REDIST_STR_BGPD " metric (0-4294967295)",
11983 "Redistribute information from another routing protocol\n" FRR_IP_REDIST_HELP_STR_BGPD
11984 "Metric for redistributed routes\n"
11985 "Default metric\n")
11986
11987 DEFUN (bgp_redistribute_ipv4_rmap_metric,
11988 bgp_redistribute_ipv4_rmap_metric_cmd,
11989 "redistribute " FRR_IP_REDIST_STR_BGPD " route-map WORD metric (0-4294967295)",
11990 "Redistribute information from another routing protocol\n"
11991 FRR_IP_REDIST_HELP_STR_BGPD
11992 "Route map reference\n"
11993 "Pointer to route-map entries\n"
11994 "Metric for redistributed routes\n"
11995 "Default metric\n")
11996 {
11997 VTY_DECLVAR_CONTEXT(bgp, bgp);
11998 int idx_protocol = 1;
11999 int idx_word = 3;
12000 int idx_number = 5;
12001 int type;
12002 uint32_t metric;
12003 struct bgp_redist *red;
12004 bool changed;
12005 struct route_map *route_map =
12006 route_map_lookup_warn_noexist(vty, argv[idx_word]->arg);
12007
12008 type = proto_redistnum(AFI_IP, argv[idx_protocol]->text);
12009 if (type < 0) {
12010 vty_out(vty, "%% Invalid route type\n");
12011 return CMD_WARNING_CONFIG_FAILED;
12012 }
12013 metric = strtoul(argv[idx_number]->arg, NULL, 10);
12014
12015 red = bgp_redist_add(bgp, AFI_IP, type, 0);
12016 changed =
12017 bgp_redistribute_rmap_set(red, argv[idx_word]->arg, route_map);
12018 changed |= bgp_redistribute_metric_set(bgp, red, AFI_IP, type, metric);
12019 return bgp_redistribute_set(bgp, AFI_IP, type, 0, changed);
12020 }
12021
12022 ALIAS_HIDDEN(
12023 bgp_redistribute_ipv4_rmap_metric,
12024 bgp_redistribute_ipv4_rmap_metric_hidden_cmd,
12025 "redistribute " FRR_IP_REDIST_STR_BGPD
12026 " route-map WORD metric (0-4294967295)",
12027 "Redistribute information from another routing protocol\n" FRR_IP_REDIST_HELP_STR_BGPD
12028 "Route map reference\n"
12029 "Pointer to route-map entries\n"
12030 "Metric for redistributed routes\n"
12031 "Default metric\n")
12032
12033 DEFUN (bgp_redistribute_ipv4_metric_rmap,
12034 bgp_redistribute_ipv4_metric_rmap_cmd,
12035 "redistribute " FRR_IP_REDIST_STR_BGPD " metric (0-4294967295) route-map WORD",
12036 "Redistribute information from another routing protocol\n"
12037 FRR_IP_REDIST_HELP_STR_BGPD
12038 "Metric for redistributed routes\n"
12039 "Default metric\n"
12040 "Route map reference\n"
12041 "Pointer to route-map entries\n")
12042 {
12043 VTY_DECLVAR_CONTEXT(bgp, bgp);
12044 int idx_protocol = 1;
12045 int idx_number = 3;
12046 int idx_word = 5;
12047 int type;
12048 uint32_t metric;
12049 struct bgp_redist *red;
12050 bool changed;
12051 struct route_map *route_map =
12052 route_map_lookup_warn_noexist(vty, argv[idx_word]->arg);
12053
12054 type = proto_redistnum(AFI_IP, argv[idx_protocol]->text);
12055 if (type < 0) {
12056 vty_out(vty, "%% Invalid route type\n");
12057 return CMD_WARNING_CONFIG_FAILED;
12058 }
12059 metric = strtoul(argv[idx_number]->arg, NULL, 10);
12060
12061 red = bgp_redist_add(bgp, AFI_IP, type, 0);
12062 changed = bgp_redistribute_metric_set(bgp, red, AFI_IP, type, metric);
12063 changed |=
12064 bgp_redistribute_rmap_set(red, argv[idx_word]->arg, route_map);
12065 return bgp_redistribute_set(bgp, AFI_IP, type, 0, changed);
12066 }
12067
12068 ALIAS_HIDDEN(
12069 bgp_redistribute_ipv4_metric_rmap,
12070 bgp_redistribute_ipv4_metric_rmap_hidden_cmd,
12071 "redistribute " FRR_IP_REDIST_STR_BGPD
12072 " metric (0-4294967295) route-map WORD",
12073 "Redistribute information from another routing protocol\n" FRR_IP_REDIST_HELP_STR_BGPD
12074 "Metric for redistributed routes\n"
12075 "Default metric\n"
12076 "Route map reference\n"
12077 "Pointer to route-map entries\n")
12078
12079 DEFUN (bgp_redistribute_ipv4_ospf,
12080 bgp_redistribute_ipv4_ospf_cmd,
12081 "redistribute <ospf|table> (1-65535)",
12082 "Redistribute information from another routing protocol\n"
12083 "Open Shortest Path First (OSPFv2)\n"
12084 "Non-main Kernel Routing Table\n"
12085 "Instance ID/Table ID\n")
12086 {
12087 VTY_DECLVAR_CONTEXT(bgp, bgp);
12088 int idx_ospf_table = 1;
12089 int idx_number = 2;
12090 unsigned short instance;
12091 unsigned short protocol;
12092
12093 instance = strtoul(argv[idx_number]->arg, NULL, 10);
12094
12095 if (strncmp(argv[idx_ospf_table]->arg, "o", 1) == 0)
12096 protocol = ZEBRA_ROUTE_OSPF;
12097 else
12098 protocol = ZEBRA_ROUTE_TABLE;
12099
12100 bgp_redist_add(bgp, AFI_IP, protocol, instance);
12101 return bgp_redistribute_set(bgp, AFI_IP, protocol, instance, false);
12102 }
12103
12104 ALIAS_HIDDEN(bgp_redistribute_ipv4_ospf, bgp_redistribute_ipv4_ospf_hidden_cmd,
12105 "redistribute <ospf|table> (1-65535)",
12106 "Redistribute information from another routing protocol\n"
12107 "Open Shortest Path First (OSPFv2)\n"
12108 "Non-main Kernel Routing Table\n"
12109 "Instance ID/Table ID\n")
12110
12111 DEFUN (bgp_redistribute_ipv4_ospf_rmap,
12112 bgp_redistribute_ipv4_ospf_rmap_cmd,
12113 "redistribute <ospf|table> (1-65535) route-map WORD",
12114 "Redistribute information from another routing protocol\n"
12115 "Open Shortest Path First (OSPFv2)\n"
12116 "Non-main Kernel Routing Table\n"
12117 "Instance ID/Table ID\n"
12118 "Route map reference\n"
12119 "Pointer to route-map entries\n")
12120 {
12121 VTY_DECLVAR_CONTEXT(bgp, bgp);
12122 int idx_ospf_table = 1;
12123 int idx_number = 2;
12124 int idx_word = 4;
12125 struct bgp_redist *red;
12126 unsigned short instance;
12127 int protocol;
12128 bool changed;
12129 struct route_map *route_map =
12130 route_map_lookup_warn_noexist(vty, argv[idx_word]->arg);
12131
12132 if (strncmp(argv[idx_ospf_table]->arg, "o", 1) == 0)
12133 protocol = ZEBRA_ROUTE_OSPF;
12134 else
12135 protocol = ZEBRA_ROUTE_TABLE;
12136
12137 instance = strtoul(argv[idx_number]->arg, NULL, 10);
12138 red = bgp_redist_add(bgp, AFI_IP, protocol, instance);
12139 changed =
12140 bgp_redistribute_rmap_set(red, argv[idx_word]->arg, route_map);
12141 return bgp_redistribute_set(bgp, AFI_IP, protocol, instance, changed);
12142 }
12143
12144 ALIAS_HIDDEN(bgp_redistribute_ipv4_ospf_rmap,
12145 bgp_redistribute_ipv4_ospf_rmap_hidden_cmd,
12146 "redistribute <ospf|table> (1-65535) route-map WORD",
12147 "Redistribute information from another routing protocol\n"
12148 "Open Shortest Path First (OSPFv2)\n"
12149 "Non-main Kernel Routing Table\n"
12150 "Instance ID/Table ID\n"
12151 "Route map reference\n"
12152 "Pointer to route-map entries\n")
12153
12154 DEFUN (bgp_redistribute_ipv4_ospf_metric,
12155 bgp_redistribute_ipv4_ospf_metric_cmd,
12156 "redistribute <ospf|table> (1-65535) metric (0-4294967295)",
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 "Metric for redistributed routes\n"
12162 "Default metric\n")
12163 {
12164 VTY_DECLVAR_CONTEXT(bgp, bgp);
12165 int idx_ospf_table = 1;
12166 int idx_number = 2;
12167 int idx_number_2 = 4;
12168 uint32_t metric;
12169 struct bgp_redist *red;
12170 unsigned short instance;
12171 int protocol;
12172 bool changed;
12173
12174 if (strncmp(argv[idx_ospf_table]->arg, "o", 1) == 0)
12175 protocol = ZEBRA_ROUTE_OSPF;
12176 else
12177 protocol = ZEBRA_ROUTE_TABLE;
12178
12179 instance = strtoul(argv[idx_number]->arg, NULL, 10);
12180 metric = strtoul(argv[idx_number_2]->arg, NULL, 10);
12181
12182 red = bgp_redist_add(bgp, AFI_IP, protocol, instance);
12183 changed = bgp_redistribute_metric_set(bgp, red, AFI_IP, protocol,
12184 metric);
12185 return bgp_redistribute_set(bgp, AFI_IP, protocol, instance, changed);
12186 }
12187
12188 ALIAS_HIDDEN(bgp_redistribute_ipv4_ospf_metric,
12189 bgp_redistribute_ipv4_ospf_metric_hidden_cmd,
12190 "redistribute <ospf|table> (1-65535) metric (0-4294967295)",
12191 "Redistribute information from another routing protocol\n"
12192 "Open Shortest Path First (OSPFv2)\n"
12193 "Non-main Kernel Routing Table\n"
12194 "Instance ID/Table ID\n"
12195 "Metric for redistributed routes\n"
12196 "Default metric\n")
12197
12198 DEFUN (bgp_redistribute_ipv4_ospf_rmap_metric,
12199 bgp_redistribute_ipv4_ospf_rmap_metric_cmd,
12200 "redistribute <ospf|table> (1-65535) route-map WORD 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 "Route map reference\n"
12206 "Pointer to route-map entries\n"
12207 "Metric for redistributed routes\n"
12208 "Default metric\n")
12209 {
12210 VTY_DECLVAR_CONTEXT(bgp, bgp);
12211 int idx_ospf_table = 1;
12212 int idx_number = 2;
12213 int idx_word = 4;
12214 int idx_number_2 = 6;
12215 uint32_t metric;
12216 struct bgp_redist *red;
12217 unsigned short instance;
12218 int protocol;
12219 bool changed;
12220 struct route_map *route_map =
12221 route_map_lookup_warn_noexist(vty, argv[idx_word]->arg);
12222
12223 if (strncmp(argv[idx_ospf_table]->arg, "o", 1) == 0)
12224 protocol = ZEBRA_ROUTE_OSPF;
12225 else
12226 protocol = ZEBRA_ROUTE_TABLE;
12227
12228 instance = strtoul(argv[idx_number]->arg, NULL, 10);
12229 metric = strtoul(argv[idx_number_2]->arg, NULL, 10);
12230
12231 red = bgp_redist_add(bgp, AFI_IP, protocol, instance);
12232 changed =
12233 bgp_redistribute_rmap_set(red, argv[idx_word]->arg, route_map);
12234 changed |= bgp_redistribute_metric_set(bgp, red, AFI_IP, protocol,
12235 metric);
12236 return bgp_redistribute_set(bgp, AFI_IP, protocol, instance, changed);
12237 }
12238
12239 ALIAS_HIDDEN(
12240 bgp_redistribute_ipv4_ospf_rmap_metric,
12241 bgp_redistribute_ipv4_ospf_rmap_metric_hidden_cmd,
12242 "redistribute <ospf|table> (1-65535) route-map WORD metric (0-4294967295)",
12243 "Redistribute information from another routing protocol\n"
12244 "Open Shortest Path First (OSPFv2)\n"
12245 "Non-main Kernel Routing Table\n"
12246 "Instance ID/Table ID\n"
12247 "Route map reference\n"
12248 "Pointer to route-map entries\n"
12249 "Metric for redistributed routes\n"
12250 "Default metric\n")
12251
12252 DEFUN (bgp_redistribute_ipv4_ospf_metric_rmap,
12253 bgp_redistribute_ipv4_ospf_metric_rmap_cmd,
12254 "redistribute <ospf|table> (1-65535) metric (0-4294967295) route-map WORD",
12255 "Redistribute information from another routing protocol\n"
12256 "Open Shortest Path First (OSPFv2)\n"
12257 "Non-main Kernel Routing Table\n"
12258 "Instance ID/Table ID\n"
12259 "Metric for redistributed routes\n"
12260 "Default metric\n"
12261 "Route map reference\n"
12262 "Pointer to route-map entries\n")
12263 {
12264 VTY_DECLVAR_CONTEXT(bgp, bgp);
12265 int idx_ospf_table = 1;
12266 int idx_number = 2;
12267 int idx_number_2 = 4;
12268 int idx_word = 6;
12269 uint32_t metric;
12270 struct bgp_redist *red;
12271 unsigned short instance;
12272 int protocol;
12273 bool changed;
12274 struct route_map *route_map =
12275 route_map_lookup_warn_noexist(vty, argv[idx_word]->arg);
12276
12277 if (strncmp(argv[idx_ospf_table]->arg, "o", 1) == 0)
12278 protocol = ZEBRA_ROUTE_OSPF;
12279 else
12280 protocol = ZEBRA_ROUTE_TABLE;
12281
12282 instance = strtoul(argv[idx_number]->arg, NULL, 10);
12283 metric = strtoul(argv[idx_number_2]->arg, NULL, 10);
12284
12285 red = bgp_redist_add(bgp, AFI_IP, protocol, instance);
12286 changed = bgp_redistribute_metric_set(bgp, red, AFI_IP, protocol,
12287 metric);
12288 changed |=
12289 bgp_redistribute_rmap_set(red, argv[idx_word]->arg, route_map);
12290 return bgp_redistribute_set(bgp, AFI_IP, protocol, instance, changed);
12291 }
12292
12293 ALIAS_HIDDEN(
12294 bgp_redistribute_ipv4_ospf_metric_rmap,
12295 bgp_redistribute_ipv4_ospf_metric_rmap_hidden_cmd,
12296 "redistribute <ospf|table> (1-65535) metric (0-4294967295) route-map WORD",
12297 "Redistribute information from another routing protocol\n"
12298 "Open Shortest Path First (OSPFv2)\n"
12299 "Non-main Kernel Routing Table\n"
12300 "Instance ID/Table ID\n"
12301 "Metric for redistributed routes\n"
12302 "Default metric\n"
12303 "Route map reference\n"
12304 "Pointer to route-map entries\n")
12305
12306 DEFUN (no_bgp_redistribute_ipv4_ospf,
12307 no_bgp_redistribute_ipv4_ospf_cmd,
12308 "no redistribute <ospf|table> (1-65535) [metric (0-4294967295)] [route-map WORD]",
12309 NO_STR
12310 "Redistribute information from another routing protocol\n"
12311 "Open Shortest Path First (OSPFv2)\n"
12312 "Non-main Kernel Routing Table\n"
12313 "Instance ID/Table ID\n"
12314 "Metric for redistributed routes\n"
12315 "Default metric\n"
12316 "Route map reference\n"
12317 "Pointer to route-map entries\n")
12318 {
12319 VTY_DECLVAR_CONTEXT(bgp, bgp);
12320 int idx_ospf_table = 2;
12321 int idx_number = 3;
12322 unsigned short instance;
12323 int protocol;
12324
12325 if (strncmp(argv[idx_ospf_table]->arg, "o", 1) == 0)
12326 protocol = ZEBRA_ROUTE_OSPF;
12327 else
12328 protocol = ZEBRA_ROUTE_TABLE;
12329
12330 instance = strtoul(argv[idx_number]->arg, NULL, 10);
12331 return bgp_redistribute_unset(bgp, AFI_IP, protocol, instance);
12332 }
12333
12334 ALIAS_HIDDEN(
12335 no_bgp_redistribute_ipv4_ospf, no_bgp_redistribute_ipv4_ospf_hidden_cmd,
12336 "no redistribute <ospf|table> (1-65535) [metric (0-4294967295)] [route-map WORD]",
12337 NO_STR
12338 "Redistribute information from another routing protocol\n"
12339 "Open Shortest Path First (OSPFv2)\n"
12340 "Non-main Kernel Routing Table\n"
12341 "Instance ID/Table ID\n"
12342 "Metric for redistributed routes\n"
12343 "Default metric\n"
12344 "Route map reference\n"
12345 "Pointer to route-map entries\n")
12346
12347 DEFUN (no_bgp_redistribute_ipv4,
12348 no_bgp_redistribute_ipv4_cmd,
12349 "no redistribute " FRR_IP_REDIST_STR_BGPD " [metric (0-4294967295)] [route-map WORD]",
12350 NO_STR
12351 "Redistribute information from another routing protocol\n"
12352 FRR_IP_REDIST_HELP_STR_BGPD
12353 "Metric for redistributed routes\n"
12354 "Default metric\n"
12355 "Route map reference\n"
12356 "Pointer to route-map entries\n")
12357 {
12358 VTY_DECLVAR_CONTEXT(bgp, bgp);
12359 int idx_protocol = 2;
12360 int type;
12361
12362 type = proto_redistnum(AFI_IP, argv[idx_protocol]->text);
12363 if (type < 0) {
12364 vty_out(vty, "%% Invalid route type\n");
12365 return CMD_WARNING_CONFIG_FAILED;
12366 }
12367 return bgp_redistribute_unset(bgp, AFI_IP, type, 0);
12368 }
12369
12370 ALIAS_HIDDEN(
12371 no_bgp_redistribute_ipv4, no_bgp_redistribute_ipv4_hidden_cmd,
12372 "no redistribute " FRR_IP_REDIST_STR_BGPD
12373 " [metric (0-4294967295)] [route-map WORD]",
12374 NO_STR
12375 "Redistribute information from another routing protocol\n" FRR_IP_REDIST_HELP_STR_BGPD
12376 "Metric for redistributed routes\n"
12377 "Default metric\n"
12378 "Route map reference\n"
12379 "Pointer to route-map entries\n")
12380
12381 DEFUN (bgp_redistribute_ipv6,
12382 bgp_redistribute_ipv6_cmd,
12383 "redistribute " FRR_IP6_REDIST_STR_BGPD,
12384 "Redistribute information from another routing protocol\n"
12385 FRR_IP6_REDIST_HELP_STR_BGPD)
12386 {
12387 VTY_DECLVAR_CONTEXT(bgp, bgp);
12388 int idx_protocol = 1;
12389 int type;
12390
12391 type = proto_redistnum(AFI_IP6, argv[idx_protocol]->text);
12392 if (type < 0) {
12393 vty_out(vty, "%% Invalid route type\n");
12394 return CMD_WARNING_CONFIG_FAILED;
12395 }
12396
12397 bgp_redist_add(bgp, AFI_IP6, type, 0);
12398 return bgp_redistribute_set(bgp, AFI_IP6, type, 0, false);
12399 }
12400
12401 DEFUN (bgp_redistribute_ipv6_rmap,
12402 bgp_redistribute_ipv6_rmap_cmd,
12403 "redistribute " FRR_IP6_REDIST_STR_BGPD " route-map WORD",
12404 "Redistribute information from another routing protocol\n"
12405 FRR_IP6_REDIST_HELP_STR_BGPD
12406 "Route map reference\n"
12407 "Pointer to route-map entries\n")
12408 {
12409 VTY_DECLVAR_CONTEXT(bgp, bgp);
12410 int idx_protocol = 1;
12411 int idx_word = 3;
12412 int type;
12413 struct bgp_redist *red;
12414 bool changed;
12415 struct route_map *route_map =
12416 route_map_lookup_warn_noexist(vty, argv[idx_word]->arg);
12417
12418 type = proto_redistnum(AFI_IP6, argv[idx_protocol]->text);
12419 if (type < 0) {
12420 vty_out(vty, "%% Invalid route type\n");
12421 return CMD_WARNING_CONFIG_FAILED;
12422 }
12423
12424 red = bgp_redist_add(bgp, AFI_IP6, type, 0);
12425 changed =
12426 bgp_redistribute_rmap_set(red, argv[idx_word]->arg, route_map);
12427 return bgp_redistribute_set(bgp, AFI_IP6, type, 0, changed);
12428 }
12429
12430 DEFUN (bgp_redistribute_ipv6_metric,
12431 bgp_redistribute_ipv6_metric_cmd,
12432 "redistribute " FRR_IP6_REDIST_STR_BGPD " metric (0-4294967295)",
12433 "Redistribute information from another routing protocol\n"
12434 FRR_IP6_REDIST_HELP_STR_BGPD
12435 "Metric for redistributed routes\n"
12436 "Default metric\n")
12437 {
12438 VTY_DECLVAR_CONTEXT(bgp, bgp);
12439 int idx_protocol = 1;
12440 int idx_number = 3;
12441 int type;
12442 uint32_t metric;
12443 struct bgp_redist *red;
12444 bool changed;
12445
12446 type = proto_redistnum(AFI_IP6, argv[idx_protocol]->text);
12447 if (type < 0) {
12448 vty_out(vty, "%% Invalid route type\n");
12449 return CMD_WARNING_CONFIG_FAILED;
12450 }
12451 metric = strtoul(argv[idx_number]->arg, NULL, 10);
12452
12453 red = bgp_redist_add(bgp, AFI_IP6, type, 0);
12454 changed = bgp_redistribute_metric_set(bgp, red, AFI_IP6, type, metric);
12455 return bgp_redistribute_set(bgp, AFI_IP6, type, 0, changed);
12456 }
12457
12458 DEFUN (bgp_redistribute_ipv6_rmap_metric,
12459 bgp_redistribute_ipv6_rmap_metric_cmd,
12460 "redistribute " FRR_IP6_REDIST_STR_BGPD " route-map WORD metric (0-4294967295)",
12461 "Redistribute information from another routing protocol\n"
12462 FRR_IP6_REDIST_HELP_STR_BGPD
12463 "Route map reference\n"
12464 "Pointer to route-map entries\n"
12465 "Metric for redistributed routes\n"
12466 "Default metric\n")
12467 {
12468 VTY_DECLVAR_CONTEXT(bgp, bgp);
12469 int idx_protocol = 1;
12470 int idx_word = 3;
12471 int idx_number = 5;
12472 int type;
12473 uint32_t metric;
12474 struct bgp_redist *red;
12475 bool changed;
12476 struct route_map *route_map =
12477 route_map_lookup_warn_noexist(vty, argv[idx_word]->arg);
12478
12479 type = proto_redistnum(AFI_IP6, argv[idx_protocol]->text);
12480 if (type < 0) {
12481 vty_out(vty, "%% Invalid route type\n");
12482 return CMD_WARNING_CONFIG_FAILED;
12483 }
12484 metric = strtoul(argv[idx_number]->arg, NULL, 10);
12485
12486 red = bgp_redist_add(bgp, AFI_IP6, type, 0);
12487 changed =
12488 bgp_redistribute_rmap_set(red, argv[idx_word]->arg, route_map);
12489 changed |= bgp_redistribute_metric_set(bgp, red, AFI_IP6, type,
12490 metric);
12491 return bgp_redistribute_set(bgp, AFI_IP6, type, 0, changed);
12492 }
12493
12494 DEFUN (bgp_redistribute_ipv6_metric_rmap,
12495 bgp_redistribute_ipv6_metric_rmap_cmd,
12496 "redistribute " FRR_IP6_REDIST_STR_BGPD " metric (0-4294967295) route-map WORD",
12497 "Redistribute information from another routing protocol\n"
12498 FRR_IP6_REDIST_HELP_STR_BGPD
12499 "Metric for redistributed routes\n"
12500 "Default metric\n"
12501 "Route map reference\n"
12502 "Pointer to route-map entries\n")
12503 {
12504 VTY_DECLVAR_CONTEXT(bgp, bgp);
12505 int idx_protocol = 1;
12506 int idx_number = 3;
12507 int idx_word = 5;
12508 int type;
12509 uint32_t metric;
12510 struct bgp_redist *red;
12511 bool changed;
12512 struct route_map *route_map =
12513 route_map_lookup_warn_noexist(vty, argv[idx_word]->arg);
12514
12515 type = proto_redistnum(AFI_IP6, argv[idx_protocol]->text);
12516 if (type < 0) {
12517 vty_out(vty, "%% Invalid route type\n");
12518 return CMD_WARNING_CONFIG_FAILED;
12519 }
12520 metric = strtoul(argv[idx_number]->arg, NULL, 10);
12521
12522 red = bgp_redist_add(bgp, AFI_IP6, type, 0);
12523 changed = bgp_redistribute_metric_set(bgp, red, AFI_IP6, SAFI_UNICAST,
12524 metric);
12525 changed |=
12526 bgp_redistribute_rmap_set(red, argv[idx_word]->arg, route_map);
12527 return bgp_redistribute_set(bgp, AFI_IP6, type, 0, changed);
12528 }
12529
12530 DEFUN (no_bgp_redistribute_ipv6,
12531 no_bgp_redistribute_ipv6_cmd,
12532 "no redistribute " FRR_IP6_REDIST_STR_BGPD " [metric (0-4294967295)] [route-map WORD]",
12533 NO_STR
12534 "Redistribute information from another routing protocol\n"
12535 FRR_IP6_REDIST_HELP_STR_BGPD
12536 "Metric for redistributed routes\n"
12537 "Default metric\n"
12538 "Route map reference\n"
12539 "Pointer to route-map entries\n")
12540 {
12541 VTY_DECLVAR_CONTEXT(bgp, bgp);
12542 int idx_protocol = 2;
12543 int type;
12544
12545 type = proto_redistnum(AFI_IP6, argv[idx_protocol]->text);
12546 if (type < 0) {
12547 vty_out(vty, "%% Invalid route type\n");
12548 return CMD_WARNING_CONFIG_FAILED;
12549 }
12550
12551 return bgp_redistribute_unset(bgp, AFI_IP6, type, 0);
12552 }
12553
12554 void bgp_config_write_redistribute(struct vty *vty, struct bgp *bgp, afi_t afi,
12555 safi_t safi)
12556 {
12557 int i;
12558
12559 /* Unicast redistribution only. */
12560 if (safi != SAFI_UNICAST)
12561 return;
12562
12563 for (i = 0; i < ZEBRA_ROUTE_MAX; i++) {
12564 /* Redistribute BGP does not make sense. */
12565 if (i != ZEBRA_ROUTE_BGP) {
12566 struct list *red_list;
12567 struct listnode *node;
12568 struct bgp_redist *red;
12569
12570 red_list = bgp->redist[afi][i];
12571 if (!red_list)
12572 continue;
12573
12574 for (ALL_LIST_ELEMENTS_RO(red_list, node, red)) {
12575 /* "redistribute" configuration. */
12576 vty_out(vty, " redistribute %s",
12577 zebra_route_string(i));
12578 if (red->instance)
12579 vty_out(vty, " %d", red->instance);
12580 if (red->redist_metric_flag)
12581 vty_out(vty, " metric %u",
12582 red->redist_metric);
12583 if (red->rmap.name)
12584 vty_out(vty, " route-map %s",
12585 red->rmap.name);
12586 vty_out(vty, "\n");
12587 }
12588 }
12589 }
12590 }
12591
12592 /* This is part of the address-family block (unicast only) */
12593 void bgp_vpn_policy_config_write_afi(struct vty *vty, struct bgp *bgp,
12594 afi_t afi)
12595 {
12596 int indent = 2;
12597
12598 if (bgp->vpn_policy[afi].rmap_name[BGP_VPN_POLICY_DIR_FROMVPN]) {
12599 if (listcount(bgp->vpn_policy[afi].import_vrf))
12600 vty_out(vty, "%*simport vrf route-map %s\n", indent, "",
12601 bgp->vpn_policy[afi]
12602 .rmap_name[BGP_VPN_POLICY_DIR_FROMVPN]);
12603 else
12604 vty_out(vty, "%*sroute-map vpn import %s\n", indent, "",
12605 bgp->vpn_policy[afi]
12606 .rmap_name[BGP_VPN_POLICY_DIR_FROMVPN]);
12607 }
12608 if (CHECK_FLAG(bgp->af_flags[afi][SAFI_UNICAST],
12609 BGP_CONFIG_VRF_TO_VRF_IMPORT)
12610 || CHECK_FLAG(bgp->af_flags[afi][SAFI_UNICAST],
12611 BGP_CONFIG_VRF_TO_VRF_EXPORT))
12612 return;
12613
12614 if (CHECK_FLAG(bgp->vpn_policy[afi].flags,
12615 BGP_VPN_POLICY_TOVPN_LABEL_AUTO)) {
12616
12617 vty_out(vty, "%*slabel vpn export %s\n", indent, "", "auto");
12618
12619 } else {
12620 if (bgp->vpn_policy[afi].tovpn_label != MPLS_LABEL_NONE) {
12621 vty_out(vty, "%*slabel vpn export %u\n", indent, "",
12622 bgp->vpn_policy[afi].tovpn_label);
12623 }
12624 }
12625 if (CHECK_FLAG(bgp->vpn_policy[afi].flags,
12626 BGP_VPN_POLICY_TOVPN_RD_SET)) {
12627 char buf[RD_ADDRSTRLEN];
12628 vty_out(vty, "%*srd vpn export %s\n", indent, "",
12629 prefix_rd2str(&bgp->vpn_policy[afi].tovpn_rd, buf,
12630 sizeof(buf)));
12631 }
12632 if (CHECK_FLAG(bgp->vpn_policy[afi].flags,
12633 BGP_VPN_POLICY_TOVPN_NEXTHOP_SET)) {
12634
12635 char buf[PREFIX_STRLEN];
12636 if (inet_ntop(bgp->vpn_policy[afi].tovpn_nexthop.family,
12637 &bgp->vpn_policy[afi].tovpn_nexthop.u.prefix, buf,
12638 sizeof(buf))) {
12639
12640 vty_out(vty, "%*snexthop vpn export %s\n",
12641 indent, "", buf);
12642 }
12643 }
12644 if (bgp->vpn_policy[afi].rtlist[BGP_VPN_POLICY_DIR_FROMVPN]
12645 && bgp->vpn_policy[afi].rtlist[BGP_VPN_POLICY_DIR_TOVPN]
12646 && ecommunity_cmp(
12647 bgp->vpn_policy[afi].rtlist[BGP_VPN_POLICY_DIR_FROMVPN],
12648 bgp->vpn_policy[afi].rtlist[BGP_VPN_POLICY_DIR_TOVPN])) {
12649
12650 char *b = ecommunity_ecom2str(
12651 bgp->vpn_policy[afi].rtlist[BGP_VPN_POLICY_DIR_TOVPN],
12652 ECOMMUNITY_FORMAT_ROUTE_MAP, ECOMMUNITY_ROUTE_TARGET);
12653 vty_out(vty, "%*srt vpn both %s\n", indent, "", b);
12654 XFREE(MTYPE_ECOMMUNITY_STR, b);
12655 } else {
12656 if (bgp->vpn_policy[afi].rtlist[BGP_VPN_POLICY_DIR_FROMVPN]) {
12657 char *b = ecommunity_ecom2str(
12658 bgp->vpn_policy[afi]
12659 .rtlist[BGP_VPN_POLICY_DIR_FROMVPN],
12660 ECOMMUNITY_FORMAT_ROUTE_MAP,
12661 ECOMMUNITY_ROUTE_TARGET);
12662 vty_out(vty, "%*srt vpn import %s\n", indent, "", b);
12663 XFREE(MTYPE_ECOMMUNITY_STR, b);
12664 }
12665 if (bgp->vpn_policy[afi].rtlist[BGP_VPN_POLICY_DIR_TOVPN]) {
12666 char *b = ecommunity_ecom2str(
12667 bgp->vpn_policy[afi]
12668 .rtlist[BGP_VPN_POLICY_DIR_TOVPN],
12669 ECOMMUNITY_FORMAT_ROUTE_MAP,
12670 ECOMMUNITY_ROUTE_TARGET);
12671 vty_out(vty, "%*srt vpn export %s\n", indent, "", b);
12672 XFREE(MTYPE_ECOMMUNITY_STR, b);
12673 }
12674 }
12675
12676 if (bgp->vpn_policy[afi].rmap_name[BGP_VPN_POLICY_DIR_TOVPN])
12677 vty_out(vty, "%*sroute-map vpn export %s\n", indent, "",
12678 bgp->vpn_policy[afi]
12679 .rmap_name[BGP_VPN_POLICY_DIR_TOVPN]);
12680
12681 if (bgp->vpn_policy[afi].import_redirect_rtlist) {
12682 char *b = ecommunity_ecom2str(
12683 bgp->vpn_policy[afi]
12684 .import_redirect_rtlist,
12685 ECOMMUNITY_FORMAT_ROUTE_MAP,
12686 ECOMMUNITY_ROUTE_TARGET);
12687
12688 vty_out(vty, "%*srt redirect import %s\n", indent, "", b);
12689 XFREE(MTYPE_ECOMMUNITY_STR, b);
12690 }
12691 }
12692
12693
12694 /* BGP node structure. */
12695 static struct cmd_node bgp_node = {
12696 BGP_NODE, "%s(config-router)# ", 1,
12697 };
12698
12699 static struct cmd_node bgp_ipv4_unicast_node = {
12700 BGP_IPV4_NODE, "%s(config-router-af)# ", 1,
12701 };
12702
12703 static struct cmd_node bgp_ipv4_multicast_node = {
12704 BGP_IPV4M_NODE, "%s(config-router-af)# ", 1,
12705 };
12706
12707 static struct cmd_node bgp_ipv4_labeled_unicast_node = {
12708 BGP_IPV4L_NODE, "%s(config-router-af)# ", 1,
12709 };
12710
12711 static struct cmd_node bgp_ipv6_unicast_node = {
12712 BGP_IPV6_NODE, "%s(config-router-af)# ", 1,
12713 };
12714
12715 static struct cmd_node bgp_ipv6_multicast_node = {
12716 BGP_IPV6M_NODE, "%s(config-router-af)# ", 1,
12717 };
12718
12719 static struct cmd_node bgp_ipv6_labeled_unicast_node = {
12720 BGP_IPV6L_NODE, "%s(config-router-af)# ", 1,
12721 };
12722
12723 static struct cmd_node bgp_vpnv4_node = {BGP_VPNV4_NODE,
12724 "%s(config-router-af)# ", 1};
12725
12726 static struct cmd_node bgp_vpnv6_node = {BGP_VPNV6_NODE,
12727 "%s(config-router-af-vpnv6)# ", 1};
12728
12729 static struct cmd_node bgp_evpn_node = {BGP_EVPN_NODE,
12730 "%s(config-router-evpn)# ", 1};
12731
12732 static struct cmd_node bgp_evpn_vni_node = {BGP_EVPN_VNI_NODE,
12733 "%s(config-router-af-vni)# ", 1};
12734
12735 static struct cmd_node bgp_flowspecv4_node = {BGP_FLOWSPECV4_NODE,
12736 "%s(config-router-af)# ", 1};
12737
12738 static struct cmd_node bgp_flowspecv6_node = {BGP_FLOWSPECV6_NODE,
12739 "%s(config-router-af-vpnv6)# ", 1};
12740
12741 static void community_list_vty(void);
12742
12743 static void bgp_ac_neighbor(vector comps, struct cmd_token *token)
12744 {
12745 struct bgp *bgp;
12746 struct peer *peer;
12747 struct listnode *lnbgp, *lnpeer;
12748
12749 for (ALL_LIST_ELEMENTS_RO(bm->bgp, lnbgp, bgp)) {
12750 for (ALL_LIST_ELEMENTS_RO(bgp->peer, lnpeer, peer)) {
12751 /* only provide suggestions on the appropriate input
12752 * token type,
12753 * they'll otherwise show up multiple times */
12754 enum cmd_token_type match_type;
12755 char *name = peer->host;
12756
12757 if (peer->conf_if) {
12758 match_type = VARIABLE_TKN;
12759 name = peer->conf_if;
12760 } else if (strchr(peer->host, ':'))
12761 match_type = IPV6_TKN;
12762 else
12763 match_type = IPV4_TKN;
12764
12765 if (token->type != match_type)
12766 continue;
12767
12768 vector_set(comps, XSTRDUP(MTYPE_COMPLETION, name));
12769 }
12770 }
12771 }
12772
12773 static const struct cmd_variable_handler bgp_var_neighbor[] = {
12774 {.varname = "neighbor", .completions = bgp_ac_neighbor},
12775 {.varname = "neighbors", .completions = bgp_ac_neighbor},
12776 {.varname = "peer", .completions = bgp_ac_neighbor},
12777 {.completions = NULL}};
12778
12779 static void bgp_ac_peergroup(vector comps, struct cmd_token *token)
12780 {
12781 struct bgp *bgp;
12782 struct peer_group *group;
12783 struct listnode *lnbgp, *lnpeer;
12784
12785 for (ALL_LIST_ELEMENTS_RO(bm->bgp, lnbgp, bgp)) {
12786 for (ALL_LIST_ELEMENTS_RO(bgp->group, lnpeer, group))
12787 vector_set(comps, XSTRDUP(MTYPE_COMPLETION,
12788 group->name));
12789 }
12790 }
12791
12792 static const struct cmd_variable_handler bgp_var_peergroup[] = {
12793 {.tokenname = "PGNAME", .completions = bgp_ac_peergroup},
12794 {.completions = NULL} };
12795
12796 void bgp_vty_init(void)
12797 {
12798 cmd_variable_handler_register(bgp_var_neighbor);
12799 cmd_variable_handler_register(bgp_var_peergroup);
12800
12801 /* Install bgp top node. */
12802 install_node(&bgp_node, bgp_config_write);
12803 install_node(&bgp_ipv4_unicast_node, NULL);
12804 install_node(&bgp_ipv4_multicast_node, NULL);
12805 install_node(&bgp_ipv4_labeled_unicast_node, NULL);
12806 install_node(&bgp_ipv6_unicast_node, NULL);
12807 install_node(&bgp_ipv6_multicast_node, NULL);
12808 install_node(&bgp_ipv6_labeled_unicast_node, NULL);
12809 install_node(&bgp_vpnv4_node, NULL);
12810 install_node(&bgp_vpnv6_node, NULL);
12811 install_node(&bgp_evpn_node, NULL);
12812 install_node(&bgp_evpn_vni_node, NULL);
12813 install_node(&bgp_flowspecv4_node, NULL);
12814 install_node(&bgp_flowspecv6_node, NULL);
12815
12816 /* Install default VTY commands to new nodes. */
12817 install_default(BGP_NODE);
12818 install_default(BGP_IPV4_NODE);
12819 install_default(BGP_IPV4M_NODE);
12820 install_default(BGP_IPV4L_NODE);
12821 install_default(BGP_IPV6_NODE);
12822 install_default(BGP_IPV6M_NODE);
12823 install_default(BGP_IPV6L_NODE);
12824 install_default(BGP_VPNV4_NODE);
12825 install_default(BGP_VPNV6_NODE);
12826 install_default(BGP_FLOWSPECV4_NODE);
12827 install_default(BGP_FLOWSPECV6_NODE);
12828 install_default(BGP_EVPN_NODE);
12829 install_default(BGP_EVPN_VNI_NODE);
12830
12831 /* "bgp local-mac" hidden commands. */
12832 install_element(CONFIG_NODE, &bgp_local_mac_cmd);
12833 install_element(CONFIG_NODE, &no_bgp_local_mac_cmd);
12834
12835 /* bgp route-map delay-timer commands. */
12836 install_element(CONFIG_NODE, &bgp_set_route_map_delay_timer_cmd);
12837 install_element(CONFIG_NODE, &no_bgp_set_route_map_delay_timer_cmd);
12838
12839 /* Dummy commands (Currently not supported) */
12840 install_element(BGP_NODE, &no_synchronization_cmd);
12841 install_element(BGP_NODE, &no_auto_summary_cmd);
12842
12843 /* "router bgp" commands. */
12844 install_element(CONFIG_NODE, &router_bgp_cmd);
12845
12846 /* "no router bgp" commands. */
12847 install_element(CONFIG_NODE, &no_router_bgp_cmd);
12848
12849 /* "bgp router-id" commands. */
12850 install_element(BGP_NODE, &bgp_router_id_cmd);
12851 install_element(BGP_NODE, &no_bgp_router_id_cmd);
12852
12853 /* "bgp cluster-id" commands. */
12854 install_element(BGP_NODE, &bgp_cluster_id_cmd);
12855 install_element(BGP_NODE, &no_bgp_cluster_id_cmd);
12856
12857 /* "bgp confederation" commands. */
12858 install_element(BGP_NODE, &bgp_confederation_identifier_cmd);
12859 install_element(BGP_NODE, &no_bgp_confederation_identifier_cmd);
12860
12861 /* "bgp confederation peers" commands. */
12862 install_element(BGP_NODE, &bgp_confederation_peers_cmd);
12863 install_element(BGP_NODE, &no_bgp_confederation_peers_cmd);
12864
12865 /* bgp max-med command */
12866 install_element(BGP_NODE, &bgp_maxmed_admin_cmd);
12867 install_element(BGP_NODE, &no_bgp_maxmed_admin_cmd);
12868 install_element(BGP_NODE, &bgp_maxmed_admin_medv_cmd);
12869 install_element(BGP_NODE, &bgp_maxmed_onstartup_cmd);
12870 install_element(BGP_NODE, &no_bgp_maxmed_onstartup_cmd);
12871
12872 /* bgp disable-ebgp-connected-nh-check */
12873 install_element(BGP_NODE, &bgp_disable_connected_route_check_cmd);
12874 install_element(BGP_NODE, &no_bgp_disable_connected_route_check_cmd);
12875
12876 /* bgp update-delay command */
12877 install_element(BGP_NODE, &bgp_update_delay_cmd);
12878 install_element(BGP_NODE, &no_bgp_update_delay_cmd);
12879 install_element(BGP_NODE, &bgp_update_delay_establish_wait_cmd);
12880
12881 install_element(BGP_NODE, &bgp_wpkt_quanta_cmd);
12882 install_element(BGP_NODE, &no_bgp_wpkt_quanta_cmd);
12883 install_element(BGP_NODE, &bgp_rpkt_quanta_cmd);
12884 install_element(BGP_NODE, &no_bgp_rpkt_quanta_cmd);
12885
12886 install_element(BGP_NODE, &bgp_coalesce_time_cmd);
12887 install_element(BGP_NODE, &no_bgp_coalesce_time_cmd);
12888
12889 /* "maximum-paths" commands. */
12890 install_element(BGP_NODE, &bgp_maxpaths_hidden_cmd);
12891 install_element(BGP_NODE, &no_bgp_maxpaths_hidden_cmd);
12892 install_element(BGP_IPV4_NODE, &bgp_maxpaths_cmd);
12893 install_element(BGP_IPV4_NODE, &no_bgp_maxpaths_cmd);
12894 install_element(BGP_IPV6_NODE, &bgp_maxpaths_cmd);
12895 install_element(BGP_IPV6_NODE, &no_bgp_maxpaths_cmd);
12896 install_element(BGP_NODE, &bgp_maxpaths_ibgp_hidden_cmd);
12897 install_element(BGP_NODE, &bgp_maxpaths_ibgp_cluster_hidden_cmd);
12898 install_element(BGP_NODE, &no_bgp_maxpaths_ibgp_hidden_cmd);
12899 install_element(BGP_IPV4_NODE, &bgp_maxpaths_ibgp_cmd);
12900 install_element(BGP_IPV4_NODE, &bgp_maxpaths_ibgp_cluster_cmd);
12901 install_element(BGP_IPV4_NODE, &no_bgp_maxpaths_ibgp_cmd);
12902 install_element(BGP_IPV6_NODE, &bgp_maxpaths_ibgp_cmd);
12903 install_element(BGP_IPV6_NODE, &bgp_maxpaths_ibgp_cluster_cmd);
12904 install_element(BGP_IPV6_NODE, &no_bgp_maxpaths_ibgp_cmd);
12905
12906 install_element(BGP_IPV6L_NODE, &bgp_maxpaths_cmd);
12907 install_element(BGP_IPV6L_NODE, &no_bgp_maxpaths_cmd);
12908 install_element(BGP_IPV6L_NODE, &bgp_maxpaths_ibgp_cmd);
12909 install_element(BGP_IPV6L_NODE, &bgp_maxpaths_ibgp_cluster_cmd);
12910 install_element(BGP_IPV6L_NODE, &no_bgp_maxpaths_ibgp_cmd);
12911
12912 /* "timers bgp" commands. */
12913 install_element(BGP_NODE, &bgp_timers_cmd);
12914 install_element(BGP_NODE, &no_bgp_timers_cmd);
12915
12916 /* route-map delay-timer commands - per instance for backwards compat.
12917 */
12918 install_element(BGP_NODE, &bgp_set_route_map_delay_timer_cmd);
12919 install_element(BGP_NODE, &no_bgp_set_route_map_delay_timer_cmd);
12920
12921 /* "bgp client-to-client reflection" commands */
12922 install_element(BGP_NODE, &no_bgp_client_to_client_reflection_cmd);
12923 install_element(BGP_NODE, &bgp_client_to_client_reflection_cmd);
12924
12925 /* "bgp always-compare-med" commands */
12926 install_element(BGP_NODE, &bgp_always_compare_med_cmd);
12927 install_element(BGP_NODE, &no_bgp_always_compare_med_cmd);
12928
12929 /* bgp ebgp-requires-policy */
12930 install_element(BGP_NODE, &bgp_ebgp_requires_policy_cmd);
12931 install_element(BGP_NODE, &no_bgp_ebgp_requires_policy_cmd);
12932
12933 /* "bgp deterministic-med" commands */
12934 install_element(BGP_NODE, &bgp_deterministic_med_cmd);
12935 install_element(BGP_NODE, &no_bgp_deterministic_med_cmd);
12936
12937 /* "bgp graceful-restart" commands */
12938 install_element(BGP_NODE, &bgp_graceful_restart_cmd);
12939 install_element(BGP_NODE, &no_bgp_graceful_restart_cmd);
12940 install_element(BGP_NODE, &bgp_graceful_restart_stalepath_time_cmd);
12941 install_element(BGP_NODE, &no_bgp_graceful_restart_stalepath_time_cmd);
12942 install_element(BGP_NODE, &bgp_graceful_restart_restart_time_cmd);
12943 install_element(BGP_NODE, &no_bgp_graceful_restart_restart_time_cmd);
12944
12945 install_element(BGP_NODE, &bgp_graceful_restart_preserve_fw_cmd);
12946 install_element(BGP_NODE, &no_bgp_graceful_restart_preserve_fw_cmd);
12947
12948 /* "bgp graceful-shutdown" commands */
12949 install_element(BGP_NODE, &bgp_graceful_shutdown_cmd);
12950 install_element(BGP_NODE, &no_bgp_graceful_shutdown_cmd);
12951
12952 /* "bgp fast-external-failover" commands */
12953 install_element(BGP_NODE, &bgp_fast_external_failover_cmd);
12954 install_element(BGP_NODE, &no_bgp_fast_external_failover_cmd);
12955
12956 /* "bgp bestpath compare-routerid" commands */
12957 install_element(BGP_NODE, &bgp_bestpath_compare_router_id_cmd);
12958 install_element(BGP_NODE, &no_bgp_bestpath_compare_router_id_cmd);
12959
12960 /* "bgp bestpath as-path ignore" commands */
12961 install_element(BGP_NODE, &bgp_bestpath_aspath_ignore_cmd);
12962 install_element(BGP_NODE, &no_bgp_bestpath_aspath_ignore_cmd);
12963
12964 /* "bgp bestpath as-path confed" commands */
12965 install_element(BGP_NODE, &bgp_bestpath_aspath_confed_cmd);
12966 install_element(BGP_NODE, &no_bgp_bestpath_aspath_confed_cmd);
12967
12968 /* "bgp bestpath as-path multipath-relax" commands */
12969 install_element(BGP_NODE, &bgp_bestpath_aspath_multipath_relax_cmd);
12970 install_element(BGP_NODE, &no_bgp_bestpath_aspath_multipath_relax_cmd);
12971
12972 /* "bgp log-neighbor-changes" commands */
12973 install_element(BGP_NODE, &bgp_log_neighbor_changes_cmd);
12974 install_element(BGP_NODE, &no_bgp_log_neighbor_changes_cmd);
12975
12976 /* "bgp bestpath med" commands */
12977 install_element(BGP_NODE, &bgp_bestpath_med_cmd);
12978 install_element(BGP_NODE, &no_bgp_bestpath_med_cmd);
12979
12980 /* "no bgp default ipv4-unicast" commands. */
12981 install_element(BGP_NODE, &no_bgp_default_ipv4_unicast_cmd);
12982 install_element(BGP_NODE, &bgp_default_ipv4_unicast_cmd);
12983
12984 /* "bgp network import-check" commands. */
12985 install_element(BGP_NODE, &bgp_network_import_check_cmd);
12986 install_element(BGP_NODE, &bgp_network_import_check_exact_cmd);
12987 install_element(BGP_NODE, &no_bgp_network_import_check_cmd);
12988
12989 /* "bgp default local-preference" commands. */
12990 install_element(BGP_NODE, &bgp_default_local_preference_cmd);
12991 install_element(BGP_NODE, &no_bgp_default_local_preference_cmd);
12992
12993 /* bgp default show-hostname */
12994 install_element(BGP_NODE, &bgp_default_show_hostname_cmd);
12995 install_element(BGP_NODE, &no_bgp_default_show_hostname_cmd);
12996
12997 /* "bgp default subgroup-pkt-queue-max" commands. */
12998 install_element(BGP_NODE, &bgp_default_subgroup_pkt_queue_max_cmd);
12999 install_element(BGP_NODE, &no_bgp_default_subgroup_pkt_queue_max_cmd);
13000
13001 /* bgp ibgp-allow-policy-mods command */
13002 install_element(BGP_NODE, &bgp_rr_allow_outbound_policy_cmd);
13003 install_element(BGP_NODE, &no_bgp_rr_allow_outbound_policy_cmd);
13004
13005 /* "bgp listen limit" commands. */
13006 install_element(BGP_NODE, &bgp_listen_limit_cmd);
13007 install_element(BGP_NODE, &no_bgp_listen_limit_cmd);
13008
13009 /* "bgp listen range" commands. */
13010 install_element(BGP_NODE, &bgp_listen_range_cmd);
13011 install_element(BGP_NODE, &no_bgp_listen_range_cmd);
13012
13013 /* "bgp default shutdown" command */
13014 install_element(BGP_NODE, &bgp_default_shutdown_cmd);
13015
13016 /* "neighbor remote-as" commands. */
13017 install_element(BGP_NODE, &neighbor_remote_as_cmd);
13018 install_element(BGP_NODE, &neighbor_interface_config_cmd);
13019 install_element(BGP_NODE, &neighbor_interface_config_v6only_cmd);
13020 install_element(BGP_NODE, &neighbor_interface_config_remote_as_cmd);
13021 install_element(BGP_NODE,
13022 &neighbor_interface_v6only_config_remote_as_cmd);
13023 install_element(BGP_NODE, &no_neighbor_cmd);
13024 install_element(BGP_NODE, &no_neighbor_interface_config_cmd);
13025
13026 /* "neighbor peer-group" commands. */
13027 install_element(BGP_NODE, &neighbor_peer_group_cmd);
13028 install_element(BGP_NODE, &no_neighbor_peer_group_cmd);
13029 install_element(BGP_NODE,
13030 &no_neighbor_interface_peer_group_remote_as_cmd);
13031
13032 /* "neighbor local-as" commands. */
13033 install_element(BGP_NODE, &neighbor_local_as_cmd);
13034 install_element(BGP_NODE, &neighbor_local_as_no_prepend_cmd);
13035 install_element(BGP_NODE, &neighbor_local_as_no_prepend_replace_as_cmd);
13036 install_element(BGP_NODE, &no_neighbor_local_as_cmd);
13037
13038 /* "neighbor solo" commands. */
13039 install_element(BGP_NODE, &neighbor_solo_cmd);
13040 install_element(BGP_NODE, &no_neighbor_solo_cmd);
13041
13042 /* "neighbor password" commands. */
13043 install_element(BGP_NODE, &neighbor_password_cmd);
13044 install_element(BGP_NODE, &no_neighbor_password_cmd);
13045
13046 /* "neighbor activate" commands. */
13047 install_element(BGP_NODE, &neighbor_activate_hidden_cmd);
13048 install_element(BGP_IPV4_NODE, &neighbor_activate_cmd);
13049 install_element(BGP_IPV4M_NODE, &neighbor_activate_cmd);
13050 install_element(BGP_IPV4L_NODE, &neighbor_activate_cmd);
13051 install_element(BGP_IPV6_NODE, &neighbor_activate_cmd);
13052 install_element(BGP_IPV6M_NODE, &neighbor_activate_cmd);
13053 install_element(BGP_IPV6L_NODE, &neighbor_activate_cmd);
13054 install_element(BGP_VPNV4_NODE, &neighbor_activate_cmd);
13055 install_element(BGP_VPNV6_NODE, &neighbor_activate_cmd);
13056 install_element(BGP_FLOWSPECV4_NODE, &neighbor_activate_cmd);
13057 install_element(BGP_FLOWSPECV6_NODE, &neighbor_activate_cmd);
13058 install_element(BGP_EVPN_NODE, &neighbor_activate_cmd);
13059
13060 /* "no neighbor activate" commands. */
13061 install_element(BGP_NODE, &no_neighbor_activate_hidden_cmd);
13062 install_element(BGP_IPV4_NODE, &no_neighbor_activate_cmd);
13063 install_element(BGP_IPV4M_NODE, &no_neighbor_activate_cmd);
13064 install_element(BGP_IPV4L_NODE, &no_neighbor_activate_cmd);
13065 install_element(BGP_IPV6_NODE, &no_neighbor_activate_cmd);
13066 install_element(BGP_IPV6M_NODE, &no_neighbor_activate_cmd);
13067 install_element(BGP_IPV6L_NODE, &no_neighbor_activate_cmd);
13068 install_element(BGP_VPNV4_NODE, &no_neighbor_activate_cmd);
13069 install_element(BGP_VPNV6_NODE, &no_neighbor_activate_cmd);
13070 install_element(BGP_FLOWSPECV4_NODE, &no_neighbor_activate_cmd);
13071 install_element(BGP_FLOWSPECV6_NODE, &no_neighbor_activate_cmd);
13072 install_element(BGP_EVPN_NODE, &no_neighbor_activate_cmd);
13073
13074 /* "neighbor peer-group" set commands. */
13075 install_element(BGP_NODE, &neighbor_set_peer_group_cmd);
13076 install_element(BGP_IPV4_NODE, &neighbor_set_peer_group_hidden_cmd);
13077 install_element(BGP_IPV4M_NODE, &neighbor_set_peer_group_hidden_cmd);
13078 install_element(BGP_IPV6_NODE, &neighbor_set_peer_group_hidden_cmd);
13079 install_element(BGP_IPV6M_NODE, &neighbor_set_peer_group_hidden_cmd);
13080 install_element(BGP_IPV6L_NODE, &neighbor_set_peer_group_hidden_cmd);
13081 install_element(BGP_VPNV4_NODE, &neighbor_set_peer_group_hidden_cmd);
13082 install_element(BGP_VPNV6_NODE, &neighbor_set_peer_group_hidden_cmd);
13083 install_element(BGP_FLOWSPECV4_NODE,
13084 &neighbor_set_peer_group_hidden_cmd);
13085 install_element(BGP_FLOWSPECV6_NODE,
13086 &neighbor_set_peer_group_hidden_cmd);
13087
13088 /* "no neighbor peer-group unset" commands. */
13089 install_element(BGP_NODE, &no_neighbor_set_peer_group_cmd);
13090 install_element(BGP_IPV4_NODE, &no_neighbor_set_peer_group_hidden_cmd);
13091 install_element(BGP_IPV4M_NODE, &no_neighbor_set_peer_group_hidden_cmd);
13092 install_element(BGP_IPV6_NODE, &no_neighbor_set_peer_group_hidden_cmd);
13093 install_element(BGP_IPV6M_NODE, &no_neighbor_set_peer_group_hidden_cmd);
13094 install_element(BGP_IPV6L_NODE, &no_neighbor_set_peer_group_hidden_cmd);
13095 install_element(BGP_VPNV4_NODE, &no_neighbor_set_peer_group_hidden_cmd);
13096 install_element(BGP_VPNV6_NODE, &no_neighbor_set_peer_group_hidden_cmd);
13097 install_element(BGP_FLOWSPECV4_NODE,
13098 &no_neighbor_set_peer_group_hidden_cmd);
13099 install_element(BGP_FLOWSPECV6_NODE,
13100 &no_neighbor_set_peer_group_hidden_cmd);
13101
13102 /* "neighbor softreconfiguration inbound" commands.*/
13103 install_element(BGP_NODE, &neighbor_soft_reconfiguration_hidden_cmd);
13104 install_element(BGP_NODE, &no_neighbor_soft_reconfiguration_hidden_cmd);
13105 install_element(BGP_IPV4_NODE, &neighbor_soft_reconfiguration_cmd);
13106 install_element(BGP_IPV4_NODE, &no_neighbor_soft_reconfiguration_cmd);
13107 install_element(BGP_IPV4L_NODE, &neighbor_soft_reconfiguration_cmd);
13108 install_element(BGP_IPV4L_NODE, &no_neighbor_soft_reconfiguration_cmd);
13109 install_element(BGP_IPV4M_NODE, &neighbor_soft_reconfiguration_cmd);
13110 install_element(BGP_IPV4M_NODE, &no_neighbor_soft_reconfiguration_cmd);
13111 install_element(BGP_IPV6_NODE, &neighbor_soft_reconfiguration_cmd);
13112 install_element(BGP_IPV6_NODE, &no_neighbor_soft_reconfiguration_cmd);
13113 install_element(BGP_IPV6M_NODE, &neighbor_soft_reconfiguration_cmd);
13114 install_element(BGP_IPV6M_NODE, &no_neighbor_soft_reconfiguration_cmd);
13115 install_element(BGP_IPV6L_NODE, &neighbor_soft_reconfiguration_cmd);
13116 install_element(BGP_IPV6L_NODE, &no_neighbor_soft_reconfiguration_cmd);
13117 install_element(BGP_VPNV4_NODE, &neighbor_soft_reconfiguration_cmd);
13118 install_element(BGP_VPNV4_NODE, &no_neighbor_soft_reconfiguration_cmd);
13119 install_element(BGP_VPNV6_NODE, &neighbor_soft_reconfiguration_cmd);
13120 install_element(BGP_VPNV6_NODE, &no_neighbor_soft_reconfiguration_cmd);
13121 install_element(BGP_FLOWSPECV4_NODE,
13122 &neighbor_soft_reconfiguration_cmd);
13123 install_element(BGP_FLOWSPECV4_NODE,
13124 &no_neighbor_soft_reconfiguration_cmd);
13125 install_element(BGP_FLOWSPECV6_NODE,
13126 &neighbor_soft_reconfiguration_cmd);
13127 install_element(BGP_FLOWSPECV6_NODE,
13128 &no_neighbor_soft_reconfiguration_cmd);
13129 install_element(BGP_EVPN_NODE, &neighbor_soft_reconfiguration_cmd);
13130 install_element(BGP_EVPN_NODE, &no_neighbor_soft_reconfiguration_cmd);
13131
13132 /* "neighbor attribute-unchanged" commands. */
13133 install_element(BGP_NODE, &neighbor_attr_unchanged_hidden_cmd);
13134 install_element(BGP_NODE, &no_neighbor_attr_unchanged_hidden_cmd);
13135 install_element(BGP_IPV4_NODE, &neighbor_attr_unchanged_cmd);
13136 install_element(BGP_IPV4_NODE, &no_neighbor_attr_unchanged_cmd);
13137 install_element(BGP_IPV4M_NODE, &neighbor_attr_unchanged_cmd);
13138 install_element(BGP_IPV4M_NODE, &no_neighbor_attr_unchanged_cmd);
13139 install_element(BGP_IPV4L_NODE, &neighbor_attr_unchanged_cmd);
13140 install_element(BGP_IPV4L_NODE, &no_neighbor_attr_unchanged_cmd);
13141 install_element(BGP_IPV6_NODE, &neighbor_attr_unchanged_cmd);
13142 install_element(BGP_IPV6_NODE, &no_neighbor_attr_unchanged_cmd);
13143 install_element(BGP_IPV6M_NODE, &neighbor_attr_unchanged_cmd);
13144 install_element(BGP_IPV6M_NODE, &no_neighbor_attr_unchanged_cmd);
13145 install_element(BGP_IPV6L_NODE, &neighbor_attr_unchanged_cmd);
13146 install_element(BGP_IPV6L_NODE, &no_neighbor_attr_unchanged_cmd);
13147 install_element(BGP_VPNV4_NODE, &neighbor_attr_unchanged_cmd);
13148 install_element(BGP_VPNV4_NODE, &no_neighbor_attr_unchanged_cmd);
13149 install_element(BGP_VPNV6_NODE, &neighbor_attr_unchanged_cmd);
13150 install_element(BGP_VPNV6_NODE, &no_neighbor_attr_unchanged_cmd);
13151
13152 install_element(BGP_EVPN_NODE, &neighbor_attr_unchanged_cmd);
13153 install_element(BGP_EVPN_NODE, &no_neighbor_attr_unchanged_cmd);
13154
13155 /* "nexthop-local unchanged" commands */
13156 install_element(BGP_IPV6_NODE, &neighbor_nexthop_local_unchanged_cmd);
13157 install_element(BGP_IPV6_NODE,
13158 &no_neighbor_nexthop_local_unchanged_cmd);
13159
13160 /* "neighbor next-hop-self" commands. */
13161 install_element(BGP_NODE, &neighbor_nexthop_self_hidden_cmd);
13162 install_element(BGP_NODE, &no_neighbor_nexthop_self_hidden_cmd);
13163 install_element(BGP_IPV4_NODE, &neighbor_nexthop_self_cmd);
13164 install_element(BGP_IPV4_NODE, &no_neighbor_nexthop_self_cmd);
13165 install_element(BGP_IPV4M_NODE, &neighbor_nexthop_self_cmd);
13166 install_element(BGP_IPV4M_NODE, &no_neighbor_nexthop_self_cmd);
13167 install_element(BGP_IPV4L_NODE, &neighbor_nexthop_self_cmd);
13168 install_element(BGP_IPV4L_NODE, &no_neighbor_nexthop_self_cmd);
13169 install_element(BGP_IPV6_NODE, &neighbor_nexthop_self_cmd);
13170 install_element(BGP_IPV6_NODE, &no_neighbor_nexthop_self_cmd);
13171 install_element(BGP_IPV6M_NODE, &neighbor_nexthop_self_cmd);
13172 install_element(BGP_IPV6M_NODE, &no_neighbor_nexthop_self_cmd);
13173 install_element(BGP_IPV6L_NODE, &neighbor_nexthop_self_cmd);
13174 install_element(BGP_IPV6L_NODE, &no_neighbor_nexthop_self_cmd);
13175 install_element(BGP_VPNV4_NODE, &neighbor_nexthop_self_cmd);
13176 install_element(BGP_VPNV4_NODE, &no_neighbor_nexthop_self_cmd);
13177 install_element(BGP_VPNV6_NODE, &neighbor_nexthop_self_cmd);
13178 install_element(BGP_VPNV6_NODE, &no_neighbor_nexthop_self_cmd);
13179 install_element(BGP_EVPN_NODE, &neighbor_nexthop_self_cmd);
13180 install_element(BGP_EVPN_NODE, &no_neighbor_nexthop_self_cmd);
13181
13182 /* "neighbor next-hop-self force" commands. */
13183 install_element(BGP_NODE, &neighbor_nexthop_self_force_hidden_cmd);
13184 install_element(BGP_NODE, &no_neighbor_nexthop_self_force_hidden_cmd);
13185 install_element(BGP_NODE, &neighbor_nexthop_self_all_hidden_cmd);
13186 install_element(BGP_NODE, &no_neighbor_nexthop_self_all_hidden_cmd);
13187 install_element(BGP_IPV4_NODE, &neighbor_nexthop_self_force_cmd);
13188 install_element(BGP_IPV4_NODE, &no_neighbor_nexthop_self_force_cmd);
13189 install_element(BGP_IPV4M_NODE, &neighbor_nexthop_self_force_cmd);
13190 install_element(BGP_IPV4M_NODE, &no_neighbor_nexthop_self_force_cmd);
13191 install_element(BGP_IPV4L_NODE, &neighbor_nexthop_self_force_cmd);
13192 install_element(BGP_IPV4L_NODE, &no_neighbor_nexthop_self_force_cmd);
13193 install_element(BGP_IPV6_NODE, &neighbor_nexthop_self_force_cmd);
13194 install_element(BGP_IPV6_NODE, &no_neighbor_nexthop_self_force_cmd);
13195 install_element(BGP_IPV6M_NODE, &neighbor_nexthop_self_force_cmd);
13196 install_element(BGP_IPV6M_NODE, &no_neighbor_nexthop_self_force_cmd);
13197 install_element(BGP_IPV6L_NODE, &neighbor_nexthop_self_force_cmd);
13198 install_element(BGP_IPV6L_NODE, &no_neighbor_nexthop_self_force_cmd);
13199 install_element(BGP_VPNV4_NODE, &neighbor_nexthop_self_force_cmd);
13200 install_element(BGP_VPNV4_NODE, &no_neighbor_nexthop_self_force_cmd);
13201 install_element(BGP_VPNV6_NODE, &neighbor_nexthop_self_force_cmd);
13202 install_element(BGP_VPNV6_NODE, &no_neighbor_nexthop_self_force_cmd);
13203
13204 /* "neighbor as-override" commands. */
13205 install_element(BGP_NODE, &neighbor_as_override_hidden_cmd);
13206 install_element(BGP_NODE, &no_neighbor_as_override_hidden_cmd);
13207 install_element(BGP_IPV4_NODE, &neighbor_as_override_cmd);
13208 install_element(BGP_IPV4_NODE, &no_neighbor_as_override_cmd);
13209 install_element(BGP_IPV4M_NODE, &neighbor_as_override_cmd);
13210 install_element(BGP_IPV4M_NODE, &no_neighbor_as_override_cmd);
13211 install_element(BGP_IPV4L_NODE, &neighbor_as_override_cmd);
13212 install_element(BGP_IPV4L_NODE, &no_neighbor_as_override_cmd);
13213 install_element(BGP_IPV6_NODE, &neighbor_as_override_cmd);
13214 install_element(BGP_IPV6_NODE, &no_neighbor_as_override_cmd);
13215 install_element(BGP_IPV6M_NODE, &neighbor_as_override_cmd);
13216 install_element(BGP_IPV6M_NODE, &no_neighbor_as_override_cmd);
13217 install_element(BGP_IPV6L_NODE, &neighbor_as_override_cmd);
13218 install_element(BGP_IPV6L_NODE, &no_neighbor_as_override_cmd);
13219 install_element(BGP_VPNV4_NODE, &neighbor_as_override_cmd);
13220 install_element(BGP_VPNV4_NODE, &no_neighbor_as_override_cmd);
13221 install_element(BGP_VPNV6_NODE, &neighbor_as_override_cmd);
13222 install_element(BGP_VPNV6_NODE, &no_neighbor_as_override_cmd);
13223
13224 /* "neighbor remove-private-AS" commands. */
13225 install_element(BGP_NODE, &neighbor_remove_private_as_hidden_cmd);
13226 install_element(BGP_NODE, &no_neighbor_remove_private_as_hidden_cmd);
13227 install_element(BGP_NODE, &neighbor_remove_private_as_all_hidden_cmd);
13228 install_element(BGP_NODE,
13229 &no_neighbor_remove_private_as_all_hidden_cmd);
13230 install_element(BGP_NODE,
13231 &neighbor_remove_private_as_replace_as_hidden_cmd);
13232 install_element(BGP_NODE,
13233 &no_neighbor_remove_private_as_replace_as_hidden_cmd);
13234 install_element(BGP_NODE,
13235 &neighbor_remove_private_as_all_replace_as_hidden_cmd);
13236 install_element(
13237 BGP_NODE,
13238 &no_neighbor_remove_private_as_all_replace_as_hidden_cmd);
13239 install_element(BGP_IPV4_NODE, &neighbor_remove_private_as_cmd);
13240 install_element(BGP_IPV4_NODE, &no_neighbor_remove_private_as_cmd);
13241 install_element(BGP_IPV4_NODE, &neighbor_remove_private_as_all_cmd);
13242 install_element(BGP_IPV4_NODE, &no_neighbor_remove_private_as_all_cmd);
13243 install_element(BGP_IPV4_NODE,
13244 &neighbor_remove_private_as_replace_as_cmd);
13245 install_element(BGP_IPV4_NODE,
13246 &no_neighbor_remove_private_as_replace_as_cmd);
13247 install_element(BGP_IPV4_NODE,
13248 &neighbor_remove_private_as_all_replace_as_cmd);
13249 install_element(BGP_IPV4_NODE,
13250 &no_neighbor_remove_private_as_all_replace_as_cmd);
13251 install_element(BGP_IPV4M_NODE, &neighbor_remove_private_as_cmd);
13252 install_element(BGP_IPV4M_NODE, &no_neighbor_remove_private_as_cmd);
13253 install_element(BGP_IPV4M_NODE, &neighbor_remove_private_as_all_cmd);
13254 install_element(BGP_IPV4M_NODE, &no_neighbor_remove_private_as_all_cmd);
13255 install_element(BGP_IPV4M_NODE,
13256 &neighbor_remove_private_as_replace_as_cmd);
13257 install_element(BGP_IPV4M_NODE,
13258 &no_neighbor_remove_private_as_replace_as_cmd);
13259 install_element(BGP_IPV4M_NODE,
13260 &neighbor_remove_private_as_all_replace_as_cmd);
13261 install_element(BGP_IPV4M_NODE,
13262 &no_neighbor_remove_private_as_all_replace_as_cmd);
13263 install_element(BGP_IPV4L_NODE, &neighbor_remove_private_as_cmd);
13264 install_element(BGP_IPV4L_NODE, &no_neighbor_remove_private_as_cmd);
13265 install_element(BGP_IPV4L_NODE, &neighbor_remove_private_as_all_cmd);
13266 install_element(BGP_IPV4L_NODE, &no_neighbor_remove_private_as_all_cmd);
13267 install_element(BGP_IPV4L_NODE,
13268 &neighbor_remove_private_as_replace_as_cmd);
13269 install_element(BGP_IPV4L_NODE,
13270 &no_neighbor_remove_private_as_replace_as_cmd);
13271 install_element(BGP_IPV4L_NODE,
13272 &neighbor_remove_private_as_all_replace_as_cmd);
13273 install_element(BGP_IPV4L_NODE,
13274 &no_neighbor_remove_private_as_all_replace_as_cmd);
13275 install_element(BGP_IPV6_NODE, &neighbor_remove_private_as_cmd);
13276 install_element(BGP_IPV6_NODE, &no_neighbor_remove_private_as_cmd);
13277 install_element(BGP_IPV6_NODE, &neighbor_remove_private_as_all_cmd);
13278 install_element(BGP_IPV6_NODE, &no_neighbor_remove_private_as_all_cmd);
13279 install_element(BGP_IPV6_NODE,
13280 &neighbor_remove_private_as_replace_as_cmd);
13281 install_element(BGP_IPV6_NODE,
13282 &no_neighbor_remove_private_as_replace_as_cmd);
13283 install_element(BGP_IPV6_NODE,
13284 &neighbor_remove_private_as_all_replace_as_cmd);
13285 install_element(BGP_IPV6_NODE,
13286 &no_neighbor_remove_private_as_all_replace_as_cmd);
13287 install_element(BGP_IPV6M_NODE, &neighbor_remove_private_as_cmd);
13288 install_element(BGP_IPV6M_NODE, &no_neighbor_remove_private_as_cmd);
13289 install_element(BGP_IPV6M_NODE, &neighbor_remove_private_as_all_cmd);
13290 install_element(BGP_IPV6M_NODE, &no_neighbor_remove_private_as_all_cmd);
13291 install_element(BGP_IPV6M_NODE,
13292 &neighbor_remove_private_as_replace_as_cmd);
13293 install_element(BGP_IPV6M_NODE,
13294 &no_neighbor_remove_private_as_replace_as_cmd);
13295 install_element(BGP_IPV6M_NODE,
13296 &neighbor_remove_private_as_all_replace_as_cmd);
13297 install_element(BGP_IPV6M_NODE,
13298 &no_neighbor_remove_private_as_all_replace_as_cmd);
13299 install_element(BGP_IPV6L_NODE, &neighbor_remove_private_as_cmd);
13300 install_element(BGP_IPV6L_NODE, &no_neighbor_remove_private_as_cmd);
13301 install_element(BGP_IPV6L_NODE, &neighbor_remove_private_as_all_cmd);
13302 install_element(BGP_IPV6L_NODE, &no_neighbor_remove_private_as_all_cmd);
13303 install_element(BGP_IPV6L_NODE,
13304 &neighbor_remove_private_as_replace_as_cmd);
13305 install_element(BGP_IPV6L_NODE,
13306 &no_neighbor_remove_private_as_replace_as_cmd);
13307 install_element(BGP_IPV6L_NODE,
13308 &neighbor_remove_private_as_all_replace_as_cmd);
13309 install_element(BGP_IPV6L_NODE,
13310 &no_neighbor_remove_private_as_all_replace_as_cmd);
13311 install_element(BGP_VPNV4_NODE, &neighbor_remove_private_as_cmd);
13312 install_element(BGP_VPNV4_NODE, &no_neighbor_remove_private_as_cmd);
13313 install_element(BGP_VPNV4_NODE, &neighbor_remove_private_as_all_cmd);
13314 install_element(BGP_VPNV4_NODE, &no_neighbor_remove_private_as_all_cmd);
13315 install_element(BGP_VPNV4_NODE,
13316 &neighbor_remove_private_as_replace_as_cmd);
13317 install_element(BGP_VPNV4_NODE,
13318 &no_neighbor_remove_private_as_replace_as_cmd);
13319 install_element(BGP_VPNV4_NODE,
13320 &neighbor_remove_private_as_all_replace_as_cmd);
13321 install_element(BGP_VPNV4_NODE,
13322 &no_neighbor_remove_private_as_all_replace_as_cmd);
13323 install_element(BGP_VPNV6_NODE, &neighbor_remove_private_as_cmd);
13324 install_element(BGP_VPNV6_NODE, &no_neighbor_remove_private_as_cmd);
13325 install_element(BGP_VPNV6_NODE, &neighbor_remove_private_as_all_cmd);
13326 install_element(BGP_VPNV6_NODE, &no_neighbor_remove_private_as_all_cmd);
13327 install_element(BGP_VPNV6_NODE,
13328 &neighbor_remove_private_as_replace_as_cmd);
13329 install_element(BGP_VPNV6_NODE,
13330 &no_neighbor_remove_private_as_replace_as_cmd);
13331 install_element(BGP_VPNV6_NODE,
13332 &neighbor_remove_private_as_all_replace_as_cmd);
13333 install_element(BGP_VPNV6_NODE,
13334 &no_neighbor_remove_private_as_all_replace_as_cmd);
13335
13336 /* "neighbor send-community" commands.*/
13337 install_element(BGP_NODE, &neighbor_send_community_hidden_cmd);
13338 install_element(BGP_NODE, &neighbor_send_community_type_hidden_cmd);
13339 install_element(BGP_NODE, &no_neighbor_send_community_hidden_cmd);
13340 install_element(BGP_NODE, &no_neighbor_send_community_type_hidden_cmd);
13341 install_element(BGP_IPV4_NODE, &neighbor_send_community_cmd);
13342 install_element(BGP_IPV4_NODE, &neighbor_send_community_type_cmd);
13343 install_element(BGP_IPV4_NODE, &no_neighbor_send_community_cmd);
13344 install_element(BGP_IPV4_NODE, &no_neighbor_send_community_type_cmd);
13345 install_element(BGP_IPV4M_NODE, &neighbor_send_community_cmd);
13346 install_element(BGP_IPV4M_NODE, &neighbor_send_community_type_cmd);
13347 install_element(BGP_IPV4M_NODE, &no_neighbor_send_community_cmd);
13348 install_element(BGP_IPV4M_NODE, &no_neighbor_send_community_type_cmd);
13349 install_element(BGP_IPV4L_NODE, &neighbor_send_community_cmd);
13350 install_element(BGP_IPV4L_NODE, &neighbor_send_community_type_cmd);
13351 install_element(BGP_IPV4L_NODE, &no_neighbor_send_community_cmd);
13352 install_element(BGP_IPV4L_NODE, &no_neighbor_send_community_type_cmd);
13353 install_element(BGP_IPV6_NODE, &neighbor_send_community_cmd);
13354 install_element(BGP_IPV6_NODE, &neighbor_send_community_type_cmd);
13355 install_element(BGP_IPV6_NODE, &no_neighbor_send_community_cmd);
13356 install_element(BGP_IPV6_NODE, &no_neighbor_send_community_type_cmd);
13357 install_element(BGP_IPV6M_NODE, &neighbor_send_community_cmd);
13358 install_element(BGP_IPV6M_NODE, &neighbor_send_community_type_cmd);
13359 install_element(BGP_IPV6M_NODE, &no_neighbor_send_community_cmd);
13360 install_element(BGP_IPV6M_NODE, &no_neighbor_send_community_type_cmd);
13361 install_element(BGP_IPV6L_NODE, &neighbor_send_community_cmd);
13362 install_element(BGP_IPV6L_NODE, &neighbor_send_community_type_cmd);
13363 install_element(BGP_IPV6L_NODE, &no_neighbor_send_community_cmd);
13364 install_element(BGP_IPV6L_NODE, &no_neighbor_send_community_type_cmd);
13365 install_element(BGP_VPNV4_NODE, &neighbor_send_community_cmd);
13366 install_element(BGP_VPNV4_NODE, &neighbor_send_community_type_cmd);
13367 install_element(BGP_VPNV4_NODE, &no_neighbor_send_community_cmd);
13368 install_element(BGP_VPNV4_NODE, &no_neighbor_send_community_type_cmd);
13369 install_element(BGP_VPNV6_NODE, &neighbor_send_community_cmd);
13370 install_element(BGP_VPNV6_NODE, &neighbor_send_community_type_cmd);
13371 install_element(BGP_VPNV6_NODE, &no_neighbor_send_community_cmd);
13372 install_element(BGP_VPNV6_NODE, &no_neighbor_send_community_type_cmd);
13373
13374 /* "neighbor route-reflector" commands.*/
13375 install_element(BGP_NODE, &neighbor_route_reflector_client_hidden_cmd);
13376 install_element(BGP_NODE,
13377 &no_neighbor_route_reflector_client_hidden_cmd);
13378 install_element(BGP_IPV4_NODE, &neighbor_route_reflector_client_cmd);
13379 install_element(BGP_IPV4_NODE, &no_neighbor_route_reflector_client_cmd);
13380 install_element(BGP_IPV4M_NODE, &neighbor_route_reflector_client_cmd);
13381 install_element(BGP_IPV4M_NODE,
13382 &no_neighbor_route_reflector_client_cmd);
13383 install_element(BGP_IPV4L_NODE, &neighbor_route_reflector_client_cmd);
13384 install_element(BGP_IPV4L_NODE,
13385 &no_neighbor_route_reflector_client_cmd);
13386 install_element(BGP_IPV6_NODE, &neighbor_route_reflector_client_cmd);
13387 install_element(BGP_IPV6_NODE, &no_neighbor_route_reflector_client_cmd);
13388 install_element(BGP_IPV6M_NODE, &neighbor_route_reflector_client_cmd);
13389 install_element(BGP_IPV6M_NODE,
13390 &no_neighbor_route_reflector_client_cmd);
13391 install_element(BGP_IPV6L_NODE, &neighbor_route_reflector_client_cmd);
13392 install_element(BGP_IPV6L_NODE,
13393 &no_neighbor_route_reflector_client_cmd);
13394 install_element(BGP_VPNV4_NODE, &neighbor_route_reflector_client_cmd);
13395 install_element(BGP_VPNV4_NODE,
13396 &no_neighbor_route_reflector_client_cmd);
13397 install_element(BGP_VPNV6_NODE, &neighbor_route_reflector_client_cmd);
13398 install_element(BGP_VPNV6_NODE,
13399 &no_neighbor_route_reflector_client_cmd);
13400 install_element(BGP_FLOWSPECV4_NODE,
13401 &neighbor_route_reflector_client_cmd);
13402 install_element(BGP_FLOWSPECV4_NODE,
13403 &no_neighbor_route_reflector_client_cmd);
13404 install_element(BGP_FLOWSPECV6_NODE,
13405 &neighbor_route_reflector_client_cmd);
13406 install_element(BGP_FLOWSPECV6_NODE,
13407 &no_neighbor_route_reflector_client_cmd);
13408 install_element(BGP_EVPN_NODE, &neighbor_route_reflector_client_cmd);
13409 install_element(BGP_EVPN_NODE, &no_neighbor_route_reflector_client_cmd);
13410
13411 /* "neighbor route-server" commands.*/
13412 install_element(BGP_NODE, &neighbor_route_server_client_hidden_cmd);
13413 install_element(BGP_NODE, &no_neighbor_route_server_client_hidden_cmd);
13414 install_element(BGP_IPV4_NODE, &neighbor_route_server_client_cmd);
13415 install_element(BGP_IPV4_NODE, &no_neighbor_route_server_client_cmd);
13416 install_element(BGP_IPV4M_NODE, &neighbor_route_server_client_cmd);
13417 install_element(BGP_IPV4M_NODE, &no_neighbor_route_server_client_cmd);
13418 install_element(BGP_IPV4L_NODE, &neighbor_route_server_client_cmd);
13419 install_element(BGP_IPV4L_NODE, &no_neighbor_route_server_client_cmd);
13420 install_element(BGP_IPV6_NODE, &neighbor_route_server_client_cmd);
13421 install_element(BGP_IPV6_NODE, &no_neighbor_route_server_client_cmd);
13422 install_element(BGP_IPV6M_NODE, &neighbor_route_server_client_cmd);
13423 install_element(BGP_IPV6M_NODE, &no_neighbor_route_server_client_cmd);
13424 install_element(BGP_IPV6L_NODE, &neighbor_route_server_client_cmd);
13425 install_element(BGP_IPV6L_NODE, &no_neighbor_route_server_client_cmd);
13426 install_element(BGP_VPNV4_NODE, &neighbor_route_server_client_cmd);
13427 install_element(BGP_VPNV4_NODE, &no_neighbor_route_server_client_cmd);
13428 install_element(BGP_VPNV6_NODE, &neighbor_route_server_client_cmd);
13429 install_element(BGP_VPNV6_NODE, &no_neighbor_route_server_client_cmd);
13430 install_element(BGP_EVPN_NODE, &neighbor_route_server_client_cmd);
13431 install_element(BGP_EVPN_NODE, &no_neighbor_route_server_client_cmd);
13432 install_element(BGP_FLOWSPECV4_NODE, &neighbor_route_server_client_cmd);
13433 install_element(BGP_FLOWSPECV4_NODE,
13434 &no_neighbor_route_server_client_cmd);
13435 install_element(BGP_FLOWSPECV6_NODE, &neighbor_route_server_client_cmd);
13436 install_element(BGP_FLOWSPECV6_NODE,
13437 &no_neighbor_route_server_client_cmd);
13438
13439 /* "neighbor addpath-tx-all-paths" commands.*/
13440 install_element(BGP_NODE, &neighbor_addpath_tx_all_paths_hidden_cmd);
13441 install_element(BGP_NODE, &no_neighbor_addpath_tx_all_paths_hidden_cmd);
13442 install_element(BGP_IPV4_NODE, &neighbor_addpath_tx_all_paths_cmd);
13443 install_element(BGP_IPV4_NODE, &no_neighbor_addpath_tx_all_paths_cmd);
13444 install_element(BGP_IPV4M_NODE, &neighbor_addpath_tx_all_paths_cmd);
13445 install_element(BGP_IPV4M_NODE, &no_neighbor_addpath_tx_all_paths_cmd);
13446 install_element(BGP_IPV4L_NODE, &neighbor_addpath_tx_all_paths_cmd);
13447 install_element(BGP_IPV4L_NODE, &no_neighbor_addpath_tx_all_paths_cmd);
13448 install_element(BGP_IPV6_NODE, &neighbor_addpath_tx_all_paths_cmd);
13449 install_element(BGP_IPV6_NODE, &no_neighbor_addpath_tx_all_paths_cmd);
13450 install_element(BGP_IPV6M_NODE, &neighbor_addpath_tx_all_paths_cmd);
13451 install_element(BGP_IPV6M_NODE, &no_neighbor_addpath_tx_all_paths_cmd);
13452 install_element(BGP_IPV6L_NODE, &neighbor_addpath_tx_all_paths_cmd);
13453 install_element(BGP_IPV6L_NODE, &no_neighbor_addpath_tx_all_paths_cmd);
13454 install_element(BGP_VPNV4_NODE, &neighbor_addpath_tx_all_paths_cmd);
13455 install_element(BGP_VPNV4_NODE, &no_neighbor_addpath_tx_all_paths_cmd);
13456 install_element(BGP_VPNV6_NODE, &neighbor_addpath_tx_all_paths_cmd);
13457 install_element(BGP_VPNV6_NODE, &no_neighbor_addpath_tx_all_paths_cmd);
13458
13459 /* "neighbor addpath-tx-bestpath-per-AS" commands.*/
13460 install_element(BGP_NODE,
13461 &neighbor_addpath_tx_bestpath_per_as_hidden_cmd);
13462 install_element(BGP_NODE,
13463 &no_neighbor_addpath_tx_bestpath_per_as_hidden_cmd);
13464 install_element(BGP_IPV4_NODE,
13465 &neighbor_addpath_tx_bestpath_per_as_cmd);
13466 install_element(BGP_IPV4_NODE,
13467 &no_neighbor_addpath_tx_bestpath_per_as_cmd);
13468 install_element(BGP_IPV4M_NODE,
13469 &neighbor_addpath_tx_bestpath_per_as_cmd);
13470 install_element(BGP_IPV4M_NODE,
13471 &no_neighbor_addpath_tx_bestpath_per_as_cmd);
13472 install_element(BGP_IPV4L_NODE,
13473 &neighbor_addpath_tx_bestpath_per_as_cmd);
13474 install_element(BGP_IPV4L_NODE,
13475 &no_neighbor_addpath_tx_bestpath_per_as_cmd);
13476 install_element(BGP_IPV6_NODE,
13477 &neighbor_addpath_tx_bestpath_per_as_cmd);
13478 install_element(BGP_IPV6_NODE,
13479 &no_neighbor_addpath_tx_bestpath_per_as_cmd);
13480 install_element(BGP_IPV6M_NODE,
13481 &neighbor_addpath_tx_bestpath_per_as_cmd);
13482 install_element(BGP_IPV6M_NODE,
13483 &no_neighbor_addpath_tx_bestpath_per_as_cmd);
13484 install_element(BGP_IPV6L_NODE,
13485 &neighbor_addpath_tx_bestpath_per_as_cmd);
13486 install_element(BGP_IPV6L_NODE,
13487 &no_neighbor_addpath_tx_bestpath_per_as_cmd);
13488 install_element(BGP_VPNV4_NODE,
13489 &neighbor_addpath_tx_bestpath_per_as_cmd);
13490 install_element(BGP_VPNV4_NODE,
13491 &no_neighbor_addpath_tx_bestpath_per_as_cmd);
13492 install_element(BGP_VPNV6_NODE,
13493 &neighbor_addpath_tx_bestpath_per_as_cmd);
13494 install_element(BGP_VPNV6_NODE,
13495 &no_neighbor_addpath_tx_bestpath_per_as_cmd);
13496
13497 /* "neighbor passive" commands. */
13498 install_element(BGP_NODE, &neighbor_passive_cmd);
13499 install_element(BGP_NODE, &no_neighbor_passive_cmd);
13500
13501
13502 /* "neighbor shutdown" commands. */
13503 install_element(BGP_NODE, &neighbor_shutdown_cmd);
13504 install_element(BGP_NODE, &no_neighbor_shutdown_cmd);
13505 install_element(BGP_NODE, &neighbor_shutdown_msg_cmd);
13506 install_element(BGP_NODE, &no_neighbor_shutdown_msg_cmd);
13507
13508 /* "neighbor capability extended-nexthop" commands.*/
13509 install_element(BGP_NODE, &neighbor_capability_enhe_cmd);
13510 install_element(BGP_NODE, &no_neighbor_capability_enhe_cmd);
13511
13512 /* "neighbor capability orf prefix-list" commands.*/
13513 install_element(BGP_NODE, &neighbor_capability_orf_prefix_hidden_cmd);
13514 install_element(BGP_NODE,
13515 &no_neighbor_capability_orf_prefix_hidden_cmd);
13516 install_element(BGP_IPV4_NODE, &neighbor_capability_orf_prefix_cmd);
13517 install_element(BGP_IPV4_NODE, &no_neighbor_capability_orf_prefix_cmd);
13518 install_element(BGP_IPV4M_NODE, &neighbor_capability_orf_prefix_cmd);
13519 install_element(BGP_IPV4M_NODE, &no_neighbor_capability_orf_prefix_cmd);
13520 install_element(BGP_IPV4L_NODE, &neighbor_capability_orf_prefix_cmd);
13521 install_element(BGP_IPV4L_NODE, &no_neighbor_capability_orf_prefix_cmd);
13522 install_element(BGP_IPV6_NODE, &neighbor_capability_orf_prefix_cmd);
13523 install_element(BGP_IPV6_NODE, &no_neighbor_capability_orf_prefix_cmd);
13524 install_element(BGP_IPV6M_NODE, &neighbor_capability_orf_prefix_cmd);
13525 install_element(BGP_IPV6M_NODE, &no_neighbor_capability_orf_prefix_cmd);
13526 install_element(BGP_IPV6L_NODE, &neighbor_capability_orf_prefix_cmd);
13527 install_element(BGP_IPV6L_NODE, &no_neighbor_capability_orf_prefix_cmd);
13528
13529 /* "neighbor capability dynamic" commands.*/
13530 install_element(BGP_NODE, &neighbor_capability_dynamic_cmd);
13531 install_element(BGP_NODE, &no_neighbor_capability_dynamic_cmd);
13532
13533 /* "neighbor dont-capability-negotiate" commands. */
13534 install_element(BGP_NODE, &neighbor_dont_capability_negotiate_cmd);
13535 install_element(BGP_NODE, &no_neighbor_dont_capability_negotiate_cmd);
13536
13537 /* "neighbor ebgp-multihop" commands. */
13538 install_element(BGP_NODE, &neighbor_ebgp_multihop_cmd);
13539 install_element(BGP_NODE, &neighbor_ebgp_multihop_ttl_cmd);
13540 install_element(BGP_NODE, &no_neighbor_ebgp_multihop_cmd);
13541
13542 /* "neighbor disable-connected-check" commands. */
13543 install_element(BGP_NODE, &neighbor_disable_connected_check_cmd);
13544 install_element(BGP_NODE, &no_neighbor_disable_connected_check_cmd);
13545
13546 /* "neighbor enforce-first-as" commands. */
13547 install_element(BGP_NODE, &neighbor_enforce_first_as_cmd);
13548 install_element(BGP_NODE, &no_neighbor_enforce_first_as_cmd);
13549
13550 /* "neighbor description" commands. */
13551 install_element(BGP_NODE, &neighbor_description_cmd);
13552 install_element(BGP_NODE, &no_neighbor_description_cmd);
13553 install_element(BGP_NODE, &no_neighbor_description_comment_cmd);
13554
13555 /* "neighbor update-source" commands. "*/
13556 install_element(BGP_NODE, &neighbor_update_source_cmd);
13557 install_element(BGP_NODE, &no_neighbor_update_source_cmd);
13558
13559 /* "neighbor default-originate" commands. */
13560 install_element(BGP_NODE, &neighbor_default_originate_hidden_cmd);
13561 install_element(BGP_NODE, &neighbor_default_originate_rmap_hidden_cmd);
13562 install_element(BGP_NODE, &no_neighbor_default_originate_hidden_cmd);
13563 install_element(BGP_IPV4_NODE, &neighbor_default_originate_cmd);
13564 install_element(BGP_IPV4_NODE, &neighbor_default_originate_rmap_cmd);
13565 install_element(BGP_IPV4_NODE, &no_neighbor_default_originate_cmd);
13566 install_element(BGP_IPV4M_NODE, &neighbor_default_originate_cmd);
13567 install_element(BGP_IPV4M_NODE, &neighbor_default_originate_rmap_cmd);
13568 install_element(BGP_IPV4M_NODE, &no_neighbor_default_originate_cmd);
13569 install_element(BGP_IPV4L_NODE, &neighbor_default_originate_cmd);
13570 install_element(BGP_IPV4L_NODE, &neighbor_default_originate_rmap_cmd);
13571 install_element(BGP_IPV4L_NODE, &no_neighbor_default_originate_cmd);
13572 install_element(BGP_IPV6_NODE, &neighbor_default_originate_cmd);
13573 install_element(BGP_IPV6_NODE, &neighbor_default_originate_rmap_cmd);
13574 install_element(BGP_IPV6_NODE, &no_neighbor_default_originate_cmd);
13575 install_element(BGP_IPV6M_NODE, &neighbor_default_originate_cmd);
13576 install_element(BGP_IPV6M_NODE, &neighbor_default_originate_rmap_cmd);
13577 install_element(BGP_IPV6M_NODE, &no_neighbor_default_originate_cmd);
13578 install_element(BGP_IPV6L_NODE, &neighbor_default_originate_cmd);
13579 install_element(BGP_IPV6L_NODE, &neighbor_default_originate_rmap_cmd);
13580 install_element(BGP_IPV6L_NODE, &no_neighbor_default_originate_cmd);
13581
13582 /* "neighbor port" commands. */
13583 install_element(BGP_NODE, &neighbor_port_cmd);
13584 install_element(BGP_NODE, &no_neighbor_port_cmd);
13585
13586 /* "neighbor weight" commands. */
13587 install_element(BGP_NODE, &neighbor_weight_hidden_cmd);
13588 install_element(BGP_NODE, &no_neighbor_weight_hidden_cmd);
13589
13590 install_element(BGP_IPV4_NODE, &neighbor_weight_cmd);
13591 install_element(BGP_IPV4_NODE, &no_neighbor_weight_cmd);
13592 install_element(BGP_IPV4M_NODE, &neighbor_weight_cmd);
13593 install_element(BGP_IPV4M_NODE, &no_neighbor_weight_cmd);
13594 install_element(BGP_IPV4L_NODE, &neighbor_weight_cmd);
13595 install_element(BGP_IPV4L_NODE, &no_neighbor_weight_cmd);
13596 install_element(BGP_IPV6_NODE, &neighbor_weight_cmd);
13597 install_element(BGP_IPV6_NODE, &no_neighbor_weight_cmd);
13598 install_element(BGP_IPV6M_NODE, &neighbor_weight_cmd);
13599 install_element(BGP_IPV6M_NODE, &no_neighbor_weight_cmd);
13600 install_element(BGP_IPV6L_NODE, &neighbor_weight_cmd);
13601 install_element(BGP_IPV6L_NODE, &no_neighbor_weight_cmd);
13602 install_element(BGP_VPNV4_NODE, &neighbor_weight_cmd);
13603 install_element(BGP_VPNV4_NODE, &no_neighbor_weight_cmd);
13604 install_element(BGP_VPNV6_NODE, &neighbor_weight_cmd);
13605 install_element(BGP_VPNV6_NODE, &no_neighbor_weight_cmd);
13606
13607 /* "neighbor override-capability" commands. */
13608 install_element(BGP_NODE, &neighbor_override_capability_cmd);
13609 install_element(BGP_NODE, &no_neighbor_override_capability_cmd);
13610
13611 /* "neighbor strict-capability-match" commands. */
13612 install_element(BGP_NODE, &neighbor_strict_capability_cmd);
13613 install_element(BGP_NODE, &no_neighbor_strict_capability_cmd);
13614
13615 /* "neighbor timers" commands. */
13616 install_element(BGP_NODE, &neighbor_timers_cmd);
13617 install_element(BGP_NODE, &no_neighbor_timers_cmd);
13618
13619 /* "neighbor timers connect" commands. */
13620 install_element(BGP_NODE, &neighbor_timers_connect_cmd);
13621 install_element(BGP_NODE, &no_neighbor_timers_connect_cmd);
13622
13623 /* "neighbor advertisement-interval" commands. */
13624 install_element(BGP_NODE, &neighbor_advertise_interval_cmd);
13625 install_element(BGP_NODE, &no_neighbor_advertise_interval_cmd);
13626
13627 /* "neighbor interface" commands. */
13628 install_element(BGP_NODE, &neighbor_interface_cmd);
13629 install_element(BGP_NODE, &no_neighbor_interface_cmd);
13630
13631 /* "neighbor distribute" commands. */
13632 install_element(BGP_NODE, &neighbor_distribute_list_hidden_cmd);
13633 install_element(BGP_NODE, &no_neighbor_distribute_list_hidden_cmd);
13634 install_element(BGP_IPV4_NODE, &neighbor_distribute_list_cmd);
13635 install_element(BGP_IPV4_NODE, &no_neighbor_distribute_list_cmd);
13636 install_element(BGP_IPV4M_NODE, &neighbor_distribute_list_cmd);
13637 install_element(BGP_IPV4M_NODE, &no_neighbor_distribute_list_cmd);
13638 install_element(BGP_IPV4L_NODE, &neighbor_distribute_list_cmd);
13639 install_element(BGP_IPV4L_NODE, &no_neighbor_distribute_list_cmd);
13640 install_element(BGP_IPV6_NODE, &neighbor_distribute_list_cmd);
13641 install_element(BGP_IPV6_NODE, &no_neighbor_distribute_list_cmd);
13642 install_element(BGP_IPV6M_NODE, &neighbor_distribute_list_cmd);
13643 install_element(BGP_IPV6M_NODE, &no_neighbor_distribute_list_cmd);
13644 install_element(BGP_IPV6L_NODE, &neighbor_distribute_list_cmd);
13645 install_element(BGP_IPV6L_NODE, &no_neighbor_distribute_list_cmd);
13646 install_element(BGP_VPNV4_NODE, &neighbor_distribute_list_cmd);
13647 install_element(BGP_VPNV4_NODE, &no_neighbor_distribute_list_cmd);
13648 install_element(BGP_VPNV6_NODE, &neighbor_distribute_list_cmd);
13649 install_element(BGP_VPNV6_NODE, &no_neighbor_distribute_list_cmd);
13650
13651 /* "neighbor prefix-list" commands. */
13652 install_element(BGP_NODE, &neighbor_prefix_list_hidden_cmd);
13653 install_element(BGP_NODE, &no_neighbor_prefix_list_hidden_cmd);
13654 install_element(BGP_IPV4_NODE, &neighbor_prefix_list_cmd);
13655 install_element(BGP_IPV4_NODE, &no_neighbor_prefix_list_cmd);
13656 install_element(BGP_IPV4M_NODE, &neighbor_prefix_list_cmd);
13657 install_element(BGP_IPV4M_NODE, &no_neighbor_prefix_list_cmd);
13658 install_element(BGP_IPV4L_NODE, &neighbor_prefix_list_cmd);
13659 install_element(BGP_IPV4L_NODE, &no_neighbor_prefix_list_cmd);
13660 install_element(BGP_IPV6_NODE, &neighbor_prefix_list_cmd);
13661 install_element(BGP_IPV6_NODE, &no_neighbor_prefix_list_cmd);
13662 install_element(BGP_IPV6M_NODE, &neighbor_prefix_list_cmd);
13663 install_element(BGP_IPV6M_NODE, &no_neighbor_prefix_list_cmd);
13664 install_element(BGP_IPV6L_NODE, &neighbor_prefix_list_cmd);
13665 install_element(BGP_IPV6L_NODE, &no_neighbor_prefix_list_cmd);
13666 install_element(BGP_VPNV4_NODE, &neighbor_prefix_list_cmd);
13667 install_element(BGP_VPNV4_NODE, &no_neighbor_prefix_list_cmd);
13668 install_element(BGP_VPNV6_NODE, &neighbor_prefix_list_cmd);
13669 install_element(BGP_VPNV6_NODE, &no_neighbor_prefix_list_cmd);
13670 install_element(BGP_FLOWSPECV4_NODE, &neighbor_prefix_list_cmd);
13671 install_element(BGP_FLOWSPECV4_NODE, &no_neighbor_prefix_list_cmd);
13672 install_element(BGP_FLOWSPECV6_NODE, &neighbor_prefix_list_cmd);
13673 install_element(BGP_FLOWSPECV6_NODE, &no_neighbor_prefix_list_cmd);
13674
13675 /* "neighbor filter-list" commands. */
13676 install_element(BGP_NODE, &neighbor_filter_list_hidden_cmd);
13677 install_element(BGP_NODE, &no_neighbor_filter_list_hidden_cmd);
13678 install_element(BGP_IPV4_NODE, &neighbor_filter_list_cmd);
13679 install_element(BGP_IPV4_NODE, &no_neighbor_filter_list_cmd);
13680 install_element(BGP_IPV4M_NODE, &neighbor_filter_list_cmd);
13681 install_element(BGP_IPV4M_NODE, &no_neighbor_filter_list_cmd);
13682 install_element(BGP_IPV4L_NODE, &neighbor_filter_list_cmd);
13683 install_element(BGP_IPV4L_NODE, &no_neighbor_filter_list_cmd);
13684 install_element(BGP_IPV6_NODE, &neighbor_filter_list_cmd);
13685 install_element(BGP_IPV6_NODE, &no_neighbor_filter_list_cmd);
13686 install_element(BGP_IPV6M_NODE, &neighbor_filter_list_cmd);
13687 install_element(BGP_IPV6M_NODE, &no_neighbor_filter_list_cmd);
13688 install_element(BGP_IPV6L_NODE, &neighbor_filter_list_cmd);
13689 install_element(BGP_IPV6L_NODE, &no_neighbor_filter_list_cmd);
13690 install_element(BGP_VPNV4_NODE, &neighbor_filter_list_cmd);
13691 install_element(BGP_VPNV4_NODE, &no_neighbor_filter_list_cmd);
13692 install_element(BGP_VPNV6_NODE, &neighbor_filter_list_cmd);
13693 install_element(BGP_VPNV6_NODE, &no_neighbor_filter_list_cmd);
13694 install_element(BGP_FLOWSPECV4_NODE, &neighbor_filter_list_cmd);
13695 install_element(BGP_FLOWSPECV4_NODE, &no_neighbor_filter_list_cmd);
13696 install_element(BGP_FLOWSPECV6_NODE, &neighbor_filter_list_cmd);
13697 install_element(BGP_FLOWSPECV6_NODE, &no_neighbor_filter_list_cmd);
13698
13699 /* "neighbor route-map" commands. */
13700 install_element(BGP_NODE, &neighbor_route_map_hidden_cmd);
13701 install_element(BGP_NODE, &no_neighbor_route_map_hidden_cmd);
13702 install_element(BGP_IPV4_NODE, &neighbor_route_map_cmd);
13703 install_element(BGP_IPV4_NODE, &no_neighbor_route_map_cmd);
13704 install_element(BGP_IPV4M_NODE, &neighbor_route_map_cmd);
13705 install_element(BGP_IPV4M_NODE, &no_neighbor_route_map_cmd);
13706 install_element(BGP_IPV4L_NODE, &neighbor_route_map_cmd);
13707 install_element(BGP_IPV4L_NODE, &no_neighbor_route_map_cmd);
13708 install_element(BGP_IPV6_NODE, &neighbor_route_map_cmd);
13709 install_element(BGP_IPV6_NODE, &no_neighbor_route_map_cmd);
13710 install_element(BGP_IPV6M_NODE, &neighbor_route_map_cmd);
13711 install_element(BGP_IPV6M_NODE, &no_neighbor_route_map_cmd);
13712 install_element(BGP_IPV6L_NODE, &neighbor_route_map_cmd);
13713 install_element(BGP_IPV6L_NODE, &no_neighbor_route_map_cmd);
13714 install_element(BGP_VPNV4_NODE, &neighbor_route_map_cmd);
13715 install_element(BGP_VPNV4_NODE, &no_neighbor_route_map_cmd);
13716 install_element(BGP_VPNV6_NODE, &neighbor_route_map_cmd);
13717 install_element(BGP_VPNV6_NODE, &no_neighbor_route_map_cmd);
13718 install_element(BGP_FLOWSPECV4_NODE, &neighbor_route_map_cmd);
13719 install_element(BGP_FLOWSPECV4_NODE, &no_neighbor_route_map_cmd);
13720 install_element(BGP_FLOWSPECV6_NODE, &neighbor_route_map_cmd);
13721 install_element(BGP_FLOWSPECV6_NODE, &no_neighbor_route_map_cmd);
13722 install_element(BGP_EVPN_NODE, &neighbor_route_map_cmd);
13723 install_element(BGP_EVPN_NODE, &no_neighbor_route_map_cmd);
13724
13725 /* "neighbor unsuppress-map" commands. */
13726 install_element(BGP_NODE, &neighbor_unsuppress_map_hidden_cmd);
13727 install_element(BGP_NODE, &no_neighbor_unsuppress_map_hidden_cmd);
13728 install_element(BGP_IPV4_NODE, &neighbor_unsuppress_map_cmd);
13729 install_element(BGP_IPV4_NODE, &no_neighbor_unsuppress_map_cmd);
13730 install_element(BGP_IPV4M_NODE, &neighbor_unsuppress_map_cmd);
13731 install_element(BGP_IPV4M_NODE, &no_neighbor_unsuppress_map_cmd);
13732 install_element(BGP_IPV4L_NODE, &neighbor_unsuppress_map_cmd);
13733 install_element(BGP_IPV4L_NODE, &no_neighbor_unsuppress_map_cmd);
13734 install_element(BGP_IPV6_NODE, &neighbor_unsuppress_map_cmd);
13735 install_element(BGP_IPV6_NODE, &no_neighbor_unsuppress_map_cmd);
13736 install_element(BGP_IPV6M_NODE, &neighbor_unsuppress_map_cmd);
13737 install_element(BGP_IPV6M_NODE, &no_neighbor_unsuppress_map_cmd);
13738 install_element(BGP_IPV6L_NODE, &neighbor_unsuppress_map_cmd);
13739 install_element(BGP_IPV6L_NODE, &no_neighbor_unsuppress_map_cmd);
13740 install_element(BGP_VPNV4_NODE, &neighbor_unsuppress_map_cmd);
13741 install_element(BGP_VPNV4_NODE, &no_neighbor_unsuppress_map_cmd);
13742 install_element(BGP_VPNV6_NODE, &neighbor_unsuppress_map_cmd);
13743 install_element(BGP_VPNV6_NODE, &no_neighbor_unsuppress_map_cmd);
13744
13745 /* "neighbor maximum-prefix" commands. */
13746 install_element(BGP_NODE, &neighbor_maximum_prefix_hidden_cmd);
13747 install_element(BGP_NODE,
13748 &neighbor_maximum_prefix_threshold_hidden_cmd);
13749 install_element(BGP_NODE, &neighbor_maximum_prefix_warning_hidden_cmd);
13750 install_element(BGP_NODE,
13751 &neighbor_maximum_prefix_threshold_warning_hidden_cmd);
13752 install_element(BGP_NODE, &neighbor_maximum_prefix_restart_hidden_cmd);
13753 install_element(BGP_NODE,
13754 &neighbor_maximum_prefix_threshold_restart_hidden_cmd);
13755 install_element(BGP_NODE, &no_neighbor_maximum_prefix_hidden_cmd);
13756 install_element(BGP_IPV4_NODE, &neighbor_maximum_prefix_cmd);
13757 install_element(BGP_IPV4_NODE, &neighbor_maximum_prefix_threshold_cmd);
13758 install_element(BGP_IPV4_NODE, &neighbor_maximum_prefix_warning_cmd);
13759 install_element(BGP_IPV4_NODE,
13760 &neighbor_maximum_prefix_threshold_warning_cmd);
13761 install_element(BGP_IPV4_NODE, &neighbor_maximum_prefix_restart_cmd);
13762 install_element(BGP_IPV4_NODE,
13763 &neighbor_maximum_prefix_threshold_restart_cmd);
13764 install_element(BGP_IPV4_NODE, &no_neighbor_maximum_prefix_cmd);
13765 install_element(BGP_IPV4M_NODE, &neighbor_maximum_prefix_cmd);
13766 install_element(BGP_IPV4M_NODE, &neighbor_maximum_prefix_threshold_cmd);
13767 install_element(BGP_IPV4M_NODE, &neighbor_maximum_prefix_warning_cmd);
13768 install_element(BGP_IPV4M_NODE,
13769 &neighbor_maximum_prefix_threshold_warning_cmd);
13770 install_element(BGP_IPV4M_NODE, &neighbor_maximum_prefix_restart_cmd);
13771 install_element(BGP_IPV4M_NODE,
13772 &neighbor_maximum_prefix_threshold_restart_cmd);
13773 install_element(BGP_IPV4M_NODE, &no_neighbor_maximum_prefix_cmd);
13774 install_element(BGP_IPV4L_NODE, &neighbor_maximum_prefix_cmd);
13775 install_element(BGP_IPV4L_NODE, &neighbor_maximum_prefix_threshold_cmd);
13776 install_element(BGP_IPV4L_NODE, &neighbor_maximum_prefix_warning_cmd);
13777 install_element(BGP_IPV4L_NODE,
13778 &neighbor_maximum_prefix_threshold_warning_cmd);
13779 install_element(BGP_IPV4L_NODE, &neighbor_maximum_prefix_restart_cmd);
13780 install_element(BGP_IPV4L_NODE,
13781 &neighbor_maximum_prefix_threshold_restart_cmd);
13782 install_element(BGP_IPV4L_NODE, &no_neighbor_maximum_prefix_cmd);
13783 install_element(BGP_IPV6_NODE, &neighbor_maximum_prefix_cmd);
13784 install_element(BGP_IPV6_NODE, &neighbor_maximum_prefix_threshold_cmd);
13785 install_element(BGP_IPV6_NODE, &neighbor_maximum_prefix_warning_cmd);
13786 install_element(BGP_IPV6_NODE,
13787 &neighbor_maximum_prefix_threshold_warning_cmd);
13788 install_element(BGP_IPV6_NODE, &neighbor_maximum_prefix_restart_cmd);
13789 install_element(BGP_IPV6_NODE,
13790 &neighbor_maximum_prefix_threshold_restart_cmd);
13791 install_element(BGP_IPV6_NODE, &no_neighbor_maximum_prefix_cmd);
13792 install_element(BGP_IPV6M_NODE, &neighbor_maximum_prefix_cmd);
13793 install_element(BGP_IPV6M_NODE, &neighbor_maximum_prefix_threshold_cmd);
13794 install_element(BGP_IPV6M_NODE, &neighbor_maximum_prefix_warning_cmd);
13795 install_element(BGP_IPV6M_NODE,
13796 &neighbor_maximum_prefix_threshold_warning_cmd);
13797 install_element(BGP_IPV6M_NODE, &neighbor_maximum_prefix_restart_cmd);
13798 install_element(BGP_IPV6M_NODE,
13799 &neighbor_maximum_prefix_threshold_restart_cmd);
13800 install_element(BGP_IPV6M_NODE, &no_neighbor_maximum_prefix_cmd);
13801 install_element(BGP_IPV6L_NODE, &neighbor_maximum_prefix_cmd);
13802 install_element(BGP_IPV6L_NODE, &neighbor_maximum_prefix_threshold_cmd);
13803 install_element(BGP_IPV6L_NODE, &neighbor_maximum_prefix_warning_cmd);
13804 install_element(BGP_IPV6L_NODE,
13805 &neighbor_maximum_prefix_threshold_warning_cmd);
13806 install_element(BGP_IPV6L_NODE, &neighbor_maximum_prefix_restart_cmd);
13807 install_element(BGP_IPV6L_NODE,
13808 &neighbor_maximum_prefix_threshold_restart_cmd);
13809 install_element(BGP_IPV6L_NODE, &no_neighbor_maximum_prefix_cmd);
13810 install_element(BGP_VPNV4_NODE, &neighbor_maximum_prefix_cmd);
13811 install_element(BGP_VPNV4_NODE, &neighbor_maximum_prefix_threshold_cmd);
13812 install_element(BGP_VPNV4_NODE, &neighbor_maximum_prefix_warning_cmd);
13813 install_element(BGP_VPNV4_NODE,
13814 &neighbor_maximum_prefix_threshold_warning_cmd);
13815 install_element(BGP_VPNV4_NODE, &neighbor_maximum_prefix_restart_cmd);
13816 install_element(BGP_VPNV4_NODE,
13817 &neighbor_maximum_prefix_threshold_restart_cmd);
13818 install_element(BGP_VPNV4_NODE, &no_neighbor_maximum_prefix_cmd);
13819 install_element(BGP_VPNV6_NODE, &neighbor_maximum_prefix_cmd);
13820 install_element(BGP_VPNV6_NODE, &neighbor_maximum_prefix_threshold_cmd);
13821 install_element(BGP_VPNV6_NODE, &neighbor_maximum_prefix_warning_cmd);
13822 install_element(BGP_VPNV6_NODE,
13823 &neighbor_maximum_prefix_threshold_warning_cmd);
13824 install_element(BGP_VPNV6_NODE, &neighbor_maximum_prefix_restart_cmd);
13825 install_element(BGP_VPNV6_NODE,
13826 &neighbor_maximum_prefix_threshold_restart_cmd);
13827 install_element(BGP_VPNV6_NODE, &no_neighbor_maximum_prefix_cmd);
13828
13829 /* "neighbor allowas-in" */
13830 install_element(BGP_NODE, &neighbor_allowas_in_hidden_cmd);
13831 install_element(BGP_NODE, &no_neighbor_allowas_in_hidden_cmd);
13832 install_element(BGP_IPV4_NODE, &neighbor_allowas_in_cmd);
13833 install_element(BGP_IPV4_NODE, &no_neighbor_allowas_in_cmd);
13834 install_element(BGP_IPV4M_NODE, &neighbor_allowas_in_cmd);
13835 install_element(BGP_IPV4M_NODE, &no_neighbor_allowas_in_cmd);
13836 install_element(BGP_IPV4L_NODE, &neighbor_allowas_in_cmd);
13837 install_element(BGP_IPV4L_NODE, &no_neighbor_allowas_in_cmd);
13838 install_element(BGP_IPV6_NODE, &neighbor_allowas_in_cmd);
13839 install_element(BGP_IPV6_NODE, &no_neighbor_allowas_in_cmd);
13840 install_element(BGP_IPV6M_NODE, &neighbor_allowas_in_cmd);
13841 install_element(BGP_IPV6M_NODE, &no_neighbor_allowas_in_cmd);
13842 install_element(BGP_IPV6L_NODE, &neighbor_allowas_in_cmd);
13843 install_element(BGP_IPV6L_NODE, &no_neighbor_allowas_in_cmd);
13844 install_element(BGP_VPNV4_NODE, &neighbor_allowas_in_cmd);
13845 install_element(BGP_VPNV4_NODE, &no_neighbor_allowas_in_cmd);
13846 install_element(BGP_VPNV6_NODE, &neighbor_allowas_in_cmd);
13847 install_element(BGP_VPNV6_NODE, &no_neighbor_allowas_in_cmd);
13848 install_element(BGP_EVPN_NODE, &neighbor_allowas_in_cmd);
13849 install_element(BGP_EVPN_NODE, &no_neighbor_allowas_in_cmd);
13850
13851 /* address-family commands. */
13852 install_element(BGP_NODE, &address_family_ipv4_safi_cmd);
13853 install_element(BGP_NODE, &address_family_ipv6_safi_cmd);
13854 #ifdef KEEP_OLD_VPN_COMMANDS
13855 install_element(BGP_NODE, &address_family_vpnv4_cmd);
13856 install_element(BGP_NODE, &address_family_vpnv6_cmd);
13857 #endif /* KEEP_OLD_VPN_COMMANDS */
13858
13859 install_element(BGP_NODE, &address_family_evpn_cmd);
13860
13861 /* "exit-address-family" command. */
13862 install_element(BGP_IPV4_NODE, &exit_address_family_cmd);
13863 install_element(BGP_IPV4M_NODE, &exit_address_family_cmd);
13864 install_element(BGP_IPV4L_NODE, &exit_address_family_cmd);
13865 install_element(BGP_IPV6_NODE, &exit_address_family_cmd);
13866 install_element(BGP_IPV6M_NODE, &exit_address_family_cmd);
13867 install_element(BGP_IPV6L_NODE, &exit_address_family_cmd);
13868 install_element(BGP_VPNV4_NODE, &exit_address_family_cmd);
13869 install_element(BGP_VPNV6_NODE, &exit_address_family_cmd);
13870 install_element(BGP_FLOWSPECV4_NODE, &exit_address_family_cmd);
13871 install_element(BGP_FLOWSPECV6_NODE, &exit_address_family_cmd);
13872 install_element(BGP_EVPN_NODE, &exit_address_family_cmd);
13873
13874 /* "clear ip bgp commands" */
13875 install_element(ENABLE_NODE, &clear_ip_bgp_all_cmd);
13876
13877 /* clear ip bgp prefix */
13878 install_element(ENABLE_NODE, &clear_ip_bgp_prefix_cmd);
13879 install_element(ENABLE_NODE, &clear_bgp_ipv6_safi_prefix_cmd);
13880 install_element(ENABLE_NODE, &clear_bgp_instance_ipv6_safi_prefix_cmd);
13881
13882 /* "show [ip] bgp summary" commands. */
13883 install_element(VIEW_NODE, &show_bgp_instance_all_ipv6_updgrps_cmd);
13884 install_element(VIEW_NODE, &show_bgp_l2vpn_evpn_updgrps_cmd);
13885 install_element(VIEW_NODE, &show_bgp_instance_updgrps_stats_cmd);
13886 install_element(VIEW_NODE, &show_bgp_updgrps_stats_cmd);
13887 install_element(VIEW_NODE, &show_ip_bgp_instance_updgrps_adj_s_cmd);
13888 install_element(VIEW_NODE, &show_ip_bgp_summary_cmd);
13889 install_element(VIEW_NODE, &show_ip_bgp_updgrps_cmd);
13890
13891 /* "show [ip] bgp neighbors" commands. */
13892 install_element(VIEW_NODE, &show_ip_bgp_neighbors_cmd);
13893
13894 /* "show [ip] bgp peer-group" commands. */
13895 install_element(VIEW_NODE, &show_ip_bgp_peer_groups_cmd);
13896
13897 /* "show [ip] bgp paths" commands. */
13898 install_element(VIEW_NODE, &show_ip_bgp_paths_cmd);
13899
13900 /* "show [ip] bgp community" commands. */
13901 install_element(VIEW_NODE, &show_ip_bgp_community_info_cmd);
13902
13903 /* "show ip bgp large-community" commands. */
13904 install_element(VIEW_NODE, &show_ip_bgp_lcommunity_info_cmd);
13905 /* "show [ip] bgp attribute-info" commands. */
13906 install_element(VIEW_NODE, &show_ip_bgp_attr_info_cmd);
13907 /* "show [ip] bgp route-leak" command */
13908 install_element(VIEW_NODE, &show_ip_bgp_route_leak_cmd);
13909
13910 /* "redistribute" commands. */
13911 install_element(BGP_NODE, &bgp_redistribute_ipv4_hidden_cmd);
13912 install_element(BGP_NODE, &no_bgp_redistribute_ipv4_hidden_cmd);
13913 install_element(BGP_NODE, &bgp_redistribute_ipv4_rmap_hidden_cmd);
13914 install_element(BGP_NODE, &bgp_redistribute_ipv4_metric_hidden_cmd);
13915 install_element(BGP_NODE,
13916 &bgp_redistribute_ipv4_rmap_metric_hidden_cmd);
13917 install_element(BGP_NODE,
13918 &bgp_redistribute_ipv4_metric_rmap_hidden_cmd);
13919 install_element(BGP_NODE, &bgp_redistribute_ipv4_ospf_hidden_cmd);
13920 install_element(BGP_NODE, &no_bgp_redistribute_ipv4_ospf_hidden_cmd);
13921 install_element(BGP_NODE, &bgp_redistribute_ipv4_ospf_rmap_hidden_cmd);
13922 install_element(BGP_NODE,
13923 &bgp_redistribute_ipv4_ospf_metric_hidden_cmd);
13924 install_element(BGP_NODE,
13925 &bgp_redistribute_ipv4_ospf_rmap_metric_hidden_cmd);
13926 install_element(BGP_NODE,
13927 &bgp_redistribute_ipv4_ospf_metric_rmap_hidden_cmd);
13928 install_element(BGP_IPV4_NODE, &bgp_redistribute_ipv4_cmd);
13929 install_element(BGP_IPV4_NODE, &no_bgp_redistribute_ipv4_cmd);
13930 install_element(BGP_IPV4_NODE, &bgp_redistribute_ipv4_rmap_cmd);
13931 install_element(BGP_IPV4_NODE, &bgp_redistribute_ipv4_metric_cmd);
13932 install_element(BGP_IPV4_NODE, &bgp_redistribute_ipv4_rmap_metric_cmd);
13933 install_element(BGP_IPV4_NODE, &bgp_redistribute_ipv4_metric_rmap_cmd);
13934 install_element(BGP_IPV4_NODE, &bgp_redistribute_ipv4_ospf_cmd);
13935 install_element(BGP_IPV4_NODE, &no_bgp_redistribute_ipv4_ospf_cmd);
13936 install_element(BGP_IPV4_NODE, &bgp_redistribute_ipv4_ospf_rmap_cmd);
13937 install_element(BGP_IPV4_NODE, &bgp_redistribute_ipv4_ospf_metric_cmd);
13938 install_element(BGP_IPV4_NODE,
13939 &bgp_redistribute_ipv4_ospf_rmap_metric_cmd);
13940 install_element(BGP_IPV4_NODE,
13941 &bgp_redistribute_ipv4_ospf_metric_rmap_cmd);
13942 install_element(BGP_IPV6_NODE, &bgp_redistribute_ipv6_cmd);
13943 install_element(BGP_IPV6_NODE, &no_bgp_redistribute_ipv6_cmd);
13944 install_element(BGP_IPV6_NODE, &bgp_redistribute_ipv6_rmap_cmd);
13945 install_element(BGP_IPV6_NODE, &bgp_redistribute_ipv6_metric_cmd);
13946 install_element(BGP_IPV6_NODE, &bgp_redistribute_ipv6_rmap_metric_cmd);
13947 install_element(BGP_IPV6_NODE, &bgp_redistribute_ipv6_metric_rmap_cmd);
13948
13949 /* import|export vpn [route-map WORD] */
13950 install_element(BGP_IPV4_NODE, &bgp_imexport_vpn_cmd);
13951 install_element(BGP_IPV6_NODE, &bgp_imexport_vpn_cmd);
13952
13953 install_element(BGP_IPV4_NODE, &bgp_imexport_vrf_cmd);
13954 install_element(BGP_IPV6_NODE, &bgp_imexport_vrf_cmd);
13955
13956 /* ttl_security commands */
13957 install_element(BGP_NODE, &neighbor_ttl_security_cmd);
13958 install_element(BGP_NODE, &no_neighbor_ttl_security_cmd);
13959
13960 /* "show [ip] bgp memory" commands. */
13961 install_element(VIEW_NODE, &show_bgp_memory_cmd);
13962
13963 /* "show bgp martian next-hop" */
13964 install_element(VIEW_NODE, &show_bgp_martian_nexthop_db_cmd);
13965
13966 install_element(VIEW_NODE, &show_bgp_mac_hash_cmd);
13967
13968 /* "show [ip] bgp views" commands. */
13969 install_element(VIEW_NODE, &show_bgp_views_cmd);
13970
13971 /* "show [ip] bgp vrfs" commands. */
13972 install_element(VIEW_NODE, &show_bgp_vrfs_cmd);
13973
13974 /* Community-list. */
13975 community_list_vty();
13976
13977 /* vpn-policy commands */
13978 install_element(BGP_IPV4_NODE, &af_rd_vpn_export_cmd);
13979 install_element(BGP_IPV6_NODE, &af_rd_vpn_export_cmd);
13980 install_element(BGP_IPV4_NODE, &af_label_vpn_export_cmd);
13981 install_element(BGP_IPV6_NODE, &af_label_vpn_export_cmd);
13982 install_element(BGP_IPV4_NODE, &af_nexthop_vpn_export_cmd);
13983 install_element(BGP_IPV6_NODE, &af_nexthop_vpn_export_cmd);
13984 install_element(BGP_IPV4_NODE, &af_rt_vpn_imexport_cmd);
13985 install_element(BGP_IPV6_NODE, &af_rt_vpn_imexport_cmd);
13986 install_element(BGP_IPV4_NODE, &af_route_map_vpn_imexport_cmd);
13987 install_element(BGP_IPV6_NODE, &af_route_map_vpn_imexport_cmd);
13988 install_element(BGP_IPV4_NODE, &af_import_vrf_route_map_cmd);
13989 install_element(BGP_IPV6_NODE, &af_import_vrf_route_map_cmd);
13990
13991 install_element(BGP_IPV4_NODE, &af_routetarget_import_cmd);
13992 install_element(BGP_IPV6_NODE, &af_routetarget_import_cmd);
13993
13994 install_element(BGP_IPV4_NODE, &af_no_rd_vpn_export_cmd);
13995 install_element(BGP_IPV6_NODE, &af_no_rd_vpn_export_cmd);
13996 install_element(BGP_IPV4_NODE, &af_no_label_vpn_export_cmd);
13997 install_element(BGP_IPV6_NODE, &af_no_label_vpn_export_cmd);
13998 install_element(BGP_IPV4_NODE, &af_no_nexthop_vpn_export_cmd);
13999 install_element(BGP_IPV6_NODE, &af_no_nexthop_vpn_export_cmd);
14000 install_element(BGP_IPV4_NODE, &af_no_rt_vpn_imexport_cmd);
14001 install_element(BGP_IPV6_NODE, &af_no_rt_vpn_imexport_cmd);
14002 install_element(BGP_IPV4_NODE, &af_no_route_map_vpn_imexport_cmd);
14003 install_element(BGP_IPV6_NODE, &af_no_route_map_vpn_imexport_cmd);
14004 install_element(BGP_IPV4_NODE, &af_no_import_vrf_route_map_cmd);
14005 install_element(BGP_IPV6_NODE, &af_no_import_vrf_route_map_cmd);
14006 }
14007
14008 #include "memory.h"
14009 #include "bgp_regex.h"
14010 #include "bgp_clist.h"
14011 #include "bgp_ecommunity.h"
14012
14013 /* VTY functions. */
14014
14015 /* Direction value to string conversion. */
14016 static const char *community_direct_str(int direct)
14017 {
14018 switch (direct) {
14019 case COMMUNITY_DENY:
14020 return "deny";
14021 case COMMUNITY_PERMIT:
14022 return "permit";
14023 default:
14024 return "unknown";
14025 }
14026 }
14027
14028 /* Display error string. */
14029 static void community_list_perror(struct vty *vty, int ret)
14030 {
14031 switch (ret) {
14032 case COMMUNITY_LIST_ERR_CANT_FIND_LIST:
14033 vty_out(vty, "%% Can't find community-list\n");
14034 break;
14035 case COMMUNITY_LIST_ERR_MALFORMED_VAL:
14036 vty_out(vty, "%% Malformed community-list value\n");
14037 break;
14038 case COMMUNITY_LIST_ERR_STANDARD_CONFLICT:
14039 vty_out(vty,
14040 "%% Community name conflict, previously defined as standard community\n");
14041 break;
14042 case COMMUNITY_LIST_ERR_EXPANDED_CONFLICT:
14043 vty_out(vty,
14044 "%% Community name conflict, previously defined as expanded community\n");
14045 break;
14046 }
14047 }
14048
14049 /* "community-list" keyword help string. */
14050 #define COMMUNITY_LIST_STR "Add a community list entry\n"
14051
14052 /*community-list standard */
14053 DEFUN (community_list_standard,
14054 bgp_community_list_standard_cmd,
14055 "bgp community-list <(1-99)|standard WORD> <deny|permit> AA:NN...",
14056 BGP_STR
14057 COMMUNITY_LIST_STR
14058 "Community list number (standard)\n"
14059 "Add an standard community-list entry\n"
14060 "Community list name\n"
14061 "Specify community to reject\n"
14062 "Specify community to accept\n"
14063 COMMUNITY_VAL_STR)
14064 {
14065 char *cl_name_or_number = NULL;
14066 int direct = 0;
14067 int style = COMMUNITY_LIST_STANDARD;
14068
14069 int idx = 0;
14070
14071 if (argv_find(argv, argc, "ip", &idx)) {
14072 vty_out(vty, "This config option is deprecated, and is scheduled for removal.\n");
14073 vty_out(vty, "if you are using this please migrate to the below command.\n");
14074 vty_out(vty, "'bgp community-list <(1-99)|(100-500)|standard|expanded> <deny|permit> AA:NN'\n");
14075 zlog_warn("Deprecated option: 'ip community-list <(1-99)|(100-500)|standard|expanded> <deny|permit> AA:NN' being used");
14076 }
14077
14078 argv_find(argv, argc, "(1-99)", &idx);
14079 argv_find(argv, argc, "WORD", &idx);
14080 cl_name_or_number = argv[idx]->arg;
14081 direct = argv_find(argv, argc, "permit", &idx) ? COMMUNITY_PERMIT
14082 : COMMUNITY_DENY;
14083 argv_find(argv, argc, "AA:NN", &idx);
14084 char *str = argv_concat(argv, argc, idx);
14085
14086 int ret = community_list_set(bgp_clist, cl_name_or_number, str, direct,
14087 style);
14088
14089 XFREE(MTYPE_TMP, str);
14090
14091 if (ret < 0) {
14092 /* Display error string. */
14093 community_list_perror(vty, ret);
14094 return CMD_WARNING_CONFIG_FAILED;
14095 }
14096
14097 return CMD_SUCCESS;
14098 }
14099
14100 #if CONFDATE > 20191005
14101 CPP_NOTICE("bgpd: remove deprecated 'ip community-list <(1-99)|(100-500)|standard|expanded> <deny|permit> AA:NN' command")
14102 #endif
14103 ALIAS (community_list_standard,
14104 ip_community_list_standard_cmd,
14105 "ip community-list <(1-99)|standard WORD> <deny|permit> AA:NN...",
14106 IP_STR
14107 COMMUNITY_LIST_STR
14108 "Community list number (standard)\n"
14109 "Add an standard community-list entry\n"
14110 "Community list name\n"
14111 "Specify community to reject\n"
14112 "Specify community to accept\n"
14113 COMMUNITY_VAL_STR)
14114
14115 DEFUN (no_community_list_standard_all,
14116 no_bgp_community_list_standard_all_cmd,
14117 "no bgp community-list <(1-99)|standard WORD> <deny|permit> AA:NN...",
14118 NO_STR
14119 BGP_STR
14120 COMMUNITY_LIST_STR
14121 "Community list number (standard)\n"
14122 "Add an standard community-list entry\n"
14123 "Community list name\n"
14124 "Specify community to reject\n"
14125 "Specify community to accept\n"
14126 COMMUNITY_VAL_STR)
14127 {
14128 char *cl_name_or_number = NULL;
14129 char *str = NULL;
14130 int direct = 0;
14131 int style = COMMUNITY_LIST_STANDARD;
14132
14133 int idx = 0;
14134
14135 if (argv_find(argv, argc, "ip", &idx)) {
14136 vty_out(vty, "This config option is deprecated, and is scheduled for removal\n");
14137 vty_out(vty, "if you are using this please migrate to the below command.\n");
14138 vty_out(vty, "'no bgp community-list <(1-99)|(100-500)|standard|expanded> <deny|permit> AA:NN'\n");
14139 zlog_warn("Deprecated option: 'no ip community-list <(1-99)|(100-500)|standard|expanded> <deny|permit> |AA:NN' being used");
14140 }
14141
14142 argv_find(argv, argc, "permit", &idx);
14143 argv_find(argv, argc, "deny", &idx);
14144
14145 if (idx) {
14146 direct = argv_find(argv, argc, "permit", &idx)
14147 ? COMMUNITY_PERMIT
14148 : COMMUNITY_DENY;
14149
14150 idx = 0;
14151 argv_find(argv, argc, "AA:NN", &idx);
14152 str = argv_concat(argv, argc, idx);
14153 }
14154
14155 idx = 0;
14156 argv_find(argv, argc, "(1-99)", &idx);
14157 argv_find(argv, argc, "WORD", &idx);
14158 cl_name_or_number = argv[idx]->arg;
14159
14160 int ret = community_list_unset(bgp_clist, cl_name_or_number, str,
14161 direct, style);
14162
14163 XFREE(MTYPE_TMP, str);
14164
14165 if (ret < 0) {
14166 community_list_perror(vty, ret);
14167 return CMD_WARNING_CONFIG_FAILED;
14168 }
14169
14170 return CMD_SUCCESS;
14171 }
14172 ALIAS (no_community_list_standard_all,
14173 no_ip_community_list_standard_all_cmd,
14174 "no ip community-list <(1-99)|standard WORD> <deny|permit> AA:NN...",
14175 NO_STR
14176 IP_STR
14177 COMMUNITY_LIST_STR
14178 "Community list number (standard)\n"
14179 "Add an standard community-list entry\n"
14180 "Community list name\n"
14181 "Specify community to reject\n"
14182 "Specify community to accept\n"
14183 COMMUNITY_VAL_STR)
14184
14185 ALIAS(no_community_list_standard_all, no_bgp_community_list_standard_all_list_cmd,
14186 "no bgp community-list <(1-99)|standard WORD>",
14187 NO_STR BGP_STR COMMUNITY_LIST_STR
14188 "Community list number (standard)\n"
14189 "Add an standard community-list entry\n"
14190 "Community list name\n")
14191
14192 ALIAS(no_community_list_standard_all, no_ip_community_list_standard_all_list_cmd,
14193 "no ip community-list <(1-99)|standard WORD>",
14194 NO_STR BGP_STR COMMUNITY_LIST_STR
14195 "Community list number (standard)\n"
14196 "Add an standard community-list entry\n"
14197 "Community list name\n")
14198
14199 /*community-list expanded */
14200 DEFUN (community_list_expanded_all,
14201 bgp_community_list_expanded_all_cmd,
14202 "bgp community-list <(100-500)|expanded WORD> <deny|permit> AA:NN...",
14203 BGP_STR
14204 COMMUNITY_LIST_STR
14205 "Community list number (expanded)\n"
14206 "Add an expanded community-list entry\n"
14207 "Community list name\n"
14208 "Specify community to reject\n"
14209 "Specify community to accept\n"
14210 COMMUNITY_VAL_STR)
14211 {
14212 char *cl_name_or_number = NULL;
14213 int direct = 0;
14214 int style = COMMUNITY_LIST_EXPANDED;
14215
14216 int idx = 0;
14217 if (argv_find(argv, argc, "ip", &idx)) {
14218 vty_out(vty, "This config option is deprecated, and is scheduled for removal.\n");
14219 vty_out(vty, "if you are using this please migrate to the below command.\n");
14220 vty_out(vty, "'bgp community-list <(1-99)|(100-500)|standard|expanded> <deny|permit> AA:NN'\n");
14221 zlog_warn("Deprecated option: 'ip community-list <(1-99)|(100-500)|standard|expanded> <deny|permit> AA:NN' being used");
14222 }
14223 argv_find(argv, argc, "(100-500)", &idx);
14224 argv_find(argv, argc, "WORD", &idx);
14225 cl_name_or_number = argv[idx]->arg;
14226 direct = argv_find(argv, argc, "permit", &idx) ? COMMUNITY_PERMIT
14227 : COMMUNITY_DENY;
14228 argv_find(argv, argc, "AA:NN", &idx);
14229 char *str = argv_concat(argv, argc, idx);
14230
14231 int ret = community_list_set(bgp_clist, cl_name_or_number, str, direct,
14232 style);
14233
14234 XFREE(MTYPE_TMP, str);
14235
14236 if (ret < 0) {
14237 /* Display error string. */
14238 community_list_perror(vty, ret);
14239 return CMD_WARNING_CONFIG_FAILED;
14240 }
14241
14242 return CMD_SUCCESS;
14243 }
14244
14245 ALIAS (community_list_expanded_all,
14246 ip_community_list_expanded_all_cmd,
14247 "ip community-list <(100-500)|expanded WORD> <deny|permit> AA:NN...",
14248 IP_STR
14249 COMMUNITY_LIST_STR
14250 "Community list number (expanded)\n"
14251 "Add an expanded community-list entry\n"
14252 "Community list name\n"
14253 "Specify community to reject\n"
14254 "Specify community to accept\n"
14255 COMMUNITY_VAL_STR)
14256
14257 DEFUN (no_community_list_expanded_all,
14258 no_bgp_community_list_expanded_all_cmd,
14259 "no bgp community-list <(100-500)|expanded WORD> <deny|permit> AA:NN...",
14260 NO_STR
14261 BGP_STR
14262 COMMUNITY_LIST_STR
14263 "Community list number (expanded)\n"
14264 "Add an expanded community-list entry\n"
14265 "Community list name\n"
14266 "Specify community to reject\n"
14267 "Specify community to accept\n"
14268 COMMUNITY_VAL_STR)
14269 {
14270 char *cl_name_or_number = NULL;
14271 char *str = NULL;
14272 int direct = 0;
14273 int style = COMMUNITY_LIST_EXPANDED;
14274
14275 int idx = 0;
14276 if (argv_find(argv, argc, "ip", &idx)) {
14277 vty_out(vty, "This config option is deprecated, and is scheduled for removal.\n");
14278 vty_out(vty, "if you are using this please migrate to the below command.\n");
14279 vty_out(vty, "'no bgp community-list <(1-99)|(100-500)|standard|expanded> <deny|permit> AA:NN'\n");
14280 zlog_warn("Deprecated option: 'no ip community-list <(1-99)|(100-500)|standard|expanded> <deny|permit> AA:NN' being used");
14281 }
14282
14283 idx = 0;
14284 argv_find(argv, argc, "permit", &idx);
14285 argv_find(argv, argc, "deny", &idx);
14286
14287 if (idx) {
14288 direct = argv_find(argv, argc, "permit", &idx)
14289 ? COMMUNITY_PERMIT
14290 : COMMUNITY_DENY;
14291
14292 idx = 0;
14293 argv_find(argv, argc, "AA:NN", &idx);
14294 str = argv_concat(argv, argc, idx);
14295 }
14296
14297 idx = 0;
14298 argv_find(argv, argc, "(100-500)", &idx);
14299 argv_find(argv, argc, "WORD", &idx);
14300 cl_name_or_number = argv[idx]->arg;
14301
14302 int ret = community_list_unset(bgp_clist, cl_name_or_number, str,
14303 direct, style);
14304
14305 XFREE(MTYPE_TMP, str);
14306
14307 if (ret < 0) {
14308 community_list_perror(vty, ret);
14309 return CMD_WARNING_CONFIG_FAILED;
14310 }
14311
14312 return CMD_SUCCESS;
14313 }
14314
14315 ALIAS (no_community_list_expanded_all,
14316 no_ip_community_list_expanded_all_cmd,
14317 "no ip community-list <(100-500)|expanded WORD> <deny|permit> AA:NN...",
14318 NO_STR
14319 IP_STR
14320 COMMUNITY_LIST_STR
14321 "Community list number (expanded)\n"
14322 "Add an expanded community-list entry\n"
14323 "Community list name\n"
14324 "Specify community to reject\n"
14325 "Specify community to accept\n"
14326 COMMUNITY_VAL_STR)
14327
14328 ALIAS(no_community_list_expanded_all, no_bgp_community_list_expanded_all_list_cmd,
14329 "no bgp community-list <(100-500)|expanded WORD>",
14330 NO_STR IP_STR COMMUNITY_LIST_STR
14331 "Community list number (expanded)\n"
14332 "Add an expanded community-list entry\n"
14333 "Community list name\n")
14334
14335 ALIAS(no_community_list_expanded_all, no_ip_community_list_expanded_all_list_cmd,
14336 "no ip community-list <(100-500)|expanded WORD>",
14337 NO_STR IP_STR COMMUNITY_LIST_STR
14338 "Community list number (expanded)\n"
14339 "Add an expanded community-list entry\n"
14340 "Community list name\n")
14341
14342 /* Return configuration string of community-list entry. */
14343 static const char *community_list_config_str(struct community_entry *entry)
14344 {
14345 const char *str;
14346
14347 if (entry->any)
14348 str = "";
14349 else {
14350 if (entry->style == COMMUNITY_LIST_STANDARD)
14351 str = community_str(entry->u.com, false);
14352 else if (entry->style == LARGE_COMMUNITY_LIST_STANDARD)
14353 str = lcommunity_str(entry->u.lcom, false);
14354 else
14355 str = entry->config;
14356 }
14357 return str;
14358 }
14359
14360 static void community_list_show(struct vty *vty, struct community_list *list)
14361 {
14362 struct community_entry *entry;
14363
14364 for (entry = list->head; entry; entry = entry->next) {
14365 if (entry == list->head) {
14366 if (all_digit(list->name))
14367 vty_out(vty, "Community %s list %s\n",
14368 entry->style == COMMUNITY_LIST_STANDARD
14369 ? "standard"
14370 : "(expanded) access",
14371 list->name);
14372 else
14373 vty_out(vty, "Named Community %s list %s\n",
14374 entry->style == COMMUNITY_LIST_STANDARD
14375 ? "standard"
14376 : "expanded",
14377 list->name);
14378 }
14379 if (entry->any)
14380 vty_out(vty, " %s\n",
14381 community_direct_str(entry->direct));
14382 else
14383 vty_out(vty, " %s %s\n",
14384 community_direct_str(entry->direct),
14385 community_list_config_str(entry));
14386 }
14387 }
14388
14389 DEFUN (show_community_list,
14390 show_bgp_community_list_cmd,
14391 "show bgp community-list",
14392 SHOW_STR
14393 BGP_STR
14394 "List community-list\n")
14395 {
14396 struct community_list *list;
14397 struct community_list_master *cm;
14398
14399 int idx = 0;
14400 if (argv_find(argv, argc, "ip", &idx)) {
14401 vty_out(vty, "This config option is deprecated, and is scheduled for removal.\n");
14402 vty_out(vty, "if you are using this please migrate to the below command.\n");
14403 vty_out(vty, "'show bgp community-list <(1-500)|WORD>'\n");
14404 zlog_warn("Deprecated option: 'ip show community-list <(1-500)|WORD>' being used");
14405 }
14406 cm = community_list_master_lookup(bgp_clist, COMMUNITY_LIST_MASTER);
14407 if (!cm)
14408 return CMD_SUCCESS;
14409
14410 for (list = cm->num.head; list; list = list->next)
14411 community_list_show(vty, list);
14412
14413 for (list = cm->str.head; list; list = list->next)
14414 community_list_show(vty, list);
14415
14416 return CMD_SUCCESS;
14417 }
14418
14419 ALIAS (show_community_list,
14420 show_ip_community_list_cmd,
14421 "show ip community-list",
14422 SHOW_STR
14423 IP_STR
14424 "List community-list\n")
14425
14426 DEFUN (show_community_list_arg,
14427 show_bgp_community_list_arg_cmd,
14428 "show bgp community-list <(1-500)|WORD>",
14429 SHOW_STR
14430 BGP_STR
14431 "List community-list\n"
14432 "Community-list number\n"
14433 "Community-list name\n")
14434 {
14435 int idx_comm_list = 3;
14436 struct community_list *list;
14437
14438 int idx = 0;
14439 if (argv_find(argv, argc, "ip", &idx)) {
14440 vty_out(vty, "This config option is deprecated, and is scheduled for removal.\n");
14441 vty_out(vty, "if you are using this please migrate to the below command.\n");
14442 vty_out(vty, "'show bgp community-list <(1-500)|WORD>'\n");
14443 zlog_warn("Deprecated option: 'ip show community-list <(1-500)|WORD>' being used");
14444 }
14445 list = community_list_lookup(bgp_clist, argv[idx_comm_list]->arg, 0,
14446 COMMUNITY_LIST_MASTER);
14447 if (!list) {
14448 vty_out(vty, "%% Can't find community-list\n");
14449 return CMD_WARNING;
14450 }
14451
14452 community_list_show(vty, list);
14453
14454 return CMD_SUCCESS;
14455 }
14456
14457 ALIAS (show_community_list_arg,
14458 show_ip_community_list_arg_cmd,
14459 "show ip community-list <(1-500)|WORD>",
14460 SHOW_STR
14461 IP_STR
14462 "List community-list\n"
14463 "Community-list number\n"
14464 "Community-list name\n")
14465
14466 /*
14467 * Large Community code.
14468 */
14469 static int lcommunity_list_set_vty(struct vty *vty, int argc,
14470 struct cmd_token **argv, int style,
14471 int reject_all_digit_name)
14472 {
14473 int ret;
14474 int direct;
14475 char *str;
14476 int idx = 0;
14477 char *cl_name;
14478
14479 if (argv_find(argv, argc, "ip", &idx)) {
14480 vty_out(vty, "This config option is deprecated, and is scheduled for removal.\n");
14481 vty_out(vty, "if you are using this please migrate to the below command.\n");
14482 vty_out(vty, "'bgp large-community-list <(1-99)|(100-500)|standard|expanded> <deny|permit> <LINE|AA:BB:CC>'\n");
14483 zlog_warn("Deprecated option: 'large-community-list <(1-99)|(100-500)|standard|expanded> <deny|permit> <LINE|AA:BB:CC>' being used");
14484 }
14485 direct = argv_find(argv, argc, "permit", &idx) ? COMMUNITY_PERMIT
14486 : COMMUNITY_DENY;
14487
14488 /* All digit name check. */
14489 idx = 0;
14490 argv_find(argv, argc, "WORD", &idx);
14491 argv_find(argv, argc, "(1-99)", &idx);
14492 argv_find(argv, argc, "(100-500)", &idx);
14493 cl_name = argv[idx]->arg;
14494 if (reject_all_digit_name && all_digit(cl_name)) {
14495 vty_out(vty, "%% Community name cannot have all digits\n");
14496 return CMD_WARNING_CONFIG_FAILED;
14497 }
14498
14499 idx = 0;
14500 argv_find(argv, argc, "AA:BB:CC", &idx);
14501 argv_find(argv, argc, "LINE", &idx);
14502 /* Concat community string argument. */
14503 if (idx)
14504 str = argv_concat(argv, argc, idx);
14505 else
14506 str = NULL;
14507
14508 ret = lcommunity_list_set(bgp_clist, cl_name, str, direct, style);
14509
14510 /* Free temporary community list string allocated by
14511 argv_concat(). */
14512 XFREE(MTYPE_TMP, str);
14513
14514 if (ret < 0) {
14515 community_list_perror(vty, ret);
14516 return CMD_WARNING_CONFIG_FAILED;
14517 }
14518 return CMD_SUCCESS;
14519 }
14520
14521 static int lcommunity_list_unset_vty(struct vty *vty, int argc,
14522 struct cmd_token **argv, int style)
14523 {
14524 int ret;
14525 int direct = 0;
14526 char *str = NULL;
14527 int idx = 0;
14528
14529 if (argv_find(argv, argc, "ip", &idx)) {
14530 vty_out(vty, "This config option is deprecated, and is scheduled for removal.\n");
14531 vty_out(vty, "if you are using this please migrate to the below command.\n");
14532 vty_out(vty, "'no bgp large-community-list <(1-99)|(100-500)|standard|expanded> <deny|permit> <LINE|AA:BB:CC>'\n");
14533 zlog_warn("Deprecated option: 'no ip large-community-list <(1-99)|(100-500)|standard|expanded> <deny|permit> <LINE|AA:BB:CC>' being used");
14534 }
14535 argv_find(argv, argc, "permit", &idx);
14536 argv_find(argv, argc, "deny", &idx);
14537
14538 if (idx) {
14539 /* Check the list direct. */
14540 if (strncmp(argv[idx]->arg, "p", 1) == 0)
14541 direct = COMMUNITY_PERMIT;
14542 else
14543 direct = COMMUNITY_DENY;
14544
14545 idx = 0;
14546 argv_find(argv, argc, "LINE", &idx);
14547 argv_find(argv, argc, "AA:AA:NN", &idx);
14548 /* Concat community string argument. */
14549 str = argv_concat(argv, argc, idx);
14550 }
14551
14552 idx = 0;
14553 argv_find(argv, argc, "(1-99)", &idx);
14554 argv_find(argv, argc, "(100-500)", &idx);
14555 argv_find(argv, argc, "WORD", &idx);
14556
14557 /* Unset community list. */
14558 ret = lcommunity_list_unset(bgp_clist, argv[idx]->arg, str, direct,
14559 style);
14560
14561 /* Free temporary community list string allocated by
14562 argv_concat(). */
14563 XFREE(MTYPE_TMP, str);
14564
14565 if (ret < 0) {
14566 community_list_perror(vty, ret);
14567 return CMD_WARNING_CONFIG_FAILED;
14568 }
14569
14570 return CMD_SUCCESS;
14571 }
14572
14573 /* "large-community-list" keyword help string. */
14574 #define LCOMMUNITY_LIST_STR "Add a large community list entry\n"
14575 #define LCOMMUNITY_VAL_STR "large community in 'aa:bb:cc' format\n"
14576
14577 #if CONFDATE > 20191005
14578 CPP_NOTICE("bgpd: remove deprecated 'ip large-community-list <(1-99)|(100-500)|standard|expanded> <deny|permit> <LINE|AA:BB:CC>' command")
14579 #endif
14580 DEFUN (lcommunity_list_standard,
14581 bgp_lcommunity_list_standard_cmd,
14582 "bgp large-community-list (1-99) <deny|permit>",
14583 BGP_STR
14584 LCOMMUNITY_LIST_STR
14585 "Large Community list number (standard)\n"
14586 "Specify large community to reject\n"
14587 "Specify large community to accept\n")
14588 {
14589 return lcommunity_list_set_vty(vty, argc, argv,
14590 LARGE_COMMUNITY_LIST_STANDARD, 0);
14591 }
14592
14593 ALIAS (lcommunity_list_standard,
14594 ip_lcommunity_list_standard_cmd,
14595 "ip large-community-list (1-99) <deny|permit>",
14596 IP_STR
14597 LCOMMUNITY_LIST_STR
14598 "Large Community list number (standard)\n"
14599 "Specify large community to reject\n"
14600 "Specify large community to accept\n")
14601
14602 DEFUN (lcommunity_list_standard1,
14603 bgp_lcommunity_list_standard1_cmd,
14604 "bgp large-community-list (1-99) <deny|permit> AA:BB:CC...",
14605 BGP_STR
14606 LCOMMUNITY_LIST_STR
14607 "Large Community list number (standard)\n"
14608 "Specify large community to reject\n"
14609 "Specify large community to accept\n"
14610 LCOMMUNITY_VAL_STR)
14611 {
14612 return lcommunity_list_set_vty(vty, argc, argv,
14613 LARGE_COMMUNITY_LIST_STANDARD, 0);
14614 }
14615
14616 ALIAS (lcommunity_list_standard1,
14617 ip_lcommunity_list_standard1_cmd,
14618 "ip large-community-list (1-99) <deny|permit> AA:BB:CC...",
14619 IP_STR
14620 LCOMMUNITY_LIST_STR
14621 "Large Community list number (standard)\n"
14622 "Specify large community to reject\n"
14623 "Specify large community to accept\n"
14624 LCOMMUNITY_VAL_STR)
14625
14626 DEFUN (lcommunity_list_expanded,
14627 bgp_lcommunity_list_expanded_cmd,
14628 "bgp large-community-list (100-500) <deny|permit> LINE...",
14629 BGP_STR
14630 LCOMMUNITY_LIST_STR
14631 "Large Community list number (expanded)\n"
14632 "Specify large community to reject\n"
14633 "Specify large community to accept\n"
14634 "An ordered list as a regular-expression\n")
14635 {
14636 return lcommunity_list_set_vty(vty, argc, argv,
14637 LARGE_COMMUNITY_LIST_EXPANDED, 0);
14638 }
14639
14640 ALIAS (lcommunity_list_expanded,
14641 ip_lcommunity_list_expanded_cmd,
14642 "ip large-community-list (100-500) <deny|permit> LINE...",
14643 IP_STR
14644 LCOMMUNITY_LIST_STR
14645 "Large Community list number (expanded)\n"
14646 "Specify large community to reject\n"
14647 "Specify large community to accept\n"
14648 "An ordered list as a regular-expression\n")
14649
14650 DEFUN (lcommunity_list_name_standard,
14651 bgp_lcommunity_list_name_standard_cmd,
14652 "bgp large-community-list standard WORD <deny|permit>",
14653 BGP_STR
14654 LCOMMUNITY_LIST_STR
14655 "Specify standard large-community-list\n"
14656 "Large Community list name\n"
14657 "Specify large community to reject\n"
14658 "Specify large community to accept\n")
14659 {
14660 return lcommunity_list_set_vty(vty, argc, argv,
14661 LARGE_COMMUNITY_LIST_STANDARD, 1);
14662 }
14663
14664 ALIAS (lcommunity_list_name_standard,
14665 ip_lcommunity_list_name_standard_cmd,
14666 "ip large-community-list standard WORD <deny|permit>",
14667 IP_STR
14668 LCOMMUNITY_LIST_STR
14669 "Specify standard large-community-list\n"
14670 "Large Community list name\n"
14671 "Specify large community to reject\n"
14672 "Specify large community to accept\n")
14673
14674 DEFUN (lcommunity_list_name_standard1,
14675 bgp_lcommunity_list_name_standard1_cmd,
14676 "bgp large-community-list standard WORD <deny|permit> AA:BB:CC...",
14677 BGP_STR
14678 LCOMMUNITY_LIST_STR
14679 "Specify standard large-community-list\n"
14680 "Large Community list name\n"
14681 "Specify large community to reject\n"
14682 "Specify large community to accept\n"
14683 LCOMMUNITY_VAL_STR)
14684 {
14685 return lcommunity_list_set_vty(vty, argc, argv,
14686 LARGE_COMMUNITY_LIST_STANDARD, 1);
14687 }
14688
14689 ALIAS (lcommunity_list_name_standard1,
14690 ip_lcommunity_list_name_standard1_cmd,
14691 "ip large-community-list standard WORD <deny|permit> AA:BB:CC...",
14692 IP_STR
14693 LCOMMUNITY_LIST_STR
14694 "Specify standard large-community-list\n"
14695 "Large Community list name\n"
14696 "Specify large community to reject\n"
14697 "Specify large community to accept\n"
14698 LCOMMUNITY_VAL_STR)
14699
14700 DEFUN (lcommunity_list_name_expanded,
14701 bgp_lcommunity_list_name_expanded_cmd,
14702 "bgp large-community-list expanded WORD <deny|permit> LINE...",
14703 BGP_STR
14704 LCOMMUNITY_LIST_STR
14705 "Specify expanded large-community-list\n"
14706 "Large Community list name\n"
14707 "Specify large community to reject\n"
14708 "Specify large community to accept\n"
14709 "An ordered list as a regular-expression\n")
14710 {
14711 return lcommunity_list_set_vty(vty, argc, argv,
14712 LARGE_COMMUNITY_LIST_EXPANDED, 1);
14713 }
14714
14715 ALIAS (lcommunity_list_name_expanded,
14716 ip_lcommunity_list_name_expanded_cmd,
14717 "ip large-community-list expanded WORD <deny|permit> LINE...",
14718 IP_STR
14719 LCOMMUNITY_LIST_STR
14720 "Specify expanded large-community-list\n"
14721 "Large Community list name\n"
14722 "Specify large community to reject\n"
14723 "Specify large community to accept\n"
14724 "An ordered list as a regular-expression\n")
14725
14726 DEFUN (no_lcommunity_list_standard_all,
14727 no_bgp_lcommunity_list_standard_all_cmd,
14728 "no bgp large-community-list <(1-99)|(100-500)|WORD>",
14729 NO_STR
14730 BGP_STR
14731 LCOMMUNITY_LIST_STR
14732 "Large Community list number (standard)\n"
14733 "Large Community list number (expanded)\n"
14734 "Large Community list name\n")
14735 {
14736 return lcommunity_list_unset_vty(vty, argc, argv,
14737 LARGE_COMMUNITY_LIST_STANDARD);
14738 }
14739
14740 ALIAS (no_lcommunity_list_standard_all,
14741 no_ip_lcommunity_list_standard_all_cmd,
14742 "no ip large-community-list <(1-99)|(100-500)|WORD>",
14743 NO_STR
14744 IP_STR
14745 LCOMMUNITY_LIST_STR
14746 "Large Community list number (standard)\n"
14747 "Large Community list number (expanded)\n"
14748 "Large Community list name\n")
14749
14750 DEFUN (no_lcommunity_list_name_expanded_all,
14751 no_bgp_lcommunity_list_name_expanded_all_cmd,
14752 "no bgp large-community-list expanded WORD",
14753 NO_STR
14754 BGP_STR
14755 LCOMMUNITY_LIST_STR
14756 "Specify expanded large-community-list\n"
14757 "Large Community list name\n")
14758 {
14759 return lcommunity_list_unset_vty(vty, argc, argv,
14760 LARGE_COMMUNITY_LIST_EXPANDED);
14761 }
14762
14763 ALIAS (no_lcommunity_list_name_expanded_all,
14764 no_ip_lcommunity_list_name_expanded_all_cmd,
14765 "no ip large-community-list expanded WORD",
14766 NO_STR
14767 IP_STR
14768 LCOMMUNITY_LIST_STR
14769 "Specify expanded large-community-list\n"
14770 "Large Community list name\n")
14771
14772 DEFUN (no_lcommunity_list_standard,
14773 no_bgp_lcommunity_list_standard_cmd,
14774 "no bgp large-community-list (1-99) <deny|permit> AA:AA:NN...",
14775 NO_STR
14776 BGP_STR
14777 LCOMMUNITY_LIST_STR
14778 "Large Community list number (standard)\n"
14779 "Specify large community to reject\n"
14780 "Specify large community to accept\n"
14781 LCOMMUNITY_VAL_STR)
14782 {
14783 return lcommunity_list_unset_vty(vty, argc, argv,
14784 LARGE_COMMUNITY_LIST_STANDARD);
14785 }
14786
14787 ALIAS (no_lcommunity_list_standard,
14788 no_ip_lcommunity_list_standard_cmd,
14789 "no ip large-community-list (1-99) <deny|permit> AA:AA:NN...",
14790 NO_STR
14791 IP_STR
14792 LCOMMUNITY_LIST_STR
14793 "Large Community list number (standard)\n"
14794 "Specify large community to reject\n"
14795 "Specify large community to accept\n"
14796 LCOMMUNITY_VAL_STR)
14797
14798 DEFUN (no_lcommunity_list_expanded,
14799 no_bgp_lcommunity_list_expanded_cmd,
14800 "no bgp large-community-list (100-500) <deny|permit> LINE...",
14801 NO_STR
14802 BGP_STR
14803 LCOMMUNITY_LIST_STR
14804 "Large Community list number (expanded)\n"
14805 "Specify large community to reject\n"
14806 "Specify large community to accept\n"
14807 "An ordered list as a regular-expression\n")
14808 {
14809 return lcommunity_list_unset_vty(vty, argc, argv,
14810 LARGE_COMMUNITY_LIST_EXPANDED);
14811 }
14812
14813 ALIAS (no_lcommunity_list_expanded,
14814 no_ip_lcommunity_list_expanded_cmd,
14815 "no ip large-community-list (100-500) <deny|permit> LINE...",
14816 NO_STR
14817 IP_STR
14818 LCOMMUNITY_LIST_STR
14819 "Large Community list number (expanded)\n"
14820 "Specify large community to reject\n"
14821 "Specify large community to accept\n"
14822 "An ordered list as a regular-expression\n")
14823
14824 DEFUN (no_lcommunity_list_name_standard,
14825 no_bgp_lcommunity_list_name_standard_cmd,
14826 "no bgp large-community-list standard WORD <deny|permit> AA:AA:NN...",
14827 NO_STR
14828 BGP_STR
14829 LCOMMUNITY_LIST_STR
14830 "Specify standard large-community-list\n"
14831 "Large Community list name\n"
14832 "Specify large community to reject\n"
14833 "Specify large community to accept\n"
14834 LCOMMUNITY_VAL_STR)
14835 {
14836 return lcommunity_list_unset_vty(vty, argc, argv,
14837 LARGE_COMMUNITY_LIST_STANDARD);
14838 }
14839
14840 ALIAS (no_lcommunity_list_name_standard,
14841 no_ip_lcommunity_list_name_standard_cmd,
14842 "no ip large-community-list standard WORD <deny|permit> AA:AA:NN...",
14843 NO_STR
14844 IP_STR
14845 LCOMMUNITY_LIST_STR
14846 "Specify standard large-community-list\n"
14847 "Large Community list name\n"
14848 "Specify large community to reject\n"
14849 "Specify large community to accept\n"
14850 LCOMMUNITY_VAL_STR)
14851
14852 DEFUN (no_lcommunity_list_name_expanded,
14853 no_bgp_lcommunity_list_name_expanded_cmd,
14854 "no bgp large-community-list expanded WORD <deny|permit> LINE...",
14855 NO_STR
14856 BGP_STR
14857 LCOMMUNITY_LIST_STR
14858 "Specify expanded large-community-list\n"
14859 "Large community list name\n"
14860 "Specify large community to reject\n"
14861 "Specify large community to accept\n"
14862 "An ordered list as a regular-expression\n")
14863 {
14864 return lcommunity_list_unset_vty(vty, argc, argv,
14865 LARGE_COMMUNITY_LIST_EXPANDED);
14866 }
14867
14868 ALIAS (no_lcommunity_list_name_expanded,
14869 no_ip_lcommunity_list_name_expanded_cmd,
14870 "no ip large-community-list expanded WORD <deny|permit> LINE...",
14871 NO_STR
14872 IP_STR
14873 LCOMMUNITY_LIST_STR
14874 "Specify expanded large-community-list\n"
14875 "Large community list name\n"
14876 "Specify large community to reject\n"
14877 "Specify large community to accept\n"
14878 "An ordered list as a regular-expression\n")
14879
14880 static void lcommunity_list_show(struct vty *vty, struct community_list *list)
14881 {
14882 struct community_entry *entry;
14883
14884 for (entry = list->head; entry; entry = entry->next) {
14885 if (entry == list->head) {
14886 if (all_digit(list->name))
14887 vty_out(vty, "Large community %s list %s\n",
14888 entry->style ==
14889 LARGE_COMMUNITY_LIST_STANDARD
14890 ? "standard"
14891 : "(expanded) access",
14892 list->name);
14893 else
14894 vty_out(vty,
14895 "Named large community %s list %s\n",
14896 entry->style ==
14897 LARGE_COMMUNITY_LIST_STANDARD
14898 ? "standard"
14899 : "expanded",
14900 list->name);
14901 }
14902 if (entry->any)
14903 vty_out(vty, " %s\n",
14904 community_direct_str(entry->direct));
14905 else
14906 vty_out(vty, " %s %s\n",
14907 community_direct_str(entry->direct),
14908 community_list_config_str(entry));
14909 }
14910 }
14911
14912 DEFUN (show_lcommunity_list,
14913 show_bgp_lcommunity_list_cmd,
14914 "show bgp large-community-list",
14915 SHOW_STR
14916 BGP_STR
14917 "List large-community list\n")
14918 {
14919 struct community_list *list;
14920 struct community_list_master *cm;
14921 int idx = 0;
14922
14923 if (argv_find(argv, argc, "ip", &idx)) {
14924 vty_out(vty, "This config option is deprecated, and is scheduled for removal.\n");
14925 vty_out(vty, "if you are using this please migrate to the below command.\n");
14926 vty_out(vty, "'show bgp large-community-list <(1-500)|WORD>'\n");
14927 zlog_warn("Deprecated option: 'ip show large-community-list <(1-500)|WORD>' being used");
14928 }
14929
14930 cm = community_list_master_lookup(bgp_clist,
14931 LARGE_COMMUNITY_LIST_MASTER);
14932 if (!cm)
14933 return CMD_SUCCESS;
14934
14935 for (list = cm->num.head; list; list = list->next)
14936 lcommunity_list_show(vty, list);
14937
14938 for (list = cm->str.head; list; list = list->next)
14939 lcommunity_list_show(vty, list);
14940
14941 return CMD_SUCCESS;
14942 }
14943
14944 ALIAS (show_lcommunity_list,
14945 show_ip_lcommunity_list_cmd,
14946 "show ip large-community-list",
14947 SHOW_STR
14948 IP_STR
14949 "List large-community list\n")
14950
14951 DEFUN (show_lcommunity_list_arg,
14952 show_bgp_lcommunity_list_arg_cmd,
14953 "show bgp large-community-list <(1-500)|WORD>",
14954 SHOW_STR
14955 BGP_STR
14956 "List large-community list\n"
14957 "large-community-list number\n"
14958 "large-community-list name\n")
14959 {
14960 struct community_list *list;
14961 int idx = 0;
14962
14963 if (argv_find(argv, argc, "ip", &idx)) {
14964 vty_out(vty, "This config option is deprecated, and is scheduled for removal.\n");
14965 vty_out(vty, "if you are using this please migrate to the below command.\n");
14966 vty_out(vty, "'show bgp large-community-list <(1-500)|WORD>'\n");
14967 zlog_warn("Deprecated option: 'ip show large-community-list <(1-500)|WORD>' being used");
14968 }
14969
14970 list = community_list_lookup(bgp_clist, argv[3]->arg, 0,
14971 LARGE_COMMUNITY_LIST_MASTER);
14972 if (!list) {
14973 vty_out(vty, "%% Can't find extcommunity-list\n");
14974 return CMD_WARNING;
14975 }
14976
14977 lcommunity_list_show(vty, list);
14978
14979 return CMD_SUCCESS;
14980 }
14981
14982 ALIAS (show_lcommunity_list_arg,
14983 show_ip_lcommunity_list_arg_cmd,
14984 "show ip large-community-list <(1-500)|WORD>",
14985 SHOW_STR
14986 IP_STR
14987 "List large-community list\n"
14988 "large-community-list number\n"
14989 "large-community-list name\n")
14990
14991 /* "extcommunity-list" keyword help string. */
14992 #define EXTCOMMUNITY_LIST_STR "Add a extended community list entry\n"
14993 #define EXTCOMMUNITY_VAL_STR "Extended community attribute in 'rt aa:nn_or_IPaddr:nn' OR 'soo aa:nn_or_IPaddr:nn' format\n"
14994
14995 DEFUN (extcommunity_list_standard,
14996 bgp_extcommunity_list_standard_cmd,
14997 "bgp extcommunity-list <(1-99)|standard WORD> <deny|permit> AA:NN...",
14998 BGP_STR
14999 EXTCOMMUNITY_LIST_STR
15000 "Extended Community list number (standard)\n"
15001 "Specify standard extcommunity-list\n"
15002 "Community list name\n"
15003 "Specify community to reject\n"
15004 "Specify community to accept\n"
15005 EXTCOMMUNITY_VAL_STR)
15006 {
15007 int style = EXTCOMMUNITY_LIST_STANDARD;
15008 int direct = 0;
15009 char *cl_number_or_name = NULL;
15010
15011 int idx = 0;
15012 if (argv_find(argv, argc, "ip", &idx)) {
15013 vty_out(vty, "This config option is deprecated, and is scheduled for removal.\n");
15014 vty_out(vty, "if you are using this please migrate to the below command.\n");
15015 vty_out(vty, "'bgp extcommunity-list <(1-99)|(100-500)|standard|expanded> <deny|permit> <LINE|AA:NN>'\n");
15016 zlog_warn("Deprecated option: 'ip extcommunity-list <(1-99)|(100-500)|standard|expanded> <deny|permit> <LINE|AA:NN>' being used");
15017 }
15018 argv_find(argv, argc, "(1-99)", &idx);
15019 argv_find(argv, argc, "WORD", &idx);
15020 cl_number_or_name = argv[idx]->arg;
15021 direct = argv_find(argv, argc, "permit", &idx) ? COMMUNITY_PERMIT
15022 : COMMUNITY_DENY;
15023 argv_find(argv, argc, "AA:NN", &idx);
15024 char *str = argv_concat(argv, argc, idx);
15025
15026 int ret = extcommunity_list_set(bgp_clist, cl_number_or_name, str,
15027 direct, style);
15028
15029 XFREE(MTYPE_TMP, str);
15030
15031 if (ret < 0) {
15032 community_list_perror(vty, ret);
15033 return CMD_WARNING_CONFIG_FAILED;
15034 }
15035
15036 return CMD_SUCCESS;
15037 }
15038
15039 #if CONFDATE > 20191005
15040 CPP_NOTICE("bgpd: remove deprecated 'ip extcommunity-list <(1-99)|(100-500)|standard|expanded> <deny|permit> <LINE|AA:NN>' command")
15041 #endif
15042 ALIAS (extcommunity_list_standard,
15043 ip_extcommunity_list_standard_cmd,
15044 "ip extcommunity-list <(1-99)|standard WORD> <deny|permit> AA:NN...",
15045 IP_STR
15046 EXTCOMMUNITY_LIST_STR
15047 "Extended Community list number (standard)\n"
15048 "Specify standard extcommunity-list\n"
15049 "Community list name\n"
15050 "Specify community to reject\n"
15051 "Specify community to accept\n"
15052 EXTCOMMUNITY_VAL_STR)
15053
15054 DEFUN (extcommunity_list_name_expanded,
15055 bgp_extcommunity_list_name_expanded_cmd,
15056 "bgp extcommunity-list <(100-500)|expanded WORD> <deny|permit> LINE...",
15057 BGP_STR
15058 EXTCOMMUNITY_LIST_STR
15059 "Extended Community list number (expanded)\n"
15060 "Specify expanded extcommunity-list\n"
15061 "Extended Community list name\n"
15062 "Specify community to reject\n"
15063 "Specify community to accept\n"
15064 "An ordered list as a regular-expression\n")
15065 {
15066 int style = EXTCOMMUNITY_LIST_EXPANDED;
15067 int direct = 0;
15068 char *cl_number_or_name = NULL;
15069
15070 int idx = 0;
15071 if (argv_find(argv, argc, "ip", &idx)) {
15072 vty_out(vty, "This config option is deprecated, and is scheduled for removal.\n");
15073 vty_out(vty, "if you are using this please migrate to the below command.\n");
15074 vty_out(vty, "'extcommunity-list <(1-99)|(100-500)|standard|expanded> <deny|permit> <LINE|AA:NN>'\n");
15075 zlog_warn("Deprecated option: ‘ip extcommunity-list <(1-99)|(100-500)|standard|expanded> <deny|permit> <LINE|AA:NN>' being used");
15076 }
15077
15078 argv_find(argv, argc, "(100-500)", &idx);
15079 argv_find(argv, argc, "WORD", &idx);
15080 cl_number_or_name = argv[idx]->arg;
15081 direct = argv_find(argv, argc, "permit", &idx) ? COMMUNITY_PERMIT
15082 : COMMUNITY_DENY;
15083 argv_find(argv, argc, "LINE", &idx);
15084 char *str = argv_concat(argv, argc, idx);
15085
15086 int ret = extcommunity_list_set(bgp_clist, cl_number_or_name, str,
15087 direct, style);
15088
15089 XFREE(MTYPE_TMP, str);
15090
15091 if (ret < 0) {
15092 community_list_perror(vty, ret);
15093 return CMD_WARNING_CONFIG_FAILED;
15094 }
15095
15096 return CMD_SUCCESS;
15097 }
15098
15099 ALIAS (extcommunity_list_name_expanded,
15100 ip_extcommunity_list_name_expanded_cmd,
15101 "ip extcommunity-list <(100-500)|expanded WORD> <deny|permit> LINE...",
15102 IP_STR
15103 EXTCOMMUNITY_LIST_STR
15104 "Extended Community list number (expanded)\n"
15105 "Specify expanded extcommunity-list\n"
15106 "Extended Community list name\n"
15107 "Specify community to reject\n"
15108 "Specify community to accept\n"
15109 "An ordered list as a regular-expression\n")
15110
15111 DEFUN (no_extcommunity_list_standard_all,
15112 no_bgp_extcommunity_list_standard_all_cmd,
15113 "no bgp extcommunity-list <(1-99)|standard WORD> <deny|permit> AA:NN...",
15114 NO_STR
15115 BGP_STR
15116 EXTCOMMUNITY_LIST_STR
15117 "Extended Community list number (standard)\n"
15118 "Specify standard extcommunity-list\n"
15119 "Community list name\n"
15120 "Specify community to reject\n"
15121 "Specify community to accept\n"
15122 EXTCOMMUNITY_VAL_STR)
15123 {
15124 int style = EXTCOMMUNITY_LIST_STANDARD;
15125 int direct = 0;
15126 char *cl_number_or_name = NULL;
15127 char *str = NULL;
15128
15129 int idx = 0;
15130 if (argv_find(argv, argc, "ip", &idx)) {
15131 vty_out(vty, "This config option is deprecated, and is scheduled for removal\n");
15132 vty_out(vty, "if you are using this please migrate to the below command.\n");
15133 vty_out(vty, "'no bgp extcommunity-list <(1-99)|(100-500)|standard|expanded> <deny|permit> <LINE|AA:NN>'\n");
15134 zlog_warn("Deprecated option: ‘no ip extcommunity-list <(1-99)|(100-500)|standard|expanded> <deny|permit> <LINE|AA:NN>' being used");
15135 }
15136
15137 idx = 0;
15138 argv_find(argv, argc, "permit", &idx);
15139 argv_find(argv, argc, "deny", &idx);
15140
15141 if (idx) {
15142 direct = argv_find(argv, argc, "permit", &idx)
15143 ? COMMUNITY_PERMIT
15144 : COMMUNITY_DENY;
15145
15146 idx = 0;
15147 argv_find(argv, argc, "AA:NN", &idx);
15148 str = argv_concat(argv, argc, idx);
15149 }
15150
15151 idx = 0;
15152 argv_find(argv, argc, "(1-99)", &idx);
15153 argv_find(argv, argc, "WORD", &idx);
15154 cl_number_or_name = argv[idx]->arg;
15155
15156 int ret = extcommunity_list_unset(bgp_clist, cl_number_or_name, str,
15157 direct, style);
15158
15159 XFREE(MTYPE_TMP, str);
15160
15161 if (ret < 0) {
15162 community_list_perror(vty, ret);
15163 return CMD_WARNING_CONFIG_FAILED;
15164 }
15165
15166 return CMD_SUCCESS;
15167 }
15168
15169 ALIAS (no_extcommunity_list_standard_all,
15170 no_ip_extcommunity_list_standard_all_cmd,
15171 "no ip extcommunity-list <(1-99)|standard WORD> <deny|permit> AA:NN...",
15172 NO_STR
15173 IP_STR
15174 EXTCOMMUNITY_LIST_STR
15175 "Extended Community list number (standard)\n"
15176 "Specify standard extcommunity-list\n"
15177 "Community list name\n"
15178 "Specify community to reject\n"
15179 "Specify community to accept\n"
15180 EXTCOMMUNITY_VAL_STR)
15181
15182 ALIAS(no_extcommunity_list_standard_all,
15183 no_bgp_extcommunity_list_standard_all_list_cmd,
15184 "no bgp extcommunity-list <(1-99)|standard WORD>",
15185 NO_STR IP_STR EXTCOMMUNITY_LIST_STR
15186 "Extended Community list number (standard)\n"
15187 "Specify standard extcommunity-list\n"
15188 "Community list name\n")
15189
15190 ALIAS(no_extcommunity_list_standard_all,
15191 no_ip_extcommunity_list_standard_all_list_cmd,
15192 "no ip extcommunity-list <(1-99)|standard WORD>",
15193 NO_STR IP_STR EXTCOMMUNITY_LIST_STR
15194 "Extended Community list number (standard)\n"
15195 "Specify standard extcommunity-list\n"
15196 "Community list name\n")
15197
15198 DEFUN (no_extcommunity_list_expanded_all,
15199 no_bgp_extcommunity_list_expanded_all_cmd,
15200 "no bgp extcommunity-list <(100-500)|expanded WORD> <deny|permit> LINE...",
15201 NO_STR
15202 BGP_STR
15203 EXTCOMMUNITY_LIST_STR
15204 "Extended Community list number (expanded)\n"
15205 "Specify expanded extcommunity-list\n"
15206 "Extended Community list name\n"
15207 "Specify community to reject\n"
15208 "Specify community to accept\n"
15209 "An ordered list as a regular-expression\n")
15210 {
15211 int style = EXTCOMMUNITY_LIST_EXPANDED;
15212 int direct = 0;
15213 char *cl_number_or_name = NULL;
15214 char *str = NULL;
15215
15216 int idx = 0;
15217 if (argv_find(argv, argc, "ip", &idx)) {
15218 vty_out(vty, "This config option is deprecated, and is scheduled for removal.\n");
15219 vty_out(vty, "if you are using this please migrate to the below command.\n");
15220 vty_out(vty, "'no bgp extcommunity-list <(1-99)|(100-500)|standard|expanded> <deny|permit> <LINE|AA:NN>'\n");
15221 zlog_warn("Deprecated option: ‘no ip extcommunity-list <(1-99)|(100-500)|standard|expanded> <deny|permit> <LINE|AA:NN>' being used");
15222 }
15223
15224 idx = 0;
15225 argv_find(argv, argc, "permit", &idx);
15226 argv_find(argv, argc, "deny", &idx);
15227
15228 if (idx) {
15229 direct = argv_find(argv, argc, "permit", &idx)
15230 ? COMMUNITY_PERMIT
15231 : COMMUNITY_DENY;
15232
15233 idx = 0;
15234 argv_find(argv, argc, "LINE", &idx);
15235 str = argv_concat(argv, argc, idx);
15236 }
15237
15238 idx = 0;
15239 argv_find(argv, argc, "(100-500)", &idx);
15240 argv_find(argv, argc, "WORD", &idx);
15241 cl_number_or_name = argv[idx]->arg;
15242
15243 int ret = extcommunity_list_unset(bgp_clist, cl_number_or_name, str,
15244 direct, style);
15245
15246 XFREE(MTYPE_TMP, str);
15247
15248 if (ret < 0) {
15249 community_list_perror(vty, ret);
15250 return CMD_WARNING_CONFIG_FAILED;
15251 }
15252
15253 return CMD_SUCCESS;
15254 }
15255
15256 ALIAS (no_extcommunity_list_expanded_all,
15257 no_ip_extcommunity_list_expanded_all_cmd,
15258 "no ip extcommunity-list <(100-500)|expanded WORD> <deny|permit> LINE...",
15259 NO_STR
15260 IP_STR
15261 EXTCOMMUNITY_LIST_STR
15262 "Extended Community list number (expanded)\n"
15263 "Specify expanded extcommunity-list\n"
15264 "Extended Community list name\n"
15265 "Specify community to reject\n"
15266 "Specify community to accept\n"
15267 "An ordered list as a regular-expression\n")
15268
15269 ALIAS(no_extcommunity_list_expanded_all,
15270 no_ip_extcommunity_list_expanded_all_list_cmd,
15271 "no ip extcommunity-list <(100-500)|expanded WORD>",
15272 NO_STR IP_STR EXTCOMMUNITY_LIST_STR
15273 "Extended Community list number (expanded)\n"
15274 "Specify expanded extcommunity-list\n"
15275 "Extended Community list name\n")
15276
15277 ALIAS(no_extcommunity_list_expanded_all,
15278 no_bgp_extcommunity_list_expanded_all_list_cmd,
15279 "no bgp extcommunity-list <(100-500)|expanded WORD>",
15280 NO_STR IP_STR EXTCOMMUNITY_LIST_STR
15281 "Extended Community list number (expanded)\n"
15282 "Specify expanded extcommunity-list\n"
15283 "Extended Community list name\n")
15284
15285 static void extcommunity_list_show(struct vty *vty, struct community_list *list)
15286 {
15287 struct community_entry *entry;
15288
15289 for (entry = list->head; entry; entry = entry->next) {
15290 if (entry == list->head) {
15291 if (all_digit(list->name))
15292 vty_out(vty, "Extended community %s list %s\n",
15293 entry->style == EXTCOMMUNITY_LIST_STANDARD
15294 ? "standard"
15295 : "(expanded) access",
15296 list->name);
15297 else
15298 vty_out(vty,
15299 "Named extended community %s list %s\n",
15300 entry->style == EXTCOMMUNITY_LIST_STANDARD
15301 ? "standard"
15302 : "expanded",
15303 list->name);
15304 }
15305 if (entry->any)
15306 vty_out(vty, " %s\n",
15307 community_direct_str(entry->direct));
15308 else
15309 vty_out(vty, " %s %s\n",
15310 community_direct_str(entry->direct),
15311 community_list_config_str(entry));
15312 }
15313 }
15314
15315 DEFUN (show_extcommunity_list,
15316 show_bgp_extcommunity_list_cmd,
15317 "show bgp extcommunity-list",
15318 SHOW_STR
15319 BGP_STR
15320 "List extended-community list\n")
15321 {
15322 struct community_list *list;
15323 struct community_list_master *cm;
15324 int idx = 0;
15325
15326 if (argv_find(argv, argc, "ip", &idx)) {
15327 vty_out(vty, "This config option is deprecated, and is scheduled for removal\n");
15328 vty_out(vty, "if you are using this please migrate to the below command.\n");
15329 vty_out(vty, "'show bgp extcommunity-list <(1-500)|WORD>'\n");
15330 zlog_warn("Deprecated option: 'ip show extcommunity-list <(1-500)|WORD>' being used");
15331 }
15332 cm = community_list_master_lookup(bgp_clist, EXTCOMMUNITY_LIST_MASTER);
15333 if (!cm)
15334 return CMD_SUCCESS;
15335
15336 for (list = cm->num.head; list; list = list->next)
15337 extcommunity_list_show(vty, list);
15338
15339 for (list = cm->str.head; list; list = list->next)
15340 extcommunity_list_show(vty, list);
15341
15342 return CMD_SUCCESS;
15343 }
15344
15345 ALIAS (show_extcommunity_list,
15346 show_ip_extcommunity_list_cmd,
15347 "show ip extcommunity-list",
15348 SHOW_STR
15349 IP_STR
15350 "List extended-community list\n")
15351
15352 DEFUN (show_extcommunity_list_arg,
15353 show_bgp_extcommunity_list_arg_cmd,
15354 "show bgp extcommunity-list <(1-500)|WORD>",
15355 SHOW_STR
15356 BGP_STR
15357 "List extended-community list\n"
15358 "Extcommunity-list number\n"
15359 "Extcommunity-list name\n")
15360 {
15361 int idx_comm_list = 3;
15362 struct community_list *list;
15363 int idx = 0;
15364
15365 if (argv_find(argv, argc, "ip", &idx)) {
15366 vty_out(vty, "This config option is deprecated, and is scheduled for removal.\n");
15367 vty_out(vty, "if you are using this please migrate to the below command.\n");
15368 vty_out(vty, "'show bgp extcommunity-list <(1-500)|WORD>'\n");
15369 zlog_warn("Deprecated option: 'ip show extcommunity-list <(1-500)|WORD>' being used");
15370 }
15371 list = community_list_lookup(bgp_clist, argv[idx_comm_list]->arg, 0,
15372 EXTCOMMUNITY_LIST_MASTER);
15373 if (!list) {
15374 vty_out(vty, "%% Can't find extcommunity-list\n");
15375 return CMD_WARNING;
15376 }
15377
15378 extcommunity_list_show(vty, list);
15379
15380 return CMD_SUCCESS;
15381 }
15382
15383 ALIAS (show_extcommunity_list_arg,
15384 show_ip_extcommunity_list_arg_cmd,
15385 "show ip extcommunity-list <(1-500)|WORD>",
15386 SHOW_STR
15387 IP_STR
15388 "List extended-community list\n"
15389 "Extcommunity-list number\n"
15390 "Extcommunity-list name\n")
15391
15392 /* Display community-list and extcommunity-list configuration. */
15393 static int community_list_config_write(struct vty *vty)
15394 {
15395 struct community_list *list;
15396 struct community_entry *entry;
15397 struct community_list_master *cm;
15398 int write = 0;
15399
15400 /* Community-list. */
15401 cm = community_list_master_lookup(bgp_clist, COMMUNITY_LIST_MASTER);
15402
15403 for (list = cm->num.head; list; list = list->next)
15404 for (entry = list->head; entry; entry = entry->next) {
15405 vty_out(vty, "bgp community-list %s %s %s\n", list->name,
15406 community_direct_str(entry->direct),
15407 community_list_config_str(entry));
15408 write++;
15409 }
15410 for (list = cm->str.head; list; list = list->next)
15411 for (entry = list->head; entry; entry = entry->next) {
15412 vty_out(vty, "bgp community-list %s %s %s %s\n",
15413 entry->style == COMMUNITY_LIST_STANDARD
15414 ? "standard"
15415 : "expanded",
15416 list->name, community_direct_str(entry->direct),
15417 community_list_config_str(entry));
15418 write++;
15419 }
15420
15421 /* Extcommunity-list. */
15422 cm = community_list_master_lookup(bgp_clist, EXTCOMMUNITY_LIST_MASTER);
15423
15424 for (list = cm->num.head; list; list = list->next)
15425 for (entry = list->head; entry; entry = entry->next) {
15426 vty_out(vty, "bgp extcommunity-list %s %s %s\n",
15427 list->name, community_direct_str(entry->direct),
15428 community_list_config_str(entry));
15429 write++;
15430 }
15431 for (list = cm->str.head; list; list = list->next)
15432 for (entry = list->head; entry; entry = entry->next) {
15433 vty_out(vty, "bgp extcommunity-list %s %s %s %s\n",
15434 entry->style == EXTCOMMUNITY_LIST_STANDARD
15435 ? "standard"
15436 : "expanded",
15437 list->name, community_direct_str(entry->direct),
15438 community_list_config_str(entry));
15439 write++;
15440 }
15441
15442
15443 /* lcommunity-list. */
15444 cm = community_list_master_lookup(bgp_clist,
15445 LARGE_COMMUNITY_LIST_MASTER);
15446
15447 for (list = cm->num.head; list; list = list->next)
15448 for (entry = list->head; entry; entry = entry->next) {
15449 vty_out(vty, "bgp large-community-list %s %s %s\n",
15450 list->name, community_direct_str(entry->direct),
15451 community_list_config_str(entry));
15452 write++;
15453 }
15454 for (list = cm->str.head; list; list = list->next)
15455 for (entry = list->head; entry; entry = entry->next) {
15456 vty_out(vty, "bgp large-community-list %s %s %s %s\n",
15457 entry->style == LARGE_COMMUNITY_LIST_STANDARD
15458 ? "standard"
15459 : "expanded",
15460 list->name, community_direct_str(entry->direct),
15461 community_list_config_str(entry));
15462 write++;
15463 }
15464
15465 return write;
15466 }
15467
15468 static struct cmd_node community_list_node = {
15469 COMMUNITY_LIST_NODE, "", 1 /* Export to vtysh. */
15470 };
15471
15472 static void community_list_vty(void)
15473 {
15474 install_node(&community_list_node, community_list_config_write);
15475
15476 /* Community-list. */
15477 install_element(CONFIG_NODE, &bgp_community_list_standard_cmd);
15478 install_element(CONFIG_NODE, &bgp_community_list_expanded_all_cmd);
15479 install_element(CONFIG_NODE, &no_bgp_community_list_standard_all_cmd);
15480 install_element(CONFIG_NODE, &no_bgp_community_list_standard_all_list_cmd);
15481 install_element(CONFIG_NODE, &no_bgp_community_list_expanded_all_cmd);
15482 install_element(CONFIG_NODE, &no_bgp_community_list_expanded_all_list_cmd);
15483 install_element(VIEW_NODE, &show_bgp_community_list_cmd);
15484 install_element(VIEW_NODE, &show_bgp_community_list_arg_cmd);
15485 install_element(CONFIG_NODE, &ip_community_list_standard_cmd);
15486 install_element(CONFIG_NODE, &ip_community_list_expanded_all_cmd);
15487 install_element(CONFIG_NODE, &no_ip_community_list_standard_all_cmd);
15488 install_element(CONFIG_NODE, &no_ip_community_list_standard_all_list_cmd);
15489 install_element(CONFIG_NODE, &no_ip_community_list_expanded_all_cmd);
15490 install_element(CONFIG_NODE, &no_ip_community_list_expanded_all_list_cmd);
15491 install_element(VIEW_NODE, &show_ip_community_list_cmd);
15492 install_element(VIEW_NODE, &show_ip_community_list_arg_cmd);
15493
15494 /* Extcommunity-list. */
15495 install_element(CONFIG_NODE, &bgp_extcommunity_list_standard_cmd);
15496 install_element(CONFIG_NODE, &bgp_extcommunity_list_name_expanded_cmd);
15497 install_element(CONFIG_NODE, &no_bgp_extcommunity_list_standard_all_cmd);
15498 install_element(CONFIG_NODE,
15499 &no_bgp_extcommunity_list_standard_all_list_cmd);
15500 install_element(CONFIG_NODE, &no_bgp_extcommunity_list_expanded_all_cmd);
15501 install_element(CONFIG_NODE,
15502 &no_bgp_extcommunity_list_expanded_all_list_cmd);
15503 install_element(VIEW_NODE, &show_bgp_extcommunity_list_cmd);
15504 install_element(VIEW_NODE, &show_bgp_extcommunity_list_arg_cmd);
15505 install_element(CONFIG_NODE, &ip_extcommunity_list_standard_cmd);
15506 install_element(CONFIG_NODE, &ip_extcommunity_list_name_expanded_cmd);
15507 install_element(CONFIG_NODE, &no_ip_extcommunity_list_standard_all_cmd);
15508 install_element(CONFIG_NODE, &no_ip_extcommunity_list_standard_all_list_cmd);
15509 install_element(CONFIG_NODE, &no_ip_extcommunity_list_expanded_all_cmd);
15510 install_element(CONFIG_NODE, &no_ip_extcommunity_list_expanded_all_list_cmd);
15511 install_element(VIEW_NODE, &show_ip_extcommunity_list_cmd);
15512 install_element(VIEW_NODE, &show_ip_extcommunity_list_arg_cmd);
15513
15514 /* Large Community List */
15515 install_element(CONFIG_NODE, &bgp_lcommunity_list_standard_cmd);
15516 install_element(CONFIG_NODE, &bgp_lcommunity_list_standard1_cmd);
15517 install_element(CONFIG_NODE, &bgp_lcommunity_list_expanded_cmd);
15518 install_element(CONFIG_NODE, &bgp_lcommunity_list_name_standard_cmd);
15519 install_element(CONFIG_NODE, &bgp_lcommunity_list_name_standard1_cmd);
15520 install_element(CONFIG_NODE, &bgp_lcommunity_list_name_expanded_cmd);
15521 install_element(CONFIG_NODE, &no_bgp_lcommunity_list_standard_all_cmd);
15522 install_element(CONFIG_NODE,
15523 &no_bgp_lcommunity_list_name_expanded_all_cmd);
15524 install_element(CONFIG_NODE, &no_bgp_lcommunity_list_standard_cmd);
15525 install_element(CONFIG_NODE, &no_bgp_lcommunity_list_expanded_cmd);
15526 install_element(CONFIG_NODE, &no_bgp_lcommunity_list_name_standard_cmd);
15527 install_element(CONFIG_NODE, &no_bgp_lcommunity_list_name_expanded_cmd);
15528 install_element(VIEW_NODE, &show_bgp_lcommunity_list_cmd);
15529 install_element(VIEW_NODE, &show_bgp_lcommunity_list_arg_cmd);
15530 install_element(CONFIG_NODE, &ip_lcommunity_list_standard_cmd);
15531 install_element(CONFIG_NODE, &ip_lcommunity_list_standard1_cmd);
15532 install_element(CONFIG_NODE, &ip_lcommunity_list_expanded_cmd);
15533 install_element(CONFIG_NODE, &ip_lcommunity_list_name_standard_cmd);
15534 install_element(CONFIG_NODE, &ip_lcommunity_list_name_standard1_cmd);
15535 install_element(CONFIG_NODE, &ip_lcommunity_list_name_expanded_cmd);
15536 install_element(CONFIG_NODE, &no_ip_lcommunity_list_standard_all_cmd);
15537 install_element(CONFIG_NODE,
15538 &no_ip_lcommunity_list_name_expanded_all_cmd);
15539 install_element(CONFIG_NODE, &no_ip_lcommunity_list_standard_cmd);
15540 install_element(CONFIG_NODE, &no_ip_lcommunity_list_expanded_cmd);
15541 install_element(CONFIG_NODE, &no_ip_lcommunity_list_name_standard_cmd);
15542 install_element(CONFIG_NODE, &no_ip_lcommunity_list_name_expanded_cmd);
15543 install_element(VIEW_NODE, &show_ip_lcommunity_list_cmd);
15544 install_element(VIEW_NODE, &show_ip_lcommunity_list_arg_cmd);
15545 }