]> git.proxmox.com Git - mirror_frr.git/blob - bgpd/bgp_vty.c
bgpd: Add Established and Dropped counts to JSON output of bgp summary
[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_errors.h"
26 #include "lib/zclient.h"
27 #include "prefix.h"
28 #include "plist.h"
29 #include "buffer.h"
30 #include "linklist.h"
31 #include "stream.h"
32 #include "thread.h"
33 #include "log.h"
34 #include "memory.h"
35 #include "memory_vty.h"
36 #include "hash.h"
37 #include "queue.h"
38 #include "filter.h"
39 #include "frrstr.h"
40
41 #include "bgpd/bgpd.h"
42 #include "bgpd/bgp_attr_evpn.h"
43 #include "bgpd/bgp_advertise.h"
44 #include "bgpd/bgp_attr.h"
45 #include "bgpd/bgp_aspath.h"
46 #include "bgpd/bgp_community.h"
47 #include "bgpd/bgp_ecommunity.h"
48 #include "bgpd/bgp_lcommunity.h"
49 #include "bgpd/bgp_damp.h"
50 #include "bgpd/bgp_debug.h"
51 #include "bgpd/bgp_errors.h"
52 #include "bgpd/bgp_fsm.h"
53 #include "bgpd/bgp_nexthop.h"
54 #include "bgpd/bgp_open.h"
55 #include "bgpd/bgp_regex.h"
56 #include "bgpd/bgp_route.h"
57 #include "bgpd/bgp_mplsvpn.h"
58 #include "bgpd/bgp_zebra.h"
59 #include "bgpd/bgp_table.h"
60 #include "bgpd/bgp_vty.h"
61 #include "bgpd/bgp_mpath.h"
62 #include "bgpd/bgp_packet.h"
63 #include "bgpd/bgp_updgrp.h"
64 #include "bgpd/bgp_bfd.h"
65 #include "bgpd/bgp_io.h"
66 #include "bgpd/bgp_evpn.h"
67 #include "bgpd/bgp_addpath.h"
68 #include "bgpd/bgp_mac.h"
69
70 static struct peer_group *listen_range_exists(struct bgp *bgp,
71 struct prefix *range, int exact);
72
73 static enum node_type bgp_node_type(afi_t afi, safi_t safi)
74 {
75 switch (afi) {
76 case AFI_IP:
77 switch (safi) {
78 case SAFI_UNICAST:
79 return BGP_IPV4_NODE;
80 break;
81 case SAFI_MULTICAST:
82 return BGP_IPV4M_NODE;
83 break;
84 case SAFI_LABELED_UNICAST:
85 return BGP_IPV4L_NODE;
86 break;
87 case SAFI_MPLS_VPN:
88 return BGP_VPNV4_NODE;
89 break;
90 case SAFI_FLOWSPEC:
91 return BGP_FLOWSPECV4_NODE;
92 default:
93 /* not expected */
94 return BGP_IPV4_NODE;
95 break;
96 }
97 break;
98 case AFI_IP6:
99 switch (safi) {
100 case SAFI_UNICAST:
101 return BGP_IPV6_NODE;
102 break;
103 case SAFI_MULTICAST:
104 return BGP_IPV6M_NODE;
105 break;
106 case SAFI_LABELED_UNICAST:
107 return BGP_IPV6L_NODE;
108 break;
109 case SAFI_MPLS_VPN:
110 return BGP_VPNV6_NODE;
111 break;
112 case SAFI_FLOWSPEC:
113 return BGP_FLOWSPECV6_NODE;
114 default:
115 /* not expected */
116 return BGP_IPV4_NODE;
117 break;
118 }
119 break;
120 case AFI_L2VPN:
121 return BGP_EVPN_NODE;
122 break;
123 case AFI_UNSPEC:
124 case AFI_MAX:
125 // We should never be here but to clarify the switch statement..
126 return BGP_IPV4_NODE;
127 break;
128 }
129
130 // Impossible to happen
131 return BGP_IPV4_NODE;
132 }
133
134 static const char *get_afi_safi_vty_str(afi_t afi, safi_t safi)
135 {
136 if (afi == AFI_IP && safi == SAFI_UNICAST)
137 return "IPv4 Unicast";
138 else if (afi == AFI_IP && safi == SAFI_MULTICAST)
139 return "IPv4 Multicast";
140 else if (afi == AFI_IP && safi == SAFI_LABELED_UNICAST)
141 return "IPv4 Labeled Unicast";
142 else if (afi == AFI_IP && safi == SAFI_MPLS_VPN)
143 return "IPv4 VPN";
144 else if (afi == AFI_IP && safi == SAFI_ENCAP)
145 return "IPv4 Encap";
146 else if (afi == AFI_IP && safi == SAFI_FLOWSPEC)
147 return "IPv4 Flowspec";
148 else if (afi == AFI_IP6 && safi == SAFI_UNICAST)
149 return "IPv6 Unicast";
150 else if (afi == AFI_IP6 && safi == SAFI_MULTICAST)
151 return "IPv6 Multicast";
152 else if (afi == AFI_IP6 && safi == SAFI_LABELED_UNICAST)
153 return "IPv6 Labeled Unicast";
154 else if (afi == AFI_IP6 && safi == SAFI_MPLS_VPN)
155 return "IPv6 VPN";
156 else if (afi == AFI_IP6 && safi == SAFI_ENCAP)
157 return "IPv6 Encap";
158 else if (afi == AFI_IP6 && safi == SAFI_FLOWSPEC)
159 return "IPv6 Flowspec";
160 else if (afi == AFI_L2VPN && safi == SAFI_EVPN)
161 return "L2VPN EVPN";
162 else {
163 flog_err(EC_LIB_DEVELOPMENT, "New afi/safi that needs to be taken care of?");
164 return "Unknown";
165 }
166 }
167
168 /*
169 * Please note that we have intentionally camelCased
170 * the return strings here. So if you want
171 * to use this function, please ensure you
172 * are doing this within json output
173 */
174 static const char *get_afi_safi_json_str(afi_t afi, safi_t safi)
175 {
176 if (afi == AFI_IP && safi == SAFI_UNICAST)
177 return "ipv4Unicast";
178 else if (afi == AFI_IP && safi == SAFI_MULTICAST)
179 return "ipv4Multicast";
180 else if (afi == AFI_IP && safi == SAFI_LABELED_UNICAST)
181 return "ipv4LabeledUnicast";
182 else if (afi == AFI_IP && safi == SAFI_MPLS_VPN)
183 return "ipv4Vpn";
184 else if (afi == AFI_IP && safi == SAFI_ENCAP)
185 return "ipv4Encap";
186 else if (afi == AFI_IP && safi == SAFI_FLOWSPEC)
187 return "ipv4Flowspec";
188 else if (afi == AFI_IP6 && safi == SAFI_UNICAST)
189 return "ipv6Unicast";
190 else if (afi == AFI_IP6 && safi == SAFI_MULTICAST)
191 return "ipv6Multicast";
192 else if (afi == AFI_IP6 && safi == SAFI_LABELED_UNICAST)
193 return "ipv6LabeledUnicast";
194 else if (afi == AFI_IP6 && safi == SAFI_MPLS_VPN)
195 return "ipv6Vpn";
196 else if (afi == AFI_IP6 && safi == SAFI_ENCAP)
197 return "ipv6Encap";
198 else if (afi == AFI_IP6 && safi == SAFI_FLOWSPEC)
199 return "ipv6Flowspec";
200 else if (afi == AFI_L2VPN && safi == SAFI_EVPN)
201 return "l2VpnEvpn";
202 else {
203 flog_err(EC_LIB_DEVELOPMENT, "New afi/safi that needs to be taken care of?");
204 return "Unknown";
205 }
206 }
207
208 /* Utility function to get address family from current node. */
209 afi_t bgp_node_afi(struct vty *vty)
210 {
211 afi_t afi;
212 switch (vty->node) {
213 case BGP_IPV6_NODE:
214 case BGP_IPV6M_NODE:
215 case BGP_IPV6L_NODE:
216 case BGP_VPNV6_NODE:
217 case BGP_FLOWSPECV6_NODE:
218 afi = AFI_IP6;
219 break;
220 case BGP_EVPN_NODE:
221 afi = AFI_L2VPN;
222 break;
223 default:
224 afi = AFI_IP;
225 break;
226 }
227 return afi;
228 }
229
230 /* Utility function to get subsequent address family from current
231 node. */
232 safi_t bgp_node_safi(struct vty *vty)
233 {
234 safi_t safi;
235 switch (vty->node) {
236 case BGP_VPNV4_NODE:
237 case BGP_VPNV6_NODE:
238 safi = SAFI_MPLS_VPN;
239 break;
240 case BGP_IPV4M_NODE:
241 case BGP_IPV6M_NODE:
242 safi = SAFI_MULTICAST;
243 break;
244 case BGP_EVPN_NODE:
245 safi = SAFI_EVPN;
246 break;
247 case BGP_IPV4L_NODE:
248 case BGP_IPV6L_NODE:
249 safi = SAFI_LABELED_UNICAST;
250 break;
251 case BGP_FLOWSPECV4_NODE:
252 case BGP_FLOWSPECV6_NODE:
253 safi = SAFI_FLOWSPEC;
254 break;
255 default:
256 safi = SAFI_UNICAST;
257 break;
258 }
259 return safi;
260 }
261
262 /**
263 * Converts an AFI in string form to afi_t
264 *
265 * @param afi string, one of
266 * - "ipv4"
267 * - "ipv6"
268 * - "l2vpn"
269 * @return the corresponding afi_t
270 */
271 afi_t bgp_vty_afi_from_str(const char *afi_str)
272 {
273 afi_t afi = AFI_MAX; /* unknown */
274 if (strmatch(afi_str, "ipv4"))
275 afi = AFI_IP;
276 else if (strmatch(afi_str, "ipv6"))
277 afi = AFI_IP6;
278 else if (strmatch(afi_str, "l2vpn"))
279 afi = AFI_L2VPN;
280 return afi;
281 }
282
283 int argv_find_and_parse_afi(struct cmd_token **argv, int argc, int *index,
284 afi_t *afi)
285 {
286 int ret = 0;
287 if (argv_find(argv, argc, "ipv4", index)) {
288 ret = 1;
289 if (afi)
290 *afi = AFI_IP;
291 } else if (argv_find(argv, argc, "ipv6", index)) {
292 ret = 1;
293 if (afi)
294 *afi = AFI_IP6;
295 } else if (argv_find(argv, argc, "l2vpn", index)) {
296 ret = 1;
297 if (afi)
298 *afi = AFI_L2VPN;
299 }
300 return ret;
301 }
302
303 /* supports <unicast|multicast|vpn|labeled-unicast> */
304 safi_t bgp_vty_safi_from_str(const char *safi_str)
305 {
306 safi_t safi = SAFI_MAX; /* unknown */
307 if (strmatch(safi_str, "multicast"))
308 safi = SAFI_MULTICAST;
309 else if (strmatch(safi_str, "unicast"))
310 safi = SAFI_UNICAST;
311 else if (strmatch(safi_str, "vpn"))
312 safi = SAFI_MPLS_VPN;
313 else if (strmatch(safi_str, "evpn"))
314 safi = SAFI_EVPN;
315 else if (strmatch(safi_str, "labeled-unicast"))
316 safi = SAFI_LABELED_UNICAST;
317 else if (strmatch(safi_str, "flowspec"))
318 safi = SAFI_FLOWSPEC;
319 return safi;
320 }
321
322 int argv_find_and_parse_safi(struct cmd_token **argv, int argc, int *index,
323 safi_t *safi)
324 {
325 int ret = 0;
326 if (argv_find(argv, argc, "unicast", index)) {
327 ret = 1;
328 if (safi)
329 *safi = SAFI_UNICAST;
330 } else if (argv_find(argv, argc, "multicast", index)) {
331 ret = 1;
332 if (safi)
333 *safi = SAFI_MULTICAST;
334 } else if (argv_find(argv, argc, "labeled-unicast", index)) {
335 ret = 1;
336 if (safi)
337 *safi = SAFI_LABELED_UNICAST;
338 } else if (argv_find(argv, argc, "vpn", index)) {
339 ret = 1;
340 if (safi)
341 *safi = SAFI_MPLS_VPN;
342 } else if (argv_find(argv, argc, "evpn", index)) {
343 ret = 1;
344 if (safi)
345 *safi = SAFI_EVPN;
346 } else if (argv_find(argv, argc, "flowspec", index)) {
347 ret = 1;
348 if (safi)
349 *safi = SAFI_FLOWSPEC;
350 }
351 return ret;
352 }
353
354 /*
355 * bgp_vty_find_and_parse_afi_safi_bgp
356 *
357 * For a given 'show ...' command, correctly parse the afi/safi/bgp out from it
358 * This function *assumes* that the calling function pre-sets the afi/safi/bgp
359 * to appropriate values for the calling function. This is to allow the
360 * calling function to make decisions appropriate for the show command
361 * that is being parsed.
362 *
363 * The show commands are generally of the form:
364 * "show [ip] bgp [<view|vrf> VIEWVRFNAME] [<ipv4|ipv6>
365 * [<unicast|multicast|vpn|labeled-unicast>]] ..."
366 *
367 * Since we use argv_find if the show command in particular doesn't have:
368 * [ip]
369 * [<view|vrf> VIEWVRFNAME]
370 * [<ipv4|ipv6> [<unicast|multicast|vpn|labeled-unicast>]]
371 * The command parsing should still be ok.
372 *
373 * vty -> The vty for the command so we can output some useful data in
374 * the event of a parse error in the vrf.
375 * argv -> The command tokens
376 * argc -> How many command tokens we have
377 * idx -> The current place in the command, generally should be 0 for this
378 * function
379 * afi -> The parsed afi if it was included in the show command, returned here
380 * safi -> The parsed safi if it was included in the show command, returned here
381 * bgp -> Pointer to the bgp data structure we need to fill in.
382 * use_json -> json is configured or not
383 *
384 * The function returns the correct location in the parse tree for the
385 * last token found.
386 *
387 * Returns 0 for failure to parse correctly, else the idx position of where
388 * it found the last token.
389 */
390 int bgp_vty_find_and_parse_afi_safi_bgp(struct vty *vty,
391 struct cmd_token **argv, int argc,
392 int *idx, afi_t *afi, safi_t *safi,
393 struct bgp **bgp, bool use_json)
394 {
395 char *vrf_name = NULL;
396
397 assert(afi);
398 assert(safi);
399 assert(bgp);
400
401 if (argv_find(argv, argc, "ip", idx))
402 *afi = AFI_IP;
403
404 if (argv_find(argv, argc, "view", idx))
405 vrf_name = argv[*idx + 1]->arg;
406 else if (argv_find(argv, argc, "vrf", idx)) {
407 vrf_name = argv[*idx + 1]->arg;
408 if (strmatch(vrf_name, VRF_DEFAULT_NAME))
409 vrf_name = NULL;
410 }
411 if (vrf_name) {
412 if (strmatch(vrf_name, "all"))
413 *bgp = NULL;
414 else {
415 *bgp = bgp_lookup_by_name(vrf_name);
416 if (!*bgp) {
417 if (use_json) {
418 json_object *json = NULL;
419 json = json_object_new_object();
420 json_object_string_add(
421 json, "warning",
422 "View/Vrf is unknown");
423 vty_out(vty, "%s\n",
424 json_object_to_json_string_ext(json,
425 JSON_C_TO_STRING_PRETTY));
426 json_object_free(json);
427 }
428 else
429 vty_out(vty, "View/Vrf %s is unknown\n",
430 vrf_name);
431 *idx = 0;
432 return 0;
433 }
434 }
435 } else {
436 *bgp = bgp_get_default();
437 if (!*bgp) {
438 if (use_json) {
439 json_object *json = NULL;
440 json = json_object_new_object();
441 json_object_string_add(
442 json, "warning",
443 "Default BGP instance not found");
444 vty_out(vty, "%s\n",
445 json_object_to_json_string_ext(json,
446 JSON_C_TO_STRING_PRETTY));
447 json_object_free(json);
448 }
449 else
450 vty_out(vty,
451 "Default BGP instance not found\n");
452 *idx = 0;
453 return 0;
454 }
455 }
456
457 if (argv_find_and_parse_afi(argv, argc, idx, afi))
458 argv_find_and_parse_safi(argv, argc, idx, safi);
459
460 *idx += 1;
461 return *idx;
462 }
463
464 static int peer_address_self_check(struct bgp *bgp, union sockunion *su)
465 {
466 struct interface *ifp = NULL;
467
468 if (su->sa.sa_family == AF_INET)
469 ifp = if_lookup_by_ipv4_exact(&su->sin.sin_addr, bgp->vrf_id);
470 else if (su->sa.sa_family == AF_INET6)
471 ifp = if_lookup_by_ipv6_exact(&su->sin6.sin6_addr,
472 su->sin6.sin6_scope_id,
473 bgp->vrf_id);
474
475 if (ifp)
476 return 1;
477
478 return 0;
479 }
480
481 /* Utility function for looking up peer from VTY. */
482 /* This is used only for configuration, so disallow if attempted on
483 * a dynamic neighbor.
484 */
485 static struct peer *peer_lookup_vty(struct vty *vty, const char *ip_str)
486 {
487 struct bgp *bgp = VTY_GET_CONTEXT(bgp);
488 int ret;
489 union sockunion su;
490 struct peer *peer;
491
492 if (!bgp) {
493 return NULL;
494 }
495
496 ret = str2sockunion(ip_str, &su);
497 if (ret < 0) {
498 peer = peer_lookup_by_conf_if(bgp, ip_str);
499 if (!peer) {
500 if ((peer = peer_lookup_by_hostname(bgp, ip_str))
501 == NULL) {
502 vty_out(vty,
503 "%% Malformed address or name: %s\n",
504 ip_str);
505 return NULL;
506 }
507 }
508 } else {
509 peer = peer_lookup(bgp, &su);
510 if (!peer) {
511 vty_out(vty,
512 "%% Specify remote-as or peer-group commands first\n");
513 return NULL;
514 }
515 if (peer_dynamic_neighbor(peer)) {
516 vty_out(vty,
517 "%% Operation not allowed on a dynamic neighbor\n");
518 return NULL;
519 }
520 }
521 return peer;
522 }
523
524 /* Utility function for looking up peer or peer group. */
525 /* This is used only for configuration, so disallow if attempted on
526 * a dynamic neighbor.
527 */
528 struct peer *peer_and_group_lookup_vty(struct vty *vty, const char *peer_str)
529 {
530 struct bgp *bgp = VTY_GET_CONTEXT(bgp);
531 int ret;
532 union sockunion su;
533 struct peer *peer = NULL;
534 struct peer_group *group = NULL;
535
536 if (!bgp) {
537 return NULL;
538 }
539
540 ret = str2sockunion(peer_str, &su);
541 if (ret == 0) {
542 /* IP address, locate peer. */
543 peer = peer_lookup(bgp, &su);
544 } else {
545 /* Not IP, could match either peer configured on interface or a
546 * group. */
547 peer = peer_lookup_by_conf_if(bgp, peer_str);
548 if (!peer)
549 group = peer_group_lookup(bgp, peer_str);
550 }
551
552 if (peer) {
553 if (peer_dynamic_neighbor(peer)) {
554 vty_out(vty,
555 "%% Operation not allowed on a dynamic neighbor\n");
556 return NULL;
557 }
558
559 return peer;
560 }
561
562 if (group)
563 return group->conf;
564
565 vty_out(vty, "%% Specify remote-as or peer-group commands first\n");
566
567 return NULL;
568 }
569
570 int bgp_vty_return(struct vty *vty, int ret)
571 {
572 const char *str = NULL;
573
574 switch (ret) {
575 case BGP_ERR_INVALID_VALUE:
576 str = "Invalid value";
577 break;
578 case BGP_ERR_INVALID_FLAG:
579 str = "Invalid flag";
580 break;
581 case BGP_ERR_PEER_GROUP_SHUTDOWN:
582 str = "Peer-group has been shutdown. Activate the peer-group first";
583 break;
584 case BGP_ERR_PEER_FLAG_CONFLICT:
585 str = "Can't set override-capability and strict-capability-match at the same time";
586 break;
587 case BGP_ERR_PEER_GROUP_NO_REMOTE_AS:
588 str = "Specify remote-as or peer-group remote AS first";
589 break;
590 case BGP_ERR_PEER_GROUP_CANT_CHANGE:
591 str = "Cannot change the peer-group. Deconfigure first";
592 break;
593 case BGP_ERR_PEER_GROUP_MISMATCH:
594 str = "Peer is not a member of this peer-group";
595 break;
596 case BGP_ERR_PEER_FILTER_CONFLICT:
597 str = "Prefix/distribute list can not co-exist";
598 break;
599 case BGP_ERR_NOT_INTERNAL_PEER:
600 str = "Invalid command. Not an internal neighbor";
601 break;
602 case BGP_ERR_REMOVE_PRIVATE_AS:
603 str = "remove-private-AS cannot be configured for IBGP peers";
604 break;
605 case BGP_ERR_LOCAL_AS_ALLOWED_ONLY_FOR_EBGP:
606 str = "Local-AS allowed only for EBGP peers";
607 break;
608 case BGP_ERR_CANNOT_HAVE_LOCAL_AS_SAME_AS:
609 str = "Cannot have local-as same as BGP AS number";
610 break;
611 case BGP_ERR_TCPSIG_FAILED:
612 str = "Error while applying TCP-Sig to session(s)";
613 break;
614 case BGP_ERR_NO_EBGP_MULTIHOP_WITH_TTLHACK:
615 str = "ebgp-multihop and ttl-security cannot be configured together";
616 break;
617 case BGP_ERR_NO_IBGP_WITH_TTLHACK:
618 str = "ttl-security only allowed for EBGP peers";
619 break;
620 case BGP_ERR_AS_OVERRIDE:
621 str = "as-override cannot be configured for IBGP peers";
622 break;
623 case BGP_ERR_INVALID_DYNAMIC_NEIGHBORS_LIMIT:
624 str = "Invalid limit for number of dynamic neighbors";
625 break;
626 case BGP_ERR_DYNAMIC_NEIGHBORS_RANGE_EXISTS:
627 str = "Dynamic neighbor listen range already exists";
628 break;
629 case BGP_ERR_INVALID_FOR_DYNAMIC_PEER:
630 str = "Operation not allowed on a dynamic neighbor";
631 break;
632 case BGP_ERR_INVALID_FOR_DIRECT_PEER:
633 str = "Operation not allowed on a directly connected neighbor";
634 break;
635 case BGP_ERR_PEER_SAFI_CONFLICT:
636 str = "Cannot activate peer for both 'ipv4 unicast' and 'ipv4 labeled-unicast'";
637 break;
638 }
639 if (str) {
640 vty_out(vty, "%% %s\n", str);
641 return CMD_WARNING_CONFIG_FAILED;
642 }
643 return CMD_SUCCESS;
644 }
645
646 /* BGP clear sort. */
647 enum clear_sort {
648 clear_all,
649 clear_peer,
650 clear_group,
651 clear_external,
652 clear_as
653 };
654
655 static void bgp_clear_vty_error(struct vty *vty, struct peer *peer, afi_t afi,
656 safi_t safi, int error)
657 {
658 switch (error) {
659 case BGP_ERR_AF_UNCONFIGURED:
660 vty_out(vty,
661 "%%BGP: Enable %s address family for the neighbor %s\n",
662 get_afi_safi_str(afi, safi, false), peer->host);
663 break;
664 case BGP_ERR_SOFT_RECONFIG_UNCONFIGURED:
665 vty_out(vty,
666 "%%BGP: Inbound soft reconfig for %s not possible as it\n has neither refresh capability, nor inbound soft reconfig\n",
667 peer->host);
668 break;
669 default:
670 break;
671 }
672 }
673
674 static int bgp_peer_clear(struct peer *peer, afi_t afi, safi_t safi,
675 struct listnode *nnode, enum bgp_clear_type stype)
676 {
677 int ret = 0;
678
679 /* if afi/.safi not specified, spin thru all of them */
680 if ((afi == AFI_UNSPEC) && (safi == SAFI_UNSPEC)) {
681 afi_t tmp_afi;
682 safi_t tmp_safi;
683
684 FOREACH_AFI_SAFI (tmp_afi, tmp_safi) {
685 if (!peer->afc[tmp_afi][tmp_safi])
686 continue;
687
688 if (stype == BGP_CLEAR_SOFT_NONE)
689 ret = peer_clear(peer, &nnode);
690 else
691 ret = peer_clear_soft(peer, tmp_afi, tmp_safi,
692 stype);
693 }
694 /* if afi specified and safi not, spin thru safis on this afi */
695 } else if (safi == SAFI_UNSPEC) {
696 safi_t tmp_safi;
697
698 for (tmp_safi = SAFI_UNICAST;
699 tmp_safi < SAFI_MAX; tmp_safi++) {
700 if (!peer->afc[afi][tmp_safi])
701 continue;
702
703 if (stype == BGP_CLEAR_SOFT_NONE)
704 ret = peer_clear(peer, &nnode);
705 else
706 ret = peer_clear_soft(peer, afi,
707 tmp_safi, stype);
708 }
709 /* both afi/safi specified, let the caller know if not defined */
710 } else {
711 if (!peer->afc[afi][safi])
712 return 1;
713
714 if (stype == BGP_CLEAR_SOFT_NONE)
715 ret = peer_clear(peer, &nnode);
716 else
717 ret = peer_clear_soft(peer, afi, safi, stype);
718 }
719
720 return ret;
721 }
722
723 /* `clear ip bgp' functions. */
724 static int bgp_clear(struct vty *vty, struct bgp *bgp, afi_t afi, safi_t safi,
725 enum clear_sort sort, enum bgp_clear_type stype,
726 const char *arg)
727 {
728 int ret = 0;
729 bool found = false;
730 struct peer *peer;
731 struct listnode *node, *nnode;
732
733 /* Clear all neighbors. */
734 /*
735 * Pass along pointer to next node to peer_clear() when walking all
736 * nodes on the BGP instance as that may get freed if it is a
737 * doppelganger
738 */
739 if (sort == clear_all) {
740 for (ALL_LIST_ELEMENTS(bgp->peer, node, nnode, peer)) {
741 ret = bgp_peer_clear(peer, afi, safi, nnode,
742 stype);
743
744 if (ret < 0)
745 bgp_clear_vty_error(vty, peer, afi, safi, ret);
746 }
747
748 /* This is to apply read-only mode on this clear. */
749 if (stype == BGP_CLEAR_SOFT_NONE)
750 bgp->update_delay_over = 0;
751
752 return CMD_SUCCESS;
753 }
754
755 /* Clear specified neighbor. */
756 if (sort == clear_peer) {
757 union sockunion su;
758
759 /* Make sockunion for lookup. */
760 ret = str2sockunion(arg, &su);
761 if (ret < 0) {
762 peer = peer_lookup_by_conf_if(bgp, arg);
763 if (!peer) {
764 peer = peer_lookup_by_hostname(bgp, arg);
765 if (!peer) {
766 vty_out(vty,
767 "Malformed address or name: %s\n",
768 arg);
769 return CMD_WARNING;
770 }
771 }
772 } else {
773 peer = peer_lookup(bgp, &su);
774 if (!peer) {
775 vty_out(vty,
776 "%%BGP: Unknown neighbor - \"%s\"\n",
777 arg);
778 return CMD_WARNING;
779 }
780 }
781
782 ret = bgp_peer_clear(peer, afi, safi, NULL, stype);
783
784 /* if afi/safi not defined for this peer, let caller know */
785 if (ret == 1)
786 ret = BGP_ERR_AF_UNCONFIGURED;
787
788 if (ret < 0)
789 bgp_clear_vty_error(vty, peer, afi, safi, ret);
790
791 return CMD_SUCCESS;
792 }
793
794 /* Clear all neighbors belonging to a specific peer-group. */
795 if (sort == clear_group) {
796 struct peer_group *group;
797
798 group = peer_group_lookup(bgp, arg);
799 if (!group) {
800 vty_out(vty, "%%BGP: No such peer-group %s\n", arg);
801 return CMD_WARNING;
802 }
803
804 for (ALL_LIST_ELEMENTS(group->peer, node, nnode, peer)) {
805 ret = bgp_peer_clear(peer, afi, safi, nnode, stype);
806
807 if (ret < 0)
808 bgp_clear_vty_error(vty, peer, afi, safi, ret);
809 else
810 found = true;
811 }
812
813 if (!found)
814 vty_out(vty,
815 "%%BGP: No %s peer belonging to peer-group %s is configured\n",
816 get_afi_safi_str(afi, safi, false), arg);
817
818 return CMD_SUCCESS;
819 }
820
821 /* Clear all external (eBGP) neighbors. */
822 if (sort == clear_external) {
823 for (ALL_LIST_ELEMENTS(bgp->peer, node, nnode, peer)) {
824 if (peer->sort == BGP_PEER_IBGP)
825 continue;
826
827 ret = bgp_peer_clear(peer, afi, safi, nnode, stype);
828
829 if (ret < 0)
830 bgp_clear_vty_error(vty, peer, afi, safi, ret);
831 else
832 found = true;
833 }
834
835 if (!found)
836 vty_out(vty,
837 "%%BGP: No external %s peer is configured\n",
838 get_afi_safi_str(afi, safi, false));
839
840 return CMD_SUCCESS;
841 }
842
843 /* Clear all neighbors belonging to a specific AS. */
844 if (sort == clear_as) {
845 as_t as = strtoul(arg, NULL, 10);
846
847 for (ALL_LIST_ELEMENTS(bgp->peer, node, nnode, peer)) {
848 if (peer->as != as)
849 continue;
850
851 ret = bgp_peer_clear(peer, afi, safi, nnode, stype);
852
853 if (ret < 0)
854 bgp_clear_vty_error(vty, peer, afi, safi, ret);
855 else
856 found = true;
857 }
858
859 if (!found)
860 vty_out(vty,
861 "%%BGP: No %s peer is configured with AS %s\n",
862 get_afi_safi_str(afi, safi, false), arg);
863
864 return CMD_SUCCESS;
865 }
866
867 return CMD_SUCCESS;
868 }
869
870 static int bgp_clear_vty(struct vty *vty, const char *name, afi_t afi,
871 safi_t safi, enum clear_sort sort,
872 enum bgp_clear_type stype, const char *arg)
873 {
874 struct bgp *bgp;
875
876 /* BGP structure lookup. */
877 if (name) {
878 bgp = bgp_lookup_by_name(name);
879 if (bgp == NULL) {
880 vty_out(vty, "Can't find BGP instance %s\n", name);
881 return CMD_WARNING;
882 }
883 } else {
884 bgp = bgp_get_default();
885 if (bgp == NULL) {
886 vty_out(vty, "No BGP process is configured\n");
887 return CMD_WARNING;
888 }
889 }
890
891 return bgp_clear(vty, bgp, afi, safi, sort, stype, arg);
892 }
893
894 /* clear soft inbound */
895 static void bgp_clear_star_soft_in(struct vty *vty, const char *name)
896 {
897 afi_t afi;
898 safi_t safi;
899
900 FOREACH_AFI_SAFI (afi, safi)
901 bgp_clear_vty(vty, name, afi, safi, clear_all,
902 BGP_CLEAR_SOFT_IN, NULL);
903 }
904
905 /* clear soft outbound */
906 static void bgp_clear_star_soft_out(struct vty *vty, const char *name)
907 {
908 afi_t afi;
909 safi_t safi;
910
911 FOREACH_AFI_SAFI (afi, safi)
912 bgp_clear_vty(vty, name, afi, safi, clear_all,
913 BGP_CLEAR_SOFT_OUT, NULL);
914 }
915
916
917 #ifndef VTYSH_EXTRACT_PL
918 #include "bgpd/bgp_vty_clippy.c"
919 #endif
920
921 DEFUN_HIDDEN (bgp_local_mac,
922 bgp_local_mac_cmd,
923 "bgp local-mac vni " CMD_VNI_RANGE " mac WORD seq (0-4294967295)",
924 BGP_STR
925 "Local MAC config\n"
926 "VxLAN Network Identifier\n"
927 "VNI number\n"
928 "local mac\n"
929 "mac address\n"
930 "mac-mobility sequence\n"
931 "seq number\n")
932 {
933 int rv;
934 vni_t vni;
935 struct ethaddr mac;
936 struct ipaddr ip;
937 uint32_t seq;
938 struct bgp *bgp;
939
940 vni = strtoul(argv[3]->arg, NULL, 10);
941 if (!prefix_str2mac(argv[5]->arg, &mac)) {
942 vty_out(vty, "%% Malformed MAC address\n");
943 return CMD_WARNING;
944 }
945 memset(&ip, 0, sizeof(ip));
946 seq = strtoul(argv[7]->arg, NULL, 10);
947
948 bgp = bgp_get_default();
949 if (!bgp) {
950 vty_out(vty, "Default BGP instance is not there\n");
951 return CMD_WARNING;
952 }
953
954 rv = bgp_evpn_local_macip_add(bgp, vni, &mac, &ip, 0 /* flags */, seq);
955 if (rv < 0) {
956 vty_out(vty, "Internal error\n");
957 return CMD_WARNING;
958 }
959
960 return CMD_SUCCESS;
961 }
962
963 DEFUN_HIDDEN (no_bgp_local_mac,
964 no_bgp_local_mac_cmd,
965 "no bgp local-mac vni " CMD_VNI_RANGE " mac WORD",
966 NO_STR
967 BGP_STR
968 "Local MAC config\n"
969 "VxLAN Network Identifier\n"
970 "VNI number\n"
971 "local mac\n"
972 "mac address\n")
973 {
974 int rv;
975 vni_t vni;
976 struct ethaddr mac;
977 struct ipaddr ip;
978 struct bgp *bgp;
979
980 vni = strtoul(argv[4]->arg, NULL, 10);
981 if (!prefix_str2mac(argv[6]->arg, &mac)) {
982 vty_out(vty, "%% Malformed MAC address\n");
983 return CMD_WARNING;
984 }
985 memset(&ip, 0, sizeof(ip));
986
987 bgp = bgp_get_default();
988 if (!bgp) {
989 vty_out(vty, "Default BGP instance is not there\n");
990 return CMD_WARNING;
991 }
992
993 rv = bgp_evpn_local_macip_del(bgp, vni, &mac, &ip, ZEBRA_NEIGH_ACTIVE);
994 if (rv < 0) {
995 vty_out(vty, "Internal error\n");
996 return CMD_WARNING;
997 }
998
999 return CMD_SUCCESS;
1000 }
1001
1002 DEFUN (no_synchronization,
1003 no_synchronization_cmd,
1004 "no synchronization",
1005 NO_STR
1006 "Perform IGP synchronization\n")
1007 {
1008 return CMD_SUCCESS;
1009 }
1010
1011 DEFUN (no_auto_summary,
1012 no_auto_summary_cmd,
1013 "no auto-summary",
1014 NO_STR
1015 "Enable automatic network number summarization\n")
1016 {
1017 return CMD_SUCCESS;
1018 }
1019
1020 /* "router bgp" commands. */
1021 DEFUN_NOSH (router_bgp,
1022 router_bgp_cmd,
1023 "router bgp [(1-4294967295)$instasn [<view|vrf> VIEWVRFNAME]]",
1024 ROUTER_STR
1025 BGP_STR
1026 AS_STR
1027 BGP_INSTANCE_HELP_STR)
1028 {
1029 int idx_asn = 2;
1030 int idx_view_vrf = 3;
1031 int idx_vrf = 4;
1032 int is_new_bgp = 0;
1033 int ret;
1034 as_t as;
1035 struct bgp *bgp;
1036 const char *name = NULL;
1037 enum bgp_instance_type inst_type;
1038
1039 // "router bgp" without an ASN
1040 if (argc == 2) {
1041 // Pending: Make VRF option available for ASN less config
1042 bgp = bgp_get_default();
1043
1044 if (bgp == NULL) {
1045 vty_out(vty, "%% No BGP process is configured\n");
1046 return CMD_WARNING_CONFIG_FAILED;
1047 }
1048
1049 if (listcount(bm->bgp) > 1) {
1050 vty_out(vty, "%% Please specify ASN and VRF\n");
1051 return CMD_WARNING_CONFIG_FAILED;
1052 }
1053 }
1054
1055 // "router bgp X"
1056 else {
1057 as = strtoul(argv[idx_asn]->arg, NULL, 10);
1058
1059 inst_type = BGP_INSTANCE_TYPE_DEFAULT;
1060 if (argc > 3) {
1061 name = argv[idx_vrf]->arg;
1062
1063 if (!strcmp(argv[idx_view_vrf]->text, "vrf")) {
1064 if (strmatch(name, VRF_DEFAULT_NAME))
1065 name = NULL;
1066 else
1067 inst_type = BGP_INSTANCE_TYPE_VRF;
1068 } else if (!strcmp(argv[idx_view_vrf]->text, "view"))
1069 inst_type = BGP_INSTANCE_TYPE_VIEW;
1070 }
1071
1072 if (inst_type == BGP_INSTANCE_TYPE_DEFAULT)
1073 is_new_bgp = (bgp_lookup(as, name) == NULL);
1074
1075 ret = bgp_get(&bgp, &as, name, inst_type);
1076 switch (ret) {
1077 case BGP_ERR_AS_MISMATCH:
1078 vty_out(vty, "BGP is already running; AS is %u\n", as);
1079 return CMD_WARNING_CONFIG_FAILED;
1080 case BGP_ERR_INSTANCE_MISMATCH:
1081 vty_out(vty,
1082 "BGP instance name and AS number mismatch\n");
1083 vty_out(vty,
1084 "BGP instance is already running; AS is %u\n",
1085 as);
1086 return CMD_WARNING_CONFIG_FAILED;
1087 }
1088
1089 /*
1090 * If we just instantiated the default instance, complete
1091 * any pending VRF-VPN leaking that was configured via
1092 * earlier "router bgp X vrf FOO" blocks.
1093 */
1094 if (is_new_bgp && inst_type == BGP_INSTANCE_TYPE_DEFAULT)
1095 vpn_leak_postchange_all();
1096
1097 if (inst_type == BGP_INSTANCE_TYPE_VRF)
1098 bgp_vpn_leak_export(bgp);
1099 /* Pending: handle when user tries to change a view to vrf n vv.
1100 */
1101 }
1102
1103 /* unset the auto created flag as the user config is now present */
1104 UNSET_FLAG(bgp->vrf_flags, BGP_VRF_AUTO);
1105 VTY_PUSH_CONTEXT(BGP_NODE, bgp);
1106
1107 return CMD_SUCCESS;
1108 }
1109
1110 /* "no router bgp" commands. */
1111 DEFUN (no_router_bgp,
1112 no_router_bgp_cmd,
1113 "no router bgp [(1-4294967295)$instasn [<view|vrf> VIEWVRFNAME]]",
1114 NO_STR
1115 ROUTER_STR
1116 BGP_STR
1117 AS_STR
1118 BGP_INSTANCE_HELP_STR)
1119 {
1120 int idx_asn = 3;
1121 int idx_vrf = 5;
1122 as_t as;
1123 struct bgp *bgp;
1124 const char *name = NULL;
1125
1126 // "no router bgp" without an ASN
1127 if (argc == 3) {
1128 // Pending: Make VRF option available for ASN less config
1129 bgp = bgp_get_default();
1130
1131 if (bgp == NULL) {
1132 vty_out(vty, "%% No BGP process is configured\n");
1133 return CMD_WARNING_CONFIG_FAILED;
1134 }
1135
1136 if (listcount(bm->bgp) > 1) {
1137 vty_out(vty, "%% Please specify ASN and VRF\n");
1138 return CMD_WARNING_CONFIG_FAILED;
1139 }
1140
1141 if (bgp->l3vni) {
1142 vty_out(vty, "%% Please unconfigure l3vni %u",
1143 bgp->l3vni);
1144 return CMD_WARNING_CONFIG_FAILED;
1145 }
1146 } else {
1147 as = strtoul(argv[idx_asn]->arg, NULL, 10);
1148
1149 if (argc > 4)
1150 name = argv[idx_vrf]->arg;
1151
1152 /* Lookup bgp structure. */
1153 bgp = bgp_lookup(as, name);
1154 if (!bgp) {
1155 vty_out(vty, "%% Can't find BGP instance\n");
1156 return CMD_WARNING_CONFIG_FAILED;
1157 }
1158
1159 if (bgp->l3vni) {
1160 vty_out(vty, "%% Please unconfigure l3vni %u\n",
1161 bgp->l3vni);
1162 return CMD_WARNING_CONFIG_FAILED;
1163 }
1164
1165 /* Cannot delete default instance if vrf instances exist */
1166 if (bgp->inst_type == BGP_INSTANCE_TYPE_DEFAULT) {
1167 struct listnode *node;
1168 struct bgp *tmp_bgp;
1169
1170 for (ALL_LIST_ELEMENTS_RO(bm->bgp, node, tmp_bgp)) {
1171 if (tmp_bgp->inst_type
1172 == BGP_INSTANCE_TYPE_VRF) {
1173 vty_out(vty,
1174 "%% Cannot delete default BGP instance. Dependent VRF instances exist\n");
1175 return CMD_WARNING_CONFIG_FAILED;
1176 }
1177 }
1178 }
1179 }
1180
1181 if (bgp_vpn_leak_unimport(bgp, vty))
1182 return CMD_WARNING_CONFIG_FAILED;
1183
1184 bgp_delete(bgp);
1185
1186 return CMD_SUCCESS;
1187 }
1188
1189
1190 /* BGP router-id. */
1191
1192 DEFPY (bgp_router_id,
1193 bgp_router_id_cmd,
1194 "bgp router-id A.B.C.D",
1195 BGP_STR
1196 "Override configured router identifier\n"
1197 "Manually configured router identifier\n")
1198 {
1199 VTY_DECLVAR_CONTEXT(bgp, bgp);
1200 bgp_router_id_static_set(bgp, router_id);
1201 return CMD_SUCCESS;
1202 }
1203
1204 DEFPY (no_bgp_router_id,
1205 no_bgp_router_id_cmd,
1206 "no bgp router-id [A.B.C.D]",
1207 NO_STR
1208 BGP_STR
1209 "Override configured router identifier\n"
1210 "Manually configured router identifier\n")
1211 {
1212 VTY_DECLVAR_CONTEXT(bgp, bgp);
1213
1214 if (router_id_str) {
1215 if (!IPV4_ADDR_SAME(&bgp->router_id_static, &router_id)) {
1216 vty_out(vty, "%% BGP router-id doesn't match\n");
1217 return CMD_WARNING_CONFIG_FAILED;
1218 }
1219 }
1220
1221 router_id.s_addr = 0;
1222 bgp_router_id_static_set(bgp, router_id);
1223
1224 return CMD_SUCCESS;
1225 }
1226
1227
1228 /* BGP Cluster ID. */
1229 DEFUN (bgp_cluster_id,
1230 bgp_cluster_id_cmd,
1231 "bgp cluster-id <A.B.C.D|(1-4294967295)>",
1232 BGP_STR
1233 "Configure Route-Reflector Cluster-id\n"
1234 "Route-Reflector Cluster-id in IP address format\n"
1235 "Route-Reflector Cluster-id as 32 bit quantity\n")
1236 {
1237 VTY_DECLVAR_CONTEXT(bgp, bgp);
1238 int idx_ipv4 = 2;
1239 int ret;
1240 struct in_addr cluster;
1241
1242 ret = inet_aton(argv[idx_ipv4]->arg, &cluster);
1243 if (!ret) {
1244 vty_out(vty, "%% Malformed bgp cluster identifier\n");
1245 return CMD_WARNING_CONFIG_FAILED;
1246 }
1247
1248 bgp_cluster_id_set(bgp, &cluster);
1249 bgp_clear_star_soft_out(vty, bgp->name);
1250
1251 return CMD_SUCCESS;
1252 }
1253
1254 DEFUN (no_bgp_cluster_id,
1255 no_bgp_cluster_id_cmd,
1256 "no bgp cluster-id [<A.B.C.D|(1-4294967295)>]",
1257 NO_STR
1258 BGP_STR
1259 "Configure Route-Reflector Cluster-id\n"
1260 "Route-Reflector Cluster-id in IP address format\n"
1261 "Route-Reflector Cluster-id as 32 bit quantity\n")
1262 {
1263 VTY_DECLVAR_CONTEXT(bgp, bgp);
1264 bgp_cluster_id_unset(bgp);
1265 bgp_clear_star_soft_out(vty, bgp->name);
1266
1267 return CMD_SUCCESS;
1268 }
1269
1270 DEFUN (bgp_confederation_identifier,
1271 bgp_confederation_identifier_cmd,
1272 "bgp confederation identifier (1-4294967295)",
1273 "BGP specific commands\n"
1274 "AS confederation parameters\n"
1275 "AS number\n"
1276 "Set routing domain confederation AS\n")
1277 {
1278 VTY_DECLVAR_CONTEXT(bgp, bgp);
1279 int idx_number = 3;
1280 as_t as;
1281
1282 as = strtoul(argv[idx_number]->arg, NULL, 10);
1283
1284 bgp_confederation_id_set(bgp, as);
1285
1286 return CMD_SUCCESS;
1287 }
1288
1289 DEFUN (no_bgp_confederation_identifier,
1290 no_bgp_confederation_identifier_cmd,
1291 "no bgp confederation identifier [(1-4294967295)]",
1292 NO_STR
1293 "BGP specific commands\n"
1294 "AS confederation parameters\n"
1295 "AS number\n"
1296 "Set routing domain confederation AS\n")
1297 {
1298 VTY_DECLVAR_CONTEXT(bgp, bgp);
1299 bgp_confederation_id_unset(bgp);
1300
1301 return CMD_SUCCESS;
1302 }
1303
1304 DEFUN (bgp_confederation_peers,
1305 bgp_confederation_peers_cmd,
1306 "bgp confederation peers (1-4294967295)...",
1307 "BGP specific commands\n"
1308 "AS confederation parameters\n"
1309 "Peer ASs in BGP confederation\n"
1310 AS_STR)
1311 {
1312 VTY_DECLVAR_CONTEXT(bgp, bgp);
1313 int idx_asn = 3;
1314 as_t as;
1315 int i;
1316
1317 for (i = idx_asn; i < argc; i++) {
1318 as = strtoul(argv[i]->arg, NULL, 10);
1319
1320 if (bgp->as == as) {
1321 vty_out(vty,
1322 "%% Local member-AS not allowed in confed peer list\n");
1323 continue;
1324 }
1325
1326 bgp_confederation_peers_add(bgp, as);
1327 }
1328 return CMD_SUCCESS;
1329 }
1330
1331 DEFUN (no_bgp_confederation_peers,
1332 no_bgp_confederation_peers_cmd,
1333 "no bgp confederation peers (1-4294967295)...",
1334 NO_STR
1335 "BGP specific commands\n"
1336 "AS confederation parameters\n"
1337 "Peer ASs in BGP confederation\n"
1338 AS_STR)
1339 {
1340 VTY_DECLVAR_CONTEXT(bgp, bgp);
1341 int idx_asn = 4;
1342 as_t as;
1343 int i;
1344
1345 for (i = idx_asn; i < argc; i++) {
1346 as = strtoul(argv[i]->arg, NULL, 10);
1347
1348 bgp_confederation_peers_remove(bgp, as);
1349 }
1350 return CMD_SUCCESS;
1351 }
1352
1353 /**
1354 * Central routine for maximum-paths configuration.
1355 * @peer_type: BGP_PEER_EBGP or BGP_PEER_IBGP
1356 * @set: 1 for setting values, 0 for removing the max-paths config.
1357 */
1358 static int bgp_maxpaths_config_vty(struct vty *vty, int peer_type,
1359 const char *mpaths, uint16_t options,
1360 int set)
1361 {
1362 VTY_DECLVAR_CONTEXT(bgp, bgp);
1363 uint16_t maxpaths = 0;
1364 int ret;
1365 afi_t afi;
1366 safi_t safi;
1367
1368 afi = bgp_node_afi(vty);
1369 safi = bgp_node_safi(vty);
1370
1371 if (set) {
1372 maxpaths = strtol(mpaths, NULL, 10);
1373 if (maxpaths > multipath_num) {
1374 vty_out(vty,
1375 "%% Maxpaths Specified: %d is > than multipath num specified on bgp command line %d",
1376 maxpaths, multipath_num);
1377 return CMD_WARNING_CONFIG_FAILED;
1378 }
1379 ret = bgp_maximum_paths_set(bgp, afi, safi, peer_type, maxpaths,
1380 options);
1381 } else
1382 ret = bgp_maximum_paths_unset(bgp, afi, safi, peer_type);
1383
1384 if (ret < 0) {
1385 vty_out(vty,
1386 "%% Failed to %sset maximum-paths %s %u for afi %u, safi %u\n",
1387 (set == 1) ? "" : "un",
1388 (peer_type == BGP_PEER_EBGP) ? "ebgp" : "ibgp",
1389 maxpaths, afi, safi);
1390 return CMD_WARNING_CONFIG_FAILED;
1391 }
1392
1393 bgp_recalculate_all_bestpaths(bgp);
1394
1395 return CMD_SUCCESS;
1396 }
1397
1398 DEFUN (bgp_maxmed_admin,
1399 bgp_maxmed_admin_cmd,
1400 "bgp max-med administrative ",
1401 BGP_STR
1402 "Advertise routes with max-med\n"
1403 "Administratively applied, for an indefinite period\n")
1404 {
1405 VTY_DECLVAR_CONTEXT(bgp, bgp);
1406
1407 bgp->v_maxmed_admin = 1;
1408 bgp->maxmed_admin_value = BGP_MAXMED_VALUE_DEFAULT;
1409
1410 bgp_maxmed_update(bgp);
1411
1412 return CMD_SUCCESS;
1413 }
1414
1415 DEFUN (bgp_maxmed_admin_medv,
1416 bgp_maxmed_admin_medv_cmd,
1417 "bgp max-med administrative (0-4294967295)",
1418 BGP_STR
1419 "Advertise routes with max-med\n"
1420 "Administratively applied, for an indefinite period\n"
1421 "Max MED value to be used\n")
1422 {
1423 VTY_DECLVAR_CONTEXT(bgp, bgp);
1424 int idx_number = 3;
1425
1426 bgp->v_maxmed_admin = 1;
1427 bgp->maxmed_admin_value = strtoul(argv[idx_number]->arg, NULL, 10);
1428
1429 bgp_maxmed_update(bgp);
1430
1431 return CMD_SUCCESS;
1432 }
1433
1434 DEFUN (no_bgp_maxmed_admin,
1435 no_bgp_maxmed_admin_cmd,
1436 "no bgp max-med administrative [(0-4294967295)]",
1437 NO_STR
1438 BGP_STR
1439 "Advertise routes with max-med\n"
1440 "Administratively applied, for an indefinite period\n"
1441 "Max MED value to be used\n")
1442 {
1443 VTY_DECLVAR_CONTEXT(bgp, bgp);
1444 bgp->v_maxmed_admin = BGP_MAXMED_ADMIN_UNCONFIGURED;
1445 bgp->maxmed_admin_value = BGP_MAXMED_VALUE_DEFAULT;
1446 bgp_maxmed_update(bgp);
1447
1448 return CMD_SUCCESS;
1449 }
1450
1451 DEFUN (bgp_maxmed_onstartup,
1452 bgp_maxmed_onstartup_cmd,
1453 "bgp max-med on-startup (5-86400) [(0-4294967295)]",
1454 BGP_STR
1455 "Advertise routes with max-med\n"
1456 "Effective on a startup\n"
1457 "Time (seconds) period for max-med\n"
1458 "Max MED value to be used\n")
1459 {
1460 VTY_DECLVAR_CONTEXT(bgp, bgp);
1461 int idx = 0;
1462
1463 argv_find(argv, argc, "(5-86400)", &idx);
1464 bgp->v_maxmed_onstartup = strtoul(argv[idx]->arg, NULL, 10);
1465 if (argv_find(argv, argc, "(0-4294967295)", &idx))
1466 bgp->maxmed_onstartup_value = strtoul(argv[idx]->arg, NULL, 10);
1467 else
1468 bgp->maxmed_onstartup_value = BGP_MAXMED_VALUE_DEFAULT;
1469
1470 bgp_maxmed_update(bgp);
1471
1472 return CMD_SUCCESS;
1473 }
1474
1475 DEFUN (no_bgp_maxmed_onstartup,
1476 no_bgp_maxmed_onstartup_cmd,
1477 "no bgp max-med on-startup [(5-86400) [(0-4294967295)]]",
1478 NO_STR
1479 BGP_STR
1480 "Advertise routes with max-med\n"
1481 "Effective on a startup\n"
1482 "Time (seconds) period for max-med\n"
1483 "Max MED value to be used\n")
1484 {
1485 VTY_DECLVAR_CONTEXT(bgp, bgp);
1486
1487 /* Cancel max-med onstartup if its on */
1488 if (bgp->t_maxmed_onstartup) {
1489 THREAD_TIMER_OFF(bgp->t_maxmed_onstartup);
1490 bgp->maxmed_onstartup_over = 1;
1491 }
1492
1493 bgp->v_maxmed_onstartup = BGP_MAXMED_ONSTARTUP_UNCONFIGURED;
1494 bgp->maxmed_onstartup_value = BGP_MAXMED_VALUE_DEFAULT;
1495
1496 bgp_maxmed_update(bgp);
1497
1498 return CMD_SUCCESS;
1499 }
1500
1501 static int bgp_update_delay_config_vty(struct vty *vty, const char *delay,
1502 const char *wait)
1503 {
1504 VTY_DECLVAR_CONTEXT(bgp, bgp);
1505 uint16_t update_delay;
1506 uint16_t establish_wait;
1507
1508 update_delay = strtoul(delay, NULL, 10);
1509
1510 if (!wait) /* update-delay <delay> */
1511 {
1512 bgp->v_update_delay = update_delay;
1513 bgp->v_establish_wait = bgp->v_update_delay;
1514 return CMD_SUCCESS;
1515 }
1516
1517 /* update-delay <delay> <establish-wait> */
1518 establish_wait = atoi(wait);
1519 if (update_delay < establish_wait) {
1520 vty_out(vty,
1521 "%%Failed: update-delay less than the establish-wait!\n");
1522 return CMD_WARNING_CONFIG_FAILED;
1523 }
1524
1525 bgp->v_update_delay = update_delay;
1526 bgp->v_establish_wait = establish_wait;
1527
1528 return CMD_SUCCESS;
1529 }
1530
1531 static int bgp_update_delay_deconfig_vty(struct vty *vty)
1532 {
1533 VTY_DECLVAR_CONTEXT(bgp, bgp);
1534
1535 bgp->v_update_delay = BGP_UPDATE_DELAY_DEF;
1536 bgp->v_establish_wait = bgp->v_update_delay;
1537
1538 return CMD_SUCCESS;
1539 }
1540
1541 void bgp_config_write_update_delay(struct vty *vty, struct bgp *bgp)
1542 {
1543 if (bgp->v_update_delay != BGP_UPDATE_DELAY_DEF) {
1544 vty_out(vty, " update-delay %d", bgp->v_update_delay);
1545 if (bgp->v_update_delay != bgp->v_establish_wait)
1546 vty_out(vty, " %d", bgp->v_establish_wait);
1547 vty_out(vty, "\n");
1548 }
1549 }
1550
1551
1552 /* Update-delay configuration */
1553 DEFUN (bgp_update_delay,
1554 bgp_update_delay_cmd,
1555 "update-delay (0-3600)",
1556 "Force initial delay for best-path and updates\n"
1557 "Seconds\n")
1558 {
1559 int idx_number = 1;
1560 return bgp_update_delay_config_vty(vty, argv[idx_number]->arg, NULL);
1561 }
1562
1563 DEFUN (bgp_update_delay_establish_wait,
1564 bgp_update_delay_establish_wait_cmd,
1565 "update-delay (0-3600) (1-3600)",
1566 "Force initial delay for best-path and updates\n"
1567 "Seconds\n"
1568 "Seconds\n")
1569 {
1570 int idx_number = 1;
1571 int idx_number_2 = 2;
1572 return bgp_update_delay_config_vty(vty, argv[idx_number]->arg,
1573 argv[idx_number_2]->arg);
1574 }
1575
1576 /* Update-delay deconfiguration */
1577 DEFUN (no_bgp_update_delay,
1578 no_bgp_update_delay_cmd,
1579 "no update-delay [(0-3600) [(1-3600)]]",
1580 NO_STR
1581 "Force initial delay for best-path and updates\n"
1582 "Seconds\n"
1583 "Seconds\n")
1584 {
1585 return bgp_update_delay_deconfig_vty(vty);
1586 }
1587
1588
1589 static int bgp_wpkt_quanta_config_vty(struct vty *vty, const char *num,
1590 char set)
1591 {
1592 VTY_DECLVAR_CONTEXT(bgp, bgp);
1593
1594 if (set) {
1595 uint32_t quanta = strtoul(num, NULL, 10);
1596 atomic_store_explicit(&bgp->wpkt_quanta, quanta,
1597 memory_order_relaxed);
1598 } else {
1599 atomic_store_explicit(&bgp->wpkt_quanta, BGP_WRITE_PACKET_MAX,
1600 memory_order_relaxed);
1601 }
1602
1603 return CMD_SUCCESS;
1604 }
1605
1606 static int bgp_rpkt_quanta_config_vty(struct vty *vty, const char *num,
1607 char set)
1608 {
1609 VTY_DECLVAR_CONTEXT(bgp, bgp);
1610
1611 if (set) {
1612 uint32_t quanta = strtoul(num, NULL, 10);
1613 atomic_store_explicit(&bgp->rpkt_quanta, quanta,
1614 memory_order_relaxed);
1615 } else {
1616 atomic_store_explicit(&bgp->rpkt_quanta, BGP_READ_PACKET_MAX,
1617 memory_order_relaxed);
1618 }
1619
1620 return CMD_SUCCESS;
1621 }
1622
1623 void bgp_config_write_wpkt_quanta(struct vty *vty, struct bgp *bgp)
1624 {
1625 uint32_t quanta =
1626 atomic_load_explicit(&bgp->wpkt_quanta, memory_order_relaxed);
1627 if (quanta != BGP_WRITE_PACKET_MAX)
1628 vty_out(vty, " write-quanta %d\n", quanta);
1629 }
1630
1631 void bgp_config_write_rpkt_quanta(struct vty *vty, struct bgp *bgp)
1632 {
1633 uint32_t quanta =
1634 atomic_load_explicit(&bgp->rpkt_quanta, memory_order_relaxed);
1635 if (quanta != BGP_READ_PACKET_MAX)
1636 vty_out(vty, " read-quanta %d\n", quanta);
1637 }
1638
1639 /* Packet quanta configuration */
1640 DEFUN (bgp_wpkt_quanta,
1641 bgp_wpkt_quanta_cmd,
1642 "write-quanta (1-10)",
1643 "How many packets to write to peer socket per run\n"
1644 "Number of packets\n")
1645 {
1646 int idx_number = 1;
1647 return bgp_wpkt_quanta_config_vty(vty, argv[idx_number]->arg, 1);
1648 }
1649
1650 DEFUN (no_bgp_wpkt_quanta,
1651 no_bgp_wpkt_quanta_cmd,
1652 "no write-quanta (1-10)",
1653 NO_STR
1654 "How many packets to write to peer socket per I/O cycle\n"
1655 "Number of packets\n")
1656 {
1657 int idx_number = 2;
1658 return bgp_wpkt_quanta_config_vty(vty, argv[idx_number]->arg, 0);
1659 }
1660
1661 DEFUN (bgp_rpkt_quanta,
1662 bgp_rpkt_quanta_cmd,
1663 "read-quanta (1-10)",
1664 "How many packets to read from peer socket per I/O cycle\n"
1665 "Number of packets\n")
1666 {
1667 int idx_number = 1;
1668 return bgp_rpkt_quanta_config_vty(vty, argv[idx_number]->arg, 1);
1669 }
1670
1671 DEFUN (no_bgp_rpkt_quanta,
1672 no_bgp_rpkt_quanta_cmd,
1673 "no read-quanta (1-10)",
1674 NO_STR
1675 "How many packets to read from peer socket per I/O cycle\n"
1676 "Number of packets\n")
1677 {
1678 int idx_number = 2;
1679 return bgp_rpkt_quanta_config_vty(vty, argv[idx_number]->arg, 0);
1680 }
1681
1682 void bgp_config_write_coalesce_time(struct vty *vty, struct bgp *bgp)
1683 {
1684 if (!bgp->heuristic_coalesce)
1685 vty_out(vty, " coalesce-time %u\n", bgp->coalesce_time);
1686 }
1687
1688
1689 DEFUN (bgp_coalesce_time,
1690 bgp_coalesce_time_cmd,
1691 "coalesce-time (0-4294967295)",
1692 "Subgroup coalesce timer\n"
1693 "Subgroup coalesce timer value (in ms)\n")
1694 {
1695 VTY_DECLVAR_CONTEXT(bgp, bgp);
1696
1697 int idx = 0;
1698 argv_find(argv, argc, "(0-4294967295)", &idx);
1699 bgp->heuristic_coalesce = false;
1700 bgp->coalesce_time = strtoul(argv[idx]->arg, NULL, 10);
1701 return CMD_SUCCESS;
1702 }
1703
1704 DEFUN (no_bgp_coalesce_time,
1705 no_bgp_coalesce_time_cmd,
1706 "no coalesce-time (0-4294967295)",
1707 NO_STR
1708 "Subgroup coalesce timer\n"
1709 "Subgroup coalesce timer value (in ms)\n")
1710 {
1711 VTY_DECLVAR_CONTEXT(bgp, bgp);
1712
1713 bgp->heuristic_coalesce = true;
1714 bgp->coalesce_time = BGP_DEFAULT_SUBGROUP_COALESCE_TIME;
1715 return CMD_SUCCESS;
1716 }
1717
1718 /* Maximum-paths configuration */
1719 DEFUN (bgp_maxpaths,
1720 bgp_maxpaths_cmd,
1721 "maximum-paths " CMD_RANGE_STR(1, MULTIPATH_NUM),
1722 "Forward packets over multiple paths\n"
1723 "Number of paths\n")
1724 {
1725 int idx_number = 1;
1726 return bgp_maxpaths_config_vty(vty, BGP_PEER_EBGP,
1727 argv[idx_number]->arg, 0, 1);
1728 }
1729
1730 ALIAS_HIDDEN(bgp_maxpaths, bgp_maxpaths_hidden_cmd,
1731 "maximum-paths " CMD_RANGE_STR(1, MULTIPATH_NUM),
1732 "Forward packets over multiple paths\n"
1733 "Number of paths\n")
1734
1735 DEFUN (bgp_maxpaths_ibgp,
1736 bgp_maxpaths_ibgp_cmd,
1737 "maximum-paths ibgp " CMD_RANGE_STR(1, MULTIPATH_NUM),
1738 "Forward packets over multiple paths\n"
1739 "iBGP-multipath\n"
1740 "Number of paths\n")
1741 {
1742 int idx_number = 2;
1743 return bgp_maxpaths_config_vty(vty, BGP_PEER_IBGP,
1744 argv[idx_number]->arg, 0, 1);
1745 }
1746
1747 ALIAS_HIDDEN(bgp_maxpaths_ibgp, bgp_maxpaths_ibgp_hidden_cmd,
1748 "maximum-paths ibgp " CMD_RANGE_STR(1, MULTIPATH_NUM),
1749 "Forward packets over multiple paths\n"
1750 "iBGP-multipath\n"
1751 "Number of paths\n")
1752
1753 DEFUN (bgp_maxpaths_ibgp_cluster,
1754 bgp_maxpaths_ibgp_cluster_cmd,
1755 "maximum-paths ibgp " CMD_RANGE_STR(1, MULTIPATH_NUM) " equal-cluster-length",
1756 "Forward packets over multiple paths\n"
1757 "iBGP-multipath\n"
1758 "Number of paths\n"
1759 "Match the cluster length\n")
1760 {
1761 int idx_number = 2;
1762 return bgp_maxpaths_config_vty(
1763 vty, BGP_PEER_IBGP, argv[idx_number]->arg,
1764 BGP_FLAG_IBGP_MULTIPATH_SAME_CLUSTERLEN, 1);
1765 }
1766
1767 ALIAS_HIDDEN(bgp_maxpaths_ibgp_cluster, bgp_maxpaths_ibgp_cluster_hidden_cmd,
1768 "maximum-paths ibgp " CMD_RANGE_STR(
1769 1, MULTIPATH_NUM) " equal-cluster-length",
1770 "Forward packets over multiple paths\n"
1771 "iBGP-multipath\n"
1772 "Number of paths\n"
1773 "Match the cluster length\n")
1774
1775 DEFUN (no_bgp_maxpaths,
1776 no_bgp_maxpaths_cmd,
1777 "no maximum-paths [" CMD_RANGE_STR(1, MULTIPATH_NUM) "]",
1778 NO_STR
1779 "Forward packets over multiple paths\n"
1780 "Number of paths\n")
1781 {
1782 return bgp_maxpaths_config_vty(vty, BGP_PEER_EBGP, NULL, 0, 0);
1783 }
1784
1785 ALIAS_HIDDEN(no_bgp_maxpaths, no_bgp_maxpaths_hidden_cmd,
1786 "no maximum-paths [" CMD_RANGE_STR(1, MULTIPATH_NUM) "]", NO_STR
1787 "Forward packets over multiple paths\n"
1788 "Number of paths\n")
1789
1790 DEFUN (no_bgp_maxpaths_ibgp,
1791 no_bgp_maxpaths_ibgp_cmd,
1792 "no maximum-paths ibgp [" CMD_RANGE_STR(1, MULTIPATH_NUM) " [equal-cluster-length]]",
1793 NO_STR
1794 "Forward packets over multiple paths\n"
1795 "iBGP-multipath\n"
1796 "Number of paths\n"
1797 "Match the cluster length\n")
1798 {
1799 return bgp_maxpaths_config_vty(vty, BGP_PEER_IBGP, NULL, 0, 0);
1800 }
1801
1802 ALIAS_HIDDEN(no_bgp_maxpaths_ibgp, no_bgp_maxpaths_ibgp_hidden_cmd,
1803 "no maximum-paths ibgp [" CMD_RANGE_STR(
1804 1, MULTIPATH_NUM) " [equal-cluster-length]]",
1805 NO_STR
1806 "Forward packets over multiple paths\n"
1807 "iBGP-multipath\n"
1808 "Number of paths\n"
1809 "Match the cluster length\n")
1810
1811 void bgp_config_write_maxpaths(struct vty *vty, struct bgp *bgp, afi_t afi,
1812 safi_t safi)
1813 {
1814 if (bgp->maxpaths[afi][safi].maxpaths_ebgp != MULTIPATH_NUM) {
1815 vty_out(vty, " maximum-paths %d\n",
1816 bgp->maxpaths[afi][safi].maxpaths_ebgp);
1817 }
1818
1819 if (bgp->maxpaths[afi][safi].maxpaths_ibgp != MULTIPATH_NUM) {
1820 vty_out(vty, " maximum-paths ibgp %d",
1821 bgp->maxpaths[afi][safi].maxpaths_ibgp);
1822 if (CHECK_FLAG(bgp->maxpaths[afi][safi].ibgp_flags,
1823 BGP_FLAG_IBGP_MULTIPATH_SAME_CLUSTERLEN))
1824 vty_out(vty, " equal-cluster-length");
1825 vty_out(vty, "\n");
1826 }
1827 }
1828
1829 /* BGP timers. */
1830
1831 DEFUN (bgp_timers,
1832 bgp_timers_cmd,
1833 "timers bgp (0-65535) (0-65535)",
1834 "Adjust routing timers\n"
1835 "BGP timers\n"
1836 "Keepalive interval\n"
1837 "Holdtime\n")
1838 {
1839 VTY_DECLVAR_CONTEXT(bgp, bgp);
1840 int idx_number = 2;
1841 int idx_number_2 = 3;
1842 unsigned long keepalive = 0;
1843 unsigned long holdtime = 0;
1844
1845 keepalive = strtoul(argv[idx_number]->arg, NULL, 10);
1846 holdtime = strtoul(argv[idx_number_2]->arg, NULL, 10);
1847
1848 /* Holdtime value check. */
1849 if (holdtime < 3 && holdtime != 0) {
1850 vty_out(vty,
1851 "%% hold time value must be either 0 or greater than 3\n");
1852 return CMD_WARNING_CONFIG_FAILED;
1853 }
1854
1855 bgp_timers_set(bgp, keepalive, holdtime);
1856
1857 return CMD_SUCCESS;
1858 }
1859
1860 DEFUN (no_bgp_timers,
1861 no_bgp_timers_cmd,
1862 "no timers bgp [(0-65535) (0-65535)]",
1863 NO_STR
1864 "Adjust routing timers\n"
1865 "BGP timers\n"
1866 "Keepalive interval\n"
1867 "Holdtime\n")
1868 {
1869 VTY_DECLVAR_CONTEXT(bgp, bgp);
1870 bgp_timers_unset(bgp);
1871
1872 return CMD_SUCCESS;
1873 }
1874
1875
1876 DEFUN (bgp_client_to_client_reflection,
1877 bgp_client_to_client_reflection_cmd,
1878 "bgp client-to-client reflection",
1879 "BGP specific commands\n"
1880 "Configure client to client route reflection\n"
1881 "reflection of routes allowed\n")
1882 {
1883 VTY_DECLVAR_CONTEXT(bgp, bgp);
1884 bgp_flag_unset(bgp, BGP_FLAG_NO_CLIENT_TO_CLIENT);
1885 bgp_clear_star_soft_out(vty, bgp->name);
1886
1887 return CMD_SUCCESS;
1888 }
1889
1890 DEFUN (no_bgp_client_to_client_reflection,
1891 no_bgp_client_to_client_reflection_cmd,
1892 "no bgp client-to-client reflection",
1893 NO_STR
1894 "BGP specific commands\n"
1895 "Configure client to client route reflection\n"
1896 "reflection of routes allowed\n")
1897 {
1898 VTY_DECLVAR_CONTEXT(bgp, bgp);
1899 bgp_flag_set(bgp, BGP_FLAG_NO_CLIENT_TO_CLIENT);
1900 bgp_clear_star_soft_out(vty, bgp->name);
1901
1902 return CMD_SUCCESS;
1903 }
1904
1905 /* "bgp always-compare-med" configuration. */
1906 DEFUN (bgp_always_compare_med,
1907 bgp_always_compare_med_cmd,
1908 "bgp always-compare-med",
1909 "BGP specific commands\n"
1910 "Allow comparing MED from different neighbors\n")
1911 {
1912 VTY_DECLVAR_CONTEXT(bgp, bgp);
1913 bgp_flag_set(bgp, BGP_FLAG_ALWAYS_COMPARE_MED);
1914 bgp_recalculate_all_bestpaths(bgp);
1915
1916 return CMD_SUCCESS;
1917 }
1918
1919 DEFUN (no_bgp_always_compare_med,
1920 no_bgp_always_compare_med_cmd,
1921 "no bgp always-compare-med",
1922 NO_STR
1923 "BGP specific commands\n"
1924 "Allow comparing MED from different neighbors\n")
1925 {
1926 VTY_DECLVAR_CONTEXT(bgp, bgp);
1927 bgp_flag_unset(bgp, BGP_FLAG_ALWAYS_COMPARE_MED);
1928 bgp_recalculate_all_bestpaths(bgp);
1929
1930 return CMD_SUCCESS;
1931 }
1932
1933
1934 DEFUN(bgp_ebgp_requires_policy, bgp_ebgp_requires_policy_cmd,
1935 "bgp ebgp-requires-policy",
1936 "BGP specific commands\n"
1937 "Require in and out policy for eBGP peers (RFC8212)\n")
1938 {
1939 VTY_DECLVAR_CONTEXT(bgp, bgp);
1940 bgp->ebgp_requires_policy = DEFAULT_EBGP_POLICY_ENABLED;
1941 return CMD_SUCCESS;
1942 }
1943
1944 DEFUN(no_bgp_ebgp_requires_policy, no_bgp_ebgp_requires_policy_cmd,
1945 "no bgp ebgp-requires-policy",
1946 NO_STR
1947 "BGP specific commands\n"
1948 "Require in and out policy for eBGP peers (RFC8212)\n")
1949 {
1950 VTY_DECLVAR_CONTEXT(bgp, bgp);
1951 bgp->ebgp_requires_policy = DEFAULT_EBGP_POLICY_DISABLED;
1952 return CMD_SUCCESS;
1953 }
1954
1955
1956 /* "bgp deterministic-med" configuration. */
1957 DEFUN (bgp_deterministic_med,
1958 bgp_deterministic_med_cmd,
1959 "bgp deterministic-med",
1960 "BGP specific commands\n"
1961 "Pick the best-MED path among paths advertised from the neighboring AS\n")
1962 {
1963 VTY_DECLVAR_CONTEXT(bgp, bgp);
1964
1965 if (!bgp_flag_check(bgp, BGP_FLAG_DETERMINISTIC_MED)) {
1966 bgp_flag_set(bgp, BGP_FLAG_DETERMINISTIC_MED);
1967 bgp_recalculate_all_bestpaths(bgp);
1968 }
1969
1970 return CMD_SUCCESS;
1971 }
1972
1973 DEFUN (no_bgp_deterministic_med,
1974 no_bgp_deterministic_med_cmd,
1975 "no bgp deterministic-med",
1976 NO_STR
1977 "BGP specific commands\n"
1978 "Pick the best-MED path among paths advertised from the neighboring AS\n")
1979 {
1980 VTY_DECLVAR_CONTEXT(bgp, bgp);
1981 int bestpath_per_as_used;
1982 afi_t afi;
1983 safi_t safi;
1984 struct peer *peer;
1985 struct listnode *node, *nnode;
1986
1987 if (bgp_flag_check(bgp, BGP_FLAG_DETERMINISTIC_MED)) {
1988 bestpath_per_as_used = 0;
1989
1990 for (ALL_LIST_ELEMENTS(bgp->peer, node, nnode, peer)) {
1991 FOREACH_AFI_SAFI (afi, safi)
1992 if (bgp_addpath_dmed_required(
1993 peer->addpath_type[afi][safi])) {
1994 bestpath_per_as_used = 1;
1995 break;
1996 }
1997
1998 if (bestpath_per_as_used)
1999 break;
2000 }
2001
2002 if (bestpath_per_as_used) {
2003 vty_out(vty,
2004 "bgp deterministic-med cannot be disabled while addpath-tx-bestpath-per-AS is in use\n");
2005 return CMD_WARNING_CONFIG_FAILED;
2006 } else {
2007 bgp_flag_unset(bgp, BGP_FLAG_DETERMINISTIC_MED);
2008 bgp_recalculate_all_bestpaths(bgp);
2009 }
2010 }
2011
2012 return CMD_SUCCESS;
2013 }
2014
2015 /* "bgp graceful-restart" configuration. */
2016 DEFUN (bgp_graceful_restart,
2017 bgp_graceful_restart_cmd,
2018 "bgp graceful-restart",
2019 "BGP specific commands\n"
2020 "Graceful restart capability parameters\n")
2021 {
2022 VTY_DECLVAR_CONTEXT(bgp, bgp);
2023 bgp_flag_set(bgp, BGP_FLAG_GRACEFUL_RESTART);
2024 return CMD_SUCCESS;
2025 }
2026
2027 DEFUN (no_bgp_graceful_restart,
2028 no_bgp_graceful_restart_cmd,
2029 "no bgp graceful-restart",
2030 NO_STR
2031 "BGP specific commands\n"
2032 "Graceful restart capability parameters\n")
2033 {
2034 VTY_DECLVAR_CONTEXT(bgp, bgp);
2035 bgp_flag_unset(bgp, BGP_FLAG_GRACEFUL_RESTART);
2036 return CMD_SUCCESS;
2037 }
2038
2039 DEFUN (bgp_graceful_restart_stalepath_time,
2040 bgp_graceful_restart_stalepath_time_cmd,
2041 "bgp graceful-restart stalepath-time (1-4095)",
2042 "BGP specific commands\n"
2043 "Graceful restart capability parameters\n"
2044 "Set the max time to hold onto restarting peer's stale paths\n"
2045 "Delay value (seconds)\n")
2046 {
2047 VTY_DECLVAR_CONTEXT(bgp, bgp);
2048 int idx_number = 3;
2049 uint32_t stalepath;
2050
2051 stalepath = strtoul(argv[idx_number]->arg, NULL, 10);
2052 bgp->stalepath_time = stalepath;
2053 return CMD_SUCCESS;
2054 }
2055
2056 DEFUN (bgp_graceful_restart_restart_time,
2057 bgp_graceful_restart_restart_time_cmd,
2058 "bgp graceful-restart restart-time (1-4095)",
2059 "BGP specific commands\n"
2060 "Graceful restart capability parameters\n"
2061 "Set the time to wait to delete stale routes before a BGP open message is received\n"
2062 "Delay value (seconds)\n")
2063 {
2064 VTY_DECLVAR_CONTEXT(bgp, bgp);
2065 int idx_number = 3;
2066 uint32_t restart;
2067
2068 restart = strtoul(argv[idx_number]->arg, NULL, 10);
2069 bgp->restart_time = restart;
2070 return CMD_SUCCESS;
2071 }
2072
2073 DEFUN (no_bgp_graceful_restart_stalepath_time,
2074 no_bgp_graceful_restart_stalepath_time_cmd,
2075 "no bgp graceful-restart stalepath-time [(1-4095)]",
2076 NO_STR
2077 "BGP specific commands\n"
2078 "Graceful restart capability parameters\n"
2079 "Set the max time to hold onto restarting peer's stale paths\n"
2080 "Delay value (seconds)\n")
2081 {
2082 VTY_DECLVAR_CONTEXT(bgp, bgp);
2083
2084 bgp->stalepath_time = BGP_DEFAULT_STALEPATH_TIME;
2085 return CMD_SUCCESS;
2086 }
2087
2088 DEFUN (no_bgp_graceful_restart_restart_time,
2089 no_bgp_graceful_restart_restart_time_cmd,
2090 "no bgp graceful-restart restart-time [(1-4095)]",
2091 NO_STR
2092 "BGP specific commands\n"
2093 "Graceful restart capability parameters\n"
2094 "Set the time to wait to delete stale routes before a BGP open message is received\n"
2095 "Delay value (seconds)\n")
2096 {
2097 VTY_DECLVAR_CONTEXT(bgp, bgp);
2098
2099 bgp->restart_time = BGP_DEFAULT_RESTART_TIME;
2100 return CMD_SUCCESS;
2101 }
2102
2103 DEFUN (bgp_graceful_restart_preserve_fw,
2104 bgp_graceful_restart_preserve_fw_cmd,
2105 "bgp graceful-restart preserve-fw-state",
2106 "BGP specific commands\n"
2107 "Graceful restart capability parameters\n"
2108 "Sets F-bit indication that fib is preserved while doing Graceful Restart\n")
2109 {
2110 VTY_DECLVAR_CONTEXT(bgp, bgp);
2111 bgp_flag_set(bgp, BGP_FLAG_GR_PRESERVE_FWD);
2112 return CMD_SUCCESS;
2113 }
2114
2115 DEFUN (no_bgp_graceful_restart_preserve_fw,
2116 no_bgp_graceful_restart_preserve_fw_cmd,
2117 "no bgp graceful-restart preserve-fw-state",
2118 NO_STR
2119 "BGP specific commands\n"
2120 "Graceful restart capability parameters\n"
2121 "Unsets F-bit indication that fib is preserved while doing Graceful Restart\n")
2122 {
2123 VTY_DECLVAR_CONTEXT(bgp, bgp);
2124 bgp_flag_unset(bgp, BGP_FLAG_GR_PRESERVE_FWD);
2125 return CMD_SUCCESS;
2126 }
2127
2128 /* "bgp graceful-shutdown" configuration */
2129 DEFUN (bgp_graceful_shutdown,
2130 bgp_graceful_shutdown_cmd,
2131 "bgp graceful-shutdown",
2132 BGP_STR
2133 "Graceful shutdown parameters\n")
2134 {
2135 VTY_DECLVAR_CONTEXT(bgp, bgp);
2136
2137 if (!bgp_flag_check(bgp, BGP_FLAG_GRACEFUL_SHUTDOWN)) {
2138 bgp_flag_set(bgp, BGP_FLAG_GRACEFUL_SHUTDOWN);
2139 bgp_static_redo_import_check(bgp);
2140 bgp_redistribute_redo(bgp);
2141 bgp_clear_star_soft_out(vty, bgp->name);
2142 bgp_clear_star_soft_in(vty, bgp->name);
2143 }
2144
2145 return CMD_SUCCESS;
2146 }
2147
2148 DEFUN (no_bgp_graceful_shutdown,
2149 no_bgp_graceful_shutdown_cmd,
2150 "no bgp graceful-shutdown",
2151 NO_STR
2152 BGP_STR
2153 "Graceful shutdown parameters\n")
2154 {
2155 VTY_DECLVAR_CONTEXT(bgp, bgp);
2156
2157 if (bgp_flag_check(bgp, BGP_FLAG_GRACEFUL_SHUTDOWN)) {
2158 bgp_flag_unset(bgp, BGP_FLAG_GRACEFUL_SHUTDOWN);
2159 bgp_static_redo_import_check(bgp);
2160 bgp_redistribute_redo(bgp);
2161 bgp_clear_star_soft_out(vty, bgp->name);
2162 bgp_clear_star_soft_in(vty, bgp->name);
2163 }
2164
2165 return CMD_SUCCESS;
2166 }
2167
2168 /* "bgp fast-external-failover" configuration. */
2169 DEFUN (bgp_fast_external_failover,
2170 bgp_fast_external_failover_cmd,
2171 "bgp fast-external-failover",
2172 BGP_STR
2173 "Immediately reset session if a link to a directly connected external peer goes down\n")
2174 {
2175 VTY_DECLVAR_CONTEXT(bgp, bgp);
2176 bgp_flag_unset(bgp, BGP_FLAG_NO_FAST_EXT_FAILOVER);
2177 return CMD_SUCCESS;
2178 }
2179
2180 DEFUN (no_bgp_fast_external_failover,
2181 no_bgp_fast_external_failover_cmd,
2182 "no bgp fast-external-failover",
2183 NO_STR
2184 BGP_STR
2185 "Immediately reset session if a link to a directly connected external peer goes down\n")
2186 {
2187 VTY_DECLVAR_CONTEXT(bgp, bgp);
2188 bgp_flag_set(bgp, BGP_FLAG_NO_FAST_EXT_FAILOVER);
2189 return CMD_SUCCESS;
2190 }
2191
2192 /* "bgp bestpath compare-routerid" configuration. */
2193 DEFUN (bgp_bestpath_compare_router_id,
2194 bgp_bestpath_compare_router_id_cmd,
2195 "bgp bestpath compare-routerid",
2196 "BGP specific commands\n"
2197 "Change the default bestpath selection\n"
2198 "Compare router-id for identical EBGP paths\n")
2199 {
2200 VTY_DECLVAR_CONTEXT(bgp, bgp);
2201 bgp_flag_set(bgp, BGP_FLAG_COMPARE_ROUTER_ID);
2202 bgp_recalculate_all_bestpaths(bgp);
2203
2204 return CMD_SUCCESS;
2205 }
2206
2207 DEFUN (no_bgp_bestpath_compare_router_id,
2208 no_bgp_bestpath_compare_router_id_cmd,
2209 "no bgp bestpath compare-routerid",
2210 NO_STR
2211 "BGP specific commands\n"
2212 "Change the default bestpath selection\n"
2213 "Compare router-id for identical EBGP paths\n")
2214 {
2215 VTY_DECLVAR_CONTEXT(bgp, bgp);
2216 bgp_flag_unset(bgp, BGP_FLAG_COMPARE_ROUTER_ID);
2217 bgp_recalculate_all_bestpaths(bgp);
2218
2219 return CMD_SUCCESS;
2220 }
2221
2222 /* "bgp bestpath as-path ignore" configuration. */
2223 DEFUN (bgp_bestpath_aspath_ignore,
2224 bgp_bestpath_aspath_ignore_cmd,
2225 "bgp bestpath as-path ignore",
2226 "BGP specific commands\n"
2227 "Change the default bestpath selection\n"
2228 "AS-path attribute\n"
2229 "Ignore as-path length in selecting a route\n")
2230 {
2231 VTY_DECLVAR_CONTEXT(bgp, bgp);
2232 bgp_flag_set(bgp, BGP_FLAG_ASPATH_IGNORE);
2233 bgp_recalculate_all_bestpaths(bgp);
2234
2235 return CMD_SUCCESS;
2236 }
2237
2238 DEFUN (no_bgp_bestpath_aspath_ignore,
2239 no_bgp_bestpath_aspath_ignore_cmd,
2240 "no bgp bestpath as-path ignore",
2241 NO_STR
2242 "BGP specific commands\n"
2243 "Change the default bestpath selection\n"
2244 "AS-path attribute\n"
2245 "Ignore as-path length in selecting a route\n")
2246 {
2247 VTY_DECLVAR_CONTEXT(bgp, bgp);
2248 bgp_flag_unset(bgp, BGP_FLAG_ASPATH_IGNORE);
2249 bgp_recalculate_all_bestpaths(bgp);
2250
2251 return CMD_SUCCESS;
2252 }
2253
2254 /* "bgp bestpath as-path confed" configuration. */
2255 DEFUN (bgp_bestpath_aspath_confed,
2256 bgp_bestpath_aspath_confed_cmd,
2257 "bgp bestpath as-path confed",
2258 "BGP specific commands\n"
2259 "Change the default bestpath selection\n"
2260 "AS-path attribute\n"
2261 "Compare path lengths including confederation sets & sequences in selecting a route\n")
2262 {
2263 VTY_DECLVAR_CONTEXT(bgp, bgp);
2264 bgp_flag_set(bgp, BGP_FLAG_ASPATH_CONFED);
2265 bgp_recalculate_all_bestpaths(bgp);
2266
2267 return CMD_SUCCESS;
2268 }
2269
2270 DEFUN (no_bgp_bestpath_aspath_confed,
2271 no_bgp_bestpath_aspath_confed_cmd,
2272 "no bgp bestpath as-path confed",
2273 NO_STR
2274 "BGP specific commands\n"
2275 "Change the default bestpath selection\n"
2276 "AS-path attribute\n"
2277 "Compare path lengths including confederation sets & sequences in selecting a route\n")
2278 {
2279 VTY_DECLVAR_CONTEXT(bgp, bgp);
2280 bgp_flag_unset(bgp, BGP_FLAG_ASPATH_CONFED);
2281 bgp_recalculate_all_bestpaths(bgp);
2282
2283 return CMD_SUCCESS;
2284 }
2285
2286 /* "bgp bestpath as-path multipath-relax" configuration. */
2287 DEFUN (bgp_bestpath_aspath_multipath_relax,
2288 bgp_bestpath_aspath_multipath_relax_cmd,
2289 "bgp bestpath as-path multipath-relax [<as-set|no-as-set>]",
2290 "BGP specific commands\n"
2291 "Change the default bestpath selection\n"
2292 "AS-path attribute\n"
2293 "Allow load sharing across routes that have different AS paths (but same length)\n"
2294 "Generate an AS_SET\n"
2295 "Do not generate an AS_SET\n")
2296 {
2297 VTY_DECLVAR_CONTEXT(bgp, bgp);
2298 int idx = 0;
2299 bgp_flag_set(bgp, BGP_FLAG_ASPATH_MULTIPATH_RELAX);
2300
2301 /* no-as-set is now the default behavior so we can silently
2302 * ignore it */
2303 if (argv_find(argv, argc, "as-set", &idx))
2304 bgp_flag_set(bgp, BGP_FLAG_MULTIPATH_RELAX_AS_SET);
2305 else
2306 bgp_flag_unset(bgp, BGP_FLAG_MULTIPATH_RELAX_AS_SET);
2307
2308 bgp_recalculate_all_bestpaths(bgp);
2309
2310 return CMD_SUCCESS;
2311 }
2312
2313 DEFUN (no_bgp_bestpath_aspath_multipath_relax,
2314 no_bgp_bestpath_aspath_multipath_relax_cmd,
2315 "no bgp bestpath as-path multipath-relax [<as-set|no-as-set>]",
2316 NO_STR
2317 "BGP specific commands\n"
2318 "Change the default bestpath selection\n"
2319 "AS-path attribute\n"
2320 "Allow load sharing across routes that have different AS paths (but same length)\n"
2321 "Generate an AS_SET\n"
2322 "Do not generate an AS_SET\n")
2323 {
2324 VTY_DECLVAR_CONTEXT(bgp, bgp);
2325 bgp_flag_unset(bgp, BGP_FLAG_ASPATH_MULTIPATH_RELAX);
2326 bgp_flag_unset(bgp, BGP_FLAG_MULTIPATH_RELAX_AS_SET);
2327 bgp_recalculate_all_bestpaths(bgp);
2328
2329 return CMD_SUCCESS;
2330 }
2331
2332 /* "bgp log-neighbor-changes" configuration. */
2333 DEFUN (bgp_log_neighbor_changes,
2334 bgp_log_neighbor_changes_cmd,
2335 "bgp log-neighbor-changes",
2336 "BGP specific commands\n"
2337 "Log neighbor up/down and reset reason\n")
2338 {
2339 VTY_DECLVAR_CONTEXT(bgp, bgp);
2340 bgp_flag_set(bgp, BGP_FLAG_LOG_NEIGHBOR_CHANGES);
2341 return CMD_SUCCESS;
2342 }
2343
2344 DEFUN (no_bgp_log_neighbor_changes,
2345 no_bgp_log_neighbor_changes_cmd,
2346 "no bgp log-neighbor-changes",
2347 NO_STR
2348 "BGP specific commands\n"
2349 "Log neighbor up/down and reset reason\n")
2350 {
2351 VTY_DECLVAR_CONTEXT(bgp, bgp);
2352 bgp_flag_unset(bgp, BGP_FLAG_LOG_NEIGHBOR_CHANGES);
2353 return CMD_SUCCESS;
2354 }
2355
2356 /* "bgp bestpath med" configuration. */
2357 DEFUN (bgp_bestpath_med,
2358 bgp_bestpath_med_cmd,
2359 "bgp bestpath med <confed [missing-as-worst]|missing-as-worst [confed]>",
2360 "BGP specific commands\n"
2361 "Change the default bestpath selection\n"
2362 "MED attribute\n"
2363 "Compare MED among confederation paths\n"
2364 "Treat missing MED as the least preferred one\n"
2365 "Treat missing MED as the least preferred one\n"
2366 "Compare MED among confederation paths\n")
2367 {
2368 VTY_DECLVAR_CONTEXT(bgp, bgp);
2369
2370 int idx = 0;
2371 if (argv_find(argv, argc, "confed", &idx))
2372 bgp_flag_set(bgp, BGP_FLAG_MED_CONFED);
2373 idx = 0;
2374 if (argv_find(argv, argc, "missing-as-worst", &idx))
2375 bgp_flag_set(bgp, BGP_FLAG_MED_MISSING_AS_WORST);
2376
2377 bgp_recalculate_all_bestpaths(bgp);
2378
2379 return CMD_SUCCESS;
2380 }
2381
2382 DEFUN (no_bgp_bestpath_med,
2383 no_bgp_bestpath_med_cmd,
2384 "no bgp bestpath med <confed [missing-as-worst]|missing-as-worst [confed]>",
2385 NO_STR
2386 "BGP specific commands\n"
2387 "Change the default bestpath selection\n"
2388 "MED attribute\n"
2389 "Compare MED among confederation paths\n"
2390 "Treat missing MED as the least preferred one\n"
2391 "Treat missing MED as the least preferred one\n"
2392 "Compare MED among confederation paths\n")
2393 {
2394 VTY_DECLVAR_CONTEXT(bgp, bgp);
2395
2396 int idx = 0;
2397 if (argv_find(argv, argc, "confed", &idx))
2398 bgp_flag_unset(bgp, BGP_FLAG_MED_CONFED);
2399 idx = 0;
2400 if (argv_find(argv, argc, "missing-as-worst", &idx))
2401 bgp_flag_unset(bgp, BGP_FLAG_MED_MISSING_AS_WORST);
2402
2403 bgp_recalculate_all_bestpaths(bgp);
2404
2405 return CMD_SUCCESS;
2406 }
2407
2408 /* "no bgp default ipv4-unicast". */
2409 DEFUN (no_bgp_default_ipv4_unicast,
2410 no_bgp_default_ipv4_unicast_cmd,
2411 "no bgp default ipv4-unicast",
2412 NO_STR
2413 "BGP specific commands\n"
2414 "Configure BGP defaults\n"
2415 "Activate ipv4-unicast for a peer by default\n")
2416 {
2417 VTY_DECLVAR_CONTEXT(bgp, bgp);
2418 bgp_flag_set(bgp, BGP_FLAG_NO_DEFAULT_IPV4);
2419 return CMD_SUCCESS;
2420 }
2421
2422 DEFUN (bgp_default_ipv4_unicast,
2423 bgp_default_ipv4_unicast_cmd,
2424 "bgp default ipv4-unicast",
2425 "BGP specific commands\n"
2426 "Configure BGP defaults\n"
2427 "Activate ipv4-unicast for a peer by default\n")
2428 {
2429 VTY_DECLVAR_CONTEXT(bgp, bgp);
2430 bgp_flag_unset(bgp, BGP_FLAG_NO_DEFAULT_IPV4);
2431 return CMD_SUCCESS;
2432 }
2433
2434 /* Display hostname in certain command outputs */
2435 DEFUN (bgp_default_show_hostname,
2436 bgp_default_show_hostname_cmd,
2437 "bgp default show-hostname",
2438 "BGP specific commands\n"
2439 "Configure BGP defaults\n"
2440 "Show hostname in certain command outputs\n")
2441 {
2442 VTY_DECLVAR_CONTEXT(bgp, bgp);
2443 bgp_flag_set(bgp, BGP_FLAG_SHOW_HOSTNAME);
2444 return CMD_SUCCESS;
2445 }
2446
2447 DEFUN (no_bgp_default_show_hostname,
2448 no_bgp_default_show_hostname_cmd,
2449 "no bgp default show-hostname",
2450 NO_STR
2451 "BGP specific commands\n"
2452 "Configure BGP defaults\n"
2453 "Show hostname in certain command outputs\n")
2454 {
2455 VTY_DECLVAR_CONTEXT(bgp, bgp);
2456 bgp_flag_unset(bgp, BGP_FLAG_SHOW_HOSTNAME);
2457 return CMD_SUCCESS;
2458 }
2459
2460 /* "bgp network import-check" configuration. */
2461 DEFUN (bgp_network_import_check,
2462 bgp_network_import_check_cmd,
2463 "bgp network import-check",
2464 "BGP specific commands\n"
2465 "BGP network command\n"
2466 "Check BGP network route exists in IGP\n")
2467 {
2468 VTY_DECLVAR_CONTEXT(bgp, bgp);
2469 if (!bgp_flag_check(bgp, BGP_FLAG_IMPORT_CHECK)) {
2470 bgp_flag_set(bgp, BGP_FLAG_IMPORT_CHECK);
2471 bgp_static_redo_import_check(bgp);
2472 }
2473
2474 return CMD_SUCCESS;
2475 }
2476
2477 ALIAS_HIDDEN(bgp_network_import_check, bgp_network_import_check_exact_cmd,
2478 "bgp network import-check exact",
2479 "BGP specific commands\n"
2480 "BGP network command\n"
2481 "Check BGP network route exists in IGP\n"
2482 "Match route precisely\n")
2483
2484 DEFUN (no_bgp_network_import_check,
2485 no_bgp_network_import_check_cmd,
2486 "no bgp network import-check",
2487 NO_STR
2488 "BGP specific commands\n"
2489 "BGP network command\n"
2490 "Check BGP network route exists in IGP\n")
2491 {
2492 VTY_DECLVAR_CONTEXT(bgp, bgp);
2493 if (bgp_flag_check(bgp, BGP_FLAG_IMPORT_CHECK)) {
2494 bgp_flag_unset(bgp, BGP_FLAG_IMPORT_CHECK);
2495 bgp_static_redo_import_check(bgp);
2496 }
2497
2498 return CMD_SUCCESS;
2499 }
2500
2501 DEFUN (bgp_default_local_preference,
2502 bgp_default_local_preference_cmd,
2503 "bgp default local-preference (0-4294967295)",
2504 "BGP specific commands\n"
2505 "Configure BGP defaults\n"
2506 "local preference (higher=more preferred)\n"
2507 "Configure default local preference value\n")
2508 {
2509 VTY_DECLVAR_CONTEXT(bgp, bgp);
2510 int idx_number = 3;
2511 uint32_t local_pref;
2512
2513 local_pref = strtoul(argv[idx_number]->arg, NULL, 10);
2514
2515 bgp_default_local_preference_set(bgp, local_pref);
2516 bgp_clear_star_soft_in(vty, bgp->name);
2517
2518 return CMD_SUCCESS;
2519 }
2520
2521 DEFUN (no_bgp_default_local_preference,
2522 no_bgp_default_local_preference_cmd,
2523 "no bgp default local-preference [(0-4294967295)]",
2524 NO_STR
2525 "BGP specific commands\n"
2526 "Configure BGP defaults\n"
2527 "local preference (higher=more preferred)\n"
2528 "Configure default local preference value\n")
2529 {
2530 VTY_DECLVAR_CONTEXT(bgp, bgp);
2531 bgp_default_local_preference_unset(bgp);
2532 bgp_clear_star_soft_in(vty, bgp->name);
2533
2534 return CMD_SUCCESS;
2535 }
2536
2537
2538 DEFUN (bgp_default_subgroup_pkt_queue_max,
2539 bgp_default_subgroup_pkt_queue_max_cmd,
2540 "bgp default subgroup-pkt-queue-max (20-100)",
2541 "BGP specific commands\n"
2542 "Configure BGP defaults\n"
2543 "subgroup-pkt-queue-max\n"
2544 "Configure subgroup packet queue max\n")
2545 {
2546 VTY_DECLVAR_CONTEXT(bgp, bgp);
2547 int idx_number = 3;
2548 uint32_t max_size;
2549
2550 max_size = strtoul(argv[idx_number]->arg, NULL, 10);
2551
2552 bgp_default_subgroup_pkt_queue_max_set(bgp, max_size);
2553
2554 return CMD_SUCCESS;
2555 }
2556
2557 DEFUN (no_bgp_default_subgroup_pkt_queue_max,
2558 no_bgp_default_subgroup_pkt_queue_max_cmd,
2559 "no bgp default subgroup-pkt-queue-max [(20-100)]",
2560 NO_STR
2561 "BGP specific commands\n"
2562 "Configure BGP defaults\n"
2563 "subgroup-pkt-queue-max\n"
2564 "Configure subgroup packet queue max\n")
2565 {
2566 VTY_DECLVAR_CONTEXT(bgp, bgp);
2567 bgp_default_subgroup_pkt_queue_max_unset(bgp);
2568 return CMD_SUCCESS;
2569 }
2570
2571
2572 DEFUN (bgp_rr_allow_outbound_policy,
2573 bgp_rr_allow_outbound_policy_cmd,
2574 "bgp route-reflector allow-outbound-policy",
2575 "BGP specific commands\n"
2576 "Allow modifications made by out route-map\n"
2577 "on ibgp neighbors\n")
2578 {
2579 VTY_DECLVAR_CONTEXT(bgp, bgp);
2580
2581 if (!bgp_flag_check(bgp, BGP_FLAG_RR_ALLOW_OUTBOUND_POLICY)) {
2582 bgp_flag_set(bgp, BGP_FLAG_RR_ALLOW_OUTBOUND_POLICY);
2583 update_group_announce_rrclients(bgp);
2584 bgp_clear_star_soft_out(vty, bgp->name);
2585 }
2586
2587 return CMD_SUCCESS;
2588 }
2589
2590 DEFUN (no_bgp_rr_allow_outbound_policy,
2591 no_bgp_rr_allow_outbound_policy_cmd,
2592 "no bgp route-reflector allow-outbound-policy",
2593 NO_STR
2594 "BGP specific commands\n"
2595 "Allow modifications made by out route-map\n"
2596 "on ibgp neighbors\n")
2597 {
2598 VTY_DECLVAR_CONTEXT(bgp, bgp);
2599
2600 if (bgp_flag_check(bgp, BGP_FLAG_RR_ALLOW_OUTBOUND_POLICY)) {
2601 bgp_flag_unset(bgp, BGP_FLAG_RR_ALLOW_OUTBOUND_POLICY);
2602 update_group_announce_rrclients(bgp);
2603 bgp_clear_star_soft_out(vty, bgp->name);
2604 }
2605
2606 return CMD_SUCCESS;
2607 }
2608
2609 DEFUN (bgp_listen_limit,
2610 bgp_listen_limit_cmd,
2611 "bgp listen limit (1-5000)",
2612 "BGP specific commands\n"
2613 "Configure BGP defaults\n"
2614 "maximum number of BGP Dynamic Neighbors that can be created\n"
2615 "Configure Dynamic Neighbors listen limit value\n")
2616 {
2617 VTY_DECLVAR_CONTEXT(bgp, bgp);
2618 int idx_number = 3;
2619 int listen_limit;
2620
2621 listen_limit = strtoul(argv[idx_number]->arg, NULL, 10);
2622
2623 bgp_listen_limit_set(bgp, listen_limit);
2624
2625 return CMD_SUCCESS;
2626 }
2627
2628 DEFUN (no_bgp_listen_limit,
2629 no_bgp_listen_limit_cmd,
2630 "no bgp listen limit [(1-5000)]",
2631 "BGP specific commands\n"
2632 "Configure BGP defaults\n"
2633 "unset maximum number of BGP Dynamic Neighbors that can be created\n"
2634 "Configure Dynamic Neighbors listen limit value to default\n"
2635 "Configure Dynamic Neighbors listen limit value\n")
2636 {
2637 VTY_DECLVAR_CONTEXT(bgp, bgp);
2638 bgp_listen_limit_unset(bgp);
2639 return CMD_SUCCESS;
2640 }
2641
2642
2643 /*
2644 * Check if this listen range is already configured. Check for exact
2645 * match or overlap based on input.
2646 */
2647 static struct peer_group *listen_range_exists(struct bgp *bgp,
2648 struct prefix *range, int exact)
2649 {
2650 struct listnode *node, *nnode;
2651 struct listnode *node1, *nnode1;
2652 struct peer_group *group;
2653 struct prefix *lr;
2654 afi_t afi;
2655 int match;
2656
2657 afi = family2afi(range->family);
2658 for (ALL_LIST_ELEMENTS(bgp->group, node, nnode, group)) {
2659 for (ALL_LIST_ELEMENTS(group->listen_range[afi], node1, nnode1,
2660 lr)) {
2661 if (exact)
2662 match = prefix_same(range, lr);
2663 else
2664 match = (prefix_match(range, lr)
2665 || prefix_match(lr, range));
2666 if (match)
2667 return group;
2668 }
2669 }
2670
2671 return NULL;
2672 }
2673
2674 DEFUN (bgp_listen_range,
2675 bgp_listen_range_cmd,
2676 "bgp listen range <A.B.C.D/M|X:X::X:X/M> peer-group PGNAME",
2677 "BGP specific commands\n"
2678 "Configure BGP dynamic neighbors listen range\n"
2679 "Configure BGP dynamic neighbors listen range\n"
2680 NEIGHBOR_ADDR_STR
2681 "Member of the peer-group\n"
2682 "Peer-group name\n")
2683 {
2684 VTY_DECLVAR_CONTEXT(bgp, bgp);
2685 struct prefix range;
2686 struct peer_group *group, *existing_group;
2687 afi_t afi;
2688 int ret;
2689 int idx = 0;
2690
2691 argv_find(argv, argc, "A.B.C.D/M", &idx);
2692 argv_find(argv, argc, "X:X::X:X/M", &idx);
2693 char *prefix = argv[idx]->arg;
2694 argv_find(argv, argc, "PGNAME", &idx);
2695 char *peergroup = argv[idx]->arg;
2696
2697 /* Convert IP prefix string to struct prefix. */
2698 ret = str2prefix(prefix, &range);
2699 if (!ret) {
2700 vty_out(vty, "%% Malformed listen range\n");
2701 return CMD_WARNING_CONFIG_FAILED;
2702 }
2703
2704 afi = family2afi(range.family);
2705
2706 if (afi == AFI_IP6 && IN6_IS_ADDR_LINKLOCAL(&range.u.prefix6)) {
2707 vty_out(vty,
2708 "%% Malformed listen range (link-local address)\n");
2709 return CMD_WARNING_CONFIG_FAILED;
2710 }
2711
2712 apply_mask(&range);
2713
2714 /* Check if same listen range is already configured. */
2715 existing_group = listen_range_exists(bgp, &range, 1);
2716 if (existing_group) {
2717 if (strcmp(existing_group->name, peergroup) == 0)
2718 return CMD_SUCCESS;
2719 else {
2720 vty_out(vty,
2721 "%% Same listen range is attached to peer-group %s\n",
2722 existing_group->name);
2723 return CMD_WARNING_CONFIG_FAILED;
2724 }
2725 }
2726
2727 /* Check if an overlapping listen range exists. */
2728 if (listen_range_exists(bgp, &range, 0)) {
2729 vty_out(vty,
2730 "%% Listen range overlaps with existing listen range\n");
2731 return CMD_WARNING_CONFIG_FAILED;
2732 }
2733
2734 group = peer_group_lookup(bgp, peergroup);
2735 if (!group) {
2736 vty_out(vty, "%% Configure the peer-group first\n");
2737 return CMD_WARNING_CONFIG_FAILED;
2738 }
2739
2740 ret = peer_group_listen_range_add(group, &range);
2741 return bgp_vty_return(vty, ret);
2742 }
2743
2744 DEFUN (no_bgp_listen_range,
2745 no_bgp_listen_range_cmd,
2746 "no bgp listen range <A.B.C.D/M|X:X::X:X/M> peer-group PGNAME",
2747 NO_STR
2748 "BGP specific commands\n"
2749 "Unconfigure BGP dynamic neighbors listen range\n"
2750 "Unconfigure BGP dynamic neighbors listen range\n"
2751 NEIGHBOR_ADDR_STR
2752 "Member of the peer-group\n"
2753 "Peer-group name\n")
2754 {
2755 VTY_DECLVAR_CONTEXT(bgp, bgp);
2756 struct prefix range;
2757 struct peer_group *group;
2758 afi_t afi;
2759 int ret;
2760 int idx = 0;
2761
2762 argv_find(argv, argc, "A.B.C.D/M", &idx);
2763 argv_find(argv, argc, "X:X::X:X/M", &idx);
2764 char *prefix = argv[idx]->arg;
2765 argv_find(argv, argc, "WORD", &idx);
2766 char *peergroup = argv[idx]->arg;
2767
2768 /* Convert IP prefix string to struct prefix. */
2769 ret = str2prefix(prefix, &range);
2770 if (!ret) {
2771 vty_out(vty, "%% Malformed listen range\n");
2772 return CMD_WARNING_CONFIG_FAILED;
2773 }
2774
2775 afi = family2afi(range.family);
2776
2777 if (afi == AFI_IP6 && IN6_IS_ADDR_LINKLOCAL(&range.u.prefix6)) {
2778 vty_out(vty,
2779 "%% Malformed listen range (link-local address)\n");
2780 return CMD_WARNING_CONFIG_FAILED;
2781 }
2782
2783 apply_mask(&range);
2784
2785 group = peer_group_lookup(bgp, peergroup);
2786 if (!group) {
2787 vty_out(vty, "%% Peer-group does not exist\n");
2788 return CMD_WARNING_CONFIG_FAILED;
2789 }
2790
2791 ret = peer_group_listen_range_del(group, &range);
2792 return bgp_vty_return(vty, ret);
2793 }
2794
2795 void bgp_config_write_listen(struct vty *vty, struct bgp *bgp)
2796 {
2797 struct peer_group *group;
2798 struct listnode *node, *nnode, *rnode, *nrnode;
2799 struct prefix *range;
2800 afi_t afi;
2801 char buf[PREFIX2STR_BUFFER];
2802
2803 if (bgp->dynamic_neighbors_limit != BGP_DYNAMIC_NEIGHBORS_LIMIT_DEFAULT)
2804 vty_out(vty, " bgp listen limit %d\n",
2805 bgp->dynamic_neighbors_limit);
2806
2807 for (ALL_LIST_ELEMENTS(bgp->group, node, nnode, group)) {
2808 for (afi = AFI_IP; afi < AFI_MAX; afi++) {
2809 for (ALL_LIST_ELEMENTS(group->listen_range[afi], rnode,
2810 nrnode, range)) {
2811 prefix2str(range, buf, sizeof(buf));
2812 vty_out(vty,
2813 " bgp listen range %s peer-group %s\n",
2814 buf, group->name);
2815 }
2816 }
2817 }
2818 }
2819
2820
2821 DEFUN (bgp_disable_connected_route_check,
2822 bgp_disable_connected_route_check_cmd,
2823 "bgp disable-ebgp-connected-route-check",
2824 "BGP specific commands\n"
2825 "Disable checking if nexthop is connected on ebgp sessions\n")
2826 {
2827 VTY_DECLVAR_CONTEXT(bgp, bgp);
2828 bgp_flag_set(bgp, BGP_FLAG_DISABLE_NH_CONNECTED_CHK);
2829 bgp_clear_star_soft_in(vty, bgp->name);
2830
2831 return CMD_SUCCESS;
2832 }
2833
2834 DEFUN (no_bgp_disable_connected_route_check,
2835 no_bgp_disable_connected_route_check_cmd,
2836 "no bgp disable-ebgp-connected-route-check",
2837 NO_STR
2838 "BGP specific commands\n"
2839 "Disable checking if nexthop is connected on ebgp sessions\n")
2840 {
2841 VTY_DECLVAR_CONTEXT(bgp, bgp);
2842 bgp_flag_unset(bgp, BGP_FLAG_DISABLE_NH_CONNECTED_CHK);
2843 bgp_clear_star_soft_in(vty, bgp->name);
2844
2845 return CMD_SUCCESS;
2846 }
2847
2848
2849 static int peer_remote_as_vty(struct vty *vty, const char *peer_str,
2850 const char *as_str, afi_t afi, safi_t safi)
2851 {
2852 VTY_DECLVAR_CONTEXT(bgp, bgp);
2853 int ret;
2854 as_t as;
2855 int as_type = AS_SPECIFIED;
2856 union sockunion su;
2857
2858 if (as_str[0] == 'i') {
2859 as = 0;
2860 as_type = AS_INTERNAL;
2861 } else if (as_str[0] == 'e') {
2862 as = 0;
2863 as_type = AS_EXTERNAL;
2864 } else {
2865 /* Get AS number. */
2866 as = strtoul(as_str, NULL, 10);
2867 }
2868
2869 /* If peer is peer group or interface peer, call proper function. */
2870 ret = str2sockunion(peer_str, &su);
2871 if (ret < 0) {
2872 struct peer *peer;
2873
2874 /* Check if existing interface peer */
2875 peer = peer_lookup_by_conf_if(bgp, peer_str);
2876
2877 ret = peer_remote_as(bgp, NULL, peer_str, &as, as_type, afi,
2878 safi);
2879
2880 /* if not interface peer, check peer-group settings */
2881 if (ret < 0 && !peer) {
2882 ret = peer_group_remote_as(bgp, peer_str, &as, as_type);
2883 if (ret < 0) {
2884 vty_out(vty,
2885 "%% Create the peer-group or interface first\n");
2886 return CMD_WARNING_CONFIG_FAILED;
2887 }
2888 return CMD_SUCCESS;
2889 }
2890 } else {
2891 if (peer_address_self_check(bgp, &su)) {
2892 vty_out(vty,
2893 "%% Can not configure the local system as neighbor\n");
2894 return CMD_WARNING_CONFIG_FAILED;
2895 }
2896 ret = peer_remote_as(bgp, &su, NULL, &as, as_type, afi, safi);
2897 }
2898
2899 /* This peer belongs to peer group. */
2900 switch (ret) {
2901 case BGP_ERR_PEER_GROUP_MEMBER:
2902 vty_out(vty,
2903 "%% Peer-group member cannot override remote-as of peer-group\n");
2904 return CMD_WARNING_CONFIG_FAILED;
2905 case BGP_ERR_PEER_GROUP_PEER_TYPE_DIFFERENT:
2906 vty_out(vty,
2907 "%% Peer-group members must be all internal or all external\n");
2908 return CMD_WARNING_CONFIG_FAILED;
2909 }
2910 return bgp_vty_return(vty, ret);
2911 }
2912
2913 DEFUN (bgp_default_shutdown,
2914 bgp_default_shutdown_cmd,
2915 "[no] bgp default shutdown",
2916 NO_STR
2917 BGP_STR
2918 "Configure BGP defaults\n"
2919 "Apply administrative shutdown to newly configured peers\n")
2920 {
2921 VTY_DECLVAR_CONTEXT(bgp, bgp);
2922 bgp->autoshutdown = !strmatch(argv[0]->text, "no");
2923 return CMD_SUCCESS;
2924 }
2925
2926 DEFUN (neighbor_remote_as,
2927 neighbor_remote_as_cmd,
2928 "neighbor <A.B.C.D|X:X::X:X|WORD> remote-as <(1-4294967295)|internal|external>",
2929 NEIGHBOR_STR
2930 NEIGHBOR_ADDR_STR2
2931 "Specify a BGP neighbor\n"
2932 AS_STR
2933 "Internal BGP peer\n"
2934 "External BGP peer\n")
2935 {
2936 int idx_peer = 1;
2937 int idx_remote_as = 3;
2938 return peer_remote_as_vty(vty, argv[idx_peer]->arg,
2939 argv[idx_remote_as]->arg, AFI_IP,
2940 SAFI_UNICAST);
2941 }
2942
2943 static int peer_conf_interface_get(struct vty *vty, const char *conf_if,
2944 afi_t afi, safi_t safi, int v6only,
2945 const char *peer_group_name,
2946 const char *as_str)
2947 {
2948 VTY_DECLVAR_CONTEXT(bgp, bgp);
2949 as_t as = 0;
2950 int as_type = AS_UNSPECIFIED;
2951 struct peer *peer;
2952 struct peer_group *group;
2953 int ret = 0;
2954 union sockunion su;
2955
2956 group = peer_group_lookup(bgp, conf_if);
2957
2958 if (group) {
2959 vty_out(vty, "%% Name conflict with peer-group \n");
2960 return CMD_WARNING_CONFIG_FAILED;
2961 }
2962
2963 if (as_str) {
2964 if (as_str[0] == 'i') {
2965 as_type = AS_INTERNAL;
2966 } else if (as_str[0] == 'e') {
2967 as_type = AS_EXTERNAL;
2968 } else {
2969 /* Get AS number. */
2970 as = strtoul(as_str, NULL, 10);
2971 as_type = AS_SPECIFIED;
2972 }
2973 }
2974
2975 peer = peer_lookup_by_conf_if(bgp, conf_if);
2976 if (peer) {
2977 if (as_str)
2978 ret = peer_remote_as(bgp, NULL, conf_if, &as, as_type,
2979 afi, safi);
2980 } else {
2981 if (bgp_flag_check(bgp, BGP_FLAG_NO_DEFAULT_IPV4)
2982 && afi == AFI_IP && safi == SAFI_UNICAST)
2983 peer = peer_create(NULL, conf_if, bgp, bgp->as, as,
2984 as_type, 0, 0, NULL);
2985 else
2986 peer = peer_create(NULL, conf_if, bgp, bgp->as, as,
2987 as_type, afi, safi, NULL);
2988
2989 if (!peer) {
2990 vty_out(vty, "%% BGP failed to create peer\n");
2991 return CMD_WARNING_CONFIG_FAILED;
2992 }
2993
2994 if (v6only)
2995 peer_flag_set(peer, PEER_FLAG_IFPEER_V6ONLY);
2996
2997 /* Request zebra to initiate IPv6 RAs on this interface. We do
2998 * this
2999 * any unnumbered peer in order to not worry about run-time
3000 * transitions
3001 * (e.g., peering is initially IPv4, but the IPv4 /30 or /31
3002 * address
3003 * gets deleted later etc.)
3004 */
3005 if (peer->ifp)
3006 bgp_zebra_initiate_radv(bgp, peer);
3007 }
3008
3009 if ((v6only && !CHECK_FLAG(peer->flags, PEER_FLAG_IFPEER_V6ONLY))
3010 || (!v6only && CHECK_FLAG(peer->flags, PEER_FLAG_IFPEER_V6ONLY))) {
3011 if (v6only)
3012 peer_flag_set(peer, PEER_FLAG_IFPEER_V6ONLY);
3013 else
3014 peer_flag_unset(peer, PEER_FLAG_IFPEER_V6ONLY);
3015
3016 /* v6only flag changed. Reset bgp seesion */
3017 if (BGP_IS_VALID_STATE_FOR_NOTIF(peer->status)) {
3018 peer->last_reset = PEER_DOWN_V6ONLY_CHANGE;
3019 bgp_notify_send(peer, BGP_NOTIFY_CEASE,
3020 BGP_NOTIFY_CEASE_CONFIG_CHANGE);
3021 } else
3022 bgp_session_reset(peer);
3023 }
3024
3025 if (!CHECK_FLAG(peer->flags_invert, PEER_FLAG_CAPABILITY_ENHE)) {
3026 SET_FLAG(peer->flags, PEER_FLAG_CAPABILITY_ENHE);
3027 SET_FLAG(peer->flags_invert, PEER_FLAG_CAPABILITY_ENHE);
3028 SET_FLAG(peer->flags_override, PEER_FLAG_CAPABILITY_ENHE);
3029 }
3030
3031 if (peer_group_name) {
3032 group = peer_group_lookup(bgp, peer_group_name);
3033 if (!group) {
3034 vty_out(vty, "%% Configure the peer-group first\n");
3035 return CMD_WARNING_CONFIG_FAILED;
3036 }
3037
3038 ret = peer_group_bind(bgp, &su, peer, group, &as);
3039 }
3040
3041 return bgp_vty_return(vty, ret);
3042 }
3043
3044 DEFUN (neighbor_interface_config,
3045 neighbor_interface_config_cmd,
3046 "neighbor WORD interface [peer-group PGNAME]",
3047 NEIGHBOR_STR
3048 "Interface name or neighbor tag\n"
3049 "Enable BGP on interface\n"
3050 "Member of the peer-group\n"
3051 "Peer-group name\n")
3052 {
3053 int idx_word = 1;
3054 int idx_peer_group_word = 4;
3055
3056 if (argc > idx_peer_group_word)
3057 return peer_conf_interface_get(
3058 vty, argv[idx_word]->arg, AFI_IP, SAFI_UNICAST, 0,
3059 argv[idx_peer_group_word]->arg, NULL);
3060 else
3061 return peer_conf_interface_get(vty, argv[idx_word]->arg, AFI_IP,
3062 SAFI_UNICAST, 0, NULL, NULL);
3063 }
3064
3065 DEFUN (neighbor_interface_config_v6only,
3066 neighbor_interface_config_v6only_cmd,
3067 "neighbor WORD interface v6only [peer-group PGNAME]",
3068 NEIGHBOR_STR
3069 "Interface name or neighbor tag\n"
3070 "Enable BGP on interface\n"
3071 "Enable BGP with v6 link-local only\n"
3072 "Member of the peer-group\n"
3073 "Peer-group name\n")
3074 {
3075 int idx_word = 1;
3076 int idx_peer_group_word = 5;
3077
3078 if (argc > idx_peer_group_word)
3079 return peer_conf_interface_get(
3080 vty, argv[idx_word]->arg, AFI_IP, SAFI_UNICAST, 1,
3081 argv[idx_peer_group_word]->arg, NULL);
3082
3083 return peer_conf_interface_get(vty, argv[idx_word]->arg, AFI_IP,
3084 SAFI_UNICAST, 1, NULL, NULL);
3085 }
3086
3087
3088 DEFUN (neighbor_interface_config_remote_as,
3089 neighbor_interface_config_remote_as_cmd,
3090 "neighbor WORD interface remote-as <(1-4294967295)|internal|external>",
3091 NEIGHBOR_STR
3092 "Interface name or neighbor tag\n"
3093 "Enable BGP on interface\n"
3094 "Specify a BGP neighbor\n"
3095 AS_STR
3096 "Internal BGP peer\n"
3097 "External BGP peer\n")
3098 {
3099 int idx_word = 1;
3100 int idx_remote_as = 4;
3101 return peer_conf_interface_get(vty, argv[idx_word]->arg, AFI_IP,
3102 SAFI_UNICAST, 0, NULL,
3103 argv[idx_remote_as]->arg);
3104 }
3105
3106 DEFUN (neighbor_interface_v6only_config_remote_as,
3107 neighbor_interface_v6only_config_remote_as_cmd,
3108 "neighbor WORD interface v6only remote-as <(1-4294967295)|internal|external>",
3109 NEIGHBOR_STR
3110 "Interface name or neighbor tag\n"
3111 "Enable BGP with v6 link-local only\n"
3112 "Enable BGP on interface\n"
3113 "Specify a BGP neighbor\n"
3114 AS_STR
3115 "Internal BGP peer\n"
3116 "External BGP peer\n")
3117 {
3118 int idx_word = 1;
3119 int idx_remote_as = 5;
3120 return peer_conf_interface_get(vty, argv[idx_word]->arg, AFI_IP,
3121 SAFI_UNICAST, 1, NULL,
3122 argv[idx_remote_as]->arg);
3123 }
3124
3125 DEFUN (neighbor_peer_group,
3126 neighbor_peer_group_cmd,
3127 "neighbor WORD peer-group",
3128 NEIGHBOR_STR
3129 "Interface name or neighbor tag\n"
3130 "Configure peer-group\n")
3131 {
3132 VTY_DECLVAR_CONTEXT(bgp, bgp);
3133 int idx_word = 1;
3134 struct peer *peer;
3135 struct peer_group *group;
3136
3137 peer = peer_lookup_by_conf_if(bgp, argv[idx_word]->arg);
3138 if (peer) {
3139 vty_out(vty, "%% Name conflict with interface: \n");
3140 return CMD_WARNING_CONFIG_FAILED;
3141 }
3142
3143 group = peer_group_get(bgp, argv[idx_word]->arg);
3144 if (!group) {
3145 vty_out(vty, "%% BGP failed to find or create peer-group\n");
3146 return CMD_WARNING_CONFIG_FAILED;
3147 }
3148
3149 return CMD_SUCCESS;
3150 }
3151
3152 DEFUN (no_neighbor,
3153 no_neighbor_cmd,
3154 "no neighbor <WORD|<A.B.C.D|X:X::X:X> [remote-as <(1-4294967295)|internal|external>]>",
3155 NO_STR
3156 NEIGHBOR_STR
3157 NEIGHBOR_ADDR_STR2
3158 "Specify a BGP neighbor\n"
3159 AS_STR
3160 "Internal BGP peer\n"
3161 "External BGP peer\n")
3162 {
3163 VTY_DECLVAR_CONTEXT(bgp, bgp);
3164 int idx_peer = 2;
3165 int ret;
3166 union sockunion su;
3167 struct peer_group *group;
3168 struct peer *peer;
3169 struct peer *other;
3170
3171 ret = str2sockunion(argv[idx_peer]->arg, &su);
3172 if (ret < 0) {
3173 /* look up for neighbor by interface name config. */
3174 peer = peer_lookup_by_conf_if(bgp, argv[idx_peer]->arg);
3175 if (peer) {
3176 /* Request zebra to terminate IPv6 RAs on this
3177 * interface. */
3178 if (peer->ifp)
3179 bgp_zebra_terminate_radv(peer->bgp, peer);
3180 peer_delete(peer);
3181 return CMD_SUCCESS;
3182 }
3183
3184 group = peer_group_lookup(bgp, argv[idx_peer]->arg);
3185 if (group)
3186 peer_group_delete(group);
3187 else {
3188 vty_out(vty, "%% Create the peer-group first\n");
3189 return CMD_WARNING_CONFIG_FAILED;
3190 }
3191 } else {
3192 peer = peer_lookup(bgp, &su);
3193 if (peer) {
3194 if (peer_dynamic_neighbor(peer)) {
3195 vty_out(vty,
3196 "%% Operation not allowed on a dynamic neighbor\n");
3197 return CMD_WARNING_CONFIG_FAILED;
3198 }
3199
3200 other = peer->doppelganger;
3201 peer_delete(peer);
3202 if (other && other->status != Deleted)
3203 peer_delete(other);
3204 }
3205 }
3206
3207 return CMD_SUCCESS;
3208 }
3209
3210 DEFUN (no_neighbor_interface_config,
3211 no_neighbor_interface_config_cmd,
3212 "no neighbor WORD interface [v6only] [peer-group PGNAME] [remote-as <(1-4294967295)|internal|external>]",
3213 NO_STR
3214 NEIGHBOR_STR
3215 "Interface name\n"
3216 "Configure BGP on interface\n"
3217 "Enable BGP with v6 link-local only\n"
3218 "Member of the peer-group\n"
3219 "Peer-group name\n"
3220 "Specify a BGP neighbor\n"
3221 AS_STR
3222 "Internal BGP peer\n"
3223 "External BGP peer\n")
3224 {
3225 VTY_DECLVAR_CONTEXT(bgp, bgp);
3226 int idx_word = 2;
3227 struct peer *peer;
3228
3229 /* look up for neighbor by interface name config. */
3230 peer = peer_lookup_by_conf_if(bgp, argv[idx_word]->arg);
3231 if (peer) {
3232 /* Request zebra to terminate IPv6 RAs on this interface. */
3233 if (peer->ifp)
3234 bgp_zebra_terminate_radv(peer->bgp, peer);
3235 peer_delete(peer);
3236 } else {
3237 vty_out(vty, "%% Create the bgp interface first\n");
3238 return CMD_WARNING_CONFIG_FAILED;
3239 }
3240 return CMD_SUCCESS;
3241 }
3242
3243 DEFUN (no_neighbor_peer_group,
3244 no_neighbor_peer_group_cmd,
3245 "no neighbor WORD peer-group",
3246 NO_STR
3247 NEIGHBOR_STR
3248 "Neighbor tag\n"
3249 "Configure peer-group\n")
3250 {
3251 VTY_DECLVAR_CONTEXT(bgp, bgp);
3252 int idx_word = 2;
3253 struct peer_group *group;
3254
3255 group = peer_group_lookup(bgp, argv[idx_word]->arg);
3256 if (group)
3257 peer_group_delete(group);
3258 else {
3259 vty_out(vty, "%% Create the peer-group first\n");
3260 return CMD_WARNING_CONFIG_FAILED;
3261 }
3262 return CMD_SUCCESS;
3263 }
3264
3265 DEFUN (no_neighbor_interface_peer_group_remote_as,
3266 no_neighbor_interface_peer_group_remote_as_cmd,
3267 "no neighbor WORD remote-as <(1-4294967295)|internal|external>",
3268 NO_STR
3269 NEIGHBOR_STR
3270 "Interface name or neighbor tag\n"
3271 "Specify a BGP neighbor\n"
3272 AS_STR
3273 "Internal BGP peer\n"
3274 "External BGP peer\n")
3275 {
3276 VTY_DECLVAR_CONTEXT(bgp, bgp);
3277 int idx_word = 2;
3278 struct peer_group *group;
3279 struct peer *peer;
3280
3281 /* look up for neighbor by interface name config. */
3282 peer = peer_lookup_by_conf_if(bgp, argv[idx_word]->arg);
3283 if (peer) {
3284 peer_as_change(peer, 0, AS_UNSPECIFIED);
3285 return CMD_SUCCESS;
3286 }
3287
3288 group = peer_group_lookup(bgp, argv[idx_word]->arg);
3289 if (group)
3290 peer_group_remote_as_delete(group);
3291 else {
3292 vty_out(vty, "%% Create the peer-group or interface first\n");
3293 return CMD_WARNING_CONFIG_FAILED;
3294 }
3295 return CMD_SUCCESS;
3296 }
3297
3298 DEFUN (neighbor_local_as,
3299 neighbor_local_as_cmd,
3300 "neighbor <A.B.C.D|X:X::X:X|WORD> local-as (1-4294967295)",
3301 NEIGHBOR_STR
3302 NEIGHBOR_ADDR_STR2
3303 "Specify a local-as number\n"
3304 "AS number used as local AS\n")
3305 {
3306 int idx_peer = 1;
3307 int idx_number = 3;
3308 struct peer *peer;
3309 int ret;
3310 as_t as;
3311
3312 peer = peer_and_group_lookup_vty(vty, argv[idx_peer]->arg);
3313 if (!peer)
3314 return CMD_WARNING_CONFIG_FAILED;
3315
3316 as = strtoul(argv[idx_number]->arg, NULL, 10);
3317 ret = peer_local_as_set(peer, as, 0, 0);
3318 return bgp_vty_return(vty, ret);
3319 }
3320
3321 DEFUN (neighbor_local_as_no_prepend,
3322 neighbor_local_as_no_prepend_cmd,
3323 "neighbor <A.B.C.D|X:X::X:X|WORD> local-as (1-4294967295) no-prepend",
3324 NEIGHBOR_STR
3325 NEIGHBOR_ADDR_STR2
3326 "Specify a local-as number\n"
3327 "AS number used as local AS\n"
3328 "Do not prepend local-as to updates from ebgp peers\n")
3329 {
3330 int idx_peer = 1;
3331 int idx_number = 3;
3332 struct peer *peer;
3333 int ret;
3334 as_t as;
3335
3336 peer = peer_and_group_lookup_vty(vty, argv[idx_peer]->arg);
3337 if (!peer)
3338 return CMD_WARNING_CONFIG_FAILED;
3339
3340 as = strtoul(argv[idx_number]->arg, NULL, 10);
3341 ret = peer_local_as_set(peer, as, 1, 0);
3342 return bgp_vty_return(vty, ret);
3343 }
3344
3345 DEFUN (neighbor_local_as_no_prepend_replace_as,
3346 neighbor_local_as_no_prepend_replace_as_cmd,
3347 "neighbor <A.B.C.D|X:X::X:X|WORD> local-as (1-4294967295) no-prepend replace-as",
3348 NEIGHBOR_STR
3349 NEIGHBOR_ADDR_STR2
3350 "Specify a local-as number\n"
3351 "AS number used as local AS\n"
3352 "Do not prepend local-as to updates from ebgp peers\n"
3353 "Do not prepend local-as to updates from ibgp peers\n")
3354 {
3355 int idx_peer = 1;
3356 int idx_number = 3;
3357 struct peer *peer;
3358 int ret;
3359 as_t as;
3360
3361 peer = peer_and_group_lookup_vty(vty, argv[idx_peer]->arg);
3362 if (!peer)
3363 return CMD_WARNING_CONFIG_FAILED;
3364
3365 as = strtoul(argv[idx_number]->arg, NULL, 10);
3366 ret = peer_local_as_set(peer, as, 1, 1);
3367 return bgp_vty_return(vty, ret);
3368 }
3369
3370 DEFUN (no_neighbor_local_as,
3371 no_neighbor_local_as_cmd,
3372 "no neighbor <A.B.C.D|X:X::X:X|WORD> local-as [(1-4294967295) [no-prepend [replace-as]]]",
3373 NO_STR
3374 NEIGHBOR_STR
3375 NEIGHBOR_ADDR_STR2
3376 "Specify a local-as number\n"
3377 "AS number used as local AS\n"
3378 "Do not prepend local-as to updates from ebgp peers\n"
3379 "Do not prepend local-as to updates from ibgp peers\n")
3380 {
3381 int idx_peer = 2;
3382 struct peer *peer;
3383 int ret;
3384
3385 peer = peer_and_group_lookup_vty(vty, argv[idx_peer]->arg);
3386 if (!peer)
3387 return CMD_WARNING_CONFIG_FAILED;
3388
3389 ret = peer_local_as_unset(peer);
3390 return bgp_vty_return(vty, ret);
3391 }
3392
3393
3394 DEFUN (neighbor_solo,
3395 neighbor_solo_cmd,
3396 "neighbor <A.B.C.D|X:X::X:X|WORD> solo",
3397 NEIGHBOR_STR
3398 NEIGHBOR_ADDR_STR2
3399 "Solo peer - part of its own update group\n")
3400 {
3401 int idx_peer = 1;
3402 struct peer *peer;
3403 int ret;
3404
3405 peer = peer_and_group_lookup_vty(vty, argv[idx_peer]->arg);
3406 if (!peer)
3407 return CMD_WARNING_CONFIG_FAILED;
3408
3409 ret = update_group_adjust_soloness(peer, 1);
3410 return bgp_vty_return(vty, ret);
3411 }
3412
3413 DEFUN (no_neighbor_solo,
3414 no_neighbor_solo_cmd,
3415 "no neighbor <A.B.C.D|X:X::X:X|WORD> solo",
3416 NO_STR
3417 NEIGHBOR_STR
3418 NEIGHBOR_ADDR_STR2
3419 "Solo peer - part of its own update group\n")
3420 {
3421 int idx_peer = 2;
3422 struct peer *peer;
3423 int ret;
3424
3425 peer = peer_and_group_lookup_vty(vty, argv[idx_peer]->arg);
3426 if (!peer)
3427 return CMD_WARNING_CONFIG_FAILED;
3428
3429 ret = update_group_adjust_soloness(peer, 0);
3430 return bgp_vty_return(vty, ret);
3431 }
3432
3433 DEFUN (neighbor_password,
3434 neighbor_password_cmd,
3435 "neighbor <A.B.C.D|X:X::X:X|WORD> password LINE",
3436 NEIGHBOR_STR
3437 NEIGHBOR_ADDR_STR2
3438 "Set a password\n"
3439 "The password\n")
3440 {
3441 int idx_peer = 1;
3442 int idx_line = 3;
3443 struct peer *peer;
3444 int ret;
3445
3446 peer = peer_and_group_lookup_vty(vty, argv[idx_peer]->arg);
3447 if (!peer)
3448 return CMD_WARNING_CONFIG_FAILED;
3449
3450 ret = peer_password_set(peer, argv[idx_line]->arg);
3451 return bgp_vty_return(vty, ret);
3452 }
3453
3454 DEFUN (no_neighbor_password,
3455 no_neighbor_password_cmd,
3456 "no neighbor <A.B.C.D|X:X::X:X|WORD> password [LINE]",
3457 NO_STR
3458 NEIGHBOR_STR
3459 NEIGHBOR_ADDR_STR2
3460 "Set a password\n"
3461 "The password\n")
3462 {
3463 int idx_peer = 2;
3464 struct peer *peer;
3465 int ret;
3466
3467 peer = peer_and_group_lookup_vty(vty, argv[idx_peer]->arg);
3468 if (!peer)
3469 return CMD_WARNING_CONFIG_FAILED;
3470
3471 ret = peer_password_unset(peer);
3472 return bgp_vty_return(vty, ret);
3473 }
3474
3475 DEFUN (neighbor_activate,
3476 neighbor_activate_cmd,
3477 "neighbor <A.B.C.D|X:X::X:X|WORD> activate",
3478 NEIGHBOR_STR
3479 NEIGHBOR_ADDR_STR2
3480 "Enable the Address Family for this Neighbor\n")
3481 {
3482 int idx_peer = 1;
3483 int ret;
3484 struct peer *peer;
3485
3486 peer = peer_and_group_lookup_vty(vty, argv[idx_peer]->arg);
3487 if (!peer)
3488 return CMD_WARNING_CONFIG_FAILED;
3489
3490 ret = peer_activate(peer, bgp_node_afi(vty), bgp_node_safi(vty));
3491 return bgp_vty_return(vty, ret);
3492 }
3493
3494 ALIAS_HIDDEN(neighbor_activate, neighbor_activate_hidden_cmd,
3495 "neighbor <A.B.C.D|X:X::X:X|WORD> activate",
3496 NEIGHBOR_STR NEIGHBOR_ADDR_STR2
3497 "Enable the Address Family for this Neighbor\n")
3498
3499 DEFUN (no_neighbor_activate,
3500 no_neighbor_activate_cmd,
3501 "no neighbor <A.B.C.D|X:X::X:X|WORD> activate",
3502 NO_STR
3503 NEIGHBOR_STR
3504 NEIGHBOR_ADDR_STR2
3505 "Enable the Address Family for this Neighbor\n")
3506 {
3507 int idx_peer = 2;
3508 int ret;
3509 struct peer *peer;
3510
3511 /* Lookup peer. */
3512 peer = peer_and_group_lookup_vty(vty, argv[idx_peer]->arg);
3513 if (!peer)
3514 return CMD_WARNING_CONFIG_FAILED;
3515
3516 ret = peer_deactivate(peer, bgp_node_afi(vty), bgp_node_safi(vty));
3517 return bgp_vty_return(vty, ret);
3518 }
3519
3520 ALIAS_HIDDEN(no_neighbor_activate, no_neighbor_activate_hidden_cmd,
3521 "no neighbor <A.B.C.D|X:X::X:X|WORD> activate",
3522 NO_STR NEIGHBOR_STR NEIGHBOR_ADDR_STR2
3523 "Enable the Address Family for this Neighbor\n")
3524
3525 DEFUN (neighbor_set_peer_group,
3526 neighbor_set_peer_group_cmd,
3527 "neighbor <A.B.C.D|X:X::X:X|WORD> peer-group PGNAME",
3528 NEIGHBOR_STR
3529 NEIGHBOR_ADDR_STR2
3530 "Member of the peer-group\n"
3531 "Peer-group name\n")
3532 {
3533 VTY_DECLVAR_CONTEXT(bgp, bgp);
3534 int idx_peer = 1;
3535 int idx_word = 3;
3536 int ret;
3537 as_t as;
3538 union sockunion su;
3539 struct peer *peer;
3540 struct peer_group *group;
3541
3542 ret = str2sockunion(argv[idx_peer]->arg, &su);
3543 if (ret < 0) {
3544 peer = peer_lookup_by_conf_if(bgp, argv[idx_peer]->arg);
3545 if (!peer) {
3546 vty_out(vty, "%% Malformed address or name: %s\n",
3547 argv[idx_peer]->arg);
3548 return CMD_WARNING_CONFIG_FAILED;
3549 }
3550 } else {
3551 if (peer_address_self_check(bgp, &su)) {
3552 vty_out(vty,
3553 "%% Can not configure the local system as neighbor\n");
3554 return CMD_WARNING_CONFIG_FAILED;
3555 }
3556
3557 /* Disallow for dynamic neighbor. */
3558 peer = peer_lookup(bgp, &su);
3559 if (peer && peer_dynamic_neighbor(peer)) {
3560 vty_out(vty,
3561 "%% Operation not allowed on a dynamic neighbor\n");
3562 return CMD_WARNING_CONFIG_FAILED;
3563 }
3564 }
3565
3566 group = peer_group_lookup(bgp, argv[idx_word]->arg);
3567 if (!group) {
3568 vty_out(vty, "%% Configure the peer-group first\n");
3569 return CMD_WARNING_CONFIG_FAILED;
3570 }
3571
3572 ret = peer_group_bind(bgp, &su, peer, group, &as);
3573
3574 if (ret == BGP_ERR_PEER_GROUP_PEER_TYPE_DIFFERENT) {
3575 vty_out(vty,
3576 "%% Peer with AS %u cannot be in this peer-group, members must be all internal or all external\n",
3577 as);
3578 return CMD_WARNING_CONFIG_FAILED;
3579 }
3580
3581 return bgp_vty_return(vty, ret);
3582 }
3583
3584 ALIAS_HIDDEN(neighbor_set_peer_group, neighbor_set_peer_group_hidden_cmd,
3585 "neighbor <A.B.C.D|X:X::X:X|WORD> peer-group PGNAME",
3586 NEIGHBOR_STR NEIGHBOR_ADDR_STR2
3587 "Member of the peer-group\n"
3588 "Peer-group name\n")
3589
3590 DEFUN (no_neighbor_set_peer_group,
3591 no_neighbor_set_peer_group_cmd,
3592 "no neighbor <A.B.C.D|X:X::X:X|WORD> peer-group PGNAME",
3593 NO_STR
3594 NEIGHBOR_STR
3595 NEIGHBOR_ADDR_STR2
3596 "Member of the peer-group\n"
3597 "Peer-group name\n")
3598 {
3599 VTY_DECLVAR_CONTEXT(bgp, bgp);
3600 int idx_peer = 2;
3601 int idx_word = 4;
3602 int ret;
3603 struct peer *peer;
3604 struct peer_group *group;
3605
3606 peer = peer_lookup_vty(vty, argv[idx_peer]->arg);
3607 if (!peer)
3608 return CMD_WARNING_CONFIG_FAILED;
3609
3610 group = peer_group_lookup(bgp, argv[idx_word]->arg);
3611 if (!group) {
3612 vty_out(vty, "%% Configure the peer-group first\n");
3613 return CMD_WARNING_CONFIG_FAILED;
3614 }
3615
3616 ret = peer_delete(peer);
3617
3618 return bgp_vty_return(vty, ret);
3619 }
3620
3621 ALIAS_HIDDEN(no_neighbor_set_peer_group, no_neighbor_set_peer_group_hidden_cmd,
3622 "no neighbor <A.B.C.D|X:X::X:X|WORD> peer-group PGNAME",
3623 NO_STR NEIGHBOR_STR NEIGHBOR_ADDR_STR2
3624 "Member of the peer-group\n"
3625 "Peer-group name\n")
3626
3627 static int peer_flag_modify_vty(struct vty *vty, const char *ip_str,
3628 uint32_t flag, int set)
3629 {
3630 int ret;
3631 struct peer *peer;
3632
3633 peer = peer_and_group_lookup_vty(vty, ip_str);
3634 if (!peer)
3635 return CMD_WARNING_CONFIG_FAILED;
3636
3637 /*
3638 * If 'neighbor <interface>', then this is for directly connected peers,
3639 * we should not accept disable-connected-check.
3640 */
3641 if (peer->conf_if && (flag == PEER_FLAG_DISABLE_CONNECTED_CHECK)) {
3642 vty_out(vty,
3643 "%s is directly connected peer, cannot accept disable-"
3644 "connected-check\n",
3645 ip_str);
3646 return CMD_WARNING_CONFIG_FAILED;
3647 }
3648
3649 if (!set && flag == PEER_FLAG_SHUTDOWN)
3650 peer_tx_shutdown_message_unset(peer);
3651
3652 if (set)
3653 ret = peer_flag_set(peer, flag);
3654 else
3655 ret = peer_flag_unset(peer, flag);
3656
3657 return bgp_vty_return(vty, ret);
3658 }
3659
3660 static int peer_flag_set_vty(struct vty *vty, const char *ip_str, uint32_t flag)
3661 {
3662 return peer_flag_modify_vty(vty, ip_str, flag, 1);
3663 }
3664
3665 static int peer_flag_unset_vty(struct vty *vty, const char *ip_str,
3666 uint32_t flag)
3667 {
3668 return peer_flag_modify_vty(vty, ip_str, flag, 0);
3669 }
3670
3671 /* neighbor passive. */
3672 DEFUN (neighbor_passive,
3673 neighbor_passive_cmd,
3674 "neighbor <A.B.C.D|X:X::X:X|WORD> passive",
3675 NEIGHBOR_STR
3676 NEIGHBOR_ADDR_STR2
3677 "Don't send open messages to this neighbor\n")
3678 {
3679 int idx_peer = 1;
3680 return peer_flag_set_vty(vty, argv[idx_peer]->arg, PEER_FLAG_PASSIVE);
3681 }
3682
3683 DEFUN (no_neighbor_passive,
3684 no_neighbor_passive_cmd,
3685 "no neighbor <A.B.C.D|X:X::X:X|WORD> passive",
3686 NO_STR
3687 NEIGHBOR_STR
3688 NEIGHBOR_ADDR_STR2
3689 "Don't send open messages to this neighbor\n")
3690 {
3691 int idx_peer = 2;
3692 return peer_flag_unset_vty(vty, argv[idx_peer]->arg, PEER_FLAG_PASSIVE);
3693 }
3694
3695 /* neighbor shutdown. */
3696 DEFUN (neighbor_shutdown_msg,
3697 neighbor_shutdown_msg_cmd,
3698 "neighbor <A.B.C.D|X:X::X:X|WORD> shutdown message MSG...",
3699 NEIGHBOR_STR
3700 NEIGHBOR_ADDR_STR2
3701 "Administratively shut down this neighbor\n"
3702 "Add a shutdown message (draft-ietf-idr-shutdown-06)\n"
3703 "Shutdown message\n")
3704 {
3705 int idx_peer = 1;
3706
3707 if (argc >= 5) {
3708 struct peer *peer =
3709 peer_and_group_lookup_vty(vty, argv[idx_peer]->arg);
3710 char *message;
3711
3712 if (!peer)
3713 return CMD_WARNING_CONFIG_FAILED;
3714 message = argv_concat(argv, argc, 4);
3715 peer_tx_shutdown_message_set(peer, message);
3716 XFREE(MTYPE_TMP, message);
3717 }
3718
3719 return peer_flag_set_vty(vty, argv[idx_peer]->arg, PEER_FLAG_SHUTDOWN);
3720 }
3721
3722 ALIAS(neighbor_shutdown_msg, neighbor_shutdown_cmd,
3723 "neighbor <A.B.C.D|X:X::X:X|WORD> shutdown",
3724 NEIGHBOR_STR NEIGHBOR_ADDR_STR2
3725 "Administratively shut down this neighbor\n")
3726
3727 DEFUN (no_neighbor_shutdown_msg,
3728 no_neighbor_shutdown_msg_cmd,
3729 "no neighbor <A.B.C.D|X:X::X:X|WORD> shutdown message MSG...",
3730 NO_STR
3731 NEIGHBOR_STR
3732 NEIGHBOR_ADDR_STR2
3733 "Administratively shut down this neighbor\n"
3734 "Remove a shutdown message (draft-ietf-idr-shutdown-06)\n"
3735 "Shutdown message\n")
3736 {
3737 int idx_peer = 2;
3738
3739 return peer_flag_unset_vty(vty, argv[idx_peer]->arg,
3740 PEER_FLAG_SHUTDOWN);
3741 }
3742
3743 ALIAS(no_neighbor_shutdown_msg, no_neighbor_shutdown_cmd,
3744 "no neighbor <A.B.C.D|X:X::X:X|WORD> shutdown",
3745 NO_STR NEIGHBOR_STR NEIGHBOR_ADDR_STR2
3746 "Administratively shut down this neighbor\n")
3747
3748 /* neighbor capability dynamic. */
3749 DEFUN (neighbor_capability_dynamic,
3750 neighbor_capability_dynamic_cmd,
3751 "neighbor <A.B.C.D|X:X::X:X|WORD> capability dynamic",
3752 NEIGHBOR_STR
3753 NEIGHBOR_ADDR_STR2
3754 "Advertise capability to the peer\n"
3755 "Advertise dynamic capability to this neighbor\n")
3756 {
3757 int idx_peer = 1;
3758 return peer_flag_set_vty(vty, argv[idx_peer]->arg,
3759 PEER_FLAG_DYNAMIC_CAPABILITY);
3760 }
3761
3762 DEFUN (no_neighbor_capability_dynamic,
3763 no_neighbor_capability_dynamic_cmd,
3764 "no neighbor <A.B.C.D|X:X::X:X|WORD> capability dynamic",
3765 NO_STR
3766 NEIGHBOR_STR
3767 NEIGHBOR_ADDR_STR2
3768 "Advertise capability to the peer\n"
3769 "Advertise dynamic capability to this neighbor\n")
3770 {
3771 int idx_peer = 2;
3772 return peer_flag_unset_vty(vty, argv[idx_peer]->arg,
3773 PEER_FLAG_DYNAMIC_CAPABILITY);
3774 }
3775
3776 /* neighbor dont-capability-negotiate */
3777 DEFUN (neighbor_dont_capability_negotiate,
3778 neighbor_dont_capability_negotiate_cmd,
3779 "neighbor <A.B.C.D|X:X::X:X|WORD> dont-capability-negotiate",
3780 NEIGHBOR_STR
3781 NEIGHBOR_ADDR_STR2
3782 "Do not perform capability negotiation\n")
3783 {
3784 int idx_peer = 1;
3785 return peer_flag_set_vty(vty, argv[idx_peer]->arg,
3786 PEER_FLAG_DONT_CAPABILITY);
3787 }
3788
3789 DEFUN (no_neighbor_dont_capability_negotiate,
3790 no_neighbor_dont_capability_negotiate_cmd,
3791 "no neighbor <A.B.C.D|X:X::X:X|WORD> dont-capability-negotiate",
3792 NO_STR
3793 NEIGHBOR_STR
3794 NEIGHBOR_ADDR_STR2
3795 "Do not perform capability negotiation\n")
3796 {
3797 int idx_peer = 2;
3798 return peer_flag_unset_vty(vty, argv[idx_peer]->arg,
3799 PEER_FLAG_DONT_CAPABILITY);
3800 }
3801
3802 /* neighbor capability extended next hop encoding */
3803 DEFUN (neighbor_capability_enhe,
3804 neighbor_capability_enhe_cmd,
3805 "neighbor <A.B.C.D|X:X::X:X|WORD> capability extended-nexthop",
3806 NEIGHBOR_STR
3807 NEIGHBOR_ADDR_STR2
3808 "Advertise capability to the peer\n"
3809 "Advertise extended next-hop capability to the peer\n")
3810 {
3811 int idx_peer = 1;
3812 return peer_flag_set_vty(vty, argv[idx_peer]->arg,
3813 PEER_FLAG_CAPABILITY_ENHE);
3814 }
3815
3816 DEFUN (no_neighbor_capability_enhe,
3817 no_neighbor_capability_enhe_cmd,
3818 "no neighbor <A.B.C.D|X:X::X:X|WORD> capability extended-nexthop",
3819 NO_STR
3820 NEIGHBOR_STR
3821 NEIGHBOR_ADDR_STR2
3822 "Advertise capability to the peer\n"
3823 "Advertise extended next-hop capability to the peer\n")
3824 {
3825 int idx_peer = 2;
3826 return peer_flag_unset_vty(vty, argv[idx_peer]->arg,
3827 PEER_FLAG_CAPABILITY_ENHE);
3828 }
3829
3830 static int peer_af_flag_modify_vty(struct vty *vty, const char *peer_str,
3831 afi_t afi, safi_t safi, uint32_t flag,
3832 int set)
3833 {
3834 int ret;
3835 struct peer *peer;
3836
3837 peer = peer_and_group_lookup_vty(vty, peer_str);
3838 if (!peer)
3839 return CMD_WARNING_CONFIG_FAILED;
3840
3841 if (set)
3842 ret = peer_af_flag_set(peer, afi, safi, flag);
3843 else
3844 ret = peer_af_flag_unset(peer, afi, safi, flag);
3845
3846 return bgp_vty_return(vty, ret);
3847 }
3848
3849 static int peer_af_flag_set_vty(struct vty *vty, const char *peer_str,
3850 afi_t afi, safi_t safi, uint32_t flag)
3851 {
3852 return peer_af_flag_modify_vty(vty, peer_str, afi, safi, flag, 1);
3853 }
3854
3855 static int peer_af_flag_unset_vty(struct vty *vty, const char *peer_str,
3856 afi_t afi, safi_t safi, uint32_t flag)
3857 {
3858 return peer_af_flag_modify_vty(vty, peer_str, afi, safi, flag, 0);
3859 }
3860
3861 /* neighbor capability orf prefix-list. */
3862 DEFUN (neighbor_capability_orf_prefix,
3863 neighbor_capability_orf_prefix_cmd,
3864 "neighbor <A.B.C.D|X:X::X:X|WORD> capability orf prefix-list <both|send|receive>",
3865 NEIGHBOR_STR
3866 NEIGHBOR_ADDR_STR2
3867 "Advertise capability to the peer\n"
3868 "Advertise ORF capability to the peer\n"
3869 "Advertise prefixlist ORF capability to this neighbor\n"
3870 "Capability to SEND and RECEIVE the ORF to/from this neighbor\n"
3871 "Capability to RECEIVE the ORF from this neighbor\n"
3872 "Capability to SEND the ORF to this neighbor\n")
3873 {
3874 int idx_peer = 1;
3875 int idx_send_recv = 5;
3876 uint16_t flag = 0;
3877
3878 if (strmatch(argv[idx_send_recv]->text, "send"))
3879 flag = PEER_FLAG_ORF_PREFIX_SM;
3880 else if (strmatch(argv[idx_send_recv]->text, "receive"))
3881 flag = PEER_FLAG_ORF_PREFIX_RM;
3882 else if (strmatch(argv[idx_send_recv]->text, "both"))
3883 flag = PEER_FLAG_ORF_PREFIX_SM | PEER_FLAG_ORF_PREFIX_RM;
3884 else {
3885 vty_out(vty, "%% BGP invalid orf prefix-list option\n");
3886 return CMD_WARNING_CONFIG_FAILED;
3887 }
3888
3889 return peer_af_flag_set_vty(vty, argv[idx_peer]->arg, bgp_node_afi(vty),
3890 bgp_node_safi(vty), flag);
3891 }
3892
3893 ALIAS_HIDDEN(
3894 neighbor_capability_orf_prefix,
3895 neighbor_capability_orf_prefix_hidden_cmd,
3896 "neighbor <A.B.C.D|X:X::X:X|WORD> capability orf prefix-list <both|send|receive>",
3897 NEIGHBOR_STR NEIGHBOR_ADDR_STR2
3898 "Advertise capability to the peer\n"
3899 "Advertise ORF capability to the peer\n"
3900 "Advertise prefixlist ORF capability to this neighbor\n"
3901 "Capability to SEND and RECEIVE the ORF to/from this neighbor\n"
3902 "Capability to RECEIVE the ORF from this neighbor\n"
3903 "Capability to SEND the ORF to this neighbor\n")
3904
3905 DEFUN (no_neighbor_capability_orf_prefix,
3906 no_neighbor_capability_orf_prefix_cmd,
3907 "no neighbor <A.B.C.D|X:X::X:X|WORD> capability orf prefix-list <both|send|receive>",
3908 NO_STR
3909 NEIGHBOR_STR
3910 NEIGHBOR_ADDR_STR2
3911 "Advertise capability to the peer\n"
3912 "Advertise ORF capability to the peer\n"
3913 "Advertise prefixlist ORF capability to this neighbor\n"
3914 "Capability to SEND and RECEIVE the ORF to/from this neighbor\n"
3915 "Capability to RECEIVE the ORF from this neighbor\n"
3916 "Capability to SEND the ORF to this neighbor\n")
3917 {
3918 int idx_peer = 2;
3919 int idx_send_recv = 6;
3920 uint16_t flag = 0;
3921
3922 if (strmatch(argv[idx_send_recv]->text, "send"))
3923 flag = PEER_FLAG_ORF_PREFIX_SM;
3924 else if (strmatch(argv[idx_send_recv]->text, "receive"))
3925 flag = PEER_FLAG_ORF_PREFIX_RM;
3926 else if (strmatch(argv[idx_send_recv]->text, "both"))
3927 flag = PEER_FLAG_ORF_PREFIX_SM | PEER_FLAG_ORF_PREFIX_RM;
3928 else {
3929 vty_out(vty, "%% BGP invalid orf prefix-list option\n");
3930 return CMD_WARNING_CONFIG_FAILED;
3931 }
3932
3933 return peer_af_flag_unset_vty(vty, argv[idx_peer]->arg,
3934 bgp_node_afi(vty), bgp_node_safi(vty),
3935 flag);
3936 }
3937
3938 ALIAS_HIDDEN(
3939 no_neighbor_capability_orf_prefix,
3940 no_neighbor_capability_orf_prefix_hidden_cmd,
3941 "no neighbor <A.B.C.D|X:X::X:X|WORD> capability orf prefix-list <both|send|receive>",
3942 NO_STR NEIGHBOR_STR NEIGHBOR_ADDR_STR2
3943 "Advertise capability to the peer\n"
3944 "Advertise ORF capability to the peer\n"
3945 "Advertise prefixlist ORF capability to this neighbor\n"
3946 "Capability to SEND and RECEIVE the ORF to/from this neighbor\n"
3947 "Capability to RECEIVE the ORF from this neighbor\n"
3948 "Capability to SEND the ORF to this neighbor\n")
3949
3950 /* neighbor next-hop-self. */
3951 DEFUN (neighbor_nexthop_self,
3952 neighbor_nexthop_self_cmd,
3953 "neighbor <A.B.C.D|X:X::X:X|WORD> next-hop-self",
3954 NEIGHBOR_STR
3955 NEIGHBOR_ADDR_STR2
3956 "Disable the next hop calculation for this neighbor\n")
3957 {
3958 int idx_peer = 1;
3959 return peer_af_flag_set_vty(vty, argv[idx_peer]->arg, bgp_node_afi(vty),
3960 bgp_node_safi(vty), PEER_FLAG_NEXTHOP_SELF);
3961 }
3962
3963 ALIAS_HIDDEN(neighbor_nexthop_self, neighbor_nexthop_self_hidden_cmd,
3964 "neighbor <A.B.C.D|X:X::X:X|WORD> next-hop-self",
3965 NEIGHBOR_STR NEIGHBOR_ADDR_STR2
3966 "Disable the next hop calculation for this neighbor\n")
3967
3968 /* neighbor next-hop-self. */
3969 DEFUN (neighbor_nexthop_self_force,
3970 neighbor_nexthop_self_force_cmd,
3971 "neighbor <A.B.C.D|X:X::X:X|WORD> next-hop-self force",
3972 NEIGHBOR_STR
3973 NEIGHBOR_ADDR_STR2
3974 "Disable the next hop calculation for this neighbor\n"
3975 "Set the next hop to self for reflected routes\n")
3976 {
3977 int idx_peer = 1;
3978 return peer_af_flag_set_vty(vty, argv[idx_peer]->arg, bgp_node_afi(vty),
3979 bgp_node_safi(vty),
3980 PEER_FLAG_FORCE_NEXTHOP_SELF);
3981 }
3982
3983 ALIAS_HIDDEN(neighbor_nexthop_self_force,
3984 neighbor_nexthop_self_force_hidden_cmd,
3985 "neighbor <A.B.C.D|X:X::X:X|WORD> next-hop-self force",
3986 NEIGHBOR_STR NEIGHBOR_ADDR_STR2
3987 "Disable the next hop calculation for this neighbor\n"
3988 "Set the next hop to self for reflected routes\n")
3989
3990 ALIAS_HIDDEN(neighbor_nexthop_self_force,
3991 neighbor_nexthop_self_all_hidden_cmd,
3992 "neighbor <A.B.C.D|X:X::X:X|WORD> next-hop-self all",
3993 NEIGHBOR_STR NEIGHBOR_ADDR_STR2
3994 "Disable the next hop calculation for this neighbor\n"
3995 "Set the next hop to self for reflected routes\n")
3996
3997 DEFUN (no_neighbor_nexthop_self,
3998 no_neighbor_nexthop_self_cmd,
3999 "no neighbor <A.B.C.D|X:X::X:X|WORD> next-hop-self",
4000 NO_STR
4001 NEIGHBOR_STR
4002 NEIGHBOR_ADDR_STR2
4003 "Disable the next hop calculation for this neighbor\n")
4004 {
4005 int idx_peer = 2;
4006 return peer_af_flag_unset_vty(vty, argv[idx_peer]->arg,
4007 bgp_node_afi(vty), bgp_node_safi(vty),
4008 PEER_FLAG_NEXTHOP_SELF);
4009 }
4010
4011 ALIAS_HIDDEN(no_neighbor_nexthop_self, no_neighbor_nexthop_self_hidden_cmd,
4012 "no neighbor <A.B.C.D|X:X::X:X|WORD> next-hop-self",
4013 NO_STR NEIGHBOR_STR NEIGHBOR_ADDR_STR2
4014 "Disable the next hop calculation for this neighbor\n")
4015
4016 DEFUN (no_neighbor_nexthop_self_force,
4017 no_neighbor_nexthop_self_force_cmd,
4018 "no neighbor <A.B.C.D|X:X::X:X|WORD> next-hop-self force",
4019 NO_STR
4020 NEIGHBOR_STR
4021 NEIGHBOR_ADDR_STR2
4022 "Disable the next hop calculation for this neighbor\n"
4023 "Set the next hop to self for reflected routes\n")
4024 {
4025 int idx_peer = 2;
4026 return peer_af_flag_unset_vty(vty, argv[idx_peer]->arg,
4027 bgp_node_afi(vty), bgp_node_safi(vty),
4028 PEER_FLAG_FORCE_NEXTHOP_SELF);
4029 }
4030
4031 ALIAS_HIDDEN(no_neighbor_nexthop_self_force,
4032 no_neighbor_nexthop_self_force_hidden_cmd,
4033 "no neighbor <A.B.C.D|X:X::X:X|WORD> next-hop-self force",
4034 NO_STR NEIGHBOR_STR NEIGHBOR_ADDR_STR2
4035 "Disable the next hop calculation for this neighbor\n"
4036 "Set the next hop to self for reflected routes\n")
4037
4038 ALIAS_HIDDEN(no_neighbor_nexthop_self_force,
4039 no_neighbor_nexthop_self_all_hidden_cmd,
4040 "no neighbor <A.B.C.D|X:X::X:X|WORD> next-hop-self all",
4041 NO_STR NEIGHBOR_STR NEIGHBOR_ADDR_STR2
4042 "Disable the next hop calculation for this neighbor\n"
4043 "Set the next hop to self for reflected routes\n")
4044
4045 /* neighbor as-override */
4046 DEFUN (neighbor_as_override,
4047 neighbor_as_override_cmd,
4048 "neighbor <A.B.C.D|X:X::X:X|WORD> as-override",
4049 NEIGHBOR_STR
4050 NEIGHBOR_ADDR_STR2
4051 "Override ASNs in outbound updates if aspath equals remote-as\n")
4052 {
4053 int idx_peer = 1;
4054 return peer_af_flag_set_vty(vty, argv[idx_peer]->arg, bgp_node_afi(vty),
4055 bgp_node_safi(vty), PEER_FLAG_AS_OVERRIDE);
4056 }
4057
4058 ALIAS_HIDDEN(neighbor_as_override, neighbor_as_override_hidden_cmd,
4059 "neighbor <A.B.C.D|X:X::X:X|WORD> as-override",
4060 NEIGHBOR_STR NEIGHBOR_ADDR_STR2
4061 "Override ASNs in outbound updates if aspath equals remote-as\n")
4062
4063 DEFUN (no_neighbor_as_override,
4064 no_neighbor_as_override_cmd,
4065 "no neighbor <A.B.C.D|X:X::X:X|WORD> as-override",
4066 NO_STR
4067 NEIGHBOR_STR
4068 NEIGHBOR_ADDR_STR2
4069 "Override ASNs in outbound updates if aspath equals remote-as\n")
4070 {
4071 int idx_peer = 2;
4072 return peer_af_flag_unset_vty(vty, argv[idx_peer]->arg,
4073 bgp_node_afi(vty), bgp_node_safi(vty),
4074 PEER_FLAG_AS_OVERRIDE);
4075 }
4076
4077 ALIAS_HIDDEN(no_neighbor_as_override, no_neighbor_as_override_hidden_cmd,
4078 "no neighbor <A.B.C.D|X:X::X:X|WORD> as-override",
4079 NO_STR NEIGHBOR_STR NEIGHBOR_ADDR_STR2
4080 "Override ASNs in outbound updates if aspath equals remote-as\n")
4081
4082 /* neighbor remove-private-AS. */
4083 DEFUN (neighbor_remove_private_as,
4084 neighbor_remove_private_as_cmd,
4085 "neighbor <A.B.C.D|X:X::X:X|WORD> remove-private-AS",
4086 NEIGHBOR_STR
4087 NEIGHBOR_ADDR_STR2
4088 "Remove private ASNs in outbound updates\n")
4089 {
4090 int idx_peer = 1;
4091 return peer_af_flag_set_vty(vty, argv[idx_peer]->arg, bgp_node_afi(vty),
4092 bgp_node_safi(vty),
4093 PEER_FLAG_REMOVE_PRIVATE_AS);
4094 }
4095
4096 ALIAS_HIDDEN(neighbor_remove_private_as, neighbor_remove_private_as_hidden_cmd,
4097 "neighbor <A.B.C.D|X:X::X:X|WORD> remove-private-AS",
4098 NEIGHBOR_STR NEIGHBOR_ADDR_STR2
4099 "Remove private ASNs in outbound updates\n")
4100
4101 DEFUN (neighbor_remove_private_as_all,
4102 neighbor_remove_private_as_all_cmd,
4103 "neighbor <A.B.C.D|X:X::X:X|WORD> remove-private-AS all",
4104 NEIGHBOR_STR
4105 NEIGHBOR_ADDR_STR2
4106 "Remove private ASNs in outbound updates\n"
4107 "Apply to all AS numbers\n")
4108 {
4109 int idx_peer = 1;
4110 return peer_af_flag_set_vty(vty, argv[idx_peer]->arg, bgp_node_afi(vty),
4111 bgp_node_safi(vty),
4112 PEER_FLAG_REMOVE_PRIVATE_AS_ALL);
4113 }
4114
4115 ALIAS_HIDDEN(neighbor_remove_private_as_all,
4116 neighbor_remove_private_as_all_hidden_cmd,
4117 "neighbor <A.B.C.D|X:X::X:X|WORD> remove-private-AS all",
4118 NEIGHBOR_STR NEIGHBOR_ADDR_STR2
4119 "Remove private ASNs in outbound updates\n"
4120 "Apply to all AS numbers")
4121
4122 DEFUN (neighbor_remove_private_as_replace_as,
4123 neighbor_remove_private_as_replace_as_cmd,
4124 "neighbor <A.B.C.D|X:X::X:X|WORD> remove-private-AS replace-AS",
4125 NEIGHBOR_STR
4126 NEIGHBOR_ADDR_STR2
4127 "Remove private ASNs in outbound updates\n"
4128 "Replace private ASNs with our ASN in outbound updates\n")
4129 {
4130 int idx_peer = 1;
4131 return peer_af_flag_set_vty(vty, argv[idx_peer]->arg, bgp_node_afi(vty),
4132 bgp_node_safi(vty),
4133 PEER_FLAG_REMOVE_PRIVATE_AS_REPLACE);
4134 }
4135
4136 ALIAS_HIDDEN(neighbor_remove_private_as_replace_as,
4137 neighbor_remove_private_as_replace_as_hidden_cmd,
4138 "neighbor <A.B.C.D|X:X::X:X|WORD> remove-private-AS replace-AS",
4139 NEIGHBOR_STR NEIGHBOR_ADDR_STR2
4140 "Remove private ASNs in outbound updates\n"
4141 "Replace private ASNs with our ASN in outbound updates\n")
4142
4143 DEFUN (neighbor_remove_private_as_all_replace_as,
4144 neighbor_remove_private_as_all_replace_as_cmd,
4145 "neighbor <A.B.C.D|X:X::X:X|WORD> remove-private-AS all replace-AS",
4146 NEIGHBOR_STR
4147 NEIGHBOR_ADDR_STR2
4148 "Remove private ASNs in outbound updates\n"
4149 "Apply to all AS numbers\n"
4150 "Replace private ASNs with our ASN in outbound updates\n")
4151 {
4152 int idx_peer = 1;
4153 return peer_af_flag_set_vty(vty, argv[idx_peer]->arg, bgp_node_afi(vty),
4154 bgp_node_safi(vty),
4155 PEER_FLAG_REMOVE_PRIVATE_AS_ALL_REPLACE);
4156 }
4157
4158 ALIAS_HIDDEN(
4159 neighbor_remove_private_as_all_replace_as,
4160 neighbor_remove_private_as_all_replace_as_hidden_cmd,
4161 "neighbor <A.B.C.D|X:X::X:X|WORD> remove-private-AS all replace-AS",
4162 NEIGHBOR_STR NEIGHBOR_ADDR_STR2
4163 "Remove private ASNs in outbound updates\n"
4164 "Apply to all AS numbers\n"
4165 "Replace private ASNs with our ASN in outbound updates\n")
4166
4167 DEFUN (no_neighbor_remove_private_as,
4168 no_neighbor_remove_private_as_cmd,
4169 "no neighbor <A.B.C.D|X:X::X:X|WORD> remove-private-AS",
4170 NO_STR
4171 NEIGHBOR_STR
4172 NEIGHBOR_ADDR_STR2
4173 "Remove private ASNs in outbound updates\n")
4174 {
4175 int idx_peer = 2;
4176 return peer_af_flag_unset_vty(vty, argv[idx_peer]->arg,
4177 bgp_node_afi(vty), bgp_node_safi(vty),
4178 PEER_FLAG_REMOVE_PRIVATE_AS);
4179 }
4180
4181 ALIAS_HIDDEN(no_neighbor_remove_private_as,
4182 no_neighbor_remove_private_as_hidden_cmd,
4183 "no neighbor <A.B.C.D|X:X::X:X|WORD> remove-private-AS",
4184 NO_STR NEIGHBOR_STR NEIGHBOR_ADDR_STR2
4185 "Remove private ASNs in outbound updates\n")
4186
4187 DEFUN (no_neighbor_remove_private_as_all,
4188 no_neighbor_remove_private_as_all_cmd,
4189 "no neighbor <A.B.C.D|X:X::X:X|WORD> remove-private-AS all",
4190 NO_STR
4191 NEIGHBOR_STR
4192 NEIGHBOR_ADDR_STR2
4193 "Remove private ASNs in outbound updates\n"
4194 "Apply to all AS numbers\n")
4195 {
4196 int idx_peer = 2;
4197 return peer_af_flag_unset_vty(vty, argv[idx_peer]->arg,
4198 bgp_node_afi(vty), bgp_node_safi(vty),
4199 PEER_FLAG_REMOVE_PRIVATE_AS_ALL);
4200 }
4201
4202 ALIAS_HIDDEN(no_neighbor_remove_private_as_all,
4203 no_neighbor_remove_private_as_all_hidden_cmd,
4204 "no neighbor <A.B.C.D|X:X::X:X|WORD> remove-private-AS all",
4205 NO_STR NEIGHBOR_STR NEIGHBOR_ADDR_STR2
4206 "Remove private ASNs in outbound updates\n"
4207 "Apply to all AS numbers\n")
4208
4209 DEFUN (no_neighbor_remove_private_as_replace_as,
4210 no_neighbor_remove_private_as_replace_as_cmd,
4211 "no neighbor <A.B.C.D|X:X::X:X|WORD> remove-private-AS replace-AS",
4212 NO_STR
4213 NEIGHBOR_STR
4214 NEIGHBOR_ADDR_STR2
4215 "Remove private ASNs in outbound updates\n"
4216 "Replace private ASNs with our ASN in outbound updates\n")
4217 {
4218 int idx_peer = 2;
4219 return peer_af_flag_unset_vty(vty, argv[idx_peer]->arg,
4220 bgp_node_afi(vty), bgp_node_safi(vty),
4221 PEER_FLAG_REMOVE_PRIVATE_AS_REPLACE);
4222 }
4223
4224 ALIAS_HIDDEN(no_neighbor_remove_private_as_replace_as,
4225 no_neighbor_remove_private_as_replace_as_hidden_cmd,
4226 "no neighbor <A.B.C.D|X:X::X:X|WORD> remove-private-AS replace-AS",
4227 NO_STR NEIGHBOR_STR NEIGHBOR_ADDR_STR2
4228 "Remove private ASNs in outbound updates\n"
4229 "Replace private ASNs with our ASN in outbound updates\n")
4230
4231 DEFUN (no_neighbor_remove_private_as_all_replace_as,
4232 no_neighbor_remove_private_as_all_replace_as_cmd,
4233 "no neighbor <A.B.C.D|X:X::X:X|WORD> remove-private-AS all replace-AS",
4234 NO_STR
4235 NEIGHBOR_STR
4236 NEIGHBOR_ADDR_STR2
4237 "Remove private ASNs in outbound updates\n"
4238 "Apply to all AS numbers\n"
4239 "Replace private ASNs with our ASN in outbound updates\n")
4240 {
4241 int idx_peer = 2;
4242 return peer_af_flag_unset_vty(vty, argv[idx_peer]->arg,
4243 bgp_node_afi(vty), bgp_node_safi(vty),
4244 PEER_FLAG_REMOVE_PRIVATE_AS_ALL_REPLACE);
4245 }
4246
4247 ALIAS_HIDDEN(
4248 no_neighbor_remove_private_as_all_replace_as,
4249 no_neighbor_remove_private_as_all_replace_as_hidden_cmd,
4250 "no neighbor <A.B.C.D|X:X::X:X|WORD> remove-private-AS all replace-AS",
4251 NO_STR NEIGHBOR_STR NEIGHBOR_ADDR_STR2
4252 "Remove private ASNs in outbound updates\n"
4253 "Apply to all AS numbers\n"
4254 "Replace private ASNs with our ASN in outbound updates\n")
4255
4256
4257 /* neighbor send-community. */
4258 DEFUN (neighbor_send_community,
4259 neighbor_send_community_cmd,
4260 "neighbor <A.B.C.D|X:X::X:X|WORD> send-community",
4261 NEIGHBOR_STR
4262 NEIGHBOR_ADDR_STR2
4263 "Send Community attribute to this neighbor\n")
4264 {
4265 int idx_peer = 1;
4266
4267 return peer_af_flag_set_vty(vty, argv[idx_peer]->arg, bgp_node_afi(vty),
4268 bgp_node_safi(vty),
4269 PEER_FLAG_SEND_COMMUNITY);
4270 }
4271
4272 ALIAS_HIDDEN(neighbor_send_community, neighbor_send_community_hidden_cmd,
4273 "neighbor <A.B.C.D|X:X::X:X|WORD> send-community",
4274 NEIGHBOR_STR NEIGHBOR_ADDR_STR2
4275 "Send Community attribute to this neighbor\n")
4276
4277 DEFUN (no_neighbor_send_community,
4278 no_neighbor_send_community_cmd,
4279 "no neighbor <A.B.C.D|X:X::X:X|WORD> send-community",
4280 NO_STR
4281 NEIGHBOR_STR
4282 NEIGHBOR_ADDR_STR2
4283 "Send Community attribute to this neighbor\n")
4284 {
4285 int idx_peer = 2;
4286
4287 return peer_af_flag_unset_vty(vty, argv[idx_peer]->arg,
4288 bgp_node_afi(vty), bgp_node_safi(vty),
4289 PEER_FLAG_SEND_COMMUNITY);
4290 }
4291
4292 ALIAS_HIDDEN(no_neighbor_send_community, no_neighbor_send_community_hidden_cmd,
4293 "no neighbor <A.B.C.D|X:X::X:X|WORD> send-community",
4294 NO_STR NEIGHBOR_STR NEIGHBOR_ADDR_STR2
4295 "Send Community attribute to this neighbor\n")
4296
4297 /* neighbor send-community extended. */
4298 DEFUN (neighbor_send_community_type,
4299 neighbor_send_community_type_cmd,
4300 "neighbor <A.B.C.D|X:X::X:X|WORD> send-community <both|all|extended|standard|large>",
4301 NEIGHBOR_STR
4302 NEIGHBOR_ADDR_STR2
4303 "Send Community attribute to this neighbor\n"
4304 "Send Standard and Extended Community attributes\n"
4305 "Send Standard, Large and Extended Community attributes\n"
4306 "Send Extended Community attributes\n"
4307 "Send Standard Community attributes\n"
4308 "Send Large Community attributes\n")
4309 {
4310 int idx_peer = 1;
4311 uint32_t flag = 0;
4312 const char *type = argv[argc - 1]->text;
4313
4314 if (strmatch(type, "standard")) {
4315 SET_FLAG(flag, PEER_FLAG_SEND_COMMUNITY);
4316 } else if (strmatch(type, "extended")) {
4317 SET_FLAG(flag, PEER_FLAG_SEND_EXT_COMMUNITY);
4318 } else if (strmatch(type, "large")) {
4319 SET_FLAG(flag, PEER_FLAG_SEND_LARGE_COMMUNITY);
4320 } else if (strmatch(type, "both")) {
4321 SET_FLAG(flag, PEER_FLAG_SEND_COMMUNITY);
4322 SET_FLAG(flag, PEER_FLAG_SEND_EXT_COMMUNITY);
4323 } else { /* if (strmatch(type, "all")) */
4324 SET_FLAG(flag, PEER_FLAG_SEND_COMMUNITY);
4325 SET_FLAG(flag, PEER_FLAG_SEND_EXT_COMMUNITY);
4326 SET_FLAG(flag, PEER_FLAG_SEND_LARGE_COMMUNITY);
4327 }
4328
4329 return peer_af_flag_set_vty(vty, argv[idx_peer]->arg, bgp_node_afi(vty),
4330 bgp_node_safi(vty), flag);
4331 }
4332
4333 ALIAS_HIDDEN(
4334 neighbor_send_community_type, neighbor_send_community_type_hidden_cmd,
4335 "neighbor <A.B.C.D|X:X::X:X|WORD> send-community <both|all|extended|standard|large>",
4336 NEIGHBOR_STR NEIGHBOR_ADDR_STR2
4337 "Send Community attribute to this neighbor\n"
4338 "Send Standard and Extended Community attributes\n"
4339 "Send Standard, Large and Extended Community attributes\n"
4340 "Send Extended Community attributes\n"
4341 "Send Standard Community attributes\n"
4342 "Send Large Community attributes\n")
4343
4344 DEFUN (no_neighbor_send_community_type,
4345 no_neighbor_send_community_type_cmd,
4346 "no neighbor <A.B.C.D|X:X::X:X|WORD> send-community <both|all|extended|standard|large>",
4347 NO_STR
4348 NEIGHBOR_STR
4349 NEIGHBOR_ADDR_STR2
4350 "Send Community attribute to this neighbor\n"
4351 "Send Standard and Extended Community attributes\n"
4352 "Send Standard, Large and Extended Community attributes\n"
4353 "Send Extended Community attributes\n"
4354 "Send Standard Community attributes\n"
4355 "Send Large Community attributes\n")
4356 {
4357 int idx_peer = 2;
4358 uint32_t flag = 0;
4359 const char *type = argv[argc - 1]->text;
4360
4361 if (strmatch(type, "standard")) {
4362 SET_FLAG(flag, PEER_FLAG_SEND_COMMUNITY);
4363 } else if (strmatch(type, "extended")) {
4364 SET_FLAG(flag, PEER_FLAG_SEND_EXT_COMMUNITY);
4365 } else if (strmatch(type, "large")) {
4366 SET_FLAG(flag, PEER_FLAG_SEND_LARGE_COMMUNITY);
4367 } else if (strmatch(type, "both")) {
4368 SET_FLAG(flag, PEER_FLAG_SEND_COMMUNITY);
4369 SET_FLAG(flag, PEER_FLAG_SEND_EXT_COMMUNITY);
4370 } else { /* if (strmatch(type, "all")) */
4371 SET_FLAG(flag, PEER_FLAG_SEND_COMMUNITY);
4372 SET_FLAG(flag, PEER_FLAG_SEND_EXT_COMMUNITY);
4373 SET_FLAG(flag, PEER_FLAG_SEND_LARGE_COMMUNITY);
4374 }
4375
4376 return peer_af_flag_unset_vty(vty, argv[idx_peer]->arg,
4377 bgp_node_afi(vty), bgp_node_safi(vty),
4378 flag);
4379 }
4380
4381 ALIAS_HIDDEN(
4382 no_neighbor_send_community_type,
4383 no_neighbor_send_community_type_hidden_cmd,
4384 "no neighbor <A.B.C.D|X:X::X:X|WORD> send-community <both|all|extended|standard|large>",
4385 NO_STR NEIGHBOR_STR NEIGHBOR_ADDR_STR2
4386 "Send Community attribute to this neighbor\n"
4387 "Send Standard and Extended Community attributes\n"
4388 "Send Standard, Large and Extended Community attributes\n"
4389 "Send Extended Community attributes\n"
4390 "Send Standard Community attributes\n"
4391 "Send Large Community attributes\n")
4392
4393 /* neighbor soft-reconfig. */
4394 DEFUN (neighbor_soft_reconfiguration,
4395 neighbor_soft_reconfiguration_cmd,
4396 "neighbor <A.B.C.D|X:X::X:X|WORD> soft-reconfiguration inbound",
4397 NEIGHBOR_STR
4398 NEIGHBOR_ADDR_STR2
4399 "Per neighbor soft reconfiguration\n"
4400 "Allow inbound soft reconfiguration for this neighbor\n")
4401 {
4402 int idx_peer = 1;
4403 return peer_af_flag_set_vty(vty, argv[idx_peer]->arg, bgp_node_afi(vty),
4404 bgp_node_safi(vty),
4405 PEER_FLAG_SOFT_RECONFIG);
4406 }
4407
4408 ALIAS_HIDDEN(neighbor_soft_reconfiguration,
4409 neighbor_soft_reconfiguration_hidden_cmd,
4410 "neighbor <A.B.C.D|X:X::X:X|WORD> soft-reconfiguration inbound",
4411 NEIGHBOR_STR NEIGHBOR_ADDR_STR2
4412 "Per neighbor soft reconfiguration\n"
4413 "Allow inbound soft reconfiguration for this neighbor\n")
4414
4415 DEFUN (no_neighbor_soft_reconfiguration,
4416 no_neighbor_soft_reconfiguration_cmd,
4417 "no neighbor <A.B.C.D|X:X::X:X|WORD> soft-reconfiguration inbound",
4418 NO_STR
4419 NEIGHBOR_STR
4420 NEIGHBOR_ADDR_STR2
4421 "Per neighbor soft reconfiguration\n"
4422 "Allow inbound soft reconfiguration for this neighbor\n")
4423 {
4424 int idx_peer = 2;
4425 return peer_af_flag_unset_vty(vty, argv[idx_peer]->arg,
4426 bgp_node_afi(vty), bgp_node_safi(vty),
4427 PEER_FLAG_SOFT_RECONFIG);
4428 }
4429
4430 ALIAS_HIDDEN(no_neighbor_soft_reconfiguration,
4431 no_neighbor_soft_reconfiguration_hidden_cmd,
4432 "no neighbor <A.B.C.D|X:X::X:X|WORD> soft-reconfiguration inbound",
4433 NO_STR NEIGHBOR_STR NEIGHBOR_ADDR_STR2
4434 "Per neighbor soft reconfiguration\n"
4435 "Allow inbound soft reconfiguration for this neighbor\n")
4436
4437 DEFUN (neighbor_route_reflector_client,
4438 neighbor_route_reflector_client_cmd,
4439 "neighbor <A.B.C.D|X:X::X:X|WORD> route-reflector-client",
4440 NEIGHBOR_STR
4441 NEIGHBOR_ADDR_STR2
4442 "Configure a neighbor as Route Reflector client\n")
4443 {
4444 int idx_peer = 1;
4445 struct peer *peer;
4446
4447
4448 peer = peer_and_group_lookup_vty(vty, argv[idx_peer]->arg);
4449 if (!peer)
4450 return CMD_WARNING_CONFIG_FAILED;
4451
4452 return peer_af_flag_set_vty(vty, argv[idx_peer]->arg, bgp_node_afi(vty),
4453 bgp_node_safi(vty),
4454 PEER_FLAG_REFLECTOR_CLIENT);
4455 }
4456
4457 ALIAS_HIDDEN(neighbor_route_reflector_client,
4458 neighbor_route_reflector_client_hidden_cmd,
4459 "neighbor <A.B.C.D|X:X::X:X|WORD> route-reflector-client",
4460 NEIGHBOR_STR NEIGHBOR_ADDR_STR2
4461 "Configure a neighbor as Route Reflector client\n")
4462
4463 DEFUN (no_neighbor_route_reflector_client,
4464 no_neighbor_route_reflector_client_cmd,
4465 "no neighbor <A.B.C.D|X:X::X:X|WORD> route-reflector-client",
4466 NO_STR
4467 NEIGHBOR_STR
4468 NEIGHBOR_ADDR_STR2
4469 "Configure a neighbor as Route Reflector client\n")
4470 {
4471 int idx_peer = 2;
4472 return peer_af_flag_unset_vty(vty, argv[idx_peer]->arg,
4473 bgp_node_afi(vty), bgp_node_safi(vty),
4474 PEER_FLAG_REFLECTOR_CLIENT);
4475 }
4476
4477 ALIAS_HIDDEN(no_neighbor_route_reflector_client,
4478 no_neighbor_route_reflector_client_hidden_cmd,
4479 "no neighbor <A.B.C.D|X:X::X:X|WORD> route-reflector-client",
4480 NO_STR NEIGHBOR_STR NEIGHBOR_ADDR_STR2
4481 "Configure a neighbor as Route Reflector client\n")
4482
4483 /* neighbor route-server-client. */
4484 DEFUN (neighbor_route_server_client,
4485 neighbor_route_server_client_cmd,
4486 "neighbor <A.B.C.D|X:X::X:X|WORD> route-server-client",
4487 NEIGHBOR_STR
4488 NEIGHBOR_ADDR_STR2
4489 "Configure a neighbor as Route Server client\n")
4490 {
4491 int idx_peer = 1;
4492 struct peer *peer;
4493
4494 peer = peer_and_group_lookup_vty(vty, argv[idx_peer]->arg);
4495 if (!peer)
4496 return CMD_WARNING_CONFIG_FAILED;
4497 return peer_af_flag_set_vty(vty, argv[idx_peer]->arg, bgp_node_afi(vty),
4498 bgp_node_safi(vty),
4499 PEER_FLAG_RSERVER_CLIENT);
4500 }
4501
4502 ALIAS_HIDDEN(neighbor_route_server_client,
4503 neighbor_route_server_client_hidden_cmd,
4504 "neighbor <A.B.C.D|X:X::X:X|WORD> route-server-client",
4505 NEIGHBOR_STR NEIGHBOR_ADDR_STR2
4506 "Configure a neighbor as Route Server client\n")
4507
4508 DEFUN (no_neighbor_route_server_client,
4509 no_neighbor_route_server_client_cmd,
4510 "no neighbor <A.B.C.D|X:X::X:X|WORD> route-server-client",
4511 NO_STR
4512 NEIGHBOR_STR
4513 NEIGHBOR_ADDR_STR2
4514 "Configure a neighbor as Route Server client\n")
4515 {
4516 int idx_peer = 2;
4517 return peer_af_flag_unset_vty(vty, argv[idx_peer]->arg,
4518 bgp_node_afi(vty), bgp_node_safi(vty),
4519 PEER_FLAG_RSERVER_CLIENT);
4520 }
4521
4522 ALIAS_HIDDEN(no_neighbor_route_server_client,
4523 no_neighbor_route_server_client_hidden_cmd,
4524 "no neighbor <A.B.C.D|X:X::X:X|WORD> route-server-client",
4525 NO_STR NEIGHBOR_STR NEIGHBOR_ADDR_STR2
4526 "Configure a neighbor as Route Server client\n")
4527
4528 DEFUN (neighbor_nexthop_local_unchanged,
4529 neighbor_nexthop_local_unchanged_cmd,
4530 "neighbor <A.B.C.D|X:X::X:X|WORD> nexthop-local unchanged",
4531 NEIGHBOR_STR
4532 NEIGHBOR_ADDR_STR2
4533 "Configure treatment of outgoing link-local nexthop attribute\n"
4534 "Leave link-local nexthop unchanged for this peer\n")
4535 {
4536 int idx_peer = 1;
4537 return peer_af_flag_set_vty(vty, argv[idx_peer]->arg, bgp_node_afi(vty),
4538 bgp_node_safi(vty),
4539 PEER_FLAG_NEXTHOP_LOCAL_UNCHANGED);
4540 }
4541
4542 DEFUN (no_neighbor_nexthop_local_unchanged,
4543 no_neighbor_nexthop_local_unchanged_cmd,
4544 "no neighbor <A.B.C.D|X:X::X:X|WORD> nexthop-local unchanged",
4545 NO_STR
4546 NEIGHBOR_STR
4547 NEIGHBOR_ADDR_STR2
4548 "Configure treatment of outgoing link-local-nexthop attribute\n"
4549 "Leave link-local nexthop unchanged for this peer\n")
4550 {
4551 int idx_peer = 2;
4552 return peer_af_flag_unset_vty(vty, argv[idx_peer]->arg,
4553 bgp_node_afi(vty), bgp_node_safi(vty),
4554 PEER_FLAG_NEXTHOP_LOCAL_UNCHANGED);
4555 }
4556
4557 DEFUN (neighbor_attr_unchanged,
4558 neighbor_attr_unchanged_cmd,
4559 "neighbor <A.B.C.D|X:X::X:X|WORD> attribute-unchanged [{as-path|next-hop|med}]",
4560 NEIGHBOR_STR
4561 NEIGHBOR_ADDR_STR2
4562 "BGP attribute is propagated unchanged to this neighbor\n"
4563 "As-path attribute\n"
4564 "Nexthop attribute\n"
4565 "Med attribute\n")
4566 {
4567 int idx = 0;
4568 char *peer_str = argv[1]->arg;
4569 struct peer *peer;
4570 uint16_t flags = 0;
4571 afi_t afi = bgp_node_afi(vty);
4572 safi_t safi = bgp_node_safi(vty);
4573
4574 peer = peer_and_group_lookup_vty(vty, peer_str);
4575 if (!peer)
4576 return CMD_WARNING_CONFIG_FAILED;
4577
4578 if (argv_find(argv, argc, "as-path", &idx))
4579 SET_FLAG(flags, PEER_FLAG_AS_PATH_UNCHANGED);
4580 idx = 0;
4581 if (argv_find(argv, argc, "next-hop", &idx))
4582 SET_FLAG(flags, PEER_FLAG_NEXTHOP_UNCHANGED);
4583 idx = 0;
4584 if (argv_find(argv, argc, "med", &idx))
4585 SET_FLAG(flags, PEER_FLAG_MED_UNCHANGED);
4586
4587 /* no flags means all of them! */
4588 if (!flags) {
4589 SET_FLAG(flags, PEER_FLAG_AS_PATH_UNCHANGED);
4590 SET_FLAG(flags, PEER_FLAG_NEXTHOP_UNCHANGED);
4591 SET_FLAG(flags, PEER_FLAG_MED_UNCHANGED);
4592 } else {
4593 if (!CHECK_FLAG(flags, PEER_FLAG_AS_PATH_UNCHANGED)
4594 && peer_af_flag_check(peer, afi, safi,
4595 PEER_FLAG_AS_PATH_UNCHANGED)) {
4596 peer_af_flag_unset_vty(vty, peer_str, afi, safi,
4597 PEER_FLAG_AS_PATH_UNCHANGED);
4598 }
4599
4600 if (!CHECK_FLAG(flags, PEER_FLAG_NEXTHOP_UNCHANGED)
4601 && peer_af_flag_check(peer, afi, safi,
4602 PEER_FLAG_NEXTHOP_UNCHANGED)) {
4603 peer_af_flag_unset_vty(vty, peer_str, afi, safi,
4604 PEER_FLAG_NEXTHOP_UNCHANGED);
4605 }
4606
4607 if (!CHECK_FLAG(flags, PEER_FLAG_MED_UNCHANGED)
4608 && peer_af_flag_check(peer, afi, safi,
4609 PEER_FLAG_MED_UNCHANGED)) {
4610 peer_af_flag_unset_vty(vty, peer_str, afi, safi,
4611 PEER_FLAG_MED_UNCHANGED);
4612 }
4613 }
4614
4615 return peer_af_flag_set_vty(vty, peer_str, afi, safi, flags);
4616 }
4617
4618 ALIAS_HIDDEN(
4619 neighbor_attr_unchanged, neighbor_attr_unchanged_hidden_cmd,
4620 "neighbor <A.B.C.D|X:X::X:X|WORD> attribute-unchanged [{as-path|next-hop|med}]",
4621 NEIGHBOR_STR NEIGHBOR_ADDR_STR2
4622 "BGP attribute is propagated unchanged to this neighbor\n"
4623 "As-path attribute\n"
4624 "Nexthop attribute\n"
4625 "Med attribute\n")
4626
4627 DEFUN (no_neighbor_attr_unchanged,
4628 no_neighbor_attr_unchanged_cmd,
4629 "no neighbor <A.B.C.D|X:X::X:X|WORD> attribute-unchanged [{as-path|next-hop|med}]",
4630 NO_STR
4631 NEIGHBOR_STR
4632 NEIGHBOR_ADDR_STR2
4633 "BGP attribute is propagated unchanged to this neighbor\n"
4634 "As-path attribute\n"
4635 "Nexthop attribute\n"
4636 "Med attribute\n")
4637 {
4638 int idx = 0;
4639 char *peer = argv[2]->arg;
4640 uint16_t flags = 0;
4641
4642 if (argv_find(argv, argc, "as-path", &idx))
4643 SET_FLAG(flags, PEER_FLAG_AS_PATH_UNCHANGED);
4644 idx = 0;
4645 if (argv_find(argv, argc, "next-hop", &idx))
4646 SET_FLAG(flags, PEER_FLAG_NEXTHOP_UNCHANGED);
4647 idx = 0;
4648 if (argv_find(argv, argc, "med", &idx))
4649 SET_FLAG(flags, PEER_FLAG_MED_UNCHANGED);
4650
4651 if (!flags) // no flags means all of them!
4652 {
4653 SET_FLAG(flags, PEER_FLAG_AS_PATH_UNCHANGED);
4654 SET_FLAG(flags, PEER_FLAG_NEXTHOP_UNCHANGED);
4655 SET_FLAG(flags, PEER_FLAG_MED_UNCHANGED);
4656 }
4657
4658 return peer_af_flag_unset_vty(vty, peer, bgp_node_afi(vty),
4659 bgp_node_safi(vty), flags);
4660 }
4661
4662 ALIAS_HIDDEN(
4663 no_neighbor_attr_unchanged, no_neighbor_attr_unchanged_hidden_cmd,
4664 "no neighbor <A.B.C.D|X:X::X:X|WORD> attribute-unchanged [{as-path|next-hop|med}]",
4665 NO_STR NEIGHBOR_STR NEIGHBOR_ADDR_STR2
4666 "BGP attribute is propagated unchanged to this neighbor\n"
4667 "As-path attribute\n"
4668 "Nexthop attribute\n"
4669 "Med attribute\n")
4670
4671 /* EBGP multihop configuration. */
4672 static int peer_ebgp_multihop_set_vty(struct vty *vty, const char *ip_str,
4673 const char *ttl_str)
4674 {
4675 struct peer *peer;
4676 unsigned int ttl;
4677
4678 peer = peer_and_group_lookup_vty(vty, ip_str);
4679 if (!peer)
4680 return CMD_WARNING_CONFIG_FAILED;
4681
4682 if (peer->conf_if)
4683 return bgp_vty_return(vty, BGP_ERR_INVALID_FOR_DIRECT_PEER);
4684
4685 if (!ttl_str)
4686 ttl = MAXTTL;
4687 else
4688 ttl = strtoul(ttl_str, NULL, 10);
4689
4690 return bgp_vty_return(vty, peer_ebgp_multihop_set(peer, ttl));
4691 }
4692
4693 static int peer_ebgp_multihop_unset_vty(struct vty *vty, const char *ip_str)
4694 {
4695 struct peer *peer;
4696
4697 peer = peer_and_group_lookup_vty(vty, ip_str);
4698 if (!peer)
4699 return CMD_WARNING_CONFIG_FAILED;
4700
4701 return bgp_vty_return(vty, peer_ebgp_multihop_unset(peer));
4702 }
4703
4704 /* neighbor ebgp-multihop. */
4705 DEFUN (neighbor_ebgp_multihop,
4706 neighbor_ebgp_multihop_cmd,
4707 "neighbor <A.B.C.D|X:X::X:X|WORD> ebgp-multihop",
4708 NEIGHBOR_STR
4709 NEIGHBOR_ADDR_STR2
4710 "Allow EBGP neighbors not on directly connected networks\n")
4711 {
4712 int idx_peer = 1;
4713 return peer_ebgp_multihop_set_vty(vty, argv[idx_peer]->arg, NULL);
4714 }
4715
4716 DEFUN (neighbor_ebgp_multihop_ttl,
4717 neighbor_ebgp_multihop_ttl_cmd,
4718 "neighbor <A.B.C.D|X:X::X:X|WORD> ebgp-multihop (1-255)",
4719 NEIGHBOR_STR
4720 NEIGHBOR_ADDR_STR2
4721 "Allow EBGP neighbors not on directly connected networks\n"
4722 "maximum hop count\n")
4723 {
4724 int idx_peer = 1;
4725 int idx_number = 3;
4726 return peer_ebgp_multihop_set_vty(vty, argv[idx_peer]->arg,
4727 argv[idx_number]->arg);
4728 }
4729
4730 DEFUN (no_neighbor_ebgp_multihop,
4731 no_neighbor_ebgp_multihop_cmd,
4732 "no neighbor <A.B.C.D|X:X::X:X|WORD> ebgp-multihop [(1-255)]",
4733 NO_STR
4734 NEIGHBOR_STR
4735 NEIGHBOR_ADDR_STR2
4736 "Allow EBGP neighbors not on directly connected networks\n"
4737 "maximum hop count\n")
4738 {
4739 int idx_peer = 2;
4740 return peer_ebgp_multihop_unset_vty(vty, argv[idx_peer]->arg);
4741 }
4742
4743
4744 /* disable-connected-check */
4745 DEFUN (neighbor_disable_connected_check,
4746 neighbor_disable_connected_check_cmd,
4747 "neighbor <A.B.C.D|X:X::X:X|WORD> <disable-connected-check|enforce-multihop>",
4748 NEIGHBOR_STR
4749 NEIGHBOR_ADDR_STR2
4750 "one-hop away EBGP peer using loopback address\n"
4751 "Enforce EBGP neighbors perform multihop\n")
4752 {
4753 int idx_peer = 1;
4754 return peer_flag_set_vty(vty, argv[idx_peer]->arg,
4755 PEER_FLAG_DISABLE_CONNECTED_CHECK);
4756 }
4757
4758 DEFUN (no_neighbor_disable_connected_check,
4759 no_neighbor_disable_connected_check_cmd,
4760 "no neighbor <A.B.C.D|X:X::X:X|WORD> <disable-connected-check|enforce-multihop>",
4761 NO_STR
4762 NEIGHBOR_STR
4763 NEIGHBOR_ADDR_STR2
4764 "one-hop away EBGP peer using loopback address\n"
4765 "Enforce EBGP neighbors perform multihop\n")
4766 {
4767 int idx_peer = 2;
4768 return peer_flag_unset_vty(vty, argv[idx_peer]->arg,
4769 PEER_FLAG_DISABLE_CONNECTED_CHECK);
4770 }
4771
4772
4773 /* enforce-first-as */
4774 DEFUN (neighbor_enforce_first_as,
4775 neighbor_enforce_first_as_cmd,
4776 "neighbor <A.B.C.D|X:X::X:X|WORD> enforce-first-as",
4777 NEIGHBOR_STR
4778 NEIGHBOR_ADDR_STR2
4779 "Enforce the first AS for EBGP routes\n")
4780 {
4781 int idx_peer = 1;
4782
4783 return peer_flag_set_vty(vty, argv[idx_peer]->arg,
4784 PEER_FLAG_ENFORCE_FIRST_AS);
4785 }
4786
4787 DEFUN (no_neighbor_enforce_first_as,
4788 no_neighbor_enforce_first_as_cmd,
4789 "no neighbor <A.B.C.D|X:X::X:X|WORD> enforce-first-as",
4790 NO_STR
4791 NEIGHBOR_STR
4792 NEIGHBOR_ADDR_STR2
4793 "Enforce the first AS for EBGP routes\n")
4794 {
4795 int idx_peer = 2;
4796
4797 return peer_flag_unset_vty(vty, argv[idx_peer]->arg,
4798 PEER_FLAG_ENFORCE_FIRST_AS);
4799 }
4800
4801
4802 DEFUN (neighbor_description,
4803 neighbor_description_cmd,
4804 "neighbor <A.B.C.D|X:X::X:X|WORD> description LINE...",
4805 NEIGHBOR_STR
4806 NEIGHBOR_ADDR_STR2
4807 "Neighbor specific description\n"
4808 "Up to 80 characters describing this neighbor\n")
4809 {
4810 int idx_peer = 1;
4811 int idx_line = 3;
4812 struct peer *peer;
4813 char *str;
4814
4815 peer = peer_and_group_lookup_vty(vty, argv[idx_peer]->arg);
4816 if (!peer)
4817 return CMD_WARNING_CONFIG_FAILED;
4818
4819 str = argv_concat(argv, argc, idx_line);
4820
4821 peer_description_set(peer, str);
4822
4823 XFREE(MTYPE_TMP, str);
4824
4825 return CMD_SUCCESS;
4826 }
4827
4828 DEFUN (no_neighbor_description,
4829 no_neighbor_description_cmd,
4830 "no neighbor <A.B.C.D|X:X::X:X|WORD> description",
4831 NO_STR
4832 NEIGHBOR_STR
4833 NEIGHBOR_ADDR_STR2
4834 "Neighbor specific description\n")
4835 {
4836 int idx_peer = 2;
4837 struct peer *peer;
4838
4839 peer = peer_and_group_lookup_vty(vty, argv[idx_peer]->arg);
4840 if (!peer)
4841 return CMD_WARNING_CONFIG_FAILED;
4842
4843 peer_description_unset(peer);
4844
4845 return CMD_SUCCESS;
4846 }
4847
4848 ALIAS(no_neighbor_description, no_neighbor_description_comment_cmd,
4849 "no neighbor <A.B.C.D|X:X::X:X|WORD> description LINE...",
4850 NO_STR NEIGHBOR_STR NEIGHBOR_ADDR_STR2
4851 "Neighbor specific description\n"
4852 "Up to 80 characters describing this neighbor\n")
4853
4854 /* Neighbor update-source. */
4855 static int peer_update_source_vty(struct vty *vty, const char *peer_str,
4856 const char *source_str)
4857 {
4858 struct peer *peer;
4859 struct prefix p;
4860 union sockunion su;
4861
4862 peer = peer_and_group_lookup_vty(vty, peer_str);
4863 if (!peer)
4864 return CMD_WARNING_CONFIG_FAILED;
4865
4866 if (peer->conf_if)
4867 return CMD_WARNING;
4868
4869 if (source_str) {
4870 if (str2sockunion(source_str, &su) == 0)
4871 peer_update_source_addr_set(peer, &su);
4872 else {
4873 if (str2prefix(source_str, &p)) {
4874 vty_out(vty,
4875 "%% Invalid update-source, remove prefix length \n");
4876 return CMD_WARNING_CONFIG_FAILED;
4877 } else
4878 peer_update_source_if_set(peer, source_str);
4879 }
4880 } else
4881 peer_update_source_unset(peer);
4882
4883 return CMD_SUCCESS;
4884 }
4885
4886 #define BGP_UPDATE_SOURCE_HELP_STR \
4887 "IPv4 address\n" \
4888 "IPv6 address\n" \
4889 "Interface name (requires zebra to be running)\n"
4890
4891 DEFUN (neighbor_update_source,
4892 neighbor_update_source_cmd,
4893 "neighbor <A.B.C.D|X:X::X:X|WORD> update-source <A.B.C.D|X:X::X:X|WORD>",
4894 NEIGHBOR_STR
4895 NEIGHBOR_ADDR_STR2
4896 "Source of routing updates\n"
4897 BGP_UPDATE_SOURCE_HELP_STR)
4898 {
4899 int idx_peer = 1;
4900 int idx_peer_2 = 3;
4901 return peer_update_source_vty(vty, argv[idx_peer]->arg,
4902 argv[idx_peer_2]->arg);
4903 }
4904
4905 DEFUN (no_neighbor_update_source,
4906 no_neighbor_update_source_cmd,
4907 "no neighbor <A.B.C.D|X:X::X:X|WORD> update-source [<A.B.C.D|X:X::X:X|WORD>]",
4908 NO_STR
4909 NEIGHBOR_STR
4910 NEIGHBOR_ADDR_STR2
4911 "Source of routing updates\n"
4912 BGP_UPDATE_SOURCE_HELP_STR)
4913 {
4914 int idx_peer = 2;
4915 return peer_update_source_vty(vty, argv[idx_peer]->arg, NULL);
4916 }
4917
4918 static int peer_default_originate_set_vty(struct vty *vty, const char *peer_str,
4919 afi_t afi, safi_t safi,
4920 const char *rmap, int set)
4921 {
4922 int ret;
4923 struct peer *peer;
4924 struct route_map *route_map = NULL;
4925
4926 peer = peer_and_group_lookup_vty(vty, peer_str);
4927 if (!peer)
4928 return CMD_WARNING_CONFIG_FAILED;
4929
4930 if (set) {
4931 if (rmap)
4932 route_map = route_map_lookup_warn_noexist(vty, rmap);
4933 ret = peer_default_originate_set(peer, afi, safi,
4934 rmap, route_map);
4935 } else
4936 ret = peer_default_originate_unset(peer, afi, safi);
4937
4938 return bgp_vty_return(vty, ret);
4939 }
4940
4941 /* neighbor default-originate. */
4942 DEFUN (neighbor_default_originate,
4943 neighbor_default_originate_cmd,
4944 "neighbor <A.B.C.D|X:X::X:X|WORD> default-originate",
4945 NEIGHBOR_STR
4946 NEIGHBOR_ADDR_STR2
4947 "Originate default route to this neighbor\n")
4948 {
4949 int idx_peer = 1;
4950 return peer_default_originate_set_vty(vty, argv[idx_peer]->arg,
4951 bgp_node_afi(vty),
4952 bgp_node_safi(vty), NULL, 1);
4953 }
4954
4955 ALIAS_HIDDEN(neighbor_default_originate, neighbor_default_originate_hidden_cmd,
4956 "neighbor <A.B.C.D|X:X::X:X|WORD> default-originate",
4957 NEIGHBOR_STR NEIGHBOR_ADDR_STR2
4958 "Originate default route to this neighbor\n")
4959
4960 DEFUN (neighbor_default_originate_rmap,
4961 neighbor_default_originate_rmap_cmd,
4962 "neighbor <A.B.C.D|X:X::X:X|WORD> default-originate route-map WORD",
4963 NEIGHBOR_STR
4964 NEIGHBOR_ADDR_STR2
4965 "Originate default route to this neighbor\n"
4966 "Route-map to specify criteria to originate default\n"
4967 "route-map name\n")
4968 {
4969 int idx_peer = 1;
4970 int idx_word = 4;
4971 return peer_default_originate_set_vty(
4972 vty, argv[idx_peer]->arg, bgp_node_afi(vty), bgp_node_safi(vty),
4973 argv[idx_word]->arg, 1);
4974 }
4975
4976 ALIAS_HIDDEN(
4977 neighbor_default_originate_rmap,
4978 neighbor_default_originate_rmap_hidden_cmd,
4979 "neighbor <A.B.C.D|X:X::X:X|WORD> default-originate route-map WORD",
4980 NEIGHBOR_STR NEIGHBOR_ADDR_STR2
4981 "Originate default route to this neighbor\n"
4982 "Route-map to specify criteria to originate default\n"
4983 "route-map name\n")
4984
4985 DEFUN (no_neighbor_default_originate,
4986 no_neighbor_default_originate_cmd,
4987 "no neighbor <A.B.C.D|X:X::X:X|WORD> default-originate [route-map WORD]",
4988 NO_STR
4989 NEIGHBOR_STR
4990 NEIGHBOR_ADDR_STR2
4991 "Originate default route to this neighbor\n"
4992 "Route-map to specify criteria to originate default\n"
4993 "route-map name\n")
4994 {
4995 int idx_peer = 2;
4996 return peer_default_originate_set_vty(vty, argv[idx_peer]->arg,
4997 bgp_node_afi(vty),
4998 bgp_node_safi(vty), NULL, 0);
4999 }
5000
5001 ALIAS_HIDDEN(
5002 no_neighbor_default_originate, no_neighbor_default_originate_hidden_cmd,
5003 "no neighbor <A.B.C.D|X:X::X:X|WORD> default-originate [route-map WORD]",
5004 NO_STR NEIGHBOR_STR NEIGHBOR_ADDR_STR2
5005 "Originate default route to this neighbor\n"
5006 "Route-map to specify criteria to originate default\n"
5007 "route-map name\n")
5008
5009
5010 /* Set neighbor's BGP port. */
5011 static int peer_port_vty(struct vty *vty, const char *ip_str, int afi,
5012 const char *port_str)
5013 {
5014 struct peer *peer;
5015 uint16_t port;
5016 struct servent *sp;
5017
5018 peer = peer_lookup_vty(vty, ip_str);
5019 if (!peer)
5020 return CMD_WARNING_CONFIG_FAILED;
5021
5022 if (!port_str) {
5023 sp = getservbyname("bgp", "tcp");
5024 port = (sp == NULL) ? BGP_PORT_DEFAULT : ntohs(sp->s_port);
5025 } else {
5026 port = strtoul(port_str, NULL, 10);
5027 }
5028
5029 peer_port_set(peer, port);
5030
5031 return CMD_SUCCESS;
5032 }
5033
5034 /* Set specified peer's BGP port. */
5035 DEFUN (neighbor_port,
5036 neighbor_port_cmd,
5037 "neighbor <A.B.C.D|X:X::X:X> port (0-65535)",
5038 NEIGHBOR_STR
5039 NEIGHBOR_ADDR_STR
5040 "Neighbor's BGP port\n"
5041 "TCP port number\n")
5042 {
5043 int idx_ip = 1;
5044 int idx_number = 3;
5045 return peer_port_vty(vty, argv[idx_ip]->arg, AFI_IP,
5046 argv[idx_number]->arg);
5047 }
5048
5049 DEFUN (no_neighbor_port,
5050 no_neighbor_port_cmd,
5051 "no neighbor <A.B.C.D|X:X::X:X> port [(0-65535)]",
5052 NO_STR
5053 NEIGHBOR_STR
5054 NEIGHBOR_ADDR_STR
5055 "Neighbor's BGP port\n"
5056 "TCP port number\n")
5057 {
5058 int idx_ip = 2;
5059 return peer_port_vty(vty, argv[idx_ip]->arg, AFI_IP, NULL);
5060 }
5061
5062
5063 /* neighbor weight. */
5064 static int peer_weight_set_vty(struct vty *vty, const char *ip_str, afi_t afi,
5065 safi_t safi, const char *weight_str)
5066 {
5067 int ret;
5068 struct peer *peer;
5069 unsigned long weight;
5070
5071 peer = peer_and_group_lookup_vty(vty, ip_str);
5072 if (!peer)
5073 return CMD_WARNING_CONFIG_FAILED;
5074
5075 weight = strtoul(weight_str, NULL, 10);
5076
5077 ret = peer_weight_set(peer, afi, safi, weight);
5078 return bgp_vty_return(vty, ret);
5079 }
5080
5081 static int peer_weight_unset_vty(struct vty *vty, const char *ip_str, afi_t afi,
5082 safi_t safi)
5083 {
5084 int ret;
5085 struct peer *peer;
5086
5087 peer = peer_and_group_lookup_vty(vty, ip_str);
5088 if (!peer)
5089 return CMD_WARNING_CONFIG_FAILED;
5090
5091 ret = peer_weight_unset(peer, afi, safi);
5092 return bgp_vty_return(vty, ret);
5093 }
5094
5095 DEFUN (neighbor_weight,
5096 neighbor_weight_cmd,
5097 "neighbor <A.B.C.D|X:X::X:X|WORD> weight (0-65535)",
5098 NEIGHBOR_STR
5099 NEIGHBOR_ADDR_STR2
5100 "Set default weight for routes from this neighbor\n"
5101 "default weight\n")
5102 {
5103 int idx_peer = 1;
5104 int idx_number = 3;
5105 return peer_weight_set_vty(vty, argv[idx_peer]->arg, bgp_node_afi(vty),
5106 bgp_node_safi(vty), argv[idx_number]->arg);
5107 }
5108
5109 ALIAS_HIDDEN(neighbor_weight, neighbor_weight_hidden_cmd,
5110 "neighbor <A.B.C.D|X:X::X:X|WORD> weight (0-65535)",
5111 NEIGHBOR_STR NEIGHBOR_ADDR_STR2
5112 "Set default weight for routes from this neighbor\n"
5113 "default weight\n")
5114
5115 DEFUN (no_neighbor_weight,
5116 no_neighbor_weight_cmd,
5117 "no neighbor <A.B.C.D|X:X::X:X|WORD> weight [(0-65535)]",
5118 NO_STR
5119 NEIGHBOR_STR
5120 NEIGHBOR_ADDR_STR2
5121 "Set default weight for routes from this neighbor\n"
5122 "default weight\n")
5123 {
5124 int idx_peer = 2;
5125 return peer_weight_unset_vty(vty, argv[idx_peer]->arg,
5126 bgp_node_afi(vty), bgp_node_safi(vty));
5127 }
5128
5129 ALIAS_HIDDEN(no_neighbor_weight, no_neighbor_weight_hidden_cmd,
5130 "no neighbor <A.B.C.D|X:X::X:X|WORD> weight [(0-65535)]",
5131 NO_STR NEIGHBOR_STR NEIGHBOR_ADDR_STR2
5132 "Set default weight for routes from this neighbor\n"
5133 "default weight\n")
5134
5135
5136 /* Override capability negotiation. */
5137 DEFUN (neighbor_override_capability,
5138 neighbor_override_capability_cmd,
5139 "neighbor <A.B.C.D|X:X::X:X|WORD> override-capability",
5140 NEIGHBOR_STR
5141 NEIGHBOR_ADDR_STR2
5142 "Override capability negotiation result\n")
5143 {
5144 int idx_peer = 1;
5145 return peer_flag_set_vty(vty, argv[idx_peer]->arg,
5146 PEER_FLAG_OVERRIDE_CAPABILITY);
5147 }
5148
5149 DEFUN (no_neighbor_override_capability,
5150 no_neighbor_override_capability_cmd,
5151 "no neighbor <A.B.C.D|X:X::X:X|WORD> override-capability",
5152 NO_STR
5153 NEIGHBOR_STR
5154 NEIGHBOR_ADDR_STR2
5155 "Override capability negotiation result\n")
5156 {
5157 int idx_peer = 2;
5158 return peer_flag_unset_vty(vty, argv[idx_peer]->arg,
5159 PEER_FLAG_OVERRIDE_CAPABILITY);
5160 }
5161
5162 DEFUN (neighbor_strict_capability,
5163 neighbor_strict_capability_cmd,
5164 "neighbor <A.B.C.D|X:X::X:X|WORD> strict-capability-match",
5165 NEIGHBOR_STR
5166 NEIGHBOR_ADDR_STR2
5167 "Strict capability negotiation match\n")
5168 {
5169 int idx_peer = 1;
5170
5171 return peer_flag_set_vty(vty, argv[idx_peer]->arg,
5172 PEER_FLAG_STRICT_CAP_MATCH);
5173 }
5174
5175 DEFUN (no_neighbor_strict_capability,
5176 no_neighbor_strict_capability_cmd,
5177 "no neighbor <A.B.C.D|X:X::X:X|WORD> strict-capability-match",
5178 NO_STR
5179 NEIGHBOR_STR
5180 NEIGHBOR_ADDR_STR2
5181 "Strict capability negotiation match\n")
5182 {
5183 int idx_peer = 2;
5184
5185 return peer_flag_unset_vty(vty, argv[idx_peer]->arg,
5186 PEER_FLAG_STRICT_CAP_MATCH);
5187 }
5188
5189 static int peer_timers_set_vty(struct vty *vty, const char *ip_str,
5190 const char *keep_str, const char *hold_str)
5191 {
5192 int ret;
5193 struct peer *peer;
5194 uint32_t keepalive;
5195 uint32_t holdtime;
5196
5197 peer = peer_and_group_lookup_vty(vty, ip_str);
5198 if (!peer)
5199 return CMD_WARNING_CONFIG_FAILED;
5200
5201 keepalive = strtoul(keep_str, NULL, 10);
5202 holdtime = strtoul(hold_str, NULL, 10);
5203
5204 ret = peer_timers_set(peer, keepalive, holdtime);
5205
5206 return bgp_vty_return(vty, ret);
5207 }
5208
5209 static int peer_timers_unset_vty(struct vty *vty, const char *ip_str)
5210 {
5211 int ret;
5212 struct peer *peer;
5213
5214 peer = peer_and_group_lookup_vty(vty, ip_str);
5215 if (!peer)
5216 return CMD_WARNING_CONFIG_FAILED;
5217
5218 ret = peer_timers_unset(peer);
5219
5220 return bgp_vty_return(vty, ret);
5221 }
5222
5223 DEFUN (neighbor_timers,
5224 neighbor_timers_cmd,
5225 "neighbor <A.B.C.D|X:X::X:X|WORD> timers (0-65535) (0-65535)",
5226 NEIGHBOR_STR
5227 NEIGHBOR_ADDR_STR2
5228 "BGP per neighbor timers\n"
5229 "Keepalive interval\n"
5230 "Holdtime\n")
5231 {
5232 int idx_peer = 1;
5233 int idx_number = 3;
5234 int idx_number_2 = 4;
5235 return peer_timers_set_vty(vty, argv[idx_peer]->arg,
5236 argv[idx_number]->arg,
5237 argv[idx_number_2]->arg);
5238 }
5239
5240 DEFUN (no_neighbor_timers,
5241 no_neighbor_timers_cmd,
5242 "no neighbor <A.B.C.D|X:X::X:X|WORD> timers [(0-65535) (0-65535)]",
5243 NO_STR
5244 NEIGHBOR_STR
5245 NEIGHBOR_ADDR_STR2
5246 "BGP per neighbor timers\n"
5247 "Keepalive interval\n"
5248 "Holdtime\n")
5249 {
5250 int idx_peer = 2;
5251 return peer_timers_unset_vty(vty, argv[idx_peer]->arg);
5252 }
5253
5254
5255 static int peer_timers_connect_set_vty(struct vty *vty, const char *ip_str,
5256 const char *time_str)
5257 {
5258 int ret;
5259 struct peer *peer;
5260 uint32_t connect;
5261
5262 peer = peer_and_group_lookup_vty(vty, ip_str);
5263 if (!peer)
5264 return CMD_WARNING_CONFIG_FAILED;
5265
5266 connect = strtoul(time_str, NULL, 10);
5267
5268 ret = peer_timers_connect_set(peer, connect);
5269
5270 return bgp_vty_return(vty, ret);
5271 }
5272
5273 static int peer_timers_connect_unset_vty(struct vty *vty, const char *ip_str)
5274 {
5275 int ret;
5276 struct peer *peer;
5277
5278 peer = peer_and_group_lookup_vty(vty, ip_str);
5279 if (!peer)
5280 return CMD_WARNING_CONFIG_FAILED;
5281
5282 ret = peer_timers_connect_unset(peer);
5283
5284 return bgp_vty_return(vty, ret);
5285 }
5286
5287 DEFUN (neighbor_timers_connect,
5288 neighbor_timers_connect_cmd,
5289 "neighbor <A.B.C.D|X:X::X:X|WORD> timers connect (1-65535)",
5290 NEIGHBOR_STR
5291 NEIGHBOR_ADDR_STR2
5292 "BGP per neighbor timers\n"
5293 "BGP connect timer\n"
5294 "Connect timer\n")
5295 {
5296 int idx_peer = 1;
5297 int idx_number = 4;
5298 return peer_timers_connect_set_vty(vty, argv[idx_peer]->arg,
5299 argv[idx_number]->arg);
5300 }
5301
5302 DEFUN (no_neighbor_timers_connect,
5303 no_neighbor_timers_connect_cmd,
5304 "no neighbor <A.B.C.D|X:X::X:X|WORD> timers connect [(1-65535)]",
5305 NO_STR
5306 NEIGHBOR_STR
5307 NEIGHBOR_ADDR_STR2
5308 "BGP per neighbor timers\n"
5309 "BGP connect timer\n"
5310 "Connect timer\n")
5311 {
5312 int idx_peer = 2;
5313 return peer_timers_connect_unset_vty(vty, argv[idx_peer]->arg);
5314 }
5315
5316
5317 static int peer_advertise_interval_vty(struct vty *vty, const char *ip_str,
5318 const char *time_str, int set)
5319 {
5320 int ret;
5321 struct peer *peer;
5322 uint32_t routeadv = 0;
5323
5324 peer = peer_and_group_lookup_vty(vty, ip_str);
5325 if (!peer)
5326 return CMD_WARNING_CONFIG_FAILED;
5327
5328 if (time_str)
5329 routeadv = strtoul(time_str, NULL, 10);
5330
5331 if (set)
5332 ret = peer_advertise_interval_set(peer, routeadv);
5333 else
5334 ret = peer_advertise_interval_unset(peer);
5335
5336 return bgp_vty_return(vty, ret);
5337 }
5338
5339 DEFUN (neighbor_advertise_interval,
5340 neighbor_advertise_interval_cmd,
5341 "neighbor <A.B.C.D|X:X::X:X|WORD> advertisement-interval (0-600)",
5342 NEIGHBOR_STR
5343 NEIGHBOR_ADDR_STR2
5344 "Minimum interval between sending BGP routing updates\n"
5345 "time in seconds\n")
5346 {
5347 int idx_peer = 1;
5348 int idx_number = 3;
5349 return peer_advertise_interval_vty(vty, argv[idx_peer]->arg,
5350 argv[idx_number]->arg, 1);
5351 }
5352
5353 DEFUN (no_neighbor_advertise_interval,
5354 no_neighbor_advertise_interval_cmd,
5355 "no neighbor <A.B.C.D|X:X::X:X|WORD> advertisement-interval [(0-600)]",
5356 NO_STR
5357 NEIGHBOR_STR
5358 NEIGHBOR_ADDR_STR2
5359 "Minimum interval between sending BGP routing updates\n"
5360 "time in seconds\n")
5361 {
5362 int idx_peer = 2;
5363 return peer_advertise_interval_vty(vty, argv[idx_peer]->arg, NULL, 0);
5364 }
5365
5366
5367 /* Time to wait before processing route-map updates */
5368 DEFUN (bgp_set_route_map_delay_timer,
5369 bgp_set_route_map_delay_timer_cmd,
5370 "bgp route-map delay-timer (0-600)",
5371 SET_STR
5372 "BGP route-map delay timer\n"
5373 "Time in secs to wait before processing route-map changes\n"
5374 "0 disables the timer, no route updates happen when route-maps change\n")
5375 {
5376 int idx_number = 3;
5377 uint32_t rmap_delay_timer;
5378
5379 if (argv[idx_number]->arg) {
5380 rmap_delay_timer = strtoul(argv[idx_number]->arg, NULL, 10);
5381 bm->rmap_update_timer = rmap_delay_timer;
5382
5383 /* if the dynamic update handling is being disabled, and a timer
5384 * is
5385 * running, stop the timer and act as if the timer has already
5386 * fired.
5387 */
5388 if (!rmap_delay_timer && bm->t_rmap_update) {
5389 BGP_TIMER_OFF(bm->t_rmap_update);
5390 thread_execute(bm->master, bgp_route_map_update_timer,
5391 NULL, 0);
5392 }
5393 return CMD_SUCCESS;
5394 } else {
5395 vty_out(vty, "%% BGP invalid route-map delay-timer\n");
5396 return CMD_WARNING_CONFIG_FAILED;
5397 }
5398 }
5399
5400 DEFUN (no_bgp_set_route_map_delay_timer,
5401 no_bgp_set_route_map_delay_timer_cmd,
5402 "no bgp route-map delay-timer [(0-600)]",
5403 NO_STR
5404 BGP_STR
5405 "Default BGP route-map delay timer\n"
5406 "Reset to default time to wait for processing route-map changes\n"
5407 "0 disables the timer, no route updates happen when route-maps change\n")
5408 {
5409
5410 bm->rmap_update_timer = RMAP_DEFAULT_UPDATE_TIMER;
5411
5412 return CMD_SUCCESS;
5413 }
5414
5415
5416 /* neighbor interface */
5417 static int peer_interface_vty(struct vty *vty, const char *ip_str,
5418 const char *str)
5419 {
5420 struct peer *peer;
5421
5422 peer = peer_lookup_vty(vty, ip_str);
5423 if (!peer || peer->conf_if) {
5424 vty_out(vty, "%% BGP invalid peer %s\n", ip_str);
5425 return CMD_WARNING_CONFIG_FAILED;
5426 }
5427
5428 if (str)
5429 peer_interface_set(peer, str);
5430 else
5431 peer_interface_unset(peer);
5432
5433 return CMD_SUCCESS;
5434 }
5435
5436 DEFUN (neighbor_interface,
5437 neighbor_interface_cmd,
5438 "neighbor <A.B.C.D|X:X::X:X> interface WORD",
5439 NEIGHBOR_STR
5440 NEIGHBOR_ADDR_STR
5441 "Interface\n"
5442 "Interface name\n")
5443 {
5444 int idx_ip = 1;
5445 int idx_word = 3;
5446 return peer_interface_vty(vty, argv[idx_ip]->arg, argv[idx_word]->arg);
5447 }
5448
5449 DEFUN (no_neighbor_interface,
5450 no_neighbor_interface_cmd,
5451 "no neighbor <A.B.C.D|X:X::X:X|WORD> interface WORD",
5452 NO_STR
5453 NEIGHBOR_STR
5454 NEIGHBOR_ADDR_STR2
5455 "Interface\n"
5456 "Interface name\n")
5457 {
5458 int idx_peer = 2;
5459 return peer_interface_vty(vty, argv[idx_peer]->arg, NULL);
5460 }
5461
5462 DEFUN (neighbor_distribute_list,
5463 neighbor_distribute_list_cmd,
5464 "neighbor <A.B.C.D|X:X::X:X|WORD> distribute-list <(1-199)|(1300-2699)|WORD> <in|out>",
5465 NEIGHBOR_STR
5466 NEIGHBOR_ADDR_STR2
5467 "Filter updates to/from this neighbor\n"
5468 "IP access-list number\n"
5469 "IP access-list number (expanded range)\n"
5470 "IP Access-list name\n"
5471 "Filter incoming updates\n"
5472 "Filter outgoing updates\n")
5473 {
5474 int idx_peer = 1;
5475 int idx_acl = 3;
5476 int direct, ret;
5477 struct peer *peer;
5478
5479 const char *pstr = argv[idx_peer]->arg;
5480 const char *acl = argv[idx_acl]->arg;
5481 const char *inout = argv[argc - 1]->text;
5482
5483 peer = peer_and_group_lookup_vty(vty, pstr);
5484 if (!peer)
5485 return CMD_WARNING_CONFIG_FAILED;
5486
5487 /* Check filter direction. */
5488 direct = strmatch(inout, "in") ? FILTER_IN : FILTER_OUT;
5489 ret = peer_distribute_set(peer, bgp_node_afi(vty), bgp_node_safi(vty),
5490 direct, acl);
5491
5492 return bgp_vty_return(vty, ret);
5493 }
5494
5495 ALIAS_HIDDEN(
5496 neighbor_distribute_list, neighbor_distribute_list_hidden_cmd,
5497 "neighbor <A.B.C.D|X:X::X:X|WORD> distribute-list <(1-199)|(1300-2699)|WORD> <in|out>",
5498 NEIGHBOR_STR NEIGHBOR_ADDR_STR2
5499 "Filter updates to/from this neighbor\n"
5500 "IP access-list number\n"
5501 "IP access-list number (expanded range)\n"
5502 "IP Access-list name\n"
5503 "Filter incoming updates\n"
5504 "Filter outgoing updates\n")
5505
5506 DEFUN (no_neighbor_distribute_list,
5507 no_neighbor_distribute_list_cmd,
5508 "no neighbor <A.B.C.D|X:X::X:X|WORD> distribute-list <(1-199)|(1300-2699)|WORD> <in|out>",
5509 NO_STR
5510 NEIGHBOR_STR
5511 NEIGHBOR_ADDR_STR2
5512 "Filter updates to/from this neighbor\n"
5513 "IP access-list number\n"
5514 "IP access-list number (expanded range)\n"
5515 "IP Access-list name\n"
5516 "Filter incoming updates\n"
5517 "Filter outgoing updates\n")
5518 {
5519 int idx_peer = 2;
5520 int direct, ret;
5521 struct peer *peer;
5522
5523 const char *pstr = argv[idx_peer]->arg;
5524 const char *inout = argv[argc - 1]->text;
5525
5526 peer = peer_and_group_lookup_vty(vty, pstr);
5527 if (!peer)
5528 return CMD_WARNING_CONFIG_FAILED;
5529
5530 /* Check filter direction. */
5531 direct = strmatch(inout, "in") ? FILTER_IN : FILTER_OUT;
5532 ret = peer_distribute_unset(peer, bgp_node_afi(vty), bgp_node_safi(vty),
5533 direct);
5534
5535 return bgp_vty_return(vty, ret);
5536 }
5537
5538 ALIAS_HIDDEN(
5539 no_neighbor_distribute_list, no_neighbor_distribute_list_hidden_cmd,
5540 "no neighbor <A.B.C.D|X:X::X:X|WORD> distribute-list <(1-199)|(1300-2699)|WORD> <in|out>",
5541 NO_STR NEIGHBOR_STR NEIGHBOR_ADDR_STR2
5542 "Filter updates to/from this neighbor\n"
5543 "IP access-list number\n"
5544 "IP access-list number (expanded range)\n"
5545 "IP Access-list name\n"
5546 "Filter incoming updates\n"
5547 "Filter outgoing updates\n")
5548
5549 /* Set prefix list to the peer. */
5550 static int peer_prefix_list_set_vty(struct vty *vty, const char *ip_str,
5551 afi_t afi, safi_t safi,
5552 const char *name_str,
5553 const char *direct_str)
5554 {
5555 int ret;
5556 int direct = FILTER_IN;
5557 struct peer *peer;
5558
5559 peer = peer_and_group_lookup_vty(vty, ip_str);
5560 if (!peer)
5561 return CMD_WARNING_CONFIG_FAILED;
5562
5563 /* Check filter direction. */
5564 if (strncmp(direct_str, "i", 1) == 0)
5565 direct = FILTER_IN;
5566 else if (strncmp(direct_str, "o", 1) == 0)
5567 direct = FILTER_OUT;
5568
5569 ret = peer_prefix_list_set(peer, afi, safi, direct, name_str);
5570
5571 return bgp_vty_return(vty, ret);
5572 }
5573
5574 static int peer_prefix_list_unset_vty(struct vty *vty, const char *ip_str,
5575 afi_t afi, safi_t safi,
5576 const char *direct_str)
5577 {
5578 int ret;
5579 struct peer *peer;
5580 int direct = FILTER_IN;
5581
5582 peer = peer_and_group_lookup_vty(vty, ip_str);
5583 if (!peer)
5584 return CMD_WARNING_CONFIG_FAILED;
5585
5586 /* Check filter direction. */
5587 if (strncmp(direct_str, "i", 1) == 0)
5588 direct = FILTER_IN;
5589 else if (strncmp(direct_str, "o", 1) == 0)
5590 direct = FILTER_OUT;
5591
5592 ret = peer_prefix_list_unset(peer, afi, safi, direct);
5593
5594 return bgp_vty_return(vty, ret);
5595 }
5596
5597 DEFUN (neighbor_prefix_list,
5598 neighbor_prefix_list_cmd,
5599 "neighbor <A.B.C.D|X:X::X:X|WORD> prefix-list WORD <in|out>",
5600 NEIGHBOR_STR
5601 NEIGHBOR_ADDR_STR2
5602 "Filter updates to/from this neighbor\n"
5603 "Name of a prefix list\n"
5604 "Filter incoming updates\n"
5605 "Filter outgoing updates\n")
5606 {
5607 int idx_peer = 1;
5608 int idx_word = 3;
5609 int idx_in_out = 4;
5610 return peer_prefix_list_set_vty(
5611 vty, argv[idx_peer]->arg, bgp_node_afi(vty), bgp_node_safi(vty),
5612 argv[idx_word]->arg, argv[idx_in_out]->arg);
5613 }
5614
5615 ALIAS_HIDDEN(neighbor_prefix_list, neighbor_prefix_list_hidden_cmd,
5616 "neighbor <A.B.C.D|X:X::X:X|WORD> prefix-list WORD <in|out>",
5617 NEIGHBOR_STR NEIGHBOR_ADDR_STR2
5618 "Filter updates to/from this neighbor\n"
5619 "Name of a prefix list\n"
5620 "Filter incoming updates\n"
5621 "Filter outgoing updates\n")
5622
5623 DEFUN (no_neighbor_prefix_list,
5624 no_neighbor_prefix_list_cmd,
5625 "no neighbor <A.B.C.D|X:X::X:X|WORD> prefix-list WORD <in|out>",
5626 NO_STR
5627 NEIGHBOR_STR
5628 NEIGHBOR_ADDR_STR2
5629 "Filter updates to/from this neighbor\n"
5630 "Name of a prefix list\n"
5631 "Filter incoming updates\n"
5632 "Filter outgoing updates\n")
5633 {
5634 int idx_peer = 2;
5635 int idx_in_out = 5;
5636 return peer_prefix_list_unset_vty(vty, argv[idx_peer]->arg,
5637 bgp_node_afi(vty), bgp_node_safi(vty),
5638 argv[idx_in_out]->arg);
5639 }
5640
5641 ALIAS_HIDDEN(no_neighbor_prefix_list, no_neighbor_prefix_list_hidden_cmd,
5642 "no neighbor <A.B.C.D|X:X::X:X|WORD> prefix-list WORD <in|out>",
5643 NO_STR NEIGHBOR_STR NEIGHBOR_ADDR_STR2
5644 "Filter updates to/from this neighbor\n"
5645 "Name of a prefix list\n"
5646 "Filter incoming updates\n"
5647 "Filter outgoing updates\n")
5648
5649 static int peer_aslist_set_vty(struct vty *vty, const char *ip_str, afi_t afi,
5650 safi_t safi, const char *name_str,
5651 const char *direct_str)
5652 {
5653 int ret;
5654 struct peer *peer;
5655 int direct = FILTER_IN;
5656
5657 peer = peer_and_group_lookup_vty(vty, ip_str);
5658 if (!peer)
5659 return CMD_WARNING_CONFIG_FAILED;
5660
5661 /* Check filter direction. */
5662 if (strncmp(direct_str, "i", 1) == 0)
5663 direct = FILTER_IN;
5664 else if (strncmp(direct_str, "o", 1) == 0)
5665 direct = FILTER_OUT;
5666
5667 ret = peer_aslist_set(peer, afi, safi, direct, name_str);
5668
5669 return bgp_vty_return(vty, ret);
5670 }
5671
5672 static int peer_aslist_unset_vty(struct vty *vty, const char *ip_str, afi_t afi,
5673 safi_t safi, const char *direct_str)
5674 {
5675 int ret;
5676 struct peer *peer;
5677 int direct = FILTER_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, "i", 1) == 0)
5685 direct = FILTER_IN;
5686 else if (strncmp(direct_str, "o", 1) == 0)
5687 direct = FILTER_OUT;
5688
5689 ret = peer_aslist_unset(peer, afi, safi, direct);
5690
5691 return bgp_vty_return(vty, ret);
5692 }
5693
5694 DEFUN (neighbor_filter_list,
5695 neighbor_filter_list_cmd,
5696 "neighbor <A.B.C.D|X:X::X:X|WORD> filter-list WORD <in|out>",
5697 NEIGHBOR_STR
5698 NEIGHBOR_ADDR_STR2
5699 "Establish BGP filters\n"
5700 "AS path access-list name\n"
5701 "Filter incoming routes\n"
5702 "Filter outgoing routes\n")
5703 {
5704 int idx_peer = 1;
5705 int idx_word = 3;
5706 int idx_in_out = 4;
5707 return peer_aslist_set_vty(vty, argv[idx_peer]->arg, bgp_node_afi(vty),
5708 bgp_node_safi(vty), argv[idx_word]->arg,
5709 argv[idx_in_out]->arg);
5710 }
5711
5712 ALIAS_HIDDEN(neighbor_filter_list, neighbor_filter_list_hidden_cmd,
5713 "neighbor <A.B.C.D|X:X::X:X|WORD> filter-list WORD <in|out>",
5714 NEIGHBOR_STR NEIGHBOR_ADDR_STR2
5715 "Establish BGP filters\n"
5716 "AS path access-list name\n"
5717 "Filter incoming routes\n"
5718 "Filter outgoing routes\n")
5719
5720 DEFUN (no_neighbor_filter_list,
5721 no_neighbor_filter_list_cmd,
5722 "no neighbor <A.B.C.D|X:X::X:X|WORD> filter-list WORD <in|out>",
5723 NO_STR
5724 NEIGHBOR_STR
5725 NEIGHBOR_ADDR_STR2
5726 "Establish BGP filters\n"
5727 "AS path access-list name\n"
5728 "Filter incoming routes\n"
5729 "Filter outgoing routes\n")
5730 {
5731 int idx_peer = 2;
5732 int idx_in_out = 5;
5733 return peer_aslist_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_filter_list, no_neighbor_filter_list_hidden_cmd,
5739 "no neighbor <A.B.C.D|X:X::X:X|WORD> filter-list WORD <in|out>",
5740 NO_STR NEIGHBOR_STR NEIGHBOR_ADDR_STR2
5741 "Establish BGP filters\n"
5742 "AS path access-list name\n"
5743 "Filter incoming routes\n"
5744 "Filter outgoing routes\n")
5745
5746 /* Set route-map to the peer. */
5747 static int peer_route_map_set_vty(struct vty *vty, const char *ip_str,
5748 afi_t afi, safi_t safi, const char *name_str,
5749 const char *direct_str)
5750 {
5751 int ret;
5752 struct peer *peer;
5753 int direct = RMAP_IN;
5754 struct route_map *route_map;
5755
5756 peer = peer_and_group_lookup_vty(vty, ip_str);
5757 if (!peer)
5758 return CMD_WARNING_CONFIG_FAILED;
5759
5760 /* Check filter direction. */
5761 if (strncmp(direct_str, "in", 2) == 0)
5762 direct = RMAP_IN;
5763 else if (strncmp(direct_str, "o", 1) == 0)
5764 direct = RMAP_OUT;
5765
5766 route_map = route_map_lookup_warn_noexist(vty, name_str);
5767 ret = peer_route_map_set(peer, afi, safi, direct, name_str, route_map);
5768
5769 return bgp_vty_return(vty, ret);
5770 }
5771
5772 static int peer_route_map_unset_vty(struct vty *vty, const char *ip_str,
5773 afi_t afi, safi_t safi,
5774 const char *direct_str)
5775 {
5776 int ret;
5777 struct peer *peer;
5778 int direct = RMAP_IN;
5779
5780 peer = peer_and_group_lookup_vty(vty, ip_str);
5781 if (!peer)
5782 return CMD_WARNING_CONFIG_FAILED;
5783
5784 /* Check filter direction. */
5785 if (strncmp(direct_str, "in", 2) == 0)
5786 direct = RMAP_IN;
5787 else if (strncmp(direct_str, "o", 1) == 0)
5788 direct = RMAP_OUT;
5789
5790 ret = peer_route_map_unset(peer, afi, safi, direct);
5791
5792 return bgp_vty_return(vty, ret);
5793 }
5794
5795 DEFUN (neighbor_route_map,
5796 neighbor_route_map_cmd,
5797 "neighbor <A.B.C.D|X:X::X:X|WORD> route-map WORD <in|out>",
5798 NEIGHBOR_STR
5799 NEIGHBOR_ADDR_STR2
5800 "Apply route map to neighbor\n"
5801 "Name of route map\n"
5802 "Apply map to incoming routes\n"
5803 "Apply map to outbound routes\n")
5804 {
5805 int idx_peer = 1;
5806 int idx_word = 3;
5807 int idx_in_out = 4;
5808 return peer_route_map_set_vty(
5809 vty, argv[idx_peer]->arg, bgp_node_afi(vty), bgp_node_safi(vty),
5810 argv[idx_word]->arg, argv[idx_in_out]->arg);
5811 }
5812
5813 ALIAS_HIDDEN(neighbor_route_map, neighbor_route_map_hidden_cmd,
5814 "neighbor <A.B.C.D|X:X::X:X|WORD> route-map WORD <in|out>",
5815 NEIGHBOR_STR NEIGHBOR_ADDR_STR2
5816 "Apply route map to neighbor\n"
5817 "Name of route map\n"
5818 "Apply map to incoming routes\n"
5819 "Apply map to outbound routes\n")
5820
5821 DEFUN (no_neighbor_route_map,
5822 no_neighbor_route_map_cmd,
5823 "no neighbor <A.B.C.D|X:X::X:X|WORD> route-map WORD <in|out>",
5824 NO_STR
5825 NEIGHBOR_STR
5826 NEIGHBOR_ADDR_STR2
5827 "Apply route map to neighbor\n"
5828 "Name of route map\n"
5829 "Apply map to incoming routes\n"
5830 "Apply map to outbound routes\n")
5831 {
5832 int idx_peer = 2;
5833 int idx_in_out = 5;
5834 return peer_route_map_unset_vty(vty, argv[idx_peer]->arg,
5835 bgp_node_afi(vty), bgp_node_safi(vty),
5836 argv[idx_in_out]->arg);
5837 }
5838
5839 ALIAS_HIDDEN(no_neighbor_route_map, no_neighbor_route_map_hidden_cmd,
5840 "no neighbor <A.B.C.D|X:X::X:X|WORD> route-map WORD <in|out>",
5841 NO_STR NEIGHBOR_STR NEIGHBOR_ADDR_STR2
5842 "Apply route map to neighbor\n"
5843 "Name of route map\n"
5844 "Apply map to incoming routes\n"
5845 "Apply map to outbound routes\n")
5846
5847 /* Set unsuppress-map to the peer. */
5848 static int peer_unsuppress_map_set_vty(struct vty *vty, const char *ip_str,
5849 afi_t afi, safi_t safi,
5850 const char *name_str)
5851 {
5852 int ret;
5853 struct peer *peer;
5854 struct route_map *route_map;
5855
5856 peer = peer_and_group_lookup_vty(vty, ip_str);
5857 if (!peer)
5858 return CMD_WARNING_CONFIG_FAILED;
5859
5860 route_map = route_map_lookup_warn_noexist(vty, name_str);
5861 ret = peer_unsuppress_map_set(peer, afi, safi, name_str, route_map);
5862
5863 return bgp_vty_return(vty, ret);
5864 }
5865
5866 /* Unset route-map from the peer. */
5867 static int peer_unsuppress_map_unset_vty(struct vty *vty, const char *ip_str,
5868 afi_t afi, safi_t safi)
5869 {
5870 int ret;
5871 struct peer *peer;
5872
5873 peer = peer_and_group_lookup_vty(vty, ip_str);
5874 if (!peer)
5875 return CMD_WARNING_CONFIG_FAILED;
5876
5877 ret = peer_unsuppress_map_unset(peer, afi, safi);
5878
5879 return bgp_vty_return(vty, ret);
5880 }
5881
5882 DEFUN (neighbor_unsuppress_map,
5883 neighbor_unsuppress_map_cmd,
5884 "neighbor <A.B.C.D|X:X::X:X|WORD> unsuppress-map WORD",
5885 NEIGHBOR_STR
5886 NEIGHBOR_ADDR_STR2
5887 "Route-map to selectively unsuppress suppressed routes\n"
5888 "Name of route map\n")
5889 {
5890 int idx_peer = 1;
5891 int idx_word = 3;
5892 return peer_unsuppress_map_set_vty(
5893 vty, argv[idx_peer]->arg, bgp_node_afi(vty), bgp_node_safi(vty),
5894 argv[idx_word]->arg);
5895 }
5896
5897 ALIAS_HIDDEN(neighbor_unsuppress_map, neighbor_unsuppress_map_hidden_cmd,
5898 "neighbor <A.B.C.D|X:X::X:X|WORD> unsuppress-map WORD",
5899 NEIGHBOR_STR NEIGHBOR_ADDR_STR2
5900 "Route-map to selectively unsuppress suppressed routes\n"
5901 "Name of route map\n")
5902
5903 DEFUN (no_neighbor_unsuppress_map,
5904 no_neighbor_unsuppress_map_cmd,
5905 "no neighbor <A.B.C.D|X:X::X:X|WORD> unsuppress-map WORD",
5906 NO_STR
5907 NEIGHBOR_STR
5908 NEIGHBOR_ADDR_STR2
5909 "Route-map to selectively unsuppress suppressed routes\n"
5910 "Name of route map\n")
5911 {
5912 int idx_peer = 2;
5913 return peer_unsuppress_map_unset_vty(vty, argv[idx_peer]->arg,
5914 bgp_node_afi(vty),
5915 bgp_node_safi(vty));
5916 }
5917
5918 ALIAS_HIDDEN(no_neighbor_unsuppress_map, no_neighbor_unsuppress_map_hidden_cmd,
5919 "no neighbor <A.B.C.D|X:X::X:X|WORD> unsuppress-map WORD",
5920 NO_STR NEIGHBOR_STR NEIGHBOR_ADDR_STR2
5921 "Route-map to selectively unsuppress suppressed routes\n"
5922 "Name of route map\n")
5923
5924 static int peer_maximum_prefix_set_vty(struct vty *vty, const char *ip_str,
5925 afi_t afi, safi_t safi,
5926 const char *num_str,
5927 const char *threshold_str, int warning,
5928 const char *restart_str)
5929 {
5930 int ret;
5931 struct peer *peer;
5932 uint32_t max;
5933 uint8_t threshold;
5934 uint16_t restart;
5935
5936 peer = peer_and_group_lookup_vty(vty, ip_str);
5937 if (!peer)
5938 return CMD_WARNING_CONFIG_FAILED;
5939
5940 max = strtoul(num_str, NULL, 10);
5941 if (threshold_str)
5942 threshold = atoi(threshold_str);
5943 else
5944 threshold = MAXIMUM_PREFIX_THRESHOLD_DEFAULT;
5945
5946 if (restart_str)
5947 restart = atoi(restart_str);
5948 else
5949 restart = 0;
5950
5951 ret = peer_maximum_prefix_set(peer, afi, safi, max, threshold, warning,
5952 restart);
5953
5954 return bgp_vty_return(vty, ret);
5955 }
5956
5957 static int peer_maximum_prefix_unset_vty(struct vty *vty, const char *ip_str,
5958 afi_t afi, safi_t safi)
5959 {
5960 int ret;
5961 struct peer *peer;
5962
5963 peer = peer_and_group_lookup_vty(vty, ip_str);
5964 if (!peer)
5965 return CMD_WARNING_CONFIG_FAILED;
5966
5967 ret = peer_maximum_prefix_unset(peer, afi, safi);
5968
5969 return bgp_vty_return(vty, ret);
5970 }
5971
5972 /* Maximum number of prefix configuration. prefix count is different
5973 for each peer configuration. So this configuration can be set for
5974 each peer configuration. */
5975 DEFUN (neighbor_maximum_prefix,
5976 neighbor_maximum_prefix_cmd,
5977 "neighbor <A.B.C.D|X:X::X:X|WORD> maximum-prefix (1-4294967295)",
5978 NEIGHBOR_STR
5979 NEIGHBOR_ADDR_STR2
5980 "Maximum number of prefix accept from this peer\n"
5981 "maximum no. of prefix limit\n")
5982 {
5983 int idx_peer = 1;
5984 int idx_number = 3;
5985 return peer_maximum_prefix_set_vty(
5986 vty, argv[idx_peer]->arg, bgp_node_afi(vty), bgp_node_safi(vty),
5987 argv[idx_number]->arg, NULL, 0, NULL);
5988 }
5989
5990 ALIAS_HIDDEN(neighbor_maximum_prefix, neighbor_maximum_prefix_hidden_cmd,
5991 "neighbor <A.B.C.D|X:X::X:X|WORD> maximum-prefix (1-4294967295)",
5992 NEIGHBOR_STR NEIGHBOR_ADDR_STR2
5993 "Maximum number of prefix accept from this peer\n"
5994 "maximum no. of prefix limit\n")
5995
5996 DEFUN (neighbor_maximum_prefix_threshold,
5997 neighbor_maximum_prefix_threshold_cmd,
5998 "neighbor <A.B.C.D|X:X::X:X|WORD> maximum-prefix (1-4294967295) (1-100)",
5999 NEIGHBOR_STR
6000 NEIGHBOR_ADDR_STR2
6001 "Maximum number of prefix accept from this peer\n"
6002 "maximum no. of prefix limit\n"
6003 "Threshold value (%) at which to generate a warning msg\n")
6004 {
6005 int idx_peer = 1;
6006 int idx_number = 3;
6007 int idx_number_2 = 4;
6008 return peer_maximum_prefix_set_vty(
6009 vty, argv[idx_peer]->arg, bgp_node_afi(vty), bgp_node_safi(vty),
6010 argv[idx_number]->arg, argv[idx_number_2]->arg, 0, NULL);
6011 }
6012
6013 ALIAS_HIDDEN(
6014 neighbor_maximum_prefix_threshold,
6015 neighbor_maximum_prefix_threshold_hidden_cmd,
6016 "neighbor <A.B.C.D|X:X::X:X|WORD> maximum-prefix (1-4294967295) (1-100)",
6017 NEIGHBOR_STR NEIGHBOR_ADDR_STR2
6018 "Maximum number of prefix accept from this peer\n"
6019 "maximum no. of prefix limit\n"
6020 "Threshold value (%) at which to generate a warning msg\n")
6021
6022 DEFUN (neighbor_maximum_prefix_warning,
6023 neighbor_maximum_prefix_warning_cmd,
6024 "neighbor <A.B.C.D|X:X::X:X|WORD> maximum-prefix (1-4294967295) warning-only",
6025 NEIGHBOR_STR
6026 NEIGHBOR_ADDR_STR2
6027 "Maximum number of prefix accept from this peer\n"
6028 "maximum no. of prefix limit\n"
6029 "Only give warning message when limit is exceeded\n")
6030 {
6031 int idx_peer = 1;
6032 int idx_number = 3;
6033 return peer_maximum_prefix_set_vty(
6034 vty, argv[idx_peer]->arg, bgp_node_afi(vty), bgp_node_safi(vty),
6035 argv[idx_number]->arg, NULL, 1, NULL);
6036 }
6037
6038 ALIAS_HIDDEN(
6039 neighbor_maximum_prefix_warning,
6040 neighbor_maximum_prefix_warning_hidden_cmd,
6041 "neighbor <A.B.C.D|X:X::X:X|WORD> maximum-prefix (1-4294967295) warning-only",
6042 NEIGHBOR_STR NEIGHBOR_ADDR_STR2
6043 "Maximum number of prefix accept from this peer\n"
6044 "maximum no. of prefix limit\n"
6045 "Only give warning message when limit is exceeded\n")
6046
6047 DEFUN (neighbor_maximum_prefix_threshold_warning,
6048 neighbor_maximum_prefix_threshold_warning_cmd,
6049 "neighbor <A.B.C.D|X:X::X:X|WORD> maximum-prefix (1-4294967295) (1-100) warning-only",
6050 NEIGHBOR_STR
6051 NEIGHBOR_ADDR_STR2
6052 "Maximum number of prefix accept from this peer\n"
6053 "maximum no. of prefix limit\n"
6054 "Threshold value (%) at which to generate a warning msg\n"
6055 "Only give warning message when limit is exceeded\n")
6056 {
6057 int idx_peer = 1;
6058 int idx_number = 3;
6059 int idx_number_2 = 4;
6060 return peer_maximum_prefix_set_vty(
6061 vty, argv[idx_peer]->arg, bgp_node_afi(vty), bgp_node_safi(vty),
6062 argv[idx_number]->arg, argv[idx_number_2]->arg, 1, NULL);
6063 }
6064
6065 ALIAS_HIDDEN(
6066 neighbor_maximum_prefix_threshold_warning,
6067 neighbor_maximum_prefix_threshold_warning_hidden_cmd,
6068 "neighbor <A.B.C.D|X:X::X:X|WORD> maximum-prefix (1-4294967295) (1-100) warning-only",
6069 NEIGHBOR_STR NEIGHBOR_ADDR_STR2
6070 "Maximum number of prefix accept from this peer\n"
6071 "maximum no. of prefix limit\n"
6072 "Threshold value (%) at which to generate a warning msg\n"
6073 "Only give warning message when limit is exceeded\n")
6074
6075 DEFUN (neighbor_maximum_prefix_restart,
6076 neighbor_maximum_prefix_restart_cmd,
6077 "neighbor <A.B.C.D|X:X::X:X|WORD> maximum-prefix (1-4294967295) restart (1-65535)",
6078 NEIGHBOR_STR
6079 NEIGHBOR_ADDR_STR2
6080 "Maximum number of prefix accept from this peer\n"
6081 "maximum no. of prefix limit\n"
6082 "Restart bgp connection after limit is exceeded\n"
6083 "Restart interval in minutes\n")
6084 {
6085 int idx_peer = 1;
6086 int idx_number = 3;
6087 int idx_number_2 = 5;
6088 return peer_maximum_prefix_set_vty(
6089 vty, argv[idx_peer]->arg, bgp_node_afi(vty), bgp_node_safi(vty),
6090 argv[idx_number]->arg, NULL, 0, argv[idx_number_2]->arg);
6091 }
6092
6093 ALIAS_HIDDEN(
6094 neighbor_maximum_prefix_restart,
6095 neighbor_maximum_prefix_restart_hidden_cmd,
6096 "neighbor <A.B.C.D|X:X::X:X|WORD> maximum-prefix (1-4294967295) restart (1-65535)",
6097 NEIGHBOR_STR NEIGHBOR_ADDR_STR2
6098 "Maximum number of prefix accept from this peer\n"
6099 "maximum no. of prefix limit\n"
6100 "Restart bgp connection after limit is exceeded\n"
6101 "Restart interval in minutes\n")
6102
6103 DEFUN (neighbor_maximum_prefix_threshold_restart,
6104 neighbor_maximum_prefix_threshold_restart_cmd,
6105 "neighbor <A.B.C.D|X:X::X:X|WORD> maximum-prefix (1-4294967295) (1-100) restart (1-65535)",
6106 NEIGHBOR_STR
6107 NEIGHBOR_ADDR_STR2
6108 "Maximum number of prefixes to accept from this peer\n"
6109 "maximum no. of prefix limit\n"
6110 "Threshold value (%) at which to generate a warning msg\n"
6111 "Restart bgp connection after limit is exceeded\n"
6112 "Restart interval in minutes\n")
6113 {
6114 int idx_peer = 1;
6115 int idx_number = 3;
6116 int idx_number_2 = 4;
6117 int idx_number_3 = 6;
6118 return peer_maximum_prefix_set_vty(
6119 vty, argv[idx_peer]->arg, bgp_node_afi(vty), bgp_node_safi(vty),
6120 argv[idx_number]->arg, argv[idx_number_2]->arg, 0,
6121 argv[idx_number_3]->arg);
6122 }
6123
6124 ALIAS_HIDDEN(
6125 neighbor_maximum_prefix_threshold_restart,
6126 neighbor_maximum_prefix_threshold_restart_hidden_cmd,
6127 "neighbor <A.B.C.D|X:X::X:X|WORD> maximum-prefix (1-4294967295) (1-100) restart (1-65535)",
6128 NEIGHBOR_STR NEIGHBOR_ADDR_STR2
6129 "Maximum number of prefixes to accept from this peer\n"
6130 "maximum no. of prefix limit\n"
6131 "Threshold value (%) at which to generate a warning msg\n"
6132 "Restart bgp connection after limit is exceeded\n"
6133 "Restart interval in minutes\n")
6134
6135 DEFUN (no_neighbor_maximum_prefix,
6136 no_neighbor_maximum_prefix_cmd,
6137 "no neighbor <A.B.C.D|X:X::X:X|WORD> maximum-prefix [(1-4294967295) [(1-100)] [restart (1-65535)] [warning-only]]",
6138 NO_STR
6139 NEIGHBOR_STR
6140 NEIGHBOR_ADDR_STR2
6141 "Maximum number of prefixes to accept from this peer\n"
6142 "maximum no. of prefix limit\n"
6143 "Threshold value (%) at which to generate a warning msg\n"
6144 "Restart bgp connection after limit is exceeded\n"
6145 "Restart interval in minutes\n"
6146 "Only give warning message when limit is exceeded\n")
6147 {
6148 int idx_peer = 2;
6149 return peer_maximum_prefix_unset_vty(vty, argv[idx_peer]->arg,
6150 bgp_node_afi(vty),
6151 bgp_node_safi(vty));
6152 }
6153
6154 ALIAS_HIDDEN(
6155 no_neighbor_maximum_prefix, no_neighbor_maximum_prefix_hidden_cmd,
6156 "no neighbor <A.B.C.D|X:X::X:X|WORD> maximum-prefix [(1-4294967295) [(1-100)] [restart (1-65535)] [warning-only]]",
6157 NO_STR NEIGHBOR_STR NEIGHBOR_ADDR_STR2
6158 "Maximum number of prefixes to accept from this peer\n"
6159 "maximum no. of prefix limit\n"
6160 "Threshold value (%) at which to generate a warning msg\n"
6161 "Restart bgp connection after limit is exceeded\n"
6162 "Restart interval in minutes\n"
6163 "Only give warning message when limit is exceeded\n")
6164
6165
6166 /* "neighbor allowas-in" */
6167 DEFUN (neighbor_allowas_in,
6168 neighbor_allowas_in_cmd,
6169 "neighbor <A.B.C.D|X:X::X:X|WORD> allowas-in [<(1-10)|origin>]",
6170 NEIGHBOR_STR
6171 NEIGHBOR_ADDR_STR2
6172 "Accept as-path with my AS present in it\n"
6173 "Number of occurrences of AS number\n"
6174 "Only accept my AS in the as-path if the route was originated in my AS\n")
6175 {
6176 int idx_peer = 1;
6177 int idx_number_origin = 3;
6178 int ret;
6179 int origin = 0;
6180 struct peer *peer;
6181 int allow_num = 0;
6182
6183 peer = peer_and_group_lookup_vty(vty, argv[idx_peer]->arg);
6184 if (!peer)
6185 return CMD_WARNING_CONFIG_FAILED;
6186
6187 if (argc <= idx_number_origin)
6188 allow_num = 3;
6189 else {
6190 if (argv[idx_number_origin]->type == WORD_TKN)
6191 origin = 1;
6192 else
6193 allow_num = atoi(argv[idx_number_origin]->arg);
6194 }
6195
6196 ret = peer_allowas_in_set(peer, bgp_node_afi(vty), bgp_node_safi(vty),
6197 allow_num, origin);
6198
6199 return bgp_vty_return(vty, ret);
6200 }
6201
6202 ALIAS_HIDDEN(
6203 neighbor_allowas_in, neighbor_allowas_in_hidden_cmd,
6204 "neighbor <A.B.C.D|X:X::X:X|WORD> allowas-in [<(1-10)|origin>]",
6205 NEIGHBOR_STR NEIGHBOR_ADDR_STR2
6206 "Accept as-path with my AS present in it\n"
6207 "Number of occurrences of AS number\n"
6208 "Only accept my AS in the as-path if the route was originated in my AS\n")
6209
6210 DEFUN (no_neighbor_allowas_in,
6211 no_neighbor_allowas_in_cmd,
6212 "no neighbor <A.B.C.D|X:X::X:X|WORD> allowas-in [<(1-10)|origin>]",
6213 NO_STR
6214 NEIGHBOR_STR
6215 NEIGHBOR_ADDR_STR2
6216 "allow local ASN appears in aspath attribute\n"
6217 "Number of occurrences of AS number\n"
6218 "Only accept my AS in the as-path if the route was originated in my AS\n")
6219 {
6220 int idx_peer = 2;
6221 int ret;
6222 struct peer *peer;
6223
6224 peer = peer_and_group_lookup_vty(vty, argv[idx_peer]->arg);
6225 if (!peer)
6226 return CMD_WARNING_CONFIG_FAILED;
6227
6228 ret = peer_allowas_in_unset(peer, bgp_node_afi(vty),
6229 bgp_node_safi(vty));
6230
6231 return bgp_vty_return(vty, ret);
6232 }
6233
6234 ALIAS_HIDDEN(
6235 no_neighbor_allowas_in, no_neighbor_allowas_in_hidden_cmd,
6236 "no neighbor <A.B.C.D|X:X::X:X|WORD> allowas-in [<(1-10)|origin>]",
6237 NO_STR NEIGHBOR_STR NEIGHBOR_ADDR_STR2
6238 "allow local ASN appears in aspath attribute\n"
6239 "Number of occurrences of AS number\n"
6240 "Only accept my AS in the as-path if the route was originated in my AS\n")
6241
6242 DEFUN (neighbor_ttl_security,
6243 neighbor_ttl_security_cmd,
6244 "neighbor <A.B.C.D|X:X::X:X|WORD> ttl-security hops (1-254)",
6245 NEIGHBOR_STR
6246 NEIGHBOR_ADDR_STR2
6247 "BGP ttl-security parameters\n"
6248 "Specify the maximum number of hops to the BGP peer\n"
6249 "Number of hops to BGP peer\n")
6250 {
6251 int idx_peer = 1;
6252 int idx_number = 4;
6253 struct peer *peer;
6254 int gtsm_hops;
6255
6256 peer = peer_and_group_lookup_vty(vty, argv[idx_peer]->arg);
6257 if (!peer)
6258 return CMD_WARNING_CONFIG_FAILED;
6259
6260 gtsm_hops = strtoul(argv[idx_number]->arg, NULL, 10);
6261
6262 /*
6263 * If 'neighbor swpX', then this is for directly connected peers,
6264 * we should not accept a ttl-security hops value greater than 1.
6265 */
6266 if (peer->conf_if && (gtsm_hops > 1)) {
6267 vty_out(vty,
6268 "%s is directly connected peer, hops cannot exceed 1\n",
6269 argv[idx_peer]->arg);
6270 return CMD_WARNING_CONFIG_FAILED;
6271 }
6272
6273 return bgp_vty_return(vty, peer_ttl_security_hops_set(peer, gtsm_hops));
6274 }
6275
6276 DEFUN (no_neighbor_ttl_security,
6277 no_neighbor_ttl_security_cmd,
6278 "no neighbor <A.B.C.D|X:X::X:X|WORD> ttl-security hops (1-254)",
6279 NO_STR
6280 NEIGHBOR_STR
6281 NEIGHBOR_ADDR_STR2
6282 "BGP ttl-security parameters\n"
6283 "Specify the maximum number of hops to the BGP peer\n"
6284 "Number of hops to BGP peer\n")
6285 {
6286 int idx_peer = 2;
6287 struct peer *peer;
6288
6289 peer = peer_and_group_lookup_vty(vty, argv[idx_peer]->arg);
6290 if (!peer)
6291 return CMD_WARNING_CONFIG_FAILED;
6292
6293 return bgp_vty_return(vty, peer_ttl_security_hops_unset(peer));
6294 }
6295
6296 DEFUN (neighbor_addpath_tx_all_paths,
6297 neighbor_addpath_tx_all_paths_cmd,
6298 "neighbor <A.B.C.D|X:X::X:X|WORD> addpath-tx-all-paths",
6299 NEIGHBOR_STR
6300 NEIGHBOR_ADDR_STR2
6301 "Use addpath to advertise all paths to a neighbor\n")
6302 {
6303 int idx_peer = 1;
6304 struct peer *peer;
6305
6306 peer = peer_and_group_lookup_vty(vty, argv[idx_peer]->arg);
6307 if (!peer)
6308 return CMD_WARNING_CONFIG_FAILED;
6309
6310 bgp_addpath_set_peer_type(peer, bgp_node_afi(vty), bgp_node_safi(vty),
6311 BGP_ADDPATH_ALL);
6312 return CMD_SUCCESS;
6313 }
6314
6315 ALIAS_HIDDEN(neighbor_addpath_tx_all_paths,
6316 neighbor_addpath_tx_all_paths_hidden_cmd,
6317 "neighbor <A.B.C.D|X:X::X:X|WORD> addpath-tx-all-paths",
6318 NEIGHBOR_STR NEIGHBOR_ADDR_STR2
6319 "Use addpath to advertise all paths to a neighbor\n")
6320
6321 DEFUN (no_neighbor_addpath_tx_all_paths,
6322 no_neighbor_addpath_tx_all_paths_cmd,
6323 "no neighbor <A.B.C.D|X:X::X:X|WORD> addpath-tx-all-paths",
6324 NO_STR
6325 NEIGHBOR_STR
6326 NEIGHBOR_ADDR_STR2
6327 "Use addpath to advertise all paths to a neighbor\n")
6328 {
6329 int idx_peer = 2;
6330 struct peer *peer;
6331
6332 peer = peer_and_group_lookup_vty(vty, argv[idx_peer]->arg);
6333 if (!peer)
6334 return CMD_WARNING_CONFIG_FAILED;
6335
6336 if (peer->addpath_type[bgp_node_afi(vty)][bgp_node_safi(vty)]
6337 != BGP_ADDPATH_ALL) {
6338 vty_out(vty,
6339 "%% Peer not currently configured to transmit all paths.");
6340 return CMD_WARNING_CONFIG_FAILED;
6341 }
6342
6343 bgp_addpath_set_peer_type(peer, bgp_node_afi(vty), bgp_node_safi(vty),
6344 BGP_ADDPATH_NONE);
6345
6346 return CMD_SUCCESS;
6347 }
6348
6349 ALIAS_HIDDEN(no_neighbor_addpath_tx_all_paths,
6350 no_neighbor_addpath_tx_all_paths_hidden_cmd,
6351 "no neighbor <A.B.C.D|X:X::X:X|WORD> addpath-tx-all-paths",
6352 NO_STR NEIGHBOR_STR NEIGHBOR_ADDR_STR2
6353 "Use addpath to advertise all paths to a neighbor\n")
6354
6355 DEFUN (neighbor_addpath_tx_bestpath_per_as,
6356 neighbor_addpath_tx_bestpath_per_as_cmd,
6357 "neighbor <A.B.C.D|X:X::X:X|WORD> addpath-tx-bestpath-per-AS",
6358 NEIGHBOR_STR
6359 NEIGHBOR_ADDR_STR2
6360 "Use addpath to advertise the bestpath per each neighboring AS\n")
6361 {
6362 int idx_peer = 1;
6363 struct peer *peer;
6364
6365 peer = peer_and_group_lookup_vty(vty, argv[idx_peer]->arg);
6366 if (!peer)
6367 return CMD_WARNING_CONFIG_FAILED;
6368
6369 bgp_addpath_set_peer_type(peer, bgp_node_afi(vty), bgp_node_safi(vty),
6370 BGP_ADDPATH_BEST_PER_AS);
6371
6372 return CMD_SUCCESS;
6373 }
6374
6375 ALIAS_HIDDEN(neighbor_addpath_tx_bestpath_per_as,
6376 neighbor_addpath_tx_bestpath_per_as_hidden_cmd,
6377 "neighbor <A.B.C.D|X:X::X:X|WORD> addpath-tx-bestpath-per-AS",
6378 NEIGHBOR_STR NEIGHBOR_ADDR_STR2
6379 "Use addpath to advertise the bestpath per each neighboring AS\n")
6380
6381 DEFUN (no_neighbor_addpath_tx_bestpath_per_as,
6382 no_neighbor_addpath_tx_bestpath_per_as_cmd,
6383 "no neighbor <A.B.C.D|X:X::X:X|WORD> addpath-tx-bestpath-per-AS",
6384 NO_STR
6385 NEIGHBOR_STR
6386 NEIGHBOR_ADDR_STR2
6387 "Use addpath to advertise the bestpath per each neighboring AS\n")
6388 {
6389 int idx_peer = 2;
6390 struct peer *peer;
6391
6392 peer = peer_and_group_lookup_vty(vty, argv[idx_peer]->arg);
6393 if (!peer)
6394 return CMD_WARNING_CONFIG_FAILED;
6395
6396 if (peer->addpath_type[bgp_node_afi(vty)][bgp_node_safi(vty)]
6397 != BGP_ADDPATH_BEST_PER_AS) {
6398 vty_out(vty,
6399 "%% Peer not currently configured to transmit all best path per as.");
6400 return CMD_WARNING_CONFIG_FAILED;
6401 }
6402
6403 bgp_addpath_set_peer_type(peer, bgp_node_afi(vty), bgp_node_safi(vty),
6404 BGP_ADDPATH_NONE);
6405
6406 return CMD_SUCCESS;
6407 }
6408
6409 ALIAS_HIDDEN(no_neighbor_addpath_tx_bestpath_per_as,
6410 no_neighbor_addpath_tx_bestpath_per_as_hidden_cmd,
6411 "no neighbor <A.B.C.D|X:X::X:X|WORD> addpath-tx-bestpath-per-AS",
6412 NO_STR NEIGHBOR_STR NEIGHBOR_ADDR_STR2
6413 "Use addpath to advertise the bestpath per each neighboring AS\n")
6414
6415 static int set_ecom_list(struct vty *vty, int argc, struct cmd_token **argv,
6416 struct ecommunity **list)
6417 {
6418 struct ecommunity *ecom = NULL;
6419 struct ecommunity *ecomadd;
6420
6421 for (; argc; --argc, ++argv) {
6422
6423 ecomadd = ecommunity_str2com(argv[0]->arg,
6424 ECOMMUNITY_ROUTE_TARGET, 0);
6425 if (!ecomadd) {
6426 vty_out(vty, "Malformed community-list value\n");
6427 if (ecom)
6428 ecommunity_free(&ecom);
6429 return CMD_WARNING_CONFIG_FAILED;
6430 }
6431
6432 if (ecom) {
6433 ecommunity_merge(ecom, ecomadd);
6434 ecommunity_free(&ecomadd);
6435 } else {
6436 ecom = ecomadd;
6437 }
6438 }
6439
6440 if (*list) {
6441 ecommunity_free(&*list);
6442 }
6443 *list = ecom;
6444
6445 return CMD_SUCCESS;
6446 }
6447
6448 /*
6449 * v2vimport is true if we are handling a `import vrf ...` command
6450 */
6451 static afi_t vpn_policy_getafi(struct vty *vty, struct bgp *bgp, bool v2vimport)
6452 {
6453 afi_t afi;
6454
6455 switch (vty->node) {
6456 case BGP_IPV4_NODE:
6457 afi = AFI_IP;
6458 break;
6459 case BGP_IPV6_NODE:
6460 afi = AFI_IP6;
6461 break;
6462 default:
6463 vty_out(vty,
6464 "%% context error: valid only in address-family <ipv4|ipv6> unicast block\n");
6465 return AFI_MAX;
6466 }
6467
6468 if (!v2vimport) {
6469 if (CHECK_FLAG(bgp->af_flags[afi][SAFI_UNICAST],
6470 BGP_CONFIG_VRF_TO_VRF_IMPORT)
6471 || CHECK_FLAG(bgp->af_flags[afi][SAFI_UNICAST],
6472 BGP_CONFIG_VRF_TO_VRF_EXPORT)) {
6473 vty_out(vty,
6474 "%% error: Please unconfigure import vrf commands before using vpn commands\n");
6475 return AFI_MAX;
6476 }
6477 } else {
6478 if (CHECK_FLAG(bgp->af_flags[afi][SAFI_UNICAST],
6479 BGP_CONFIG_VRF_TO_MPLSVPN_EXPORT)
6480 || CHECK_FLAG(bgp->af_flags[afi][SAFI_UNICAST],
6481 BGP_CONFIG_MPLSVPN_TO_VRF_IMPORT)) {
6482 vty_out(vty,
6483 "%% error: Please unconfigure vpn to vrf commands before using import vrf commands\n");
6484 return AFI_MAX;
6485 }
6486 }
6487 return afi;
6488 }
6489
6490 DEFPY (af_rd_vpn_export,
6491 af_rd_vpn_export_cmd,
6492 "[no] rd vpn export ASN:NN_OR_IP-ADDRESS:NN$rd_str",
6493 NO_STR
6494 "Specify route distinguisher\n"
6495 "Between current address-family and vpn\n"
6496 "For routes leaked from current address-family to vpn\n"
6497 "Route Distinguisher (<as-number>:<number> | <ip-address>:<number>)\n")
6498 {
6499 VTY_DECLVAR_CONTEXT(bgp, bgp);
6500 struct prefix_rd prd;
6501 int ret;
6502 afi_t afi;
6503 int idx = 0;
6504 int yes = 1;
6505
6506 if (argv_find(argv, argc, "no", &idx))
6507 yes = 0;
6508
6509 if (yes) {
6510 ret = str2prefix_rd(rd_str, &prd);
6511 if (!ret) {
6512 vty_out(vty, "%% Malformed rd\n");
6513 return CMD_WARNING_CONFIG_FAILED;
6514 }
6515 }
6516
6517 afi = vpn_policy_getafi(vty, bgp, false);
6518 if (afi == AFI_MAX)
6519 return CMD_WARNING_CONFIG_FAILED;
6520
6521 /*
6522 * pre-change: un-export vpn routes (vpn->vrf routes unaffected)
6523 */
6524 vpn_leak_prechange(BGP_VPN_POLICY_DIR_TOVPN, afi,
6525 bgp_get_default(), bgp);
6526
6527 if (yes) {
6528 bgp->vpn_policy[afi].tovpn_rd = prd;
6529 SET_FLAG(bgp->vpn_policy[afi].flags,
6530 BGP_VPN_POLICY_TOVPN_RD_SET);
6531 } else {
6532 UNSET_FLAG(bgp->vpn_policy[afi].flags,
6533 BGP_VPN_POLICY_TOVPN_RD_SET);
6534 }
6535
6536 /* post-change: re-export vpn routes */
6537 vpn_leak_postchange(BGP_VPN_POLICY_DIR_TOVPN, afi,
6538 bgp_get_default(), bgp);
6539
6540 return CMD_SUCCESS;
6541 }
6542
6543 ALIAS (af_rd_vpn_export,
6544 af_no_rd_vpn_export_cmd,
6545 "no rd vpn export",
6546 NO_STR
6547 "Specify route distinguisher\n"
6548 "Between current address-family and vpn\n"
6549 "For routes leaked from current address-family to vpn\n")
6550
6551 DEFPY (af_label_vpn_export,
6552 af_label_vpn_export_cmd,
6553 "[no] label vpn export <(0-1048575)$label_val|auto$label_auto>",
6554 NO_STR
6555 "label value for VRF\n"
6556 "Between current address-family and vpn\n"
6557 "For routes leaked from current address-family to vpn\n"
6558 "Label Value <0-1048575>\n"
6559 "Automatically assign a label\n")
6560 {
6561 VTY_DECLVAR_CONTEXT(bgp, bgp);
6562 mpls_label_t label = MPLS_LABEL_NONE;
6563 afi_t afi;
6564 int idx = 0;
6565 int yes = 1;
6566
6567 if (argv_find(argv, argc, "no", &idx))
6568 yes = 0;
6569
6570 /* If "no ...", squash trailing parameter */
6571 if (!yes)
6572 label_auto = NULL;
6573
6574 if (yes) {
6575 if (!label_auto)
6576 label = label_val; /* parser should force unsigned */
6577 }
6578
6579 afi = vpn_policy_getafi(vty, bgp, false);
6580 if (afi == AFI_MAX)
6581 return CMD_WARNING_CONFIG_FAILED;
6582
6583
6584 if (label_auto && CHECK_FLAG(bgp->vpn_policy[afi].flags,
6585 BGP_VPN_POLICY_TOVPN_LABEL_AUTO))
6586 /* no change */
6587 return CMD_SUCCESS;
6588
6589 /*
6590 * pre-change: un-export vpn routes (vpn->vrf routes unaffected)
6591 */
6592 vpn_leak_prechange(BGP_VPN_POLICY_DIR_TOVPN, afi,
6593 bgp_get_default(), bgp);
6594
6595 if (!label_auto && CHECK_FLAG(bgp->vpn_policy[afi].flags,
6596 BGP_VPN_POLICY_TOVPN_LABEL_AUTO)) {
6597
6598 if (bgp->vpn_policy[afi].tovpn_label != MPLS_LABEL_NONE) {
6599
6600 /*
6601 * label has previously been automatically
6602 * assigned by labelpool: release it
6603 *
6604 * NB if tovpn_label == MPLS_LABEL_NONE it
6605 * means the automatic assignment is in flight
6606 * and therefore the labelpool callback must
6607 * detect that the auto label is not needed.
6608 */
6609
6610 bgp_lp_release(LP_TYPE_VRF,
6611 &bgp->vpn_policy[afi],
6612 bgp->vpn_policy[afi].tovpn_label);
6613 }
6614 UNSET_FLAG(bgp->vpn_policy[afi].flags,
6615 BGP_VPN_POLICY_TOVPN_LABEL_AUTO);
6616 }
6617
6618 bgp->vpn_policy[afi].tovpn_label = label;
6619 if (label_auto) {
6620 SET_FLAG(bgp->vpn_policy[afi].flags,
6621 BGP_VPN_POLICY_TOVPN_LABEL_AUTO);
6622 bgp_lp_get(LP_TYPE_VRF, &bgp->vpn_policy[afi],
6623 vpn_leak_label_callback);
6624 }
6625
6626 /* post-change: re-export vpn routes */
6627 vpn_leak_postchange(BGP_VPN_POLICY_DIR_TOVPN, afi,
6628 bgp_get_default(), bgp);
6629
6630 return CMD_SUCCESS;
6631 }
6632
6633 ALIAS (af_label_vpn_export,
6634 af_no_label_vpn_export_cmd,
6635 "no label vpn export",
6636 NO_STR
6637 "label value for VRF\n"
6638 "Between current address-family and vpn\n"
6639 "For routes leaked from current address-family to vpn\n")
6640
6641 DEFPY (af_nexthop_vpn_export,
6642 af_nexthop_vpn_export_cmd,
6643 "[no] nexthop vpn export <A.B.C.D|X:X::X:X>$nexthop_str",
6644 NO_STR
6645 "Specify next hop to use for VRF advertised prefixes\n"
6646 "Between current address-family and vpn\n"
6647 "For routes leaked from current address-family to vpn\n"
6648 "IPv4 prefix\n"
6649 "IPv6 prefix\n")
6650 {
6651 VTY_DECLVAR_CONTEXT(bgp, bgp);
6652 afi_t afi;
6653 struct prefix p;
6654 int idx = 0;
6655 int yes = 1;
6656
6657 if (argv_find(argv, argc, "no", &idx))
6658 yes = 0;
6659
6660 if (yes) {
6661 if (!sockunion2hostprefix(nexthop_str, &p))
6662 return CMD_WARNING_CONFIG_FAILED;
6663 }
6664
6665 afi = vpn_policy_getafi(vty, bgp, false);
6666 if (afi == AFI_MAX)
6667 return CMD_WARNING_CONFIG_FAILED;
6668
6669 /*
6670 * pre-change: un-export vpn routes (vpn->vrf routes unaffected)
6671 */
6672 vpn_leak_prechange(BGP_VPN_POLICY_DIR_TOVPN, afi,
6673 bgp_get_default(), bgp);
6674
6675 if (yes) {
6676 bgp->vpn_policy[afi].tovpn_nexthop = p;
6677 SET_FLAG(bgp->vpn_policy[afi].flags,
6678 BGP_VPN_POLICY_TOVPN_NEXTHOP_SET);
6679 } else {
6680 UNSET_FLAG(bgp->vpn_policy[afi].flags,
6681 BGP_VPN_POLICY_TOVPN_NEXTHOP_SET);
6682 }
6683
6684 /* post-change: re-export vpn routes */
6685 vpn_leak_postchange(BGP_VPN_POLICY_DIR_TOVPN, afi,
6686 bgp_get_default(), bgp);
6687
6688 return CMD_SUCCESS;
6689 }
6690
6691 ALIAS (af_nexthop_vpn_export,
6692 af_no_nexthop_vpn_export_cmd,
6693 "no nexthop vpn export",
6694 NO_STR
6695 "Specify next hop to use for VRF advertised prefixes\n"
6696 "Between current address-family and vpn\n"
6697 "For routes leaked from current address-family to vpn\n")
6698
6699 static int vpn_policy_getdirs(struct vty *vty, const char *dstr, int *dodir)
6700 {
6701 if (!strcmp(dstr, "import")) {
6702 dodir[BGP_VPN_POLICY_DIR_FROMVPN] = 1;
6703 } else if (!strcmp(dstr, "export")) {
6704 dodir[BGP_VPN_POLICY_DIR_TOVPN] = 1;
6705 } else if (!strcmp(dstr, "both")) {
6706 dodir[BGP_VPN_POLICY_DIR_FROMVPN] = 1;
6707 dodir[BGP_VPN_POLICY_DIR_TOVPN] = 1;
6708 } else {
6709 vty_out(vty, "%% direction parse error\n");
6710 return CMD_WARNING_CONFIG_FAILED;
6711 }
6712 return CMD_SUCCESS;
6713 }
6714
6715 DEFPY (af_rt_vpn_imexport,
6716 af_rt_vpn_imexport_cmd,
6717 "[no] <rt|route-target> vpn <import|export|both>$direction_str RTLIST...",
6718 NO_STR
6719 "Specify route target list\n"
6720 "Specify route target list\n"
6721 "Between current address-family and vpn\n"
6722 "For routes leaked from vpn to current address-family: match any\n"
6723 "For routes leaked from current address-family to vpn: set\n"
6724 "both import: match any and export: set\n"
6725 "Space separated route target list (A.B.C.D:MN|EF:OPQR|GHJK:MN)\n")
6726 {
6727 VTY_DECLVAR_CONTEXT(bgp, bgp);
6728 int ret;
6729 struct ecommunity *ecom = NULL;
6730 int dodir[BGP_VPN_POLICY_DIR_MAX] = {0};
6731 vpn_policy_direction_t dir;
6732 afi_t afi;
6733 int idx = 0;
6734 int yes = 1;
6735
6736 if (argv_find(argv, argc, "no", &idx))
6737 yes = 0;
6738
6739 afi = vpn_policy_getafi(vty, bgp, false);
6740 if (afi == AFI_MAX)
6741 return CMD_WARNING_CONFIG_FAILED;
6742
6743 ret = vpn_policy_getdirs(vty, direction_str, dodir);
6744 if (ret != CMD_SUCCESS)
6745 return ret;
6746
6747 if (yes) {
6748 if (!argv_find(argv, argc, "RTLIST", &idx)) {
6749 vty_out(vty, "%% Missing RTLIST\n");
6750 return CMD_WARNING_CONFIG_FAILED;
6751 }
6752 ret = set_ecom_list(vty, argc - idx, argv + idx, &ecom);
6753 if (ret != CMD_SUCCESS) {
6754 return ret;
6755 }
6756 }
6757
6758 for (dir = 0; dir < BGP_VPN_POLICY_DIR_MAX; ++dir) {
6759 if (!dodir[dir])
6760 continue;
6761
6762 vpn_leak_prechange(dir, afi, bgp_get_default(), bgp);
6763
6764 if (yes) {
6765 if (bgp->vpn_policy[afi].rtlist[dir])
6766 ecommunity_free(
6767 &bgp->vpn_policy[afi].rtlist[dir]);
6768 bgp->vpn_policy[afi].rtlist[dir] =
6769 ecommunity_dup(ecom);
6770 } else {
6771 if (bgp->vpn_policy[afi].rtlist[dir])
6772 ecommunity_free(
6773 &bgp->vpn_policy[afi].rtlist[dir]);
6774 bgp->vpn_policy[afi].rtlist[dir] = NULL;
6775 }
6776
6777 vpn_leak_postchange(dir, afi, bgp_get_default(), bgp);
6778 }
6779
6780 if (ecom)
6781 ecommunity_free(&ecom);
6782
6783 return CMD_SUCCESS;
6784 }
6785
6786 ALIAS (af_rt_vpn_imexport,
6787 af_no_rt_vpn_imexport_cmd,
6788 "no <rt|route-target> vpn <import|export|both>$direction_str",
6789 NO_STR
6790 "Specify route target list\n"
6791 "Specify route target list\n"
6792 "Between current address-family and vpn\n"
6793 "For routes leaked from vpn to current address-family\n"
6794 "For routes leaked from current address-family to vpn\n"
6795 "both import and export\n")
6796
6797 DEFPY (af_route_map_vpn_imexport,
6798 af_route_map_vpn_imexport_cmd,
6799 /* future: "route-map <vpn|evpn|vrf NAME> <import|export> RMAP" */
6800 "[no] route-map vpn <import|export>$direction_str RMAP$rmap_str",
6801 NO_STR
6802 "Specify route map\n"
6803 "Between current address-family and vpn\n"
6804 "For routes leaked from vpn to current address-family\n"
6805 "For routes leaked from current address-family to vpn\n"
6806 "name of route-map\n")
6807 {
6808 VTY_DECLVAR_CONTEXT(bgp, bgp);
6809 int ret;
6810 int dodir[BGP_VPN_POLICY_DIR_MAX] = {0};
6811 vpn_policy_direction_t dir;
6812 afi_t afi;
6813 int idx = 0;
6814 int yes = 1;
6815
6816 if (argv_find(argv, argc, "no", &idx))
6817 yes = 0;
6818
6819 afi = vpn_policy_getafi(vty, bgp, false);
6820 if (afi == AFI_MAX)
6821 return CMD_WARNING_CONFIG_FAILED;
6822
6823 ret = vpn_policy_getdirs(vty, direction_str, dodir);
6824 if (ret != CMD_SUCCESS)
6825 return ret;
6826
6827 for (dir = 0; dir < BGP_VPN_POLICY_DIR_MAX; ++dir) {
6828 if (!dodir[dir])
6829 continue;
6830
6831 vpn_leak_prechange(dir, afi, bgp_get_default(), bgp);
6832
6833 if (yes) {
6834 if (bgp->vpn_policy[afi].rmap_name[dir])
6835 XFREE(MTYPE_ROUTE_MAP_NAME,
6836 bgp->vpn_policy[afi].rmap_name[dir]);
6837 bgp->vpn_policy[afi].rmap_name[dir] = XSTRDUP(
6838 MTYPE_ROUTE_MAP_NAME, rmap_str);
6839 bgp->vpn_policy[afi].rmap[dir] =
6840 route_map_lookup_warn_noexist(vty, rmap_str);
6841 if (!bgp->vpn_policy[afi].rmap[dir])
6842 return CMD_SUCCESS;
6843 } else {
6844 if (bgp->vpn_policy[afi].rmap_name[dir])
6845 XFREE(MTYPE_ROUTE_MAP_NAME,
6846 bgp->vpn_policy[afi].rmap_name[dir]);
6847 bgp->vpn_policy[afi].rmap_name[dir] = NULL;
6848 bgp->vpn_policy[afi].rmap[dir] = NULL;
6849 }
6850
6851 vpn_leak_postchange(dir, afi, bgp_get_default(), bgp);
6852 }
6853
6854 return CMD_SUCCESS;
6855 }
6856
6857 ALIAS (af_route_map_vpn_imexport,
6858 af_no_route_map_vpn_imexport_cmd,
6859 "no route-map vpn <import|export>$direction_str",
6860 NO_STR
6861 "Specify route map\n"
6862 "Between current address-family and vpn\n"
6863 "For routes leaked from vpn to current address-family\n"
6864 "For routes leaked from current address-family to vpn\n")
6865
6866 DEFPY(af_import_vrf_route_map, af_import_vrf_route_map_cmd,
6867 "[no] import vrf route-map RMAP$rmap_str",
6868 NO_STR
6869 "Import routes from another VRF\n"
6870 "Vrf routes being filtered\n"
6871 "Specify route map\n"
6872 "name of route-map\n")
6873 {
6874 VTY_DECLVAR_CONTEXT(bgp, bgp);
6875 vpn_policy_direction_t dir = BGP_VPN_POLICY_DIR_FROMVPN;
6876 afi_t afi;
6877 int idx = 0;
6878 int yes = 1;
6879 struct bgp *bgp_default;
6880
6881 if (argv_find(argv, argc, "no", &idx))
6882 yes = 0;
6883
6884 afi = vpn_policy_getafi(vty, bgp, true);
6885 if (afi == AFI_MAX)
6886 return CMD_WARNING_CONFIG_FAILED;
6887
6888 bgp_default = bgp_get_default();
6889 if (!bgp_default) {
6890 int32_t ret;
6891 as_t as = bgp->as;
6892
6893 /* Auto-create assuming the same AS */
6894 ret = bgp_get(&bgp_default, &as, NULL,
6895 BGP_INSTANCE_TYPE_DEFAULT);
6896
6897 if (ret) {
6898 vty_out(vty,
6899 "VRF default is not configured as a bgp instance\n");
6900 return CMD_WARNING;
6901 }
6902 }
6903
6904 vpn_leak_prechange(dir, afi, bgp_get_default(), bgp);
6905
6906 if (yes) {
6907 if (bgp->vpn_policy[afi].rmap_name[dir])
6908 XFREE(MTYPE_ROUTE_MAP_NAME,
6909 bgp->vpn_policy[afi].rmap_name[dir]);
6910 bgp->vpn_policy[afi].rmap_name[dir] =
6911 XSTRDUP(MTYPE_ROUTE_MAP_NAME, rmap_str);
6912 bgp->vpn_policy[afi].rmap[dir] =
6913 route_map_lookup_warn_noexist(vty, rmap_str);
6914 if (!bgp->vpn_policy[afi].rmap[dir])
6915 return CMD_SUCCESS;
6916 } else {
6917 if (bgp->vpn_policy[afi].rmap_name[dir])
6918 XFREE(MTYPE_ROUTE_MAP_NAME,
6919 bgp->vpn_policy[afi].rmap_name[dir]);
6920 bgp->vpn_policy[afi].rmap_name[dir] = NULL;
6921 bgp->vpn_policy[afi].rmap[dir] = NULL;
6922 }
6923
6924 vpn_leak_postchange(dir, afi, bgp_get_default(), bgp);
6925
6926 return CMD_SUCCESS;
6927 }
6928
6929 ALIAS(af_import_vrf_route_map, af_no_import_vrf_route_map_cmd,
6930 "no import vrf route-map",
6931 NO_STR
6932 "Import routes from another VRF\n"
6933 "Vrf routes being filtered\n"
6934 "Specify route map\n")
6935
6936 DEFPY(bgp_imexport_vrf, bgp_imexport_vrf_cmd,
6937 "[no] import vrf VIEWVRFNAME$import_name",
6938 NO_STR
6939 "Import routes from another VRF\n"
6940 "VRF to import from\n"
6941 "The name of the VRF\n")
6942 {
6943 VTY_DECLVAR_CONTEXT(bgp, bgp);
6944 struct listnode *node;
6945 struct bgp *vrf_bgp, *bgp_default;
6946 int32_t ret = 0;
6947 as_t as = bgp->as;
6948 bool remove = false;
6949 int32_t idx = 0;
6950 char *vname;
6951 enum bgp_instance_type bgp_type = BGP_INSTANCE_TYPE_VRF;
6952 safi_t safi;
6953 afi_t afi;
6954
6955 if (import_name == NULL) {
6956 vty_out(vty, "%% Missing import name\n");
6957 return CMD_WARNING;
6958 }
6959
6960 if (argv_find(argv, argc, "no", &idx))
6961 remove = true;
6962
6963 afi = vpn_policy_getafi(vty, bgp, true);
6964 if (afi == AFI_MAX)
6965 return CMD_WARNING_CONFIG_FAILED;
6966
6967 safi = bgp_node_safi(vty);
6968
6969 if (((BGP_INSTANCE_TYPE_DEFAULT == bgp->inst_type)
6970 && (strcmp(import_name, VRF_DEFAULT_NAME) == 0))
6971 || (bgp->name && (strcmp(import_name, bgp->name) == 0))) {
6972 vty_out(vty, "%% Cannot %s vrf %s into itself\n",
6973 remove ? "unimport" : "import", import_name);
6974 return CMD_WARNING;
6975 }
6976
6977 bgp_default = bgp_get_default();
6978 if (!bgp_default) {
6979 /* Auto-create assuming the same AS */
6980 ret = bgp_get(&bgp_default, &as, NULL,
6981 BGP_INSTANCE_TYPE_DEFAULT);
6982
6983 if (ret) {
6984 vty_out(vty,
6985 "VRF default is not configured as a bgp instance\n");
6986 return CMD_WARNING;
6987 }
6988 }
6989
6990 vrf_bgp = bgp_lookup_by_name(import_name);
6991 if (!vrf_bgp) {
6992 if (strcmp(import_name, VRF_DEFAULT_NAME) == 0)
6993 vrf_bgp = bgp_default;
6994 else
6995 /* Auto-create assuming the same AS */
6996 ret = bgp_get(&vrf_bgp, &as, import_name, bgp_type);
6997
6998 if (ret) {
6999 vty_out(vty,
7000 "VRF %s is not configured as a bgp instance\n",
7001 import_name);
7002 return CMD_WARNING;
7003 }
7004 }
7005
7006 if (remove) {
7007 vrf_unimport_from_vrf(bgp, vrf_bgp, afi, safi);
7008 } else {
7009 /* Already importing from "import_vrf"? */
7010 for (ALL_LIST_ELEMENTS_RO(bgp->vpn_policy[afi].import_vrf, node,
7011 vname)) {
7012 if (strcmp(vname, import_name) == 0)
7013 return CMD_WARNING;
7014 }
7015
7016 vrf_import_from_vrf(bgp, vrf_bgp, afi, safi);
7017 }
7018
7019 return CMD_SUCCESS;
7020 }
7021
7022 /* This command is valid only in a bgp vrf instance or the default instance */
7023 DEFPY (bgp_imexport_vpn,
7024 bgp_imexport_vpn_cmd,
7025 "[no] <import|export>$direction_str vpn",
7026 NO_STR
7027 "Import routes to this address-family\n"
7028 "Export routes from this address-family\n"
7029 "to/from default instance VPN RIB\n")
7030 {
7031 VTY_DECLVAR_CONTEXT(bgp, bgp);
7032 int previous_state;
7033 afi_t afi;
7034 safi_t safi;
7035 int idx = 0;
7036 int yes = 1;
7037 int flag;
7038 vpn_policy_direction_t dir;
7039
7040 if (argv_find(argv, argc, "no", &idx))
7041 yes = 0;
7042
7043 if (BGP_INSTANCE_TYPE_VRF != bgp->inst_type &&
7044 BGP_INSTANCE_TYPE_DEFAULT != bgp->inst_type) {
7045
7046 vty_out(vty, "%% import|export vpn valid only for bgp vrf or default instance\n");
7047 return CMD_WARNING_CONFIG_FAILED;
7048 }
7049
7050 afi = bgp_node_afi(vty);
7051 safi = bgp_node_safi(vty);
7052 if ((SAFI_UNICAST != safi) || ((AFI_IP != afi) && (AFI_IP6 != afi))) {
7053 vty_out(vty, "%% import|export vpn valid only for unicast ipv4|ipv6\n");
7054 return CMD_WARNING_CONFIG_FAILED;
7055 }
7056
7057 if (!strcmp(direction_str, "import")) {
7058 flag = BGP_CONFIG_MPLSVPN_TO_VRF_IMPORT;
7059 dir = BGP_VPN_POLICY_DIR_FROMVPN;
7060 } else if (!strcmp(direction_str, "export")) {
7061 flag = BGP_CONFIG_VRF_TO_MPLSVPN_EXPORT;
7062 dir = BGP_VPN_POLICY_DIR_TOVPN;
7063 } else {
7064 vty_out(vty, "%% unknown direction %s\n", direction_str);
7065 return CMD_WARNING_CONFIG_FAILED;
7066 }
7067
7068 previous_state = CHECK_FLAG(bgp->af_flags[afi][safi], flag);
7069
7070 if (yes) {
7071 SET_FLAG(bgp->af_flags[afi][safi], flag);
7072 if (!previous_state) {
7073 /* trigger export current vrf */
7074 vpn_leak_postchange(dir, afi, bgp_get_default(), bgp);
7075 }
7076 } else {
7077 if (previous_state) {
7078 /* trigger un-export current vrf */
7079 vpn_leak_prechange(dir, afi, bgp_get_default(), bgp);
7080 }
7081 UNSET_FLAG(bgp->af_flags[afi][safi], flag);
7082 }
7083
7084 return CMD_SUCCESS;
7085 }
7086
7087 DEFPY (af_routetarget_import,
7088 af_routetarget_import_cmd,
7089 "[no] <rt|route-target> redirect import RTLIST...",
7090 NO_STR
7091 "Specify route target list\n"
7092 "Specify route target list\n"
7093 "Flow-spec redirect type route target\n"
7094 "Import routes to this address-family\n"
7095 "Space separated route target list (A.B.C.D:MN|EF:OPQR|GHJK:MN)\n")
7096 {
7097 VTY_DECLVAR_CONTEXT(bgp, bgp);
7098 int ret;
7099 struct ecommunity *ecom = NULL;
7100 afi_t afi;
7101 int idx = 0;
7102 int yes = 1;
7103
7104 if (argv_find(argv, argc, "no", &idx))
7105 yes = 0;
7106
7107 afi = vpn_policy_getafi(vty, bgp, false);
7108 if (afi == AFI_MAX)
7109 return CMD_WARNING_CONFIG_FAILED;
7110
7111 if (yes) {
7112 if (!argv_find(argv, argc, "RTLIST", &idx)) {
7113 vty_out(vty, "%% Missing RTLIST\n");
7114 return CMD_WARNING_CONFIG_FAILED;
7115 }
7116 ret = set_ecom_list(vty, argc - idx, argv + idx, &ecom);
7117 if (ret != CMD_SUCCESS)
7118 return ret;
7119 }
7120
7121 if (yes) {
7122 if (bgp->vpn_policy[afi].import_redirect_rtlist)
7123 ecommunity_free(&bgp->vpn_policy[afi]
7124 .import_redirect_rtlist);
7125 bgp->vpn_policy[afi].import_redirect_rtlist =
7126 ecommunity_dup(ecom);
7127 } else {
7128 if (bgp->vpn_policy[afi].import_redirect_rtlist)
7129 ecommunity_free(&bgp->vpn_policy[afi]
7130 .import_redirect_rtlist);
7131 bgp->vpn_policy[afi].import_redirect_rtlist = NULL;
7132 }
7133
7134 if (ecom)
7135 ecommunity_free(&ecom);
7136
7137 return CMD_SUCCESS;
7138 }
7139
7140 DEFUN_NOSH (address_family_ipv4_safi,
7141 address_family_ipv4_safi_cmd,
7142 "address-family ipv4 [<unicast|multicast|vpn|labeled-unicast|flowspec>]",
7143 "Enter Address Family command mode\n"
7144 "Address Family\n"
7145 BGP_SAFI_WITH_LABEL_HELP_STR)
7146 {
7147
7148 if (argc == 3) {
7149 VTY_DECLVAR_CONTEXT(bgp, bgp);
7150 safi_t safi = bgp_vty_safi_from_str(argv[2]->text);
7151 if (bgp->inst_type != BGP_INSTANCE_TYPE_DEFAULT
7152 && safi != SAFI_UNICAST && safi != SAFI_MULTICAST
7153 && safi != SAFI_EVPN) {
7154 vty_out(vty,
7155 "Only Unicast/Multicast/EVPN SAFIs supported in non-core instances.\n");
7156 return CMD_WARNING_CONFIG_FAILED;
7157 }
7158 vty->node = bgp_node_type(AFI_IP, safi);
7159 } else
7160 vty->node = BGP_IPV4_NODE;
7161
7162 return CMD_SUCCESS;
7163 }
7164
7165 DEFUN_NOSH (address_family_ipv6_safi,
7166 address_family_ipv6_safi_cmd,
7167 "address-family ipv6 [<unicast|multicast|vpn|labeled-unicast|flowspec>]",
7168 "Enter Address Family command mode\n"
7169 "Address Family\n"
7170 BGP_SAFI_WITH_LABEL_HELP_STR)
7171 {
7172 if (argc == 3) {
7173 VTY_DECLVAR_CONTEXT(bgp, bgp);
7174 safi_t safi = bgp_vty_safi_from_str(argv[2]->text);
7175 if (bgp->inst_type != BGP_INSTANCE_TYPE_DEFAULT
7176 && safi != SAFI_UNICAST && safi != SAFI_MULTICAST
7177 && safi != SAFI_EVPN) {
7178 vty_out(vty,
7179 "Only Unicast/Multicast/EVPN SAFIs supported in non-core instances.\n");
7180 return CMD_WARNING_CONFIG_FAILED;
7181 }
7182 vty->node = bgp_node_type(AFI_IP6, safi);
7183 } else
7184 vty->node = BGP_IPV6_NODE;
7185
7186 return CMD_SUCCESS;
7187 }
7188
7189 #ifdef KEEP_OLD_VPN_COMMANDS
7190 DEFUN_NOSH (address_family_vpnv4,
7191 address_family_vpnv4_cmd,
7192 "address-family vpnv4 [unicast]",
7193 "Enter Address Family command mode\n"
7194 "Address Family\n"
7195 "Address Family modifier\n")
7196 {
7197 vty->node = BGP_VPNV4_NODE;
7198 return CMD_SUCCESS;
7199 }
7200
7201 DEFUN_NOSH (address_family_vpnv6,
7202 address_family_vpnv6_cmd,
7203 "address-family vpnv6 [unicast]",
7204 "Enter Address Family command mode\n"
7205 "Address Family\n"
7206 "Address Family modifier\n")
7207 {
7208 vty->node = BGP_VPNV6_NODE;
7209 return CMD_SUCCESS;
7210 }
7211 #endif /* KEEP_OLD_VPN_COMMANDS */
7212
7213 DEFUN_NOSH (address_family_evpn,
7214 address_family_evpn_cmd,
7215 "address-family l2vpn evpn",
7216 "Enter Address Family command mode\n"
7217 "Address Family\n"
7218 "Address Family modifier\n")
7219 {
7220 VTY_DECLVAR_CONTEXT(bgp, bgp);
7221 vty->node = BGP_EVPN_NODE;
7222 return CMD_SUCCESS;
7223 }
7224
7225 DEFUN_NOSH (exit_address_family,
7226 exit_address_family_cmd,
7227 "exit-address-family",
7228 "Exit from Address Family configuration mode\n")
7229 {
7230 if (vty->node == BGP_IPV4_NODE || vty->node == BGP_IPV4M_NODE
7231 || vty->node == BGP_IPV4L_NODE || vty->node == BGP_VPNV4_NODE
7232 || vty->node == BGP_IPV6_NODE || vty->node == BGP_IPV6M_NODE
7233 || vty->node == BGP_IPV6L_NODE || vty->node == BGP_VPNV6_NODE
7234 || vty->node == BGP_EVPN_NODE
7235 || vty->node == BGP_FLOWSPECV4_NODE
7236 || vty->node == BGP_FLOWSPECV6_NODE)
7237 vty->node = BGP_NODE;
7238 return CMD_SUCCESS;
7239 }
7240
7241 /* Recalculate bestpath and re-advertise a prefix */
7242 static int bgp_clear_prefix(struct vty *vty, const char *view_name,
7243 const char *ip_str, afi_t afi, safi_t safi,
7244 struct prefix_rd *prd)
7245 {
7246 int ret;
7247 struct prefix match;
7248 struct bgp_node *rn;
7249 struct bgp_node *rm;
7250 struct bgp *bgp;
7251 struct bgp_table *table;
7252 struct bgp_table *rib;
7253
7254 /* BGP structure lookup. */
7255 if (view_name) {
7256 bgp = bgp_lookup_by_name(view_name);
7257 if (bgp == NULL) {
7258 vty_out(vty, "%% Can't find BGP instance %s\n",
7259 view_name);
7260 return CMD_WARNING;
7261 }
7262 } else {
7263 bgp = bgp_get_default();
7264 if (bgp == NULL) {
7265 vty_out(vty, "%% No BGP process is configured\n");
7266 return CMD_WARNING;
7267 }
7268 }
7269
7270 /* Check IP address argument. */
7271 ret = str2prefix(ip_str, &match);
7272 if (!ret) {
7273 vty_out(vty, "%% address is malformed\n");
7274 return CMD_WARNING;
7275 }
7276
7277 match.family = afi2family(afi);
7278 rib = bgp->rib[afi][safi];
7279
7280 if (safi == SAFI_MPLS_VPN) {
7281 for (rn = bgp_table_top(rib); rn; rn = bgp_route_next(rn)) {
7282 if (prd && memcmp(rn->p.u.val, prd->val, 8) != 0)
7283 continue;
7284
7285 table = bgp_node_get_bgp_table_info(rn);
7286 if (table != NULL) {
7287
7288 if ((rm = bgp_node_match(table, &match))
7289 != NULL) {
7290 if (rm->p.prefixlen
7291 == match.prefixlen) {
7292 SET_FLAG(rm->flags,
7293 BGP_NODE_USER_CLEAR);
7294 bgp_process(bgp, rm, afi, safi);
7295 }
7296 bgp_unlock_node(rm);
7297 }
7298 }
7299 }
7300 } else {
7301 if ((rn = bgp_node_match(rib, &match)) != NULL) {
7302 if (rn->p.prefixlen == match.prefixlen) {
7303 SET_FLAG(rn->flags, BGP_NODE_USER_CLEAR);
7304 bgp_process(bgp, rn, afi, safi);
7305 }
7306 bgp_unlock_node(rn);
7307 }
7308 }
7309
7310 return CMD_SUCCESS;
7311 }
7312
7313 /* one clear bgp command to rule them all */
7314 DEFUN (clear_ip_bgp_all,
7315 clear_ip_bgp_all_cmd,
7316 "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>]",
7317 CLEAR_STR
7318 IP_STR
7319 BGP_STR
7320 BGP_INSTANCE_HELP_STR
7321 BGP_AFI_HELP_STR
7322 "Address Family\n"
7323 BGP_SAFI_WITH_LABEL_HELP_STR
7324 "Address Family modifier\n"
7325 "Clear all peers\n"
7326 "BGP neighbor address to clear\n"
7327 "BGP IPv6 neighbor to clear\n"
7328 "BGP neighbor on interface to clear\n"
7329 "Clear peers with the AS number\n"
7330 "Clear all external peers\n"
7331 "Clear all members of peer-group\n"
7332 "BGP peer-group name\n"
7333 BGP_SOFT_STR
7334 BGP_SOFT_IN_STR
7335 BGP_SOFT_OUT_STR
7336 BGP_SOFT_IN_STR
7337 "Push out prefix-list ORF and do inbound soft reconfig\n"
7338 BGP_SOFT_OUT_STR)
7339 {
7340 char *vrf = NULL;
7341
7342 afi_t afi = AFI_UNSPEC;
7343 safi_t safi = SAFI_UNSPEC;
7344 enum clear_sort clr_sort = clear_peer;
7345 enum bgp_clear_type clr_type;
7346 char *clr_arg = NULL;
7347
7348 int idx = 0;
7349
7350 /* clear [ip] bgp */
7351 if (argv_find(argv, argc, "ip", &idx))
7352 afi = AFI_IP;
7353
7354 /* [<vrf> VIEWVRFNAME] */
7355 if (argv_find(argv, argc, "vrf", &idx)) {
7356 vrf = argv[idx + 1]->arg;
7357 idx += 2;
7358 if (vrf && strmatch(vrf, VRF_DEFAULT_NAME))
7359 vrf = NULL;
7360 } else if (argv_find(argv, argc, "view", &idx)) {
7361 /* [<view> VIEWVRFNAME] */
7362 vrf = argv[idx + 1]->arg;
7363 idx += 2;
7364 }
7365 /* ["BGP_AFI_CMD_STR" ["BGP_SAFI_CMD_STR"]] */
7366 if (argv_find_and_parse_afi(argv, argc, &idx, &afi))
7367 argv_find_and_parse_safi(argv, argc, &idx, &safi);
7368
7369 /* <*|A.B.C.D|X:X::X:X|WORD|(1-4294967295)|external|peer-group PGNAME> */
7370 if (argv_find(argv, argc, "*", &idx)) {
7371 clr_sort = clear_all;
7372 } else if (argv_find(argv, argc, "A.B.C.D", &idx)) {
7373 clr_sort = clear_peer;
7374 clr_arg = argv[idx]->arg;
7375 } else if (argv_find(argv, argc, "X:X::X:X", &idx)) {
7376 clr_sort = clear_peer;
7377 clr_arg = argv[idx]->arg;
7378 } else if (argv_find(argv, argc, "peer-group", &idx)) {
7379 clr_sort = clear_group;
7380 idx++;
7381 clr_arg = argv[idx]->arg;
7382 } else if (argv_find(argv, argc, "PGNAME", &idx)) {
7383 clr_sort = clear_peer;
7384 clr_arg = argv[idx]->arg;
7385 } else if (argv_find(argv, argc, "WORD", &idx)) {
7386 clr_sort = clear_peer;
7387 clr_arg = argv[idx]->arg;
7388 } else if (argv_find(argv, argc, "(1-4294967295)", &idx)) {
7389 clr_sort = clear_as;
7390 clr_arg = argv[idx]->arg;
7391 } else if (argv_find(argv, argc, "external", &idx)) {
7392 clr_sort = clear_external;
7393 }
7394
7395 /* [<soft [<in|out>]|in [prefix-filter]|out>] */
7396 if (argv_find(argv, argc, "soft", &idx)) {
7397 if (argv_find(argv, argc, "in", &idx)
7398 || argv_find(argv, argc, "out", &idx))
7399 clr_type = strmatch(argv[idx]->text, "in")
7400 ? BGP_CLEAR_SOFT_IN
7401 : BGP_CLEAR_SOFT_OUT;
7402 else
7403 clr_type = BGP_CLEAR_SOFT_BOTH;
7404 } else if (argv_find(argv, argc, "in", &idx)) {
7405 clr_type = argv_find(argv, argc, "prefix-filter", &idx)
7406 ? BGP_CLEAR_SOFT_IN_ORF_PREFIX
7407 : BGP_CLEAR_SOFT_IN;
7408 } else if (argv_find(argv, argc, "out", &idx)) {
7409 clr_type = BGP_CLEAR_SOFT_OUT;
7410 } else
7411 clr_type = BGP_CLEAR_SOFT_NONE;
7412
7413 return bgp_clear_vty(vty, vrf, afi, safi, clr_sort, clr_type, clr_arg);
7414 }
7415
7416 DEFUN (clear_ip_bgp_prefix,
7417 clear_ip_bgp_prefix_cmd,
7418 "clear [ip] bgp [<view|vrf> VIEWVRFNAME] prefix A.B.C.D/M",
7419 CLEAR_STR
7420 IP_STR
7421 BGP_STR
7422 BGP_INSTANCE_HELP_STR
7423 "Clear bestpath and re-advertise\n"
7424 "IPv4 prefix\n")
7425 {
7426 char *vrf = NULL;
7427 char *prefix = NULL;
7428
7429 int idx = 0;
7430
7431 /* [<view|vrf> VIEWVRFNAME] */
7432 if (argv_find(argv, argc, "vrf", &idx)) {
7433 vrf = argv[idx + 1]->arg;
7434 idx += 2;
7435 if (vrf && strmatch(vrf, VRF_DEFAULT_NAME))
7436 vrf = NULL;
7437 } else if (argv_find(argv, argc, "view", &idx)) {
7438 /* [<view> VIEWVRFNAME] */
7439 vrf = argv[idx + 1]->arg;
7440 idx += 2;
7441 }
7442
7443 prefix = argv[argc - 1]->arg;
7444
7445 return bgp_clear_prefix(vty, vrf, prefix, AFI_IP, SAFI_UNICAST, NULL);
7446 }
7447
7448 DEFUN (clear_bgp_ipv6_safi_prefix,
7449 clear_bgp_ipv6_safi_prefix_cmd,
7450 "clear [ip] bgp ipv6 "BGP_SAFI_CMD_STR" prefix X:X::X:X/M",
7451 CLEAR_STR
7452 IP_STR
7453 BGP_STR
7454 "Address Family\n"
7455 BGP_SAFI_HELP_STR
7456 "Clear bestpath and re-advertise\n"
7457 "IPv6 prefix\n")
7458 {
7459 int idx_safi = 0;
7460 int idx_ipv6_prefix = 0;
7461 safi_t safi = SAFI_UNICAST;
7462 char *prefix = argv_find(argv, argc, "X:X::X:X/M", &idx_ipv6_prefix) ?
7463 argv[idx_ipv6_prefix]->arg : NULL;
7464
7465 argv_find_and_parse_safi(argv, argc, &idx_safi, &safi);
7466 return bgp_clear_prefix(
7467 vty, NULL, prefix, AFI_IP6,
7468 safi, NULL);
7469 }
7470
7471 DEFUN (clear_bgp_instance_ipv6_safi_prefix,
7472 clear_bgp_instance_ipv6_safi_prefix_cmd,
7473 "clear [ip] bgp <view|vrf> VIEWVRFNAME ipv6 "BGP_SAFI_CMD_STR" prefix X:X::X:X/M",
7474 CLEAR_STR
7475 IP_STR
7476 BGP_STR
7477 BGP_INSTANCE_HELP_STR
7478 "Address Family\n"
7479 BGP_SAFI_HELP_STR
7480 "Clear bestpath and re-advertise\n"
7481 "IPv6 prefix\n")
7482 {
7483 int idx_safi = 0;
7484 int idx_vrfview = 0;
7485 int idx_ipv6_prefix = 0;
7486 safi_t safi = SAFI_UNICAST;
7487 char *prefix = argv_find(argv, argc, "X:X::X:X/M", &idx_ipv6_prefix) ?
7488 argv[idx_ipv6_prefix]->arg : NULL;
7489 char *vrfview = NULL;
7490
7491 /* [<view|vrf> VIEWVRFNAME] */
7492 if (argv_find(argv, argc, "vrf", &idx_vrfview)) {
7493 vrfview = argv[idx_vrfview + 1]->arg;
7494 if (vrfview && strmatch(vrfview, VRF_DEFAULT_NAME))
7495 vrfview = NULL;
7496 } else if (argv_find(argv, argc, "view", &idx_vrfview)) {
7497 /* [<view> VIEWVRFNAME] */
7498 vrfview = argv[idx_vrfview + 1]->arg;
7499 }
7500 argv_find_and_parse_safi(argv, argc, &idx_safi, &safi);
7501
7502 return bgp_clear_prefix(
7503 vty, vrfview, prefix,
7504 AFI_IP6, safi, NULL);
7505 }
7506
7507 DEFUN (show_bgp_views,
7508 show_bgp_views_cmd,
7509 "show [ip] bgp views",
7510 SHOW_STR
7511 IP_STR
7512 BGP_STR
7513 "Show the defined BGP views\n")
7514 {
7515 struct list *inst = bm->bgp;
7516 struct listnode *node;
7517 struct bgp *bgp;
7518
7519 vty_out(vty, "Defined BGP views:\n");
7520 for (ALL_LIST_ELEMENTS_RO(inst, node, bgp)) {
7521 /* Skip VRFs. */
7522 if (bgp->inst_type == BGP_INSTANCE_TYPE_VRF)
7523 continue;
7524 vty_out(vty, "\t%s (AS%u)\n", bgp->name ? bgp->name : "(null)",
7525 bgp->as);
7526 }
7527
7528 return CMD_SUCCESS;
7529 }
7530
7531 DEFUN (show_bgp_vrfs,
7532 show_bgp_vrfs_cmd,
7533 "show [ip] bgp vrfs [json]",
7534 SHOW_STR
7535 IP_STR
7536 BGP_STR
7537 "Show BGP VRFs\n"
7538 JSON_STR)
7539 {
7540 char buf[ETHER_ADDR_STRLEN];
7541 struct list *inst = bm->bgp;
7542 struct listnode *node;
7543 struct bgp *bgp;
7544 bool uj = use_json(argc, argv);
7545 json_object *json = NULL;
7546 json_object *json_vrfs = NULL;
7547 int count = 0;
7548
7549 if (uj) {
7550 json = json_object_new_object();
7551 json_vrfs = json_object_new_object();
7552 }
7553
7554 for (ALL_LIST_ELEMENTS_RO(inst, node, bgp)) {
7555 const char *name, *type;
7556 struct peer *peer;
7557 struct listnode *node2, *nnode2;
7558 int peers_cfg, peers_estb;
7559 json_object *json_vrf = NULL;
7560
7561 /* Skip Views. */
7562 if (bgp->inst_type == BGP_INSTANCE_TYPE_VIEW)
7563 continue;
7564
7565 count++;
7566 if (!uj && count == 1) {
7567 vty_out(vty,
7568 "%4s %-5s %-16s %9s %10s %-37s\n",
7569 "Type", "Id", "routerId", "#PeersVfg",
7570 "#PeersEstb", "Name");
7571 vty_out(vty, "%11s %-16s %-21s %-6s\n", " ",
7572 "L3-VNI", "RouterMAC", "Interface");
7573 }
7574
7575 peers_cfg = peers_estb = 0;
7576 if (uj)
7577 json_vrf = json_object_new_object();
7578
7579
7580 for (ALL_LIST_ELEMENTS(bgp->peer, node2, nnode2, peer)) {
7581 if (!CHECK_FLAG(peer->flags, PEER_FLAG_CONFIG_NODE))
7582 continue;
7583 peers_cfg++;
7584 if (peer->status == Established)
7585 peers_estb++;
7586 }
7587
7588 if (bgp->inst_type == BGP_INSTANCE_TYPE_DEFAULT) {
7589 name = VRF_DEFAULT_NAME;
7590 type = "DFLT";
7591 } else {
7592 name = bgp->name;
7593 type = "VRF";
7594 }
7595
7596
7597 if (uj) {
7598 int64_t vrf_id_ui = (bgp->vrf_id == VRF_UNKNOWN)
7599 ? -1
7600 : (int64_t)bgp->vrf_id;
7601 json_object_string_add(json_vrf, "type", type);
7602 json_object_int_add(json_vrf, "vrfId", vrf_id_ui);
7603 json_object_string_add(json_vrf, "routerId",
7604 inet_ntoa(bgp->router_id));
7605 json_object_int_add(json_vrf, "numConfiguredPeers",
7606 peers_cfg);
7607 json_object_int_add(json_vrf, "numEstablishedPeers",
7608 peers_estb);
7609
7610 json_object_int_add(json_vrf, "l3vni", bgp->l3vni);
7611 json_object_string_add(
7612 json_vrf, "rmac",
7613 prefix_mac2str(&bgp->rmac, buf, sizeof(buf)));
7614 json_object_string_add(json_vrf, "interface",
7615 ifindex2ifname(bgp->l3vni_svi_ifindex,
7616 bgp->vrf_id));
7617 json_object_object_add(json_vrfs, name, json_vrf);
7618 } else {
7619 vty_out(vty,
7620 "%4s %-5d %-16s %-9u %-10u %-37s\n",
7621 type,
7622 bgp->vrf_id == VRF_UNKNOWN ? -1
7623 : (int)bgp->vrf_id,
7624 inet_ntoa(bgp->router_id), peers_cfg,
7625 peers_estb, name);
7626 vty_out(vty,"%11s %-16u %-21s %-20s\n", " ",
7627 bgp->l3vni,
7628 prefix_mac2str(&bgp->rmac, buf, sizeof(buf)),
7629 ifindex2ifname(bgp->l3vni_svi_ifindex,
7630 bgp->vrf_id));
7631 }
7632 }
7633
7634 if (uj) {
7635 json_object_object_add(json, "vrfs", json_vrfs);
7636
7637 json_object_int_add(json, "totalVrfs", count);
7638
7639 vty_out(vty, "%s\n", json_object_to_json_string_ext(
7640 json, JSON_C_TO_STRING_PRETTY));
7641 json_object_free(json);
7642 } else {
7643 if (count)
7644 vty_out(vty,
7645 "\nTotal number of VRFs (including default): %d\n",
7646 count);
7647 }
7648
7649 return CMD_SUCCESS;
7650 }
7651
7652 DEFUN (show_bgp_mac_hash,
7653 show_bgp_mac_hash_cmd,
7654 "show bgp mac hash",
7655 SHOW_STR
7656 BGP_STR
7657 "Mac Address\n"
7658 "Mac Address database\n")
7659 {
7660 bgp_mac_dump_table(vty);
7661
7662 return CMD_SUCCESS;
7663 }
7664
7665 static void show_tip_entry(struct hash_bucket *bucket, void *args)
7666 {
7667 struct vty *vty = (struct vty *)args;
7668 struct tip_addr *tip = (struct tip_addr *)bucket->data;
7669
7670 vty_out(vty, "addr: %s, count: %d\n", inet_ntoa(tip->addr),
7671 tip->refcnt);
7672 }
7673
7674 static void bgp_show_martian_nexthops(struct vty *vty, struct bgp *bgp)
7675 {
7676 vty_out(vty, "self nexthop database:\n");
7677 bgp_nexthop_show_address_hash(vty, bgp);
7678
7679 vty_out(vty, "Tunnel-ip database:\n");
7680 hash_iterate(bgp->tip_hash,
7681 (void (*)(struct hash_bucket *, void *))show_tip_entry,
7682 vty);
7683 }
7684
7685 DEFUN(show_bgp_martian_nexthop_db, show_bgp_martian_nexthop_db_cmd,
7686 "show bgp [<view|vrf> VIEWVRFNAME] martian next-hop",
7687 SHOW_STR BGP_STR BGP_INSTANCE_HELP_STR
7688 "martian next-hops\n"
7689 "martian next-hop database\n")
7690 {
7691 struct bgp *bgp = NULL;
7692 int idx = 0;
7693 char *name = NULL;
7694
7695 /* [<vrf> VIEWVRFNAME] */
7696 if (argv_find(argv, argc, "vrf", &idx)) {
7697 name = argv[idx + 1]->arg;
7698 if (name && strmatch(name, VRF_DEFAULT_NAME))
7699 name = NULL;
7700 } else if (argv_find(argv, argc, "view", &idx))
7701 /* [<view> VIEWVRFNAME] */
7702 name = argv[idx + 1]->arg;
7703 if (name)
7704 bgp = bgp_lookup_by_name(name);
7705 else
7706 bgp = bgp_get_default();
7707
7708 if (!bgp) {
7709 vty_out(vty, "%% No BGP process is configured\n");
7710 return CMD_WARNING;
7711 }
7712 bgp_show_martian_nexthops(vty, bgp);
7713
7714 return CMD_SUCCESS;
7715 }
7716
7717 DEFUN (show_bgp_memory,
7718 show_bgp_memory_cmd,
7719 "show [ip] bgp memory",
7720 SHOW_STR
7721 IP_STR
7722 BGP_STR
7723 "Global BGP memory statistics\n")
7724 {
7725 char memstrbuf[MTYPE_MEMSTR_LEN];
7726 unsigned long count;
7727
7728 /* RIB related usage stats */
7729 count = mtype_stats_alloc(MTYPE_BGP_NODE);
7730 vty_out(vty, "%ld RIB nodes, using %s of memory\n", count,
7731 mtype_memstr(memstrbuf, sizeof(memstrbuf),
7732 count * sizeof(struct bgp_node)));
7733
7734 count = mtype_stats_alloc(MTYPE_BGP_ROUTE);
7735 vty_out(vty, "%ld BGP routes, using %s of memory\n", count,
7736 mtype_memstr(memstrbuf, sizeof(memstrbuf),
7737 count * sizeof(struct bgp_path_info)));
7738 if ((count = mtype_stats_alloc(MTYPE_BGP_ROUTE_EXTRA)))
7739 vty_out(vty, "%ld BGP route ancillaries, using %s of memory\n",
7740 count,
7741 mtype_memstr(
7742 memstrbuf, sizeof(memstrbuf),
7743 count * sizeof(struct bgp_path_info_extra)));
7744
7745 if ((count = mtype_stats_alloc(MTYPE_BGP_STATIC)))
7746 vty_out(vty, "%ld Static routes, using %s of memory\n", count,
7747 mtype_memstr(memstrbuf, sizeof(memstrbuf),
7748 count * sizeof(struct bgp_static)));
7749
7750 if ((count = mtype_stats_alloc(MTYPE_BGP_PACKET)))
7751 vty_out(vty, "%ld Packets, using %s of memory\n", count,
7752 mtype_memstr(memstrbuf, sizeof(memstrbuf),
7753 count * sizeof(struct bpacket)));
7754
7755 /* Adj-In/Out */
7756 if ((count = mtype_stats_alloc(MTYPE_BGP_ADJ_IN)))
7757 vty_out(vty, "%ld Adj-In entries, using %s of memory\n", count,
7758 mtype_memstr(memstrbuf, sizeof(memstrbuf),
7759 count * sizeof(struct bgp_adj_in)));
7760 if ((count = mtype_stats_alloc(MTYPE_BGP_ADJ_OUT)))
7761 vty_out(vty, "%ld Adj-Out entries, using %s of memory\n", count,
7762 mtype_memstr(memstrbuf, sizeof(memstrbuf),
7763 count * sizeof(struct bgp_adj_out)));
7764
7765 if ((count = mtype_stats_alloc(MTYPE_BGP_NEXTHOP_CACHE)))
7766 vty_out(vty, "%ld Nexthop cache entries, using %s of memory\n",
7767 count,
7768 mtype_memstr(memstrbuf, sizeof(memstrbuf),
7769 count * sizeof(struct bgp_nexthop_cache)));
7770
7771 if ((count = mtype_stats_alloc(MTYPE_BGP_DAMP_INFO)))
7772 vty_out(vty, "%ld Dampening entries, using %s of memory\n",
7773 count,
7774 mtype_memstr(memstrbuf, sizeof(memstrbuf),
7775 count * sizeof(struct bgp_damp_info)));
7776
7777 /* Attributes */
7778 count = attr_count();
7779 vty_out(vty, "%ld BGP attributes, using %s of memory\n", count,
7780 mtype_memstr(memstrbuf, sizeof(memstrbuf),
7781 count * sizeof(struct attr)));
7782
7783 if ((count = attr_unknown_count()))
7784 vty_out(vty, "%ld unknown attributes\n", count);
7785
7786 /* AS_PATH attributes */
7787 count = aspath_count();
7788 vty_out(vty, "%ld BGP AS-PATH entries, using %s of memory\n", count,
7789 mtype_memstr(memstrbuf, sizeof(memstrbuf),
7790 count * sizeof(struct aspath)));
7791
7792 count = mtype_stats_alloc(MTYPE_AS_SEG);
7793 vty_out(vty, "%ld BGP AS-PATH segments, using %s of memory\n", count,
7794 mtype_memstr(memstrbuf, sizeof(memstrbuf),
7795 count * sizeof(struct assegment)));
7796
7797 /* Other attributes */
7798 if ((count = community_count()))
7799 vty_out(vty, "%ld BGP community entries, using %s of memory\n",
7800 count, mtype_memstr(memstrbuf, sizeof(memstrbuf),
7801 count * sizeof(struct community)));
7802 if ((count = mtype_stats_alloc(MTYPE_ECOMMUNITY)))
7803 vty_out(vty, "%ld BGP community entries, using %s of memory\n",
7804 count, mtype_memstr(memstrbuf, sizeof(memstrbuf),
7805 count * sizeof(struct ecommunity)));
7806 if ((count = mtype_stats_alloc(MTYPE_LCOMMUNITY)))
7807 vty_out(vty,
7808 "%ld BGP large-community entries, using %s of memory\n",
7809 count, mtype_memstr(memstrbuf, sizeof(memstrbuf),
7810 count * sizeof(struct lcommunity)));
7811
7812 if ((count = mtype_stats_alloc(MTYPE_CLUSTER)))
7813 vty_out(vty, "%ld Cluster lists, using %s of memory\n", count,
7814 mtype_memstr(memstrbuf, sizeof(memstrbuf),
7815 count * sizeof(struct cluster_list)));
7816
7817 /* Peer related usage */
7818 count = mtype_stats_alloc(MTYPE_BGP_PEER);
7819 vty_out(vty, "%ld peers, using %s of memory\n", count,
7820 mtype_memstr(memstrbuf, sizeof(memstrbuf),
7821 count * sizeof(struct peer)));
7822
7823 if ((count = mtype_stats_alloc(MTYPE_PEER_GROUP)))
7824 vty_out(vty, "%ld peer groups, using %s of memory\n", count,
7825 mtype_memstr(memstrbuf, sizeof(memstrbuf),
7826 count * sizeof(struct peer_group)));
7827
7828 /* Other */
7829 if ((count = mtype_stats_alloc(MTYPE_BGP_REGEXP)))
7830 vty_out(vty, "%ld compiled regexes, using %s of memory\n",
7831 count, mtype_memstr(memstrbuf, sizeof(memstrbuf),
7832 count * sizeof(regex_t)));
7833 return CMD_SUCCESS;
7834 }
7835
7836 static void bgp_show_bestpath_json(struct bgp *bgp, json_object *json)
7837 {
7838 json_object *bestpath = json_object_new_object();
7839
7840 if (bgp_flag_check(bgp, BGP_FLAG_ASPATH_IGNORE))
7841 json_object_string_add(bestpath, "asPath", "ignore");
7842
7843 if (bgp_flag_check(bgp, BGP_FLAG_ASPATH_CONFED))
7844 json_object_string_add(bestpath, "asPath", "confed");
7845
7846 if (bgp_flag_check(bgp, BGP_FLAG_ASPATH_MULTIPATH_RELAX)) {
7847 if (bgp_flag_check(bgp, BGP_FLAG_MULTIPATH_RELAX_AS_SET))
7848 json_object_string_add(bestpath, "multiPathRelax",
7849 "as-set");
7850 else
7851 json_object_string_add(bestpath, "multiPathRelax",
7852 "true");
7853 } else
7854 json_object_string_add(bestpath, "multiPathRelax", "false");
7855
7856 if (bgp_flag_check(bgp, BGP_FLAG_COMPARE_ROUTER_ID))
7857 json_object_string_add(bestpath, "compareRouterId", "true");
7858 if (bgp_flag_check(bgp, BGP_FLAG_MED_CONFED)
7859 || bgp_flag_check(bgp, BGP_FLAG_MED_MISSING_AS_WORST)) {
7860 if (bgp_flag_check(bgp, BGP_FLAG_MED_CONFED))
7861 json_object_string_add(bestpath, "med", "confed");
7862 if (bgp_flag_check(bgp, BGP_FLAG_MED_MISSING_AS_WORST))
7863 json_object_string_add(bestpath, "med",
7864 "missing-as-worst");
7865 else
7866 json_object_string_add(bestpath, "med", "true");
7867 }
7868
7869 json_object_object_add(json, "bestPath", bestpath);
7870 }
7871
7872 /* Print the error code/subcode for why the peer is down */
7873 static void bgp_show_peer_reset(struct vty * vty, struct peer *peer,
7874 json_object *json_peer, bool use_json)
7875 {
7876 const char *code_str;
7877 const char *subcode_str;
7878
7879 if (use_json) {
7880 if (peer->last_reset == PEER_DOWN_NOTIFY_SEND
7881 || peer->last_reset == PEER_DOWN_NOTIFY_RECEIVED) {
7882 char errorcodesubcode_hexstr[5];
7883 char errorcodesubcode_str[256];
7884
7885 code_str = bgp_notify_code_str(peer->notify.code);
7886 subcode_str = bgp_notify_subcode_str(
7887 peer->notify.code,
7888 peer->notify.subcode);
7889
7890 sprintf(errorcodesubcode_hexstr, "%02X%02X",
7891 peer->notify.code, peer->notify.subcode);
7892 json_object_string_add(json_peer,
7893 "lastErrorCodeSubcode",
7894 errorcodesubcode_hexstr);
7895 snprintf(errorcodesubcode_str, 255, "%s%s",
7896 code_str, subcode_str);
7897 json_object_string_add(json_peer,
7898 "lastNotificationReason",
7899 errorcodesubcode_str);
7900 if (peer->last_reset == PEER_DOWN_NOTIFY_RECEIVED
7901 && peer->notify.code == BGP_NOTIFY_CEASE
7902 && (peer->notify.subcode
7903 == BGP_NOTIFY_CEASE_ADMIN_SHUTDOWN
7904 || peer->notify.subcode
7905 == BGP_NOTIFY_CEASE_ADMIN_RESET)
7906 && peer->notify.length) {
7907 char msgbuf[1024];
7908 const char *msg_str;
7909
7910 msg_str = bgp_notify_admin_message(
7911 msgbuf, sizeof(msgbuf),
7912 (uint8_t *)peer->notify.data,
7913 peer->notify.length);
7914 if (msg_str)
7915 json_object_string_add(
7916 json_peer,
7917 "lastShutdownDescription",
7918 msg_str);
7919 }
7920
7921 }
7922 json_object_string_add(json_peer, "lastResetDueTo",
7923 peer_down_str[(int)peer->last_reset]);
7924 } else {
7925 if (peer->last_reset == PEER_DOWN_NOTIFY_SEND
7926 || peer->last_reset == PEER_DOWN_NOTIFY_RECEIVED) {
7927 code_str = bgp_notify_code_str(peer->notify.code);
7928 subcode_str =
7929 bgp_notify_subcode_str(peer->notify.code,
7930 peer->notify.subcode);
7931 vty_out(vty, " Notification %s (%s%s)\n",
7932 peer->last_reset == PEER_DOWN_NOTIFY_SEND
7933 ? "sent"
7934 : "received",
7935 code_str, subcode_str);
7936 } else {
7937 vty_out(vty, " %s\n",
7938 peer_down_str[(int)peer->last_reset]);
7939 }
7940 }
7941 }
7942
7943 static inline bool bgp_has_peer_failed(struct peer *peer, afi_t afi,
7944 safi_t safi)
7945 {
7946 return ((peer->status != Established) ||
7947 !peer->afc_recv[afi][safi]);
7948 }
7949
7950 static void bgp_show_failed_summary(struct vty *vty, struct bgp *bgp,
7951 struct peer *peer, json_object *json_peer,
7952 int max_neighbor_width, bool use_json)
7953 {
7954 char timebuf[BGP_UPTIME_LEN], dn_flag[2];
7955 int len;
7956
7957 if (use_json) {
7958 if (peer_dynamic_neighbor(peer))
7959 json_object_boolean_true_add(json_peer,
7960 "dynamicPeer");
7961 if (peer->hostname)
7962 json_object_string_add(json_peer, "hostname",
7963 peer->hostname);
7964
7965 if (peer->domainname)
7966 json_object_string_add(json_peer, "domainname",
7967 peer->domainname);
7968 json_object_int_add(json_peer, "connectionsEstablished",
7969 peer->established);
7970 json_object_int_add(json_peer, "connectionsDropped",
7971 peer->dropped);
7972 peer_uptime(peer->uptime, timebuf, BGP_UPTIME_LEN,
7973 use_json, json_peer);
7974 if (peer->status == Established)
7975 json_object_string_add(json_peer, "lastResetDueTo",
7976 "AFI/SAFI Not Negotiated");
7977 else
7978 bgp_show_peer_reset(NULL, peer, json_peer, true);
7979 } else {
7980 dn_flag[1] = '\0';
7981 dn_flag[0] = peer_dynamic_neighbor(peer) ? '*' : '\0';
7982 if (peer->hostname
7983 && bgp_flag_check(bgp, BGP_FLAG_SHOW_HOSTNAME))
7984 len = vty_out(vty, "%s%s(%s)", dn_flag,
7985 peer->hostname, peer->host);
7986 else
7987 len = vty_out(vty, "%s%s", dn_flag, peer->host);
7988
7989 /* pad the neighbor column with spaces */
7990 if (len < max_neighbor_width)
7991 vty_out(vty, "%*s", max_neighbor_width - len,
7992 " ");
7993 vty_out(vty, "%7d %7d %8s", peer->established,
7994 peer->dropped,
7995 peer_uptime(peer->uptime, timebuf,
7996 BGP_UPTIME_LEN, 0, NULL));
7997 if (peer->status == Established)
7998 vty_out(vty, " AFI/SAFI Not Negotiated\n");
7999 else
8000 bgp_show_peer_reset(vty, peer, NULL,
8001 false);
8002 }
8003 }
8004
8005
8006 /* Show BGP peer's summary information. */
8007 static int bgp_show_summary(struct vty *vty, struct bgp *bgp, int afi, int safi,
8008 bool show_failed, bool use_json)
8009 {
8010 struct peer *peer;
8011 struct listnode *node, *nnode;
8012 unsigned int count = 0, dn_count = 0;
8013 char timebuf[BGP_UPTIME_LEN], dn_flag[2];
8014 char neighbor_buf[VTY_BUFSIZ];
8015 int neighbor_col_default_width = 16;
8016 int len, failed_count = 0;
8017 int max_neighbor_width = 0;
8018 int pfx_rcd_safi;
8019 json_object *json = NULL;
8020 json_object *json_peer = NULL;
8021 json_object *json_peers = NULL;
8022 struct peer_af *paf;
8023
8024 /* labeled-unicast routes are installed in the unicast table so in order
8025 * to
8026 * display the correct PfxRcd value we must look at SAFI_UNICAST
8027 */
8028
8029 if (safi == SAFI_LABELED_UNICAST)
8030 pfx_rcd_safi = SAFI_UNICAST;
8031 else
8032 pfx_rcd_safi = safi;
8033
8034 if (use_json) {
8035 json = json_object_new_object();
8036 json_peers = json_object_new_object();
8037 for (ALL_LIST_ELEMENTS(bgp->peer, node, nnode, peer)) {
8038 if (!CHECK_FLAG(peer->flags, PEER_FLAG_CONFIG_NODE))
8039 continue;
8040
8041 if (peer->afc[afi][safi]) {
8042 /* See if we have at least a single failed peer */
8043 if (bgp_has_peer_failed(peer, afi, safi))
8044 failed_count++;
8045 count++;
8046 }
8047 if (peer_dynamic_neighbor(peer))
8048 dn_count++;
8049 }
8050
8051 } else {
8052 /* Loop over all neighbors that will be displayed to determine
8053 * how many
8054 * characters are needed for the Neighbor column
8055 */
8056 for (ALL_LIST_ELEMENTS(bgp->peer, node, nnode, peer)) {
8057 if (!CHECK_FLAG(peer->flags, PEER_FLAG_CONFIG_NODE))
8058 continue;
8059
8060 if (peer->afc[afi][safi]) {
8061 memset(dn_flag, '\0', sizeof(dn_flag));
8062 if (peer_dynamic_neighbor(peer))
8063 dn_flag[0] = '*';
8064
8065 if (peer->hostname
8066 && bgp_flag_check(bgp,
8067 BGP_FLAG_SHOW_HOSTNAME))
8068 sprintf(neighbor_buf, "%s%s(%s) ",
8069 dn_flag, peer->hostname,
8070 peer->host);
8071 else
8072 sprintf(neighbor_buf, "%s%s ", dn_flag,
8073 peer->host);
8074
8075 len = strlen(neighbor_buf);
8076
8077 if (len > max_neighbor_width)
8078 max_neighbor_width = len;
8079
8080 /* See if we have at least a single failed peer */
8081 if (bgp_has_peer_failed(peer, afi, safi))
8082 failed_count++;
8083 count++;
8084 }
8085 }
8086
8087 /* Originally we displayed the Neighbor column as 16
8088 * characters wide so make that the default
8089 */
8090 if (max_neighbor_width < neighbor_col_default_width)
8091 max_neighbor_width = neighbor_col_default_width;
8092 }
8093
8094 if (show_failed && !failed_count) {
8095 if (use_json) {
8096 json_object_int_add(json, "failedPeersCount", 0);
8097 json_object_int_add(json, "dynamicPeers", dn_count);
8098 json_object_int_add(json, "totalPeers", count);
8099
8100 vty_out(vty, "%s\n", json_object_to_json_string_ext(
8101 json, JSON_C_TO_STRING_PRETTY));
8102 json_object_free(json);
8103 } else {
8104 vty_out(vty, "%% No failed BGP neighbors found\n");
8105 vty_out(vty, "\nTotal number of neighbors %d\n", count);
8106 }
8107 return CMD_SUCCESS;
8108 }
8109
8110 count = 0; /* Reset the value as its used again */
8111 for (ALL_LIST_ELEMENTS(bgp->peer, node, nnode, peer)) {
8112 if (!CHECK_FLAG(peer->flags, PEER_FLAG_CONFIG_NODE))
8113 continue;
8114
8115 if (!peer->afc[afi][safi])
8116 continue;
8117
8118 if (!count) {
8119 unsigned long ents;
8120 char memstrbuf[MTYPE_MEMSTR_LEN];
8121 int64_t vrf_id_ui;
8122
8123 vrf_id_ui = (bgp->vrf_id == VRF_UNKNOWN)
8124 ? -1
8125 : (int64_t)bgp->vrf_id;
8126
8127 /* Usage summary and header */
8128 if (use_json) {
8129 json_object_string_add(
8130 json, "routerId",
8131 inet_ntoa(bgp->router_id));
8132 json_object_int_add(json, "as", bgp->as);
8133 json_object_int_add(json, "vrfId", vrf_id_ui);
8134 json_object_string_add(
8135 json, "vrfName",
8136 (bgp->inst_type
8137 == BGP_INSTANCE_TYPE_DEFAULT)
8138 ? VRF_DEFAULT_NAME
8139 : bgp->name);
8140 } else {
8141 vty_out(vty,
8142 "BGP router identifier %s, local AS number %u vrf-id %d",
8143 inet_ntoa(bgp->router_id), bgp->as,
8144 bgp->vrf_id == VRF_UNKNOWN
8145 ? -1
8146 : (int)bgp->vrf_id);
8147 vty_out(vty, "\n");
8148 }
8149
8150 if (bgp_update_delay_configured(bgp)) {
8151 if (use_json) {
8152 json_object_int_add(
8153 json, "updateDelayLimit",
8154 bgp->v_update_delay);
8155
8156 if (bgp->v_update_delay
8157 != bgp->v_establish_wait)
8158 json_object_int_add(
8159 json,
8160 "updateDelayEstablishWait",
8161 bgp->v_establish_wait);
8162
8163 if (bgp_update_delay_active(bgp)) {
8164 json_object_string_add(
8165 json,
8166 "updateDelayFirstNeighbor",
8167 bgp->update_delay_begin_time);
8168 json_object_boolean_true_add(
8169 json,
8170 "updateDelayInProgress");
8171 } else {
8172 if (bgp->update_delay_over) {
8173 json_object_string_add(
8174 json,
8175 "updateDelayFirstNeighbor",
8176 bgp->update_delay_begin_time);
8177 json_object_string_add(
8178 json,
8179 "updateDelayBestpathResumed",
8180 bgp->update_delay_end_time);
8181 json_object_string_add(
8182 json,
8183 "updateDelayZebraUpdateResume",
8184 bgp->update_delay_zebra_resume_time);
8185 json_object_string_add(
8186 json,
8187 "updateDelayPeerUpdateResume",
8188 bgp->update_delay_peers_resume_time);
8189 }
8190 }
8191 } else {
8192 vty_out(vty,
8193 "Read-only mode update-delay limit: %d seconds\n",
8194 bgp->v_update_delay);
8195 if (bgp->v_update_delay
8196 != bgp->v_establish_wait)
8197 vty_out(vty,
8198 " Establish wait: %d seconds\n",
8199 bgp->v_establish_wait);
8200
8201 if (bgp_update_delay_active(bgp)) {
8202 vty_out(vty,
8203 " First neighbor established: %s\n",
8204 bgp->update_delay_begin_time);
8205 vty_out(vty,
8206 " Delay in progress\n");
8207 } else {
8208 if (bgp->update_delay_over) {
8209 vty_out(vty,
8210 " First neighbor established: %s\n",
8211 bgp->update_delay_begin_time);
8212 vty_out(vty,
8213 " Best-paths resumed: %s\n",
8214 bgp->update_delay_end_time);
8215 vty_out(vty,
8216 " zebra update resumed: %s\n",
8217 bgp->update_delay_zebra_resume_time);
8218 vty_out(vty,
8219 " peers update resumed: %s\n",
8220 bgp->update_delay_peers_resume_time);
8221 }
8222 }
8223 }
8224 }
8225
8226 if (use_json) {
8227 if (bgp_maxmed_onstartup_configured(bgp)
8228 && bgp->maxmed_active)
8229 json_object_boolean_true_add(
8230 json, "maxMedOnStartup");
8231 if (bgp->v_maxmed_admin)
8232 json_object_boolean_true_add(
8233 json, "maxMedAdministrative");
8234
8235 json_object_int_add(
8236 json, "tableVersion",
8237 bgp_table_version(bgp->rib[afi][safi]));
8238
8239 ents = bgp_table_count(bgp->rib[afi][safi]);
8240 json_object_int_add(json, "ribCount", ents);
8241 json_object_int_add(
8242 json, "ribMemory",
8243 ents * sizeof(struct bgp_node));
8244
8245 ents = bgp->af_peer_count[afi][safi];
8246 json_object_int_add(json, "peerCount", ents);
8247 json_object_int_add(json, "peerMemory",
8248 ents * sizeof(struct peer));
8249
8250 if ((ents = listcount(bgp->group))) {
8251 json_object_int_add(
8252 json, "peerGroupCount", ents);
8253 json_object_int_add(
8254 json, "peerGroupMemory",
8255 ents * sizeof(struct
8256 peer_group));
8257 }
8258
8259 if (CHECK_FLAG(bgp->af_flags[afi][safi],
8260 BGP_CONFIG_DAMPENING))
8261 json_object_boolean_true_add(
8262 json, "dampeningEnabled");
8263 } else {
8264 if (bgp_maxmed_onstartup_configured(bgp)
8265 && bgp->maxmed_active)
8266 vty_out(vty,
8267 "Max-med on-startup active\n");
8268 if (bgp->v_maxmed_admin)
8269 vty_out(vty,
8270 "Max-med administrative active\n");
8271
8272 vty_out(vty, "BGP table version %" PRIu64 "\n",
8273 bgp_table_version(bgp->rib[afi][safi]));
8274
8275 ents = bgp_table_count(bgp->rib[afi][safi]);
8276 vty_out(vty,
8277 "RIB entries %ld, using %s of memory\n",
8278 ents,
8279 mtype_memstr(memstrbuf,
8280 sizeof(memstrbuf),
8281 ents * sizeof(struct
8282 bgp_node)));
8283
8284 /* Peer related usage */
8285 ents = bgp->af_peer_count[afi][safi];
8286 vty_out(vty, "Peers %ld, using %s of memory\n",
8287 ents,
8288 mtype_memstr(
8289 memstrbuf, sizeof(memstrbuf),
8290 ents * sizeof(struct peer)));
8291
8292 if ((ents = listcount(bgp->group)))
8293 vty_out(vty,
8294 "Peer groups %ld, using %s of memory\n",
8295 ents,
8296 mtype_memstr(
8297 memstrbuf,
8298 sizeof(memstrbuf),
8299 ents * sizeof(struct
8300 peer_group)));
8301
8302 if (CHECK_FLAG(bgp->af_flags[afi][safi],
8303 BGP_CONFIG_DAMPENING))
8304 vty_out(vty, "Dampening enabled.\n");
8305 vty_out(vty, "\n");
8306
8307 /* Subtract 8 here because 'Neighbor' is
8308 * 8 characters */
8309 vty_out(vty, "Neighbor");
8310 vty_out(vty, "%*s", max_neighbor_width - 8,
8311 " ");
8312 if (show_failed)
8313 vty_out(vty, "EstdCnt DropCnt ResetTime Reason\n");
8314 else
8315 vty_out(vty,
8316 "V AS MsgRcvd MsgSent TblVer InQ OutQ Up/Down State/PfxRcd\n");
8317 }
8318 }
8319
8320 count++;
8321 /* Works for both failed & successful cases */
8322 if (peer_dynamic_neighbor(peer))
8323 dn_count++;
8324
8325 if (use_json) {
8326 json_peer = NULL;
8327
8328 if (show_failed &&
8329 bgp_has_peer_failed(peer, afi, safi)) {
8330 json_peer = json_object_new_object();
8331 bgp_show_failed_summary(vty, bgp, peer,
8332 json_peer, 0, use_json);
8333 } else if (!show_failed) {
8334 json_peer = json_object_new_object();
8335 if (peer_dynamic_neighbor(peer)) {
8336 json_object_boolean_true_add(json_peer,
8337 "dynamicPeer");
8338 }
8339
8340 if (peer->hostname)
8341 json_object_string_add(json_peer, "hostname",
8342 peer->hostname);
8343
8344 if (peer->domainname)
8345 json_object_string_add(json_peer, "domainname",
8346 peer->domainname);
8347
8348 json_object_int_add(json_peer, "remoteAs", peer->as);
8349 json_object_int_add(json_peer, "version", 4);
8350 json_object_int_add(json_peer, "msgRcvd",
8351 PEER_TOTAL_RX(peer));
8352 json_object_int_add(json_peer, "msgSent",
8353 PEER_TOTAL_TX(peer));
8354
8355 json_object_int_add(json_peer, "tableVersion",
8356 peer->version[afi][safi]);
8357 json_object_int_add(json_peer, "outq",
8358 peer->obuf->count);
8359 json_object_int_add(json_peer, "inq", 0);
8360 peer_uptime(peer->uptime, timebuf, BGP_UPTIME_LEN,
8361 use_json, json_peer);
8362
8363 /*
8364 * Adding "pfxRcd" field to match with the corresponding
8365 * CLI. "prefixReceivedCount" will be deprecated in
8366 * future.
8367 */
8368 json_object_int_add(json_peer, "prefixReceivedCount",
8369 peer->pcount[afi][pfx_rcd_safi]);
8370 json_object_int_add(json_peer, "pfxRcd",
8371 peer->pcount[afi][pfx_rcd_safi]);
8372
8373 paf = peer_af_find(peer, afi, pfx_rcd_safi);
8374 if (paf && PAF_SUBGRP(paf))
8375 json_object_int_add(json_peer,
8376 "pfxSnt",
8377 (PAF_SUBGRP(paf))->scount);
8378 if (CHECK_FLAG(peer->flags, PEER_FLAG_SHUTDOWN))
8379 json_object_string_add(json_peer, "state",
8380 "Idle (Admin)");
8381 else if (peer->afc_recv[afi][safi])
8382 json_object_string_add(
8383 json_peer, "state",
8384 lookup_msg(bgp_status_msg, peer->status,
8385 NULL));
8386 else if (CHECK_FLAG(peer->sflags,
8387 PEER_STATUS_PREFIX_OVERFLOW))
8388 json_object_string_add(json_peer, "state",
8389 "Idle (PfxCt)");
8390 else
8391 json_object_string_add(
8392 json_peer, "state",
8393 lookup_msg(bgp_status_msg, peer->status,
8394 NULL));
8395 json_object_int_add(json_peer, "connectionsEstablished",
8396 peer->established);
8397 json_object_int_add(json_peer, "connectionsDropped",
8398 peer->dropped);
8399 }
8400 /* Avoid creating empty peer dicts in JSON */
8401 if (json_peer == NULL)
8402 continue;
8403
8404 if (peer->conf_if)
8405 json_object_string_add(json_peer, "idType",
8406 "interface");
8407 else if (peer->su.sa.sa_family == AF_INET)
8408 json_object_string_add(json_peer, "idType",
8409 "ipv4");
8410 else if (peer->su.sa.sa_family == AF_INET6)
8411 json_object_string_add(json_peer, "idType",
8412 "ipv6");
8413 json_object_object_add(json_peers, peer->host,
8414 json_peer);
8415 } else {
8416 if (show_failed &&
8417 bgp_has_peer_failed(peer, afi, safi)) {
8418 bgp_show_failed_summary(vty, bgp, peer, NULL,
8419 max_neighbor_width,
8420 use_json);
8421 } else if (!show_failed) {
8422 memset(dn_flag, '\0', sizeof(dn_flag));
8423 if (peer_dynamic_neighbor(peer)) {
8424 dn_flag[0] = '*';
8425 }
8426
8427 if (peer->hostname
8428 && bgp_flag_check(bgp, BGP_FLAG_SHOW_HOSTNAME))
8429 len = vty_out(vty, "%s%s(%s)", dn_flag,
8430 peer->hostname, peer->host);
8431 else
8432 len = vty_out(vty, "%s%s", dn_flag, peer->host);
8433
8434 /* pad the neighbor column with spaces */
8435 if (len < max_neighbor_width)
8436 vty_out(vty, "%*s", max_neighbor_width - len,
8437 " ");
8438
8439 vty_out(vty, "4 %10u %7u %7u %8" PRIu64 " %4d %4zd %8s",
8440 peer->as, PEER_TOTAL_RX(peer),
8441 PEER_TOTAL_TX(peer), peer->version[afi][safi],
8442 0, peer->obuf->count,
8443 peer_uptime(peer->uptime, timebuf,
8444 BGP_UPTIME_LEN, 0, NULL));
8445
8446 if (peer->status == Established)
8447 if (peer->afc_recv[afi][safi])
8448 vty_out(vty, " %12ld",
8449 peer->pcount[afi]
8450 [pfx_rcd_safi]);
8451 else
8452 vty_out(vty, " NoNeg");
8453 else {
8454 if (CHECK_FLAG(peer->flags, PEER_FLAG_SHUTDOWN))
8455 vty_out(vty, " Idle (Admin)");
8456 else if (CHECK_FLAG(
8457 peer->sflags,
8458 PEER_STATUS_PREFIX_OVERFLOW))
8459 vty_out(vty, " Idle (PfxCt)");
8460 else
8461 vty_out(vty, " %12s",
8462 lookup_msg(bgp_status_msg,
8463 peer->status, NULL));
8464 }
8465 vty_out(vty, "\n");
8466 }
8467
8468 }
8469 }
8470
8471 if (use_json) {
8472 json_object_object_add(json, "peers", json_peers);
8473 json_object_int_add(json, "failedPeers", failed_count);
8474 json_object_int_add(json, "totalPeers", count);
8475 json_object_int_add(json, "dynamicPeers", dn_count);
8476
8477 if (!show_failed)
8478 bgp_show_bestpath_json(bgp, json);
8479
8480 vty_out(vty, "%s\n", json_object_to_json_string_ext(
8481 json, JSON_C_TO_STRING_PRETTY));
8482 json_object_free(json);
8483 } else {
8484 if (count)
8485 vty_out(vty, "\nTotal number of neighbors %d\n", count);
8486 else {
8487 vty_out(vty, "No %s neighbor is configured\n",
8488 get_afi_safi_str(afi, safi, false));
8489 }
8490
8491 if (dn_count) {
8492 vty_out(vty, "* - dynamic neighbor\n");
8493 vty_out(vty, "%d dynamic neighbor(s), limit %d\n",
8494 dn_count, bgp->dynamic_neighbors_limit);
8495 }
8496 }
8497
8498 return CMD_SUCCESS;
8499 }
8500
8501 static void bgp_show_summary_afi_safi(struct vty *vty, struct bgp *bgp, int afi,
8502 int safi, bool show_failed, bool use_json)
8503 {
8504 int is_first = 1;
8505 int afi_wildcard = (afi == AFI_MAX);
8506 int safi_wildcard = (safi == SAFI_MAX);
8507 int is_wildcard = (afi_wildcard || safi_wildcard);
8508 bool nbr_output = false;
8509
8510 if (use_json && is_wildcard)
8511 vty_out(vty, "{\n");
8512 if (afi_wildcard)
8513 afi = 1; /* AFI_IP */
8514 while (afi < AFI_MAX) {
8515 if (safi_wildcard)
8516 safi = 1; /* SAFI_UNICAST */
8517 while (safi < SAFI_MAX) {
8518 if (bgp_afi_safi_peer_exists(bgp, afi, safi)) {
8519 nbr_output = true;
8520
8521 if (is_wildcard) {
8522 /*
8523 * So limit output to those afi/safi
8524 * pairs that
8525 * actualy have something interesting in
8526 * them
8527 */
8528 if (use_json) {
8529 if (!is_first)
8530 vty_out(vty, ",\n");
8531 else
8532 is_first = 0;
8533
8534 vty_out(vty, "\"%s\":",
8535 get_afi_safi_str(afi,
8536 safi,
8537 true));
8538 } else {
8539 vty_out(vty, "\n%s Summary:\n",
8540 get_afi_safi_str(afi,
8541 safi,
8542 false));
8543 }
8544 }
8545 bgp_show_summary(vty, bgp, afi, safi, show_failed,
8546 use_json);
8547 }
8548 safi++;
8549 if (!safi_wildcard)
8550 safi = SAFI_MAX;
8551 }
8552 afi++;
8553 if (!afi_wildcard)
8554 afi = AFI_MAX;
8555 }
8556
8557 if (use_json && is_wildcard)
8558 vty_out(vty, "}\n");
8559 else if (!nbr_output) {
8560 if (use_json)
8561 vty_out(vty, "{}\n");
8562 else
8563 vty_out(vty, "%% No BGP neighbors found\n");
8564 }
8565 }
8566
8567 static void bgp_show_all_instances_summary_vty(struct vty *vty, afi_t afi,
8568 safi_t safi, bool show_failed,
8569 bool use_json)
8570 {
8571 struct listnode *node, *nnode;
8572 struct bgp *bgp;
8573 int is_first = 1;
8574 bool nbr_output = false;
8575
8576 if (use_json)
8577 vty_out(vty, "{\n");
8578
8579 for (ALL_LIST_ELEMENTS(bm->bgp, node, nnode, bgp)) {
8580 nbr_output = true;
8581 if (use_json) {
8582 if (!is_first)
8583 vty_out(vty, ",\n");
8584 else
8585 is_first = 0;
8586
8587 vty_out(vty, "\"%s\":",
8588 (bgp->inst_type == BGP_INSTANCE_TYPE_DEFAULT)
8589 ? VRF_DEFAULT_NAME
8590 : bgp->name);
8591 } else {
8592 vty_out(vty, "\nInstance %s:\n",
8593 (bgp->inst_type == BGP_INSTANCE_TYPE_DEFAULT)
8594 ? VRF_DEFAULT_NAME
8595 : bgp->name);
8596 }
8597 bgp_show_summary_afi_safi(vty, bgp, afi, safi, show_failed,
8598 use_json);
8599 }
8600
8601 if (use_json)
8602 vty_out(vty, "}\n");
8603 else if (!nbr_output)
8604 vty_out(vty, "%% BGP instance not found\n");
8605 }
8606
8607 int bgp_show_summary_vty(struct vty *vty, const char *name, afi_t afi,
8608 safi_t safi, bool show_failed, bool use_json)
8609 {
8610 struct bgp *bgp;
8611
8612 if (name) {
8613 if (strmatch(name, "all")) {
8614 bgp_show_all_instances_summary_vty(vty, afi, safi,
8615 show_failed,
8616 use_json);
8617 return CMD_SUCCESS;
8618 } else {
8619 bgp = bgp_lookup_by_name(name);
8620
8621 if (!bgp) {
8622 if (use_json)
8623 vty_out(vty, "{}\n");
8624 else
8625 vty_out(vty,
8626 "%% BGP instance not found\n");
8627 return CMD_WARNING;
8628 }
8629
8630 bgp_show_summary_afi_safi(vty, bgp, afi, safi,
8631 show_failed, use_json);
8632 return CMD_SUCCESS;
8633 }
8634 }
8635
8636 bgp = bgp_get_default();
8637
8638 if (bgp)
8639 bgp_show_summary_afi_safi(vty, bgp, afi, safi, show_failed,
8640 use_json);
8641 else {
8642 if (use_json)
8643 vty_out(vty, "{}\n");
8644 else
8645 vty_out(vty, "%% BGP instance not found\n");
8646 return CMD_WARNING;
8647 }
8648
8649 return CMD_SUCCESS;
8650 }
8651
8652 /* `show [ip] bgp summary' commands. */
8653 DEFUN (show_ip_bgp_summary,
8654 show_ip_bgp_summary_cmd,
8655 "show [ip] bgp [<view|vrf> VIEWVRFNAME] ["BGP_AFI_CMD_STR" ["BGP_SAFI_WITH_LABEL_CMD_STR"]] summary [failed] [json]",
8656 SHOW_STR
8657 IP_STR
8658 BGP_STR
8659 BGP_INSTANCE_HELP_STR
8660 BGP_AFI_HELP_STR
8661 BGP_SAFI_WITH_LABEL_HELP_STR
8662 "Summary of BGP neighbor status\n"
8663 "Show only sessions not in Established state\n"
8664 JSON_STR)
8665 {
8666 char *vrf = NULL;
8667 afi_t afi = AFI_MAX;
8668 safi_t safi = SAFI_MAX;
8669 bool show_failed = false;
8670
8671 int idx = 0;
8672
8673 /* show [ip] bgp */
8674 if (argv_find(argv, argc, "ip", &idx))
8675 afi = AFI_IP;
8676 /* [<vrf> VIEWVRFNAME] */
8677 if (argv_find(argv, argc, "vrf", &idx)) {
8678 vrf = argv[idx + 1]->arg;
8679 if (vrf && strmatch(vrf, VRF_DEFAULT_NAME))
8680 vrf = NULL;
8681 } else if (argv_find(argv, argc, "view", &idx))
8682 /* [<view> VIEWVRFNAME] */
8683 vrf = argv[idx + 1]->arg;
8684 /* ["BGP_AFI_CMD_STR" ["BGP_SAFI_CMD_STR"]] */
8685 if (argv_find_and_parse_afi(argv, argc, &idx, &afi)) {
8686 argv_find_and_parse_safi(argv, argc, &idx, &safi);
8687 }
8688
8689 if (argv_find(argv, argc, "failed", &idx))
8690 show_failed = true;
8691
8692 bool uj = use_json(argc, argv);
8693
8694 return bgp_show_summary_vty(vty, vrf, afi, safi, show_failed, uj);
8695 }
8696
8697 const char *get_afi_safi_str(afi_t afi, safi_t safi, bool for_json)
8698 {
8699 if (for_json)
8700 return get_afi_safi_json_str(afi, safi);
8701 else
8702 return get_afi_safi_vty_str(afi, safi);
8703 }
8704
8705 /* Show BGP peer's information. */
8706 enum show_type { show_all, show_peer, show_ipv4_all, show_ipv6_all, show_ipv4_peer, show_ipv6_peer };
8707
8708 static void bgp_show_peer_afi_orf_cap(struct vty *vty, struct peer *p,
8709 afi_t afi, safi_t safi,
8710 uint16_t adv_smcap, uint16_t adv_rmcap,
8711 uint16_t rcv_smcap, uint16_t rcv_rmcap,
8712 bool use_json, json_object *json_pref)
8713 {
8714 /* Send-Mode */
8715 if (CHECK_FLAG(p->af_cap[afi][safi], adv_smcap)
8716 || CHECK_FLAG(p->af_cap[afi][safi], rcv_smcap)) {
8717 if (use_json) {
8718 if (CHECK_FLAG(p->af_cap[afi][safi], adv_smcap)
8719 && CHECK_FLAG(p->af_cap[afi][safi], rcv_smcap))
8720 json_object_string_add(json_pref, "sendMode",
8721 "advertisedAndReceived");
8722 else if (CHECK_FLAG(p->af_cap[afi][safi], adv_smcap))
8723 json_object_string_add(json_pref, "sendMode",
8724 "advertised");
8725 else if (CHECK_FLAG(p->af_cap[afi][safi], rcv_smcap))
8726 json_object_string_add(json_pref, "sendMode",
8727 "received");
8728 } else {
8729 vty_out(vty, " Send-mode: ");
8730 if (CHECK_FLAG(p->af_cap[afi][safi], adv_smcap))
8731 vty_out(vty, "advertised");
8732 if (CHECK_FLAG(p->af_cap[afi][safi], rcv_smcap))
8733 vty_out(vty, "%sreceived",
8734 CHECK_FLAG(p->af_cap[afi][safi],
8735 adv_smcap)
8736 ? ", "
8737 : "");
8738 vty_out(vty, "\n");
8739 }
8740 }
8741
8742 /* Receive-Mode */
8743 if (CHECK_FLAG(p->af_cap[afi][safi], adv_rmcap)
8744 || CHECK_FLAG(p->af_cap[afi][safi], rcv_rmcap)) {
8745 if (use_json) {
8746 if (CHECK_FLAG(p->af_cap[afi][safi], adv_rmcap)
8747 && CHECK_FLAG(p->af_cap[afi][safi], rcv_rmcap))
8748 json_object_string_add(json_pref, "recvMode",
8749 "advertisedAndReceived");
8750 else if (CHECK_FLAG(p->af_cap[afi][safi], adv_rmcap))
8751 json_object_string_add(json_pref, "recvMode",
8752 "advertised");
8753 else if (CHECK_FLAG(p->af_cap[afi][safi], rcv_rmcap))
8754 json_object_string_add(json_pref, "recvMode",
8755 "received");
8756 } else {
8757 vty_out(vty, " Receive-mode: ");
8758 if (CHECK_FLAG(p->af_cap[afi][safi], adv_rmcap))
8759 vty_out(vty, "advertised");
8760 if (CHECK_FLAG(p->af_cap[afi][safi], rcv_rmcap))
8761 vty_out(vty, "%sreceived",
8762 CHECK_FLAG(p->af_cap[afi][safi],
8763 adv_rmcap)
8764 ? ", "
8765 : "");
8766 vty_out(vty, "\n");
8767 }
8768 }
8769 }
8770
8771 static void bgp_show_peer_afi(struct vty *vty, struct peer *p, afi_t afi,
8772 safi_t safi, bool use_json,
8773 json_object *json_neigh)
8774 {
8775 struct bgp_filter *filter;
8776 struct peer_af *paf;
8777 char orf_pfx_name[BUFSIZ];
8778 int orf_pfx_count;
8779 json_object *json_af = NULL;
8780 json_object *json_prefA = NULL;
8781 json_object *json_prefB = NULL;
8782 json_object *json_addr = NULL;
8783
8784 if (use_json) {
8785 json_addr = json_object_new_object();
8786 json_af = json_object_new_object();
8787 filter = &p->filter[afi][safi];
8788
8789 if (peer_group_active(p))
8790 json_object_string_add(json_addr, "peerGroupMember",
8791 p->group->name);
8792
8793 paf = peer_af_find(p, afi, safi);
8794 if (paf && PAF_SUBGRP(paf)) {
8795 json_object_int_add(json_addr, "updateGroupId",
8796 PAF_UPDGRP(paf)->id);
8797 json_object_int_add(json_addr, "subGroupId",
8798 PAF_SUBGRP(paf)->id);
8799 json_object_int_add(json_addr, "packetQueueLength",
8800 bpacket_queue_virtual_length(paf));
8801 }
8802
8803 if (CHECK_FLAG(p->af_cap[afi][safi], PEER_CAP_ORF_PREFIX_SM_ADV)
8804 || CHECK_FLAG(p->af_cap[afi][safi],
8805 PEER_CAP_ORF_PREFIX_SM_RCV)
8806 || CHECK_FLAG(p->af_cap[afi][safi],
8807 PEER_CAP_ORF_PREFIX_RM_ADV)
8808 || CHECK_FLAG(p->af_cap[afi][safi],
8809 PEER_CAP_ORF_PREFIX_RM_RCV)) {
8810 json_object_int_add(json_af, "orfType",
8811 ORF_TYPE_PREFIX);
8812 json_prefA = json_object_new_object();
8813 bgp_show_peer_afi_orf_cap(vty, p, afi, safi,
8814 PEER_CAP_ORF_PREFIX_SM_ADV,
8815 PEER_CAP_ORF_PREFIX_RM_ADV,
8816 PEER_CAP_ORF_PREFIX_SM_RCV,
8817 PEER_CAP_ORF_PREFIX_RM_RCV,
8818 use_json, json_prefA);
8819 json_object_object_add(json_af, "orfPrefixList",
8820 json_prefA);
8821 }
8822
8823 if (CHECK_FLAG(p->af_cap[afi][safi], PEER_CAP_ORF_PREFIX_SM_ADV)
8824 || CHECK_FLAG(p->af_cap[afi][safi],
8825 PEER_CAP_ORF_PREFIX_SM_OLD_RCV)
8826 || CHECK_FLAG(p->af_cap[afi][safi],
8827 PEER_CAP_ORF_PREFIX_RM_ADV)
8828 || CHECK_FLAG(p->af_cap[afi][safi],
8829 PEER_CAP_ORF_PREFIX_RM_OLD_RCV)) {
8830 json_object_int_add(json_af, "orfOldType",
8831 ORF_TYPE_PREFIX_OLD);
8832 json_prefB = json_object_new_object();
8833 bgp_show_peer_afi_orf_cap(
8834 vty, p, afi, safi, PEER_CAP_ORF_PREFIX_SM_ADV,
8835 PEER_CAP_ORF_PREFIX_RM_ADV,
8836 PEER_CAP_ORF_PREFIX_SM_OLD_RCV,
8837 PEER_CAP_ORF_PREFIX_RM_OLD_RCV, use_json,
8838 json_prefB);
8839 json_object_object_add(json_af, "orfOldPrefixList",
8840 json_prefB);
8841 }
8842
8843 if (CHECK_FLAG(p->af_cap[afi][safi], PEER_CAP_ORF_PREFIX_SM_ADV)
8844 || CHECK_FLAG(p->af_cap[afi][safi],
8845 PEER_CAP_ORF_PREFIX_SM_RCV)
8846 || CHECK_FLAG(p->af_cap[afi][safi],
8847 PEER_CAP_ORF_PREFIX_SM_OLD_RCV)
8848 || CHECK_FLAG(p->af_cap[afi][safi],
8849 PEER_CAP_ORF_PREFIX_RM_ADV)
8850 || CHECK_FLAG(p->af_cap[afi][safi],
8851 PEER_CAP_ORF_PREFIX_RM_RCV)
8852 || CHECK_FLAG(p->af_cap[afi][safi],
8853 PEER_CAP_ORF_PREFIX_RM_OLD_RCV))
8854 json_object_object_add(json_addr, "afDependentCap",
8855 json_af);
8856 else
8857 json_object_free(json_af);
8858
8859 sprintf(orf_pfx_name, "%s.%d.%d", p->host, afi, safi);
8860 orf_pfx_count = prefix_bgp_show_prefix_list(
8861 NULL, afi, orf_pfx_name, use_json);
8862
8863 if (CHECK_FLAG(p->af_sflags[afi][safi],
8864 PEER_STATUS_ORF_PREFIX_SEND)
8865 || orf_pfx_count) {
8866 if (CHECK_FLAG(p->af_sflags[afi][safi],
8867 PEER_STATUS_ORF_PREFIX_SEND))
8868 json_object_boolean_true_add(json_neigh,
8869 "orfSent");
8870 if (orf_pfx_count)
8871 json_object_int_add(json_addr, "orfRecvCounter",
8872 orf_pfx_count);
8873 }
8874 if (CHECK_FLAG(p->af_sflags[afi][safi],
8875 PEER_STATUS_ORF_WAIT_REFRESH))
8876 json_object_string_add(
8877 json_addr, "orfFirstUpdate",
8878 "deferredUntilORFOrRouteRefreshRecvd");
8879
8880 if (CHECK_FLAG(p->af_flags[afi][safi],
8881 PEER_FLAG_REFLECTOR_CLIENT))
8882 json_object_boolean_true_add(json_addr,
8883 "routeReflectorClient");
8884 if (CHECK_FLAG(p->af_flags[afi][safi],
8885 PEER_FLAG_RSERVER_CLIENT))
8886 json_object_boolean_true_add(json_addr,
8887 "routeServerClient");
8888 if (CHECK_FLAG(p->af_flags[afi][safi], PEER_FLAG_SOFT_RECONFIG))
8889 json_object_boolean_true_add(json_addr,
8890 "inboundSoftConfigPermit");
8891
8892 if (CHECK_FLAG(p->af_flags[afi][safi],
8893 PEER_FLAG_REMOVE_PRIVATE_AS_ALL_REPLACE))
8894 json_object_boolean_true_add(
8895 json_addr,
8896 "privateAsNumsAllReplacedInUpdatesToNbr");
8897 else if (CHECK_FLAG(p->af_flags[afi][safi],
8898 PEER_FLAG_REMOVE_PRIVATE_AS_REPLACE))
8899 json_object_boolean_true_add(
8900 json_addr,
8901 "privateAsNumsReplacedInUpdatesToNbr");
8902 else if (CHECK_FLAG(p->af_flags[afi][safi],
8903 PEER_FLAG_REMOVE_PRIVATE_AS_ALL))
8904 json_object_boolean_true_add(
8905 json_addr,
8906 "privateAsNumsAllRemovedInUpdatesToNbr");
8907 else if (CHECK_FLAG(p->af_flags[afi][safi],
8908 PEER_FLAG_REMOVE_PRIVATE_AS))
8909 json_object_boolean_true_add(
8910 json_addr,
8911 "privateAsNumsRemovedInUpdatesToNbr");
8912
8913 if (p->addpath_type[afi][safi] != BGP_ADDPATH_NONE)
8914 json_object_boolean_true_add(
8915 json_addr,
8916 bgp_addpath_names(p->addpath_type[afi][safi])
8917 ->type_json_name);
8918
8919 if (CHECK_FLAG(p->af_flags[afi][safi], PEER_FLAG_AS_OVERRIDE))
8920 json_object_string_add(json_addr,
8921 "overrideASNsInOutboundUpdates",
8922 "ifAspathEqualRemoteAs");
8923
8924 if (CHECK_FLAG(p->af_flags[afi][safi], PEER_FLAG_NEXTHOP_SELF)
8925 || CHECK_FLAG(p->af_flags[afi][safi],
8926 PEER_FLAG_FORCE_NEXTHOP_SELF))
8927 json_object_boolean_true_add(json_addr,
8928 "routerAlwaysNextHop");
8929 if (CHECK_FLAG(p->af_flags[afi][safi],
8930 PEER_FLAG_AS_PATH_UNCHANGED))
8931 json_object_boolean_true_add(
8932 json_addr, "unchangedAsPathPropogatedToNbr");
8933 if (CHECK_FLAG(p->af_flags[afi][safi],
8934 PEER_FLAG_NEXTHOP_UNCHANGED))
8935 json_object_boolean_true_add(
8936 json_addr, "unchangedNextHopPropogatedToNbr");
8937 if (CHECK_FLAG(p->af_flags[afi][safi], PEER_FLAG_MED_UNCHANGED))
8938 json_object_boolean_true_add(
8939 json_addr, "unchangedMedPropogatedToNbr");
8940 if (CHECK_FLAG(p->af_flags[afi][safi], PEER_FLAG_SEND_COMMUNITY)
8941 || CHECK_FLAG(p->af_flags[afi][safi],
8942 PEER_FLAG_SEND_EXT_COMMUNITY)) {
8943 if (CHECK_FLAG(p->af_flags[afi][safi],
8944 PEER_FLAG_SEND_COMMUNITY)
8945 && CHECK_FLAG(p->af_flags[afi][safi],
8946 PEER_FLAG_SEND_EXT_COMMUNITY))
8947 json_object_string_add(json_addr,
8948 "commAttriSentToNbr",
8949 "extendedAndStandard");
8950 else if (CHECK_FLAG(p->af_flags[afi][safi],
8951 PEER_FLAG_SEND_EXT_COMMUNITY))
8952 json_object_string_add(json_addr,
8953 "commAttriSentToNbr",
8954 "extended");
8955 else
8956 json_object_string_add(json_addr,
8957 "commAttriSentToNbr",
8958 "standard");
8959 }
8960 if (CHECK_FLAG(p->af_flags[afi][safi],
8961 PEER_FLAG_DEFAULT_ORIGINATE)) {
8962 if (p->default_rmap[afi][safi].name)
8963 json_object_string_add(
8964 json_addr, "defaultRouteMap",
8965 p->default_rmap[afi][safi].name);
8966
8967 if (paf && PAF_SUBGRP(paf)
8968 && CHECK_FLAG(PAF_SUBGRP(paf)->sflags,
8969 SUBGRP_STATUS_DEFAULT_ORIGINATE))
8970 json_object_boolean_true_add(json_addr,
8971 "defaultSent");
8972 else
8973 json_object_boolean_true_add(json_addr,
8974 "defaultNotSent");
8975 }
8976
8977 if (afi == AFI_L2VPN && safi == SAFI_EVPN) {
8978 if (is_evpn_enabled())
8979 json_object_boolean_true_add(
8980 json_addr, "advertiseAllVnis");
8981 }
8982
8983 if (filter->plist[FILTER_IN].name
8984 || filter->dlist[FILTER_IN].name
8985 || filter->aslist[FILTER_IN].name
8986 || filter->map[RMAP_IN].name)
8987 json_object_boolean_true_add(json_addr,
8988 "inboundPathPolicyConfig");
8989 if (filter->plist[FILTER_OUT].name
8990 || filter->dlist[FILTER_OUT].name
8991 || filter->aslist[FILTER_OUT].name
8992 || filter->map[RMAP_OUT].name || filter->usmap.name)
8993 json_object_boolean_true_add(
8994 json_addr, "outboundPathPolicyConfig");
8995
8996 /* prefix-list */
8997 if (filter->plist[FILTER_IN].name)
8998 json_object_string_add(json_addr,
8999 "incomingUpdatePrefixFilterList",
9000 filter->plist[FILTER_IN].name);
9001 if (filter->plist[FILTER_OUT].name)
9002 json_object_string_add(json_addr,
9003 "outgoingUpdatePrefixFilterList",
9004 filter->plist[FILTER_OUT].name);
9005
9006 /* distribute-list */
9007 if (filter->dlist[FILTER_IN].name)
9008 json_object_string_add(
9009 json_addr, "incomingUpdateNetworkFilterList",
9010 filter->dlist[FILTER_IN].name);
9011 if (filter->dlist[FILTER_OUT].name)
9012 json_object_string_add(
9013 json_addr, "outgoingUpdateNetworkFilterList",
9014 filter->dlist[FILTER_OUT].name);
9015
9016 /* filter-list. */
9017 if (filter->aslist[FILTER_IN].name)
9018 json_object_string_add(json_addr,
9019 "incomingUpdateAsPathFilterList",
9020 filter->aslist[FILTER_IN].name);
9021 if (filter->aslist[FILTER_OUT].name)
9022 json_object_string_add(json_addr,
9023 "outgoingUpdateAsPathFilterList",
9024 filter->aslist[FILTER_OUT].name);
9025
9026 /* route-map. */
9027 if (filter->map[RMAP_IN].name)
9028 json_object_string_add(
9029 json_addr, "routeMapForIncomingAdvertisements",
9030 filter->map[RMAP_IN].name);
9031 if (filter->map[RMAP_OUT].name)
9032 json_object_string_add(
9033 json_addr, "routeMapForOutgoingAdvertisements",
9034 filter->map[RMAP_OUT].name);
9035
9036 /* ebgp-requires-policy (inbound) */
9037 if (p->bgp->ebgp_requires_policy == DEFAULT_EBGP_POLICY_ENABLED
9038 && !bgp_inbound_policy_exists(p, filter))
9039 json_object_string_add(
9040 json_addr, "inboundEbgpRequiresPolicy",
9041 "Inbound updates discarded due to missing policy");
9042
9043 /* ebgp-requires-policy (outbound) */
9044 if (p->bgp->ebgp_requires_policy == DEFAULT_EBGP_POLICY_ENABLED
9045 && (!bgp_outbound_policy_exists(p, filter)))
9046 json_object_string_add(
9047 json_addr, "outboundEbgpRequiresPolicy",
9048 "Outbound updates discarded due to missing policy");
9049
9050 /* unsuppress-map */
9051 if (filter->usmap.name)
9052 json_object_string_add(json_addr,
9053 "selectiveUnsuppressRouteMap",
9054 filter->usmap.name);
9055
9056 /* Receive prefix count */
9057 json_object_int_add(json_addr, "acceptedPrefixCounter",
9058 p->pcount[afi][safi]);
9059 if (paf && PAF_SUBGRP(paf))
9060 json_object_int_add(json_addr, "sentPrefixCounter",
9061 (PAF_SUBGRP(paf))->scount);
9062
9063 /* Maximum prefix */
9064 if (CHECK_FLAG(p->af_flags[afi][safi], PEER_FLAG_MAX_PREFIX)) {
9065 json_object_int_add(json_addr, "prefixAllowedMax",
9066 p->pmax[afi][safi]);
9067 if (CHECK_FLAG(p->af_flags[afi][safi],
9068 PEER_FLAG_MAX_PREFIX_WARNING))
9069 json_object_boolean_true_add(
9070 json_addr, "prefixAllowedMaxWarning");
9071 json_object_int_add(json_addr,
9072 "prefixAllowedWarningThresh",
9073 p->pmax_threshold[afi][safi]);
9074 if (p->pmax_restart[afi][safi])
9075 json_object_int_add(
9076 json_addr,
9077 "prefixAllowedRestartIntervalMsecs",
9078 p->pmax_restart[afi][safi] * 60000);
9079 }
9080 json_object_object_add(json_neigh, get_afi_safi_str(afi, safi, true),
9081 json_addr);
9082
9083 } else {
9084 filter = &p->filter[afi][safi];
9085
9086 vty_out(vty, " For address family: %s\n",
9087 get_afi_safi_str(afi, safi, false));
9088
9089 if (peer_group_active(p))
9090 vty_out(vty, " %s peer-group member\n",
9091 p->group->name);
9092
9093 paf = peer_af_find(p, afi, safi);
9094 if (paf && PAF_SUBGRP(paf)) {
9095 vty_out(vty, " Update group %" PRIu64
9096 ", subgroup %" PRIu64 "\n",
9097 PAF_UPDGRP(paf)->id, PAF_SUBGRP(paf)->id);
9098 vty_out(vty, " Packet Queue length %d\n",
9099 bpacket_queue_virtual_length(paf));
9100 } else {
9101 vty_out(vty, " Not part of any update group\n");
9102 }
9103 if (CHECK_FLAG(p->af_cap[afi][safi], PEER_CAP_ORF_PREFIX_SM_ADV)
9104 || CHECK_FLAG(p->af_cap[afi][safi],
9105 PEER_CAP_ORF_PREFIX_SM_RCV)
9106 || CHECK_FLAG(p->af_cap[afi][safi],
9107 PEER_CAP_ORF_PREFIX_SM_OLD_RCV)
9108 || CHECK_FLAG(p->af_cap[afi][safi],
9109 PEER_CAP_ORF_PREFIX_RM_ADV)
9110 || CHECK_FLAG(p->af_cap[afi][safi],
9111 PEER_CAP_ORF_PREFIX_RM_RCV)
9112 || CHECK_FLAG(p->af_cap[afi][safi],
9113 PEER_CAP_ORF_PREFIX_RM_OLD_RCV))
9114 vty_out(vty, " AF-dependant capabilities:\n");
9115
9116 if (CHECK_FLAG(p->af_cap[afi][safi], PEER_CAP_ORF_PREFIX_SM_ADV)
9117 || CHECK_FLAG(p->af_cap[afi][safi],
9118 PEER_CAP_ORF_PREFIX_SM_RCV)
9119 || CHECK_FLAG(p->af_cap[afi][safi],
9120 PEER_CAP_ORF_PREFIX_RM_ADV)
9121 || CHECK_FLAG(p->af_cap[afi][safi],
9122 PEER_CAP_ORF_PREFIX_RM_RCV)) {
9123 vty_out(vty,
9124 " Outbound Route Filter (ORF) type (%d) Prefix-list:\n",
9125 ORF_TYPE_PREFIX);
9126 bgp_show_peer_afi_orf_cap(
9127 vty, p, afi, safi, PEER_CAP_ORF_PREFIX_SM_ADV,
9128 PEER_CAP_ORF_PREFIX_RM_ADV,
9129 PEER_CAP_ORF_PREFIX_SM_RCV,
9130 PEER_CAP_ORF_PREFIX_RM_RCV, use_json, NULL);
9131 }
9132 if (CHECK_FLAG(p->af_cap[afi][safi], PEER_CAP_ORF_PREFIX_SM_ADV)
9133 || CHECK_FLAG(p->af_cap[afi][safi],
9134 PEER_CAP_ORF_PREFIX_SM_OLD_RCV)
9135 || CHECK_FLAG(p->af_cap[afi][safi],
9136 PEER_CAP_ORF_PREFIX_RM_ADV)
9137 || CHECK_FLAG(p->af_cap[afi][safi],
9138 PEER_CAP_ORF_PREFIX_RM_OLD_RCV)) {
9139 vty_out(vty,
9140 " Outbound Route Filter (ORF) type (%d) Prefix-list:\n",
9141 ORF_TYPE_PREFIX_OLD);
9142 bgp_show_peer_afi_orf_cap(
9143 vty, p, afi, safi, PEER_CAP_ORF_PREFIX_SM_ADV,
9144 PEER_CAP_ORF_PREFIX_RM_ADV,
9145 PEER_CAP_ORF_PREFIX_SM_OLD_RCV,
9146 PEER_CAP_ORF_PREFIX_RM_OLD_RCV, use_json, NULL);
9147 }
9148
9149 sprintf(orf_pfx_name, "%s.%d.%d", p->host, afi, safi);
9150 orf_pfx_count = prefix_bgp_show_prefix_list(
9151 NULL, afi, orf_pfx_name, use_json);
9152
9153 if (CHECK_FLAG(p->af_sflags[afi][safi],
9154 PEER_STATUS_ORF_PREFIX_SEND)
9155 || orf_pfx_count) {
9156 vty_out(vty, " Outbound Route Filter (ORF):");
9157 if (CHECK_FLAG(p->af_sflags[afi][safi],
9158 PEER_STATUS_ORF_PREFIX_SEND))
9159 vty_out(vty, " sent;");
9160 if (orf_pfx_count)
9161 vty_out(vty, " received (%d entries)",
9162 orf_pfx_count);
9163 vty_out(vty, "\n");
9164 }
9165 if (CHECK_FLAG(p->af_sflags[afi][safi],
9166 PEER_STATUS_ORF_WAIT_REFRESH))
9167 vty_out(vty,
9168 " First update is deferred until ORF or ROUTE-REFRESH is received\n");
9169
9170 if (CHECK_FLAG(p->af_flags[afi][safi],
9171 PEER_FLAG_REFLECTOR_CLIENT))
9172 vty_out(vty, " Route-Reflector Client\n");
9173 if (CHECK_FLAG(p->af_flags[afi][safi],
9174 PEER_FLAG_RSERVER_CLIENT))
9175 vty_out(vty, " Route-Server Client\n");
9176 if (CHECK_FLAG(p->af_flags[afi][safi], PEER_FLAG_SOFT_RECONFIG))
9177 vty_out(vty,
9178 " Inbound soft reconfiguration allowed\n");
9179
9180 if (CHECK_FLAG(p->af_flags[afi][safi],
9181 PEER_FLAG_REMOVE_PRIVATE_AS_ALL_REPLACE))
9182 vty_out(vty,
9183 " Private AS numbers (all) replaced in updates to this neighbor\n");
9184 else if (CHECK_FLAG(p->af_flags[afi][safi],
9185 PEER_FLAG_REMOVE_PRIVATE_AS_REPLACE))
9186 vty_out(vty,
9187 " Private AS numbers replaced in updates to this neighbor\n");
9188 else if (CHECK_FLAG(p->af_flags[afi][safi],
9189 PEER_FLAG_REMOVE_PRIVATE_AS_ALL))
9190 vty_out(vty,
9191 " Private AS numbers (all) removed in updates to this neighbor\n");
9192 else if (CHECK_FLAG(p->af_flags[afi][safi],
9193 PEER_FLAG_REMOVE_PRIVATE_AS))
9194 vty_out(vty,
9195 " Private AS numbers removed in updates to this neighbor\n");
9196
9197 if (p->addpath_type[afi][safi] != BGP_ADDPATH_NONE)
9198 vty_out(vty, " %s\n",
9199 bgp_addpath_names(p->addpath_type[afi][safi])
9200 ->human_description);
9201
9202 if (CHECK_FLAG(p->af_flags[afi][safi], PEER_FLAG_AS_OVERRIDE))
9203 vty_out(vty,
9204 " Override ASNs in outbound updates if aspath equals remote-as\n");
9205
9206 if (CHECK_FLAG(p->af_flags[afi][safi], PEER_FLAG_NEXTHOP_SELF)
9207 || CHECK_FLAG(p->af_flags[afi][safi],
9208 PEER_FLAG_FORCE_NEXTHOP_SELF))
9209 vty_out(vty, " NEXT_HOP is always this router\n");
9210 if (CHECK_FLAG(p->af_flags[afi][safi],
9211 PEER_FLAG_AS_PATH_UNCHANGED))
9212 vty_out(vty,
9213 " AS_PATH is propagated unchanged to this neighbor\n");
9214 if (CHECK_FLAG(p->af_flags[afi][safi],
9215 PEER_FLAG_NEXTHOP_UNCHANGED))
9216 vty_out(vty,
9217 " NEXT_HOP is propagated unchanged to this neighbor\n");
9218 if (CHECK_FLAG(p->af_flags[afi][safi], PEER_FLAG_MED_UNCHANGED))
9219 vty_out(vty,
9220 " MED is propagated unchanged to this neighbor\n");
9221 if (CHECK_FLAG(p->af_flags[afi][safi], PEER_FLAG_SEND_COMMUNITY)
9222 || CHECK_FLAG(p->af_flags[afi][safi],
9223 PEER_FLAG_SEND_EXT_COMMUNITY)
9224 || CHECK_FLAG(p->af_flags[afi][safi],
9225 PEER_FLAG_SEND_LARGE_COMMUNITY)) {
9226 vty_out(vty,
9227 " Community attribute sent to this neighbor");
9228 if (CHECK_FLAG(p->af_flags[afi][safi],
9229 PEER_FLAG_SEND_COMMUNITY)
9230 && CHECK_FLAG(p->af_flags[afi][safi],
9231 PEER_FLAG_SEND_EXT_COMMUNITY)
9232 && CHECK_FLAG(p->af_flags[afi][safi],
9233 PEER_FLAG_SEND_LARGE_COMMUNITY))
9234 vty_out(vty, "(all)\n");
9235 else if (CHECK_FLAG(p->af_flags[afi][safi],
9236 PEER_FLAG_SEND_LARGE_COMMUNITY))
9237 vty_out(vty, "(large)\n");
9238 else if (CHECK_FLAG(p->af_flags[afi][safi],
9239 PEER_FLAG_SEND_EXT_COMMUNITY))
9240 vty_out(vty, "(extended)\n");
9241 else
9242 vty_out(vty, "(standard)\n");
9243 }
9244 if (CHECK_FLAG(p->af_flags[afi][safi],
9245 PEER_FLAG_DEFAULT_ORIGINATE)) {
9246 vty_out(vty, " Default information originate,");
9247
9248 if (p->default_rmap[afi][safi].name)
9249 vty_out(vty, " default route-map %s%s,",
9250 p->default_rmap[afi][safi].map ? "*"
9251 : "",
9252 p->default_rmap[afi][safi].name);
9253 if (paf && PAF_SUBGRP(paf)
9254 && CHECK_FLAG(PAF_SUBGRP(paf)->sflags,
9255 SUBGRP_STATUS_DEFAULT_ORIGINATE))
9256 vty_out(vty, " default sent\n");
9257 else
9258 vty_out(vty, " default not sent\n");
9259 }
9260
9261 /* advertise-vni-all */
9262 if (afi == AFI_L2VPN && safi == SAFI_EVPN) {
9263 if (is_evpn_enabled())
9264 vty_out(vty, " advertise-all-vni\n");
9265 }
9266
9267 if (filter->plist[FILTER_IN].name
9268 || filter->dlist[FILTER_IN].name
9269 || filter->aslist[FILTER_IN].name
9270 || filter->map[RMAP_IN].name)
9271 vty_out(vty, " Inbound path policy configured\n");
9272 if (filter->plist[FILTER_OUT].name
9273 || filter->dlist[FILTER_OUT].name
9274 || filter->aslist[FILTER_OUT].name
9275 || filter->map[RMAP_OUT].name || filter->usmap.name)
9276 vty_out(vty, " Outbound path policy configured\n");
9277
9278 /* prefix-list */
9279 if (filter->plist[FILTER_IN].name)
9280 vty_out(vty,
9281 " Incoming update prefix filter list is %s%s\n",
9282 filter->plist[FILTER_IN].plist ? "*" : "",
9283 filter->plist[FILTER_IN].name);
9284 if (filter->plist[FILTER_OUT].name)
9285 vty_out(vty,
9286 " Outgoing update prefix filter list is %s%s\n",
9287 filter->plist[FILTER_OUT].plist ? "*" : "",
9288 filter->plist[FILTER_OUT].name);
9289
9290 /* distribute-list */
9291 if (filter->dlist[FILTER_IN].name)
9292 vty_out(vty,
9293 " Incoming update network filter list is %s%s\n",
9294 filter->dlist[FILTER_IN].alist ? "*" : "",
9295 filter->dlist[FILTER_IN].name);
9296 if (filter->dlist[FILTER_OUT].name)
9297 vty_out(vty,
9298 " Outgoing update network filter list is %s%s\n",
9299 filter->dlist[FILTER_OUT].alist ? "*" : "",
9300 filter->dlist[FILTER_OUT].name);
9301
9302 /* filter-list. */
9303 if (filter->aslist[FILTER_IN].name)
9304 vty_out(vty,
9305 " Incoming update AS path filter list is %s%s\n",
9306 filter->aslist[FILTER_IN].aslist ? "*" : "",
9307 filter->aslist[FILTER_IN].name);
9308 if (filter->aslist[FILTER_OUT].name)
9309 vty_out(vty,
9310 " Outgoing update AS path filter list is %s%s\n",
9311 filter->aslist[FILTER_OUT].aslist ? "*" : "",
9312 filter->aslist[FILTER_OUT].name);
9313
9314 /* route-map. */
9315 if (filter->map[RMAP_IN].name)
9316 vty_out(vty,
9317 " Route map for incoming advertisements is %s%s\n",
9318 filter->map[RMAP_IN].map ? "*" : "",
9319 filter->map[RMAP_IN].name);
9320 if (filter->map[RMAP_OUT].name)
9321 vty_out(vty,
9322 " Route map for outgoing advertisements is %s%s\n",
9323 filter->map[RMAP_OUT].map ? "*" : "",
9324 filter->map[RMAP_OUT].name);
9325
9326 /* ebgp-requires-policy (inbound) */
9327 if (p->bgp->ebgp_requires_policy == DEFAULT_EBGP_POLICY_ENABLED
9328 && !bgp_inbound_policy_exists(p, filter))
9329 vty_out(vty,
9330 " Inbound updates discarded due to missing policy\n");
9331
9332 /* ebgp-requires-policy (outbound) */
9333 if (p->bgp->ebgp_requires_policy == DEFAULT_EBGP_POLICY_ENABLED
9334 && !bgp_outbound_policy_exists(p, filter))
9335 vty_out(vty,
9336 " Outbound updates discarded due to missing policy\n");
9337
9338 /* unsuppress-map */
9339 if (filter->usmap.name)
9340 vty_out(vty,
9341 " Route map for selective unsuppress is %s%s\n",
9342 filter->usmap.map ? "*" : "",
9343 filter->usmap.name);
9344
9345 /* Receive prefix count */
9346 vty_out(vty, " %ld accepted prefixes\n", p->pcount[afi][safi]);
9347
9348 /* Maximum prefix */
9349 if (CHECK_FLAG(p->af_flags[afi][safi], PEER_FLAG_MAX_PREFIX)) {
9350 vty_out(vty, " Maximum prefixes allowed %ld%s\n",
9351 p->pmax[afi][safi],
9352 CHECK_FLAG(p->af_flags[afi][safi],
9353 PEER_FLAG_MAX_PREFIX_WARNING)
9354 ? " (warning-only)"
9355 : "");
9356 vty_out(vty, " Threshold for warning message %d%%",
9357 p->pmax_threshold[afi][safi]);
9358 if (p->pmax_restart[afi][safi])
9359 vty_out(vty, ", restart interval %d min",
9360 p->pmax_restart[afi][safi]);
9361 vty_out(vty, "\n");
9362 }
9363
9364 vty_out(vty, "\n");
9365 }
9366 }
9367
9368 static void bgp_show_peer(struct vty *vty, struct peer *p, bool use_json,
9369 json_object *json)
9370 {
9371 struct bgp *bgp;
9372 char buf1[PREFIX2STR_BUFFER], buf[SU_ADDRSTRLEN];
9373 char timebuf[BGP_UPTIME_LEN];
9374 char dn_flag[2];
9375 afi_t afi;
9376 safi_t safi;
9377 uint16_t i;
9378 uint8_t *msg;
9379 json_object *json_neigh = NULL;
9380 time_t epoch_tbuf;
9381
9382 bgp = p->bgp;
9383
9384 if (use_json)
9385 json_neigh = json_object_new_object();
9386
9387 memset(dn_flag, '\0', sizeof(dn_flag));
9388 if (!p->conf_if && peer_dynamic_neighbor(p))
9389 dn_flag[0] = '*';
9390
9391 if (!use_json) {
9392 if (p->conf_if) /* Configured interface name. */
9393 vty_out(vty, "BGP neighbor on %s: %s, ", p->conf_if,
9394 BGP_PEER_SU_UNSPEC(p)
9395 ? "None"
9396 : sockunion2str(&p->su, buf,
9397 SU_ADDRSTRLEN));
9398 else /* Configured IP address. */
9399 vty_out(vty, "BGP neighbor is %s%s, ", dn_flag,
9400 p->host);
9401 }
9402
9403 if (use_json) {
9404 if (p->conf_if && BGP_PEER_SU_UNSPEC(p))
9405 json_object_string_add(json_neigh, "bgpNeighborAddr",
9406 "none");
9407 else if (p->conf_if && !BGP_PEER_SU_UNSPEC(p))
9408 json_object_string_add(
9409 json_neigh, "bgpNeighborAddr",
9410 sockunion2str(&p->su, buf, SU_ADDRSTRLEN));
9411
9412 json_object_int_add(json_neigh, "remoteAs", p->as);
9413
9414 if (p->change_local_as)
9415 json_object_int_add(json_neigh, "localAs",
9416 p->change_local_as);
9417 else
9418 json_object_int_add(json_neigh, "localAs", p->local_as);
9419
9420 if (CHECK_FLAG(p->flags, PEER_FLAG_LOCAL_AS_NO_PREPEND))
9421 json_object_boolean_true_add(json_neigh,
9422 "localAsNoPrepend");
9423
9424 if (CHECK_FLAG(p->flags, PEER_FLAG_LOCAL_AS_REPLACE_AS))
9425 json_object_boolean_true_add(json_neigh,
9426 "localAsReplaceAs");
9427 } else {
9428 if ((p->as_type == AS_SPECIFIED) || (p->as_type == AS_EXTERNAL)
9429 || (p->as_type == AS_INTERNAL))
9430 vty_out(vty, "remote AS %u, ", p->as);
9431 else
9432 vty_out(vty, "remote AS Unspecified, ");
9433 vty_out(vty, "local AS %u%s%s, ",
9434 p->change_local_as ? p->change_local_as : p->local_as,
9435 CHECK_FLAG(p->flags, PEER_FLAG_LOCAL_AS_NO_PREPEND)
9436 ? " no-prepend"
9437 : "",
9438 CHECK_FLAG(p->flags, PEER_FLAG_LOCAL_AS_REPLACE_AS)
9439 ? " replace-as"
9440 : "");
9441 }
9442 /* peer type internal or confed-internal */
9443 if ((p->as == p->local_as) || (p->as_type == AS_INTERNAL)) {
9444 if (use_json) {
9445 if (CHECK_FLAG(bgp->config, BGP_CONFIG_CONFEDERATION))
9446 json_object_boolean_true_add(
9447 json_neigh, "nbrConfedInternalLink");
9448 else
9449 json_object_boolean_true_add(json_neigh,
9450 "nbrInternalLink");
9451 } else {
9452 if (CHECK_FLAG(bgp->config, BGP_CONFIG_CONFEDERATION))
9453 vty_out(vty, "confed-internal link\n");
9454 else
9455 vty_out(vty, "internal link\n");
9456 }
9457 /* peer type external or confed-external */
9458 } else if (p->as || (p->as_type == AS_EXTERNAL)) {
9459 if (use_json) {
9460 if (CHECK_FLAG(bgp->config, BGP_CONFIG_CONFEDERATION))
9461 json_object_boolean_true_add(
9462 json_neigh, "nbrConfedExternalLink");
9463 else
9464 json_object_boolean_true_add(json_neigh,
9465 "nbrExternalLink");
9466 } else {
9467 if (bgp_confederation_peers_check(bgp, p->as))
9468 vty_out(vty, "confed-external link\n");
9469 else
9470 vty_out(vty, "external link\n");
9471 }
9472 } else {
9473 if (use_json)
9474 json_object_boolean_true_add(json_neigh,
9475 "nbrUnspecifiedLink");
9476 else
9477 vty_out(vty, "unspecified link\n");
9478 }
9479
9480 /* Description. */
9481 if (p->desc) {
9482 if (use_json)
9483 json_object_string_add(json_neigh, "nbrDesc", p->desc);
9484 else
9485 vty_out(vty, " Description: %s\n", p->desc);
9486 }
9487
9488 if (p->hostname) {
9489 if (use_json) {
9490 if (p->hostname)
9491 json_object_string_add(json_neigh, "hostname",
9492 p->hostname);
9493
9494 if (p->domainname)
9495 json_object_string_add(json_neigh, "domainname",
9496 p->domainname);
9497 } else {
9498 if (p->domainname && (p->domainname[0] != '\0'))
9499 vty_out(vty, "Hostname: %s.%s\n", p->hostname,
9500 p->domainname);
9501 else
9502 vty_out(vty, "Hostname: %s\n", p->hostname);
9503 }
9504 }
9505
9506 /* Peer-group */
9507 if (p->group) {
9508 if (use_json) {
9509 json_object_string_add(json_neigh, "peerGroup",
9510 p->group->name);
9511
9512 if (dn_flag[0]) {
9513 struct prefix prefix, *range = NULL;
9514
9515 sockunion2hostprefix(&(p->su), &prefix);
9516 range = peer_group_lookup_dynamic_neighbor_range(
9517 p->group, &prefix);
9518
9519 if (range) {
9520 prefix2str(range, buf1, sizeof(buf1));
9521 json_object_string_add(
9522 json_neigh,
9523 "peerSubnetRangeGroup", buf1);
9524 }
9525 }
9526 } else {
9527 vty_out(vty,
9528 " Member of peer-group %s for session parameters\n",
9529 p->group->name);
9530
9531 if (dn_flag[0]) {
9532 struct prefix prefix, *range = NULL;
9533
9534 sockunion2hostprefix(&(p->su), &prefix);
9535 range = peer_group_lookup_dynamic_neighbor_range(
9536 p->group, &prefix);
9537
9538 if (range) {
9539 prefix2str(range, buf1, sizeof(buf1));
9540 vty_out(vty,
9541 " Belongs to the subnet range group: %s\n",
9542 buf1);
9543 }
9544 }
9545 }
9546 }
9547
9548 if (use_json) {
9549 /* Administrative shutdown. */
9550 if (CHECK_FLAG(p->flags, PEER_FLAG_SHUTDOWN))
9551 json_object_boolean_true_add(json_neigh,
9552 "adminShutDown");
9553
9554 /* BGP Version. */
9555 json_object_int_add(json_neigh, "bgpVersion", 4);
9556 json_object_string_add(
9557 json_neigh, "remoteRouterId",
9558 inet_ntop(AF_INET, &p->remote_id, buf1, sizeof(buf1)));
9559 json_object_string_add(
9560 json_neigh, "localRouterId",
9561 inet_ntop(AF_INET, &bgp->router_id, buf1,
9562 sizeof(buf1)));
9563
9564 /* Confederation */
9565 if (CHECK_FLAG(bgp->config, BGP_CONFIG_CONFEDERATION)
9566 && bgp_confederation_peers_check(bgp, p->as))
9567 json_object_boolean_true_add(json_neigh,
9568 "nbrCommonAdmin");
9569
9570 /* Status. */
9571 json_object_string_add(
9572 json_neigh, "bgpState",
9573 lookup_msg(bgp_status_msg, p->status, NULL));
9574
9575 if (p->status == Established) {
9576 time_t uptime;
9577
9578 uptime = bgp_clock();
9579 uptime -= p->uptime;
9580 epoch_tbuf = time(NULL) - uptime;
9581
9582 #if CONFDATE > 20200101
9583 CPP_NOTICE(
9584 "bgpTimerUp should be deprecated and can be removed now");
9585 #endif
9586 /*
9587 * bgpTimerUp was miliseconds that was accurate
9588 * up to 1 day, then the value returned
9589 * became garbage. So in order to provide
9590 * some level of backwards compatability,
9591 * we still provde the data, but now
9592 * we are returning the correct value
9593 * and also adding a new bgpTimerUpMsec
9594 * which will allow us to deprecate
9595 * this eventually
9596 */
9597 json_object_int_add(json_neigh, "bgpTimerUp",
9598 uptime * 1000);
9599 json_object_int_add(json_neigh, "bgpTimerUpMsec",
9600 uptime * 1000);
9601 json_object_string_add(json_neigh, "bgpTimerUpString",
9602 peer_uptime(p->uptime, timebuf,
9603 BGP_UPTIME_LEN, 0,
9604 NULL));
9605 json_object_int_add(json_neigh,
9606 "bgpTimerUpEstablishedEpoch",
9607 epoch_tbuf);
9608 }
9609
9610 else if (p->status == Active) {
9611 if (CHECK_FLAG(p->flags, PEER_FLAG_PASSIVE))
9612 json_object_string_add(json_neigh, "bgpStateIs",
9613 "passive");
9614 else if (CHECK_FLAG(p->sflags, PEER_STATUS_NSF_WAIT))
9615 json_object_string_add(json_neigh, "bgpStateIs",
9616 "passiveNSF");
9617 }
9618
9619 /* read timer */
9620 time_t uptime;
9621 struct tm *tm;
9622
9623 uptime = bgp_clock();
9624 uptime -= p->readtime;
9625 tm = gmtime(&uptime);
9626 json_object_int_add(json_neigh, "bgpTimerLastRead",
9627 (tm->tm_sec * 1000) + (tm->tm_min * 60000)
9628 + (tm->tm_hour * 3600000));
9629
9630 uptime = bgp_clock();
9631 uptime -= p->last_write;
9632 tm = gmtime(&uptime);
9633 json_object_int_add(json_neigh, "bgpTimerLastWrite",
9634 (tm->tm_sec * 1000) + (tm->tm_min * 60000)
9635 + (tm->tm_hour * 3600000));
9636
9637 uptime = bgp_clock();
9638 uptime -= p->update_time;
9639 tm = gmtime(&uptime);
9640 json_object_int_add(json_neigh, "bgpInUpdateElapsedTimeMsecs",
9641 (tm->tm_sec * 1000) + (tm->tm_min * 60000)
9642 + (tm->tm_hour * 3600000));
9643
9644 /* Configured timer values. */
9645 json_object_int_add(json_neigh, "bgpTimerHoldTimeMsecs",
9646 p->v_holdtime * 1000);
9647 json_object_int_add(json_neigh,
9648 "bgpTimerKeepAliveIntervalMsecs",
9649 p->v_keepalive * 1000);
9650 if (CHECK_FLAG(p->flags, PEER_FLAG_TIMER)) {
9651 json_object_int_add(json_neigh,
9652 "bgpTimerConfiguredHoldTimeMsecs",
9653 p->holdtime * 1000);
9654 json_object_int_add(
9655 json_neigh,
9656 "bgpTimerConfiguredKeepAliveIntervalMsecs",
9657 p->keepalive * 1000);
9658 } else if ((bgp->default_holdtime != BGP_DEFAULT_HOLDTIME)
9659 || (bgp->default_keepalive
9660 != BGP_DEFAULT_KEEPALIVE)) {
9661 json_object_int_add(json_neigh,
9662 "bgpTimerConfiguredHoldTimeMsecs",
9663 bgp->default_holdtime);
9664 json_object_int_add(
9665 json_neigh,
9666 "bgpTimerConfiguredKeepAliveIntervalMsecs",
9667 bgp->default_keepalive);
9668 }
9669 } else {
9670 /* Administrative shutdown. */
9671 if (CHECK_FLAG(p->flags, PEER_FLAG_SHUTDOWN))
9672 vty_out(vty, " Administratively shut down\n");
9673
9674 /* BGP Version. */
9675 vty_out(vty, " BGP version 4");
9676 vty_out(vty, ", remote router ID %s",
9677 inet_ntop(AF_INET, &p->remote_id, buf1, sizeof(buf1)));
9678 vty_out(vty, ", local router ID %s\n",
9679 inet_ntop(AF_INET, &bgp->router_id, buf1,
9680 sizeof(buf1)));
9681
9682 /* Confederation */
9683 if (CHECK_FLAG(bgp->config, BGP_CONFIG_CONFEDERATION)
9684 && bgp_confederation_peers_check(bgp, p->as))
9685 vty_out(vty,
9686 " Neighbor under common administration\n");
9687
9688 /* Status. */
9689 vty_out(vty, " BGP state = %s",
9690 lookup_msg(bgp_status_msg, p->status, NULL));
9691
9692 if (p->status == Established)
9693 vty_out(vty, ", up for %8s",
9694 peer_uptime(p->uptime, timebuf, BGP_UPTIME_LEN,
9695 0, NULL));
9696
9697 else if (p->status == Active) {
9698 if (CHECK_FLAG(p->flags, PEER_FLAG_PASSIVE))
9699 vty_out(vty, " (passive)");
9700 else if (CHECK_FLAG(p->sflags, PEER_STATUS_NSF_WAIT))
9701 vty_out(vty, " (NSF passive)");
9702 }
9703 vty_out(vty, "\n");
9704
9705 /* read timer */
9706 vty_out(vty, " Last read %s",
9707 peer_uptime(p->readtime, timebuf, BGP_UPTIME_LEN, 0,
9708 NULL));
9709 vty_out(vty, ", Last write %s\n",
9710 peer_uptime(p->last_write, timebuf, BGP_UPTIME_LEN, 0,
9711 NULL));
9712
9713 /* Configured timer values. */
9714 vty_out(vty,
9715 " Hold time is %d, keepalive interval is %d seconds\n",
9716 p->v_holdtime, p->v_keepalive);
9717 if (CHECK_FLAG(p->flags, PEER_FLAG_TIMER)) {
9718 vty_out(vty, " Configured hold time is %d",
9719 p->holdtime);
9720 vty_out(vty, ", keepalive interval is %d seconds\n",
9721 p->keepalive);
9722 } else if ((bgp->default_holdtime != BGP_DEFAULT_HOLDTIME)
9723 || (bgp->default_keepalive
9724 != BGP_DEFAULT_KEEPALIVE)) {
9725 vty_out(vty, " Configured hold time is %d",
9726 bgp->default_holdtime);
9727 vty_out(vty, ", keepalive interval is %d seconds\n",
9728 bgp->default_keepalive);
9729 }
9730 }
9731 /* Capability. */
9732 if (p->status == Established) {
9733 if (p->cap || p->afc_adv[AFI_IP][SAFI_UNICAST]
9734 || p->afc_recv[AFI_IP][SAFI_UNICAST]
9735 || p->afc_adv[AFI_IP][SAFI_MULTICAST]
9736 || p->afc_recv[AFI_IP][SAFI_MULTICAST]
9737 || p->afc_adv[AFI_IP6][SAFI_UNICAST]
9738 || p->afc_recv[AFI_IP6][SAFI_UNICAST]
9739 || p->afc_adv[AFI_IP6][SAFI_MULTICAST]
9740 || p->afc_recv[AFI_IP6][SAFI_MULTICAST]
9741 || p->afc_adv[AFI_IP6][SAFI_MPLS_VPN]
9742 || p->afc_recv[AFI_IP6][SAFI_MPLS_VPN]
9743 || p->afc_adv[AFI_IP6][SAFI_ENCAP]
9744 || p->afc_recv[AFI_IP6][SAFI_ENCAP]
9745 || p->afc_adv[AFI_IP6][SAFI_FLOWSPEC]
9746 || p->afc_recv[AFI_IP6][SAFI_FLOWSPEC]
9747 || p->afc_adv[AFI_IP][SAFI_ENCAP]
9748 || p->afc_recv[AFI_IP][SAFI_ENCAP]
9749 || p->afc_adv[AFI_IP][SAFI_FLOWSPEC]
9750 || p->afc_recv[AFI_IP][SAFI_FLOWSPEC]
9751 || p->afc_adv[AFI_IP][SAFI_MPLS_VPN]
9752 || p->afc_recv[AFI_IP][SAFI_MPLS_VPN]) {
9753 if (use_json) {
9754 json_object *json_cap = NULL;
9755
9756 json_cap = json_object_new_object();
9757
9758 /* AS4 */
9759 if (CHECK_FLAG(p->cap, PEER_CAP_AS4_RCV)
9760 || CHECK_FLAG(p->cap, PEER_CAP_AS4_ADV)) {
9761 if (CHECK_FLAG(p->cap, PEER_CAP_AS4_ADV)
9762 && CHECK_FLAG(p->cap,
9763 PEER_CAP_AS4_RCV))
9764 json_object_string_add(
9765 json_cap, "4byteAs",
9766 "advertisedAndReceived");
9767 else if (CHECK_FLAG(p->cap,
9768 PEER_CAP_AS4_ADV))
9769 json_object_string_add(
9770 json_cap, "4byteAs",
9771 "advertised");
9772 else if (CHECK_FLAG(p->cap,
9773 PEER_CAP_AS4_RCV))
9774 json_object_string_add(
9775 json_cap, "4byteAs",
9776 "received");
9777 }
9778
9779 /* AddPath */
9780 if (CHECK_FLAG(p->cap, PEER_CAP_ADDPATH_RCV)
9781 || CHECK_FLAG(p->cap,
9782 PEER_CAP_ADDPATH_ADV)) {
9783 json_object *json_add = NULL;
9784 const char *print_store;
9785
9786 json_add = json_object_new_object();
9787
9788 FOREACH_AFI_SAFI (afi, safi) {
9789 json_object *json_sub = NULL;
9790 json_sub =
9791 json_object_new_object();
9792 print_store = get_afi_safi_str(
9793 afi, safi, true);
9794
9795 if (CHECK_FLAG(
9796 p->af_cap[afi]
9797 [safi],
9798 PEER_CAP_ADDPATH_AF_TX_ADV)
9799 || CHECK_FLAG(
9800 p->af_cap[afi]
9801 [safi],
9802 PEER_CAP_ADDPATH_AF_TX_RCV)) {
9803 if (CHECK_FLAG(
9804 p->af_cap
9805 [afi]
9806 [safi],
9807 PEER_CAP_ADDPATH_AF_TX_ADV)
9808 && CHECK_FLAG(
9809 p->af_cap
9810 [afi]
9811 [safi],
9812 PEER_CAP_ADDPATH_AF_TX_RCV))
9813 json_object_boolean_true_add(
9814 json_sub,
9815 "txAdvertisedAndReceived");
9816 else if (
9817 CHECK_FLAG(
9818 p->af_cap
9819 [afi]
9820 [safi],
9821 PEER_CAP_ADDPATH_AF_TX_ADV))
9822 json_object_boolean_true_add(
9823 json_sub,
9824 "txAdvertised");
9825 else if (
9826 CHECK_FLAG(
9827 p->af_cap
9828 [afi]
9829 [safi],
9830 PEER_CAP_ADDPATH_AF_TX_RCV))
9831 json_object_boolean_true_add(
9832 json_sub,
9833 "txReceived");
9834 }
9835
9836 if (CHECK_FLAG(
9837 p->af_cap[afi]
9838 [safi],
9839 PEER_CAP_ADDPATH_AF_RX_ADV)
9840 || CHECK_FLAG(
9841 p->af_cap[afi]
9842 [safi],
9843 PEER_CAP_ADDPATH_AF_RX_RCV)) {
9844 if (CHECK_FLAG(
9845 p->af_cap
9846 [afi]
9847 [safi],
9848 PEER_CAP_ADDPATH_AF_RX_ADV)
9849 && CHECK_FLAG(
9850 p->af_cap
9851 [afi]
9852 [safi],
9853 PEER_CAP_ADDPATH_AF_RX_RCV))
9854 json_object_boolean_true_add(
9855 json_sub,
9856 "rxAdvertisedAndReceived");
9857 else if (
9858 CHECK_FLAG(
9859 p->af_cap
9860 [afi]
9861 [safi],
9862 PEER_CAP_ADDPATH_AF_RX_ADV))
9863 json_object_boolean_true_add(
9864 json_sub,
9865 "rxAdvertised");
9866 else if (
9867 CHECK_FLAG(
9868 p->af_cap
9869 [afi]
9870 [safi],
9871 PEER_CAP_ADDPATH_AF_RX_RCV))
9872 json_object_boolean_true_add(
9873 json_sub,
9874 "rxReceived");
9875 }
9876
9877 if (CHECK_FLAG(
9878 p->af_cap[afi]
9879 [safi],
9880 PEER_CAP_ADDPATH_AF_TX_ADV)
9881 || CHECK_FLAG(
9882 p->af_cap[afi]
9883 [safi],
9884 PEER_CAP_ADDPATH_AF_TX_RCV)
9885 || CHECK_FLAG(
9886 p->af_cap[afi]
9887 [safi],
9888 PEER_CAP_ADDPATH_AF_RX_ADV)
9889 || CHECK_FLAG(
9890 p->af_cap[afi]
9891 [safi],
9892 PEER_CAP_ADDPATH_AF_RX_RCV))
9893 json_object_object_add(
9894 json_add,
9895 print_store,
9896 json_sub);
9897 else
9898 json_object_free(
9899 json_sub);
9900 }
9901
9902 json_object_object_add(
9903 json_cap, "addPath", json_add);
9904 }
9905
9906 /* Dynamic */
9907 if (CHECK_FLAG(p->cap, PEER_CAP_DYNAMIC_RCV)
9908 || CHECK_FLAG(p->cap,
9909 PEER_CAP_DYNAMIC_ADV)) {
9910 if (CHECK_FLAG(p->cap,
9911 PEER_CAP_DYNAMIC_ADV)
9912 && CHECK_FLAG(p->cap,
9913 PEER_CAP_DYNAMIC_RCV))
9914 json_object_string_add(
9915 json_cap, "dynamic",
9916 "advertisedAndReceived");
9917 else if (CHECK_FLAG(
9918 p->cap,
9919 PEER_CAP_DYNAMIC_ADV))
9920 json_object_string_add(
9921 json_cap, "dynamic",
9922 "advertised");
9923 else if (CHECK_FLAG(
9924 p->cap,
9925 PEER_CAP_DYNAMIC_RCV))
9926 json_object_string_add(
9927 json_cap, "dynamic",
9928 "received");
9929 }
9930
9931 /* Extended nexthop */
9932 if (CHECK_FLAG(p->cap, PEER_CAP_ENHE_RCV)
9933 || CHECK_FLAG(p->cap, PEER_CAP_ENHE_ADV)) {
9934 json_object *json_nxt = NULL;
9935 const char *print_store;
9936
9937
9938 if (CHECK_FLAG(p->cap,
9939 PEER_CAP_ENHE_ADV)
9940 && CHECK_FLAG(p->cap,
9941 PEER_CAP_ENHE_RCV))
9942 json_object_string_add(
9943 json_cap,
9944 "extendedNexthop",
9945 "advertisedAndReceived");
9946 else if (CHECK_FLAG(p->cap,
9947 PEER_CAP_ENHE_ADV))
9948 json_object_string_add(
9949 json_cap,
9950 "extendedNexthop",
9951 "advertised");
9952 else if (CHECK_FLAG(p->cap,
9953 PEER_CAP_ENHE_RCV))
9954 json_object_string_add(
9955 json_cap,
9956 "extendedNexthop",
9957 "received");
9958
9959 if (CHECK_FLAG(p->cap,
9960 PEER_CAP_ENHE_RCV)) {
9961 json_nxt =
9962 json_object_new_object();
9963
9964 for (safi = SAFI_UNICAST;
9965 safi < SAFI_MAX; safi++) {
9966 if (CHECK_FLAG(
9967 p->af_cap
9968 [AFI_IP]
9969 [safi],
9970 PEER_CAP_ENHE_AF_RCV)) {
9971 print_store = get_afi_safi_str(
9972 AFI_IP,
9973 safi, true);
9974 json_object_string_add(
9975 json_nxt,
9976 print_store,
9977 "recieved"); /* misspelled for compatibility */
9978 }
9979 }
9980 json_object_object_add(
9981 json_cap,
9982 "extendedNexthopFamililesByPeer",
9983 json_nxt);
9984 }
9985 }
9986
9987 /* Route Refresh */
9988 if (CHECK_FLAG(p->cap, PEER_CAP_REFRESH_ADV)
9989 || CHECK_FLAG(p->cap,
9990 PEER_CAP_REFRESH_NEW_RCV)
9991 || CHECK_FLAG(p->cap,
9992 PEER_CAP_REFRESH_OLD_RCV)) {
9993 if (CHECK_FLAG(p->cap,
9994 PEER_CAP_REFRESH_ADV)
9995 && (CHECK_FLAG(
9996 p->cap,
9997 PEER_CAP_REFRESH_NEW_RCV)
9998 || CHECK_FLAG(
9999 p->cap,
10000 PEER_CAP_REFRESH_OLD_RCV))) {
10001 if (CHECK_FLAG(
10002 p->cap,
10003 PEER_CAP_REFRESH_OLD_RCV)
10004 && CHECK_FLAG(
10005 p->cap,
10006 PEER_CAP_REFRESH_NEW_RCV))
10007 json_object_string_add(
10008 json_cap,
10009 "routeRefresh",
10010 "advertisedAndReceivedOldNew");
10011 else {
10012 if (CHECK_FLAG(
10013 p->cap,
10014 PEER_CAP_REFRESH_OLD_RCV))
10015 json_object_string_add(
10016 json_cap,
10017 "routeRefresh",
10018 "advertisedAndReceivedOld");
10019 else
10020 json_object_string_add(
10021 json_cap,
10022 "routeRefresh",
10023 "advertisedAndReceivedNew");
10024 }
10025 } else if (
10026 CHECK_FLAG(
10027 p->cap,
10028 PEER_CAP_REFRESH_ADV))
10029 json_object_string_add(
10030 json_cap,
10031 "routeRefresh",
10032 "advertised");
10033 else if (
10034 CHECK_FLAG(
10035 p->cap,
10036 PEER_CAP_REFRESH_NEW_RCV)
10037 || CHECK_FLAG(
10038 p->cap,
10039 PEER_CAP_REFRESH_OLD_RCV))
10040 json_object_string_add(
10041 json_cap,
10042 "routeRefresh",
10043 "received");
10044 }
10045
10046 /* Multiprotocol Extensions */
10047 json_object *json_multi = NULL;
10048 json_multi = json_object_new_object();
10049
10050 FOREACH_AFI_SAFI (afi, safi) {
10051 if (p->afc_adv[afi][safi]
10052 || p->afc_recv[afi][safi]) {
10053 json_object *json_exten = NULL;
10054 json_exten =
10055 json_object_new_object();
10056
10057 if (p->afc_adv[afi][safi]
10058 && p->afc_recv[afi][safi])
10059 json_object_boolean_true_add(
10060 json_exten,
10061 "advertisedAndReceived");
10062 else if (p->afc_adv[afi][safi])
10063 json_object_boolean_true_add(
10064 json_exten,
10065 "advertised");
10066 else if (p->afc_recv[afi][safi])
10067 json_object_boolean_true_add(
10068 json_exten,
10069 "received");
10070
10071 json_object_object_add(
10072 json_multi,
10073 get_afi_safi_str(afi,
10074 safi,
10075 true),
10076 json_exten);
10077 }
10078 }
10079 json_object_object_add(
10080 json_cap, "multiprotocolExtensions",
10081 json_multi);
10082
10083 /* Hostname capabilities */
10084 json_object *json_hname = NULL;
10085
10086 json_hname = json_object_new_object();
10087
10088 if (CHECK_FLAG(p->cap, PEER_CAP_HOSTNAME_ADV)) {
10089 json_object_string_add(
10090 json_hname, "advHostName",
10091 bgp->peer_self->hostname
10092 ? bgp->peer_self
10093 ->hostname
10094 : "n/a");
10095 json_object_string_add(
10096 json_hname, "advDomainName",
10097 bgp->peer_self->domainname
10098 ? bgp->peer_self
10099 ->domainname
10100 : "n/a");
10101 }
10102
10103
10104 if (CHECK_FLAG(p->cap, PEER_CAP_HOSTNAME_RCV)) {
10105 json_object_string_add(
10106 json_hname, "rcvHostName",
10107 p->hostname ? p->hostname
10108 : "n/a");
10109 json_object_string_add(
10110 json_hname, "rcvDomainName",
10111 p->domainname ? p->domainname
10112 : "n/a");
10113 }
10114
10115 json_object_object_add(json_cap, "hostName",
10116 json_hname);
10117
10118 /* Gracefull Restart */
10119 if (CHECK_FLAG(p->cap, PEER_CAP_RESTART_RCV)
10120 || CHECK_FLAG(p->cap,
10121 PEER_CAP_RESTART_ADV)) {
10122 if (CHECK_FLAG(p->cap,
10123 PEER_CAP_RESTART_ADV)
10124 && CHECK_FLAG(p->cap,
10125 PEER_CAP_RESTART_RCV))
10126 json_object_string_add(
10127 json_cap,
10128 "gracefulRestart",
10129 "advertisedAndReceived");
10130 else if (CHECK_FLAG(
10131 p->cap,
10132 PEER_CAP_RESTART_ADV))
10133 json_object_string_add(
10134 json_cap,
10135 "gracefulRestartCapability",
10136 "advertised");
10137 else if (CHECK_FLAG(
10138 p->cap,
10139 PEER_CAP_RESTART_RCV))
10140 json_object_string_add(
10141 json_cap,
10142 "gracefulRestartCapability",
10143 "received");
10144
10145 if (CHECK_FLAG(p->cap,
10146 PEER_CAP_RESTART_RCV)) {
10147 int restart_af_count = 0;
10148 json_object *json_restart =
10149 NULL;
10150 json_restart =
10151 json_object_new_object();
10152
10153 json_object_int_add(
10154 json_cap,
10155 "gracefulRestartRemoteTimerMsecs",
10156 p->v_gr_restart * 1000);
10157
10158 FOREACH_AFI_SAFI (afi, safi) {
10159 if (CHECK_FLAG(
10160 p->af_cap
10161 [afi]
10162 [safi],
10163 PEER_CAP_RESTART_AF_RCV)) {
10164 json_object *
10165 json_sub =
10166 NULL;
10167 json_sub =
10168 json_object_new_object();
10169
10170 if (CHECK_FLAG(
10171 p->af_cap
10172 [afi]
10173 [safi],
10174 PEER_CAP_RESTART_AF_PRESERVE_RCV))
10175 json_object_boolean_true_add(
10176 json_sub,
10177 "preserved");
10178 restart_af_count++;
10179 json_object_object_add(
10180 json_restart,
10181 get_afi_safi_str(
10182 afi,
10183 safi,
10184 true),
10185 json_sub);
10186 }
10187 }
10188 if (!restart_af_count) {
10189 json_object_string_add(
10190 json_cap,
10191 "addressFamiliesByPeer",
10192 "none");
10193 json_object_free(
10194 json_restart);
10195 } else
10196 json_object_object_add(
10197 json_cap,
10198 "addressFamiliesByPeer",
10199 json_restart);
10200 }
10201 }
10202 json_object_object_add(json_neigh,
10203 "neighborCapabilities",
10204 json_cap);
10205 } else {
10206 vty_out(vty, " Neighbor capabilities:\n");
10207
10208 /* AS4 */
10209 if (CHECK_FLAG(p->cap, PEER_CAP_AS4_RCV)
10210 || CHECK_FLAG(p->cap, PEER_CAP_AS4_ADV)) {
10211 vty_out(vty, " 4 Byte AS:");
10212 if (CHECK_FLAG(p->cap,
10213 PEER_CAP_AS4_ADV))
10214 vty_out(vty, " advertised");
10215 if (CHECK_FLAG(p->cap,
10216 PEER_CAP_AS4_RCV))
10217 vty_out(vty, " %sreceived",
10218 CHECK_FLAG(
10219 p->cap,
10220 PEER_CAP_AS4_ADV)
10221 ? "and "
10222 : "");
10223 vty_out(vty, "\n");
10224 }
10225
10226 /* AddPath */
10227 if (CHECK_FLAG(p->cap, PEER_CAP_ADDPATH_RCV)
10228 || CHECK_FLAG(p->cap,
10229 PEER_CAP_ADDPATH_ADV)) {
10230 vty_out(vty, " AddPath:\n");
10231
10232 FOREACH_AFI_SAFI (afi, safi) {
10233 if (CHECK_FLAG(
10234 p->af_cap[afi]
10235 [safi],
10236 PEER_CAP_ADDPATH_AF_TX_ADV)
10237 || CHECK_FLAG(
10238 p->af_cap[afi]
10239 [safi],
10240 PEER_CAP_ADDPATH_AF_TX_RCV)) {
10241 vty_out(vty,
10242 " %s: TX ",
10243 get_afi_safi_str(
10244 afi,
10245 safi,
10246 false));
10247
10248 if (CHECK_FLAG(
10249 p->af_cap
10250 [afi]
10251 [safi],
10252 PEER_CAP_ADDPATH_AF_TX_ADV))
10253 vty_out(vty,
10254 "advertised %s",
10255 get_afi_safi_str(
10256 afi,
10257 safi,
10258 false));
10259
10260 if (CHECK_FLAG(
10261 p->af_cap
10262 [afi]
10263 [safi],
10264 PEER_CAP_ADDPATH_AF_TX_RCV))
10265 vty_out(vty,
10266 "%sreceived",
10267 CHECK_FLAG(
10268 p->af_cap
10269 [afi]
10270 [safi],
10271 PEER_CAP_ADDPATH_AF_TX_ADV)
10272 ? " and "
10273 : "");
10274
10275 vty_out(vty, "\n");
10276 }
10277
10278 if (CHECK_FLAG(
10279 p->af_cap[afi]
10280 [safi],
10281 PEER_CAP_ADDPATH_AF_RX_ADV)
10282 || CHECK_FLAG(
10283 p->af_cap[afi]
10284 [safi],
10285 PEER_CAP_ADDPATH_AF_RX_RCV)) {
10286 vty_out(vty,
10287 " %s: RX ",
10288 get_afi_safi_str(
10289 afi,
10290 safi,
10291 false));
10292
10293 if (CHECK_FLAG(
10294 p->af_cap
10295 [afi]
10296 [safi],
10297 PEER_CAP_ADDPATH_AF_RX_ADV))
10298 vty_out(vty,
10299 "advertised %s",
10300 get_afi_safi_str(
10301 afi,
10302 safi,
10303 false));
10304
10305 if (CHECK_FLAG(
10306 p->af_cap
10307 [afi]
10308 [safi],
10309 PEER_CAP_ADDPATH_AF_RX_RCV))
10310 vty_out(vty,
10311 "%sreceived",
10312 CHECK_FLAG(
10313 p->af_cap
10314 [afi]
10315 [safi],
10316 PEER_CAP_ADDPATH_AF_RX_ADV)
10317 ? " and "
10318 : "");
10319
10320 vty_out(vty, "\n");
10321 }
10322 }
10323 }
10324
10325 /* Dynamic */
10326 if (CHECK_FLAG(p->cap, PEER_CAP_DYNAMIC_RCV)
10327 || CHECK_FLAG(p->cap,
10328 PEER_CAP_DYNAMIC_ADV)) {
10329 vty_out(vty, " Dynamic:");
10330 if (CHECK_FLAG(p->cap,
10331 PEER_CAP_DYNAMIC_ADV))
10332 vty_out(vty, " advertised");
10333 if (CHECK_FLAG(p->cap,
10334 PEER_CAP_DYNAMIC_RCV))
10335 vty_out(vty, " %sreceived",
10336 CHECK_FLAG(
10337 p->cap,
10338 PEER_CAP_DYNAMIC_ADV)
10339 ? "and "
10340 : "");
10341 vty_out(vty, "\n");
10342 }
10343
10344 /* Extended nexthop */
10345 if (CHECK_FLAG(p->cap, PEER_CAP_ENHE_RCV)
10346 || CHECK_FLAG(p->cap, PEER_CAP_ENHE_ADV)) {
10347 vty_out(vty, " Extended nexthop:");
10348 if (CHECK_FLAG(p->cap,
10349 PEER_CAP_ENHE_ADV))
10350 vty_out(vty, " advertised");
10351 if (CHECK_FLAG(p->cap,
10352 PEER_CAP_ENHE_RCV))
10353 vty_out(vty, " %sreceived",
10354 CHECK_FLAG(
10355 p->cap,
10356 PEER_CAP_ENHE_ADV)
10357 ? "and "
10358 : "");
10359 vty_out(vty, "\n");
10360
10361 if (CHECK_FLAG(p->cap,
10362 PEER_CAP_ENHE_RCV)) {
10363 vty_out(vty,
10364 " Address families by peer:\n ");
10365 for (safi = SAFI_UNICAST;
10366 safi < SAFI_MAX; safi++)
10367 if (CHECK_FLAG(
10368 p->af_cap
10369 [AFI_IP]
10370 [safi],
10371 PEER_CAP_ENHE_AF_RCV))
10372 vty_out(vty,
10373 " %s\n",
10374 get_afi_safi_str(
10375 AFI_IP,
10376 safi,
10377 false));
10378 }
10379 }
10380
10381 /* Route Refresh */
10382 if (CHECK_FLAG(p->cap, PEER_CAP_REFRESH_ADV)
10383 || CHECK_FLAG(p->cap,
10384 PEER_CAP_REFRESH_NEW_RCV)
10385 || CHECK_FLAG(p->cap,
10386 PEER_CAP_REFRESH_OLD_RCV)) {
10387 vty_out(vty, " Route refresh:");
10388 if (CHECK_FLAG(p->cap,
10389 PEER_CAP_REFRESH_ADV))
10390 vty_out(vty, " advertised");
10391 if (CHECK_FLAG(p->cap,
10392 PEER_CAP_REFRESH_NEW_RCV)
10393 || CHECK_FLAG(
10394 p->cap,
10395 PEER_CAP_REFRESH_OLD_RCV))
10396 vty_out(vty, " %sreceived(%s)",
10397 CHECK_FLAG(
10398 p->cap,
10399 PEER_CAP_REFRESH_ADV)
10400 ? "and "
10401 : "",
10402 (CHECK_FLAG(
10403 p->cap,
10404 PEER_CAP_REFRESH_OLD_RCV)
10405 && CHECK_FLAG(
10406 p->cap,
10407 PEER_CAP_REFRESH_NEW_RCV))
10408 ? "old & new"
10409 : CHECK_FLAG(
10410 p->cap,
10411 PEER_CAP_REFRESH_OLD_RCV)
10412 ? "old"
10413 : "new");
10414
10415 vty_out(vty, "\n");
10416 }
10417
10418 /* Multiprotocol Extensions */
10419 FOREACH_AFI_SAFI (afi, safi)
10420 if (p->afc_adv[afi][safi]
10421 || p->afc_recv[afi][safi]) {
10422 vty_out(vty,
10423 " Address Family %s:",
10424 get_afi_safi_str(
10425 afi,
10426 safi,
10427 false));
10428 if (p->afc_adv[afi][safi])
10429 vty_out(vty,
10430 " advertised");
10431 if (p->afc_recv[afi][safi])
10432 vty_out(vty,
10433 " %sreceived",
10434 p->afc_adv[afi]
10435 [safi]
10436 ? "and "
10437 : "");
10438 vty_out(vty, "\n");
10439 }
10440
10441 /* Hostname capability */
10442 vty_out(vty, " Hostname Capability:");
10443
10444 if (CHECK_FLAG(p->cap, PEER_CAP_HOSTNAME_ADV)) {
10445 vty_out(vty,
10446 " advertised (name: %s,domain name: %s)",
10447 bgp->peer_self->hostname
10448 ? bgp->peer_self
10449 ->hostname
10450 : "n/a",
10451 bgp->peer_self->domainname
10452 ? bgp->peer_self
10453 ->domainname
10454 : "n/a");
10455 } else {
10456 vty_out(vty, " not advertised");
10457 }
10458
10459 if (CHECK_FLAG(p->cap, PEER_CAP_HOSTNAME_RCV)) {
10460 vty_out(vty,
10461 " received (name: %s,domain name: %s)",
10462 p->hostname ? p->hostname
10463 : "n/a",
10464 p->domainname ? p->domainname
10465 : "n/a");
10466 } else {
10467 vty_out(vty, " not received");
10468 }
10469
10470 vty_out(vty, "\n");
10471
10472 /* Gracefull Restart */
10473 if (CHECK_FLAG(p->cap, PEER_CAP_RESTART_RCV)
10474 || CHECK_FLAG(p->cap,
10475 PEER_CAP_RESTART_ADV)) {
10476 vty_out(vty,
10477 " Graceful Restart Capabilty:");
10478 if (CHECK_FLAG(p->cap,
10479 PEER_CAP_RESTART_ADV))
10480 vty_out(vty, " advertised");
10481 if (CHECK_FLAG(p->cap,
10482 PEER_CAP_RESTART_RCV))
10483 vty_out(vty, " %sreceived",
10484 CHECK_FLAG(
10485 p->cap,
10486 PEER_CAP_RESTART_ADV)
10487 ? "and "
10488 : "");
10489 vty_out(vty, "\n");
10490
10491 if (CHECK_FLAG(p->cap,
10492 PEER_CAP_RESTART_RCV)) {
10493 int restart_af_count = 0;
10494
10495 vty_out(vty,
10496 " Remote Restart timer is %d seconds\n",
10497 p->v_gr_restart);
10498 vty_out(vty,
10499 " Address families by peer:\n ");
10500
10501 FOREACH_AFI_SAFI (afi, safi)
10502 if (CHECK_FLAG(
10503 p->af_cap
10504 [afi]
10505 [safi],
10506 PEER_CAP_RESTART_AF_RCV)) {
10507 vty_out(vty,
10508 "%s%s(%s)",
10509 restart_af_count
10510 ? ", "
10511 : "",
10512 get_afi_safi_str(
10513 afi,
10514 safi,
10515 false),
10516 CHECK_FLAG(
10517 p->af_cap
10518 [afi]
10519 [safi],
10520 PEER_CAP_RESTART_AF_PRESERVE_RCV)
10521 ? "preserved"
10522 : "not preserved");
10523 restart_af_count++;
10524 }
10525 if (!restart_af_count)
10526 vty_out(vty, "none");
10527 vty_out(vty, "\n");
10528 }
10529 }
10530 }
10531 }
10532 }
10533
10534 /* graceful restart information */
10535 if (CHECK_FLAG(p->cap, PEER_CAP_RESTART_RCV) || p->t_gr_restart
10536 || p->t_gr_stale) {
10537 json_object *json_grace = NULL;
10538 json_object *json_grace_send = NULL;
10539 json_object *json_grace_recv = NULL;
10540 int eor_send_af_count = 0;
10541 int eor_receive_af_count = 0;
10542
10543 if (use_json) {
10544 json_grace = json_object_new_object();
10545 json_grace_send = json_object_new_object();
10546 json_grace_recv = json_object_new_object();
10547
10548 if (p->status == Established) {
10549 FOREACH_AFI_SAFI (afi, safi) {
10550 if (CHECK_FLAG(p->af_sflags[afi][safi],
10551 PEER_STATUS_EOR_SEND)) {
10552 json_object_boolean_true_add(
10553 json_grace_send,
10554 get_afi_safi_str(afi,
10555 safi,
10556 true));
10557 eor_send_af_count++;
10558 }
10559 }
10560 FOREACH_AFI_SAFI (afi, safi) {
10561 if (CHECK_FLAG(
10562 p->af_sflags[afi][safi],
10563 PEER_STATUS_EOR_RECEIVED)) {
10564 json_object_boolean_true_add(
10565 json_grace_recv,
10566 get_afi_safi_str(afi,
10567 safi,
10568 true));
10569 eor_receive_af_count++;
10570 }
10571 }
10572 }
10573
10574 json_object_object_add(json_grace, "endOfRibSend",
10575 json_grace_send);
10576 json_object_object_add(json_grace, "endOfRibRecv",
10577 json_grace_recv);
10578
10579 if (p->t_gr_restart)
10580 json_object_int_add(json_grace,
10581 "gracefulRestartTimerMsecs",
10582 thread_timer_remain_second(
10583 p->t_gr_restart)
10584 * 1000);
10585
10586 if (p->t_gr_stale)
10587 json_object_int_add(
10588 json_grace,
10589 "gracefulStalepathTimerMsecs",
10590 thread_timer_remain_second(
10591 p->t_gr_stale)
10592 * 1000);
10593
10594 json_object_object_add(
10595 json_neigh, "gracefulRestartInfo", json_grace);
10596 } else {
10597 vty_out(vty, " Graceful restart information:\n");
10598 if (p->status == Established) {
10599 vty_out(vty, " End-of-RIB send: ");
10600 FOREACH_AFI_SAFI (afi, safi) {
10601 if (CHECK_FLAG(p->af_sflags[afi][safi],
10602 PEER_STATUS_EOR_SEND)) {
10603 vty_out(vty, "%s%s",
10604 eor_send_af_count ? ", "
10605 : "",
10606 get_afi_safi_str(afi,
10607 safi,
10608 false));
10609 eor_send_af_count++;
10610 }
10611 }
10612 vty_out(vty, "\n");
10613 vty_out(vty, " End-of-RIB received: ");
10614 FOREACH_AFI_SAFI (afi, safi) {
10615 if (CHECK_FLAG(
10616 p->af_sflags[afi][safi],
10617 PEER_STATUS_EOR_RECEIVED)) {
10618 vty_out(vty, "%s%s",
10619 eor_receive_af_count
10620 ? ", "
10621 : "",
10622 get_afi_safi_str(afi,
10623 safi,
10624 false));
10625 eor_receive_af_count++;
10626 }
10627 }
10628 vty_out(vty, "\n");
10629 }
10630
10631 if (p->t_gr_restart)
10632 vty_out(vty,
10633 " The remaining time of restart timer is %ld\n",
10634 thread_timer_remain_second(
10635 p->t_gr_restart));
10636
10637 if (p->t_gr_stale)
10638 vty_out(vty,
10639 " The remaining time of stalepath timer is %ld\n",
10640 thread_timer_remain_second(
10641 p->t_gr_stale));
10642 }
10643 }
10644 if (use_json) {
10645 json_object *json_stat = NULL;
10646 json_stat = json_object_new_object();
10647 /* Packet counts. */
10648 json_object_int_add(json_stat, "depthInq", 0);
10649 json_object_int_add(json_stat, "depthOutq",
10650 (unsigned long)p->obuf->count);
10651 json_object_int_add(json_stat, "opensSent",
10652 atomic_load_explicit(&p->open_out,
10653 memory_order_relaxed));
10654 json_object_int_add(json_stat, "opensRecv",
10655 atomic_load_explicit(&p->open_in,
10656 memory_order_relaxed));
10657 json_object_int_add(json_stat, "notificationsSent",
10658 atomic_load_explicit(&p->notify_out,
10659 memory_order_relaxed));
10660 json_object_int_add(json_stat, "notificationsRecv",
10661 atomic_load_explicit(&p->notify_in,
10662 memory_order_relaxed));
10663 json_object_int_add(json_stat, "updatesSent",
10664 atomic_load_explicit(&p->update_out,
10665 memory_order_relaxed));
10666 json_object_int_add(json_stat, "updatesRecv",
10667 atomic_load_explicit(&p->update_in,
10668 memory_order_relaxed));
10669 json_object_int_add(json_stat, "keepalivesSent",
10670 atomic_load_explicit(&p->keepalive_out,
10671 memory_order_relaxed));
10672 json_object_int_add(json_stat, "keepalivesRecv",
10673 atomic_load_explicit(&p->keepalive_in,
10674 memory_order_relaxed));
10675 json_object_int_add(json_stat, "routeRefreshSent",
10676 atomic_load_explicit(&p->refresh_out,
10677 memory_order_relaxed));
10678 json_object_int_add(json_stat, "routeRefreshRecv",
10679 atomic_load_explicit(&p->refresh_in,
10680 memory_order_relaxed));
10681 json_object_int_add(json_stat, "capabilitySent",
10682 atomic_load_explicit(&p->dynamic_cap_out,
10683 memory_order_relaxed));
10684 json_object_int_add(json_stat, "capabilityRecv",
10685 atomic_load_explicit(&p->dynamic_cap_in,
10686 memory_order_relaxed));
10687 json_object_int_add(json_stat, "totalSent", PEER_TOTAL_TX(p));
10688 json_object_int_add(json_stat, "totalRecv", PEER_TOTAL_RX(p));
10689 json_object_object_add(json_neigh, "messageStats", json_stat);
10690 } else {
10691 /* Packet counts. */
10692 vty_out(vty, " Message statistics:\n");
10693 vty_out(vty, " Inq depth is 0\n");
10694 vty_out(vty, " Outq depth is %lu\n",
10695 (unsigned long)p->obuf->count);
10696 vty_out(vty, " Sent Rcvd\n");
10697 vty_out(vty, " Opens: %10d %10d\n",
10698 atomic_load_explicit(&p->open_out,
10699 memory_order_relaxed),
10700 atomic_load_explicit(&p->open_in,
10701 memory_order_relaxed));
10702 vty_out(vty, " Notifications: %10d %10d\n",
10703 atomic_load_explicit(&p->notify_out,
10704 memory_order_relaxed),
10705 atomic_load_explicit(&p->notify_in,
10706 memory_order_relaxed));
10707 vty_out(vty, " Updates: %10d %10d\n",
10708 atomic_load_explicit(&p->update_out,
10709 memory_order_relaxed),
10710 atomic_load_explicit(&p->update_in,
10711 memory_order_relaxed));
10712 vty_out(vty, " Keepalives: %10d %10d\n",
10713 atomic_load_explicit(&p->keepalive_out,
10714 memory_order_relaxed),
10715 atomic_load_explicit(&p->keepalive_in,
10716 memory_order_relaxed));
10717 vty_out(vty, " Route Refresh: %10d %10d\n",
10718 atomic_load_explicit(&p->refresh_out,
10719 memory_order_relaxed),
10720 atomic_load_explicit(&p->refresh_in,
10721 memory_order_relaxed));
10722 vty_out(vty, " Capability: %10d %10d\n",
10723 atomic_load_explicit(&p->dynamic_cap_out,
10724 memory_order_relaxed),
10725 atomic_load_explicit(&p->dynamic_cap_in,
10726 memory_order_relaxed));
10727 vty_out(vty, " Total: %10d %10d\n", PEER_TOTAL_TX(p),
10728 PEER_TOTAL_RX(p));
10729 }
10730
10731 if (use_json) {
10732 /* advertisement-interval */
10733 json_object_int_add(json_neigh,
10734 "minBtwnAdvertisementRunsTimerMsecs",
10735 p->v_routeadv * 1000);
10736
10737 /* Update-source. */
10738 if (p->update_if || p->update_source) {
10739 if (p->update_if)
10740 json_object_string_add(json_neigh,
10741 "updateSource",
10742 p->update_if);
10743 else if (p->update_source)
10744 json_object_string_add(
10745 json_neigh, "updateSource",
10746 sockunion2str(p->update_source, buf1,
10747 SU_ADDRSTRLEN));
10748 }
10749 } else {
10750 /* advertisement-interval */
10751 vty_out(vty,
10752 " Minimum time between advertisement runs is %d seconds\n",
10753 p->v_routeadv);
10754
10755 /* Update-source. */
10756 if (p->update_if || p->update_source) {
10757 vty_out(vty, " Update source is ");
10758 if (p->update_if)
10759 vty_out(vty, "%s", p->update_if);
10760 else if (p->update_source)
10761 vty_out(vty, "%s",
10762 sockunion2str(p->update_source, buf1,
10763 SU_ADDRSTRLEN));
10764 vty_out(vty, "\n");
10765 }
10766
10767 vty_out(vty, "\n");
10768 }
10769
10770 /* Address Family Information */
10771 json_object *json_hold = NULL;
10772
10773 if (use_json)
10774 json_hold = json_object_new_object();
10775
10776 FOREACH_AFI_SAFI (afi, safi)
10777 if (p->afc[afi][safi])
10778 bgp_show_peer_afi(vty, p, afi, safi, use_json,
10779 json_hold);
10780
10781 if (use_json) {
10782 json_object_object_add(json_neigh, "addressFamilyInfo",
10783 json_hold);
10784 json_object_int_add(json_neigh, "connectionsEstablished",
10785 p->established);
10786 json_object_int_add(json_neigh, "connectionsDropped",
10787 p->dropped);
10788 } else
10789 vty_out(vty, " Connections established %d; dropped %d\n",
10790 p->established, p->dropped);
10791
10792 if (!p->last_reset) {
10793 if (use_json)
10794 json_object_string_add(json_neigh, "lastReset",
10795 "never");
10796 else
10797 vty_out(vty, " Last reset never\n");
10798 } else {
10799 if (use_json) {
10800 time_t uptime;
10801 struct tm *tm;
10802
10803 uptime = bgp_clock();
10804 uptime -= p->resettime;
10805 tm = gmtime(&uptime);
10806 json_object_int_add(json_neigh, "lastResetTimerMsecs",
10807 (tm->tm_sec * 1000)
10808 + (tm->tm_min * 60000)
10809 + (tm->tm_hour * 3600000));
10810 bgp_show_peer_reset(NULL, p, json_neigh, true);
10811 } else {
10812 vty_out(vty, " Last reset %s, ",
10813 peer_uptime(p->resettime, timebuf,
10814 BGP_UPTIME_LEN, 0, NULL));
10815
10816 bgp_show_peer_reset(vty, p, NULL, false);
10817 if (p->last_reset_cause_size) {
10818 msg = p->last_reset_cause;
10819 vty_out(vty,
10820 " Message received that caused BGP to send a NOTIFICATION:\n ");
10821 for (i = 1; i <= p->last_reset_cause_size;
10822 i++) {
10823 vty_out(vty, "%02X", *msg++);
10824
10825 if (i != p->last_reset_cause_size) {
10826 if (i % 16 == 0) {
10827 vty_out(vty, "\n ");
10828 } else if (i % 4 == 0) {
10829 vty_out(vty, " ");
10830 }
10831 }
10832 }
10833 vty_out(vty, "\n");
10834 }
10835 }
10836 }
10837
10838 if (CHECK_FLAG(p->sflags, PEER_STATUS_PREFIX_OVERFLOW)) {
10839 if (use_json)
10840 json_object_boolean_true_add(json_neigh,
10841 "prefixesConfigExceedMax");
10842 else
10843 vty_out(vty,
10844 " Peer had exceeded the max. no. of prefixes configured.\n");
10845
10846 if (p->t_pmax_restart) {
10847 if (use_json) {
10848 json_object_boolean_true_add(
10849 json_neigh, "reducePrefixNumFrom");
10850 json_object_int_add(json_neigh,
10851 "restartInTimerMsec",
10852 thread_timer_remain_second(
10853 p->t_pmax_restart)
10854 * 1000);
10855 } else
10856 vty_out(vty,
10857 " Reduce the no. of prefix from %s, will restart in %ld seconds\n",
10858 p->host, thread_timer_remain_second(
10859 p->t_pmax_restart));
10860 } else {
10861 if (use_json)
10862 json_object_boolean_true_add(
10863 json_neigh,
10864 "reducePrefixNumAndClearIpBgp");
10865 else
10866 vty_out(vty,
10867 " Reduce the no. of prefix and clear ip bgp %s to restore peering\n",
10868 p->host);
10869 }
10870 }
10871
10872 /* EBGP Multihop and GTSM */
10873 if (p->sort != BGP_PEER_IBGP) {
10874 if (use_json) {
10875 if (p->gtsm_hops > 0)
10876 json_object_int_add(json_neigh,
10877 "externalBgpNbrMaxHopsAway",
10878 p->gtsm_hops);
10879 else if (p->ttl > 1)
10880 json_object_int_add(json_neigh,
10881 "externalBgpNbrMaxHopsAway",
10882 p->ttl);
10883 } else {
10884 if (p->gtsm_hops > 0)
10885 vty_out(vty,
10886 " External BGP neighbor may be up to %d hops away.\n",
10887 p->gtsm_hops);
10888 else if (p->ttl > 1)
10889 vty_out(vty,
10890 " External BGP neighbor may be up to %d hops away.\n",
10891 p->ttl);
10892 }
10893 } else {
10894 if (p->gtsm_hops > 0) {
10895 if (use_json)
10896 json_object_int_add(json_neigh,
10897 "internalBgpNbrMaxHopsAway",
10898 p->gtsm_hops);
10899 else
10900 vty_out(vty,
10901 " Internal BGP neighbor may be up to %d hops away.\n",
10902 p->gtsm_hops);
10903 }
10904 }
10905
10906 /* Local address. */
10907 if (p->su_local) {
10908 if (use_json) {
10909 json_object_string_add(json_neigh, "hostLocal",
10910 sockunion2str(p->su_local, buf1,
10911 SU_ADDRSTRLEN));
10912 json_object_int_add(json_neigh, "portLocal",
10913 ntohs(p->su_local->sin.sin_port));
10914 } else
10915 vty_out(vty, "Local host: %s, Local port: %d\n",
10916 sockunion2str(p->su_local, buf1, SU_ADDRSTRLEN),
10917 ntohs(p->su_local->sin.sin_port));
10918 }
10919
10920 /* Remote address. */
10921 if (p->su_remote) {
10922 if (use_json) {
10923 json_object_string_add(json_neigh, "hostForeign",
10924 sockunion2str(p->su_remote, buf1,
10925 SU_ADDRSTRLEN));
10926 json_object_int_add(json_neigh, "portForeign",
10927 ntohs(p->su_remote->sin.sin_port));
10928 } else
10929 vty_out(vty, "Foreign host: %s, Foreign port: %d\n",
10930 sockunion2str(p->su_remote, buf1,
10931 SU_ADDRSTRLEN),
10932 ntohs(p->su_remote->sin.sin_port));
10933 }
10934
10935 /* Nexthop display. */
10936 if (p->su_local) {
10937 if (use_json) {
10938 json_object_string_add(json_neigh, "nexthop",
10939 inet_ntop(AF_INET,
10940 &p->nexthop.v4, buf1,
10941 sizeof(buf1)));
10942 json_object_string_add(json_neigh, "nexthopGlobal",
10943 inet_ntop(AF_INET6,
10944 &p->nexthop.v6_global,
10945 buf1, sizeof(buf1)));
10946 json_object_string_add(json_neigh, "nexthopLocal",
10947 inet_ntop(AF_INET6,
10948 &p->nexthop.v6_local,
10949 buf1, sizeof(buf1)));
10950 if (p->shared_network)
10951 json_object_string_add(json_neigh,
10952 "bgpConnection",
10953 "sharedNetwork");
10954 else
10955 json_object_string_add(json_neigh,
10956 "bgpConnection",
10957 "nonSharedNetwork");
10958 } else {
10959 vty_out(vty, "Nexthop: %s\n",
10960 inet_ntop(AF_INET, &p->nexthop.v4, buf1,
10961 sizeof(buf1)));
10962 vty_out(vty, "Nexthop global: %s\n",
10963 inet_ntop(AF_INET6, &p->nexthop.v6_global, buf1,
10964 sizeof(buf1)));
10965 vty_out(vty, "Nexthop local: %s\n",
10966 inet_ntop(AF_INET6, &p->nexthop.v6_local, buf1,
10967 sizeof(buf1)));
10968 vty_out(vty, "BGP connection: %s\n",
10969 p->shared_network ? "shared network"
10970 : "non shared network");
10971 }
10972 }
10973
10974 /* Timer information. */
10975 if (use_json) {
10976 json_object_int_add(json_neigh, "connectRetryTimer",
10977 p->v_connect);
10978 if (p->status == Established && p->rtt)
10979 json_object_int_add(json_neigh, "estimatedRttInMsecs",
10980 p->rtt);
10981 if (p->t_start)
10982 json_object_int_add(
10983 json_neigh, "nextStartTimerDueInMsecs",
10984 thread_timer_remain_second(p->t_start) * 1000);
10985 if (p->t_connect)
10986 json_object_int_add(
10987 json_neigh, "nextConnectTimerDueInMsecs",
10988 thread_timer_remain_second(p->t_connect)
10989 * 1000);
10990 if (p->t_routeadv) {
10991 json_object_int_add(json_neigh, "mraiInterval",
10992 p->v_routeadv);
10993 json_object_int_add(
10994 json_neigh, "mraiTimerExpireInMsecs",
10995 thread_timer_remain_second(p->t_routeadv)
10996 * 1000);
10997 }
10998 if (p->password)
10999 json_object_int_add(json_neigh, "authenticationEnabled",
11000 1);
11001
11002 if (p->t_read)
11003 json_object_string_add(json_neigh, "readThread", "on");
11004 else
11005 json_object_string_add(json_neigh, "readThread", "off");
11006
11007 if (CHECK_FLAG(p->thread_flags, PEER_THREAD_WRITES_ON))
11008 json_object_string_add(json_neigh, "writeThread", "on");
11009 else
11010 json_object_string_add(json_neigh, "writeThread",
11011 "off");
11012 } else {
11013 vty_out(vty, "BGP Connect Retry Timer in Seconds: %d\n",
11014 p->v_connect);
11015 if (p->status == Established && p->rtt)
11016 vty_out(vty, "Estimated round trip time: %d ms\n",
11017 p->rtt);
11018 if (p->t_start)
11019 vty_out(vty, "Next start timer due in %ld seconds\n",
11020 thread_timer_remain_second(p->t_start));
11021 if (p->t_connect)
11022 vty_out(vty, "Next connect timer due in %ld seconds\n",
11023 thread_timer_remain_second(p->t_connect));
11024 if (p->t_routeadv)
11025 vty_out(vty,
11026 "MRAI (interval %u) timer expires in %ld seconds\n",
11027 p->v_routeadv,
11028 thread_timer_remain_second(p->t_routeadv));
11029 if (p->password)
11030 vty_out(vty, "Peer Authentication Enabled\n");
11031
11032 vty_out(vty, "Read thread: %s Write thread: %s FD used: %d\n",
11033 p->t_read ? "on" : "off",
11034 CHECK_FLAG(p->thread_flags, PEER_THREAD_WRITES_ON)
11035 ? "on"
11036 : "off", p->fd);
11037 }
11038
11039 if (p->notify.code == BGP_NOTIFY_OPEN_ERR
11040 && p->notify.subcode == BGP_NOTIFY_OPEN_UNSUP_CAPBL)
11041 bgp_capability_vty_out(vty, p, use_json, json_neigh);
11042
11043 if (!use_json)
11044 vty_out(vty, "\n");
11045
11046 /* BFD information. */
11047 bgp_bfd_show_info(vty, p, use_json, json_neigh);
11048
11049 if (use_json) {
11050 if (p->conf_if) /* Configured interface name. */
11051 json_object_object_add(json, p->conf_if, json_neigh);
11052 else /* Configured IP address. */
11053 json_object_object_add(json, p->host, json_neigh);
11054 }
11055 }
11056
11057 static int bgp_show_neighbor(struct vty *vty, struct bgp *bgp,
11058 enum show_type type, union sockunion *su,
11059 const char *conf_if, bool use_json,
11060 json_object *json)
11061 {
11062 struct listnode *node, *nnode;
11063 struct peer *peer;
11064 int find = 0;
11065 bool nbr_output = false;
11066 afi_t afi = AFI_MAX;
11067 safi_t safi = SAFI_MAX;
11068
11069 if (type == show_ipv4_peer || type == show_ipv4_all) {
11070 afi = AFI_IP;
11071 } else if (type == show_ipv6_peer || type == show_ipv6_all) {
11072 afi = AFI_IP6;
11073 }
11074
11075 for (ALL_LIST_ELEMENTS(bgp->peer, node, nnode, peer)) {
11076 if (!CHECK_FLAG(peer->flags, PEER_FLAG_CONFIG_NODE))
11077 continue;
11078
11079 switch (type) {
11080 case show_all:
11081 bgp_show_peer(vty, peer, use_json, json);
11082 nbr_output = true;
11083 break;
11084 case show_peer:
11085 if (conf_if) {
11086 if ((peer->conf_if
11087 && !strcmp(peer->conf_if, conf_if))
11088 || (peer->hostname
11089 && !strcmp(peer->hostname, conf_if))) {
11090 find = 1;
11091 bgp_show_peer(vty, peer, use_json,
11092 json);
11093 }
11094 } else {
11095 if (sockunion_same(&peer->su, su)) {
11096 find = 1;
11097 bgp_show_peer(vty, peer, use_json,
11098 json);
11099 }
11100 }
11101 break;
11102 case show_ipv4_peer:
11103 case show_ipv6_peer:
11104 FOREACH_SAFI (safi) {
11105 if (peer->afc[afi][safi]) {
11106 if (conf_if) {
11107 if ((peer->conf_if
11108 && !strcmp(peer->conf_if, conf_if))
11109 || (peer->hostname
11110 && !strcmp(peer->hostname, conf_if))) {
11111 find = 1;
11112 bgp_show_peer(vty, peer, use_json,
11113 json);
11114 break;
11115 }
11116 } else {
11117 if (sockunion_same(&peer->su, su)) {
11118 find = 1;
11119 bgp_show_peer(vty, peer, use_json,
11120 json);
11121 break;
11122 }
11123 }
11124 }
11125 }
11126 break;
11127 case show_ipv4_all:
11128 case show_ipv6_all:
11129 FOREACH_SAFI (safi) {
11130 if (peer->afc[afi][safi]) {
11131 bgp_show_peer(vty, peer, use_json, json);
11132 nbr_output = true;
11133 break;
11134 }
11135 }
11136 break;
11137 }
11138 }
11139
11140 if ((type == show_peer || type == show_ipv4_peer ||
11141 type == show_ipv6_peer) && !find) {
11142 if (use_json)
11143 json_object_boolean_true_add(json, "bgpNoSuchNeighbor");
11144 else
11145 vty_out(vty, "%% No such neighbor in this view/vrf\n");
11146 }
11147
11148 if (type != show_peer && type != show_ipv4_peer &&
11149 type != show_ipv6_peer && !nbr_output && !use_json)
11150 vty_out(vty, "%% No BGP neighbors found\n");
11151
11152 if (use_json) {
11153 vty_out(vty, "%s\n", json_object_to_json_string_ext(
11154 json, JSON_C_TO_STRING_PRETTY));
11155 } else {
11156 vty_out(vty, "\n");
11157 }
11158
11159 return CMD_SUCCESS;
11160 }
11161
11162 static void bgp_show_all_instances_neighbors_vty(struct vty *vty,
11163 enum show_type type,
11164 const char *ip_str,
11165 bool use_json)
11166 {
11167 struct listnode *node, *nnode;
11168 struct bgp *bgp;
11169 union sockunion su;
11170 json_object *json = NULL;
11171 int ret, is_first = 1;
11172 bool nbr_output = false;
11173
11174 if (use_json)
11175 vty_out(vty, "{\n");
11176
11177 for (ALL_LIST_ELEMENTS(bm->bgp, node, nnode, bgp)) {
11178 nbr_output = true;
11179 if (use_json) {
11180 if (!(json = json_object_new_object())) {
11181 flog_err(
11182 EC_BGP_JSON_MEM_ERROR,
11183 "Unable to allocate memory for JSON object");
11184 vty_out(vty,
11185 "{\"error\": {\"message:\": \"Unable to allocate memory for JSON object\"}}}\n");
11186 return;
11187 }
11188
11189 json_object_int_add(json, "vrfId",
11190 (bgp->vrf_id == VRF_UNKNOWN)
11191 ? -1
11192 : (int64_t)bgp->vrf_id);
11193 json_object_string_add(
11194 json, "vrfName",
11195 (bgp->inst_type == BGP_INSTANCE_TYPE_DEFAULT)
11196 ? VRF_DEFAULT_NAME
11197 : bgp->name);
11198
11199 if (!is_first)
11200 vty_out(vty, ",\n");
11201 else
11202 is_first = 0;
11203
11204 vty_out(vty, "\"%s\":",
11205 (bgp->inst_type == BGP_INSTANCE_TYPE_DEFAULT)
11206 ? VRF_DEFAULT_NAME
11207 : bgp->name);
11208 } else {
11209 vty_out(vty, "\nInstance %s:\n",
11210 (bgp->inst_type == BGP_INSTANCE_TYPE_DEFAULT)
11211 ? VRF_DEFAULT_NAME
11212 : bgp->name);
11213 }
11214
11215 if (type == show_peer || type == show_ipv4_peer ||
11216 type == show_ipv6_peer) {
11217 ret = str2sockunion(ip_str, &su);
11218 if (ret < 0)
11219 bgp_show_neighbor(vty, bgp, type, NULL, ip_str,
11220 use_json, json);
11221 else
11222 bgp_show_neighbor(vty, bgp, type, &su, NULL,
11223 use_json, json);
11224 } else {
11225 bgp_show_neighbor(vty, bgp, type, NULL, NULL,
11226 use_json, json);
11227 }
11228 json_object_free(json);
11229 }
11230
11231 if (use_json) {
11232 vty_out(vty, "}\n");
11233 json_object_free(json);
11234 }
11235 else if (!nbr_output)
11236 vty_out(vty, "%% BGP instance not found\n");
11237 }
11238
11239 static int bgp_show_neighbor_vty(struct vty *vty, const char *name,
11240 enum show_type type, const char *ip_str,
11241 bool use_json)
11242 {
11243 int ret;
11244 struct bgp *bgp;
11245 union sockunion su;
11246 json_object *json = NULL;
11247
11248 if (name) {
11249 if (strmatch(name, "all")) {
11250 bgp_show_all_instances_neighbors_vty(vty, type, ip_str,
11251 use_json);
11252 return CMD_SUCCESS;
11253 } else {
11254 bgp = bgp_lookup_by_name(name);
11255 if (!bgp) {
11256 if (use_json) {
11257 json = json_object_new_object();
11258 vty_out(vty, "%s\n",
11259 json_object_to_json_string_ext(
11260 json,
11261 JSON_C_TO_STRING_PRETTY));
11262 json_object_free(json);
11263 } else
11264 vty_out(vty,
11265 "%% BGP instance not found\n");
11266
11267 return CMD_WARNING;
11268 }
11269 }
11270 } else {
11271 bgp = bgp_get_default();
11272 }
11273
11274 if (bgp) {
11275 json = json_object_new_object();
11276 if (ip_str) {
11277 ret = str2sockunion(ip_str, &su);
11278 if (ret < 0)
11279 bgp_show_neighbor(vty, bgp, type, NULL, ip_str,
11280 use_json, json);
11281 else
11282 bgp_show_neighbor(vty, bgp, type, &su, NULL,
11283 use_json, json);
11284 } else {
11285 bgp_show_neighbor(vty, bgp, type, NULL, NULL, use_json,
11286 json);
11287 }
11288 json_object_free(json);
11289 } else {
11290 if (use_json)
11291 vty_out(vty, "{}\n");
11292 else
11293 vty_out(vty, "%% BGP instance not found\n");
11294 }
11295
11296 return CMD_SUCCESS;
11297 }
11298
11299 /* "show [ip] bgp neighbors" commands. */
11300 DEFUN (show_ip_bgp_neighbors,
11301 show_ip_bgp_neighbors_cmd,
11302 "show [ip] bgp [<view|vrf> VIEWVRFNAME] [<ipv4|ipv6>] neighbors [<A.B.C.D|X:X::X:X|WORD>] [json]",
11303 SHOW_STR
11304 IP_STR
11305 BGP_STR
11306 BGP_INSTANCE_HELP_STR
11307 "Address Family\n"
11308 "Address Family\n"
11309 "Detailed information on TCP and BGP neighbor connections\n"
11310 "Neighbor to display information about\n"
11311 "Neighbor to display information about\n"
11312 "Neighbor on BGP configured interface\n"
11313 JSON_STR)
11314 {
11315 char *vrf = NULL;
11316 char *sh_arg = NULL;
11317 enum show_type sh_type;
11318 afi_t afi = AFI_MAX;
11319
11320 bool uj = use_json(argc, argv);
11321
11322 int idx = 0;
11323
11324 /* [<vrf> VIEWVRFNAME] */
11325 if (argv_find(argv, argc, "vrf", &idx)) {
11326 vrf = argv[idx + 1]->arg;
11327 if (vrf && strmatch(vrf, VRF_DEFAULT_NAME))
11328 vrf = NULL;
11329 } else if (argv_find(argv, argc, "view", &idx))
11330 /* [<view> VIEWVRFNAME] */
11331 vrf = argv[idx + 1]->arg;
11332
11333 idx++;
11334
11335 if (argv_find(argv, argc, "ipv4", &idx)) {
11336 sh_type = show_ipv4_all;
11337 afi = AFI_IP;
11338 } else if (argv_find(argv, argc, "ipv6", &idx)) {
11339 sh_type = show_ipv6_all;
11340 afi = AFI_IP6;
11341 } else {
11342 sh_type = show_all;
11343 }
11344
11345 if (argv_find(argv, argc, "A.B.C.D", &idx)
11346 || argv_find(argv, argc, "X:X::X:X", &idx)
11347 || argv_find(argv, argc, "WORD", &idx)) {
11348 sh_type = show_peer;
11349 sh_arg = argv[idx]->arg;
11350 }
11351
11352 if (sh_type == show_peer && afi == AFI_IP) {
11353 sh_type = show_ipv4_peer;
11354 } else if (sh_type == show_peer && afi == AFI_IP6) {
11355 sh_type = show_ipv6_peer;
11356 }
11357
11358 return bgp_show_neighbor_vty(vty, vrf, sh_type, sh_arg, uj);
11359 }
11360
11361 /* Show BGP's AS paths internal data. There are both `show [ip] bgp
11362 paths' and `show ip mbgp paths'. Those functions results are the
11363 same.*/
11364 DEFUN (show_ip_bgp_paths,
11365 show_ip_bgp_paths_cmd,
11366 "show [ip] bgp ["BGP_SAFI_CMD_STR"] paths",
11367 SHOW_STR
11368 IP_STR
11369 BGP_STR
11370 BGP_SAFI_HELP_STR
11371 "Path information\n")
11372 {
11373 vty_out(vty, "Address Refcnt Path\n");
11374 aspath_print_all_vty(vty);
11375 return CMD_SUCCESS;
11376 }
11377
11378 #include "hash.h"
11379
11380 static void community_show_all_iterator(struct hash_bucket *bucket,
11381 struct vty *vty)
11382 {
11383 struct community *com;
11384
11385 com = (struct community *)bucket->data;
11386 vty_out(vty, "[%p] (%ld) %s\n", (void *)com, com->refcnt,
11387 community_str(com, false));
11388 }
11389
11390 /* Show BGP's community internal data. */
11391 DEFUN (show_ip_bgp_community_info,
11392 show_ip_bgp_community_info_cmd,
11393 "show [ip] bgp community-info",
11394 SHOW_STR
11395 IP_STR
11396 BGP_STR
11397 "List all bgp community information\n")
11398 {
11399 vty_out(vty, "Address Refcnt Community\n");
11400
11401 hash_iterate(community_hash(),
11402 (void (*)(struct hash_bucket *,
11403 void *))community_show_all_iterator,
11404 vty);
11405
11406 return CMD_SUCCESS;
11407 }
11408
11409 static void lcommunity_show_all_iterator(struct hash_bucket *bucket,
11410 struct vty *vty)
11411 {
11412 struct lcommunity *lcom;
11413
11414 lcom = (struct lcommunity *)bucket->data;
11415 vty_out(vty, "[%p] (%ld) %s\n", (void *)lcom, lcom->refcnt,
11416 lcommunity_str(lcom, false));
11417 }
11418
11419 /* Show BGP's community internal data. */
11420 DEFUN (show_ip_bgp_lcommunity_info,
11421 show_ip_bgp_lcommunity_info_cmd,
11422 "show ip bgp large-community-info",
11423 SHOW_STR
11424 IP_STR
11425 BGP_STR
11426 "List all bgp large-community information\n")
11427 {
11428 vty_out(vty, "Address Refcnt Large-community\n");
11429
11430 hash_iterate(lcommunity_hash(),
11431 (void (*)(struct hash_bucket *,
11432 void *))lcommunity_show_all_iterator,
11433 vty);
11434
11435 return CMD_SUCCESS;
11436 }
11437
11438
11439 DEFUN (show_ip_bgp_attr_info,
11440 show_ip_bgp_attr_info_cmd,
11441 "show [ip] bgp attribute-info",
11442 SHOW_STR
11443 IP_STR
11444 BGP_STR
11445 "List all bgp attribute information\n")
11446 {
11447 attr_show_all(vty);
11448 return CMD_SUCCESS;
11449 }
11450
11451 static int bgp_show_route_leak_vty(struct vty *vty, const char *name,
11452 afi_t afi, safi_t safi,
11453 bool use_json, json_object *json)
11454 {
11455 struct bgp *bgp;
11456 struct listnode *node;
11457 char *vname;
11458 char buf1[INET6_ADDRSTRLEN];
11459 char *ecom_str;
11460 vpn_policy_direction_t dir;
11461
11462 if (json) {
11463 json_object *json_import_vrfs = NULL;
11464 json_object *json_export_vrfs = NULL;
11465
11466 bgp = name ? bgp_lookup_by_name(name) : bgp_get_default();
11467
11468 if (!bgp) {
11469 vty_out(vty, "%s\n",
11470 json_object_to_json_string_ext(
11471 json,
11472 JSON_C_TO_STRING_PRETTY));
11473 json_object_free(json);
11474
11475 return CMD_WARNING;
11476 }
11477
11478 /* Provide context for the block */
11479 json_object_string_add(json, "vrf", name ? name : "default");
11480 json_object_string_add(json, "afiSafi",
11481 get_afi_safi_str(afi, safi, true));
11482
11483 if (!CHECK_FLAG(bgp->af_flags[afi][safi],
11484 BGP_CONFIG_VRF_TO_VRF_IMPORT)) {
11485 json_object_string_add(json, "importFromVrfs", "none");
11486 json_object_string_add(json, "importRts", "none");
11487 } else {
11488 json_import_vrfs = json_object_new_array();
11489
11490 for (ALL_LIST_ELEMENTS_RO(
11491 bgp->vpn_policy[afi].import_vrf,
11492 node, vname))
11493 json_object_array_add(json_import_vrfs,
11494 json_object_new_string(vname));
11495
11496 json_object_object_add(json, "importFromVrfs",
11497 json_import_vrfs);
11498 dir = BGP_VPN_POLICY_DIR_FROMVPN;
11499 if (bgp->vpn_policy[afi].rtlist[dir]) {
11500 ecom_str = ecommunity_ecom2str(
11501 bgp->vpn_policy[afi].rtlist[dir],
11502 ECOMMUNITY_FORMAT_ROUTE_MAP, 0);
11503 json_object_string_add(json, "importRts",
11504 ecom_str);
11505 XFREE(MTYPE_ECOMMUNITY_STR, ecom_str);
11506 } else
11507 json_object_string_add(json, "importRts",
11508 "none");
11509 }
11510
11511 if (!CHECK_FLAG(bgp->af_flags[afi][safi],
11512 BGP_CONFIG_VRF_TO_VRF_EXPORT)) {
11513 json_object_string_add(json, "exportToVrfs", "none");
11514 json_object_string_add(json, "routeDistinguisher",
11515 "none");
11516 json_object_string_add(json, "exportRts", "none");
11517 } else {
11518 json_export_vrfs = json_object_new_array();
11519
11520 for (ALL_LIST_ELEMENTS_RO(
11521 bgp->vpn_policy[afi].export_vrf,
11522 node, vname))
11523 json_object_array_add(json_export_vrfs,
11524 json_object_new_string(vname));
11525 json_object_object_add(json, "exportToVrfs",
11526 json_export_vrfs);
11527 json_object_string_add(json, "routeDistinguisher",
11528 prefix_rd2str(&bgp->vpn_policy[afi].tovpn_rd,
11529 buf1, RD_ADDRSTRLEN));
11530
11531 dir = BGP_VPN_POLICY_DIR_TOVPN;
11532 if (bgp->vpn_policy[afi].rtlist[dir]) {
11533 ecom_str = ecommunity_ecom2str(
11534 bgp->vpn_policy[afi].rtlist[dir],
11535 ECOMMUNITY_FORMAT_ROUTE_MAP, 0);
11536 json_object_string_add(json, "exportRts",
11537 ecom_str);
11538 XFREE(MTYPE_ECOMMUNITY_STR, ecom_str);
11539 } else
11540 json_object_string_add(json, "exportRts",
11541 "none");
11542 }
11543
11544 if (use_json) {
11545 vty_out(vty, "%s\n",
11546 json_object_to_json_string_ext(json,
11547 JSON_C_TO_STRING_PRETTY));
11548 json_object_free(json);
11549 }
11550 } else {
11551 bgp = name ? bgp_lookup_by_name(name) : bgp_get_default();
11552
11553 if (!bgp) {
11554 vty_out(vty, "%% No such BGP instance exist\n");
11555 return CMD_WARNING;
11556 }
11557
11558 if (!CHECK_FLAG(bgp->af_flags[afi][safi],
11559 BGP_CONFIG_VRF_TO_VRF_IMPORT))
11560 vty_out(vty,
11561 "This VRF is not importing %s routes from any other VRF\n",
11562 get_afi_safi_str(afi, safi, false));
11563 else {
11564 vty_out(vty,
11565 "This VRF is importing %s routes from the following VRFs:\n",
11566 get_afi_safi_str(afi, safi, false));
11567
11568 for (ALL_LIST_ELEMENTS_RO(
11569 bgp->vpn_policy[afi].import_vrf,
11570 node, vname))
11571 vty_out(vty, " %s\n", vname);
11572
11573 dir = BGP_VPN_POLICY_DIR_FROMVPN;
11574 ecom_str = NULL;
11575 if (bgp->vpn_policy[afi].rtlist[dir]) {
11576 ecom_str = ecommunity_ecom2str(
11577 bgp->vpn_policy[afi].rtlist[dir],
11578 ECOMMUNITY_FORMAT_ROUTE_MAP, 0);
11579 vty_out(vty, "Import RT(s): %s\n", ecom_str);
11580
11581 XFREE(MTYPE_ECOMMUNITY_STR, ecom_str);
11582 } else
11583 vty_out(vty, "Import RT(s):\n");
11584 }
11585
11586 if (!CHECK_FLAG(bgp->af_flags[afi][safi],
11587 BGP_CONFIG_VRF_TO_VRF_EXPORT))
11588 vty_out(vty,
11589 "This VRF is not exporting %s routes to any other VRF\n",
11590 get_afi_safi_str(afi, safi, false));
11591 else {
11592 vty_out(vty,
11593 "This VRF is exporting %s routes to the following VRFs:\n",
11594 get_afi_safi_str(afi, safi, false));
11595
11596 for (ALL_LIST_ELEMENTS_RO(
11597 bgp->vpn_policy[afi].export_vrf,
11598 node, vname))
11599 vty_out(vty, " %s\n", vname);
11600
11601 vty_out(vty, "RD: %s\n",
11602 prefix_rd2str(&bgp->vpn_policy[afi].tovpn_rd,
11603 buf1, RD_ADDRSTRLEN));
11604
11605 dir = BGP_VPN_POLICY_DIR_TOVPN;
11606 if (bgp->vpn_policy[afi].rtlist[dir]) {
11607 ecom_str = ecommunity_ecom2str(
11608 bgp->vpn_policy[afi].rtlist[dir],
11609 ECOMMUNITY_FORMAT_ROUTE_MAP, 0);
11610 vty_out(vty, "Export RT: %s\n", ecom_str);
11611 XFREE(MTYPE_ECOMMUNITY_STR, ecom_str);
11612 } else
11613 vty_out(vty, "Import RT(s):\n");
11614 }
11615 }
11616
11617 return CMD_SUCCESS;
11618 }
11619
11620 static int bgp_show_all_instance_route_leak_vty(struct vty *vty, afi_t afi,
11621 safi_t safi, bool use_json)
11622 {
11623 struct listnode *node, *nnode;
11624 struct bgp *bgp;
11625 char *vrf_name = NULL;
11626 json_object *json = NULL;
11627 json_object *json_vrf = NULL;
11628 json_object *json_vrfs = NULL;
11629
11630 if (use_json) {
11631 json = json_object_new_object();
11632 json_vrfs = json_object_new_object();
11633 }
11634
11635 for (ALL_LIST_ELEMENTS(bm->bgp, node, nnode, bgp)) {
11636
11637 if (bgp->inst_type != BGP_INSTANCE_TYPE_DEFAULT)
11638 vrf_name = bgp->name;
11639
11640 if (use_json) {
11641 json_vrf = json_object_new_object();
11642 } else {
11643 vty_out(vty, "\nInstance %s:\n",
11644 (bgp->inst_type == BGP_INSTANCE_TYPE_DEFAULT)
11645 ? VRF_DEFAULT_NAME : bgp->name);
11646 }
11647 bgp_show_route_leak_vty(vty, vrf_name, afi, safi, 0, json_vrf);
11648 if (use_json) {
11649 if (bgp->inst_type == BGP_INSTANCE_TYPE_DEFAULT)
11650 json_object_object_add(json_vrfs,
11651 VRF_DEFAULT_NAME, json_vrf);
11652 else
11653 json_object_object_add(json_vrfs, vrf_name,
11654 json_vrf);
11655 }
11656 }
11657
11658 if (use_json) {
11659 json_object_object_add(json, "vrfs", json_vrfs);
11660 vty_out(vty, "%s\n", json_object_to_json_string_ext(json,
11661 JSON_C_TO_STRING_PRETTY));
11662 json_object_free(json);
11663 }
11664
11665 return CMD_SUCCESS;
11666 }
11667
11668 /* "show [ip] bgp route-leak" command. */
11669 DEFUN (show_ip_bgp_route_leak,
11670 show_ip_bgp_route_leak_cmd,
11671 "show [ip] bgp [<view|vrf> VIEWVRFNAME] ["BGP_AFI_CMD_STR" ["BGP_SAFI_CMD_STR"]] route-leak [json]",
11672 SHOW_STR
11673 IP_STR
11674 BGP_STR
11675 BGP_INSTANCE_HELP_STR
11676 BGP_AFI_HELP_STR
11677 BGP_SAFI_HELP_STR
11678 "Route leaking information\n"
11679 JSON_STR)
11680 {
11681 char *vrf = NULL;
11682 afi_t afi = AFI_MAX;
11683 safi_t safi = SAFI_MAX;
11684
11685 bool uj = use_json(argc, argv);
11686 int idx = 0;
11687 json_object *json = NULL;
11688
11689 /* show [ip] bgp */
11690 if (argv_find(argv, argc, "ip", &idx)) {
11691 afi = AFI_IP;
11692 safi = SAFI_UNICAST;
11693 }
11694 /* [vrf VIEWVRFNAME] */
11695 if (argv_find(argv, argc, "view", &idx)) {
11696 vty_out(vty,
11697 "%% This command is not applicable to BGP views\n");
11698 return CMD_WARNING;
11699 }
11700
11701 if (argv_find(argv, argc, "vrf", &idx)) {
11702 vrf = argv[idx + 1]->arg;
11703 if (vrf && strmatch(vrf, VRF_DEFAULT_NAME))
11704 vrf = NULL;
11705 }
11706 /* ["BGP_AFI_CMD_STR" ["BGP_SAFI_CMD_STR"]] */
11707 if (argv_find_and_parse_afi(argv, argc, &idx, &afi)) {
11708 argv_find_and_parse_safi(argv, argc, &idx, &safi);
11709 }
11710
11711 if (!((afi == AFI_IP || afi == AFI_IP6) && safi == SAFI_UNICAST)) {
11712 vty_out(vty,
11713 "%% This command is applicable only for unicast ipv4|ipv6\n");
11714 return CMD_WARNING;
11715 }
11716
11717 if (vrf && strmatch(vrf, "all"))
11718 return bgp_show_all_instance_route_leak_vty(vty, afi, safi, uj);
11719
11720 if (uj)
11721 json = json_object_new_object();
11722
11723 return bgp_show_route_leak_vty(vty, vrf, afi, safi, uj, json);
11724 }
11725
11726 static void bgp_show_all_instances_updgrps_vty(struct vty *vty, afi_t afi,
11727 safi_t safi)
11728 {
11729 struct listnode *node, *nnode;
11730 struct bgp *bgp;
11731
11732 for (ALL_LIST_ELEMENTS(bm->bgp, node, nnode, bgp)) {
11733 vty_out(vty, "\nInstance %s:\n",
11734 (bgp->inst_type == BGP_INSTANCE_TYPE_DEFAULT)
11735 ? VRF_DEFAULT_NAME
11736 : bgp->name);
11737 update_group_show(bgp, afi, safi, vty, 0);
11738 }
11739 }
11740
11741 static int bgp_show_update_groups(struct vty *vty, const char *name, int afi,
11742 int safi, uint64_t subgrp_id)
11743 {
11744 struct bgp *bgp;
11745
11746 if (name) {
11747 if (strmatch(name, "all")) {
11748 bgp_show_all_instances_updgrps_vty(vty, afi, safi);
11749 return CMD_SUCCESS;
11750 } else {
11751 bgp = bgp_lookup_by_name(name);
11752 }
11753 } else {
11754 bgp = bgp_get_default();
11755 }
11756
11757 if (bgp)
11758 update_group_show(bgp, afi, safi, vty, subgrp_id);
11759 return CMD_SUCCESS;
11760 }
11761
11762 DEFUN (show_ip_bgp_updgrps,
11763 show_ip_bgp_updgrps_cmd,
11764 "show [ip] bgp [<view|vrf> VIEWVRFNAME] ["BGP_AFI_CMD_STR" ["BGP_SAFI_WITH_LABEL_CMD_STR"]] update-groups [SUBGROUP-ID]",
11765 SHOW_STR
11766 IP_STR
11767 BGP_STR
11768 BGP_INSTANCE_HELP_STR
11769 BGP_AFI_HELP_STR
11770 BGP_SAFI_WITH_LABEL_HELP_STR
11771 "Detailed info about dynamic update groups\n"
11772 "Specific subgroup to display detailed info for\n")
11773 {
11774 char *vrf = NULL;
11775 afi_t afi = AFI_IP6;
11776 safi_t safi = SAFI_UNICAST;
11777 uint64_t subgrp_id = 0;
11778
11779 int idx = 0;
11780
11781 /* show [ip] bgp */
11782 if (argv_find(argv, argc, "ip", &idx))
11783 afi = AFI_IP;
11784 /* [<vrf> VIEWVRFNAME] */
11785 if (argv_find(argv, argc, "vrf", &idx)) {
11786 vrf = argv[idx + 1]->arg;
11787 if (vrf && strmatch(vrf, VRF_DEFAULT_NAME))
11788 vrf = NULL;
11789 } else if (argv_find(argv, argc, "view", &idx))
11790 /* [<view> VIEWVRFNAME] */
11791 vrf = argv[idx + 1]->arg;
11792 /* ["BGP_AFI_CMD_STR" ["BGP_SAFI_CMD_STR"]] */
11793 if (argv_find_and_parse_afi(argv, argc, &idx, &afi)) {
11794 argv_find_and_parse_safi(argv, argc, &idx, &safi);
11795 }
11796
11797 /* get subgroup id, if provided */
11798 idx = argc - 1;
11799 if (argv[idx]->type == VARIABLE_TKN)
11800 subgrp_id = strtoull(argv[idx]->arg, NULL, 10);
11801
11802 return (bgp_show_update_groups(vty, vrf, afi, safi, subgrp_id));
11803 }
11804
11805 DEFUN (show_bgp_instance_all_ipv6_updgrps,
11806 show_bgp_instance_all_ipv6_updgrps_cmd,
11807 "show [ip] bgp <view|vrf> all update-groups",
11808 SHOW_STR
11809 IP_STR
11810 BGP_STR
11811 BGP_INSTANCE_ALL_HELP_STR
11812 "Detailed info about dynamic update groups\n")
11813 {
11814 bgp_show_all_instances_updgrps_vty(vty, AFI_IP6, SAFI_UNICAST);
11815 return CMD_SUCCESS;
11816 }
11817
11818 DEFUN (show_bgp_l2vpn_evpn_updgrps,
11819 show_bgp_l2vpn_evpn_updgrps_cmd,
11820 "show [ip] bgp l2vpn evpn update-groups",
11821 SHOW_STR
11822 IP_STR
11823 BGP_STR
11824 "l2vpn address family\n"
11825 "evpn sub-address family\n"
11826 "Detailed info about dynamic update groups\n")
11827 {
11828 char *vrf = NULL;
11829 uint64_t subgrp_id = 0;
11830
11831 bgp_show_update_groups(vty, vrf, AFI_L2VPN, SAFI_EVPN, subgrp_id);
11832 return CMD_SUCCESS;
11833 }
11834
11835 DEFUN (show_bgp_updgrps_stats,
11836 show_bgp_updgrps_stats_cmd,
11837 "show [ip] bgp update-groups statistics",
11838 SHOW_STR
11839 IP_STR
11840 BGP_STR
11841 "Detailed info about dynamic update groups\n"
11842 "Statistics\n")
11843 {
11844 struct bgp *bgp;
11845
11846 bgp = bgp_get_default();
11847 if (bgp)
11848 update_group_show_stats(bgp, vty);
11849
11850 return CMD_SUCCESS;
11851 }
11852
11853 DEFUN (show_bgp_instance_updgrps_stats,
11854 show_bgp_instance_updgrps_stats_cmd,
11855 "show [ip] bgp <view|vrf> VIEWVRFNAME update-groups statistics",
11856 SHOW_STR
11857 IP_STR
11858 BGP_STR
11859 BGP_INSTANCE_HELP_STR
11860 "Detailed info about dynamic update groups\n"
11861 "Statistics\n")
11862 {
11863 int idx_word = 3;
11864 struct bgp *bgp;
11865
11866 bgp = bgp_lookup_by_name(argv[idx_word]->arg);
11867 if (bgp)
11868 update_group_show_stats(bgp, vty);
11869
11870 return CMD_SUCCESS;
11871 }
11872
11873 static void show_bgp_updgrps_adj_info_aux(struct vty *vty, const char *name,
11874 afi_t afi, safi_t safi,
11875 const char *what, uint64_t subgrp_id)
11876 {
11877 struct bgp *bgp;
11878
11879 if (name)
11880 bgp = bgp_lookup_by_name(name);
11881 else
11882 bgp = bgp_get_default();
11883
11884 if (bgp) {
11885 if (!strcmp(what, "advertise-queue"))
11886 update_group_show_adj_queue(bgp, afi, safi, vty,
11887 subgrp_id);
11888 else if (!strcmp(what, "advertised-routes"))
11889 update_group_show_advertised(bgp, afi, safi, vty,
11890 subgrp_id);
11891 else if (!strcmp(what, "packet-queue"))
11892 update_group_show_packet_queue(bgp, afi, safi, vty,
11893 subgrp_id);
11894 }
11895 }
11896
11897 DEFPY(show_ip_bgp_instance_updgrps_adj_s,
11898 show_ip_bgp_instance_updgrps_adj_s_cmd,
11899 "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",
11900 SHOW_STR IP_STR BGP_STR BGP_INSTANCE_HELP_STR BGP_AFI_HELP_STR
11901 BGP_SAFI_HELP_STR
11902 "Detailed info about dynamic update groups\n"
11903 "Specific subgroup to display info for\n"
11904 "Advertisement queue\n"
11905 "Announced routes\n"
11906 "Packet queue\n")
11907 {
11908 uint64_t subgrp_id = 0;
11909 afi_t afiz;
11910 safi_t safiz;
11911 if (sgid)
11912 subgrp_id = strtoull(sgid, NULL, 10);
11913
11914 if (!ip && !afi)
11915 afiz = AFI_IP6;
11916 if (!ip && afi)
11917 afiz = bgp_vty_afi_from_str(afi);
11918 if (ip && !afi)
11919 afiz = AFI_IP;
11920 if (ip && afi) {
11921 afiz = bgp_vty_afi_from_str(afi);
11922 if (afiz != AFI_IP)
11923 vty_out(vty,
11924 "%% Cannot specify both 'ip' and 'ipv6'\n");
11925 return CMD_WARNING;
11926 }
11927
11928 safiz = safi ? bgp_vty_safi_from_str(safi) : SAFI_UNICAST;
11929
11930 show_bgp_updgrps_adj_info_aux(vty, vrf, afiz, safiz, rtq, subgrp_id);
11931 return CMD_SUCCESS;
11932 }
11933
11934 static int bgp_show_one_peer_group(struct vty *vty, struct peer_group *group)
11935 {
11936 struct listnode *node, *nnode;
11937 struct prefix *range;
11938 struct peer *conf;
11939 struct peer *peer;
11940 char buf[PREFIX2STR_BUFFER];
11941 afi_t afi;
11942 safi_t safi;
11943 const char *peer_status;
11944 const char *af_str;
11945 int lr_count;
11946 int dynamic;
11947 int af_cfgd;
11948
11949 conf = group->conf;
11950
11951 if (conf->as_type == AS_SPECIFIED || conf->as_type == AS_EXTERNAL) {
11952 vty_out(vty, "\nBGP peer-group %s, remote AS %" PRIu32 "\n",
11953 group->name, conf->as);
11954 } else if (conf->as_type == AS_INTERNAL) {
11955 vty_out(vty, "\nBGP peer-group %s, remote AS %" PRIu32 "\n",
11956 group->name, group->bgp->as);
11957 } else {
11958 vty_out(vty, "\nBGP peer-group %s\n", group->name);
11959 }
11960
11961 if ((group->bgp->as == conf->as) || (conf->as_type == AS_INTERNAL))
11962 vty_out(vty, " Peer-group type is internal\n");
11963 else
11964 vty_out(vty, " Peer-group type is external\n");
11965
11966 /* Display AFs configured. */
11967 vty_out(vty, " Configured address-families:");
11968 FOREACH_AFI_SAFI (afi, safi) {
11969 if (conf->afc[afi][safi]) {
11970 af_cfgd = 1;
11971 vty_out(vty, " %s;", get_afi_safi_str(afi, safi, false));
11972 }
11973 }
11974 if (!af_cfgd)
11975 vty_out(vty, " none\n");
11976 else
11977 vty_out(vty, "\n");
11978
11979 /* Display listen ranges (for dynamic neighbors), if any */
11980 for (afi = AFI_IP; afi < AFI_MAX; afi++) {
11981 if (afi == AFI_IP)
11982 af_str = "IPv4";
11983 else if (afi == AFI_IP6)
11984 af_str = "IPv6";
11985 else
11986 af_str = "???";
11987 lr_count = listcount(group->listen_range[afi]);
11988 if (lr_count) {
11989 vty_out(vty, " %d %s listen range(s)\n", lr_count,
11990 af_str);
11991
11992
11993 for (ALL_LIST_ELEMENTS(group->listen_range[afi], node,
11994 nnode, range)) {
11995 prefix2str(range, buf, sizeof(buf));
11996 vty_out(vty, " %s\n", buf);
11997 }
11998 }
11999 }
12000
12001 /* Display group members and their status */
12002 if (listcount(group->peer)) {
12003 vty_out(vty, " Peer-group members:\n");
12004 for (ALL_LIST_ELEMENTS(group->peer, node, nnode, peer)) {
12005 if (CHECK_FLAG(peer->flags, PEER_FLAG_SHUTDOWN))
12006 peer_status = "Idle (Admin)";
12007 else if (CHECK_FLAG(peer->sflags,
12008 PEER_STATUS_PREFIX_OVERFLOW))
12009 peer_status = "Idle (PfxCt)";
12010 else
12011 peer_status = lookup_msg(bgp_status_msg,
12012 peer->status, NULL);
12013
12014 dynamic = peer_dynamic_neighbor(peer);
12015 vty_out(vty, " %s %s %s \n", peer->host,
12016 dynamic ? "(dynamic)" : "", peer_status);
12017 }
12018 }
12019
12020 return CMD_SUCCESS;
12021 }
12022
12023 static int bgp_show_peer_group_vty(struct vty *vty, const char *name,
12024 const char *group_name)
12025 {
12026 struct bgp *bgp;
12027 struct listnode *node, *nnode;
12028 struct peer_group *group;
12029 bool found = false;
12030
12031 bgp = name ? bgp_lookup_by_name(name) : bgp_get_default();
12032
12033 if (!bgp) {
12034 vty_out(vty, "%% BGP instance not found\n");
12035 return CMD_WARNING;
12036 }
12037
12038 for (ALL_LIST_ELEMENTS(bgp->group, node, nnode, group)) {
12039 if (group_name) {
12040 if (strmatch(group->name, group_name)) {
12041 bgp_show_one_peer_group(vty, group);
12042 found = true;
12043 break;
12044 }
12045 } else {
12046 bgp_show_one_peer_group(vty, group);
12047 }
12048 }
12049
12050 if (group_name && !found)
12051 vty_out(vty, "%% No such peer-group\n");
12052
12053 return CMD_SUCCESS;
12054 }
12055
12056 DEFUN (show_ip_bgp_peer_groups,
12057 show_ip_bgp_peer_groups_cmd,
12058 "show [ip] bgp [<view|vrf> VIEWVRFNAME] peer-group [PGNAME]",
12059 SHOW_STR
12060 IP_STR
12061 BGP_STR
12062 BGP_INSTANCE_HELP_STR
12063 "Detailed information on BGP peer groups\n"
12064 "Peer group name\n")
12065 {
12066 char *vrf, *pg;
12067 int idx = 0;
12068
12069 vrf = argv_find(argv, argc, "VIEWVRFNAME", &idx) ? argv[idx]->arg
12070 : NULL;
12071 pg = argv_find(argv, argc, "PGNAME", &idx) ? argv[idx]->arg : NULL;
12072
12073 return bgp_show_peer_group_vty(vty, vrf, pg);
12074 }
12075
12076
12077 /* Redistribute VTY commands. */
12078
12079 DEFUN (bgp_redistribute_ipv4,
12080 bgp_redistribute_ipv4_cmd,
12081 "redistribute " FRR_IP_REDIST_STR_BGPD,
12082 "Redistribute information from another routing protocol\n"
12083 FRR_IP_REDIST_HELP_STR_BGPD)
12084 {
12085 VTY_DECLVAR_CONTEXT(bgp, bgp);
12086 int idx_protocol = 1;
12087 int type;
12088
12089 type = proto_redistnum(AFI_IP, argv[idx_protocol]->text);
12090 if (type < 0) {
12091 vty_out(vty, "%% Invalid route type\n");
12092 return CMD_WARNING_CONFIG_FAILED;
12093 }
12094
12095 bgp_redist_add(bgp, AFI_IP, type, 0);
12096 return bgp_redistribute_set(bgp, AFI_IP, type, 0, false);
12097 }
12098
12099 ALIAS_HIDDEN(
12100 bgp_redistribute_ipv4, bgp_redistribute_ipv4_hidden_cmd,
12101 "redistribute " FRR_IP_REDIST_STR_BGPD,
12102 "Redistribute information from another routing protocol\n" FRR_IP_REDIST_HELP_STR_BGPD)
12103
12104 DEFUN (bgp_redistribute_ipv4_rmap,
12105 bgp_redistribute_ipv4_rmap_cmd,
12106 "redistribute " FRR_IP_REDIST_STR_BGPD " route-map WORD",
12107 "Redistribute information from another routing protocol\n"
12108 FRR_IP_REDIST_HELP_STR_BGPD
12109 "Route map reference\n"
12110 "Pointer to route-map entries\n")
12111 {
12112 VTY_DECLVAR_CONTEXT(bgp, bgp);
12113 int idx_protocol = 1;
12114 int idx_word = 3;
12115 int type;
12116 struct bgp_redist *red;
12117 bool changed;
12118 struct route_map *route_map = route_map_lookup_warn_noexist(
12119 vty, argv[idx_word]->arg);
12120
12121 type = proto_redistnum(AFI_IP, argv[idx_protocol]->text);
12122 if (type < 0) {
12123 vty_out(vty, "%% Invalid route type\n");
12124 return CMD_WARNING_CONFIG_FAILED;
12125 }
12126
12127 red = bgp_redist_add(bgp, AFI_IP, type, 0);
12128 changed =
12129 bgp_redistribute_rmap_set(red, argv[idx_word]->arg, route_map);
12130 return bgp_redistribute_set(bgp, AFI_IP, type, 0, changed);
12131 }
12132
12133 ALIAS_HIDDEN(
12134 bgp_redistribute_ipv4_rmap, bgp_redistribute_ipv4_rmap_hidden_cmd,
12135 "redistribute " FRR_IP_REDIST_STR_BGPD " route-map WORD",
12136 "Redistribute information from another routing protocol\n" FRR_IP_REDIST_HELP_STR_BGPD
12137 "Route map reference\n"
12138 "Pointer to route-map entries\n")
12139
12140 DEFUN (bgp_redistribute_ipv4_metric,
12141 bgp_redistribute_ipv4_metric_cmd,
12142 "redistribute " FRR_IP_REDIST_STR_BGPD " metric (0-4294967295)",
12143 "Redistribute information from another routing protocol\n"
12144 FRR_IP_REDIST_HELP_STR_BGPD
12145 "Metric for redistributed routes\n"
12146 "Default metric\n")
12147 {
12148 VTY_DECLVAR_CONTEXT(bgp, bgp);
12149 int idx_protocol = 1;
12150 int idx_number = 3;
12151 int type;
12152 uint32_t metric;
12153 struct bgp_redist *red;
12154 bool changed;
12155
12156 type = proto_redistnum(AFI_IP, argv[idx_protocol]->text);
12157 if (type < 0) {
12158 vty_out(vty, "%% Invalid route type\n");
12159 return CMD_WARNING_CONFIG_FAILED;
12160 }
12161 metric = strtoul(argv[idx_number]->arg, NULL, 10);
12162
12163 red = bgp_redist_add(bgp, AFI_IP, type, 0);
12164 changed = bgp_redistribute_metric_set(bgp, red, AFI_IP, type, metric);
12165 return bgp_redistribute_set(bgp, AFI_IP, type, 0, changed);
12166 }
12167
12168 ALIAS_HIDDEN(
12169 bgp_redistribute_ipv4_metric, bgp_redistribute_ipv4_metric_hidden_cmd,
12170 "redistribute " FRR_IP_REDIST_STR_BGPD " metric (0-4294967295)",
12171 "Redistribute information from another routing protocol\n" FRR_IP_REDIST_HELP_STR_BGPD
12172 "Metric for redistributed routes\n"
12173 "Default metric\n")
12174
12175 DEFUN (bgp_redistribute_ipv4_rmap_metric,
12176 bgp_redistribute_ipv4_rmap_metric_cmd,
12177 "redistribute " FRR_IP_REDIST_STR_BGPD " route-map WORD metric (0-4294967295)",
12178 "Redistribute information from another routing protocol\n"
12179 FRR_IP_REDIST_HELP_STR_BGPD
12180 "Route map reference\n"
12181 "Pointer to route-map entries\n"
12182 "Metric for redistributed routes\n"
12183 "Default metric\n")
12184 {
12185 VTY_DECLVAR_CONTEXT(bgp, bgp);
12186 int idx_protocol = 1;
12187 int idx_word = 3;
12188 int idx_number = 5;
12189 int type;
12190 uint32_t metric;
12191 struct bgp_redist *red;
12192 bool changed;
12193 struct route_map *route_map =
12194 route_map_lookup_warn_noexist(vty, argv[idx_word]->arg);
12195
12196 type = proto_redistnum(AFI_IP, argv[idx_protocol]->text);
12197 if (type < 0) {
12198 vty_out(vty, "%% Invalid route type\n");
12199 return CMD_WARNING_CONFIG_FAILED;
12200 }
12201 metric = strtoul(argv[idx_number]->arg, NULL, 10);
12202
12203 red = bgp_redist_add(bgp, AFI_IP, type, 0);
12204 changed =
12205 bgp_redistribute_rmap_set(red, argv[idx_word]->arg, route_map);
12206 changed |= bgp_redistribute_metric_set(bgp, red, AFI_IP, type, metric);
12207 return bgp_redistribute_set(bgp, AFI_IP, type, 0, changed);
12208 }
12209
12210 ALIAS_HIDDEN(
12211 bgp_redistribute_ipv4_rmap_metric,
12212 bgp_redistribute_ipv4_rmap_metric_hidden_cmd,
12213 "redistribute " FRR_IP_REDIST_STR_BGPD
12214 " route-map WORD metric (0-4294967295)",
12215 "Redistribute information from another routing protocol\n" FRR_IP_REDIST_HELP_STR_BGPD
12216 "Route map reference\n"
12217 "Pointer to route-map entries\n"
12218 "Metric for redistributed routes\n"
12219 "Default metric\n")
12220
12221 DEFUN (bgp_redistribute_ipv4_metric_rmap,
12222 bgp_redistribute_ipv4_metric_rmap_cmd,
12223 "redistribute " FRR_IP_REDIST_STR_BGPD " metric (0-4294967295) route-map WORD",
12224 "Redistribute information from another routing protocol\n"
12225 FRR_IP_REDIST_HELP_STR_BGPD
12226 "Metric for redistributed routes\n"
12227 "Default metric\n"
12228 "Route map reference\n"
12229 "Pointer to route-map entries\n")
12230 {
12231 VTY_DECLVAR_CONTEXT(bgp, bgp);
12232 int idx_protocol = 1;
12233 int idx_number = 3;
12234 int idx_word = 5;
12235 int type;
12236 uint32_t metric;
12237 struct bgp_redist *red;
12238 bool changed;
12239 struct route_map *route_map =
12240 route_map_lookup_warn_noexist(vty, argv[idx_word]->arg);
12241
12242 type = proto_redistnum(AFI_IP, argv[idx_protocol]->text);
12243 if (type < 0) {
12244 vty_out(vty, "%% Invalid route type\n");
12245 return CMD_WARNING_CONFIG_FAILED;
12246 }
12247 metric = strtoul(argv[idx_number]->arg, NULL, 10);
12248
12249 red = bgp_redist_add(bgp, AFI_IP, type, 0);
12250 changed = bgp_redistribute_metric_set(bgp, red, AFI_IP, type, metric);
12251 changed |=
12252 bgp_redistribute_rmap_set(red, argv[idx_word]->arg, route_map);
12253 return bgp_redistribute_set(bgp, AFI_IP, type, 0, changed);
12254 }
12255
12256 ALIAS_HIDDEN(
12257 bgp_redistribute_ipv4_metric_rmap,
12258 bgp_redistribute_ipv4_metric_rmap_hidden_cmd,
12259 "redistribute " FRR_IP_REDIST_STR_BGPD
12260 " metric (0-4294967295) route-map WORD",
12261 "Redistribute information from another routing protocol\n" FRR_IP_REDIST_HELP_STR_BGPD
12262 "Metric for redistributed routes\n"
12263 "Default metric\n"
12264 "Route map reference\n"
12265 "Pointer to route-map entries\n")
12266
12267 DEFUN (bgp_redistribute_ipv4_ospf,
12268 bgp_redistribute_ipv4_ospf_cmd,
12269 "redistribute <ospf|table> (1-65535)",
12270 "Redistribute information from another routing protocol\n"
12271 "Open Shortest Path First (OSPFv2)\n"
12272 "Non-main Kernel Routing Table\n"
12273 "Instance ID/Table ID\n")
12274 {
12275 VTY_DECLVAR_CONTEXT(bgp, bgp);
12276 int idx_ospf_table = 1;
12277 int idx_number = 2;
12278 unsigned short instance;
12279 unsigned short protocol;
12280
12281 instance = strtoul(argv[idx_number]->arg, NULL, 10);
12282
12283 if (strncmp(argv[idx_ospf_table]->arg, "o", 1) == 0)
12284 protocol = ZEBRA_ROUTE_OSPF;
12285 else
12286 protocol = ZEBRA_ROUTE_TABLE;
12287
12288 bgp_redist_add(bgp, AFI_IP, protocol, instance);
12289 return bgp_redistribute_set(bgp, AFI_IP, protocol, instance, false);
12290 }
12291
12292 ALIAS_HIDDEN(bgp_redistribute_ipv4_ospf, bgp_redistribute_ipv4_ospf_hidden_cmd,
12293 "redistribute <ospf|table> (1-65535)",
12294 "Redistribute information from another routing protocol\n"
12295 "Open Shortest Path First (OSPFv2)\n"
12296 "Non-main Kernel Routing Table\n"
12297 "Instance ID/Table ID\n")
12298
12299 DEFUN (bgp_redistribute_ipv4_ospf_rmap,
12300 bgp_redistribute_ipv4_ospf_rmap_cmd,
12301 "redistribute <ospf|table> (1-65535) route-map WORD",
12302 "Redistribute information from another routing protocol\n"
12303 "Open Shortest Path First (OSPFv2)\n"
12304 "Non-main Kernel Routing Table\n"
12305 "Instance ID/Table ID\n"
12306 "Route map reference\n"
12307 "Pointer to route-map entries\n")
12308 {
12309 VTY_DECLVAR_CONTEXT(bgp, bgp);
12310 int idx_ospf_table = 1;
12311 int idx_number = 2;
12312 int idx_word = 4;
12313 struct bgp_redist *red;
12314 unsigned short instance;
12315 int protocol;
12316 bool changed;
12317 struct route_map *route_map =
12318 route_map_lookup_warn_noexist(vty, argv[idx_word]->arg);
12319
12320 if (strncmp(argv[idx_ospf_table]->arg, "o", 1) == 0)
12321 protocol = ZEBRA_ROUTE_OSPF;
12322 else
12323 protocol = ZEBRA_ROUTE_TABLE;
12324
12325 instance = strtoul(argv[idx_number]->arg, NULL, 10);
12326 red = bgp_redist_add(bgp, AFI_IP, protocol, instance);
12327 changed =
12328 bgp_redistribute_rmap_set(red, argv[idx_word]->arg, route_map);
12329 return bgp_redistribute_set(bgp, AFI_IP, protocol, instance, changed);
12330 }
12331
12332 ALIAS_HIDDEN(bgp_redistribute_ipv4_ospf_rmap,
12333 bgp_redistribute_ipv4_ospf_rmap_hidden_cmd,
12334 "redistribute <ospf|table> (1-65535) route-map WORD",
12335 "Redistribute information from another routing protocol\n"
12336 "Open Shortest Path First (OSPFv2)\n"
12337 "Non-main Kernel Routing Table\n"
12338 "Instance ID/Table ID\n"
12339 "Route map reference\n"
12340 "Pointer to route-map entries\n")
12341
12342 DEFUN (bgp_redistribute_ipv4_ospf_metric,
12343 bgp_redistribute_ipv4_ospf_metric_cmd,
12344 "redistribute <ospf|table> (1-65535) metric (0-4294967295)",
12345 "Redistribute information from another routing protocol\n"
12346 "Open Shortest Path First (OSPFv2)\n"
12347 "Non-main Kernel Routing Table\n"
12348 "Instance ID/Table ID\n"
12349 "Metric for redistributed routes\n"
12350 "Default metric\n")
12351 {
12352 VTY_DECLVAR_CONTEXT(bgp, bgp);
12353 int idx_ospf_table = 1;
12354 int idx_number = 2;
12355 int idx_number_2 = 4;
12356 uint32_t metric;
12357 struct bgp_redist *red;
12358 unsigned short instance;
12359 int protocol;
12360 bool changed;
12361
12362 if (strncmp(argv[idx_ospf_table]->arg, "o", 1) == 0)
12363 protocol = ZEBRA_ROUTE_OSPF;
12364 else
12365 protocol = ZEBRA_ROUTE_TABLE;
12366
12367 instance = strtoul(argv[idx_number]->arg, NULL, 10);
12368 metric = strtoul(argv[idx_number_2]->arg, NULL, 10);
12369
12370 red = bgp_redist_add(bgp, AFI_IP, protocol, instance);
12371 changed = bgp_redistribute_metric_set(bgp, red, AFI_IP, protocol,
12372 metric);
12373 return bgp_redistribute_set(bgp, AFI_IP, protocol, instance, changed);
12374 }
12375
12376 ALIAS_HIDDEN(bgp_redistribute_ipv4_ospf_metric,
12377 bgp_redistribute_ipv4_ospf_metric_hidden_cmd,
12378 "redistribute <ospf|table> (1-65535) metric (0-4294967295)",
12379 "Redistribute information from another routing protocol\n"
12380 "Open Shortest Path First (OSPFv2)\n"
12381 "Non-main Kernel Routing Table\n"
12382 "Instance ID/Table ID\n"
12383 "Metric for redistributed routes\n"
12384 "Default metric\n")
12385
12386 DEFUN (bgp_redistribute_ipv4_ospf_rmap_metric,
12387 bgp_redistribute_ipv4_ospf_rmap_metric_cmd,
12388 "redistribute <ospf|table> (1-65535) route-map WORD metric (0-4294967295)",
12389 "Redistribute information from another routing protocol\n"
12390 "Open Shortest Path First (OSPFv2)\n"
12391 "Non-main Kernel Routing Table\n"
12392 "Instance ID/Table ID\n"
12393 "Route map reference\n"
12394 "Pointer to route-map entries\n"
12395 "Metric for redistributed routes\n"
12396 "Default metric\n")
12397 {
12398 VTY_DECLVAR_CONTEXT(bgp, bgp);
12399 int idx_ospf_table = 1;
12400 int idx_number = 2;
12401 int idx_word = 4;
12402 int idx_number_2 = 6;
12403 uint32_t metric;
12404 struct bgp_redist *red;
12405 unsigned short instance;
12406 int protocol;
12407 bool changed;
12408 struct route_map *route_map =
12409 route_map_lookup_warn_noexist(vty, argv[idx_word]->arg);
12410
12411 if (strncmp(argv[idx_ospf_table]->arg, "o", 1) == 0)
12412 protocol = ZEBRA_ROUTE_OSPF;
12413 else
12414 protocol = ZEBRA_ROUTE_TABLE;
12415
12416 instance = strtoul(argv[idx_number]->arg, NULL, 10);
12417 metric = strtoul(argv[idx_number_2]->arg, NULL, 10);
12418
12419 red = bgp_redist_add(bgp, AFI_IP, protocol, instance);
12420 changed =
12421 bgp_redistribute_rmap_set(red, argv[idx_word]->arg, route_map);
12422 changed |= bgp_redistribute_metric_set(bgp, red, AFI_IP, protocol,
12423 metric);
12424 return bgp_redistribute_set(bgp, AFI_IP, protocol, instance, changed);
12425 }
12426
12427 ALIAS_HIDDEN(
12428 bgp_redistribute_ipv4_ospf_rmap_metric,
12429 bgp_redistribute_ipv4_ospf_rmap_metric_hidden_cmd,
12430 "redistribute <ospf|table> (1-65535) route-map WORD metric (0-4294967295)",
12431 "Redistribute information from another routing protocol\n"
12432 "Open Shortest Path First (OSPFv2)\n"
12433 "Non-main Kernel Routing Table\n"
12434 "Instance ID/Table ID\n"
12435 "Route map reference\n"
12436 "Pointer to route-map entries\n"
12437 "Metric for redistributed routes\n"
12438 "Default metric\n")
12439
12440 DEFUN (bgp_redistribute_ipv4_ospf_metric_rmap,
12441 bgp_redistribute_ipv4_ospf_metric_rmap_cmd,
12442 "redistribute <ospf|table> (1-65535) metric (0-4294967295) route-map WORD",
12443 "Redistribute information from another routing protocol\n"
12444 "Open Shortest Path First (OSPFv2)\n"
12445 "Non-main Kernel Routing Table\n"
12446 "Instance ID/Table ID\n"
12447 "Metric for redistributed routes\n"
12448 "Default metric\n"
12449 "Route map reference\n"
12450 "Pointer to route-map entries\n")
12451 {
12452 VTY_DECLVAR_CONTEXT(bgp, bgp);
12453 int idx_ospf_table = 1;
12454 int idx_number = 2;
12455 int idx_number_2 = 4;
12456 int idx_word = 6;
12457 uint32_t metric;
12458 struct bgp_redist *red;
12459 unsigned short instance;
12460 int protocol;
12461 bool changed;
12462 struct route_map *route_map =
12463 route_map_lookup_warn_noexist(vty, argv[idx_word]->arg);
12464
12465 if (strncmp(argv[idx_ospf_table]->arg, "o", 1) == 0)
12466 protocol = ZEBRA_ROUTE_OSPF;
12467 else
12468 protocol = ZEBRA_ROUTE_TABLE;
12469
12470 instance = strtoul(argv[idx_number]->arg, NULL, 10);
12471 metric = strtoul(argv[idx_number_2]->arg, NULL, 10);
12472
12473 red = bgp_redist_add(bgp, AFI_IP, protocol, instance);
12474 changed = bgp_redistribute_metric_set(bgp, red, AFI_IP, protocol,
12475 metric);
12476 changed |=
12477 bgp_redistribute_rmap_set(red, argv[idx_word]->arg, route_map);
12478 return bgp_redistribute_set(bgp, AFI_IP, protocol, instance, changed);
12479 }
12480
12481 ALIAS_HIDDEN(
12482 bgp_redistribute_ipv4_ospf_metric_rmap,
12483 bgp_redistribute_ipv4_ospf_metric_rmap_hidden_cmd,
12484 "redistribute <ospf|table> (1-65535) metric (0-4294967295) route-map WORD",
12485 "Redistribute information from another routing protocol\n"
12486 "Open Shortest Path First (OSPFv2)\n"
12487 "Non-main Kernel Routing Table\n"
12488 "Instance ID/Table ID\n"
12489 "Metric for redistributed routes\n"
12490 "Default metric\n"
12491 "Route map reference\n"
12492 "Pointer to route-map entries\n")
12493
12494 DEFUN (no_bgp_redistribute_ipv4_ospf,
12495 no_bgp_redistribute_ipv4_ospf_cmd,
12496 "no redistribute <ospf|table> (1-65535) [{metric (0-4294967295)|route-map WORD}]",
12497 NO_STR
12498 "Redistribute information from another routing protocol\n"
12499 "Open Shortest Path First (OSPFv2)\n"
12500 "Non-main Kernel Routing Table\n"
12501 "Instance ID/Table ID\n"
12502 "Metric for redistributed routes\n"
12503 "Default metric\n"
12504 "Route map reference\n"
12505 "Pointer to route-map entries\n")
12506 {
12507 VTY_DECLVAR_CONTEXT(bgp, bgp);
12508 int idx_ospf_table = 2;
12509 int idx_number = 3;
12510 unsigned short instance;
12511 int protocol;
12512
12513 if (strncmp(argv[idx_ospf_table]->arg, "o", 1) == 0)
12514 protocol = ZEBRA_ROUTE_OSPF;
12515 else
12516 protocol = ZEBRA_ROUTE_TABLE;
12517
12518 instance = strtoul(argv[idx_number]->arg, NULL, 10);
12519 return bgp_redistribute_unset(bgp, AFI_IP, protocol, instance);
12520 }
12521
12522 ALIAS_HIDDEN(
12523 no_bgp_redistribute_ipv4_ospf, no_bgp_redistribute_ipv4_ospf_hidden_cmd,
12524 "no redistribute <ospf|table> (1-65535) [{metric (0-4294967295)|route-map WORD}]",
12525 NO_STR
12526 "Redistribute information from another routing protocol\n"
12527 "Open Shortest Path First (OSPFv2)\n"
12528 "Non-main Kernel Routing Table\n"
12529 "Instance ID/Table ID\n"
12530 "Metric for redistributed routes\n"
12531 "Default metric\n"
12532 "Route map reference\n"
12533 "Pointer to route-map entries\n")
12534
12535 DEFUN (no_bgp_redistribute_ipv4,
12536 no_bgp_redistribute_ipv4_cmd,
12537 "no redistribute " FRR_IP_REDIST_STR_BGPD " [{metric (0-4294967295)|route-map WORD}]",
12538 NO_STR
12539 "Redistribute information from another routing protocol\n"
12540 FRR_IP_REDIST_HELP_STR_BGPD
12541 "Metric for redistributed routes\n"
12542 "Default metric\n"
12543 "Route map reference\n"
12544 "Pointer to route-map entries\n")
12545 {
12546 VTY_DECLVAR_CONTEXT(bgp, bgp);
12547 int idx_protocol = 2;
12548 int type;
12549
12550 type = proto_redistnum(AFI_IP, argv[idx_protocol]->text);
12551 if (type < 0) {
12552 vty_out(vty, "%% Invalid route type\n");
12553 return CMD_WARNING_CONFIG_FAILED;
12554 }
12555 return bgp_redistribute_unset(bgp, AFI_IP, type, 0);
12556 }
12557
12558 ALIAS_HIDDEN(
12559 no_bgp_redistribute_ipv4, no_bgp_redistribute_ipv4_hidden_cmd,
12560 "no redistribute " FRR_IP_REDIST_STR_BGPD
12561 " [{metric (0-4294967295)|route-map WORD}]",
12562 NO_STR
12563 "Redistribute information from another routing protocol\n" FRR_IP_REDIST_HELP_STR_BGPD
12564 "Metric for redistributed routes\n"
12565 "Default metric\n"
12566 "Route map reference\n"
12567 "Pointer to route-map entries\n")
12568
12569 DEFUN (bgp_redistribute_ipv6,
12570 bgp_redistribute_ipv6_cmd,
12571 "redistribute " FRR_IP6_REDIST_STR_BGPD,
12572 "Redistribute information from another routing protocol\n"
12573 FRR_IP6_REDIST_HELP_STR_BGPD)
12574 {
12575 VTY_DECLVAR_CONTEXT(bgp, bgp);
12576 int idx_protocol = 1;
12577 int type;
12578
12579 type = proto_redistnum(AFI_IP6, argv[idx_protocol]->text);
12580 if (type < 0) {
12581 vty_out(vty, "%% Invalid route type\n");
12582 return CMD_WARNING_CONFIG_FAILED;
12583 }
12584
12585 bgp_redist_add(bgp, AFI_IP6, type, 0);
12586 return bgp_redistribute_set(bgp, AFI_IP6, type, 0, false);
12587 }
12588
12589 DEFUN (bgp_redistribute_ipv6_rmap,
12590 bgp_redistribute_ipv6_rmap_cmd,
12591 "redistribute " FRR_IP6_REDIST_STR_BGPD " route-map WORD",
12592 "Redistribute information from another routing protocol\n"
12593 FRR_IP6_REDIST_HELP_STR_BGPD
12594 "Route map reference\n"
12595 "Pointer to route-map entries\n")
12596 {
12597 VTY_DECLVAR_CONTEXT(bgp, bgp);
12598 int idx_protocol = 1;
12599 int idx_word = 3;
12600 int type;
12601 struct bgp_redist *red;
12602 bool changed;
12603 struct route_map *route_map =
12604 route_map_lookup_warn_noexist(vty, argv[idx_word]->arg);
12605
12606 type = proto_redistnum(AFI_IP6, argv[idx_protocol]->text);
12607 if (type < 0) {
12608 vty_out(vty, "%% Invalid route type\n");
12609 return CMD_WARNING_CONFIG_FAILED;
12610 }
12611
12612 red = bgp_redist_add(bgp, AFI_IP6, type, 0);
12613 changed =
12614 bgp_redistribute_rmap_set(red, argv[idx_word]->arg, route_map);
12615 return bgp_redistribute_set(bgp, AFI_IP6, type, 0, changed);
12616 }
12617
12618 DEFUN (bgp_redistribute_ipv6_metric,
12619 bgp_redistribute_ipv6_metric_cmd,
12620 "redistribute " FRR_IP6_REDIST_STR_BGPD " metric (0-4294967295)",
12621 "Redistribute information from another routing protocol\n"
12622 FRR_IP6_REDIST_HELP_STR_BGPD
12623 "Metric for redistributed routes\n"
12624 "Default metric\n")
12625 {
12626 VTY_DECLVAR_CONTEXT(bgp, bgp);
12627 int idx_protocol = 1;
12628 int idx_number = 3;
12629 int type;
12630 uint32_t metric;
12631 struct bgp_redist *red;
12632 bool changed;
12633
12634 type = proto_redistnum(AFI_IP6, argv[idx_protocol]->text);
12635 if (type < 0) {
12636 vty_out(vty, "%% Invalid route type\n");
12637 return CMD_WARNING_CONFIG_FAILED;
12638 }
12639 metric = strtoul(argv[idx_number]->arg, NULL, 10);
12640
12641 red = bgp_redist_add(bgp, AFI_IP6, type, 0);
12642 changed = bgp_redistribute_metric_set(bgp, red, AFI_IP6, type, metric);
12643 return bgp_redistribute_set(bgp, AFI_IP6, type, 0, changed);
12644 }
12645
12646 DEFUN (bgp_redistribute_ipv6_rmap_metric,
12647 bgp_redistribute_ipv6_rmap_metric_cmd,
12648 "redistribute " FRR_IP6_REDIST_STR_BGPD " route-map WORD metric (0-4294967295)",
12649 "Redistribute information from another routing protocol\n"
12650 FRR_IP6_REDIST_HELP_STR_BGPD
12651 "Route map reference\n"
12652 "Pointer to route-map entries\n"
12653 "Metric for redistributed routes\n"
12654 "Default metric\n")
12655 {
12656 VTY_DECLVAR_CONTEXT(bgp, bgp);
12657 int idx_protocol = 1;
12658 int idx_word = 3;
12659 int idx_number = 5;
12660 int type;
12661 uint32_t metric;
12662 struct bgp_redist *red;
12663 bool changed;
12664 struct route_map *route_map =
12665 route_map_lookup_warn_noexist(vty, argv[idx_word]->arg);
12666
12667 type = proto_redistnum(AFI_IP6, argv[idx_protocol]->text);
12668 if (type < 0) {
12669 vty_out(vty, "%% Invalid route type\n");
12670 return CMD_WARNING_CONFIG_FAILED;
12671 }
12672 metric = strtoul(argv[idx_number]->arg, NULL, 10);
12673
12674 red = bgp_redist_add(bgp, AFI_IP6, type, 0);
12675 changed =
12676 bgp_redistribute_rmap_set(red, argv[idx_word]->arg, route_map);
12677 changed |= bgp_redistribute_metric_set(bgp, red, AFI_IP6, type,
12678 metric);
12679 return bgp_redistribute_set(bgp, AFI_IP6, type, 0, changed);
12680 }
12681
12682 DEFUN (bgp_redistribute_ipv6_metric_rmap,
12683 bgp_redistribute_ipv6_metric_rmap_cmd,
12684 "redistribute " FRR_IP6_REDIST_STR_BGPD " metric (0-4294967295) route-map WORD",
12685 "Redistribute information from another routing protocol\n"
12686 FRR_IP6_REDIST_HELP_STR_BGPD
12687 "Metric for redistributed routes\n"
12688 "Default metric\n"
12689 "Route map reference\n"
12690 "Pointer to route-map entries\n")
12691 {
12692 VTY_DECLVAR_CONTEXT(bgp, bgp);
12693 int idx_protocol = 1;
12694 int idx_number = 3;
12695 int idx_word = 5;
12696 int type;
12697 uint32_t metric;
12698 struct bgp_redist *red;
12699 bool changed;
12700 struct route_map *route_map =
12701 route_map_lookup_warn_noexist(vty, argv[idx_word]->arg);
12702
12703 type = proto_redistnum(AFI_IP6, argv[idx_protocol]->text);
12704 if (type < 0) {
12705 vty_out(vty, "%% Invalid route type\n");
12706 return CMD_WARNING_CONFIG_FAILED;
12707 }
12708 metric = strtoul(argv[idx_number]->arg, NULL, 10);
12709
12710 red = bgp_redist_add(bgp, AFI_IP6, type, 0);
12711 changed = bgp_redistribute_metric_set(bgp, red, AFI_IP6, SAFI_UNICAST,
12712 metric);
12713 changed |=
12714 bgp_redistribute_rmap_set(red, argv[idx_word]->arg, route_map);
12715 return bgp_redistribute_set(bgp, AFI_IP6, type, 0, changed);
12716 }
12717
12718 DEFUN (no_bgp_redistribute_ipv6,
12719 no_bgp_redistribute_ipv6_cmd,
12720 "no redistribute " FRR_IP6_REDIST_STR_BGPD " [{metric (0-4294967295)|route-map WORD}]",
12721 NO_STR
12722 "Redistribute information from another routing protocol\n"
12723 FRR_IP6_REDIST_HELP_STR_BGPD
12724 "Metric for redistributed routes\n"
12725 "Default metric\n"
12726 "Route map reference\n"
12727 "Pointer to route-map entries\n")
12728 {
12729 VTY_DECLVAR_CONTEXT(bgp, bgp);
12730 int idx_protocol = 2;
12731 int type;
12732
12733 type = proto_redistnum(AFI_IP6, argv[idx_protocol]->text);
12734 if (type < 0) {
12735 vty_out(vty, "%% Invalid route type\n");
12736 return CMD_WARNING_CONFIG_FAILED;
12737 }
12738
12739 return bgp_redistribute_unset(bgp, AFI_IP6, type, 0);
12740 }
12741
12742 void bgp_config_write_redistribute(struct vty *vty, struct bgp *bgp, afi_t afi,
12743 safi_t safi)
12744 {
12745 int i;
12746
12747 /* Unicast redistribution only. */
12748 if (safi != SAFI_UNICAST)
12749 return;
12750
12751 for (i = 0; i < ZEBRA_ROUTE_MAX; i++) {
12752 /* Redistribute BGP does not make sense. */
12753 if (i != ZEBRA_ROUTE_BGP) {
12754 struct list *red_list;
12755 struct listnode *node;
12756 struct bgp_redist *red;
12757
12758 red_list = bgp->redist[afi][i];
12759 if (!red_list)
12760 continue;
12761
12762 for (ALL_LIST_ELEMENTS_RO(red_list, node, red)) {
12763 /* "redistribute" configuration. */
12764 vty_out(vty, " redistribute %s",
12765 zebra_route_string(i));
12766 if (red->instance)
12767 vty_out(vty, " %d", red->instance);
12768 if (red->redist_metric_flag)
12769 vty_out(vty, " metric %u",
12770 red->redist_metric);
12771 if (red->rmap.name)
12772 vty_out(vty, " route-map %s",
12773 red->rmap.name);
12774 vty_out(vty, "\n");
12775 }
12776 }
12777 }
12778 }
12779
12780 /* This is part of the address-family block (unicast only) */
12781 void bgp_vpn_policy_config_write_afi(struct vty *vty, struct bgp *bgp,
12782 afi_t afi)
12783 {
12784 int indent = 2;
12785
12786 if (bgp->vpn_policy[afi].rmap_name[BGP_VPN_POLICY_DIR_FROMVPN]) {
12787 if (listcount(bgp->vpn_policy[afi].import_vrf))
12788 vty_out(vty, "%*simport vrf route-map %s\n", indent, "",
12789 bgp->vpn_policy[afi]
12790 .rmap_name[BGP_VPN_POLICY_DIR_FROMVPN]);
12791 else
12792 vty_out(vty, "%*sroute-map vpn import %s\n", indent, "",
12793 bgp->vpn_policy[afi]
12794 .rmap_name[BGP_VPN_POLICY_DIR_FROMVPN]);
12795 }
12796 if (CHECK_FLAG(bgp->af_flags[afi][SAFI_UNICAST],
12797 BGP_CONFIG_VRF_TO_VRF_IMPORT)
12798 || CHECK_FLAG(bgp->af_flags[afi][SAFI_UNICAST],
12799 BGP_CONFIG_VRF_TO_VRF_EXPORT))
12800 return;
12801
12802 if (CHECK_FLAG(bgp->vpn_policy[afi].flags,
12803 BGP_VPN_POLICY_TOVPN_LABEL_AUTO)) {
12804
12805 vty_out(vty, "%*slabel vpn export %s\n", indent, "", "auto");
12806
12807 } else {
12808 if (bgp->vpn_policy[afi].tovpn_label != MPLS_LABEL_NONE) {
12809 vty_out(vty, "%*slabel vpn export %u\n", indent, "",
12810 bgp->vpn_policy[afi].tovpn_label);
12811 }
12812 }
12813 if (CHECK_FLAG(bgp->vpn_policy[afi].flags,
12814 BGP_VPN_POLICY_TOVPN_RD_SET)) {
12815 char buf[RD_ADDRSTRLEN];
12816 vty_out(vty, "%*srd vpn export %s\n", indent, "",
12817 prefix_rd2str(&bgp->vpn_policy[afi].tovpn_rd, buf,
12818 sizeof(buf)));
12819 }
12820 if (CHECK_FLAG(bgp->vpn_policy[afi].flags,
12821 BGP_VPN_POLICY_TOVPN_NEXTHOP_SET)) {
12822
12823 char buf[PREFIX_STRLEN];
12824 if (inet_ntop(bgp->vpn_policy[afi].tovpn_nexthop.family,
12825 &bgp->vpn_policy[afi].tovpn_nexthop.u.prefix, buf,
12826 sizeof(buf))) {
12827
12828 vty_out(vty, "%*snexthop vpn export %s\n",
12829 indent, "", buf);
12830 }
12831 }
12832 if (bgp->vpn_policy[afi].rtlist[BGP_VPN_POLICY_DIR_FROMVPN]
12833 && bgp->vpn_policy[afi].rtlist[BGP_VPN_POLICY_DIR_TOVPN]
12834 && ecommunity_cmp(
12835 bgp->vpn_policy[afi].rtlist[BGP_VPN_POLICY_DIR_FROMVPN],
12836 bgp->vpn_policy[afi].rtlist[BGP_VPN_POLICY_DIR_TOVPN])) {
12837
12838 char *b = ecommunity_ecom2str(
12839 bgp->vpn_policy[afi].rtlist[BGP_VPN_POLICY_DIR_TOVPN],
12840 ECOMMUNITY_FORMAT_ROUTE_MAP, ECOMMUNITY_ROUTE_TARGET);
12841 vty_out(vty, "%*srt vpn both %s\n", indent, "", b);
12842 XFREE(MTYPE_ECOMMUNITY_STR, b);
12843 } else {
12844 if (bgp->vpn_policy[afi].rtlist[BGP_VPN_POLICY_DIR_FROMVPN]) {
12845 char *b = ecommunity_ecom2str(
12846 bgp->vpn_policy[afi]
12847 .rtlist[BGP_VPN_POLICY_DIR_FROMVPN],
12848 ECOMMUNITY_FORMAT_ROUTE_MAP,
12849 ECOMMUNITY_ROUTE_TARGET);
12850 vty_out(vty, "%*srt vpn import %s\n", indent, "", b);
12851 XFREE(MTYPE_ECOMMUNITY_STR, b);
12852 }
12853 if (bgp->vpn_policy[afi].rtlist[BGP_VPN_POLICY_DIR_TOVPN]) {
12854 char *b = ecommunity_ecom2str(
12855 bgp->vpn_policy[afi]
12856 .rtlist[BGP_VPN_POLICY_DIR_TOVPN],
12857 ECOMMUNITY_FORMAT_ROUTE_MAP,
12858 ECOMMUNITY_ROUTE_TARGET);
12859 vty_out(vty, "%*srt vpn export %s\n", indent, "", b);
12860 XFREE(MTYPE_ECOMMUNITY_STR, b);
12861 }
12862 }
12863
12864 if (bgp->vpn_policy[afi].rmap_name[BGP_VPN_POLICY_DIR_TOVPN])
12865 vty_out(vty, "%*sroute-map vpn export %s\n", indent, "",
12866 bgp->vpn_policy[afi]
12867 .rmap_name[BGP_VPN_POLICY_DIR_TOVPN]);
12868
12869 if (bgp->vpn_policy[afi].import_redirect_rtlist) {
12870 char *b = ecommunity_ecom2str(
12871 bgp->vpn_policy[afi]
12872 .import_redirect_rtlist,
12873 ECOMMUNITY_FORMAT_ROUTE_MAP,
12874 ECOMMUNITY_ROUTE_TARGET);
12875
12876 vty_out(vty, "%*srt redirect import %s\n", indent, "", b);
12877 XFREE(MTYPE_ECOMMUNITY_STR, b);
12878 }
12879 }
12880
12881
12882 /* BGP node structure. */
12883 static struct cmd_node bgp_node = {
12884 BGP_NODE, "%s(config-router)# ", 1,
12885 };
12886
12887 static struct cmd_node bgp_ipv4_unicast_node = {
12888 BGP_IPV4_NODE, "%s(config-router-af)# ", 1,
12889 };
12890
12891 static struct cmd_node bgp_ipv4_multicast_node = {
12892 BGP_IPV4M_NODE, "%s(config-router-af)# ", 1,
12893 };
12894
12895 static struct cmd_node bgp_ipv4_labeled_unicast_node = {
12896 BGP_IPV4L_NODE, "%s(config-router-af)# ", 1,
12897 };
12898
12899 static struct cmd_node bgp_ipv6_unicast_node = {
12900 BGP_IPV6_NODE, "%s(config-router-af)# ", 1,
12901 };
12902
12903 static struct cmd_node bgp_ipv6_multicast_node = {
12904 BGP_IPV6M_NODE, "%s(config-router-af)# ", 1,
12905 };
12906
12907 static struct cmd_node bgp_ipv6_labeled_unicast_node = {
12908 BGP_IPV6L_NODE, "%s(config-router-af)# ", 1,
12909 };
12910
12911 static struct cmd_node bgp_vpnv4_node = {BGP_VPNV4_NODE,
12912 "%s(config-router-af)# ", 1};
12913
12914 static struct cmd_node bgp_vpnv6_node = {BGP_VPNV6_NODE,
12915 "%s(config-router-af-vpnv6)# ", 1};
12916
12917 static struct cmd_node bgp_evpn_node = {BGP_EVPN_NODE,
12918 "%s(config-router-evpn)# ", 1};
12919
12920 static struct cmd_node bgp_evpn_vni_node = {BGP_EVPN_VNI_NODE,
12921 "%s(config-router-af-vni)# ", 1};
12922
12923 static struct cmd_node bgp_flowspecv4_node = {BGP_FLOWSPECV4_NODE,
12924 "%s(config-router-af)# ", 1};
12925
12926 static struct cmd_node bgp_flowspecv6_node = {BGP_FLOWSPECV6_NODE,
12927 "%s(config-router-af-vpnv6)# ", 1};
12928
12929 static void community_list_vty(void);
12930
12931 static void bgp_ac_neighbor(vector comps, struct cmd_token *token)
12932 {
12933 struct bgp *bgp;
12934 struct peer *peer;
12935 struct listnode *lnbgp, *lnpeer;
12936
12937 for (ALL_LIST_ELEMENTS_RO(bm->bgp, lnbgp, bgp)) {
12938 for (ALL_LIST_ELEMENTS_RO(bgp->peer, lnpeer, peer)) {
12939 /* only provide suggestions on the appropriate input
12940 * token type,
12941 * they'll otherwise show up multiple times */
12942 enum cmd_token_type match_type;
12943 char *name = peer->host;
12944
12945 if (peer->conf_if) {
12946 match_type = VARIABLE_TKN;
12947 name = peer->conf_if;
12948 } else if (strchr(peer->host, ':'))
12949 match_type = IPV6_TKN;
12950 else
12951 match_type = IPV4_TKN;
12952
12953 if (token->type != match_type)
12954 continue;
12955
12956 vector_set(comps, XSTRDUP(MTYPE_COMPLETION, name));
12957 }
12958 }
12959 }
12960
12961 static const struct cmd_variable_handler bgp_var_neighbor[] = {
12962 {.varname = "neighbor", .completions = bgp_ac_neighbor},
12963 {.varname = "neighbors", .completions = bgp_ac_neighbor},
12964 {.varname = "peer", .completions = bgp_ac_neighbor},
12965 {.completions = NULL}};
12966
12967 static void bgp_ac_peergroup(vector comps, struct cmd_token *token)
12968 {
12969 struct bgp *bgp;
12970 struct peer_group *group;
12971 struct listnode *lnbgp, *lnpeer;
12972
12973 for (ALL_LIST_ELEMENTS_RO(bm->bgp, lnbgp, bgp)) {
12974 for (ALL_LIST_ELEMENTS_RO(bgp->group, lnpeer, group))
12975 vector_set(comps, XSTRDUP(MTYPE_COMPLETION,
12976 group->name));
12977 }
12978 }
12979
12980 static const struct cmd_variable_handler bgp_var_peergroup[] = {
12981 {.tokenname = "PGNAME", .completions = bgp_ac_peergroup},
12982 {.completions = NULL} };
12983
12984 void bgp_vty_init(void)
12985 {
12986 cmd_variable_handler_register(bgp_var_neighbor);
12987 cmd_variable_handler_register(bgp_var_peergroup);
12988
12989 /* Install bgp top node. */
12990 install_node(&bgp_node, bgp_config_write);
12991 install_node(&bgp_ipv4_unicast_node, NULL);
12992 install_node(&bgp_ipv4_multicast_node, NULL);
12993 install_node(&bgp_ipv4_labeled_unicast_node, NULL);
12994 install_node(&bgp_ipv6_unicast_node, NULL);
12995 install_node(&bgp_ipv6_multicast_node, NULL);
12996 install_node(&bgp_ipv6_labeled_unicast_node, NULL);
12997 install_node(&bgp_vpnv4_node, NULL);
12998 install_node(&bgp_vpnv6_node, NULL);
12999 install_node(&bgp_evpn_node, NULL);
13000 install_node(&bgp_evpn_vni_node, NULL);
13001 install_node(&bgp_flowspecv4_node, NULL);
13002 install_node(&bgp_flowspecv6_node, NULL);
13003
13004 /* Install default VTY commands to new nodes. */
13005 install_default(BGP_NODE);
13006 install_default(BGP_IPV4_NODE);
13007 install_default(BGP_IPV4M_NODE);
13008 install_default(BGP_IPV4L_NODE);
13009 install_default(BGP_IPV6_NODE);
13010 install_default(BGP_IPV6M_NODE);
13011 install_default(BGP_IPV6L_NODE);
13012 install_default(BGP_VPNV4_NODE);
13013 install_default(BGP_VPNV6_NODE);
13014 install_default(BGP_FLOWSPECV4_NODE);
13015 install_default(BGP_FLOWSPECV6_NODE);
13016 install_default(BGP_EVPN_NODE);
13017 install_default(BGP_EVPN_VNI_NODE);
13018
13019 /* "bgp local-mac" hidden commands. */
13020 install_element(CONFIG_NODE, &bgp_local_mac_cmd);
13021 install_element(CONFIG_NODE, &no_bgp_local_mac_cmd);
13022
13023 /* bgp route-map delay-timer commands. */
13024 install_element(CONFIG_NODE, &bgp_set_route_map_delay_timer_cmd);
13025 install_element(CONFIG_NODE, &no_bgp_set_route_map_delay_timer_cmd);
13026
13027 /* Dummy commands (Currently not supported) */
13028 install_element(BGP_NODE, &no_synchronization_cmd);
13029 install_element(BGP_NODE, &no_auto_summary_cmd);
13030
13031 /* "router bgp" commands. */
13032 install_element(CONFIG_NODE, &router_bgp_cmd);
13033
13034 /* "no router bgp" commands. */
13035 install_element(CONFIG_NODE, &no_router_bgp_cmd);
13036
13037 /* "bgp router-id" commands. */
13038 install_element(BGP_NODE, &bgp_router_id_cmd);
13039 install_element(BGP_NODE, &no_bgp_router_id_cmd);
13040
13041 /* "bgp cluster-id" commands. */
13042 install_element(BGP_NODE, &bgp_cluster_id_cmd);
13043 install_element(BGP_NODE, &no_bgp_cluster_id_cmd);
13044
13045 /* "bgp confederation" commands. */
13046 install_element(BGP_NODE, &bgp_confederation_identifier_cmd);
13047 install_element(BGP_NODE, &no_bgp_confederation_identifier_cmd);
13048
13049 /* "bgp confederation peers" commands. */
13050 install_element(BGP_NODE, &bgp_confederation_peers_cmd);
13051 install_element(BGP_NODE, &no_bgp_confederation_peers_cmd);
13052
13053 /* bgp max-med command */
13054 install_element(BGP_NODE, &bgp_maxmed_admin_cmd);
13055 install_element(BGP_NODE, &no_bgp_maxmed_admin_cmd);
13056 install_element(BGP_NODE, &bgp_maxmed_admin_medv_cmd);
13057 install_element(BGP_NODE, &bgp_maxmed_onstartup_cmd);
13058 install_element(BGP_NODE, &no_bgp_maxmed_onstartup_cmd);
13059
13060 /* bgp disable-ebgp-connected-nh-check */
13061 install_element(BGP_NODE, &bgp_disable_connected_route_check_cmd);
13062 install_element(BGP_NODE, &no_bgp_disable_connected_route_check_cmd);
13063
13064 /* bgp update-delay command */
13065 install_element(BGP_NODE, &bgp_update_delay_cmd);
13066 install_element(BGP_NODE, &no_bgp_update_delay_cmd);
13067 install_element(BGP_NODE, &bgp_update_delay_establish_wait_cmd);
13068
13069 install_element(BGP_NODE, &bgp_wpkt_quanta_cmd);
13070 install_element(BGP_NODE, &no_bgp_wpkt_quanta_cmd);
13071 install_element(BGP_NODE, &bgp_rpkt_quanta_cmd);
13072 install_element(BGP_NODE, &no_bgp_rpkt_quanta_cmd);
13073
13074 install_element(BGP_NODE, &bgp_coalesce_time_cmd);
13075 install_element(BGP_NODE, &no_bgp_coalesce_time_cmd);
13076
13077 /* "maximum-paths" commands. */
13078 install_element(BGP_NODE, &bgp_maxpaths_hidden_cmd);
13079 install_element(BGP_NODE, &no_bgp_maxpaths_hidden_cmd);
13080 install_element(BGP_IPV4_NODE, &bgp_maxpaths_cmd);
13081 install_element(BGP_IPV4_NODE, &no_bgp_maxpaths_cmd);
13082 install_element(BGP_IPV6_NODE, &bgp_maxpaths_cmd);
13083 install_element(BGP_IPV6_NODE, &no_bgp_maxpaths_cmd);
13084 install_element(BGP_NODE, &bgp_maxpaths_ibgp_hidden_cmd);
13085 install_element(BGP_NODE, &bgp_maxpaths_ibgp_cluster_hidden_cmd);
13086 install_element(BGP_NODE, &no_bgp_maxpaths_ibgp_hidden_cmd);
13087 install_element(BGP_IPV4_NODE, &bgp_maxpaths_ibgp_cmd);
13088 install_element(BGP_IPV4_NODE, &bgp_maxpaths_ibgp_cluster_cmd);
13089 install_element(BGP_IPV4_NODE, &no_bgp_maxpaths_ibgp_cmd);
13090 install_element(BGP_IPV6_NODE, &bgp_maxpaths_ibgp_cmd);
13091 install_element(BGP_IPV6_NODE, &bgp_maxpaths_ibgp_cluster_cmd);
13092 install_element(BGP_IPV6_NODE, &no_bgp_maxpaths_ibgp_cmd);
13093
13094 install_element(BGP_IPV6L_NODE, &bgp_maxpaths_cmd);
13095 install_element(BGP_IPV6L_NODE, &no_bgp_maxpaths_cmd);
13096 install_element(BGP_IPV6L_NODE, &bgp_maxpaths_ibgp_cmd);
13097 install_element(BGP_IPV6L_NODE, &bgp_maxpaths_ibgp_cluster_cmd);
13098 install_element(BGP_IPV6L_NODE, &no_bgp_maxpaths_ibgp_cmd);
13099
13100 /* "timers bgp" commands. */
13101 install_element(BGP_NODE, &bgp_timers_cmd);
13102 install_element(BGP_NODE, &no_bgp_timers_cmd);
13103
13104 /* route-map delay-timer commands - per instance for backwards compat.
13105 */
13106 install_element(BGP_NODE, &bgp_set_route_map_delay_timer_cmd);
13107 install_element(BGP_NODE, &no_bgp_set_route_map_delay_timer_cmd);
13108
13109 /* "bgp client-to-client reflection" commands */
13110 install_element(BGP_NODE, &no_bgp_client_to_client_reflection_cmd);
13111 install_element(BGP_NODE, &bgp_client_to_client_reflection_cmd);
13112
13113 /* "bgp always-compare-med" commands */
13114 install_element(BGP_NODE, &bgp_always_compare_med_cmd);
13115 install_element(BGP_NODE, &no_bgp_always_compare_med_cmd);
13116
13117 /* bgp ebgp-requires-policy */
13118 install_element(BGP_NODE, &bgp_ebgp_requires_policy_cmd);
13119 install_element(BGP_NODE, &no_bgp_ebgp_requires_policy_cmd);
13120
13121 /* "bgp deterministic-med" commands */
13122 install_element(BGP_NODE, &bgp_deterministic_med_cmd);
13123 install_element(BGP_NODE, &no_bgp_deterministic_med_cmd);
13124
13125 /* "bgp graceful-restart" commands */
13126 install_element(BGP_NODE, &bgp_graceful_restart_cmd);
13127 install_element(BGP_NODE, &no_bgp_graceful_restart_cmd);
13128 install_element(BGP_NODE, &bgp_graceful_restart_stalepath_time_cmd);
13129 install_element(BGP_NODE, &no_bgp_graceful_restart_stalepath_time_cmd);
13130 install_element(BGP_NODE, &bgp_graceful_restart_restart_time_cmd);
13131 install_element(BGP_NODE, &no_bgp_graceful_restart_restart_time_cmd);
13132
13133 install_element(BGP_NODE, &bgp_graceful_restart_preserve_fw_cmd);
13134 install_element(BGP_NODE, &no_bgp_graceful_restart_preserve_fw_cmd);
13135
13136 /* "bgp graceful-shutdown" commands */
13137 install_element(BGP_NODE, &bgp_graceful_shutdown_cmd);
13138 install_element(BGP_NODE, &no_bgp_graceful_shutdown_cmd);
13139
13140 /* "bgp fast-external-failover" commands */
13141 install_element(BGP_NODE, &bgp_fast_external_failover_cmd);
13142 install_element(BGP_NODE, &no_bgp_fast_external_failover_cmd);
13143
13144 /* "bgp bestpath compare-routerid" commands */
13145 install_element(BGP_NODE, &bgp_bestpath_compare_router_id_cmd);
13146 install_element(BGP_NODE, &no_bgp_bestpath_compare_router_id_cmd);
13147
13148 /* "bgp bestpath as-path ignore" commands */
13149 install_element(BGP_NODE, &bgp_bestpath_aspath_ignore_cmd);
13150 install_element(BGP_NODE, &no_bgp_bestpath_aspath_ignore_cmd);
13151
13152 /* "bgp bestpath as-path confed" commands */
13153 install_element(BGP_NODE, &bgp_bestpath_aspath_confed_cmd);
13154 install_element(BGP_NODE, &no_bgp_bestpath_aspath_confed_cmd);
13155
13156 /* "bgp bestpath as-path multipath-relax" commands */
13157 install_element(BGP_NODE, &bgp_bestpath_aspath_multipath_relax_cmd);
13158 install_element(BGP_NODE, &no_bgp_bestpath_aspath_multipath_relax_cmd);
13159
13160 /* "bgp log-neighbor-changes" commands */
13161 install_element(BGP_NODE, &bgp_log_neighbor_changes_cmd);
13162 install_element(BGP_NODE, &no_bgp_log_neighbor_changes_cmd);
13163
13164 /* "bgp bestpath med" commands */
13165 install_element(BGP_NODE, &bgp_bestpath_med_cmd);
13166 install_element(BGP_NODE, &no_bgp_bestpath_med_cmd);
13167
13168 /* "no bgp default ipv4-unicast" commands. */
13169 install_element(BGP_NODE, &no_bgp_default_ipv4_unicast_cmd);
13170 install_element(BGP_NODE, &bgp_default_ipv4_unicast_cmd);
13171
13172 /* "bgp network import-check" commands. */
13173 install_element(BGP_NODE, &bgp_network_import_check_cmd);
13174 install_element(BGP_NODE, &bgp_network_import_check_exact_cmd);
13175 install_element(BGP_NODE, &no_bgp_network_import_check_cmd);
13176
13177 /* "bgp default local-preference" commands. */
13178 install_element(BGP_NODE, &bgp_default_local_preference_cmd);
13179 install_element(BGP_NODE, &no_bgp_default_local_preference_cmd);
13180
13181 /* bgp default show-hostname */
13182 install_element(BGP_NODE, &bgp_default_show_hostname_cmd);
13183 install_element(BGP_NODE, &no_bgp_default_show_hostname_cmd);
13184
13185 /* "bgp default subgroup-pkt-queue-max" commands. */
13186 install_element(BGP_NODE, &bgp_default_subgroup_pkt_queue_max_cmd);
13187 install_element(BGP_NODE, &no_bgp_default_subgroup_pkt_queue_max_cmd);
13188
13189 /* bgp ibgp-allow-policy-mods command */
13190 install_element(BGP_NODE, &bgp_rr_allow_outbound_policy_cmd);
13191 install_element(BGP_NODE, &no_bgp_rr_allow_outbound_policy_cmd);
13192
13193 /* "bgp listen limit" commands. */
13194 install_element(BGP_NODE, &bgp_listen_limit_cmd);
13195 install_element(BGP_NODE, &no_bgp_listen_limit_cmd);
13196
13197 /* "bgp listen range" commands. */
13198 install_element(BGP_NODE, &bgp_listen_range_cmd);
13199 install_element(BGP_NODE, &no_bgp_listen_range_cmd);
13200
13201 /* "bgp default shutdown" command */
13202 install_element(BGP_NODE, &bgp_default_shutdown_cmd);
13203
13204 /* "neighbor remote-as" commands. */
13205 install_element(BGP_NODE, &neighbor_remote_as_cmd);
13206 install_element(BGP_NODE, &neighbor_interface_config_cmd);
13207 install_element(BGP_NODE, &neighbor_interface_config_v6only_cmd);
13208 install_element(BGP_NODE, &neighbor_interface_config_remote_as_cmd);
13209 install_element(BGP_NODE,
13210 &neighbor_interface_v6only_config_remote_as_cmd);
13211 install_element(BGP_NODE, &no_neighbor_cmd);
13212 install_element(BGP_NODE, &no_neighbor_interface_config_cmd);
13213
13214 /* "neighbor peer-group" commands. */
13215 install_element(BGP_NODE, &neighbor_peer_group_cmd);
13216 install_element(BGP_NODE, &no_neighbor_peer_group_cmd);
13217 install_element(BGP_NODE,
13218 &no_neighbor_interface_peer_group_remote_as_cmd);
13219
13220 /* "neighbor local-as" commands. */
13221 install_element(BGP_NODE, &neighbor_local_as_cmd);
13222 install_element(BGP_NODE, &neighbor_local_as_no_prepend_cmd);
13223 install_element(BGP_NODE, &neighbor_local_as_no_prepend_replace_as_cmd);
13224 install_element(BGP_NODE, &no_neighbor_local_as_cmd);
13225
13226 /* "neighbor solo" commands. */
13227 install_element(BGP_NODE, &neighbor_solo_cmd);
13228 install_element(BGP_NODE, &no_neighbor_solo_cmd);
13229
13230 /* "neighbor password" commands. */
13231 install_element(BGP_NODE, &neighbor_password_cmd);
13232 install_element(BGP_NODE, &no_neighbor_password_cmd);
13233
13234 /* "neighbor activate" commands. */
13235 install_element(BGP_NODE, &neighbor_activate_hidden_cmd);
13236 install_element(BGP_IPV4_NODE, &neighbor_activate_cmd);
13237 install_element(BGP_IPV4M_NODE, &neighbor_activate_cmd);
13238 install_element(BGP_IPV4L_NODE, &neighbor_activate_cmd);
13239 install_element(BGP_IPV6_NODE, &neighbor_activate_cmd);
13240 install_element(BGP_IPV6M_NODE, &neighbor_activate_cmd);
13241 install_element(BGP_IPV6L_NODE, &neighbor_activate_cmd);
13242 install_element(BGP_VPNV4_NODE, &neighbor_activate_cmd);
13243 install_element(BGP_VPNV6_NODE, &neighbor_activate_cmd);
13244 install_element(BGP_FLOWSPECV4_NODE, &neighbor_activate_cmd);
13245 install_element(BGP_FLOWSPECV6_NODE, &neighbor_activate_cmd);
13246 install_element(BGP_EVPN_NODE, &neighbor_activate_cmd);
13247
13248 /* "no neighbor activate" commands. */
13249 install_element(BGP_NODE, &no_neighbor_activate_hidden_cmd);
13250 install_element(BGP_IPV4_NODE, &no_neighbor_activate_cmd);
13251 install_element(BGP_IPV4M_NODE, &no_neighbor_activate_cmd);
13252 install_element(BGP_IPV4L_NODE, &no_neighbor_activate_cmd);
13253 install_element(BGP_IPV6_NODE, &no_neighbor_activate_cmd);
13254 install_element(BGP_IPV6M_NODE, &no_neighbor_activate_cmd);
13255 install_element(BGP_IPV6L_NODE, &no_neighbor_activate_cmd);
13256 install_element(BGP_VPNV4_NODE, &no_neighbor_activate_cmd);
13257 install_element(BGP_VPNV6_NODE, &no_neighbor_activate_cmd);
13258 install_element(BGP_FLOWSPECV4_NODE, &no_neighbor_activate_cmd);
13259 install_element(BGP_FLOWSPECV6_NODE, &no_neighbor_activate_cmd);
13260 install_element(BGP_EVPN_NODE, &no_neighbor_activate_cmd);
13261
13262 /* "neighbor peer-group" set commands. */
13263 install_element(BGP_NODE, &neighbor_set_peer_group_cmd);
13264 install_element(BGP_IPV4_NODE, &neighbor_set_peer_group_hidden_cmd);
13265 install_element(BGP_IPV4M_NODE, &neighbor_set_peer_group_hidden_cmd);
13266 install_element(BGP_IPV6_NODE, &neighbor_set_peer_group_hidden_cmd);
13267 install_element(BGP_IPV6M_NODE, &neighbor_set_peer_group_hidden_cmd);
13268 install_element(BGP_IPV6L_NODE, &neighbor_set_peer_group_hidden_cmd);
13269 install_element(BGP_VPNV4_NODE, &neighbor_set_peer_group_hidden_cmd);
13270 install_element(BGP_VPNV6_NODE, &neighbor_set_peer_group_hidden_cmd);
13271 install_element(BGP_FLOWSPECV4_NODE,
13272 &neighbor_set_peer_group_hidden_cmd);
13273 install_element(BGP_FLOWSPECV6_NODE,
13274 &neighbor_set_peer_group_hidden_cmd);
13275
13276 /* "no neighbor peer-group unset" commands. */
13277 install_element(BGP_NODE, &no_neighbor_set_peer_group_cmd);
13278 install_element(BGP_IPV4_NODE, &no_neighbor_set_peer_group_hidden_cmd);
13279 install_element(BGP_IPV4M_NODE, &no_neighbor_set_peer_group_hidden_cmd);
13280 install_element(BGP_IPV6_NODE, &no_neighbor_set_peer_group_hidden_cmd);
13281 install_element(BGP_IPV6M_NODE, &no_neighbor_set_peer_group_hidden_cmd);
13282 install_element(BGP_IPV6L_NODE, &no_neighbor_set_peer_group_hidden_cmd);
13283 install_element(BGP_VPNV4_NODE, &no_neighbor_set_peer_group_hidden_cmd);
13284 install_element(BGP_VPNV6_NODE, &no_neighbor_set_peer_group_hidden_cmd);
13285 install_element(BGP_FLOWSPECV4_NODE,
13286 &no_neighbor_set_peer_group_hidden_cmd);
13287 install_element(BGP_FLOWSPECV6_NODE,
13288 &no_neighbor_set_peer_group_hidden_cmd);
13289
13290 /* "neighbor softreconfiguration inbound" commands.*/
13291 install_element(BGP_NODE, &neighbor_soft_reconfiguration_hidden_cmd);
13292 install_element(BGP_NODE, &no_neighbor_soft_reconfiguration_hidden_cmd);
13293 install_element(BGP_IPV4_NODE, &neighbor_soft_reconfiguration_cmd);
13294 install_element(BGP_IPV4_NODE, &no_neighbor_soft_reconfiguration_cmd);
13295 install_element(BGP_IPV4L_NODE, &neighbor_soft_reconfiguration_cmd);
13296 install_element(BGP_IPV4L_NODE, &no_neighbor_soft_reconfiguration_cmd);
13297 install_element(BGP_IPV4M_NODE, &neighbor_soft_reconfiguration_cmd);
13298 install_element(BGP_IPV4M_NODE, &no_neighbor_soft_reconfiguration_cmd);
13299 install_element(BGP_IPV6_NODE, &neighbor_soft_reconfiguration_cmd);
13300 install_element(BGP_IPV6_NODE, &no_neighbor_soft_reconfiguration_cmd);
13301 install_element(BGP_IPV6M_NODE, &neighbor_soft_reconfiguration_cmd);
13302 install_element(BGP_IPV6M_NODE, &no_neighbor_soft_reconfiguration_cmd);
13303 install_element(BGP_IPV6L_NODE, &neighbor_soft_reconfiguration_cmd);
13304 install_element(BGP_IPV6L_NODE, &no_neighbor_soft_reconfiguration_cmd);
13305 install_element(BGP_VPNV4_NODE, &neighbor_soft_reconfiguration_cmd);
13306 install_element(BGP_VPNV4_NODE, &no_neighbor_soft_reconfiguration_cmd);
13307 install_element(BGP_VPNV6_NODE, &neighbor_soft_reconfiguration_cmd);
13308 install_element(BGP_VPNV6_NODE, &no_neighbor_soft_reconfiguration_cmd);
13309 install_element(BGP_FLOWSPECV4_NODE,
13310 &neighbor_soft_reconfiguration_cmd);
13311 install_element(BGP_FLOWSPECV4_NODE,
13312 &no_neighbor_soft_reconfiguration_cmd);
13313 install_element(BGP_FLOWSPECV6_NODE,
13314 &neighbor_soft_reconfiguration_cmd);
13315 install_element(BGP_FLOWSPECV6_NODE,
13316 &no_neighbor_soft_reconfiguration_cmd);
13317 install_element(BGP_EVPN_NODE, &neighbor_soft_reconfiguration_cmd);
13318 install_element(BGP_EVPN_NODE, &no_neighbor_soft_reconfiguration_cmd);
13319
13320 /* "neighbor attribute-unchanged" commands. */
13321 install_element(BGP_NODE, &neighbor_attr_unchanged_hidden_cmd);
13322 install_element(BGP_NODE, &no_neighbor_attr_unchanged_hidden_cmd);
13323 install_element(BGP_IPV4_NODE, &neighbor_attr_unchanged_cmd);
13324 install_element(BGP_IPV4_NODE, &no_neighbor_attr_unchanged_cmd);
13325 install_element(BGP_IPV4M_NODE, &neighbor_attr_unchanged_cmd);
13326 install_element(BGP_IPV4M_NODE, &no_neighbor_attr_unchanged_cmd);
13327 install_element(BGP_IPV4L_NODE, &neighbor_attr_unchanged_cmd);
13328 install_element(BGP_IPV4L_NODE, &no_neighbor_attr_unchanged_cmd);
13329 install_element(BGP_IPV6_NODE, &neighbor_attr_unchanged_cmd);
13330 install_element(BGP_IPV6_NODE, &no_neighbor_attr_unchanged_cmd);
13331 install_element(BGP_IPV6M_NODE, &neighbor_attr_unchanged_cmd);
13332 install_element(BGP_IPV6M_NODE, &no_neighbor_attr_unchanged_cmd);
13333 install_element(BGP_IPV6L_NODE, &neighbor_attr_unchanged_cmd);
13334 install_element(BGP_IPV6L_NODE, &no_neighbor_attr_unchanged_cmd);
13335 install_element(BGP_VPNV4_NODE, &neighbor_attr_unchanged_cmd);
13336 install_element(BGP_VPNV4_NODE, &no_neighbor_attr_unchanged_cmd);
13337 install_element(BGP_VPNV6_NODE, &neighbor_attr_unchanged_cmd);
13338 install_element(BGP_VPNV6_NODE, &no_neighbor_attr_unchanged_cmd);
13339
13340 install_element(BGP_EVPN_NODE, &neighbor_attr_unchanged_cmd);
13341 install_element(BGP_EVPN_NODE, &no_neighbor_attr_unchanged_cmd);
13342
13343 /* "nexthop-local unchanged" commands */
13344 install_element(BGP_IPV6_NODE, &neighbor_nexthop_local_unchanged_cmd);
13345 install_element(BGP_IPV6_NODE,
13346 &no_neighbor_nexthop_local_unchanged_cmd);
13347
13348 /* "neighbor next-hop-self" commands. */
13349 install_element(BGP_NODE, &neighbor_nexthop_self_hidden_cmd);
13350 install_element(BGP_NODE, &no_neighbor_nexthop_self_hidden_cmd);
13351 install_element(BGP_IPV4_NODE, &neighbor_nexthop_self_cmd);
13352 install_element(BGP_IPV4_NODE, &no_neighbor_nexthop_self_cmd);
13353 install_element(BGP_IPV4M_NODE, &neighbor_nexthop_self_cmd);
13354 install_element(BGP_IPV4M_NODE, &no_neighbor_nexthop_self_cmd);
13355 install_element(BGP_IPV4L_NODE, &neighbor_nexthop_self_cmd);
13356 install_element(BGP_IPV4L_NODE, &no_neighbor_nexthop_self_cmd);
13357 install_element(BGP_IPV6_NODE, &neighbor_nexthop_self_cmd);
13358 install_element(BGP_IPV6_NODE, &no_neighbor_nexthop_self_cmd);
13359 install_element(BGP_IPV6M_NODE, &neighbor_nexthop_self_cmd);
13360 install_element(BGP_IPV6M_NODE, &no_neighbor_nexthop_self_cmd);
13361 install_element(BGP_IPV6L_NODE, &neighbor_nexthop_self_cmd);
13362 install_element(BGP_IPV6L_NODE, &no_neighbor_nexthop_self_cmd);
13363 install_element(BGP_VPNV4_NODE, &neighbor_nexthop_self_cmd);
13364 install_element(BGP_VPNV4_NODE, &no_neighbor_nexthop_self_cmd);
13365 install_element(BGP_VPNV6_NODE, &neighbor_nexthop_self_cmd);
13366 install_element(BGP_VPNV6_NODE, &no_neighbor_nexthop_self_cmd);
13367 install_element(BGP_EVPN_NODE, &neighbor_nexthop_self_cmd);
13368 install_element(BGP_EVPN_NODE, &no_neighbor_nexthop_self_cmd);
13369
13370 /* "neighbor next-hop-self force" commands. */
13371 install_element(BGP_NODE, &neighbor_nexthop_self_force_hidden_cmd);
13372 install_element(BGP_NODE, &no_neighbor_nexthop_self_force_hidden_cmd);
13373 install_element(BGP_NODE, &neighbor_nexthop_self_all_hidden_cmd);
13374 install_element(BGP_NODE, &no_neighbor_nexthop_self_all_hidden_cmd);
13375 install_element(BGP_IPV4_NODE, &neighbor_nexthop_self_force_cmd);
13376 install_element(BGP_IPV4_NODE, &no_neighbor_nexthop_self_force_cmd);
13377 install_element(BGP_IPV4_NODE, &neighbor_nexthop_self_all_hidden_cmd);
13378 install_element(BGP_IPV4_NODE,
13379 &no_neighbor_nexthop_self_all_hidden_cmd);
13380 install_element(BGP_IPV4M_NODE, &neighbor_nexthop_self_force_cmd);
13381 install_element(BGP_IPV4M_NODE, &no_neighbor_nexthop_self_force_cmd);
13382 install_element(BGP_IPV4M_NODE, &neighbor_nexthop_self_all_hidden_cmd);
13383 install_element(BGP_IPV4M_NODE,
13384 &no_neighbor_nexthop_self_all_hidden_cmd);
13385 install_element(BGP_IPV4L_NODE, &neighbor_nexthop_self_force_cmd);
13386 install_element(BGP_IPV4L_NODE, &no_neighbor_nexthop_self_force_cmd);
13387 install_element(BGP_IPV4L_NODE, &neighbor_nexthop_self_all_hidden_cmd);
13388 install_element(BGP_IPV4L_NODE,
13389 &no_neighbor_nexthop_self_all_hidden_cmd);
13390 install_element(BGP_IPV6_NODE, &neighbor_nexthop_self_force_cmd);
13391 install_element(BGP_IPV6_NODE, &no_neighbor_nexthop_self_force_cmd);
13392 install_element(BGP_IPV6_NODE, &neighbor_nexthop_self_all_hidden_cmd);
13393 install_element(BGP_IPV6_NODE,
13394 &no_neighbor_nexthop_self_all_hidden_cmd);
13395 install_element(BGP_IPV6M_NODE, &neighbor_nexthop_self_force_cmd);
13396 install_element(BGP_IPV6M_NODE, &no_neighbor_nexthop_self_force_cmd);
13397 install_element(BGP_IPV6M_NODE, &neighbor_nexthop_self_all_hidden_cmd);
13398 install_element(BGP_IPV6M_NODE,
13399 &no_neighbor_nexthop_self_all_hidden_cmd);
13400 install_element(BGP_IPV6L_NODE, &neighbor_nexthop_self_force_cmd);
13401 install_element(BGP_IPV6L_NODE, &no_neighbor_nexthop_self_force_cmd);
13402 install_element(BGP_IPV6L_NODE, &neighbor_nexthop_self_all_hidden_cmd);
13403 install_element(BGP_IPV6L_NODE,
13404 &no_neighbor_nexthop_self_all_hidden_cmd);
13405 install_element(BGP_VPNV4_NODE, &neighbor_nexthop_self_force_cmd);
13406 install_element(BGP_VPNV4_NODE, &no_neighbor_nexthop_self_force_cmd);
13407 install_element(BGP_VPNV4_NODE, &neighbor_nexthop_self_all_hidden_cmd);
13408 install_element(BGP_VPNV4_NODE,
13409 &no_neighbor_nexthop_self_all_hidden_cmd);
13410 install_element(BGP_VPNV6_NODE, &neighbor_nexthop_self_force_cmd);
13411 install_element(BGP_VPNV6_NODE, &no_neighbor_nexthop_self_force_cmd);
13412 install_element(BGP_VPNV6_NODE, &neighbor_nexthop_self_all_hidden_cmd);
13413 install_element(BGP_VPNV6_NODE,
13414 &no_neighbor_nexthop_self_all_hidden_cmd);
13415
13416 /* "neighbor as-override" commands. */
13417 install_element(BGP_NODE, &neighbor_as_override_hidden_cmd);
13418 install_element(BGP_NODE, &no_neighbor_as_override_hidden_cmd);
13419 install_element(BGP_IPV4_NODE, &neighbor_as_override_cmd);
13420 install_element(BGP_IPV4_NODE, &no_neighbor_as_override_cmd);
13421 install_element(BGP_IPV4M_NODE, &neighbor_as_override_cmd);
13422 install_element(BGP_IPV4M_NODE, &no_neighbor_as_override_cmd);
13423 install_element(BGP_IPV4L_NODE, &neighbor_as_override_cmd);
13424 install_element(BGP_IPV4L_NODE, &no_neighbor_as_override_cmd);
13425 install_element(BGP_IPV6_NODE, &neighbor_as_override_cmd);
13426 install_element(BGP_IPV6_NODE, &no_neighbor_as_override_cmd);
13427 install_element(BGP_IPV6M_NODE, &neighbor_as_override_cmd);
13428 install_element(BGP_IPV6M_NODE, &no_neighbor_as_override_cmd);
13429 install_element(BGP_IPV6L_NODE, &neighbor_as_override_cmd);
13430 install_element(BGP_IPV6L_NODE, &no_neighbor_as_override_cmd);
13431 install_element(BGP_VPNV4_NODE, &neighbor_as_override_cmd);
13432 install_element(BGP_VPNV4_NODE, &no_neighbor_as_override_cmd);
13433 install_element(BGP_VPNV6_NODE, &neighbor_as_override_cmd);
13434 install_element(BGP_VPNV6_NODE, &no_neighbor_as_override_cmd);
13435
13436 /* "neighbor remove-private-AS" commands. */
13437 install_element(BGP_NODE, &neighbor_remove_private_as_hidden_cmd);
13438 install_element(BGP_NODE, &no_neighbor_remove_private_as_hidden_cmd);
13439 install_element(BGP_NODE, &neighbor_remove_private_as_all_hidden_cmd);
13440 install_element(BGP_NODE,
13441 &no_neighbor_remove_private_as_all_hidden_cmd);
13442 install_element(BGP_NODE,
13443 &neighbor_remove_private_as_replace_as_hidden_cmd);
13444 install_element(BGP_NODE,
13445 &no_neighbor_remove_private_as_replace_as_hidden_cmd);
13446 install_element(BGP_NODE,
13447 &neighbor_remove_private_as_all_replace_as_hidden_cmd);
13448 install_element(
13449 BGP_NODE,
13450 &no_neighbor_remove_private_as_all_replace_as_hidden_cmd);
13451 install_element(BGP_IPV4_NODE, &neighbor_remove_private_as_cmd);
13452 install_element(BGP_IPV4_NODE, &no_neighbor_remove_private_as_cmd);
13453 install_element(BGP_IPV4_NODE, &neighbor_remove_private_as_all_cmd);
13454 install_element(BGP_IPV4_NODE, &no_neighbor_remove_private_as_all_cmd);
13455 install_element(BGP_IPV4_NODE,
13456 &neighbor_remove_private_as_replace_as_cmd);
13457 install_element(BGP_IPV4_NODE,
13458 &no_neighbor_remove_private_as_replace_as_cmd);
13459 install_element(BGP_IPV4_NODE,
13460 &neighbor_remove_private_as_all_replace_as_cmd);
13461 install_element(BGP_IPV4_NODE,
13462 &no_neighbor_remove_private_as_all_replace_as_cmd);
13463 install_element(BGP_IPV4M_NODE, &neighbor_remove_private_as_cmd);
13464 install_element(BGP_IPV4M_NODE, &no_neighbor_remove_private_as_cmd);
13465 install_element(BGP_IPV4M_NODE, &neighbor_remove_private_as_all_cmd);
13466 install_element(BGP_IPV4M_NODE, &no_neighbor_remove_private_as_all_cmd);
13467 install_element(BGP_IPV4M_NODE,
13468 &neighbor_remove_private_as_replace_as_cmd);
13469 install_element(BGP_IPV4M_NODE,
13470 &no_neighbor_remove_private_as_replace_as_cmd);
13471 install_element(BGP_IPV4M_NODE,
13472 &neighbor_remove_private_as_all_replace_as_cmd);
13473 install_element(BGP_IPV4M_NODE,
13474 &no_neighbor_remove_private_as_all_replace_as_cmd);
13475 install_element(BGP_IPV4L_NODE, &neighbor_remove_private_as_cmd);
13476 install_element(BGP_IPV4L_NODE, &no_neighbor_remove_private_as_cmd);
13477 install_element(BGP_IPV4L_NODE, &neighbor_remove_private_as_all_cmd);
13478 install_element(BGP_IPV4L_NODE, &no_neighbor_remove_private_as_all_cmd);
13479 install_element(BGP_IPV4L_NODE,
13480 &neighbor_remove_private_as_replace_as_cmd);
13481 install_element(BGP_IPV4L_NODE,
13482 &no_neighbor_remove_private_as_replace_as_cmd);
13483 install_element(BGP_IPV4L_NODE,
13484 &neighbor_remove_private_as_all_replace_as_cmd);
13485 install_element(BGP_IPV4L_NODE,
13486 &no_neighbor_remove_private_as_all_replace_as_cmd);
13487 install_element(BGP_IPV6_NODE, &neighbor_remove_private_as_cmd);
13488 install_element(BGP_IPV6_NODE, &no_neighbor_remove_private_as_cmd);
13489 install_element(BGP_IPV6_NODE, &neighbor_remove_private_as_all_cmd);
13490 install_element(BGP_IPV6_NODE, &no_neighbor_remove_private_as_all_cmd);
13491 install_element(BGP_IPV6_NODE,
13492 &neighbor_remove_private_as_replace_as_cmd);
13493 install_element(BGP_IPV6_NODE,
13494 &no_neighbor_remove_private_as_replace_as_cmd);
13495 install_element(BGP_IPV6_NODE,
13496 &neighbor_remove_private_as_all_replace_as_cmd);
13497 install_element(BGP_IPV6_NODE,
13498 &no_neighbor_remove_private_as_all_replace_as_cmd);
13499 install_element(BGP_IPV6M_NODE, &neighbor_remove_private_as_cmd);
13500 install_element(BGP_IPV6M_NODE, &no_neighbor_remove_private_as_cmd);
13501 install_element(BGP_IPV6M_NODE, &neighbor_remove_private_as_all_cmd);
13502 install_element(BGP_IPV6M_NODE, &no_neighbor_remove_private_as_all_cmd);
13503 install_element(BGP_IPV6M_NODE,
13504 &neighbor_remove_private_as_replace_as_cmd);
13505 install_element(BGP_IPV6M_NODE,
13506 &no_neighbor_remove_private_as_replace_as_cmd);
13507 install_element(BGP_IPV6M_NODE,
13508 &neighbor_remove_private_as_all_replace_as_cmd);
13509 install_element(BGP_IPV6M_NODE,
13510 &no_neighbor_remove_private_as_all_replace_as_cmd);
13511 install_element(BGP_IPV6L_NODE, &neighbor_remove_private_as_cmd);
13512 install_element(BGP_IPV6L_NODE, &no_neighbor_remove_private_as_cmd);
13513 install_element(BGP_IPV6L_NODE, &neighbor_remove_private_as_all_cmd);
13514 install_element(BGP_IPV6L_NODE, &no_neighbor_remove_private_as_all_cmd);
13515 install_element(BGP_IPV6L_NODE,
13516 &neighbor_remove_private_as_replace_as_cmd);
13517 install_element(BGP_IPV6L_NODE,
13518 &no_neighbor_remove_private_as_replace_as_cmd);
13519 install_element(BGP_IPV6L_NODE,
13520 &neighbor_remove_private_as_all_replace_as_cmd);
13521 install_element(BGP_IPV6L_NODE,
13522 &no_neighbor_remove_private_as_all_replace_as_cmd);
13523 install_element(BGP_VPNV4_NODE, &neighbor_remove_private_as_cmd);
13524 install_element(BGP_VPNV4_NODE, &no_neighbor_remove_private_as_cmd);
13525 install_element(BGP_VPNV4_NODE, &neighbor_remove_private_as_all_cmd);
13526 install_element(BGP_VPNV4_NODE, &no_neighbor_remove_private_as_all_cmd);
13527 install_element(BGP_VPNV4_NODE,
13528 &neighbor_remove_private_as_replace_as_cmd);
13529 install_element(BGP_VPNV4_NODE,
13530 &no_neighbor_remove_private_as_replace_as_cmd);
13531 install_element(BGP_VPNV4_NODE,
13532 &neighbor_remove_private_as_all_replace_as_cmd);
13533 install_element(BGP_VPNV4_NODE,
13534 &no_neighbor_remove_private_as_all_replace_as_cmd);
13535 install_element(BGP_VPNV6_NODE, &neighbor_remove_private_as_cmd);
13536 install_element(BGP_VPNV6_NODE, &no_neighbor_remove_private_as_cmd);
13537 install_element(BGP_VPNV6_NODE, &neighbor_remove_private_as_all_cmd);
13538 install_element(BGP_VPNV6_NODE, &no_neighbor_remove_private_as_all_cmd);
13539 install_element(BGP_VPNV6_NODE,
13540 &neighbor_remove_private_as_replace_as_cmd);
13541 install_element(BGP_VPNV6_NODE,
13542 &no_neighbor_remove_private_as_replace_as_cmd);
13543 install_element(BGP_VPNV6_NODE,
13544 &neighbor_remove_private_as_all_replace_as_cmd);
13545 install_element(BGP_VPNV6_NODE,
13546 &no_neighbor_remove_private_as_all_replace_as_cmd);
13547
13548 /* "neighbor send-community" commands.*/
13549 install_element(BGP_NODE, &neighbor_send_community_hidden_cmd);
13550 install_element(BGP_NODE, &neighbor_send_community_type_hidden_cmd);
13551 install_element(BGP_NODE, &no_neighbor_send_community_hidden_cmd);
13552 install_element(BGP_NODE, &no_neighbor_send_community_type_hidden_cmd);
13553 install_element(BGP_IPV4_NODE, &neighbor_send_community_cmd);
13554 install_element(BGP_IPV4_NODE, &neighbor_send_community_type_cmd);
13555 install_element(BGP_IPV4_NODE, &no_neighbor_send_community_cmd);
13556 install_element(BGP_IPV4_NODE, &no_neighbor_send_community_type_cmd);
13557 install_element(BGP_IPV4M_NODE, &neighbor_send_community_cmd);
13558 install_element(BGP_IPV4M_NODE, &neighbor_send_community_type_cmd);
13559 install_element(BGP_IPV4M_NODE, &no_neighbor_send_community_cmd);
13560 install_element(BGP_IPV4M_NODE, &no_neighbor_send_community_type_cmd);
13561 install_element(BGP_IPV4L_NODE, &neighbor_send_community_cmd);
13562 install_element(BGP_IPV4L_NODE, &neighbor_send_community_type_cmd);
13563 install_element(BGP_IPV4L_NODE, &no_neighbor_send_community_cmd);
13564 install_element(BGP_IPV4L_NODE, &no_neighbor_send_community_type_cmd);
13565 install_element(BGP_IPV6_NODE, &neighbor_send_community_cmd);
13566 install_element(BGP_IPV6_NODE, &neighbor_send_community_type_cmd);
13567 install_element(BGP_IPV6_NODE, &no_neighbor_send_community_cmd);
13568 install_element(BGP_IPV6_NODE, &no_neighbor_send_community_type_cmd);
13569 install_element(BGP_IPV6M_NODE, &neighbor_send_community_cmd);
13570 install_element(BGP_IPV6M_NODE, &neighbor_send_community_type_cmd);
13571 install_element(BGP_IPV6M_NODE, &no_neighbor_send_community_cmd);
13572 install_element(BGP_IPV6M_NODE, &no_neighbor_send_community_type_cmd);
13573 install_element(BGP_IPV6L_NODE, &neighbor_send_community_cmd);
13574 install_element(BGP_IPV6L_NODE, &neighbor_send_community_type_cmd);
13575 install_element(BGP_IPV6L_NODE, &no_neighbor_send_community_cmd);
13576 install_element(BGP_IPV6L_NODE, &no_neighbor_send_community_type_cmd);
13577 install_element(BGP_VPNV4_NODE, &neighbor_send_community_cmd);
13578 install_element(BGP_VPNV4_NODE, &neighbor_send_community_type_cmd);
13579 install_element(BGP_VPNV4_NODE, &no_neighbor_send_community_cmd);
13580 install_element(BGP_VPNV4_NODE, &no_neighbor_send_community_type_cmd);
13581 install_element(BGP_VPNV6_NODE, &neighbor_send_community_cmd);
13582 install_element(BGP_VPNV6_NODE, &neighbor_send_community_type_cmd);
13583 install_element(BGP_VPNV6_NODE, &no_neighbor_send_community_cmd);
13584 install_element(BGP_VPNV6_NODE, &no_neighbor_send_community_type_cmd);
13585
13586 /* "neighbor route-reflector" commands.*/
13587 install_element(BGP_NODE, &neighbor_route_reflector_client_hidden_cmd);
13588 install_element(BGP_NODE,
13589 &no_neighbor_route_reflector_client_hidden_cmd);
13590 install_element(BGP_IPV4_NODE, &neighbor_route_reflector_client_cmd);
13591 install_element(BGP_IPV4_NODE, &no_neighbor_route_reflector_client_cmd);
13592 install_element(BGP_IPV4M_NODE, &neighbor_route_reflector_client_cmd);
13593 install_element(BGP_IPV4M_NODE,
13594 &no_neighbor_route_reflector_client_cmd);
13595 install_element(BGP_IPV4L_NODE, &neighbor_route_reflector_client_cmd);
13596 install_element(BGP_IPV4L_NODE,
13597 &no_neighbor_route_reflector_client_cmd);
13598 install_element(BGP_IPV6_NODE, &neighbor_route_reflector_client_cmd);
13599 install_element(BGP_IPV6_NODE, &no_neighbor_route_reflector_client_cmd);
13600 install_element(BGP_IPV6M_NODE, &neighbor_route_reflector_client_cmd);
13601 install_element(BGP_IPV6M_NODE,
13602 &no_neighbor_route_reflector_client_cmd);
13603 install_element(BGP_IPV6L_NODE, &neighbor_route_reflector_client_cmd);
13604 install_element(BGP_IPV6L_NODE,
13605 &no_neighbor_route_reflector_client_cmd);
13606 install_element(BGP_VPNV4_NODE, &neighbor_route_reflector_client_cmd);
13607 install_element(BGP_VPNV4_NODE,
13608 &no_neighbor_route_reflector_client_cmd);
13609 install_element(BGP_VPNV6_NODE, &neighbor_route_reflector_client_cmd);
13610 install_element(BGP_VPNV6_NODE,
13611 &no_neighbor_route_reflector_client_cmd);
13612 install_element(BGP_FLOWSPECV4_NODE,
13613 &neighbor_route_reflector_client_cmd);
13614 install_element(BGP_FLOWSPECV4_NODE,
13615 &no_neighbor_route_reflector_client_cmd);
13616 install_element(BGP_FLOWSPECV6_NODE,
13617 &neighbor_route_reflector_client_cmd);
13618 install_element(BGP_FLOWSPECV6_NODE,
13619 &no_neighbor_route_reflector_client_cmd);
13620 install_element(BGP_EVPN_NODE, &neighbor_route_reflector_client_cmd);
13621 install_element(BGP_EVPN_NODE, &no_neighbor_route_reflector_client_cmd);
13622
13623 /* "neighbor route-server" commands.*/
13624 install_element(BGP_NODE, &neighbor_route_server_client_hidden_cmd);
13625 install_element(BGP_NODE, &no_neighbor_route_server_client_hidden_cmd);
13626 install_element(BGP_IPV4_NODE, &neighbor_route_server_client_cmd);
13627 install_element(BGP_IPV4_NODE, &no_neighbor_route_server_client_cmd);
13628 install_element(BGP_IPV4M_NODE, &neighbor_route_server_client_cmd);
13629 install_element(BGP_IPV4M_NODE, &no_neighbor_route_server_client_cmd);
13630 install_element(BGP_IPV4L_NODE, &neighbor_route_server_client_cmd);
13631 install_element(BGP_IPV4L_NODE, &no_neighbor_route_server_client_cmd);
13632 install_element(BGP_IPV6_NODE, &neighbor_route_server_client_cmd);
13633 install_element(BGP_IPV6_NODE, &no_neighbor_route_server_client_cmd);
13634 install_element(BGP_IPV6M_NODE, &neighbor_route_server_client_cmd);
13635 install_element(BGP_IPV6M_NODE, &no_neighbor_route_server_client_cmd);
13636 install_element(BGP_IPV6L_NODE, &neighbor_route_server_client_cmd);
13637 install_element(BGP_IPV6L_NODE, &no_neighbor_route_server_client_cmd);
13638 install_element(BGP_VPNV4_NODE, &neighbor_route_server_client_cmd);
13639 install_element(BGP_VPNV4_NODE, &no_neighbor_route_server_client_cmd);
13640 install_element(BGP_VPNV6_NODE, &neighbor_route_server_client_cmd);
13641 install_element(BGP_VPNV6_NODE, &no_neighbor_route_server_client_cmd);
13642 install_element(BGP_EVPN_NODE, &neighbor_route_server_client_cmd);
13643 install_element(BGP_EVPN_NODE, &no_neighbor_route_server_client_cmd);
13644 install_element(BGP_FLOWSPECV4_NODE, &neighbor_route_server_client_cmd);
13645 install_element(BGP_FLOWSPECV4_NODE,
13646 &no_neighbor_route_server_client_cmd);
13647 install_element(BGP_FLOWSPECV6_NODE, &neighbor_route_server_client_cmd);
13648 install_element(BGP_FLOWSPECV6_NODE,
13649 &no_neighbor_route_server_client_cmd);
13650
13651 /* "neighbor addpath-tx-all-paths" commands.*/
13652 install_element(BGP_NODE, &neighbor_addpath_tx_all_paths_hidden_cmd);
13653 install_element(BGP_NODE, &no_neighbor_addpath_tx_all_paths_hidden_cmd);
13654 install_element(BGP_IPV4_NODE, &neighbor_addpath_tx_all_paths_cmd);
13655 install_element(BGP_IPV4_NODE, &no_neighbor_addpath_tx_all_paths_cmd);
13656 install_element(BGP_IPV4M_NODE, &neighbor_addpath_tx_all_paths_cmd);
13657 install_element(BGP_IPV4M_NODE, &no_neighbor_addpath_tx_all_paths_cmd);
13658 install_element(BGP_IPV4L_NODE, &neighbor_addpath_tx_all_paths_cmd);
13659 install_element(BGP_IPV4L_NODE, &no_neighbor_addpath_tx_all_paths_cmd);
13660 install_element(BGP_IPV6_NODE, &neighbor_addpath_tx_all_paths_cmd);
13661 install_element(BGP_IPV6_NODE, &no_neighbor_addpath_tx_all_paths_cmd);
13662 install_element(BGP_IPV6M_NODE, &neighbor_addpath_tx_all_paths_cmd);
13663 install_element(BGP_IPV6M_NODE, &no_neighbor_addpath_tx_all_paths_cmd);
13664 install_element(BGP_IPV6L_NODE, &neighbor_addpath_tx_all_paths_cmd);
13665 install_element(BGP_IPV6L_NODE, &no_neighbor_addpath_tx_all_paths_cmd);
13666 install_element(BGP_VPNV4_NODE, &neighbor_addpath_tx_all_paths_cmd);
13667 install_element(BGP_VPNV4_NODE, &no_neighbor_addpath_tx_all_paths_cmd);
13668 install_element(BGP_VPNV6_NODE, &neighbor_addpath_tx_all_paths_cmd);
13669 install_element(BGP_VPNV6_NODE, &no_neighbor_addpath_tx_all_paths_cmd);
13670
13671 /* "neighbor addpath-tx-bestpath-per-AS" commands.*/
13672 install_element(BGP_NODE,
13673 &neighbor_addpath_tx_bestpath_per_as_hidden_cmd);
13674 install_element(BGP_NODE,
13675 &no_neighbor_addpath_tx_bestpath_per_as_hidden_cmd);
13676 install_element(BGP_IPV4_NODE,
13677 &neighbor_addpath_tx_bestpath_per_as_cmd);
13678 install_element(BGP_IPV4_NODE,
13679 &no_neighbor_addpath_tx_bestpath_per_as_cmd);
13680 install_element(BGP_IPV4M_NODE,
13681 &neighbor_addpath_tx_bestpath_per_as_cmd);
13682 install_element(BGP_IPV4M_NODE,
13683 &no_neighbor_addpath_tx_bestpath_per_as_cmd);
13684 install_element(BGP_IPV4L_NODE,
13685 &neighbor_addpath_tx_bestpath_per_as_cmd);
13686 install_element(BGP_IPV4L_NODE,
13687 &no_neighbor_addpath_tx_bestpath_per_as_cmd);
13688 install_element(BGP_IPV6_NODE,
13689 &neighbor_addpath_tx_bestpath_per_as_cmd);
13690 install_element(BGP_IPV6_NODE,
13691 &no_neighbor_addpath_tx_bestpath_per_as_cmd);
13692 install_element(BGP_IPV6M_NODE,
13693 &neighbor_addpath_tx_bestpath_per_as_cmd);
13694 install_element(BGP_IPV6M_NODE,
13695 &no_neighbor_addpath_tx_bestpath_per_as_cmd);
13696 install_element(BGP_IPV6L_NODE,
13697 &neighbor_addpath_tx_bestpath_per_as_cmd);
13698 install_element(BGP_IPV6L_NODE,
13699 &no_neighbor_addpath_tx_bestpath_per_as_cmd);
13700 install_element(BGP_VPNV4_NODE,
13701 &neighbor_addpath_tx_bestpath_per_as_cmd);
13702 install_element(BGP_VPNV4_NODE,
13703 &no_neighbor_addpath_tx_bestpath_per_as_cmd);
13704 install_element(BGP_VPNV6_NODE,
13705 &neighbor_addpath_tx_bestpath_per_as_cmd);
13706 install_element(BGP_VPNV6_NODE,
13707 &no_neighbor_addpath_tx_bestpath_per_as_cmd);
13708
13709 /* "neighbor passive" commands. */
13710 install_element(BGP_NODE, &neighbor_passive_cmd);
13711 install_element(BGP_NODE, &no_neighbor_passive_cmd);
13712
13713
13714 /* "neighbor shutdown" commands. */
13715 install_element(BGP_NODE, &neighbor_shutdown_cmd);
13716 install_element(BGP_NODE, &no_neighbor_shutdown_cmd);
13717 install_element(BGP_NODE, &neighbor_shutdown_msg_cmd);
13718 install_element(BGP_NODE, &no_neighbor_shutdown_msg_cmd);
13719
13720 /* "neighbor capability extended-nexthop" commands.*/
13721 install_element(BGP_NODE, &neighbor_capability_enhe_cmd);
13722 install_element(BGP_NODE, &no_neighbor_capability_enhe_cmd);
13723
13724 /* "neighbor capability orf prefix-list" commands.*/
13725 install_element(BGP_NODE, &neighbor_capability_orf_prefix_hidden_cmd);
13726 install_element(BGP_NODE,
13727 &no_neighbor_capability_orf_prefix_hidden_cmd);
13728 install_element(BGP_IPV4_NODE, &neighbor_capability_orf_prefix_cmd);
13729 install_element(BGP_IPV4_NODE, &no_neighbor_capability_orf_prefix_cmd);
13730 install_element(BGP_IPV4M_NODE, &neighbor_capability_orf_prefix_cmd);
13731 install_element(BGP_IPV4M_NODE, &no_neighbor_capability_orf_prefix_cmd);
13732 install_element(BGP_IPV4L_NODE, &neighbor_capability_orf_prefix_cmd);
13733 install_element(BGP_IPV4L_NODE, &no_neighbor_capability_orf_prefix_cmd);
13734 install_element(BGP_IPV6_NODE, &neighbor_capability_orf_prefix_cmd);
13735 install_element(BGP_IPV6_NODE, &no_neighbor_capability_orf_prefix_cmd);
13736 install_element(BGP_IPV6M_NODE, &neighbor_capability_orf_prefix_cmd);
13737 install_element(BGP_IPV6M_NODE, &no_neighbor_capability_orf_prefix_cmd);
13738 install_element(BGP_IPV6L_NODE, &neighbor_capability_orf_prefix_cmd);
13739 install_element(BGP_IPV6L_NODE, &no_neighbor_capability_orf_prefix_cmd);
13740
13741 /* "neighbor capability dynamic" commands.*/
13742 install_element(BGP_NODE, &neighbor_capability_dynamic_cmd);
13743 install_element(BGP_NODE, &no_neighbor_capability_dynamic_cmd);
13744
13745 /* "neighbor dont-capability-negotiate" commands. */
13746 install_element(BGP_NODE, &neighbor_dont_capability_negotiate_cmd);
13747 install_element(BGP_NODE, &no_neighbor_dont_capability_negotiate_cmd);
13748
13749 /* "neighbor ebgp-multihop" commands. */
13750 install_element(BGP_NODE, &neighbor_ebgp_multihop_cmd);
13751 install_element(BGP_NODE, &neighbor_ebgp_multihop_ttl_cmd);
13752 install_element(BGP_NODE, &no_neighbor_ebgp_multihop_cmd);
13753
13754 /* "neighbor disable-connected-check" commands. */
13755 install_element(BGP_NODE, &neighbor_disable_connected_check_cmd);
13756 install_element(BGP_NODE, &no_neighbor_disable_connected_check_cmd);
13757
13758 /* "neighbor enforce-first-as" commands. */
13759 install_element(BGP_NODE, &neighbor_enforce_first_as_cmd);
13760 install_element(BGP_NODE, &no_neighbor_enforce_first_as_cmd);
13761
13762 /* "neighbor description" commands. */
13763 install_element(BGP_NODE, &neighbor_description_cmd);
13764 install_element(BGP_NODE, &no_neighbor_description_cmd);
13765 install_element(BGP_NODE, &no_neighbor_description_comment_cmd);
13766
13767 /* "neighbor update-source" commands. "*/
13768 install_element(BGP_NODE, &neighbor_update_source_cmd);
13769 install_element(BGP_NODE, &no_neighbor_update_source_cmd);
13770
13771 /* "neighbor default-originate" commands. */
13772 install_element(BGP_NODE, &neighbor_default_originate_hidden_cmd);
13773 install_element(BGP_NODE, &neighbor_default_originate_rmap_hidden_cmd);
13774 install_element(BGP_NODE, &no_neighbor_default_originate_hidden_cmd);
13775 install_element(BGP_IPV4_NODE, &neighbor_default_originate_cmd);
13776 install_element(BGP_IPV4_NODE, &neighbor_default_originate_rmap_cmd);
13777 install_element(BGP_IPV4_NODE, &no_neighbor_default_originate_cmd);
13778 install_element(BGP_IPV4M_NODE, &neighbor_default_originate_cmd);
13779 install_element(BGP_IPV4M_NODE, &neighbor_default_originate_rmap_cmd);
13780 install_element(BGP_IPV4M_NODE, &no_neighbor_default_originate_cmd);
13781 install_element(BGP_IPV4L_NODE, &neighbor_default_originate_cmd);
13782 install_element(BGP_IPV4L_NODE, &neighbor_default_originate_rmap_cmd);
13783 install_element(BGP_IPV4L_NODE, &no_neighbor_default_originate_cmd);
13784 install_element(BGP_IPV6_NODE, &neighbor_default_originate_cmd);
13785 install_element(BGP_IPV6_NODE, &neighbor_default_originate_rmap_cmd);
13786 install_element(BGP_IPV6_NODE, &no_neighbor_default_originate_cmd);
13787 install_element(BGP_IPV6M_NODE, &neighbor_default_originate_cmd);
13788 install_element(BGP_IPV6M_NODE, &neighbor_default_originate_rmap_cmd);
13789 install_element(BGP_IPV6M_NODE, &no_neighbor_default_originate_cmd);
13790 install_element(BGP_IPV6L_NODE, &neighbor_default_originate_cmd);
13791 install_element(BGP_IPV6L_NODE, &neighbor_default_originate_rmap_cmd);
13792 install_element(BGP_IPV6L_NODE, &no_neighbor_default_originate_cmd);
13793
13794 /* "neighbor port" commands. */
13795 install_element(BGP_NODE, &neighbor_port_cmd);
13796 install_element(BGP_NODE, &no_neighbor_port_cmd);
13797
13798 /* "neighbor weight" commands. */
13799 install_element(BGP_NODE, &neighbor_weight_hidden_cmd);
13800 install_element(BGP_NODE, &no_neighbor_weight_hidden_cmd);
13801
13802 install_element(BGP_IPV4_NODE, &neighbor_weight_cmd);
13803 install_element(BGP_IPV4_NODE, &no_neighbor_weight_cmd);
13804 install_element(BGP_IPV4M_NODE, &neighbor_weight_cmd);
13805 install_element(BGP_IPV4M_NODE, &no_neighbor_weight_cmd);
13806 install_element(BGP_IPV4L_NODE, &neighbor_weight_cmd);
13807 install_element(BGP_IPV4L_NODE, &no_neighbor_weight_cmd);
13808 install_element(BGP_IPV6_NODE, &neighbor_weight_cmd);
13809 install_element(BGP_IPV6_NODE, &no_neighbor_weight_cmd);
13810 install_element(BGP_IPV6M_NODE, &neighbor_weight_cmd);
13811 install_element(BGP_IPV6M_NODE, &no_neighbor_weight_cmd);
13812 install_element(BGP_IPV6L_NODE, &neighbor_weight_cmd);
13813 install_element(BGP_IPV6L_NODE, &no_neighbor_weight_cmd);
13814 install_element(BGP_VPNV4_NODE, &neighbor_weight_cmd);
13815 install_element(BGP_VPNV4_NODE, &no_neighbor_weight_cmd);
13816 install_element(BGP_VPNV6_NODE, &neighbor_weight_cmd);
13817 install_element(BGP_VPNV6_NODE, &no_neighbor_weight_cmd);
13818
13819 /* "neighbor override-capability" commands. */
13820 install_element(BGP_NODE, &neighbor_override_capability_cmd);
13821 install_element(BGP_NODE, &no_neighbor_override_capability_cmd);
13822
13823 /* "neighbor strict-capability-match" commands. */
13824 install_element(BGP_NODE, &neighbor_strict_capability_cmd);
13825 install_element(BGP_NODE, &no_neighbor_strict_capability_cmd);
13826
13827 /* "neighbor timers" commands. */
13828 install_element(BGP_NODE, &neighbor_timers_cmd);
13829 install_element(BGP_NODE, &no_neighbor_timers_cmd);
13830
13831 /* "neighbor timers connect" commands. */
13832 install_element(BGP_NODE, &neighbor_timers_connect_cmd);
13833 install_element(BGP_NODE, &no_neighbor_timers_connect_cmd);
13834
13835 /* "neighbor advertisement-interval" commands. */
13836 install_element(BGP_NODE, &neighbor_advertise_interval_cmd);
13837 install_element(BGP_NODE, &no_neighbor_advertise_interval_cmd);
13838
13839 /* "neighbor interface" commands. */
13840 install_element(BGP_NODE, &neighbor_interface_cmd);
13841 install_element(BGP_NODE, &no_neighbor_interface_cmd);
13842
13843 /* "neighbor distribute" commands. */
13844 install_element(BGP_NODE, &neighbor_distribute_list_hidden_cmd);
13845 install_element(BGP_NODE, &no_neighbor_distribute_list_hidden_cmd);
13846 install_element(BGP_IPV4_NODE, &neighbor_distribute_list_cmd);
13847 install_element(BGP_IPV4_NODE, &no_neighbor_distribute_list_cmd);
13848 install_element(BGP_IPV4M_NODE, &neighbor_distribute_list_cmd);
13849 install_element(BGP_IPV4M_NODE, &no_neighbor_distribute_list_cmd);
13850 install_element(BGP_IPV4L_NODE, &neighbor_distribute_list_cmd);
13851 install_element(BGP_IPV4L_NODE, &no_neighbor_distribute_list_cmd);
13852 install_element(BGP_IPV6_NODE, &neighbor_distribute_list_cmd);
13853 install_element(BGP_IPV6_NODE, &no_neighbor_distribute_list_cmd);
13854 install_element(BGP_IPV6M_NODE, &neighbor_distribute_list_cmd);
13855 install_element(BGP_IPV6M_NODE, &no_neighbor_distribute_list_cmd);
13856 install_element(BGP_IPV6L_NODE, &neighbor_distribute_list_cmd);
13857 install_element(BGP_IPV6L_NODE, &no_neighbor_distribute_list_cmd);
13858 install_element(BGP_VPNV4_NODE, &neighbor_distribute_list_cmd);
13859 install_element(BGP_VPNV4_NODE, &no_neighbor_distribute_list_cmd);
13860 install_element(BGP_VPNV6_NODE, &neighbor_distribute_list_cmd);
13861 install_element(BGP_VPNV6_NODE, &no_neighbor_distribute_list_cmd);
13862
13863 /* "neighbor prefix-list" commands. */
13864 install_element(BGP_NODE, &neighbor_prefix_list_hidden_cmd);
13865 install_element(BGP_NODE, &no_neighbor_prefix_list_hidden_cmd);
13866 install_element(BGP_IPV4_NODE, &neighbor_prefix_list_cmd);
13867 install_element(BGP_IPV4_NODE, &no_neighbor_prefix_list_cmd);
13868 install_element(BGP_IPV4M_NODE, &neighbor_prefix_list_cmd);
13869 install_element(BGP_IPV4M_NODE, &no_neighbor_prefix_list_cmd);
13870 install_element(BGP_IPV4L_NODE, &neighbor_prefix_list_cmd);
13871 install_element(BGP_IPV4L_NODE, &no_neighbor_prefix_list_cmd);
13872 install_element(BGP_IPV6_NODE, &neighbor_prefix_list_cmd);
13873 install_element(BGP_IPV6_NODE, &no_neighbor_prefix_list_cmd);
13874 install_element(BGP_IPV6M_NODE, &neighbor_prefix_list_cmd);
13875 install_element(BGP_IPV6M_NODE, &no_neighbor_prefix_list_cmd);
13876 install_element(BGP_IPV6L_NODE, &neighbor_prefix_list_cmd);
13877 install_element(BGP_IPV6L_NODE, &no_neighbor_prefix_list_cmd);
13878 install_element(BGP_VPNV4_NODE, &neighbor_prefix_list_cmd);
13879 install_element(BGP_VPNV4_NODE, &no_neighbor_prefix_list_cmd);
13880 install_element(BGP_VPNV6_NODE, &neighbor_prefix_list_cmd);
13881 install_element(BGP_VPNV6_NODE, &no_neighbor_prefix_list_cmd);
13882 install_element(BGP_FLOWSPECV4_NODE, &neighbor_prefix_list_cmd);
13883 install_element(BGP_FLOWSPECV4_NODE, &no_neighbor_prefix_list_cmd);
13884 install_element(BGP_FLOWSPECV6_NODE, &neighbor_prefix_list_cmd);
13885 install_element(BGP_FLOWSPECV6_NODE, &no_neighbor_prefix_list_cmd);
13886
13887 /* "neighbor filter-list" commands. */
13888 install_element(BGP_NODE, &neighbor_filter_list_hidden_cmd);
13889 install_element(BGP_NODE, &no_neighbor_filter_list_hidden_cmd);
13890 install_element(BGP_IPV4_NODE, &neighbor_filter_list_cmd);
13891 install_element(BGP_IPV4_NODE, &no_neighbor_filter_list_cmd);
13892 install_element(BGP_IPV4M_NODE, &neighbor_filter_list_cmd);
13893 install_element(BGP_IPV4M_NODE, &no_neighbor_filter_list_cmd);
13894 install_element(BGP_IPV4L_NODE, &neighbor_filter_list_cmd);
13895 install_element(BGP_IPV4L_NODE, &no_neighbor_filter_list_cmd);
13896 install_element(BGP_IPV6_NODE, &neighbor_filter_list_cmd);
13897 install_element(BGP_IPV6_NODE, &no_neighbor_filter_list_cmd);
13898 install_element(BGP_IPV6M_NODE, &neighbor_filter_list_cmd);
13899 install_element(BGP_IPV6M_NODE, &no_neighbor_filter_list_cmd);
13900 install_element(BGP_IPV6L_NODE, &neighbor_filter_list_cmd);
13901 install_element(BGP_IPV6L_NODE, &no_neighbor_filter_list_cmd);
13902 install_element(BGP_VPNV4_NODE, &neighbor_filter_list_cmd);
13903 install_element(BGP_VPNV4_NODE, &no_neighbor_filter_list_cmd);
13904 install_element(BGP_VPNV6_NODE, &neighbor_filter_list_cmd);
13905 install_element(BGP_VPNV6_NODE, &no_neighbor_filter_list_cmd);
13906 install_element(BGP_FLOWSPECV4_NODE, &neighbor_filter_list_cmd);
13907 install_element(BGP_FLOWSPECV4_NODE, &no_neighbor_filter_list_cmd);
13908 install_element(BGP_FLOWSPECV6_NODE, &neighbor_filter_list_cmd);
13909 install_element(BGP_FLOWSPECV6_NODE, &no_neighbor_filter_list_cmd);
13910
13911 /* "neighbor route-map" commands. */
13912 install_element(BGP_NODE, &neighbor_route_map_hidden_cmd);
13913 install_element(BGP_NODE, &no_neighbor_route_map_hidden_cmd);
13914 install_element(BGP_IPV4_NODE, &neighbor_route_map_cmd);
13915 install_element(BGP_IPV4_NODE, &no_neighbor_route_map_cmd);
13916 install_element(BGP_IPV4M_NODE, &neighbor_route_map_cmd);
13917 install_element(BGP_IPV4M_NODE, &no_neighbor_route_map_cmd);
13918 install_element(BGP_IPV4L_NODE, &neighbor_route_map_cmd);
13919 install_element(BGP_IPV4L_NODE, &no_neighbor_route_map_cmd);
13920 install_element(BGP_IPV6_NODE, &neighbor_route_map_cmd);
13921 install_element(BGP_IPV6_NODE, &no_neighbor_route_map_cmd);
13922 install_element(BGP_IPV6M_NODE, &neighbor_route_map_cmd);
13923 install_element(BGP_IPV6M_NODE, &no_neighbor_route_map_cmd);
13924 install_element(BGP_IPV6L_NODE, &neighbor_route_map_cmd);
13925 install_element(BGP_IPV6L_NODE, &no_neighbor_route_map_cmd);
13926 install_element(BGP_VPNV4_NODE, &neighbor_route_map_cmd);
13927 install_element(BGP_VPNV4_NODE, &no_neighbor_route_map_cmd);
13928 install_element(BGP_VPNV6_NODE, &neighbor_route_map_cmd);
13929 install_element(BGP_VPNV6_NODE, &no_neighbor_route_map_cmd);
13930 install_element(BGP_FLOWSPECV4_NODE, &neighbor_route_map_cmd);
13931 install_element(BGP_FLOWSPECV4_NODE, &no_neighbor_route_map_cmd);
13932 install_element(BGP_FLOWSPECV6_NODE, &neighbor_route_map_cmd);
13933 install_element(BGP_FLOWSPECV6_NODE, &no_neighbor_route_map_cmd);
13934 install_element(BGP_EVPN_NODE, &neighbor_route_map_cmd);
13935 install_element(BGP_EVPN_NODE, &no_neighbor_route_map_cmd);
13936
13937 /* "neighbor unsuppress-map" commands. */
13938 install_element(BGP_NODE, &neighbor_unsuppress_map_hidden_cmd);
13939 install_element(BGP_NODE, &no_neighbor_unsuppress_map_hidden_cmd);
13940 install_element(BGP_IPV4_NODE, &neighbor_unsuppress_map_cmd);
13941 install_element(BGP_IPV4_NODE, &no_neighbor_unsuppress_map_cmd);
13942 install_element(BGP_IPV4M_NODE, &neighbor_unsuppress_map_cmd);
13943 install_element(BGP_IPV4M_NODE, &no_neighbor_unsuppress_map_cmd);
13944 install_element(BGP_IPV4L_NODE, &neighbor_unsuppress_map_cmd);
13945 install_element(BGP_IPV4L_NODE, &no_neighbor_unsuppress_map_cmd);
13946 install_element(BGP_IPV6_NODE, &neighbor_unsuppress_map_cmd);
13947 install_element(BGP_IPV6_NODE, &no_neighbor_unsuppress_map_cmd);
13948 install_element(BGP_IPV6M_NODE, &neighbor_unsuppress_map_cmd);
13949 install_element(BGP_IPV6M_NODE, &no_neighbor_unsuppress_map_cmd);
13950 install_element(BGP_IPV6L_NODE, &neighbor_unsuppress_map_cmd);
13951 install_element(BGP_IPV6L_NODE, &no_neighbor_unsuppress_map_cmd);
13952 install_element(BGP_VPNV4_NODE, &neighbor_unsuppress_map_cmd);
13953 install_element(BGP_VPNV4_NODE, &no_neighbor_unsuppress_map_cmd);
13954 install_element(BGP_VPNV6_NODE, &neighbor_unsuppress_map_cmd);
13955 install_element(BGP_VPNV6_NODE, &no_neighbor_unsuppress_map_cmd);
13956
13957 /* "neighbor maximum-prefix" commands. */
13958 install_element(BGP_NODE, &neighbor_maximum_prefix_hidden_cmd);
13959 install_element(BGP_NODE,
13960 &neighbor_maximum_prefix_threshold_hidden_cmd);
13961 install_element(BGP_NODE, &neighbor_maximum_prefix_warning_hidden_cmd);
13962 install_element(BGP_NODE,
13963 &neighbor_maximum_prefix_threshold_warning_hidden_cmd);
13964 install_element(BGP_NODE, &neighbor_maximum_prefix_restart_hidden_cmd);
13965 install_element(BGP_NODE,
13966 &neighbor_maximum_prefix_threshold_restart_hidden_cmd);
13967 install_element(BGP_NODE, &no_neighbor_maximum_prefix_hidden_cmd);
13968 install_element(BGP_IPV4_NODE, &neighbor_maximum_prefix_cmd);
13969 install_element(BGP_IPV4_NODE, &neighbor_maximum_prefix_threshold_cmd);
13970 install_element(BGP_IPV4_NODE, &neighbor_maximum_prefix_warning_cmd);
13971 install_element(BGP_IPV4_NODE,
13972 &neighbor_maximum_prefix_threshold_warning_cmd);
13973 install_element(BGP_IPV4_NODE, &neighbor_maximum_prefix_restart_cmd);
13974 install_element(BGP_IPV4_NODE,
13975 &neighbor_maximum_prefix_threshold_restart_cmd);
13976 install_element(BGP_IPV4_NODE, &no_neighbor_maximum_prefix_cmd);
13977 install_element(BGP_IPV4M_NODE, &neighbor_maximum_prefix_cmd);
13978 install_element(BGP_IPV4M_NODE, &neighbor_maximum_prefix_threshold_cmd);
13979 install_element(BGP_IPV4M_NODE, &neighbor_maximum_prefix_warning_cmd);
13980 install_element(BGP_IPV4M_NODE,
13981 &neighbor_maximum_prefix_threshold_warning_cmd);
13982 install_element(BGP_IPV4M_NODE, &neighbor_maximum_prefix_restart_cmd);
13983 install_element(BGP_IPV4M_NODE,
13984 &neighbor_maximum_prefix_threshold_restart_cmd);
13985 install_element(BGP_IPV4M_NODE, &no_neighbor_maximum_prefix_cmd);
13986 install_element(BGP_IPV4L_NODE, &neighbor_maximum_prefix_cmd);
13987 install_element(BGP_IPV4L_NODE, &neighbor_maximum_prefix_threshold_cmd);
13988 install_element(BGP_IPV4L_NODE, &neighbor_maximum_prefix_warning_cmd);
13989 install_element(BGP_IPV4L_NODE,
13990 &neighbor_maximum_prefix_threshold_warning_cmd);
13991 install_element(BGP_IPV4L_NODE, &neighbor_maximum_prefix_restart_cmd);
13992 install_element(BGP_IPV4L_NODE,
13993 &neighbor_maximum_prefix_threshold_restart_cmd);
13994 install_element(BGP_IPV4L_NODE, &no_neighbor_maximum_prefix_cmd);
13995 install_element(BGP_IPV6_NODE, &neighbor_maximum_prefix_cmd);
13996 install_element(BGP_IPV6_NODE, &neighbor_maximum_prefix_threshold_cmd);
13997 install_element(BGP_IPV6_NODE, &neighbor_maximum_prefix_warning_cmd);
13998 install_element(BGP_IPV6_NODE,
13999 &neighbor_maximum_prefix_threshold_warning_cmd);
14000 install_element(BGP_IPV6_NODE, &neighbor_maximum_prefix_restart_cmd);
14001 install_element(BGP_IPV6_NODE,
14002 &neighbor_maximum_prefix_threshold_restart_cmd);
14003 install_element(BGP_IPV6_NODE, &no_neighbor_maximum_prefix_cmd);
14004 install_element(BGP_IPV6M_NODE, &neighbor_maximum_prefix_cmd);
14005 install_element(BGP_IPV6M_NODE, &neighbor_maximum_prefix_threshold_cmd);
14006 install_element(BGP_IPV6M_NODE, &neighbor_maximum_prefix_warning_cmd);
14007 install_element(BGP_IPV6M_NODE,
14008 &neighbor_maximum_prefix_threshold_warning_cmd);
14009 install_element(BGP_IPV6M_NODE, &neighbor_maximum_prefix_restart_cmd);
14010 install_element(BGP_IPV6M_NODE,
14011 &neighbor_maximum_prefix_threshold_restart_cmd);
14012 install_element(BGP_IPV6M_NODE, &no_neighbor_maximum_prefix_cmd);
14013 install_element(BGP_IPV6L_NODE, &neighbor_maximum_prefix_cmd);
14014 install_element(BGP_IPV6L_NODE, &neighbor_maximum_prefix_threshold_cmd);
14015 install_element(BGP_IPV6L_NODE, &neighbor_maximum_prefix_warning_cmd);
14016 install_element(BGP_IPV6L_NODE,
14017 &neighbor_maximum_prefix_threshold_warning_cmd);
14018 install_element(BGP_IPV6L_NODE, &neighbor_maximum_prefix_restart_cmd);
14019 install_element(BGP_IPV6L_NODE,
14020 &neighbor_maximum_prefix_threshold_restart_cmd);
14021 install_element(BGP_IPV6L_NODE, &no_neighbor_maximum_prefix_cmd);
14022 install_element(BGP_VPNV4_NODE, &neighbor_maximum_prefix_cmd);
14023 install_element(BGP_VPNV4_NODE, &neighbor_maximum_prefix_threshold_cmd);
14024 install_element(BGP_VPNV4_NODE, &neighbor_maximum_prefix_warning_cmd);
14025 install_element(BGP_VPNV4_NODE,
14026 &neighbor_maximum_prefix_threshold_warning_cmd);
14027 install_element(BGP_VPNV4_NODE, &neighbor_maximum_prefix_restart_cmd);
14028 install_element(BGP_VPNV4_NODE,
14029 &neighbor_maximum_prefix_threshold_restart_cmd);
14030 install_element(BGP_VPNV4_NODE, &no_neighbor_maximum_prefix_cmd);
14031 install_element(BGP_VPNV6_NODE, &neighbor_maximum_prefix_cmd);
14032 install_element(BGP_VPNV6_NODE, &neighbor_maximum_prefix_threshold_cmd);
14033 install_element(BGP_VPNV6_NODE, &neighbor_maximum_prefix_warning_cmd);
14034 install_element(BGP_VPNV6_NODE,
14035 &neighbor_maximum_prefix_threshold_warning_cmd);
14036 install_element(BGP_VPNV6_NODE, &neighbor_maximum_prefix_restart_cmd);
14037 install_element(BGP_VPNV6_NODE,
14038 &neighbor_maximum_prefix_threshold_restart_cmd);
14039 install_element(BGP_VPNV6_NODE, &no_neighbor_maximum_prefix_cmd);
14040
14041 /* "neighbor allowas-in" */
14042 install_element(BGP_NODE, &neighbor_allowas_in_hidden_cmd);
14043 install_element(BGP_NODE, &no_neighbor_allowas_in_hidden_cmd);
14044 install_element(BGP_IPV4_NODE, &neighbor_allowas_in_cmd);
14045 install_element(BGP_IPV4_NODE, &no_neighbor_allowas_in_cmd);
14046 install_element(BGP_IPV4M_NODE, &neighbor_allowas_in_cmd);
14047 install_element(BGP_IPV4M_NODE, &no_neighbor_allowas_in_cmd);
14048 install_element(BGP_IPV4L_NODE, &neighbor_allowas_in_cmd);
14049 install_element(BGP_IPV4L_NODE, &no_neighbor_allowas_in_cmd);
14050 install_element(BGP_IPV6_NODE, &neighbor_allowas_in_cmd);
14051 install_element(BGP_IPV6_NODE, &no_neighbor_allowas_in_cmd);
14052 install_element(BGP_IPV6M_NODE, &neighbor_allowas_in_cmd);
14053 install_element(BGP_IPV6M_NODE, &no_neighbor_allowas_in_cmd);
14054 install_element(BGP_IPV6L_NODE, &neighbor_allowas_in_cmd);
14055 install_element(BGP_IPV6L_NODE, &no_neighbor_allowas_in_cmd);
14056 install_element(BGP_VPNV4_NODE, &neighbor_allowas_in_cmd);
14057 install_element(BGP_VPNV4_NODE, &no_neighbor_allowas_in_cmd);
14058 install_element(BGP_VPNV6_NODE, &neighbor_allowas_in_cmd);
14059 install_element(BGP_VPNV6_NODE, &no_neighbor_allowas_in_cmd);
14060 install_element(BGP_EVPN_NODE, &neighbor_allowas_in_cmd);
14061 install_element(BGP_EVPN_NODE, &no_neighbor_allowas_in_cmd);
14062
14063 /* address-family commands. */
14064 install_element(BGP_NODE, &address_family_ipv4_safi_cmd);
14065 install_element(BGP_NODE, &address_family_ipv6_safi_cmd);
14066 #ifdef KEEP_OLD_VPN_COMMANDS
14067 install_element(BGP_NODE, &address_family_vpnv4_cmd);
14068 install_element(BGP_NODE, &address_family_vpnv6_cmd);
14069 #endif /* KEEP_OLD_VPN_COMMANDS */
14070
14071 install_element(BGP_NODE, &address_family_evpn_cmd);
14072
14073 /* "exit-address-family" command. */
14074 install_element(BGP_IPV4_NODE, &exit_address_family_cmd);
14075 install_element(BGP_IPV4M_NODE, &exit_address_family_cmd);
14076 install_element(BGP_IPV4L_NODE, &exit_address_family_cmd);
14077 install_element(BGP_IPV6_NODE, &exit_address_family_cmd);
14078 install_element(BGP_IPV6M_NODE, &exit_address_family_cmd);
14079 install_element(BGP_IPV6L_NODE, &exit_address_family_cmd);
14080 install_element(BGP_VPNV4_NODE, &exit_address_family_cmd);
14081 install_element(BGP_VPNV6_NODE, &exit_address_family_cmd);
14082 install_element(BGP_FLOWSPECV4_NODE, &exit_address_family_cmd);
14083 install_element(BGP_FLOWSPECV6_NODE, &exit_address_family_cmd);
14084 install_element(BGP_EVPN_NODE, &exit_address_family_cmd);
14085
14086 /* "clear ip bgp commands" */
14087 install_element(ENABLE_NODE, &clear_ip_bgp_all_cmd);
14088
14089 /* clear ip bgp prefix */
14090 install_element(ENABLE_NODE, &clear_ip_bgp_prefix_cmd);
14091 install_element(ENABLE_NODE, &clear_bgp_ipv6_safi_prefix_cmd);
14092 install_element(ENABLE_NODE, &clear_bgp_instance_ipv6_safi_prefix_cmd);
14093
14094 /* "show [ip] bgp summary" commands. */
14095 install_element(VIEW_NODE, &show_bgp_instance_all_ipv6_updgrps_cmd);
14096 install_element(VIEW_NODE, &show_bgp_l2vpn_evpn_updgrps_cmd);
14097 install_element(VIEW_NODE, &show_bgp_instance_updgrps_stats_cmd);
14098 install_element(VIEW_NODE, &show_bgp_updgrps_stats_cmd);
14099 install_element(VIEW_NODE, &show_ip_bgp_instance_updgrps_adj_s_cmd);
14100 install_element(VIEW_NODE, &show_ip_bgp_summary_cmd);
14101 install_element(VIEW_NODE, &show_ip_bgp_updgrps_cmd);
14102
14103 /* "show [ip] bgp neighbors" commands. */
14104 install_element(VIEW_NODE, &show_ip_bgp_neighbors_cmd);
14105
14106 /* "show [ip] bgp peer-group" commands. */
14107 install_element(VIEW_NODE, &show_ip_bgp_peer_groups_cmd);
14108
14109 /* "show [ip] bgp paths" commands. */
14110 install_element(VIEW_NODE, &show_ip_bgp_paths_cmd);
14111
14112 /* "show [ip] bgp community" commands. */
14113 install_element(VIEW_NODE, &show_ip_bgp_community_info_cmd);
14114
14115 /* "show ip bgp large-community" commands. */
14116 install_element(VIEW_NODE, &show_ip_bgp_lcommunity_info_cmd);
14117 /* "show [ip] bgp attribute-info" commands. */
14118 install_element(VIEW_NODE, &show_ip_bgp_attr_info_cmd);
14119 /* "show [ip] bgp route-leak" command */
14120 install_element(VIEW_NODE, &show_ip_bgp_route_leak_cmd);
14121
14122 /* "redistribute" commands. */
14123 install_element(BGP_NODE, &bgp_redistribute_ipv4_hidden_cmd);
14124 install_element(BGP_NODE, &no_bgp_redistribute_ipv4_hidden_cmd);
14125 install_element(BGP_NODE, &bgp_redistribute_ipv4_rmap_hidden_cmd);
14126 install_element(BGP_NODE, &bgp_redistribute_ipv4_metric_hidden_cmd);
14127 install_element(BGP_NODE,
14128 &bgp_redistribute_ipv4_rmap_metric_hidden_cmd);
14129 install_element(BGP_NODE,
14130 &bgp_redistribute_ipv4_metric_rmap_hidden_cmd);
14131 install_element(BGP_NODE, &bgp_redistribute_ipv4_ospf_hidden_cmd);
14132 install_element(BGP_NODE, &no_bgp_redistribute_ipv4_ospf_hidden_cmd);
14133 install_element(BGP_NODE, &bgp_redistribute_ipv4_ospf_rmap_hidden_cmd);
14134 install_element(BGP_NODE,
14135 &bgp_redistribute_ipv4_ospf_metric_hidden_cmd);
14136 install_element(BGP_NODE,
14137 &bgp_redistribute_ipv4_ospf_rmap_metric_hidden_cmd);
14138 install_element(BGP_NODE,
14139 &bgp_redistribute_ipv4_ospf_metric_rmap_hidden_cmd);
14140 install_element(BGP_IPV4_NODE, &bgp_redistribute_ipv4_cmd);
14141 install_element(BGP_IPV4_NODE, &no_bgp_redistribute_ipv4_cmd);
14142 install_element(BGP_IPV4_NODE, &bgp_redistribute_ipv4_rmap_cmd);
14143 install_element(BGP_IPV4_NODE, &bgp_redistribute_ipv4_metric_cmd);
14144 install_element(BGP_IPV4_NODE, &bgp_redistribute_ipv4_rmap_metric_cmd);
14145 install_element(BGP_IPV4_NODE, &bgp_redistribute_ipv4_metric_rmap_cmd);
14146 install_element(BGP_IPV4_NODE, &bgp_redistribute_ipv4_ospf_cmd);
14147 install_element(BGP_IPV4_NODE, &no_bgp_redistribute_ipv4_ospf_cmd);
14148 install_element(BGP_IPV4_NODE, &bgp_redistribute_ipv4_ospf_rmap_cmd);
14149 install_element(BGP_IPV4_NODE, &bgp_redistribute_ipv4_ospf_metric_cmd);
14150 install_element(BGP_IPV4_NODE,
14151 &bgp_redistribute_ipv4_ospf_rmap_metric_cmd);
14152 install_element(BGP_IPV4_NODE,
14153 &bgp_redistribute_ipv4_ospf_metric_rmap_cmd);
14154 install_element(BGP_IPV6_NODE, &bgp_redistribute_ipv6_cmd);
14155 install_element(BGP_IPV6_NODE, &no_bgp_redistribute_ipv6_cmd);
14156 install_element(BGP_IPV6_NODE, &bgp_redistribute_ipv6_rmap_cmd);
14157 install_element(BGP_IPV6_NODE, &bgp_redistribute_ipv6_metric_cmd);
14158 install_element(BGP_IPV6_NODE, &bgp_redistribute_ipv6_rmap_metric_cmd);
14159 install_element(BGP_IPV6_NODE, &bgp_redistribute_ipv6_metric_rmap_cmd);
14160
14161 /* import|export vpn [route-map WORD] */
14162 install_element(BGP_IPV4_NODE, &bgp_imexport_vpn_cmd);
14163 install_element(BGP_IPV6_NODE, &bgp_imexport_vpn_cmd);
14164
14165 install_element(BGP_IPV4_NODE, &bgp_imexport_vrf_cmd);
14166 install_element(BGP_IPV6_NODE, &bgp_imexport_vrf_cmd);
14167
14168 /* ttl_security commands */
14169 install_element(BGP_NODE, &neighbor_ttl_security_cmd);
14170 install_element(BGP_NODE, &no_neighbor_ttl_security_cmd);
14171
14172 /* "show [ip] bgp memory" commands. */
14173 install_element(VIEW_NODE, &show_bgp_memory_cmd);
14174
14175 /* "show bgp martian next-hop" */
14176 install_element(VIEW_NODE, &show_bgp_martian_nexthop_db_cmd);
14177
14178 install_element(VIEW_NODE, &show_bgp_mac_hash_cmd);
14179
14180 /* "show [ip] bgp views" commands. */
14181 install_element(VIEW_NODE, &show_bgp_views_cmd);
14182
14183 /* "show [ip] bgp vrfs" commands. */
14184 install_element(VIEW_NODE, &show_bgp_vrfs_cmd);
14185
14186 /* Community-list. */
14187 community_list_vty();
14188
14189 /* vpn-policy commands */
14190 install_element(BGP_IPV4_NODE, &af_rd_vpn_export_cmd);
14191 install_element(BGP_IPV6_NODE, &af_rd_vpn_export_cmd);
14192 install_element(BGP_IPV4_NODE, &af_label_vpn_export_cmd);
14193 install_element(BGP_IPV6_NODE, &af_label_vpn_export_cmd);
14194 install_element(BGP_IPV4_NODE, &af_nexthop_vpn_export_cmd);
14195 install_element(BGP_IPV6_NODE, &af_nexthop_vpn_export_cmd);
14196 install_element(BGP_IPV4_NODE, &af_rt_vpn_imexport_cmd);
14197 install_element(BGP_IPV6_NODE, &af_rt_vpn_imexport_cmd);
14198 install_element(BGP_IPV4_NODE, &af_route_map_vpn_imexport_cmd);
14199 install_element(BGP_IPV6_NODE, &af_route_map_vpn_imexport_cmd);
14200 install_element(BGP_IPV4_NODE, &af_import_vrf_route_map_cmd);
14201 install_element(BGP_IPV6_NODE, &af_import_vrf_route_map_cmd);
14202
14203 install_element(BGP_IPV4_NODE, &af_routetarget_import_cmd);
14204 install_element(BGP_IPV6_NODE, &af_routetarget_import_cmd);
14205
14206 install_element(BGP_IPV4_NODE, &af_no_rd_vpn_export_cmd);
14207 install_element(BGP_IPV6_NODE, &af_no_rd_vpn_export_cmd);
14208 install_element(BGP_IPV4_NODE, &af_no_label_vpn_export_cmd);
14209 install_element(BGP_IPV6_NODE, &af_no_label_vpn_export_cmd);
14210 install_element(BGP_IPV4_NODE, &af_no_nexthop_vpn_export_cmd);
14211 install_element(BGP_IPV6_NODE, &af_no_nexthop_vpn_export_cmd);
14212 install_element(BGP_IPV4_NODE, &af_no_rt_vpn_imexport_cmd);
14213 install_element(BGP_IPV6_NODE, &af_no_rt_vpn_imexport_cmd);
14214 install_element(BGP_IPV4_NODE, &af_no_route_map_vpn_imexport_cmd);
14215 install_element(BGP_IPV6_NODE, &af_no_route_map_vpn_imexport_cmd);
14216 install_element(BGP_IPV4_NODE, &af_no_import_vrf_route_map_cmd);
14217 install_element(BGP_IPV6_NODE, &af_no_import_vrf_route_map_cmd);
14218 }
14219
14220 #include "memory.h"
14221 #include "bgp_regex.h"
14222 #include "bgp_clist.h"
14223 #include "bgp_ecommunity.h"
14224
14225 /* VTY functions. */
14226
14227 /* Direction value to string conversion. */
14228 static const char *community_direct_str(int direct)
14229 {
14230 switch (direct) {
14231 case COMMUNITY_DENY:
14232 return "deny";
14233 case COMMUNITY_PERMIT:
14234 return "permit";
14235 default:
14236 return "unknown";
14237 }
14238 }
14239
14240 /* Display error string. */
14241 static void community_list_perror(struct vty *vty, int ret)
14242 {
14243 switch (ret) {
14244 case COMMUNITY_LIST_ERR_CANT_FIND_LIST:
14245 vty_out(vty, "%% Can't find community-list\n");
14246 break;
14247 case COMMUNITY_LIST_ERR_MALFORMED_VAL:
14248 vty_out(vty, "%% Malformed community-list value\n");
14249 break;
14250 case COMMUNITY_LIST_ERR_STANDARD_CONFLICT:
14251 vty_out(vty,
14252 "%% Community name conflict, previously defined as standard community\n");
14253 break;
14254 case COMMUNITY_LIST_ERR_EXPANDED_CONFLICT:
14255 vty_out(vty,
14256 "%% Community name conflict, previously defined as expanded community\n");
14257 break;
14258 }
14259 }
14260
14261 /* "community-list" keyword help string. */
14262 #define COMMUNITY_LIST_STR "Add a community list entry\n"
14263
14264 /*community-list standard */
14265 DEFUN (community_list_standard,
14266 bgp_community_list_standard_cmd,
14267 "bgp community-list <(1-99)|standard WORD> <deny|permit> AA:NN...",
14268 BGP_STR
14269 COMMUNITY_LIST_STR
14270 "Community list number (standard)\n"
14271 "Add an standard community-list entry\n"
14272 "Community list name\n"
14273 "Specify community to reject\n"
14274 "Specify community to accept\n"
14275 COMMUNITY_VAL_STR)
14276 {
14277 char *cl_name_or_number = NULL;
14278 int direct = 0;
14279 int style = COMMUNITY_LIST_STANDARD;
14280
14281 int idx = 0;
14282
14283 if (argv_find(argv, argc, "ip", &idx)) {
14284 vty_out(vty, "This config option is deprecated, and is scheduled for removal.\n");
14285 vty_out(vty, "if you are using this please migrate to the below command.\n");
14286 vty_out(vty, "'bgp community-list <(1-99)|(100-500)|standard|expanded> <deny|permit> AA:NN'\n");
14287 zlog_warn("Deprecated option: 'ip community-list <(1-99)|(100-500)|standard|expanded> <deny|permit> AA:NN' being used");
14288 }
14289
14290 argv_find(argv, argc, "(1-99)", &idx);
14291 argv_find(argv, argc, "WORD", &idx);
14292 cl_name_or_number = argv[idx]->arg;
14293 direct = argv_find(argv, argc, "permit", &idx) ? COMMUNITY_PERMIT
14294 : COMMUNITY_DENY;
14295 argv_find(argv, argc, "AA:NN", &idx);
14296 char *str = argv_concat(argv, argc, idx);
14297
14298 int ret = community_list_set(bgp_clist, cl_name_or_number, str, direct,
14299 style);
14300
14301 XFREE(MTYPE_TMP, str);
14302
14303 if (ret < 0) {
14304 /* Display error string. */
14305 community_list_perror(vty, ret);
14306 return CMD_WARNING_CONFIG_FAILED;
14307 }
14308
14309 return CMD_SUCCESS;
14310 }
14311
14312 #if CONFDATE > 20191005
14313 CPP_NOTICE("bgpd: remove deprecated 'ip community-list <(1-99)|(100-500)|standard|expanded> <deny|permit> AA:NN' command")
14314 #endif
14315 ALIAS (community_list_standard,
14316 ip_community_list_standard_cmd,
14317 "ip community-list <(1-99)|standard WORD> <deny|permit> AA:NN...",
14318 IP_STR
14319 COMMUNITY_LIST_STR
14320 "Community list number (standard)\n"
14321 "Add an standard community-list entry\n"
14322 "Community list name\n"
14323 "Specify community to reject\n"
14324 "Specify community to accept\n"
14325 COMMUNITY_VAL_STR)
14326
14327 DEFUN (no_community_list_standard_all,
14328 no_bgp_community_list_standard_all_cmd,
14329 "no bgp community-list <(1-99)|standard WORD> <deny|permit> AA:NN...",
14330 NO_STR
14331 BGP_STR
14332 COMMUNITY_LIST_STR
14333 "Community list number (standard)\n"
14334 "Add an standard community-list entry\n"
14335 "Community list name\n"
14336 "Specify community to reject\n"
14337 "Specify community to accept\n"
14338 COMMUNITY_VAL_STR)
14339 {
14340 char *cl_name_or_number = NULL;
14341 char *str = NULL;
14342 int direct = 0;
14343 int style = COMMUNITY_LIST_STANDARD;
14344
14345 int idx = 0;
14346
14347 if (argv_find(argv, argc, "ip", &idx)) {
14348 vty_out(vty, "This config option is deprecated, and is scheduled for removal\n");
14349 vty_out(vty, "if you are using this please migrate to the below command.\n");
14350 vty_out(vty, "'no bgp community-list <(1-99)|(100-500)|standard|expanded> <deny|permit> AA:NN'\n");
14351 zlog_warn("Deprecated option: 'no ip community-list <(1-99)|(100-500)|standard|expanded> <deny|permit> |AA:NN' being used");
14352 }
14353
14354 argv_find(argv, argc, "permit", &idx);
14355 argv_find(argv, argc, "deny", &idx);
14356
14357 if (idx) {
14358 direct = argv_find(argv, argc, "permit", &idx)
14359 ? COMMUNITY_PERMIT
14360 : COMMUNITY_DENY;
14361
14362 idx = 0;
14363 argv_find(argv, argc, "AA:NN", &idx);
14364 str = argv_concat(argv, argc, idx);
14365 }
14366
14367 idx = 0;
14368 argv_find(argv, argc, "(1-99)", &idx);
14369 argv_find(argv, argc, "WORD", &idx);
14370 cl_name_or_number = argv[idx]->arg;
14371
14372 int ret = community_list_unset(bgp_clist, cl_name_or_number, str,
14373 direct, style);
14374
14375 XFREE(MTYPE_TMP, str);
14376
14377 if (ret < 0) {
14378 community_list_perror(vty, ret);
14379 return CMD_WARNING_CONFIG_FAILED;
14380 }
14381
14382 return CMD_SUCCESS;
14383 }
14384 ALIAS (no_community_list_standard_all,
14385 no_ip_community_list_standard_all_cmd,
14386 "no ip community-list <(1-99)|standard WORD> <deny|permit> AA:NN...",
14387 NO_STR
14388 IP_STR
14389 COMMUNITY_LIST_STR
14390 "Community list number (standard)\n"
14391 "Add an standard community-list entry\n"
14392 "Community list name\n"
14393 "Specify community to reject\n"
14394 "Specify community to accept\n"
14395 COMMUNITY_VAL_STR)
14396
14397 ALIAS(no_community_list_standard_all, no_bgp_community_list_standard_all_list_cmd,
14398 "no bgp community-list <(1-99)|standard WORD>",
14399 NO_STR BGP_STR COMMUNITY_LIST_STR
14400 "Community list number (standard)\n"
14401 "Add an standard community-list entry\n"
14402 "Community list name\n")
14403
14404 ALIAS(no_community_list_standard_all, no_ip_community_list_standard_all_list_cmd,
14405 "no ip community-list <(1-99)|standard WORD>",
14406 NO_STR BGP_STR COMMUNITY_LIST_STR
14407 "Community list number (standard)\n"
14408 "Add an standard community-list entry\n"
14409 "Community list name\n")
14410
14411 /*community-list expanded */
14412 DEFUN (community_list_expanded_all,
14413 bgp_community_list_expanded_all_cmd,
14414 "bgp community-list <(100-500)|expanded WORD> <deny|permit> AA:NN...",
14415 BGP_STR
14416 COMMUNITY_LIST_STR
14417 "Community list number (expanded)\n"
14418 "Add an expanded community-list entry\n"
14419 "Community list name\n"
14420 "Specify community to reject\n"
14421 "Specify community to accept\n"
14422 COMMUNITY_VAL_STR)
14423 {
14424 char *cl_name_or_number = NULL;
14425 int direct = 0;
14426 int style = COMMUNITY_LIST_EXPANDED;
14427
14428 int idx = 0;
14429 if (argv_find(argv, argc, "ip", &idx)) {
14430 vty_out(vty, "This config option is deprecated, and is scheduled for removal.\n");
14431 vty_out(vty, "if you are using this please migrate to the below command.\n");
14432 vty_out(vty, "'bgp community-list <(1-99)|(100-500)|standard|expanded> <deny|permit> AA:NN'\n");
14433 zlog_warn("Deprecated option: 'ip community-list <(1-99)|(100-500)|standard|expanded> <deny|permit> AA:NN' being used");
14434 }
14435 argv_find(argv, argc, "(100-500)", &idx);
14436 argv_find(argv, argc, "WORD", &idx);
14437 cl_name_or_number = argv[idx]->arg;
14438 direct = argv_find(argv, argc, "permit", &idx) ? COMMUNITY_PERMIT
14439 : COMMUNITY_DENY;
14440 argv_find(argv, argc, "AA:NN", &idx);
14441 char *str = argv_concat(argv, argc, idx);
14442
14443 int ret = community_list_set(bgp_clist, cl_name_or_number, str, direct,
14444 style);
14445
14446 XFREE(MTYPE_TMP, str);
14447
14448 if (ret < 0) {
14449 /* Display error string. */
14450 community_list_perror(vty, ret);
14451 return CMD_WARNING_CONFIG_FAILED;
14452 }
14453
14454 return CMD_SUCCESS;
14455 }
14456
14457 ALIAS (community_list_expanded_all,
14458 ip_community_list_expanded_all_cmd,
14459 "ip community-list <(100-500)|expanded WORD> <deny|permit> AA:NN...",
14460 IP_STR
14461 COMMUNITY_LIST_STR
14462 "Community list number (expanded)\n"
14463 "Add an expanded community-list entry\n"
14464 "Community list name\n"
14465 "Specify community to reject\n"
14466 "Specify community to accept\n"
14467 COMMUNITY_VAL_STR)
14468
14469 DEFUN (no_community_list_expanded_all,
14470 no_bgp_community_list_expanded_all_cmd,
14471 "no bgp community-list <(100-500)|expanded WORD> <deny|permit> AA:NN...",
14472 NO_STR
14473 BGP_STR
14474 COMMUNITY_LIST_STR
14475 "Community list number (expanded)\n"
14476 "Add an expanded community-list entry\n"
14477 "Community list name\n"
14478 "Specify community to reject\n"
14479 "Specify community to accept\n"
14480 COMMUNITY_VAL_STR)
14481 {
14482 char *cl_name_or_number = NULL;
14483 char *str = NULL;
14484 int direct = 0;
14485 int style = COMMUNITY_LIST_EXPANDED;
14486
14487 int idx = 0;
14488 if (argv_find(argv, argc, "ip", &idx)) {
14489 vty_out(vty, "This config option is deprecated, and is scheduled for removal.\n");
14490 vty_out(vty, "if you are using this please migrate to the below command.\n");
14491 vty_out(vty, "'no bgp community-list <(1-99)|(100-500)|standard|expanded> <deny|permit> AA:NN'\n");
14492 zlog_warn("Deprecated option: 'no ip community-list <(1-99)|(100-500)|standard|expanded> <deny|permit> AA:NN' being used");
14493 }
14494
14495 idx = 0;
14496 argv_find(argv, argc, "permit", &idx);
14497 argv_find(argv, argc, "deny", &idx);
14498
14499 if (idx) {
14500 direct = argv_find(argv, argc, "permit", &idx)
14501 ? COMMUNITY_PERMIT
14502 : COMMUNITY_DENY;
14503
14504 idx = 0;
14505 argv_find(argv, argc, "AA:NN", &idx);
14506 str = argv_concat(argv, argc, idx);
14507 }
14508
14509 idx = 0;
14510 argv_find(argv, argc, "(100-500)", &idx);
14511 argv_find(argv, argc, "WORD", &idx);
14512 cl_name_or_number = argv[idx]->arg;
14513
14514 int ret = community_list_unset(bgp_clist, cl_name_or_number, str,
14515 direct, style);
14516
14517 XFREE(MTYPE_TMP, str);
14518
14519 if (ret < 0) {
14520 community_list_perror(vty, ret);
14521 return CMD_WARNING_CONFIG_FAILED;
14522 }
14523
14524 return CMD_SUCCESS;
14525 }
14526
14527 ALIAS (no_community_list_expanded_all,
14528 no_ip_community_list_expanded_all_cmd,
14529 "no ip community-list <(100-500)|expanded WORD> <deny|permit> AA:NN...",
14530 NO_STR
14531 IP_STR
14532 COMMUNITY_LIST_STR
14533 "Community list number (expanded)\n"
14534 "Add an expanded community-list entry\n"
14535 "Community list name\n"
14536 "Specify community to reject\n"
14537 "Specify community to accept\n"
14538 COMMUNITY_VAL_STR)
14539
14540 ALIAS(no_community_list_expanded_all, no_bgp_community_list_expanded_all_list_cmd,
14541 "no bgp community-list <(100-500)|expanded WORD>",
14542 NO_STR IP_STR COMMUNITY_LIST_STR
14543 "Community list number (expanded)\n"
14544 "Add an expanded community-list entry\n"
14545 "Community list name\n")
14546
14547 ALIAS(no_community_list_expanded_all, no_ip_community_list_expanded_all_list_cmd,
14548 "no ip community-list <(100-500)|expanded WORD>",
14549 NO_STR IP_STR COMMUNITY_LIST_STR
14550 "Community list number (expanded)\n"
14551 "Add an expanded community-list entry\n"
14552 "Community list name\n")
14553
14554 /* Return configuration string of community-list entry. */
14555 static const char *community_list_config_str(struct community_entry *entry)
14556 {
14557 const char *str;
14558
14559 if (entry->any)
14560 str = "";
14561 else {
14562 if (entry->style == COMMUNITY_LIST_STANDARD)
14563 str = community_str(entry->u.com, false);
14564 else if (entry->style == LARGE_COMMUNITY_LIST_STANDARD)
14565 str = lcommunity_str(entry->u.lcom, false);
14566 else
14567 str = entry->config;
14568 }
14569 return str;
14570 }
14571
14572 static void community_list_show(struct vty *vty, struct community_list *list)
14573 {
14574 struct community_entry *entry;
14575
14576 for (entry = list->head; entry; entry = entry->next) {
14577 if (entry == list->head) {
14578 if (all_digit(list->name))
14579 vty_out(vty, "Community %s list %s\n",
14580 entry->style == COMMUNITY_LIST_STANDARD
14581 ? "standard"
14582 : "(expanded) access",
14583 list->name);
14584 else
14585 vty_out(vty, "Named Community %s list %s\n",
14586 entry->style == COMMUNITY_LIST_STANDARD
14587 ? "standard"
14588 : "expanded",
14589 list->name);
14590 }
14591 if (entry->any)
14592 vty_out(vty, " %s\n",
14593 community_direct_str(entry->direct));
14594 else
14595 vty_out(vty, " %s %s\n",
14596 community_direct_str(entry->direct),
14597 community_list_config_str(entry));
14598 }
14599 }
14600
14601 DEFUN (show_community_list,
14602 show_bgp_community_list_cmd,
14603 "show bgp community-list",
14604 SHOW_STR
14605 BGP_STR
14606 "List community-list\n")
14607 {
14608 struct community_list *list;
14609 struct community_list_master *cm;
14610
14611 int idx = 0;
14612 if (argv_find(argv, argc, "ip", &idx)) {
14613 vty_out(vty, "This config option is deprecated, and is scheduled for removal.\n");
14614 vty_out(vty, "if you are using this please migrate to the below command.\n");
14615 vty_out(vty, "'show bgp community-list <(1-500)|WORD>'\n");
14616 zlog_warn("Deprecated option: 'ip show community-list <(1-500)|WORD>' being used");
14617 }
14618 cm = community_list_master_lookup(bgp_clist, COMMUNITY_LIST_MASTER);
14619 if (!cm)
14620 return CMD_SUCCESS;
14621
14622 for (list = cm->num.head; list; list = list->next)
14623 community_list_show(vty, list);
14624
14625 for (list = cm->str.head; list; list = list->next)
14626 community_list_show(vty, list);
14627
14628 return CMD_SUCCESS;
14629 }
14630
14631 ALIAS (show_community_list,
14632 show_ip_community_list_cmd,
14633 "show ip community-list",
14634 SHOW_STR
14635 IP_STR
14636 "List community-list\n")
14637
14638 DEFUN (show_community_list_arg,
14639 show_bgp_community_list_arg_cmd,
14640 "show bgp community-list <(1-500)|WORD> detail",
14641 SHOW_STR
14642 BGP_STR
14643 "List community-list\n"
14644 "Community-list number\n"
14645 "Community-list name\n"
14646 "Detailed information on community-list\n")
14647 {
14648 int idx_comm_list = 3;
14649 struct community_list *list;
14650
14651 int idx = 0;
14652 if (argv_find(argv, argc, "ip", &idx)) {
14653 vty_out(vty, "This config option is deprecated, and is scheduled for removal.\n");
14654 vty_out(vty, "if you are using this please migrate to the below command.\n");
14655 vty_out(vty, "'show bgp community-list <(1-500)|WORD> detail'\n");
14656 zlog_warn("Deprecated option: 'show ip community-list <(1-500)|WORD>' being used");
14657 }
14658 list = community_list_lookup(bgp_clist, argv[idx_comm_list]->arg, 0,
14659 COMMUNITY_LIST_MASTER);
14660 if (!list) {
14661 vty_out(vty, "%% Can't find community-list\n");
14662 return CMD_WARNING;
14663 }
14664
14665 community_list_show(vty, list);
14666
14667 return CMD_SUCCESS;
14668 }
14669
14670 ALIAS (show_community_list_arg,
14671 show_ip_community_list_arg_cmd,
14672 "show ip community-list <(1-500)|WORD>",
14673 SHOW_STR
14674 IP_STR
14675 "List community-list\n"
14676 "Community-list number\n"
14677 "Community-list name\n")
14678
14679 /*
14680 * Large Community code.
14681 */
14682 static int lcommunity_list_set_vty(struct vty *vty, int argc,
14683 struct cmd_token **argv, int style,
14684 int reject_all_digit_name)
14685 {
14686 int ret;
14687 int direct;
14688 char *str;
14689 int idx = 0;
14690 char *cl_name;
14691
14692 if (argv_find(argv, argc, "ip", &idx)) {
14693 vty_out(vty, "This config option is deprecated, and is scheduled for removal.\n");
14694 vty_out(vty, "if you are using this please migrate to the below command.\n");
14695 vty_out(vty, "'bgp large-community-list <(1-99)|(100-500)|standard|expanded> <deny|permit> <LINE|AA:BB:CC>'\n");
14696 zlog_warn("Deprecated option: 'large-community-list <(1-99)|(100-500)|standard|expanded> <deny|permit> <LINE|AA:BB:CC>' being used");
14697 }
14698 direct = argv_find(argv, argc, "permit", &idx) ? COMMUNITY_PERMIT
14699 : COMMUNITY_DENY;
14700
14701 /* All digit name check. */
14702 idx = 0;
14703 argv_find(argv, argc, "WORD", &idx);
14704 argv_find(argv, argc, "(1-99)", &idx);
14705 argv_find(argv, argc, "(100-500)", &idx);
14706 cl_name = argv[idx]->arg;
14707 if (reject_all_digit_name && all_digit(cl_name)) {
14708 vty_out(vty, "%% Community name cannot have all digits\n");
14709 return CMD_WARNING_CONFIG_FAILED;
14710 }
14711
14712 idx = 0;
14713 argv_find(argv, argc, "AA:BB:CC", &idx);
14714 argv_find(argv, argc, "LINE", &idx);
14715 /* Concat community string argument. */
14716 if (idx)
14717 str = argv_concat(argv, argc, idx);
14718 else
14719 str = NULL;
14720
14721 ret = lcommunity_list_set(bgp_clist, cl_name, str, direct, style);
14722
14723 /* Free temporary community list string allocated by
14724 argv_concat(). */
14725 XFREE(MTYPE_TMP, str);
14726
14727 if (ret < 0) {
14728 community_list_perror(vty, ret);
14729 return CMD_WARNING_CONFIG_FAILED;
14730 }
14731 return CMD_SUCCESS;
14732 }
14733
14734 static int lcommunity_list_unset_vty(struct vty *vty, int argc,
14735 struct cmd_token **argv, int style)
14736 {
14737 int ret;
14738 int direct = 0;
14739 char *str = NULL;
14740 int idx = 0;
14741
14742 if (argv_find(argv, argc, "ip", &idx)) {
14743 vty_out(vty, "This config option is deprecated, and is scheduled for removal.\n");
14744 vty_out(vty, "if you are using this please migrate to the below command.\n");
14745 vty_out(vty, "'no bgp large-community-list <(1-99)|(100-500)|standard|expanded> <deny|permit> <LINE|AA:BB:CC>'\n");
14746 zlog_warn("Deprecated option: 'no ip large-community-list <(1-99)|(100-500)|standard|expanded> <deny|permit> <LINE|AA:BB:CC>' being used");
14747 }
14748 argv_find(argv, argc, "permit", &idx);
14749 argv_find(argv, argc, "deny", &idx);
14750
14751 if (idx) {
14752 /* Check the list direct. */
14753 if (strncmp(argv[idx]->arg, "p", 1) == 0)
14754 direct = COMMUNITY_PERMIT;
14755 else
14756 direct = COMMUNITY_DENY;
14757
14758 idx = 0;
14759 argv_find(argv, argc, "LINE", &idx);
14760 argv_find(argv, argc, "AA:AA:NN", &idx);
14761 /* Concat community string argument. */
14762 str = argv_concat(argv, argc, idx);
14763 }
14764
14765 idx = 0;
14766 argv_find(argv, argc, "(1-99)", &idx);
14767 argv_find(argv, argc, "(100-500)", &idx);
14768 argv_find(argv, argc, "WORD", &idx);
14769
14770 /* Unset community list. */
14771 ret = lcommunity_list_unset(bgp_clist, argv[idx]->arg, str, direct,
14772 style);
14773
14774 /* Free temporary community list string allocated by
14775 argv_concat(). */
14776 XFREE(MTYPE_TMP, str);
14777
14778 if (ret < 0) {
14779 community_list_perror(vty, ret);
14780 return CMD_WARNING_CONFIG_FAILED;
14781 }
14782
14783 return CMD_SUCCESS;
14784 }
14785
14786 /* "large-community-list" keyword help string. */
14787 #define LCOMMUNITY_LIST_STR "Add a large community list entry\n"
14788 #define LCOMMUNITY_VAL_STR "large community in 'aa:bb:cc' format\n"
14789
14790 #if CONFDATE > 20191005
14791 CPP_NOTICE("bgpd: remove deprecated 'ip large-community-list <(1-99)|(100-500)|standard|expanded> <deny|permit> <LINE|AA:BB:CC>' command")
14792 #endif
14793 DEFUN (lcommunity_list_standard,
14794 bgp_lcommunity_list_standard_cmd,
14795 "bgp large-community-list (1-99) <deny|permit> AA:BB:CC...",
14796 BGP_STR
14797 LCOMMUNITY_LIST_STR
14798 "Large Community list number (standard)\n"
14799 "Specify large community to reject\n"
14800 "Specify large community to accept\n"
14801 LCOMMUNITY_VAL_STR)
14802 {
14803 return lcommunity_list_set_vty(vty, argc, argv,
14804 LARGE_COMMUNITY_LIST_STANDARD, 0);
14805 }
14806
14807 ALIAS (lcommunity_list_standard,
14808 ip_lcommunity_list_standard_cmd,
14809 "ip large-community-list (1-99) <deny|permit> AA:BB:CC...",
14810 IP_STR
14811 LCOMMUNITY_LIST_STR
14812 "Large Community list number (standard)\n"
14813 "Specify large community to reject\n"
14814 "Specify large community to accept\n"
14815 LCOMMUNITY_VAL_STR)
14816
14817 DEFUN (lcommunity_list_expanded,
14818 bgp_lcommunity_list_expanded_cmd,
14819 "bgp large-community-list (100-500) <deny|permit> LINE...",
14820 BGP_STR
14821 LCOMMUNITY_LIST_STR
14822 "Large Community list number (expanded)\n"
14823 "Specify large community to reject\n"
14824 "Specify large community to accept\n"
14825 "An ordered list as a regular-expression\n")
14826 {
14827 return lcommunity_list_set_vty(vty, argc, argv,
14828 LARGE_COMMUNITY_LIST_EXPANDED, 0);
14829 }
14830
14831 ALIAS (lcommunity_list_expanded,
14832 ip_lcommunity_list_expanded_cmd,
14833 "ip large-community-list (100-500) <deny|permit> LINE...",
14834 IP_STR
14835 LCOMMUNITY_LIST_STR
14836 "Large Community list number (expanded)\n"
14837 "Specify large community to reject\n"
14838 "Specify large community to accept\n"
14839 "An ordered list as a regular-expression\n")
14840
14841 DEFUN (lcommunity_list_name_standard,
14842 bgp_lcommunity_list_name_standard_cmd,
14843 "bgp large-community-list standard WORD <deny|permit> AA:BB:CC...",
14844 BGP_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 return lcommunity_list_set_vty(vty, argc, argv,
14853 LARGE_COMMUNITY_LIST_STANDARD, 1);
14854 }
14855
14856 ALIAS (lcommunity_list_name_standard,
14857 ip_lcommunity_list_name_standard_cmd,
14858 "ip large-community-list standard WORD <deny|permit> AA:BB:CC...",
14859 IP_STR
14860 LCOMMUNITY_LIST_STR
14861 "Specify standard large-community-list\n"
14862 "Large Community list name\n"
14863 "Specify large community to reject\n"
14864 "Specify large community to accept\n"
14865 LCOMMUNITY_VAL_STR)
14866
14867 DEFUN (lcommunity_list_name_expanded,
14868 bgp_lcommunity_list_name_expanded_cmd,
14869 "bgp large-community-list expanded WORD <deny|permit> LINE...",
14870 BGP_STR
14871 LCOMMUNITY_LIST_STR
14872 "Specify expanded large-community-list\n"
14873 "Large Community list name\n"
14874 "Specify large community to reject\n"
14875 "Specify large community to accept\n"
14876 "An ordered list as a regular-expression\n")
14877 {
14878 return lcommunity_list_set_vty(vty, argc, argv,
14879 LARGE_COMMUNITY_LIST_EXPANDED, 1);
14880 }
14881
14882 ALIAS (lcommunity_list_name_expanded,
14883 ip_lcommunity_list_name_expanded_cmd,
14884 "ip large-community-list expanded WORD <deny|permit> LINE...",
14885 IP_STR
14886 LCOMMUNITY_LIST_STR
14887 "Specify expanded large-community-list\n"
14888 "Large Community list name\n"
14889 "Specify large community to reject\n"
14890 "Specify large community to accept\n"
14891 "An ordered list as a regular-expression\n")
14892
14893 DEFUN (no_lcommunity_list_standard_all,
14894 no_bgp_lcommunity_list_standard_all_cmd,
14895 "no bgp large-community-list <(1-99)|(100-500)|WORD>",
14896 NO_STR
14897 BGP_STR
14898 LCOMMUNITY_LIST_STR
14899 "Large Community list number (standard)\n"
14900 "Large Community list number (expanded)\n"
14901 "Large Community list name\n")
14902 {
14903 return lcommunity_list_unset_vty(vty, argc, argv,
14904 LARGE_COMMUNITY_LIST_STANDARD);
14905 }
14906
14907 ALIAS (no_lcommunity_list_standard_all,
14908 no_ip_lcommunity_list_standard_all_cmd,
14909 "no ip large-community-list <(1-99)|(100-500)|WORD>",
14910 NO_STR
14911 IP_STR
14912 LCOMMUNITY_LIST_STR
14913 "Large Community list number (standard)\n"
14914 "Large Community list number (expanded)\n"
14915 "Large Community list name\n")
14916
14917 DEFUN (no_lcommunity_list_name_expanded_all,
14918 no_bgp_lcommunity_list_name_expanded_all_cmd,
14919 "no bgp large-community-list expanded WORD",
14920 NO_STR
14921 BGP_STR
14922 LCOMMUNITY_LIST_STR
14923 "Specify expanded large-community-list\n"
14924 "Large Community list name\n")
14925 {
14926 return lcommunity_list_unset_vty(vty, argc, argv,
14927 LARGE_COMMUNITY_LIST_EXPANDED);
14928 }
14929
14930 ALIAS (no_lcommunity_list_name_expanded_all,
14931 no_ip_lcommunity_list_name_expanded_all_cmd,
14932 "no ip large-community-list expanded WORD",
14933 NO_STR
14934 IP_STR
14935 LCOMMUNITY_LIST_STR
14936 "Specify expanded large-community-list\n"
14937 "Large Community list name\n")
14938
14939 DEFUN (no_lcommunity_list_standard,
14940 no_bgp_lcommunity_list_standard_cmd,
14941 "no bgp large-community-list (1-99) <deny|permit> AA:AA:NN...",
14942 NO_STR
14943 BGP_STR
14944 LCOMMUNITY_LIST_STR
14945 "Large Community list number (standard)\n"
14946 "Specify large community to reject\n"
14947 "Specify large community to accept\n"
14948 LCOMMUNITY_VAL_STR)
14949 {
14950 return lcommunity_list_unset_vty(vty, argc, argv,
14951 LARGE_COMMUNITY_LIST_STANDARD);
14952 }
14953
14954 ALIAS (no_lcommunity_list_standard,
14955 no_ip_lcommunity_list_standard_cmd,
14956 "no ip large-community-list (1-99) <deny|permit> AA:AA:NN...",
14957 NO_STR
14958 IP_STR
14959 LCOMMUNITY_LIST_STR
14960 "Large Community list number (standard)\n"
14961 "Specify large community to reject\n"
14962 "Specify large community to accept\n"
14963 LCOMMUNITY_VAL_STR)
14964
14965 DEFUN (no_lcommunity_list_expanded,
14966 no_bgp_lcommunity_list_expanded_cmd,
14967 "no bgp large-community-list (100-500) <deny|permit> LINE...",
14968 NO_STR
14969 BGP_STR
14970 LCOMMUNITY_LIST_STR
14971 "Large Community list number (expanded)\n"
14972 "Specify large community to reject\n"
14973 "Specify large community to accept\n"
14974 "An ordered list as a regular-expression\n")
14975 {
14976 return lcommunity_list_unset_vty(vty, argc, argv,
14977 LARGE_COMMUNITY_LIST_EXPANDED);
14978 }
14979
14980 ALIAS (no_lcommunity_list_expanded,
14981 no_ip_lcommunity_list_expanded_cmd,
14982 "no ip large-community-list (100-500) <deny|permit> LINE...",
14983 NO_STR
14984 IP_STR
14985 LCOMMUNITY_LIST_STR
14986 "Large Community list number (expanded)\n"
14987 "Specify large community to reject\n"
14988 "Specify large community to accept\n"
14989 "An ordered list as a regular-expression\n")
14990
14991 DEFUN (no_lcommunity_list_name_standard,
14992 no_bgp_lcommunity_list_name_standard_cmd,
14993 "no bgp large-community-list standard WORD <deny|permit> AA:AA:NN...",
14994 NO_STR
14995 BGP_STR
14996 LCOMMUNITY_LIST_STR
14997 "Specify standard large-community-list\n"
14998 "Large Community list name\n"
14999 "Specify large community to reject\n"
15000 "Specify large community to accept\n"
15001 LCOMMUNITY_VAL_STR)
15002 {
15003 return lcommunity_list_unset_vty(vty, argc, argv,
15004 LARGE_COMMUNITY_LIST_STANDARD);
15005 }
15006
15007 ALIAS (no_lcommunity_list_name_standard,
15008 no_ip_lcommunity_list_name_standard_cmd,
15009 "no ip large-community-list standard WORD <deny|permit> AA:AA:NN...",
15010 NO_STR
15011 IP_STR
15012 LCOMMUNITY_LIST_STR
15013 "Specify standard large-community-list\n"
15014 "Large Community list name\n"
15015 "Specify large community to reject\n"
15016 "Specify large community to accept\n"
15017 LCOMMUNITY_VAL_STR)
15018
15019 DEFUN (no_lcommunity_list_name_expanded,
15020 no_bgp_lcommunity_list_name_expanded_cmd,
15021 "no bgp large-community-list expanded WORD <deny|permit> LINE...",
15022 NO_STR
15023 BGP_STR
15024 LCOMMUNITY_LIST_STR
15025 "Specify expanded large-community-list\n"
15026 "Large community list name\n"
15027 "Specify large community to reject\n"
15028 "Specify large community to accept\n"
15029 "An ordered list as a regular-expression\n")
15030 {
15031 return lcommunity_list_unset_vty(vty, argc, argv,
15032 LARGE_COMMUNITY_LIST_EXPANDED);
15033 }
15034
15035 ALIAS (no_lcommunity_list_name_expanded,
15036 no_ip_lcommunity_list_name_expanded_cmd,
15037 "no ip large-community-list expanded WORD <deny|permit> LINE...",
15038 NO_STR
15039 IP_STR
15040 LCOMMUNITY_LIST_STR
15041 "Specify expanded large-community-list\n"
15042 "Large community list name\n"
15043 "Specify large community to reject\n"
15044 "Specify large community to accept\n"
15045 "An ordered list as a regular-expression\n")
15046
15047 static void lcommunity_list_show(struct vty *vty, struct community_list *list)
15048 {
15049 struct community_entry *entry;
15050
15051 for (entry = list->head; entry; entry = entry->next) {
15052 if (entry == list->head) {
15053 if (all_digit(list->name))
15054 vty_out(vty, "Large community %s list %s\n",
15055 entry->style ==
15056 LARGE_COMMUNITY_LIST_STANDARD
15057 ? "standard"
15058 : "(expanded) access",
15059 list->name);
15060 else
15061 vty_out(vty,
15062 "Named large community %s list %s\n",
15063 entry->style ==
15064 LARGE_COMMUNITY_LIST_STANDARD
15065 ? "standard"
15066 : "expanded",
15067 list->name);
15068 }
15069 if (entry->any)
15070 vty_out(vty, " %s\n",
15071 community_direct_str(entry->direct));
15072 else
15073 vty_out(vty, " %s %s\n",
15074 community_direct_str(entry->direct),
15075 community_list_config_str(entry));
15076 }
15077 }
15078
15079 DEFUN (show_lcommunity_list,
15080 show_bgp_lcommunity_list_cmd,
15081 "show bgp large-community-list",
15082 SHOW_STR
15083 BGP_STR
15084 "List large-community list\n")
15085 {
15086 struct community_list *list;
15087 struct community_list_master *cm;
15088 int idx = 0;
15089
15090 if (argv_find(argv, argc, "ip", &idx)) {
15091 vty_out(vty, "This config option is deprecated, and is scheduled for removal.\n");
15092 vty_out(vty, "if you are using this please migrate to the below command.\n");
15093 vty_out(vty, "'show bgp large-community-list <(1-500)|WORD>'\n");
15094 zlog_warn("Deprecated option: 'ip show large-community-list <(1-500)|WORD>' being used");
15095 }
15096
15097 cm = community_list_master_lookup(bgp_clist,
15098 LARGE_COMMUNITY_LIST_MASTER);
15099 if (!cm)
15100 return CMD_SUCCESS;
15101
15102 for (list = cm->num.head; list; list = list->next)
15103 lcommunity_list_show(vty, list);
15104
15105 for (list = cm->str.head; list; list = list->next)
15106 lcommunity_list_show(vty, list);
15107
15108 return CMD_SUCCESS;
15109 }
15110
15111 ALIAS (show_lcommunity_list,
15112 show_ip_lcommunity_list_cmd,
15113 "show ip large-community-list",
15114 SHOW_STR
15115 IP_STR
15116 "List large-community list\n")
15117
15118 DEFUN (show_lcommunity_list_arg,
15119 show_bgp_lcommunity_list_arg_cmd,
15120 "show bgp large-community-list <(1-500)|WORD> detail",
15121 SHOW_STR
15122 BGP_STR
15123 "List large-community list\n"
15124 "Large-community-list number\n"
15125 "Large-community-list name\n"
15126 "Detailed information on large-community-list\n")
15127 {
15128 struct community_list *list;
15129 int idx = 0;
15130
15131 if (argv_find(argv, argc, "ip", &idx)) {
15132 vty_out(vty, "This config option is deprecated, and is scheduled for removal.\n");
15133 vty_out(vty, "if you are using this please migrate to the below command.\n");
15134 vty_out(vty, "'show bgp large-community-list <(1-500)|WORD> detail'\n");
15135 zlog_warn("Deprecated option: 'show ip large-community-list <(1-500)|WORD>' being used");
15136 }
15137
15138 list = community_list_lookup(bgp_clist, argv[3]->arg, 0,
15139 LARGE_COMMUNITY_LIST_MASTER);
15140 if (!list) {
15141 vty_out(vty, "%% Can't find large-community-list\n");
15142 return CMD_WARNING;
15143 }
15144
15145 lcommunity_list_show(vty, list);
15146
15147 return CMD_SUCCESS;
15148 }
15149
15150 ALIAS (show_lcommunity_list_arg,
15151 show_ip_lcommunity_list_arg_cmd,
15152 "show ip large-community-list <(1-500)|WORD>",
15153 SHOW_STR
15154 IP_STR
15155 "List large-community list\n"
15156 "large-community-list number\n"
15157 "large-community-list name\n")
15158
15159 /* "extcommunity-list" keyword help string. */
15160 #define EXTCOMMUNITY_LIST_STR "Add a extended community list entry\n"
15161 #define EXTCOMMUNITY_VAL_STR "Extended community attribute in 'rt aa:nn_or_IPaddr:nn' OR 'soo aa:nn_or_IPaddr:nn' format\n"
15162
15163 DEFUN (extcommunity_list_standard,
15164 bgp_extcommunity_list_standard_cmd,
15165 "bgp extcommunity-list <(1-99)|standard WORD> <deny|permit> AA:NN...",
15166 BGP_STR
15167 EXTCOMMUNITY_LIST_STR
15168 "Extended Community list number (standard)\n"
15169 "Specify standard extcommunity-list\n"
15170 "Community list name\n"
15171 "Specify community to reject\n"
15172 "Specify community to accept\n"
15173 EXTCOMMUNITY_VAL_STR)
15174 {
15175 int style = EXTCOMMUNITY_LIST_STANDARD;
15176 int direct = 0;
15177 char *cl_number_or_name = NULL;
15178
15179 int idx = 0;
15180 if (argv_find(argv, argc, "ip", &idx)) {
15181 vty_out(vty, "This config option is deprecated, and is scheduled for removal.\n");
15182 vty_out(vty, "if you are using this please migrate to the below command.\n");
15183 vty_out(vty, "'bgp extcommunity-list <(1-99)|(100-500)|standard|expanded> <deny|permit> <LINE|AA:NN>'\n");
15184 zlog_warn("Deprecated option: 'ip extcommunity-list <(1-99)|(100-500)|standard|expanded> <deny|permit> <LINE|AA:NN>' being used");
15185 }
15186 argv_find(argv, argc, "(1-99)", &idx);
15187 argv_find(argv, argc, "WORD", &idx);
15188 cl_number_or_name = argv[idx]->arg;
15189 direct = argv_find(argv, argc, "permit", &idx) ? COMMUNITY_PERMIT
15190 : COMMUNITY_DENY;
15191 argv_find(argv, argc, "AA:NN", &idx);
15192 char *str = argv_concat(argv, argc, idx);
15193
15194 int ret = extcommunity_list_set(bgp_clist, cl_number_or_name, str,
15195 direct, style);
15196
15197 XFREE(MTYPE_TMP, str);
15198
15199 if (ret < 0) {
15200 community_list_perror(vty, ret);
15201 return CMD_WARNING_CONFIG_FAILED;
15202 }
15203
15204 return CMD_SUCCESS;
15205 }
15206
15207 #if CONFDATE > 20191005
15208 CPP_NOTICE("bgpd: remove deprecated 'ip extcommunity-list <(1-99)|(100-500)|standard|expanded> <deny|permit> <LINE|AA:NN>' command")
15209 #endif
15210 ALIAS (extcommunity_list_standard,
15211 ip_extcommunity_list_standard_cmd,
15212 "ip extcommunity-list <(1-99)|standard WORD> <deny|permit> AA:NN...",
15213 IP_STR
15214 EXTCOMMUNITY_LIST_STR
15215 "Extended Community list number (standard)\n"
15216 "Specify standard extcommunity-list\n"
15217 "Community list name\n"
15218 "Specify community to reject\n"
15219 "Specify community to accept\n"
15220 EXTCOMMUNITY_VAL_STR)
15221
15222 DEFUN (extcommunity_list_name_expanded,
15223 bgp_extcommunity_list_name_expanded_cmd,
15224 "bgp extcommunity-list <(100-500)|expanded WORD> <deny|permit> LINE...",
15225 BGP_STR
15226 EXTCOMMUNITY_LIST_STR
15227 "Extended Community list number (expanded)\n"
15228 "Specify expanded extcommunity-list\n"
15229 "Extended Community list name\n"
15230 "Specify community to reject\n"
15231 "Specify community to accept\n"
15232 "An ordered list as a regular-expression\n")
15233 {
15234 int style = EXTCOMMUNITY_LIST_EXPANDED;
15235 int direct = 0;
15236 char *cl_number_or_name = NULL;
15237
15238 int idx = 0;
15239 if (argv_find(argv, argc, "ip", &idx)) {
15240 vty_out(vty, "This config option is deprecated, and is scheduled for removal.\n");
15241 vty_out(vty, "if you are using this please migrate to the below command.\n");
15242 vty_out(vty, "'extcommunity-list <(1-99)|(100-500)|standard|expanded> <deny|permit> <LINE|AA:NN>'\n");
15243 zlog_warn("Deprecated option: ‘ip extcommunity-list <(1-99)|(100-500)|standard|expanded> <deny|permit> <LINE|AA:NN>' being used");
15244 }
15245
15246 argv_find(argv, argc, "(100-500)", &idx);
15247 argv_find(argv, argc, "WORD", &idx);
15248 cl_number_or_name = argv[idx]->arg;
15249 direct = argv_find(argv, argc, "permit", &idx) ? COMMUNITY_PERMIT
15250 : COMMUNITY_DENY;
15251 argv_find(argv, argc, "LINE", &idx);
15252 char *str = argv_concat(argv, argc, idx);
15253
15254 int ret = extcommunity_list_set(bgp_clist, cl_number_or_name, str,
15255 direct, style);
15256
15257 XFREE(MTYPE_TMP, str);
15258
15259 if (ret < 0) {
15260 community_list_perror(vty, ret);
15261 return CMD_WARNING_CONFIG_FAILED;
15262 }
15263
15264 return CMD_SUCCESS;
15265 }
15266
15267 ALIAS (extcommunity_list_name_expanded,
15268 ip_extcommunity_list_name_expanded_cmd,
15269 "ip extcommunity-list <(100-500)|expanded WORD> <deny|permit> LINE...",
15270 IP_STR
15271 EXTCOMMUNITY_LIST_STR
15272 "Extended Community list number (expanded)\n"
15273 "Specify expanded extcommunity-list\n"
15274 "Extended Community list name\n"
15275 "Specify community to reject\n"
15276 "Specify community to accept\n"
15277 "An ordered list as a regular-expression\n")
15278
15279 DEFUN (no_extcommunity_list_standard_all,
15280 no_bgp_extcommunity_list_standard_all_cmd,
15281 "no bgp extcommunity-list <(1-99)|standard WORD> <deny|permit> AA:NN...",
15282 NO_STR
15283 BGP_STR
15284 EXTCOMMUNITY_LIST_STR
15285 "Extended Community list number (standard)\n"
15286 "Specify standard extcommunity-list\n"
15287 "Community list name\n"
15288 "Specify community to reject\n"
15289 "Specify community to accept\n"
15290 EXTCOMMUNITY_VAL_STR)
15291 {
15292 int style = EXTCOMMUNITY_LIST_STANDARD;
15293 int direct = 0;
15294 char *cl_number_or_name = NULL;
15295 char *str = NULL;
15296
15297 int idx = 0;
15298 if (argv_find(argv, argc, "ip", &idx)) {
15299 vty_out(vty, "This config option is deprecated, and is scheduled for removal\n");
15300 vty_out(vty, "if you are using this please migrate to the below command.\n");
15301 vty_out(vty, "'no bgp extcommunity-list <(1-99)|(100-500)|standard|expanded> <deny|permit> <LINE|AA:NN>'\n");
15302 zlog_warn("Deprecated option: ‘no ip extcommunity-list <(1-99)|(100-500)|standard|expanded> <deny|permit> <LINE|AA:NN>' being used");
15303 }
15304
15305 idx = 0;
15306 argv_find(argv, argc, "permit", &idx);
15307 argv_find(argv, argc, "deny", &idx);
15308
15309 if (idx) {
15310 direct = argv_find(argv, argc, "permit", &idx)
15311 ? COMMUNITY_PERMIT
15312 : COMMUNITY_DENY;
15313
15314 idx = 0;
15315 argv_find(argv, argc, "AA:NN", &idx);
15316 str = argv_concat(argv, argc, idx);
15317 }
15318
15319 idx = 0;
15320 argv_find(argv, argc, "(1-99)", &idx);
15321 argv_find(argv, argc, "WORD", &idx);
15322 cl_number_or_name = argv[idx]->arg;
15323
15324 int ret = extcommunity_list_unset(bgp_clist, cl_number_or_name, str,
15325 direct, style);
15326
15327 XFREE(MTYPE_TMP, str);
15328
15329 if (ret < 0) {
15330 community_list_perror(vty, ret);
15331 return CMD_WARNING_CONFIG_FAILED;
15332 }
15333
15334 return CMD_SUCCESS;
15335 }
15336
15337 ALIAS (no_extcommunity_list_standard_all,
15338 no_ip_extcommunity_list_standard_all_cmd,
15339 "no ip extcommunity-list <(1-99)|standard WORD> <deny|permit> AA:NN...",
15340 NO_STR
15341 IP_STR
15342 EXTCOMMUNITY_LIST_STR
15343 "Extended Community list number (standard)\n"
15344 "Specify standard extcommunity-list\n"
15345 "Community list name\n"
15346 "Specify community to reject\n"
15347 "Specify community to accept\n"
15348 EXTCOMMUNITY_VAL_STR)
15349
15350 ALIAS(no_extcommunity_list_standard_all,
15351 no_bgp_extcommunity_list_standard_all_list_cmd,
15352 "no bgp extcommunity-list <(1-99)|standard WORD>",
15353 NO_STR IP_STR EXTCOMMUNITY_LIST_STR
15354 "Extended Community list number (standard)\n"
15355 "Specify standard extcommunity-list\n"
15356 "Community list name\n")
15357
15358 ALIAS(no_extcommunity_list_standard_all,
15359 no_ip_extcommunity_list_standard_all_list_cmd,
15360 "no ip extcommunity-list <(1-99)|standard WORD>",
15361 NO_STR IP_STR EXTCOMMUNITY_LIST_STR
15362 "Extended Community list number (standard)\n"
15363 "Specify standard extcommunity-list\n"
15364 "Community list name\n")
15365
15366 DEFUN (no_extcommunity_list_expanded_all,
15367 no_bgp_extcommunity_list_expanded_all_cmd,
15368 "no bgp extcommunity-list <(100-500)|expanded WORD> <deny|permit> LINE...",
15369 NO_STR
15370 BGP_STR
15371 EXTCOMMUNITY_LIST_STR
15372 "Extended Community list number (expanded)\n"
15373 "Specify expanded extcommunity-list\n"
15374 "Extended Community list name\n"
15375 "Specify community to reject\n"
15376 "Specify community to accept\n"
15377 "An ordered list as a regular-expression\n")
15378 {
15379 int style = EXTCOMMUNITY_LIST_EXPANDED;
15380 int direct = 0;
15381 char *cl_number_or_name = NULL;
15382 char *str = NULL;
15383
15384 int idx = 0;
15385 if (argv_find(argv, argc, "ip", &idx)) {
15386 vty_out(vty, "This config option is deprecated, and is scheduled for removal.\n");
15387 vty_out(vty, "if you are using this please migrate to the below command.\n");
15388 vty_out(vty, "'no bgp extcommunity-list <(1-99)|(100-500)|standard|expanded> <deny|permit> <LINE|AA:NN>'\n");
15389 zlog_warn("Deprecated option: ‘no ip extcommunity-list <(1-99)|(100-500)|standard|expanded> <deny|permit> <LINE|AA:NN>' being used");
15390 }
15391
15392 idx = 0;
15393 argv_find(argv, argc, "permit", &idx);
15394 argv_find(argv, argc, "deny", &idx);
15395
15396 if (idx) {
15397 direct = argv_find(argv, argc, "permit", &idx)
15398 ? COMMUNITY_PERMIT
15399 : COMMUNITY_DENY;
15400
15401 idx = 0;
15402 argv_find(argv, argc, "LINE", &idx);
15403 str = argv_concat(argv, argc, idx);
15404 }
15405
15406 idx = 0;
15407 argv_find(argv, argc, "(100-500)", &idx);
15408 argv_find(argv, argc, "WORD", &idx);
15409 cl_number_or_name = argv[idx]->arg;
15410
15411 int ret = extcommunity_list_unset(bgp_clist, cl_number_or_name, str,
15412 direct, style);
15413
15414 XFREE(MTYPE_TMP, str);
15415
15416 if (ret < 0) {
15417 community_list_perror(vty, ret);
15418 return CMD_WARNING_CONFIG_FAILED;
15419 }
15420
15421 return CMD_SUCCESS;
15422 }
15423
15424 ALIAS (no_extcommunity_list_expanded_all,
15425 no_ip_extcommunity_list_expanded_all_cmd,
15426 "no ip extcommunity-list <(100-500)|expanded WORD> <deny|permit> LINE...",
15427 NO_STR
15428 IP_STR
15429 EXTCOMMUNITY_LIST_STR
15430 "Extended Community list number (expanded)\n"
15431 "Specify expanded extcommunity-list\n"
15432 "Extended Community list name\n"
15433 "Specify community to reject\n"
15434 "Specify community to accept\n"
15435 "An ordered list as a regular-expression\n")
15436
15437 ALIAS(no_extcommunity_list_expanded_all,
15438 no_ip_extcommunity_list_expanded_all_list_cmd,
15439 "no ip extcommunity-list <(100-500)|expanded WORD>",
15440 NO_STR IP_STR EXTCOMMUNITY_LIST_STR
15441 "Extended Community list number (expanded)\n"
15442 "Specify expanded extcommunity-list\n"
15443 "Extended Community list name\n")
15444
15445 ALIAS(no_extcommunity_list_expanded_all,
15446 no_bgp_extcommunity_list_expanded_all_list_cmd,
15447 "no bgp extcommunity-list <(100-500)|expanded WORD>",
15448 NO_STR IP_STR EXTCOMMUNITY_LIST_STR
15449 "Extended Community list number (expanded)\n"
15450 "Specify expanded extcommunity-list\n"
15451 "Extended Community list name\n")
15452
15453 static void extcommunity_list_show(struct vty *vty, struct community_list *list)
15454 {
15455 struct community_entry *entry;
15456
15457 for (entry = list->head; entry; entry = entry->next) {
15458 if (entry == list->head) {
15459 if (all_digit(list->name))
15460 vty_out(vty, "Extended community %s list %s\n",
15461 entry->style == EXTCOMMUNITY_LIST_STANDARD
15462 ? "standard"
15463 : "(expanded) access",
15464 list->name);
15465 else
15466 vty_out(vty,
15467 "Named extended community %s list %s\n",
15468 entry->style == EXTCOMMUNITY_LIST_STANDARD
15469 ? "standard"
15470 : "expanded",
15471 list->name);
15472 }
15473 if (entry->any)
15474 vty_out(vty, " %s\n",
15475 community_direct_str(entry->direct));
15476 else
15477 vty_out(vty, " %s %s\n",
15478 community_direct_str(entry->direct),
15479 community_list_config_str(entry));
15480 }
15481 }
15482
15483 DEFUN (show_extcommunity_list,
15484 show_bgp_extcommunity_list_cmd,
15485 "show bgp extcommunity-list",
15486 SHOW_STR
15487 BGP_STR
15488 "List extended-community list\n")
15489 {
15490 struct community_list *list;
15491 struct community_list_master *cm;
15492 int idx = 0;
15493
15494 if (argv_find(argv, argc, "ip", &idx)) {
15495 vty_out(vty, "This config option is deprecated, and is scheduled for removal\n");
15496 vty_out(vty, "if you are using this please migrate to the below command.\n");
15497 vty_out(vty, "'show bgp extcommunity-list <(1-500)|WORD>'\n");
15498 zlog_warn("Deprecated option: 'ip show extcommunity-list <(1-500)|WORD>' being used");
15499 }
15500 cm = community_list_master_lookup(bgp_clist, EXTCOMMUNITY_LIST_MASTER);
15501 if (!cm)
15502 return CMD_SUCCESS;
15503
15504 for (list = cm->num.head; list; list = list->next)
15505 extcommunity_list_show(vty, list);
15506
15507 for (list = cm->str.head; list; list = list->next)
15508 extcommunity_list_show(vty, list);
15509
15510 return CMD_SUCCESS;
15511 }
15512
15513 ALIAS (show_extcommunity_list,
15514 show_ip_extcommunity_list_cmd,
15515 "show ip extcommunity-list",
15516 SHOW_STR
15517 IP_STR
15518 "List extended-community list\n")
15519
15520 DEFUN (show_extcommunity_list_arg,
15521 show_bgp_extcommunity_list_arg_cmd,
15522 "show bgp extcommunity-list <(1-500)|WORD> detail",
15523 SHOW_STR
15524 BGP_STR
15525 "List extended-community list\n"
15526 "Extcommunity-list number\n"
15527 "Extcommunity-list name\n"
15528 "Detailed information on extcommunity-list\n")
15529 {
15530 int idx_comm_list = 3;
15531 struct community_list *list;
15532 int idx = 0;
15533
15534 if (argv_find(argv, argc, "ip", &idx)) {
15535 vty_out(vty, "This config option is deprecated, and is scheduled for removal.\n");
15536 vty_out(vty, "if you are using this please migrate to the below command.\n");
15537 vty_out(vty, "'show bgp extcommunity-list <(1-500)|WORD> detail'\n");
15538 zlog_warn("Deprecated option: 'show ip extcommunity-list <(1-500)|WORD>' being used");
15539 }
15540 list = community_list_lookup(bgp_clist, argv[idx_comm_list]->arg, 0,
15541 EXTCOMMUNITY_LIST_MASTER);
15542 if (!list) {
15543 vty_out(vty, "%% Can't find extcommunity-list\n");
15544 return CMD_WARNING;
15545 }
15546
15547 extcommunity_list_show(vty, list);
15548
15549 return CMD_SUCCESS;
15550 }
15551
15552 ALIAS (show_extcommunity_list_arg,
15553 show_ip_extcommunity_list_arg_cmd,
15554 "show ip extcommunity-list <(1-500)|WORD>",
15555 SHOW_STR
15556 IP_STR
15557 "List extended-community list\n"
15558 "Extcommunity-list number\n"
15559 "Extcommunity-list name\n")
15560
15561 /* Display community-list and extcommunity-list configuration. */
15562 static int community_list_config_write(struct vty *vty)
15563 {
15564 struct community_list *list;
15565 struct community_entry *entry;
15566 struct community_list_master *cm;
15567 int write = 0;
15568
15569 /* Community-list. */
15570 cm = community_list_master_lookup(bgp_clist, COMMUNITY_LIST_MASTER);
15571
15572 for (list = cm->num.head; list; list = list->next)
15573 for (entry = list->head; entry; entry = entry->next) {
15574 vty_out(vty, "bgp community-list %s %s %s\n", list->name,
15575 community_direct_str(entry->direct),
15576 community_list_config_str(entry));
15577 write++;
15578 }
15579 for (list = cm->str.head; list; list = list->next)
15580 for (entry = list->head; entry; entry = entry->next) {
15581 vty_out(vty, "bgp community-list %s %s %s %s\n",
15582 entry->style == COMMUNITY_LIST_STANDARD
15583 ? "standard"
15584 : "expanded",
15585 list->name, community_direct_str(entry->direct),
15586 community_list_config_str(entry));
15587 write++;
15588 }
15589
15590 /* Extcommunity-list. */
15591 cm = community_list_master_lookup(bgp_clist, EXTCOMMUNITY_LIST_MASTER);
15592
15593 for (list = cm->num.head; list; list = list->next)
15594 for (entry = list->head; entry; entry = entry->next) {
15595 vty_out(vty, "bgp extcommunity-list %s %s %s\n",
15596 list->name, community_direct_str(entry->direct),
15597 community_list_config_str(entry));
15598 write++;
15599 }
15600 for (list = cm->str.head; list; list = list->next)
15601 for (entry = list->head; entry; entry = entry->next) {
15602 vty_out(vty, "bgp extcommunity-list %s %s %s %s\n",
15603 entry->style == EXTCOMMUNITY_LIST_STANDARD
15604 ? "standard"
15605 : "expanded",
15606 list->name, community_direct_str(entry->direct),
15607 community_list_config_str(entry));
15608 write++;
15609 }
15610
15611
15612 /* lcommunity-list. */
15613 cm = community_list_master_lookup(bgp_clist,
15614 LARGE_COMMUNITY_LIST_MASTER);
15615
15616 for (list = cm->num.head; list; list = list->next)
15617 for (entry = list->head; entry; entry = entry->next) {
15618 vty_out(vty, "bgp large-community-list %s %s %s\n",
15619 list->name, community_direct_str(entry->direct),
15620 community_list_config_str(entry));
15621 write++;
15622 }
15623 for (list = cm->str.head; list; list = list->next)
15624 for (entry = list->head; entry; entry = entry->next) {
15625 vty_out(vty, "bgp large-community-list %s %s %s %s\n",
15626 entry->style == LARGE_COMMUNITY_LIST_STANDARD
15627 ? "standard"
15628 : "expanded",
15629 list->name, community_direct_str(entry->direct),
15630 community_list_config_str(entry));
15631 write++;
15632 }
15633
15634 return write;
15635 }
15636
15637 static struct cmd_node community_list_node = {
15638 COMMUNITY_LIST_NODE, "", 1 /* Export to vtysh. */
15639 };
15640
15641 static void community_list_vty(void)
15642 {
15643 install_node(&community_list_node, community_list_config_write);
15644
15645 /* Community-list. */
15646 install_element(CONFIG_NODE, &bgp_community_list_standard_cmd);
15647 install_element(CONFIG_NODE, &bgp_community_list_expanded_all_cmd);
15648 install_element(CONFIG_NODE, &no_bgp_community_list_standard_all_cmd);
15649 install_element(CONFIG_NODE, &no_bgp_community_list_standard_all_list_cmd);
15650 install_element(CONFIG_NODE, &no_bgp_community_list_expanded_all_cmd);
15651 install_element(CONFIG_NODE, &no_bgp_community_list_expanded_all_list_cmd);
15652 install_element(VIEW_NODE, &show_bgp_community_list_cmd);
15653 install_element(VIEW_NODE, &show_bgp_community_list_arg_cmd);
15654 install_element(CONFIG_NODE, &ip_community_list_standard_cmd);
15655 install_element(CONFIG_NODE, &ip_community_list_expanded_all_cmd);
15656 install_element(CONFIG_NODE, &no_ip_community_list_standard_all_cmd);
15657 install_element(CONFIG_NODE, &no_ip_community_list_standard_all_list_cmd);
15658 install_element(CONFIG_NODE, &no_ip_community_list_expanded_all_cmd);
15659 install_element(CONFIG_NODE, &no_ip_community_list_expanded_all_list_cmd);
15660 install_element(VIEW_NODE, &show_ip_community_list_cmd);
15661 install_element(VIEW_NODE, &show_ip_community_list_arg_cmd);
15662
15663 /* Extcommunity-list. */
15664 install_element(CONFIG_NODE, &bgp_extcommunity_list_standard_cmd);
15665 install_element(CONFIG_NODE, &bgp_extcommunity_list_name_expanded_cmd);
15666 install_element(CONFIG_NODE, &no_bgp_extcommunity_list_standard_all_cmd);
15667 install_element(CONFIG_NODE,
15668 &no_bgp_extcommunity_list_standard_all_list_cmd);
15669 install_element(CONFIG_NODE, &no_bgp_extcommunity_list_expanded_all_cmd);
15670 install_element(CONFIG_NODE,
15671 &no_bgp_extcommunity_list_expanded_all_list_cmd);
15672 install_element(VIEW_NODE, &show_bgp_extcommunity_list_cmd);
15673 install_element(VIEW_NODE, &show_bgp_extcommunity_list_arg_cmd);
15674 install_element(CONFIG_NODE, &ip_extcommunity_list_standard_cmd);
15675 install_element(CONFIG_NODE, &ip_extcommunity_list_name_expanded_cmd);
15676 install_element(CONFIG_NODE, &no_ip_extcommunity_list_standard_all_cmd);
15677 install_element(CONFIG_NODE, &no_ip_extcommunity_list_standard_all_list_cmd);
15678 install_element(CONFIG_NODE, &no_ip_extcommunity_list_expanded_all_cmd);
15679 install_element(CONFIG_NODE, &no_ip_extcommunity_list_expanded_all_list_cmd);
15680 install_element(VIEW_NODE, &show_ip_extcommunity_list_cmd);
15681 install_element(VIEW_NODE, &show_ip_extcommunity_list_arg_cmd);
15682
15683 /* Large Community List */
15684 install_element(CONFIG_NODE, &bgp_lcommunity_list_standard_cmd);
15685 install_element(CONFIG_NODE, &bgp_lcommunity_list_expanded_cmd);
15686 install_element(CONFIG_NODE, &bgp_lcommunity_list_name_standard_cmd);
15687 install_element(CONFIG_NODE, &bgp_lcommunity_list_name_expanded_cmd);
15688 install_element(CONFIG_NODE, &no_bgp_lcommunity_list_standard_all_cmd);
15689 install_element(CONFIG_NODE,
15690 &no_bgp_lcommunity_list_name_expanded_all_cmd);
15691 install_element(CONFIG_NODE, &no_bgp_lcommunity_list_standard_cmd);
15692 install_element(CONFIG_NODE, &no_bgp_lcommunity_list_expanded_cmd);
15693 install_element(CONFIG_NODE, &no_bgp_lcommunity_list_name_standard_cmd);
15694 install_element(CONFIG_NODE, &no_bgp_lcommunity_list_name_expanded_cmd);
15695 install_element(VIEW_NODE, &show_bgp_lcommunity_list_cmd);
15696 install_element(VIEW_NODE, &show_bgp_lcommunity_list_arg_cmd);
15697 install_element(CONFIG_NODE, &ip_lcommunity_list_standard_cmd);
15698 install_element(CONFIG_NODE, &ip_lcommunity_list_expanded_cmd);
15699 install_element(CONFIG_NODE, &ip_lcommunity_list_name_standard_cmd);
15700 install_element(CONFIG_NODE, &ip_lcommunity_list_name_expanded_cmd);
15701 install_element(CONFIG_NODE, &no_ip_lcommunity_list_standard_all_cmd);
15702 install_element(CONFIG_NODE,
15703 &no_ip_lcommunity_list_name_expanded_all_cmd);
15704 install_element(CONFIG_NODE, &no_ip_lcommunity_list_standard_cmd);
15705 install_element(CONFIG_NODE, &no_ip_lcommunity_list_expanded_cmd);
15706 install_element(CONFIG_NODE, &no_ip_lcommunity_list_name_standard_cmd);
15707 install_element(CONFIG_NODE, &no_ip_lcommunity_list_name_expanded_cmd);
15708 install_element(VIEW_NODE, &show_ip_lcommunity_list_cmd);
15709 install_element(VIEW_NODE, &show_ip_lcommunity_list_arg_cmd);
15710 }