]> git.proxmox.com Git - mirror_frr.git/blob - bgpd/bgp_vty.c
bgpd: move config-write to bgp_vty.c
[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 "lib_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_evpn_vty.h"
68 #include "bgpd/bgp_addpath.h"
69 #include "bgpd/bgp_mac.h"
70 #include "bgpd/bgp_flowspec.h"
71 #if ENABLE_BGP_VNC
72 #include "bgpd/rfapi/bgp_rfapi_cfg.h"
73 #endif
74
75 DEFINE_HOOK(bgp_inst_config_write,
76 (struct bgp *bgp, struct vty *vty),
77 (bgp, vty))
78
79 static struct peer_group *listen_range_exists(struct bgp *bgp,
80 struct prefix *range, int exact);
81
82 static enum node_type bgp_node_type(afi_t afi, safi_t safi)
83 {
84 switch (afi) {
85 case AFI_IP:
86 switch (safi) {
87 case SAFI_UNICAST:
88 return BGP_IPV4_NODE;
89 break;
90 case SAFI_MULTICAST:
91 return BGP_IPV4M_NODE;
92 break;
93 case SAFI_LABELED_UNICAST:
94 return BGP_IPV4L_NODE;
95 break;
96 case SAFI_MPLS_VPN:
97 return BGP_VPNV4_NODE;
98 break;
99 case SAFI_FLOWSPEC:
100 return BGP_FLOWSPECV4_NODE;
101 default:
102 /* not expected */
103 return BGP_IPV4_NODE;
104 break;
105 }
106 break;
107 case AFI_IP6:
108 switch (safi) {
109 case SAFI_UNICAST:
110 return BGP_IPV6_NODE;
111 break;
112 case SAFI_MULTICAST:
113 return BGP_IPV6M_NODE;
114 break;
115 case SAFI_LABELED_UNICAST:
116 return BGP_IPV6L_NODE;
117 break;
118 case SAFI_MPLS_VPN:
119 return BGP_VPNV6_NODE;
120 break;
121 case SAFI_FLOWSPEC:
122 return BGP_FLOWSPECV6_NODE;
123 default:
124 /* not expected */
125 return BGP_IPV4_NODE;
126 break;
127 }
128 break;
129 case AFI_L2VPN:
130 return BGP_EVPN_NODE;
131 break;
132 case AFI_UNSPEC:
133 case AFI_MAX:
134 // We should never be here but to clarify the switch statement..
135 return BGP_IPV4_NODE;
136 break;
137 }
138
139 // Impossible to happen
140 return BGP_IPV4_NODE;
141 }
142
143 static const char *get_afi_safi_vty_str(afi_t afi, safi_t safi)
144 {
145 if (afi == AFI_IP && safi == SAFI_UNICAST)
146 return "IPv4 Unicast";
147 else if (afi == AFI_IP && safi == SAFI_MULTICAST)
148 return "IPv4 Multicast";
149 else if (afi == AFI_IP && safi == SAFI_LABELED_UNICAST)
150 return "IPv4 Labeled Unicast";
151 else if (afi == AFI_IP && safi == SAFI_MPLS_VPN)
152 return "IPv4 VPN";
153 else if (afi == AFI_IP && safi == SAFI_ENCAP)
154 return "IPv4 Encap";
155 else if (afi == AFI_IP && safi == SAFI_FLOWSPEC)
156 return "IPv4 Flowspec";
157 else if (afi == AFI_IP6 && safi == SAFI_UNICAST)
158 return "IPv6 Unicast";
159 else if (afi == AFI_IP6 && safi == SAFI_MULTICAST)
160 return "IPv6 Multicast";
161 else if (afi == AFI_IP6 && safi == SAFI_LABELED_UNICAST)
162 return "IPv6 Labeled Unicast";
163 else if (afi == AFI_IP6 && safi == SAFI_MPLS_VPN)
164 return "IPv6 VPN";
165 else if (afi == AFI_IP6 && safi == SAFI_ENCAP)
166 return "IPv6 Encap";
167 else if (afi == AFI_IP6 && safi == SAFI_FLOWSPEC)
168 return "IPv6 Flowspec";
169 else if (afi == AFI_L2VPN && safi == SAFI_EVPN)
170 return "L2VPN EVPN";
171 else
172 return "Unknown";
173 }
174
175 /*
176 * Please note that we have intentionally camelCased
177 * the return strings here. So if you want
178 * to use this function, please ensure you
179 * are doing this within json output
180 */
181 static const char *get_afi_safi_json_str(afi_t afi, safi_t safi)
182 {
183 if (afi == AFI_IP && safi == SAFI_UNICAST)
184 return "ipv4Unicast";
185 else if (afi == AFI_IP && safi == SAFI_MULTICAST)
186 return "ipv4Multicast";
187 else if (afi == AFI_IP && safi == SAFI_LABELED_UNICAST)
188 return "ipv4LabeledUnicast";
189 else if (afi == AFI_IP && safi == SAFI_MPLS_VPN)
190 return "ipv4Vpn";
191 else if (afi == AFI_IP && safi == SAFI_ENCAP)
192 return "ipv4Encap";
193 else if (afi == AFI_IP && safi == SAFI_FLOWSPEC)
194 return "ipv4Flowspec";
195 else if (afi == AFI_IP6 && safi == SAFI_UNICAST)
196 return "ipv6Unicast";
197 else if (afi == AFI_IP6 && safi == SAFI_MULTICAST)
198 return "ipv6Multicast";
199 else if (afi == AFI_IP6 && safi == SAFI_LABELED_UNICAST)
200 return "ipv6LabeledUnicast";
201 else if (afi == AFI_IP6 && safi == SAFI_MPLS_VPN)
202 return "ipv6Vpn";
203 else if (afi == AFI_IP6 && safi == SAFI_ENCAP)
204 return "ipv6Encap";
205 else if (afi == AFI_IP6 && safi == SAFI_FLOWSPEC)
206 return "ipv6Flowspec";
207 else if (afi == AFI_L2VPN && safi == SAFI_EVPN)
208 return "l2VpnEvpn";
209 else
210 return "Unknown";
211 }
212
213 /* Utility function to get address family from current node. */
214 afi_t bgp_node_afi(struct vty *vty)
215 {
216 afi_t afi;
217 switch (vty->node) {
218 case BGP_IPV6_NODE:
219 case BGP_IPV6M_NODE:
220 case BGP_IPV6L_NODE:
221 case BGP_VPNV6_NODE:
222 case BGP_FLOWSPECV6_NODE:
223 afi = AFI_IP6;
224 break;
225 case BGP_EVPN_NODE:
226 afi = AFI_L2VPN;
227 break;
228 default:
229 afi = AFI_IP;
230 break;
231 }
232 return afi;
233 }
234
235 /* Utility function to get subsequent address family from current
236 node. */
237 safi_t bgp_node_safi(struct vty *vty)
238 {
239 safi_t safi;
240 switch (vty->node) {
241 case BGP_VPNV4_NODE:
242 case BGP_VPNV6_NODE:
243 safi = SAFI_MPLS_VPN;
244 break;
245 case BGP_IPV4M_NODE:
246 case BGP_IPV6M_NODE:
247 safi = SAFI_MULTICAST;
248 break;
249 case BGP_EVPN_NODE:
250 safi = SAFI_EVPN;
251 break;
252 case BGP_IPV4L_NODE:
253 case BGP_IPV6L_NODE:
254 safi = SAFI_LABELED_UNICAST;
255 break;
256 case BGP_FLOWSPECV4_NODE:
257 case BGP_FLOWSPECV6_NODE:
258 safi = SAFI_FLOWSPEC;
259 break;
260 default:
261 safi = SAFI_UNICAST;
262 break;
263 }
264 return safi;
265 }
266
267 /**
268 * Converts an AFI in string form to afi_t
269 *
270 * @param afi string, one of
271 * - "ipv4"
272 * - "ipv6"
273 * - "l2vpn"
274 * @return the corresponding afi_t
275 */
276 afi_t bgp_vty_afi_from_str(const char *afi_str)
277 {
278 afi_t afi = AFI_MAX; /* unknown */
279 if (strmatch(afi_str, "ipv4"))
280 afi = AFI_IP;
281 else if (strmatch(afi_str, "ipv6"))
282 afi = AFI_IP6;
283 else if (strmatch(afi_str, "l2vpn"))
284 afi = AFI_L2VPN;
285 return afi;
286 }
287
288 int argv_find_and_parse_afi(struct cmd_token **argv, int argc, int *index,
289 afi_t *afi)
290 {
291 int ret = 0;
292 if (argv_find(argv, argc, "ipv4", index)) {
293 ret = 1;
294 if (afi)
295 *afi = AFI_IP;
296 } else if (argv_find(argv, argc, "ipv6", index)) {
297 ret = 1;
298 if (afi)
299 *afi = AFI_IP6;
300 } else if (argv_find(argv, argc, "l2vpn", index)) {
301 ret = 1;
302 if (afi)
303 *afi = AFI_L2VPN;
304 }
305 return ret;
306 }
307
308 /* supports <unicast|multicast|vpn|labeled-unicast> */
309 safi_t bgp_vty_safi_from_str(const char *safi_str)
310 {
311 safi_t safi = SAFI_MAX; /* unknown */
312 if (strmatch(safi_str, "multicast"))
313 safi = SAFI_MULTICAST;
314 else if (strmatch(safi_str, "unicast"))
315 safi = SAFI_UNICAST;
316 else if (strmatch(safi_str, "vpn"))
317 safi = SAFI_MPLS_VPN;
318 else if (strmatch(safi_str, "evpn"))
319 safi = SAFI_EVPN;
320 else if (strmatch(safi_str, "labeled-unicast"))
321 safi = SAFI_LABELED_UNICAST;
322 else if (strmatch(safi_str, "flowspec"))
323 safi = SAFI_FLOWSPEC;
324 return safi;
325 }
326
327 int argv_find_and_parse_safi(struct cmd_token **argv, int argc, int *index,
328 safi_t *safi)
329 {
330 int ret = 0;
331 if (argv_find(argv, argc, "unicast", index)) {
332 ret = 1;
333 if (safi)
334 *safi = SAFI_UNICAST;
335 } else if (argv_find(argv, argc, "multicast", index)) {
336 ret = 1;
337 if (safi)
338 *safi = SAFI_MULTICAST;
339 } else if (argv_find(argv, argc, "labeled-unicast", index)) {
340 ret = 1;
341 if (safi)
342 *safi = SAFI_LABELED_UNICAST;
343 } else if (argv_find(argv, argc, "vpn", index)) {
344 ret = 1;
345 if (safi)
346 *safi = SAFI_MPLS_VPN;
347 } else if (argv_find(argv, argc, "evpn", index)) {
348 ret = 1;
349 if (safi)
350 *safi = SAFI_EVPN;
351 } else if (argv_find(argv, argc, "flowspec", index)) {
352 ret = 1;
353 if (safi)
354 *safi = SAFI_FLOWSPEC;
355 }
356 return ret;
357 }
358
359 /*
360 * bgp_vty_find_and_parse_afi_safi_bgp
361 *
362 * For a given 'show ...' command, correctly parse the afi/safi/bgp out from it
363 * This function *assumes* that the calling function pre-sets the afi/safi/bgp
364 * to appropriate values for the calling function. This is to allow the
365 * calling function to make decisions appropriate for the show command
366 * that is being parsed.
367 *
368 * The show commands are generally of the form:
369 * "show [ip] bgp [<view|vrf> VIEWVRFNAME] [<ipv4|ipv6>
370 * [<unicast|multicast|vpn|labeled-unicast>]] ..."
371 *
372 * Since we use argv_find if the show command in particular doesn't have:
373 * [ip]
374 * [<view|vrf> VIEWVRFNAME]
375 * [<ipv4|ipv6> [<unicast|multicast|vpn|labeled-unicast>]]
376 * The command parsing should still be ok.
377 *
378 * vty -> The vty for the command so we can output some useful data in
379 * the event of a parse error in the vrf.
380 * argv -> The command tokens
381 * argc -> How many command tokens we have
382 * idx -> The current place in the command, generally should be 0 for this
383 * function
384 * afi -> The parsed afi if it was included in the show command, returned here
385 * safi -> The parsed safi if it was included in the show command, returned here
386 * bgp -> Pointer to the bgp data structure we need to fill in.
387 * use_json -> json is configured or not
388 *
389 * The function returns the correct location in the parse tree for the
390 * last token found.
391 *
392 * Returns 0 for failure to parse correctly, else the idx position of where
393 * it found the last token.
394 */
395 int bgp_vty_find_and_parse_afi_safi_bgp(struct vty *vty,
396 struct cmd_token **argv, int argc,
397 int *idx, afi_t *afi, safi_t *safi,
398 struct bgp **bgp, bool use_json)
399 {
400 char *vrf_name = NULL;
401
402 assert(afi);
403 assert(safi);
404 assert(bgp);
405
406 if (argv_find(argv, argc, "ip", idx))
407 *afi = AFI_IP;
408
409 if (argv_find(argv, argc, "view", idx))
410 vrf_name = argv[*idx + 1]->arg;
411 else if (argv_find(argv, argc, "vrf", idx)) {
412 vrf_name = argv[*idx + 1]->arg;
413 if (strmatch(vrf_name, VRF_DEFAULT_NAME))
414 vrf_name = NULL;
415 }
416 if (vrf_name) {
417 if (strmatch(vrf_name, "all"))
418 *bgp = NULL;
419 else {
420 *bgp = bgp_lookup_by_name(vrf_name);
421 if (!*bgp) {
422 if (use_json) {
423 json_object *json = NULL;
424 json = json_object_new_object();
425 json_object_string_add(
426 json, "warning",
427 "View/Vrf is unknown");
428 vty_out(vty, "%s\n",
429 json_object_to_json_string_ext(json,
430 JSON_C_TO_STRING_PRETTY));
431 json_object_free(json);
432 }
433 else
434 vty_out(vty, "View/Vrf %s is unknown\n",
435 vrf_name);
436 *idx = 0;
437 return 0;
438 }
439 }
440 } else {
441 *bgp = bgp_get_default();
442 if (!*bgp) {
443 if (use_json) {
444 json_object *json = NULL;
445 json = json_object_new_object();
446 json_object_string_add(
447 json, "warning",
448 "Default BGP instance not found");
449 vty_out(vty, "%s\n",
450 json_object_to_json_string_ext(json,
451 JSON_C_TO_STRING_PRETTY));
452 json_object_free(json);
453 }
454 else
455 vty_out(vty,
456 "Default BGP instance not found\n");
457 *idx = 0;
458 return 0;
459 }
460 }
461
462 if (argv_find_and_parse_afi(argv, argc, idx, afi))
463 argv_find_and_parse_safi(argv, argc, idx, safi);
464
465 *idx += 1;
466 return *idx;
467 }
468
469 static int peer_address_self_check(struct bgp *bgp, union sockunion *su)
470 {
471 struct interface *ifp = NULL;
472
473 if (su->sa.sa_family == AF_INET)
474 ifp = if_lookup_by_ipv4_exact(&su->sin.sin_addr, bgp->vrf_id);
475 else if (su->sa.sa_family == AF_INET6)
476 ifp = if_lookup_by_ipv6_exact(&su->sin6.sin6_addr,
477 su->sin6.sin6_scope_id,
478 bgp->vrf_id);
479
480 if (ifp)
481 return 1;
482
483 return 0;
484 }
485
486 /* Utility function for looking up peer from VTY. */
487 /* This is used only for configuration, so disallow if attempted on
488 * a dynamic neighbor.
489 */
490 static struct peer *peer_lookup_vty(struct vty *vty, const char *ip_str)
491 {
492 struct bgp *bgp = VTY_GET_CONTEXT(bgp);
493 int ret;
494 union sockunion su;
495 struct peer *peer;
496
497 if (!bgp) {
498 return NULL;
499 }
500
501 ret = str2sockunion(ip_str, &su);
502 if (ret < 0) {
503 peer = peer_lookup_by_conf_if(bgp, ip_str);
504 if (!peer) {
505 if ((peer = peer_lookup_by_hostname(bgp, ip_str))
506 == NULL) {
507 vty_out(vty,
508 "%% Malformed address or name: %s\n",
509 ip_str);
510 return NULL;
511 }
512 }
513 } else {
514 peer = peer_lookup(bgp, &su);
515 if (!peer) {
516 vty_out(vty,
517 "%% Specify remote-as or peer-group commands first\n");
518 return NULL;
519 }
520 if (peer_dynamic_neighbor(peer)) {
521 vty_out(vty,
522 "%% Operation not allowed on a dynamic neighbor\n");
523 return NULL;
524 }
525 }
526 return peer;
527 }
528
529 /* Utility function for looking up peer or peer group. */
530 /* This is used only for configuration, so disallow if attempted on
531 * a dynamic neighbor.
532 */
533 struct peer *peer_and_group_lookup_vty(struct vty *vty, const char *peer_str)
534 {
535 struct bgp *bgp = VTY_GET_CONTEXT(bgp);
536 int ret;
537 union sockunion su;
538 struct peer *peer = NULL;
539 struct peer_group *group = NULL;
540
541 if (!bgp) {
542 return NULL;
543 }
544
545 ret = str2sockunion(peer_str, &su);
546 if (ret == 0) {
547 /* IP address, locate peer. */
548 peer = peer_lookup(bgp, &su);
549 } else {
550 /* Not IP, could match either peer configured on interface or a
551 * group. */
552 peer = peer_lookup_by_conf_if(bgp, peer_str);
553 if (!peer)
554 group = peer_group_lookup(bgp, peer_str);
555 }
556
557 if (peer) {
558 if (peer_dynamic_neighbor(peer)) {
559 vty_out(vty,
560 "%% Operation not allowed on a dynamic neighbor\n");
561 return NULL;
562 }
563
564 return peer;
565 }
566
567 if (group)
568 return group->conf;
569
570 vty_out(vty, "%% Specify remote-as or peer-group commands first\n");
571
572 return NULL;
573 }
574
575 int bgp_vty_return(struct vty *vty, int ret)
576 {
577 const char *str = NULL;
578
579 switch (ret) {
580 case BGP_ERR_INVALID_VALUE:
581 str = "Invalid value";
582 break;
583 case BGP_ERR_INVALID_FLAG:
584 str = "Invalid flag";
585 break;
586 case BGP_ERR_PEER_GROUP_SHUTDOWN:
587 str = "Peer-group has been shutdown. Activate the peer-group first";
588 break;
589 case BGP_ERR_PEER_FLAG_CONFLICT:
590 str = "Can't set override-capability and strict-capability-match at the same time";
591 break;
592 case BGP_ERR_PEER_GROUP_NO_REMOTE_AS:
593 str = "Specify remote-as or peer-group remote AS first";
594 break;
595 case BGP_ERR_PEER_GROUP_CANT_CHANGE:
596 str = "Cannot change the peer-group. Deconfigure first";
597 break;
598 case BGP_ERR_PEER_GROUP_MISMATCH:
599 str = "Peer is not a member of this peer-group";
600 break;
601 case BGP_ERR_PEER_FILTER_CONFLICT:
602 str = "Prefix/distribute list can not co-exist";
603 break;
604 case BGP_ERR_NOT_INTERNAL_PEER:
605 str = "Invalid command. Not an internal neighbor";
606 break;
607 case BGP_ERR_REMOVE_PRIVATE_AS:
608 str = "remove-private-AS cannot be configured for IBGP peers";
609 break;
610 case BGP_ERR_LOCAL_AS_ALLOWED_ONLY_FOR_EBGP:
611 str = "Local-AS allowed only for EBGP peers";
612 break;
613 case BGP_ERR_CANNOT_HAVE_LOCAL_AS_SAME_AS:
614 str = "Cannot have local-as same as BGP AS number";
615 break;
616 case BGP_ERR_TCPSIG_FAILED:
617 str = "Error while applying TCP-Sig to session(s)";
618 break;
619 case BGP_ERR_NO_EBGP_MULTIHOP_WITH_TTLHACK:
620 str = "ebgp-multihop and ttl-security cannot be configured together";
621 break;
622 case BGP_ERR_NO_IBGP_WITH_TTLHACK:
623 str = "ttl-security only allowed for EBGP peers";
624 break;
625 case BGP_ERR_AS_OVERRIDE:
626 str = "as-override cannot be configured for IBGP peers";
627 break;
628 case BGP_ERR_INVALID_DYNAMIC_NEIGHBORS_LIMIT:
629 str = "Invalid limit for number of dynamic neighbors";
630 break;
631 case BGP_ERR_DYNAMIC_NEIGHBORS_RANGE_EXISTS:
632 str = "Dynamic neighbor listen range already exists";
633 break;
634 case BGP_ERR_INVALID_FOR_DYNAMIC_PEER:
635 str = "Operation not allowed on a dynamic neighbor";
636 break;
637 case BGP_ERR_INVALID_FOR_DIRECT_PEER:
638 str = "Operation not allowed on a directly connected neighbor";
639 break;
640 case BGP_ERR_PEER_SAFI_CONFLICT:
641 str = "Cannot activate peer for both 'ipv4 unicast' and 'ipv4 labeled-unicast'";
642 break;
643 }
644 if (str) {
645 vty_out(vty, "%% %s\n", str);
646 return CMD_WARNING_CONFIG_FAILED;
647 }
648 return CMD_SUCCESS;
649 }
650
651 /* BGP clear sort. */
652 enum clear_sort {
653 clear_all,
654 clear_peer,
655 clear_group,
656 clear_external,
657 clear_as
658 };
659
660 static void bgp_clear_vty_error(struct vty *vty, struct peer *peer, afi_t afi,
661 safi_t safi, int error)
662 {
663 switch (error) {
664 case BGP_ERR_AF_UNCONFIGURED:
665 vty_out(vty,
666 "%%BGP: Enable %s address family for the neighbor %s\n",
667 get_afi_safi_str(afi, safi, false), peer->host);
668 break;
669 case BGP_ERR_SOFT_RECONFIG_UNCONFIGURED:
670 vty_out(vty,
671 "%%BGP: Inbound soft reconfig for %s not possible as it\n has neither refresh capability, nor inbound soft reconfig\n",
672 peer->host);
673 break;
674 default:
675 break;
676 }
677 }
678
679 static int bgp_peer_clear(struct peer *peer, afi_t afi, safi_t safi,
680 struct listnode *nnode, enum bgp_clear_type stype)
681 {
682 int ret = 0;
683
684 /* if afi/.safi not specified, spin thru all of them */
685 if ((afi == AFI_UNSPEC) && (safi == SAFI_UNSPEC)) {
686 afi_t tmp_afi;
687 safi_t tmp_safi;
688
689 FOREACH_AFI_SAFI (tmp_afi, tmp_safi) {
690 if (!peer->afc[tmp_afi][tmp_safi])
691 continue;
692
693 if (stype == BGP_CLEAR_SOFT_NONE)
694 ret = peer_clear(peer, &nnode);
695 else
696 ret = peer_clear_soft(peer, tmp_afi, tmp_safi,
697 stype);
698 }
699 /* if afi specified and safi not, spin thru safis on this afi */
700 } else if (safi == SAFI_UNSPEC) {
701 safi_t tmp_safi;
702
703 for (tmp_safi = SAFI_UNICAST;
704 tmp_safi < SAFI_MAX; tmp_safi++) {
705 if (!peer->afc[afi][tmp_safi])
706 continue;
707
708 if (stype == BGP_CLEAR_SOFT_NONE)
709 ret = peer_clear(peer, &nnode);
710 else
711 ret = peer_clear_soft(peer, afi,
712 tmp_safi, stype);
713 }
714 /* both afi/safi specified, let the caller know if not defined */
715 } else {
716 if (!peer->afc[afi][safi])
717 return 1;
718
719 if (stype == BGP_CLEAR_SOFT_NONE)
720 ret = peer_clear(peer, &nnode);
721 else
722 ret = peer_clear_soft(peer, afi, safi, stype);
723 }
724
725 return ret;
726 }
727
728 /* `clear ip bgp' functions. */
729 static int bgp_clear(struct vty *vty, struct bgp *bgp, afi_t afi, safi_t safi,
730 enum clear_sort sort, enum bgp_clear_type stype,
731 const char *arg)
732 {
733 int ret = 0;
734 bool found = false;
735 struct peer *peer;
736 struct listnode *node, *nnode;
737
738 /* Clear all neighbors. */
739 /*
740 * Pass along pointer to next node to peer_clear() when walking all
741 * nodes on the BGP instance as that may get freed if it is a
742 * doppelganger
743 */
744 if (sort == clear_all) {
745 for (ALL_LIST_ELEMENTS(bgp->peer, node, nnode, peer)) {
746 ret = bgp_peer_clear(peer, afi, safi, nnode,
747 stype);
748
749 if (ret < 0)
750 bgp_clear_vty_error(vty, peer, afi, safi, ret);
751 }
752
753 /* This is to apply read-only mode on this clear. */
754 if (stype == BGP_CLEAR_SOFT_NONE)
755 bgp->update_delay_over = 0;
756
757 return CMD_SUCCESS;
758 }
759
760 /* Clear specified neighbor. */
761 if (sort == clear_peer) {
762 union sockunion su;
763
764 /* Make sockunion for lookup. */
765 ret = str2sockunion(arg, &su);
766 if (ret < 0) {
767 peer = peer_lookup_by_conf_if(bgp, arg);
768 if (!peer) {
769 peer = peer_lookup_by_hostname(bgp, arg);
770 if (!peer) {
771 vty_out(vty,
772 "Malformed address or name: %s\n",
773 arg);
774 return CMD_WARNING;
775 }
776 }
777 } else {
778 peer = peer_lookup(bgp, &su);
779 if (!peer) {
780 vty_out(vty,
781 "%%BGP: Unknown neighbor - \"%s\"\n",
782 arg);
783 return CMD_WARNING;
784 }
785 }
786
787 ret = bgp_peer_clear(peer, afi, safi, NULL, stype);
788
789 /* if afi/safi not defined for this peer, let caller know */
790 if (ret == 1)
791 ret = BGP_ERR_AF_UNCONFIGURED;
792
793 if (ret < 0)
794 bgp_clear_vty_error(vty, peer, afi, safi, ret);
795
796 return CMD_SUCCESS;
797 }
798
799 /* Clear all neighbors belonging to a specific peer-group. */
800 if (sort == clear_group) {
801 struct peer_group *group;
802
803 group = peer_group_lookup(bgp, arg);
804 if (!group) {
805 vty_out(vty, "%%BGP: No such peer-group %s\n", arg);
806 return CMD_WARNING;
807 }
808
809 for (ALL_LIST_ELEMENTS(group->peer, node, nnode, peer)) {
810 ret = bgp_peer_clear(peer, afi, safi, nnode, stype);
811
812 if (ret < 0)
813 bgp_clear_vty_error(vty, peer, afi, safi, ret);
814 else
815 found = true;
816 }
817
818 if (!found)
819 vty_out(vty,
820 "%%BGP: No %s peer belonging to peer-group %s is configured\n",
821 get_afi_safi_str(afi, safi, false), arg);
822
823 return CMD_SUCCESS;
824 }
825
826 /* Clear all external (eBGP) neighbors. */
827 if (sort == clear_external) {
828 for (ALL_LIST_ELEMENTS(bgp->peer, node, nnode, peer)) {
829 if (peer->sort == BGP_PEER_IBGP)
830 continue;
831
832 ret = bgp_peer_clear(peer, afi, safi, nnode, stype);
833
834 if (ret < 0)
835 bgp_clear_vty_error(vty, peer, afi, safi, ret);
836 else
837 found = true;
838 }
839
840 if (!found)
841 vty_out(vty,
842 "%%BGP: No external %s peer is configured\n",
843 get_afi_safi_str(afi, safi, false));
844
845 return CMD_SUCCESS;
846 }
847
848 /* Clear all neighbors belonging to a specific AS. */
849 if (sort == clear_as) {
850 as_t as = strtoul(arg, NULL, 10);
851
852 for (ALL_LIST_ELEMENTS(bgp->peer, node, nnode, peer)) {
853 if (peer->as != as)
854 continue;
855
856 ret = bgp_peer_clear(peer, afi, safi, nnode, stype);
857
858 if (ret < 0)
859 bgp_clear_vty_error(vty, peer, afi, safi, ret);
860 else
861 found = true;
862 }
863
864 if (!found)
865 vty_out(vty,
866 "%%BGP: No %s peer is configured with AS %s\n",
867 get_afi_safi_str(afi, safi, false), arg);
868
869 return CMD_SUCCESS;
870 }
871
872 return CMD_SUCCESS;
873 }
874
875 static int bgp_clear_vty(struct vty *vty, const char *name, afi_t afi,
876 safi_t safi, enum clear_sort sort,
877 enum bgp_clear_type stype, const char *arg)
878 {
879 struct bgp *bgp;
880
881 /* BGP structure lookup. */
882 if (name) {
883 bgp = bgp_lookup_by_name(name);
884 if (bgp == NULL) {
885 vty_out(vty, "Can't find BGP instance %s\n", name);
886 return CMD_WARNING;
887 }
888 } else {
889 bgp = bgp_get_default();
890 if (bgp == NULL) {
891 vty_out(vty, "No BGP process is configured\n");
892 return CMD_WARNING;
893 }
894 }
895
896 return bgp_clear(vty, bgp, afi, safi, sort, stype, arg);
897 }
898
899 /* clear soft inbound */
900 static void bgp_clear_star_soft_in(struct vty *vty, const char *name)
901 {
902 afi_t afi;
903 safi_t safi;
904
905 FOREACH_AFI_SAFI (afi, safi)
906 bgp_clear_vty(vty, name, afi, safi, clear_all,
907 BGP_CLEAR_SOFT_IN, NULL);
908 }
909
910 /* clear soft outbound */
911 static void bgp_clear_star_soft_out(struct vty *vty, const char *name)
912 {
913 afi_t afi;
914 safi_t safi;
915
916 FOREACH_AFI_SAFI (afi, safi)
917 bgp_clear_vty(vty, name, afi, safi, clear_all,
918 BGP_CLEAR_SOFT_OUT, NULL);
919 }
920
921
922 #ifndef VTYSH_EXTRACT_PL
923 #include "bgpd/bgp_vty_clippy.c"
924 #endif
925
926 DEFUN_HIDDEN (bgp_local_mac,
927 bgp_local_mac_cmd,
928 "bgp local-mac vni " CMD_VNI_RANGE " mac WORD seq (0-4294967295)",
929 BGP_STR
930 "Local MAC config\n"
931 "VxLAN Network Identifier\n"
932 "VNI number\n"
933 "local mac\n"
934 "mac address\n"
935 "mac-mobility sequence\n"
936 "seq number\n")
937 {
938 int rv;
939 vni_t vni;
940 struct ethaddr mac;
941 struct ipaddr ip;
942 uint32_t seq;
943 struct bgp *bgp;
944
945 vni = strtoul(argv[3]->arg, NULL, 10);
946 if (!prefix_str2mac(argv[5]->arg, &mac)) {
947 vty_out(vty, "%% Malformed MAC address\n");
948 return CMD_WARNING;
949 }
950 memset(&ip, 0, sizeof(ip));
951 seq = strtoul(argv[7]->arg, NULL, 10);
952
953 bgp = bgp_get_default();
954 if (!bgp) {
955 vty_out(vty, "Default BGP instance is not there\n");
956 return CMD_WARNING;
957 }
958
959 rv = bgp_evpn_local_macip_add(bgp, vni, &mac, &ip, 0 /* flags */, seq);
960 if (rv < 0) {
961 vty_out(vty, "Internal error\n");
962 return CMD_WARNING;
963 }
964
965 return CMD_SUCCESS;
966 }
967
968 DEFUN_HIDDEN (no_bgp_local_mac,
969 no_bgp_local_mac_cmd,
970 "no bgp local-mac vni " CMD_VNI_RANGE " mac WORD",
971 NO_STR
972 BGP_STR
973 "Local MAC config\n"
974 "VxLAN Network Identifier\n"
975 "VNI number\n"
976 "local mac\n"
977 "mac address\n")
978 {
979 int rv;
980 vni_t vni;
981 struct ethaddr mac;
982 struct ipaddr ip;
983 struct bgp *bgp;
984
985 vni = strtoul(argv[4]->arg, NULL, 10);
986 if (!prefix_str2mac(argv[6]->arg, &mac)) {
987 vty_out(vty, "%% Malformed MAC address\n");
988 return CMD_WARNING;
989 }
990 memset(&ip, 0, sizeof(ip));
991
992 bgp = bgp_get_default();
993 if (!bgp) {
994 vty_out(vty, "Default BGP instance is not there\n");
995 return CMD_WARNING;
996 }
997
998 rv = bgp_evpn_local_macip_del(bgp, vni, &mac, &ip, ZEBRA_NEIGH_ACTIVE);
999 if (rv < 0) {
1000 vty_out(vty, "Internal error\n");
1001 return CMD_WARNING;
1002 }
1003
1004 return CMD_SUCCESS;
1005 }
1006
1007 DEFUN (no_synchronization,
1008 no_synchronization_cmd,
1009 "no synchronization",
1010 NO_STR
1011 "Perform IGP synchronization\n")
1012 {
1013 return CMD_SUCCESS;
1014 }
1015
1016 DEFUN (no_auto_summary,
1017 no_auto_summary_cmd,
1018 "no auto-summary",
1019 NO_STR
1020 "Enable automatic network number summarization\n")
1021 {
1022 return CMD_SUCCESS;
1023 }
1024
1025 /* "router bgp" commands. */
1026 DEFUN_NOSH (router_bgp,
1027 router_bgp_cmd,
1028 "router bgp [(1-4294967295)$instasn [<view|vrf> VIEWVRFNAME]]",
1029 ROUTER_STR
1030 BGP_STR
1031 AS_STR
1032 BGP_INSTANCE_HELP_STR)
1033 {
1034 int idx_asn = 2;
1035 int idx_view_vrf = 3;
1036 int idx_vrf = 4;
1037 int is_new_bgp = 0;
1038 int ret;
1039 as_t as;
1040 struct bgp *bgp;
1041 const char *name = NULL;
1042 enum bgp_instance_type inst_type;
1043
1044 // "router bgp" without an ASN
1045 if (argc == 2) {
1046 // Pending: Make VRF option available for ASN less config
1047 bgp = bgp_get_default();
1048
1049 if (bgp == NULL) {
1050 vty_out(vty, "%% No BGP process is configured\n");
1051 return CMD_WARNING_CONFIG_FAILED;
1052 }
1053
1054 if (listcount(bm->bgp) > 1) {
1055 vty_out(vty, "%% Please specify ASN and VRF\n");
1056 return CMD_WARNING_CONFIG_FAILED;
1057 }
1058 }
1059
1060 // "router bgp X"
1061 else {
1062 as = strtoul(argv[idx_asn]->arg, NULL, 10);
1063
1064 inst_type = BGP_INSTANCE_TYPE_DEFAULT;
1065 if (argc > 3) {
1066 name = argv[idx_vrf]->arg;
1067
1068 if (!strcmp(argv[idx_view_vrf]->text, "vrf")) {
1069 if (strmatch(name, VRF_DEFAULT_NAME))
1070 name = NULL;
1071 else
1072 inst_type = BGP_INSTANCE_TYPE_VRF;
1073 } else if (!strcmp(argv[idx_view_vrf]->text, "view"))
1074 inst_type = BGP_INSTANCE_TYPE_VIEW;
1075 }
1076
1077 if (inst_type == BGP_INSTANCE_TYPE_DEFAULT)
1078 is_new_bgp = (bgp_lookup(as, name) == NULL);
1079
1080 ret = bgp_get(&bgp, &as, name, inst_type);
1081 switch (ret) {
1082 case BGP_ERR_AS_MISMATCH:
1083 vty_out(vty, "BGP is already running; AS is %u\n", as);
1084 return CMD_WARNING_CONFIG_FAILED;
1085 case BGP_ERR_INSTANCE_MISMATCH:
1086 vty_out(vty,
1087 "BGP instance name and AS number mismatch\n");
1088 vty_out(vty,
1089 "BGP instance is already running; AS is %u\n",
1090 as);
1091 return CMD_WARNING_CONFIG_FAILED;
1092 }
1093
1094 /*
1095 * If we just instantiated the default instance, complete
1096 * any pending VRF-VPN leaking that was configured via
1097 * earlier "router bgp X vrf FOO" blocks.
1098 */
1099 if (is_new_bgp && inst_type == BGP_INSTANCE_TYPE_DEFAULT)
1100 vpn_leak_postchange_all();
1101
1102 if (inst_type == BGP_INSTANCE_TYPE_VRF)
1103 bgp_vpn_leak_export(bgp);
1104 /* Pending: handle when user tries to change a view to vrf n vv.
1105 */
1106 }
1107
1108 /* unset the auto created flag as the user config is now present */
1109 UNSET_FLAG(bgp->vrf_flags, BGP_VRF_AUTO);
1110 VTY_PUSH_CONTEXT(BGP_NODE, bgp);
1111
1112 return CMD_SUCCESS;
1113 }
1114
1115 /* "no router bgp" commands. */
1116 DEFUN (no_router_bgp,
1117 no_router_bgp_cmd,
1118 "no router bgp [(1-4294967295)$instasn [<view|vrf> VIEWVRFNAME]]",
1119 NO_STR
1120 ROUTER_STR
1121 BGP_STR
1122 AS_STR
1123 BGP_INSTANCE_HELP_STR)
1124 {
1125 int idx_asn = 3;
1126 int idx_vrf = 5;
1127 as_t as;
1128 struct bgp *bgp;
1129 const char *name = NULL;
1130
1131 // "no router bgp" without an ASN
1132 if (argc == 3) {
1133 // Pending: Make VRF option available for ASN less config
1134 bgp = bgp_get_default();
1135
1136 if (bgp == NULL) {
1137 vty_out(vty, "%% No BGP process is configured\n");
1138 return CMD_WARNING_CONFIG_FAILED;
1139 }
1140
1141 if (listcount(bm->bgp) > 1) {
1142 vty_out(vty, "%% Please specify ASN and VRF\n");
1143 return CMD_WARNING_CONFIG_FAILED;
1144 }
1145
1146 if (bgp->l3vni) {
1147 vty_out(vty, "%% Please unconfigure l3vni %u",
1148 bgp->l3vni);
1149 return CMD_WARNING_CONFIG_FAILED;
1150 }
1151 } else {
1152 as = strtoul(argv[idx_asn]->arg, NULL, 10);
1153
1154 if (argc > 4)
1155 name = argv[idx_vrf]->arg;
1156
1157 /* Lookup bgp structure. */
1158 bgp = bgp_lookup(as, name);
1159 if (!bgp) {
1160 vty_out(vty, "%% Can't find BGP instance\n");
1161 return CMD_WARNING_CONFIG_FAILED;
1162 }
1163
1164 if (bgp->l3vni) {
1165 vty_out(vty, "%% Please unconfigure l3vni %u\n",
1166 bgp->l3vni);
1167 return CMD_WARNING_CONFIG_FAILED;
1168 }
1169
1170 /* Cannot delete default instance if vrf instances exist */
1171 if (bgp->inst_type == BGP_INSTANCE_TYPE_DEFAULT) {
1172 struct listnode *node;
1173 struct bgp *tmp_bgp;
1174
1175 for (ALL_LIST_ELEMENTS_RO(bm->bgp, node, tmp_bgp)) {
1176 if (tmp_bgp->inst_type
1177 == BGP_INSTANCE_TYPE_VRF) {
1178 vty_out(vty,
1179 "%% Cannot delete default BGP instance. Dependent VRF instances exist\n");
1180 return CMD_WARNING_CONFIG_FAILED;
1181 }
1182 }
1183 }
1184 }
1185
1186 if (bgp_vpn_leak_unimport(bgp, vty))
1187 return CMD_WARNING_CONFIG_FAILED;
1188
1189 bgp_delete(bgp);
1190
1191 return CMD_SUCCESS;
1192 }
1193
1194
1195 /* BGP router-id. */
1196
1197 DEFPY (bgp_router_id,
1198 bgp_router_id_cmd,
1199 "bgp router-id A.B.C.D",
1200 BGP_STR
1201 "Override configured router identifier\n"
1202 "Manually configured router identifier\n")
1203 {
1204 VTY_DECLVAR_CONTEXT(bgp, bgp);
1205 bgp_router_id_static_set(bgp, router_id);
1206 return CMD_SUCCESS;
1207 }
1208
1209 DEFPY (no_bgp_router_id,
1210 no_bgp_router_id_cmd,
1211 "no bgp router-id [A.B.C.D]",
1212 NO_STR
1213 BGP_STR
1214 "Override configured router identifier\n"
1215 "Manually configured router identifier\n")
1216 {
1217 VTY_DECLVAR_CONTEXT(bgp, bgp);
1218
1219 if (router_id_str) {
1220 if (!IPV4_ADDR_SAME(&bgp->router_id_static, &router_id)) {
1221 vty_out(vty, "%% BGP router-id doesn't match\n");
1222 return CMD_WARNING_CONFIG_FAILED;
1223 }
1224 }
1225
1226 router_id.s_addr = 0;
1227 bgp_router_id_static_set(bgp, router_id);
1228
1229 return CMD_SUCCESS;
1230 }
1231
1232
1233 /* BGP Cluster ID. */
1234 DEFUN (bgp_cluster_id,
1235 bgp_cluster_id_cmd,
1236 "bgp cluster-id <A.B.C.D|(1-4294967295)>",
1237 BGP_STR
1238 "Configure Route-Reflector Cluster-id\n"
1239 "Route-Reflector Cluster-id in IP address format\n"
1240 "Route-Reflector Cluster-id as 32 bit quantity\n")
1241 {
1242 VTY_DECLVAR_CONTEXT(bgp, bgp);
1243 int idx_ipv4 = 2;
1244 int ret;
1245 struct in_addr cluster;
1246
1247 ret = inet_aton(argv[idx_ipv4]->arg, &cluster);
1248 if (!ret) {
1249 vty_out(vty, "%% Malformed bgp cluster identifier\n");
1250 return CMD_WARNING_CONFIG_FAILED;
1251 }
1252
1253 bgp_cluster_id_set(bgp, &cluster);
1254 bgp_clear_star_soft_out(vty, bgp->name);
1255
1256 return CMD_SUCCESS;
1257 }
1258
1259 DEFUN (no_bgp_cluster_id,
1260 no_bgp_cluster_id_cmd,
1261 "no bgp cluster-id [<A.B.C.D|(1-4294967295)>]",
1262 NO_STR
1263 BGP_STR
1264 "Configure Route-Reflector Cluster-id\n"
1265 "Route-Reflector Cluster-id in IP address format\n"
1266 "Route-Reflector Cluster-id as 32 bit quantity\n")
1267 {
1268 VTY_DECLVAR_CONTEXT(bgp, bgp);
1269 bgp_cluster_id_unset(bgp);
1270 bgp_clear_star_soft_out(vty, bgp->name);
1271
1272 return CMD_SUCCESS;
1273 }
1274
1275 DEFUN (bgp_confederation_identifier,
1276 bgp_confederation_identifier_cmd,
1277 "bgp confederation identifier (1-4294967295)",
1278 "BGP specific commands\n"
1279 "AS confederation parameters\n"
1280 "AS number\n"
1281 "Set routing domain confederation AS\n")
1282 {
1283 VTY_DECLVAR_CONTEXT(bgp, bgp);
1284 int idx_number = 3;
1285 as_t as;
1286
1287 as = strtoul(argv[idx_number]->arg, NULL, 10);
1288
1289 bgp_confederation_id_set(bgp, as);
1290
1291 return CMD_SUCCESS;
1292 }
1293
1294 DEFUN (no_bgp_confederation_identifier,
1295 no_bgp_confederation_identifier_cmd,
1296 "no bgp confederation identifier [(1-4294967295)]",
1297 NO_STR
1298 "BGP specific commands\n"
1299 "AS confederation parameters\n"
1300 "AS number\n"
1301 "Set routing domain confederation AS\n")
1302 {
1303 VTY_DECLVAR_CONTEXT(bgp, bgp);
1304 bgp_confederation_id_unset(bgp);
1305
1306 return CMD_SUCCESS;
1307 }
1308
1309 DEFUN (bgp_confederation_peers,
1310 bgp_confederation_peers_cmd,
1311 "bgp confederation peers (1-4294967295)...",
1312 "BGP specific commands\n"
1313 "AS confederation parameters\n"
1314 "Peer ASs in BGP confederation\n"
1315 AS_STR)
1316 {
1317 VTY_DECLVAR_CONTEXT(bgp, bgp);
1318 int idx_asn = 3;
1319 as_t as;
1320 int i;
1321
1322 for (i = idx_asn; i < argc; i++) {
1323 as = strtoul(argv[i]->arg, NULL, 10);
1324
1325 if (bgp->as == as) {
1326 vty_out(vty,
1327 "%% Local member-AS not allowed in confed peer list\n");
1328 continue;
1329 }
1330
1331 bgp_confederation_peers_add(bgp, as);
1332 }
1333 return CMD_SUCCESS;
1334 }
1335
1336 DEFUN (no_bgp_confederation_peers,
1337 no_bgp_confederation_peers_cmd,
1338 "no bgp confederation peers (1-4294967295)...",
1339 NO_STR
1340 "BGP specific commands\n"
1341 "AS confederation parameters\n"
1342 "Peer ASs in BGP confederation\n"
1343 AS_STR)
1344 {
1345 VTY_DECLVAR_CONTEXT(bgp, bgp);
1346 int idx_asn = 4;
1347 as_t as;
1348 int i;
1349
1350 for (i = idx_asn; i < argc; i++) {
1351 as = strtoul(argv[i]->arg, NULL, 10);
1352
1353 bgp_confederation_peers_remove(bgp, as);
1354 }
1355 return CMD_SUCCESS;
1356 }
1357
1358 /**
1359 * Central routine for maximum-paths configuration.
1360 * @peer_type: BGP_PEER_EBGP or BGP_PEER_IBGP
1361 * @set: 1 for setting values, 0 for removing the max-paths config.
1362 */
1363 static int bgp_maxpaths_config_vty(struct vty *vty, int peer_type,
1364 const char *mpaths, uint16_t options,
1365 int set)
1366 {
1367 VTY_DECLVAR_CONTEXT(bgp, bgp);
1368 uint16_t maxpaths = 0;
1369 int ret;
1370 afi_t afi;
1371 safi_t safi;
1372
1373 afi = bgp_node_afi(vty);
1374 safi = bgp_node_safi(vty);
1375
1376 if (set) {
1377 maxpaths = strtol(mpaths, NULL, 10);
1378 if (maxpaths > multipath_num) {
1379 vty_out(vty,
1380 "%% Maxpaths Specified: %d is > than multipath num specified on bgp command line %d",
1381 maxpaths, multipath_num);
1382 return CMD_WARNING_CONFIG_FAILED;
1383 }
1384 ret = bgp_maximum_paths_set(bgp, afi, safi, peer_type, maxpaths,
1385 options);
1386 } else
1387 ret = bgp_maximum_paths_unset(bgp, afi, safi, peer_type);
1388
1389 if (ret < 0) {
1390 vty_out(vty,
1391 "%% Failed to %sset maximum-paths %s %u for afi %u, safi %u\n",
1392 (set == 1) ? "" : "un",
1393 (peer_type == BGP_PEER_EBGP) ? "ebgp" : "ibgp",
1394 maxpaths, afi, safi);
1395 return CMD_WARNING_CONFIG_FAILED;
1396 }
1397
1398 bgp_recalculate_all_bestpaths(bgp);
1399
1400 return CMD_SUCCESS;
1401 }
1402
1403 DEFUN (bgp_maxmed_admin,
1404 bgp_maxmed_admin_cmd,
1405 "bgp max-med administrative ",
1406 BGP_STR
1407 "Advertise routes with max-med\n"
1408 "Administratively applied, for an indefinite period\n")
1409 {
1410 VTY_DECLVAR_CONTEXT(bgp, bgp);
1411
1412 bgp->v_maxmed_admin = 1;
1413 bgp->maxmed_admin_value = BGP_MAXMED_VALUE_DEFAULT;
1414
1415 bgp_maxmed_update(bgp);
1416
1417 return CMD_SUCCESS;
1418 }
1419
1420 DEFUN (bgp_maxmed_admin_medv,
1421 bgp_maxmed_admin_medv_cmd,
1422 "bgp max-med administrative (0-4294967295)",
1423 BGP_STR
1424 "Advertise routes with max-med\n"
1425 "Administratively applied, for an indefinite period\n"
1426 "Max MED value to be used\n")
1427 {
1428 VTY_DECLVAR_CONTEXT(bgp, bgp);
1429 int idx_number = 3;
1430
1431 bgp->v_maxmed_admin = 1;
1432 bgp->maxmed_admin_value = strtoul(argv[idx_number]->arg, NULL, 10);
1433
1434 bgp_maxmed_update(bgp);
1435
1436 return CMD_SUCCESS;
1437 }
1438
1439 DEFUN (no_bgp_maxmed_admin,
1440 no_bgp_maxmed_admin_cmd,
1441 "no bgp max-med administrative [(0-4294967295)]",
1442 NO_STR
1443 BGP_STR
1444 "Advertise routes with max-med\n"
1445 "Administratively applied, for an indefinite period\n"
1446 "Max MED value to be used\n")
1447 {
1448 VTY_DECLVAR_CONTEXT(bgp, bgp);
1449 bgp->v_maxmed_admin = BGP_MAXMED_ADMIN_UNCONFIGURED;
1450 bgp->maxmed_admin_value = BGP_MAXMED_VALUE_DEFAULT;
1451 bgp_maxmed_update(bgp);
1452
1453 return CMD_SUCCESS;
1454 }
1455
1456 DEFUN (bgp_maxmed_onstartup,
1457 bgp_maxmed_onstartup_cmd,
1458 "bgp max-med on-startup (5-86400) [(0-4294967295)]",
1459 BGP_STR
1460 "Advertise routes with max-med\n"
1461 "Effective on a startup\n"
1462 "Time (seconds) period for max-med\n"
1463 "Max MED value to be used\n")
1464 {
1465 VTY_DECLVAR_CONTEXT(bgp, bgp);
1466 int idx = 0;
1467
1468 argv_find(argv, argc, "(5-86400)", &idx);
1469 bgp->v_maxmed_onstartup = strtoul(argv[idx]->arg, NULL, 10);
1470 if (argv_find(argv, argc, "(0-4294967295)", &idx))
1471 bgp->maxmed_onstartup_value = strtoul(argv[idx]->arg, NULL, 10);
1472 else
1473 bgp->maxmed_onstartup_value = BGP_MAXMED_VALUE_DEFAULT;
1474
1475 bgp_maxmed_update(bgp);
1476
1477 return CMD_SUCCESS;
1478 }
1479
1480 DEFUN (no_bgp_maxmed_onstartup,
1481 no_bgp_maxmed_onstartup_cmd,
1482 "no bgp max-med on-startup [(5-86400) [(0-4294967295)]]",
1483 NO_STR
1484 BGP_STR
1485 "Advertise routes with max-med\n"
1486 "Effective on a startup\n"
1487 "Time (seconds) period for max-med\n"
1488 "Max MED value to be used\n")
1489 {
1490 VTY_DECLVAR_CONTEXT(bgp, bgp);
1491
1492 /* Cancel max-med onstartup if its on */
1493 if (bgp->t_maxmed_onstartup) {
1494 THREAD_TIMER_OFF(bgp->t_maxmed_onstartup);
1495 bgp->maxmed_onstartup_over = 1;
1496 }
1497
1498 bgp->v_maxmed_onstartup = BGP_MAXMED_ONSTARTUP_UNCONFIGURED;
1499 bgp->maxmed_onstartup_value = BGP_MAXMED_VALUE_DEFAULT;
1500
1501 bgp_maxmed_update(bgp);
1502
1503 return CMD_SUCCESS;
1504 }
1505
1506 static int bgp_update_delay_config_vty(struct vty *vty, const char *delay,
1507 const char *wait)
1508 {
1509 VTY_DECLVAR_CONTEXT(bgp, bgp);
1510 uint16_t update_delay;
1511 uint16_t establish_wait;
1512
1513 update_delay = strtoul(delay, NULL, 10);
1514
1515 if (!wait) /* update-delay <delay> */
1516 {
1517 bgp->v_update_delay = update_delay;
1518 bgp->v_establish_wait = bgp->v_update_delay;
1519 return CMD_SUCCESS;
1520 }
1521
1522 /* update-delay <delay> <establish-wait> */
1523 establish_wait = atoi(wait);
1524 if (update_delay < establish_wait) {
1525 vty_out(vty,
1526 "%%Failed: update-delay less than the establish-wait!\n");
1527 return CMD_WARNING_CONFIG_FAILED;
1528 }
1529
1530 bgp->v_update_delay = update_delay;
1531 bgp->v_establish_wait = establish_wait;
1532
1533 return CMD_SUCCESS;
1534 }
1535
1536 static int bgp_update_delay_deconfig_vty(struct vty *vty)
1537 {
1538 VTY_DECLVAR_CONTEXT(bgp, bgp);
1539
1540 bgp->v_update_delay = BGP_UPDATE_DELAY_DEF;
1541 bgp->v_establish_wait = bgp->v_update_delay;
1542
1543 return CMD_SUCCESS;
1544 }
1545
1546 void bgp_config_write_update_delay(struct vty *vty, struct bgp *bgp)
1547 {
1548 if (bgp->v_update_delay != BGP_UPDATE_DELAY_DEF) {
1549 vty_out(vty, " update-delay %d", bgp->v_update_delay);
1550 if (bgp->v_update_delay != bgp->v_establish_wait)
1551 vty_out(vty, " %d", bgp->v_establish_wait);
1552 vty_out(vty, "\n");
1553 }
1554 }
1555
1556
1557 /* Update-delay configuration */
1558 DEFUN (bgp_update_delay,
1559 bgp_update_delay_cmd,
1560 "update-delay (0-3600)",
1561 "Force initial delay for best-path and updates\n"
1562 "Seconds\n")
1563 {
1564 int idx_number = 1;
1565 return bgp_update_delay_config_vty(vty, argv[idx_number]->arg, NULL);
1566 }
1567
1568 DEFUN (bgp_update_delay_establish_wait,
1569 bgp_update_delay_establish_wait_cmd,
1570 "update-delay (0-3600) (1-3600)",
1571 "Force initial delay for best-path and updates\n"
1572 "Seconds\n"
1573 "Seconds\n")
1574 {
1575 int idx_number = 1;
1576 int idx_number_2 = 2;
1577 return bgp_update_delay_config_vty(vty, argv[idx_number]->arg,
1578 argv[idx_number_2]->arg);
1579 }
1580
1581 /* Update-delay deconfiguration */
1582 DEFUN (no_bgp_update_delay,
1583 no_bgp_update_delay_cmd,
1584 "no update-delay [(0-3600) [(1-3600)]]",
1585 NO_STR
1586 "Force initial delay for best-path and updates\n"
1587 "Seconds\n"
1588 "Seconds\n")
1589 {
1590 return bgp_update_delay_deconfig_vty(vty);
1591 }
1592
1593
1594 static int bgp_wpkt_quanta_config_vty(struct vty *vty, uint32_t quanta,
1595 bool set)
1596 {
1597 VTY_DECLVAR_CONTEXT(bgp, bgp);
1598
1599 quanta = set ? quanta : BGP_WRITE_PACKET_MAX;
1600 atomic_store_explicit(&bgp->wpkt_quanta, quanta, memory_order_relaxed);
1601
1602 return CMD_SUCCESS;
1603 }
1604
1605 static int bgp_rpkt_quanta_config_vty(struct vty *vty, uint32_t quanta,
1606 bool set)
1607 {
1608 VTY_DECLVAR_CONTEXT(bgp, bgp);
1609
1610 quanta = set ? quanta : BGP_READ_PACKET_MAX;
1611 atomic_store_explicit(&bgp->rpkt_quanta, quanta, memory_order_relaxed);
1612
1613 return CMD_SUCCESS;
1614 }
1615
1616 void bgp_config_write_wpkt_quanta(struct vty *vty, struct bgp *bgp)
1617 {
1618 uint32_t quanta =
1619 atomic_load_explicit(&bgp->wpkt_quanta, memory_order_relaxed);
1620 if (quanta != BGP_WRITE_PACKET_MAX)
1621 vty_out(vty, " write-quanta %d\n", quanta);
1622 }
1623
1624 void bgp_config_write_rpkt_quanta(struct vty *vty, struct bgp *bgp)
1625 {
1626 uint32_t quanta =
1627 atomic_load_explicit(&bgp->rpkt_quanta, memory_order_relaxed);
1628 if (quanta != BGP_READ_PACKET_MAX)
1629 vty_out(vty, " read-quanta %d\n", quanta);
1630 }
1631
1632 /* Packet quanta configuration
1633 *
1634 * XXX: The value set here controls the size of a stack buffer in the IO
1635 * thread. When changing these limits be careful to prevent stack overflow.
1636 *
1637 * Furthermore, the maximums used here should correspond to
1638 * BGP_WRITE_PACKET_MAX and BGP_READ_PACKET_MAX.
1639 */
1640 DEFPY (bgp_wpkt_quanta,
1641 bgp_wpkt_quanta_cmd,
1642 "[no] write-quanta (1-64)$quanta",
1643 NO_STR
1644 "How many packets to write to peer socket per run\n"
1645 "Number of packets\n")
1646 {
1647 return bgp_wpkt_quanta_config_vty(vty, quanta, !no);
1648 }
1649
1650 DEFPY (bgp_rpkt_quanta,
1651 bgp_rpkt_quanta_cmd,
1652 "[no] read-quanta (1-10)$quanta",
1653 NO_STR
1654 "How many packets to read from peer socket per I/O cycle\n"
1655 "Number of packets\n")
1656 {
1657 return bgp_rpkt_quanta_config_vty(vty, quanta, !no);
1658 }
1659
1660 void bgp_config_write_coalesce_time(struct vty *vty, struct bgp *bgp)
1661 {
1662 if (!bgp->heuristic_coalesce)
1663 vty_out(vty, " coalesce-time %u\n", bgp->coalesce_time);
1664 }
1665
1666
1667 DEFUN (bgp_coalesce_time,
1668 bgp_coalesce_time_cmd,
1669 "coalesce-time (0-4294967295)",
1670 "Subgroup coalesce timer\n"
1671 "Subgroup coalesce timer value (in ms)\n")
1672 {
1673 VTY_DECLVAR_CONTEXT(bgp, bgp);
1674
1675 int idx = 0;
1676 argv_find(argv, argc, "(0-4294967295)", &idx);
1677 bgp->heuristic_coalesce = false;
1678 bgp->coalesce_time = strtoul(argv[idx]->arg, NULL, 10);
1679 return CMD_SUCCESS;
1680 }
1681
1682 DEFUN (no_bgp_coalesce_time,
1683 no_bgp_coalesce_time_cmd,
1684 "no coalesce-time (0-4294967295)",
1685 NO_STR
1686 "Subgroup coalesce timer\n"
1687 "Subgroup coalesce timer value (in ms)\n")
1688 {
1689 VTY_DECLVAR_CONTEXT(bgp, bgp);
1690
1691 bgp->heuristic_coalesce = true;
1692 bgp->coalesce_time = BGP_DEFAULT_SUBGROUP_COALESCE_TIME;
1693 return CMD_SUCCESS;
1694 }
1695
1696 /* Maximum-paths configuration */
1697 DEFUN (bgp_maxpaths,
1698 bgp_maxpaths_cmd,
1699 "maximum-paths " CMD_RANGE_STR(1, MULTIPATH_NUM),
1700 "Forward packets over multiple paths\n"
1701 "Number of paths\n")
1702 {
1703 int idx_number = 1;
1704 return bgp_maxpaths_config_vty(vty, BGP_PEER_EBGP,
1705 argv[idx_number]->arg, 0, 1);
1706 }
1707
1708 ALIAS_HIDDEN(bgp_maxpaths, bgp_maxpaths_hidden_cmd,
1709 "maximum-paths " CMD_RANGE_STR(1, MULTIPATH_NUM),
1710 "Forward packets over multiple paths\n"
1711 "Number of paths\n")
1712
1713 DEFUN (bgp_maxpaths_ibgp,
1714 bgp_maxpaths_ibgp_cmd,
1715 "maximum-paths ibgp " CMD_RANGE_STR(1, MULTIPATH_NUM),
1716 "Forward packets over multiple paths\n"
1717 "iBGP-multipath\n"
1718 "Number of paths\n")
1719 {
1720 int idx_number = 2;
1721 return bgp_maxpaths_config_vty(vty, BGP_PEER_IBGP,
1722 argv[idx_number]->arg, 0, 1);
1723 }
1724
1725 ALIAS_HIDDEN(bgp_maxpaths_ibgp, bgp_maxpaths_ibgp_hidden_cmd,
1726 "maximum-paths ibgp " CMD_RANGE_STR(1, MULTIPATH_NUM),
1727 "Forward packets over multiple paths\n"
1728 "iBGP-multipath\n"
1729 "Number of paths\n")
1730
1731 DEFUN (bgp_maxpaths_ibgp_cluster,
1732 bgp_maxpaths_ibgp_cluster_cmd,
1733 "maximum-paths ibgp " CMD_RANGE_STR(1, MULTIPATH_NUM) " equal-cluster-length",
1734 "Forward packets over multiple paths\n"
1735 "iBGP-multipath\n"
1736 "Number of paths\n"
1737 "Match the cluster length\n")
1738 {
1739 int idx_number = 2;
1740 return bgp_maxpaths_config_vty(
1741 vty, BGP_PEER_IBGP, argv[idx_number]->arg,
1742 BGP_FLAG_IBGP_MULTIPATH_SAME_CLUSTERLEN, 1);
1743 }
1744
1745 ALIAS_HIDDEN(bgp_maxpaths_ibgp_cluster, bgp_maxpaths_ibgp_cluster_hidden_cmd,
1746 "maximum-paths ibgp " CMD_RANGE_STR(
1747 1, MULTIPATH_NUM) " equal-cluster-length",
1748 "Forward packets over multiple paths\n"
1749 "iBGP-multipath\n"
1750 "Number of paths\n"
1751 "Match the cluster length\n")
1752
1753 DEFUN (no_bgp_maxpaths,
1754 no_bgp_maxpaths_cmd,
1755 "no maximum-paths [" CMD_RANGE_STR(1, MULTIPATH_NUM) "]",
1756 NO_STR
1757 "Forward packets over multiple paths\n"
1758 "Number of paths\n")
1759 {
1760 return bgp_maxpaths_config_vty(vty, BGP_PEER_EBGP, NULL, 0, 0);
1761 }
1762
1763 ALIAS_HIDDEN(no_bgp_maxpaths, no_bgp_maxpaths_hidden_cmd,
1764 "no maximum-paths [" CMD_RANGE_STR(1, MULTIPATH_NUM) "]", NO_STR
1765 "Forward packets over multiple paths\n"
1766 "Number of paths\n")
1767
1768 DEFUN (no_bgp_maxpaths_ibgp,
1769 no_bgp_maxpaths_ibgp_cmd,
1770 "no maximum-paths ibgp [" CMD_RANGE_STR(1, MULTIPATH_NUM) " [equal-cluster-length]]",
1771 NO_STR
1772 "Forward packets over multiple paths\n"
1773 "iBGP-multipath\n"
1774 "Number of paths\n"
1775 "Match the cluster length\n")
1776 {
1777 return bgp_maxpaths_config_vty(vty, BGP_PEER_IBGP, NULL, 0, 0);
1778 }
1779
1780 ALIAS_HIDDEN(no_bgp_maxpaths_ibgp, no_bgp_maxpaths_ibgp_hidden_cmd,
1781 "no maximum-paths ibgp [" CMD_RANGE_STR(
1782 1, MULTIPATH_NUM) " [equal-cluster-length]]",
1783 NO_STR
1784 "Forward packets over multiple paths\n"
1785 "iBGP-multipath\n"
1786 "Number of paths\n"
1787 "Match the cluster length\n")
1788
1789 static void bgp_config_write_maxpaths(struct vty *vty, struct bgp *bgp,
1790 afi_t afi, safi_t safi)
1791 {
1792 if (bgp->maxpaths[afi][safi].maxpaths_ebgp != MULTIPATH_NUM) {
1793 vty_out(vty, " maximum-paths %d\n",
1794 bgp->maxpaths[afi][safi].maxpaths_ebgp);
1795 }
1796
1797 if (bgp->maxpaths[afi][safi].maxpaths_ibgp != MULTIPATH_NUM) {
1798 vty_out(vty, " maximum-paths ibgp %d",
1799 bgp->maxpaths[afi][safi].maxpaths_ibgp);
1800 if (CHECK_FLAG(bgp->maxpaths[afi][safi].ibgp_flags,
1801 BGP_FLAG_IBGP_MULTIPATH_SAME_CLUSTERLEN))
1802 vty_out(vty, " equal-cluster-length");
1803 vty_out(vty, "\n");
1804 }
1805 }
1806
1807 /* BGP timers. */
1808
1809 DEFUN (bgp_timers,
1810 bgp_timers_cmd,
1811 "timers bgp (0-65535) (0-65535)",
1812 "Adjust routing timers\n"
1813 "BGP timers\n"
1814 "Keepalive interval\n"
1815 "Holdtime\n")
1816 {
1817 VTY_DECLVAR_CONTEXT(bgp, bgp);
1818 int idx_number = 2;
1819 int idx_number_2 = 3;
1820 unsigned long keepalive = 0;
1821 unsigned long holdtime = 0;
1822
1823 keepalive = strtoul(argv[idx_number]->arg, NULL, 10);
1824 holdtime = strtoul(argv[idx_number_2]->arg, NULL, 10);
1825
1826 /* Holdtime value check. */
1827 if (holdtime < 3 && holdtime != 0) {
1828 vty_out(vty,
1829 "%% hold time value must be either 0 or greater than 3\n");
1830 return CMD_WARNING_CONFIG_FAILED;
1831 }
1832
1833 bgp_timers_set(bgp, keepalive, holdtime);
1834
1835 return CMD_SUCCESS;
1836 }
1837
1838 DEFUN (no_bgp_timers,
1839 no_bgp_timers_cmd,
1840 "no timers bgp [(0-65535) (0-65535)]",
1841 NO_STR
1842 "Adjust routing timers\n"
1843 "BGP timers\n"
1844 "Keepalive interval\n"
1845 "Holdtime\n")
1846 {
1847 VTY_DECLVAR_CONTEXT(bgp, bgp);
1848 bgp_timers_unset(bgp);
1849
1850 return CMD_SUCCESS;
1851 }
1852
1853
1854 DEFUN (bgp_client_to_client_reflection,
1855 bgp_client_to_client_reflection_cmd,
1856 "bgp client-to-client reflection",
1857 "BGP specific commands\n"
1858 "Configure client to client route reflection\n"
1859 "reflection of routes allowed\n")
1860 {
1861 VTY_DECLVAR_CONTEXT(bgp, bgp);
1862 bgp_flag_unset(bgp, BGP_FLAG_NO_CLIENT_TO_CLIENT);
1863 bgp_clear_star_soft_out(vty, bgp->name);
1864
1865 return CMD_SUCCESS;
1866 }
1867
1868 DEFUN (no_bgp_client_to_client_reflection,
1869 no_bgp_client_to_client_reflection_cmd,
1870 "no bgp client-to-client reflection",
1871 NO_STR
1872 "BGP specific commands\n"
1873 "Configure client to client route reflection\n"
1874 "reflection of routes allowed\n")
1875 {
1876 VTY_DECLVAR_CONTEXT(bgp, bgp);
1877 bgp_flag_set(bgp, BGP_FLAG_NO_CLIENT_TO_CLIENT);
1878 bgp_clear_star_soft_out(vty, bgp->name);
1879
1880 return CMD_SUCCESS;
1881 }
1882
1883 /* "bgp always-compare-med" configuration. */
1884 DEFUN (bgp_always_compare_med,
1885 bgp_always_compare_med_cmd,
1886 "bgp always-compare-med",
1887 "BGP specific commands\n"
1888 "Allow comparing MED from different neighbors\n")
1889 {
1890 VTY_DECLVAR_CONTEXT(bgp, bgp);
1891 bgp_flag_set(bgp, BGP_FLAG_ALWAYS_COMPARE_MED);
1892 bgp_recalculate_all_bestpaths(bgp);
1893
1894 return CMD_SUCCESS;
1895 }
1896
1897 DEFUN (no_bgp_always_compare_med,
1898 no_bgp_always_compare_med_cmd,
1899 "no bgp always-compare-med",
1900 NO_STR
1901 "BGP specific commands\n"
1902 "Allow comparing MED from different neighbors\n")
1903 {
1904 VTY_DECLVAR_CONTEXT(bgp, bgp);
1905 bgp_flag_unset(bgp, BGP_FLAG_ALWAYS_COMPARE_MED);
1906 bgp_recalculate_all_bestpaths(bgp);
1907
1908 return CMD_SUCCESS;
1909 }
1910
1911
1912 DEFUN(bgp_ebgp_requires_policy, bgp_ebgp_requires_policy_cmd,
1913 "bgp ebgp-requires-policy",
1914 "BGP specific commands\n"
1915 "Require in and out policy for eBGP peers (RFC8212)\n")
1916 {
1917 VTY_DECLVAR_CONTEXT(bgp, bgp);
1918 bgp->ebgp_requires_policy = DEFAULT_EBGP_POLICY_ENABLED;
1919 return CMD_SUCCESS;
1920 }
1921
1922 DEFUN(no_bgp_ebgp_requires_policy, no_bgp_ebgp_requires_policy_cmd,
1923 "no bgp ebgp-requires-policy",
1924 NO_STR
1925 "BGP specific commands\n"
1926 "Require in and out policy for eBGP peers (RFC8212)\n")
1927 {
1928 VTY_DECLVAR_CONTEXT(bgp, bgp);
1929 bgp->ebgp_requires_policy = DEFAULT_EBGP_POLICY_DISABLED;
1930 return CMD_SUCCESS;
1931 }
1932
1933 DEFUN(bgp_reject_as_sets, bgp_reject_as_sets_cmd,
1934 "bgp reject-as-sets",
1935 "BGP specific commands\n"
1936 "Reject routes with AS_SET or AS_CONFED_SET flag\n")
1937 {
1938 VTY_DECLVAR_CONTEXT(bgp, bgp);
1939 struct listnode *node, *nnode;
1940 struct peer *peer;
1941
1942 bgp->reject_as_sets = BGP_REJECT_AS_SETS_ENABLED;
1943
1944 /* Reset existing BGP sessions to reject routes
1945 * with aspath containing AS_SET or AS_CONFED_SET.
1946 */
1947 for (ALL_LIST_ELEMENTS(bgp->peer, node, nnode, peer)) {
1948 if (BGP_IS_VALID_STATE_FOR_NOTIF(peer->status)) {
1949 peer->last_reset = PEER_DOWN_AS_SETS_REJECT;
1950 bgp_notify_send(peer, BGP_NOTIFY_CEASE,
1951 BGP_NOTIFY_CEASE_CONFIG_CHANGE);
1952 }
1953 }
1954
1955 return CMD_SUCCESS;
1956 }
1957
1958 DEFUN(no_bgp_reject_as_sets, no_bgp_reject_as_sets_cmd,
1959 "no bgp reject-as-sets",
1960 NO_STR
1961 "BGP specific commands\n"
1962 "Reject routes with AS_SET or AS_CONFED_SET flag\n")
1963 {
1964 VTY_DECLVAR_CONTEXT(bgp, bgp);
1965 struct listnode *node, *nnode;
1966 struct peer *peer;
1967
1968 bgp->reject_as_sets = BGP_REJECT_AS_SETS_DISABLED;
1969
1970 /* Reset existing BGP sessions to reject routes
1971 * with aspath containing AS_SET or AS_CONFED_SET.
1972 */
1973 for (ALL_LIST_ELEMENTS(bgp->peer, node, nnode, peer)) {
1974 if (BGP_IS_VALID_STATE_FOR_NOTIF(peer->status)) {
1975 peer->last_reset = PEER_DOWN_AS_SETS_REJECT;
1976 bgp_notify_send(peer, BGP_NOTIFY_CEASE,
1977 BGP_NOTIFY_CEASE_CONFIG_CHANGE);
1978 }
1979 }
1980
1981 return CMD_SUCCESS;
1982 }
1983
1984 /* "bgp deterministic-med" configuration. */
1985 DEFUN (bgp_deterministic_med,
1986 bgp_deterministic_med_cmd,
1987 "bgp deterministic-med",
1988 "BGP specific commands\n"
1989 "Pick the best-MED path among paths advertised from the neighboring AS\n")
1990 {
1991 VTY_DECLVAR_CONTEXT(bgp, bgp);
1992
1993 if (!bgp_flag_check(bgp, BGP_FLAG_DETERMINISTIC_MED)) {
1994 bgp_flag_set(bgp, BGP_FLAG_DETERMINISTIC_MED);
1995 bgp_recalculate_all_bestpaths(bgp);
1996 }
1997
1998 return CMD_SUCCESS;
1999 }
2000
2001 DEFUN (no_bgp_deterministic_med,
2002 no_bgp_deterministic_med_cmd,
2003 "no bgp deterministic-med",
2004 NO_STR
2005 "BGP specific commands\n"
2006 "Pick the best-MED path among paths advertised from the neighboring AS\n")
2007 {
2008 VTY_DECLVAR_CONTEXT(bgp, bgp);
2009 int bestpath_per_as_used;
2010 afi_t afi;
2011 safi_t safi;
2012 struct peer *peer;
2013 struct listnode *node, *nnode;
2014
2015 if (bgp_flag_check(bgp, BGP_FLAG_DETERMINISTIC_MED)) {
2016 bestpath_per_as_used = 0;
2017
2018 for (ALL_LIST_ELEMENTS(bgp->peer, node, nnode, peer)) {
2019 FOREACH_AFI_SAFI (afi, safi)
2020 if (bgp_addpath_dmed_required(
2021 peer->addpath_type[afi][safi])) {
2022 bestpath_per_as_used = 1;
2023 break;
2024 }
2025
2026 if (bestpath_per_as_used)
2027 break;
2028 }
2029
2030 if (bestpath_per_as_used) {
2031 vty_out(vty,
2032 "bgp deterministic-med cannot be disabled while addpath-tx-bestpath-per-AS is in use\n");
2033 return CMD_WARNING_CONFIG_FAILED;
2034 } else {
2035 bgp_flag_unset(bgp, BGP_FLAG_DETERMINISTIC_MED);
2036 bgp_recalculate_all_bestpaths(bgp);
2037 }
2038 }
2039
2040 return CMD_SUCCESS;
2041 }
2042
2043 /* "bgp graceful-restart" configuration. */
2044 DEFUN (bgp_graceful_restart,
2045 bgp_graceful_restart_cmd,
2046 "bgp graceful-restart",
2047 "BGP specific commands\n"
2048 "Graceful restart capability parameters\n")
2049 {
2050 VTY_DECLVAR_CONTEXT(bgp, bgp);
2051 bgp_flag_set(bgp, BGP_FLAG_GRACEFUL_RESTART);
2052 return CMD_SUCCESS;
2053 }
2054
2055 DEFUN (no_bgp_graceful_restart,
2056 no_bgp_graceful_restart_cmd,
2057 "no bgp graceful-restart",
2058 NO_STR
2059 "BGP specific commands\n"
2060 "Graceful restart capability parameters\n")
2061 {
2062 VTY_DECLVAR_CONTEXT(bgp, bgp);
2063 bgp_flag_unset(bgp, BGP_FLAG_GRACEFUL_RESTART);
2064 return CMD_SUCCESS;
2065 }
2066
2067 DEFUN (bgp_graceful_restart_stalepath_time,
2068 bgp_graceful_restart_stalepath_time_cmd,
2069 "bgp graceful-restart stalepath-time (1-4095)",
2070 "BGP specific commands\n"
2071 "Graceful restart capability parameters\n"
2072 "Set the max time to hold onto restarting peer's stale paths\n"
2073 "Delay value (seconds)\n")
2074 {
2075 VTY_DECLVAR_CONTEXT(bgp, bgp);
2076 int idx_number = 3;
2077 uint32_t stalepath;
2078
2079 stalepath = strtoul(argv[idx_number]->arg, NULL, 10);
2080 bgp->stalepath_time = stalepath;
2081 return CMD_SUCCESS;
2082 }
2083
2084 DEFUN (bgp_graceful_restart_restart_time,
2085 bgp_graceful_restart_restart_time_cmd,
2086 "bgp graceful-restart restart-time (1-4095)",
2087 "BGP specific commands\n"
2088 "Graceful restart capability parameters\n"
2089 "Set the time to wait to delete stale routes before a BGP open message is received\n"
2090 "Delay value (seconds)\n")
2091 {
2092 VTY_DECLVAR_CONTEXT(bgp, bgp);
2093 int idx_number = 3;
2094 uint32_t restart;
2095
2096 restart = strtoul(argv[idx_number]->arg, NULL, 10);
2097 bgp->restart_time = restart;
2098 return CMD_SUCCESS;
2099 }
2100
2101 DEFUN (no_bgp_graceful_restart_stalepath_time,
2102 no_bgp_graceful_restart_stalepath_time_cmd,
2103 "no bgp graceful-restart stalepath-time [(1-4095)]",
2104 NO_STR
2105 "BGP specific commands\n"
2106 "Graceful restart capability parameters\n"
2107 "Set the max time to hold onto restarting peer's stale paths\n"
2108 "Delay value (seconds)\n")
2109 {
2110 VTY_DECLVAR_CONTEXT(bgp, bgp);
2111
2112 bgp->stalepath_time = BGP_DEFAULT_STALEPATH_TIME;
2113 return CMD_SUCCESS;
2114 }
2115
2116 DEFUN (no_bgp_graceful_restart_restart_time,
2117 no_bgp_graceful_restart_restart_time_cmd,
2118 "no bgp graceful-restart restart-time [(1-4095)]",
2119 NO_STR
2120 "BGP specific commands\n"
2121 "Graceful restart capability parameters\n"
2122 "Set the time to wait to delete stale routes before a BGP open message is received\n"
2123 "Delay value (seconds)\n")
2124 {
2125 VTY_DECLVAR_CONTEXT(bgp, bgp);
2126
2127 bgp->restart_time = BGP_DEFAULT_RESTART_TIME;
2128 return CMD_SUCCESS;
2129 }
2130
2131 DEFUN (bgp_graceful_restart_preserve_fw,
2132 bgp_graceful_restart_preserve_fw_cmd,
2133 "bgp graceful-restart preserve-fw-state",
2134 "BGP specific commands\n"
2135 "Graceful restart capability parameters\n"
2136 "Sets F-bit indication that fib is preserved while doing Graceful Restart\n")
2137 {
2138 VTY_DECLVAR_CONTEXT(bgp, bgp);
2139 bgp_flag_set(bgp, BGP_FLAG_GR_PRESERVE_FWD);
2140 return CMD_SUCCESS;
2141 }
2142
2143 DEFUN (no_bgp_graceful_restart_preserve_fw,
2144 no_bgp_graceful_restart_preserve_fw_cmd,
2145 "no bgp graceful-restart preserve-fw-state",
2146 NO_STR
2147 "BGP specific commands\n"
2148 "Graceful restart capability parameters\n"
2149 "Unsets F-bit indication that fib is preserved while doing Graceful Restart\n")
2150 {
2151 VTY_DECLVAR_CONTEXT(bgp, bgp);
2152 bgp_flag_unset(bgp, BGP_FLAG_GR_PRESERVE_FWD);
2153 return CMD_SUCCESS;
2154 }
2155
2156 /* "bgp graceful-shutdown" configuration */
2157 DEFUN (bgp_graceful_shutdown,
2158 bgp_graceful_shutdown_cmd,
2159 "bgp graceful-shutdown",
2160 BGP_STR
2161 "Graceful shutdown parameters\n")
2162 {
2163 VTY_DECLVAR_CONTEXT(bgp, bgp);
2164
2165 if (!bgp_flag_check(bgp, BGP_FLAG_GRACEFUL_SHUTDOWN)) {
2166 bgp_flag_set(bgp, BGP_FLAG_GRACEFUL_SHUTDOWN);
2167 bgp_static_redo_import_check(bgp);
2168 bgp_redistribute_redo(bgp);
2169 bgp_clear_star_soft_out(vty, bgp->name);
2170 bgp_clear_star_soft_in(vty, bgp->name);
2171 }
2172
2173 return CMD_SUCCESS;
2174 }
2175
2176 DEFUN (no_bgp_graceful_shutdown,
2177 no_bgp_graceful_shutdown_cmd,
2178 "no bgp graceful-shutdown",
2179 NO_STR
2180 BGP_STR
2181 "Graceful shutdown parameters\n")
2182 {
2183 VTY_DECLVAR_CONTEXT(bgp, bgp);
2184
2185 if (bgp_flag_check(bgp, BGP_FLAG_GRACEFUL_SHUTDOWN)) {
2186 bgp_flag_unset(bgp, BGP_FLAG_GRACEFUL_SHUTDOWN);
2187 bgp_static_redo_import_check(bgp);
2188 bgp_redistribute_redo(bgp);
2189 bgp_clear_star_soft_out(vty, bgp->name);
2190 bgp_clear_star_soft_in(vty, bgp->name);
2191 }
2192
2193 return CMD_SUCCESS;
2194 }
2195
2196 /* "bgp fast-external-failover" configuration. */
2197 DEFUN (bgp_fast_external_failover,
2198 bgp_fast_external_failover_cmd,
2199 "bgp fast-external-failover",
2200 BGP_STR
2201 "Immediately reset session if a link to a directly connected external peer goes down\n")
2202 {
2203 VTY_DECLVAR_CONTEXT(bgp, bgp);
2204 bgp_flag_unset(bgp, BGP_FLAG_NO_FAST_EXT_FAILOVER);
2205 return CMD_SUCCESS;
2206 }
2207
2208 DEFUN (no_bgp_fast_external_failover,
2209 no_bgp_fast_external_failover_cmd,
2210 "no bgp fast-external-failover",
2211 NO_STR
2212 BGP_STR
2213 "Immediately reset session if a link to a directly connected external peer goes down\n")
2214 {
2215 VTY_DECLVAR_CONTEXT(bgp, bgp);
2216 bgp_flag_set(bgp, BGP_FLAG_NO_FAST_EXT_FAILOVER);
2217 return CMD_SUCCESS;
2218 }
2219
2220 /* "bgp bestpath compare-routerid" configuration. */
2221 DEFUN (bgp_bestpath_compare_router_id,
2222 bgp_bestpath_compare_router_id_cmd,
2223 "bgp bestpath compare-routerid",
2224 "BGP specific commands\n"
2225 "Change the default bestpath selection\n"
2226 "Compare router-id for identical EBGP paths\n")
2227 {
2228 VTY_DECLVAR_CONTEXT(bgp, bgp);
2229 bgp_flag_set(bgp, BGP_FLAG_COMPARE_ROUTER_ID);
2230 bgp_recalculate_all_bestpaths(bgp);
2231
2232 return CMD_SUCCESS;
2233 }
2234
2235 DEFUN (no_bgp_bestpath_compare_router_id,
2236 no_bgp_bestpath_compare_router_id_cmd,
2237 "no bgp bestpath compare-routerid",
2238 NO_STR
2239 "BGP specific commands\n"
2240 "Change the default bestpath selection\n"
2241 "Compare router-id for identical EBGP paths\n")
2242 {
2243 VTY_DECLVAR_CONTEXT(bgp, bgp);
2244 bgp_flag_unset(bgp, BGP_FLAG_COMPARE_ROUTER_ID);
2245 bgp_recalculate_all_bestpaths(bgp);
2246
2247 return CMD_SUCCESS;
2248 }
2249
2250 /* "bgp bestpath as-path ignore" configuration. */
2251 DEFUN (bgp_bestpath_aspath_ignore,
2252 bgp_bestpath_aspath_ignore_cmd,
2253 "bgp bestpath as-path ignore",
2254 "BGP specific commands\n"
2255 "Change the default bestpath selection\n"
2256 "AS-path attribute\n"
2257 "Ignore as-path length in selecting a route\n")
2258 {
2259 VTY_DECLVAR_CONTEXT(bgp, bgp);
2260 bgp_flag_set(bgp, BGP_FLAG_ASPATH_IGNORE);
2261 bgp_recalculate_all_bestpaths(bgp);
2262
2263 return CMD_SUCCESS;
2264 }
2265
2266 DEFUN (no_bgp_bestpath_aspath_ignore,
2267 no_bgp_bestpath_aspath_ignore_cmd,
2268 "no bgp bestpath as-path ignore",
2269 NO_STR
2270 "BGP specific commands\n"
2271 "Change the default bestpath selection\n"
2272 "AS-path attribute\n"
2273 "Ignore as-path length in selecting a route\n")
2274 {
2275 VTY_DECLVAR_CONTEXT(bgp, bgp);
2276 bgp_flag_unset(bgp, BGP_FLAG_ASPATH_IGNORE);
2277 bgp_recalculate_all_bestpaths(bgp);
2278
2279 return CMD_SUCCESS;
2280 }
2281
2282 /* "bgp bestpath as-path confed" configuration. */
2283 DEFUN (bgp_bestpath_aspath_confed,
2284 bgp_bestpath_aspath_confed_cmd,
2285 "bgp bestpath as-path confed",
2286 "BGP specific commands\n"
2287 "Change the default bestpath selection\n"
2288 "AS-path attribute\n"
2289 "Compare path lengths including confederation sets & sequences in selecting a route\n")
2290 {
2291 VTY_DECLVAR_CONTEXT(bgp, bgp);
2292 bgp_flag_set(bgp, BGP_FLAG_ASPATH_CONFED);
2293 bgp_recalculate_all_bestpaths(bgp);
2294
2295 return CMD_SUCCESS;
2296 }
2297
2298 DEFUN (no_bgp_bestpath_aspath_confed,
2299 no_bgp_bestpath_aspath_confed_cmd,
2300 "no bgp bestpath as-path confed",
2301 NO_STR
2302 "BGP specific commands\n"
2303 "Change the default bestpath selection\n"
2304 "AS-path attribute\n"
2305 "Compare path lengths including confederation sets & sequences in selecting a route\n")
2306 {
2307 VTY_DECLVAR_CONTEXT(bgp, bgp);
2308 bgp_flag_unset(bgp, BGP_FLAG_ASPATH_CONFED);
2309 bgp_recalculate_all_bestpaths(bgp);
2310
2311 return CMD_SUCCESS;
2312 }
2313
2314 /* "bgp bestpath as-path multipath-relax" configuration. */
2315 DEFUN (bgp_bestpath_aspath_multipath_relax,
2316 bgp_bestpath_aspath_multipath_relax_cmd,
2317 "bgp bestpath as-path multipath-relax [<as-set|no-as-set>]",
2318 "BGP specific commands\n"
2319 "Change the default bestpath selection\n"
2320 "AS-path attribute\n"
2321 "Allow load sharing across routes that have different AS paths (but same length)\n"
2322 "Generate an AS_SET\n"
2323 "Do not generate an AS_SET\n")
2324 {
2325 VTY_DECLVAR_CONTEXT(bgp, bgp);
2326 int idx = 0;
2327 bgp_flag_set(bgp, BGP_FLAG_ASPATH_MULTIPATH_RELAX);
2328
2329 /* no-as-set is now the default behavior so we can silently
2330 * ignore it */
2331 if (argv_find(argv, argc, "as-set", &idx))
2332 bgp_flag_set(bgp, BGP_FLAG_MULTIPATH_RELAX_AS_SET);
2333 else
2334 bgp_flag_unset(bgp, BGP_FLAG_MULTIPATH_RELAX_AS_SET);
2335
2336 bgp_recalculate_all_bestpaths(bgp);
2337
2338 return CMD_SUCCESS;
2339 }
2340
2341 DEFUN (no_bgp_bestpath_aspath_multipath_relax,
2342 no_bgp_bestpath_aspath_multipath_relax_cmd,
2343 "no bgp bestpath as-path multipath-relax [<as-set|no-as-set>]",
2344 NO_STR
2345 "BGP specific commands\n"
2346 "Change the default bestpath selection\n"
2347 "AS-path attribute\n"
2348 "Allow load sharing across routes that have different AS paths (but same length)\n"
2349 "Generate an AS_SET\n"
2350 "Do not generate an AS_SET\n")
2351 {
2352 VTY_DECLVAR_CONTEXT(bgp, bgp);
2353 bgp_flag_unset(bgp, BGP_FLAG_ASPATH_MULTIPATH_RELAX);
2354 bgp_flag_unset(bgp, BGP_FLAG_MULTIPATH_RELAX_AS_SET);
2355 bgp_recalculate_all_bestpaths(bgp);
2356
2357 return CMD_SUCCESS;
2358 }
2359
2360 /* "bgp log-neighbor-changes" configuration. */
2361 DEFUN (bgp_log_neighbor_changes,
2362 bgp_log_neighbor_changes_cmd,
2363 "bgp log-neighbor-changes",
2364 "BGP specific commands\n"
2365 "Log neighbor up/down and reset reason\n")
2366 {
2367 VTY_DECLVAR_CONTEXT(bgp, bgp);
2368 bgp_flag_set(bgp, BGP_FLAG_LOG_NEIGHBOR_CHANGES);
2369 return CMD_SUCCESS;
2370 }
2371
2372 DEFUN (no_bgp_log_neighbor_changes,
2373 no_bgp_log_neighbor_changes_cmd,
2374 "no bgp log-neighbor-changes",
2375 NO_STR
2376 "BGP specific commands\n"
2377 "Log neighbor up/down and reset reason\n")
2378 {
2379 VTY_DECLVAR_CONTEXT(bgp, bgp);
2380 bgp_flag_unset(bgp, BGP_FLAG_LOG_NEIGHBOR_CHANGES);
2381 return CMD_SUCCESS;
2382 }
2383
2384 /* "bgp bestpath med" configuration. */
2385 DEFUN (bgp_bestpath_med,
2386 bgp_bestpath_med_cmd,
2387 "bgp bestpath med <confed [missing-as-worst]|missing-as-worst [confed]>",
2388 "BGP specific commands\n"
2389 "Change the default bestpath selection\n"
2390 "MED attribute\n"
2391 "Compare MED among confederation paths\n"
2392 "Treat missing MED as the least preferred one\n"
2393 "Treat missing MED as the least preferred one\n"
2394 "Compare MED among confederation paths\n")
2395 {
2396 VTY_DECLVAR_CONTEXT(bgp, bgp);
2397
2398 int idx = 0;
2399 if (argv_find(argv, argc, "confed", &idx))
2400 bgp_flag_set(bgp, BGP_FLAG_MED_CONFED);
2401 idx = 0;
2402 if (argv_find(argv, argc, "missing-as-worst", &idx))
2403 bgp_flag_set(bgp, BGP_FLAG_MED_MISSING_AS_WORST);
2404
2405 bgp_recalculate_all_bestpaths(bgp);
2406
2407 return CMD_SUCCESS;
2408 }
2409
2410 DEFUN (no_bgp_bestpath_med,
2411 no_bgp_bestpath_med_cmd,
2412 "no bgp bestpath med <confed [missing-as-worst]|missing-as-worst [confed]>",
2413 NO_STR
2414 "BGP specific commands\n"
2415 "Change the default bestpath selection\n"
2416 "MED attribute\n"
2417 "Compare MED among confederation paths\n"
2418 "Treat missing MED as the least preferred one\n"
2419 "Treat missing MED as the least preferred one\n"
2420 "Compare MED among confederation paths\n")
2421 {
2422 VTY_DECLVAR_CONTEXT(bgp, bgp);
2423
2424 int idx = 0;
2425 if (argv_find(argv, argc, "confed", &idx))
2426 bgp_flag_unset(bgp, BGP_FLAG_MED_CONFED);
2427 idx = 0;
2428 if (argv_find(argv, argc, "missing-as-worst", &idx))
2429 bgp_flag_unset(bgp, BGP_FLAG_MED_MISSING_AS_WORST);
2430
2431 bgp_recalculate_all_bestpaths(bgp);
2432
2433 return CMD_SUCCESS;
2434 }
2435
2436 /* "no bgp default ipv4-unicast". */
2437 DEFUN (no_bgp_default_ipv4_unicast,
2438 no_bgp_default_ipv4_unicast_cmd,
2439 "no bgp default ipv4-unicast",
2440 NO_STR
2441 "BGP specific commands\n"
2442 "Configure BGP defaults\n"
2443 "Activate ipv4-unicast for a peer by default\n")
2444 {
2445 VTY_DECLVAR_CONTEXT(bgp, bgp);
2446 bgp_flag_set(bgp, BGP_FLAG_NO_DEFAULT_IPV4);
2447 return CMD_SUCCESS;
2448 }
2449
2450 DEFUN (bgp_default_ipv4_unicast,
2451 bgp_default_ipv4_unicast_cmd,
2452 "bgp default ipv4-unicast",
2453 "BGP specific commands\n"
2454 "Configure BGP defaults\n"
2455 "Activate ipv4-unicast for a peer by default\n")
2456 {
2457 VTY_DECLVAR_CONTEXT(bgp, bgp);
2458 bgp_flag_unset(bgp, BGP_FLAG_NO_DEFAULT_IPV4);
2459 return CMD_SUCCESS;
2460 }
2461
2462 /* Display hostname in certain command outputs */
2463 DEFUN (bgp_default_show_hostname,
2464 bgp_default_show_hostname_cmd,
2465 "bgp default show-hostname",
2466 "BGP specific commands\n"
2467 "Configure BGP defaults\n"
2468 "Show hostname in certain command outputs\n")
2469 {
2470 VTY_DECLVAR_CONTEXT(bgp, bgp);
2471 bgp_flag_set(bgp, BGP_FLAG_SHOW_HOSTNAME);
2472 return CMD_SUCCESS;
2473 }
2474
2475 DEFUN (no_bgp_default_show_hostname,
2476 no_bgp_default_show_hostname_cmd,
2477 "no bgp default show-hostname",
2478 NO_STR
2479 "BGP specific commands\n"
2480 "Configure BGP defaults\n"
2481 "Show hostname in certain command outputs\n")
2482 {
2483 VTY_DECLVAR_CONTEXT(bgp, bgp);
2484 bgp_flag_unset(bgp, BGP_FLAG_SHOW_HOSTNAME);
2485 return CMD_SUCCESS;
2486 }
2487
2488 /* "bgp network import-check" configuration. */
2489 DEFUN (bgp_network_import_check,
2490 bgp_network_import_check_cmd,
2491 "bgp network import-check",
2492 "BGP specific commands\n"
2493 "BGP network command\n"
2494 "Check BGP network route exists in IGP\n")
2495 {
2496 VTY_DECLVAR_CONTEXT(bgp, bgp);
2497 if (!bgp_flag_check(bgp, BGP_FLAG_IMPORT_CHECK)) {
2498 bgp_flag_set(bgp, BGP_FLAG_IMPORT_CHECK);
2499 bgp_static_redo_import_check(bgp);
2500 }
2501
2502 return CMD_SUCCESS;
2503 }
2504
2505 ALIAS_HIDDEN(bgp_network_import_check, bgp_network_import_check_exact_cmd,
2506 "bgp network import-check exact",
2507 "BGP specific commands\n"
2508 "BGP network command\n"
2509 "Check BGP network route exists in IGP\n"
2510 "Match route precisely\n")
2511
2512 DEFUN (no_bgp_network_import_check,
2513 no_bgp_network_import_check_cmd,
2514 "no bgp network import-check",
2515 NO_STR
2516 "BGP specific commands\n"
2517 "BGP network command\n"
2518 "Check BGP network route exists in IGP\n")
2519 {
2520 VTY_DECLVAR_CONTEXT(bgp, bgp);
2521 if (bgp_flag_check(bgp, BGP_FLAG_IMPORT_CHECK)) {
2522 bgp_flag_unset(bgp, BGP_FLAG_IMPORT_CHECK);
2523 bgp_static_redo_import_check(bgp);
2524 }
2525
2526 return CMD_SUCCESS;
2527 }
2528
2529 DEFUN (bgp_default_local_preference,
2530 bgp_default_local_preference_cmd,
2531 "bgp default local-preference (0-4294967295)",
2532 "BGP specific commands\n"
2533 "Configure BGP defaults\n"
2534 "local preference (higher=more preferred)\n"
2535 "Configure default local preference value\n")
2536 {
2537 VTY_DECLVAR_CONTEXT(bgp, bgp);
2538 int idx_number = 3;
2539 uint32_t local_pref;
2540
2541 local_pref = strtoul(argv[idx_number]->arg, NULL, 10);
2542
2543 bgp_default_local_preference_set(bgp, local_pref);
2544 bgp_clear_star_soft_in(vty, bgp->name);
2545
2546 return CMD_SUCCESS;
2547 }
2548
2549 DEFUN (no_bgp_default_local_preference,
2550 no_bgp_default_local_preference_cmd,
2551 "no bgp default local-preference [(0-4294967295)]",
2552 NO_STR
2553 "BGP specific commands\n"
2554 "Configure BGP defaults\n"
2555 "local preference (higher=more preferred)\n"
2556 "Configure default local preference value\n")
2557 {
2558 VTY_DECLVAR_CONTEXT(bgp, bgp);
2559 bgp_default_local_preference_unset(bgp);
2560 bgp_clear_star_soft_in(vty, bgp->name);
2561
2562 return CMD_SUCCESS;
2563 }
2564
2565
2566 DEFUN (bgp_default_subgroup_pkt_queue_max,
2567 bgp_default_subgroup_pkt_queue_max_cmd,
2568 "bgp default subgroup-pkt-queue-max (20-100)",
2569 "BGP specific commands\n"
2570 "Configure BGP defaults\n"
2571 "subgroup-pkt-queue-max\n"
2572 "Configure subgroup packet queue max\n")
2573 {
2574 VTY_DECLVAR_CONTEXT(bgp, bgp);
2575 int idx_number = 3;
2576 uint32_t max_size;
2577
2578 max_size = strtoul(argv[idx_number]->arg, NULL, 10);
2579
2580 bgp_default_subgroup_pkt_queue_max_set(bgp, max_size);
2581
2582 return CMD_SUCCESS;
2583 }
2584
2585 DEFUN (no_bgp_default_subgroup_pkt_queue_max,
2586 no_bgp_default_subgroup_pkt_queue_max_cmd,
2587 "no bgp default subgroup-pkt-queue-max [(20-100)]",
2588 NO_STR
2589 "BGP specific commands\n"
2590 "Configure BGP defaults\n"
2591 "subgroup-pkt-queue-max\n"
2592 "Configure subgroup packet queue max\n")
2593 {
2594 VTY_DECLVAR_CONTEXT(bgp, bgp);
2595 bgp_default_subgroup_pkt_queue_max_unset(bgp);
2596 return CMD_SUCCESS;
2597 }
2598
2599
2600 DEFUN (bgp_rr_allow_outbound_policy,
2601 bgp_rr_allow_outbound_policy_cmd,
2602 "bgp route-reflector allow-outbound-policy",
2603 "BGP specific commands\n"
2604 "Allow modifications made by out route-map\n"
2605 "on ibgp neighbors\n")
2606 {
2607 VTY_DECLVAR_CONTEXT(bgp, bgp);
2608
2609 if (!bgp_flag_check(bgp, BGP_FLAG_RR_ALLOW_OUTBOUND_POLICY)) {
2610 bgp_flag_set(bgp, BGP_FLAG_RR_ALLOW_OUTBOUND_POLICY);
2611 update_group_announce_rrclients(bgp);
2612 bgp_clear_star_soft_out(vty, bgp->name);
2613 }
2614
2615 return CMD_SUCCESS;
2616 }
2617
2618 DEFUN (no_bgp_rr_allow_outbound_policy,
2619 no_bgp_rr_allow_outbound_policy_cmd,
2620 "no bgp route-reflector allow-outbound-policy",
2621 NO_STR
2622 "BGP specific commands\n"
2623 "Allow modifications made by out route-map\n"
2624 "on ibgp neighbors\n")
2625 {
2626 VTY_DECLVAR_CONTEXT(bgp, bgp);
2627
2628 if (bgp_flag_check(bgp, BGP_FLAG_RR_ALLOW_OUTBOUND_POLICY)) {
2629 bgp_flag_unset(bgp, BGP_FLAG_RR_ALLOW_OUTBOUND_POLICY);
2630 update_group_announce_rrclients(bgp);
2631 bgp_clear_star_soft_out(vty, bgp->name);
2632 }
2633
2634 return CMD_SUCCESS;
2635 }
2636
2637 DEFUN (bgp_listen_limit,
2638 bgp_listen_limit_cmd,
2639 "bgp listen limit (1-5000)",
2640 "BGP specific commands\n"
2641 "Configure BGP defaults\n"
2642 "maximum number of BGP Dynamic Neighbors that can be created\n"
2643 "Configure Dynamic Neighbors listen limit value\n")
2644 {
2645 VTY_DECLVAR_CONTEXT(bgp, bgp);
2646 int idx_number = 3;
2647 int listen_limit;
2648
2649 listen_limit = strtoul(argv[idx_number]->arg, NULL, 10);
2650
2651 bgp_listen_limit_set(bgp, listen_limit);
2652
2653 return CMD_SUCCESS;
2654 }
2655
2656 DEFUN (no_bgp_listen_limit,
2657 no_bgp_listen_limit_cmd,
2658 "no bgp listen limit [(1-5000)]",
2659 "BGP specific commands\n"
2660 "Configure BGP defaults\n"
2661 "unset maximum number of BGP Dynamic Neighbors that can be created\n"
2662 "Configure Dynamic Neighbors listen limit value to default\n"
2663 "Configure Dynamic Neighbors listen limit value\n")
2664 {
2665 VTY_DECLVAR_CONTEXT(bgp, bgp);
2666 bgp_listen_limit_unset(bgp);
2667 return CMD_SUCCESS;
2668 }
2669
2670
2671 /*
2672 * Check if this listen range is already configured. Check for exact
2673 * match or overlap based on input.
2674 */
2675 static struct peer_group *listen_range_exists(struct bgp *bgp,
2676 struct prefix *range, int exact)
2677 {
2678 struct listnode *node, *nnode;
2679 struct listnode *node1, *nnode1;
2680 struct peer_group *group;
2681 struct prefix *lr;
2682 afi_t afi;
2683 int match;
2684
2685 afi = family2afi(range->family);
2686 for (ALL_LIST_ELEMENTS(bgp->group, node, nnode, group)) {
2687 for (ALL_LIST_ELEMENTS(group->listen_range[afi], node1, nnode1,
2688 lr)) {
2689 if (exact)
2690 match = prefix_same(range, lr);
2691 else
2692 match = (prefix_match(range, lr)
2693 || prefix_match(lr, range));
2694 if (match)
2695 return group;
2696 }
2697 }
2698
2699 return NULL;
2700 }
2701
2702 DEFUN (bgp_listen_range,
2703 bgp_listen_range_cmd,
2704 "bgp listen range <A.B.C.D/M|X:X::X:X/M> peer-group PGNAME",
2705 "BGP specific commands\n"
2706 "Configure BGP dynamic neighbors listen range\n"
2707 "Configure BGP dynamic neighbors listen range\n"
2708 NEIGHBOR_ADDR_STR
2709 "Member of the peer-group\n"
2710 "Peer-group name\n")
2711 {
2712 VTY_DECLVAR_CONTEXT(bgp, bgp);
2713 struct prefix range;
2714 struct peer_group *group, *existing_group;
2715 afi_t afi;
2716 int ret;
2717 int idx = 0;
2718
2719 argv_find(argv, argc, "A.B.C.D/M", &idx);
2720 argv_find(argv, argc, "X:X::X:X/M", &idx);
2721 char *prefix = argv[idx]->arg;
2722 argv_find(argv, argc, "PGNAME", &idx);
2723 char *peergroup = argv[idx]->arg;
2724
2725 /* Convert IP prefix string to struct prefix. */
2726 ret = str2prefix(prefix, &range);
2727 if (!ret) {
2728 vty_out(vty, "%% Malformed listen range\n");
2729 return CMD_WARNING_CONFIG_FAILED;
2730 }
2731
2732 afi = family2afi(range.family);
2733
2734 if (afi == AFI_IP6 && IN6_IS_ADDR_LINKLOCAL(&range.u.prefix6)) {
2735 vty_out(vty,
2736 "%% Malformed listen range (link-local address)\n");
2737 return CMD_WARNING_CONFIG_FAILED;
2738 }
2739
2740 apply_mask(&range);
2741
2742 /* Check if same listen range is already configured. */
2743 existing_group = listen_range_exists(bgp, &range, 1);
2744 if (existing_group) {
2745 if (strcmp(existing_group->name, peergroup) == 0)
2746 return CMD_SUCCESS;
2747 else {
2748 vty_out(vty,
2749 "%% Same listen range is attached to peer-group %s\n",
2750 existing_group->name);
2751 return CMD_WARNING_CONFIG_FAILED;
2752 }
2753 }
2754
2755 /* Check if an overlapping listen range exists. */
2756 if (listen_range_exists(bgp, &range, 0)) {
2757 vty_out(vty,
2758 "%% Listen range overlaps with existing listen range\n");
2759 return CMD_WARNING_CONFIG_FAILED;
2760 }
2761
2762 group = peer_group_lookup(bgp, peergroup);
2763 if (!group) {
2764 vty_out(vty, "%% Configure the peer-group first\n");
2765 return CMD_WARNING_CONFIG_FAILED;
2766 }
2767
2768 ret = peer_group_listen_range_add(group, &range);
2769 return bgp_vty_return(vty, ret);
2770 }
2771
2772 DEFUN (no_bgp_listen_range,
2773 no_bgp_listen_range_cmd,
2774 "no bgp listen range <A.B.C.D/M|X:X::X:X/M> peer-group PGNAME",
2775 NO_STR
2776 "BGP specific commands\n"
2777 "Unconfigure BGP dynamic neighbors listen range\n"
2778 "Unconfigure BGP dynamic neighbors listen range\n"
2779 NEIGHBOR_ADDR_STR
2780 "Member of the peer-group\n"
2781 "Peer-group name\n")
2782 {
2783 VTY_DECLVAR_CONTEXT(bgp, bgp);
2784 struct prefix range;
2785 struct peer_group *group;
2786 afi_t afi;
2787 int ret;
2788 int idx = 0;
2789
2790 argv_find(argv, argc, "A.B.C.D/M", &idx);
2791 argv_find(argv, argc, "X:X::X:X/M", &idx);
2792 char *prefix = argv[idx]->arg;
2793 argv_find(argv, argc, "WORD", &idx);
2794 char *peergroup = argv[idx]->arg;
2795
2796 /* Convert IP prefix string to struct prefix. */
2797 ret = str2prefix(prefix, &range);
2798 if (!ret) {
2799 vty_out(vty, "%% Malformed listen range\n");
2800 return CMD_WARNING_CONFIG_FAILED;
2801 }
2802
2803 afi = family2afi(range.family);
2804
2805 if (afi == AFI_IP6 && IN6_IS_ADDR_LINKLOCAL(&range.u.prefix6)) {
2806 vty_out(vty,
2807 "%% Malformed listen range (link-local address)\n");
2808 return CMD_WARNING_CONFIG_FAILED;
2809 }
2810
2811 apply_mask(&range);
2812
2813 group = peer_group_lookup(bgp, peergroup);
2814 if (!group) {
2815 vty_out(vty, "%% Peer-group does not exist\n");
2816 return CMD_WARNING_CONFIG_FAILED;
2817 }
2818
2819 ret = peer_group_listen_range_del(group, &range);
2820 return bgp_vty_return(vty, ret);
2821 }
2822
2823 void bgp_config_write_listen(struct vty *vty, struct bgp *bgp)
2824 {
2825 struct peer_group *group;
2826 struct listnode *node, *nnode, *rnode, *nrnode;
2827 struct prefix *range;
2828 afi_t afi;
2829 char buf[PREFIX2STR_BUFFER];
2830
2831 if (bgp->dynamic_neighbors_limit != BGP_DYNAMIC_NEIGHBORS_LIMIT_DEFAULT)
2832 vty_out(vty, " bgp listen limit %d\n",
2833 bgp->dynamic_neighbors_limit);
2834
2835 for (ALL_LIST_ELEMENTS(bgp->group, node, nnode, group)) {
2836 for (afi = AFI_IP; afi < AFI_MAX; afi++) {
2837 for (ALL_LIST_ELEMENTS(group->listen_range[afi], rnode,
2838 nrnode, range)) {
2839 prefix2str(range, buf, sizeof(buf));
2840 vty_out(vty,
2841 " bgp listen range %s peer-group %s\n",
2842 buf, group->name);
2843 }
2844 }
2845 }
2846 }
2847
2848
2849 DEFUN (bgp_disable_connected_route_check,
2850 bgp_disable_connected_route_check_cmd,
2851 "bgp disable-ebgp-connected-route-check",
2852 "BGP specific commands\n"
2853 "Disable checking if nexthop is connected on ebgp sessions\n")
2854 {
2855 VTY_DECLVAR_CONTEXT(bgp, bgp);
2856 bgp_flag_set(bgp, BGP_FLAG_DISABLE_NH_CONNECTED_CHK);
2857 bgp_clear_star_soft_in(vty, bgp->name);
2858
2859 return CMD_SUCCESS;
2860 }
2861
2862 DEFUN (no_bgp_disable_connected_route_check,
2863 no_bgp_disable_connected_route_check_cmd,
2864 "no bgp disable-ebgp-connected-route-check",
2865 NO_STR
2866 "BGP specific commands\n"
2867 "Disable checking if nexthop is connected on ebgp sessions\n")
2868 {
2869 VTY_DECLVAR_CONTEXT(bgp, bgp);
2870 bgp_flag_unset(bgp, BGP_FLAG_DISABLE_NH_CONNECTED_CHK);
2871 bgp_clear_star_soft_in(vty, bgp->name);
2872
2873 return CMD_SUCCESS;
2874 }
2875
2876
2877 static int peer_remote_as_vty(struct vty *vty, const char *peer_str,
2878 const char *as_str, afi_t afi, safi_t safi)
2879 {
2880 VTY_DECLVAR_CONTEXT(bgp, bgp);
2881 int ret;
2882 as_t as;
2883 int as_type = AS_SPECIFIED;
2884 union sockunion su;
2885
2886 if (as_str[0] == 'i') {
2887 as = 0;
2888 as_type = AS_INTERNAL;
2889 } else if (as_str[0] == 'e') {
2890 as = 0;
2891 as_type = AS_EXTERNAL;
2892 } else {
2893 /* Get AS number. */
2894 as = strtoul(as_str, NULL, 10);
2895 }
2896
2897 /* If peer is peer group or interface peer, call proper function. */
2898 ret = str2sockunion(peer_str, &su);
2899 if (ret < 0) {
2900 struct peer *peer;
2901
2902 /* Check if existing interface peer */
2903 peer = peer_lookup_by_conf_if(bgp, peer_str);
2904
2905 ret = peer_remote_as(bgp, NULL, peer_str, &as, as_type, afi,
2906 safi);
2907
2908 /* if not interface peer, check peer-group settings */
2909 if (ret < 0 && !peer) {
2910 ret = peer_group_remote_as(bgp, peer_str, &as, as_type);
2911 if (ret < 0) {
2912 vty_out(vty,
2913 "%% Create the peer-group or interface first\n");
2914 return CMD_WARNING_CONFIG_FAILED;
2915 }
2916 return CMD_SUCCESS;
2917 }
2918 } else {
2919 if (peer_address_self_check(bgp, &su)) {
2920 vty_out(vty,
2921 "%% Can not configure the local system as neighbor\n");
2922 return CMD_WARNING_CONFIG_FAILED;
2923 }
2924 ret = peer_remote_as(bgp, &su, NULL, &as, as_type, afi, safi);
2925 }
2926
2927 /* This peer belongs to peer group. */
2928 switch (ret) {
2929 case BGP_ERR_PEER_GROUP_MEMBER:
2930 vty_out(vty,
2931 "%% Peer-group member cannot override remote-as of peer-group\n");
2932 return CMD_WARNING_CONFIG_FAILED;
2933 case BGP_ERR_PEER_GROUP_PEER_TYPE_DIFFERENT:
2934 vty_out(vty,
2935 "%% Peer-group members must be all internal or all external\n");
2936 return CMD_WARNING_CONFIG_FAILED;
2937 }
2938 return bgp_vty_return(vty, ret);
2939 }
2940
2941 DEFUN (bgp_default_shutdown,
2942 bgp_default_shutdown_cmd,
2943 "[no] bgp default shutdown",
2944 NO_STR
2945 BGP_STR
2946 "Configure BGP defaults\n"
2947 "Apply administrative shutdown to newly configured peers\n")
2948 {
2949 VTY_DECLVAR_CONTEXT(bgp, bgp);
2950 bgp->autoshutdown = !strmatch(argv[0]->text, "no");
2951 return CMD_SUCCESS;
2952 }
2953
2954 DEFUN (neighbor_remote_as,
2955 neighbor_remote_as_cmd,
2956 "neighbor <A.B.C.D|X:X::X:X|WORD> remote-as <(1-4294967295)|internal|external>",
2957 NEIGHBOR_STR
2958 NEIGHBOR_ADDR_STR2
2959 "Specify a BGP neighbor\n"
2960 AS_STR
2961 "Internal BGP peer\n"
2962 "External BGP peer\n")
2963 {
2964 int idx_peer = 1;
2965 int idx_remote_as = 3;
2966 return peer_remote_as_vty(vty, argv[idx_peer]->arg,
2967 argv[idx_remote_as]->arg, AFI_IP,
2968 SAFI_UNICAST);
2969 }
2970
2971 static int peer_conf_interface_get(struct vty *vty, const char *conf_if,
2972 afi_t afi, safi_t safi, int v6only,
2973 const char *peer_group_name,
2974 const char *as_str)
2975 {
2976 VTY_DECLVAR_CONTEXT(bgp, bgp);
2977 as_t as = 0;
2978 int as_type = AS_UNSPECIFIED;
2979 struct peer *peer;
2980 struct peer_group *group;
2981 int ret = 0;
2982 union sockunion su;
2983
2984 group = peer_group_lookup(bgp, conf_if);
2985
2986 if (group) {
2987 vty_out(vty, "%% Name conflict with peer-group \n");
2988 return CMD_WARNING_CONFIG_FAILED;
2989 }
2990
2991 if (as_str) {
2992 if (as_str[0] == 'i') {
2993 as_type = AS_INTERNAL;
2994 } else if (as_str[0] == 'e') {
2995 as_type = AS_EXTERNAL;
2996 } else {
2997 /* Get AS number. */
2998 as = strtoul(as_str, NULL, 10);
2999 as_type = AS_SPECIFIED;
3000 }
3001 }
3002
3003 peer = peer_lookup_by_conf_if(bgp, conf_if);
3004 if (peer) {
3005 if (as_str)
3006 ret = peer_remote_as(bgp, NULL, conf_if, &as, as_type,
3007 afi, safi);
3008 } else {
3009 if (bgp_flag_check(bgp, BGP_FLAG_NO_DEFAULT_IPV4)
3010 && afi == AFI_IP && safi == SAFI_UNICAST)
3011 peer = peer_create(NULL, conf_if, bgp, bgp->as, as,
3012 as_type, 0, 0, NULL);
3013 else
3014 peer = peer_create(NULL, conf_if, bgp, bgp->as, as,
3015 as_type, afi, safi, NULL);
3016
3017 if (!peer) {
3018 vty_out(vty, "%% BGP failed to create peer\n");
3019 return CMD_WARNING_CONFIG_FAILED;
3020 }
3021
3022 if (v6only)
3023 peer_flag_set(peer, PEER_FLAG_IFPEER_V6ONLY);
3024
3025 /* Request zebra to initiate IPv6 RAs on this interface. We do
3026 * this
3027 * any unnumbered peer in order to not worry about run-time
3028 * transitions
3029 * (e.g., peering is initially IPv4, but the IPv4 /30 or /31
3030 * address
3031 * gets deleted later etc.)
3032 */
3033 if (peer->ifp)
3034 bgp_zebra_initiate_radv(bgp, peer);
3035 }
3036
3037 if ((v6only && !CHECK_FLAG(peer->flags, PEER_FLAG_IFPEER_V6ONLY))
3038 || (!v6only && CHECK_FLAG(peer->flags, PEER_FLAG_IFPEER_V6ONLY))) {
3039 if (v6only)
3040 peer_flag_set(peer, PEER_FLAG_IFPEER_V6ONLY);
3041 else
3042 peer_flag_unset(peer, PEER_FLAG_IFPEER_V6ONLY);
3043
3044 /* v6only flag changed. Reset bgp seesion */
3045 if (BGP_IS_VALID_STATE_FOR_NOTIF(peer->status)) {
3046 peer->last_reset = PEER_DOWN_V6ONLY_CHANGE;
3047 bgp_notify_send(peer, BGP_NOTIFY_CEASE,
3048 BGP_NOTIFY_CEASE_CONFIG_CHANGE);
3049 } else
3050 bgp_session_reset(peer);
3051 }
3052
3053 if (!CHECK_FLAG(peer->flags_invert, PEER_FLAG_CAPABILITY_ENHE)) {
3054 SET_FLAG(peer->flags, PEER_FLAG_CAPABILITY_ENHE);
3055 SET_FLAG(peer->flags_invert, PEER_FLAG_CAPABILITY_ENHE);
3056 SET_FLAG(peer->flags_override, PEER_FLAG_CAPABILITY_ENHE);
3057 }
3058
3059 if (peer_group_name) {
3060 group = peer_group_lookup(bgp, peer_group_name);
3061 if (!group) {
3062 vty_out(vty, "%% Configure the peer-group first\n");
3063 return CMD_WARNING_CONFIG_FAILED;
3064 }
3065
3066 ret = peer_group_bind(bgp, &su, peer, group, &as);
3067 }
3068
3069 return bgp_vty_return(vty, ret);
3070 }
3071
3072 DEFUN (neighbor_interface_config,
3073 neighbor_interface_config_cmd,
3074 "neighbor WORD interface [peer-group PGNAME]",
3075 NEIGHBOR_STR
3076 "Interface name or neighbor tag\n"
3077 "Enable BGP on interface\n"
3078 "Member of the peer-group\n"
3079 "Peer-group name\n")
3080 {
3081 int idx_word = 1;
3082 int idx_peer_group_word = 4;
3083
3084 if (argc > idx_peer_group_word)
3085 return peer_conf_interface_get(
3086 vty, argv[idx_word]->arg, AFI_IP, SAFI_UNICAST, 0,
3087 argv[idx_peer_group_word]->arg, NULL);
3088 else
3089 return peer_conf_interface_get(vty, argv[idx_word]->arg, AFI_IP,
3090 SAFI_UNICAST, 0, NULL, NULL);
3091 }
3092
3093 DEFUN (neighbor_interface_config_v6only,
3094 neighbor_interface_config_v6only_cmd,
3095 "neighbor WORD interface v6only [peer-group PGNAME]",
3096 NEIGHBOR_STR
3097 "Interface name or neighbor tag\n"
3098 "Enable BGP on interface\n"
3099 "Enable BGP with v6 link-local only\n"
3100 "Member of the peer-group\n"
3101 "Peer-group name\n")
3102 {
3103 int idx_word = 1;
3104 int idx_peer_group_word = 5;
3105
3106 if (argc > idx_peer_group_word)
3107 return peer_conf_interface_get(
3108 vty, argv[idx_word]->arg, AFI_IP, SAFI_UNICAST, 1,
3109 argv[idx_peer_group_word]->arg, NULL);
3110
3111 return peer_conf_interface_get(vty, argv[idx_word]->arg, AFI_IP,
3112 SAFI_UNICAST, 1, NULL, NULL);
3113 }
3114
3115
3116 DEFUN (neighbor_interface_config_remote_as,
3117 neighbor_interface_config_remote_as_cmd,
3118 "neighbor WORD interface remote-as <(1-4294967295)|internal|external>",
3119 NEIGHBOR_STR
3120 "Interface name or neighbor tag\n"
3121 "Enable BGP on interface\n"
3122 "Specify a BGP neighbor\n"
3123 AS_STR
3124 "Internal BGP peer\n"
3125 "External BGP peer\n")
3126 {
3127 int idx_word = 1;
3128 int idx_remote_as = 4;
3129 return peer_conf_interface_get(vty, argv[idx_word]->arg, AFI_IP,
3130 SAFI_UNICAST, 0, NULL,
3131 argv[idx_remote_as]->arg);
3132 }
3133
3134 DEFUN (neighbor_interface_v6only_config_remote_as,
3135 neighbor_interface_v6only_config_remote_as_cmd,
3136 "neighbor WORD interface v6only remote-as <(1-4294967295)|internal|external>",
3137 NEIGHBOR_STR
3138 "Interface name or neighbor tag\n"
3139 "Enable BGP with v6 link-local only\n"
3140 "Enable BGP on interface\n"
3141 "Specify a BGP neighbor\n"
3142 AS_STR
3143 "Internal BGP peer\n"
3144 "External BGP peer\n")
3145 {
3146 int idx_word = 1;
3147 int idx_remote_as = 5;
3148 return peer_conf_interface_get(vty, argv[idx_word]->arg, AFI_IP,
3149 SAFI_UNICAST, 1, NULL,
3150 argv[idx_remote_as]->arg);
3151 }
3152
3153 DEFUN (neighbor_peer_group,
3154 neighbor_peer_group_cmd,
3155 "neighbor WORD peer-group",
3156 NEIGHBOR_STR
3157 "Interface name or neighbor tag\n"
3158 "Configure peer-group\n")
3159 {
3160 VTY_DECLVAR_CONTEXT(bgp, bgp);
3161 int idx_word = 1;
3162 struct peer *peer;
3163 struct peer_group *group;
3164
3165 peer = peer_lookup_by_conf_if(bgp, argv[idx_word]->arg);
3166 if (peer) {
3167 vty_out(vty, "%% Name conflict with interface: \n");
3168 return CMD_WARNING_CONFIG_FAILED;
3169 }
3170
3171 group = peer_group_get(bgp, argv[idx_word]->arg);
3172 if (!group) {
3173 vty_out(vty, "%% BGP failed to find or create peer-group\n");
3174 return CMD_WARNING_CONFIG_FAILED;
3175 }
3176
3177 return CMD_SUCCESS;
3178 }
3179
3180 DEFUN (no_neighbor,
3181 no_neighbor_cmd,
3182 "no neighbor <WORD|<A.B.C.D|X:X::X:X> [remote-as <(1-4294967295)|internal|external>]>",
3183 NO_STR
3184 NEIGHBOR_STR
3185 NEIGHBOR_ADDR_STR2
3186 "Specify a BGP neighbor\n"
3187 AS_STR
3188 "Internal BGP peer\n"
3189 "External BGP peer\n")
3190 {
3191 VTY_DECLVAR_CONTEXT(bgp, bgp);
3192 int idx_peer = 2;
3193 int ret;
3194 union sockunion su;
3195 struct peer_group *group;
3196 struct peer *peer;
3197 struct peer *other;
3198
3199 ret = str2sockunion(argv[idx_peer]->arg, &su);
3200 if (ret < 0) {
3201 /* look up for neighbor by interface name config. */
3202 peer = peer_lookup_by_conf_if(bgp, argv[idx_peer]->arg);
3203 if (peer) {
3204 /* Request zebra to terminate IPv6 RAs on this
3205 * interface. */
3206 if (peer->ifp)
3207 bgp_zebra_terminate_radv(peer->bgp, peer);
3208 peer_notify_unconfig(peer);
3209 peer_delete(peer);
3210 return CMD_SUCCESS;
3211 }
3212
3213 group = peer_group_lookup(bgp, argv[idx_peer]->arg);
3214 if (group) {
3215 peer_group_notify_unconfig(group);
3216 peer_group_delete(group);
3217 } else {
3218 vty_out(vty, "%% Create the peer-group first\n");
3219 return CMD_WARNING_CONFIG_FAILED;
3220 }
3221 } else {
3222 peer = peer_lookup(bgp, &su);
3223 if (peer) {
3224 if (peer_dynamic_neighbor(peer)) {
3225 vty_out(vty,
3226 "%% Operation not allowed on a dynamic neighbor\n");
3227 return CMD_WARNING_CONFIG_FAILED;
3228 }
3229
3230 other = peer->doppelganger;
3231 peer_notify_unconfig(peer);
3232 peer_delete(peer);
3233 if (other && other->status != Deleted) {
3234 peer_notify_unconfig(other);
3235 peer_delete(other);
3236 }
3237 }
3238 }
3239
3240 return CMD_SUCCESS;
3241 }
3242
3243 DEFUN (no_neighbor_interface_config,
3244 no_neighbor_interface_config_cmd,
3245 "no neighbor WORD interface [v6only] [peer-group PGNAME] [remote-as <(1-4294967295)|internal|external>]",
3246 NO_STR
3247 NEIGHBOR_STR
3248 "Interface name\n"
3249 "Configure BGP on interface\n"
3250 "Enable BGP with v6 link-local only\n"
3251 "Member of the peer-group\n"
3252 "Peer-group name\n"
3253 "Specify a BGP neighbor\n"
3254 AS_STR
3255 "Internal BGP peer\n"
3256 "External BGP peer\n")
3257 {
3258 VTY_DECLVAR_CONTEXT(bgp, bgp);
3259 int idx_word = 2;
3260 struct peer *peer;
3261
3262 /* look up for neighbor by interface name config. */
3263 peer = peer_lookup_by_conf_if(bgp, argv[idx_word]->arg);
3264 if (peer) {
3265 /* Request zebra to terminate IPv6 RAs on this interface. */
3266 if (peer->ifp)
3267 bgp_zebra_terminate_radv(peer->bgp, peer);
3268 peer_notify_unconfig(peer);
3269 peer_delete(peer);
3270 } else {
3271 vty_out(vty, "%% Create the bgp interface first\n");
3272 return CMD_WARNING_CONFIG_FAILED;
3273 }
3274 return CMD_SUCCESS;
3275 }
3276
3277 DEFUN (no_neighbor_peer_group,
3278 no_neighbor_peer_group_cmd,
3279 "no neighbor WORD peer-group",
3280 NO_STR
3281 NEIGHBOR_STR
3282 "Neighbor tag\n"
3283 "Configure peer-group\n")
3284 {
3285 VTY_DECLVAR_CONTEXT(bgp, bgp);
3286 int idx_word = 2;
3287 struct peer_group *group;
3288
3289 group = peer_group_lookup(bgp, argv[idx_word]->arg);
3290 if (group) {
3291 peer_group_notify_unconfig(group);
3292 peer_group_delete(group);
3293 } else {
3294 vty_out(vty, "%% Create the peer-group first\n");
3295 return CMD_WARNING_CONFIG_FAILED;
3296 }
3297 return CMD_SUCCESS;
3298 }
3299
3300 DEFUN (no_neighbor_interface_peer_group_remote_as,
3301 no_neighbor_interface_peer_group_remote_as_cmd,
3302 "no neighbor WORD remote-as <(1-4294967295)|internal|external>",
3303 NO_STR
3304 NEIGHBOR_STR
3305 "Interface name or neighbor tag\n"
3306 "Specify a BGP neighbor\n"
3307 AS_STR
3308 "Internal BGP peer\n"
3309 "External BGP peer\n")
3310 {
3311 VTY_DECLVAR_CONTEXT(bgp, bgp);
3312 int idx_word = 2;
3313 struct peer_group *group;
3314 struct peer *peer;
3315
3316 /* look up for neighbor by interface name config. */
3317 peer = peer_lookup_by_conf_if(bgp, argv[idx_word]->arg);
3318 if (peer) {
3319 peer_as_change(peer, 0, AS_UNSPECIFIED);
3320 return CMD_SUCCESS;
3321 }
3322
3323 group = peer_group_lookup(bgp, argv[idx_word]->arg);
3324 if (group)
3325 peer_group_remote_as_delete(group);
3326 else {
3327 vty_out(vty, "%% Create the peer-group or interface first\n");
3328 return CMD_WARNING_CONFIG_FAILED;
3329 }
3330 return CMD_SUCCESS;
3331 }
3332
3333 DEFUN (neighbor_local_as,
3334 neighbor_local_as_cmd,
3335 "neighbor <A.B.C.D|X:X::X:X|WORD> local-as (1-4294967295)",
3336 NEIGHBOR_STR
3337 NEIGHBOR_ADDR_STR2
3338 "Specify a local-as number\n"
3339 "AS number used as local AS\n")
3340 {
3341 int idx_peer = 1;
3342 int idx_number = 3;
3343 struct peer *peer;
3344 int ret;
3345 as_t as;
3346
3347 peer = peer_and_group_lookup_vty(vty, argv[idx_peer]->arg);
3348 if (!peer)
3349 return CMD_WARNING_CONFIG_FAILED;
3350
3351 as = strtoul(argv[idx_number]->arg, NULL, 10);
3352 ret = peer_local_as_set(peer, as, 0, 0);
3353 return bgp_vty_return(vty, ret);
3354 }
3355
3356 DEFUN (neighbor_local_as_no_prepend,
3357 neighbor_local_as_no_prepend_cmd,
3358 "neighbor <A.B.C.D|X:X::X:X|WORD> local-as (1-4294967295) no-prepend",
3359 NEIGHBOR_STR
3360 NEIGHBOR_ADDR_STR2
3361 "Specify a local-as number\n"
3362 "AS number used as local AS\n"
3363 "Do not prepend local-as to updates from ebgp peers\n")
3364 {
3365 int idx_peer = 1;
3366 int idx_number = 3;
3367 struct peer *peer;
3368 int ret;
3369 as_t as;
3370
3371 peer = peer_and_group_lookup_vty(vty, argv[idx_peer]->arg);
3372 if (!peer)
3373 return CMD_WARNING_CONFIG_FAILED;
3374
3375 as = strtoul(argv[idx_number]->arg, NULL, 10);
3376 ret = peer_local_as_set(peer, as, 1, 0);
3377 return bgp_vty_return(vty, ret);
3378 }
3379
3380 DEFUN (neighbor_local_as_no_prepend_replace_as,
3381 neighbor_local_as_no_prepend_replace_as_cmd,
3382 "neighbor <A.B.C.D|X:X::X:X|WORD> local-as (1-4294967295) no-prepend replace-as",
3383 NEIGHBOR_STR
3384 NEIGHBOR_ADDR_STR2
3385 "Specify a local-as number\n"
3386 "AS number used as local AS\n"
3387 "Do not prepend local-as to updates from ebgp peers\n"
3388 "Do not prepend local-as to updates from ibgp peers\n")
3389 {
3390 int idx_peer = 1;
3391 int idx_number = 3;
3392 struct peer *peer;
3393 int ret;
3394 as_t as;
3395
3396 peer = peer_and_group_lookup_vty(vty, argv[idx_peer]->arg);
3397 if (!peer)
3398 return CMD_WARNING_CONFIG_FAILED;
3399
3400 as = strtoul(argv[idx_number]->arg, NULL, 10);
3401 ret = peer_local_as_set(peer, as, 1, 1);
3402 return bgp_vty_return(vty, ret);
3403 }
3404
3405 DEFUN (no_neighbor_local_as,
3406 no_neighbor_local_as_cmd,
3407 "no neighbor <A.B.C.D|X:X::X:X|WORD> local-as [(1-4294967295) [no-prepend [replace-as]]]",
3408 NO_STR
3409 NEIGHBOR_STR
3410 NEIGHBOR_ADDR_STR2
3411 "Specify a local-as number\n"
3412 "AS number used as local AS\n"
3413 "Do not prepend local-as to updates from ebgp peers\n"
3414 "Do not prepend local-as to updates from ibgp peers\n")
3415 {
3416 int idx_peer = 2;
3417 struct peer *peer;
3418 int ret;
3419
3420 peer = peer_and_group_lookup_vty(vty, argv[idx_peer]->arg);
3421 if (!peer)
3422 return CMD_WARNING_CONFIG_FAILED;
3423
3424 ret = peer_local_as_unset(peer);
3425 return bgp_vty_return(vty, ret);
3426 }
3427
3428
3429 DEFUN (neighbor_solo,
3430 neighbor_solo_cmd,
3431 "neighbor <A.B.C.D|X:X::X:X|WORD> solo",
3432 NEIGHBOR_STR
3433 NEIGHBOR_ADDR_STR2
3434 "Solo peer - part of its own update group\n")
3435 {
3436 int idx_peer = 1;
3437 struct peer *peer;
3438 int ret;
3439
3440 peer = peer_and_group_lookup_vty(vty, argv[idx_peer]->arg);
3441 if (!peer)
3442 return CMD_WARNING_CONFIG_FAILED;
3443
3444 ret = update_group_adjust_soloness(peer, 1);
3445 return bgp_vty_return(vty, ret);
3446 }
3447
3448 DEFUN (no_neighbor_solo,
3449 no_neighbor_solo_cmd,
3450 "no neighbor <A.B.C.D|X:X::X:X|WORD> solo",
3451 NO_STR
3452 NEIGHBOR_STR
3453 NEIGHBOR_ADDR_STR2
3454 "Solo peer - part of its own update group\n")
3455 {
3456 int idx_peer = 2;
3457 struct peer *peer;
3458 int ret;
3459
3460 peer = peer_and_group_lookup_vty(vty, argv[idx_peer]->arg);
3461 if (!peer)
3462 return CMD_WARNING_CONFIG_FAILED;
3463
3464 ret = update_group_adjust_soloness(peer, 0);
3465 return bgp_vty_return(vty, ret);
3466 }
3467
3468 DEFUN (neighbor_password,
3469 neighbor_password_cmd,
3470 "neighbor <A.B.C.D|X:X::X:X|WORD> password LINE",
3471 NEIGHBOR_STR
3472 NEIGHBOR_ADDR_STR2
3473 "Set a password\n"
3474 "The password\n")
3475 {
3476 int idx_peer = 1;
3477 int idx_line = 3;
3478 struct peer *peer;
3479 int ret;
3480
3481 peer = peer_and_group_lookup_vty(vty, argv[idx_peer]->arg);
3482 if (!peer)
3483 return CMD_WARNING_CONFIG_FAILED;
3484
3485 ret = peer_password_set(peer, argv[idx_line]->arg);
3486 return bgp_vty_return(vty, ret);
3487 }
3488
3489 DEFUN (no_neighbor_password,
3490 no_neighbor_password_cmd,
3491 "no neighbor <A.B.C.D|X:X::X:X|WORD> password [LINE]",
3492 NO_STR
3493 NEIGHBOR_STR
3494 NEIGHBOR_ADDR_STR2
3495 "Set a password\n"
3496 "The password\n")
3497 {
3498 int idx_peer = 2;
3499 struct peer *peer;
3500 int ret;
3501
3502 peer = peer_and_group_lookup_vty(vty, argv[idx_peer]->arg);
3503 if (!peer)
3504 return CMD_WARNING_CONFIG_FAILED;
3505
3506 ret = peer_password_unset(peer);
3507 return bgp_vty_return(vty, ret);
3508 }
3509
3510 DEFUN (neighbor_activate,
3511 neighbor_activate_cmd,
3512 "neighbor <A.B.C.D|X:X::X:X|WORD> activate",
3513 NEIGHBOR_STR
3514 NEIGHBOR_ADDR_STR2
3515 "Enable the Address Family for this Neighbor\n")
3516 {
3517 int idx_peer = 1;
3518 int ret;
3519 struct peer *peer;
3520
3521 peer = peer_and_group_lookup_vty(vty, argv[idx_peer]->arg);
3522 if (!peer)
3523 return CMD_WARNING_CONFIG_FAILED;
3524
3525 ret = peer_activate(peer, bgp_node_afi(vty), bgp_node_safi(vty));
3526 return bgp_vty_return(vty, ret);
3527 }
3528
3529 ALIAS_HIDDEN(neighbor_activate, neighbor_activate_hidden_cmd,
3530 "neighbor <A.B.C.D|X:X::X:X|WORD> activate",
3531 NEIGHBOR_STR NEIGHBOR_ADDR_STR2
3532 "Enable the Address Family for this Neighbor\n")
3533
3534 DEFUN (no_neighbor_activate,
3535 no_neighbor_activate_cmd,
3536 "no neighbor <A.B.C.D|X:X::X:X|WORD> activate",
3537 NO_STR
3538 NEIGHBOR_STR
3539 NEIGHBOR_ADDR_STR2
3540 "Enable the Address Family for this Neighbor\n")
3541 {
3542 int idx_peer = 2;
3543 int ret;
3544 struct peer *peer;
3545
3546 /* Lookup peer. */
3547 peer = peer_and_group_lookup_vty(vty, argv[idx_peer]->arg);
3548 if (!peer)
3549 return CMD_WARNING_CONFIG_FAILED;
3550
3551 ret = peer_deactivate(peer, bgp_node_afi(vty), bgp_node_safi(vty));
3552 return bgp_vty_return(vty, ret);
3553 }
3554
3555 ALIAS_HIDDEN(no_neighbor_activate, no_neighbor_activate_hidden_cmd,
3556 "no neighbor <A.B.C.D|X:X::X:X|WORD> activate",
3557 NO_STR NEIGHBOR_STR NEIGHBOR_ADDR_STR2
3558 "Enable the Address Family for this Neighbor\n")
3559
3560 DEFUN (neighbor_set_peer_group,
3561 neighbor_set_peer_group_cmd,
3562 "neighbor <A.B.C.D|X:X::X:X|WORD> peer-group PGNAME",
3563 NEIGHBOR_STR
3564 NEIGHBOR_ADDR_STR2
3565 "Member of the peer-group\n"
3566 "Peer-group name\n")
3567 {
3568 VTY_DECLVAR_CONTEXT(bgp, bgp);
3569 int idx_peer = 1;
3570 int idx_word = 3;
3571 int ret;
3572 as_t as;
3573 union sockunion su;
3574 struct peer *peer;
3575 struct peer_group *group;
3576
3577 ret = str2sockunion(argv[idx_peer]->arg, &su);
3578 if (ret < 0) {
3579 peer = peer_lookup_by_conf_if(bgp, argv[idx_peer]->arg);
3580 if (!peer) {
3581 vty_out(vty, "%% Malformed address or name: %s\n",
3582 argv[idx_peer]->arg);
3583 return CMD_WARNING_CONFIG_FAILED;
3584 }
3585 } else {
3586 if (peer_address_self_check(bgp, &su)) {
3587 vty_out(vty,
3588 "%% Can not configure the local system as neighbor\n");
3589 return CMD_WARNING_CONFIG_FAILED;
3590 }
3591
3592 /* Disallow for dynamic neighbor. */
3593 peer = peer_lookup(bgp, &su);
3594 if (peer && peer_dynamic_neighbor(peer)) {
3595 vty_out(vty,
3596 "%% Operation not allowed on a dynamic neighbor\n");
3597 return CMD_WARNING_CONFIG_FAILED;
3598 }
3599 }
3600
3601 group = peer_group_lookup(bgp, argv[idx_word]->arg);
3602 if (!group) {
3603 vty_out(vty, "%% Configure the peer-group first\n");
3604 return CMD_WARNING_CONFIG_FAILED;
3605 }
3606
3607 ret = peer_group_bind(bgp, &su, peer, group, &as);
3608
3609 if (ret == BGP_ERR_PEER_GROUP_PEER_TYPE_DIFFERENT) {
3610 vty_out(vty,
3611 "%% Peer with AS %u cannot be in this peer-group, members must be all internal or all external\n",
3612 as);
3613 return CMD_WARNING_CONFIG_FAILED;
3614 }
3615
3616 return bgp_vty_return(vty, ret);
3617 }
3618
3619 ALIAS_HIDDEN(neighbor_set_peer_group, neighbor_set_peer_group_hidden_cmd,
3620 "neighbor <A.B.C.D|X:X::X:X|WORD> peer-group PGNAME",
3621 NEIGHBOR_STR NEIGHBOR_ADDR_STR2
3622 "Member of the peer-group\n"
3623 "Peer-group name\n")
3624
3625 DEFUN (no_neighbor_set_peer_group,
3626 no_neighbor_set_peer_group_cmd,
3627 "no neighbor <A.B.C.D|X:X::X:X|WORD> peer-group PGNAME",
3628 NO_STR
3629 NEIGHBOR_STR
3630 NEIGHBOR_ADDR_STR2
3631 "Member of the peer-group\n"
3632 "Peer-group name\n")
3633 {
3634 VTY_DECLVAR_CONTEXT(bgp, bgp);
3635 int idx_peer = 2;
3636 int idx_word = 4;
3637 int ret;
3638 struct peer *peer;
3639 struct peer_group *group;
3640
3641 peer = peer_lookup_vty(vty, argv[idx_peer]->arg);
3642 if (!peer)
3643 return CMD_WARNING_CONFIG_FAILED;
3644
3645 group = peer_group_lookup(bgp, argv[idx_word]->arg);
3646 if (!group) {
3647 vty_out(vty, "%% Configure the peer-group first\n");
3648 return CMD_WARNING_CONFIG_FAILED;
3649 }
3650
3651 peer_notify_unconfig(peer);
3652 ret = peer_delete(peer);
3653
3654 return bgp_vty_return(vty, ret);
3655 }
3656
3657 ALIAS_HIDDEN(no_neighbor_set_peer_group, no_neighbor_set_peer_group_hidden_cmd,
3658 "no neighbor <A.B.C.D|X:X::X:X|WORD> peer-group PGNAME",
3659 NO_STR NEIGHBOR_STR NEIGHBOR_ADDR_STR2
3660 "Member of the peer-group\n"
3661 "Peer-group name\n")
3662
3663 static int peer_flag_modify_vty(struct vty *vty, const char *ip_str,
3664 uint32_t flag, int set)
3665 {
3666 int ret;
3667 struct peer *peer;
3668
3669 peer = peer_and_group_lookup_vty(vty, ip_str);
3670 if (!peer)
3671 return CMD_WARNING_CONFIG_FAILED;
3672
3673 /*
3674 * If 'neighbor <interface>', then this is for directly connected peers,
3675 * we should not accept disable-connected-check.
3676 */
3677 if (peer->conf_if && (flag == PEER_FLAG_DISABLE_CONNECTED_CHECK)) {
3678 vty_out(vty,
3679 "%s is directly connected peer, cannot accept disable-"
3680 "connected-check\n",
3681 ip_str);
3682 return CMD_WARNING_CONFIG_FAILED;
3683 }
3684
3685 if (!set && flag == PEER_FLAG_SHUTDOWN)
3686 peer_tx_shutdown_message_unset(peer);
3687
3688 if (set)
3689 ret = peer_flag_set(peer, flag);
3690 else
3691 ret = peer_flag_unset(peer, flag);
3692
3693 return bgp_vty_return(vty, ret);
3694 }
3695
3696 static int peer_flag_set_vty(struct vty *vty, const char *ip_str, uint32_t flag)
3697 {
3698 return peer_flag_modify_vty(vty, ip_str, flag, 1);
3699 }
3700
3701 static int peer_flag_unset_vty(struct vty *vty, const char *ip_str,
3702 uint32_t flag)
3703 {
3704 return peer_flag_modify_vty(vty, ip_str, flag, 0);
3705 }
3706
3707 /* neighbor passive. */
3708 DEFUN (neighbor_passive,
3709 neighbor_passive_cmd,
3710 "neighbor <A.B.C.D|X:X::X:X|WORD> passive",
3711 NEIGHBOR_STR
3712 NEIGHBOR_ADDR_STR2
3713 "Don't send open messages to this neighbor\n")
3714 {
3715 int idx_peer = 1;
3716 return peer_flag_set_vty(vty, argv[idx_peer]->arg, PEER_FLAG_PASSIVE);
3717 }
3718
3719 DEFUN (no_neighbor_passive,
3720 no_neighbor_passive_cmd,
3721 "no neighbor <A.B.C.D|X:X::X:X|WORD> passive",
3722 NO_STR
3723 NEIGHBOR_STR
3724 NEIGHBOR_ADDR_STR2
3725 "Don't send open messages to this neighbor\n")
3726 {
3727 int idx_peer = 2;
3728 return peer_flag_unset_vty(vty, argv[idx_peer]->arg, PEER_FLAG_PASSIVE);
3729 }
3730
3731 /* neighbor shutdown. */
3732 DEFUN (neighbor_shutdown_msg,
3733 neighbor_shutdown_msg_cmd,
3734 "neighbor <A.B.C.D|X:X::X:X|WORD> shutdown message MSG...",
3735 NEIGHBOR_STR
3736 NEIGHBOR_ADDR_STR2
3737 "Administratively shut down this neighbor\n"
3738 "Add a shutdown message (draft-ietf-idr-shutdown-06)\n"
3739 "Shutdown message\n")
3740 {
3741 int idx_peer = 1;
3742
3743 if (argc >= 5) {
3744 struct peer *peer =
3745 peer_and_group_lookup_vty(vty, argv[idx_peer]->arg);
3746 char *message;
3747
3748 if (!peer)
3749 return CMD_WARNING_CONFIG_FAILED;
3750 message = argv_concat(argv, argc, 4);
3751 peer_tx_shutdown_message_set(peer, message);
3752 XFREE(MTYPE_TMP, message);
3753 }
3754
3755 return peer_flag_set_vty(vty, argv[idx_peer]->arg, PEER_FLAG_SHUTDOWN);
3756 }
3757
3758 ALIAS(neighbor_shutdown_msg, neighbor_shutdown_cmd,
3759 "neighbor <A.B.C.D|X:X::X:X|WORD> shutdown",
3760 NEIGHBOR_STR NEIGHBOR_ADDR_STR2
3761 "Administratively shut down this neighbor\n")
3762
3763 DEFUN (no_neighbor_shutdown_msg,
3764 no_neighbor_shutdown_msg_cmd,
3765 "no neighbor <A.B.C.D|X:X::X:X|WORD> shutdown message MSG...",
3766 NO_STR
3767 NEIGHBOR_STR
3768 NEIGHBOR_ADDR_STR2
3769 "Administratively shut down this neighbor\n"
3770 "Remove a shutdown message (draft-ietf-idr-shutdown-06)\n"
3771 "Shutdown message\n")
3772 {
3773 int idx_peer = 2;
3774
3775 return peer_flag_unset_vty(vty, argv[idx_peer]->arg,
3776 PEER_FLAG_SHUTDOWN);
3777 }
3778
3779 ALIAS(no_neighbor_shutdown_msg, no_neighbor_shutdown_cmd,
3780 "no neighbor <A.B.C.D|X:X::X:X|WORD> shutdown",
3781 NO_STR NEIGHBOR_STR NEIGHBOR_ADDR_STR2
3782 "Administratively shut down this neighbor\n")
3783
3784 /* neighbor capability dynamic. */
3785 DEFUN (neighbor_capability_dynamic,
3786 neighbor_capability_dynamic_cmd,
3787 "neighbor <A.B.C.D|X:X::X:X|WORD> capability dynamic",
3788 NEIGHBOR_STR
3789 NEIGHBOR_ADDR_STR2
3790 "Advertise capability to the peer\n"
3791 "Advertise dynamic capability to this neighbor\n")
3792 {
3793 int idx_peer = 1;
3794 return peer_flag_set_vty(vty, argv[idx_peer]->arg,
3795 PEER_FLAG_DYNAMIC_CAPABILITY);
3796 }
3797
3798 DEFUN (no_neighbor_capability_dynamic,
3799 no_neighbor_capability_dynamic_cmd,
3800 "no neighbor <A.B.C.D|X:X::X:X|WORD> capability dynamic",
3801 NO_STR
3802 NEIGHBOR_STR
3803 NEIGHBOR_ADDR_STR2
3804 "Advertise capability to the peer\n"
3805 "Advertise dynamic capability to this neighbor\n")
3806 {
3807 int idx_peer = 2;
3808 return peer_flag_unset_vty(vty, argv[idx_peer]->arg,
3809 PEER_FLAG_DYNAMIC_CAPABILITY);
3810 }
3811
3812 /* neighbor dont-capability-negotiate */
3813 DEFUN (neighbor_dont_capability_negotiate,
3814 neighbor_dont_capability_negotiate_cmd,
3815 "neighbor <A.B.C.D|X:X::X:X|WORD> dont-capability-negotiate",
3816 NEIGHBOR_STR
3817 NEIGHBOR_ADDR_STR2
3818 "Do not perform capability negotiation\n")
3819 {
3820 int idx_peer = 1;
3821 return peer_flag_set_vty(vty, argv[idx_peer]->arg,
3822 PEER_FLAG_DONT_CAPABILITY);
3823 }
3824
3825 DEFUN (no_neighbor_dont_capability_negotiate,
3826 no_neighbor_dont_capability_negotiate_cmd,
3827 "no neighbor <A.B.C.D|X:X::X:X|WORD> dont-capability-negotiate",
3828 NO_STR
3829 NEIGHBOR_STR
3830 NEIGHBOR_ADDR_STR2
3831 "Do not perform capability negotiation\n")
3832 {
3833 int idx_peer = 2;
3834 return peer_flag_unset_vty(vty, argv[idx_peer]->arg,
3835 PEER_FLAG_DONT_CAPABILITY);
3836 }
3837
3838 /* neighbor capability extended next hop encoding */
3839 DEFUN (neighbor_capability_enhe,
3840 neighbor_capability_enhe_cmd,
3841 "neighbor <A.B.C.D|X:X::X:X|WORD> capability extended-nexthop",
3842 NEIGHBOR_STR
3843 NEIGHBOR_ADDR_STR2
3844 "Advertise capability to the peer\n"
3845 "Advertise extended next-hop capability to the peer\n")
3846 {
3847 int idx_peer = 1;
3848 return peer_flag_set_vty(vty, argv[idx_peer]->arg,
3849 PEER_FLAG_CAPABILITY_ENHE);
3850 }
3851
3852 DEFUN (no_neighbor_capability_enhe,
3853 no_neighbor_capability_enhe_cmd,
3854 "no neighbor <A.B.C.D|X:X::X:X|WORD> capability extended-nexthop",
3855 NO_STR
3856 NEIGHBOR_STR
3857 NEIGHBOR_ADDR_STR2
3858 "Advertise capability to the peer\n"
3859 "Advertise extended next-hop capability to the peer\n")
3860 {
3861 int idx_peer = 2;
3862 return peer_flag_unset_vty(vty, argv[idx_peer]->arg,
3863 PEER_FLAG_CAPABILITY_ENHE);
3864 }
3865
3866 static int peer_af_flag_modify_vty(struct vty *vty, const char *peer_str,
3867 afi_t afi, safi_t safi, uint32_t flag,
3868 int set)
3869 {
3870 int ret;
3871 struct peer *peer;
3872
3873 peer = peer_and_group_lookup_vty(vty, peer_str);
3874 if (!peer)
3875 return CMD_WARNING_CONFIG_FAILED;
3876
3877 if (set)
3878 ret = peer_af_flag_set(peer, afi, safi, flag);
3879 else
3880 ret = peer_af_flag_unset(peer, afi, safi, flag);
3881
3882 return bgp_vty_return(vty, ret);
3883 }
3884
3885 static int peer_af_flag_set_vty(struct vty *vty, const char *peer_str,
3886 afi_t afi, safi_t safi, uint32_t flag)
3887 {
3888 return peer_af_flag_modify_vty(vty, peer_str, afi, safi, flag, 1);
3889 }
3890
3891 static int peer_af_flag_unset_vty(struct vty *vty, const char *peer_str,
3892 afi_t afi, safi_t safi, uint32_t flag)
3893 {
3894 return peer_af_flag_modify_vty(vty, peer_str, afi, safi, flag, 0);
3895 }
3896
3897 /* neighbor capability orf prefix-list. */
3898 DEFUN (neighbor_capability_orf_prefix,
3899 neighbor_capability_orf_prefix_cmd,
3900 "neighbor <A.B.C.D|X:X::X:X|WORD> capability orf prefix-list <both|send|receive>",
3901 NEIGHBOR_STR
3902 NEIGHBOR_ADDR_STR2
3903 "Advertise capability to the peer\n"
3904 "Advertise ORF capability to the peer\n"
3905 "Advertise prefixlist ORF capability to this neighbor\n"
3906 "Capability to SEND and RECEIVE the ORF to/from this neighbor\n"
3907 "Capability to RECEIVE the ORF from this neighbor\n"
3908 "Capability to SEND the ORF to this neighbor\n")
3909 {
3910 int idx_peer = 1;
3911 int idx_send_recv = 5;
3912 uint16_t flag = 0;
3913
3914 if (strmatch(argv[idx_send_recv]->text, "send"))
3915 flag = PEER_FLAG_ORF_PREFIX_SM;
3916 else if (strmatch(argv[idx_send_recv]->text, "receive"))
3917 flag = PEER_FLAG_ORF_PREFIX_RM;
3918 else if (strmatch(argv[idx_send_recv]->text, "both"))
3919 flag = PEER_FLAG_ORF_PREFIX_SM | PEER_FLAG_ORF_PREFIX_RM;
3920 else {
3921 vty_out(vty, "%% BGP invalid orf prefix-list option\n");
3922 return CMD_WARNING_CONFIG_FAILED;
3923 }
3924
3925 return peer_af_flag_set_vty(vty, argv[idx_peer]->arg, bgp_node_afi(vty),
3926 bgp_node_safi(vty), flag);
3927 }
3928
3929 ALIAS_HIDDEN(
3930 neighbor_capability_orf_prefix,
3931 neighbor_capability_orf_prefix_hidden_cmd,
3932 "neighbor <A.B.C.D|X:X::X:X|WORD> capability orf prefix-list <both|send|receive>",
3933 NEIGHBOR_STR NEIGHBOR_ADDR_STR2
3934 "Advertise capability to the peer\n"
3935 "Advertise ORF capability to the peer\n"
3936 "Advertise prefixlist ORF capability to this neighbor\n"
3937 "Capability to SEND and RECEIVE the ORF to/from this neighbor\n"
3938 "Capability to RECEIVE the ORF from this neighbor\n"
3939 "Capability to SEND the ORF to this neighbor\n")
3940
3941 DEFUN (no_neighbor_capability_orf_prefix,
3942 no_neighbor_capability_orf_prefix_cmd,
3943 "no neighbor <A.B.C.D|X:X::X:X|WORD> capability orf prefix-list <both|send|receive>",
3944 NO_STR
3945 NEIGHBOR_STR
3946 NEIGHBOR_ADDR_STR2
3947 "Advertise capability to the peer\n"
3948 "Advertise ORF capability to the peer\n"
3949 "Advertise prefixlist ORF capability to this neighbor\n"
3950 "Capability to SEND and RECEIVE the ORF to/from this neighbor\n"
3951 "Capability to RECEIVE the ORF from this neighbor\n"
3952 "Capability to SEND the ORF to this neighbor\n")
3953 {
3954 int idx_peer = 2;
3955 int idx_send_recv = 6;
3956 uint16_t flag = 0;
3957
3958 if (strmatch(argv[idx_send_recv]->text, "send"))
3959 flag = PEER_FLAG_ORF_PREFIX_SM;
3960 else if (strmatch(argv[idx_send_recv]->text, "receive"))
3961 flag = PEER_FLAG_ORF_PREFIX_RM;
3962 else if (strmatch(argv[idx_send_recv]->text, "both"))
3963 flag = PEER_FLAG_ORF_PREFIX_SM | PEER_FLAG_ORF_PREFIX_RM;
3964 else {
3965 vty_out(vty, "%% BGP invalid orf prefix-list option\n");
3966 return CMD_WARNING_CONFIG_FAILED;
3967 }
3968
3969 return peer_af_flag_unset_vty(vty, argv[idx_peer]->arg,
3970 bgp_node_afi(vty), bgp_node_safi(vty),
3971 flag);
3972 }
3973
3974 ALIAS_HIDDEN(
3975 no_neighbor_capability_orf_prefix,
3976 no_neighbor_capability_orf_prefix_hidden_cmd,
3977 "no neighbor <A.B.C.D|X:X::X:X|WORD> capability orf prefix-list <both|send|receive>",
3978 NO_STR NEIGHBOR_STR NEIGHBOR_ADDR_STR2
3979 "Advertise capability to the peer\n"
3980 "Advertise ORF capability to the peer\n"
3981 "Advertise prefixlist ORF capability to this neighbor\n"
3982 "Capability to SEND and RECEIVE the ORF to/from this neighbor\n"
3983 "Capability to RECEIVE the ORF from this neighbor\n"
3984 "Capability to SEND the ORF to this neighbor\n")
3985
3986 /* neighbor next-hop-self. */
3987 DEFUN (neighbor_nexthop_self,
3988 neighbor_nexthop_self_cmd,
3989 "neighbor <A.B.C.D|X:X::X:X|WORD> next-hop-self",
3990 NEIGHBOR_STR
3991 NEIGHBOR_ADDR_STR2
3992 "Disable the next hop calculation for this neighbor\n")
3993 {
3994 int idx_peer = 1;
3995 return peer_af_flag_set_vty(vty, argv[idx_peer]->arg, bgp_node_afi(vty),
3996 bgp_node_safi(vty), PEER_FLAG_NEXTHOP_SELF);
3997 }
3998
3999 ALIAS_HIDDEN(neighbor_nexthop_self, neighbor_nexthop_self_hidden_cmd,
4000 "neighbor <A.B.C.D|X:X::X:X|WORD> next-hop-self",
4001 NEIGHBOR_STR NEIGHBOR_ADDR_STR2
4002 "Disable the next hop calculation for this neighbor\n")
4003
4004 /* neighbor next-hop-self. */
4005 DEFUN (neighbor_nexthop_self_force,
4006 neighbor_nexthop_self_force_cmd,
4007 "neighbor <A.B.C.D|X:X::X:X|WORD> next-hop-self force",
4008 NEIGHBOR_STR
4009 NEIGHBOR_ADDR_STR2
4010 "Disable the next hop calculation for this neighbor\n"
4011 "Set the next hop to self for reflected routes\n")
4012 {
4013 int idx_peer = 1;
4014 return peer_af_flag_set_vty(vty, argv[idx_peer]->arg, bgp_node_afi(vty),
4015 bgp_node_safi(vty),
4016 PEER_FLAG_FORCE_NEXTHOP_SELF);
4017 }
4018
4019 ALIAS_HIDDEN(neighbor_nexthop_self_force,
4020 neighbor_nexthop_self_force_hidden_cmd,
4021 "neighbor <A.B.C.D|X:X::X:X|WORD> next-hop-self force",
4022 NEIGHBOR_STR NEIGHBOR_ADDR_STR2
4023 "Disable the next hop calculation for this neighbor\n"
4024 "Set the next hop to self for reflected routes\n")
4025
4026 ALIAS_HIDDEN(neighbor_nexthop_self_force,
4027 neighbor_nexthop_self_all_hidden_cmd,
4028 "neighbor <A.B.C.D|X:X::X:X|WORD> next-hop-self all",
4029 NEIGHBOR_STR NEIGHBOR_ADDR_STR2
4030 "Disable the next hop calculation for this neighbor\n"
4031 "Set the next hop to self for reflected routes\n")
4032
4033 DEFUN (no_neighbor_nexthop_self,
4034 no_neighbor_nexthop_self_cmd,
4035 "no neighbor <A.B.C.D|X:X::X:X|WORD> next-hop-self",
4036 NO_STR
4037 NEIGHBOR_STR
4038 NEIGHBOR_ADDR_STR2
4039 "Disable the next hop calculation for this neighbor\n")
4040 {
4041 int idx_peer = 2;
4042 return peer_af_flag_unset_vty(vty, argv[idx_peer]->arg,
4043 bgp_node_afi(vty), bgp_node_safi(vty),
4044 PEER_FLAG_NEXTHOP_SELF);
4045 }
4046
4047 ALIAS_HIDDEN(no_neighbor_nexthop_self, no_neighbor_nexthop_self_hidden_cmd,
4048 "no neighbor <A.B.C.D|X:X::X:X|WORD> next-hop-self",
4049 NO_STR NEIGHBOR_STR NEIGHBOR_ADDR_STR2
4050 "Disable the next hop calculation for this neighbor\n")
4051
4052 DEFUN (no_neighbor_nexthop_self_force,
4053 no_neighbor_nexthop_self_force_cmd,
4054 "no neighbor <A.B.C.D|X:X::X:X|WORD> next-hop-self force",
4055 NO_STR
4056 NEIGHBOR_STR
4057 NEIGHBOR_ADDR_STR2
4058 "Disable the next hop calculation for this neighbor\n"
4059 "Set the next hop to self for reflected routes\n")
4060 {
4061 int idx_peer = 2;
4062 return peer_af_flag_unset_vty(vty, argv[idx_peer]->arg,
4063 bgp_node_afi(vty), bgp_node_safi(vty),
4064 PEER_FLAG_FORCE_NEXTHOP_SELF);
4065 }
4066
4067 ALIAS_HIDDEN(no_neighbor_nexthop_self_force,
4068 no_neighbor_nexthop_self_force_hidden_cmd,
4069 "no neighbor <A.B.C.D|X:X::X:X|WORD> next-hop-self force",
4070 NO_STR NEIGHBOR_STR NEIGHBOR_ADDR_STR2
4071 "Disable the next hop calculation for this neighbor\n"
4072 "Set the next hop to self for reflected routes\n")
4073
4074 ALIAS_HIDDEN(no_neighbor_nexthop_self_force,
4075 no_neighbor_nexthop_self_all_hidden_cmd,
4076 "no neighbor <A.B.C.D|X:X::X:X|WORD> next-hop-self all",
4077 NO_STR NEIGHBOR_STR NEIGHBOR_ADDR_STR2
4078 "Disable the next hop calculation for this neighbor\n"
4079 "Set the next hop to self for reflected routes\n")
4080
4081 /* neighbor as-override */
4082 DEFUN (neighbor_as_override,
4083 neighbor_as_override_cmd,
4084 "neighbor <A.B.C.D|X:X::X:X|WORD> as-override",
4085 NEIGHBOR_STR
4086 NEIGHBOR_ADDR_STR2
4087 "Override ASNs in outbound updates if aspath equals remote-as\n")
4088 {
4089 int idx_peer = 1;
4090 return peer_af_flag_set_vty(vty, argv[idx_peer]->arg, bgp_node_afi(vty),
4091 bgp_node_safi(vty), PEER_FLAG_AS_OVERRIDE);
4092 }
4093
4094 ALIAS_HIDDEN(neighbor_as_override, neighbor_as_override_hidden_cmd,
4095 "neighbor <A.B.C.D|X:X::X:X|WORD> as-override",
4096 NEIGHBOR_STR NEIGHBOR_ADDR_STR2
4097 "Override ASNs in outbound updates if aspath equals remote-as\n")
4098
4099 DEFUN (no_neighbor_as_override,
4100 no_neighbor_as_override_cmd,
4101 "no neighbor <A.B.C.D|X:X::X:X|WORD> as-override",
4102 NO_STR
4103 NEIGHBOR_STR
4104 NEIGHBOR_ADDR_STR2
4105 "Override ASNs in outbound updates if aspath equals remote-as\n")
4106 {
4107 int idx_peer = 2;
4108 return peer_af_flag_unset_vty(vty, argv[idx_peer]->arg,
4109 bgp_node_afi(vty), bgp_node_safi(vty),
4110 PEER_FLAG_AS_OVERRIDE);
4111 }
4112
4113 ALIAS_HIDDEN(no_neighbor_as_override, no_neighbor_as_override_hidden_cmd,
4114 "no neighbor <A.B.C.D|X:X::X:X|WORD> as-override",
4115 NO_STR NEIGHBOR_STR NEIGHBOR_ADDR_STR2
4116 "Override ASNs in outbound updates if aspath equals remote-as\n")
4117
4118 /* neighbor remove-private-AS. */
4119 DEFUN (neighbor_remove_private_as,
4120 neighbor_remove_private_as_cmd,
4121 "neighbor <A.B.C.D|X:X::X:X|WORD> remove-private-AS",
4122 NEIGHBOR_STR
4123 NEIGHBOR_ADDR_STR2
4124 "Remove private ASNs in outbound updates\n")
4125 {
4126 int idx_peer = 1;
4127 return peer_af_flag_set_vty(vty, argv[idx_peer]->arg, bgp_node_afi(vty),
4128 bgp_node_safi(vty),
4129 PEER_FLAG_REMOVE_PRIVATE_AS);
4130 }
4131
4132 ALIAS_HIDDEN(neighbor_remove_private_as, neighbor_remove_private_as_hidden_cmd,
4133 "neighbor <A.B.C.D|X:X::X:X|WORD> remove-private-AS",
4134 NEIGHBOR_STR NEIGHBOR_ADDR_STR2
4135 "Remove private ASNs in outbound updates\n")
4136
4137 DEFUN (neighbor_remove_private_as_all,
4138 neighbor_remove_private_as_all_cmd,
4139 "neighbor <A.B.C.D|X:X::X:X|WORD> remove-private-AS all",
4140 NEIGHBOR_STR
4141 NEIGHBOR_ADDR_STR2
4142 "Remove private ASNs in outbound updates\n"
4143 "Apply to all AS numbers\n")
4144 {
4145 int idx_peer = 1;
4146 return peer_af_flag_set_vty(vty, argv[idx_peer]->arg, bgp_node_afi(vty),
4147 bgp_node_safi(vty),
4148 PEER_FLAG_REMOVE_PRIVATE_AS_ALL);
4149 }
4150
4151 ALIAS_HIDDEN(neighbor_remove_private_as_all,
4152 neighbor_remove_private_as_all_hidden_cmd,
4153 "neighbor <A.B.C.D|X:X::X:X|WORD> remove-private-AS all",
4154 NEIGHBOR_STR NEIGHBOR_ADDR_STR2
4155 "Remove private ASNs in outbound updates\n"
4156 "Apply to all AS numbers")
4157
4158 DEFUN (neighbor_remove_private_as_replace_as,
4159 neighbor_remove_private_as_replace_as_cmd,
4160 "neighbor <A.B.C.D|X:X::X:X|WORD> remove-private-AS replace-AS",
4161 NEIGHBOR_STR
4162 NEIGHBOR_ADDR_STR2
4163 "Remove private ASNs in outbound updates\n"
4164 "Replace private ASNs with our ASN in outbound updates\n")
4165 {
4166 int idx_peer = 1;
4167 return peer_af_flag_set_vty(vty, argv[idx_peer]->arg, bgp_node_afi(vty),
4168 bgp_node_safi(vty),
4169 PEER_FLAG_REMOVE_PRIVATE_AS_REPLACE);
4170 }
4171
4172 ALIAS_HIDDEN(neighbor_remove_private_as_replace_as,
4173 neighbor_remove_private_as_replace_as_hidden_cmd,
4174 "neighbor <A.B.C.D|X:X::X:X|WORD> remove-private-AS replace-AS",
4175 NEIGHBOR_STR NEIGHBOR_ADDR_STR2
4176 "Remove private ASNs in outbound updates\n"
4177 "Replace private ASNs with our ASN in outbound updates\n")
4178
4179 DEFUN (neighbor_remove_private_as_all_replace_as,
4180 neighbor_remove_private_as_all_replace_as_cmd,
4181 "neighbor <A.B.C.D|X:X::X:X|WORD> remove-private-AS all replace-AS",
4182 NEIGHBOR_STR
4183 NEIGHBOR_ADDR_STR2
4184 "Remove private ASNs in outbound updates\n"
4185 "Apply to all AS numbers\n"
4186 "Replace private ASNs with our ASN in outbound updates\n")
4187 {
4188 int idx_peer = 1;
4189 return peer_af_flag_set_vty(vty, argv[idx_peer]->arg, bgp_node_afi(vty),
4190 bgp_node_safi(vty),
4191 PEER_FLAG_REMOVE_PRIVATE_AS_ALL_REPLACE);
4192 }
4193
4194 ALIAS_HIDDEN(
4195 neighbor_remove_private_as_all_replace_as,
4196 neighbor_remove_private_as_all_replace_as_hidden_cmd,
4197 "neighbor <A.B.C.D|X:X::X:X|WORD> remove-private-AS all replace-AS",
4198 NEIGHBOR_STR NEIGHBOR_ADDR_STR2
4199 "Remove private ASNs in outbound updates\n"
4200 "Apply to all AS numbers\n"
4201 "Replace private ASNs with our ASN in outbound updates\n")
4202
4203 DEFUN (no_neighbor_remove_private_as,
4204 no_neighbor_remove_private_as_cmd,
4205 "no neighbor <A.B.C.D|X:X::X:X|WORD> remove-private-AS",
4206 NO_STR
4207 NEIGHBOR_STR
4208 NEIGHBOR_ADDR_STR2
4209 "Remove private ASNs in outbound updates\n")
4210 {
4211 int idx_peer = 2;
4212 return peer_af_flag_unset_vty(vty, argv[idx_peer]->arg,
4213 bgp_node_afi(vty), bgp_node_safi(vty),
4214 PEER_FLAG_REMOVE_PRIVATE_AS);
4215 }
4216
4217 ALIAS_HIDDEN(no_neighbor_remove_private_as,
4218 no_neighbor_remove_private_as_hidden_cmd,
4219 "no neighbor <A.B.C.D|X:X::X:X|WORD> remove-private-AS",
4220 NO_STR NEIGHBOR_STR NEIGHBOR_ADDR_STR2
4221 "Remove private ASNs in outbound updates\n")
4222
4223 DEFUN (no_neighbor_remove_private_as_all,
4224 no_neighbor_remove_private_as_all_cmd,
4225 "no neighbor <A.B.C.D|X:X::X:X|WORD> remove-private-AS all",
4226 NO_STR
4227 NEIGHBOR_STR
4228 NEIGHBOR_ADDR_STR2
4229 "Remove private ASNs in outbound updates\n"
4230 "Apply to all AS numbers\n")
4231 {
4232 int idx_peer = 2;
4233 return peer_af_flag_unset_vty(vty, argv[idx_peer]->arg,
4234 bgp_node_afi(vty), bgp_node_safi(vty),
4235 PEER_FLAG_REMOVE_PRIVATE_AS_ALL);
4236 }
4237
4238 ALIAS_HIDDEN(no_neighbor_remove_private_as_all,
4239 no_neighbor_remove_private_as_all_hidden_cmd,
4240 "no neighbor <A.B.C.D|X:X::X:X|WORD> remove-private-AS all",
4241 NO_STR NEIGHBOR_STR NEIGHBOR_ADDR_STR2
4242 "Remove private ASNs in outbound updates\n"
4243 "Apply to all AS numbers\n")
4244
4245 DEFUN (no_neighbor_remove_private_as_replace_as,
4246 no_neighbor_remove_private_as_replace_as_cmd,
4247 "no neighbor <A.B.C.D|X:X::X:X|WORD> remove-private-AS replace-AS",
4248 NO_STR
4249 NEIGHBOR_STR
4250 NEIGHBOR_ADDR_STR2
4251 "Remove private ASNs in outbound updates\n"
4252 "Replace private ASNs with our ASN in outbound updates\n")
4253 {
4254 int idx_peer = 2;
4255 return peer_af_flag_unset_vty(vty, argv[idx_peer]->arg,
4256 bgp_node_afi(vty), bgp_node_safi(vty),
4257 PEER_FLAG_REMOVE_PRIVATE_AS_REPLACE);
4258 }
4259
4260 ALIAS_HIDDEN(no_neighbor_remove_private_as_replace_as,
4261 no_neighbor_remove_private_as_replace_as_hidden_cmd,
4262 "no neighbor <A.B.C.D|X:X::X:X|WORD> remove-private-AS replace-AS",
4263 NO_STR NEIGHBOR_STR NEIGHBOR_ADDR_STR2
4264 "Remove private ASNs in outbound updates\n"
4265 "Replace private ASNs with our ASN in outbound updates\n")
4266
4267 DEFUN (no_neighbor_remove_private_as_all_replace_as,
4268 no_neighbor_remove_private_as_all_replace_as_cmd,
4269 "no neighbor <A.B.C.D|X:X::X:X|WORD> remove-private-AS all replace-AS",
4270 NO_STR
4271 NEIGHBOR_STR
4272 NEIGHBOR_ADDR_STR2
4273 "Remove private ASNs in outbound updates\n"
4274 "Apply to all AS numbers\n"
4275 "Replace private ASNs with our ASN in outbound updates\n")
4276 {
4277 int idx_peer = 2;
4278 return peer_af_flag_unset_vty(vty, argv[idx_peer]->arg,
4279 bgp_node_afi(vty), bgp_node_safi(vty),
4280 PEER_FLAG_REMOVE_PRIVATE_AS_ALL_REPLACE);
4281 }
4282
4283 ALIAS_HIDDEN(
4284 no_neighbor_remove_private_as_all_replace_as,
4285 no_neighbor_remove_private_as_all_replace_as_hidden_cmd,
4286 "no neighbor <A.B.C.D|X:X::X:X|WORD> remove-private-AS all replace-AS",
4287 NO_STR NEIGHBOR_STR NEIGHBOR_ADDR_STR2
4288 "Remove private ASNs in outbound updates\n"
4289 "Apply to all AS numbers\n"
4290 "Replace private ASNs with our ASN in outbound updates\n")
4291
4292
4293 /* neighbor send-community. */
4294 DEFUN (neighbor_send_community,
4295 neighbor_send_community_cmd,
4296 "neighbor <A.B.C.D|X:X::X:X|WORD> send-community",
4297 NEIGHBOR_STR
4298 NEIGHBOR_ADDR_STR2
4299 "Send Community attribute to this neighbor\n")
4300 {
4301 int idx_peer = 1;
4302
4303 return peer_af_flag_set_vty(vty, argv[idx_peer]->arg, bgp_node_afi(vty),
4304 bgp_node_safi(vty),
4305 PEER_FLAG_SEND_COMMUNITY);
4306 }
4307
4308 ALIAS_HIDDEN(neighbor_send_community, neighbor_send_community_hidden_cmd,
4309 "neighbor <A.B.C.D|X:X::X:X|WORD> send-community",
4310 NEIGHBOR_STR NEIGHBOR_ADDR_STR2
4311 "Send Community attribute to this neighbor\n")
4312
4313 DEFUN (no_neighbor_send_community,
4314 no_neighbor_send_community_cmd,
4315 "no neighbor <A.B.C.D|X:X::X:X|WORD> send-community",
4316 NO_STR
4317 NEIGHBOR_STR
4318 NEIGHBOR_ADDR_STR2
4319 "Send Community attribute to this neighbor\n")
4320 {
4321 int idx_peer = 2;
4322
4323 return peer_af_flag_unset_vty(vty, argv[idx_peer]->arg,
4324 bgp_node_afi(vty), bgp_node_safi(vty),
4325 PEER_FLAG_SEND_COMMUNITY);
4326 }
4327
4328 ALIAS_HIDDEN(no_neighbor_send_community, no_neighbor_send_community_hidden_cmd,
4329 "no neighbor <A.B.C.D|X:X::X:X|WORD> send-community",
4330 NO_STR NEIGHBOR_STR NEIGHBOR_ADDR_STR2
4331 "Send Community attribute to this neighbor\n")
4332
4333 /* neighbor send-community extended. */
4334 DEFUN (neighbor_send_community_type,
4335 neighbor_send_community_type_cmd,
4336 "neighbor <A.B.C.D|X:X::X:X|WORD> send-community <both|all|extended|standard|large>",
4337 NEIGHBOR_STR
4338 NEIGHBOR_ADDR_STR2
4339 "Send Community attribute to this neighbor\n"
4340 "Send Standard and Extended Community attributes\n"
4341 "Send Standard, Large and Extended Community attributes\n"
4342 "Send Extended Community attributes\n"
4343 "Send Standard Community attributes\n"
4344 "Send Large Community attributes\n")
4345 {
4346 int idx_peer = 1;
4347 uint32_t flag = 0;
4348 const char *type = argv[argc - 1]->text;
4349
4350 if (strmatch(type, "standard")) {
4351 SET_FLAG(flag, PEER_FLAG_SEND_COMMUNITY);
4352 } else if (strmatch(type, "extended")) {
4353 SET_FLAG(flag, PEER_FLAG_SEND_EXT_COMMUNITY);
4354 } else if (strmatch(type, "large")) {
4355 SET_FLAG(flag, PEER_FLAG_SEND_LARGE_COMMUNITY);
4356 } else if (strmatch(type, "both")) {
4357 SET_FLAG(flag, PEER_FLAG_SEND_COMMUNITY);
4358 SET_FLAG(flag, PEER_FLAG_SEND_EXT_COMMUNITY);
4359 } else { /* if (strmatch(type, "all")) */
4360 SET_FLAG(flag, PEER_FLAG_SEND_COMMUNITY);
4361 SET_FLAG(flag, PEER_FLAG_SEND_EXT_COMMUNITY);
4362 SET_FLAG(flag, PEER_FLAG_SEND_LARGE_COMMUNITY);
4363 }
4364
4365 return peer_af_flag_set_vty(vty, argv[idx_peer]->arg, bgp_node_afi(vty),
4366 bgp_node_safi(vty), flag);
4367 }
4368
4369 ALIAS_HIDDEN(
4370 neighbor_send_community_type, neighbor_send_community_type_hidden_cmd,
4371 "neighbor <A.B.C.D|X:X::X:X|WORD> send-community <both|all|extended|standard|large>",
4372 NEIGHBOR_STR NEIGHBOR_ADDR_STR2
4373 "Send Community attribute to this neighbor\n"
4374 "Send Standard and Extended Community attributes\n"
4375 "Send Standard, Large and Extended Community attributes\n"
4376 "Send Extended Community attributes\n"
4377 "Send Standard Community attributes\n"
4378 "Send Large Community attributes\n")
4379
4380 DEFUN (no_neighbor_send_community_type,
4381 no_neighbor_send_community_type_cmd,
4382 "no neighbor <A.B.C.D|X:X::X:X|WORD> send-community <both|all|extended|standard|large>",
4383 NO_STR
4384 NEIGHBOR_STR
4385 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 int idx_peer = 2;
4394 uint32_t flag = 0;
4395 const char *type = argv[argc - 1]->text;
4396
4397 if (strmatch(type, "standard")) {
4398 SET_FLAG(flag, PEER_FLAG_SEND_COMMUNITY);
4399 } else if (strmatch(type, "extended")) {
4400 SET_FLAG(flag, PEER_FLAG_SEND_EXT_COMMUNITY);
4401 } else if (strmatch(type, "large")) {
4402 SET_FLAG(flag, PEER_FLAG_SEND_LARGE_COMMUNITY);
4403 } else if (strmatch(type, "both")) {
4404 SET_FLAG(flag, PEER_FLAG_SEND_COMMUNITY);
4405 SET_FLAG(flag, PEER_FLAG_SEND_EXT_COMMUNITY);
4406 } else { /* if (strmatch(type, "all")) */
4407 SET_FLAG(flag, PEER_FLAG_SEND_COMMUNITY);
4408 SET_FLAG(flag, PEER_FLAG_SEND_EXT_COMMUNITY);
4409 SET_FLAG(flag, PEER_FLAG_SEND_LARGE_COMMUNITY);
4410 }
4411
4412 return peer_af_flag_unset_vty(vty, argv[idx_peer]->arg,
4413 bgp_node_afi(vty), bgp_node_safi(vty),
4414 flag);
4415 }
4416
4417 ALIAS_HIDDEN(
4418 no_neighbor_send_community_type,
4419 no_neighbor_send_community_type_hidden_cmd,
4420 "no neighbor <A.B.C.D|X:X::X:X|WORD> send-community <both|all|extended|standard|large>",
4421 NO_STR NEIGHBOR_STR NEIGHBOR_ADDR_STR2
4422 "Send Community attribute to this neighbor\n"
4423 "Send Standard and Extended Community attributes\n"
4424 "Send Standard, Large and Extended Community attributes\n"
4425 "Send Extended Community attributes\n"
4426 "Send Standard Community attributes\n"
4427 "Send Large Community attributes\n")
4428
4429 /* neighbor soft-reconfig. */
4430 DEFUN (neighbor_soft_reconfiguration,
4431 neighbor_soft_reconfiguration_cmd,
4432 "neighbor <A.B.C.D|X:X::X:X|WORD> soft-reconfiguration inbound",
4433 NEIGHBOR_STR
4434 NEIGHBOR_ADDR_STR2
4435 "Per neighbor soft reconfiguration\n"
4436 "Allow inbound soft reconfiguration for this neighbor\n")
4437 {
4438 int idx_peer = 1;
4439 return peer_af_flag_set_vty(vty, argv[idx_peer]->arg, bgp_node_afi(vty),
4440 bgp_node_safi(vty),
4441 PEER_FLAG_SOFT_RECONFIG);
4442 }
4443
4444 ALIAS_HIDDEN(neighbor_soft_reconfiguration,
4445 neighbor_soft_reconfiguration_hidden_cmd,
4446 "neighbor <A.B.C.D|X:X::X:X|WORD> soft-reconfiguration inbound",
4447 NEIGHBOR_STR NEIGHBOR_ADDR_STR2
4448 "Per neighbor soft reconfiguration\n"
4449 "Allow inbound soft reconfiguration for this neighbor\n")
4450
4451 DEFUN (no_neighbor_soft_reconfiguration,
4452 no_neighbor_soft_reconfiguration_cmd,
4453 "no neighbor <A.B.C.D|X:X::X:X|WORD> soft-reconfiguration inbound",
4454 NO_STR
4455 NEIGHBOR_STR
4456 NEIGHBOR_ADDR_STR2
4457 "Per neighbor soft reconfiguration\n"
4458 "Allow inbound soft reconfiguration for this neighbor\n")
4459 {
4460 int idx_peer = 2;
4461 return peer_af_flag_unset_vty(vty, argv[idx_peer]->arg,
4462 bgp_node_afi(vty), bgp_node_safi(vty),
4463 PEER_FLAG_SOFT_RECONFIG);
4464 }
4465
4466 ALIAS_HIDDEN(no_neighbor_soft_reconfiguration,
4467 no_neighbor_soft_reconfiguration_hidden_cmd,
4468 "no neighbor <A.B.C.D|X:X::X:X|WORD> soft-reconfiguration inbound",
4469 NO_STR NEIGHBOR_STR NEIGHBOR_ADDR_STR2
4470 "Per neighbor soft reconfiguration\n"
4471 "Allow inbound soft reconfiguration for this neighbor\n")
4472
4473 DEFUN (neighbor_route_reflector_client,
4474 neighbor_route_reflector_client_cmd,
4475 "neighbor <A.B.C.D|X:X::X:X|WORD> route-reflector-client",
4476 NEIGHBOR_STR
4477 NEIGHBOR_ADDR_STR2
4478 "Configure a neighbor as Route Reflector client\n")
4479 {
4480 int idx_peer = 1;
4481 struct peer *peer;
4482
4483
4484 peer = peer_and_group_lookup_vty(vty, argv[idx_peer]->arg);
4485 if (!peer)
4486 return CMD_WARNING_CONFIG_FAILED;
4487
4488 return peer_af_flag_set_vty(vty, argv[idx_peer]->arg, bgp_node_afi(vty),
4489 bgp_node_safi(vty),
4490 PEER_FLAG_REFLECTOR_CLIENT);
4491 }
4492
4493 ALIAS_HIDDEN(neighbor_route_reflector_client,
4494 neighbor_route_reflector_client_hidden_cmd,
4495 "neighbor <A.B.C.D|X:X::X:X|WORD> route-reflector-client",
4496 NEIGHBOR_STR NEIGHBOR_ADDR_STR2
4497 "Configure a neighbor as Route Reflector client\n")
4498
4499 DEFUN (no_neighbor_route_reflector_client,
4500 no_neighbor_route_reflector_client_cmd,
4501 "no neighbor <A.B.C.D|X:X::X:X|WORD> route-reflector-client",
4502 NO_STR
4503 NEIGHBOR_STR
4504 NEIGHBOR_ADDR_STR2
4505 "Configure a neighbor as Route Reflector client\n")
4506 {
4507 int idx_peer = 2;
4508 return peer_af_flag_unset_vty(vty, argv[idx_peer]->arg,
4509 bgp_node_afi(vty), bgp_node_safi(vty),
4510 PEER_FLAG_REFLECTOR_CLIENT);
4511 }
4512
4513 ALIAS_HIDDEN(no_neighbor_route_reflector_client,
4514 no_neighbor_route_reflector_client_hidden_cmd,
4515 "no neighbor <A.B.C.D|X:X::X:X|WORD> route-reflector-client",
4516 NO_STR NEIGHBOR_STR NEIGHBOR_ADDR_STR2
4517 "Configure a neighbor as Route Reflector client\n")
4518
4519 /* neighbor route-server-client. */
4520 DEFUN (neighbor_route_server_client,
4521 neighbor_route_server_client_cmd,
4522 "neighbor <A.B.C.D|X:X::X:X|WORD> route-server-client",
4523 NEIGHBOR_STR
4524 NEIGHBOR_ADDR_STR2
4525 "Configure a neighbor as Route Server client\n")
4526 {
4527 int idx_peer = 1;
4528 struct peer *peer;
4529
4530 peer = peer_and_group_lookup_vty(vty, argv[idx_peer]->arg);
4531 if (!peer)
4532 return CMD_WARNING_CONFIG_FAILED;
4533 return peer_af_flag_set_vty(vty, argv[idx_peer]->arg, bgp_node_afi(vty),
4534 bgp_node_safi(vty),
4535 PEER_FLAG_RSERVER_CLIENT);
4536 }
4537
4538 ALIAS_HIDDEN(neighbor_route_server_client,
4539 neighbor_route_server_client_hidden_cmd,
4540 "neighbor <A.B.C.D|X:X::X:X|WORD> route-server-client",
4541 NEIGHBOR_STR NEIGHBOR_ADDR_STR2
4542 "Configure a neighbor as Route Server client\n")
4543
4544 DEFUN (no_neighbor_route_server_client,
4545 no_neighbor_route_server_client_cmd,
4546 "no neighbor <A.B.C.D|X:X::X:X|WORD> route-server-client",
4547 NO_STR
4548 NEIGHBOR_STR
4549 NEIGHBOR_ADDR_STR2
4550 "Configure a neighbor as Route Server client\n")
4551 {
4552 int idx_peer = 2;
4553 return peer_af_flag_unset_vty(vty, argv[idx_peer]->arg,
4554 bgp_node_afi(vty), bgp_node_safi(vty),
4555 PEER_FLAG_RSERVER_CLIENT);
4556 }
4557
4558 ALIAS_HIDDEN(no_neighbor_route_server_client,
4559 no_neighbor_route_server_client_hidden_cmd,
4560 "no neighbor <A.B.C.D|X:X::X:X|WORD> route-server-client",
4561 NO_STR NEIGHBOR_STR NEIGHBOR_ADDR_STR2
4562 "Configure a neighbor as Route Server client\n")
4563
4564 DEFUN (neighbor_nexthop_local_unchanged,
4565 neighbor_nexthop_local_unchanged_cmd,
4566 "neighbor <A.B.C.D|X:X::X:X|WORD> nexthop-local unchanged",
4567 NEIGHBOR_STR
4568 NEIGHBOR_ADDR_STR2
4569 "Configure treatment of outgoing link-local nexthop attribute\n"
4570 "Leave link-local nexthop unchanged for this peer\n")
4571 {
4572 int idx_peer = 1;
4573 return peer_af_flag_set_vty(vty, argv[idx_peer]->arg, bgp_node_afi(vty),
4574 bgp_node_safi(vty),
4575 PEER_FLAG_NEXTHOP_LOCAL_UNCHANGED);
4576 }
4577
4578 DEFUN (no_neighbor_nexthop_local_unchanged,
4579 no_neighbor_nexthop_local_unchanged_cmd,
4580 "no neighbor <A.B.C.D|X:X::X:X|WORD> nexthop-local unchanged",
4581 NO_STR
4582 NEIGHBOR_STR
4583 NEIGHBOR_ADDR_STR2
4584 "Configure treatment of outgoing link-local-nexthop attribute\n"
4585 "Leave link-local nexthop unchanged for this peer\n")
4586 {
4587 int idx_peer = 2;
4588 return peer_af_flag_unset_vty(vty, argv[idx_peer]->arg,
4589 bgp_node_afi(vty), bgp_node_safi(vty),
4590 PEER_FLAG_NEXTHOP_LOCAL_UNCHANGED);
4591 }
4592
4593 DEFUN (neighbor_attr_unchanged,
4594 neighbor_attr_unchanged_cmd,
4595 "neighbor <A.B.C.D|X:X::X:X|WORD> attribute-unchanged [{as-path|next-hop|med}]",
4596 NEIGHBOR_STR
4597 NEIGHBOR_ADDR_STR2
4598 "BGP attribute is propagated unchanged to this neighbor\n"
4599 "As-path attribute\n"
4600 "Nexthop attribute\n"
4601 "Med attribute\n")
4602 {
4603 int idx = 0;
4604 char *peer_str = argv[1]->arg;
4605 struct peer *peer;
4606 uint16_t flags = 0;
4607 afi_t afi = bgp_node_afi(vty);
4608 safi_t safi = bgp_node_safi(vty);
4609
4610 peer = peer_and_group_lookup_vty(vty, peer_str);
4611 if (!peer)
4612 return CMD_WARNING_CONFIG_FAILED;
4613
4614 if (argv_find(argv, argc, "as-path", &idx))
4615 SET_FLAG(flags, PEER_FLAG_AS_PATH_UNCHANGED);
4616 idx = 0;
4617 if (argv_find(argv, argc, "next-hop", &idx))
4618 SET_FLAG(flags, PEER_FLAG_NEXTHOP_UNCHANGED);
4619 idx = 0;
4620 if (argv_find(argv, argc, "med", &idx))
4621 SET_FLAG(flags, PEER_FLAG_MED_UNCHANGED);
4622
4623 /* no flags means all of them! */
4624 if (!flags) {
4625 SET_FLAG(flags, PEER_FLAG_AS_PATH_UNCHANGED);
4626 SET_FLAG(flags, PEER_FLAG_NEXTHOP_UNCHANGED);
4627 SET_FLAG(flags, PEER_FLAG_MED_UNCHANGED);
4628 } else {
4629 if (!CHECK_FLAG(flags, PEER_FLAG_AS_PATH_UNCHANGED)
4630 && peer_af_flag_check(peer, afi, safi,
4631 PEER_FLAG_AS_PATH_UNCHANGED)) {
4632 peer_af_flag_unset_vty(vty, peer_str, afi, safi,
4633 PEER_FLAG_AS_PATH_UNCHANGED);
4634 }
4635
4636 if (!CHECK_FLAG(flags, PEER_FLAG_NEXTHOP_UNCHANGED)
4637 && peer_af_flag_check(peer, afi, safi,
4638 PEER_FLAG_NEXTHOP_UNCHANGED)) {
4639 peer_af_flag_unset_vty(vty, peer_str, afi, safi,
4640 PEER_FLAG_NEXTHOP_UNCHANGED);
4641 }
4642
4643 if (!CHECK_FLAG(flags, PEER_FLAG_MED_UNCHANGED)
4644 && peer_af_flag_check(peer, afi, safi,
4645 PEER_FLAG_MED_UNCHANGED)) {
4646 peer_af_flag_unset_vty(vty, peer_str, afi, safi,
4647 PEER_FLAG_MED_UNCHANGED);
4648 }
4649 }
4650
4651 return peer_af_flag_set_vty(vty, peer_str, afi, safi, flags);
4652 }
4653
4654 ALIAS_HIDDEN(
4655 neighbor_attr_unchanged, neighbor_attr_unchanged_hidden_cmd,
4656 "neighbor <A.B.C.D|X:X::X:X|WORD> attribute-unchanged [{as-path|next-hop|med}]",
4657 NEIGHBOR_STR NEIGHBOR_ADDR_STR2
4658 "BGP attribute is propagated unchanged to this neighbor\n"
4659 "As-path attribute\n"
4660 "Nexthop attribute\n"
4661 "Med attribute\n")
4662
4663 DEFUN (no_neighbor_attr_unchanged,
4664 no_neighbor_attr_unchanged_cmd,
4665 "no neighbor <A.B.C.D|X:X::X:X|WORD> attribute-unchanged [{as-path|next-hop|med}]",
4666 NO_STR
4667 NEIGHBOR_STR
4668 NEIGHBOR_ADDR_STR2
4669 "BGP attribute is propagated unchanged to this neighbor\n"
4670 "As-path attribute\n"
4671 "Nexthop attribute\n"
4672 "Med attribute\n")
4673 {
4674 int idx = 0;
4675 char *peer = argv[2]->arg;
4676 uint16_t flags = 0;
4677
4678 if (argv_find(argv, argc, "as-path", &idx))
4679 SET_FLAG(flags, PEER_FLAG_AS_PATH_UNCHANGED);
4680 idx = 0;
4681 if (argv_find(argv, argc, "next-hop", &idx))
4682 SET_FLAG(flags, PEER_FLAG_NEXTHOP_UNCHANGED);
4683 idx = 0;
4684 if (argv_find(argv, argc, "med", &idx))
4685 SET_FLAG(flags, PEER_FLAG_MED_UNCHANGED);
4686
4687 if (!flags) // no flags means all of them!
4688 {
4689 SET_FLAG(flags, PEER_FLAG_AS_PATH_UNCHANGED);
4690 SET_FLAG(flags, PEER_FLAG_NEXTHOP_UNCHANGED);
4691 SET_FLAG(flags, PEER_FLAG_MED_UNCHANGED);
4692 }
4693
4694 return peer_af_flag_unset_vty(vty, peer, bgp_node_afi(vty),
4695 bgp_node_safi(vty), flags);
4696 }
4697
4698 ALIAS_HIDDEN(
4699 no_neighbor_attr_unchanged, no_neighbor_attr_unchanged_hidden_cmd,
4700 "no neighbor <A.B.C.D|X:X::X:X|WORD> attribute-unchanged [{as-path|next-hop|med}]",
4701 NO_STR NEIGHBOR_STR NEIGHBOR_ADDR_STR2
4702 "BGP attribute is propagated unchanged to this neighbor\n"
4703 "As-path attribute\n"
4704 "Nexthop attribute\n"
4705 "Med attribute\n")
4706
4707 /* EBGP multihop configuration. */
4708 static int peer_ebgp_multihop_set_vty(struct vty *vty, const char *ip_str,
4709 const char *ttl_str)
4710 {
4711 struct peer *peer;
4712 unsigned int ttl;
4713
4714 peer = peer_and_group_lookup_vty(vty, ip_str);
4715 if (!peer)
4716 return CMD_WARNING_CONFIG_FAILED;
4717
4718 if (peer->conf_if)
4719 return bgp_vty_return(vty, BGP_ERR_INVALID_FOR_DIRECT_PEER);
4720
4721 if (!ttl_str)
4722 ttl = MAXTTL;
4723 else
4724 ttl = strtoul(ttl_str, NULL, 10);
4725
4726 return bgp_vty_return(vty, peer_ebgp_multihop_set(peer, ttl));
4727 }
4728
4729 static int peer_ebgp_multihop_unset_vty(struct vty *vty, const char *ip_str)
4730 {
4731 struct peer *peer;
4732
4733 peer = peer_and_group_lookup_vty(vty, ip_str);
4734 if (!peer)
4735 return CMD_WARNING_CONFIG_FAILED;
4736
4737 return bgp_vty_return(vty, peer_ebgp_multihop_unset(peer));
4738 }
4739
4740 /* neighbor ebgp-multihop. */
4741 DEFUN (neighbor_ebgp_multihop,
4742 neighbor_ebgp_multihop_cmd,
4743 "neighbor <A.B.C.D|X:X::X:X|WORD> ebgp-multihop",
4744 NEIGHBOR_STR
4745 NEIGHBOR_ADDR_STR2
4746 "Allow EBGP neighbors not on directly connected networks\n")
4747 {
4748 int idx_peer = 1;
4749 return peer_ebgp_multihop_set_vty(vty, argv[idx_peer]->arg, NULL);
4750 }
4751
4752 DEFUN (neighbor_ebgp_multihop_ttl,
4753 neighbor_ebgp_multihop_ttl_cmd,
4754 "neighbor <A.B.C.D|X:X::X:X|WORD> ebgp-multihop (1-255)",
4755 NEIGHBOR_STR
4756 NEIGHBOR_ADDR_STR2
4757 "Allow EBGP neighbors not on directly connected networks\n"
4758 "maximum hop count\n")
4759 {
4760 int idx_peer = 1;
4761 int idx_number = 3;
4762 return peer_ebgp_multihop_set_vty(vty, argv[idx_peer]->arg,
4763 argv[idx_number]->arg);
4764 }
4765
4766 DEFUN (no_neighbor_ebgp_multihop,
4767 no_neighbor_ebgp_multihop_cmd,
4768 "no neighbor <A.B.C.D|X:X::X:X|WORD> ebgp-multihop [(1-255)]",
4769 NO_STR
4770 NEIGHBOR_STR
4771 NEIGHBOR_ADDR_STR2
4772 "Allow EBGP neighbors not on directly connected networks\n"
4773 "maximum hop count\n")
4774 {
4775 int idx_peer = 2;
4776 return peer_ebgp_multihop_unset_vty(vty, argv[idx_peer]->arg);
4777 }
4778
4779
4780 /* disable-connected-check */
4781 DEFUN (neighbor_disable_connected_check,
4782 neighbor_disable_connected_check_cmd,
4783 "neighbor <A.B.C.D|X:X::X:X|WORD> <disable-connected-check|enforce-multihop>",
4784 NEIGHBOR_STR
4785 NEIGHBOR_ADDR_STR2
4786 "one-hop away EBGP peer using loopback address\n"
4787 "Enforce EBGP neighbors perform multihop\n")
4788 {
4789 int idx_peer = 1;
4790 return peer_flag_set_vty(vty, argv[idx_peer]->arg,
4791 PEER_FLAG_DISABLE_CONNECTED_CHECK);
4792 }
4793
4794 DEFUN (no_neighbor_disable_connected_check,
4795 no_neighbor_disable_connected_check_cmd,
4796 "no neighbor <A.B.C.D|X:X::X:X|WORD> <disable-connected-check|enforce-multihop>",
4797 NO_STR
4798 NEIGHBOR_STR
4799 NEIGHBOR_ADDR_STR2
4800 "one-hop away EBGP peer using loopback address\n"
4801 "Enforce EBGP neighbors perform multihop\n")
4802 {
4803 int idx_peer = 2;
4804 return peer_flag_unset_vty(vty, argv[idx_peer]->arg,
4805 PEER_FLAG_DISABLE_CONNECTED_CHECK);
4806 }
4807
4808
4809 /* enforce-first-as */
4810 DEFUN (neighbor_enforce_first_as,
4811 neighbor_enforce_first_as_cmd,
4812 "neighbor <A.B.C.D|X:X::X:X|WORD> enforce-first-as",
4813 NEIGHBOR_STR
4814 NEIGHBOR_ADDR_STR2
4815 "Enforce the first AS for EBGP routes\n")
4816 {
4817 int idx_peer = 1;
4818
4819 return peer_flag_set_vty(vty, argv[idx_peer]->arg,
4820 PEER_FLAG_ENFORCE_FIRST_AS);
4821 }
4822
4823 DEFUN (no_neighbor_enforce_first_as,
4824 no_neighbor_enforce_first_as_cmd,
4825 "no neighbor <A.B.C.D|X:X::X:X|WORD> enforce-first-as",
4826 NO_STR
4827 NEIGHBOR_STR
4828 NEIGHBOR_ADDR_STR2
4829 "Enforce the first AS for EBGP routes\n")
4830 {
4831 int idx_peer = 2;
4832
4833 return peer_flag_unset_vty(vty, argv[idx_peer]->arg,
4834 PEER_FLAG_ENFORCE_FIRST_AS);
4835 }
4836
4837
4838 DEFUN (neighbor_description,
4839 neighbor_description_cmd,
4840 "neighbor <A.B.C.D|X:X::X:X|WORD> description LINE...",
4841 NEIGHBOR_STR
4842 NEIGHBOR_ADDR_STR2
4843 "Neighbor specific description\n"
4844 "Up to 80 characters describing this neighbor\n")
4845 {
4846 int idx_peer = 1;
4847 int idx_line = 3;
4848 struct peer *peer;
4849 char *str;
4850
4851 peer = peer_and_group_lookup_vty(vty, argv[idx_peer]->arg);
4852 if (!peer)
4853 return CMD_WARNING_CONFIG_FAILED;
4854
4855 str = argv_concat(argv, argc, idx_line);
4856
4857 peer_description_set(peer, str);
4858
4859 XFREE(MTYPE_TMP, str);
4860
4861 return CMD_SUCCESS;
4862 }
4863
4864 DEFUN (no_neighbor_description,
4865 no_neighbor_description_cmd,
4866 "no neighbor <A.B.C.D|X:X::X:X|WORD> description",
4867 NO_STR
4868 NEIGHBOR_STR
4869 NEIGHBOR_ADDR_STR2
4870 "Neighbor specific description\n")
4871 {
4872 int idx_peer = 2;
4873 struct peer *peer;
4874
4875 peer = peer_and_group_lookup_vty(vty, argv[idx_peer]->arg);
4876 if (!peer)
4877 return CMD_WARNING_CONFIG_FAILED;
4878
4879 peer_description_unset(peer);
4880
4881 return CMD_SUCCESS;
4882 }
4883
4884 ALIAS(no_neighbor_description, no_neighbor_description_comment_cmd,
4885 "no neighbor <A.B.C.D|X:X::X:X|WORD> description LINE...",
4886 NO_STR NEIGHBOR_STR NEIGHBOR_ADDR_STR2
4887 "Neighbor specific description\n"
4888 "Up to 80 characters describing this neighbor\n")
4889
4890 /* Neighbor update-source. */
4891 static int peer_update_source_vty(struct vty *vty, const char *peer_str,
4892 const char *source_str)
4893 {
4894 struct peer *peer;
4895 struct prefix p;
4896 union sockunion su;
4897
4898 peer = peer_and_group_lookup_vty(vty, peer_str);
4899 if (!peer)
4900 return CMD_WARNING_CONFIG_FAILED;
4901
4902 if (peer->conf_if)
4903 return CMD_WARNING;
4904
4905 if (source_str) {
4906 if (str2sockunion(source_str, &su) == 0)
4907 peer_update_source_addr_set(peer, &su);
4908 else {
4909 if (str2prefix(source_str, &p)) {
4910 vty_out(vty,
4911 "%% Invalid update-source, remove prefix length \n");
4912 return CMD_WARNING_CONFIG_FAILED;
4913 } else
4914 peer_update_source_if_set(peer, source_str);
4915 }
4916 } else
4917 peer_update_source_unset(peer);
4918
4919 return CMD_SUCCESS;
4920 }
4921
4922 #define BGP_UPDATE_SOURCE_HELP_STR \
4923 "IPv4 address\n" \
4924 "IPv6 address\n" \
4925 "Interface name (requires zebra to be running)\n"
4926
4927 DEFUN (neighbor_update_source,
4928 neighbor_update_source_cmd,
4929 "neighbor <A.B.C.D|X:X::X:X|WORD> update-source <A.B.C.D|X:X::X:X|WORD>",
4930 NEIGHBOR_STR
4931 NEIGHBOR_ADDR_STR2
4932 "Source of routing updates\n"
4933 BGP_UPDATE_SOURCE_HELP_STR)
4934 {
4935 int idx_peer = 1;
4936 int idx_peer_2 = 3;
4937 return peer_update_source_vty(vty, argv[idx_peer]->arg,
4938 argv[idx_peer_2]->arg);
4939 }
4940
4941 DEFUN (no_neighbor_update_source,
4942 no_neighbor_update_source_cmd,
4943 "no neighbor <A.B.C.D|X:X::X:X|WORD> update-source [<A.B.C.D|X:X::X:X|WORD>]",
4944 NO_STR
4945 NEIGHBOR_STR
4946 NEIGHBOR_ADDR_STR2
4947 "Source of routing updates\n"
4948 BGP_UPDATE_SOURCE_HELP_STR)
4949 {
4950 int idx_peer = 2;
4951 return peer_update_source_vty(vty, argv[idx_peer]->arg, NULL);
4952 }
4953
4954 static int peer_default_originate_set_vty(struct vty *vty, const char *peer_str,
4955 afi_t afi, safi_t safi,
4956 const char *rmap, int set)
4957 {
4958 int ret;
4959 struct peer *peer;
4960 struct route_map *route_map = NULL;
4961
4962 peer = peer_and_group_lookup_vty(vty, peer_str);
4963 if (!peer)
4964 return CMD_WARNING_CONFIG_FAILED;
4965
4966 if (set) {
4967 if (rmap)
4968 route_map = route_map_lookup_warn_noexist(vty, rmap);
4969 ret = peer_default_originate_set(peer, afi, safi,
4970 rmap, route_map);
4971 } else
4972 ret = peer_default_originate_unset(peer, afi, safi);
4973
4974 return bgp_vty_return(vty, ret);
4975 }
4976
4977 /* neighbor default-originate. */
4978 DEFUN (neighbor_default_originate,
4979 neighbor_default_originate_cmd,
4980 "neighbor <A.B.C.D|X:X::X:X|WORD> default-originate",
4981 NEIGHBOR_STR
4982 NEIGHBOR_ADDR_STR2
4983 "Originate default route to this neighbor\n")
4984 {
4985 int idx_peer = 1;
4986 return peer_default_originate_set_vty(vty, argv[idx_peer]->arg,
4987 bgp_node_afi(vty),
4988 bgp_node_safi(vty), NULL, 1);
4989 }
4990
4991 ALIAS_HIDDEN(neighbor_default_originate, neighbor_default_originate_hidden_cmd,
4992 "neighbor <A.B.C.D|X:X::X:X|WORD> default-originate",
4993 NEIGHBOR_STR NEIGHBOR_ADDR_STR2
4994 "Originate default route to this neighbor\n")
4995
4996 DEFUN (neighbor_default_originate_rmap,
4997 neighbor_default_originate_rmap_cmd,
4998 "neighbor <A.B.C.D|X:X::X:X|WORD> default-originate route-map WORD",
4999 NEIGHBOR_STR
5000 NEIGHBOR_ADDR_STR2
5001 "Originate default route to this neighbor\n"
5002 "Route-map to specify criteria to originate default\n"
5003 "route-map name\n")
5004 {
5005 int idx_peer = 1;
5006 int idx_word = 4;
5007 return peer_default_originate_set_vty(
5008 vty, argv[idx_peer]->arg, bgp_node_afi(vty), bgp_node_safi(vty),
5009 argv[idx_word]->arg, 1);
5010 }
5011
5012 ALIAS_HIDDEN(
5013 neighbor_default_originate_rmap,
5014 neighbor_default_originate_rmap_hidden_cmd,
5015 "neighbor <A.B.C.D|X:X::X:X|WORD> default-originate route-map WORD",
5016 NEIGHBOR_STR NEIGHBOR_ADDR_STR2
5017 "Originate default route to this neighbor\n"
5018 "Route-map to specify criteria to originate default\n"
5019 "route-map name\n")
5020
5021 DEFUN (no_neighbor_default_originate,
5022 no_neighbor_default_originate_cmd,
5023 "no neighbor <A.B.C.D|X:X::X:X|WORD> default-originate [route-map WORD]",
5024 NO_STR
5025 NEIGHBOR_STR
5026 NEIGHBOR_ADDR_STR2
5027 "Originate default route to this neighbor\n"
5028 "Route-map to specify criteria to originate default\n"
5029 "route-map name\n")
5030 {
5031 int idx_peer = 2;
5032 return peer_default_originate_set_vty(vty, argv[idx_peer]->arg,
5033 bgp_node_afi(vty),
5034 bgp_node_safi(vty), NULL, 0);
5035 }
5036
5037 ALIAS_HIDDEN(
5038 no_neighbor_default_originate, no_neighbor_default_originate_hidden_cmd,
5039 "no neighbor <A.B.C.D|X:X::X:X|WORD> default-originate [route-map WORD]",
5040 NO_STR NEIGHBOR_STR NEIGHBOR_ADDR_STR2
5041 "Originate default route to this neighbor\n"
5042 "Route-map to specify criteria to originate default\n"
5043 "route-map name\n")
5044
5045
5046 /* Set neighbor's BGP port. */
5047 static int peer_port_vty(struct vty *vty, const char *ip_str, int afi,
5048 const char *port_str)
5049 {
5050 struct peer *peer;
5051 uint16_t port;
5052 struct servent *sp;
5053
5054 peer = peer_lookup_vty(vty, ip_str);
5055 if (!peer)
5056 return CMD_WARNING_CONFIG_FAILED;
5057
5058 if (!port_str) {
5059 sp = getservbyname("bgp", "tcp");
5060 port = (sp == NULL) ? BGP_PORT_DEFAULT : ntohs(sp->s_port);
5061 } else {
5062 port = strtoul(port_str, NULL, 10);
5063 }
5064
5065 peer_port_set(peer, port);
5066
5067 return CMD_SUCCESS;
5068 }
5069
5070 /* Set specified peer's BGP port. */
5071 DEFUN (neighbor_port,
5072 neighbor_port_cmd,
5073 "neighbor <A.B.C.D|X:X::X:X> port (0-65535)",
5074 NEIGHBOR_STR
5075 NEIGHBOR_ADDR_STR
5076 "Neighbor's BGP port\n"
5077 "TCP port number\n")
5078 {
5079 int idx_ip = 1;
5080 int idx_number = 3;
5081 return peer_port_vty(vty, argv[idx_ip]->arg, AFI_IP,
5082 argv[idx_number]->arg);
5083 }
5084
5085 DEFUN (no_neighbor_port,
5086 no_neighbor_port_cmd,
5087 "no neighbor <A.B.C.D|X:X::X:X> port [(0-65535)]",
5088 NO_STR
5089 NEIGHBOR_STR
5090 NEIGHBOR_ADDR_STR
5091 "Neighbor's BGP port\n"
5092 "TCP port number\n")
5093 {
5094 int idx_ip = 2;
5095 return peer_port_vty(vty, argv[idx_ip]->arg, AFI_IP, NULL);
5096 }
5097
5098
5099 /* neighbor weight. */
5100 static int peer_weight_set_vty(struct vty *vty, const char *ip_str, afi_t afi,
5101 safi_t safi, const char *weight_str)
5102 {
5103 int ret;
5104 struct peer *peer;
5105 unsigned long weight;
5106
5107 peer = peer_and_group_lookup_vty(vty, ip_str);
5108 if (!peer)
5109 return CMD_WARNING_CONFIG_FAILED;
5110
5111 weight = strtoul(weight_str, NULL, 10);
5112
5113 ret = peer_weight_set(peer, afi, safi, weight);
5114 return bgp_vty_return(vty, ret);
5115 }
5116
5117 static int peer_weight_unset_vty(struct vty *vty, const char *ip_str, afi_t afi,
5118 safi_t safi)
5119 {
5120 int ret;
5121 struct peer *peer;
5122
5123 peer = peer_and_group_lookup_vty(vty, ip_str);
5124 if (!peer)
5125 return CMD_WARNING_CONFIG_FAILED;
5126
5127 ret = peer_weight_unset(peer, afi, safi);
5128 return bgp_vty_return(vty, ret);
5129 }
5130
5131 DEFUN (neighbor_weight,
5132 neighbor_weight_cmd,
5133 "neighbor <A.B.C.D|X:X::X:X|WORD> weight (0-65535)",
5134 NEIGHBOR_STR
5135 NEIGHBOR_ADDR_STR2
5136 "Set default weight for routes from this neighbor\n"
5137 "default weight\n")
5138 {
5139 int idx_peer = 1;
5140 int idx_number = 3;
5141 return peer_weight_set_vty(vty, argv[idx_peer]->arg, bgp_node_afi(vty),
5142 bgp_node_safi(vty), argv[idx_number]->arg);
5143 }
5144
5145 ALIAS_HIDDEN(neighbor_weight, neighbor_weight_hidden_cmd,
5146 "neighbor <A.B.C.D|X:X::X:X|WORD> weight (0-65535)",
5147 NEIGHBOR_STR NEIGHBOR_ADDR_STR2
5148 "Set default weight for routes from this neighbor\n"
5149 "default weight\n")
5150
5151 DEFUN (no_neighbor_weight,
5152 no_neighbor_weight_cmd,
5153 "no neighbor <A.B.C.D|X:X::X:X|WORD> weight [(0-65535)]",
5154 NO_STR
5155 NEIGHBOR_STR
5156 NEIGHBOR_ADDR_STR2
5157 "Set default weight for routes from this neighbor\n"
5158 "default weight\n")
5159 {
5160 int idx_peer = 2;
5161 return peer_weight_unset_vty(vty, argv[idx_peer]->arg,
5162 bgp_node_afi(vty), bgp_node_safi(vty));
5163 }
5164
5165 ALIAS_HIDDEN(no_neighbor_weight, no_neighbor_weight_hidden_cmd,
5166 "no neighbor <A.B.C.D|X:X::X:X|WORD> weight [(0-65535)]",
5167 NO_STR NEIGHBOR_STR NEIGHBOR_ADDR_STR2
5168 "Set default weight for routes from this neighbor\n"
5169 "default weight\n")
5170
5171
5172 /* Override capability negotiation. */
5173 DEFUN (neighbor_override_capability,
5174 neighbor_override_capability_cmd,
5175 "neighbor <A.B.C.D|X:X::X:X|WORD> override-capability",
5176 NEIGHBOR_STR
5177 NEIGHBOR_ADDR_STR2
5178 "Override capability negotiation result\n")
5179 {
5180 int idx_peer = 1;
5181 return peer_flag_set_vty(vty, argv[idx_peer]->arg,
5182 PEER_FLAG_OVERRIDE_CAPABILITY);
5183 }
5184
5185 DEFUN (no_neighbor_override_capability,
5186 no_neighbor_override_capability_cmd,
5187 "no neighbor <A.B.C.D|X:X::X:X|WORD> override-capability",
5188 NO_STR
5189 NEIGHBOR_STR
5190 NEIGHBOR_ADDR_STR2
5191 "Override capability negotiation result\n")
5192 {
5193 int idx_peer = 2;
5194 return peer_flag_unset_vty(vty, argv[idx_peer]->arg,
5195 PEER_FLAG_OVERRIDE_CAPABILITY);
5196 }
5197
5198 DEFUN (neighbor_strict_capability,
5199 neighbor_strict_capability_cmd,
5200 "neighbor <A.B.C.D|X:X::X:X|WORD> strict-capability-match",
5201 NEIGHBOR_STR
5202 NEIGHBOR_ADDR_STR2
5203 "Strict capability negotiation match\n")
5204 {
5205 int idx_peer = 1;
5206
5207 return peer_flag_set_vty(vty, argv[idx_peer]->arg,
5208 PEER_FLAG_STRICT_CAP_MATCH);
5209 }
5210
5211 DEFUN (no_neighbor_strict_capability,
5212 no_neighbor_strict_capability_cmd,
5213 "no neighbor <A.B.C.D|X:X::X:X|WORD> strict-capability-match",
5214 NO_STR
5215 NEIGHBOR_STR
5216 NEIGHBOR_ADDR_STR2
5217 "Strict capability negotiation match\n")
5218 {
5219 int idx_peer = 2;
5220
5221 return peer_flag_unset_vty(vty, argv[idx_peer]->arg,
5222 PEER_FLAG_STRICT_CAP_MATCH);
5223 }
5224
5225 static int peer_timers_set_vty(struct vty *vty, const char *ip_str,
5226 const char *keep_str, const char *hold_str)
5227 {
5228 int ret;
5229 struct peer *peer;
5230 uint32_t keepalive;
5231 uint32_t holdtime;
5232
5233 peer = peer_and_group_lookup_vty(vty, ip_str);
5234 if (!peer)
5235 return CMD_WARNING_CONFIG_FAILED;
5236
5237 keepalive = strtoul(keep_str, NULL, 10);
5238 holdtime = strtoul(hold_str, NULL, 10);
5239
5240 ret = peer_timers_set(peer, keepalive, holdtime);
5241
5242 return bgp_vty_return(vty, ret);
5243 }
5244
5245 static int peer_timers_unset_vty(struct vty *vty, const char *ip_str)
5246 {
5247 int ret;
5248 struct peer *peer;
5249
5250 peer = peer_and_group_lookup_vty(vty, ip_str);
5251 if (!peer)
5252 return CMD_WARNING_CONFIG_FAILED;
5253
5254 ret = peer_timers_unset(peer);
5255
5256 return bgp_vty_return(vty, ret);
5257 }
5258
5259 DEFUN (neighbor_timers,
5260 neighbor_timers_cmd,
5261 "neighbor <A.B.C.D|X:X::X:X|WORD> timers (0-65535) (0-65535)",
5262 NEIGHBOR_STR
5263 NEIGHBOR_ADDR_STR2
5264 "BGP per neighbor timers\n"
5265 "Keepalive interval\n"
5266 "Holdtime\n")
5267 {
5268 int idx_peer = 1;
5269 int idx_number = 3;
5270 int idx_number_2 = 4;
5271 return peer_timers_set_vty(vty, argv[idx_peer]->arg,
5272 argv[idx_number]->arg,
5273 argv[idx_number_2]->arg);
5274 }
5275
5276 DEFUN (no_neighbor_timers,
5277 no_neighbor_timers_cmd,
5278 "no neighbor <A.B.C.D|X:X::X:X|WORD> timers [(0-65535) (0-65535)]",
5279 NO_STR
5280 NEIGHBOR_STR
5281 NEIGHBOR_ADDR_STR2
5282 "BGP per neighbor timers\n"
5283 "Keepalive interval\n"
5284 "Holdtime\n")
5285 {
5286 int idx_peer = 2;
5287 return peer_timers_unset_vty(vty, argv[idx_peer]->arg);
5288 }
5289
5290
5291 static int peer_timers_connect_set_vty(struct vty *vty, const char *ip_str,
5292 const char *time_str)
5293 {
5294 int ret;
5295 struct peer *peer;
5296 uint32_t connect;
5297
5298 peer = peer_and_group_lookup_vty(vty, ip_str);
5299 if (!peer)
5300 return CMD_WARNING_CONFIG_FAILED;
5301
5302 connect = strtoul(time_str, NULL, 10);
5303
5304 ret = peer_timers_connect_set(peer, connect);
5305
5306 return bgp_vty_return(vty, ret);
5307 }
5308
5309 static int peer_timers_connect_unset_vty(struct vty *vty, const char *ip_str)
5310 {
5311 int ret;
5312 struct peer *peer;
5313
5314 peer = peer_and_group_lookup_vty(vty, ip_str);
5315 if (!peer)
5316 return CMD_WARNING_CONFIG_FAILED;
5317
5318 ret = peer_timers_connect_unset(peer);
5319
5320 return bgp_vty_return(vty, ret);
5321 }
5322
5323 DEFUN (neighbor_timers_connect,
5324 neighbor_timers_connect_cmd,
5325 "neighbor <A.B.C.D|X:X::X:X|WORD> timers connect (1-65535)",
5326 NEIGHBOR_STR
5327 NEIGHBOR_ADDR_STR2
5328 "BGP per neighbor timers\n"
5329 "BGP connect timer\n"
5330 "Connect timer\n")
5331 {
5332 int idx_peer = 1;
5333 int idx_number = 4;
5334 return peer_timers_connect_set_vty(vty, argv[idx_peer]->arg,
5335 argv[idx_number]->arg);
5336 }
5337
5338 DEFUN (no_neighbor_timers_connect,
5339 no_neighbor_timers_connect_cmd,
5340 "no neighbor <A.B.C.D|X:X::X:X|WORD> timers connect [(1-65535)]",
5341 NO_STR
5342 NEIGHBOR_STR
5343 NEIGHBOR_ADDR_STR2
5344 "BGP per neighbor timers\n"
5345 "BGP connect timer\n"
5346 "Connect timer\n")
5347 {
5348 int idx_peer = 2;
5349 return peer_timers_connect_unset_vty(vty, argv[idx_peer]->arg);
5350 }
5351
5352
5353 static int peer_advertise_interval_vty(struct vty *vty, const char *ip_str,
5354 const char *time_str, int set)
5355 {
5356 int ret;
5357 struct peer *peer;
5358 uint32_t routeadv = 0;
5359
5360 peer = peer_and_group_lookup_vty(vty, ip_str);
5361 if (!peer)
5362 return CMD_WARNING_CONFIG_FAILED;
5363
5364 if (time_str)
5365 routeadv = strtoul(time_str, NULL, 10);
5366
5367 if (set)
5368 ret = peer_advertise_interval_set(peer, routeadv);
5369 else
5370 ret = peer_advertise_interval_unset(peer);
5371
5372 return bgp_vty_return(vty, ret);
5373 }
5374
5375 DEFUN (neighbor_advertise_interval,
5376 neighbor_advertise_interval_cmd,
5377 "neighbor <A.B.C.D|X:X::X:X|WORD> advertisement-interval (0-600)",
5378 NEIGHBOR_STR
5379 NEIGHBOR_ADDR_STR2
5380 "Minimum interval between sending BGP routing updates\n"
5381 "time in seconds\n")
5382 {
5383 int idx_peer = 1;
5384 int idx_number = 3;
5385 return peer_advertise_interval_vty(vty, argv[idx_peer]->arg,
5386 argv[idx_number]->arg, 1);
5387 }
5388
5389 DEFUN (no_neighbor_advertise_interval,
5390 no_neighbor_advertise_interval_cmd,
5391 "no neighbor <A.B.C.D|X:X::X:X|WORD> advertisement-interval [(0-600)]",
5392 NO_STR
5393 NEIGHBOR_STR
5394 NEIGHBOR_ADDR_STR2
5395 "Minimum interval between sending BGP routing updates\n"
5396 "time in seconds\n")
5397 {
5398 int idx_peer = 2;
5399 return peer_advertise_interval_vty(vty, argv[idx_peer]->arg, NULL, 0);
5400 }
5401
5402
5403 /* Time to wait before processing route-map updates */
5404 DEFUN (bgp_set_route_map_delay_timer,
5405 bgp_set_route_map_delay_timer_cmd,
5406 "bgp route-map delay-timer (0-600)",
5407 SET_STR
5408 "BGP route-map delay timer\n"
5409 "Time in secs to wait before processing route-map changes\n"
5410 "0 disables the timer, no route updates happen when route-maps change\n")
5411 {
5412 int idx_number = 3;
5413 uint32_t rmap_delay_timer;
5414
5415 if (argv[idx_number]->arg) {
5416 rmap_delay_timer = strtoul(argv[idx_number]->arg, NULL, 10);
5417 bm->rmap_update_timer = rmap_delay_timer;
5418
5419 /* if the dynamic update handling is being disabled, and a timer
5420 * is
5421 * running, stop the timer and act as if the timer has already
5422 * fired.
5423 */
5424 if (!rmap_delay_timer && bm->t_rmap_update) {
5425 BGP_TIMER_OFF(bm->t_rmap_update);
5426 thread_execute(bm->master, bgp_route_map_update_timer,
5427 NULL, 0);
5428 }
5429 return CMD_SUCCESS;
5430 } else {
5431 vty_out(vty, "%% BGP invalid route-map delay-timer\n");
5432 return CMD_WARNING_CONFIG_FAILED;
5433 }
5434 }
5435
5436 DEFUN (no_bgp_set_route_map_delay_timer,
5437 no_bgp_set_route_map_delay_timer_cmd,
5438 "no bgp route-map delay-timer [(0-600)]",
5439 NO_STR
5440 BGP_STR
5441 "Default BGP route-map delay timer\n"
5442 "Reset to default time to wait for processing route-map changes\n"
5443 "0 disables the timer, no route updates happen when route-maps change\n")
5444 {
5445
5446 bm->rmap_update_timer = RMAP_DEFAULT_UPDATE_TIMER;
5447
5448 return CMD_SUCCESS;
5449 }
5450
5451
5452 /* neighbor interface */
5453 static int peer_interface_vty(struct vty *vty, const char *ip_str,
5454 const char *str)
5455 {
5456 struct peer *peer;
5457
5458 peer = peer_lookup_vty(vty, ip_str);
5459 if (!peer || peer->conf_if) {
5460 vty_out(vty, "%% BGP invalid peer %s\n", ip_str);
5461 return CMD_WARNING_CONFIG_FAILED;
5462 }
5463
5464 if (str)
5465 peer_interface_set(peer, str);
5466 else
5467 peer_interface_unset(peer);
5468
5469 return CMD_SUCCESS;
5470 }
5471
5472 DEFUN (neighbor_interface,
5473 neighbor_interface_cmd,
5474 "neighbor <A.B.C.D|X:X::X:X> interface WORD",
5475 NEIGHBOR_STR
5476 NEIGHBOR_ADDR_STR
5477 "Interface\n"
5478 "Interface name\n")
5479 {
5480 int idx_ip = 1;
5481 int idx_word = 3;
5482 return peer_interface_vty(vty, argv[idx_ip]->arg, argv[idx_word]->arg);
5483 }
5484
5485 DEFUN (no_neighbor_interface,
5486 no_neighbor_interface_cmd,
5487 "no neighbor <A.B.C.D|X:X::X:X|WORD> interface WORD",
5488 NO_STR
5489 NEIGHBOR_STR
5490 NEIGHBOR_ADDR_STR2
5491 "Interface\n"
5492 "Interface name\n")
5493 {
5494 int idx_peer = 2;
5495 return peer_interface_vty(vty, argv[idx_peer]->arg, NULL);
5496 }
5497
5498 DEFUN (neighbor_distribute_list,
5499 neighbor_distribute_list_cmd,
5500 "neighbor <A.B.C.D|X:X::X:X|WORD> distribute-list <(1-199)|(1300-2699)|WORD> <in|out>",
5501 NEIGHBOR_STR
5502 NEIGHBOR_ADDR_STR2
5503 "Filter updates to/from this neighbor\n"
5504 "IP access-list number\n"
5505 "IP access-list number (expanded range)\n"
5506 "IP Access-list name\n"
5507 "Filter incoming updates\n"
5508 "Filter outgoing updates\n")
5509 {
5510 int idx_peer = 1;
5511 int idx_acl = 3;
5512 int direct, ret;
5513 struct peer *peer;
5514
5515 const char *pstr = argv[idx_peer]->arg;
5516 const char *acl = argv[idx_acl]->arg;
5517 const char *inout = argv[argc - 1]->text;
5518
5519 peer = peer_and_group_lookup_vty(vty, pstr);
5520 if (!peer)
5521 return CMD_WARNING_CONFIG_FAILED;
5522
5523 /* Check filter direction. */
5524 direct = strmatch(inout, "in") ? FILTER_IN : FILTER_OUT;
5525 ret = peer_distribute_set(peer, bgp_node_afi(vty), bgp_node_safi(vty),
5526 direct, acl);
5527
5528 return bgp_vty_return(vty, ret);
5529 }
5530
5531 ALIAS_HIDDEN(
5532 neighbor_distribute_list, neighbor_distribute_list_hidden_cmd,
5533 "neighbor <A.B.C.D|X:X::X:X|WORD> distribute-list <(1-199)|(1300-2699)|WORD> <in|out>",
5534 NEIGHBOR_STR NEIGHBOR_ADDR_STR2
5535 "Filter updates to/from this neighbor\n"
5536 "IP access-list number\n"
5537 "IP access-list number (expanded range)\n"
5538 "IP Access-list name\n"
5539 "Filter incoming updates\n"
5540 "Filter outgoing updates\n")
5541
5542 DEFUN (no_neighbor_distribute_list,
5543 no_neighbor_distribute_list_cmd,
5544 "no neighbor <A.B.C.D|X:X::X:X|WORD> distribute-list <(1-199)|(1300-2699)|WORD> <in|out>",
5545 NO_STR
5546 NEIGHBOR_STR
5547 NEIGHBOR_ADDR_STR2
5548 "Filter updates to/from this neighbor\n"
5549 "IP access-list number\n"
5550 "IP access-list number (expanded range)\n"
5551 "IP Access-list name\n"
5552 "Filter incoming updates\n"
5553 "Filter outgoing updates\n")
5554 {
5555 int idx_peer = 2;
5556 int direct, ret;
5557 struct peer *peer;
5558
5559 const char *pstr = argv[idx_peer]->arg;
5560 const char *inout = argv[argc - 1]->text;
5561
5562 peer = peer_and_group_lookup_vty(vty, pstr);
5563 if (!peer)
5564 return CMD_WARNING_CONFIG_FAILED;
5565
5566 /* Check filter direction. */
5567 direct = strmatch(inout, "in") ? FILTER_IN : FILTER_OUT;
5568 ret = peer_distribute_unset(peer, bgp_node_afi(vty), bgp_node_safi(vty),
5569 direct);
5570
5571 return bgp_vty_return(vty, ret);
5572 }
5573
5574 ALIAS_HIDDEN(
5575 no_neighbor_distribute_list, no_neighbor_distribute_list_hidden_cmd,
5576 "no neighbor <A.B.C.D|X:X::X:X|WORD> distribute-list <(1-199)|(1300-2699)|WORD> <in|out>",
5577 NO_STR NEIGHBOR_STR NEIGHBOR_ADDR_STR2
5578 "Filter updates to/from this neighbor\n"
5579 "IP access-list number\n"
5580 "IP access-list number (expanded range)\n"
5581 "IP Access-list name\n"
5582 "Filter incoming updates\n"
5583 "Filter outgoing updates\n")
5584
5585 /* Set prefix list to the peer. */
5586 static int peer_prefix_list_set_vty(struct vty *vty, const char *ip_str,
5587 afi_t afi, safi_t safi,
5588 const char *name_str,
5589 const char *direct_str)
5590 {
5591 int ret;
5592 int direct = FILTER_IN;
5593 struct peer *peer;
5594
5595 peer = peer_and_group_lookup_vty(vty, ip_str);
5596 if (!peer)
5597 return CMD_WARNING_CONFIG_FAILED;
5598
5599 /* Check filter direction. */
5600 if (strncmp(direct_str, "i", 1) == 0)
5601 direct = FILTER_IN;
5602 else if (strncmp(direct_str, "o", 1) == 0)
5603 direct = FILTER_OUT;
5604
5605 ret = peer_prefix_list_set(peer, afi, safi, direct, name_str);
5606
5607 return bgp_vty_return(vty, ret);
5608 }
5609
5610 static int peer_prefix_list_unset_vty(struct vty *vty, const char *ip_str,
5611 afi_t afi, safi_t safi,
5612 const char *direct_str)
5613 {
5614 int ret;
5615 struct peer *peer;
5616 int direct = FILTER_IN;
5617
5618 peer = peer_and_group_lookup_vty(vty, ip_str);
5619 if (!peer)
5620 return CMD_WARNING_CONFIG_FAILED;
5621
5622 /* Check filter direction. */
5623 if (strncmp(direct_str, "i", 1) == 0)
5624 direct = FILTER_IN;
5625 else if (strncmp(direct_str, "o", 1) == 0)
5626 direct = FILTER_OUT;
5627
5628 ret = peer_prefix_list_unset(peer, afi, safi, direct);
5629
5630 return bgp_vty_return(vty, ret);
5631 }
5632
5633 DEFUN (neighbor_prefix_list,
5634 neighbor_prefix_list_cmd,
5635 "neighbor <A.B.C.D|X:X::X:X|WORD> prefix-list WORD <in|out>",
5636 NEIGHBOR_STR
5637 NEIGHBOR_ADDR_STR2
5638 "Filter updates to/from this neighbor\n"
5639 "Name of a prefix list\n"
5640 "Filter incoming updates\n"
5641 "Filter outgoing updates\n")
5642 {
5643 int idx_peer = 1;
5644 int idx_word = 3;
5645 int idx_in_out = 4;
5646 return peer_prefix_list_set_vty(
5647 vty, argv[idx_peer]->arg, bgp_node_afi(vty), bgp_node_safi(vty),
5648 argv[idx_word]->arg, argv[idx_in_out]->arg);
5649 }
5650
5651 ALIAS_HIDDEN(neighbor_prefix_list, neighbor_prefix_list_hidden_cmd,
5652 "neighbor <A.B.C.D|X:X::X:X|WORD> prefix-list WORD <in|out>",
5653 NEIGHBOR_STR NEIGHBOR_ADDR_STR2
5654 "Filter updates to/from this neighbor\n"
5655 "Name of a prefix list\n"
5656 "Filter incoming updates\n"
5657 "Filter outgoing updates\n")
5658
5659 DEFUN (no_neighbor_prefix_list,
5660 no_neighbor_prefix_list_cmd,
5661 "no neighbor <A.B.C.D|X:X::X:X|WORD> prefix-list WORD <in|out>",
5662 NO_STR
5663 NEIGHBOR_STR
5664 NEIGHBOR_ADDR_STR2
5665 "Filter updates to/from this neighbor\n"
5666 "Name of a prefix list\n"
5667 "Filter incoming updates\n"
5668 "Filter outgoing updates\n")
5669 {
5670 int idx_peer = 2;
5671 int idx_in_out = 5;
5672 return peer_prefix_list_unset_vty(vty, argv[idx_peer]->arg,
5673 bgp_node_afi(vty), bgp_node_safi(vty),
5674 argv[idx_in_out]->arg);
5675 }
5676
5677 ALIAS_HIDDEN(no_neighbor_prefix_list, no_neighbor_prefix_list_hidden_cmd,
5678 "no neighbor <A.B.C.D|X:X::X:X|WORD> prefix-list WORD <in|out>",
5679 NO_STR NEIGHBOR_STR NEIGHBOR_ADDR_STR2
5680 "Filter updates to/from this neighbor\n"
5681 "Name of a prefix list\n"
5682 "Filter incoming updates\n"
5683 "Filter outgoing updates\n")
5684
5685 static int peer_aslist_set_vty(struct vty *vty, const char *ip_str, afi_t afi,
5686 safi_t safi, const char *name_str,
5687 const char *direct_str)
5688 {
5689 int ret;
5690 struct peer *peer;
5691 int direct = FILTER_IN;
5692
5693 peer = peer_and_group_lookup_vty(vty, ip_str);
5694 if (!peer)
5695 return CMD_WARNING_CONFIG_FAILED;
5696
5697 /* Check filter direction. */
5698 if (strncmp(direct_str, "i", 1) == 0)
5699 direct = FILTER_IN;
5700 else if (strncmp(direct_str, "o", 1) == 0)
5701 direct = FILTER_OUT;
5702
5703 ret = peer_aslist_set(peer, afi, safi, direct, name_str);
5704
5705 return bgp_vty_return(vty, ret);
5706 }
5707
5708 static int peer_aslist_unset_vty(struct vty *vty, const char *ip_str, afi_t afi,
5709 safi_t safi, const char *direct_str)
5710 {
5711 int ret;
5712 struct peer *peer;
5713 int direct = FILTER_IN;
5714
5715 peer = peer_and_group_lookup_vty(vty, ip_str);
5716 if (!peer)
5717 return CMD_WARNING_CONFIG_FAILED;
5718
5719 /* Check filter direction. */
5720 if (strncmp(direct_str, "i", 1) == 0)
5721 direct = FILTER_IN;
5722 else if (strncmp(direct_str, "o", 1) == 0)
5723 direct = FILTER_OUT;
5724
5725 ret = peer_aslist_unset(peer, afi, safi, direct);
5726
5727 return bgp_vty_return(vty, ret);
5728 }
5729
5730 DEFUN (neighbor_filter_list,
5731 neighbor_filter_list_cmd,
5732 "neighbor <A.B.C.D|X:X::X:X|WORD> filter-list WORD <in|out>",
5733 NEIGHBOR_STR
5734 NEIGHBOR_ADDR_STR2
5735 "Establish BGP filters\n"
5736 "AS path access-list name\n"
5737 "Filter incoming routes\n"
5738 "Filter outgoing routes\n")
5739 {
5740 int idx_peer = 1;
5741 int idx_word = 3;
5742 int idx_in_out = 4;
5743 return peer_aslist_set_vty(vty, argv[idx_peer]->arg, bgp_node_afi(vty),
5744 bgp_node_safi(vty), argv[idx_word]->arg,
5745 argv[idx_in_out]->arg);
5746 }
5747
5748 ALIAS_HIDDEN(neighbor_filter_list, neighbor_filter_list_hidden_cmd,
5749 "neighbor <A.B.C.D|X:X::X:X|WORD> filter-list WORD <in|out>",
5750 NEIGHBOR_STR NEIGHBOR_ADDR_STR2
5751 "Establish BGP filters\n"
5752 "AS path access-list name\n"
5753 "Filter incoming routes\n"
5754 "Filter outgoing routes\n")
5755
5756 DEFUN (no_neighbor_filter_list,
5757 no_neighbor_filter_list_cmd,
5758 "no neighbor <A.B.C.D|X:X::X:X|WORD> filter-list WORD <in|out>",
5759 NO_STR
5760 NEIGHBOR_STR
5761 NEIGHBOR_ADDR_STR2
5762 "Establish BGP filters\n"
5763 "AS path access-list name\n"
5764 "Filter incoming routes\n"
5765 "Filter outgoing routes\n")
5766 {
5767 int idx_peer = 2;
5768 int idx_in_out = 5;
5769 return peer_aslist_unset_vty(vty, argv[idx_peer]->arg,
5770 bgp_node_afi(vty), bgp_node_safi(vty),
5771 argv[idx_in_out]->arg);
5772 }
5773
5774 ALIAS_HIDDEN(no_neighbor_filter_list, no_neighbor_filter_list_hidden_cmd,
5775 "no neighbor <A.B.C.D|X:X::X:X|WORD> filter-list WORD <in|out>",
5776 NO_STR NEIGHBOR_STR NEIGHBOR_ADDR_STR2
5777 "Establish BGP filters\n"
5778 "AS path access-list name\n"
5779 "Filter incoming routes\n"
5780 "Filter outgoing routes\n")
5781
5782 /* Set route-map to the peer. */
5783 static int peer_route_map_set_vty(struct vty *vty, const char *ip_str,
5784 afi_t afi, safi_t safi, const char *name_str,
5785 const char *direct_str)
5786 {
5787 int ret;
5788 struct peer *peer;
5789 int direct = RMAP_IN;
5790 struct route_map *route_map;
5791
5792 peer = peer_and_group_lookup_vty(vty, ip_str);
5793 if (!peer)
5794 return CMD_WARNING_CONFIG_FAILED;
5795
5796 /* Check filter direction. */
5797 if (strncmp(direct_str, "in", 2) == 0)
5798 direct = RMAP_IN;
5799 else if (strncmp(direct_str, "o", 1) == 0)
5800 direct = RMAP_OUT;
5801
5802 route_map = route_map_lookup_warn_noexist(vty, name_str);
5803 ret = peer_route_map_set(peer, afi, safi, direct, name_str, route_map);
5804
5805 return bgp_vty_return(vty, ret);
5806 }
5807
5808 static int peer_route_map_unset_vty(struct vty *vty, const char *ip_str,
5809 afi_t afi, safi_t safi,
5810 const char *direct_str)
5811 {
5812 int ret;
5813 struct peer *peer;
5814 int direct = RMAP_IN;
5815
5816 peer = peer_and_group_lookup_vty(vty, ip_str);
5817 if (!peer)
5818 return CMD_WARNING_CONFIG_FAILED;
5819
5820 /* Check filter direction. */
5821 if (strncmp(direct_str, "in", 2) == 0)
5822 direct = RMAP_IN;
5823 else if (strncmp(direct_str, "o", 1) == 0)
5824 direct = RMAP_OUT;
5825
5826 ret = peer_route_map_unset(peer, afi, safi, direct);
5827
5828 return bgp_vty_return(vty, ret);
5829 }
5830
5831 DEFUN (neighbor_route_map,
5832 neighbor_route_map_cmd,
5833 "neighbor <A.B.C.D|X:X::X:X|WORD> route-map WORD <in|out>",
5834 NEIGHBOR_STR
5835 NEIGHBOR_ADDR_STR2
5836 "Apply route map to neighbor\n"
5837 "Name of route map\n"
5838 "Apply map to incoming routes\n"
5839 "Apply map to outbound routes\n")
5840 {
5841 int idx_peer = 1;
5842 int idx_word = 3;
5843 int idx_in_out = 4;
5844 return peer_route_map_set_vty(
5845 vty, argv[idx_peer]->arg, bgp_node_afi(vty), bgp_node_safi(vty),
5846 argv[idx_word]->arg, argv[idx_in_out]->arg);
5847 }
5848
5849 ALIAS_HIDDEN(neighbor_route_map, neighbor_route_map_hidden_cmd,
5850 "neighbor <A.B.C.D|X:X::X:X|WORD> route-map WORD <in|out>",
5851 NEIGHBOR_STR NEIGHBOR_ADDR_STR2
5852 "Apply route map to neighbor\n"
5853 "Name of route map\n"
5854 "Apply map to incoming routes\n"
5855 "Apply map to outbound routes\n")
5856
5857 DEFUN (no_neighbor_route_map,
5858 no_neighbor_route_map_cmd,
5859 "no neighbor <A.B.C.D|X:X::X:X|WORD> route-map WORD <in|out>",
5860 NO_STR
5861 NEIGHBOR_STR
5862 NEIGHBOR_ADDR_STR2
5863 "Apply route map to neighbor\n"
5864 "Name of route map\n"
5865 "Apply map to incoming routes\n"
5866 "Apply map to outbound routes\n")
5867 {
5868 int idx_peer = 2;
5869 int idx_in_out = 5;
5870 return peer_route_map_unset_vty(vty, argv[idx_peer]->arg,
5871 bgp_node_afi(vty), bgp_node_safi(vty),
5872 argv[idx_in_out]->arg);
5873 }
5874
5875 ALIAS_HIDDEN(no_neighbor_route_map, no_neighbor_route_map_hidden_cmd,
5876 "no neighbor <A.B.C.D|X:X::X:X|WORD> route-map WORD <in|out>",
5877 NO_STR NEIGHBOR_STR NEIGHBOR_ADDR_STR2
5878 "Apply route map to neighbor\n"
5879 "Name of route map\n"
5880 "Apply map to incoming routes\n"
5881 "Apply map to outbound routes\n")
5882
5883 /* Set unsuppress-map to the peer. */
5884 static int peer_unsuppress_map_set_vty(struct vty *vty, const char *ip_str,
5885 afi_t afi, safi_t safi,
5886 const char *name_str)
5887 {
5888 int ret;
5889 struct peer *peer;
5890 struct route_map *route_map;
5891
5892 peer = peer_and_group_lookup_vty(vty, ip_str);
5893 if (!peer)
5894 return CMD_WARNING_CONFIG_FAILED;
5895
5896 route_map = route_map_lookup_warn_noexist(vty, name_str);
5897 ret = peer_unsuppress_map_set(peer, afi, safi, name_str, route_map);
5898
5899 return bgp_vty_return(vty, ret);
5900 }
5901
5902 /* Unset route-map from the peer. */
5903 static int peer_unsuppress_map_unset_vty(struct vty *vty, const char *ip_str,
5904 afi_t afi, safi_t safi)
5905 {
5906 int ret;
5907 struct peer *peer;
5908
5909 peer = peer_and_group_lookup_vty(vty, ip_str);
5910 if (!peer)
5911 return CMD_WARNING_CONFIG_FAILED;
5912
5913 ret = peer_unsuppress_map_unset(peer, afi, safi);
5914
5915 return bgp_vty_return(vty, ret);
5916 }
5917
5918 DEFUN (neighbor_unsuppress_map,
5919 neighbor_unsuppress_map_cmd,
5920 "neighbor <A.B.C.D|X:X::X:X|WORD> unsuppress-map WORD",
5921 NEIGHBOR_STR
5922 NEIGHBOR_ADDR_STR2
5923 "Route-map to selectively unsuppress suppressed routes\n"
5924 "Name of route map\n")
5925 {
5926 int idx_peer = 1;
5927 int idx_word = 3;
5928 return peer_unsuppress_map_set_vty(
5929 vty, argv[idx_peer]->arg, bgp_node_afi(vty), bgp_node_safi(vty),
5930 argv[idx_word]->arg);
5931 }
5932
5933 ALIAS_HIDDEN(neighbor_unsuppress_map, neighbor_unsuppress_map_hidden_cmd,
5934 "neighbor <A.B.C.D|X:X::X:X|WORD> unsuppress-map WORD",
5935 NEIGHBOR_STR NEIGHBOR_ADDR_STR2
5936 "Route-map to selectively unsuppress suppressed routes\n"
5937 "Name of route map\n")
5938
5939 DEFUN (no_neighbor_unsuppress_map,
5940 no_neighbor_unsuppress_map_cmd,
5941 "no neighbor <A.B.C.D|X:X::X:X|WORD> unsuppress-map WORD",
5942 NO_STR
5943 NEIGHBOR_STR
5944 NEIGHBOR_ADDR_STR2
5945 "Route-map to selectively unsuppress suppressed routes\n"
5946 "Name of route map\n")
5947 {
5948 int idx_peer = 2;
5949 return peer_unsuppress_map_unset_vty(vty, argv[idx_peer]->arg,
5950 bgp_node_afi(vty),
5951 bgp_node_safi(vty));
5952 }
5953
5954 ALIAS_HIDDEN(no_neighbor_unsuppress_map, no_neighbor_unsuppress_map_hidden_cmd,
5955 "no neighbor <A.B.C.D|X:X::X:X|WORD> unsuppress-map WORD",
5956 NO_STR NEIGHBOR_STR NEIGHBOR_ADDR_STR2
5957 "Route-map to selectively unsuppress suppressed routes\n"
5958 "Name of route map\n")
5959
5960 static int peer_maximum_prefix_set_vty(struct vty *vty, const char *ip_str,
5961 afi_t afi, safi_t safi,
5962 const char *num_str,
5963 const char *threshold_str, int warning,
5964 const char *restart_str)
5965 {
5966 int ret;
5967 struct peer *peer;
5968 uint32_t max;
5969 uint8_t threshold;
5970 uint16_t restart;
5971
5972 peer = peer_and_group_lookup_vty(vty, ip_str);
5973 if (!peer)
5974 return CMD_WARNING_CONFIG_FAILED;
5975
5976 max = strtoul(num_str, NULL, 10);
5977 if (threshold_str)
5978 threshold = atoi(threshold_str);
5979 else
5980 threshold = MAXIMUM_PREFIX_THRESHOLD_DEFAULT;
5981
5982 if (restart_str)
5983 restart = atoi(restart_str);
5984 else
5985 restart = 0;
5986
5987 ret = peer_maximum_prefix_set(peer, afi, safi, max, threshold, warning,
5988 restart);
5989
5990 return bgp_vty_return(vty, ret);
5991 }
5992
5993 static int peer_maximum_prefix_unset_vty(struct vty *vty, const char *ip_str,
5994 afi_t afi, safi_t safi)
5995 {
5996 int ret;
5997 struct peer *peer;
5998
5999 peer = peer_and_group_lookup_vty(vty, ip_str);
6000 if (!peer)
6001 return CMD_WARNING_CONFIG_FAILED;
6002
6003 ret = peer_maximum_prefix_unset(peer, afi, safi);
6004
6005 return bgp_vty_return(vty, ret);
6006 }
6007
6008 /* Maximum number of prefix configuration. prefix count is different
6009 for each peer configuration. So this configuration can be set for
6010 each peer configuration. */
6011 DEFUN (neighbor_maximum_prefix,
6012 neighbor_maximum_prefix_cmd,
6013 "neighbor <A.B.C.D|X:X::X:X|WORD> maximum-prefix (1-4294967295)",
6014 NEIGHBOR_STR
6015 NEIGHBOR_ADDR_STR2
6016 "Maximum number of prefix accept from this peer\n"
6017 "maximum no. of prefix limit\n")
6018 {
6019 int idx_peer = 1;
6020 int idx_number = 3;
6021 return peer_maximum_prefix_set_vty(
6022 vty, argv[idx_peer]->arg, bgp_node_afi(vty), bgp_node_safi(vty),
6023 argv[idx_number]->arg, NULL, 0, NULL);
6024 }
6025
6026 ALIAS_HIDDEN(neighbor_maximum_prefix, neighbor_maximum_prefix_hidden_cmd,
6027 "neighbor <A.B.C.D|X:X::X:X|WORD> maximum-prefix (1-4294967295)",
6028 NEIGHBOR_STR NEIGHBOR_ADDR_STR2
6029 "Maximum number of prefix accept from this peer\n"
6030 "maximum no. of prefix limit\n")
6031
6032 DEFUN (neighbor_maximum_prefix_threshold,
6033 neighbor_maximum_prefix_threshold_cmd,
6034 "neighbor <A.B.C.D|X:X::X:X|WORD> maximum-prefix (1-4294967295) (1-100)",
6035 NEIGHBOR_STR
6036 NEIGHBOR_ADDR_STR2
6037 "Maximum number of prefix accept from this peer\n"
6038 "maximum no. of prefix limit\n"
6039 "Threshold value (%) at which to generate a warning msg\n")
6040 {
6041 int idx_peer = 1;
6042 int idx_number = 3;
6043 int idx_number_2 = 4;
6044 return peer_maximum_prefix_set_vty(
6045 vty, argv[idx_peer]->arg, bgp_node_afi(vty), bgp_node_safi(vty),
6046 argv[idx_number]->arg, argv[idx_number_2]->arg, 0, NULL);
6047 }
6048
6049 ALIAS_HIDDEN(
6050 neighbor_maximum_prefix_threshold,
6051 neighbor_maximum_prefix_threshold_hidden_cmd,
6052 "neighbor <A.B.C.D|X:X::X:X|WORD> maximum-prefix (1-4294967295) (1-100)",
6053 NEIGHBOR_STR NEIGHBOR_ADDR_STR2
6054 "Maximum number of prefix accept from this peer\n"
6055 "maximum no. of prefix limit\n"
6056 "Threshold value (%) at which to generate a warning msg\n")
6057
6058 DEFUN (neighbor_maximum_prefix_warning,
6059 neighbor_maximum_prefix_warning_cmd,
6060 "neighbor <A.B.C.D|X:X::X:X|WORD> maximum-prefix (1-4294967295) warning-only",
6061 NEIGHBOR_STR
6062 NEIGHBOR_ADDR_STR2
6063 "Maximum number of prefix accept from this peer\n"
6064 "maximum no. of prefix limit\n"
6065 "Only give warning message when limit is exceeded\n")
6066 {
6067 int idx_peer = 1;
6068 int idx_number = 3;
6069 return peer_maximum_prefix_set_vty(
6070 vty, argv[idx_peer]->arg, bgp_node_afi(vty), bgp_node_safi(vty),
6071 argv[idx_number]->arg, NULL, 1, NULL);
6072 }
6073
6074 ALIAS_HIDDEN(
6075 neighbor_maximum_prefix_warning,
6076 neighbor_maximum_prefix_warning_hidden_cmd,
6077 "neighbor <A.B.C.D|X:X::X:X|WORD> maximum-prefix (1-4294967295) warning-only",
6078 NEIGHBOR_STR NEIGHBOR_ADDR_STR2
6079 "Maximum number of prefix accept from this peer\n"
6080 "maximum no. of prefix limit\n"
6081 "Only give warning message when limit is exceeded\n")
6082
6083 DEFUN (neighbor_maximum_prefix_threshold_warning,
6084 neighbor_maximum_prefix_threshold_warning_cmd,
6085 "neighbor <A.B.C.D|X:X::X:X|WORD> maximum-prefix (1-4294967295) (1-100) warning-only",
6086 NEIGHBOR_STR
6087 NEIGHBOR_ADDR_STR2
6088 "Maximum number of prefix accept from this peer\n"
6089 "maximum no. of prefix limit\n"
6090 "Threshold value (%) at which to generate a warning msg\n"
6091 "Only give warning message when limit is exceeded\n")
6092 {
6093 int idx_peer = 1;
6094 int idx_number = 3;
6095 int idx_number_2 = 4;
6096 return peer_maximum_prefix_set_vty(
6097 vty, argv[idx_peer]->arg, bgp_node_afi(vty), bgp_node_safi(vty),
6098 argv[idx_number]->arg, argv[idx_number_2]->arg, 1, NULL);
6099 }
6100
6101 ALIAS_HIDDEN(
6102 neighbor_maximum_prefix_threshold_warning,
6103 neighbor_maximum_prefix_threshold_warning_hidden_cmd,
6104 "neighbor <A.B.C.D|X:X::X:X|WORD> maximum-prefix (1-4294967295) (1-100) warning-only",
6105 NEIGHBOR_STR NEIGHBOR_ADDR_STR2
6106 "Maximum number of prefix accept from this peer\n"
6107 "maximum no. of prefix limit\n"
6108 "Threshold value (%) at which to generate a warning msg\n"
6109 "Only give warning message when limit is exceeded\n")
6110
6111 DEFUN (neighbor_maximum_prefix_restart,
6112 neighbor_maximum_prefix_restart_cmd,
6113 "neighbor <A.B.C.D|X:X::X:X|WORD> maximum-prefix (1-4294967295) restart (1-65535)",
6114 NEIGHBOR_STR
6115 NEIGHBOR_ADDR_STR2
6116 "Maximum number of prefix accept from this peer\n"
6117 "maximum no. of prefix limit\n"
6118 "Restart bgp connection after limit is exceeded\n"
6119 "Restart interval in minutes\n")
6120 {
6121 int idx_peer = 1;
6122 int idx_number = 3;
6123 int idx_number_2 = 5;
6124 return peer_maximum_prefix_set_vty(
6125 vty, argv[idx_peer]->arg, bgp_node_afi(vty), bgp_node_safi(vty),
6126 argv[idx_number]->arg, NULL, 0, argv[idx_number_2]->arg);
6127 }
6128
6129 ALIAS_HIDDEN(
6130 neighbor_maximum_prefix_restart,
6131 neighbor_maximum_prefix_restart_hidden_cmd,
6132 "neighbor <A.B.C.D|X:X::X:X|WORD> maximum-prefix (1-4294967295) restart (1-65535)",
6133 NEIGHBOR_STR NEIGHBOR_ADDR_STR2
6134 "Maximum number of prefix accept from this peer\n"
6135 "maximum no. of prefix limit\n"
6136 "Restart bgp connection after limit is exceeded\n"
6137 "Restart interval in minutes\n")
6138
6139 DEFUN (neighbor_maximum_prefix_threshold_restart,
6140 neighbor_maximum_prefix_threshold_restart_cmd,
6141 "neighbor <A.B.C.D|X:X::X:X|WORD> maximum-prefix (1-4294967295) (1-100) restart (1-65535)",
6142 NEIGHBOR_STR
6143 NEIGHBOR_ADDR_STR2
6144 "Maximum number of prefixes to accept from this peer\n"
6145 "maximum no. of prefix limit\n"
6146 "Threshold value (%) at which to generate a warning msg\n"
6147 "Restart bgp connection after limit is exceeded\n"
6148 "Restart interval in minutes\n")
6149 {
6150 int idx_peer = 1;
6151 int idx_number = 3;
6152 int idx_number_2 = 4;
6153 int idx_number_3 = 6;
6154 return peer_maximum_prefix_set_vty(
6155 vty, argv[idx_peer]->arg, bgp_node_afi(vty), bgp_node_safi(vty),
6156 argv[idx_number]->arg, argv[idx_number_2]->arg, 0,
6157 argv[idx_number_3]->arg);
6158 }
6159
6160 ALIAS_HIDDEN(
6161 neighbor_maximum_prefix_threshold_restart,
6162 neighbor_maximum_prefix_threshold_restart_hidden_cmd,
6163 "neighbor <A.B.C.D|X:X::X:X|WORD> maximum-prefix (1-4294967295) (1-100) restart (1-65535)",
6164 NEIGHBOR_STR NEIGHBOR_ADDR_STR2
6165 "Maximum number of prefixes to accept from this peer\n"
6166 "maximum no. of prefix limit\n"
6167 "Threshold value (%) at which to generate a warning msg\n"
6168 "Restart bgp connection after limit is exceeded\n"
6169 "Restart interval in minutes\n")
6170
6171 DEFUN (no_neighbor_maximum_prefix,
6172 no_neighbor_maximum_prefix_cmd,
6173 "no neighbor <A.B.C.D|X:X::X:X|WORD> maximum-prefix [(1-4294967295) [(1-100)] [restart (1-65535)] [warning-only]]",
6174 NO_STR
6175 NEIGHBOR_STR
6176 NEIGHBOR_ADDR_STR2
6177 "Maximum number of prefixes to accept from this peer\n"
6178 "maximum no. of prefix limit\n"
6179 "Threshold value (%) at which to generate a warning msg\n"
6180 "Restart bgp connection after limit is exceeded\n"
6181 "Restart interval in minutes\n"
6182 "Only give warning message when limit is exceeded\n")
6183 {
6184 int idx_peer = 2;
6185 return peer_maximum_prefix_unset_vty(vty, argv[idx_peer]->arg,
6186 bgp_node_afi(vty),
6187 bgp_node_safi(vty));
6188 }
6189
6190 ALIAS_HIDDEN(
6191 no_neighbor_maximum_prefix, no_neighbor_maximum_prefix_hidden_cmd,
6192 "no neighbor <A.B.C.D|X:X::X:X|WORD> maximum-prefix [(1-4294967295) [(1-100)] [restart (1-65535)] [warning-only]]",
6193 NO_STR NEIGHBOR_STR NEIGHBOR_ADDR_STR2
6194 "Maximum number of prefixes to accept from this peer\n"
6195 "maximum no. of prefix limit\n"
6196 "Threshold value (%) at which to generate a warning msg\n"
6197 "Restart bgp connection after limit is exceeded\n"
6198 "Restart interval in minutes\n"
6199 "Only give warning message when limit is exceeded\n")
6200
6201
6202 /* "neighbor allowas-in" */
6203 DEFUN (neighbor_allowas_in,
6204 neighbor_allowas_in_cmd,
6205 "neighbor <A.B.C.D|X:X::X:X|WORD> allowas-in [<(1-10)|origin>]",
6206 NEIGHBOR_STR
6207 NEIGHBOR_ADDR_STR2
6208 "Accept as-path with my AS present in it\n"
6209 "Number of occurrences of AS number\n"
6210 "Only accept my AS in the as-path if the route was originated in my AS\n")
6211 {
6212 int idx_peer = 1;
6213 int idx_number_origin = 3;
6214 int ret;
6215 int origin = 0;
6216 struct peer *peer;
6217 int allow_num = 0;
6218
6219 peer = peer_and_group_lookup_vty(vty, argv[idx_peer]->arg);
6220 if (!peer)
6221 return CMD_WARNING_CONFIG_FAILED;
6222
6223 if (argc <= idx_number_origin)
6224 allow_num = 3;
6225 else {
6226 if (argv[idx_number_origin]->type == WORD_TKN)
6227 origin = 1;
6228 else
6229 allow_num = atoi(argv[idx_number_origin]->arg);
6230 }
6231
6232 ret = peer_allowas_in_set(peer, bgp_node_afi(vty), bgp_node_safi(vty),
6233 allow_num, origin);
6234
6235 return bgp_vty_return(vty, ret);
6236 }
6237
6238 ALIAS_HIDDEN(
6239 neighbor_allowas_in, neighbor_allowas_in_hidden_cmd,
6240 "neighbor <A.B.C.D|X:X::X:X|WORD> allowas-in [<(1-10)|origin>]",
6241 NEIGHBOR_STR NEIGHBOR_ADDR_STR2
6242 "Accept as-path with my AS present in it\n"
6243 "Number of occurrences of AS number\n"
6244 "Only accept my AS in the as-path if the route was originated in my AS\n")
6245
6246 DEFUN (no_neighbor_allowas_in,
6247 no_neighbor_allowas_in_cmd,
6248 "no neighbor <A.B.C.D|X:X::X:X|WORD> allowas-in [<(1-10)|origin>]",
6249 NO_STR
6250 NEIGHBOR_STR
6251 NEIGHBOR_ADDR_STR2
6252 "allow local ASN appears in aspath attribute\n"
6253 "Number of occurrences of AS number\n"
6254 "Only accept my AS in the as-path if the route was originated in my AS\n")
6255 {
6256 int idx_peer = 2;
6257 int ret;
6258 struct peer *peer;
6259
6260 peer = peer_and_group_lookup_vty(vty, argv[idx_peer]->arg);
6261 if (!peer)
6262 return CMD_WARNING_CONFIG_FAILED;
6263
6264 ret = peer_allowas_in_unset(peer, bgp_node_afi(vty),
6265 bgp_node_safi(vty));
6266
6267 return bgp_vty_return(vty, ret);
6268 }
6269
6270 ALIAS_HIDDEN(
6271 no_neighbor_allowas_in, no_neighbor_allowas_in_hidden_cmd,
6272 "no neighbor <A.B.C.D|X:X::X:X|WORD> allowas-in [<(1-10)|origin>]",
6273 NO_STR NEIGHBOR_STR NEIGHBOR_ADDR_STR2
6274 "allow local ASN appears in aspath attribute\n"
6275 "Number of occurrences of AS number\n"
6276 "Only accept my AS in the as-path if the route was originated in my AS\n")
6277
6278 DEFUN (neighbor_ttl_security,
6279 neighbor_ttl_security_cmd,
6280 "neighbor <A.B.C.D|X:X::X:X|WORD> ttl-security hops (1-254)",
6281 NEIGHBOR_STR
6282 NEIGHBOR_ADDR_STR2
6283 "BGP ttl-security parameters\n"
6284 "Specify the maximum number of hops to the BGP peer\n"
6285 "Number of hops to BGP peer\n")
6286 {
6287 int idx_peer = 1;
6288 int idx_number = 4;
6289 struct peer *peer;
6290 int gtsm_hops;
6291
6292 peer = peer_and_group_lookup_vty(vty, argv[idx_peer]->arg);
6293 if (!peer)
6294 return CMD_WARNING_CONFIG_FAILED;
6295
6296 gtsm_hops = strtoul(argv[idx_number]->arg, NULL, 10);
6297
6298 /*
6299 * If 'neighbor swpX', then this is for directly connected peers,
6300 * we should not accept a ttl-security hops value greater than 1.
6301 */
6302 if (peer->conf_if && (gtsm_hops > 1)) {
6303 vty_out(vty,
6304 "%s is directly connected peer, hops cannot exceed 1\n",
6305 argv[idx_peer]->arg);
6306 return CMD_WARNING_CONFIG_FAILED;
6307 }
6308
6309 return bgp_vty_return(vty, peer_ttl_security_hops_set(peer, gtsm_hops));
6310 }
6311
6312 DEFUN (no_neighbor_ttl_security,
6313 no_neighbor_ttl_security_cmd,
6314 "no neighbor <A.B.C.D|X:X::X:X|WORD> ttl-security hops (1-254)",
6315 NO_STR
6316 NEIGHBOR_STR
6317 NEIGHBOR_ADDR_STR2
6318 "BGP ttl-security parameters\n"
6319 "Specify the maximum number of hops to the BGP peer\n"
6320 "Number of hops to BGP peer\n")
6321 {
6322 int idx_peer = 2;
6323 struct peer *peer;
6324
6325 peer = peer_and_group_lookup_vty(vty, argv[idx_peer]->arg);
6326 if (!peer)
6327 return CMD_WARNING_CONFIG_FAILED;
6328
6329 return bgp_vty_return(vty, peer_ttl_security_hops_unset(peer));
6330 }
6331
6332 DEFUN (neighbor_addpath_tx_all_paths,
6333 neighbor_addpath_tx_all_paths_cmd,
6334 "neighbor <A.B.C.D|X:X::X:X|WORD> addpath-tx-all-paths",
6335 NEIGHBOR_STR
6336 NEIGHBOR_ADDR_STR2
6337 "Use addpath to advertise all paths to a neighbor\n")
6338 {
6339 int idx_peer = 1;
6340 struct peer *peer;
6341
6342 peer = peer_and_group_lookup_vty(vty, argv[idx_peer]->arg);
6343 if (!peer)
6344 return CMD_WARNING_CONFIG_FAILED;
6345
6346 bgp_addpath_set_peer_type(peer, bgp_node_afi(vty), bgp_node_safi(vty),
6347 BGP_ADDPATH_ALL);
6348 return CMD_SUCCESS;
6349 }
6350
6351 ALIAS_HIDDEN(neighbor_addpath_tx_all_paths,
6352 neighbor_addpath_tx_all_paths_hidden_cmd,
6353 "neighbor <A.B.C.D|X:X::X:X|WORD> addpath-tx-all-paths",
6354 NEIGHBOR_STR NEIGHBOR_ADDR_STR2
6355 "Use addpath to advertise all paths to a neighbor\n")
6356
6357 DEFUN (no_neighbor_addpath_tx_all_paths,
6358 no_neighbor_addpath_tx_all_paths_cmd,
6359 "no neighbor <A.B.C.D|X:X::X:X|WORD> addpath-tx-all-paths",
6360 NO_STR
6361 NEIGHBOR_STR
6362 NEIGHBOR_ADDR_STR2
6363 "Use addpath to advertise all paths to a neighbor\n")
6364 {
6365 int idx_peer = 2;
6366 struct peer *peer;
6367
6368 peer = peer_and_group_lookup_vty(vty, argv[idx_peer]->arg);
6369 if (!peer)
6370 return CMD_WARNING_CONFIG_FAILED;
6371
6372 if (peer->addpath_type[bgp_node_afi(vty)][bgp_node_safi(vty)]
6373 != BGP_ADDPATH_ALL) {
6374 vty_out(vty,
6375 "%% Peer not currently configured to transmit all paths.");
6376 return CMD_WARNING_CONFIG_FAILED;
6377 }
6378
6379 bgp_addpath_set_peer_type(peer, bgp_node_afi(vty), bgp_node_safi(vty),
6380 BGP_ADDPATH_NONE);
6381
6382 return CMD_SUCCESS;
6383 }
6384
6385 ALIAS_HIDDEN(no_neighbor_addpath_tx_all_paths,
6386 no_neighbor_addpath_tx_all_paths_hidden_cmd,
6387 "no neighbor <A.B.C.D|X:X::X:X|WORD> addpath-tx-all-paths",
6388 NO_STR NEIGHBOR_STR NEIGHBOR_ADDR_STR2
6389 "Use addpath to advertise all paths to a neighbor\n")
6390
6391 DEFUN (neighbor_addpath_tx_bestpath_per_as,
6392 neighbor_addpath_tx_bestpath_per_as_cmd,
6393 "neighbor <A.B.C.D|X:X::X:X|WORD> addpath-tx-bestpath-per-AS",
6394 NEIGHBOR_STR
6395 NEIGHBOR_ADDR_STR2
6396 "Use addpath to advertise the bestpath per each neighboring AS\n")
6397 {
6398 int idx_peer = 1;
6399 struct peer *peer;
6400
6401 peer = peer_and_group_lookup_vty(vty, argv[idx_peer]->arg);
6402 if (!peer)
6403 return CMD_WARNING_CONFIG_FAILED;
6404
6405 bgp_addpath_set_peer_type(peer, bgp_node_afi(vty), bgp_node_safi(vty),
6406 BGP_ADDPATH_BEST_PER_AS);
6407
6408 return CMD_SUCCESS;
6409 }
6410
6411 ALIAS_HIDDEN(neighbor_addpath_tx_bestpath_per_as,
6412 neighbor_addpath_tx_bestpath_per_as_hidden_cmd,
6413 "neighbor <A.B.C.D|X:X::X:X|WORD> addpath-tx-bestpath-per-AS",
6414 NEIGHBOR_STR NEIGHBOR_ADDR_STR2
6415 "Use addpath to advertise the bestpath per each neighboring AS\n")
6416
6417 DEFUN (no_neighbor_addpath_tx_bestpath_per_as,
6418 no_neighbor_addpath_tx_bestpath_per_as_cmd,
6419 "no neighbor <A.B.C.D|X:X::X:X|WORD> addpath-tx-bestpath-per-AS",
6420 NO_STR
6421 NEIGHBOR_STR
6422 NEIGHBOR_ADDR_STR2
6423 "Use addpath to advertise the bestpath per each neighboring AS\n")
6424 {
6425 int idx_peer = 2;
6426 struct peer *peer;
6427
6428 peer = peer_and_group_lookup_vty(vty, argv[idx_peer]->arg);
6429 if (!peer)
6430 return CMD_WARNING_CONFIG_FAILED;
6431
6432 if (peer->addpath_type[bgp_node_afi(vty)][bgp_node_safi(vty)]
6433 != BGP_ADDPATH_BEST_PER_AS) {
6434 vty_out(vty,
6435 "%% Peer not currently configured to transmit all best path per as.");
6436 return CMD_WARNING_CONFIG_FAILED;
6437 }
6438
6439 bgp_addpath_set_peer_type(peer, bgp_node_afi(vty), bgp_node_safi(vty),
6440 BGP_ADDPATH_NONE);
6441
6442 return CMD_SUCCESS;
6443 }
6444
6445 ALIAS_HIDDEN(no_neighbor_addpath_tx_bestpath_per_as,
6446 no_neighbor_addpath_tx_bestpath_per_as_hidden_cmd,
6447 "no neighbor <A.B.C.D|X:X::X:X|WORD> addpath-tx-bestpath-per-AS",
6448 NO_STR NEIGHBOR_STR NEIGHBOR_ADDR_STR2
6449 "Use addpath to advertise the bestpath per each neighboring AS\n")
6450
6451 DEFPY(
6452 neighbor_aspath_loop_detection, neighbor_aspath_loop_detection_cmd,
6453 "neighbor <A.B.C.D|X:X::X:X|WORD>$neighbor sender-as-path-loop-detection",
6454 NEIGHBOR_STR
6455 NEIGHBOR_ADDR_STR2
6456 "Detect AS loops before sending to neighbor\n")
6457 {
6458 struct peer *peer;
6459
6460 peer = peer_and_group_lookup_vty(vty, neighbor);
6461 if (!peer)
6462 return CMD_WARNING_CONFIG_FAILED;
6463
6464 peer->as_path_loop_detection = true;
6465
6466 return CMD_SUCCESS;
6467 }
6468
6469 DEFPY(
6470 no_neighbor_aspath_loop_detection,
6471 no_neighbor_aspath_loop_detection_cmd,
6472 "no neighbor <A.B.C.D|X:X::X:X|WORD>$neighbor sender-as-path-loop-detection",
6473 NO_STR
6474 NEIGHBOR_STR
6475 NEIGHBOR_ADDR_STR2
6476 "Detect AS loops before sending to neighbor\n")
6477 {
6478 struct peer *peer;
6479
6480 peer = peer_and_group_lookup_vty(vty, neighbor);
6481 if (!peer)
6482 return CMD_WARNING_CONFIG_FAILED;
6483
6484 peer->as_path_loop_detection = false;
6485
6486 return CMD_SUCCESS;
6487 }
6488
6489 static int set_ecom_list(struct vty *vty, int argc, struct cmd_token **argv,
6490 struct ecommunity **list)
6491 {
6492 struct ecommunity *ecom = NULL;
6493 struct ecommunity *ecomadd;
6494
6495 for (; argc; --argc, ++argv) {
6496
6497 ecomadd = ecommunity_str2com(argv[0]->arg,
6498 ECOMMUNITY_ROUTE_TARGET, 0);
6499 if (!ecomadd) {
6500 vty_out(vty, "Malformed community-list value\n");
6501 if (ecom)
6502 ecommunity_free(&ecom);
6503 return CMD_WARNING_CONFIG_FAILED;
6504 }
6505
6506 if (ecom) {
6507 ecommunity_merge(ecom, ecomadd);
6508 ecommunity_free(&ecomadd);
6509 } else {
6510 ecom = ecomadd;
6511 }
6512 }
6513
6514 if (*list) {
6515 ecommunity_free(&*list);
6516 }
6517 *list = ecom;
6518
6519 return CMD_SUCCESS;
6520 }
6521
6522 /*
6523 * v2vimport is true if we are handling a `import vrf ...` command
6524 */
6525 static afi_t vpn_policy_getafi(struct vty *vty, struct bgp *bgp, bool v2vimport)
6526 {
6527 afi_t afi;
6528
6529 switch (vty->node) {
6530 case BGP_IPV4_NODE:
6531 afi = AFI_IP;
6532 break;
6533 case BGP_IPV6_NODE:
6534 afi = AFI_IP6;
6535 break;
6536 default:
6537 vty_out(vty,
6538 "%% context error: valid only in address-family <ipv4|ipv6> unicast block\n");
6539 return AFI_MAX;
6540 }
6541
6542 if (!v2vimport) {
6543 if (CHECK_FLAG(bgp->af_flags[afi][SAFI_UNICAST],
6544 BGP_CONFIG_VRF_TO_VRF_IMPORT)
6545 || CHECK_FLAG(bgp->af_flags[afi][SAFI_UNICAST],
6546 BGP_CONFIG_VRF_TO_VRF_EXPORT)) {
6547 vty_out(vty,
6548 "%% error: Please unconfigure import vrf commands before using vpn commands\n");
6549 return AFI_MAX;
6550 }
6551 } else {
6552 if (CHECK_FLAG(bgp->af_flags[afi][SAFI_UNICAST],
6553 BGP_CONFIG_VRF_TO_MPLSVPN_EXPORT)
6554 || CHECK_FLAG(bgp->af_flags[afi][SAFI_UNICAST],
6555 BGP_CONFIG_MPLSVPN_TO_VRF_IMPORT)) {
6556 vty_out(vty,
6557 "%% error: Please unconfigure vpn to vrf commands before using import vrf commands\n");
6558 return AFI_MAX;
6559 }
6560 }
6561 return afi;
6562 }
6563
6564 DEFPY (af_rd_vpn_export,
6565 af_rd_vpn_export_cmd,
6566 "[no] rd vpn export ASN:NN_OR_IP-ADDRESS:NN$rd_str",
6567 NO_STR
6568 "Specify route distinguisher\n"
6569 "Between current address-family and vpn\n"
6570 "For routes leaked from current address-family to vpn\n"
6571 "Route Distinguisher (<as-number>:<number> | <ip-address>:<number>)\n")
6572 {
6573 VTY_DECLVAR_CONTEXT(bgp, bgp);
6574 struct prefix_rd prd;
6575 int ret;
6576 afi_t afi;
6577 int idx = 0;
6578 int yes = 1;
6579
6580 if (argv_find(argv, argc, "no", &idx))
6581 yes = 0;
6582
6583 if (yes) {
6584 ret = str2prefix_rd(rd_str, &prd);
6585 if (!ret) {
6586 vty_out(vty, "%% Malformed rd\n");
6587 return CMD_WARNING_CONFIG_FAILED;
6588 }
6589 }
6590
6591 afi = vpn_policy_getafi(vty, bgp, false);
6592 if (afi == AFI_MAX)
6593 return CMD_WARNING_CONFIG_FAILED;
6594
6595 /*
6596 * pre-change: un-export vpn routes (vpn->vrf routes unaffected)
6597 */
6598 vpn_leak_prechange(BGP_VPN_POLICY_DIR_TOVPN, afi,
6599 bgp_get_default(), bgp);
6600
6601 if (yes) {
6602 bgp->vpn_policy[afi].tovpn_rd = prd;
6603 SET_FLAG(bgp->vpn_policy[afi].flags,
6604 BGP_VPN_POLICY_TOVPN_RD_SET);
6605 } else {
6606 UNSET_FLAG(bgp->vpn_policy[afi].flags,
6607 BGP_VPN_POLICY_TOVPN_RD_SET);
6608 }
6609
6610 /* post-change: re-export vpn routes */
6611 vpn_leak_postchange(BGP_VPN_POLICY_DIR_TOVPN, afi,
6612 bgp_get_default(), bgp);
6613
6614 return CMD_SUCCESS;
6615 }
6616
6617 ALIAS (af_rd_vpn_export,
6618 af_no_rd_vpn_export_cmd,
6619 "no rd vpn export",
6620 NO_STR
6621 "Specify route distinguisher\n"
6622 "Between current address-family and vpn\n"
6623 "For routes leaked from current address-family to vpn\n")
6624
6625 DEFPY (af_label_vpn_export,
6626 af_label_vpn_export_cmd,
6627 "[no] label vpn export <(0-1048575)$label_val|auto$label_auto>",
6628 NO_STR
6629 "label value for VRF\n"
6630 "Between current address-family and vpn\n"
6631 "For routes leaked from current address-family to vpn\n"
6632 "Label Value <0-1048575>\n"
6633 "Automatically assign a label\n")
6634 {
6635 VTY_DECLVAR_CONTEXT(bgp, bgp);
6636 mpls_label_t label = MPLS_LABEL_NONE;
6637 afi_t afi;
6638 int idx = 0;
6639 int yes = 1;
6640
6641 if (argv_find(argv, argc, "no", &idx))
6642 yes = 0;
6643
6644 /* If "no ...", squash trailing parameter */
6645 if (!yes)
6646 label_auto = NULL;
6647
6648 if (yes) {
6649 if (!label_auto)
6650 label = label_val; /* parser should force unsigned */
6651 }
6652
6653 afi = vpn_policy_getafi(vty, bgp, false);
6654 if (afi == AFI_MAX)
6655 return CMD_WARNING_CONFIG_FAILED;
6656
6657
6658 if (label_auto && CHECK_FLAG(bgp->vpn_policy[afi].flags,
6659 BGP_VPN_POLICY_TOVPN_LABEL_AUTO))
6660 /* no change */
6661 return CMD_SUCCESS;
6662
6663 /*
6664 * pre-change: un-export vpn routes (vpn->vrf routes unaffected)
6665 */
6666 vpn_leak_prechange(BGP_VPN_POLICY_DIR_TOVPN, afi,
6667 bgp_get_default(), bgp);
6668
6669 if (!label_auto && CHECK_FLAG(bgp->vpn_policy[afi].flags,
6670 BGP_VPN_POLICY_TOVPN_LABEL_AUTO)) {
6671
6672 if (bgp->vpn_policy[afi].tovpn_label != MPLS_LABEL_NONE) {
6673
6674 /*
6675 * label has previously been automatically
6676 * assigned by labelpool: release it
6677 *
6678 * NB if tovpn_label == MPLS_LABEL_NONE it
6679 * means the automatic assignment is in flight
6680 * and therefore the labelpool callback must
6681 * detect that the auto label is not needed.
6682 */
6683
6684 bgp_lp_release(LP_TYPE_VRF,
6685 &bgp->vpn_policy[afi],
6686 bgp->vpn_policy[afi].tovpn_label);
6687 }
6688 UNSET_FLAG(bgp->vpn_policy[afi].flags,
6689 BGP_VPN_POLICY_TOVPN_LABEL_AUTO);
6690 }
6691
6692 bgp->vpn_policy[afi].tovpn_label = label;
6693 if (label_auto) {
6694 SET_FLAG(bgp->vpn_policy[afi].flags,
6695 BGP_VPN_POLICY_TOVPN_LABEL_AUTO);
6696 bgp_lp_get(LP_TYPE_VRF, &bgp->vpn_policy[afi],
6697 vpn_leak_label_callback);
6698 }
6699
6700 /* post-change: re-export vpn routes */
6701 vpn_leak_postchange(BGP_VPN_POLICY_DIR_TOVPN, afi,
6702 bgp_get_default(), bgp);
6703
6704 return CMD_SUCCESS;
6705 }
6706
6707 ALIAS (af_label_vpn_export,
6708 af_no_label_vpn_export_cmd,
6709 "no label vpn export",
6710 NO_STR
6711 "label value for VRF\n"
6712 "Between current address-family and vpn\n"
6713 "For routes leaked from current address-family to vpn\n")
6714
6715 DEFPY (af_nexthop_vpn_export,
6716 af_nexthop_vpn_export_cmd,
6717 "[no] nexthop vpn export <A.B.C.D|X:X::X:X>$nexthop_str",
6718 NO_STR
6719 "Specify next hop to use for VRF advertised prefixes\n"
6720 "Between current address-family and vpn\n"
6721 "For routes leaked from current address-family to vpn\n"
6722 "IPv4 prefix\n"
6723 "IPv6 prefix\n")
6724 {
6725 VTY_DECLVAR_CONTEXT(bgp, bgp);
6726 afi_t afi;
6727 struct prefix p;
6728 int idx = 0;
6729 int yes = 1;
6730
6731 if (argv_find(argv, argc, "no", &idx))
6732 yes = 0;
6733
6734 if (yes) {
6735 if (!sockunion2hostprefix(nexthop_str, &p))
6736 return CMD_WARNING_CONFIG_FAILED;
6737 }
6738
6739 afi = vpn_policy_getafi(vty, bgp, false);
6740 if (afi == AFI_MAX)
6741 return CMD_WARNING_CONFIG_FAILED;
6742
6743 /*
6744 * pre-change: un-export vpn routes (vpn->vrf routes unaffected)
6745 */
6746 vpn_leak_prechange(BGP_VPN_POLICY_DIR_TOVPN, afi,
6747 bgp_get_default(), bgp);
6748
6749 if (yes) {
6750 bgp->vpn_policy[afi].tovpn_nexthop = p;
6751 SET_FLAG(bgp->vpn_policy[afi].flags,
6752 BGP_VPN_POLICY_TOVPN_NEXTHOP_SET);
6753 } else {
6754 UNSET_FLAG(bgp->vpn_policy[afi].flags,
6755 BGP_VPN_POLICY_TOVPN_NEXTHOP_SET);
6756 }
6757
6758 /* post-change: re-export vpn routes */
6759 vpn_leak_postchange(BGP_VPN_POLICY_DIR_TOVPN, afi,
6760 bgp_get_default(), bgp);
6761
6762 return CMD_SUCCESS;
6763 }
6764
6765 ALIAS (af_nexthop_vpn_export,
6766 af_no_nexthop_vpn_export_cmd,
6767 "no nexthop vpn export",
6768 NO_STR
6769 "Specify next hop to use for VRF advertised prefixes\n"
6770 "Between current address-family and vpn\n"
6771 "For routes leaked from current address-family to vpn\n")
6772
6773 static int vpn_policy_getdirs(struct vty *vty, const char *dstr, int *dodir)
6774 {
6775 if (!strcmp(dstr, "import")) {
6776 dodir[BGP_VPN_POLICY_DIR_FROMVPN] = 1;
6777 } else if (!strcmp(dstr, "export")) {
6778 dodir[BGP_VPN_POLICY_DIR_TOVPN] = 1;
6779 } else if (!strcmp(dstr, "both")) {
6780 dodir[BGP_VPN_POLICY_DIR_FROMVPN] = 1;
6781 dodir[BGP_VPN_POLICY_DIR_TOVPN] = 1;
6782 } else {
6783 vty_out(vty, "%% direction parse error\n");
6784 return CMD_WARNING_CONFIG_FAILED;
6785 }
6786 return CMD_SUCCESS;
6787 }
6788
6789 DEFPY (af_rt_vpn_imexport,
6790 af_rt_vpn_imexport_cmd,
6791 "[no] <rt|route-target> vpn <import|export|both>$direction_str RTLIST...",
6792 NO_STR
6793 "Specify route target list\n"
6794 "Specify route target list\n"
6795 "Between current address-family and vpn\n"
6796 "For routes leaked from vpn to current address-family: match any\n"
6797 "For routes leaked from current address-family to vpn: set\n"
6798 "both import: match any and export: set\n"
6799 "Space separated route target list (A.B.C.D:MN|EF:OPQR|GHJK:MN)\n")
6800 {
6801 VTY_DECLVAR_CONTEXT(bgp, bgp);
6802 int ret;
6803 struct ecommunity *ecom = NULL;
6804 int dodir[BGP_VPN_POLICY_DIR_MAX] = {0};
6805 vpn_policy_direction_t dir;
6806 afi_t afi;
6807 int idx = 0;
6808 int yes = 1;
6809
6810 if (argv_find(argv, argc, "no", &idx))
6811 yes = 0;
6812
6813 afi = vpn_policy_getafi(vty, bgp, false);
6814 if (afi == AFI_MAX)
6815 return CMD_WARNING_CONFIG_FAILED;
6816
6817 ret = vpn_policy_getdirs(vty, direction_str, dodir);
6818 if (ret != CMD_SUCCESS)
6819 return ret;
6820
6821 if (yes) {
6822 if (!argv_find(argv, argc, "RTLIST", &idx)) {
6823 vty_out(vty, "%% Missing RTLIST\n");
6824 return CMD_WARNING_CONFIG_FAILED;
6825 }
6826 ret = set_ecom_list(vty, argc - idx, argv + idx, &ecom);
6827 if (ret != CMD_SUCCESS) {
6828 return ret;
6829 }
6830 }
6831
6832 for (dir = 0; dir < BGP_VPN_POLICY_DIR_MAX; ++dir) {
6833 if (!dodir[dir])
6834 continue;
6835
6836 vpn_leak_prechange(dir, afi, bgp_get_default(), bgp);
6837
6838 if (yes) {
6839 if (bgp->vpn_policy[afi].rtlist[dir])
6840 ecommunity_free(
6841 &bgp->vpn_policy[afi].rtlist[dir]);
6842 bgp->vpn_policy[afi].rtlist[dir] =
6843 ecommunity_dup(ecom);
6844 } else {
6845 if (bgp->vpn_policy[afi].rtlist[dir])
6846 ecommunity_free(
6847 &bgp->vpn_policy[afi].rtlist[dir]);
6848 bgp->vpn_policy[afi].rtlist[dir] = NULL;
6849 }
6850
6851 vpn_leak_postchange(dir, afi, bgp_get_default(), bgp);
6852 }
6853
6854 if (ecom)
6855 ecommunity_free(&ecom);
6856
6857 return CMD_SUCCESS;
6858 }
6859
6860 ALIAS (af_rt_vpn_imexport,
6861 af_no_rt_vpn_imexport_cmd,
6862 "no <rt|route-target> vpn <import|export|both>$direction_str",
6863 NO_STR
6864 "Specify route target list\n"
6865 "Specify route target list\n"
6866 "Between current address-family and vpn\n"
6867 "For routes leaked from vpn to current address-family\n"
6868 "For routes leaked from current address-family to vpn\n"
6869 "both import and export\n")
6870
6871 DEFPY (af_route_map_vpn_imexport,
6872 af_route_map_vpn_imexport_cmd,
6873 /* future: "route-map <vpn|evpn|vrf NAME> <import|export> RMAP" */
6874 "[no] route-map vpn <import|export>$direction_str RMAP$rmap_str",
6875 NO_STR
6876 "Specify route map\n"
6877 "Between current address-family and vpn\n"
6878 "For routes leaked from vpn to current address-family\n"
6879 "For routes leaked from current address-family to vpn\n"
6880 "name of route-map\n")
6881 {
6882 VTY_DECLVAR_CONTEXT(bgp, bgp);
6883 int ret;
6884 int dodir[BGP_VPN_POLICY_DIR_MAX] = {0};
6885 vpn_policy_direction_t dir;
6886 afi_t afi;
6887 int idx = 0;
6888 int yes = 1;
6889
6890 if (argv_find(argv, argc, "no", &idx))
6891 yes = 0;
6892
6893 afi = vpn_policy_getafi(vty, bgp, false);
6894 if (afi == AFI_MAX)
6895 return CMD_WARNING_CONFIG_FAILED;
6896
6897 ret = vpn_policy_getdirs(vty, direction_str, dodir);
6898 if (ret != CMD_SUCCESS)
6899 return ret;
6900
6901 for (dir = 0; dir < BGP_VPN_POLICY_DIR_MAX; ++dir) {
6902 if (!dodir[dir])
6903 continue;
6904
6905 vpn_leak_prechange(dir, afi, bgp_get_default(), bgp);
6906
6907 if (yes) {
6908 if (bgp->vpn_policy[afi].rmap_name[dir])
6909 XFREE(MTYPE_ROUTE_MAP_NAME,
6910 bgp->vpn_policy[afi].rmap_name[dir]);
6911 bgp->vpn_policy[afi].rmap_name[dir] = XSTRDUP(
6912 MTYPE_ROUTE_MAP_NAME, rmap_str);
6913 bgp->vpn_policy[afi].rmap[dir] =
6914 route_map_lookup_warn_noexist(vty, rmap_str);
6915 if (!bgp->vpn_policy[afi].rmap[dir])
6916 return CMD_SUCCESS;
6917 } else {
6918 if (bgp->vpn_policy[afi].rmap_name[dir])
6919 XFREE(MTYPE_ROUTE_MAP_NAME,
6920 bgp->vpn_policy[afi].rmap_name[dir]);
6921 bgp->vpn_policy[afi].rmap_name[dir] = NULL;
6922 bgp->vpn_policy[afi].rmap[dir] = NULL;
6923 }
6924
6925 vpn_leak_postchange(dir, afi, bgp_get_default(), bgp);
6926 }
6927
6928 return CMD_SUCCESS;
6929 }
6930
6931 ALIAS (af_route_map_vpn_imexport,
6932 af_no_route_map_vpn_imexport_cmd,
6933 "no route-map vpn <import|export>$direction_str",
6934 NO_STR
6935 "Specify route map\n"
6936 "Between current address-family and vpn\n"
6937 "For routes leaked from vpn to current address-family\n"
6938 "For routes leaked from current address-family to vpn\n")
6939
6940 DEFPY(af_import_vrf_route_map, af_import_vrf_route_map_cmd,
6941 "[no] import vrf route-map RMAP$rmap_str",
6942 NO_STR
6943 "Import routes from another VRF\n"
6944 "Vrf routes being filtered\n"
6945 "Specify route map\n"
6946 "name of route-map\n")
6947 {
6948 VTY_DECLVAR_CONTEXT(bgp, bgp);
6949 vpn_policy_direction_t dir = BGP_VPN_POLICY_DIR_FROMVPN;
6950 afi_t afi;
6951 int idx = 0;
6952 int yes = 1;
6953 struct bgp *bgp_default;
6954
6955 if (argv_find(argv, argc, "no", &idx))
6956 yes = 0;
6957
6958 afi = vpn_policy_getafi(vty, bgp, true);
6959 if (afi == AFI_MAX)
6960 return CMD_WARNING_CONFIG_FAILED;
6961
6962 bgp_default = bgp_get_default();
6963 if (!bgp_default) {
6964 int32_t ret;
6965 as_t as = bgp->as;
6966
6967 /* Auto-create assuming the same AS */
6968 ret = bgp_get(&bgp_default, &as, NULL,
6969 BGP_INSTANCE_TYPE_DEFAULT);
6970
6971 if (ret) {
6972 vty_out(vty,
6973 "VRF default is not configured as a bgp instance\n");
6974 return CMD_WARNING;
6975 }
6976 }
6977
6978 vpn_leak_prechange(dir, afi, bgp_get_default(), bgp);
6979
6980 if (yes) {
6981 if (bgp->vpn_policy[afi].rmap_name[dir])
6982 XFREE(MTYPE_ROUTE_MAP_NAME,
6983 bgp->vpn_policy[afi].rmap_name[dir]);
6984 bgp->vpn_policy[afi].rmap_name[dir] =
6985 XSTRDUP(MTYPE_ROUTE_MAP_NAME, rmap_str);
6986 bgp->vpn_policy[afi].rmap[dir] =
6987 route_map_lookup_warn_noexist(vty, rmap_str);
6988 if (!bgp->vpn_policy[afi].rmap[dir])
6989 return CMD_SUCCESS;
6990 } else {
6991 if (bgp->vpn_policy[afi].rmap_name[dir])
6992 XFREE(MTYPE_ROUTE_MAP_NAME,
6993 bgp->vpn_policy[afi].rmap_name[dir]);
6994 bgp->vpn_policy[afi].rmap_name[dir] = NULL;
6995 bgp->vpn_policy[afi].rmap[dir] = NULL;
6996 }
6997
6998 vpn_leak_postchange(dir, afi, bgp_get_default(), bgp);
6999
7000 return CMD_SUCCESS;
7001 }
7002
7003 ALIAS(af_import_vrf_route_map, af_no_import_vrf_route_map_cmd,
7004 "no import vrf route-map",
7005 NO_STR
7006 "Import routes from another VRF\n"
7007 "Vrf routes being filtered\n"
7008 "Specify route map\n")
7009
7010 DEFPY(bgp_imexport_vrf, bgp_imexport_vrf_cmd,
7011 "[no] import vrf VIEWVRFNAME$import_name",
7012 NO_STR
7013 "Import routes from another VRF\n"
7014 "VRF to import from\n"
7015 "The name of the VRF\n")
7016 {
7017 VTY_DECLVAR_CONTEXT(bgp, bgp);
7018 struct listnode *node;
7019 struct bgp *vrf_bgp, *bgp_default;
7020 int32_t ret = 0;
7021 as_t as = bgp->as;
7022 bool remove = false;
7023 int32_t idx = 0;
7024 char *vname;
7025 enum bgp_instance_type bgp_type = BGP_INSTANCE_TYPE_VRF;
7026 safi_t safi;
7027 afi_t afi;
7028
7029 if (import_name == NULL) {
7030 vty_out(vty, "%% Missing import name\n");
7031 return CMD_WARNING;
7032 }
7033
7034 if (argv_find(argv, argc, "no", &idx))
7035 remove = true;
7036
7037 afi = vpn_policy_getafi(vty, bgp, true);
7038 if (afi == AFI_MAX)
7039 return CMD_WARNING_CONFIG_FAILED;
7040
7041 safi = bgp_node_safi(vty);
7042
7043 if (((BGP_INSTANCE_TYPE_DEFAULT == bgp->inst_type)
7044 && (strcmp(import_name, VRF_DEFAULT_NAME) == 0))
7045 || (bgp->name && (strcmp(import_name, bgp->name) == 0))) {
7046 vty_out(vty, "%% Cannot %s vrf %s into itself\n",
7047 remove ? "unimport" : "import", import_name);
7048 return CMD_WARNING;
7049 }
7050
7051 bgp_default = bgp_get_default();
7052 if (!bgp_default) {
7053 /* Auto-create assuming the same AS */
7054 ret = bgp_get(&bgp_default, &as, NULL,
7055 BGP_INSTANCE_TYPE_DEFAULT);
7056
7057 if (ret) {
7058 vty_out(vty,
7059 "VRF default is not configured as a bgp instance\n");
7060 return CMD_WARNING;
7061 }
7062 }
7063
7064 vrf_bgp = bgp_lookup_by_name(import_name);
7065 if (!vrf_bgp) {
7066 if (strcmp(import_name, VRF_DEFAULT_NAME) == 0)
7067 vrf_bgp = bgp_default;
7068 else
7069 /* Auto-create assuming the same AS */
7070 ret = bgp_get(&vrf_bgp, &as, import_name, bgp_type);
7071
7072 if (ret) {
7073 vty_out(vty,
7074 "VRF %s is not configured as a bgp instance\n",
7075 import_name);
7076 return CMD_WARNING;
7077 }
7078 }
7079
7080 if (remove) {
7081 vrf_unimport_from_vrf(bgp, vrf_bgp, afi, safi);
7082 } else {
7083 /* Already importing from "import_vrf"? */
7084 for (ALL_LIST_ELEMENTS_RO(bgp->vpn_policy[afi].import_vrf, node,
7085 vname)) {
7086 if (strcmp(vname, import_name) == 0)
7087 return CMD_WARNING;
7088 }
7089
7090 vrf_import_from_vrf(bgp, vrf_bgp, afi, safi);
7091 }
7092
7093 return CMD_SUCCESS;
7094 }
7095
7096 /* This command is valid only in a bgp vrf instance or the default instance */
7097 DEFPY (bgp_imexport_vpn,
7098 bgp_imexport_vpn_cmd,
7099 "[no] <import|export>$direction_str vpn",
7100 NO_STR
7101 "Import routes to this address-family\n"
7102 "Export routes from this address-family\n"
7103 "to/from default instance VPN RIB\n")
7104 {
7105 VTY_DECLVAR_CONTEXT(bgp, bgp);
7106 int previous_state;
7107 afi_t afi;
7108 safi_t safi;
7109 int idx = 0;
7110 int yes = 1;
7111 int flag;
7112 vpn_policy_direction_t dir;
7113
7114 if (argv_find(argv, argc, "no", &idx))
7115 yes = 0;
7116
7117 if (BGP_INSTANCE_TYPE_VRF != bgp->inst_type &&
7118 BGP_INSTANCE_TYPE_DEFAULT != bgp->inst_type) {
7119
7120 vty_out(vty, "%% import|export vpn valid only for bgp vrf or default instance\n");
7121 return CMD_WARNING_CONFIG_FAILED;
7122 }
7123
7124 afi = bgp_node_afi(vty);
7125 safi = bgp_node_safi(vty);
7126 if ((SAFI_UNICAST != safi) || ((AFI_IP != afi) && (AFI_IP6 != afi))) {
7127 vty_out(vty, "%% import|export vpn valid only for unicast ipv4|ipv6\n");
7128 return CMD_WARNING_CONFIG_FAILED;
7129 }
7130
7131 if (!strcmp(direction_str, "import")) {
7132 flag = BGP_CONFIG_MPLSVPN_TO_VRF_IMPORT;
7133 dir = BGP_VPN_POLICY_DIR_FROMVPN;
7134 } else if (!strcmp(direction_str, "export")) {
7135 flag = BGP_CONFIG_VRF_TO_MPLSVPN_EXPORT;
7136 dir = BGP_VPN_POLICY_DIR_TOVPN;
7137 } else {
7138 vty_out(vty, "%% unknown direction %s\n", direction_str);
7139 return CMD_WARNING_CONFIG_FAILED;
7140 }
7141
7142 previous_state = CHECK_FLAG(bgp->af_flags[afi][safi], flag);
7143
7144 if (yes) {
7145 SET_FLAG(bgp->af_flags[afi][safi], flag);
7146 if (!previous_state) {
7147 /* trigger export current vrf */
7148 vpn_leak_postchange(dir, afi, bgp_get_default(), bgp);
7149 }
7150 } else {
7151 if (previous_state) {
7152 /* trigger un-export current vrf */
7153 vpn_leak_prechange(dir, afi, bgp_get_default(), bgp);
7154 }
7155 UNSET_FLAG(bgp->af_flags[afi][safi], flag);
7156 }
7157
7158 return CMD_SUCCESS;
7159 }
7160
7161 DEFPY (af_routetarget_import,
7162 af_routetarget_import_cmd,
7163 "[no] <rt|route-target> redirect import RTLIST...",
7164 NO_STR
7165 "Specify route target list\n"
7166 "Specify route target list\n"
7167 "Flow-spec redirect type route target\n"
7168 "Import routes to this address-family\n"
7169 "Space separated route target list (A.B.C.D:MN|EF:OPQR|GHJK:MN)\n")
7170 {
7171 VTY_DECLVAR_CONTEXT(bgp, bgp);
7172 int ret;
7173 struct ecommunity *ecom = NULL;
7174 afi_t afi;
7175 int idx = 0;
7176 int yes = 1;
7177
7178 if (argv_find(argv, argc, "no", &idx))
7179 yes = 0;
7180
7181 afi = vpn_policy_getafi(vty, bgp, false);
7182 if (afi == AFI_MAX)
7183 return CMD_WARNING_CONFIG_FAILED;
7184
7185 if (yes) {
7186 if (!argv_find(argv, argc, "RTLIST", &idx)) {
7187 vty_out(vty, "%% Missing RTLIST\n");
7188 return CMD_WARNING_CONFIG_FAILED;
7189 }
7190 ret = set_ecom_list(vty, argc - idx, argv + idx, &ecom);
7191 if (ret != CMD_SUCCESS)
7192 return ret;
7193 }
7194
7195 if (yes) {
7196 if (bgp->vpn_policy[afi].import_redirect_rtlist)
7197 ecommunity_free(&bgp->vpn_policy[afi]
7198 .import_redirect_rtlist);
7199 bgp->vpn_policy[afi].import_redirect_rtlist =
7200 ecommunity_dup(ecom);
7201 } else {
7202 if (bgp->vpn_policy[afi].import_redirect_rtlist)
7203 ecommunity_free(&bgp->vpn_policy[afi]
7204 .import_redirect_rtlist);
7205 bgp->vpn_policy[afi].import_redirect_rtlist = NULL;
7206 }
7207
7208 if (ecom)
7209 ecommunity_free(&ecom);
7210
7211 return CMD_SUCCESS;
7212 }
7213
7214 DEFUN_NOSH (address_family_ipv4_safi,
7215 address_family_ipv4_safi_cmd,
7216 "address-family ipv4 [<unicast|multicast|vpn|labeled-unicast|flowspec>]",
7217 "Enter Address Family command mode\n"
7218 "Address Family\n"
7219 BGP_SAFI_WITH_LABEL_HELP_STR)
7220 {
7221
7222 if (argc == 3) {
7223 VTY_DECLVAR_CONTEXT(bgp, bgp);
7224 safi_t safi = bgp_vty_safi_from_str(argv[2]->text);
7225 if (bgp->inst_type != BGP_INSTANCE_TYPE_DEFAULT
7226 && safi != SAFI_UNICAST && safi != SAFI_MULTICAST
7227 && safi != SAFI_EVPN) {
7228 vty_out(vty,
7229 "Only Unicast/Multicast/EVPN SAFIs supported in non-core instances.\n");
7230 return CMD_WARNING_CONFIG_FAILED;
7231 }
7232 vty->node = bgp_node_type(AFI_IP, safi);
7233 } else
7234 vty->node = BGP_IPV4_NODE;
7235
7236 return CMD_SUCCESS;
7237 }
7238
7239 DEFUN_NOSH (address_family_ipv6_safi,
7240 address_family_ipv6_safi_cmd,
7241 "address-family ipv6 [<unicast|multicast|vpn|labeled-unicast|flowspec>]",
7242 "Enter Address Family command mode\n"
7243 "Address Family\n"
7244 BGP_SAFI_WITH_LABEL_HELP_STR)
7245 {
7246 if (argc == 3) {
7247 VTY_DECLVAR_CONTEXT(bgp, bgp);
7248 safi_t safi = bgp_vty_safi_from_str(argv[2]->text);
7249 if (bgp->inst_type != BGP_INSTANCE_TYPE_DEFAULT
7250 && safi != SAFI_UNICAST && safi != SAFI_MULTICAST
7251 && safi != SAFI_EVPN) {
7252 vty_out(vty,
7253 "Only Unicast/Multicast/EVPN SAFIs supported in non-core instances.\n");
7254 return CMD_WARNING_CONFIG_FAILED;
7255 }
7256 vty->node = bgp_node_type(AFI_IP6, safi);
7257 } else
7258 vty->node = BGP_IPV6_NODE;
7259
7260 return CMD_SUCCESS;
7261 }
7262
7263 #ifdef KEEP_OLD_VPN_COMMANDS
7264 DEFUN_NOSH (address_family_vpnv4,
7265 address_family_vpnv4_cmd,
7266 "address-family vpnv4 [unicast]",
7267 "Enter Address Family command mode\n"
7268 "Address Family\n"
7269 "Address Family modifier\n")
7270 {
7271 vty->node = BGP_VPNV4_NODE;
7272 return CMD_SUCCESS;
7273 }
7274
7275 DEFUN_NOSH (address_family_vpnv6,
7276 address_family_vpnv6_cmd,
7277 "address-family vpnv6 [unicast]",
7278 "Enter Address Family command mode\n"
7279 "Address Family\n"
7280 "Address Family modifier\n")
7281 {
7282 vty->node = BGP_VPNV6_NODE;
7283 return CMD_SUCCESS;
7284 }
7285 #endif /* KEEP_OLD_VPN_COMMANDS */
7286
7287 DEFUN_NOSH (address_family_evpn,
7288 address_family_evpn_cmd,
7289 "address-family l2vpn evpn",
7290 "Enter Address Family command mode\n"
7291 "Address Family\n"
7292 "Address Family modifier\n")
7293 {
7294 VTY_DECLVAR_CONTEXT(bgp, bgp);
7295 vty->node = BGP_EVPN_NODE;
7296 return CMD_SUCCESS;
7297 }
7298
7299 DEFUN_NOSH (exit_address_family,
7300 exit_address_family_cmd,
7301 "exit-address-family",
7302 "Exit from Address Family configuration mode\n")
7303 {
7304 if (vty->node == BGP_IPV4_NODE || vty->node == BGP_IPV4M_NODE
7305 || vty->node == BGP_IPV4L_NODE || vty->node == BGP_VPNV4_NODE
7306 || vty->node == BGP_IPV6_NODE || vty->node == BGP_IPV6M_NODE
7307 || vty->node == BGP_IPV6L_NODE || vty->node == BGP_VPNV6_NODE
7308 || vty->node == BGP_EVPN_NODE
7309 || vty->node == BGP_FLOWSPECV4_NODE
7310 || vty->node == BGP_FLOWSPECV6_NODE)
7311 vty->node = BGP_NODE;
7312 return CMD_SUCCESS;
7313 }
7314
7315 /* Recalculate bestpath and re-advertise a prefix */
7316 static int bgp_clear_prefix(struct vty *vty, const char *view_name,
7317 const char *ip_str, afi_t afi, safi_t safi,
7318 struct prefix_rd *prd)
7319 {
7320 int ret;
7321 struct prefix match;
7322 struct bgp_node *rn;
7323 struct bgp_node *rm;
7324 struct bgp *bgp;
7325 struct bgp_table *table;
7326 struct bgp_table *rib;
7327
7328 /* BGP structure lookup. */
7329 if (view_name) {
7330 bgp = bgp_lookup_by_name(view_name);
7331 if (bgp == NULL) {
7332 vty_out(vty, "%% Can't find BGP instance %s\n",
7333 view_name);
7334 return CMD_WARNING;
7335 }
7336 } else {
7337 bgp = bgp_get_default();
7338 if (bgp == NULL) {
7339 vty_out(vty, "%% No BGP process is configured\n");
7340 return CMD_WARNING;
7341 }
7342 }
7343
7344 /* Check IP address argument. */
7345 ret = str2prefix(ip_str, &match);
7346 if (!ret) {
7347 vty_out(vty, "%% address is malformed\n");
7348 return CMD_WARNING;
7349 }
7350
7351 match.family = afi2family(afi);
7352 rib = bgp->rib[afi][safi];
7353
7354 if (safi == SAFI_MPLS_VPN) {
7355 for (rn = bgp_table_top(rib); rn; rn = bgp_route_next(rn)) {
7356 if (prd && memcmp(rn->p.u.val, prd->val, 8) != 0)
7357 continue;
7358
7359 table = bgp_node_get_bgp_table_info(rn);
7360 if (table != NULL) {
7361
7362 if ((rm = bgp_node_match(table, &match))
7363 != NULL) {
7364 if (rm->p.prefixlen
7365 == match.prefixlen) {
7366 SET_FLAG(rm->flags,
7367 BGP_NODE_USER_CLEAR);
7368 bgp_process(bgp, rm, afi, safi);
7369 }
7370 bgp_unlock_node(rm);
7371 }
7372 }
7373 }
7374 } else {
7375 if ((rn = bgp_node_match(rib, &match)) != NULL) {
7376 if (rn->p.prefixlen == match.prefixlen) {
7377 SET_FLAG(rn->flags, BGP_NODE_USER_CLEAR);
7378 bgp_process(bgp, rn, afi, safi);
7379 }
7380 bgp_unlock_node(rn);
7381 }
7382 }
7383
7384 return CMD_SUCCESS;
7385 }
7386
7387 /* one clear bgp command to rule them all */
7388 DEFUN (clear_ip_bgp_all,
7389 clear_ip_bgp_all_cmd,
7390 "clear [ip] bgp [<view|vrf> VIEWVRFNAME] [<ipv4|ipv6|l2vpn> [<unicast|multicast|vpn|labeled-unicast|flowspec|evpn>]] <*|A.B.C.D$neighbor|X:X::X:X$neighbor|WORD$neighbor|(1-4294967295)|external|peer-group PGNAME> [<soft [<in|out>]|in [prefix-filter]|out>]",
7391 CLEAR_STR
7392 IP_STR
7393 BGP_STR
7394 BGP_INSTANCE_HELP_STR
7395 BGP_AFI_HELP_STR
7396 "Address Family\n"
7397 BGP_SAFI_WITH_LABEL_HELP_STR
7398 "Address Family modifier\n"
7399 "Clear all peers\n"
7400 "BGP IPv4 neighbor to clear\n"
7401 "BGP IPv6 neighbor to clear\n"
7402 "BGP neighbor on interface to clear\n"
7403 "Clear peers with the AS number\n"
7404 "Clear all external peers\n"
7405 "Clear all members of peer-group\n"
7406 "BGP peer-group name\n"
7407 BGP_SOFT_STR
7408 BGP_SOFT_IN_STR
7409 BGP_SOFT_OUT_STR
7410 BGP_SOFT_IN_STR
7411 "Push out prefix-list ORF and do inbound soft reconfig\n"
7412 BGP_SOFT_OUT_STR)
7413 {
7414 char *vrf = NULL;
7415
7416 afi_t afi = AFI_UNSPEC;
7417 safi_t safi = SAFI_UNSPEC;
7418 enum clear_sort clr_sort = clear_peer;
7419 enum bgp_clear_type clr_type;
7420 char *clr_arg = NULL;
7421
7422 int idx = 0;
7423
7424 /* clear [ip] bgp */
7425 if (argv_find(argv, argc, "ip", &idx))
7426 afi = AFI_IP;
7427
7428 /* [<vrf> VIEWVRFNAME] */
7429 if (argv_find(argv, argc, "vrf", &idx)) {
7430 vrf = argv[idx + 1]->arg;
7431 idx += 2;
7432 if (vrf && strmatch(vrf, VRF_DEFAULT_NAME))
7433 vrf = NULL;
7434 } else if (argv_find(argv, argc, "view", &idx)) {
7435 /* [<view> VIEWVRFNAME] */
7436 vrf = argv[idx + 1]->arg;
7437 idx += 2;
7438 }
7439 /* ["BGP_AFI_CMD_STR" ["BGP_SAFI_CMD_STR"]] */
7440 if (argv_find_and_parse_afi(argv, argc, &idx, &afi))
7441 argv_find_and_parse_safi(argv, argc, &idx, &safi);
7442
7443 /* <*|A.B.C.D|X:X::X:X|WORD|(1-4294967295)|external|peer-group PGNAME> */
7444 if (argv_find(argv, argc, "*", &idx)) {
7445 clr_sort = clear_all;
7446 } else if (argv_find(argv, argc, "A.B.C.D", &idx)) {
7447 clr_sort = clear_peer;
7448 clr_arg = argv[idx]->arg;
7449 } else if (argv_find(argv, argc, "X:X::X:X", &idx)) {
7450 clr_sort = clear_peer;
7451 clr_arg = argv[idx]->arg;
7452 } else if (argv_find(argv, argc, "peer-group", &idx)) {
7453 clr_sort = clear_group;
7454 idx++;
7455 clr_arg = argv[idx]->arg;
7456 } else if (argv_find(argv, argc, "PGNAME", &idx)) {
7457 clr_sort = clear_peer;
7458 clr_arg = argv[idx]->arg;
7459 } else if (argv_find(argv, argc, "WORD", &idx)) {
7460 clr_sort = clear_peer;
7461 clr_arg = argv[idx]->arg;
7462 } else if (argv_find(argv, argc, "(1-4294967295)", &idx)) {
7463 clr_sort = clear_as;
7464 clr_arg = argv[idx]->arg;
7465 } else if (argv_find(argv, argc, "external", &idx)) {
7466 clr_sort = clear_external;
7467 }
7468
7469 /* [<soft [<in|out>]|in [prefix-filter]|out>] */
7470 if (argv_find(argv, argc, "soft", &idx)) {
7471 if (argv_find(argv, argc, "in", &idx)
7472 || argv_find(argv, argc, "out", &idx))
7473 clr_type = strmatch(argv[idx]->text, "in")
7474 ? BGP_CLEAR_SOFT_IN
7475 : BGP_CLEAR_SOFT_OUT;
7476 else
7477 clr_type = BGP_CLEAR_SOFT_BOTH;
7478 } else if (argv_find(argv, argc, "in", &idx)) {
7479 clr_type = argv_find(argv, argc, "prefix-filter", &idx)
7480 ? BGP_CLEAR_SOFT_IN_ORF_PREFIX
7481 : BGP_CLEAR_SOFT_IN;
7482 } else if (argv_find(argv, argc, "out", &idx)) {
7483 clr_type = BGP_CLEAR_SOFT_OUT;
7484 } else
7485 clr_type = BGP_CLEAR_SOFT_NONE;
7486
7487 return bgp_clear_vty(vty, vrf, afi, safi, clr_sort, clr_type, clr_arg);
7488 }
7489
7490 DEFUN (clear_ip_bgp_prefix,
7491 clear_ip_bgp_prefix_cmd,
7492 "clear [ip] bgp [<view|vrf> VIEWVRFNAME] prefix A.B.C.D/M",
7493 CLEAR_STR
7494 IP_STR
7495 BGP_STR
7496 BGP_INSTANCE_HELP_STR
7497 "Clear bestpath and re-advertise\n"
7498 "IPv4 prefix\n")
7499 {
7500 char *vrf = NULL;
7501 char *prefix = NULL;
7502
7503 int idx = 0;
7504
7505 /* [<view|vrf> VIEWVRFNAME] */
7506 if (argv_find(argv, argc, "vrf", &idx)) {
7507 vrf = argv[idx + 1]->arg;
7508 idx += 2;
7509 if (vrf && strmatch(vrf, VRF_DEFAULT_NAME))
7510 vrf = NULL;
7511 } else if (argv_find(argv, argc, "view", &idx)) {
7512 /* [<view> VIEWVRFNAME] */
7513 vrf = argv[idx + 1]->arg;
7514 idx += 2;
7515 }
7516
7517 prefix = argv[argc - 1]->arg;
7518
7519 return bgp_clear_prefix(vty, vrf, prefix, AFI_IP, SAFI_UNICAST, NULL);
7520 }
7521
7522 DEFUN (clear_bgp_ipv6_safi_prefix,
7523 clear_bgp_ipv6_safi_prefix_cmd,
7524 "clear [ip] bgp ipv6 "BGP_SAFI_CMD_STR" prefix X:X::X:X/M",
7525 CLEAR_STR
7526 IP_STR
7527 BGP_STR
7528 "Address Family\n"
7529 BGP_SAFI_HELP_STR
7530 "Clear bestpath and re-advertise\n"
7531 "IPv6 prefix\n")
7532 {
7533 int idx_safi = 0;
7534 int idx_ipv6_prefix = 0;
7535 safi_t safi = SAFI_UNICAST;
7536 char *prefix = argv_find(argv, argc, "X:X::X:X/M", &idx_ipv6_prefix) ?
7537 argv[idx_ipv6_prefix]->arg : NULL;
7538
7539 argv_find_and_parse_safi(argv, argc, &idx_safi, &safi);
7540 return bgp_clear_prefix(
7541 vty, NULL, prefix, AFI_IP6,
7542 safi, NULL);
7543 }
7544
7545 DEFUN (clear_bgp_instance_ipv6_safi_prefix,
7546 clear_bgp_instance_ipv6_safi_prefix_cmd,
7547 "clear [ip] bgp <view|vrf> VIEWVRFNAME ipv6 "BGP_SAFI_CMD_STR" prefix X:X::X:X/M",
7548 CLEAR_STR
7549 IP_STR
7550 BGP_STR
7551 BGP_INSTANCE_HELP_STR
7552 "Address Family\n"
7553 BGP_SAFI_HELP_STR
7554 "Clear bestpath and re-advertise\n"
7555 "IPv6 prefix\n")
7556 {
7557 int idx_safi = 0;
7558 int idx_vrfview = 0;
7559 int idx_ipv6_prefix = 0;
7560 safi_t safi = SAFI_UNICAST;
7561 char *prefix = argv_find(argv, argc, "X:X::X:X/M", &idx_ipv6_prefix) ?
7562 argv[idx_ipv6_prefix]->arg : NULL;
7563 char *vrfview = NULL;
7564
7565 /* [<view|vrf> VIEWVRFNAME] */
7566 if (argv_find(argv, argc, "vrf", &idx_vrfview)) {
7567 vrfview = argv[idx_vrfview + 1]->arg;
7568 if (vrfview && strmatch(vrfview, VRF_DEFAULT_NAME))
7569 vrfview = NULL;
7570 } else if (argv_find(argv, argc, "view", &idx_vrfview)) {
7571 /* [<view> VIEWVRFNAME] */
7572 vrfview = argv[idx_vrfview + 1]->arg;
7573 }
7574 argv_find_and_parse_safi(argv, argc, &idx_safi, &safi);
7575
7576 return bgp_clear_prefix(
7577 vty, vrfview, prefix,
7578 AFI_IP6, safi, NULL);
7579 }
7580
7581 DEFUN (show_bgp_views,
7582 show_bgp_views_cmd,
7583 "show [ip] bgp views",
7584 SHOW_STR
7585 IP_STR
7586 BGP_STR
7587 "Show the defined BGP views\n")
7588 {
7589 struct list *inst = bm->bgp;
7590 struct listnode *node;
7591 struct bgp *bgp;
7592
7593 vty_out(vty, "Defined BGP views:\n");
7594 for (ALL_LIST_ELEMENTS_RO(inst, node, bgp)) {
7595 /* Skip VRFs. */
7596 if (bgp->inst_type == BGP_INSTANCE_TYPE_VRF)
7597 continue;
7598 vty_out(vty, "\t%s (AS%u)\n", bgp->name ? bgp->name : "(null)",
7599 bgp->as);
7600 }
7601
7602 return CMD_SUCCESS;
7603 }
7604
7605 DEFUN (show_bgp_vrfs,
7606 show_bgp_vrfs_cmd,
7607 "show [ip] bgp vrfs [json]",
7608 SHOW_STR
7609 IP_STR
7610 BGP_STR
7611 "Show BGP VRFs\n"
7612 JSON_STR)
7613 {
7614 char buf[ETHER_ADDR_STRLEN];
7615 struct list *inst = bm->bgp;
7616 struct listnode *node;
7617 struct bgp *bgp;
7618 bool uj = use_json(argc, argv);
7619 json_object *json = NULL;
7620 json_object *json_vrfs = NULL;
7621 int count = 0;
7622
7623 if (uj) {
7624 json = json_object_new_object();
7625 json_vrfs = json_object_new_object();
7626 }
7627
7628 for (ALL_LIST_ELEMENTS_RO(inst, node, bgp)) {
7629 const char *name, *type;
7630 struct peer *peer;
7631 struct listnode *node2, *nnode2;
7632 int peers_cfg, peers_estb;
7633 json_object *json_vrf = NULL;
7634
7635 /* Skip Views. */
7636 if (bgp->inst_type == BGP_INSTANCE_TYPE_VIEW)
7637 continue;
7638
7639 count++;
7640 if (!uj && count == 1) {
7641 vty_out(vty,
7642 "%4s %-5s %-16s %9s %10s %-37s\n",
7643 "Type", "Id", "routerId", "#PeersVfg",
7644 "#PeersEstb", "Name");
7645 vty_out(vty, "%11s %-16s %-21s %-6s\n", " ",
7646 "L3-VNI", "RouterMAC", "Interface");
7647 }
7648
7649 peers_cfg = peers_estb = 0;
7650 if (uj)
7651 json_vrf = json_object_new_object();
7652
7653
7654 for (ALL_LIST_ELEMENTS(bgp->peer, node2, nnode2, peer)) {
7655 if (!CHECK_FLAG(peer->flags, PEER_FLAG_CONFIG_NODE))
7656 continue;
7657 peers_cfg++;
7658 if (peer->status == Established)
7659 peers_estb++;
7660 }
7661
7662 if (bgp->inst_type == BGP_INSTANCE_TYPE_DEFAULT) {
7663 name = VRF_DEFAULT_NAME;
7664 type = "DFLT";
7665 } else {
7666 name = bgp->name;
7667 type = "VRF";
7668 }
7669
7670
7671 if (uj) {
7672 int64_t vrf_id_ui = (bgp->vrf_id == VRF_UNKNOWN)
7673 ? -1
7674 : (int64_t)bgp->vrf_id;
7675 json_object_string_add(json_vrf, "type", type);
7676 json_object_int_add(json_vrf, "vrfId", vrf_id_ui);
7677 json_object_string_add(json_vrf, "routerId",
7678 inet_ntoa(bgp->router_id));
7679 json_object_int_add(json_vrf, "numConfiguredPeers",
7680 peers_cfg);
7681 json_object_int_add(json_vrf, "numEstablishedPeers",
7682 peers_estb);
7683
7684 json_object_int_add(json_vrf, "l3vni", bgp->l3vni);
7685 json_object_string_add(
7686 json_vrf, "rmac",
7687 prefix_mac2str(&bgp->rmac, buf, sizeof(buf)));
7688 json_object_string_add(json_vrf, "interface",
7689 ifindex2ifname(bgp->l3vni_svi_ifindex,
7690 bgp->vrf_id));
7691 json_object_object_add(json_vrfs, name, json_vrf);
7692 } else {
7693 vty_out(vty,
7694 "%4s %-5d %-16s %-9u %-10u %-37s\n",
7695 type,
7696 bgp->vrf_id == VRF_UNKNOWN ? -1
7697 : (int)bgp->vrf_id,
7698 inet_ntoa(bgp->router_id), peers_cfg,
7699 peers_estb, name);
7700 vty_out(vty,"%11s %-16u %-21s %-20s\n", " ",
7701 bgp->l3vni,
7702 prefix_mac2str(&bgp->rmac, buf, sizeof(buf)),
7703 ifindex2ifname(bgp->l3vni_svi_ifindex,
7704 bgp->vrf_id));
7705 }
7706 }
7707
7708 if (uj) {
7709 json_object_object_add(json, "vrfs", json_vrfs);
7710
7711 json_object_int_add(json, "totalVrfs", count);
7712
7713 vty_out(vty, "%s\n", json_object_to_json_string_ext(
7714 json, JSON_C_TO_STRING_PRETTY));
7715 json_object_free(json);
7716 } else {
7717 if (count)
7718 vty_out(vty,
7719 "\nTotal number of VRFs (including default): %d\n",
7720 count);
7721 }
7722
7723 return CMD_SUCCESS;
7724 }
7725
7726 DEFUN (show_bgp_mac_hash,
7727 show_bgp_mac_hash_cmd,
7728 "show bgp mac hash",
7729 SHOW_STR
7730 BGP_STR
7731 "Mac Address\n"
7732 "Mac Address database\n")
7733 {
7734 bgp_mac_dump_table(vty);
7735
7736 return CMD_SUCCESS;
7737 }
7738
7739 static void show_tip_entry(struct hash_bucket *bucket, void *args)
7740 {
7741 struct vty *vty = (struct vty *)args;
7742 struct tip_addr *tip = (struct tip_addr *)bucket->data;
7743
7744 vty_out(vty, "addr: %s, count: %d\n", inet_ntoa(tip->addr),
7745 tip->refcnt);
7746 }
7747
7748 static void bgp_show_martian_nexthops(struct vty *vty, struct bgp *bgp)
7749 {
7750 vty_out(vty, "self nexthop database:\n");
7751 bgp_nexthop_show_address_hash(vty, bgp);
7752
7753 vty_out(vty, "Tunnel-ip database:\n");
7754 hash_iterate(bgp->tip_hash,
7755 (void (*)(struct hash_bucket *, void *))show_tip_entry,
7756 vty);
7757 }
7758
7759 DEFUN(show_bgp_martian_nexthop_db, show_bgp_martian_nexthop_db_cmd,
7760 "show bgp [<view|vrf> VIEWVRFNAME] martian next-hop",
7761 SHOW_STR BGP_STR BGP_INSTANCE_HELP_STR
7762 "martian next-hops\n"
7763 "martian next-hop database\n")
7764 {
7765 struct bgp *bgp = NULL;
7766 int idx = 0;
7767 char *name = NULL;
7768
7769 /* [<vrf> VIEWVRFNAME] */
7770 if (argv_find(argv, argc, "vrf", &idx)) {
7771 name = argv[idx + 1]->arg;
7772 if (name && strmatch(name, VRF_DEFAULT_NAME))
7773 name = NULL;
7774 } else if (argv_find(argv, argc, "view", &idx))
7775 /* [<view> VIEWVRFNAME] */
7776 name = argv[idx + 1]->arg;
7777 if (name)
7778 bgp = bgp_lookup_by_name(name);
7779 else
7780 bgp = bgp_get_default();
7781
7782 if (!bgp) {
7783 vty_out(vty, "%% No BGP process is configured\n");
7784 return CMD_WARNING;
7785 }
7786 bgp_show_martian_nexthops(vty, bgp);
7787
7788 return CMD_SUCCESS;
7789 }
7790
7791 DEFUN (show_bgp_memory,
7792 show_bgp_memory_cmd,
7793 "show [ip] bgp memory",
7794 SHOW_STR
7795 IP_STR
7796 BGP_STR
7797 "Global BGP memory statistics\n")
7798 {
7799 char memstrbuf[MTYPE_MEMSTR_LEN];
7800 unsigned long count;
7801
7802 /* RIB related usage stats */
7803 count = mtype_stats_alloc(MTYPE_BGP_NODE);
7804 vty_out(vty, "%ld RIB nodes, using %s of memory\n", count,
7805 mtype_memstr(memstrbuf, sizeof(memstrbuf),
7806 count * sizeof(struct bgp_node)));
7807
7808 count = mtype_stats_alloc(MTYPE_BGP_ROUTE);
7809 vty_out(vty, "%ld BGP routes, using %s of memory\n", count,
7810 mtype_memstr(memstrbuf, sizeof(memstrbuf),
7811 count * sizeof(struct bgp_path_info)));
7812 if ((count = mtype_stats_alloc(MTYPE_BGP_ROUTE_EXTRA)))
7813 vty_out(vty, "%ld BGP route ancillaries, using %s of memory\n",
7814 count,
7815 mtype_memstr(
7816 memstrbuf, sizeof(memstrbuf),
7817 count * sizeof(struct bgp_path_info_extra)));
7818
7819 if ((count = mtype_stats_alloc(MTYPE_BGP_STATIC)))
7820 vty_out(vty, "%ld Static routes, using %s of memory\n", count,
7821 mtype_memstr(memstrbuf, sizeof(memstrbuf),
7822 count * sizeof(struct bgp_static)));
7823
7824 if ((count = mtype_stats_alloc(MTYPE_BGP_PACKET)))
7825 vty_out(vty, "%ld Packets, using %s of memory\n", count,
7826 mtype_memstr(memstrbuf, sizeof(memstrbuf),
7827 count * sizeof(struct bpacket)));
7828
7829 /* Adj-In/Out */
7830 if ((count = mtype_stats_alloc(MTYPE_BGP_ADJ_IN)))
7831 vty_out(vty, "%ld Adj-In entries, using %s of memory\n", count,
7832 mtype_memstr(memstrbuf, sizeof(memstrbuf),
7833 count * sizeof(struct bgp_adj_in)));
7834 if ((count = mtype_stats_alloc(MTYPE_BGP_ADJ_OUT)))
7835 vty_out(vty, "%ld Adj-Out entries, using %s of memory\n", count,
7836 mtype_memstr(memstrbuf, sizeof(memstrbuf),
7837 count * sizeof(struct bgp_adj_out)));
7838
7839 if ((count = mtype_stats_alloc(MTYPE_BGP_NEXTHOP_CACHE)))
7840 vty_out(vty, "%ld Nexthop cache entries, using %s of memory\n",
7841 count,
7842 mtype_memstr(memstrbuf, sizeof(memstrbuf),
7843 count * sizeof(struct bgp_nexthop_cache)));
7844
7845 if ((count = mtype_stats_alloc(MTYPE_BGP_DAMP_INFO)))
7846 vty_out(vty, "%ld Dampening entries, using %s of memory\n",
7847 count,
7848 mtype_memstr(memstrbuf, sizeof(memstrbuf),
7849 count * sizeof(struct bgp_damp_info)));
7850
7851 /* Attributes */
7852 count = attr_count();
7853 vty_out(vty, "%ld BGP attributes, using %s of memory\n", count,
7854 mtype_memstr(memstrbuf, sizeof(memstrbuf),
7855 count * sizeof(struct attr)));
7856
7857 if ((count = attr_unknown_count()))
7858 vty_out(vty, "%ld unknown attributes\n", count);
7859
7860 /* AS_PATH attributes */
7861 count = aspath_count();
7862 vty_out(vty, "%ld BGP AS-PATH entries, using %s of memory\n", count,
7863 mtype_memstr(memstrbuf, sizeof(memstrbuf),
7864 count * sizeof(struct aspath)));
7865
7866 count = mtype_stats_alloc(MTYPE_AS_SEG);
7867 vty_out(vty, "%ld BGP AS-PATH segments, using %s of memory\n", count,
7868 mtype_memstr(memstrbuf, sizeof(memstrbuf),
7869 count * sizeof(struct assegment)));
7870
7871 /* Other attributes */
7872 if ((count = community_count()))
7873 vty_out(vty, "%ld BGP community entries, using %s of memory\n",
7874 count, mtype_memstr(memstrbuf, sizeof(memstrbuf),
7875 count * sizeof(struct community)));
7876 if ((count = mtype_stats_alloc(MTYPE_ECOMMUNITY)))
7877 vty_out(vty, "%ld BGP community entries, using %s of memory\n",
7878 count, mtype_memstr(memstrbuf, sizeof(memstrbuf),
7879 count * sizeof(struct ecommunity)));
7880 if ((count = mtype_stats_alloc(MTYPE_LCOMMUNITY)))
7881 vty_out(vty,
7882 "%ld BGP large-community entries, using %s of memory\n",
7883 count, mtype_memstr(memstrbuf, sizeof(memstrbuf),
7884 count * sizeof(struct lcommunity)));
7885
7886 if ((count = mtype_stats_alloc(MTYPE_CLUSTER)))
7887 vty_out(vty, "%ld Cluster lists, using %s of memory\n", count,
7888 mtype_memstr(memstrbuf, sizeof(memstrbuf),
7889 count * sizeof(struct cluster_list)));
7890
7891 /* Peer related usage */
7892 count = mtype_stats_alloc(MTYPE_BGP_PEER);
7893 vty_out(vty, "%ld peers, using %s of memory\n", count,
7894 mtype_memstr(memstrbuf, sizeof(memstrbuf),
7895 count * sizeof(struct peer)));
7896
7897 if ((count = mtype_stats_alloc(MTYPE_PEER_GROUP)))
7898 vty_out(vty, "%ld peer groups, using %s of memory\n", count,
7899 mtype_memstr(memstrbuf, sizeof(memstrbuf),
7900 count * sizeof(struct peer_group)));
7901
7902 /* Other */
7903 if ((count = mtype_stats_alloc(MTYPE_BGP_REGEXP)))
7904 vty_out(vty, "%ld compiled regexes, using %s of memory\n",
7905 count, mtype_memstr(memstrbuf, sizeof(memstrbuf),
7906 count * sizeof(regex_t)));
7907 return CMD_SUCCESS;
7908 }
7909
7910 static void bgp_show_bestpath_json(struct bgp *bgp, json_object *json)
7911 {
7912 json_object *bestpath = json_object_new_object();
7913
7914 if (bgp_flag_check(bgp, BGP_FLAG_ASPATH_IGNORE))
7915 json_object_string_add(bestpath, "asPath", "ignore");
7916
7917 if (bgp_flag_check(bgp, BGP_FLAG_ASPATH_CONFED))
7918 json_object_string_add(bestpath, "asPath", "confed");
7919
7920 if (bgp_flag_check(bgp, BGP_FLAG_ASPATH_MULTIPATH_RELAX)) {
7921 if (bgp_flag_check(bgp, BGP_FLAG_MULTIPATH_RELAX_AS_SET))
7922 json_object_string_add(bestpath, "multiPathRelax",
7923 "as-set");
7924 else
7925 json_object_string_add(bestpath, "multiPathRelax",
7926 "true");
7927 } else
7928 json_object_string_add(bestpath, "multiPathRelax", "false");
7929
7930 if (bgp_flag_check(bgp, BGP_FLAG_COMPARE_ROUTER_ID))
7931 json_object_string_add(bestpath, "compareRouterId", "true");
7932 if (bgp_flag_check(bgp, BGP_FLAG_MED_CONFED)
7933 || bgp_flag_check(bgp, BGP_FLAG_MED_MISSING_AS_WORST)) {
7934 if (bgp_flag_check(bgp, BGP_FLAG_MED_CONFED))
7935 json_object_string_add(bestpath, "med", "confed");
7936 if (bgp_flag_check(bgp, BGP_FLAG_MED_MISSING_AS_WORST))
7937 json_object_string_add(bestpath, "med",
7938 "missing-as-worst");
7939 else
7940 json_object_string_add(bestpath, "med", "true");
7941 }
7942
7943 json_object_object_add(json, "bestPath", bestpath);
7944 }
7945
7946 /* Print the error code/subcode for why the peer is down */
7947 static void bgp_show_peer_reset(struct vty * vty, struct peer *peer,
7948 json_object *json_peer, bool use_json)
7949 {
7950 const char *code_str;
7951 const char *subcode_str;
7952
7953 if (use_json) {
7954 if (peer->last_reset == PEER_DOWN_NOTIFY_SEND
7955 || peer->last_reset == PEER_DOWN_NOTIFY_RECEIVED) {
7956 char errorcodesubcode_hexstr[5];
7957 char errorcodesubcode_str[256];
7958
7959 code_str = bgp_notify_code_str(peer->notify.code);
7960 subcode_str = bgp_notify_subcode_str(
7961 peer->notify.code,
7962 peer->notify.subcode);
7963
7964 sprintf(errorcodesubcode_hexstr, "%02X%02X",
7965 peer->notify.code, peer->notify.subcode);
7966 json_object_string_add(json_peer,
7967 "lastErrorCodeSubcode",
7968 errorcodesubcode_hexstr);
7969 snprintf(errorcodesubcode_str, 255, "%s%s",
7970 code_str, subcode_str);
7971 json_object_string_add(json_peer,
7972 "lastNotificationReason",
7973 errorcodesubcode_str);
7974 if (peer->last_reset == PEER_DOWN_NOTIFY_RECEIVED
7975 && peer->notify.code == BGP_NOTIFY_CEASE
7976 && (peer->notify.subcode
7977 == BGP_NOTIFY_CEASE_ADMIN_SHUTDOWN
7978 || peer->notify.subcode
7979 == BGP_NOTIFY_CEASE_ADMIN_RESET)
7980 && peer->notify.length) {
7981 char msgbuf[1024];
7982 const char *msg_str;
7983
7984 msg_str = bgp_notify_admin_message(
7985 msgbuf, sizeof(msgbuf),
7986 (uint8_t *)peer->notify.data,
7987 peer->notify.length);
7988 if (msg_str)
7989 json_object_string_add(
7990 json_peer,
7991 "lastShutdownDescription",
7992 msg_str);
7993 }
7994
7995 }
7996 json_object_string_add(json_peer, "lastResetDueTo",
7997 peer_down_str[(int)peer->last_reset]);
7998 json_object_int_add(json_peer, "lastResetCode",
7999 peer->last_reset);
8000 } else {
8001 if (peer->last_reset == PEER_DOWN_NOTIFY_SEND
8002 || peer->last_reset == PEER_DOWN_NOTIFY_RECEIVED) {
8003 code_str = bgp_notify_code_str(peer->notify.code);
8004 subcode_str =
8005 bgp_notify_subcode_str(peer->notify.code,
8006 peer->notify.subcode);
8007 vty_out(vty, " Notification %s (%s%s)\n",
8008 peer->last_reset == PEER_DOWN_NOTIFY_SEND
8009 ? "sent"
8010 : "received",
8011 code_str, subcode_str);
8012 } else {
8013 vty_out(vty, " %s\n",
8014 peer_down_str[(int)peer->last_reset]);
8015 }
8016 }
8017 }
8018
8019 static inline bool bgp_has_peer_failed(struct peer *peer, afi_t afi,
8020 safi_t safi)
8021 {
8022 return ((peer->status != Established) ||
8023 !peer->afc_recv[afi][safi]);
8024 }
8025
8026 static void bgp_show_failed_summary(struct vty *vty, struct bgp *bgp,
8027 struct peer *peer, json_object *json_peer,
8028 int max_neighbor_width, bool use_json)
8029 {
8030 char timebuf[BGP_UPTIME_LEN], dn_flag[2];
8031 int len;
8032
8033 if (use_json) {
8034 if (peer_dynamic_neighbor(peer))
8035 json_object_boolean_true_add(json_peer,
8036 "dynamicPeer");
8037 if (peer->hostname)
8038 json_object_string_add(json_peer, "hostname",
8039 peer->hostname);
8040
8041 if (peer->domainname)
8042 json_object_string_add(json_peer, "domainname",
8043 peer->domainname);
8044 json_object_int_add(json_peer, "connectionsEstablished",
8045 peer->established);
8046 json_object_int_add(json_peer, "connectionsDropped",
8047 peer->dropped);
8048 peer_uptime(peer->uptime, timebuf, BGP_UPTIME_LEN,
8049 use_json, json_peer);
8050 if (peer->status == Established)
8051 json_object_string_add(json_peer, "lastResetDueTo",
8052 "AFI/SAFI Not Negotiated");
8053 else
8054 bgp_show_peer_reset(NULL, peer, json_peer, true);
8055 } else {
8056 dn_flag[1] = '\0';
8057 dn_flag[0] = peer_dynamic_neighbor(peer) ? '*' : '\0';
8058 if (peer->hostname
8059 && bgp_flag_check(bgp, BGP_FLAG_SHOW_HOSTNAME))
8060 len = vty_out(vty, "%s%s(%s)", dn_flag,
8061 peer->hostname, peer->host);
8062 else
8063 len = vty_out(vty, "%s%s", dn_flag, peer->host);
8064
8065 /* pad the neighbor column with spaces */
8066 if (len < max_neighbor_width)
8067 vty_out(vty, "%*s", max_neighbor_width - len,
8068 " ");
8069 vty_out(vty, "%7d %7d %8s", peer->established,
8070 peer->dropped,
8071 peer_uptime(peer->uptime, timebuf,
8072 BGP_UPTIME_LEN, 0, NULL));
8073 if (peer->status == Established)
8074 vty_out(vty, " AFI/SAFI Not Negotiated\n");
8075 else
8076 bgp_show_peer_reset(vty, peer, NULL,
8077 false);
8078 }
8079 }
8080
8081
8082 /* Show BGP peer's summary information. */
8083 static int bgp_show_summary(struct vty *vty, struct bgp *bgp, int afi, int safi,
8084 bool show_failed, bool use_json)
8085 {
8086 struct peer *peer;
8087 struct listnode *node, *nnode;
8088 unsigned int count = 0, dn_count = 0;
8089 char timebuf[BGP_UPTIME_LEN], dn_flag[2];
8090 char neighbor_buf[VTY_BUFSIZ];
8091 int neighbor_col_default_width = 16;
8092 int len, failed_count = 0;
8093 int max_neighbor_width = 0;
8094 int pfx_rcd_safi;
8095 json_object *json = NULL;
8096 json_object *json_peer = NULL;
8097 json_object *json_peers = NULL;
8098 struct peer_af *paf;
8099
8100 /* labeled-unicast routes are installed in the unicast table so in order
8101 * to
8102 * display the correct PfxRcd value we must look at SAFI_UNICAST
8103 */
8104
8105 if (safi == SAFI_LABELED_UNICAST)
8106 pfx_rcd_safi = SAFI_UNICAST;
8107 else
8108 pfx_rcd_safi = safi;
8109
8110 if (use_json) {
8111 json = json_object_new_object();
8112 json_peers = json_object_new_object();
8113 for (ALL_LIST_ELEMENTS(bgp->peer, node, nnode, peer)) {
8114 if (!CHECK_FLAG(peer->flags, PEER_FLAG_CONFIG_NODE))
8115 continue;
8116
8117 if (peer->afc[afi][safi]) {
8118 /* See if we have at least a single failed peer */
8119 if (bgp_has_peer_failed(peer, afi, safi))
8120 failed_count++;
8121 count++;
8122 }
8123 if (peer_dynamic_neighbor(peer))
8124 dn_count++;
8125 }
8126
8127 } else {
8128 /* Loop over all neighbors that will be displayed to determine
8129 * how many
8130 * characters are needed for the Neighbor column
8131 */
8132 for (ALL_LIST_ELEMENTS(bgp->peer, node, nnode, peer)) {
8133 if (!CHECK_FLAG(peer->flags, PEER_FLAG_CONFIG_NODE))
8134 continue;
8135
8136 if (peer->afc[afi][safi]) {
8137 memset(dn_flag, '\0', sizeof(dn_flag));
8138 if (peer_dynamic_neighbor(peer))
8139 dn_flag[0] = '*';
8140
8141 if (peer->hostname
8142 && bgp_flag_check(bgp,
8143 BGP_FLAG_SHOW_HOSTNAME))
8144 sprintf(neighbor_buf, "%s%s(%s) ",
8145 dn_flag, peer->hostname,
8146 peer->host);
8147 else
8148 sprintf(neighbor_buf, "%s%s ", dn_flag,
8149 peer->host);
8150
8151 len = strlen(neighbor_buf);
8152
8153 if (len > max_neighbor_width)
8154 max_neighbor_width = len;
8155
8156 /* See if we have at least a single failed peer */
8157 if (bgp_has_peer_failed(peer, afi, safi))
8158 failed_count++;
8159 count++;
8160 }
8161 }
8162
8163 /* Originally we displayed the Neighbor column as 16
8164 * characters wide so make that the default
8165 */
8166 if (max_neighbor_width < neighbor_col_default_width)
8167 max_neighbor_width = neighbor_col_default_width;
8168 }
8169
8170 if (show_failed && !failed_count) {
8171 if (use_json) {
8172 json_object_int_add(json, "failedPeersCount", 0);
8173 json_object_int_add(json, "dynamicPeers", dn_count);
8174 json_object_int_add(json, "totalPeers", count);
8175
8176 vty_out(vty, "%s\n", json_object_to_json_string_ext(
8177 json, JSON_C_TO_STRING_PRETTY));
8178 json_object_free(json);
8179 } else {
8180 vty_out(vty, "%% No failed BGP neighbors found\n");
8181 vty_out(vty, "\nTotal number of neighbors %d\n", count);
8182 }
8183 return CMD_SUCCESS;
8184 }
8185
8186 count = 0; /* Reset the value as its used again */
8187 for (ALL_LIST_ELEMENTS(bgp->peer, node, nnode, peer)) {
8188 if (!CHECK_FLAG(peer->flags, PEER_FLAG_CONFIG_NODE))
8189 continue;
8190
8191 if (!peer->afc[afi][safi])
8192 continue;
8193
8194 if (!count) {
8195 unsigned long ents;
8196 char memstrbuf[MTYPE_MEMSTR_LEN];
8197 int64_t vrf_id_ui;
8198
8199 vrf_id_ui = (bgp->vrf_id == VRF_UNKNOWN)
8200 ? -1
8201 : (int64_t)bgp->vrf_id;
8202
8203 /* Usage summary and header */
8204 if (use_json) {
8205 json_object_string_add(
8206 json, "routerId",
8207 inet_ntoa(bgp->router_id));
8208 json_object_int_add(json, "as", bgp->as);
8209 json_object_int_add(json, "vrfId", vrf_id_ui);
8210 json_object_string_add(
8211 json, "vrfName",
8212 (bgp->inst_type
8213 == BGP_INSTANCE_TYPE_DEFAULT)
8214 ? VRF_DEFAULT_NAME
8215 : bgp->name);
8216 } else {
8217 vty_out(vty,
8218 "BGP router identifier %s, local AS number %u vrf-id %d",
8219 inet_ntoa(bgp->router_id), bgp->as,
8220 bgp->vrf_id == VRF_UNKNOWN
8221 ? -1
8222 : (int)bgp->vrf_id);
8223 vty_out(vty, "\n");
8224 }
8225
8226 if (bgp_update_delay_configured(bgp)) {
8227 if (use_json) {
8228 json_object_int_add(
8229 json, "updateDelayLimit",
8230 bgp->v_update_delay);
8231
8232 if (bgp->v_update_delay
8233 != bgp->v_establish_wait)
8234 json_object_int_add(
8235 json,
8236 "updateDelayEstablishWait",
8237 bgp->v_establish_wait);
8238
8239 if (bgp_update_delay_active(bgp)) {
8240 json_object_string_add(
8241 json,
8242 "updateDelayFirstNeighbor",
8243 bgp->update_delay_begin_time);
8244 json_object_boolean_true_add(
8245 json,
8246 "updateDelayInProgress");
8247 } else {
8248 if (bgp->update_delay_over) {
8249 json_object_string_add(
8250 json,
8251 "updateDelayFirstNeighbor",
8252 bgp->update_delay_begin_time);
8253 json_object_string_add(
8254 json,
8255 "updateDelayBestpathResumed",
8256 bgp->update_delay_end_time);
8257 json_object_string_add(
8258 json,
8259 "updateDelayZebraUpdateResume",
8260 bgp->update_delay_zebra_resume_time);
8261 json_object_string_add(
8262 json,
8263 "updateDelayPeerUpdateResume",
8264 bgp->update_delay_peers_resume_time);
8265 }
8266 }
8267 } else {
8268 vty_out(vty,
8269 "Read-only mode update-delay limit: %d seconds\n",
8270 bgp->v_update_delay);
8271 if (bgp->v_update_delay
8272 != bgp->v_establish_wait)
8273 vty_out(vty,
8274 " Establish wait: %d seconds\n",
8275 bgp->v_establish_wait);
8276
8277 if (bgp_update_delay_active(bgp)) {
8278 vty_out(vty,
8279 " First neighbor established: %s\n",
8280 bgp->update_delay_begin_time);
8281 vty_out(vty,
8282 " Delay in progress\n");
8283 } else {
8284 if (bgp->update_delay_over) {
8285 vty_out(vty,
8286 " First neighbor established: %s\n",
8287 bgp->update_delay_begin_time);
8288 vty_out(vty,
8289 " Best-paths resumed: %s\n",
8290 bgp->update_delay_end_time);
8291 vty_out(vty,
8292 " zebra update resumed: %s\n",
8293 bgp->update_delay_zebra_resume_time);
8294 vty_out(vty,
8295 " peers update resumed: %s\n",
8296 bgp->update_delay_peers_resume_time);
8297 }
8298 }
8299 }
8300 }
8301
8302 if (use_json) {
8303 if (bgp_maxmed_onstartup_configured(bgp)
8304 && bgp->maxmed_active)
8305 json_object_boolean_true_add(
8306 json, "maxMedOnStartup");
8307 if (bgp->v_maxmed_admin)
8308 json_object_boolean_true_add(
8309 json, "maxMedAdministrative");
8310
8311 json_object_int_add(
8312 json, "tableVersion",
8313 bgp_table_version(bgp->rib[afi][safi]));
8314
8315 ents = bgp_table_count(bgp->rib[afi][safi]);
8316 json_object_int_add(json, "ribCount", ents);
8317 json_object_int_add(
8318 json, "ribMemory",
8319 ents * sizeof(struct bgp_node));
8320
8321 ents = bgp->af_peer_count[afi][safi];
8322 json_object_int_add(json, "peerCount", ents);
8323 json_object_int_add(json, "peerMemory",
8324 ents * sizeof(struct peer));
8325
8326 if ((ents = listcount(bgp->group))) {
8327 json_object_int_add(
8328 json, "peerGroupCount", ents);
8329 json_object_int_add(
8330 json, "peerGroupMemory",
8331 ents * sizeof(struct
8332 peer_group));
8333 }
8334
8335 if (CHECK_FLAG(bgp->af_flags[afi][safi],
8336 BGP_CONFIG_DAMPENING))
8337 json_object_boolean_true_add(
8338 json, "dampeningEnabled");
8339 } else {
8340 if (bgp_maxmed_onstartup_configured(bgp)
8341 && bgp->maxmed_active)
8342 vty_out(vty,
8343 "Max-med on-startup active\n");
8344 if (bgp->v_maxmed_admin)
8345 vty_out(vty,
8346 "Max-med administrative active\n");
8347
8348 vty_out(vty, "BGP table version %" PRIu64 "\n",
8349 bgp_table_version(bgp->rib[afi][safi]));
8350
8351 ents = bgp_table_count(bgp->rib[afi][safi]);
8352 vty_out(vty,
8353 "RIB entries %ld, using %s of memory\n",
8354 ents,
8355 mtype_memstr(memstrbuf,
8356 sizeof(memstrbuf),
8357 ents * sizeof(struct
8358 bgp_node)));
8359
8360 /* Peer related usage */
8361 ents = bgp->af_peer_count[afi][safi];
8362 vty_out(vty, "Peers %ld, using %s of memory\n",
8363 ents,
8364 mtype_memstr(
8365 memstrbuf, sizeof(memstrbuf),
8366 ents * sizeof(struct peer)));
8367
8368 if ((ents = listcount(bgp->group)))
8369 vty_out(vty,
8370 "Peer groups %ld, using %s of memory\n",
8371 ents,
8372 mtype_memstr(
8373 memstrbuf,
8374 sizeof(memstrbuf),
8375 ents * sizeof(struct
8376 peer_group)));
8377
8378 if (CHECK_FLAG(bgp->af_flags[afi][safi],
8379 BGP_CONFIG_DAMPENING))
8380 vty_out(vty, "Dampening enabled.\n");
8381 vty_out(vty, "\n");
8382
8383 /* Subtract 8 here because 'Neighbor' is
8384 * 8 characters */
8385 vty_out(vty, "Neighbor");
8386 vty_out(vty, "%*s", max_neighbor_width - 8,
8387 " ");
8388 if (show_failed)
8389 vty_out(vty, "EstdCnt DropCnt ResetTime Reason\n");
8390 else
8391 vty_out(vty,
8392 "V AS MsgRcvd MsgSent TblVer InQ OutQ Up/Down State/PfxRcd\n");
8393 }
8394 }
8395
8396 count++;
8397 /* Works for both failed & successful cases */
8398 if (peer_dynamic_neighbor(peer))
8399 dn_count++;
8400
8401 if (use_json) {
8402 json_peer = NULL;
8403
8404 if (show_failed &&
8405 bgp_has_peer_failed(peer, afi, safi)) {
8406 json_peer = json_object_new_object();
8407 bgp_show_failed_summary(vty, bgp, peer,
8408 json_peer, 0, use_json);
8409 } else if (!show_failed) {
8410 json_peer = json_object_new_object();
8411 if (peer_dynamic_neighbor(peer)) {
8412 json_object_boolean_true_add(json_peer,
8413 "dynamicPeer");
8414 }
8415
8416 if (peer->hostname)
8417 json_object_string_add(json_peer, "hostname",
8418 peer->hostname);
8419
8420 if (peer->domainname)
8421 json_object_string_add(json_peer, "domainname",
8422 peer->domainname);
8423
8424 json_object_int_add(json_peer, "remoteAs", peer->as);
8425 json_object_int_add(json_peer, "version", 4);
8426 json_object_int_add(json_peer, "msgRcvd",
8427 PEER_TOTAL_RX(peer));
8428 json_object_int_add(json_peer, "msgSent",
8429 PEER_TOTAL_TX(peer));
8430
8431 json_object_int_add(json_peer, "tableVersion",
8432 peer->version[afi][safi]);
8433 json_object_int_add(json_peer, "outq",
8434 peer->obuf->count);
8435 json_object_int_add(json_peer, "inq", 0);
8436 peer_uptime(peer->uptime, timebuf, BGP_UPTIME_LEN,
8437 use_json, json_peer);
8438
8439 /*
8440 * Adding "pfxRcd" field to match with the corresponding
8441 * CLI. "prefixReceivedCount" will be deprecated in
8442 * future.
8443 */
8444 json_object_int_add(json_peer, "prefixReceivedCount",
8445 peer->pcount[afi][pfx_rcd_safi]);
8446 json_object_int_add(json_peer, "pfxRcd",
8447 peer->pcount[afi][pfx_rcd_safi]);
8448
8449 paf = peer_af_find(peer, afi, pfx_rcd_safi);
8450 if (paf && PAF_SUBGRP(paf))
8451 json_object_int_add(json_peer,
8452 "pfxSnt",
8453 (PAF_SUBGRP(paf))->scount);
8454 if (CHECK_FLAG(peer->flags, PEER_FLAG_SHUTDOWN))
8455 json_object_string_add(json_peer, "state",
8456 "Idle (Admin)");
8457 else if (peer->afc_recv[afi][safi])
8458 json_object_string_add(
8459 json_peer, "state",
8460 lookup_msg(bgp_status_msg, peer->status,
8461 NULL));
8462 else if (CHECK_FLAG(peer->sflags,
8463 PEER_STATUS_PREFIX_OVERFLOW))
8464 json_object_string_add(json_peer, "state",
8465 "Idle (PfxCt)");
8466 else
8467 json_object_string_add(
8468 json_peer, "state",
8469 lookup_msg(bgp_status_msg, peer->status,
8470 NULL));
8471 json_object_int_add(json_peer, "connectionsEstablished",
8472 peer->established);
8473 json_object_int_add(json_peer, "connectionsDropped",
8474 peer->dropped);
8475 }
8476 /* Avoid creating empty peer dicts in JSON */
8477 if (json_peer == NULL)
8478 continue;
8479
8480 if (peer->conf_if)
8481 json_object_string_add(json_peer, "idType",
8482 "interface");
8483 else if (peer->su.sa.sa_family == AF_INET)
8484 json_object_string_add(json_peer, "idType",
8485 "ipv4");
8486 else if (peer->su.sa.sa_family == AF_INET6)
8487 json_object_string_add(json_peer, "idType",
8488 "ipv6");
8489 json_object_object_add(json_peers, peer->host,
8490 json_peer);
8491 } else {
8492 if (show_failed &&
8493 bgp_has_peer_failed(peer, afi, safi)) {
8494 bgp_show_failed_summary(vty, bgp, peer, NULL,
8495 max_neighbor_width,
8496 use_json);
8497 } else if (!show_failed) {
8498 memset(dn_flag, '\0', sizeof(dn_flag));
8499 if (peer_dynamic_neighbor(peer)) {
8500 dn_flag[0] = '*';
8501 }
8502
8503 if (peer->hostname
8504 && bgp_flag_check(bgp, BGP_FLAG_SHOW_HOSTNAME))
8505 len = vty_out(vty, "%s%s(%s)", dn_flag,
8506 peer->hostname, peer->host);
8507 else
8508 len = vty_out(vty, "%s%s", dn_flag, peer->host);
8509
8510 /* pad the neighbor column with spaces */
8511 if (len < max_neighbor_width)
8512 vty_out(vty, "%*s", max_neighbor_width - len,
8513 " ");
8514
8515 vty_out(vty, "4 %10u %7u %7u %8" PRIu64 " %4d %4zd %8s",
8516 peer->as, PEER_TOTAL_RX(peer),
8517 PEER_TOTAL_TX(peer), peer->version[afi][safi],
8518 0, peer->obuf->count,
8519 peer_uptime(peer->uptime, timebuf,
8520 BGP_UPTIME_LEN, 0, NULL));
8521
8522 if (peer->status == Established)
8523 if (peer->afc_recv[afi][safi])
8524 vty_out(vty, " %12" PRIu32,
8525 peer->pcount
8526 [afi]
8527 [pfx_rcd_safi]);
8528 else
8529 vty_out(vty, " NoNeg");
8530 else {
8531 if (CHECK_FLAG(peer->flags, PEER_FLAG_SHUTDOWN))
8532 vty_out(vty, " Idle (Admin)");
8533 else if (CHECK_FLAG(
8534 peer->sflags,
8535 PEER_STATUS_PREFIX_OVERFLOW))
8536 vty_out(vty, " Idle (PfxCt)");
8537 else
8538 vty_out(vty, " %12s",
8539 lookup_msg(bgp_status_msg,
8540 peer->status, NULL));
8541 }
8542 vty_out(vty, "\n");
8543 }
8544
8545 }
8546 }
8547
8548 if (use_json) {
8549 json_object_object_add(json, "peers", json_peers);
8550 json_object_int_add(json, "failedPeers", failed_count);
8551 json_object_int_add(json, "totalPeers", count);
8552 json_object_int_add(json, "dynamicPeers", dn_count);
8553
8554 if (!show_failed)
8555 bgp_show_bestpath_json(bgp, json);
8556
8557 vty_out(vty, "%s\n", json_object_to_json_string_ext(
8558 json, JSON_C_TO_STRING_PRETTY));
8559 json_object_free(json);
8560 } else {
8561 if (count)
8562 vty_out(vty, "\nTotal number of neighbors %d\n", count);
8563 else {
8564 vty_out(vty, "No %s neighbor is configured\n",
8565 get_afi_safi_str(afi, safi, false));
8566 }
8567
8568 if (dn_count) {
8569 vty_out(vty, "* - dynamic neighbor\n");
8570 vty_out(vty, "%d dynamic neighbor(s), limit %d\n",
8571 dn_count, bgp->dynamic_neighbors_limit);
8572 }
8573 }
8574
8575 return CMD_SUCCESS;
8576 }
8577
8578 static void bgp_show_summary_afi_safi(struct vty *vty, struct bgp *bgp, int afi,
8579 int safi, bool show_failed, bool use_json)
8580 {
8581 int is_first = 1;
8582 int afi_wildcard = (afi == AFI_MAX);
8583 int safi_wildcard = (safi == SAFI_MAX);
8584 int is_wildcard = (afi_wildcard || safi_wildcard);
8585 bool nbr_output = false;
8586
8587 if (use_json && is_wildcard)
8588 vty_out(vty, "{\n");
8589 if (afi_wildcard)
8590 afi = 1; /* AFI_IP */
8591 while (afi < AFI_MAX) {
8592 if (safi_wildcard)
8593 safi = 1; /* SAFI_UNICAST */
8594 while (safi < SAFI_MAX) {
8595 if (bgp_afi_safi_peer_exists(bgp, afi, safi)) {
8596 nbr_output = true;
8597
8598 if (is_wildcard) {
8599 /*
8600 * So limit output to those afi/safi
8601 * pairs that
8602 * actualy have something interesting in
8603 * them
8604 */
8605 if (use_json) {
8606 if (!is_first)
8607 vty_out(vty, ",\n");
8608 else
8609 is_first = 0;
8610
8611 vty_out(vty, "\"%s\":",
8612 get_afi_safi_str(afi,
8613 safi,
8614 true));
8615 } else {
8616 vty_out(vty, "\n%s Summary:\n",
8617 get_afi_safi_str(afi,
8618 safi,
8619 false));
8620 }
8621 }
8622 bgp_show_summary(vty, bgp, afi, safi, show_failed,
8623 use_json);
8624 }
8625 safi++;
8626 if (!safi_wildcard)
8627 safi = SAFI_MAX;
8628 }
8629 afi++;
8630 if (!afi_wildcard)
8631 afi = AFI_MAX;
8632 }
8633
8634 if (use_json && is_wildcard)
8635 vty_out(vty, "}\n");
8636 else if (!nbr_output) {
8637 if (use_json)
8638 vty_out(vty, "{}\n");
8639 else
8640 vty_out(vty, "%% No BGP neighbors found\n");
8641 }
8642 }
8643
8644 static void bgp_show_all_instances_summary_vty(struct vty *vty, afi_t afi,
8645 safi_t safi, bool show_failed,
8646 bool use_json)
8647 {
8648 struct listnode *node, *nnode;
8649 struct bgp *bgp;
8650 int is_first = 1;
8651 bool nbr_output = false;
8652
8653 if (use_json)
8654 vty_out(vty, "{\n");
8655
8656 for (ALL_LIST_ELEMENTS(bm->bgp, node, nnode, bgp)) {
8657 nbr_output = true;
8658 if (use_json) {
8659 if (!is_first)
8660 vty_out(vty, ",\n");
8661 else
8662 is_first = 0;
8663
8664 vty_out(vty, "\"%s\":",
8665 (bgp->inst_type == BGP_INSTANCE_TYPE_DEFAULT)
8666 ? VRF_DEFAULT_NAME
8667 : bgp->name);
8668 } else {
8669 vty_out(vty, "\nInstance %s:\n",
8670 (bgp->inst_type == BGP_INSTANCE_TYPE_DEFAULT)
8671 ? VRF_DEFAULT_NAME
8672 : bgp->name);
8673 }
8674 bgp_show_summary_afi_safi(vty, bgp, afi, safi, show_failed,
8675 use_json);
8676 }
8677
8678 if (use_json)
8679 vty_out(vty, "}\n");
8680 else if (!nbr_output)
8681 vty_out(vty, "%% BGP instance not found\n");
8682 }
8683
8684 int bgp_show_summary_vty(struct vty *vty, const char *name, afi_t afi,
8685 safi_t safi, bool show_failed, bool use_json)
8686 {
8687 struct bgp *bgp;
8688
8689 if (name) {
8690 if (strmatch(name, "all")) {
8691 bgp_show_all_instances_summary_vty(vty, afi, safi,
8692 show_failed,
8693 use_json);
8694 return CMD_SUCCESS;
8695 } else {
8696 bgp = bgp_lookup_by_name(name);
8697
8698 if (!bgp) {
8699 if (use_json)
8700 vty_out(vty, "{}\n");
8701 else
8702 vty_out(vty,
8703 "%% BGP instance not found\n");
8704 return CMD_WARNING;
8705 }
8706
8707 bgp_show_summary_afi_safi(vty, bgp, afi, safi,
8708 show_failed, use_json);
8709 return CMD_SUCCESS;
8710 }
8711 }
8712
8713 bgp = bgp_get_default();
8714
8715 if (bgp)
8716 bgp_show_summary_afi_safi(vty, bgp, afi, safi, show_failed,
8717 use_json);
8718 else {
8719 if (use_json)
8720 vty_out(vty, "{}\n");
8721 else
8722 vty_out(vty, "%% BGP instance not found\n");
8723 return CMD_WARNING;
8724 }
8725
8726 return CMD_SUCCESS;
8727 }
8728
8729 /* `show [ip] bgp summary' commands. */
8730 DEFUN (show_ip_bgp_summary,
8731 show_ip_bgp_summary_cmd,
8732 "show [ip] bgp [<view|vrf> VIEWVRFNAME] ["BGP_AFI_CMD_STR" ["BGP_SAFI_WITH_LABEL_CMD_STR"]] summary [failed] [json]",
8733 SHOW_STR
8734 IP_STR
8735 BGP_STR
8736 BGP_INSTANCE_HELP_STR
8737 BGP_AFI_HELP_STR
8738 BGP_SAFI_WITH_LABEL_HELP_STR
8739 "Summary of BGP neighbor status\n"
8740 "Show only sessions not in Established state\n"
8741 JSON_STR)
8742 {
8743 char *vrf = NULL;
8744 afi_t afi = AFI_MAX;
8745 safi_t safi = SAFI_MAX;
8746 bool show_failed = false;
8747
8748 int idx = 0;
8749
8750 /* show [ip] bgp */
8751 if (argv_find(argv, argc, "ip", &idx))
8752 afi = AFI_IP;
8753 /* [<vrf> VIEWVRFNAME] */
8754 if (argv_find(argv, argc, "vrf", &idx)) {
8755 vrf = argv[idx + 1]->arg;
8756 if (vrf && strmatch(vrf, VRF_DEFAULT_NAME))
8757 vrf = NULL;
8758 } else if (argv_find(argv, argc, "view", &idx))
8759 /* [<view> VIEWVRFNAME] */
8760 vrf = argv[idx + 1]->arg;
8761 /* ["BGP_AFI_CMD_STR" ["BGP_SAFI_CMD_STR"]] */
8762 if (argv_find_and_parse_afi(argv, argc, &idx, &afi)) {
8763 argv_find_and_parse_safi(argv, argc, &idx, &safi);
8764 }
8765
8766 if (argv_find(argv, argc, "failed", &idx))
8767 show_failed = true;
8768
8769 bool uj = use_json(argc, argv);
8770
8771 return bgp_show_summary_vty(vty, vrf, afi, safi, show_failed, uj);
8772 }
8773
8774 const char *get_afi_safi_str(afi_t afi, safi_t safi, bool for_json)
8775 {
8776 if (for_json)
8777 return get_afi_safi_json_str(afi, safi);
8778 else
8779 return get_afi_safi_vty_str(afi, safi);
8780 }
8781
8782 /* Show BGP peer's information. */
8783 enum show_type { show_all, show_peer, show_ipv4_all, show_ipv6_all, show_ipv4_peer, show_ipv6_peer };
8784
8785 static void bgp_show_peer_afi_orf_cap(struct vty *vty, struct peer *p,
8786 afi_t afi, safi_t safi,
8787 uint16_t adv_smcap, uint16_t adv_rmcap,
8788 uint16_t rcv_smcap, uint16_t rcv_rmcap,
8789 bool use_json, json_object *json_pref)
8790 {
8791 /* Send-Mode */
8792 if (CHECK_FLAG(p->af_cap[afi][safi], adv_smcap)
8793 || CHECK_FLAG(p->af_cap[afi][safi], rcv_smcap)) {
8794 if (use_json) {
8795 if (CHECK_FLAG(p->af_cap[afi][safi], adv_smcap)
8796 && CHECK_FLAG(p->af_cap[afi][safi], rcv_smcap))
8797 json_object_string_add(json_pref, "sendMode",
8798 "advertisedAndReceived");
8799 else if (CHECK_FLAG(p->af_cap[afi][safi], adv_smcap))
8800 json_object_string_add(json_pref, "sendMode",
8801 "advertised");
8802 else if (CHECK_FLAG(p->af_cap[afi][safi], rcv_smcap))
8803 json_object_string_add(json_pref, "sendMode",
8804 "received");
8805 } else {
8806 vty_out(vty, " Send-mode: ");
8807 if (CHECK_FLAG(p->af_cap[afi][safi], adv_smcap))
8808 vty_out(vty, "advertised");
8809 if (CHECK_FLAG(p->af_cap[afi][safi], rcv_smcap))
8810 vty_out(vty, "%sreceived",
8811 CHECK_FLAG(p->af_cap[afi][safi],
8812 adv_smcap)
8813 ? ", "
8814 : "");
8815 vty_out(vty, "\n");
8816 }
8817 }
8818
8819 /* Receive-Mode */
8820 if (CHECK_FLAG(p->af_cap[afi][safi], adv_rmcap)
8821 || CHECK_FLAG(p->af_cap[afi][safi], rcv_rmcap)) {
8822 if (use_json) {
8823 if (CHECK_FLAG(p->af_cap[afi][safi], adv_rmcap)
8824 && CHECK_FLAG(p->af_cap[afi][safi], rcv_rmcap))
8825 json_object_string_add(json_pref, "recvMode",
8826 "advertisedAndReceived");
8827 else if (CHECK_FLAG(p->af_cap[afi][safi], adv_rmcap))
8828 json_object_string_add(json_pref, "recvMode",
8829 "advertised");
8830 else if (CHECK_FLAG(p->af_cap[afi][safi], rcv_rmcap))
8831 json_object_string_add(json_pref, "recvMode",
8832 "received");
8833 } else {
8834 vty_out(vty, " Receive-mode: ");
8835 if (CHECK_FLAG(p->af_cap[afi][safi], adv_rmcap))
8836 vty_out(vty, "advertised");
8837 if (CHECK_FLAG(p->af_cap[afi][safi], rcv_rmcap))
8838 vty_out(vty, "%sreceived",
8839 CHECK_FLAG(p->af_cap[afi][safi],
8840 adv_rmcap)
8841 ? ", "
8842 : "");
8843 vty_out(vty, "\n");
8844 }
8845 }
8846 }
8847
8848 static void bgp_show_peer_afi(struct vty *vty, struct peer *p, afi_t afi,
8849 safi_t safi, bool use_json,
8850 json_object *json_neigh)
8851 {
8852 struct bgp_filter *filter;
8853 struct peer_af *paf;
8854 char orf_pfx_name[BUFSIZ];
8855 int orf_pfx_count;
8856 json_object *json_af = NULL;
8857 json_object *json_prefA = NULL;
8858 json_object *json_prefB = NULL;
8859 json_object *json_addr = NULL;
8860
8861 if (use_json) {
8862 json_addr = json_object_new_object();
8863 json_af = json_object_new_object();
8864 filter = &p->filter[afi][safi];
8865
8866 if (peer_group_active(p))
8867 json_object_string_add(json_addr, "peerGroupMember",
8868 p->group->name);
8869
8870 paf = peer_af_find(p, afi, safi);
8871 if (paf && PAF_SUBGRP(paf)) {
8872 json_object_int_add(json_addr, "updateGroupId",
8873 PAF_UPDGRP(paf)->id);
8874 json_object_int_add(json_addr, "subGroupId",
8875 PAF_SUBGRP(paf)->id);
8876 json_object_int_add(json_addr, "packetQueueLength",
8877 bpacket_queue_virtual_length(paf));
8878 }
8879
8880 if (CHECK_FLAG(p->af_cap[afi][safi], PEER_CAP_ORF_PREFIX_SM_ADV)
8881 || CHECK_FLAG(p->af_cap[afi][safi],
8882 PEER_CAP_ORF_PREFIX_SM_RCV)
8883 || CHECK_FLAG(p->af_cap[afi][safi],
8884 PEER_CAP_ORF_PREFIX_RM_ADV)
8885 || CHECK_FLAG(p->af_cap[afi][safi],
8886 PEER_CAP_ORF_PREFIX_RM_RCV)) {
8887 json_object_int_add(json_af, "orfType",
8888 ORF_TYPE_PREFIX);
8889 json_prefA = json_object_new_object();
8890 bgp_show_peer_afi_orf_cap(vty, p, afi, safi,
8891 PEER_CAP_ORF_PREFIX_SM_ADV,
8892 PEER_CAP_ORF_PREFIX_RM_ADV,
8893 PEER_CAP_ORF_PREFIX_SM_RCV,
8894 PEER_CAP_ORF_PREFIX_RM_RCV,
8895 use_json, json_prefA);
8896 json_object_object_add(json_af, "orfPrefixList",
8897 json_prefA);
8898 }
8899
8900 if (CHECK_FLAG(p->af_cap[afi][safi], PEER_CAP_ORF_PREFIX_SM_ADV)
8901 || CHECK_FLAG(p->af_cap[afi][safi],
8902 PEER_CAP_ORF_PREFIX_SM_OLD_RCV)
8903 || CHECK_FLAG(p->af_cap[afi][safi],
8904 PEER_CAP_ORF_PREFIX_RM_ADV)
8905 || CHECK_FLAG(p->af_cap[afi][safi],
8906 PEER_CAP_ORF_PREFIX_RM_OLD_RCV)) {
8907 json_object_int_add(json_af, "orfOldType",
8908 ORF_TYPE_PREFIX_OLD);
8909 json_prefB = json_object_new_object();
8910 bgp_show_peer_afi_orf_cap(
8911 vty, p, afi, safi, PEER_CAP_ORF_PREFIX_SM_ADV,
8912 PEER_CAP_ORF_PREFIX_RM_ADV,
8913 PEER_CAP_ORF_PREFIX_SM_OLD_RCV,
8914 PEER_CAP_ORF_PREFIX_RM_OLD_RCV, use_json,
8915 json_prefB);
8916 json_object_object_add(json_af, "orfOldPrefixList",
8917 json_prefB);
8918 }
8919
8920 if (CHECK_FLAG(p->af_cap[afi][safi], PEER_CAP_ORF_PREFIX_SM_ADV)
8921 || CHECK_FLAG(p->af_cap[afi][safi],
8922 PEER_CAP_ORF_PREFIX_SM_RCV)
8923 || CHECK_FLAG(p->af_cap[afi][safi],
8924 PEER_CAP_ORF_PREFIX_SM_OLD_RCV)
8925 || CHECK_FLAG(p->af_cap[afi][safi],
8926 PEER_CAP_ORF_PREFIX_RM_ADV)
8927 || CHECK_FLAG(p->af_cap[afi][safi],
8928 PEER_CAP_ORF_PREFIX_RM_RCV)
8929 || CHECK_FLAG(p->af_cap[afi][safi],
8930 PEER_CAP_ORF_PREFIX_RM_OLD_RCV))
8931 json_object_object_add(json_addr, "afDependentCap",
8932 json_af);
8933 else
8934 json_object_free(json_af);
8935
8936 sprintf(orf_pfx_name, "%s.%d.%d", p->host, afi, safi);
8937 orf_pfx_count = prefix_bgp_show_prefix_list(
8938 NULL, afi, orf_pfx_name, use_json);
8939
8940 if (CHECK_FLAG(p->af_sflags[afi][safi],
8941 PEER_STATUS_ORF_PREFIX_SEND)
8942 || orf_pfx_count) {
8943 if (CHECK_FLAG(p->af_sflags[afi][safi],
8944 PEER_STATUS_ORF_PREFIX_SEND))
8945 json_object_boolean_true_add(json_neigh,
8946 "orfSent");
8947 if (orf_pfx_count)
8948 json_object_int_add(json_addr, "orfRecvCounter",
8949 orf_pfx_count);
8950 }
8951 if (CHECK_FLAG(p->af_sflags[afi][safi],
8952 PEER_STATUS_ORF_WAIT_REFRESH))
8953 json_object_string_add(
8954 json_addr, "orfFirstUpdate",
8955 "deferredUntilORFOrRouteRefreshRecvd");
8956
8957 if (CHECK_FLAG(p->af_flags[afi][safi],
8958 PEER_FLAG_REFLECTOR_CLIENT))
8959 json_object_boolean_true_add(json_addr,
8960 "routeReflectorClient");
8961 if (CHECK_FLAG(p->af_flags[afi][safi],
8962 PEER_FLAG_RSERVER_CLIENT))
8963 json_object_boolean_true_add(json_addr,
8964 "routeServerClient");
8965 if (CHECK_FLAG(p->af_flags[afi][safi], PEER_FLAG_SOFT_RECONFIG))
8966 json_object_boolean_true_add(json_addr,
8967 "inboundSoftConfigPermit");
8968
8969 if (CHECK_FLAG(p->af_flags[afi][safi],
8970 PEER_FLAG_REMOVE_PRIVATE_AS_ALL_REPLACE))
8971 json_object_boolean_true_add(
8972 json_addr,
8973 "privateAsNumsAllReplacedInUpdatesToNbr");
8974 else if (CHECK_FLAG(p->af_flags[afi][safi],
8975 PEER_FLAG_REMOVE_PRIVATE_AS_REPLACE))
8976 json_object_boolean_true_add(
8977 json_addr,
8978 "privateAsNumsReplacedInUpdatesToNbr");
8979 else if (CHECK_FLAG(p->af_flags[afi][safi],
8980 PEER_FLAG_REMOVE_PRIVATE_AS_ALL))
8981 json_object_boolean_true_add(
8982 json_addr,
8983 "privateAsNumsAllRemovedInUpdatesToNbr");
8984 else if (CHECK_FLAG(p->af_flags[afi][safi],
8985 PEER_FLAG_REMOVE_PRIVATE_AS))
8986 json_object_boolean_true_add(
8987 json_addr,
8988 "privateAsNumsRemovedInUpdatesToNbr");
8989
8990 if (p->addpath_type[afi][safi] != BGP_ADDPATH_NONE)
8991 json_object_boolean_true_add(
8992 json_addr,
8993 bgp_addpath_names(p->addpath_type[afi][safi])
8994 ->type_json_name);
8995
8996 if (CHECK_FLAG(p->af_flags[afi][safi], PEER_FLAG_AS_OVERRIDE))
8997 json_object_string_add(json_addr,
8998 "overrideASNsInOutboundUpdates",
8999 "ifAspathEqualRemoteAs");
9000
9001 if (CHECK_FLAG(p->af_flags[afi][safi], PEER_FLAG_NEXTHOP_SELF)
9002 || CHECK_FLAG(p->af_flags[afi][safi],
9003 PEER_FLAG_FORCE_NEXTHOP_SELF))
9004 json_object_boolean_true_add(json_addr,
9005 "routerAlwaysNextHop");
9006 if (CHECK_FLAG(p->af_flags[afi][safi],
9007 PEER_FLAG_AS_PATH_UNCHANGED))
9008 json_object_boolean_true_add(
9009 json_addr, "unchangedAsPathPropogatedToNbr");
9010 if (CHECK_FLAG(p->af_flags[afi][safi],
9011 PEER_FLAG_NEXTHOP_UNCHANGED))
9012 json_object_boolean_true_add(
9013 json_addr, "unchangedNextHopPropogatedToNbr");
9014 if (CHECK_FLAG(p->af_flags[afi][safi], PEER_FLAG_MED_UNCHANGED))
9015 json_object_boolean_true_add(
9016 json_addr, "unchangedMedPropogatedToNbr");
9017 if (CHECK_FLAG(p->af_flags[afi][safi], PEER_FLAG_SEND_COMMUNITY)
9018 || CHECK_FLAG(p->af_flags[afi][safi],
9019 PEER_FLAG_SEND_EXT_COMMUNITY)) {
9020 if (CHECK_FLAG(p->af_flags[afi][safi],
9021 PEER_FLAG_SEND_COMMUNITY)
9022 && CHECK_FLAG(p->af_flags[afi][safi],
9023 PEER_FLAG_SEND_EXT_COMMUNITY))
9024 json_object_string_add(json_addr,
9025 "commAttriSentToNbr",
9026 "extendedAndStandard");
9027 else if (CHECK_FLAG(p->af_flags[afi][safi],
9028 PEER_FLAG_SEND_EXT_COMMUNITY))
9029 json_object_string_add(json_addr,
9030 "commAttriSentToNbr",
9031 "extended");
9032 else
9033 json_object_string_add(json_addr,
9034 "commAttriSentToNbr",
9035 "standard");
9036 }
9037 if (CHECK_FLAG(p->af_flags[afi][safi],
9038 PEER_FLAG_DEFAULT_ORIGINATE)) {
9039 if (p->default_rmap[afi][safi].name)
9040 json_object_string_add(
9041 json_addr, "defaultRouteMap",
9042 p->default_rmap[afi][safi].name);
9043
9044 if (paf && PAF_SUBGRP(paf)
9045 && CHECK_FLAG(PAF_SUBGRP(paf)->sflags,
9046 SUBGRP_STATUS_DEFAULT_ORIGINATE))
9047 json_object_boolean_true_add(json_addr,
9048 "defaultSent");
9049 else
9050 json_object_boolean_true_add(json_addr,
9051 "defaultNotSent");
9052 }
9053
9054 if (afi == AFI_L2VPN && safi == SAFI_EVPN) {
9055 if (is_evpn_enabled())
9056 json_object_boolean_true_add(
9057 json_addr, "advertiseAllVnis");
9058 }
9059
9060 if (filter->plist[FILTER_IN].name
9061 || filter->dlist[FILTER_IN].name
9062 || filter->aslist[FILTER_IN].name
9063 || filter->map[RMAP_IN].name)
9064 json_object_boolean_true_add(json_addr,
9065 "inboundPathPolicyConfig");
9066 if (filter->plist[FILTER_OUT].name
9067 || filter->dlist[FILTER_OUT].name
9068 || filter->aslist[FILTER_OUT].name
9069 || filter->map[RMAP_OUT].name || filter->usmap.name)
9070 json_object_boolean_true_add(
9071 json_addr, "outboundPathPolicyConfig");
9072
9073 /* prefix-list */
9074 if (filter->plist[FILTER_IN].name)
9075 json_object_string_add(json_addr,
9076 "incomingUpdatePrefixFilterList",
9077 filter->plist[FILTER_IN].name);
9078 if (filter->plist[FILTER_OUT].name)
9079 json_object_string_add(json_addr,
9080 "outgoingUpdatePrefixFilterList",
9081 filter->plist[FILTER_OUT].name);
9082
9083 /* distribute-list */
9084 if (filter->dlist[FILTER_IN].name)
9085 json_object_string_add(
9086 json_addr, "incomingUpdateNetworkFilterList",
9087 filter->dlist[FILTER_IN].name);
9088 if (filter->dlist[FILTER_OUT].name)
9089 json_object_string_add(
9090 json_addr, "outgoingUpdateNetworkFilterList",
9091 filter->dlist[FILTER_OUT].name);
9092
9093 /* filter-list. */
9094 if (filter->aslist[FILTER_IN].name)
9095 json_object_string_add(json_addr,
9096 "incomingUpdateAsPathFilterList",
9097 filter->aslist[FILTER_IN].name);
9098 if (filter->aslist[FILTER_OUT].name)
9099 json_object_string_add(json_addr,
9100 "outgoingUpdateAsPathFilterList",
9101 filter->aslist[FILTER_OUT].name);
9102
9103 /* route-map. */
9104 if (filter->map[RMAP_IN].name)
9105 json_object_string_add(
9106 json_addr, "routeMapForIncomingAdvertisements",
9107 filter->map[RMAP_IN].name);
9108 if (filter->map[RMAP_OUT].name)
9109 json_object_string_add(
9110 json_addr, "routeMapForOutgoingAdvertisements",
9111 filter->map[RMAP_OUT].name);
9112
9113 /* ebgp-requires-policy (inbound) */
9114 if (p->bgp->ebgp_requires_policy == DEFAULT_EBGP_POLICY_ENABLED
9115 && !bgp_inbound_policy_exists(p, filter))
9116 json_object_string_add(
9117 json_addr, "inboundEbgpRequiresPolicy",
9118 "Inbound updates discarded due to missing policy");
9119
9120 /* ebgp-requires-policy (outbound) */
9121 if (p->bgp->ebgp_requires_policy == DEFAULT_EBGP_POLICY_ENABLED
9122 && (!bgp_outbound_policy_exists(p, filter)))
9123 json_object_string_add(
9124 json_addr, "outboundEbgpRequiresPolicy",
9125 "Outbound updates discarded due to missing policy");
9126
9127 /* unsuppress-map */
9128 if (filter->usmap.name)
9129 json_object_string_add(json_addr,
9130 "selectiveUnsuppressRouteMap",
9131 filter->usmap.name);
9132
9133 /* Receive prefix count */
9134 json_object_int_add(json_addr, "acceptedPrefixCounter",
9135 p->pcount[afi][safi]);
9136 if (paf && PAF_SUBGRP(paf))
9137 json_object_int_add(json_addr, "sentPrefixCounter",
9138 (PAF_SUBGRP(paf))->scount);
9139
9140 /* Maximum prefix */
9141 if (CHECK_FLAG(p->af_flags[afi][safi], PEER_FLAG_MAX_PREFIX)) {
9142 json_object_int_add(json_addr, "prefixAllowedMax",
9143 p->pmax[afi][safi]);
9144 if (CHECK_FLAG(p->af_flags[afi][safi],
9145 PEER_FLAG_MAX_PREFIX_WARNING))
9146 json_object_boolean_true_add(
9147 json_addr, "prefixAllowedMaxWarning");
9148 json_object_int_add(json_addr,
9149 "prefixAllowedWarningThresh",
9150 p->pmax_threshold[afi][safi]);
9151 if (p->pmax_restart[afi][safi])
9152 json_object_int_add(
9153 json_addr,
9154 "prefixAllowedRestartIntervalMsecs",
9155 p->pmax_restart[afi][safi] * 60000);
9156 }
9157 json_object_object_add(json_neigh, get_afi_safi_str(afi, safi, true),
9158 json_addr);
9159
9160 } else {
9161 filter = &p->filter[afi][safi];
9162
9163 vty_out(vty, " For address family: %s\n",
9164 get_afi_safi_str(afi, safi, false));
9165
9166 if (peer_group_active(p))
9167 vty_out(vty, " %s peer-group member\n",
9168 p->group->name);
9169
9170 paf = peer_af_find(p, afi, safi);
9171 if (paf && PAF_SUBGRP(paf)) {
9172 vty_out(vty, " Update group %" PRIu64
9173 ", subgroup %" PRIu64 "\n",
9174 PAF_UPDGRP(paf)->id, PAF_SUBGRP(paf)->id);
9175 vty_out(vty, " Packet Queue length %d\n",
9176 bpacket_queue_virtual_length(paf));
9177 } else {
9178 vty_out(vty, " Not part of any update group\n");
9179 }
9180 if (CHECK_FLAG(p->af_cap[afi][safi], PEER_CAP_ORF_PREFIX_SM_ADV)
9181 || CHECK_FLAG(p->af_cap[afi][safi],
9182 PEER_CAP_ORF_PREFIX_SM_RCV)
9183 || CHECK_FLAG(p->af_cap[afi][safi],
9184 PEER_CAP_ORF_PREFIX_SM_OLD_RCV)
9185 || CHECK_FLAG(p->af_cap[afi][safi],
9186 PEER_CAP_ORF_PREFIX_RM_ADV)
9187 || CHECK_FLAG(p->af_cap[afi][safi],
9188 PEER_CAP_ORF_PREFIX_RM_RCV)
9189 || CHECK_FLAG(p->af_cap[afi][safi],
9190 PEER_CAP_ORF_PREFIX_RM_OLD_RCV))
9191 vty_out(vty, " AF-dependant capabilities:\n");
9192
9193 if (CHECK_FLAG(p->af_cap[afi][safi], PEER_CAP_ORF_PREFIX_SM_ADV)
9194 || CHECK_FLAG(p->af_cap[afi][safi],
9195 PEER_CAP_ORF_PREFIX_SM_RCV)
9196 || CHECK_FLAG(p->af_cap[afi][safi],
9197 PEER_CAP_ORF_PREFIX_RM_ADV)
9198 || CHECK_FLAG(p->af_cap[afi][safi],
9199 PEER_CAP_ORF_PREFIX_RM_RCV)) {
9200 vty_out(vty,
9201 " Outbound Route Filter (ORF) type (%d) Prefix-list:\n",
9202 ORF_TYPE_PREFIX);
9203 bgp_show_peer_afi_orf_cap(
9204 vty, p, afi, safi, PEER_CAP_ORF_PREFIX_SM_ADV,
9205 PEER_CAP_ORF_PREFIX_RM_ADV,
9206 PEER_CAP_ORF_PREFIX_SM_RCV,
9207 PEER_CAP_ORF_PREFIX_RM_RCV, use_json, NULL);
9208 }
9209 if (CHECK_FLAG(p->af_cap[afi][safi], PEER_CAP_ORF_PREFIX_SM_ADV)
9210 || CHECK_FLAG(p->af_cap[afi][safi],
9211 PEER_CAP_ORF_PREFIX_SM_OLD_RCV)
9212 || CHECK_FLAG(p->af_cap[afi][safi],
9213 PEER_CAP_ORF_PREFIX_RM_ADV)
9214 || CHECK_FLAG(p->af_cap[afi][safi],
9215 PEER_CAP_ORF_PREFIX_RM_OLD_RCV)) {
9216 vty_out(vty,
9217 " Outbound Route Filter (ORF) type (%d) Prefix-list:\n",
9218 ORF_TYPE_PREFIX_OLD);
9219 bgp_show_peer_afi_orf_cap(
9220 vty, p, afi, safi, PEER_CAP_ORF_PREFIX_SM_ADV,
9221 PEER_CAP_ORF_PREFIX_RM_ADV,
9222 PEER_CAP_ORF_PREFIX_SM_OLD_RCV,
9223 PEER_CAP_ORF_PREFIX_RM_OLD_RCV, use_json, NULL);
9224 }
9225
9226 sprintf(orf_pfx_name, "%s.%d.%d", p->host, afi, safi);
9227 orf_pfx_count = prefix_bgp_show_prefix_list(
9228 NULL, afi, orf_pfx_name, use_json);
9229
9230 if (CHECK_FLAG(p->af_sflags[afi][safi],
9231 PEER_STATUS_ORF_PREFIX_SEND)
9232 || orf_pfx_count) {
9233 vty_out(vty, " Outbound Route Filter (ORF):");
9234 if (CHECK_FLAG(p->af_sflags[afi][safi],
9235 PEER_STATUS_ORF_PREFIX_SEND))
9236 vty_out(vty, " sent;");
9237 if (orf_pfx_count)
9238 vty_out(vty, " received (%d entries)",
9239 orf_pfx_count);
9240 vty_out(vty, "\n");
9241 }
9242 if (CHECK_FLAG(p->af_sflags[afi][safi],
9243 PEER_STATUS_ORF_WAIT_REFRESH))
9244 vty_out(vty,
9245 " First update is deferred until ORF or ROUTE-REFRESH is received\n");
9246
9247 if (CHECK_FLAG(p->af_flags[afi][safi],
9248 PEER_FLAG_REFLECTOR_CLIENT))
9249 vty_out(vty, " Route-Reflector Client\n");
9250 if (CHECK_FLAG(p->af_flags[afi][safi],
9251 PEER_FLAG_RSERVER_CLIENT))
9252 vty_out(vty, " Route-Server Client\n");
9253 if (CHECK_FLAG(p->af_flags[afi][safi], PEER_FLAG_SOFT_RECONFIG))
9254 vty_out(vty,
9255 " Inbound soft reconfiguration allowed\n");
9256
9257 if (CHECK_FLAG(p->af_flags[afi][safi],
9258 PEER_FLAG_REMOVE_PRIVATE_AS_ALL_REPLACE))
9259 vty_out(vty,
9260 " Private AS numbers (all) replaced in updates to this neighbor\n");
9261 else if (CHECK_FLAG(p->af_flags[afi][safi],
9262 PEER_FLAG_REMOVE_PRIVATE_AS_REPLACE))
9263 vty_out(vty,
9264 " Private AS numbers replaced in updates to this neighbor\n");
9265 else if (CHECK_FLAG(p->af_flags[afi][safi],
9266 PEER_FLAG_REMOVE_PRIVATE_AS_ALL))
9267 vty_out(vty,
9268 " Private AS numbers (all) removed in updates to this neighbor\n");
9269 else if (CHECK_FLAG(p->af_flags[afi][safi],
9270 PEER_FLAG_REMOVE_PRIVATE_AS))
9271 vty_out(vty,
9272 " Private AS numbers removed in updates to this neighbor\n");
9273
9274 if (p->addpath_type[afi][safi] != BGP_ADDPATH_NONE)
9275 vty_out(vty, " %s\n",
9276 bgp_addpath_names(p->addpath_type[afi][safi])
9277 ->human_description);
9278
9279 if (CHECK_FLAG(p->af_flags[afi][safi], PEER_FLAG_AS_OVERRIDE))
9280 vty_out(vty,
9281 " Override ASNs in outbound updates if aspath equals remote-as\n");
9282
9283 if (CHECK_FLAG(p->af_flags[afi][safi], PEER_FLAG_NEXTHOP_SELF)
9284 || CHECK_FLAG(p->af_flags[afi][safi],
9285 PEER_FLAG_FORCE_NEXTHOP_SELF))
9286 vty_out(vty, " NEXT_HOP is always this router\n");
9287 if (CHECK_FLAG(p->af_flags[afi][safi],
9288 PEER_FLAG_AS_PATH_UNCHANGED))
9289 vty_out(vty,
9290 " AS_PATH is propagated unchanged to this neighbor\n");
9291 if (CHECK_FLAG(p->af_flags[afi][safi],
9292 PEER_FLAG_NEXTHOP_UNCHANGED))
9293 vty_out(vty,
9294 " NEXT_HOP is propagated unchanged to this neighbor\n");
9295 if (CHECK_FLAG(p->af_flags[afi][safi], PEER_FLAG_MED_UNCHANGED))
9296 vty_out(vty,
9297 " MED is propagated unchanged to this neighbor\n");
9298 if (CHECK_FLAG(p->af_flags[afi][safi], PEER_FLAG_SEND_COMMUNITY)
9299 || CHECK_FLAG(p->af_flags[afi][safi],
9300 PEER_FLAG_SEND_EXT_COMMUNITY)
9301 || CHECK_FLAG(p->af_flags[afi][safi],
9302 PEER_FLAG_SEND_LARGE_COMMUNITY)) {
9303 vty_out(vty,
9304 " Community attribute sent to this neighbor");
9305 if (CHECK_FLAG(p->af_flags[afi][safi],
9306 PEER_FLAG_SEND_COMMUNITY)
9307 && CHECK_FLAG(p->af_flags[afi][safi],
9308 PEER_FLAG_SEND_EXT_COMMUNITY)
9309 && CHECK_FLAG(p->af_flags[afi][safi],
9310 PEER_FLAG_SEND_LARGE_COMMUNITY))
9311 vty_out(vty, "(all)\n");
9312 else if (CHECK_FLAG(p->af_flags[afi][safi],
9313 PEER_FLAG_SEND_LARGE_COMMUNITY))
9314 vty_out(vty, "(large)\n");
9315 else if (CHECK_FLAG(p->af_flags[afi][safi],
9316 PEER_FLAG_SEND_EXT_COMMUNITY))
9317 vty_out(vty, "(extended)\n");
9318 else
9319 vty_out(vty, "(standard)\n");
9320 }
9321 if (CHECK_FLAG(p->af_flags[afi][safi],
9322 PEER_FLAG_DEFAULT_ORIGINATE)) {
9323 vty_out(vty, " Default information originate,");
9324
9325 if (p->default_rmap[afi][safi].name)
9326 vty_out(vty, " default route-map %s%s,",
9327 p->default_rmap[afi][safi].map ? "*"
9328 : "",
9329 p->default_rmap[afi][safi].name);
9330 if (paf && PAF_SUBGRP(paf)
9331 && CHECK_FLAG(PAF_SUBGRP(paf)->sflags,
9332 SUBGRP_STATUS_DEFAULT_ORIGINATE))
9333 vty_out(vty, " default sent\n");
9334 else
9335 vty_out(vty, " default not sent\n");
9336 }
9337
9338 /* advertise-vni-all */
9339 if (afi == AFI_L2VPN && safi == SAFI_EVPN) {
9340 if (is_evpn_enabled())
9341 vty_out(vty, " advertise-all-vni\n");
9342 }
9343
9344 if (filter->plist[FILTER_IN].name
9345 || filter->dlist[FILTER_IN].name
9346 || filter->aslist[FILTER_IN].name
9347 || filter->map[RMAP_IN].name)
9348 vty_out(vty, " Inbound path policy configured\n");
9349 if (filter->plist[FILTER_OUT].name
9350 || filter->dlist[FILTER_OUT].name
9351 || filter->aslist[FILTER_OUT].name
9352 || filter->map[RMAP_OUT].name || filter->usmap.name)
9353 vty_out(vty, " Outbound path policy configured\n");
9354
9355 /* prefix-list */
9356 if (filter->plist[FILTER_IN].name)
9357 vty_out(vty,
9358 " Incoming update prefix filter list is %s%s\n",
9359 filter->plist[FILTER_IN].plist ? "*" : "",
9360 filter->plist[FILTER_IN].name);
9361 if (filter->plist[FILTER_OUT].name)
9362 vty_out(vty,
9363 " Outgoing update prefix filter list is %s%s\n",
9364 filter->plist[FILTER_OUT].plist ? "*" : "",
9365 filter->plist[FILTER_OUT].name);
9366
9367 /* distribute-list */
9368 if (filter->dlist[FILTER_IN].name)
9369 vty_out(vty,
9370 " Incoming update network filter list is %s%s\n",
9371 filter->dlist[FILTER_IN].alist ? "*" : "",
9372 filter->dlist[FILTER_IN].name);
9373 if (filter->dlist[FILTER_OUT].name)
9374 vty_out(vty,
9375 " Outgoing update network filter list is %s%s\n",
9376 filter->dlist[FILTER_OUT].alist ? "*" : "",
9377 filter->dlist[FILTER_OUT].name);
9378
9379 /* filter-list. */
9380 if (filter->aslist[FILTER_IN].name)
9381 vty_out(vty,
9382 " Incoming update AS path filter list is %s%s\n",
9383 filter->aslist[FILTER_IN].aslist ? "*" : "",
9384 filter->aslist[FILTER_IN].name);
9385 if (filter->aslist[FILTER_OUT].name)
9386 vty_out(vty,
9387 " Outgoing update AS path filter list is %s%s\n",
9388 filter->aslist[FILTER_OUT].aslist ? "*" : "",
9389 filter->aslist[FILTER_OUT].name);
9390
9391 /* route-map. */
9392 if (filter->map[RMAP_IN].name)
9393 vty_out(vty,
9394 " Route map for incoming advertisements is %s%s\n",
9395 filter->map[RMAP_IN].map ? "*" : "",
9396 filter->map[RMAP_IN].name);
9397 if (filter->map[RMAP_OUT].name)
9398 vty_out(vty,
9399 " Route map for outgoing advertisements is %s%s\n",
9400 filter->map[RMAP_OUT].map ? "*" : "",
9401 filter->map[RMAP_OUT].name);
9402
9403 /* ebgp-requires-policy (inbound) */
9404 if (p->bgp->ebgp_requires_policy == DEFAULT_EBGP_POLICY_ENABLED
9405 && !bgp_inbound_policy_exists(p, filter))
9406 vty_out(vty,
9407 " Inbound updates discarded due to missing policy\n");
9408
9409 /* ebgp-requires-policy (outbound) */
9410 if (p->bgp->ebgp_requires_policy == DEFAULT_EBGP_POLICY_ENABLED
9411 && !bgp_outbound_policy_exists(p, filter))
9412 vty_out(vty,
9413 " Outbound updates discarded due to missing policy\n");
9414
9415 /* unsuppress-map */
9416 if (filter->usmap.name)
9417 vty_out(vty,
9418 " Route map for selective unsuppress is %s%s\n",
9419 filter->usmap.map ? "*" : "",
9420 filter->usmap.name);
9421
9422 /* Receive prefix count */
9423 vty_out(vty, " %" PRIu32 " accepted prefixes\n",
9424 p->pcount[afi][safi]);
9425
9426 /* Maximum prefix */
9427 if (CHECK_FLAG(p->af_flags[afi][safi], PEER_FLAG_MAX_PREFIX)) {
9428 vty_out(vty,
9429 " Maximum prefixes allowed %" PRIu32 "%s\n",
9430 p->pmax[afi][safi],
9431 CHECK_FLAG(p->af_flags[afi][safi],
9432 PEER_FLAG_MAX_PREFIX_WARNING)
9433 ? " (warning-only)"
9434 : "");
9435 vty_out(vty, " Threshold for warning message %d%%",
9436 p->pmax_threshold[afi][safi]);
9437 if (p->pmax_restart[afi][safi])
9438 vty_out(vty, ", restart interval %d min",
9439 p->pmax_restart[afi][safi]);
9440 vty_out(vty, "\n");
9441 }
9442
9443 vty_out(vty, "\n");
9444 }
9445 }
9446
9447 static void bgp_show_peer(struct vty *vty, struct peer *p, bool use_json,
9448 json_object *json)
9449 {
9450 struct bgp *bgp;
9451 char buf1[PREFIX2STR_BUFFER], buf[SU_ADDRSTRLEN];
9452 char timebuf[BGP_UPTIME_LEN];
9453 char dn_flag[2];
9454 afi_t afi;
9455 safi_t safi;
9456 uint16_t i;
9457 uint8_t *msg;
9458 json_object *json_neigh = NULL;
9459 time_t epoch_tbuf;
9460
9461 bgp = p->bgp;
9462
9463 if (use_json)
9464 json_neigh = json_object_new_object();
9465
9466 memset(dn_flag, '\0', sizeof(dn_flag));
9467 if (!p->conf_if && peer_dynamic_neighbor(p))
9468 dn_flag[0] = '*';
9469
9470 if (!use_json) {
9471 if (p->conf_if) /* Configured interface name. */
9472 vty_out(vty, "BGP neighbor on %s: %s, ", p->conf_if,
9473 BGP_PEER_SU_UNSPEC(p)
9474 ? "None"
9475 : sockunion2str(&p->su, buf,
9476 SU_ADDRSTRLEN));
9477 else /* Configured IP address. */
9478 vty_out(vty, "BGP neighbor is %s%s, ", dn_flag,
9479 p->host);
9480 }
9481
9482 if (use_json) {
9483 if (p->conf_if && BGP_PEER_SU_UNSPEC(p))
9484 json_object_string_add(json_neigh, "bgpNeighborAddr",
9485 "none");
9486 else if (p->conf_if && !BGP_PEER_SU_UNSPEC(p))
9487 json_object_string_add(
9488 json_neigh, "bgpNeighborAddr",
9489 sockunion2str(&p->su, buf, SU_ADDRSTRLEN));
9490
9491 json_object_int_add(json_neigh, "remoteAs", p->as);
9492
9493 if (p->change_local_as)
9494 json_object_int_add(json_neigh, "localAs",
9495 p->change_local_as);
9496 else
9497 json_object_int_add(json_neigh, "localAs", p->local_as);
9498
9499 if (CHECK_FLAG(p->flags, PEER_FLAG_LOCAL_AS_NO_PREPEND))
9500 json_object_boolean_true_add(json_neigh,
9501 "localAsNoPrepend");
9502
9503 if (CHECK_FLAG(p->flags, PEER_FLAG_LOCAL_AS_REPLACE_AS))
9504 json_object_boolean_true_add(json_neigh,
9505 "localAsReplaceAs");
9506 } else {
9507 if ((p->as_type == AS_SPECIFIED) || (p->as_type == AS_EXTERNAL)
9508 || (p->as_type == AS_INTERNAL))
9509 vty_out(vty, "remote AS %u, ", p->as);
9510 else
9511 vty_out(vty, "remote AS Unspecified, ");
9512 vty_out(vty, "local AS %u%s%s, ",
9513 p->change_local_as ? p->change_local_as : p->local_as,
9514 CHECK_FLAG(p->flags, PEER_FLAG_LOCAL_AS_NO_PREPEND)
9515 ? " no-prepend"
9516 : "",
9517 CHECK_FLAG(p->flags, PEER_FLAG_LOCAL_AS_REPLACE_AS)
9518 ? " replace-as"
9519 : "");
9520 }
9521 /* peer type internal or confed-internal */
9522 if ((p->as == p->local_as) || (p->as_type == AS_INTERNAL)) {
9523 if (use_json) {
9524 if (CHECK_FLAG(bgp->config, BGP_CONFIG_CONFEDERATION))
9525 json_object_boolean_true_add(
9526 json_neigh, "nbrConfedInternalLink");
9527 else
9528 json_object_boolean_true_add(json_neigh,
9529 "nbrInternalLink");
9530 } else {
9531 if (CHECK_FLAG(bgp->config, BGP_CONFIG_CONFEDERATION))
9532 vty_out(vty, "confed-internal link\n");
9533 else
9534 vty_out(vty, "internal link\n");
9535 }
9536 /* peer type external or confed-external */
9537 } else if (p->as || (p->as_type == AS_EXTERNAL)) {
9538 if (use_json) {
9539 if (CHECK_FLAG(bgp->config, BGP_CONFIG_CONFEDERATION))
9540 json_object_boolean_true_add(
9541 json_neigh, "nbrConfedExternalLink");
9542 else
9543 json_object_boolean_true_add(json_neigh,
9544 "nbrExternalLink");
9545 } else {
9546 if (bgp_confederation_peers_check(bgp, p->as))
9547 vty_out(vty, "confed-external link\n");
9548 else
9549 vty_out(vty, "external link\n");
9550 }
9551 } else {
9552 if (use_json)
9553 json_object_boolean_true_add(json_neigh,
9554 "nbrUnspecifiedLink");
9555 else
9556 vty_out(vty, "unspecified link\n");
9557 }
9558
9559 /* Description. */
9560 if (p->desc) {
9561 if (use_json)
9562 json_object_string_add(json_neigh, "nbrDesc", p->desc);
9563 else
9564 vty_out(vty, " Description: %s\n", p->desc);
9565 }
9566
9567 if (p->hostname) {
9568 if (use_json) {
9569 if (p->hostname)
9570 json_object_string_add(json_neigh, "hostname",
9571 p->hostname);
9572
9573 if (p->domainname)
9574 json_object_string_add(json_neigh, "domainname",
9575 p->domainname);
9576 } else {
9577 if (p->domainname && (p->domainname[0] != '\0'))
9578 vty_out(vty, "Hostname: %s.%s\n", p->hostname,
9579 p->domainname);
9580 else
9581 vty_out(vty, "Hostname: %s\n", p->hostname);
9582 }
9583 }
9584
9585 /* Peer-group */
9586 if (p->group) {
9587 if (use_json) {
9588 json_object_string_add(json_neigh, "peerGroup",
9589 p->group->name);
9590
9591 if (dn_flag[0]) {
9592 struct prefix prefix, *range = NULL;
9593
9594 sockunion2hostprefix(&(p->su), &prefix);
9595 range = peer_group_lookup_dynamic_neighbor_range(
9596 p->group, &prefix);
9597
9598 if (range) {
9599 prefix2str(range, buf1, sizeof(buf1));
9600 json_object_string_add(
9601 json_neigh,
9602 "peerSubnetRangeGroup", buf1);
9603 }
9604 }
9605 } else {
9606 vty_out(vty,
9607 " Member of peer-group %s for session parameters\n",
9608 p->group->name);
9609
9610 if (dn_flag[0]) {
9611 struct prefix prefix, *range = NULL;
9612
9613 sockunion2hostprefix(&(p->su), &prefix);
9614 range = peer_group_lookup_dynamic_neighbor_range(
9615 p->group, &prefix);
9616
9617 if (range) {
9618 prefix2str(range, buf1, sizeof(buf1));
9619 vty_out(vty,
9620 " Belongs to the subnet range group: %s\n",
9621 buf1);
9622 }
9623 }
9624 }
9625 }
9626
9627 if (use_json) {
9628 /* Administrative shutdown. */
9629 if (CHECK_FLAG(p->flags, PEER_FLAG_SHUTDOWN))
9630 json_object_boolean_true_add(json_neigh,
9631 "adminShutDown");
9632
9633 /* BGP Version. */
9634 json_object_int_add(json_neigh, "bgpVersion", 4);
9635 json_object_string_add(
9636 json_neigh, "remoteRouterId",
9637 inet_ntop(AF_INET, &p->remote_id, buf1, sizeof(buf1)));
9638 json_object_string_add(
9639 json_neigh, "localRouterId",
9640 inet_ntop(AF_INET, &bgp->router_id, buf1,
9641 sizeof(buf1)));
9642
9643 /* Confederation */
9644 if (CHECK_FLAG(bgp->config, BGP_CONFIG_CONFEDERATION)
9645 && bgp_confederation_peers_check(bgp, p->as))
9646 json_object_boolean_true_add(json_neigh,
9647 "nbrCommonAdmin");
9648
9649 /* Status. */
9650 json_object_string_add(
9651 json_neigh, "bgpState",
9652 lookup_msg(bgp_status_msg, p->status, NULL));
9653
9654 if (p->status == Established) {
9655 time_t uptime;
9656
9657 uptime = bgp_clock();
9658 uptime -= p->uptime;
9659 epoch_tbuf = time(NULL) - uptime;
9660
9661 #if CONFDATE > 20200101
9662 CPP_NOTICE(
9663 "bgpTimerUp should be deprecated and can be removed now");
9664 #endif
9665 /*
9666 * bgpTimerUp was miliseconds that was accurate
9667 * up to 1 day, then the value returned
9668 * became garbage. So in order to provide
9669 * some level of backwards compatability,
9670 * we still provde the data, but now
9671 * we are returning the correct value
9672 * and also adding a new bgpTimerUpMsec
9673 * which will allow us to deprecate
9674 * this eventually
9675 */
9676 json_object_int_add(json_neigh, "bgpTimerUp",
9677 uptime * 1000);
9678 json_object_int_add(json_neigh, "bgpTimerUpMsec",
9679 uptime * 1000);
9680 json_object_string_add(json_neigh, "bgpTimerUpString",
9681 peer_uptime(p->uptime, timebuf,
9682 BGP_UPTIME_LEN, 0,
9683 NULL));
9684 json_object_int_add(json_neigh,
9685 "bgpTimerUpEstablishedEpoch",
9686 epoch_tbuf);
9687 }
9688
9689 else if (p->status == Active) {
9690 if (CHECK_FLAG(p->flags, PEER_FLAG_PASSIVE))
9691 json_object_string_add(json_neigh, "bgpStateIs",
9692 "passive");
9693 else if (CHECK_FLAG(p->sflags, PEER_STATUS_NSF_WAIT))
9694 json_object_string_add(json_neigh, "bgpStateIs",
9695 "passiveNSF");
9696 }
9697
9698 /* read timer */
9699 time_t uptime;
9700 struct tm *tm;
9701
9702 uptime = bgp_clock();
9703 uptime -= p->readtime;
9704 tm = gmtime(&uptime);
9705 json_object_int_add(json_neigh, "bgpTimerLastRead",
9706 (tm->tm_sec * 1000) + (tm->tm_min * 60000)
9707 + (tm->tm_hour * 3600000));
9708
9709 uptime = bgp_clock();
9710 uptime -= p->last_write;
9711 tm = gmtime(&uptime);
9712 json_object_int_add(json_neigh, "bgpTimerLastWrite",
9713 (tm->tm_sec * 1000) + (tm->tm_min * 60000)
9714 + (tm->tm_hour * 3600000));
9715
9716 uptime = bgp_clock();
9717 uptime -= p->update_time;
9718 tm = gmtime(&uptime);
9719 json_object_int_add(json_neigh, "bgpInUpdateElapsedTimeMsecs",
9720 (tm->tm_sec * 1000) + (tm->tm_min * 60000)
9721 + (tm->tm_hour * 3600000));
9722
9723 /* Configured timer values. */
9724 json_object_int_add(json_neigh, "bgpTimerHoldTimeMsecs",
9725 p->v_holdtime * 1000);
9726 json_object_int_add(json_neigh,
9727 "bgpTimerKeepAliveIntervalMsecs",
9728 p->v_keepalive * 1000);
9729 if (CHECK_FLAG(p->flags, PEER_FLAG_TIMER)) {
9730 json_object_int_add(json_neigh,
9731 "bgpTimerConfiguredHoldTimeMsecs",
9732 p->holdtime * 1000);
9733 json_object_int_add(
9734 json_neigh,
9735 "bgpTimerConfiguredKeepAliveIntervalMsecs",
9736 p->keepalive * 1000);
9737 } else if ((bgp->default_holdtime != BGP_DEFAULT_HOLDTIME)
9738 || (bgp->default_keepalive
9739 != BGP_DEFAULT_KEEPALIVE)) {
9740 json_object_int_add(json_neigh,
9741 "bgpTimerConfiguredHoldTimeMsecs",
9742 bgp->default_holdtime);
9743 json_object_int_add(
9744 json_neigh,
9745 "bgpTimerConfiguredKeepAliveIntervalMsecs",
9746 bgp->default_keepalive);
9747 }
9748 } else {
9749 /* Administrative shutdown. */
9750 if (CHECK_FLAG(p->flags, PEER_FLAG_SHUTDOWN))
9751 vty_out(vty, " Administratively shut down\n");
9752
9753 /* BGP Version. */
9754 vty_out(vty, " BGP version 4");
9755 vty_out(vty, ", remote router ID %s",
9756 inet_ntop(AF_INET, &p->remote_id, buf1, sizeof(buf1)));
9757 vty_out(vty, ", local router ID %s\n",
9758 inet_ntop(AF_INET, &bgp->router_id, buf1,
9759 sizeof(buf1)));
9760
9761 /* Confederation */
9762 if (CHECK_FLAG(bgp->config, BGP_CONFIG_CONFEDERATION)
9763 && bgp_confederation_peers_check(bgp, p->as))
9764 vty_out(vty,
9765 " Neighbor under common administration\n");
9766
9767 /* Status. */
9768 vty_out(vty, " BGP state = %s",
9769 lookup_msg(bgp_status_msg, p->status, NULL));
9770
9771 if (p->status == Established)
9772 vty_out(vty, ", up for %8s",
9773 peer_uptime(p->uptime, timebuf, BGP_UPTIME_LEN,
9774 0, NULL));
9775
9776 else if (p->status == Active) {
9777 if (CHECK_FLAG(p->flags, PEER_FLAG_PASSIVE))
9778 vty_out(vty, " (passive)");
9779 else if (CHECK_FLAG(p->sflags, PEER_STATUS_NSF_WAIT))
9780 vty_out(vty, " (NSF passive)");
9781 }
9782 vty_out(vty, "\n");
9783
9784 /* read timer */
9785 vty_out(vty, " Last read %s",
9786 peer_uptime(p->readtime, timebuf, BGP_UPTIME_LEN, 0,
9787 NULL));
9788 vty_out(vty, ", Last write %s\n",
9789 peer_uptime(p->last_write, timebuf, BGP_UPTIME_LEN, 0,
9790 NULL));
9791
9792 /* Configured timer values. */
9793 vty_out(vty,
9794 " Hold time is %d, keepalive interval is %d seconds\n",
9795 p->v_holdtime, p->v_keepalive);
9796 if (CHECK_FLAG(p->flags, PEER_FLAG_TIMER)) {
9797 vty_out(vty, " Configured hold time is %d",
9798 p->holdtime);
9799 vty_out(vty, ", keepalive interval is %d seconds\n",
9800 p->keepalive);
9801 } else if ((bgp->default_holdtime != BGP_DEFAULT_HOLDTIME)
9802 || (bgp->default_keepalive
9803 != BGP_DEFAULT_KEEPALIVE)) {
9804 vty_out(vty, " Configured hold time is %d",
9805 bgp->default_holdtime);
9806 vty_out(vty, ", keepalive interval is %d seconds\n",
9807 bgp->default_keepalive);
9808 }
9809 }
9810 /* Capability. */
9811 if (p->status == Established) {
9812 if (p->cap || p->afc_adv[AFI_IP][SAFI_UNICAST]
9813 || p->afc_recv[AFI_IP][SAFI_UNICAST]
9814 || p->afc_adv[AFI_IP][SAFI_MULTICAST]
9815 || p->afc_recv[AFI_IP][SAFI_MULTICAST]
9816 || p->afc_adv[AFI_IP6][SAFI_UNICAST]
9817 || p->afc_recv[AFI_IP6][SAFI_UNICAST]
9818 || p->afc_adv[AFI_IP6][SAFI_MULTICAST]
9819 || p->afc_recv[AFI_IP6][SAFI_MULTICAST]
9820 || p->afc_adv[AFI_IP6][SAFI_MPLS_VPN]
9821 || p->afc_recv[AFI_IP6][SAFI_MPLS_VPN]
9822 || p->afc_adv[AFI_IP6][SAFI_ENCAP]
9823 || p->afc_recv[AFI_IP6][SAFI_ENCAP]
9824 || p->afc_adv[AFI_IP6][SAFI_FLOWSPEC]
9825 || p->afc_recv[AFI_IP6][SAFI_FLOWSPEC]
9826 || p->afc_adv[AFI_IP][SAFI_ENCAP]
9827 || p->afc_recv[AFI_IP][SAFI_ENCAP]
9828 || p->afc_adv[AFI_IP][SAFI_FLOWSPEC]
9829 || p->afc_recv[AFI_IP][SAFI_FLOWSPEC]
9830 || p->afc_adv[AFI_IP][SAFI_MPLS_VPN]
9831 || p->afc_recv[AFI_IP][SAFI_MPLS_VPN]) {
9832 if (use_json) {
9833 json_object *json_cap = NULL;
9834
9835 json_cap = json_object_new_object();
9836
9837 /* AS4 */
9838 if (CHECK_FLAG(p->cap, PEER_CAP_AS4_RCV)
9839 || CHECK_FLAG(p->cap, PEER_CAP_AS4_ADV)) {
9840 if (CHECK_FLAG(p->cap, PEER_CAP_AS4_ADV)
9841 && CHECK_FLAG(p->cap,
9842 PEER_CAP_AS4_RCV))
9843 json_object_string_add(
9844 json_cap, "4byteAs",
9845 "advertisedAndReceived");
9846 else if (CHECK_FLAG(p->cap,
9847 PEER_CAP_AS4_ADV))
9848 json_object_string_add(
9849 json_cap, "4byteAs",
9850 "advertised");
9851 else if (CHECK_FLAG(p->cap,
9852 PEER_CAP_AS4_RCV))
9853 json_object_string_add(
9854 json_cap, "4byteAs",
9855 "received");
9856 }
9857
9858 /* AddPath */
9859 if (CHECK_FLAG(p->cap, PEER_CAP_ADDPATH_RCV)
9860 || CHECK_FLAG(p->cap,
9861 PEER_CAP_ADDPATH_ADV)) {
9862 json_object *json_add = NULL;
9863 const char *print_store;
9864
9865 json_add = json_object_new_object();
9866
9867 FOREACH_AFI_SAFI (afi, safi) {
9868 json_object *json_sub = NULL;
9869 json_sub =
9870 json_object_new_object();
9871 print_store = get_afi_safi_str(
9872 afi, safi, true);
9873
9874 if (CHECK_FLAG(
9875 p->af_cap[afi]
9876 [safi],
9877 PEER_CAP_ADDPATH_AF_TX_ADV)
9878 || CHECK_FLAG(
9879 p->af_cap[afi]
9880 [safi],
9881 PEER_CAP_ADDPATH_AF_TX_RCV)) {
9882 if (CHECK_FLAG(
9883 p->af_cap
9884 [afi]
9885 [safi],
9886 PEER_CAP_ADDPATH_AF_TX_ADV)
9887 && CHECK_FLAG(
9888 p->af_cap
9889 [afi]
9890 [safi],
9891 PEER_CAP_ADDPATH_AF_TX_RCV))
9892 json_object_boolean_true_add(
9893 json_sub,
9894 "txAdvertisedAndReceived");
9895 else if (
9896 CHECK_FLAG(
9897 p->af_cap
9898 [afi]
9899 [safi],
9900 PEER_CAP_ADDPATH_AF_TX_ADV))
9901 json_object_boolean_true_add(
9902 json_sub,
9903 "txAdvertised");
9904 else if (
9905 CHECK_FLAG(
9906 p->af_cap
9907 [afi]
9908 [safi],
9909 PEER_CAP_ADDPATH_AF_TX_RCV))
9910 json_object_boolean_true_add(
9911 json_sub,
9912 "txReceived");
9913 }
9914
9915 if (CHECK_FLAG(
9916 p->af_cap[afi]
9917 [safi],
9918 PEER_CAP_ADDPATH_AF_RX_ADV)
9919 || CHECK_FLAG(
9920 p->af_cap[afi]
9921 [safi],
9922 PEER_CAP_ADDPATH_AF_RX_RCV)) {
9923 if (CHECK_FLAG(
9924 p->af_cap
9925 [afi]
9926 [safi],
9927 PEER_CAP_ADDPATH_AF_RX_ADV)
9928 && CHECK_FLAG(
9929 p->af_cap
9930 [afi]
9931 [safi],
9932 PEER_CAP_ADDPATH_AF_RX_RCV))
9933 json_object_boolean_true_add(
9934 json_sub,
9935 "rxAdvertisedAndReceived");
9936 else if (
9937 CHECK_FLAG(
9938 p->af_cap
9939 [afi]
9940 [safi],
9941 PEER_CAP_ADDPATH_AF_RX_ADV))
9942 json_object_boolean_true_add(
9943 json_sub,
9944 "rxAdvertised");
9945 else if (
9946 CHECK_FLAG(
9947 p->af_cap
9948 [afi]
9949 [safi],
9950 PEER_CAP_ADDPATH_AF_RX_RCV))
9951 json_object_boolean_true_add(
9952 json_sub,
9953 "rxReceived");
9954 }
9955
9956 if (CHECK_FLAG(
9957 p->af_cap[afi]
9958 [safi],
9959 PEER_CAP_ADDPATH_AF_TX_ADV)
9960 || CHECK_FLAG(
9961 p->af_cap[afi]
9962 [safi],
9963 PEER_CAP_ADDPATH_AF_TX_RCV)
9964 || CHECK_FLAG(
9965 p->af_cap[afi]
9966 [safi],
9967 PEER_CAP_ADDPATH_AF_RX_ADV)
9968 || CHECK_FLAG(
9969 p->af_cap[afi]
9970 [safi],
9971 PEER_CAP_ADDPATH_AF_RX_RCV))
9972 json_object_object_add(
9973 json_add,
9974 print_store,
9975 json_sub);
9976 else
9977 json_object_free(
9978 json_sub);
9979 }
9980
9981 json_object_object_add(
9982 json_cap, "addPath", json_add);
9983 }
9984
9985 /* Dynamic */
9986 if (CHECK_FLAG(p->cap, PEER_CAP_DYNAMIC_RCV)
9987 || CHECK_FLAG(p->cap,
9988 PEER_CAP_DYNAMIC_ADV)) {
9989 if (CHECK_FLAG(p->cap,
9990 PEER_CAP_DYNAMIC_ADV)
9991 && CHECK_FLAG(p->cap,
9992 PEER_CAP_DYNAMIC_RCV))
9993 json_object_string_add(
9994 json_cap, "dynamic",
9995 "advertisedAndReceived");
9996 else if (CHECK_FLAG(
9997 p->cap,
9998 PEER_CAP_DYNAMIC_ADV))
9999 json_object_string_add(
10000 json_cap, "dynamic",
10001 "advertised");
10002 else if (CHECK_FLAG(
10003 p->cap,
10004 PEER_CAP_DYNAMIC_RCV))
10005 json_object_string_add(
10006 json_cap, "dynamic",
10007 "received");
10008 }
10009
10010 /* Extended nexthop */
10011 if (CHECK_FLAG(p->cap, PEER_CAP_ENHE_RCV)
10012 || CHECK_FLAG(p->cap, PEER_CAP_ENHE_ADV)) {
10013 json_object *json_nxt = NULL;
10014 const char *print_store;
10015
10016
10017 if (CHECK_FLAG(p->cap,
10018 PEER_CAP_ENHE_ADV)
10019 && CHECK_FLAG(p->cap,
10020 PEER_CAP_ENHE_RCV))
10021 json_object_string_add(
10022 json_cap,
10023 "extendedNexthop",
10024 "advertisedAndReceived");
10025 else if (CHECK_FLAG(p->cap,
10026 PEER_CAP_ENHE_ADV))
10027 json_object_string_add(
10028 json_cap,
10029 "extendedNexthop",
10030 "advertised");
10031 else if (CHECK_FLAG(p->cap,
10032 PEER_CAP_ENHE_RCV))
10033 json_object_string_add(
10034 json_cap,
10035 "extendedNexthop",
10036 "received");
10037
10038 if (CHECK_FLAG(p->cap,
10039 PEER_CAP_ENHE_RCV)) {
10040 json_nxt =
10041 json_object_new_object();
10042
10043 for (safi = SAFI_UNICAST;
10044 safi < SAFI_MAX; safi++) {
10045 if (CHECK_FLAG(
10046 p->af_cap
10047 [AFI_IP]
10048 [safi],
10049 PEER_CAP_ENHE_AF_RCV)) {
10050 print_store = get_afi_safi_str(
10051 AFI_IP,
10052 safi, true);
10053 json_object_string_add(
10054 json_nxt,
10055 print_store,
10056 "recieved"); /* misspelled for compatibility */
10057 }
10058 }
10059 json_object_object_add(
10060 json_cap,
10061 "extendedNexthopFamililesByPeer",
10062 json_nxt);
10063 }
10064 }
10065
10066 /* Route Refresh */
10067 if (CHECK_FLAG(p->cap, PEER_CAP_REFRESH_ADV)
10068 || CHECK_FLAG(p->cap,
10069 PEER_CAP_REFRESH_NEW_RCV)
10070 || CHECK_FLAG(p->cap,
10071 PEER_CAP_REFRESH_OLD_RCV)) {
10072 if (CHECK_FLAG(p->cap,
10073 PEER_CAP_REFRESH_ADV)
10074 && (CHECK_FLAG(
10075 p->cap,
10076 PEER_CAP_REFRESH_NEW_RCV)
10077 || CHECK_FLAG(
10078 p->cap,
10079 PEER_CAP_REFRESH_OLD_RCV))) {
10080 if (CHECK_FLAG(
10081 p->cap,
10082 PEER_CAP_REFRESH_OLD_RCV)
10083 && CHECK_FLAG(
10084 p->cap,
10085 PEER_CAP_REFRESH_NEW_RCV))
10086 json_object_string_add(
10087 json_cap,
10088 "routeRefresh",
10089 "advertisedAndReceivedOldNew");
10090 else {
10091 if (CHECK_FLAG(
10092 p->cap,
10093 PEER_CAP_REFRESH_OLD_RCV))
10094 json_object_string_add(
10095 json_cap,
10096 "routeRefresh",
10097 "advertisedAndReceivedOld");
10098 else
10099 json_object_string_add(
10100 json_cap,
10101 "routeRefresh",
10102 "advertisedAndReceivedNew");
10103 }
10104 } else if (
10105 CHECK_FLAG(
10106 p->cap,
10107 PEER_CAP_REFRESH_ADV))
10108 json_object_string_add(
10109 json_cap,
10110 "routeRefresh",
10111 "advertised");
10112 else if (
10113 CHECK_FLAG(
10114 p->cap,
10115 PEER_CAP_REFRESH_NEW_RCV)
10116 || CHECK_FLAG(
10117 p->cap,
10118 PEER_CAP_REFRESH_OLD_RCV))
10119 json_object_string_add(
10120 json_cap,
10121 "routeRefresh",
10122 "received");
10123 }
10124
10125 /* Multiprotocol Extensions */
10126 json_object *json_multi = NULL;
10127 json_multi = json_object_new_object();
10128
10129 FOREACH_AFI_SAFI (afi, safi) {
10130 if (p->afc_adv[afi][safi]
10131 || p->afc_recv[afi][safi]) {
10132 json_object *json_exten = NULL;
10133 json_exten =
10134 json_object_new_object();
10135
10136 if (p->afc_adv[afi][safi]
10137 && p->afc_recv[afi][safi])
10138 json_object_boolean_true_add(
10139 json_exten,
10140 "advertisedAndReceived");
10141 else if (p->afc_adv[afi][safi])
10142 json_object_boolean_true_add(
10143 json_exten,
10144 "advertised");
10145 else if (p->afc_recv[afi][safi])
10146 json_object_boolean_true_add(
10147 json_exten,
10148 "received");
10149
10150 json_object_object_add(
10151 json_multi,
10152 get_afi_safi_str(afi,
10153 safi,
10154 true),
10155 json_exten);
10156 }
10157 }
10158 json_object_object_add(
10159 json_cap, "multiprotocolExtensions",
10160 json_multi);
10161
10162 /* Hostname capabilities */
10163 json_object *json_hname = NULL;
10164
10165 json_hname = json_object_new_object();
10166
10167 if (CHECK_FLAG(p->cap, PEER_CAP_HOSTNAME_ADV)) {
10168 json_object_string_add(
10169 json_hname, "advHostName",
10170 bgp->peer_self->hostname
10171 ? bgp->peer_self
10172 ->hostname
10173 : "n/a");
10174 json_object_string_add(
10175 json_hname, "advDomainName",
10176 bgp->peer_self->domainname
10177 ? bgp->peer_self
10178 ->domainname
10179 : "n/a");
10180 }
10181
10182
10183 if (CHECK_FLAG(p->cap, PEER_CAP_HOSTNAME_RCV)) {
10184 json_object_string_add(
10185 json_hname, "rcvHostName",
10186 p->hostname ? p->hostname
10187 : "n/a");
10188 json_object_string_add(
10189 json_hname, "rcvDomainName",
10190 p->domainname ? p->domainname
10191 : "n/a");
10192 }
10193
10194 json_object_object_add(json_cap, "hostName",
10195 json_hname);
10196
10197 /* Gracefull Restart */
10198 if (CHECK_FLAG(p->cap, PEER_CAP_RESTART_RCV)
10199 || CHECK_FLAG(p->cap,
10200 PEER_CAP_RESTART_ADV)) {
10201 if (CHECK_FLAG(p->cap,
10202 PEER_CAP_RESTART_ADV)
10203 && CHECK_FLAG(p->cap,
10204 PEER_CAP_RESTART_RCV))
10205 json_object_string_add(
10206 json_cap,
10207 "gracefulRestart",
10208 "advertisedAndReceived");
10209 else if (CHECK_FLAG(
10210 p->cap,
10211 PEER_CAP_RESTART_ADV))
10212 json_object_string_add(
10213 json_cap,
10214 "gracefulRestartCapability",
10215 "advertised");
10216 else if (CHECK_FLAG(
10217 p->cap,
10218 PEER_CAP_RESTART_RCV))
10219 json_object_string_add(
10220 json_cap,
10221 "gracefulRestartCapability",
10222 "received");
10223
10224 if (CHECK_FLAG(p->cap,
10225 PEER_CAP_RESTART_RCV)) {
10226 int restart_af_count = 0;
10227 json_object *json_restart =
10228 NULL;
10229 json_restart =
10230 json_object_new_object();
10231
10232 json_object_int_add(
10233 json_cap,
10234 "gracefulRestartRemoteTimerMsecs",
10235 p->v_gr_restart * 1000);
10236
10237 FOREACH_AFI_SAFI (afi, safi) {
10238 if (CHECK_FLAG(
10239 p->af_cap
10240 [afi]
10241 [safi],
10242 PEER_CAP_RESTART_AF_RCV)) {
10243 json_object *
10244 json_sub =
10245 NULL;
10246 json_sub =
10247 json_object_new_object();
10248
10249 if (CHECK_FLAG(
10250 p->af_cap
10251 [afi]
10252 [safi],
10253 PEER_CAP_RESTART_AF_PRESERVE_RCV))
10254 json_object_boolean_true_add(
10255 json_sub,
10256 "preserved");
10257 restart_af_count++;
10258 json_object_object_add(
10259 json_restart,
10260 get_afi_safi_str(
10261 afi,
10262 safi,
10263 true),
10264 json_sub);
10265 }
10266 }
10267 if (!restart_af_count) {
10268 json_object_string_add(
10269 json_cap,
10270 "addressFamiliesByPeer",
10271 "none");
10272 json_object_free(
10273 json_restart);
10274 } else
10275 json_object_object_add(
10276 json_cap,
10277 "addressFamiliesByPeer",
10278 json_restart);
10279 }
10280 }
10281 json_object_object_add(json_neigh,
10282 "neighborCapabilities",
10283 json_cap);
10284 } else {
10285 vty_out(vty, " Neighbor capabilities:\n");
10286
10287 /* AS4 */
10288 if (CHECK_FLAG(p->cap, PEER_CAP_AS4_RCV)
10289 || CHECK_FLAG(p->cap, PEER_CAP_AS4_ADV)) {
10290 vty_out(vty, " 4 Byte AS:");
10291 if (CHECK_FLAG(p->cap,
10292 PEER_CAP_AS4_ADV))
10293 vty_out(vty, " advertised");
10294 if (CHECK_FLAG(p->cap,
10295 PEER_CAP_AS4_RCV))
10296 vty_out(vty, " %sreceived",
10297 CHECK_FLAG(
10298 p->cap,
10299 PEER_CAP_AS4_ADV)
10300 ? "and "
10301 : "");
10302 vty_out(vty, "\n");
10303 }
10304
10305 /* AddPath */
10306 if (CHECK_FLAG(p->cap, PEER_CAP_ADDPATH_RCV)
10307 || CHECK_FLAG(p->cap,
10308 PEER_CAP_ADDPATH_ADV)) {
10309 vty_out(vty, " AddPath:\n");
10310
10311 FOREACH_AFI_SAFI (afi, safi) {
10312 if (CHECK_FLAG(
10313 p->af_cap[afi]
10314 [safi],
10315 PEER_CAP_ADDPATH_AF_TX_ADV)
10316 || CHECK_FLAG(
10317 p->af_cap[afi]
10318 [safi],
10319 PEER_CAP_ADDPATH_AF_TX_RCV)) {
10320 vty_out(vty,
10321 " %s: TX ",
10322 get_afi_safi_str(
10323 afi,
10324 safi,
10325 false));
10326
10327 if (CHECK_FLAG(
10328 p->af_cap
10329 [afi]
10330 [safi],
10331 PEER_CAP_ADDPATH_AF_TX_ADV))
10332 vty_out(vty,
10333 "advertised %s",
10334 get_afi_safi_str(
10335 afi,
10336 safi,
10337 false));
10338
10339 if (CHECK_FLAG(
10340 p->af_cap
10341 [afi]
10342 [safi],
10343 PEER_CAP_ADDPATH_AF_TX_RCV))
10344 vty_out(vty,
10345 "%sreceived",
10346 CHECK_FLAG(
10347 p->af_cap
10348 [afi]
10349 [safi],
10350 PEER_CAP_ADDPATH_AF_TX_ADV)
10351 ? " and "
10352 : "");
10353
10354 vty_out(vty, "\n");
10355 }
10356
10357 if (CHECK_FLAG(
10358 p->af_cap[afi]
10359 [safi],
10360 PEER_CAP_ADDPATH_AF_RX_ADV)
10361 || CHECK_FLAG(
10362 p->af_cap[afi]
10363 [safi],
10364 PEER_CAP_ADDPATH_AF_RX_RCV)) {
10365 vty_out(vty,
10366 " %s: RX ",
10367 get_afi_safi_str(
10368 afi,
10369 safi,
10370 false));
10371
10372 if (CHECK_FLAG(
10373 p->af_cap
10374 [afi]
10375 [safi],
10376 PEER_CAP_ADDPATH_AF_RX_ADV))
10377 vty_out(vty,
10378 "advertised %s",
10379 get_afi_safi_str(
10380 afi,
10381 safi,
10382 false));
10383
10384 if (CHECK_FLAG(
10385 p->af_cap
10386 [afi]
10387 [safi],
10388 PEER_CAP_ADDPATH_AF_RX_RCV))
10389 vty_out(vty,
10390 "%sreceived",
10391 CHECK_FLAG(
10392 p->af_cap
10393 [afi]
10394 [safi],
10395 PEER_CAP_ADDPATH_AF_RX_ADV)
10396 ? " and "
10397 : "");
10398
10399 vty_out(vty, "\n");
10400 }
10401 }
10402 }
10403
10404 /* Dynamic */
10405 if (CHECK_FLAG(p->cap, PEER_CAP_DYNAMIC_RCV)
10406 || CHECK_FLAG(p->cap,
10407 PEER_CAP_DYNAMIC_ADV)) {
10408 vty_out(vty, " Dynamic:");
10409 if (CHECK_FLAG(p->cap,
10410 PEER_CAP_DYNAMIC_ADV))
10411 vty_out(vty, " advertised");
10412 if (CHECK_FLAG(p->cap,
10413 PEER_CAP_DYNAMIC_RCV))
10414 vty_out(vty, " %sreceived",
10415 CHECK_FLAG(
10416 p->cap,
10417 PEER_CAP_DYNAMIC_ADV)
10418 ? "and "
10419 : "");
10420 vty_out(vty, "\n");
10421 }
10422
10423 /* Extended nexthop */
10424 if (CHECK_FLAG(p->cap, PEER_CAP_ENHE_RCV)
10425 || CHECK_FLAG(p->cap, PEER_CAP_ENHE_ADV)) {
10426 vty_out(vty, " Extended nexthop:");
10427 if (CHECK_FLAG(p->cap,
10428 PEER_CAP_ENHE_ADV))
10429 vty_out(vty, " advertised");
10430 if (CHECK_FLAG(p->cap,
10431 PEER_CAP_ENHE_RCV))
10432 vty_out(vty, " %sreceived",
10433 CHECK_FLAG(
10434 p->cap,
10435 PEER_CAP_ENHE_ADV)
10436 ? "and "
10437 : "");
10438 vty_out(vty, "\n");
10439
10440 if (CHECK_FLAG(p->cap,
10441 PEER_CAP_ENHE_RCV)) {
10442 vty_out(vty,
10443 " Address families by peer:\n ");
10444 for (safi = SAFI_UNICAST;
10445 safi < SAFI_MAX; safi++)
10446 if (CHECK_FLAG(
10447 p->af_cap
10448 [AFI_IP]
10449 [safi],
10450 PEER_CAP_ENHE_AF_RCV))
10451 vty_out(vty,
10452 " %s\n",
10453 get_afi_safi_str(
10454 AFI_IP,
10455 safi,
10456 false));
10457 }
10458 }
10459
10460 /* Route Refresh */
10461 if (CHECK_FLAG(p->cap, PEER_CAP_REFRESH_ADV)
10462 || CHECK_FLAG(p->cap,
10463 PEER_CAP_REFRESH_NEW_RCV)
10464 || CHECK_FLAG(p->cap,
10465 PEER_CAP_REFRESH_OLD_RCV)) {
10466 vty_out(vty, " Route refresh:");
10467 if (CHECK_FLAG(p->cap,
10468 PEER_CAP_REFRESH_ADV))
10469 vty_out(vty, " advertised");
10470 if (CHECK_FLAG(p->cap,
10471 PEER_CAP_REFRESH_NEW_RCV)
10472 || CHECK_FLAG(
10473 p->cap,
10474 PEER_CAP_REFRESH_OLD_RCV))
10475 vty_out(vty, " %sreceived(%s)",
10476 CHECK_FLAG(
10477 p->cap,
10478 PEER_CAP_REFRESH_ADV)
10479 ? "and "
10480 : "",
10481 (CHECK_FLAG(
10482 p->cap,
10483 PEER_CAP_REFRESH_OLD_RCV)
10484 && CHECK_FLAG(
10485 p->cap,
10486 PEER_CAP_REFRESH_NEW_RCV))
10487 ? "old & new"
10488 : CHECK_FLAG(
10489 p->cap,
10490 PEER_CAP_REFRESH_OLD_RCV)
10491 ? "old"
10492 : "new");
10493
10494 vty_out(vty, "\n");
10495 }
10496
10497 /* Multiprotocol Extensions */
10498 FOREACH_AFI_SAFI (afi, safi)
10499 if (p->afc_adv[afi][safi]
10500 || p->afc_recv[afi][safi]) {
10501 vty_out(vty,
10502 " Address Family %s:",
10503 get_afi_safi_str(
10504 afi,
10505 safi,
10506 false));
10507 if (p->afc_adv[afi][safi])
10508 vty_out(vty,
10509 " advertised");
10510 if (p->afc_recv[afi][safi])
10511 vty_out(vty,
10512 " %sreceived",
10513 p->afc_adv[afi]
10514 [safi]
10515 ? "and "
10516 : "");
10517 vty_out(vty, "\n");
10518 }
10519
10520 /* Hostname capability */
10521 vty_out(vty, " Hostname Capability:");
10522
10523 if (CHECK_FLAG(p->cap, PEER_CAP_HOSTNAME_ADV)) {
10524 vty_out(vty,
10525 " advertised (name: %s,domain name: %s)",
10526 bgp->peer_self->hostname
10527 ? bgp->peer_self
10528 ->hostname
10529 : "n/a",
10530 bgp->peer_self->domainname
10531 ? bgp->peer_self
10532 ->domainname
10533 : "n/a");
10534 } else {
10535 vty_out(vty, " not advertised");
10536 }
10537
10538 if (CHECK_FLAG(p->cap, PEER_CAP_HOSTNAME_RCV)) {
10539 vty_out(vty,
10540 " received (name: %s,domain name: %s)",
10541 p->hostname ? p->hostname
10542 : "n/a",
10543 p->domainname ? p->domainname
10544 : "n/a");
10545 } else {
10546 vty_out(vty, " not received");
10547 }
10548
10549 vty_out(vty, "\n");
10550
10551 /* Gracefull Restart */
10552 if (CHECK_FLAG(p->cap, PEER_CAP_RESTART_RCV)
10553 || CHECK_FLAG(p->cap,
10554 PEER_CAP_RESTART_ADV)) {
10555 vty_out(vty,
10556 " Graceful Restart Capabilty:");
10557 if (CHECK_FLAG(p->cap,
10558 PEER_CAP_RESTART_ADV))
10559 vty_out(vty, " advertised");
10560 if (CHECK_FLAG(p->cap,
10561 PEER_CAP_RESTART_RCV))
10562 vty_out(vty, " %sreceived",
10563 CHECK_FLAG(
10564 p->cap,
10565 PEER_CAP_RESTART_ADV)
10566 ? "and "
10567 : "");
10568 vty_out(vty, "\n");
10569
10570 if (CHECK_FLAG(p->cap,
10571 PEER_CAP_RESTART_RCV)) {
10572 int restart_af_count = 0;
10573
10574 vty_out(vty,
10575 " Remote Restart timer is %d seconds\n",
10576 p->v_gr_restart);
10577 vty_out(vty,
10578 " Address families by peer:\n ");
10579
10580 FOREACH_AFI_SAFI (afi, safi)
10581 if (CHECK_FLAG(
10582 p->af_cap
10583 [afi]
10584 [safi],
10585 PEER_CAP_RESTART_AF_RCV)) {
10586 vty_out(vty,
10587 "%s%s(%s)",
10588 restart_af_count
10589 ? ", "
10590 : "",
10591 get_afi_safi_str(
10592 afi,
10593 safi,
10594 false),
10595 CHECK_FLAG(
10596 p->af_cap
10597 [afi]
10598 [safi],
10599 PEER_CAP_RESTART_AF_PRESERVE_RCV)
10600 ? "preserved"
10601 : "not preserved");
10602 restart_af_count++;
10603 }
10604 if (!restart_af_count)
10605 vty_out(vty, "none");
10606 vty_out(vty, "\n");
10607 }
10608 }
10609 }
10610 }
10611 }
10612
10613 /* graceful restart information */
10614 if (CHECK_FLAG(p->cap, PEER_CAP_RESTART_RCV) || p->t_gr_restart
10615 || p->t_gr_stale) {
10616 json_object *json_grace = NULL;
10617 json_object *json_grace_send = NULL;
10618 json_object *json_grace_recv = NULL;
10619 int eor_send_af_count = 0;
10620 int eor_receive_af_count = 0;
10621
10622 if (use_json) {
10623 json_grace = json_object_new_object();
10624 json_grace_send = json_object_new_object();
10625 json_grace_recv = json_object_new_object();
10626
10627 if (p->status == Established) {
10628 FOREACH_AFI_SAFI (afi, safi) {
10629 if (CHECK_FLAG(p->af_sflags[afi][safi],
10630 PEER_STATUS_EOR_SEND)) {
10631 json_object_boolean_true_add(
10632 json_grace_send,
10633 get_afi_safi_str(afi,
10634 safi,
10635 true));
10636 eor_send_af_count++;
10637 }
10638 }
10639 FOREACH_AFI_SAFI (afi, safi) {
10640 if (CHECK_FLAG(
10641 p->af_sflags[afi][safi],
10642 PEER_STATUS_EOR_RECEIVED)) {
10643 json_object_boolean_true_add(
10644 json_grace_recv,
10645 get_afi_safi_str(afi,
10646 safi,
10647 true));
10648 eor_receive_af_count++;
10649 }
10650 }
10651 }
10652
10653 json_object_object_add(json_grace, "endOfRibSend",
10654 json_grace_send);
10655 json_object_object_add(json_grace, "endOfRibRecv",
10656 json_grace_recv);
10657
10658 if (p->t_gr_restart)
10659 json_object_int_add(json_grace,
10660 "gracefulRestartTimerMsecs",
10661 thread_timer_remain_second(
10662 p->t_gr_restart)
10663 * 1000);
10664
10665 if (p->t_gr_stale)
10666 json_object_int_add(
10667 json_grace,
10668 "gracefulStalepathTimerMsecs",
10669 thread_timer_remain_second(
10670 p->t_gr_stale)
10671 * 1000);
10672
10673 json_object_object_add(
10674 json_neigh, "gracefulRestartInfo", json_grace);
10675 } else {
10676 vty_out(vty, " Graceful restart information:\n");
10677 if (p->status == Established) {
10678 vty_out(vty, " End-of-RIB send: ");
10679 FOREACH_AFI_SAFI (afi, safi) {
10680 if (CHECK_FLAG(p->af_sflags[afi][safi],
10681 PEER_STATUS_EOR_SEND)) {
10682 vty_out(vty, "%s%s",
10683 eor_send_af_count ? ", "
10684 : "",
10685 get_afi_safi_str(afi,
10686 safi,
10687 false));
10688 eor_send_af_count++;
10689 }
10690 }
10691 vty_out(vty, "\n");
10692 vty_out(vty, " End-of-RIB received: ");
10693 FOREACH_AFI_SAFI (afi, safi) {
10694 if (CHECK_FLAG(
10695 p->af_sflags[afi][safi],
10696 PEER_STATUS_EOR_RECEIVED)) {
10697 vty_out(vty, "%s%s",
10698 eor_receive_af_count
10699 ? ", "
10700 : "",
10701 get_afi_safi_str(afi,
10702 safi,
10703 false));
10704 eor_receive_af_count++;
10705 }
10706 }
10707 vty_out(vty, "\n");
10708 }
10709
10710 if (p->t_gr_restart)
10711 vty_out(vty,
10712 " The remaining time of restart timer is %ld\n",
10713 thread_timer_remain_second(
10714 p->t_gr_restart));
10715
10716 if (p->t_gr_stale)
10717 vty_out(vty,
10718 " The remaining time of stalepath timer is %ld\n",
10719 thread_timer_remain_second(
10720 p->t_gr_stale));
10721 }
10722 }
10723 if (use_json) {
10724 json_object *json_stat = NULL;
10725 json_stat = json_object_new_object();
10726 /* Packet counts. */
10727 json_object_int_add(json_stat, "depthInq", 0);
10728 json_object_int_add(json_stat, "depthOutq",
10729 (unsigned long)p->obuf->count);
10730 json_object_int_add(json_stat, "opensSent",
10731 atomic_load_explicit(&p->open_out,
10732 memory_order_relaxed));
10733 json_object_int_add(json_stat, "opensRecv",
10734 atomic_load_explicit(&p->open_in,
10735 memory_order_relaxed));
10736 json_object_int_add(json_stat, "notificationsSent",
10737 atomic_load_explicit(&p->notify_out,
10738 memory_order_relaxed));
10739 json_object_int_add(json_stat, "notificationsRecv",
10740 atomic_load_explicit(&p->notify_in,
10741 memory_order_relaxed));
10742 json_object_int_add(json_stat, "updatesSent",
10743 atomic_load_explicit(&p->update_out,
10744 memory_order_relaxed));
10745 json_object_int_add(json_stat, "updatesRecv",
10746 atomic_load_explicit(&p->update_in,
10747 memory_order_relaxed));
10748 json_object_int_add(json_stat, "keepalivesSent",
10749 atomic_load_explicit(&p->keepalive_out,
10750 memory_order_relaxed));
10751 json_object_int_add(json_stat, "keepalivesRecv",
10752 atomic_load_explicit(&p->keepalive_in,
10753 memory_order_relaxed));
10754 json_object_int_add(json_stat, "routeRefreshSent",
10755 atomic_load_explicit(&p->refresh_out,
10756 memory_order_relaxed));
10757 json_object_int_add(json_stat, "routeRefreshRecv",
10758 atomic_load_explicit(&p->refresh_in,
10759 memory_order_relaxed));
10760 json_object_int_add(json_stat, "capabilitySent",
10761 atomic_load_explicit(&p->dynamic_cap_out,
10762 memory_order_relaxed));
10763 json_object_int_add(json_stat, "capabilityRecv",
10764 atomic_load_explicit(&p->dynamic_cap_in,
10765 memory_order_relaxed));
10766 json_object_int_add(json_stat, "totalSent", PEER_TOTAL_TX(p));
10767 json_object_int_add(json_stat, "totalRecv", PEER_TOTAL_RX(p));
10768 json_object_object_add(json_neigh, "messageStats", json_stat);
10769 } else {
10770 /* Packet counts. */
10771 vty_out(vty, " Message statistics:\n");
10772 vty_out(vty, " Inq depth is 0\n");
10773 vty_out(vty, " Outq depth is %lu\n",
10774 (unsigned long)p->obuf->count);
10775 vty_out(vty, " Sent Rcvd\n");
10776 vty_out(vty, " Opens: %10d %10d\n",
10777 atomic_load_explicit(&p->open_out,
10778 memory_order_relaxed),
10779 atomic_load_explicit(&p->open_in,
10780 memory_order_relaxed));
10781 vty_out(vty, " Notifications: %10d %10d\n",
10782 atomic_load_explicit(&p->notify_out,
10783 memory_order_relaxed),
10784 atomic_load_explicit(&p->notify_in,
10785 memory_order_relaxed));
10786 vty_out(vty, " Updates: %10d %10d\n",
10787 atomic_load_explicit(&p->update_out,
10788 memory_order_relaxed),
10789 atomic_load_explicit(&p->update_in,
10790 memory_order_relaxed));
10791 vty_out(vty, " Keepalives: %10d %10d\n",
10792 atomic_load_explicit(&p->keepalive_out,
10793 memory_order_relaxed),
10794 atomic_load_explicit(&p->keepalive_in,
10795 memory_order_relaxed));
10796 vty_out(vty, " Route Refresh: %10d %10d\n",
10797 atomic_load_explicit(&p->refresh_out,
10798 memory_order_relaxed),
10799 atomic_load_explicit(&p->refresh_in,
10800 memory_order_relaxed));
10801 vty_out(vty, " Capability: %10d %10d\n",
10802 atomic_load_explicit(&p->dynamic_cap_out,
10803 memory_order_relaxed),
10804 atomic_load_explicit(&p->dynamic_cap_in,
10805 memory_order_relaxed));
10806 vty_out(vty, " Total: %10d %10d\n", PEER_TOTAL_TX(p),
10807 PEER_TOTAL_RX(p));
10808 }
10809
10810 if (use_json) {
10811 /* advertisement-interval */
10812 json_object_int_add(json_neigh,
10813 "minBtwnAdvertisementRunsTimerMsecs",
10814 p->v_routeadv * 1000);
10815
10816 /* Update-source. */
10817 if (p->update_if || p->update_source) {
10818 if (p->update_if)
10819 json_object_string_add(json_neigh,
10820 "updateSource",
10821 p->update_if);
10822 else if (p->update_source)
10823 json_object_string_add(
10824 json_neigh, "updateSource",
10825 sockunion2str(p->update_source, buf1,
10826 SU_ADDRSTRLEN));
10827 }
10828 } else {
10829 /* advertisement-interval */
10830 vty_out(vty,
10831 " Minimum time between advertisement runs is %d seconds\n",
10832 p->v_routeadv);
10833
10834 /* Update-source. */
10835 if (p->update_if || p->update_source) {
10836 vty_out(vty, " Update source is ");
10837 if (p->update_if)
10838 vty_out(vty, "%s", p->update_if);
10839 else if (p->update_source)
10840 vty_out(vty, "%s",
10841 sockunion2str(p->update_source, buf1,
10842 SU_ADDRSTRLEN));
10843 vty_out(vty, "\n");
10844 }
10845
10846 vty_out(vty, "\n");
10847 }
10848
10849 /* Address Family Information */
10850 json_object *json_hold = NULL;
10851
10852 if (use_json)
10853 json_hold = json_object_new_object();
10854
10855 FOREACH_AFI_SAFI (afi, safi)
10856 if (p->afc[afi][safi])
10857 bgp_show_peer_afi(vty, p, afi, safi, use_json,
10858 json_hold);
10859
10860 if (use_json) {
10861 json_object_object_add(json_neigh, "addressFamilyInfo",
10862 json_hold);
10863 json_object_int_add(json_neigh, "connectionsEstablished",
10864 p->established);
10865 json_object_int_add(json_neigh, "connectionsDropped",
10866 p->dropped);
10867 } else
10868 vty_out(vty, " Connections established %d; dropped %d\n",
10869 p->established, p->dropped);
10870
10871 if (!p->last_reset) {
10872 if (use_json)
10873 json_object_string_add(json_neigh, "lastReset",
10874 "never");
10875 else
10876 vty_out(vty, " Last reset never\n");
10877 } else {
10878 if (use_json) {
10879 time_t uptime;
10880 struct tm *tm;
10881
10882 uptime = bgp_clock();
10883 uptime -= p->resettime;
10884 tm = gmtime(&uptime);
10885 json_object_int_add(json_neigh, "lastResetTimerMsecs",
10886 (tm->tm_sec * 1000)
10887 + (tm->tm_min * 60000)
10888 + (tm->tm_hour * 3600000));
10889 bgp_show_peer_reset(NULL, p, json_neigh, true);
10890 } else {
10891 vty_out(vty, " Last reset %s, ",
10892 peer_uptime(p->resettime, timebuf,
10893 BGP_UPTIME_LEN, 0, NULL));
10894
10895 bgp_show_peer_reset(vty, p, NULL, false);
10896 if (p->last_reset_cause_size) {
10897 msg = p->last_reset_cause;
10898 vty_out(vty,
10899 " Message received that caused BGP to send a NOTIFICATION:\n ");
10900 for (i = 1; i <= p->last_reset_cause_size;
10901 i++) {
10902 vty_out(vty, "%02X", *msg++);
10903
10904 if (i != p->last_reset_cause_size) {
10905 if (i % 16 == 0) {
10906 vty_out(vty, "\n ");
10907 } else if (i % 4 == 0) {
10908 vty_out(vty, " ");
10909 }
10910 }
10911 }
10912 vty_out(vty, "\n");
10913 }
10914 }
10915 }
10916
10917 if (CHECK_FLAG(p->sflags, PEER_STATUS_PREFIX_OVERFLOW)) {
10918 if (use_json)
10919 json_object_boolean_true_add(json_neigh,
10920 "prefixesConfigExceedMax");
10921 else
10922 vty_out(vty,
10923 " Peer had exceeded the max. no. of prefixes configured.\n");
10924
10925 if (p->t_pmax_restart) {
10926 if (use_json) {
10927 json_object_boolean_true_add(
10928 json_neigh, "reducePrefixNumFrom");
10929 json_object_int_add(json_neigh,
10930 "restartInTimerMsec",
10931 thread_timer_remain_second(
10932 p->t_pmax_restart)
10933 * 1000);
10934 } else
10935 vty_out(vty,
10936 " Reduce the no. of prefix from %s, will restart in %ld seconds\n",
10937 p->host, thread_timer_remain_second(
10938 p->t_pmax_restart));
10939 } else {
10940 if (use_json)
10941 json_object_boolean_true_add(
10942 json_neigh,
10943 "reducePrefixNumAndClearIpBgp");
10944 else
10945 vty_out(vty,
10946 " Reduce the no. of prefix and clear ip bgp %s to restore peering\n",
10947 p->host);
10948 }
10949 }
10950
10951 /* EBGP Multihop and GTSM */
10952 if (p->sort != BGP_PEER_IBGP) {
10953 if (use_json) {
10954 if (p->gtsm_hops > 0)
10955 json_object_int_add(json_neigh,
10956 "externalBgpNbrMaxHopsAway",
10957 p->gtsm_hops);
10958 else if (p->ttl > BGP_DEFAULT_TTL)
10959 json_object_int_add(json_neigh,
10960 "externalBgpNbrMaxHopsAway",
10961 p->ttl);
10962 } else {
10963 if (p->gtsm_hops > 0)
10964 vty_out(vty,
10965 " External BGP neighbor may be up to %d hops away.\n",
10966 p->gtsm_hops);
10967 else if (p->ttl > BGP_DEFAULT_TTL)
10968 vty_out(vty,
10969 " External BGP neighbor may be up to %d hops away.\n",
10970 p->ttl);
10971 }
10972 } else {
10973 if (p->gtsm_hops > 0) {
10974 if (use_json)
10975 json_object_int_add(json_neigh,
10976 "internalBgpNbrMaxHopsAway",
10977 p->gtsm_hops);
10978 else
10979 vty_out(vty,
10980 " Internal BGP neighbor may be up to %d hops away.\n",
10981 p->gtsm_hops);
10982 }
10983 }
10984
10985 /* Local address. */
10986 if (p->su_local) {
10987 if (use_json) {
10988 json_object_string_add(json_neigh, "hostLocal",
10989 sockunion2str(p->su_local, buf1,
10990 SU_ADDRSTRLEN));
10991 json_object_int_add(json_neigh, "portLocal",
10992 ntohs(p->su_local->sin.sin_port));
10993 } else
10994 vty_out(vty, "Local host: %s, Local port: %d\n",
10995 sockunion2str(p->su_local, buf1, SU_ADDRSTRLEN),
10996 ntohs(p->su_local->sin.sin_port));
10997 }
10998
10999 /* Remote address. */
11000 if (p->su_remote) {
11001 if (use_json) {
11002 json_object_string_add(json_neigh, "hostForeign",
11003 sockunion2str(p->su_remote, buf1,
11004 SU_ADDRSTRLEN));
11005 json_object_int_add(json_neigh, "portForeign",
11006 ntohs(p->su_remote->sin.sin_port));
11007 } else
11008 vty_out(vty, "Foreign host: %s, Foreign port: %d\n",
11009 sockunion2str(p->su_remote, buf1,
11010 SU_ADDRSTRLEN),
11011 ntohs(p->su_remote->sin.sin_port));
11012 }
11013
11014 /* Nexthop display. */
11015 if (p->su_local) {
11016 if (use_json) {
11017 json_object_string_add(json_neigh, "nexthop",
11018 inet_ntop(AF_INET,
11019 &p->nexthop.v4, buf1,
11020 sizeof(buf1)));
11021 json_object_string_add(json_neigh, "nexthopGlobal",
11022 inet_ntop(AF_INET6,
11023 &p->nexthop.v6_global,
11024 buf1, sizeof(buf1)));
11025 json_object_string_add(json_neigh, "nexthopLocal",
11026 inet_ntop(AF_INET6,
11027 &p->nexthop.v6_local,
11028 buf1, sizeof(buf1)));
11029 if (p->shared_network)
11030 json_object_string_add(json_neigh,
11031 "bgpConnection",
11032 "sharedNetwork");
11033 else
11034 json_object_string_add(json_neigh,
11035 "bgpConnection",
11036 "nonSharedNetwork");
11037 } else {
11038 vty_out(vty, "Nexthop: %s\n",
11039 inet_ntop(AF_INET, &p->nexthop.v4, buf1,
11040 sizeof(buf1)));
11041 vty_out(vty, "Nexthop global: %s\n",
11042 inet_ntop(AF_INET6, &p->nexthop.v6_global, buf1,
11043 sizeof(buf1)));
11044 vty_out(vty, "Nexthop local: %s\n",
11045 inet_ntop(AF_INET6, &p->nexthop.v6_local, buf1,
11046 sizeof(buf1)));
11047 vty_out(vty, "BGP connection: %s\n",
11048 p->shared_network ? "shared network"
11049 : "non shared network");
11050 }
11051 }
11052
11053 /* Timer information. */
11054 if (use_json) {
11055 json_object_int_add(json_neigh, "connectRetryTimer",
11056 p->v_connect);
11057 if (p->status == Established && p->rtt)
11058 json_object_int_add(json_neigh, "estimatedRttInMsecs",
11059 p->rtt);
11060 if (p->t_start)
11061 json_object_int_add(
11062 json_neigh, "nextStartTimerDueInMsecs",
11063 thread_timer_remain_second(p->t_start) * 1000);
11064 if (p->t_connect)
11065 json_object_int_add(
11066 json_neigh, "nextConnectTimerDueInMsecs",
11067 thread_timer_remain_second(p->t_connect)
11068 * 1000);
11069 if (p->t_routeadv) {
11070 json_object_int_add(json_neigh, "mraiInterval",
11071 p->v_routeadv);
11072 json_object_int_add(
11073 json_neigh, "mraiTimerExpireInMsecs",
11074 thread_timer_remain_second(p->t_routeadv)
11075 * 1000);
11076 }
11077 if (p->password)
11078 json_object_int_add(json_neigh, "authenticationEnabled",
11079 1);
11080
11081 if (p->t_read)
11082 json_object_string_add(json_neigh, "readThread", "on");
11083 else
11084 json_object_string_add(json_neigh, "readThread", "off");
11085
11086 if (CHECK_FLAG(p->thread_flags, PEER_THREAD_WRITES_ON))
11087 json_object_string_add(json_neigh, "writeThread", "on");
11088 else
11089 json_object_string_add(json_neigh, "writeThread",
11090 "off");
11091 } else {
11092 vty_out(vty, "BGP Connect Retry Timer in Seconds: %d\n",
11093 p->v_connect);
11094 if (p->status == Established && p->rtt)
11095 vty_out(vty, "Estimated round trip time: %d ms\n",
11096 p->rtt);
11097 if (p->t_start)
11098 vty_out(vty, "Next start timer due in %ld seconds\n",
11099 thread_timer_remain_second(p->t_start));
11100 if (p->t_connect)
11101 vty_out(vty, "Next connect timer due in %ld seconds\n",
11102 thread_timer_remain_second(p->t_connect));
11103 if (p->t_routeadv)
11104 vty_out(vty,
11105 "MRAI (interval %u) timer expires in %ld seconds\n",
11106 p->v_routeadv,
11107 thread_timer_remain_second(p->t_routeadv));
11108 if (p->password)
11109 vty_out(vty, "Peer Authentication Enabled\n");
11110
11111 vty_out(vty, "Read thread: %s Write thread: %s FD used: %d\n",
11112 p->t_read ? "on" : "off",
11113 CHECK_FLAG(p->thread_flags, PEER_THREAD_WRITES_ON)
11114 ? "on"
11115 : "off", p->fd);
11116 }
11117
11118 if (p->notify.code == BGP_NOTIFY_OPEN_ERR
11119 && p->notify.subcode == BGP_NOTIFY_OPEN_UNSUP_CAPBL)
11120 bgp_capability_vty_out(vty, p, use_json, json_neigh);
11121
11122 if (!use_json)
11123 vty_out(vty, "\n");
11124
11125 /* BFD information. */
11126 bgp_bfd_show_info(vty, p, use_json, json_neigh);
11127
11128 if (use_json) {
11129 if (p->conf_if) /* Configured interface name. */
11130 json_object_object_add(json, p->conf_if, json_neigh);
11131 else /* Configured IP address. */
11132 json_object_object_add(json, p->host, json_neigh);
11133 }
11134 }
11135
11136 static int bgp_show_neighbor(struct vty *vty, struct bgp *bgp,
11137 enum show_type type, union sockunion *su,
11138 const char *conf_if, bool use_json,
11139 json_object *json)
11140 {
11141 struct listnode *node, *nnode;
11142 struct peer *peer;
11143 int find = 0;
11144 bool nbr_output = false;
11145 afi_t afi = AFI_MAX;
11146 safi_t safi = SAFI_MAX;
11147
11148 if (type == show_ipv4_peer || type == show_ipv4_all) {
11149 afi = AFI_IP;
11150 } else if (type == show_ipv6_peer || type == show_ipv6_all) {
11151 afi = AFI_IP6;
11152 }
11153
11154 for (ALL_LIST_ELEMENTS(bgp->peer, node, nnode, peer)) {
11155 if (!CHECK_FLAG(peer->flags, PEER_FLAG_CONFIG_NODE))
11156 continue;
11157
11158 switch (type) {
11159 case show_all:
11160 bgp_show_peer(vty, peer, use_json, json);
11161 nbr_output = true;
11162 break;
11163 case show_peer:
11164 if (conf_if) {
11165 if ((peer->conf_if
11166 && !strcmp(peer->conf_if, conf_if))
11167 || (peer->hostname
11168 && !strcmp(peer->hostname, conf_if))) {
11169 find = 1;
11170 bgp_show_peer(vty, peer, use_json,
11171 json);
11172 }
11173 } else {
11174 if (sockunion_same(&peer->su, su)) {
11175 find = 1;
11176 bgp_show_peer(vty, peer, use_json,
11177 json);
11178 }
11179 }
11180 break;
11181 case show_ipv4_peer:
11182 case show_ipv6_peer:
11183 FOREACH_SAFI (safi) {
11184 if (peer->afc[afi][safi]) {
11185 if (conf_if) {
11186 if ((peer->conf_if
11187 && !strcmp(peer->conf_if, conf_if))
11188 || (peer->hostname
11189 && !strcmp(peer->hostname, conf_if))) {
11190 find = 1;
11191 bgp_show_peer(vty, peer, use_json,
11192 json);
11193 break;
11194 }
11195 } else {
11196 if (sockunion_same(&peer->su, su)) {
11197 find = 1;
11198 bgp_show_peer(vty, peer, use_json,
11199 json);
11200 break;
11201 }
11202 }
11203 }
11204 }
11205 break;
11206 case show_ipv4_all:
11207 case show_ipv6_all:
11208 FOREACH_SAFI (safi) {
11209 if (peer->afc[afi][safi]) {
11210 bgp_show_peer(vty, peer, use_json, json);
11211 nbr_output = true;
11212 break;
11213 }
11214 }
11215 break;
11216 }
11217 }
11218
11219 if ((type == show_peer || type == show_ipv4_peer ||
11220 type == show_ipv6_peer) && !find) {
11221 if (use_json)
11222 json_object_boolean_true_add(json, "bgpNoSuchNeighbor");
11223 else
11224 vty_out(vty, "%% No such neighbor in this view/vrf\n");
11225 }
11226
11227 if (type != show_peer && type != show_ipv4_peer &&
11228 type != show_ipv6_peer && !nbr_output && !use_json)
11229 vty_out(vty, "%% No BGP neighbors found\n");
11230
11231 if (use_json) {
11232 vty_out(vty, "%s\n", json_object_to_json_string_ext(
11233 json, JSON_C_TO_STRING_PRETTY));
11234 } else {
11235 vty_out(vty, "\n");
11236 }
11237
11238 return CMD_SUCCESS;
11239 }
11240
11241 static void bgp_show_all_instances_neighbors_vty(struct vty *vty,
11242 enum show_type type,
11243 const char *ip_str,
11244 bool use_json)
11245 {
11246 struct listnode *node, *nnode;
11247 struct bgp *bgp;
11248 union sockunion su;
11249 json_object *json = NULL;
11250 int ret, is_first = 1;
11251 bool nbr_output = false;
11252
11253 if (use_json)
11254 vty_out(vty, "{\n");
11255
11256 for (ALL_LIST_ELEMENTS(bm->bgp, node, nnode, bgp)) {
11257 nbr_output = true;
11258 if (use_json) {
11259 if (!(json = json_object_new_object())) {
11260 flog_err(
11261 EC_BGP_JSON_MEM_ERROR,
11262 "Unable to allocate memory for JSON object");
11263 vty_out(vty,
11264 "{\"error\": {\"message:\": \"Unable to allocate memory for JSON object\"}}}\n");
11265 return;
11266 }
11267
11268 json_object_int_add(json, "vrfId",
11269 (bgp->vrf_id == VRF_UNKNOWN)
11270 ? -1
11271 : (int64_t)bgp->vrf_id);
11272 json_object_string_add(
11273 json, "vrfName",
11274 (bgp->inst_type == BGP_INSTANCE_TYPE_DEFAULT)
11275 ? VRF_DEFAULT_NAME
11276 : bgp->name);
11277
11278 if (!is_first)
11279 vty_out(vty, ",\n");
11280 else
11281 is_first = 0;
11282
11283 vty_out(vty, "\"%s\":",
11284 (bgp->inst_type == BGP_INSTANCE_TYPE_DEFAULT)
11285 ? VRF_DEFAULT_NAME
11286 : bgp->name);
11287 } else {
11288 vty_out(vty, "\nInstance %s:\n",
11289 (bgp->inst_type == BGP_INSTANCE_TYPE_DEFAULT)
11290 ? VRF_DEFAULT_NAME
11291 : bgp->name);
11292 }
11293
11294 if (type == show_peer || type == show_ipv4_peer ||
11295 type == show_ipv6_peer) {
11296 ret = str2sockunion(ip_str, &su);
11297 if (ret < 0)
11298 bgp_show_neighbor(vty, bgp, type, NULL, ip_str,
11299 use_json, json);
11300 else
11301 bgp_show_neighbor(vty, bgp, type, &su, NULL,
11302 use_json, json);
11303 } else {
11304 bgp_show_neighbor(vty, bgp, type, NULL, NULL,
11305 use_json, json);
11306 }
11307 json_object_free(json);
11308 }
11309
11310 if (use_json) {
11311 vty_out(vty, "}\n");
11312 json_object_free(json);
11313 }
11314 else if (!nbr_output)
11315 vty_out(vty, "%% BGP instance not found\n");
11316 }
11317
11318 static int bgp_show_neighbor_vty(struct vty *vty, const char *name,
11319 enum show_type type, const char *ip_str,
11320 bool use_json)
11321 {
11322 int ret;
11323 struct bgp *bgp;
11324 union sockunion su;
11325 json_object *json = NULL;
11326
11327 if (name) {
11328 if (strmatch(name, "all")) {
11329 bgp_show_all_instances_neighbors_vty(vty, type, ip_str,
11330 use_json);
11331 return CMD_SUCCESS;
11332 } else {
11333 bgp = bgp_lookup_by_name(name);
11334 if (!bgp) {
11335 if (use_json) {
11336 json = json_object_new_object();
11337 vty_out(vty, "%s\n",
11338 json_object_to_json_string_ext(
11339 json,
11340 JSON_C_TO_STRING_PRETTY));
11341 json_object_free(json);
11342 } else
11343 vty_out(vty,
11344 "%% BGP instance not found\n");
11345
11346 return CMD_WARNING;
11347 }
11348 }
11349 } else {
11350 bgp = bgp_get_default();
11351 }
11352
11353 if (bgp) {
11354 json = json_object_new_object();
11355 if (ip_str) {
11356 ret = str2sockunion(ip_str, &su);
11357 if (ret < 0)
11358 bgp_show_neighbor(vty, bgp, type, NULL, ip_str,
11359 use_json, json);
11360 else
11361 bgp_show_neighbor(vty, bgp, type, &su, NULL,
11362 use_json, json);
11363 } else {
11364 bgp_show_neighbor(vty, bgp, type, NULL, NULL, use_json,
11365 json);
11366 }
11367 json_object_free(json);
11368 } else {
11369 if (use_json)
11370 vty_out(vty, "{}\n");
11371 else
11372 vty_out(vty, "%% BGP instance not found\n");
11373 }
11374
11375 return CMD_SUCCESS;
11376 }
11377
11378 /* "show [ip] bgp neighbors" commands. */
11379 DEFUN (show_ip_bgp_neighbors,
11380 show_ip_bgp_neighbors_cmd,
11381 "show [ip] bgp [<view|vrf> VIEWVRFNAME] [<ipv4|ipv6>] neighbors [<A.B.C.D|X:X::X:X|WORD>] [json]",
11382 SHOW_STR
11383 IP_STR
11384 BGP_STR
11385 BGP_INSTANCE_HELP_STR
11386 "Address Family\n"
11387 "Address Family\n"
11388 "Detailed information on TCP and BGP neighbor connections\n"
11389 "Neighbor to display information about\n"
11390 "Neighbor to display information about\n"
11391 "Neighbor on BGP configured interface\n"
11392 JSON_STR)
11393 {
11394 char *vrf = NULL;
11395 char *sh_arg = NULL;
11396 enum show_type sh_type;
11397 afi_t afi = AFI_MAX;
11398
11399 bool uj = use_json(argc, argv);
11400
11401 int idx = 0;
11402
11403 /* [<vrf> VIEWVRFNAME] */
11404 if (argv_find(argv, argc, "vrf", &idx)) {
11405 vrf = argv[idx + 1]->arg;
11406 if (vrf && strmatch(vrf, VRF_DEFAULT_NAME))
11407 vrf = NULL;
11408 } else if (argv_find(argv, argc, "view", &idx))
11409 /* [<view> VIEWVRFNAME] */
11410 vrf = argv[idx + 1]->arg;
11411
11412 idx++;
11413
11414 if (argv_find(argv, argc, "ipv4", &idx)) {
11415 sh_type = show_ipv4_all;
11416 afi = AFI_IP;
11417 } else if (argv_find(argv, argc, "ipv6", &idx)) {
11418 sh_type = show_ipv6_all;
11419 afi = AFI_IP6;
11420 } else {
11421 sh_type = show_all;
11422 }
11423
11424 if (argv_find(argv, argc, "A.B.C.D", &idx)
11425 || argv_find(argv, argc, "X:X::X:X", &idx)
11426 || argv_find(argv, argc, "WORD", &idx)) {
11427 sh_type = show_peer;
11428 sh_arg = argv[idx]->arg;
11429 }
11430
11431 if (sh_type == show_peer && afi == AFI_IP) {
11432 sh_type = show_ipv4_peer;
11433 } else if (sh_type == show_peer && afi == AFI_IP6) {
11434 sh_type = show_ipv6_peer;
11435 }
11436
11437 return bgp_show_neighbor_vty(vty, vrf, sh_type, sh_arg, uj);
11438 }
11439
11440 /* Show BGP's AS paths internal data. There are both `show [ip] bgp
11441 paths' and `show ip mbgp paths'. Those functions results are the
11442 same.*/
11443 DEFUN (show_ip_bgp_paths,
11444 show_ip_bgp_paths_cmd,
11445 "show [ip] bgp ["BGP_SAFI_CMD_STR"] paths",
11446 SHOW_STR
11447 IP_STR
11448 BGP_STR
11449 BGP_SAFI_HELP_STR
11450 "Path information\n")
11451 {
11452 vty_out(vty, "Address Refcnt Path\n");
11453 aspath_print_all_vty(vty);
11454 return CMD_SUCCESS;
11455 }
11456
11457 #include "hash.h"
11458
11459 static void community_show_all_iterator(struct hash_bucket *bucket,
11460 struct vty *vty)
11461 {
11462 struct community *com;
11463
11464 com = (struct community *)bucket->data;
11465 vty_out(vty, "[%p] (%ld) %s\n", (void *)com, com->refcnt,
11466 community_str(com, false));
11467 }
11468
11469 /* Show BGP's community internal data. */
11470 DEFUN (show_ip_bgp_community_info,
11471 show_ip_bgp_community_info_cmd,
11472 "show [ip] bgp community-info",
11473 SHOW_STR
11474 IP_STR
11475 BGP_STR
11476 "List all bgp community information\n")
11477 {
11478 vty_out(vty, "Address Refcnt Community\n");
11479
11480 hash_iterate(community_hash(),
11481 (void (*)(struct hash_bucket *,
11482 void *))community_show_all_iterator,
11483 vty);
11484
11485 return CMD_SUCCESS;
11486 }
11487
11488 static void lcommunity_show_all_iterator(struct hash_bucket *bucket,
11489 struct vty *vty)
11490 {
11491 struct lcommunity *lcom;
11492
11493 lcom = (struct lcommunity *)bucket->data;
11494 vty_out(vty, "[%p] (%ld) %s\n", (void *)lcom, lcom->refcnt,
11495 lcommunity_str(lcom, false));
11496 }
11497
11498 /* Show BGP's community internal data. */
11499 DEFUN (show_ip_bgp_lcommunity_info,
11500 show_ip_bgp_lcommunity_info_cmd,
11501 "show ip bgp large-community-info",
11502 SHOW_STR
11503 IP_STR
11504 BGP_STR
11505 "List all bgp large-community information\n")
11506 {
11507 vty_out(vty, "Address Refcnt Large-community\n");
11508
11509 hash_iterate(lcommunity_hash(),
11510 (void (*)(struct hash_bucket *,
11511 void *))lcommunity_show_all_iterator,
11512 vty);
11513
11514 return CMD_SUCCESS;
11515 }
11516
11517
11518 DEFUN (show_ip_bgp_attr_info,
11519 show_ip_bgp_attr_info_cmd,
11520 "show [ip] bgp attribute-info",
11521 SHOW_STR
11522 IP_STR
11523 BGP_STR
11524 "List all bgp attribute information\n")
11525 {
11526 attr_show_all(vty);
11527 return CMD_SUCCESS;
11528 }
11529
11530 static int bgp_show_route_leak_vty(struct vty *vty, const char *name,
11531 afi_t afi, safi_t safi,
11532 bool use_json, json_object *json)
11533 {
11534 struct bgp *bgp;
11535 struct listnode *node;
11536 char *vname;
11537 char buf1[INET6_ADDRSTRLEN];
11538 char *ecom_str;
11539 vpn_policy_direction_t dir;
11540
11541 if (json) {
11542 json_object *json_import_vrfs = NULL;
11543 json_object *json_export_vrfs = NULL;
11544
11545 bgp = name ? bgp_lookup_by_name(name) : bgp_get_default();
11546
11547 if (!bgp) {
11548 vty_out(vty, "%s\n",
11549 json_object_to_json_string_ext(
11550 json,
11551 JSON_C_TO_STRING_PRETTY));
11552 json_object_free(json);
11553
11554 return CMD_WARNING;
11555 }
11556
11557 /* Provide context for the block */
11558 json_object_string_add(json, "vrf", name ? name : "default");
11559 json_object_string_add(json, "afiSafi",
11560 get_afi_safi_str(afi, safi, true));
11561
11562 if (!CHECK_FLAG(bgp->af_flags[afi][safi],
11563 BGP_CONFIG_VRF_TO_VRF_IMPORT)) {
11564 json_object_string_add(json, "importFromVrfs", "none");
11565 json_object_string_add(json, "importRts", "none");
11566 } else {
11567 json_import_vrfs = json_object_new_array();
11568
11569 for (ALL_LIST_ELEMENTS_RO(
11570 bgp->vpn_policy[afi].import_vrf,
11571 node, vname))
11572 json_object_array_add(json_import_vrfs,
11573 json_object_new_string(vname));
11574
11575 json_object_object_add(json, "importFromVrfs",
11576 json_import_vrfs);
11577 dir = BGP_VPN_POLICY_DIR_FROMVPN;
11578 if (bgp->vpn_policy[afi].rtlist[dir]) {
11579 ecom_str = ecommunity_ecom2str(
11580 bgp->vpn_policy[afi].rtlist[dir],
11581 ECOMMUNITY_FORMAT_ROUTE_MAP, 0);
11582 json_object_string_add(json, "importRts",
11583 ecom_str);
11584 XFREE(MTYPE_ECOMMUNITY_STR, ecom_str);
11585 } else
11586 json_object_string_add(json, "importRts",
11587 "none");
11588 }
11589
11590 if (!CHECK_FLAG(bgp->af_flags[afi][safi],
11591 BGP_CONFIG_VRF_TO_VRF_EXPORT)) {
11592 json_object_string_add(json, "exportToVrfs", "none");
11593 json_object_string_add(json, "routeDistinguisher",
11594 "none");
11595 json_object_string_add(json, "exportRts", "none");
11596 } else {
11597 json_export_vrfs = json_object_new_array();
11598
11599 for (ALL_LIST_ELEMENTS_RO(
11600 bgp->vpn_policy[afi].export_vrf,
11601 node, vname))
11602 json_object_array_add(json_export_vrfs,
11603 json_object_new_string(vname));
11604 json_object_object_add(json, "exportToVrfs",
11605 json_export_vrfs);
11606 json_object_string_add(json, "routeDistinguisher",
11607 prefix_rd2str(&bgp->vpn_policy[afi].tovpn_rd,
11608 buf1, RD_ADDRSTRLEN));
11609
11610 dir = BGP_VPN_POLICY_DIR_TOVPN;
11611 if (bgp->vpn_policy[afi].rtlist[dir]) {
11612 ecom_str = ecommunity_ecom2str(
11613 bgp->vpn_policy[afi].rtlist[dir],
11614 ECOMMUNITY_FORMAT_ROUTE_MAP, 0);
11615 json_object_string_add(json, "exportRts",
11616 ecom_str);
11617 XFREE(MTYPE_ECOMMUNITY_STR, ecom_str);
11618 } else
11619 json_object_string_add(json, "exportRts",
11620 "none");
11621 }
11622
11623 if (use_json) {
11624 vty_out(vty, "%s\n",
11625 json_object_to_json_string_ext(json,
11626 JSON_C_TO_STRING_PRETTY));
11627 json_object_free(json);
11628 }
11629 } else {
11630 bgp = name ? bgp_lookup_by_name(name) : bgp_get_default();
11631
11632 if (!bgp) {
11633 vty_out(vty, "%% No such BGP instance exist\n");
11634 return CMD_WARNING;
11635 }
11636
11637 if (!CHECK_FLAG(bgp->af_flags[afi][safi],
11638 BGP_CONFIG_VRF_TO_VRF_IMPORT))
11639 vty_out(vty,
11640 "This VRF is not importing %s routes from any other VRF\n",
11641 get_afi_safi_str(afi, safi, false));
11642 else {
11643 vty_out(vty,
11644 "This VRF is importing %s routes from the following VRFs:\n",
11645 get_afi_safi_str(afi, safi, false));
11646
11647 for (ALL_LIST_ELEMENTS_RO(
11648 bgp->vpn_policy[afi].import_vrf,
11649 node, vname))
11650 vty_out(vty, " %s\n", vname);
11651
11652 dir = BGP_VPN_POLICY_DIR_FROMVPN;
11653 ecom_str = NULL;
11654 if (bgp->vpn_policy[afi].rtlist[dir]) {
11655 ecom_str = ecommunity_ecom2str(
11656 bgp->vpn_policy[afi].rtlist[dir],
11657 ECOMMUNITY_FORMAT_ROUTE_MAP, 0);
11658 vty_out(vty, "Import RT(s): %s\n", ecom_str);
11659
11660 XFREE(MTYPE_ECOMMUNITY_STR, ecom_str);
11661 } else
11662 vty_out(vty, "Import RT(s):\n");
11663 }
11664
11665 if (!CHECK_FLAG(bgp->af_flags[afi][safi],
11666 BGP_CONFIG_VRF_TO_VRF_EXPORT))
11667 vty_out(vty,
11668 "This VRF is not exporting %s routes to any other VRF\n",
11669 get_afi_safi_str(afi, safi, false));
11670 else {
11671 vty_out(vty,
11672 "This VRF is exporting %s routes to the following VRFs:\n",
11673 get_afi_safi_str(afi, safi, false));
11674
11675 for (ALL_LIST_ELEMENTS_RO(
11676 bgp->vpn_policy[afi].export_vrf,
11677 node, vname))
11678 vty_out(vty, " %s\n", vname);
11679
11680 vty_out(vty, "RD: %s\n",
11681 prefix_rd2str(&bgp->vpn_policy[afi].tovpn_rd,
11682 buf1, RD_ADDRSTRLEN));
11683
11684 dir = BGP_VPN_POLICY_DIR_TOVPN;
11685 if (bgp->vpn_policy[afi].rtlist[dir]) {
11686 ecom_str = ecommunity_ecom2str(
11687 bgp->vpn_policy[afi].rtlist[dir],
11688 ECOMMUNITY_FORMAT_ROUTE_MAP, 0);
11689 vty_out(vty, "Export RT: %s\n", ecom_str);
11690 XFREE(MTYPE_ECOMMUNITY_STR, ecom_str);
11691 } else
11692 vty_out(vty, "Import RT(s):\n");
11693 }
11694 }
11695
11696 return CMD_SUCCESS;
11697 }
11698
11699 static int bgp_show_all_instance_route_leak_vty(struct vty *vty, afi_t afi,
11700 safi_t safi, bool use_json)
11701 {
11702 struct listnode *node, *nnode;
11703 struct bgp *bgp;
11704 char *vrf_name = NULL;
11705 json_object *json = NULL;
11706 json_object *json_vrf = NULL;
11707 json_object *json_vrfs = NULL;
11708
11709 if (use_json) {
11710 json = json_object_new_object();
11711 json_vrfs = json_object_new_object();
11712 }
11713
11714 for (ALL_LIST_ELEMENTS(bm->bgp, node, nnode, bgp)) {
11715
11716 if (bgp->inst_type != BGP_INSTANCE_TYPE_DEFAULT)
11717 vrf_name = bgp->name;
11718
11719 if (use_json) {
11720 json_vrf = json_object_new_object();
11721 } else {
11722 vty_out(vty, "\nInstance %s:\n",
11723 (bgp->inst_type == BGP_INSTANCE_TYPE_DEFAULT)
11724 ? VRF_DEFAULT_NAME : bgp->name);
11725 }
11726 bgp_show_route_leak_vty(vty, vrf_name, afi, safi, 0, json_vrf);
11727 if (use_json) {
11728 if (bgp->inst_type == BGP_INSTANCE_TYPE_DEFAULT)
11729 json_object_object_add(json_vrfs,
11730 VRF_DEFAULT_NAME, json_vrf);
11731 else
11732 json_object_object_add(json_vrfs, vrf_name,
11733 json_vrf);
11734 }
11735 }
11736
11737 if (use_json) {
11738 json_object_object_add(json, "vrfs", json_vrfs);
11739 vty_out(vty, "%s\n", json_object_to_json_string_ext(json,
11740 JSON_C_TO_STRING_PRETTY));
11741 json_object_free(json);
11742 }
11743
11744 return CMD_SUCCESS;
11745 }
11746
11747 /* "show [ip] bgp route-leak" command. */
11748 DEFUN (show_ip_bgp_route_leak,
11749 show_ip_bgp_route_leak_cmd,
11750 "show [ip] bgp [<view|vrf> VIEWVRFNAME] ["BGP_AFI_CMD_STR" ["BGP_SAFI_CMD_STR"]] route-leak [json]",
11751 SHOW_STR
11752 IP_STR
11753 BGP_STR
11754 BGP_INSTANCE_HELP_STR
11755 BGP_AFI_HELP_STR
11756 BGP_SAFI_HELP_STR
11757 "Route leaking information\n"
11758 JSON_STR)
11759 {
11760 char *vrf = NULL;
11761 afi_t afi = AFI_MAX;
11762 safi_t safi = SAFI_MAX;
11763
11764 bool uj = use_json(argc, argv);
11765 int idx = 0;
11766 json_object *json = NULL;
11767
11768 /* show [ip] bgp */
11769 if (argv_find(argv, argc, "ip", &idx)) {
11770 afi = AFI_IP;
11771 safi = SAFI_UNICAST;
11772 }
11773 /* [vrf VIEWVRFNAME] */
11774 if (argv_find(argv, argc, "view", &idx)) {
11775 vty_out(vty,
11776 "%% This command is not applicable to BGP views\n");
11777 return CMD_WARNING;
11778 }
11779
11780 if (argv_find(argv, argc, "vrf", &idx)) {
11781 vrf = argv[idx + 1]->arg;
11782 if (vrf && strmatch(vrf, VRF_DEFAULT_NAME))
11783 vrf = NULL;
11784 }
11785 /* ["BGP_AFI_CMD_STR" ["BGP_SAFI_CMD_STR"]] */
11786 if (argv_find_and_parse_afi(argv, argc, &idx, &afi)) {
11787 argv_find_and_parse_safi(argv, argc, &idx, &safi);
11788 }
11789
11790 if (!((afi == AFI_IP || afi == AFI_IP6) && safi == SAFI_UNICAST)) {
11791 vty_out(vty,
11792 "%% This command is applicable only for unicast ipv4|ipv6\n");
11793 return CMD_WARNING;
11794 }
11795
11796 if (vrf && strmatch(vrf, "all"))
11797 return bgp_show_all_instance_route_leak_vty(vty, afi, safi, uj);
11798
11799 if (uj)
11800 json = json_object_new_object();
11801
11802 return bgp_show_route_leak_vty(vty, vrf, afi, safi, uj, json);
11803 }
11804
11805 static void bgp_show_all_instances_updgrps_vty(struct vty *vty, afi_t afi,
11806 safi_t safi)
11807 {
11808 struct listnode *node, *nnode;
11809 struct bgp *bgp;
11810
11811 for (ALL_LIST_ELEMENTS(bm->bgp, node, nnode, bgp)) {
11812 vty_out(vty, "\nInstance %s:\n",
11813 (bgp->inst_type == BGP_INSTANCE_TYPE_DEFAULT)
11814 ? VRF_DEFAULT_NAME
11815 : bgp->name);
11816 update_group_show(bgp, afi, safi, vty, 0);
11817 }
11818 }
11819
11820 static int bgp_show_update_groups(struct vty *vty, const char *name, int afi,
11821 int safi, uint64_t subgrp_id)
11822 {
11823 struct bgp *bgp;
11824
11825 if (name) {
11826 if (strmatch(name, "all")) {
11827 bgp_show_all_instances_updgrps_vty(vty, afi, safi);
11828 return CMD_SUCCESS;
11829 } else {
11830 bgp = bgp_lookup_by_name(name);
11831 }
11832 } else {
11833 bgp = bgp_get_default();
11834 }
11835
11836 if (bgp)
11837 update_group_show(bgp, afi, safi, vty, subgrp_id);
11838 return CMD_SUCCESS;
11839 }
11840
11841 DEFUN (show_ip_bgp_updgrps,
11842 show_ip_bgp_updgrps_cmd,
11843 "show [ip] bgp [<view|vrf> VIEWVRFNAME] ["BGP_AFI_CMD_STR" ["BGP_SAFI_WITH_LABEL_CMD_STR"]] update-groups [SUBGROUP-ID]",
11844 SHOW_STR
11845 IP_STR
11846 BGP_STR
11847 BGP_INSTANCE_HELP_STR
11848 BGP_AFI_HELP_STR
11849 BGP_SAFI_WITH_LABEL_HELP_STR
11850 "Detailed info about dynamic update groups\n"
11851 "Specific subgroup to display detailed info for\n")
11852 {
11853 char *vrf = NULL;
11854 afi_t afi = AFI_IP6;
11855 safi_t safi = SAFI_UNICAST;
11856 uint64_t subgrp_id = 0;
11857
11858 int idx = 0;
11859
11860 /* show [ip] bgp */
11861 if (argv_find(argv, argc, "ip", &idx))
11862 afi = AFI_IP;
11863 /* [<vrf> VIEWVRFNAME] */
11864 if (argv_find(argv, argc, "vrf", &idx)) {
11865 vrf = argv[idx + 1]->arg;
11866 if (vrf && strmatch(vrf, VRF_DEFAULT_NAME))
11867 vrf = NULL;
11868 } else if (argv_find(argv, argc, "view", &idx))
11869 /* [<view> VIEWVRFNAME] */
11870 vrf = argv[idx + 1]->arg;
11871 /* ["BGP_AFI_CMD_STR" ["BGP_SAFI_CMD_STR"]] */
11872 if (argv_find_and_parse_afi(argv, argc, &idx, &afi)) {
11873 argv_find_and_parse_safi(argv, argc, &idx, &safi);
11874 }
11875
11876 /* get subgroup id, if provided */
11877 idx = argc - 1;
11878 if (argv[idx]->type == VARIABLE_TKN)
11879 subgrp_id = strtoull(argv[idx]->arg, NULL, 10);
11880
11881 return (bgp_show_update_groups(vty, vrf, afi, safi, subgrp_id));
11882 }
11883
11884 DEFUN (show_bgp_instance_all_ipv6_updgrps,
11885 show_bgp_instance_all_ipv6_updgrps_cmd,
11886 "show [ip] bgp <view|vrf> all update-groups",
11887 SHOW_STR
11888 IP_STR
11889 BGP_STR
11890 BGP_INSTANCE_ALL_HELP_STR
11891 "Detailed info about dynamic update groups\n")
11892 {
11893 bgp_show_all_instances_updgrps_vty(vty, AFI_IP6, SAFI_UNICAST);
11894 return CMD_SUCCESS;
11895 }
11896
11897 DEFUN (show_bgp_l2vpn_evpn_updgrps,
11898 show_bgp_l2vpn_evpn_updgrps_cmd,
11899 "show [ip] bgp l2vpn evpn update-groups",
11900 SHOW_STR
11901 IP_STR
11902 BGP_STR
11903 "l2vpn address family\n"
11904 "evpn sub-address family\n"
11905 "Detailed info about dynamic update groups\n")
11906 {
11907 char *vrf = NULL;
11908 uint64_t subgrp_id = 0;
11909
11910 bgp_show_update_groups(vty, vrf, AFI_L2VPN, SAFI_EVPN, subgrp_id);
11911 return CMD_SUCCESS;
11912 }
11913
11914 DEFUN (show_bgp_updgrps_stats,
11915 show_bgp_updgrps_stats_cmd,
11916 "show [ip] bgp update-groups statistics",
11917 SHOW_STR
11918 IP_STR
11919 BGP_STR
11920 "Detailed info about dynamic update groups\n"
11921 "Statistics\n")
11922 {
11923 struct bgp *bgp;
11924
11925 bgp = bgp_get_default();
11926 if (bgp)
11927 update_group_show_stats(bgp, vty);
11928
11929 return CMD_SUCCESS;
11930 }
11931
11932 DEFUN (show_bgp_instance_updgrps_stats,
11933 show_bgp_instance_updgrps_stats_cmd,
11934 "show [ip] bgp <view|vrf> VIEWVRFNAME update-groups statistics",
11935 SHOW_STR
11936 IP_STR
11937 BGP_STR
11938 BGP_INSTANCE_HELP_STR
11939 "Detailed info about dynamic update groups\n"
11940 "Statistics\n")
11941 {
11942 int idx_word = 3;
11943 struct bgp *bgp;
11944
11945 bgp = bgp_lookup_by_name(argv[idx_word]->arg);
11946 if (bgp)
11947 update_group_show_stats(bgp, vty);
11948
11949 return CMD_SUCCESS;
11950 }
11951
11952 static void show_bgp_updgrps_adj_info_aux(struct vty *vty, const char *name,
11953 afi_t afi, safi_t safi,
11954 const char *what, uint64_t subgrp_id)
11955 {
11956 struct bgp *bgp;
11957
11958 if (name)
11959 bgp = bgp_lookup_by_name(name);
11960 else
11961 bgp = bgp_get_default();
11962
11963 if (bgp) {
11964 if (!strcmp(what, "advertise-queue"))
11965 update_group_show_adj_queue(bgp, afi, safi, vty,
11966 subgrp_id);
11967 else if (!strcmp(what, "advertised-routes"))
11968 update_group_show_advertised(bgp, afi, safi, vty,
11969 subgrp_id);
11970 else if (!strcmp(what, "packet-queue"))
11971 update_group_show_packet_queue(bgp, afi, safi, vty,
11972 subgrp_id);
11973 }
11974 }
11975
11976 DEFPY(show_ip_bgp_instance_updgrps_adj_s,
11977 show_ip_bgp_instance_updgrps_adj_s_cmd,
11978 "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",
11979 SHOW_STR IP_STR BGP_STR BGP_INSTANCE_HELP_STR BGP_AFI_HELP_STR
11980 BGP_SAFI_HELP_STR
11981 "Detailed info about dynamic update groups\n"
11982 "Specific subgroup to display info for\n"
11983 "Advertisement queue\n"
11984 "Announced routes\n"
11985 "Packet queue\n")
11986 {
11987 uint64_t subgrp_id = 0;
11988 afi_t afiz;
11989 safi_t safiz;
11990 if (sgid)
11991 subgrp_id = strtoull(sgid, NULL, 10);
11992
11993 if (!ip && !afi)
11994 afiz = AFI_IP6;
11995 if (!ip && afi)
11996 afiz = bgp_vty_afi_from_str(afi);
11997 if (ip && !afi)
11998 afiz = AFI_IP;
11999 if (ip && afi) {
12000 afiz = bgp_vty_afi_from_str(afi);
12001 if (afiz != AFI_IP)
12002 vty_out(vty,
12003 "%% Cannot specify both 'ip' and 'ipv6'\n");
12004 return CMD_WARNING;
12005 }
12006
12007 safiz = safi ? bgp_vty_safi_from_str(safi) : SAFI_UNICAST;
12008
12009 show_bgp_updgrps_adj_info_aux(vty, vrf, afiz, safiz, rtq, subgrp_id);
12010 return CMD_SUCCESS;
12011 }
12012
12013 static int bgp_show_one_peer_group(struct vty *vty, struct peer_group *group)
12014 {
12015 struct listnode *node, *nnode;
12016 struct prefix *range;
12017 struct peer *conf;
12018 struct peer *peer;
12019 char buf[PREFIX2STR_BUFFER];
12020 afi_t afi;
12021 safi_t safi;
12022 const char *peer_status;
12023 const char *af_str;
12024 int lr_count;
12025 int dynamic;
12026 int af_cfgd;
12027
12028 conf = group->conf;
12029
12030 if (conf->as_type == AS_SPECIFIED || conf->as_type == AS_EXTERNAL) {
12031 vty_out(vty, "\nBGP peer-group %s, remote AS %" PRIu32 "\n",
12032 group->name, conf->as);
12033 } else if (conf->as_type == AS_INTERNAL) {
12034 vty_out(vty, "\nBGP peer-group %s, remote AS %" PRIu32 "\n",
12035 group->name, group->bgp->as);
12036 } else {
12037 vty_out(vty, "\nBGP peer-group %s\n", group->name);
12038 }
12039
12040 if ((group->bgp->as == conf->as) || (conf->as_type == AS_INTERNAL))
12041 vty_out(vty, " Peer-group type is internal\n");
12042 else
12043 vty_out(vty, " Peer-group type is external\n");
12044
12045 /* Display AFs configured. */
12046 vty_out(vty, " Configured address-families:");
12047 FOREACH_AFI_SAFI (afi, safi) {
12048 if (conf->afc[afi][safi]) {
12049 af_cfgd = 1;
12050 vty_out(vty, " %s;", get_afi_safi_str(afi, safi, false));
12051 }
12052 }
12053 if (!af_cfgd)
12054 vty_out(vty, " none\n");
12055 else
12056 vty_out(vty, "\n");
12057
12058 /* Display listen ranges (for dynamic neighbors), if any */
12059 for (afi = AFI_IP; afi < AFI_MAX; afi++) {
12060 if (afi == AFI_IP)
12061 af_str = "IPv4";
12062 else if (afi == AFI_IP6)
12063 af_str = "IPv6";
12064 else
12065 af_str = "???";
12066 lr_count = listcount(group->listen_range[afi]);
12067 if (lr_count) {
12068 vty_out(vty, " %d %s listen range(s)\n", lr_count,
12069 af_str);
12070
12071
12072 for (ALL_LIST_ELEMENTS(group->listen_range[afi], node,
12073 nnode, range)) {
12074 prefix2str(range, buf, sizeof(buf));
12075 vty_out(vty, " %s\n", buf);
12076 }
12077 }
12078 }
12079
12080 /* Display group members and their status */
12081 if (listcount(group->peer)) {
12082 vty_out(vty, " Peer-group members:\n");
12083 for (ALL_LIST_ELEMENTS(group->peer, node, nnode, peer)) {
12084 if (CHECK_FLAG(peer->flags, PEER_FLAG_SHUTDOWN))
12085 peer_status = "Idle (Admin)";
12086 else if (CHECK_FLAG(peer->sflags,
12087 PEER_STATUS_PREFIX_OVERFLOW))
12088 peer_status = "Idle (PfxCt)";
12089 else
12090 peer_status = lookup_msg(bgp_status_msg,
12091 peer->status, NULL);
12092
12093 dynamic = peer_dynamic_neighbor(peer);
12094 vty_out(vty, " %s %s %s \n", peer->host,
12095 dynamic ? "(dynamic)" : "", peer_status);
12096 }
12097 }
12098
12099 return CMD_SUCCESS;
12100 }
12101
12102 static int bgp_show_peer_group_vty(struct vty *vty, const char *name,
12103 const char *group_name)
12104 {
12105 struct bgp *bgp;
12106 struct listnode *node, *nnode;
12107 struct peer_group *group;
12108 bool found = false;
12109
12110 bgp = name ? bgp_lookup_by_name(name) : bgp_get_default();
12111
12112 if (!bgp) {
12113 vty_out(vty, "%% BGP instance not found\n");
12114 return CMD_WARNING;
12115 }
12116
12117 for (ALL_LIST_ELEMENTS(bgp->group, node, nnode, group)) {
12118 if (group_name) {
12119 if (strmatch(group->name, group_name)) {
12120 bgp_show_one_peer_group(vty, group);
12121 found = true;
12122 break;
12123 }
12124 } else {
12125 bgp_show_one_peer_group(vty, group);
12126 }
12127 }
12128
12129 if (group_name && !found)
12130 vty_out(vty, "%% No such peer-group\n");
12131
12132 return CMD_SUCCESS;
12133 }
12134
12135 DEFUN (show_ip_bgp_peer_groups,
12136 show_ip_bgp_peer_groups_cmd,
12137 "show [ip] bgp [<view|vrf> VIEWVRFNAME] peer-group [PGNAME]",
12138 SHOW_STR
12139 IP_STR
12140 BGP_STR
12141 BGP_INSTANCE_HELP_STR
12142 "Detailed information on BGP peer groups\n"
12143 "Peer group name\n")
12144 {
12145 char *vrf, *pg;
12146 int idx = 0;
12147
12148 vrf = argv_find(argv, argc, "VIEWVRFNAME", &idx) ? argv[idx]->arg
12149 : NULL;
12150 pg = argv_find(argv, argc, "PGNAME", &idx) ? argv[idx]->arg : NULL;
12151
12152 return bgp_show_peer_group_vty(vty, vrf, pg);
12153 }
12154
12155
12156 /* Redistribute VTY commands. */
12157
12158 DEFUN (bgp_redistribute_ipv4,
12159 bgp_redistribute_ipv4_cmd,
12160 "redistribute " FRR_IP_REDIST_STR_BGPD,
12161 "Redistribute information from another routing protocol\n"
12162 FRR_IP_REDIST_HELP_STR_BGPD)
12163 {
12164 VTY_DECLVAR_CONTEXT(bgp, bgp);
12165 int idx_protocol = 1;
12166 int type;
12167
12168 type = proto_redistnum(AFI_IP, argv[idx_protocol]->text);
12169 if (type < 0) {
12170 vty_out(vty, "%% Invalid route type\n");
12171 return CMD_WARNING_CONFIG_FAILED;
12172 }
12173
12174 bgp_redist_add(bgp, AFI_IP, type, 0);
12175 return bgp_redistribute_set(bgp, AFI_IP, type, 0, false);
12176 }
12177
12178 ALIAS_HIDDEN(
12179 bgp_redistribute_ipv4, bgp_redistribute_ipv4_hidden_cmd,
12180 "redistribute " FRR_IP_REDIST_STR_BGPD,
12181 "Redistribute information from another routing protocol\n" FRR_IP_REDIST_HELP_STR_BGPD)
12182
12183 DEFUN (bgp_redistribute_ipv4_rmap,
12184 bgp_redistribute_ipv4_rmap_cmd,
12185 "redistribute " FRR_IP_REDIST_STR_BGPD " route-map WORD",
12186 "Redistribute information from another routing protocol\n"
12187 FRR_IP_REDIST_HELP_STR_BGPD
12188 "Route map reference\n"
12189 "Pointer to route-map entries\n")
12190 {
12191 VTY_DECLVAR_CONTEXT(bgp, bgp);
12192 int idx_protocol = 1;
12193 int idx_word = 3;
12194 int type;
12195 struct bgp_redist *red;
12196 bool changed;
12197 struct route_map *route_map = route_map_lookup_warn_noexist(
12198 vty, argv[idx_word]->arg);
12199
12200 type = proto_redistnum(AFI_IP, argv[idx_protocol]->text);
12201 if (type < 0) {
12202 vty_out(vty, "%% Invalid route type\n");
12203 return CMD_WARNING_CONFIG_FAILED;
12204 }
12205
12206 red = bgp_redist_add(bgp, AFI_IP, type, 0);
12207 changed =
12208 bgp_redistribute_rmap_set(red, argv[idx_word]->arg, route_map);
12209 return bgp_redistribute_set(bgp, AFI_IP, type, 0, changed);
12210 }
12211
12212 ALIAS_HIDDEN(
12213 bgp_redistribute_ipv4_rmap, bgp_redistribute_ipv4_rmap_hidden_cmd,
12214 "redistribute " FRR_IP_REDIST_STR_BGPD " route-map WORD",
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
12219 DEFUN (bgp_redistribute_ipv4_metric,
12220 bgp_redistribute_ipv4_metric_cmd,
12221 "redistribute " FRR_IP_REDIST_STR_BGPD " metric (0-4294967295)",
12222 "Redistribute information from another routing protocol\n"
12223 FRR_IP_REDIST_HELP_STR_BGPD
12224 "Metric for redistributed routes\n"
12225 "Default metric\n")
12226 {
12227 VTY_DECLVAR_CONTEXT(bgp, bgp);
12228 int idx_protocol = 1;
12229 int idx_number = 3;
12230 int type;
12231 uint32_t metric;
12232 struct bgp_redist *red;
12233 bool changed;
12234
12235 type = proto_redistnum(AFI_IP, argv[idx_protocol]->text);
12236 if (type < 0) {
12237 vty_out(vty, "%% Invalid route type\n");
12238 return CMD_WARNING_CONFIG_FAILED;
12239 }
12240 metric = strtoul(argv[idx_number]->arg, NULL, 10);
12241
12242 red = bgp_redist_add(bgp, AFI_IP, type, 0);
12243 changed = bgp_redistribute_metric_set(bgp, red, AFI_IP, type, metric);
12244 return bgp_redistribute_set(bgp, AFI_IP, type, 0, changed);
12245 }
12246
12247 ALIAS_HIDDEN(
12248 bgp_redistribute_ipv4_metric, bgp_redistribute_ipv4_metric_hidden_cmd,
12249 "redistribute " FRR_IP_REDIST_STR_BGPD " metric (0-4294967295)",
12250 "Redistribute information from another routing protocol\n" FRR_IP_REDIST_HELP_STR_BGPD
12251 "Metric for redistributed routes\n"
12252 "Default metric\n")
12253
12254 DEFUN (bgp_redistribute_ipv4_rmap_metric,
12255 bgp_redistribute_ipv4_rmap_metric_cmd,
12256 "redistribute " FRR_IP_REDIST_STR_BGPD " route-map WORD metric (0-4294967295)",
12257 "Redistribute information from another routing protocol\n"
12258 FRR_IP_REDIST_HELP_STR_BGPD
12259 "Route map reference\n"
12260 "Pointer to route-map entries\n"
12261 "Metric for redistributed routes\n"
12262 "Default metric\n")
12263 {
12264 VTY_DECLVAR_CONTEXT(bgp, bgp);
12265 int idx_protocol = 1;
12266 int idx_word = 3;
12267 int idx_number = 5;
12268 int type;
12269 uint32_t metric;
12270 struct bgp_redist *red;
12271 bool changed;
12272 struct route_map *route_map =
12273 route_map_lookup_warn_noexist(vty, argv[idx_word]->arg);
12274
12275 type = proto_redistnum(AFI_IP, argv[idx_protocol]->text);
12276 if (type < 0) {
12277 vty_out(vty, "%% Invalid route type\n");
12278 return CMD_WARNING_CONFIG_FAILED;
12279 }
12280 metric = strtoul(argv[idx_number]->arg, NULL, 10);
12281
12282 red = bgp_redist_add(bgp, AFI_IP, type, 0);
12283 changed =
12284 bgp_redistribute_rmap_set(red, argv[idx_word]->arg, route_map);
12285 changed |= bgp_redistribute_metric_set(bgp, red, AFI_IP, type, metric);
12286 return bgp_redistribute_set(bgp, AFI_IP, type, 0, changed);
12287 }
12288
12289 ALIAS_HIDDEN(
12290 bgp_redistribute_ipv4_rmap_metric,
12291 bgp_redistribute_ipv4_rmap_metric_hidden_cmd,
12292 "redistribute " FRR_IP_REDIST_STR_BGPD
12293 " route-map WORD metric (0-4294967295)",
12294 "Redistribute information from another routing protocol\n" FRR_IP_REDIST_HELP_STR_BGPD
12295 "Route map reference\n"
12296 "Pointer to route-map entries\n"
12297 "Metric for redistributed routes\n"
12298 "Default metric\n")
12299
12300 DEFUN (bgp_redistribute_ipv4_metric_rmap,
12301 bgp_redistribute_ipv4_metric_rmap_cmd,
12302 "redistribute " FRR_IP_REDIST_STR_BGPD " metric (0-4294967295) route-map WORD",
12303 "Redistribute information from another routing protocol\n"
12304 FRR_IP_REDIST_HELP_STR_BGPD
12305 "Metric for redistributed routes\n"
12306 "Default metric\n"
12307 "Route map reference\n"
12308 "Pointer to route-map entries\n")
12309 {
12310 VTY_DECLVAR_CONTEXT(bgp, bgp);
12311 int idx_protocol = 1;
12312 int idx_number = 3;
12313 int idx_word = 5;
12314 int type;
12315 uint32_t metric;
12316 struct bgp_redist *red;
12317 bool changed;
12318 struct route_map *route_map =
12319 route_map_lookup_warn_noexist(vty, argv[idx_word]->arg);
12320
12321 type = proto_redistnum(AFI_IP, argv[idx_protocol]->text);
12322 if (type < 0) {
12323 vty_out(vty, "%% Invalid route type\n");
12324 return CMD_WARNING_CONFIG_FAILED;
12325 }
12326 metric = strtoul(argv[idx_number]->arg, NULL, 10);
12327
12328 red = bgp_redist_add(bgp, AFI_IP, type, 0);
12329 changed = bgp_redistribute_metric_set(bgp, red, AFI_IP, type, metric);
12330 changed |=
12331 bgp_redistribute_rmap_set(red, argv[idx_word]->arg, route_map);
12332 return bgp_redistribute_set(bgp, AFI_IP, type, 0, changed);
12333 }
12334
12335 ALIAS_HIDDEN(
12336 bgp_redistribute_ipv4_metric_rmap,
12337 bgp_redistribute_ipv4_metric_rmap_hidden_cmd,
12338 "redistribute " FRR_IP_REDIST_STR_BGPD
12339 " metric (0-4294967295) route-map WORD",
12340 "Redistribute information from another routing protocol\n" FRR_IP_REDIST_HELP_STR_BGPD
12341 "Metric for redistributed routes\n"
12342 "Default metric\n"
12343 "Route map reference\n"
12344 "Pointer to route-map entries\n")
12345
12346 DEFUN (bgp_redistribute_ipv4_ospf,
12347 bgp_redistribute_ipv4_ospf_cmd,
12348 "redistribute <ospf|table> (1-65535)",
12349 "Redistribute information from another routing protocol\n"
12350 "Open Shortest Path First (OSPFv2)\n"
12351 "Non-main Kernel Routing Table\n"
12352 "Instance ID/Table ID\n")
12353 {
12354 VTY_DECLVAR_CONTEXT(bgp, bgp);
12355 int idx_ospf_table = 1;
12356 int idx_number = 2;
12357 unsigned short instance;
12358 unsigned short protocol;
12359
12360 instance = strtoul(argv[idx_number]->arg, NULL, 10);
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 bgp_redist_add(bgp, AFI_IP, protocol, instance);
12368 return bgp_redistribute_set(bgp, AFI_IP, protocol, instance, false);
12369 }
12370
12371 ALIAS_HIDDEN(bgp_redistribute_ipv4_ospf, bgp_redistribute_ipv4_ospf_hidden_cmd,
12372 "redistribute <ospf|table> (1-65535)",
12373 "Redistribute information from another routing protocol\n"
12374 "Open Shortest Path First (OSPFv2)\n"
12375 "Non-main Kernel Routing Table\n"
12376 "Instance ID/Table ID\n")
12377
12378 DEFUN (bgp_redistribute_ipv4_ospf_rmap,
12379 bgp_redistribute_ipv4_ospf_rmap_cmd,
12380 "redistribute <ospf|table> (1-65535) route-map WORD",
12381 "Redistribute information from another routing protocol\n"
12382 "Open Shortest Path First (OSPFv2)\n"
12383 "Non-main Kernel Routing Table\n"
12384 "Instance ID/Table ID\n"
12385 "Route map reference\n"
12386 "Pointer to route-map entries\n")
12387 {
12388 VTY_DECLVAR_CONTEXT(bgp, bgp);
12389 int idx_ospf_table = 1;
12390 int idx_number = 2;
12391 int idx_word = 4;
12392 struct bgp_redist *red;
12393 unsigned short instance;
12394 int protocol;
12395 bool changed;
12396 struct route_map *route_map =
12397 route_map_lookup_warn_noexist(vty, argv[idx_word]->arg);
12398
12399 if (strncmp(argv[idx_ospf_table]->arg, "o", 1) == 0)
12400 protocol = ZEBRA_ROUTE_OSPF;
12401 else
12402 protocol = ZEBRA_ROUTE_TABLE;
12403
12404 instance = strtoul(argv[idx_number]->arg, NULL, 10);
12405 red = bgp_redist_add(bgp, AFI_IP, protocol, instance);
12406 changed =
12407 bgp_redistribute_rmap_set(red, argv[idx_word]->arg, route_map);
12408 return bgp_redistribute_set(bgp, AFI_IP, protocol, instance, changed);
12409 }
12410
12411 ALIAS_HIDDEN(bgp_redistribute_ipv4_ospf_rmap,
12412 bgp_redistribute_ipv4_ospf_rmap_hidden_cmd,
12413 "redistribute <ospf|table> (1-65535) route-map WORD",
12414 "Redistribute information from another routing protocol\n"
12415 "Open Shortest Path First (OSPFv2)\n"
12416 "Non-main Kernel Routing Table\n"
12417 "Instance ID/Table ID\n"
12418 "Route map reference\n"
12419 "Pointer to route-map entries\n")
12420
12421 DEFUN (bgp_redistribute_ipv4_ospf_metric,
12422 bgp_redistribute_ipv4_ospf_metric_cmd,
12423 "redistribute <ospf|table> (1-65535) metric (0-4294967295)",
12424 "Redistribute information from another routing protocol\n"
12425 "Open Shortest Path First (OSPFv2)\n"
12426 "Non-main Kernel Routing Table\n"
12427 "Instance ID/Table ID\n"
12428 "Metric for redistributed routes\n"
12429 "Default metric\n")
12430 {
12431 VTY_DECLVAR_CONTEXT(bgp, bgp);
12432 int idx_ospf_table = 1;
12433 int idx_number = 2;
12434 int idx_number_2 = 4;
12435 uint32_t metric;
12436 struct bgp_redist *red;
12437 unsigned short instance;
12438 int protocol;
12439 bool changed;
12440
12441 if (strncmp(argv[idx_ospf_table]->arg, "o", 1) == 0)
12442 protocol = ZEBRA_ROUTE_OSPF;
12443 else
12444 protocol = ZEBRA_ROUTE_TABLE;
12445
12446 instance = strtoul(argv[idx_number]->arg, NULL, 10);
12447 metric = strtoul(argv[idx_number_2]->arg, NULL, 10);
12448
12449 red = bgp_redist_add(bgp, AFI_IP, protocol, instance);
12450 changed = bgp_redistribute_metric_set(bgp, red, AFI_IP, protocol,
12451 metric);
12452 return bgp_redistribute_set(bgp, AFI_IP, protocol, instance, changed);
12453 }
12454
12455 ALIAS_HIDDEN(bgp_redistribute_ipv4_ospf_metric,
12456 bgp_redistribute_ipv4_ospf_metric_hidden_cmd,
12457 "redistribute <ospf|table> (1-65535) metric (0-4294967295)",
12458 "Redistribute information from another routing protocol\n"
12459 "Open Shortest Path First (OSPFv2)\n"
12460 "Non-main Kernel Routing Table\n"
12461 "Instance ID/Table ID\n"
12462 "Metric for redistributed routes\n"
12463 "Default metric\n")
12464
12465 DEFUN (bgp_redistribute_ipv4_ospf_rmap_metric,
12466 bgp_redistribute_ipv4_ospf_rmap_metric_cmd,
12467 "redistribute <ospf|table> (1-65535) route-map WORD metric (0-4294967295)",
12468 "Redistribute information from another routing protocol\n"
12469 "Open Shortest Path First (OSPFv2)\n"
12470 "Non-main Kernel Routing Table\n"
12471 "Instance ID/Table ID\n"
12472 "Route map reference\n"
12473 "Pointer to route-map entries\n"
12474 "Metric for redistributed routes\n"
12475 "Default metric\n")
12476 {
12477 VTY_DECLVAR_CONTEXT(bgp, bgp);
12478 int idx_ospf_table = 1;
12479 int idx_number = 2;
12480 int idx_word = 4;
12481 int idx_number_2 = 6;
12482 uint32_t metric;
12483 struct bgp_redist *red;
12484 unsigned short instance;
12485 int protocol;
12486 bool changed;
12487 struct route_map *route_map =
12488 route_map_lookup_warn_noexist(vty, argv[idx_word]->arg);
12489
12490 if (strncmp(argv[idx_ospf_table]->arg, "o", 1) == 0)
12491 protocol = ZEBRA_ROUTE_OSPF;
12492 else
12493 protocol = ZEBRA_ROUTE_TABLE;
12494
12495 instance = strtoul(argv[idx_number]->arg, NULL, 10);
12496 metric = strtoul(argv[idx_number_2]->arg, NULL, 10);
12497
12498 red = bgp_redist_add(bgp, AFI_IP, protocol, instance);
12499 changed =
12500 bgp_redistribute_rmap_set(red, argv[idx_word]->arg, route_map);
12501 changed |= bgp_redistribute_metric_set(bgp, red, AFI_IP, protocol,
12502 metric);
12503 return bgp_redistribute_set(bgp, AFI_IP, protocol, instance, changed);
12504 }
12505
12506 ALIAS_HIDDEN(
12507 bgp_redistribute_ipv4_ospf_rmap_metric,
12508 bgp_redistribute_ipv4_ospf_rmap_metric_hidden_cmd,
12509 "redistribute <ospf|table> (1-65535) route-map WORD metric (0-4294967295)",
12510 "Redistribute information from another routing protocol\n"
12511 "Open Shortest Path First (OSPFv2)\n"
12512 "Non-main Kernel Routing Table\n"
12513 "Instance ID/Table ID\n"
12514 "Route map reference\n"
12515 "Pointer to route-map entries\n"
12516 "Metric for redistributed routes\n"
12517 "Default metric\n")
12518
12519 DEFUN (bgp_redistribute_ipv4_ospf_metric_rmap,
12520 bgp_redistribute_ipv4_ospf_metric_rmap_cmd,
12521 "redistribute <ospf|table> (1-65535) metric (0-4294967295) route-map WORD",
12522 "Redistribute information from another routing protocol\n"
12523 "Open Shortest Path First (OSPFv2)\n"
12524 "Non-main Kernel Routing Table\n"
12525 "Instance ID/Table ID\n"
12526 "Metric for redistributed routes\n"
12527 "Default metric\n"
12528 "Route map reference\n"
12529 "Pointer to route-map entries\n")
12530 {
12531 VTY_DECLVAR_CONTEXT(bgp, bgp);
12532 int idx_ospf_table = 1;
12533 int idx_number = 2;
12534 int idx_number_2 = 4;
12535 int idx_word = 6;
12536 uint32_t metric;
12537 struct bgp_redist *red;
12538 unsigned short instance;
12539 int protocol;
12540 bool changed;
12541 struct route_map *route_map =
12542 route_map_lookup_warn_noexist(vty, argv[idx_word]->arg);
12543
12544 if (strncmp(argv[idx_ospf_table]->arg, "o", 1) == 0)
12545 protocol = ZEBRA_ROUTE_OSPF;
12546 else
12547 protocol = ZEBRA_ROUTE_TABLE;
12548
12549 instance = strtoul(argv[idx_number]->arg, NULL, 10);
12550 metric = strtoul(argv[idx_number_2]->arg, NULL, 10);
12551
12552 red = bgp_redist_add(bgp, AFI_IP, protocol, instance);
12553 changed = bgp_redistribute_metric_set(bgp, red, AFI_IP, protocol,
12554 metric);
12555 changed |=
12556 bgp_redistribute_rmap_set(red, argv[idx_word]->arg, route_map);
12557 return bgp_redistribute_set(bgp, AFI_IP, protocol, instance, changed);
12558 }
12559
12560 ALIAS_HIDDEN(
12561 bgp_redistribute_ipv4_ospf_metric_rmap,
12562 bgp_redistribute_ipv4_ospf_metric_rmap_hidden_cmd,
12563 "redistribute <ospf|table> (1-65535) metric (0-4294967295) route-map WORD",
12564 "Redistribute information from another routing protocol\n"
12565 "Open Shortest Path First (OSPFv2)\n"
12566 "Non-main Kernel Routing Table\n"
12567 "Instance ID/Table ID\n"
12568 "Metric for redistributed routes\n"
12569 "Default metric\n"
12570 "Route map reference\n"
12571 "Pointer to route-map entries\n")
12572
12573 DEFUN (no_bgp_redistribute_ipv4_ospf,
12574 no_bgp_redistribute_ipv4_ospf_cmd,
12575 "no redistribute <ospf|table> (1-65535) [{metric (0-4294967295)|route-map WORD}]",
12576 NO_STR
12577 "Redistribute information from another routing protocol\n"
12578 "Open Shortest Path First (OSPFv2)\n"
12579 "Non-main Kernel Routing Table\n"
12580 "Instance ID/Table ID\n"
12581 "Metric for redistributed routes\n"
12582 "Default metric\n"
12583 "Route map reference\n"
12584 "Pointer to route-map entries\n")
12585 {
12586 VTY_DECLVAR_CONTEXT(bgp, bgp);
12587 int idx_ospf_table = 2;
12588 int idx_number = 3;
12589 unsigned short instance;
12590 int protocol;
12591
12592 if (strncmp(argv[idx_ospf_table]->arg, "o", 1) == 0)
12593 protocol = ZEBRA_ROUTE_OSPF;
12594 else
12595 protocol = ZEBRA_ROUTE_TABLE;
12596
12597 instance = strtoul(argv[idx_number]->arg, NULL, 10);
12598 return bgp_redistribute_unset(bgp, AFI_IP, protocol, instance);
12599 }
12600
12601 ALIAS_HIDDEN(
12602 no_bgp_redistribute_ipv4_ospf, no_bgp_redistribute_ipv4_ospf_hidden_cmd,
12603 "no redistribute <ospf|table> (1-65535) [{metric (0-4294967295)|route-map WORD}]",
12604 NO_STR
12605 "Redistribute information from another routing protocol\n"
12606 "Open Shortest Path First (OSPFv2)\n"
12607 "Non-main Kernel Routing Table\n"
12608 "Instance ID/Table ID\n"
12609 "Metric for redistributed routes\n"
12610 "Default metric\n"
12611 "Route map reference\n"
12612 "Pointer to route-map entries\n")
12613
12614 DEFUN (no_bgp_redistribute_ipv4,
12615 no_bgp_redistribute_ipv4_cmd,
12616 "no redistribute " FRR_IP_REDIST_STR_BGPD " [{metric (0-4294967295)|route-map WORD}]",
12617 NO_STR
12618 "Redistribute information from another routing protocol\n"
12619 FRR_IP_REDIST_HELP_STR_BGPD
12620 "Metric for redistributed routes\n"
12621 "Default metric\n"
12622 "Route map reference\n"
12623 "Pointer to route-map entries\n")
12624 {
12625 VTY_DECLVAR_CONTEXT(bgp, bgp);
12626 int idx_protocol = 2;
12627 int type;
12628
12629 type = proto_redistnum(AFI_IP, argv[idx_protocol]->text);
12630 if (type < 0) {
12631 vty_out(vty, "%% Invalid route type\n");
12632 return CMD_WARNING_CONFIG_FAILED;
12633 }
12634 return bgp_redistribute_unset(bgp, AFI_IP, type, 0);
12635 }
12636
12637 ALIAS_HIDDEN(
12638 no_bgp_redistribute_ipv4, no_bgp_redistribute_ipv4_hidden_cmd,
12639 "no redistribute " FRR_IP_REDIST_STR_BGPD
12640 " [{metric (0-4294967295)|route-map WORD}]",
12641 NO_STR
12642 "Redistribute information from another routing protocol\n" FRR_IP_REDIST_HELP_STR_BGPD
12643 "Metric for redistributed routes\n"
12644 "Default metric\n"
12645 "Route map reference\n"
12646 "Pointer to route-map entries\n")
12647
12648 DEFUN (bgp_redistribute_ipv6,
12649 bgp_redistribute_ipv6_cmd,
12650 "redistribute " FRR_IP6_REDIST_STR_BGPD,
12651 "Redistribute information from another routing protocol\n"
12652 FRR_IP6_REDIST_HELP_STR_BGPD)
12653 {
12654 VTY_DECLVAR_CONTEXT(bgp, bgp);
12655 int idx_protocol = 1;
12656 int type;
12657
12658 type = proto_redistnum(AFI_IP6, argv[idx_protocol]->text);
12659 if (type < 0) {
12660 vty_out(vty, "%% Invalid route type\n");
12661 return CMD_WARNING_CONFIG_FAILED;
12662 }
12663
12664 bgp_redist_add(bgp, AFI_IP6, type, 0);
12665 return bgp_redistribute_set(bgp, AFI_IP6, type, 0, false);
12666 }
12667
12668 DEFUN (bgp_redistribute_ipv6_rmap,
12669 bgp_redistribute_ipv6_rmap_cmd,
12670 "redistribute " FRR_IP6_REDIST_STR_BGPD " route-map WORD",
12671 "Redistribute information from another routing protocol\n"
12672 FRR_IP6_REDIST_HELP_STR_BGPD
12673 "Route map reference\n"
12674 "Pointer to route-map entries\n")
12675 {
12676 VTY_DECLVAR_CONTEXT(bgp, bgp);
12677 int idx_protocol = 1;
12678 int idx_word = 3;
12679 int type;
12680 struct bgp_redist *red;
12681 bool changed;
12682 struct route_map *route_map =
12683 route_map_lookup_warn_noexist(vty, argv[idx_word]->arg);
12684
12685 type = proto_redistnum(AFI_IP6, argv[idx_protocol]->text);
12686 if (type < 0) {
12687 vty_out(vty, "%% Invalid route type\n");
12688 return CMD_WARNING_CONFIG_FAILED;
12689 }
12690
12691 red = bgp_redist_add(bgp, AFI_IP6, type, 0);
12692 changed =
12693 bgp_redistribute_rmap_set(red, argv[idx_word]->arg, route_map);
12694 return bgp_redistribute_set(bgp, AFI_IP6, type, 0, changed);
12695 }
12696
12697 DEFUN (bgp_redistribute_ipv6_metric,
12698 bgp_redistribute_ipv6_metric_cmd,
12699 "redistribute " FRR_IP6_REDIST_STR_BGPD " metric (0-4294967295)",
12700 "Redistribute information from another routing protocol\n"
12701 FRR_IP6_REDIST_HELP_STR_BGPD
12702 "Metric for redistributed routes\n"
12703 "Default metric\n")
12704 {
12705 VTY_DECLVAR_CONTEXT(bgp, bgp);
12706 int idx_protocol = 1;
12707 int idx_number = 3;
12708 int type;
12709 uint32_t metric;
12710 struct bgp_redist *red;
12711 bool changed;
12712
12713 type = proto_redistnum(AFI_IP6, argv[idx_protocol]->text);
12714 if (type < 0) {
12715 vty_out(vty, "%% Invalid route type\n");
12716 return CMD_WARNING_CONFIG_FAILED;
12717 }
12718 metric = strtoul(argv[idx_number]->arg, NULL, 10);
12719
12720 red = bgp_redist_add(bgp, AFI_IP6, type, 0);
12721 changed = bgp_redistribute_metric_set(bgp, red, AFI_IP6, type, metric);
12722 return bgp_redistribute_set(bgp, AFI_IP6, type, 0, changed);
12723 }
12724
12725 DEFUN (bgp_redistribute_ipv6_rmap_metric,
12726 bgp_redistribute_ipv6_rmap_metric_cmd,
12727 "redistribute " FRR_IP6_REDIST_STR_BGPD " route-map WORD metric (0-4294967295)",
12728 "Redistribute information from another routing protocol\n"
12729 FRR_IP6_REDIST_HELP_STR_BGPD
12730 "Route map reference\n"
12731 "Pointer to route-map entries\n"
12732 "Metric for redistributed routes\n"
12733 "Default metric\n")
12734 {
12735 VTY_DECLVAR_CONTEXT(bgp, bgp);
12736 int idx_protocol = 1;
12737 int idx_word = 3;
12738 int idx_number = 5;
12739 int type;
12740 uint32_t metric;
12741 struct bgp_redist *red;
12742 bool changed;
12743 struct route_map *route_map =
12744 route_map_lookup_warn_noexist(vty, argv[idx_word]->arg);
12745
12746 type = proto_redistnum(AFI_IP6, argv[idx_protocol]->text);
12747 if (type < 0) {
12748 vty_out(vty, "%% Invalid route type\n");
12749 return CMD_WARNING_CONFIG_FAILED;
12750 }
12751 metric = strtoul(argv[idx_number]->arg, NULL, 10);
12752
12753 red = bgp_redist_add(bgp, AFI_IP6, type, 0);
12754 changed =
12755 bgp_redistribute_rmap_set(red, argv[idx_word]->arg, route_map);
12756 changed |= bgp_redistribute_metric_set(bgp, red, AFI_IP6, type,
12757 metric);
12758 return bgp_redistribute_set(bgp, AFI_IP6, type, 0, changed);
12759 }
12760
12761 DEFUN (bgp_redistribute_ipv6_metric_rmap,
12762 bgp_redistribute_ipv6_metric_rmap_cmd,
12763 "redistribute " FRR_IP6_REDIST_STR_BGPD " metric (0-4294967295) route-map WORD",
12764 "Redistribute information from another routing protocol\n"
12765 FRR_IP6_REDIST_HELP_STR_BGPD
12766 "Metric for redistributed routes\n"
12767 "Default metric\n"
12768 "Route map reference\n"
12769 "Pointer to route-map entries\n")
12770 {
12771 VTY_DECLVAR_CONTEXT(bgp, bgp);
12772 int idx_protocol = 1;
12773 int idx_number = 3;
12774 int idx_word = 5;
12775 int type;
12776 uint32_t metric;
12777 struct bgp_redist *red;
12778 bool changed;
12779 struct route_map *route_map =
12780 route_map_lookup_warn_noexist(vty, argv[idx_word]->arg);
12781
12782 type = proto_redistnum(AFI_IP6, argv[idx_protocol]->text);
12783 if (type < 0) {
12784 vty_out(vty, "%% Invalid route type\n");
12785 return CMD_WARNING_CONFIG_FAILED;
12786 }
12787 metric = strtoul(argv[idx_number]->arg, NULL, 10);
12788
12789 red = bgp_redist_add(bgp, AFI_IP6, type, 0);
12790 changed = bgp_redistribute_metric_set(bgp, red, AFI_IP6, SAFI_UNICAST,
12791 metric);
12792 changed |=
12793 bgp_redistribute_rmap_set(red, argv[idx_word]->arg, route_map);
12794 return bgp_redistribute_set(bgp, AFI_IP6, type, 0, changed);
12795 }
12796
12797 DEFUN (no_bgp_redistribute_ipv6,
12798 no_bgp_redistribute_ipv6_cmd,
12799 "no redistribute " FRR_IP6_REDIST_STR_BGPD " [{metric (0-4294967295)|route-map WORD}]",
12800 NO_STR
12801 "Redistribute information from another routing protocol\n"
12802 FRR_IP6_REDIST_HELP_STR_BGPD
12803 "Metric for redistributed routes\n"
12804 "Default metric\n"
12805 "Route map reference\n"
12806 "Pointer to route-map entries\n")
12807 {
12808 VTY_DECLVAR_CONTEXT(bgp, bgp);
12809 int idx_protocol = 2;
12810 int type;
12811
12812 type = proto_redistnum(AFI_IP6, argv[idx_protocol]->text);
12813 if (type < 0) {
12814 vty_out(vty, "%% Invalid route type\n");
12815 return CMD_WARNING_CONFIG_FAILED;
12816 }
12817
12818 return bgp_redistribute_unset(bgp, AFI_IP6, type, 0);
12819 }
12820
12821 static void bgp_config_write_redistribute(struct vty *vty, struct bgp *bgp,
12822 afi_t afi, safi_t safi)
12823 {
12824 int i;
12825
12826 /* Unicast redistribution only. */
12827 if (safi != SAFI_UNICAST)
12828 return;
12829
12830 for (i = 0; i < ZEBRA_ROUTE_MAX; i++) {
12831 /* Redistribute BGP does not make sense. */
12832 if (i != ZEBRA_ROUTE_BGP) {
12833 struct list *red_list;
12834 struct listnode *node;
12835 struct bgp_redist *red;
12836
12837 red_list = bgp->redist[afi][i];
12838 if (!red_list)
12839 continue;
12840
12841 for (ALL_LIST_ELEMENTS_RO(red_list, node, red)) {
12842 /* "redistribute" configuration. */
12843 vty_out(vty, " redistribute %s",
12844 zebra_route_string(i));
12845 if (red->instance)
12846 vty_out(vty, " %d", red->instance);
12847 if (red->redist_metric_flag)
12848 vty_out(vty, " metric %u",
12849 red->redist_metric);
12850 if (red->rmap.name)
12851 vty_out(vty, " route-map %s",
12852 red->rmap.name);
12853 vty_out(vty, "\n");
12854 }
12855 }
12856 }
12857 }
12858
12859 /* peer-group helpers for config-write */
12860
12861 static bool peergroup_flag_check(struct peer *peer, uint32_t flag)
12862 {
12863 if (!peer_group_active(peer)) {
12864 if (CHECK_FLAG(peer->flags_invert, flag))
12865 return !CHECK_FLAG(peer->flags, flag);
12866 else
12867 return !!CHECK_FLAG(peer->flags, flag);
12868 }
12869
12870 return !!CHECK_FLAG(peer->flags_override, flag);
12871 }
12872
12873 static bool peergroup_af_flag_check(struct peer *peer, afi_t afi, safi_t safi,
12874 uint32_t flag)
12875 {
12876 if (!peer_group_active(peer)) {
12877 if (CHECK_FLAG(peer->af_flags_invert[afi][safi], flag))
12878 return !peer_af_flag_check(peer, afi, safi, flag);
12879 else
12880 return !!peer_af_flag_check(peer, afi, safi, flag);
12881 }
12882
12883 return !!CHECK_FLAG(peer->af_flags_override[afi][safi], flag);
12884 }
12885
12886 static bool peergroup_filter_check(struct peer *peer, afi_t afi, safi_t safi,
12887 uint8_t type, int direct)
12888 {
12889 struct bgp_filter *filter;
12890
12891 if (peer_group_active(peer))
12892 return !!CHECK_FLAG(peer->filter_override[afi][safi][direct],
12893 type);
12894
12895 filter = &peer->filter[afi][safi];
12896 switch (type) {
12897 case PEER_FT_DISTRIBUTE_LIST:
12898 return !!(filter->dlist[direct].name);
12899 case PEER_FT_FILTER_LIST:
12900 return !!(filter->aslist[direct].name);
12901 case PEER_FT_PREFIX_LIST:
12902 return !!(filter->plist[direct].name);
12903 case PEER_FT_ROUTE_MAP:
12904 return !!(filter->map[direct].name);
12905 case PEER_FT_UNSUPPRESS_MAP:
12906 return !!(filter->usmap.name);
12907 default:
12908 return false;
12909 }
12910 }
12911
12912 /* Return true if the addpath type is set for peer and different from
12913 * peer-group.
12914 */
12915 static int peergroup_af_addpath_check(struct peer *peer, afi_t afi, safi_t safi)
12916 {
12917 enum bgp_addpath_strat type, g_type;
12918
12919 type = peer->addpath_type[afi][safi];
12920
12921 if (type != BGP_ADDPATH_NONE) {
12922 if (peer_group_active(peer)) {
12923 g_type = peer->group->conf->addpath_type[afi][safi];
12924
12925 if (type != g_type)
12926 return 1;
12927 else
12928 return 0;
12929 }
12930
12931 return 1;
12932 }
12933
12934 return 0;
12935 }
12936
12937 /* This is part of the address-family block (unicast only) */
12938 static void bgp_vpn_policy_config_write_afi(struct vty *vty, struct bgp *bgp,
12939 afi_t afi)
12940 {
12941 int indent = 2;
12942
12943 if (bgp->vpn_policy[afi].rmap_name[BGP_VPN_POLICY_DIR_FROMVPN]) {
12944 if (listcount(bgp->vpn_policy[afi].import_vrf))
12945 vty_out(vty, "%*simport vrf route-map %s\n", indent, "",
12946 bgp->vpn_policy[afi]
12947 .rmap_name[BGP_VPN_POLICY_DIR_FROMVPN]);
12948 else
12949 vty_out(vty, "%*sroute-map vpn import %s\n", indent, "",
12950 bgp->vpn_policy[afi]
12951 .rmap_name[BGP_VPN_POLICY_DIR_FROMVPN]);
12952 }
12953 if (CHECK_FLAG(bgp->af_flags[afi][SAFI_UNICAST],
12954 BGP_CONFIG_VRF_TO_VRF_IMPORT)
12955 || CHECK_FLAG(bgp->af_flags[afi][SAFI_UNICAST],
12956 BGP_CONFIG_VRF_TO_VRF_EXPORT))
12957 return;
12958
12959 if (CHECK_FLAG(bgp->vpn_policy[afi].flags,
12960 BGP_VPN_POLICY_TOVPN_LABEL_AUTO)) {
12961
12962 vty_out(vty, "%*slabel vpn export %s\n", indent, "", "auto");
12963
12964 } else {
12965 if (bgp->vpn_policy[afi].tovpn_label != MPLS_LABEL_NONE) {
12966 vty_out(vty, "%*slabel vpn export %u\n", indent, "",
12967 bgp->vpn_policy[afi].tovpn_label);
12968 }
12969 }
12970 if (CHECK_FLAG(bgp->vpn_policy[afi].flags,
12971 BGP_VPN_POLICY_TOVPN_RD_SET)) {
12972 char buf[RD_ADDRSTRLEN];
12973 vty_out(vty, "%*srd vpn export %s\n", indent, "",
12974 prefix_rd2str(&bgp->vpn_policy[afi].tovpn_rd, buf,
12975 sizeof(buf)));
12976 }
12977 if (CHECK_FLAG(bgp->vpn_policy[afi].flags,
12978 BGP_VPN_POLICY_TOVPN_NEXTHOP_SET)) {
12979
12980 char buf[PREFIX_STRLEN];
12981 if (inet_ntop(bgp->vpn_policy[afi].tovpn_nexthop.family,
12982 &bgp->vpn_policy[afi].tovpn_nexthop.u.prefix, buf,
12983 sizeof(buf))) {
12984
12985 vty_out(vty, "%*snexthop vpn export %s\n",
12986 indent, "", buf);
12987 }
12988 }
12989 if (bgp->vpn_policy[afi].rtlist[BGP_VPN_POLICY_DIR_FROMVPN]
12990 && bgp->vpn_policy[afi].rtlist[BGP_VPN_POLICY_DIR_TOVPN]
12991 && ecommunity_cmp(
12992 bgp->vpn_policy[afi].rtlist[BGP_VPN_POLICY_DIR_FROMVPN],
12993 bgp->vpn_policy[afi].rtlist[BGP_VPN_POLICY_DIR_TOVPN])) {
12994
12995 char *b = ecommunity_ecom2str(
12996 bgp->vpn_policy[afi].rtlist[BGP_VPN_POLICY_DIR_TOVPN],
12997 ECOMMUNITY_FORMAT_ROUTE_MAP, ECOMMUNITY_ROUTE_TARGET);
12998 vty_out(vty, "%*srt vpn both %s\n", indent, "", b);
12999 XFREE(MTYPE_ECOMMUNITY_STR, b);
13000 } else {
13001 if (bgp->vpn_policy[afi].rtlist[BGP_VPN_POLICY_DIR_FROMVPN]) {
13002 char *b = ecommunity_ecom2str(
13003 bgp->vpn_policy[afi]
13004 .rtlist[BGP_VPN_POLICY_DIR_FROMVPN],
13005 ECOMMUNITY_FORMAT_ROUTE_MAP,
13006 ECOMMUNITY_ROUTE_TARGET);
13007 vty_out(vty, "%*srt vpn import %s\n", indent, "", b);
13008 XFREE(MTYPE_ECOMMUNITY_STR, b);
13009 }
13010 if (bgp->vpn_policy[afi].rtlist[BGP_VPN_POLICY_DIR_TOVPN]) {
13011 char *b = ecommunity_ecom2str(
13012 bgp->vpn_policy[afi]
13013 .rtlist[BGP_VPN_POLICY_DIR_TOVPN],
13014 ECOMMUNITY_FORMAT_ROUTE_MAP,
13015 ECOMMUNITY_ROUTE_TARGET);
13016 vty_out(vty, "%*srt vpn export %s\n", indent, "", b);
13017 XFREE(MTYPE_ECOMMUNITY_STR, b);
13018 }
13019 }
13020
13021 if (bgp->vpn_policy[afi].rmap_name[BGP_VPN_POLICY_DIR_TOVPN])
13022 vty_out(vty, "%*sroute-map vpn export %s\n", indent, "",
13023 bgp->vpn_policy[afi]
13024 .rmap_name[BGP_VPN_POLICY_DIR_TOVPN]);
13025
13026 if (bgp->vpn_policy[afi].import_redirect_rtlist) {
13027 char *b = ecommunity_ecom2str(
13028 bgp->vpn_policy[afi]
13029 .import_redirect_rtlist,
13030 ECOMMUNITY_FORMAT_ROUTE_MAP,
13031 ECOMMUNITY_ROUTE_TARGET);
13032
13033 vty_out(vty, "%*srt redirect import %s\n", indent, "", b);
13034 XFREE(MTYPE_ECOMMUNITY_STR, b);
13035 }
13036 }
13037
13038 static void bgp_config_write_filter(struct vty *vty, struct peer *peer,
13039 afi_t afi, safi_t safi)
13040 {
13041 struct bgp_filter *filter;
13042 char *addr;
13043
13044 addr = peer->host;
13045 filter = &peer->filter[afi][safi];
13046
13047 /* distribute-list. */
13048 if (peergroup_filter_check(peer, afi, safi, PEER_FT_DISTRIBUTE_LIST,
13049 FILTER_IN))
13050 vty_out(vty, " neighbor %s distribute-list %s in\n", addr,
13051 filter->dlist[FILTER_IN].name);
13052
13053 if (peergroup_filter_check(peer, afi, safi, PEER_FT_DISTRIBUTE_LIST,
13054 FILTER_OUT))
13055 vty_out(vty, " neighbor %s distribute-list %s out\n", addr,
13056 filter->dlist[FILTER_OUT].name);
13057
13058 /* prefix-list. */
13059 if (peergroup_filter_check(peer, afi, safi, PEER_FT_PREFIX_LIST,
13060 FILTER_IN))
13061 vty_out(vty, " neighbor %s prefix-list %s in\n", addr,
13062 filter->plist[FILTER_IN].name);
13063
13064 if (peergroup_filter_check(peer, afi, safi, PEER_FT_PREFIX_LIST,
13065 FILTER_OUT))
13066 vty_out(vty, " neighbor %s prefix-list %s out\n", addr,
13067 filter->plist[FILTER_OUT].name);
13068
13069 /* route-map. */
13070 if (peergroup_filter_check(peer, afi, safi, PEER_FT_ROUTE_MAP, RMAP_IN))
13071 vty_out(vty, " neighbor %s route-map %s in\n", addr,
13072 filter->map[RMAP_IN].name);
13073
13074 if (peergroup_filter_check(peer, afi, safi, PEER_FT_ROUTE_MAP,
13075 RMAP_OUT))
13076 vty_out(vty, " neighbor %s route-map %s out\n", addr,
13077 filter->map[RMAP_OUT].name);
13078
13079 /* unsuppress-map */
13080 if (peergroup_filter_check(peer, afi, safi, PEER_FT_UNSUPPRESS_MAP, 0))
13081 vty_out(vty, " neighbor %s unsuppress-map %s\n", addr,
13082 filter->usmap.name);
13083
13084 /* filter-list. */
13085 if (peergroup_filter_check(peer, afi, safi, PEER_FT_FILTER_LIST,
13086 FILTER_IN))
13087 vty_out(vty, " neighbor %s filter-list %s in\n", addr,
13088 filter->aslist[FILTER_IN].name);
13089
13090 if (peergroup_filter_check(peer, afi, safi, PEER_FT_FILTER_LIST,
13091 FILTER_OUT))
13092 vty_out(vty, " neighbor %s filter-list %s out\n", addr,
13093 filter->aslist[FILTER_OUT].name);
13094 }
13095
13096 /* BGP peer configuration display function. */
13097 static void bgp_config_write_peer_global(struct vty *vty, struct bgp *bgp,
13098 struct peer *peer)
13099 {
13100 struct peer *g_peer = NULL;
13101 char buf[SU_ADDRSTRLEN];
13102 char *addr;
13103 int if_pg_printed = false;
13104 int if_ras_printed = false;
13105
13106 /* Skip dynamic neighbors. */
13107 if (peer_dynamic_neighbor(peer))
13108 return;
13109
13110 if (peer->conf_if)
13111 addr = peer->conf_if;
13112 else
13113 addr = peer->host;
13114
13115 /************************************
13116 ****** Global to the neighbor ******
13117 ************************************/
13118 if (peer->conf_if) {
13119 if (CHECK_FLAG(peer->flags, PEER_FLAG_IFPEER_V6ONLY))
13120 vty_out(vty, " neighbor %s interface v6only", addr);
13121 else
13122 vty_out(vty, " neighbor %s interface", addr);
13123
13124 if (peer_group_active(peer)) {
13125 vty_out(vty, " peer-group %s", peer->group->name);
13126 if_pg_printed = true;
13127 } else if (peer->as_type == AS_SPECIFIED) {
13128 vty_out(vty, " remote-as %u", peer->as);
13129 if_ras_printed = true;
13130 } else if (peer->as_type == AS_INTERNAL) {
13131 vty_out(vty, " remote-as internal");
13132 if_ras_printed = true;
13133 } else if (peer->as_type == AS_EXTERNAL) {
13134 vty_out(vty, " remote-as external");
13135 if_ras_printed = true;
13136 }
13137
13138 vty_out(vty, "\n");
13139 }
13140
13141 /* remote-as and peer-group */
13142 /* peer is a member of a peer-group */
13143 if (peer_group_active(peer)) {
13144 g_peer = peer->group->conf;
13145
13146 if (g_peer->as_type == AS_UNSPECIFIED && !if_ras_printed) {
13147 if (peer->as_type == AS_SPECIFIED) {
13148 vty_out(vty, " neighbor %s remote-as %u\n",
13149 addr, peer->as);
13150 } else if (peer->as_type == AS_INTERNAL) {
13151 vty_out(vty,
13152 " neighbor %s remote-as internal\n",
13153 addr);
13154 } else if (peer->as_type == AS_EXTERNAL) {
13155 vty_out(vty,
13156 " neighbor %s remote-as external\n",
13157 addr);
13158 }
13159 }
13160
13161 /* For swpX peers we displayed the peer-group
13162 * via 'neighbor swpX interface peer-group PGNAME' */
13163 if (!if_pg_printed)
13164 vty_out(vty, " neighbor %s peer-group %s\n", addr,
13165 peer->group->name);
13166 }
13167
13168 /* peer is NOT a member of a peer-group */
13169 else {
13170 /* peer is a peer-group, declare the peer-group */
13171 if (CHECK_FLAG(peer->sflags, PEER_STATUS_GROUP)) {
13172 vty_out(vty, " neighbor %s peer-group\n", addr);
13173 }
13174
13175 if (!if_ras_printed) {
13176 if (peer->as_type == AS_SPECIFIED) {
13177 vty_out(vty, " neighbor %s remote-as %u\n",
13178 addr, peer->as);
13179 } else if (peer->as_type == AS_INTERNAL) {
13180 vty_out(vty,
13181 " neighbor %s remote-as internal\n",
13182 addr);
13183 } else if (peer->as_type == AS_EXTERNAL) {
13184 vty_out(vty,
13185 " neighbor %s remote-as external\n",
13186 addr);
13187 }
13188 }
13189 }
13190
13191 /* local-as */
13192 if (peergroup_flag_check(peer, PEER_FLAG_LOCAL_AS)) {
13193 vty_out(vty, " neighbor %s local-as %u", addr,
13194 peer->change_local_as);
13195 if (peergroup_flag_check(peer, PEER_FLAG_LOCAL_AS_NO_PREPEND))
13196 vty_out(vty, " no-prepend");
13197 if (peergroup_flag_check(peer, PEER_FLAG_LOCAL_AS_REPLACE_AS))
13198 vty_out(vty, " replace-as");
13199 vty_out(vty, "\n");
13200 }
13201
13202 /* description */
13203 if (peer->desc) {
13204 vty_out(vty, " neighbor %s description %s\n", addr, peer->desc);
13205 }
13206
13207 /* shutdown */
13208 if (peergroup_flag_check(peer, PEER_FLAG_SHUTDOWN)) {
13209 if (peer->tx_shutdown_message)
13210 vty_out(vty, " neighbor %s shutdown message %s\n", addr,
13211 peer->tx_shutdown_message);
13212 else
13213 vty_out(vty, " neighbor %s shutdown\n", addr);
13214 }
13215
13216 /* bfd */
13217 if (peer->bfd_info) {
13218 if (!peer_group_active(peer) || !g_peer->bfd_info) {
13219 bgp_bfd_peer_config_write(vty, peer, addr);
13220 }
13221 }
13222
13223 /* password */
13224 if (peergroup_flag_check(peer, PEER_FLAG_PASSWORD))
13225 vty_out(vty, " neighbor %s password %s\n", addr,
13226 peer->password);
13227
13228 /* neighbor solo */
13229 if (CHECK_FLAG(peer->flags, PEER_FLAG_LONESOUL)) {
13230 if (!peer_group_active(peer)) {
13231 vty_out(vty, " neighbor %s solo\n", addr);
13232 }
13233 }
13234
13235 /* BGP port */
13236 if (peer->port != BGP_PORT_DEFAULT) {
13237 vty_out(vty, " neighbor %s port %d\n", addr, peer->port);
13238 }
13239
13240 /* Local interface name */
13241 if (peer->ifname) {
13242 vty_out(vty, " neighbor %s interface %s\n", addr, peer->ifname);
13243 }
13244
13245 /* passive */
13246 if (peergroup_flag_check(peer, PEER_FLAG_PASSIVE))
13247 vty_out(vty, " neighbor %s passive\n", addr);
13248
13249 /* ebgp-multihop */
13250 if (peer->sort != BGP_PEER_IBGP && peer->ttl != BGP_DEFAULT_TTL
13251 && !(peer->gtsm_hops != 0 && peer->ttl == MAXTTL)) {
13252 if (!peer_group_active(peer) || g_peer->ttl != peer->ttl) {
13253 vty_out(vty, " neighbor %s ebgp-multihop %d\n", addr,
13254 peer->ttl);
13255 }
13256 }
13257
13258 /* ttl-security hops */
13259 if (peer->gtsm_hops != 0) {
13260 if (!peer_group_active(peer)
13261 || g_peer->gtsm_hops != peer->gtsm_hops) {
13262 vty_out(vty, " neighbor %s ttl-security hops %d\n",
13263 addr, peer->gtsm_hops);
13264 }
13265 }
13266
13267 /* disable-connected-check */
13268 if (peergroup_flag_check(peer, PEER_FLAG_DISABLE_CONNECTED_CHECK))
13269 vty_out(vty, " neighbor %s disable-connected-check\n", addr);
13270
13271 /* enforce-first-as */
13272 if (peergroup_flag_check(peer, PEER_FLAG_ENFORCE_FIRST_AS))
13273 vty_out(vty, " neighbor %s enforce-first-as\n", addr);
13274
13275 /* update-source */
13276 if (peergroup_flag_check(peer, PEER_FLAG_UPDATE_SOURCE)) {
13277 if (peer->update_source)
13278 vty_out(vty, " neighbor %s update-source %s\n", addr,
13279 sockunion2str(peer->update_source, buf,
13280 SU_ADDRSTRLEN));
13281 else if (peer->update_if)
13282 vty_out(vty, " neighbor %s update-source %s\n", addr,
13283 peer->update_if);
13284 }
13285
13286 /* advertisement-interval */
13287 if (peergroup_flag_check(peer, PEER_FLAG_ROUTEADV))
13288 vty_out(vty, " neighbor %s advertisement-interval %u\n", addr,
13289 peer->routeadv);
13290
13291 /* timers */
13292 if (peergroup_flag_check(peer, PEER_FLAG_TIMER))
13293 vty_out(vty, " neighbor %s timers %u %u\n", addr,
13294 peer->keepalive, peer->holdtime);
13295
13296 /* timers connect */
13297 if (peergroup_flag_check(peer, PEER_FLAG_TIMER_CONNECT))
13298 vty_out(vty, " neighbor %s timers connect %u\n", addr,
13299 peer->connect);
13300
13301 /* capability dynamic */
13302 if (peergroup_flag_check(peer, PEER_FLAG_DYNAMIC_CAPABILITY))
13303 vty_out(vty, " neighbor %s capability dynamic\n", addr);
13304
13305 /* capability extended-nexthop */
13306 if (peergroup_flag_check(peer, PEER_FLAG_CAPABILITY_ENHE)) {
13307 if (!peer->conf_if) {
13308 if (CHECK_FLAG(peer->flags_invert,
13309 PEER_FLAG_CAPABILITY_ENHE))
13310 vty_out(vty,
13311 " no neighbor %s capability extended-nexthop\n",
13312 addr);
13313 else
13314 vty_out(vty,
13315 " neighbor %s capability extended-nexthop\n",
13316 addr);
13317 }
13318 }
13319
13320 /* dont-capability-negotiation */
13321 if (peergroup_flag_check(peer, PEER_FLAG_DONT_CAPABILITY))
13322 vty_out(vty, " neighbor %s dont-capability-negotiate\n", addr);
13323
13324 /* override-capability */
13325 if (peergroup_flag_check(peer, PEER_FLAG_OVERRIDE_CAPABILITY))
13326 vty_out(vty, " neighbor %s override-capability\n", addr);
13327
13328 /* strict-capability-match */
13329 if (peergroup_flag_check(peer, PEER_FLAG_STRICT_CAP_MATCH))
13330 vty_out(vty, " neighbor %s strict-capability-match\n", addr);
13331
13332 /* Sender side AS path loop detection. */
13333 if (peer->as_path_loop_detection)
13334 vty_out(vty, " neighbor %s sender-as-path-loop-detection\n",
13335 addr);
13336 }
13337
13338 /* BGP peer configuration display function. */
13339 static void bgp_config_write_peer_af(struct vty *vty, struct bgp *bgp,
13340 struct peer *peer, afi_t afi, safi_t safi)
13341 {
13342 struct peer *g_peer = NULL;
13343 char *addr;
13344 bool flag_scomm, flag_secomm, flag_slcomm;
13345
13346 /* Skip dynamic neighbors. */
13347 if (peer_dynamic_neighbor(peer))
13348 return;
13349
13350 if (peer->conf_if)
13351 addr = peer->conf_if;
13352 else
13353 addr = peer->host;
13354
13355 /************************************
13356 ****** Per AF to the neighbor ******
13357 ************************************/
13358 if (peer_group_active(peer)) {
13359 g_peer = peer->group->conf;
13360
13361 /* If the peer-group is active but peer is not, print a 'no
13362 * activate' */
13363 if (g_peer->afc[afi][safi] && !peer->afc[afi][safi]) {
13364 vty_out(vty, " no neighbor %s activate\n", addr);
13365 }
13366
13367 /* If the peer-group is not active but peer is, print an
13368 'activate' */
13369 else if (!g_peer->afc[afi][safi] && peer->afc[afi][safi]) {
13370 vty_out(vty, " neighbor %s activate\n", addr);
13371 }
13372 } else {
13373 if (peer->afc[afi][safi]) {
13374 if ((afi == AFI_IP) && (safi == SAFI_UNICAST)) {
13375 if (bgp_flag_check(bgp,
13376 BGP_FLAG_NO_DEFAULT_IPV4)) {
13377 vty_out(vty, " neighbor %s activate\n",
13378 addr);
13379 }
13380 } else
13381 vty_out(vty, " neighbor %s activate\n", addr);
13382 } else {
13383 if ((afi == AFI_IP) && (safi == SAFI_UNICAST)) {
13384 if (!bgp_flag_check(bgp,
13385 BGP_FLAG_NO_DEFAULT_IPV4)) {
13386 vty_out(vty,
13387 " no neighbor %s activate\n",
13388 addr);
13389 }
13390 }
13391 }
13392 }
13393
13394 /* addpath TX knobs */
13395 if (peergroup_af_addpath_check(peer, afi, safi)) {
13396 switch (peer->addpath_type[afi][safi]) {
13397 case BGP_ADDPATH_ALL:
13398 vty_out(vty, " neighbor %s addpath-tx-all-paths\n",
13399 addr);
13400 break;
13401 case BGP_ADDPATH_BEST_PER_AS:
13402 vty_out(vty,
13403 " neighbor %s addpath-tx-bestpath-per-AS\n",
13404 addr);
13405 break;
13406 case BGP_ADDPATH_MAX:
13407 case BGP_ADDPATH_NONE:
13408 break;
13409 }
13410 }
13411
13412 /* ORF capability. */
13413 if (peergroup_af_flag_check(peer, afi, safi, PEER_FLAG_ORF_PREFIX_SM)
13414 || peergroup_af_flag_check(peer, afi, safi,
13415 PEER_FLAG_ORF_PREFIX_RM)) {
13416 vty_out(vty, " neighbor %s capability orf prefix-list", addr);
13417
13418 if (peergroup_af_flag_check(peer, afi, safi,
13419 PEER_FLAG_ORF_PREFIX_SM)
13420 && peergroup_af_flag_check(peer, afi, safi,
13421 PEER_FLAG_ORF_PREFIX_RM))
13422 vty_out(vty, " both");
13423 else if (peergroup_af_flag_check(peer, afi, safi,
13424 PEER_FLAG_ORF_PREFIX_SM))
13425 vty_out(vty, " send");
13426 else
13427 vty_out(vty, " receive");
13428 vty_out(vty, "\n");
13429 }
13430
13431 /* BGP flag dampening. */
13432 if (CHECK_FLAG(bgp->af_flags[afi][safi],
13433 BGP_CONFIG_DAMPENING))
13434 bgp_config_write_damp(vty, afi, safi);
13435
13436 /* Route reflector client. */
13437 if (peergroup_af_flag_check(peer, afi, safi,
13438 PEER_FLAG_REFLECTOR_CLIENT)) {
13439 vty_out(vty, " neighbor %s route-reflector-client\n", addr);
13440 }
13441
13442 /* next-hop-self force */
13443 if (peergroup_af_flag_check(peer, afi, safi,
13444 PEER_FLAG_FORCE_NEXTHOP_SELF)) {
13445 vty_out(vty, " neighbor %s next-hop-self force\n", addr);
13446 }
13447
13448 /* next-hop-self */
13449 if (peergroup_af_flag_check(peer, afi, safi, PEER_FLAG_NEXTHOP_SELF)) {
13450 vty_out(vty, " neighbor %s next-hop-self\n", addr);
13451 }
13452
13453 /* remove-private-AS */
13454 if (peergroup_af_flag_check(peer, afi, safi,
13455 PEER_FLAG_REMOVE_PRIVATE_AS_ALL_REPLACE)) {
13456 vty_out(vty, " neighbor %s remove-private-AS all replace-AS\n",
13457 addr);
13458 }
13459
13460 else if (peergroup_af_flag_check(peer, afi, safi,
13461 PEER_FLAG_REMOVE_PRIVATE_AS_REPLACE)) {
13462 vty_out(vty, " neighbor %s remove-private-AS replace-AS\n",
13463 addr);
13464 }
13465
13466 else if (peergroup_af_flag_check(peer, afi, safi,
13467 PEER_FLAG_REMOVE_PRIVATE_AS_ALL)) {
13468 vty_out(vty, " neighbor %s remove-private-AS all\n", addr);
13469 }
13470
13471 else if (peergroup_af_flag_check(peer, afi, safi,
13472 PEER_FLAG_REMOVE_PRIVATE_AS)) {
13473 vty_out(vty, " neighbor %s remove-private-AS\n", addr);
13474 }
13475
13476 /* as-override */
13477 if (peergroup_af_flag_check(peer, afi, safi, PEER_FLAG_AS_OVERRIDE)) {
13478 vty_out(vty, " neighbor %s as-override\n", addr);
13479 }
13480
13481 /* send-community print. */
13482 flag_scomm = peergroup_af_flag_check(peer, afi, safi,
13483 PEER_FLAG_SEND_COMMUNITY);
13484 flag_secomm = peergroup_af_flag_check(peer, afi, safi,
13485 PEER_FLAG_SEND_EXT_COMMUNITY);
13486 flag_slcomm = peergroup_af_flag_check(peer, afi, safi,
13487 PEER_FLAG_SEND_LARGE_COMMUNITY);
13488
13489 if (flag_scomm && flag_secomm && flag_slcomm) {
13490 vty_out(vty, " no neighbor %s send-community all\n", addr);
13491 } else {
13492 if (flag_scomm)
13493 vty_out(vty, " no neighbor %s send-community\n", addr);
13494 if (flag_secomm)
13495 vty_out(vty,
13496 " no neighbor %s send-community extended\n",
13497 addr);
13498
13499 if (flag_slcomm)
13500 vty_out(vty, " no neighbor %s send-community large\n",
13501 addr);
13502 }
13503
13504 /* Default information */
13505 if (peergroup_af_flag_check(peer, afi, safi,
13506 PEER_FLAG_DEFAULT_ORIGINATE)) {
13507 vty_out(vty, " neighbor %s default-originate", addr);
13508
13509 if (peer->default_rmap[afi][safi].name)
13510 vty_out(vty, " route-map %s",
13511 peer->default_rmap[afi][safi].name);
13512
13513 vty_out(vty, "\n");
13514 }
13515
13516 /* Soft reconfiguration inbound. */
13517 if (peergroup_af_flag_check(peer, afi, safi, PEER_FLAG_SOFT_RECONFIG)) {
13518 vty_out(vty, " neighbor %s soft-reconfiguration inbound\n",
13519 addr);
13520 }
13521
13522 /* maximum-prefix. */
13523 if (peergroup_af_flag_check(peer, afi, safi, PEER_FLAG_MAX_PREFIX)) {
13524 vty_out(vty, " neighbor %s maximum-prefix %" PRIu32, addr,
13525 peer->pmax[afi][safi]);
13526
13527 if (peer->pmax_threshold[afi][safi]
13528 != MAXIMUM_PREFIX_THRESHOLD_DEFAULT)
13529 vty_out(vty, " %u", peer->pmax_threshold[afi][safi]);
13530 if (peer_af_flag_check(peer, afi, safi,
13531 PEER_FLAG_MAX_PREFIX_WARNING))
13532 vty_out(vty, " warning-only");
13533 if (peer->pmax_restart[afi][safi])
13534 vty_out(vty, " restart %u",
13535 peer->pmax_restart[afi][safi]);
13536
13537 vty_out(vty, "\n");
13538 }
13539
13540 /* Route server client. */
13541 if (peergroup_af_flag_check(peer, afi, safi,
13542 PEER_FLAG_RSERVER_CLIENT)) {
13543 vty_out(vty, " neighbor %s route-server-client\n", addr);
13544 }
13545
13546 /* Nexthop-local unchanged. */
13547 if (peergroup_af_flag_check(peer, afi, safi,
13548 PEER_FLAG_NEXTHOP_LOCAL_UNCHANGED)) {
13549 vty_out(vty, " neighbor %s nexthop-local unchanged\n", addr);
13550 }
13551
13552 /* allowas-in <1-10> */
13553 if (peergroup_af_flag_check(peer, afi, safi, PEER_FLAG_ALLOWAS_IN)) {
13554 if (peer_af_flag_check(peer, afi, safi,
13555 PEER_FLAG_ALLOWAS_IN_ORIGIN)) {
13556 vty_out(vty, " neighbor %s allowas-in origin\n", addr);
13557 } else if (peer->allowas_in[afi][safi] == 3) {
13558 vty_out(vty, " neighbor %s allowas-in\n", addr);
13559 } else {
13560 vty_out(vty, " neighbor %s allowas-in %d\n", addr,
13561 peer->allowas_in[afi][safi]);
13562 }
13563 }
13564
13565 /* weight */
13566 if (peergroup_af_flag_check(peer, afi, safi, PEER_FLAG_WEIGHT))
13567 vty_out(vty, " neighbor %s weight %lu\n", addr,
13568 peer->weight[afi][safi]);
13569
13570 /* Filter. */
13571 bgp_config_write_filter(vty, peer, afi, safi);
13572
13573 /* atribute-unchanged. */
13574 if (peer_af_flag_check(peer, afi, safi, PEER_FLAG_AS_PATH_UNCHANGED)
13575 || (safi != SAFI_EVPN
13576 && peer_af_flag_check(peer, afi, safi,
13577 PEER_FLAG_NEXTHOP_UNCHANGED))
13578 || peer_af_flag_check(peer, afi, safi, PEER_FLAG_MED_UNCHANGED)) {
13579
13580 if (!peer_group_active(peer)
13581 || peergroup_af_flag_check(peer, afi, safi,
13582 PEER_FLAG_AS_PATH_UNCHANGED)
13583 || peergroup_af_flag_check(peer, afi, safi,
13584 PEER_FLAG_NEXTHOP_UNCHANGED)
13585 || peergroup_af_flag_check(peer, afi, safi,
13586 PEER_FLAG_MED_UNCHANGED)) {
13587
13588 vty_out(vty,
13589 " neighbor %s attribute-unchanged%s%s%s\n",
13590 addr,
13591 peer_af_flag_check(peer, afi, safi,
13592 PEER_FLAG_AS_PATH_UNCHANGED)
13593 ? " as-path"
13594 : "",
13595 peer_af_flag_check(peer, afi, safi,
13596 PEER_FLAG_NEXTHOP_UNCHANGED)
13597 ? " next-hop"
13598 : "",
13599 peer_af_flag_check(peer, afi, safi,
13600 PEER_FLAG_MED_UNCHANGED)
13601 ? " med"
13602 : "");
13603 }
13604 }
13605 }
13606
13607 /* Address family based peer configuration display. */
13608 static void bgp_config_write_family(struct vty *vty, struct bgp *bgp, afi_t afi,
13609 safi_t safi)
13610 {
13611 struct peer *peer;
13612 struct peer_group *group;
13613 struct listnode *node, *nnode;
13614
13615
13616 vty_frame(vty, " !\n address-family ");
13617 if (afi == AFI_IP) {
13618 if (safi == SAFI_UNICAST)
13619 vty_frame(vty, "ipv4 unicast");
13620 else if (safi == SAFI_LABELED_UNICAST)
13621 vty_frame(vty, "ipv4 labeled-unicast");
13622 else if (safi == SAFI_MULTICAST)
13623 vty_frame(vty, "ipv4 multicast");
13624 else if (safi == SAFI_MPLS_VPN)
13625 vty_frame(vty, "ipv4 vpn");
13626 else if (safi == SAFI_ENCAP)
13627 vty_frame(vty, "ipv4 encap");
13628 else if (safi == SAFI_FLOWSPEC)
13629 vty_frame(vty, "ipv4 flowspec");
13630 } else if (afi == AFI_IP6) {
13631 if (safi == SAFI_UNICAST)
13632 vty_frame(vty, "ipv6 unicast");
13633 else if (safi == SAFI_LABELED_UNICAST)
13634 vty_frame(vty, "ipv6 labeled-unicast");
13635 else if (safi == SAFI_MULTICAST)
13636 vty_frame(vty, "ipv6 multicast");
13637 else if (safi == SAFI_MPLS_VPN)
13638 vty_frame(vty, "ipv6 vpn");
13639 else if (safi == SAFI_ENCAP)
13640 vty_frame(vty, "ipv6 encap");
13641 else if (safi == SAFI_FLOWSPEC)
13642 vty_frame(vty, "ipv6 flowspec");
13643 } else if (afi == AFI_L2VPN) {
13644 if (safi == SAFI_EVPN)
13645 vty_frame(vty, "l2vpn evpn");
13646 }
13647 vty_frame(vty, "\n");
13648
13649 bgp_config_write_distance(vty, bgp, afi, safi);
13650
13651 bgp_config_write_network(vty, bgp, afi, safi);
13652
13653 bgp_config_write_redistribute(vty, bgp, afi, safi);
13654
13655 for (ALL_LIST_ELEMENTS(bgp->group, node, nnode, group))
13656 bgp_config_write_peer_af(vty, bgp, group->conf, afi, safi);
13657
13658 for (ALL_LIST_ELEMENTS(bgp->peer, node, nnode, peer)) {
13659 /* Skip dynamic neighbors. */
13660 if (peer_dynamic_neighbor(peer))
13661 continue;
13662
13663 /* Do not display doppelganger peers */
13664 if (CHECK_FLAG(peer->flags, PEER_FLAG_CONFIG_NODE))
13665 bgp_config_write_peer_af(vty, bgp, peer, afi, safi);
13666 }
13667
13668 bgp_config_write_maxpaths(vty, bgp, afi, safi);
13669 bgp_config_write_table_map(vty, bgp, afi, safi);
13670
13671 if (safi == SAFI_EVPN)
13672 bgp_config_write_evpn_info(vty, bgp, afi, safi);
13673
13674 if (safi == SAFI_FLOWSPEC)
13675 bgp_fs_config_write_pbr(vty, bgp, afi, safi);
13676
13677 if (safi == SAFI_UNICAST) {
13678 bgp_vpn_policy_config_write_afi(vty, bgp, afi);
13679 if (CHECK_FLAG(bgp->af_flags[afi][safi],
13680 BGP_CONFIG_VRF_TO_MPLSVPN_EXPORT)) {
13681
13682 vty_out(vty, " export vpn\n");
13683 }
13684 if (CHECK_FLAG(bgp->af_flags[afi][safi],
13685 BGP_CONFIG_MPLSVPN_TO_VRF_IMPORT)) {
13686
13687 vty_out(vty, " import vpn\n");
13688 }
13689 if (CHECK_FLAG(bgp->af_flags[afi][safi],
13690 BGP_CONFIG_VRF_TO_VRF_IMPORT)) {
13691 char *name;
13692
13693 for (ALL_LIST_ELEMENTS_RO(
13694 bgp->vpn_policy[afi].import_vrf, node,
13695 name))
13696 vty_out(vty, " import vrf %s\n", name);
13697 }
13698 }
13699
13700 vty_endframe(vty, " exit-address-family\n");
13701 }
13702
13703 int bgp_config_write(struct vty *vty)
13704 {
13705 struct bgp *bgp;
13706 struct peer_group *group;
13707 struct peer *peer;
13708 struct listnode *node, *nnode;
13709 struct listnode *mnode, *mnnode;
13710
13711 if (bm->rmap_update_timer != RMAP_DEFAULT_UPDATE_TIMER)
13712 vty_out(vty, "bgp route-map delay-timer %u\n",
13713 bm->rmap_update_timer);
13714
13715 /* BGP configuration. */
13716 for (ALL_LIST_ELEMENTS(bm->bgp, mnode, mnnode, bgp)) {
13717
13718 /* skip all auto created vrf as they dont have user config */
13719 if (CHECK_FLAG(bgp->vrf_flags, BGP_VRF_AUTO))
13720 continue;
13721
13722 /* Router bgp ASN */
13723 vty_out(vty, "router bgp %u", bgp->as);
13724
13725 if (bgp->name)
13726 vty_out(vty, " %s %s",
13727 (bgp->inst_type == BGP_INSTANCE_TYPE_VIEW)
13728 ? "view" : "vrf", bgp->name);
13729 vty_out(vty, "\n");
13730
13731 /* BGP fast-external-failover. */
13732 if (CHECK_FLAG(bgp->flags, BGP_FLAG_NO_FAST_EXT_FAILOVER))
13733 vty_out(vty, " no bgp fast-external-failover\n");
13734
13735 /* BGP router ID. */
13736 if (bgp->router_id_static.s_addr != 0)
13737 vty_out(vty, " bgp router-id %s\n",
13738 inet_ntoa(bgp->router_id_static));
13739
13740 /* BGP log-neighbor-changes. */
13741 if (!!bgp_flag_check(bgp, BGP_FLAG_LOG_NEIGHBOR_CHANGES)
13742 != DFLT_BGP_LOG_NEIGHBOR_CHANGES)
13743 vty_out(vty, " %sbgp log-neighbor-changes\n",
13744 bgp_flag_check(bgp,
13745 BGP_FLAG_LOG_NEIGHBOR_CHANGES)
13746 ? ""
13747 : "no ");
13748
13749 /* BGP configuration. */
13750 if (bgp_flag_check(bgp, BGP_FLAG_ALWAYS_COMPARE_MED))
13751 vty_out(vty, " bgp always-compare-med\n");
13752
13753 /* RFC8212 default eBGP policy. */
13754 if (bgp->ebgp_requires_policy
13755 == DEFAULT_EBGP_POLICY_ENABLED)
13756 vty_out(vty, " bgp ebgp-requires-policy\n");
13757
13758 /* draft-ietf-idr-deprecate-as-set-confed-set */
13759 if (bgp->reject_as_sets == BGP_REJECT_AS_SETS_ENABLED)
13760 vty_out(vty, " bgp reject-as-sets\n");
13761
13762 /* BGP default ipv4-unicast. */
13763 if (bgp_flag_check(bgp, BGP_FLAG_NO_DEFAULT_IPV4))
13764 vty_out(vty, " no bgp default ipv4-unicast\n");
13765
13766 /* BGP default local-preference. */
13767 if (bgp->default_local_pref != BGP_DEFAULT_LOCAL_PREF)
13768 vty_out(vty, " bgp default local-preference %u\n",
13769 bgp->default_local_pref);
13770
13771 /* BGP default show-hostname */
13772 if (!!bgp_flag_check(bgp, BGP_FLAG_SHOW_HOSTNAME)
13773 != DFLT_BGP_SHOW_HOSTNAME)
13774 vty_out(vty, " %sbgp default show-hostname\n",
13775 bgp_flag_check(bgp, BGP_FLAG_SHOW_HOSTNAME)
13776 ? ""
13777 : "no ");
13778
13779 /* BGP default subgroup-pkt-queue-max. */
13780 if (bgp->default_subgroup_pkt_queue_max
13781 != BGP_DEFAULT_SUBGROUP_PKT_QUEUE_MAX)
13782 vty_out(vty, " bgp default subgroup-pkt-queue-max %u\n",
13783 bgp->default_subgroup_pkt_queue_max);
13784
13785 /* BGP client-to-client reflection. */
13786 if (bgp_flag_check(bgp, BGP_FLAG_NO_CLIENT_TO_CLIENT))
13787 vty_out(vty, " no bgp client-to-client reflection\n");
13788
13789 /* BGP cluster ID. */
13790 if (CHECK_FLAG(bgp->config, BGP_CONFIG_CLUSTER_ID))
13791 vty_out(vty, " bgp cluster-id %s\n",
13792 inet_ntoa(bgp->cluster_id));
13793
13794 /* Disable ebgp connected nexthop check */
13795 if (bgp_flag_check(bgp, BGP_FLAG_DISABLE_NH_CONNECTED_CHK))
13796 vty_out(vty,
13797 " bgp disable-ebgp-connected-route-check\n");
13798
13799 /* Confederation identifier*/
13800 if (CHECK_FLAG(bgp->config, BGP_CONFIG_CONFEDERATION))
13801 vty_out(vty, " bgp confederation identifier %u\n",
13802 bgp->confed_id);
13803
13804 /* Confederation peer */
13805 if (bgp->confed_peers_cnt > 0) {
13806 int i;
13807
13808 vty_out(vty, " bgp confederation peers");
13809
13810 for (i = 0; i < bgp->confed_peers_cnt; i++)
13811 vty_out(vty, " %u", bgp->confed_peers[i]);
13812
13813 vty_out(vty, "\n");
13814 }
13815
13816 /* BGP deterministic-med. */
13817 if (!!bgp_flag_check(bgp, BGP_FLAG_DETERMINISTIC_MED)
13818 != DFLT_BGP_DETERMINISTIC_MED)
13819 vty_out(vty, " %sbgp deterministic-med\n",
13820 bgp_flag_check(bgp, BGP_FLAG_DETERMINISTIC_MED)
13821 ? ""
13822 : "no ");
13823
13824 /* BGP update-delay. */
13825 bgp_config_write_update_delay(vty, bgp);
13826
13827 if (bgp->v_maxmed_onstartup
13828 != BGP_MAXMED_ONSTARTUP_UNCONFIGURED) {
13829 vty_out(vty, " bgp max-med on-startup %u",
13830 bgp->v_maxmed_onstartup);
13831 if (bgp->maxmed_onstartup_value
13832 != BGP_MAXMED_VALUE_DEFAULT)
13833 vty_out(vty, " %u",
13834 bgp->maxmed_onstartup_value);
13835 vty_out(vty, "\n");
13836 }
13837 if (bgp->v_maxmed_admin != BGP_MAXMED_ADMIN_UNCONFIGURED) {
13838 vty_out(vty, " bgp max-med administrative");
13839 if (bgp->maxmed_admin_value != BGP_MAXMED_VALUE_DEFAULT)
13840 vty_out(vty, " %u", bgp->maxmed_admin_value);
13841 vty_out(vty, "\n");
13842 }
13843
13844 /* write quanta */
13845 bgp_config_write_wpkt_quanta(vty, bgp);
13846 /* read quanta */
13847 bgp_config_write_rpkt_quanta(vty, bgp);
13848
13849 /* coalesce time */
13850 bgp_config_write_coalesce_time(vty, bgp);
13851
13852 /* BGP graceful-restart. */
13853 if (bgp->stalepath_time != BGP_DEFAULT_STALEPATH_TIME)
13854 vty_out(vty,
13855 " bgp graceful-restart stalepath-time %u\n",
13856 bgp->stalepath_time);
13857 if (bgp->restart_time != BGP_DEFAULT_RESTART_TIME)
13858 vty_out(vty, " bgp graceful-restart restart-time %u\n",
13859 bgp->restart_time);
13860 if (bgp_flag_check(bgp, BGP_FLAG_GRACEFUL_RESTART))
13861 vty_out(vty, " bgp graceful-restart\n");
13862
13863 /* BGP graceful-shutdown */
13864 if (bgp_flag_check(bgp, BGP_FLAG_GRACEFUL_SHUTDOWN))
13865 vty_out(vty, " bgp graceful-shutdown\n");
13866
13867 /* BGP graceful-restart Preserve State F bit. */
13868 if (bgp_flag_check(bgp, BGP_FLAG_GR_PRESERVE_FWD))
13869 vty_out(vty,
13870 " bgp graceful-restart preserve-fw-state\n");
13871
13872 /* BGP bestpath method. */
13873 if (bgp_flag_check(bgp, BGP_FLAG_ASPATH_IGNORE))
13874 vty_out(vty, " bgp bestpath as-path ignore\n");
13875 if (bgp_flag_check(bgp, BGP_FLAG_ASPATH_CONFED))
13876 vty_out(vty, " bgp bestpath as-path confed\n");
13877
13878 if (bgp_flag_check(bgp, BGP_FLAG_ASPATH_MULTIPATH_RELAX)) {
13879 if (bgp_flag_check(bgp,
13880 BGP_FLAG_MULTIPATH_RELAX_AS_SET)) {
13881 vty_out(vty,
13882 " bgp bestpath as-path multipath-relax as-set\n");
13883 } else {
13884 vty_out(vty,
13885 " bgp bestpath as-path multipath-relax\n");
13886 }
13887 }
13888
13889 if (bgp_flag_check(bgp, BGP_FLAG_RR_ALLOW_OUTBOUND_POLICY)) {
13890 vty_out(vty,
13891 " bgp route-reflector allow-outbound-policy\n");
13892 }
13893 if (bgp_flag_check(bgp, BGP_FLAG_COMPARE_ROUTER_ID))
13894 vty_out(vty, " bgp bestpath compare-routerid\n");
13895 if (bgp_flag_check(bgp, BGP_FLAG_MED_CONFED)
13896 || bgp_flag_check(bgp, BGP_FLAG_MED_MISSING_AS_WORST)) {
13897 vty_out(vty, " bgp bestpath med");
13898 if (bgp_flag_check(bgp, BGP_FLAG_MED_CONFED))
13899 vty_out(vty, " confed");
13900 if (bgp_flag_check(bgp, BGP_FLAG_MED_MISSING_AS_WORST))
13901 vty_out(vty, " missing-as-worst");
13902 vty_out(vty, "\n");
13903 }
13904
13905 /* BGP network import check. */
13906 if (!!bgp_flag_check(bgp, BGP_FLAG_IMPORT_CHECK)
13907 != DFLT_BGP_IMPORT_CHECK)
13908 vty_out(vty, " %sbgp network import-check\n",
13909 bgp_flag_check(bgp, BGP_FLAG_IMPORT_CHECK)
13910 ? ""
13911 : "no ");
13912
13913 /* BGP timers configuration. */
13914 if (bgp->default_keepalive != BGP_DEFAULT_KEEPALIVE
13915 && bgp->default_holdtime != BGP_DEFAULT_HOLDTIME)
13916 vty_out(vty, " timers bgp %u %u\n",
13917 bgp->default_keepalive, bgp->default_holdtime);
13918
13919 /* peer-group */
13920 for (ALL_LIST_ELEMENTS(bgp->group, node, nnode, group)) {
13921 bgp_config_write_peer_global(vty, bgp, group->conf);
13922 }
13923
13924 /* Normal neighbor configuration. */
13925 for (ALL_LIST_ELEMENTS(bgp->peer, node, nnode, peer)) {
13926 if (CHECK_FLAG(peer->flags, PEER_FLAG_CONFIG_NODE))
13927 bgp_config_write_peer_global(vty, bgp, peer);
13928 }
13929
13930 /* listen range and limit for dynamic BGP neighbors */
13931 bgp_config_write_listen(vty, bgp);
13932
13933 /*
13934 * BGP default autoshutdown neighbors
13935 *
13936 * This must be placed after any peer and peer-group
13937 * configuration, to avoid setting all peers to shutdown after
13938 * a daemon restart, which is undesired behavior. (see #2286)
13939 */
13940 if (bgp->autoshutdown)
13941 vty_out(vty, " bgp default shutdown\n");
13942
13943 /* IPv4 unicast configuration. */
13944 bgp_config_write_family(vty, bgp, AFI_IP, SAFI_UNICAST);
13945
13946 /* IPv4 multicast configuration. */
13947 bgp_config_write_family(vty, bgp, AFI_IP, SAFI_MULTICAST);
13948
13949 /* IPv4 labeled-unicast configuration. */
13950 bgp_config_write_family(vty, bgp, AFI_IP, SAFI_LABELED_UNICAST);
13951
13952 /* IPv4 VPN configuration. */
13953 bgp_config_write_family(vty, bgp, AFI_IP, SAFI_MPLS_VPN);
13954
13955 /* ENCAPv4 configuration. */
13956 bgp_config_write_family(vty, bgp, AFI_IP, SAFI_ENCAP);
13957
13958 /* FLOWSPEC v4 configuration. */
13959 bgp_config_write_family(vty, bgp, AFI_IP, SAFI_FLOWSPEC);
13960
13961 /* IPv6 unicast configuration. */
13962 bgp_config_write_family(vty, bgp, AFI_IP6, SAFI_UNICAST);
13963
13964 /* IPv6 multicast configuration. */
13965 bgp_config_write_family(vty, bgp, AFI_IP6, SAFI_MULTICAST);
13966
13967 /* IPv6 labeled-unicast configuration. */
13968 bgp_config_write_family(vty, bgp, AFI_IP6,
13969 SAFI_LABELED_UNICAST);
13970
13971 /* IPv6 VPN configuration. */
13972 bgp_config_write_family(vty, bgp, AFI_IP6, SAFI_MPLS_VPN);
13973
13974 /* ENCAPv6 configuration. */
13975 bgp_config_write_family(vty, bgp, AFI_IP6, SAFI_ENCAP);
13976
13977 /* FLOWSPEC v6 configuration. */
13978 bgp_config_write_family(vty, bgp, AFI_IP6, SAFI_FLOWSPEC);
13979
13980 /* EVPN configuration. */
13981 bgp_config_write_family(vty, bgp, AFI_L2VPN, SAFI_EVPN);
13982
13983 hook_call(bgp_inst_config_write, bgp, vty);
13984
13985 #if ENABLE_BGP_VNC
13986 bgp_rfapi_cfg_write(vty, bgp);
13987 #endif
13988
13989 vty_out(vty, "!\n");
13990 }
13991 return 0;
13992 }
13993
13994
13995 /* BGP node structure. */
13996 static struct cmd_node bgp_node = {
13997 BGP_NODE, "%s(config-router)# ", 1,
13998 };
13999
14000 static struct cmd_node bgp_ipv4_unicast_node = {
14001 BGP_IPV4_NODE, "%s(config-router-af)# ", 1,
14002 };
14003
14004 static struct cmd_node bgp_ipv4_multicast_node = {
14005 BGP_IPV4M_NODE, "%s(config-router-af)# ", 1,
14006 };
14007
14008 static struct cmd_node bgp_ipv4_labeled_unicast_node = {
14009 BGP_IPV4L_NODE, "%s(config-router-af)# ", 1,
14010 };
14011
14012 static struct cmd_node bgp_ipv6_unicast_node = {
14013 BGP_IPV6_NODE, "%s(config-router-af)# ", 1,
14014 };
14015
14016 static struct cmd_node bgp_ipv6_multicast_node = {
14017 BGP_IPV6M_NODE, "%s(config-router-af)# ", 1,
14018 };
14019
14020 static struct cmd_node bgp_ipv6_labeled_unicast_node = {
14021 BGP_IPV6L_NODE, "%s(config-router-af)# ", 1,
14022 };
14023
14024 static struct cmd_node bgp_vpnv4_node = {BGP_VPNV4_NODE,
14025 "%s(config-router-af)# ", 1};
14026
14027 static struct cmd_node bgp_vpnv6_node = {BGP_VPNV6_NODE,
14028 "%s(config-router-af-vpnv6)# ", 1};
14029
14030 static struct cmd_node bgp_evpn_node = {BGP_EVPN_NODE,
14031 "%s(config-router-evpn)# ", 1};
14032
14033 static struct cmd_node bgp_evpn_vni_node = {BGP_EVPN_VNI_NODE,
14034 "%s(config-router-af-vni)# ", 1};
14035
14036 static struct cmd_node bgp_flowspecv4_node = {BGP_FLOWSPECV4_NODE,
14037 "%s(config-router-af)# ", 1};
14038
14039 static struct cmd_node bgp_flowspecv6_node = {BGP_FLOWSPECV6_NODE,
14040 "%s(config-router-af-vpnv6)# ", 1};
14041
14042 static void community_list_vty(void);
14043
14044 static void bgp_ac_neighbor(vector comps, struct cmd_token *token)
14045 {
14046 struct bgp *bgp;
14047 struct peer *peer;
14048 struct listnode *lnbgp, *lnpeer;
14049
14050 for (ALL_LIST_ELEMENTS_RO(bm->bgp, lnbgp, bgp)) {
14051 for (ALL_LIST_ELEMENTS_RO(bgp->peer, lnpeer, peer)) {
14052 /* only provide suggestions on the appropriate input
14053 * token type,
14054 * they'll otherwise show up multiple times */
14055 enum cmd_token_type match_type;
14056 char *name = peer->host;
14057
14058 if (peer->conf_if) {
14059 match_type = VARIABLE_TKN;
14060 name = peer->conf_if;
14061 } else if (strchr(peer->host, ':'))
14062 match_type = IPV6_TKN;
14063 else
14064 match_type = IPV4_TKN;
14065
14066 if (token->type != match_type)
14067 continue;
14068
14069 vector_set(comps, XSTRDUP(MTYPE_COMPLETION, name));
14070 }
14071 }
14072 }
14073
14074 static const struct cmd_variable_handler bgp_var_neighbor[] = {
14075 {.varname = "neighbor", .completions = bgp_ac_neighbor},
14076 {.varname = "neighbors", .completions = bgp_ac_neighbor},
14077 {.varname = "peer", .completions = bgp_ac_neighbor},
14078 {.completions = NULL}};
14079
14080 static void bgp_ac_peergroup(vector comps, struct cmd_token *token)
14081 {
14082 struct bgp *bgp;
14083 struct peer_group *group;
14084 struct listnode *lnbgp, *lnpeer;
14085
14086 for (ALL_LIST_ELEMENTS_RO(bm->bgp, lnbgp, bgp)) {
14087 for (ALL_LIST_ELEMENTS_RO(bgp->group, lnpeer, group))
14088 vector_set(comps, XSTRDUP(MTYPE_COMPLETION,
14089 group->name));
14090 }
14091 }
14092
14093 static const struct cmd_variable_handler bgp_var_peergroup[] = {
14094 {.tokenname = "PGNAME", .completions = bgp_ac_peergroup},
14095 {.completions = NULL} };
14096
14097 void bgp_vty_init(void)
14098 {
14099 cmd_variable_handler_register(bgp_var_neighbor);
14100 cmd_variable_handler_register(bgp_var_peergroup);
14101
14102 /* Install bgp top node. */
14103 install_node(&bgp_node, bgp_config_write);
14104 install_node(&bgp_ipv4_unicast_node, NULL);
14105 install_node(&bgp_ipv4_multicast_node, NULL);
14106 install_node(&bgp_ipv4_labeled_unicast_node, NULL);
14107 install_node(&bgp_ipv6_unicast_node, NULL);
14108 install_node(&bgp_ipv6_multicast_node, NULL);
14109 install_node(&bgp_ipv6_labeled_unicast_node, NULL);
14110 install_node(&bgp_vpnv4_node, NULL);
14111 install_node(&bgp_vpnv6_node, NULL);
14112 install_node(&bgp_evpn_node, NULL);
14113 install_node(&bgp_evpn_vni_node, NULL);
14114 install_node(&bgp_flowspecv4_node, NULL);
14115 install_node(&bgp_flowspecv6_node, NULL);
14116
14117 /* Install default VTY commands to new nodes. */
14118 install_default(BGP_NODE);
14119 install_default(BGP_IPV4_NODE);
14120 install_default(BGP_IPV4M_NODE);
14121 install_default(BGP_IPV4L_NODE);
14122 install_default(BGP_IPV6_NODE);
14123 install_default(BGP_IPV6M_NODE);
14124 install_default(BGP_IPV6L_NODE);
14125 install_default(BGP_VPNV4_NODE);
14126 install_default(BGP_VPNV6_NODE);
14127 install_default(BGP_FLOWSPECV4_NODE);
14128 install_default(BGP_FLOWSPECV6_NODE);
14129 install_default(BGP_EVPN_NODE);
14130 install_default(BGP_EVPN_VNI_NODE);
14131
14132 /* "bgp local-mac" hidden commands. */
14133 install_element(CONFIG_NODE, &bgp_local_mac_cmd);
14134 install_element(CONFIG_NODE, &no_bgp_local_mac_cmd);
14135
14136 /* bgp route-map delay-timer commands. */
14137 install_element(CONFIG_NODE, &bgp_set_route_map_delay_timer_cmd);
14138 install_element(CONFIG_NODE, &no_bgp_set_route_map_delay_timer_cmd);
14139
14140 /* Dummy commands (Currently not supported) */
14141 install_element(BGP_NODE, &no_synchronization_cmd);
14142 install_element(BGP_NODE, &no_auto_summary_cmd);
14143
14144 /* "router bgp" commands. */
14145 install_element(CONFIG_NODE, &router_bgp_cmd);
14146
14147 /* "no router bgp" commands. */
14148 install_element(CONFIG_NODE, &no_router_bgp_cmd);
14149
14150 /* "bgp router-id" commands. */
14151 install_element(BGP_NODE, &bgp_router_id_cmd);
14152 install_element(BGP_NODE, &no_bgp_router_id_cmd);
14153
14154 /* "bgp cluster-id" commands. */
14155 install_element(BGP_NODE, &bgp_cluster_id_cmd);
14156 install_element(BGP_NODE, &no_bgp_cluster_id_cmd);
14157
14158 /* "bgp confederation" commands. */
14159 install_element(BGP_NODE, &bgp_confederation_identifier_cmd);
14160 install_element(BGP_NODE, &no_bgp_confederation_identifier_cmd);
14161
14162 /* "bgp confederation peers" commands. */
14163 install_element(BGP_NODE, &bgp_confederation_peers_cmd);
14164 install_element(BGP_NODE, &no_bgp_confederation_peers_cmd);
14165
14166 /* bgp max-med command */
14167 install_element(BGP_NODE, &bgp_maxmed_admin_cmd);
14168 install_element(BGP_NODE, &no_bgp_maxmed_admin_cmd);
14169 install_element(BGP_NODE, &bgp_maxmed_admin_medv_cmd);
14170 install_element(BGP_NODE, &bgp_maxmed_onstartup_cmd);
14171 install_element(BGP_NODE, &no_bgp_maxmed_onstartup_cmd);
14172
14173 /* bgp disable-ebgp-connected-nh-check */
14174 install_element(BGP_NODE, &bgp_disable_connected_route_check_cmd);
14175 install_element(BGP_NODE, &no_bgp_disable_connected_route_check_cmd);
14176
14177 /* bgp update-delay command */
14178 install_element(BGP_NODE, &bgp_update_delay_cmd);
14179 install_element(BGP_NODE, &no_bgp_update_delay_cmd);
14180 install_element(BGP_NODE, &bgp_update_delay_establish_wait_cmd);
14181
14182 install_element(BGP_NODE, &bgp_wpkt_quanta_cmd);
14183 install_element(BGP_NODE, &bgp_rpkt_quanta_cmd);
14184
14185 install_element(BGP_NODE, &bgp_coalesce_time_cmd);
14186 install_element(BGP_NODE, &no_bgp_coalesce_time_cmd);
14187
14188 /* "maximum-paths" commands. */
14189 install_element(BGP_NODE, &bgp_maxpaths_hidden_cmd);
14190 install_element(BGP_NODE, &no_bgp_maxpaths_hidden_cmd);
14191 install_element(BGP_IPV4_NODE, &bgp_maxpaths_cmd);
14192 install_element(BGP_IPV4_NODE, &no_bgp_maxpaths_cmd);
14193 install_element(BGP_IPV6_NODE, &bgp_maxpaths_cmd);
14194 install_element(BGP_IPV6_NODE, &no_bgp_maxpaths_cmd);
14195 install_element(BGP_NODE, &bgp_maxpaths_ibgp_hidden_cmd);
14196 install_element(BGP_NODE, &bgp_maxpaths_ibgp_cluster_hidden_cmd);
14197 install_element(BGP_NODE, &no_bgp_maxpaths_ibgp_hidden_cmd);
14198 install_element(BGP_IPV4_NODE, &bgp_maxpaths_ibgp_cmd);
14199 install_element(BGP_IPV4_NODE, &bgp_maxpaths_ibgp_cluster_cmd);
14200 install_element(BGP_IPV4_NODE, &no_bgp_maxpaths_ibgp_cmd);
14201 install_element(BGP_IPV6_NODE, &bgp_maxpaths_ibgp_cmd);
14202 install_element(BGP_IPV6_NODE, &bgp_maxpaths_ibgp_cluster_cmd);
14203 install_element(BGP_IPV6_NODE, &no_bgp_maxpaths_ibgp_cmd);
14204
14205 install_element(BGP_IPV6L_NODE, &bgp_maxpaths_cmd);
14206 install_element(BGP_IPV6L_NODE, &no_bgp_maxpaths_cmd);
14207 install_element(BGP_IPV6L_NODE, &bgp_maxpaths_ibgp_cmd);
14208 install_element(BGP_IPV6L_NODE, &bgp_maxpaths_ibgp_cluster_cmd);
14209 install_element(BGP_IPV6L_NODE, &no_bgp_maxpaths_ibgp_cmd);
14210
14211 /* "timers bgp" commands. */
14212 install_element(BGP_NODE, &bgp_timers_cmd);
14213 install_element(BGP_NODE, &no_bgp_timers_cmd);
14214
14215 /* route-map delay-timer commands - per instance for backwards compat.
14216 */
14217 install_element(BGP_NODE, &bgp_set_route_map_delay_timer_cmd);
14218 install_element(BGP_NODE, &no_bgp_set_route_map_delay_timer_cmd);
14219
14220 /* "bgp client-to-client reflection" commands */
14221 install_element(BGP_NODE, &no_bgp_client_to_client_reflection_cmd);
14222 install_element(BGP_NODE, &bgp_client_to_client_reflection_cmd);
14223
14224 /* "bgp always-compare-med" commands */
14225 install_element(BGP_NODE, &bgp_always_compare_med_cmd);
14226 install_element(BGP_NODE, &no_bgp_always_compare_med_cmd);
14227
14228 /* bgp ebgp-requires-policy */
14229 install_element(BGP_NODE, &bgp_ebgp_requires_policy_cmd);
14230 install_element(BGP_NODE, &no_bgp_ebgp_requires_policy_cmd);
14231
14232 /* bgp reject-as-sets */
14233 install_element(BGP_NODE, &bgp_reject_as_sets_cmd);
14234 install_element(BGP_NODE, &no_bgp_reject_as_sets_cmd);
14235
14236 /* "bgp deterministic-med" commands */
14237 install_element(BGP_NODE, &bgp_deterministic_med_cmd);
14238 install_element(BGP_NODE, &no_bgp_deterministic_med_cmd);
14239
14240 /* "bgp graceful-restart" commands */
14241 install_element(BGP_NODE, &bgp_graceful_restart_cmd);
14242 install_element(BGP_NODE, &no_bgp_graceful_restart_cmd);
14243 install_element(BGP_NODE, &bgp_graceful_restart_stalepath_time_cmd);
14244 install_element(BGP_NODE, &no_bgp_graceful_restart_stalepath_time_cmd);
14245 install_element(BGP_NODE, &bgp_graceful_restart_restart_time_cmd);
14246 install_element(BGP_NODE, &no_bgp_graceful_restart_restart_time_cmd);
14247
14248 install_element(BGP_NODE, &bgp_graceful_restart_preserve_fw_cmd);
14249 install_element(BGP_NODE, &no_bgp_graceful_restart_preserve_fw_cmd);
14250
14251 /* "bgp graceful-shutdown" commands */
14252 install_element(BGP_NODE, &bgp_graceful_shutdown_cmd);
14253 install_element(BGP_NODE, &no_bgp_graceful_shutdown_cmd);
14254
14255 /* "bgp fast-external-failover" commands */
14256 install_element(BGP_NODE, &bgp_fast_external_failover_cmd);
14257 install_element(BGP_NODE, &no_bgp_fast_external_failover_cmd);
14258
14259 /* "bgp bestpath compare-routerid" commands */
14260 install_element(BGP_NODE, &bgp_bestpath_compare_router_id_cmd);
14261 install_element(BGP_NODE, &no_bgp_bestpath_compare_router_id_cmd);
14262
14263 /* "bgp bestpath as-path ignore" commands */
14264 install_element(BGP_NODE, &bgp_bestpath_aspath_ignore_cmd);
14265 install_element(BGP_NODE, &no_bgp_bestpath_aspath_ignore_cmd);
14266
14267 /* "bgp bestpath as-path confed" commands */
14268 install_element(BGP_NODE, &bgp_bestpath_aspath_confed_cmd);
14269 install_element(BGP_NODE, &no_bgp_bestpath_aspath_confed_cmd);
14270
14271 /* "bgp bestpath as-path multipath-relax" commands */
14272 install_element(BGP_NODE, &bgp_bestpath_aspath_multipath_relax_cmd);
14273 install_element(BGP_NODE, &no_bgp_bestpath_aspath_multipath_relax_cmd);
14274
14275 /* "bgp log-neighbor-changes" commands */
14276 install_element(BGP_NODE, &bgp_log_neighbor_changes_cmd);
14277 install_element(BGP_NODE, &no_bgp_log_neighbor_changes_cmd);
14278
14279 /* "bgp bestpath med" commands */
14280 install_element(BGP_NODE, &bgp_bestpath_med_cmd);
14281 install_element(BGP_NODE, &no_bgp_bestpath_med_cmd);
14282
14283 /* "no bgp default ipv4-unicast" commands. */
14284 install_element(BGP_NODE, &no_bgp_default_ipv4_unicast_cmd);
14285 install_element(BGP_NODE, &bgp_default_ipv4_unicast_cmd);
14286
14287 /* "bgp network import-check" commands. */
14288 install_element(BGP_NODE, &bgp_network_import_check_cmd);
14289 install_element(BGP_NODE, &bgp_network_import_check_exact_cmd);
14290 install_element(BGP_NODE, &no_bgp_network_import_check_cmd);
14291
14292 /* "bgp default local-preference" commands. */
14293 install_element(BGP_NODE, &bgp_default_local_preference_cmd);
14294 install_element(BGP_NODE, &no_bgp_default_local_preference_cmd);
14295
14296 /* bgp default show-hostname */
14297 install_element(BGP_NODE, &bgp_default_show_hostname_cmd);
14298 install_element(BGP_NODE, &no_bgp_default_show_hostname_cmd);
14299
14300 /* "bgp default subgroup-pkt-queue-max" commands. */
14301 install_element(BGP_NODE, &bgp_default_subgroup_pkt_queue_max_cmd);
14302 install_element(BGP_NODE, &no_bgp_default_subgroup_pkt_queue_max_cmd);
14303
14304 /* bgp ibgp-allow-policy-mods command */
14305 install_element(BGP_NODE, &bgp_rr_allow_outbound_policy_cmd);
14306 install_element(BGP_NODE, &no_bgp_rr_allow_outbound_policy_cmd);
14307
14308 /* "bgp listen limit" commands. */
14309 install_element(BGP_NODE, &bgp_listen_limit_cmd);
14310 install_element(BGP_NODE, &no_bgp_listen_limit_cmd);
14311
14312 /* "bgp listen range" commands. */
14313 install_element(BGP_NODE, &bgp_listen_range_cmd);
14314 install_element(BGP_NODE, &no_bgp_listen_range_cmd);
14315
14316 /* "bgp default shutdown" command */
14317 install_element(BGP_NODE, &bgp_default_shutdown_cmd);
14318
14319 /* "neighbor remote-as" commands. */
14320 install_element(BGP_NODE, &neighbor_remote_as_cmd);
14321 install_element(BGP_NODE, &neighbor_interface_config_cmd);
14322 install_element(BGP_NODE, &neighbor_interface_config_v6only_cmd);
14323 install_element(BGP_NODE, &neighbor_interface_config_remote_as_cmd);
14324 install_element(BGP_NODE,
14325 &neighbor_interface_v6only_config_remote_as_cmd);
14326 install_element(BGP_NODE, &no_neighbor_cmd);
14327 install_element(BGP_NODE, &no_neighbor_interface_config_cmd);
14328
14329 /* "neighbor peer-group" commands. */
14330 install_element(BGP_NODE, &neighbor_peer_group_cmd);
14331 install_element(BGP_NODE, &no_neighbor_peer_group_cmd);
14332 install_element(BGP_NODE,
14333 &no_neighbor_interface_peer_group_remote_as_cmd);
14334
14335 /* "neighbor local-as" commands. */
14336 install_element(BGP_NODE, &neighbor_local_as_cmd);
14337 install_element(BGP_NODE, &neighbor_local_as_no_prepend_cmd);
14338 install_element(BGP_NODE, &neighbor_local_as_no_prepend_replace_as_cmd);
14339 install_element(BGP_NODE, &no_neighbor_local_as_cmd);
14340
14341 /* "neighbor solo" commands. */
14342 install_element(BGP_NODE, &neighbor_solo_cmd);
14343 install_element(BGP_NODE, &no_neighbor_solo_cmd);
14344
14345 /* "neighbor password" commands. */
14346 install_element(BGP_NODE, &neighbor_password_cmd);
14347 install_element(BGP_NODE, &no_neighbor_password_cmd);
14348
14349 /* "neighbor activate" commands. */
14350 install_element(BGP_NODE, &neighbor_activate_hidden_cmd);
14351 install_element(BGP_IPV4_NODE, &neighbor_activate_cmd);
14352 install_element(BGP_IPV4M_NODE, &neighbor_activate_cmd);
14353 install_element(BGP_IPV4L_NODE, &neighbor_activate_cmd);
14354 install_element(BGP_IPV6_NODE, &neighbor_activate_cmd);
14355 install_element(BGP_IPV6M_NODE, &neighbor_activate_cmd);
14356 install_element(BGP_IPV6L_NODE, &neighbor_activate_cmd);
14357 install_element(BGP_VPNV4_NODE, &neighbor_activate_cmd);
14358 install_element(BGP_VPNV6_NODE, &neighbor_activate_cmd);
14359 install_element(BGP_FLOWSPECV4_NODE, &neighbor_activate_cmd);
14360 install_element(BGP_FLOWSPECV6_NODE, &neighbor_activate_cmd);
14361 install_element(BGP_EVPN_NODE, &neighbor_activate_cmd);
14362
14363 /* "no neighbor activate" commands. */
14364 install_element(BGP_NODE, &no_neighbor_activate_hidden_cmd);
14365 install_element(BGP_IPV4_NODE, &no_neighbor_activate_cmd);
14366 install_element(BGP_IPV4M_NODE, &no_neighbor_activate_cmd);
14367 install_element(BGP_IPV4L_NODE, &no_neighbor_activate_cmd);
14368 install_element(BGP_IPV6_NODE, &no_neighbor_activate_cmd);
14369 install_element(BGP_IPV6M_NODE, &no_neighbor_activate_cmd);
14370 install_element(BGP_IPV6L_NODE, &no_neighbor_activate_cmd);
14371 install_element(BGP_VPNV4_NODE, &no_neighbor_activate_cmd);
14372 install_element(BGP_VPNV6_NODE, &no_neighbor_activate_cmd);
14373 install_element(BGP_FLOWSPECV4_NODE, &no_neighbor_activate_cmd);
14374 install_element(BGP_FLOWSPECV6_NODE, &no_neighbor_activate_cmd);
14375 install_element(BGP_EVPN_NODE, &no_neighbor_activate_cmd);
14376
14377 /* "neighbor peer-group" set commands. */
14378 install_element(BGP_NODE, &neighbor_set_peer_group_cmd);
14379 install_element(BGP_IPV4_NODE, &neighbor_set_peer_group_hidden_cmd);
14380 install_element(BGP_IPV4M_NODE, &neighbor_set_peer_group_hidden_cmd);
14381 install_element(BGP_IPV6_NODE, &neighbor_set_peer_group_hidden_cmd);
14382 install_element(BGP_IPV6M_NODE, &neighbor_set_peer_group_hidden_cmd);
14383 install_element(BGP_IPV6L_NODE, &neighbor_set_peer_group_hidden_cmd);
14384 install_element(BGP_VPNV4_NODE, &neighbor_set_peer_group_hidden_cmd);
14385 install_element(BGP_VPNV6_NODE, &neighbor_set_peer_group_hidden_cmd);
14386 install_element(BGP_FLOWSPECV4_NODE,
14387 &neighbor_set_peer_group_hidden_cmd);
14388 install_element(BGP_FLOWSPECV6_NODE,
14389 &neighbor_set_peer_group_hidden_cmd);
14390
14391 /* "no neighbor peer-group unset" commands. */
14392 install_element(BGP_NODE, &no_neighbor_set_peer_group_cmd);
14393 install_element(BGP_IPV4_NODE, &no_neighbor_set_peer_group_hidden_cmd);
14394 install_element(BGP_IPV4M_NODE, &no_neighbor_set_peer_group_hidden_cmd);
14395 install_element(BGP_IPV6_NODE, &no_neighbor_set_peer_group_hidden_cmd);
14396 install_element(BGP_IPV6M_NODE, &no_neighbor_set_peer_group_hidden_cmd);
14397 install_element(BGP_IPV6L_NODE, &no_neighbor_set_peer_group_hidden_cmd);
14398 install_element(BGP_VPNV4_NODE, &no_neighbor_set_peer_group_hidden_cmd);
14399 install_element(BGP_VPNV6_NODE, &no_neighbor_set_peer_group_hidden_cmd);
14400 install_element(BGP_FLOWSPECV4_NODE,
14401 &no_neighbor_set_peer_group_hidden_cmd);
14402 install_element(BGP_FLOWSPECV6_NODE,
14403 &no_neighbor_set_peer_group_hidden_cmd);
14404
14405 /* "neighbor softreconfiguration inbound" commands.*/
14406 install_element(BGP_NODE, &neighbor_soft_reconfiguration_hidden_cmd);
14407 install_element(BGP_NODE, &no_neighbor_soft_reconfiguration_hidden_cmd);
14408 install_element(BGP_IPV4_NODE, &neighbor_soft_reconfiguration_cmd);
14409 install_element(BGP_IPV4_NODE, &no_neighbor_soft_reconfiguration_cmd);
14410 install_element(BGP_IPV4L_NODE, &neighbor_soft_reconfiguration_cmd);
14411 install_element(BGP_IPV4L_NODE, &no_neighbor_soft_reconfiguration_cmd);
14412 install_element(BGP_IPV4M_NODE, &neighbor_soft_reconfiguration_cmd);
14413 install_element(BGP_IPV4M_NODE, &no_neighbor_soft_reconfiguration_cmd);
14414 install_element(BGP_IPV6_NODE, &neighbor_soft_reconfiguration_cmd);
14415 install_element(BGP_IPV6_NODE, &no_neighbor_soft_reconfiguration_cmd);
14416 install_element(BGP_IPV6M_NODE, &neighbor_soft_reconfiguration_cmd);
14417 install_element(BGP_IPV6M_NODE, &no_neighbor_soft_reconfiguration_cmd);
14418 install_element(BGP_IPV6L_NODE, &neighbor_soft_reconfiguration_cmd);
14419 install_element(BGP_IPV6L_NODE, &no_neighbor_soft_reconfiguration_cmd);
14420 install_element(BGP_VPNV4_NODE, &neighbor_soft_reconfiguration_cmd);
14421 install_element(BGP_VPNV4_NODE, &no_neighbor_soft_reconfiguration_cmd);
14422 install_element(BGP_VPNV6_NODE, &neighbor_soft_reconfiguration_cmd);
14423 install_element(BGP_VPNV6_NODE, &no_neighbor_soft_reconfiguration_cmd);
14424 install_element(BGP_FLOWSPECV4_NODE,
14425 &neighbor_soft_reconfiguration_cmd);
14426 install_element(BGP_FLOWSPECV4_NODE,
14427 &no_neighbor_soft_reconfiguration_cmd);
14428 install_element(BGP_FLOWSPECV6_NODE,
14429 &neighbor_soft_reconfiguration_cmd);
14430 install_element(BGP_FLOWSPECV6_NODE,
14431 &no_neighbor_soft_reconfiguration_cmd);
14432 install_element(BGP_EVPN_NODE, &neighbor_soft_reconfiguration_cmd);
14433 install_element(BGP_EVPN_NODE, &no_neighbor_soft_reconfiguration_cmd);
14434
14435 /* "neighbor attribute-unchanged" commands. */
14436 install_element(BGP_NODE, &neighbor_attr_unchanged_hidden_cmd);
14437 install_element(BGP_NODE, &no_neighbor_attr_unchanged_hidden_cmd);
14438 install_element(BGP_IPV4_NODE, &neighbor_attr_unchanged_cmd);
14439 install_element(BGP_IPV4_NODE, &no_neighbor_attr_unchanged_cmd);
14440 install_element(BGP_IPV4M_NODE, &neighbor_attr_unchanged_cmd);
14441 install_element(BGP_IPV4M_NODE, &no_neighbor_attr_unchanged_cmd);
14442 install_element(BGP_IPV4L_NODE, &neighbor_attr_unchanged_cmd);
14443 install_element(BGP_IPV4L_NODE, &no_neighbor_attr_unchanged_cmd);
14444 install_element(BGP_IPV6_NODE, &neighbor_attr_unchanged_cmd);
14445 install_element(BGP_IPV6_NODE, &no_neighbor_attr_unchanged_cmd);
14446 install_element(BGP_IPV6M_NODE, &neighbor_attr_unchanged_cmd);
14447 install_element(BGP_IPV6M_NODE, &no_neighbor_attr_unchanged_cmd);
14448 install_element(BGP_IPV6L_NODE, &neighbor_attr_unchanged_cmd);
14449 install_element(BGP_IPV6L_NODE, &no_neighbor_attr_unchanged_cmd);
14450 install_element(BGP_VPNV4_NODE, &neighbor_attr_unchanged_cmd);
14451 install_element(BGP_VPNV4_NODE, &no_neighbor_attr_unchanged_cmd);
14452 install_element(BGP_VPNV6_NODE, &neighbor_attr_unchanged_cmd);
14453 install_element(BGP_VPNV6_NODE, &no_neighbor_attr_unchanged_cmd);
14454
14455 install_element(BGP_EVPN_NODE, &neighbor_attr_unchanged_cmd);
14456 install_element(BGP_EVPN_NODE, &no_neighbor_attr_unchanged_cmd);
14457
14458 /* "nexthop-local unchanged" commands */
14459 install_element(BGP_IPV6_NODE, &neighbor_nexthop_local_unchanged_cmd);
14460 install_element(BGP_IPV6_NODE,
14461 &no_neighbor_nexthop_local_unchanged_cmd);
14462
14463 /* "neighbor next-hop-self" commands. */
14464 install_element(BGP_NODE, &neighbor_nexthop_self_hidden_cmd);
14465 install_element(BGP_NODE, &no_neighbor_nexthop_self_hidden_cmd);
14466 install_element(BGP_IPV4_NODE, &neighbor_nexthop_self_cmd);
14467 install_element(BGP_IPV4_NODE, &no_neighbor_nexthop_self_cmd);
14468 install_element(BGP_IPV4M_NODE, &neighbor_nexthop_self_cmd);
14469 install_element(BGP_IPV4M_NODE, &no_neighbor_nexthop_self_cmd);
14470 install_element(BGP_IPV4L_NODE, &neighbor_nexthop_self_cmd);
14471 install_element(BGP_IPV4L_NODE, &no_neighbor_nexthop_self_cmd);
14472 install_element(BGP_IPV6_NODE, &neighbor_nexthop_self_cmd);
14473 install_element(BGP_IPV6_NODE, &no_neighbor_nexthop_self_cmd);
14474 install_element(BGP_IPV6M_NODE, &neighbor_nexthop_self_cmd);
14475 install_element(BGP_IPV6M_NODE, &no_neighbor_nexthop_self_cmd);
14476 install_element(BGP_IPV6L_NODE, &neighbor_nexthop_self_cmd);
14477 install_element(BGP_IPV6L_NODE, &no_neighbor_nexthop_self_cmd);
14478 install_element(BGP_VPNV4_NODE, &neighbor_nexthop_self_cmd);
14479 install_element(BGP_VPNV4_NODE, &no_neighbor_nexthop_self_cmd);
14480 install_element(BGP_VPNV6_NODE, &neighbor_nexthop_self_cmd);
14481 install_element(BGP_VPNV6_NODE, &no_neighbor_nexthop_self_cmd);
14482 install_element(BGP_EVPN_NODE, &neighbor_nexthop_self_cmd);
14483 install_element(BGP_EVPN_NODE, &no_neighbor_nexthop_self_cmd);
14484
14485 /* "neighbor next-hop-self force" commands. */
14486 install_element(BGP_NODE, &neighbor_nexthop_self_force_hidden_cmd);
14487 install_element(BGP_NODE, &no_neighbor_nexthop_self_force_hidden_cmd);
14488 install_element(BGP_NODE, &neighbor_nexthop_self_all_hidden_cmd);
14489 install_element(BGP_NODE, &no_neighbor_nexthop_self_all_hidden_cmd);
14490 install_element(BGP_IPV4_NODE, &neighbor_nexthop_self_force_cmd);
14491 install_element(BGP_IPV4_NODE, &no_neighbor_nexthop_self_force_cmd);
14492 install_element(BGP_IPV4_NODE, &neighbor_nexthop_self_all_hidden_cmd);
14493 install_element(BGP_IPV4_NODE,
14494 &no_neighbor_nexthop_self_all_hidden_cmd);
14495 install_element(BGP_IPV4M_NODE, &neighbor_nexthop_self_force_cmd);
14496 install_element(BGP_IPV4M_NODE, &no_neighbor_nexthop_self_force_cmd);
14497 install_element(BGP_IPV4M_NODE, &neighbor_nexthop_self_all_hidden_cmd);
14498 install_element(BGP_IPV4M_NODE,
14499 &no_neighbor_nexthop_self_all_hidden_cmd);
14500 install_element(BGP_IPV4L_NODE, &neighbor_nexthop_self_force_cmd);
14501 install_element(BGP_IPV4L_NODE, &no_neighbor_nexthop_self_force_cmd);
14502 install_element(BGP_IPV4L_NODE, &neighbor_nexthop_self_all_hidden_cmd);
14503 install_element(BGP_IPV4L_NODE,
14504 &no_neighbor_nexthop_self_all_hidden_cmd);
14505 install_element(BGP_IPV6_NODE, &neighbor_nexthop_self_force_cmd);
14506 install_element(BGP_IPV6_NODE, &no_neighbor_nexthop_self_force_cmd);
14507 install_element(BGP_IPV6_NODE, &neighbor_nexthop_self_all_hidden_cmd);
14508 install_element(BGP_IPV6_NODE,
14509 &no_neighbor_nexthop_self_all_hidden_cmd);
14510 install_element(BGP_IPV6M_NODE, &neighbor_nexthop_self_force_cmd);
14511 install_element(BGP_IPV6M_NODE, &no_neighbor_nexthop_self_force_cmd);
14512 install_element(BGP_IPV6M_NODE, &neighbor_nexthop_self_all_hidden_cmd);
14513 install_element(BGP_IPV6M_NODE,
14514 &no_neighbor_nexthop_self_all_hidden_cmd);
14515 install_element(BGP_IPV6L_NODE, &neighbor_nexthop_self_force_cmd);
14516 install_element(BGP_IPV6L_NODE, &no_neighbor_nexthop_self_force_cmd);
14517 install_element(BGP_IPV6L_NODE, &neighbor_nexthop_self_all_hidden_cmd);
14518 install_element(BGP_IPV6L_NODE,
14519 &no_neighbor_nexthop_self_all_hidden_cmd);
14520 install_element(BGP_VPNV4_NODE, &neighbor_nexthop_self_force_cmd);
14521 install_element(BGP_VPNV4_NODE, &no_neighbor_nexthop_self_force_cmd);
14522 install_element(BGP_VPNV4_NODE, &neighbor_nexthop_self_all_hidden_cmd);
14523 install_element(BGP_VPNV4_NODE,
14524 &no_neighbor_nexthop_self_all_hidden_cmd);
14525 install_element(BGP_VPNV6_NODE, &neighbor_nexthop_self_force_cmd);
14526 install_element(BGP_VPNV6_NODE, &no_neighbor_nexthop_self_force_cmd);
14527 install_element(BGP_VPNV6_NODE, &neighbor_nexthop_self_all_hidden_cmd);
14528 install_element(BGP_VPNV6_NODE,
14529 &no_neighbor_nexthop_self_all_hidden_cmd);
14530
14531 /* "neighbor as-override" commands. */
14532 install_element(BGP_NODE, &neighbor_as_override_hidden_cmd);
14533 install_element(BGP_NODE, &no_neighbor_as_override_hidden_cmd);
14534 install_element(BGP_IPV4_NODE, &neighbor_as_override_cmd);
14535 install_element(BGP_IPV4_NODE, &no_neighbor_as_override_cmd);
14536 install_element(BGP_IPV4M_NODE, &neighbor_as_override_cmd);
14537 install_element(BGP_IPV4M_NODE, &no_neighbor_as_override_cmd);
14538 install_element(BGP_IPV4L_NODE, &neighbor_as_override_cmd);
14539 install_element(BGP_IPV4L_NODE, &no_neighbor_as_override_cmd);
14540 install_element(BGP_IPV6_NODE, &neighbor_as_override_cmd);
14541 install_element(BGP_IPV6_NODE, &no_neighbor_as_override_cmd);
14542 install_element(BGP_IPV6M_NODE, &neighbor_as_override_cmd);
14543 install_element(BGP_IPV6M_NODE, &no_neighbor_as_override_cmd);
14544 install_element(BGP_IPV6L_NODE, &neighbor_as_override_cmd);
14545 install_element(BGP_IPV6L_NODE, &no_neighbor_as_override_cmd);
14546 install_element(BGP_VPNV4_NODE, &neighbor_as_override_cmd);
14547 install_element(BGP_VPNV4_NODE, &no_neighbor_as_override_cmd);
14548 install_element(BGP_VPNV6_NODE, &neighbor_as_override_cmd);
14549 install_element(BGP_VPNV6_NODE, &no_neighbor_as_override_cmd);
14550
14551 /* "neighbor remove-private-AS" commands. */
14552 install_element(BGP_NODE, &neighbor_remove_private_as_hidden_cmd);
14553 install_element(BGP_NODE, &no_neighbor_remove_private_as_hidden_cmd);
14554 install_element(BGP_NODE, &neighbor_remove_private_as_all_hidden_cmd);
14555 install_element(BGP_NODE,
14556 &no_neighbor_remove_private_as_all_hidden_cmd);
14557 install_element(BGP_NODE,
14558 &neighbor_remove_private_as_replace_as_hidden_cmd);
14559 install_element(BGP_NODE,
14560 &no_neighbor_remove_private_as_replace_as_hidden_cmd);
14561 install_element(BGP_NODE,
14562 &neighbor_remove_private_as_all_replace_as_hidden_cmd);
14563 install_element(
14564 BGP_NODE,
14565 &no_neighbor_remove_private_as_all_replace_as_hidden_cmd);
14566 install_element(BGP_IPV4_NODE, &neighbor_remove_private_as_cmd);
14567 install_element(BGP_IPV4_NODE, &no_neighbor_remove_private_as_cmd);
14568 install_element(BGP_IPV4_NODE, &neighbor_remove_private_as_all_cmd);
14569 install_element(BGP_IPV4_NODE, &no_neighbor_remove_private_as_all_cmd);
14570 install_element(BGP_IPV4_NODE,
14571 &neighbor_remove_private_as_replace_as_cmd);
14572 install_element(BGP_IPV4_NODE,
14573 &no_neighbor_remove_private_as_replace_as_cmd);
14574 install_element(BGP_IPV4_NODE,
14575 &neighbor_remove_private_as_all_replace_as_cmd);
14576 install_element(BGP_IPV4_NODE,
14577 &no_neighbor_remove_private_as_all_replace_as_cmd);
14578 install_element(BGP_IPV4M_NODE, &neighbor_remove_private_as_cmd);
14579 install_element(BGP_IPV4M_NODE, &no_neighbor_remove_private_as_cmd);
14580 install_element(BGP_IPV4M_NODE, &neighbor_remove_private_as_all_cmd);
14581 install_element(BGP_IPV4M_NODE, &no_neighbor_remove_private_as_all_cmd);
14582 install_element(BGP_IPV4M_NODE,
14583 &neighbor_remove_private_as_replace_as_cmd);
14584 install_element(BGP_IPV4M_NODE,
14585 &no_neighbor_remove_private_as_replace_as_cmd);
14586 install_element(BGP_IPV4M_NODE,
14587 &neighbor_remove_private_as_all_replace_as_cmd);
14588 install_element(BGP_IPV4M_NODE,
14589 &no_neighbor_remove_private_as_all_replace_as_cmd);
14590 install_element(BGP_IPV4L_NODE, &neighbor_remove_private_as_cmd);
14591 install_element(BGP_IPV4L_NODE, &no_neighbor_remove_private_as_cmd);
14592 install_element(BGP_IPV4L_NODE, &neighbor_remove_private_as_all_cmd);
14593 install_element(BGP_IPV4L_NODE, &no_neighbor_remove_private_as_all_cmd);
14594 install_element(BGP_IPV4L_NODE,
14595 &neighbor_remove_private_as_replace_as_cmd);
14596 install_element(BGP_IPV4L_NODE,
14597 &no_neighbor_remove_private_as_replace_as_cmd);
14598 install_element(BGP_IPV4L_NODE,
14599 &neighbor_remove_private_as_all_replace_as_cmd);
14600 install_element(BGP_IPV4L_NODE,
14601 &no_neighbor_remove_private_as_all_replace_as_cmd);
14602 install_element(BGP_IPV6_NODE, &neighbor_remove_private_as_cmd);
14603 install_element(BGP_IPV6_NODE, &no_neighbor_remove_private_as_cmd);
14604 install_element(BGP_IPV6_NODE, &neighbor_remove_private_as_all_cmd);
14605 install_element(BGP_IPV6_NODE, &no_neighbor_remove_private_as_all_cmd);
14606 install_element(BGP_IPV6_NODE,
14607 &neighbor_remove_private_as_replace_as_cmd);
14608 install_element(BGP_IPV6_NODE,
14609 &no_neighbor_remove_private_as_replace_as_cmd);
14610 install_element(BGP_IPV6_NODE,
14611 &neighbor_remove_private_as_all_replace_as_cmd);
14612 install_element(BGP_IPV6_NODE,
14613 &no_neighbor_remove_private_as_all_replace_as_cmd);
14614 install_element(BGP_IPV6M_NODE, &neighbor_remove_private_as_cmd);
14615 install_element(BGP_IPV6M_NODE, &no_neighbor_remove_private_as_cmd);
14616 install_element(BGP_IPV6M_NODE, &neighbor_remove_private_as_all_cmd);
14617 install_element(BGP_IPV6M_NODE, &no_neighbor_remove_private_as_all_cmd);
14618 install_element(BGP_IPV6M_NODE,
14619 &neighbor_remove_private_as_replace_as_cmd);
14620 install_element(BGP_IPV6M_NODE,
14621 &no_neighbor_remove_private_as_replace_as_cmd);
14622 install_element(BGP_IPV6M_NODE,
14623 &neighbor_remove_private_as_all_replace_as_cmd);
14624 install_element(BGP_IPV6M_NODE,
14625 &no_neighbor_remove_private_as_all_replace_as_cmd);
14626 install_element(BGP_IPV6L_NODE, &neighbor_remove_private_as_cmd);
14627 install_element(BGP_IPV6L_NODE, &no_neighbor_remove_private_as_cmd);
14628 install_element(BGP_IPV6L_NODE, &neighbor_remove_private_as_all_cmd);
14629 install_element(BGP_IPV6L_NODE, &no_neighbor_remove_private_as_all_cmd);
14630 install_element(BGP_IPV6L_NODE,
14631 &neighbor_remove_private_as_replace_as_cmd);
14632 install_element(BGP_IPV6L_NODE,
14633 &no_neighbor_remove_private_as_replace_as_cmd);
14634 install_element(BGP_IPV6L_NODE,
14635 &neighbor_remove_private_as_all_replace_as_cmd);
14636 install_element(BGP_IPV6L_NODE,
14637 &no_neighbor_remove_private_as_all_replace_as_cmd);
14638 install_element(BGP_VPNV4_NODE, &neighbor_remove_private_as_cmd);
14639 install_element(BGP_VPNV4_NODE, &no_neighbor_remove_private_as_cmd);
14640 install_element(BGP_VPNV4_NODE, &neighbor_remove_private_as_all_cmd);
14641 install_element(BGP_VPNV4_NODE, &no_neighbor_remove_private_as_all_cmd);
14642 install_element(BGP_VPNV4_NODE,
14643 &neighbor_remove_private_as_replace_as_cmd);
14644 install_element(BGP_VPNV4_NODE,
14645 &no_neighbor_remove_private_as_replace_as_cmd);
14646 install_element(BGP_VPNV4_NODE,
14647 &neighbor_remove_private_as_all_replace_as_cmd);
14648 install_element(BGP_VPNV4_NODE,
14649 &no_neighbor_remove_private_as_all_replace_as_cmd);
14650 install_element(BGP_VPNV6_NODE, &neighbor_remove_private_as_cmd);
14651 install_element(BGP_VPNV6_NODE, &no_neighbor_remove_private_as_cmd);
14652 install_element(BGP_VPNV6_NODE, &neighbor_remove_private_as_all_cmd);
14653 install_element(BGP_VPNV6_NODE, &no_neighbor_remove_private_as_all_cmd);
14654 install_element(BGP_VPNV6_NODE,
14655 &neighbor_remove_private_as_replace_as_cmd);
14656 install_element(BGP_VPNV6_NODE,
14657 &no_neighbor_remove_private_as_replace_as_cmd);
14658 install_element(BGP_VPNV6_NODE,
14659 &neighbor_remove_private_as_all_replace_as_cmd);
14660 install_element(BGP_VPNV6_NODE,
14661 &no_neighbor_remove_private_as_all_replace_as_cmd);
14662
14663 /* "neighbor send-community" commands.*/
14664 install_element(BGP_NODE, &neighbor_send_community_hidden_cmd);
14665 install_element(BGP_NODE, &neighbor_send_community_type_hidden_cmd);
14666 install_element(BGP_NODE, &no_neighbor_send_community_hidden_cmd);
14667 install_element(BGP_NODE, &no_neighbor_send_community_type_hidden_cmd);
14668 install_element(BGP_IPV4_NODE, &neighbor_send_community_cmd);
14669 install_element(BGP_IPV4_NODE, &neighbor_send_community_type_cmd);
14670 install_element(BGP_IPV4_NODE, &no_neighbor_send_community_cmd);
14671 install_element(BGP_IPV4_NODE, &no_neighbor_send_community_type_cmd);
14672 install_element(BGP_IPV4M_NODE, &neighbor_send_community_cmd);
14673 install_element(BGP_IPV4M_NODE, &neighbor_send_community_type_cmd);
14674 install_element(BGP_IPV4M_NODE, &no_neighbor_send_community_cmd);
14675 install_element(BGP_IPV4M_NODE, &no_neighbor_send_community_type_cmd);
14676 install_element(BGP_IPV4L_NODE, &neighbor_send_community_cmd);
14677 install_element(BGP_IPV4L_NODE, &neighbor_send_community_type_cmd);
14678 install_element(BGP_IPV4L_NODE, &no_neighbor_send_community_cmd);
14679 install_element(BGP_IPV4L_NODE, &no_neighbor_send_community_type_cmd);
14680 install_element(BGP_IPV6_NODE, &neighbor_send_community_cmd);
14681 install_element(BGP_IPV6_NODE, &neighbor_send_community_type_cmd);
14682 install_element(BGP_IPV6_NODE, &no_neighbor_send_community_cmd);
14683 install_element(BGP_IPV6_NODE, &no_neighbor_send_community_type_cmd);
14684 install_element(BGP_IPV6M_NODE, &neighbor_send_community_cmd);
14685 install_element(BGP_IPV6M_NODE, &neighbor_send_community_type_cmd);
14686 install_element(BGP_IPV6M_NODE, &no_neighbor_send_community_cmd);
14687 install_element(BGP_IPV6M_NODE, &no_neighbor_send_community_type_cmd);
14688 install_element(BGP_IPV6L_NODE, &neighbor_send_community_cmd);
14689 install_element(BGP_IPV6L_NODE, &neighbor_send_community_type_cmd);
14690 install_element(BGP_IPV6L_NODE, &no_neighbor_send_community_cmd);
14691 install_element(BGP_IPV6L_NODE, &no_neighbor_send_community_type_cmd);
14692 install_element(BGP_VPNV4_NODE, &neighbor_send_community_cmd);
14693 install_element(BGP_VPNV4_NODE, &neighbor_send_community_type_cmd);
14694 install_element(BGP_VPNV4_NODE, &no_neighbor_send_community_cmd);
14695 install_element(BGP_VPNV4_NODE, &no_neighbor_send_community_type_cmd);
14696 install_element(BGP_VPNV6_NODE, &neighbor_send_community_cmd);
14697 install_element(BGP_VPNV6_NODE, &neighbor_send_community_type_cmd);
14698 install_element(BGP_VPNV6_NODE, &no_neighbor_send_community_cmd);
14699 install_element(BGP_VPNV6_NODE, &no_neighbor_send_community_type_cmd);
14700
14701 /* "neighbor route-reflector" commands.*/
14702 install_element(BGP_NODE, &neighbor_route_reflector_client_hidden_cmd);
14703 install_element(BGP_NODE,
14704 &no_neighbor_route_reflector_client_hidden_cmd);
14705 install_element(BGP_IPV4_NODE, &neighbor_route_reflector_client_cmd);
14706 install_element(BGP_IPV4_NODE, &no_neighbor_route_reflector_client_cmd);
14707 install_element(BGP_IPV4M_NODE, &neighbor_route_reflector_client_cmd);
14708 install_element(BGP_IPV4M_NODE,
14709 &no_neighbor_route_reflector_client_cmd);
14710 install_element(BGP_IPV4L_NODE, &neighbor_route_reflector_client_cmd);
14711 install_element(BGP_IPV4L_NODE,
14712 &no_neighbor_route_reflector_client_cmd);
14713 install_element(BGP_IPV6_NODE, &neighbor_route_reflector_client_cmd);
14714 install_element(BGP_IPV6_NODE, &no_neighbor_route_reflector_client_cmd);
14715 install_element(BGP_IPV6M_NODE, &neighbor_route_reflector_client_cmd);
14716 install_element(BGP_IPV6M_NODE,
14717 &no_neighbor_route_reflector_client_cmd);
14718 install_element(BGP_IPV6L_NODE, &neighbor_route_reflector_client_cmd);
14719 install_element(BGP_IPV6L_NODE,
14720 &no_neighbor_route_reflector_client_cmd);
14721 install_element(BGP_VPNV4_NODE, &neighbor_route_reflector_client_cmd);
14722 install_element(BGP_VPNV4_NODE,
14723 &no_neighbor_route_reflector_client_cmd);
14724 install_element(BGP_VPNV6_NODE, &neighbor_route_reflector_client_cmd);
14725 install_element(BGP_VPNV6_NODE,
14726 &no_neighbor_route_reflector_client_cmd);
14727 install_element(BGP_FLOWSPECV4_NODE,
14728 &neighbor_route_reflector_client_cmd);
14729 install_element(BGP_FLOWSPECV4_NODE,
14730 &no_neighbor_route_reflector_client_cmd);
14731 install_element(BGP_FLOWSPECV6_NODE,
14732 &neighbor_route_reflector_client_cmd);
14733 install_element(BGP_FLOWSPECV6_NODE,
14734 &no_neighbor_route_reflector_client_cmd);
14735 install_element(BGP_EVPN_NODE, &neighbor_route_reflector_client_cmd);
14736 install_element(BGP_EVPN_NODE, &no_neighbor_route_reflector_client_cmd);
14737
14738 /* "neighbor route-server" commands.*/
14739 install_element(BGP_NODE, &neighbor_route_server_client_hidden_cmd);
14740 install_element(BGP_NODE, &no_neighbor_route_server_client_hidden_cmd);
14741 install_element(BGP_IPV4_NODE, &neighbor_route_server_client_cmd);
14742 install_element(BGP_IPV4_NODE, &no_neighbor_route_server_client_cmd);
14743 install_element(BGP_IPV4M_NODE, &neighbor_route_server_client_cmd);
14744 install_element(BGP_IPV4M_NODE, &no_neighbor_route_server_client_cmd);
14745 install_element(BGP_IPV4L_NODE, &neighbor_route_server_client_cmd);
14746 install_element(BGP_IPV4L_NODE, &no_neighbor_route_server_client_cmd);
14747 install_element(BGP_IPV6_NODE, &neighbor_route_server_client_cmd);
14748 install_element(BGP_IPV6_NODE, &no_neighbor_route_server_client_cmd);
14749 install_element(BGP_IPV6M_NODE, &neighbor_route_server_client_cmd);
14750 install_element(BGP_IPV6M_NODE, &no_neighbor_route_server_client_cmd);
14751 install_element(BGP_IPV6L_NODE, &neighbor_route_server_client_cmd);
14752 install_element(BGP_IPV6L_NODE, &no_neighbor_route_server_client_cmd);
14753 install_element(BGP_VPNV4_NODE, &neighbor_route_server_client_cmd);
14754 install_element(BGP_VPNV4_NODE, &no_neighbor_route_server_client_cmd);
14755 install_element(BGP_VPNV6_NODE, &neighbor_route_server_client_cmd);
14756 install_element(BGP_VPNV6_NODE, &no_neighbor_route_server_client_cmd);
14757 install_element(BGP_EVPN_NODE, &neighbor_route_server_client_cmd);
14758 install_element(BGP_EVPN_NODE, &no_neighbor_route_server_client_cmd);
14759 install_element(BGP_FLOWSPECV4_NODE, &neighbor_route_server_client_cmd);
14760 install_element(BGP_FLOWSPECV4_NODE,
14761 &no_neighbor_route_server_client_cmd);
14762 install_element(BGP_FLOWSPECV6_NODE, &neighbor_route_server_client_cmd);
14763 install_element(BGP_FLOWSPECV6_NODE,
14764 &no_neighbor_route_server_client_cmd);
14765
14766 /* "neighbor addpath-tx-all-paths" commands.*/
14767 install_element(BGP_NODE, &neighbor_addpath_tx_all_paths_hidden_cmd);
14768 install_element(BGP_NODE, &no_neighbor_addpath_tx_all_paths_hidden_cmd);
14769 install_element(BGP_IPV4_NODE, &neighbor_addpath_tx_all_paths_cmd);
14770 install_element(BGP_IPV4_NODE, &no_neighbor_addpath_tx_all_paths_cmd);
14771 install_element(BGP_IPV4M_NODE, &neighbor_addpath_tx_all_paths_cmd);
14772 install_element(BGP_IPV4M_NODE, &no_neighbor_addpath_tx_all_paths_cmd);
14773 install_element(BGP_IPV4L_NODE, &neighbor_addpath_tx_all_paths_cmd);
14774 install_element(BGP_IPV4L_NODE, &no_neighbor_addpath_tx_all_paths_cmd);
14775 install_element(BGP_IPV6_NODE, &neighbor_addpath_tx_all_paths_cmd);
14776 install_element(BGP_IPV6_NODE, &no_neighbor_addpath_tx_all_paths_cmd);
14777 install_element(BGP_IPV6M_NODE, &neighbor_addpath_tx_all_paths_cmd);
14778 install_element(BGP_IPV6M_NODE, &no_neighbor_addpath_tx_all_paths_cmd);
14779 install_element(BGP_IPV6L_NODE, &neighbor_addpath_tx_all_paths_cmd);
14780 install_element(BGP_IPV6L_NODE, &no_neighbor_addpath_tx_all_paths_cmd);
14781 install_element(BGP_VPNV4_NODE, &neighbor_addpath_tx_all_paths_cmd);
14782 install_element(BGP_VPNV4_NODE, &no_neighbor_addpath_tx_all_paths_cmd);
14783 install_element(BGP_VPNV6_NODE, &neighbor_addpath_tx_all_paths_cmd);
14784 install_element(BGP_VPNV6_NODE, &no_neighbor_addpath_tx_all_paths_cmd);
14785
14786 /* "neighbor addpath-tx-bestpath-per-AS" commands.*/
14787 install_element(BGP_NODE,
14788 &neighbor_addpath_tx_bestpath_per_as_hidden_cmd);
14789 install_element(BGP_NODE,
14790 &no_neighbor_addpath_tx_bestpath_per_as_hidden_cmd);
14791 install_element(BGP_IPV4_NODE,
14792 &neighbor_addpath_tx_bestpath_per_as_cmd);
14793 install_element(BGP_IPV4_NODE,
14794 &no_neighbor_addpath_tx_bestpath_per_as_cmd);
14795 install_element(BGP_IPV4M_NODE,
14796 &neighbor_addpath_tx_bestpath_per_as_cmd);
14797 install_element(BGP_IPV4M_NODE,
14798 &no_neighbor_addpath_tx_bestpath_per_as_cmd);
14799 install_element(BGP_IPV4L_NODE,
14800 &neighbor_addpath_tx_bestpath_per_as_cmd);
14801 install_element(BGP_IPV4L_NODE,
14802 &no_neighbor_addpath_tx_bestpath_per_as_cmd);
14803 install_element(BGP_IPV6_NODE,
14804 &neighbor_addpath_tx_bestpath_per_as_cmd);
14805 install_element(BGP_IPV6_NODE,
14806 &no_neighbor_addpath_tx_bestpath_per_as_cmd);
14807 install_element(BGP_IPV6M_NODE,
14808 &neighbor_addpath_tx_bestpath_per_as_cmd);
14809 install_element(BGP_IPV6M_NODE,
14810 &no_neighbor_addpath_tx_bestpath_per_as_cmd);
14811 install_element(BGP_IPV6L_NODE,
14812 &neighbor_addpath_tx_bestpath_per_as_cmd);
14813 install_element(BGP_IPV6L_NODE,
14814 &no_neighbor_addpath_tx_bestpath_per_as_cmd);
14815 install_element(BGP_VPNV4_NODE,
14816 &neighbor_addpath_tx_bestpath_per_as_cmd);
14817 install_element(BGP_VPNV4_NODE,
14818 &no_neighbor_addpath_tx_bestpath_per_as_cmd);
14819 install_element(BGP_VPNV6_NODE,
14820 &neighbor_addpath_tx_bestpath_per_as_cmd);
14821 install_element(BGP_VPNV6_NODE,
14822 &no_neighbor_addpath_tx_bestpath_per_as_cmd);
14823
14824 /* "neighbor sender-as-path-loop-detection" commands. */
14825 install_element(BGP_NODE, &neighbor_aspath_loop_detection_cmd);
14826 install_element(BGP_NODE, &no_neighbor_aspath_loop_detection_cmd);
14827
14828 /* "neighbor passive" commands. */
14829 install_element(BGP_NODE, &neighbor_passive_cmd);
14830 install_element(BGP_NODE, &no_neighbor_passive_cmd);
14831
14832
14833 /* "neighbor shutdown" commands. */
14834 install_element(BGP_NODE, &neighbor_shutdown_cmd);
14835 install_element(BGP_NODE, &no_neighbor_shutdown_cmd);
14836 install_element(BGP_NODE, &neighbor_shutdown_msg_cmd);
14837 install_element(BGP_NODE, &no_neighbor_shutdown_msg_cmd);
14838
14839 /* "neighbor capability extended-nexthop" commands.*/
14840 install_element(BGP_NODE, &neighbor_capability_enhe_cmd);
14841 install_element(BGP_NODE, &no_neighbor_capability_enhe_cmd);
14842
14843 /* "neighbor capability orf prefix-list" commands.*/
14844 install_element(BGP_NODE, &neighbor_capability_orf_prefix_hidden_cmd);
14845 install_element(BGP_NODE,
14846 &no_neighbor_capability_orf_prefix_hidden_cmd);
14847 install_element(BGP_IPV4_NODE, &neighbor_capability_orf_prefix_cmd);
14848 install_element(BGP_IPV4_NODE, &no_neighbor_capability_orf_prefix_cmd);
14849 install_element(BGP_IPV4M_NODE, &neighbor_capability_orf_prefix_cmd);
14850 install_element(BGP_IPV4M_NODE, &no_neighbor_capability_orf_prefix_cmd);
14851 install_element(BGP_IPV4L_NODE, &neighbor_capability_orf_prefix_cmd);
14852 install_element(BGP_IPV4L_NODE, &no_neighbor_capability_orf_prefix_cmd);
14853 install_element(BGP_IPV6_NODE, &neighbor_capability_orf_prefix_cmd);
14854 install_element(BGP_IPV6_NODE, &no_neighbor_capability_orf_prefix_cmd);
14855 install_element(BGP_IPV6M_NODE, &neighbor_capability_orf_prefix_cmd);
14856 install_element(BGP_IPV6M_NODE, &no_neighbor_capability_orf_prefix_cmd);
14857 install_element(BGP_IPV6L_NODE, &neighbor_capability_orf_prefix_cmd);
14858 install_element(BGP_IPV6L_NODE, &no_neighbor_capability_orf_prefix_cmd);
14859
14860 /* "neighbor capability dynamic" commands.*/
14861 install_element(BGP_NODE, &neighbor_capability_dynamic_cmd);
14862 install_element(BGP_NODE, &no_neighbor_capability_dynamic_cmd);
14863
14864 /* "neighbor dont-capability-negotiate" commands. */
14865 install_element(BGP_NODE, &neighbor_dont_capability_negotiate_cmd);
14866 install_element(BGP_NODE, &no_neighbor_dont_capability_negotiate_cmd);
14867
14868 /* "neighbor ebgp-multihop" commands. */
14869 install_element(BGP_NODE, &neighbor_ebgp_multihop_cmd);
14870 install_element(BGP_NODE, &neighbor_ebgp_multihop_ttl_cmd);
14871 install_element(BGP_NODE, &no_neighbor_ebgp_multihop_cmd);
14872
14873 /* "neighbor disable-connected-check" commands. */
14874 install_element(BGP_NODE, &neighbor_disable_connected_check_cmd);
14875 install_element(BGP_NODE, &no_neighbor_disable_connected_check_cmd);
14876
14877 /* "neighbor enforce-first-as" commands. */
14878 install_element(BGP_NODE, &neighbor_enforce_first_as_cmd);
14879 install_element(BGP_NODE, &no_neighbor_enforce_first_as_cmd);
14880
14881 /* "neighbor description" commands. */
14882 install_element(BGP_NODE, &neighbor_description_cmd);
14883 install_element(BGP_NODE, &no_neighbor_description_cmd);
14884 install_element(BGP_NODE, &no_neighbor_description_comment_cmd);
14885
14886 /* "neighbor update-source" commands. "*/
14887 install_element(BGP_NODE, &neighbor_update_source_cmd);
14888 install_element(BGP_NODE, &no_neighbor_update_source_cmd);
14889
14890 /* "neighbor default-originate" commands. */
14891 install_element(BGP_NODE, &neighbor_default_originate_hidden_cmd);
14892 install_element(BGP_NODE, &neighbor_default_originate_rmap_hidden_cmd);
14893 install_element(BGP_NODE, &no_neighbor_default_originate_hidden_cmd);
14894 install_element(BGP_IPV4_NODE, &neighbor_default_originate_cmd);
14895 install_element(BGP_IPV4_NODE, &neighbor_default_originate_rmap_cmd);
14896 install_element(BGP_IPV4_NODE, &no_neighbor_default_originate_cmd);
14897 install_element(BGP_IPV4M_NODE, &neighbor_default_originate_cmd);
14898 install_element(BGP_IPV4M_NODE, &neighbor_default_originate_rmap_cmd);
14899 install_element(BGP_IPV4M_NODE, &no_neighbor_default_originate_cmd);
14900 install_element(BGP_IPV4L_NODE, &neighbor_default_originate_cmd);
14901 install_element(BGP_IPV4L_NODE, &neighbor_default_originate_rmap_cmd);
14902 install_element(BGP_IPV4L_NODE, &no_neighbor_default_originate_cmd);
14903 install_element(BGP_IPV6_NODE, &neighbor_default_originate_cmd);
14904 install_element(BGP_IPV6_NODE, &neighbor_default_originate_rmap_cmd);
14905 install_element(BGP_IPV6_NODE, &no_neighbor_default_originate_cmd);
14906 install_element(BGP_IPV6M_NODE, &neighbor_default_originate_cmd);
14907 install_element(BGP_IPV6M_NODE, &neighbor_default_originate_rmap_cmd);
14908 install_element(BGP_IPV6M_NODE, &no_neighbor_default_originate_cmd);
14909 install_element(BGP_IPV6L_NODE, &neighbor_default_originate_cmd);
14910 install_element(BGP_IPV6L_NODE, &neighbor_default_originate_rmap_cmd);
14911 install_element(BGP_IPV6L_NODE, &no_neighbor_default_originate_cmd);
14912
14913 /* "neighbor port" commands. */
14914 install_element(BGP_NODE, &neighbor_port_cmd);
14915 install_element(BGP_NODE, &no_neighbor_port_cmd);
14916
14917 /* "neighbor weight" commands. */
14918 install_element(BGP_NODE, &neighbor_weight_hidden_cmd);
14919 install_element(BGP_NODE, &no_neighbor_weight_hidden_cmd);
14920
14921 install_element(BGP_IPV4_NODE, &neighbor_weight_cmd);
14922 install_element(BGP_IPV4_NODE, &no_neighbor_weight_cmd);
14923 install_element(BGP_IPV4M_NODE, &neighbor_weight_cmd);
14924 install_element(BGP_IPV4M_NODE, &no_neighbor_weight_cmd);
14925 install_element(BGP_IPV4L_NODE, &neighbor_weight_cmd);
14926 install_element(BGP_IPV4L_NODE, &no_neighbor_weight_cmd);
14927 install_element(BGP_IPV6_NODE, &neighbor_weight_cmd);
14928 install_element(BGP_IPV6_NODE, &no_neighbor_weight_cmd);
14929 install_element(BGP_IPV6M_NODE, &neighbor_weight_cmd);
14930 install_element(BGP_IPV6M_NODE, &no_neighbor_weight_cmd);
14931 install_element(BGP_IPV6L_NODE, &neighbor_weight_cmd);
14932 install_element(BGP_IPV6L_NODE, &no_neighbor_weight_cmd);
14933 install_element(BGP_VPNV4_NODE, &neighbor_weight_cmd);
14934 install_element(BGP_VPNV4_NODE, &no_neighbor_weight_cmd);
14935 install_element(BGP_VPNV6_NODE, &neighbor_weight_cmd);
14936 install_element(BGP_VPNV6_NODE, &no_neighbor_weight_cmd);
14937
14938 /* "neighbor override-capability" commands. */
14939 install_element(BGP_NODE, &neighbor_override_capability_cmd);
14940 install_element(BGP_NODE, &no_neighbor_override_capability_cmd);
14941
14942 /* "neighbor strict-capability-match" commands. */
14943 install_element(BGP_NODE, &neighbor_strict_capability_cmd);
14944 install_element(BGP_NODE, &no_neighbor_strict_capability_cmd);
14945
14946 /* "neighbor timers" commands. */
14947 install_element(BGP_NODE, &neighbor_timers_cmd);
14948 install_element(BGP_NODE, &no_neighbor_timers_cmd);
14949
14950 /* "neighbor timers connect" commands. */
14951 install_element(BGP_NODE, &neighbor_timers_connect_cmd);
14952 install_element(BGP_NODE, &no_neighbor_timers_connect_cmd);
14953
14954 /* "neighbor advertisement-interval" commands. */
14955 install_element(BGP_NODE, &neighbor_advertise_interval_cmd);
14956 install_element(BGP_NODE, &no_neighbor_advertise_interval_cmd);
14957
14958 /* "neighbor interface" commands. */
14959 install_element(BGP_NODE, &neighbor_interface_cmd);
14960 install_element(BGP_NODE, &no_neighbor_interface_cmd);
14961
14962 /* "neighbor distribute" commands. */
14963 install_element(BGP_NODE, &neighbor_distribute_list_hidden_cmd);
14964 install_element(BGP_NODE, &no_neighbor_distribute_list_hidden_cmd);
14965 install_element(BGP_IPV4_NODE, &neighbor_distribute_list_cmd);
14966 install_element(BGP_IPV4_NODE, &no_neighbor_distribute_list_cmd);
14967 install_element(BGP_IPV4M_NODE, &neighbor_distribute_list_cmd);
14968 install_element(BGP_IPV4M_NODE, &no_neighbor_distribute_list_cmd);
14969 install_element(BGP_IPV4L_NODE, &neighbor_distribute_list_cmd);
14970 install_element(BGP_IPV4L_NODE, &no_neighbor_distribute_list_cmd);
14971 install_element(BGP_IPV6_NODE, &neighbor_distribute_list_cmd);
14972 install_element(BGP_IPV6_NODE, &no_neighbor_distribute_list_cmd);
14973 install_element(BGP_IPV6M_NODE, &neighbor_distribute_list_cmd);
14974 install_element(BGP_IPV6M_NODE, &no_neighbor_distribute_list_cmd);
14975 install_element(BGP_IPV6L_NODE, &neighbor_distribute_list_cmd);
14976 install_element(BGP_IPV6L_NODE, &no_neighbor_distribute_list_cmd);
14977 install_element(BGP_VPNV4_NODE, &neighbor_distribute_list_cmd);
14978 install_element(BGP_VPNV4_NODE, &no_neighbor_distribute_list_cmd);
14979 install_element(BGP_VPNV6_NODE, &neighbor_distribute_list_cmd);
14980 install_element(BGP_VPNV6_NODE, &no_neighbor_distribute_list_cmd);
14981
14982 /* "neighbor prefix-list" commands. */
14983 install_element(BGP_NODE, &neighbor_prefix_list_hidden_cmd);
14984 install_element(BGP_NODE, &no_neighbor_prefix_list_hidden_cmd);
14985 install_element(BGP_IPV4_NODE, &neighbor_prefix_list_cmd);
14986 install_element(BGP_IPV4_NODE, &no_neighbor_prefix_list_cmd);
14987 install_element(BGP_IPV4M_NODE, &neighbor_prefix_list_cmd);
14988 install_element(BGP_IPV4M_NODE, &no_neighbor_prefix_list_cmd);
14989 install_element(BGP_IPV4L_NODE, &neighbor_prefix_list_cmd);
14990 install_element(BGP_IPV4L_NODE, &no_neighbor_prefix_list_cmd);
14991 install_element(BGP_IPV6_NODE, &neighbor_prefix_list_cmd);
14992 install_element(BGP_IPV6_NODE, &no_neighbor_prefix_list_cmd);
14993 install_element(BGP_IPV6M_NODE, &neighbor_prefix_list_cmd);
14994 install_element(BGP_IPV6M_NODE, &no_neighbor_prefix_list_cmd);
14995 install_element(BGP_IPV6L_NODE, &neighbor_prefix_list_cmd);
14996 install_element(BGP_IPV6L_NODE, &no_neighbor_prefix_list_cmd);
14997 install_element(BGP_VPNV4_NODE, &neighbor_prefix_list_cmd);
14998 install_element(BGP_VPNV4_NODE, &no_neighbor_prefix_list_cmd);
14999 install_element(BGP_VPNV6_NODE, &neighbor_prefix_list_cmd);
15000 install_element(BGP_VPNV6_NODE, &no_neighbor_prefix_list_cmd);
15001 install_element(BGP_FLOWSPECV4_NODE, &neighbor_prefix_list_cmd);
15002 install_element(BGP_FLOWSPECV4_NODE, &no_neighbor_prefix_list_cmd);
15003 install_element(BGP_FLOWSPECV6_NODE, &neighbor_prefix_list_cmd);
15004 install_element(BGP_FLOWSPECV6_NODE, &no_neighbor_prefix_list_cmd);
15005
15006 /* "neighbor filter-list" commands. */
15007 install_element(BGP_NODE, &neighbor_filter_list_hidden_cmd);
15008 install_element(BGP_NODE, &no_neighbor_filter_list_hidden_cmd);
15009 install_element(BGP_IPV4_NODE, &neighbor_filter_list_cmd);
15010 install_element(BGP_IPV4_NODE, &no_neighbor_filter_list_cmd);
15011 install_element(BGP_IPV4M_NODE, &neighbor_filter_list_cmd);
15012 install_element(BGP_IPV4M_NODE, &no_neighbor_filter_list_cmd);
15013 install_element(BGP_IPV4L_NODE, &neighbor_filter_list_cmd);
15014 install_element(BGP_IPV4L_NODE, &no_neighbor_filter_list_cmd);
15015 install_element(BGP_IPV6_NODE, &neighbor_filter_list_cmd);
15016 install_element(BGP_IPV6_NODE, &no_neighbor_filter_list_cmd);
15017 install_element(BGP_IPV6M_NODE, &neighbor_filter_list_cmd);
15018 install_element(BGP_IPV6M_NODE, &no_neighbor_filter_list_cmd);
15019 install_element(BGP_IPV6L_NODE, &neighbor_filter_list_cmd);
15020 install_element(BGP_IPV6L_NODE, &no_neighbor_filter_list_cmd);
15021 install_element(BGP_VPNV4_NODE, &neighbor_filter_list_cmd);
15022 install_element(BGP_VPNV4_NODE, &no_neighbor_filter_list_cmd);
15023 install_element(BGP_VPNV6_NODE, &neighbor_filter_list_cmd);
15024 install_element(BGP_VPNV6_NODE, &no_neighbor_filter_list_cmd);
15025 install_element(BGP_FLOWSPECV4_NODE, &neighbor_filter_list_cmd);
15026 install_element(BGP_FLOWSPECV4_NODE, &no_neighbor_filter_list_cmd);
15027 install_element(BGP_FLOWSPECV6_NODE, &neighbor_filter_list_cmd);
15028 install_element(BGP_FLOWSPECV6_NODE, &no_neighbor_filter_list_cmd);
15029
15030 /* "neighbor route-map" commands. */
15031 install_element(BGP_NODE, &neighbor_route_map_hidden_cmd);
15032 install_element(BGP_NODE, &no_neighbor_route_map_hidden_cmd);
15033 install_element(BGP_IPV4_NODE, &neighbor_route_map_cmd);
15034 install_element(BGP_IPV4_NODE, &no_neighbor_route_map_cmd);
15035 install_element(BGP_IPV4M_NODE, &neighbor_route_map_cmd);
15036 install_element(BGP_IPV4M_NODE, &no_neighbor_route_map_cmd);
15037 install_element(BGP_IPV4L_NODE, &neighbor_route_map_cmd);
15038 install_element(BGP_IPV4L_NODE, &no_neighbor_route_map_cmd);
15039 install_element(BGP_IPV6_NODE, &neighbor_route_map_cmd);
15040 install_element(BGP_IPV6_NODE, &no_neighbor_route_map_cmd);
15041 install_element(BGP_IPV6M_NODE, &neighbor_route_map_cmd);
15042 install_element(BGP_IPV6M_NODE, &no_neighbor_route_map_cmd);
15043 install_element(BGP_IPV6L_NODE, &neighbor_route_map_cmd);
15044 install_element(BGP_IPV6L_NODE, &no_neighbor_route_map_cmd);
15045 install_element(BGP_VPNV4_NODE, &neighbor_route_map_cmd);
15046 install_element(BGP_VPNV4_NODE, &no_neighbor_route_map_cmd);
15047 install_element(BGP_VPNV6_NODE, &neighbor_route_map_cmd);
15048 install_element(BGP_VPNV6_NODE, &no_neighbor_route_map_cmd);
15049 install_element(BGP_FLOWSPECV4_NODE, &neighbor_route_map_cmd);
15050 install_element(BGP_FLOWSPECV4_NODE, &no_neighbor_route_map_cmd);
15051 install_element(BGP_FLOWSPECV6_NODE, &neighbor_route_map_cmd);
15052 install_element(BGP_FLOWSPECV6_NODE, &no_neighbor_route_map_cmd);
15053 install_element(BGP_EVPN_NODE, &neighbor_route_map_cmd);
15054 install_element(BGP_EVPN_NODE, &no_neighbor_route_map_cmd);
15055
15056 /* "neighbor unsuppress-map" commands. */
15057 install_element(BGP_NODE, &neighbor_unsuppress_map_hidden_cmd);
15058 install_element(BGP_NODE, &no_neighbor_unsuppress_map_hidden_cmd);
15059 install_element(BGP_IPV4_NODE, &neighbor_unsuppress_map_cmd);
15060 install_element(BGP_IPV4_NODE, &no_neighbor_unsuppress_map_cmd);
15061 install_element(BGP_IPV4M_NODE, &neighbor_unsuppress_map_cmd);
15062 install_element(BGP_IPV4M_NODE, &no_neighbor_unsuppress_map_cmd);
15063 install_element(BGP_IPV4L_NODE, &neighbor_unsuppress_map_cmd);
15064 install_element(BGP_IPV4L_NODE, &no_neighbor_unsuppress_map_cmd);
15065 install_element(BGP_IPV6_NODE, &neighbor_unsuppress_map_cmd);
15066 install_element(BGP_IPV6_NODE, &no_neighbor_unsuppress_map_cmd);
15067 install_element(BGP_IPV6M_NODE, &neighbor_unsuppress_map_cmd);
15068 install_element(BGP_IPV6M_NODE, &no_neighbor_unsuppress_map_cmd);
15069 install_element(BGP_IPV6L_NODE, &neighbor_unsuppress_map_cmd);
15070 install_element(BGP_IPV6L_NODE, &no_neighbor_unsuppress_map_cmd);
15071 install_element(BGP_VPNV4_NODE, &neighbor_unsuppress_map_cmd);
15072 install_element(BGP_VPNV4_NODE, &no_neighbor_unsuppress_map_cmd);
15073 install_element(BGP_VPNV6_NODE, &neighbor_unsuppress_map_cmd);
15074 install_element(BGP_VPNV6_NODE, &no_neighbor_unsuppress_map_cmd);
15075
15076 /* "neighbor maximum-prefix" commands. */
15077 install_element(BGP_NODE, &neighbor_maximum_prefix_hidden_cmd);
15078 install_element(BGP_NODE,
15079 &neighbor_maximum_prefix_threshold_hidden_cmd);
15080 install_element(BGP_NODE, &neighbor_maximum_prefix_warning_hidden_cmd);
15081 install_element(BGP_NODE,
15082 &neighbor_maximum_prefix_threshold_warning_hidden_cmd);
15083 install_element(BGP_NODE, &neighbor_maximum_prefix_restart_hidden_cmd);
15084 install_element(BGP_NODE,
15085 &neighbor_maximum_prefix_threshold_restart_hidden_cmd);
15086 install_element(BGP_NODE, &no_neighbor_maximum_prefix_hidden_cmd);
15087 install_element(BGP_IPV4_NODE, &neighbor_maximum_prefix_cmd);
15088 install_element(BGP_IPV4_NODE, &neighbor_maximum_prefix_threshold_cmd);
15089 install_element(BGP_IPV4_NODE, &neighbor_maximum_prefix_warning_cmd);
15090 install_element(BGP_IPV4_NODE,
15091 &neighbor_maximum_prefix_threshold_warning_cmd);
15092 install_element(BGP_IPV4_NODE, &neighbor_maximum_prefix_restart_cmd);
15093 install_element(BGP_IPV4_NODE,
15094 &neighbor_maximum_prefix_threshold_restart_cmd);
15095 install_element(BGP_IPV4_NODE, &no_neighbor_maximum_prefix_cmd);
15096 install_element(BGP_IPV4M_NODE, &neighbor_maximum_prefix_cmd);
15097 install_element(BGP_IPV4M_NODE, &neighbor_maximum_prefix_threshold_cmd);
15098 install_element(BGP_IPV4M_NODE, &neighbor_maximum_prefix_warning_cmd);
15099 install_element(BGP_IPV4M_NODE,
15100 &neighbor_maximum_prefix_threshold_warning_cmd);
15101 install_element(BGP_IPV4M_NODE, &neighbor_maximum_prefix_restart_cmd);
15102 install_element(BGP_IPV4M_NODE,
15103 &neighbor_maximum_prefix_threshold_restart_cmd);
15104 install_element(BGP_IPV4M_NODE, &no_neighbor_maximum_prefix_cmd);
15105 install_element(BGP_IPV4L_NODE, &neighbor_maximum_prefix_cmd);
15106 install_element(BGP_IPV4L_NODE, &neighbor_maximum_prefix_threshold_cmd);
15107 install_element(BGP_IPV4L_NODE, &neighbor_maximum_prefix_warning_cmd);
15108 install_element(BGP_IPV4L_NODE,
15109 &neighbor_maximum_prefix_threshold_warning_cmd);
15110 install_element(BGP_IPV4L_NODE, &neighbor_maximum_prefix_restart_cmd);
15111 install_element(BGP_IPV4L_NODE,
15112 &neighbor_maximum_prefix_threshold_restart_cmd);
15113 install_element(BGP_IPV4L_NODE, &no_neighbor_maximum_prefix_cmd);
15114 install_element(BGP_IPV6_NODE, &neighbor_maximum_prefix_cmd);
15115 install_element(BGP_IPV6_NODE, &neighbor_maximum_prefix_threshold_cmd);
15116 install_element(BGP_IPV6_NODE, &neighbor_maximum_prefix_warning_cmd);
15117 install_element(BGP_IPV6_NODE,
15118 &neighbor_maximum_prefix_threshold_warning_cmd);
15119 install_element(BGP_IPV6_NODE, &neighbor_maximum_prefix_restart_cmd);
15120 install_element(BGP_IPV6_NODE,
15121 &neighbor_maximum_prefix_threshold_restart_cmd);
15122 install_element(BGP_IPV6_NODE, &no_neighbor_maximum_prefix_cmd);
15123 install_element(BGP_IPV6M_NODE, &neighbor_maximum_prefix_cmd);
15124 install_element(BGP_IPV6M_NODE, &neighbor_maximum_prefix_threshold_cmd);
15125 install_element(BGP_IPV6M_NODE, &neighbor_maximum_prefix_warning_cmd);
15126 install_element(BGP_IPV6M_NODE,
15127 &neighbor_maximum_prefix_threshold_warning_cmd);
15128 install_element(BGP_IPV6M_NODE, &neighbor_maximum_prefix_restart_cmd);
15129 install_element(BGP_IPV6M_NODE,
15130 &neighbor_maximum_prefix_threshold_restart_cmd);
15131 install_element(BGP_IPV6M_NODE, &no_neighbor_maximum_prefix_cmd);
15132 install_element(BGP_IPV6L_NODE, &neighbor_maximum_prefix_cmd);
15133 install_element(BGP_IPV6L_NODE, &neighbor_maximum_prefix_threshold_cmd);
15134 install_element(BGP_IPV6L_NODE, &neighbor_maximum_prefix_warning_cmd);
15135 install_element(BGP_IPV6L_NODE,
15136 &neighbor_maximum_prefix_threshold_warning_cmd);
15137 install_element(BGP_IPV6L_NODE, &neighbor_maximum_prefix_restart_cmd);
15138 install_element(BGP_IPV6L_NODE,
15139 &neighbor_maximum_prefix_threshold_restart_cmd);
15140 install_element(BGP_IPV6L_NODE, &no_neighbor_maximum_prefix_cmd);
15141 install_element(BGP_VPNV4_NODE, &neighbor_maximum_prefix_cmd);
15142 install_element(BGP_VPNV4_NODE, &neighbor_maximum_prefix_threshold_cmd);
15143 install_element(BGP_VPNV4_NODE, &neighbor_maximum_prefix_warning_cmd);
15144 install_element(BGP_VPNV4_NODE,
15145 &neighbor_maximum_prefix_threshold_warning_cmd);
15146 install_element(BGP_VPNV4_NODE, &neighbor_maximum_prefix_restart_cmd);
15147 install_element(BGP_VPNV4_NODE,
15148 &neighbor_maximum_prefix_threshold_restart_cmd);
15149 install_element(BGP_VPNV4_NODE, &no_neighbor_maximum_prefix_cmd);
15150 install_element(BGP_VPNV6_NODE, &neighbor_maximum_prefix_cmd);
15151 install_element(BGP_VPNV6_NODE, &neighbor_maximum_prefix_threshold_cmd);
15152 install_element(BGP_VPNV6_NODE, &neighbor_maximum_prefix_warning_cmd);
15153 install_element(BGP_VPNV6_NODE,
15154 &neighbor_maximum_prefix_threshold_warning_cmd);
15155 install_element(BGP_VPNV6_NODE, &neighbor_maximum_prefix_restart_cmd);
15156 install_element(BGP_VPNV6_NODE,
15157 &neighbor_maximum_prefix_threshold_restart_cmd);
15158 install_element(BGP_VPNV6_NODE, &no_neighbor_maximum_prefix_cmd);
15159
15160 /* "neighbor allowas-in" */
15161 install_element(BGP_NODE, &neighbor_allowas_in_hidden_cmd);
15162 install_element(BGP_NODE, &no_neighbor_allowas_in_hidden_cmd);
15163 install_element(BGP_IPV4_NODE, &neighbor_allowas_in_cmd);
15164 install_element(BGP_IPV4_NODE, &no_neighbor_allowas_in_cmd);
15165 install_element(BGP_IPV4M_NODE, &neighbor_allowas_in_cmd);
15166 install_element(BGP_IPV4M_NODE, &no_neighbor_allowas_in_cmd);
15167 install_element(BGP_IPV4L_NODE, &neighbor_allowas_in_cmd);
15168 install_element(BGP_IPV4L_NODE, &no_neighbor_allowas_in_cmd);
15169 install_element(BGP_IPV6_NODE, &neighbor_allowas_in_cmd);
15170 install_element(BGP_IPV6_NODE, &no_neighbor_allowas_in_cmd);
15171 install_element(BGP_IPV6M_NODE, &neighbor_allowas_in_cmd);
15172 install_element(BGP_IPV6M_NODE, &no_neighbor_allowas_in_cmd);
15173 install_element(BGP_IPV6L_NODE, &neighbor_allowas_in_cmd);
15174 install_element(BGP_IPV6L_NODE, &no_neighbor_allowas_in_cmd);
15175 install_element(BGP_VPNV4_NODE, &neighbor_allowas_in_cmd);
15176 install_element(BGP_VPNV4_NODE, &no_neighbor_allowas_in_cmd);
15177 install_element(BGP_VPNV6_NODE, &neighbor_allowas_in_cmd);
15178 install_element(BGP_VPNV6_NODE, &no_neighbor_allowas_in_cmd);
15179 install_element(BGP_EVPN_NODE, &neighbor_allowas_in_cmd);
15180 install_element(BGP_EVPN_NODE, &no_neighbor_allowas_in_cmd);
15181
15182 /* address-family commands. */
15183 install_element(BGP_NODE, &address_family_ipv4_safi_cmd);
15184 install_element(BGP_NODE, &address_family_ipv6_safi_cmd);
15185 #ifdef KEEP_OLD_VPN_COMMANDS
15186 install_element(BGP_NODE, &address_family_vpnv4_cmd);
15187 install_element(BGP_NODE, &address_family_vpnv6_cmd);
15188 #endif /* KEEP_OLD_VPN_COMMANDS */
15189
15190 install_element(BGP_NODE, &address_family_evpn_cmd);
15191
15192 /* "exit-address-family" command. */
15193 install_element(BGP_IPV4_NODE, &exit_address_family_cmd);
15194 install_element(BGP_IPV4M_NODE, &exit_address_family_cmd);
15195 install_element(BGP_IPV4L_NODE, &exit_address_family_cmd);
15196 install_element(BGP_IPV6_NODE, &exit_address_family_cmd);
15197 install_element(BGP_IPV6M_NODE, &exit_address_family_cmd);
15198 install_element(BGP_IPV6L_NODE, &exit_address_family_cmd);
15199 install_element(BGP_VPNV4_NODE, &exit_address_family_cmd);
15200 install_element(BGP_VPNV6_NODE, &exit_address_family_cmd);
15201 install_element(BGP_FLOWSPECV4_NODE, &exit_address_family_cmd);
15202 install_element(BGP_FLOWSPECV6_NODE, &exit_address_family_cmd);
15203 install_element(BGP_EVPN_NODE, &exit_address_family_cmd);
15204
15205 /* "clear ip bgp commands" */
15206 install_element(ENABLE_NODE, &clear_ip_bgp_all_cmd);
15207
15208 /* clear ip bgp prefix */
15209 install_element(ENABLE_NODE, &clear_ip_bgp_prefix_cmd);
15210 install_element(ENABLE_NODE, &clear_bgp_ipv6_safi_prefix_cmd);
15211 install_element(ENABLE_NODE, &clear_bgp_instance_ipv6_safi_prefix_cmd);
15212
15213 /* "show [ip] bgp summary" commands. */
15214 install_element(VIEW_NODE, &show_bgp_instance_all_ipv6_updgrps_cmd);
15215 install_element(VIEW_NODE, &show_bgp_l2vpn_evpn_updgrps_cmd);
15216 install_element(VIEW_NODE, &show_bgp_instance_updgrps_stats_cmd);
15217 install_element(VIEW_NODE, &show_bgp_updgrps_stats_cmd);
15218 install_element(VIEW_NODE, &show_ip_bgp_instance_updgrps_adj_s_cmd);
15219 install_element(VIEW_NODE, &show_ip_bgp_summary_cmd);
15220 install_element(VIEW_NODE, &show_ip_bgp_updgrps_cmd);
15221
15222 /* "show [ip] bgp neighbors" commands. */
15223 install_element(VIEW_NODE, &show_ip_bgp_neighbors_cmd);
15224
15225 /* "show [ip] bgp peer-group" commands. */
15226 install_element(VIEW_NODE, &show_ip_bgp_peer_groups_cmd);
15227
15228 /* "show [ip] bgp paths" commands. */
15229 install_element(VIEW_NODE, &show_ip_bgp_paths_cmd);
15230
15231 /* "show [ip] bgp community" commands. */
15232 install_element(VIEW_NODE, &show_ip_bgp_community_info_cmd);
15233
15234 /* "show ip bgp large-community" commands. */
15235 install_element(VIEW_NODE, &show_ip_bgp_lcommunity_info_cmd);
15236 /* "show [ip] bgp attribute-info" commands. */
15237 install_element(VIEW_NODE, &show_ip_bgp_attr_info_cmd);
15238 /* "show [ip] bgp route-leak" command */
15239 install_element(VIEW_NODE, &show_ip_bgp_route_leak_cmd);
15240
15241 /* "redistribute" commands. */
15242 install_element(BGP_NODE, &bgp_redistribute_ipv4_hidden_cmd);
15243 install_element(BGP_NODE, &no_bgp_redistribute_ipv4_hidden_cmd);
15244 install_element(BGP_NODE, &bgp_redistribute_ipv4_rmap_hidden_cmd);
15245 install_element(BGP_NODE, &bgp_redistribute_ipv4_metric_hidden_cmd);
15246 install_element(BGP_NODE,
15247 &bgp_redistribute_ipv4_rmap_metric_hidden_cmd);
15248 install_element(BGP_NODE,
15249 &bgp_redistribute_ipv4_metric_rmap_hidden_cmd);
15250 install_element(BGP_NODE, &bgp_redistribute_ipv4_ospf_hidden_cmd);
15251 install_element(BGP_NODE, &no_bgp_redistribute_ipv4_ospf_hidden_cmd);
15252 install_element(BGP_NODE, &bgp_redistribute_ipv4_ospf_rmap_hidden_cmd);
15253 install_element(BGP_NODE,
15254 &bgp_redistribute_ipv4_ospf_metric_hidden_cmd);
15255 install_element(BGP_NODE,
15256 &bgp_redistribute_ipv4_ospf_rmap_metric_hidden_cmd);
15257 install_element(BGP_NODE,
15258 &bgp_redistribute_ipv4_ospf_metric_rmap_hidden_cmd);
15259 install_element(BGP_IPV4_NODE, &bgp_redistribute_ipv4_cmd);
15260 install_element(BGP_IPV4_NODE, &no_bgp_redistribute_ipv4_cmd);
15261 install_element(BGP_IPV4_NODE, &bgp_redistribute_ipv4_rmap_cmd);
15262 install_element(BGP_IPV4_NODE, &bgp_redistribute_ipv4_metric_cmd);
15263 install_element(BGP_IPV4_NODE, &bgp_redistribute_ipv4_rmap_metric_cmd);
15264 install_element(BGP_IPV4_NODE, &bgp_redistribute_ipv4_metric_rmap_cmd);
15265 install_element(BGP_IPV4_NODE, &bgp_redistribute_ipv4_ospf_cmd);
15266 install_element(BGP_IPV4_NODE, &no_bgp_redistribute_ipv4_ospf_cmd);
15267 install_element(BGP_IPV4_NODE, &bgp_redistribute_ipv4_ospf_rmap_cmd);
15268 install_element(BGP_IPV4_NODE, &bgp_redistribute_ipv4_ospf_metric_cmd);
15269 install_element(BGP_IPV4_NODE,
15270 &bgp_redistribute_ipv4_ospf_rmap_metric_cmd);
15271 install_element(BGP_IPV4_NODE,
15272 &bgp_redistribute_ipv4_ospf_metric_rmap_cmd);
15273 install_element(BGP_IPV6_NODE, &bgp_redistribute_ipv6_cmd);
15274 install_element(BGP_IPV6_NODE, &no_bgp_redistribute_ipv6_cmd);
15275 install_element(BGP_IPV6_NODE, &bgp_redistribute_ipv6_rmap_cmd);
15276 install_element(BGP_IPV6_NODE, &bgp_redistribute_ipv6_metric_cmd);
15277 install_element(BGP_IPV6_NODE, &bgp_redistribute_ipv6_rmap_metric_cmd);
15278 install_element(BGP_IPV6_NODE, &bgp_redistribute_ipv6_metric_rmap_cmd);
15279
15280 /* import|export vpn [route-map WORD] */
15281 install_element(BGP_IPV4_NODE, &bgp_imexport_vpn_cmd);
15282 install_element(BGP_IPV6_NODE, &bgp_imexport_vpn_cmd);
15283
15284 install_element(BGP_IPV4_NODE, &bgp_imexport_vrf_cmd);
15285 install_element(BGP_IPV6_NODE, &bgp_imexport_vrf_cmd);
15286
15287 /* ttl_security commands */
15288 install_element(BGP_NODE, &neighbor_ttl_security_cmd);
15289 install_element(BGP_NODE, &no_neighbor_ttl_security_cmd);
15290
15291 /* "show [ip] bgp memory" commands. */
15292 install_element(VIEW_NODE, &show_bgp_memory_cmd);
15293
15294 /* "show bgp martian next-hop" */
15295 install_element(VIEW_NODE, &show_bgp_martian_nexthop_db_cmd);
15296
15297 install_element(VIEW_NODE, &show_bgp_mac_hash_cmd);
15298
15299 /* "show [ip] bgp views" commands. */
15300 install_element(VIEW_NODE, &show_bgp_views_cmd);
15301
15302 /* "show [ip] bgp vrfs" commands. */
15303 install_element(VIEW_NODE, &show_bgp_vrfs_cmd);
15304
15305 /* Community-list. */
15306 community_list_vty();
15307
15308 /* vpn-policy commands */
15309 install_element(BGP_IPV4_NODE, &af_rd_vpn_export_cmd);
15310 install_element(BGP_IPV6_NODE, &af_rd_vpn_export_cmd);
15311 install_element(BGP_IPV4_NODE, &af_label_vpn_export_cmd);
15312 install_element(BGP_IPV6_NODE, &af_label_vpn_export_cmd);
15313 install_element(BGP_IPV4_NODE, &af_nexthop_vpn_export_cmd);
15314 install_element(BGP_IPV6_NODE, &af_nexthop_vpn_export_cmd);
15315 install_element(BGP_IPV4_NODE, &af_rt_vpn_imexport_cmd);
15316 install_element(BGP_IPV6_NODE, &af_rt_vpn_imexport_cmd);
15317 install_element(BGP_IPV4_NODE, &af_route_map_vpn_imexport_cmd);
15318 install_element(BGP_IPV6_NODE, &af_route_map_vpn_imexport_cmd);
15319 install_element(BGP_IPV4_NODE, &af_import_vrf_route_map_cmd);
15320 install_element(BGP_IPV6_NODE, &af_import_vrf_route_map_cmd);
15321
15322 install_element(BGP_IPV4_NODE, &af_routetarget_import_cmd);
15323 install_element(BGP_IPV6_NODE, &af_routetarget_import_cmd);
15324
15325 install_element(BGP_IPV4_NODE, &af_no_rd_vpn_export_cmd);
15326 install_element(BGP_IPV6_NODE, &af_no_rd_vpn_export_cmd);
15327 install_element(BGP_IPV4_NODE, &af_no_label_vpn_export_cmd);
15328 install_element(BGP_IPV6_NODE, &af_no_label_vpn_export_cmd);
15329 install_element(BGP_IPV4_NODE, &af_no_nexthop_vpn_export_cmd);
15330 install_element(BGP_IPV6_NODE, &af_no_nexthop_vpn_export_cmd);
15331 install_element(BGP_IPV4_NODE, &af_no_rt_vpn_imexport_cmd);
15332 install_element(BGP_IPV6_NODE, &af_no_rt_vpn_imexport_cmd);
15333 install_element(BGP_IPV4_NODE, &af_no_route_map_vpn_imexport_cmd);
15334 install_element(BGP_IPV6_NODE, &af_no_route_map_vpn_imexport_cmd);
15335 install_element(BGP_IPV4_NODE, &af_no_import_vrf_route_map_cmd);
15336 install_element(BGP_IPV6_NODE, &af_no_import_vrf_route_map_cmd);
15337 }
15338
15339 #include "memory.h"
15340 #include "bgp_regex.h"
15341 #include "bgp_clist.h"
15342 #include "bgp_ecommunity.h"
15343
15344 /* VTY functions. */
15345
15346 /* Direction value to string conversion. */
15347 static const char *community_direct_str(int direct)
15348 {
15349 switch (direct) {
15350 case COMMUNITY_DENY:
15351 return "deny";
15352 case COMMUNITY_PERMIT:
15353 return "permit";
15354 default:
15355 return "unknown";
15356 }
15357 }
15358
15359 /* Display error string. */
15360 static void community_list_perror(struct vty *vty, int ret)
15361 {
15362 switch (ret) {
15363 case COMMUNITY_LIST_ERR_CANT_FIND_LIST:
15364 vty_out(vty, "%% Can't find community-list\n");
15365 break;
15366 case COMMUNITY_LIST_ERR_MALFORMED_VAL:
15367 vty_out(vty, "%% Malformed community-list value\n");
15368 break;
15369 case COMMUNITY_LIST_ERR_STANDARD_CONFLICT:
15370 vty_out(vty,
15371 "%% Community name conflict, previously defined as standard community\n");
15372 break;
15373 case COMMUNITY_LIST_ERR_EXPANDED_CONFLICT:
15374 vty_out(vty,
15375 "%% Community name conflict, previously defined as expanded community\n");
15376 break;
15377 }
15378 }
15379
15380 /* "community-list" keyword help string. */
15381 #define COMMUNITY_LIST_STR "Add a community list entry\n"
15382
15383 /*community-list standard */
15384 DEFUN (community_list_standard,
15385 bgp_community_list_standard_cmd,
15386 "bgp community-list <(1-99)|standard WORD> <deny|permit> AA:NN...",
15387 BGP_STR
15388 COMMUNITY_LIST_STR
15389 "Community list number (standard)\n"
15390 "Add an standard community-list entry\n"
15391 "Community list name\n"
15392 "Specify community to reject\n"
15393 "Specify community to accept\n"
15394 COMMUNITY_VAL_STR)
15395 {
15396 char *cl_name_or_number = NULL;
15397 int direct = 0;
15398 int style = COMMUNITY_LIST_STANDARD;
15399 int idx = 0;
15400
15401 argv_find(argv, argc, "(1-99)", &idx);
15402 argv_find(argv, argc, "WORD", &idx);
15403 cl_name_or_number = argv[idx]->arg;
15404 direct = argv_find(argv, argc, "permit", &idx) ? COMMUNITY_PERMIT
15405 : COMMUNITY_DENY;
15406 argv_find(argv, argc, "AA:NN", &idx);
15407 char *str = argv_concat(argv, argc, idx);
15408
15409 int ret = community_list_set(bgp_clist, cl_name_or_number, str, direct,
15410 style);
15411
15412 XFREE(MTYPE_TMP, str);
15413
15414 if (ret < 0) {
15415 /* Display error string. */
15416 community_list_perror(vty, ret);
15417 return CMD_WARNING_CONFIG_FAILED;
15418 }
15419
15420 return CMD_SUCCESS;
15421 }
15422
15423 DEFUN (no_community_list_standard_all,
15424 no_bgp_community_list_standard_all_cmd,
15425 "no bgp community-list <(1-99)|standard WORD> <deny|permit> AA:NN...",
15426 NO_STR
15427 BGP_STR
15428 COMMUNITY_LIST_STR
15429 "Community list number (standard)\n"
15430 "Add an standard community-list entry\n"
15431 "Community list name\n"
15432 "Specify community to reject\n"
15433 "Specify community to accept\n"
15434 COMMUNITY_VAL_STR)
15435 {
15436 char *cl_name_or_number = NULL;
15437 char *str = NULL;
15438 int direct = 0;
15439 int style = COMMUNITY_LIST_STANDARD;
15440
15441 int idx = 0;
15442
15443 argv_find(argv, argc, "permit", &idx);
15444 argv_find(argv, argc, "deny", &idx);
15445
15446 if (idx) {
15447 direct = argv_find(argv, argc, "permit", &idx)
15448 ? COMMUNITY_PERMIT
15449 : COMMUNITY_DENY;
15450
15451 idx = 0;
15452 argv_find(argv, argc, "AA:NN", &idx);
15453 str = argv_concat(argv, argc, idx);
15454 }
15455
15456 idx = 0;
15457 argv_find(argv, argc, "(1-99)", &idx);
15458 argv_find(argv, argc, "WORD", &idx);
15459 cl_name_or_number = argv[idx]->arg;
15460
15461 int ret = community_list_unset(bgp_clist, cl_name_or_number, str,
15462 direct, style);
15463
15464 XFREE(MTYPE_TMP, str);
15465
15466 if (ret < 0) {
15467 community_list_perror(vty, ret);
15468 return CMD_WARNING_CONFIG_FAILED;
15469 }
15470
15471 return CMD_SUCCESS;
15472 }
15473
15474 ALIAS(no_community_list_standard_all, no_bgp_community_list_standard_all_list_cmd,
15475 "no bgp community-list <(1-99)|standard WORD>",
15476 NO_STR BGP_STR COMMUNITY_LIST_STR
15477 "Community list number (standard)\n"
15478 "Add an standard community-list entry\n"
15479 "Community list name\n")
15480
15481 /*community-list expanded */
15482 DEFUN (community_list_expanded_all,
15483 bgp_community_list_expanded_all_cmd,
15484 "bgp community-list <(100-500)|expanded WORD> <deny|permit> AA:NN...",
15485 BGP_STR
15486 COMMUNITY_LIST_STR
15487 "Community list number (expanded)\n"
15488 "Add an expanded community-list entry\n"
15489 "Community list name\n"
15490 "Specify community to reject\n"
15491 "Specify community to accept\n"
15492 COMMUNITY_VAL_STR)
15493 {
15494 char *cl_name_or_number = NULL;
15495 int direct = 0;
15496 int style = COMMUNITY_LIST_EXPANDED;
15497
15498 int idx = 0;
15499
15500 argv_find(argv, argc, "(100-500)", &idx);
15501 argv_find(argv, argc, "WORD", &idx);
15502 cl_name_or_number = argv[idx]->arg;
15503 direct = argv_find(argv, argc, "permit", &idx) ? COMMUNITY_PERMIT
15504 : COMMUNITY_DENY;
15505 argv_find(argv, argc, "AA:NN", &idx);
15506 char *str = argv_concat(argv, argc, idx);
15507
15508 int ret = community_list_set(bgp_clist, cl_name_or_number, str, direct,
15509 style);
15510
15511 XFREE(MTYPE_TMP, str);
15512
15513 if (ret < 0) {
15514 /* Display error string. */
15515 community_list_perror(vty, ret);
15516 return CMD_WARNING_CONFIG_FAILED;
15517 }
15518
15519 return CMD_SUCCESS;
15520 }
15521
15522 DEFUN (no_community_list_expanded_all,
15523 no_bgp_community_list_expanded_all_cmd,
15524 "no bgp community-list <(100-500)|expanded WORD> <deny|permit> AA:NN...",
15525 NO_STR
15526 BGP_STR
15527 COMMUNITY_LIST_STR
15528 "Community list number (expanded)\n"
15529 "Add an expanded community-list entry\n"
15530 "Community list name\n"
15531 "Specify community to reject\n"
15532 "Specify community to accept\n"
15533 COMMUNITY_VAL_STR)
15534 {
15535 char *cl_name_or_number = NULL;
15536 char *str = NULL;
15537 int direct = 0;
15538 int style = COMMUNITY_LIST_EXPANDED;
15539
15540 int idx = 0;
15541
15542 argv_find(argv, argc, "permit", &idx);
15543 argv_find(argv, argc, "deny", &idx);
15544
15545 if (idx) {
15546 direct = argv_find(argv, argc, "permit", &idx)
15547 ? COMMUNITY_PERMIT
15548 : COMMUNITY_DENY;
15549
15550 idx = 0;
15551 argv_find(argv, argc, "AA:NN", &idx);
15552 str = argv_concat(argv, argc, idx);
15553 }
15554
15555 idx = 0;
15556 argv_find(argv, argc, "(100-500)", &idx);
15557 argv_find(argv, argc, "WORD", &idx);
15558 cl_name_or_number = argv[idx]->arg;
15559
15560 int ret = community_list_unset(bgp_clist, cl_name_or_number, str,
15561 direct, style);
15562
15563 XFREE(MTYPE_TMP, str);
15564
15565 if (ret < 0) {
15566 community_list_perror(vty, ret);
15567 return CMD_WARNING_CONFIG_FAILED;
15568 }
15569
15570 return CMD_SUCCESS;
15571 }
15572
15573 ALIAS(no_community_list_expanded_all, no_bgp_community_list_expanded_all_list_cmd,
15574 "no bgp community-list <(100-500)|expanded WORD>",
15575 NO_STR IP_STR COMMUNITY_LIST_STR
15576 "Community list number (expanded)\n"
15577 "Add an expanded community-list entry\n"
15578 "Community list name\n")
15579
15580 /* Return configuration string of community-list entry. */
15581 static const char *community_list_config_str(struct community_entry *entry)
15582 {
15583 const char *str;
15584
15585 if (entry->any)
15586 str = "";
15587 else {
15588 if (entry->style == COMMUNITY_LIST_STANDARD)
15589 str = community_str(entry->u.com, false);
15590 else if (entry->style == LARGE_COMMUNITY_LIST_STANDARD)
15591 str = lcommunity_str(entry->u.lcom, false);
15592 else
15593 str = entry->config;
15594 }
15595 return str;
15596 }
15597
15598 static void community_list_show(struct vty *vty, struct community_list *list)
15599 {
15600 struct community_entry *entry;
15601
15602 for (entry = list->head; entry; entry = entry->next) {
15603 if (entry == list->head) {
15604 if (all_digit(list->name))
15605 vty_out(vty, "Community %s list %s\n",
15606 entry->style == COMMUNITY_LIST_STANDARD
15607 ? "standard"
15608 : "(expanded) access",
15609 list->name);
15610 else
15611 vty_out(vty, "Named Community %s list %s\n",
15612 entry->style == COMMUNITY_LIST_STANDARD
15613 ? "standard"
15614 : "expanded",
15615 list->name);
15616 }
15617 if (entry->any)
15618 vty_out(vty, " %s\n",
15619 community_direct_str(entry->direct));
15620 else
15621 vty_out(vty, " %s %s\n",
15622 community_direct_str(entry->direct),
15623 community_list_config_str(entry));
15624 }
15625 }
15626
15627 DEFUN (show_community_list,
15628 show_bgp_community_list_cmd,
15629 "show bgp community-list",
15630 SHOW_STR
15631 BGP_STR
15632 "List community-list\n")
15633 {
15634 struct community_list *list;
15635 struct community_list_master *cm;
15636
15637 cm = community_list_master_lookup(bgp_clist, COMMUNITY_LIST_MASTER);
15638 if (!cm)
15639 return CMD_SUCCESS;
15640
15641 for (list = cm->num.head; list; list = list->next)
15642 community_list_show(vty, list);
15643
15644 for (list = cm->str.head; list; list = list->next)
15645 community_list_show(vty, list);
15646
15647 return CMD_SUCCESS;
15648 }
15649
15650 DEFUN (show_community_list_arg,
15651 show_bgp_community_list_arg_cmd,
15652 "show bgp community-list <(1-500)|WORD> detail",
15653 SHOW_STR
15654 BGP_STR
15655 "List community-list\n"
15656 "Community-list number\n"
15657 "Community-list name\n"
15658 "Detailed information on community-list\n")
15659 {
15660 int idx_comm_list = 3;
15661 struct community_list *list;
15662
15663 list = community_list_lookup(bgp_clist, argv[idx_comm_list]->arg, 0,
15664 COMMUNITY_LIST_MASTER);
15665 if (!list) {
15666 vty_out(vty, "%% Can't find community-list\n");
15667 return CMD_WARNING;
15668 }
15669
15670 community_list_show(vty, list);
15671
15672 return CMD_SUCCESS;
15673 }
15674
15675 /*
15676 * Large Community code.
15677 */
15678 static int lcommunity_list_set_vty(struct vty *vty, int argc,
15679 struct cmd_token **argv, int style,
15680 int reject_all_digit_name)
15681 {
15682 int ret;
15683 int direct;
15684 char *str;
15685 int idx = 0;
15686 char *cl_name;
15687
15688 direct = argv_find(argv, argc, "permit", &idx) ? COMMUNITY_PERMIT
15689 : COMMUNITY_DENY;
15690
15691 /* All digit name check. */
15692 idx = 0;
15693 argv_find(argv, argc, "WORD", &idx);
15694 argv_find(argv, argc, "(1-99)", &idx);
15695 argv_find(argv, argc, "(100-500)", &idx);
15696 cl_name = argv[idx]->arg;
15697 if (reject_all_digit_name && all_digit(cl_name)) {
15698 vty_out(vty, "%% Community name cannot have all digits\n");
15699 return CMD_WARNING_CONFIG_FAILED;
15700 }
15701
15702 idx = 0;
15703 argv_find(argv, argc, "AA:BB:CC", &idx);
15704 argv_find(argv, argc, "LINE", &idx);
15705 /* Concat community string argument. */
15706 if (idx)
15707 str = argv_concat(argv, argc, idx);
15708 else
15709 str = NULL;
15710
15711 ret = lcommunity_list_set(bgp_clist, cl_name, str, direct, style);
15712
15713 /* Free temporary community list string allocated by
15714 argv_concat(). */
15715 XFREE(MTYPE_TMP, str);
15716
15717 if (ret < 0) {
15718 community_list_perror(vty, ret);
15719 return CMD_WARNING_CONFIG_FAILED;
15720 }
15721 return CMD_SUCCESS;
15722 }
15723
15724 static int lcommunity_list_unset_vty(struct vty *vty, int argc,
15725 struct cmd_token **argv, int style)
15726 {
15727 int ret;
15728 int direct = 0;
15729 char *str = NULL;
15730 int idx = 0;
15731
15732 argv_find(argv, argc, "permit", &idx);
15733 argv_find(argv, argc, "deny", &idx);
15734
15735 if (idx) {
15736 /* Check the list direct. */
15737 if (strncmp(argv[idx]->arg, "p", 1) == 0)
15738 direct = COMMUNITY_PERMIT;
15739 else
15740 direct = COMMUNITY_DENY;
15741
15742 idx = 0;
15743 argv_find(argv, argc, "LINE", &idx);
15744 argv_find(argv, argc, "AA:AA:NN", &idx);
15745 /* Concat community string argument. */
15746 str = argv_concat(argv, argc, idx);
15747 }
15748
15749 idx = 0;
15750 argv_find(argv, argc, "(1-99)", &idx);
15751 argv_find(argv, argc, "(100-500)", &idx);
15752 argv_find(argv, argc, "WORD", &idx);
15753
15754 /* Unset community list. */
15755 ret = lcommunity_list_unset(bgp_clist, argv[idx]->arg, str, direct,
15756 style);
15757
15758 /* Free temporary community list string allocated by
15759 argv_concat(). */
15760 XFREE(MTYPE_TMP, str);
15761
15762 if (ret < 0) {
15763 community_list_perror(vty, ret);
15764 return CMD_WARNING_CONFIG_FAILED;
15765 }
15766
15767 return CMD_SUCCESS;
15768 }
15769
15770 /* "large-community-list" keyword help string. */
15771 #define LCOMMUNITY_LIST_STR "Add a large community list entry\n"
15772 #define LCOMMUNITY_VAL_STR "large community in 'aa:bb:cc' format\n"
15773
15774 DEFUN (lcommunity_list_standard,
15775 bgp_lcommunity_list_standard_cmd,
15776 "bgp large-community-list (1-99) <deny|permit> AA:BB:CC...",
15777 BGP_STR
15778 LCOMMUNITY_LIST_STR
15779 "Large Community list number (standard)\n"
15780 "Specify large community to reject\n"
15781 "Specify large community to accept\n"
15782 LCOMMUNITY_VAL_STR)
15783 {
15784 return lcommunity_list_set_vty(vty, argc, argv,
15785 LARGE_COMMUNITY_LIST_STANDARD, 0);
15786 }
15787
15788 DEFUN (lcommunity_list_expanded,
15789 bgp_lcommunity_list_expanded_cmd,
15790 "bgp large-community-list (100-500) <deny|permit> LINE...",
15791 BGP_STR
15792 LCOMMUNITY_LIST_STR
15793 "Large Community list number (expanded)\n"
15794 "Specify large community to reject\n"
15795 "Specify large community to accept\n"
15796 "An ordered list as a regular-expression\n")
15797 {
15798 return lcommunity_list_set_vty(vty, argc, argv,
15799 LARGE_COMMUNITY_LIST_EXPANDED, 0);
15800 }
15801
15802 DEFUN (lcommunity_list_name_standard,
15803 bgp_lcommunity_list_name_standard_cmd,
15804 "bgp large-community-list standard WORD <deny|permit> AA:BB:CC...",
15805 BGP_STR
15806 LCOMMUNITY_LIST_STR
15807 "Specify standard large-community-list\n"
15808 "Large Community list name\n"
15809 "Specify large community to reject\n"
15810 "Specify large community to accept\n"
15811 LCOMMUNITY_VAL_STR)
15812 {
15813 return lcommunity_list_set_vty(vty, argc, argv,
15814 LARGE_COMMUNITY_LIST_STANDARD, 1);
15815 }
15816
15817 DEFUN (lcommunity_list_name_expanded,
15818 bgp_lcommunity_list_name_expanded_cmd,
15819 "bgp large-community-list expanded WORD <deny|permit> LINE...",
15820 BGP_STR
15821 LCOMMUNITY_LIST_STR
15822 "Specify expanded large-community-list\n"
15823 "Large Community list name\n"
15824 "Specify large community to reject\n"
15825 "Specify large community to accept\n"
15826 "An ordered list as a regular-expression\n")
15827 {
15828 return lcommunity_list_set_vty(vty, argc, argv,
15829 LARGE_COMMUNITY_LIST_EXPANDED, 1);
15830 }
15831
15832 DEFUN (no_lcommunity_list_standard_all,
15833 no_bgp_lcommunity_list_standard_all_cmd,
15834 "no bgp large-community-list <(1-99)|(100-500)|WORD>",
15835 NO_STR
15836 BGP_STR
15837 LCOMMUNITY_LIST_STR
15838 "Large Community list number (standard)\n"
15839 "Large Community list number (expanded)\n"
15840 "Large Community list name\n")
15841 {
15842 return lcommunity_list_unset_vty(vty, argc, argv,
15843 LARGE_COMMUNITY_LIST_STANDARD);
15844 }
15845
15846 DEFUN (no_lcommunity_list_name_expanded_all,
15847 no_bgp_lcommunity_list_name_expanded_all_cmd,
15848 "no bgp large-community-list expanded WORD",
15849 NO_STR
15850 BGP_STR
15851 LCOMMUNITY_LIST_STR
15852 "Specify expanded large-community-list\n"
15853 "Large Community list name\n")
15854 {
15855 return lcommunity_list_unset_vty(vty, argc, argv,
15856 LARGE_COMMUNITY_LIST_EXPANDED);
15857 }
15858
15859 DEFUN (no_lcommunity_list_standard,
15860 no_bgp_lcommunity_list_standard_cmd,
15861 "no bgp large-community-list (1-99) <deny|permit> AA:AA:NN...",
15862 NO_STR
15863 BGP_STR
15864 LCOMMUNITY_LIST_STR
15865 "Large Community list number (standard)\n"
15866 "Specify large community to reject\n"
15867 "Specify large community to accept\n"
15868 LCOMMUNITY_VAL_STR)
15869 {
15870 return lcommunity_list_unset_vty(vty, argc, argv,
15871 LARGE_COMMUNITY_LIST_STANDARD);
15872 }
15873
15874 DEFUN (no_lcommunity_list_expanded,
15875 no_bgp_lcommunity_list_expanded_cmd,
15876 "no bgp large-community-list (100-500) <deny|permit> LINE...",
15877 NO_STR
15878 BGP_STR
15879 LCOMMUNITY_LIST_STR
15880 "Large Community list number (expanded)\n"
15881 "Specify large community to reject\n"
15882 "Specify large community to accept\n"
15883 "An ordered list as a regular-expression\n")
15884 {
15885 return lcommunity_list_unset_vty(vty, argc, argv,
15886 LARGE_COMMUNITY_LIST_EXPANDED);
15887 }
15888
15889 DEFUN (no_lcommunity_list_name_standard,
15890 no_bgp_lcommunity_list_name_standard_cmd,
15891 "no bgp large-community-list standard WORD <deny|permit> AA:AA:NN...",
15892 NO_STR
15893 BGP_STR
15894 LCOMMUNITY_LIST_STR
15895 "Specify standard large-community-list\n"
15896 "Large Community list name\n"
15897 "Specify large community to reject\n"
15898 "Specify large community to accept\n"
15899 LCOMMUNITY_VAL_STR)
15900 {
15901 return lcommunity_list_unset_vty(vty, argc, argv,
15902 LARGE_COMMUNITY_LIST_STANDARD);
15903 }
15904
15905 DEFUN (no_lcommunity_list_name_expanded,
15906 no_bgp_lcommunity_list_name_expanded_cmd,
15907 "no bgp large-community-list expanded WORD <deny|permit> LINE...",
15908 NO_STR
15909 BGP_STR
15910 LCOMMUNITY_LIST_STR
15911 "Specify expanded large-community-list\n"
15912 "Large community list name\n"
15913 "Specify large community to reject\n"
15914 "Specify large community to accept\n"
15915 "An ordered list as a regular-expression\n")
15916 {
15917 return lcommunity_list_unset_vty(vty, argc, argv,
15918 LARGE_COMMUNITY_LIST_EXPANDED);
15919 }
15920
15921 static void lcommunity_list_show(struct vty *vty, struct community_list *list)
15922 {
15923 struct community_entry *entry;
15924
15925 for (entry = list->head; entry; entry = entry->next) {
15926 if (entry == list->head) {
15927 if (all_digit(list->name))
15928 vty_out(vty, "Large community %s list %s\n",
15929 entry->style ==
15930 LARGE_COMMUNITY_LIST_STANDARD
15931 ? "standard"
15932 : "(expanded) access",
15933 list->name);
15934 else
15935 vty_out(vty,
15936 "Named large community %s list %s\n",
15937 entry->style ==
15938 LARGE_COMMUNITY_LIST_STANDARD
15939 ? "standard"
15940 : "expanded",
15941 list->name);
15942 }
15943 if (entry->any)
15944 vty_out(vty, " %s\n",
15945 community_direct_str(entry->direct));
15946 else
15947 vty_out(vty, " %s %s\n",
15948 community_direct_str(entry->direct),
15949 community_list_config_str(entry));
15950 }
15951 }
15952
15953 DEFUN (show_lcommunity_list,
15954 show_bgp_lcommunity_list_cmd,
15955 "show bgp large-community-list",
15956 SHOW_STR
15957 BGP_STR
15958 "List large-community list\n")
15959 {
15960 struct community_list *list;
15961 struct community_list_master *cm;
15962
15963 cm = community_list_master_lookup(bgp_clist,
15964 LARGE_COMMUNITY_LIST_MASTER);
15965 if (!cm)
15966 return CMD_SUCCESS;
15967
15968 for (list = cm->num.head; list; list = list->next)
15969 lcommunity_list_show(vty, list);
15970
15971 for (list = cm->str.head; list; list = list->next)
15972 lcommunity_list_show(vty, list);
15973
15974 return CMD_SUCCESS;
15975 }
15976
15977 DEFUN (show_lcommunity_list_arg,
15978 show_bgp_lcommunity_list_arg_cmd,
15979 "show bgp large-community-list <(1-500)|WORD> detail",
15980 SHOW_STR
15981 BGP_STR
15982 "List large-community list\n"
15983 "Large-community-list number\n"
15984 "Large-community-list name\n"
15985 "Detailed information on large-community-list\n")
15986 {
15987 struct community_list *list;
15988
15989 list = community_list_lookup(bgp_clist, argv[3]->arg, 0,
15990 LARGE_COMMUNITY_LIST_MASTER);
15991 if (!list) {
15992 vty_out(vty, "%% Can't find large-community-list\n");
15993 return CMD_WARNING;
15994 }
15995
15996 lcommunity_list_show(vty, list);
15997
15998 return CMD_SUCCESS;
15999 }
16000
16001 /* "extcommunity-list" keyword help string. */
16002 #define EXTCOMMUNITY_LIST_STR "Add a extended community list entry\n"
16003 #define EXTCOMMUNITY_VAL_STR "Extended community attribute in 'rt aa:nn_or_IPaddr:nn' OR 'soo aa:nn_or_IPaddr:nn' format\n"
16004
16005 DEFUN (extcommunity_list_standard,
16006 bgp_extcommunity_list_standard_cmd,
16007 "bgp extcommunity-list <(1-99)|standard WORD> <deny|permit> AA:NN...",
16008 BGP_STR
16009 EXTCOMMUNITY_LIST_STR
16010 "Extended Community list number (standard)\n"
16011 "Specify standard extcommunity-list\n"
16012 "Community list name\n"
16013 "Specify community to reject\n"
16014 "Specify community to accept\n"
16015 EXTCOMMUNITY_VAL_STR)
16016 {
16017 int style = EXTCOMMUNITY_LIST_STANDARD;
16018 int direct = 0;
16019 char *cl_number_or_name = NULL;
16020
16021 int idx = 0;
16022
16023 argv_find(argv, argc, "(1-99)", &idx);
16024 argv_find(argv, argc, "WORD", &idx);
16025 cl_number_or_name = argv[idx]->arg;
16026 direct = argv_find(argv, argc, "permit", &idx) ? COMMUNITY_PERMIT
16027 : COMMUNITY_DENY;
16028 argv_find(argv, argc, "AA:NN", &idx);
16029 char *str = argv_concat(argv, argc, idx);
16030
16031 int ret = extcommunity_list_set(bgp_clist, cl_number_or_name, str,
16032 direct, style);
16033
16034 XFREE(MTYPE_TMP, str);
16035
16036 if (ret < 0) {
16037 community_list_perror(vty, ret);
16038 return CMD_WARNING_CONFIG_FAILED;
16039 }
16040
16041 return CMD_SUCCESS;
16042 }
16043
16044 DEFUN (extcommunity_list_name_expanded,
16045 bgp_extcommunity_list_name_expanded_cmd,
16046 "bgp extcommunity-list <(100-500)|expanded WORD> <deny|permit> LINE...",
16047 BGP_STR
16048 EXTCOMMUNITY_LIST_STR
16049 "Extended Community list number (expanded)\n"
16050 "Specify expanded extcommunity-list\n"
16051 "Extended Community list name\n"
16052 "Specify community to reject\n"
16053 "Specify community to accept\n"
16054 "An ordered list as a regular-expression\n")
16055 {
16056 int style = EXTCOMMUNITY_LIST_EXPANDED;
16057 int direct = 0;
16058 char *cl_number_or_name = NULL;
16059 int idx = 0;
16060
16061 argv_find(argv, argc, "(100-500)", &idx);
16062 argv_find(argv, argc, "WORD", &idx);
16063 cl_number_or_name = argv[idx]->arg;
16064 direct = argv_find(argv, argc, "permit", &idx) ? COMMUNITY_PERMIT
16065 : COMMUNITY_DENY;
16066 argv_find(argv, argc, "LINE", &idx);
16067 char *str = argv_concat(argv, argc, idx);
16068
16069 int ret = extcommunity_list_set(bgp_clist, cl_number_or_name, str,
16070 direct, style);
16071
16072 XFREE(MTYPE_TMP, str);
16073
16074 if (ret < 0) {
16075 community_list_perror(vty, ret);
16076 return CMD_WARNING_CONFIG_FAILED;
16077 }
16078
16079 return CMD_SUCCESS;
16080 }
16081
16082 DEFUN (no_extcommunity_list_standard_all,
16083 no_bgp_extcommunity_list_standard_all_cmd,
16084 "no bgp extcommunity-list <(1-99)|standard WORD> <deny|permit> AA:NN...",
16085 NO_STR
16086 BGP_STR
16087 EXTCOMMUNITY_LIST_STR
16088 "Extended Community list number (standard)\n"
16089 "Specify standard extcommunity-list\n"
16090 "Community list name\n"
16091 "Specify community to reject\n"
16092 "Specify community to accept\n"
16093 EXTCOMMUNITY_VAL_STR)
16094 {
16095 int style = EXTCOMMUNITY_LIST_STANDARD;
16096 int direct = 0;
16097 char *cl_number_or_name = NULL;
16098 char *str = NULL;
16099 int idx = 0;
16100
16101 argv_find(argv, argc, "permit", &idx);
16102 argv_find(argv, argc, "deny", &idx);
16103
16104 if (idx) {
16105 direct = argv_find(argv, argc, "permit", &idx)
16106 ? COMMUNITY_PERMIT
16107 : COMMUNITY_DENY;
16108
16109 idx = 0;
16110 argv_find(argv, argc, "AA:NN", &idx);
16111 str = argv_concat(argv, argc, idx);
16112 }
16113
16114 idx = 0;
16115 argv_find(argv, argc, "(1-99)", &idx);
16116 argv_find(argv, argc, "WORD", &idx);
16117 cl_number_or_name = argv[idx]->arg;
16118
16119 int ret = extcommunity_list_unset(bgp_clist, cl_number_or_name, str,
16120 direct, style);
16121
16122 XFREE(MTYPE_TMP, str);
16123
16124 if (ret < 0) {
16125 community_list_perror(vty, ret);
16126 return CMD_WARNING_CONFIG_FAILED;
16127 }
16128
16129 return CMD_SUCCESS;
16130 }
16131
16132 ALIAS(no_extcommunity_list_standard_all,
16133 no_bgp_extcommunity_list_standard_all_list_cmd,
16134 "no bgp extcommunity-list <(1-99)|standard WORD>",
16135 NO_STR IP_STR EXTCOMMUNITY_LIST_STR
16136 "Extended Community list number (standard)\n"
16137 "Specify standard extcommunity-list\n"
16138 "Community list name\n")
16139
16140 DEFUN (no_extcommunity_list_expanded_all,
16141 no_bgp_extcommunity_list_expanded_all_cmd,
16142 "no bgp extcommunity-list <(100-500)|expanded WORD> <deny|permit> LINE...",
16143 NO_STR
16144 BGP_STR
16145 EXTCOMMUNITY_LIST_STR
16146 "Extended Community list number (expanded)\n"
16147 "Specify expanded extcommunity-list\n"
16148 "Extended Community list name\n"
16149 "Specify community to reject\n"
16150 "Specify community to accept\n"
16151 "An ordered list as a regular-expression\n")
16152 {
16153 int style = EXTCOMMUNITY_LIST_EXPANDED;
16154 int direct = 0;
16155 char *cl_number_or_name = NULL;
16156 char *str = NULL;
16157 int idx = 0;
16158
16159 argv_find(argv, argc, "permit", &idx);
16160 argv_find(argv, argc, "deny", &idx);
16161
16162 if (idx) {
16163 direct = argv_find(argv, argc, "permit", &idx)
16164 ? COMMUNITY_PERMIT
16165 : COMMUNITY_DENY;
16166
16167 idx = 0;
16168 argv_find(argv, argc, "LINE", &idx);
16169 str = argv_concat(argv, argc, idx);
16170 }
16171
16172 idx = 0;
16173 argv_find(argv, argc, "(100-500)", &idx);
16174 argv_find(argv, argc, "WORD", &idx);
16175 cl_number_or_name = argv[idx]->arg;
16176
16177 int ret = extcommunity_list_unset(bgp_clist, cl_number_or_name, str,
16178 direct, style);
16179
16180 XFREE(MTYPE_TMP, str);
16181
16182 if (ret < 0) {
16183 community_list_perror(vty, ret);
16184 return CMD_WARNING_CONFIG_FAILED;
16185 }
16186
16187 return CMD_SUCCESS;
16188 }
16189
16190 ALIAS(no_extcommunity_list_expanded_all,
16191 no_bgp_extcommunity_list_expanded_all_list_cmd,
16192 "no bgp extcommunity-list <(100-500)|expanded WORD>",
16193 NO_STR IP_STR EXTCOMMUNITY_LIST_STR
16194 "Extended Community list number (expanded)\n"
16195 "Specify expanded extcommunity-list\n"
16196 "Extended Community list name\n")
16197
16198 static void extcommunity_list_show(struct vty *vty, struct community_list *list)
16199 {
16200 struct community_entry *entry;
16201
16202 for (entry = list->head; entry; entry = entry->next) {
16203 if (entry == list->head) {
16204 if (all_digit(list->name))
16205 vty_out(vty, "Extended community %s list %s\n",
16206 entry->style == EXTCOMMUNITY_LIST_STANDARD
16207 ? "standard"
16208 : "(expanded) access",
16209 list->name);
16210 else
16211 vty_out(vty,
16212 "Named extended community %s list %s\n",
16213 entry->style == EXTCOMMUNITY_LIST_STANDARD
16214 ? "standard"
16215 : "expanded",
16216 list->name);
16217 }
16218 if (entry->any)
16219 vty_out(vty, " %s\n",
16220 community_direct_str(entry->direct));
16221 else
16222 vty_out(vty, " %s %s\n",
16223 community_direct_str(entry->direct),
16224 community_list_config_str(entry));
16225 }
16226 }
16227
16228 DEFUN (show_extcommunity_list,
16229 show_bgp_extcommunity_list_cmd,
16230 "show bgp extcommunity-list",
16231 SHOW_STR
16232 BGP_STR
16233 "List extended-community list\n")
16234 {
16235 struct community_list *list;
16236 struct community_list_master *cm;
16237
16238 cm = community_list_master_lookup(bgp_clist, EXTCOMMUNITY_LIST_MASTER);
16239 if (!cm)
16240 return CMD_SUCCESS;
16241
16242 for (list = cm->num.head; list; list = list->next)
16243 extcommunity_list_show(vty, list);
16244
16245 for (list = cm->str.head; list; list = list->next)
16246 extcommunity_list_show(vty, list);
16247
16248 return CMD_SUCCESS;
16249 }
16250
16251 DEFUN (show_extcommunity_list_arg,
16252 show_bgp_extcommunity_list_arg_cmd,
16253 "show bgp extcommunity-list <(1-500)|WORD> detail",
16254 SHOW_STR
16255 BGP_STR
16256 "List extended-community list\n"
16257 "Extcommunity-list number\n"
16258 "Extcommunity-list name\n"
16259 "Detailed information on extcommunity-list\n")
16260 {
16261 int idx_comm_list = 3;
16262 struct community_list *list;
16263
16264 list = community_list_lookup(bgp_clist, argv[idx_comm_list]->arg, 0,
16265 EXTCOMMUNITY_LIST_MASTER);
16266 if (!list) {
16267 vty_out(vty, "%% Can't find extcommunity-list\n");
16268 return CMD_WARNING;
16269 }
16270
16271 extcommunity_list_show(vty, list);
16272
16273 return CMD_SUCCESS;
16274 }
16275
16276 /* Display community-list and extcommunity-list configuration. */
16277 static int community_list_config_write(struct vty *vty)
16278 {
16279 struct community_list *list;
16280 struct community_entry *entry;
16281 struct community_list_master *cm;
16282 int write = 0;
16283
16284 /* Community-list. */
16285 cm = community_list_master_lookup(bgp_clist, COMMUNITY_LIST_MASTER);
16286
16287 for (list = cm->num.head; list; list = list->next)
16288 for (entry = list->head; entry; entry = entry->next) {
16289 vty_out(vty, "bgp community-list %s %s %s\n", list->name,
16290 community_direct_str(entry->direct),
16291 community_list_config_str(entry));
16292 write++;
16293 }
16294 for (list = cm->str.head; list; list = list->next)
16295 for (entry = list->head; entry; entry = entry->next) {
16296 vty_out(vty, "bgp community-list %s %s %s %s\n",
16297 entry->style == COMMUNITY_LIST_STANDARD
16298 ? "standard"
16299 : "expanded",
16300 list->name, community_direct_str(entry->direct),
16301 community_list_config_str(entry));
16302 write++;
16303 }
16304
16305 /* Extcommunity-list. */
16306 cm = community_list_master_lookup(bgp_clist, EXTCOMMUNITY_LIST_MASTER);
16307
16308 for (list = cm->num.head; list; list = list->next)
16309 for (entry = list->head; entry; entry = entry->next) {
16310 vty_out(vty, "bgp extcommunity-list %s %s %s\n",
16311 list->name, community_direct_str(entry->direct),
16312 community_list_config_str(entry));
16313 write++;
16314 }
16315 for (list = cm->str.head; list; list = list->next)
16316 for (entry = list->head; entry; entry = entry->next) {
16317 vty_out(vty, "bgp extcommunity-list %s %s %s %s\n",
16318 entry->style == EXTCOMMUNITY_LIST_STANDARD
16319 ? "standard"
16320 : "expanded",
16321 list->name, community_direct_str(entry->direct),
16322 community_list_config_str(entry));
16323 write++;
16324 }
16325
16326
16327 /* lcommunity-list. */
16328 cm = community_list_master_lookup(bgp_clist,
16329 LARGE_COMMUNITY_LIST_MASTER);
16330
16331 for (list = cm->num.head; list; list = list->next)
16332 for (entry = list->head; entry; entry = entry->next) {
16333 vty_out(vty, "bgp large-community-list %s %s %s\n",
16334 list->name, community_direct_str(entry->direct),
16335 community_list_config_str(entry));
16336 write++;
16337 }
16338 for (list = cm->str.head; list; list = list->next)
16339 for (entry = list->head; entry; entry = entry->next) {
16340 vty_out(vty, "bgp large-community-list %s %s %s %s\n",
16341 entry->style == LARGE_COMMUNITY_LIST_STANDARD
16342 ? "standard"
16343 : "expanded",
16344 list->name, community_direct_str(entry->direct),
16345 community_list_config_str(entry));
16346 write++;
16347 }
16348
16349 return write;
16350 }
16351
16352 static struct cmd_node community_list_node = {
16353 COMMUNITY_LIST_NODE, "", 1 /* Export to vtysh. */
16354 };
16355
16356 static void community_list_vty(void)
16357 {
16358 install_node(&community_list_node, community_list_config_write);
16359
16360 /* Community-list. */
16361 install_element(CONFIG_NODE, &bgp_community_list_standard_cmd);
16362 install_element(CONFIG_NODE, &bgp_community_list_expanded_all_cmd);
16363 install_element(CONFIG_NODE, &no_bgp_community_list_standard_all_cmd);
16364 install_element(CONFIG_NODE, &no_bgp_community_list_standard_all_list_cmd);
16365 install_element(CONFIG_NODE, &no_bgp_community_list_expanded_all_cmd);
16366 install_element(CONFIG_NODE, &no_bgp_community_list_expanded_all_list_cmd);
16367 install_element(VIEW_NODE, &show_bgp_community_list_cmd);
16368 install_element(VIEW_NODE, &show_bgp_community_list_arg_cmd);
16369
16370 /* Extcommunity-list. */
16371 install_element(CONFIG_NODE, &bgp_extcommunity_list_standard_cmd);
16372 install_element(CONFIG_NODE, &bgp_extcommunity_list_name_expanded_cmd);
16373 install_element(CONFIG_NODE, &no_bgp_extcommunity_list_standard_all_cmd);
16374 install_element(CONFIG_NODE,
16375 &no_bgp_extcommunity_list_standard_all_list_cmd);
16376 install_element(CONFIG_NODE, &no_bgp_extcommunity_list_expanded_all_cmd);
16377 install_element(CONFIG_NODE,
16378 &no_bgp_extcommunity_list_expanded_all_list_cmd);
16379 install_element(VIEW_NODE, &show_bgp_extcommunity_list_cmd);
16380 install_element(VIEW_NODE, &show_bgp_extcommunity_list_arg_cmd);
16381
16382 /* Large Community List */
16383 install_element(CONFIG_NODE, &bgp_lcommunity_list_standard_cmd);
16384 install_element(CONFIG_NODE, &bgp_lcommunity_list_expanded_cmd);
16385 install_element(CONFIG_NODE, &bgp_lcommunity_list_name_standard_cmd);
16386 install_element(CONFIG_NODE, &bgp_lcommunity_list_name_expanded_cmd);
16387 install_element(CONFIG_NODE, &no_bgp_lcommunity_list_standard_all_cmd);
16388 install_element(CONFIG_NODE,
16389 &no_bgp_lcommunity_list_name_expanded_all_cmd);
16390 install_element(CONFIG_NODE, &no_bgp_lcommunity_list_standard_cmd);
16391 install_element(CONFIG_NODE, &no_bgp_lcommunity_list_expanded_cmd);
16392 install_element(CONFIG_NODE, &no_bgp_lcommunity_list_name_standard_cmd);
16393 install_element(CONFIG_NODE, &no_bgp_lcommunity_list_name_expanded_cmd);
16394 install_element(VIEW_NODE, &show_bgp_lcommunity_list_cmd);
16395 install_element(VIEW_NODE, &show_bgp_lcommunity_list_arg_cmd);
16396 }